@tangle-network/agent-app 0.57.0 → 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.
Files changed (35) hide show
  1. package/dist/agent-profiles/d1.d.ts +24 -0
  2. package/dist/agent-profiles/d1.js +428 -0
  3. package/dist/agent-profiles/d1.js.map +1 -0
  4. package/dist/agent-profiles/drizzle.d.ts +1191 -0
  5. package/dist/agent-profiles/drizzle.js +85 -0
  6. package/dist/agent-profiles/drizzle.js.map +1 -0
  7. package/dist/agent-profiles/index.d.ts +270 -0
  8. package/dist/agent-profiles/index.js +43 -0
  9. package/dist/agent-profiles/index.js.map +1 -0
  10. package/dist/agent-profiles/reaper.d.ts +31 -0
  11. package/dist/agent-profiles/reaper.js +29 -0
  12. package/dist/agent-profiles/reaper.js.map +1 -0
  13. package/dist/assistant/index.js +5 -5
  14. package/dist/chat-routes/index.js +11 -11
  15. package/dist/chat-store/index.js +2 -2
  16. package/dist/{chunk-JAK2WU5U.js → chunk-APZ4W7HJ.js} +2 -2
  17. package/dist/chunk-D2NZQCOB.js +421 -0
  18. package/dist/chunk-D2NZQCOB.js.map +1 -0
  19. package/dist/{chunk-7YLSF33A.js → chunk-IVE3T73T.js} +7 -7
  20. package/dist/{chunk-RNHXRPHO.js → chunk-NWR5CERQ.js} +12 -12
  21. package/dist/{chunk-HTAFI247.js → chunk-WTGSLW5X.js} +4 -4
  22. package/dist/design-canvas-react/index.js +4 -4
  23. package/dist/preset-cloudflare/index.js +3 -3
  24. package/dist/profile/index.js +9 -9
  25. package/dist/public-consultation/index.js +6 -6
  26. package/dist/sandbox/index.js +2 -2
  27. package/dist/skills-placement/index.js +3 -3
  28. package/dist/stream/index.js +16 -16
  29. package/dist/tools/index.js +2 -2
  30. package/dist/web-react/index.js +10 -10
  31. package/package.json +21 -1
  32. /package/dist/{chunk-JAK2WU5U.js.map → chunk-APZ4W7HJ.js.map} +0 -0
  33. /package/dist/{chunk-7YLSF33A.js.map → chunk-IVE3T73T.js.map} +0 -0
  34. /package/dist/{chunk-RNHXRPHO.js.map → chunk-NWR5CERQ.js.map} +0 -0
  35. /package/dist/{chunk-HTAFI247.js.map → chunk-WTGSLW5X.js.map} +0 -0
