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