@tangle-network/agent-app 0.50.13 → 0.50.14
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.
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { WorkspaceAppRecord } from './index';
|
|
2
|
+
export interface WorkspaceAppDataEntry {
|
|
3
|
+
value: string;
|
|
4
|
+
revision: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class WorkspaceAppDataConflict extends Error {
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
export interface WorkspaceAppDataHostOptions {
|
|
10
|
+
/** Product-authorized registration for the current viewer. */
|
|
11
|
+
app: Pick<WorkspaceAppRecord, 'id' | 'previewUrl' | 'status'>;
|
|
12
|
+
frame: HTMLIFrameElement;
|
|
13
|
+
/** Product callbacks are bound to the authorized business and app namespace. */
|
|
14
|
+
read(key: string): Promise<WorkspaceAppDataEntry | null>;
|
|
15
|
+
/** Null creates only if absent; a revision updates only that version. */
|
|
16
|
+
write(key: string, value: string, expectedRevision: number | null): Promise<{
|
|
17
|
+
revision: number;
|
|
18
|
+
}>;
|
|
19
|
+
remove(key: string, expectedRevision: number): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export interface WorkspaceAppDataHost {
|
|
22
|
+
dispose(): void;
|
|
23
|
+
}
|
|
24
|
+
export interface WorkspaceAppDataClientOptions {
|
|
25
|
+
appId: string;
|
|
26
|
+
/** Exact authenticated product origin, provided by the product. */
|
|
27
|
+
parentOrigin: string;
|
|
28
|
+
}
|
|
29
|
+
export interface WorkspaceAppDataClient {
|
|
30
|
+
ready(): Promise<void>;
|
|
31
|
+
read(key: string): Promise<WorkspaceAppDataEntry | null>;
|
|
32
|
+
write(key: string, value: string, expectedRevision: number | null): Promise<{
|
|
33
|
+
revision: number;
|
|
34
|
+
}>;
|
|
35
|
+
remove(key: string, expectedRevision: number): Promise<void>;
|
|
36
|
+
dispose(): void;
|
|
37
|
+
}
|
|
38
|
+
/** Bind one registered preview to a product-authorized data adapter. */
|
|
39
|
+
export declare function createWorkspaceAppDataHost(options: WorkspaceAppDataHostOptions): WorkspaceAppDataHost;
|
|
40
|
+
/** Use inside a registered preview; no product credential crosses the frame. */
|
|
41
|
+
export declare function createWorkspaceAppDataClient(options: WorkspaceAppDataClientOptions): WorkspaceAppDataClient;
|
|
@@ -70,3 +70,5 @@ export type WorkspaceAppBuilderInstructionsOptions = {
|
|
|
70
70
|
};
|
|
71
71
|
/** Portable instructions for an agent profile that builds workspace apps. */
|
|
72
72
|
export declare function workspaceAppBuilderInstructions(options: WorkspaceAppBuilderInstructionsOptions): string[];
|
|
73
|
+
export { WorkspaceAppDataConflict, createWorkspaceAppDataClient, createWorkspaceAppDataHost, } from './data-bridge';
|
|
74
|
+
export type { WorkspaceAppDataClient, WorkspaceAppDataClientOptions, WorkspaceAppDataEntry, WorkspaceAppDataHost, WorkspaceAppDataHostOptions, } from './data-bridge';
|
|
@@ -1,3 +1,203 @@
|
|
|
1
|
+
// src/workspace-apps/data-bridge.ts
|
|
2
|
+
var protocol = "tangle.workspace-app-data.v1";
|
|
3
|
+
var maxBytes = 65536;
|
|
4
|
+
var maxPending = 16;
|
|
5
|
+
var keyPattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,79}$/;
|
|
6
|
+
var idPattern = /^[A-Za-z0-9_-]{1,80}$/;
|
|
7
|
+
var WorkspaceAppDataConflict = class extends Error {
|
|
8
|
+
constructor() {
|
|
9
|
+
super("Workspace app data changed. Read it again before saving.");
|
|
10
|
+
this.name = "WorkspaceAppDataConflict";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
function object(value) {
|
|
14
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
function key(value) {
|
|
17
|
+
return typeof value === "string" && keyPattern.test(value) && value !== "." && value !== "..";
|
|
18
|
+
}
|
|
19
|
+
function revision(value) {
|
|
20
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
21
|
+
}
|
|
22
|
+
function bounded(value) {
|
|
23
|
+
return typeof value === "string" && value.length <= maxBytes && new TextEncoder().encode(value).byteLength <= maxBytes;
|
|
24
|
+
}
|
|
25
|
+
function appId(value) {
|
|
26
|
+
if (!idPattern.test(value)) throw new Error("Invalid workspace app ID");
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function origin(value) {
|
|
30
|
+
const url = new URL(value);
|
|
31
|
+
if (url.origin !== value || url.protocol !== "https:" && !(url.protocol === "http:" && ["localhost", "127.0.0.1"].includes(url.hostname))) {
|
|
32
|
+
throw new Error("Invalid workspace app data origin");
|
|
33
|
+
}
|
|
34
|
+
return url.origin;
|
|
35
|
+
}
|
|
36
|
+
function packet(value) {
|
|
37
|
+
return object(value) && value.protocol === protocol && typeof value.appId === "string" && typeof value.requestId === "string" && /^[A-Za-z0-9_-]{1,64}$/.test(value.requestId) && typeof value.action === "string" && ["ready", "read", "write", "remove"].includes(value.action);
|
|
38
|
+
}
|
|
39
|
+
function createWorkspaceAppDataHost(options) {
|
|
40
|
+
const { app, frame } = options;
|
|
41
|
+
appId(app.id);
|
|
42
|
+
if (app.status !== "ready") throw new Error("Workspace app is not ready");
|
|
43
|
+
const preview = new URL(app.previewUrl);
|
|
44
|
+
const previewOrigin = origin(preview.origin);
|
|
45
|
+
if (preview.protocol !== "https:" || preview.username || preview.password || preview.search || preview.hash || new URL(frame.src).href !== preview.href) {
|
|
46
|
+
throw new Error("Iframe does not render the registered workspace app preview");
|
|
47
|
+
}
|
|
48
|
+
let closed = false;
|
|
49
|
+
let active = 0;
|
|
50
|
+
let messagesLeft = 64;
|
|
51
|
+
let nextWindow = Date.now() + 1e3;
|
|
52
|
+
const onMessage = (event) => {
|
|
53
|
+
if (closed || event.source !== frame.contentWindow || event.origin !== previewOrigin || !packet(event.data) || event.data.appId !== app.id) return;
|
|
54
|
+
const now = Date.now();
|
|
55
|
+
if (now >= nextWindow) {
|
|
56
|
+
messagesLeft = 64;
|
|
57
|
+
nextWindow = now + 1e3;
|
|
58
|
+
}
|
|
59
|
+
if (messagesLeft-- <= 0) return;
|
|
60
|
+
const message = event.data;
|
|
61
|
+
const reply = (result) => {
|
|
62
|
+
if (closed || event.source !== frame.contentWindow) return;
|
|
63
|
+
frame.contentWindow?.postMessage({
|
|
64
|
+
protocol,
|
|
65
|
+
appId: app.id,
|
|
66
|
+
requestId: message.requestId,
|
|
67
|
+
action: message.action,
|
|
68
|
+
...result
|
|
69
|
+
}, previewOrigin);
|
|
70
|
+
};
|
|
71
|
+
if (message.action === "ready") {
|
|
72
|
+
reply({ ok: true });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!key(message.key) || message.action === "write" && (!bounded(message.value) || !(message.expectedRevision === null || revision(message.expectedRevision))) || message.action === "remove" && !revision(message.expectedRevision)) {
|
|
76
|
+
reply({ ok: false, error: "invalid" });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (active >= maxPending) {
|
|
80
|
+
reply({ ok: false, error: "unavailable" });
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
active += 1;
|
|
84
|
+
const checkedKey = message.key;
|
|
85
|
+
void (async () => {
|
|
86
|
+
try {
|
|
87
|
+
if (message.action === "read") {
|
|
88
|
+
const entry = await options.read(checkedKey);
|
|
89
|
+
if (entry !== null && (!bounded(entry.value) || !revision(entry.revision))) throw new Error("Invalid entry");
|
|
90
|
+
reply({ ok: true, entry });
|
|
91
|
+
} else if (message.action === "write") {
|
|
92
|
+
const result = await options.write(checkedKey, message.value, message.expectedRevision);
|
|
93
|
+
if (!revision(result.revision)) throw new Error("Invalid revision");
|
|
94
|
+
reply({ ok: true, revision: result.revision });
|
|
95
|
+
} else {
|
|
96
|
+
await options.remove(checkedKey, message.expectedRevision);
|
|
97
|
+
reply({ ok: true });
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
reply({ ok: false, error: error instanceof WorkspaceAppDataConflict ? "conflict" : "unavailable" });
|
|
101
|
+
} finally {
|
|
102
|
+
active -= 1;
|
|
103
|
+
}
|
|
104
|
+
})();
|
|
105
|
+
};
|
|
106
|
+
window.addEventListener("message", onMessage);
|
|
107
|
+
return { dispose() {
|
|
108
|
+
closed = true;
|
|
109
|
+
window.removeEventListener("message", onMessage);
|
|
110
|
+
} };
|
|
111
|
+
}
|
|
112
|
+
function createWorkspaceAppDataClient(options) {
|
|
113
|
+
const id = appId(options.appId);
|
|
114
|
+
const parentOrigin = origin(options.parentOrigin);
|
|
115
|
+
if (window.parent === window) throw new Error("Workspace app data requires an embedded preview");
|
|
116
|
+
const pending = /* @__PURE__ */ new Map();
|
|
117
|
+
let closed = false;
|
|
118
|
+
let readyPromise;
|
|
119
|
+
const onMessage = (event) => {
|
|
120
|
+
if (closed || event.source !== window.parent || event.origin !== parentOrigin || !packet(event.data) || event.data.appId !== id || typeof event.data.ok !== "boolean") return;
|
|
121
|
+
const waiting = pending.get(event.data.requestId);
|
|
122
|
+
if (!waiting || waiting.action !== event.data.action) return;
|
|
123
|
+
pending.delete(event.data.requestId);
|
|
124
|
+
clearTimeout(waiting.timeout);
|
|
125
|
+
if (event.data.ok) waiting.resolve(event.data);
|
|
126
|
+
else waiting.reject(event.data.error === "conflict" ? new WorkspaceAppDataConflict() : new Error("Workspace app data unavailable"));
|
|
127
|
+
};
|
|
128
|
+
window.addEventListener("message", onMessage);
|
|
129
|
+
const send = (action, fields = {}, timeoutMs = 1e4) => {
|
|
130
|
+
if (closed) return Promise.reject(new Error("Workspace app data client is closed"));
|
|
131
|
+
if (pending.size >= maxPending) return Promise.reject(new Error("Too many workspace app data requests"));
|
|
132
|
+
const requestId = crypto.randomUUID();
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
const timeout = setTimeout(() => {
|
|
135
|
+
pending.delete(requestId);
|
|
136
|
+
reject(new Error("Workspace app data timed out"));
|
|
137
|
+
}, timeoutMs);
|
|
138
|
+
pending.set(requestId, { action, resolve, reject, timeout });
|
|
139
|
+
window.parent.postMessage({ protocol, appId: id, requestId, action, ...fields }, parentOrigin);
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
const ready = () => {
|
|
143
|
+
if (readyPromise) return readyPromise;
|
|
144
|
+
readyPromise = new Promise((resolve, reject) => {
|
|
145
|
+
const deadline = Date.now() + 1e4;
|
|
146
|
+
const attempt = () => {
|
|
147
|
+
if (closed) {
|
|
148
|
+
reject(new Error("Workspace app data client is closed"));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (Date.now() >= deadline) {
|
|
152
|
+
reject(new Error("Workspace app data host did not become ready"));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
void send("ready", {}, 300).then(() => resolve(), () => setTimeout(attempt, 200));
|
|
156
|
+
};
|
|
157
|
+
attempt();
|
|
158
|
+
}).catch((error) => {
|
|
159
|
+
readyPromise = void 0;
|
|
160
|
+
throw error;
|
|
161
|
+
});
|
|
162
|
+
return readyPromise;
|
|
163
|
+
};
|
|
164
|
+
return {
|
|
165
|
+
ready,
|
|
166
|
+
async read(value) {
|
|
167
|
+
if (!key(value)) throw new Error("Invalid workspace app data key");
|
|
168
|
+
await ready();
|
|
169
|
+
const response = await send("read", { key: value });
|
|
170
|
+
if (response.entry !== null && (!object(response.entry) || !bounded(response.entry.value) || !revision(response.entry.revision))) {
|
|
171
|
+
throw new Error("Invalid workspace app data response");
|
|
172
|
+
}
|
|
173
|
+
return response.entry ?? null;
|
|
174
|
+
},
|
|
175
|
+
async write(value, data, expectedRevision) {
|
|
176
|
+
if (!key(value) || !bounded(data) || !(expectedRevision === null || revision(expectedRevision))) {
|
|
177
|
+
throw new Error("Invalid workspace app data write");
|
|
178
|
+
}
|
|
179
|
+
await ready();
|
|
180
|
+
const response = await send("write", { key: value, value: data, expectedRevision });
|
|
181
|
+
if (!revision(response.revision)) throw new Error("Invalid workspace app data response");
|
|
182
|
+
return { revision: response.revision };
|
|
183
|
+
},
|
|
184
|
+
async remove(value, expectedRevision) {
|
|
185
|
+
if (!key(value) || !revision(expectedRevision)) throw new Error("Invalid workspace app data remove");
|
|
186
|
+
await ready();
|
|
187
|
+
await send("remove", { key: value, expectedRevision });
|
|
188
|
+
},
|
|
189
|
+
dispose() {
|
|
190
|
+
closed = true;
|
|
191
|
+
window.removeEventListener("message", onMessage);
|
|
192
|
+
for (const waiting of pending.values()) {
|
|
193
|
+
clearTimeout(waiting.timeout);
|
|
194
|
+
waiting.reject(new Error("Workspace app data client is closed"));
|
|
195
|
+
}
|
|
196
|
+
pending.clear();
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
1
201
|
// src/workspace-apps/index.ts
|
|
2
202
|
function nonempty(value, field) {
|
|
3
203
|
if (typeof value !== "string" || !value.trim() || /[\u0000-\u001f\u007f]/.test(value)) {
|
|
@@ -110,7 +310,10 @@ function workspaceAppBuilderInstructions(options) {
|
|
|
110
310
|
];
|
|
111
311
|
}
|
|
112
312
|
export {
|
|
313
|
+
WorkspaceAppDataConflict,
|
|
113
314
|
confirmWorkspaceAppReady,
|
|
315
|
+
createWorkspaceAppDataClient,
|
|
316
|
+
createWorkspaceAppDataHost,
|
|
114
317
|
refreshWorkspaceAppPreview,
|
|
115
318
|
workspaceAppBuilderInstructions,
|
|
116
319
|
workspaceAppFromPreviewLink
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/workspace-apps/index.ts"],"sourcesContent":["/** A sandbox app registered in one product workspace. Products persist and authorize these rows. */\nexport interface WorkspaceAppRecord {\n id: string\n workspaceId: string\n name: string\n sandboxId: string\n previewId: string\n port: number\n previewUrl: string\n status: 'starting' | 'ready' | 'unavailable'\n createdAt: string\n updatedAt: string\n}\n\n/** Structural shape returned by the Sandbox SDK previewLinks API. */\nexport interface WorkspaceAppPreviewLink {\n previewId: string\n sandboxId: string\n port: number\n protocol: 'tcp' | 'udp'\n hostname: string\n url: string\n status: 'provisioning' | 'ready' | 'error' | 'disabled'\n}\n\nexport interface WorkspaceAppIdentity {\n /** Assigned by the product, stable across preview updates and deliberate republishes. */\n id: string\n /** Taken from the authenticated route or session, never agent tool arguments. */\n workspaceId: string\n /** Current box resolved by the product from that workspace or session. */\n sandboxId: string\n name: string\n /** Preserve this when republishing the same app onto a replacement sandbox. */\n createdAt?: string\n updatedAt?: string\n}\n\nfunction nonempty(value: string, field: string): string {\n if (typeof value !== 'string' || !value.trim() || /[\\u0000-\\u001f\\u007f]/.test(value)) {\n throw new Error('Invalid workspace app ' + field)\n }\n return value.trim()\n}\n\nfunction checkedLink(link: WorkspaceAppPreviewLink, sandboxId: string): void {\n if (link.sandboxId !== sandboxId) {\n throw new Error('Preview link belongs to another sandbox')\n }\n nonempty(link.previewId, 'previewId')\n if (link.protocol !== 'tcp') throw new Error('Workspace app preview must use TCP')\n if (!Number.isInteger(link.port) || link.port < 1 || link.port > 65535) {\n throw new Error('Invalid workspace app port')\n }\n if (!['provisioning', 'ready', 'error', 'disabled'].includes(link.status)) {\n throw new Error('Invalid workspace app preview status')\n }\n let url: URL\n try {\n url = new URL(link.url)\n } catch {\n throw new Error('Invalid workspace app preview URL')\n }\n if (\n url.protocol !== 'https:' ||\n !url.hostname ||\n url.hostname !== link.hostname ||\n url.username ||\n url.password ||\n url.search ||\n url.hash\n ) {\n throw new Error('Invalid workspace app preview URL')\n }\n}\n\nfunction appStatus(status: WorkspaceAppPreviewLink['status']): WorkspaceAppRecord['status'] {\n if (status === 'ready' || status === 'provisioning') return 'starting'\n return 'unavailable'\n}\n\n/**\n * Build a durable registration from a preview link created on the box that\n * the authenticated product request resolved. The product owns row identity,\n * access policy, persistence, and the decision to publish.\n */\nexport function workspaceAppFromPreviewLink(\n identity: WorkspaceAppIdentity,\n link: WorkspaceAppPreviewLink,\n): WorkspaceAppRecord {\n const sandboxId = nonempty(identity.sandboxId, 'sandboxId')\n checkedLink(link, sandboxId)\n const timestamp = identity.updatedAt ?? new Date().toISOString()\n return {\n id: nonempty(identity.id, 'id'),\n workspaceId: nonempty(identity.workspaceId, 'workspaceId'),\n name: nonempty(identity.name, 'name'),\n sandboxId,\n previewId: link.previewId,\n port: link.port,\n previewUrl: link.url,\n status: appStatus(link.status),\n createdAt: identity.createdAt ?? timestamp,\n updatedAt: timestamp,\n }\n}\n\nexport interface WorkspaceAppHttpProof {\n /** The exact trusted SDK preview URL requested by the server. */\n previewUrl: string\n status: number\n contentType: string\n /** Number of bytes read from the response body, excluding headers. */\n bodyBytes: number\n checkedAt: string\n}\n\n/**\n * Mark an app ready only after the host fetched its HTML over the trusted\n * preview URL. The host owns the request timeout, redirect and credential\n * policy, authorization, and compare-and-swap storage update.\n */\nexport function confirmWorkspaceAppReady(\n app: WorkspaceAppRecord,\n proof: WorkspaceAppHttpProof,\n): WorkspaceAppRecord {\n if (\n proof.previewUrl !== app.previewUrl ||\n proof.status !== 200 ||\n !/^text\\/html(?:\\s*;|\\s*$)/i.test(proof.contentType) ||\n !Number.isInteger(proof.bodyBytes) ||\n proof.bodyBytes < 1 ||\n !Number.isFinite(Date.parse(proof.checkedAt))\n ) {\n throw new Error('Workspace app HTML preview is not ready')\n }\n return { ...app, status: 'ready', updatedAt: proof.checkedAt }\n}\n\n/** Refresh delivery state without changing which sandbox service this app means. */\nexport function refreshWorkspaceAppPreview(\n app: WorkspaceAppRecord,\n link: WorkspaceAppPreviewLink,\n updatedAt = new Date().toISOString(),\n): WorkspaceAppRecord {\n checkedLink(link, app.sandboxId)\n if (link.previewId !== app.previewId || link.port !== app.port) {\n throw new Error('Preview link does not match workspace app')\n }\n return {\n ...app,\n previewUrl: link.url,\n status: appStatus(link.status),\n updatedAt,\n }\n}\n\nexport type WorkspaceAppBuilderInstructionsOptions =\n | {\n /** Host tool that writes the registration after creating a trusted preview. */\n publishTool: string\n /** Optional host tool for finding app IDs the builder may update. */\n listTool?: string\n manifestPath?: never\n }\n | {\n /** Host-scoped manifest the builder writes after creating runnable projects. */\n manifestPath: string\n publishTool?: never\n listTool?: never\n }\n\nfunction toolName(value: string): string {\n if (!/^[A-Za-z][A-Za-z0-9_.-]*$/.test(value)) {\n throw new Error('Invalid workspace app tool name')\n }\n return value\n}\n\nfunction builderManifestPath(value: string): string {\n if (\n !/^[A-Za-z0-9._-]+(?:[/][A-Za-z0-9._-]+)*$/.test(value) ||\n value.split('/').some(segment => segment === '..' || segment === '.')\n ) {\n throw new Error('Invalid workspace app manifest path')\n }\n return value\n}\n\n/** Portable instructions for an agent profile that builds workspace apps. */\nexport function workspaceAppBuilderInstructions(\n options: WorkspaceAppBuilderInstructionsOptions,\n): string[] {\n const common = [\n 'Build a working HTTP application in the current sandbox when the user asks for an app.',\n 'Keep the same app ID for later revisions of that app.',\n 'Treat a preview link as public. Do not embed secrets or private business facts in client code or responses.',\n 'Read real business data through authorized product APIs. Do not fabricate records to make the app look complete.',\n 'Report the app as available only after the host confirms its preview is ready.',\n ] as const\n if (options.manifestPath !== undefined) {\n const path = builderManifestPath(options.manifestPath)\n return [\n common[0],\n 'Inspect the existing app projects and manifest before creating or updating an app.',\n 'Keep each runnable project under apps/<id> relative to the sandbox working directory. Give it a package.json dev script; its HTTP server must listen on 0.0.0.0 and use PORT when supplied.',\n 'Write ' + path + ' as JSON with exactly an apps array of { id, name, projectPath } records; each projectPath is apps/<id>.',\n 'Do not put URLs, credentials, tokens, sandbox IDs, or preview IDs in that manifest.',\n 'The host reads this manifest and owns server launch, port selection, preview creation, registration, and access policy.',\n ...common.slice(1),\n ]\n }\n const publish = toolName(options.publishTool)\n const list = options.listTool ? toolName(options.listTool) : undefined\n return [\n common[0],\n ...(list ? ['Use ' + list + ' to inspect the existing apps before creating or updating one.'] : []),\n 'Start its server on 0.0.0.0 using an available, unclaimed port.',\n 'Call ' + publish + ' with the app name, stable app ID when updating, and listening port.',\n 'Use the host tool result as the source of the registered app URL and status; never invent a preview URL.',\n ...common.slice(1),\n ]\n}\n"],"mappings":";AAsCA,SAAS,SAAS,OAAe,OAAuB;AACtD,MAAI,O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QAAM,SAAS;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,MAAI,QAAQ,iBAAiB,QAAW;AACtC,UAAM,OAAO,oBAAoB,QAAQ,YAAY;AACrD,WAAO;AAAA,MACL,OAAO,CAAC;AAAA,MACR;AAAA,MACA;AAAA,MACA,WAAW,OAAO;AAAA,MAClB;AAAA,MACA;AAAA,MACA,GAAG,OAAO,MAAM,CAAC;AAAA,IACnB;AAAA,EACF;AACA,QAAM,UAAU,SAAS,QAAQ,WAAW;AAC5C,QAAM,OAAO,QAAQ,WAAW,SAAS,QAAQ,QAAQ,IAAI;AAC7D,SAAO;AAAA,IACL,OAAO,CAAC;AAAA,IACR,GAAI,OAAO,CAAC,SAAS,OAAO,gEAAgE,IAAI,CAAC;AAAA,IACjG;AAAA,IACA,UAAU,UAAU;AAAA,IACpB;AAAA,IACA,GAAG,OAAO,MAAM,CAAC;AAAA,EACnB;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/workspace-apps/data-bridge.ts","../../src/workspace-apps/index.ts"],"sourcesContent":["import type { WorkspaceAppRecord } from './index'\n\nconst protocol = 'tangle.workspace-app-data.v1'\nconst maxBytes = 65_536\nconst maxPending = 16\nconst keyPattern = /^[A-Za-z0-9][A-Za-z0-9._-]{0,79}$/\nconst idPattern = /^[A-Za-z0-9_-]{1,80}$/\n\nexport interface WorkspaceAppDataEntry { value: string; revision: number }\nexport class WorkspaceAppDataConflict extends Error {\n constructor() {\n super('Workspace app data changed. Read it again before saving.')\n this.name = 'WorkspaceAppDataConflict'\n }\n}\nexport interface WorkspaceAppDataHostOptions {\n /** Product-authorized registration for the current viewer. */\n app: Pick<WorkspaceAppRecord, 'id' | 'previewUrl' | 'status'>\n frame: HTMLIFrameElement\n /** Product callbacks are bound to the authorized business and app namespace. */\n read(key: string): Promise<WorkspaceAppDataEntry | null>\n /** Null creates only if absent; a revision updates only that version. */\n write(key: string, value: string, expectedRevision: number | null): Promise<{ revision: number }>\n remove(key: string, expectedRevision: number): Promise<void>\n}\nexport interface WorkspaceAppDataHost { dispose(): void }\nexport interface WorkspaceAppDataClientOptions {\n appId: string\n /** Exact authenticated product origin, provided by the product. */\n parentOrigin: string\n}\nexport interface WorkspaceAppDataClient {\n ready(): Promise<void>\n read(key: string): Promise<WorkspaceAppDataEntry | null>\n write(key: string, value: string, expectedRevision: number | null): Promise<{ revision: number }>\n remove(key: string, expectedRevision: number): Promise<void>\n dispose(): void\n}\n\ntype Action = 'ready' | 'read' | 'write' | 'remove'\ntype Packet = {\n protocol: typeof protocol\n appId: string\n requestId: string\n action: Action\n key?: string\n value?: string\n expectedRevision?: number | null\n ok?: boolean\n entry?: WorkspaceAppDataEntry | null\n revision?: number\n error?: 'invalid' | 'conflict' | 'unavailable'\n}\nfunction object(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\nfunction key(value: unknown): value is string {\n return typeof value === 'string' && keyPattern.test(value) && value !== '.' && value !== '..'\n}\nfunction revision(value: unknown): value is number {\n return typeof value === 'number' && Number.isSafeInteger(value) && value > 0\n}\nfunction bounded(value: unknown): value is string {\n return typeof value === 'string' && value.length <= maxBytes && new TextEncoder().encode(value).byteLength <= maxBytes\n}\nfunction appId(value: string): string {\n if (!idPattern.test(value)) throw new Error('Invalid workspace app ID')\n return value\n}\nfunction origin(value: string): string {\n const url = new URL(value)\n if (url.origin !== value || (url.protocol !== 'https:' &&\n !(url.protocol === 'http:' && ['localhost', '127.0.0.1'].includes(url.hostname)))) {\n throw new Error('Invalid workspace app data origin')\n }\n return url.origin\n}\nfunction packet(value: unknown): value is Packet {\n return object(value) && value.protocol === protocol &&\n typeof value.appId === 'string' && typeof value.requestId === 'string' &&\n /^[A-Za-z0-9_-]{1,64}$/.test(value.requestId) &&\n typeof value.action === 'string' && ['ready', 'read', 'write', 'remove'].includes(value.action)\n}\n\n/** Bind one registered preview to a product-authorized data adapter. */\nexport function createWorkspaceAppDataHost(options: WorkspaceAppDataHostOptions): WorkspaceAppDataHost {\n const { app, frame } = options\n appId(app.id)\n if (app.status !== 'ready') throw new Error('Workspace app is not ready')\n const preview = new URL(app.previewUrl)\n const previewOrigin = origin(preview.origin)\n if (preview.protocol !== 'https:' || preview.username || preview.password || preview.search || preview.hash ||\n new URL(frame.src).href !== preview.href) {\n throw new Error('Iframe does not render the registered workspace app preview')\n }\n let closed = false\n let active = 0\n let messagesLeft = 64\n let nextWindow = Date.now() + 1000\n const onMessage = (event: MessageEvent<unknown>): void => {\n if (closed || event.source !== frame.contentWindow || event.origin !== previewOrigin ||\n !packet(event.data) || event.data.appId !== app.id) return\n const now = Date.now()\n if (now >= nextWindow) { messagesLeft = 64; nextWindow = now + 1000 }\n if (messagesLeft-- <= 0) return\n const message = event.data\n const reply = (result: Pick<Packet, 'ok' | 'entry' | 'revision' | 'error'>): void => {\n if (closed || event.source !== frame.contentWindow) return\n frame.contentWindow?.postMessage({\n protocol, appId: app.id, requestId: message.requestId, action: message.action, ...result,\n } satisfies Packet, previewOrigin)\n }\n if (message.action === 'ready') { reply({ ok: true }); return }\n if (!key(message.key) ||\n (message.action === 'write' && (!bounded(message.value) ||\n !(message.expectedRevision === null || revision(message.expectedRevision)))) ||\n (message.action === 'remove' && !revision(message.expectedRevision))) {\n reply({ ok: false, error: 'invalid' }); return\n }\n if (active >= maxPending) { reply({ ok: false, error: 'unavailable' }); return }\n active += 1\n const checkedKey = message.key\n void (async () => {\n try {\n if (message.action === 'read') {\n const entry = await options.read(checkedKey)\n if (entry !== null && (!bounded(entry.value) || !revision(entry.revision))) throw new Error('Invalid entry')\n reply({ ok: true, entry })\n } else if (message.action === 'write') {\n const result = await options.write(checkedKey, message.value as string, message.expectedRevision as number | null)\n if (!revision(result.revision)) throw new Error('Invalid revision')\n reply({ ok: true, revision: result.revision })\n } else {\n await options.remove(checkedKey, message.expectedRevision as number)\n reply({ ok: true })\n }\n } catch (error) {\n reply({ ok: false, error: error instanceof WorkspaceAppDataConflict ? 'conflict' : 'unavailable' })\n } finally { active -= 1 }\n })()\n }\n window.addEventListener('message', onMessage)\n return { dispose() { closed = true; window.removeEventListener('message', onMessage) } }\n}\n\n/** Use inside a registered preview; no product credential crosses the frame. */\nexport function createWorkspaceAppDataClient(options: WorkspaceAppDataClientOptions): WorkspaceAppDataClient {\n const id = appId(options.appId)\n const parentOrigin = origin(options.parentOrigin)\n if (window.parent === window) throw new Error('Workspace app data requires an embedded preview')\n const pending = new Map<string, {\n action: Action\n resolve(value: Packet): void\n reject(error: Error): void\n timeout: ReturnType<typeof setTimeout>\n }>()\n let closed = false\n let readyPromise: Promise<void> | undefined\n const onMessage = (event: MessageEvent<unknown>): void => {\n if (closed || event.source !== window.parent || event.origin !== parentOrigin || !packet(event.data) ||\n event.data.appId !== id || typeof event.data.ok !== 'boolean') return\n const waiting = pending.get(event.data.requestId)\n if (!waiting || waiting.action !== event.data.action) return\n pending.delete(event.data.requestId)\n clearTimeout(waiting.timeout)\n if (event.data.ok) waiting.resolve(event.data)\n else waiting.reject(event.data.error === 'conflict' ? new WorkspaceAppDataConflict() :\n new Error('Workspace app data unavailable'))\n }\n window.addEventListener('message', onMessage)\n const send = (action: Action, fields: Partial<Packet> = {}, timeoutMs = 10_000): Promise<Packet> => {\n if (closed) return Promise.reject(new Error('Workspace app data client is closed'))\n if (pending.size >= maxPending) return Promise.reject(new Error('Too many workspace app data requests'))\n const requestId = crypto.randomUUID()\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => { pending.delete(requestId); reject(new Error('Workspace app data timed out')) }, timeoutMs)\n pending.set(requestId, { action, resolve, reject, timeout })\n window.parent.postMessage({ protocol, appId: id, requestId, action, ...fields } satisfies Packet, parentOrigin)\n })\n }\n const ready = (): Promise<void> => {\n if (readyPromise) return readyPromise\n readyPromise = new Promise<void>((resolve, reject) => {\n const deadline = Date.now() + 10_000\n const attempt = (): void => {\n if (closed) { reject(new Error('Workspace app data client is closed')); return }\n if (Date.now() >= deadline) { reject(new Error('Workspace app data host did not become ready')); return }\n void send('ready', {}, 300).then(() => resolve(), () => setTimeout(attempt, 200))\n }\n attempt()\n }).catch((error: unknown) => { readyPromise = undefined; throw error })\n return readyPromise\n }\n return {\n ready,\n async read(value) {\n if (!key(value)) throw new Error('Invalid workspace app data key')\n await ready()\n const response = await send('read', { key: value })\n if (response.entry !== null && (!object(response.entry) ||\n !bounded(response.entry.value) || !revision(response.entry.revision))) {\n throw new Error('Invalid workspace app data response')\n }\n return response.entry ?? null\n },\n async write(value, data, expectedRevision) {\n if (!key(value) || !bounded(data) || !(expectedRevision === null || revision(expectedRevision))) {\n throw new Error('Invalid workspace app data write')\n }\n await ready()\n const response = await send('write', { key: value, value: data, expectedRevision })\n if (!revision(response.revision)) throw new Error('Invalid workspace app data response')\n return { revision: response.revision }\n },\n async remove(value, expectedRevision) {\n if (!key(value) || !revision(expectedRevision)) throw new Error('Invalid workspace app data remove')\n await ready()\n await send('remove', { key: value, expectedRevision })\n },\n dispose() {\n closed = true\n window.removeEventListener('message', onMessage)\n for (const waiting of pending.values()) {\n clearTimeout(waiting.timeout)\n waiting.reject(new Error('Workspace app data client is closed'))\n }\n pending.clear()\n },\n }\n}\n","/** A sandbox app registered in one product workspace. Products persist and authorize these rows. */\nexport interface WorkspaceAppRecord {\n id: string\n workspaceId: string\n name: string\n sandboxId: string\n previewId: string\n port: number\n previewUrl: string\n status: 'starting' | 'ready' | 'unavailable'\n createdAt: string\n updatedAt: string\n}\n\n/** Structural shape returned by the Sandbox SDK previewLinks API. */\nexport interface WorkspaceAppPreviewLink {\n previewId: string\n sandboxId: string\n port: number\n protocol: 'tcp' | 'udp'\n hostname: string\n url: string\n status: 'provisioning' | 'ready' | 'error' | 'disabled'\n}\n\nexport interface WorkspaceAppIdentity {\n /** Assigned by the product, stable across preview updates and deliberate republishes. */\n id: string\n /** Taken from the authenticated route or session, never agent tool arguments. */\n workspaceId: string\n /** Current box resolved by the product from that workspace or session. */\n sandboxId: string\n name: string\n /** Preserve this when republishing the same app onto a replacement sandbox. */\n createdAt?: string\n updatedAt?: string\n}\n\nfunction nonempty(value: string, field: string): string {\n if (typeof value !== 'string' || !value.trim() || /[\\u0000-\\u001f\\u007f]/.test(value)) {\n throw new Error('Invalid workspace app ' + field)\n }\n return value.trim()\n}\n\nfunction checkedLink(link: WorkspaceAppPreviewLink, sandboxId: string): void {\n if (link.sandboxId !== sandboxId) {\n throw new Error('Preview link belongs to another sandbox')\n }\n nonempty(link.previewId, 'previewId')\n if (link.protocol !== 'tcp') throw new Error('Workspace app preview must use TCP')\n if (!Number.isInteger(link.port) || link.port < 1 || link.port > 65535) {\n throw new Error('Invalid workspace app port')\n }\n if (!['provisioning', 'ready', 'error', 'disabled'].includes(link.status)) {\n throw new Error('Invalid workspace app preview status')\n }\n let url: URL\n try {\n url = new URL(link.url)\n } catch {\n throw new Error('Invalid workspace app preview URL')\n }\n if (\n url.protocol !== 'https:' ||\n !url.hostname ||\n url.hostname !== link.hostname ||\n url.username ||\n url.password ||\n url.search ||\n url.hash\n ) {\n throw new Error('Invalid workspace app preview URL')\n }\n}\n\nfunction appStatus(status: WorkspaceAppPreviewLink['status']): WorkspaceAppRecord['status'] {\n if (status === 'ready' || status === 'provisioning') return 'starting'\n return 'unavailable'\n}\n\n/**\n * Build a durable registration from a preview link created on the box that\n * the authenticated product request resolved. The product owns row identity,\n * access policy, persistence, and the decision to publish.\n */\nexport function workspaceAppFromPreviewLink(\n identity: WorkspaceAppIdentity,\n link: WorkspaceAppPreviewLink,\n): WorkspaceAppRecord {\n const sandboxId = nonempty(identity.sandboxId, 'sandboxId')\n checkedLink(link, sandboxId)\n const timestamp = identity.updatedAt ?? new Date().toISOString()\n return {\n id: nonempty(identity.id, 'id'),\n workspaceId: nonempty(identity.workspaceId, 'workspaceId'),\n name: nonempty(identity.name, 'name'),\n sandboxId,\n previewId: link.previewId,\n port: link.port,\n previewUrl: link.url,\n status: appStatus(link.status),\n createdAt: identity.createdAt ?? timestamp,\n updatedAt: timestamp,\n }\n}\n\nexport interface WorkspaceAppHttpProof {\n /** The exact trusted SDK preview URL requested by the server. */\n previewUrl: string\n status: number\n contentType: string\n /** Number of bytes read from the response body, excluding headers. */\n bodyBytes: number\n checkedAt: string\n}\n\n/**\n * Mark an app ready only after the host fetched its HTML over the trusted\n * preview URL. The host owns the request timeout, redirect and credential\n * policy, authorization, and compare-and-swap storage update.\n */\nexport function confirmWorkspaceAppReady(\n app: WorkspaceAppRecord,\n proof: WorkspaceAppHttpProof,\n): WorkspaceAppRecord {\n if (\n proof.previewUrl !== app.previewUrl ||\n proof.status !== 200 ||\n !/^text\\/html(?:\\s*;|\\s*$)/i.test(proof.contentType) ||\n !Number.isInteger(proof.bodyBytes) ||\n proof.bodyBytes < 1 ||\n !Number.isFinite(Date.parse(proof.checkedAt))\n ) {\n throw new Error('Workspace app HTML preview is not ready')\n }\n return { ...app, status: 'ready', updatedAt: proof.checkedAt }\n}\n\n/** Refresh delivery state without changing which sandbox service this app means. */\nexport function refreshWorkspaceAppPreview(\n app: WorkspaceAppRecord,\n link: WorkspaceAppPreviewLink,\n updatedAt = new Date().toISOString(),\n): WorkspaceAppRecord {\n checkedLink(link, app.sandboxId)\n if (link.previewId !== app.previewId || link.port !== app.port) {\n throw new Error('Preview link does not match workspace app')\n }\n return {\n ...app,\n previewUrl: link.url,\n status: appStatus(link.status),\n updatedAt,\n }\n}\n\nexport type WorkspaceAppBuilderInstructionsOptions =\n | {\n /** Host tool that writes the registration after creating a trusted preview. */\n publishTool: string\n /** Optional host tool for finding app IDs the builder may update. */\n listTool?: string\n manifestPath?: never\n }\n | {\n /** Host-scoped manifest the builder writes after creating runnable projects. */\n manifestPath: string\n publishTool?: never\n listTool?: never\n }\n\nfunction toolName(value: string): string {\n if (!/^[A-Za-z][A-Za-z0-9_.-]*$/.test(value)) {\n throw new Error('Invalid workspace app tool name')\n }\n return value\n}\n\nfunction builderManifestPath(value: string): string {\n if (\n !/^[A-Za-z0-9._-]+(?:[/][A-Za-z0-9._-]+)*$/.test(value) ||\n value.split('/').some(segment => segment === '..' || segment === '.')\n ) {\n throw new Error('Invalid workspace app manifest path')\n }\n return value\n}\n\n/** Portable instructions for an agent profile that builds workspace apps. */\nexport function workspaceAppBuilderInstructions(\n options: WorkspaceAppBuilderInstructionsOptions,\n): string[] {\n const common = [\n 'Build a working HTTP application in the current sandbox when the user asks for an app.',\n 'Keep the same app ID for later revisions of that app.',\n 'Treat a preview link as public. Do not embed secrets or private business facts in client code or responses.',\n 'Read real business data through authorized product APIs. Do not fabricate records to make the app look complete.',\n 'Report the app as available only after the host confirms its preview is ready.',\n ] as const\n if (options.manifestPath !== undefined) {\n const path = builderManifestPath(options.manifestPath)\n return [\n common[0],\n 'Inspect the existing app projects and manifest before creating or updating an app.',\n 'Keep each runnable project under apps/<id> relative to the sandbox working directory. Give it a package.json dev script; its HTTP server must listen on 0.0.0.0 and use PORT when supplied.',\n 'Write ' + path + ' as JSON with exactly an apps array of { id, name, projectPath } records; each projectPath is apps/<id>.',\n 'Do not put URLs, credentials, tokens, sandbox IDs, or preview IDs in that manifest.',\n 'The host reads this manifest and owns server launch, port selection, preview creation, registration, and access policy.',\n ...common.slice(1),\n ]\n }\n const publish = toolName(options.publishTool)\n const list = options.listTool ? toolName(options.listTool) : undefined\n return [\n common[0],\n ...(list ? ['Use ' + list + ' to inspect the existing apps before creating or updating one.'] : []),\n 'Start its server on 0.0.0.0 using an available, unclaimed port.',\n 'Call ' + publish + ' with the app name, stable app ID when updating, and listening port.',\n 'Use the host tool result as the source of the registered app URL and status; never invent a preview URL.',\n ...common.slice(1),\n ]\n}\n\nexport {\n WorkspaceAppDataConflict,\n createWorkspaceAppDataClient,\n createWorkspaceAppDataHost,\n} from './data-bridge'\nexport type {\n WorkspaceAppDataClient,\n WorkspaceAppDataClientOptions,\n WorkspaceAppDataEntry,\n WorkspaceAppDataHost,\n WorkspaceAppDataHostOptions,\n} from './data-bridge'\n"],"mappings":";AAEA,IAAM,WAAW;AACjB,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