@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
package/dist/esm/kits/tools.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools Kit: a lifecycle registry for domain tools with declared invocation and contribution.
|
|
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, context fields, task rules
|
|
6
|
+
* and delivery hooks. Actual invocation is delegated to Core (`ToolRegistry` and
|
|
7
|
+
* `executeInvocation`); domain predicates, phase names and vocabulary stay App configuration.
|
|
8
|
+
*
|
|
9
|
+
* Exports: `ToolLifecycleRegistry` (also exported as `Tools`) and the tool lifecycle types.
|
|
10
|
+
*/
|
|
1
11
|
import { assertion, booleanResult, synchronous } from '../utils/synchronous.js';
|
|
2
12
|
import { toolInvocation } from '../utils/invocation.js';
|
|
3
13
|
import { breakWhile } from '../utils/rules.js';
|
|
@@ -7,24 +17,53 @@ import { ProtocolRegistry } from '../utils/protocol-registry.js';
|
|
|
7
17
|
import { registrationData } from '../utils/registration.js';
|
|
8
18
|
/** Pin contract methods and configuration without cloning the App services they use. */
|
|
9
19
|
function snapshotLifecycleOptions(options) {
|
|
10
|
-
const { receiver, execution, errors, registration, step, outputs, modelOutputs, unavailableStep, forbidden, contextFragment, intentIds, diagnostics, signal, journal, checkpoint, receipt, receiptError } = options;
|
|
20
|
+
const { receiver, execution, errors, registration, step, outputs, modelOutputs, unavailableStep, forbidden, contextFragment, intentIds, diagnostics, signal, journal, checkpoint, receipt, receiptError, } = options;
|
|
11
21
|
if (typeof intentIds !== 'function')
|
|
12
22
|
throw new TypeError('An intentIds provider is required');
|
|
13
|
-
const { kinds, isValidId, audiences, effects, intentExists, protocolVersion, tags, invalidTool, invalidInvocation } = registration;
|
|
23
|
+
const { kinds, isValidId, audiences, effects, intentExists, protocolVersion, tags, invalidTool, invalidInvocation, } = registration;
|
|
14
24
|
return Object.freeze({
|
|
15
25
|
receiver: receiver?.bind(options),
|
|
16
26
|
execution: execution && Object.freeze({ signal: execution.signal, diagnostics: execution.diagnostics }),
|
|
17
|
-
errors: errors &&
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
errors: errors &&
|
|
28
|
+
Object.freeze({
|
|
29
|
+
unavailable: errors.unavailable?.bind(errors),
|
|
30
|
+
errorCode: errors.errorCode?.bind(errors),
|
|
31
|
+
}),
|
|
32
|
+
registration: Object.freeze({
|
|
33
|
+
kinds: Object.freeze([...kinds]),
|
|
34
|
+
audiences: Object.freeze([...audiences]),
|
|
35
|
+
effects: Object.freeze([...effects]),
|
|
36
|
+
isValidId: isValidId.bind(registration),
|
|
37
|
+
intentExists: intentExists.bind(registration),
|
|
38
|
+
protocolVersion,
|
|
39
|
+
tags: tags && Object.freeze([...tags]),
|
|
40
|
+
invalidTool: typeof invalidTool === 'function' ? invalidTool.bind(registration) : invalidTool,
|
|
41
|
+
invalidInvocation: typeof invalidInvocation === 'function'
|
|
42
|
+
? invalidInvocation.bind(registration)
|
|
43
|
+
: invalidInvocation,
|
|
44
|
+
}),
|
|
45
|
+
step: step.bind(options),
|
|
46
|
+
outputs: outputs.bind(options),
|
|
47
|
+
modelOutputs: modelOutputs?.bind(options),
|
|
48
|
+
unavailableStep: unavailableStep?.bind(options),
|
|
49
|
+
forbidden: forbidden?.bind(options),
|
|
50
|
+
contextFragment: contextFragment.bind(options),
|
|
51
|
+
intentIds: intentIds.bind(options),
|
|
52
|
+
diagnostics: diagnostics?.bind(options),
|
|
53
|
+
signal: signal?.bind(options),
|
|
54
|
+
journal: journal?.bind(options),
|
|
55
|
+
checkpoint: checkpoint?.bind(options),
|
|
56
|
+
receipt: receipt?.bind(options),
|
|
57
|
+
receiptError: receiptError?.bind(options),
|
|
26
58
|
});
|
|
27
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Registry of tools whose lifecycle, protocols and contributions are declared by the App.
|
|
62
|
+
*
|
|
63
|
+
* Registration is only possible before `seal()`; afterwards the catalog is read-only, so a run
|
|
64
|
+
* cannot change which tools exist. Every contribution hook is optional and is applied in
|
|
65
|
+
* registration order, which is why `registerAll` preserves iteration order.
|
|
66
|
+
*/
|
|
28
67
|
export class ToolLifecycleRegistry {
|
|
29
68
|
tools;
|
|
30
69
|
registered = new Map();
|
|
@@ -37,9 +76,17 @@ export class ToolLifecycleRegistry {
|
|
|
37
76
|
activeDiagnostics;
|
|
38
77
|
invocationPorts;
|
|
39
78
|
options;
|
|
79
|
+
/**
|
|
80
|
+
* @param options - Receiver, execution context, error wording, registration policy, protocol
|
|
81
|
+
* providers and optional journal/receipt ports; contract methods are bound to their owner.
|
|
82
|
+
* @throws TypeError When no `intentIds` provider is supplied.
|
|
83
|
+
*/
|
|
40
84
|
constructor(options) {
|
|
41
85
|
this.options = snapshotLifecycleOptions(options);
|
|
42
|
-
this.tools = new ToolRegistry({
|
|
86
|
+
this.tools = new ToolRegistry({
|
|
87
|
+
execution: this.options.execution,
|
|
88
|
+
errors: this.options.errors,
|
|
89
|
+
});
|
|
43
90
|
this.diagnostics = this.options.execution?.diagnostics;
|
|
44
91
|
this.invocationPorts = Object.freeze({
|
|
45
92
|
diagnostics: this.options.diagnostics ?? (() => this.diagnostics),
|
|
@@ -50,22 +97,104 @@ export class ToolLifecycleRegistry {
|
|
|
50
97
|
receiptError: this.options.receiptError,
|
|
51
98
|
});
|
|
52
99
|
}
|
|
53
|
-
|
|
54
|
-
|
|
100
|
+
/** Core tool events, forwarded unchanged. */
|
|
101
|
+
get events() {
|
|
102
|
+
return this.tools.events;
|
|
103
|
+
}
|
|
104
|
+
/** Swap the diagnostics sink for later invocations; the Core registry is updated as well. */
|
|
105
|
+
setDiagnostics(value) {
|
|
106
|
+
this.diagnostics = value;
|
|
107
|
+
this.tools.setDiagnostics(value);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Register and freeze one tool definition.
|
|
111
|
+
*
|
|
112
|
+
* Handlers are bound to the original object; authorization, inspection and finalization
|
|
113
|
+
* hooks must return `void` synchronously, while the remaining handlers are checked for
|
|
114
|
+
* accidental thenables only.
|
|
115
|
+
*
|
|
116
|
+
* @param input - Tool definition with identity, audience, effect and its handlers.
|
|
117
|
+
* @returns This registry, for chaining.
|
|
118
|
+
* @throws A configured registration error for a sealed registry, invalid identity,
|
|
119
|
+
* description, audience, effect, intent ids, missing handlers, duplicate tool id,
|
|
120
|
+
* incomplete invocation contract, protocol version mismatch or duplicate invocation step.
|
|
121
|
+
*/
|
|
55
122
|
register(input) {
|
|
56
|
-
const { id, kind, description, audience, effect, intentIds, invocation, contribution, parseInput: inputParser, parseOutput: outputParser, available: availability, execute, debugSteps } = input;
|
|
123
|
+
const { id, kind, description, audience, effect, intentIds, invocation, contribution, parseInput: inputParser, parseOutput: outputParser, available: availability, execute, debugSteps, } = input;
|
|
57
124
|
const parseInput = inputParser?.bind(input), parseOutput = outputParser?.bind(input);
|
|
58
125
|
const available = availability?.bind(input);
|
|
59
126
|
const frozenIntents = Array.isArray(intentIds) ? Object.freeze([...intentIds]) : intentIds;
|
|
60
|
-
const tool = {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
127
|
+
const tool = {
|
|
128
|
+
...registrationData(input, [
|
|
129
|
+
'id',
|
|
130
|
+
'kind',
|
|
131
|
+
'description',
|
|
132
|
+
'audience',
|
|
133
|
+
'effect',
|
|
134
|
+
'intentIds',
|
|
135
|
+
'invocation',
|
|
136
|
+
'contribution',
|
|
137
|
+
'parseInput',
|
|
138
|
+
'parseOutput',
|
|
139
|
+
'execute',
|
|
140
|
+
'debugSteps',
|
|
141
|
+
'available',
|
|
142
|
+
]),
|
|
143
|
+
id,
|
|
144
|
+
kind,
|
|
145
|
+
description,
|
|
146
|
+
audience,
|
|
147
|
+
effect,
|
|
148
|
+
invocation,
|
|
149
|
+
contribution,
|
|
150
|
+
intentIds: frozenIntents,
|
|
151
|
+
parseInput,
|
|
152
|
+
parseOutput,
|
|
153
|
+
debugSteps: debugSteps?.bind(input),
|
|
154
|
+
execute: execute?.bind(input),
|
|
155
|
+
available: available
|
|
156
|
+
? (context) => booleanResult(available(context), 'Tool availability must be synchronous', 'Tool availability must return boolean')
|
|
157
|
+
: undefined,
|
|
158
|
+
};
|
|
159
|
+
const bindMethods = (value, keys, data = {}) => Object.freeze({
|
|
160
|
+
...registrationData(value, [...keys, ...Reflect.ownKeys(data)]),
|
|
161
|
+
...data,
|
|
162
|
+
...Object.fromEntries(keys.map((key) => {
|
|
163
|
+
const handler = value[key];
|
|
164
|
+
return [
|
|
165
|
+
key,
|
|
166
|
+
typeof handler === 'function'
|
|
167
|
+
? (...args) => (['authorize', 'inspect', 'finalize'].includes(String(key))
|
|
168
|
+
? assertion
|
|
169
|
+
: synchronous)(handler.apply(value, args), `Tool lifecycle ${String(key)} must finish synchronously with the declared result`)
|
|
170
|
+
: handler,
|
|
171
|
+
];
|
|
172
|
+
})),
|
|
173
|
+
});
|
|
174
|
+
const registered = Object.freeze({
|
|
175
|
+
...tool,
|
|
176
|
+
...(invocation
|
|
177
|
+
? {
|
|
178
|
+
invocation: bindMethods(invocation, ['call', 'inspect', 'authorize', 'resume', 'complete'], { step: invocation.step, protocol: invocation.protocol }),
|
|
179
|
+
}
|
|
180
|
+
: {}),
|
|
181
|
+
...(contribution
|
|
182
|
+
? {
|
|
183
|
+
contribution: bindMethods(contribution, [
|
|
184
|
+
'composition',
|
|
185
|
+
'inspect',
|
|
186
|
+
'recoveryContext',
|
|
187
|
+
'projectContext',
|
|
188
|
+
'visibleText',
|
|
189
|
+
'reviewDraft',
|
|
190
|
+
'finalize',
|
|
191
|
+
'missingInteractionAllowed',
|
|
192
|
+
'rules',
|
|
193
|
+
'modelFields',
|
|
194
|
+
'supportsIntent',
|
|
195
|
+
]),
|
|
196
|
+
}
|
|
197
|
+
: {}),
|
|
69
198
|
});
|
|
70
199
|
return this.install(input, registered);
|
|
71
200
|
}
|
|
@@ -77,29 +206,67 @@ export class ToolLifecycleRegistry {
|
|
|
77
206
|
const invalid = policy.invalidTool ?? 'Invalid registered tool';
|
|
78
207
|
const invalidInvocation = policy.invalidInvocation ?? 'Invalid or duplicate tool invocation';
|
|
79
208
|
breakWhile([
|
|
80
|
-
{
|
|
209
|
+
{
|
|
210
|
+
occur: [() => !policy.kinds.includes(tool.kind), () => !isValidId()],
|
|
211
|
+
error: invalid,
|
|
212
|
+
tags: ['identity'],
|
|
213
|
+
},
|
|
81
214
|
{ occur: () => !tool.description.trim(), error: invalid, tags: ['description'] },
|
|
82
|
-
{
|
|
215
|
+
{
|
|
216
|
+
occur: [
|
|
217
|
+
() => !policy.audiences.includes(tool.audience),
|
|
218
|
+
() => !policy.effects.includes(tool.effect),
|
|
219
|
+
],
|
|
220
|
+
error: invalid,
|
|
221
|
+
tags: ['execution-contract'],
|
|
222
|
+
},
|
|
83
223
|
{
|
|
84
224
|
occur: [
|
|
85
225
|
() => tool.intentIds !== 'all' && !Array.isArray(tool.intentIds),
|
|
86
226
|
() => tool.intentIds !== 'all' && !tool.intentIds.length,
|
|
87
|
-
() => tool.intentIds !== 'all' &&
|
|
227
|
+
() => tool.intentIds !== 'all' &&
|
|
228
|
+
tool.intentIds.some((goal) => !booleanResult(policy.intentExists(goal), 'Intent lookup must return boolean synchronously')),
|
|
88
229
|
() => tool.intentIds !== 'all' && new Set(tool.intentIds).size !== tool.intentIds.length,
|
|
89
|
-
],
|
|
230
|
+
],
|
|
231
|
+
error: invalid,
|
|
232
|
+
tags: ['intents'],
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
occur: () => ![tool.parseInput, tool.parseOutput, tool.execute].every((handler) => typeof handler === 'function'),
|
|
236
|
+
error: invalid,
|
|
237
|
+
tags: ['handlers'],
|
|
90
238
|
},
|
|
91
|
-
{ occur: () => ![tool.parseInput, tool.parseOutput, tool.execute].every(handler => typeof handler === 'function'), error: invalid, tags: ['handlers'] },
|
|
92
|
-
{ occur: () => this.tools.has(tool.id), error: () => new Error(`Duplicate registered tool: ${tool.id}`), tags: ['duplicate-name'] },
|
|
93
|
-
{ occur: () => tool.invocation && !tool.invocation.step, error: invalidInvocation, tags: ['invocation', 'step'] },
|
|
94
239
|
{
|
|
95
|
-
occur:
|
|
96
|
-
error:
|
|
240
|
+
occur: () => this.tools.has(tool.id),
|
|
241
|
+
error: () => new Error(`Duplicate registered tool: ${tool.id}`),
|
|
242
|
+
tags: ['duplicate-name'],
|
|
97
243
|
},
|
|
98
244
|
{
|
|
99
|
-
occur: () => tool.invocation &&
|
|
100
|
-
error: invalidInvocation,
|
|
245
|
+
occur: () => tool.invocation && !tool.invocation.step,
|
|
246
|
+
error: invalidInvocation,
|
|
247
|
+
tags: ['invocation', 'step'],
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
occur: [
|
|
251
|
+
() => tool.invocation && typeof tool.invocation.call !== 'function',
|
|
252
|
+
() => tool.invocation && typeof tool.invocation.protocol?.keys !== 'function',
|
|
253
|
+
],
|
|
254
|
+
error: invalidInvocation,
|
|
255
|
+
tags: ['invocation', 'contract'],
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
occur: () => tool.invocation &&
|
|
259
|
+
policy.protocolVersion !== undefined &&
|
|
260
|
+
tool.invocation.protocol.version !== undefined &&
|
|
261
|
+
tool.invocation.protocol.version !== policy.protocolVersion,
|
|
262
|
+
error: invalidInvocation,
|
|
263
|
+
tags: ['invocation', 'version'],
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
occur: () => tool.invocation && this.invocations.has(tool.invocation.step),
|
|
267
|
+
error: invalidInvocation,
|
|
268
|
+
tags: ['invocation', 'duplicate-step'],
|
|
101
269
|
},
|
|
102
|
-
{ occur: () => tool.invocation && this.invocations.has(tool.invocation.step), error: invalidInvocation, tags: ['invocation', 'duplicate-step'] },
|
|
103
270
|
], policy.tags);
|
|
104
271
|
this.tools.register(tool);
|
|
105
272
|
this.registered.set(tool.id, tool);
|
|
@@ -108,41 +275,115 @@ export class ToolLifecycleRegistry {
|
|
|
108
275
|
this.invocations.set(tool.invocation.step, tool);
|
|
109
276
|
return this;
|
|
110
277
|
}
|
|
111
|
-
|
|
112
|
-
|
|
278
|
+
/** Register every tool in iteration order. */
|
|
279
|
+
registerAll(tools) {
|
|
280
|
+
for (const tool of tools)
|
|
281
|
+
this.register(tool);
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Invoke one Core tool by its already-validated request.
|
|
286
|
+
*
|
|
287
|
+
* When the request carries no diagnostics, the currently active one is used, so a call made
|
|
288
|
+
* from inside a tool inherits that tool's diagnostic context.
|
|
289
|
+
*/
|
|
113
290
|
invoke(request) {
|
|
114
291
|
const call = toolInvocation(request, arguments.length);
|
|
115
292
|
return this.tools.invoke({ ...call, diagnostics: call.diagnostics ?? this.activeDiagnostics });
|
|
116
293
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
294
|
+
/** Registered tools in registration order. */
|
|
295
|
+
get definitions() {
|
|
296
|
+
return Object.freeze([...this.registered.values()]);
|
|
297
|
+
}
|
|
298
|
+
/** Registered tool ids, delegated to the Core registry. */
|
|
299
|
+
ids() {
|
|
300
|
+
return this.tools.ids();
|
|
301
|
+
}
|
|
302
|
+
/** Iterate `[id, tool]` pairs. */
|
|
303
|
+
entries() {
|
|
304
|
+
return this.registered.entries();
|
|
305
|
+
}
|
|
306
|
+
/** Registered tool for `id`, or `undefined` when it is absent. */
|
|
307
|
+
get(id) {
|
|
308
|
+
return this.registered.get(id);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Registered tool for `id`.
|
|
312
|
+
*
|
|
313
|
+
* @throws TypeError When the id is not registered.
|
|
314
|
+
*/
|
|
315
|
+
require(id) {
|
|
316
|
+
this.tools.require(id);
|
|
317
|
+
return this.registered.get(id);
|
|
318
|
+
}
|
|
319
|
+
/** Whether a tool id is registered. */
|
|
320
|
+
has(name) {
|
|
321
|
+
return this.tools.has(name);
|
|
322
|
+
}
|
|
323
|
+
/** Iterate the registered tools. */
|
|
324
|
+
values() {
|
|
325
|
+
return this.registered.values();
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Install the single normalization handler.
|
|
329
|
+
*
|
|
330
|
+
* @throws An error when a handler is already installed or the registry is sealed, because a
|
|
331
|
+
* second handler would make normalization order ambiguous.
|
|
332
|
+
*/
|
|
124
333
|
registerNormalizer(handler) {
|
|
125
334
|
breakWhile(this.sealed || this.normalizer, 'Normalizer already registered or registry sealed');
|
|
126
335
|
this.normalizer = handler;
|
|
127
336
|
}
|
|
337
|
+
/** Apply the installed normalizer, or return the value unchanged when none exists. */
|
|
128
338
|
normalize(value, ...args) {
|
|
129
|
-
return this.normalizer
|
|
339
|
+
return this.normalizer
|
|
340
|
+
? synchronous(this.normalizer.call(this.options.receiver?.() ?? this, value, ...args), 'Tool normalization must be synchronous')
|
|
341
|
+
: value;
|
|
130
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Install the single reply finalizer.
|
|
345
|
+
*
|
|
346
|
+
* @throws An error when a finalizer is already installed or the registry is sealed.
|
|
347
|
+
*/
|
|
131
348
|
registerFinalizer(handler) {
|
|
132
349
|
breakWhile(this.sealed || this.finalizer, 'Finalizer already registered or registry sealed');
|
|
133
350
|
this.finalizer = handler;
|
|
134
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* Run the installed finalizer over a decision.
|
|
354
|
+
*
|
|
355
|
+
* @throws An error when no finalizer is installed, or when it does not finish synchronously.
|
|
356
|
+
*/
|
|
135
357
|
finish(receiver, decision, context) {
|
|
136
358
|
breakWhile(!this.finalizer, 'No registered reply finalizer');
|
|
137
359
|
return synchronous(this.finalizer.call(receiver, receiver, decision, context), 'Tool finalization must be synchronous');
|
|
138
360
|
}
|
|
361
|
+
/**
|
|
362
|
+
* Execute the invocation registered for a step type.
|
|
363
|
+
*
|
|
364
|
+
* Diagnostics are swapped to the invocation's own sink for the duration of the call and
|
|
365
|
+
* restored afterwards, so nested tool calls report under the innermost scope.
|
|
366
|
+
*
|
|
367
|
+
* @param step - Step carrying the registered `type`.
|
|
368
|
+
* @param context - Execution context forwarded to Core's invocation executor.
|
|
369
|
+
* @throws A configured error when the step is unknown or the tool is unavailable.
|
|
370
|
+
*/
|
|
139
371
|
call(step, context) {
|
|
140
372
|
const tool = this.invocations.get(step.type);
|
|
141
373
|
breakWhile([
|
|
142
|
-
{
|
|
143
|
-
|
|
374
|
+
{
|
|
375
|
+
occur: () => !tool?.invocation,
|
|
376
|
+
error: () => this.options.unavailableStep?.(step.type) ??
|
|
377
|
+
new Error(`Tool step is not registered: ${step.type}`),
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
occur: () => tool.available && !tool.available(context),
|
|
381
|
+
error: () => this.options.forbidden?.() ?? new Error('Tool is not available'),
|
|
382
|
+
},
|
|
144
383
|
]);
|
|
145
|
-
executeInvocation({
|
|
384
|
+
executeInvocation({
|
|
385
|
+
id: tool.id,
|
|
386
|
+
call: (value, input, execution) => {
|
|
146
387
|
const previous = this.activeDiagnostics;
|
|
147
388
|
this.activeDiagnostics = execution.diagnostics;
|
|
148
389
|
try {
|
|
@@ -151,60 +392,152 @@ export class ToolLifecycleRegistry {
|
|
|
151
392
|
finally {
|
|
152
393
|
this.activeDiagnostics = previous;
|
|
153
394
|
}
|
|
154
|
-
}
|
|
395
|
+
},
|
|
396
|
+
}, step, context, this.invocationPorts);
|
|
155
397
|
}
|
|
398
|
+
/** Output protocols plus one protocol per registered invocation step. */
|
|
156
399
|
protocols() {
|
|
157
|
-
return new ProtocolRegistry([
|
|
400
|
+
return new ProtocolRegistry([
|
|
401
|
+
...this.options.outputs(),
|
|
402
|
+
...[...this.invocations].map(([step, tool]) => [step, tool.invocation.protocol]),
|
|
403
|
+
]);
|
|
158
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Protocols exposed to the model: output protocols plus steps whose audience is `model` and
|
|
407
|
+
* which are currently available in `context`.
|
|
408
|
+
*/
|
|
159
409
|
modelProtocols(context) {
|
|
160
|
-
return new ProtocolRegistry([
|
|
410
|
+
return new ProtocolRegistry([
|
|
411
|
+
...(this.options.modelOutputs?.(context) ?? this.options.outputs()),
|
|
412
|
+
...[...this.invocations]
|
|
161
413
|
.filter(([, tool]) => tool.audience === 'model' && (!tool.available || tool.available(context)))
|
|
162
|
-
.map(([step, tool]) => [step, tool.invocation.protocol])
|
|
414
|
+
.map(([step, tool]) => [step, tool.invocation.protocol]),
|
|
415
|
+
]);
|
|
416
|
+
}
|
|
417
|
+
/** Whether the protocol registered for this step is declared terminal. */
|
|
418
|
+
isTerminal(step) {
|
|
419
|
+
return this.protocols().get(step.type)?.terminal === true;
|
|
163
420
|
}
|
|
164
|
-
|
|
421
|
+
/** Run contribution inspection for every tool, then the selected invocation's own check. */
|
|
165
422
|
assertDecision(decision, context) {
|
|
166
423
|
for (const tool of this.registered.values())
|
|
167
424
|
tool.contribution?.inspect?.(decision, context);
|
|
168
425
|
this.selected(decision)?.invocation?.inspect?.(decision, context);
|
|
169
426
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
427
|
+
/** Run the selected invocation's authorization hook, if any. */
|
|
428
|
+
authorize(decision, context) {
|
|
429
|
+
this.selected(decision)?.invocation?.authorize?.(decision, context);
|
|
430
|
+
}
|
|
431
|
+
/** Whether the selected invocation should resume rather than start fresh; defaults to false. */
|
|
432
|
+
resume(decision, context) {
|
|
433
|
+
const invocation = this.selected(decision)?.invocation;
|
|
434
|
+
return invocation?.resume
|
|
435
|
+
? booleanResult(invocation.resume(decision, context), 'Tool resume must return boolean synchronously')
|
|
436
|
+
: false;
|
|
437
|
+
}
|
|
438
|
+
/** Let the selected invocation rewrite the decision on completion, if it declares a hook. */
|
|
439
|
+
complete(decision, context) {
|
|
440
|
+
return this.selected(decision)?.invocation?.complete?.(decision, context);
|
|
441
|
+
}
|
|
442
|
+
/** Fold every contribution's context projection over the value, in registration order. */
|
|
443
|
+
projectContext(value) {
|
|
444
|
+
return [...this.registered.values()].reduce((current, tool) => tool.contribution?.projectContext?.(current) ?? current, value);
|
|
445
|
+
}
|
|
446
|
+
/** Fold every contribution's visible-text transform over the text. */
|
|
447
|
+
visibleText(text, context) {
|
|
448
|
+
return [...this.registered.values()].reduce((value, tool) => tool.contribution?.visibleText?.(value, context) ?? value, text);
|
|
449
|
+
}
|
|
450
|
+
/** Fold every contribution's review transform over the draft. */
|
|
451
|
+
reviewDraft(draft, context) {
|
|
452
|
+
return [...this.registered.values()].reduce((value, tool) => tool.contribution?.reviewDraft?.(value, context) ?? value, draft);
|
|
453
|
+
}
|
|
454
|
+
/** Collected recovery context values; `undefined` results are omitted. */
|
|
176
455
|
recoveryContext(context) {
|
|
177
|
-
return [...this.registered.values()].flatMap(tool => {
|
|
456
|
+
return [...this.registered.values()].flatMap((tool) => {
|
|
457
|
+
const value = tool.contribution?.recoveryContext?.(context);
|
|
458
|
+
return value === undefined ? [] : [value];
|
|
459
|
+
});
|
|
178
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* The single output template that owns this delivery.
|
|
463
|
+
*
|
|
464
|
+
* @throws An error when more than one contribution claims composition, because delivery
|
|
465
|
+
* would otherwise depend on registration order.
|
|
466
|
+
*/
|
|
179
467
|
composition(context) {
|
|
180
|
-
const values = [...this.registered.values()].flatMap(tool => {
|
|
468
|
+
const values = [...this.registered.values()].flatMap((tool) => {
|
|
469
|
+
const value = tool.contribution?.composition?.(context);
|
|
470
|
+
return value ? [value] : [];
|
|
471
|
+
});
|
|
181
472
|
breakWhile(values.length > 1, 'More than one output template owns this delivery');
|
|
182
473
|
return values[0];
|
|
183
474
|
}
|
|
475
|
+
/** Run every contribution's finalize hook for the given phase. */
|
|
184
476
|
finalize(decision, context, phase) {
|
|
185
477
|
for (const tool of this.registered.values())
|
|
186
478
|
tool.contribution?.finalize?.(decision, context, phase);
|
|
187
479
|
}
|
|
480
|
+
/** Whether any contribution permits the interaction to be missing. */
|
|
188
481
|
missingInteractionAllowed(decision, context) {
|
|
189
|
-
return [...this.registered.values()].some(tool => tool.contribution?.missingInteractionAllowed
|
|
482
|
+
return [...this.registered.values()].some((tool) => tool.contribution?.missingInteractionAllowed
|
|
483
|
+
? booleanResult(tool.contribution.missingInteractionAllowed(decision, context), 'Missing interaction predicates must return boolean synchronously')
|
|
484
|
+
: false);
|
|
190
485
|
}
|
|
486
|
+
/** Task rules ordered by their declared `order`, joined into one prompt block. */
|
|
191
487
|
taskRules(context) {
|
|
192
|
-
return [...this.registered.values()]
|
|
193
|
-
.
|
|
488
|
+
return [...this.registered.values()]
|
|
489
|
+
.flatMap((tool) => tool.contribution?.rules?.(context) ?? [])
|
|
490
|
+
.sort((left, right) => left.order - right.order)
|
|
491
|
+
.map((rule) => rule.text)
|
|
492
|
+
.filter(Boolean)
|
|
493
|
+
.join('\n\n');
|
|
194
494
|
}
|
|
495
|
+
/** Model-context fragments for one placement, ordered by each field's `order`. */
|
|
195
496
|
contextFields(context, placement) {
|
|
196
|
-
return [...this.registered.values()]
|
|
197
|
-
.
|
|
497
|
+
return [...this.registered.values()]
|
|
498
|
+
.flatMap((tool) => (tool.contribution?.modelFields?.(context, placement) ?? [])
|
|
499
|
+
.filter((field) => field.placement === placement)
|
|
500
|
+
.map((field) => ({ tool, field })))
|
|
198
501
|
.sort((left, right) => left.field.order - right.field.order)
|
|
199
502
|
.map(({ tool, field }) => this.options.contextFragment(this.sources.get(tool.id), field));
|
|
200
503
|
}
|
|
201
|
-
|
|
202
|
-
|
|
504
|
+
/** Merged model-context values for one placement; later fragments win per key. */
|
|
505
|
+
modelFields(context, placement) {
|
|
506
|
+
return Object.assign({}, ...this.contextFields(context, placement).map((fragment) => fragment.value));
|
|
507
|
+
}
|
|
508
|
+
/** A contribution may veto an intent by returning `false`; silence means support. */
|
|
509
|
+
supportsIntent(intentId, context) {
|
|
510
|
+
return [...this.registered.values()].every((tool) => tool.contribution?.supportsIntent?.(intentId, context) !== false);
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Describe registered tools, optionally limited by audience and availability.
|
|
514
|
+
*
|
|
515
|
+
* A tool with an `available` predicate is only listed when a context is supplied and the
|
|
516
|
+
* predicate holds, so a caller that omits the context sees just the unconditional tools.
|
|
517
|
+
*
|
|
518
|
+
* @param audience - Audience to keep; omit to include every audience.
|
|
519
|
+
* @param context - Context for availability checks.
|
|
520
|
+
* @returns Plain metadata; `intentIds: 'all'` is expanded to the current intent ids.
|
|
521
|
+
*/
|
|
203
522
|
describe(audience, context) {
|
|
204
|
-
return [...this.registered.values()]
|
|
205
|
-
.
|
|
206
|
-
|
|
523
|
+
return [...this.registered.values()]
|
|
524
|
+
.filter((tool) => (!audience || tool.audience === audience) &&
|
|
525
|
+
(!tool.available || (!!context && tool.available(context))))
|
|
526
|
+
.map(({ id, kind, description, audience, effect, intentIds }) => ({
|
|
527
|
+
id,
|
|
528
|
+
kind,
|
|
529
|
+
description,
|
|
530
|
+
audience,
|
|
531
|
+
effect,
|
|
532
|
+
intentIds: intentIds === 'all' ? [...this.options.intentIds()] : [...intentIds],
|
|
533
|
+
}));
|
|
207
534
|
}
|
|
535
|
+
/**
|
|
536
|
+
* Reinstall every registered tool, plus the finalizer and normalizer, into another registry.
|
|
537
|
+
*
|
|
538
|
+
* The original definitions are reused rather than the compiled views, so the target applies
|
|
539
|
+
* its own policy checks and binding exactly as it would for a first registration.
|
|
540
|
+
*/
|
|
208
541
|
copyTo(target) {
|
|
209
542
|
for (const tool of this.registered.values())
|
|
210
543
|
target.install(this.sources.get(tool.id), tool);
|
|
@@ -213,7 +546,16 @@ export class ToolLifecycleRegistry {
|
|
|
213
546
|
if (this.normalizer)
|
|
214
547
|
target.registerNormalizer(this.normalizer);
|
|
215
548
|
}
|
|
216
|
-
|
|
217
|
-
|
|
549
|
+
/** Freeze the registry: no further registration, normalizer or finalizer is accepted. */
|
|
550
|
+
seal() {
|
|
551
|
+
this.sealed = true;
|
|
552
|
+
this.tools.seal();
|
|
553
|
+
return this;
|
|
554
|
+
}
|
|
555
|
+
/** Tool that owns the invocation step named by the decision, if any. */
|
|
556
|
+
selected(decision) {
|
|
557
|
+
return this.invocations.get(this.options.step(decision));
|
|
558
|
+
}
|
|
218
559
|
}
|
|
560
|
+
/** The lifecycle registry is the public `Tools` Kit entry point. */
|
|
219
561
|
export { ToolLifecycleRegistry as Tools };
|