//native
type Gitbook = {
token: string;
};
/**
* Ask a question in an organization (streamed)
* Ask a question to an AI across spaces that is accessible by the currently authenticated target and stream the answer as a Server-Sent Events URL.
*/
export async function main(
auth: Gitbook,
organizationId: string,
query: string | undefined,
format: "document" | "markdown" | undefined,
details: string | undefined,
) {
const url = new URL(`https://api.gitbook.com/v1/orgs/${organizationId}/ask/stream`);
for (const [k, v] of [
["query", query],
["format", format],
["details", details],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 235 days ago