@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,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Incremental reply preview: project partial model output into presentable bubbles.
|
|
3
|
+
*
|
|
4
|
+
* The projection is a lexical scan, deliberately separate from authoritative JSON or schema
|
|
5
|
+
* validation, and it only reads explicitly registered prose fields. It is presentation only: it
|
|
6
|
+
* must never authorize, persist or execute a proposal.
|
|
7
|
+
*
|
|
8
|
+
* Main export: `createReplyPreview` and its rule/settings types.
|
|
9
|
+
*/
|
|
1
10
|
import { synchronous } from '../../utils/synchronous.js';
|
|
2
11
|
/** Incremental lexical projection, deliberately separate from authoritative JSON/schema validation. */
|
|
3
12
|
class StringProjection {
|
|
@@ -41,7 +50,16 @@ class StringProjection {
|
|
|
41
50
|
if (ch === 'u')
|
|
42
51
|
token.unicode = '';
|
|
43
52
|
else {
|
|
44
|
-
const escapes = {
|
|
53
|
+
const escapes = {
|
|
54
|
+
'"': '"',
|
|
55
|
+
'\\': '\\',
|
|
56
|
+
'/': '/',
|
|
57
|
+
b: '\b',
|
|
58
|
+
f: '\f',
|
|
59
|
+
n: '\n',
|
|
60
|
+
r: '\r',
|
|
61
|
+
t: '\t',
|
|
62
|
+
};
|
|
45
63
|
if (!(ch in escapes))
|
|
46
64
|
throw new Error('Invalid escape');
|
|
47
65
|
token.text += escapes[ch];
|
|
@@ -86,7 +104,9 @@ class StringProjection {
|
|
|
86
104
|
}
|
|
87
105
|
const frame = this.stack.at(-1);
|
|
88
106
|
if (ch === '}' || ch === ']') {
|
|
89
|
-
if (!frame ||
|
|
107
|
+
if (!frame ||
|
|
108
|
+
(ch === '}' ? frame.kind !== '{' : frame.kind !== '[') ||
|
|
109
|
+
!['key', 'value', 'comma'].includes(frame.state))
|
|
90
110
|
throw new Error('Invalid close');
|
|
91
111
|
this.stack.pop();
|
|
92
112
|
this.complete();
|
|
@@ -108,8 +128,16 @@ class StringProjection {
|
|
|
108
128
|
if (!frame || !['key', 'value'].includes(frame.state))
|
|
109
129
|
throw new Error('Invalid string position');
|
|
110
130
|
const key = frame.state === 'key', path = this.path();
|
|
111
|
-
const projected = !key &&
|
|
112
|
-
|
|
131
|
+
const projected = !key &&
|
|
132
|
+
this.paths.some((pattern) => path.length === pattern.length &&
|
|
133
|
+
pattern.every((key, i) => (key === '*' ? /^\d+$/.test(path[i]) : key === path[i])));
|
|
134
|
+
this.token = {
|
|
135
|
+
key,
|
|
136
|
+
path,
|
|
137
|
+
text: '',
|
|
138
|
+
projectionKey: projected ? JSON.stringify(path) : undefined,
|
|
139
|
+
escape: false,
|
|
140
|
+
};
|
|
113
141
|
continue;
|
|
114
142
|
}
|
|
115
143
|
if (frame && frame.state !== 'value')
|
|
@@ -120,23 +148,46 @@ class StringProjection {
|
|
|
120
148
|
if (ch === '{' || ch === '[') {
|
|
121
149
|
if (this.stack.length >= 32)
|
|
122
150
|
throw new Error('Too deep');
|
|
123
|
-
this.stack.push({
|
|
151
|
+
this.stack.push({
|
|
152
|
+
path: this.path(),
|
|
153
|
+
kind: ch,
|
|
154
|
+
state: ch === '{' ? 'key' : 'value',
|
|
155
|
+
index: 0,
|
|
156
|
+
keys: new Set(),
|
|
157
|
+
});
|
|
124
158
|
}
|
|
125
159
|
else
|
|
126
160
|
this.primitive = true;
|
|
127
161
|
}
|
|
128
162
|
}
|
|
129
|
-
string(path) {
|
|
163
|
+
string(path) {
|
|
164
|
+
const key = JSON.stringify(path);
|
|
165
|
+
return this.completedStrings.has(key) ? this.values.get(key)?.text : undefined;
|
|
166
|
+
}
|
|
130
167
|
texts(paths = this.paths) {
|
|
131
168
|
// Later bubbles can arrive first in JSON; keep their indices stable until the leading prose exists.
|
|
132
169
|
const first = paths[0];
|
|
133
170
|
if (first && !first.includes('*') && !this.values.has(JSON.stringify(first)))
|
|
134
171
|
return [];
|
|
135
|
-
return paths
|
|
136
|
-
.
|
|
172
|
+
return paths
|
|
173
|
+
.flatMap((pattern) => [...this.values.values()]
|
|
174
|
+
.filter(({ path }) => path.length === pattern.length &&
|
|
175
|
+
pattern.every((key, i) => (key === '*' ? /^\d+$/.test(path[i]) : key === path[i])))
|
|
176
|
+
.sort((a, b) => Number(a.path.at(-1)) - Number(b.path.at(-1))))
|
|
177
|
+
.map((value) => value.text);
|
|
137
178
|
}
|
|
138
179
|
}
|
|
139
|
-
/**
|
|
180
|
+
/**
|
|
181
|
+
* Create a model-output event handler that publishes preview bubbles.
|
|
182
|
+
*
|
|
183
|
+
* The handler resets on `model.start`, ignores other invocations, disables itself on unexpected
|
|
184
|
+
* output, and clears the preview when a call ends unsuccessfully. Rules are snapshotted at
|
|
185
|
+
* creation, and only explicitly registered prose fields are projected.
|
|
186
|
+
*
|
|
187
|
+
* @param options Rules, optional renderer, character budget and the bubble sink.
|
|
188
|
+
* @returns An async handler for `ModelOutputEvent`.
|
|
189
|
+
* @throws {TypeError} When the sink is missing or `maxChars` is not a positive integer.
|
|
190
|
+
*/
|
|
140
191
|
export function createReplyPreview(options) {
|
|
141
192
|
if (typeof options.sink !== 'function')
|
|
142
193
|
throw new TypeError('A reply preview sink is required');
|
|
@@ -144,7 +195,7 @@ export function createReplyPreview(options) {
|
|
|
144
195
|
const maxChars = options.maxChars ?? 16000;
|
|
145
196
|
if (!Number.isSafeInteger(maxChars) || maxChars < 1)
|
|
146
197
|
throw new TypeError('Invalid reply preview budget');
|
|
147
|
-
const rules = options.rules.map(rule => Object.freeze({
|
|
198
|
+
const rules = options.rules.map((rule) => Object.freeze({
|
|
148
199
|
capabilityId: rule.capabilityId,
|
|
149
200
|
stageId: rule.stageId,
|
|
150
201
|
paths: rule.paths === undefined ? undefined : structuredClone(rule.paths),
|
|
@@ -155,10 +206,13 @@ export function createReplyPreview(options) {
|
|
|
155
206
|
let selected;
|
|
156
207
|
let activeCall;
|
|
157
208
|
const publish = async (texts) => {
|
|
158
|
-
// Hold incomplete surrogate pairs and never show internal control characters.
|
|
209
|
+
// Hold incomplete surrogate pairs and never show internal control characters. The bubble cap
|
|
210
|
+
// is independent of `maxChars`: at most five bubbles and 16000 characters reach the sink.
|
|
159
211
|
let remaining = 16000;
|
|
160
|
-
const bubbles = texts.slice(0, 5).map(text => {
|
|
161
|
-
const value = (render ? synchronous(render(text), 'Reply preview renderers must be synchronous') : text)
|
|
212
|
+
const bubbles = texts.slice(0, 5).map((text) => {
|
|
213
|
+
const value = (render ? synchronous(render(text), 'Reply preview renderers must be synchronous') : text)
|
|
214
|
+
.slice(0, remaining)
|
|
215
|
+
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]|[\ud800-\udbff]$/gu, '');
|
|
162
216
|
remaining -= value.length;
|
|
163
217
|
return value;
|
|
164
218
|
});
|
|
@@ -194,14 +248,17 @@ export function createReplyPreview(options) {
|
|
|
194
248
|
if (disabled)
|
|
195
249
|
return;
|
|
196
250
|
const part = event.payload.part;
|
|
197
|
-
chars +=
|
|
251
|
+
chars +=
|
|
252
|
+
typeof part === 'string'
|
|
253
|
+
? part.length
|
|
254
|
+
: (part.name?.length ?? 0) + (part.arguments?.length ?? 0);
|
|
198
255
|
if (chars > maxChars) {
|
|
199
256
|
disabled = true;
|
|
200
257
|
await publish([]);
|
|
201
258
|
return;
|
|
202
259
|
}
|
|
203
260
|
if (typeof part === 'string') {
|
|
204
|
-
const rule = rules.find(rule => !rule.capabilityId && rule.stageId === event.payload.stageId);
|
|
261
|
+
const rule = rules.find((rule) => !rule.capabilityId && rule.stageId === event.payload.stageId);
|
|
205
262
|
if (!rule) {
|
|
206
263
|
if (part.trim()) {
|
|
207
264
|
disabled = true;
|
|
@@ -219,7 +276,7 @@ export function createReplyPreview(options) {
|
|
|
219
276
|
return;
|
|
220
277
|
}
|
|
221
278
|
name += part.name ?? '';
|
|
222
|
-
const rule = rules.find(rule => rule.capabilityId === name && (!rule.stageId || rule.stageId === event.payload.stageId));
|
|
279
|
+
const rule = rules.find((rule) => rule.capabilityId === name && (!rule.stageId || rule.stageId === event.payload.stageId));
|
|
223
280
|
if (!rule) {
|
|
224
281
|
if (selected) {
|
|
225
282
|
disabled = true;
|
|
@@ -232,7 +289,10 @@ export function createReplyPreview(options) {
|
|
|
232
289
|
try {
|
|
233
290
|
if (!selected) {
|
|
234
291
|
selected = rule;
|
|
235
|
-
parser = new StringProjection([
|
|
292
|
+
parser = new StringProjection([
|
|
293
|
+
...(rule.paths ?? [['text'], ['bubbles', '*']]),
|
|
294
|
+
...(rule.when ? [rule.when.path] : []),
|
|
295
|
+
]);
|
|
236
296
|
parser.push(argumentsText);
|
|
237
297
|
argumentsText = '';
|
|
238
298
|
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { ModelStageTransportRegistration } from '../../structs/support/model/interactions.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Build a transport that projects a capability source through declared stage references.
|
|
4
|
+
*
|
|
5
|
+
* @param registration Transport declaration: unique ID, stage-to-capability references, interaction
|
|
6
|
+
* adapter, options and a static or per-stage capability source.
|
|
7
|
+
* @returns A Core model transport with `capabilities(stage)`.
|
|
8
|
+
* @throws {Error} When a stage ID repeats, has no capability IDs, the declaration has no stages, a
|
|
9
|
+
* stage or capability is not registered, or a dynamic capability source is asynchronous.
|
|
10
|
+
*/
|
|
3
11
|
export declare function createStageModelTransport<Result, const Id extends string = string>(registration: ModelStageTransportRegistration<Result> & {
|
|
4
12
|
readonly id: Id;
|
|
5
13
|
}): import("../../index.js").ModelTransportDefinition<Result> & {
|
|
@@ -1,14 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage-scoped model transport: expose only the capabilities declared for each stage.
|
|
3
|
+
*
|
|
4
|
+
* Static capability sources are projected once at construction; dynamic sources are re-projected
|
|
5
|
+
* at the model boundary. Either way, an undeclared stage or capability is rejected rather than
|
|
6
|
+
* silently omitted.
|
|
7
|
+
*
|
|
8
|
+
* Main export: `createStageModelTransport`.
|
|
9
|
+
*/
|
|
1
10
|
import { synchronous } from '../../utils/synchronous.js';
|
|
2
11
|
import { ModelCapabilityRegistry } from '../../capabilities/model.js';
|
|
3
12
|
import { breakWhile } from '../../utils/rules.js';
|
|
4
13
|
import { createModelTransport } from './transports.js';
|
|
5
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Build a transport that projects a capability source through declared stage references.
|
|
16
|
+
*
|
|
17
|
+
* @param registration Transport declaration: unique ID, stage-to-capability references, interaction
|
|
18
|
+
* adapter, options and a static or per-stage capability source.
|
|
19
|
+
* @returns A Core model transport with `capabilities(stage)`.
|
|
20
|
+
* @throws {Error} When a stage ID repeats, has no capability IDs, the declaration has no stages, a
|
|
21
|
+
* stage or capability is not registered, or a dynamic capability source is asynchronous.
|
|
22
|
+
*/
|
|
6
23
|
export function createStageModelTransport(registration) {
|
|
7
24
|
const stages = new Map();
|
|
8
25
|
for (const stage of registration.stages) {
|
|
9
26
|
const ids = stage.capabilityIds;
|
|
10
|
-
breakWhile(!stage.id?.trim() ||
|
|
11
|
-
|
|
27
|
+
breakWhile(!stage.id?.trim() ||
|
|
28
|
+
stages.has(stage.id) ||
|
|
29
|
+
!Array.isArray(ids) ||
|
|
30
|
+
!ids.length ||
|
|
31
|
+
new Set(ids).size !== ids.length, `Invalid model stage: ${stage.id}`);
|
|
12
32
|
stages.set(stage.id, Object.freeze([...ids]));
|
|
13
33
|
}
|
|
14
34
|
breakWhile(!stages.size, 'Model transport requires declared stages');
|
|
@@ -30,13 +50,19 @@ export function createStageModelTransport(registration) {
|
|
|
30
50
|
},
|
|
31
51
|
});
|
|
32
52
|
};
|
|
33
|
-
const fixed = typeof source === 'function'
|
|
34
|
-
|
|
53
|
+
const fixed = typeof source === 'function'
|
|
54
|
+
? undefined
|
|
55
|
+
: new Map([...stages.keys()].map((stage) => [stage, project(stage, source)]));
|
|
35
56
|
return createModelTransport({
|
|
36
|
-
id,
|
|
57
|
+
id,
|
|
58
|
+
adapter,
|
|
59
|
+
options,
|
|
60
|
+
requireStrictArguments,
|
|
37
61
|
capabilities(stage) {
|
|
38
62
|
breakWhile(!stages.has(stage), `Unregistered model stage: ${id} -> ${stage}`);
|
|
39
|
-
return fixed
|
|
63
|
+
return fixed
|
|
64
|
+
? fixed.get(stage)
|
|
65
|
+
: project(stage, synchronous(source.call(registration, stage), 'Model capability sources must be synchronous'));
|
|
40
66
|
},
|
|
41
67
|
});
|
|
42
68
|
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { ExecutionOptions } from '../../structs/common.js';
|
|
2
2
|
import type { ModelRunnerOptions, ModelRunnerSettings, ModelTransportDefinition } from '../../structs/model/runtime.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Budget presets by expected workload size.
|
|
5
|
+
*
|
|
6
|
+
* `maxCalls` counts model calls per run; `maxInputChars`/`maxOutputChars` are character budgets;
|
|
7
|
+
* `maxOutputTokens` is the per-call output reservation; `callTimeoutMs` bounds one call in
|
|
8
|
+
* milliseconds. These are local admission and output allowances, never a claim about provider
|
|
9
|
+
* capacity or performance.
|
|
10
|
+
*/
|
|
4
11
|
export declare const modelBudgetStrategies: Readonly<{
|
|
5
12
|
small: Readonly<{
|
|
6
13
|
maxCalls: 2;
|
|
@@ -24,17 +31,25 @@ export declare const modelBudgetStrategies: Readonly<{
|
|
|
24
31
|
callTimeoutMs: 60000;
|
|
25
32
|
}>;
|
|
26
33
|
}>;
|
|
34
|
+
/** Preset name, or an explicit partial set of Core runner settings. */
|
|
27
35
|
export type ModelBudgetStrategy = keyof typeof modelBudgetStrategies | Partial<ModelRunnerSettings>;
|
|
28
36
|
type StrategyModel<Transports extends readonly ModelTransportDefinition[], Execution> = Omit<ModelRunnerOptions<Transports>, 'execution'> & {
|
|
29
37
|
execution?: Execution;
|
|
30
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Input of `createModelStrategy`: model selection, optional reasoning and budget plus explicit
|
|
41
|
+
* Core overrides. Explicit Core fields win over every generated value.
|
|
42
|
+
*/
|
|
31
43
|
export type ModelStrategyOptions<Transports extends readonly ModelTransportDefinition[] = readonly ModelTransportDefinition[], Execution = ExecutionOptions> = Partial<StrategyModel<Transports, Execution>> & {
|
|
32
44
|
/** An existing definition, or an ID in the explicitly supplied model catalog. */
|
|
33
45
|
readonly model: StrategyModel<Transports, Execution> | string;
|
|
46
|
+
/** Named model definitions; required when `model` is a string ID. */
|
|
34
47
|
readonly models?: Readonly<Record<string, StrategyModel<Transports, Execution>>>;
|
|
35
48
|
/** Names and supplier-specific implementations are declared by the App, never guessed. */
|
|
36
49
|
readonly reasoning?: string;
|
|
50
|
+
/** Per-reasoning overrides; entries are applied only when `reasoning` names them. */
|
|
37
51
|
readonly reasoningOptions?: Readonly<Record<string, Partial<StrategyModel<Transports, Execution>>>>;
|
|
52
|
+
/** Preset name, or an explicit partial budget; defaults to `medium`. */
|
|
38
53
|
readonly budget?: ModelBudgetStrategy;
|
|
39
54
|
};
|
|
40
55
|
type NamedDefinition<Catalog, Id> = Id extends string ? string extends Id ? Catalog[keyof Catalog] : Id extends keyof Catalog ? Catalog[Id] : never : never;
|
|
@@ -45,6 +60,17 @@ type ExecutionFrom<Source, Fallback> = Source extends unknown ? 'execution' exte
|
|
|
45
60
|
type StrategyResult<Options extends ModelStrategyOptions> = Omit<ModelRunnerOptions<TransportsFrom<Options, TransportsFrom<SelectedReasoning<Options>, TransportsFrom<SelectedModel<Options>, readonly []>>>>, 'execution'> & {
|
|
46
61
|
execution?: ExecutionFrom<Options, ExecutionFrom<SelectedReasoning<Options>, ExecutionFrom<SelectedModel<Options>, undefined>>>;
|
|
47
62
|
};
|
|
48
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Compose runner options in precedence order: budget preset, selected model, declared reasoning,
|
|
65
|
+
* exact budget, then explicit Core fields.
|
|
66
|
+
*
|
|
67
|
+
* The result is validated through the same Core binding rules but creates no runner and spends no
|
|
68
|
+
* calls.
|
|
69
|
+
*
|
|
70
|
+
* @param options Model selection, optional reasoning and budget, and explicit Core overrides.
|
|
71
|
+
* @returns A frozen, validated `ModelRunnerOptions` with inferred transport/execution types.
|
|
72
|
+
* @throws {TypeError} When a model ID is unknown, a string model is combined with inline
|
|
73
|
+
* definitions, a reasoning name is unknown, or a budget field or preset is invalid.
|
|
74
|
+
*/
|
|
49
75
|
export declare function createModelStrategy<const Options extends ModelStrategyOptions>(options: Options): StrategyResult<Options>;
|
|
50
76
|
export {};
|
|
@@ -1,18 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model strategy presets: compose a Core `ModelRunnerOptions` from named sources.
|
|
3
|
+
*
|
|
4
|
+
* A strategy selects a model definition (inline or by catalog ID), optional reasoning variant and
|
|
5
|
+
* a budget preset, then layers any explicit Core fields last. Values are local admission
|
|
6
|
+
* allowances, not claims about provider capacity or performance.
|
|
7
|
+
*
|
|
8
|
+
* Main exports: `modelBudgetStrategies`, `createModelStrategy` and the strategy option types.
|
|
9
|
+
*/
|
|
1
10
|
import { snapshotModelBinding } from '../../model/binding.js';
|
|
2
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Budget presets by expected workload size.
|
|
13
|
+
*
|
|
14
|
+
* `maxCalls` counts model calls per run; `maxInputChars`/`maxOutputChars` are character budgets;
|
|
15
|
+
* `maxOutputTokens` is the per-call output reservation; `callTimeoutMs` bounds one call in
|
|
16
|
+
* milliseconds. These are local admission and output allowances, never a claim about provider
|
|
17
|
+
* capacity or performance.
|
|
18
|
+
*/
|
|
3
19
|
export const modelBudgetStrategies = Object.freeze({
|
|
4
|
-
small: Object.freeze({
|
|
5
|
-
|
|
6
|
-
|
|
20
|
+
small: Object.freeze({
|
|
21
|
+
maxCalls: 2,
|
|
22
|
+
maxInputChars: 8000,
|
|
23
|
+
maxOutputChars: 4000,
|
|
24
|
+
maxOutputTokens: 512,
|
|
25
|
+
callTimeoutMs: 15000,
|
|
26
|
+
}),
|
|
27
|
+
medium: Object.freeze({
|
|
28
|
+
maxCalls: 8,
|
|
29
|
+
maxInputChars: 32000,
|
|
30
|
+
maxOutputChars: 16000,
|
|
31
|
+
maxOutputTokens: 1024,
|
|
32
|
+
callTimeoutMs: 30000,
|
|
33
|
+
}),
|
|
34
|
+
large: Object.freeze({
|
|
35
|
+
maxCalls: 16,
|
|
36
|
+
maxInputChars: 64000,
|
|
37
|
+
maxOutputChars: 32000,
|
|
38
|
+
maxOutputTokens: 4096,
|
|
39
|
+
callTimeoutMs: 60000,
|
|
40
|
+
}),
|
|
7
41
|
});
|
|
8
|
-
// Exhaustiveness ensures new Core settings cannot silently disappear at this boundary
|
|
42
|
+
// Exhaustiveness ensures new Core settings cannot silently disappear at this boundary: adding a
|
|
43
|
+
// setting to `ModelRunnerSettings` without listing it here fails type checking.
|
|
9
44
|
const budgetSettingKeys = {
|
|
10
|
-
maxCalls: true,
|
|
11
|
-
|
|
45
|
+
maxCalls: true,
|
|
46
|
+
callTimeoutMs: true,
|
|
47
|
+
maxOutputChars: true,
|
|
48
|
+
usage: true,
|
|
49
|
+
children: true,
|
|
50
|
+
maxInputChars: true,
|
|
51
|
+
maxSchemaChars: true,
|
|
52
|
+
tokenBudget: true,
|
|
53
|
+
maxOutputTokens: true,
|
|
12
54
|
};
|
|
13
55
|
const settingKeys = {
|
|
14
|
-
...budgetSettingKeys,
|
|
56
|
+
...budgetSettingKeys,
|
|
57
|
+
provider: true,
|
|
58
|
+
execution: true,
|
|
59
|
+
transports: true,
|
|
60
|
+
sink: true,
|
|
61
|
+
errors: true,
|
|
15
62
|
};
|
|
63
|
+
// Copy only known Core keys, so helper fields such as `model`, `models` or `budget` in a selected
|
|
64
|
+
// definition are not forwarded as runner options.
|
|
16
65
|
function settings(source) {
|
|
17
66
|
const result = {};
|
|
18
67
|
for (const key of Object.keys(settingKeys))
|
|
@@ -38,20 +87,32 @@ export function createModelStrategy(options) {
|
|
|
38
87
|
if (typeof model !== 'string' && models !== undefined)
|
|
39
88
|
throw new TypeError('Use a model ID with configured models');
|
|
40
89
|
const selected = typeof model === 'string'
|
|
41
|
-
? models && Object.hasOwn(models, model)
|
|
90
|
+
? models && Object.hasOwn(models, model)
|
|
91
|
+
? models[model]
|
|
92
|
+
: undefined
|
|
93
|
+
: model;
|
|
42
94
|
if (!selected || typeof selected !== 'object')
|
|
43
95
|
throw new TypeError(`Unknown model strategy: ${String(model)}`);
|
|
44
|
-
const reasoningSettings = reasoning === undefined
|
|
45
|
-
|
|
96
|
+
const reasoningSettings = reasoning === undefined
|
|
97
|
+
? undefined
|
|
98
|
+
: reasoningOptions && Object.hasOwn(reasoningOptions, reasoning)
|
|
99
|
+
? reasoningOptions[reasoning]
|
|
100
|
+
: undefined;
|
|
46
101
|
if (reasoning !== undefined && !reasoningSettings)
|
|
47
102
|
throw new TypeError(`Unknown reasoning strategy: ${reasoning}`);
|
|
48
103
|
if (typeof budget === 'string' && !Object.hasOwn(modelBudgetStrategies, budget))
|
|
49
104
|
throw new TypeError(`Unknown model budget: ${budget}`);
|
|
50
|
-
if (!budget ||
|
|
105
|
+
if (!budget ||
|
|
106
|
+
(typeof budget !== 'string' && (typeof budget !== 'object' || Array.isArray(budget))))
|
|
51
107
|
throw new TypeError('Invalid model budget strategy');
|
|
52
108
|
const preset = typeof budget === 'string' ? modelBudgetStrategies[budget] : modelBudgetStrategies.medium;
|
|
53
|
-
const result = {
|
|
54
|
-
...
|
|
109
|
+
const result = {
|
|
110
|
+
...preset,
|
|
111
|
+
...settings(selected),
|
|
112
|
+
...(reasoningSettings && settings(reasoningSettings)),
|
|
113
|
+
...(typeof budget === 'object' && budgetSettings(budget)),
|
|
114
|
+
...settings(options),
|
|
115
|
+
};
|
|
55
116
|
// Validate through the same Core rules without creating a request runner or spending calls.
|
|
56
117
|
snapshotModelBinding(result);
|
|
57
118
|
return Object.freeze(result);
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { ModelOptions } from '../../structs/model/messages.js';
|
|
2
2
|
import type { ModelTransportDefinition } from '../../structs/model/runtime.js';
|
|
3
3
|
export { createModelTransport } from '../../model/selection-transport.js';
|
|
4
|
+
/**
|
|
5
|
+
* Create a plain-text transport that trims the assembled response.
|
|
6
|
+
*
|
|
7
|
+
* @param definition Transport ID and optional temperature.
|
|
8
|
+
* @returns A frozen Core transport definition typed as string output.
|
|
9
|
+
*/
|
|
4
10
|
export declare function createTextTransport<const Id extends string>(definition: {
|
|
5
11
|
readonly id: Id;
|
|
6
12
|
readonly options?: Pick<ModelOptions, 'temperature'>;
|
|
@@ -8,7 +14,17 @@ export declare function createTextTransport<const Id extends string>(definition:
|
|
|
8
14
|
readonly id: Id;
|
|
9
15
|
};
|
|
10
16
|
export type { ModelTransportRegistration } from '../../structs/support/model/interactions.js';
|
|
11
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Create a typed JSON transport without a capability-selection envelope.
|
|
19
|
+
*
|
|
20
|
+
* The transport embeds the JSON Schema in the instruction and requires the response to be one
|
|
21
|
+
* complete JSON value. The returned response parser rejects native call events and invalid JSON,
|
|
22
|
+
* then validates the value through the supplied schema.
|
|
23
|
+
*
|
|
24
|
+
* @param definition Transport ID, output schema and optional temperature/json settings.
|
|
25
|
+
* @returns A frozen Core transport definition typed as `Output`.
|
|
26
|
+
* @throws {TypeError} When the ID is blank or the schema adapter cannot be snapshotted.
|
|
27
|
+
*/
|
|
12
28
|
export declare function createJsonTransport<Output, const Id extends string = string>(definition: {
|
|
13
29
|
readonly id: Id;
|
|
14
30
|
readonly outputSchema: import('../../structs/common.js').SchemaAdapter<Output>;
|
|
@@ -1,28 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model transport creators for plain text and typed JSON values.
|
|
3
|
+
*
|
|
4
|
+
* Both produce Core `ModelTransportDefinition` objects with an ID, so a runner can select them by
|
|
5
|
+
* name. Neither invokes a model: preparation, response assembly and parsing stay in Core.
|
|
6
|
+
*
|
|
7
|
+
* Main exports: `createTextTransport`, `createJsonTransport`, `createModelTransport` and the
|
|
8
|
+
* transport registration type.
|
|
9
|
+
*/
|
|
1
10
|
import { snapshotSchemaAdapter } from '../../utils/schema-adapter.js';
|
|
2
11
|
import { snapshotModelOptions } from '../../model/options.js';
|
|
3
12
|
import { modelProtocolError } from '../../utils/model-protocol.js';
|
|
4
13
|
import { createPlainTextTransport } from '../../model/transports.js';
|
|
5
14
|
export { createModelTransport } from '../../model/selection-transport.js';
|
|
15
|
+
/**
|
|
16
|
+
* Create a plain-text transport that trims the assembled response.
|
|
17
|
+
*
|
|
18
|
+
* @param definition Transport ID and optional temperature.
|
|
19
|
+
* @returns A frozen Core transport definition typed as string output.
|
|
20
|
+
*/
|
|
6
21
|
export function createTextTransport(definition) {
|
|
7
22
|
return createPlainTextTransport(definition.id, definition.options);
|
|
8
23
|
}
|
|
9
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Create a typed JSON transport without a capability-selection envelope.
|
|
26
|
+
*
|
|
27
|
+
* The transport embeds the JSON Schema in the instruction and requires the response to be one
|
|
28
|
+
* complete JSON value. The returned response parser rejects native call events and invalid JSON,
|
|
29
|
+
* then validates the value through the supplied schema.
|
|
30
|
+
*
|
|
31
|
+
* @param definition Transport ID, output schema and optional temperature/json settings.
|
|
32
|
+
* @returns A frozen Core transport definition typed as `Output`.
|
|
33
|
+
* @throws {TypeError} When the ID is blank or the schema adapter cannot be snapshotted.
|
|
34
|
+
*/
|
|
10
35
|
export function createJsonTransport(definition) {
|
|
11
36
|
const { id, outputSchema, options } = definition;
|
|
12
37
|
if (typeof id !== 'string' || !id.trim())
|
|
13
38
|
throw new TypeError('JSON transport requires an ID');
|
|
14
39
|
const schema = snapshotSchemaAdapter(outputSchema);
|
|
15
|
-
const settings = Object.freeze({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
40
|
+
const settings = Object.freeze({
|
|
41
|
+
...snapshotModelOptions({ temperature: options?.temperature, json: options?.json ?? true }),
|
|
42
|
+
});
|
|
43
|
+
const instruction = 'Return exactly one complete JSON value matching this JSON Schema: ' +
|
|
44
|
+
JSON.stringify(schema.jsonSchema) +
|
|
45
|
+
'\nReturn the value itself, without prose, fences, a schema document or a capability-selection envelope.';
|
|
46
|
+
return Object.freeze({
|
|
47
|
+
id,
|
|
48
|
+
prepare() {
|
|
49
|
+
return {
|
|
50
|
+
options: settings,
|
|
51
|
+
instruction,
|
|
52
|
+
schemaChars: instruction.length,
|
|
53
|
+
createResponse() {
|
|
20
54
|
let raw = '';
|
|
21
|
-
return {
|
|
55
|
+
return {
|
|
56
|
+
get outputChars() {
|
|
57
|
+
return raw.length;
|
|
58
|
+
},
|
|
59
|
+
push(part) {
|
|
22
60
|
if (typeof part !== 'string')
|
|
23
61
|
modelProtocolError('JSON value transport does not accept native call events');
|
|
24
62
|
raw += part;
|
|
25
|
-
},
|
|
63
|
+
},
|
|
64
|
+
finish() {
|
|
26
65
|
let value;
|
|
27
66
|
try {
|
|
28
67
|
value = JSON.parse(raw);
|
|
@@ -31,7 +70,10 @@ export function createJsonTransport(definition) {
|
|
|
31
70
|
modelProtocolError('JSON value transport requires complete JSON');
|
|
32
71
|
}
|
|
33
72
|
return schema.parse(value);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
});
|
|
37
79
|
}
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import type { RegistrationDefinition } from '../structs/support/registration.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Compile an ordered installation plan.
|
|
4
|
+
*
|
|
5
|
+
* Predicates observe the effects of preceding installations at request time; a predicate that
|
|
6
|
+
* throws rejects the install instead of being treated as `false`. Callbacks are bound to their
|
|
7
|
+
* declaring definition so implementations may rely on `this`.
|
|
8
|
+
*
|
|
9
|
+
* @param definitions Registration steps in execution order.
|
|
10
|
+
* @returns A frozen catalog plus `install(context)`, which runs enabled steps sequentially.
|
|
11
|
+
* @throws {Error} When a `register` handler is missing or a `when` predicate is not a function.
|
|
12
|
+
*/
|
|
3
13
|
export declare function defineRegistrationCatalog<Context>(definitions: readonly RegistrationDefinition<Context>[]): Readonly<{
|
|
14
|
+
/**
|
|
15
|
+
* Run every enabled step in declaration order against `context`.
|
|
16
|
+
*
|
|
17
|
+
* Stops at the first failing predicate or handler; earlier installations are not rolled back.
|
|
18
|
+
*
|
|
19
|
+
* @param context Value passed to each predicate and registration handler.
|
|
20
|
+
* @throws {TypeError} When a predicate is asynchronous or does not return a boolean, or when
|
|
21
|
+
* a handler is asynchronous.
|
|
22
|
+
*/
|
|
4
23
|
install(context: Context): void;
|
|
5
24
|
definitions: readonly Readonly<{
|
|
6
25
|
id: string;
|
|
@@ -1,21 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditional registration support: compile an ordered list of install steps for an application.
|
|
3
|
+
*
|
|
4
|
+
* Steps are validated and bound once, then installed per invocation. Predicates run at install
|
|
5
|
+
* time and only see what previous steps already installed, so ordering is part of the contract.
|
|
6
|
+
* This is app-side composition for Core-facing handlers; it defines no new scheduling protocol.
|
|
7
|
+
*
|
|
8
|
+
* Main export: `defineRegistrationCatalog`.
|
|
9
|
+
*/
|
|
1
10
|
import { readonlyCatalog } from '../utils/catalog.js';
|
|
2
11
|
import { synchronous, booleanResult } from '../utils/synchronous.js';
|
|
3
12
|
import { breakWhile } from '../utils/rules.js';
|
|
4
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Compile an ordered installation plan.
|
|
15
|
+
*
|
|
16
|
+
* Predicates observe the effects of preceding installations at request time; a predicate that
|
|
17
|
+
* throws rejects the install instead of being treated as `false`. Callbacks are bound to their
|
|
18
|
+
* declaring definition so implementations may rely on `this`.
|
|
19
|
+
*
|
|
20
|
+
* @param definitions Registration steps in execution order.
|
|
21
|
+
* @returns A frozen catalog plus `install(context)`, which runs enabled steps sequentially.
|
|
22
|
+
* @throws {Error} When a `register` handler is missing or a `when` predicate is not a function.
|
|
23
|
+
*/
|
|
5
24
|
export function defineRegistrationCatalog(definitions) {
|
|
6
|
-
const catalog = readonlyCatalog(definitions.map(definition => {
|
|
25
|
+
const catalog = readonlyCatalog(definitions.map((definition) => {
|
|
7
26
|
const { id, when, register } = definition;
|
|
8
27
|
breakWhile([
|
|
9
|
-
{
|
|
10
|
-
|
|
28
|
+
{
|
|
29
|
+
occur: typeof register !== 'function',
|
|
30
|
+
error: 'Missing registration handler',
|
|
31
|
+
tags: ['handler'],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
occur: when !== undefined && typeof when !== 'function',
|
|
35
|
+
error: 'Invalid registration predicate',
|
|
36
|
+
tags: ['predicate'],
|
|
37
|
+
},
|
|
11
38
|
], ['agent-core', 'registration']);
|
|
12
|
-
return Object.freeze({
|
|
13
|
-
|
|
39
|
+
return Object.freeze({
|
|
40
|
+
id,
|
|
41
|
+
when: when?.bind(definition),
|
|
42
|
+
register: register.bind(definition),
|
|
43
|
+
});
|
|
44
|
+
}), (id) => new TypeError(`Unknown registration: ${id}`));
|
|
14
45
|
return Object.freeze({
|
|
15
46
|
...catalog,
|
|
47
|
+
/**
|
|
48
|
+
* Run every enabled step in declaration order against `context`.
|
|
49
|
+
*
|
|
50
|
+
* Stops at the first failing predicate or handler; earlier installations are not rolled back.
|
|
51
|
+
*
|
|
52
|
+
* @param context Value passed to each predicate and registration handler.
|
|
53
|
+
* @throws {TypeError} When a predicate is asynchronous or does not return a boolean, or when
|
|
54
|
+
* a handler is asynchronous.
|
|
55
|
+
*/
|
|
16
56
|
install(context) {
|
|
17
57
|
for (const entry of catalog.definitions) {
|
|
18
|
-
const enabled = entry.when
|
|
58
|
+
const enabled = entry.when
|
|
59
|
+
? booleanResult(entry.when(context), 'Registration predicates must be synchronous', 'Registration predicates must return boolean')
|
|
60
|
+
: true;
|
|
19
61
|
if (enabled) {
|
|
20
62
|
synchronous(entry.register(context), 'Registration handlers must be synchronous');
|
|
21
63
|
}
|