@tangle-network/agent-app 0.50.30 → 0.50.32
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/dist/VaultPane-RHLY4DR5.js +7 -0
- package/dist/agent-enrollment/application.d.ts +42 -0
- package/dist/agent-enrollment/drizzle.d.ts +63 -0
- package/dist/agent-enrollment/drizzle.js +160 -0
- package/dist/agent-enrollment/drizzle.js.map +1 -0
- package/dist/agent-enrollment/index.d.ts +59 -0
- package/dist/agent-enrollment/index.js +14 -0
- package/dist/agent-enrollment/index.js.map +1 -0
- package/dist/assistant/index.js +7 -7
- package/dist/chat-routes/index.js +13 -13
- package/dist/chat-store/index.js +4 -4
- package/dist/{chunk-2ZNU55YJ.js → chunk-3IATFW4U.js} +5 -5
- package/dist/chunk-3IATFW4U.js.map +1 -0
- package/dist/{chunk-RACQDXJ7.js → chunk-4PZE7XAM.js} +6 -6
- package/dist/{chunk-QWYAR2CY.js → chunk-5KFRCVAO.js} +2 -2
- package/dist/{chunk-KTV5RQBQ.js → chunk-5TOV7EDF.js} +4 -4
- package/dist/chunk-6RWQ4VW5.js +124 -0
- package/dist/chunk-6RWQ4VW5.js.map +1 -0
- package/dist/{chunk-RFVTTZPG.js → chunk-CNI46COH.js} +2 -2
- package/dist/{chunk-RFVTTZPG.js.map → chunk-CNI46COH.js.map} +1 -1
- package/dist/{chunk-TJCTC5QI.js → chunk-LDCR7MRU.js} +2 -2
- package/dist/chunk-NLXY7TFB.js +207 -0
- package/dist/chunk-NLXY7TFB.js.map +1 -0
- package/dist/{chunk-QJRXKMHJ.js → chunk-UNXMIWPK.js} +6 -6
- package/dist/{chunk-XFCKMBOC.js → chunk-YFGG722I.js} +5 -5
- package/dist/{chunk-MX55JP7D.js → chunk-ZMMIQOFI.js} +5 -5
- package/dist/design-canvas-react/index.js +4 -4
- package/dist/hosted-agent/application.js +5 -116
- package/dist/hosted-agent/application.js.map +1 -1
- package/dist/integrations-react/callback.d.ts +6 -0
- package/dist/integrations-react/client.d.ts +34 -0
- package/dist/integrations-react/index.d.ts +6 -0
- package/dist/integrations-react/index.js +830 -0
- package/dist/integrations-react/index.js.map +1 -0
- package/dist/integrations-react/panel.d.ts +22 -0
- package/dist/integrations-react/popup.d.ts +19 -0
- package/dist/integrations-react/projection.d.ts +25 -0
- package/dist/integrations-react/use-hub-integrations.d.ts +102 -0
- package/dist/platform/hub-settings.d.ts +117 -0
- package/dist/platform/index.d.ts +1 -0
- package/dist/platform/index.js +225 -20
- package/dist/platform/index.js.map +1 -1
- package/dist/preset-cloudflare/index.js +2 -2
- package/dist/public-consultation/index.js +6 -6
- package/dist/sandbox/index.js +4 -4
- package/dist/stream/index.js +2 -2
- package/dist/tools/index.js +4 -4
- package/dist/vault/index.js +1 -1
- package/dist/vault/lazy.js +1 -1
- package/dist/web-react/index.js +9 -9
- package/dist/work-product/index.js +2 -2
- package/package.json +19 -4
- package/dist/VaultPane-OTUP5AEX.js +0 -7
- package/dist/chunk-2ZNU55YJ.js.map +0 -1
- /package/dist/{VaultPane-OTUP5AEX.js.map → VaultPane-RHLY4DR5.js.map} +0 -0
- /package/dist/{chunk-RACQDXJ7.js.map → chunk-4PZE7XAM.js.map} +0 -0
- /package/dist/{chunk-QWYAR2CY.js.map → chunk-5KFRCVAO.js.map} +0 -0
- /package/dist/{chunk-KTV5RQBQ.js.map → chunk-5TOV7EDF.js.map} +0 -0
- /package/dist/{chunk-TJCTC5QI.js.map → chunk-LDCR7MRU.js.map} +0 -0
- /package/dist/{chunk-QJRXKMHJ.js.map → chunk-UNXMIWPK.js.map} +0 -0
- /package/dist/{chunk-XFCKMBOC.js.map → chunk-YFGG722I.js.map} +0 -0
- /package/dist/{chunk-MX55JP7D.js.map → chunk-ZMMIQOFI.js.map} +0 -0
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
OPENUI_NODE_JSON_SCHEMA,
|
|
6
6
|
OPENUI_NODE_TYPES
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-CNI46COH.js";
|
|
8
8
|
|
|
9
9
|
// src/tools/openai.ts
|
|
10
10
|
var APP_TOOL_NAMES = ["submit_proposal", "schedule_followup", "render_ui", "add_citation"];
|
|
@@ -112,4 +112,4 @@ export {
|
|
|
112
112
|
customToolToOpenAI,
|
|
113
113
|
findCustomTool
|
|
114
114
|
};
|
|
115
|
-
//# sourceMappingURL=chunk-
|
|
115
|
+
//# sourceMappingURL=chunk-LDCR7MRU.js.map
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createApplicationLineHandler
|
|
3
|
+
} from "./chunk-6RWQ4VW5.js";
|
|
4
|
+
|
|
5
|
+
// src/agent-enrollment/application.ts
|
|
6
|
+
function forbidden() {
|
|
7
|
+
return Response.json(
|
|
8
|
+
{ error: { code: "enrollment_binding_mismatch" } },
|
|
9
|
+
{ status: 403, headers: { "cache-control": "no-store" } }
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
function subjectId(input) {
|
|
13
|
+
const value = input.subjectId;
|
|
14
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
15
|
+
}
|
|
16
|
+
function matches(input, member) {
|
|
17
|
+
return !!member.enrollmentId && !!member.grantRevision && member.binding === input.binding && member.subjectId === subjectId(input) && member.lineId === input.lineId && member.attachmentId === input.attachmentId && member.memberId === input.memberId && member.ownerUserId === input.ownerUserId && member.senderAddress === input.sender.address;
|
|
18
|
+
}
|
|
19
|
+
function sameMember(left, right) {
|
|
20
|
+
return left.binding === right.binding && left.subjectId === right.subjectId && left.appId === right.appId && left.grantRevision === right.grantRevision && left.enrollmentId === right.enrollmentId && left.agentId === right.agentId && left.workspaceId === right.workspaceId && left.threadId === right.threadId && left.lineId === right.lineId && left.attachmentId === right.attachmentId && left.memberId === right.memberId && left.ownerUserId === right.ownerUserId && left.senderAddress === right.senderAddress;
|
|
21
|
+
}
|
|
22
|
+
function matchesTarget(member, target) {
|
|
23
|
+
return member.enrollmentId === target.enrollmentId && member.agentId === target.agentId && member.workspaceId === target.workspaceId && member.threadId === target.threadId;
|
|
24
|
+
}
|
|
25
|
+
function sameTarget(left, right) {
|
|
26
|
+
return left.enrollmentId === right.enrollmentId && left.agentId === right.agentId && left.workspaceId === right.workspaceId && left.threadId === right.threadId && left.instanceKey === right.instanceKey && left.configurationDigest === right.configurationDigest && left.profileVersion === right.profileVersion && left.generation === right.generation && left.sandboxId === right.sandboxId && left.filesystemIncarnationId === right.filesystemIncarnationId && left.sessionId === right.sessionId;
|
|
27
|
+
}
|
|
28
|
+
function createEnrolledApplicationLineHandler(options) {
|
|
29
|
+
async function resolve(authenticated, input) {
|
|
30
|
+
const subject = subjectId(input);
|
|
31
|
+
if (!subject) throw forbidden();
|
|
32
|
+
const appId = await options.selectApp(authenticated, input);
|
|
33
|
+
if (!appId || authenticated.selectedAppId && authenticated.selectedAppId !== appId) throw forbidden();
|
|
34
|
+
authenticated.selectedAppId = appId;
|
|
35
|
+
const observedMember = await options.lookup(authenticated.principal, authenticated.binding, subject, appId);
|
|
36
|
+
if (!observedMember) throw forbidden();
|
|
37
|
+
const member = Object.freeze({ ...observedMember });
|
|
38
|
+
if (member.appId !== appId || !matches(input, member) || authenticated.pinned && !sameMember(authenticated.pinned.member, member)) throw forbidden();
|
|
39
|
+
const resolved = await options.enrollment.resolve(authenticated.principal, member.enrollmentId);
|
|
40
|
+
const target = Object.freeze({ ...resolved.target });
|
|
41
|
+
if (!matchesTarget(member, target) || authenticated.pinned && !sameTarget(authenticated.pinned.target, target)) throw forbidden();
|
|
42
|
+
const current = await options.lookup(authenticated.principal, authenticated.binding, subject, appId);
|
|
43
|
+
if (!current || !sameMember(current, member)) throw forbidden();
|
|
44
|
+
authenticated.pinned ??= Object.freeze({ member, target });
|
|
45
|
+
return { resolved: { ...resolved, target }, member: authenticated.pinned.member };
|
|
46
|
+
}
|
|
47
|
+
return createApplicationLineHandler({
|
|
48
|
+
authenticate: async (request) => {
|
|
49
|
+
const target = await options.authenticate(request);
|
|
50
|
+
if (!target.binding) throw forbidden();
|
|
51
|
+
return { binding: target.binding, target: { ...target, selectedAppId: void 0, pinned: void 0 } };
|
|
52
|
+
},
|
|
53
|
+
authorize: async (target, input) => {
|
|
54
|
+
await resolve(target, input);
|
|
55
|
+
},
|
|
56
|
+
read: async (target, input) => {
|
|
57
|
+
const { resolved, member } = await resolve(target, input);
|
|
58
|
+
return options.read(resolved, input, member);
|
|
59
|
+
},
|
|
60
|
+
admit: async (target, input) => {
|
|
61
|
+
const { resolved, member } = await resolve(target, input);
|
|
62
|
+
return options.admit(resolved, input, member);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/agent-enrollment/index.ts
|
|
68
|
+
var EnrollmentTargetError = class extends Error {
|
|
69
|
+
constructor(code) {
|
|
70
|
+
super(code);
|
|
71
|
+
this.code = code;
|
|
72
|
+
this.name = "EnrollmentTargetError";
|
|
73
|
+
}
|
|
74
|
+
code;
|
|
75
|
+
};
|
|
76
|
+
function valid(value) {
|
|
77
|
+
return value.trim().length > 0;
|
|
78
|
+
}
|
|
79
|
+
function sameIdentity(left, right) {
|
|
80
|
+
return left.enrollmentId === right.enrollmentId && left.agentId === right.agentId && left.workspaceId === right.workspaceId && left.threadId === right.threadId;
|
|
81
|
+
}
|
|
82
|
+
function sameTarget2(left, right) {
|
|
83
|
+
return sameIdentity(left, right) && left.instanceKey === right.instanceKey && left.generation === right.generation && left.profileVersion === right.profileVersion && left.configurationDigest === right.configurationDigest && left.sandboxId === right.sandboxId && left.filesystemIncarnationId === right.filesystemIncarnationId && left.sessionId === right.sessionId;
|
|
84
|
+
}
|
|
85
|
+
function sameClaim(left, right) {
|
|
86
|
+
return sameIdentity(left, right) && left.instanceKey === right.instanceKey && left.profileVersion === right.profileVersion && left.configurationDigest === right.configurationDigest;
|
|
87
|
+
}
|
|
88
|
+
async function configurationDigest(request) {
|
|
89
|
+
let serialized;
|
|
90
|
+
try {
|
|
91
|
+
serialized = JSON.stringify(
|
|
92
|
+
{ profile: request.instance.profile, create: request.instance.create },
|
|
93
|
+
(_key, value) => value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)) : value
|
|
94
|
+
);
|
|
95
|
+
} catch {
|
|
96
|
+
throw new EnrollmentTargetError("invalid_request");
|
|
97
|
+
}
|
|
98
|
+
if (!serialized) throw new EnrollmentTargetError("invalid_request");
|
|
99
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(serialized));
|
|
100
|
+
return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
101
|
+
}
|
|
102
|
+
function snapshotRequest(request) {
|
|
103
|
+
try {
|
|
104
|
+
return {
|
|
105
|
+
enrollmentId: request.enrollmentId,
|
|
106
|
+
agentId: request.agentId,
|
|
107
|
+
workspaceId: request.workspaceId,
|
|
108
|
+
threadId: request.threadId,
|
|
109
|
+
instance: structuredClone(request.instance)
|
|
110
|
+
};
|
|
111
|
+
} catch {
|
|
112
|
+
throw new EnrollmentTargetError("invalid_request");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function createAgentEnrollment(options) {
|
|
116
|
+
async function resolve(principal, enrollmentId) {
|
|
117
|
+
if (!valid(enrollmentId)) throw new EnrollmentTargetError("invalid_request");
|
|
118
|
+
const stored = await options.store.get(enrollmentId);
|
|
119
|
+
if (!stored) throw new EnrollmentTargetError("missing");
|
|
120
|
+
const target = Object.freeze({ ...stored });
|
|
121
|
+
await options.authorize(principal, target, "resolve");
|
|
122
|
+
const client = await options.client(principal);
|
|
123
|
+
const record = await client.instances.get(target.instanceKey);
|
|
124
|
+
if (!record || record.key !== target.instanceKey || record.generation !== target.generation || record.profileVersion !== target.profileVersion || record.sandboxId !== target.sandboxId) {
|
|
125
|
+
throw new EnrollmentTargetError("target_changed");
|
|
126
|
+
}
|
|
127
|
+
const box = await client.get(target.sandboxId);
|
|
128
|
+
if (!box || box.id !== target.sandboxId || box.filesystemIncarnationReadiness !== "ready" || box.filesystemIncarnationId !== target.filesystemIncarnationId) {
|
|
129
|
+
throw new EnrollmentTargetError("target_changed");
|
|
130
|
+
}
|
|
131
|
+
const session = box.session(target.sessionId);
|
|
132
|
+
const status = await session.status();
|
|
133
|
+
if (!status || status.id !== target.sessionId) throw new EnrollmentTargetError("session_missing");
|
|
134
|
+
await options.authorize(principal, target, "resolve");
|
|
135
|
+
return { target, box, session };
|
|
136
|
+
}
|
|
137
|
+
async function enroll(principal, request) {
|
|
138
|
+
const snapshot = snapshotRequest(request);
|
|
139
|
+
if (![
|
|
140
|
+
snapshot.enrollmentId,
|
|
141
|
+
snapshot.agentId,
|
|
142
|
+
snapshot.workspaceId,
|
|
143
|
+
snapshot.threadId,
|
|
144
|
+
snapshot.instance.key,
|
|
145
|
+
snapshot.instance.profile.version
|
|
146
|
+
].every(valid)) {
|
|
147
|
+
throw new EnrollmentTargetError("invalid_request");
|
|
148
|
+
}
|
|
149
|
+
const identity = Object.freeze({
|
|
150
|
+
enrollmentId: snapshot.enrollmentId,
|
|
151
|
+
agentId: snapshot.agentId,
|
|
152
|
+
workspaceId: snapshot.workspaceId,
|
|
153
|
+
threadId: snapshot.threadId
|
|
154
|
+
});
|
|
155
|
+
await options.authorize(principal, identity, "enroll");
|
|
156
|
+
const claim = Object.freeze({
|
|
157
|
+
...identity,
|
|
158
|
+
instanceKey: snapshot.instance.key,
|
|
159
|
+
profileVersion: snapshot.instance.profile.version,
|
|
160
|
+
configurationDigest: await configurationDigest(snapshot)
|
|
161
|
+
});
|
|
162
|
+
const winner = await options.store.claimIfAbsent(claim);
|
|
163
|
+
if (!sameClaim(winner, claim)) throw new EnrollmentTargetError("conflict");
|
|
164
|
+
const existing = await options.store.get(snapshot.enrollmentId);
|
|
165
|
+
if (existing) {
|
|
166
|
+
if (!sameClaim(existing, claim)) throw new EnrollmentTargetError("conflict");
|
|
167
|
+
return (await resolve(principal, snapshot.enrollmentId)).target;
|
|
168
|
+
}
|
|
169
|
+
const client = await options.client(principal);
|
|
170
|
+
await options.authorize(principal, identity, "enroll");
|
|
171
|
+
const instance = await client.instances.ensure(structuredClone(snapshot.instance));
|
|
172
|
+
const box = instance.box;
|
|
173
|
+
if (instance.key !== claim.instanceKey || instance.profileVersion !== claim.profileVersion || !Number.isSafeInteger(instance.generation) || instance.generation < 1 || instance.sandboxId !== box.id || box.filesystemIncarnationReadiness !== "ready" || !box.filesystemIncarnationId) throw new EnrollmentTargetError("target_changed");
|
|
174
|
+
const sessionId = instance.sessionId(claim.threadId);
|
|
175
|
+
if (!valid(sessionId)) throw new EnrollmentTargetError("target_changed");
|
|
176
|
+
await options.authorize(principal, identity, "enroll");
|
|
177
|
+
const created = await box.createSession({ sessionId, retention: "workspace", backend: snapshot.instance.profile.backend });
|
|
178
|
+
if (created.info.id !== sessionId) throw new EnrollmentTargetError("target_changed");
|
|
179
|
+
const target = Object.freeze({
|
|
180
|
+
enrollmentId: claim.enrollmentId,
|
|
181
|
+
agentId: claim.agentId,
|
|
182
|
+
workspaceId: claim.workspaceId,
|
|
183
|
+
threadId: claim.threadId,
|
|
184
|
+
instanceKey: instance.key,
|
|
185
|
+
configurationDigest: claim.configurationDigest,
|
|
186
|
+
generation: instance.generation,
|
|
187
|
+
profileVersion: instance.profileVersion,
|
|
188
|
+
sandboxId: instance.sandboxId,
|
|
189
|
+
filesystemIncarnationId: box.filesystemIncarnationId,
|
|
190
|
+
sessionId
|
|
191
|
+
});
|
|
192
|
+
const record = await client.instances.get(target.instanceKey);
|
|
193
|
+
if (!record || record.generation !== target.generation || record.sandboxId !== target.sandboxId || record.profileVersion !== target.profileVersion) throw new EnrollmentTargetError("target_changed");
|
|
194
|
+
await options.authorize(principal, identity, "enroll");
|
|
195
|
+
const saved = await options.store.insertIfAbsent(target);
|
|
196
|
+
if (!sameTarget2(saved, target)) throw new EnrollmentTargetError("conflict");
|
|
197
|
+
return (await resolve(principal, claim.enrollmentId)).target;
|
|
198
|
+
}
|
|
199
|
+
return { enroll, resolve };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export {
|
|
203
|
+
createEnrolledApplicationLineHandler,
|
|
204
|
+
EnrollmentTargetError,
|
|
205
|
+
createAgentEnrollment
|
|
206
|
+
};
|
|
207
|
+
//# sourceMappingURL=chunk-NLXY7TFB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/agent-enrollment/application.ts","../src/agent-enrollment/index.ts"],"sourcesContent":["import type { LineApplicationRequest } from '@tangle-network/sandbox/core'\nimport { createApplicationLineHandler, type ApplicationLineObservation } from '../hosted-agent/application'\nimport type { AgentEnrollmentTarget, ResolvedAgentEnrollment } from './index'\n\n/** The host verifies Hub's signed callback before the SDK parses its body. */\nexport interface AuthenticatedSharedLinePrincipal<Principal> {\n principal: Principal\n binding: string\n}\n\n/** Current host-owned app, customer and member grant for one Hub subject. */\nexport interface LiveSharedEnrollmentMember {\n binding: string\n subjectId: string\n appId: string\n lineId: string\n attachmentId: string\n memberId: string\n /** Changes on every grant, consent, or target remap, including revoke and regrant. */\n grantRevision: string\n ownerUserId: string\n senderAddress: string\n enrollmentId: string\n agentId: string\n workspaceId: string\n threadId: string\n}\n\nexport interface EnrolledApplicationLineOptions<Principal> {\n /** Verify the server-to-server callback; the maintained SDK parses its subjectId. */\n authenticate(request: Request): Promise<AuthenticatedSharedLinePrincipal<Principal>>\n /** Select an intended app from durable policy. Message text is intent, never a grant. */\n selectApp(authenticated: AuthenticatedSharedLinePrincipal<Principal>, input: Readonly<LineApplicationRequest>): Promise<string>\n /** Re-read live app, customer, consent and member grant for the selected app. */\n lookup(principal: Principal, binding: string, subjectId: string, appId: string): Promise<LiveSharedEnrollmentMember | null>\n enrollment: { resolve(principal: Principal, enrollmentId: string): Promise<ResolvedAgentEnrollment> }\n /** Read through the application's existing durable output store using the pinned grant. */\n read(resolved: ResolvedAgentEnrollment, input: Readonly<LineApplicationRequest>,\n member: Readonly<LiveSharedEnrollmentMember>): Promise<ApplicationLineObservation>\n /** Atomically compare the pinned grant revision at the durable task write before paid work. */\n admit(resolved: ResolvedAgentEnrollment, input: Readonly<LineApplicationRequest>,\n member: Readonly<LiveSharedEnrollmentMember>): Promise<void>\n}\n\nfunction forbidden(): Response {\n return Response.json({ error: { code: 'enrollment_binding_mismatch' } },\n { status: 403, headers: { 'cache-control': 'no-store' } })\n}\n\nfunction subjectId(input: Readonly<LineApplicationRequest>): string | null {\n const value = (input as LineApplicationRequest & { subjectId?: unknown }).subjectId\n return typeof value === 'string' && value.length > 0 ? value : null\n}\n\nfunction matches(input: Readonly<LineApplicationRequest>, member: LiveSharedEnrollmentMember): boolean {\n return !!member.enrollmentId && !!member.grantRevision\n && member.binding === input.binding && member.subjectId === subjectId(input)\n && member.lineId === input.lineId && member.attachmentId === input.attachmentId\n && member.memberId === input.memberId && member.ownerUserId === input.ownerUserId\n && member.senderAddress === input.sender.address\n}\n\nfunction sameMember(left: LiveSharedEnrollmentMember, right: LiveSharedEnrollmentMember): boolean {\n return left.binding === right.binding && left.subjectId === right.subjectId\n && left.appId === right.appId && left.grantRevision === right.grantRevision\n && left.enrollmentId === right.enrollmentId && left.agentId === right.agentId\n && left.workspaceId === right.workspaceId && left.threadId === right.threadId\n && left.lineId === right.lineId && left.attachmentId === right.attachmentId\n && left.memberId === right.memberId && left.ownerUserId === right.ownerUserId\n && left.senderAddress === right.senderAddress\n}\n\nfunction matchesTarget(member: LiveSharedEnrollmentMember, target: AgentEnrollmentTarget): boolean {\n return member.enrollmentId === target.enrollmentId && member.agentId === target.agentId\n && member.workspaceId === target.workspaceId && member.threadId === target.threadId\n}\n\nfunction sameTarget(left: AgentEnrollmentTarget, right: AgentEnrollmentTarget): boolean {\n return left.enrollmentId === right.enrollmentId && left.agentId === right.agentId\n && left.workspaceId === right.workspaceId && left.threadId === right.threadId\n && left.instanceKey === right.instanceKey && left.configurationDigest === right.configurationDigest\n && left.profileVersion === right.profileVersion && left.generation === right.generation\n && left.sandboxId === right.sandboxId && left.filesystemIncarnationId === right.filesystemIncarnationId\n && left.sessionId === right.sessionId\n}\n\ninterface PinnedResolution {\n member: Readonly<LiveSharedEnrollmentMember>\n target: Readonly<AgentEnrollmentTarget>\n}\n\ninterface AuthenticatedContext<Principal> extends AuthenticatedSharedLinePrincipal<Principal> {\n selectedAppId?: string\n pinned?: PinnedResolution\n}\n\n/** Bind a signed shared Line member to the same native target used by web and ChatGPT. */\nexport function createEnrolledApplicationLineHandler<Principal>(options: EnrolledApplicationLineOptions<Principal>) {\n async function resolve(authenticated: AuthenticatedContext<Principal>,\n input: Readonly<LineApplicationRequest>) {\n const subject = subjectId(input)\n if (!subject) throw forbidden()\n const appId = await options.selectApp(authenticated, input)\n if (!appId || (authenticated.selectedAppId && authenticated.selectedAppId !== appId)) throw forbidden()\n authenticated.selectedAppId = appId\n const observedMember = await options.lookup(authenticated.principal, authenticated.binding, subject, appId)\n if (!observedMember) throw forbidden()\n // A host cache may return the same mutable object on both lookups.\n const member = Object.freeze({ ...observedMember })\n if (member.appId !== appId || !matches(input, member)\n || (authenticated.pinned && !sameMember(authenticated.pinned.member, member))) throw forbidden()\n const resolved = await options.enrollment.resolve(authenticated.principal, member.enrollmentId)\n const target = Object.freeze({ ...resolved.target })\n if (!matchesTarget(member, target)\n || (authenticated.pinned && !sameTarget(authenticated.pinned.target, target))) throw forbidden()\n // SDK observations yield. A revoked or remapped member must not start or read a turn.\n const current = await options.lookup(authenticated.principal, authenticated.binding, subject, appId)\n if (!current || !sameMember(current, member)) throw forbidden()\n authenticated.pinned ??= Object.freeze({ member, target })\n return { resolved: { ...resolved, target }, member: authenticated.pinned.member }\n }\n\n return createApplicationLineHandler({\n authenticate: async request => {\n const target = await options.authenticate(request)\n if (!target.binding) throw forbidden()\n return { binding: target.binding, target: { ...target, selectedAppId: undefined, pinned: undefined } }\n },\n authorize: async (target, input) => { await resolve(target, input) },\n read: async (target, input) => {\n const { resolved, member } = await resolve(target, input)\n return options.read(resolved, input, member)\n },\n admit: async (target, input) => {\n const { resolved, member } = await resolve(target, input)\n return options.admit(resolved, input, member)\n },\n })\n}\n","import type { EnsureInstanceOptions, Sandbox, SandboxInstance } from '@tangle-network/sandbox/core'\n\nexport { createEnrolledApplicationLineHandler } from './application'\nexport type { AuthenticatedSharedLinePrincipal, LiveSharedEnrollmentMember, EnrolledApplicationLineOptions } from './application'\n\n/** An application's durable pointer to one private agent's native SDK session. */\nexport interface AgentEnrollmentTarget {\n enrollmentId: string\n agentId: string\n workspaceId: string\n threadId: string\n instanceKey: string\n configurationDigest: string\n generation: number\n profileVersion: string\n sandboxId: string\n filesystemIncarnationId: string\n sessionId: string\n}\n\nexport type AgentEnrollmentIdentity = Pick<AgentEnrollmentTarget, 'enrollmentId' | 'agentId' | 'workspaceId' | 'threadId'>\n\nexport interface AgentEnrollmentRequest extends AgentEnrollmentIdentity {\n /** The host derives this from the authorized agent and its saved profile. */\n instance: Pick<EnsureInstanceOptions, 'key' | 'create'> & { profile: NonNullable<EnsureInstanceOptions['profile']> }\n}\n\n/** Immutable reservation made before any SDK provisioning can change an instance. */\nexport type AgentEnrollmentClaim = AgentEnrollmentIdentity & Pick<AgentEnrollmentTarget,\n 'instanceKey' | 'profileVersion' | 'configurationDigest'>\n\nexport interface AgentEnrollmentStore {\n get(enrollmentId: string): Promise<AgentEnrollmentTarget | null>\n /**\n * Atomically reserve the enrollment and instance key before SDK effects.\n * Return the existing claim for an enrollment ID. Reject another configuration\n * for a reserved instance key, even under a different enrollment ID.\n * Claims survive failed provisioning so an identical request can retry.\n */\n claimIfAbsent(claim: AgentEnrollmentClaim): Promise<AgentEnrollmentClaim>\n /** Atomically commit only under the matching claim. Never overwrite a target. */\n insertIfAbsent(target: AgentEnrollmentTarget): Promise<AgentEnrollmentTarget>\n}\n\nexport interface AgentEnrollmentOptions<Principal> {\n /** Check the live agent, workspace, thread and owner grant on every call. */\n authorize(principal: Principal, identity: AgentEnrollmentIdentity, operation: 'enroll' | 'resolve'): Promise<void>\n /** Return the caller's owner-scoped SDK client. Never use a global service key. */\n client(principal: Principal): Pick<Sandbox, 'instances' | 'get'> | Promise<Pick<Sandbox, 'instances' | 'get'>>\n store: AgentEnrollmentStore\n}\n\nexport class EnrollmentTargetError extends Error {\n constructor(readonly code: 'invalid_request' | 'missing' | 'conflict' | 'target_changed' | 'session_missing') {\n super(code)\n this.name = 'EnrollmentTargetError'\n }\n}\n\nexport interface ResolvedAgentEnrollment {\n target: AgentEnrollmentTarget\n box: SandboxInstance\n session: ReturnType<SandboxInstance['session']>\n}\n\nfunction valid(value: string): boolean {\n return value.trim().length > 0\n}\n\nfunction sameIdentity(left: AgentEnrollmentIdentity, right: AgentEnrollmentIdentity): boolean {\n return left.enrollmentId === right.enrollmentId && left.agentId === right.agentId\n && left.workspaceId === right.workspaceId && left.threadId === right.threadId\n}\n\nfunction sameTarget(left: AgentEnrollmentTarget, right: AgentEnrollmentTarget): boolean {\n return sameIdentity(left, right) && left.instanceKey === right.instanceKey\n && left.generation === right.generation && left.profileVersion === right.profileVersion\n && left.configurationDigest === right.configurationDigest\n && left.sandboxId === right.sandboxId && left.filesystemIncarnationId === right.filesystemIncarnationId\n && left.sessionId === right.sessionId\n}\n\nfunction sameClaim(left: AgentEnrollmentClaim, right: AgentEnrollmentClaim): boolean {\n return sameIdentity(left, right) && left.instanceKey === right.instanceKey\n && left.profileVersion === right.profileVersion\n && left.configurationDigest === right.configurationDigest\n}\n\nasync function configurationDigest(request: AgentEnrollmentRequest): Promise<string> {\n let serialized: string | undefined\n try {\n serialized = JSON.stringify({ profile: request.instance.profile, create: request.instance.create },\n (_key, value: unknown) => value && typeof value === 'object' && !Array.isArray(value)\n ? Object.fromEntries(Object.entries(value).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0))\n : value)\n } catch {\n throw new EnrollmentTargetError('invalid_request')\n }\n if (!serialized) throw new EnrollmentTargetError('invalid_request')\n const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(serialized))\n return Array.from(new Uint8Array(digest), byte => byte.toString(16).padStart(2, '0')).join('')\n}\n\nfunction snapshotRequest(request: AgentEnrollmentRequest): AgentEnrollmentRequest {\n try {\n return {\n enrollmentId: request.enrollmentId, agentId: request.agentId,\n workspaceId: request.workspaceId, threadId: request.threadId,\n instance: structuredClone(request.instance),\n }\n } catch {\n throw new EnrollmentTargetError('invalid_request')\n }\n}\n\n/** Share one authenticated target between an app's phone, web and ChatGPT adapters. */\nexport function createAgentEnrollment<Principal>(options: AgentEnrollmentOptions<Principal>) {\n async function resolve(principal: Principal, enrollmentId: string): Promise<ResolvedAgentEnrollment> {\n if (!valid(enrollmentId)) throw new EnrollmentTargetError('invalid_request')\n const stored = await options.store.get(enrollmentId)\n if (!stored) throw new EnrollmentTargetError('missing')\n const target = Object.freeze({ ...stored })\n await options.authorize(principal, target, 'resolve')\n const client = await options.client(principal)\n const record = await client.instances.get(target.instanceKey)\n if (!record || record.key !== target.instanceKey || record.generation !== target.generation\n || record.profileVersion !== target.profileVersion || record.sandboxId !== target.sandboxId) {\n throw new EnrollmentTargetError('target_changed')\n }\n const box = await client.get(target.sandboxId)\n if (!box || box.id !== target.sandboxId || box.filesystemIncarnationReadiness !== 'ready'\n || box.filesystemIncarnationId !== target.filesystemIncarnationId) {\n throw new EnrollmentTargetError('target_changed')\n }\n const session = box.session(target.sessionId)\n const status = await session.status()\n if (!status || status.id !== target.sessionId) throw new EnrollmentTargetError('session_missing')\n // Each external observation can yield; deny if the host revoked the grant meanwhile.\n await options.authorize(principal, target, 'resolve')\n return { target, box, session }\n }\n\n async function enroll(principal: Principal, request: AgentEnrollmentRequest): Promise<AgentEnrollmentTarget> {\n const snapshot = snapshotRequest(request)\n if (![snapshot.enrollmentId, snapshot.agentId, snapshot.workspaceId, snapshot.threadId,\n snapshot.instance.key, snapshot.instance.profile.version].every(valid)) {\n throw new EnrollmentTargetError('invalid_request')\n }\n const identity: AgentEnrollmentIdentity = Object.freeze({\n enrollmentId: snapshot.enrollmentId, agentId: snapshot.agentId,\n workspaceId: snapshot.workspaceId, threadId: snapshot.threadId,\n })\n await options.authorize(principal, identity, 'enroll')\n const claim: AgentEnrollmentClaim = Object.freeze({\n ...identity,\n instanceKey: snapshot.instance.key, profileVersion: snapshot.instance.profile.version,\n configurationDigest: await configurationDigest(snapshot),\n })\n const winner = await options.store.claimIfAbsent(claim)\n if (!sameClaim(winner, claim)) throw new EnrollmentTargetError('conflict')\n const existing = await options.store.get(snapshot.enrollmentId)\n if (existing) {\n if (!sameClaim(existing, claim)) throw new EnrollmentTargetError('conflict')\n return (await resolve(principal, snapshot.enrollmentId)).target\n }\n const client = await options.client(principal)\n // Store and client lookups can yield after the first grant check.\n await options.authorize(principal, identity, 'enroll')\n const instance = await client.instances.ensure(structuredClone(snapshot.instance))\n const box = instance.box\n if (instance.key !== claim.instanceKey || instance.profileVersion !== claim.profileVersion\n || !Number.isSafeInteger(instance.generation) || instance.generation < 1\n || instance.sandboxId !== box.id || box.filesystemIncarnationReadiness !== 'ready'\n || !box.filesystemIncarnationId) throw new EnrollmentTargetError('target_changed')\n const sessionId = instance.sessionId(claim.threadId)\n if (!valid(sessionId)) throw new EnrollmentTargetError('target_changed')\n // Provisioning can await a revoked grant. Check again before creating a session.\n await options.authorize(principal, identity, 'enroll')\n const created = await box.createSession({ sessionId, retention: 'workspace', backend: snapshot.instance.profile.backend })\n if (created.info.id !== sessionId) throw new EnrollmentTargetError('target_changed')\n const target: AgentEnrollmentTarget = Object.freeze({\n enrollmentId: claim.enrollmentId, agentId: claim.agentId, workspaceId: claim.workspaceId,\n threadId: claim.threadId, instanceKey: instance.key,\n configurationDigest: claim.configurationDigest, generation: instance.generation,\n profileVersion: instance.profileVersion, sandboxId: instance.sandboxId,\n filesystemIncarnationId: box.filesystemIncarnationId, sessionId,\n })\n const record = await client.instances.get(target.instanceKey)\n if (!record || record.generation !== target.generation || record.sandboxId !== target.sandboxId\n || record.profileVersion !== target.profileVersion) throw new EnrollmentTargetError('target_changed')\n await options.authorize(principal, identity, 'enroll')\n const saved = await options.store.insertIfAbsent(target)\n if (!sameTarget(saved, target)) throw new EnrollmentTargetError('conflict')\n return (await resolve(principal, claim.enrollmentId)).target\n }\n\n return { enroll, resolve }\n}\n"],"mappings":";;;;;AA4CA,SAAS,YAAsB;AAC7B,SAAO,SAAS;AAAA,IAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,EAAE;AAAA,IACpE,EAAE,QAAQ,KAAK,SAAS,EAAE,iBAAiB,WAAW,EAAE;AAAA,EAAC;AAC7D;AAEA,SAAS,UAAU,OAAwD;AACzE,QAAM,QAAS,MAA2D;AAC1E,SAAO,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ;AACjE;AAEA,SAAS,QAAQ,OAAyC,QAA6C;AACrG,SAAO,CAAC,CAAC,OAAO,gBAAgB,CAAC,CAAC,OAAO,iBACpC,OAAO,YAAY,MAAM,WAAW,OAAO,cAAc,UAAU,KAAK,KACxE,OAAO,WAAW,MAAM,UAAU,OAAO,iBAAiB,MAAM,gBAChE,OAAO,aAAa,MAAM,YAAY,OAAO,gBAAgB,MAAM,eACnE,OAAO,kBAAkB,MAAM,OAAO;AAC7C;AAEA,SAAS,WAAW,MAAkC,OAA4C;AAChG,SAAO,KAAK,YAAY,MAAM,WAAW,KAAK,cAAc,MAAM,aAC7D,KAAK,UAAU,MAAM,SAAS,KAAK,kBAAkB,MAAM,iBAC3D,KAAK,iBAAiB,MAAM,gBAAgB,KAAK,YAAY,MAAM,WACnE,KAAK,gBAAgB,MAAM,eAAe,KAAK,aAAa,MAAM,YAClE,KAAK,WAAW,MAAM,UAAU,KAAK,iBAAiB,MAAM,gBAC5D,KAAK,aAAa,MAAM,YAAY,KAAK,gBAAgB,MAAM,eAC/D,KAAK,kBAAkB,MAAM;AACpC;AAEA,SAAS,cAAc,QAAoC,QAAwC;AACjG,SAAO,OAAO,iBAAiB,OAAO,gBAAgB,OAAO,Y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,EACxD;AAEA,SAAO,EAAE,QAAQ,QAAQ;AAC3B;","names":["sameTarget"]}
|
|
@@ -33,11 +33,7 @@ import {
|
|
|
33
33
|
} from "./chunk-Q3ZHNN5X.js";
|
|
34
34
|
import {
|
|
35
35
|
attachmentPartsFromMessageParts
|
|
36
|
-
} from "./chunk-
|
|
37
|
-
import {
|
|
38
|
-
parsePlanSubmittedEvent,
|
|
39
|
-
persistedPartToPlan
|
|
40
|
-
} from "./chunk-YJMCRXQQ.js";
|
|
36
|
+
} from "./chunk-4PZE7XAM.js";
|
|
41
37
|
import {
|
|
42
38
|
cancelStatusFor,
|
|
43
39
|
fieldAcceptsFreeText,
|
|
@@ -48,6 +44,10 @@ import {
|
|
|
48
44
|
persistedPartToInteraction,
|
|
49
45
|
questionInteractionContentSignature
|
|
50
46
|
} from "./chunk-M3K2HVQD.js";
|
|
47
|
+
import {
|
|
48
|
+
parsePlanSubmittedEvent,
|
|
49
|
+
persistedPartToPlan
|
|
50
|
+
} from "./chunk-YJMCRXQQ.js";
|
|
51
51
|
|
|
52
52
|
// src/web-react/index.tsx
|
|
53
53
|
import { useEffect as useEffect13, useMemo as useMemo7, useRef as useRef12, useState as useState17, memo } from "react";
|
|
@@ -7138,4 +7138,4 @@ export {
|
|
|
7138
7138
|
useThinkingSeconds,
|
|
7139
7139
|
ChatMessages
|
|
7140
7140
|
};
|
|
7141
|
-
//# sourceMappingURL=chunk-
|
|
7141
|
+
//# sourceMappingURL=chunk-UNXMIWPK.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parseJsonObjectBody
|
|
3
|
-
} from "./chunk-3NCPXNBZ.js";
|
|
4
1
|
import {
|
|
5
2
|
createInteractionAnswerRoute
|
|
6
3
|
} from "./chunk-WWFE5EXY.js";
|
|
4
|
+
import {
|
|
5
|
+
parseJsonObjectBody
|
|
6
|
+
} from "./chunk-3NCPXNBZ.js";
|
|
7
7
|
import {
|
|
8
8
|
mentionInputToPart,
|
|
9
9
|
toChatMessageParts
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-4PZE7XAM.js";
|
|
11
11
|
import {
|
|
12
12
|
ChatTurnInputError,
|
|
13
13
|
assertPromptPartsWithinCap,
|
|
@@ -1078,4 +1078,4 @@ export {
|
|
|
1078
1078
|
createChatTurnRoutes,
|
|
1079
1079
|
streamChatRouteAsSandboxEvents
|
|
1080
1080
|
};
|
|
1081
|
-
//# sourceMappingURL=chunk-
|
|
1081
|
+
//# sourceMappingURL=chunk-YFGG722I.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canTransitionInteractionStatus,
|
|
3
|
+
persistedPartToInteraction
|
|
4
|
+
} from "./chunk-M3K2HVQD.js";
|
|
1
5
|
import {
|
|
2
6
|
canTransitionPlanStatus,
|
|
3
7
|
persistedPartToPlan,
|
|
4
8
|
planPartKey,
|
|
5
9
|
planToPersistedPart
|
|
6
10
|
} from "./chunk-YJMCRXQQ.js";
|
|
7
|
-
import {
|
|
8
|
-
canTransitionInteractionStatus,
|
|
9
|
-
persistedPartToInteraction
|
|
10
|
-
} from "./chunk-M3K2HVQD.js";
|
|
11
11
|
|
|
12
12
|
// src/stream/stream-normalizer.ts
|
|
13
13
|
function asRecord(value) {
|
|
@@ -406,4 +406,4 @@ export {
|
|
|
406
406
|
terminalizeDanglingAssistantToolUpdates,
|
|
407
407
|
encodeEvent
|
|
408
408
|
};
|
|
409
|
-
//# sourceMappingURL=chunk-
|
|
409
|
+
//# sourceMappingURL=chunk-ZMMIQOFI.js.map
|
|
@@ -43,6 +43,10 @@ import {
|
|
|
43
43
|
selectTickStep
|
|
44
44
|
} from "../chunk-YJYPXMDL.js";
|
|
45
45
|
import "../chunk-Q2QKEV6J.js";
|
|
46
|
+
import {
|
|
47
|
+
DesignCanvasChromeLazy,
|
|
48
|
+
DesignCanvasLazy
|
|
49
|
+
} from "../chunk-ACFM2GFL.js";
|
|
46
50
|
import "../chunk-ZN5J47UX.js";
|
|
47
51
|
import {
|
|
48
52
|
DEFAULT_INSERT_TEMPLATES,
|
|
@@ -90,10 +94,6 @@ import {
|
|
|
90
94
|
bleedAwareExportBounds,
|
|
91
95
|
scaleForPreset
|
|
92
96
|
} from "../chunk-H6XQZFTT.js";
|
|
93
|
-
import {
|
|
94
|
-
DesignCanvasChromeLazy,
|
|
95
|
-
DesignCanvasLazy
|
|
96
|
-
} from "../chunk-ACFM2GFL.js";
|
|
97
97
|
import "../chunk-TZEEGDHS.js";
|
|
98
98
|
import "../chunk-3NCPXNBZ.js";
|
|
99
99
|
import "../chunk-TXD5HXLE.js";
|
|
@@ -1,121 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
attachWorkspaceLine,
|
|
3
|
+
createApplicationLineHandler,
|
|
4
|
+
publicApplicationSenderVerification
|
|
5
|
+
} from "../chunk-6RWQ4VW5.js";
|
|
6
|
+
import "../chunk-3NCPXNBZ.js";
|
|
4
7
|
import "../chunk-TXD5HXLE.js";
|
|
5
|
-
|
|
6
|
-
// src/hosted-agent/application.ts
|
|
7
|
-
import {
|
|
8
|
-
LINE_APPLICATION_REQUEST_MAX_BYTES,
|
|
9
|
-
parseLineApplicationRequest,
|
|
10
|
-
parseLineApplicationResult
|
|
11
|
-
} from "@tangle-network/sandbox/core";
|
|
12
|
-
|
|
13
|
-
// src/hosted-agent/workspace-line.ts
|
|
14
|
-
async function attachWorkspaceLine(input) {
|
|
15
|
-
if (!/^lsv_[A-Za-z0-9_-]+$/.test(input.senderVerificationId)) {
|
|
16
|
-
throw new TypeError("A valid sender verification id is required");
|
|
17
|
-
}
|
|
18
|
-
const verification = await input.ownerLines.getSenderVerification(input.lineId, input.senderVerificationId);
|
|
19
|
-
const expiresAt = new Date(verification.expiresAt).getTime();
|
|
20
|
-
if (verification.lineId !== input.lineId || verification.testId !== input.senderVerificationId || verification.state !== "verified" || !verification.proof.signedInboundTestAt || !verification.proof.providerReplyAcknowledgedAt || !verification.proof.signedInboundConfirmAt || !Number.isFinite(expiresAt) || expiresAt <= Date.now()) {
|
|
21
|
-
throw new TypeError("The selected line has no current verified sender proof");
|
|
22
|
-
}
|
|
23
|
-
const address = verification.approvedSender?.trim() ?? "";
|
|
24
|
-
const turnsPerDay = input.turnsPerDay ?? 20;
|
|
25
|
-
if (!/^\+[1-9]\d{6,14}$/.test(address)) {
|
|
26
|
-
throw new TypeError("The verified sender must be an E.164 phone number");
|
|
27
|
-
}
|
|
28
|
-
if (!Number.isSafeInteger(turnsPerDay) || turnsPerDay < 1 || turnsPerDay > 1e4) {
|
|
29
|
-
throw new TypeError("A daily turn limit between 1 and 10000 is required");
|
|
30
|
-
}
|
|
31
|
-
const url = new URL(input.application.url);
|
|
32
|
-
if (url.protocol !== "https:" || url.username || url.password || url.hash) {
|
|
33
|
-
throw new TypeError("The application callback must use HTTPS without URL credentials or a fragment");
|
|
34
|
-
}
|
|
35
|
-
if (!/^[\x21-\x7e]{1,1024}$/.test(input.application.binding) || !/^[\x21-\x7e]{16,512}$/.test(input.application.secret)) {
|
|
36
|
-
throw new TypeError("A binding and a header-safe callback credential are required");
|
|
37
|
-
}
|
|
38
|
-
const attachment = {
|
|
39
|
-
number: input.lineId,
|
|
40
|
-
senderVerificationId: input.senderVerificationId,
|
|
41
|
-
mode: "personal",
|
|
42
|
-
members: [{ address, role: "owner" }],
|
|
43
|
-
unknownSenders: "reject",
|
|
44
|
-
roles: { owner: { context: "own", tools: "act" } },
|
|
45
|
-
respond: { kind: "agent", application: { ...input.application } },
|
|
46
|
-
limits: { turnsPerMemberPerDay: turnsPerDay }
|
|
47
|
-
};
|
|
48
|
-
return input.box.lines.attach(attachment);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// src/hosted-agent/application-verification.ts
|
|
52
|
-
function publicApplicationSenderVerification(result) {
|
|
53
|
-
return {
|
|
54
|
-
lineId: result.lineId,
|
|
55
|
-
testId: result.testId,
|
|
56
|
-
state: result.state,
|
|
57
|
-
expiresAt: result.expiresAt,
|
|
58
|
-
proof: {
|
|
59
|
-
signedInboundTestAt: result.proof.signedInboundTestAt,
|
|
60
|
-
providerReplyAcknowledgedAt: result.proof.providerReplyAcknowledgedAt,
|
|
61
|
-
signedInboundConfirmAt: result.proof.signedInboundConfirmAt
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/hosted-agent/application.ts
|
|
67
|
-
function createApplicationLineHandler(options) {
|
|
68
|
-
return async (request) => {
|
|
69
|
-
if (request.method !== "POST") return failure(405, "method_not_allowed");
|
|
70
|
-
let authenticated;
|
|
71
|
-
try {
|
|
72
|
-
authenticated = await options.authenticate(request);
|
|
73
|
-
} catch (error) {
|
|
74
|
-
return error instanceof Response ? error : failure(503, "line_authentication_unavailable");
|
|
75
|
-
}
|
|
76
|
-
let input;
|
|
77
|
-
try {
|
|
78
|
-
if (request.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase() !== "application/json")
|
|
79
|
-
return failure(415, "json_required");
|
|
80
|
-
const [body, error] = await parseJsonObjectBody(request, { maxBytes: LINE_APPLICATION_REQUEST_MAX_BYTES });
|
|
81
|
-
if (error) return error;
|
|
82
|
-
input = parseLineApplicationRequest(body);
|
|
83
|
-
if (input.binding !== authenticated.binding) return failure(403, "line_binding_mismatch");
|
|
84
|
-
if (request.headers.get("idempotency-key") !== `line-application:${input.messageId}`)
|
|
85
|
-
return failure(400, "idempotency_key_mismatch");
|
|
86
|
-
} catch {
|
|
87
|
-
return failure(400, "line_request_invalid");
|
|
88
|
-
}
|
|
89
|
-
const immutable = Object.freeze({ ...input, sender: Object.freeze({ ...input.sender }) });
|
|
90
|
-
try {
|
|
91
|
-
const { target } = authenticated;
|
|
92
|
-
await options.authorize(target, immutable);
|
|
93
|
-
let observed = await options.read(target, immutable);
|
|
94
|
-
if (observed.state === "missing") {
|
|
95
|
-
if (immutable.acceptedExecutionId !== void 0)
|
|
96
|
-
return failure(503, "accepted_execution_unavailable");
|
|
97
|
-
await options.authorize(target, immutable);
|
|
98
|
-
await options.admit(target, immutable);
|
|
99
|
-
observed = await options.read(target, immutable);
|
|
100
|
-
if (observed.state === "missing") observed = { state: "pending", admitted: false };
|
|
101
|
-
}
|
|
102
|
-
await options.authorize(target, immutable);
|
|
103
|
-
const result = parseLineApplicationResult({
|
|
104
|
-
...observed,
|
|
105
|
-
version: 1,
|
|
106
|
-
binding: input.binding,
|
|
107
|
-
messageId: input.messageId,
|
|
108
|
-
attachmentId: input.attachmentId
|
|
109
|
-
}, input);
|
|
110
|
-
return Response.json(result, { headers: { "cache-control": "no-store" } });
|
|
111
|
-
} catch (error) {
|
|
112
|
-
return error instanceof Response ? error : failure(503, "line_application_unavailable");
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function failure(status, code) {
|
|
117
|
-
return Response.json({ error: { code } }, { status, headers: { "cache-control": "no-store" } });
|
|
118
|
-
}
|
|
119
8
|
export {
|
|
120
9
|
attachWorkspaceLine,
|
|
121
10
|
createApplicationLineHandler,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hosted-agent/application.ts","../../src/hosted-agent/workspace-line.ts","../../src/hosted-agent/application-verification.ts"],"sourcesContent":["import { parseJsonObjectBody } from '../web/core'\nimport {\n LINE_APPLICATION_REQUEST_MAX_BYTES,\n parseLineApplicationRequest,\n parseLineApplicationResult,\n type LineApplicationRequest,\n type LineApplicationResult,\n type LineApplicationState,\n} from '@tangle-network/sandbox/core'\n\nexport { attachWorkspaceLine } from './workspace-line'\nexport { publicApplicationSenderVerification } from './application-verification'\nexport type { ApplicationOwnerLines } from './workspace-line'\nexport type { ApplicationSenderVerification, ApplicationSenderVerificationStart, OwnerApplicationSenderVerification } from './application-verification'\n\n/** Missing is an affirmative storage observation, never an error fallback. */\nexport type ApplicationLineObservation = LineApplicationState | { state: 'missing' }\n\nexport interface ApplicationLineOptions<T> {\n /** Authenticate before consuming the body. It must not trust model-supplied identity. */\n authenticate(request: Request): Promise<{ binding: string; target: T }>\n /** Recheck live binding, membership, owner authority and exact retained message. */\n authorize(target: T, input: Readonly<LineApplicationRequest>): Promise<void>\n /** Observe the application's existing durable turn, transcript and outputs. */\n read(target: T, input: Readonly<LineApplicationRequest>): Promise<ApplicationLineObservation>\n /**\n * Enter the normal persisted chat route using input.messageId as its stable\n * client turn identity. That route owns admission, locks and completion.\n * This callback MUST deduplicate that identity across concurrent requests.\n */\n admit(target: T, input: Readonly<LineApplicationRequest>): Promise<void>\n}\n\n/** One bounded pass from the native Lines worker into the application's existing execution path. */\nexport function createApplicationLineHandler<T>(options: ApplicationLineOptions<T>) {\n return async (request: Request): Promise<Response> => {\n if (request.method !== 'POST') return failure(405, 'method_not_allowed')\n let authenticated: { binding: string; target: T }\n try {\n authenticated = await options.authenticate(request)\n } catch (error) {\n return error instanceof Response ? error : failure(503, 'line_authentication_unavailable')\n }\n let input: LineApplicationRequest\n try {\n if (request.headers.get('content-type')?.split(';')[0]?.trim().toLowerCase() !== 'application/json')\n return failure(415, 'json_required')\n const [body, error] = await parseJsonObjectBody(request, { maxBytes: LINE_APPLICATION_REQUEST_MAX_BYTES })\n if (error) return error\n input = parseLineApplicationRequest(body)\n if (input.binding !== authenticated.binding) return failure(403, 'line_binding_mismatch')\n if (request.headers.get('idempotency-key') !== `line-application:${input.messageId}`)\n return failure(400, 'idempotency_key_mismatch')\n } catch {\n return failure(400, 'line_request_invalid')\n }\n // A viewer's AbortSignal must not cancel the accepted application task.\n const immutable = Object.freeze({ ...input, sender: Object.freeze({ ...input.sender }) })\n try {\n const { target } = authenticated\n await options.authorize(target, immutable)\n let observed = await options.read(target, immutable)\n if (observed.state === 'missing') {\n if (immutable.acceptedExecutionId !== undefined)\n return failure(503, 'accepted_execution_unavailable')\n // The read may yield to revocation; check again before admitting work.\n await options.authorize(target, immutable)\n await options.admit(target, immutable)\n observed = await options.read(target, immutable)\n if (observed.state === 'missing') observed = { state: 'pending', admitted: false }\n }\n // Reading or admitting work may yield to a disconnect or member revocation.\n await options.authorize(target, immutable)\n const result: LineApplicationResult = parseLineApplicationResult({\n ...observed, version: 1, binding: input.binding,\n messageId: input.messageId, attachmentId: input.attachmentId,\n }, input)\n return Response.json(result, { headers: { 'cache-control': 'no-store' } })\n } catch (error) {\n // Unavailable authoritative state is not permission to start a new task.\n return error instanceof Response ? error : failure(503, 'line_application_unavailable')\n }\n }\n}\n\nfunction failure(status: number, code: string): Response {\n return Response.json({ error: { code } }, { status, headers: { 'cache-control': 'no-store' } })\n}\n","import type { LineApplication, LineAttachment, SandboxInstance } from '@tangle-network/sandbox/core'\nimport type { OwnerApplicationSenderVerification } from './application-verification'\n\nexport interface ApplicationOwnerLines {\n /** Read with the same owner API key that started TEST and will attach. */\n getSenderVerification(lineId: string, testId: string): Promise<OwnerApplicationSenderVerification>\n}\n\n/** Attach a proved handset to the application's normal chat path. Platform\n * atomically consumes the one-use proof and checks this owner key again. */\nexport async function attachWorkspaceLine(input: {\n box: Pick<SandboxInstance, 'lines'>\n ownerLines: ApplicationOwnerLines\n lineId: string\n senderVerificationId: string\n application: LineApplication\n turnsPerDay?: number\n}): Promise<LineAttachment> {\n if (!/^lsv_[A-Za-z0-9_-]+$/.test(input.senderVerificationId)) {\n throw new TypeError('A valid sender verification id is required')\n }\n const verification = await input.ownerLines.getSenderVerification(input.lineId, input.senderVerificationId)\n const expiresAt = new Date(verification.expiresAt).getTime()\n if (verification.lineId !== input.lineId || verification.testId !== input.senderVerificationId\n || verification.state !== 'verified' || !verification.proof.signedInboundTestAt\n || !verification.proof.providerReplyAcknowledgedAt || !verification.proof.signedInboundConfirmAt\n || !Number.isFinite(expiresAt) || expiresAt <= Date.now()) {\n throw new TypeError('The selected line has no current verified sender proof')\n }\n const address = verification.approvedSender?.trim() ?? ''\n const turnsPerDay = input.turnsPerDay ?? 20\n if (!/^\\+[1-9]\\d{6,14}$/.test(address)) {\n throw new TypeError('The verified sender must be an E.164 phone number')\n }\n if (!Number.isSafeInteger(turnsPerDay) || turnsPerDay < 1 || turnsPerDay > 10_000) {\n throw new TypeError('A daily turn limit between 1 and 10000 is required')\n }\n const url = new URL(input.application.url)\n if (url.protocol !== 'https:' || url.username || url.password || url.hash) {\n throw new TypeError('The application callback must use HTTPS without URL credentials or a fragment')\n }\n if (!/^[\\x21-\\x7e]{1,1024}$/.test(input.application.binding)\n || !/^[\\x21-\\x7e]{16,512}$/.test(input.application.secret)) {\n throw new TypeError('A binding and a header-safe callback credential are required')\n }\n const attachment = {\n number: input.lineId,\n senderVerificationId: input.senderVerificationId,\n mode: 'personal',\n members: [{ address, role: 'owner' }],\n unknownSenders: 'reject',\n roles: { owner: { context: 'own', tools: 'act' } },\n respond: { kind: 'agent', application: { ...input.application } },\n limits: { turnsPerMemberPerDay: turnsPerDay },\n } satisfies Parameters<SandboxInstance['lines']['attach']>[0] & { senderVerificationId: string }\n return input.box.lines.attach(attachment)\n}\n","/** Public TEST data. The private CONFIRM reply is never returned to a browser. */\nexport interface ApplicationSenderVerificationStart {\n lineId: string\n testId: string\n state: 'awaiting_test'\n testText: string\n expiresAt: string\n}\n\n/** Browser-safe status from the owner server. No sender address is present. */\nexport interface ApplicationSenderVerification {\n lineId: string\n testId: string\n state: 'awaiting_test' | 'sending' | 'challenge_sent' | 'verified'\n | 'consumed' | 'cancelled' | 'superseded' | 'failed' | 'expired'\n expiresAt: string\n proof: {\n signedInboundTestAt: string | null\n providerReplyAcknowledgedAt: string | null\n signedInboundConfirmAt: string | null\n }\n}\n\n/** The owner-key SDK read includes the confirmed sender for the attach helper. */\nexport interface OwnerApplicationSenderVerification extends ApplicationSenderVerification {\n approvedSender?: string\n}\n\n/** Use at the host response boundary so approvedSender cannot enter page state. */\nexport function publicApplicationSenderVerification(\n result: OwnerApplicationSenderVerification,\n): ApplicationSenderVerification {\n return {\n lineId: result.lineId,\n testId: result.testId,\n state: result.state,\n expiresAt: result.expiresAt,\n proof: {\n signedInboundTestAt: result.proof.signedInbound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AAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,SAAS,EAAE,iBAAiB,WAAW,EAAE,CAAC;AAChG;","names":[]}
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface HubConnectCallbackPageProps {
|
|
2
|
+
/** Local settings destination owned by the consuming app. */
|
|
3
|
+
returnHref: string;
|
|
4
|
+
}
|
|
5
|
+
/** The callback only signals completion; the opener verifies fresh Hub state. */
|
|
6
|
+
export declare function HubConnectCallbackPage({ returnHref }: HubConnectCallbackPageProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { HubApiKeyConnectionMetadata, HubConnection, HubConnectionHealthResponse, HubOAuthStartResponse, HubPolicy, HubPolicyDecision, HubProvider, HubTool } from '@tangle-network/hub-sdk';
|
|
2
|
+
/** The host must bind each request to this server-verified identity. */
|
|
3
|
+
export interface HubIntegrationsIdentity {
|
|
4
|
+
readonly userId: string;
|
|
5
|
+
readonly sessionId: string;
|
|
6
|
+
readonly workspaceId: string;
|
|
7
|
+
}
|
|
8
|
+
export interface HubSettingsRequest {
|
|
9
|
+
readonly identity: HubIntegrationsIdentity;
|
|
10
|
+
readonly path: string;
|
|
11
|
+
readonly init: RequestInit;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The host supplies its authenticated fetch, CSRF protection and expected
|
|
15
|
+
* identity check. The browser never receives a Hub credential or SDK client.
|
|
16
|
+
*/
|
|
17
|
+
export type HubSettingsRequestFn = (request: HubSettingsRequest) => Promise<Response>;
|
|
18
|
+
export interface HubIntegrationsClient {
|
|
19
|
+
providers(identity: HubIntegrationsIdentity, signal?: AbortSignal): Promise<HubProvider[]>;
|
|
20
|
+
connections(identity: HubIntegrationsIdentity, signal?: AbortSignal): Promise<HubConnection[]>;
|
|
21
|
+
startOAuth(identity: HubIntegrationsIdentity, providerId: string, input: {
|
|
22
|
+
returnUrl: string;
|
|
23
|
+
connectionParameters?: Record<string, string>;
|
|
24
|
+
}, signal?: AbortSignal): Promise<HubOAuthStartResponse>;
|
|
25
|
+
connectApiKey(identity: HubIntegrationsIdentity, providerId: string, apiKey: string, metadata?: HubApiKeyConnectionMetadata, signal?: AbortSignal): Promise<HubConnection>;
|
|
26
|
+
revoke(identity: HubIntegrationsIdentity, connectionId: string, signal?: AbortSignal): Promise<HubConnection>;
|
|
27
|
+
health(identity: HubIntegrationsIdentity, connectionId: string, signal?: AbortSignal): Promise<HubConnectionHealthResponse>;
|
|
28
|
+
actions(identity: HubIntegrationsIdentity, providerId: string, limit: number, signal?: AbortSignal): Promise<HubTool[]>;
|
|
29
|
+
policies(identity: HubIntegrationsIdentity, connectionId: string, signal?: AbortSignal): Promise<HubPolicy[]>;
|
|
30
|
+
setPolicy(identity: HubIntegrationsIdentity, connectionId: string, actionPath: string, decision: HubPolicyDecision, signal?: AbortSignal): Promise<HubPolicy>;
|
|
31
|
+
resetPolicy(identity: HubIntegrationsIdentity, connectionId: string, actionPath: string, signal?: AbortSignal): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/** Finite browser transport for the server-owned `createHubSettingsRoutes` API. */
|
|
34
|
+
export declare function createHubIntegrationsClient(request: HubSettingsRequestFn, basePath?: string): HubIntegrationsClient;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { HubConnectCallbackPage, type HubConnectCallbackPageProps } from './callback';
|
|
2
|
+
export { createHubIntegrationsClient, type HubIntegrationsClient, type HubIntegrationsIdentity, type HubSettingsRequest, type HubSettingsRequestFn } from './client';
|
|
3
|
+
export { HubIntegrationsPanel, type HubIntegrationsPanelProps } from './panel';
|
|
4
|
+
export { HUB_CONNECT_CHANNEL, HUB_CONNECTED_MESSAGE_TYPE, HUB_CONNECT_FAILED_MESSAGE_TYPE, POPUP_TIMEOUT_MS } from './popup';
|
|
5
|
+
export { useHubIntegrations, type HubWriteReceipt, type UseHubIntegrationsOptions } from './use-hub-integrations';
|
|
6
|
+
export { type HubIntegrationCapabilities, type HubIntegrationCapability } from './projection';
|