@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.
Files changed (37) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/index.d.ts +2 -6
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -4
  5. package/dist/index.js.map +1 -1
  6. package/dist/resources/runtimes.d.ts +4 -74
  7. package/dist/resources/runtimes.d.ts.map +1 -1
  8. package/dist/resources/runtimes.js +5 -171
  9. package/dist/resources/runtimes.js.map +1 -1
  10. package/dist/runner.d.ts +1 -4
  11. package/dist/runner.d.ts.map +1 -1
  12. package/dist/runner.js +1 -4
  13. package/dist/runner.js.map +1 -1
  14. package/package.json +5 -5
  15. package/src/index.ts +9 -7
  16. package/src/resources/runtimes.ts +14 -216
  17. package/src/runner.ts +6 -4
  18. package/dist/runner-resources/conversations.d.ts +0 -73
  19. package/dist/runner-resources/conversations.d.ts.map +0 -1
  20. package/dist/runner-resources/conversations.js +0 -161
  21. package/dist/runner-resources/conversations.js.map +0 -1
  22. package/dist/runner-resources/files.d.ts +0 -45
  23. package/dist/runner-resources/files.d.ts.map +0 -1
  24. package/dist/runner-resources/files.js +0 -125
  25. package/dist/runner-resources/files.js.map +0 -1
  26. package/dist/runner-resources/shares.d.ts +0 -27
  27. package/dist/runner-resources/shares.d.ts.map +0 -1
  28. package/dist/runner-resources/shares.js +0 -50
  29. package/dist/runner-resources/shares.js.map +0 -1
  30. package/dist/runner-resources/tasks.d.ts +0 -45
  31. package/dist/runner-resources/tasks.d.ts.map +0 -1
  32. package/dist/runner-resources/tasks.js +0 -127
  33. package/dist/runner-resources/tasks.js.map +0 -1
  34. package/src/runner-resources/conversations.ts +0 -202
  35. package/src/runner-resources/files.ts +0 -162
  36. package/src/runner-resources/shares.ts +0 -62
  37. package/src/runner-resources/tasks.ts +0 -158