@@ -0,0 +1,85 @@
1
+ // src/agent-profiles/drizzle.ts
2
+ import { index, integer, primaryKey, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
3
+ function createAgentProfileTables() {
4
+ const revisions = sqliteTable("agent_profile_revision", {
5
+ id: text("revision_id").primaryKey(),
6
+ workspaceId: text("workspace_id").notNull(),
7
+ profileId: text("profile_id").notNull(),
8
+ parentId: text("parent_id"),
9
+ profileJson: text("profile_json").notNull(),
10
+ knowledgeText: text("knowledge_text").notNull(),
11
+ authorKind: text("author_kind", { enum: ["person", "agent", "optimizer"] }).notNull(),
12
+ authorId: text("author_id").notNull(),
13
+ reason: text("reason").notNull(),
14
+ diffJson: text("diff_json").notNull(),
15
+ authorityDigest: text("authority_digest").notNull(),
16
+ planDigest: text("plan_digest").notNull(),
17
+ state: text("state", { enum: ["active", "candidate", "pending-consent"] }).notNull(),
18
+ createdAt: integer("created_at").notNull()
19
+ }, (table) => [index("agent_profile_revision_history").on(table.workspaceId, table.profileId, table.createdAt)]);
20
+ const activations = sqliteTable("agent_profile_activation_event", {
21
+ eventId: text("event_id").primaryKey(),
22
+ workspaceId: text("workspace_id").notNull(),
23
+ profileId: text("profile_id").notNull(),
24
+ version: integer("version").notNull(),
25
+ revisionId: text("revision_id").notNull().references(() => revisions.id),
26
+ createdAt: integer("created_at").notNull()
27
+ }, (table) => [uniqueIndex("agent_profile_activation_order").on(table.workspaceId, table.profileId, table.version)]);
28
+ const bindingEvents = sqliteTable("agent_profile_binding_event", {
29
+ eventId: text("event_id").primaryKey(),
30
+ workspaceId: text("workspace_id").notNull(),
31
+ memberId: text("member_id").notNull(),
32
+ channel: text("channel").notNull(),
33
+ profileId: text("profile_id").notNull(),
34
+ pinnedRevisionId: text("pinned_revision_id"),
35
+ authorityDigest: text("authority_digest").notNull(),
36
+ planDigest: text("plan_digest").notNull(),
37
+ version: integer("version").notNull(),
38
+ sourceMessageId: text("source_message_id").notNull(),
39
+ createdAt: integer("created_at").notNull()
40
+ }, (table) => [
41
+ uniqueIndex("agent_profile_binding_order").on(table.workspaceId, table.memberId, table.channel, table.version),
42
+ uniqueIndex("agent_profile_binding_source").on(table.workspaceId, table.memberId, table.channel, table.sourceMessageId)
43
+ ]);
44
+ const switchReceipts = sqliteTable("agent_profile_switch_receipt", {
45
+ workspaceId: text("workspace_id").notNull(),
46
+ memberId: text("member_id").notNull(),
47
+ channel: text("channel").notNull(),
48
+ messageId: text("message_id").notNull(),
49
+ inputHash: text("input_hash").notNull(),
50
+ profileId: text("profile_id"),
51
+ revisionId: text("revision_id"),
52
+ pinnedRevisionId: text("pinned_revision_id"),
53
+ authorityDigest: text("authority_digest"),
54
+ planDigest: text("plan_digest"),
55
+ outcome: text("outcome", { enum: ["switched", "refused"] }).notNull(),
56
+ message: text("message").notNull(),
57
+ conflictsJson: text("conflicts_json").notNull()
58
+ }, (table) => [primaryKey({ columns: [table.workspaceId, table.memberId, table.channel, table.messageId] })]);
59
+ const turnPins = sqliteTable("agent_profile_turn_pin", {
60
+ workspaceId: text("workspace_id").notNull(),
61
+ memberId: text("member_id").notNull(),
62
+ channel: text("channel").notNull(),
63
+ messageId: text("message_id").notNull(),
64
+ inputHash: text("input_hash").notNull(),
65
+ profileId: text("profile_id").notNull(),
66
+ revisionId: text("revision_id").notNull(),
67
+ authorityDigest: text("authority_digest").notNull(),
68
+ planDigest: text("plan_digest").notNull()
69
+ }, (table) => [primaryKey({ columns: [table.workspaceId, table.memberId, table.channel, table.messageId] })]);
70
+ const knowledgeEvents = sqliteTable("agent_profile_knowledge_event", {
71
+ eventId: text("event_id").primaryKey(),
72
+ workspaceId: text("workspace_id").notNull(),
73
+ profileId: text("profile_id").notNull(),
74
+ documentId: text("document_id").notNull(),
75
+ kind: text("kind", { enum: ["add", "remove"] }).notNull(),
76
+ content: text("content"),
77
+ observedAddIdsJson: text("observed_add_ids_json").notNull(),
78
+ createdAt: integer("created_at").notNull()
79
+ }, (table) => [index("agent_profile_knowledge_history").on(table.workspaceId, table.profileId, table.documentId, table.createdAt)]);
80
+ return { revisions, activations, bindingEvents, switchReceipts, turnPins, knowledgeEvents };
81
+ }
82
+ export {
83
+ createAgentProfileTables
84
+ };
85
+ //# sourceMappingURL=drizzle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/agent-profiles/drizzle.ts"],"sourcesContent":["/** Drizzle table definitions matching `AGENT_PROFILE_D1_SCHEMA_SQL`. */\nimport { index, integer, primaryKey, sqliteTable, text, uniqueIndex } from 'drizzle-orm/sqlite-core'\n\nexport function createAgentProfileTables() {\n const revisions = sqliteTable('agent_profile_revision', {\n id: text('revision_id').primaryKey(),\n workspaceId: text('workspace_id').notNull(),\n profileId: text('profile_id').notNull(),\n parentId: text('parent_id'),\n profileJson: text('profile_json').notNull(),\n knowledgeText: text('knowledge_text').notNull(),\n authorKind: text('author_kind', { enum: ['person', 'agent', 'optimizer'] }).notNull(),\n authorId: text('author_id').notNull(),\n reason: text('reason').notNull(),\n diffJson: text('diff_json').notNull(),\n authorityDigest: text('authority_digest').notNull(),\n planDigest: text('plan_digest').notNull(),\n state: text('state', { enum: ['active', 'candidate', 'pending-consent'] }).notNull(),\n createdAt: integer('created_at').notNull(),\n }, table => [index('agent_profile_revision_history')\n .on(table.workspaceId, table.profileId, table.createdAt)])\n\n const activations = sqliteTable('agent_profile_activation_event', {\n eventId: text('event_id').primaryKey(),\n workspaceId: text('workspace_id').notNull(),\n profileId: text('profile_id').notNull(),\n version: integer('version').notNull(),\n revisionId: text('revision_id').notNull().references(() => revisions.id),\n createdAt: integer('created_at').notNull(),\n }, table => [uniqueIndex('agent_profile_activation_order').on(table.workspaceId, table.profileId, table.version)])\n\n const bindingEvents = sqliteTable('agent_profile_binding_event', {\n eventId: text('event_id').primaryKey(),\n workspaceId: text('workspace_id').notNull(),\n memberId: text('member_id').notNull(),\n channel: text('channel').notNull(),\n profileId: text('profile_id').notNull(),\n pinnedRevisionId: text('pinned_revision_id'),\n authorityDigest: text('authority_digest').notNull(),\n planDigest: text('plan_digest').notNull(),\n version: integer('version').notNull(),\n sourceMessageId: text('source_message_id').notNull(),\n createdAt: integer('created_at').notNull(),\n }, table => [\n uniqueIndex('agent_profile_binding_order').on(table.workspaceId, table.memberId, table.channel, table.version),\n uniqueIndex('agent_profile_binding_source').on(table.workspaceId, table.memberId, table.channel, table.sourceMessageId),\n ])\n\n const switchReceipts = sqliteTable('agent_profile_switch_receipt', {\n workspaceId: text('workspace_id').notNull(),\n memberId: text('member_id').notNull(),\n channel: text('channel').notNull(),\n messageId: text('message_id').notNull(),\n inputHash: text('input_hash').notNull(),\n profileId: text('profile_id'),\n revisionId: text('revision_id'),\n pinnedRevisionId: text('pinned_revision_id'),\n authorityDigest: text('authority_digest'),\n planDigest: text('plan_digest'),\n outcome: text('outcome', { enum: ['switched', 'refused'] }).notNull(),\n message: text('message').notNull(),\n conflictsJson: text('conflicts_json').notNull(),\n }, table => [primaryKey({ columns: [table.workspaceId, table.memberId, table.channel, table.messageId] })])\n\n const turnPins = sqliteTable('agent_profile_turn_pin', {\n workspaceId: text('workspace_id').notNull(),\n memberId: text('member_id').notNull(),\n channel: text('channel').notNull(),\n messageId: text('message_id').notNull(),\n inputHash: text('input_hash').notNull(),\n profileId: text('profile_id').notNull(),\n revisionId: text('revision_id').notNull(),\n authorityDigest: text('authority_digest').notNull(),\n planDigest: text('plan_digest').notNull(),\n }, table => [primaryKey({ columns: [table.workspaceId, table.memberId, table.channel, table.messageId] })])\n\n const knowledgeEvents = sqliteTable('agent_profile_knowledge_event', {\n eventId: text('event_id').primaryKey(),\n workspaceId: text('workspace_id').notNull(),\n profileId: text('profile_id').notNull(),\n documentId: text('document_id').notNull(),\n kind: text('kind', { enum: ['add', 'remove'] }).notNull(),\n content: text('content'),\n observedAddIdsJson: text('observed_add_ids_json').notNull(),\n createdAt: integer('created_at').notNull(),\n }, table => [index('agent_profile_knowledge_history')\n .on(table.workspaceId, table.profileId, table.documentId, table.createdAt)])\n\n return { revisions, activations, bindingEvents, switchReceipts, turnPins, knowledgeEvents }\n}\n"],"mappings":";AACA,SAAS,OAAO,SAAS,YAAY,aAAa,MAAM,mBAAmB;AAEpE,SAAS,2BAA2B;AACzC,QAAM,YAAY,YAAY,0BAA0B;AAAA,IACtD,IAAI,KAAK,aAAa,EAAE,WAAW;AAAA,IACnC,aAAa,KAAK,cAAc,EAAE,QAAQ;AAAA,IAC1C,WAAW,KAAK,YAAY,EAAE,QAAQ;AAAA,IACtC,UAAU,KAAK,WAAW;AAAA,IAC1B,aAAa,KAAK,cAAc,EAAE,QAAQ;AAAA,IAC1C,eAAe,KAAK,gBAAgB,EAAE,QAAQ;AAAA,IAC9C,YAAY,KAAK,eAAe,EAAE,MAAM,CAAC,UAAU,SAAS,WAAW,EAAE,CAAC,EAAE,QAAQ;AAAA,IACpF,UAAU,KAAK,WAAW,EAAE,QAAQ;AAAA,IACpC,QAAQ,KAAK,QAAQ,EAAE,QAAQ;AAAA,IAC/B,UAAU,KAAK,WAAW,EAAE,QAAQ;AAAA,IACpC,iBAAiB,KAAK,kBAAkB,EAAE,QAAQ;AAAA,IAClD,YAAY,KAAK,aAAa,EAAE,QAAQ;AAAA,IACxC,OAAO,KAAK,SAAS,EAAE,MAAM,CAAC,UAAU,aAAa,iBAAiB,EAAE,CAAC,EAAE,QAAQ;AAAA,IACnF,WAAW,QAAQ,YAAY,EAAE,QAAQ;AAAA,EAC3C,GAAG,WAAS,CAAC,MAAM,gCAAgC,EAChD,GAAG,MAAM,aAAa,MAAM,WAAW,MAAM,SAAS,CAAC,CAAC;AAE3D,QAAM,cAAc,YAAY,kCAAkC;AAAA,IAChE,SAAS,KAAK,UAAU,EAAE,WAAW;AAAA,IACrC,aAAa,KAAK,cAAc,EAAE,QAAQ;AAAA,IAC1C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AAE,QAAQ;AAAA,IACtC,YAAY,KAAK,aAAa,EAAE,QAAQ;AAAA,IACxC,MAAM,KAAK,QAAQ,EAAE,MAAM,CAAC,OAAO,QAAQ,EAAE,CAAC,EAAE,QAAQ;AAAA,IACxD,SAAS,KAAK,SAAS;AAAA,IACvB,oBAAoB,KAAK,uBAAuB,EAAE,QAAQ;AAAA,IAC1D,WAAW,QAAQ,YAAY,EAAE,QAAQ;AAAA,EAC3C,GAAG,WAAS,CAAC,MAAM,iCAAiC,EACjD,GAAG,MAAM,aAAa,MAAM,WAAW,MAAM,YAAY,MAAM,SAAS,CAAC,CAAC;AAE7E,SAAO,EAAE,WAAW,aAAa,eAAe,gBAAgB,UAAU,gBAAgB;AAC5F;","names":[]}
@@ -0,0 +1,270 @@
1
+ /** Chat-owned profile revisions and member/channel bindings. Execution stays in the substrate. */
2
+ import { type AgentProfile, type AgentProfileDiff } from '@tangle-network/agent-interface';
3
+ import { z } from 'zod';
4
+ import type { McpToolDefinition } from '../tools';
5
+ export type ProfileAuthorKind = 'person' | 'agent' | 'optimizer';
6
+ export type ProfileRevisionState = 'active' | 'candidate' | 'pending-consent';
7
+ /** The decision table used by every write path; products may narrow access, never widen it. */
8
+ export declare const PROFILE_CHANGE_POLICY: {
9
+ readonly textEdit: {
10
+ readonly admission: 'automatic';
11
+ readonly conversation: 'same';
12
+ readonly destructive: false;
13
+ };
14
+ readonly sameAuthoritySwitch: {
15
+ readonly admission: 'automatic';
16
+ readonly conversation: 'same';
17
+ readonly destructive: false;
18
+ };
19
+ readonly differentAuthoritySwitch: {
20
+ readonly admission: 'prepare-then-flip';
21
+ readonly conversation: 'same';
22
+ readonly destructive: false;
23
+ };
24
+ readonly authorityEdit: {
25
+ readonly admission: 'editor-consent';
26
+ readonly conversation: 'same';
27
+ readonly destructive: false;
28
+ };
29
+ readonly optimizerRevision: {
30
+ readonly admission: 'eval-promotion';
31
+ readonly conversation: 'same';
32
+ readonly destructive: false;
33
+ };
34
+ readonly destructiveAction: {
35
+ readonly admission: 'reaper-only';
36
+ readonly conversation: 'none';
37
+ readonly destructive: true;
38
+ };
39
+ };
40
+ export interface ProfileRevision {
41
+ id: string;
42
+ workspaceId: string;
43
+ profileId: string;
44
+ parentId: string | null;
45
+ profile: AgentProfile;
46
+ knowledgeText: string;
47
+ author: {
48
+ kind: ProfileAuthorKind;
49
+ id: string;
50
+ };
51
+ reason: string;
52
+ diff: AgentProfileDiff[];
53
+ authorityDigest: string;
54
+ /** ADC hash of the public profile plan, without per-turn product attachments. */
55
+ planDigest: string;
56
+ state: ProfileRevisionState;
57
+ createdAt: number;
58
+ }
59
+ export interface ProfileBindingKey {
60
+ workspaceId: string;
61
+ memberId: string;
62
+ /** `chat`, or a product-scoped phone line and sender key. */
63
+ channel: string;
64
+ }
65
+ export interface ProfileBinding extends ProfileBindingKey {
66
+ profileId: string;
67
+ pinnedRevisionId: string | null;
68
+ authorityDigest: string;
69
+ planDigest: string;
70
+ version: number;
71
+ }
72
+ export interface ProfileTurnPin {
73
+ workspaceId: string;
74
+ memberId: string;
75
+ channel: string;
76
+ messageId: string;
77
+ inputHash: string;
78
+ profileId: string;
79
+ revisionId: string;
80
+ authorityDigest: string;
81
+ /** Effective ADC plan selected by the executor, including allowed turn attachments. */
82
+ planDigest: string;
83
+ }
84
+ /** Remove events name only adds they observed; a concurrent add survives. */
85
+ export interface ProfileKnowledgeEvent {
86
+ id: string;
87
+ workspaceId: string;
88
+ profileId: string;
89
+ documentId: string;
90
+ kind: 'add' | 'remove';
91
+ content: string | null;
92
+ observedAddIds: string[];
93
+ createdAt: number;
94
+ }
95
+ export interface ProfileKnowledgeDocument {
96
+ documentId: string;
97
+ content: string;
98
+ addEventId: string;
99
+ }
100
+ export interface ProfileSwitchReceipt {
101
+ key: ProfileBindingKey;
102
+ messageId: string;
103
+ inputHash: string;
104
+ profileId: string | null;
105
+ revisionId: string | null;
106
+ /** A rollback binds the previous immutable revision, not the current head. */
107
+ pinnedRevisionId: string | null;
108
+ authorityDigest: string | null;
109
+ planDigest: string | null;
110
+ outcome: 'switched' | 'refused';
111
+ message: string;
112
+ /** Workspace resource collisions retain the original and place the profile copy beside it. */
113
+ conflicts: string[];
114
+ }
115
+ export interface ProfileRevisionStore {
116
+ getActiveRevision(workspaceId: string, profileId: string): Promise<ProfileRevision | null>;
117
+ getRevision(workspaceId: string, profileId: string, revisionId: string): Promise<ProfileRevision | null>;
118
+ /** Append the immutable row and optionally an activation event in one guarded transaction. */
119
+ appendRevision(revision: ProfileRevision, expectedActiveId: string | null, activate: boolean): Promise<boolean>;
120
+ /** Promotion appends an activation event; the historical revision remains immutable. */
121
+ promoteRevision(workspaceId: string, profileId: string, revisionId: string, expectedActiveId: string | null): Promise<boolean>;
122
+ getBinding(key: ProfileBindingKey): Promise<ProfileBinding | null>;
123
+ getSwitchReceipt(key: ProfileBindingKey, messageId: string, inputHash: string): Promise<ProfileSwitchReceipt | null>;
124
+ /** Receipt and binding event append atomically; a refusal leaves the binding untouched. */
125
+ recordSwitch(receipt: ProfileSwitchReceipt, expectedVersion: number): Promise<ProfileSwitchReceipt>;
126
+ /** Persist one immutable pin under a message id; retries must return the same pin. */
127
+ pinTurn(pin: ProfileTurnPin, expectedBindingVersion: number): Promise<ProfileTurnPin>;
128
+ getTurnPin(key: ProfileBindingKey, messageId: string, inputHash: string): Promise<ProfileTurnPin | null>;
129
+ listKnowledgeEvents(workspaceId: string, profileId: string): Promise<ProfileKnowledgeEvent[]>;
130
+ appendKnowledgeEvent(event: ProfileKnowledgeEvent): Promise<void>;
131
+ }
132
+ export declare class ProfileConflictError extends Error {
133
+ constructor(message: string);
134
+ }
135
+ export declare class ProfileAccessError extends Error {
136
+ constructor(message: string);
137
+ }
138
+ /** Remove exactly the declared text axes. Unknown future fields remain authority. */
139
+ export declare function profileAuthority(profile: AgentProfile): AgentProfile;
140
+ export declare function profileAuthorityDigest(profile: AgentProfile): string;
141
+ export declare function projectKnowledgeDocuments(events: readonly ProfileKnowledgeEvent[]): ProfileKnowledgeDocument[];
142
+ export declare function addProfileKnowledgeDocument(input: {
143
+ store: ProfileRevisionStore;
144
+ workspaceId: string;
145
+ profileId: string;
146
+ documentId: string;
147
+ content: string;
148
+ actorRole: 'owner' | 'manager' | 'member' | 'viewer';
149
+ id?: string;
150
+ now?: number;
151
+ }): Promise<ProfileKnowledgeEvent>;
152
+ export declare function removeProfileKnowledgeDocument(input: {
153
+ store: ProfileRevisionStore;
154
+ workspaceId: string;
155
+ profileId: string;
156
+ documentId: string;
157
+ actorRole: 'owner' | 'manager' | 'member' | 'viewer';
158
+ id?: string;
159
+ now?: number;
160
+ }): Promise<ProfileKnowledgeEvent>;
161
+ /** The per-turn text overlay is validated without admitting tools, model, MCP or resources. */
162
+ export declare function bindProfileText(consentedBaseline: AgentProfile, selected: AgentProfile): AgentProfile;
163
+ export interface ProposeRevisionInput {
164
+ store: ProfileRevisionStore;
165
+ workspaceId: string;
166
+ profileId: string;
167
+ expectedRevisionId: string | null;
168
+ profile: AgentProfile;
169
+ knowledgeText: string;
170
+ /** The exact ADC `hashWorkspacePlan` for this authored snapshot. */
171
+ planDigest: string;
172
+ author: ProfileRevision['author'];
173
+ /** Trusted role from the authenticated session, never model arguments. */
174
+ actorRole: 'owner' | 'manager' | 'member' | 'viewer';
175
+ reason: string;
176
+ id?: string;
177
+ now?: number;
178
+ }
179
+ /** All authors use one immutable write path. Optimizer and authority edits cannot self-activate. */
180
+ export declare function proposeRevision(input: ProposeRevisionInput): Promise<ProfileRevision>;
181
+ export declare function promoteRevision(input: {
182
+ store: ProfileRevisionStore;
183
+ workspaceId: string;
184
+ profileId: string;
185
+ revisionId: string;
186
+ actorRole: 'owner' | 'manager' | 'member' | 'viewer';
187
+ /** Verified by the product's consent route; required when authority changes. */
188
+ verifyConsent?: (revision: ProfileRevision) => Promise<boolean>;
189
+ }): Promise<ProfileRevision>;
190
+ export declare function parseProfileSwitch(text: string): {
191
+ name: string;
192
+ } | {
193
+ invalid: true;
194
+ } | null;
195
+ export declare function normalizeProfileName(name: string): string;
196
+ export interface SwitchableProfile {
197
+ id: string;
198
+ name: string;
199
+ status: 'active' | 'draft' | 'paused';
200
+ }
201
+ export interface SwitchProfileInput {
202
+ store: ProfileRevisionStore;
203
+ key: ProfileBindingKey;
204
+ messageId: string;
205
+ content: string;
206
+ choice: {
207
+ name: string;
208
+ } | {
209
+ profileId: string;
210
+ };
211
+ profiles: readonly SwitchableProfile[];
212
+ /** Product's role/phone allowlist decision for the authenticated member. */
213
+ canSelect: (profileId: string) => Promise<boolean>;
214
+ /** Stage a complete managed plan for the same conversation; never mutate live workspace files. */
215
+ prepareAuthority: (revision: ProfileRevision, key: ProfileBindingKey) => Promise<{
216
+ planDigest: string;
217
+ healthy: true;
218
+ conflicts: string[];
219
+ }>;
220
+ }
221
+ /** The picker and deterministic text command converge here. Models cannot call it. */
222
+ export declare function switchProfile(input: SwitchProfileInput): Promise<ProfileSwitchReceipt>;
223
+ /** Call before dispatching a chat message; a recognized command is never sent to the model. */
224
+ export declare function handleProfileSwitchText(input: Omit<SwitchProfileInput, 'choice'>): Promise<ProfileSwitchReceipt | null>;
225
+ /** One-step rollback moves this member/channel to its previous immutable revision. */
226
+ export declare function rollbackProfileBinding(input: {
227
+ store: ProfileRevisionStore;
228
+ key: ProfileBindingKey;
229
+ messageId: string;
230
+ actorRole: 'owner' | 'manager' | 'member' | 'viewer';
231
+ canSelect: (profileId: string) => Promise<boolean>;
232
+ prepareAuthority: SwitchProfileInput['prepareAuthority'];
233
+ }): Promise<ProfileSwitchReceipt>;
234
+ export declare function admitProfileTurn(input: {
235
+ store: ProfileRevisionStore;
236
+ key: ProfileBindingKey;
237
+ messageId: string;
238
+ content: string;
239
+ /** Effective ADC plan digest selected by the executor for this revision and turn. */
240
+ observedManagedPlanDigest: string;
241
+ /** Required if trusted per-turn attachments change the public profile plan. */
242
+ verifyEffectivePlan?: (revision: ProfileRevision, effectivePlanDigest: string, key: ProfileBindingKey) => Promise<boolean>;
243
+ }): Promise<ProfileTurnPin>;
244
+ declare const textChangeSchema: z.ZodObject<{
245
+ name: z.ZodOptional<z.ZodString>;
246
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
247
+ systemPrompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
248
+ instructions: z.ZodOptional<z.ZodArray<z.ZodString>>;
249
+ knowledgeText: z.ZodOptional<z.ZodString>;
250
+ }, z.core.$strict>;
251
+ export declare function profileTextChange(revision: ProfileRevision, changes: z.infer<typeof textChangeSchema>): {
252
+ profile: AgentProfile;
253
+ knowledgeText: string;
254
+ };
255
+ export interface ProfileToolContext {
256
+ /** Resolve the running turn from the trusted server session; never from tool arguments. */
257
+ activeTurn(): Promise<{
258
+ workspaceId: string;
259
+ profileId: string;
260
+ revisionId: string;
261
+ memberId: string;
262
+ role: 'owner' | 'manager' | 'member' | 'viewer';
263
+ }>;
264
+ /** Product computes the plan with ADC, returning `hashWorkspacePlan(plan)`. */
265
+ planDigest(profile: AgentProfile, knowledgeText: string): Promise<string>;
266
+ store: ProfileRevisionStore;
267
+ }
268
+ /** Shared self-edit tools; only the authenticated active turn can name the profile. */
269
+ export declare function profileTools(context: ProfileToolContext): McpToolDefinition<Record<string, never>>[];
270
+ export {};
@@ -0,0 +1,43 @@
1
+ import {
2
+ PROFILE_CHANGE_POLICY,
3
+ ProfileAccessError,
4
+ ProfileConflictError,
5
+ addProfileKnowledgeDocument,
6
+ admitProfileTurn,
7
+ bindProfileText,
8
+ handleProfileSwitchText,
9
+ normalizeProfileName,
10
+ parseProfileSwitch,
11
+ profileAuthority,
12
+ profileAuthorityDigest,
13
+ profileTextChange,
14
+ profileTools,
15
+ projectKnowledgeDocuments,
16
+ promoteRevision,
17
+ proposeRevision,
18
+ removeProfileKnowledgeDocument,
19
+ rollbackProfileBinding,
20
+ switchProfile
21
+ } from "../chunk-D2NZQCOB.js";
22
+ export {
23
+ PROFILE_CHANGE_POLICY,
24
+ ProfileAccessError,
25
+ ProfileConflictError,
26
+ addProfileKnowledgeDocument,
27
+ admitProfileTurn,
28
+ bindProfileText,
29
+ handleProfileSwitchText,
30
+ normalizeProfileName,
31
+ parseProfileSwitch,
32
+ profileAuthority,
33
+ profileAuthorityDigest,
34
+ profileTextChange,
35
+ profileTools,
36
+ projectKnowledgeDocuments,
37
+ promoteRevision,
38
+ proposeRevision,
39
+ removeProfileKnowledgeDocument,
40
+ rollbackProfileBinding,
41
+ switchProfile
42
+ };
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,31 @@
1
+ /** Separate cleanup policy. Chat switches and profile tools never import this module. */
2
+ export declare const MIN_PROFILE_REAP_GRACE_MS: number;
3
+ export interface ProfileReapCandidate {
4
+ resourceId: string;
5
+ workspaceId: string;
6
+ /** When the final reference stopped using this resource. */
7
+ retiredAt: number;
8
+ /** Binding event that replaced this resource. */
9
+ successorBindingVersion: number;
10
+ }
11
+ export interface ProfileReaperPort {
12
+ listCandidates(): Promise<ProfileReapCandidate[]>;
13
+ /** Must include current bindings and all admitted turns still in flight. */
14
+ hasLiveReference(candidate: ProfileReapCandidate): Promise<boolean>;
15
+ hasSuccessfulSuccessorTurn(candidate: ProfileReapCandidate): Promise<boolean>;
16
+ hasDryRunReceipt(candidate: ProfileReapCandidate): Promise<boolean>;
17
+ recordDryRun(candidate: ProfileReapCandidate): Promise<void>;
18
+ /** Platform retire path. Recheck references atomically at retirement. */
19
+ retireIfStillUnreferenced(candidate: ProfileReapCandidate): Promise<boolean>;
20
+ }
21
+ export interface ProfileReapDecision {
22
+ candidate: ProfileReapCandidate;
23
+ status: 'too-new' | 'referenced' | 'no-successor-turn' | 'dry-run' | 'needs-dry-run' | 'retired' | 'changed';
24
+ }
25
+ /** Defaults to a logged dry run; a destructive pass requires a prior dry-run receipt. */
26
+ export declare function runProfileReaper(input: {
27
+ port: ProfileReaperPort;
28
+ now?: number;
29
+ graceMs?: number;
30
+ dryRun?: boolean;
31
+ }): Promise<ProfileReapDecision[]>;
@@ -0,0 +1,29 @@
1
+ // src/agent-profiles/reaper.ts
2
+ var MIN_PROFILE_REAP_GRACE_MS = 24 * 60 * 60 * 1e3;
3
+ async function runProfileReaper(input) {
4
+ const now = input.now ?? Date.now();
5
+ const graceMs = input.graceMs ?? MIN_PROFILE_REAP_GRACE_MS;
6
+ if (!Number.isFinite(now) || !Number.isFinite(graceMs) || graceMs < MIN_PROFILE_REAP_GRACE_MS) {
7
+ throw new TypeError("Profile reaper requires a grace period of at least 24 hours");
8
+ }
9
+ const dryRun = input.dryRun ?? true;
10
+ const decisions = [];
11
+ for (const candidate of await input.port.listCandidates()) {
12
+ let status;
13
+ if (candidate.retiredAt > now - graceMs) status = "too-new";
14
+ else if (await input.port.hasLiveReference(candidate)) status = "referenced";
15
+ else if (!await input.port.hasSuccessfulSuccessorTurn(candidate)) status = "no-successor-turn";
16
+ else if (dryRun) {
17
+ await input.port.recordDryRun(candidate);
18
+ status = "dry-run";
19
+ } else if (!await input.port.hasDryRunReceipt(candidate)) status = "needs-dry-run";
20
+ else status = await input.port.retireIfStillUnreferenced(candidate) ? "retired" : "changed";
21
+ decisions.push({ candidate, status });
22
+ }
23
+ return decisions;
24
+ }
25
+ export {
26
+ MIN_PROFILE_REAP_GRACE_MS,
27
+ runProfileReaper
28
+ };
29
+ //# sourceMappingURL=reaper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/agent-profiles/reaper.ts"],"sourcesContent":["/** Separate cleanup policy. Chat switches and profile tools never import this module. */\nexport const MIN_PROFILE_REAP_GRACE_MS = 24 * 60 * 60 * 1000\n\nexport interface ProfileReapCandidate {\n resourceId: string\n workspaceId: string\n /** When the final reference stopped using this resource. */\n retiredAt: number\n /** Binding event that replaced this resource. */\n successorBindingVersion: number\n}\n\nexport interface ProfileReaperPort {\n listCandidates(): Promise<ProfileReapCandidate[]>\n /** Must include current bindings and all admitted turns still in flight. */\n hasLiveReference(candidate: ProfileReapCandidate): Promise<boolean>\n hasSuccessfulSuccessorTurn(candidate: ProfileReapCandidate): Promise<boolean>\n hasDryRunReceipt(candidate: ProfileReapCandidate): Promise<boolean>\n recordDryRun(candidate: ProfileReapCandidate): Promise<void>\n /** Platform retire path. Recheck references atomically at retirement. */\n retireIfStillUnreferenced(candidate: ProfileReapCandidate): Promise<boolean>\n}\n\nexport interface ProfileReapDecision {\n candidate: ProfileReapCandidate\n status: 'too-new' | 'referenced' | 'no-successor-turn' | 'dry-run' | 'needs-dry-run' | 'retired' | 'changed'\n}\n\n/** Defaults to a logged dry run; a destructive pass requires a prior dry-run receipt. */\nexport async function runProfileReaper(input: {\n port: ProfileReaperPort\n now?: number\n graceMs?: number\n dryRun?: boolean\n}): Promise<ProfileReapDecision[]> {\n const now = input.now ?? Date.now()\n const graceMs = input.graceMs ?? MIN_PROFILE_REAP_GRACE_MS\n if (!Number.isFinite(now) || !Number.isFinite(graceMs) || graceMs < MIN_PROFILE_REAP_GRACE_MS) {\n throw new TypeError('Profile reaper requires a grace period of at least 24 hours')\n }\n const dryRun = input.dryRun ?? true\n const decisions: ProfileReapDecision[] = []\n for (const candidate of await input.port.listCandidates()) {\n let status: ProfileReapDecision['status']\n if (candidate.retiredAt > now - graceMs) status = 'too-new'\n else if (await input.port.hasLiveReference(candidate)) status = 'referenced'\n else if (!await input.port.hasSuccessfulSuccessorTurn(candidate)) status = 'no-successor-turn'\n else if (dryRun) {\n await input.port.recordDryRun(candidate)\n status = 'dry-run'\n } else if (!await input.port.hasDryRunReceipt(candidate)) status = 'needs-dry-run'\n else status = await input.port.retireIfStillUnreferenced(candidate) ? 'retired' : 'changed'\n decisions.push({ candidate, status })\n }\n return decisions\n}\n"],"mappings":";AACO,IAAM,4BAA4B,KAAK,KAAK,KAAK;AA4BxD,eAAsB,iBAAiB,OAKJ;AACjC,QAAM,MAAM,MAAM,OAAO,KAAK,IAAI;AAClC,QAAM,UAAU,MAAM,WAAW;AACjC,MAAI,CAAC,OAAO,SAAS,GAAG,KAAK,CAAC,OAAO,SAAS,OAAO,KAAK,UAAU,2BAA2B;AAC7F,UAAM,IAAI,UAAU,6DAA6D;AAAA,EACnF;AACA,QAAM,SAAS,MAAM,UAAU;AAC/B,QAAM,YAAmC,CAAC;AAC1C,aAAW,aAAa,MAAM,MAAM,KAAK,eAAe,GAAG;AACzD,QAAI;AACJ,QAAI,UAAU,YAAY,MAAM,QAAS,UAAS;AAAA,aACzC,MAAM,MAAM,KAAK,iBAAiB,SAAS,EAAG,UAAS;AAAA,aACvD,CAAC,MAAM,MAAM,KAAK,2BAA2B,SAAS,EAAG,UAAS;AAAA,aAClE,QAAQ;AACf,YAAM,MAAM,KAAK,aAAa,SAAS;AACvC,eAAS;AAAA,IACX,WAAW,CAAC,MAAM,MAAM,KAAK,iBAAiB,SAAS,EAAG,UAAS;AAAA,QAC9D,UAAS,MAAM,MAAM,KAAK,0BAA0B,SAAS,IAAI,YAAY;AAClF,cAAU,KAAK,EAAE,WAAW,OAAO,CAAC;AAAA,EACtC;AACA,SAAO;AACT;","names":[]}
@@ -1,12 +1,10 @@
1
1
  import {
2
2
  chatToolCallPart
3
- } from "../chunk-JAK2WU5U.js";
3
+ } from "../chunk-APZ4W7HJ.js";
4
4
  import "../chunk-X374TCDT.js";
