@deepagents/context 0.17.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // packages/context/src/lib/agent.ts
2
- import { groq } from "@ai-sdk/groq";
3
2
  import {
4
- NoSuchToolError,
5
3
  Output,
6
4
  convertToModelMessages,
7
5
  createUIMessageStream,
@@ -13,7 +11,7 @@ import {
13
11
  } from "ai";
14
12
  import chalk from "chalk";
15
13
  import "zod";
16
- import "@deepagents/agent";
14
+ import { createRepairToolCall } from "@deepagents/agent";
17
15
 
18
16
  // packages/context/src/lib/fragments.ts
19
17
  import { generateId } from "ai";
@@ -169,7 +167,7 @@ var Agent = class _Agent {
169
167
  stopWhen: stepCountIs(25),
170
168
  tools: this.#options.tools,
171
169
  experimental_context: contextVariables,
172
- experimental_repairToolCall: repairToolCall,
170
+ experimental_repairToolCall: createRepairToolCall(this.#options.model),
173
171
  toolChoice: this.#options.toolChoice,
174
172
  onStepFinish: (step) => {
175
173
  const toolCall = step.toolCalls.at(-1);
@@ -225,7 +223,7 @@ var Agent = class _Agent {
225
223
  model: this.#options.model,
226
224
  system: systemPrompt,
227
225
  messages: await convertToModelMessages(messages),
228
- experimental_repairToolCall: repairToolCall,
226
+ experimental_repairToolCall: createRepairToolCall(this.#options.model),
229
227
  stopWhen: stepCountIs(50),
230
228
  experimental_transform: config?.transform ?? smoothStream(),
231
229
  tools: this.#options.tools,
@@ -365,7 +363,7 @@ function structuredOutput(options) {
365
363
  system: systemPrompt,
366
364
  messages: await convertToModelMessages(messages),
367
365
  stopWhen: stepCountIs(25),
368
- experimental_repairToolCall: repairToolCall,
366
+ experimental_repairToolCall: createRepairToolCall(options.model),
369
367
  experimental_context: contextVariables,
370
368
  output: Output.object({ schema: options.schema }),
371
369
  tools: options.tools
@@ -387,7 +385,7 @@ function structuredOutput(options) {
387
385
  providerOptions: options.providerOptions,
388
386
  model: options.model,
389
387
  system: systemPrompt,
390
- experimental_repairToolCall: repairToolCall,
388
+ experimental_repairToolCall: createRepairToolCall(options.model),
391
389
  messages: await convertToModelMessages(messages),
392
390
  stopWhen: stepCountIs(50),
393
391
  experimental_transform: config?.transform ?? smoothStream(),
@@ -398,34 +396,6 @@ function structuredOutput(options) {
398
396
  }
399
397
  };
400
398
  }
401
- var repairToolCall = async ({
402
- toolCall,
403
- tools,
404
- inputSchema,
405
- error
406
- }) => {
407
- console.log(
408
- `Debug: ${chalk.yellow("RepairingToolCall")}: ${chalk.bgYellow(toolCall.toolName)}`,
409
- error.name,
410
- JSON.stringify(toolCall)
411
- );
412
- if (NoSuchToolError.isInstance(error)) {
413
- return null;
414
- }
415
- const tool = tools[toolCall.toolName];
416
- const { output } = await generateText({
417
- model: groq("openai/gpt-oss-20b"),
418
- output: Output.object({ schema: tool.inputSchema }),
419
- prompt: [
420
- `The model tried to call the tool "${toolCall.toolName}" with the following inputs:`,
421
- JSON.stringify(toolCall.input),
422
- `The tool accepts the following schema:`,
423
- JSON.stringify(inputSchema(toolCall)),
424
- "Please fix the inputs."
425
- ].join("\n")
426
- });
427
- return { ...toolCall, input: JSON.stringify(output) };
428
- };
429
399
  function writeText(writer, text) {
430
400
  const feedbackPartId = generateId2();
431
401
  writer.write({
@@ -1593,6 +1563,13 @@ var ContextEngine = class {
1593
1563
  get branch() {
1594
1564
  return this.#branchName;
1595
1565
  }
1566
+ /**
1567
+ * Get the current branch head message ID.
1568
+ * Returns undefined if no messages have been saved yet.
1569
+ */
1570
+ get headMessageId() {
1571
+ return this.#branch?.headMessageId ?? void 0;
1572
+ }
1596
1573
  /**
1597
1574
  * Get metadata for the current chat.
1598
1575
  * Returns null if the chat hasn't been initialized yet.
@@ -1699,7 +1676,7 @@ var ContextEngine = class {
1699
1676
  async save(options) {
1700
1677
  await this.#ensureInitialized();
1701
1678
  if (this.#pendingMessages.length === 0) {
1702
- return;
1679
+ return { headMessageId: this.#branch?.headMessageId ?? void 0 };
1703
1680
  }
1704
1681
  const shouldBranch = options?.branch ?? true;
1705
1682
  for (let i = 0; i < this.#pendingMessages.length; i++) {
@@ -1751,6 +1728,7 @@ var ContextEngine = class {
1751
1728
  await this.#store.updateBranchHead(this.#branch.id, parentId);
1752
1729
  this.#branch.headMessageId = parentId;
1753
1730
  this.#pendingMessages = [];
1731
+ return { headMessageId: this.#branch.headMessageId ?? void 0 };
1754
1732
  }
1755
1733
  /**
1756
1734
  * Resolve a lazy fragment by finding the appropriate ID.