@introspection-sdk/introspection-node 0.5.4 → 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.
- package/.turbo/turbo-build.log +1 -1
- package/dist/index.d.ts +2 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/resources/runtimes.d.ts +4 -74
- package/dist/resources/runtimes.d.ts.map +1 -1
- package/dist/resources/runtimes.js +5 -171
- package/dist/resources/runtimes.js.map +1 -1
- package/dist/runner.d.ts +1 -4
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +1 -4
- package/dist/runner.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +9 -7
- package/src/resources/runtimes.ts +14 -216
- package/src/runner.ts +6 -4
- package/dist/runner-resources/conversations.d.ts +0 -73
- package/dist/runner-resources/conversations.d.ts.map +0 -1
- package/dist/runner-resources/conversations.js +0 -161
- package/dist/runner-resources/conversations.js.map +0 -1
- package/dist/runner-resources/files.d.ts +0 -45
- package/dist/runner-resources/files.d.ts.map +0 -1
- package/dist/runner-resources/files.js +0 -125
- package/dist/runner-resources/files.js.map +0 -1
- package/dist/runner-resources/shares.d.ts +0 -27
- package/dist/runner-resources/shares.d.ts.map +0 -1
- package/dist/runner-resources/shares.js +0 -50
- package/dist/runner-resources/shares.js.map +0 -1
- package/dist/runner-resources/tasks.d.ts +0 -45
- package/dist/runner-resources/tasks.d.ts.map +0 -1
- package/dist/runner-resources/tasks.js +0 -127
- package/dist/runner-resources/tasks.js.map +0 -1
- package/src/runner-resources/conversations.ts +0 -202
- package/src/runner-resources/files.ts +0 -162
- package/src/runner-resources/shares.ts +0 -62
- package/src/runner-resources/tasks.ts +0 -158
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { cursorPaginate } from "../pagination.js";
|
|
2
|
-
export class FileVersionsApi {
|
|
3
|
-
http;
|
|
4
|
-
constructor(http) {
|
|
5
|
-
this.http = http;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* List versions of a file. `await` the result for the first page, or
|
|
9
|
-
* `for await` it to stream every version across pages (fetched lazily;
|
|
10
|
-
* stop early to stop fetching).
|
|
11
|
-
*/
|
|
12
|
-
list(fileId, params) {
|
|
13
|
-
return cursorPaginate((next) => this.http.request({
|
|
14
|
-
method: "GET",
|
|
15
|
-
path: `/v1/files/${encodeURIComponent(fileId)}/versions`,
|
|
16
|
-
query: { ...params, next },
|
|
17
|
-
}), params?.next);
|
|
18
|
-
}
|
|
19
|
-
get(fileId, versionId) {
|
|
20
|
-
return this.http.request({
|
|
21
|
-
method: "GET",
|
|
22
|
-
path: `/v1/files/${encodeURIComponent(fileId)}/versions/${encodeURIComponent(versionId)}`,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
create(fileId, body) {
|
|
26
|
-
const form = toFormData(body);
|
|
27
|
-
return this.http.request({
|
|
28
|
-
method: "POST",
|
|
29
|
-
path: `/v1/files/${encodeURIComponent(fileId)}/versions`,
|
|
30
|
-
body: form,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
export class FilesApi {
|
|
35
|
-
http;
|
|
36
|
-
versions;
|
|
37
|
-
constructor(http) {
|
|
38
|
-
this.http = http;
|
|
39
|
-
this.versions = new FileVersionsApi(http);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* List files matching `params`. `await` the result for the first page,
|
|
43
|
-
* or `for await` it to stream every file across pages (fetched lazily —
|
|
44
|
-
* `limit` sets the page size, `next` the starting cursor; stop early to
|
|
45
|
-
* stop fetching).
|
|
46
|
-
*/
|
|
47
|
-
list(params) {
|
|
48
|
-
return cursorPaginate((next) => this.http.request({
|
|
49
|
-
method: "GET",
|
|
50
|
-
path: "/v1/files",
|
|
51
|
-
query: { ...params, next },
|
|
52
|
-
}), params?.next);
|
|
53
|
-
}
|
|
54
|
-
upload(body) {
|
|
55
|
-
const form = toFormData(body);
|
|
56
|
-
return this.http.request({
|
|
57
|
-
method: "POST",
|
|
58
|
-
path: "/v1/files",
|
|
59
|
-
body: form,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
createText(body) {
|
|
63
|
-
return this.http.request({
|
|
64
|
-
method: "POST",
|
|
65
|
-
path: "/v1/files",
|
|
66
|
-
body,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
get(fileId) {
|
|
70
|
-
return this.http.request({
|
|
71
|
-
method: "GET",
|
|
72
|
-
path: `/v1/files/${encodeURIComponent(fileId)}`,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
update(fileId, body) {
|
|
76
|
-
return this.http.request({
|
|
77
|
-
method: "PATCH",
|
|
78
|
-
path: `/v1/files/${encodeURIComponent(fileId)}`,
|
|
79
|
-
body,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
delete(fileId) {
|
|
83
|
-
return this.http.request({
|
|
84
|
-
method: "DELETE",
|
|
85
|
-
path: `/v1/files/${encodeURIComponent(fileId)}`,
|
|
86
|
-
expect: "empty",
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
download(fileId) {
|
|
90
|
-
return this.http.request({
|
|
91
|
-
method: "GET",
|
|
92
|
-
path: `/v1/files/${encodeURIComponent(fileId)}/content`,
|
|
93
|
-
expect: "bytes",
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
downloadStream(fileId) {
|
|
97
|
-
return this.http.request({
|
|
98
|
-
method: "GET",
|
|
99
|
-
path: `/v1/files/${encodeURIComponent(fileId)}/content`,
|
|
100
|
-
expect: "stream",
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function toFormData(body) {
|
|
105
|
-
const fd = new FormData();
|
|
106
|
-
if ("file" in body && body.file instanceof Blob) {
|
|
107
|
-
fd.append("file", body.file, body.name);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
// Uint8Array branch — copy into a fresh ArrayBuffer so the Blob
|
|
111
|
-
// constructor sees a concrete ArrayBuffer (not ArrayBufferLike,
|
|
112
|
-
// which TS rejects under nodenext lib).
|
|
113
|
-
const u8 = body.file;
|
|
114
|
-
const ct = body.contentType ??
|
|
115
|
-
"application/octet-stream";
|
|
116
|
-
const ab = u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength);
|
|
117
|
-
fd.append("file", new Blob([ab], { type: ct }), body.name);
|
|
118
|
-
}
|
|
119
|
-
if (body.name)
|
|
120
|
-
fd.append("name", body.name);
|
|
121
|
-
if (body.file_type)
|
|
122
|
-
fd.append("file_type", body.file_type);
|
|
123
|
-
return fd;
|
|
124
|
-
}
|
|
125
|
-
//# sourceMappingURL=files.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/runner-resources/files.ts"],"names":[],"mappings":"AAUA,OAAO,EAAa,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAW7D,MAAM,OAAO,eAAe;IACG;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD;;;;OAIG;IACH,IAAI,CAAC,MAAc,EAAE,MAAmB;QACtC,OAAO,cAAc,CACnB,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,IAAI,CAAC,OAAO,CAA0B;YACzC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,aAAa,kBAAkB,CAAC,MAAM,CAAC,WAAW;YACxD,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,IAAI,EAA6B;SACtD,CAAC,EACJ,MAAM,EAAE,IAAI,CACb,CAAC;IACJ,CAAC;IAED,GAAG,CAAC,MAAc,EAAE,SAAiB;QACnC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAe;YACrC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,aAAa,kBAAkB,CAAC,MAAM,CAAC,aAAa,kBAAkB,CAAC,SAAS,CAAC,EAAE;SAC1F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gE;QAChE,gEAAgE;QAChE,wCAAwC;QACxC,MAAM,EAAE,GAAI,IAA6B,CAAC,IAAI,CAAC;QAC/C,MAAM,EAAE,GACL,IAAiC,CAAC,WAAW;YAC9C,0BAA0B,CAAC;QAC7B,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CACxB,EAAE,CAAC,UAAU,EACb,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,UAAU,CACf,CAAC;QACjB,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,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,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ResourceShare, ShareCreateParams, ShareListParams } from "@introspection-sdk/types";
|
|
2
|
-
import { HttpClient } from "../http.js";
|
|
3
|
-
import { Paginator } from "../pagination.js";
|
|
4
|
-
/**
|
|
5
|
-
* Runner-bound Resource Shares API (`/v1/shares`).
|
|
6
|
-
*
|
|
7
|
-
* Read-sharing grants for files and conversations: `create` / `list` / `get` /
|
|
8
|
-
* `delete` (revoke). A grant carries a `url` (with the `?share_id` capability)
|
|
9
|
-
* for reading the shared resource. To fork a new task from a shared
|
|
10
|
-
* conversation, pass `fork_share_id` to `runner.tasks.create(...)`.
|
|
11
|
-
*/
|
|
12
|
-
export declare class SharesApi {
|
|
13
|
-
private readonly http;
|
|
14
|
-
constructor(http: HttpClient);
|
|
15
|
-
/**
|
|
16
|
-
* List grants the caller created or that target them. `await` for the first
|
|
17
|
-
* page, or `for await` to stream every grant across pages.
|
|
18
|
-
*/
|
|
19
|
-
list(params?: ShareListParams): Paginator<ResourceShare>;
|
|
20
|
-
/** Create a read-sharing grant. The caller must own the target resource. */
|
|
21
|
-
create(body: ShareCreateParams): Promise<ResourceShare>;
|
|
22
|
-
/** Read a single grant (carries the `url` to the shared resource). */
|
|
23
|
-
get(shareId: string): Promise<ResourceShare>;
|
|
24
|
-
/** Revoke a grant. Only the grantor (or an admin/owner) may revoke. */
|
|
25
|
-
delete(shareId: string): Promise<void>;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=shares.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shares.d.ts","sourceRoot":"","sources":["../../src/runner-resources/shares.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,aAAa,EACb,iBAAiB,EACjB,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,SAAS,EAAkB,MAAM,kBAAkB,CAAC;AAE7D;;;;;;;GAOG;AACH,qBAAa,SAAS;IACR,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;;OAGG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,aAAa,CAAC;IAYxD,4EAA4E;IAC5E,MAAM,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC;IAQvD,sEAAsE;IACtE,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAO5C,uEAAuE;IACvE,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOvC"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { cursorPaginate } from "../pagination.js";
|
|
2
|
-
/**
|
|
3
|
-
* Runner-bound Resource Shares API (`/v1/shares`).
|
|
4
|
-
*
|
|
5
|
-
* Read-sharing grants for files and conversations: `create` / `list` / `get` /
|
|
6
|
-
* `delete` (revoke). A grant carries a `url` (with the `?share_id` capability)
|
|
7
|
-
* for reading the shared resource. To fork a new task from a shared
|
|
8
|
-
* conversation, pass `fork_share_id` to `runner.tasks.create(...)`.
|
|
9
|
-
*/
|
|
10
|
-
export class SharesApi {
|
|
11
|
-
http;
|
|
12
|
-
constructor(http) {
|
|
13
|
-
this.http = http;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* List grants the caller created or that target them. `await` for the first
|
|
17
|
-
* page, or `for await` to stream every grant across pages.
|
|
18
|
-
*/
|
|
19
|
-
list(params) {
|
|
20
|
-
return cursorPaginate((next) => this.http.request({
|
|
21
|
-
method: "GET",
|
|
22
|
-
path: "/v1/shares",
|
|
23
|
-
query: { ...params, next },
|
|
24
|
-
}), params?.next);
|
|
25
|
-
}
|
|
26
|
-
/** Create a read-sharing grant. The caller must own the target resource. */
|
|
27
|
-
create(body) {
|
|
28
|
-
return this.http.request({
|
|
29
|
-
method: "POST",
|
|
30
|
-
path: "/v1/shares",
|
|
31
|
-
body,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
/** Read a single grant (carries the `url` to the shared resource). */
|
|
35
|
-
get(shareId) {
|
|
36
|
-
return this.http.request({
|
|
37
|
-
method: "GET",
|
|
38
|
-
path: `/v1/shares/${encodeURIComponent(shareId)}`,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
/** Revoke a grant. Only the grantor (or an admin/owner) may revoke. */
|
|
42
|
-
delete(shareId) {
|
|
43
|
-
return this.http.request({
|
|
44
|
-
method: "DELETE",
|
|
45
|
-
path: `/v1/shares/${encodeURIComponent(shareId)}`,
|
|
46
|
-
expect: "empty",
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=shares.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shares.js","sourceRoot":"","sources":["../../src/runner-resources/shares.ts"],"names":[],"mappings":"AAOA,OAAO,EAAa,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,OAAO,SAAS;IACS;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD;;;OAGG;IACH,IAAI,CAAC,MAAwB;QAC3B,OAAO,cAAc,CACnB,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,IAAI,CAAC,OAAO,CAA2B;YAC1C,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,IAAI,EAA6B;SACtD,CAAC,EACJ,MAAM,EAAE,IAAI,CACb,CAAC;IACJ,CAAC;IAED,4EAA4E;IAC5E,MAAM,CAAC,IAAuB;QAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAgB;YACtC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,YAAY;YAClB,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IAED,sEAAsE;IACtE,GAAG,CAAC,OAAe;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAgB;YACtC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,cAAc,kBAAkB,CAAC,OAAO,CAAC,EAAE;SAClD,CAAC,CAAC;IACL,CAAC;IAED,uEAAuE;IACvE,MAAM,CAAC,OAAe;QACpB,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAO;YAC7B,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,cAAc,kBAAkB,CAAC,OAAO,CAAC,EAAE;YACjD,MAAM,EAAE,OAAO;SAChB,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { SseEvent, Task, TaskCancelResponse, TaskCreateParams, TaskCreateResponse, TaskListParams, TaskRun, TaskRunCreateParams, TaskUpdateParams } from "@introspection-sdk/types";
|
|
2
|
-
import { HttpClient } from "../http.js";
|
|
3
|
-
import { Paginator } from "../pagination.js";
|
|
4
|
-
export interface StartParams extends TaskCreateParams {
|
|
5
|
-
prompt: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class RunHandle {
|
|
8
|
-
readonly task: Task | null;
|
|
9
|
-
readonly run: TaskRun;
|
|
10
|
-
private readonly runs;
|
|
11
|
-
constructor(task: Task | null, run: TaskRun, runs: TaskRunsApi);
|
|
12
|
-
stream(): AsyncIterable<SseEvent>;
|
|
13
|
-
cancel(): Promise<TaskCancelResponse>;
|
|
14
|
-
/** Convenience: collect `data` from `event: text`-style frames into a string. */
|
|
15
|
-
text(): Promise<string>;
|
|
16
|
-
}
|
|
17
|
-
export declare class TaskRunsApi {
|
|
18
|
-
private readonly http;
|
|
19
|
-
constructor(http: HttpClient);
|
|
20
|
-
create(taskId: string, body: TaskRunCreateParams): Promise<RunHandle>;
|
|
21
|
-
get(taskId: string, runId: string): Promise<TaskRun>;
|
|
22
|
-
cancel(taskId: string, runId: string): Promise<TaskCancelResponse>;
|
|
23
|
-
stream(taskId: string, runId: string): AsyncIterable<SseEvent>;
|
|
24
|
-
}
|
|
25
|
-
export declare class TasksApi {
|
|
26
|
-
private readonly http;
|
|
27
|
-
readonly runs: TaskRunsApi;
|
|
28
|
-
constructor(http: HttpClient);
|
|
29
|
-
/**
|
|
30
|
-
* List tasks matching `params`. `await` the result for the first page,
|
|
31
|
-
* or `for await` it to stream every task across pages (fetched lazily —
|
|
32
|
-
* `limit` sets the page size, `next` the starting cursor; stop early to
|
|
33
|
-
* stop fetching).
|
|
34
|
-
*/
|
|
35
|
-
list(params?: TaskListParams): Paginator<Task>;
|
|
36
|
-
create(body: TaskCreateParams): Promise<TaskCreateResponse>;
|
|
37
|
-
get(taskId: string): Promise<Task>;
|
|
38
|
-
update(taskId: string, body: TaskUpdateParams): Promise<Task>;
|
|
39
|
-
delete(taskId: string): Promise<void>;
|
|
40
|
-
archive(taskId: string): Promise<void>;
|
|
41
|
-
unarchive(taskId: string): Promise<void>;
|
|
42
|
-
/** Cursor-style sugar: create a task + return a handle on its initial run. */
|
|
43
|
-
start(params: StartParams): Promise<RunHandle>;
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=tasks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../../src/runner-resources/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,QAAQ,EACR,IAAI,EACJ,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,OAAO,EACP,mBAAmB,EAEnB,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,SAAS,EAAkB,MAAM,kBAAkB,CAAC;AAG7D,MAAM,WAAW,WAAY,SAAQ,gBAAgB;IACnD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,SAAS;aAEF,IAAI,EAAE,IAAI,GAAG,IAAI;aACjB,GAAG,EAAE,OAAO;IAC5B,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAFL,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,GAAG,EAAE,OAAO,EACX,IAAI,EAAE,WAAW;IAGpC,MAAM,IAAI,aAAa,CAAC,QAAQ,CAAC;IAIjC,MAAM,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAIrC,iFAAiF;IAC3E,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;CAO9B;AAED,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEvC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,SAAS,CAAC;IAS3E,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOpD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAO3D,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC;CAMtE;AAED,qBAAa,QAAQ;IAGP,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;gBAEE,IAAI,EAAE,UAAU;IAI7C;;;;;OAKG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC,IAAI,CAAC;IAY9C,MAAM,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAQ3D,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOlC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQtC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQxC,8EAA8E;IACxE,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC;CAIrD"}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { cursorPaginate } from "../pagination.js";
|
|
2
|
-
import { parseSse } from "../streaming.js";
|
|
3
|
-
export class RunHandle {
|
|
4
|
-
task;
|
|
5
|
-
run;
|
|
6
|
-
runs;
|
|
7
|
-
constructor(task, run, runs) {
|
|
8
|
-
this.task = task;
|
|
9
|
-
this.run = run;
|
|
10
|
-
this.runs = runs;
|
|
11
|
-
}
|
|
12
|
-
stream() {
|
|
13
|
-
return this.runs.stream(this.run.task_id, this.run.id);
|
|
14
|
-
}
|
|
15
|
-
cancel() {
|
|
16
|
-
return this.runs.cancel(this.run.task_id, this.run.id);
|
|
17
|
-
}
|
|
18
|
-
/** Convenience: collect `data` from `event: text`-style frames into a string. */
|
|
19
|
-
async text() {
|
|
20
|
-
let out = "";
|
|
21
|
-
for await (const ev of this.stream()) {
|
|
22
|
-
if (ev.event === "text" || ev.event === "message")
|
|
23
|
-
out += ev.data;
|
|
24
|
-
}
|
|
25
|
-
return out;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export class TaskRunsApi {
|
|
29
|
-
http;
|
|
30
|
-
constructor(http) {
|
|
31
|
-
this.http = http;
|
|
32
|
-
}
|
|
33
|
-
async create(taskId, body) {
|
|
34
|
-
const res = await this.http.request({
|
|
35
|
-
method: "POST",
|
|
36
|
-
path: `/v1/tasks/${encodeURIComponent(taskId)}/runs`,
|
|
37
|
-
body,
|
|
38
|
-
});
|
|
39
|
-
return new RunHandle(null, res.run, this);
|
|
40
|
-
}
|
|
41
|
-
get(taskId, runId) {
|
|
42
|
-
return this.http.request({
|
|
43
|
-
method: "GET",
|
|
44
|
-
path: `/v1/tasks/${encodeURIComponent(taskId)}/runs/${encodeURIComponent(runId)}`,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
cancel(taskId, runId) {
|
|
48
|
-
return this.http.request({
|
|
49
|
-
method: "POST",
|
|
50
|
-
path: `/v1/tasks/${encodeURIComponent(taskId)}/runs/${encodeURIComponent(runId)}/cancel`,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
async *stream(taskId, runId) {
|
|
54
|
-
const res = await this.http.stream({
|
|
55
|
-
path: `/v1/tasks/${encodeURIComponent(taskId)}/runs/${encodeURIComponent(runId)}/stream`,
|
|
56
|
-
});
|
|
57
|
-
yield* parseSse(res);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export class TasksApi {
|
|
61
|
-
http;
|
|
62
|
-
runs;
|
|
63
|
-
constructor(http) {
|
|
64
|
-
this.http = http;
|
|
65
|
-
this.runs = new TaskRunsApi(http);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* List tasks matching `params`. `await` the result for the first page,
|
|
69
|
-
* or `for await` it to stream every task across pages (fetched lazily —
|
|
70
|
-
* `limit` sets the page size, `next` the starting cursor; stop early to
|
|
71
|
-
* stop fetching).
|
|
72
|
-
*/
|
|
73
|
-
list(params) {
|
|
74
|
-
return cursorPaginate((next) => this.http.request({
|
|
75
|
-
method: "GET",
|
|
76
|
-
path: "/v1/tasks",
|
|
77
|
-
query: { ...params, next },
|
|
78
|
-
}), params?.next);
|
|
79
|
-
}
|
|
80
|
-
create(body) {
|
|
81
|
-
return this.http.request({
|
|
82
|
-
method: "POST",
|
|
83
|
-
path: "/v1/tasks",
|
|
84
|
-
body,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
get(taskId) {
|
|
88
|
-
return this.http.request({
|
|
89
|
-
method: "GET",
|
|
90
|
-
path: `/v1/tasks/${encodeURIComponent(taskId)}`,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
update(taskId, body) {
|
|
94
|
-
return this.http.request({
|
|
95
|
-
method: "PATCH",
|
|
96
|
-
path: `/v1/tasks/${encodeURIComponent(taskId)}`,
|
|
97
|
-
body,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
delete(taskId) {
|
|
101
|
-
return this.http.request({
|
|
102
|
-
method: "DELETE",
|
|
103
|
-
path: `/v1/tasks/${encodeURIComponent(taskId)}`,
|
|
104
|
-
expect: "empty",
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
archive(taskId) {
|
|
108
|
-
return this.http.request({
|
|
109
|
-
method: "POST",
|
|
110
|
-
path: `/v1/tasks/${encodeURIComponent(taskId)}/archive`,
|
|
111
|
-
expect: "empty",
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
unarchive(taskId) {
|
|
115
|
-
return this.http.request({
|
|
116
|
-
method: "POST",
|
|
117
|
-
path: `/v1/tasks/${encodeURIComponent(taskId)}/unarchive`,
|
|
118
|
-
expect: "empty",
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/** Cursor-style sugar: create a task + return a handle on its initial run. */
|
|
122
|
-
async start(params) {
|
|
123
|
-
const res = await this.create(params);
|
|
124
|
-
return new RunHandle(res.task, res.run, this.runs);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
//# sourceMappingURL=tasks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../src/runner-resources/tasks.ts"],"names":[],"mappings":"AAcA,OAAO,EAAa,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAM3C,MAAM,OAAO,SAAS;IAEF;IACA;IACC;IAHnB,YACkB,IAAiB,EACjB,GAAY,EACX,IAAiB;QAFlB,SAAI,GAAJ,IAAI,CAAa;QACjB,QAAG,GAAH,GAAG,CAAS;QACX,SAAI,GAAJ,IAAI,CAAa;IACjC,CAAC;IAEJ,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACzD,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACzD,CAAC;IAED,iFAAiF;IACjF,KAAK,CAAC,IAAI;QACR,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,IAAI,KAAK,EAAE,MAAM,EAAE,IAAI,IAAI,CAAC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,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,8EAA8E;IAC9E,KAAK,CAAC,KAAK,CAAC,MAAmB;QAC7B,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"}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ConversationItem,
|
|
3
|
-
ConversationItemInclude,
|
|
4
|
-
ConversationItemList,
|
|
5
|
-
ConversationItemListParams,
|
|
6
|
-
ConversationListParams,
|
|
7
|
-
ConversationResponse,
|
|
8
|
-
ConversationSummary,
|
|
9
|
-
MessagePart,
|
|
10
|
-
Paginated,
|
|
11
|
-
ToolCallResponsePart,
|
|
12
|
-
} from "@introspection-sdk/types";
|
|
13
|
-
import { HttpClient } from "../http.js";
|
|
14
|
-
import { Paginator, cursorPaginate } from "../pagination.js";
|
|
15
|
-
|
|
16
|
-
/** Includes requested when building a {@link ConversationResponse}. */
|
|
17
|
-
const RESPONSE_INCLUDES: ConversationItemInclude[] = [
|
|
18
|
-
"gen_ai.input.messages",
|
|
19
|
-
"gen_ai.system_instructions",
|
|
20
|
-
"gen_ai.tool.definitions",
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Items of a conversation (`/v1/conversations/{id}/items`). Read-only.
|
|
25
|
-
*
|
|
26
|
-
* Paging is OpenAI-style underneath: the envelope has NO `next` token —
|
|
27
|
-
* `list()` drives `after` = the previous page's `last_id` while
|
|
28
|
-
* `has_more` is true.
|
|
29
|
-
*/
|
|
30
|
-
export class ConversationItemsApi {
|
|
31
|
-
constructor(private readonly http: HttpClient) {}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* List items of a conversation. `await` the result for the first page
|
|
35
|
-
* (an OpenAI-style {@link ConversationItemList} envelope), or
|
|
36
|
-
* `for await` it to stream every item across pages (fetched lazily —
|
|
37
|
-
* `limit` sets the page size, `after` the starting cursor; stop early to
|
|
38
|
-
* stop fetching). Pass `order: "asc"` to walk the transcript from the
|
|
39
|
-
* start.
|
|
40
|
-
*
|
|
41
|
-
* Items carry the turn-local delta in `input_messages` — only the
|
|
42
|
-
* messages new to that turn. Use `get()` for the full input history.
|
|
43
|
-
*/
|
|
44
|
-
list(
|
|
45
|
-
conversationId: string,
|
|
46
|
-
params?: ConversationItemListParams,
|
|
47
|
-
): Paginator<ConversationItem, ConversationItemList> {
|
|
48
|
-
return new Paginator(
|
|
49
|
-
{
|
|
50
|
-
fetch: (after) =>
|
|
51
|
-
this.http.request<ConversationItemList>({
|
|
52
|
-
method: "GET",
|
|
53
|
-
path: `/v1/conversations/${encodeURIComponent(conversationId)}/items`,
|
|
54
|
-
query: { ...params, after } as Record<string, unknown>,
|
|
55
|
-
}),
|
|
56
|
-
items: (page) => page.data,
|
|
57
|
-
next: (page) =>
|
|
58
|
-
page.has_more && page.last_id !== null ? page.last_id : undefined,
|
|
59
|
-
},
|
|
60
|
-
params?.after,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Fetch a single conversation item. Unlike the list route, the
|
|
66
|
-
* detail's `input_messages` is the FULL input history for that span.
|
|
67
|
-
*/
|
|
68
|
-
get(
|
|
69
|
-
conversationId: string,
|
|
70
|
-
itemId: string,
|
|
71
|
-
params?: { include?: ConversationItemInclude[] },
|
|
72
|
-
): Promise<ConversationItem> {
|
|
73
|
-
return this.http.request<ConversationItem>({
|
|
74
|
-
method: "GET",
|
|
75
|
-
path: `/v1/conversations/${encodeURIComponent(conversationId)}/items/${encodeURIComponent(itemId)}`,
|
|
76
|
-
query: params as Record<string, unknown> | undefined,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Read-only Conversations API (`/v1/conversations`).
|
|
83
|
-
*
|
|
84
|
-
* Both `list()` and `items.list()` are auto-paging async generators,
|
|
85
|
-
* but they drive different wire protocols underneath: `list()` walks
|
|
86
|
-
* the standard Introspection cursor envelope's opaque `next` token,
|
|
87
|
-
* while `items.list()` walks an OpenAI-style envelope via `after` =
|
|
88
|
-
* the previous page's `last_id` while `has_more` is true.
|
|
89
|
-
*/
|
|
90
|
-
export class ConversationsApi {
|
|
91
|
-
/** Items of a conversation — `conversations.items.list(...)` etc. */
|
|
92
|
-
readonly items: ConversationItemsApi;
|
|
93
|
-
|
|
94
|
-
constructor(private readonly http: HttpClient) {
|
|
95
|
-
this.items = new ConversationItemsApi(http);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* List conversation summaries matching `params`. `await` the result for
|
|
100
|
-
* the first page, or `for await` it to stream every summary across
|
|
101
|
-
* pages (fetched lazily — `limit` sets the page size, `next` the
|
|
102
|
-
* starting cursor; stop early to stop fetching).
|
|
103
|
-
*/
|
|
104
|
-
list(params?: ConversationListParams): Paginator<ConversationSummary> {
|
|
105
|
-
return cursorPaginate(
|
|
106
|
-
(next) =>
|
|
107
|
-
this.http.request<Paginated<ConversationSummary>>({
|
|
108
|
-
method: "GET",
|
|
109
|
-
path: "/v1/conversations",
|
|
110
|
-
query: { ...params, next } as Record<string, unknown>,
|
|
111
|
-
}),
|
|
112
|
-
params?.next,
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Responses-API-style retrieve: load the state of a conversation as of
|
|
118
|
-
* one item — the full input history, output, system instructions, and
|
|
119
|
-
* tool definitions of that turn.
|
|
120
|
-
*
|
|
121
|
-
* When `itemId` is omitted, the latest LLM turn is used: the first
|
|
122
|
-
* item (in descending order) whose `node_type` is `"assistant"` or
|
|
123
|
-
* whose `operation_name` is `"chat"`, falling back to the first item
|
|
124
|
-
* with a non-null `output_message`. Returns `null` when the
|
|
125
|
-
* conversation has no items.
|
|
126
|
-
*
|
|
127
|
-
* For the full per-turn transcript instead, iterate
|
|
128
|
-
* `items.list(conversationId, { order: "asc" })`.
|
|
129
|
-
*/
|
|
130
|
-
async retrieve(
|
|
131
|
-
conversationId: string,
|
|
132
|
-
itemId?: string,
|
|
133
|
-
): Promise<ConversationResponse | null> {
|
|
134
|
-
const targetId = itemId ?? (await this.findLatestTurnId(conversationId));
|
|
135
|
-
if (targetId === null) return null;
|
|
136
|
-
|
|
137
|
-
const detail = await this.items.get(conversationId, targetId, {
|
|
138
|
-
include: RESPONSE_INCLUDES,
|
|
139
|
-
});
|
|
140
|
-
const outputMessages =
|
|
141
|
-
detail.gen_ai_output_messages ??
|
|
142
|
-
(detail.output_message ? [detail.output_message] : []);
|
|
143
|
-
return {
|
|
144
|
-
conversation_id: conversationId,
|
|
145
|
-
response_id: detail.response_id ?? null,
|
|
146
|
-
item_id: detail.id,
|
|
147
|
-
created_at: detail.created_at,
|
|
148
|
-
model:
|
|
149
|
-
detail.model_name ??
|
|
150
|
-
detail.response_model ??
|
|
151
|
-
detail.request_model ??
|
|
152
|
-
null,
|
|
153
|
-
provider_name: detail.provider_name ?? null,
|
|
154
|
-
// The single-item route returns the FULL input history here.
|
|
155
|
-
input_messages: normalizeMessages(detail.input_messages),
|
|
156
|
-
output_messages: normalizeMessages(outputMessages),
|
|
157
|
-
system_instructions: detail.system_instructions ?? null,
|
|
158
|
-
tool_definitions: detail.tool_definitions ?? null,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** Scan items in descending order for the most recent LLM turn. */
|
|
163
|
-
private async findLatestTurnId(
|
|
164
|
-
conversationId: string,
|
|
165
|
-
): Promise<string | null> {
|
|
166
|
-
let fallback: ConversationItem | null = null;
|
|
167
|
-
for await (const item of this.items.list(conversationId, {
|
|
168
|
-
order: "desc",
|
|
169
|
-
})) {
|
|
170
|
-
if (item.node_type === "assistant" || item.operation_name === "chat") {
|
|
171
|
-
return item.id;
|
|
172
|
-
}
|
|
173
|
-
if (fallback === null && item.output_message != null) fallback = item;
|
|
174
|
-
}
|
|
175
|
-
return fallback?.id ?? null;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Defensive normalization for {@link ConversationsApi.retrieve} only:
|
|
181
|
-
* older DP deployments emitted `tool_call_response` parts with a legacy
|
|
182
|
-
* `result` key instead of the semconv `response` key. Map it across so
|
|
183
|
-
* replayed history is always semconv-shaped.
|
|
184
|
-
*/
|
|
185
|
-
function normalizeMessages<T extends { parts: MessagePart[] }>(
|
|
186
|
-
messages: T[],
|
|
187
|
-
): T[] {
|
|
188
|
-
return messages.map((message) => ({
|
|
189
|
-
...message,
|
|
190
|
-
parts: message.parts.map(normalizePart),
|
|
191
|
-
}));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function normalizePart(part: MessagePart): MessagePart {
|
|
195
|
-
if (part.type !== "tool_call_response") return part;
|
|
196
|
-
const legacy = part as ToolCallResponsePart & { result?: unknown };
|
|
197
|
-
if (legacy.response !== undefined || legacy.result === undefined) {
|
|
198
|
-
return part;
|
|
199
|
-
}
|
|
200
|
-
const { result, ...rest } = legacy;
|
|
201
|
-
return { ...rest, response: result };
|
|
202
|
-
}
|