5
5
  import "../chunk-3HUFJ5LO.js";
6
- import "../chunk-E4AY62T2.js";
7
6
  import "../chunk-FBVLEGEG.js";
8
7
  import "../chunk-Y6PRDUFJ.js";
9
- import "../chunk-GEYACSFW.js";
10
8
  import {
11
9
  ChatComposer
12
10
  } from "../chunk-7NEO73ZY.js";
@@ -17,7 +15,9 @@ import "../chunk-AUA75YFF.js";
17
15
  import {
18
16
  ModelPicker
19
17
  } from "../chunk-LVSKKDX2.js";
18
+ import "../chunk-E4AY62T2.js";
20
19
  import "../chunk-SJWIZT7B.js";
20
+ import "../chunk-GEYACSFW.js";
21
21
  import "../chunk-MLG6XKPV.js";
22
22
  import {
23
23
  AsyncView
@@ -26,9 +26,9 @@ import "../chunk-FQYAJYPW.js";
26
26
  import "../chunk-NJA6X7JI.js";
27
27
  import "../chunk-MCYJON3F.js";
28
28
  import "../chunk-7YA4QNTU.js";
29
- import "../chunk-HTAFI247.js";
30
- import "../chunk-ZVEEWGDK.js";
29
+ import "../chunk-WTGSLW5X.js";
31
30
  import "../chunk-GYDFGEJ2.js";
31
+ import "../chunk-ZVEEWGDK.js";
32
32
  import "../chunk-TXD5HXLE.js";
33
33
  import "../chunk-N56FWDSP.js";
34
34
  import "../chunk-FCON65I2.js";
@@ -45,13 +45,13 @@ import {
45
45
  } from "../chunk-73WE4UQG.js";
46
46
  import "../chunk-MCYJON3F.js";
47
47
  import "../chunk-LWSJK546.js";
48
- import "../chunk-7YLSF33A.js";
48
+ import "../chunk-IVE3T73T.js";
49
49
  import "../chunk-6A7MYOUI.js";
50
50
  import "../chunk-J5EBGZTD.js";
51
51
  import "../chunk-UGWQLQDS.js";
52
- import "../chunk-S5SRJJQG.js";
53
52
  import "../chunk-2BD7VZKN.js";
54
53
  import "../chunk-M63EUBSH.js";
54
+ import "../chunk-S5SRJJQG.js";
55
55
  import {
56
56
  ProtectedModelSettlementError
57
57
  } from "../chunk-IMMCSVLV.js";
@@ -64,16 +64,20 @@ import {
64
64
  rowIdOf,
65
65
  storeSupportsDraftPersistence,
66
66
  streamChatRouteAsSandboxEvents
67
- } from "../chunk-RNHXRPHO.js";
68
- import "../chunk-6VRVRWYN.js";
67
+ } from "../chunk-NWR5CERQ.js";
69
68
  import "../chunk-YNSPVKMS.js";
