@algolia/wizard 0.97.0-rc.217.725 → 0.97.0-rc.217.726
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/main.js +71 -18
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1606,6 +1606,10 @@ async function clearWorkflowState(workflowId) {
|
|
|
1606
1606
|
}
|
|
1607
1607
|
|
|
1608
1608
|
// src/lib/modelProfiles.ts
|
|
1609
|
+
var MODEL_CAPABILITIES = {
|
|
1610
|
+
"claude-haiku-5-5": { forcedToolUse: true, lowestThinking: "disabled" },
|
|
1611
|
+
"claude-sonnet-5-5": { forcedToolUse: false, lowestThinking: "between_tools" }
|
|
1612
|
+
};
|
|
1609
1613
|
var TOKENS_PER_MILLION = 1e6;
|
|
1610
1614
|
var INITIAL_MODEL_ATTEMPT = 1;
|
|
1611
1615
|
var NO_TOKENS = 0;
|
|
@@ -1680,6 +1684,14 @@ function providerOptionsForProfile(profileName) {
|
|
|
1680
1684
|
...profile.effort !== void 0 && { effort: profile.effort }
|
|
1681
1685
|
};
|
|
1682
1686
|
}
|
|
1687
|
+
function toolChoiceForProfile(profileName) {
|
|
1688
|
+
const { model } = getModelProfile(profileName);
|
|
1689
|
+
return MODEL_CAPABILITIES[model].forcedToolUse ? "required" : "auto";
|
|
1690
|
+
}
|
|
1691
|
+
function lowestThinkingForProfile(profileName) {
|
|
1692
|
+
const { model } = getModelProfile(profileName);
|
|
1693
|
+
return { type: MODEL_CAPABILITIES[model].lowestThinking };
|
|
1694
|
+
}
|
|
1683
1695
|
function tokenCount(value = NO_TOKENS) {
|
|
1684
1696
|
return value;
|
|
1685
1697
|
}
|
|
@@ -2384,7 +2396,7 @@ async function ensureApplication(resumeAppId) {
|
|
|
2384
2396
|
// package.json
|
|
2385
2397
|
var package_default = {
|
|
2386
2398
|
name: "@algolia/wizard",
|
|
2387
|
-
version: "0.97.0-rc.217.
|
|
2399
|
+
version: "0.97.0-rc.217.726",
|
|
2388
2400
|
description: "Magically implement Algolia functionality in your codebase",
|
|
2389
2401
|
type: "module",
|
|
2390
2402
|
engines: {
|
|
@@ -5270,6 +5282,10 @@ var MISSING_REPORT_STATUS_ERROR_MESSAGE = "Agent finished without calling report
|
|
|
5270
5282
|
var MISSING_REPORT_USER_MESSAGE = "This step ran into a problem finishing. Run the wizard again to retry it.";
|
|
5271
5283
|
var REPORT_STATUS_RETRIES = 2;
|
|
5272
5284
|
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.";
|
|
5285
|
+
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.";
|
|
5286
|
+
var ENDED_TURN_NUDGE = "Your last response did not call a tool. Continue the work with tools. When the work is done, call reportStatus.";
|
|
5287
|
+
var INITIAL_PROMPT = "Follow system instructions";
|
|
5288
|
+
var ENDED_TURN_CONTINUATIONS = 3;
|
|
5273
5289
|
var RECENT_STEPS_LOGGED = 3;
|
|
5274
5290
|
var LOGGED_CHARS = 300;
|
|
5275
5291
|
var ATTEMPT_NUMBER_OFFSET = 1;
|
|
@@ -5307,6 +5323,13 @@ var MissingReportError = class extends Error {
|
|
|
5307
5323
|
this.incompleteCause = incompleteCause;
|
|
5308
5324
|
}
|
|
5309
5325
|
};
|
|
5326
|
+
var EndedTurnError = class extends MissingReportError {
|
|
5327
|
+
continuation;
|
|
5328
|
+
constructor(continuation) {
|
|
5329
|
+
super(null);
|
|
5330
|
+
this.continuation = continuation;
|
|
5331
|
+
}
|
|
5332
|
+
};
|
|
5310
5333
|
function incompleteCauseOf(stepCount, maxSteps, finishReason) {
|
|
5311
5334
|
if (stepCount >= maxSteps) return "stepLimit";
|
|
5312
5335
|
if (finishReason === "length") return "truncated";
|
|
@@ -5357,10 +5380,23 @@ function exhaustedError(kind, err) {
|
|
|
5357
5380
|
}
|
|
5358
5381
|
async function runAgent(req) {
|
|
5359
5382
|
let retryReason = null;
|
|
5360
|
-
|
|
5383
|
+
let attempt = INITIAL_ATTEMPT;
|
|
5384
|
+
let continuation;
|
|
5385
|
+
let continuations = 0;
|
|
5386
|
+
for (; ; ) {
|
|
5361
5387
|
try {
|
|
5362
|
-
return await runAgentAttempt(req, attempt, retryReason);
|
|
5388
|
+
return await runAgentAttempt(req, attempt, retryReason, continuation);
|
|
5363
5389
|
} catch (err) {
|
|
5390
|
+
continuation = void 0;
|
|
5391
|
+
if (err instanceof EndedTurnError && continuations < ENDED_TURN_CONTINUATIONS) {
|
|
5392
|
+
continuations++;
|
|
5393
|
+
continuation = err.continuation;
|
|
5394
|
+
logger.warn(
|
|
5395
|
+
{ attempt: attempt + 1, continuations },
|
|
5396
|
+
"continuing runAgent after a turn ended without a tool call"
|
|
5397
|
+
);
|
|
5398
|
+
continue;
|
|
5399
|
+
}
|
|
5364
5400
|
const kind = retryKind(err);
|
|
5365
5401
|
if (!kind) throw err;
|
|
5366
5402
|
if (attempt === REPORT_STATUS_RETRIES) throw exhaustedError(kind, err);
|
|
@@ -5369,19 +5405,23 @@ async function runAgent(req) {
|
|
|
5369
5405
|
{ attempt: attempt + 1, err },
|
|
5370
5406
|
isMissingReportRetry(kind) ? "retrying runAgent after missing reportStatus" : "retrying runAgent after a transient provider error"
|
|
5371
5407
|
);
|
|
5408
|
+
attempt++;
|
|
5372
5409
|
}
|
|
5373
5410
|
}
|
|
5374
|
-
throw new Error("unreachable");
|
|
5375
5411
|
}
|
|
5376
|
-
async function runAgentAttempt(req, attempt, retryReason) {
|
|
5412
|
+
async function runAgentAttempt(req, attempt, retryReason, continuation) {
|
|
5377
5413
|
const start = Date.now();
|
|
5378
5414
|
const profileName = req.modelProfile ?? "implementation" /* implementation */;
|
|
5379
5415
|
const profile = getModelProfile(profileName);
|
|
5380
5416
|
const profileOptions = providerOptionsForProfile(profileName);
|
|
5417
|
+
const toolChoice = toolChoiceForProfile(profileName);
|
|
5381
5418
|
const maxSteps = req.maxSteps ?? profile.maxSteps;
|
|
5419
|
+
const stepsUsed = continuation?.stepsUsed ?? 0;
|
|
5420
|
+
const stepsLeft = maxSteps - stepsUsed;
|
|
5382
5421
|
const forceReport = retryReason === "missingReport";
|
|
5383
5422
|
const incompleteReason = incompleteReasonOf(retryReason);
|
|
5384
|
-
const
|
|
5423
|
+
const reportThinking = lowestThinkingForProfile(profileName);
|
|
5424
|
+
const modelOptions = forceReport ? { thinking: reportThinking, effort: void 0 } : profileOptions;
|
|
5385
5425
|
logger.info(
|
|
5386
5426
|
{
|
|
5387
5427
|
startedAt: new Date(start).toISOString(),
|
|
@@ -5389,8 +5429,9 @@ async function runAgentAttempt(req, attempt, retryReason) {
|
|
|
5389
5429
|
profile: profileName,
|
|
5390
5430
|
model: profile.model,
|
|
5391
5431
|
effort: forceReport ? void 0 : profile.effort,
|
|
5392
|
-
thinking: forceReport ?
|
|
5393
|
-
retryReason
|
|
5432
|
+
thinking: forceReport ? reportThinking.type : profile.thinking,
|
|
5433
|
+
retryReason,
|
|
5434
|
+
stepsUsed
|
|
5394
5435
|
},
|
|
5395
5436
|
"runAgent started"
|
|
5396
5437
|
);
|
|
@@ -5404,7 +5445,7 @@ async function runAgentAttempt(req, attempt, retryReason) {
|
|
|
5404
5445
|
fetch: proxyFetch
|
|
5405
5446
|
});
|
|
5406
5447
|
const toolContext = req.toolContext ?? createToolContext();
|
|
5407
|
-
if (attempt > INITIAL_ATTEMPT) resetToolCounts(toolContext);
|
|
5448
|
+
if (attempt > INITIAL_ATTEMPT && !continuation) resetToolCounts(toolContext);
|
|
5408
5449
|
const readTools = ["readFile", "searchFiles", "listFiles"];
|
|
5409
5450
|
const hasReadTools = !req.tools || req.tools.some((t) => readTools.includes(t));
|
|
5410
5451
|
const instructions = [
|
|
@@ -5413,6 +5454,7 @@ async function runAgentAttempt(req, attempt, retryReason) {
|
|
|
5413
5454
|
"When you need to read or search multiple files, issue those tool calls together in one step rather than one at a time."
|
|
5414
5455
|
] : [],
|
|
5415
5456
|
"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.",
|
|
5457
|
+
...toolChoice === "auto" ? [TOOL_EVERY_TURN_INSTRUCTION] : [],
|
|
5416
5458
|
STEP_LIMIT_INSTRUCTION,
|
|
5417
5459
|
// Last so a retry does not bust the cached tools+system prefix from
|
|
5418
5460
|
// the first attempt. Inspect-and-continue, not start over: implement
|
|
@@ -5457,14 +5499,14 @@ async function runAgentAttempt(req, attempt, retryReason) {
|
|
|
5457
5499
|
output: req.outputSchema,
|
|
5458
5500
|
tools: req.tools
|
|
5459
5501
|
}),
|
|
5460
|
-
toolChoice
|
|
5502
|
+
toolChoice,
|
|
5461
5503
|
stopWhen: [
|
|
5462
5504
|
hasToolCall("reportStatus"),
|
|
5463
|
-
stepCountIs(
|
|
5505
|
+
stepCountIs(stepsLeft)
|
|
5464
5506
|
],
|
|
5465
5507
|
prepareStep: ({ stepNumber, messages }) => ({
|
|
5466
5508
|
messages: withCachedHistory(messages),
|
|
5467
|
-
...stepNumber >=
|
|
5509
|
+
...stepNumber >= stepsLeft - 1 && {
|
|
5468
5510
|
activeTools: ["reportStatus"]
|
|
5469
5511
|
}
|
|
5470
5512
|
}),
|
|
@@ -5472,9 +5514,11 @@ async function runAgentAttempt(req, attempt, retryReason) {
|
|
|
5472
5514
|
...{ onError: () => {
|
|
5473
5515
|
} }
|
|
5474
5516
|
});
|
|
5475
|
-
const
|
|
5476
|
-
|
|
5477
|
-
|
|
5517
|
+
const prompt = continuation ? [
|
|
5518
|
+
...continuation.messages,
|
|
5519
|
+
{ role: "user", content: ENDED_TURN_NUDGE }
|
|
5520
|
+
] : [{ role: "user", content: INITIAL_PROMPT }];
|
|
5521
|
+
const stream = await agent.stream({ prompt });
|
|
5478
5522
|
let chunks = [];
|
|
5479
5523
|
const chunkLimit = 5;
|
|
5480
5524
|
let streamError;
|
|
@@ -5506,7 +5550,8 @@ async function runAgentAttempt(req, attempt, retryReason) {
|
|
|
5506
5550
|
const usage = await stream.totalUsage;
|
|
5507
5551
|
const steps = await stream.steps;
|
|
5508
5552
|
const stepCount = steps.length;
|
|
5509
|
-
const
|
|
5553
|
+
const totalSteps = stepsUsed + stepCount;
|
|
5554
|
+
const hitStepLimit = totalSteps >= maxSteps;
|
|
5510
5555
|
const lastStep = steps[steps.length - 1];
|
|
5511
5556
|
const finishReason = lastStep?.finishReason;
|
|
5512
5557
|
trackAgentRun({
|
|
@@ -5554,8 +5599,16 @@ async function runAgentAttempt(req, attempt, retryReason) {
|
|
|
5554
5599
|
},
|
|
5555
5600
|
"Agent finished without calling reportStatus"
|
|
5556
5601
|
);
|
|
5602
|
+
const endedTurn = toolChoice === "auto" && finishReason === "stop" && !lastStep?.toolCalls?.length && !hitStepLimit;
|
|
5603
|
+
if (endedTurn) {
|
|
5604
|
+
const { messages } = await stream.response;
|
|
5605
|
+
throw new EndedTurnError({
|
|
5606
|
+
messages: [...prompt, ...messages],
|
|
5607
|
+
stepsUsed: totalSteps
|
|
5608
|
+
});
|
|
5609
|
+
}
|
|
5557
5610
|
throw new MissingReportError(
|
|
5558
|
-
incompleteCauseOf(
|
|
5611
|
+
incompleteCauseOf(totalSteps, maxSteps, finishReason)
|
|
5559
5612
|
);
|
|
5560
5613
|
}
|
|
5561
5614
|
const result = report.output;
|
|
@@ -9903,7 +9956,7 @@ async function resetProjectState() {
|
|
|
9903
9956
|
// package.json with { type: 'json' }
|
|
9904
9957
|
var package_default2 = {
|
|
9905
9958
|
name: "@algolia/wizard",
|
|
9906
|
-
version: "0.97.0-rc.217.
|
|
9959
|
+
version: "0.97.0-rc.217.726",
|
|
9907
9960
|
description: "Magically implement Algolia functionality in your codebase",
|
|
9908
9961
|
type: "module",
|
|
9909
9962
|
engines: {
|