@dirgha/code 1.2.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.
- package/LICENSE +101 -0
- package/README.md +674 -0
- package/dist/dirgha.mjs +2185 -0
- package/dist_v2/acp/index.d.ts +1 -0
- package/dist_v2/acp/index.js +2 -0
- package/dist_v2/acp/server.d.ts +31 -0
- package/dist_v2/acp/server.js +137 -0
- package/dist_v2/cli/auth-cmd.d.ts +10 -0
- package/dist_v2/cli/auth-cmd.js +69 -0
- package/dist_v2/cli/config.d.ts +46 -0
- package/dist_v2/cli/config.js +70 -0
- package/dist_v2/cli/flags.d.ts +10 -0
- package/dist_v2/cli/flags.js +49 -0
- package/dist_v2/cli/flows/full-cycle.d.ts +30 -0
- package/dist_v2/cli/flows/full-cycle.js +39 -0
- package/dist_v2/cli/flows/index.d.ts +2 -0
- package/dist_v2/cli/flows/index.js +3 -0
- package/dist_v2/cli/flows/tarball.d.ts +10 -0
- package/dist_v2/cli/flows/tarball.js +47 -0
- package/dist_v2/cli/index.d.ts +4 -0
- package/dist_v2/cli/index.js +5 -0
- package/dist_v2/cli/interactive.d.ts +21 -0
- package/dist_v2/cli/interactive.js +207 -0
- package/dist_v2/cli/main.d.ts +10 -0
- package/dist_v2/cli/main.js +173 -0
- package/dist_v2/cli/models-cmd.d.ts +6 -0
- package/dist_v2/cli/models-cmd.js +50 -0
- package/dist_v2/cli/setup.d.ts +13 -0
- package/dist_v2/cli/setup.js +128 -0
- package/dist_v2/cli/slash/account.d.ts +10 -0
- package/dist_v2/cli/slash/account.js +59 -0
- package/dist_v2/cli/slash/clear.d.ts +8 -0
- package/dist_v2/cli/slash/clear.js +15 -0
- package/dist_v2/cli/slash/compact.d.ts +7 -0
- package/dist_v2/cli/slash/compact.js +13 -0
- package/dist_v2/cli/slash/config.d.ts +8 -0
- package/dist_v2/cli/slash/config.js +49 -0
- package/dist_v2/cli/slash/exit.d.ts +7 -0
- package/dist_v2/cli/slash/exit.js +16 -0
- package/dist_v2/cli/slash/fleet.d.ts +7 -0
- package/dist_v2/cli/slash/fleet.js +22 -0
- package/dist_v2/cli/slash/help.d.ts +9 -0
- package/dist_v2/cli/slash/help.js +31 -0
- package/dist_v2/cli/slash/history.d.ts +7 -0
- package/dist_v2/cli/slash/history.js +42 -0
- package/dist_v2/cli/slash/index.d.ts +30 -0
- package/dist_v2/cli/slash/index.js +52 -0
- package/dist_v2/cli/slash/init.d.ts +8 -0
- package/dist_v2/cli/slash/init.js +57 -0
- package/dist_v2/cli/slash/keys.d.ts +8 -0
- package/dist_v2/cli/slash/keys.js +101 -0
- package/dist_v2/cli/slash/login.d.ts +10 -0
- package/dist_v2/cli/slash/login.js +47 -0
- package/dist_v2/cli/slash/memory.d.ts +8 -0
- package/dist_v2/cli/slash/memory.js +101 -0
- package/dist_v2/cli/slash/mode.d.ts +8 -0
- package/dist_v2/cli/slash/mode.js +30 -0
- package/dist_v2/cli/slash/models.d.ts +8 -0
- package/dist_v2/cli/slash/models.js +73 -0
- package/dist_v2/cli/slash/resume.d.ts +8 -0
- package/dist_v2/cli/slash/resume.js +24 -0
- package/dist_v2/cli/slash/session.d.ts +8 -0
- package/dist_v2/cli/slash/session.js +74 -0
- package/dist_v2/cli/slash/setup.d.ts +8 -0
- package/dist_v2/cli/slash/setup.js +50 -0
- package/dist_v2/cli/slash/status.d.ts +7 -0
- package/dist_v2/cli/slash/status.js +37 -0
- package/dist_v2/cli/slash/theme.d.ts +9 -0
- package/dist_v2/cli/slash/theme.js +53 -0
- package/dist_v2/cli/slash/types.d.ts +14 -0
- package/dist_v2/cli/slash/types.js +9 -0
- package/dist_v2/cli/slash/upgrade.d.ts +9 -0
- package/dist_v2/cli/slash/upgrade.js +66 -0
- package/dist_v2/cli/slash.d.ts +72 -0
- package/dist_v2/cli/slash.js +77 -0
- package/dist_v2/cli/subcommands/ask.d.ts +17 -0
- package/dist_v2/cli/subcommands/ask.js +76 -0
- package/dist_v2/cli/subcommands/audit.d.ts +15 -0
- package/dist_v2/cli/subcommands/audit.js +128 -0
- package/dist_v2/cli/subcommands/chat.d.ts +13 -0
- package/dist_v2/cli/subcommands/chat.js +72 -0
- package/dist_v2/cli/subcommands/compact.d.ts +14 -0
- package/dist_v2/cli/subcommands/compact.js +114 -0
- package/dist_v2/cli/subcommands/doctor.d.ts +11 -0
- package/dist_v2/cli/subcommands/doctor.js +103 -0
- package/dist_v2/cli/subcommands/export-session.d.ts +10 -0
- package/dist_v2/cli/subcommands/export-session.js +60 -0
- package/dist_v2/cli/subcommands/import-session.d.ts +11 -0
- package/dist_v2/cli/subcommands/import-session.js +77 -0
- package/dist_v2/cli/subcommands/index.d.ts +40 -0
- package/dist_v2/cli/subcommands/index.js +38 -0
- package/dist_v2/cli/subcommands/init.d.ts +10 -0
- package/dist_v2/cli/subcommands/init.js +74 -0
- package/dist_v2/cli/subcommands/keys.d.ts +12 -0
- package/dist_v2/cli/subcommands/keys.js +136 -0
- package/dist_v2/cli/subcommands/login.d.ts +10 -0
- package/dist_v2/cli/subcommands/login.js +60 -0
- package/dist_v2/cli/subcommands/logout.d.ts +10 -0
- package/dist_v2/cli/subcommands/logout.js +21 -0
- package/dist_v2/cli/subcommands/models.d.ts +14 -0
- package/dist_v2/cli/subcommands/models.js +144 -0
- package/dist_v2/cli/subcommands/setup.d.ts +11 -0
- package/dist_v2/cli/subcommands/setup.js +107 -0
- package/dist_v2/cli/subcommands/stats.d.ts +13 -0
- package/dist_v2/cli/subcommands/stats.js +148 -0
- package/dist_v2/cli/subcommands/status.d.ts +14 -0
- package/dist_v2/cli/subcommands/status.js +91 -0
- package/dist_v2/cli/submit-paper.d.ts +15 -0
- package/dist_v2/cli/submit-paper.js +68 -0
- package/dist_v2/context/_fts.d.ts +62 -0
- package/dist_v2/context/_fts.js +195 -0
- package/dist_v2/context/branch.d.ts +18 -0
- package/dist_v2/context/branch.js +66 -0
- package/dist_v2/context/compaction.d.ts +26 -0
- package/dist_v2/context/compaction.js +120 -0
- package/dist_v2/context/index.d.ts +5 -0
- package/dist_v2/context/index.js +6 -0
- package/dist_v2/context/knowledge.d.ts +38 -0
- package/dist_v2/context/knowledge.js +146 -0
- package/dist_v2/context/memory.d.ts +80 -0
- package/dist_v2/context/memory.js +276 -0
- package/dist_v2/context/mode.d.ts +25 -0
- package/dist_v2/context/mode.js +81 -0
- package/dist_v2/context/session.d.ts +56 -0
- package/dist_v2/context/session.js +108 -0
- package/dist_v2/daemon/index.d.ts +2 -0
- package/dist_v2/daemon/index.js +3 -0
- package/dist_v2/daemon/protocol.d.ts +73 -0
- package/dist_v2/daemon/protocol.js +6 -0
- package/dist_v2/daemon/server.d.ts +35 -0
- package/dist_v2/daemon/server.js +191 -0
- package/dist_v2/eval/index.d.ts +5 -0
- package/dist_v2/eval/index.js +6 -0
- package/dist_v2/eval/regression.d.ts +14 -0
- package/dist_v2/eval/regression.js +106 -0
- package/dist_v2/eval/reporter.d.ts +7 -0
- package/dist_v2/eval/reporter.js +34 -0
- package/dist_v2/eval/swe-bench.d.ts +18 -0
- package/dist_v2/eval/swe-bench.js +23 -0
- package/dist_v2/eval/terminal-bench.d.ts +13 -0
- package/dist_v2/eval/terminal-bench.js +19 -0
- package/dist_v2/eval/types.d.ts +36 -0
- package/dist_v2/eval/types.js +5 -0
- package/dist_v2/fleet/apply-back.d.ts +27 -0
- package/dist_v2/fleet/apply-back.js +191 -0
- package/dist_v2/fleet/cli-command.d.ts +61 -0
- package/dist_v2/fleet/cli-command.js +329 -0
- package/dist_v2/fleet/index.d.ts +21 -0
- package/dist_v2/fleet/index.js +21 -0
- package/dist_v2/fleet/runner.d.ts +28 -0
- package/dist_v2/fleet/runner.js +347 -0
- package/dist_v2/fleet/tripleshot.d.ts +21 -0
- package/dist_v2/fleet/tripleshot.js +222 -0
- package/dist_v2/fleet/types.d.ts +193 -0
- package/dist_v2/fleet/types.js +24 -0
- package/dist_v2/fleet/worktree.d.ts +51 -0
- package/dist_v2/fleet/worktree.js +176 -0
- package/dist_v2/hooks/index.d.ts +1 -0
- package/dist_v2/hooks/index.js +2 -0
- package/dist_v2/hooks/registry.d.ts +21 -0
- package/dist_v2/hooks/registry.js +40 -0
- package/dist_v2/index.d.ts +12 -0
- package/dist_v2/index.js +11 -0
- package/dist_v2/integrations/arniko-client.d.ts +42 -0
- package/dist_v2/integrations/arniko-client.js +86 -0
- package/dist_v2/integrations/auth.d.ts +45 -0
- package/dist_v2/integrations/auth.js +54 -0
- package/dist_v2/integrations/billing.d.ts +71 -0
- package/dist_v2/integrations/billing.js +107 -0
- package/dist_v2/integrations/bucky-client.d.ts +105 -0
- package/dist_v2/integrations/bucky-client.js +76 -0
- package/dist_v2/integrations/deploy-client.d.ts +60 -0
- package/dist_v2/integrations/deploy-client.js +87 -0
- package/dist_v2/integrations/device-auth.d.ts +48 -0
- package/dist_v2/integrations/device-auth.js +192 -0
- package/dist_v2/integrations/entitlements.d.ts +34 -0
- package/dist_v2/integrations/entitlements.js +43 -0
- package/dist_v2/integrations/http.d.ts +22 -0
- package/dist_v2/integrations/http.js +114 -0
- package/dist_v2/integrations/index.d.ts +8 -0
- package/dist_v2/integrations/index.js +15 -0
- package/dist_v2/intelligence/cost.d.ts +28 -0
- package/dist_v2/intelligence/cost.js +58 -0
- package/dist_v2/intelligence/error-classifier.d.ts +8 -0
- package/dist_v2/intelligence/error-classifier.js +71 -0
- package/dist_v2/intelligence/index.d.ts +5 -0
- package/dist_v2/intelligence/index.js +6 -0
- package/dist_v2/intelligence/prices.d.ts +13 -0
- package/dist_v2/intelligence/prices.js +26 -0
- package/dist_v2/intelligence/smart-router.d.ts +21 -0
- package/dist_v2/intelligence/smart-router.js +59 -0
- package/dist_v2/intelligence/telemetry.d.ts +22 -0
- package/dist_v2/intelligence/telemetry.js +31 -0
- package/dist_v2/kernel/agent-loop.d.ts +32 -0
- package/dist_v2/kernel/agent-loop.js +151 -0
- package/dist_v2/kernel/event-stream.d.ts +18 -0
- package/dist_v2/kernel/event-stream.js +102 -0
- package/dist_v2/kernel/index.d.ts +4 -0
- package/dist_v2/kernel/index.js +5 -0
- package/dist_v2/kernel/message.d.ts +29 -0
- package/dist_v2/kernel/message.js +118 -0
- package/dist_v2/kernel/types.d.ts +206 -0
- package/dist_v2/kernel/types.js +9 -0
- package/dist_v2/mcp/client.d.ts +44 -0
- package/dist_v2/mcp/client.js +63 -0
- package/dist_v2/mcp/index.d.ts +3 -0
- package/dist_v2/mcp/index.js +4 -0
- package/dist_v2/mcp/tool-bridge.d.ts +11 -0
- package/dist_v2/mcp/tool-bridge.js +33 -0
- package/dist_v2/mcp/transport.d.ts +29 -0
- package/dist_v2/mcp/transport.js +73 -0
- package/dist_v2/parity/index.d.ts +3 -0
- package/dist_v2/parity/index.js +4 -0
- package/dist_v2/parity/mock-openai-compat.d.ts +15 -0
- package/dist_v2/parity/mock-openai-compat.js +35 -0
- package/dist_v2/parity/runner.d.ts +21 -0
- package/dist_v2/parity/runner.js +76 -0
- package/dist_v2/parity/scenarios.d.ts +20 -0
- package/dist_v2/parity/scenarios.js +70 -0
- package/dist_v2/providers/anthropic.d.ts +21 -0
- package/dist_v2/providers/anthropic.js +191 -0
- package/dist_v2/providers/dispatch.d.ts +11 -0
- package/dist_v2/providers/dispatch.js +45 -0
- package/dist_v2/providers/fireworks.d.ts +18 -0
- package/dist_v2/providers/fireworks.js +44 -0
- package/dist_v2/providers/gemini.d.ts +19 -0
- package/dist_v2/providers/gemini.js +188 -0
- package/dist_v2/providers/http.d.ts +41 -0
- package/dist_v2/providers/http.js +188 -0
- package/dist_v2/providers/iface.d.ts +18 -0
- package/dist_v2/providers/iface.js +18 -0
- package/dist_v2/providers/index.d.ts +39 -0
- package/dist_v2/providers/index.js +51 -0
- package/dist_v2/providers/nvidia.d.ts +27 -0
- package/dist_v2/providers/nvidia.js +142 -0
- package/dist_v2/providers/ollama.d.ts +15 -0
- package/dist_v2/providers/ollama.js +37 -0
- package/dist_v2/providers/openai-compat.d.ts +29 -0
- package/dist_v2/providers/openai-compat.js +239 -0
- package/dist_v2/providers/openai.d.ts +20 -0
- package/dist_v2/providers/openai.js +107 -0
- package/dist_v2/providers/openrouter.d.ts +24 -0
- package/dist_v2/providers/openrouter.js +69 -0
- package/dist_v2/safety/approval-bus.d.ts +26 -0
- package/dist_v2/safety/approval-bus.js +48 -0
- package/dist_v2/safety/audit-log.d.ts +27 -0
- package/dist_v2/safety/audit-log.js +71 -0
- package/dist_v2/safety/index.d.ts +4 -0
- package/dist_v2/safety/index.js +5 -0
- package/dist_v2/safety/policy.d.ts +32 -0
- package/dist_v2/safety/policy.js +131 -0
- package/dist_v2/safety/sandbox/bwrap.d.ts +11 -0
- package/dist_v2/safety/sandbox/bwrap.js +52 -0
- package/dist_v2/safety/sandbox/iface.d.ts +29 -0
- package/dist_v2/safety/sandbox/iface.js +8 -0
- package/dist_v2/safety/sandbox/index.d.ts +7 -0
- package/dist_v2/safety/sandbox/index.js +8 -0
- package/dist_v2/safety/sandbox/landlock.d.ts +17 -0
- package/dist_v2/safety/sandbox/landlock.js +26 -0
- package/dist_v2/safety/sandbox/noop.d.ts +12 -0
- package/dist_v2/safety/sandbox/noop.js +52 -0
- package/dist_v2/safety/sandbox/seatbelt.d.ts +11 -0
- package/dist_v2/safety/sandbox/seatbelt.js +49 -0
- package/dist_v2/safety/sandbox/select.d.ts +6 -0
- package/dist_v2/safety/sandbox/select.js +42 -0
- package/dist_v2/safety/sandbox/windows.d.ts +13 -0
- package/dist_v2/safety/sandbox/windows.js +22 -0
- package/dist_v2/skills/index.d.ts +3 -0
- package/dist_v2/skills/index.js +4 -0
- package/dist_v2/skills/loader.d.ts +38 -0
- package/dist_v2/skills/loader.js +102 -0
- package/dist_v2/skills/matcher.d.ts +14 -0
- package/dist_v2/skills/matcher.js +72 -0
- package/dist_v2/skills/runtime.d.ts +13 -0
- package/dist_v2/skills/runtime.js +40 -0
- package/dist_v2/subagents/delegator.d.ts +36 -0
- package/dist_v2/subagents/delegator.js +82 -0
- package/dist_v2/subagents/index.d.ts +2 -0
- package/dist_v2/subagents/index.js +3 -0
- package/dist_v2/subagents/pool.d.ts +18 -0
- package/dist_v2/subagents/pool.js +31 -0
- package/dist_v2/tools/browser.d.ts +27 -0
- package/dist_v2/tools/browser.js +179 -0
- package/dist_v2/tools/checkpoint.d.ts +25 -0
- package/dist_v2/tools/checkpoint.js +222 -0
- package/dist_v2/tools/cron.d.ts +32 -0
- package/dist_v2/tools/cron.js +160 -0
- package/dist_v2/tools/diff.d.ts +18 -0
- package/dist_v2/tools/diff.js +117 -0
- package/dist_v2/tools/exec.d.ts +19 -0
- package/dist_v2/tools/exec.js +49 -0
- package/dist_v2/tools/fs-edit.d.ts +11 -0
- package/dist_v2/tools/fs-edit.js +81 -0
- package/dist_v2/tools/fs-ls.d.ts +7 -0
- package/dist_v2/tools/fs-ls.js +57 -0
- package/dist_v2/tools/fs-read.d.ts +7 -0
- package/dist_v2/tools/fs-read.js +60 -0
- package/dist_v2/tools/fs-write.d.ts +8 -0
- package/dist_v2/tools/fs-write.js +46 -0
- package/dist_v2/tools/git.d.ts +8 -0
- package/dist_v2/tools/git.js +57 -0
- package/dist_v2/tools/index.d.ts +25 -0
- package/dist_v2/tools/index.js +39 -0
- package/dist_v2/tools/multimodal.d.ts +41 -0
- package/dist_v2/tools/multimodal.js +381 -0
- package/dist_v2/tools/permission.d.ts +27 -0
- package/dist_v2/tools/permission.js +43 -0
- package/dist_v2/tools/registry.d.ts +44 -0
- package/dist_v2/tools/registry.js +62 -0
- package/dist_v2/tools/search-glob.d.ts +7 -0
- package/dist_v2/tools/search-glob.js +98 -0
- package/dist_v2/tools/search-grep.d.ts +7 -0
- package/dist_v2/tools/search-grep.js +109 -0
- package/dist_v2/tools/shell.d.ts +10 -0
- package/dist_v2/tools/shell.js +76 -0
- package/dist_v2/tools/task.d.ts +8 -0
- package/dist_v2/tools/task.js +37 -0
- package/dist_v2/tui/approval.d.ts +7 -0
- package/dist_v2/tui/approval.js +55 -0
- package/dist_v2/tui/index.d.ts +4 -0
- package/dist_v2/tui/index.js +5 -0
- package/dist_v2/tui/ink/App.d.ts +39 -0
- package/dist_v2/tui/ink/App.js +206 -0
- package/dist_v2/tui/ink/components/AtFileComplete.d.ts +25 -0
- package/dist_v2/tui/ink/components/AtFileComplete.js +158 -0
- package/dist_v2/tui/ink/components/HelpOverlay.d.ts +24 -0
- package/dist_v2/tui/ink/components/HelpOverlay.js +130 -0
- package/dist_v2/tui/ink/components/InputBox.d.ts +35 -0
- package/dist_v2/tui/ink/components/InputBox.js +153 -0
- package/dist_v2/tui/ink/components/Logo.d.ts +12 -0
- package/dist_v2/tui/ink/components/Logo.js +27 -0
- package/dist_v2/tui/ink/components/ModelPicker.d.ts +26 -0
- package/dist_v2/tui/ink/components/ModelPicker.js +80 -0
- package/dist_v2/tui/ink/components/PasteCollapse.d.ts +36 -0
- package/dist_v2/tui/ink/components/PasteCollapse.js +59 -0
- package/dist_v2/tui/ink/components/StatusBar.d.ts +18 -0
- package/dist_v2/tui/ink/components/StatusBar.js +41 -0
- package/dist_v2/tui/ink/components/StreamingText.d.ts +14 -0
- package/dist_v2/tui/ink/components/StreamingText.js +11 -0
- package/dist_v2/tui/ink/components/ThinkingBlock.d.ts +13 -0
- package/dist_v2/tui/ink/components/ThinkingBlock.js +13 -0
- package/dist_v2/tui/ink/components/ToolBox.d.ts +20 -0
- package/dist_v2/tui/ink/components/ToolBox.js +63 -0
- package/dist_v2/tui/ink/components/vim-bindings.d.ts +43 -0
- package/dist_v2/tui/ink/components/vim-bindings.js +135 -0
- package/dist_v2/tui/ink/index.d.ts +39 -0
- package/dist_v2/tui/ink/index.js +47 -0
- package/dist_v2/tui/ink/use-event-projection.d.ts +51 -0
- package/dist_v2/tui/ink/use-event-projection.js +126 -0
- package/dist_v2/tui/ink/use-overlays.d.ts +24 -0
- package/dist_v2/tui/ink/use-overlays.js +50 -0
- package/dist_v2/tui/renderer.d.ts +19 -0
- package/dist_v2/tui/renderer.js +64 -0
- package/dist_v2/tui/status-bar.d.ts +12 -0
- package/dist_v2/tui/status-bar.js +16 -0
- package/dist_v2/tui/theme.d.ts +27 -0
- package/dist_v2/tui/theme.js +56 -0
- package/dist_v2/utils/json-repair.d.ts +7 -0
- package/dist_v2/utils/json-repair.js +45 -0
- package/package.json +113 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical message and event types.
|
|
3
|
+
*
|
|
4
|
+
* Every layer above kernel consumes these types. Providers emit events,
|
|
5
|
+
* tools consume tool-use parts and emit tool-result parts, surfaces render
|
|
6
|
+
* events, the daemon streams events over RPC. One shape, everywhere.
|
|
7
|
+
*/
|
|
8
|
+
export type Role = 'system' | 'user' | 'assistant' | 'tool';
|
|
9
|
+
export interface TextPart {
|
|
10
|
+
type: 'text';
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ThinkingPart {
|
|
14
|
+
type: 'thinking';
|
|
15
|
+
text: string;
|
|
16
|
+
signature?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ToolUsePart {
|
|
19
|
+
type: 'tool_use';
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
input: unknown;
|
|
23
|
+
}
|
|
24
|
+
export interface ToolResultPart {
|
|
25
|
+
type: 'tool_result';
|
|
26
|
+
toolUseId: string;
|
|
27
|
+
content: string;
|
|
28
|
+
isError?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export type ContentPart = TextPart | ThinkingPart | ToolUsePart | ToolResultPart;
|
|
31
|
+
export interface Message {
|
|
32
|
+
role: Role;
|
|
33
|
+
content: string | ContentPart[];
|
|
34
|
+
name?: string;
|
|
35
|
+
}
|
|
36
|
+
export type StopReason = 'end_turn' | 'tool_use' | 'max_tokens' | 'stop_sequence' | 'error' | 'aborted';
|
|
37
|
+
export interface UsageTotal {
|
|
38
|
+
inputTokens: number;
|
|
39
|
+
outputTokens: number;
|
|
40
|
+
cachedTokens: number;
|
|
41
|
+
costUsd: number;
|
|
42
|
+
}
|
|
43
|
+
export type AgentEvent = {
|
|
44
|
+
type: 'agent_start';
|
|
45
|
+
sessionId: string;
|
|
46
|
+
model: string;
|
|
47
|
+
} | {
|
|
48
|
+
type: 'turn_start';
|
|
49
|
+
turnId: string;
|
|
50
|
+
turnIndex: number;
|
|
51
|
+
} | {
|
|
52
|
+
type: 'text_start';
|
|
53
|
+
} | {
|
|
54
|
+
type: 'text_delta';
|
|
55
|
+
delta: string;
|
|
56
|
+
} | {
|
|
57
|
+
type: 'text_end';
|
|
58
|
+
} | {
|
|
59
|
+
type: 'thinking_start';
|
|
60
|
+
} | {
|
|
61
|
+
type: 'thinking_delta';
|
|
62
|
+
delta: string;
|
|
63
|
+
} | {
|
|
64
|
+
type: 'thinking_end';
|
|
65
|
+
} | {
|
|
66
|
+
type: 'toolcall_start';
|
|
67
|
+
id: string;
|
|
68
|
+
name: string;
|
|
69
|
+
} | {
|
|
70
|
+
type: 'toolcall_delta';
|
|
71
|
+
id: string;
|
|
72
|
+
deltaJson: string;
|
|
73
|
+
} | {
|
|
74
|
+
type: 'toolcall_end';
|
|
75
|
+
id: string;
|
|
76
|
+
input: unknown;
|
|
77
|
+
} | {
|
|
78
|
+
type: 'tool_exec_start';
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
input: unknown;
|
|
82
|
+
} | {
|
|
83
|
+
type: 'tool_exec_progress';
|
|
84
|
+
id: string;
|
|
85
|
+
message: string;
|
|
86
|
+
} | {
|
|
87
|
+
type: 'tool_exec_end';
|
|
88
|
+
id: string;
|
|
89
|
+
output: string;
|
|
90
|
+
isError: boolean;
|
|
91
|
+
durationMs: number;
|
|
92
|
+
} | {
|
|
93
|
+
type: 'usage';
|
|
94
|
+
inputTokens: number;
|
|
95
|
+
outputTokens: number;
|
|
96
|
+
cachedTokens?: number;
|
|
97
|
+
} | {
|
|
98
|
+
type: 'turn_end';
|
|
99
|
+
turnId: string;
|
|
100
|
+
stopReason: StopReason;
|
|
101
|
+
} | {
|
|
102
|
+
type: 'agent_end';
|
|
103
|
+
sessionId: string;
|
|
104
|
+
stopReason: StopReason;
|
|
105
|
+
usage: UsageTotal;
|
|
106
|
+
} | {
|
|
107
|
+
type: 'error';
|
|
108
|
+
message: string;
|
|
109
|
+
reason?: string;
|
|
110
|
+
retryable?: boolean;
|
|
111
|
+
};
|
|
112
|
+
export interface ToolCall {
|
|
113
|
+
id: string;
|
|
114
|
+
name: string;
|
|
115
|
+
input: unknown;
|
|
116
|
+
}
|
|
117
|
+
export interface ToolResult<T = unknown> {
|
|
118
|
+
content: string;
|
|
119
|
+
data?: T;
|
|
120
|
+
isError: boolean;
|
|
121
|
+
metadata?: Record<string, unknown>;
|
|
122
|
+
durationMs?: number;
|
|
123
|
+
}
|
|
124
|
+
export interface ToolDefinition {
|
|
125
|
+
name: string;
|
|
126
|
+
description: string;
|
|
127
|
+
inputSchema: JsonSchema;
|
|
128
|
+
}
|
|
129
|
+
export interface StreamRequest {
|
|
130
|
+
model: string;
|
|
131
|
+
messages: Message[];
|
|
132
|
+
tools?: ToolDefinition[];
|
|
133
|
+
temperature?: number;
|
|
134
|
+
maxTokens?: number;
|
|
135
|
+
thinking?: 'off' | 'low' | 'medium' | 'high';
|
|
136
|
+
signal?: AbortSignal;
|
|
137
|
+
}
|
|
138
|
+
export interface ImageGenRequest {
|
|
139
|
+
prompt: string;
|
|
140
|
+
model?: string;
|
|
141
|
+
width?: number;
|
|
142
|
+
height?: number;
|
|
143
|
+
seed?: number;
|
|
144
|
+
steps?: number;
|
|
145
|
+
}
|
|
146
|
+
export interface ImageGenResult {
|
|
147
|
+
base64: string;
|
|
148
|
+
mimeType: string;
|
|
149
|
+
model: string;
|
|
150
|
+
}
|
|
151
|
+
export interface Provider {
|
|
152
|
+
readonly id: string;
|
|
153
|
+
supportsTools(modelId: string): boolean;
|
|
154
|
+
supportsThinking(modelId: string): boolean;
|
|
155
|
+
stream(req: StreamRequest): AsyncIterable<AgentEvent>;
|
|
156
|
+
generateImage?(req: ImageGenRequest, signal?: AbortSignal): Promise<ImageGenResult>;
|
|
157
|
+
}
|
|
158
|
+
export interface ToolExecutor {
|
|
159
|
+
execute(call: ToolCall, signal: AbortSignal): Promise<ToolResult>;
|
|
160
|
+
}
|
|
161
|
+
export interface ApprovalBus {
|
|
162
|
+
request(req: {
|
|
163
|
+
id: string;
|
|
164
|
+
tool: string;
|
|
165
|
+
summary: string;
|
|
166
|
+
diff?: string;
|
|
167
|
+
}): Promise<'approve' | 'deny' | 'approve_once' | 'deny_always'>;
|
|
168
|
+
requiresApproval(toolName: string, input: unknown): boolean;
|
|
169
|
+
}
|
|
170
|
+
export interface ErrorClassifier {
|
|
171
|
+
classify(err: unknown, provider: string, model: string): ClassifiedError;
|
|
172
|
+
}
|
|
173
|
+
export interface ClassifiedError {
|
|
174
|
+
retryable: boolean;
|
|
175
|
+
backoffMs?: number;
|
|
176
|
+
shouldFallback: boolean;
|
|
177
|
+
reason: string;
|
|
178
|
+
}
|
|
179
|
+
export interface AgentHooks {
|
|
180
|
+
beforeTurn?: (turnIndex: number, messages: Message[]) => Promise<'continue' | 'abort'>;
|
|
181
|
+
beforeToolCall?: (call: ToolCall) => Promise<{
|
|
182
|
+
block: true;
|
|
183
|
+
reason: string;
|
|
184
|
+
} | {
|
|
185
|
+
block: false;
|
|
186
|
+
replaceInput?: unknown;
|
|
187
|
+
} | undefined>;
|
|
188
|
+
afterToolCall?: (call: ToolCall, result: ToolResult) => Promise<ToolResult>;
|
|
189
|
+
afterTurn?: (turnIndex: number, usage: UsageTotal) => Promise<void>;
|
|
190
|
+
}
|
|
191
|
+
export type JsonSchema = {
|
|
192
|
+
type?: string;
|
|
193
|
+
properties?: Record<string, JsonSchema>;
|
|
194
|
+
required?: string[];
|
|
195
|
+
items?: JsonSchema;
|
|
196
|
+
enum?: unknown[];
|
|
197
|
+
description?: string;
|
|
198
|
+
[key: string]: unknown;
|
|
199
|
+
};
|
|
200
|
+
export interface AgentResult {
|
|
201
|
+
messages: Message[];
|
|
202
|
+
usage: UsageTotal;
|
|
203
|
+
stopReason: StopReason;
|
|
204
|
+
turnCount: number;
|
|
205
|
+
sessionId: string;
|
|
206
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical message and event types.
|
|
3
|
+
*
|
|
4
|
+
* Every layer above kernel consumes these types. Providers emit events,
|
|
5
|
+
* tools consume tool-use parts and emit tool-result parts, surfaces render
|
|
6
|
+
* events, the daemon streams events over RPC. One shape, everywhere.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal MCP client: JSON-RPC 2.0 over a Transport, with request
|
|
3
|
+
* correlation by id and a simple notification fan-out. Sufficient for
|
|
4
|
+
* initialize / tools/list / tools/call and resources/read.
|
|
5
|
+
*/
|
|
6
|
+
import { Transport } from './transport.js';
|
|
7
|
+
export interface McpClient {
|
|
8
|
+
initialize(): Promise<InitializeResult>;
|
|
9
|
+
listTools(): Promise<McpTool[]>;
|
|
10
|
+
callTool(name: string, arguments_: unknown): Promise<McpToolCallResult>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export interface InitializeResult {
|
|
14
|
+
protocolVersion: string;
|
|
15
|
+
serverInfo: {
|
|
16
|
+
name: string;
|
|
17
|
+
version: string;
|
|
18
|
+
};
|
|
19
|
+
capabilities: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
export interface McpTool {
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
inputSchema: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
export interface McpToolCallResult {
|
|
27
|
+
content: Array<{
|
|
28
|
+
type: string;
|
|
29
|
+
text?: string;
|
|
30
|
+
}>;
|
|
31
|
+
isError?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare class DefaultMcpClient implements McpClient {
|
|
34
|
+
private transport;
|
|
35
|
+
private nextId;
|
|
36
|
+
private pending;
|
|
37
|
+
constructor(transport: Transport);
|
|
38
|
+
initialize(): Promise<InitializeResult>;
|
|
39
|
+
listTools(): Promise<McpTool[]>;
|
|
40
|
+
callTool(name: string, arguments_: unknown): Promise<McpToolCallResult>;
|
|
41
|
+
close(): Promise<void>;
|
|
42
|
+
private request;
|
|
43
|
+
private handle;
|
|
44
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal MCP client: JSON-RPC 2.0 over a Transport, with request
|
|
3
|
+
* correlation by id and a simple notification fan-out. Sufficient for
|
|
4
|
+
* initialize / tools/list / tools/call and resources/read.
|
|
5
|
+
*/
|
|
6
|
+
export class DefaultMcpClient {
|
|
7
|
+
transport;
|
|
8
|
+
nextId = 1;
|
|
9
|
+
pending = new Map();
|
|
10
|
+
constructor(transport) {
|
|
11
|
+
this.transport = transport;
|
|
12
|
+
this.transport.onMessage(msg => this.handle(msg));
|
|
13
|
+
}
|
|
14
|
+
async initialize() {
|
|
15
|
+
return await this.request('initialize', {
|
|
16
|
+
protocolVersion: '2024-11-05',
|
|
17
|
+
capabilities: { tools: {} },
|
|
18
|
+
clientInfo: { name: 'dirgha-cli', version: '0.2.0' },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async listTools() {
|
|
22
|
+
const result = await this.request('tools/list');
|
|
23
|
+
return result.tools ?? [];
|
|
24
|
+
}
|
|
25
|
+
async callTool(name, arguments_) {
|
|
26
|
+
return await this.request('tools/call', { name, arguments: arguments_ });
|
|
27
|
+
}
|
|
28
|
+
async close() {
|
|
29
|
+
for (const [, pending] of this.pending)
|
|
30
|
+
pending.reject(new Error('Client closed'));
|
|
31
|
+
this.pending.clear();
|
|
32
|
+
await this.transport.close();
|
|
33
|
+
}
|
|
34
|
+
async request(method, params) {
|
|
35
|
+
const id = this.nextId++;
|
|
36
|
+
const message = { jsonrpc: '2.0', id, method, params };
|
|
37
|
+
const promise = new Promise((resolve, reject) => {
|
|
38
|
+
this.pending.set(id, { resolve: v => resolve(v), reject });
|
|
39
|
+
});
|
|
40
|
+
await this.transport.send(message);
|
|
41
|
+
return promise;
|
|
42
|
+
}
|
|
43
|
+
handle(raw) {
|
|
44
|
+
if (!isResponse(raw))
|
|
45
|
+
return;
|
|
46
|
+
const pending = this.pending.get(raw.id);
|
|
47
|
+
if (!pending)
|
|
48
|
+
return;
|
|
49
|
+
this.pending.delete(raw.id);
|
|
50
|
+
if (raw.error)
|
|
51
|
+
pending.reject(new Error(`${raw.error.code}: ${raw.error.message}`));
|
|
52
|
+
else
|
|
53
|
+
pending.resolve(raw.result);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function isResponse(v) {
|
|
57
|
+
return typeof v === 'object'
|
|
58
|
+
&& v !== null
|
|
59
|
+
&& 'jsonrpc' in v
|
|
60
|
+
&& v.jsonrpc === '2.0'
|
|
61
|
+
&& 'id' in v;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridges MCP-exposed tools into the local Tool registry. Each MCP tool
|
|
3
|
+
* becomes a Tool whose execute() proxies to client.callTool().
|
|
4
|
+
*/
|
|
5
|
+
import type { Tool } from '../tools/registry.js';
|
|
6
|
+
import type { McpClient } from './client.js';
|
|
7
|
+
export interface McpBridgeOptions {
|
|
8
|
+
serverName: string;
|
|
9
|
+
prefix?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function bridgeMcpTools(client: McpClient, opts: McpBridgeOptions): Promise<Tool[]>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridges MCP-exposed tools into the local Tool registry. Each MCP tool
|
|
3
|
+
* becomes a Tool whose execute() proxies to client.callTool().
|
|
4
|
+
*/
|
|
5
|
+
export async function bridgeMcpTools(client, opts) {
|
|
6
|
+
const tools = await client.listTools();
|
|
7
|
+
const prefix = opts.prefix ?? `${opts.serverName}_`;
|
|
8
|
+
return tools.map(t => toolFromMcp(client, t, prefix));
|
|
9
|
+
}
|
|
10
|
+
function toolFromMcp(client, mcp, prefix) {
|
|
11
|
+
return {
|
|
12
|
+
name: `${prefix}${mcp.name}`,
|
|
13
|
+
description: mcp.description ?? `MCP tool: ${mcp.name}`,
|
|
14
|
+
inputSchema: mcp.inputSchema,
|
|
15
|
+
async execute(input, _ctx) {
|
|
16
|
+
try {
|
|
17
|
+
const response = await client.callTool(mcp.name, input);
|
|
18
|
+
const text = response.content.map(p => p.text ?? '').join('\n').trim();
|
|
19
|
+
return {
|
|
20
|
+
content: text.length > 0 ? text : '(empty response)',
|
|
21
|
+
isError: response.isError ?? false,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
return {
|
|
26
|
+
content: `MCP tool call failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
27
|
+
isError: true,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=tool-bridge.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP transport. Supports stdio (spawn subprocess, JSON-RPC over
|
|
3
|
+
* stdin/stdout) for local servers. Remote HTTP/SSE transport can be
|
|
4
|
+
* added later by implementing the same Transport interface.
|
|
5
|
+
*/
|
|
6
|
+
export interface Transport {
|
|
7
|
+
send(message: unknown): Promise<void>;
|
|
8
|
+
onMessage(handler: (message: unknown) => void): void;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export interface StdioTransportOptions {
|
|
12
|
+
command: string;
|
|
13
|
+
args?: string[];
|
|
14
|
+
env?: Record<string, string>;
|
|
15
|
+
cwd?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class StdioTransport implements Transport {
|
|
18
|
+
private opts;
|
|
19
|
+
private child;
|
|
20
|
+
private handlers;
|
|
21
|
+
private buffer;
|
|
22
|
+
private ready;
|
|
23
|
+
constructor(opts: StdioTransportOptions);
|
|
24
|
+
private start;
|
|
25
|
+
private onData;
|
|
26
|
+
send(message: unknown): Promise<void>;
|
|
27
|
+
onMessage(handler: (message: unknown) => void): void;
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP transport. Supports stdio (spawn subprocess, JSON-RPC over
|
|
3
|
+
* stdin/stdout) for local servers. Remote HTTP/SSE transport can be
|
|
4
|
+
* added later by implementing the same Transport interface.
|
|
5
|
+
*/
|
|
6
|
+
import { spawn } from 'node:child_process';
|
|
7
|
+
export class StdioTransport {
|
|
8
|
+
opts;
|
|
9
|
+
child = null;
|
|
10
|
+
handlers = [];
|
|
11
|
+
buffer = '';
|
|
12
|
+
ready;
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
this.opts = opts;
|
|
15
|
+
this.ready = this.start();
|
|
16
|
+
}
|
|
17
|
+
start() {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
try {
|
|
20
|
+
const child = spawn(this.opts.command, this.opts.args ?? [], {
|
|
21
|
+
env: { ...process.env, ...this.opts.env },
|
|
22
|
+
cwd: this.opts.cwd,
|
|
23
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
24
|
+
});
|
|
25
|
+
this.child = child;
|
|
26
|
+
child.stdout.on('data', (buf) => this.onData(buf));
|
|
27
|
+
child.stderr.on('data', () => { });
|
|
28
|
+
child.on('error', err => reject(err));
|
|
29
|
+
child.on('spawn', () => resolve());
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
reject(err);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
onData(buf) {
|
|
37
|
+
this.buffer += buf.toString('utf8');
|
|
38
|
+
let idx;
|
|
39
|
+
while ((idx = this.buffer.indexOf('\n')) >= 0) {
|
|
40
|
+
const line = this.buffer.slice(0, idx);
|
|
41
|
+
this.buffer = this.buffer.slice(idx + 1);
|
|
42
|
+
if (!line.trim())
|
|
43
|
+
continue;
|
|
44
|
+
try {
|
|
45
|
+
const parsed = JSON.parse(line);
|
|
46
|
+
for (const h of this.handlers)
|
|
47
|
+
h(parsed);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async send(message) {
|
|
55
|
+
await this.ready;
|
|
56
|
+
if (!this.child || !this.child.stdin)
|
|
57
|
+
throw new Error('Transport is closed');
|
|
58
|
+
await new Promise((resolve, reject) => {
|
|
59
|
+
const data = `${JSON.stringify(message)}\n`;
|
|
60
|
+
this.child.stdin.write(data, err => err ? reject(err) : resolve());
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
onMessage(handler) {
|
|
64
|
+
this.handlers.push(handler);
|
|
65
|
+
}
|
|
66
|
+
async close() {
|
|
67
|
+
if (this.child && !this.child.killed) {
|
|
68
|
+
this.child.kill();
|
|
69
|
+
this.child = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-port HTTP server that serves scripted SSE responses for the
|
|
3
|
+
* OpenAI-compatible dialect. Used by the parity harness to drive the
|
|
4
|
+
* real provider adapters against deterministic fixtures.
|
|
5
|
+
*/
|
|
6
|
+
export interface MockResponse {
|
|
7
|
+
chunks: string[];
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
status?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface MockServer {
|
|
12
|
+
readonly url: string;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare function startMockOpenAICompat(queue: MockResponse[]): Promise<MockServer>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-port HTTP server that serves scripted SSE responses for the
|
|
3
|
+
* OpenAI-compatible dialect. Used by the parity harness to drive the
|
|
4
|
+
* real provider adapters against deterministic fixtures.
|
|
5
|
+
*/
|
|
6
|
+
import { createServer } from 'node:http';
|
|
7
|
+
export async function startMockOpenAICompat(queue) {
|
|
8
|
+
const pending = [...queue];
|
|
9
|
+
const server = createServer((req, res) => {
|
|
10
|
+
const response = pending.shift() ?? { chunks: [] };
|
|
11
|
+
const status = response.status ?? 200;
|
|
12
|
+
res.writeHead(status, {
|
|
13
|
+
'Content-Type': 'text/event-stream',
|
|
14
|
+
'Cache-Control': 'no-cache',
|
|
15
|
+
'Connection': 'keep-alive',
|
|
16
|
+
...response.headers,
|
|
17
|
+
});
|
|
18
|
+
// Consume request body fully before replying to match real server semantics.
|
|
19
|
+
req.on('data', () => { });
|
|
20
|
+
req.on('end', () => {
|
|
21
|
+
for (const chunk of response.chunks) {
|
|
22
|
+
res.write(`data: ${chunk}\n\n`);
|
|
23
|
+
}
|
|
24
|
+
res.end();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
await new Promise(resolve => server.listen(0, '127.0.0.1', () => resolve()));
|
|
28
|
+
const address = server.address();
|
|
29
|
+
const url = `http://127.0.0.1:${address.port}`;
|
|
30
|
+
return {
|
|
31
|
+
url,
|
|
32
|
+
close: () => new Promise(resolve => server.close(() => resolve())),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=mock-openai-compat.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parity runner. For each scenario, spins up a mock server, points the
|
|
3
|
+
* provider adapter at it, collects events, and diffs against the
|
|
4
|
+
* scenario's expected type sequence. Reports success/failure with a
|
|
5
|
+
* per-scenario diff.
|
|
6
|
+
*/
|
|
7
|
+
import type { ParityScenario } from './scenarios.js';
|
|
8
|
+
export interface ParityReport {
|
|
9
|
+
total: number;
|
|
10
|
+
passed: number;
|
|
11
|
+
failed: number;
|
|
12
|
+
scenarios: ParityScenarioReport[];
|
|
13
|
+
}
|
|
14
|
+
export interface ParityScenarioReport {
|
|
15
|
+
name: string;
|
|
16
|
+
ok: boolean;
|
|
17
|
+
expected: string[];
|
|
18
|
+
actual: string[];
|
|
19
|
+
diff?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function runParity(scenarios: ParityScenario[]): Promise<ParityReport>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parity runner. For each scenario, spins up a mock server, points the
|
|
3
|
+
* provider adapter at it, collects events, and diffs against the
|
|
4
|
+
* scenario's expected type sequence. Reports success/failure with a
|
|
5
|
+
* per-scenario diff.
|
|
6
|
+
*/
|
|
7
|
+
import { NvidiaProvider } from '../providers/nvidia.js';
|
|
8
|
+
import { OpenRouterProvider } from '../providers/openrouter.js';
|
|
9
|
+
import { OpenAIProvider } from '../providers/openai.js';
|
|
10
|
+
import { startMockOpenAICompat } from './mock-openai-compat.js';
|
|
11
|
+
export async function runParity(scenarios) {
|
|
12
|
+
const results = [];
|
|
13
|
+
for (const scenario of scenarios) {
|
|
14
|
+
results.push(await runScenario(scenario));
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
total: results.length,
|
|
18
|
+
passed: results.filter(r => r.ok).length,
|
|
19
|
+
failed: results.filter(r => !r.ok).length,
|
|
20
|
+
scenarios: results,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async function runScenario(scenario) {
|
|
24
|
+
const mock = await startMockOpenAICompat([{ chunks: scenario.mockChunks }]);
|
|
25
|
+
try {
|
|
26
|
+
const provider = makeProvider(scenario.provider, mock.url);
|
|
27
|
+
const events = [];
|
|
28
|
+
for await (const ev of provider.stream({ model: scenario.model, messages: scenario.request.messages, tools: scenario.request.tools })) {
|
|
29
|
+
events.push(ev);
|
|
30
|
+
}
|
|
31
|
+
const actualTypes = events.map(e => e.type);
|
|
32
|
+
const ok = sameSequence(actualTypes, scenario.expectedEventTypes);
|
|
33
|
+
return {
|
|
34
|
+
name: scenario.name,
|
|
35
|
+
ok,
|
|
36
|
+
expected: [...scenario.expectedEventTypes],
|
|
37
|
+
actual: actualTypes,
|
|
38
|
+
diff: ok ? undefined : diffSequences(scenario.expectedEventTypes, actualTypes),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
await mock.close();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function makeProvider(id, baseUrl) {
|
|
46
|
+
switch (id) {
|
|
47
|
+
case 'nvidia':
|
|
48
|
+
return new NvidiaProvider({ apiKey: 'test', baseUrl, timeoutMs: 5000 });
|
|
49
|
+
case 'openrouter':
|
|
50
|
+
return new OpenRouterProvider({ apiKey: 'test', baseUrl, timeoutMs: 5000 });
|
|
51
|
+
case 'openai':
|
|
52
|
+
return new OpenAIProvider({ apiKey: 'test', baseUrl, timeoutMs: 5000 });
|
|
53
|
+
case 'anthropic':
|
|
54
|
+
case 'gemini':
|
|
55
|
+
throw new Error(`Parity mock for ${id} not yet implemented in runner`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function sameSequence(a, b) {
|
|
59
|
+
if (a.length !== b.length)
|
|
60
|
+
return false;
|
|
61
|
+
for (let i = 0; i < a.length; i++)
|
|
62
|
+
if (a[i] !== b[i])
|
|
63
|
+
return false;
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
function diffSequences(expected, actual) {
|
|
67
|
+
const max = Math.max(expected.length, actual.length);
|
|
68
|
+
const lines = [];
|
|
69
|
+
for (let i = 0; i < max; i++) {
|
|
70
|
+
const e = expected[i] ?? '(none)';
|
|
71
|
+
const a = actual[i] ?? '(none)';
|
|
72
|
+
lines.push(`${i === 0 ? ' idx' : ''.padStart(4)} expected=${e.padEnd(18)} actual=${a}${e === a ? '' : ' <-- mismatch'}`);
|
|
73
|
+
}
|
|
74
|
+
return lines.join('\n');
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scripted parity scenarios. Each scenario describes a sequence of
|
|
3
|
+
* inputs (messages, tool stubs) and the expected event sequence from
|
|
4
|
+
* the provider adapter under test. Scenarios are format-agnostic; the
|
|
5
|
+
* runner maps them onto mock HTTP servers per provider.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentEvent, Message, ToolDefinition } from '../kernel/types.js';
|
|
8
|
+
export interface ParityScenario {
|
|
9
|
+
name: string;
|
|
10
|
+
provider: 'nvidia' | 'openrouter' | 'openai' | 'anthropic' | 'gemini';
|
|
11
|
+
model: string;
|
|
12
|
+
request: {
|
|
13
|
+
messages: Message[];
|
|
14
|
+
tools?: ToolDefinition[];
|
|
15
|
+
};
|
|
16
|
+
/** Mock SSE response lines (without the leading `data:` prefix). */
|
|
17
|
+
mockChunks: string[];
|
|
18
|
+
expectedEventTypes: Array<AgentEvent['type']>;
|
|
19
|
+
}
|
|
20
|
+
export declare const DEFAULT_SCENARIOS: ParityScenario[];
|