69
+ import "../chunk-6VRVRWYN.js";
70
70
  import "../chunk-3NCPXNBZ.js";
71
+ import "../chunk-53K4S3K6.js";
72
+ import {
73
+ coalesceDeltas,
74
+ createBufferedTurnTap
75
+ } from "../chunk-OEHEHPPA.js";
71
76
  import {
72
77
  attachmentInputToPart,
73
78
  attachmentKindForMime,
74
79
  toChatMessageParts
75
- } from "../chunk-HTAFI247.js";
76
- import "../chunk-ZVEEWGDK.js";
80
+ } from "../chunk-WTGSLW5X.js";
77
81
  import {
78
82
  ChatTurnInputError,
79
83
  DISPATCH_MAX_MEDIA_PARTS,
@@ -95,10 +99,10 @@ import {
95
99
  promptPartsByteSize,
96
100
  validateSandboxMentionPath
97
101
  } from "../chunk-GYDFGEJ2.js";
102
+ import "../chunk-ZVEEWGDK.js";
98
103
  import {
99
104
  isWorkspaceFileExportable
100
105
  } from "../chunk-TXD5HXLE.js";
101
- import "../chunk-53K4S3K6.js";
102
106
  import {
103
107
  asRecord,
104
108
  asString,
@@ -128,10 +132,6 @@ import {
128
132
  planFollowUpTurnId,
129
133
  planToPersistedPart
130
134
  } from "../chunk-LQYIBL3G.js";
131
- import {
132
- coalesceDeltas,
133
- createBufferedTurnTap
134
- } from "../chunk-OEHEHPPA.js";
135
135
 
136
136
  // src/chat-routes/model-failover-stream.ts
137
137
  var TERMINAL_FAILURE_TYPES = /* @__PURE__ */ new Set(["error", "session.run.failed"]);
@@ -14,9 +14,9 @@ import {
14
14
  mentionInputToPart,
15
15
  mentionPartsFromMessageParts,
16
16
  toChatMessageParts
17
- } from "../chunk-HTAFI247.js";
18
- import "../chunk-ZVEEWGDK.js";
17
+ } from "../chunk-WTGSLW5X.js";
19
18
  import "../chunk-GYDFGEJ2.js";
19
+ import "../chunk-ZVEEWGDK.js";
20
20
  import "../chunk-TXD5HXLE.js";
21
21
  import {
22
22
  attachmentPartKey
@@ -33,7 +33,7 @@ import {
33
33
  } from "./chunk-Q3ZHNN5X.js";
34
34
  import {
35
35
  attachmentPartsFromMessageParts
36
- } from "./chunk-HTAFI247.js";
36
+ } from "./chunk-WTGSLW5X.js";
37
37
  import {
38
38
  cancelStatusFor,
39
39
  fieldAcceptsFreeText,
@@ -7491,4 +7491,4 @@ export {
7491
7491
  useThinkingSeconds,
7492
7492
  ChatMessages
7493
7493
  };
7494
- //# sourceMappingURL=chunk-JAK2WU5U.js.map
7494
+ //# sourceMappingURL=chunk-APZ4W7HJ.js.map