@zaly/agent 0.1.1 → 0.3.0

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 (57) hide show
  1. package/dist/{agent-BRENvuvx.mjs → agent-GXRF7DUP.mjs} +102 -33
  2. package/dist/agent-GXRF7DUP.mjs.map +1 -0
  3. package/dist/{bash-DSy03sAj.mjs → bash-CB_VXpyd.mjs} +2 -2
  4. package/dist/{bash-DSy03sAj.mjs.map → bash-CB_VXpyd.mjs.map} +1 -1
  5. package/dist/{compactions-HFjEgrv3.mjs → compactions-92bMlcxJ.mjs} +25 -15
  6. package/dist/compactions-92bMlcxJ.mjs.map +1 -0
  7. package/dist/{edit-DT672zIy.mjs → edit-gkb6MCW-.mjs} +2 -2
  8. package/dist/{edit-DT672zIy.mjs.map → edit-gkb6MCW-.mjs.map} +1 -1
  9. package/dist/{fetch-BrtIqrid.mjs → fetch-D_GzL2yy.mjs} +4 -4
  10. package/dist/{fetch-BrtIqrid.mjs.map → fetch-D_GzL2yy.mjs.map} +1 -1
  11. package/dist/{find-B-vvdlHu.mjs → find-DlrYUTXT.mjs} +2 -2
  12. package/dist/{find-B-vvdlHu.mjs.map → find-DlrYUTXT.mjs.map} +1 -1
  13. package/dist/{grep-rvZ5S319.mjs → grep-BI8Rou2q.mjs} +2 -2
  14. package/dist/{grep-rvZ5S319.mjs.map → grep-BI8Rou2q.mjs.map} +1 -1
  15. package/dist/{html-VrAsoGBK.mjs → html-B-Lr-9W6.mjs} +9457 -4826
  16. package/dist/html-B-Lr-9W6.mjs.map +1 -0
  17. package/dist/{index-node-esm-BwaOzhXB.mjs → index-node-esm-75XSYyIw.mjs} +16 -13
  18. package/dist/index-node-esm-75XSYyIw.mjs.map +1 -0
  19. package/dist/index.d.mts +21 -6
  20. package/dist/index.d.mts.map +1 -1
  21. package/dist/index.mjs +2 -2
  22. package/dist/{manager-1zEE5WiA.mjs → manager-CEociHy_.mjs} +2 -2
  23. package/dist/{manager-1zEE5WiA.mjs.map → manager-CEociHy_.mjs.map} +1 -1
  24. package/dist/{masker-DEgR_ntk.mjs → masker-DWuL2Fjs.mjs} +16 -5
  25. package/dist/{masker-DEgR_ntk.mjs.map → masker-DWuL2Fjs.mjs.map} +1 -1
  26. package/dist/{read-C5keKntU.mjs → read-DLtNq4XJ.mjs} +2 -2
  27. package/dist/{read-C5keKntU.mjs.map → read-DLtNq4XJ.mjs.map} +1 -1
  28. package/dist/{registry-CntkeXlo.mjs → registry-7mJQhyBA.mjs} +3 -3
  29. package/dist/{registry-CntkeXlo.mjs.map → registry-7mJQhyBA.mjs.map} +1 -1
  30. package/dist/{rolldown-runtime-DYf_mQCB.mjs → rolldown-runtime-BVN1G_yT.mjs} +4 -4
  31. package/dist/{session-C8zqqbPE.mjs → session-C5ra-Hi1.mjs} +80 -45
  32. package/dist/session-C5ra-Hi1.mjs.map +1 -0
  33. package/dist/{session-Cq52cam5.d.mts → session-WtXqtAaq.d.mts} +19 -10
  34. package/dist/session-WtXqtAaq.d.mts.map +1 -0
  35. package/dist/session.d.mts +1 -1
  36. package/dist/session.mjs +1 -1
  37. package/dist/{src-C04Qk9KE.mjs → src-Di-H3Oya.mjs} +71 -41
  38. package/dist/src-Di-H3Oya.mjs.map +1 -0
  39. package/dist/{subagent-BbcxLzgC.mjs → subagent-BOK4GFd4.mjs} +3 -3
  40. package/dist/{subagent-BbcxLzgC.mjs.map → subagent-BOK4GFd4.mjs.map} +1 -1
  41. package/dist/{tasks-Dgsiuh0Q.mjs → tasks-BUFqFoh6.mjs} +2 -2
  42. package/dist/{tasks-Dgsiuh0Q.mjs.map → tasks-BUFqFoh6.mjs.map} +1 -1
  43. package/dist/{tasks-D76WXWr2.mjs → tasks-CkDWJk_3.mjs} +4 -4
  44. package/dist/tasks-CkDWJk_3.mjs.map +1 -0
  45. package/dist/{tools-DmoUYORG.mjs → tools-Ca7VsMg3.mjs} +2 -2
  46. package/dist/{tools-DmoUYORG.mjs.map → tools-Ca7VsMg3.mjs.map} +1 -1
  47. package/dist/{write-BRQFfWAn.mjs → write-y93TC5ng.mjs} +2 -2
  48. package/dist/{write-BRQFfWAn.mjs.map → write-y93TC5ng.mjs.map} +1 -1
  49. package/package.json +11 -11
  50. package/dist/agent-BRENvuvx.mjs.map +0 -1
  51. package/dist/compactions-HFjEgrv3.mjs.map +0 -1
  52. package/dist/html-VrAsoGBK.mjs.map +0 -1
  53. package/dist/index-node-esm-BwaOzhXB.mjs.map +0 -1
  54. package/dist/session-C8zqqbPE.mjs.map +0 -1
  55. package/dist/session-Cq52cam5.d.mts.map +0 -1
  56. package/dist/src-C04Qk9KE.mjs.map +0 -1
  57. package/dist/tasks-D76WXWr2.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"tasks-D76WXWr2.mjs","names":[],"sources":["../src/tasks.ts"],"sourcesContent":["import type {\n ContentPart,\n Message,\n MetaPart,\n TextPart,\n Tool,\n ToolCallPart,\n ToolContext,\n ToolResult,\n ToolResultPart,\n Streamable as TStreamable,\n} from \"@zaly/ai\"\n\nimport { AiError, isStreamable, runTool, stringifyContent, toErrorResult } from \"@zaly/ai\"\nimport { Emitter, safeStringify } from \"@zaly/shared\"\nimport { uuidv7 } from \"./utils/uuid.ts\"\n\nconst DEFAULT_GRACE_MS = 10_000\n\n/** Status of a task. `pending` = queued behind a dependency, not yet\n * started. `running` = work in progress (a Streamable is being polled).\n * `done` = result captured, no longer mutating. */\nexport type TaskStatus = \"pending\" | \"running\" | \"done\"\n\n/** Public projection of a registered task. Status-discriminated so the\n * fields visible at any moment are exactly the ones that make sense\n * for that lifecycle stage:\n *\n * - `running`: `elapsedMs` since start; `hasNewOutput` when the\n * streamable signals that `task_poll` would yield bytes.\n * - `pending`: queued behind another task (`waitingFor`); `elapsedMs`\n * counts time-since-registration.\n * - `done`: settled. Carries `durationMs` and the captured `result`.\n *\n * This is the only public task type — the registry exposes it via\n * `running()` / `finished()` / `get()`, events carry it (`task-done`\n * is narrowed to `status: \"done\"` so listeners get `result` typed\n * without checks), and `task_list` JSON-stringifies it directly. */\nexport type TaskInfo = {\n id: string\n type: string\n desc: string\n} & (\n | { status: \"running\"; elapsedMs: number; hasNewOutput?: boolean }\n | { status: \"pending\"; waitingFor: string; elapsedMs: number }\n | { status: \"done\"; durationMs: number; result: ToolResult }\n)\n\n/** A `TaskInfo` known to be in the `done` state. `task-done` event\n * payloads use this so listeners get `result` and `durationMs` typed\n * without manual narrowing. */\nexport type DoneTaskInfo = Extract<TaskInfo, { status: \"done\" }>\n\n/** Events emitted by a `Tasks` instance. `task-done` only fires for\n * completions that happen *outside* an in-flight `run()` round —\n * round-internal completions are folded into the `run()` return value\n * instead. `heartbeat` fires periodically (when `heartbeatMs` is set\n * and at least one task is active), giving the agent a hook to keep\n * the model engaged on long-running work. */\nexport type TasksEvents = {\n \"task-added\": { task: TaskInfo }\n \"task-removed\": { task: TaskInfo }\n \"task-done\": { task: DoneTaskInfo }\n heartbeat: { running: readonly TaskInfo[] }\n}\n\n/** Augment ToolMeta so tools and consumers can read freshness/state info\n * off `ToolResultPart.meta.task`. The registry stamps this on every\n * result it produces so the model can correlate placeholders to their\n * eventual completion. */\nexport interface TaskMeta {\n task?: {\n id: string\n status: TaskStatus\n type: string\n desc: string\n dependsOn?: string\n durationMs?: number\n }\n}\n\n/** Internal storage record. Not exposed — `toTaskInfo` projects it to\n * `TaskInfo` for any caller that crosses the boundary (events,\n * registry methods, the `task_*` tools). Carries everything the\n * registry needs to drive lifecycle transitions, plus the raw\n * timestamps `TaskInfo` derives elapsed/duration from. */\ninterface InternalTask {\n id: string\n type: string\n desc: string\n status: TaskStatus\n /** Wallclock at registration. */\n startedAt: number\n /** Wallclock at completion; set once status is `done`. */\n finishedAt?: number\n /** Captured result when status is `done`. */\n result?: ToolResult\n /** When set, this task is queued behind another and won't start until\n * the named task transitions to `done`. */\n waitingFor?: string\n /** Streamable returned by the tool, if any — held so we can `abort()`\n * on cancellation and call `poll()` for partial snapshots. */\n streamable?: TStreamable\n /** Resolves when the task transitions to `done`. Used by the round\n * race in `run()`. */\n donePromise: Promise<void>\n resolveDone: () => void\n /** When set, the task belongs to an in-flight `run()` round — its\n * completion does *not* fire `task-done` (the round folds it into the\n * returned parts instead). Cleared once the round ends. */\n ownerRound?: symbol\n /** Stashed call so a pending task can be restarted once its\n * dependency completes. */\n pending?: { tool: Tool; call: ToolCallPart; ctx: ToolContext }\n}\n\n/**\n * Tool registry + execution machinery + long-running task bookkeeping.\n * One Tasks instance per Agent. Owns the tool list (the agent delegates\n * `agent.tools` to it) and runs every assistant tool batch through\n * `run()`, which:\n *\n * - validates each call's params,\n * - dispatches to the named tool (sync results land immediately),\n * - races `Streamable` returns against a grace window,\n * - chains `parallel: false` calls behind their predecessors,\n * - returns `ToolResultPart[]` 1:1 with the assistant's calls,\n * surfacing partial results / placeholders for anything still running\n * when the grace expires.\n *\n * Completions during a round are folded into the returned parts and do\n * NOT fire `task-done`. Completions afterward fire normally — the agent\n * listens and injects a system message into the next step.\n */\nexport class Tasks extends Emitter<TasksEvents> {\n readonly #map = new Map<string, InternalTask>()\n graceMs = DEFAULT_GRACE_MS\n\n #tools: (() => Promise<readonly Tool[]>) | Tool[] = []\n\n /** Heartbeat interval in ms. When set, fires `heartbeat` events while\n * at least one task is pending or running. Self-managing: starts on\n * the first active task, stops when the last one finishes. Set to\n * `undefined` to disable. */\n #heartbeatMs?: number\n #heartbeatTimer?: ReturnType<typeof setInterval>\n\n get heartbeatMs(): number | undefined {\n return this.#heartbeatMs\n }\n set heartbeatMs(value: number | undefined) {\n this.#heartbeatMs = value\n this.#syncHeartbeat()\n }\n\n // ── Public registry surface ─────────────────────────────────────────\n\n /** Snapshot of every active task (pending or running). */\n running(): readonly TaskInfo[] {\n return [...this.#map.values()].filter((t) => t.status !== \"done\").map((t) => toTaskInfo(t))\n }\n\n /** Snapshot of every task that has completed. Drops are by `remove()`\n * or implicit retention; this list grows unless the caller prunes. */\n finished(): readonly DoneTaskInfo[] {\n return [...this.#map.values()]\n .filter((t): t is InternalTask & { status: \"done\" } => t.status === \"done\")\n .map((t) => toTaskInfo(t) as DoneTaskInfo)\n }\n\n /** Look up a task by id. Useful for `task_stop` / `task_poll`. */\n get(id: string): TaskInfo | undefined {\n const t = this.#map.get(id)\n return t ? toTaskInfo(t) : undefined\n }\n\n /** Snapshot of every task in the registry — running, pending, and done. */\n info(): readonly TaskInfo[] {\n return [...this.#map.values()].map(toTaskInfo)\n }\n\n async tools(): Promise<readonly Tool[]> {\n return typeof this.#tools === \"function\" ? this.#tools() : this.#tools\n }\n\n set $tools(tools: (() => Promise<readonly Tool[]>) | Tool[]) {\n this.#tools = tools\n }\n\n /** Non-consuming check: does the underlying streamable have output\n * the model hasn't seen since the last `poll()`? Returns false for\n * tasks without a streamable, completed tasks, or streamables that\n * don't implement the optional `hasNew` hook (no signal to give).\n * Used by heartbeats to flag tasks worth polling. */\n hasNewOutput(id: string): boolean {\n const t = this.#map.get(id)\n if (t?.status !== \"running\" || !t.streamable) return false\n return t.streamable.hasNew?.() ?? false\n }\n\n /** Poll a task's streamable for incremental output without changing\n * its lifecycle state. Advances the streamable's cursor — the next\n * call returns only what arrived since *this* one. Returns the same\n * `ToolResult` shape the original tool produces (parts + meta).\n * Errors when the task is unknown, already done, or has no streamable\n * (the latter is the case for plain-Promise tools — there's no\n * partial state to read). */\n pollOutput(id: string): ToolResult & { running: boolean } {\n const t = this.#map.get(id)\n if (!t) {\n throw new AiError({\n code: \"NOT_FOUND\",\n data: { id },\n message: `no task with id \"${id}\"`,\n })\n }\n if (t.status === \"done\") {\n throw new AiError({\n code: \"TASK_DONE\",\n data: { id },\n message: `task \"${id}\" has already completed; its result was injected as a system message`,\n })\n }\n if (!t.streamable) {\n throw new AiError({\n code: \"NOT_STREAMABLE\",\n data: { id },\n message:\n `task \"${id}\" has no incremental output — it's a plain-Promise tool ` +\n `whose result is delivered all-at-once when complete`,\n })\n }\n return t.streamable.poll()\n }\n\n /** Drop a task from the registry — does not abort. Caller is\n * responsible for `abort()`-ing if the task is still running. */\n remove(id: string): boolean {\n const task = this.#map.get(id)\n if (!task) return false\n this.#map.delete(id)\n void this.emit(\"task-removed\", { task: toTaskInfo(task) })\n return true\n }\n\n /** Mark a task done with a final result. Fires `task-done` UNLESS the\n * task is currently owned by an in-flight `run()` round — in that\n * case the round folds the completion into its returned parts and\n * the event is suppressed. Starts any pending dependents. */\n done(id: string, result: ToolResult): void {\n const task = this.#map.get(id)\n if (!task || task.status === \"done\") return\n task.status = \"done\"\n task.result = result\n task.finishedAt = Date.now()\n task.resolveDone()\n if (!task.ownerRound) {\n void this.emit(\"task-done\", { task: toTaskInfo(task) as DoneTaskInfo })\n }\n this.#startReadyDependents(id, result)\n this.#syncHeartbeat()\n }\n\n /** Abort a running task. Calls the streamable's `abort()` if present;\n * pending tasks transition straight to `done` with a cancelled\n * result. Idempotent. */\n abort(id: string, reason = \"aborted by request\"): void {\n const task = this.#map.get(id)\n if (!task || task.status === \"done\") return\n if (task.streamable) task.streamable.abort()\n if (task.status === \"pending\") {\n this.done(id, toErrorResult(new AiError({ code: \"TASK_ABORTED\", message: reason })))\n }\n // Running tasks: the streamable will eventually settle and call done()\n // via its watcher. We could force a synchronous \"done\" here, but\n // letting the streamable's natural completion path run keeps the\n // final snapshot accurate (output that arrived before abort lands).\n }\n\n /** Abort every active task. Used on agent dispose. Awaits each\n * task's `donePromise` so the registry is fully drained before\n * resolving — so callers can rely on no pending I/O after `dispose`. */\n async killAll(): Promise<void> {\n const active = [...this.#map.values()].filter((t) => t.status !== \"done\")\n for (const t of active) {\n if (t.streamable) t.streamable.abort()\n if (t.status === \"pending\") {\n this.done(\n t.id,\n toErrorResult(new AiError({ code: \"TASK_ABORTED\", message: \"agent disposed\" }))\n )\n }\n }\n await Promise.all(active.map((t) => t.donePromise.catch(() => undefined)))\n this.#syncHeartbeat()\n }\n\n /** Start or stop the heartbeat timer based on whether any task is\n * active and whether `heartbeatMs` is configured. Idempotent — called\n * after every state transition (`add` / `done` / `killAll`). The\n * timer is `unref`'d so it never holds the process open. */\n #syncHeartbeat(): void {\n const hasActive = [...this.#map.values()].some((t) => t.status !== \"done\")\n const want = hasActive && this.#heartbeatMs !== undefined\n if (want && !this.#heartbeatTimer) {\n this.#heartbeatTimer = setInterval(() => {\n void this.emit(\"heartbeat\", { running: this.info().filter((t) => t.status !== \"done\") })\n }, this.#heartbeatMs)\n this.#heartbeatTimer.unref()\n } else if (!want && this.#heartbeatTimer) {\n clearInterval(this.#heartbeatTimer)\n this.#heartbeatTimer = undefined\n }\n }\n\n // ── Batch execution ─────────────────────────────────────────────────\n\n /**\n * Execute a batch of assistant tool calls. Returns ToolResultPart[]\n * mapped 1:1 with `calls`. Sync completions land in the result array\n * immediately; long-running ones return a placeholder and the eventual\n * completion fires `task-done` post-round (the agent injects a system\n * message in response).\n *\n * The `messages` snapshot is what tools see on `ctx.messages` — pass\n * the conversation up to (and including) the assistant message that\n * produced these calls, so freshness checks can scan back through\n * prior tool results.\n */\n async run(\n calls: readonly ToolCallPart[],\n ctx: ToolContext,\n opts: { onResult?: (call: ToolCallPart, result: ToolResultPart, idx: number) => void } = {}\n ): Promise<ToolResultPart[]> {\n const round = Symbol(\"round\")\n const tasks: InternalTask[] = []\n let chainHead: string | undefined\n\n const tools = await this.tools()\n\n for (const call of calls) {\n const tool = tools.find((t) => t.name === call.name)\n if (!tool) {\n tasks.push(this.#startSyncResult(call, unknownToolResult(call.name), round))\n continue\n }\n\n const parallel = tool.parallel ?? false\n\n if (chainHead && !parallel) {\n // Queue behind the chain head — won't start until that finishes.\n tasks.push(\n this.#registerPending({ call, ctxBase: ctx, round, tool, waitingFor: chainHead })\n )\n chainHead = tasks[tasks.length - 1].id\n continue\n }\n\n if (this.#needsPreflight(tool, ctx)) {\n // Preflight is intentionally sequential: permission prompts should\n // appear one at a time and should not register/background a task while\n // waiting for the user's answer.\n // oxlint-disable-next-line no-await-in-loop\n const preflight = await this.#preflight(tool, call, ctx)\n if (preflight) {\n tasks.push(this.#startSyncResult(call, preflight, round))\n continue\n }\n }\n\n const task = this.#start({ call, ctxBase: ctx, round, tool })\n tasks.push(task)\n // If this call promoted to a long-running task and `parallel: false`,\n // subsequent serial calls chain behind it.\n if (task.status === \"running\" && !parallel) chainHead = task.id\n }\n\n const parts: ToolResultPart[] = []\n\n const resultPart = (idx: number): ToolResultPart => {\n if (parts[idx]) return parts[idx]\n const task = tasks[idx]\n if (task.status !== \"done\") task.ownerRound = undefined\n const call = calls[idx]\n const part = this.#buildPart(call, task)\n parts[idx] = part\n return part\n }\n\n let onResult = opts.onResult\n\n // Race: every task done, OR grace expires, OR ctx.signal aborts.\n const allDone = Promise.all(\n tasks.map(async (t, ti) => {\n await t.donePromise\n onResult?.(calls[ti], resultPart(ti), ti)\n })\n )\n const grace = sleep(this.graceMs)\n const aborted = ctx.signal\n ? new Promise<void>((resolve) => {\n if (ctx.signal!.aborted) resolve()\n else ctx.signal!.addEventListener(\"abort\", () => resolve(), { once: true })\n })\n : new Promise<void>(() => undefined) // never resolves\n await Promise.race([allDone, grace, aborted])\n onResult = undefined\n\n // Release ownership on still-active tasks BEFORE building the result\n // array, so the post-round listener sees them as free-floating if\n // they happen to settle in the same tick.\n return tasks.map((_, i) => resultPart(i))\n }\n\n // ── Internals ──────────────────────────────────────────────────────\n\n /** Build a \"done\" task synchronously from a precomputed result.\n * Used for unknown-tool errors and validation failures. */\n #startSyncResult(call: ToolCallPart, result: ToolResult, round: symbol): InternalTask {\n // oxlint-disable-next-line sort-keys -- semantic field order\n const task = this.#allocate({ id: uuidv7(), type: call.name, desc: call.name, round })\n task.status = \"done\"\n task.result = result\n task.finishedAt = task.startedAt\n task.resolveDone()\n return task\n }\n\n /** Allocate an internal task record, register it, and emit `task-added`. */\n #allocate(opts: {\n id: string\n type: string\n desc: string\n waitingFor?: string\n round: symbol\n }): InternalTask {\n let resolveDone!: () => void\n const donePromise = new Promise<void>((r) => {\n resolveDone = r\n })\n const task: InternalTask = {\n desc: opts.desc,\n donePromise,\n id: opts.id,\n ownerRound: opts.round,\n resolveDone,\n startedAt: Date.now(),\n status: \"pending\",\n type: opts.type,\n waitingFor: opts.waitingFor,\n }\n this.#map.set(task.id, task)\n void this.emit(\"task-added\", { task: toTaskInfo(task) })\n this.#syncHeartbeat()\n return task\n }\n\n /** Register a pending task (chained behind `dependsOn`). Does not\n * invoke the tool — that happens once the dependency completes. */\n #registerPending(opts: {\n call: ToolCallPart\n tool: Tool\n ctxBase: ToolContext\n waitingFor: string\n round: symbol\n }): InternalTask {\n // oxlint-disable-next-line sort-keys -- semantic field order\n const task = this.#allocate({\n id: uuidv7(),\n type: opts.tool.name,\n desc: descOfCall(opts.call),\n waitingFor: opts.waitingFor,\n round: opts.round,\n })\n task.pending = { call: opts.call, ctx: opts.ctxBase, tool: opts.tool }\n return task\n }\n\n /** Start a tool call. Allocates a task record, validates params,\n * invokes `tool.call`, detects `Streamable`, and wires completion\n * back to `done()`. Returns the task in its post-launch state\n * (`done` for sync failures or already-resolved sync calls,\n * `running` for everything else). */\n #start(opts: {\n call: ToolCallPart\n tool: Tool\n ctxBase: ToolContext\n round: symbol\n }): InternalTask {\n // oxlint-disable-next-line sort-keys -- semantic field order\n const task = this.#allocate({\n id: uuidv7(),\n type: opts.tool.name,\n desc: descOfCall(opts.call),\n round: opts.round,\n })\n this.#dispatch(task, opts.tool, opts.call, opts.ctxBase)\n return task\n }\n\n #needsPreflight(tool: Tool, ctx: ToolContext): boolean {\n return ctx.need !== undefined || tool.preflight !== undefined\n }\n\n /** Run schema validation and semantic/tool permission checks before a\n * public task is allocated. Returns a formatted tool error when the\n * call should short-circuit, otherwise undefined. */\n async #preflight(\n tool: Tool,\n call: ToolCallPart,\n ctxBase: ToolContext\n ): Promise<ToolResult | undefined> {\n const ctx: ToolContext = { ...ctxBase, tasks: this }\n let params: unknown\n try {\n params = await tool.validator.validateParams(call.params)\n await ctx.need?.(\"tool\", tool.name)\n await tool.preflight?.(params, ctx)\n } catch (error) {\n return toErrorResult(error)\n }\n }\n\n /** Validate / call / wire up completion for an existing task record.\n * Used both for fresh tasks (`#start`) and pending-becoming-ready\n * (`#startReadyDependents`). The task's id and registry entry are\n * reused so identifiers stay stable across the pending → running\n * transition.\n *\n * Delegates the validate/call/error machinery to `runTool` (in\n * streaming mode) so there's one source of truth. The task's status\n * is flipped to `running` synchronously — the round loop reads it\n * right after `#start` returns to decide chain heads, and we want\n * that read to see the post-launch state, not the allocation default.\n * Async resolution either keeps it `running` (streamable returned)\n * or transitions to `done` (sync result or error). */\n #dispatch(task: InternalTask, tool: Tool, call: ToolCallPart, ctxBase: ToolContext): void {\n const ctx: ToolContext = { ...ctxBase, tasks: this }\n task.status = \"running\"\n\n const dispatchPromise = runTool(tool, call.params, ctx, { preflight: false, streaming: true })\n\n void dispatchPromise.then(\n (settled) => {\n if (isStreamable(settled)) {\n // Long-running — hold the streamable for partial snapshots /\n // abort, wire its completion back through done().\n task.streamable = settled\n settled.done.then(\n () => {\n const snap = settled.poll()\n this.done(task.id, {\n content: snap.content,\n error: snap.error,\n isError: snap.isError,\n meta: snap.meta,\n })\n },\n // `done` shouldn't reject by contract; treat as internal bug.\n (error: unknown) => this.done(task.id, toErrorResult(error))\n )\n return\n }\n // Sync path: validation error, sync return, or thrown error —\n // runTool has already formatted everything into a ToolResult.\n this.done(task.id, settled)\n },\n // The permission gate threw (or AiError leaked from runTool).\n // Either way, format and settle the task.\n (error: unknown) => this.done(task.id, toErrorResult(error))\n )\n }\n\n /** Walk pending tasks; start any whose `dependsOn` just completed.\n * If the dependency failed, propagate cancellation: dependents land\n * in `done` with an `UPSTREAM_FAILED` result. */\n #startReadyDependents(completedId: string, completedResult: ToolResult): void {\n for (const t of this.#map.values()) {\n if (t.status !== \"pending\" || t.waitingFor !== completedId) continue\n if (completedResult.isError) {\n // Skip dependent — its predecessor failed.\n this.done(\n t.id,\n toErrorResult(\n new AiError({\n code: \"UPSTREAM_FAILED\",\n data: { dependsOn: completedId },\n message: `skipped: upstream task ${completedId} failed`,\n })\n )\n )\n continue\n }\n void this.#startPending(t)\n }\n }\n\n async #startPending(task: InternalTask): Promise<void> {\n const pending = task.pending\n if (!pending) return\n if (!this.#needsPreflight(pending.tool, pending.ctx)) {\n task.pending = undefined\n task.waitingFor = undefined\n task.ownerRound = undefined\n this.#dispatch(task, pending.tool, pending.call, pending.ctx)\n return\n }\n\n const preflight = await this.#preflight(pending.tool, pending.call, pending.ctx)\n if (preflight) {\n this.done(task.id, preflight)\n return\n }\n\n // Restart as a regular task. The round that originally registered\n // this task has already returned its placeholder, so whatever happens\n // now flows through normal `task-done`.\n task.pending = undefined\n task.waitingFor = undefined\n task.ownerRound = undefined\n this.#dispatch(task, pending.tool, pending.call, pending.ctx)\n }\n\n /** Build a `ToolResultPart` for a task at round-end. Done tasks pass\n * through their captured result; still-running tasks get a snapshot\n * from the streamable (if any) plus a placeholder note for the model. */\n #buildPart(call: ToolCallPart, task: InternalTask): ToolResultPart {\n if (task.status === \"done\" && task.result) {\n return {\n content: task.result.content,\n error: task.result.error,\n id: call.id,\n isError: task.result.isError,\n meta: stampTaskMeta(task.result.meta, task),\n name: call.name,\n type: \"tool-result\",\n }\n }\n\n // Pending: never started, will run when its dependency completes.\n // Placeholder uses the standard TaskInfo shape so it's parseable\n // the same way as task_list / heartbeat entries.\n if (task.status === \"pending\") {\n return {\n content: [{ data: toTaskInfo(task), tag: \"task\", type: \"meta\" }],\n id: call.id,\n isError: false,\n meta: stampTaskMeta(undefined, task),\n name: call.name,\n type: \"tool-result\",\n }\n }\n\n // Running: capture whatever the streamable has so far (partial output)\n // and append a `<task>` MetaPart with an explicit \"still running\"\n // hint. Without the hint, models tend to treat partial output as a\n // final answer and respond prematurely; with it they see the state\n // structurally and know the final result will arrive as a later\n // system message. Tagged `<task>` for symmetry with the pending /\n // task_list / heartbeat / task-done entries — same shape everywhere\n // a task surfaces.\n const snap = task.streamable?.poll()\n const baseContent = partialContentFrom(snap)\n const trailer: MetaPart = {\n content:\n \"Task is still running. Partial output above. The final result \" +\n \"will arrive as a system message when the task completes; you \" +\n \"do not need to poll. Continue with other work or wait.\",\n data: {\n ...toTaskInfo(task),\n },\n tag: \"task\",\n type: \"meta\",\n }\n const parts: ContentPart[] = []\n if (typeof baseContent === \"string\") {\n if (baseContent !== \"\") parts.push({ text: baseContent, type: \"text\" })\n } else {\n parts.push(...baseContent)\n }\n parts.push(trailer)\n return {\n content: parts,\n id: call.id,\n isError: false,\n meta: stampTaskMeta(snap?.meta, task),\n name: call.name,\n type: \"tool-result\",\n }\n }\n}\n\n/** Stamp `meta.task` with the current task state. Preserves any\n * tool-attached `meta` fields. Used both on done results (so the\n * model can correlate completion to the original call) and on\n * partial / pending placeholders. */\nfunction stampTaskMeta(\n base: ToolResult[\"meta\"] | undefined,\n task: InternalTask\n): ToolResult[\"meta\"] & TaskMeta {\n return {\n ...base,\n task: {\n dependsOn: task.waitingFor,\n desc: task.desc,\n durationMs: task.finishedAt ? task.finishedAt - task.startedAt : undefined,\n id: task.id,\n status: task.status,\n type: task.type,\n },\n }\n}\n\n/** Build the \"running\" placeholder content from a streamable snapshot.\n * Empty string when there's nothing yet to show; copies the parts\n * array so downstream mutation of the result message can't reach back\n * into the streamable's accumulator. */\nfunction partialContentFrom(\n snap: { content: ToolResult[\"content\"] } | undefined\n): ToolResultPart[\"content\"] {\n if (!snap) return \"\"\n if (typeof snap.content === \"string\") return snap.content\n return [...snap.content]\n}\n\n/** Best-effort human-readable label for a tool call. Reads a\n * `description` field from params if the tool defined one (bash does);\n * otherwise falls back to the tool name. Kept short so log lines stay\n * scannable. */\nfunction descOfCall(call: ToolCallPart): string {\n const params = call.params as { description?: unknown } | null | undefined\n if (params && typeof params === \"object\" && typeof params.description === \"string\") {\n return params.description\n }\n return call.name\n}\n\n/** Synthesize the tool-result payload returned when the model calls a\n * tool that wasn't registered for this turn. Same shape the previous\n * `unknownToolResult` helper produced; inlined here to keep `tasks.ts`\n * self-contained. */\nfunction unknownToolResult(name: string): ToolResult {\n const err = new AiError({\n code: \"UNKNOWN_TOOL\",\n message: `no tool named \"${name}\" is registered for this turn`,\n })\n return toErrorResult(err)\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((r) => {\n const t = setTimeout(r, ms)\n t.unref()\n })\n}\n\n/** Render an array of `TaskInfo` as a `<tasks>` MetaPart for the model\n * (heartbeat pulses and `task_list`). Each task lands as one line of\n * JSON. The `result` field on done tasks is stripped — listing should\n * give an inventory, not historical output (the result was already\n * injected as a system message at task-done time, and re-shipping it\n * on every heartbeat / list call would be a token bomb). */\nexport function taskInfoPart(info: readonly TaskInfo[]): MetaPart {\n if (info.length === 0) return { data: \"no active tasks\", tag: \"tasks\", type: \"meta\" }\n const data = info.map((t) => safeStringify(t, omitResult)).join(\"\\n\")\n return { data, tag: \"tasks\", type: \"meta\" }\n}\n\n/** JSON.stringify replacer that drops the `result` field. Used by\n * `taskInfoPart` to keep listing payloads bounded. */\nfunction omitResult(key: string, value: unknown): unknown {\n return key === \"result\" ? undefined : value\n}\n\nfunction toTaskInfo(task: InternalTask): TaskInfo {\n const { id, status, type, desc } = task\n const ms = (task.finishedAt ?? Date.now()) - task.startedAt\n if (status === \"running\") {\n return { desc, elapsedMs: ms, hasNewOutput: task.streamable?.hasNew?.(), id, status, type }\n }\n if (status === \"pending\") {\n return { desc, elapsedMs: ms, id, status, type, waitingFor: task.waitingFor ?? \"\" }\n }\n // status === \"done\" — `result` is set by `done()` before status flips,\n // so the `?? toErrorResult(...)` is just a defensive fallback for\n // a malformed record (shouldn't happen in practice).\n return {\n desc,\n durationMs: ms,\n id,\n result:\n task.result ??\n toErrorResult(\n new AiError({\n code: \"INTERNAL\",\n message: `task \"${task.id}\" completed without a result`,\n })\n ),\n status,\n type,\n }\n}\n\n/** Format a finished task as the parts of a system inject. Layout:\n *\n * <task>{id, type, desc, status: \"done\", durationMs}</task>\n * {result body}\n *\n * The header is the standard `TaskInfo`-shaped JSON so consumers\n * (model, TUI) can parse it the same way they parse `task_list` and\n * heartbeat output — same shape everywhere a task surfaces.\n *\n * The body comes straight from `result.content`. For errors, that\n * already includes the `<error>{code, message, ...}</error>` MetaPart\n * + the formatted `❌ CODE: message` block (baked in by\n * `toErrorResult`), so this function doesn't need to special-case\n * errors — the structured tag and human body ride along with the\n * result content for any tool failure, anywhere.\n *\n * System messages can't carry attachments, so any image/pdf/etc. in\n * the result degrades to a `[image]` placeholder via\n * `stringifyContent` — best-effort, model still sees *something* was\n * there. */\nfunction formatTaskCompletion(task: DoneTaskInfo): (TextPart | MetaPart)[] {\n const { result, ...header } = task\n const parts: (TextPart | MetaPart)[] = [{ data: header, tag: \"task\", type: \"meta\" }]\n const bodyText = stringifyContent(result.content)\n if (bodyText !== \"\") parts.push({ text: bodyText, type: \"text\" })\n return parts\n}\n\n/** Build an `inject`-ready system message for a finished task. */\nexport function taskCompletionMessage(task: DoneTaskInfo): Message<\"system\"> {\n return {\n content: formatTaskCompletion(task),\n meta: { kind: \"task\", taskId: task.id },\n role: \"system\",\n }\n}\n"],"mappings":";;;;AAiBA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;AAqHzB,IAAa,QAAb,cAA2B,QAAqB;CAC9C,uBAAgB,IAAI,IAA0B;CAC9C,UAAU;CAEV,SAAoD,CAAC;;;;;CAMrD;CACA;CAEA,IAAI,cAAkC;EACpC,OAAO,KAAK;CACd;CACA,IAAI,YAAY,OAA2B;EACzC,KAAK,eAAe;EACpB,KAAK,eAAe;CACtB;;CAKA,UAA+B;EAC7B,OAAO,CAAC,GAAG,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,MAAM,EAAE,WAAW,MAAM,CAAC,CAAC,KAAK,MAAM,WAAW,CAAC,CAAC;CAC5F;;;CAIA,WAAoC;EAClC,OAAO,CAAC,GAAG,KAAK,KAAK,OAAO,CAAC,CAAC,CAC3B,QAAQ,MAA8C,EAAE,WAAW,MAAM,CAAC,CAC1E,KAAK,MAAM,WAAW,CAAC,CAAiB;CAC7C;;CAGA,IAAI,IAAkC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