@algolia/wizard 0.102.0 → 0.103.0-rc.217.756

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 (2) hide show
  1. package/dist/main.js +106 -43
  2. package/package.json +4 -4
package/dist/main.js CHANGED
@@ -1616,6 +1616,10 @@ async function clearWorkflowState(workflowId) {
1616
1616
  }
1617
1617
 
1618
1618
  // src/lib/modelProfiles.ts
1619
+ var MODEL_CAPABILITIES = {
1620
+ "claude-haiku-5-5": { forcedToolUse: true, lowestThinking: "disabled" },
1621
+ "claude-sonnet-5-5": { forcedToolUse: false, lowestThinking: "between_tools" }
1622
+ };
1619
1623
  var TOKENS_PER_MILLION = 1e6;
1620
1624
  var INITIAL_MODEL_ATTEMPT = 1;
1621
1625
  var NO_TOKENS = 0;
@@ -1627,57 +1631,57 @@ var IMPLEMENTATION_MAX_OUTPUT_TOKENS = 65536;
1627
1631
  var IMPLEMENTATION_MAX_STEPS = 48;
1628
1632
  var VALIDATION_MAX_OUTPUT_TOKENS = 8192;
1629
1633
  var VALIDATION_MAX_STEPS = 24;
1630
- var HAIKU_4_5_PRICES = {
1631
- input: 1,
1632
- output: 5,
1633
- cacheRead: 0.1,
1634
- cacheWrite: 1.25
1634
+ var HAIKU_5_5_PRICES = {
1635
+ input: 0.1,
1636
+ output: 0.5,
1637
+ cacheRead: 0.01,
1638
+ cacheWrite: 0.125
1635
1639
  };
1636
- var SONNET_5_PRICES = {
1640
+ var SONNET_5_5_PRICES = {
1637
1641
  input: 2,
1638
1642
  output: 10,
1639
- cacheRead: 0.2,
1643
+ cacheRead: 0.1,
1640
1644
  cacheWrite: 2.5
1641
1645
  };
1642
1646
  var MODEL_PROFILES = {
1643
1647
  quick: {
1644
- model: "claude-haiku-4-5",
1648
+ model: "claude-haiku-5-5",
1645
1649
  thinking: "disabled",
1646
1650
  maxOutputTokens: QUICK_MAX_OUTPUT_TOKENS,
1647
1651
  maxSteps: QUICK_MAX_STEPS,
1648
- prices: HAIKU_4_5_PRICES
1652
+ prices: HAIKU_5_5_PRICES
1649
1653
  },
1650
1654
  analysis: {
1651
- model: "claude-sonnet-5",
1655
+ model: "claude-sonnet-5-5",
1652
1656
  thinking: "adaptive",
1653
1657
  effort: "low",
1654
1658
  maxOutputTokens: ANALYSIS_MAX_OUTPUT_TOKENS,
1655
1659
  maxSteps: ANALYSIS_MAX_STEPS,
1656
- prices: SONNET_5_PRICES
1660
+ prices: SONNET_5_5_PRICES
1657
1661
  },
1658
1662
  implementation: {
1659
- model: "claude-sonnet-5",
1663
+ model: "claude-sonnet-5-5",
1660
1664
  thinking: "adaptive",
1661
1665
  effort: "medium",
1662
1666
  maxOutputTokens: IMPLEMENTATION_MAX_OUTPUT_TOKENS,
1663
1667
  maxSteps: IMPLEMENTATION_MAX_STEPS,
1664
- prices: SONNET_5_PRICES
1668
+ prices: SONNET_5_5_PRICES
1665
1669
  },
1666
1670
  implementationRetry: {
1667
- model: "claude-sonnet-5",
1671
+ model: "claude-sonnet-5-5",
1668
1672
  thinking: "adaptive",
1669
1673
  effort: "high",
1670
1674
  maxOutputTokens: IMPLEMENTATION_MAX_OUTPUT_TOKENS,
1671
1675
  maxSteps: IMPLEMENTATION_MAX_STEPS,
1672
- prices: SONNET_5_PRICES
1676
+ prices: SONNET_5_5_PRICES
1673
1677
  },
1674
1678
  validation: {
1675
- model: "claude-sonnet-5",
1679
+ model: "claude-sonnet-5-5",
1676
1680
  thinking: "adaptive",
1677
1681
  effort: "low",
1678
1682
  maxOutputTokens: VALIDATION_MAX_OUTPUT_TOKENS,
1679
1683
  maxSteps: VALIDATION_MAX_STEPS,
1680
- prices: SONNET_5_PRICES
1684
+ prices: SONNET_5_5_PRICES
1681
1685
  }
1682
1686
  };
1683
1687
  function getModelProfile(profileName) {
@@ -1690,6 +1694,14 @@ function providerOptionsForProfile(profileName) {
1690
1694
  ...profile.effort !== void 0 && { effort: profile.effort }
1691
1695
  };
1692
1696
  }
1697
+ function toolChoiceForProfile(profileName) {
1698
+ const { model } = getModelProfile(profileName);
1699
+ return MODEL_CAPABILITIES[model].forcedToolUse ? "required" : "auto";
1700
+ }
1701
+ function lowestThinkingForProfile(profileName) {
1702
+ const { model } = getModelProfile(profileName);
1703
+ return { type: MODEL_CAPABILITIES[model].lowestThinking };
1704
+ }
1693
1705
  function tokenCount(value = NO_TOKENS) {
1694
1706
  return value;
1695
1707
  }
@@ -1710,6 +1722,7 @@ function estimateModelCost(profileName, usage) {
1710
1722
  var COUNT_METRIC = 1;
1711
1723
  var GAUGE_METRIC = 3;
1712
1724
  var FIRST_ATTEMPT = 1;
1725
+ var NO_CONTINUATION = 0;
1713
1726
  var NO_TOKENS2 = 0;
1714
1727
  var NO_COST = 0;
1715
1728
  var AGENT_TELEMETRY_CONTEXT = {
@@ -1863,6 +1876,12 @@ function agentRunMetrics(event, values, tags) {
1863
1876
  type: COUNT_METRIC,
1864
1877
  tags: runTags
1865
1878
  },
1879
+ {
1880
+ name: "wizard.agent.continuation",
1881
+ value: Number((event.continuation ?? NO_CONTINUATION) > NO_CONTINUATION),
1882
+ type: COUNT_METRIC,
1883
+ tags: runTags
1884
+ },
1866
1885
  ...event.stepCount === void 0 ? [] : [
1867
1886
  {
1868
1887
  name: "wizard.agent.step_count",
@@ -1905,6 +1924,7 @@ function trackAgentRun(event) {
1905
1924
  effort: profile.effort ?? "none",
1906
1925
  thinking: profile.thinking,
1907
1926
  attempt: event.attempt,
1927
+ continuation: event.continuation,
1908
1928
  durationMs: event.durationMs,
1909
1929
  stepCount: event.stepCount,
1910
1930
  hitStepLimit: event.hitStepLimit,
@@ -2447,7 +2467,7 @@ async function ensureApplication(resumeAppId) {
2447
2467
  // package.json
2448
2468
  var package_default = {
2449
2469
  name: "@algolia/wizard",
2450
- version: "0.102.0",
2470
+ version: "0.103.0-rc.217.756",
2451
2471
  description: "Magically implement Algolia functionality in your codebase",
2452
2472
  type: "module",
2453
2473
  engines: {
@@ -2494,11 +2514,11 @@ var package_default = {
2494
2514
  vitest: "^4.1.11"
2495
2515
  },
2496
2516
  dependencies: {
2497
- "@ai-sdk/anthropic": "^3.0.118",
2498
- "@ai-sdk/openai-compatible": "^2.0.75",
2517
+ "@ai-sdk/anthropic": "^3.0.128",
2518
+ "@ai-sdk/openai-compatible": "^2.0.81",
2499
2519
  "@hono/node-server": "^2.0.10",
2500
2520
  "@segment/analytics-node": "^3.1.0",
2501
- ai: "^6.0.283",
2521
+ ai: "^6.0.302",
2502
2522
  "cross-keychain": "^1.1.0",
2503
2523
  dotenv: "^17.4.2",
2504
2524
  hono: "^4.13.8",
@@ -5418,6 +5438,10 @@ var MISSING_REPORT_STATUS_ERROR_MESSAGE = "Agent finished without calling report
5418
5438
  var MISSING_REPORT_USER_MESSAGE = "This step ran into a problem finishing. Run the wizard again to retry it.";
5419
5439
  var REPORT_STATUS_RETRIES = 2;
5420
5440
  var STEP_LIMIT_INSTRUCTION = "When reportStatus is the only tool available, you reached the step limit. This limit is not a failure, so do not report fail because of it: report status=success with the work done so far, and name the remaining work in the summary.";
5441
+ var TOOL_EVERY_TURN_INSTRUCTION = "Call at least one tool in every response. Do not reply with text only. The run ends only when you call reportStatus.";
5442
+ var ENDED_TURN_NUDGE = "Your last response did not call a tool. Continue the work with tools. When the work is done, call reportStatus.";
5443
+ var INITIAL_PROMPT = "Follow system instructions";
5444
+ var ENDED_TURN_CONTINUATIONS = 3;
5421
5445
  var RECENT_STEPS_LOGGED = 3;
5422
5446
  var LOGGED_CHARS = 300;
5423
5447
  var ATTEMPT_NUMBER_OFFSET = 1;
@@ -5455,6 +5479,13 @@ var MissingReportError = class extends Error {
5455
5479
  this.incompleteCause = incompleteCause;
5456
5480
  }
5457
5481
  };
5482
+ var EndedTurnError = class extends MissingReportError {
5483
+ continuation;
5484
+ constructor(continuation) {
5485
+ super(null);
5486
+ this.continuation = continuation;
5487
+ }
5488
+ };
5458
5489
  function incompleteCauseOf(stepCount, maxSteps, finishReason) {
5459
5490
  if (stepCount >= maxSteps) return "stepLimit";
5460
5491
  if (finishReason === "length") return "truncated";
@@ -5513,10 +5544,23 @@ function exhaustedError(kind, err) {
5513
5544
  }
5514
5545
  async function runAgent(req) {
5515
5546
  let retryReason = null;
5516
- for (let attempt = INITIAL_ATTEMPT; attempt <= REPORT_STATUS_RETRIES; attempt++) {
5547
+ let attempt = INITIAL_ATTEMPT;
5548
+ let continuation;
5549
+ let continuations = 0;
5550
+ for (; ; ) {
5517
5551
  try {
5518
- return await runAgentAttempt(req, attempt, retryReason);
5552
+ return await runAgentAttempt(req, attempt, retryReason, continuation);
5519
5553
  } catch (err) {
5554
+ continuation = void 0;
5555
+ if (err instanceof EndedTurnError && continuations < ENDED_TURN_CONTINUATIONS) {
5556
+ continuations++;
5557
+ continuation = err.continuation;
5558
+ logger.warn(
5559
+ { attempt: attempt + 1, continuations },
5560
+ "continuing runAgent after a turn ended without a tool call"
5561
+ );
5562
+ continue;
5563
+ }
5520
5564
  const kind = retryKind(err);
5521
5565
  if (!kind) throw err;
5522
5566
  if (attempt === REPORT_STATUS_RETRIES) throw exhaustedError(kind, err);
@@ -5525,19 +5569,23 @@ async function runAgent(req) {
5525
5569
  { attempt: attempt + 1, err },
5526
5570
  isMissingReportRetry(kind) ? "retrying runAgent after missing reportStatus" : "retrying runAgent after a transient provider error"
5527
5571
  );
5572
+ attempt++;
5528
5573
  }
5529
5574
  }
5530
- throw new Error("unreachable");
5531
5575
  }
5532
- async function runAgentAttempt(req, attempt, retryReason) {
5576
+ async function runAgentAttempt(req, attempt, retryReason, continuation) {
5533
5577
  const start = Date.now();
5534
5578
  const profileName = req.modelProfile ?? "implementation" /* implementation */;
5535
5579
  const profile = getModelProfile(profileName);
5536
5580
  const profileOptions = providerOptionsForProfile(profileName);
5581
+ const toolChoice = toolChoiceForProfile(profileName);
5537
5582
  const maxSteps = req.maxSteps ?? profile.maxSteps;
5583
+ const stepsUsed = continuation?.stepsUsed ?? 0;
5584
+ const stepsLeft = maxSteps - stepsUsed;
5538
5585
  const forceReport = retryReason === "missingReport";
5539
5586
  const incompleteReason = incompleteReasonOf(retryReason);
5540
- const modelOptions = forceReport ? { thinking: { type: "disabled" } } : profileOptions;
5587
+ const reportThinking = lowestThinkingForProfile(profileName);
5588
+ const modelOptions = forceReport ? { thinking: reportThinking, effort: void 0 } : profileOptions;
5541
5589
  logger.info(
5542
5590
  {
5543
5591
  startedAt: new Date(start).toISOString(),
@@ -5545,8 +5593,9 @@ async function runAgentAttempt(req, attempt, retryReason) {
5545
5593
  profile: profileName,
5546
5594
  model: profile.model,
5547
5595
  effort: forceReport ? void 0 : profile.effort,
5548
- thinking: forceReport ? "disabled" : profile.thinking,
5549
- retryReason
5596
+ thinking: forceReport ? reportThinking.type : profile.thinking,
5597
+ retryReason,
5598
+ stepsUsed
5550
5599
  },
5551
5600
  "runAgent started"
5552
5601
  );
@@ -5560,7 +5609,7 @@ async function runAgentAttempt(req, attempt, retryReason) {
5560
5609
  fetch: proxyFetch
5561
5610
  });
5562
5611
  const toolContext = req.toolContext ?? createToolContext();
5563
- if (attempt > INITIAL_ATTEMPT) resetToolCounts(toolContext);
5612
+ if (attempt > INITIAL_ATTEMPT && !continuation) resetToolCounts(toolContext);
5564
5613
  const readTools = ["readFile", "searchFiles", "listFiles"];
5565
5614
  const hasReadTools = !req.tools || req.tools.some((t) => readTools.includes(t));
5566
5615
  const instructions = [
@@ -5569,6 +5618,7 @@ async function runAgentAttempt(req, attempt, retryReason) {
5569
5618
  "When you need to read or search multiple files, issue those tool calls together in one step rather than one at a time."
5570
5619
  ] : [],
5571
5620
  "Call notifyUser whenever you start a new phase of work or your focus shifts (e.g. moving from reading code to writing files) \u2014 a short, plain-language, high-level update. Do not call it for every tool use.",
5621
+ ...toolChoice === "auto" ? [TOOL_EVERY_TURN_INSTRUCTION] : [],
5572
5622
  STEP_LIMIT_INSTRUCTION,
5573
5623
  // Last so a retry does not bust the cached tools+system prefix from
5574
5624
  // the first attempt. Inspect-and-continue, not start over: implement
@@ -5613,11 +5663,11 @@ async function runAgentAttempt(req, attempt, retryReason) {
5613
5663
  output: req.outputSchema,
5614
5664
  tools: req.tools
5615
5665
  }),
5616
- toolChoice: "required",
5617
- stopWhen: [reportAccepted, stepCountIs(maxSteps)],
5666
+ toolChoice,
5667
+ stopWhen: [reportAccepted, stepCountIs(stepsLeft)],
5618
5668
  prepareStep: ({ stepNumber, messages }) => ({
5619
5669
  messages: withCachedHistory(messages),
5620
- ...stepNumber >= maxSteps - 1 && {
5670
+ ...stepNumber >= stepsLeft - 1 && {
5621
5671
  activeTools: ["reportStatus"]
5622
5672
  }
5623
5673
  }),
@@ -5625,9 +5675,11 @@ async function runAgentAttempt(req, attempt, retryReason) {
5625
5675
  ...{ onError: () => {
5626
5676
  } }
5627
5677
  });
5628
- const stream = await agent.stream({
5629
- prompt: "Follow system instructions"
5630
- });
5678
+ const prompt = continuation ? [
5679
+ ...continuation.messages,
5680
+ { role: "user", content: ENDED_TURN_NUDGE }
5681
+ ] : [{ role: "user", content: INITIAL_PROMPT }];
5682
+ const stream = await agent.stream({ prompt });
5631
5683
  let chunks = [];
5632
5684
  const chunkLimit = 5;
5633
5685
  let streamError;
@@ -5659,16 +5711,18 @@ async function runAgentAttempt(req, attempt, retryReason) {
5659
5711
  const usage = await stream.totalUsage;
5660
5712
  const steps = await stream.steps;
5661
5713
  const stepCount = steps.length;
5662
- const hitStepLimit = stepCount >= maxSteps;
5714
+ const totalSteps = stepsUsed + stepCount;
5715
+ const hitStepLimit = totalSteps >= maxSteps;
5663
5716
  const lastStep = steps[steps.length - 1];
5664
5717
  const finishReason = lastStep?.finishReason;
5665
5718
  trackAgentRun({
5666
5719
  operation: req.operation,
5667
5720
  profile: profileName,
5668
5721
  attempt: attempt + ATTEMPT_NUMBER_OFFSET,
5722
+ continuation: continuation?.number ?? 0,
5669
5723
  durationMs: end - start,
5670
5724
  usage,
5671
- stepCount,
5725
+ stepCount: totalSteps,
5672
5726
  hitStepLimit,
5673
5727
  finishReason
5674
5728
  });
@@ -5680,7 +5734,7 @@ async function runAgentAttempt(req, attempt, retryReason) {
5680
5734
  profile: profileName,
5681
5735
  model: profile.model,
5682
5736
  usage,
5683
- stepCount,
5737
+ stepCount: totalSteps,
5684
5738
  maxSteps,
5685
5739
  hitStepLimit,
5686
5740
  finishReason
@@ -5707,8 +5761,17 @@ async function runAgentAttempt(req, attempt, retryReason) {
5707
5761
  },
5708
5762
  "Agent finished without calling reportStatus"
5709
5763
  );
5764
+ const endedTurn = toolChoice === "auto" && finishReason === "stop" && !lastStep?.toolCalls?.length && !hitStepLimit;
5765
+ if (endedTurn) {
5766
+ const { messages } = await stream.response;
5767
+ throw new EndedTurnError({
5768
+ messages: [...prompt, ...messages],
5769
+ stepsUsed: totalSteps,
5770
+ number: (continuation?.number ?? 0) + 1
5771
+ });
5772
+ }
5710
5773
  throw new MissingReportError(
5711
- incompleteCauseOf(stepCount, maxSteps, finishReason)
5774
+ incompleteCauseOf(totalSteps, maxSteps, finishReason)
5712
5775
  );
5713
5776
  }
5714
5777
  const result = report.output;
@@ -10073,7 +10136,7 @@ async function resetProjectState() {
10073
10136
  // package.json with { type: 'json' }
10074
10137
  var package_default2 = {
10075
10138
  name: "@algolia/wizard",
10076
- version: "0.102.0",
10139
+ version: "0.103.0-rc.217.756",
10077
10140
  description: "Magically implement Algolia functionality in your codebase",
10078
10141
  type: "module",
10079
10142
  engines: {
@@ -10120,11 +10183,11 @@ var package_default2 = {
10120
10183
  vitest: "^4.1.11"
10121
10184
  },
10122
10185
  dependencies: {
10123
- "@ai-sdk/anthropic": "^3.0.118",
10124
- "@ai-sdk/openai-compatible": "^2.0.75",
10186
+ "@ai-sdk/anthropic": "^3.0.128",
10187
+ "@ai-sdk/openai-compatible": "^2.0.81",
10125
10188
  "@hono/node-server": "^2.0.10",
10126
10189
  "@segment/analytics-node": "^3.1.0",
10127
- ai: "^6.0.283",
10190
+ ai: "^6.0.302",
10128
10191
  "cross-keychain": "^1.1.0",
10129
10192
  dotenv: "^17.4.2",
10130
10193
  hono: "^4.13.8",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.102.0",
3
+ "version": "0.103.0-rc.217.756",
4
4
  "description": "Magically implement Algolia functionality in your codebase",
5
5
  "type": "module",
6
6
  "engines": {
@@ -47,11 +47,11 @@
47
47
  "vitest": "^4.1.11"
48
48
  },
49
49
  "dependencies": {
50
- "@ai-sdk/anthropic": "^3.0.118",
51
- "@ai-sdk/openai-compatible": "^2.0.75",
50
+ "@ai-sdk/anthropic": "^3.0.128",
51
+ "@ai-sdk/openai-compatible": "^2.0.81",
52
52
  "@hono/node-server": "^2.0.10",
53
53
  "@segment/analytics-node": "^3.1.0",
54
- "ai": "^6.0.283",
54
+ "ai": "^6.0.302",
55
55
  "cross-keychain": "^1.1.0",
56
56
  "dotenv": "^17.4.2",
57
57
  "hono": "^4.13.8",