@hoilab/ada-cli 0.84.21 → 0.84.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.es.md +163 -0
- package/README.md +99 -652
- package/dist/cli/args.d.ts +3 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +11 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +2 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/home-screen.d.ts.map +1 -1
- package/dist/cli/home-screen.js +2 -2
- package/dist/cli/home-screen.js.map +1 -1
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +9 -3
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -1
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +57 -7
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +449 -73
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +4 -3
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +3 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +4 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +41 -32
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/defaults.d.ts +1 -0
- package/dist/core/defaults.d.ts.map +1 -1
- package/dist/core/defaults.js +9 -0
- package/dist/core/defaults.js.map +1 -1
- package/dist/core/engine-personality.d.ts +12 -0
- package/dist/core/engine-personality.d.ts.map +1 -0
- package/dist/core/engine-personality.js +53 -0
- package/dist/core/engine-personality.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +10 -5
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/types.d.ts +23 -4
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +2 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/memory-engine/audit-export.d.ts +54 -0
- package/dist/core/memory-engine/audit-export.d.ts.map +1 -0
- package/dist/core/memory-engine/audit-export.js +85 -0
- package/dist/core/memory-engine/audit-export.js.map +1 -0
- package/dist/core/memory-engine/audit.d.ts.map +1 -1
- package/dist/core/memory-engine/audit.js +7 -8
- package/dist/core/memory-engine/audit.js.map +1 -1
- package/dist/core/memory-engine/engine.d.ts +2 -3
- package/dist/core/memory-engine/engine.d.ts.map +1 -1
- package/dist/core/memory-engine/engine.js +148 -50
- package/dist/core/memory-engine/engine.js.map +1 -1
- package/dist/core/memory-engine/inverted-index.d.ts.map +1 -1
- package/dist/core/memory-engine/inverted-index.js +67 -10
- package/dist/core/memory-engine/inverted-index.js.map +1 -1
- package/dist/core/memory-engine/keychain.d.ts.map +1 -1
- package/dist/core/memory-engine/keychain.js +1 -6
- package/dist/core/memory-engine/keychain.js.map +1 -1
- package/dist/core/memory-engine/observation-store.d.ts +1 -0
- package/dist/core/memory-engine/observation-store.d.ts.map +1 -1
- package/dist/core/memory-engine/observation-store.js +37 -8
- package/dist/core/memory-engine/observation-store.js.map +1 -1
- package/dist/core/memory-engine/scanner.d.ts.map +1 -1
- package/dist/core/memory-engine/scanner.js +25 -5
- package/dist/core/memory-engine/scanner.js.map +1 -1
- package/dist/core/memory-engine/security.d.ts.map +1 -1
- package/dist/core/memory-engine/security.js +131 -23
- package/dist/core/memory-engine/security.js.map +1 -1
- package/dist/core/memory-engine/session-indexer.d.ts.map +1 -1
- package/dist/core/memory-engine/session-indexer.js +8 -2
- package/dist/core/memory-engine/session-indexer.js.map +1 -1
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.d.ts.map +1 -1
- package/dist/core/memory-engine/tools.js +14 -7
- package/dist/core/memory-engine/tools.js.map +1 -1
- package/dist/core/memory-engine/vault.d.ts.map +1 -1
- package/dist/core/memory-engine/vault.js +2 -2
- package/dist/core/memory-engine/vault.js.map +1 -1
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +2 -1
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -0
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +12 -6
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +2 -1
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +11 -6
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-manifest.d.ts.map +1 -1
- package/dist/core/pi-manifest.js +2 -1
- package/dist/core/pi-manifest.js.map +1 -1
- package/dist/core/prompt-optimizer.d.ts +53 -0
- package/dist/core/prompt-optimizer.d.ts.map +1 -0
- package/dist/core/prompt-optimizer.js +138 -0
- package/dist/core/prompt-optimizer.js.map +1 -0
- package/dist/core/provider-attribution.d.ts.map +1 -1
- package/dist/core/provider-attribution.js +1 -1
- package/dist/core/provider-attribution.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +2 -1
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts +50 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +233 -7
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +8 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +11 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +2 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-diagnostics.d.ts +9 -0
- package/dist/core/settings-diagnostics.d.ts.map +1 -0
- package/dist/core/settings-diagnostics.js +21 -0
- package/dist/core/settings-diagnostics.js.map +1 -0
- package/dist/core/settings-manager.d.ts +52 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +204 -10
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +51 -33
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +2 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +0 -5
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +2 -5
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +20 -4
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +2 -2
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/project-memory-tool.d.ts.map +1 -1
- package/dist/core/tools/project-memory-tool.js +4 -1
- package/dist/core/tools/project-memory-tool.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +2 -1
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/workflows/agent-runner.d.ts +86 -0
- package/dist/core/workflows/agent-runner.d.ts.map +1 -0
- package/dist/core/workflows/agent-runner.js +225 -0
- package/dist/core/workflows/agent-runner.js.map +1 -0
- package/dist/core/workflows/builtins.d.ts +41 -0
- package/dist/core/workflows/builtins.d.ts.map +1 -0
- package/dist/core/workflows/builtins.js +282 -0
- package/dist/core/workflows/builtins.js.map +1 -0
- package/dist/core/workflows/goal-engine/engine.d.ts +134 -0
- package/dist/core/workflows/goal-engine/engine.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/engine.js +462 -0
- package/dist/core/workflows/goal-engine/engine.js.map +1 -0
- package/dist/core/workflows/goal-engine/errors.d.ts +7 -0
- package/dist/core/workflows/goal-engine/errors.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/errors.js +9 -0
- package/dist/core/workflows/goal-engine/errors.js.map +1 -0
- package/dist/core/workflows/goal-engine/index.d.ts +13 -0
- package/dist/core/workflows/goal-engine/index.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/index.js +8 -0
- package/dist/core/workflows/goal-engine/index.js.map +1 -0
- package/dist/core/workflows/goal-engine/persistence.d.ts +31 -0
- package/dist/core/workflows/goal-engine/persistence.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/persistence.js +145 -0
- package/dist/core/workflows/goal-engine/persistence.js.map +1 -0
- package/dist/core/workflows/goal-engine/prompts.d.ts +37 -0
- package/dist/core/workflows/goal-engine/prompts.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/prompts.js +131 -0
- package/dist/core/workflows/goal-engine/prompts.js.map +1 -0
- package/dist/core/workflows/goal-engine/state.d.ts +41 -0
- package/dist/core/workflows/goal-engine/state.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/state.js +397 -0
- package/dist/core/workflows/goal-engine/state.js.map +1 -0
- package/dist/core/workflows/goal-engine/tools.d.ts +31 -0
- package/dist/core/workflows/goal-engine/tools.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/tools.js +211 -0
- package/dist/core/workflows/goal-engine/tools.js.map +1 -0
- package/dist/core/workflows/goal-engine/types.d.ts +286 -0
- package/dist/core/workflows/goal-engine/types.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/types.js +17 -0
- package/dist/core/workflows/goal-engine/types.js.map +1 -0
- package/dist/core/workflows/goal-engine/worktree-fingerprint.d.ts +23 -0
- package/dist/core/workflows/goal-engine/worktree-fingerprint.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/worktree-fingerprint.js +72 -0
- package/dist/core/workflows/goal-engine/worktree-fingerprint.js.map +1 -0
- package/dist/core/workflows/graph-sync.d.ts +67 -0
- package/dist/core/workflows/graph-sync.d.ts.map +1 -0
- package/dist/core/workflows/graph-sync.js +188 -0
- package/dist/core/workflows/graph-sync.js.map +1 -0
- package/dist/core/workflows/graph.d.ts +143 -0
- package/dist/core/workflows/graph.d.ts.map +1 -0
- package/dist/core/workflows/graph.js +319 -0
- package/dist/core/workflows/graph.js.map +1 -0
- package/dist/core/workflows/index.d.ts +18 -0
- package/dist/core/workflows/index.d.ts.map +1 -0
- package/dist/core/workflows/index.js +14 -0
- package/dist/core/workflows/index.js.map +1 -0
- package/dist/core/workflows/journal.d.ts +68 -0
- package/dist/core/workflows/journal.d.ts.map +1 -0
- package/dist/core/workflows/journal.js +83 -0
- package/dist/core/workflows/journal.js.map +1 -0
- package/dist/core/workflows/manager.d.ts +112 -0
- package/dist/core/workflows/manager.d.ts.map +1 -0
- package/dist/core/workflows/manager.js +327 -0
- package/dist/core/workflows/manager.js.map +1 -0
- package/dist/core/workflows/resolve-script.d.ts +35 -0
- package/dist/core/workflows/resolve-script.d.ts.map +1 -0
- package/dist/core/workflows/resolve-script.js +66 -0
- package/dist/core/workflows/resolve-script.js.map +1 -0
- package/dist/core/workflows/runtime.d.ts +49 -0
- package/dist/core/workflows/runtime.d.ts.map +1 -0
- package/dist/core/workflows/runtime.js +301 -0
- package/dist/core/workflows/runtime.js.map +1 -0
- package/dist/core/workflows/shared-store.d.ts +31 -0
- package/dist/core/workflows/shared-store.d.ts.map +1 -0
- package/dist/core/workflows/shared-store.js +80 -0
- package/dist/core/workflows/shared-store.js.map +1 -0
- package/dist/core/workflows/subagent-host.d.ts +50 -0
- package/dist/core/workflows/subagent-host.d.ts.map +1 -0
- package/dist/core/workflows/subagent-host.js +225 -0
- package/dist/core/workflows/subagent-host.js.map +1 -0
- package/dist/core/workflows/tool-workflow.d.ts +22 -0
- package/dist/core/workflows/tool-workflow.d.ts.map +1 -0
- package/dist/core/workflows/tool-workflow.js +120 -0
- package/dist/core/workflows/tool-workflow.js.map +1 -0
- package/dist/core/workflows/types.d.ts +142 -0
- package/dist/core/workflows/types.d.ts.map +1 -0
- package/dist/core/workflows/types.js +26 -0
- package/dist/core/workflows/types.js.map +1 -0
- package/dist/core/workflows/worktree.d.ts +42 -0
- package/dist/core/workflows/worktree.d.ts.map +1 -0
- package/dist/core/workflows/worktree.js +107 -0
- package/dist/core/workflows/worktree.js.map +1 -0
- package/dist/extensions/llama/index.d.ts.map +1 -1
- package/dist/extensions/llama/index.js +2 -0
- package/dist/extensions/llama/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +6 -2
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/index.d.ts +16 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -11
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +4 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +20 -15
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +4 -3
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/components/home-screen.d.ts.map +1 -1
- package/dist/modes/interactive/components/home-screen.js +2 -2
- package/dist/modes/interactive/components/home-screen.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +2 -3
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +16 -6
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/prompt-optimization.d.ts +16 -0
- package/dist/modes/interactive/components/prompt-optimization.d.ts.map +1 -0
- package/dist/modes/interactive/components/prompt-optimization.js +46 -0
- package/dist/modes/interactive/components/prompt-optimization.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +19 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +247 -46
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts +72 -0
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-submenu.js +165 -0
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +8 -3
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +29 -3
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +2 -1
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +24 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +677 -34
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +4 -3
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/json-event.d.ts +16 -13
- package/dist/modes/json-event.d.ts.map +1 -1
- package/dist/modes/json-event.js +20 -6
- package/dist/modes/json-event.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +173 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +29 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +1 -1
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/skills/ada-engine/SKILL.md +153 -0
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +2 -1
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/management-http.d.ts +5 -3
- package/dist/utils/management-http.d.ts.map +1 -1
- package/dist/utils/management-http.js +14 -10
- package/dist/utils/management-http.js.map +1 -1
- package/dist/utils/text.d.ts +8 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +9 -0
- package/dist/utils/text.js.map +1 -0
- package/docs/compaction.md +15 -0
- package/docs/custom-provider.md +5 -2
- package/docs/extensions.md +11 -2
- package/docs/json.md +7 -2
- package/docs/llama-cpp.md +2 -0
- package/docs/models.md +8 -2
- package/docs/rpc.md +9 -3
- package/docs/settings.md +2 -2
- package/docs/skills.md +4 -3
- package/examples/extensions/border-status-editor.ts +1 -1
- package/examples/extensions/git-checkpoint.ts +2 -2
- package/examples/extensions/notify.ts +3 -1
- package/examples/extensions/subagent/README.md +1 -1
- package/examples/extensions/subagent/index.ts +6 -1
- package/examples/extensions/titlebar-spinner.ts +1 -1
- package/examples/rpc-extension-ui.ts +1 -1
- package/examples/sdk/06-extensions.ts +1 -1
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +2 -12
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/workflows/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAI7D,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC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MAAM,CAAC;IACd,UAAU,EAAE;QACX,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACF;AAID,MAAM,MAAM,iBAAiB,GAC1B,yBAAyB,GACzB,yBAAyB,GACzB,wBAAwB,GACxB,qBAAqB,GACrB,kBAAkB,GAClB,0BAA0B,GAC1B,yBAAyB,GACzB,iBAAiB,CAAC;AAErB,qBAAa,aAAc,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAE9B,YAAY,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,WAAW,CAAC,EAAE,OAAO,CAAA;KAAO,EAK5F;CACD","sourcesContent":["/**\n * Ada Intelligence Engine — shared types (Fase 1).\n *\n * Workflows dinámicos: scripts JS en sandbox vm con agent/parallel/pipeline/\n * store/phase/workflow/checkpoint; subagentes via AgentSessionRuntime; journal\n * con resume determinista; SharedStore con deltas por agente.\n */\n\nimport type { TSchema } from \"typebox\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\n\n// ─── Meta y fases ───\n\nexport interface WorkflowPhase {\n\ttitle: string;\n\tdetail?: string;\n\tmodel?: string;\n}\n\nexport interface WorkflowMeta {\n\tname: string;\n\tdescription: string;\n\tphases?: WorkflowPhase[];\n\t/** Modelo por defecto para agentes sin ruta de fase ni model/tier. */\n\tmodel?: string;\n}\n\n// ─── Límites ───\n\nexport interface WorkflowLimits {\n\tmaxAgentsPerRun: number;\n\tmaxConcurrency: number;\n\tmaxRetries: number;\n\t/** Timeout por agente en ms; null = sin timeout. */\n\tagentTimeoutMs: number | null;\n\t/** Timeout del script vm en ms. */\n\tscriptTimeoutMs: number;\n\t/** Timeout del drain de agentes in-flight en ms (finito — adversarial B). */\n\tdrainTimeoutMs: number;\n}\n\nexport const DEFAULT_WORKFLOW_LIMITS: WorkflowLimits = {\n\tmaxAgentsPerRun: 100,\n\tmaxConcurrency: 4,\n\tmaxRetries: 3,\n\tagentTimeoutMs: 30 * 60 * 1000, // 30 min (Kimi Code alineado)\n\tscriptTimeoutMs: 5 * 60 * 1000, // 5 min\n\tdrainTimeoutMs: 30_000,\n};\n\n// ─── Subagente ───\n\nexport interface AgentRunOptions<TSchemaDef extends TSchema | undefined = TSchema | undefined> {\n\tprompt: string; // OBLIGATORIO\n\tlabel?: string; // nombre en la UI y nombre de la sesión del subagente\n\t/** Modelo \"provider/model\" o \"model\" — MODEL_NOT_FOUND si no resuelve. */\n\tmodel?: string;\n\t/** Tier (\"small\"|\"medium\"|\"big\") con fallback al modelo de sesión. */\n\ttier?: string;\n\t/** Fase actual (routing + UI). */\n\tphase?: string;\n\t/** Structured output (typebox). */\n\tschema?: TSchemaDef;\n\t/** Tools extra (web_search/web_fetch…). Se AÑADEN a las del agente. */\n\ttools?: ToolDefinition[];\n\t/**\n\t * Mínimo privilegio: el agente solo puede leer (`read`/`grep`/`find`/`ls`).\n\t * Para fases de análisis que no deben poder escribir ni ejecutar comandos.\n\t * No es un sandbox de SO — acota las tools del subagente, nada más.\n\t */\n\treadOnly?: boolean;\n\tinstructions?: string;\n\t/** Aislamiento git. */\n\tisolation?: \"none\" | \"worktree\";\n\t/** Clave determinista del worktree (runId:callIndex) — la pone el runtime. */\n\tisolationKey?: string;\n\ttimeoutMs?: number | null;\n\tsignal?: AbortSignal;\n\t/** Clave estable para cache/resume (el autor declara idempotencia). */\n\tstableKey?: string;\n\t/** cwd del agente (base o worktree). Default: cwd del run. */\n\tcwd?: string;\n}\n\nexport interface AgentUsage {\n\tinput: number;\n\toutput: number;\n\ttotal: number;\n\tcost: number;\n\tcacheRead?: number;\n\tcacheWrite?: number;\n}\n\nexport interface AgentRunResult<T = unknown> {\n\tresult: T | null;\n\ttext: string;\n\tusage: AgentUsage;\n\tsessionId?: string;\n\t/** Rama `ada/wf/*` con el trabajo del agente, si corrió aislado y escribió. */\n\tworktreeBranch?: string;\n}\n\n// ─── Journal ───\n\nexport interface JournalEntry {\n\tindex: number;\n\trunId?: string;\n\t/** sha256 de la identidad (prompt+model+phase+schema+stableKey). */\n\thash: string;\n\tresult: unknown;\n\t/** Deltas del store escritos por este agente (replay aditivo). */\n\tstoreDelta?: Record<string, unknown>;\n\t/** Marcado cuando el resultado vino de extracción de prosa (fallback schema). */\n\torigin?: \"structured\" | \"recovered\";\n}\n\n// ─── SharedStore ───\n\nexport interface SharedStoreApi {\n\tput(key: string, value: unknown): void;\n\tget<T = unknown>(key: string): T | undefined;\n\thas(key: string): boolean;\n\tdelete(key: string): void;\n\tentries(): Array<[string, unknown]>;\n}\n\n// ─── Checkpoint (gate humano) ───\n\nexport interface CheckpointOptions {\n\tdefault?: unknown;\n\theadless?: \"default\" | \"abort\";\n\tkind?: \"confirm\" | \"input\" | \"select\";\n\tchoices?: string[];\n}\n\n// ─── API del script (lo que recibe la función del vm) ───\n\nexport interface WorkflowApi {\n\tagent(options: AgentRunOptions): Promise<unknown>;\n\tparallel<R>(fns: Array<() => Promise<R>>): Promise<Array<Awaited<R>>>;\n\tpipeline<R>(fns: Array<(prev?: Awaited<R>) => Promise<R>>): Promise<Awaited<R>>;\n\tphase(title: string, detail?: string): void;\n\tstore: SharedStoreApi;\n\tcheckpoint<T>(promptText: string, options?: CheckpointOptions): Promise<T>;\n\targs: Record<string, unknown>;\n\tcwd: string;\n\trunId: string;\n\tlog(message: string): void;\n}\n\n// ─── Resultado del run ───\n\nexport interface WorkflowRunResult<T = unknown> {\n\tmeta: WorkflowMeta;\n\tresult: T;\n\tlogs: string[];\n\tphases: string[];\n\tagentCount: number;\n\tdurationMs: number;\n\trunId: string;\n\ttokenUsage: {\n\t\tinput: number;\n\t\toutput: number;\n\t\ttotal: number;\n\t\tcost: number;\n\t\tcacheRead?: number;\n\t\tcacheWrite?: number;\n\t};\n}\n\n// ─── Errores ───\n\nexport type WorkflowErrorCode =\n\t| \"WORKFLOW_INVALID_SCRIPT\"\n\t| \"WORKFLOW_SCRIPT_TIMEOUT\"\n\t| \"WORKFLOW_AGENT_TIMEOUT\"\n\t| \"WORKFLOW_MAX_AGENTS\"\n\t| \"WORKFLOW_ABORTED\"\n\t| \"WORKFLOW_BUDGET_EXCEEDED\"\n\t| \"WORKFLOW_RESUME_CORRUPT\"\n\t| \"MODEL_NOT_FOUND\";\n\nexport class WorkflowError extends Error {\n\treadonly code: WorkflowErrorCode;\n\treadonly recoverable: boolean;\n\n\tconstructor(code: WorkflowErrorCode, message: string, options: { recoverable?: boolean } = {}) {\n\t\tsuper(message);\n\t\tthis.name = \"WorkflowError\";\n\t\tthis.code = code;\n\t\tthis.recoverable = options.recoverable ?? true;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ada Intelligence Engine — shared types (Fase 1).
|
|
3
|
+
*
|
|
4
|
+
* Workflows dinámicos: scripts JS en sandbox vm con agent/parallel/pipeline/
|
|
5
|
+
* store/phase/workflow/checkpoint; subagentes via AgentSessionRuntime; journal
|
|
6
|
+
* con resume determinista; SharedStore con deltas por agente.
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_WORKFLOW_LIMITS = {
|
|
9
|
+
maxAgentsPerRun: 100,
|
|
10
|
+
maxConcurrency: 4,
|
|
11
|
+
maxRetries: 3,
|
|
12
|
+
agentTimeoutMs: 30 * 60 * 1000, // 30 min (Kimi Code alineado)
|
|
13
|
+
scriptTimeoutMs: 5 * 60 * 1000, // 5 min
|
|
14
|
+
drainTimeoutMs: 30_000,
|
|
15
|
+
};
|
|
16
|
+
export class WorkflowError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
recoverable;
|
|
19
|
+
constructor(code, message, options = {}) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "WorkflowError";
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.recoverable = options.recoverable ?? true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/workflows/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAmCH,MAAM,CAAC,MAAM,uBAAuB,GAAmB;IACtD,eAAe,EAAE,GAAG;IACpB,cAAc,EAAE,CAAC;IACjB,UAAU,EAAE,CAAC;IACb,cAAc,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,8BAA8B;IAC9D,eAAe,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,QAAQ;IACxC,cAAc,EAAE,MAAM;CACtB,CAAC;AAsIF,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC9B,IAAI,CAAoB;IACxB,WAAW,CAAU;IAE9B,YAAY,IAAuB,EAAE,OAAe,EAAE,OAAO,GAA8B,EAAE,EAAE;QAC9F,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC;IAAA,CAC/C;CACD","sourcesContent":["/**\n * Ada Intelligence Engine — shared types (Fase 1).\n *\n * Workflows dinámicos: scripts JS en sandbox vm con agent/parallel/pipeline/\n * store/phase/workflow/checkpoint; subagentes via AgentSessionRuntime; journal\n * con resume determinista; SharedStore con deltas por agente.\n */\n\nimport type { TSchema } from \"typebox\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\n\n// ─── Meta y fases ───\n\nexport interface WorkflowPhase {\n\ttitle: string;\n\tdetail?: string;\n\tmodel?: string;\n}\n\nexport interface WorkflowMeta {\n\tname: string;\n\tdescription: string;\n\tphases?: WorkflowPhase[];\n\t/** Modelo por defecto para agentes sin ruta de fase ni model/tier. */\n\tmodel?: string;\n}\n\n// ─── Límites ───\n\nexport interface WorkflowLimits {\n\tmaxAgentsPerRun: number;\n\tmaxConcurrency: number;\n\tmaxRetries: number;\n\t/** Timeout por agente en ms; null = sin timeout. */\n\tagentTimeoutMs: number | null;\n\t/** Timeout del script vm en ms. */\n\tscriptTimeoutMs: number;\n\t/** Timeout del drain de agentes in-flight en ms (finito — adversarial B). */\n\tdrainTimeoutMs: number;\n}\n\nexport const DEFAULT_WORKFLOW_LIMITS: WorkflowLimits = {\n\tmaxAgentsPerRun: 100,\n\tmaxConcurrency: 4,\n\tmaxRetries: 3,\n\tagentTimeoutMs: 30 * 60 * 1000, // 30 min (Kimi Code alineado)\n\tscriptTimeoutMs: 5 * 60 * 1000, // 5 min\n\tdrainTimeoutMs: 30_000,\n};\n\n// ─── Subagente ───\n\nexport interface AgentRunOptions<TSchemaDef extends TSchema | undefined = TSchema | undefined> {\n\tprompt: string; // OBLIGATORIO\n\tlabel?: string; // nombre en la UI y nombre de la sesión del subagente\n\t/** Modelo \"provider/model\" o \"model\" — MODEL_NOT_FOUND si no resuelve. */\n\tmodel?: string;\n\t/** Tier (\"small\"|\"medium\"|\"big\") con fallback al modelo de sesión. */\n\ttier?: string;\n\t/** Fase actual (routing + UI). */\n\tphase?: string;\n\t/** Structured output (typebox). */\n\tschema?: TSchemaDef;\n\t/** Tools extra (web_search/web_fetch…). Se AÑADEN a las del agente. */\n\ttools?: ToolDefinition[];\n\t/**\n\t * Mínimo privilegio: el agente solo puede leer (`read`/`grep`/`find`/`ls`).\n\t * Para fases de análisis que no deben poder escribir ni ejecutar comandos.\n\t * No es un sandbox de SO — acota las tools del subagente, nada más.\n\t */\n\treadOnly?: boolean;\n\tinstructions?: string;\n\t/** Aislamiento git. */\n\tisolation?: \"none\" | \"worktree\";\n\t/** Clave determinista del worktree (runId:callIndex) — la pone el runtime. */\n\tisolationKey?: string;\n\ttimeoutMs?: number | null;\n\tsignal?: AbortSignal;\n\t/** Clave estable para cache/resume (el autor declara idempotencia). */\n\tstableKey?: string;\n\t/** cwd del agente (base o worktree). Default: cwd del run. */\n\tcwd?: string;\n}\n\nexport interface AgentUsage {\n\tinput: number;\n\toutput: number;\n\ttotal: number;\n\tcost: number;\n\tcacheRead?: number;\n\tcacheWrite?: number;\n}\n\nexport interface AgentRunResult<T = unknown> {\n\tresult: T | null;\n\ttext: string;\n\tusage: AgentUsage;\n\tsessionId?: string;\n\t/** Rama `ada/wf/*` con el trabajo del agente, si corrió aislado y escribió. */\n\tworktreeBranch?: string;\n}\n\n// ─── Journal ───\n\nexport interface JournalEntry {\n\tindex: number;\n\trunId?: string;\n\t/** sha256 de la identidad (prompt+model+phase+schema+stableKey). */\n\thash: string;\n\tresult: unknown;\n\t/** Deltas del store escritos por este agente (replay aditivo). */\n\tstoreDelta?: Record<string, unknown>;\n\t/** Marcado cuando el resultado vino de extracción de prosa (fallback schema). */\n\torigin?: \"structured\" | \"recovered\";\n}\n\n// ─── SharedStore ───\n\nexport interface SharedStoreApi {\n\tput(key: string, value: unknown): void;\n\tget<T = unknown>(key: string): T | undefined;\n\thas(key: string): boolean;\n\tdelete(key: string): void;\n\tentries(): Array<[string, unknown]>;\n}\n\n// ─── Checkpoint (gate humano) ───\n\nexport interface CheckpointOptions {\n\tdefault?: unknown;\n\theadless?: \"default\" | \"abort\";\n\tkind?: \"confirm\" | \"input\" | \"select\";\n\tchoices?: string[];\n}\n\n// ─── API del script (lo que recibe la función del vm) ───\n\nexport interface WorkflowApi {\n\tagent(options: AgentRunOptions): Promise<unknown>;\n\tparallel<R>(fns: Array<() => Promise<R>>): Promise<Array<Awaited<R>>>;\n\tpipeline<R>(fns: Array<(prev?: Awaited<R>) => Promise<R>>): Promise<Awaited<R>>;\n\tphase(title: string, detail?: string): void;\n\tstore: SharedStoreApi;\n\tcheckpoint<T>(promptText: string, options?: CheckpointOptions): Promise<T>;\n\targs: Record<string, unknown>;\n\tcwd: string;\n\trunId: string;\n\tlog(message: string): void;\n}\n\n// ─── Resultado del run ───\n\nexport interface WorkflowRunResult<T = unknown> {\n\tmeta: WorkflowMeta;\n\tresult: T;\n\tlogs: string[];\n\tphases: string[];\n\tagentCount: number;\n\tdurationMs: number;\n\trunId: string;\n\ttokenUsage: {\n\t\tinput: number;\n\t\toutput: number;\n\t\ttotal: number;\n\t\tcost: number;\n\t\tcacheRead?: number;\n\t\tcacheWrite?: number;\n\t};\n}\n\n// ─── Errores ───\n\nexport type WorkflowErrorCode =\n\t| \"WORKFLOW_INVALID_SCRIPT\"\n\t| \"WORKFLOW_SCRIPT_TIMEOUT\"\n\t| \"WORKFLOW_AGENT_TIMEOUT\"\n\t| \"WORKFLOW_MAX_AGENTS\"\n\t| \"WORKFLOW_ABORTED\"\n\t| \"WORKFLOW_BUDGET_EXCEEDED\"\n\t| \"WORKFLOW_RESUME_CORRUPT\"\n\t| \"MODEL_NOT_FOUND\";\n\nexport class WorkflowError extends Error {\n\treadonly code: WorkflowErrorCode;\n\treadonly recoverable: boolean;\n\n\tconstructor(code: WorkflowErrorCode, message: string, options: { recoverable?: boolean } = {}) {\n\t\tsuper(message);\n\t\tthis.name = \"WorkflowError\";\n\t\tthis.code = code;\n\t\tthis.recoverable = options.recoverable ?? true;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worktree — aislamiento git por agente.
|
|
3
|
+
*
|
|
4
|
+
* Cuando un agente pide `isolation: "worktree"` (o tiene tools de escritura),
|
|
5
|
+
* corre en un worktree desechable sobre su propia rama: los subagentes pueden
|
|
6
|
+
* editar los mismos archivos sin conflicto. El nombre es determinista
|
|
7
|
+
* (runId+callIndex) para que el resume reencuentre el mismo worktree.
|
|
8
|
+
* Sin auto-merge: la ruta se expone al caller. Limpieza best-effort.
|
|
9
|
+
*/
|
|
10
|
+
export interface Worktree {
|
|
11
|
+
/** True cuando se creó un worktree real; false = corrió en el árbol compartido. */
|
|
12
|
+
isolated: boolean;
|
|
13
|
+
/** cwd del agente (worktree cuando aislado, si no el base). */
|
|
14
|
+
cwd: string;
|
|
15
|
+
branch?: string;
|
|
16
|
+
repoRoot?: string;
|
|
17
|
+
reason?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Crea un worktree aislado bajo `<repoRoot>/.ada/worktrees/<name>` en la rama
|
|
21
|
+
* `ada/wf/<name>`. Fallback a no-op (árbol compartido) ante cualquier fallo.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createWorktree(baseCwd: string, name: string): Promise<Worktree>;
|
|
24
|
+
/**
|
|
25
|
+
* Cierra un worktree CONSERVANDO el trabajo: commitea lo que haya en su rama y
|
|
26
|
+
* retira solo el directorio.
|
|
27
|
+
*
|
|
28
|
+
* Retirar el worktree sin más borraría los cambios sin commitear del agente, y
|
|
29
|
+
* entonces el aislamiento no serviría de nada: los escritores paralelos no
|
|
30
|
+
* chocarían, pero su trabajo se perdería igual. Sin auto-merge a propósito — la
|
|
31
|
+
* rama queda para que un humano la revise (`git branch --list 'ada/wf/*'`).
|
|
32
|
+
*
|
|
33
|
+
* Si el agente no tocó nada (p.ej. una fase de análisis de solo lectura), borra
|
|
34
|
+
* también la rama: no hay nada que conservar y las ramas vacías son ruido.
|
|
35
|
+
*/
|
|
36
|
+
export declare function finalizeWorktree(wt: Worktree, message: string): Promise<{
|
|
37
|
+
branch?: string;
|
|
38
|
+
kept: boolean;
|
|
39
|
+
}>;
|
|
40
|
+
/** Elimina un worktree y su rama, DESCARTANDO el trabajo. Best-effort. */
|
|
41
|
+
export declare function removeWorktree(wt: Worktree): Promise<void>;
|
|
42
|
+
//# sourceMappingURL=worktree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worktree.d.ts","sourceRoot":"","sources":["../../../src/core/workflows/worktree.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,MAAM,WAAW,QAAQ;IACxB,sFAAmF;IACnF,QAAQ,EAAE,OAAO,CAAC;IAClB,+DAA+D;IAC/D,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAYD;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkBrF;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAyBjH;AAED,0EAA0E;AAC1E,wBAAsB,cAAc,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAchE","sourcesContent":["/**\n * Worktree — aislamiento git por agente.\n *\n * Cuando un agente pide `isolation: \"worktree\"` (o tiene tools de escritura),\n * corre en un worktree desechable sobre su propia rama: los subagentes pueden\n * editar los mismos archivos sin conflicto. El nombre es determinista\n * (runId+callIndex) para que el resume reencuentre el mismo worktree.\n * Sin auto-merge: la ruta se expone al caller. Limpieza best-effort.\n */\n\nimport { execFile } from \"node:child_process\";\nimport { join } from \"node:path\";\nimport { promisify } from \"node:util\";\n\n// execFile (no shell): los argumentos van en array, sin interpolar en una cadena.\nconst execFileAsync = promisify(execFile);\n\nexport interface Worktree {\n\t/** True cuando se creó un worktree real; false = corrió en el árbol compartido. */\n\tisolated: boolean;\n\t/** cwd del agente (worktree cuando aislado, si no el base). */\n\tcwd: string;\n\tbranch?: string;\n\trepoRoot?: string;\n\treason?: string;\n}\n\nfunction slug(name: string): string {\n\treturn (\n\t\tname\n\t\t\t.toLowerCase()\n\t\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t\t.replace(/^-+|-+$/g, \"\")\n\t\t\t.slice(0, 48) || \"agent\"\n\t);\n}\n\n/**\n * Crea un worktree aislado bajo `<repoRoot>/.ada/worktrees/<name>` en la rama\n * `ada/wf/<name>`. Fallback a no-op (árbol compartido) ante cualquier fallo.\n */\nexport async function createWorktree(baseCwd: string, name: string): Promise<Worktree> {\n\tconst id = slug(name);\n\tlet repoRoot: string;\n\ttry {\n\t\tconst { stdout } = await execFileAsync(\"git\", [\"-C\", baseCwd, \"rev-parse\", \"--show-toplevel\"]);\n\t\trepoRoot = stdout.trim();\n\t} catch {\n\t\treturn { isolated: false, cwd: baseCwd, reason: \"not a git repository\" };\n\t}\n\n\tconst path = join(repoRoot, \".ada\", \"worktrees\", id);\n\tconst branch = `ada/wf/${id}`;\n\ttry {\n\t\tawait execFileAsync(\"git\", [\"-C\", repoRoot, \"worktree\", \"add\", \"-b\", branch, path, \"HEAD\"]);\n\t\treturn { isolated: true, cwd: path, branch, repoRoot };\n\t} catch (error) {\n\t\treturn { isolated: false, cwd: baseCwd, reason: error instanceof Error ? error.message : String(error) };\n\t}\n}\n\n/**\n * Cierra un worktree CONSERVANDO el trabajo: commitea lo que haya en su rama y\n * retira solo el directorio.\n *\n * Retirar el worktree sin más borraría los cambios sin commitear del agente, y\n * entonces el aislamiento no serviría de nada: los escritores paralelos no\n * chocarían, pero su trabajo se perdería igual. Sin auto-merge a propósito — la\n * rama queda para que un humano la revise (`git branch --list 'ada/wf/*'`).\n *\n * Si el agente no tocó nada (p.ej. una fase de análisis de solo lectura), borra\n * también la rama: no hay nada que conservar y las ramas vacías son ruido.\n */\nexport async function finalizeWorktree(wt: Worktree, message: string): Promise<{ branch?: string; kept: boolean }> {\n\tif (!wt.isolated || !wt.repoRoot) return { kept: false };\n\tlet kept = false;\n\ttry {\n\t\tawait execFileAsync(\"git\", [\"-C\", wt.cwd, \"add\", \"-A\"]);\n\t\t// `commit` sale distinto de 0 cuando no hay nada que commitear; eso no es\n\t\t// un error, es el camino normal de un agente que no escribió.\n\t\tawait execFileAsync(\"git\", [\"-C\", wt.cwd, \"commit\", \"-m\", message]);\n\t\tkept = true;\n\t} catch {\n\t\tkept = false;\n\t}\n\ttry {\n\t\tawait execFileAsync(\"git\", [\"-C\", wt.repoRoot, \"worktree\", \"remove\", \"--force\", wt.cwd]);\n\t} catch {\n\t\t// ya no existe / locked — continuar\n\t}\n\tif (!kept && wt.branch) {\n\t\ttry {\n\t\t\tawait execFileAsync(\"git\", [\"-C\", wt.repoRoot, \"branch\", \"-D\", wt.branch]);\n\t\t} catch {\n\t\t\t// rama ya borrada\n\t\t}\n\t}\n\treturn { branch: kept ? wt.branch : undefined, kept };\n}\n\n/** Elimina un worktree y su rama, DESCARTANDO el trabajo. Best-effort. */\nexport async function removeWorktree(wt: Worktree): Promise<void> {\n\tif (!wt.isolated || !wt.repoRoot) return;\n\ttry {\n\t\tawait execFileAsync(\"git\", [\"-C\", wt.repoRoot, \"worktree\", \"remove\", \"--force\", wt.cwd]);\n\t} catch {\n\t\t// ya no existe / locked — continuar\n\t}\n\tif (wt.branch) {\n\t\ttry {\n\t\t\tawait execFileAsync(\"git\", [\"-C\", wt.repoRoot, \"branch\", \"-D\", wt.branch]);\n\t\t} catch {\n\t\t\t// rama ya borrada\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worktree — aislamiento git por agente.
|
|
3
|
+
*
|
|
4
|
+
* Cuando un agente pide `isolation: "worktree"` (o tiene tools de escritura),
|
|
5
|
+
* corre en un worktree desechable sobre su propia rama: los subagentes pueden
|
|
6
|
+
* editar los mismos archivos sin conflicto. El nombre es determinista
|
|
7
|
+
* (runId+callIndex) para que el resume reencuentre el mismo worktree.
|
|
8
|
+
* Sin auto-merge: la ruta se expone al caller. Limpieza best-effort.
|
|
9
|
+
*/
|
|
10
|
+
import { execFile } from "node:child_process";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { promisify } from "node:util";
|
|
13
|
+
// execFile (no shell): los argumentos van en array, sin interpolar en una cadena.
|
|
14
|
+
const execFileAsync = promisify(execFile);
|
|
15
|
+
function slug(name) {
|
|
16
|
+
return (name
|
|
17
|
+
.toLowerCase()
|
|
18
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
19
|
+
.replace(/^-+|-+$/g, "")
|
|
20
|
+
.slice(0, 48) || "agent");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Crea un worktree aislado bajo `<repoRoot>/.ada/worktrees/<name>` en la rama
|
|
24
|
+
* `ada/wf/<name>`. Fallback a no-op (árbol compartido) ante cualquier fallo.
|
|
25
|
+
*/
|
|
26
|
+
export async function createWorktree(baseCwd, name) {
|
|
27
|
+
const id = slug(name);
|
|
28
|
+
let repoRoot;
|
|
29
|
+
try {
|
|
30
|
+
const { stdout } = await execFileAsync("git", ["-C", baseCwd, "rev-parse", "--show-toplevel"]);
|
|
31
|
+
repoRoot = stdout.trim();
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return { isolated: false, cwd: baseCwd, reason: "not a git repository" };
|
|
35
|
+
}
|
|
36
|
+
const path = join(repoRoot, ".ada", "worktrees", id);
|
|
37
|
+
const branch = `ada/wf/${id}`;
|
|
38
|
+
try {
|
|
39
|
+
await execFileAsync("git", ["-C", repoRoot, "worktree", "add", "-b", branch, path, "HEAD"]);
|
|
40
|
+
return { isolated: true, cwd: path, branch, repoRoot };
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return { isolated: false, cwd: baseCwd, reason: error instanceof Error ? error.message : String(error) };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Cierra un worktree CONSERVANDO el trabajo: commitea lo que haya en su rama y
|
|
48
|
+
* retira solo el directorio.
|
|
49
|
+
*
|
|
50
|
+
* Retirar el worktree sin más borraría los cambios sin commitear del agente, y
|
|
51
|
+
* entonces el aislamiento no serviría de nada: los escritores paralelos no
|
|
52
|
+
* chocarían, pero su trabajo se perdería igual. Sin auto-merge a propósito — la
|
|
53
|
+
* rama queda para que un humano la revise (`git branch --list 'ada/wf/*'`).
|
|
54
|
+
*
|
|
55
|
+
* Si el agente no tocó nada (p.ej. una fase de análisis de solo lectura), borra
|
|
56
|
+
* también la rama: no hay nada que conservar y las ramas vacías son ruido.
|
|
57
|
+
*/
|
|
58
|
+
export async function finalizeWorktree(wt, message) {
|
|
59
|
+
if (!wt.isolated || !wt.repoRoot)
|
|
60
|
+
return { kept: false };
|
|
61
|
+
let kept = false;
|
|
62
|
+
try {
|
|
63
|
+
await execFileAsync("git", ["-C", wt.cwd, "add", "-A"]);
|
|
64
|
+
// `commit` sale distinto de 0 cuando no hay nada que commitear; eso no es
|
|
65
|
+
// un error, es el camino normal de un agente que no escribió.
|
|
66
|
+
await execFileAsync("git", ["-C", wt.cwd, "commit", "-m", message]);
|
|
67
|
+
kept = true;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
kept = false;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
await execFileAsync("git", ["-C", wt.repoRoot, "worktree", "remove", "--force", wt.cwd]);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// ya no existe / locked — continuar
|
|
77
|
+
}
|
|
78
|
+
if (!kept && wt.branch) {
|
|
79
|
+
try {
|
|
80
|
+
await execFileAsync("git", ["-C", wt.repoRoot, "branch", "-D", wt.branch]);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
// rama ya borrada
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { branch: kept ? wt.branch : undefined, kept };
|
|
87
|
+
}
|
|
88
|
+
/** Elimina un worktree y su rama, DESCARTANDO el trabajo. Best-effort. */
|
|
89
|
+
export async function removeWorktree(wt) {
|
|
90
|
+
if (!wt.isolated || !wt.repoRoot)
|
|
91
|
+
return;
|
|
92
|
+
try {
|
|
93
|
+
await execFileAsync("git", ["-C", wt.repoRoot, "worktree", "remove", "--force", wt.cwd]);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// ya no existe / locked — continuar
|
|
97
|
+
}
|
|
98
|
+
if (wt.branch) {
|
|
99
|
+
try {
|
|
100
|
+
await execFileAsync("git", ["-C", wt.repoRoot, "branch", "-D", wt.branch]);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// rama ya borrada
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=worktree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worktree.js","sourceRoot":"","sources":["../../../src/core/workflows/worktree.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,kFAAkF;AAClF,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAY1C,SAAS,IAAI,CAAC,IAAY,EAAU;IACnC,OAAO,CACN,IAAI;SACF,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,OAAO,CACzB,CAAC;AAAA,CACF;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAe,EAAE,IAAY,EAAqB;IACtF,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IACtB,IAAI,QAAgB,CAAC;IACrB,IAAI,CAAC;QACJ,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,iBAAiB,C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,CAAC;IAC1F,CAAC;IAAC,MAAM,CAAC;QACR,sCAAoC;IACrC,CAAC;IACD,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;QACf,IAAI,CAAC;YACJ,MAAM,aAAa,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5E,CAAC;QAAC,MAAM,CAAC;YACR,kBAAkB;QACnB,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["/**\n * Worktree — aislamiento git por agente.\n *\n * Cuando un agente pide `isolation: \"worktree\"` (o tiene tools de escritura),\n * corre en un worktree desechable sobre su propia rama: los subagentes pueden\n * editar los mismos archivos sin conflicto. El nombre es determinista\n * (runId+callIndex) para que el resume reencuentre el mismo worktree.\n * Sin auto-merge: la ruta se expone al caller. Limpieza best-effort.\n */\n\nimport { execFile } from \"node:child_process\";\nimport { join } from \"node:path\";\nimport { promisify } from \"node:util\";\n\n// execFile (no shell): los argumentos van en array, sin interpolar en una cadena.\nconst execFileAsync = promisify(execFile);\n\nexport interface Worktree {\n\t/** True cuando se creó un worktree real; false = corrió en el árbol compartido. */\n\tisolated: boolean;\n\t/** cwd del agente (worktree cuando aislado, si no el base). */\n\tcwd: string;\n\tbranch?: string;\n\trepoRoot?: string;\n\treason?: string;\n}\n\nfunction slug(name: string): string {\n\treturn (\n\t\tname\n\t\t\t.toLowerCase()\n\t\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t\t.replace(/^-+|-+$/g, \"\")\n\t\t\t.slice(0, 48) || \"agent\"\n\t);\n}\n\n/**\n * Crea un worktree aislado bajo `<repoRoot>/.ada/worktrees/<name>` en la rama\n * `ada/wf/<name>`. Fallback a no-op (árbol compartido) ante cualquier fallo.\n */\nexport async function createWorktree(baseCwd: string, name: string): Promise<Worktree> {\n\tconst id = slug(name);\n\tlet repoRoot: string;\n\ttry {\n\t\tconst { stdout } = await execFileAsync(\"git\", [\"-C\", baseCwd, \"rev-parse\", \"--show-toplevel\"]);\n\t\trepoRoot = stdout.trim();\n\t} catch {\n\t\treturn { isolated: false, cwd: baseCwd, reason: \"not a git repository\" };\n\t}\n\n\tconst path = join(repoRoot, \".ada\", \"worktrees\", id);\n\tconst branch = `ada/wf/${id}`;\n\ttry {\n\t\tawait execFileAsync(\"git\", [\"-C\", repoRoot, \"worktree\", \"add\", \"-b\", branch, path, \"HEAD\"]);\n\t\treturn { isolated: true, cwd: path, branch, repoRoot };\n\t} catch (error) {\n\t\treturn { isolated: false, cwd: baseCwd, reason: error instanceof Error ? error.message : String(error) };\n\t}\n}\n\n/**\n * Cierra un worktree CONSERVANDO el trabajo: commitea lo que haya en su rama y\n * retira solo el directorio.\n *\n * Retirar el worktree sin más borraría los cambios sin commitear del agente, y\n * entonces el aislamiento no serviría de nada: los escritores paralelos no\n * chocarían, pero su trabajo se perdería igual. Sin auto-merge a propósito — la\n * rama queda para que un humano la revise (`git branch --list 'ada/wf/*'`).\n *\n * Si el agente no tocó nada (p.ej. una fase de análisis de solo lectura), borra\n * también la rama: no hay nada que conservar y las ramas vacías son ruido.\n */\nexport async function finalizeWorktree(wt: Worktree, message: string): Promise<{ branch?: string; kept: boolean }> {\n\tif (!wt.isolated || !wt.repoRoot) return { kept: false };\n\tlet kept = false;\n\ttry {\n\t\tawait execFileAsync(\"git\", [\"-C\", wt.cwd, \"add\", \"-A\"]);\n\t\t// `commit` sale distinto de 0 cuando no hay nada que commitear; eso no es\n\t\t// un error, es el camino normal de un agente que no escribió.\n\t\tawait execFileAsync(\"git\", [\"-C\", wt.cwd, \"commit\", \"-m\", message]);\n\t\tkept = true;\n\t} catch {\n\t\tkept = false;\n\t}\n\ttry {\n\t\tawait execFileAsync(\"git\", [\"-C\", wt.repoRoot, \"worktree\", \"remove\", \"--force\", wt.cwd]);\n\t} catch {\n\t\t// ya no existe / locked — continuar\n\t}\n\tif (!kept && wt.branch) {\n\t\ttry {\n\t\t\tawait execFileAsync(\"git\", [\"-C\", wt.repoRoot, \"branch\", \"-D\", wt.branch]);\n\t\t} catch {\n\t\t\t// rama ya borrada\n\t\t}\n\t}\n\treturn { branch: kept ? wt.branch : undefined, kept };\n}\n\n/** Elimina un worktree y su rama, DESCARTANDO el trabajo. Best-effort. */\nexport async function removeWorktree(wt: Worktree): Promise<void> {\n\tif (!wt.isolated || !wt.repoRoot) return;\n\ttry {\n\t\tawait execFileAsync(\"git\", [\"-C\", wt.repoRoot, \"worktree\", \"remove\", \"--force\", wt.cwd]);\n\t} catch {\n\t\t// ya no existe / locked — continuar\n\t}\n\tif (wt.branch) {\n\t\ttry {\n\t\t\tawait execFileAsync(\"git\", [\"-C\", wt.repoRoot, \"branch\", \"-D\", wt.branch]);\n\t\t} catch {\n\t\t\t// rama ya borrada\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/llama/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAA2B,MAAM,gCAAgC,CAAC;AAyC5F,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/llama/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAA2B,MAAM,gCAAgC,CAAC;AAyC5F,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CA4L7D","sourcesContent":["import type { ExtensionAPI, ExtensionCommandContext } from \"../../core/extensions/types.ts\";\nimport { formatBytes, LlamaClient, type LlamaModelInfo, normalizeLlamaServerUrl } from \"./client.ts\";\nimport { findHuggingFaceToken, HuggingFaceClient } from \"./huggingface.ts\";\nimport { createLlamaProvider, LLAMA_PROVIDER_ID } from \"./provider.ts\";\nimport { type LlamaUi, runWithProgress, showLlamaUi } from \"./ui.ts\";\n\nfunction modelIsLoaded(model: LlamaModelInfo): boolean {\n\treturn model.status.value === \"loaded\" || model.status.value === \"sleeping\";\n}\n\nfunction isConnectionError(error: unknown): boolean {\n\tif (!(error instanceof Error)) return false;\n\tconst message = `${error.name} ${error.message}`.toLowerCase();\n\treturn message.includes(\"fetch failed\") || message.includes(\"timeout\") || message.includes(\"network\");\n}\n\nfunction connectionErrorMessage(error: unknown): string {\n\tif (isConnectionError(error)) return \"Could not connect to the server.\";\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction parseHuggingFaceModel(value: string): { repository: string; quantization?: string } {\n\tconst colon = value.indexOf(\":\", value.indexOf(\"/\") + 1);\n\treturn colon < 0\n\t\t? { repository: value }\n\t\t: { repository: value.slice(0, colon), quantization: value.slice(colon + 1) };\n}\n\nasync function configuredClient(ctx: ExtensionCommandContext): Promise<LlamaClient | undefined> {\n\tconst result = await ctx.modelRegistry.getProviderAuth(LLAMA_PROVIDER_ID);\n\tif (!result) {\n\t\tctx.ui.notify(`Configure llama.cpp with /login ${LLAMA_PROVIDER_ID}`, \"warning\");\n\t\treturn undefined;\n\t}\n\tconst configuredUrl = result.env?.LLAMA_BASE_URL;\n\tconst serverUrl = normalizeLlamaServerUrl(\n\t\ttypeof configuredUrl === \"string\" && configuredUrl ? configuredUrl : (result.auth.baseUrl ?? \"\"),\n\t);\n\treturn new LlamaClient(serverUrl, result.auth.apiKey);\n}\n\nexport default function llamaExtension(pi: ExtensionAPI): void {\n\tconst provider = createLlamaProvider();\n\tpi.registerProvider(provider.provider);\n\n\tconst syncCatalog = async (\n\t\tctx: ExtensionCommandContext,\n\t\tclient: LlamaClient,\n\t\tcatalog?: LlamaModelInfo[],\n\t): Promise<LlamaModelInfo[]> => {\n\t\tconst signal = AbortSignal.timeout(15_000);\n\t\tconst current = catalog ?? (await client.list({ signal }));\n\t\tprovider.setCatalog(current, client.serverUrl);\n\t\tconst result = await ctx.modelRegistry.refresh({\n\t\t\tproviders: [LLAMA_PROVIDER_ID],\n\t\t\t// /llama already contacted the configured llama.cpp server, so keep this refresh live even in PI_OFFLINE.\n\t\t\tallowNetwork: true,\n\t\t\tsignal,\n\t\t});\n\t\tif (result.aborted) throw new Error(\"Model catalog refresh timed out.\");\n\t\tconst refreshError = result.errors.get(LLAMA_PROVIDER_ID);\n\t\tif (refreshError) throw refreshError;\n\t\treturn current;\n\t};\n\n\tconst loadModel = async (\n\t\tctx: ExtensionCommandContext,\n\t\tui: LlamaUi,\n\t\tclient: LlamaClient,\n\t\tcatalog: LlamaModelInfo[],\n\t\ttarget: LlamaModelInfo,\n\t): Promise<void> => {\n\t\tconst loaded = catalog.filter((model) => model.id !== target.id && modelIsLoaded(model));\n\t\tlet replace = false;\n\t\tif (loaded.length > 0) {\n\t\t\tconst choice = await ui.select(`${loaded.length} model${loaded.length === 1 ? \" is\" : \"s are\"} loaded`, [\n\t\t\t\t\"Unload all and load\",\n\t\t\t\t\"Keep loaded and load\",\n\t\t\t\t\"Cancel\",\n\t\t\t]);\n\t\t\tif (!choice || choice === \"Cancel\") return;\n\t\t\treplace = choice === \"Unload all and load\";\n\t\t}\n\n\t\tconst restoreLoaded = async (): Promise<void> => {\n\t\t\tctx.ui.notify(\"Restoring previously loaded models\");\n\t\t\tfor (const model of loaded) await client.loadAndWait(model.id, () => {});\n\t\t\tawait syncCatalog(ctx, client);\n\t\t};\n\t\tif (replace) {\n\t\t\tfor (const model of loaded) await client.unloadAndWait(model.id);\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await runWithProgress(ui, {\n\t\t\t\ttitle: \"Loading model\",\n\t\t\t\tmodel: target.id,\n\t\t\t\tinitialMessage: \"Starting…\",\n\t\t\t\tcancelTitle: \"Stop loading?\",\n\t\t\t\tcancelMessage: target.id,\n\t\t\t\trun: (signal, update) => client.loadAndWait(target.id, update, signal),\n\t\t\t\tcancel: () => client.unload(target.id),\n\t\t\t});\n\t\t\tif (result.cancelled) {\n\t\t\t\tif (replace) await restoreLoaded();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst refreshed = await syncCatalog(ctx, client);\n\t\t\tconst loadedModel = refreshed.find((model) => model.id === target.id);\n\t\t\tctx.ui.notify(\n\t\t\t\tloadedModel?.status.value === \"loaded\" ? `Loaded ${target.id}` : `Load started for ${target.id}`,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (replace) {\n\t\t\t\ttry {\n\t\t\t\t\tawait restoreLoaded();\n\t\t\t\t} catch {\n\t\t\t\t\t// Preserve the original load error.\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t};\n\n\tconst unloadModel = async (\n\t\tctx: ExtensionCommandContext,\n\t\tui: LlamaUi,\n\t\tclient: LlamaClient,\n\t\tmodel: LlamaModelInfo,\n\t): Promise<void> => {\n\t\tif (!(await ui.confirm(\"Unload model?\", model.id))) return;\n\t\tawait client.unloadAndWait(model.id);\n\t\tawait syncCatalog(ctx, client);\n\t\tctx.ui.notify(`Unloaded ${model.id}`);\n\t};\n\n\tconst downloadModel = async (ctx: ExtensionCommandContext, ui: LlamaUi, client: LlamaClient): Promise<void> => {\n\t\tconst huggingFace = new HuggingFaceClient(await findHuggingFaceToken());\n\t\tconst selected = await ui.searchModels((query, signal) => huggingFace.search(query, signal));\n\t\tif (!selected) return;\n\t\tconst parsed = parseHuggingFaceModel(selected);\n\t\tui.showStatus(\"Loading model details\", parsed.repository);\n\t\tconst details = await huggingFace.details(parsed.repository);\n\t\tif (details.gated) {\n\t\t\tconst approval = details.gated === \"manual\" ? \"Manual approval is required\" : \"Accept the access terms\";\n\t\t\tconst choice = await ui.select(\n\t\t\t\t`Hugging Face access required\\n${details.id}\\n\\n${approval} at:\\nhttps://huggingface.co/${details.id}\\n\\nThe llama.cpp server needs HF_TOKEN with access.`,\n\t\t\t\t[\"Continue\", \"Back\"],\n\t\t\t);\n\t\t\tif (choice !== \"Continue\") return;\n\t\t}\n\t\tlet quantization = parsed.quantization;\n\t\tif (!quantization && details.quantizations.length > 0) {\n\t\t\tconst options = details.quantizations.map((entry) => {\n\t\t\t\tconst detail = [\n\t\t\t\t\tentry.size === undefined ? undefined : formatBytes(entry.size),\n\t\t\t\t\tentry.name === \"Q4_K_M\" ? \"recommended\" : undefined,\n\t\t\t\t]\n\t\t\t\t\t.filter((value): value is string => Boolean(value))\n\t\t\t\t\t.join(\" · \");\n\t\t\t\treturn detail ? `${entry.name} · ${detail}` : entry.name;\n\t\t\t});\n\t\t\tconst choice = await ui.select(`Select quantization\\n${details.id}`, options);\n\t\t\tif (!choice) return;\n\t\t\tquantization = details.quantizations[options.indexOf(choice)]?.name;\n\t\t\tif (!quantization) return;\n\t\t}\n\t\tconst model = quantization ? `${details.id}:${quantization}` : details.id;\n\t\tconst result = await runWithProgress(ui, {\n\t\t\ttitle: \"Downloading model\",\n\t\t\tmodel,\n\t\t\tinitialMessage: \"Starting…\",\n\t\t\tcancelTitle: \"Stop download?\",\n\t\t\tcancelMessage: model,\n\t\t\trun: (signal, update) => client.downloadAndWait(model, update, signal),\n\t\t\tcancel: () => client.unload(model),\n\t\t});\n\t\tif (result.cancelled) return;\n\t\tawait syncCatalog(ctx, client, result.value);\n\t\tctx.ui.notify(`Downloaded ${model}`);\n\t};\n\n\tpi.registerCommand(\"llama\", {\n\t\tdescription: \"Manage llama.cpp router models\",\n\t\thandler: async (_args, ctx) => {\n\t\t\tif (ctx.mode !== \"tui\") {\n\t\t\t\tctx.ui.notify(\"/llama is available in interactive mode\", \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst client = await configuredClient(ctx);\n\t\t\tif (!client) return;\n\t\t\tawait showLlamaUi(ctx, async (ui) => {\n\t\t\t\tconst readCatalog = async (): Promise<LlamaModelInfo[] | undefined> => {\n\t\t\t\t\twhile (true) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn await syncCatalog(ctx, client);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif ((await ui.connectionError(client.serverUrl, connectionErrorMessage(error))) === \"close\") {\n\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tlet catalog = await readCatalog();\n\t\t\t\tif (!catalog) return;\n\t\t\t\twhile (true) {\n\t\t\t\t\tconst action = await ui.showModels(client.serverUrl, catalog);\n\t\t\t\t\tif (action.type === \"close\") return;\n\t\t\t\t\tlet actionError: unknown;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (action.type === \"download\") await downloadModel(ctx, ui, client);\n\t\t\t\t\t\telse if (modelIsLoaded(action.model)) await unloadModel(ctx, ui, client, action.model);\n\t\t\t\t\t\telse if (action.model.status.value === \"unloaded\")\n\t\t\t\t\t\t\tawait loadModel(ctx, ui, client, catalog, action.model);\n\t\t\t\t\t\telse ctx.ui.notify(`${action.model.id} is ${action.model.status.value}`, \"warning\");\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tactionError = error;\n\t\t\t\t\t}\n\t\t\t\t\tconst refreshed = await readCatalog();\n\t\t\t\t\tif (!refreshed) return;\n\t\t\t\t\tcatalog = refreshed;\n\t\t\t\t\tif (actionError && !isConnectionError(actionError)) {\n\t\t\t\t\t\tctx.ui.notify(actionError instanceof Error ? actionError.message : String(actionError), \"error\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t});\n}\n"]}
|
|
@@ -41,6 +41,8 @@ export default function llamaExtension(pi) {
|
|
|
41
41
|
provider.setCatalog(current, client.serverUrl);
|
|
42
42
|
const result = await ctx.modelRegistry.refresh({
|
|
43
43
|
providers: [LLAMA_PROVIDER_ID],
|
|
44
|
+
// /llama already contacted the configured llama.cpp server, so keep this refresh live even in PI_OFFLINE.
|
|
45
|
+
allowNetwork: true,
|
|
44
46
|
signal,
|
|
45
47
|
});
|
|
46
48
|
if (result.aborted)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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E,EAAE,EAAE,MAAM,CAAC,CAAC;6BAChE,IAAI,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC;4BAAE,MAAM,WAAW,CAAC,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;6BAClF,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,UAAU;4BAChD,MAAM,SAAS,CAAC,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;;4BACpD,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAC;oBACrF,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBAChB,WAAW,GAAG,KAAK,CAAC;oBACrB,CAAC;oBACD,MAAM,SAAS,GAAG,MAAM,WAAW,EAAE,CAAC;oBACtC,IAAI,CAAC,SAAS;wBAAE,OAAO;oBACvB,OAAO,GAAG,SAAS,CAAC;oBACpB,IAAI,WAAW,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,EAAE,CAAC;wBACpD,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,YAAY,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,CAAC;oBAClG,CAAC;gBACF,CAAC;YAAA,CACD,CAAC,CAAC;QAAA,CACH;KACD,CAAC,CAAC;AAAA,CACH","sourcesContent":["import type { ExtensionAPI, ExtensionCommandContext } from \"../../core/extensions/types.ts\";\nimport { formatBytes, LlamaClient, type LlamaModelInfo, normalizeLlamaServerUrl } from \"./client.ts\";\nimport { findHuggingFaceToken, HuggingFaceClient } from \"./huggingface.ts\";\nimport { createLlamaProvider, LLAMA_PROVIDER_ID } from \"./provider.ts\";\nimport { type LlamaUi, runWithProgress, showLlamaUi } from \"./ui.ts\";\n\nfunction modelIsLoaded(model: LlamaModelInfo): boolean {\n\treturn model.status.value === \"loaded\" || model.status.value === \"sleeping\";\n}\n\nfunction isConnectionError(error: unknown): boolean {\n\tif (!(error instanceof Error)) return false;\n\tconst message = `${error.name} ${error.message}`.toLowerCase();\n\treturn message.includes(\"fetch failed\") || message.includes(\"timeout\") || message.includes(\"network\");\n}\n\nfunction connectionErrorMessage(error: unknown): string {\n\tif (isConnectionError(error)) return \"Could not connect to the server.\";\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction parseHuggingFaceModel(value: string): { repository: string; quantization?: string } {\n\tconst colon = value.indexOf(\":\", value.indexOf(\"/\") + 1);\n\treturn colon < 0\n\t\t? { repository: value }\n\t\t: { repository: value.slice(0, colon), quantization: value.slice(colon + 1) };\n}\n\nasync function configuredClient(ctx: ExtensionCommandContext): Promise<LlamaClient | undefined> {\n\tconst result = await ctx.modelRegistry.getProviderAuth(LLAMA_PROVIDER_ID);\n\tif (!result) {\n\t\tctx.ui.notify(`Configure llama.cpp with /login ${LLAMA_PROVIDER_ID}`, \"warning\");\n\t\treturn undefined;\n\t}\n\tconst configuredUrl = result.env?.LLAMA_BASE_URL;\n\tconst serverUrl = normalizeLlamaServerUrl(\n\t\ttypeof configuredUrl === \"string\" && configuredUrl ? configuredUrl : (result.auth.baseUrl ?? \"\"),\n\t);\n\treturn new LlamaClient(serverUrl, result.auth.apiKey);\n}\n\nexport default function llamaExtension(pi: ExtensionAPI): void {\n\tconst provider = createLlamaProvider();\n\tpi.registerProvider(provider.provider);\n\n\tconst syncCatalog = async (\n\t\tctx: ExtensionCommandContext,\n\t\tclient: LlamaClient,\n\t\tcatalog?: LlamaModelInfo[],\n\t): Promise<LlamaModelInfo[]> => {\n\t\tconst signal = AbortSignal.timeout(15_000);\n\t\tconst current = catalog ?? (await client.list({ signal }));\n\t\tprovider.setCatalog(current, client.serverUrl);\n\t\tconst result = await ctx.modelRegistry.refresh({\n\t\t\tproviders: [LLAMA_PROVIDER_ID],\n\t\t\tsignal,\n\t\t});\n\t\tif (result.aborted) throw new Error(\"Model catalog refresh timed out.\");\n\t\tconst refreshError = result.errors.get(LLAMA_PROVIDER_ID);\n\t\tif (refreshError) throw refreshError;\n\t\treturn current;\n\t};\n\n\tconst loadModel = async (\n\t\tctx: ExtensionCommandContext,\n\t\tui: LlamaUi,\n\t\tclient: LlamaClient,\n\t\tcatalog: LlamaModelInfo[],\n\t\ttarget: LlamaModelInfo,\n\t): Promise<void> => {\n\t\tconst loaded = catalog.filter((model) => model.id !== target.id && modelIsLoaded(model));\n\t\tlet replace = false;\n\t\tif (loaded.length > 0) {\n\t\t\tconst choice = await ui.select(`${loaded.length} model${loaded.length === 1 ? \" is\" : \"s are\"} loaded`, [\n\t\t\t\t\"Unload all and load\",\n\t\t\t\t\"Keep loaded and load\",\n\t\t\t\t\"Cancel\",\n\t\t\t]);\n\t\t\tif (!choice || choice === \"Cancel\") return;\n\t\t\treplace = choice === \"Unload all and load\";\n\t\t}\n\n\t\tconst restoreLoaded = async (): Promise<void> => {\n\t\t\tctx.ui.notify(\"Restoring previously loaded models\");\n\t\t\tfor (const model of loaded) await client.loadAndWait(model.id, () => {});\n\t\t\tawait syncCatalog(ctx, client);\n\t\t};\n\t\tif (replace) {\n\t\t\tfor (const model of loaded) await client.unloadAndWait(model.id);\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await runWithProgress(ui, {\n\t\t\t\ttitle: \"Loading model\",\n\t\t\t\tmodel: target.id,\n\t\t\t\tinitialMessage: \"Starting…\",\n\t\t\t\tcancelTitle: \"Stop loading?\",\n\t\t\t\tcancelMessage: target.id,\n\t\t\t\trun: (signal, update) => client.loadAndWait(target.id, update, signal),\n\t\t\t\tcancel: () => client.unload(target.id),\n\t\t\t});\n\t\t\tif (result.cancelled) {\n\t\t\t\tif (replace) await restoreLoaded();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst refreshed = await syncCatalog(ctx, client);\n\t\t\tconst loadedModel = refreshed.find((model) => model.id === target.id);\n\t\t\tctx.ui.notify(\n\t\t\t\tloadedModel?.status.value === \"loaded\" ? `Loaded ${target.id}` : `Load started for ${target.id}`,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (replace) {\n\t\t\t\ttry {\n\t\t\t\t\tawait restoreLoaded();\n\t\t\t\t} catch {\n\t\t\t\t\t// Preserve the original load error.\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t};\n\n\tconst unloadModel = async (\n\t\tctx: ExtensionCommandContext,\n\t\tui: LlamaUi,\n\t\tclient: LlamaClient,\n\t\tmodel: LlamaModelInfo,\n\t): Promise<void> => {\n\t\tif (!(await ui.confirm(\"Unload model?\", model.id))) return;\n\t\tawait client.unloadAndWait(model.id);\n\t\tawait syncCatalog(ctx, client);\n\t\tctx.ui.notify(`Unloaded ${model.id}`);\n\t};\n\n\tconst downloadModel = async (ctx: ExtensionCommandContext, ui: LlamaUi, client: LlamaClient): Promise<void> => {\n\t\tconst huggingFace = new HuggingFaceClient(await findHuggingFaceToken());\n\t\tconst selected = await ui.searchModels((query, signal) => huggingFace.search(query, signal));\n\t\tif (!selected) return;\n\t\tconst parsed = parseHuggingFaceModel(selected);\n\t\tui.showStatus(\"Loading model details\", parsed.repository);\n\t\tconst details = await huggingFace.details(parsed.repository);\n\t\tif (details.gated) {\n\t\t\tconst approval = details.gated === \"manual\" ? \"Manual approval is required\" : \"Accept the access terms\";\n\t\t\tconst choice = await ui.select(\n\t\t\t\t`Hugging Face access required\\n${details.id}\\n\\n${approval} at:\\nhttps://huggingface.co/${details.id}\\n\\nThe llama.cpp server needs HF_TOKEN with access.`,\n\t\t\t\t[\"Continue\", \"Back\"],\n\t\t\t);\n\t\t\tif (choice !== \"Continue\") return;\n\t\t}\n\t\tlet quantization = parsed.quantization;\n\t\tif (!quantization && details.quantizations.length > 0) {\n\t\t\tconst options = details.quantizations.map((entry) => {\n\t\t\t\tconst detail = [\n\t\t\t\t\tentry.size === undefined ? undefined : formatBytes(entry.size),\n\t\t\t\t\tentry.name === \"Q4_K_M\" ? \"recommended\" : undefined,\n\t\t\t\t]\n\t\t\t\t\t.filter((value): value is string => Boolean(value))\n\t\t\t\t\t.join(\" · \");\n\t\t\t\treturn detail ? `${entry.name} · ${detail}` : entry.name;\n\t\t\t});\n\t\t\tconst choice = await ui.select(`Select quantization\\n${details.id}`, options);\n\t\t\tif (!choice) return;\n\t\t\tquantization = details.quantizations[options.indexOf(choice)]?.name;\n\t\t\tif (!quantization) return;\n\t\t}\n\t\tconst model = quantization ? `${details.id}:${quantization}` : details.id;\n\t\tconst result = await runWithProgress(ui, {\n\t\t\ttitle: \"Downloading model\",\n\t\t\tmodel,\n\t\t\tinitialMessage: \"Starting…\",\n\t\t\tcancelTitle: \"Stop download?\",\n\t\t\tcancelMessage: model,\n\t\t\trun: (signal, update) => client.downloadAndWait(model, update, signal),\n\t\t\tcancel: () => client.unload(model),\n\t\t});\n\t\tif (result.cancelled) return;\n\t\tawait syncCatalog(ctx, client, result.value);\n\t\tctx.ui.notify(`Downloaded ${model}`);\n\t};\n\n\tpi.registerCommand(\"llama\", {\n\t\tdescription: \"Manage llama.cpp router models\",\n\t\thandler: async (_args, ctx) => {\n\t\t\tif (ctx.mode !== \"tui\") {\n\t\t\t\tctx.ui.notify(\"/llama is available in interactive mode\", \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst client = await configuredClient(ctx);\n\t\t\tif (!client) return;\n\t\t\tawait showLlamaUi(ctx, async (ui) => {\n\t\t\t\tconst readCatalog = async (): Promise<LlamaModelInfo[] | undefined> => {\n\t\t\t\t\twhile (true) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn await syncCatalog(ctx, client);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif ((await ui.connectionError(client.serverUrl, connectionErrorMessage(error))) === \"close\") {\n\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tlet catalog = await readCatalog();\n\t\t\t\tif (!catalog) return;\n\t\t\t\twhile (true) {\n\t\t\t\t\tconst action = await ui.showModels(client.serverUrl, catalog);\n\t\t\t\t\tif (action.type === \"close\") return;\n\t\t\t\t\tlet actionError: unknown;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (action.type === \"download\") await downloadModel(ctx, ui, client);\n\t\t\t\t\t\telse if (modelIsLoaded(action.model)) await unloadModel(ctx, ui, client, action.model);\n\t\t\t\t\t\telse if (action.model.status.value === \"unloaded\")\n\t\t\t\t\t\t\tawait loadModel(ctx, ui, client, catalog, action.model);\n\t\t\t\t\t\telse ctx.ui.notify(`${action.model.id} is ${action.model.status.value}`, \"warning\");\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tactionError = error;\n\t\t\t\t\t}\n\t\t\t\t\tconst refreshed = await readCatalog();\n\t\t\t\t\tif (!refreshed) return;\n\t\t\t\t\tcatalog = refreshed;\n\t\t\t\t\tif (actionError && !isConnectionError(actionError)) {\n\t\t\t\t\t\tctx.ui.notify(actionError instanceof Error ? actionError.message : String(actionError), \"error\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/llama/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAuB,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACrG,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAgB,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAErE,SAAS,aAAa,CAAC,KAAqB,E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M,CAAC,KAAK,CAAC,CAAC;;4BACpD,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAC;oBACrF,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBAChB,WAAW,GAAG,KAAK,CAAC;oBACrB,CAAC;oBACD,MAAM,SAAS,GAAG,MAAM,WAAW,EAAE,CAAC;oBACtC,IAAI,CAAC,SAAS;wBAAE,OAAO;oBACvB,OAAO,GAAG,SAAS,CAAC;oBACpB,IAAI,WAAW,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,EAAE,CAAC;wBACpD,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,YAAY,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,CAAC;oBAClG,CAAC;gBACF,CAAC;YAAA,CACD,CAAC,CAAC;QAAA,CACH;KACD,CAAC,CAAC;AAAA,CACH","sourcesContent":["import type { ExtensionAPI, ExtensionCommandContext } from \"../../core/extensions/types.ts\";\nimport { formatBytes, LlamaClient, type LlamaModelInfo, normalizeLlamaServerUrl } from \"./client.ts\";\nimport { findHuggingFaceToken, HuggingFaceClient } from \"./huggingface.ts\";\nimport { createLlamaProvider, LLAMA_PROVIDER_ID } from \"./provider.ts\";\nimport { type LlamaUi, runWithProgress, showLlamaUi } from \"./ui.ts\";\n\nfunction modelIsLoaded(model: LlamaModelInfo): boolean {\n\treturn model.status.value === \"loaded\" || model.status.value === \"sleeping\";\n}\n\nfunction isConnectionError(error: unknown): boolean {\n\tif (!(error instanceof Error)) return false;\n\tconst message = `${error.name} ${error.message}`.toLowerCase();\n\treturn message.includes(\"fetch failed\") || message.includes(\"timeout\") || message.includes(\"network\");\n}\n\nfunction connectionErrorMessage(error: unknown): string {\n\tif (isConnectionError(error)) return \"Could not connect to the server.\";\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction parseHuggingFaceModel(value: string): { repository: string; quantization?: string } {\n\tconst colon = value.indexOf(\":\", value.indexOf(\"/\") + 1);\n\treturn colon < 0\n\t\t? { repository: value }\n\t\t: { repository: value.slice(0, colon), quantization: value.slice(colon + 1) };\n}\n\nasync function configuredClient(ctx: ExtensionCommandContext): Promise<LlamaClient | undefined> {\n\tconst result = await ctx.modelRegistry.getProviderAuth(LLAMA_PROVIDER_ID);\n\tif (!result) {\n\t\tctx.ui.notify(`Configure llama.cpp with /login ${LLAMA_PROVIDER_ID}`, \"warning\");\n\t\treturn undefined;\n\t}\n\tconst configuredUrl = result.env?.LLAMA_BASE_URL;\n\tconst serverUrl = normalizeLlamaServerUrl(\n\t\ttypeof configuredUrl === \"string\" && configuredUrl ? configuredUrl : (result.auth.baseUrl ?? \"\"),\n\t);\n\treturn new LlamaClient(serverUrl, result.auth.apiKey);\n}\n\nexport default function llamaExtension(pi: ExtensionAPI): void {\n\tconst provider = createLlamaProvider();\n\tpi.registerProvider(provider.provider);\n\n\tconst syncCatalog = async (\n\t\tctx: ExtensionCommandContext,\n\t\tclient: LlamaClient,\n\t\tcatalog?: LlamaModelInfo[],\n\t): Promise<LlamaModelInfo[]> => {\n\t\tconst signal = AbortSignal.timeout(15_000);\n\t\tconst current = catalog ?? (await client.list({ signal }));\n\t\tprovider.setCatalog(current, client.serverUrl);\n\t\tconst result = await ctx.modelRegistry.refresh({\n\t\t\tproviders: [LLAMA_PROVIDER_ID],\n\t\t\t// /llama already contacted the configured llama.cpp server, so keep this refresh live even in PI_OFFLINE.\n\t\t\tallowNetwork: true,\n\t\t\tsignal,\n\t\t});\n\t\tif (result.aborted) throw new Error(\"Model catalog refresh timed out.\");\n\t\tconst refreshError = result.errors.get(LLAMA_PROVIDER_ID);\n\t\tif (refreshError) throw refreshError;\n\t\treturn current;\n\t};\n\n\tconst loadModel = async (\n\t\tctx: ExtensionCommandContext,\n\t\tui: LlamaUi,\n\t\tclient: LlamaClient,\n\t\tcatalog: LlamaModelInfo[],\n\t\ttarget: LlamaModelInfo,\n\t): Promise<void> => {\n\t\tconst loaded = catalog.filter((model) => model.id !== target.id && modelIsLoaded(model));\n\t\tlet replace = false;\n\t\tif (loaded.length > 0) {\n\t\t\tconst choice = await ui.select(`${loaded.length} model${loaded.length === 1 ? \" is\" : \"s are\"} loaded`, [\n\t\t\t\t\"Unload all and load\",\n\t\t\t\t\"Keep loaded and load\",\n\t\t\t\t\"Cancel\",\n\t\t\t]);\n\t\t\tif (!choice || choice === \"Cancel\") return;\n\t\t\treplace = choice === \"Unload all and load\";\n\t\t}\n\n\t\tconst restoreLoaded = async (): Promise<void> => {\n\t\t\tctx.ui.notify(\"Restoring previously loaded models\");\n\t\t\tfor (const model of loaded) await client.loadAndWait(model.id, () => {});\n\t\t\tawait syncCatalog(ctx, client);\n\t\t};\n\t\tif (replace) {\n\t\t\tfor (const model of loaded) await client.unloadAndWait(model.id);\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await runWithProgress(ui, {\n\t\t\t\ttitle: \"Loading model\",\n\t\t\t\tmodel: target.id,\n\t\t\t\tinitialMessage: \"Starting…\",\n\t\t\t\tcancelTitle: \"Stop loading?\",\n\t\t\t\tcancelMessage: target.id,\n\t\t\t\trun: (signal, update) => client.loadAndWait(target.id, update, signal),\n\t\t\t\tcancel: () => client.unload(target.id),\n\t\t\t});\n\t\t\tif (result.cancelled) {\n\t\t\t\tif (replace) await restoreLoaded();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst refreshed = await syncCatalog(ctx, client);\n\t\t\tconst loadedModel = refreshed.find((model) => model.id === target.id);\n\t\t\tctx.ui.notify(\n\t\t\t\tloadedModel?.status.value === \"loaded\" ? `Loaded ${target.id}` : `Load started for ${target.id}`,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (replace) {\n\t\t\t\ttry {\n\t\t\t\t\tawait restoreLoaded();\n\t\t\t\t} catch {\n\t\t\t\t\t// Preserve the original load error.\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t};\n\n\tconst unloadModel = async (\n\t\tctx: ExtensionCommandContext,\n\t\tui: LlamaUi,\n\t\tclient: LlamaClient,\n\t\tmodel: LlamaModelInfo,\n\t): Promise<void> => {\n\t\tif (!(await ui.confirm(\"Unload model?\", model.id))) return;\n\t\tawait client.unloadAndWait(model.id);\n\t\tawait syncCatalog(ctx, client);\n\t\tctx.ui.notify(`Unloaded ${model.id}`);\n\t};\n\n\tconst downloadModel = async (ctx: ExtensionCommandContext, ui: LlamaUi, client: LlamaClient): Promise<void> => {\n\t\tconst huggingFace = new HuggingFaceClient(await findHuggingFaceToken());\n\t\tconst selected = await ui.searchModels((query, signal) => huggingFace.search(query, signal));\n\t\tif (!selected) return;\n\t\tconst parsed = parseHuggingFaceModel(selected);\n\t\tui.showStatus(\"Loading model details\", parsed.repository);\n\t\tconst details = await huggingFace.details(parsed.repository);\n\t\tif (details.gated) {\n\t\t\tconst approval = details.gated === \"manual\" ? \"Manual approval is required\" : \"Accept the access terms\";\n\t\t\tconst choice = await ui.select(\n\t\t\t\t`Hugging Face access required\\n${details.id}\\n\\n${approval} at:\\nhttps://huggingface.co/${details.id}\\n\\nThe llama.cpp server needs HF_TOKEN with access.`,\n\t\t\t\t[\"Continue\", \"Back\"],\n\t\t\t);\n\t\t\tif (choice !== \"Continue\") return;\n\t\t}\n\t\tlet quantization = parsed.quantization;\n\t\tif (!quantization && details.quantizations.length > 0) {\n\t\t\tconst options = details.quantizations.map((entry) => {\n\t\t\t\tconst detail = [\n\t\t\t\t\tentry.size === undefined ? undefined : formatBytes(entry.size),\n\t\t\t\t\tentry.name === \"Q4_K_M\" ? \"recommended\" : undefined,\n\t\t\t\t]\n\t\t\t\t\t.filter((value): value is string => Boolean(value))\n\t\t\t\t\t.join(\" · \");\n\t\t\t\treturn detail ? `${entry.name} · ${detail}` : entry.name;\n\t\t\t});\n\t\t\tconst choice = await ui.select(`Select quantization\\n${details.id}`, options);\n\t\t\tif (!choice) return;\n\t\t\tquantization = details.quantizations[options.indexOf(choice)]?.name;\n\t\t\tif (!quantization) return;\n\t\t}\n\t\tconst model = quantization ? `${details.id}:${quantization}` : details.id;\n\t\tconst result = await runWithProgress(ui, {\n\t\t\ttitle: \"Downloading model\",\n\t\t\tmodel,\n\t\t\tinitialMessage: \"Starting…\",\n\t\t\tcancelTitle: \"Stop download?\",\n\t\t\tcancelMessage: model,\n\t\t\trun: (signal, update) => client.downloadAndWait(model, update, signal),\n\t\t\tcancel: () => client.unload(model),\n\t\t});\n\t\tif (result.cancelled) return;\n\t\tawait syncCatalog(ctx, client, result.value);\n\t\tctx.ui.notify(`Downloaded ${model}`);\n\t};\n\n\tpi.registerCommand(\"llama\", {\n\t\tdescription: \"Manage llama.cpp router models\",\n\t\thandler: async (_args, ctx) => {\n\t\t\tif (ctx.mode !== \"tui\") {\n\t\t\t\tctx.ui.notify(\"/llama is available in interactive mode\", \"warning\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst client = await configuredClient(ctx);\n\t\t\tif (!client) return;\n\t\t\tawait showLlamaUi(ctx, async (ui) => {\n\t\t\t\tconst readCatalog = async (): Promise<LlamaModelInfo[] | undefined> => {\n\t\t\t\t\twhile (true) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn await syncCatalog(ctx, client);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif ((await ui.connectionError(client.serverUrl, connectionErrorMessage(error))) === \"close\") {\n\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tlet catalog = await readCatalog();\n\t\t\t\tif (!catalog) return;\n\t\t\t\twhile (true) {\n\t\t\t\t\tconst action = await ui.showModels(client.serverUrl, catalog);\n\t\t\t\t\tif (action.type === \"close\") return;\n\t\t\t\t\tlet actionError: unknown;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (action.type === \"download\") await downloadModel(ctx, ui, client);\n\t\t\t\t\t\telse if (modelIsLoaded(action.model)) await unloadModel(ctx, ui, client, action.model);\n\t\t\t\t\t\telse if (action.model.status.value === \"unloaded\")\n\t\t\t\t\t\t\tawait loadModel(ctx, ui, client, catalog, action.model);\n\t\t\t\t\t\telse ctx.ui.notify(`${action.model.id} is ${action.model.status.value}`, \"warning\");\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tactionError = error;\n\t\t\t\t\t}\n\t\t\t\t\tconst refreshed = await readCatalog();\n\t\t\t\t\tif (!refreshed) return;\n\t\t\t\t\tcatalog = refreshed;\n\t\t\t\t\tif (actionError && !isConnectionError(actionError)) {\n\t\t\t\t\t\tctx.ui.notify(actionError instanceof Error ? actionError.message : String(actionError), \"error\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/extensions/llama/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKX,QAAQ,EAGR,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAe,KAAK,cAAc,EAA8C,MAAM,aAAa,CAAC;AAE3G,eAAO,MAAM,iBAAiB,cAAc,CAAC;AAC7C,eAAO,MAAM,wBAAwB,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/extensions/llama/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKX,QAAQ,EAGR,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAe,KAAK,cAAc,EAA8C,MAAM,aAAa,CAAC;AAE3G,eAAO,MAAM,iBAAiB,cAAc,CAAC;AAC7C,eAAO,MAAM,wBAAwB,0BAA0B,CAAC;AA4ChE,MAAM,WAAW,uBAAuB;IACvC,QAAQ,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAC;IACzC,UAAU,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CACvE;AAED,wBAAgB,mBAAmB,IAAI,uBAAuB,CA4F7D","sourcesContent":["import type {\n\tApiKeyCredential,\n\tAuthContext,\n\tAuthResult,\n\tModel,\n\tProvider,\n\tProviderStreamOptions,\n\tRefreshModelsContext,\n} from \"@earendil-works/pi-ai\";\nimport { stream, streamSimple } from \"@earendil-works/pi-ai/compat\";\nimport { LlamaClient, type LlamaModelInfo, llamaInferenceUrl, normalizeLlamaServerUrl } from \"./client.ts\";\n\nexport const LLAMA_PROVIDER_ID = \"llama.cpp\";\nexport const DEFAULT_LLAMA_SERVER_URL = \"http://127.0.0.1:8080\";\nfunction credentialServerUrl(credential: ApiKeyCredential | undefined): string | undefined {\n\tconst value = credential?.env?.LLAMA_BASE_URL;\n\treturn typeof value === \"string\" && value.trim() ? normalizeLlamaServerUrl(value) : undefined;\n}\n\nasync function resolveServerUrl(\n\tctx: AuthContext,\n\tcredential: ApiKeyCredential | undefined,\n): Promise<string | undefined> {\n\tconst configured = credentialServerUrl(credential) ?? (await ctx.env(\"LLAMA_BASE_URL\"))?.trim();\n\treturn configured ? normalizeLlamaServerUrl(configured) : undefined;\n}\n\nfunction modelIsSelectable(model: LlamaModelInfo): boolean {\n\t// llama.cpp reports idle-slept models as \"sleeping\"; requests wake them automatically.\n\treturn model.status.value === \"loaded\" || model.status.value === \"sleeping\";\n}\n\nfunction toPiModel(model: LlamaModelInfo, serverUrl: string): Model<\"openai-completions\"> {\n\tconst reportedContextWindow = model.meta?.n_ctx ?? model.meta?.n_ctx_train;\n\tconst contextWindow = reportedContextWindow && reportedContextWindow > 0 ? reportedContextWindow : 128000;\n\treturn {\n\t\tid: model.id,\n\t\tname: model.id,\n\t\tapi: \"openai-completions\",\n\t\tprovider: LLAMA_PROVIDER_ID,\n\t\tbaseUrl: llamaInferenceUrl(serverUrl),\n\t\treasoning: false,\n\t\tinput: model.architecture?.input_modalities?.includes(\"image\") ? [\"text\", \"image\"] : [\"text\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow,\n\t\tmaxTokens: contextWindow,\n\t\tcompat: {\n\t\t\tsupportsStore: false,\n\t\t\tsupportsDeveloperRole: false,\n\t\t\tsupportsReasoningEffort: false,\n\t\t\tsupportsUsageInStreaming: true,\n\t\t\tsupportsStrictMode: false,\n\t\t\tmaxTokensField: \"max_tokens\",\n\t\t},\n\t};\n}\n\nexport interface LlamaProviderController {\n\tprovider: Provider<\"openai-completions\">;\n\tsetCatalog(models: readonly LlamaModelInfo[], serverUrl: string): void;\n}\n\nexport function createLlamaProvider(): LlamaProviderController {\n\tlet models: readonly Model<\"openai-completions\">[] = [];\n\n\tconst setCatalog = (catalog: readonly LlamaModelInfo[], serverUrl: string): void => {\n\t\tmodels = catalog.filter((model) => modelIsSelectable(model)).map((model) => toPiModel(model, serverUrl));\n\t};\n\n\tconst provider: Provider<\"openai-completions\"> = {\n\t\tid: LLAMA_PROVIDER_ID,\n\t\tname: \"llama.cpp\",\n\t\tbaseUrl: llamaInferenceUrl(DEFAULT_LLAMA_SERVER_URL),\n\t\tauth: {\n\t\t\tapiKey: {\n\t\t\t\tname: \"llama.cpp server\",\n\t\t\t\tlogin: async (interaction): Promise<ApiKeyCredential> => {\n\t\t\t\t\tconst enteredUrl = await interaction.prompt({\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\tmessage: \"llama.cpp server URL\",\n\t\t\t\t\t\tplaceholder: process.env.LLAMA_BASE_URL ?? DEFAULT_LLAMA_SERVER_URL,\n\t\t\t\t\t});\n\t\t\t\t\tconst serverUrl = normalizeLlamaServerUrl(\n\t\t\t\t\t\tenteredUrl.trim() || process.env.LLAMA_BASE_URL || DEFAULT_LLAMA_SERVER_URL,\n\t\t\t\t\t);\n\t\t\t\t\tconst apiKey = (\n\t\t\t\t\t\tawait interaction.prompt({\n\t\t\t\t\t\t\ttype: \"secret\",\n\t\t\t\t\t\t\tmessage: \"API key (optional)\",\n\t\t\t\t\t\t})\n\t\t\t\t\t).trim();\n\t\t\t\t\tawait new LlamaClient(serverUrl, apiKey || undefined).list({ signal: interaction.signal });\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"api_key\",\n\t\t\t\t\t\tkey: apiKey || undefined,\n\t\t\t\t\t\tenv: { LLAMA_BASE_URL: serverUrl },\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tcheck: async ({ ctx, credential }) => {\n\t\t\t\t\tconst serverUrl = await resolveServerUrl(ctx, credential);\n\t\t\t\t\treturn serverUrl\n\t\t\t\t\t\t? { type: \"api_key\", source: credential ? \"stored credential\" : \"LLAMA_BASE_URL\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t\t},\n\t\t\t\tresolve: async ({ ctx, credential }): Promise<AuthResult | undefined> => {\n\t\t\t\t\tconst serverUrl = await resolveServerUrl(ctx, credential);\n\t\t\t\t\tif (!serverUrl) return undefined;\n\t\t\t\t\tconst apiKey = credential?.key ?? (await ctx.env(\"LLAMA_API_KEY\")) ?? \"local\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\tauth: { apiKey, baseUrl: llamaInferenceUrl(serverUrl) },\n\t\t\t\t\t\tenv: { ...credential?.env, LLAMA_BASE_URL: serverUrl },\n\t\t\t\t\t\tsource: credential ? \"stored credential\" : \"LLAMA_BASE_URL\",\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tgetModels: () => models,\n\t\trefreshModels: async (context: RefreshModelsContext): Promise<void> => {\n\t\t\tif (context.stored) {\n\t\t\t\tconst restored = context.stored.models.filter(\n\t\t\t\t\t(model): model is Model<\"openai-completions\"> =>\n\t\t\t\t\t\tmodel.provider === LLAMA_PROVIDER_ID && model.api === \"openai-completions\",\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\t!(await context.publish({\n\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\tmodels = restored;\n\t\t\t\t\t\t},\n\t\t\t\t\t}))\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!context.allowNetwork || context.signal.aborted || context.credential?.type !== \"api_key\") return;\n\t\t\tconst serverUrl = credentialServerUrl(context.credential);\n\t\t\tif (!serverUrl) return;\n\t\t\tconst catalog = await new LlamaClient(serverUrl, context.credential.key).list({ signal: context.signal });\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst refreshed = catalog\n\t\t\t\t.filter((model) => modelIsSelectable(model))\n\t\t\t\t.map((model) => toPiModel(model, serverUrl));\n\t\t\tawait context.publish({\n\t\t\t\tpersist: { models: refreshed, checkedAt: Date.now() },\n\t\t\t\tupdate: () => {\n\t\t\t\t\tmodels = refreshed;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t\tstream: (model, context, options) => stream(model, context, options as ProviderStreamOptions | undefined),\n\t\tstreamSimple: (model, context, options) => streamSimple(model, context, options),\n\t};\n\n\treturn { provider, setCatalog };\n}\n"]}
|
|
@@ -10,6 +10,10 @@ async function resolveServerUrl(ctx, credential) {
|
|
|
10
10
|
const configured = credentialServerUrl(credential) ?? (await ctx.env("LLAMA_BASE_URL"))?.trim();
|
|
11
11
|
return configured ? normalizeLlamaServerUrl(configured) : undefined;
|
|
12
12
|
}
|
|
13
|
+
function modelIsSelectable(model) {
|
|
14
|
+
// llama.cpp reports idle-slept models as "sleeping"; requests wake them automatically.
|
|
15
|
+
return model.status.value === "loaded" || model.status.value === "sleeping";
|
|
16
|
+
}
|
|
13
17
|
function toPiModel(model, serverUrl) {
|
|
14
18
|
const reportedContextWindow = model.meta?.n_ctx ?? model.meta?.n_ctx_train;
|
|
15
19
|
const contextWindow = reportedContextWindow && reportedContextWindow > 0 ? reportedContextWindow : 128000;
|
|
@@ -37,7 +41,7 @@ function toPiModel(model, serverUrl) {
|
|
|
37
41
|
export function createLlamaProvider() {
|
|
38
42
|
let models = [];
|
|
39
43
|
const setCatalog = (catalog, serverUrl) => {
|
|
40
|
-
models = catalog.filter((model) => model
|
|
44
|
+
models = catalog.filter((model) => modelIsSelectable(model)).map((model) => toPiModel(model, serverUrl));
|
|
41
45
|
};
|
|
42
46
|
const provider = {
|
|
43
47
|
id: LLAMA_PROVIDER_ID,
|
|
@@ -104,7 +108,7 @@ export function createLlamaProvider() {
|
|
|
104
108
|
if (context.signal.aborted)
|
|
105
109
|
return;
|
|
106
110
|
const refreshed = catalog
|
|
107
|
-
.filter((model) => model
|
|
111
|
+
.filter((model) => modelIsSelectable(model))
|
|
108
112
|
.map((model) => toPiModel(model, serverUrl));
|
|
109
113
|
await context.publish({
|
|
110
114
|
persist: { models: refreshed, checkedAt: Date.now() },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/extensions/llama/provider.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAuB,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3G,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAC7C,MAAM,CAAC,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;AAChE,SAAS,mBAAmB,CAAC,UAAwC,EAAsB;IAC1F,MAAM,KAAK,GAAG,UAAU,EAAE,GAAG,EAAE,cAAc,CAAC;IAC9C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAAA,CAC9F;AAED,KAAK,UAAU,gBAAgB,CAC9B,GAAgB,EAChB,UAAwC,EACV;IAC9B,MAAM,UAAU,GAAG,mBAAmB,CAAC,UAAU,CAAC,I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AAM,GAAG,SAAS,CAAC;gBAAA,CACnB;aACD,CAAC,CAAC;QAAA,CACH;QACD,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAA4C,CAAC;QACzG,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC;KAChF,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;AAAA,CAChC","sourcesContent":["import type {\n\tApiKeyCredential,\n\tAuthContext,\n\tAuthResult,\n\tModel,\n\tProvider,\n\tProviderStreamOptions,\n\tRefreshModelsContext,\n} from \"@earendil-works/pi-ai\";\nimport { stream, streamSimple } from \"@earendil-works/pi-ai/compat\";\nimport { LlamaClient, type LlamaModelInfo, llamaInferenceUrl, normalizeLlamaServerUrl } from \"./client.ts\";\n\nexport const LLAMA_PROVIDER_ID = \"llama.cpp\";\nexport const DEFAULT_LLAMA_SERVER_URL = \"http://127.0.0.1:8080\";\nfunction credentialServerUrl(credential: ApiKeyCredential | undefined): string | undefined {\n\tconst value = credential?.env?.LLAMA_BASE_URL;\n\treturn typeof value === \"string\" && value.trim() ? normalizeLlamaServerUrl(value) : undefined;\n}\n\nasync function resolveServerUrl(\n\tctx: AuthContext,\n\tcredential: ApiKeyCredential | undefined,\n): Promise<string | undefined> {\n\tconst configured = credentialServerUrl(credential) ?? (await ctx.env(\"LLAMA_BASE_URL\"))?.trim();\n\treturn configured ? normalizeLlamaServerUrl(configured) : undefined;\n}\n\nfunction toPiModel(model: LlamaModelInfo, serverUrl: string): Model<\"openai-completions\"> {\n\tconst reportedContextWindow = model.meta?.n_ctx ?? model.meta?.n_ctx_train;\n\tconst contextWindow = reportedContextWindow && reportedContextWindow > 0 ? reportedContextWindow : 128000;\n\treturn {\n\t\tid: model.id,\n\t\tname: model.id,\n\t\tapi: \"openai-completions\",\n\t\tprovider: LLAMA_PROVIDER_ID,\n\t\tbaseUrl: llamaInferenceUrl(serverUrl),\n\t\treasoning: false,\n\t\tinput: model.architecture?.input_modalities?.includes(\"image\") ? [\"text\", \"image\"] : [\"text\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow,\n\t\tmaxTokens: contextWindow,\n\t\tcompat: {\n\t\t\tsupportsStore: false,\n\t\t\tsupportsDeveloperRole: false,\n\t\t\tsupportsReasoningEffort: false,\n\t\t\tsupportsUsageInStreaming: true,\n\t\t\tsupportsStrictMode: false,\n\t\t\tmaxTokensField: \"max_tokens\",\n\t\t},\n\t};\n}\n\nexport interface LlamaProviderController {\n\tprovider: Provider<\"openai-completions\">;\n\tsetCatalog(models: readonly LlamaModelInfo[], serverUrl: string): void;\n}\n\nexport function createLlamaProvider(): LlamaProviderController {\n\tlet models: readonly Model<\"openai-completions\">[] = [];\n\n\tconst setCatalog = (catalog: readonly LlamaModelInfo[], serverUrl: string): void => {\n\t\tmodels = catalog.filter((model) => model.status.value === \"loaded\").map((model) => toPiModel(model, serverUrl));\n\t};\n\n\tconst provider: Provider<\"openai-completions\"> = {\n\t\tid: LLAMA_PROVIDER_ID,\n\t\tname: \"llama.cpp\",\n\t\tbaseUrl: llamaInferenceUrl(DEFAULT_LLAMA_SERVER_URL),\n\t\tauth: {\n\t\t\tapiKey: {\n\t\t\t\tname: \"llama.cpp server\",\n\t\t\t\tlogin: async (interaction): Promise<ApiKeyCredential> => {\n\t\t\t\t\tconst enteredUrl = await interaction.prompt({\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\tmessage: \"llama.cpp server URL\",\n\t\t\t\t\t\tplaceholder: process.env.LLAMA_BASE_URL ?? DEFAULT_LLAMA_SERVER_URL,\n\t\t\t\t\t});\n\t\t\t\t\tconst serverUrl = normalizeLlamaServerUrl(\n\t\t\t\t\t\tenteredUrl.trim() || process.env.LLAMA_BASE_URL || DEFAULT_LLAMA_SERVER_URL,\n\t\t\t\t\t);\n\t\t\t\t\tconst apiKey = (\n\t\t\t\t\t\tawait interaction.prompt({\n\t\t\t\t\t\t\ttype: \"secret\",\n\t\t\t\t\t\t\tmessage: \"API key (optional)\",\n\t\t\t\t\t\t})\n\t\t\t\t\t).trim();\n\t\t\t\t\tawait new LlamaClient(serverUrl, apiKey || undefined).list({ signal: interaction.signal });\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"api_key\",\n\t\t\t\t\t\tkey: apiKey || undefined,\n\t\t\t\t\t\tenv: { LLAMA_BASE_URL: serverUrl },\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tcheck: async ({ ctx, credential }) => {\n\t\t\t\t\tconst serverUrl = await resolveServerUrl(ctx, credential);\n\t\t\t\t\treturn serverUrl\n\t\t\t\t\t\t? { type: \"api_key\", source: credential ? \"stored credential\" : \"LLAMA_BASE_URL\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t\t},\n\t\t\t\tresolve: async ({ ctx, credential }): Promise<AuthResult | undefined> => {\n\t\t\t\t\tconst serverUrl = await resolveServerUrl(ctx, credential);\n\t\t\t\t\tif (!serverUrl) return undefined;\n\t\t\t\t\tconst apiKey = credential?.key ?? (await ctx.env(\"LLAMA_API_KEY\")) ?? \"local\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\tauth: { apiKey, baseUrl: llamaInferenceUrl(serverUrl) },\n\t\t\t\t\t\tenv: { ...credential?.env, LLAMA_BASE_URL: serverUrl },\n\t\t\t\t\t\tsource: credential ? \"stored credential\" : \"LLAMA_BASE_URL\",\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tgetModels: () => models,\n\t\trefreshModels: async (context: RefreshModelsContext): Promise<void> => {\n\t\t\tif (context.stored) {\n\t\t\t\tconst restored = context.stored.models.filter(\n\t\t\t\t\t(model): model is Model<\"openai-completions\"> =>\n\t\t\t\t\t\tmodel.provider === LLAMA_PROVIDER_ID && model.api === \"openai-completions\",\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\t!(await context.publish({\n\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\tmodels = restored;\n\t\t\t\t\t\t},\n\t\t\t\t\t}))\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!context.allowNetwork || context.signal.aborted || context.credential?.type !== \"api_key\") return;\n\t\t\tconst serverUrl = credentialServerUrl(context.credential);\n\t\t\tif (!serverUrl) return;\n\t\t\tconst catalog = await new LlamaClient(serverUrl, context.credential.key).list({ signal: context.signal });\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst refreshed = catalog\n\t\t\t\t.filter((model) => model.status.value === \"loaded\")\n\t\t\t\t.map((model) => toPiModel(model, serverUrl));\n\t\t\tawait context.publish({\n\t\t\t\tpersist: { models: refreshed, checkedAt: Date.now() },\n\t\t\t\tupdate: () => {\n\t\t\t\t\tmodels = refreshed;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t\tstream: (model, context, options) => stream(model, context, options as ProviderStreamOptions | undefined),\n\t\tstreamSimple: (model, context, options) => streamSimple(model, context, options),\n\t};\n\n\treturn { provider, setCatalog };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/extensions/llama/provider.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAuB,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3G,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAC7C,MAAM,CAAC,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;AAChE,SAAS,mBAAmB,CAAC,UAAwC,EAAsB;IAC1F,MAAM,KAAK,GAAG,UAAU,EAAE,GAAG,EAAE,cAAc,CAAC;IAC9C,OAAO,OAAO,KAA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AAO;YACnC,MAAM,SAAS,GAAG,OAAO;iBACvB,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;iBAC3C,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC;YAC9C,MAAM,OAAO,CAAC,OAAO,CAAC;gBACrB,OAAO,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE;gBACrD,MAAM,EAAE,GAAG,EAAE,CAAC;oBACb,MAAM,GAAG,SAAS,CAAC;gBAAA,CACnB;aACD,CAAC,CAAC;QAAA,CACH;QACD,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAA4C,CAAC;QACzG,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC;KAChF,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;AAAA,CAChC","sourcesContent":["import type {\n\tApiKeyCredential,\n\tAuthContext,\n\tAuthResult,\n\tModel,\n\tProvider,\n\tProviderStreamOptions,\n\tRefreshModelsContext,\n} from \"@earendil-works/pi-ai\";\nimport { stream, streamSimple } from \"@earendil-works/pi-ai/compat\";\nimport { LlamaClient, type LlamaModelInfo, llamaInferenceUrl, normalizeLlamaServerUrl } from \"./client.ts\";\n\nexport const LLAMA_PROVIDER_ID = \"llama.cpp\";\nexport const DEFAULT_LLAMA_SERVER_URL = \"http://127.0.0.1:8080\";\nfunction credentialServerUrl(credential: ApiKeyCredential | undefined): string | undefined {\n\tconst value = credential?.env?.LLAMA_BASE_URL;\n\treturn typeof value === \"string\" && value.trim() ? normalizeLlamaServerUrl(value) : undefined;\n}\n\nasync function resolveServerUrl(\n\tctx: AuthContext,\n\tcredential: ApiKeyCredential | undefined,\n): Promise<string | undefined> {\n\tconst configured = credentialServerUrl(credential) ?? (await ctx.env(\"LLAMA_BASE_URL\"))?.trim();\n\treturn configured ? normalizeLlamaServerUrl(configured) : undefined;\n}\n\nfunction modelIsSelectable(model: LlamaModelInfo): boolean {\n\t// llama.cpp reports idle-slept models as \"sleeping\"; requests wake them automatically.\n\treturn model.status.value === \"loaded\" || model.status.value === \"sleeping\";\n}\n\nfunction toPiModel(model: LlamaModelInfo, serverUrl: string): Model<\"openai-completions\"> {\n\tconst reportedContextWindow = model.meta?.n_ctx ?? model.meta?.n_ctx_train;\n\tconst contextWindow = reportedContextWindow && reportedContextWindow > 0 ? reportedContextWindow : 128000;\n\treturn {\n\t\tid: model.id,\n\t\tname: model.id,\n\t\tapi: \"openai-completions\",\n\t\tprovider: LLAMA_PROVIDER_ID,\n\t\tbaseUrl: llamaInferenceUrl(serverUrl),\n\t\treasoning: false,\n\t\tinput: model.architecture?.input_modalities?.includes(\"image\") ? [\"text\", \"image\"] : [\"text\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow,\n\t\tmaxTokens: contextWindow,\n\t\tcompat: {\n\t\t\tsupportsStore: false,\n\t\t\tsupportsDeveloperRole: false,\n\t\t\tsupportsReasoningEffort: false,\n\t\t\tsupportsUsageInStreaming: true,\n\t\t\tsupportsStrictMode: false,\n\t\t\tmaxTokensField: \"max_tokens\",\n\t\t},\n\t};\n}\n\nexport interface LlamaProviderController {\n\tprovider: Provider<\"openai-completions\">;\n\tsetCatalog(models: readonly LlamaModelInfo[], serverUrl: string): void;\n}\n\nexport function createLlamaProvider(): LlamaProviderController {\n\tlet models: readonly Model<\"openai-completions\">[] = [];\n\n\tconst setCatalog = (catalog: readonly LlamaModelInfo[], serverUrl: string): void => {\n\t\tmodels = catalog.filter((model) => modelIsSelectable(model)).map((model) => toPiModel(model, serverUrl));\n\t};\n\n\tconst provider: Provider<\"openai-completions\"> = {\n\t\tid: LLAMA_PROVIDER_ID,\n\t\tname: \"llama.cpp\",\n\t\tbaseUrl: llamaInferenceUrl(DEFAULT_LLAMA_SERVER_URL),\n\t\tauth: {\n\t\t\tapiKey: {\n\t\t\t\tname: \"llama.cpp server\",\n\t\t\t\tlogin: async (interaction): Promise<ApiKeyCredential> => {\n\t\t\t\t\tconst enteredUrl = await interaction.prompt({\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\tmessage: \"llama.cpp server URL\",\n\t\t\t\t\t\tplaceholder: process.env.LLAMA_BASE_URL ?? DEFAULT_LLAMA_SERVER_URL,\n\t\t\t\t\t});\n\t\t\t\t\tconst serverUrl = normalizeLlamaServerUrl(\n\t\t\t\t\t\tenteredUrl.trim() || process.env.LLAMA_BASE_URL || DEFAULT_LLAMA_SERVER_URL,\n\t\t\t\t\t);\n\t\t\t\t\tconst apiKey = (\n\t\t\t\t\t\tawait interaction.prompt({\n\t\t\t\t\t\t\ttype: \"secret\",\n\t\t\t\t\t\t\tmessage: \"API key (optional)\",\n\t\t\t\t\t\t})\n\t\t\t\t\t).trim();\n\t\t\t\t\tawait new LlamaClient(serverUrl, apiKey || undefined).list({ signal: interaction.signal });\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"api_key\",\n\t\t\t\t\t\tkey: apiKey || undefined,\n\t\t\t\t\t\tenv: { LLAMA_BASE_URL: serverUrl },\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tcheck: async ({ ctx, credential }) => {\n\t\t\t\t\tconst serverUrl = await resolveServerUrl(ctx, credential);\n\t\t\t\t\treturn serverUrl\n\t\t\t\t\t\t? { type: \"api_key\", source: credential ? \"stored credential\" : \"LLAMA_BASE_URL\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t\t},\n\t\t\t\tresolve: async ({ ctx, credential }): Promise<AuthResult | undefined> => {\n\t\t\t\t\tconst serverUrl = await resolveServerUrl(ctx, credential);\n\t\t\t\t\tif (!serverUrl) return undefined;\n\t\t\t\t\tconst apiKey = credential?.key ?? (await ctx.env(\"LLAMA_API_KEY\")) ?? \"local\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\tauth: { apiKey, baseUrl: llamaInferenceUrl(serverUrl) },\n\t\t\t\t\t\tenv: { ...credential?.env, LLAMA_BASE_URL: serverUrl },\n\t\t\t\t\t\tsource: credential ? \"stored credential\" : \"LLAMA_BASE_URL\",\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tgetModels: () => models,\n\t\trefreshModels: async (context: RefreshModelsContext): Promise<void> => {\n\t\t\tif (context.stored) {\n\t\t\t\tconst restored = context.stored.models.filter(\n\t\t\t\t\t(model): model is Model<\"openai-completions\"> =>\n\t\t\t\t\t\tmodel.provider === LLAMA_PROVIDER_ID && model.api === \"openai-completions\",\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\t!(await context.publish({\n\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\tmodels = restored;\n\t\t\t\t\t\t},\n\t\t\t\t\t}))\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!context.allowNetwork || context.signal.aborted || context.credential?.type !== \"api_key\") return;\n\t\t\tconst serverUrl = credentialServerUrl(context.credential);\n\t\t\tif (!serverUrl) return;\n\t\t\tconst catalog = await new LlamaClient(serverUrl, context.credential.key).list({ signal: context.signal });\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst refreshed = catalog\n\t\t\t\t.filter((model) => modelIsSelectable(model))\n\t\t\t\t.map((model) => toPiModel(model, serverUrl));\n\t\t\tawait context.publish({\n\t\t\t\tpersist: { models: refreshed, checkedAt: Date.now() },\n\t\t\t\tupdate: () => {\n\t\t\t\t\tmodels = refreshed;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t\tstream: (model, context, options) => stream(model, context, options as ProviderStreamOptions | undefined),\n\t\tstreamSimple: (model, context, options) => streamSimple(model, context, options),\n\t};\n\n\treturn { provider, setCatalog };\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,24 +7,24 @@ export { createEventBus, type EventBus, type EventBusController } from "./core/e
|
|
|
7
7
|
export type { AgentEndEvent, AgentSettledEvent, AgentStartEvent, AgentToolResult, AgentToolUpdateCallback, AppKeybinding, AutocompleteProviderFactory, BashToolCallEvent, BeforeAgentStartEvent, BeforeAgentStartEventResult, BeforeProviderHeadersEvent, BeforeProviderRequestEvent, BeforeProviderRequestEventResult, BuildSystemPromptOptions, CompactOptions, ContextEvent, ContextUsage, CustomToolCallEvent, EditToolCallEvent, EntryRenderer, EntryRenderOptions, ExecOptions, ExecResult, Extension, ExtensionActions, ExtensionAPI, ExtensionCommandContext, ExtensionCommandContextActions, ExtensionContext, ExtensionContextActions, ExtensionError, ExtensionEvent, ExtensionFactory, ExtensionFlag, ExtensionHandler, ExtensionRuntime, ExtensionShortcut, ExtensionUIContext, ExtensionUIDialogOptions, ExtensionWidgetOptions, FindToolCallEvent, GrepToolCallEvent, InlineExtension, InputEvent, InputEventResult, InputSource, KeybindingsManager, LoadExtensionsResult, LsToolCallEvent, MarkdownTransformContext, MarkdownTransformer, MessageEndEvent, MessageRenderer, MessageRenderOptions, MessageStartEvent, MessageUpdateEvent, ProjectTrustContext, ProjectTrustEvent, ProjectTrustEventDecision, ProjectTrustEventResult, ProjectTrustHandler, ProviderConfig, ProviderModelConfig, ReadToolCallEvent, RegisteredCommand, RegisteredTool, ResolvedCommand, SessionBeforeCompactEvent, SessionBeforeForkEvent, SessionBeforeSwitchEvent, SessionBeforeTreeEvent, SessionCompactEvent, SessionInfoChangedEvent, SessionShutdownEvent, SessionStartEvent, SessionTreeEvent, SlashCommandInfo, SlashCommandSource, SourceInfo, TerminalInputHandler, ToolCallEvent, ToolCallEventResult, ToolDefinition, ToolExecutionEndEvent, ToolExecutionMode, ToolExecutionStartEvent, ToolExecutionUpdateEvent, ToolInfo, ToolRenderResultOptions, ToolResultEvent, TurnEndEvent, TurnStartEvent, UserBashEvent, UserBashEventResult, WidgetPlacement, WorkingIndicatorOptions, WriteToolCallEvent, } from "./core/extensions/index.ts";
|
|
8
8
|
export { createExtensionRuntime, defineTool, discoverAndLoadExtensions, ExtensionRunner, isBashToolResult, isEditToolResult, isFindToolResult, isGrepToolResult, isLsToolResult, isReadToolResult, isToolCallEventType, isWriteToolResult, wrapRegisteredTool, wrapRegisteredTools, } from "./core/extensions/index.ts";
|
|
9
9
|
export type { ReadonlyFooterDataProvider } from "./core/footer-data-provider.ts";
|
|
10
|
+
export { type AuditEntry, AuditLog } from "./core/memory-engine/audit.ts";
|
|
11
|
+
export { isCorrection, MEMORY_POLICY_PROMPT, MemoryEngine, parseOperations, projectHashOf, } from "./core/memory-engine/engine.ts";
|
|
12
|
+
export { InvertedIndex, tokenize } from "./core/memory-engine/inverted-index.ts";
|
|
13
|
+
export { isKeychainAvailable, keychainClearPassphrase, keychainHasPassphrase, keychainLoadPassphrase, keychainSavePassphrase, } from "./core/memory-engine/keychain.ts";
|
|
14
|
+
export { ENTRY_DELIMITER, encodeEntry, listProjectHashes, loadStores, ObservationStore, parseEntry, stripMetadata, } from "./core/memory-engine/observation-store.ts";
|
|
15
|
+
export { scanContent } from "./core/memory-engine/scanner.ts";
|
|
16
|
+
export { classifySensitive, type PrivacyLevel, type SensitiveCategory, type SensitivityResult, } from "./core/memory-engine/security.ts";
|
|
17
|
+
export { extractText, parseSessionFile, SessionIndexer } from "./core/memory-engine/session-indexer.ts";
|
|
18
|
+
export { createMemoryEngineTools, type MemoryEngineToolSet } from "./core/memory-engine/tools.ts";
|
|
19
|
+
export { DEFAULT_MEMORY_CONFIG, type MemoryEngineConfig, type MemoryMode, type MemoryMutationInput, type MemoryOperation, type MemoryResult, type MemorySearchHit, type MemorySearchQuery, type MemoryTarget, OBSERVATION_TYPES, type Observation, type ObservationType, type ObservationView, type SessionSearchHit, } from "./core/memory-engine/types.ts";
|
|
20
|
+
export { expandVaultRefs, ProjectVault, SessionVault, VAULT_REF_PATTERN, type VaultExpansion, type VaultListEntry, VaultManager, type VaultSecret, } from "./core/memory-engine/vault.ts";
|
|
10
21
|
export { convertToLlm } from "./core/messages.ts";
|
|
11
22
|
export { ModelRegistry } from "./core/model-registry.ts";
|
|
12
23
|
export { type ModelScopeDiagnostic, type ResolveCliModelResult, type ResolveModelScopeResult, resolveCliModel, resolveModelScopeWithDiagnostics, type ScopedModel, } from "./core/model-resolver.ts";
|
|
13
24
|
export { type CreateModelRuntimeOptions, CredentialSynchronizationError, type CredentialSynchronizationOperation, ModelRuntime, type ModelRuntimeAuthOverrides, } from "./core/model-runtime.ts";
|
|
14
25
|
export type { PackageManager, PathMetadata, ProgressCallback, ProgressEvent, ResolvedPaths, ResolvedResource, } from "./core/package-manager.ts";
|
|
15
26
|
export { DefaultPackageManager } from "./core/package-manager.ts";
|
|
16
|
-
export { getProjectMemoryDirName, getProjectMemoryPath, hasProjectMemory, loadProjectMemory, loadProjectMemorySync,
|
|
17
|
-
export { MemoryEngine, isCorrection, parseOperations, projectHashOf, MEMORY_POLICY_PROMPT, } from "./core/memory-engine/engine.ts";
|
|
18
|
-
export { ObservationStore, loadStores, listProjectHashes, parseEntry, encodeEntry, stripMetadata, ENTRY_DELIMITER, } from "./core/memory-engine/observation-store.ts";
|
|
19
|
-
export { InvertedIndex, tokenize } from "./core/memory-engine/inverted-index.ts";
|
|
20
|
-
export { SessionIndexer, parseSessionFile, extractText } from "./core/memory-engine/session-indexer.ts";
|
|
21
|
-
export { scanContent } from "./core/memory-engine/scanner.ts";
|
|
22
|
-
export { classifySensitive, type PrivacyLevel, type SensitiveCategory, type SensitivityResult } from "./core/memory-engine/security.ts";
|
|
23
|
-
export { AuditLog, type AuditEntry } from "./core/memory-engine/audit.ts";
|
|
24
|
-
export { VaultManager, ProjectVault, SessionVault, expandVaultRefs, VAULT_REF_PATTERN, type VaultListEntry, type VaultSecret, type VaultExpansion, } from "./core/memory-engine/vault.ts";
|
|
25
|
-
export { isKeychainAvailable, keychainHasPassphrase, keychainLoadPassphrase, keychainSavePassphrase, keychainClearPassphrase, } from "./core/memory-engine/keychain.ts";
|
|
26
|
-
export { createMemoryEngineTools, type MemoryEngineToolSet } from "./core/memory-engine/tools.ts";
|
|
27
|
-
export { DEFAULT_MEMORY_CONFIG, OBSERVATION_TYPES, type MemoryEngineConfig, type MemoryMode, type MemoryMutationInput, type MemoryOperation, type MemoryResult, type MemorySearchHit, type MemorySearchQuery, type MemoryTarget, type Observation, type ObservationType, type ObservationView, type SessionSearchHit, } from "./core/memory-engine/types.ts";
|
|
27
|
+
export { getProjectMemoryDirName, getProjectMemoryPath, hasProjectMemory, loadProjectMemory, loadProjectMemorySync, type ProjectMemory, saveProjectMemory, } from "./core/project-memory.ts";
|
|
28
28
|
export type { ResourceCollision, ResourceDiagnostic, ResourceLoader } from "./core/resource-loader.ts";
|
|
29
29
|
export { DefaultResourceLoader, loadProjectContextFiles } from "./core/resource-loader.ts";
|
|
30
30
|
export { AgentSessionRuntime, type AgentSessionRuntimeDiagnostic, type AgentSessionServices, type CreateAgentSessionFromServicesOptions, type CreateAgentSessionOptions, type CreateAgentSessionResult, type CreateAgentSessionRuntimeFactory, type CreateAgentSessionRuntimeResult, type CreateAgentSessionServicesOptions, createAgentSession, createAgentSessionFromServices, createAgentSessionRuntime, createAgentSessionServices, createBashTool, createCodingTools, createEditTool, createFindTool, createGrepTool, createLsTool, createReadOnlyTools, createReadTool, createWriteTool, type PromptTemplate, } from "./core/sdk.ts";
|
|
@@ -35,6 +35,10 @@ export { createSyntheticSourceInfo } from "./core/source-info.ts";
|
|
|
35
35
|
export { type EditDiffResult, generateDiffString, generateUnifiedPatch } from "./core/tools/edit-diff.ts";
|
|
36
36
|
export { type BashOperations, type BashSpawnContext, type BashSpawnHook, type BashToolDetails, type BashToolInput, type BashToolOptions, createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLocalBashOperations, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition, DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type EditOperations, type EditToolDetails, type EditToolInput, type EditToolOptions, type FindOperations, type FindToolDetails, type FindToolInput, type FindToolOptions, formatSize, type GrepOperations, type GrepToolDetails, type GrepToolInput, type GrepToolOptions, type LsOperations, type LsToolDetails, type LsToolInput, type LsToolOptions, type ReadOperations, type ReadToolDetails, type ReadToolInput, type ReadToolOptions, type ToolsOptions, type TruncationOptions, type TruncationResult, truncateHead, truncateLine, truncateTail, type WriteOperations, type WriteToolInput, type WriteToolOptions, withFileMutationQueue, } from "./core/tools/index.ts";
|
|
37
37
|
export { hasTrustRequiringProjectResources, type ProjectTrustDecision, ProjectTrustStore, type ProjectTrustStoreEntry, type ProjectTrustUpdate, } from "./core/trust-manager.ts";
|
|
38
|
+
export { generateCodebaseAuditScript, generateCodeReviewScript, generateDeepResearchScript, generateMultiPerspectiveScript, generateProductBuildScript, } from "./core/workflows/builtins.ts";
|
|
39
|
+
export { AgentRunner, type AgentRunOptions, type AgentRunResult, type AgentUsage, agentIdentityHash, createLimiter, DEFAULT_WORKFLOW_LIMITS, extractJson, messageText, parseWorkflowScript, runWorkflow, SharedStore, type WorkflowApi, WorkflowError, type WorkflowErrorCode, type WorkflowMeta, type WorkflowPhase, type WorkflowRunResult, } from "./core/workflows/index.ts";
|
|
40
|
+
export type { ResolveWorkflowResult } from "./core/workflows/resolve-script.ts";
|
|
41
|
+
export { listUserWorkflowScripts, resolveBuiltinWorkflowScript, resolveWorkflowScriptByName, } from "./core/workflows/resolve-script.ts";
|
|
38
42
|
export { type MainOptions, main } from "./main.ts";
|
|
39
43
|
export { InteractiveMode, type InteractiveModeOptions, type JsonAgentSessionEvent, type ModelInfo, type PrintModeOptions, RpcClient, type RpcClientOptions, type RpcCommand, type RpcEventListener, type RpcExtensionUIRequest, type RpcExtensionUIResponse, type RpcResponse, type RpcSessionState, runPrintMode, runRpcMode, } from "./modes/index.ts";
|
|
40
44
|
export { ArminComponent, AssistantMessageComponent, BashExecutionComponent, BorderedLoader, BranchSummaryMessageComponent, CompactionSummaryMessageComponent, CustomEditor, CustomMessageComponent, DynamicBorder, ExtensionEditorComponent, ExtensionInputComponent, ExtensionSelectorComponent, FooterComponent, keyHint, keyText, LoginDialogComponent, ModelSelectorComponent, OAuthSelectorComponent, type RenderDiffOptions, rawKeyHint, renderDiff, SessionSelectorComponent, type SettingsCallbacks, type SettingsConfig, SettingsSelectorComponent, ShowImagesSelectorComponent, SkillInvocationMessageComponent, ThemeSelectorComponent, ThinkingSelectorComponent, ToolExecutionComponent, type ToolExecutionOptions, TreeSelectorComponent, truncateToVisualLines, UserMessageComponent, UserMessageSelectorComponent, type VisualTruncateResult, } from "./modes/interactive/components/index.ts";
|