@runtypelabs/sdk 1.9.0 → 1.9.2
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.cjs +192 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -4
- package/dist/index.d.ts +76 -4
- package/dist/index.js +192 -118
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2786,6 +2786,57 @@ var executionPhase = {
|
|
|
2786
2786
|
};
|
|
2787
2787
|
function classifyVariant(message) {
|
|
2788
2788
|
const lower = message.toLowerCase();
|
|
2789
|
+
const modificationVerbs = [
|
|
2790
|
+
"fix",
|
|
2791
|
+
"update",
|
|
2792
|
+
"change",
|
|
2793
|
+
"modify",
|
|
2794
|
+
"edit",
|
|
2795
|
+
"refactor",
|
|
2796
|
+
"improve",
|
|
2797
|
+
"add to",
|
|
2798
|
+
"remove",
|
|
2799
|
+
"delete",
|
|
2800
|
+
"rename",
|
|
2801
|
+
"migrate"
|
|
2802
|
+
];
|
|
2803
|
+
const hasModificationVerb = modificationVerbs.some(
|
|
2804
|
+
(v) => lower.startsWith(v) || new RegExp(`\\b${v}\\b`).test(lower)
|
|
2805
|
+
);
|
|
2806
|
+
const creationPatterns = [
|
|
2807
|
+
/^create\b/,
|
|
2808
|
+
/^build\b/,
|
|
2809
|
+
/^make\b/,
|
|
2810
|
+
/^generate\b/,
|
|
2811
|
+
/^scaffold\b/,
|
|
2812
|
+
/^set up\b/,
|
|
2813
|
+
/^setup\b/,
|
|
2814
|
+
/^bootstrap\b/,
|
|
2815
|
+
/^initialize\b/,
|
|
2816
|
+
/^init\b/,
|
|
2817
|
+
/^write a\b/,
|
|
2818
|
+
/^write an\b/,
|
|
2819
|
+
/^implement a\b/,
|
|
2820
|
+
/^implement an\b/,
|
|
2821
|
+
/^start a\b/,
|
|
2822
|
+
/^start an\b/,
|
|
2823
|
+
/^new\b/
|
|
2824
|
+
];
|
|
2825
|
+
const hasCreationStart = creationPatterns.some((p) => p.test(lower));
|
|
2826
|
+
const creationVerbs = [
|
|
2827
|
+
"build",
|
|
2828
|
+
"create",
|
|
2829
|
+
"make",
|
|
2830
|
+
"generate",
|
|
2831
|
+
"scaffold",
|
|
2832
|
+
"implement"
|
|
2833
|
+
];
|
|
2834
|
+
const hasCreationVerb = creationVerbs.some(
|
|
2835
|
+
(v) => new RegExp(`\\b${v}\\b`).test(lower)
|
|
2836
|
+
);
|
|
2837
|
+
if ((hasCreationStart || hasCreationVerb) && !hasModificationVerb) {
|
|
2838
|
+
return "create";
|
|
2839
|
+
}
|
|
2789
2840
|
const externalVerbs = [
|
|
2790
2841
|
"fetch",
|
|
2791
2842
|
"browse",
|
|
@@ -2825,49 +2876,9 @@ function classifyVariant(message) {
|
|
|
2825
2876
|
];
|
|
2826
2877
|
const hasExternalVerb = externalVerbs.some((v) => lower.includes(v));
|
|
2827
2878
|
const hasExternalTarget = externalTargets.some((t) => lower.includes(t));
|
|
2828
|
-
const modificationVerbs = [
|
|
2829
|
-
"fix",
|
|
2830
|
-
"update",
|
|
2831
|
-
"change",
|
|
2832
|
-
"modify",
|
|
2833
|
-
"edit",
|
|
2834
|
-
"refactor",
|
|
2835
|
-
"improve",
|
|
2836
|
-
"add to",
|
|
2837
|
-
"remove",
|
|
2838
|
-
"delete",
|
|
2839
|
-
"rename",
|
|
2840
|
-
"migrate"
|
|
2841
|
-
];
|
|
2842
|
-
const hasModificationVerb = modificationVerbs.some(
|
|
2843
|
-
(v) => lower.startsWith(v) || new RegExp(`\\b${v}\\b`).test(lower)
|
|
2844
|
-
);
|
|
2845
2879
|
if (hasExternalVerb && hasExternalTarget && !hasModificationVerb) {
|
|
2846
2880
|
return "external";
|
|
2847
2881
|
}
|
|
2848
|
-
const creationPatterns = [
|
|
2849
|
-
/^create\b/,
|
|
2850
|
-
/^build\b/,
|
|
2851
|
-
/^make\b/,
|
|
2852
|
-
/^generate\b/,
|
|
2853
|
-
/^scaffold\b/,
|
|
2854
|
-
/^set up\b/,
|
|
2855
|
-
/^setup\b/,
|
|
2856
|
-
/^bootstrap\b/,
|
|
2857
|
-
/^initialize\b/,
|
|
2858
|
-
/^init\b/,
|
|
2859
|
-
/^write a\b/,
|
|
2860
|
-
/^write an\b/,
|
|
2861
|
-
/^implement a\b/,
|
|
2862
|
-
/^implement an\b/,
|
|
2863
|
-
/^start a\b/,
|
|
2864
|
-
/^start an\b/,
|
|
2865
|
-
/^new\b/
|
|
2866
|
-
];
|
|
2867
|
-
const hasCreationStart = creationPatterns.some((p) => p.test(lower));
|
|
2868
|
-
if (hasCreationStart && !hasModificationVerb) {
|
|
2869
|
-
return "create";
|
|
2870
|
-
}
|
|
2871
2882
|
return "modify";
|
|
2872
2883
|
}
|
|
2873
2884
|
async function generateBootstrapContext(message, localTools, variant) {
|
|
@@ -3014,7 +3025,9 @@ var deployPhase = {
|
|
|
3014
3025
|
" 4. If the deploy fails, read the error output, fix the code, and call deploy_sandbox again.",
|
|
3015
3026
|
" 5. The sandbox is persistent \u2014 subsequent calls reuse the same sandbox.",
|
|
3016
3027
|
" 6. When the deploy succeeds and the preview URL is live, tell the user and end with TASK_COMPLETE.",
|
|
3017
|
-
" 7. For apps with HTML frontends, use the `files` parameter to write HTML/CSS/JS to separate files and serve them with express.static, rather than embedding HTML in template literals."
|
|
3028
|
+
" 7. For apps with HTML frontends, use the `files` parameter to write HTML/CSS/JS to separate files and serve them with express.static, rather than embedding HTML in template literals.",
|
|
3029
|
+
" 8. If the prompt asks for a multi-route app or names concrete output paths (for example `public/v1/index.html`), mirror that structure in the `files` payload.",
|
|
3030
|
+
" 9. If the prompt asks you to verify specific routes after deploy, check those paths against the preview URL before TASK_COMPLETE and iterate until they work."
|
|
3018
3031
|
].join("\n");
|
|
3019
3032
|
},
|
|
3020
3033
|
buildToolGuidance(_state) {
|
|
@@ -3022,6 +3035,7 @@ var deployPhase = {
|
|
|
3022
3035
|
"Your primary tool is deploy_sandbox. Call it with code, packageJson, language, and port.",
|
|
3023
3036
|
"Do NOT use write_file, read_file, search_repo, glob_files, tree_directory, or list_directory \u2014 you are deploying to a sandbox, not editing local files.",
|
|
3024
3037
|
"You may use run_sandbox_code for quick one-off script execution if needed.",
|
|
3038
|
+
"For static or multi-page sites, use `files` to create the requested folder structure and have the server expose those routes.",
|
|
3025
3039
|
"When deploy_sandbox returns successfully with a previewUrl, tell the user the URL and end with TASK_COMPLETE."
|
|
3026
3040
|
];
|
|
3027
3041
|
},
|
|
@@ -3071,34 +3085,7 @@ var deployPhase = {
|
|
|
3071
3085
|
return void 0;
|
|
3072
3086
|
}
|
|
3073
3087
|
};
|
|
3074
|
-
function classifyVariant2(
|
|
3075
|
-
const lower = message.toLowerCase();
|
|
3076
|
-
const deployPatterns = [
|
|
3077
|
-
/\bdeploy\b/,
|
|
3078
|
-
/\bsandbox\b/,
|
|
3079
|
-
/\bpreview\s*url\b/,
|
|
3080
|
-
/\blive\s*preview\b/,
|
|
3081
|
-
/\bhost\b.*\b(?:app|server|api|site)\b/,
|
|
3082
|
-
/\b(?:app|server|api|site)\b.*\bhost\b/,
|
|
3083
|
-
/\brun\b.*\b(?:server|web\s*app)\b/,
|
|
3084
|
-
/\blaunch\b.*\b(?:app|server|api|site)\b/,
|
|
3085
|
-
/\bstart\b.*\b(?:server|web\s*app)\b/
|
|
3086
|
-
];
|
|
3087
|
-
if (deployPatterns.some((p) => p.test(lower))) {
|
|
3088
|
-
return "deploy";
|
|
3089
|
-
}
|
|
3090
|
-
const webAppPatterns = [
|
|
3091
|
-
/\bbuild\b.*\b(?:web\s*app|website|api|server|express|hono|fastify)\b/,
|
|
3092
|
-
/\bcreate\b.*\b(?:web\s*app|website|api|server|express|hono|fastify)\b/,
|
|
3093
|
-
/\bmake\b.*\b(?:web\s*app|website|api|server|express|hono|fastify)\b/
|
|
3094
|
-
];
|
|
3095
|
-
const repoPatterns = [
|
|
3096
|
-
/\b(?:file|repo|repository|codebase|project|directory|folder)\b/,
|
|
3097
|
-
/\b(?:edit|modify|update|fix|refactor|change)\b/
|
|
3098
|
-
];
|
|
3099
|
-
if (webAppPatterns.some((p) => p.test(lower)) && !repoPatterns.some((p) => p.test(lower))) {
|
|
3100
|
-
return "deploy";
|
|
3101
|
-
}
|
|
3088
|
+
function classifyVariant2(_message) {
|
|
3102
3089
|
return "deploy";
|
|
3103
3090
|
}
|
|
3104
3091
|
var deployWorkflow = {
|
|
@@ -4210,6 +4197,12 @@ function dispatchAgentEvent(event, callbacks) {
|
|
|
4210
4197
|
case "agent_tool_delta":
|
|
4211
4198
|
callbacks.onToolDelta?.(typedData);
|
|
4212
4199
|
break;
|
|
4200
|
+
case "agent_tool_input_delta":
|
|
4201
|
+
callbacks.onToolInputDelta?.(typedData);
|
|
4202
|
+
break;
|
|
4203
|
+
case "agent_tool_input_complete":
|
|
4204
|
+
callbacks.onToolInputComplete?.(typedData);
|
|
4205
|
+
break;
|
|
4213
4206
|
case "agent_tool_complete":
|
|
4214
4207
|
callbacks.onToolComplete?.(typedData);
|
|
4215
4208
|
break;
|
|
@@ -4593,6 +4586,15 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
4593
4586
|
String(current).slice(0, 200)
|
|
4594
4587
|
);
|
|
4595
4588
|
}
|
|
4589
|
+
const localExecutionStartedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4590
|
+
const localExecutionStartedAtMs = Date.now();
|
|
4591
|
+
callbacks?.onLocalToolExecutionStart?.({
|
|
4592
|
+
executionId,
|
|
4593
|
+
toolCallId: toolId,
|
|
4594
|
+
toolName,
|
|
4595
|
+
parameters: parsedParams,
|
|
4596
|
+
startedAt: localExecutionStartedAt
|
|
4597
|
+
});
|
|
4596
4598
|
let toolResult;
|
|
4597
4599
|
try {
|
|
4598
4600
|
toolResult = await toolDef.execute(parsedParams);
|
|
@@ -4602,20 +4604,24 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
4602
4604
|
toolMessages.push({
|
|
4603
4605
|
role: "assistant",
|
|
4604
4606
|
content: "",
|
|
4605
|
-
toolCalls: [
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4607
|
+
toolCalls: [
|
|
4608
|
+
{
|
|
4609
|
+
toolCallId: toolId,
|
|
4610
|
+
toolName,
|
|
4611
|
+
args: parsedParams
|
|
4612
|
+
}
|
|
4613
|
+
]
|
|
4610
4614
|
});
|
|
4611
4615
|
toolMessages.push({
|
|
4612
4616
|
role: "tool",
|
|
4613
4617
|
content: "",
|
|
4614
|
-
toolResults: [
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4618
|
+
toolResults: [
|
|
4619
|
+
{
|
|
4620
|
+
toolCallId: toolId,
|
|
4621
|
+
toolName,
|
|
4622
|
+
result: toolResult
|
|
4623
|
+
}
|
|
4624
|
+
]
|
|
4619
4625
|
});
|
|
4620
4626
|
pauseCount += 1;
|
|
4621
4627
|
const toolNameCount = (toolNameCounts[toolName] || 0) + 1;
|
|
@@ -4647,6 +4653,16 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
4647
4653
|
recentActionKeys
|
|
4648
4654
|
});
|
|
4649
4655
|
if (forcedCompleteEvent) {
|
|
4656
|
+
callbacks?.onLocalToolExecutionComplete?.({
|
|
4657
|
+
executionId,
|
|
4658
|
+
toolCallId: toolId,
|
|
4659
|
+
toolName,
|
|
4660
|
+
parameters: parsedParams,
|
|
4661
|
+
result: toolResult,
|
|
4662
|
+
success: true,
|
|
4663
|
+
completedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4664
|
+
durationMs: Date.now() - localExecutionStartedAtMs
|
|
4665
|
+
});
|
|
4650
4666
|
if (!forcedCompleteEvent.finalOutput && accumulatedOutput) {
|
|
4651
4667
|
forcedCompleteEvent.finalOutput = accumulatedOutput;
|
|
4652
4668
|
}
|
|
@@ -4666,6 +4682,16 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
4666
4682
|
const error = await resumeResponse.json().catch(() => ({ error: "Unknown error" }));
|
|
4667
4683
|
throw new Error(error.error || `HTTP ${resumeResponse.status}`);
|
|
4668
4684
|
}
|
|
4685
|
+
callbacks?.onLocalToolExecutionComplete?.({
|
|
4686
|
+
executionId,
|
|
4687
|
+
toolCallId: toolId,
|
|
4688
|
+
toolName,
|
|
4689
|
+
parameters: parsedParams,
|
|
4690
|
+
result: toolResult,
|
|
4691
|
+
success: true,
|
|
4692
|
+
completedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4693
|
+
durationMs: Date.now() - localExecutionStartedAtMs
|
|
4694
|
+
});
|
|
4669
4695
|
currentBody = resumeResponse.body;
|
|
4670
4696
|
continue;
|
|
4671
4697
|
}
|
|
@@ -4888,7 +4914,10 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
4888
4914
|
}
|
|
4889
4915
|
const currentPhase = workflow.phases.find((p) => p.name === state.workflowPhase);
|
|
4890
4916
|
if (currentPhase?.canAcceptCompletion) {
|
|
4891
|
-
return currentPhase.canAcceptCompletion(
|
|
4917
|
+
return currentPhase.canAcceptCompletion(
|
|
4918
|
+
state,
|
|
4919
|
+
sessionTrace
|
|
4920
|
+
);
|
|
4892
4921
|
}
|
|
4893
4922
|
return true;
|
|
4894
4923
|
}
|
|
@@ -4960,7 +4989,10 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
4960
4989
|
compactOneResult(tr, taskName, mode) {
|
|
4961
4990
|
if (typeof tr.result === "string" && tr.result.startsWith("[")) return tr;
|
|
4962
4991
|
if (mode === "hot-tail") {
|
|
4963
|
-
return {
|
|
4992
|
+
return {
|
|
4993
|
+
...tr,
|
|
4994
|
+
result: this.offloadToolResult(taskName, tr.toolCallId, tr.toolName, tr.result)
|
|
4995
|
+
};
|
|
4964
4996
|
}
|
|
4965
4997
|
return { ...tr, result: `[Output from ${tr.toolName} masked \u2014 re-run the tool if needed]` };
|
|
4966
4998
|
}
|
|
@@ -5059,7 +5091,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5059
5091
|
}
|
|
5060
5092
|
};
|
|
5061
5093
|
const baseDir = sourcePath ? this.dirnameOfCandidatePath(sourcePath) : "";
|
|
5062
|
-
for (const match of text.matchAll(
|
|
5094
|
+
for (const match of text.matchAll(
|
|
5095
|
+
/(?:href|src)=["']([^"']+\.(?:html|tsx|ts|jsx|js|md|json))["']/gi
|
|
5096
|
+
)) {
|
|
5063
5097
|
const target = match[1] || "";
|
|
5064
5098
|
const resolved = baseDir ? this.joinCandidatePath(baseDir, target) : target;
|
|
5065
5099
|
add(resolved, `linked from ${sourcePath || "discovery result"} via ${target}`);
|
|
@@ -5099,7 +5133,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5099
5133
|
if (!bootstrapContext) return void 0;
|
|
5100
5134
|
const candidates = this.parseSearchRepoResultForCandidates(bootstrapContext);
|
|
5101
5135
|
if (candidates.length === 0) return void 0;
|
|
5102
|
-
return candidates.sort(
|
|
5136
|
+
return candidates.sort(
|
|
5137
|
+
(a, b) => this.scoreCandidatePath(b.path) - this.scoreCandidatePath(a.path)
|
|
5138
|
+
)[0];
|
|
5103
5139
|
}
|
|
5104
5140
|
sanitizeResumeState(resumeState, taskName) {
|
|
5105
5141
|
if (!resumeState) return void 0;
|
|
@@ -5206,10 +5242,17 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5206
5242
|
isArtifactPath: this.isMarathonArtifactPath.bind(this),
|
|
5207
5243
|
isDiscoveryTool: this.isDiscoveryToolName.bind(this)
|
|
5208
5244
|
};
|
|
5209
|
-
const blockedMessage = currentPhase.interceptToolCall(
|
|
5245
|
+
const blockedMessage = currentPhase.interceptToolCall(
|
|
5246
|
+
toolName,
|
|
5247
|
+
args,
|
|
5248
|
+
ctx
|
|
5249
|
+
);
|
|
5210
5250
|
if (blockedMessage) {
|
|
5211
5251
|
if (isWriteLikeTool) trace.attemptedWrite = true;
|
|
5212
|
-
this.pushToolTraceEntry(
|
|
5252
|
+
this.pushToolTraceEntry(
|
|
5253
|
+
trace,
|
|
5254
|
+
`${toolName}${pathArg}${queryArg}${patternArg} -> ${blockedMessage}`
|
|
5255
|
+
);
|
|
5213
5256
|
return blockedMessage;
|
|
5214
5257
|
}
|
|
5215
5258
|
}
|
|
@@ -5266,7 +5309,10 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5266
5309
|
verificationResult.error || verificationResult.output
|
|
5267
5310
|
].filter(Boolean).join(" | ").slice(0, 240) : this.summarizeTextBlockForTrace(result);
|
|
5268
5311
|
const resultSuffix = summarizedResult ? ` -> ${summarizedResult}` : "";
|
|
5269
|
-
this.pushToolTraceEntry(
|
|
5312
|
+
this.pushToolTraceEntry(
|
|
5313
|
+
trace,
|
|
5314
|
+
`${toolName}${pathArg}${queryArg}${patternArg}${resultSuffix}`
|
|
5315
|
+
);
|
|
5270
5316
|
const textResult = typeof result === "string" ? result : "";
|
|
5271
5317
|
if (toolName === "read_file" && normalizedPathArg && normalizedBestCandidatePath && normalizedPathArg === normalizedBestCandidatePath && (trace.bestCandidateWritten || state.bestCandidateNeedsVerification)) {
|
|
5272
5318
|
trace.bestCandidateVerified = true;
|
|
@@ -5357,7 +5403,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5357
5403
|
return [
|
|
5358
5404
|
"Session working memory:",
|
|
5359
5405
|
...flags.length > 0 ? [`- ${flags.join("; ")}`] : [],
|
|
5360
|
-
...trace.bestCandidatePath ? [
|
|
5406
|
+
...trace.bestCandidatePath ? [
|
|
5407
|
+
`- best candidate: ${trace.bestCandidatePath}${trace.bestCandidateReason ? ` (${trace.bestCandidateReason})` : ""}`
|
|
5408
|
+
] : [],
|
|
5361
5409
|
...lines
|
|
5362
5410
|
].join("\n").slice(0, 1200);
|
|
5363
5411
|
}
|
|
@@ -5431,12 +5479,7 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5431
5479
|
}
|
|
5432
5480
|
};
|
|
5433
5481
|
const lowerMessage = message.toLowerCase();
|
|
5434
|
-
const phraseHints = [
|
|
5435
|
-
"agent editor",
|
|
5436
|
-
"theme.html",
|
|
5437
|
-
"/theme.html",
|
|
5438
|
-
"style it visually"
|
|
5439
|
-
];
|
|
5482
|
+
const phraseHints = ["agent editor", "theme.html", "/theme.html", "style it visually"];
|
|
5440
5483
|
for (const hint of phraseHints) {
|
|
5441
5484
|
if (lowerMessage.includes(hint.toLowerCase())) push(hint);
|
|
5442
5485
|
}
|
|
@@ -5463,7 +5506,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5463
5506
|
for (const match of message.matchAll(/\b([a-z0-9]+(?:\s+[a-z0-9]+){1,2})\b/gi)) {
|
|
5464
5507
|
const phrase = (match[1] || "").toLowerCase();
|
|
5465
5508
|
const words = phrase.split(" ");
|
|
5466
|
-
if (words.some(
|
|
5509
|
+
if (words.some(
|
|
5510
|
+
(word) => ["editor", "page", "screen", "view", "route", "component"].includes(word)
|
|
5511
|
+
)) {
|
|
5467
5512
|
push(match[1] || "");
|
|
5468
5513
|
}
|
|
5469
5514
|
}
|
|
@@ -5493,7 +5538,11 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5493
5538
|
}
|
|
5494
5539
|
if (globTool && /\./.test(query)) {
|
|
5495
5540
|
try {
|
|
5496
|
-
const result = await globTool.execute({
|
|
5541
|
+
const result = await globTool.execute({
|
|
5542
|
+
pattern: `**/${query}`,
|
|
5543
|
+
path: ".",
|
|
5544
|
+
maxResults: 5
|
|
5545
|
+
});
|
|
5497
5546
|
const summary = this.summarizeTextBlockForTrace(result, 3);
|
|
5498
5547
|
if (summary && !summary.startsWith("No files matched")) {
|
|
5499
5548
|
lines.push(`glob_files "**/${query}": ${summary}`);
|
|
@@ -5594,7 +5643,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5594
5643
|
state.isCreationTask || state.workflowVariant === "external"
|
|
5595
5644
|
);
|
|
5596
5645
|
}
|
|
5597
|
-
const bootstrapCandidate = this.extractBestCandidateFromBootstrapContext(
|
|
5646
|
+
const bootstrapCandidate = this.extractBestCandidateFromBootstrapContext(
|
|
5647
|
+
state.bootstrapContext
|
|
5648
|
+
);
|
|
5598
5649
|
if (bootstrapCandidate) {
|
|
5599
5650
|
state.bestCandidatePath = bootstrapCandidate.path;
|
|
5600
5651
|
state.bestCandidateReason = bootstrapCandidate.reason;
|
|
@@ -5603,7 +5654,12 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5603
5654
|
}
|
|
5604
5655
|
for (let session = 0; session < maxSessions; session++) {
|
|
5605
5656
|
const sessionTrace = this.createEmptyToolTrace();
|
|
5606
|
-
const sessionLocalTools = this.wrapLocalToolsForTrace(
|
|
5657
|
+
const sessionLocalTools = this.wrapLocalToolsForTrace(
|
|
5658
|
+
options.localTools,
|
|
5659
|
+
sessionTrace,
|
|
5660
|
+
state,
|
|
5661
|
+
workflow
|
|
5662
|
+
);
|
|
5607
5663
|
const sessionCallbacks = this.createTraceCallbacks(options.streamCallbacks, sessionTrace);
|
|
5608
5664
|
const continuationContext = session === 0 && options.previousMessages ? {
|
|
5609
5665
|
previousMessages: options.previousMessages,
|
|
@@ -5634,16 +5690,13 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5634
5690
|
onContextNotice: options.onContextNotice
|
|
5635
5691
|
}
|
|
5636
5692
|
);
|
|
5637
|
-
const {
|
|
5638
|
-
messages,
|
|
5639
|
-
requestContextManagement,
|
|
5640
|
-
pendingNativeCompactionEvent
|
|
5641
|
-
} = preparedSession;
|
|
5693
|
+
const { messages, requestContextManagement, pendingNativeCompactionEvent } = preparedSession;
|
|
5642
5694
|
let sessionResult;
|
|
5643
5695
|
const sessionData = {
|
|
5644
5696
|
messages,
|
|
5645
5697
|
debugMode: options.debugMode,
|
|
5646
5698
|
model: options.model,
|
|
5699
|
+
...options.reasoning !== void 0 ? { reasoning: options.reasoning } : {},
|
|
5647
5700
|
...options.toolIds?.length ? { tools: { toolIds: options.toolIds } } : {},
|
|
5648
5701
|
...requestContextManagement ? { contextManagement: requestContextManagement } : {}
|
|
5649
5702
|
};
|
|
@@ -5761,7 +5814,10 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5761
5814
|
).slice(-20);
|
|
5762
5815
|
}
|
|
5763
5816
|
if (sessionTrace.actionKeys.length > 0) {
|
|
5764
|
-
state.recentActionKeys = [
|
|
5817
|
+
state.recentActionKeys = [
|
|
5818
|
+
...state.recentActionKeys || [],
|
|
5819
|
+
...sessionTrace.actionKeys
|
|
5820
|
+
].slice(-20);
|
|
5765
5821
|
}
|
|
5766
5822
|
if (sessionTrace.planWritten) {
|
|
5767
5823
|
state.planWritten = true;
|
|
@@ -5790,7 +5846,11 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
5790
5846
|
const latestSession = state.sessions[state.sessions.length - 1];
|
|
5791
5847
|
if (latestSession) {
|
|
5792
5848
|
latestSession.outputPreview = [phaseTransitionSummary, "", latestSession.outputPreview].join("\n").slice(0, 300);
|
|
5793
|
-
latestSession.toolTraceSummary = [
|
|
5849
|
+
latestSession.toolTraceSummary = [
|
|
5850
|
+
phaseTransitionSummary,
|
|
5851
|
+
"",
|
|
5852
|
+
latestSession.toolTraceSummary || ""
|
|
5853
|
+
].join("\n").trim().slice(0, 1200);
|
|
5794
5854
|
}
|
|
5795
5855
|
}
|
|
5796
5856
|
if (!state.messages) state.messages = [];
|
|
@@ -6027,7 +6087,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
6027
6087
|
details.builtinToolSchemas
|
|
6028
6088
|
);
|
|
6029
6089
|
const reservedOutputTokens = this.resolveReservedOutputTokens(details.contextLimitTokens);
|
|
6030
|
-
const effectiveInputBudgetTokens = this.resolveEffectiveInputBudgetTokens(
|
|
6090
|
+
const effectiveInputBudgetTokens = this.resolveEffectiveInputBudgetTokens(
|
|
6091
|
+
details.contextLimitTokens
|
|
6092
|
+
);
|
|
6031
6093
|
const summaryTokens = details.summaryText ? this.estimateTextTokens(
|
|
6032
6094
|
`${_AgentsEndpoint.AUTO_COMPACT_SUMMARY_PREFIX}
|
|
6033
6095
|
|
|
@@ -6148,7 +6210,9 @@ Do NOT redo any of the above work.`
|
|
|
6148
6210
|
"",
|
|
6149
6211
|
"Changed Files / Candidate Paths",
|
|
6150
6212
|
...candidatePaths.length > 0 ? candidatePaths.map((candidatePath) => `- ${candidatePath}`) : ["- No candidate paths recorded yet."],
|
|
6151
|
-
...state.planPath ? [
|
|
6213
|
+
...state.planPath ? [
|
|
6214
|
+
`- ${state.workflowVariant === "external" ? "Report path" : "Plan path"}: ${state.planPath}`
|
|
6215
|
+
] : [],
|
|
6152
6216
|
...state.planWritten ? ["- Planning artifact has been written."] : [],
|
|
6153
6217
|
...state.bestCandidateReason ? [`- Best candidate rationale: ${state.bestCandidateReason}`] : [],
|
|
6154
6218
|
"",
|
|
@@ -6170,10 +6234,14 @@ Do NOT redo any of the above work.`
|
|
|
6170
6234
|
].join("\n");
|
|
6171
6235
|
}
|
|
6172
6236
|
isAssistantToolCallMessage(message) {
|
|
6173
|
-
return Boolean(
|
|
6237
|
+
return Boolean(
|
|
6238
|
+
message?.role === "assistant" && message.toolCalls && message.toolCalls.length > 0
|
|
6239
|
+
);
|
|
6174
6240
|
}
|
|
6175
6241
|
isToolResultMessage(message) {
|
|
6176
|
-
return Boolean(
|
|
6242
|
+
return Boolean(
|
|
6243
|
+
message?.role === "tool" && message.toolResults && message.toolResults.length > 0
|
|
6244
|
+
);
|
|
6177
6245
|
}
|
|
6178
6246
|
/**
|
|
6179
6247
|
* Replay only complete adjacent tool-call/result pairs so provider validation
|
|
@@ -6321,7 +6389,9 @@ Do NOT redo any of the above work.`
|
|
|
6321
6389
|
"Use these tools to inspect the existing repository and make real file edits \u2014 not just code in your response."
|
|
6322
6390
|
],
|
|
6323
6391
|
...toolGuidanceLines,
|
|
6324
|
-
...isDeployWorkflow ? [] : isExternalTask2 ? [
|
|
6392
|
+
...isDeployWorkflow ? [] : isExternalTask2 ? [
|
|
6393
|
+
"Use write_file only if you want to save the final deliverable into the workspace."
|
|
6394
|
+
] : ["Always use write_file to save your output so the user can run it immediately."]
|
|
6325
6395
|
].join("\n") : "";
|
|
6326
6396
|
const builtinToolNames = builtinToolIds?.map((id) => id.replace(/^builtin:/, ""));
|
|
6327
6397
|
const builtinToolsBlock = builtinToolNames?.length ? [
|
|
@@ -6343,9 +6413,12 @@ Do NOT redo any of the above work.`
|
|
|
6343
6413
|
const replayHistoryMessages = this.sanitizeReplayHistoryMessages(
|
|
6344
6414
|
continuationContext.previousMessages
|
|
6345
6415
|
);
|
|
6416
|
+
const continuationGuardrail = "IMPORTANT: You are continuing a previously completed task. The conversation above shows your prior work. Do NOT redo any of it. Build on what was already accomplished. If there is nothing new to do, respond with TASK_COMPLETE.";
|
|
6346
6417
|
const defaultContinueMessage = "Continue the task. Review your prior work above and proceed with any remaining work. If everything is already complete, respond with TASK_COMPLETE.";
|
|
6347
6418
|
const userMessage = continuationContext.newUserMessage || defaultContinueMessage;
|
|
6348
6419
|
const userContent = [
|
|
6420
|
+
continuationGuardrail,
|
|
6421
|
+
"",
|
|
6349
6422
|
userMessage,
|
|
6350
6423
|
phaseBlock,
|
|
6351
6424
|
toolsBlock,
|
|
@@ -6356,10 +6429,6 @@ Do NOT redo any of the above work.`
|
|
|
6356
6429
|
].join("\n");
|
|
6357
6430
|
const fullHistoryMessages = [
|
|
6358
6431
|
...replayHistoryMessages,
|
|
6359
|
-
{
|
|
6360
|
-
role: "system",
|
|
6361
|
-
content: "IMPORTANT: You are continuing a previously completed task. The conversation above shows your prior work. Do NOT redo any of it. Build on what was already accomplished. If there is nothing new to do, respond with TASK_COMPLETE."
|
|
6362
|
-
},
|
|
6363
6432
|
{
|
|
6364
6433
|
role: "user",
|
|
6365
6434
|
content: userContent
|
|
@@ -6430,7 +6499,15 @@ Do NOT redo any of the above work.`
|
|
|
6430
6499
|
};
|
|
6431
6500
|
}
|
|
6432
6501
|
if (sessionIndex === 0) {
|
|
6433
|
-
const content2 = [
|
|
6502
|
+
const content2 = [
|
|
6503
|
+
originalMessage,
|
|
6504
|
+
phaseBlock,
|
|
6505
|
+
toolsBlock,
|
|
6506
|
+
bootstrapBlock,
|
|
6507
|
+
candidateBlock,
|
|
6508
|
+
"",
|
|
6509
|
+
multiSessionInstruction
|
|
6510
|
+
].join("\n");
|
|
6434
6511
|
return {
|
|
6435
6512
|
messages: [{ role: "user", content: content2 }],
|
|
6436
6513
|
requestContextManagement
|
|
@@ -6481,10 +6558,7 @@ Do NOT redo any of the above work.`
|
|
|
6481
6558
|
contextLimitTokens: compactionOptions?.contextLimitTokens
|
|
6482
6559
|
});
|
|
6483
6560
|
await maybeEmitToolDefinitionWarning(breakdown);
|
|
6484
|
-
const messages = [
|
|
6485
|
-
...historyMessages,
|
|
6486
|
-
{ role: "user", content: continuationContent }
|
|
6487
|
-
];
|
|
6561
|
+
const messages = [...historyMessages, { role: "user", content: continuationContent }];
|
|
6488
6562
|
if (resolvedStrategy === "summary_fallback" && typeof compactionOptions?.autoCompactTokenThreshold === "number" && compactionOptions.autoCompactTokenThreshold > 0 && breakdown.estimatedInputTokens >= compactionOptions.autoCompactTokenThreshold) {
|
|
6489
6563
|
return {
|
|
6490
6564
|
messages: await this.buildCompactHistoryMessagesWithLifecycle(
|