@deepagents/experimental 7.7.1 → 7.7.2

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/index.js CHANGED
@@ -325,6 +325,7 @@ __export(zukhruf_exports, {
325
325
  AgentPluginCapability: () => AgentPluginCapability,
326
326
  AgentRuntime: () => AgentRuntime,
327
327
  AgentThread: () => AgentThread,
328
+ ConversationNotFoundError: () => ConversationNotFoundError,
328
329
  DEFAULT_CONVERSATION_STATUS_CHANNEL: () => DEFAULT_CONVERSATION_STATUS_CHANNEL,
329
330
  InterAgentCommunicationTypes: () => InterAgentCommunicationTypes,
330
331
  MailboxStore: () => MailboxStore,
@@ -526,6 +527,21 @@ var AgentThread = class _AgentThread {
526
527
  }
527
528
  };
528
529
 
530
+ // packages/experimental/src/zukhruf/control-plane/conversation-not-found-error.ts
531
+ var ConversationNotFoundError = class extends Error {
532
+ name = "ConversationNotFoundError";
533
+ chatId;
534
+ constructor(chatId) {
535
+ super(`chat "${chatId}" does not exist`);
536
+ this.chatId = chatId;
537
+ }
538
+ };
539
+ function assertConversationOwner(conversation, storedUserId) {
540
+ if (storedUserId !== conversation.userId) {
541
+ throw new ConversationNotFoundError(conversation.chatId);
542
+ }
543
+ }
544
+
529
545
  // packages/experimental/src/zukhruf/instructions.ts
530
546
  function defineInstructions(...fragments) {
531
547
  return fragments;
@@ -1201,14 +1217,14 @@ var AgentDirectory = class _AgentDirectory {
1201
1217
  async assertOwnerIfExists(conversation) {
1202
1218
  const chat2 = await this.#store.getChat(conversation.chatId);
1203
1219
  if (!chat2) return;
1204
- this.#assertOwner(conversation, chat2.userId);
1220
+ assertConversationOwner(conversation, chat2.userId);
1205
1221
  const thread = this.#threadFromMetadata(conversation, chat2.metadata);
1206
1222
  if (thread) await this.#assertValidParent(thread);
1207
1223
  }
1208
1224
  async load(conversation) {
1209
1225
  const chat2 = await this.#store.getChat(conversation.chatId);
1210
- if (chat2) this.#assertOwner(conversation, chat2.userId);
1211
1226
  if (!chat2) return void 0;
1227
+ assertConversationOwner(conversation, chat2.userId);
1212
1228
  const thread = this.#threadFromMetadata(conversation, chat2.metadata);
1213
1229
  if (thread) await this.#assertValidParent(thread);
1214
1230
  return thread;
@@ -1221,7 +1237,7 @@ var AgentDirectory = class _AgentDirectory {
1221
1237
  let thread;
1222
1238
  let adopted = false;
1223
1239
  await this.#store.updateChat(conversation.chatId, (chat2) => {
1224
- this.#assertOwner(conversation, chat2.userId);
1240
+ assertConversationOwner(conversation, chat2.userId);
1225
1241
  const existing = this.#threadFromMetadata(conversation, chat2.metadata);
1226
1242
  if (existing) {
1227
1243
  thread = existing;
@@ -1318,12 +1334,6 @@ var AgentDirectory = class _AgentDirectory {
1318
1334
  uuidv5.URL
1319
1335
  );
1320
1336
  }
1321
- #assertOwner(conversation, storedUserId) {
1322
- if (storedUserId === conversation.userId) return;
1323
- throw new Error(
1324
- `chat "${conversation.chatId}" belongs to user "${storedUserId}", not "${conversation.userId}"`
1325
- );
1326
- }
1327
1337
  #threadFromMetadata(conversation, metadata) {
1328
1338
  const thread = AgentThread.fromMetadata(conversation, metadata);
1329
1339
  if (!thread && AgentThread.hasReservedMetadata(metadata)) {
@@ -1361,7 +1371,7 @@ var AgentDirectory = class _AgentDirectory {
1361
1371
  async #updateLatestTurn(conversation, streamId, ...expected) {
1362
1372
  let result;
1363
1373
  await this.#store.updateChat(conversation.chatId, (chat2) => {
1364
- this.#assertOwner(conversation, chat2.userId);
1374
+ assertConversationOwner(conversation, chat2.userId);
1365
1375
  const thread = this.#threadFromMetadata(conversation, chat2.metadata);
1366
1376
  if (!thread) {
1367
1377
  throw new Error(
@@ -4821,10 +4831,13 @@ var RuntimeHost = class {
4821
4831
  subscribeConversationStatus: (signal) => this.subscribeConversationStatus(signal),
4822
4832
  // Borrows the root declaration's sandbox directly: resolving the
4823
4833
  // conversation through the control plane would create its root thread.
4824
- sandbox: (conversation) => sandboxes.acquire(this.#root, {
4825
- chatId: conversation.chatId,
4826
- userId: conversation.userId
4827
- })
4834
+ sandbox: async (conversation) => {
4835
+ await this.#directory.assertOwnerIfExists(conversation);
4836
+ return sandboxes.acquire(this.#root, {
4837
+ chatId: conversation.chatId,
4838
+ userId: conversation.userId
4839
+ });
4840
+ }
4828
4841
  };
4829
4842
  resources.use(this.#workers);
4830
4843
  }
@@ -4881,21 +4894,13 @@ var RuntimeHost = class {
4881
4894
  }
4882
4895
  async #readConversationMetadata(conversation) {
4883
4896
  const chat2 = await this.#store.getChat(conversation.chatId);
4884
- if (!chat2) throw new Error(`chat "${conversation.chatId}" not found`);
4885
- if (chat2.userId !== conversation.userId) {
4886
- throw new Error(
4887
- `chat "${conversation.chatId}" belongs to user "${chat2.userId}", not "${conversation.userId}"`
4888
- );
4889
- }
4897
+ if (!chat2) throw new ConversationNotFoundError(conversation.chatId);
4898
+ assertConversationOwner(conversation, chat2.userId);
4890
4899
  return chat2.metadata;
4891
4900
  }
4892
4901
  async #updateConversationMetadata(conversation, update) {
4893
4902
  await this.#store.updateChat(conversation.chatId, (chat2) => {
4894
- if (chat2.userId !== conversation.userId) {
4895
- throw new Error(
4896
- `chat "${conversation.chatId}" belongs to user "${chat2.userId}", not "${conversation.userId}"`
4897
- );
4898
- }
4903
+ assertConversationOwner(conversation, chat2.userId);
4899
4904
  return { metadata: update(chat2.metadata) };
4900
4905
  });
4901
4906
  }