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