1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Ingest conversations |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | organizationId: string, |
12 | body: |
13 | | { |
14 | id: string; |
15 | metadata?: { url?: string; attributes?: {}; createdAt?: string }; |
16 | subject?: string; |
17 | parts: { |
18 | type: "message"; |
19 | role: "user" | "assistant" | "team-member"; |
20 | body: string; |
21 | }[]; |
22 | } |
23 | | { |
24 | id: string; |
25 | metadata?: { url?: string; attributes?: {}; createdAt?: string }; |
26 | subject?: string; |
27 | parts: { |
28 | type: "message"; |
29 | role: "user" | "assistant" | "team-member"; |
30 | body: string; |
31 | }[]; |
32 | }[], |
33 | ) { |
34 | const url = new URL(`https://api.gitbook.com/v1/orgs/${organizationId}/conversations`); |
35 |
|
36 | const response = await fetch(url, { |
37 | method: "POST", |
38 | headers: { |
39 | "Content-Type": "application/json", |
40 | Authorization: "Bearer " + auth.token, |
41 | }, |
42 | body: JSON.stringify(body), |
43 | }); |
44 | if (!response.ok) { |
45 | const text = await response.text(); |
46 | throw new Error(`${response.status} ${text}`); |
47 | } |
48 | return await response.text(); |
49 | } |
50 |
|