@jangts/agent-core 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/LICENSE +55 -0
- package/NOTICE +6 -0
- package/README.md +8 -0
- package/development/docs/README.en.md +70 -0
- package/development/docs/README.md +1 -1
- package/development/docs/acceptance.en.md +34 -0
- package/development/docs/agent-development.en.md +42 -0
- package/development/docs/api/README.en.md +62 -0
- package/development/docs/api/advanced-agents.en.md +135 -0
- package/development/docs/api/context-processing.en.md +110 -0
- package/development/docs/api/core.en.md +274 -0
- package/development/docs/api/examples.en.md +118 -0
- package/development/docs/api/kits.en.md +183 -0
- package/development/docs/api/knowledge-answering.en.md +166 -0
- package/development/docs/api/mock.en.md +186 -0
- package/development/docs/api/observability.en.md +166 -0
- package/development/docs/api/reference.en.md +2235 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.en.md +252 -0
- package/development/docs/api/support.md +27 -0
- package/development/docs/api/types.en.md +181 -0
- package/development/docs/api/workflow.en.md +188 -0
- package/development/docs/basic-usage.en.md +78 -0
- package/development/docs/create-app.en.md +76 -0
- package/development/docs/examples/offline-agent.en.md +273 -0
- package/development/docs/examples.en.md +36 -0
- package/development/docs/flows/knowledge-maintenance.en.md +38 -0
- package/development/docs/getting-started.en.md +71 -0
- package/development/docs/knowledge.en.md +89 -0
- package/development/docs/maintenance.en.md +62 -0
- package/development/docs/materials.en.md +38 -0
- package/development/docs/mechanisms.en.md +227 -0
- package/development/docs/memory-and-learning.en.md +42 -0
- package/development/docs/operations.en.md +51 -0
- package/development/docs/records.en.md +63 -0
- package/development/docs/registration.en.md +63 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +286 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +77 -16
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +46 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +62 -17
- package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
- package/development/skills/agent-core-app/templates/catalog.json +36 -22
- package/dist/cjs/capabilities/index.js +13 -0
- package/dist/cjs/capabilities/invocation.js +80 -10
- package/dist/cjs/capabilities/model.js +126 -13
- package/dist/cjs/capabilities/tool-runtime.js +64 -12
- package/dist/cjs/capabilities/tools.js +266 -31
- package/dist/cjs/context/assembly.js +46 -5
- package/dist/cjs/context/audit.js +31 -6
- package/dist/cjs/context/fragments.js +54 -11
- package/dist/cjs/context/index.js +12 -0
- package/dist/cjs/context/journal.js +84 -7
- package/dist/cjs/context/plan.js +30 -2
- package/dist/cjs/diagnostics/catalog.js +17 -3
- package/dist/cjs/diagnostics/index.js +149 -29
- package/dist/cjs/diagnostics/sub-flow.js +240 -40
- package/dist/cjs/errors.js +99 -17
- package/dist/cjs/execution/branch.js +20 -4
- package/dist/cjs/execution/engine.js +470 -56
- package/dist/cjs/execution/events.js +136 -18
- package/dist/cjs/execution/index.js +7 -0
- package/dist/cjs/execution/reporting.js +75 -6
- package/dist/cjs/execution/state.js +161 -22
- package/dist/cjs/execution/workflow.js +224 -32
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/kits/aggregation.js +45 -3
- package/dist/cjs/kits/answering/batch.js +23 -4
- package/dist/cjs/kits/answering/check-result.js +31 -8
- package/dist/cjs/kits/answering/checks.js +24 -3
- package/dist/cjs/kits/answering/flow.js +192 -36
- package/dist/cjs/kits/answering/index.js +19 -1
- package/dist/cjs/kits/answering/tasks.js +88 -13
- package/dist/cjs/kits/artifacts.js +36 -4
- package/dist/cjs/kits/candidates.js +47 -5
- package/dist/cjs/kits/delivery.js +40 -5
- package/dist/cjs/kits/durable.js +155 -31
- package/dist/cjs/kits/evidence.js +66 -15
- package/dist/cjs/kits/family.js +152 -22
- package/dist/cjs/kits/index.js +12 -1
- package/dist/cjs/kits/inference.js +104 -16
- package/dist/cjs/kits/intents/catalog.js +67 -16
- package/dist/cjs/kits/intents/index.js +11 -0
- package/dist/cjs/kits/intents/registry.js +188 -43
- package/dist/cjs/kits/intents/scopes.js +215 -46
- package/dist/cjs/kits/interaction/command.js +140 -36
- package/dist/cjs/kits/interaction/commands.js +86 -11
- package/dist/cjs/kits/interaction/handlers.js +27 -10
- package/dist/cjs/kits/interaction/index.js +10 -0
- package/dist/cjs/kits/interaction/transfer.js +80 -14
- package/dist/cjs/kits/knowledge/catalog.js +62 -11
- package/dist/cjs/kits/knowledge/index.js +16 -1
- package/dist/cjs/kits/knowledge/publication.js +99 -23
- package/dist/cjs/kits/knowledge/sections.js +33 -4
- package/dist/cjs/kits/normalization.js +51 -7
- package/dist/cjs/kits/policies.js +79 -15
- package/dist/cjs/kits/presentation/events.js +54 -10
- package/dist/cjs/kits/presentation/index.js +24 -1
- package/dist/cjs/kits/presentation/outputs.js +176 -38
- package/dist/cjs/kits/presentation/templates.js +33 -5
- package/dist/cjs/kits/presentation/variants.js +31 -2
- package/dist/cjs/kits/projection.js +63 -8
- package/dist/cjs/kits/rank-fusion.js +27 -4
- package/dist/cjs/kits/reflection-log-source.js +89 -16
- package/dist/cjs/kits/reflection.js +234 -60
- package/dist/cjs/kits/retrieval.js +98 -18
- package/dist/cjs/kits/search.js +180 -27
- package/dist/cjs/kits/text-skills.js +104 -19
- package/dist/cjs/kits/tools.js +415 -74
- package/dist/cjs/kits/vector-search.js +50 -16
- package/dist/cjs/mock/node.js +7 -1
- package/dist/cjs/mock/web.js +7 -1
- package/dist/cjs/mock.js +7 -1
- package/dist/cjs/model/binding.js +68 -17
- package/dist/cjs/model/call-budget.js +45 -4
- package/dist/cjs/model/decision-retry.js +19 -1
- package/dist/cjs/model/defaults.js +27 -4
- package/dist/cjs/model/index.js +7 -0
- package/dist/cjs/model/interactions/arguments.js +36 -1
- package/dist/cjs/model/interactions/json-object.js +48 -12
- package/dist/cjs/model/interactions/native-functions.js +52 -10
- package/dist/cjs/model/message-diagnostics.js +17 -4
- package/dist/cjs/model/options.js +9 -1
- package/dist/cjs/model/preparation.js +86 -12
- package/dist/cjs/model/runner.js +413 -79
- package/dist/cjs/model/selection-transport.js +48 -8
- package/dist/cjs/model/settings.js +67 -13
- package/dist/cjs/model/token-budget.js +69 -11
- package/dist/cjs/model/transports.js +59 -6
- package/dist/cjs/structs/common.js +11 -0
- package/dist/cjs/structs/debug.js +34 -5
- package/dist/cjs/structs/errors.js +26 -1
- package/dist/cjs/structs/index.js +11 -1
- package/dist/cjs/structs/kits/durable.js +7 -0
- package/dist/cjs/structs/kits/family.js +1 -0
- package/dist/cjs/structs/kits/interaction.js +8 -1
- package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
- package/dist/cjs/structs/kits/reflection.js +18 -3
- package/dist/cjs/structs/model/chat-provider.js +6 -0
- package/dist/cjs/structs/support/model/completion.js +2 -0
- package/dist/cjs/structs/support/model/messages.js +2 -0
- package/dist/cjs/support/capabilities.js +43 -6
- package/dist/cjs/support/context/assembly.js +88 -16
- package/dist/cjs/support/context/compression.js +48 -6
- package/dist/cjs/support/context/fragments.js +6 -0
- package/dist/cjs/support/context/history.js +36 -1
- package/dist/cjs/support/context/index.js +11 -0
- package/dist/cjs/support/context/nodes.js +164 -35
- package/dist/cjs/support/context/processing.js +319 -61
- package/dist/cjs/support/context/selection-policy.js +98 -21
- package/dist/cjs/support/context/selection.js +61 -10
- package/dist/cjs/support/context/snapshot.js +29 -7
- package/dist/cjs/support/context/strategies.js +120 -28
- package/dist/cjs/support/index.js +9 -1
- package/dist/cjs/support/model/capabilities.js +20 -1
- package/dist/cjs/support/model/chat-completions.js +92 -20
- package/dist/cjs/support/model/children.js +34 -6
- package/dist/cjs/support/model/compatible-provider.js +189 -59
- package/dist/cjs/support/model/completion/calls.js +61 -0
- package/dist/cjs/support/model/completion/default.js +33 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +107 -0
- package/dist/cjs/support/model/index.js +12 -0
- package/dist/cjs/support/model/interactions/index.js +12 -1
- package/dist/cjs/support/model/interactions/json-object.js +6 -0
- package/dist/cjs/support/model/interactions/native-functions.js +6 -0
- package/dist/cjs/support/model/observer.js +32 -6
- package/dist/cjs/support/model/preview-rules.js +66 -16
- package/dist/cjs/support/model/reply-preview.js +77 -17
- package/dist/cjs/support/model/stage-transport.js +33 -7
- package/dist/cjs/support/model/strategies.js +75 -14
- package/dist/cjs/support/model/transports.js +53 -11
- package/dist/cjs/support/registration.js +49 -7
- package/dist/cjs/support/schema.js +46 -4
- package/dist/cjs/support/stream-events.js +60 -8
- package/dist/cjs/support/tool-runtime.js +6 -0
- package/dist/cjs/support/tools.js +79 -10
- package/dist/cjs/support/transport/index.js +7 -0
- package/dist/cjs/support/transport/json.js +28 -4
- package/dist/cjs/support/transport/sse.js +25 -2
- package/dist/cjs/utils/break-observer.js +20 -2
- package/dist/cjs/utils/cancellation.js +77 -9
- package/dist/cjs/utils/catalog.js +19 -4
- package/dist/cjs/utils/debug.js +14 -2
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/interaction-definition.js +26 -6
- package/dist/cjs/utils/invocation.js +42 -4
- package/dist/cjs/utils/model-protocol.js +20 -1
- package/dist/cjs/utils/object.js +16 -0
- package/dist/cjs/utils/observer.js +22 -2
- package/dist/cjs/utils/protocol-registry.js +47 -4
- package/dist/cjs/utils/query-key.js +21 -2
- package/dist/cjs/utils/registration.js +18 -2
- package/dist/cjs/utils/rules.js +39 -11
- package/dist/cjs/utils/schema-adapter.js +25 -2
- package/dist/cjs/utils/synchronous.js +64 -7
- package/dist/cjs/utils/text.js +15 -1
- package/dist/esm/capabilities/index.d.ts +13 -0
- package/dist/esm/capabilities/index.js +13 -0
- package/dist/esm/capabilities/invocation.d.ts +16 -2
- package/dist/esm/capabilities/invocation.js +80 -10
- package/dist/esm/capabilities/model.d.ts +68 -1
- package/dist/esm/capabilities/model.js +126 -13
- package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
- package/dist/esm/capabilities/tool-runtime.js +64 -12
- package/dist/esm/capabilities/tools.d.ts +96 -3
- package/dist/esm/capabilities/tools.js +267 -32
- package/dist/esm/context/assembly.d.ts +13 -2
- package/dist/esm/context/assembly.js +46 -5
- package/dist/esm/context/audit.d.ts +23 -1
- package/dist/esm/context/audit.js +31 -6
- package/dist/esm/context/fragments.d.ts +37 -3
- package/dist/esm/context/fragments.js +54 -11
- package/dist/esm/context/index.d.ts +12 -0
- package/dist/esm/context/index.js +12 -0
- package/dist/esm/context/journal.d.ts +32 -1
- package/dist/esm/context/journal.js +84 -7
- package/dist/esm/context/plan.d.ts +11 -1
- package/dist/esm/context/plan.js +30 -2
- package/dist/esm/diagnostics/catalog.d.ts +6 -0
- package/dist/esm/diagnostics/catalog.js +17 -3
- package/dist/esm/diagnostics/index.d.ts +30 -2
- package/dist/esm/diagnostics/index.js +149 -29
- package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
- package/dist/esm/diagnostics/sub-flow.js +240 -40
- package/dist/esm/errors.d.ts +22 -2
- package/dist/esm/errors.js +99 -17
- package/dist/esm/execution/branch.d.ts +19 -1
- package/dist/esm/execution/branch.js +20 -4
- package/dist/esm/execution/engine.d.ts +291 -5
- package/dist/esm/execution/engine.js +471 -57
- package/dist/esm/execution/events.d.ts +16 -2
- package/dist/esm/execution/events.js +136 -18
- package/dist/esm/execution/index.d.ts +7 -0
- package/dist/esm/execution/index.js +7 -0
- package/dist/esm/execution/reporting.d.ts +49 -1
- package/dist/esm/execution/reporting.js +75 -6
- package/dist/esm/execution/state.d.ts +126 -10
- package/dist/esm/execution/state.js +161 -22
- package/dist/esm/execution/workflow.d.ts +121 -3
- package/dist/esm/execution/workflow.js +224 -32
- package/dist/esm/index.d.ts +17 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/kits/aggregation.d.ts +34 -2
- package/dist/esm/kits/aggregation.js +45 -3
- package/dist/esm/kits/answering/batch.d.ts +17 -0
- package/dist/esm/kits/answering/batch.js +23 -4
- package/dist/esm/kits/answering/check-result.d.ts +18 -1
- package/dist/esm/kits/answering/check-result.js +31 -8
- package/dist/esm/kits/answering/checks.d.ts +11 -0
- package/dist/esm/kits/answering/checks.js +24 -3
- package/dist/esm/kits/answering/flow.d.ts +25 -2
- package/dist/esm/kits/answering/flow.js +192 -36
- package/dist/esm/kits/answering/index.d.ts +12 -0
- package/dist/esm/kits/answering/index.js +19 -1
- package/dist/esm/kits/answering/tasks.d.ts +32 -1
- package/dist/esm/kits/answering/tasks.js +88 -13
- package/dist/esm/kits/artifacts.d.ts +11 -0
- package/dist/esm/kits/artifacts.js +36 -4
- package/dist/esm/kits/candidates.d.ts +23 -1
- package/dist/esm/kits/candidates.js +47 -5
- package/dist/esm/kits/delivery.d.ts +34 -0
- package/dist/esm/kits/delivery.js +40 -5
- package/dist/esm/kits/durable.d.ts +19 -0
- package/dist/esm/kits/durable.js +155 -31
- package/dist/esm/kits/evidence.d.ts +28 -5
- package/dist/esm/kits/evidence.js +66 -15
- package/dist/esm/kits/family.d.ts +17 -1
- package/dist/esm/kits/family.js +152 -22
- package/dist/esm/kits/index.d.ts +12 -1
- package/dist/esm/kits/index.js +12 -1
- package/dist/esm/kits/inference.d.ts +64 -0
- package/dist/esm/kits/inference.js +104 -16
- package/dist/esm/kits/intents/catalog.d.ts +13 -1
- package/dist/esm/kits/intents/catalog.js +67 -16
- package/dist/esm/kits/intents/index.d.ts +11 -0
- package/dist/esm/kits/intents/index.js +11 -0
- package/dist/esm/kits/intents/registry.d.ts +61 -3
- package/dist/esm/kits/intents/registry.js +188 -43
- package/dist/esm/kits/intents/scopes.d.ts +73 -3
- package/dist/esm/kits/intents/scopes.js +215 -46
- package/dist/esm/kits/interaction/command.d.ts +38 -4
- package/dist/esm/kits/interaction/command.js +140 -36
- package/dist/esm/kits/interaction/commands.d.ts +66 -2
- package/dist/esm/kits/interaction/commands.js +86 -11
- package/dist/esm/kits/interaction/handlers.d.ts +19 -2
- package/dist/esm/kits/interaction/handlers.js +27 -10
- package/dist/esm/kits/interaction/index.d.ts +10 -0
- package/dist/esm/kits/interaction/index.js +10 -0
- package/dist/esm/kits/interaction/transfer.d.ts +39 -2
- package/dist/esm/kits/interaction/transfer.js +80 -14
- package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
- package/dist/esm/kits/knowledge/catalog.js +62 -11
- package/dist/esm/kits/knowledge/index.d.ts +11 -0
- package/dist/esm/kits/knowledge/index.js +16 -1
- package/dist/esm/kits/knowledge/publication.d.ts +15 -1
- package/dist/esm/kits/knowledge/publication.js +99 -23
- package/dist/esm/kits/knowledge/sections.d.ts +31 -1
- package/dist/esm/kits/knowledge/sections.js +33 -4
- package/dist/esm/kits/normalization.d.ts +25 -2
- package/dist/esm/kits/normalization.js +51 -7
- package/dist/esm/kits/policies.d.ts +26 -3
- package/dist/esm/kits/policies.js +79 -15
- package/dist/esm/kits/presentation/events.d.ts +51 -4
- package/dist/esm/kits/presentation/events.js +54 -10
- package/dist/esm/kits/presentation/index.d.ts +12 -0
- package/dist/esm/kits/presentation/index.js +25 -2
- package/dist/esm/kits/presentation/outputs.d.ts +30 -1
- package/dist/esm/kits/presentation/outputs.js +176 -38
- package/dist/esm/kits/presentation/templates.d.ts +32 -3
- package/dist/esm/kits/presentation/templates.js +33 -5
- package/dist/esm/kits/presentation/variants.d.ts +29 -0
- package/dist/esm/kits/presentation/variants.js +31 -2
- package/dist/esm/kits/projection.d.ts +42 -5
- package/dist/esm/kits/projection.js +63 -8
- package/dist/esm/kits/rank-fusion.d.ts +21 -1
- package/dist/esm/kits/rank-fusion.js +28 -5
- package/dist/esm/kits/reflection-log-source.d.ts +28 -1
- package/dist/esm/kits/reflection-log-source.js +89 -16
- package/dist/esm/kits/reflection.d.ts +17 -1
- package/dist/esm/kits/reflection.js +235 -61
- package/dist/esm/kits/retrieval.d.ts +18 -2
- package/dist/esm/kits/retrieval.js +98 -18
- package/dist/esm/kits/search.d.ts +56 -3
- package/dist/esm/kits/search.js +180 -27
- package/dist/esm/kits/text-skills.d.ts +16 -2
- package/dist/esm/kits/text-skills.js +104 -19
- package/dist/esm/kits/tools.d.ts +122 -2
- package/dist/esm/kits/tools.js +416 -74
- package/dist/esm/kits/vector-search.d.ts +47 -1
- package/dist/esm/kits/vector-search.js +51 -17
- package/dist/esm/mock/node.d.ts +7 -0
- package/dist/esm/mock/node.js +7 -1
- package/dist/esm/mock/web.d.ts +7 -0
- package/dist/esm/mock/web.js +7 -1
- package/dist/esm/mock.d.ts +7 -0
- package/dist/esm/mock.js +7 -1
- package/dist/esm/model/binding.d.ts +32 -3
- package/dist/esm/model/binding.js +68 -17
- package/dist/esm/model/call-budget.d.ts +30 -2
- package/dist/esm/model/call-budget.js +45 -4
- package/dist/esm/model/decision-retry.d.ts +10 -1
- package/dist/esm/model/decision-retry.js +19 -1
- package/dist/esm/model/defaults.d.ts +13 -2
- package/dist/esm/model/defaults.js +27 -4
- package/dist/esm/model/index.d.ts +7 -0
- package/dist/esm/model/index.js +7 -0
- package/dist/esm/model/interactions/arguments.d.ts +27 -0
- package/dist/esm/model/interactions/arguments.js +36 -1
- package/dist/esm/model/interactions/json-object.d.ts +7 -1
- package/dist/esm/model/interactions/json-object.js +48 -12
- package/dist/esm/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/model/interactions/native-functions.js +52 -10
- package/dist/esm/model/message-diagnostics.d.ts +17 -1
- package/dist/esm/model/message-diagnostics.js +17 -4
- package/dist/esm/model/options.d.ts +18 -1
- package/dist/esm/model/options.js +9 -1
- package/dist/esm/model/preparation.d.ts +30 -2
- package/dist/esm/model/preparation.js +86 -12
- package/dist/esm/model/runner.d.ts +129 -5
- package/dist/esm/model/runner.js +414 -80
- package/dist/esm/model/selection-transport.d.ts +14 -1
- package/dist/esm/model/selection-transport.js +48 -8
- package/dist/esm/model/settings.d.ts +11 -0
- package/dist/esm/model/settings.js +67 -13
- package/dist/esm/model/token-budget.d.ts +59 -1
- package/dist/esm/model/token-budget.js +69 -11
- package/dist/esm/model/transports.d.ts +20 -2
- package/dist/esm/model/transports.js +59 -6
- package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
- package/dist/esm/structs/capabilities/model.d.ts +27 -0
- package/dist/esm/structs/capabilities/tools.d.ts +38 -0
- package/dist/esm/structs/common.d.ts +62 -2
- package/dist/esm/structs/common.js +11 -0
- package/dist/esm/structs/context/fragments.d.ts +28 -0
- package/dist/esm/structs/context/journal.d.ts +28 -3
- package/dist/esm/structs/context/processing.d.ts +11 -0
- package/dist/esm/structs/debug.d.ts +58 -1
- package/dist/esm/structs/debug.js +34 -5
- package/dist/esm/structs/diagnostics.d.ts +119 -1
- package/dist/esm/structs/errors.d.ts +42 -1
- package/dist/esm/structs/errors.js +26 -1
- package/dist/esm/structs/execution/engine.d.ts +24 -1
- package/dist/esm/structs/execution/events.d.ts +12 -0
- package/dist/esm/structs/execution/workflow.d.ts +71 -0
- package/dist/esm/structs/index.d.ts +11 -1
- package/dist/esm/structs/index.js +11 -1
- package/dist/esm/structs/invocation.d.ts +30 -0
- package/dist/esm/structs/kits/aggregation.d.ts +12 -0
- package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
- package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
- package/dist/esm/structs/kits/answering/state.d.ts +21 -0
- package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
- package/dist/esm/structs/kits/artifacts.d.ts +14 -0
- package/dist/esm/structs/kits/candidates.d.ts +19 -0
- package/dist/esm/structs/kits/delivery.d.ts +22 -0
- package/dist/esm/structs/kits/durable.d.ts +56 -3
- package/dist/esm/structs/kits/durable.js +7 -0
- package/dist/esm/structs/kits/evidence.d.ts +23 -0
- package/dist/esm/structs/kits/family.d.ts +49 -1
- package/dist/esm/structs/kits/family.js +1 -0
- package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
- package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
- package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
- package/dist/esm/structs/kits/interaction.d.ts +64 -0
- package/dist/esm/structs/kits/interaction.js +8 -1
- package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
- package/dist/esm/structs/kits/knowledge-publication.js +1 -0
- package/dist/esm/structs/kits/knowledge.d.ts +39 -2
- package/dist/esm/structs/kits/normalization.d.ts +15 -0
- package/dist/esm/structs/kits/policies.d.ts +25 -1
- package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
- package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
- package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
- package/dist/esm/structs/kits/projection.d.ts +21 -0
- package/dist/esm/structs/kits/reflection.d.ts +61 -2
- package/dist/esm/structs/kits/reflection.js +18 -3
- package/dist/esm/structs/kits/retrieval.d.ts +39 -0
- package/dist/esm/structs/kits/search.d.ts +24 -0
- package/dist/esm/structs/kits/text-skills.d.ts +36 -0
- package/dist/esm/structs/kits/tools.d.ts +87 -0
- package/dist/esm/structs/model/chat-provider.d.ts +24 -1
- package/dist/esm/structs/model/chat-provider.js +6 -0
- package/dist/esm/structs/model/interactions.d.ts +38 -0
- package/dist/esm/structs/model/messages.d.ts +34 -0
- package/dist/esm/structs/model/runtime.d.ts +104 -6
- package/dist/esm/structs/support/capabilities.d.ts +19 -2
- package/dist/esm/structs/support/context-processing.d.ts +88 -9
- package/dist/esm/structs/support/context.d.ts +29 -1
- package/dist/esm/structs/support/model/completion.d.ts +50 -0
- package/dist/esm/structs/support/model/completion.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +13 -1
- package/dist/esm/structs/support/model/messages.d.ts +54 -0
- package/dist/esm/structs/support/model/messages.js +1 -0
- package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
- package/dist/esm/structs/support/model/provider.d.ts +71 -6
- package/dist/esm/structs/support/registration.d.ts +13 -0
- package/dist/esm/structs/support/schema.d.ts +14 -0
- package/dist/esm/structs/support/tools.d.ts +28 -0
- package/dist/esm/structs/support/transport/json.d.ts +16 -0
- package/dist/esm/structs/support/transport/sse.d.ts +15 -0
- package/dist/esm/structs/utils/rules.d.ts +19 -0
- package/dist/esm/support/capabilities.d.ts +25 -2
- package/dist/esm/support/capabilities.js +43 -6
- package/dist/esm/support/context/assembly.d.ts +35 -4
- package/dist/esm/support/context/assembly.js +88 -16
- package/dist/esm/support/context/compression.d.ts +17 -1
- package/dist/esm/support/context/compression.js +48 -6
- package/dist/esm/support/context/fragments.d.ts +6 -0
- package/dist/esm/support/context/fragments.js +6 -0
- package/dist/esm/support/context/history.d.ts +43 -0
- package/dist/esm/support/context/history.js +36 -1
- package/dist/esm/support/context/index.d.ts +13 -2
- package/dist/esm/support/context/index.js +12 -1
- package/dist/esm/support/context/nodes.d.ts +65 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +152 -1
- package/dist/esm/support/context/processing.js +320 -62
- package/dist/esm/support/context/selection-policy.d.ts +42 -2
- package/dist/esm/support/context/selection-policy.js +98 -21
- package/dist/esm/support/context/selection.d.ts +14 -1
- package/dist/esm/support/context/selection.js +61 -10
- package/dist/esm/support/context/snapshot.d.ts +23 -1
- package/dist/esm/support/context/snapshot.js +29 -7
- package/dist/esm/support/context/strategies.d.ts +35 -2
- package/dist/esm/support/context/strategies.js +120 -28
- package/dist/esm/support/index.d.ts +9 -1
- package/dist/esm/support/index.js +9 -1
- package/dist/esm/support/model/capabilities.d.ts +10 -0
- package/dist/esm/support/model/capabilities.js +20 -1
- package/dist/esm/support/model/chat-completions.d.ts +44 -15
- package/dist/esm/support/model/chat-completions.js +92 -20
- package/dist/esm/support/model/children.d.ts +34 -2
- package/dist/esm/support/model/children.js +34 -6
- package/dist/esm/support/model/compatible-provider.d.ts +29 -3
- package/dist/esm/support/model/compatible-provider.js +190 -60
- package/dist/esm/support/model/completion/calls.d.ts +40 -0
- package/dist/esm/support/model/completion/calls.js +58 -0
- package/dist/esm/support/model/completion/default.d.ts +11 -0
- package/dist/esm/support/model/completion/default.js +30 -0
- package/dist/esm/support/model/completion/index.d.ts +10 -0
- package/dist/esm/support/model/completion/index.js +22 -0
- package/dist/esm/support/model/completion/session.d.ts +16 -0
- package/dist/esm/support/model/completion/session.js +104 -0
- package/dist/esm/support/model/index.d.ts +14 -0
- package/dist/esm/support/model/index.js +12 -0
- package/dist/esm/support/model/interactions/index.d.ts +1 -1
- package/dist/esm/support/model/interactions/index.js +12 -1
- package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
- package/dist/esm/support/model/interactions/json-object.js +6 -0
- package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/support/model/interactions/native-functions.js +6 -0
- package/dist/esm/support/model/observer.d.ts +25 -2
- package/dist/esm/support/model/observer.js +32 -6
- package/dist/esm/support/model/preview-rules.d.ts +26 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +22 -1
- package/dist/esm/support/model/reply-preview.js +77 -17
- package/dist/esm/support/model/stage-transport.d.ts +9 -1
- package/dist/esm/support/model/stage-transport.js +33 -7
- package/dist/esm/support/model/strategies.d.ts +28 -2
- package/dist/esm/support/model/strategies.js +75 -14
- package/dist/esm/support/model/transports.d.ts +17 -1
- package/dist/esm/support/model/transports.js +53 -11
- package/dist/esm/support/registration.d.ts +20 -1
- package/dist/esm/support/registration.js +49 -7
- package/dist/esm/support/schema.d.ts +31 -1
- package/dist/esm/support/schema.js +46 -4
- package/dist/esm/support/stream-events.d.ts +22 -1
- package/dist/esm/support/stream-events.js +60 -8
- package/dist/esm/support/tool-runtime.d.ts +6 -0
- package/dist/esm/support/tool-runtime.js +6 -0
- package/dist/esm/support/tools.d.ts +22 -0
- package/dist/esm/support/tools.js +79 -10
- package/dist/esm/support/transport/index.d.ts +7 -0
- package/dist/esm/support/transport/index.js +7 -0
- package/dist/esm/support/transport/json.d.ts +29 -2
- package/dist/esm/support/transport/json.js +28 -4
- package/dist/esm/support/transport/sse.d.ts +31 -1
- package/dist/esm/support/transport/sse.js +25 -2
- package/dist/esm/types.d.ts +9 -1
- package/dist/esm/utils/break-observer.d.ts +27 -2
- package/dist/esm/utils/break-observer.js +20 -2
- package/dist/esm/utils/cancellation.d.ts +56 -5
- package/dist/esm/utils/cancellation.js +77 -9
- package/dist/esm/utils/catalog.d.ts +20 -1
- package/dist/esm/utils/catalog.js +19 -4
- package/dist/esm/utils/debug.d.ts +20 -1
- package/dist/esm/utils/debug.js +14 -2
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/interaction-definition.d.ts +18 -1
- package/dist/esm/utils/interaction-definition.js +26 -6
- package/dist/esm/utils/invocation.d.ts +36 -1
- package/dist/esm/utils/invocation.js +42 -4
- package/dist/esm/utils/model-protocol.d.ts +8 -0
- package/dist/esm/utils/model-protocol.js +20 -1
- package/dist/esm/utils/object.d.ts +16 -0
- package/dist/esm/utils/object.js +16 -0
- package/dist/esm/utils/observer.d.ts +19 -1
- package/dist/esm/utils/observer.js +22 -2
- package/dist/esm/utils/protocol-registry.d.ts +38 -1
- package/dist/esm/utils/protocol-registry.js +47 -4
- package/dist/esm/utils/query-key.d.ts +11 -1
- package/dist/esm/utils/query-key.js +21 -2
- package/dist/esm/utils/registration.d.ts +34 -2
- package/dist/esm/utils/registration.js +18 -2
- package/dist/esm/utils/rules.d.ts +81 -4
- package/dist/esm/utils/rules.js +39 -11
- package/dist/esm/utils/schema-adapter.d.ts +12 -1
- package/dist/esm/utils/schema-adapter.js +25 -2
- package/dist/esm/utils/synchronous.d.ts +60 -4
- package/dist/esm/utils/synchronous.js +64 -7
- package/dist/esm/utils/text.d.ts +15 -1
- package/dist/esm/utils/text.js +15 -1
- package/package.json +7 -3
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool lifecycle contract for the Tools Kit.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: an optional App-side library for tools that need more than a plain
|
|
5
|
+
* definition — availability, per-step protocols, output ownership, model-context fields, task rules
|
|
6
|
+
* and delivery hooks. Actual invocation is delegated to Core (`ToolRegistry`, `executeInvocation`);
|
|
7
|
+
* domain predicates, phase names and vocabulary stay App configuration.
|
|
8
|
+
*
|
|
9
|
+
* Exports: `ToolRuntimeTypes`, `ToolModelField`, `LifecycleProtocol`, `ToolInvocation`,
|
|
10
|
+
* `ToolContribution`, `LifecycleTool`, `RegisteredLifecycleTool`, `Policy`, `ToolProtocol`,
|
|
11
|
+
* `ToolNormalizer`, `ToolFinalizer`, `ToolLifecycleOptions`, `ToolJournal` (type re-export).
|
|
12
|
+
*/
|
|
1
13
|
import type { ContextFragment, ContextLifetime } from '../context/fragments.js';
|
|
2
14
|
import type { BreakReason } from '../utils/rules.js';
|
|
3
15
|
import type { ExecutableTool, ToolRegistryPorts } from '../capabilities/tools.js';
|
|
@@ -6,59 +18,108 @@ import type { ToolInvocationPorts } from '../capabilities/invocation.js';
|
|
|
6
18
|
import type { RegistrationProjection } from '../../utils/registration.js';
|
|
7
19
|
/** One schema binds lifecycle handler types without introducing platform fields into core. */
|
|
8
20
|
export interface ToolRuntimeTypes {
|
|
21
|
+
/** App decision object carried through invocation steps. */
|
|
9
22
|
decision: unknown;
|
|
23
|
+
/** App handler context for one request. */
|
|
10
24
|
context: unknown;
|
|
25
|
+
/** Value produced by a tool's `composition` hook. */
|
|
11
26
|
composition: unknown;
|
|
27
|
+
/** App phase names used by `finalize`. */
|
|
12
28
|
phase: string;
|
|
29
|
+
/** App placement names used to group model-context fields. */
|
|
13
30
|
placement: string;
|
|
31
|
+
/** Extra arguments accepted by a tool normalizer. */
|
|
14
32
|
normalizerArgs: unknown[];
|
|
33
|
+
/** Value produced by a tool finalizer. */
|
|
15
34
|
result: unknown;
|
|
35
|
+
/** Value handed to the finalizer, supplied by the lifecycle receiver. */
|
|
16
36
|
receiver: unknown;
|
|
17
37
|
}
|
|
38
|
+
/** One model-context field contributed by a tool. */
|
|
18
39
|
export interface ToolModelField<Placement extends string = string> {
|
|
40
|
+
/** Validity window of the produced fragment. */
|
|
19
41
|
lifetime?: ContextLifetime;
|
|
42
|
+
/** Character budget of the produced fragment. */
|
|
20
43
|
maxChars?: number;
|
|
44
|
+
/** Placement group this field belongs to; only that placement consumes it. */
|
|
21
45
|
placement: Placement;
|
|
46
|
+
/** Ordering key; lower values are emitted first within a placement. */
|
|
22
47
|
order: number;
|
|
48
|
+
/** Key inside the merged model field record; later entries win. */
|
|
23
49
|
key: string;
|
|
50
|
+
/** Field value, rendered by the registry's fragment factory. */
|
|
24
51
|
value: unknown;
|
|
25
52
|
}
|
|
53
|
+
/** Output protocol carried by a lifecycle step. */
|
|
26
54
|
export interface LifecycleProtocol extends ProtocolShape {
|
|
55
|
+
/** Protocol version; compared with the configured `protocolVersion` when present. */
|
|
27
56
|
readonly version?: number;
|
|
57
|
+
/** Marks an output that ends the interaction. */
|
|
28
58
|
readonly terminal?: boolean;
|
|
29
59
|
}
|
|
60
|
+
/** One lifecycle step of a tool. */
|
|
30
61
|
export interface ToolInvocation<Types extends ToolRuntimeTypes, Protocol extends LifecycleProtocol = LifecycleProtocol> {
|
|
62
|
+
/** Step id this invocation handles; must be unique across registered tools. */
|
|
31
63
|
step: string;
|
|
64
|
+
/** Output protocol of the step. */
|
|
32
65
|
protocol: Protocol;
|
|
66
|
+
/** Executes the step. Must be synchronous and return nothing. */
|
|
33
67
|
call(value: unknown, context: Types['context'], execution: import('../capabilities/tools.js').ToolExecutionContext): void;
|
|
68
|
+
/** Inspects a decision before any step runs. */
|
|
34
69
|
inspect?(decision: Types['decision'], context: Types['context']): void;
|
|
70
|
+
/** Permission check for the decision; runs before execution. */
|
|
35
71
|
authorize?(decision: Types['decision'], context: Types['context']): void;
|
|
72
|
+
/** Returns true when this step is a valid continuation of the decision. */
|
|
36
73
|
resume?(decision: Types['decision'], context: Types['context']): boolean;
|
|
74
|
+
/** Normalizes the decision after the step; returning undefined keeps it unchanged. */
|
|
37
75
|
complete?(decision: Types['decision'], context: Types['context']): Types['decision'] | undefined;
|
|
38
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Non-execution hooks a tool may contribute to a request.
|
|
79
|
+
*
|
|
80
|
+
* Every hook is optional; one returns nothing to express "no opinion".
|
|
81
|
+
*/
|
|
39
82
|
export interface ToolContribution<Types extends ToolRuntimeTypes> {
|
|
83
|
+
/** Builds the tool's composition value for the current context. */
|
|
40
84
|
composition?(context: Types['context']): Types['composition'] | undefined;
|
|
85
|
+
/** Observes the decision during the inspect phase. */
|
|
41
86
|
inspect?(decision: Types['decision'], context: Types['context']): void;
|
|
87
|
+
/** Extra context used when recovering a previous attempt. */
|
|
42
88
|
recoveryContext?(context: Types['context']): unknown;
|
|
89
|
+
/** Projects the stored context before it is shown or persisted. */
|
|
43
90
|
projectContext?(context: unknown): unknown;
|
|
91
|
+
/** Rewrites visible text produced by this tool. */
|
|
44
92
|
visibleText?(text: string, context: Types['context']): string;
|
|
93
|
+
/** Reviews a draft before delivery. */
|
|
45
94
|
reviewDraft?(draft: unknown, context: Types['context']): unknown;
|
|
95
|
+
/** Runs finalization for one phase. */
|
|
46
96
|
finalize?(decision: Types['decision'], context: Types['context'], phase: Types['phase']): void;
|
|
97
|
+
/** Returns true when an absent interaction is acceptable in this phase. */
|
|
47
98
|
missingInteractionAllowed?(decision: Types['decision'], context: Types['context']): boolean;
|
|
99
|
+
/** Extra rules contributed to the model context, ordered by `order`. */
|
|
48
100
|
rules?(context: Types['context']): {
|
|
49
101
|
order: number;
|
|
50
102
|
text: string;
|
|
51
103
|
}[];
|
|
104
|
+
/** Model-context fields for one placement, ordered by `order`. */
|
|
52
105
|
modelFields?(context: Types['context'], placement: Types['placement']): ToolModelField<Types['placement']>[];
|
|
106
|
+
/** Vetoes an intent by returning false; silence (undefined) means support. */
|
|
53
107
|
supportsIntent?(intentId: string, context: Types['context']): boolean | undefined;
|
|
54
108
|
}
|
|
109
|
+
/** A tool with lifecycle steps and delivery contributions. */
|
|
55
110
|
export interface LifecycleTool<Types extends ToolRuntimeTypes> extends ExecutableTool {
|
|
111
|
+
/** Intent ids this tool serves, or `'all'` when it is always available. */
|
|
56
112
|
readonly intentIds: 'all' | readonly string[];
|
|
57
113
|
readonly description: string;
|
|
114
|
+
/** Audience this tool is described to; validated against the registry policy. */
|
|
58
115
|
readonly audience: string;
|
|
116
|
+
/** Declared effect class, for example read-only or mutating. */
|
|
59
117
|
readonly effect: string;
|
|
118
|
+
/** Per-step invocation contract. */
|
|
60
119
|
readonly invocation?: ToolInvocation<Types>;
|
|
120
|
+
/** Non-execution hooks. */
|
|
61
121
|
readonly contribution?: ToolContribution<Types>;
|
|
122
|
+
/** Returns whether the tool may run for this context; absent means always available. */
|
|
62
123
|
available?(context: Types['context']): boolean;
|
|
63
124
|
}
|
|
64
125
|
type RegisteredInvocation<Types extends ToolRuntimeTypes, Value> = Value extends ToolInvocation<Types> ? RegistrationProjection<Value, ToolInvocation<Types>> : Value;
|
|
@@ -66,38 +127,64 @@ type RegisteredContribution<Types extends ToolRuntimeTypes, Value> = Value exten
|
|
|
66
127
|
type RegisteredLifecycleHooks<Types extends ToolRuntimeTypes, Tool extends LifecycleTool<Types>> = {
|
|
67
128
|
[Key in keyof Pick<Tool, Extract<keyof Tool, 'invocation' | 'contribution'>>]: Key extends 'invocation' ? RegisteredInvocation<Types, Tool[Key]> : RegisteredContribution<Types, Tool[Key]>;
|
|
68
129
|
};
|
|
130
|
+
/** Registered snapshot with frozen intent ids and projected hooks. */
|
|
69
131
|
export type RegisteredLifecycleTool<Types extends ToolRuntimeTypes, Tool extends LifecycleTool<Types> = LifecycleTool<Types>> = Readonly<Omit<RegistrationProjection<Tool, LifecycleTool<Types>>, 'invocation' | 'contribution' | 'intentIds'> & RegisteredLifecycleHooks<Types, Tool> & {
|
|
70
132
|
intentIds: Readonly<Tool['intentIds']>;
|
|
71
133
|
}>;
|
|
134
|
+
/** Registration policy shared by every tool in the registry. */
|
|
72
135
|
export interface Policy<Tool> {
|
|
136
|
+
/** Accepted values of a tool's `kind`. */
|
|
73
137
|
readonly kinds: readonly string[];
|
|
138
|
+
/** Identity and shape predicate; must be synchronous boolean. */
|
|
74
139
|
readonly isValidId: (tool: Tool) => boolean;
|
|
140
|
+
/** Accepted `audience` values. */
|
|
75
141
|
readonly audiences: readonly string[];
|
|
142
|
+
/** Accepted `effect` values. */
|
|
76
143
|
readonly effects: readonly string[];
|
|
144
|
+
/** Reports whether an intent id exists, for validating `intentIds` references. */
|
|
77
145
|
readonly intentExists: (goal: string) => boolean;
|
|
146
|
+
/** When set, every step protocol must declare this version. */
|
|
78
147
|
readonly protocolVersion?: number;
|
|
148
|
+
/** Diagnostic tags attached to registration rejections. */
|
|
79
149
|
readonly tags?: readonly string[];
|
|
150
|
+
/** Rejection wording for an invalid tool definition. */
|
|
80
151
|
readonly invalidTool?: BreakReason;
|
|
152
|
+
/** Rejection wording for an invalid or duplicate invocation step. */
|
|
81
153
|
readonly invalidInvocation?: BreakReason;
|
|
82
154
|
}
|
|
155
|
+
/** Protocol type of a tool's invocation step. */
|
|
83
156
|
export type ToolProtocol<Tool extends {
|
|
84
157
|
invocation?: {
|
|
85
158
|
protocol: LifecycleProtocol;
|
|
86
159
|
};
|
|
87
160
|
}> = NonNullable<Tool['invocation']>['protocol'];
|
|
161
|
+
/** Converts untrusted input into a decision; must be synchronous. */
|
|
88
162
|
export type ToolNormalizer<Types extends ToolRuntimeTypes> = (value: unknown, ...args: Types['normalizerArgs']) => unknown;
|
|
163
|
+
/** Converts an executed decision into the tool result; must be synchronous. */
|
|
89
164
|
export type ToolFinalizer<Types extends ToolRuntimeTypes> = (receiver: Types['receiver'], decision: Types['decision'], context: Types['context']) => Types['result'];
|
|
165
|
+
/** Construction options for a lifecycle tool registry. */
|
|
90
166
|
export interface ToolLifecycleOptions<Types extends ToolRuntimeTypes, Tool extends LifecycleTool<Types>> extends ToolInvocationPorts<Types['context']> {
|
|
167
|
+
/** Supplies the receiver handed to the finalizer. */
|
|
91
168
|
readonly receiver?: () => Types['receiver'];
|
|
169
|
+
/** Execution defaults (signal and diagnostics) applied to invocations. */
|
|
92
170
|
readonly execution?: import('../common.js').ExecutionOptions;
|
|
171
|
+
/** Error factories shared by the registry. */
|
|
93
172
|
readonly errors?: Pick<ToolRegistryPorts, 'unavailable' | 'errorCode'>;
|
|
173
|
+
/** Registration policy for every tool. */
|
|
94
174
|
readonly registration: Policy<Tool>;
|
|
175
|
+
/** Maps a decision to its lifecycle step id. */
|
|
95
176
|
readonly step: (decision: Types['decision']) => string;
|
|
177
|
+
/** Output protocols by id, used to validate step outputs. */
|
|
96
178
|
readonly outputs: () => Iterable<readonly [string, ToolProtocol<Tool>]>;
|
|
179
|
+
/** Optional context-dependent output protocols, exposed alongside `outputs`. */
|
|
97
180
|
readonly modelOutputs?: (context: Types['context']) => Iterable<readonly [string, ToolProtocol<Tool>]>;
|
|
181
|
+
/** Builds the error for a step with no registered tool. */
|
|
98
182
|
readonly unavailableStep?: (step: string) => Error;
|
|
183
|
+
/** Builds the error for a tool that is currently unavailable. */
|
|
99
184
|
readonly forbidden?: () => Error;
|
|
185
|
+
/** Renders a model field into a context fragment. */
|
|
100
186
|
readonly contextFragment: (tool: Tool, field: ToolModelField<Types['placement']>) => ContextFragment;
|
|
187
|
+
/** Current intent ids, used to validate `intentIds: 'all'` availability. */
|
|
101
188
|
readonly intentIds: () => readonly string[];
|
|
102
189
|
}
|
|
103
190
|
export type { ToolJournal } from '../capabilities/invocation.js';
|
|
@@ -1,9 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider boundary contract.
|
|
3
|
+
*
|
|
4
|
+
* A chat provider streams neutral parts for a prepared message list; everything provider-specific
|
|
5
|
+
* lives behind this abstraction. The module also re-exports the message primitives so adapters can
|
|
6
|
+
* depend on one entry.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `ModelProviderContext`, `ChatProvider`, and type re-exports of `ModelMessage`,
|
|
9
|
+
* `ModelImage`, `ModelUsage`, `ModelFunction`, `FunctionCallDelta`, `ModelPart`, `ModelOptions`.
|
|
10
|
+
*/
|
|
1
11
|
import type { ExecutionContext } from '../common.js';
|
|
2
12
|
import type { ModelMessage, ModelOptions, ModelPart } from './messages.js';
|
|
13
|
+
/** Per-call facts a provider receives besides the messages themselves. */
|
|
3
14
|
export interface ModelProviderContext extends ExecutionContext {
|
|
15
|
+
/** Options prepared for this call, including function schemas and JSON mode. */
|
|
4
16
|
readonly options?: Readonly<ModelOptions>;
|
|
5
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Streaming model provider.
|
|
20
|
+
*
|
|
21
|
+
* Implementations must stop producing when `context.signal` aborts and should surface transport
|
|
22
|
+
* failures by rejecting the iteration rather than ending it silently.
|
|
23
|
+
*/
|
|
6
24
|
export declare abstract class ChatProvider {
|
|
25
|
+
/**
|
|
26
|
+
* @param messages - Final message list, already budget-checked by the caller.
|
|
27
|
+
* @param context - Cancellation and per-call options.
|
|
28
|
+
* @returns Parts in arrival order; function-call fragments keep their provider index.
|
|
29
|
+
*/
|
|
7
30
|
abstract stream(messages: readonly ModelMessage[], context: ModelProviderContext): AsyncIterable<ModelPart>;
|
|
8
31
|
}
|
|
9
|
-
export type { ModelMessage, ModelImage, ModelUsage, ModelFunction, FunctionCallDelta, ModelPart, ModelOptions } from './messages.js';
|
|
32
|
+
export type { ModelMessage, ModelImage, ModelUsage, ModelFunction, FunctionCallDelta, ModelPart, ModelOptions, } from './messages.js';
|
|
@@ -1,18 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model interaction contracts: how model output is turned into a business selection.
|
|
3
|
+
*
|
|
4
|
+
* An adapter compiles registered capabilities into provider options plus an instruction, and
|
|
5
|
+
* decodes the streamed response into a `ModelSelection`. A transport registration binds one adapter
|
|
6
|
+
* to a capability source, so the same business registry can be served by different wire formats.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `ModelResponseCollector`, `PreparedModelInteraction`, `PreparedModelTransport`,
|
|
9
|
+
* `ModelInteractionAdapter`, `ModelTransportRegistration`, `NativeFunctionCall`.
|
|
10
|
+
*/
|
|
1
11
|
import type { ModelOptions, ModelPart } from './messages.js';
|
|
2
12
|
import type { ModelSelection, ModelCapabilitySource, RegisteredModelCapability } from '../capabilities/model.js';
|
|
13
|
+
/** Accumulates streamed parts for one call and resolves them into the transport's result. */
|
|
3
14
|
export interface ModelResponseCollector<Result = ModelSelection> {
|
|
15
|
+
/** Native function call that carried the selection, when the response used one. */
|
|
4
16
|
readonly call?: ModelSelection['call'];
|
|
17
|
+
/** Output characters accumulated so far, for output-budget accounting. */
|
|
5
18
|
readonly outputChars: number;
|
|
19
|
+
/** Appends one streamed part; parts arrive in provider order. */
|
|
6
20
|
push(part: ModelPart): void;
|
|
21
|
+
/** Finalizes the response. Throws when the accumulated content is not a valid selection. */
|
|
7
22
|
finish(): Result;
|
|
8
23
|
}
|
|
24
|
+
/** Adapter output for one stage, before the caller binds capability resolution. */
|
|
9
25
|
export interface PreparedModelInteraction<Result = unknown> {
|
|
26
|
+
/** Provider options produced from the stage's capabilities. */
|
|
10
27
|
readonly options: Pick<ModelOptions, 'functions' | 'json'>;
|
|
28
|
+
/** Characters the compiled schemas add to the input, counted against the schema budget. */
|
|
11
29
|
readonly schemaChars: number;
|
|
30
|
+
/** Instruction text that teaches the model how to answer; absent when the format is native. */
|
|
12
31
|
readonly instruction?: string;
|
|
32
|
+
/** Creates a fresh collector for one call; never reuse a collector across calls. */
|
|
13
33
|
createResponse(): ModelResponseCollector;
|
|
34
|
+
/** Resolves a validated selection into the stage result. */
|
|
14
35
|
resolve(selection: ModelSelection, stage: string): Result;
|
|
15
36
|
}
|
|
37
|
+
/** Prepared transport handed to the runner, including sampling defaults. */
|
|
16
38
|
export interface PreparedModelTransport<Result = unknown> {
|
|
17
39
|
readonly options: Pick<ModelOptions, 'functions' | 'json' | 'temperature'>;
|
|
18
40
|
readonly schemaChars: number;
|
|
@@ -21,22 +43,38 @@ export interface PreparedModelTransport<Result = unknown> {
|
|
|
21
43
|
}
|
|
22
44
|
/** Pluggable implementations all consume the same business registry. No automatic fallback. */
|
|
23
45
|
export interface ModelInteractionAdapter {
|
|
46
|
+
/** Adapter id, reported when a transport is validated or rejected. */
|
|
24
47
|
readonly id: string;
|
|
25
48
|
readonly features: {
|
|
26
49
|
readonly strictArguments: boolean;
|
|
27
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Compiles one stage's capabilities.
|
|
53
|
+
*
|
|
54
|
+
* @param capabilities - Capabilities available in this stage; must be non-empty.
|
|
55
|
+
* @returns Options, instruction and collector factory; the transport adds `resolve`.
|
|
56
|
+
*/
|
|
28
57
|
prepare(capabilities: readonly RegisteredModelCapability[]): Omit<PreparedModelInteraction, 'resolve'>;
|
|
29
58
|
}
|
|
59
|
+
/** Binds an adapter to the capabilities one transport serves. */
|
|
30
60
|
export interface ModelTransportRegistration<Result = unknown> {
|
|
61
|
+
/** Transport id used by call requests and reported in diagnostic events. */
|
|
31
62
|
id: string;
|
|
63
|
+
/** Static capability source, or a factory that selects capabilities per stage. */
|
|
32
64
|
capabilities: ModelCapabilitySource<Result> | ((stage: string) => ModelCapabilitySource<Result>);
|
|
65
|
+
/** Wire-format adapter; defaults to native function calling. */
|
|
33
66
|
adapter?: ModelInteractionAdapter;
|
|
67
|
+
/** Sampling defaults this transport contributes to every call. */
|
|
34
68
|
options?: Pick<ModelOptions, 'temperature'>;
|
|
69
|
+
/** Reject the registration when the chosen adapter cannot enforce strict arguments. */
|
|
35
70
|
requireStrictArguments?: boolean;
|
|
36
71
|
}
|
|
37
72
|
/** Request-local native call buffer; never an execution receipt. */
|
|
38
73
|
export interface NativeFunctionCall {
|
|
74
|
+
/** Provider call id; only unique within the response. */
|
|
39
75
|
id: string;
|
|
76
|
+
/** Function name exactly as returned by the model. */
|
|
40
77
|
name: string;
|
|
78
|
+
/** Raw JSON argument text, validated only when the selection is parsed. */
|
|
41
79
|
arguments: string;
|
|
42
80
|
}
|
|
@@ -1,38 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model message primitives shared by every provider adapter.
|
|
3
|
+
*
|
|
4
|
+
* These shapes are deliberately provider-neutral: they describe text, optional images, streamed
|
|
5
|
+
* parts and the options a call may carry. Provider-specific wire formats stay in `support/model`.
|
|
6
|
+
*
|
|
7
|
+
* Exports: `ModelImage`, `ModelMessage`, `ModelUsage`, `ModelFunction`, `FunctionCallDelta`,
|
|
8
|
+
* `ModelPart`, `ModelOptions`.
|
|
9
|
+
*/
|
|
1
10
|
export interface ModelImage {
|
|
11
|
+
/** Absolute or data URL the provider can fetch; never a local file path. */
|
|
2
12
|
url: string;
|
|
13
|
+
/** Provider resolution hint; `original` asks for no downscaling where supported. */
|
|
3
14
|
detail?: 'auto' | 'low' | 'high' | 'original';
|
|
4
15
|
}
|
|
16
|
+
/** One provider-neutral turn; `images` are user visual input and are not part of the text budget. */
|
|
5
17
|
export interface ModelMessage {
|
|
6
18
|
role: 'system' | 'user' | 'assistant';
|
|
19
|
+
/** Rendered text content sent to the model. */
|
|
7
20
|
content: string;
|
|
8
21
|
/** User-supplied visual input. Binary payload is separate from the text character budget. */
|
|
9
22
|
images?: readonly ModelImage[];
|
|
10
23
|
}
|
|
24
|
+
/** Provider-reported token counts for one call; used for accounting, never for admission. */
|
|
11
25
|
export interface ModelUsage {
|
|
26
|
+
/** Input tokens billed for the call. */
|
|
12
27
|
promptTokens: number;
|
|
28
|
+
/** Output tokens billed for the call. */
|
|
13
29
|
completionTokens: number;
|
|
30
|
+
/** Provider-reported total; may include tokens not covered by the two fields above. */
|
|
14
31
|
totalTokens: number;
|
|
15
32
|
}
|
|
16
33
|
/** Provider-neutral function definition. Execution and authorization stay with the host. */
|
|
17
34
|
export interface ModelFunction {
|
|
35
|
+
/** Function name the model must use when selecting the capability. */
|
|
18
36
|
name: string;
|
|
37
|
+
/** Model-visible description of when the function applies. */
|
|
19
38
|
description: string;
|
|
39
|
+
/** JSON Schema of the arguments; must be an object schema. */
|
|
20
40
|
parameters: Record<string, unknown>;
|
|
41
|
+
/** Request strict argument validation from providers that support it. */
|
|
21
42
|
strict?: boolean;
|
|
22
43
|
}
|
|
44
|
+
/** One streamed fragment of a function call; fragments with the same `index` must be joined. */
|
|
23
45
|
export interface FunctionCallDelta {
|
|
24
46
|
type: 'function-call-delta';
|
|
47
|
+
/** Index of the call within the response; deltas with the same index belong together. */
|
|
25
48
|
index: number;
|
|
49
|
+
/** Provider call id, usually delivered once with the first delta. */
|
|
26
50
|
id?: string;
|
|
51
|
+
/** Function name, usually delivered once with the first delta. */
|
|
27
52
|
name?: string;
|
|
53
|
+
/** Raw JSON argument fragment; concatenating all fragments yields the full arguments. */
|
|
28
54
|
arguments?: string;
|
|
29
55
|
}
|
|
56
|
+
/** One streamed response part: assistant text or a function-call fragment. */
|
|
30
57
|
export type ModelPart = string | FunctionCallDelta;
|
|
58
|
+
/** Per-call provider options; Core passes them through and does not normalize provider ranges. */
|
|
31
59
|
export interface ModelOptions {
|
|
60
|
+
/** Request a JSON-object response from providers that support it. */
|
|
32
61
|
json?: boolean;
|
|
62
|
+
/** Sampling temperature; provider range is not normalized by Core. */
|
|
33
63
|
temperature?: number;
|
|
64
|
+
/** Output ceiling for the call; the effective value is the smaller of this and the budget. */
|
|
34
65
|
maxOutputTokens?: number;
|
|
66
|
+
/** Ask the provider to report usage for streamed responses. */
|
|
35
67
|
includeUsage?: boolean;
|
|
68
|
+
/** Receives usage the provider reports; may be called once per call. */
|
|
36
69
|
onUsage?: (usage: ModelUsage) => void;
|
|
70
|
+
/** Functions offered to the model for this call. */
|
|
37
71
|
functions?: readonly ModelFunction[];
|
|
38
72
|
}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model runtime contract: budgets, transports, call traces and prepared calls.
|
|
3
|
+
*
|
|
4
|
+
* A runner owns one request's call budget, deadlines and input/output limits. It prepares a
|
|
5
|
+
* transport (schemas, instruction, collector), measures the input, charges one call and reports a
|
|
6
|
+
* trace. Child runners share the request-wide limits, so a nested stage can only consume what the
|
|
7
|
+
* parent already reserved.
|
|
8
|
+
*
|
|
9
|
+
* Exports: `ModelTokenBudget`, `ModelRuntimeConfig`, `ModelChildPolicy`,
|
|
10
|
+
* `ModelTransportDefinition`,
|
|
11
|
+
* `ModelCallTrace`, `ModelOutputEvent`, `ModelRunnerPorts`, `ModelChildOptions`,
|
|
12
|
+
* `ModelRunnerSettings`, `RegisteredTransportOutput`, `ModelRunnerOptions`, `ModelCallRequest`,
|
|
13
|
+
* `ModelInputMeasurement`, `PreparedModelCall`, `ModelPrepareRequest`.
|
|
14
|
+
*/
|
|
1
15
|
import type { PreparedModelTransport } from './interactions.js';
|
|
2
16
|
import type { InvocationMetadata } from '../invocation.js';
|
|
3
17
|
import type { ExecutionOptions } from '../common.js';
|
|
@@ -7,52 +21,83 @@ import type { ChatProvider } from './chat-provider.js';
|
|
|
7
21
|
import type { BuiltContext } from '../context/fragments.js';
|
|
8
22
|
import type { ContextPlan } from '../context/processing.js';
|
|
9
23
|
import type { ContextFragmentUsage } from '../context/fragments.js';
|
|
10
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Provider-injected token accounting.
|
|
26
|
+
*
|
|
27
|
+
* Core never guesses a character-to-token conversion, so token budgets exist only when a host
|
|
28
|
+
* supplies a real counter.
|
|
29
|
+
*/
|
|
11
30
|
export interface ModelTokenBudget {
|
|
31
|
+
/** Identifies the tokenizer and its version; recorded in every measurement. */
|
|
12
32
|
counterId: string;
|
|
33
|
+
/** Total context window of the model, in tokens. */
|
|
13
34
|
contextWindowTokens: number;
|
|
35
|
+
/** Additional reserve subtracted together with the output reservation. */
|
|
14
36
|
safetyMarginTokens?: number;
|
|
37
|
+
/** Counts input tokens for the exact request shape that will be sent. */
|
|
15
38
|
countTokens(input: {
|
|
16
39
|
messages: readonly ModelMessage[];
|
|
17
40
|
functions?: ModelOptions['functions'];
|
|
18
41
|
json?: boolean;
|
|
19
42
|
}): number;
|
|
20
43
|
}
|
|
44
|
+
/** Per-request model runtime limits. */
|
|
21
45
|
export interface ModelRuntimeConfig {
|
|
46
|
+
/** Calls allowed for the whole request, including descendant runners' reservations. */
|
|
22
47
|
maxCalls: number;
|
|
48
|
+
/** Deadline for one provider call, in milliseconds. */
|
|
23
49
|
callTimeoutMs: number;
|
|
50
|
+
/** Cap on streamed output characters; exceeding it fails the call. */
|
|
24
51
|
maxOutputChars?: number;
|
|
52
|
+
/** Request and record provider usage for each call. */
|
|
25
53
|
usage?: boolean;
|
|
26
54
|
}
|
|
27
55
|
/** Request-wide limits, shared by every descendant. They cannot be enlarged by a child. */
|
|
28
56
|
export interface ModelChildPolicy {
|
|
57
|
+
/** Maximum nesting depth of child runners; `0` forbids children. */
|
|
29
58
|
readonly maxDepth?: number;
|
|
59
|
+
/** Maximum calls running at the same time across the request. */
|
|
30
60
|
readonly maxConcurrentCalls?: number;
|
|
61
|
+
/** Maximum child runners created across the request. */
|
|
31
62
|
readonly maxChildren?: number;
|
|
32
63
|
}
|
|
64
|
+
/** One registered transport: a wire format prepared for a stage. */
|
|
33
65
|
export interface ModelTransportDefinition<Result = unknown> {
|
|
66
|
+
/** Transport id used by call requests and reported in diagnostics. */
|
|
34
67
|
readonly id: string;
|
|
68
|
+
/** Builds the prepared transport for `stageId`; must not spend a call by itself. */
|
|
35
69
|
prepare(stageId: string): import('./interactions.js').PreparedModelTransport<Result>;
|
|
36
70
|
}
|
|
71
|
+
/** Accumulated facts of one model call, reported on success and on failure. */
|
|
37
72
|
export interface ModelCallTrace extends InvocationMetadata {
|
|
73
|
+
/** One-based position of the call within its runner's lifetime. */
|
|
38
74
|
callSequence: number;
|
|
39
75
|
stageId: string;
|
|
76
|
+
/** Model binding used for the call, when one was configured. */
|
|
40
77
|
modelId?: string;
|
|
41
|
-
|
|
78
|
+
/** Counted input characters (messages, instruction and schemas). */
|
|
42
79
|
inputChars: number;
|
|
80
|
+
/** Measured input tokens; present only with an explicit token counter. */
|
|
43
81
|
inputTokens?: number;
|
|
82
|
+
/** Token ceiling the measurement was compared against. */
|
|
44
83
|
inputTokenLimit?: number;
|
|
84
|
+
/** Characters received from the provider. */
|
|
45
85
|
outputChars: number;
|
|
86
|
+
/** Time to first streamed part in milliseconds; `null` until a part arrived. */
|
|
46
87
|
firstOutputMs?: number | null;
|
|
88
|
+
/** Milliseconds from the first part to the end of the stream. */
|
|
47
89
|
outputDurationMs?: number;
|
|
48
90
|
status: import('../common.js').InvocationStatus;
|
|
91
|
+
/** Error or protocol codes observed during the call, in occurrence order. */
|
|
49
92
|
codes: string[];
|
|
50
93
|
usage?: ModelUsage;
|
|
94
|
+
/** Selected function call, when the response produced one. */
|
|
51
95
|
functionCall?: {
|
|
52
96
|
id: string;
|
|
53
97
|
name: string;
|
|
54
98
|
argumentChars: number;
|
|
55
99
|
};
|
|
100
|
+
/** Context accounting: per-fragment usage and characters shared with the previous call. */
|
|
56
101
|
context?: {
|
|
57
102
|
fragmentUsage: ContextFragmentUsage[];
|
|
58
103
|
stablePrefixChars: number;
|
|
@@ -62,40 +107,60 @@ export interface ModelCallTrace extends InvocationMetadata {
|
|
|
62
107
|
export type ModelOutputEvent = Extract<import('../execution/events.js').CoreEvent, {
|
|
63
108
|
type: 'model.start' | 'model.output' | 'model.parsed' | 'model.end';
|
|
64
109
|
}>;
|
|
110
|
+
/** Host ports a model runner needs in addition to its provider and transports. */
|
|
65
111
|
export interface ModelRunnerPorts {
|
|
112
|
+
/** Ordered delivery of model events; awaits each call before continuing. */
|
|
66
113
|
onOutput?(event: ModelOutputEvent): void | Promise<void>;
|
|
114
|
+
/** Transports available by id and instance. */
|
|
67
115
|
transports?: readonly ModelTransportDefinition[];
|
|
68
116
|
diagnostics?: DiagnosticContext;
|
|
69
|
-
/** Separate
|
|
117
|
+
/** Separate allowance for registered schemas; existing context budgets keep their meaning. */
|
|
70
118
|
maxSchemaChars?: number;
|
|
71
119
|
tokenBudget?: ModelTokenBudget;
|
|
120
|
+
/** Builds the error for an input that exceeds the character or token limit. */
|
|
72
121
|
inputBudgetError?(limit: number): Error;
|
|
122
|
+
/** Builds the error for output that exceeds the character limit. */
|
|
73
123
|
outputBudgetError?(): Error;
|
|
74
124
|
}
|
|
75
125
|
/** Request-bound isolated runner settings; provider and ancestor budgets cannot be replaced. */
|
|
76
126
|
export interface ModelChildOptions {
|
|
127
|
+
/** Child stage id, reported in traces and events. */
|
|
77
128
|
readonly id: string;
|
|
129
|
+
/** Calls the child may use from the shared request budget. */
|
|
78
130
|
readonly maxCalls: number;
|
|
131
|
+
/** Calls kept for the parent; the child cannot spend them. */
|
|
79
132
|
readonly reserveCalls: number;
|
|
133
|
+
/** Deadline for the child's own calls, in milliseconds. */
|
|
80
134
|
readonly timeoutMs: number;
|
|
135
|
+
/** Additional transports visible to the child. */
|
|
81
136
|
readonly transports?: readonly ModelTransportDefinition[];
|
|
82
137
|
readonly diagnostics?: DiagnosticContext;
|
|
138
|
+
/** Extra cancellation; can only shorten the parent's lifetime. */
|
|
83
139
|
readonly signal?: AbortSignal;
|
|
84
140
|
}
|
|
85
141
|
/** Named settings keep all model limits together; output token reservation stays per call. */
|
|
86
142
|
export interface ModelRunnerSettings extends Partial<ModelRuntimeConfig> {
|
|
87
143
|
readonly children?: ModelChildPolicy;
|
|
144
|
+
/** Character budget for the assembled input. */
|
|
88
145
|
maxInputChars?: number;
|
|
146
|
+
/** Character allowance for registered capability schemas. */
|
|
89
147
|
maxSchemaChars?: number;
|
|
90
148
|
tokenBudget?: ModelTokenBudget;
|
|
91
149
|
/** Default output reservation; invoke can override it for one call. */
|
|
92
150
|
maxOutputTokens?: number;
|
|
93
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Result type of a transport selected by id.
|
|
154
|
+
*
|
|
155
|
+
* `core:plain-text` yields `string`, a registered id yields its declared result, and an id the
|
|
156
|
+
* runner does not know yields `unknown` rather than a guessed type.
|
|
157
|
+
*/
|
|
94
158
|
export type RegisteredTransportOutput<Transports extends readonly ModelTransportDefinition[], Id extends string> = string extends Id ? unknown : Id extends 'core:plain-text' ? string : [Extract<Transports[number], {
|
|
95
159
|
readonly id: Id;
|
|
96
160
|
}>] extends [never] ? unknown : Extract<Transports[number], {
|
|
97
161
|
readonly id: Id;
|
|
98
162
|
}> extends ModelTransportDefinition<infer Value> ? Value : unknown;
|
|
163
|
+
/** Full runner construction options: provider, transports, sinks and named limits. */
|
|
99
164
|
export type ModelRunnerOptions<Transports extends readonly ModelTransportDefinition[] = readonly ModelTransportDefinition[]> = {
|
|
100
165
|
provider: ChatProvider;
|
|
101
166
|
execution?: ExecutionOptions;
|
|
@@ -108,46 +173,79 @@ export type ModelRunnerOptions<Transports extends readonly ModelTransportDefinit
|
|
|
108
173
|
outputBudget?: ModelRunnerPorts['outputBudgetError'];
|
|
109
174
|
};
|
|
110
175
|
} & ModelRunnerSettings;
|
|
176
|
+
/** One model call request. The input shape selects prompt mode or message mode. */
|
|
111
177
|
export type ModelCallRequest<Transport = string> = {
|
|
112
178
|
/** Additional cancellation can shorten, never replace, the Runner lifetime. */
|
|
113
179
|
readonly signal?: AbortSignal;
|
|
114
180
|
/** Parent observation scope for this invocation; never changes execution budget or signal. */
|
|
115
181
|
readonly diagnostics?: DiagnosticContext;
|
|
182
|
+
/** Reuse a prepared call; its stage, transport and output reservation then take precedence. */
|
|
116
183
|
readonly prepared?: PreparedModelCall;
|
|
117
184
|
readonly maxOutputTokens?: number;
|
|
118
185
|
readonly stageId?: string;
|
|
119
186
|
readonly transport?: Transport;
|
|
120
|
-
} &
|
|
187
|
+
} &
|
|
188
|
+
/** Prompt mode: one user message plus optional instructions. */
|
|
189
|
+
({
|
|
121
190
|
input: string;
|
|
122
191
|
instructions?: string;
|
|
123
|
-
}
|
|
192
|
+
}
|
|
193
|
+
/** Message mode: messages or a context plan; instructions are already inside the input. */
|
|
194
|
+
| {
|
|
124
195
|
input: readonly ModelMessage[] | BuiltContext | ContextPlan;
|
|
125
196
|
instructions?: never;
|
|
126
197
|
});
|
|
127
198
|
/** Exact prepared-request accounting; token values exist only with an explicit model counter. */
|
|
128
199
|
export interface ModelInputMeasurement {
|
|
200
|
+
/** Characters of the message content. */
|
|
129
201
|
readonly messageChars: number;
|
|
202
|
+
/** Characters of the instruction text. */
|
|
130
203
|
readonly instructionChars: number;
|
|
204
|
+
/** Characters of the compiled capability schemas. */
|
|
131
205
|
readonly schemaChars: number;
|
|
206
|
+
/** Characters the transport itself contributes (for example framing). */
|
|
132
207
|
readonly transportChars: number;
|
|
208
|
+
/** Sum of the character components above. */
|
|
133
209
|
readonly inputChars: number;
|
|
210
|
+
/** Character budget the input was compared against. */
|
|
134
211
|
readonly maxInputChars: number;
|
|
212
|
+
/** Schema budget the input was compared against. */
|
|
135
213
|
readonly maxSchemaChars: number;
|
|
214
|
+
/** Output tokens reserved for this call, which reduces the token input ceiling. */
|
|
136
215
|
readonly maxOutputTokens: number;
|
|
216
|
+
/** Tokenizer identity; present only when a token budget applies. */
|
|
137
217
|
readonly counterId?: string;
|
|
218
|
+
/** Measured input tokens. */
|
|
138
219
|
readonly inputTokens?: number;
|
|
220
|
+
/** Token ceiling after reserving output and the safety margin. */
|
|
139
221
|
readonly inputTokenLimit?: number;
|
|
222
|
+
/** True when every applicable character and token budget accepted the input. */
|
|
140
223
|
readonly withinBudget: boolean;
|
|
141
224
|
}
|
|
142
|
-
/**
|
|
225
|
+
/**
|
|
226
|
+
* Request-bound, single-use transport snapshot.
|
|
227
|
+
*
|
|
228
|
+
* Repeated measurements do not prepare or spend calls.
|
|
229
|
+
*/
|
|
143
230
|
export interface PreparedModelCall<Result = unknown> extends PreparedModelTransport<Result> {
|
|
231
|
+
/** Model binding the call was prepared with. */
|
|
144
232
|
readonly modelId?: string;
|
|
145
233
|
readonly stageId: string;
|
|
146
234
|
readonly transportId: string;
|
|
147
235
|
readonly maxOutputTokens: number;
|
|
236
|
+
/** Calls still available; a live value, so later spends are visible. */
|
|
148
237
|
readonly remainingCalls: number;
|
|
238
|
+
/**
|
|
239
|
+
* Preflight measurement of one input shape.
|
|
240
|
+
*
|
|
241
|
+
* Never marks the call used and never charges the budget.
|
|
242
|
+
*
|
|
243
|
+
* @param input - Prompt string, message array or built context to measure.
|
|
244
|
+
* @returns Character and token sizes plus a `withinBudget` verdict.
|
|
245
|
+
*/
|
|
149
246
|
measure(input: string | readonly ModelMessage[] | BuiltContext): ModelInputMeasurement;
|
|
150
247
|
}
|
|
248
|
+
/** Transport selection for `prepare`; omitted fields take the runner defaults. */
|
|
151
249
|
export interface ModelPrepareRequest<Transport = string> {
|
|
152
250
|
readonly stageId?: string;
|
|
153
251
|
readonly transport?: Transport;
|