@introspection-sdk/introspection-browser 0.5.3 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/README.md +45 -33
  3. package/dist/api/client.d.ts +35 -12
  4. package/dist/api/client.d.ts.map +1 -1
  5. package/dist/api/client.js +81 -17
  6. package/dist/api/client.js.map +1 -1
  7. package/dist/api/http.d.ts +23 -0
  8. package/dist/api/http.d.ts.map +1 -1
  9. package/dist/api/http.js +38 -0
  10. package/dist/api/http.js.map +1 -1
  11. package/dist/api/index.d.ts +13 -12
  12. package/dist/api/index.d.ts.map +1 -1
  13. package/dist/api/index.js +12 -11
  14. package/dist/api/index.js.map +1 -1
  15. package/dist/api/runner.d.ts +45 -0
  16. package/dist/api/runner.d.ts.map +1 -0
  17. package/dist/api/runner.js +87 -0
  18. package/dist/api/runner.js.map +1 -0
  19. package/dist/api/runtimes.d.ts +12 -0
  20. package/dist/api/runtimes.d.ts.map +1 -0
  21. package/dist/api/runtimes.js +14 -0
  22. package/dist/api/runtimes.js.map +1 -0
  23. package/dist/api/tasks.d.ts +15 -48
  24. package/dist/api/tasks.d.ts.map +1 -1
  25. package/dist/api/tasks.js +7 -130
  26. package/dist/api/tasks.js.map +1 -1
  27. package/package.json +3 -3
  28. package/src/api/client.ts +133 -22
  29. package/src/api/http.ts +56 -0
  30. package/src/api/index.ts +46 -15
  31. package/src/api/runner.ts +127 -0
  32. package/src/api/runtimes.ts +32 -0
  33. package/src/api/tasks.ts +25 -160
  34. package/dist/api/conversations.d.ts +0 -84
  35. package/dist/api/conversations.d.ts.map +0 -1
  36. package/dist/api/conversations.js +0 -172
  37. package/dist/api/conversations.js.map +0 -1
  38. package/dist/api/files.d.ts +0 -61
  39. package/dist/api/files.d.ts.map +0 -1
  40. package/dist/api/files.js +0 -145
  41. package/dist/api/files.js.map +0 -1
  42. package/src/api/conversations.ts +0 -214
  43. package/src/api/files.ts +0 -196
