@tangle-network/agent-app 0.60.104 → 0.60.106

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.
@@ -35,11 +35,16 @@ export interface OpenAIStreamChunk {
35
35
  name?: string;
36
36
  arguments?: string;
37
37
  };
38
+ /** Provider-specific call data the next request must echo back. Gemini 3
39
+ * sends `{ google: { thought_signature } }` here and answers HTTP 400
40
+ * when a later request's assistant `tool_calls` entry lacks it. */
41
+ extra_content?: unknown;
38
42
  }>;
39
43
  };
40
44
  finish_reason?: string | null;
41
45
  }>;
42
- /** Final-chunk token accounting (requires `stream_options.include_usage`). */
46
+ /** Token accounting (requires `stream_options.include_usage`). Cumulative for
47
+ * the call: the Tangle Router can send it on more than one chunk. */
43
48
  usage?: {
44
49
  prompt_tokens?: number;
45
50
  completion_tokens?: number;
@@ -52,6 +57,11 @@ export interface OpenAIStreamChunk {
52
57
  * (arguments JSON-parsed; an empty/garbled args string yields `{}` rather than
53
58
  * throwing). Works for the Tangle Router, tcloud, or any OpenAI-compat source.
54
59
  *
60
+ * A call's `extra_content` is kept as `providerFields.extra_content`, which the
61
+ * tool loop echoes on the call's assistant `tool_calls` entry in the next request.
62
+ * Usage is cumulative per call and may arrive on several chunks, so it is
63
+ * yielded once, the last value, when the stream ends.
64
+ *
55
65
  * Each call also yields one `tool_call_start` as soon as its name arrives,
56
66
  * while its arguments are still streaming, so a caller can start work the call
57
67
  * will need. Providers send the whole name in the call's first delta.
@@ -2,7 +2,7 @@ import {
2
2
  composeRouterTurnPrompt,
3
3
  routerFunctionName,
4
4
  runRouterTurn
5
- } from "../chunk-HIFYAQ42.js";
5
+ } from "../chunk-Q7M3GVLL.js";
6
6
  import "../chunk-D6UJEOZQ.js";
7
7
  import "../chunk-7YA4QNTU.js";
8
8
  export {
@@ -12,6 +12,23 @@ import {
12
12
  normalizeClientTurnId,
13
13
  resolveChatTurn
14
14
  } from "../chunk-YG66IHDU.js";
15
+ import {
16
+ DEFAULT_RUNNING_TURN_LEASE_MS,
17
+ DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS,
18
+ TURN_EVENTS_MIGRATION_SQL,
19
+ TURN_STATUS_LEASE_MIGRATION_SQL,
20
+ TURN_STATUS_RETENTION_MIGRATION_SQL,
21
+ TURN_STATUS_SCOPE_MIGRATION_SQL,
22
+ coalesceChatStreamEvents,
23
+ coalesceDeltas,
24
+ createBufferedTurnTap,
25
+ createD1TurnEventStore,
26
+ createMemoryTurnEventStore,
27
+ isLiveProgressEvent,
28
+ pumpBufferedTurn,
29
+ replayTurnEvents,
30
+ stampReplaySeq
31
+ } from "../chunk-ISP6ZH3G.js";
15
32
  import {
16
33
  MISSING_TOOL_TERMINAL_ERROR,
17
34
  MISSING_TOOL_TERMINAL_REASON,
@@ -36,23 +53,6 @@ import {
36
53
  } from "../chunk-ZGUXI5SI.js";
37
54
  import "../chunk-6VQCFJWP.js";
38
55
  import "../chunk-LQYIBL3G.js";
39
- import {
40
- DEFAULT_RUNNING_TURN_LEASE_MS,
41
- DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS,
42
- TURN_EVENTS_MIGRATION_SQL,
43
- TURN_STATUS_LEASE_MIGRATION_SQL,
44
- TURN_STATUS_RETENTION_MIGRATION_SQL,
45
- TURN_STATUS_SCOPE_MIGRATION_SQL,
46
- coalesceChatStreamEvents,
47
- coalesceDeltas,
48
- createBufferedTurnTap,
49
- createD1TurnEventStore,
50
- createMemoryTurnEventStore,
51
- isLiveProgressEvent,
52
- pumpBufferedTurn,
53
- replayTurnEvents,
54
- stampReplaySeq
55
- } from "../chunk-ISP6ZH3G.js";
56
56
  export {
57
57
  DEFAULT_RUNNING_TURN_LEASE_MS,
58
58
  DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS,
@@ -1,3 +1,6 @@
1
+ import {
2
+ SeatLimitError
3
+ } from "../chunk-MEUNTJL5.js";
1
4
  import {
2
5
  generateInvitationToken,
3
6
  getInvitationExpiresAt,
@@ -5,9 +8,6 @@ import {
5
8
  normalizeInvitationEmail,
6
9
  parseInvitationPermission
7
10
  } from "../chunk-AB63T2LM.js";
8
- import {
9
- SeatLimitError
10
- } from "../chunk-MEUNTJL5.js";
11
11
  import "../chunk-DJ4VJIH5.js";
12
12
  import {
13
13
  hasWorkspaceRole
@@ -136,7 +136,10 @@ import {
136
136
  withoutRecordGridCreated,
137
137
  withoutRecordGridRemoved,
138
138
  withoutRecordGridUpdate
139
- } from "../chunk-DO6JHTJY.js";
139
+ } from "../chunk-NBZQYRRM.js";
140
+ import {
141
+ MENTION_PILL_CLASS
142
+ } from "../chunk-3HUFJ5LO.js";
140
143
  import {
141
144
  SessionHistoryPanel,
142
145
  formatSessionTimestamp,
@@ -144,9 +147,6 @@ import {
144
147
  useSessionActions,
145
148
  useSessionHistory
146
149
  } from "../chunk-Y4WLCFDZ.js";
147
- import {
148
- MENTION_PILL_CLASS
149
- } from "../chunk-3HUFJ5LO.js";
150
150
  import "../chunk-FBVLEGEG.js";
151
151
  import {
152
152
  EvidenceLineageTable,
@@ -161,6 +161,9 @@ import {
161
161
  workProductStatusLabel,
162
162
  workProductStatusTone
163
163
  } from "../chunk-Y6PRDUFJ.js";
164
+ import {
165
+ parseReviewQueueItem
166
+ } from "../chunk-GEYACSFW.js";
164
167
  import {
165
168
  ChatComposer,
166
169
  ComposerModeControls,
@@ -218,13 +221,10 @@ import {
218
221
  usePending,
219
222
  usePopover
220
223
  } from "../chunk-HG4OONJA.js";
221
- import {
222
- parseReviewQueueItem
223
- } from "../chunk-GEYACSFW.js";
224
+ import "../chunk-LSUELMHY.js";
224
225
  import {
225
226
  ProviderLogo
226
227
  } from "../chunk-MLG6XKPV.js";
227
- import "../chunk-LSUELMHY.js";
228
228
  import "../chunk-FQYAJYPW.js";
229
229
  import {
230
230
  ATTACHMENT_ACCEPT
@@ -240,7 +240,8 @@ import {
240
240
  isChatAttachmentPart,
241
241
  mentionInputToPart,
242
242
  mentionPartsFromMessageParts
243
- } from "../chunk-WKD4E52F.js";
243
+ } from "../chunk-2YLSWZ5W.js";
244
+ import "../chunk-ZVEEWGDK.js";
244
245
  import {
245
246
  DISPATCH_MAX_MEDIA_PARTS,
246
247
  DISPATCH_MAX_PARTS,
@@ -262,7 +263,6 @@ import {
262
263
  mentionKindForPath,
263
264
  settleTurnResponse
264
265
  } from "../chunk-6E7LKHYV.js";
265
- import "../chunk-ZVEEWGDK.js";
266
266
  import "../chunk-TXD5HXLE.js";
267
267
  import {
268
268
  attachmentPartKey
@@ -0,0 +1,43 @@
1
+ /**
2
+ * D1 + R2 adapter for agent-runtime's `./workspace-store` port: one versioned
3
+ * memory and file store per tenant, shared by every executor of an app.
4
+ *
5
+ * Text lives in D1 rows; an entry carrying `bytes` points at an R2 object the
6
+ * host uploaded under a key it owns. Delete erases the row, records a tombstone
7
+ * and then removes the R2 object. Products apply {@link WORKSPACE_STORE_D1_SCHEMA_SQL}
8
+ * in their own migration.
9
+ */
10
+ import { type WorkspaceStore } from '@tangle-network/agent-runtime/workspace-store';
11
+ /** Structural subset of Cloudflare D1; keeps the driver out of the public types. */
12
+ export interface WorkspaceStoreD1Statement {
13
+ bind(...values: (string | number | null)[]): WorkspaceStoreD1Statement;
14
+ first<T>(): Promise<T | null>;
15
+ all<T>(): Promise<{
16
+ results: T[];
17
+ }>;
18
+ run(): Promise<{
19
+ meta: {
20
+ changes: number;
21
+ };
22
+ }>;
23
+ }
24
+ export interface WorkspaceStoreD1Database {
25
+ prepare(sql: string): WorkspaceStoreD1Statement;
26
+ batch(statements: WorkspaceStoreD1Statement[]): Promise<{
27
+ meta: {
28
+ changes: number;
29
+ };
30
+ }[]>;
31
+ }
32
+ /** Only `delete` is needed: the host uploads bytes before it puts the entry. */
33
+ export interface WorkspaceStoreR2Bucket {
34
+ delete(key: string): Promise<void>;
35
+ }
36
+ export declare const WORKSPACE_STORE_D1_SCHEMA_SQL = "\nCREATE TABLE workspace_store_entry (\n workspace_id TEXT NOT NULL,\n path TEXT NOT NULL,\n id TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('fact', 'preference', 'instruction', 'file')),\n scope TEXT NOT NULL CHECK (scope IN ('workspace', 'member')),\n content TEXT,\n bytes_key TEXT,\n bytes_size INTEGER,\n bytes_content_type TEXT,\n bytes_sha256 TEXT,\n revision INTEGER NOT NULL,\n created_by TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_by TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n PRIMARY KEY (workspace_id, path),\n CHECK ((content IS NULL) <> (bytes_key IS NULL))\n);\nCREATE TABLE workspace_store_path_revision (\n workspace_id TEXT NOT NULL,\n path TEXT NOT NULL,\n last_revision INTEGER NOT NULL,\n PRIMARY KEY (workspace_id, path)\n);\nCREATE TABLE workspace_store_tombstone (\n workspace_id TEXT NOT NULL,\n id TEXT NOT NULL,\n path TEXT NOT NULL,\n revision INTEGER NOT NULL,\n deleted_by TEXT NOT NULL,\n deleted_at TEXT NOT NULL,\n PRIMARY KEY (workspace_id, path, revision)\n);\n";
37
+ export interface D1R2WorkspaceStoreOptions {
38
+ db: WorkspaceStoreD1Database;
39
+ /** Required when entries carry `bytes`; delete removes the object after the row. */
40
+ bucket?: WorkspaceStoreR2Bucket;
41
+ now?: () => Date;
42
+ }
43
+ export declare function createD1R2WorkspaceStore(options: D1R2WorkspaceStoreOptions): WorkspaceStore;
@@ -0,0 +1,210 @@
1
+ // src/workspace-store/d1.ts
2
+ import {
3
+ checkWorkspacePut,
4
+ WorkspaceConflictError,
5
+ assertWorkspacePath
6
+ } from "@tangle-network/agent-runtime/workspace-store";
7
+ var WORKSPACE_STORE_D1_SCHEMA_SQL = `
8
+ CREATE TABLE workspace_store_entry (
9
+ workspace_id TEXT NOT NULL,
10
+ path TEXT NOT NULL,
11
+ id TEXT NOT NULL,
12
+ kind TEXT NOT NULL CHECK (kind IN ('fact', 'preference', 'instruction', 'file')),
13
+ scope TEXT NOT NULL CHECK (scope IN ('workspace', 'member')),
14
+ content TEXT,
15
+ bytes_key TEXT,
16
+ bytes_size INTEGER,
17
+ bytes_content_type TEXT,
18
+ bytes_sha256 TEXT,
19
+ revision INTEGER NOT NULL,
20
+ created_by TEXT NOT NULL,
21
+ created_at TEXT NOT NULL,
22
+ updated_by TEXT NOT NULL,
23
+ updated_at TEXT NOT NULL,
24
+ PRIMARY KEY (workspace_id, path),
25
+ CHECK ((content IS NULL) <> (bytes_key IS NULL))
26
+ );
27
+ CREATE TABLE workspace_store_path_revision (
28
+ workspace_id TEXT NOT NULL,
29
+ path TEXT NOT NULL,
30
+ last_revision INTEGER NOT NULL,
31
+ PRIMARY KEY (workspace_id, path)
32
+ );
33
+ CREATE TABLE workspace_store_tombstone (
34
+ workspace_id TEXT NOT NULL,
35
+ id TEXT NOT NULL,
36
+ path TEXT NOT NULL,
37
+ revision INTEGER NOT NULL,
38
+ deleted_by TEXT NOT NULL,
39
+ deleted_at TEXT NOT NULL,
40
+ PRIMARY KEY (workspace_id, path, revision)
41
+ );
42
+ `;
43
+ var ENTRY_COLUMNS = `workspace_id, path, id, kind, scope, content, bytes_key, bytes_size,
44
+ bytes_content_type, bytes_sha256, revision, created_by, created_at, updated_by, updated_at`;
45
+ function entry(row) {
46
+ const bytes = row.bytes_key === null ? void 0 : {
47
+ key: row.bytes_key,
48
+ size: row.bytes_size ?? 0,
49
+ ...row.bytes_content_type ? { contentType: row.bytes_content_type } : {},
50
+ ...row.bytes_sha256 ? { sha256: row.bytes_sha256 } : {}
51
+ };
52
+ return {
53
+ workspaceId: row.workspace_id,
54
+ id: row.id,
55
+ path: row.path,
56
+ kind: row.kind,
57
+ scope: row.scope,
58
+ ...row.content !== null ? { content: row.content } : {},
59
+ ...bytes ? { bytes } : {},
60
+ revision: row.revision,
61
+ createdBy: row.created_by,
62
+ createdAt: row.created_at,
63
+ updatedBy: row.updated_by,
64
+ updatedAt: row.updated_at
65
+ };
66
+ }
67
+ function tombstone(row) {
68
+ return {
69
+ workspaceId: row.workspace_id,
70
+ id: row.id,
71
+ path: row.path,
72
+ revision: row.revision,
73
+ deletedBy: row.deleted_by,
74
+ deletedAt: row.deleted_at
75
+ };
76
+ }
77
+ function scopeOf(path) {
78
+ return /^\/memories\/members\/[^/]+\//.test(path) ? "member" : "workspace";
79
+ }
80
+ var PREFIX = "substr(path, 1, length(?)) = ?";
81
+ function createD1R2WorkspaceStore(options) {
82
+ const { db, bucket } = options;
83
+ const now = () => (options.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
84
+ async function current(workspaceId, path) {
85
+ return db.prepare(`SELECT ${ENTRY_COLUMNS} FROM workspace_store_entry WHERE workspace_id = ? AND path = ?`).bind(workspaceId, path).first();
86
+ }
87
+ async function lastRevision(workspaceId, path) {
88
+ const row = await db.prepare(`SELECT last_revision FROM workspace_store_path_revision
89
+ WHERE workspace_id = ? AND path = ?`).bind(workspaceId, path).first();
90
+ return row?.last_revision ?? 0;
91
+ }
92
+ function bumpRevision(workspaceId, path, previous, next, landed) {
93
+ return db.prepare(`INSERT INTO workspace_store_path_revision (workspace_id, path, last_revision)
94
+ SELECT ?, ?, ? WHERE ${landed.sql}
95
+ ON CONFLICT (workspace_id, path) DO UPDATE SET last_revision = excluded.last_revision
96
+ WHERE workspace_store_path_revision.last_revision = ?`).bind(workspaceId, path, next, ...landed.values, previous);
97
+ }
98
+ async function conflict(input, expected) {
99
+ const actual = await current(input.workspaceId, input.path);
100
+ throw new WorkspaceConflictError(input.path, expected, actual?.revision ?? null);
101
+ }
102
+ return {
103
+ async get(workspaceId, path) {
104
+ assertWorkspacePath(path);
105
+ const row = await current(workspaceId, path);
106
+ return row ? entry(row) : null;
107
+ },
108
+ async list(workspaceId, prefix) {
109
+ const { results } = await db.prepare(`SELECT ${ENTRY_COLUMNS} FROM workspace_store_entry
110
+ WHERE workspace_id = ? AND ${PREFIX} ORDER BY path`).bind(workspaceId, prefix, prefix).all();
111
+ return results.map(entry);
112
+ },
113
+ async put(input) {
114
+ checkWorkspacePut(input);
115
+ const existing = await current(input.workspaceId, input.path);
116
+ if ((existing?.revision ?? null) !== input.ifRevision) return conflict(input, input.ifRevision);
117
+ const previous = await lastRevision(input.workspaceId, input.path);
118
+ const revision = previous + 1;
119
+ const at = now();
120
+ const bytes = input.bytes;
121
+ const body = [
122
+ input.content ?? null,
123
+ bytes?.key ?? null,
124
+ bytes?.size ?? null,
125
+ bytes?.contentType ?? null,
126
+ bytes?.sha256 ?? null
127
+ ];
128
+ const write = existing ? db.prepare(`UPDATE workspace_store_entry SET kind = ?, content = ?, bytes_key = ?, bytes_size = ?,
129
+ bytes_content_type = ?, bytes_sha256 = ?, revision = ?, updated_by = ?, updated_at = ?
130
+ WHERE workspace_id = ? AND path = ? AND revision = ?`).bind(input.kind, ...body, revision, input.actor, at, input.workspaceId, input.path, existing.revision) : db.prepare(`INSERT INTO workspace_store_entry (${ENTRY_COLUMNS})
131
+ SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
132
+ WHERE NOT EXISTS (SELECT 1 FROM workspace_store_entry WHERE workspace_id = ? AND path = ?)`).bind(
133
+ input.workspaceId,
134
+ input.path,
135
+ input.id ?? crypto.randomUUID(),
136
+ input.kind,
137
+ scopeOf(input.path),
138
+ ...body,
139
+ revision,
140
+ input.actor,
141
+ at,
142
+ input.actor,
143
+ at,
144
+ input.workspaceId,
145
+ input.path
146
+ );
147
+ const landed = {
148
+ sql: `EXISTS (SELECT 1 FROM workspace_store_entry
149
+ WHERE workspace_id = ? AND path = ? AND revision = ? AND updated_at = ?)`,
150
+ values: [input.workspaceId, input.path, revision, at]
151
+ };
152
+ const [written] = await db.batch([
153
+ write,
154
+ bumpRevision(input.workspaceId, input.path, previous, revision, landed)
155
+ ]);
156
+ if (written?.meta.changes !== 1) return conflict(input, input.ifRevision);
157
+ const saved = await current(input.workspaceId, input.path);
158
+ if (!saved || saved.revision !== revision) return conflict(input, input.ifRevision);
159
+ return entry(saved);
160
+ },
161
+ async delete(input) {
162
+ assertWorkspacePath(input.path);
163
+ const existing = await current(input.workspaceId, input.path);
164
+ if (!existing) {
165
+ if (input.ifRevision !== void 0) return conflict(input, input.ifRevision);
166
+ return null;
167
+ }
168
+ if (input.ifRevision !== void 0 && existing.revision !== input.ifRevision) {
169
+ return conflict(input, input.ifRevision);
170
+ }
171
+ const previous = await lastRevision(input.workspaceId, input.path);
172
+ const revision = Math.max(previous, existing.revision) + 1;
173
+ const at = now();
174
+ const gone = {
175
+ sql: `NOT EXISTS (SELECT 1 FROM workspace_store_entry WHERE workspace_id = ? AND path = ?)`,
176
+ values: [input.workspaceId, input.path]
177
+ };
178
+ const [erased] = await db.batch([
179
+ db.prepare(`DELETE FROM workspace_store_entry WHERE workspace_id = ? AND path = ? AND revision = ?`).bind(input.workspaceId, input.path, existing.revision),
180
+ db.prepare(`INSERT INTO workspace_store_tombstone (workspace_id, id, path, revision, deleted_by, deleted_at)
181
+ SELECT ?, ?, ?, ?, ?, ? WHERE ${gone.sql}`).bind(input.workspaceId, existing.id, input.path, revision, input.actor, at, ...gone.values),
182
+ bumpRevision(input.workspaceId, input.path, previous, revision, gone)
183
+ ]);
184
+ if (erased?.meta.changes !== 1) return conflict(input, input.ifRevision ?? existing.revision);
185
+ if (existing.bytes_key) {
186
+ if (!bucket) throw new Error(`${input.path}: an R2 bucket is required to erase its bytes`);
187
+ await bucket.delete(existing.bytes_key);
188
+ }
189
+ return {
190
+ workspaceId: input.workspaceId,
191
+ id: existing.id,
192
+ path: input.path,
193
+ revision,
194
+ deletedBy: input.actor,
195
+ deletedAt: at
196
+ };
197
+ },
198
+ async tombstones(workspaceId, prefix = "/") {
199
+ const { results } = await db.prepare(`SELECT workspace_id, id, path, revision, deleted_by, deleted_at
200
+ FROM workspace_store_tombstone WHERE workspace_id = ? AND ${PREFIX}
201
+ ORDER BY deleted_at, revision`).bind(workspaceId, prefix, prefix).all();
202
+ return results.map(tombstone);
203
+ }
204
+ };
205
+ }
206
+ export {
207
+ WORKSPACE_STORE_D1_SCHEMA_SQL,
208
+ createD1R2WorkspaceStore
209
+ };
210
+ //# sourceMappingURL=d1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/workspace-store/d1.ts"],"sourcesContent":["/**\n * D1 + R2 adapter for agent-runtime's `./workspace-store` port: one versioned\n * memory and file store per tenant, shared by every executor of an app.\n *\n * Text lives in D1 rows; an entry carrying `bytes` points at an R2 object the\n * host uploaded under a key it owns. Delete erases the row, records a tombstone\n * and then removes the R2 object. Products apply {@link WORKSPACE_STORE_D1_SCHEMA_SQL}\n * in their own migration.\n */\nimport {\n checkWorkspacePut, WorkspaceConflictError, assertWorkspacePath,\n type WorkspaceBytesRef, type WorkspaceDeleteInput, type WorkspaceEntry, type WorkspaceEntryKind,\n type WorkspacePutInput, type WorkspaceStore, type WorkspaceTombstone,\n} from '@tangle-network/agent-runtime/workspace-store'\n\n/** Structural subset of Cloudflare D1; keeps the driver out of the public types. */\nexport interface WorkspaceStoreD1Statement {\n bind(...values: (string | number | null)[]): WorkspaceStoreD1Statement\n first<T>(): Promise<T | null>\n all<T>(): Promise<{ results: T[] }>\n run(): Promise<{ meta: { changes: number } }>\n}\n\nexport interface WorkspaceStoreD1Database {\n prepare(sql: string): WorkspaceStoreD1Statement\n batch(statements: WorkspaceStoreD1Statement[]): Promise<{ meta: { changes: number } }[]>\n}\n\n/** Only `delete` is needed: the host uploads bytes before it puts the entry. */\nexport interface WorkspaceStoreR2Bucket {\n delete(key: string): Promise<void>\n}\n\nexport const WORKSPACE_STORE_D1_SCHEMA_SQL = `\nCREATE TABLE workspace_store_entry (\n workspace_id TEXT NOT NULL,\n path TEXT NOT NULL,\n id TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('fact', 'preference', 'instruction', 'file')),\n scope TEXT NOT NULL CHECK (scope IN ('workspace', 'member')),\n content TEXT,\n bytes_key TEXT,\n bytes_size INTEGER,\n bytes_content_type TEXT,\n bytes_sha256 TEXT,\n revision INTEGER NOT NULL,\n created_by TEXT NOT NULL,\n created_at TEXT NOT NULL,\n updated_by TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n PRIMARY KEY (workspace_id, path),\n CHECK ((content IS NULL) <> (bytes_key IS NULL))\n);\nCREATE TABLE workspace_store_path_revision (\n workspace_id TEXT NOT NULL,\n path TEXT NOT NULL,\n last_revision INTEGER NOT NULL,\n PRIMARY KEY (workspace_id, path)\n);\nCREATE TABLE workspace_store_tombstone (\n workspace_id TEXT NOT NULL,\n id TEXT NOT NULL,\n path TEXT NOT NULL,\n revision INTEGER NOT NULL,\n deleted_by TEXT NOT NULL,\n deleted_at TEXT NOT NULL,\n PRIMARY KEY (workspace_id, path, revision)\n);\n`\n\ninterface EntryRow {\n workspace_id: string; path: string; id: string; kind: WorkspaceEntryKind; scope: WorkspaceEntry['scope']\n content: string | null; bytes_key: string | null; bytes_size: number | null\n bytes_content_type: string | null; bytes_sha256: string | null; revision: number\n created_by: string; created_at: string; updated_by: string; updated_at: string\n}\n\ninterface TombstoneRow {\n workspace_id: string; id: string; path: string; revision: number; deleted_by: string; deleted_at: string\n}\n\nconst ENTRY_COLUMNS = `workspace_id, path, id, kind, scope, content, bytes_key, bytes_size,\n bytes_content_type, bytes_sha256, revision, created_by, created_at, updated_by, updated_at`\n\nfunction entry(row: EntryRow): WorkspaceEntry {\n const bytes: WorkspaceBytesRef | undefined = row.bytes_key === null ? undefined : {\n key: row.bytes_key, size: row.bytes_size ?? 0,\n ...(row.bytes_content_type ? { contentType: row.bytes_content_type } : {}),\n ...(row.bytes_sha256 ? { sha256: row.bytes_sha256 } : {}),\n }\n return { workspaceId: row.workspace_id, id: row.id, path: row.path, kind: row.kind, scope: row.scope,\n ...(row.content !== null ? { content: row.content } : {}), ...(bytes ? { bytes } : {}),\n revision: row.revision, createdBy: row.created_by, createdAt: row.created_at,\n updatedBy: row.updated_by, updatedAt: row.updated_at }\n}\n\nfunction tombstone(row: TombstoneRow): WorkspaceTombstone {\n return { workspaceId: row.workspace_id, id: row.id, path: row.path, revision: row.revision,\n deletedBy: row.deleted_by, deletedAt: row.deleted_at }\n}\n\nfunction scopeOf(path: string): WorkspaceEntry['scope'] {\n return /^\\/memories\\/members\\/[^/]+\\//.test(path) ? 'member' : 'workspace'\n}\n\n/** Prefix match without LIKE wildcards: model-chosen paths may contain `%` and `_`. */\nconst PREFIX = 'substr(path, 1, length(?)) = ?'\n\nexport interface D1R2WorkspaceStoreOptions {\n db: WorkspaceStoreD1Database\n /** Required when entries carry `bytes`; delete removes the object after the row. */\n bucket?: WorkspaceStoreR2Bucket\n now?: () => Date\n}\n\nexport function createD1R2WorkspaceStore(options: D1R2WorkspaceStoreOptions): WorkspaceStore {\n const { db, bucket } = options\n const now = () => (options.now?.() ?? new Date()).toISOString()\n\n async function current(workspaceId: string, path: string): Promise<EntryRow | null> {\n return db.prepare(`SELECT ${ENTRY_COLUMNS} FROM workspace_store_entry WHERE workspace_id = ? AND path = ?`)\n .bind(workspaceId, path).first<EntryRow>()\n }\n\n async function lastRevision(workspaceId: string, path: string): Promise<number> {\n const row = await db.prepare(`SELECT last_revision FROM workspace_store_path_revision\n WHERE workspace_id = ? AND path = ?`).bind(workspaceId, path).first<{ last_revision: number }>()\n return row?.last_revision ?? 0\n }\n\n /** Advance the path counter only when the entry write in the same batch landed. */\n function bumpRevision(workspaceId: string, path: string, previous: number, next: number,\n landed: { sql: string; values: (string | number | null)[] }): WorkspaceStoreD1Statement {\n return db.prepare(`INSERT INTO workspace_store_path_revision (workspace_id, path, last_revision)\n SELECT ?, ?, ? WHERE ${landed.sql}\n ON CONFLICT (workspace_id, path) DO UPDATE SET last_revision = excluded.last_revision\n WHERE workspace_store_path_revision.last_revision = ?`)\n .bind(workspaceId, path, next, ...landed.values, previous)\n }\n\n async function conflict(input: { workspaceId: string; path: string }, expected: number | null): Promise<never> {\n const actual = await current(input.workspaceId, input.path)\n throw new WorkspaceConflictError(input.path, expected, actual?.revision ?? null)\n }\n\n return {\n async get(workspaceId, path) {\n assertWorkspacePath(path)\n const row = await current(workspaceId, path)\n return row ? entry(row) : null\n },\n\n async list(workspaceId, prefix) {\n const { results } = await db.prepare(`SELECT ${ENTRY_COLUMNS} FROM workspace_store_entry\n WHERE workspace_id = ? AND ${PREFIX} ORDER BY path`).bind(workspaceId, prefix, prefix).all<EntryRow>()\n return results.map(entry)\n },\n\n async put(input: WorkspacePutInput) {\n checkWorkspacePut(input)\n const existing = await current(input.workspaceId, input.path)\n if ((existing?.revision ?? null) !== input.ifRevision) return conflict(input, input.ifRevision)\n const previous = await lastRevision(input.workspaceId, input.path)\n const revision = previous + 1\n const at = now()\n const bytes = input.bytes\n const body = [input.content ?? null, bytes?.key ?? null, bytes?.size ?? null,\n bytes?.contentType ?? null, bytes?.sha256 ?? null] as const\n const write = existing\n ? db.prepare(`UPDATE workspace_store_entry SET kind = ?, content = ?, bytes_key = ?, bytes_size = ?,\n bytes_content_type = ?, bytes_sha256 = ?, revision = ?, updated_by = ?, updated_at = ?\n WHERE workspace_id = ? AND path = ? AND revision = ?`)\n .bind(input.kind, ...body, revision, input.actor, at, input.workspaceId, input.path, existing.revision)\n : db.prepare(`INSERT INTO workspace_store_entry (${ENTRY_COLUMNS})\n SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?\n WHERE NOT EXISTS (SELECT 1 FROM workspace_store_entry WHERE workspace_id = ? AND path = ?)`)\n .bind(input.workspaceId, input.path, input.id ?? crypto.randomUUID(), input.kind, scopeOf(input.path),\n ...body, revision, input.actor, at, input.actor, at, input.workspaceId, input.path)\n const landed = { sql: `EXISTS (SELECT 1 FROM workspace_store_entry\n WHERE workspace_id = ? AND path = ? AND revision = ? AND updated_at = ?)`,\n values: [input.workspaceId, input.path, revision, at] }\n const [written] = await db.batch([write,\n bumpRevision(input.workspaceId, input.path, previous, revision, landed)])\n if (written?.meta.changes !== 1) return conflict(input, input.ifRevision)\n const saved = await current(input.workspaceId, input.path)\n if (!saved || saved.revision !== revision) return conflict(input, input.ifRevision)\n return entry(saved)\n },\n\n async delete(input: WorkspaceDeleteInput) {\n assertWorkspacePath(input.path)\n const existing = await current(input.workspaceId, input.path)\n if (!existing) {\n if (input.ifRevision !== undefined) return conflict(input, input.ifRevision)\n return null\n }\n if (input.ifRevision !== undefined && existing.revision !== input.ifRevision) {\n return conflict(input, input.ifRevision)\n }\n const previous = await lastRevision(input.workspaceId, input.path)\n const revision = Math.max(previous, existing.revision) + 1\n const at = now()\n const gone = { sql: `NOT EXISTS (SELECT 1 FROM workspace_store_entry WHERE workspace_id = ? AND path = ?)`,\n values: [input.workspaceId, input.path] }\n const [erased] = await db.batch([\n db.prepare(`DELETE FROM workspace_store_entry WHERE workspace_id = ? AND path = ? AND revision = ?`)\n .bind(input.workspaceId, input.path, existing.revision),\n db.prepare(`INSERT INTO workspace_store_tombstone (workspace_id, id, path, revision, deleted_by, deleted_at)\n SELECT ?, ?, ?, ?, ?, ? WHERE ${gone.sql}`)\n .bind(input.workspaceId, existing.id, input.path, revision, input.actor, at, ...gone.values),\n bumpRevision(input.workspaceId, input.path, previous, revision, gone),\n ])\n if (erased?.meta.changes !== 1) return conflict(input, input.ifRevision ?? existing.revision)\n // The row is gone first, so a failed object delete leaves an orphan object,\n // never an entry that points at missing bytes. Surface the failure.\n if (existing.bytes_key) {\n if (!bucket) throw new Error(`${input.path}: an R2 bucket is required to erase its bytes`)\n await bucket.delete(existing.bytes_key)\n }\n return { workspaceId: input.workspaceId, id: existing.id, path: input.path, revision,\n deletedBy: input.actor, deletedAt: at }\n },\n\n async tombstones(workspaceId, prefix = '/') {\n const { results } = await db.prepare(`SELECT workspace_id, id, path, revision, deleted_by, deleted_at\n FROM workspace_store_tombstone WHERE workspace_id = ? AND ${PREFIX}\n ORDER BY deleted_at, revision`).bind(workspaceId, prefix, prefix).all<TombstoneRow>()\n return results.map(tombstone)\n },\n }\n}\n"],"mappings":";AASA;AAAA,EACE;AAAA,EAAmB;AAAA,EAAwB;AAAA,OAGtC;AAoBA,IAAM,gCAAgC;AAAA;AAAA;A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AAA,QAAE,aAAa,MAAM;AAAA,QAAa,IAAI,SAAS;AAAA,QAAI,MAAM,MAAM;AAAA,QAAM;AAAA,QAC1E,WAAW,MAAM;AAAA,QAAO,WAAW;AAAA,MAAG;AAAA,IAC1C;AAAA,IAEA,MAAM,WAAW,aAAa,SAAS,KAAK;AAC1C,YAAM,EAAE,QAAQ,IAAI,MAAM,GAAG,QAAQ;AAAA,oEACyB,MAAM;AAAA,sCACpC,EAAE,KAAK,aAAa,QAAQ,MAAM,EAAE,IAAkB;AACtF,aAAO,QAAQ,IAAI,SAAS;AAAA,IAC9B;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-app",
3
- "version": "0.60.104",
3
+ "version": "0.60.106",
4
4
  "packageManager": "pnpm@11.24.0",
5
5
  "description": "Build agent applications with typed chat, tools, sandboxes, integrations, billing, and evaluation.",
6
6
  "keywords": [
@@ -152,6 +152,11 @@
152
152
  "import": "./dist/agent-profiles/switch.js",
153
153
  "default": "./dist/agent-profiles/switch.js"
154
154
  },
155
+ "./workspace-store/d1": {
156
+ "types": "./dist/workspace-store/d1.d.ts",
157
+ "import": "./dist/workspace-store/d1.js",
158
+ "default": "./dist/workspace-store/d1.js"
159
+ },
155
160
  "./agent-profiles/d1": {
156
161
  "types": "./dist/agent-profiles/d1.d.ts",
157
162
  "import": "./dist/agent-profiles/d1.js",
@@ -674,7 +679,7 @@
674
679
  "@tangle-network/agent-interface": "3.1.1",
675
680
  "@tangle-network/agent-knowledge": "20.0.0",
676
681
  "@tangle-network/agent-profile-materialize": "0.22.0",
677
- "@tangle-network/agent-runtime": "0.313.1",
682
+ "@tangle-network/agent-runtime": "0.317.0",
678
683
  "@tangle-network/brand": "1.21.1",
679
684
  "@tangle-network/hub-sdk": "0.28.0",
680
685
  "@tangle-network/sandbox": "0.60.22",
@@ -746,7 +751,7 @@
746
751
  "@tangle-network/agent-interface": "^2.13.0 || ^3.0.0",
747
752
  "@tangle-network/agent-knowledge": "^17.1.2 || ^18.0.0 || ^19.0.1 || ^20.0.0",
748
753
  "@tangle-network/agent-profile-materialize": ">=0.20.1 <0.21.0 || >=0.21.0 <0.22.0 || >=0.22.0 <0.23.0",
749
- "@tangle-network/agent-runtime": ">=0.282.2 <0.284.0 || >=0.285.0 <0.286.0 || >=0.289.1 <0.290.0 || >=0.291.0 <0.292.0 || >=0.293.0 <0.294.0 || >=0.308.0 <0.309.0 || >=0.313.1 <0.314.0",
754
+ "@tangle-network/agent-runtime": ">=0.282.2 <0.284.0 || >=0.285.0 <0.286.0 || >=0.289.1 <0.290.0 || >=0.291.0 <0.292.0 || >=0.293.0 <0.294.0 || >=0.308.0 <0.309.0 || >=0.313.1 <0.314.0 || >=0.316.0 <0.317.0 || >=0.317.0 <0.318.0",
750
755
  "@tangle-network/brand": ">=1.21.1",
751
756
  "@tangle-network/hub-sdk": ">=0.19.3 <0.21.0 || >=0.21.0 <0.22.0 || >=0.22.1 <0.25.0 || >=0.27.0 <0.28.0 || >=0.28.0 <0.29.0",
752
757
  "@tangle-network/sandbox": ">=0.45.0 <0.48.0 || ^0.49.0 || ^0.50.0 || ^0.51.0 || ^0.52.0 || ^0.53.0 || ^0.54.0 || ^0.55.0 || >=0.58.1 <0.60.0 || >=0.60.3 <0.61.0",