@tangle-network/agent-app 0.56.5 → 0.57.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-profiles/d1.d.ts +24 -0
- package/dist/agent-profiles/d1.js +428 -0
- package/dist/agent-profiles/d1.js.map +1 -0
- package/dist/agent-profiles/drizzle.d.ts +1191 -0
- package/dist/agent-profiles/drizzle.js +85 -0
- package/dist/agent-profiles/drizzle.js.map +1 -0
- package/dist/agent-profiles/index.d.ts +270 -0
- package/dist/agent-profiles/index.js +43 -0
- package/dist/agent-profiles/index.js.map +1 -0
- package/dist/agent-profiles/reaper.d.ts +31 -0
- package/dist/agent-profiles/reaper.js +29 -0
- package/dist/agent-profiles/reaper.js.map +1 -0
- package/dist/assistant/index.js +5 -5
- package/dist/chat-routes/index.js +11 -11
- package/dist/chat-store/index.js +2 -2
- package/dist/{chunk-JAK2WU5U.js → chunk-APZ4W7HJ.js} +2 -2
- package/dist/chunk-D2NZQCOB.js +421 -0
- package/dist/chunk-D2NZQCOB.js.map +1 -0
- package/dist/{chunk-7YLSF33A.js → chunk-IVE3T73T.js} +7 -7
- package/dist/{chunk-RNHXRPHO.js → chunk-NWR5CERQ.js} +12 -12
- package/dist/{chunk-HTAFI247.js → chunk-WTGSLW5X.js} +4 -4
- package/dist/design-canvas-react/index.js +4 -4
- package/dist/preset-cloudflare/index.js +3 -3
- package/dist/profile/index.js +9 -9
- package/dist/public-consultation/index.js +6 -6
- package/dist/sandbox/index.js +2 -2
- package/dist/skills-placement/index.js +3 -3
- package/dist/stream/index.js +16 -16
- package/dist/tools/index.js +2 -2
- package/dist/web-react/index.js +10 -10
- package/package.json +21 -1
- /package/dist/{chunk-JAK2WU5U.js.map → chunk-APZ4W7HJ.js.map} +0 -0
- /package/dist/{chunk-7YLSF33A.js.map → chunk-IVE3T73T.js.map} +0 -0
- /package/dist/{chunk-RNHXRPHO.js.map → chunk-NWR5CERQ.js.map} +0 -0
- /package/dist/{chunk-HTAFI247.js.map → chunk-WTGSLW5X.js.map} +0 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
// src/agent-profiles/index.ts
|
|
2
|
+
import {
|
|
3
|
+
canonicalAgentProfileDigest,
|
|
4
|
+
diffAgentProfiles,
|
|
5
|
+
snapshotAgentProfile,
|
|
6
|
+
sha256Utf8
|
|
7
|
+
} from "@tangle-network/agent-interface";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
var PROFILE_CHANGE_POLICY = {
|
|
10
|
+
textEdit: { admission: "automatic", conversation: "same", destructive: false },
|
|
11
|
+
sameAuthoritySwitch: { admission: "automatic", conversation: "same", destructive: false },
|
|
12
|
+
differentAuthoritySwitch: { admission: "prepare-then-flip", conversation: "same", destructive: false },
|
|
13
|
+
authorityEdit: { admission: "editor-consent", conversation: "same", destructive: false },
|
|
14
|
+
optimizerRevision: { admission: "eval-promotion", conversation: "same", destructive: false },
|
|
15
|
+
destructiveAction: { admission: "reaper-only", conversation: "none", destructive: true }
|
|
16
|
+
};
|
|
17
|
+
var ProfileConflictError = class extends Error {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "ProfileConflictError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var ProfileAccessError = class extends Error {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "ProfileAccessError";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
function profileAuthority(profile) {
|
|
30
|
+
const { name: _name, description: _description, prompt, ...authority } = profile;
|
|
31
|
+
const { systemPrompt: _systemPrompt, instructions: _instructions, ...promptAuthority } = prompt ?? {};
|
|
32
|
+
return { ...authority, ...Object.keys(promptAuthority).length ? { prompt: promptAuthority } : {} };
|
|
33
|
+
}
|
|
34
|
+
function profileAuthorityDigest(profile) {
|
|
35
|
+
return canonicalAgentProfileDigest(profileAuthority(snapshotAgentProfile(profile)));
|
|
36
|
+
}
|
|
37
|
+
function projectKnowledgeDocuments(events) {
|
|
38
|
+
const removed = new Set(events.filter((event) => event.kind === "remove").flatMap((event) => event.observedAddIds));
|
|
39
|
+
const visible = events.filter((event) => event.kind === "add" && !removed.has(event.id));
|
|
40
|
+
const latest = /* @__PURE__ */ new Map();
|
|
41
|
+
for (const event of visible) {
|
|
42
|
+
const prior = latest.get(event.documentId);
|
|
43
|
+
if (!prior || event.createdAt > prior.createdAt || event.createdAt === prior.createdAt && event.id > prior.id) latest.set(event.documentId, event);
|
|
44
|
+
}
|
|
45
|
+
return [...latest.values()].sort((a, b) => a.documentId.localeCompare(b.documentId)).map((event) => ({ documentId: event.documentId, content: event.content, addEventId: event.id }));
|
|
46
|
+
}
|
|
47
|
+
async function addProfileKnowledgeDocument(input) {
|
|
48
|
+
if (input.actorRole !== "owner" && input.actorRole !== "manager") {
|
|
49
|
+
throw new ProfileAccessError("Profile management is required");
|
|
50
|
+
}
|
|
51
|
+
if (!input.documentId || !input.content) throw new TypeError("A knowledge document needs an id and content");
|
|
52
|
+
const event = {
|
|
53
|
+
id: input.id ?? crypto.randomUUID(),
|
|
54
|
+
workspaceId: input.workspaceId,
|
|
55
|
+
profileId: input.profileId,
|
|
56
|
+
documentId: input.documentId,
|
|
57
|
+
kind: "add",
|
|
58
|
+
content: input.content,
|
|
59
|
+
observedAddIds: [],
|
|
60
|
+
createdAt: input.now ?? Date.now()
|
|
61
|
+
};
|
|
62
|
+
await input.store.appendKnowledgeEvent(event);
|
|
63
|
+
return event;
|
|
64
|
+
}
|
|
65
|
+
async function removeProfileKnowledgeDocument(input) {
|
|
66
|
+
if (input.actorRole !== "owner" && input.actorRole !== "manager") {
|
|
67
|
+
throw new ProfileAccessError("Profile management is required");
|
|
68
|
+
}
|
|
69
|
+
const events = await input.store.listKnowledgeEvents(input.workspaceId, input.profileId);
|
|
70
|
+
const removed = new Set(events.filter((event2) => event2.kind === "remove").flatMap((event2) => event2.observedAddIds));
|
|
71
|
+
const observedAddIds = events.filter((event2) => event2.kind === "add" && event2.documentId === input.documentId && !removed.has(event2.id)).map((event2) => event2.id);
|
|
72
|
+
const event = {
|
|
73
|
+
id: input.id ?? crypto.randomUUID(),
|
|
74
|
+
workspaceId: input.workspaceId,
|
|
75
|
+
profileId: input.profileId,
|
|
76
|
+
documentId: input.documentId,
|
|
77
|
+
kind: "remove",
|
|
78
|
+
content: null,
|
|
79
|
+
observedAddIds,
|
|
80
|
+
createdAt: input.now ?? Date.now()
|
|
81
|
+
};
|
|
82
|
+
await input.store.appendKnowledgeEvent(event);
|
|
83
|
+
return event;
|
|
84
|
+
}
|
|
85
|
+
function bindProfileText(consentedBaseline, selected) {
|
|
86
|
+
if (profileAuthorityDigest(consentedBaseline) !== profileAuthorityDigest(selected)) {
|
|
87
|
+
throw new ProfileAccessError("Profile authority differs; prepare its managed plan before the next turn");
|
|
88
|
+
}
|
|
89
|
+
const result = { ...consentedBaseline, name: selected.name, description: selected.description };
|
|
90
|
+
const prompt = {
|
|
91
|
+
...consentedBaseline.prompt,
|
|
92
|
+
systemPrompt: selected.prompt?.systemPrompt,
|
|
93
|
+
instructions: selected.prompt?.instructions
|
|
94
|
+
};
|
|
95
|
+
if (Object.values(prompt).some((value) => value !== void 0)) result.prompt = prompt;
|
|
96
|
+
else delete result.prompt;
|
|
97
|
+
return snapshotAgentProfile(result);
|
|
98
|
+
}
|
|
99
|
+
async function proposeRevision(input) {
|
|
100
|
+
if (input.author.kind !== "optimizer" && input.actorRole !== "owner" && input.actorRole !== "manager") {
|
|
101
|
+
throw new ProfileAccessError("Only an owner or manager can change a profile");
|
|
102
|
+
}
|
|
103
|
+
if (!input.workspaceId || !input.profileId || !input.author.id || !input.reason.trim() || !/^sha256:[a-f0-9]{64}$/.test(input.planDigest)) {
|
|
104
|
+
throw new TypeError("A profile revision needs workspace, profile, author, reason and plan digest");
|
|
105
|
+
}
|
|
106
|
+
const previous = await input.store.getActiveRevision(input.workspaceId, input.profileId);
|
|
107
|
+
if ((previous?.id ?? null) !== input.expectedRevisionId) {
|
|
108
|
+
throw new ProfileConflictError("The profile changed; read its latest revision before saving");
|
|
109
|
+
}
|
|
110
|
+
const profile = snapshotAgentProfile(input.profile);
|
|
111
|
+
const diff = previous ? diffAgentProfiles(previous.profile, profile) : [];
|
|
112
|
+
const authorityDigest = profileAuthorityDigest(profile);
|
|
113
|
+
const authorityChanged = !!previous && previous.authorityDigest !== authorityDigest;
|
|
114
|
+
const admission = input.author.kind === "optimizer" ? PROFILE_CHANGE_POLICY.optimizerRevision.admission : authorityChanged ? PROFILE_CHANGE_POLICY.authorityEdit.admission : PROFILE_CHANGE_POLICY.textEdit.admission;
|
|
115
|
+
const state = admission === "eval-promotion" ? "candidate" : admission === "editor-consent" ? "pending-consent" : "active";
|
|
116
|
+
const revision = {
|
|
117
|
+
id: input.id ?? crypto.randomUUID(),
|
|
118
|
+
workspaceId: input.workspaceId,
|
|
119
|
+
profileId: input.profileId,
|
|
120
|
+
parentId: previous?.id ?? null,
|
|
121
|
+
profile,
|
|
122
|
+
knowledgeText: input.knowledgeText,
|
|
123
|
+
author: input.author,
|
|
124
|
+
reason: input.reason.trim(),
|
|
125
|
+
diff,
|
|
126
|
+
authorityDigest,
|
|
127
|
+
planDigest: input.planDigest,
|
|
128
|
+
state,
|
|
129
|
+
createdAt: input.now ?? Date.now()
|
|
130
|
+
};
|
|
131
|
+
if (!await input.store.appendRevision(revision, input.expectedRevisionId, state === "active")) {
|
|
132
|
+
throw new ProfileConflictError("The profile changed while saving");
|
|
133
|
+
}
|
|
134
|
+
return revision;
|
|
135
|
+
}
|
|
136
|
+
async function promoteRevision(input) {
|
|
137
|
+
if (input.actorRole !== "owner" && input.actorRole !== "manager") {
|
|
138
|
+
throw new ProfileAccessError("Only an owner or manager can promote a profile");
|
|
139
|
+
}
|
|
140
|
+
const [revision, head] = await Promise.all([
|
|
141
|
+
input.store.getRevision(input.workspaceId, input.profileId, input.revisionId),
|
|
142
|
+
input.store.getActiveRevision(input.workspaceId, input.profileId)
|
|
143
|
+
]);
|
|
144
|
+
if (!revision || revision.parentId !== (head?.id ?? null)) throw new ProfileConflictError("Profile parent changed");
|
|
145
|
+
if (revision.authorityDigest !== head?.authorityDigest && (!input.verifyConsent || !await input.verifyConsent(revision))) {
|
|
146
|
+
throw new ProfileAccessError("Authority changes require owner consent");
|
|
147
|
+
}
|
|
148
|
+
if (!await input.store.promoteRevision(input.workspaceId, input.profileId, revision.id, head?.id ?? null)) {
|
|
149
|
+
throw new ProfileConflictError("The profile changed while promoting");
|
|
150
|
+
}
|
|
151
|
+
return revision;
|
|
152
|
+
}
|
|
153
|
+
function parseProfileSwitch(text) {
|
|
154
|
+
const trimmed = text.trim();
|
|
155
|
+
if (!/^switch\s+to\b/i.test(trimmed)) return null;
|
|
156
|
+
const match = /^switch[ \t]+to[ \t]+([^\r\n]+)$/i.exec(trimmed);
|
|
157
|
+
return match?.[1]?.trim() ? { name: match[1].trim() } : { invalid: true };
|
|
158
|
+
}
|
|
159
|
+
function normalizeProfileName(name) {
|
|
160
|
+
return name.trim().replace(/\s+/g, " ").toLowerCase();
|
|
161
|
+
}
|
|
162
|
+
async function switchProfile(input) {
|
|
163
|
+
const inputHash = sha256Utf8(input.content);
|
|
164
|
+
const previousReceipt = await input.store.getSwitchReceipt(input.key, input.messageId, inputHash);
|
|
165
|
+
if (previousReceipt) return previousReceipt;
|
|
166
|
+
const binding = await input.store.getBinding(input.key);
|
|
167
|
+
const choice = input.choice;
|
|
168
|
+
const matches = "name" in choice ? input.profiles.filter((profile) => normalizeProfileName(profile.name) === normalizeProfileName(choice.name)) : input.profiles.filter((profile) => profile.id === choice.profileId);
|
|
169
|
+
const target = matches.length === 1 ? matches[0] : void 0;
|
|
170
|
+
let revision = null;
|
|
171
|
+
if (target?.status === "active" && await input.canSelect(target.id)) {
|
|
172
|
+
revision = await input.store.getActiveRevision(input.key.workspaceId, target.id);
|
|
173
|
+
if (revision && "name" in choice && normalizeProfileName(revision.profile.name ?? "") !== normalizeProfileName(choice.name)) {
|
|
174
|
+
revision = null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
let outcome = "refused";
|
|
178
|
+
let message = matches.length > 1 ? "That profile name is ambiguous." : target?.status !== "active" && target ? `${target.name} is not active.` : "That profile is not available for this member.";
|
|
179
|
+
let planDigest = null;
|
|
180
|
+
let conflicts = [];
|
|
181
|
+
if (revision && target) {
|
|
182
|
+
const admission = binding?.authorityDigest === revision.authorityDigest ? PROFILE_CHANGE_POLICY.sameAuthoritySwitch.admission : PROFILE_CHANGE_POLICY.differentAuthoritySwitch.admission;
|
|
183
|
+
if (admission === "prepare-then-flip" || binding?.planDigest !== revision.planDigest) {
|
|
184
|
+
try {
|
|
185
|
+
const prepared = await input.prepareAuthority(revision, input.key);
|
|
186
|
+
if (!prepared.healthy || prepared.planDigest !== revision.planDigest) {
|
|
187
|
+
throw new ProfileConflictError("The managed plan was not prepared for this revision");
|
|
188
|
+
}
|
|
189
|
+
planDigest = prepared.planDigest;
|
|
190
|
+
conflicts = prepared.conflicts;
|
|
191
|
+
} catch {
|
|
192
|
+
revision = null;
|
|
193
|
+
message = `Could not prepare ${target.name}; your current agent is unchanged.`;
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
planDigest = binding.planDigest;
|
|
197
|
+
}
|
|
198
|
+
if (revision && planDigest) {
|
|
199
|
+
outcome = "switched";
|
|
200
|
+
message = `Now talking to ${target.name}`;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return input.store.recordSwitch({
|
|
204
|
+
key: input.key,
|
|
205
|
+
messageId: input.messageId,
|
|
206
|
+
inputHash,
|
|
207
|
+
profileId: revision?.profileId ?? null,
|
|
208
|
+
revisionId: revision?.id ?? null,
|
|
209
|
+
pinnedRevisionId: null,
|
|
210
|
+
authorityDigest: revision?.authorityDigest ?? null,
|
|
211
|
+
planDigest,
|
|
212
|
+
outcome,
|
|
213
|
+
message,
|
|
214
|
+
conflicts
|
|
215
|
+
}, binding?.version ?? 0);
|
|
216
|
+
}
|
|
217
|
+
async function handleProfileSwitchText(input) {
|
|
218
|
+
const parsed = parseProfileSwitch(input.content);
|
|
219
|
+
if (!parsed) return null;
|
|
220
|
+
if ("name" in parsed) return switchProfile({ ...input, choice: parsed });
|
|
221
|
+
const inputHash = sha256Utf8(input.content);
|
|
222
|
+
const previous = await input.store.getSwitchReceipt(input.key, input.messageId, inputHash);
|
|
223
|
+
if (previous) return previous;
|
|
224
|
+
const binding = await input.store.getBinding(input.key);
|
|
225
|
+
return input.store.recordSwitch(
|
|
226
|
+
{
|
|
227
|
+
key: input.key,
|
|
228
|
+
messageId: input.messageId,
|
|
229
|
+
inputHash,
|
|
230
|
+
profileId: null,
|
|
231
|
+
revisionId: null,
|
|
232
|
+
pinnedRevisionId: null,
|
|
233
|
+
outcome: "refused",
|
|
234
|
+
authorityDigest: null,
|
|
235
|
+
planDigest: null,
|
|
236
|
+
conflicts: [],
|
|
237
|
+
message: "Send only \u201CSwitch to [agent name]\u201D to change agents."
|
|
238
|
+
},
|
|
239
|
+
binding?.version ?? 0
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
async function rollbackProfileBinding(input) {
|
|
243
|
+
if (input.actorRole !== "owner" && input.actorRole !== "manager") {
|
|
244
|
+
throw new ProfileAccessError("Only an owner or manager can roll back a profile");
|
|
245
|
+
}
|
|
246
|
+
const inputHash = sha256Utf8(`rollback:${input.messageId}`);
|
|
247
|
+
const prior = await input.store.getSwitchReceipt(input.key, input.messageId, inputHash);
|
|
248
|
+
if (prior) return prior;
|
|
249
|
+
const binding = await input.store.getBinding(input.key);
|
|
250
|
+
if (!binding || !await input.canSelect(binding.profileId)) throw new ProfileAccessError("Profile is unavailable");
|
|
251
|
+
const current = binding.pinnedRevisionId ? await input.store.getRevision(input.key.workspaceId, binding.profileId, binding.pinnedRevisionId) : await input.store.getActiveRevision(input.key.workspaceId, binding.profileId);
|
|
252
|
+
if (!current?.parentId) throw new ProfileConflictError("The bound profile has no previous revision");
|
|
253
|
+
const parent = await input.store.getRevision(input.key.workspaceId, binding.profileId, current.parentId);
|
|
254
|
+
if (!parent) throw new ProfileConflictError("The previous revision is unavailable");
|
|
255
|
+
let planDigest = binding.planDigest;
|
|
256
|
+
let conflicts = [];
|
|
257
|
+
if (binding.authorityDigest !== parent.authorityDigest || binding.planDigest !== parent.planDigest) {
|
|
258
|
+
try {
|
|
259
|
+
const prepared = await input.prepareAuthority(parent, input.key);
|
|
260
|
+
if (!prepared.healthy || prepared.planDigest !== parent.planDigest) {
|
|
261
|
+
throw new ProfileConflictError("The prior managed plan was not prepared");
|
|
262
|
+
}
|
|
263
|
+
planDigest = prepared.planDigest;
|
|
264
|
+
conflicts = prepared.conflicts;
|
|
265
|
+
} catch {
|
|
266
|
+
return input.store.recordSwitch(
|
|
267
|
+
{
|
|
268
|
+
key: input.key,
|
|
269
|
+
messageId: input.messageId,
|
|
270
|
+
inputHash,
|
|
271
|
+
profileId: null,
|
|
272
|
+
revisionId: null,
|
|
273
|
+
pinnedRevisionId: null,
|
|
274
|
+
outcome: "refused",
|
|
275
|
+
authorityDigest: null,
|
|
276
|
+
planDigest: null,
|
|
277
|
+
conflicts: [],
|
|
278
|
+
message: "Could not prepare the previous profile; your current agent is unchanged."
|
|
279
|
+
},
|
|
280
|
+
binding.version
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return input.store.recordSwitch({
|
|
285
|
+
key: input.key,
|
|
286
|
+
messageId: input.messageId,
|
|
287
|
+
inputHash,
|
|
288
|
+
profileId: parent.profileId,
|
|
289
|
+
revisionId: parent.id,
|
|
290
|
+
pinnedRevisionId: parent.id,
|
|
291
|
+
authorityDigest: parent.authorityDigest,
|
|
292
|
+
planDigest,
|
|
293
|
+
outcome: "switched",
|
|
294
|
+
conflicts,
|
|
295
|
+
message: `Now talking to ${parent.profile.name ?? "this profile"}`
|
|
296
|
+
}, binding.version);
|
|
297
|
+
}
|
|
298
|
+
async function admitProfileTurn(input) {
|
|
299
|
+
const inputHash = sha256Utf8(input.content);
|
|
300
|
+
const prior = await input.store.getTurnPin(input.key, input.messageId, inputHash);
|
|
301
|
+
if (prior) return prior;
|
|
302
|
+
const binding = await input.store.getBinding(input.key);
|
|
303
|
+
if (!binding) throw new ProfileAccessError("Choose a profile before sending a message");
|
|
304
|
+
const revision = binding.pinnedRevisionId ? await input.store.getRevision(input.key.workspaceId, binding.profileId, binding.pinnedRevisionId) : await input.store.getActiveRevision(input.key.workspaceId, binding.profileId);
|
|
305
|
+
if (!revision) throw new ProfileConflictError("The bound profile revision is unavailable");
|
|
306
|
+
if (revision.authorityDigest !== binding.authorityDigest || !/^sha256:[a-f0-9]{64}$/.test(input.observedManagedPlanDigest)) {
|
|
307
|
+
throw new ProfileAccessError("The selected managed plan is not active for this turn");
|
|
308
|
+
}
|
|
309
|
+
const planMatches = revision.planDigest === input.observedManagedPlanDigest || input.verifyEffectivePlan !== void 0 && await input.verifyEffectivePlan(revision, input.observedManagedPlanDigest, input.key);
|
|
310
|
+
if (!planMatches) {
|
|
311
|
+
throw new ProfileAccessError("The selected managed plan is not active for this turn");
|
|
312
|
+
}
|
|
313
|
+
return input.store.pinTurn({
|
|
314
|
+
...input.key,
|
|
315
|
+
messageId: input.messageId,
|
|
316
|
+
inputHash,
|
|
317
|
+
profileId: revision.profileId,
|
|
318
|
+
revisionId: revision.id,
|
|
319
|
+
authorityDigest: revision.authorityDigest,
|
|
320
|
+
planDigest: input.observedManagedPlanDigest
|
|
321
|
+
}, binding.version);
|
|
322
|
+
}
|
|
323
|
+
var textChangeSchema = z.object({
|
|
324
|
+
name: z.string().trim().min(1).max(160).optional(),
|
|
325
|
+
description: z.string().max(2e3).nullable().optional(),
|
|
326
|
+
systemPrompt: z.string().max(32e3).nullable().optional(),
|
|
327
|
+
instructions: z.array(z.string().max(32e3)).max(40).optional(),
|
|
328
|
+
knowledgeText: z.string().max(32e3).optional()
|
|
329
|
+
}).strict().refine((changes) => Object.keys(changes).length > 0);
|
|
330
|
+
var updateToolSchema = z.object({ expectedRevisionId: z.string().min(1), changes: textChangeSchema }).strict();
|
|
331
|
+
function profileTextChange(revision, changes) {
|
|
332
|
+
const profile = structuredClone(revision.profile);
|
|
333
|
+
if (changes.name !== void 0) profile.name = changes.name;
|
|
334
|
+
if (changes.description !== void 0) profile.description = changes.description ?? void 0;
|
|
335
|
+
if (changes.systemPrompt !== void 0 || changes.instructions !== void 0) {
|
|
336
|
+
profile.prompt = {
|
|
337
|
+
...profile.prompt,
|
|
338
|
+
...changes.systemPrompt !== void 0 ? { systemPrompt: changes.systemPrompt ?? void 0 } : {},
|
|
339
|
+
...changes.instructions !== void 0 ? { instructions: changes.instructions } : {}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
return { profile: snapshotAgentProfile(profile), knowledgeText: changes.knowledgeText ?? revision.knowledgeText };
|
|
343
|
+
}
|
|
344
|
+
function profileTools(context) {
|
|
345
|
+
return [{
|
|
346
|
+
name: "profile.read",
|
|
347
|
+
description: "Read the active agent profile text and revision. Saved text applies on the next message.",
|
|
348
|
+
inputSchema: z.toJSONSchema(z.object({}).strict(), { io: "input" }),
|
|
349
|
+
async run(args) {
|
|
350
|
+
z.object({}).strict().parse(args);
|
|
351
|
+
const turn = await context.activeTurn();
|
|
352
|
+
if (turn.role !== "owner" && turn.role !== "manager") throw new ProfileAccessError("Profile management is required");
|
|
353
|
+
const revision = await context.store.getActiveRevision(turn.workspaceId, turn.profileId);
|
|
354
|
+
if (!revision) throw new ProfileConflictError("Profile revision is unavailable");
|
|
355
|
+
return {
|
|
356
|
+
profileId: turn.profileId,
|
|
357
|
+
revisionId: revision.id,
|
|
358
|
+
currentTurnRevisionId: turn.revisionId,
|
|
359
|
+
name: revision.profile.name,
|
|
360
|
+
description: revision.profile.description ?? null,
|
|
361
|
+
systemPrompt: revision.profile.prompt?.systemPrompt ?? null,
|
|
362
|
+
instructions: revision.profile.prompt?.instructions ?? [],
|
|
363
|
+
knowledgeText: revision.knowledgeText
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
}, {
|
|
367
|
+
name: "profile.update",
|
|
368
|
+
description: "Save a requested owner or manager text change with the revision from profile.read. Applies on the next message.",
|
|
369
|
+
inputSchema: z.toJSONSchema(updateToolSchema, { io: "input" }),
|
|
370
|
+
async run(args) {
|
|
371
|
+
const { expectedRevisionId, changes } = updateToolSchema.parse(args);
|
|
372
|
+
const turn = await context.activeTurn();
|
|
373
|
+
if (turn.role !== "owner" && turn.role !== "manager") throw new ProfileAccessError("Profile management is required");
|
|
374
|
+
const current = await context.store.getActiveRevision(turn.workspaceId, turn.profileId);
|
|
375
|
+
if (!current || current.id !== expectedRevisionId) throw new ProfileConflictError("The profile changed; read it again");
|
|
376
|
+
const next = profileTextChange(current, changes);
|
|
377
|
+
const revision = await proposeRevision({
|
|
378
|
+
store: context.store,
|
|
379
|
+
workspaceId: turn.workspaceId,
|
|
380
|
+
profileId: turn.profileId,
|
|
381
|
+
expectedRevisionId,
|
|
382
|
+
...next,
|
|
383
|
+
planDigest: await context.planDigest(next.profile, next.knowledgeText),
|
|
384
|
+
author: { kind: "agent", id: turn.memberId },
|
|
385
|
+
actorRole: turn.role,
|
|
386
|
+
reason: "Owner or manager requested a text change during chat"
|
|
387
|
+
});
|
|
388
|
+
return {
|
|
389
|
+
profileId: turn.profileId,
|
|
390
|
+
revisionId: revision.id,
|
|
391
|
+
state: revision.state,
|
|
392
|
+
canonicalSaved: revision.state === "active",
|
|
393
|
+
appliesTo: "next_message",
|
|
394
|
+
currentTurn: "unchanged"
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
}];
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export {
|
|
401
|
+
PROFILE_CHANGE_POLICY,
|
|
402
|
+
ProfileConflictError,
|
|
403
|
+
ProfileAccessError,
|
|
404
|
+
profileAuthority,
|
|
405
|
+
profileAuthorityDigest,
|
|
406
|
+
projectKnowledgeDocuments,
|
|
407
|
+
addProfileKnowledgeDocument,
|
|
408
|
+
removeProfileKnowledgeDocument,
|
|
409
|
+
bindProfileText,
|
|
410
|
+
proposeRevision,
|
|
411
|
+
promoteRevision,
|
|
412
|
+
parseProfileSwitch,
|
|
413
|
+
normalizeProfileName,
|
|
414
|
+
switchProfile,
|
|
415
|
+
handleProfileSwitchText,
|
|
416
|
+
rollbackProfileBinding,
|
|
417
|
+
admitProfileTurn,
|
|
418
|
+
profileTextChange,
|
|
419
|
+
profileTools
|
|
420
|
+
};
|
|
421
|
+
//# sourceMappingURL=chunk-D2NZQCOB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/agent-profiles/index.ts"],"sourcesContent":["/** Chat-owned profile revisions and member/channel bindings. Execution stays in the substrate. */\nimport {\n canonicalAgentProfileDigest,\n diffAgentProfiles,\n snapshotAgentProfile,\n sha256Utf8,\n type AgentProfile,\n type AgentProfileDiff,\n} from '@tangle-network/agent-interface'\nimport { z } from 'zod'\nimport type { McpToolDefinition } from '../tools'\n\nexport type ProfileAuthorKind = 'person' | 'agent' | 'optimizer'\nexport type ProfileRevisionState = 'active' | 'candidate' | 'pending-consent'\n\n/** The decision table used by every write path; products may narrow access, never widen it. */\nexport const PROFILE_CHANGE_POLICY = {\n textEdit: { admission: 'automatic', conversation: 'same', destructive: false },\n sameAuthoritySwitch: { admission: 'automatic', conversation: 'same', destructive: false },\n differentAuthoritySwitch: { admission: 'prepare-then-flip', conversation: 'same', destructive: false },\n authorityEdit: { admission: 'editor-consent', conversation: 'same', destructive: false },\n optimizerRevision: { admission: 'eval-promotion', conversation: 'same', destructive: false },\n destructiveAction: { admission: 'reaper-only', conversation: 'none', destructive: true },\n} as const\n\nexport interface ProfileRevision {\n id: string\n workspaceId: string\n profileId: string\n parentId: string | null\n profile: AgentProfile\n knowledgeText: string\n author: { kind: ProfileAuthorKind; id: string }\n reason: string\n diff: AgentProfileDiff[]\n authorityDigest: string\n /** ADC hash of the public profile plan, without per-turn product attachments. */\n planDigest: string\n state: ProfileRevisionState\n createdAt: number\n}\n\nexport interface ProfileBindingKey {\n workspaceId: string\n memberId: string\n /** `chat`, or a product-scoped phone line and sender key. */\n channel: string\n}\n\nexport interface ProfileBinding extends ProfileBindingKey {\n profileId: string\n pinnedRevisionId: string | null\n authorityDigest: string\n planDigest: string\n version: number\n}\n\nexport interface ProfileTurnPin {\n workspaceId: string\n memberId: string\n channel: string\n messageId: string\n inputHash: string\n profileId: string\n revisionId: string\n authorityDigest: string\n /** Effective ADC plan selected by the executor, including allowed turn attachments. */\n planDigest: string\n}\n\n/** Remove events name only adds they observed; a concurrent add survives. */\nexport interface ProfileKnowledgeEvent {\n id: string\n workspaceId: string\n profileId: string\n documentId: string\n kind: 'add' | 'remove'\n content: string | null\n observedAddIds: string[]\n createdAt: number\n}\n\nexport interface ProfileKnowledgeDocument {\n documentId: string\n content: string\n addEventId: string\n}\n\nexport interface ProfileSwitchReceipt {\n key: ProfileBindingKey\n messageId: string\n inputHash: string\n profileId: string | null\n revisionId: string | null\n /** A rollback binds the previous immutable revision, not the current head. */\n pinnedRevisionId: string | null\n authorityDigest: string | null\n planDigest: string | null\n outcome: 'switched' | 'refused'\n message: string\n /** Workspace resource collisions retain the original and place the profile copy beside it. */\n conflicts: string[]\n}\n\nexport interface ProfileRevisionStore {\n getActiveRevision(workspaceId: string, profileId: string): Promise<ProfileRevision | null>\n getRevision(workspaceId: string, profileId: string, revisionId: string): Promise<ProfileRevision | null>\n /** Append the immutable row and optionally an activation event in one guarded transaction. */\n appendRevision(revision: ProfileRevision, expectedActiveId: string | null, activate: boolean): Promise<boolean>\n /** Promotion appends an activation event; the historical revision remains immutable. */\n promoteRevision(workspaceId: string, profileId: string, revisionId: string, expectedActiveId: string | null): Promise<boolean>\n getBinding(key: ProfileBindingKey): Promise<ProfileBinding | null>\n getSwitchReceipt(key: ProfileBindingKey, messageId: string, inputHash: string): Promise<ProfileSwitchReceipt | null>\n /** Receipt and binding event append atomically; a refusal leaves the binding untouched. */\n recordSwitch(receipt: ProfileSwitchReceipt, expectedVersion: number): Promise<ProfileSwitchReceipt>\n /** Persist one immutable pin under a message id; retries must return the same pin. */\n pinTurn(pin: ProfileTurnPin, expectedBindingVersion: number): Promise<ProfileTurnPin>\n getTurnPin(key: ProfileBindingKey, messageId: string, inputHash: string): Promise<ProfileTurnPin | null>\n listKnowledgeEvents(workspaceId: string, profileId: string): Promise<ProfileKnowledgeEvent[]>\n appendKnowledgeEvent(event: ProfileKnowledgeEvent): Promise<void>\n}\n\nexport class ProfileConflictError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'ProfileConflictError'\n }\n}\n\nexport class ProfileAccessError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'ProfileAccessError'\n }\n}\n\n/** Remove exactly the declared text axes. Unknown future fields remain authority. */\nexport function profileAuthority(profile: AgentProfile): AgentProfile {\n const { name: _name, description: _description, prompt, ...authority } = profile\n const { systemPrompt: _systemPrompt, instructions: _instructions, ...promptAuthority } = prompt ?? {}\n return { ...authority, ...(Object.keys(promptAuthority).length ? { prompt: promptAuthority } : {}) }\n}\n\nexport function profileAuthorityDigest(profile: AgentProfile): string {\n return canonicalAgentProfileDigest(profileAuthority(snapshotAgentProfile(profile)))\n}\n\nexport function projectKnowledgeDocuments(events: readonly ProfileKnowledgeEvent[]): ProfileKnowledgeDocument[] {\n const removed = new Set(events.filter(event => event.kind === 'remove').flatMap(event => event.observedAddIds))\n const visible = events.filter(event => event.kind === 'add' && !removed.has(event.id))\n const latest = new Map<string, ProfileKnowledgeEvent>()\n for (const event of visible) {\n const prior = latest.get(event.documentId)\n if (!prior || event.createdAt > prior.createdAt ||\n (event.createdAt === prior.createdAt && event.id > prior.id)) latest.set(event.documentId, event)\n }\n return [...latest.values()].sort((a, b) => a.documentId.localeCompare(b.documentId))\n .map(event => ({ documentId: event.documentId, content: event.content!, addEventId: event.id }))\n}\n\nexport async function addProfileKnowledgeDocument(input: {\n store: ProfileRevisionStore\n workspaceId: string\n profileId: string\n documentId: string\n content: string\n actorRole: 'owner' | 'manager' | 'member' | 'viewer'\n id?: string\n now?: number\n}): Promise<ProfileKnowledgeEvent> {\n if (input.actorRole !== 'owner' && input.actorRole !== 'manager') {\n throw new ProfileAccessError('Profile management is required')\n }\n if (!input.documentId || !input.content) throw new TypeError('A knowledge document needs an id and content')\n const event: ProfileKnowledgeEvent = { id: input.id ?? crypto.randomUUID(),\n workspaceId: input.workspaceId, profileId: input.profileId, documentId: input.documentId,\n kind: 'add', content: input.content, observedAddIds: [], createdAt: input.now ?? Date.now() }\n await input.store.appendKnowledgeEvent(event)\n return event\n}\n\nexport async function removeProfileKnowledgeDocument(input: {\n store: ProfileRevisionStore\n workspaceId: string\n profileId: string\n documentId: string\n actorRole: 'owner' | 'manager' | 'member' | 'viewer'\n id?: string\n now?: number\n}): Promise<ProfileKnowledgeEvent> {\n if (input.actorRole !== 'owner' && input.actorRole !== 'manager') {\n throw new ProfileAccessError('Profile management is required')\n }\n const events = await input.store.listKnowledgeEvents(input.workspaceId, input.profileId)\n const removed = new Set(events.filter(event => event.kind === 'remove').flatMap(event => event.observedAddIds))\n const observedAddIds = events.filter(event => event.kind === 'add' &&\n event.documentId === input.documentId && !removed.has(event.id)).map(event => event.id)\n const event: ProfileKnowledgeEvent = { id: input.id ?? crypto.randomUUID(),\n workspaceId: input.workspaceId, profileId: input.profileId, documentId: input.documentId,\n kind: 'remove', content: null, observedAddIds, createdAt: input.now ?? Date.now() }\n await input.store.appendKnowledgeEvent(event)\n return event\n}\n\n/** The per-turn text overlay is validated without admitting tools, model, MCP or resources. */\nexport function bindProfileText(consentedBaseline: AgentProfile, selected: AgentProfile): AgentProfile {\n if (profileAuthorityDigest(consentedBaseline) !== profileAuthorityDigest(selected)) {\n throw new ProfileAccessError('Profile authority differs; prepare its managed plan before the next turn')\n }\n const result: AgentProfile = { ...consentedBaseline, name: selected.name, description: selected.description }\n const prompt = { ...consentedBaseline.prompt, systemPrompt: selected.prompt?.systemPrompt,\n instructions: selected.prompt?.instructions }\n if (Object.values(prompt).some(value => value !== undefined)) result.prompt = prompt\n else delete result.prompt\n return snapshotAgentProfile(result)\n}\n\nexport interface ProposeRevisionInput {\n store: ProfileRevisionStore\n workspaceId: string\n profileId: string\n expectedRevisionId: string | null\n profile: AgentProfile\n knowledgeText: string\n /** The exact ADC `hashWorkspacePlan` for this authored snapshot. */\n planDigest: string\n author: ProfileRevision['author']\n /** Trusted role from the authenticated session, never model arguments. */\n actorRole: 'owner' | 'manager' | 'member' | 'viewer'\n reason: string\n id?: string\n now?: number\n}\n\n/** All authors use one immutable write path. Optimizer and authority edits cannot self-activate. */\nexport async function proposeRevision(input: ProposeRevisionInput): Promise<ProfileRevision> {\n if (input.author.kind !== 'optimizer' && input.actorRole !== 'owner' && input.actorRole !== 'manager') {\n throw new ProfileAccessError('Only an owner or manager can change a profile')\n }\n if (!input.workspaceId || !input.profileId || !input.author.id || !input.reason.trim() ||\n !/^sha256:[a-f0-9]{64}$/.test(input.planDigest)) {\n throw new TypeError('A profile revision needs workspace, profile, author, reason and plan digest')\n }\n const previous = await input.store.getActiveRevision(input.workspaceId, input.profileId)\n if ((previous?.id ?? null) !== input.expectedRevisionId) {\n throw new ProfileConflictError('The profile changed; read its latest revision before saving')\n }\n const profile = snapshotAgentProfile(input.profile)\n const diff = previous ? diffAgentProfiles(previous.profile, profile) : []\n const authorityDigest = profileAuthorityDigest(profile)\n const authorityChanged = !!previous && previous.authorityDigest !== authorityDigest\n const admission = input.author.kind === 'optimizer'\n ? PROFILE_CHANGE_POLICY.optimizerRevision.admission\n : authorityChanged\n ? PROFILE_CHANGE_POLICY.authorityEdit.admission\n : PROFILE_CHANGE_POLICY.textEdit.admission\n const state: ProfileRevisionState = admission === 'eval-promotion' ? 'candidate'\n : admission === 'editor-consent' ? 'pending-consent' : 'active'\n const revision: ProfileRevision = {\n id: input.id ?? crypto.randomUUID(), workspaceId: input.workspaceId, profileId: input.profileId,\n parentId: previous?.id ?? null, profile, knowledgeText: input.knowledgeText,\n author: input.author, reason: input.reason.trim(), diff, authorityDigest,\n planDigest: input.planDigest, state, createdAt: input.now ?? Date.now(),\n }\n if (!await input.store.appendRevision(revision, input.expectedRevisionId, state === 'active')) {\n throw new ProfileConflictError('The profile changed while saving')\n }\n return revision\n}\n\nexport async function promoteRevision(input: {\n store: ProfileRevisionStore\n workspaceId: string\n profileId: string\n revisionId: string\n actorRole: 'owner' | 'manager' | 'member' | 'viewer'\n /** Verified by the product's consent route; required when authority changes. */\n verifyConsent?: (revision: ProfileRevision) => Promise<boolean>\n}): Promise<ProfileRevision> {\n if (input.actorRole !== 'owner' && input.actorRole !== 'manager') {\n throw new ProfileAccessError('Only an owner or manager can promote a profile')\n }\n const [revision, head] = await Promise.all([\n input.store.getRevision(input.workspaceId, input.profileId, input.revisionId),\n input.store.getActiveRevision(input.workspaceId, input.profileId),\n ])\n if (!revision || revision.parentId !== (head?.id ?? null)) throw new ProfileConflictError('Profile parent changed')\n if (revision.authorityDigest !== head?.authorityDigest &&\n (!input.verifyConsent || !await input.verifyConsent(revision))) {\n throw new ProfileAccessError('Authority changes require owner consent')\n }\n if (!await input.store.promoteRevision(input.workspaceId, input.profileId, revision.id, head?.id ?? null)) {\n throw new ProfileConflictError('The profile changed while promoting')\n }\n return revision\n}\n\nexport function parseProfileSwitch(text: string): { name: string } | { invalid: true } | null {\n const trimmed = text.trim()\n if (!/^switch\\s+to\\b/i.test(trimmed)) return null\n const match = /^switch[ \\t]+to[ \\t]+([^\\r\\n]+)$/i.exec(trimmed)\n return match?.[1]?.trim() ? { name: match[1].trim() } : { invalid: true }\n}\n\nexport function normalizeProfileName(name: string): string {\n return name.trim().replace(/\\s+/g, ' ').toLowerCase()\n}\n\nexport interface SwitchableProfile {\n id: string\n name: string\n status: 'active' | 'draft' | 'paused'\n}\n\nexport interface SwitchProfileInput {\n store: ProfileRevisionStore\n key: ProfileBindingKey\n messageId: string\n content: string\n choice: { name: string } | { profileId: string }\n profiles: readonly SwitchableProfile[]\n /** Product's role/phone allowlist decision for the authenticated member. */\n canSelect: (profileId: string) => Promise<boolean>\n /** Stage a complete managed plan for the same conversation; never mutate live workspace files. */\n prepareAuthority: (revision: ProfileRevision, key: ProfileBindingKey) => Promise<{\n planDigest: string; healthy: true; conflicts: string[]\n }>\n}\n\n/** The picker and deterministic text command converge here. Models cannot call it. */\nexport async function switchProfile(input: SwitchProfileInput): Promise<ProfileSwitchReceipt> {\n const inputHash = sha256Utf8(input.content)\n const previousReceipt = await input.store.getSwitchReceipt(input.key, input.messageId, inputHash)\n if (previousReceipt) return previousReceipt\n const binding = await input.store.getBinding(input.key)\n const choice = input.choice\n const matches = 'name' in choice\n ? input.profiles.filter(profile => normalizeProfileName(profile.name) === normalizeProfileName(choice.name))\n : input.profiles.filter(profile => profile.id === choice.profileId)\n const target = matches.length === 1 ? matches[0] : undefined\n let revision: ProfileRevision | null = null\n if (target?.status === 'active' && await input.canSelect(target.id)) {\n revision = await input.store.getActiveRevision(input.key.workspaceId, target.id)\n if (revision && 'name' in choice &&\n normalizeProfileName(revision.profile.name ?? '') !== normalizeProfileName(choice.name)) {\n revision = null\n }\n }\n let outcome: ProfileSwitchReceipt['outcome'] = 'refused'\n let message = matches.length > 1 ? 'That profile name is ambiguous.'\n : target?.status !== 'active' && target ? `${target.name} is not active.`\n : 'That profile is not available for this member.'\n let planDigest: string | null = null\n let conflicts: string[] = []\n if (revision && target) {\n const admission = binding?.authorityDigest === revision.authorityDigest\n ? PROFILE_CHANGE_POLICY.sameAuthoritySwitch.admission\n : PROFILE_CHANGE_POLICY.differentAuthoritySwitch.admission\n if (admission === 'prepare-then-flip' || binding?.planDigest !== revision.planDigest) {\n try {\n const prepared = await input.prepareAuthority(revision, input.key)\n if (!prepared.healthy || prepared.planDigest !== revision.planDigest) {\n throw new ProfileConflictError('The managed plan was not prepared for this revision')\n }\n planDigest = prepared.planDigest\n conflicts = prepared.conflicts\n } catch {\n revision = null\n message = `Could not prepare ${target.name}; your current agent is unchanged.`\n }\n } else {\n planDigest = binding.planDigest\n }\n if (revision && planDigest) {\n outcome = 'switched'\n message = `Now talking to ${target.name}`\n }\n }\n return input.store.recordSwitch({ key: input.key, messageId: input.messageId, inputHash,\n profileId: revision?.profileId ?? null, revisionId: revision?.id ?? null,\n pinnedRevisionId: null, authorityDigest: revision?.authorityDigest ?? null,\n planDigest, outcome, message, conflicts }, binding?.version ?? 0)\n}\n\n/** Call before dispatching a chat message; a recognized command is never sent to the model. */\nexport async function handleProfileSwitchText(\n input: Omit<SwitchProfileInput, 'choice'>,\n): Promise<ProfileSwitchReceipt | null> {\n const parsed = parseProfileSwitch(input.content)\n if (!parsed) return null\n if ('name' in parsed) return switchProfile({ ...input, choice: parsed })\n const inputHash = sha256Utf8(input.content)\n const previous = await input.store.getSwitchReceipt(input.key, input.messageId, inputHash)\n if (previous) return previous\n const binding = await input.store.getBinding(input.key)\n return input.store.recordSwitch({ key: input.key, messageId: input.messageId, inputHash,\n profileId: null, revisionId: null, pinnedRevisionId: null, outcome: 'refused',\n authorityDigest: null, planDigest: null, conflicts: [],\n message: 'Send only “Switch to [agent name]” to change agents.' },\n binding?.version ?? 0)\n}\n\n/** One-step rollback moves this member/channel to its previous immutable revision. */\nexport async function rollbackProfileBinding(input: {\n store: ProfileRevisionStore\n key: ProfileBindingKey\n messageId: string\n actorRole: 'owner' | 'manager' | 'member' | 'viewer'\n canSelect: (profileId: string) => Promise<boolean>\n prepareAuthority: SwitchProfileInput['prepareAuthority']\n}): Promise<ProfileSwitchReceipt> {\n if (input.actorRole !== 'owner' && input.actorRole !== 'manager') {\n throw new ProfileAccessError('Only an owner or manager can roll back a profile')\n }\n const inputHash = sha256Utf8(`rollback:${input.messageId}`)\n const prior = await input.store.getSwitchReceipt(input.key, input.messageId, inputHash)\n if (prior) return prior\n const binding = await input.store.getBinding(input.key)\n if (!binding || !await input.canSelect(binding.profileId)) throw new ProfileAccessError('Profile is unavailable')\n const current = binding.pinnedRevisionId\n ? await input.store.getRevision(input.key.workspaceId, binding.profileId, binding.pinnedRevisionId)\n : await input.store.getActiveRevision(input.key.workspaceId, binding.profileId)\n if (!current?.parentId) throw new ProfileConflictError('The bound profile has no previous revision')\n const parent = await input.store.getRevision(input.key.workspaceId, binding.profileId, current.parentId)\n if (!parent) throw new ProfileConflictError('The previous revision is unavailable')\n let planDigest = binding.planDigest\n let conflicts: string[] = []\n if (binding.authorityDigest !== parent.authorityDigest || binding.planDigest !== parent.planDigest) {\n try {\n const prepared = await input.prepareAuthority(parent, input.key)\n if (!prepared.healthy || prepared.planDigest !== parent.planDigest) {\n throw new ProfileConflictError('The prior managed plan was not prepared')\n }\n planDigest = prepared.planDigest\n conflicts = prepared.conflicts\n } catch {\n return input.store.recordSwitch({ key: input.key, messageId: input.messageId, inputHash,\n profileId: null, revisionId: null, pinnedRevisionId: null, outcome: 'refused',\n authorityDigest: null, planDigest: null, conflicts: [],\n message: 'Could not prepare the previous profile; your current agent is unchanged.' },\n binding.version)\n }\n }\n return input.store.recordSwitch({ key: input.key, messageId: input.messageId, inputHash,\n profileId: parent.profileId, revisionId: parent.id, pinnedRevisionId: parent.id,\n authorityDigest: parent.authorityDigest, planDigest, outcome: 'switched', conflicts,\n message: `Now talking to ${parent.profile.name ?? 'this profile'}` }, binding.version)\n}\n\nexport async function admitProfileTurn(input: {\n store: ProfileRevisionStore\n key: ProfileBindingKey\n messageId: string\n content: string\n /** Effective ADC plan digest selected by the executor for this revision and turn. */\n observedManagedPlanDigest: string\n /** Required if trusted per-turn attachments change the public profile plan. */\n verifyEffectivePlan?: (revision: ProfileRevision, effectivePlanDigest: string,\n key: ProfileBindingKey) => Promise<boolean>\n}): Promise<ProfileTurnPin> {\n const inputHash = sha256Utf8(input.content)\n const prior = await input.store.getTurnPin(input.key, input.messageId, inputHash)\n if (prior) return prior\n const binding = await input.store.getBinding(input.key)\n if (!binding) throw new ProfileAccessError('Choose a profile before sending a message')\n const revision = binding.pinnedRevisionId\n ? await input.store.getRevision(input.key.workspaceId, binding.profileId, binding.pinnedRevisionId)\n : await input.store.getActiveRevision(input.key.workspaceId, binding.profileId)\n if (!revision) throw new ProfileConflictError('The bound profile revision is unavailable')\n if (revision.authorityDigest !== binding.authorityDigest ||\n !/^sha256:[a-f0-9]{64}$/.test(input.observedManagedPlanDigest)) {\n throw new ProfileAccessError('The selected managed plan is not active for this turn')\n }\n const planMatches = revision.planDigest === input.observedManagedPlanDigest ||\n (input.verifyEffectivePlan !== undefined &&\n await input.verifyEffectivePlan(revision, input.observedManagedPlanDigest, input.key))\n if (!planMatches) {\n throw new ProfileAccessError('The selected managed plan is not active for this turn')\n }\n return input.store.pinTurn({ ...input.key, messageId: input.messageId, inputHash,\n profileId: revision.profileId, revisionId: revision.id,\n authorityDigest: revision.authorityDigest, planDigest: input.observedManagedPlanDigest }, binding.version)\n}\n\nconst textChangeSchema = z.object({\n name: z.string().trim().min(1).max(160).optional(),\n description: z.string().max(2000).nullable().optional(),\n systemPrompt: z.string().max(32000).nullable().optional(),\n instructions: z.array(z.string().max(32000)).max(40).optional(),\n knowledgeText: z.string().max(32000).optional(),\n}).strict().refine(changes => Object.keys(changes).length > 0)\nconst updateToolSchema = z.object({ expectedRevisionId: z.string().min(1), changes: textChangeSchema }).strict()\n\nexport function profileTextChange(revision: ProfileRevision, changes: z.infer<typeof textChangeSchema>): {\n profile: AgentProfile; knowledgeText: string\n} {\n const profile = structuredClone(revision.profile)\n if (changes.name !== undefined) profile.name = changes.name\n if (changes.description !== undefined) profile.description = changes.description ?? undefined\n if (changes.systemPrompt !== undefined || changes.instructions !== undefined) {\n profile.prompt = { ...profile.prompt,\n ...(changes.systemPrompt !== undefined ? { systemPrompt: changes.systemPrompt ?? undefined } : {}),\n ...(changes.instructions !== undefined ? { instructions: changes.instructions } : {}) }\n }\n return { profile: snapshotAgentProfile(profile), knowledgeText: changes.knowledgeText ?? revision.knowledgeText }\n}\n\nexport interface ProfileToolContext {\n /** Resolve the running turn from the trusted server session; never from tool arguments. */\n activeTurn(): Promise<{ workspaceId: string; profileId: string; revisionId: string;\n memberId: string; role: 'owner' | 'manager' | 'member' | 'viewer' }>\n /** Product computes the plan with ADC, returning `hashWorkspacePlan(plan)`. */\n planDigest(profile: AgentProfile, knowledgeText: string): Promise<string>\n store: ProfileRevisionStore\n}\n\n/** Shared self-edit tools; only the authenticated active turn can name the profile. */\nexport function profileTools(context: ProfileToolContext): McpToolDefinition<Record<string, never>>[] {\n return [{\n name: 'profile.read',\n description: 'Read the active agent profile text and revision. Saved text applies on the next message.',\n inputSchema: z.toJSONSchema(z.object({}).strict(), { io: 'input' }) as Record<string, unknown>,\n async run(args) {\n z.object({}).strict().parse(args)\n const turn = await context.activeTurn()\n if (turn.role !== 'owner' && turn.role !== 'manager') throw new ProfileAccessError('Profile management is required')\n const revision = await context.store.getActiveRevision(turn.workspaceId, turn.profileId)\n if (!revision) throw new ProfileConflictError('Profile revision is unavailable')\n return { profileId: turn.profileId, revisionId: revision.id, currentTurnRevisionId: turn.revisionId,\n name: revision.profile.name, description: revision.profile.description ?? null,\n systemPrompt: revision.profile.prompt?.systemPrompt ?? null,\n instructions: revision.profile.prompt?.instructions ?? [], knowledgeText: revision.knowledgeText }\n },\n }, {\n name: 'profile.update',\n description: 'Save a requested owner or manager text change with the revision from profile.read. Applies on the next message.',\n inputSchema: z.toJSONSchema(updateToolSchema, { io: 'input' }) as Record<string, unknown>,\n async run(args) {\n const { expectedRevisionId, changes } = updateToolSchema.parse(args)\n const turn = await context.activeTurn()\n if (turn.role !== 'owner' && turn.role !== 'manager') throw new ProfileAccessError('Profile management is required')\n const current = await context.store.getActiveRevision(turn.workspaceId, turn.profileId)\n if (!current || current.id !== expectedRevisionId) throw new ProfileConflictError('The profile changed; read it again')\n const next = profileTextChange(current, changes)\n const revision = await proposeRevision({ store: context.store, workspaceId: turn.workspaceId,\n profileId: turn.profileId, expectedRevisionId, ...next,\n planDigest: await context.planDigest(next.profile, next.knowledgeText),\n author: { kind: 'agent', id: turn.memberId }, actorRole: turn.role,\n reason: 'Owner or manager requested a text change during chat' })\n return { profileId: turn.profileId, revisionId: revision.id, state: revision.state,\n canonicalSaved: revision.state === 'active', appliesTo: 'next_message', currentTurn: 'unchanged' }\n },\n }]\n}\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,SAAS;AAOX,IAAM,wBAAwB;AAAA,EACnC,UAAU,EAAE,WAAW,aAAa,cAAc,QAAQ,aAAa,MAAM;AAAA,EAC7E,qBAAqB,EAAE,WAAW,aAAa,cAAc,QAAQ,aAAa,MAAM;AAAA,EACxF,0BAA0B,EAAE,WAAW,qBAAqB,cAAc,QAAQ,aAAa,MAAM;AAAA,EACrG,eAAe,EAAE,WAAW,kBAAkB,cAAc,QAAQ,aAAa,MAAM;AAAA,EACvF,mBAAmB,EAAE,WAAW,kBAAkB,cAAc,QAAQ,aAAa,MAAM;AAAA,EAC3F,mBAAmB,EAAE,WAAW,eAAe,cAAc,QAAQ,aAAa,KAAK;AACzF;AAmGO,IAAM,uBAAN,cAAmC,MAAM;AAAA,EAC9C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,qBAAN,cAAiC,MAAM;AAAA,EAC5C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAGO,SAAS,iBAAiB,SAAqC;AACpE,QAAM,EAAE,MAAM,OAAO,aAAa,cAAc,QAAQ,GAAG,UAAU,IAAI;AACzE,QAAM,EAAE,cAAc,eAAe,cAAc,eAAe,GAAG,gBAAgB,IAAI,UAAU,CAAC;AACpG,SAAO,EAAE,GAAG,WAAW,GAAI,OAAO,KAAK,eAAe,EAAE,SAAS,EAAE,QAAQ,gBAAgB,IAAI,CAAC,EAAG;AACrG;AAEO,SAAS,uBAAuB,SAA+B;AACpE,SAAO,4BAA4B,iBAAiB,qBAAqB,OAAO,CAAC,CAAC;AACpF;AAEO,SAAS,0B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nE,YAAM,OAAO,MAAM,QAAQ,WAAW;AACtC,UAAI,KAAK,SAAS,WAAW,KAAK,SAAS,UAAW,OAAM,IAAI,mBAAmB,gCAAgC;AACnH,YAAM,UAAU,MAAM,QAAQ,MAAM,kBAAkB,KAAK,aAAa,KAAK,SAAS;AACtF,UAAI,CAAC,WAAW,QAAQ,OAAO,mBAAoB,OAAM,IAAI,qBAAqB,oCAAoC;AACtH,YAAM,OAAO,kBAAkB,SAAS,OAAO;AAC/C,YAAM,WAAW,MAAM,gBAAgB;AAAA,QAAE,OAAO,QAAQ;AAAA,QAAO,aAAa,KAAK;AAAA,QAC/E,WAAW,KAAK;AAAA,QAAW;AAAA,QAAoB,GAAG;AAAA,QAClD,YAAY,MAAM,QAAQ,WAAW,KAAK,SAAS,KAAK,aAAa;AAAA,QACrE,QAAQ,EAAE,MAAM,SAAS,IAAI,KAAK,SAAS;AAAA,QAAG,WAAW,KAAK;AAAA,QAC9D,QAAQ;AAAA,MAAuD,CAAC;AAClE,aAAO;AAAA,QAAE,WAAW,KAAK;AAAA,QAAW,YAAY,SAAS;AAAA,QAAI,OAAO,SAAS;AAAA,QAC3E,gBAAgB,SAAS,UAAU;AAAA,QAAU,WAAW;AAAA,QAAgB,aAAa;AAAA,MAAY;AAAA,IACrG;AAAA,EACF,CAAC;AACH;","names":["event"]}
|
|
@@ -7,18 +7,18 @@ import {
|
|
|
7
7
|
findCustomTool,
|
|
8
8
|
isAppToolName
|
|
9
9
|
} from "./chunk-J5EBGZTD.js";
|
|
10
|
-
import {
|
|
11
|
-
base64UrlDecodeText,
|
|
12
|
-
base64UrlEncodeText,
|
|
13
|
-
constantTimeEqual,
|
|
14
|
-
hmacSha256Base64Url
|
|
15
|
-
} from "./chunk-S5SRJJQG.js";
|
|
16
10
|
import {
|
|
17
11
|
assertRenderUiSchema
|
|
18
12
|
} from "./chunk-2BD7VZKN.js";
|
|
19
13
|
import {
|
|
20
14
|
ToolInputError
|
|
21
15
|
} from "./chunk-M63EUBSH.js";
|
|
16
|
+
import {
|
|
17
|
+
base64UrlDecodeText,
|
|
18
|
+
base64UrlEncodeText,
|
|
19
|
+
constantTimeEqual,
|
|
20
|
+
hmacSha256Base64Url
|
|
21
|
+
} from "./chunk-S5SRJJQG.js";
|
|
22
22
|
|
|
23
23
|
// src/tools/capability.ts
|
|
24
24
|
async function createCapabilityToken(userId, opts) {
|
|
@@ -270,4 +270,4 @@ export {
|
|
|
270
270
|
createAppToolRuntimeExecutor,
|
|
271
271
|
handleAppToolRequest
|
|
272
272
|
};
|
|
273
|
-
//# sourceMappingURL=chunk-
|
|
273
|
+
//# sourceMappingURL=chunk-IVE3T73T.js.map
|
|
@@ -4,17 +4,6 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
parseJsonObjectBody
|
|
6
6
|
} from "./chunk-3NCPXNBZ.js";
|
|
7
|
-
import {
|
|
8
|
-
mentionInputToPart,
|
|
9
|
-
toChatMessageParts
|
|
10
|
-
} from "./chunk-HTAFI247.js";
|
|
11
|
-
import {
|
|
12
|
-
ChatTurnInputError,
|
|
13
|
-
assertPromptPartsWithinCap,
|
|
14
|
-
chatTurnRequestInit,
|
|
15
|
-
parseChatTurnParts,
|
|
16
|
-
parseFileMentions
|
|
17
|
-
} from "./chunk-GYDFGEJ2.js";
|
|
18
7
|
import {
|
|
19
8
|
normalizeClientTurnId,
|
|
20
9
|
resolveChatTurn
|
|
@@ -25,6 +14,17 @@ import {
|
|
|
25
14
|
replayTurnEvents,
|
|
26
15
|
stampReplaySeq
|
|
27
16
|
} from "./chunk-OEHEHPPA.js";
|
|
17
|
+
import {
|
|
18
|
+
mentionInputToPart,
|
|
19
|
+
toChatMessageParts
|
|
20
|
+
} from "./chunk-WTGSLW5X.js";
|
|
21
|
+
import {
|
|
22
|
+
ChatTurnInputError,
|
|
23
|
+
assertPromptPartsWithinCap,
|
|
24
|
+
chatTurnRequestInit,
|
|
25
|
+
parseChatTurnParts,
|
|
26
|
+
parseFileMentions
|
|
27
|
+
} from "./chunk-GYDFGEJ2.js";
|
|
28
28
|
|
|
29
29
|
// src/chat-routes/draft-persistence.ts
|
|
30
30
|
var CONTENT_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
@@ -1082,4 +1082,4 @@ export {
|
|
|
1082
1082
|
createChatTurnRoutes,
|
|
1083
1083
|
streamChatRouteAsSandboxEvents
|
|
1084
1084
|
};
|
|
1085
|
-
//# sourceMappingURL=chunk-
|
|
1085
|
+
//# sourceMappingURL=chunk-NWR5CERQ.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
persistedPartToWorkProduct
|
|
3
|
-
} from "./chunk-ZVEEWGDK.js";
|
|
4
1
|
import {
|
|
5
2
|
mentionKindForPath
|
|
6
3
|
} from "./chunk-GYDFGEJ2.js";
|
|
4
|
+
import {
|
|
5
|
+
persistedPartToWorkProduct
|
|
6
|
+
} from "./chunk-ZVEEWGDK.js";
|
|
7
7
|
import {
|
|
8
8
|
persistedPartToInteraction
|
|
9
9
|
} from "./chunk-FCON65I2.js";
|
|
@@ -135,4 +135,4 @@ export {
|
|
|
135
135
|
buildAttachmentPromptBlock,
|
|
136
136
|
historyContentWithAttachments
|
|
137
137
|
};
|
|
138
|
-
//# sourceMappingURL=chunk-
|
|
138
|
+
//# sourceMappingURL=chunk-WTGSLW5X.js.map
|
|
@@ -42,10 +42,6 @@ import {
|
|
|
42
42
|
selectTickStep
|
|
43
43
|
} from "../chunk-DKHM4B4A.js";
|
|
44
44
|
import "../chunk-GDB3YCNS.js";
|
|
45
|
-
import {
|
|
46
|
-
DesignCanvasChromeLazy,
|
|
47
|
-
DesignCanvasLazy
|
|
48
|
-
} from "../chunk-GPRTXOBI.js";
|
|
49
45
|
import "../chunk-ZN5J47UX.js";
|
|
50
46
|
import {
|
|
51
47
|
DEFAULT_INSERT_TEMPLATES,
|
|
@@ -93,6 +89,10 @@ import {
|
|
|
93
89
|
bleedAwareExportBounds,
|
|
94
90
|
scaleForPreset
|
|
95
91
|
} from "../chunk-OHWQUKBP.js";
|
|
92
|
+
import {
|
|
93
|
+
DesignCanvasChromeLazy,
|
|
94
|
+
DesignCanvasLazy
|
|
95
|
+
} from "../chunk-GPRTXOBI.js";
|
|
96
96
|
import "../chunk-YNSPVKMS.js";
|
|
97
97
|
import "../chunk-3NCPXNBZ.js";
|
|
98
98
|
import "../chunk-TXD5HXLE.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createFieldCrypto
|
|
3
|
-
} from "../chunk-7KKOFMLD.js";
|
|
4
1
|
import {
|
|
5
2
|
createWorkspaceKeyManager
|
|
6
3
|
} from "../chunk-4ZJYNI53.js";
|
|
4
|
+
import {
|
|
5
|
+
createFieldCrypto
|
|
6
|
+
} from "../chunk-7KKOFMLD.js";
|
|
7
7
|
import {
|
|
8
8
|
assertRenderUiSchema
|
|
9
9
|
} from "../chunk-2BD7VZKN.js";
|