@draht/coding-agent 2026.10.4 → 2026.10.8-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +32 -6
- package/dist/bundle/chunks/{anthropic-messages-GAKYXF65.js → anthropic-messages-E2P6C3P7.js} +1 -1
- package/dist/bundle/chunks/anthropic.js +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-ZIXMK6JO.js → azure-openai-responses-JZMSTDIM.js} +1 -1
- package/dist/bundle/chunks/bedrock-converse-stream.js +20 -20
- package/dist/bundle/chunks/chunk-2JZLKNZ4.js +3 -0
- package/dist/bundle/chunks/chunk-5QJFWTKA.js +4 -0
- package/dist/bundle/chunks/{chunk-XKDTJ4YR.js → chunk-6QIFWMDF.js} +1 -1
- package/dist/bundle/chunks/{chunk-5VZWYVZB.js → chunk-AHGUOQPH.js} +2 -2
- package/dist/bundle/chunks/{chunk-H6FT43VC.js → chunk-BOGY4QVF.js} +4 -4
- package/dist/bundle/chunks/{chunk-RZKPFWMH.js → chunk-D3HO453P.js} +2 -2
- package/dist/bundle/chunks/{chunk-KVH4HR57.js → chunk-FHX2S5IG.js} +1 -1
- package/dist/bundle/chunks/chunk-GBFVS2SF.js +12 -0
- package/dist/bundle/chunks/chunk-GD2WVXWT.js +65 -0
- package/dist/bundle/chunks/{chunk-Z2INEV2J.js → chunk-KJJJSTND.js} +307 -168
- package/dist/bundle/chunks/{chunk-BXSHCX3G.js → chunk-KY2BG6BC.js} +1 -1
- package/dist/bundle/chunks/chunk-LO6CVU2L.js +6 -0
- package/dist/bundle/chunks/chunk-PGJAHC3R.js +107 -0
- package/dist/bundle/chunks/chunk-QVFELZW2.js +312 -0
- package/dist/bundle/chunks/{chunk-COF5JT7R.js → chunk-QVTLBSTH.js} +1 -1
- package/dist/bundle/chunks/{chunk-DPE4ALPU.js → chunk-U6LDZZGM.js} +10 -10
- package/dist/bundle/chunks/{chunk-D6TMD5Q2.js → chunk-UTRX2VHB.js} +8 -8
- package/dist/bundle/chunks/{chunk-LDAOC5RB.js → chunk-VQOV5VFH.js} +1 -1
- package/dist/bundle/chunks/chunk-VXUJMEMO.js +2 -0
- package/dist/bundle/chunks/{cli-SR5QBZH4.js → cli-O6OWCY7N.js} +1 -1
- package/dist/bundle/chunks/execute-4JU5WQXP.js +18 -0
- package/dist/bundle/chunks/google-antigravity.js +1 -1
- package/dist/bundle/chunks/google-gemini-cli.js +1 -1
- package/dist/bundle/chunks/{google-generative-ai-RPUPQ6PM.js → google-generative-ai-HPNDIAZD.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-EZES5QVQ.js → google-vertex-KPAWJ4SP.js} +1 -1
- package/dist/bundle/chunks/https-proxy-agent-WQIRL24U.js +13 -0
- package/dist/bundle/chunks/lib-ULKZYRGD.js +9 -0
- package/dist/bundle/chunks/{mistral-conversations-AOYGU43Y.js → mistral-conversations-FMSPWQ7A.js} +1 -1
- package/dist/bundle/chunks/{multipart-parser-AZP5BX2W.js → multipart-parser-HMCXZ4BD.js} +1 -1
- package/dist/bundle/chunks/{node-LQ52KV6B.js → node-4JNG6XQO.js} +1 -1
- package/dist/bundle/chunks/{node-C2JGH2OB.js → node-6IIDYB3K.js} +1 -1
- package/dist/bundle/chunks/openai-chatgpt.js +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-M2Y77JEQ.js → openai-codex-responses-TU7NGPXE.js} +1 -1
- package/dist/bundle/chunks/openai-codex.js +1 -1
- package/dist/bundle/chunks/{openai-completions-A4OKYOYV.js → openai-completions-GANCQQO5.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-6IXV53T3.js → openai-responses-ASDPAX3E.js} +1 -1
- package/dist/bundle/chunks/{openrouter-images-LYV4NKFM.js → openrouter-images-NROSQXMZ.js} +1 -1
- package/dist/bundle/chunks/openrouter.js +1 -1
- package/dist/bundle/chunks/{pi-messages-KKMEUT3Z.js → pi-messages-2QEJYOAO.js} +1 -1
- package/dist/bundle/chunks/radius.js +1 -1
- package/dist/bundle/chunks/{runtime-6YJPGSP7.js → runtime-FIGQHW75.js} +1 -1
- package/dist/bundle/chunks/runtime-TJ3EAMJK.js +3 -0
- package/dist/bundle/chunks/{settings-manager-D2EG7WDO.js → settings-manager-HC5RR36T.js} +1 -1
- package/dist/bundle/chunks/src-KDGO7EGF.js +4 -0
- package/dist/bundle/chunks/virtual-modules-UIGTRGHQ.js +2 -0
- package/dist/bundle/chunks/xai.js +1 -1
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.js +3 -3
- package/dist/cli/args.js.map +1 -1
- package/dist/core/builtins/duet.d.ts +5 -2
- package/dist/core/builtins/duet.d.ts.map +1 -1
- package/dist/core/builtins/duet.js +65 -27
- package/dist/core/builtins/duet.js.map +1 -1
- package/dist/core/builtins/index.d.ts.map +1 -1
- package/dist/core/builtins/index.js +2 -0
- package/dist/core/builtins/index.js.map +1 -1
- package/dist/core/builtins/polyphase.d.ts +15 -0
- package/dist/core/builtins/polyphase.d.ts.map +1 -0
- package/dist/core/builtins/polyphase.js +196 -0
- package/dist/core/builtins/polyphase.js.map +1 -0
- package/dist/core/builtins/subagent.d.ts +44 -34
- package/dist/core/builtins/subagent.d.ts.map +1 -1
- package/dist/core/builtins/subagent.js +827 -560
- package/dist/core/builtins/subagent.js.map +1 -1
- package/dist/core/extensions/types.d.ts +17 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybindings.d.ts +30 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +24 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-resolver.js +4 -4
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/multi-agent/permission-gate.d.ts.map +1 -1
- package/dist/core/multi-agent/permission-gate.js +4 -1
- package/dist/core/multi-agent/permission-gate.js.map +1 -1
- package/dist/core/polyphase/approval.d.ts +35 -0
- package/dist/core/polyphase/approval.d.ts.map +1 -0
- package/dist/core/polyphase/approval.js +184 -0
- package/dist/core/polyphase/approval.js.map +1 -0
- package/dist/core/polyphase/child-events.d.ts +107 -0
- package/dist/core/polyphase/child-events.d.ts.map +1 -0
- package/dist/core/polyphase/child-events.js +862 -0
- package/dist/core/polyphase/child-events.js.map +1 -0
- package/dist/core/polyphase/child-process.d.ts +65 -0
- package/dist/core/polyphase/child-process.d.ts.map +1 -0
- package/dist/core/polyphase/child-process.js +361 -0
- package/dist/core/polyphase/child-process.js.map +1 -0
- package/dist/core/polyphase/commands.d.ts +44 -0
- package/dist/core/polyphase/commands.d.ts.map +1 -0
- package/dist/core/polyphase/commands.js +244 -0
- package/dist/core/polyphase/commands.js.map +1 -0
- package/dist/core/polyphase/details.d.ts +40 -0
- package/dist/core/polyphase/details.d.ts.map +1 -0
- package/dist/core/polyphase/details.js +538 -0
- package/dist/core/polyphase/details.js.map +1 -0
- package/dist/core/polyphase/emitter.d.ts +20 -0
- package/dist/core/polyphase/emitter.d.ts.map +1 -0
- package/dist/core/polyphase/emitter.js +90 -0
- package/dist/core/polyphase/emitter.js.map +1 -0
- package/dist/core/polyphase/jsonl-reader.d.ts +31 -0
- package/dist/core/polyphase/jsonl-reader.d.ts.map +1 -0
- package/dist/core/polyphase/jsonl-reader.js +161 -0
- package/dist/core/polyphase/jsonl-reader.js.map +1 -0
- package/dist/core/polyphase/keyword.d.ts +27 -0
- package/dist/core/polyphase/keyword.d.ts.map +1 -0
- package/dist/core/polyphase/keyword.js +97 -0
- package/dist/core/polyphase/keyword.js.map +1 -0
- package/dist/core/polyphase/limiter.d.ts +38 -0
- package/dist/core/polyphase/limiter.d.ts.map +1 -0
- package/dist/core/polyphase/limiter.js +129 -0
- package/dist/core/polyphase/limiter.js.map +1 -0
- package/dist/core/polyphase/model-selection.d.ts +35 -0
- package/dist/core/polyphase/model-selection.d.ts.map +1 -0
- package/dist/core/polyphase/model-selection.js +72 -0
- package/dist/core/polyphase/model-selection.js.map +1 -0
- package/dist/core/polyphase/render/format.d.ts +52 -0
- package/dist/core/polyphase/render/format.d.ts.map +1 -0
- package/dist/core/polyphase/render/format.js +169 -0
- package/dist/core/polyphase/render/format.js.map +1 -0
- package/dist/core/polyphase/render/renderers.d.ts +63 -0
- package/dist/core/polyphase/render/renderers.d.ts.map +1 -0
- package/dist/core/polyphase/render/renderers.js +277 -0
- package/dist/core/polyphase/render/renderers.js.map +1 -0
- package/dist/core/polyphase/render/run-block.d.ts +45 -0
- package/dist/core/polyphase/render/run-block.d.ts.map +1 -0
- package/dist/core/polyphase/render/run-block.js +843 -0
- package/dist/core/polyphase/render/run-block.js.map +1 -0
- package/dist/core/polyphase/render/snapshot.d.ts +106 -0
- package/dist/core/polyphase/render/snapshot.d.ts.map +1 -0
- package/dist/core/polyphase/render/snapshot.js +292 -0
- package/dist/core/polyphase/render/snapshot.js.map +1 -0
- package/dist/core/polyphase/result-text.d.ts +41 -0
- package/dist/core/polyphase/result-text.d.ts.map +1 -0
- package/dist/core/polyphase/result-text.js +326 -0
- package/dist/core/polyphase/result-text.js.map +1 -0
- package/dist/core/polyphase/session.d.ts +33 -0
- package/dist/core/polyphase/session.d.ts.map +1 -0
- package/dist/core/polyphase/session.js +106 -0
- package/dist/core/polyphase/session.js.map +1 -0
- package/dist/core/polyphase/settings.d.ts +18 -0
- package/dist/core/polyphase/settings.d.ts.map +1 -0
- package/dist/core/polyphase/settings.js +93 -0
- package/dist/core/polyphase/settings.js.map +1 -0
- package/dist/core/polyphase/store.d.ts +197 -0
- package/dist/core/polyphase/store.d.ts.map +1 -0
- package/dist/core/polyphase/store.js +558 -0
- package/dist/core/polyphase/store.js.map +1 -0
- package/dist/core/polyphase/types.d.ts +371 -0
- package/dist/core/polyphase/types.d.ts.map +1 -0
- package/dist/core/polyphase/types.js +36 -0
- package/dist/core/polyphase/types.js.map +1 -0
- package/dist/core/polyphase/ui/controller.d.ts +28 -0
- package/dist/core/polyphase/ui/controller.d.ts.map +1 -0
- package/dist/core/polyphase/ui/controller.js +150 -0
- package/dist/core/polyphase/ui/controller.js.map +1 -0
- package/dist/core/polyphase/ui/dock.d.ts +27 -0
- package/dist/core/polyphase/ui/dock.d.ts.map +1 -0
- package/dist/core/polyphase/ui/dock.js +121 -0
- package/dist/core/polyphase/ui/dock.js.map +1 -0
- package/dist/core/polyphase/ui/inspector.d.ts +117 -0
- package/dist/core/polyphase/ui/inspector.d.ts.map +1 -0
- package/dist/core/polyphase/ui/inspector.js +1016 -0
- package/dist/core/polyphase/ui/inspector.js.map +1 -0
- package/dist/core/polyphase/ui/transcript-layout.d.ts +55 -0
- package/dist/core/polyphase/ui/transcript-layout.d.ts.map +1 -0
- package/dist/core/polyphase/ui/transcript-layout.js +210 -0
- package/dist/core/polyphase/ui/transcript-layout.js.map +1 -0
- package/dist/core/polyphase/update-pump.d.ts +18 -0
- package/dist/core/polyphase/update-pump.d.ts.map +1 -0
- package/dist/core/polyphase/update-pump.js +132 -0
- package/dist/core/polyphase/update-pump.js.map +1 -0
- package/dist/core/polyphase/workflow/agent-host.d.ts +26 -0
- package/dist/core/polyphase/workflow/agent-host.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/agent-host.js +187 -0
- package/dist/core/polyphase/workflow/agent-host.js.map +1 -0
- package/dist/core/polyphase/workflow/guidance.d.ts +19 -0
- package/dist/core/polyphase/workflow/guidance.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/guidance.js +119 -0
- package/dist/core/polyphase/workflow/guidance.js.map +1 -0
- package/dist/core/polyphase/workflow/launch.d.ts +41 -0
- package/dist/core/polyphase/workflow/launch.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/launch.js +173 -0
- package/dist/core/polyphase/workflow/launch.js.map +1 -0
- package/dist/core/polyphase/workflow/meta.d.ts +43 -0
- package/dist/core/polyphase/workflow/meta.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/meta.js +529 -0
- package/dist/core/polyphase/workflow/meta.js.map +1 -0
- package/dist/core/polyphase/workflow/prelude.d.ts +24 -0
- package/dist/core/polyphase/workflow/prelude.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/prelude.js +93 -0
- package/dist/core/polyphase/workflow/prelude.js.map +1 -0
- package/dist/core/polyphase/workflow/runtime.d.ts +79 -0
- package/dist/core/polyphase/workflow/runtime.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/runtime.js +217 -0
- package/dist/core/polyphase/workflow/runtime.js.map +1 -0
- package/dist/core/polyphase/workflow/runtime.lazy.d.ts +3 -0
- package/dist/core/polyphase/workflow/runtime.lazy.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/runtime.lazy.js +3 -0
- package/dist/core/polyphase/workflow/runtime.lazy.js.map +1 -0
- package/dist/core/polyphase/workflow/saved.d.ts +55 -0
- package/dist/core/polyphase/workflow/saved.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/saved.js +299 -0
- package/dist/core/polyphase/workflow/saved.js.map +1 -0
- package/dist/core/polyphase/workflow/structured-output.d.ts +22 -0
- package/dist/core/polyphase/workflow/structured-output.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/structured-output.js +66 -0
- package/dist/core/polyphase/workflow/structured-output.js.map +1 -0
- package/dist/core/polyphase/workflow/tool.d.ts +24 -0
- package/dist/core/polyphase/workflow/tool.d.ts.map +1 -0
- package/dist/core/polyphase/workflow/tool.js +139 -0
- package/dist/core/polyphase/workflow/tool.js.map +1 -0
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +27 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/socket-server/permission-relay.js +4 -0
- package/dist/core/socket-server/permission-relay.js.map +1 -1
- package/dist/core/trust-manager.d.ts +3 -2
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +5 -2
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/experimental/micro/runtime.js +1 -1
- package/dist/experimental/micro/runtime.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +18 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +11 -2
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +9 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/prompts/commands/orchestrate.md +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +7 -1
- package/dist/utils/shell.js.map +1 -1
- package/docs/docs.json +4 -0
- package/docs/duet.md +3 -3
- package/docs/environment-variables.md +11 -0
- package/docs/json.md +7 -0
- package/docs/keybindings.md +20 -0
- package/docs/polyphase.md +391 -0
- package/docs/rpc-commands.md +9 -9
- package/docs/settings.md +12 -0
- package/docs/virtual-models.md +3 -3
- package/examples/extensions/preset.ts +3 -3
- package/examples/extensions/subagent/README.md +1 -1
- package/examples/extensions/subagent/agents/planner.md +1 -1
- package/examples/extensions/subagent/agents/reviewer.md +1 -1
- package/examples/extensions/subagent/agents/scout.md +1 -1
- package/examples/extensions/subagent/agents/worker.md +1 -1
- package/examples/extensions/summarize.ts +3 -3
- package/examples/sdk/02-custom-model.ts +1 -1
- package/examples/sdk/12-full-control.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/package.json +10 -10
- package/prompts/commands/orchestrate.md +1 -1
- package/dist/bundle/chunks/chunk-6MSE6LZ3.js +0 -6
- package/dist/bundle/chunks/chunk-6ZJKIMU7.js +0 -2
- package/dist/bundle/chunks/chunk-736QBNUZ.js +0 -12
- package/dist/bundle/chunks/chunk-CEJJ5XF2.js +0 -170
- package/dist/bundle/chunks/chunk-IWTUBX6V.js +0 -4
- package/dist/bundle/chunks/chunk-TIA2T6EO.js +0 -3
- package/dist/bundle/chunks/execute-VCYDHEYA.js +0 -328
- package/dist/bundle/chunks/https-proxy-agent-O2PVUIOI.js +0 -13
- package/dist/bundle/chunks/lib-XOG5PI3Y.js +0 -9
- package/dist/bundle/chunks/src-TIBHS42X.js +0 -4
- package/dist/bundle/chunks/virtual-modules-JTCGDL2Z.js +0 -2
- /package/dist/bundle/chunks/{chunk-ZZD35WKM.js → chunk-FBU742QF.js} +0 -0
- /package/dist/bundle/chunks/{chunk-SVNWI7EV.js → chunk-XHCO4PPH.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limiter.js","sourceRoot":"","sources":["../../../src/core/polyphase/limiter.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC7C,YAAY,OAAO,GAAG,yCAAyC;QAC9D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACnC,CAAC;CACD;AAQD,SAAS,iBAAiB,CAAC,QAAgB;IAC1C,IAAI,QAAQ,KAAK,MAAM,CAAC,iBAAiB;QAAE,OAAO,MAAM,CAAC,gBAAgB,CAAC;IAC1E,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACrC,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAChB,GAAG,CAAS;IACZ,MAAM,GAAG,CAAC,CAAC;IACF,OAAO,GAAa,EAAE,CAAC;IACvB,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IAEnD,YAAY,QAAgB;QAC3B,IAAI,CA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AAI,CAAC;QAChB,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;IAEO,MAAM;QACb,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACvC,IAAI,CAAC;gBACJ,QAAQ,EAAE,CAAC;YACZ,CAAC;YAAC,MAAM,CAAC;gBACR,oEAAoE;YACrE,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["export interface LimiterLease {\n\t/** Idempotent: a second call is a no-op. */\n\trelease(): void;\n}\n\nexport interface LimiterStats {\n\tcapacity: number;\n\tactive: number;\n\tqueued: number;\n}\n\nexport class LimiterAbortedError extends Error {\n\tconstructor(message = \"aborted while waiting for an agent slot\") {\n\t\tsuper(message);\n\t\tthis.name = \"LimiterAbortedError\";\n\t}\n}\n\ninterface Waiter {\n\tresolve: (lease: LimiterLease) => void;\n\treject: (error: Error) => void;\n\tcleanup: () => void;\n}\n\nfunction normalizeCapacity(capacity: number): number {\n\tif (capacity === Number.POSITIVE_INFINITY) return Number.MAX_SAFE_INTEGER;\n\tconst floored = Math.floor(capacity);\n\treturn Number.isFinite(floored) && floored >= 1 ? floored : 1;\n}\n\n/**\n * FIFO semaphore gating how many child agent processes run at once in a session.\n * Leases are held only around a child process, never by orchestrators, so nested\n * acquisition inside a lease cannot deadlock.\n */\nexport class AgentLimiter {\n\tprivate cap: number;\n\tprivate active = 0;\n\tprivate readonly waiters: Waiter[] = [];\n\tprivate readonly listeners = new Set<() => void>();\n\n\tconstructor(capacity: number) {\n\t\tthis.cap = normalizeCapacity(capacity);\n\t}\n\n\tget capacity(): number {\n\t\treturn this.cap;\n\t}\n\n\tsetCapacity(capacity: number): void {\n\t\tthis.cap = normalizeCapacity(capacity);\n\t\tthis.grantWaiting();\n\t\tthis.notify();\n\t}\n\n\tacquire(options?: { signal?: AbortSignal; onQueued?: () => void }): Promise<LimiterLease> {\n\t\tconst signal = options?.signal;\n\t\tif (signal?.aborted) {\n\t\t\treturn Promise.reject(new LimiterAbortedError());\n\t\t}\n\n\t\tif (this.active < this.cap && this.waiters.length === 0) {\n\t\t\tthis.active++;\n\t\t\tthis.notify();\n\t\t\treturn Promise.resolve(this.makeLease());\n\t\t}\n\n\t\treturn new Promise<LimiterLease>((resolve, reject) => {\n\t\t\tconst waiter: Waiter = { resolve, reject, cleanup: () => {} };\n\t\t\tif (signal) {\n\t\t\t\tconst onAbort = () => {\n\t\t\t\t\tconst index = this.waiters.indexOf(waiter);\n\t\t\t\t\tif (index === -1) return;\n\t\t\t\t\tthis.waiters.splice(index, 1);\n\t\t\t\t\twaiter.reject(new LimiterAbortedError());\n\t\t\t\t\tthis.notify();\n\t\t\t\t};\n\t\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\twaiter.cleanup = () => signal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t\tthis.waiters.push(waiter);\n\t\t\tthis.notify();\n\t\t\t// onQueued may abort the signal synchronously; the listener above already ran by now.\n\t\t\ttry {\n\t\t\t\toptions?.onQueued?.();\n\t\t\t} catch (error) {\n\t\t\t\tconst index = this.waiters.indexOf(waiter);\n\t\t\t\tif (index !== -1) {\n\t\t\t\t\tthis.waiters.splice(index, 1);\n\t\t\t\t\twaiter.cleanup();\n\t\t\t\t\tthis.notify();\n\t\t\t\t}\n\t\t\t\treject(error instanceof Error ? error : new Error(String(error)));\n\t\t\t}\n\t\t});\n\t}\n\n\tstats(): LimiterStats {\n\t\treturn { capacity: this.cap, active: this.active, queued: this.waiters.length };\n\t}\n\n\tonChange(listener: () => void): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => this.listeners.delete(listener);\n\t}\n\n\trejectAll(reason: Error): void {\n\t\tconst waiters = this.waiters.splice(0, this.waiters.length);\n\t\tfor (const waiter of waiters) {\n\t\t\twaiter.cleanup();\n\t\t\twaiter.reject(reason);\n\t\t}\n\t\tif (waiters.length > 0) this.notify();\n\t}\n\n\tprivate makeLease(): LimiterLease {\n\t\tlet released = false;\n\t\treturn {\n\t\t\trelease: () => {\n\t\t\t\tif (released) return;\n\t\t\t\treleased = true;\n\t\t\t\tthis.active--;\n\t\t\t\tthis.grantWaiting();\n\t\t\t\tthis.notify();\n\t\t\t},\n\t\t};\n\t}\n\n\t/** Grants queued waiters up to capacity. Does not notify; callers notify once themselves. */\n\tprivate grantWaiting(): boolean {\n\t\tlet granted = false;\n\t\twhile (this.active < this.cap && this.waiters.length > 0) {\n\t\t\tconst waiter = this.waiters.shift();\n\t\t\tif (!waiter) break;\n\t\t\twaiter.cleanup();\n\t\t\tthis.active++;\n\t\t\twaiter.resolve(this.makeLease());\n\t\t\tgranted = true;\n\t\t}\n\t\treturn granted;\n\t}\n\n\tprivate notify(): void {\n\t\tfor (const listener of this.listeners) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch {\n\t\t\t\t// A listener (store/dock rendering) must not stall the grant queue.\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model and thinking-level selection for a child run (§7.5, D1).
|
|
3
|
+
*
|
|
4
|
+
* Precedence, first match wins: an explicit override, a workflow phase model, the
|
|
5
|
+
* agent's frontmatter model, the parent session's model (inherited), or the child's
|
|
6
|
+
* own default when nothing else applies.
|
|
7
|
+
*/
|
|
8
|
+
import type { ThinkingLevel } from "@draht/agent-core";
|
|
9
|
+
import type { Api, Model } from "@draht/ai";
|
|
10
|
+
import { type AgentModelInfo } from "./types.ts";
|
|
11
|
+
export declare class ModelSelectionError extends Error {
|
|
12
|
+
}
|
|
13
|
+
export interface ChildModelInput {
|
|
14
|
+
/** Tool parameter / `agent()` opts.model. */
|
|
15
|
+
override?: string;
|
|
16
|
+
/** Tool parameter thinking / `agent()` opts.effort. */
|
|
17
|
+
effort?: string;
|
|
18
|
+
/** Workflow meta phase model. */
|
|
19
|
+
phaseModel?: string;
|
|
20
|
+
/** Agent frontmatter model, verbatim (may carry a `:level` suffix). */
|
|
21
|
+
agentModel?: string;
|
|
22
|
+
parentModel?: Model<Api>;
|
|
23
|
+
parentThinking?: ThinkingLevel;
|
|
24
|
+
available: Model<Api>[];
|
|
25
|
+
}
|
|
26
|
+
export interface ChildModelChoice {
|
|
27
|
+
/** Value to pass with `--model`, when the child should be told which model to use. */
|
|
28
|
+
modelArg?: string;
|
|
29
|
+
thinking?: ThinkingLevel;
|
|
30
|
+
info: AgentModelInfo;
|
|
31
|
+
}
|
|
32
|
+
/** `"none"` maps to `"off"`; otherwise a `ThinkingLevel`. Throws `ModelSelectionError` for anything else. */
|
|
33
|
+
export declare function normalizeEffort(effort: string): ThinkingLevel;
|
|
34
|
+
export declare function resolveChildModel(input: ChildModelInput): ChildModelChoice;
|
|
35
|
+
//# sourceMappingURL=model-selection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-selection.d.ts","sourceRoot":"","sources":["../../../src/core/polyphase/model-selection.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,KAAK,cAAc,EAAqC,MAAM,YAAY,CAAC;AAEpF,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAEjD,MAAM,WAAW,eAAe;IAC/B,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,cAAc,CAAC,EAAE,aAAa,CAAC;IAC/B,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAChC,sFAAsF;IACtF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,IAAI,EAAE,cAAc,CAAC;CACrB;AAED,6GAA6G;AAC7G,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAI7D;AA4CD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,CA4B1E"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model and thinking-level selection for a child run (§7.5, D1).
|
|
3
|
+
*
|
|
4
|
+
* Precedence, first match wins: an explicit override, a workflow phase model, the
|
|
5
|
+
* agent's frontmatter model, the parent session's model (inherited), or the child's
|
|
6
|
+
* own default when nothing else applies.
|
|
7
|
+
*/
|
|
8
|
+
import { parseModelPattern } from "../model-resolver.js";
|
|
9
|
+
import { isThinkingLevel } from "./types.js";
|
|
10
|
+
export class ModelSelectionError extends Error {
|
|
11
|
+
}
|
|
12
|
+
/** `"none"` maps to `"off"`; otherwise a `ThinkingLevel`. Throws `ModelSelectionError` for anything else. */
|
|
13
|
+
export function normalizeEffort(effort) {
|
|
14
|
+
if (effort === "none")
|
|
15
|
+
return "off";
|
|
16
|
+
if (isThinkingLevel(effort))
|
|
17
|
+
return effort;
|
|
18
|
+
throw new ModelSelectionError(`unknown thinking level "${effort}"`);
|
|
19
|
+
}
|
|
20
|
+
/** Strict resolution (no invalid-thinking-level fallback): throws when the pattern matches nothing. */
|
|
21
|
+
function resolveStrict(pattern, available) {
|
|
22
|
+
const result = parseModelPattern(pattern, available, { allowInvalidThinkingLevelFallback: false });
|
|
23
|
+
if (!result.model)
|
|
24
|
+
throw new ModelSelectionError(`unknown model "${pattern}"`);
|
|
25
|
+
return { provider: result.model.provider, id: result.model.id, thinkingLevel: result.thinkingLevel };
|
|
26
|
+
}
|
|
27
|
+
/** Best-effort resolution for display only: never throws, leaves provider/id undefined when unresolved. */
|
|
28
|
+
function resolveForDisplay(pattern, available) {
|
|
29
|
+
const result = parseModelPattern(pattern, available, { allowInvalidThinkingLevelFallback: false });
|
|
30
|
+
return result.model
|
|
31
|
+
? { provider: result.model.provider, id: result.model.id, thinkingLevel: result.thinkingLevel }
|
|
32
|
+
: {};
|
|
33
|
+
}
|
|
34
|
+
function choiceFor(source, requested, parsed, thinking, modelArg) {
|
|
35
|
+
return {
|
|
36
|
+
modelArg,
|
|
37
|
+
thinking,
|
|
38
|
+
info: {
|
|
39
|
+
source,
|
|
40
|
+
requested,
|
|
41
|
+
requestedThinking: thinking,
|
|
42
|
+
provider: parsed.provider,
|
|
43
|
+
id: parsed.id,
|
|
44
|
+
confirmed: false,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function resolveChildModel(input) {
|
|
49
|
+
const normalizedEffort = input.effort !== undefined ? normalizeEffort(input.effort) : undefined;
|
|
50
|
+
if (input.override !== undefined) {
|
|
51
|
+
const parsed = resolveStrict(input.override, input.available);
|
|
52
|
+
const thinking = normalizedEffort ?? parsed.thinkingLevel;
|
|
53
|
+
return choiceFor("override", input.override, parsed, thinking, `${parsed.provider}/${parsed.id}`);
|
|
54
|
+
}
|
|
55
|
+
if (input.phaseModel !== undefined) {
|
|
56
|
+
const parsed = resolveStrict(input.phaseModel, input.available);
|
|
57
|
+
const thinking = normalizedEffort ?? parsed.thinkingLevel;
|
|
58
|
+
return choiceFor("phase", input.phaseModel, parsed, thinking, `${parsed.provider}/${parsed.id}`);
|
|
59
|
+
}
|
|
60
|
+
if (input.agentModel !== undefined) {
|
|
61
|
+
const parsed = resolveForDisplay(input.agentModel, input.available);
|
|
62
|
+
return choiceFor("frontmatter", input.agentModel, parsed, normalizedEffort, input.agentModel);
|
|
63
|
+
}
|
|
64
|
+
if (input.parentModel !== undefined) {
|
|
65
|
+
const thinking = normalizedEffort ?? input.parentThinking;
|
|
66
|
+
const parsed = { provider: input.parentModel.provider, id: input.parentModel.id };
|
|
67
|
+
const requested = `${input.parentModel.provider}/${input.parentModel.id}`;
|
|
68
|
+
return choiceFor("inherited", requested, parsed, thinking, requested);
|
|
69
|
+
}
|
|
70
|
+
return choiceFor("child-default", undefined, {}, normalizedEffort, undefined);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=model-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-selection.js","sourceRoot":"","sources":["../../../src/core/polyphase/model-selection.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAuB,eAAe,EAAoB,MAAM,YAAY,CAAC;AAEpF,MAAM,OAAO,mBAAoB,SAAQ,KAAK;CAAG;AAuBjD,6GAA6G;AAC7G,MAAM,UAAU,eAAe,CAAC,MAAc;IAC7C,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACpC,IAAI,eAAe,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC3C,MAAM,IAAI,mBAAmB,CAAC,2BAA2B,MAAM,GAAG,CAAC,CAAC;AACrE,CAAC;AAQD,uGAAuG;AACvG,SAAS,aAAa,CAAC,OAAe,EAAE,SAAuB;IAC9D,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,iCAAiC,EAAE,KAAK,EAAE,CAAC,CAAC;IACnG,IAAI,CAAC,MAAM,CAAC,KAAK;QAAE,MAAM,IAAI,mBAAmB,CAAC,kBAAkB,OAAO,GAAG,CAAC,CAAC;IAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,aAAa,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;AACtG,CAAC;AAED,2GAA2G;AAC3G,SAAS,iBAAiB,CAAC,OA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Model and thinking-level selection for a child run (§7.5, D1).\n *\n * Precedence, first match wins: an explicit override, a workflow phase model, the\n * agent's frontmatter model, the parent session's model (inherited), or the child's\n * own default when nothing else applies.\n */\n\nimport type { ThinkingLevel } from \"@draht/agent-core\";\nimport type { Api, Model } from \"@draht/ai\";\nimport { parseModelPattern } from \"../model-resolver.ts\";\nimport { type AgentModelInfo, isThinkingLevel, type ModelSource } from \"./types.ts\";\n\nexport class ModelSelectionError extends Error {}\n\nexport interface ChildModelInput {\n\t/** Tool parameter / `agent()` opts.model. */\n\toverride?: string;\n\t/** Tool parameter thinking / `agent()` opts.effort. */\n\teffort?: string;\n\t/** Workflow meta phase model. */\n\tphaseModel?: string;\n\t/** Agent frontmatter model, verbatim (may carry a `:level` suffix). */\n\tagentModel?: string;\n\tparentModel?: Model<Api>;\n\tparentThinking?: ThinkingLevel;\n\tavailable: Model<Api>[];\n}\n\nexport interface ChildModelChoice {\n\t/** Value to pass with `--model`, when the child should be told which model to use. */\n\tmodelArg?: string;\n\tthinking?: ThinkingLevel;\n\tinfo: AgentModelInfo;\n}\n\n/** `\"none\"` maps to `\"off\"`; otherwise a `ThinkingLevel`. Throws `ModelSelectionError` for anything else. */\nexport function normalizeEffort(effort: string): ThinkingLevel {\n\tif (effort === \"none\") return \"off\";\n\tif (isThinkingLevel(effort)) return effort;\n\tthrow new ModelSelectionError(`unknown thinking level \"${effort}\"`);\n}\n\ninterface ParsedPattern {\n\tprovider?: string;\n\tid?: string;\n\tthinkingLevel?: ThinkingLevel;\n}\n\n/** Strict resolution (no invalid-thinking-level fallback): throws when the pattern matches nothing. */\nfunction resolveStrict(pattern: string, available: Model<Api>[]): ParsedPattern {\n\tconst result = parseModelPattern(pattern, available, { allowInvalidThinkingLevelFallback: false });\n\tif (!result.model) throw new ModelSelectionError(`unknown model \"${pattern}\"`);\n\treturn { provider: result.model.provider, id: result.model.id, thinkingLevel: result.thinkingLevel };\n}\n\n/** Best-effort resolution for display only: never throws, leaves provider/id undefined when unresolved. */\nfunction resolveForDisplay(pattern: string, available: Model<Api>[]): ParsedPattern {\n\tconst result = parseModelPattern(pattern, available, { allowInvalidThinkingLevelFallback: false });\n\treturn result.model\n\t\t? { provider: result.model.provider, id: result.model.id, thinkingLevel: result.thinkingLevel }\n\t\t: {};\n}\n\nfunction choiceFor(\n\tsource: ModelSource,\n\trequested: string | undefined,\n\tparsed: ParsedPattern,\n\tthinking: ThinkingLevel | undefined,\n\tmodelArg: string | undefined,\n): ChildModelChoice {\n\treturn {\n\t\tmodelArg,\n\t\tthinking,\n\t\tinfo: {\n\t\t\tsource,\n\t\t\trequested,\n\t\t\trequestedThinking: thinking,\n\t\t\tprovider: parsed.provider,\n\t\t\tid: parsed.id,\n\t\t\tconfirmed: false,\n\t\t},\n\t};\n}\n\nexport function resolveChildModel(input: ChildModelInput): ChildModelChoice {\n\tconst normalizedEffort = input.effort !== undefined ? normalizeEffort(input.effort) : undefined;\n\n\tif (input.override !== undefined) {\n\t\tconst parsed = resolveStrict(input.override, input.available);\n\t\tconst thinking = normalizedEffort ?? parsed.thinkingLevel;\n\t\treturn choiceFor(\"override\", input.override, parsed, thinking, `${parsed.provider}/${parsed.id}`);\n\t}\n\n\tif (input.phaseModel !== undefined) {\n\t\tconst parsed = resolveStrict(input.phaseModel, input.available);\n\t\tconst thinking = normalizedEffort ?? parsed.thinkingLevel;\n\t\treturn choiceFor(\"phase\", input.phaseModel, parsed, thinking, `${parsed.provider}/${parsed.id}`);\n\t}\n\n\tif (input.agentModel !== undefined) {\n\t\tconst parsed = resolveForDisplay(input.agentModel, input.available);\n\t\treturn choiceFor(\"frontmatter\", input.agentModel, parsed, normalizedEffort, input.agentModel);\n\t}\n\n\tif (input.parentModel !== undefined) {\n\t\tconst thinking = normalizedEffort ?? input.parentThinking;\n\t\tconst parsed: ParsedPattern = { provider: input.parentModel.provider, id: input.parentModel.id };\n\t\tconst requested = `${input.parentModel.provider}/${input.parentModel.id}`;\n\t\treturn choiceFor(\"inherited\", requested, parsed, thinking, requested);\n\t}\n\n\treturn choiceFor(\"child-default\", undefined, {}, normalizedEffort, undefined);\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Glyphs, colours, and width-safe text formatting shared by the tool-row renderer (render/run-block.ts,
|
|
3
|
+
* P9) and the inspector (ui/inspector.ts, P10). Every exported formatter is pure: no timers, no I/O.
|
|
4
|
+
*/
|
|
5
|
+
import type { ThinkingLevel } from "@draht/agent-core";
|
|
6
|
+
import type { Theme, ThemeColor } from "../../../modes/interactive/theme/theme.ts";
|
|
7
|
+
import type { AgentStatus, ModelSource } from "../types.ts";
|
|
8
|
+
export declare const SPINNER_FRAMES: readonly string[];
|
|
9
|
+
export declare function spinnerFrame(now: number): string;
|
|
10
|
+
export declare function statusColor(status: AgentStatus): ThemeColor;
|
|
11
|
+
export declare function statusGlyph(status: AgentStatus, theme: Theme, options: {
|
|
12
|
+
now: number;
|
|
13
|
+
animate: boolean;
|
|
14
|
+
}): string;
|
|
15
|
+
/** `0:07`, `4:51`, `1:02:03`. */
|
|
16
|
+
export declare function formatDuration(ms: number): string;
|
|
17
|
+
/** `950`, `12.3k`, `1.2M`. Rounds first, then picks the unit, so values never round up into the next
|
|
18
|
+
* unit's territory (e.g. 999_600 is `1.0M`, not `1000k`). */
|
|
19
|
+
export declare function formatTokens(n: number): string;
|
|
20
|
+
/** `""` for 0, `<$0.01`, `$0.08`, `$12.40`. */
|
|
21
|
+
export declare function formatCost(usd: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* Collapsed: `id thinking`. Expanded (`withProvider`): `provider/id thinking (source)`, source shown
|
|
24
|
+
* only for `inherited` and `child-default`. Before confirmation (no provider/modelId), falls back to
|
|
25
|
+
* `modelText`, the requested pattern or `"default model"` for an unconfirmed child-default model.
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatModelLabel(row: {
|
|
28
|
+
provider?: string;
|
|
29
|
+
modelId?: string;
|
|
30
|
+
modelText?: string;
|
|
31
|
+
thinking?: ThinkingLevel;
|
|
32
|
+
modelSource?: ModelSource;
|
|
33
|
+
}, options: {
|
|
34
|
+
withProvider: boolean;
|
|
35
|
+
withSource?: boolean;
|
|
36
|
+
}): string;
|
|
37
|
+
/** Collapses whitespace runs (including newlines) to single spaces and trims. */
|
|
38
|
+
export declare function oneLine(text: string): string;
|
|
39
|
+
/** `truncateToWidth(text, width, "…")`: never exceeds `width`, never pads. */
|
|
40
|
+
export declare function fitLine(text: string, width: number): string;
|
|
41
|
+
/** Truncates (no ellipsis) and pads with spaces to exactly `width` visible columns. */
|
|
42
|
+
export declare function padToWidth(text: string, width: number): string;
|
|
43
|
+
export interface ColumnCell {
|
|
44
|
+
text: string;
|
|
45
|
+
width: number | "flex";
|
|
46
|
+
align?: "left" | "right";
|
|
47
|
+
}
|
|
48
|
+
/** Lays out `cells` within `width` columns separated by `gap` spaces (default 1). Fixed-width cells are
|
|
49
|
+
* truncated/padded to their width; `"flex"` cells share the remaining space evenly. The result's visible
|
|
50
|
+
* width never exceeds `width`, even with CJK or emoji content. */
|
|
51
|
+
export declare function columns(cells: readonly ColumnCell[], width: number, gap?: number): string;
|
|
52
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../src/core/polyphase/render/format.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE5D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAAyB,CAAC;AAEtE,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,G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BAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAI,GAAG,MAAM,CA4BpF"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Glyphs, colours, and width-safe text formatting shared by the tool-row renderer (render/run-block.ts,
|
|
3
|
+
* P9) and the inspector (ui/inspector.ts, P10). Every exported formatter is pure: no timers, no I/O.
|
|
4
|
+
*/
|
|
5
|
+
import { truncateToWidth, visibleWidth } from "@draht/tui";
|
|
6
|
+
export const SPINNER_FRAMES = ["◐", "◓", "◑", "◒"];
|
|
7
|
+
export function spinnerFrame(now) {
|
|
8
|
+
const index = Math.floor(now / 250) % SPINNER_FRAMES.length;
|
|
9
|
+
return SPINNER_FRAMES[index] ?? SPINNER_FRAMES[0] ?? "";
|
|
10
|
+
}
|
|
11
|
+
export function statusColor(status) {
|
|
12
|
+
switch (status) {
|
|
13
|
+
case "pending":
|
|
14
|
+
return "dim";
|
|
15
|
+
case "queued":
|
|
16
|
+
return "dim";
|
|
17
|
+
case "starting":
|
|
18
|
+
case "running":
|
|
19
|
+
return "accent";
|
|
20
|
+
case "done":
|
|
21
|
+
return "success";
|
|
22
|
+
case "failed":
|
|
23
|
+
return "error";
|
|
24
|
+
case "cancelled":
|
|
25
|
+
return "warning";
|
|
26
|
+
case "skipped":
|
|
27
|
+
return "muted";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function statusGlyphChar(status, options) {
|
|
31
|
+
switch (status) {
|
|
32
|
+
case "pending":
|
|
33
|
+
return "·";
|
|
34
|
+
case "queued":
|
|
35
|
+
return "◌";
|
|
36
|
+
case "starting":
|
|
37
|
+
case "running":
|
|
38
|
+
return options.animate ? spinnerFrame(options.now) : "●";
|
|
39
|
+
case "done":
|
|
40
|
+
return "✓";
|
|
41
|
+
case "failed":
|
|
42
|
+
return "✗";
|
|
43
|
+
case "cancelled":
|
|
44
|
+
return "⊘";
|
|
45
|
+
case "skipped":
|
|
46
|
+
return "–";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function statusGlyph(status, theme, options) {
|
|
50
|
+
return theme.fg(statusColor(status), statusGlyphChar(status, options));
|
|
51
|
+
}
|
|
52
|
+
function pad2(n) {
|
|
53
|
+
return n < 10 ? `0${n}` : String(n);
|
|
54
|
+
}
|
|
55
|
+
/** `0:07`, `4:51`, `1:02:03`. */
|
|
56
|
+
export function formatDuration(ms) {
|
|
57
|
+
const safeMs = Number.isFinite(ms) ? ms : 0;
|
|
58
|
+
const totalSeconds = Math.max(0, Math.floor(safeMs / 1000));
|
|
59
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
60
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
61
|
+
const seconds = totalSeconds % 60;
|
|
62
|
+
if (hours > 0)
|
|
63
|
+
return `${hours}:${pad2(minutes)}:${pad2(seconds)}`;
|
|
64
|
+
return `${minutes}:${pad2(seconds)}`;
|
|
65
|
+
}
|
|
66
|
+
/** `950`, `12.3k`, `1.2M`. Rounds first, then picks the unit, so values never round up into the next
|
|
67
|
+
* unit's territory (e.g. 999_600 is `1.0M`, not `1000k`). */
|
|
68
|
+
export function formatTokens(n) {
|
|
69
|
+
if (!Number.isFinite(n))
|
|
70
|
+
return "0";
|
|
71
|
+
const sign = n < 0 ? "-" : "";
|
|
72
|
+
const abs = Math.abs(n);
|
|
73
|
+
if (abs < 1000)
|
|
74
|
+
return `${sign}${Math.round(abs)}`;
|
|
75
|
+
if (abs < 1_000_000) {
|
|
76
|
+
const oneDecimalK = Math.round(abs / 100) / 10;
|
|
77
|
+
if (oneDecimalK < 100)
|
|
78
|
+
return `${sign}${oneDecimalK.toFixed(1)}k`;
|
|
79
|
+
const wholeK = Math.round(abs / 1000);
|
|
80
|
+
if (wholeK < 1000)
|
|
81
|
+
return `${sign}${wholeK}k`;
|
|
82
|
+
}
|
|
83
|
+
const oneDecimalM = Math.round(abs / 100_000) / 10;
|
|
84
|
+
if (oneDecimalM < 10)
|
|
85
|
+
return `${sign}${oneDecimalM.toFixed(1)}M`;
|
|
86
|
+
return `${sign}${Math.round(abs / 1_000_000)}M`;
|
|
87
|
+
}
|
|
88
|
+
/** `""` for 0, `<$0.01`, `$0.08`, `$12.40`. */
|
|
89
|
+
export function formatCost(usd) {
|
|
90
|
+
const safeUsd = Number.isFinite(usd) ? usd : 0;
|
|
91
|
+
if (safeUsd === 0)
|
|
92
|
+
return "";
|
|
93
|
+
if (safeUsd < 0.01)
|
|
94
|
+
return "<$0.01";
|
|
95
|
+
return `$${safeUsd.toFixed(2)}`;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Collapsed: `id thinking`. Expanded (`withProvider`): `provider/id thinking (source)`, source shown
|
|
99
|
+
* only for `inherited` and `child-default`. Before confirmation (no provider/modelId), falls back to
|
|
100
|
+
* `modelText`, the requested pattern or `"default model"` for an unconfirmed child-default model.
|
|
101
|
+
*/
|
|
102
|
+
export function formatModelLabel(row, options) {
|
|
103
|
+
const idPart = row.provider && row.modelId
|
|
104
|
+
? options.withProvider
|
|
105
|
+
? `${row.provider}/${row.modelId}`
|
|
106
|
+
: row.modelId
|
|
107
|
+
: (row.modelText ?? row.modelId ?? row.provider ?? "");
|
|
108
|
+
const parts = [idPart];
|
|
109
|
+
if (row.thinking)
|
|
110
|
+
parts.push(row.thinking);
|
|
111
|
+
const label = parts.filter((part) => part.length > 0).join(" ");
|
|
112
|
+
const withSource = options.withSource ?? false;
|
|
113
|
+
const sourceSuffix = withSource && (row.modelSource === "inherited" || row.modelSource === "child-default")
|
|
114
|
+
? `(${row.modelSource})`
|
|
115
|
+
: "";
|
|
116
|
+
return [label, sourceSuffix].filter((part) => part.length > 0).join(" ");
|
|
117
|
+
}
|
|
118
|
+
/** Collapses whitespace runs (including newlines) to single spaces and trims. */
|
|
119
|
+
export function oneLine(text) {
|
|
120
|
+
return text.replace(/\s+/g, " ").trim();
|
|
121
|
+
}
|
|
122
|
+
/** `truncateToWidth(text, width, "…")`: never exceeds `width`, never pads. */
|
|
123
|
+
export function fitLine(text, width) {
|
|
124
|
+
return truncateToWidth(text, width, "…");
|
|
125
|
+
}
|
|
126
|
+
/** Truncates (no ellipsis) and pads with spaces to exactly `width` visible columns. */
|
|
127
|
+
export function padToWidth(text, width) {
|
|
128
|
+
if (width <= 0)
|
|
129
|
+
return "";
|
|
130
|
+
return truncateToWidth(text, width, "", true);
|
|
131
|
+
}
|
|
132
|
+
function alignToWidth(text, width, align) {
|
|
133
|
+
if (width <= 0)
|
|
134
|
+
return "";
|
|
135
|
+
const truncated = truncateToWidth(text, width, "", false);
|
|
136
|
+
const padding = " ".repeat(Math.max(0, width - visibleWidth(truncated)));
|
|
137
|
+
return align === "right" ? padding + truncated : truncated + padding;
|
|
138
|
+
}
|
|
139
|
+
/** Lays out `cells` within `width` columns separated by `gap` spaces (default 1). Fixed-width cells are
|
|
140
|
+
* truncated/padded to their width; `"flex"` cells share the remaining space evenly. The result's visible
|
|
141
|
+
* width never exceeds `width`, even with CJK or emoji content. */
|
|
142
|
+
export function columns(cells, width, gap = 1) {
|
|
143
|
+
if (cells.length === 0 || width <= 0)
|
|
144
|
+
return "";
|
|
145
|
+
const gapStr = " ".repeat(Math.max(0, gap));
|
|
146
|
+
const gapTotal = gapStr.length * Math.max(0, cells.length - 1);
|
|
147
|
+
const fixedTotal = cells.reduce((sum, cell) => sum + (typeof cell.width === "number" ? Math.max(0, cell.width) : 0), 0);
|
|
148
|
+
const flexCells = cells.filter((cell) => cell.width === "flex");
|
|
149
|
+
const remaining = Math.max(0, width - gapTotal - fixedTotal);
|
|
150
|
+
const flexWidths = [];
|
|
151
|
+
if (flexCells.length > 0) {
|
|
152
|
+
const base = Math.floor(remaining / flexCells.length);
|
|
153
|
+
let used = 0;
|
|
154
|
+
for (let i = 0; i < flexCells.length; i++) {
|
|
155
|
+
const isLast = i === flexCells.length - 1;
|
|
156
|
+
const flexWidth = isLast ? remaining - used : base;
|
|
157
|
+
flexWidths.push(Math.max(0, flexWidth));
|
|
158
|
+
used += flexWidth;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let flexIndex = 0;
|
|
162
|
+
const parts = cells.map((cell) => {
|
|
163
|
+
const cellWidth = cell.width === "flex" ? (flexWidths[flexIndex++] ?? 0) : Math.max(0, cell.width);
|
|
164
|
+
return alignToWidth(cell.text, cellWidth, cell.align ?? "left");
|
|
165
|
+
});
|
|
166
|
+
const joined = parts.join(gapStr);
|
|
167
|
+
return truncateToWidth(joined, width, "", false);
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../../src/core/polyphase/render/format.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI3D,MAAM,CAAC,MAAM,cAAc,GAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEtE,MAAM,UAAU,YAAY,CAAC,GAAW;IACvC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC;IAC5D,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAmB;IAC9C,QAAQ,MAAM,EAAE,CAAC;QAChB,KAAK,SAAS;YACb,OAAO,KAAK,CAAC;QACd,KAAK,QAAQ;YACZ,OAAO,KAAK,CAAC;QACd,KAAK,UAAU,CAAC;QAChB,KAAK,SAAS;YACb,OAAO,QAAQ,CAAC;QACjB,KAAK,MAAM;YACV,OAAO,SAAS,CAAC;QAClB,KAAK,QAAQ;YACZ,OAAO,OAAO,CAAC;QAChB,KAAK,WAAW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renderer (render/run-block.ts,\n * P9) and the inspector (ui/inspector.ts, P10). Every exported formatter is pure: no timers, no I/O.\n */\n\nimport type { ThinkingLevel } from \"@draht/agent-core\";\nimport { truncateToWidth, visibleWidth } from \"@draht/tui\";\nimport type { Theme, ThemeColor } from \"../../../modes/interactive/theme/theme.ts\";\nimport type { AgentStatus, ModelSource } from \"../types.ts\";\n\nexport const SPINNER_FRAMES: readonly string[] = [\"◐\", \"◓\", \"◑\", \"◒\"];\n\nexport function spinnerFrame(now: number): string {\n\tconst index = Math.floor(now / 250) % SPINNER_FRAMES.length;\n\treturn SPINNER_FRAMES[index] ?? SPINNER_FRAMES[0] ?? \"\";\n}\n\nexport function statusColor(status: AgentStatus): ThemeColor {\n\tswitch (status) {\n\t\tcase \"pending\":\n\t\t\treturn \"dim\";\n\t\tcase \"queued\":\n\t\t\treturn \"dim\";\n\t\tcase \"starting\":\n\t\tcase \"running\":\n\t\t\treturn \"accent\";\n\t\tcase \"done\":\n\t\t\treturn \"success\";\n\t\tcase \"failed\":\n\t\t\treturn \"error\";\n\t\tcase \"cancelled\":\n\t\t\treturn \"warning\";\n\t\tcase \"skipped\":\n\t\t\treturn \"muted\";\n\t}\n}\n\nfunction statusGlyphChar(status: AgentStatus, options: { now: number; animate: boolean }): string {\n\tswitch (status) {\n\t\tcase \"pending\":\n\t\t\treturn \"·\";\n\t\tcase \"queued\":\n\t\t\treturn \"◌\";\n\t\tcase \"starting\":\n\t\tcase \"running\":\n\t\t\treturn options.animate ? spinnerFrame(options.now) : \"●\";\n\t\tcase \"done\":\n\t\t\treturn \"✓\";\n\t\tcase \"failed\":\n\t\t\treturn \"✗\";\n\t\tcase \"cancelled\":\n\t\t\treturn \"⊘\";\n\t\tcase \"skipped\":\n\t\t\treturn \"–\";\n\t}\n}\n\nexport function statusGlyph(status: AgentStatus, theme: Theme, options: { now: number; animate: boolean }): string {\n\treturn theme.fg(statusColor(status), statusGlyphChar(status, options));\n}\n\nfunction pad2(n: number): string {\n\treturn n < 10 ? `0${n}` : String(n);\n}\n\n/** `0:07`, `4:51`, `1:02:03`. */\nexport function formatDuration(ms: number): string {\n\tconst safeMs = Number.isFinite(ms) ? ms : 0;\n\tconst totalSeconds = Math.max(0, Math.floor(safeMs / 1000));\n\tconst hours = Math.floor(totalSeconds / 3600);\n\tconst minutes = Math.floor((totalSeconds % 3600) / 60);\n\tconst seconds = totalSeconds % 60;\n\tif (hours > 0) return `${hours}:${pad2(minutes)}:${pad2(seconds)}`;\n\treturn `${minutes}:${pad2(seconds)}`;\n}\n\n/** `950`, `12.3k`, `1.2M`. Rounds first, then picks the unit, so values never round up into the next\n * unit's territory (e.g. 999_600 is `1.0M`, not `1000k`). */\nexport function formatTokens(n: number): string {\n\tif (!Number.isFinite(n)) return \"0\";\n\tconst sign = n < 0 ? \"-\" : \"\";\n\tconst abs = Math.abs(n);\n\tif (abs < 1000) return `${sign}${Math.round(abs)}`;\n\tif (abs < 1_000_000) {\n\t\tconst oneDecimalK = Math.round(abs / 100) / 10;\n\t\tif (oneDecimalK < 100) return `${sign}${oneDecimalK.toFixed(1)}k`;\n\t\tconst wholeK = Math.round(abs / 1000);\n\t\tif (wholeK < 1000) return `${sign}${wholeK}k`;\n\t}\n\tconst oneDecimalM = Math.round(abs / 100_000) / 10;\n\tif (oneDecimalM < 10) return `${sign}${oneDecimalM.toFixed(1)}M`;\n\treturn `${sign}${Math.round(abs / 1_000_000)}M`;\n}\n\n/** `\"\"` for 0, `<$0.01`, `$0.08`, `$12.40`. */\nexport function formatCost(usd: number): string {\n\tconst safeUsd = Number.isFinite(usd) ? usd : 0;\n\tif (safeUsd === 0) return \"\";\n\tif (safeUsd < 0.01) return \"<$0.01\";\n\treturn `$${safeUsd.toFixed(2)}`;\n}\n\n/**\n * Collapsed: `id thinking`. Expanded (`withProvider`): `provider/id thinking (source)`, source shown\n * only for `inherited` and `child-default`. Before confirmation (no provider/modelId), falls back to\n * `modelText`, the requested pattern or `\"default model\"` for an unconfirmed child-default model.\n */\nexport function formatModelLabel(\n\trow: {\n\t\tprovider?: string;\n\t\tmodelId?: string;\n\t\tmodelText?: string;\n\t\tthinking?: ThinkingLevel;\n\t\tmodelSource?: ModelSource;\n\t},\n\toptions: { withProvider: boolean; withSource?: boolean },\n): string {\n\tconst idPart =\n\t\trow.provider && row.modelId\n\t\t\t? options.withProvider\n\t\t\t\t? `${row.provider}/${row.modelId}`\n\t\t\t\t: row.modelId\n\t\t\t: (row.modelText ?? row.modelId ?? row.provider ?? \"\");\n\tconst parts = [idPart];\n\tif (row.thinking) parts.push(row.thinking);\n\tconst label = parts.filter((part) => part.length > 0).join(\" \");\n\tconst withSource = options.withSource ?? false;\n\tconst sourceSuffix =\n\t\twithSource && (row.modelSource === \"inherited\" || row.modelSource === \"child-default\")\n\t\t\t? `(${row.modelSource})`\n\t\t\t: \"\";\n\treturn [label, sourceSuffix].filter((part) => part.length > 0).join(\" \");\n}\n\n/** Collapses whitespace runs (including newlines) to single spaces and trims. */\nexport function oneLine(text: string): string {\n\treturn text.replace(/\\s+/g, \" \").trim();\n}\n\n/** `truncateToWidth(text, width, \"…\")`: never exceeds `width`, never pads. */\nexport function fitLine(text: string, width: number): string {\n\treturn truncateToWidth(text, width, \"…\");\n}\n\n/** Truncates (no ellipsis) and pads with spaces to exactly `width` visible columns. */\nexport function padToWidth(text: string, width: number): string {\n\tif (width <= 0) return \"\";\n\treturn truncateToWidth(text, width, \"\", true);\n}\n\nfunction alignToWidth(text: string, width: number, align: \"left\" | \"right\"): string {\n\tif (width <= 0) return \"\";\n\tconst truncated = truncateToWidth(text, width, \"\", false);\n\tconst padding = \" \".repeat(Math.max(0, width - visibleWidth(truncated)));\n\treturn align === \"right\" ? padding + truncated : truncated + padding;\n}\n\nexport interface ColumnCell {\n\ttext: string;\n\twidth: number | \"flex\";\n\talign?: \"left\" | \"right\";\n}\n\n/** Lays out `cells` within `width` columns separated by `gap` spaces (default 1). Fixed-width cells are\n * truncated/padded to their width; `\"flex\"` cells share the remaining space evenly. The result's visible\n * width never exceeds `width`, even with CJK or emoji content. */\nexport function columns(cells: readonly ColumnCell[], width: number, gap = 1): string {\n\tif (cells.length === 0 || width <= 0) return \"\";\n\tconst gapStr = \" \".repeat(Math.max(0, gap));\n\tconst gapTotal = gapStr.length * Math.max(0, cells.length - 1);\n\tconst fixedTotal = cells.reduce(\n\t\t(sum, cell) => sum + (typeof cell.width === \"number\" ? Math.max(0, cell.width) : 0),\n\t\t0,\n\t);\n\tconst flexCells = cells.filter((cell) => cell.width === \"flex\");\n\tconst remaining = Math.max(0, width - gapTotal - fixedTotal);\n\tconst flexWidths: number[] = [];\n\tif (flexCells.length > 0) {\n\t\tconst base = Math.floor(remaining / flexCells.length);\n\t\tlet used = 0;\n\t\tfor (let i = 0; i < flexCells.length; i++) {\n\t\t\tconst isLast = i === flexCells.length - 1;\n\t\t\tconst flexWidth = isLast ? remaining - used : base;\n\t\t\tflexWidths.push(Math.max(0, flexWidth));\n\t\t\tused += flexWidth;\n\t\t}\n\t}\n\tlet flexIndex = 0;\n\tconst parts = cells.map((cell) => {\n\t\tconst cellWidth = cell.width === \"flex\" ? (flexWidths[flexIndex++] ?? 0) : Math.max(0, cell.width);\n\t\treturn alignToWidth(cell.text, cellWidth, cell.align ?? \"left\");\n\t});\n\tconst joined = parts.join(gapStr);\n\treturn truncateToWidth(joined, width, \"\", false);\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-row renderers for `subagent` and `workflow` (§11.5): lazy call previews, result blocks
|
|
3
|
+
* reused from the live store or persisted details, the legacy fallback for old sessions, and the
|
|
4
|
+
* `polyphase-workflow` custom-message renderer. No timers anywhere (§11.2.5): rows re-render on
|
|
5
|
+
* emitter updates (at least every second via the heartbeat), never from a renderer-owned clock.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentToolResult } from "@draht/agent-core";
|
|
8
|
+
import { type Component } from "@draht/tui";
|
|
9
|
+
import type { Theme } from "../../../modes/interactive/theme/theme.ts";
|
|
10
|
+
import type { MessageRenderer, ToolRenderContext, ToolRenderResultOptions } from "../../extensions/types.ts";
|
|
11
|
+
import type { LimiterStats } from "../limiter.ts";
|
|
12
|
+
import type { PolyphaseStore } from "../store.ts";
|
|
13
|
+
import type { PolyphaseDetails } from "../types.ts";
|
|
14
|
+
export interface PolyphaseRenderDeps {
|
|
15
|
+
getStore(): PolyphaseStore | undefined;
|
|
16
|
+
viewportRows(): number;
|
|
17
|
+
now?(): number;
|
|
18
|
+
/** Optional: when present, `(a/c slots busy)` can appear on a live tool row's summary line
|
|
19
|
+
* (§11.3). Left undefined, the suffix never shows, which matches today's wiring. */
|
|
20
|
+
limiterStats?(): LimiterStats | undefined;
|
|
21
|
+
}
|
|
22
|
+
export interface SubagentCallArgs {
|
|
23
|
+
agent?: string;
|
|
24
|
+
task?: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
model?: string;
|
|
27
|
+
thinking?: string;
|
|
28
|
+
tasks?: Array<{
|
|
29
|
+
agent?: string;
|
|
30
|
+
task?: string;
|
|
31
|
+
label?: string;
|
|
32
|
+
model?: string;
|
|
33
|
+
}>;
|
|
34
|
+
chain?: Array<{
|
|
35
|
+
agent?: string;
|
|
36
|
+
task?: string;
|
|
37
|
+
label?: string;
|
|
38
|
+
model?: string;
|
|
39
|
+
}>;
|
|
40
|
+
worktree?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface WorkflowCallArgs {
|
|
43
|
+
script?: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
args?: string;
|
|
46
|
+
budgetTokens?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface PolyphaseRowState {
|
|
49
|
+
hasResult?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export declare function renderLegacySubagentResult(result: AgentToolResult<unknown>, options: ToolRenderResultOptions, theme: Theme): Component;
|
|
52
|
+
export declare function createSubagentRenderers(deps: PolyphaseRenderDeps): {
|
|
53
|
+
renderCall(args: SubagentCallArgs, theme: Theme, context: ToolRenderContext<PolyphaseRowState, SubagentCallArgs>): Component;
|
|
54
|
+
renderResult(result: AgentToolResult<unknown>, options: ToolRenderResultOptions, theme: Theme, context: ToolRenderContext<PolyphaseRowState, SubagentCallArgs>): Component;
|
|
55
|
+
};
|
|
56
|
+
export declare function createWorkflowRenderers(deps: PolyphaseRenderDeps): {
|
|
57
|
+
renderCall(args: WorkflowCallArgs, theme: Theme, context: ToolRenderContext<PolyphaseRowState, WorkflowCallArgs>): Component;
|
|
58
|
+
renderResult(result: AgentToolResult<unknown>, options: ToolRenderResultOptions, theme: Theme, context: ToolRenderContext<PolyphaseRowState, WorkflowCallArgs>): Component;
|
|
59
|
+
};
|
|
60
|
+
/** Renders `polyphase-workflow` custom messages (command-run results) as a static block built from
|
|
61
|
+
* `message.details`, prefixed with `▶ /<name> <args>` (§11.5). */
|
|
62
|
+
export declare function createPolyphaseMessageRenderer(): MessageRenderer<PolyphaseDetails>;
|
|
63
|
+
//# sourceMappingURL=renderers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../../../src/core/polyphase/render/renderers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,KAAK,SAAS,EAAQ,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAE7G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAgB,MAAM,aAAa,CAAC;AAMlE,MAAM,WAAW,mBAAmB;IACnC,QAAQ,IAAI,cAAc,GAAG,SAAS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