@neta-art/cohub 1.8.0 → 1.10.0

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 (51) hide show
  1. package/README.md +6 -105
  2. package/dist/chunks/environment.js +33 -0
  3. package/dist/chunks/http.d.ts +1615 -0
  4. package/dist/chunks/http.js +1919 -0
  5. package/dist/chunks/websocket.d.ts +266 -0
  6. package/dist/chunks/websocket.js +655 -0
  7. package/dist/http.d.ts +3 -30
  8. package/dist/http.js +2 -45
  9. package/dist/index.d.ts +35 -14
  10. package/dist/index.js +105 -8
  11. package/dist/websocket.d.ts +2 -141
  12. package/dist/websocket.js +2 -628
  13. package/package.json +7 -7
  14. package/dist/apis/channels.d.ts +0 -13
  15. package/dist/apis/channels.js +0 -24
  16. package/dist/apis/cron-jobs.d.ts +0 -18
  17. package/dist/apis/cron-jobs.js +0 -25
  18. package/dist/apis/explore.d.ts +0 -9
  19. package/dist/apis/explore.js +0 -9
  20. package/dist/apis/generations.d.ts +0 -8
  21. package/dist/apis/generations.js +0 -16
  22. package/dist/apis/invitations.d.ts +0 -20
  23. package/dist/apis/invitations.js +0 -36
  24. package/dist/apis/models.d.ts +0 -7
  25. package/dist/apis/models.js +0 -9
  26. package/dist/apis/prompts.d.ts +0 -9
  27. package/dist/apis/prompts.js +0 -16
  28. package/dist/apis/search.d.ts +0 -10
  29. package/dist/apis/search.js +0 -14
  30. package/dist/apis/session-access.d.ts +0 -13
  31. package/dist/apis/session-access.js +0 -19
  32. package/dist/apis/spaces.d.ts +0 -371
  33. package/dist/apis/spaces.js +0 -766
  34. package/dist/apis/tasks.d.ts +0 -13
  35. package/dist/apis/tasks.js +0 -18
  36. package/dist/apis/user.d.ts +0 -27
  37. package/dist/apis/user.js +0 -71
  38. package/dist/client.d.ts +0 -33
  39. package/dist/client.js +0 -103
  40. package/dist/environment.d.ts +0 -22
  41. package/dist/environment.js +0 -37
  42. package/dist/realtime.d.ts +0 -2
  43. package/dist/realtime.js +0 -8
  44. package/dist/session-generation-stream.d.ts +0 -114
  45. package/dist/session-generation-stream.js +0 -514
  46. package/dist/session-patch-reducer.d.ts +0 -61
  47. package/dist/session-patch-reducer.js +0 -432
  48. package/dist/transport.d.ts +0 -40
  49. package/dist/transport.js +0 -78
  50. package/dist/types.d.ts +0 -535
  51. package/dist/types.js +0 -1
