@introspection-sdk/introspection-browser 0.5.1 → 0.5.3
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.
- package/.turbo/turbo-build.log +1 -1
- package/README.md +87 -0
- package/dist/api/client.d.ts +59 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +82 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/conversations.d.ts +84 -0
- package/dist/api/conversations.d.ts.map +1 -0
- package/dist/api/conversations.js +172 -0
- package/dist/api/conversations.js.map +1 -0
- package/dist/api/files.d.ts +61 -0
- package/dist/api/files.d.ts.map +1 -0
- package/dist/api/files.js +145 -0
- package/dist/api/files.js.map +1 -0
- package/dist/api/http.d.ts +36 -0
- package/dist/api/http.d.ts.map +1 -0
- package/dist/api/http.js +34 -0
- package/dist/api/http.js.map +1 -0
- package/dist/api/index.d.ts +38 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +37 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/sse.d.ts +7 -0
- package/dist/api/sse.d.ts.map +1 -0
- package/dist/api/sse.js +7 -0
- package/dist/api/sse.js.map +1 -0
- package/dist/api/tasks.d.ts +83 -0
- package/dist/api/tasks.d.ts.map +1 -0
- package/dist/api/tasks.js +146 -0
- package/dist/api/tasks.js.map +1 -0
- package/package.json +11 -6
- package/src/api/client.ts +106 -0
- package/src/api/conversations.ts +214 -0
- package/src/api/files.ts +196 -0
- package/src/api/http.ts +55 -0
- package/src/api/index.ts +93 -0
- package/src/api/sse.ts +6 -0
- package/src/api/tasks.ts +208 -0
|
@@ -0,0 +1,145 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;I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EAAE,IAAI,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"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser HTTP transport for the Introspection Data Plane `/v1` surface.
|
|
3
|
+
*
|
|
4
|
+
* The request/response machinery — URL joining, query building, body
|
|
5
|
+
* serialization, error mapping, SSE — lives in the shared
|
|
6
|
+
* `@introspection-sdk/http` {@link BaseHttpClient}. This module pins the
|
|
7
|
+
* browser auth strategy on top of it: the DP is reached with the HttpOnly
|
|
8
|
+
* `intro_dp_session` cookie minted by `POST /v1/oauth/exchange`, so every
|
|
9
|
+
* request opts into `credentials: "include"` and sends NO bearer token —
|
|
10
|
+
* no Introspection credential ever lives in JavaScript. A 401 (expired
|
|
11
|
+
* session cookie) triggers a single `onUnauthorized` refresh + retry.
|
|
12
|
+
*/
|
|
13
|
+
import { BaseHttpClient, stripTrailingSlash, toApiError } from "@introspection-sdk/http";
|
|
14
|
+
export { stripTrailingSlash, toApiError };
|
|
15
|
+
export interface BrowserHttpConfig {
|
|
16
|
+
/** DP REST base URL every request is prefixed with. */
|
|
17
|
+
apiUrl: string;
|
|
18
|
+
/** Extra headers merged into every request. */
|
|
19
|
+
additionalHeaders?: Record<string, string>;
|
|
20
|
+
/** Custom `fetch` (for tests or non-standard runtimes). */
|
|
21
|
+
fetch?: typeof fetch;
|
|
22
|
+
/**
|
|
23
|
+
* Invoked when a request comes back `401`. Return `true` if the DP
|
|
24
|
+
* session was refreshed and the request should be retried once;
|
|
25
|
+
* `false` to surface the original error.
|
|
26
|
+
*/
|
|
27
|
+
onUnauthorized?: () => Promise<boolean>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Cookie-authenticated HTTP wrapper bound to one DP endpoint. Has no
|
|
31
|
+
* opinion about which resource it serves — the caller picks the path.
|
|
32
|
+
*/
|
|
33
|
+
export declare class BrowserHttpClient extends BaseHttpClient {
|
|
34
|
+
constructor(cfg: BrowserHttpConfig);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/api/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,UAAU,EACX,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC;AAE1C,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,2DAA2D;IAC3D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CACzC;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,cAAc;gBACvC,GAAG,EAAE,iBAAiB;CAYnC"}
|
package/dist/api/http.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser HTTP transport for the Introspection Data Plane `/v1` surface.
|
|
3
|
+
*
|
|
4
|
+
* The request/response machinery — URL joining, query building, body
|
|
5
|
+
* serialization, error mapping, SSE — lives in the shared
|
|
6
|
+
* `@introspection-sdk/http` {@link BaseHttpClient}. This module pins the
|
|
7
|
+
* browser auth strategy on top of it: the DP is reached with the HttpOnly
|
|
8
|
+
* `intro_dp_session` cookie minted by `POST /v1/oauth/exchange`, so every
|
|
9
|
+
* request opts into `credentials: "include"` and sends NO bearer token —
|
|
10
|
+
* no Introspection credential ever lives in JavaScript. A 401 (expired
|
|
11
|
+
* session cookie) triggers a single `onUnauthorized` refresh + retry.
|
|
12
|
+
*/
|
|
13
|
+
import { BaseHttpClient, stripTrailingSlash, toApiError, } from "@introspection-sdk/http";
|
|
14
|
+
// Re-exported for `client.ts`, which redeems the DP session on `connect()`.
|
|
15
|
+
export { stripTrailingSlash, toApiError };
|
|
16
|
+
/**
|
|
17
|
+
* Cookie-authenticated HTTP wrapper bound to one DP endpoint. Has no
|
|
18
|
+
* opinion about which resource it serves — the caller picks the path.
|
|
19
|
+
*/
|
|
20
|
+
export class BrowserHttpClient extends BaseHttpClient {
|
|
21
|
+
constructor(cfg) {
|
|
22
|
+
super({
|
|
23
|
+
apiUrl: cfg.apiUrl,
|
|
24
|
+
additionalHeaders: cfg.additionalHeaders,
|
|
25
|
+
fetch: cfg.fetch,
|
|
26
|
+
transport: {
|
|
27
|
+
authHeaders: () => ({}),
|
|
28
|
+
credentials: "include",
|
|
29
|
+
onUnauthorized: cfg.onUnauthorized,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/api/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,UAAU,GACX,MAAM,yBAAyB,CAAC;AAEjC,4EAA4E;AAC5E,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC;AAiB1C;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,cAAc;IACnD,YAAY,GAAsB;QAChC,KAAK,CAAC;YACJ,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;YACxC,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,SAAS,EAAE;gBACT,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;gBACvB,WAAW,EAAE,SAAS;gBACtB,cAAc,EAAE,GAAG,CAAC,cAAc;aACnC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Introspection Browser API surface — `@introspection-sdk/introspection-browser/api`.
|
|
3
|
+
*
|
|
4
|
+
* A cookie-authenticated client for creating and streaming Introspection
|
|
5
|
+
* tasks directly from a single-page app, with no API key in the browser.
|
|
6
|
+
* Separate from the package's default telemetry export so apps only pull
|
|
7
|
+
* in what they use.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { IntrospectionApiClient } from "@introspection-sdk/introspection-browser/api";
|
|
12
|
+
*
|
|
13
|
+
* const client = new IntrospectionApiClient({
|
|
14
|
+
* dpUrl: "https://dp.us.introspection.dev",
|
|
15
|
+
* projectId: "proj_…",
|
|
16
|
+
* // your backend mints the Introspection access token
|
|
17
|
+
* getToken: () => fetch("/api/introspection/token").then((r) => r.text()),
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* await client.connect(); // → intro_dp_session cookie
|
|
21
|
+
* const run = await client.tasks.start({
|
|
22
|
+
* prompt: "Summarize my latest order",
|
|
23
|
+
* agent_name: "support-agent",
|
|
24
|
+
* identity: { user_id: "u_42" },
|
|
25
|
+
* });
|
|
26
|
+
* for await (const ev of run.stream()) console.log(ev.event, ev.data);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export { IntrospectionApiClient, type IntrospectionApiClientOptions, } from "./client.js";
|
|
30
|
+
export { TasksClient, TaskRunsClient, RunHandle, type CreateTaskParams, type StartTaskParams, } from "./tasks.js";
|
|
31
|
+
export { FilesClient, FileVersionsClient, type FileUploadBody, } from "./files.js";
|
|
32
|
+
export { ConversationsClient, ConversationItemsClient, } from "./conversations.js";
|
|
33
|
+
export { BrowserHttpClient, type BrowserHttpConfig } from "./http.js";
|
|
34
|
+
export { parseSse } from "./sse.js";
|
|
35
|
+
export { Paginator, cursorPaginate, type PageSource, } from "@introspection-sdk/http";
|
|
36
|
+
export type { Task, TaskRun, TaskStatus, TaskVisibility, TaskCreateResponse, TaskListParams, TaskUpdateParams, TaskRunCreateParams, TaskCancelResponse, RunIdentityInput, Paginated, SseEvent, File, FileType, FileListParams, FileUpdateParams, FileCreateTextParams, FileCreateOptions, ListParams, ConversationSummary, ConversationItem, ConversationItemList, ConversationListParams, ConversationItemListParams, ConversationItemInclude, ConversationResponse, } from "@introspection-sdk/types";
|
|
37
|
+
export { IntrospectionAPIError, AuthenticationError, InsufficientScopeError, NotFoundError, NetworkError, } from "@introspection-sdk/types";
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EACL,sBAAsB,EACtB,KAAK,6BAA6B,GACnC,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,WAAW,EACX,cAAc,EACd,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,KAAK,cAAc,GACpB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EACL,SAAS,EACT,cAAc,EACd,KAAK,UAAU,GAChB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EACV,IAAI,EACJ,OAAO,EACP,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,YAAY,GACb,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Introspection Browser API surface — `@introspection-sdk/introspection-browser/api`.
|
|
3
|
+
*
|
|
4
|
+
* A cookie-authenticated client for creating and streaming Introspection
|
|
5
|
+
* tasks directly from a single-page app, with no API key in the browser.
|
|
6
|
+
* Separate from the package's default telemetry export so apps only pull
|
|
7
|
+
* in what they use.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { IntrospectionApiClient } from "@introspection-sdk/introspection-browser/api";
|
|
12
|
+
*
|
|
13
|
+
* const client = new IntrospectionApiClient({
|
|
14
|
+
* dpUrl: "https://dp.us.introspection.dev",
|
|
15
|
+
* projectId: "proj_…",
|
|
16
|
+
* // your backend mints the Introspection access token
|
|
17
|
+
* getToken: () => fetch("/api/introspection/token").then((r) => r.text()),
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* await client.connect(); // → intro_dp_session cookie
|
|
21
|
+
* const run = await client.tasks.start({
|
|
22
|
+
* prompt: "Summarize my latest order",
|
|
23
|
+
* agent_name: "support-agent",
|
|
24
|
+
* identity: { user_id: "u_42" },
|
|
25
|
+
* });
|
|
26
|
+
* for await (const ev of run.stream()) console.log(ev.event, ev.data);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export { IntrospectionApiClient, } from "./client.js";
|
|
30
|
+
export { TasksClient, TaskRunsClient, RunHandle, } from "./tasks.js";
|
|
31
|
+
export { FilesClient, FileVersionsClient, } from "./files.js";
|
|
32
|
+
export { ConversationsClient, ConversationItemsClient, } from "./conversations.js";
|
|
33
|
+
export { BrowserHttpClient } from "./http.js";
|
|
34
|
+
export { parseSse } from "./sse.js";
|
|
35
|
+
export { Paginator, cursorPaginate, } from "@introspection-sdk/http";
|
|
36
|
+
export { IntrospectionAPIError, AuthenticationError, InsufficientScopeError, NotFoundError, NetworkError, } from "@introspection-sdk/types";
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EACL,sBAAsB,GAEvB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,WAAW,EACX,cAAc,EACd,SAAS,GAGV,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,WAAW,EACX,kBAAkB,GAEnB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAA0B,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EACL,SAAS,EACT,cAAc,GAEf,MAAM,yBAAyB,CAAC;AA+BjC,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,YAAY,GACb,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSE parsing now lives in the shared `@introspection-sdk/http` core so
|
|
3
|
+
* the browser and Node SDKs stay byte-for-byte identical. Re-exported
|
|
4
|
+
* here to keep the existing `./sse.js` import path stable.
|
|
5
|
+
*/
|
|
6
|
+
export { parseSse } from "@introspection-sdk/http";
|
|
7
|
+
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/api/sse.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/api/sse.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSE parsing now lives in the shared `@introspection-sdk/http` core so
|
|
3
|
+
* the browser and Node SDKs stay byte-for-byte identical. Re-exported
|
|
4
|
+
* here to keep the existing `./sse.js` import path stable.
|
|
5
|
+
*/
|
|
6
|
+
export { parseSse } from "@introspection-sdk/http";
|
|
7
|
+
//# sourceMappingURL=sse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/api/sse.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { RunIdentityInput, SseEvent, Task, TaskCancelResponse, TaskCreateResponse, TaskListParams, TaskRun, TaskRunCreateParams, TaskUpdateParams, TaskVisibility } from "@introspection-sdk/types";
|
|
2
|
+
import { Paginator } from "@introspection-sdk/http";
|
|
3
|
+
import { BrowserHttpClient } from "./http.js";
|
|
4
|
+
/**
|
|
5
|
+
* Body for creating a task directly against the DP from the browser.
|
|
6
|
+
*
|
|
7
|
+
* A browser caller has no pre-pinned `Runner`, so — unlike the Node
|
|
8
|
+
* SDK's runner-bound create — it selects the agent itself: pass
|
|
9
|
+
* `runtime_id` to pin a recipe runtime, or `agent_name` to fall back to
|
|
10
|
+
* a named recipe agent. `identity` is a convenience that is folded into
|
|
11
|
+
* `metadata.identity` for attribution (the DP derives the owning
|
|
12
|
+
* `identity_key` from the session's JWT claims, never from this body).
|
|
13
|
+
*/
|
|
14
|
+
export interface CreateTaskParams {
|
|
15
|
+
prompt?: string;
|
|
16
|
+
/** Pin the task to a specific recipe runtime. */
|
|
17
|
+
runtime_id?: string;
|
|
18
|
+
/** Named recipe agent, when no `runtime_id` is pinned. */
|
|
19
|
+
agent_name?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
visibility?: TaskVisibility;
|
|
23
|
+
/**
|
|
24
|
+
* Override the interactive idle window (seconds) before the sandbox is
|
|
25
|
+
* torn down. `0` tears down as soon as it's provisioned; omit to use the
|
|
26
|
+
* deployment default. Clamped to the task timeout.
|
|
27
|
+
*/
|
|
28
|
+
idle_timeout_seconds?: number;
|
|
29
|
+
/** Caller identity for attribution; merged into `metadata.identity`. */
|
|
30
|
+
identity?: RunIdentityInput;
|
|
31
|
+
}
|
|
32
|
+
export interface StartTaskParams extends CreateTaskParams {
|
|
33
|
+
/** Required for the `start()` sugar that returns a run handle. */
|
|
34
|
+
prompt: string;
|
|
35
|
+
}
|
|
36
|
+
/** Live handle on a task's run: stream its events, collect text, cancel. */
|
|
37
|
+
export declare class RunHandle {
|
|
38
|
+
readonly task: Task | null;
|
|
39
|
+
readonly run: TaskRun;
|
|
40
|
+
private readonly runs;
|
|
41
|
+
constructor(task: Task | null, run: TaskRun, runs: TaskRunsClient);
|
|
42
|
+
stream(): AsyncIterable<SseEvent>;
|
|
43
|
+
cancel(): Promise<TaskCancelResponse>;
|
|
44
|
+
/** Convenience: concatenate `data` from `text`/`message` SSE frames. */
|
|
45
|
+
text(): Promise<string>;
|
|
46
|
+
}
|
|
47
|
+
export declare class TaskRunsClient {
|
|
48
|
+
private readonly http;
|
|
49
|
+
constructor(http: BrowserHttpClient);
|
|
50
|
+
create(taskId: string, body: TaskRunCreateParams): Promise<RunHandle>;
|
|
51
|
+
get(taskId: string, runId: string): Promise<TaskRun>;
|
|
52
|
+
cancel(taskId: string, runId: string): Promise<TaskCancelResponse>;
|
|
53
|
+
stream(taskId: string, runId: string): AsyncIterable<SseEvent>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Cookie-authenticated `/v1/tasks` client. Mirrors the Node SDK's
|
|
57
|
+
* `TasksApi` shape but is bound to a DP session cookie rather than a
|
|
58
|
+
* bearer token, and lets the caller select the agent on create.
|
|
59
|
+
*/
|
|
60
|
+
export declare class TasksClient {
|
|
61
|
+
private readonly http;
|
|
62
|
+
readonly runs: TaskRunsClient;
|
|
63
|
+
constructor(http: BrowserHttpClient);
|
|
64
|
+
/**
|
|
65
|
+
* Tasks matching `params`. `await` it for the first page (preserving
|
|
66
|
+
* the wire envelope's counts + `next` cursor), or `for await` it to
|
|
67
|
+
* stream every task across pages (fetched lazily — `limit` sets the
|
|
68
|
+
* page size, `next` the starting cursor; stop early to stop fetching).
|
|
69
|
+
*
|
|
70
|
+
* Mirrors the Node SDK's `TasksApi.list`, which is the source of truth
|
|
71
|
+
* for the `/v1/tasks` shape.
|
|
72
|
+
*/
|
|
73
|
+
list(params?: TaskListParams): Paginator<Task>;
|
|
74
|
+
create(body: CreateTaskParams): Promise<TaskCreateResponse>;
|
|
75
|
+
get(taskId: string): Promise<Task>;
|
|
76
|
+
update(taskId: string, body: TaskUpdateParams): Promise<Task>;
|
|
77
|
+
delete(taskId: string): Promise<void>;
|
|
78
|
+
archive(taskId: string): Promise<void>;
|
|
79
|
+
unarchive(taskId: string): Promise<void>;
|
|
80
|
+
/** Sugar: create a task + return a handle on its initial run. */
|
|
81
|
+
start(params: StartTaskParams): Promise<RunHandle>;
|
|
82
|
+
}
|
|
83
|
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IAC3D,KAAK,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC;CAIzD"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { cursorPaginate } from "@introspection-sdk/http";
|
|
2
|
+
import { parseSse } from "./sse.js";
|
|
3
|
+
function toTaskBody(params) {
|
|
4
|
+
const { identity, metadata, ...rest } = params;
|
|
5
|
+
const body = { ...rest };
|
|
6
|
+
const mergedMetadata = identity
|
|
7
|
+
? { ...(metadata ?? {}), identity }
|
|
8
|
+
: metadata;
|
|
9
|
+
if (mergedMetadata !== undefined)
|
|
10
|
+
body.metadata = mergedMetadata;
|
|
11
|
+
return body;
|
|
12
|
+
}
|
|
13
|
+
/** Live handle on a task's run: stream its events, collect text, cancel. */
|
|
14
|
+
export class RunHandle {
|
|
15
|
+
task;
|
|
16
|
+
run;
|
|
17
|
+
runs;
|
|
18
|
+
constructor(task, run, runs) {
|
|
19
|
+
this.task = task;
|
|
20
|
+
this.run = run;
|
|
21
|
+
this.runs = runs;
|
|
22
|
+
}
|
|
23
|
+
stream() {
|
|
24
|
+
return this.runs.stream(this.run.task_id, this.run.id);
|
|
25
|
+
}
|
|
26
|
+
cancel() {
|
|
27
|
+
return this.runs.cancel(this.run.task_id, this.run.id);
|
|
28
|
+
}
|
|
29
|
+
/** Convenience: concatenate `data` from `text`/`message` SSE frames. */
|
|
30
|
+
async text() {
|
|
31
|
+
let out = "";
|
|
32
|
+
for await (const ev of this.stream()) {
|
|
33
|
+
if (ev.event === "text" || ev.event === "message")
|
|
34
|
+
out += ev.data;
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class TaskRunsClient {
|
|
40
|
+
http;
|
|
41
|
+
constructor(http) {
|
|
42
|
+
this.http = http;
|
|
43
|
+
}
|
|
44
|
+
async create(taskId, body) {
|
|
45
|
+
const res = await this.http.request({
|
|
46
|
+
method: "POST",
|
|
47
|
+
path: `/v1/tasks/${encodeURIComponent(taskId)}/runs`,
|
|
48
|
+
body,
|
|
49
|
+
});
|
|
50
|
+
return new RunHandle(null, res.run, this);
|
|
51
|
+
}
|
|
52
|
+
get(taskId, runId) {
|
|
53
|
+
return this.http.request({
|
|
54
|
+
method: "GET",
|
|
55
|
+
path: `/v1/tasks/${encodeURIComponent(taskId)}/runs/${encodeURIComponent(runId)}`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
cancel(taskId, runId) {
|
|
59
|
+
return this.http.request({
|
|
60
|
+
method: "POST",
|
|
61
|
+
path: `/v1/tasks/${encodeURIComponent(taskId)}/runs/${encodeURIComponent(runId)}/cancel`,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async *stream(taskId, runId) {
|
|
65
|
+
const res = await this.http.stream({
|
|
66
|
+
path: `/v1/tasks/${encodeURIComponent(taskId)}/runs/${encodeURIComponent(runId)}/stream`,
|
|
67
|
+
});
|
|
68
|
+
yield* parseSse(res);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Cookie-authenticated `/v1/tasks` client. Mirrors the Node SDK's
|
|
73
|
+
* `TasksApi` shape but is bound to a DP session cookie rather than a
|
|
74
|
+
* bearer token, and lets the caller select the agent on create.
|
|
75
|
+
*/
|
|
76
|
+
export class TasksClient {
|
|
77
|
+
http;
|
|
78
|
+
runs;
|
|
79
|
+
constructor(http) {
|
|
80
|
+
this.http = http;
|
|
81
|
+
this.runs = new TaskRunsClient(http);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Tasks matching `params`. `await` it for the first page (preserving
|
|
85
|
+
* the wire envelope's counts + `next` cursor), or `for await` it to
|
|
86
|
+
* stream every task across pages (fetched lazily — `limit` sets the
|
|
87
|
+
* page size, `next` the starting cursor; stop early to stop fetching).
|
|
88
|
+
*
|
|
89
|
+
* Mirrors the Node SDK's `TasksApi.list`, which is the source of truth
|
|
90
|
+
* for the `/v1/tasks` shape.
|
|
91
|
+
*/
|
|
92
|
+
list(params) {
|
|
93
|
+
return cursorPaginate((next) => this.http.request({
|
|
94
|
+
method: "GET",
|
|
95
|
+
path: "/v1/tasks",
|
|
96
|
+
query: { ...params, next },
|
|
97
|
+
}), params?.next);
|
|
98
|
+
}
|
|
99
|
+
create(body) {
|
|
100
|
+
return this.http.request({
|
|
101
|
+
method: "POST",
|
|
102
|
+
path: "/v1/tasks",
|
|
103
|
+
body: toTaskBody(body),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
get(taskId) {
|
|
107
|
+
return this.http.request({
|
|
108
|
+
method: "GET",
|
|
109
|
+
path: `/v1/tasks/${encodeURIComponent(taskId)}`,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
update(taskId, body) {
|
|
113
|
+
return this.http.request({
|
|
114
|
+
method: "PATCH",
|
|
115
|
+
path: `/v1/tasks/${encodeURIComponent(taskId)}`,
|
|
116
|
+
body,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
delete(taskId) {
|
|
120
|
+
return this.http.request({
|
|
121
|
+
method: "DELETE",
|
|
122
|
+
path: `/v1/tasks/${encodeURIComponent(taskId)}`,
|
|
123
|
+
expect: "empty",
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
archive(taskId) {
|
|
127
|
+
return this.http.request({
|
|
128
|
+
method: "POST",
|
|
129
|
+
path: `/v1/tasks/${encodeURIComponent(taskId)}/archive`,
|
|
130
|
+
expect: "empty",
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
unarchive(taskId) {
|
|
134
|
+
return this.http.request({
|
|
135
|
+
method: "POST",
|
|
136
|
+
path: `/v1/tasks/${encodeURIComponent(taskId)}/unarchive`,
|
|
137
|
+
expect: "empty",
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/** Sugar: create a task + return a handle on its initial run. */
|
|
141
|
+
async start(params) {
|
|
142
|
+
const res = await this.create(params);
|
|
143
|
+
return new RunHandle(res.task, res.run, this.run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AC,MAAM,CAAC,EAAE;YAC/C,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,MAAc;QACnB,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAO;YAC7B,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,aAAa,kBAAkB,CAAC,MAAM,CAAC,EAAE;YAC/C,MAAM,EAAE,OAAO;SAChB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,MAAc;QACpB,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAO;YAC7B,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,aAAa,kBAAkB,CAAC,MAAM,CAAC,UAAU;YACvD,MAAM,EAAE,OAAO;SAChB,CAAC,CAAC;IACL,CAAC;IAED,SAAS,CAAC,MAAc;QACtB,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAO;YAC7B,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,aAAa,kBAAkB,CAAC,MAAM,CAAC,YAAY;YACzD,MAAM,EAAE,OAAO;SAChB,CAAC,CAAC;IACL,CAAC;IAED,iEAAiE;IACjE,KAAK,CAAC,KAAK,CAAC,MAAuB;QACjC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACtC,OAAO,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@introspection-sdk/introspection-browser",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Introspection observability SDK for the browser",
|
|
6
6
|
"engines": {
|
|
@@ -13,10 +13,14 @@
|
|
|
13
13
|
".": {
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./api": {
|
|
18
|
+
"types": "./dist/api/index.d.ts",
|
|
19
|
+
"default": "./dist/api/index.js"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
19
|
-
"@types/node": "^22.19.
|
|
23
|
+
"@types/node": "^22.19.21",
|
|
20
24
|
"eslint": "^9.39.4",
|
|
21
25
|
"typescript": "5.9.3",
|
|
22
26
|
"@repo/eslint-config": "0.0.0",
|
|
@@ -24,10 +28,11 @@
|
|
|
24
28
|
},
|
|
25
29
|
"dependencies": {
|
|
26
30
|
"@opentelemetry/api": "^1.9.1",
|
|
27
|
-
"@opentelemetry/api-logs": "^0.
|
|
28
|
-
"@opentelemetry/sdk-logs": "^0.
|
|
29
|
-
"@opentelemetry/exporter-logs-otlp-http": "^0.
|
|
30
|
-
"@introspection-sdk/types": "0.5.
|
|
31
|
+
"@opentelemetry/api-logs": "^0.219.0",
|
|
32
|
+
"@opentelemetry/sdk-logs": "^0.219.0",
|
|
33
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.219.0",
|
|
34
|
+
"@introspection-sdk/types": "0.5.3",
|
|
35
|
+
"@introspection-sdk/http": "0.5.3"
|
|
31
36
|
},
|
|
32
37
|
"scripts": {
|
|
33
38
|
"lint": "eslint . --max-warnings 0",
|