trail-code 0.0.0-stage → 0.28.0-semantic.3
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 +21 -0
- package/README.md +567 -2
- package/dist/ai/crux.d.ts +88 -0
- package/dist/ai/crux.d.ts.map +1 -0
- package/dist/ai/crux.js +219 -0
- package/dist/ai/crux.js.map +1 -0
- package/dist/ai/failure.d.ts +60 -0
- package/dist/ai/failure.d.ts.map +1 -0
- package/dist/ai/failure.js +86 -0
- package/dist/ai/failure.js.map +1 -0
- package/dist/ai/llm/anthropic.d.ts +37 -0
- package/dist/ai/llm/anthropic.d.ts.map +1 -0
- package/dist/ai/llm/anthropic.js +144 -0
- package/dist/ai/llm/anthropic.js.map +1 -0
- package/dist/ai/llm/factory.d.ts +28 -0
- package/dist/ai/llm/factory.d.ts.map +1 -0
- package/dist/ai/llm/factory.js +36 -0
- package/dist/ai/llm/factory.js.map +1 -0
- package/dist/ai/llm/litellm.d.ts +34 -0
- package/dist/ai/llm/litellm.d.ts.map +1 -0
- package/dist/ai/llm/litellm.js +45 -0
- package/dist/ai/llm/litellm.js.map +1 -0
- package/dist/ai/llm/openai.d.ts +145 -0
- package/dist/ai/llm/openai.d.ts.map +1 -0
- package/dist/ai/llm/openai.js +629 -0
- package/dist/ai/llm/openai.js.map +1 -0
- package/dist/ai/llm/orcarouter.d.ts +34 -0
- package/dist/ai/llm/orcarouter.d.ts.map +1 -0
- package/dist/ai/llm/orcarouter.js +45 -0
- package/dist/ai/llm/orcarouter.js.map +1 -0
- package/dist/ai/llm/recover-tool.d.ts +21 -0
- package/dist/ai/llm/recover-tool.d.ts.map +1 -0
- package/dist/ai/llm/recover-tool.js +109 -0
- package/dist/ai/llm/recover-tool.js.map +1 -0
- package/dist/ai/llm/types.d.ts +122 -0
- package/dist/ai/llm/types.d.ts.map +1 -0
- package/dist/ai/llm/types.js +33 -0
- package/dist/ai/llm/types.js.map +1 -0
- package/dist/ai/providers.d.ts +59 -0
- package/dist/ai/providers.d.ts.map +1 -0
- package/dist/ai/providers.js +54 -0
- package/dist/ai/providers.js.map +1 -0
- package/dist/ai/summarize.d.ts +25 -0
- package/dist/ai/summarize.d.ts.map +1 -0
- package/dist/ai/summarize.js +34 -0
- package/dist/ai/summarize.js.map +1 -0
- package/dist/ai/synthesize.d.ts +40 -0
- package/dist/ai/synthesize.d.ts.map +1 -0
- package/dist/ai/synthesize.js +230 -0
- package/dist/ai/synthesize.js.map +1 -0
- package/dist/ask/ask.d.ts +199 -0
- package/dist/ask/ask.d.ts.map +1 -0
- package/dist/ask/ask.js +1291 -0
- package/dist/ask/ask.js.map +1 -0
- package/dist/ask/file-rank.d.ts +72 -0
- package/dist/ask/file-rank.d.ts.map +1 -0
- package/dist/ask/file-rank.js +160 -0
- package/dist/ask/file-rank.js.map +1 -0
- package/dist/ask/file-selection.d.ts +22 -0
- package/dist/ask/file-selection.d.ts.map +1 -0
- package/dist/ask/file-selection.js +66 -0
- package/dist/ask/file-selection.js.map +1 -0
- package/dist/ask/fuse.d.ts +195 -0
- package/dist/ask/fuse.d.ts.map +1 -0
- package/dist/ask/fuse.js +344 -0
- package/dist/ask/fuse.js.map +1 -0
- package/dist/ask/graphrank.d.ts +61 -0
- package/dist/ask/graphrank.d.ts.map +1 -0
- package/dist/ask/graphrank.js +130 -0
- package/dist/ask/graphrank.js.map +1 -0
- package/dist/ask/index-file.d.ts +44 -0
- package/dist/ask/index-file.d.ts.map +1 -0
- package/dist/ask/index-file.js +128 -0
- package/dist/ask/index-file.js.map +1 -0
- package/dist/ask/semantic.d.ts +42 -0
- package/dist/ask/semantic.d.ts.map +1 -0
- package/dist/ask/semantic.js +293 -0
- package/dist/ask/semantic.js.map +1 -0
- package/dist/bin/graft.d.ts +3 -0
- package/dist/bin/graft.d.ts.map +1 -0
- package/dist/bin/graft.js +14 -0
- package/dist/bin/graft.js.map +1 -0
- package/dist/bin/trail.d.ts +3 -0
- package/dist/bin/trail.d.ts.map +1 -0
- package/dist/bin/trail.js +13 -0
- package/dist/bin/trail.js.map +1 -0
- package/dist/blast/blast-cli.d.ts +35 -0
- package/dist/blast/blast-cli.d.ts.map +1 -0
- package/dist/blast/blast-cli.js +155 -0
- package/dist/blast/blast-cli.js.map +1 -0
- package/dist/blast/blast.d.ts +128 -0
- package/dist/blast/blast.d.ts.map +1 -0
- package/dist/blast/blast.js +383 -0
- package/dist/blast/blast.js.map +1 -0
- package/dist/blast/diff.d.ts +53 -0
- package/dist/blast/diff.d.ts.map +1 -0
- package/dist/blast/diff.js +193 -0
- package/dist/blast/diff.js.map +1 -0
- package/dist/blast/evidence.d.ts +51 -0
- package/dist/blast/evidence.d.ts.map +1 -0
- package/dist/blast/evidence.js +162 -0
- package/dist/blast/evidence.js.map +1 -0
- package/dist/blast/modules.d.ts +33 -0
- package/dist/blast/modules.d.ts.map +1 -0
- package/dist/blast/modules.js +83 -0
- package/dist/blast/modules.js.map +1 -0
- package/dist/blast/name.d.ts +74 -0
- package/dist/blast/name.d.ts.map +1 -0
- package/dist/blast/name.js +269 -0
- package/dist/blast/name.js.map +1 -0
- package/dist/blast/owners.d.ts +85 -0
- package/dist/blast/owners.d.ts.map +1 -0
- package/dist/blast/owners.js +272 -0
- package/dist/blast/owners.js.map +1 -0
- package/dist/blast/render.d.ts +46 -0
- package/dist/blast/render.d.ts.map +1 -0
- package/dist/blast/render.js +422 -0
- package/dist/blast/render.js.map +1 -0
- package/dist/blast/viz.d.ts +37 -0
- package/dist/blast/viz.d.ts.map +1 -0
- package/dist/blast/viz.js +180 -0
- package/dist/blast/viz.js.map +1 -0
- package/dist/brand.d.ts +111 -0
- package/dist/brand.d.ts.map +1 -0
- package/dist/brand.js +282 -0
- package/dist/brand.js.map +1 -0
- package/dist/claude/build-progress.d.ts +30 -0
- package/dist/claude/build-progress.d.ts.map +1 -0
- package/dist/claude/build-progress.js +81 -0
- package/dist/claude/build-progress.js.map +1 -0
- package/dist/claude/hermes-skill-template.d.ts +16 -0
- package/dist/claude/hermes-skill-template.d.ts.map +1 -0
- package/dist/claude/hermes-skill-template.js +154 -0
- package/dist/claude/hermes-skill-template.js.map +1 -0
- package/dist/claude/init.d.ts +65 -0
- package/dist/claude/init.d.ts.map +1 -0
- package/dist/claude/init.js +258 -0
- package/dist/claude/init.js.map +1 -0
- package/dist/claude/paths.d.ts +9 -0
- package/dist/claude/paths.d.ts.map +1 -0
- package/dist/claude/paths.js +22 -0
- package/dist/claude/paths.js.map +1 -0
- package/dist/claude/session-metrics.d.ts +73 -0
- package/dist/claude/session-metrics.d.ts.map +1 -0
- package/dist/claude/session-metrics.js +209 -0
- package/dist/claude/session-metrics.js.map +1 -0
- package/dist/claude/settings-merge.d.ts +76 -0
- package/dist/claude/settings-merge.d.ts.map +1 -0
- package/dist/claude/settings-merge.js +283 -0
- package/dist/claude/settings-merge.js.map +1 -0
- package/dist/claude/skill-template.d.ts +13 -0
- package/dist/claude/skill-template.d.ts.map +1 -0
- package/dist/claude/skill-template.js +290 -0
- package/dist/claude/skill-template.js.map +1 -0
- package/dist/claude/state.d.ts +85 -0
- package/dist/claude/state.d.ts.map +1 -0
- package/dist/claude/state.js +88 -0
- package/dist/claude/state.js.map +1 -0
- package/dist/claude/stats.d.ts +5 -0
- package/dist/claude/stats.d.ts.map +1 -0
- package/dist/claude/stats.js +24 -0
- package/dist/claude/stats.js.map +1 -0
- package/dist/cli-epilogue.d.ts +12 -0
- package/dist/cli-epilogue.d.ts.map +1 -0
- package/dist/cli-epilogue.js +72 -0
- package/dist/cli-epilogue.js.map +1 -0
- package/dist/cli-meta.d.ts +82 -0
- package/dist/cli-meta.d.ts.map +1 -0
- package/dist/cli-meta.js +238 -0
- package/dist/cli-meta.js.map +1 -0
- package/dist/cli-picker.d.ts +139 -0
- package/dist/cli-picker.d.ts.map +1 -0
- package/dist/cli-picker.js +439 -0
- package/dist/cli-picker.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +1638 -0
- package/dist/cli.js.map +1 -0
- package/dist/context/batches.d.ts +29 -0
- package/dist/context/batches.d.ts.map +1 -0
- package/dist/context/batches.js +130 -0
- package/dist/context/batches.js.map +1 -0
- package/dist/context/build.d.ts +57 -0
- package/dist/context/build.d.ts.map +1 -0
- package/dist/context/build.js +396 -0
- package/dist/context/build.js.map +1 -0
- package/dist/context/check.d.ts +42 -0
- package/dist/context/check.d.ts.map +1 -0
- package/dist/context/check.js +162 -0
- package/dist/context/check.js.map +1 -0
- package/dist/context/map-dir.d.ts +13 -0
- package/dist/context/map-dir.d.ts.map +1 -0
- package/dist/context/map-dir.js +81 -0
- package/dist/context/map-dir.js.map +1 -0
- package/dist/context/node-file.d.ts +109 -0
- package/dist/context/node-file.d.ts.map +1 -0
- package/dist/context/node-file.js +390 -0
- package/dist/context/node-file.js.map +1 -0
- package/dist/context/price.d.ts +49 -0
- package/dist/context/price.d.ts.map +1 -0
- package/dist/context/price.js +83 -0
- package/dist/context/price.js.map +1 -0
- package/dist/context/savings.d.ts +67 -0
- package/dist/context/savings.d.ts.map +1 -0
- package/dist/context/savings.js +125 -0
- package/dist/context/savings.js.map +1 -0
- package/dist/engine.d.ts +85 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +122 -0
- package/dist/engine.js.map +1 -0
- package/dist/graph/bindings.d.ts +64 -0
- package/dist/graph/bindings.d.ts.map +1 -0
- package/dist/graph/bindings.js +713 -0
- package/dist/graph/bindings.js.map +1 -0
- package/dist/graph/build-run.d.ts +25 -0
- package/dist/graph/build-run.d.ts.map +1 -0
- package/dist/graph/build-run.js +121 -0
- package/dist/graph/build-run.js.map +1 -0
- package/dist/graph/build.d.ts +88 -0
- package/dist/graph/build.d.ts.map +1 -0
- package/dist/graph/build.js +386 -0
- package/dist/graph/build.js.map +1 -0
- package/dist/graph/cards.d.ts +46 -0
- package/dist/graph/cards.d.ts.map +1 -0
- package/dist/graph/cards.js +280 -0
- package/dist/graph/cards.js.map +1 -0
- package/dist/graph/check.d.ts +25 -0
- package/dist/graph/check.d.ts.map +1 -0
- package/dist/graph/check.js +192 -0
- package/dist/graph/check.js.map +1 -0
- package/dist/graph/container.d.ts +63 -0
- package/dist/graph/container.d.ts.map +1 -0
- package/dist/graph/container.js +191 -0
- package/dist/graph/container.js.map +1 -0
- package/dist/graph/depth-parser.d.ts +61 -0
- package/dist/graph/depth-parser.d.ts.map +1 -0
- package/dist/graph/depth-parser.js +153 -0
- package/dist/graph/depth-parser.js.map +1 -0
- package/dist/graph/enrich.d.ts +62 -0
- package/dist/graph/enrich.d.ts.map +1 -0
- package/dist/graph/enrich.js +258 -0
- package/dist/graph/enrich.js.map +1 -0
- package/dist/graph/extract-cache.d.ts +101 -0
- package/dist/graph/extract-cache.d.ts.map +1 -0
- package/dist/graph/extract-cache.js +199 -0
- package/dist/graph/extract-cache.js.map +1 -0
- package/dist/graph/extract.d.ts +85 -0
- package/dist/graph/extract.d.ts.map +1 -0
- package/dist/graph/extract.js +2377 -0
- package/dist/graph/extract.js.map +1 -0
- package/dist/graph/fingerprint.d.ts +76 -0
- package/dist/graph/fingerprint.d.ts.map +1 -0
- package/dist/graph/fingerprint.js +160 -0
- package/dist/graph/fingerprint.js.map +1 -0
- package/dist/graph/generic.d.ts +74 -0
- package/dist/graph/generic.d.ts.map +1 -0
- package/dist/graph/generic.js +773 -0
- package/dist/graph/generic.js.map +1 -0
- package/dist/graph/invariants.d.ts +33 -0
- package/dist/graph/invariants.d.ts.map +1 -0
- package/dist/graph/invariants.js +52 -0
- package/dist/graph/invariants.js.map +1 -0
- package/dist/graph/load.d.ts +29 -0
- package/dist/graph/load.d.ts.map +1 -0
- package/dist/graph/load.js +97 -0
- package/dist/graph/load.js.map +1 -0
- package/dist/graph/lsp/client.d.ts +61 -0
- package/dist/graph/lsp/client.d.ts.map +1 -0
- package/dist/graph/lsp/client.js +217 -0
- package/dist/graph/lsp/client.js.map +1 -0
- package/dist/graph/lsp/enrich.d.ts +11 -0
- package/dist/graph/lsp/enrich.d.ts.map +1 -0
- package/dist/graph/lsp/enrich.js +163 -0
- package/dist/graph/lsp/enrich.js.map +1 -0
- package/dist/graph/lsp/registry.d.ts +22 -0
- package/dist/graph/lsp/registry.d.ts.map +1 -0
- package/dist/graph/lsp/registry.js +71 -0
- package/dist/graph/lsp/registry.js.map +1 -0
- package/dist/graph/map.d.ts +107 -0
- package/dist/graph/map.d.ts.map +1 -0
- package/dist/graph/map.js +239 -0
- package/dist/graph/map.js.map +1 -0
- package/dist/graph/markdown.d.ts +22 -0
- package/dist/graph/markdown.d.ts.map +1 -0
- package/dist/graph/markdown.js +143 -0
- package/dist/graph/markdown.js.map +1 -0
- package/dist/graph/native.d.ts +46 -0
- package/dist/graph/native.d.ts.map +1 -0
- package/dist/graph/native.js +169 -0
- package/dist/graph/native.js.map +1 -0
- package/dist/graph/queries/c.scm +13 -0
- package/dist/graph/queries/c_sharp.scm +19 -0
- package/dist/graph/queries/clojure.scm +58 -0
- package/dist/graph/queries/cpp.scm +23 -0
- package/dist/graph/queries/dart.scm +42 -0
- package/dist/graph/queries/elixir.scm +54 -0
- package/dist/graph/queries/gleam.scm +51 -0
- package/dist/graph/queries/java.scm +20 -0
- package/dist/graph/queries/kotlin.scm +43 -0
- package/dist/graph/queries/lua.scm +36 -0
- package/dist/graph/queries/nix.scm +32 -0
- package/dist/graph/queries/php.scm +40 -0
- package/dist/graph/queries/ruby.scm +65 -0
- package/dist/graph/queries/rust.scm +41 -0
- package/dist/graph/queries/scala.scm +66 -0
- package/dist/graph/queries/solidity.scm +43 -0
- package/dist/graph/queries/swift.scm +51 -0
- package/dist/graph/refresh.d.ts +106 -0
- package/dist/graph/refresh.d.ts.map +1 -0
- package/dist/graph/refresh.js +430 -0
- package/dist/graph/refresh.js.map +1 -0
- package/dist/graph/relations.d.ts +14 -0
- package/dist/graph/relations.d.ts.map +1 -0
- package/dist/graph/relations.js +8 -0
- package/dist/graph/relations.js.map +1 -0
- package/dist/graph/resolve.d.ts +17 -0
- package/dist/graph/resolve.d.ts.map +1 -0
- package/dist/graph/resolve.js +716 -0
- package/dist/graph/resolve.js.map +1 -0
- package/dist/graph/root.d.ts +11 -0
- package/dist/graph/root.d.ts.map +1 -0
- package/dist/graph/root.js +40 -0
- package/dist/graph/root.js.map +1 -0
- package/dist/graph/scopes.d.ts +40 -0
- package/dist/graph/scopes.d.ts.map +1 -0
- package/dist/graph/scopes.js +383 -0
- package/dist/graph/scopes.js.map +1 -0
- package/dist/graph/seed.d.ts +38 -0
- package/dist/graph/seed.d.ts.map +1 -0
- package/dist/graph/seed.js +229 -0
- package/dist/graph/seed.js.map +1 -0
- package/dist/graph/source-files.d.ts +46 -0
- package/dist/graph/source-files.d.ts.map +1 -0
- package/dist/graph/source-files.js +118 -0
- package/dist/graph/source-files.js.map +1 -0
- package/dist/graph/traverse-cli.d.ts +55 -0
- package/dist/graph/traverse-cli.d.ts.map +1 -0
- package/dist/graph/traverse-cli.js +189 -0
- package/dist/graph/traverse-cli.js.map +1 -0
- package/dist/graph/traverse.d.ts +112 -0
- package/dist/graph/traverse.d.ts.map +1 -0
- package/dist/graph/traverse.js +192 -0
- package/dist/graph/traverse.js.map +1 -0
- package/dist/graph/types.d.ts +78 -0
- package/dist/graph/types.d.ts.map +1 -0
- package/dist/graph/types.js +14 -0
- package/dist/graph/types.js.map +1 -0
- package/dist/graph/wasm-runtime.d.ts +19 -0
- package/dist/graph/wasm-runtime.d.ts.map +1 -0
- package/dist/graph/wasm-runtime.js +38 -0
- package/dist/graph/wasm-runtime.js.map +1 -0
- package/dist/graph/workspace-cli.d.ts +56 -0
- package/dist/graph/workspace-cli.d.ts.map +1 -0
- package/dist/graph/workspace-cli.js +111 -0
- package/dist/graph/workspace-cli.js.map +1 -0
- package/dist/graph/workspace.d.ts +172 -0
- package/dist/graph/workspace.d.ts.map +1 -0
- package/dist/graph/workspace.js +714 -0
- package/dist/graph/workspace.js.map +1 -0
- package/dist/graph/write.d.ts +13 -0
- package/dist/graph/write.d.ts.map +1 -0
- package/dist/graph/write.js +86 -0
- package/dist/graph/write.js.map +1 -0
- package/dist/hosts/antigravity.d.ts +14 -0
- package/dist/hosts/antigravity.d.ts.map +1 -0
- package/dist/hosts/antigravity.js +59 -0
- package/dist/hosts/antigravity.js.map +1 -0
- package/dist/hosts/auto.d.ts +37 -0
- package/dist/hosts/auto.d.ts.map +1 -0
- package/dist/hosts/auto.js +141 -0
- package/dist/hosts/auto.js.map +1 -0
- package/dist/hosts/claude-global.d.ts +72 -0
- package/dist/hosts/claude-global.d.ts.map +1 -0
- package/dist/hosts/claude-global.js +230 -0
- package/dist/hosts/claude-global.js.map +1 -0
- package/dist/hosts/config-write.d.ts +36 -0
- package/dist/hosts/config-write.d.ts.map +1 -0
- package/dist/hosts/config-write.js +64 -0
- package/dist/hosts/config-write.js.map +1 -0
- package/dist/hosts/init.d.ts +28 -0
- package/dist/hosts/init.d.ts.map +1 -0
- package/dist/hosts/init.js +89 -0
- package/dist/hosts/init.js.map +1 -0
- package/dist/hosts/instructions.d.ts +14 -0
- package/dist/hosts/instructions.d.ts.map +1 -0
- package/dist/hosts/instructions.js +95 -0
- package/dist/hosts/instructions.js.map +1 -0
- package/dist/hosts/mcp-config.d.ts +78 -0
- package/dist/hosts/mcp-config.d.ts.map +1 -0
- package/dist/hosts/mcp-config.js +251 -0
- package/dist/hosts/mcp-config.js.map +1 -0
- package/dist/hosts/plan.d.ts +32 -0
- package/dist/hosts/plan.d.ts.map +1 -0
- package/dist/hosts/plan.js +73 -0
- package/dist/hosts/plan.js.map +1 -0
- package/dist/hosts/registry.d.ts +41 -0
- package/dist/hosts/registry.d.ts.map +1 -0
- package/dist/hosts/registry.js +164 -0
- package/dist/hosts/registry.js.map +1 -0
- package/dist/hosts/retract.d.ts +47 -0
- package/dist/hosts/retract.d.ts.map +1 -0
- package/dist/hosts/retract.js +520 -0
- package/dist/hosts/retract.js.map +1 -0
- package/dist/hosts/sections.d.ts +47 -0
- package/dist/hosts/sections.d.ts.map +1 -0
- package/dist/hosts/sections.js +127 -0
- package/dist/hosts/sections.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/ingest/fs.d.ts +79 -0
- package/dist/ingest/fs.d.ts.map +1 -0
- package/dist/ingest/fs.js +306 -0
- package/dist/ingest/fs.js.map +1 -0
- package/dist/init-guard.d.ts +16 -0
- package/dist/init-guard.d.ts.map +1 -0
- package/dist/init-guard.js +27 -0
- package/dist/init-guard.js.map +1 -0
- package/dist/mcp/instructions.d.ts +5 -0
- package/dist/mcp/instructions.d.ts.map +1 -0
- package/dist/mcp/instructions.js +64 -0
- package/dist/mcp/instructions.js.map +1 -0
- package/dist/mcp/kept-listing.d.ts +27 -0
- package/dist/mcp/kept-listing.d.ts.map +1 -0
- package/dist/mcp/kept-listing.js +63 -0
- package/dist/mcp/kept-listing.js.map +1 -0
- package/dist/mcp/server.d.ts +4 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +147 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tool-names.d.ts +27 -0
- package/dist/mcp/tool-names.d.ts.map +1 -0
- package/dist/mcp/tool-names.js +47 -0
- package/dist/mcp/tool-names.js.map +1 -0
- package/dist/mcp/tools.d.ts +22 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +440 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/node-version.d.ts +15 -0
- package/dist/node-version.d.ts.map +1 -0
- package/dist/node-version.js +23 -0
- package/dist/node-version.js.map +1 -0
- package/dist/search/grep-cli.d.ts +35 -0
- package/dist/search/grep-cli.d.ts.map +1 -0
- package/dist/search/grep-cli.js +115 -0
- package/dist/search/grep-cli.js.map +1 -0
- package/dist/search/grep.d.ts +60 -0
- package/dist/search/grep.d.ts.map +1 -0
- package/dist/search/grep.js +143 -0
- package/dist/search/grep.js.map +1 -0
- package/dist/search/ignored-code.d.ts +9 -0
- package/dist/search/ignored-code.d.ts.map +1 -0
- package/dist/search/ignored-code.js +73 -0
- package/dist/search/ignored-code.js.map +1 -0
- package/dist/search/user-regexp.d.ts +26 -0
- package/dist/search/user-regexp.d.ts.map +1 -0
- package/dist/search/user-regexp.js +150 -0
- package/dist/search/user-regexp.js.map +1 -0
- package/dist/telemetry/contract.d.ts +117 -0
- package/dist/telemetry/contract.d.ts.map +1 -0
- package/dist/telemetry/contract.js +341 -0
- package/dist/telemetry/contract.js.map +1 -0
- package/dist/telemetry/flush.d.ts +21 -0
- package/dist/telemetry/flush.d.ts.map +1 -0
- package/dist/telemetry/flush.js +85 -0
- package/dist/telemetry/flush.js.map +1 -0
- package/dist/telemetry/gate.d.ts +30 -0
- package/dist/telemetry/gate.d.ts.map +1 -0
- package/dist/telemetry/gate.js +81 -0
- package/dist/telemetry/gate.js.map +1 -0
- package/dist/telemetry/identity.d.ts +40 -0
- package/dist/telemetry/identity.d.ts.map +1 -0
- package/dist/telemetry/identity.js +80 -0
- package/dist/telemetry/identity.js.map +1 -0
- package/dist/telemetry/index.d.ts +18 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +16 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry/key.d.ts +21 -0
- package/dist/telemetry/key.d.ts.map +1 -0
- package/dist/telemetry/key.js +49 -0
- package/dist/telemetry/key.js.map +1 -0
- package/dist/telemetry/notice.d.ts +19 -0
- package/dist/telemetry/notice.d.ts.map +1 -0
- package/dist/telemetry/notice.js +93 -0
- package/dist/telemetry/notice.js.map +1 -0
- package/dist/telemetry/queue.d.ts +35 -0
- package/dist/telemetry/queue.d.ts.map +1 -0
- package/dist/telemetry/queue.js +162 -0
- package/dist/telemetry/queue.js.map +1 -0
- package/dist/telemetry/send.d.ts +19 -0
- package/dist/telemetry/send.d.ts.map +1 -0
- package/dist/telemetry/send.js +84 -0
- package/dist/telemetry/send.js.map +1 -0
- package/dist/telemetry/sessions.d.ts +25 -0
- package/dist/telemetry/sessions.d.ts.map +1 -0
- package/dist/telemetry/sessions.js +104 -0
- package/dist/telemetry/sessions.js.map +1 -0
- package/dist/telemetry/track.d.ts +62 -0
- package/dist/telemetry/track.d.ts.map +1 -0
- package/dist/telemetry/track.js +143 -0
- package/dist/telemetry/track.js.map +1 -0
- package/dist/upkeep-run.d.ts +22 -0
- package/dist/upkeep-run.d.ts.map +1 -0
- package/dist/upkeep-run.js +85 -0
- package/dist/upkeep-run.js.map +1 -0
- package/dist/upkeep.d.ts +127 -0
- package/dist/upkeep.d.ts.map +1 -0
- package/dist/upkeep.js +252 -0
- package/dist/upkeep.js.map +1 -0
- package/dist/util/actions-folder.d.ts +2 -0
- package/dist/util/actions-folder.d.ts.map +1 -0
- package/dist/util/actions-folder.js +9 -0
- package/dist/util/actions-folder.js.map +1 -0
- package/dist/util/browser.d.ts +3 -0
- package/dist/util/browser.d.ts.map +1 -0
- package/dist/util/browser.js +14 -0
- package/dist/util/browser.js.map +1 -0
- package/dist/util/child-process.d.ts +15 -0
- package/dist/util/child-process.d.ts.map +1 -0
- package/dist/util/child-process.js +15 -0
- package/dist/util/child-process.js.map +1 -0
- package/dist/util/front-matter.d.ts +46 -0
- package/dist/util/front-matter.d.ts.map +1 -0
- package/dist/util/front-matter.js +113 -0
- package/dist/util/front-matter.js.map +1 -0
- package/dist/util/id.d.ts +7 -0
- package/dist/util/id.d.ts.map +1 -0
- package/dist/util/id.js +14 -0
- package/dist/util/id.js.map +1 -0
- package/dist/util/paths.d.ts +29 -0
- package/dist/util/paths.d.ts.map +1 -0
- package/dist/util/paths.js +71 -0
- package/dist/util/paths.js.map +1 -0
- package/dist/util/private-file.d.ts +14 -0
- package/dist/util/private-file.d.ts.map +1 -0
- package/dist/util/private-file.js +82 -0
- package/dist/util/private-file.js.map +1 -0
- package/dist/util/source.d.ts +4 -0
- package/dist/util/source.d.ts.map +1 -0
- package/dist/util/source.js +12 -0
- package/dist/util/source.js.map +1 -0
- package/dist/util/spinner.d.ts +15 -0
- package/dist/util/spinner.d.ts.map +1 -0
- package/dist/util/spinner.js +52 -0
- package/dist/util/spinner.js.map +1 -0
- package/dist/util/state.d.ts +120 -0
- package/dist/util/state.d.ts.map +1 -0
- package/dist/util/state.js +264 -0
- package/dist/util/state.js.map +1 -0
- package/dist/vendor/grammars/tree-sitter-go.LICENSE +21 -0
- package/dist/vendor/grammars/tree-sitter-go.wasm +0 -0
- package/dist/vendor/grammars/tree-sitter-java.LICENSE +21 -0
- package/dist/vendor/grammars/tree-sitter-java.wasm +0 -0
- package/dist/vendor/grammars/tree-sitter-kotlin.LICENSE +9 -0
- package/dist/vendor/grammars/tree-sitter-kotlin.wasm +0 -0
- package/dist/vendor/grammars/tree-sitter-php.LICENSE +22 -0
- package/dist/vendor/grammars/tree-sitter-php.wasm +0 -0
- package/dist/vendor/grammars/tree-sitter-python.LICENSE +21 -0
- package/dist/vendor/grammars/tree-sitter-python.wasm +0 -0
- package/dist/vendor/grammars/tree-sitter-r.LICENSE +9 -0
- package/dist/vendor/grammars/tree-sitter-r.wasm +0 -0
- package/dist/vendor/grammars/tree-sitter-swift.LICENSE +21 -0
- package/dist/vendor/grammars/tree-sitter-swift.wasm +0 -0
- package/dist/vendor/grammars/tree-sitter-tsx.wasm +0 -0
- package/dist/vendor/grammars/tree-sitter-typescript.LICENSE +21 -0
- package/dist/vendor/grammars/tree-sitter-typescript.wasm +0 -0
- package/dist/viewer/app.js +2 -0
- package/dist/viewer/index.html +49 -0
- package/dist/viewer/style.css +154 -0
- package/dist/viz/assemble.d.ts +83 -0
- package/dist/viz/assemble.d.ts.map +1 -0
- package/dist/viz/assemble.js +101 -0
- package/dist/viz/assemble.js.map +1 -0
- package/dist/viz/export.d.ts +39 -0
- package/dist/viz/export.d.ts.map +1 -0
- package/dist/viz/export.js +98 -0
- package/dist/viz/export.js.map +1 -0
- package/dist/viz/serve.d.ts +13 -0
- package/dist/viz/serve.d.ts.map +1 -0
- package/dist/viz/serve.js +130 -0
- package/dist/viz/serve.js.map +1 -0
- package/package.json +115 -4
- package/scripts/build-grammar-wasm.mjs +112 -0
- package/scripts/build-viewer.mjs +44 -0
- package/scripts/graph-quality.mjs +117 -0
- package/scripts/pack-trail.mjs +53 -0
- package/scripts/postinstall.mjs +65 -0
- package/scripts/run-tests.mjs +72 -0
- package/scripts/stamp-telemetry-key.mjs +56 -0
- package/scripts/tally-audit.mjs +140 -0
- package/scripts/vendor-grammars.mjs +53 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native Anthropic transport. Wraps `@anthropic-ai/sdk` (the Messages API), so
|
|
3
|
+
* Claude is a first-class provider rather than something tunneled through an
|
|
4
|
+
* OpenAI-compatible endpoint.
|
|
5
|
+
*
|
|
6
|
+
* The Messages API differs from Chat Completions in ways this adapter absorbs so
|
|
7
|
+
* the rest of graft never sees them:
|
|
8
|
+
* - `system` is a top-level parameter, not a message.
|
|
9
|
+
* - tool results ride inside a USER turn, and all results answering one
|
|
10
|
+
* assistant turn must be coalesced into a single user message.
|
|
11
|
+
* - `max_tokens` is required (callers get a default).
|
|
12
|
+
* - `temperature` is rejected by current models, so it is never forwarded.
|
|
13
|
+
* - structured output is a forced tool (there is no `response_format`).
|
|
14
|
+
* - assistant turns are replayed verbatim (via `providerRaw`) so thinking-block
|
|
15
|
+
* signatures survive a multi-turn loop.
|
|
16
|
+
*/
|
|
17
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
18
|
+
import { transportRetries } from "./types.js";
|
|
19
|
+
const PROVIDER = "anthropic";
|
|
20
|
+
const JSON_TOOL = "emit_json";
|
|
21
|
+
const DEFAULT_MAX_TOKENS = 4096;
|
|
22
|
+
const cc = (on) => (on ? { cache_control: { type: "ephemeral" } } : {});
|
|
23
|
+
export class AnthropicChatModel {
|
|
24
|
+
label;
|
|
25
|
+
client;
|
|
26
|
+
model;
|
|
27
|
+
constructor(opts) {
|
|
28
|
+
this.model = opts.model;
|
|
29
|
+
this.label = opts.label ?? `${PROVIDER}:${opts.model}`;
|
|
30
|
+
this.client =
|
|
31
|
+
opts.client ??
|
|
32
|
+
new Anthropic({ apiKey: opts.apiKey, baseURL: opts.baseUrl, maxRetries: transportRetries() });
|
|
33
|
+
}
|
|
34
|
+
async create(req) {
|
|
35
|
+
const system = [];
|
|
36
|
+
const messages = [];
|
|
37
|
+
for (const m of req.messages) {
|
|
38
|
+
if (m.role === "system") {
|
|
39
|
+
system.push({ type: "text", text: m.content, ...cc(m.cacheBreakpoint) });
|
|
40
|
+
}
|
|
41
|
+
else if (m.role === "user") {
|
|
42
|
+
messages.push({ role: "user", content: [{ type: "text", text: m.content, ...cc(m.cacheBreakpoint) }] });
|
|
43
|
+
}
|
|
44
|
+
else if (m.role === "tool") {
|
|
45
|
+
// Tool results live in a user turn; coalesce consecutive results together.
|
|
46
|
+
const block = {
|
|
47
|
+
type: "tool_result",
|
|
48
|
+
tool_use_id: m.toolCallId ?? "",
|
|
49
|
+
content: [{ type: "text", text: m.content }],
|
|
50
|
+
...cc(m.cacheBreakpoint),
|
|
51
|
+
};
|
|
52
|
+
const last = messages[messages.length - 1];
|
|
53
|
+
if (last?.role === "user" && Array.isArray(last.content)) {
|
|
54
|
+
last.content.push(block);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
messages.push({ role: "user", content: [block] });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
messages.push(this.assistantParam(m));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const tools = req.tools?.map(toAnthropicTool);
|
|
65
|
+
const params = {
|
|
66
|
+
model: this.model,
|
|
67
|
+
max_tokens: req.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
68
|
+
messages,
|
|
69
|
+
...(system.length ? { system } : {}),
|
|
70
|
+
};
|
|
71
|
+
// temperature is intentionally NOT forwarded — current models reject it.
|
|
72
|
+
const fmt = req.responseFormat ?? { kind: "text" };
|
|
73
|
+
if (fmt.kind === "json") {
|
|
74
|
+
params.tools = [
|
|
75
|
+
...(tools ?? []),
|
|
76
|
+
{ name: JSON_TOOL, description: "Return the answer as a JSON object.", input_schema: { type: "object" } },
|
|
77
|
+
];
|
|
78
|
+
params.tool_choice = { type: "tool", name: JSON_TOOL };
|
|
79
|
+
}
|
|
80
|
+
else if (fmt.kind === "tool") {
|
|
81
|
+
params.tools = tools;
|
|
82
|
+
params.tool_choice = { type: "tool", name: fmt.name };
|
|
83
|
+
}
|
|
84
|
+
else if (tools) {
|
|
85
|
+
params.tools = tools;
|
|
86
|
+
}
|
|
87
|
+
const resp = await this.client.messages.create(params);
|
|
88
|
+
return this.fromResponse(resp, fmt.kind);
|
|
89
|
+
}
|
|
90
|
+
/** Reconstruct an assistant turn, replaying the original blocks when we made them. */
|
|
91
|
+
assistantParam(m) {
|
|
92
|
+
if (m.providerRaw?.provider === PROVIDER)
|
|
93
|
+
return m.providerRaw.raw;
|
|
94
|
+
const content = [];
|
|
95
|
+
if (m.content)
|
|
96
|
+
content.push({ type: "text", text: m.content });
|
|
97
|
+
for (const tc of m.toolCalls ?? []) {
|
|
98
|
+
content.push({ type: "tool_use", id: tc.id, name: tc.name, input: tc.args });
|
|
99
|
+
}
|
|
100
|
+
return { role: "assistant", content };
|
|
101
|
+
}
|
|
102
|
+
fromResponse(resp, format) {
|
|
103
|
+
let text = "";
|
|
104
|
+
let toolCalls = [];
|
|
105
|
+
for (const block of resp.content) {
|
|
106
|
+
if (block.type === "text")
|
|
107
|
+
text += block.text;
|
|
108
|
+
else if (block.type === "tool_use")
|
|
109
|
+
toolCalls.push({ id: block.id, name: block.name, args: block.input });
|
|
110
|
+
}
|
|
111
|
+
if (format === "json") {
|
|
112
|
+
const jsonCall = toolCalls.find((c) => c.name === JSON_TOOL);
|
|
113
|
+
if (jsonCall)
|
|
114
|
+
text = JSON.stringify(jsonCall.args);
|
|
115
|
+
toolCalls = toolCalls.filter((c) => c.name !== JSON_TOOL);
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
text,
|
|
119
|
+
toolCalls,
|
|
120
|
+
usage: normalizeUsage(resp.usage),
|
|
121
|
+
stopReason: resp.stop_reason ?? null,
|
|
122
|
+
// Replay the raw content verbatim so thinking-block signatures survive.
|
|
123
|
+
assistant: {
|
|
124
|
+
role: "assistant",
|
|
125
|
+
content: text,
|
|
126
|
+
toolCalls: toolCalls.length ? toolCalls : undefined,
|
|
127
|
+
providerRaw: { provider: PROVIDER, raw: { role: "assistant", content: resp.content } },
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function toAnthropicTool(t) {
|
|
133
|
+
return { name: t.name, description: t.description, input_schema: t.parameters };
|
|
134
|
+
}
|
|
135
|
+
/** Anthropic reports uncached input in `input_tokens` and cache tokens separately. */
|
|
136
|
+
function normalizeUsage(u) {
|
|
137
|
+
return {
|
|
138
|
+
input: u.input_tokens ?? 0,
|
|
139
|
+
output: u.output_tokens ?? 0,
|
|
140
|
+
cacheRead: u.cache_read_input_tokens ?? 0,
|
|
141
|
+
cacheCreate: u.cache_creation_input_tokens ?? 0,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/ai/llm/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,MAAM,QAAQ,GAAG,WAAW,CAAC;AAC7B,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAYhC,MAAM,EAAE,GAAG,CAAC,EAAuB,EAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,W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K,CAAC;YACjC,UAAU,EAAE,IAAI,CAAC,WAAW,IAAI,IAAI;YACpC,wEAAwE;YACxE,SAAS,EAAE;gBACT,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,IAAI;gBACb,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;gBACnD,WAAW,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE;aACvF;SACF,CAAC;IACJ,CAAC;CACF;AAED,SAAS,eAAe,CAAC,CAAW;IAClC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,WAAW,EAAE,YAAY,EAAE,CAAC,CAAC,UAAwC,EAAE,CAAC;AAChH,CAAC;AAED,sFAAsF;AACtF,SAAS,cAAc,CAAC,CAAkB;IACxC,OAAO;QACL,KAAK,EAAE,CAAC,CAAC,YAAY,IAAI,CAAC;QAC1B,MAAM,EAAE,CAAC,CAAC,aAAa,IAAI,CAAC;QAC5B,SAAS,EAAE,CAAC,CAAC,uBAAuB,IAAI,CAAC;QACzC,WAAW,EAAE,CAAC,CAAC,2BAA2B,IAAI,CAAC;KAChD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One place that turns resolved config into a {@link ChatModel}. `provider` names
|
|
3
|
+
* the WIRE FORMAT, not a vendor: `openai` speaks the OpenAI-compatible API (point
|
|
4
|
+
* `baseUrl` at OpenRouter, Fireworks, a LiteLLM proxy, Groq, a local server, …),
|
|
5
|
+
* `anthropic` speaks the native Messages API. Adding a vendor is a base URL, not
|
|
6
|
+
* a code change; adding a wire format is one new adapter here.
|
|
7
|
+
*
|
|
8
|
+
* `litellm` is a convenience over `openai`: same wire format, but pointed at a
|
|
9
|
+
* LiteLLM proxy by default and paired with `/v1/models` auto-discovery
|
|
10
|
+
* (see litellm.ts), so one endpoint reaches 100+ providers.
|
|
11
|
+
*
|
|
12
|
+
* `orcarouter` is the same kind of convenience over `openai`, pointed at the
|
|
13
|
+
* OrcaRouter AI gateway by default (see orcarouter.ts) so its users get the
|
|
14
|
+
* gateway's routing, failover, and guardrails behind a named provider instead
|
|
15
|
+
* of a bare custom base URL.
|
|
16
|
+
*/
|
|
17
|
+
import type { ChatModel } from "./types.js";
|
|
18
|
+
export type ProviderKind = "openai" | "anthropic" | "litellm" | "orcarouter";
|
|
19
|
+
export interface ChatModelConfig {
|
|
20
|
+
provider: ProviderKind;
|
|
21
|
+
apiKey: string;
|
|
22
|
+
model: string;
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
/** Extra default headers for OpenAI-compatible endpoints (e.g. OpenRouter `X-Title`). */
|
|
25
|
+
headers?: Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
export declare function createChatModel(cfg: ChatModelConfig): ChatModel;
|
|
28
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/ai/llm/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAM5C,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,YAAY,CAAC;AAE7E,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,YAAY,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yFAAyF;IACzF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,eAAe,GAAG,SAAS,CA8B/D"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { OpenAIChatModel } from "./openai.js";
|
|
2
|
+
import { AnthropicChatModel } from "./anthropic.js";
|
|
3
|
+
import { LiteLLMChatModel } from "./litellm.js";
|
|
4
|
+
import { OrcaRouterChatModel } from "./orcarouter.js";
|
|
5
|
+
export function createChatModel(cfg) {
|
|
6
|
+
switch (cfg.provider) {
|
|
7
|
+
case "anthropic":
|
|
8
|
+
return new AnthropicChatModel({ apiKey: cfg.apiKey, model: cfg.model, baseUrl: cfg.baseUrl });
|
|
9
|
+
case "openai":
|
|
10
|
+
return new OpenAIChatModel({
|
|
11
|
+
apiKey: cfg.apiKey,
|
|
12
|
+
model: cfg.model,
|
|
13
|
+
baseUrl: cfg.baseUrl,
|
|
14
|
+
headers: cfg.headers,
|
|
15
|
+
});
|
|
16
|
+
case "litellm":
|
|
17
|
+
return new LiteLLMChatModel({
|
|
18
|
+
apiKey: cfg.apiKey,
|
|
19
|
+
model: cfg.model,
|
|
20
|
+
baseUrl: cfg.baseUrl,
|
|
21
|
+
headers: cfg.headers,
|
|
22
|
+
});
|
|
23
|
+
case "orcarouter":
|
|
24
|
+
return new OrcaRouterChatModel({
|
|
25
|
+
apiKey: cfg.apiKey,
|
|
26
|
+
model: cfg.model,
|
|
27
|
+
baseUrl: cfg.baseUrl,
|
|
28
|
+
headers: cfg.headers,
|
|
29
|
+
});
|
|
30
|
+
default: {
|
|
31
|
+
const _exhaustive = cfg.provider;
|
|
32
|
+
throw new Error(`unknown provider: ${String(_exhaustive)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/ai/llm/factory.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBA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1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LiteLLM transport. A LiteLLM proxy speaks the OpenAI-compatible wire format,
|
|
3
|
+
* so this reuses the OpenAI adapter's request/response translation and simply
|
|
4
|
+
* points it at the proxy. The value over a bare `openai` provider + `baseUrl`
|
|
5
|
+
* is a first-class, self-describing provider: a sensible default proxy address
|
|
6
|
+
* and `/v1/models` auto-discovery (see {@link listLiteLLMModels}), so callers
|
|
7
|
+
* can enumerate whatever models the proxy is configured to serve — reaching
|
|
8
|
+
* 100+ providers (OpenAI, Anthropic, Gemini, Bedrock, Vertex, …) through one
|
|
9
|
+
* endpoint without a per-vendor code path.
|
|
10
|
+
*/
|
|
11
|
+
import OpenAI from "openai";
|
|
12
|
+
import { OpenAIChatModel, type OpenAIChatModelOptions } from "./openai.js";
|
|
13
|
+
/** Conventional local address of a self-hosted LiteLLM proxy. */
|
|
14
|
+
export declare const DEFAULT_LITELLM_BASE_URL = "http://localhost:4000";
|
|
15
|
+
export type LiteLLMChatModelOptions = OpenAIChatModelOptions;
|
|
16
|
+
/**
|
|
17
|
+
* ChatModel backed by a LiteLLM proxy. Inherits every translation detail from
|
|
18
|
+
* {@link OpenAIChatModel} (the proxy is OpenAI-compatible) and only changes the
|
|
19
|
+
* defaults: the proxy base URL and a `litellm:<model>` label.
|
|
20
|
+
*/
|
|
21
|
+
export declare class LiteLLMChatModel extends OpenAIChatModel {
|
|
22
|
+
constructor(opts: LiteLLMChatModelOptions);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Auto-discover the models a LiteLLM proxy is serving via `GET /v1/models`.
|
|
26
|
+
* Returns the model ids so a caller can present/validate them instead of
|
|
27
|
+
* hardcoding a model string. A stub `client` may be injected for tests.
|
|
28
|
+
*/
|
|
29
|
+
export declare function listLiteLLMModels(opts: {
|
|
30
|
+
apiKey: string;
|
|
31
|
+
baseUrl?: string;
|
|
32
|
+
client?: OpenAI;
|
|
33
|
+
}): Promise<string[]>;
|
|
34
|
+
//# sourceMappingURL=litellm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"litellm.d.ts","sourceRoot":"","sources":["../../../src/ai/llm/litellm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAG3E,iEAAiE;AACjE,eAAO,MAAM,wBAAwB,0BAA0B,CAAC;AAEhE,MAAM,MAAM,uBAAuB,GAAG,sBAAsB,CAAC;AAE7D;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,eAAe;gBACvC,IAAI,EAAE,uBAAuB;CAO1C;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAUpB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LiteLLM transport. A LiteLLM proxy speaks the OpenAI-compatible wire format,
|
|
3
|
+
* so this reuses the OpenAI adapter's request/response translation and simply
|
|
4
|
+
* points it at the proxy. The value over a bare `openai` provider + `baseUrl`
|
|
5
|
+
* is a first-class, self-describing provider: a sensible default proxy address
|
|
6
|
+
* and `/v1/models` auto-discovery (see {@link listLiteLLMModels}), so callers
|
|
7
|
+
* can enumerate whatever models the proxy is configured to serve — reaching
|
|
8
|
+
* 100+ providers (OpenAI, Anthropic, Gemini, Bedrock, Vertex, …) through one
|
|
9
|
+
* endpoint without a per-vendor code path.
|
|
10
|
+
*/
|
|
11
|
+
import OpenAI from "openai";
|
|
12
|
+
import { OpenAIChatModel } from "./openai.js";
|
|
13
|
+
import { transportRetries } from "./types.js";
|
|
14
|
+
/** Conventional local address of a self-hosted LiteLLM proxy. */
|
|
15
|
+
export const DEFAULT_LITELLM_BASE_URL = "http://localhost:4000";
|
|
16
|
+
/**
|
|
17
|
+
* ChatModel backed by a LiteLLM proxy. Inherits every translation detail from
|
|
18
|
+
* {@link OpenAIChatModel} (the proxy is OpenAI-compatible) and only changes the
|
|
19
|
+
* defaults: the proxy base URL and a `litellm:<model>` label.
|
|
20
|
+
*/
|
|
21
|
+
export class LiteLLMChatModel extends OpenAIChatModel {
|
|
22
|
+
constructor(opts) {
|
|
23
|
+
super({
|
|
24
|
+
...opts,
|
|
25
|
+
baseUrl: opts.baseUrl ?? DEFAULT_LITELLM_BASE_URL,
|
|
26
|
+
label: opts.label ?? `litellm:${opts.model}`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Auto-discover the models a LiteLLM proxy is serving via `GET /v1/models`.
|
|
32
|
+
* Returns the model ids so a caller can present/validate them instead of
|
|
33
|
+
* hardcoding a model string. A stub `client` may be injected for tests.
|
|
34
|
+
*/
|
|
35
|
+
export async function listLiteLLMModels(opts) {
|
|
36
|
+
const client = opts.client ??
|
|
37
|
+
new OpenAI({
|
|
38
|
+
apiKey: opts.apiKey,
|
|
39
|
+
baseURL: opts.baseUrl ?? DEFAULT_LITELLM_BASE_URL,
|
|
40
|
+
maxRetries: transportRetries(),
|
|
41
|
+
});
|
|
42
|
+
const res = await client.models.list();
|
|
43
|
+
return res.data.map((m) => m.id);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=litellm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"litellm.js","sourceRoot":"","sources":["../../../src/ai/llm/litellm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,eAAe,EAA+B,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,iEAAiE;AACjE,MAAM,CAAC,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;AAIhE;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IACnD,YAAY,IAA6B;QACvC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,wBAAwB;YACjD,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,WAAW,IAAI,CAAC,KAAK,EAAE;SAC7C,CAAC,CAAC;IACL,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAIvC;IACC,MAAM,MAAM,GACV,IAAI,CAAC,MAAM;QACX,IAAI,MAAM,CAAC;YACT,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,wBAAwB;YACjD,UAAU,EAAE,gBAAgB,EAAE;SAC/B,CAAC,CAAC;IACL,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACvC,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-compatible transport. Wraps the `openai` SDK pointed at any
|
|
3
|
+
* OpenAI-compatible endpoint (OpenAI, OpenRouter, Fireworks, a LiteLLM proxy,
|
|
4
|
+
* Groq, Together, DeepSeek, a local server, …) — the user picks the endpoint
|
|
5
|
+
* with `baseUrl` and authenticates with their own key.
|
|
6
|
+
*
|
|
7
|
+
* This adapter reproduces graft's historical wire behavior exactly: temperature
|
|
8
|
+
* is forwarded, cache breakpoints become `cache_control` content parts (which
|
|
9
|
+
* OpenRouter forwards to Anthropic), and cached tokens are subtracted out of the
|
|
10
|
+
* input count so {@link Usage.input} is uncached-only.
|
|
11
|
+
*
|
|
12
|
+
* Past that, everything here is tolerance rather than preference. An
|
|
13
|
+
* OpenAI-compatible endpoint is a gateway whose own upstream calls can fail
|
|
14
|
+
* while the HTTP status stays 200, and whose support for a forced `tool_choice`
|
|
15
|
+
* — the one structured-output mechanism graft can rely on across providers —
|
|
16
|
+
* ranges from exact to none. Each way that goes wrong gets its own narrow
|
|
17
|
+
* recovery: {@link ProviderResponseError} for a 200 that is not a completion,
|
|
18
|
+
* and a bounded rung ladder in {@link OpenAIChatModel.structured} for a
|
|
19
|
+
* structured reply the endpoint answers some other way. None of it changes the
|
|
20
|
+
* bytes on the wire for an endpoint that behaves.
|
|
21
|
+
*/
|
|
22
|
+
import OpenAI from "openai";
|
|
23
|
+
import type { ChatModel, ChatRequest, ChatResponse } from "./types.js";
|
|
24
|
+
export interface OpenAIChatModelOptions {
|
|
25
|
+
apiKey: string;
|
|
26
|
+
model: string;
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
/** Stable manifest label; defaults to `openai:<model>`. */
|
|
29
|
+
label?: string;
|
|
30
|
+
/** Extra default headers (e.g. OpenRouter's `X-Title`). */
|
|
31
|
+
headers?: Record<string, string>;
|
|
32
|
+
/** Inject a pre-built client (tests pass a stub; production omits it). */
|
|
33
|
+
client?: OpenAI;
|
|
34
|
+
/** Wait between retries of a 200-that-is-an-error (tests pass a no-op). */
|
|
35
|
+
sleep?: (ms: number) => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A 200 that is not a completion.
|
|
39
|
+
*
|
|
40
|
+
* A proxy in front of a model can answer HTTP 200 with
|
|
41
|
+
* `{"error": {...}}` and no `choices` when the upstream call fails, because the
|
|
42
|
+
* failure belongs to a server the proxy itself did not talk to. The SDK's retry
|
|
43
|
+
* policy only ever sees the status, so it returns that body as a success, and
|
|
44
|
+
* the first `choices[0]` used to turn it into a TypeError naming nothing a user
|
|
45
|
+
* could act on. Retryable by construction — the request was never served — and
|
|
46
|
+
* carrying the provider's own message and code so the failure that does reach
|
|
47
|
+
* the caller says what the endpoint said.
|
|
48
|
+
*/
|
|
49
|
+
export declare class ProviderResponseError extends Error {
|
|
50
|
+
/** The provider's own error code, when the body carried one. */
|
|
51
|
+
readonly code?: string | number | undefined;
|
|
52
|
+
/** The status the provider actually sent. 200: that is the whole surprise. */
|
|
53
|
+
readonly status = 200;
|
|
54
|
+
/** Always true — the same request can succeed on a later attempt. */
|
|
55
|
+
readonly retryable = true;
|
|
56
|
+
constructor(message: string,
|
|
57
|
+
/** The provider's own error code, when the body carried one. */
|
|
58
|
+
code?: string | number | undefined);
|
|
59
|
+
}
|
|
60
|
+
export declare class OpenAIChatModel implements ChatModel {
|
|
61
|
+
readonly label: string;
|
|
62
|
+
private client;
|
|
63
|
+
private model;
|
|
64
|
+
private sleep;
|
|
65
|
+
/** Key into {@link forcedToolChoiceIgnored}: one entry per endpoint + model. */
|
|
66
|
+
private choiceKey;
|
|
67
|
+
private forcedIgnored;
|
|
68
|
+
constructor(opts: OpenAIChatModelOptions);
|
|
69
|
+
create(req: ChatRequest): Promise<ChatResponse>;
|
|
70
|
+
/**
|
|
71
|
+
* A structured reply, however the endpoint is willing to produce one.
|
|
72
|
+
*
|
|
73
|
+
* A forced `tool_choice` is the only structured-output mechanism graft can
|
|
74
|
+
* rely on across providers, and it is the least portable corner of the
|
|
75
|
+
* OpenAI-compatible spec: an endpoint can reject the object form (handled one
|
|
76
|
+
* layer down), answer 200 with an error object, or quietly answer in prose.
|
|
77
|
+
* So walk a bounded ladder — the object form, then `"required"`, then
|
|
78
|
+
* `"auto"` with the tool named in the prompt — and take the payload from
|
|
79
|
+
* `content` if that is where it landed. `"required"` only stands in for the
|
|
80
|
+
* object form when one tool was offered, the same rule the 400 fallback
|
|
81
|
+
* applies: with several tools it would let the model pick freely rather than
|
|
82
|
+
* honour the caller's choice.
|
|
83
|
+
*
|
|
84
|
+
* An endpoint that honours the forced form never sees rung two — the first
|
|
85
|
+
* attempt answers the question and the ladder ends.
|
|
86
|
+
*
|
|
87
|
+
* An errored body is a weaker signal than a served-but-wrong reply, since it
|
|
88
|
+
* may belong to an upstream that a retry would reach, so it never downgrades
|
|
89
|
+
* on its own: it is counted instead. A call where every forced-family rung
|
|
90
|
+
* failed that way and the final "auto" rung then answered is a rescue, and
|
|
91
|
+
* the second rescue with no successful forced call in between is the
|
|
92
|
+
* endpoint's pattern, not its upstream's — that, and only that, switches
|
|
93
|
+
* later calls straight to "auto".
|
|
94
|
+
*/
|
|
95
|
+
private structured;
|
|
96
|
+
/** One rung: the forced object form, its equivalent string form, or "auto" plus a prompt. */
|
|
97
|
+
private attempt;
|
|
98
|
+
/** Did the reply carry the payload the caller forced a tool for? */
|
|
99
|
+
private delivered;
|
|
100
|
+
/**
|
|
101
|
+
* One more rescued call for this endpoint + model. When the count reaches
|
|
102
|
+
* the threshold with no successful forced call in between, the endpoint is
|
|
103
|
+
* marked the same way a served-but-wrong reply marks it.
|
|
104
|
+
*/
|
|
105
|
+
private noteForcedRescue;
|
|
106
|
+
/**
|
|
107
|
+
* Remember, for this process, that the endpoint did not answer a forced
|
|
108
|
+
* `tool_choice` with a tool call, so later requests go straight to the rung
|
|
109
|
+
* that works. Logged once per endpoint + model — the set is shared by every
|
|
110
|
+
* instance, so a second adapter for the same endpoint never repeats it: it
|
|
111
|
+
* changes the bytes on the wire, which is exactly what someone reading a
|
|
112
|
+
* failing build needs told.
|
|
113
|
+
*/
|
|
114
|
+
private rememberForcedIgnored;
|
|
115
|
+
/**
|
|
116
|
+
* One completion, with the transport's retry policy extended to a 200 that
|
|
117
|
+
* carried an error instead of one. The SDK retries 429, 5xx and connection
|
|
118
|
+
* failures but never a successful status, and that body is the endpoint
|
|
119
|
+
* reporting a failed upstream call — the same judgement, so the same
|
|
120
|
+
* `GRAFT_LLM_RETRIES` budget and backoff apply, and the typed error is what
|
|
121
|
+
* reaches the caller once that budget is spent.
|
|
122
|
+
*/
|
|
123
|
+
private complete;
|
|
124
|
+
/**
|
|
125
|
+
* Wraps `chat.completions.create` with a narrow, safe fallback: if the
|
|
126
|
+
* server rejects an object-form `tool_choice` and exactly one tool was
|
|
127
|
+
* offered, "required" is behaviorally identical (the model has nothing
|
|
128
|
+
* else to pick), so retry once with the string form instead of failing
|
|
129
|
+
* the whole build. Left alone when more than one tool is offered, since
|
|
130
|
+
* "required" would then let the model choose freely instead of the
|
|
131
|
+
* caller-specified tool — that ambiguity isn't safe to paper over
|
|
132
|
+
* automatically.
|
|
133
|
+
*/
|
|
134
|
+
private createChatCompletion;
|
|
135
|
+
/**
|
|
136
|
+
* Normalize provider message content to the plain text representation
|
|
137
|
+
* expected by the rest of Graft. Some OpenAI-compatible providers
|
|
138
|
+
* (observed with GLM-5.3 hosted on Mistral's platform) return content as
|
|
139
|
+
* structured content parts, e.g. `[{ type: "text", text: "..." }]`,
|
|
140
|
+
* instead of a plain string — this path in Graft assumed the latter.
|
|
141
|
+
*/
|
|
142
|
+
private static contentToText;
|
|
143
|
+
private fromResponse;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/ai/llm/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAsC,MAAM,YAAY,CAAC;AAsD3G,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2EAA2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