@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
|
@@ -3,40 +3,84 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.defineCommand = defineCommand;
|
|
4
4
|
exports.compileCommands = compileCommands;
|
|
5
5
|
exports.commandSchema = commandSchema;
|
|
6
|
+
/**
|
|
7
|
+
* Interaction Kit: compile a single command protocol from field declarations.
|
|
8
|
+
*
|
|
9
|
+
* Place in the package: part of the `interaction` Kit. Parsing is synchronous and never
|
|
10
|
+
* executes a registered tool; it only validates the shape and applies an optional formatter.
|
|
11
|
+
*
|
|
12
|
+
* Exports: `defineCommand`, `compileCommands`, `commandSchema`, and the protocol types.
|
|
13
|
+
*/
|
|
6
14
|
const interaction_definition_js_1 = require("../../utils/interaction-definition.js");
|
|
7
15
|
const synchronous_js_1 = require("../../utils/synchronous.js");
|
|
8
16
|
const object_js_1 = require("../../utils/object.js");
|
|
9
17
|
const rules_js_1 = require("../../utils/rules.js");
|
|
10
18
|
const interaction_js_1 = require("../../structs/kits/interaction.js");
|
|
11
19
|
function reason(error, value, args) {
|
|
12
|
-
return () => typeof error === 'function'
|
|
20
|
+
return () => typeof error === 'function'
|
|
21
|
+
? error(value, ...args)
|
|
22
|
+
: (error ?? new TypeError('Invalid protocol value'));
|
|
13
23
|
}
|
|
14
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Compile declarations once. Parsing is synchronous and never executes a registered tool.
|
|
26
|
+
*
|
|
27
|
+
* Two schemas are produced from one declaration: `modelJsonSchema` marks only fields the model
|
|
28
|
+
* must fill, while `inputJsonSchema` marks every required field. A discriminator, when present,
|
|
29
|
+
* is prepended as a required constant field.
|
|
30
|
+
*
|
|
31
|
+
* @param definition - Fields, discriminator, checks, tags, error wording and optional
|
|
32
|
+
* formatter; predicates and formatters are bound to this object.
|
|
33
|
+
* @returns A frozen command with `keys`, `assert`, `parse` and the three schemas.
|
|
34
|
+
* @throws TypeError For an unknown category, a duplicate field or discriminator field, a check
|
|
35
|
+
* that still uses the retired `condition`/`conditions` names, or a non-synchronous predicate.
|
|
36
|
+
*/
|
|
15
37
|
function defineCommand(definition) {
|
|
16
38
|
(0, rules_js_1.breakWhile)(definition.category !== undefined && !interaction_js_1.INTERACTION_CATEGORIES.includes(definition.category), 'Invalid interaction category');
|
|
17
|
-
const fields = Object.fromEntries(Object.entries(fieldDefinitions(definition.fields)).map(([name, field]) => [
|
|
39
|
+
const fields = Object.fromEntries(Object.entries(fieldDefinitions(definition.fields)).map(([name, field]) => [
|
|
40
|
+
name,
|
|
41
|
+
{
|
|
18
42
|
jsonSchema: field.jsonSchema === undefined ? undefined : structuredClone(field.jsonSchema),
|
|
19
|
-
required: field.required,
|
|
20
|
-
|
|
43
|
+
required: field.required,
|
|
44
|
+
modelRequired: field.modelRequired,
|
|
45
|
+
owned: field.owned,
|
|
46
|
+
},
|
|
47
|
+
]));
|
|
21
48
|
for (const name of definition.ownedFields ?? []) {
|
|
22
49
|
if (!Object.hasOwn(fields, name))
|
|
23
50
|
Object.defineProperty(fields, name, { value: {}, enumerable: true });
|
|
24
51
|
}
|
|
25
|
-
const discriminator = definition.discriminator && {
|
|
52
|
+
const discriminator = definition.discriminator && {
|
|
53
|
+
field: definition.discriminator.field,
|
|
54
|
+
value: definition.discriminator.value,
|
|
55
|
+
};
|
|
26
56
|
(0, rules_js_1.breakWhile)(discriminator && Object.hasOwn(fields, discriminator.field), 'Duplicate protocol discriminator field');
|
|
27
57
|
const entries = [
|
|
28
|
-
...(discriminator
|
|
58
|
+
...(discriminator
|
|
59
|
+
? [
|
|
60
|
+
[
|
|
61
|
+
discriminator.field,
|
|
62
|
+
{ required: true, jsonSchema: { type: 'string', enum: [discriminator.value] } },
|
|
63
|
+
],
|
|
64
|
+
]
|
|
65
|
+
: []),
|
|
29
66
|
...Object.entries(fields),
|
|
30
67
|
];
|
|
31
|
-
const checks = (definition.checks ?? []).map(check => {
|
|
68
|
+
const checks = (definition.checks ?? []).map((check) => {
|
|
32
69
|
if (!check || check.occur === undefined || 'condition' in check || 'conditions' in check)
|
|
33
70
|
throw new TypeError('Protocol checks require occur');
|
|
34
71
|
const bind = (predicate) => predicate?.bind(check);
|
|
35
|
-
if (typeof check.occur !== 'function' &&
|
|
72
|
+
if (typeof check.occur !== 'function' &&
|
|
73
|
+
(!Array.isArray(check.occur) ||
|
|
74
|
+
check.occur.some((predicate) => typeof predicate !== 'function')))
|
|
36
75
|
throw new TypeError('Protocol occur requires a predicate or predicate array');
|
|
37
|
-
return Object.freeze({
|
|
38
|
-
|
|
39
|
-
|
|
76
|
+
return Object.freeze({
|
|
77
|
+
occur: typeof check.occur === 'function'
|
|
78
|
+
? check.occur.bind(check)
|
|
79
|
+
: Object.freeze(check.occur.map((predicate) => predicate.bind(check))),
|
|
80
|
+
when: bind(check.when),
|
|
81
|
+
error: typeof check.error === 'function' ? check.error.bind(check) : check.error,
|
|
82
|
+
tags: Object.freeze([...(check.tags ?? [])]),
|
|
83
|
+
});
|
|
40
84
|
});
|
|
41
85
|
const tags = [...(definition.tags ?? [])];
|
|
42
86
|
const additionalProperties = definition.additionalProperties ?? false;
|
|
@@ -45,35 +89,57 @@ function defineCommand(definition) {
|
|
|
45
89
|
const refine = definition.refine?.bind(definition), format = definition.format?.bind(definition);
|
|
46
90
|
const parameters = Object.fromEntries(Object.entries(fields).map(([name, field]) => [name, field.jsonSchema ?? {}]));
|
|
47
91
|
const schema = {
|
|
48
|
-
type: 'object',
|
|
49
|
-
|
|
92
|
+
type: 'object',
|
|
93
|
+
properties: Object.fromEntries(entries.map(([name, field]) => [name, field.jsonSchema ?? {}])),
|
|
94
|
+
required: entries
|
|
95
|
+
.filter(([, field]) => field.required && field.modelRequired !== false)
|
|
96
|
+
.map(([name]) => name),
|
|
50
97
|
additionalProperties,
|
|
51
98
|
};
|
|
52
|
-
const inputJsonSchema = {
|
|
99
|
+
const inputJsonSchema = {
|
|
100
|
+
...schema,
|
|
101
|
+
required: entries.filter(([, field]) => field.required).map(([name]) => name),
|
|
102
|
+
};
|
|
53
103
|
(0, object_js_1.freezeSchema)(inputJsonSchema);
|
|
54
104
|
(0, object_js_1.freezeSchema)(fields);
|
|
55
105
|
(0, object_js_1.freezeSchema)(parameters);
|
|
56
106
|
(0, object_js_1.freezeSchema)(schema);
|
|
57
|
-
const keys = (value) => entries
|
|
107
|
+
const keys = (value) => entries
|
|
108
|
+
.filter(([name, field]) => field.required ||
|
|
109
|
+
(optionalPresence === 'defined' ? value[name] !== undefined : Object.hasOwn(value, name)))
|
|
110
|
+
.map(([name]) => name);
|
|
58
111
|
const validate = (value, ...args) => {
|
|
59
112
|
const fail = reason(error, value, args);
|
|
60
113
|
(0, rules_js_1.breakWhile)(!value || typeof value !== 'object' || Array.isArray(value), fail, tags);
|
|
61
114
|
const record = value;
|
|
62
115
|
const expected = keys(record);
|
|
63
116
|
(0, rules_js_1.breakWhile)([
|
|
64
|
-
{ occur: () => expected.some(name => !Object.hasOwn(record, name)), error: fail, tags: ['required-fields'] },
|
|
65
117
|
{
|
|
66
|
-
occur: () =>
|
|
67
|
-
error: fail,
|
|
118
|
+
occur: () => expected.some((name) => !Object.hasOwn(record, name)),
|
|
119
|
+
error: fail,
|
|
120
|
+
tags: ['required-fields'],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
occur: () => !additionalProperties && Object.keys(record).some((name) => !expected.includes(name)),
|
|
124
|
+
error: fail,
|
|
125
|
+
tags: ['unknown-fields'],
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
occur: () => discriminator && record[discriminator.field] !== discriminator.value,
|
|
129
|
+
error: fail,
|
|
130
|
+
tags: ['discriminator'],
|
|
68
131
|
},
|
|
69
|
-
|
|
70
|
-
...checks.map(check => ({
|
|
132
|
+
...checks.map((check) => ({
|
|
71
133
|
occur: () => {
|
|
72
|
-
if (check.when &&
|
|
134
|
+
if (check.when &&
|
|
135
|
+
!(0, synchronous_js_1.booleanResult)(check.when(value, ...args), 'Protocol when predicates must return boolean synchronously'))
|
|
73
136
|
return false;
|
|
74
|
-
return typeof check.occur === 'function'
|
|
137
|
+
return typeof check.occur === 'function'
|
|
138
|
+
? (0, synchronous_js_1.synchronous)(check.occur(value, ...args), 'Protocol occur predicates must be synchronous')
|
|
139
|
+
: check.occur.some((occur) => (0, synchronous_js_1.synchronous)(occur(value, ...args), 'Protocol occur predicates must be synchronous'));
|
|
75
140
|
},
|
|
76
|
-
error: reason(check.error ?? error, value, args),
|
|
141
|
+
error: reason(check.error ?? error, value, args),
|
|
142
|
+
tags: check.tags,
|
|
77
143
|
})),
|
|
78
144
|
], tags);
|
|
79
145
|
(0, synchronous_js_1.assertion)(refine?.(value, ...args), 'Protocol refinements must return void synchronously');
|
|
@@ -83,14 +149,25 @@ function defineCommand(definition) {
|
|
|
83
149
|
...(definition.version !== undefined ? { version: definition.version } : {}),
|
|
84
150
|
...(definition.description !== undefined ? { description: definition.description } : {}),
|
|
85
151
|
...(definition.terminal !== undefined ? { terminal: definition.terminal } : {}),
|
|
86
|
-
fieldSchemas: parameters,
|
|
152
|
+
fieldSchemas: parameters,
|
|
153
|
+
modelJsonSchema: schema,
|
|
154
|
+
inputJsonSchema,
|
|
155
|
+
keys,
|
|
156
|
+
assert: validate,
|
|
87
157
|
modes: definition.modes && Object.freeze([...definition.modes]),
|
|
88
|
-
ownedFields: Object.freeze([
|
|
89
|
-
|
|
90
|
-
|
|
158
|
+
ownedFields: Object.freeze([
|
|
159
|
+
...new Set([
|
|
160
|
+
...(definition.ownedFields ?? []),
|
|
161
|
+
...Object.entries(fields)
|
|
162
|
+
.filter(([, field]) => field.owned)
|
|
163
|
+
.map(([name]) => name),
|
|
164
|
+
]),
|
|
165
|
+
]),
|
|
91
166
|
parse(value, ...args) {
|
|
92
167
|
validate(value, ...args);
|
|
93
|
-
return format
|
|
168
|
+
return format
|
|
169
|
+
? (0, synchronous_js_1.synchronous)(format(value, ...args), 'Protocol formatters must be synchronous')
|
|
170
|
+
: value;
|
|
94
171
|
},
|
|
95
172
|
});
|
|
96
173
|
}
|
|
@@ -98,9 +175,20 @@ function fieldDefinitions(fields) {
|
|
|
98
175
|
if (!Array.isArray(fields))
|
|
99
176
|
return fields;
|
|
100
177
|
(0, rules_js_1.breakWhile)(new Set(fields).size !== fields.length, 'Duplicate protocol field');
|
|
101
|
-
return Object.fromEntries(fields.map(name => [name, {}]));
|
|
178
|
+
return Object.fromEntries(fields.map((name) => [name, {}]));
|
|
102
179
|
}
|
|
103
|
-
/**
|
|
180
|
+
/**
|
|
181
|
+
* Compile a whole catalog with shared envelope fields.
|
|
182
|
+
*
|
|
183
|
+
* Applications declare only their own data and handlers. Defaults are merged in this order:
|
|
184
|
+
* unrelated default keys, then the command's own keys, with `fields`, `checks` and `tags`
|
|
185
|
+
* concatenated so shared envelope checks always run before per-command checks.
|
|
186
|
+
*
|
|
187
|
+
* @param definitions - Commands keyed by their wire id.
|
|
188
|
+
* @param defaults - Shared envelope definition; its discriminator field is removed per command.
|
|
189
|
+
* @returns A frozen record from id to compiled command.
|
|
190
|
+
* @throws TypeError From `defineCommand` for the first invalid declaration.
|
|
191
|
+
*/
|
|
104
192
|
function compileCommands(definitions, defaults = {}) {
|
|
105
193
|
defaults = (0, interaction_definition_js_1.pinCommandDefinition)(defaults);
|
|
106
194
|
return Object.freeze(Object.fromEntries(Object.entries(definitions).map(([id, value]) => {
|
|
@@ -108,20 +196,36 @@ function compileCommands(definitions, defaults = {}) {
|
|
|
108
196
|
const envelopeFields = { ...fieldDefinitions(defaults.fields ?? {}) };
|
|
109
197
|
if (definition.discriminator)
|
|
110
198
|
delete envelopeFields[definition.discriminator.field];
|
|
111
|
-
return [
|
|
112
|
-
|
|
199
|
+
return [
|
|
200
|
+
id,
|
|
201
|
+
defineCommand({
|
|
202
|
+
...defaults,
|
|
203
|
+
...definition,
|
|
113
204
|
fields: { ...envelopeFields, ...fieldDefinitions(definition.fields) },
|
|
114
205
|
checks: [...(defaults.checks ?? []), ...(definition.checks ?? [])],
|
|
115
206
|
tags: [...(defaults.tags ?? []), ...(definition.tags ?? [])],
|
|
116
|
-
})
|
|
207
|
+
}),
|
|
208
|
+
];
|
|
117
209
|
})));
|
|
118
210
|
}
|
|
119
|
-
/**
|
|
211
|
+
/**
|
|
212
|
+
* Build a JSON schema for one command id.
|
|
213
|
+
*
|
|
214
|
+
* Prefer compiled schemas; retain the existing open-schema contract for dynamic host protocols.
|
|
215
|
+
* A protocol without `fieldSchemas` falls back to an open object that only pins the
|
|
216
|
+
* discriminator, which keeps legacy hosts working without weakening compiled ones.
|
|
217
|
+
*
|
|
218
|
+
* @param id - Command id used as the discriminator value.
|
|
219
|
+
* @param protocol - Compiled command, or a shape carrying only `fieldSchemas`/`keys`.
|
|
220
|
+
* @param discriminator - Field name carrying the command id; defaults to `type`.
|
|
221
|
+
* @returns The compiled model schema, or a generated open schema.
|
|
222
|
+
*/
|
|
120
223
|
function commandSchema(id, protocol, discriminator = 'type') {
|
|
121
224
|
if (protocol.modelJsonSchema)
|
|
122
225
|
return protocol.modelJsonSchema;
|
|
123
226
|
return {
|
|
124
|
-
type: 'object',
|
|
227
|
+
type: 'object',
|
|
228
|
+
properties: { [discriminator]: { type: 'string', enum: [id] }, ...protocol.fieldSchemas },
|
|
125
229
|
required: protocol.fieldSchemas ? protocol.keys({ [discriminator]: id }) : [discriminator],
|
|
126
230
|
additionalProperties: !protocol.fieldSchemas,
|
|
127
231
|
};
|
|
@@ -5,30 +5,73 @@ exports.defineCommandCatalog = defineCommandCatalog;
|
|
|
5
5
|
const rules_js_1 = require("../../utils/rules.js");
|
|
6
6
|
const protocol_registry_js_1 = require("../../utils/protocol-registry.js");
|
|
7
7
|
const command_js_1 = require("./command.js");
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Mode and cross-protocol field ownership checks are shared by all receiving hosts.
|
|
10
|
+
*
|
|
11
|
+
* The catalog seals itself as soon as construction finishes, so a run cannot register a new
|
|
12
|
+
* command later; `set` remains available only for the superclass installation pass.
|
|
13
|
+
*/
|
|
9
14
|
class CommandCatalog extends protocol_registry_js_1.ProtocolRegistry {
|
|
15
|
+
/** Compile and construct a catalog from definitions in one call. */
|
|
10
16
|
static define = defineCommandCatalog;
|
|
17
|
+
/** Compile a set of definitions with shared envelope fields. */
|
|
11
18
|
static compile = command_js_1.compileCommands;
|
|
12
19
|
sealed = false;
|
|
13
20
|
options;
|
|
21
|
+
/**
|
|
22
|
+
* @param definitions - Compiled `[id, command]` pairs, installed in iteration order.
|
|
23
|
+
* @param options - Mode field, error wording and diagnostic tags used by `parse`.
|
|
24
|
+
*/
|
|
14
25
|
constructor(definitions, options = {}) {
|
|
15
26
|
// Map installation calls this class's set, which normalizes each registered identity.
|
|
16
27
|
super(definitions);
|
|
17
28
|
this.options = Object.freeze({ ...options, tags: Object.freeze([...(options.tags ?? [])]) });
|
|
18
29
|
this.sealed = true;
|
|
19
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Install one compiled command during construction.
|
|
33
|
+
*
|
|
34
|
+
* @throws Error When the id already exists or construction has finished.
|
|
35
|
+
*/
|
|
20
36
|
set(id, command) {
|
|
21
37
|
if (this.has(id))
|
|
22
38
|
throw new Error(`Duplicate protocol: ${id}`);
|
|
23
39
|
if (this.sealed)
|
|
24
40
|
throw new Error('Command catalog is sealed');
|
|
25
|
-
return super.set(id, Object.freeze({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
41
|
+
return super.set(id, Object.freeze({
|
|
42
|
+
...command,
|
|
43
|
+
id: id,
|
|
44
|
+
fieldSchemas: command.fieldSchemas,
|
|
45
|
+
modelJsonSchema: command.modelJsonSchema,
|
|
46
|
+
inputJsonSchema: command.inputJsonSchema,
|
|
47
|
+
category: command.category,
|
|
48
|
+
version: command.version,
|
|
49
|
+
description: command.description,
|
|
50
|
+
terminal: command.terminal,
|
|
51
|
+
modes: command.modes && Object.freeze([...command.modes]),
|
|
52
|
+
ownedFields: Object.freeze([...command.ownedFields]),
|
|
53
|
+
keys: command.keys.bind(command),
|
|
54
|
+
assert: command.assert.bind(command),
|
|
55
|
+
parse: command.parse.bind(command),
|
|
56
|
+
}));
|
|
29
57
|
}
|
|
30
|
-
|
|
31
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Removal is not supported.
|
|
60
|
+
*
|
|
61
|
+
* @throws Error Always, because the catalog is sealed.
|
|
62
|
+
*/
|
|
63
|
+
delete(_id) {
|
|
64
|
+
throw new Error('Command catalog is sealed');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Clearing is not supported.
|
|
68
|
+
*
|
|
69
|
+
* @throws Error Always, because the catalog is sealed.
|
|
70
|
+
*/
|
|
71
|
+
clear() {
|
|
72
|
+
throw new Error('Command catalog is sealed');
|
|
73
|
+
}
|
|
74
|
+
/** Compiled commands in registration order. */
|
|
32
75
|
get definitions() {
|
|
33
76
|
return Object.freeze([...this.values()]);
|
|
34
77
|
}
|
|
@@ -36,25 +79,57 @@ class CommandCatalog extends protocol_registry_js_1.ProtocolRegistry {
|
|
|
36
79
|
toRecord() {
|
|
37
80
|
return Object.freeze(Object.fromEntries(this));
|
|
38
81
|
}
|
|
39
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* The same declarations drive purpose-specific menus, documentation and handler binding.
|
|
84
|
+
*
|
|
85
|
+
* @param category - Restrict to one interaction category; omit for every command.
|
|
86
|
+
* @returns Plain descriptors in registration order, without schemas or handlers.
|
|
87
|
+
*/
|
|
40
88
|
manifest(category) {
|
|
41
|
-
return Object.freeze([...this]
|
|
89
|
+
return Object.freeze([...this]
|
|
90
|
+
.filter(([, command]) => category === undefined || command.category === category)
|
|
42
91
|
.map(([id, { category, description, terminal, modes }]) => Object.freeze({ id, category, description, terminal, modes })));
|
|
43
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Validate and parse one payload as the named command.
|
|
95
|
+
*
|
|
96
|
+
* Checks run before the command's own parser: the id must exist, the mode (when configured)
|
|
97
|
+
* must be allowed, and no other command may claim a field that this payload sets. The last
|
|
98
|
+
* rule prevents one command from silently consuming another command's data.
|
|
99
|
+
*
|
|
100
|
+
* @param id - Command id selected by the caller.
|
|
101
|
+
* @param value - Raw payload.
|
|
102
|
+
* @param args - Extra arguments forwarded to the command parser.
|
|
103
|
+
* @returns The parsed result for that command.
|
|
104
|
+
* @throws A configured error for an unknown command, a disallowed mode or a field owned by
|
|
105
|
+
* another command; the command's own error for a shape violation.
|
|
106
|
+
*/
|
|
44
107
|
parse(id, value, ...args) {
|
|
45
108
|
const protocol = this.get(id);
|
|
46
|
-
(0, rules_js_1.breakWhile)(!protocol, this.options.unknownError ?? 'Unknown command', [
|
|
109
|
+
(0, rules_js_1.breakWhile)(!protocol, this.options.unknownError ?? 'Unknown command', [
|
|
110
|
+
...this.options.tags,
|
|
111
|
+
'command-selection',
|
|
112
|
+
]);
|
|
47
113
|
const record = value;
|
|
48
114
|
const modeField = this.options.modeField;
|
|
49
115
|
(0, rules_js_1.breakWhile)(modeField && !protocol.modes?.includes(record?.[modeField]), this.options.modeError ?? 'Unsupported command mode', [...this.options.tags, 'command-mode']);
|
|
50
116
|
const ownershipTags = [...this.options.tags, 'field-ownership'];
|
|
51
117
|
for (const [owner, other] of this) {
|
|
52
|
-
(0, rules_js_1.breakWhile)(owner !== id && other.ownedFields.some(field => record?.[field] !== undefined), this.options.ownershipError ?? 'Field belongs to another command', ownershipTags);
|
|
118
|
+
(0, rules_js_1.breakWhile)(owner !== id && other.ownedFields.some((field) => record?.[field] !== undefined), this.options.ownershipError ?? 'Field belongs to another command', ownershipTags);
|
|
53
119
|
}
|
|
54
120
|
return protocol.parse(value, ...args);
|
|
55
121
|
}
|
|
56
122
|
}
|
|
57
123
|
exports.CommandCatalog = CommandCatalog;
|
|
124
|
+
/**
|
|
125
|
+
* Compile definitions and wrap them in a sealed catalog.
|
|
126
|
+
*
|
|
127
|
+
* @param definitions - Command definitions keyed by wire id.
|
|
128
|
+
* @param defaults - Shared envelope definition merged into every command.
|
|
129
|
+
* @param options - Mode field, error wording and diagnostic tags.
|
|
130
|
+
* @returns A sealed catalog ready for `manifest`, `parse` and handler binding.
|
|
131
|
+
* @throws TypeError From compilation for the first invalid definition.
|
|
132
|
+
*/
|
|
58
133
|
function defineCommandCatalog(definitions, defaults = {}, options = {}) {
|
|
59
134
|
const compiled = (0, command_js_1.compileCommands)(definitions, defaults);
|
|
60
135
|
return new CommandCatalog(Object.entries(compiled), options);
|
|
@@ -3,24 +3,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.INTERACTION_CATEGORIES = void 0;
|
|
4
4
|
exports.bindInteraction = bindInteraction;
|
|
5
5
|
const rules_js_1 = require("../../utils/rules.js");
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Bind every registered transfer command to a local handler. Models cannot add handlers.
|
|
8
|
+
*
|
|
9
|
+
* @param protocol - Object exposing the command manifest and a `receive` entry point.
|
|
10
|
+
* @param handlers - One handler per command id, bound to this handlers object.
|
|
11
|
+
* @returns A frozen `{ catalog, dispatch }`; `dispatch` selects by the validated command id.
|
|
12
|
+
* @throws A configured error when a handler is missing (including prototype members such as
|
|
13
|
+
* `constructor` that were never assigned) or when the table contains an unregistered id.
|
|
14
|
+
*/
|
|
7
15
|
function bindInteraction(protocol, handlers) {
|
|
8
|
-
const catalog = Object.freeze(protocol.commands.manifest().map(command => Object.freeze({
|
|
9
|
-
id: command.id,
|
|
16
|
+
const catalog = Object.freeze(protocol.commands.manifest().map((command) => Object.freeze({
|
|
17
|
+
id: command.id,
|
|
18
|
+
category: command.category,
|
|
19
|
+
description: command.description,
|
|
20
|
+
terminal: command.terminal,
|
|
10
21
|
modes: command.modes && Object.freeze([...command.modes]),
|
|
11
22
|
})));
|
|
12
23
|
const receive = protocol.receive.bind(protocol);
|
|
13
|
-
const ids = new Set(catalog.map(command => command.id));
|
|
24
|
+
const ids = new Set(catalog.map((command) => command.id));
|
|
14
25
|
(0, rules_js_1.breakWhile)([
|
|
15
26
|
{
|
|
16
|
-
occur: () => catalog.some(command => typeof handlers[command.id] !== 'function' ||
|
|
17
|
-
|
|
27
|
+
occur: () => catalog.some((command) => typeof handlers[command.id] !== 'function' ||
|
|
28
|
+
(!Object.hasOwn(handlers, command.id) &&
|
|
29
|
+
(command.id === 'constructor' ||
|
|
30
|
+
handlers[command.id] === Reflect.get(Object.prototype, command.id)))),
|
|
31
|
+
error: 'Missing interaction handler',
|
|
32
|
+
tags: ['missing-handler'],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
occur: () => Object.keys(handlers).some((id) => !ids.has(id)),
|
|
36
|
+
error: 'Unregistered interaction handler',
|
|
37
|
+
tags: ['unknown-handler'],
|
|
18
38
|
},
|
|
19
|
-
{ occur: () => Object.keys(handlers).some(id => !ids.has(id)), error: 'Unregistered interaction handler', tags: ['unknown-handler'] },
|
|
20
39
|
], ['agent-core', 'interaction-registration']);
|
|
21
|
-
const registered = Object.freeze(Object.fromEntries(catalog.map(({ id }) => [id,
|
|
22
|
-
handlers[id].bind(handlers),
|
|
23
|
-
])));
|
|
40
|
+
const registered = Object.freeze(Object.fromEntries(catalog.map(({ id }) => [id, handlers[id].bind(handlers)])));
|
|
24
41
|
return Object.freeze({
|
|
25
42
|
catalog,
|
|
26
43
|
dispatch(value, context, ...args) {
|
|
@@ -15,6 +15,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.Interaction = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Interaction Kit entry: command protocols, their catalog and local handler binding.
|
|
20
|
+
*
|
|
21
|
+
* Place in the package: an optional App-side library for the payload family exchanged between
|
|
22
|
+
* a web or AI client and the App. Framing, transport and the actual command execution stay
|
|
23
|
+
* outside; this directory validates shapes, routes on a discriminator and binds handlers.
|
|
24
|
+
*
|
|
25
|
+
* Exports: everything from `./command.js`, `./commands.js`, `./transfer.js` and
|
|
26
|
+
* `./handlers.js`, plus `InteractionProtocol` re-exported as `Interaction`.
|
|
27
|
+
*/
|
|
18
28
|
__exportStar(require("./command.js"), exports);
|
|
19
29
|
__exportStar(require("./commands.js"), exports);
|
|
20
30
|
__exportStar(require("./transfer.js"), exports);
|
|
@@ -2,13 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InteractionProtocol = void 0;
|
|
4
4
|
exports.defineInteractionProtocol = defineInteractionProtocol;
|
|
5
|
+
/**
|
|
6
|
+
* Interaction Kit: the web/AI payload family with selector normalization.
|
|
7
|
+
*
|
|
8
|
+
* Place in the package: part of the `interaction` Kit and its main entry. HTTP/SSE framing and
|
|
9
|
+
* the actual command execution remain separate ports; this class only validates the envelope,
|
|
10
|
+
* accepts selector aliases and delegates parsing to the sealed command catalog.
|
|
11
|
+
*
|
|
12
|
+
* Exports: `InteractionProtocol`, `defineInteractionProtocol`, and its definition type.
|
|
13
|
+
*/
|
|
5
14
|
const interaction_definition_js_1 = require("../../utils/interaction-definition.js");
|
|
6
15
|
const rules_js_1 = require("../../utils/rules.js");
|
|
7
16
|
const commands_js_1 = require("./commands.js");
|
|
8
17
|
const command_js_1 = require("./command.js");
|
|
9
18
|
const handlers_js_1 = require("./handlers.js");
|
|
10
19
|
const interaction_js_1 = require("../../structs/kits/interaction.js");
|
|
11
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Web/AI payload family. HTTP/SSE framing and actual command execution remain separate ports.
|
|
22
|
+
*
|
|
23
|
+
* Every command registered here gets the envelope's discriminator forced to its own id, so a
|
|
24
|
+
* payload cannot claim one command while carrying another command's data.
|
|
25
|
+
*/
|
|
12
26
|
class InteractionProtocol {
|
|
13
27
|
static define = defineInteractionProtocol;
|
|
14
28
|
static Commands = commands_js_1.CommandCatalog;
|
|
@@ -16,39 +30,79 @@ class InteractionProtocol {
|
|
|
16
30
|
static commandSchema = command_js_1.commandSchema;
|
|
17
31
|
static bind = handlers_js_1.bindInteraction;
|
|
18
32
|
static categories = interaction_js_1.INTERACTION_CATEGORIES;
|
|
33
|
+
/** Field carrying the command id in a payload. */
|
|
19
34
|
commandField;
|
|
35
|
+
/** Accepted selector names: the command field first, then any declared aliases. */
|
|
20
36
|
commandSelectors;
|
|
37
|
+
/** Sealed catalog of the compiled commands. */
|
|
21
38
|
commands;
|
|
22
39
|
selectionError;
|
|
40
|
+
/**
|
|
41
|
+
* @param definition - Command definitions plus envelope, selector aliases and error wording.
|
|
42
|
+
* @throws An error for a blank or duplicate selector, a conflicting per-command discriminator
|
|
43
|
+
* (it must match the envelope field and the command's own id).
|
|
44
|
+
*/
|
|
23
45
|
constructor(definition) {
|
|
24
|
-
const { commands, commandField, commandAliases, modeField, unknownError, modeError, ownershipError } = definition;
|
|
46
|
+
const { commands, commandField, commandAliases, modeField, unknownError, modeError, ownershipError, } = definition;
|
|
25
47
|
const { discriminator: _discriminator, modes: _modes, ownedFields: _ownedFields, ...envelope } = (0, interaction_definition_js_1.pinCommandDefinition)(definition);
|
|
26
|
-
const selectionError = typeof definition.selectionError === 'function'
|
|
48
|
+
const selectionError = typeof definition.selectionError === 'function'
|
|
49
|
+
? definition.selectionError.bind(definition)
|
|
50
|
+
: definition.selectionError;
|
|
27
51
|
(0, rules_js_1.breakWhile)(!commandField.trim(), 'Missing transfer command field');
|
|
28
52
|
this.commandField = commandField;
|
|
29
53
|
this.commandSelectors = Object.freeze([commandField, ...(commandAliases ?? [])]);
|
|
30
54
|
(0, rules_js_1.breakWhile)([
|
|
31
|
-
{
|
|
32
|
-
|
|
55
|
+
{
|
|
56
|
+
occur: () => this.commandSelectors.some((field) => !field.trim()),
|
|
57
|
+
error: 'Missing transfer selector',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
occur: () => new Set(this.commandSelectors).size !== this.commandSelectors.length,
|
|
61
|
+
error: 'Duplicate transfer selector',
|
|
62
|
+
},
|
|
33
63
|
]);
|
|
34
64
|
this.selectionError = selectionError;
|
|
35
65
|
const registered = Object.fromEntries(Object.entries(commands).map(([id, value]) => {
|
|
36
66
|
const command = (0, interaction_definition_js_1.pinCommandDefinition)(value);
|
|
37
|
-
(0, rules_js_1.breakWhile)(command.discriminator &&
|
|
67
|
+
(0, rules_js_1.breakWhile)(command.discriminator &&
|
|
68
|
+
(command.discriminator.field !== commandField || command.discriminator.value !== id), 'Conflicting transfer command discriminator');
|
|
38
69
|
return [id, { ...command, discriminator: { field: commandField, value: id } }];
|
|
39
70
|
}));
|
|
40
71
|
this.commands = (0, commands_js_1.defineCommandCatalog)(registered, envelope, {
|
|
41
|
-
modeField,
|
|
72
|
+
modeField,
|
|
73
|
+
unknownError,
|
|
74
|
+
modeError,
|
|
75
|
+
ownershipError,
|
|
76
|
+
tags: envelope.tags,
|
|
42
77
|
});
|
|
43
78
|
}
|
|
79
|
+
/** JSON schema for the model, expressed as a union of the per-command schemas. */
|
|
44
80
|
get modelJsonSchema() {
|
|
45
|
-
return { anyOf: [...this.commands.values()].map(command => command.modelJsonSchema) };
|
|
81
|
+
return { anyOf: [...this.commands.values()].map((command) => command.modelJsonSchema) };
|
|
46
82
|
}
|
|
47
|
-
|
|
83
|
+
/** Strict JSON schema for transport input, expressed as a union of per-command schemas. */
|
|
84
|
+
get inputJsonSchema() {
|
|
85
|
+
return { anyOf: [...this.commands.values()].map((command) => command.inputJsonSchema) };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Parse a payload and return only the result.
|
|
89
|
+
*
|
|
90
|
+
* @param value - Raw payload.
|
|
91
|
+
* @param args - Extra arguments forwarded to the command parser.
|
|
92
|
+
* @throws The same errors as `receive`.
|
|
93
|
+
*/
|
|
48
94
|
parse(value, ...args) {
|
|
49
95
|
return this.receive(value, ...args).result;
|
|
50
96
|
}
|
|
51
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Retain the selected command id separately from a formatter's output.
|
|
99
|
+
*
|
|
100
|
+
* @param value - Raw payload; aliases are normalized when more than one selector is allowed.
|
|
101
|
+
* @param args - Extra arguments forwarded to the command parser.
|
|
102
|
+
* @returns The selected command id and its parsed result.
|
|
103
|
+
* @throws A configured error for a malformed or ambiguous selector, or the catalog's
|
|
104
|
+
* command/mode/ownership errors.
|
|
105
|
+
*/
|
|
52
106
|
receive(value, ...args) {
|
|
53
107
|
const normalized = this.normalizeSelector(value, args);
|
|
54
108
|
const id = normalized[this.commandField];
|
|
@@ -58,14 +112,19 @@ class InteractionProtocol {
|
|
|
58
112
|
// Preserve the original no-alias parsing path; alias handling is an explicit host choice.
|
|
59
113
|
if (this.commandSelectors.length === 1)
|
|
60
114
|
return value;
|
|
61
|
-
const fail = () => typeof this.selectionError === 'function'
|
|
62
|
-
|
|
115
|
+
const fail = () => typeof this.selectionError === 'function'
|
|
116
|
+
? this.selectionError(value, ...args)
|
|
117
|
+
: (this.selectionError ?? new TypeError('Invalid transfer selector'));
|
|
63
118
|
(0, rules_js_1.breakWhile)(!value || typeof value !== 'object' || Array.isArray(value), fail);
|
|
64
119
|
const record = value;
|
|
65
|
-
const selectors = this.commandSelectors.filter(field => Object.hasOwn(record, field));
|
|
120
|
+
const selectors = this.commandSelectors.filter((field) => Object.hasOwn(record, field));
|
|
66
121
|
(0, rules_js_1.breakWhile)([
|
|
67
122
|
{ occur: () => selectors.length !== 1, error: fail, tags: ['selector-count'] },
|
|
68
|
-
{
|
|
123
|
+
{
|
|
124
|
+
occur: () => typeof record[selectors[0]] !== 'string',
|
|
125
|
+
error: fail,
|
|
126
|
+
tags: ['selector-value'],
|
|
127
|
+
},
|
|
69
128
|
]);
|
|
70
129
|
const normalized = { ...record, [this.commandField]: record[selectors[0]] };
|
|
71
130
|
if (selectors[0] !== this.commandField)
|
|
@@ -74,6 +133,13 @@ class InteractionProtocol {
|
|
|
74
133
|
}
|
|
75
134
|
}
|
|
76
135
|
exports.InteractionProtocol = InteractionProtocol;
|
|
136
|
+
/**
|
|
137
|
+
* Construct a protocol from one definition.
|
|
138
|
+
*
|
|
139
|
+
* @param definition - Commands, envelope and selector configuration.
|
|
140
|
+
* @returns A new protocol instance.
|
|
141
|
+
* @throws The same errors as the constructor.
|
|
142
|
+
*/
|
|
77
143
|
function defineInteractionProtocol(definition) {
|
|
78
144
|
return new InteractionProtocol(definition);
|
|
79
145
|
}
|