@introspection-sdk/introspection-node 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.
- package/.turbo/turbo-build.log +1 -1
- package/dist/client.d.ts +3 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -6
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- 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 -169
- package/dist/resources/runtimes.js.map +1 -1
- package/dist/runner.d.ts +2 -3
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +3 -3
- package/dist/runner.js.map +1 -1
- package/package.json +7 -7
- package/src/client.ts +3 -6
- package/src/index.ts +9 -6
- package/src/resources/runtimes.ts +14 -217
- package/src/runner.ts +8 -3
- 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 -129
- package/dist/runner-resources/files.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 -179
- package/src/runner-resources/tasks.ts +0 -158
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
File as FileResource,
|
|
3
|
-
FileCreateOptions,
|
|
4
|
-
FileCreateTextParams,
|
|
5
|
-
FileListParams,
|
|
6
|
-
FileType,
|
|
7
|
-
FileUpdateParams,
|
|
8
|
-
ListParams,
|
|
9
|
-
Paginated,
|
|
10
|
-
} from "@introspection-sdk/types";
|
|
11
|
-
import { HttpClient } from "../http.js";
|
|
12
|
-
import { Paginator, cursorPaginate } from "../pagination.js";
|
|
13
|
-
|
|
14
|
-
export type FileUploadBody =
|
|
15
|
-
| { file: Blob; name?: string; file_type?: FileType }
|
|
16
|
-
| {
|
|
17
|
-
file: Uint8Array;
|
|
18
|
-
name: string;
|
|
19
|
-
file_type?: FileType;
|
|
20
|
-
contentType?: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export class FileVersionsApi {
|
|
24
|
-
constructor(private readonly http: HttpClient) {}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* List versions of a file. `await` the result for the first page, or
|
|
28
|
-
* `for await` it to stream every version across pages (fetched lazily;
|
|
29
|
-
* stop early to stop fetching).
|
|
30
|
-
*/
|
|
31
|
-
list(fileId: string, params?: ListParams): Paginator<FileResource> {
|
|
32
|
-
return cursorPaginate(
|
|
33
|
-
(next) =>
|
|
34
|
-
this.http.request<Paginated<FileResource>>({
|
|
35
|
-
method: "GET",
|
|
36
|
-
path: `/v1/files/${encodeURIComponent(fileId)}/versions`,
|
|
37
|
-
query: { ...params, next } as Record<string, unknown>,
|
|
38
|
-
}),
|
|
39
|
-
params?.next,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get(fileId: string, versionId: string): Promise<FileResource> {
|
|
44
|
-
return this.http.request<FileResource>({
|
|
45
|
-
method: "GET",
|
|
46
|
-
path: `/v1/files/${encodeURIComponent(fileId)}/versions/${encodeURIComponent(versionId)}`,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
create(
|
|
51
|
-
fileId: string,
|
|
52
|
-
body: FileUploadBody,
|
|
53
|
-
options?: FileCreateOptions,
|
|
54
|
-
): Promise<FileResource> {
|
|
55
|
-
const form = toFormData(body, options);
|
|
56
|
-
return this.http.request<FileResource>({
|
|
57
|
-
method: "POST",
|
|
58
|
-
path: `/v1/files/${encodeURIComponent(fileId)}/versions`,
|
|
59
|
-
body: form,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export class FilesApi {
|
|
65
|
-
readonly versions: FileVersionsApi;
|
|
66
|
-
|
|
67
|
-
constructor(private readonly http: HttpClient) {
|
|
68
|
-
this.versions = new FileVersionsApi(http);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* List files matching `params`. `await` the result for the first page,
|
|
73
|
-
* or `for await` it to stream every file across pages (fetched lazily —
|
|
74
|
-
* `limit` sets the page size, `next` the starting cursor; stop early to
|
|
75
|
-
* stop fetching).
|
|
76
|
-
*/
|
|
77
|
-
list(params?: FileListParams): Paginator<FileResource> {
|
|
78
|
-
return cursorPaginate(
|
|
79
|
-
(next) =>
|
|
80
|
-
this.http.request<Paginated<FileResource>>({
|
|
81
|
-
method: "GET",
|
|
82
|
-
path: "/v1/files",
|
|
83
|
-
query: { ...params, next } as Record<string, unknown>,
|
|
84
|
-
}),
|
|
85
|
-
params?.next,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
upload(
|
|
90
|
-
body: FileUploadBody,
|
|
91
|
-
options?: FileCreateOptions,
|
|
92
|
-
): Promise<FileResource> {
|
|
93
|
-
const form = toFormData(body, options);
|
|
94
|
-
return this.http.request<FileResource>({
|
|
95
|
-
method: "POST",
|
|
96
|
-
path: "/v1/files",
|
|
97
|
-
body: form,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
createText(
|
|
102
|
-
body: FileCreateTextParams,
|
|
103
|
-
options?: FileCreateOptions,
|
|
104
|
-
): Promise<FileResource> {
|
|
105
|
-
return this.http.request<FileResource>({
|
|
106
|
-
method: "POST",
|
|
107
|
-
path: "/v1/files",
|
|
108
|
-
body: options?.visibility
|
|
109
|
-
? { ...body, visibility: options.visibility }
|
|
110
|
-
: body,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
get(fileId: string): Promise<FileResource> {
|
|
115
|
-
return this.http.request<FileResource>({
|
|
116
|
-
method: "GET",
|
|
117
|
-
path: `/v1/files/${encodeURIComponent(fileId)}`,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
update(fileId: string, body: FileUpdateParams): Promise<FileResource> {
|
|
122
|
-
return this.http.request<FileResource>({
|
|
123
|
-
method: "PATCH",
|
|
124
|
-
path: `/v1/files/${encodeURIComponent(fileId)}`,
|
|
125
|
-
body,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
delete(fileId: string): Promise<void> {
|
|
130
|
-
return this.http.request<void>({
|
|
131
|
-
method: "DELETE",
|
|
132
|
-
path: `/v1/files/${encodeURIComponent(fileId)}`,
|
|
133
|
-
expect: "empty",
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
download(fileId: string): Promise<Uint8Array> {
|
|
138
|
-
return this.http.request<Uint8Array>({
|
|
139
|
-
method: "GET",
|
|
140
|
-
path: `/v1/files/${encodeURIComponent(fileId)}/content`,
|
|
141
|
-
expect: "bytes",
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
downloadStream(fileId: string): Promise<ReadableStream<Uint8Array>> {
|
|
146
|
-
return this.http.request<ReadableStream<Uint8Array>>({
|
|
147
|
-
method: "GET",
|
|
148
|
-
path: `/v1/files/${encodeURIComponent(fileId)}/content`,
|
|
149
|
-
expect: "stream",
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function toFormData(
|
|
155
|
-
body: FileUploadBody,
|
|
156
|
-
options?: FileCreateOptions,
|
|
157
|
-
): FormData {
|
|
158
|
-
const fd = new FormData();
|
|
159
|
-
if ("file" in body && body.file instanceof Blob) {
|
|
160
|
-
fd.append("file", body.file, body.name);
|
|
161
|
-
} else {
|
|
162
|
-
// Uint8Array branch — copy into a fresh ArrayBuffer so the Blob
|
|
163
|
-
// constructor sees a concrete ArrayBuffer (not ArrayBufferLike,
|
|
164
|
-
// which TS rejects under nodenext lib).
|
|
165
|
-
const u8 = (body as { file: Uint8Array }).file;
|
|
166
|
-
const ct =
|
|
167
|
-
(body as { contentType?: string }).contentType ??
|
|
168
|
-
"application/octet-stream";
|
|
169
|
-
const ab = u8.buffer.slice(
|
|
170
|
-
u8.byteOffset,
|
|
171
|
-
u8.byteOffset + u8.byteLength,
|
|
172
|
-
) as ArrayBuffer;
|
|
173
|
-
fd.append("file", new Blob([ab], { type: ct }), body.name);
|
|
174
|
-
}
|
|
175
|
-
if (body.name) fd.append("name", body.name);
|
|
176
|
-
if (body.file_type) fd.append("file_type", body.file_type);
|
|
177
|
-
if (options?.visibility) fd.append("visibility", options.visibility);
|
|
178
|
-
return fd;
|
|
179
|
-
}
|
|
@@ -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
|
-
}
|