@deepagents/context 0.20.0 → 0.22.0

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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './lib/agent.ts';
2
+ export * from './lib/chat.ts';
2
3
  export * from './lib/codec.ts';
3
4
  export * from './lib/engine.ts';
4
5
  export * from './lib/estimate.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8CAA8C,CAAC;AAC7D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,sCAAsC,CAAC;AACrD,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8CAA8C,CAAC;AAC7D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,sCAAsC,CAAC;AACrD,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -120,9 +120,11 @@ var Agent = class _Agent {
120
120
  #options;
121
121
  #guardrails = [];
122
122
  tools;
123
+ context;
123
124
  constructor(options) {
124
125
  this.#options = options;
125
126
  this.tools = options.tools || {};
127
+ this.context = options.context;
126
128
  this.#guardrails = options.guardrails || [];
127
129
  }
128
130
  async generate(contextVariables, config) {
@@ -190,17 +192,25 @@ var Agent = class _Agent {
190
192
  * Create a raw stream without guardrail processing.
191
193
  */
192
194
  async #createRawStream(contextVariables, config) {
193
- const { messages, systemPrompt } = await this.#options.context.resolve({
195
+ const context = this.#options.context;
196
+ if (!context) {
197
+ throw new Error(`Agent ${this.#options.name} is missing a context.`);
198
+ }
199
+ const model = this.#options.model;
200
+ if (!model) {
201
+ throw new Error(`Agent ${this.#options.name} is missing a model.`);
202
+ }
203
+ const { messages, systemPrompt } = await context.resolve({
194
204
  renderer: new XmlRenderer()
195
205
  });
196
206
  const runId = generateId2();
197
207
  return streamText({
198
208
  abortSignal: config?.abortSignal,
199
209
  providerOptions: this.#options.providerOptions,
200
- model: this.#options.model,
210
+ model,
201
211
  system: systemPrompt,
202
212
  messages: await convertToModelMessages(messages),
203
- experimental_repairToolCall: createRepairToolCall(this.#options.model),
213
+ experimental_repairToolCall: createRepairToolCall(model),
204
214
  stopWhen: stepCountIs(50),
205
215
  experimental_transform: config?.transform ?? smoothStream(),
206
216
  tools: this.#options.tools,
@@ -227,6 +237,9 @@ var Agent = class _Agent {
227
237
  #wrapWithGuardrails(result, contextVariables, config) {
228
238
  const maxRetries = config?.maxRetries ?? this.#options.maxGuardrailRetries ?? 3;
229
239
  const context = this.#options.context;
240
+ if (!context) {
241
+ throw new Error(`Agent ${this.#options.name} is missing a context.`);
242
+ }
230
243
  const originalToUIMessageStream = result.toUIMessageStream.bind(result);
231
244
  result.toUIMessageStream = (options) => {
232
245
  return createUIMessageStream({
@@ -390,6 +403,101 @@ function writeText(writer, text) {
390
403
  });
391
404
  }
392
405
 
406
+ // packages/context/src/lib/chat.ts
407
+ import {
408
+ APICallError,
409
+ InvalidToolInputError,
410
+ NoSuchToolError,
411
+ ToolCallRepairError,
412
+ createUIMessageStream as createUIMessageStream2,
413
+ generateId as generateId3
414
+ } from "ai";
415
+ async function chat(agent2, messages, options) {
416
+ const context = agent2.context;
417
+ if (!context) {
418
+ throw new Error(
419
+ "Agent is missing a context. Provide context when creating the agent."
420
+ );
421
+ }
422
+ if (messages.length === 0) {
423
+ throw new Error("messages must not be empty");
424
+ }
425
+ const lastMessage = messages[messages.length - 1];
426
+ let assistantMsgId;
427
+ if (lastMessage.role === "assistant") {
428
+ context.set(message(lastMessage));
429
+ await context.save({ branch: false });
430
+ assistantMsgId = lastMessage.id;
431
+ } else {
432
+ context.set(message(lastMessage));
433
+ await context.save();
434
+ assistantMsgId = options?.generateMessageId?.() ?? generateId3();
435
+ }
436
+ const streamContextVariables = options?.contextVariables === void 0 ? {} : options.contextVariables;
437
+ const result = await agent2.stream(streamContextVariables, {
438
+ transform: options?.transform
439
+ });
440
+ const uiStream = result.toUIMessageStream({
441
+ onError: options?.onError ?? formatChatError,
442
+ sendStart: true,
443
+ sendFinish: true,
444
+ sendReasoning: true,
445
+ sendSources: true,
446
+ originalMessages: messages,
447
+ generateMessageId: () => assistantMsgId,
448
+ messageMetadata: options?.messageMetadata
449
+ });
450
+ return createUIMessageStream2({
451
+ originalMessages: messages,
452
+ generateId: () => assistantMsgId,
453
+ onStepFinish: async ({ responseMessage }) => {
454
+ const normalizedMessage = {
455
+ ...responseMessage,
456
+ id: assistantMsgId
457
+ };
458
+ context.set(assistant(normalizedMessage));
459
+ await context.save({ branch: false });
460
+ },
461
+ onFinish: async ({ responseMessage }) => {
462
+ const normalizedMessage = {
463
+ ...responseMessage,
464
+ id: assistantMsgId
465
+ };
466
+ const finalMetadata = await options?.finalAssistantMetadata?.(normalizedMessage);
467
+ const finalMessage = finalMetadata === void 0 ? normalizedMessage : {
468
+ ...normalizedMessage,
469
+ metadata: {
470
+ ...normalizedMessage.metadata ?? {},
471
+ ...finalMetadata
472
+ }
473
+ };
474
+ context.set(assistant(finalMessage));
475
+ await context.save({ branch: false });
476
+ const totalUsage = await result.totalUsage;
477
+ await context.trackUsage(totalUsage);
478
+ },
479
+ execute: async ({ writer }) => {
480
+ writer.merge(uiStream);
481
+ }
482
+ });
483
+ }
484
+ function formatChatError(error) {
485
+ if (NoSuchToolError.isInstance(error)) {
486
+ return "The model tried to call an unknown tool.";
487
+ }
488
+ if (InvalidToolInputError.isInstance(error)) {
489
+ return "The model called a tool with invalid arguments.";
490
+ }
491
+ if (ToolCallRepairError.isInstance(error)) {
492
+ return "The model tried to call a tool with invalid arguments, but it was repaired.";
493
+ }
494
+ if (APICallError.isInstance(error)) {
495
+ console.error("Upstream API call failed:", error);
496
+ return `Upstream API call failed with status ${error.statusCode}: ${error.message}`;
497
+ }
498
+ return JSON.stringify(error);
499
+ }
500
+
393
501
  // packages/context/src/lib/engine.ts
394
502
  import { mergeWith } from "lodash-es";
395
503
 
@@ -2256,7 +2364,7 @@ function policy(input) {
2256
2364
  }
2257
2365
 
2258
2366
  // packages/context/src/lib/fragments/message/user.ts
2259
- import { generateId as generateId3 } from "ai";
2367
+ import { generateId as generateId4 } from "ai";
2260
2368
  var SYSTEM_REMINDER_OPEN_TAG = "<system-reminder>";
2261
2369
  var SYSTEM_REMINDER_CLOSE_TAG = "</system-reminder>";
2262
2370
  function getReminderRanges(metadata) {
@@ -2288,6 +2396,43 @@ function stripTextByRanges(text, ranges) {
2288
2396
  output += text.slice(cursor);
2289
2397
  return output.trimEnd();
2290
2398
  }
2399
+ function stripReminders(message2) {
2400
+ const reminderRanges = getReminderRanges(
2401
+ isRecord(message2.metadata) ? message2.metadata : void 0
2402
+ );
2403
+ const rangesByPartIndex = /* @__PURE__ */ new Map();
2404
+ for (const range of reminderRanges) {
2405
+ const partRanges = rangesByPartIndex.get(range.partIndex) ?? [];
2406
+ partRanges.push({ start: range.start, end: range.end });
2407
+ rangesByPartIndex.set(range.partIndex, partRanges);
2408
+ }
2409
+ const strippedParts = message2.parts.flatMap((part, partIndex) => {
2410
+ const clonedPart = { ...part };
2411
+ const ranges = rangesByPartIndex.get(partIndex);
2412
+ if (clonedPart.type !== "text" || ranges === void 0) {
2413
+ return [clonedPart];
2414
+ }
2415
+ const strippedText = stripTextByRanges(clonedPart.text, ranges);
2416
+ if (strippedText.length === 0) {
2417
+ return [];
2418
+ }
2419
+ return [{ ...clonedPart, text: strippedText }];
2420
+ });
2421
+ const nextMessage = {
2422
+ ...message2,
2423
+ parts: strippedParts
2424
+ };
2425
+ if (isRecord(message2.metadata)) {
2426
+ const metadata = { ...message2.metadata };
2427
+ delete metadata.reminders;
2428
+ if (Object.keys(metadata).length > 0) {
2429
+ nextMessage.metadata = metadata;
2430
+ } else {
2431
+ delete nextMessage.metadata;
2432
+ }
2433
+ }
2434
+ return nextMessage;
2435
+ }
2291
2436
  function isRecord(value) {
2292
2437
  return typeof value === "object" && value !== null && !Array.isArray(value);
2293
2438
  }
@@ -2330,7 +2475,7 @@ function applyInlineReminder(message2, value) {
2330
2475
  const updatedText = `${textPart.text}${reminderText}`;
2331
2476
  message2.parts[partIndex] = { ...textPart, text: updatedText };
2332
2477
  return {
2333
- id: generateId3(),
2478
+ id: generateId4(),
2334
2479
  text: value,
2335
2480
  partIndex,
2336
2481
  start,
@@ -2343,7 +2488,7 @@ function applyPartReminder(message2, value) {
2343
2488
  message2.parts.push(part);
2344
2489
  const partIndex = message2.parts.length - 1;
2345
2490
  return {
2346
- id: generateId3(),
2491
+ id: generateId4(),
2347
2492
  text: value,
2348
2493
  partIndex,
2349
2494
  start: 0,
@@ -2360,7 +2505,7 @@ function reminder(text, options) {
2360
2505
  }
2361
2506
  function user(content, ...reminders) {
2362
2507
  const message2 = typeof content === "string" ? {
2363
- id: generateId3(),
2508
+ id: generateId4(),
2364
2509
  role: "user",
2365
2510
  parts: [{ type: "text", text: content }]
2366
2511
  } : { ...content, role: "user", parts: [...content.parts] };
@@ -3519,22 +3664,22 @@ var SqliteContextStore = class extends ContextStore {
3519
3664
  // ==========================================================================
3520
3665
  // Chat Operations
3521
3666
  // ==========================================================================
3522
- async createChat(chat) {
3667
+ async createChat(chat2) {
3523
3668
  return this.#useTransaction(() => {
3524
3669
  const row = this.#db.prepare(
3525
3670
  `INSERT INTO chats (id, userId, title, metadata)
3526
3671
  VALUES (?, ?, ?, ?)
3527
3672
  RETURNING *`
3528
3673
  ).get(
3529
- chat.id,
3530
- chat.userId,
3531
- chat.title ?? null,
3532
- chat.metadata ? JSON.stringify(chat.metadata) : null
3674
+ chat2.id,
3675
+ chat2.userId,
3676
+ chat2.title ?? null,
3677
+ chat2.metadata ? JSON.stringify(chat2.metadata) : null
3533
3678
  );
3534
3679
  this.#db.prepare(
3535
3680
  `INSERT INTO branches (id, chatId, name, headMessageId, isActive, createdAt)
3536
3681
  VALUES (?, ?, 'main', NULL, 1, ?)`
3537
- ).run(crypto.randomUUID(), chat.id, Date.now());
3682
+ ).run(crypto.randomUUID(), chat2.id, Date.now());
3538
3683
  return {
3539
3684
  id: row.id,
3540
3685
  userId: row.userId,
@@ -3545,7 +3690,7 @@ var SqliteContextStore = class extends ContextStore {
3545
3690
  };
3546
3691
  });
3547
3692
  }
3548
- async upsertChat(chat) {
3693
+ async upsertChat(chat2) {
3549
3694
  return this.#useTransaction(() => {
3550
3695
  const row = this.#db.prepare(
3551
3696
  `INSERT INTO chats (id, userId, title, metadata)
@@ -3553,15 +3698,15 @@ var SqliteContextStore = class extends ContextStore {
3553
3698
  ON CONFLICT(id) DO UPDATE SET id = excluded.id
3554
3699
  RETURNING *`
3555
3700
  ).get(
3556
- chat.id,
3557
- chat.userId,
3558
- chat.title ?? null,
3559
- chat.metadata ? JSON.stringify(chat.metadata) : null
3701
+ chat2.id,
3702
+ chat2.userId,
3703
+ chat2.title ?? null,
3704
+ chat2.metadata ? JSON.stringify(chat2.metadata) : null
3560
3705
  );
3561
3706
  this.#db.prepare(
3562
3707
  `INSERT OR IGNORE INTO branches (id, chatId, name, headMessageId, isActive, createdAt)
3563
3708
  VALUES (?, ?, 'main', NULL, 1, ?)`
3564
- ).run(crypto.randomUUID(), chat.id, Date.now());
3709
+ ).run(crypto.randomUUID(), chat2.id, Date.now());
3565
3710
  return {
3566
3711
  id: row.id,
3567
3712
  userId: row.userId,
@@ -3757,8 +3902,8 @@ var SqliteContextStore = class extends ContextStore {
3757
3902
  return row.hasChildren === 1;
3758
3903
  }
3759
3904
  async getMessages(chatId) {
3760
- const chat = await this.getChat(chatId);
3761
- if (!chat) {
3905
+ const chat2 = await this.getChat(chatId);
3906
+ if (!chat2) {
3762
3907
  throw new Error(`Chat "${chatId}" not found`);
3763
3908
  }
3764
3909
  const activeBranch = await this.getActiveBranch(chatId);
@@ -4182,24 +4327,24 @@ var PostgresContextStore = class _PostgresContextStore extends ContextStore {
4182
4327
  // ==========================================================================
4183
4328
  // Chat Operations
4184
4329
  // ==========================================================================
4185
- async createChat(chat) {
4330
+ async createChat(chat2) {
4186
4331
  return this.#useTransaction(async (client) => {
4187
4332
  const result = await client.query(
4188
4333
  `INSERT INTO ${this.#t("chats")} (id, userId, title, metadata)
4189
4334
  VALUES ($1, $2, $3, $4)
4190
4335
  RETURNING *`,
4191
4336
  [
4192
- chat.id,
4193
- chat.userId,
4194
- chat.title ?? null,
4195
- chat.metadata ? JSON.stringify(chat.metadata) : null
4337
+ chat2.id,
4338
+ chat2.userId,
4339
+ chat2.title ?? null,
4340
+ chat2.metadata ? JSON.stringify(chat2.metadata) : null
4196
4341
  ]
4197
4342
  );
4198
4343
  const row = result.rows[0];
4199
4344
  await client.query(
4200
4345
  `INSERT INTO ${this.#t("branches")} (id, chatId, name, headMessageId, isActive, createdAt)
4201
4346
  VALUES ($1, $2, 'main', NULL, TRUE, $3)`,
4202
- [crypto.randomUUID(), chat.id, Date.now()]
4347
+ [crypto.randomUUID(), chat2.id, Date.now()]
4203
4348
  );
4204
4349
  return {
4205
4350
  id: row.id,
@@ -4211,7 +4356,7 @@ var PostgresContextStore = class _PostgresContextStore extends ContextStore {
4211
4356
  };
4212
4357
  });
4213
4358
  }
4214
- async upsertChat(chat) {
4359
+ async upsertChat(chat2) {
4215
4360
  return this.#useTransaction(async (client) => {
4216
4361
  const result = await client.query(
4217
4362
  `INSERT INTO ${this.#t("chats")} (id, userId, title, metadata)
@@ -4219,10 +4364,10 @@ var PostgresContextStore = class _PostgresContextStore extends ContextStore {
4219
4364
  ON CONFLICT(id) DO UPDATE SET id = EXCLUDED.id
4220
4365
  RETURNING *`,
4221
4366
  [
4222
- chat.id,
4223
- chat.userId,
4224
- chat.title ?? null,
4225
- chat.metadata ? JSON.stringify(chat.metadata) : null
4367
+ chat2.id,
4368
+ chat2.userId,
4369
+ chat2.title ?? null,
4370
+ chat2.metadata ? JSON.stringify(chat2.metadata) : null
4226
4371
  ]
4227
4372
  );
4228
4373
  const row = result.rows[0];
@@ -4230,7 +4375,7 @@ var PostgresContextStore = class _PostgresContextStore extends ContextStore {
4230
4375
  `INSERT INTO ${this.#t("branches")} (id, chatId, name, headMessageId, isActive, createdAt)
4231
4376
  VALUES ($1, $2, 'main', NULL, TRUE, $3)
4232
4377
  ON CONFLICT(chatId, name) DO NOTHING`,
4233
- [crypto.randomUUID(), chat.id, Date.now()]
4378
+ [crypto.randomUUID(), chat2.id, Date.now()]
4234
4379
  );
4235
4380
  return {
4236
4381
  id: row.id,
@@ -4436,8 +4581,8 @@ var PostgresContextStore = class _PostgresContextStore extends ContextStore {
4436
4581
  return rows[0].exists;
4437
4582
  }
4438
4583
  async getMessages(chatId) {
4439
- const chat = await this.getChat(chatId);
4440
- if (!chat) {
4584
+ const chat2 = await this.getChat(chatId);
4585
+ if (!chat2) {
4441
4586
  throw new Error(`Chat "${chatId}" not found`);
4442
4587
  }
4443
4588
  const activeBranch = await this.getActiveBranch(chatId);
@@ -4941,17 +5086,17 @@ var SqlServerContextStore = class _SqlServerContextStore extends ContextStore {
4941
5086
  // ==========================================================================
4942
5087
  // Chat Operations
4943
5088
  // ==========================================================================
4944
- async createChat(chat) {
5089
+ async createChat(chat2) {
4945
5090
  return this.#useTransaction(async (transaction) => {
4946
5091
  const mssql = _SqlServerContextStore.#requireMssql();
4947
5092
  const request = transaction.request();
4948
- request.input("p0", mssql.NVarChar, chat.id);
4949
- request.input("p1", mssql.NVarChar, chat.userId);
4950
- request.input("p2", mssql.NVarChar, chat.title ?? null);
5093
+ request.input("p0", mssql.NVarChar, chat2.id);
5094
+ request.input("p1", mssql.NVarChar, chat2.userId);
5095
+ request.input("p2", mssql.NVarChar, chat2.title ?? null);
4951
5096
  request.input(
4952
5097
  "p3",
4953
5098
  mssql.NVarChar,
4954
- chat.metadata ? JSON.stringify(chat.metadata) : null
5099
+ chat2.metadata ? JSON.stringify(chat2.metadata) : null
4955
5100
  );
4956
5101
  const result = await request.query(`
4957
5102
  INSERT INTO ${this.#t("chats")} (id, userId, title, metadata)
@@ -4961,7 +5106,7 @@ var SqlServerContextStore = class _SqlServerContextStore extends ContextStore {
4961
5106
  const row = result.recordset[0];
4962
5107
  const branchRequest = transaction.request();
4963
5108
  branchRequest.input("p0", mssql.NVarChar, crypto.randomUUID());
4964
- branchRequest.input("p1", mssql.NVarChar, chat.id);
5109
+ branchRequest.input("p1", mssql.NVarChar, chat2.id);
4965
5110
  branchRequest.input("p2", mssql.BigInt, Date.now());
4966
5111
  await branchRequest.query(`
4967
5112
  INSERT INTO ${this.#t("branches")} (id, chatId, name, headMessageId, isActive, createdAt)
@@ -4977,17 +5122,17 @@ var SqlServerContextStore = class _SqlServerContextStore extends ContextStore {
4977
5122
  };
4978
5123
  });
4979
5124
  }
4980
- async upsertChat(chat) {
5125
+ async upsertChat(chat2) {
4981
5126
  return this.#useTransaction(async (transaction) => {
4982
5127
  const mssql = _SqlServerContextStore.#requireMssql();
4983
5128
  const request = transaction.request();
4984
- request.input("p0", mssql.NVarChar, chat.id);
4985
- request.input("p1", mssql.NVarChar, chat.userId);
4986
- request.input("p2", mssql.NVarChar, chat.title ?? null);
5129
+ request.input("p0", mssql.NVarChar, chat2.id);
5130
+ request.input("p1", mssql.NVarChar, chat2.userId);
5131
+ request.input("p2", mssql.NVarChar, chat2.title ?? null);
4987
5132
  request.input(
4988
5133
  "p3",
4989
5134
  mssql.NVarChar,
4990
- chat.metadata ? JSON.stringify(chat.metadata) : null
5135
+ chat2.metadata ? JSON.stringify(chat2.metadata) : null
4991
5136
  );
4992
5137
  request.input("p4", mssql.BigInt, BigInt(Date.now()));
4993
5138
  const result = await request.query(`
@@ -5004,7 +5149,7 @@ var SqlServerContextStore = class _SqlServerContextStore extends ContextStore {
5004
5149
  const row = result.recordset[0];
5005
5150
  const branchRequest = transaction.request();
5006
5151
  branchRequest.input("p0", mssql.NVarChar, crypto.randomUUID());
5007
- branchRequest.input("p1", mssql.NVarChar, chat.id);
5152
+ branchRequest.input("p1", mssql.NVarChar, chat2.id);
5008
5153
  branchRequest.input("p2", mssql.BigInt, Date.now());
5009
5154
  await branchRequest.query(`
5010
5155
  IF NOT EXISTS (SELECT 1 FROM ${this.#t("branches")} WHERE chatId = @p1 AND name = 'main')
@@ -5225,8 +5370,8 @@ var SqlServerContextStore = class _SqlServerContextStore extends ContextStore {
5225
5370
  return rows[0].hasChildren === 1;
5226
5371
  }
5227
5372
  async getMessages(chatId) {
5228
- const chat = await this.getChat(chatId);
5229
- if (!chat) {
5373
+ const chat2 = await this.getChat(chatId);
5374
+ if (!chat2) {
5230
5375
  throw new Error(`Chat "${chatId}" not found`);
5231
5376
  }
5232
5377
  const activeBranch = await this.getActiveBranch(chatId);
@@ -5941,7 +6086,7 @@ var SqliteStreamStore = class extends StreamStore {
5941
6086
  };
5942
6087
 
5943
6088
  // packages/context/src/lib/stream/stream-manager.ts
5944
- import { createUIMessageStream as createUIMessageStream2 } from "ai";
6089
+ import { createUIMessageStream as createUIMessageStream3 } from "ai";
5945
6090
  import { setTimeout } from "node:timers/promises";
5946
6091
  function isTerminal(status) {
5947
6092
  return status !== "queued" && status !== "running";
@@ -6022,7 +6167,7 @@ var StreamManager = class {
6022
6167
  }
6023
6168
  })();
6024
6169
  let pw;
6025
- const sink = createUIMessageStream2({
6170
+ const sink = createUIMessageStream3({
6026
6171
  execute: async ({ writer }) => {
6027
6172
  pw = await persistedWriter({
6028
6173
  writer,
@@ -6339,6 +6484,7 @@ export {
6339
6484
  analogy,
6340
6485
  assistant,
6341
6486
  assistantText,
6487
+ chat,
6342
6488
  clarification,
6343
6489
  correction,
6344
6490
  createAdaptivePollingState,
@@ -6387,6 +6533,7 @@ export {
6387
6533
  skills,
6388
6534
  soul,
6389
6535
  stop,
6536
+ stripReminders,
6390
6537
  stripTextByRanges,
6391
6538
  structuredOutput,
6392
6539
  styleGuide,