@@ -1,172 +0,0 @@
1
- /**
2
- * Cookie-authenticated, read-only Conversations client for the browser
3
- * (`/v1/conversations`).
4
- *
5
- * Mirrors the Node SDK's runner-bound `ConversationsApi`, but rides the
6
- * DP `intro_dp_session` cookie via {@link BrowserHttpClient} instead of a
7
- * bearer token — so a single-page app reads conversation history with the
8
- * same identity session it uses for tasks and files. Conversations are a
9
- * projection over the immutable telemetry store: list summaries, walk a
10
- * conversation's items, or `retrieve()` the resolved state of one turn.
11
- */
12
- import { Paginator, cursorPaginate } from "@introspection-sdk/http";
13
- /** Includes requested when building a {@link ConversationResponse}. */
14
- const RESPONSE_INCLUDES = [
15
- "gen_ai.input.messages",
16
- "gen_ai.system_instructions",
17
- "gen_ai.tool.definitions",
18
- ];
19
- /**
20
- * Items of a conversation (`/v1/conversations/{id}/items`). Read-only.
21
- *
22
- * Paging is OpenAI-style underneath: the envelope has NO `next` token —
23
- * `list()` drives `after` = the previous page's `last_id` while
24
- * `has_more` is true.
25
- */
26
- export class ConversationItemsClient {
27
- http;
28
- constructor(http) {
29
- this.http = http;
30
- }
31
- /**
32
- * List items of a conversation. `await` the result for the first page
33
- * (an OpenAI-style {@link ConversationItemList} envelope), or
34
- * `for await` it to stream every item across pages (fetched lazily —
35
- * `limit` sets the page size, `after` the starting cursor; stop early to
36
- * stop fetching). Pass `order: "asc"` to walk the transcript from the
37
- * start.
38
- *
39
- * Items carry the turn-local delta in `input_messages` — only the
40
- * messages new to that turn. Use `get()` for the full input history.
41
- */
42
- list(conversationId, params) {
43
- return new Paginator({
44
- fetch: (after) => this.http.request({
45
- method: "GET",
46
- path: `/v1/conversations/${encodeURIComponent(conversationId)}/items`,
47
- query: { ...params, after },
48
- }),
49
- items: (page) => page.data,
50
- next: (page) => page.has_more && page.last_id !== null ? page.last_id : undefined,
51
- }, params?.after);
52
- }
53
- /**
54
- * Fetch a single conversation item. Unlike the list route, the
55
- * detail's `input_messages` is the FULL input history for that span.
56
- */
57
- get(conversationId, itemId, params) {
58
- return this.http.request({
59
- method: "GET",
60
- path: `/v1/conversations/${encodeURIComponent(conversationId)}/items/${encodeURIComponent(itemId)}`,
61
- query: params,
62
- });
63
- }
64
- }
65
- /**
66
- * Read-only Conversations client (`/v1/conversations`).
67
- *
68
- * Both `list()` and `items.list()` are auto-paging, but they drive
69
- * different wire protocols underneath: `list()` walks the standard
70
- * Introspection cursor envelope's opaque `next` token, while
71
- * `items.list()` walks an OpenAI-style envelope via `after` = the
72
- * previous page's `last_id` while `has_more` is true.
73
- */
74
- export class ConversationsClient {
75
- http;
76
- /** Items of a conversation — `conversations.items.list(...)` etc. */
77
- items;
78
- constructor(http) {
79
- this.http = http;
80
- this.items = new ConversationItemsClient(http);
81
- }
82
- /**
83
- * List conversation summaries matching `params`. `await` the result for
84
- * the first page, or `for await` it to stream every summary across
85
- * pages (fetched lazily — `limit` sets the page size, `next` the
86
- * starting cursor; stop early to stop fetching).
87
- */
88
- list(params) {
89
- return cursorPaginate((next) => this.http.request({
90
- method: "GET",
91
- path: "/v1/conversations",
92
- query: { ...params, next },
93
- }), params?.next);
94
- }
95
- /**
96
- * Responses-API-style retrieve: load the state of a conversation as of
97
- * one item — the full input history, output, system instructions, and
98
- * tool definitions of that turn.
99
- *
100
- * When `itemId` is omitted, the latest LLM turn is used: the first
101
- * item (in descending order) whose `node_type` is `"assistant"` or
102
- * whose `operation_name` is `"chat"`, falling back to the first item
103
- * with a non-null `output_message`. Returns `null` when the
104
- * conversation has no items.
105
- *
106
- * For the full per-turn transcript instead, iterate
107
- * `items.list(conversationId, { order: "asc" })`.
108
- */
109
- async retrieve(conversationId, itemId) {
110
- const targetId = itemId ?? (await this.findLatestTurnId(conversationId));
111
- if (targetId === null)
112
- return null;
113
- const detail = await this.items.get(conversationId, targetId, {
114
- include: RESPONSE_INCLUDES,
115
- });
116
- const outputMessages = detail.gen_ai_output_messages ??
117
- (detail.output_message ? [detail.output_message] : []);
118
- return {
119
- conversation_id: conversationId,
120
- response_id: detail.response_id ?? null,
121
- item_id: detail.id,
122
- created_at: detail.created_at,
123
- model: detail.model_name ??
124
- detail.response_model ??
125
- detail.request_model ??
126
- null,
127
- provider_name: detail.provider_name ?? null,
128
- // The single-item route returns the FULL input history here.
129
- input_messages: normalizeMessages(detail.input_messages),
130
- output_messages: normalizeMessages(outputMessages),
131
- system_instructions: detail.system_instructions ?? null,
132
- tool_definitions: detail.tool_definitions ?? null,
133
- };
134
- }
135
- /** Scan items in descending order for the most recent LLM turn. */
136
- async findLatestTurnId(conversationId) {
137
- let fallback = null;
138
- for await (const item of this.items.list(conversationId, {
139
- order: "desc",
140
- })) {
141
- if (item.node_type === "assistant" || item.operation_name === "chat") {
142
- return item.id;
143
- }
144
- if (fallback === null && item.output_message != null)
145
- fallback = item;
146
- }
147
- return fallback?.id ?? null;
148
- }
149
- }
150
- /**
151
- * Defensive normalization for {@link ConversationsClient.retrieve} only:
152
- * older DP deployments emitted `tool_call_response` parts with a legacy
153
- * `result` key instead of the semconv `response` key. Map it across so
154
- * replayed history is always semconv-shaped.
155
- */
156
- function normalizeMessages(messages) {
157
- return messages.map((message) => ({
158
- ...message,
159
- parts: message.parts.map(normalizePart),
160
- }));
161
- }
162
- function normalizePart(part) {
163
- if (part.type !== "tool_call_response")
164
- return part;
165
- const legacy = part;
166
- if (legacy.response !== undefined || legacy.result === undefined) {
167
- return part;
168
- }
169
- const { result, ...rest } = legacy;
170
- return { ...rest, response: result };
171
- }
172
- //# sourceMappingURL=conversations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"conversations.js","sourceRoot":"","sources":["../../src/api/conversations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAcH,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGpE,uEAAuE;AACvE,MAAM,iBAAiB,GAA8B;IACnD,uBAAuB;IACvB,4BAA4B;IAC5B,yBAAyB;CAC1B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,O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,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AACvC,CAAC"}
@@ -1,61 +0,0 @@
1
- /**
2
- * Cookie-authenticated Files client for the browser (`/v1/files`).
3
- *
4
- * Mirrors the Node SDK's runner-bound `FilesApi`, but rides the DP
5
- * `intro_dp_session` cookie via {@link BrowserHttpClient} instead of a
6
- * bearer token — so a single-page app reads and writes files with the
7
- * same identity session it uses for tasks and conversations. The DP
8
- * derives the owning `identity_key` from the session JWT; per-identity
9
- * file visibility is enforced server-side.
10
- */
11
- import type { File as FileResource, FileCreateOptions, FileCreateTextParams, FileListParams, FileType, FileUpdateParams, ListParams } from "@introspection-sdk/types";
12
- import { Paginator } from "@introspection-sdk/http";
13
- import { BrowserHttpClient } from "./http.js";
14
- export type FileUploadBody = {
15
- file: Blob;
16
- name?: string;
17
- file_type?: FileType;
18
- } | {
19
- file: Uint8Array;
20
- name: string;
21
- file_type?: FileType;
22
- contentType?: string;
23
- };
24
- /** Versions of a file (`/v1/files/{id}/versions`). */
25
- export declare class FileVersionsClient {
26
- private readonly http;
27
- constructor(http: BrowserHttpClient);
28
- /**
29
- * List versions of a file. `await` the result for the first page, or
30
- * `for await` it to stream every version across pages (fetched lazily;
31
- * stop early to stop fetching).
32
- */
33
- list(fileId: string, params?: ListParams): Paginator<FileResource>;
34
- get(fileId: string, versionId: string): Promise<FileResource>;
35
- create(fileId: string, body: FileUploadBody, options?: FileCreateOptions): Promise<FileResource>;
36
- }
37
- /**
38
- * Cookie-authenticated `/v1/files` client. Mirrors the Node SDK's
39
- * `FilesApi` shape but is bound to a DP session cookie rather than a
40
- * bearer token.
41
- */
42
- export declare class FilesClient {
43
- private readonly http;
44
- readonly versions: FileVersionsClient;
45
- constructor(http: BrowserHttpClient);
46
- /**
47
- * List files matching `params`. `await` the result for the first page,
48
- * or `for await` it to stream every file across pages (fetched lazily —
49
- * `limit` sets the page size, `next` the starting cursor; stop early to
50
- * stop fetching).
51
- */
52
- list(params?: FileListParams): Paginator<FileResource>;
53
- upload(body: FileUploadBody, options?: FileCreateOptions): Promise<FileResource>;
54
- createText(body: FileCreateTextParams, options?: FileCreateOptions): Promise<FileResource>;
55
- get(fileId: string): Promise<FileResource>;
56
- update(fileId: string, body: FileUpdateParams): Promise<FileResource>;
57
- delete(fileId: string): Promise<void>;
58
- download(fileId: string): Promise<Uint8Array>;
59
- downloadStream(fileId: string): Promise<ReadableStream<Uint8Array>>;
60
- }
61
- //# sourceMappingURL=files.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/api/files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,IAAI,IAAI,YAAY,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,UAAU,EAEX,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAkB,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,QAAQ,CAAA;CAAE,GACnD;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN,sDAAsD;AACtD,qBAAa,kBAAkB;IACjB,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,iBAAiB;IAEpD;;;;OAIG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,YAAY,CAAC;IAYlE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAO7D,MAAM,CACJ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,YAAY,CAAC;CAQzB;AAED;;;;GAIG;AACH,qBAAa,WAAW;IAGV,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;gBAET,IAAI,EAAE,iBAAiB;IAIpD;;;;;OAKG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC,YAAY,CAAC;IAYtD,MAAM,CACJ,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,YAAY,CAAC;IASxB,UAAU,CACR,IAAI,EAAE,oBAAoB,EAC1B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,YAAY,CAAC;IAUxB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAO1C,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC;IAQrE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAQ7C,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;CAOpE"}
package/dist/api/files.js DELETED
@@ -1,145 +0,0 @@
1
- /**
2
- * Cookie-authenticated Files client for the browser (`/v1/files`).
3
- *
4
- * Mirrors the Node SDK's runner-bound `FilesApi`, but rides the DP
5
- * `intro_dp_session` cookie via {@link BrowserHttpClient} instead of a
6
- * bearer token — so a single-page app reads and writes files with the
7
- * same identity session it uses for tasks and conversations. The DP
8
- * derives the owning `identity_key` from the session JWT; per-identity
9
- * file visibility is enforced server-side.
10
- */
11
- import { cursorPaginate } from "@introspection-sdk/http";
12
- /** Versions of a file (`/v1/files/{id}/versions`). */
13
- export class FileVersionsClient {
14
- http;
15
- constructor(http) {
16
- this.http = http;
17
- }
18
- /**
19
- * List versions of a file. `await` the result for the first page, or
20
- * `for await` it to stream every version across pages (fetched lazily;
21
- * stop early to stop fetching).
22
- */
23
- list(fileId, params) {
24
- return cursorPaginate((next) => this.http.request({
25
- method: "GET",
26
- path: `/v1/files/${encodeURIComponent(fileId)}/versions`,
27
- query: { ...params, next },
28
- }), params?.next);
29
- }
30
- get(fileId, versionId) {
31
- return this.http.request({
32
- method: "GET",
33
- path: `/v1/files/${encodeURIComponent(fileId)}/versions/${encodeURIComponent(versionId)}`,
34
- });
35
- }
36
- create(fileId, body, options) {
37
- const form = toFormData(body, options);
38
- return this.http.request({
39
- method: "POST",
40
- path: `/v1/files/${encodeURIComponent(fileId)}/versions`,
41
- body: form,
42
- });
43
- }
44
- }
45
- /**
46
- * Cookie-authenticated `/v1/files` client. Mirrors the Node SDK's
47
- * `FilesApi` shape but is bound to a DP session cookie rather than a
48
- * bearer token.
49
- */
50
- export class FilesClient {
51
- http;
52
- versions;
53
- constructor(http) {
54
- this.http = http;
55
- this.versions = new FileVersionsClient(http);
56
- }
57
- /**
58
- * List files matching `params`. `await` the result for the first page,
59
- * or `for await` it to stream every file across pages (fetched lazily —
60
- * `limit` sets the page size, `next` the starting cursor; stop early to
61
- * stop fetching).
62
- */
63
- list(params) {
64
- return cursorPaginate((next) => this.http.request({
65
- method: "GET",
66
- path: "/v1/files",
67
- query: { ...params, next },
68
- }), params?.next);
69
- }
70
- upload(body, options) {
71
- const form = toFormData(body, options);
72
- return this.http.request({
73
- method: "POST",
74
- path: "/v1/files",
75
- body: form,
76
- });
77
- }
78
- createText(body, options) {
79
- return this.http.request({
80
- method: "POST",
81
- path: "/v1/files",
82
- body: options?.visibility
83
- ? { ...body, visibility: options.visibility }
84
- : body,
85
- });
86
- }
87
- get(fileId) {
88
- return this.http.request({
89
- method: "GET",
90
- path: `/v1/files/${encodeURIComponent(fileId)}`,
91
- });
92
- }
93
- update(fileId, body) {
94
- return this.http.request({
95
- method: "PATCH",
96
- path: `/v1/files/${encodeURIComponent(fileId)}`,
97
- body,
98
- });
99
- }
100
- delete(fileId) {
101
- return this.http.request({
102
- method: "DELETE",
103
- path: `/v1/files/${encodeURIComponent(fileId)}`,
104
- expect: "empty",
105
- });
106
- }
107
- download(fileId) {
108
- return this.http.request({
109
- method: "GET",
110
- path: `/v1/files/${encodeURIComponent(fileId)}/content`,
111
- expect: "bytes",
112
- });
113
- }
114
- downloadStream(fileId) {
115
- return this.http.request({
116
- method: "GET",
117
- path: `/v1/files/${encodeURIComponent(fileId)}/content`,
118
- expect: "stream",
119
- });
120
- }
121
- }
122
- function toFormData(body, options) {
123
- const fd = new FormData();
124
- if ("file" in body && body.file instanceof Blob) {
125
- fd.append("file", body.file, body.name);
126
- }
127
- else {
128
- // Uint8Array branch — copy into a fresh ArrayBuffer so the Blob
129
- // constructor sees a concrete ArrayBuffer (not ArrayBufferLike,
130
- // which TS rejects under nodenext lib).
131
- const u8 = body.file;
132
- const ct = body.contentType ??
133
- "application/octet-stream";
134
- const ab = u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength);
135
- fd.append("file", new Blob([ab], { type: ct }), body.name);
136
- }
137
- if (body.name)
138
- fd.append("name", body.name);
139
- if (body.file_type)
140
- fd.append("file_type", body.file_type);
141
- if (options?.visibility)
142
- fd.append("visibility", options.visibility);
143
- return fd;
144
- }
145
- //# sourceMappingURL=files.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/api/files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAYH,OAAO,EAAa,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAYpE,sDAAsD;AACtD,MAAM,OAAO,kBAAkB;IACA;IAA7B,YAA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I,CAAC,IAAI,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,IAAI,CAAC,IAAI;QAAE,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,IAAI,CAAC,SAAS;QAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC3D,IAAI,OAAO,EAAE,UAAU;QAAE,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACrE,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -1,214 +0,0 @@
1
- /**
2
- * Cookie-authenticated, read-only Conversations client for the browser
3
- * (`/v1/conversations`).
4
- *
5
- * Mirrors the Node SDK's runner-bound `ConversationsApi`, but rides the
6
- * DP `intro_dp_session` cookie via {@link BrowserHttpClient} instead of a
7
- * bearer token — so a single-page app reads conversation history with the
8
- * same identity session it uses for tasks and files. Conversations are a
9
- * projection over the immutable telemetry store: list summaries, walk a
10
- * conversation's items, or `retrieve()` the resolved state of one turn.
11
- */
12
-
13
- import type {
14
- ConversationItem,
15
- ConversationItemInclude,
16
- ConversationItemList,
17
- ConversationItemListParams,
18
- ConversationListParams,
19
- ConversationResponse,
20
- ConversationSummary,
21
- MessagePart,
22
- Paginated,
23
- ToolCallResponsePart,
24
- } from "@introspection-sdk/types";
25
- import { Paginator, cursorPaginate } from "@introspection-sdk/http";
26
- import { BrowserHttpClient } from "./http.js";
27
-
28
- /** Includes requested when building a {@link ConversationResponse}. */
29
- const RESPONSE_INCLUDES: ConversationItemInclude[] = [
30
- "gen_ai.input.messages",
31
- "gen_ai.system_instructions",
32
- "gen_ai.tool.definitions",
33
- ];
34
-
35
- /**
36
- * Items of a conversation (`/v1/conversations/{id}/items`). Read-only.
37
- *
38
- * Paging is OpenAI-style underneath: the envelope has NO `next` token —
39
- * `list()` drives `after` = the previous page's `last_id` while
40
- * `has_more` is true.
41
- */
42
- export class ConversationItemsClient {
43
- constructor(private readonly http: BrowserHttpClient) {}
44
-
45
- /**
46
- * List items of a conversation. `await` the result for the first page
47
- * (an OpenAI-style {@link ConversationItemList} envelope), or
48
- * `for await` it to stream every item across pages (fetched lazily —
49
- * `limit` sets the page size, `after` the starting cursor; stop early to
50
- * stop fetching). Pass `order: "asc"` to walk the transcript from the
51
- * start.
52
- *
53
- * Items carry the turn-local delta in `input_messages` — only the
54
- * messages new to that turn. Use `get()` for the full input history.
55
- */
56
- list(
57
- conversationId: string,
58
- params?: ConversationItemListParams,
59
- ): Paginator<ConversationItem, ConversationItemList> {
60
- return new Paginator(
61
- {
62
- fetch: (after) =>
63
- this.http.request<ConversationItemList>({
64
- method: "GET",
65
- path: `/v1/conversations/${encodeURIComponent(conversationId)}/items`,
66
- query: { ...params, after } as Record<string, unknown>,
67
- }),
68
- items: (page) => page.data,
69
- next: (page) =>
70
- page.has_more && page.last_id !== null ? page.last_id : undefined,
71
- },
72
- params?.after,
73
- );
74
- }
75
-
76
- /**
77
- * Fetch a single conversation item. Unlike the list route, the
78
- * detail's `input_messages` is the FULL input history for that span.
79
- */
80
- get(
81
- conversationId: string,
82
- itemId: string,
83
- params?: { include?: ConversationItemInclude[] },
84
- ): Promise<ConversationItem> {
85
- return this.http.request<ConversationItem>({
86
- method: "GET",
87
- path: `/v1/conversations/${encodeURIComponent(conversationId)}/items/${encodeURIComponent(itemId)}`,
88
- query: params as Record<string, unknown> | undefined,
89
- });
90
- }
91
- }
92
-
93
- /**
94
- * Read-only Conversations client (`/v1/conversations`).
95
- *
96
- * Both `list()` and `items.list()` are auto-paging, but they drive
97
- * different wire protocols underneath: `list()` walks the standard
98
- * Introspection cursor envelope's opaque `next` token, while
99
- * `items.list()` walks an OpenAI-style envelope via `after` = the
100
- * previous page's `last_id` while `has_more` is true.
101
- */
102
- export class ConversationsClient {
103
- /** Items of a conversation — `conversations.items.list(...)` etc. */
104
- readonly items: ConversationItemsClient;
105
-
106
- constructor(private readonly http: BrowserHttpClient) {
107
- this.items = new ConversationItemsClient(http);
108
- }
109
-
110
- /**
111
- * List conversation summaries matching `params`. `await` the result for
112
- * the first page, or `for await` it to stream every summary across
113
- * pages (fetched lazily — `limit` sets the page size, `next` the
114
- * starting cursor; stop early to stop fetching).
115
- */
116
- list(params?: ConversationListParams): Paginator<ConversationSummary> {
117
- return cursorPaginate(
118
- (next) =>
119
- this.http.request<Paginated<ConversationSummary>>({
120
- method: "GET",
121
- path: "/v1/conversations",
122
- query: { ...params, next } as Record<string, unknown>,
123
- }),
124
- params?.next,
125
- );
126
- }
127
-
128
- /**
129
- * Responses-API-style retrieve: load the state of a conversation as of
130
- * one item — the full input history, output, system instructions, and
131
- * tool definitions of that turn.
132
- *
133
- * When `itemId` is omitted, the latest LLM turn is used: the first
134
- * item (in descending order) whose `node_type` is `"assistant"` or
135
- * whose `operation_name` is `"chat"`, falling back to the first item
136
- * with a non-null `output_message`. Returns `null` when the
137
- * conversation has no items.
138
- *
139
- * For the full per-turn transcript instead, iterate
140
- * `items.list(conversationId, { order: "asc" })`.
141
- */
142
- async retrieve(
143
- conversationId: string,
144
- itemId?: string,
145
- ): Promise<ConversationResponse | null> {
146
- const targetId = itemId ?? (await this.findLatestTurnId(conversationId));
147
- if (targetId === null) return null;
148
-
149
- const detail = await this.items.get(conversationId, targetId, {
150
- include: RESPONSE_INCLUDES,
151
- });
152
- const outputMessages =
153
- detail.gen_ai_output_messages ??
154
- (detail.output_message ? [detail.output_message] : []);
155
- return {
156
- conversation_id: conversationId,
157
- response_id: detail.response_id ?? null,
158
- item_id: detail.id,
159
- created_at: detail.created_at,
160
- model:
161
- detail.model_name ??
162
- detail.response_model ??
163
- detail.request_model ??
164
- null,
165
- provider_name: detail.provider_name ?? null,
166
- // The single-item route returns the FULL input history here.
167
- input_messages: normalizeMessages(detail.input_messages),
168
- output_messages: normalizeMessages(outputMessages),
169
- system_instructions: detail.system_instructions ?? null,
170
- tool_definitions: detail.tool_definitions ?? null,
171
- };
172
- }
173
-
174
- /** Scan items in descending order for the most recent LLM turn. */
175
- private async findLatestTurnId(
176
- conversationId: string,
177
- ): Promise<string | null> {
178
- let fallback: ConversationItem | null = null;
179
- for await (const item of this.items.list(conversationId, {
180
- order: "desc",
181
- })) {
182
- if (item.node_type === "assistant" || item.operation_name === "chat") {
183
- return item.id;
184
- }
185
- if (fallback === null && item.output_message != null) fallback = item;
186
- }
187
- return fallback?.id ?? null;
188
- }
189
- }
190
-
191
- /**
192
- * Defensive normalization for {@link ConversationsClient.retrieve} only:
193
- * older DP deployments emitted `tool_call_response` parts with a legacy
194
- * `result` key instead of the semconv `response` key. Map it across so
195
- * replayed history is always semconv-shaped.
196
- */
197
- function normalizeMessages<T extends { parts: MessagePart[] }>(
198
- messages: T[],
199
- ): T[] {
200
- return messages.map((message) => ({
201
- ...message,
202
- parts: message.parts.map(normalizePart),
203
- }));
204
- }
205
-
206
- function normalizePart(part: MessagePart): MessagePart {
207
- if (part.type !== "tool_call_response") return part;
208
- const legacy = part as ToolCallResponsePart & { result?: unknown };
209
- if (legacy.response !== undefined || legacy.result === undefined) {
210
- return part;
211
- }
212
- const { result, ...rest } = legacy;
213
- return { ...rest, response: result };
214
- }