@tangle-network/sandbox 0.1.2 → 0.2.1
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/README.md +490 -2
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +271 -1
- package/dist/client-Uve6A5C6.js +2280 -0
- package/dist/collaboration/index.d.ts +1 -1
- package/dist/collaboration/index.js +2 -1
- package/dist/collaboration-CRyb5e8F.js +201 -0
- package/dist/core.d.ts +3 -3
- package/dist/core.js +4 -1
- package/dist/errors-BI75IXOM.d.ts +1177 -0
- package/dist/errors-CljiGR__.js +262 -0
- package/dist/{index-BuS8nl3b.d.ts → index-CCsA3S0D.d.ts} +6 -1
- package/dist/{index-t7xkzv0U.d.ts → index-DhNGZ0h4.d.ts} +3 -3
- package/dist/{index-gA-oRjOi.d.ts → index-Dpj1oB5i.d.ts} +35 -4
- package/dist/index.d.ts +109 -62
- package/dist/index.js +825 -1
- package/dist/openai/index.d.ts +642 -0
- package/dist/openai/index.js +1721 -0
- package/dist/platform-integrations.d.ts +2 -0
- package/dist/platform-integrations.js +2 -0
- package/dist/{sandbox-BvZ0-Iv7.d.ts → sandbox-aBpWqler.d.ts} +1528 -41
- package/dist/sandbox-ksXTNlo-.js +3394 -0
- package/dist/session-gateway/index.js +667 -1
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +2 -1
- package/dist/tangle-DQ05paN7.js +826 -0
- package/package.json +93 -34
- package/LICENSE +0 -11
- package/dist/client-CcRvqt85.js +0 -1
- package/dist/collaboration-CVvhPU8M.js +0 -1
- package/dist/errors-AIT8qikt.d.ts +0 -491
- package/dist/errors-CdMTv7uG.js +0 -1
- package/dist/sandbox-D1JnQIJx.js +0 -1
- package/dist/tangle-CSb9rjAh.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as CollaborationTransportConfig, a as CollaborationClient, c as CollaborationClientConfig, d as CollaborationDocumentRef, f as CollaborationFileBridgeOptions, g as CollaborationTokenRefreshResponse, h as CollaborationTokenRefreshRequest, i as parseCollaborationDocumentId, l as CollaborationDocumentAdapter, m as CollaborationPermissions, n as buildCollaborationDocumentId, o as CollaborationBootstrapRequest, p as CollaborationFileEvent, r as normalizeCollaborationPath, s as CollaborationBootstrapResponse, t as CollaborationFileBridge, u as CollaborationDocumentChange, v as SaveCollaborationSnapshotRequest, y as SaveCollaborationSnapshotResponse } from "../index-
|
|
1
|
+
import { _ as CollaborationTransportConfig, a as CollaborationClient, c as CollaborationClientConfig, d as CollaborationDocumentRef, f as CollaborationFileBridgeOptions, g as CollaborationTokenRefreshResponse, h as CollaborationTokenRefreshRequest, i as parseCollaborationDocumentId, l as CollaborationDocumentAdapter, m as CollaborationPermissions, n as buildCollaborationDocumentId, o as CollaborationBootstrapRequest, p as CollaborationFileEvent, r as normalizeCollaborationPath, s as CollaborationBootstrapResponse, t as CollaborationFileBridge, u as CollaborationDocumentChange, v as SaveCollaborationSnapshotRequest, y as SaveCollaborationSnapshotResponse } from "../index-CCsA3S0D.js";
|
|
2
2
|
export { CollaborationBootstrapRequest, CollaborationBootstrapResponse, CollaborationClient, CollaborationClientConfig, CollaborationDocumentAdapter, CollaborationDocumentChange, CollaborationDocumentRef, CollaborationFileBridge, CollaborationFileBridgeOptions, CollaborationFileEvent, CollaborationPermissions, CollaborationTokenRefreshRequest, CollaborationTokenRefreshResponse, CollaborationTransportConfig, SaveCollaborationSnapshotRequest, SaveCollaborationSnapshotResponse, buildCollaborationDocumentId, normalizeCollaborationPath, parseCollaborationDocumentId };
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { a as CollaborationClient, i as parseCollaborationDocumentId, n as buildCollaborationDocumentId, r as normalizeCollaborationPath, t as CollaborationFileBridge } from "../collaboration-CRyb5e8F.js";
|
|
2
|
+
export { CollaborationClient, CollaborationFileBridge, buildCollaborationDocumentId, normalizeCollaborationPath, parseCollaborationDocumentId };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { f as parseErrorResponse, r as NetworkError, u as TimeoutError } from "./errors-CljiGR__.js";
|
|
2
|
+
//#region src/collaboration/client.ts
|
|
3
|
+
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
4
|
+
function normalizeBaseUrl(url) {
|
|
5
|
+
return url.replace(/\/+$/, "");
|
|
6
|
+
}
|
|
7
|
+
var CollaborationClient = class {
|
|
8
|
+
baseUrl;
|
|
9
|
+
timeoutMs;
|
|
10
|
+
fetchImpl;
|
|
11
|
+
headers;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.baseUrl = normalizeBaseUrl(config.baseUrl);
|
|
14
|
+
this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
15
|
+
this.fetchImpl = config.fetch ?? globalThis.fetch.bind(globalThis);
|
|
16
|
+
this.headers = config.headers;
|
|
17
|
+
}
|
|
18
|
+
async bootstrap(request) {
|
|
19
|
+
return this.requestJson("/api/collaboration/bootstrap", {
|
|
20
|
+
method: "POST",
|
|
21
|
+
body: JSON.stringify(request)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async refreshToken(request) {
|
|
25
|
+
return this.requestJson("/api/collaboration/token", {
|
|
26
|
+
method: "POST",
|
|
27
|
+
body: JSON.stringify(request)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async saveSnapshot(request) {
|
|
31
|
+
return this.requestJson("/api/collaboration/snapshot", {
|
|
32
|
+
method: "POST",
|
|
33
|
+
body: JSON.stringify(request)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async requestJson(path, init) {
|
|
37
|
+
const controller = new AbortController();
|
|
38
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
39
|
+
try {
|
|
40
|
+
const headers = new Headers(await this.resolveHeaders());
|
|
41
|
+
if (!headers.has("Content-Type")) headers.set("Content-Type", "application/json");
|
|
42
|
+
const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
43
|
+
...init,
|
|
44
|
+
headers,
|
|
45
|
+
signal: init.signal ?? controller.signal
|
|
46
|
+
});
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
const body = await response.text();
|
|
49
|
+
throw parseErrorResponse(response.status, body, {
|
|
50
|
+
method: init.method,
|
|
51
|
+
path
|
|
52
|
+
}, response.headers);
|
|
53
|
+
}
|
|
54
|
+
return response.json();
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (error instanceof Error && error.name === "AbortError") throw new TimeoutError(this.timeoutMs);
|
|
57
|
+
if (error instanceof Error && "code" in error) throw error;
|
|
58
|
+
throw new NetworkError(`Failed to connect to collaboration API: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : void 0);
|
|
59
|
+
} finally {
|
|
60
|
+
clearTimeout(timeoutId);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async resolveHeaders() {
|
|
64
|
+
if (typeof this.headers === "function") return this.headers();
|
|
65
|
+
return this.headers;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/collaboration/document-id.ts
|
|
70
|
+
const DOCUMENT_PREFIX = "workspace:";
|
|
71
|
+
const FILE_SEGMENT = ":file:";
|
|
72
|
+
function assertValidWorkspaceId(workspaceId) {
|
|
73
|
+
if (!workspaceId) throw new Error("workspaceId is required");
|
|
74
|
+
if (workspaceId.includes("/") || workspaceId.includes("\\") || workspaceId.includes("\0")) throw new Error("workspaceId must not contain path separators or null bytes");
|
|
75
|
+
}
|
|
76
|
+
function normalizeCollaborationPath(path) {
|
|
77
|
+
if (!path) throw new Error("relativePath is required");
|
|
78
|
+
const normalized = path.replace(/\\/g, "/").split("/").filter((segment) => segment.length > 0 && segment !== ".");
|
|
79
|
+
if (normalized.length === 0) throw new Error("relativePath must not be empty");
|
|
80
|
+
for (const segment of normalized) {
|
|
81
|
+
if (segment === "..") throw new Error("relativePath must not contain \"..\"");
|
|
82
|
+
if (segment.includes("\0")) throw new Error("relativePath must not contain null bytes");
|
|
83
|
+
}
|
|
84
|
+
return normalized.join("/");
|
|
85
|
+
}
|
|
86
|
+
function buildCollaborationDocumentId(ref) {
|
|
87
|
+
assertValidWorkspaceId(ref.workspaceId);
|
|
88
|
+
const relativePath = normalizeCollaborationPath(ref.relativePath);
|
|
89
|
+
return `${DOCUMENT_PREFIX}${ref.workspaceId}${FILE_SEGMENT}${relativePath}`;
|
|
90
|
+
}
|
|
91
|
+
function parseCollaborationDocumentId(documentId) {
|
|
92
|
+
if (!documentId.startsWith(DOCUMENT_PREFIX)) return null;
|
|
93
|
+
const separatorIndex = documentId.indexOf(FILE_SEGMENT, 10);
|
|
94
|
+
if (separatorIndex === -1) return null;
|
|
95
|
+
const workspaceId = documentId.slice(10, separatorIndex);
|
|
96
|
+
const relativePath = documentId.slice(separatorIndex + 6);
|
|
97
|
+
try {
|
|
98
|
+
assertValidWorkspaceId(workspaceId);
|
|
99
|
+
return {
|
|
100
|
+
workspaceId,
|
|
101
|
+
relativePath: normalizeCollaborationPath(relativePath)
|
|
102
|
+
};
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/collaboration/file-bridge.ts
|
|
109
|
+
const DEFAULT_DEBOUNCE_MS = 500;
|
|
110
|
+
const FILE_ORIGIN = "bridge:file";
|
|
111
|
+
/**
|
|
112
|
+
* Headless bridge between a collaborative document adapter and the sandbox
|
|
113
|
+
* filesystem. Keeps this package free of direct Yjs assumptions.
|
|
114
|
+
*/
|
|
115
|
+
var CollaborationFileBridge = class {
|
|
116
|
+
debounceMs;
|
|
117
|
+
options;
|
|
118
|
+
adapter = null;
|
|
119
|
+
unsubscribeDocument = null;
|
|
120
|
+
unsubscribeFileEvents = null;
|
|
121
|
+
pendingWriteTimer = null;
|
|
122
|
+
destroyed = false;
|
|
123
|
+
boundPath;
|
|
124
|
+
lastWrittenContent = null;
|
|
125
|
+
constructor(options) {
|
|
126
|
+
this.options = options;
|
|
127
|
+
this.boundPath = options.relativePath;
|
|
128
|
+
this.debounceMs = options.debounceMs ?? DEFAULT_DEBOUNCE_MS;
|
|
129
|
+
}
|
|
130
|
+
bind(adapter) {
|
|
131
|
+
this.destroy();
|
|
132
|
+
this.destroyed = false;
|
|
133
|
+
this.adapter = adapter;
|
|
134
|
+
this.boundPath = this.options.relativePath;
|
|
135
|
+
this.unsubscribeDocument = adapter.subscribe((change) => {
|
|
136
|
+
if (change.origin === FILE_ORIGIN) return;
|
|
137
|
+
if (this.lastWrittenContent !== null && change.content === this.lastWrittenContent) return;
|
|
138
|
+
this.scheduleWrite(change.content);
|
|
139
|
+
});
|
|
140
|
+
this.unsubscribeFileEvents = this.options.subscribeToFileEvents(this.boundPath, (event) => {
|
|
141
|
+
this.handleFileEvent(event);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
async flush() {
|
|
145
|
+
if (!this.adapter) return;
|
|
146
|
+
if (this.pendingWriteTimer) {
|
|
147
|
+
clearTimeout(this.pendingWriteTimer);
|
|
148
|
+
this.pendingWriteTimer = null;
|
|
149
|
+
}
|
|
150
|
+
const content = this.adapter.getContent();
|
|
151
|
+
await this.write(content);
|
|
152
|
+
}
|
|
153
|
+
getPath() {
|
|
154
|
+
return this.boundPath;
|
|
155
|
+
}
|
|
156
|
+
destroy() {
|
|
157
|
+
this.destroyed = true;
|
|
158
|
+
if (this.pendingWriteTimer) {
|
|
159
|
+
clearTimeout(this.pendingWriteTimer);
|
|
160
|
+
this.pendingWriteTimer = null;
|
|
161
|
+
}
|
|
162
|
+
this.unsubscribeDocument?.();
|
|
163
|
+
this.unsubscribeDocument = null;
|
|
164
|
+
this.unsubscribeFileEvents?.();
|
|
165
|
+
this.unsubscribeFileEvents = null;
|
|
166
|
+
this.adapter = null;
|
|
167
|
+
}
|
|
168
|
+
scheduleWrite(content) {
|
|
169
|
+
if (this.pendingWriteTimer) clearTimeout(this.pendingWriteTimer);
|
|
170
|
+
this.pendingWriteTimer = setTimeout(() => {
|
|
171
|
+
this.pendingWriteTimer = null;
|
|
172
|
+
this.write(content);
|
|
173
|
+
}, this.debounceMs);
|
|
174
|
+
}
|
|
175
|
+
async write(content) {
|
|
176
|
+
if (this.destroyed) return;
|
|
177
|
+
this.lastWrittenContent = content;
|
|
178
|
+
await this.options.writeFile(this.boundPath, content);
|
|
179
|
+
}
|
|
180
|
+
handleFileEvent(event) {
|
|
181
|
+
if (!this.adapter || this.destroyed) return;
|
|
182
|
+
if (event.type === "renamed" && event.nextPath) {
|
|
183
|
+
this.boundPath = event.nextPath;
|
|
184
|
+
this.options.onFileRenamed?.(event);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (event.type === "deleted") {
|
|
188
|
+
this.options.onFileDeleted?.(event);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (event.type !== "updated" || typeof event.content !== "string") return;
|
|
192
|
+
if (event.content === this.adapter.getContent()) return;
|
|
193
|
+
if (this.lastWrittenContent !== null && event.content === this.lastWrittenContent) return;
|
|
194
|
+
this.adapter.replaceContent(event.content, {
|
|
195
|
+
origin: FILE_ORIGIN,
|
|
196
|
+
version: event.version
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
//#endregion
|
|
201
|
+
export { CollaborationClient as a, parseCollaborationDocumentId as i, buildCollaborationDocumentId as n, normalizeCollaborationPath as r, CollaborationFileBridge as t };
|
package/dist/core.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export { AuthError, type CreateSandboxOptions, type ExecOptions, type ExecResult, type NetworkConfig, NetworkError, NotFoundError, type PreviewLinkInfo, type PreviewLinkManager, QuotaError, SandboxClient as Sandbox, SandboxClient, type SandboxClientConfig, SandboxError, type SandboxInfo, SandboxInstance, type SandboxStatus, ServerError, StateError, TimeoutError, ValidationError };
|
|
1
|
+
import { _ as SandboxClient, a as PartialFailureError, c as SandboxErrorJson, d as StateError, f as TimeoutError, i as NotFoundError, l as SandboxFailureDetail, n as CapabilityError, o as QuotaError, p as ValidationError, r as NetworkError, s as SandboxError, t as AuthError, u as ServerError } from "./errors-BI75IXOM.js";
|
|
2
|
+
import { At as PreviewLinkManager, G as ExecOptions, K as ExecResult, Ln as SandboxStatus, Nn as SandboxInfo, P as CreateSandboxOptions, Tt as NetworkConfig, kt as PreviewLinkInfo, n as SandboxInstance, nn as SandboxClientConfig } from "./sandbox-aBpWqler.js";
|
|
3
|
+
export { AuthError, CapabilityError, type CreateSandboxOptions, type ExecOptions, type ExecResult, type NetworkConfig, NetworkError, NotFoundError, PartialFailureError, type PreviewLinkInfo, type PreviewLinkManager, QuotaError, SandboxClient as Sandbox, SandboxClient, type SandboxClientConfig, SandboxError, type SandboxErrorJson, type SandboxFailureDetail, type SandboxInfo, SandboxInstance, type SandboxStatus, ServerError, StateError, TimeoutError, ValidationError };
|
package/dist/core.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { a as PartialFailureError, c as ServerError, d as ValidationError, i as NotFoundError, l as StateError, n as CapabilityError, o as QuotaError, r as NetworkError, s as SandboxError, t as AuthError, u as TimeoutError } from "./errors-CljiGR__.js";
|
|
2
|
+
import { t as SandboxInstance } from "./sandbox-ksXTNlo-.js";
|
|
3
|
+
import { n as SandboxClient } from "./client-Uve6A5C6.js";
|
|
4
|
+
export { AuthError, CapabilityError, NetworkError, NotFoundError, PartialFailureError, QuotaError, SandboxClient as Sandbox, SandboxClient, SandboxError, SandboxInstance, ServerError, StateError, TimeoutError, ValidationError };
|