@@ -1,162 +0,0 @@
1
- import type {
2
- File as FileResource,
3
- FileCreateTextParams,
4
- FileListParams,
5
- FileType,
6
- FileUpdateParams,
7
- ListParams,
8
- Paginated,
9
- } from "@introspection-sdk/types";
10
- import { HttpClient } from "../http.js";
11
- import { Paginator, cursorPaginate } from "../pagination.js";
12
-
13
- export type FileUploadBody =
14
- | { file: Blob; name?: string; file_type?: FileType }
15
- | {
16
- file: Uint8Array;
17
- name: string;
18
- file_type?: FileType;
19
- contentType?: string;
20
- };
21
-
22
- export class FileVersionsApi {
23
- constructor(private readonly http: HttpClient) {}
24
-
25
- /**
26
- * List versions of a file. `await` the result for the first page, or
27
- * `for await` it to stream every version across pages (fetched lazily;
28
- * stop early to stop fetching).
29
- */
30
- list(fileId: string, params?: ListParams): Paginator<FileResource> {
31
- return cursorPaginate(
32
- (next) =>
33
- this.http.request<Paginated<FileResource>>({
34
- method: "GET",
35
- path: `/v1/files/${encodeURIComponent(fileId)}/versions`,
36
- query: { ...params, next } as Record<string, unknown>,
37
- }),
38
- params?.next,
39
- );
40
- }
41
-
42
- get(fileId: string, versionId: string): Promise<FileResource> {
43
- return this.http.request<FileResource>({
44
- method: "GET",
45
- path: `/v1/files/${encodeURIComponent(fileId)}/versions/${encodeURIComponent(versionId)}`,
46
- });
47
- }
48
-
49
- create(fileId: string, body: FileUploadBody): Promise<FileResource> {
50
- const form = toFormData(body);
51
- return this.http.request<FileResource>({
52
- method: "POST",
53
- path: `/v1/files/${encodeURIComponent(fileId)}/versions`,
54
- body: form,
55
- });
56
- }
57
- }
58
-
59
- export class FilesApi {
60
- readonly versions: FileVersionsApi;
61
-
62
- constructor(private readonly http: HttpClient) {
63
- this.versions = new FileVersionsApi(http);
64
- }
65
-
66
- /**
67
- * List files matching `params`. `await` the result for the first page,
68
- * or `for await` it to stream every file across pages (fetched lazily —
69
- * `limit` sets the page size, `next` the starting cursor; stop early to
70
- * stop fetching).
71
- */
72
- list(params?: FileListParams): Paginator<FileResource> {
73
- return cursorPaginate(
74
- (next) =>
75
- this.http.request<Paginated<FileResource>>({
76
- method: "GET",
77
- path: "/v1/files",
78
- query: { ...params, next } as Record<string, unknown>,
79
- }),
80
- params?.next,
81
- );
82
- }
83
-
84
- upload(body: FileUploadBody): Promise<FileResource> {
85
- const form = toFormData(body);
86
- return this.http.request<FileResource>({
87
- method: "POST",
88
- path: "/v1/files",
89
- body: form,
90
- });
91
- }
92
-
93
- createText(body: FileCreateTextParams): Promise<FileResource> {
94
- return this.http.request<FileResource>({
95
- method: "POST",
96
- path: "/v1/files",
97
- body,
98
- });
99
- }
100
-
101
- get(fileId: string): Promise<FileResource> {
102
- return this.http.request<FileResource>({
103
- method: "GET",
104
- path: `/v1/files/${encodeURIComponent(fileId)}`,
105
- });
106
- }
107
-
108
- update(fileId: string, body: FileUpdateParams): Promise<FileResource> {
109
- return this.http.request<FileResource>({
110
- method: "PATCH",
111
- path: `/v1/files/${encodeURIComponent(fileId)}`,
112
- body,
113
- });
114
- }
115
-
116
- delete(fileId: string): Promise<void> {
117
- return this.http.request<void>({
118
- method: "DELETE",
119
- path: `/v1/files/${encodeURIComponent(fileId)}`,
120
- expect: "empty",
121
- });
122
- }
123
-
124
- download(fileId: string): Promise<Uint8Array> {
125
- return this.http.request<Uint8Array>({
126
- method: "GET",
127
- path: `/v1/files/${encodeURIComponent(fileId)}/content`,
128
- expect: "bytes",
129
- });
130
- }
131
-
132
- downloadStream(fileId: string): Promise<ReadableStream<Uint8Array>> {
133
- return this.http.request<ReadableStream<Uint8Array>>({
134
- method: "GET",
135
- path: `/v1/files/${encodeURIComponent(fileId)}/content`,
136
- expect: "stream",
137
- });
138
- }
139
- }
140
-
141
- function toFormData(body: FileUploadBody): FormData {
142
- const fd = new FormData();
143
- if ("file" in body && body.file instanceof Blob) {
144
- fd.append("file", body.file, body.name);
145
- } else {
146
- // Uint8Array branch — copy into a fresh ArrayBuffer so the Blob
147
- // constructor sees a concrete ArrayBuffer (not ArrayBufferLike,
148
- // which TS rejects under nodenext lib).
149
- const u8 = (body as { file: Uint8Array }).file;
150
- const ct =
151
- (body as { contentType?: string }).contentType ??
152
- "application/octet-stream";
153
- const ab = u8.buffer.slice(
154
- u8.byteOffset,
155
- u8.byteOffset + u8.byteLength,
156
- ) as ArrayBuffer;
157
- fd.append("file", new Blob([ab], { type: ct }), body.name);
158
- }
159
- if (body.name) fd.append("name", body.name);
160
- if (body.file_type) fd.append("file_type", body.file_type);
161
- return fd;
162
- }
@@ -1,62 +0,0 @@
1
- import type {
2
- Paginated,
3
- ResourceShare,
4
- ShareCreateParams,
5
- ShareListParams,
6
- } from "@introspection-sdk/types";
7
- import { HttpClient } from "../http.js";
8
- import { Paginator, cursorPaginate } from "../pagination.js";
9
-
10
- /**
11
- * Runner-bound Resource Shares API (`/v1/shares`).
12
- *
13
- * Read-sharing grants for files and conversations: `create` / `list` / `get` /
14
- * `delete` (revoke). A grant carries a `url` (with the `?share_id` capability)
15
- * for reading the shared resource. To fork a new task from a shared
16
- * conversation, pass `fork_share_id` to `runner.tasks.create(...)`.
17
- */
18
- export class SharesApi {
19
- constructor(private readonly http: HttpClient) {}
20
-
21
- /**
22
- * List grants the caller created or that target them. `await` for the first
23
- * page, or `for await` to stream every grant across pages.
24
- */
25
- list(params?: ShareListParams): Paginator<ResourceShare> {
26
- return cursorPaginate(
27
- (next) =>
28
- this.http.request<Paginated<ResourceShare>>({
29
- method: "GET",
30
- path: "/v1/shares",
31
- query: { ...params, next } as Record<string, unknown>,
32
- }),
33
- params?.next,
34
- );
35
- }
36
-
37
- /** Create a read-sharing grant. The caller must own the target resource. */
38
- create(body: ShareCreateParams): Promise<ResourceShare> {
39
- return this.http.request<ResourceShare>({
40
- method: "POST",
41
- path: "/v1/shares",
42
- body,
43
- });
44
- }
45
-
46
- /** Read a single grant (carries the `url` to the shared resource). */
47
- get(shareId: string): Promise<ResourceShare> {
48
- return this.http.request<ResourceShare>({
49
- method: "GET",
50
- path: `/v1/shares/${encodeURIComponent(shareId)}`,
51
- });
52
- }
53
-
54
- /** Revoke a grant. Only the grantor (or an admin/owner) may revoke. */
55
- delete(shareId: string): Promise<void> {
56
- return this.http.request<void>({
57
- method: "DELETE",
58
- path: `/v1/shares/${encodeURIComponent(shareId)}`,
59
- expect: "empty",
60
- });
61
- }
62
- }
@@ -1,158 +0,0 @@
1
- import type {
2
- Paginated,
3
- SseEvent,
4
- Task,
5
- TaskCancelResponse,
6
- TaskCreateParams,
7
- TaskCreateResponse,
8
- TaskListParams,
9
- TaskRun,
10
- TaskRunCreateParams,
11
- TaskRunResponse,
12
- TaskUpdateParams,
13
- } from "@introspection-sdk/types";
14
- import { HttpClient } from "../http.js";
15
- import { Paginator, cursorPaginate } from "../pagination.js";
16
- import { parseSse } from "../streaming.js";
17
-
18
- export interface StartParams extends TaskCreateParams {
19
- prompt: string; // required for the cursor-style sugar
20
- }
21
-
22
- export class RunHandle {
23
- constructor(
24
- public readonly task: Task | null,
25
- public readonly run: TaskRun,
26
- private readonly runs: TaskRunsApi,
27
- ) {}
28
-
29
- stream(): AsyncIterable<SseEvent> {
30
- return this.runs.stream(this.run.task_id, this.run.id);
31
- }
32
-
33
- cancel(): Promise<TaskCancelResponse> {
34
- return this.runs.cancel(this.run.task_id, this.run.id);
35
- }
36
-
37
- /** Convenience: collect `data` from `event: text`-style frames into a string. */
38
- async text(): Promise<string> {
39
- let out = "";
40
- for await (const ev of this.stream()) {
41
- if (ev.event === "text" || ev.event === "message") out += ev.data;
42
- }
43
- return out;
44
- }
45
- }
46
-
47
- export class TaskRunsApi {
48
- constructor(private readonly http: HttpClient) {}
49
-
50
- async create(taskId: string, body: TaskRunCreateParams): Promise<RunHandle> {
51
- const res = await this.http.request<TaskRunResponse>({
52
- method: "POST",
53
- path: `/v1/tasks/${encodeURIComponent(taskId)}/runs`,
54
- body,
55
- });
56
- return new RunHandle(null, res.run, this);
57
- }
58
-
59
- get(taskId: string, runId: string): Promise<TaskRun> {
60
- return this.http.request<TaskRun>({
61
- method: "GET",
62
- path: `/v1/tasks/${encodeURIComponent(taskId)}/runs/${encodeURIComponent(runId)}`,
63
- });
64
- }
65
-
66
- cancel(taskId: string, runId: string): Promise<TaskCancelResponse> {
67
- return this.http.request<TaskCancelResponse>({
68
- method: "POST",
69
- path: `/v1/tasks/${encodeURIComponent(taskId)}/runs/${encodeURIComponent(runId)}/cancel`,
70
- });
71
- }
72
-
73
- async *stream(taskId: string, runId: string): AsyncIterable<SseEvent> {
74
- const res = await this.http.stream({
75
- path: `/v1/tasks/${encodeURIComponent(taskId)}/runs/${encodeURIComponent(runId)}/stream`,
76
- });
77
- yield* parseSse(res);
78
- }
79
- }
80
-
81
- export class TasksApi {
82
- readonly runs: TaskRunsApi;
83
-
84
- constructor(private readonly http: HttpClient) {
85
- this.runs = new TaskRunsApi(http);
86
- }
87
-
88
- /**
89
- * List tasks matching `params`. `await` the result for the first page,
90
- * or `for await` it to stream every task across pages (fetched lazily —
91
- * `limit` sets the page size, `next` the starting cursor; stop early to
92
- * stop fetching).
93
- */
94
- list(params?: TaskListParams): Paginator<Task> {
95
- return cursorPaginate(
96
- (next) =>
97
- this.http.request<Paginated<Task>>({
98
- method: "GET",
99
- path: "/v1/tasks",
100
- query: { ...params, next } as Record<string, unknown>,
101
- }),
102
- params?.next,
103
- );
104
- }
105
-
106
- create(body: TaskCreateParams): Promise<TaskCreateResponse> {
107
- return this.http.request<TaskCreateResponse>({
108
- method: "POST",
109
- path: "/v1/tasks",
110
- body,
111
- });
112
- }
113
-
114
- get(taskId: string): Promise<Task> {
115
- return this.http.request<Task>({
116
- method: "GET",
117
- path: `/v1/tasks/${encodeURIComponent(taskId)}`,
118
- });
119
- }
120
-
121
- update(taskId: string, body: TaskUpdateParams): Promise<Task> {
122
- return this.http.request<Task>({
123
- method: "PATCH",
124
- path: `/v1/tasks/${encodeURIComponent(taskId)}`,
125
- body,
126
- });
127
- }
128
-
129
- delete(taskId: string): Promise<void> {
130
- return this.http.request<void>({
131
- method: "DELETE",
132
- path: `/v1/tasks/${encodeURIComponent(taskId)}`,
133
- expect: "empty",
134
- });
135
- }
136
-
137
- archive(taskId: string): Promise<void> {
138
- return this.http.request<void>({
139
- method: "POST",
140
- path: `/v1/tasks/${encodeURIComponent(taskId)}/archive`,
141
- expect: "empty",
142
- });
143
- }
144
-
145
- unarchive(taskId: string): Promise<void> {
146
- return this.http.request<void>({
147
- method: "POST",
148
- path: `/v1/tasks/${encodeURIComponent(taskId)}/unarchive`,
149
- expect: "empty",
150
- });
151
- }
152
-
153
- /** Cursor-style sugar: create a task + return a handle on its initial run. */
154
- async start(params: StartParams): Promise<RunHandle> {
155
- const res = await this.create(params);
156
- return new RunHandle(res.task, res.run, this.runs);
157
- }
158
- }