@jangts/agent-core 0.1.1 → 0.2.0
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 +18 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.md +27 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +45 -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 +11 -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 +32 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +102 -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.js +11 -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 +38 -0
- package/dist/esm/structs/kits/search.d.ts +22 -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 +30 -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 +52 -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 +49 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +145 -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 +32 -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 +10 -0
- package/dist/esm/support/model/completion/default.js +29 -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 +11 -0
- package/dist/esm/support/model/completion/session.js +99 -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 +20 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +15 -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 +24 -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 +3 -2
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Prepare a knowledge candidate from a supplied source file.
|
|
3
|
+
*
|
|
4
|
+
* The script belongs to the App's development skills (开发技能). It never touches the
|
|
5
|
+
* active knowledge files: it validates the new document against the current catalog
|
|
6
|
+
* and writes a self-contained candidate directory that a later publication step can
|
|
7
|
+
* approve. The candidate records the base configuration hash and the revisions of the
|
|
8
|
+
* documents it was prepared against, so the publication can detect a stale base.
|
|
9
|
+
*
|
|
10
|
+
* Main exports: none. The file runs as a command and prints one JSON receipt.
|
|
11
|
+
*/
|
|
1
12
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
13
|
import { resolve, join, sep } from 'node:path';
|
|
3
14
|
import { pathToFileURL } from 'node:url';
|
|
@@ -8,17 +19,57 @@ import { readApplicationKnowledge, compileApplicationKnowledge } from './lib/kno
|
|
|
8
19
|
const args = process.argv.slice(2);
|
|
9
20
|
if (args.length !== 5 || args[1] !== '--source' || args[3] !== '--id')
|
|
10
21
|
throw new Error('Usage: node prepare-source.mjs PROJECT --source UTF8_FILE --id DOCUMENT_ID');
|
|
11
|
-
const project = resolve(args[0]),
|
|
22
|
+
const project = resolve(args[0]),
|
|
23
|
+
// A trailing separator makes the directory a base URL, so relative entries
|
|
24
|
+
// resolve inside the project instead of against the file system root.
|
|
25
|
+
directory = pathToFileURL(project + sep);
|
|
12
26
|
const { documents, policy, baseConfigSha256 } = await readApplicationKnowledge(directory);
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
27
|
+
// A document with the same id is replaced rather than added.
|
|
28
|
+
const previous = documents.find((item) => item.id === args[4]);
|
|
29
|
+
const source = await readSuppliedSource(
|
|
30
|
+
resolve(args[2]),
|
|
31
|
+
args[4],
|
|
32
|
+
policy.maxDocumentBytes,
|
|
33
|
+
// The locale of the replaced document is carried over, so the revision stays
|
|
34
|
+
// comparable across the replacement.
|
|
35
|
+
previous?.locale,
|
|
36
|
+
);
|
|
37
|
+
// The candidate must fit the catalog together with the other documents, so the
|
|
38
|
+
// whole set is compiled before anything is written.
|
|
39
|
+
compileApplicationKnowledge(
|
|
40
|
+
[...documents.filter((item) => item.id !== args[4]), source.document],
|
|
41
|
+
policy,
|
|
42
|
+
);
|
|
43
|
+
const target = join(
|
|
44
|
+
project,
|
|
45
|
+
'.local',
|
|
46
|
+
'knowledge-candidates',
|
|
47
|
+
// The random suffix keeps two candidates for the same document apart.
|
|
48
|
+
args[4].replace(/[^a-z0-9_.-]/g, '_') + '-' + randomUUID(),
|
|
49
|
+
);
|
|
17
50
|
await mkdir(target, { recursive: true });
|
|
51
|
+
// `wx` fails instead of overwriting an existing file.
|
|
18
52
|
await writeFile(join(target, 'source.knowledge.md'), source.bytes, { flag: 'wx' });
|
|
19
|
-
await writeFile(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
53
|
+
await writeFile(
|
|
54
|
+
join(target, 'proposal.json'),
|
|
55
|
+
JSON.stringify(
|
|
56
|
+
{
|
|
57
|
+
schemaVersion: 1,
|
|
58
|
+
status: 'candidate',
|
|
59
|
+
document: args[4],
|
|
60
|
+
action: previous ? 'replace' : 'add',
|
|
61
|
+
originalName: source.name,
|
|
62
|
+
locale: source.document.locale,
|
|
63
|
+
contentSha256: source.digest,
|
|
64
|
+
revision: source.document.revision,
|
|
65
|
+
baseConfigSha256,
|
|
66
|
+
baseDocuments: documents.map((item) => ({ id: item.id, revision: item.revision })),
|
|
67
|
+
published: false,
|
|
68
|
+
},
|
|
69
|
+
null,
|
|
70
|
+
2,
|
|
71
|
+
) + '\n',
|
|
72
|
+
{ flag: 'wx' },
|
|
73
|
+
);
|
|
74
|
+
// The receipt states that nothing was published and no active file was changed.
|
|
24
75
|
console.log(JSON.stringify({ candidate: target, published: false, activeFilesChanged: false }));
|
|
@@ -11,12 +11,17 @@ const assets = {
|
|
|
11
11
|
'prepare-source': 'skills/agent-core-app/scripts/prepare-source.mjs',
|
|
12
12
|
},
|
|
13
13
|
docs: {
|
|
14
|
-
guide: 'docs/README.md',
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
guide: 'docs/README.md',
|
|
15
|
+
api: 'docs/api/README.md',
|
|
16
|
+
maintenance: 'docs/maintenance.md',
|
|
17
|
+
flow: 'docs/flows/knowledge-maintenance.md',
|
|
18
|
+
gettingStarted: 'docs/getting-started.md',
|
|
19
|
+
knowledge: 'docs/knowledge.md',
|
|
17
20
|
createApp: 'docs/create-app.md',
|
|
18
|
-
materials: 'docs/materials.md',
|
|
19
|
-
|
|
21
|
+
materials: 'docs/materials.md',
|
|
22
|
+
memory: 'docs/memory-and-learning.md',
|
|
23
|
+
answering: 'docs/api/knowledge-answering.md',
|
|
24
|
+
acceptance: 'docs/acceptance.md',
|
|
20
25
|
},
|
|
21
26
|
};
|
|
22
27
|
|
|
@@ -24,28 +29,37 @@ async function packageAt(directory) {
|
|
|
24
29
|
try {
|
|
25
30
|
const manifest = JSON.parse(await readFile(join(directory, 'package.json'), 'utf8'));
|
|
26
31
|
return manifest.name === packageName ? manifest : undefined;
|
|
27
|
-
} catch (error) {
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (error.code !== 'ENOENT') throw error;
|
|
34
|
+
}
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
async function installedPackage(project) {
|
|
31
38
|
// Node resolves the public entry without loading it or evaluating App code.
|
|
32
39
|
const require = createRequire(pathToFileURL(join(project, '__agent_core_resolution__.cjs')));
|
|
33
40
|
let entry;
|
|
34
|
-
try {
|
|
35
|
-
|
|
41
|
+
try {
|
|
42
|
+
entry = require.resolve(packageName);
|
|
43
|
+
} catch (error) {
|
|
36
44
|
if (error.code !== 'MODULE_NOT_FOUND') throw error;
|
|
37
45
|
// A broken installed entry must not silently select a different SDK version.
|
|
38
46
|
for (const directory of require.resolve.paths(packageName) ?? []) {
|
|
39
|
-
try {
|
|
40
|
-
|
|
47
|
+
try {
|
|
48
|
+
await stat(join(directory, packageName));
|
|
49
|
+
} catch (missing) {
|
|
50
|
+
if (missing.code === 'ENOENT') continue;
|
|
51
|
+
throw missing;
|
|
52
|
+
}
|
|
41
53
|
throw error;
|
|
42
54
|
}
|
|
43
55
|
return;
|
|
44
56
|
}
|
|
45
57
|
for (let directory = dirname(entry); ; directory = dirname(directory)) {
|
|
46
58
|
const manifest = await packageAt(directory);
|
|
47
|
-
if (manifest)
|
|
48
|
-
|
|
59
|
+
if (manifest)
|
|
60
|
+
return { root: directory, version: manifest.version, source: 'project-dependency' };
|
|
61
|
+
if (dirname(directory) === directory)
|
|
62
|
+
throw new Error(`Cannot locate ${packageName} manifest for resolved entry ${entry}`);
|
|
49
63
|
}
|
|
50
64
|
}
|
|
51
65
|
|
|
@@ -60,16 +74,30 @@ export async function resolveSdkResources(project) {
|
|
|
60
74
|
if (!sdk) {
|
|
61
75
|
// Only the Skill distributed inside the SDK can use sibling assets.
|
|
62
76
|
const root = fileURLToPath(new URL('../../../../', import.meta.url));
|
|
63
|
-
const bundled =
|
|
77
|
+
const bundled =
|
|
78
|
+
resolve(fileURLToPath(import.meta.url)) ===
|
|
79
|
+
resolve(root, 'development/skills/agent-core-app/scripts/resources.mjs');
|
|
64
80
|
const manifest = bundled ? await packageAt(root) : undefined;
|
|
65
|
-
if (!manifest)
|
|
81
|
+
if (!manifest)
|
|
82
|
+
throw new Error(
|
|
83
|
+
`Cannot resolve ${packageName} from ${project}. Install the SDK and its real dependencies in the existing App, or use the Skill inside the distributed SDK.`,
|
|
84
|
+
);
|
|
66
85
|
sdk = { root, version: manifest.version, source: 'bundled-sdk' };
|
|
67
86
|
}
|
|
68
87
|
const resources = {};
|
|
69
88
|
for (const [group, entries] of Object.entries(assets)) {
|
|
70
|
-
resources[group] = Object.fromEntries(
|
|
71
|
-
|
|
89
|
+
resources[group] = Object.fromEntries(
|
|
90
|
+
await Promise.all(
|
|
91
|
+
Object.entries(entries).map(async ([name, relative]) => [
|
|
92
|
+
name,
|
|
93
|
+
await requiredFile(sdk.root, relative),
|
|
94
|
+
]),
|
|
95
|
+
),
|
|
96
|
+
);
|
|
72
97
|
}
|
|
73
|
-
const knowledgeLoader = await requiredFile(
|
|
98
|
+
const knowledgeLoader = await requiredFile(
|
|
99
|
+
sdk.root,
|
|
100
|
+
'skills/agent-core-app/scripts/lib/knowledge.mjs',
|
|
101
|
+
);
|
|
74
102
|
return { sdk, ...resources, knowledgeLoader };
|
|
75
103
|
}
|
|
@@ -1,8 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Validate the active knowledge catalog of one project.
|
|
3
|
+
*
|
|
4
|
+
* The script belongs to the App's development skills (开发技能). It loads the App-owned
|
|
5
|
+
* configuration and document files, compiles them into a Knowledge catalog and reports
|
|
6
|
+
* the resulting document ids. An empty catalog is reported as a distinct status, so a
|
|
7
|
+
* project that has not received its first source is not confused with a broken one.
|
|
8
|
+
*
|
|
9
|
+
* Main exports: none. The file runs as a command and prints one JSON receipt.
|
|
10
|
+
*/
|
|
1
11
|
import { pathToFileURL } from 'node:url';
|
|
2
12
|
import { resolve, sep } from 'node:path';
|
|
3
13
|
import { loadApplicationKnowledge } from './lib/knowledge.mjs';
|
|
4
14
|
|
|
5
15
|
if (process.argv.length !== 3) throw new Error('Usage: node validate-knowledge.mjs PROJECT');
|
|
16
|
+
// A trailing separator turns the project path into a base URL, so the document
|
|
17
|
+
// entries resolve inside the project directory.
|
|
6
18
|
const directory = pathToFileURL(resolve(process.argv[2]) + sep);
|
|
7
19
|
const catalog = await loadApplicationKnowledge(directory);
|
|
8
|
-
console.log(
|
|
20
|
+
console.log(
|
|
21
|
+
JSON.stringify({
|
|
22
|
+
status: catalog.ids().length ? 'valid' : 'empty-awaiting-source',
|
|
23
|
+
documents: catalog.ids(),
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
@@ -1,25 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"templates": [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
"templates": [
|
|
4
|
+
{
|
|
5
|
+
"id": "node-ts",
|
|
6
|
+
"revision": "1",
|
|
7
|
+
"directory": "node-ts",
|
|
8
|
+
"files": [
|
|
9
|
+
{ "origin": "template", "source": "package.json.tpl", "target": "package.json" },
|
|
10
|
+
{ "origin": "template", "source": "tsconfig.json.tpl", "target": "tsconfig.json" },
|
|
11
|
+
{ "origin": "template", "source": "gitignore.tpl", "target": ".gitignore" },
|
|
12
|
+
{ "origin": "template", "source": "env.example.tpl", "target": ".env.example" },
|
|
13
|
+
{ "origin": "template", "source": "README.md.tpl", "target": "README.md" },
|
|
14
|
+
{ "origin": "template", "source": "src/config.ts.tpl", "target": "src/config.ts" },
|
|
15
|
+
{ "origin": "template", "source": "src/app.ts.tpl", "target": "src/app.ts" },
|
|
16
|
+
{ "origin": "template", "source": "src/catalog.ts.tpl", "target": "src/catalog.ts" },
|
|
17
|
+
{ "origin": "template", "source": "src/handlers.ts.tpl", "target": "src/handlers.ts" },
|
|
18
|
+
{ "origin": "template", "source": "src/model.ts.tpl", "target": "src/model.ts" },
|
|
19
|
+
{
|
|
20
|
+
"origin": "template",
|
|
21
|
+
"source": "scripts/knowledge.mjs.tpl",
|
|
22
|
+
"target": "scripts/knowledge.mjs"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"origin": "skill",
|
|
26
|
+
"source": "scripts/resources.mjs",
|
|
27
|
+
"target": "scripts/sdk-resources.mjs"
|
|
28
|
+
},
|
|
29
|
+
{ "origin": "template", "source": "examples/ask.mjs.tpl", "target": "examples/ask.mjs" },
|
|
30
|
+
{ "origin": "template", "source": "test/app.test.mjs.tpl", "target": "test/app.test.mjs" },
|
|
31
|
+
{
|
|
32
|
+
"origin": "template",
|
|
33
|
+
"source": "knowledge/knowledge.config.json.tpl",
|
|
34
|
+
"target": "knowledge/knowledge.config.json"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
]
|
|
25
39
|
}
|
|
@@ -15,6 +15,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.commandSchema = exports.defineCommand = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Capability registration surface: model capabilities, executable tools and host-selected
|
|
20
|
+
* invocations.
|
|
21
|
+
*
|
|
22
|
+
* These registries hold declarations only. Which capabilities a stage may use, whether a
|
|
23
|
+
* call is authorized, and what a payload means remain App decisions; this barrel provides
|
|
24
|
+
* the mechanisms that validate, seal and execute those declarations.
|
|
25
|
+
*
|
|
26
|
+
* Exports: the model capability registry (`model`), the executable tool registry and its
|
|
27
|
+
* sync/async invocation entry points (`tools`), host-selected invocation execution
|
|
28
|
+
* (`invocation`), and the Interaction Kit's protocol, command and handler definitions that
|
|
29
|
+
* shape and validate model-produced interactions.
|
|
30
|
+
*/
|
|
18
31
|
__exportStar(require("./model.js"), exports);
|
|
19
32
|
__exportStar(require("./tools.js"), exports);
|
|
20
33
|
__exportStar(require("./invocation.js"), exports);
|
|
@@ -1,31 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeInvocation = executeInvocation;
|
|
4
|
+
/**
|
|
5
|
+
* Execution of one host-selected synchronous invocation.
|
|
6
|
+
*
|
|
7
|
+
* An invocation is the smallest Core-owned unit of work: the App decides which handler to
|
|
8
|
+
* call and supplies payload and authorization facts, while this module runs the handler once,
|
|
9
|
+
* threads cancellation and diagnostics, and pairs an optional journal start with a receipt.
|
|
10
|
+
* Selection, authorization and retries stay outside.
|
|
11
|
+
*
|
|
12
|
+
* Exports: `executeInvocation` and the invocation contracts re-exported at the bottom.
|
|
13
|
+
*/
|
|
4
14
|
const invocation_js_1 = require("../utils/invocation.js");
|
|
5
15
|
const synchronous_js_1 = require("../utils/synchronous.js");
|
|
6
16
|
const index_js_1 = require("../diagnostics/index.js");
|
|
7
17
|
const reporting_js_1 = require("../execution/reporting.js");
|
|
8
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Run one synchronous invocation and record its effects.
|
|
20
|
+
*
|
|
21
|
+
* @param invocation Handler whose `call` performs the work; its `id` becomes the tool id in
|
|
22
|
+
* diagnostics and journal records.
|
|
23
|
+
* @param input Payload handed to the handler unchanged.
|
|
24
|
+
* @param context App context passed to the ports below; it is never inspected here.
|
|
25
|
+
* @param ports Per-context callbacks for diagnostics, cancellation, journalling and receipt
|
|
26
|
+
* capture. All are optional: without them the handler still runs, just unrecorded.
|
|
27
|
+
* @returns Nothing. The outcome is conveyed through the journal receipt, when one is bound.
|
|
28
|
+
* @throws TypeError when the handler identity is missing, or when the handler returns a
|
|
29
|
+
* promise despite the synchronous contract.
|
|
30
|
+
* @throws Whatever the handler throws, unchanged, including the abort error raised by the
|
|
31
|
+
* signal checks.
|
|
32
|
+
*/
|
|
9
33
|
function executeInvocation(invocation, input, context, ports = {}) {
|
|
10
34
|
const toolId = invocation.id;
|
|
35
|
+
// Identify the call before touching the ports: journal and diagnostics records cannot be
|
|
36
|
+
// reconciled with an anonymous handler.
|
|
11
37
|
if (!toolId?.trim())
|
|
12
38
|
throw new TypeError('Invalid invocation handler identity');
|
|
13
39
|
const journal = ports.journal?.(context), id = (0, invocation_js_1.invocationId)(), startedAtMs = Date.now();
|
|
14
|
-
const diagnostics = ports.diagnostics?.(context)?.child(id, {
|
|
15
|
-
|
|
16
|
-
|
|
40
|
+
const diagnostics = ports.diagnostics?.(context)?.child(id, {
|
|
41
|
+
invocationId: id,
|
|
42
|
+
nodeRole: 'invocation',
|
|
43
|
+
definitionKind: 'tool-invocation',
|
|
44
|
+
definitionId: toolId,
|
|
45
|
+
nodeId: toolId,
|
|
46
|
+
nodeName: toolId,
|
|
47
|
+
nodeKind: 'tool-invocation',
|
|
48
|
+
});
|
|
49
|
+
const callId = journal?.beginTool({
|
|
50
|
+
toolId,
|
|
51
|
+
input,
|
|
52
|
+
invocation: { ...diagnostics?.identity, invocationId: id, startedAtMs },
|
|
53
|
+
});
|
|
54
|
+
diagnostics?.emit('tool.call', () => ({
|
|
55
|
+
toolId,
|
|
56
|
+
invocationId: id,
|
|
57
|
+
...(diagnostics?.enabled('tool.call', 'content') ? { input } : {}),
|
|
58
|
+
}));
|
|
59
|
+
// Held outside the try block so the failure path can still tell cancellation from an error.
|
|
17
60
|
let activeSignal;
|
|
18
61
|
let reports;
|
|
19
62
|
try {
|
|
20
63
|
const checkpoint = ports.checkpoint?.(context);
|
|
21
|
-
const signal = activeSignal = ports.signal?.(context);
|
|
64
|
+
const signal = (activeSignal = ports.signal?.(context));
|
|
22
65
|
signal?.throwIfAborted();
|
|
23
66
|
reports = new reporting_js_1.NodeReports(diagnostics, signal, 'tool.result');
|
|
24
|
-
|
|
25
|
-
|
|
67
|
+
// The helper rejects a promise and drains its rejection: a handler that turns async must
|
|
68
|
+
// fail here instead of escaping as an unhandled rejection.
|
|
69
|
+
(0, synchronous_js_1.synchronous)(invocation.call(input, context, {
|
|
70
|
+
mode: 'sync',
|
|
71
|
+
invocationId: id,
|
|
72
|
+
signal: signal ?? new AbortController().signal,
|
|
73
|
+
diagnostics,
|
|
74
|
+
report: reports.report.bind(reports),
|
|
75
|
+
createSubFlowLogger: reports.createSubFlowLogger.bind(reports),
|
|
76
|
+
}), 'Invocation handlers must be synchronous');
|
|
26
77
|
ports.signal?.(context)?.throwIfAborted();
|
|
27
78
|
if (callId) {
|
|
28
79
|
const receipt = ports.receipt?.(context, checkpoint);
|
|
80
|
+
// Cancellation may have arrived while the handler or receipt ran; a successful record
|
|
81
|
+
// must not be committed for a request the host has already abandoned.
|
|
29
82
|
ports.signal?.(context)?.throwIfAborted();
|
|
30
83
|
journal.finishTool({ invocationId: callId, status: 'success', value: receipt });
|
|
31
84
|
}
|
|
@@ -34,15 +87,32 @@ function executeInvocation(invocation, input, context, ports = {}) {
|
|
|
34
87
|
}
|
|
35
88
|
catch (error) {
|
|
36
89
|
reports?.close();
|
|
37
|
-
diagnostics?.emit('tool.result', () => ({
|
|
90
|
+
diagnostics?.emit('tool.result', () => ({
|
|
91
|
+
toolId,
|
|
92
|
+
invocationId: id,
|
|
93
|
+
status: activeSignal?.aborted ? 'cancelled' : 'error',
|
|
94
|
+
durationMs: Date.now() - startedAtMs,
|
|
95
|
+
...(diagnostics?.enabled('tool.result', 'content')
|
|
96
|
+
? { error: (0, index_js_1.diagnosticError)(error) }
|
|
97
|
+
: {}),
|
|
98
|
+
}), reports?.debug());
|
|
38
99
|
try {
|
|
39
100
|
if (callId)
|
|
40
|
-
journal.finishTool({
|
|
101
|
+
journal.finishTool({
|
|
102
|
+
invocationId: callId,
|
|
103
|
+
// The signal, not the error shape, decides whether this counts as cancellation.
|
|
104
|
+
status: ports.signal?.(context)?.aborted ? 'cancelled' : 'error',
|
|
105
|
+
value: ports.receiptError?.(error),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
/* Preserve the invocation failure if receipt recording also fails. */
|
|
41
110
|
}
|
|
42
|
-
catch { /* Preserve the invocation failure if receipt recording also fails. */ }
|
|
43
111
|
throw error;
|
|
44
112
|
}
|
|
45
113
|
finally {
|
|
114
|
+
// Closing is idempotent, so a port that throws on the success path still releases the
|
|
115
|
+
// reporting scope.
|
|
46
116
|
reports?.close();
|
|
47
117
|
}
|
|
48
118
|
}
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ModelCapabilityRegistry = exports.modelProtocolError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Declarative catalog of model capabilities for a request or one stage projection.
|
|
6
|
+
*
|
|
7
|
+
* A capability pairs an id and description with an input schema and a synchronous resolver,
|
|
8
|
+
* letting stage code parse model-supplied arguments and produce a typed value. Registration
|
|
9
|
+
* snapshots the schema and pins the parser and resolver to their defining object, so later
|
|
10
|
+
* mutation on the host side cannot change what a stage advertises.
|
|
11
|
+
*
|
|
12
|
+
* The registry is mutable until `seal()`. `select()` derives a sealed subset for a stage and
|
|
13
|
+
* shares the already-frozen entries rather than re-validating or re-wrapping them.
|
|
14
|
+
*
|
|
15
|
+
* Exports: `ModelCapabilityRegistry`, `modelProtocolError`, and the capability types.
|
|
16
|
+
*/
|
|
4
17
|
const synchronous_js_1 = require("../utils/synchronous.js");
|
|
5
18
|
const model_protocol_js_1 = require("../utils/model-protocol.js");
|
|
6
19
|
const schema_adapter_js_1 = require("../utils/schema-adapter.js");
|
|
@@ -8,40 +21,127 @@ var model_protocol_js_2 = require("../utils/model-protocol.js");
|
|
|
8
21
|
Object.defineProperty(exports, "modelProtocolError", { enumerable: true, get: function () { return model_protocol_js_2.modelProtocolError; } });
|
|
9
22
|
/** A request/stage projection is a sealed registry. Hosts filter availability before projection. */
|
|
10
23
|
class ModelCapabilityRegistry {
|
|
24
|
+
/** Insertion-ordered entries; iteration order is the declaration order of the catalog. */
|
|
11
25
|
definitionsById = new Map();
|
|
26
|
+
/** Sealing is one-way: stage-time code must never extend the catalog it is executing. */
|
|
12
27
|
sealed = false;
|
|
28
|
+
/**
|
|
29
|
+
* @param definitions Capabilities to register immediately, in iteration order.
|
|
30
|
+
* @throws TypeError when a definition is invalid or its id is duplicated (raised by
|
|
31
|
+
* `register`).
|
|
32
|
+
*/
|
|
13
33
|
constructor(definitions = []) {
|
|
14
34
|
for (const definition of definitions)
|
|
15
35
|
this.register(definition);
|
|
16
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Register one capability.
|
|
39
|
+
*
|
|
40
|
+
* @param capability Declaration with a non-empty unique id, non-empty description, an
|
|
41
|
+
* object-rooted JSON schema and a resolver.
|
|
42
|
+
* @returns This registry, for chaining.
|
|
43
|
+
* @throws Error when the registry is already sealed.
|
|
44
|
+
* @throws TypeError when the declaration is invalid or its id is already registered.
|
|
45
|
+
*/
|
|
17
46
|
register(capability) {
|
|
18
47
|
if (this.sealed)
|
|
19
48
|
throw new Error('Model capability registry is sealed');
|
|
49
|
+
// Model arguments are always a JSON object, so a non-object root can never validate.
|
|
20
50
|
const schema = capability.inputSchema?.jsonSchema;
|
|
21
|
-
if (!capability.id?.trim() ||
|
|
22
|
-
|
|
51
|
+
if (!capability.id?.trim() ||
|
|
52
|
+
!capability.description?.trim() ||
|
|
53
|
+
schema?.type !== 'object' ||
|
|
54
|
+
typeof capability.resolve !== 'function' ||
|
|
55
|
+
this.definitionsById.has(capability.id))
|
|
23
56
|
throw new TypeError('Invalid or duplicate model capability');
|
|
57
|
+
// Clone and freeze the schema, and pin `parse`, so the stored entry is independent of
|
|
58
|
+
// the definition object the host may keep mutating.
|
|
24
59
|
const inputSchema = (0, schema_adapter_js_1.snapshotSchemaAdapter)(capability.inputSchema, 'Model input parsers must be synchronous');
|
|
25
60
|
const resolver = capability.resolve.bind(capability);
|
|
61
|
+
// Bind once here: a later caller cannot substitute its own receiver for the resolver.
|
|
26
62
|
const resolve = (value, context) => (0, synchronous_js_1.synchronous)(resolver(value, context), 'Model capability resolvers must be synchronous');
|
|
27
|
-
this.definitionsById.set(capability.id, Object.freeze({
|
|
63
|
+
this.definitionsById.set(capability.id, Object.freeze({
|
|
64
|
+
id: capability.id,
|
|
65
|
+
description: capability.description,
|
|
66
|
+
inputSchema,
|
|
67
|
+
resolve,
|
|
68
|
+
}));
|
|
28
69
|
return this;
|
|
29
70
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
71
|
+
/** Frozen snapshot of the registered definitions, in insertion order. */
|
|
72
|
+
get definitions() {
|
|
73
|
+
return Object.freeze([...this.definitionsById.values()]);
|
|
74
|
+
}
|
|
75
|
+
/** Registered ids in declaration order. */
|
|
76
|
+
ids() {
|
|
77
|
+
return Object.freeze([...this.definitionsById.keys()]);
|
|
78
|
+
}
|
|
79
|
+
/** Live iterator over `[id, definition]` pairs; it reflects only entries added before sealing. */
|
|
80
|
+
entries() {
|
|
81
|
+
return this.definitionsById.entries();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Register several capabilities.
|
|
85
|
+
*
|
|
86
|
+
* @param definitions Declarations applied in iteration order.
|
|
87
|
+
* @returns This registry, for chaining.
|
|
88
|
+
* @throws Error or TypeError under the same conditions as `register`.
|
|
89
|
+
*/
|
|
90
|
+
registerAll(definitions) {
|
|
91
|
+
for (const definition of definitions)
|
|
92
|
+
this.register(definition);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @param id Capability id.
|
|
97
|
+
* @returns The registered definition.
|
|
98
|
+
* @throws TypeError when the id is not registered, which usually means a stage projection
|
|
99
|
+
* omitted it.
|
|
100
|
+
*/
|
|
35
101
|
require(id) {
|
|
36
102
|
const capability = this.get(id);
|
|
37
103
|
if (!capability)
|
|
38
104
|
throw new TypeError(`Unknown model capability: ${id}`);
|
|
39
105
|
return capability;
|
|
40
106
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
107
|
+
/**
|
|
108
|
+
* @param id Capability id.
|
|
109
|
+
* @returns Whether the id is registered in this registry.
|
|
110
|
+
*/
|
|
111
|
+
has(id) {
|
|
112
|
+
return this.definitionsById.has(id);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @param id Capability id.
|
|
116
|
+
* @returns The registered definition, or undefined when absent.
|
|
117
|
+
*/
|
|
118
|
+
get(id) {
|
|
119
|
+
return this.definitionsById.get(id);
|
|
120
|
+
}
|
|
121
|
+
/** Live iterator over the registered definitions. */
|
|
122
|
+
values() {
|
|
123
|
+
return this.definitionsById.values();
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Close the registry to further registration.
|
|
127
|
+
*
|
|
128
|
+
* Sealing is idempotent and does not affect existing entries.
|
|
129
|
+
*
|
|
130
|
+
* @returns This registry.
|
|
131
|
+
*/
|
|
132
|
+
seal() {
|
|
133
|
+
this.sealed = true;
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Derive a sealed sub-catalog for one stage.
|
|
138
|
+
*
|
|
139
|
+
* @param ids Capability ids available in the stage, in projection order. Must be non-empty
|
|
140
|
+
* and free of duplicates.
|
|
141
|
+
* @returns A new sealed registry that reuses the immutable entries of this registry.
|
|
142
|
+
* @throws TypeError when the selection is empty or contains a duplicate id.
|
|
143
|
+
* @throws Error when an id was never registered.
|
|
144
|
+
*/
|
|
45
145
|
select(ids) {
|
|
46
146
|
if (!ids.length || new Set(ids).size !== ids.length)
|
|
47
147
|
throw new TypeError('Invalid capability selection');
|
|
@@ -57,9 +157,22 @@ class ModelCapabilityRegistry {
|
|
|
57
157
|
}
|
|
58
158
|
return selected.seal();
|
|
59
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Parse model-supplied arguments and run the selected capability.
|
|
162
|
+
*
|
|
163
|
+
* @param selection Capability id plus the raw `input` object produced by the model. Other
|
|
164
|
+
* fields, such as the originating call, are not interpreted here.
|
|
165
|
+
* @param context Stage identity handed to the resolver.
|
|
166
|
+
* @returns The resolver output.
|
|
167
|
+
* @throws ValidationError when the capability is unavailable in this registry or the input
|
|
168
|
+
* is not a plain object; parser and resolver failures propagate unchanged.
|
|
169
|
+
*/
|
|
60
170
|
resolve(selection, context) {
|
|
61
171
|
const { stageId } = context;
|
|
62
|
-
|
|
172
|
+
// Model output is untrusted: unknown ids and non-object arguments are protocol failures,
|
|
173
|
+
// not ordinary `undefined` results.
|
|
174
|
+
const capability = this.definitionsById.get(selection.capabilityId) ??
|
|
175
|
+
(0, model_protocol_js_1.modelProtocolError)('Model capability is unavailable in this stage');
|
|
63
176
|
if (!selection.input || typeof selection.input !== 'object' || Array.isArray(selection.input))
|
|
64
177
|
(0, model_protocol_js_1.modelProtocolError)('Model capability input must be an object');
|
|
65
178
|
return (0, synchronous_js_1.synchronous)(capability.resolve(capability.inputSchema.parse(selection.input), { stageId }), 'Model capability parsers must be synchronous');
|