@@ -1,766 +0,0 @@
1
- import { ensureRealtimeConnected } from "../realtime.js";
2
- import { SessionPatchReducer, } from "../session-patch-reducer.js";
3
- import { SessionGenerationStreamClient, } from "../session-generation-stream.js";
4
- import { SpaceInvitationsApi } from "./invitations.js";
5
- const DEFAULT_DEDUP_WINDOW_MS = 2000;
6
- const getFilenameFromContentDisposition = (value) => {
7
- if (!value)
8
- return null;
9
- const encodedMatch = value.match(/filename\*=UTF-8''([^;]+)/i);
10
- if (encodedMatch?.[1]) {
11
- try {
12
- return decodeURIComponent(encodedMatch[1]);
13
- }
14
- catch {
15
- return encodedMatch[1];
16
- }
17
- }
18
- const plainMatch = value.match(/filename="?([^";]+)"?/i);
19
- return plainMatch?.[1] ?? null;
20
- };
21
- const toSessionEventName = (type) => {
22
- switch (type) {
23
- case "session.turn.patch":
24
- return "turn.patch";
25
- case "session.turn.snapshot":
26
- return "turn.snapshot";
27
- case "session.turn.progress":
28
- return "turn.progress";
29
- case "session.turn.error":
30
- return "turn.error";
31
- case "session.turn.updated":
32
- return "turn.updated";
33
- case "session.turn.finalized":
34
- return "turn.final";
35
- case "session.message.persisted":
36
- return "message.persisted";
37
- default:
38
- return null;
39
- }
40
- };
41
- const isAssistantFinalPersistedEvent = (event) => {
42
- if (event.type !== "session.message.persisted")
43
- return false;
44
- const message = event.payload.message;
45
- if (!message || typeof message !== "object")
46
- return false;
47
- const record = message;
48
- return record.role === "assistant" && (record.meta?.messageKind === "assistant_final" || record.meta?.messageKind === "assistant_error");
49
- };
50
- const isAssistantIntermediatePersistedEvent = (event) => {
51
- if (event.type !== "session.message.persisted")
52
- return false;
53
- const message = event.payload.message;
54
- if (!message || typeof message !== "object")
55
- return false;
56
- const record = message;
57
- return record.role === "assistant" && record.meta?.messageKind === "assistant_intermediate";
58
- };
59
- const getPersistedMessageTurnId = (event) => {
60
- if (event.type !== "session.message.persisted")
61
- return null;
62
- const message = event.payload.message;
63
- if (!message || typeof message !== "object")
64
- return null;
65
- const meta = message.meta;
66
- return typeof meta?.turnId === "string" ? meta.turnId : null;
67
- };
68
- export class SpacesApi {
69
- transport;
70
- constructor(transport) {
71
- this.transport = transport;
72
- }
73
- list(customFetch) {
74
- return this.transport.request("/api/spaces", {
75
- method: "GET",
76
- fetch: customFetch,
77
- });
78
- }
79
- get(spaceId, customFetch) {
80
- return this.transport.request(`/api/spaces/${spaceId}`, {
81
- fetch: customFetch,
82
- });
83
- }
84
- create(input, headers) {
85
- return this.transport.request("/api/spaces", {
86
- method: "POST",
87
- headers: {
88
- ...headers,
89
- "Content-Type": "application/json",
90
- },
91
- body: JSON.stringify(input ?? {}),
92
- });
93
- }
94
- }
95
- export class SpaceFilesApi {
96
- transport;
97
- spaceId;
98
- constructor(transport, spaceId) {
99
- this.transport = transport;
100
- this.spaceId = spaceId;
101
- }
102
- list(path = "", customFetch) {
103
- const params = new URLSearchParams();
104
- if (path)
105
- params.set("path", path);
106
- const query = params.toString();
107
- return this.transport.request(`/api/spaces/${this.spaceId}/fs/tree${query ? `?${query}` : ""}`, { fetch: customFetch });
108
- }
109
- read(path, customFetch) {
110
- const params = new URLSearchParams({ path });
111
- return this.transport.request(`/api/spaces/${this.spaceId}/fs/file?${params.toString()}`, { fetch: customFetch });
112
- }
113
- /**
114
- * Build a direct download URL. For private files, prefer `download()` so the
115
- * SDK can attach authorization headers.
116
- */
117
- getDownloadUrl(path) {
118
- const params = new URLSearchParams({ path });
119
- return `/api/spaces/${this.spaceId}/fs/download?${params.toString()}`;
120
- }
121
- async download(path, customFetch) {
122
- const params = new URLSearchParams({ path });
123
- const raw = await this.transport.raw(`/api/spaces/${this.spaceId}/fs/download?${params.toString()}`, { fetch: customFetch });
124
- const blob = await raw.blob();
125
- const filename = getFilenameFromContentDisposition(raw.response.headers.get("content-disposition")) ??
126
- path.split("/").pop() ??
127
- "download";
128
- const mimeType = raw.response.headers.get("content-type") ??
129
- blob.type ??
130
- "application/octet-stream";
131
- return { blob, filename, mimeType };
132
- }
133
- write(input) {
134
- return this.transport.request(`/api/spaces/${this.spaceId}/fs/file`, {
135
- method: "PUT",
136
- headers: { "Content-Type": "application/json" },
137
- body: JSON.stringify(input),
138
- });
139
- }
140
- createDir(path) {
141
- return this.transport.request(`/api/spaces/${this.spaceId}/fs/dir`, {
142
- method: "POST",
143
- headers: { "Content-Type": "application/json" },
144
- body: JSON.stringify({ path }),
145
- });
146
- }
147
- delete(path, recursive = false) {
148
- const params = new URLSearchParams({ path });
149
- if (recursive)
150
- params.set("recursive", "true");
151
- return this.transport.request(`/api/spaces/${this.spaceId}/fs/node?${params.toString()}`, { method: "DELETE" });
152
- }
153
- move(input) {
154
- return this.transport.request(`/api/spaces/${this.spaceId}/fs/move`, {
155
- method: "POST",
156
- headers: { "Content-Type": "application/json" },
157
- body: JSON.stringify(input),
158
- });
159
- }
160
- upload(files, dir = "") {
161
- const params = new URLSearchParams();
162
- if (dir)
163
- params.set("dir", dir);
164
- const query = params.toString();
165
- const formData = new FormData();
166
- for (const file of files)
167
- formData.append("files", file);
168
- return this.transport.request(`/api/spaces/${this.spaceId}/fs/upload${query ? `?${query}` : ""}`, {
169
- method: "POST",
170
- body: formData,
171
- });
172
- }
173
- createUpload(input) {
174
- return this.transport.request(`/api/spaces/${this.spaceId}/fs/uploads`, {
175
- method: "POST",
176
- headers: { "Content-Type": "application/json" },
177
- body: JSON.stringify(input),
178
- });
179
- }
180
- completeUpload(uploadId, input) {
181
- return this.transport.request(`/api/spaces/${this.spaceId}/fs/uploads/${uploadId}/complete`, {
182
- method: "POST",
183
- headers: { "Content-Type": "application/json" },
184
- body: JSON.stringify(input),
185
- });
186
- }
187
- }
188
- class SessionMessagesClient {
189
- transport;
190
- sessionId;
191
- lastSentSignature = "";
192
- lastSentSessionId = "";
193
- lastSentAt = 0;
194
- constructor(transport, sessionId) {
195
- this.transport = transport;
196
- this.sessionId = sessionId;
197
- }
198
- list(customFetch) {
199
- return this.transport.request(`/api/sessions/${this.sessionId}/messages`, {
200
- fetch: customFetch,
201
- });
202
- }
203
- get(messageId, optionsOrFetch, customFetch) {
204
- const options = typeof optionsOrFetch === "function" ? undefined : optionsOrFetch;
205
- const fetch = typeof optionsOrFetch === "function" ? optionsOrFetch : customFetch;
206
- const params = new URLSearchParams();
207
- if (options?.detail)
208
- params.set("detail", options.detail);
209
- const query = params.toString();
210
- return this.transport.request(`/api/sessions/${this.sessionId}/messages/${messageId}${query ? `?${query}` : ""}`, {
211
- fetch,
212
- });
213
- }
214
- listPaginated(options, customFetch) {
215
- const params = new URLSearchParams();
216
- if (options?.cursor !== undefined)
217
- params.set("cursor", String(options.cursor));
218
- if (options?.limit !== undefined)
219
- params.set("limit", String(options.limit));
220
- if (options?.direction)
221
- params.set("direction", options.direction);
222
- const query = params.toString();
223
- return this.transport.request(`/api/sessions/${this.sessionId}/messages${query ? `?${query}` : ""}`, {
224
- fetch: customFetch,
225
- });
226
- }
227
- async send(input) {
228
- const signature = JSON.stringify({ sessionId: this.sessionId, input });
229
- const now = Date.now();
230
- if (this.sessionId === this.lastSentSessionId &&
231
- signature === this.lastSentSignature &&
232
- now - this.lastSentAt < DEFAULT_DEDUP_WINDOW_MS) {
233
- throw new Error("Duplicate message ignored");
234
- }
235
- this.lastSentSessionId = this.sessionId;
236
- this.lastSentSignature = signature;
237
- this.lastSentAt = now;
238
- return this.transport.request(`/api/sessions/${this.sessionId}/messages`, {
239
- method: "POST",
240
- headers: {
241
- "Content-Type": "application/json",
242
- },
243
- body: JSON.stringify({
244
- content: input.content,
245
- model: input.model,
246
- provider: input.provider,
247
- clientMessageId: input.clientMessageId,
248
- }),
249
- });
250
- }
251
- }
252
- class SessionTurnsClient {
253
- transport;
254
- sessionId;
255
- constructor(transport, sessionId) {
256
- this.transport = transport;
257
- this.sessionId = sessionId;
258
- }
259
- listPaginated(options, customFetch) {
260
- const params = new URLSearchParams();
261
- if (options?.cursor !== undefined)
262
- params.set("cursor", String(options.cursor));
263
- if (options?.limit !== undefined)
264
- params.set("limit", String(options.limit));
265
- if (options?.direction)
266
- params.set("direction", options.direction);
267
- const query = params.toString();
268
- return this.transport.request(`/api/sessions/${this.sessionId}/turns${query ? `?${query}` : ""}`, { fetch: customFetch });
269
- }
270
- index(options, customFetch) {
271
- const params = new URLSearchParams();
272
- if (options?.cursor !== undefined)
273
- params.set("cursor", String(options.cursor));
274
- if (options?.limit !== undefined)
275
- params.set("limit", String(options.limit));
276
- const query = params.toString();
277
- return this.transport.request(`/api/sessions/${this.sessionId}/turns/index${query ? `?${query}` : ""}`, { fetch: customFetch });
278
- }
279
- window(options, customFetch) {
280
- const params = new URLSearchParams();
281
- if (options.sequence !== undefined)
282
- params.set("sequence", String(options.sequence));
283
- if (options.turnId)
284
- params.set("turnId", options.turnId);
285
- if (options.before !== undefined)
286
- params.set("before", String(options.before));
287
- if (options.after !== undefined)
288
- params.set("after", String(options.after));
289
- const query = params.toString();
290
- return this.transport.request(`/api/sessions/${this.sessionId}/turns/window${query ? `?${query}` : ""}`, { fetch: customFetch });
291
- }
292
- streamSnapshot(customFetch) {
293
- return this.transport.request(`/api/sessions/${this.sessionId}/turns/stream-snapshot`, { fetch: customFetch });
294
- }
295
- get(turnId, customFetch) {
296
- return this.transport.request(`/api/sessions/${this.sessionId}/turns/${turnId}`, { fetch: customFetch });
297
- }
298
- signedUrls(turnId, objectKeys) {
299
- return this.transport.request(`/api/sessions/${this.sessionId}/turns/${turnId}/signed-urls`, {
300
- method: "POST",
301
- headers: { "Content-Type": "application/json" },
302
- body: JSON.stringify({ objectKeys }),
303
- });
304
- }
305
- }
306
- class SessionRealtimeClient {
307
- websocketClient;
308
- spaceId;
309
- sessionId;
310
- patchReducer = new SessionPatchReducer();
311
- constructor(websocketClient, spaceId, sessionId) {
312
- this.websocketClient = websocketClient;
313
- this.spaceId = spaceId;
314
- this.sessionId = sessionId;
315
- }
316
- subscribe(handlers) {
317
- if (!this.websocketClient) {
318
- throw new Error("realtime transport is not configured for this client");
319
- }
320
- ensureRealtimeConnected(this.websocketClient);
321
- const unsubscribe = this.websocketClient.on("event", (event) => {
322
- if (event.spaceId !== this.spaceId || event.sessionId !== this.sessionId)
323
- return;
324
- handlers.event?.(event);
325
- const eventName = toSessionEventName(event.type);
326
- if (eventName === "turn.patch") {
327
- handlers.patch?.(event);
328
- if (event.type === "session.turn.patch") {
329
- const payload = event.payload;
330
- if (typeof payload.seq === "number" &&
331
- typeof payload.baseSeq === "number" &&
332
- Array.isArray(payload.ops)) {
333
- handlers.patchState?.(this.patchReducer.applyPatch({
334
- spaceId: this.spaceId,
335
- sessionId: this.sessionId,
336
- turnId: typeof payload.turnId === "string" ? payload.turnId : null,
337
- seq: payload.seq,
338
- baseSeq: payload.baseSeq,
339
- ops: payload.ops,
340
- anchorUserMessageId: typeof payload.anchorUserMessageId === "string"
341
- ? payload.anchorUserMessageId
342
- : null,
343
- }));
344
- }
345
- }
346
- }
347
- if (eventName === "turn.snapshot")
348
- handlers.snapshot?.(event);
349
- if (eventName === "turn.progress")
350
- handlers.progress?.(event);
351
- if (eventName === "turn.error") {
352
- this.patchReducer.fail({
353
- spaceId: this.spaceId,
354
- sessionId: this.sessionId,
355
- });
356
- handlers.error?.(event);
357
- }
358
- if (eventName === "message.persisted") {
359
- handlers.persisted?.(event);
360
- if (isAssistantIntermediatePersistedEvent(event)) {
361
- this.patchReducer.reset({
362
- spaceId: this.spaceId,
363
- sessionId: this.sessionId,
364
- });
365
- }
366
- }
367
- if (eventName === "turn.updated")
368
- handlers.turnUpdated?.(event);
369
- if (eventName === "turn.final") {
370
- this.patchReducer.complete({
371
- spaceId: this.spaceId,
372
- sessionId: this.sessionId,
373
- turnId: typeof event.payload.turn === "object" && event.payload.turn && "id" in event.payload.turn ? String(event.payload.turn.id) : null,
374
- });
375
- handlers.turnFinalized?.(event);
376
- handlers.final?.(event);
377
- }
378
- if (isAssistantFinalPersistedEvent(event)) {
379
- this.patchReducer.complete({
380
- spaceId: this.spaceId,
381
- sessionId: this.sessionId,
382
- turnId: getPersistedMessageTurnId(event),
383
- });
384
- handlers.final?.(event);
385
- }
386
- });
387
- return () => unsubscribe();
388
- }
389
- on(type, handler) {
390
- return this.subscribe({
391
- event: (event) => {
392
- if (type === "turn.final" && isAssistantFinalPersistedEvent(event)) {
393
- handler(event);
394
- return;
395
- }
396
- if (toSessionEventName(event.type) === type)
397
- handler(event);
398
- },
399
- });
400
- }
401
- }
402
- export class SessionClient {
403
- spaceId;
404
- id;
405
- transport;
406
- messages;
407
- turns;
408
- realtime;
409
- generation;
410
- constructor(spaceId, id, transport, websocketClient) {
411
- this.spaceId = spaceId;
412
- this.id = id;
413
- this.transport = transport;
414
- this.messages = new SessionMessagesClient(transport, id);
415
- this.turns = new SessionTurnsClient(transport, id);
416
- this.realtime = new SessionRealtimeClient(websocketClient, spaceId, id);
417
- this.generation = new SessionGenerationStreamClient(websocketClient, spaceId, id);
418
- }
419
- get(customFetch) {
420
- return this.transport.request(`/api/sessions/${this.id}`, {
421
- fetch: customFetch,
422
- });
423
- }
424
- rename(title, customFetch) {
425
- return this.transport.request(`/api/sessions/${this.id}`, {
426
- method: "PATCH",
427
- body: JSON.stringify({ title }),
428
- fetch: customFetch,
429
- });
430
- }
431
- abort(optionsOrFetch, customFetch) {
432
- const options = typeof optionsOrFetch === "function" ? undefined : optionsOrFetch;
433
- const fetch = typeof optionsOrFetch === "function" ? optionsOrFetch : customFetch;
434
- return this.transport.request(`/api/sessions/${this.id}/abort`, {
435
- method: "POST",
436
- headers: { "Content-Type": "application/json" },
437
- body: JSON.stringify({ turnId: options?.turnId ?? null }),
438
- fetch,
439
- });
440
- }
441
- turn(turnId) {
442
- return {
443
- fork: (input = {}) => this.transport.request(`/api/sessions/${this.id}/turns/${turnId}/fork`, {
444
- method: "POST",
445
- headers: { "Content-Type": "application/json" },
446
- body: JSON.stringify(input),
447
- }),
448
- };
449
- }
450
- subscribe(handlers) {
451
- return this.realtime.subscribe(handlers);
452
- }
453
- subscribeGeneration(handlers) {
454
- return this.generation.subscribe(handlers);
455
- }
456
- on(type, handler) {
457
- return this.realtime.on(type, handler);
458
- }
459
- }
460
- export class SpaceSessionsApi {
461
- transport;
462
- spaceId;
463
- websocketClient;
464
- constructor(transport, spaceId, websocketClient) {
465
- this.transport = transport;
466
- this.spaceId = spaceId;
467
- this.websocketClient = websocketClient;
468
- }
469
- create(input) {
470
- return this.transport.request(`/api/spaces/${this.spaceId}/sessions`, {
471
- method: "POST",
472
- headers: {
473
- "Content-Type": "application/json",
474
- },
475
- body: JSON.stringify(input ?? {}),
476
- });
477
- }
478
- list(optionsOrFetch, customFetch) {
479
- const options = typeof optionsOrFetch === "function" ? undefined : optionsOrFetch;
480
- const fetch = typeof optionsOrFetch === "function" ? optionsOrFetch : customFetch;
481
- const params = new URLSearchParams();
482
- if (options?.limit !== undefined)
483
- params.set("limit", String(options.limit));
484
- if (options?.cursor)
485
- params.set("cursor", options.cursor);
486
- const query = params.toString();
487
- return this.transport.request(`/api/spaces/${this.spaceId}/sessions${query ? `?${query}` : ""}`, {
488
- fetch,
489
- });
490
- }
491
- byId(sessionId) {
492
- return new SessionClient(this.spaceId, sessionId, this.transport, this.websocketClient);
493
- }
494
- }
495
- export class SpaceEventsApi {
496
- websocketClient;
497
- spaceId;
498
- constructor(websocketClient, spaceId) {
499
- this.websocketClient = websocketClient;
500
- this.spaceId = spaceId;
501
- }
502
- subscribe(handler) {
503
- if (!this.websocketClient) {
504
- throw new Error("realtime transport is not configured for this client");
505
- }
506
- ensureRealtimeConnected(this.websocketClient);
507
- return this.websocketClient.on("event", (event) => {
508
- if (event.spaceId !== this.spaceId)
509
- return;
510
- handler(event);
511
- });
512
- }
513
- on(type, handler) {
514
- return this.subscribe((event) => {
515
- if (type === "event") {
516
- handler(event);
517
- return;
518
- }
519
- if (type === "ports.changed" && event.type === "space.ports.changed") {
520
- handler(event);
521
- return;
522
- }
523
- if (type === "turn.final" && isAssistantFinalPersistedEvent(event)) {
524
- handler(event);
525
- return;
526
- }
527
- if (toSessionEventName(event.type) === type)
528
- handler(event);
529
- });
530
- }
531
- }
532
- export class SpaceMembersApi {
533
- transport;
534
- spaceId;
535
- constructor(transport, spaceId) {
536
- this.transport = transport;
537
- this.spaceId = spaceId;
538
- }
539
- list() {
540
- return this.transport.request(`/api/spaces/${this.spaceId}/members`);
541
- }
542
- update(userId, role) {
543
- return this.transport.request(`/api/spaces/${this.spaceId}/members`, {
544
- method: "PUT",
545
- headers: { "Content-Type": "application/json" },
546
- body: JSON.stringify({ userId, role }),
547
- });
548
- }
549
- remove(userId) {
550
- return this.transport.request(`/api/spaces/${this.spaceId}/members`, {
551
- method: "DELETE",
552
- headers: { "Content-Type": "application/json" },
553
- body: JSON.stringify({ userId }),
554
- });
555
- }
556
- }
557
- export class SpaceAccessApi {
558
- transport;
559
- spaceId;
560
- constructor(transport, spaceId) {
561
- this.transport = transport;
562
- this.spaceId = spaceId;
563
- }
564
- get() {
565
- return this.transport.request(`/api/spaces/${this.spaceId}/access`);
566
- }
567
- set(body) {
568
- return this.transport.request(`/api/spaces/${this.spaceId}/access`, {
569
- method: "PATCH",
570
- headers: { "Content-Type": "application/json" },
571
- body: JSON.stringify(body),
572
- });
573
- }
574
- }
575
- export class SpaceUsageApi {
576
- transport;
577
- spaceId;
578
- constructor(transport, spaceId) {
579
- this.transport = transport;
580
- this.spaceId = spaceId;
581
- }
582
- get(days = 30, customFetch) {
583
- const params = new URLSearchParams({ days: String(days) });
584
- return this.transport.request(`/api/spaces/${this.spaceId}/usage?${params.toString()}`, { fetch: customFetch });
585
- }
586
- }
587
- export class SpaceChannelsApi {
588
- transport;
589
- spaceId;
590
- constructor(transport, spaceId) {
591
- this.transport = transport;
592
- this.spaceId = spaceId;
593
- }
594
- list() {
595
- return this.transport.request(`/api/spaces/${this.spaceId}/channels`);
596
- }
597
- bind(channelId, config) {
598
- return this.transport.request(`/api/spaces/${this.spaceId}/channels/${channelId}`, {
599
- method: "POST",
600
- headers: { "Content-Type": "application/json" },
601
- body: JSON.stringify({ config: config ?? null }),
602
- });
603
- }
604
- unbind(channelId) {
605
- return this.transport.request(`/api/spaces/${this.spaceId}/channels/${channelId}`, { method: "DELETE" });
606
- }
607
- }
608
- export class SpaceEnvApi {
609
- transport;
610
- spaceId;
611
- constructor(transport, spaceId) {
612
- this.transport = transport;
613
- this.spaceId = spaceId;
614
- }
615
- list() {
616
- return this.transport.request(`/api/spaces/${this.spaceId}/env`);
617
- }
618
- create(input) {
619
- return this.transport.request(`/api/spaces/${this.spaceId}/env`, {
620
- method: "POST",
621
- headers: { "Content-Type": "application/json" },
622
- body: JSON.stringify(input),
623
- });
624
- }
625
- update(name, value) {
626
- return this.transport.request(`/api/spaces/${this.spaceId}/env/${encodeURIComponent(name)}`, {
627
- method: "PUT",
628
- headers: { "Content-Type": "application/json" },
629
- body: JSON.stringify({ value }),
630
- });
631
- }
632
- remove(name) {
633
- return this.transport.request(`/api/spaces/${this.spaceId}/env/${encodeURIComponent(name)}`, { method: "DELETE" });
634
- }
635
- }
636
- export class SpaceSandboxApi {
637
- transport;
638
- spaceId;
639
- constructor(transport, spaceId) {
640
- this.transport = transport;
641
- this.spaceId = spaceId;
642
- }
643
- get() {
644
- return this.transport.request(`/api/spaces/${this.spaceId}/sandbox`);
645
- }
646
- ports() {
647
- return this.transport.request(`/api/spaces/${this.spaceId}/sandbox/ports`);
648
- }
649
- recreate() {
650
- return this.transport.request(`/api/spaces/${this.spaceId}/sandbox/recreate`, {
651
- method: "POST",
652
- });
653
- }
654
- }
655
- export class SpaceMarksApi {
656
- transport;
657
- spaceId;
658
- constructor(transport, spaceId) {
659
- this.transport = transport;
660
- this.spaceId = spaceId;
661
- }
662
- list(kind = "pin") {
663
- const params = new URLSearchParams({ kind });
664
- return this.transport.request(`/api/spaces/${this.spaceId}/marks?${params.toString()}`);
665
- }
666
- create(input) {
667
- return this.transport.request(`/api/spaces/${this.spaceId}/marks`, {
668
- method: "POST",
669
- headers: { "Content-Type": "application/json" },
670
- body: JSON.stringify({ kind: "pin", ...input }),
671
- });
672
- }
673
- delete(markId) {
674
- return this.transport.request(`/api/spaces/${this.spaceId}/marks/${markId}`, { method: "DELETE" });
675
- }
676
- }
677
- export class SpaceCheckpointsApi {
678
- transport;
679
- spaceId;
680
- constructor(transport, spaceId) {
681
- this.transport = transport;
682
- this.spaceId = spaceId;
683
- }
684
- create(description) {
685
- return this.transport.request(`/api/spaces/${this.spaceId}/checkpoints`, {
686
- method: "POST",
687
- headers: { "Content-Type": "application/json" },
688
- body: JSON.stringify({ description: description ?? null }),
689
- });
690
- }
691
- list() {
692
- return this.transport.request(`/api/spaces/${this.spaceId}/checkpoints`);
693
- }
694
- get(checkpointId, customFetch) {
695
- return this.transport.request(`/api/spaces/${this.spaceId}/checkpoints/${checkpointId}`, { fetch: customFetch });
696
- }
697
- }
698
- export class SpaceClient {
699
- id;
700
- transport;
701
- websocketClient;
702
- files;
703
- sessions;
704
- members;
705
- access;
706
- checkpoints;
707
- usage;
708
- channels;
709
- env;
710
- sandbox;
711
- invitations;
712
- marks;
713
- constructor(id, transport, websocketClient) {
714
- this.id = id;
715
- this.transport = transport;
716
- this.websocketClient = websocketClient;
717
- this.files = new SpaceFilesApi(transport, id);
718
- this.sessions = new SpaceSessionsApi(transport, id, websocketClient);
719
- this.members = new SpaceMembersApi(transport, id);
720
- this.access = new SpaceAccessApi(transport, id);
721
- this.checkpoints = new SpaceCheckpointsApi(transport, id);
722
- this.usage = new SpaceUsageApi(transport, id);
723
- this.channels = new SpaceChannelsApi(transport, id);
724
- this.env = new SpaceEnvApi(transport, id);
725
- this.sandbox = new SpaceSandboxApi(transport, id);
726
- this.invitations = new SpaceInvitationsApi(transport, id);
727
- this.marks = new SpaceMarksApi(transport, id);
728
- }
729
- get(customFetch) {
730
- return this.transport.request(`/api/spaces/${this.id}`, {
731
- fetch: customFetch,
732
- });
733
- }
734
- prompt(input) {
735
- return this.transport.request(`/api/spaces/${this.id}/prompt`, {
736
- method: "POST",
737
- headers: { "Content-Type": "application/json" },
738
- body: JSON.stringify(input),
739
- });
740
- }
741
- rename(name) {
742
- return this.transport.request(`/api/spaces/${this.id}`, {
743
- method: "PATCH",
744
- headers: {
745
- "Content-Type": "application/json",
746
- },
747
- body: JSON.stringify({ name }),
748
- });
749
- }
750
- profile(body) {
751
- return this.transport.request(`/api/spaces/${this.id}/profile`, {
752
- method: "PATCH",
753
- headers: { "Content-Type": "application/json" },
754
- body: JSON.stringify(body),
755
- });
756
- }
757
- session(sessionId) {
758
- return new SessionClient(this.id, sessionId, this.transport, this.websocketClient);
759
- }
760
- subscribe(handler) {
761
- return new SpaceEventsApi(this.websocketClient, this.id).subscribe(handler);
762
- }
763
- on(type, handler) {
764
- return new SpaceEventsApi(this.websocketClient, this.id).on(type, handler);
765
- }
766
- }