@algolia/wizard 0.101.0 → 0.103.0-rc.217.754

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 +120 -46
  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
  }
@@ -2447,7 +2459,7 @@ async function ensureApplication(resumeAppId) {
2447
2459
  // package.json
2448
2460
  var package_default = {
2449
2461
  name: "@algolia/wizard",
2450
- version: "0.101.0",
2462
+ version: "0.103.0-rc.217.754",
2451
2463
  description: "Magically implement Algolia functionality in your codebase",
2452
2464
  type: "module",
2453
2465
  engines: {
@@ -2494,11 +2506,11 @@ var package_default = {
2494
2506
  vitest: "^4.1.11"
2495
2507
  },
2496
2508
  dependencies: {
2497
- "@ai-sdk/anthropic": "^3.0.118",
2498
- "@ai-sdk/openai-compatible": "^2.0.75",
2509
+ "@ai-sdk/anthropic": "^3.0.128",
2510
+ "@ai-sdk/openai-compatible": "^2.0.81",
2499
2511
  "@hono/node-server": "^2.0.10",
2500
2512
  "@segment/analytics-node": "^3.1.0",
2501
- ai: "^6.0.283",
2513
+ ai: "^6.0.302",
2502
2514
  "cross-keychain": "^1.1.0",
2503
2515
  dotenv: "^17.4.2",
2504
2516
  hono: "^4.13.8",
@@ -3075,7 +3087,6 @@ var selectIndexStep = async (ctx) => {
3075
3087
  // src/lib/agent.ts
3076
3088
  import {
3077
3089
  ToolLoopAgent,
3078
- hasToolCall,
3079
3090
  Output as Output3,
3080
3091
  APICallError,
3081
3092
  NoOutputGeneratedError,
@@ -3289,6 +3300,19 @@ function changeDirectoryTool(ctx) {
3289
3300
  // src/lib/tools/reportStatus.ts
3290
3301
  import { tool as tool3 } from "ai";
3291
3302
  import z8 from "zod";
3303
+ var PLACEHOLDER_REPORT_REFUSAL = 'Refused: reportStatus got the placeholder text "placeholder" instead of a real result. The task is not finished. Continue the task, then call reportStatus with the real status, reason, and output.';
3304
+ var PLACEHOLDER_VALUE = /^\s*placeholder\s*$/i;
3305
+ function isPlaceholder(value) {
3306
+ return typeof value === "string" && PLACEHOLDER_VALUE.test(value);
3307
+ }
3308
+ function hasPlaceholder(reason, output) {
3309
+ if (isPlaceholder(reason)) return true;
3310
+ if (typeof output !== "object" || output === null) return false;
3311
+ return Object.values(output).some(isPlaceholder);
3312
+ }
3313
+ function isAcceptedReport(result) {
3314
+ return typeof result === "object" && result !== null && "status" in result && !("rejected" in result);
3315
+ }
3292
3316
  function reportStatusTool(output) {
3293
3317
  return tool3({
3294
3318
  description: "Report the status of your execution. Return a reason in case of failure.",
@@ -3298,6 +3322,10 @@ function reportStatusTool(output) {
3298
3322
  output
3299
3323
  }),
3300
3324
  execute: async ({ status, reason, output: output2 }) => {
3325
+ if (hasPlaceholder(reason, output2)) {
3326
+ logger.warn({ status, reason }, "reportStatus: refused a placeholder report");
3327
+ return { rejected: true, message: PLACEHOLDER_REPORT_REFUSAL };
3328
+ }
3301
3329
  logger.info({ status, reason }, "called reportStatus tool");
3302
3330
  return { status, reason, output: output2 };
3303
3331
  }
@@ -5402,6 +5430,10 @@ var MISSING_REPORT_STATUS_ERROR_MESSAGE = "Agent finished without calling report
5402
5430
  var MISSING_REPORT_USER_MESSAGE = "This step ran into a problem finishing. Run the wizard again to retry it.";
5403
5431
  var REPORT_STATUS_RETRIES = 2;
5404
5432
  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.";
5433
+ 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.";
5434
+ var ENDED_TURN_NUDGE = "Your last response did not call a tool. Continue the work with tools. When the work is done, call reportStatus.";
5435
+ var INITIAL_PROMPT = "Follow system instructions";
5436
+ var ENDED_TURN_CONTINUATIONS = 3;
5405
5437
  var RECENT_STEPS_LOGGED = 3;
5406
5438
  var LOGGED_CHARS = 300;
5407
5439
  var ATTEMPT_NUMBER_OFFSET = 1;
@@ -5439,6 +5471,13 @@ var MissingReportError = class extends Error {
5439
5471
  this.incompleteCause = incompleteCause;
5440
5472
  }
5441
5473
  };
5474
+ var EndedTurnError = class extends MissingReportError {
5475
+ continuation;
5476
+ constructor(continuation) {
5477
+ super(null);
5478
+ this.continuation = continuation;
5479
+ }
5480
+ };
5442
5481
  function incompleteCauseOf(stepCount, maxSteps, finishReason) {
5443
5482
  if (stepCount >= maxSteps) return "stepLimit";
5444
5483
  if (finishReason === "length") return "truncated";
@@ -5471,6 +5510,14 @@ function withCachedHistory(messages) {
5471
5510
  }
5472
5511
  ];
5473
5512
  }
5513
+ function isAcceptedReportResult(result) {
5514
+ return result.toolName === "reportStatus" && isAcceptedReport(result.output);
5515
+ }
5516
+ function reportAccepted({
5517
+ steps
5518
+ }) {
5519
+ return steps.at(-1)?.toolResults?.some(isAcceptedReportResult) ?? false;
5520
+ }
5474
5521
  function isMissingReportRetry(kind) {
5475
5522
  return kind === "missingReport" || incompleteReasonOf(kind) !== void 0;
5476
5523
  }
@@ -5489,10 +5536,23 @@ function exhaustedError(kind, err) {
5489
5536
  }
5490
5537
  async function runAgent(req) {
5491
5538
  let retryReason = null;
5492
- for (let attempt = INITIAL_ATTEMPT; attempt <= REPORT_STATUS_RETRIES; attempt++) {
5539
+ let attempt = INITIAL_ATTEMPT;
5540
+ let continuation;
5541
+ let continuations = 0;
5542
+ for (; ; ) {
5493
5543
  try {
5494
- return await runAgentAttempt(req, attempt, retryReason);
5544
+ return await runAgentAttempt(req, attempt, retryReason, continuation);
5495
5545
  } catch (err) {
5546
+ continuation = void 0;
5547
+ if (err instanceof EndedTurnError && continuations < ENDED_TURN_CONTINUATIONS) {
5548
+ continuations++;
5549
+ continuation = err.continuation;
5550
+ logger.warn(
5551
+ { attempt: attempt + 1, continuations },
5552
+ "continuing runAgent after a turn ended without a tool call"
5553
+ );
5554
+ continue;
5555
+ }
5496
5556
  const kind = retryKind(err);
5497
5557
  if (!kind) throw err;
5498
5558
  if (attempt === REPORT_STATUS_RETRIES) throw exhaustedError(kind, err);
@@ -5501,19 +5561,23 @@ async function runAgent(req) {
5501
5561
  { attempt: attempt + 1, err },
5502
5562
  isMissingReportRetry(kind) ? "retrying runAgent after missing reportStatus" : "retrying runAgent after a transient provider error"
5503
5563
  );
5564
+ attempt++;
5504
5565
  }
5505
5566
  }
5506
- throw new Error("unreachable");
5507
5567
  }
5508
- async function runAgentAttempt(req, attempt, retryReason) {
5568
+ async function runAgentAttempt(req, attempt, retryReason, continuation) {
5509
5569
  const start = Date.now();
5510
5570
  const profileName = req.modelProfile ?? "implementation" /* implementation */;
5511
5571
  const profile = getModelProfile(profileName);
5512
5572
  const profileOptions = providerOptionsForProfile(profileName);
5573
+ const toolChoice = toolChoiceForProfile(profileName);
5513
5574
  const maxSteps = req.maxSteps ?? profile.maxSteps;
5575
+ const stepsUsed = continuation?.stepsUsed ?? 0;
5576
+ const stepsLeft = maxSteps - stepsUsed;
5514
5577
  const forceReport = retryReason === "missingReport";
5515
5578
  const incompleteReason = incompleteReasonOf(retryReason);
5516
- const modelOptions = forceReport ? { thinking: { type: "disabled" } } : profileOptions;
5579
+ const reportThinking = lowestThinkingForProfile(profileName);
5580
+ const modelOptions = forceReport ? { thinking: reportThinking, effort: void 0 } : profileOptions;
5517
5581
  logger.info(
5518
5582
  {
5519
5583
  startedAt: new Date(start).toISOString(),
@@ -5521,8 +5585,9 @@ async function runAgentAttempt(req, attempt, retryReason) {
5521
5585
  profile: profileName,
5522
5586
  model: profile.model,
5523
5587
  effort: forceReport ? void 0 : profile.effort,
5524
- thinking: forceReport ? "disabled" : profile.thinking,
5525
- retryReason
5588
+ thinking: forceReport ? reportThinking.type : profile.thinking,
5589
+ retryReason,
5590
+ stepsUsed
5526
5591
  },
5527
5592
  "runAgent started"
5528
5593
  );
@@ -5536,7 +5601,7 @@ async function runAgentAttempt(req, attempt, retryReason) {
5536
5601
  fetch: proxyFetch
5537
5602
  });
5538
5603
  const toolContext = req.toolContext ?? createToolContext();
5539
- if (attempt > INITIAL_ATTEMPT) resetToolCounts(toolContext);
5604
+ if (attempt > INITIAL_ATTEMPT && !continuation) resetToolCounts(toolContext);
5540
5605
  const readTools = ["readFile", "searchFiles", "listFiles"];
5541
5606
  const hasReadTools = !req.tools || req.tools.some((t) => readTools.includes(t));
5542
5607
  const instructions = [
@@ -5545,6 +5610,7 @@ async function runAgentAttempt(req, attempt, retryReason) {
5545
5610
  "When you need to read or search multiple files, issue those tool calls together in one step rather than one at a time."
5546
5611
  ] : [],
5547
5612
  "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.",
5613
+ ...toolChoice === "auto" ? [TOOL_EVERY_TURN_INSTRUCTION] : [],
5548
5614
  STEP_LIMIT_INSTRUCTION,
5549
5615
  // Last so a retry does not bust the cached tools+system prefix from
5550
5616
  // the first attempt. Inspect-and-continue, not start over: implement
@@ -5589,14 +5655,11 @@ async function runAgentAttempt(req, attempt, retryReason) {
5589
5655
  output: req.outputSchema,
5590
5656
  tools: req.tools
5591
5657
  }),
5592
- toolChoice: "required",
5593
- stopWhen: [
5594
- hasToolCall("reportStatus"),
5595
- stepCountIs(maxSteps)
5596
- ],
5658
+ toolChoice,
5659
+ stopWhen: [reportAccepted, stepCountIs(stepsLeft)],
5597
5660
  prepareStep: ({ stepNumber, messages }) => ({
5598
5661
  messages: withCachedHistory(messages),
5599
- ...stepNumber >= maxSteps - 1 && {
5662
+ ...stepNumber >= stepsLeft - 1 && {
5600
5663
  activeTools: ["reportStatus"]
5601
5664
  }
5602
5665
  }),
@@ -5604,9 +5667,11 @@ async function runAgentAttempt(req, attempt, retryReason) {
5604
5667
  ...{ onError: () => {
5605
5668
  } }
5606
5669
  });
5607
- const stream = await agent.stream({
5608
- prompt: "Follow system instructions"
5609
- });
5670
+ const prompt = continuation ? [
5671
+ ...continuation.messages,
5672
+ { role: "user", content: ENDED_TURN_NUDGE }
5673
+ ] : [{ role: "user", content: INITIAL_PROMPT }];
5674
+ const stream = await agent.stream({ prompt });
5610
5675
  let chunks = [];
5611
5676
  const chunkLimit = 5;
5612
5677
  let streamError;
@@ -5638,7 +5703,8 @@ async function runAgentAttempt(req, attempt, retryReason) {
5638
5703
  const usage = await stream.totalUsage;
5639
5704
  const steps = await stream.steps;
5640
5705
  const stepCount = steps.length;
5641
- const hitStepLimit = stepCount >= maxSteps;
5706
+ const totalSteps = stepsUsed + stepCount;
5707
+ const hitStepLimit = totalSteps >= maxSteps;
5642
5708
  const lastStep = steps[steps.length - 1];
5643
5709
  const finishReason = lastStep?.finishReason;
5644
5710
  trackAgentRun({
@@ -5675,7 +5741,7 @@ async function runAgentAttempt(req, attempt, retryReason) {
5675
5741
  "tool usage"
5676
5742
  );
5677
5743
  const toolResults = await stream.toolResults;
5678
- const report = [...toolResults].reverse().find((r) => r.toolName === "reportStatus");
5744
+ const report = [...toolResults].reverse().find(isAcceptedReportResult);
5679
5745
  if (!report) {
5680
5746
  logger.error(
5681
5747
  {
@@ -5686,8 +5752,16 @@ async function runAgentAttempt(req, attempt, retryReason) {
5686
5752
  },
5687
5753
  "Agent finished without calling reportStatus"
5688
5754
  );
5755
+ const endedTurn = toolChoice === "auto" && finishReason === "stop" && !lastStep?.toolCalls?.length && !hitStepLimit;
5756
+ if (endedTurn) {
5757
+ const { messages } = await stream.response;
5758
+ throw new EndedTurnError({
5759
+ messages: [...prompt, ...messages],
5760
+ stepsUsed: totalSteps
5761
+ });
5762
+ }
5689
5763
  throw new MissingReportError(
5690
- incompleteCauseOf(stepCount, maxSteps, finishReason)
5764
+ incompleteCauseOf(totalSteps, maxSteps, finishReason)
5691
5765
  );
5692
5766
  }
5693
5767
  const result = report.output;
@@ -10052,7 +10126,7 @@ async function resetProjectState() {
10052
10126
  // package.json with { type: 'json' }
10053
10127
  var package_default2 = {
10054
10128
  name: "@algolia/wizard",
10055
- version: "0.101.0",
10129
+ version: "0.103.0-rc.217.754",
10056
10130
  description: "Magically implement Algolia functionality in your codebase",
10057
10131
  type: "module",
10058
10132
  engines: {
@@ -10099,11 +10173,11 @@ var package_default2 = {
10099
10173
  vitest: "^4.1.11"
10100
10174
  },
10101
10175
  dependencies: {
10102
- "@ai-sdk/anthropic": "^3.0.118",
10103
- "@ai-sdk/openai-compatible": "^2.0.75",
10176
+ "@ai-sdk/anthropic": "^3.0.128",
10177
+ "@ai-sdk/openai-compatible": "^2.0.81",
10104
10178
  "@hono/node-server": "^2.0.10",
10105
10179
  "@segment/analytics-node": "^3.1.0",
10106
- ai: "^6.0.283",
10180
+ ai: "^6.0.302",
10107
10181
  "cross-keychain": "^1.1.0",
10108
10182
  dotenv: "^17.4.2",
10109
10183
  hono: "^4.13.8",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algolia/wizard",
3
- "version": "0.101.0",
3
+ "version": "0.103.0-rc.217.754",
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",