@sourcegraph/amp 0.0.1748592090-g82886f → 0.0.1748620891-gf6fd33

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 (41) hide show
  1. package/dist/amp.js +2 -2
  2. package/dist/{color-KZLHE9lz.js → console-B_a7AZVs.js} +9921 -9906
  3. package/dist/console-B_a7AZVs.js.map +1 -0
  4. package/dist/{create_file.node-CeO77-N9.js → create_file.node-DLgtL-Xm.js} +2 -2
  5. package/dist/{create_file.node-CeO77-N9.js.map → create_file.node-DLgtL-Xm.js.map} +1 -1
  6. package/dist/{edit_file.node-BRayGlMY.js → edit_file.node-CrnktvWL.js} +9 -9
  7. package/dist/{edit_file.node-BRayGlMY.js.map → edit_file.node-CrnktvWL.js.map} +1 -1
  8. package/dist/{executable-rYoa-LRU.js → executable-BglMpb2E.js} +2 -2
  9. package/dist/{executable-rYoa-LRU.js.map → executable-BglMpb2E.js.map} +1 -1
  10. package/dist/{files-DRNnhOmo.js → files-gDsYEnW1.js} +2 -2
  11. package/dist/{files-DRNnhOmo.js.map → files-gDsYEnW1.js.map} +1 -1
  12. package/dist/{glob.node-agGBjrBg.js → glob.node-CMSCjukj.js} +40 -40
  13. package/dist/{glob.node-agGBjrBg.js.map → glob.node-CMSCjukj.js.map} +1 -1
  14. package/dist/{list_directory.node-TYM6mPMl.js → list_directory.node-BTLRHJ48.js} +2 -2
  15. package/dist/{list_directory.node-TYM6mPMl.js.map → list_directory.node-BTLRHJ48.js.map} +1 -1
  16. package/dist/{load-profile-DfzWNpRA.js → load-profile-DCv3-1Ka.js} +2 -2
  17. package/dist/{load-profile-DfzWNpRA.js.map → load-profile-DCv3-1Ka.js.map} +1 -1
  18. package/dist/{main-d0nDM7GJ.js → main-DQsFuGGG.js} +32815 -32767
  19. package/dist/main-DQsFuGGG.js.map +1 -0
  20. package/dist/{node-CDZC4DW9.js → node-4Pn7H_vJ.js} +3 -3
  21. package/dist/{node-CDZC4DW9.js.map → node-4Pn7H_vJ.js.map} +1 -1
  22. package/dist/{node-DkV0OdKk.js → node-B8WXoxgO.js} +14 -14
  23. package/dist/{node-DkV0OdKk.js.map → node-B8WXoxgO.js.map} +1 -1
  24. package/dist/{node-COuJYHx_.js → node-CBVbC8Le.js} +47 -47
  25. package/dist/{node-COuJYHx_.js.map → node-CBVbC8Le.js.map} +1 -1
  26. package/dist/{node-DWXaFMNz.js → node-CODo0ZrH.js} +2 -2
  27. package/dist/{node-DWXaFMNz.js.map → node-CODo0ZrH.js.map} +1 -1
  28. package/dist/{node-HdWhJMp3.js → node-Cb0kHKh8.js} +8 -8
  29. package/dist/{node-HdWhJMp3.js.map → node-Cb0kHKh8.js.map} +1 -1
  30. package/dist/{node-XQHPbSSO.js → node-u8kG41tu.js} +3 -3
  31. package/dist/{node-XQHPbSSO.js.map → node-u8kG41tu.js.map} +1 -1
  32. package/dist/{read_file.node-2KNKpy--.js → read_file.node-BD8KJm_C.js} +2 -2
  33. package/dist/{read_file.node-2KNKpy--.js.map → read_file.node-BD8KJm_C.js.map} +1 -1
  34. package/dist/{stdio-GkdttQu7.js → stdio-B8D5AKpo.js} +12 -12
  35. package/dist/{stdio-GkdttQu7.js.map → stdio-B8D5AKpo.js.map} +1 -1
  36. package/dist/storybook.js +1 -1
  37. package/dist/{undo_edit.node-C8Hv1wkP.js → undo_edit.node-CKspKBvM.js} +4 -4
  38. package/dist/{undo_edit.node-C8Hv1wkP.js.map → undo_edit.node-CKspKBvM.js.map} +1 -1
  39. package/package.json +1 -1
  40. package/dist/color-KZLHE9lz.js.map +0 -1
  41. package/dist/main-d0nDM7GJ.js.map +0 -1
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { $ as Y, a6 as I, a1 as k, at as L, a2 as C, aF as D, f as j, a5 as J, b8 as V, E as Z, O as z, Z as M, ak as W, as as q, n as G } from "./color-KZLHE9lz.js";
3
- import { a as x, o as A, s as g, d as H, b as K, l as h, r as F, u as Q, e as X, c as _, p as ee, Z as te, g as se, h as N } from "./main-d0nDM7GJ.js";
2
+ import { ak as Y, V as $, am as k, W as L, an as C, aN as D, f as j, as as J, b7 as V, a0 as W, O as z, ai as M, J as Z, U as q, n as G } from "./console-B_a7AZVs.js";
3
+ import { a as x, o as A, s as g, d as H, b as K, l as h, r as N, u as Q, e as X, c as _, p as ee, Z as te, g as se, h as F } from "./main-DQsFuGGG.js";
4
4
  const S = A({
5
5
  context: X(["continue", "none"]).optional().default("continue"),
6
6
  tools: Q([h("all"), x(g())]).optional(),
7
7
  prompt: g(),
8
- verify: F(_()).optional()
8
+ verify: N(_()).optional()
9
9
  }), oe = S.extend({
10
10
  type: h("agent"),
11
11
  model: g().optional(),
@@ -25,7 +25,7 @@ const S = A({
25
25
  }), ie = A({
26
26
  type: h("tool_call"),
27
27
  tool: g(),
28
- parameters: F(_()).optional()
28
+ parameters: N(_()).optional()
29
29
  }), le = A({
30
30
  type: h("bash"),
31
31
  command: g()
@@ -93,7 +93,7 @@ async function ge(r, e, t, s, o, a) {
93
93
  const c = O(r.prompt, o);
94
94
  let i = e;
95
95
  const m = (p) => {
96
- i = N(i, p);
96
+ i = F(i, p);
97
97
  };
98
98
  m({
99
99
  type: "user:message",
@@ -124,7 +124,7 @@ async function ge(r, e, t, s, o, a) {
124
124
  a.throwIfAborted();
125
125
  let b;
126
126
  try {
127
- const n = I.fromNativeThread(i);
127
+ const n = $.fromNativeThread(i);
128
128
  b = await L(
129
129
  n,
130
130
  u,
@@ -171,13 +171,13 @@ async function ge(r, e, t, s, o, a) {
171
171
  a
172
172
  ), a.throwIfAborted(), y.status !== "done")
173
173
  throw new Error(JSON.stringify(y));
174
- } catch ($) {
174
+ } catch (I) {
175
175
  m({
176
176
  type: "tool:data",
177
177
  toolUse: n.id,
178
178
  data: {
179
179
  status: "error",
180
- error: { message: `Tool call error: ${$}` }
180
+ error: { message: `Tool call error: ${I}` }
181
181
  }
182
182
  }), s.update({
183
183
  status: "in-progress",
@@ -185,7 +185,7 @@ async function ge(r, e, t, s, o, a) {
185
185
  id: n.id,
186
186
  type: "toolResult",
187
187
  toolName: n.name,
188
- result: `Tool call error: ${$}`
188
+ result: `Tool call error: ${I}`
189
189
  }
190
190
  });
191
191
  continue;
@@ -211,7 +211,7 @@ async function fe(r, e, t, s, o) {
211
211
  const a = O(r.prompt, s);
212
212
  let l = e;
213
213
  const c = (d) => {
214
- l = N(l, d);
214
+ l = F(l, d);
215
215
  };
216
216
  c({
217
217
  type: "user:message",
@@ -225,7 +225,7 @@ async function fe(r, e, t, s, o) {
225
225
  status: "in-progress",
226
226
  progress: { type: "message", speaker: "user", message: a }
227
227
  });
228
- const i = I.fromNativeThread(l), m = r.model || k, u = await L(
228
+ const i = $.fromNativeThread(l), m = r.model || k, u = await L(
229
229
  i,
230
230
  [],
231
231
  // No tools for LLM-only step
@@ -245,7 +245,7 @@ async function fe(r, e, t, s, o) {
245
245
  }), l;
246
246
  }
247
247
  function ye(r, e) {
248
- const t = Z(r);
248
+ const t = W(r);
249
249
  return e.content.filter((s) => s.type === "tool_use").filter((s) => !s.inputPartialJSON).filter(
250
250
  (s) => (
251
251
  // Only include tools that haven't been invoked yet.
@@ -290,7 +290,7 @@ async function he(r, e, t, s) {
290
290
  progress: { type: "meta", message: `Loading routine: ${o} from ${l}` }
291
291
  });
292
292
  const c = D();
293
- c.registerTool(W);
293
+ c.registerTool(Z);
294
294
  const i = await R(
295
295
  c,
296
296
  "read_file",
@@ -365,4 +365,4 @@ async function he(r, e, t, s) {
365
365
  export {
366
366
  Te as runRoutine
367
367
  };
368
- //# sourceMappingURL=node-DkV0OdKk.js.map
368
+ //# sourceMappingURL=node-B8WXoxgO.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-DkV0OdKk.js","sources":["../../core/src/tools/builtin/run_routine/types.ts","../../core/src/tools/builtin/run_routine/serialization.ts","../../core/src/tools/builtin/run_routine/util.ts","../../core/src/tools/builtin/run_routine/step.ts","../../core/src/tools/builtin/run_routine/node.ts"],"sourcesContent":["import { z } from 'zod'\n\n// Base Step interface\nconst BaseStep = z.object({\n\tcontext: z.enum(['continue', 'none']).optional().default('continue'),\n\ttools: z.union([z.literal('all'), z.array(z.string())]).optional(),\n\tprompt: z.string(),\n\tverify: z.record(z.any()).optional(),\n}) satisfies z.ZodType<{\n\tcontext?: 'continue' | 'none'\n\ttools?: 'all' | string[]\n\tprompt: string\n\tverify?: Record<string, any>\n}>\n\n// Agent Step\nconst AgentStep = BaseStep.extend({\n\ttype: z.literal('agent'),\n\tmodel: z.string().optional(), // Default could be set in implementation\n\tinteractive_confirmation: z.boolean().optional(),\n})\n\n// LLM Step\nconst LLMStep = BaseStep.extend({\n\ttype: z.literal('llm'),\n\tmodel: z.string().optional(),\n})\n\n// Loop Agent Step\nconst LoopAgentStep = BaseStep.extend({\n\ttype: z.literal('loop_agent'),\n\tmodel: z.string().optional(),\n\tinput_file: z.string(),\n})\n\n// Loop LLM Step\nconst LoopLLMStep = BaseStep.extend({\n\ttype: z.literal('loop_llm'),\n\tmodel: z.string().optional(),\n\tinput_file: z.string(),\n})\n\n// Tool Call Step\nconst ToolCallStep = z.object({\n\ttype: z.literal('tool_call'),\n\ttool: z.string(),\n\tparameters: z.record(z.any()).optional(),\n})\n\n// Bash Step\nconst BashStep = z.object({\n\ttype: z.literal('bash'),\n\tcommand: z.string(),\n})\n\n// Union of all step types\nconst Step = z.discriminatedUnion('type', [\n\tAgentStep,\n\tLLMStep,\n\tLoopAgentStep,\n\tLoopLLMStep,\n\tToolCallStep,\n\tBashStep,\n])\n\n// Routine Block\nconst RoutineBlock = z.object({\n\tid: z.string(),\n\tsteps: z.array(Step),\n})\n\n// Routine (array of RoutineBlocks)\nconst Routine = z.array(RoutineBlock)\n\nconst Routines = z.array(Routine)\n\nexport type RoutineSchema = z.infer<typeof Routine>\nexport type RoutinesSchema = z.infer<typeof Routines>\nexport type RoutineBlockSchema = z.infer<typeof RoutineBlock>\nexport type StepSchema = z.infer<typeof Step>\nexport type AgentStepSchema = z.infer<typeof AgentStep>\nexport type LLMStepSchema = z.infer<typeof LLMStep>\nexport type LoopAgentStepSchema = z.infer<typeof LoopAgentStep>\nexport type LoopLLMStepSchema = z.infer<typeof LoopLLMStep>\nexport type ToolCallStepSchema = z.infer<typeof ToolCallStep>\nexport type BashStepSchema = z.infer<typeof BashStep>\n\nexport { Routine, RoutineBlock, Routines, Step }\n","import { parse } from 'yaml'\nimport { z } from 'zod'\nimport type { RoutineSchema } from './types'\nimport { Routine } from './types'\n\n/**\n * Deserialize a YAML string into a Routine\n * @param yamlString The YAML string representation of a Routine\n * @returns The parsed and validated Routine\n * @throws Error if the YAML is invalid or doesn't match the Routine schema\n */\nexport function deserializeRoutineFromYAML(yamlString: string): RoutineSchema {\n\ttry {\n\t\t// Parse the YAML string to a JavaScript object\n\t\tconst parsedYaml = parse(yamlString)\n\n\t\t// Validate and transform the parsed YAML against the Routine schema\n\t\tconst validatedRoutine = Routine.parse(parsedYaml)\n\n\t\treturn validatedRoutine\n\t} catch (error) {\n\t\tif (error instanceof z.ZodError) {\n\t\t\t// Enhance Zod validation errors with better context\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid routine format: ${error.errors\n\t\t\t\t\t.map((err) => `${err.path.join('.')} - ${err.message}`)\n\t\t\t\t\t.join(', ')}`,\n\t\t\t)\n\t\t} else if (error instanceof Error) {\n\t\t\t// Handle YAML parsing errors\n\t\t\tthrow new Error(`Failed to parse YAML: ${error.message}`)\n\t\t} else {\n\t\t\tthrow new Error(`Unknown error during routine deserialization: ${String(error)}`)\n\t\t}\n\t}\n}\n","import type { SubscriptionObserver } from '@sourcegraph/observable'\nimport type { ToolRun } from '../../tool-service'\nimport type { RunRoutineProgressMessage, RunRoutineToolDef } from './common'\n\n/**\n * Class that maintains state for status messages in run_routine implementation.\n * Keeps track of all status messages and reports them through the observer.\n */\nexport class ProgressReporter {\n\tprivate progressMessages: RunRoutineProgressMessage[] = []\n\n\tconstructor(\n\t\tprivate observer: SubscriptionObserver<ToolRun<RunRoutineToolDef>>,\n\t\tprivate signal: AbortSignal,\n\t) {}\n\n\t/**\n\t * Adds the latest message to the list of all status updates and then invokes the observer\n\t * with the updated 'in-progress' status.\n\t */\n\tupdate(update: ToolRun<RunRoutineToolDef>): void {\n\t\tthis.signal.throwIfAborted()\n\t\tif ('progress' in update && update.progress) {\n\t\t\tif (Array.isArray(update.progress)) {\n\t\t\t\tthis.progressMessages.push(...update.progress)\n\t\t\t} else {\n\t\t\t\tthis.progressMessages.push(update.progress)\n\t\t\t}\n\t\t\tthis.observer.next({\n\t\t\t\t...update,\n\t\t\t\tprogress: this.progressMessages,\n\t\t\t})\n\t\t} else {\n\t\t\tthis.observer.next(update)\n\t\t}\n\t}\n\n\terror(error: unknown): void {\n\t\tthis.observer.error(error)\n\t}\n\n\tcomplete(): void {\n\t\tthis.observer.complete()\n\t}\n}\n\n/**\n * Apply variable substitutions to a prompt string\n */\nexport function substitutePromptVars(prompt: string, vars: { userInput?: string }): string {\n\tlet result = prompt\n\n\t// Replace {{userInput}} with the actual user input if provided\n\tif (vars.userInput) {\n\t\tresult = result.replace(/\\{\\{\\s*userInput\\s*\\}\\}/g, vars.userInput)\n\t\tresult = result.replace(/\\{\\{\\s*user_input\\s*\\}\\}/g, vars.userInput)\n\t}\n\n\treturn result\n}\n","import { firstValueFrom } from '@sourcegraph/observable'\nimport {\n\tACTIVE_MODEL,\n\tAnthropicConverters,\n\tfromAnthropicResultToThreadDelta,\n\trunAnthropicSync,\n} from '../../../inference/backends/anthropic'\nimport { buildSystemPrompt, DefaultSystemPromptService } from '../../../threads/system-prompt'\nimport type { ToolUseBlock } from '../../../threads/thread'\nimport {\n\ttoolResultBlocks,\n\ttype Thread,\n\ttype ThreadAssistantMessage,\n\ttype ToolRunUserInput,\n} from '../../../threads/thread'\nimport type { ThreadDelta } from '../../../threads/thread-delta'\nimport { applyThreadDelta } from '../../../threads/thread-delta'\nimport type {\n\tToolDefinition,\n\tToolRun,\n\tToolRunEnvironment,\n\tToolService,\n} from '../../../tools/tool-service'\nimport { createToolService, isToolRunTerminalState } from '../../../tools/tool-service'\nimport { registerBuiltinToolsToToolService } from '../../tools'\nimport type { AgentStepSchema, LLMStepSchema, StepSchema } from './types'\nimport { substitutePromptVars, type ProgressReporter } from './util'\n\n/**\n * Run a step with the given conversation\n */\nexport function runStep(\n\tstep: StepSchema,\n\tconversation: Thread,\n\tenv: ToolRunEnvironment,\n\tprogressReporter: ProgressReporter,\n\tvars: { userInput?: string },\n\tsignal: AbortSignal = new AbortController().signal,\n): Promise<Thread> {\n\tswitch (step.type) {\n\t\tcase 'agent':\n\t\t\treturn runStepAgent(step, conversation, env, progressReporter, vars, signal)\n\t\t\tbreak\n\t\tcase 'llm':\n\t\t\treturn runStepLLM(step, conversation, progressReporter, vars, signal)\n\t\t\tbreak\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown step type: ${(step as any).type}`)\n\t}\n}\n\n/**\n * Run an agent step that implements a full agentic loop\n * Follows the pattern: inference -> tool calls -> tool results -> inference\n * until there are no more tool calls or the process is complete\n */\nasync function runStepAgent(\n\tstep: AgentStepSchema,\n\torigConversation: Thread,\n\tenv: ToolRunEnvironment,\n\tprogressReporter: ProgressReporter,\n\tvars: { userInput?: string },\n\tsignal: AbortSignal,\n): Promise<Thread> {\n\tconst toolService = createToolService()\n\tawait registerBuiltinToolsToToolService(toolService)\n\n\t// Process prompt template with variables if provided\n\tconst promptText = substitutePromptVars(step.prompt, vars)\n\n\t// Clone convo\n\tlet conversation = origConversation\n\tconst recordThreadDelta = (delta: ThreadDelta) => {\n\t\tconversation = applyThreadDelta(conversation, delta)\n\t}\n\n\trecordThreadDelta({\n\t\ttype: 'user:message',\n\t\tmessage: {\n\t\t\tcontent: [{ type: 'text', text: promptText }],\n\t\t\tmeta: {\n\t\t\t\tsentAt: Date.now(),\n\t\t\t},\n\t\t},\n\t})\n\n\t// Update progress with user message added\n\tprogressReporter.update({\n\t\tstatus: 'in-progress',\n\t\tprogress: { type: 'message', speaker: 'user', message: promptText },\n\t})\n\n\t// Get enabled tools from toolService (all tools for now)\n\tconst enabledToolSpecs = (await firstValueFrom(toolService.tools, signal)).map((t) => t.spec)\n\n\t// Set up parameters for the initial API call\n\tconst model = ACTIVE_MODEL\n\n\t// The agent loop will continue until there are no more tool calls needed\n\tlet loopCount = 0\n\tconst maxLoops = 100 // Prevent infinite loops\n\n\twhile (loopCount < maxLoops) {\n\t\tsignal.throwIfAborted()\n\t\tloopCount++\n\n\t\t// Get system prompt blocks from the main system prompt builder\n\t\tconst systemPromptService = new DefaultSystemPromptService()\n\t\t// Get the main system prompt blocks\n\t\tconst systemPromptBlocks = await buildSystemPrompt(systemPromptService, {\n\t\t\tenabledTodos: false,\n\t\t\tthreadEnv: env.threadEnvironment,\n\t\t})\n\n\t\t// Add the subagent-specific instruction as the final block\n\t\tsystemPromptBlocks.push({\n\t\t\ttype: 'text' as const,\n\t\t\ttext: 'You are a helpful AI assistant running as a subagent within a larger system. Your task is to handle this specific step in a routine. You can use tools to complete your task. When you are completely done, do not ask to use more tools.',\n\t\t})\n\n\t\t// Use the combined system prompt\n\t\tconst systemPrompt = systemPromptBlocks\n\n\t\tsignal.throwIfAborted()\n\n\t\t// Use runAnthropicSync to get a response\n\t\tlet result\n\t\ttry {\n\t\t\tconst anthropicMessages = AnthropicConverters.fromNativeThread(conversation)\n\t\t\tresult = await runAnthropicSync(\n\t\t\t\tanthropicMessages,\n\t\t\t\tenabledToolSpecs,\n\t\t\t\tsystemPrompt,\n\t\t\t\tmodel,\n\t\t\t\tsignal,\n\t\t\t)\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Anthropic API error: ${error}`)\n\t\t}\n\n\t\tif (!result.message || !('content' in result.message)) {\n\t\t\tthrow new Error('Unexpected response format from Anthropic')\n\t\t}\n\t\tif (result.message.content.length === 0) {\n\t\t\tbreak\n\t\t}\n\n\t\tconst assistantResponseDelta = fromAnthropicResultToThreadDelta(result.message)\n\t\trecordThreadDelta(assistantResponseDelta)\n\n\t\t// Extract text for progress reporting\n\t\tconst assistantText = result.message.content\n\t\t\t.filter((item) => item.type === 'text')\n\t\t\t.map((item) => ('text' in item ? item.text : ''))\n\t\t\t.join(' ')\n\t\t\t.trim()\n\t\tif (assistantText) {\n\t\t\t// Show assistant message\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: { type: 'message', speaker: 'assistant', message: assistantText },\n\t\t\t})\n\t\t}\n\n\t\tif (assistantResponseDelta.type !== 'assistant:message') {\n\t\t\t// No tool calls\n\t\t\tbreak\n\t\t}\n\n\t\tconst toolCalls = findToolUsesNeedingInvocation(\n\t\t\tconversation,\n\t\t\tassistantResponseDelta.message,\n\t\t)\n\t\tfor (const toolCall of toolCalls) {\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: {\n\t\t\t\t\tid: toolCall.id,\n\t\t\t\t\ttype: 'toolCall',\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\targs: JSON.stringify(toolCall.input),\n\t\t\t\t},\n\t\t\t})\n\n\t\t\tlet toolResult\n\t\t\ttry {\n\t\t\t\ttoolResult = await invokeToolAndWaitForResult(\n\t\t\t\t\ttoolService,\n\t\t\t\t\ttoolCall.name,\n\t\t\t\t\ttoolCall.input,\n\t\t\t\t\tenv,\n\t\t\t\t\tsignal,\n\t\t\t\t)\n\t\t\t\tsignal.throwIfAborted()\n\t\t\t\tif (toolResult.status !== 'done') {\n\t\t\t\t\tthrow new Error(JSON.stringify(toolResult))\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\trecordThreadDelta({\n\t\t\t\t\ttype: 'tool:data',\n\t\t\t\t\ttoolUse: toolCall.id,\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tstatus: 'error',\n\t\t\t\t\t\terror: { message: `Tool call error: ${error}` },\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tprogressReporter.update({\n\t\t\t\t\tstatus: 'in-progress',\n\t\t\t\t\tprogress: {\n\t\t\t\t\t\tid: toolCall.id,\n\t\t\t\t\t\ttype: 'toolResult',\n\t\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\t\tresult: `Tool call error: ${error}`,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\trecordThreadDelta({\n\t\t\t\ttype: 'tool:data',\n\t\t\t\ttoolUse: toolCall.id,\n\t\t\t\tdata: toolResult,\n\t\t\t})\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: {\n\t\t\t\t\tid: toolCall.id,\n\t\t\t\t\ttype: 'toolResult',\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\tresult:\n\t\t\t\t\t\ttypeof toolResult.result === 'string'\n\t\t\t\t\t\t\t? toolResult.result\n\t\t\t\t\t\t\t: JSON.stringify(toolResult.result),\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t}\n\treturn conversation\n}\n\n/**\n * Mock implementation of tool execution for the subagent\n * In a real implementation, this would connect to the actual tool execution system\n */\n// Removed mock implementation in favor of actual toolService\n\n/**\n * Run an LLM step\n */\nasync function runStepLLM(\n\tstep: LLMStepSchema,\n\torigConversation: Thread,\n\tprogressReporter: ProgressReporter,\n\tvars: { userInput?: string },\n\tsignal: AbortSignal,\n): Promise<Thread> {\n\t// Process prompt template with variables if provided\n\tconst promptText = substitutePromptVars(step.prompt, vars)\n\n\t// Create a copy of the conversation to avoid mutating the original\n\tlet conversation = origConversation\n\tconst recordThreadDelta = (delta: ThreadDelta) => {\n\t\tconversation = applyThreadDelta(conversation, delta)\n\t}\n\n\trecordThreadDelta({\n\t\ttype: 'user:message',\n\t\tmessage: {\n\t\t\tcontent: [{ type: 'text', text: promptText }],\n\t\t\tmeta: {\n\t\t\t\tsentAt: Date.now(),\n\t\t\t},\n\t\t},\n\t})\n\n\t// Update progress with user message added\n\tprogressReporter.update({\n\t\tstatus: 'in-progress',\n\t\tprogress: { type: 'message', speaker: 'user', message: promptText },\n\t})\n\n\t// Use runAnthropicSync to get a response\n\tconst anthropicMessages = AnthropicConverters.fromNativeThread(conversation)\n\tconst model = step.model || ACTIVE_MODEL\n\tconst result = await runAnthropicSync(\n\t\tanthropicMessages,\n\t\t[], // No tools for LLM-only step\n\t\t[], // No system prompt\n\t\tmodel,\n\t\tsignal,\n\t)\n\n\tif (!result.message) {\n\t\tthrow new Error('Failed to get response from Anthropic')\n\t}\n\n\tconst assistantResponseDelta = fromAnthropicResultToThreadDelta(result.message)\n\trecordThreadDelta(assistantResponseDelta)\n\n\t// Display message\n\tconst assistantText = result.message.content\n\t\t.filter((item) => item.type === 'text')\n\t\t.map((item) => (item.type === 'text' ? item.text : ''))\n\t\t.join(' ')\n\t\t.trim()\n\tprogressReporter.update({\n\t\tstatus: 'in-progress',\n\t\tprogress: { type: 'message', speaker: 'assistant', message: assistantText },\n\t})\n\treturn conversation\n}\n\nfunction findToolUsesNeedingInvocation(\n\tthread: Thread,\n\tmessage: ThreadAssistantMessage,\n): ToolUseBlock[] {\n\tconst toolResults = toolResultBlocks(thread)\n\treturn message.content\n\t\t.filter((block): block is ToolUseBlock => block.type === 'tool_use')\n\t\t.filter((block) => !block.inputPartialJSON)\n\t\t.filter(\n\t\t\t(block) =>\n\t\t\t\t// Only include tools that haven't been invoked yet.\n\t\t\t\t!toolResults.has(block.id),\n\t\t)\n}\n\n/**\n * Helper function that invokes a tool and returns a Promise with the final result\n */\nexport async function invokeToolAndWaitForResult<T extends ToolDefinition>(\n\ttoolService: ToolService,\n\ttoolName: string,\n\tinput: unknown,\n\tenv: ToolRunEnvironment,\n\tsignal: AbortSignal = new AbortController().signal,\n\tuserInput?: ToolRunUserInput,\n): Promise<ToolRun<T>> {\n\treturn new Promise((resolve, reject) => {\n\t\tlet settled = false\n\t\tconst sub = toolService\n\t\t\t.invokeTool(toolName, { args: input as any, userInput }, env)\n\t\t\t.subscribe({\n\t\t\t\tnext: (run: ToolRun) => {\n\t\t\t\t\tif (isToolRunTerminalState(run)) {\n\t\t\t\t\t\tsub.unsubscribe()\n\t\t\t\t\t\tif (!settled) {\n\t\t\t\t\t\t\tsettled = true\n\t\t\t\t\t\t\tresolve(run)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\terror: (error) => {\n\t\t\t\t\tif (!settled) {\n\t\t\t\t\t\tsettled = true\n\t\t\t\t\t\treject(error)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tcomplete: () => {},\n\t\t\t})\n\n\t\t// Handle abort signal\n\t\tsignal.addEventListener('abort', () => {\n\t\t\tsub.unsubscribe()\n\t\t\tif (!settled) {\n\t\t\t\tsettled = true\n\t\t\t\treject(new Error('Tool execution was aborted'))\n\t\t\t}\n\t\t})\n\t})\n}\n","import { Observable } from '@sourcegraph/observable'\nimport { isAbortError } from '../../../common/abort'\nimport logger from '../../../common/logger'\nimport type { Thread } from '../../../threads/thread'\nimport { newThreadID } from '../../../threads/thread'\nimport type { ToolRunEnvironment } from '../../tool-service'\nimport { createToolService } from '../../tool-service'\nimport type { ReadFileToolDef } from '../filesystem/read_file.common'\nimport { readFileToolReg } from '../filesystem/read_file.common'\nimport type { runRoutineToolReg } from './common'\nimport { deserializeRoutineFromYAML } from './serialization'\nimport { invokeToolAndWaitForResult, runStep } from './step'\nimport { ProgressReporter } from './util'\n\nexport const runRoutine: NonNullable<(typeof runRoutineToolReg)['fn']> = ({ args }, env) => {\n\treturn new Observable((observer) => {\n\t\tconst abortController = new AbortController()\n\t\tconst progressReporter = new ProgressReporter(observer, abortController.signal)\n\n\t\trunRoutineImpl(args, env, progressReporter, abortController.signal).catch((error) => {\n\t\t\t// Don't report AbortError as an error - it's expected when cancelling\n\t\t\tif (!isAbortError(error)) {\n\t\t\t\tprogressReporter.error(error)\n\t\t\t} else {\n\t\t\t\tprogressReporter.update({\n\t\t\t\t\tstatus: 'cancelled' as const,\n\t\t\t\t\tprogress: { type: 'meta', message: 'Operation cancelled' },\n\t\t\t\t})\n\t\t\t\tprogressReporter.complete()\n\t\t\t}\n\t\t})\n\n\t\treturn () => {\n\t\t\tabortController.abort()\n\t\t}\n\t})\n}\n\nasync function runRoutineImpl(\n\targs: { id: string; file?: string; userInput?: string },\n\tenv: ToolRunEnvironment,\n\tprogressReporter: ProgressReporter,\n\tsignal: AbortSignal,\n) {\n\ttry {\n\t\tconst { id, file } = args\n\t\tconst routineFile = file || 'routines.amp.yaml'\n\n\t\t// Report initial progress\n\t\tprogressReporter.update({\n\t\t\tstatus: 'in-progress',\n\t\t\tprogress: { type: 'meta', message: `Loading routine: ${id} from ${routineFile}` },\n\t\t})\n\n\t\t// Create a tool service and register the read_file tool\n\t\tconst toolService = createToolService()\n\t\ttoolService.registerTool(readFileToolReg)\n\n\t\t// Read the routine file using the tool service\n\t\tconst readFileResult = await invokeToolAndWaitForResult<ReadFileToolDef>(\n\t\t\ttoolService,\n\t\t\t'read_file',\n\t\t\t{ path: routineFile },\n\t\t\tenv,\n\t\t\tsignal,\n\t\t)\n\n\t\t// Process the file content by removing line numbers that read_file adds\n\t\tif (readFileResult.status !== 'done') {\n\t\t\tthrow new Error(`Failed to read routine file: ${routineFile}`)\n\t\t}\n\t\t// At this point TypeScript knows readFileResult has a 'result' property\n\t\tconst fileContents =\n\t\t\ttypeof readFileResult.result === 'string'\n\t\t\t\t? readFileResult.result\n\t\t\t\t: readFileResult.result.content\n\t\tconst routineContent = String(fileContents)\n\t\t\t.split('\\n')\n\t\t\t.map((line: string) => line.replace(/^\\d+:\\s/, ''))\n\t\t\t.join('\\n')\n\n\t\tsignal.throwIfAborted()\n\n\t\t// Parse the routines\n\t\tconst routines = deserializeRoutineFromYAML(routineContent)\n\t\tsignal.throwIfAborted()\n\n\t\t// Find the requested routine\n\t\tconst routine = routines.find((routine) => routine.id === id)\n\t\tif (!routine) {\n\t\t\tthrow new Error(`Routine with id \"${id}\" not found in ${routineFile}`)\n\t\t}\n\n\t\t// Initialize a Thread for the conversation\n\t\tlet conversation: Thread = {\n\t\t\tid: newThreadID(),\n\t\t\tcreated: Date.now(),\n\t\t\tv: 0,\n\t\t\tmessages: [],\n\t\t}\n\n\t\t// Report progress before executing steps\n\t\tprogressReporter.update({\n\t\t\tstatus: 'in-progress',\n\t\t\tprogress: [\n\t\t\t\t{\n\t\t\t\t\ttype: 'meta',\n\t\t\t\t\tmessage: `Executing routine ${id}`,\n\t\t\t\t},\n\t\t\t],\n\t\t})\n\n\t\t// Execute each step in the routine\n\t\tfor (let i = 0; i < routine.steps.length; i++) {\n\t\t\tconst step = routine.steps[i]\n\t\t\tif (!step) continue // Skip undefined steps\n\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'meta',\n\t\t\t\t\t\tmessage: `Executing step ${i + 1}/${routine.steps.length}: ${step.type}`,\n\t\t\t\t\t\tvariant: 'header',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t})\n\n\t\t\tsignal.throwIfAborted()\n\n\t\t\t// Execute the step and update the conversation\n\t\t\tconversation = await runStep(step, conversation, env, progressReporter, {\n\t\t\t\tuserInput: args.userInput,\n\t\t\t})\n\t\t}\n\n\t\tprogressReporter.update({\n\t\t\tstatus: 'done' as const,\n\t\t\tprogress: {\n\t\t\t\ttype: 'meta',\n\t\t\t\tmessage: `Finished executing all ${routine.steps.length} steps of routine: ${id}.`,\n\t\t\t\tvariant: 'header',\n\t\t\t},\n\t\t\tresult: '', // No output for now\n\t\t})\n\n\t\tprogressReporter.complete()\n\t} catch (error) {\n\t\tif (isAbortError(error)) {\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'cancelled' as const,\n\t\t\t\tprogress: {\n\t\t\t\t\ttype: 'meta',\n\t\t\t\t\tmessage: 'Operation cancelled',\n\t\t\t\t},\n\t\t\t})\n\t\t\tprogressReporter.complete()\n\t\t} else {\n\t\t\tlogger.error('Error in run_routine', {\n\t\t\t\terror,\n\t\t\t\tstack: error instanceof Error ? error.stack : '',\n\t\t\t})\n\t\t\tprogressReporter.error(error)\n\t\t}\n\t}\n}\n"],"names":["BaseStep","z.object","z.enum","z.union","z.literal","z.array","z.string","z.record","z.any","AgentStep","z.boolean","LLMStep","LoopAgentStep","LoopLLMStep","ToolCallStep","BashStep","Step","z.discriminatedUnion","RoutineBlock","Routine","deserializeRoutineFromYAML","yamlString","parsedYaml","parse","error","z.ZodError","err","ProgressReporter","observer","signal","update","substitutePromptVars","prompt","vars","result","runStep","step","conversation","env","progressReporter","runStepAgent","runStepLLM","origConversation","toolService","createToolService","registerBuiltinToolsToToolService","promptText","recordThreadDelta","delta","applyThreadDelta","enabledToolSpecs","firstValueFrom","t","model","ACTIVE_MODEL","loopCount","maxLoops","systemPromptService","DefaultSystemPromptService","systemPromptBlocks","buildSystemPrompt","systemPrompt","anthropicMessages","AnthropicConverters","runAnthropicSync","assistantResponseDelta","fromAnthropicResultToThreadDelta","assistantText","item","toolCalls","findToolUsesNeedingInvocation","toolCall","toolResult","invokeToolAndWaitForResult","thread","message","toolResults","toolResultBlocks","block","toolName","input","userInput","resolve","reject","settled","sub","run","isToolRunTerminalState","runRoutine","args","Observable","abortController","runRoutineImpl","isAbortError","id","file","routineFile","readFileToolReg","readFileResult","fileContents","routineContent","line","routines","routine","newThreadID","i","logger"],"mappings":";;;AAGA,MAAMA,IAAWC,EAAS;AAAA,EACzB,SAASC,EAAO,CAAC,YAAY,MAAM,CAAC,EAAE,SAAA,EAAW,QAAQ,UAAU;AAAA,EACnE,OAAOC,EAAQ,CAACC,EAAU,KAAK,GAAGC,EAAQC,EAAU,CAAA,CAAC,CAAC,EAAE,SAAS;AAAA,EACjE,QAAQA,EAAS;AAAA,EACjB,QAAQC,EAASC,EAAO,CAAA,EAAE,SAAS;AACpC,CAAC,GAQKC,KAAYT,EAAS,OAAO;AAAA,EACjC,MAAMI,EAAU,OAAO;AAAA,EACvB,OAAOE,EAAS,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E,EAAK,IAAI;AAAA,YACtE,SAAS;AAAA,UAAA;AAAA,QACV;AAAA,MACD,CACA,GAEDP,EAAO,eAAe,GAGtBQ,IAAe,MAAMF,GAAQC,GAAMC,GAAcC,GAAKC,GAAkB;AAAA,QACvE,WAAWkD,EAAK;AAAA,MAAA,CAChB;AAAA,IAAA;AAGF,IAAAlD,EAAiB,OAAO;AAAA,MACvB,QAAQ;AAAA,MACR,UAAU;AAAA,QACT,MAAM;AAAA,QACN,SAAS,0BAA0BgE,EAAQ,MAAM,MAAM,sBAAsBT,CAAE;AAAA,QAC/E,SAAS;AAAA,MACV;AAAA,MACA,QAAQ;AAAA;AAAA,IAAA,CACR,GAEDvD,EAAiB,SAAS;AAAA,WAClBf,GAAO;AACX,IAAAqE,EAAarE,CAAK,KACrBe,EAAiB,OAAO;AAAA,MACvB,QAAQ;AAAA,MACR,UAAU;AAAA,QACT,MAAM;AAAA,QACN,SAAS;AAAA,MAAA;AAAA,IACV,CACA,GACDA,EAAiB,SAAS,MAE1BmE,EAAO,MAAM,wBAAwB;AAAA,MACpC,OAAAlF;AAAA,MACA,OAAOA,aAAiB,QAAQA,EAAM,QAAQ;AAAA,IAAA,CAC9C,GACDe,EAAiB,MAAMf,CAAK;AAAA,EAC7B;AAEF;"}
1
+ {"version":3,"file":"node-B8WXoxgO.js","sources":["../../core/src/tools/builtin/run_routine/types.ts","../../core/src/tools/builtin/run_routine/serialization.ts","../../core/src/tools/builtin/run_routine/util.ts","../../core/src/tools/builtin/run_routine/step.ts","../../core/src/tools/builtin/run_routine/node.ts"],"sourcesContent":["import { z } from 'zod'\n\n// Base Step interface\nconst BaseStep = z.object({\n\tcontext: z.enum(['continue', 'none']).optional().default('continue'),\n\ttools: z.union([z.literal('all'), z.array(z.string())]).optional(),\n\tprompt: z.string(),\n\tverify: z.record(z.any()).optional(),\n}) satisfies z.ZodType<{\n\tcontext?: 'continue' | 'none'\n\ttools?: 'all' | string[]\n\tprompt: string\n\tverify?: Record<string, any>\n}>\n\n// Agent Step\nconst AgentStep = BaseStep.extend({\n\ttype: z.literal('agent'),\n\tmodel: z.string().optional(), // Default could be set in implementation\n\tinteractive_confirmation: z.boolean().optional(),\n})\n\n// LLM Step\nconst LLMStep = BaseStep.extend({\n\ttype: z.literal('llm'),\n\tmodel: z.string().optional(),\n})\n\n// Loop Agent Step\nconst LoopAgentStep = BaseStep.extend({\n\ttype: z.literal('loop_agent'),\n\tmodel: z.string().optional(),\n\tinput_file: z.string(),\n})\n\n// Loop LLM Step\nconst LoopLLMStep = BaseStep.extend({\n\ttype: z.literal('loop_llm'),\n\tmodel: z.string().optional(),\n\tinput_file: z.string(),\n})\n\n// Tool Call Step\nconst ToolCallStep = z.object({\n\ttype: z.literal('tool_call'),\n\ttool: z.string(),\n\tparameters: z.record(z.any()).optional(),\n})\n\n// Bash Step\nconst BashStep = z.object({\n\ttype: z.literal('bash'),\n\tcommand: z.string(),\n})\n\n// Union of all step types\nconst Step = z.discriminatedUnion('type', [\n\tAgentStep,\n\tLLMStep,\n\tLoopAgentStep,\n\tLoopLLMStep,\n\tToolCallStep,\n\tBashStep,\n])\n\n// Routine Block\nconst RoutineBlock = z.object({\n\tid: z.string(),\n\tsteps: z.array(Step),\n})\n\n// Routine (array of RoutineBlocks)\nconst Routine = z.array(RoutineBlock)\n\nconst Routines = z.array(Routine)\n\nexport type RoutineSchema = z.infer<typeof Routine>\nexport type RoutinesSchema = z.infer<typeof Routines>\nexport type RoutineBlockSchema = z.infer<typeof RoutineBlock>\nexport type StepSchema = z.infer<typeof Step>\nexport type AgentStepSchema = z.infer<typeof AgentStep>\nexport type LLMStepSchema = z.infer<typeof LLMStep>\nexport type LoopAgentStepSchema = z.infer<typeof LoopAgentStep>\nexport type LoopLLMStepSchema = z.infer<typeof LoopLLMStep>\nexport type ToolCallStepSchema = z.infer<typeof ToolCallStep>\nexport type BashStepSchema = z.infer<typeof BashStep>\n\nexport { Routine, RoutineBlock, Routines, Step }\n","import { parse } from 'yaml'\nimport { z } from 'zod'\nimport type { RoutineSchema } from './types'\nimport { Routine } from './types'\n\n/**\n * Deserialize a YAML string into a Routine\n * @param yamlString The YAML string representation of a Routine\n * @returns The parsed and validated Routine\n * @throws Error if the YAML is invalid or doesn't match the Routine schema\n */\nexport function deserializeRoutineFromYAML(yamlString: string): RoutineSchema {\n\ttry {\n\t\t// Parse the YAML string to a JavaScript object\n\t\tconst parsedYaml = parse(yamlString)\n\n\t\t// Validate and transform the parsed YAML against the Routine schema\n\t\tconst validatedRoutine = Routine.parse(parsedYaml)\n\n\t\treturn validatedRoutine\n\t} catch (error) {\n\t\tif (error instanceof z.ZodError) {\n\t\t\t// Enhance Zod validation errors with better context\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid routine format: ${error.errors\n\t\t\t\t\t.map((err) => `${err.path.join('.')} - ${err.message}`)\n\t\t\t\t\t.join(', ')}`,\n\t\t\t)\n\t\t} else if (error instanceof Error) {\n\t\t\t// Handle YAML parsing errors\n\t\t\tthrow new Error(`Failed to parse YAML: ${error.message}`)\n\t\t} else {\n\t\t\tthrow new Error(`Unknown error during routine deserialization: ${String(error)}`)\n\t\t}\n\t}\n}\n","import type { SubscriptionObserver } from '@sourcegraph/observable'\nimport type { ToolRun } from '../../tool-service'\nimport type { RunRoutineProgressMessage, RunRoutineToolDef } from './common'\n\n/**\n * Class that maintains state for status messages in run_routine implementation.\n * Keeps track of all status messages and reports them through the observer.\n */\nexport class ProgressReporter {\n\tprivate progressMessages: RunRoutineProgressMessage[] = []\n\n\tconstructor(\n\t\tprivate observer: SubscriptionObserver<ToolRun<RunRoutineToolDef>>,\n\t\tprivate signal: AbortSignal,\n\t) {}\n\n\t/**\n\t * Adds the latest message to the list of all status updates and then invokes the observer\n\t * with the updated 'in-progress' status.\n\t */\n\tupdate(update: ToolRun<RunRoutineToolDef>): void {\n\t\tthis.signal.throwIfAborted()\n\t\tif ('progress' in update && update.progress) {\n\t\t\tif (Array.isArray(update.progress)) {\n\t\t\t\tthis.progressMessages.push(...update.progress)\n\t\t\t} else {\n\t\t\t\tthis.progressMessages.push(update.progress)\n\t\t\t}\n\t\t\tthis.observer.next({\n\t\t\t\t...update,\n\t\t\t\tprogress: this.progressMessages,\n\t\t\t})\n\t\t} else {\n\t\t\tthis.observer.next(update)\n\t\t}\n\t}\n\n\terror(error: unknown): void {\n\t\tthis.observer.error(error)\n\t}\n\n\tcomplete(): void {\n\t\tthis.observer.complete()\n\t}\n}\n\n/**\n * Apply variable substitutions to a prompt string\n */\nexport function substitutePromptVars(prompt: string, vars: { userInput?: string }): string {\n\tlet result = prompt\n\n\t// Replace {{userInput}} with the actual user input if provided\n\tif (vars.userInput) {\n\t\tresult = result.replace(/\\{\\{\\s*userInput\\s*\\}\\}/g, vars.userInput)\n\t\tresult = result.replace(/\\{\\{\\s*user_input\\s*\\}\\}/g, vars.userInput)\n\t}\n\n\treturn result\n}\n","import { firstValueFrom } from '@sourcegraph/observable'\nimport {\n\tACTIVE_MODEL,\n\tAnthropicConverters,\n\tfromAnthropicResultToThreadDelta,\n\trunAnthropicSync,\n} from '../../../inference/backends/anthropic'\nimport { buildSystemPrompt, DefaultSystemPromptService } from '../../../threads/system-prompt'\nimport type { ToolUseBlock } from '../../../threads/thread'\nimport {\n\ttoolResultBlocks,\n\ttype Thread,\n\ttype ThreadAssistantMessage,\n\ttype ToolRunUserInput,\n} from '../../../threads/thread'\nimport type { ThreadDelta } from '../../../threads/thread-delta'\nimport { applyThreadDelta } from '../../../threads/thread-delta'\nimport type {\n\tToolDefinition,\n\tToolRun,\n\tToolRunEnvironment,\n\tToolService,\n} from '../../../tools/tool-service'\nimport { createToolService, isToolRunTerminalState } from '../../../tools/tool-service'\nimport { registerBuiltinToolsToToolService } from '../../tools'\nimport type { AgentStepSchema, LLMStepSchema, StepSchema } from './types'\nimport { substitutePromptVars, type ProgressReporter } from './util'\n\n/**\n * Run a step with the given conversation\n */\nexport function runStep(\n\tstep: StepSchema,\n\tconversation: Thread,\n\tenv: ToolRunEnvironment,\n\tprogressReporter: ProgressReporter,\n\tvars: { userInput?: string },\n\tsignal: AbortSignal = new AbortController().signal,\n): Promise<Thread> {\n\tswitch (step.type) {\n\t\tcase 'agent':\n\t\t\treturn runStepAgent(step, conversation, env, progressReporter, vars, signal)\n\t\t\tbreak\n\t\tcase 'llm':\n\t\t\treturn runStepLLM(step, conversation, progressReporter, vars, signal)\n\t\t\tbreak\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown step type: ${(step as any).type}`)\n\t}\n}\n\n/**\n * Run an agent step that implements a full agentic loop\n * Follows the pattern: inference -> tool calls -> tool results -> inference\n * until there are no more tool calls or the process is complete\n */\nasync function runStepAgent(\n\tstep: AgentStepSchema,\n\torigConversation: Thread,\n\tenv: ToolRunEnvironment,\n\tprogressReporter: ProgressReporter,\n\tvars: { userInput?: string },\n\tsignal: AbortSignal,\n): Promise<Thread> {\n\tconst toolService = createToolService()\n\tawait registerBuiltinToolsToToolService(toolService)\n\n\t// Process prompt template with variables if provided\n\tconst promptText = substitutePromptVars(step.prompt, vars)\n\n\t// Clone convo\n\tlet conversation = origConversation\n\tconst recordThreadDelta = (delta: ThreadDelta) => {\n\t\tconversation = applyThreadDelta(conversation, delta)\n\t}\n\n\trecordThreadDelta({\n\t\ttype: 'user:message',\n\t\tmessage: {\n\t\t\tcontent: [{ type: 'text', text: promptText }],\n\t\t\tmeta: {\n\t\t\t\tsentAt: Date.now(),\n\t\t\t},\n\t\t},\n\t})\n\n\t// Update progress with user message added\n\tprogressReporter.update({\n\t\tstatus: 'in-progress',\n\t\tprogress: { type: 'message', speaker: 'user', message: promptText },\n\t})\n\n\t// Get enabled tools from toolService (all tools for now)\n\tconst enabledToolSpecs = (await firstValueFrom(toolService.tools, signal)).map((t) => t.spec)\n\n\t// Set up parameters for the initial API call\n\tconst model = ACTIVE_MODEL\n\n\t// The agent loop will continue until there are no more tool calls needed\n\tlet loopCount = 0\n\tconst maxLoops = 100 // Prevent infinite loops\n\n\twhile (loopCount < maxLoops) {\n\t\tsignal.throwIfAborted()\n\t\tloopCount++\n\n\t\t// Get system prompt blocks from the main system prompt builder\n\t\tconst systemPromptService = new DefaultSystemPromptService()\n\t\t// Get the main system prompt blocks\n\t\tconst systemPromptBlocks = await buildSystemPrompt(systemPromptService, {\n\t\t\tenabledTodos: false,\n\t\t\tthreadEnv: env.threadEnvironment,\n\t\t})\n\n\t\t// Add the subagent-specific instruction as the final block\n\t\tsystemPromptBlocks.push({\n\t\t\ttype: 'text' as const,\n\t\t\ttext: 'You are a helpful AI assistant running as a subagent within a larger system. Your task is to handle this specific step in a routine. You can use tools to complete your task. When you are completely done, do not ask to use more tools.',\n\t\t})\n\n\t\t// Use the combined system prompt\n\t\tconst systemPrompt = systemPromptBlocks\n\n\t\tsignal.throwIfAborted()\n\n\t\t// Use runAnthropicSync to get a response\n\t\tlet result\n\t\ttry {\n\t\t\tconst anthropicMessages = AnthropicConverters.fromNativeThread(conversation)\n\t\t\tresult = await runAnthropicSync(\n\t\t\t\tanthropicMessages,\n\t\t\t\tenabledToolSpecs,\n\t\t\t\tsystemPrompt,\n\t\t\t\tmodel,\n\t\t\t\tsignal,\n\t\t\t)\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Anthropic API error: ${error}`)\n\t\t}\n\n\t\tif (!result.message || !('content' in result.message)) {\n\t\t\tthrow new Error('Unexpected response format from Anthropic')\n\t\t}\n\t\tif (result.message.content.length === 0) {\n\t\t\tbreak\n\t\t}\n\n\t\tconst assistantResponseDelta = fromAnthropicResultToThreadDelta(result.message)\n\t\trecordThreadDelta(assistantResponseDelta)\n\n\t\t// Extract text for progress reporting\n\t\tconst assistantText = result.message.content\n\t\t\t.filter((item) => item.type === 'text')\n\t\t\t.map((item) => ('text' in item ? item.text : ''))\n\t\t\t.join(' ')\n\t\t\t.trim()\n\t\tif (assistantText) {\n\t\t\t// Show assistant message\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: { type: 'message', speaker: 'assistant', message: assistantText },\n\t\t\t})\n\t\t}\n\n\t\tif (assistantResponseDelta.type !== 'assistant:message') {\n\t\t\t// No tool calls\n\t\t\tbreak\n\t\t}\n\n\t\tconst toolCalls = findToolUsesNeedingInvocation(\n\t\t\tconversation,\n\t\t\tassistantResponseDelta.message,\n\t\t)\n\t\tfor (const toolCall of toolCalls) {\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: {\n\t\t\t\t\tid: toolCall.id,\n\t\t\t\t\ttype: 'toolCall',\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\targs: JSON.stringify(toolCall.input),\n\t\t\t\t},\n\t\t\t})\n\n\t\t\tlet toolResult\n\t\t\ttry {\n\t\t\t\ttoolResult = await invokeToolAndWaitForResult(\n\t\t\t\t\ttoolService,\n\t\t\t\t\ttoolCall.name,\n\t\t\t\t\ttoolCall.input,\n\t\t\t\t\tenv,\n\t\t\t\t\tsignal,\n\t\t\t\t)\n\t\t\t\tsignal.throwIfAborted()\n\t\t\t\tif (toolResult.status !== 'done') {\n\t\t\t\t\tthrow new Error(JSON.stringify(toolResult))\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\trecordThreadDelta({\n\t\t\t\t\ttype: 'tool:data',\n\t\t\t\t\ttoolUse: toolCall.id,\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tstatus: 'error',\n\t\t\t\t\t\terror: { message: `Tool call error: ${error}` },\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tprogressReporter.update({\n\t\t\t\t\tstatus: 'in-progress',\n\t\t\t\t\tprogress: {\n\t\t\t\t\t\tid: toolCall.id,\n\t\t\t\t\t\ttype: 'toolResult',\n\t\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\t\tresult: `Tool call error: ${error}`,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\trecordThreadDelta({\n\t\t\t\ttype: 'tool:data',\n\t\t\t\ttoolUse: toolCall.id,\n\t\t\t\tdata: toolResult,\n\t\t\t})\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: {\n\t\t\t\t\tid: toolCall.id,\n\t\t\t\t\ttype: 'toolResult',\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\tresult:\n\t\t\t\t\t\ttypeof toolResult.result === 'string'\n\t\t\t\t\t\t\t? toolResult.result\n\t\t\t\t\t\t\t: JSON.stringify(toolResult.result),\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t}\n\treturn conversation\n}\n\n/**\n * Mock implementation of tool execution for the subagent\n * In a real implementation, this would connect to the actual tool execution system\n */\n// Removed mock implementation in favor of actual toolService\n\n/**\n * Run an LLM step\n */\nasync function runStepLLM(\n\tstep: LLMStepSchema,\n\torigConversation: Thread,\n\tprogressReporter: ProgressReporter,\n\tvars: { userInput?: string },\n\tsignal: AbortSignal,\n): Promise<Thread> {\n\t// Process prompt template with variables if provided\n\tconst promptText = substitutePromptVars(step.prompt, vars)\n\n\t// Create a copy of the conversation to avoid mutating the original\n\tlet conversation = origConversation\n\tconst recordThreadDelta = (delta: ThreadDelta) => {\n\t\tconversation = applyThreadDelta(conversation, delta)\n\t}\n\n\trecordThreadDelta({\n\t\ttype: 'user:message',\n\t\tmessage: {\n\t\t\tcontent: [{ type: 'text', text: promptText }],\n\t\t\tmeta: {\n\t\t\t\tsentAt: Date.now(),\n\t\t\t},\n\t\t},\n\t})\n\n\t// Update progress with user message added\n\tprogressReporter.update({\n\t\tstatus: 'in-progress',\n\t\tprogress: { type: 'message', speaker: 'user', message: promptText },\n\t})\n\n\t// Use runAnthropicSync to get a response\n\tconst anthropicMessages = AnthropicConverters.fromNativeThread(conversation)\n\tconst model = step.model || ACTIVE_MODEL\n\tconst result = await runAnthropicSync(\n\t\tanthropicMessages,\n\t\t[], // No tools for LLM-only step\n\t\t[], // No system prompt\n\t\tmodel,\n\t\tsignal,\n\t)\n\n\tif (!result.message) {\n\t\tthrow new Error('Failed to get response from Anthropic')\n\t}\n\n\tconst assistantResponseDelta = fromAnthropicResultToThreadDelta(result.message)\n\trecordThreadDelta(assistantResponseDelta)\n\n\t// Display message\n\tconst assistantText = result.message.content\n\t\t.filter((item) => item.type === 'text')\n\t\t.map((item) => (item.type === 'text' ? item.text : ''))\n\t\t.join(' ')\n\t\t.trim()\n\tprogressReporter.update({\n\t\tstatus: 'in-progress',\n\t\tprogress: { type: 'message', speaker: 'assistant', message: assistantText },\n\t})\n\treturn conversation\n}\n\nfunction findToolUsesNeedingInvocation(\n\tthread: Thread,\n\tmessage: ThreadAssistantMessage,\n): ToolUseBlock[] {\n\tconst toolResults = toolResultBlocks(thread)\n\treturn message.content\n\t\t.filter((block): block is ToolUseBlock => block.type === 'tool_use')\n\t\t.filter((block) => !block.inputPartialJSON)\n\t\t.filter(\n\t\t\t(block) =>\n\t\t\t\t// Only include tools that haven't been invoked yet.\n\t\t\t\t!toolResults.has(block.id),\n\t\t)\n}\n\n/**\n * Helper function that invokes a tool and returns a Promise with the final result\n */\nexport async function invokeToolAndWaitForResult<T extends ToolDefinition>(\n\ttoolService: ToolService,\n\ttoolName: string,\n\tinput: unknown,\n\tenv: ToolRunEnvironment,\n\tsignal: AbortSignal = new AbortController().signal,\n\tuserInput?: ToolRunUserInput,\n): Promise<ToolRun<T>> {\n\treturn new Promise((resolve, reject) => {\n\t\tlet settled = false\n\t\tconst sub = toolService\n\t\t\t.invokeTool(toolName, { args: input as any, userInput }, env)\n\t\t\t.subscribe({\n\t\t\t\tnext: (run: ToolRun) => {\n\t\t\t\t\tif (isToolRunTerminalState(run)) {\n\t\t\t\t\t\tsub.unsubscribe()\n\t\t\t\t\t\tif (!settled) {\n\t\t\t\t\t\t\tsettled = true\n\t\t\t\t\t\t\tresolve(run)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\terror: (error) => {\n\t\t\t\t\tif (!settled) {\n\t\t\t\t\t\tsettled = true\n\t\t\t\t\t\treject(error)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tcomplete: () => {},\n\t\t\t})\n\n\t\t// Handle abort signal\n\t\tsignal.addEventListener('abort', () => {\n\t\t\tsub.unsubscribe()\n\t\t\tif (!settled) {\n\t\t\t\tsettled = true\n\t\t\t\treject(new Error('Tool execution was aborted'))\n\t\t\t}\n\t\t})\n\t})\n}\n","import { Observable } from '@sourcegraph/observable'\nimport { isAbortError } from '../../../common/abort'\nimport logger from '../../../common/logger'\nimport type { Thread } from '../../../threads/thread'\nimport { newThreadID } from '../../../threads/thread'\nimport type { ToolRunEnvironment } from '../../tool-service'\nimport { createToolService } from '../../tool-service'\nimport type { ReadFileToolDef } from '../filesystem/read_file.common'\nimport { readFileToolReg } from '../filesystem/read_file.common'\nimport type { runRoutineToolReg } from './common'\nimport { deserializeRoutineFromYAML } from './serialization'\nimport { invokeToolAndWaitForResult, runStep } from './step'\nimport { ProgressReporter } from './util'\n\nexport const runRoutine: NonNullable<(typeof runRoutineToolReg)['fn']> = ({ args }, env) => {\n\treturn new Observable((observer) => {\n\t\tconst abortController = new AbortController()\n\t\tconst progressReporter = new ProgressReporter(observer, abortController.signal)\n\n\t\trunRoutineImpl(args, env, progressReporter, abortController.signal).catch((error) => {\n\t\t\t// Don't report AbortError as an error - it's expected when cancelling\n\t\t\tif (!isAbortError(error)) {\n\t\t\t\tprogressReporter.error(error)\n\t\t\t} else {\n\t\t\t\tprogressReporter.update({\n\t\t\t\t\tstatus: 'cancelled' as const,\n\t\t\t\t\tprogress: { type: 'meta', message: 'Operation cancelled' },\n\t\t\t\t})\n\t\t\t\tprogressReporter.complete()\n\t\t\t}\n\t\t})\n\n\t\treturn () => {\n\t\t\tabortController.abort()\n\t\t}\n\t})\n}\n\nasync function runRoutineImpl(\n\targs: { id: string; file?: string; userInput?: string },\n\tenv: ToolRunEnvironment,\n\tprogressReporter: ProgressReporter,\n\tsignal: AbortSignal,\n) {\n\ttry {\n\t\tconst { id, file } = args\n\t\tconst routineFile = file || 'routines.amp.yaml'\n\n\t\t// Report initial progress\n\t\tprogressReporter.update({\n\t\t\tstatus: 'in-progress',\n\t\t\tprogress: { type: 'meta', message: `Loading routine: ${id} from ${routineFile}` },\n\t\t})\n\n\t\t// Create a tool service and register the read_file tool\n\t\tconst toolService = createToolService()\n\t\ttoolService.registerTool(readFileToolReg)\n\n\t\t// Read the routine file using the tool service\n\t\tconst readFileResult = await invokeToolAndWaitForResult<ReadFileToolDef>(\n\t\t\ttoolService,\n\t\t\t'read_file',\n\t\t\t{ path: routineFile },\n\t\t\tenv,\n\t\t\tsignal,\n\t\t)\n\n\t\t// Process the file content by removing line numbers that read_file adds\n\t\tif (readFileResult.status !== 'done') {\n\t\t\tthrow new Error(`Failed to read routine file: ${routineFile}`)\n\t\t}\n\t\t// At this point TypeScript knows readFileResult has a 'result' property\n\t\tconst fileContents =\n\t\t\ttypeof readFileResult.result === 'string'\n\t\t\t\t? readFileResult.result\n\t\t\t\t: readFileResult.result.content\n\t\tconst routineContent = String(fileContents)\n\t\t\t.split('\\n')\n\t\t\t.map((line: string) => line.replace(/^\\d+:\\s/, ''))\n\t\t\t.join('\\n')\n\n\t\tsignal.throwIfAborted()\n\n\t\t// Parse the routines\n\t\tconst routines = deserializeRoutineFromYAML(routineContent)\n\t\tsignal.throwIfAborted()\n\n\t\t// Find the requested routine\n\t\tconst routine = routines.find((routine) => routine.id === id)\n\t\tif (!routine) {\n\t\t\tthrow new Error(`Routine with id \"${id}\" not found in ${routineFile}`)\n\t\t}\n\n\t\t// Initialize a Thread for the conversation\n\t\tlet conversation: Thread = {\n\t\t\tid: newThreadID(),\n\t\t\tcreated: Date.now(),\n\t\t\tv: 0,\n\t\t\tmessages: [],\n\t\t}\n\n\t\t// Report progress before executing steps\n\t\tprogressReporter.update({\n\t\t\tstatus: 'in-progress',\n\t\t\tprogress: [\n\t\t\t\t{\n\t\t\t\t\ttype: 'meta',\n\t\t\t\t\tmessage: `Executing routine ${id}`,\n\t\t\t\t},\n\t\t\t],\n\t\t})\n\n\t\t// Execute each step in the routine\n\t\tfor (let i = 0; i < routine.steps.length; i++) {\n\t\t\tconst step = routine.steps[i]\n\t\t\tif (!step) continue // Skip undefined steps\n\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'in-progress',\n\t\t\t\tprogress: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'meta',\n\t\t\t\t\t\tmessage: `Executing step ${i + 1}/${routine.steps.length}: ${step.type}`,\n\t\t\t\t\t\tvariant: 'header',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t})\n\n\t\t\tsignal.throwIfAborted()\n\n\t\t\t// Execute the step and update the conversation\n\t\t\tconversation = await runStep(step, conversation, env, progressReporter, {\n\t\t\t\tuserInput: args.userInput,\n\t\t\t})\n\t\t}\n\n\t\tprogressReporter.update({\n\t\t\tstatus: 'done' as const,\n\t\t\tprogress: {\n\t\t\t\ttype: 'meta',\n\t\t\t\tmessage: `Finished executing all ${routine.steps.length} steps of routine: ${id}.`,\n\t\t\t\tvariant: 'header',\n\t\t\t},\n\t\t\tresult: '', // No output for now\n\t\t})\n\n\t\tprogressReporter.complete()\n\t} catch (error) {\n\t\tif (isAbortError(error)) {\n\t\t\tprogressReporter.update({\n\t\t\t\tstatus: 'cancelled' as const,\n\t\t\t\tprogress: {\n\t\t\t\t\ttype: 'meta',\n\t\t\t\t\tmessage: 'Operation cancelled',\n\t\t\t\t},\n\t\t\t})\n\t\t\tprogressReporter.complete()\n\t\t} else {\n\t\t\tlogger.error('Error in run_routine', {\n\t\t\t\terror,\n\t\t\t\tstack: error instanceof Error ? error.stack : '',\n\t\t\t})\n\t\t\tprogressReporter.error(error)\n\t\t}\n\t}\n}\n"],"names":["BaseStep","z.object","z.enum","z.union","z.literal","z.array","z.string","z.record","z.any","AgentStep","z.boolean","LLMStep","LoopAgentStep","LoopLLMStep","ToolCallStep","BashStep","Step","z.discriminatedUnion","RoutineBlock","Routine","deserializeRoutineFromYAML","yamlString","parsedYaml","parse","error","z.ZodError","err","ProgressReporter","observer","signal","update","substitutePromptVars","prompt","vars","result","runStep","step","conversation","env","progressReporter","runStepAgent","runStepLLM","origConversation","toolService","createToolService","registerBuiltinToolsToToolService","promptText","recordThreadDelta","delta","applyThreadDelta","enabledToolSpecs","firstValueFrom","t","model","ACTIVE_MODEL","loopCount","maxLoops","systemPromptService","DefaultSystemPromptService","systemPromptBlocks","buildSystemPrompt","systemPrompt","anthropicMessages","AnthropicConverters","runAnthropicSync","assistantResponseDelta","fromAnthropicResultToThreadDelta","assistantText","item","toolCalls","findToolUsesNeedingInvocation","toolCall","toolResult","invokeToolAndWaitForResult","thread","message","toolResults","toolResultBlocks","block","toolName","input","userInput","resolve","reject","settled","sub","run","isToolRunTerminalState","runRoutine","args","Observable","abortController","runRoutineImpl","isAbortError","id","file","routineFile","readFileToolReg","readFileResult","fileContents","routineContent","line","routines","routine","newThreadID","i","logger"],"mappings":";;;AAGA,MAAMA,IAAWC,EAAS;AAAA,EACzB,SAASC,EAAO,CAAC,YAAY,MAAM,CAAC,EAAE,SAAA,EAAW,QAAQ,UAAU;AAAA,EACnE,OAAOC,EAAQ,CAACC,EAAU,KAAK,GAAGC,EAAQC,EAAU,CAAA,CAAC,CAAC,EAAE,SAAS;AAAA,EACjE,QAAQA,EAAS;AAAA,EACjB,QAAQC,EAASC,EAAO,CAAA,EAAE,SAAS;AACpC,CAAC,GAQKC,KAAYT,EAAS,OAAO;AAAA,EACjC,MAAMI,EAAU,OAAO;AAAA,EACvB,OAAOE,EAAS,EAAE,SAAS;AAAA;AAAA,EAC3B,0BAA0BI,EAAU,EAAE,SAAS;AAChD,CAAC,GAGKC,KAAUX,EAAS,OAAO;AAAA,EAC/B,MAAMI,EAAU,KAAK;AAAA,EACrB,OAAOE,EAAS,EAAE,SAAS;AAC5B,CAAC,GAGKM,KAAgBZ,EAAS,OAAO;AAAA,EACrC,MAAMI,EAAU,YAAY;AAAA,EAC5B,OAAOE,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R,UAAU;AAAA,QACT,MAAM;AAAA,QACN,SAAS,0BAA0BgE,EAAQ,MAAM,MAAM,sBAAsBT,CAAE;AAAA,QAC/E,SAAS;AAAA,MACV;AAAA,MACA,QAAQ;AAAA;AAAA,IAAA,CACR,GAEDvD,EAAiB,SAAS;AAAA,WAClBf,GAAO;AACX,IAAAqE,EAAarE,CAAK,KACrBe,EAAiB,OAAO;AAAA,MACvB,QAAQ;AAAA,MACR,UAAU;AAAA,QACT,MAAM;AAAA,QACN,SAAS;AAAA,MAAA;AAAA,IACV,CACA,GACDA,EAAiB,SAAS,MAE1BmE,EAAO,MAAM,wBAAwB;AAAA,MACpC,OAAAlF;AAAA,MACA,OAAOA,aAAiB,QAAQA,EAAM,QAAQ;AAAA,IAAA,CAC9C,GACDe,EAAiB,MAAMf,CAAK;AAAA,EAC7B;AAEF;"}
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { C as Pe, aw as st, p as lt } from "./color-KZLHE9lz.js";
2
+ import { Y as Pe, X as st, p as lt } from "./console-B_a7AZVs.js";
3
3
  var pe = {}, Pu = {}, be = {}, Me;
4
4
  function ne() {
5
5
  return Me || (Me = 1, function(u) {
@@ -60,7 +60,7 @@ function ne() {
60
60
  u.createTranslatorContext = l;
61
61
  }(be)), be;
62
62
  }
63
- var he = {}, G = {}, J = {}, hu = {}, Zu = {}, Iu = { exports: {} };
63
+ var he = {}, G = {}, J = {}, hu = {}, Yu = {}, Iu = { exports: {} };
64
64
  /*! https://mths.be/he v1.2.0 by @mathias | MIT license */
65
65
  var dt = Iu.exports, je;
66
66
  function Be() {
@@ -123,7 +123,7 @@ function Be() {
123
123
  })), y = y.replace(/&gt;\u20D2/g, "&nvgt;").replace(/&lt;\u20D2/g, "&nvlt;"), y = y.replace(e, function($) {
124
124
  return "&" + c[$] + ";";
125
125
  })) : j || (y = y.replace(d, W)), y.replace(a, function($) {
126
- var I = $.charCodeAt(0), Z = $.charCodeAt(1), eu = (I - 55296) * 1024 + Z - 56320 + 65536;
126
+ var I = $.charCodeAt(0), Y = $.charCodeAt(1), eu = (I - 55296) * 1024 + Y - 56320 + 65536;
127
127
  return X(eu);
128
128
  }).replace(t, W);
129
129
  };
@@ -137,11 +137,11 @@ function Be() {
137
137
  var F = function(y, N) {
138
138
  N = M(N, F.options);
139
139
  var _ = N.strict;
140
- return _ && p.test(y) && S("malformed character reference"), y.replace(g, function(P, k, j, X, W, $, I, Z, eu) {
140
+ return _ && p.test(y) && S("malformed character reference"), y.replace(g, function(P, k, j, X, W, $, I, Y, eu) {
141
141
  var cu, ru, Su, zu, Bu, vu;
142
142
  return k ? (Bu = k, v[Bu]) : j ? (Bu = j, vu = X, vu && N.isAttributeValue ? (_ && vu == "=" && S("`&` did not start a character reference"), P) : (_ && S(
143
143
  "named character reference was not terminated by a semicolon"
144
- ), q[Bu] + (vu || ""))) : W ? (Su = W, ru = $, _ && !ru && S("character reference was not terminated by a semicolon"), cu = parseInt(Su, 10), U(cu, _)) : I ? (zu = I, ru = Z, _ && !ru && S("character reference was not terminated by a semicolon"), cu = parseInt(zu, 16), U(cu, _)) : (_ && S(
144
+ ), q[Bu] + (vu || ""))) : W ? (Su = W, ru = $, _ && !ru && S("character reference was not terminated by a semicolon"), cu = parseInt(Su, 10), U(cu, _)) : I ? (zu = I, ru = Y, _ && !ru && S("character reference was not terminated by a semicolon"), cu = parseInt(zu, 16), U(cu, _)) : (_ && S(
145
145
  "named character reference was not terminated by a semicolon"
146
146
  ), P);
147
147
  });
@@ -174,8 +174,8 @@ function Be() {
174
174
  }
175
175
  var He;
176
176
  function ie() {
177
- if (He) return Zu;
178
- He = 1, Object.defineProperty(Zu, "__esModule", { value: !0 });
177
+ if (He) return Yu;
178
+ He = 1, Object.defineProperty(Yu, "__esModule", { value: !0 });
179
179
  var u = Be(), o = (
180
180
  /** @class */
181
181
  function() {
@@ -214,16 +214,16 @@ function ie() {
214
214
  }), s;
215
215
  }()
216
216
  );
217
- return Zu.default = o, Zu;
217
+ return Yu.default = o, Yu;
218
218
  }
219
- var Yu = {}, Ue;
219
+ var Zu = {}, Ue;
220
220
  function Gu() {
221
- if (Ue) return Yu;
222
- Ue = 1, Object.defineProperty(Yu, "__esModule", { value: !0 });
221
+ if (Ue) return Zu;
222
+ Ue = 1, Object.defineProperty(Zu, "__esModule", { value: !0 });
223
223
  var u;
224
224
  return function(o) {
225
225
  o[o.ELEMENT_NODE = 1] = "ELEMENT_NODE", o[o.TEXT_NODE = 3] = "TEXT_NODE", o[o.COMMENT_NODE = 8] = "COMMENT_NODE";
226
- }(u || (u = {})), Yu.default = u, Yu;
226
+ }(u || (u = {})), Zu.default = u, Zu;
227
227
  }
228
228
  var Ve;
229
229
  function $r() {
@@ -746,7 +746,7 @@ function pt() {
746
746
  )), Qu;
747
747
  }
748
748
  var ve = {}, Xe;
749
- function Ze() {
749
+ function Ye() {
750
750
  return Xe || (Xe = 1, function(u) {
751
751
  var o;
752
752
  Object.defineProperty(u, "__esModule", { value: !0 }), u.replaceCodePoint = u.fromCodePoint = void 0;
@@ -797,9 +797,9 @@ function Ze() {
797
797
  u.default = b;
798
798
  }(ve)), ve;
799
799
  }
800
- var Ye;
800
+ var Ze;
801
801
  function Ke() {
802
- return Ye || (Ye = 1, function(u) {
802
+ return Ze || (Ze = 1, function(u) {
803
803
  var o = nu && nu.__createBinding || (Object.create ? function(x, L, S, R) {
804
804
  R === void 0 && (R = S);
805
805
  var F = Object.getOwnPropertyDescriptor(L, S);
@@ -825,9 +825,9 @@ function Ke() {
825
825
  u.htmlDecodeTree = i.default;
826
826
  var a = b(/* @__PURE__ */ pt());
827
827
  u.xmlDecodeTree = a.default;
828
- var r = l(/* @__PURE__ */ Ze());
828
+ var r = l(/* @__PURE__ */ Ye());
829
829
  u.decodeCodePoint = r.default;
830
- var t = /* @__PURE__ */ Ze();
830
+ var t = /* @__PURE__ */ Ye();
831
831
  Object.defineProperty(u, "replaceCodePoint", { enumerable: !0, get: function() {
832
832
  return t.replaceCodePoint;
833
833
  } }), Object.defineProperty(u, "fromCodePoint", { enumerable: !0, get: function() {
@@ -1880,7 +1880,7 @@ function Lu() {
1880
1880
  }
1881
1881
  }), Ae;
1882
1882
  }
1883
- var Y = {}, V;
1883
+ var Z = {}, V;
1884
1884
  (function(u) {
1885
1885
  u.Attribute = "attribute", u.Pseudo = "pseudo", u.PseudoElement = "pseudo-element", u.Tag = "tag", u.Universal = "universal", u.Adjacent = "adjacent", u.Child = "child", u.Descendant = "descendant", u.Parent = "parent", u.Sibling = "sibling", u.ColumnCombinator = "column-combinator";
1886
1886
  })(V || (V = {}));
@@ -1910,7 +1910,7 @@ const hr = /^[^\\#]?(?:\\(?:[\da-f]{1,6}\s?|.)|[\w\-\u00b0-\uFFFF])+/, xt = /\\(
1910
1910
  "host",
1911
1911
  "host-context"
1912
1912
  ]);
1913
- function Zr(u) {
1913
+ function Yr(u) {
1914
1914
  switch (u.type) {
1915
1915
  case V.Adjacent:
1916
1916
  case V.Child:
@@ -1944,12 +1944,12 @@ function gr(u) {
1944
1944
  return u === 32 || u === 9 || u === 10 || u === 12 || u === 13;
1945
1945
  }
1946
1946
  function Nt(u) {
1947
- const o = [], s = Yr(o, `${u}`, 0);
1947
+ const o = [], s = Zr(o, `${u}`, 0);
1948
1948
  if (s < u.length)
1949
1949
  throw new Error(`Unmatched selector: ${u.slice(s)}`);
1950
1950
  return o;
1951
1951
  }
1952
- function Yr(u, o, s) {
1952
+ function Zr(u, o, s) {
1953
1953
  let l = [];
1954
1954
  function b(f) {
1955
1955
  const p = o.slice(s + f).match(hr);
@@ -1979,7 +1979,7 @@ function Yr(u, o, s) {
1979
1979
  return (p & 1) === 1;
1980
1980
  }
1981
1981
  function t() {
1982
- if (l.length > 0 && Zr(l[l.length - 1]))
1982
+ if (l.length > 0 && Yr(l[l.length - 1]))
1983
1983
  throw new Error("Did not expect successive traversals.");
1984
1984
  }
1985
1985
  function e(f) {
@@ -2104,7 +2104,7 @@ function Yr(u, o, s) {
2104
2104
  if (Tt.has(p)) {
2105
2105
  if (ye(o.charCodeAt(s + 1)))
2106
2106
  throw new Error(`Pseudo-selector ${p} cannot be quoted`);
2107
- if (n = [], s = Yr(n, o, s + 1), o.charCodeAt(s) !== 41)
2107
+ if (n = [], s = Zr(n, o, s + 1), o.charCodeAt(s) !== 41)
2108
2108
  throw new Error(`Missing closing parenthesis in :${p} (${o})`);
2109
2109
  s += 1;
2110
2110
  } else {
@@ -2239,7 +2239,7 @@ const St = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2239
2239
  get SelectorType() {
2240
2240
  return V;
2241
2241
  },
2242
- isTraversal: Zr,
2242
+ isTraversal: Yr,
2243
2243
  parse: Nt,
2244
2244
  stringify: ut
2245
2245
  }, Symbol.toStringTag, { value: "Module" })), oe = /* @__PURE__ */ st(St);
@@ -2987,9 +2987,9 @@ function Ut() {
2987
2987
  }
2988
2988
  var Fr;
2989
2989
  function Vt() {
2990
- if (Fr) return Y;
2990
+ if (Fr) return Z;
2991
2991
  Fr = 1;
2992
- var u = Y && Y.__createBinding || (Object.create ? function(E, m, h, D) {
2992
+ var u = Z && Z.__createBinding || (Object.create ? function(E, m, h, D) {
2993
2993
  D === void 0 && (D = h);
2994
2994
  var C = Object.getOwnPropertyDescriptor(m, h);
2995
2995
  (!C || ("get" in C ? !m.__esModule : C.writable || C.configurable)) && (C = { enumerable: !0, get: function() {
@@ -2997,30 +2997,30 @@ function Vt() {
2997
2997
  } }), Object.defineProperty(E, D, C);
2998
2998
  } : function(E, m, h, D) {
2999
2999
  D === void 0 && (D = h), E[D] = m[h];
3000
- }), o = Y && Y.__setModuleDefault || (Object.create ? function(E, m) {
3000
+ }), o = Z && Z.__setModuleDefault || (Object.create ? function(E, m) {
3001
3001
  Object.defineProperty(E, "default", { enumerable: !0, value: m });
3002
3002
  } : function(E, m) {
3003
3003
  E.default = m;
3004
- }), s = Y && Y.__importStar || function(E) {
3004
+ }), s = Z && Z.__importStar || function(E) {
3005
3005
  if (E && E.__esModule) return E;
3006
3006
  var m = {};
3007
3007
  if (E != null) for (var h in E) h !== "default" && Object.prototype.hasOwnProperty.call(E, h) && u(m, E, h);
3008
3008
  return o(m, E), m;
3009
- }, l = Y && Y.__importDefault || function(E) {
3009
+ }, l = Z && Z.__importDefault || function(E) {
3010
3010
  return E && E.__esModule ? E : { default: E };
3011
3011
  };
3012
- Object.defineProperty(Y, "__esModule", { value: !0 }), Y.compileToken = Y.compileUnsafe = Y.compile = void 0;
3012
+ Object.defineProperty(Z, "__esModule", { value: !0 }), Z.compileToken = Z.compileUnsafe = Z.compile = void 0;
3013
3013
  var b = oe, i = l(Lu()), a = s(rt()), r = Ut(), t = qe();
3014
3014
  function e(E, m, h) {
3015
3015
  var D = c(E, m, h);
3016
3016
  return (0, t.ensureIsTag)(D, m.adapter);
3017
3017
  }
3018
- Y.compile = e;
3018
+ Z.compile = e;
3019
3019
  function c(E, m, h) {
3020
3020
  var D = typeof E == "string" ? (0, b.parse)(E) : E;
3021
3021
  return v(D, m, h);
3022
3022
  }
3023
- Y.compileUnsafe = c;
3023
+ Z.compileUnsafe = c;
3024
3024
  function d(E) {
3025
3025
  return E.type === b.SelectorType.Pseudo && (E.name === "scope" || Array.isArray(E.data) && E.data.some(function(m) {
3026
3026
  return m.some(d);
@@ -3065,7 +3065,7 @@ function Vt() {
3065
3065
  }).reduce(w, i.default.falseFunc);
3066
3066
  return U.shouldTestNextSiblings = M, U;
3067
3067
  }
3068
- Y.compileToken = v;
3068
+ Z.compileToken = v;
3069
3069
  function q(E, m, h) {
3070
3070
  var D;
3071
3071
  return E.reduce(function(C, O) {
@@ -3077,7 +3077,7 @@ function Vt() {
3077
3077
  return E(D) || m(D);
3078
3078
  };
3079
3079
  }
3080
- return Y;
3080
+ return Z;
3081
3081
  }
3082
3082
  var _r;
3083
3083
  function It() {
@@ -3725,8 +3725,8 @@ function Ne() {
3725
3725
  if (k(I))
3726
3726
  X = I;
3727
3727
  else {
3728
- var Z = B.get(I);
3729
- Z && (X = _(k, [Z]));
3728
+ var Y = B.get(I);
3729
+ Y && (X = _(k, [Y]));
3730
3730
  }
3731
3731
  }
3732
3732
  return X;
@@ -4008,7 +4008,7 @@ function Ne() {
4008
4008
  }
4009
4009
  var W = function(tu, ku) {
4010
4010
  return [tu - vu, ku - vu];
4011
- }, $ = new D(null, {}, "", null, [0, F.length], y, T), I = $, Z = [$], eu = -1, cu = void 0, ru;
4011
+ }, $ = new D(null, {}, "", null, [0, F.length], y, T), I = $, Y = [$], eu = -1, cu = void 0, ru;
4012
4012
  F = "<".concat(x, ">").concat(F, "</").concat(x, ">");
4013
4013
  for (var Su = T.lowerCaseTagName, zu = T.fixNestedATags, Bu = F.length - (x.length + 2), vu = x.length + 2; ru = C.exec(F); ) {
4014
4014
  var Le = ru[0], se = ru[1], Q = ru[2], Se = ru[3], Oe = ru[4], le = Le.length, $u = C.lastIndex - le, Wu = C.lastIndex;
@@ -4030,12 +4030,12 @@ function Ne() {
4030
4030
  Re[it.toLowerCase()] = ct ? Ou.slice(1, Ou.length - 1) : Ou;
4031
4031
  }
4032
4032
  var Ru = I.rawTagName;
4033
- !Oe && M[Ru] && M[Ru][Q] && (Z.pop(), I = (0, a.default)(Z)), zu && (Q === "a" || Q === "A") && (cu !== void 0 && (Z.splice(cu), I = (0, a.default)(Z)), cu = Z.length);
4033
+ !Oe && M[Ru] && M[Ru][Q] && (Y.pop(), I = (0, a.default)(Y)), zu && (Q === "a" || Q === "A") && (cu !== void 0 && (Y.splice(cu), I = (0, a.default)(Y)), cu = Y.length);
4034
4034
  var Ju = C.lastIndex, ot = Ju - le;
4035
4035
  if (I = I.appendChild(
4036
4036
  // Initialize range (end position updated later for closed tags)
4037
4037
  new D(Q, Re, Se.slice(1), null, W(ot, Ju), y, T)
4038
- ), Z.push(I), X(Q)) {
4038
+ ), Y.push(I), X(Q)) {
4039
4039
  var fe = "</".concat(Q, ">"), Xu = Su ? F.toLocaleLowerCase().indexOf(fe, C.lastIndex) : F.indexOf(fe, C.lastIndex), ke = Xu === -1 ? Bu : Xu;
4040
4040
  if (j(Q)) {
4041
4041
  var Du = F.substring(Ju, ke);
@@ -4047,19 +4047,19 @@ function Ne() {
4047
4047
  if (se || Oe || y.isVoidElement(Q))
4048
4048
  for (; ; )
4049
4049
  if (cu != null && (Q === "a" || Q === "A") && (cu = void 0), I.rawTagName === Q) {
4050
- I.range[1] = W(-1, Math.max(eu, Wu))[1], Z.pop(), I = (0, a.default)(Z);
4050
+ I.range[1] = W(-1, Math.max(eu, Wu))[1], Y.pop(), I = (0, a.default)(Y);
4051
4051
  break;
4052
4052
  } else {
4053
4053
  var Ru = I.tagName;
4054
4054
  if (U[Ru] && U[Ru][Q]) {
4055
- Z.pop(), I = (0, a.default)(Z);
4055
+ Y.pop(), I = (0, a.default)(Y);
4056
4056
  continue;
4057
4057
  }
4058
4058
  break;
4059
4059
  }
4060
4060
  }
4061
4061
  }
4062
- return Z;
4062
+ return Y;
4063
4063
  }
4064
4064
  K.base_parse = L;
4065
4065
  function S(F, T) {
@@ -4600,7 +4600,7 @@ function Xt() {
4600
4600
  }(we)), we;
4601
4601
  }
4602
4602
  var Ir;
4603
- function Zt() {
4603
+ function Yt() {
4604
4604
  if (Ir) return Tu;
4605
4605
  Ir = 1, Object.defineProperty(Tu, "__esModule", { value: !0 }), Tu.getMarkdownForHtmlNodes = Tu.Visitor = void 0;
4606
4606
  const u = Xt(), o = Fe(), s = ne(), l = _e();
@@ -4740,10 +4740,10 @@ function Zt() {
4740
4740
  return Tu.getMarkdownForHtmlNodes = i, Tu;
4741
4741
  }
4742
4742
  var Gr;
4743
- function Yt() {
4743
+ function Zt() {
4744
4744
  if (Gr) return Pu;
4745
4745
  Gr = 1, Object.defineProperty(Pu, "__esModule", { value: !0 }), Pu.NodeHtmlMarkdown = void 0;
4746
- const u = ne(), o = _e(), s = Fe(), l = Zt();
4746
+ const u = ne(), o = _e(), s = Fe(), l = Yt();
4747
4747
  class b {
4748
4748
  constructor(a, r, t) {
4749
4749
  var e, c, d, f;
@@ -4793,7 +4793,7 @@ var zr;
4793
4793
  function Kt() {
4794
4794
  return zr || (zr = 1, function(u) {
4795
4795
  Object.defineProperty(u, "__esModule", { value: !0 }), u.PostProcessResult = u.TranslatorCollection = u.NodeHtmlMarkdown = void 0;
4796
- var o = Yt();
4796
+ var o = Zt();
4797
4797
  Object.defineProperty(u, "NodeHtmlMarkdown", { enumerable: !0, get: function() {
4798
4798
  return o.NodeHtmlMarkdown;
4799
4799
  } });
@@ -4850,4 +4850,4 @@ ${a}`
4850
4850
  export {
4851
4851
  ea as nodeReadWebPageTool
4852
4852
  };
4853
- //# sourceMappingURL=node-COuJYHx_.js.map
4853
+ //# sourceMappingURL=node-CBVbC8Le.js.map