@abot-ai/runtime 1.9.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/scripts/add-runtime-model.js +11 -5
- package/dist/scripts/init-runtime.js +15 -10
- package/dist/scripts/runtime-model-addition.js +6 -1
- package/dist/scripts/runtime-setup-command-options.d.ts +11 -0
- package/dist/scripts/runtime-setup-command-options.js +41 -0
- package/dist/scripts/runtime-setup-files.d.ts +3 -2
- package/dist/scripts/runtime-setup-files.js +19 -4
- package/dist/scripts/runtime-setup-model-options.d.ts +8 -0
- package/dist/scripts/runtime-setup-model-options.js +40 -0
- package/dist/scripts/runtime-setup-presentation.js +2 -2
- package/dist/scripts/runtime-setup-provider-options.d.ts +4 -0
- package/dist/scripts/runtime-setup-provider-options.js +20 -0
- package/dist/src/model-gateway/client/contracts.d.ts +3 -0
- package/dist/src/model-gateway/client/input-token-count.js +36 -16
- package/dist/src/model-gateway/client/message-projection.d.ts +2 -0
- package/dist/src/model-gateway/client/message-projection.js +1 -0
- package/dist/src/model-gateway/client/options.js +1 -1
- package/dist/src/model-gateway/client/raw.js +1 -0
- package/dist/src/model-gateway/index.d.ts +1 -1
- package/dist/src/model-gateway/observability/input-token-count-diagnostics.d.ts +26 -0
- package/dist/src/model-gateway/observability/input-token-count-diagnostics.js +178 -0
- package/dist/src/model-gateway/policy/invocation-policy.d.ts +1 -3
- package/dist/src/model-gateway/policy/invocation-policy.js +3 -30
- package/dist/src/model-gateway/policy/reasoning-mode-budget.d.ts +5 -0
- package/dist/src/model-gateway/policy/reasoning-mode-budget.js +13 -0
- package/dist/src/model-gateway/policy/reasoning-policy.d.ts +10 -0
- package/dist/src/model-gateway/policy/reasoning-policy.js +124 -0
- package/dist/src/model-gateway/protocol/openai-embedding-response.d.ts +1 -0
- package/dist/src/model-gateway/protocol/openai-embedding-response.js +28 -0
- package/dist/src/model-gateway/protocol/sse-data.d.ts +9 -0
- package/dist/src/model-gateway/protocol/sse-data.js +67 -0
- package/dist/src/model-gateway/providers/envelope-budget.js +10 -1
- package/dist/src/model-gateway/providers/llamacpp/adapter.d.ts +2 -0
- package/dist/src/model-gateway/providers/llamacpp/adapter.js +79 -0
- package/dist/src/model-gateway/providers/llamacpp/connection.d.ts +9 -0
- package/dist/src/model-gateway/providers/llamacpp/connection.js +73 -0
- package/dist/src/model-gateway/providers/llamacpp/diagnostics.d.ts +2 -0
- package/dist/src/model-gateway/providers/llamacpp/diagnostics.js +17 -0
- package/dist/src/model-gateway/providers/llamacpp/embeddings.d.ts +2 -0
- package/dist/src/model-gateway/providers/llamacpp/embeddings.js +56 -0
- package/dist/src/model-gateway/providers/llamacpp/input-token-count.d.ts +3 -0
- package/dist/src/model-gateway/providers/llamacpp/input-token-count.js +59 -0
- package/dist/src/model-gateway/providers/llamacpp/message-projection.d.ts +2 -0
- package/dist/src/model-gateway/providers/llamacpp/message-projection.js +33 -0
- package/dist/src/model-gateway/providers/llamacpp/payload.d.ts +2 -0
- package/dist/src/model-gateway/providers/llamacpp/payload.js +44 -0
- package/dist/src/model-gateway/providers/llamacpp/response-lifetime.d.ts +1 -0
- package/dist/src/model-gateway/providers/llamacpp/response-lifetime.js +56 -0
- package/dist/src/model-gateway/providers/llamacpp/schema-format.d.ts +2 -0
- package/dist/src/model-gateway/providers/llamacpp/schema-format.js +29 -0
- package/dist/src/model-gateway/providers/llamacpp/settings.d.ts +9 -0
- package/dist/src/model-gateway/providers/llamacpp/settings.js +25 -0
- package/dist/src/model-gateway/providers/llamacpp/stream-normalizer.d.ts +10 -0
- package/dist/src/model-gateway/providers/llamacpp/stream-normalizer.js +85 -0
- package/dist/src/model-gateway/providers/llamacpp/stream.d.ts +9 -0
- package/dist/src/model-gateway/providers/llamacpp/stream.js +33 -0
- package/dist/src/model-gateway/providers/openai/embeddings.js +2 -29
- package/dist/src/model-gateway/providers/openai/sse-data.d.ts +1 -9
- package/dist/src/model-gateway/providers/openai/sse-data.js +1 -67
- package/dist/src/model-gateway/providers/registry.js +2 -0
- package/dist/src/model-gateway/server/input-token-count-handler.js +10 -1
- package/dist/src/model-gateway/types.d.ts +11 -1
- package/dist/src/runtime/adapters/long-term-memory/onboarding-provider-availability.d.ts +4 -0
- package/dist/src/runtime/adapters/long-term-memory/onboarding-provider-availability.js +11 -0
- package/dist/src/runtime/adapters/long-term-memory/onboarding-service.js +28 -1
- package/dist/src/runtime/adapters/registered-tool-payload-related-artifacts.d.ts +1 -0
- package/dist/src/runtime/adapters/registered-tool-payload-related-artifacts.js +6 -1
- package/dist/src/runtime/adapters/registered-tool-worker-capabilities/contracts.d.ts +1 -0
- package/dist/src/runtime/adapters/registered-tool-worker-capabilities/execution.d.ts +1 -0
- package/dist/src/runtime/adapters/registered-tool-worker-capabilities/execution.js +2 -0
- package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-lifecycle.d.ts +1 -0
- package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-lifecycle.js +2 -0
- package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-stages.d.ts +1 -0
- package/dist/src/runtime/adapters/registered-tool-worker-capabilities/payload-stages.js +1 -0
- package/dist/src/runtime/adapters/registered-tool-worker-capabilities.js +1 -0
- package/dist/src/runtime/adapters/scheduler-runtime.js +2 -0
- package/dist/src/runtime/automations/agent-step-executor.js +1 -0
- package/dist/src/runtime/automations/catalog.d.ts +3 -0
- package/dist/src/runtime/automations/catalog.js +2 -0
- package/dist/src/runtime/automations/definition-contracts.d.ts +2 -0
- package/dist/src/runtime/automations/definition-input.js +3 -1
- package/dist/src/runtime/automations/draft-mutations.js +5 -1
- package/dist/src/runtime/automations/model-dependency-projection.d.ts +3 -1
- package/dist/src/runtime/automations/model-dependency-projection.js +4 -2
- package/dist/src/runtime/automations/publication-validation.js +7 -0
- package/dist/src/runtime/automations/saved-agent-management.js +1 -0
- package/dist/src/runtime/automations/service.d.ts +3 -0
- package/dist/src/runtime/capabilities/automation-builder/payload-schema.js +7 -5
- package/dist/src/runtime/capabilities/automations/authoring-catalog.d.ts +9 -0
- package/dist/src/runtime/capabilities/automations/authoring-catalog.js +1 -0
- package/dist/src/runtime/capabilities/automations/authoring-preparation.d.ts +3 -0
- package/dist/src/runtime/capabilities/automations/tool-contract.js +3 -2
- package/dist/src/runtime/capabilities/automations/tool-module.js +16 -7
- package/dist/src/runtime/capabilities/model-reasoning-controls.d.ts +23 -0
- package/dist/src/runtime/capabilities/model-reasoning-controls.js +56 -0
- package/dist/src/runtime/capabilities/scheduling/create-operations.js +2 -0
- package/dist/src/runtime/capabilities/scheduling/job-list-page.d.ts +1 -0
- package/dist/src/runtime/capabilities/scheduling/tool-module.js +5 -2
- package/dist/src/runtime/capabilities/scheduling/update-operations.js +2 -0
- package/dist/src/runtime/config/builders.js +6 -0
- package/dist/src/runtime/config/effective-model-config-validation.js +4 -0
- package/dist/src/runtime/config/llamacpp-profile-validation.d.ts +3 -0
- package/dist/src/runtime/config/llamacpp-profile-validation.js +15 -0
- package/dist/src/runtime/config/model-reasoning-schema.d.ts +40 -0
- package/dist/src/runtime/config/model-reasoning-schema.js +38 -0
- package/dist/src/runtime/config/model-reasoning-validation.d.ts +3 -0
- package/dist/src/runtime/config/model-reasoning-validation.js +37 -0
- package/dist/src/runtime/config/runner/step-instructions.d.ts +4 -0
- package/dist/src/runtime/config/runner/step-instructions.js +10 -6
- package/dist/src/runtime/config/schema.js +3 -0
- package/dist/src/runtime/config/validation/model-invocation-config-validation.js +14 -0
- package/dist/src/runtime/context/compacted-capability-result-receipt.d.ts +2 -0
- package/dist/src/runtime/context/compacted-capability-result-receipt.js +8 -7
- package/dist/src/runtime/context/execution-compacted-evidence.d.ts +4 -0
- package/dist/src/runtime/context/execution-compacted-evidence.js +2 -23
- package/dist/src/runtime/context/execution-compaction-checkpoint-selection.d.ts +19 -0
- package/dist/src/runtime/context/execution-compaction-checkpoint-selection.js +104 -0
- package/dist/src/runtime/context/model-step-compaction-inheritance.d.ts +12 -0
- package/dist/src/runtime/context/model-step-compaction-inheritance.js +28 -0
- package/dist/src/runtime/context/model-step-compaction-projection.d.ts +12 -0
- package/dist/src/runtime/context/model-step-compaction-projection.js +322 -0
- package/dist/src/runtime/context/model-step-compaction.d.ts +2 -1
- package/dist/src/runtime/context/model-step-compaction.js +25 -316
- package/dist/src/runtime/context/operation-supervision-compacted-evidence.js +7 -1
- package/dist/src/runtime/context/request-context.d.ts +2 -0
- package/dist/src/runtime/context/request-context.js +16 -0
- package/dist/src/runtime/context/request-tool-results-checkpoint.d.ts +2 -1
- package/dist/src/runtime/context/request-tool-results-checkpoint.js +35 -6
- package/dist/src/runtime/context/request-tool-results.js +3 -1
- package/dist/src/runtime/context/semantic-compaction/checkpoint-message.d.ts +5 -1
- package/dist/src/runtime/context/semantic-compaction/checkpoint-message.js +10 -4
- package/dist/src/runtime/context/semantic-compaction/execution-evidence-instructions.d.ts +4 -0
- package/dist/src/runtime/context/semantic-compaction/execution-evidence-instructions.js +38 -0
- package/dist/src/runtime/context/semantic-compaction/generation-contracts.d.ts +3 -1
- package/dist/src/runtime/context/semantic-compaction/generation-input.js +15 -10
- package/dist/src/runtime/context/semantic-compaction/inherited-source-digests.d.ts +8 -0
- package/dist/src/runtime/context/semantic-compaction/inherited-source-digests.js +76 -0
- package/dist/src/runtime/context/semantic-compaction/replacement-budget.js +3 -1
- package/dist/src/runtime/context/semantic-compaction/run.js +6 -12
- package/dist/src/runtime/knowledge-skills/builtins/computer-use.js +1 -1
- package/dist/src/runtime/knowledge-skills/builtins/technical-work.js +20 -2
- package/dist/src/runtime/knowledge-skills/builtins/what-can-i-do.d.ts +2 -0
- package/dist/src/runtime/knowledge-skills/builtins/what-can-i-do.js +27 -0
- package/dist/src/runtime/knowledge-skills/catalog.js +2 -0
- package/dist/src/runtime/local-application.d.ts +5 -0
- package/dist/src/runtime/local-host/app-service-dispatch.d.ts +1 -1
- package/dist/src/runtime/local-host/app-service-dispatch.js +2 -0
- package/dist/src/runtime/local-host/client-services.d.ts +5 -0
- package/dist/src/runtime/local-host/saved-approvals.js +1 -0
- package/dist/src/runtime/long-term-memory/onboarding/configuration.js +5 -7
- package/dist/src/runtime/long-term-memory/onboarding/contracts.d.ts +26 -0
- package/dist/src/runtime/long-term-memory/onboarding/embedding-profile-id.d.ts +1 -0
- package/dist/src/runtime/long-term-memory/onboarding/embedding-profile-id.js +8 -0
- package/dist/src/runtime/long-term-memory/onboarding/saved-profiles.d.ts +17 -0
- package/dist/src/runtime/long-term-memory/onboarding/saved-profiles.js +77 -0
- package/dist/src/runtime/long-term-memory/onboarding/service.js +40 -10
- package/dist/src/runtime/model/input-token-count.js +1 -0
- package/dist/src/runtime/model/invoke-step.js +12 -0
- package/dist/src/runtime/model/invoke-structured-step.d.ts +4 -1
- package/dist/src/runtime/model/invoke-structured-step.js +4 -0
- package/dist/src/runtime/model/model-catalog.d.ts +3 -0
- package/dist/src/runtime/model/model-catalog.js +2 -0
- package/dist/src/runtime/model/model-context-budget.d.ts +5 -0
- package/dist/src/runtime/model/model-context-budget.js +2 -0
- package/dist/src/runtime/model/model-step-port.d.ts +7 -0
- package/dist/src/runtime/model/optional-context-admission.d.ts +18 -0
- package/dist/src/runtime/model/optional-context-admission.js +23 -0
- package/dist/src/runtime/ports.d.ts +3 -1
- package/dist/src/runtime/projects/contracts.d.ts +6 -0
- package/dist/src/runtime/projects/registry-format.d.ts +3 -0
- package/dist/src/runtime/projects/registry-format.js +50 -0
- package/dist/src/runtime/projects/repository.d.ts +6 -3
- package/dist/src/runtime/projects/repository.js +26 -19
- package/dist/src/runtime/projects/service.js +11 -0
- package/dist/src/runtime/request/approval-wait/preflight.js +1 -0
- package/dist/src/runtime/request/approval-wait/snapshot.d.ts +1 -1
- package/dist/src/runtime/request/approval-wait/snapshot.js +1 -0
- package/dist/src/runtime/request/contracts.d.ts +5 -1
- package/dist/src/runtime/request/execution-facets.js +2 -0
- package/dist/src/runtime/request/execution-payload-artifact-policy.d.ts +3 -0
- package/dist/src/runtime/request/execution-payload-artifact-policy.js +6 -0
- package/dist/src/runtime/request/execution-payload-compacted-evidence.js +1 -0
- package/dist/src/runtime/request/execution-scope-surfaces.d.ts +2 -0
- package/dist/src/runtime/request/execution-scope-surfaces.js +3 -0
- package/dist/src/runtime/request/execution-scope.d.ts +2 -0
- package/dist/src/runtime/request/execution-scope.js +2 -0
- package/dist/src/runtime/request/input.d.ts +1 -0
- package/dist/src/runtime/request/input.js +1 -0
- package/dist/src/runtime/request/prepared-execution.d.ts +1 -0
- package/dist/src/runtime/request/prepared-execution.js +3 -0
- package/dist/src/runtime/request/reasoning-preference.d.ts +10 -0
- package/dist/src/runtime/request/reasoning-preference.js +29 -0
- package/dist/src/runtime/request/root-reference-action.js +3 -3
- package/dist/src/runtime/request/root-skill-read-admission.d.ts +4 -0
- package/dist/src/runtime/request/root-skill-read-admission.js +14 -0
- package/dist/src/runtime/request/root-skill-read.js +13 -5
- package/dist/src/runtime/request/supervisor-skill-selection-window.d.ts +16 -0
- package/dist/src/runtime/request/supervisor-skill-selection-window.js +17 -0
- package/dist/src/runtime/request/worker-capability-composition.js +2 -0
- package/dist/src/runtime/scheduler/contracts.d.ts +7 -1
- package/dist/src/runtime/scheduler/job-management.js +7 -1
- package/dist/src/runtime/scheduler/run-records.js +2 -0
- package/dist/src/runtime/scheduler/schedule-validation.js +2 -0
- package/dist/src/runtime/scheduler/scheduler-engine.js +1 -0
- package/dist/src/runtime/scheduler/snapshot-validation.js +2 -0
- package/dist/src/runtime/steps/auditor-decision/projection.js +2 -0
- package/dist/src/runtime/steps/execution-agent/capability-controls-partition.d.ts +9 -0
- package/dist/src/runtime/steps/execution-agent/capability-controls-partition.js +29 -0
- package/dist/src/runtime/steps/execution-agent/capability-scope.d.ts +17 -0
- package/dist/src/runtime/steps/execution-agent/capability-scope.js +54 -0
- package/dist/src/runtime/steps/execution-agent/compaction.js +22 -6
- package/dist/src/runtime/steps/execution-agent/controls-compacted-evidence.js +2 -0
- package/dist/src/runtime/steps/execution-agent/evidence-reuse-instructions.d.ts +6 -0
- package/dist/src/runtime/steps/execution-agent/evidence-reuse-instructions.js +13 -0
- package/dist/src/runtime/steps/execution-agent/format.js +3 -6
- package/dist/src/runtime/steps/execution-agent/input.d.ts +5 -1
- package/dist/src/runtime/steps/execution-agent/input.js +10 -36
- package/dist/src/runtime/steps/execution-agent/observation-guidance.d.ts +11 -0
- package/dist/src/runtime/steps/execution-agent/observation-guidance.js +33 -0
- package/dist/src/runtime/steps/execution-agent/prompt.js +2 -0
- package/dist/src/runtime/steps/execution-agent/refinement.d.ts +3 -2
- package/dist/src/runtime/steps/execution-agent/refinement.js +17 -6
- package/dist/src/runtime/steps/execution-agent/run.js +7 -1
- package/dist/src/runtime/steps/skill-read-decision.d.ts +1 -0
- package/dist/src/runtime/steps/skill-read-decision.js +9 -4
- package/dist/src/runtime/steps/supervisor-decision/artifact-paths.d.ts +6 -1
- package/dist/src/runtime/steps/supervisor-decision/artifact-paths.js +15 -0
- package/dist/src/runtime/steps/supervisor-decision/contracts.d.ts +1 -1
- package/dist/src/runtime/steps/supervisor-decision/contracts.js +2 -0
- package/dist/src/runtime/steps/supervisor-decision/decision-phases.d.ts +3 -0
- package/dist/src/runtime/steps/supervisor-decision/decision-phases.js +22 -3
- package/dist/src/runtime/steps/supervisor-decision/delegation-contract.d.ts +9 -0
- package/dist/src/runtime/steps/supervisor-decision/delegation-contract.js +82 -0
- package/dist/src/runtime/steps/supervisor-decision/delegation-input.d.ts +7 -0
- package/dist/src/runtime/steps/supervisor-decision/delegation-input.js +105 -0
- package/dist/src/runtime/steps/supervisor-decision/delegation-prompt.d.ts +7 -0
- package/dist/src/runtime/steps/supervisor-decision/delegation-prompt.js +13 -0
- package/dist/src/runtime/steps/supervisor-decision/input.d.ts +1 -0
- package/dist/src/runtime/steps/supervisor-decision/preparation-input.d.ts +3 -5
- package/dist/src/runtime/steps/supervisor-decision/preparation-input.js +5 -21
- package/dist/src/runtime/steps/supervisor-decision/preparation.d.ts +4 -1
- package/dist/src/runtime/steps/supervisor-decision/preparation.js +58 -6
- package/dist/src/runtime/steps/supervisor-decision/procedure-entry.d.ts +22 -0
- package/dist/src/runtime/steps/supervisor-decision/procedure-entry.js +61 -0
- package/dist/src/runtime/steps/supervisor-decision/procedure-gate.d.ts +39 -0
- package/dist/src/runtime/steps/supervisor-decision/procedure-gate.js +146 -0
- package/dist/src/runtime/steps/supervisor-decision/procedure-memory.d.ts +9 -0
- package/dist/src/runtime/steps/supervisor-decision/procedure-memory.js +100 -0
- package/dist/src/runtime/steps/supervisor-decision/procedure-recall.d.ts +10 -0
- package/dist/src/runtime/steps/supervisor-decision/procedure-recall.js +52 -0
- package/dist/src/runtime/steps/supervisor-decision/prompt.js +3 -16
- package/dist/src/runtime/steps/supervisor-decision/response-recommendation.js +2 -2
- package/dist/src/runtime/steps/supervisor-decision/role-guidance.d.ts +3 -0
- package/dist/src/runtime/steps/supervisor-decision/role-guidance.js +20 -0
- package/dist/src/runtime/steps/supervisor-decision/run.js +50 -7
- package/dist/src/runtime/steps/supervisor-decision/skill-read-state.d.ts +10 -0
- package/dist/src/runtime/steps/supervisor-decision/skill-read-state.js +45 -0
- package/dist/src/runtime/steps/supervisor-decision/skill-selection-candidates.d.ts +15 -0
- package/dist/src/runtime/steps/supervisor-decision/skill-selection-candidates.js +25 -0
- package/dist/src/runtime/steps/supervisor-decision/skill-selection-catalog.d.ts +3 -0
- package/dist/src/runtime/steps/supervisor-decision/skill-selection-catalog.js +15 -0
- package/dist/src/runtime/steps/supervisor-decision/skill-selection-continuation.d.ts +10 -0
- package/dist/src/runtime/steps/supervisor-decision/skill-selection-continuation.js +65 -0
- package/dist/src/runtime/steps/supervisor-decision/skill-selection-input.d.ts +3 -1
- package/dist/src/runtime/steps/supervisor-decision/skill-selection-input.js +20 -22
- package/dist/src/runtime/steps/supervisor-decision/skill-selection.d.ts +3 -2
- package/dist/src/runtime/steps/supervisor-decision/skill-selection.js +62 -15
- package/dist/src/runtime/steps/supervisor-response/prompt.js +18 -4
- package/dist/src/shared/model-reasoning-modes.d.ts +5 -0
- package/dist/src/shared/model-reasoning-modes.js +20 -0
- package/dist/src/shared/model-reasoning-schema.d.ts +38 -0
- package/dist/src/shared/model-reasoning-schema.js +29 -0
- package/dist/src/shared/model-reasoning.d.ts +35 -0
- package/dist/src/shared/model-reasoning.js +100 -0
- package/dist/src/web-ui/app/ARCHITECTURE.md +13 -0
- package/dist/src/web-ui/app/app-bootstrap.js +9 -12
- package/dist/src/web-ui/app/app-dom.js +6 -1
- package/dist/src/web-ui/app/app-state.js +1 -0
- package/dist/src/web-ui/app/app.js +8 -3
- package/dist/src/web-ui/app/appearance-feature.js +28 -0
- package/dist/src/web-ui/app/automations-feature.js +20 -11
- package/dist/src/web-ui/app/components/appearance-dialog.js +79 -0
- package/dist/src/web-ui/app/components/automations/archive-actions.js +5 -3
- package/dist/src/web-ui/app/components/automations/authoring-entry.js +26 -7
- package/dist/src/web-ui/app/components/automations/confirmation-actions.js +78 -0
- package/dist/src/web-ui/app/components/automations/draft-recovery-actions.js +1 -0
- package/dist/src/web-ui/app/components/automations/node-inspector.js +5 -1
- package/dist/src/web-ui/app/components/automations/step-editor-dialog.js +4 -2
- package/dist/src/web-ui/app/components/automations/timeline.js +2 -2
- package/dist/src/web-ui/app/components/automations/workspace-navigation.js +37 -0
- package/dist/src/web-ui/app/components/automations/workspace.js +31 -46
- package/dist/src/web-ui/app/components/config-workspace/config-model.js +6 -0
- package/dist/src/web-ui/app/components/config-workspace/model-removal.js +4 -2
- package/dist/src/web-ui/app/components/config-workspace/model-rendering.js +8 -16
- package/dist/src/web-ui/app/components/config-workspace/reasoning-budget-edit.js +113 -0
- package/dist/src/web-ui/app/components/config-workspace/reasoning-budget.d.ts +16 -0
- package/dist/src/web-ui/app/components/config-workspace/reasoning-budget.js +67 -0
- package/dist/src/web-ui/app/components/config-workspace/reasoning-mode-budgets.d.ts +7 -0
- package/dist/src/web-ui/app/components/config-workspace/reasoning-mode-budgets.js +25 -0
- package/dist/src/web-ui/app/components/config-workspace/workspace-events.js +15 -7
- package/dist/src/web-ui/app/components/config-workspace/workspace-mutations.js +32 -12
- package/dist/src/web-ui/app/components/config-workspace/workspace-persistence.js +1 -1
- package/dist/src/web-ui/app/components/config-workspace.js +2 -1
- package/dist/src/web-ui/app/components/confirmation-dialog.js +88 -0
- package/dist/src/web-ui/app/components/conversation-activity.d.ts +2 -0
- package/dist/src/web-ui/app/components/conversation-activity.js +32 -3
- package/dist/src/web-ui/app/components/conversation-memory-activity.js +31 -0
- package/dist/src/web-ui/app/components/conversation-role-cards.d.ts +2 -0
- package/dist/src/web-ui/app/components/conversation-role-cards.js +14 -11
- package/dist/src/web-ui/app/components/conversation-skill-activity.js +67 -0
- package/dist/src/web-ui/app/components/conversation-tools.js +5 -5
- package/dist/src/web-ui/app/components/conversation-view.js +6 -0
- package/dist/src/web-ui/app/components/dashboard/approvals.js +13 -1
- package/dist/src/web-ui/app/components/long-term-memory/embedding-connection-dialog.d.ts +38 -0
- package/dist/src/web-ui/app/components/long-term-memory/embedding-connection-dialog.js +289 -0
- package/dist/src/web-ui/app/components/long-term-memory/embedding-connection-feature.js +75 -0
- package/dist/src/web-ui/app/components/long-term-memory/embedding-connection-rendering.js +31 -0
- package/dist/src/web-ui/app/components/long-term-memory/manager.js +15 -5
- package/dist/src/web-ui/app/components/long-term-memory/saved-embedding-profiles.js +114 -0
- package/dist/src/web-ui/app/components/long-term-memory/setup-rendering.js +55 -0
- package/dist/src/web-ui/app/components/long-term-memory-setup.js +141 -76
- package/dist/src/web-ui/app/components/model-setup/rendering.js +3 -2
- package/dist/src/web-ui/app/components/model-setup/validation.js +6 -2
- package/dist/src/web-ui/app/components/model-setup/wizard.d.ts +1 -0
- package/dist/src/web-ui/app/components/model-setup/wizard.js +28 -5
- package/dist/src/web-ui/app/components/passive-learning/memory.js +12 -5
- package/dist/src/web-ui/app/components/plugins/manager.js +14 -0
- package/dist/src/web-ui/app/components/plugins/removal.js +10 -2
- package/dist/src/web-ui/app/components/project-group-actions.js +35 -0
- package/dist/src/web-ui/app/components/project-session-groups.js +17 -31
- package/dist/src/web-ui/app/components/runtime-setup/commands.js +1 -1
- package/dist/src/web-ui/app/components/runtime-setup/connection-form.d.ts +15 -0
- package/dist/src/web-ui/app/components/runtime-setup/connection-form.js +32 -9
- package/dist/src/web-ui/app/components/runtime-setup/connection-input.js +23 -0
- package/dist/src/web-ui/app/components/runtime-setup/connection-inspection.js +57 -0
- package/dist/src/web-ui/app/components/runtime-setup/connection-state.js +18 -4
- package/dist/src/web-ui/app/components/runtime-setup/embedding-credential-status.js +3 -0
- package/dist/src/web-ui/app/components/runtime-setup/embedding-provider-options.js +54 -0
- package/dist/src/web-ui/app/components/runtime-setup/embedding-provider-receipt.js +3 -0
- package/dist/src/web-ui/app/components/runtime-setup/embedding-rendering.js +22 -22
- package/dist/src/web-ui/app/components/runtime-setup/embedding.js +60 -16
- package/dist/src/web-ui/app/components/runtime-setup/reasoning-fields.d.ts +17 -0
- package/dist/src/web-ui/app/components/runtime-setup/reasoning-fields.js +54 -0
- package/dist/src/web-ui/app/components/runtime-setup/validation.js +5 -1
- package/dist/src/web-ui/app/components/runtime-setup-guide.d.ts +9 -3
- package/dist/src/web-ui/app/components/runtime-setup-guide.js +20 -29
- package/dist/src/web-ui/app/components/schedules/details.js +2 -2
- package/dist/src/web-ui/app/components/schedules/form.js +12 -5
- package/dist/src/web-ui/app/components/schedules/workspace.js +30 -18
- package/dist/src/web-ui/app/components/session-list-viewport.js +49 -0
- package/dist/src/web-ui/app/components/session-search-disclosure.js +27 -0
- package/dist/src/web-ui/app/components/skills/workspace.js +7 -3
- package/dist/src/web-ui/app/components/spark-chat/panel.js +7 -3
- package/dist/src/web-ui/app/components/spark-chat/settings.js +57 -15
- package/dist/src/web-ui/app/components/tool-approval-card.d.ts +2 -1
- package/dist/src/web-ui/app/components/tool-approval-card.js +10 -2
- package/dist/src/web-ui/app/components/tool-approval-rejection-input.js +116 -0
- package/dist/src/web-ui/app/components/workspace-shell.js +30 -38
- package/dist/src/web-ui/app/components/workspace-transitions.js +42 -0
- package/dist/src/web-ui/app/configuration-feature.js +34 -4
- package/dist/src/web-ui/app/controllers/app-event-bindings.js +45 -29
- package/dist/src/web-ui/app/controllers/appearance-controller.js +105 -0
- package/dist/src/web-ui/app/controllers/automations-controller.js +9 -1
- package/dist/src/web-ui/app/controllers/composer-feature.d.ts +1 -1
- package/dist/src/web-ui/app/controllers/composer-feature.js +10 -3
- package/dist/src/web-ui/app/controllers/composer-queue-controller.d.ts +1 -1
- package/dist/src/web-ui/app/controllers/composer-queue-controller.js +9 -3
- package/dist/src/web-ui/app/controllers/composer-submission-lifecycle.d.ts +1 -1
- package/dist/src/web-ui/app/controllers/conversation-workspace-activation.js +8 -2
- package/dist/src/web-ui/app/controllers/dashboard-approvals-controller.js +10 -9
- package/dist/src/web-ui/app/controllers/environment-transition.js +2 -2
- package/dist/src/web-ui/app/controllers/environment-workspace-preparation.js +9 -7
- package/dist/src/web-ui/app/controllers/preference-view-sync.js +35 -0
- package/dist/src/web-ui/app/controllers/projects-controller.d.ts +4 -0
- package/dist/src/web-ui/app/controllers/projects-controller.js +64 -3
- package/dist/src/web-ui/app/controllers/reasoning-budget-controller.d.ts +17 -0
- package/dist/src/web-ui/app/controllers/reasoning-budget-controller.js +80 -0
- package/dist/src/web-ui/app/controllers/reasoning-budget-menu-events.js +45 -0
- package/dist/src/web-ui/app/controllers/reasoning-mode-controller.js +35 -40
- package/dist/src/web-ui/app/controllers/runtime-selection-controller.d.ts +6 -1
- package/dist/src/web-ui/app/controllers/runtime-selection-controller.js +16 -3
- package/dist/src/web-ui/app/controllers/session-controller.js +34 -9
- package/dist/src/web-ui/app/controllers/session-sidebar-controller.js +4 -3
- package/dist/src/web-ui/app/controllers/skills-controller.js +33 -16
- package/dist/src/web-ui/app/controllers/spark-chat-sync.js +1 -1
- package/dist/src/web-ui/app/controllers/spark-handoff-navigation.js +7 -1
- package/dist/src/web-ui/app/controllers/tool-approval-controller.d.ts +2 -1
- package/dist/src/web-ui/app/controllers/tool-approval-controller.js +36 -3
- package/dist/src/web-ui/app/controllers/workspace-conversation-opener.js +8 -2
- package/dist/src/web-ui/app/controllers/workspace-route-controller.js +41 -10
- package/dist/src/web-ui/app/index.html +38 -32
- package/dist/src/web-ui/app/lib/color-palettes.d.ts +17 -0
- package/dist/src/web-ui/app/lib/color-palettes.js +20 -0
- package/dist/src/web-ui/app/lib/memory-activity-model.d.ts +12 -0
- package/dist/src/web-ui/app/lib/memory-activity-model.js +61 -0
- package/dist/src/web-ui/app/lib/navigation-display.d.ts +8 -0
- package/dist/src/web-ui/app/lib/navigation-display.js +12 -0
- package/dist/src/web-ui/app/lib/reasoning-controls.js +47 -6
- package/dist/src/web-ui/app/lib/reasoning-preference.d.ts +9 -0
- package/dist/src/web-ui/app/lib/reasoning-preference.js +75 -0
- package/dist/src/web-ui/app/lib/session-composer-queue.d.ts +4 -0
- package/dist/src/web-ui/app/lib/session-composer-queue.js +4 -0
- package/dist/src/web-ui/app/lib/session-project-groups.js +28 -0
- package/dist/src/web-ui/app/lib/session-sidebar-order.js +7 -5
- package/dist/src/web-ui/app/lib/tool-activity-event.d.ts +1 -0
- package/dist/src/web-ui/app/lib/tool-activity-event.js +1 -0
- package/dist/src/web-ui/app/lib/tool-activity-model.d.ts +1 -0
- package/dist/src/web-ui/app/lib/tool-activity-model.js +1 -0
- package/dist/src/web-ui/app/lib/tool-approval-rejection-drafts.js +45 -0
- package/dist/src/web-ui/app/lib/tool-skill-activity-fields.js +1 -1
- package/dist/src/web-ui/app/notifications-feature.js +10 -2
- package/dist/src/web-ui/app/passive-learning-feature.js +2 -2
- package/dist/src/web-ui/app/projects-feature.js +40 -10
- package/dist/src/web-ui/app/runtime-onboarding-feature.js +1 -0
- package/dist/src/web-ui/app/schedules-feature.js +28 -5
- package/dist/src/web-ui/app/services/client-preferences.d.ts +4 -1
- package/dist/src/web-ui/app/services/client-preferences.js +2 -0
- package/dist/src/web-ui/app/services/conversation-reasoning-preferences.d.ts +11 -0
- package/dist/src/web-ui/app/services/conversation-reasoning-preferences.js +30 -0
- package/dist/src/web-ui/app/services/runtime-web-client/automations.js +6 -4
- package/dist/src/web-ui/app/services/runtime-web-client/configuration.js +5 -0
- package/dist/src/web-ui/app/services/runtime-web-client/memory.js +21 -0
- package/dist/src/web-ui/app/services/runtime-web-client/projects.d.ts +2 -1
- package/dist/src/web-ui/app/services/runtime-web-client/projects.js +4 -0
- package/dist/src/web-ui/app/services/runtime-web-client/tool-approvals.js +2 -0
- package/dist/src/web-ui/app/services/runtime-web-client.d.ts +16 -0
- package/dist/src/web-ui/app/services/runtime-web-client.js +2 -0
- package/dist/src/web-ui/app/services/session-sidebar-preferences.js +33 -13
- package/dist/src/web-ui/app/skills-feature.js +2 -3
- package/dist/src/web-ui/app/spark-chat-conversation.js +29 -3
- package/dist/src/web-ui/app/spark-chat-feature.js +13 -7
- package/dist/src/web-ui/app/styles/01-color-palettes.css +90 -0
- package/dist/src/web-ui/app/styles/11-product-links.css +6 -2
- package/dist/src/web-ui/app/styles/11-workspace-header-width.css +37 -25
- package/dist/src/web-ui/app/styles/12-conversation-sidebar.css +56 -22
- package/dist/src/web-ui/app/styles/13-projects.css +56 -19
- package/dist/src/web-ui/app/styles/19-runtime-setup.css +16 -0
- package/dist/src/web-ui/app/styles/22-reasoning-budget.css +39 -0
- package/dist/src/web-ui/app/styles/27-conversation-memory.css +45 -0
- package/dist/src/web-ui/app/styles/27-conversation-skills.css +96 -0
- package/dist/src/web-ui/app/styles/28-tool-approval-card.css +38 -1
- package/dist/src/web-ui/app/styles/35-embedding-profiles.css +159 -0
- package/dist/src/web-ui/app/styles/54-spark-chat.css +62 -46
- package/dist/src/web-ui/app/styles/65-appearance.css +60 -0
- package/dist/src/web-ui/app/styles/66-navigation-display.css +30 -0
- package/dist/src/web-ui/app/styles/67-confirmation-dialog.css +32 -0
- package/dist/src/web-ui/app/styles.css +8 -0
- package/dist/src/web-ui/client-state/preference-shapes.js +6 -1
- package/dist/src/web-ui/client-state/preferences.js +8 -2
- package/dist/src/web-ui/client-state/reasoning-preference-shape.d.ts +1 -0
- package/dist/src/web-ui/client-state/reasoning-preference-shape.js +18 -0
- package/dist/src/web-ui/local-runtime/api-router.d.ts +1 -0
- package/dist/src/web-ui/local-runtime/api-router.js +11 -0
- package/dist/src/web-ui/local-runtime/memory-embedding-connection-input.d.ts +7 -0
- package/dist/src/web-ui/local-runtime/memory-embedding-connection-input.js +22 -0
- package/dist/src/web-ui/local-runtime/memory-embedding-connection-service.d.ts +20 -0
- package/dist/src/web-ui/local-runtime/memory-embedding-connection-service.js +47 -0
- package/dist/src/web-ui/local-runtime/memory-onboarding-routes.js +32 -0
- package/dist/src/web-ui/local-runtime/model-connection-inspection.d.ts +7 -0
- package/dist/src/web-ui/local-runtime/model-connection-inspection.js +48 -0
- package/dist/src/web-ui/local-runtime/model-setup-catalog.d.ts +2 -1
- package/dist/src/web-ui/local-runtime/model-setup-catalog.js +3 -1
- package/dist/src/web-ui/local-runtime/model-setup-identity.js +1 -1
- package/dist/src/web-ui/local-runtime/model-setup-input.d.ts +5 -2
- package/dist/src/web-ui/local-runtime/model-setup-input.js +29 -6
- package/dist/src/web-ui/local-runtime/model-setup-provider.d.ts +1 -1
- package/dist/src/web-ui/local-runtime/model-setup-provider.js +9 -6
- package/dist/src/web-ui/local-runtime/model-setup-retry.js +4 -1
- package/dist/src/web-ui/local-runtime/model-setup-service.d.ts +2 -1
- package/dist/src/web-ui/local-runtime/pending-tool-approvals.js +4 -1
- package/dist/src/web-ui/local-runtime/project-routes.js +10 -2
- package/dist/src/web-ui/local-runtime/request-execution.js +1 -0
- package/dist/src/web-ui/local-runtime/runtime-setup-auth.d.ts +2 -0
- package/dist/src/web-ui/local-runtime/runtime-setup-auth.js +20 -0
- package/dist/src/web-ui/local-runtime/runtime-setup-connection-edit.js +3 -2
- package/dist/src/web-ui/local-runtime/runtime-setup-credential-completion.js +6 -1
- package/dist/src/web-ui/local-runtime/runtime-setup-input.d.ts +3 -2
- package/dist/src/web-ui/local-runtime/runtime-setup-input.js +17 -5
- package/dist/src/web-ui/local-runtime/runtime-setup-provider.d.ts +4 -1
- package/dist/src/web-ui/local-runtime/runtime-setup-provider.js +6 -2
- package/dist/src/web-ui/local-runtime/runtime-setup-routes.d.ts +11 -2
- package/dist/src/web-ui/local-runtime/runtime-setup-routes.js +11 -2
- package/dist/src/web-ui/local-runtime/runtime-setup-scaffold.js +3 -2
- package/dist/src/web-ui/local-runtime/runtime-setup-service.d.ts +25 -4
- package/dist/src/web-ui/local-runtime/runtime-setup-service.js +19 -9
- package/dist/src/web-ui/local-runtime/setup-embedding-input.d.ts +3 -1
- package/dist/src/web-ui/local-runtime/setup-embedding-input.js +38 -6
- package/dist/src/web-ui/local-runtime/setup-embedding-llamacpp.d.ts +11 -0
- package/dist/src/web-ui/local-runtime/setup-embedding-llamacpp.js +53 -0
- package/dist/src/web-ui/local-runtime/setup-embedding-provider.js +23 -9
- package/dist/src/web-ui/local-runtime/setup-embedding-routes.d.ts +7 -2
- package/dist/src/web-ui/local-runtime/setup-embedding-routes.js +5 -3
- package/dist/src/web-ui/local-runtime/setup-embedding-service.d.ts +1 -0
- package/docs/configuration.md +10 -8
- package/docs/installation.md +11 -5
- package/docs/llamacpp.md +248 -0
- package/docs/long-term-memory.md +12 -0
- package/docs/running-locally.md +7 -1
- package/package.json +2 -1
- package/plugins/project-orientation/source/index.ts +2 -3
- package/plugins/project-orientation/source/inspection-failure.ts +1 -1
- package/plugins/project-orientation/source/project-target.ts +29 -0
- package/plugins/project-orientation/src/index.cjs +21 -2
- package/runtime.config.schema.json +140 -0
- package/src/runtime/README.md +50 -4
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { traceDebug } from "../../runtime/observability/debug-logger.js";
|
|
3
|
+
import { classifyRuntimeErrorType } from "../../runtime/observability/error-type.js";
|
|
4
|
+
const TRANSPORT_CODES = new Set([
|
|
5
|
+
"ETIMEDOUT", "ECONNRESET", "ECONNREFUSED", "ECONNABORTED", "EPIPE",
|
|
6
|
+
"ENOTFOUND", "EAI_AGAIN", "ENETUNREACH", "EHOSTUNREACH",
|
|
7
|
+
"UND_ERR_CONNECT_TIMEOUT", "UND_ERR_HEADERS_TIMEOUT", "UND_ERR_BODY_TIMEOUT",
|
|
8
|
+
"UND_ERR_SOCKET", "UND_ERR_ABORTED", "ABORT_ERR", "ERR_INVALID_URL",
|
|
9
|
+
"CERT_HAS_EXPIRED", "DEPTH_ZERO_SELF_SIGNED_CERT", "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
10
|
+
]);
|
|
11
|
+
function boundedDiagnosticId(value) {
|
|
12
|
+
if (typeof value !== "string")
|
|
13
|
+
return undefined;
|
|
14
|
+
if (!/^[a-zA-Z0-9_.:/-]{1,200}$/.test(value))
|
|
15
|
+
return undefined;
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
function record(value) {
|
|
19
|
+
if (value === null || typeof value !== "object")
|
|
20
|
+
return {};
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function serializedBytes(value) {
|
|
24
|
+
try {
|
|
25
|
+
const serialized = JSON.stringify(value);
|
|
26
|
+
if (serialized === undefined)
|
|
27
|
+
return undefined;
|
|
28
|
+
return Buffer.byteLength(serialized);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function countRequestShape(request) {
|
|
35
|
+
const messages = Array.isArray(request.messages) ? request.messages : [];
|
|
36
|
+
let contentChars = 0;
|
|
37
|
+
let toolCallCount = 0;
|
|
38
|
+
let toolResultCount = 0;
|
|
39
|
+
let attachmentCount = 0;
|
|
40
|
+
for (const item of messages) {
|
|
41
|
+
const message = record(item);
|
|
42
|
+
if (typeof message.content === "string")
|
|
43
|
+
contentChars += message.content.length;
|
|
44
|
+
if (Array.isArray(message.toolCalls))
|
|
45
|
+
toolCallCount += message.toolCalls.length;
|
|
46
|
+
if (message.role === "tool")
|
|
47
|
+
toolResultCount += 1;
|
|
48
|
+
if (Array.isArray(message.attachments))
|
|
49
|
+
attachmentCount += message.attachments.length;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
messageCount: messages.length, contentChars, toolCallCount, toolResultCount,
|
|
53
|
+
attachmentCount, requestBytes: serializedBytes(request),
|
|
54
|
+
formatBytes: serializedBytes(request.format),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Only trusted classifications and allowlisted transport codes leave error objects. */
|
|
58
|
+
function countErrorDetails(error) {
|
|
59
|
+
const pending = [
|
|
60
|
+
{ value: error, relation: "error", depth: 0 },
|
|
61
|
+
];
|
|
62
|
+
const seen = new Set();
|
|
63
|
+
const entries = [];
|
|
64
|
+
while (pending.length > 0 && entries.length < 8) {
|
|
65
|
+
const current = pending.shift();
|
|
66
|
+
if (seen.has(current.value))
|
|
67
|
+
continue;
|
|
68
|
+
seen.add(current.value);
|
|
69
|
+
const value = record(current.value);
|
|
70
|
+
const code = typeof value.code === "string" && TRANSPORT_CODES.has(value.code)
|
|
71
|
+
? value.code : undefined;
|
|
72
|
+
const aggregate = current.value instanceof AggregateError ? current.value : undefined;
|
|
73
|
+
entries.push({
|
|
74
|
+
relation: current.relation,
|
|
75
|
+
type: aggregate ? "AggregateError" : classifyRuntimeErrorType(current.value),
|
|
76
|
+
...(code ? { code } : {}),
|
|
77
|
+
...(typeof value.errno === "number" && Number.isSafeInteger(value.errno)
|
|
78
|
+
? { errno: value.errno } : {}),
|
|
79
|
+
...(aggregate ? { aggregateErrorCount: aggregate.errors.length } : {}),
|
|
80
|
+
});
|
|
81
|
+
if (current.depth >= 2)
|
|
82
|
+
continue;
|
|
83
|
+
if (value.cause !== undefined) {
|
|
84
|
+
pending.push({ value: value.cause, relation: "cause", depth: current.depth + 1 });
|
|
85
|
+
}
|
|
86
|
+
if (!aggregate)
|
|
87
|
+
continue;
|
|
88
|
+
for (const inner of aggregate.errors.slice(0, 4)) {
|
|
89
|
+
pending.push({ value: inner, relation: "aggregate", depth: current.depth + 1 });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return entries;
|
|
93
|
+
}
|
|
94
|
+
/** Request-local metadata only. It never reads response bodies or alters failures. */
|
|
95
|
+
export class InputTokenCountDiagnostics {
|
|
96
|
+
scope;
|
|
97
|
+
requestBody;
|
|
98
|
+
startedAt = Date.now();
|
|
99
|
+
diagnosticId = randomUUID();
|
|
100
|
+
phase = "prepare";
|
|
101
|
+
invocation;
|
|
102
|
+
provider;
|
|
103
|
+
upstream = {};
|
|
104
|
+
constructor(scope, requestBody) {
|
|
105
|
+
this.scope = scope;
|
|
106
|
+
this.requestBody = requestBody;
|
|
107
|
+
}
|
|
108
|
+
setPhase(phase) { this.phase = phase; }
|
|
109
|
+
setProvider(provider) { this.provider = provider; }
|
|
110
|
+
bindInvocation(invocation) { this.invocation = invocation; }
|
|
111
|
+
observeFetch(fetchImpl) {
|
|
112
|
+
return async (input, init) => {
|
|
113
|
+
const startedAt = Date.now();
|
|
114
|
+
this.upstream = {
|
|
115
|
+
attempted: true,
|
|
116
|
+
requestBytes: typeof init?.body === "string" ? Buffer.byteLength(init.body) : undefined,
|
|
117
|
+
};
|
|
118
|
+
try {
|
|
119
|
+
const response = await fetchImpl(input, init);
|
|
120
|
+
this.upstream = {
|
|
121
|
+
...this.upstream, ...countFetchResponseMetadata(response, startedAt),
|
|
122
|
+
};
|
|
123
|
+
return response;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
this.upstream = {
|
|
127
|
+
...this.upstream, responseReceived: false, durationMs: Date.now() - startedAt,
|
|
128
|
+
errors: safelyCountErrorDetails(error),
|
|
129
|
+
};
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
failed(params) {
|
|
135
|
+
// Diagnostics must never replace the original terminal outcome.
|
|
136
|
+
try {
|
|
137
|
+
const invocation = this.invocation;
|
|
138
|
+
traceDebug(this.scope, "input_tokens.request.failed", {
|
|
139
|
+
diagnosticId: this.diagnosticId,
|
|
140
|
+
requestId: boundedDiagnosticId(this.requestBody.debugRequestId),
|
|
141
|
+
modelStep: boundedDiagnosticId(this.requestBody.modelStep),
|
|
142
|
+
phase: this.phase, failureKind: params.kind,
|
|
143
|
+
aborted: params.aborted, statusCode: params.statusCode,
|
|
144
|
+
durationMs: Date.now() - this.startedAt,
|
|
145
|
+
profileId: boundedDiagnosticId(invocation?.profile.id),
|
|
146
|
+
providerId: boundedDiagnosticId(invocation?.profile.providerId),
|
|
147
|
+
provider: boundedDiagnosticId(invocation?.profile.provider ?? this.provider),
|
|
148
|
+
model: boundedDiagnosticId(invocation?.model),
|
|
149
|
+
requestShape: countRequestShape(this.requestBody),
|
|
150
|
+
upstream: this.upstream,
|
|
151
|
+
...(params.error !== undefined ? { errors: safelyCountErrorDetails(params.error) } : {}),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// The existing transport/error mapping remains authoritative.
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function safelyCountErrorDetails(error) {
|
|
160
|
+
try {
|
|
161
|
+
return countErrorDetails(error);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return [{ type: "unknown", relation: "error" }];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function countFetchResponseMetadata(response, startedAt) {
|
|
168
|
+
const metadata = { responseReceived: true, durationMs: Date.now() - startedAt };
|
|
169
|
+
try {
|
|
170
|
+
return {
|
|
171
|
+
...metadata, statusCode: response.status,
|
|
172
|
+
requestId: boundedDiagnosticId(response.headers.get("x-request-id")),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return metadata;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export { normalizeReasoning, resolveThink } from "./reasoning-policy.js";
|
|
2
2
|
import type { ModelGatewayRequest, ResolvedModelInvocation } from "../types.js";
|
|
3
3
|
export type ModelInvocationResolutionErrorCode = "invalid_model_preference" | "model_profile_required" | "unknown_model_profile";
|
|
4
4
|
export declare class ModelInvocationResolutionError extends Error {
|
|
@@ -6,6 +6,4 @@ export declare class ModelInvocationResolutionError extends Error {
|
|
|
6
6
|
readonly statusCode = 400;
|
|
7
7
|
constructor(code: ModelInvocationResolutionErrorCode, detail: string);
|
|
8
8
|
}
|
|
9
|
-
export declare function resolveThink(agentMode: unknown): ModelReasoningLevel;
|
|
10
|
-
export declare function normalizeReasoning(value: unknown): ModelReasoningLevel | undefined;
|
|
11
9
|
export declare function resolveModelInvocation(requestBody: ModelGatewayRequest): ResolvedModelInvocation;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { resolveInvocationReasoning } from "./reasoning-policy.js";
|
|
2
|
+
export { normalizeReasoning, resolveThink } from "./reasoning-policy.js";
|
|
1
3
|
import { normalizeModelPreference, resolveClientPreferenceProfile, resolveConfiguredInvocationProfile, resolveProfileById, } from "./invocation-profile-policy.js";
|
|
2
4
|
export class ModelInvocationResolutionError extends Error {
|
|
3
5
|
code;
|
|
@@ -8,32 +10,6 @@ export class ModelInvocationResolutionError extends Error {
|
|
|
8
10
|
this.name = "ModelInvocationResolutionError";
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
|
-
export function resolveThink(agentMode) {
|
|
12
|
-
const mode = String(agentMode || "reasoning").toLowerCase();
|
|
13
|
-
if (mode === "deep")
|
|
14
|
-
return "high";
|
|
15
|
-
if (mode === "fast")
|
|
16
|
-
return "none";
|
|
17
|
-
return "medium";
|
|
18
|
-
}
|
|
19
|
-
export function normalizeReasoning(value) {
|
|
20
|
-
const normalized = String(value || "")
|
|
21
|
-
.trim()
|
|
22
|
-
.toLowerCase();
|
|
23
|
-
if (normalized === "none")
|
|
24
|
-
return "none";
|
|
25
|
-
if (normalized === "minimal")
|
|
26
|
-
return "minimal";
|
|
27
|
-
if (normalized === "low")
|
|
28
|
-
return "low";
|
|
29
|
-
if (normalized === "medium")
|
|
30
|
-
return "medium";
|
|
31
|
-
if (normalized === "high")
|
|
32
|
-
return "high";
|
|
33
|
-
if (normalized === "xhigh")
|
|
34
|
-
return "xhigh";
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
13
|
function applyInvocationProfileOverlay(candidate) {
|
|
38
14
|
const overlay = candidate.invocationProfile;
|
|
39
15
|
if (!overlay) {
|
|
@@ -161,13 +137,10 @@ export function resolveModelInvocation(requestBody) {
|
|
|
161
137
|
? { ...calibration.profile, model: overrideModel }
|
|
162
138
|
: calibration.profile;
|
|
163
139
|
const selectedInvocationProfile = calibration.invocationProfile ?? selectedCandidate.invocationProfile;
|
|
164
|
-
const think = normalizeReasoning(requestBody?.reasoningOverride) ??
|
|
165
|
-
profile.generation.reasoningEffort ??
|
|
166
|
-
resolveThink(requestBody?.agentMode);
|
|
167
140
|
return {
|
|
168
141
|
model: profile.model,
|
|
169
142
|
profile,
|
|
170
|
-
|
|
143
|
+
...resolveInvocationReasoning(requestBody, profile),
|
|
171
144
|
...(selectedInvocationProfile?.format
|
|
172
145
|
? { format: selectedInvocationProfile.format }
|
|
173
146
|
: {}),
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ModelReasoningBudget } from "../../shared/model-reasoning.js";
|
|
2
|
+
import type { ModelReasoningBudgetByMode } from "../../shared/model-reasoning-modes.js";
|
|
3
|
+
import type { ModelGatewayRequest } from "../types.js";
|
|
4
|
+
/** Conversation presets never replace a utility step's calibrated budget. */
|
|
5
|
+
export declare function resolveReasoningModeBudget(request: ModelGatewayRequest, mapping: ModelReasoningBudgetByMode | undefined): ModelReasoningBudget | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isRegisteredModelStepInLane } from "../../shared/model-step-registry.js";
|
|
2
|
+
/** Conversation presets never replace a utility step's calibrated budget. */
|
|
3
|
+
export function resolveReasoningModeBudget(request, mapping) {
|
|
4
|
+
if (!mapping)
|
|
5
|
+
return undefined;
|
|
6
|
+
if (request.modelStep !== undefined &&
|
|
7
|
+
!isRegisteredModelStepInLane(request.modelStep, "main"))
|
|
8
|
+
return undefined;
|
|
9
|
+
const mode = String(request.agentMode || "reasoning").toLowerCase();
|
|
10
|
+
if (!Object.hasOwn(mapping, mode))
|
|
11
|
+
return undefined;
|
|
12
|
+
return { mode: "tokens", tokens: mapping[mode] };
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ModelReasoningLevel } from "../../shared/types.js";
|
|
2
|
+
import { type ModelReasoningBudget } from "../../shared/model-reasoning.js";
|
|
3
|
+
import type { ModelGatewayRequest, ModelProfile } from "../types.js";
|
|
4
|
+
export declare function resolveThink(agentMode: unknown): ModelReasoningLevel;
|
|
5
|
+
export declare function normalizeReasoning(value: unknown): ModelReasoningLevel | undefined;
|
|
6
|
+
export declare function resolveInvocationReasoning(request: ModelGatewayRequest, profile: ModelProfile): {
|
|
7
|
+
think?: ModelReasoningLevel;
|
|
8
|
+
reasoningBudget?: ModelReasoningBudget;
|
|
9
|
+
reasoningControlSource?: "invocation" | "request" | "configuration" | "agent-mode";
|
|
10
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { parseModelReasoningBudgetByMode } from "../../shared/model-reasoning-modes.js";
|
|
2
|
+
import { resolveReasoningModeBudget } from "./reasoning-mode-budget.js";
|
|
3
|
+
import { isRegisteredModelStepInLane } from "../../shared/model-step-registry.js";
|
|
4
|
+
import { ModelReasoningConfigurationError, parseModelReasoningBudget, parseModelReasoningPreference, supportsModelReasoningBudget, } from "../../shared/model-reasoning.js";
|
|
5
|
+
import { resolveProfileById } from "./invocation-profile-policy.js";
|
|
6
|
+
export function resolveThink(agentMode) {
|
|
7
|
+
const mode = String(agentMode || "reasoning").toLowerCase();
|
|
8
|
+
if (mode === "deep")
|
|
9
|
+
return "high";
|
|
10
|
+
if (mode === "fast")
|
|
11
|
+
return "none";
|
|
12
|
+
return "medium";
|
|
13
|
+
}
|
|
14
|
+
export function normalizeReasoning(value) {
|
|
15
|
+
const normalized = String(value || "")
|
|
16
|
+
.trim()
|
|
17
|
+
.toLowerCase();
|
|
18
|
+
if (normalized === "none")
|
|
19
|
+
return "none";
|
|
20
|
+
if (normalized === "minimal")
|
|
21
|
+
return "minimal";
|
|
22
|
+
if (normalized === "low")
|
|
23
|
+
return "low";
|
|
24
|
+
if (normalized === "medium")
|
|
25
|
+
return "medium";
|
|
26
|
+
if (normalized === "high")
|
|
27
|
+
return "high";
|
|
28
|
+
if (normalized === "xhigh")
|
|
29
|
+
return "xhigh";
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
function assertReasoningBudgetSupport(profile) {
|
|
33
|
+
if (supportsModelReasoningBudget(profile))
|
|
34
|
+
return;
|
|
35
|
+
throw new ModelReasoningConfigurationError("reasoning_budget_unsupported", `profile ${profile.id} does not declare numeric reasoning controls`);
|
|
36
|
+
}
|
|
37
|
+
function resolveRequestedPreference(request) {
|
|
38
|
+
const preference = parseModelReasoningPreference(request.reasoningPreference);
|
|
39
|
+
if (!preference)
|
|
40
|
+
return undefined;
|
|
41
|
+
const boundProfile = resolveProfileById(preference.profileId, request.modelPolicy);
|
|
42
|
+
if (!boundProfile) {
|
|
43
|
+
throw new ModelReasoningConfigurationError("invalid_reasoning_preference", `unknown profile ${preference.profileId}`);
|
|
44
|
+
}
|
|
45
|
+
assertReasoningBudgetSupport(boundProfile);
|
|
46
|
+
return preference;
|
|
47
|
+
}
|
|
48
|
+
function canApplyReasoningPreference(request, profile, preference) {
|
|
49
|
+
if (!preference)
|
|
50
|
+
return false;
|
|
51
|
+
if (preference.profileId !== profile.id)
|
|
52
|
+
return false;
|
|
53
|
+
// Calls without a modelStep are direct public gateway calls. Registered
|
|
54
|
+
// utility calls retain their own calibration even when preference.scope=all.
|
|
55
|
+
if (request.modelStep === undefined)
|
|
56
|
+
return true;
|
|
57
|
+
return isRegisteredModelStepInLane(request.modelStep, "main");
|
|
58
|
+
}
|
|
59
|
+
function preferenceBudget(preference) {
|
|
60
|
+
if (preference.mode === "off")
|
|
61
|
+
return undefined;
|
|
62
|
+
if (preference.mode === "server-default")
|
|
63
|
+
return { mode: "server-default" };
|
|
64
|
+
return { mode: "tokens", tokens: preference.budgetTokens };
|
|
65
|
+
}
|
|
66
|
+
function isZeroReasoningBudget(budget) {
|
|
67
|
+
if (budget?.mode !== "tokens")
|
|
68
|
+
return false;
|
|
69
|
+
return budget.tokens === 0;
|
|
70
|
+
}
|
|
71
|
+
export function resolveInvocationReasoning(request, profile) {
|
|
72
|
+
const preference = resolveRequestedPreference(request);
|
|
73
|
+
const applies = canApplyReasoningPreference(request, profile, preference);
|
|
74
|
+
const configuredBudget = parseModelReasoningBudget(profile.generation.reasoningBudget);
|
|
75
|
+
const configuredModes = parseModelReasoningBudgetByMode(profile.generation.reasoningBudgetByMode);
|
|
76
|
+
if (configuredBudget || configuredModes)
|
|
77
|
+
assertReasoningBudgetSupport(profile);
|
|
78
|
+
const modeBudget = resolveReasoningModeBudget(request, configuredModes);
|
|
79
|
+
const override = normalizeReasoning(request.reasoningOverride);
|
|
80
|
+
const configuredThink = profile.generation.reasoningEffort ?? resolveThink(request.agentMode);
|
|
81
|
+
const preferredEffort = resolvePreferredEffort(applies ? preference : undefined, configuredThink);
|
|
82
|
+
const budget = applies
|
|
83
|
+
? preferenceBudget(preference)
|
|
84
|
+
: (modeBudget ?? configuredBudget);
|
|
85
|
+
const zeroBudgetDisablesThinking = isZeroReasoningBudget(budget);
|
|
86
|
+
const budgetEffort = zeroBudgetDisablesThinking ? "none" : undefined;
|
|
87
|
+
const enabledBudget = zeroBudgetDisablesThinking ? undefined : budget;
|
|
88
|
+
const think = override ??
|
|
89
|
+
budgetEffort ??
|
|
90
|
+
preferredEffort ??
|
|
91
|
+
(modeBudget && configuredThink === "none" ? "medium" : configuredThink);
|
|
92
|
+
const reasoningControlSource = resolveReasoningControlSource(override, applies, profile);
|
|
93
|
+
if (!preference && !configuredBudget && !modeBudget)
|
|
94
|
+
return { think: profile.supportsThinking ? think : undefined };
|
|
95
|
+
if (!profile.supportsThinking)
|
|
96
|
+
return { think: undefined, reasoningControlSource };
|
|
97
|
+
if (think === "none")
|
|
98
|
+
return { think, reasoningControlSource };
|
|
99
|
+
return {
|
|
100
|
+
think,
|
|
101
|
+
...(enabledBudget ? { reasoningBudget: enabledBudget } : {}),
|
|
102
|
+
reasoningControlSource,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function resolveReasoningControlSource(override, applies, profile) {
|
|
106
|
+
if (override)
|
|
107
|
+
return "invocation";
|
|
108
|
+
if (applies)
|
|
109
|
+
return "request";
|
|
110
|
+
if (profile.generation.reasoningEffort !== undefined)
|
|
111
|
+
return "configuration";
|
|
112
|
+
if (profile.generation.reasoningBudget !== undefined)
|
|
113
|
+
return "configuration";
|
|
114
|
+
if (profile.generation.reasoningBudgetByMode !== undefined)
|
|
115
|
+
return "configuration";
|
|
116
|
+
return "agent-mode";
|
|
117
|
+
}
|
|
118
|
+
function resolvePreferredEffort(preference, configuredThink) {
|
|
119
|
+
if (!preference)
|
|
120
|
+
return undefined;
|
|
121
|
+
if (preference.mode === "off")
|
|
122
|
+
return "none";
|
|
123
|
+
return configuredThink === "none" ? "medium" : configuredThink;
|
|
124
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readOpenAiCompatibleEmbeddingVectors(value: unknown, expectedCount: number): unknown[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function readOpenAiCompatibleEmbeddingVectors(value, expectedCount) {
|
|
2
|
+
const body = value && typeof value === "object" && !Array.isArray(value)
|
|
3
|
+
? value
|
|
4
|
+
: undefined;
|
|
5
|
+
if (!body || !Array.isArray(body.data)) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
const entries = body.data.filter(isRecord);
|
|
9
|
+
if (!hasContiguousIndices(entries, expectedCount)) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
return [...entries]
|
|
13
|
+
.sort((left, right) => Number(left.index) - Number(right.index))
|
|
14
|
+
.map((entry) => entry.embedding);
|
|
15
|
+
}
|
|
16
|
+
function hasContiguousIndices(entries, expectedCount) {
|
|
17
|
+
if (entries.length !== expectedCount) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const indices = new Set(entries.map(({ index }) => index));
|
|
21
|
+
return (indices.size === expectedCount &&
|
|
22
|
+
[...indices].every((index) => Number.isSafeInteger(index) &&
|
|
23
|
+
Number(index) >= 0 &&
|
|
24
|
+
Number(index) < expectedCount));
|
|
25
|
+
}
|
|
26
|
+
function isRecord(value) {
|
|
27
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class SseDataDecoder {
|
|
2
|
+
private readonly decoder;
|
|
3
|
+
private line;
|
|
4
|
+
private data;
|
|
5
|
+
private afterCr;
|
|
6
|
+
accept(bytes: Uint8Array): string[];
|
|
7
|
+
private acceptLine;
|
|
8
|
+
}
|
|
9
|
+
export declare function readSseDataFrames(body: ReadableStream<Uint8Array>): AsyncGenerator<string>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Decode complete SSE data frames identically for response lifetime and output.
|
|
2
|
+
// Event names are metadata; each provider owns its payload semantics.
|
|
3
|
+
export class SseDataDecoder {
|
|
4
|
+
decoder = new TextDecoder();
|
|
5
|
+
line = "";
|
|
6
|
+
data = [];
|
|
7
|
+
afterCr = false;
|
|
8
|
+
accept(bytes) {
|
|
9
|
+
const text = this.decoder.decode(bytes, { stream: true });
|
|
10
|
+
const frames = [];
|
|
11
|
+
let start = 0;
|
|
12
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
13
|
+
const char = text[index];
|
|
14
|
+
if (this.afterCr) {
|
|
15
|
+
this.afterCr = false;
|
|
16
|
+
if (char === "\n") {
|
|
17
|
+
start = index + 1;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (char !== "\r" && char !== "\n")
|
|
22
|
+
continue;
|
|
23
|
+
this.line += text.slice(start, index);
|
|
24
|
+
this.acceptLine(frames);
|
|
25
|
+
this.line = "";
|
|
26
|
+
this.afterCr = char === "\r";
|
|
27
|
+
start = index + 1;
|
|
28
|
+
}
|
|
29
|
+
this.line += text.slice(start);
|
|
30
|
+
return frames;
|
|
31
|
+
}
|
|
32
|
+
acceptLine(frames) {
|
|
33
|
+
if (!this.line) {
|
|
34
|
+
if (this.data.length)
|
|
35
|
+
frames.push(this.data.join("\n"));
|
|
36
|
+
this.data = [];
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const colon = this.line.indexOf(":");
|
|
40
|
+
const field = colon < 0 ? this.line : this.line.slice(0, colon);
|
|
41
|
+
if (field !== "data")
|
|
42
|
+
return;
|
|
43
|
+
const value = colon < 0 ? "" : this.line.slice(colon + 1);
|
|
44
|
+
this.data.push(value.startsWith(" ") ? value.slice(1) : value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export async function* readSseDataFrames(body) {
|
|
48
|
+
const reader = body.getReader();
|
|
49
|
+
const decoder = new SseDataDecoder();
|
|
50
|
+
let reachedEof = false;
|
|
51
|
+
try {
|
|
52
|
+
while (true) {
|
|
53
|
+
const { done, value } = await reader.read();
|
|
54
|
+
if (done) {
|
|
55
|
+
reachedEof = true;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
yield* decoder.accept(value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
// A tee branch cannot await cancellation before the other readers finish.
|
|
63
|
+
if (!reachedEof)
|
|
64
|
+
void reader.cancel().catch(() => { });
|
|
65
|
+
reader.releaseLock();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -5,7 +5,7 @@ export function estimateProviderEnvelopeInputTokens(payload, tokenEstimation) {
|
|
|
5
5
|
}
|
|
6
6
|
export function createProviderEnvelopeFingerprint(payload) {
|
|
7
7
|
return `sha256:${createHash("sha256")
|
|
8
|
-
.update(
|
|
8
|
+
.update(serializeFingerprintEnvelope(payload))
|
|
9
9
|
.digest("hex")}`;
|
|
10
10
|
}
|
|
11
11
|
export function resolveProviderEnvelopeInputTokens(params) {
|
|
@@ -34,6 +34,15 @@ function estimatedEnvelopeAssessment(params) {
|
|
|
34
34
|
measurementBinding: "missing",
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
+
// Grammar and template controls bind the measurement but are not prompt prose.
|
|
38
|
+
function serializeFingerprintEnvelope(payload) {
|
|
39
|
+
const selected = projectTokenBearingProviderEnvelope(payload);
|
|
40
|
+
for (const key of ["response_format", "chat_template_kwargs", "reasoning_effort"]) {
|
|
41
|
+
if (Object.hasOwn(payload, key))
|
|
42
|
+
selected[key] = payload[key];
|
|
43
|
+
}
|
|
44
|
+
return JSON.stringify(selected);
|
|
45
|
+
}
|
|
37
46
|
function serializeTokenBearingEnvelope(payload) {
|
|
38
47
|
return JSON.stringify(projectTokenBearingProviderEnvelope(payload));
|
|
39
48
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { fetchProviderWithTrace } from "../../model-io-trace.js";
|
|
2
|
+
import { toolMediaSafeError, toolMediaSafeEvent, toolMediaSafeMessage } from "../../observability/tool-media-privacy.js";
|
|
3
|
+
import { emitLlamaCppStreamTermination } from "./diagnostics.js";
|
|
4
|
+
import { embedWithLlamaCpp } from "./embeddings.js";
|
|
5
|
+
import { countLlamaCppInputTokens } from "./input-token-count.js";
|
|
6
|
+
import { buildLlamaCppChatPayload } from "./payload.js";
|
|
7
|
+
import { bindLlamaCppResponseLifetime } from "./response-lifetime.js";
|
|
8
|
+
import { resolveLlamaCppProviderSettings } from "./settings.js";
|
|
9
|
+
import { collectLlamaCppChatStream, forwardLlamaCppChatStream } from "./stream.js";
|
|
10
|
+
export function createLlamaCppProviderAdapter() {
|
|
11
|
+
return Object.freeze({
|
|
12
|
+
type: "llamacpp",
|
|
13
|
+
supportsImageInput: false,
|
|
14
|
+
embed: embedWithLlamaCpp,
|
|
15
|
+
countInputTokens: countLlamaCppInputTokens,
|
|
16
|
+
async invoke(params) {
|
|
17
|
+
let settings;
|
|
18
|
+
try {
|
|
19
|
+
settings = resolveLlamaCppProviderSettings(params.invocation.profile.providerConfig);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return { kind: "error", statusCode: 500, message: toolMediaSafeMessage(error instanceof Error ? error.message : "llamacpp_configuration_invalid", params.requestBody) };
|
|
23
|
+
}
|
|
24
|
+
const payload = buildLlamaCppChatPayload(params);
|
|
25
|
+
const { response, responseTrace } = await fetchProviderWithTrace({
|
|
26
|
+
endpoint: params.endpoint, requestBody: params.requestBody, invocation: params.invocation,
|
|
27
|
+
fetchImpl: async (input, init) => bindLlamaCppResponseLifetime(await params.fetchImpl(input, init)),
|
|
28
|
+
url: `${settings.apiUrl}/chat/completions`, headers: settings.headers, payload,
|
|
29
|
+
decodeResponse: collectLlamaCppChatStream,
|
|
30
|
+
});
|
|
31
|
+
if (!response.ok || !response.body) {
|
|
32
|
+
const message = await response.text();
|
|
33
|
+
await responseTrace;
|
|
34
|
+
return { kind: "error", statusCode: response.ok ? 502 : response.status,
|
|
35
|
+
message: toolMediaSafeMessage(message || "llamacpp error", params.requestBody) };
|
|
36
|
+
}
|
|
37
|
+
const startedAt = Date.now();
|
|
38
|
+
const body = response.body;
|
|
39
|
+
if (params.endpoint === "chat") {
|
|
40
|
+
return {
|
|
41
|
+
kind: "chat",
|
|
42
|
+
async stream(writer) {
|
|
43
|
+
let failure;
|
|
44
|
+
try {
|
|
45
|
+
await forwardLlamaCppChatStream(body, {
|
|
46
|
+
emit: (event) => writer.emit(toolMediaSafeEvent(event, params.requestBody)),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
failure = toolMediaSafeError(error, params.requestBody);
|
|
51
|
+
throw failure;
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
emitLlamaCppStreamTermination(params, startedAt, failure);
|
|
55
|
+
await responseTrace;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
let failure;
|
|
61
|
+
try {
|
|
62
|
+
const result = await collectLlamaCppChatStream(body);
|
|
63
|
+
return { kind: "raw", body: {
|
|
64
|
+
text: result.text, thinking: result.thinking,
|
|
65
|
+
...(result.usage ? { usage: result.usage } : {}),
|
|
66
|
+
...(result.doneReason ? { providerCompletionReason: result.doneReason } : {}),
|
|
67
|
+
} };
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
failure = toolMediaSafeError(error, params.requestBody);
|
|
71
|
+
throw failure;
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
emitLlamaCppStreamTermination(params, startedAt, failure);
|
|
75
|
+
await responseTrace;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Explicit read-only connection check; model capabilities remain user declarations. */
|
|
2
|
+
export declare function inspectLlamaCppConnection(params: {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
fetchImpl?: typeof fetch;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
models: readonly string[];
|
|
9
|
+
}>;
|