@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,11 +1,41 @@
|
|
|
1
1
|
import type { SchemaAdapter, JsonSchema } from '../structs/common.js';
|
|
2
2
|
import type { JsonSchemaOptions } from '../structs/support/schema.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Build an adapter from a caller-owned typed JSON Schema compiler.
|
|
5
|
+
*
|
|
6
|
+
* The schema is cloned and frozen before it reaches the compiler, so later mutation of the input
|
|
7
|
+
* cannot change validation. Compilation and validation must both be synchronous.
|
|
8
|
+
*
|
|
9
|
+
* @param schema JSON Schema describing the accepted value.
|
|
10
|
+
* @param options Compiler plus an optional error factory for rejected values.
|
|
11
|
+
* @returns A frozen adapter exposing `jsonSchema` and a `parse` that returns the input as `Value`.
|
|
12
|
+
* @throws {TypeError} When the compiler is asynchronous or does not return a validator, or when no
|
|
13
|
+
* custom error applies; also when the validator is asynchronous or does not return a boolean.
|
|
14
|
+
*/
|
|
4
15
|
export declare function fromJsonSchema<Value = unknown>(schema: JsonSchema, options: JsonSchemaOptions<Value>): SchemaAdapter<Value>;
|
|
16
|
+
/**
|
|
17
|
+
* Wrap a library schema that already parses values (for example Zod or Valibot style).
|
|
18
|
+
*
|
|
19
|
+
* `parse` is delegated unchanged, so the library keeps ownership of coercion and error reporting;
|
|
20
|
+
* only the JSON Schema projection is produced here.
|
|
21
|
+
*
|
|
22
|
+
* @param schema Object exposing a `parse` method.
|
|
23
|
+
* @param options Converter that projects the schema into JSON Schema.
|
|
24
|
+
* @returns A frozen adapter whose `parse` returns the wrapped parser's result type.
|
|
25
|
+
* @throws {TypeError} When the JSON Schema conversion is asynchronous.
|
|
26
|
+
*/
|
|
5
27
|
export declare function fromParserSchema<Schema extends {
|
|
6
28
|
parse(value: unknown): unknown;
|
|
7
29
|
}>(schema: Schema, options: {
|
|
8
30
|
toJsonSchema(schema: Schema): JsonSchema;
|
|
9
31
|
}): SchemaAdapter<ReturnType<Schema['parse']>>;
|
|
32
|
+
/**
|
|
33
|
+
* Re-snapshot an existing adapter without changing its behavior.
|
|
34
|
+
*
|
|
35
|
+
* Used to detach a caller-owned adapter from later mutation before it is exposed or reused.
|
|
36
|
+
*
|
|
37
|
+
* @param definition Adapter to copy.
|
|
38
|
+
* @returns A frozen adapter with the same validation and parsing behavior.
|
|
39
|
+
*/
|
|
10
40
|
export declare function defineSchema<Value>(definition: SchemaAdapter<Value>): SchemaAdapter<Value>;
|
|
11
41
|
export type * from '../structs/support/schema.js';
|
|
@@ -1,7 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema adapter helpers: turn JSON Schema compilers and library parsers into Core adapters.
|
|
3
|
+
*
|
|
4
|
+
* Support supplies the adapter shape and snapshotting; the compiler, validator package and error
|
|
5
|
+
* messages remain application choices. A plain JSON Schema without a typed compiler stays unknown
|
|
6
|
+
* instead of being silently treated as permissive.
|
|
7
|
+
*
|
|
8
|
+
* Main exports: `fromJsonSchema`, `fromParserSchema` and `defineSchema`.
|
|
9
|
+
*/
|
|
1
10
|
import { snapshotSchemaAdapter } from '../utils/schema-adapter.js';
|
|
2
11
|
import { freezeSchema } from '../utils/object.js';
|
|
3
12
|
import { booleanResult, synchronous } from '../utils/synchronous.js';
|
|
4
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Build an adapter from a caller-owned typed JSON Schema compiler.
|
|
15
|
+
*
|
|
16
|
+
* The schema is cloned and frozen before it reaches the compiler, so later mutation of the input
|
|
17
|
+
* cannot change validation. Compilation and validation must both be synchronous.
|
|
18
|
+
*
|
|
19
|
+
* @param schema JSON Schema describing the accepted value.
|
|
20
|
+
* @param options Compiler plus an optional error factory for rejected values.
|
|
21
|
+
* @returns A frozen adapter exposing `jsonSchema` and a `parse` that returns the input as `Value`.
|
|
22
|
+
* @throws {TypeError} When the compiler is asynchronous or does not return a validator, or when no
|
|
23
|
+
* custom error applies; also when the validator is asynchronous or does not return a boolean.
|
|
24
|
+
*/
|
|
5
25
|
export function fromJsonSchema(schema, options) {
|
|
6
26
|
const jsonSchema = structuredClone(schema);
|
|
7
27
|
freezeSchema(jsonSchema);
|
|
@@ -9,19 +29,41 @@ export function fromJsonSchema(schema, options) {
|
|
|
9
29
|
if (typeof validate !== 'function')
|
|
10
30
|
throw new TypeError('Schema compilers must return a validator');
|
|
11
31
|
const error = options.error?.bind(options);
|
|
12
|
-
return snapshotSchemaAdapter({
|
|
32
|
+
return snapshotSchemaAdapter({
|
|
33
|
+
jsonSchema,
|
|
34
|
+
parse(value) {
|
|
13
35
|
const valid = booleanResult(validate(value), 'Schema validators must be synchronous', 'Schema validators must return boolean');
|
|
14
36
|
if (!valid)
|
|
15
|
-
throw synchronous(error?.(value, validate.errors), 'Schema error factories must be synchronous') ?? new TypeError('Input does not match JSON Schema');
|
|
37
|
+
throw (synchronous(error?.(value, validate.errors), 'Schema error factories must be synchronous') ?? new TypeError('Input does not match JSON Schema'));
|
|
16
38
|
return value;
|
|
17
|
-
}
|
|
39
|
+
},
|
|
40
|
+
});
|
|
18
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Wrap a library schema that already parses values (for example Zod or Valibot style).
|
|
44
|
+
*
|
|
45
|
+
* `parse` is delegated unchanged, so the library keeps ownership of coercion and error reporting;
|
|
46
|
+
* only the JSON Schema projection is produced here.
|
|
47
|
+
*
|
|
48
|
+
* @param schema Object exposing a `parse` method.
|
|
49
|
+
* @param options Converter that projects the schema into JSON Schema.
|
|
50
|
+
* @returns A frozen adapter whose `parse` returns the wrapped parser's result type.
|
|
51
|
+
* @throws {TypeError} When the JSON Schema conversion is asynchronous.
|
|
52
|
+
*/
|
|
19
53
|
export function fromParserSchema(schema, options) {
|
|
20
54
|
return snapshotSchemaAdapter({
|
|
21
55
|
jsonSchema: synchronous(options.toJsonSchema(schema), 'Schema conversion must be synchronous'),
|
|
22
56
|
parse: schema.parse.bind(schema),
|
|
23
57
|
});
|
|
24
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Re-snapshot an existing adapter without changing its behavior.
|
|
61
|
+
*
|
|
62
|
+
* Used to detach a caller-owned adapter from later mutation before it is exposed or reused.
|
|
63
|
+
*
|
|
64
|
+
* @param definition Adapter to copy.
|
|
65
|
+
* @returns A frozen adapter with the same validation and parsing behavior.
|
|
66
|
+
*/
|
|
25
67
|
export function defineSchema(definition) {
|
|
26
68
|
return snapshotSchemaAdapter(definition);
|
|
27
69
|
}
|
|
@@ -1,2 +1,23 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Bounded event plumbing for applications that must forward streamed output under cancellation.
|
|
3
|
+
*
|
|
4
|
+
* A producer pushes events one at a time and waits for each to be consumed; the consumer pulls
|
|
5
|
+
* from an async iterable. There is no unbounded queue, so a slow consumer slows the producer
|
|
6
|
+
* instead of growing memory, and aborting the signal closes both sides.
|
|
7
|
+
*
|
|
8
|
+
* Main export: `streamEvents`.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Bridge a push-style producer to a pull-style async iterable with a one-slot rendezvous.
|
|
12
|
+
*
|
|
13
|
+
* The producer must await every `emit` call before emitting again; concurrent emissions are
|
|
14
|
+
* rejected rather than buffered. The slot is released only after the consumer receives the event,
|
|
15
|
+
* so backpressure is exact.
|
|
16
|
+
*
|
|
17
|
+
* @param operation Producer that receives an `emit` callback and runs to completion.
|
|
18
|
+
* @param context Execution context carrying the abort signal used to close the rendezvous.
|
|
19
|
+
* @returns An async iterable yielding each event in production order.
|
|
20
|
+
* @throws The producer's error, or the signal's abort reason when cancelled. Also rejects an
|
|
21
|
+
* `emit` that overlaps another, occurs after close, or is never consumed by the consumer.
|
|
22
|
+
*/
|
|
2
23
|
export declare function streamEvents<Event>(operation: (emit: (event: Event) => Promise<void>) => Promise<void>, { signal }: import('../structs/common.js').ExecutionContext): AsyncIterable<Event>;
|
|
@@ -1,4 +1,25 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Bounded event plumbing for applications that must forward streamed output under cancellation.
|
|
3
|
+
*
|
|
4
|
+
* A producer pushes events one at a time and waits for each to be consumed; the consumer pulls
|
|
5
|
+
* from an async iterable. There is no unbounded queue, so a slow consumer slows the producer
|
|
6
|
+
* instead of growing memory, and aborting the signal closes both sides.
|
|
7
|
+
*
|
|
8
|
+
* Main export: `streamEvents`.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Bridge a push-style producer to a pull-style async iterable with a one-slot rendezvous.
|
|
12
|
+
*
|
|
13
|
+
* The producer must await every `emit` call before emitting again; concurrent emissions are
|
|
14
|
+
* rejected rather than buffered. The slot is released only after the consumer receives the event,
|
|
15
|
+
* so backpressure is exact.
|
|
16
|
+
*
|
|
17
|
+
* @param operation Producer that receives an `emit` callback and runs to completion.
|
|
18
|
+
* @param context Execution context carrying the abort signal used to close the rendezvous.
|
|
19
|
+
* @returns An async iterable yielding each event in production order.
|
|
20
|
+
* @throws The producer's error, or the signal's abort reason when cancelled. Also rejects an
|
|
21
|
+
* `emit` that overlaps another, occurs after close, or is never consumed by the consumer.
|
|
22
|
+
*/
|
|
2
23
|
export async function* streamEvents(operation, { signal }) {
|
|
3
24
|
let slot;
|
|
4
25
|
let wake;
|
|
@@ -6,24 +27,53 @@ export async function* streamEvents(operation, { signal }) {
|
|
|
6
27
|
let sending = false;
|
|
7
28
|
let failure;
|
|
8
29
|
let rejectSend;
|
|
9
|
-
const notify = () => {
|
|
10
|
-
|
|
30
|
+
const notify = () => {
|
|
31
|
+
wake?.();
|
|
32
|
+
wake = undefined;
|
|
33
|
+
};
|
|
34
|
+
const abort = () => {
|
|
35
|
+
closed = true;
|
|
36
|
+
rejectSend?.(signal.reason ?? new Error('Stream closed'));
|
|
37
|
+
notify();
|
|
38
|
+
};
|
|
11
39
|
signal.addEventListener('abort', abort, { once: true });
|
|
12
40
|
if (signal.aborted)
|
|
13
41
|
abort();
|
|
14
|
-
const producer = Promise.resolve()
|
|
42
|
+
const producer = Promise.resolve()
|
|
43
|
+
.then(() => {
|
|
15
44
|
signal.throwIfAborted();
|
|
16
45
|
// Before the producer starts, only abort can close this rendezvous; the
|
|
17
46
|
// signal check above already rejects it with the original reason.
|
|
18
|
-
return operation(event => {
|
|
47
|
+
return operation((event) => {
|
|
19
48
|
if (closed || signal.aborted)
|
|
20
49
|
return Promise.reject(signal.reason ?? new Error('Stream closed'));
|
|
21
50
|
if (sending)
|
|
22
51
|
return Promise.reject(new Error('Event producers must await delivery'));
|
|
23
52
|
sending = true;
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
rejectSend = reject;
|
|
55
|
+
slot = {
|
|
56
|
+
event,
|
|
57
|
+
release: () => {
|
|
58
|
+
sending = false;
|
|
59
|
+
resolve();
|
|
60
|
+
},
|
|
61
|
+
cancel: () => {
|
|
62
|
+
sending = false;
|
|
63
|
+
reject(new Error('Stream closed before event consumption'));
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
notify();
|
|
67
|
+
});
|
|
25
68
|
});
|
|
26
|
-
})
|
|
69
|
+
})
|
|
70
|
+
.catch((error) => {
|
|
71
|
+
failure = { error };
|
|
72
|
+
})
|
|
73
|
+
.finally(() => {
|
|
74
|
+
done = true;
|
|
75
|
+
notify();
|
|
76
|
+
});
|
|
27
77
|
try {
|
|
28
78
|
while (true) {
|
|
29
79
|
signal.throwIfAborted();
|
|
@@ -48,7 +98,9 @@ export async function* streamEvents(operation, { signal }) {
|
|
|
48
98
|
return;
|
|
49
99
|
}
|
|
50
100
|
else
|
|
51
|
-
await new Promise(resolve => {
|
|
101
|
+
await new Promise((resolve) => {
|
|
102
|
+
wake = resolve;
|
|
103
|
+
});
|
|
52
104
|
}
|
|
53
105
|
}
|
|
54
106
|
finally {
|
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export barrel: exposes the Core tool registry factory to Support consumers.
|
|
3
|
+
*
|
|
4
|
+
* Core owns the registry implementation; Support only re-exports it so applications can bind a
|
|
5
|
+
* `ToolCatalog` without importing internal paths. No behavior is added here.
|
|
6
|
+
*/
|
|
1
7
|
export { createToolRegistry } from '../capabilities/tool-runtime.js';
|
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export barrel: exposes the Core tool registry factory to Support consumers.
|
|
3
|
+
*
|
|
4
|
+
* Core owns the registry implementation; Support only re-exports it so applications can bind a
|
|
5
|
+
* `ToolCatalog` without importing internal paths. No behavior is added here.
|
|
6
|
+
*/
|
|
1
7
|
export { createToolRegistry } from '../capabilities/tool-runtime.js';
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import type { ToolDefinition, ToolCatalog, CompiledTool } from '../structs/support/tools.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validate one tool declaration and freeze a detached copy of it.
|
|
4
|
+
*
|
|
5
|
+
* `authorize` must settle with `void`; a rejection has to be thrown, so a returned `false` cannot
|
|
6
|
+
* silently pass. Handlers are bound to the declaration object, and the input schema is
|
|
7
|
+
* re-snapshotted so later mutation cannot widen the accepted input.
|
|
8
|
+
*
|
|
9
|
+
* @param definition Tool declaration whose `id` is preserved as a literal type.
|
|
10
|
+
* @returns A frozen tool definition with a snapshotted `inputSchema`.
|
|
11
|
+
* @throws {TypeError} When `id`, `kind` or `description` is blank, when a handler is missing, or
|
|
12
|
+
* when `authorize` returns a value instead of throwing.
|
|
13
|
+
*/
|
|
2
14
|
export declare function defineTool<Input, Output, App, const Id extends string = string>(definition: ToolDefinition<Input, Output, App> & {
|
|
3
15
|
readonly id: Id;
|
|
4
16
|
}): ToolDefinition<Input, Output, App, Id>;
|
|
17
|
+
/**
|
|
18
|
+
* Compile tool declarations into a frozen catalog with model capabilities and runtime binding.
|
|
19
|
+
*
|
|
20
|
+
* Each tool becomes a model capability whose resolver returns `{ toolId, input }`; the model only
|
|
21
|
+
* chooses among registered tools, it never invokes them directly.
|
|
22
|
+
*
|
|
23
|
+
* @param definitions Tool declarations in catalog order.
|
|
24
|
+
* @returns A frozen catalog with `capabilities`, `select` and `bind`.
|
|
25
|
+
* @throws {TypeError} When a tool declaration is invalid or a tool ID is duplicated.
|
|
26
|
+
*/
|
|
5
27
|
export declare function defineToolCatalog<App, const Definitions extends readonly ToolDefinition<any, any, App>[] = readonly ToolDefinition<any, any, App>[]>(definitions: Definitions): ToolCatalog<App, CompiledTool<App, Definitions[number]>>;
|
|
6
28
|
export type * from '../structs/support/tools.js';
|
|
@@ -1,39 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool support: turn typed application tool definitions into a Core-schedulable tool catalog.
|
|
3
|
+
*
|
|
4
|
+
* A tool declaration pairs an input schema with authorization, execution and output parsing. The
|
|
5
|
+
* catalog projects those tools into model capabilities and binds them to the Core tool registry
|
|
6
|
+
* when a runtime request supplies the application. Support only assembles the registration; Core
|
|
7
|
+
* still performs authorization, invocation, budgets and cancellation.
|
|
8
|
+
*
|
|
9
|
+
* Main exports: `defineTool` and `defineToolCatalog`.
|
|
10
|
+
*/
|
|
1
11
|
import { ModelCapabilityRegistry } from '../capabilities/model.js';
|
|
2
12
|
import { createToolRegistry } from './tool-runtime.js';
|
|
3
13
|
import { defineSchema } from './schema.js';
|
|
4
14
|
import { readonlyCatalog } from '../utils/catalog.js';
|
|
5
15
|
import { maybeAssertion } from '../utils/synchronous.js';
|
|
16
|
+
/**
|
|
17
|
+
* Validate one tool declaration and freeze a detached copy of it.
|
|
18
|
+
*
|
|
19
|
+
* `authorize` must settle with `void`; a rejection has to be thrown, so a returned `false` cannot
|
|
20
|
+
* silently pass. Handlers are bound to the declaration object, and the input schema is
|
|
21
|
+
* re-snapshotted so later mutation cannot widen the accepted input.
|
|
22
|
+
*
|
|
23
|
+
* @param definition Tool declaration whose `id` is preserved as a literal type.
|
|
24
|
+
* @returns A frozen tool definition with a snapshotted `inputSchema`.
|
|
25
|
+
* @throws {TypeError} When `id`, `kind` or `description` is blank, when a handler is missing, or
|
|
26
|
+
* when `authorize` returns a value instead of throwing.
|
|
27
|
+
*/
|
|
6
28
|
export function defineTool(definition) {
|
|
7
29
|
const { id, kind, description } = definition;
|
|
8
30
|
if (!id?.trim() || !kind?.trim() || !description?.trim())
|
|
9
31
|
throw new TypeError('Invalid tool identity');
|
|
10
|
-
if (typeof definition.authorize !== 'function' ||
|
|
32
|
+
if (typeof definition.authorize !== 'function' ||
|
|
33
|
+
typeof definition.execute !== 'function' ||
|
|
34
|
+
typeof definition.parseOutput !== 'function')
|
|
11
35
|
throw new TypeError('Missing tool handler');
|
|
12
36
|
const inputSchema = defineSchema(definition.inputSchema);
|
|
13
37
|
const authorize = definition.authorize.bind(definition);
|
|
14
|
-
return Object.freeze({
|
|
38
|
+
return Object.freeze({
|
|
39
|
+
id,
|
|
40
|
+
kind,
|
|
41
|
+
description,
|
|
42
|
+
inputSchema,
|
|
15
43
|
authorize(input, context) {
|
|
16
44
|
return maybeAssertion(authorize(input, context), 'Authorization must return void; rejection must throw');
|
|
17
45
|
},
|
|
18
46
|
execute: definition.execute.bind(definition),
|
|
19
47
|
debugSteps: definition.debugSteps?.bind(definition),
|
|
20
|
-
parseOutput: definition.parseOutput.bind(definition),
|
|
48
|
+
parseOutput: definition.parseOutput.bind(definition),
|
|
49
|
+
});
|
|
21
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Compile tool declarations into a frozen catalog with model capabilities and runtime binding.
|
|
53
|
+
*
|
|
54
|
+
* Each tool becomes a model capability whose resolver returns `{ toolId, input }`; the model only
|
|
55
|
+
* chooses among registered tools, it never invokes them directly.
|
|
56
|
+
*
|
|
57
|
+
* @param definitions Tool declarations in catalog order.
|
|
58
|
+
* @returns A frozen catalog with `capabilities`, `select` and `bind`.
|
|
59
|
+
* @throws {TypeError} When a tool declaration is invalid or a tool ID is duplicated.
|
|
60
|
+
*/
|
|
22
61
|
export function defineToolCatalog(definitions) {
|
|
23
|
-
const entries = definitions.map(definition => defineTool(definition));
|
|
24
|
-
const view = readonlyCatalog(entries, id => new TypeError(`Unknown tool: ${id}`));
|
|
25
|
-
const capabilities = new ModelCapabilityRegistry(entries.map(tool => ({
|
|
62
|
+
const entries = definitions.map((definition) => defineTool(definition));
|
|
63
|
+
const view = readonlyCatalog(entries, (id) => new TypeError(`Unknown tool: ${id}`));
|
|
64
|
+
const capabilities = new ModelCapabilityRegistry(entries.map((tool) => ({
|
|
65
|
+
id: tool.id,
|
|
66
|
+
description: tool.description,
|
|
67
|
+
inputSchema: defineSchema({
|
|
68
|
+
jsonSchema: tool.inputSchema.jsonSchema,
|
|
69
|
+
parse: (input) => input,
|
|
70
|
+
}),
|
|
26
71
|
resolve: (input) => ({ toolId: tool.id, input }),
|
|
27
72
|
}))).seal();
|
|
28
|
-
return Object.freeze({
|
|
29
|
-
|
|
73
|
+
return Object.freeze({
|
|
74
|
+
...view,
|
|
75
|
+
capabilities,
|
|
76
|
+
/**
|
|
77
|
+
* Narrow the catalog to the given tool IDs, preserving their declaration order.
|
|
78
|
+
*
|
|
79
|
+
* @param ids Registered tool IDs to keep.
|
|
80
|
+
* @returns A new catalog containing only the selected tools.
|
|
81
|
+
* @throws {TypeError} When an ID is not registered in this catalog.
|
|
82
|
+
*/
|
|
83
|
+
select(ids) {
|
|
84
|
+
capabilities.select(ids);
|
|
85
|
+
return defineToolCatalog(ids.map((id) => view.require(id)));
|
|
86
|
+
},
|
|
87
|
+
/**
|
|
88
|
+
* Bind the catalog to one application runtime request.
|
|
89
|
+
*
|
|
90
|
+
* @param request Runtime request supplying the app and optional execution/error ports.
|
|
91
|
+
* @returns A frozen runtime whose `invoke`/`invokeSync` delegate to the Core tool registry.
|
|
92
|
+
* @throws {TypeError} When the request does not carry an `app`.
|
|
93
|
+
*/
|
|
30
94
|
bind(request) {
|
|
31
95
|
if (!request || !('app' in request))
|
|
32
96
|
throw new TypeError('A runtime request requires app');
|
|
33
97
|
const registry = createToolRegistry(entries, request.app, {
|
|
34
|
-
execution: request.execution,
|
|
98
|
+
execution: request.execution,
|
|
99
|
+
errors: request.errors,
|
|
35
100
|
});
|
|
36
|
-
return Object.freeze({
|
|
101
|
+
return Object.freeze({
|
|
102
|
+
capabilities,
|
|
103
|
+
get events() {
|
|
104
|
+
return registry.events;
|
|
105
|
+
},
|
|
37
106
|
invokeSync: registry.invoke.bind(registry),
|
|
38
107
|
invoke: registry.invokeAsync.bind(registry),
|
|
39
108
|
});
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport helpers for hosts that own their own HTTP response lifecycle.
|
|
3
|
+
*
|
|
4
|
+
* `./sse.js` covers server-sent events (reading, encoding and cancellable writes) and
|
|
5
|
+
* `./json.js` covers framed JSON scanning. Both are mechanical utilities: the host decides which
|
|
6
|
+
* traffic, frames and content are acceptable.
|
|
7
|
+
*/
|
|
1
8
|
export * from './sse.js';
|
|
2
9
|
export * from './json.js';
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport helpers for hosts that own their own HTTP response lifecycle.
|
|
3
|
+
*
|
|
4
|
+
* `./sse.js` covers server-sent events (reading, encoding and cancellable writes) and
|
|
5
|
+
* `./json.js` covers framed JSON scanning. Both are mechanical utilities: the host decides which
|
|
6
|
+
* traffic, frames and content are acceptable.
|
|
7
|
+
*/
|
|
1
8
|
export * from './sse.js';
|
|
2
9
|
export * from './json.js';
|
|
@@ -1,6 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON transport framing: locate complete JSON objects inside free-form streamed text.
|
|
3
|
+
*
|
|
4
|
+
* Framing is purely mechanical. It never repairs, truncates or interprets fields; consumers decide
|
|
5
|
+
* which surrounding content and which frames they allow. Limits keep malformed or hostile streams
|
|
6
|
+
* from consuming unbounded memory.
|
|
7
|
+
*
|
|
8
|
+
* Main exports: `scanJsonObjectFrames` and `parseJsonFrames`.
|
|
9
|
+
*/
|
|
1
10
|
import type { JsonFrameLimits } from '../../structs/support/transport/json.js';
|
|
2
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Extract complete object-shaped spans from surrounding text, without parsing or selecting them.
|
|
13
|
+
*
|
|
14
|
+
* @param text Streamed text possibly containing JSON objects and unrelated content.
|
|
15
|
+
* @returns Raw object spans in source order.
|
|
16
|
+
* @throws {Error} When the text ends inside an unterminated object or string.
|
|
17
|
+
*/
|
|
3
18
|
export declare function scanJsonObjectFrames(text: string): string[];
|
|
4
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Parse complete object frames under explicit count and size limits.
|
|
21
|
+
*
|
|
22
|
+
* Only whitespace may appear outside frames; a stray closing brace is tolerated only up to
|
|
23
|
+
* `maxExtraClosings`, which covers transports that repeat the delimiter after the payload.
|
|
24
|
+
*
|
|
25
|
+
* @param text Streamed text to scan.
|
|
26
|
+
* @param limits Frame count, size and stray-closer allowances; validated before scanning.
|
|
27
|
+
* @returns Parsed frames in source order.
|
|
28
|
+
* @throws {TypeError} When a limit is not a safe integer or falls outside its allowed range.
|
|
29
|
+
* @throws {Error} When a limit is exceeded, content outside a frame is not whitespace, or the
|
|
30
|
+
* transport ends before at least one complete frame exists.
|
|
31
|
+
*/
|
|
5
32
|
export declare function parseJsonFrames(text: string, limits: JsonFrameLimits): Record<string, unknown>[];
|
|
6
33
|
export type { JsonFrameLimits } from '../../structs/support/transport/json.js';
|
|
@@ -30,7 +30,13 @@ function* scan(text) {
|
|
|
30
30
|
if (depth || quoted)
|
|
31
31
|
throw new Error('Incomplete JSON transport');
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Extract complete object-shaped spans from surrounding text, without parsing or selecting them.
|
|
35
|
+
*
|
|
36
|
+
* @param text Streamed text possibly containing JSON objects and unrelated content.
|
|
37
|
+
* @returns Raw object spans in source order.
|
|
38
|
+
* @throws {Error} When the text ends inside an unterminated object or string.
|
|
39
|
+
*/
|
|
34
40
|
export function scanJsonObjectFrames(text) {
|
|
35
41
|
const frames = [];
|
|
36
42
|
for (const part of scan(text))
|
|
@@ -38,10 +44,26 @@ export function scanJsonObjectFrames(text) {
|
|
|
38
44
|
frames.push(part.text);
|
|
39
45
|
return frames;
|
|
40
46
|
}
|
|
41
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Parse complete object frames under explicit count and size limits.
|
|
49
|
+
*
|
|
50
|
+
* Only whitespace may appear outside frames; a stray closing brace is tolerated only up to
|
|
51
|
+
* `maxExtraClosings`, which covers transports that repeat the delimiter after the payload.
|
|
52
|
+
*
|
|
53
|
+
* @param text Streamed text to scan.
|
|
54
|
+
* @param limits Frame count, size and stray-closer allowances; validated before scanning.
|
|
55
|
+
* @returns Parsed frames in source order.
|
|
56
|
+
* @throws {TypeError} When a limit is not a safe integer or falls outside its allowed range.
|
|
57
|
+
* @throws {Error} When a limit is exceeded, content outside a frame is not whitespace, or the
|
|
58
|
+
* transport ends before at least one complete frame exists.
|
|
59
|
+
*/
|
|
42
60
|
export function parseJsonFrames(text, limits) {
|
|
43
|
-
if (!Number.isSafeInteger(limits.maxFrames) ||
|
|
44
|
-
|
|
61
|
+
if (!Number.isSafeInteger(limits.maxFrames) ||
|
|
62
|
+
limits.maxFrames < 1 ||
|
|
63
|
+
!Number.isSafeInteger(limits.maxExtraClosings) ||
|
|
64
|
+
limits.maxExtraClosings < 0 ||
|
|
65
|
+
(limits.maxFrameChars !== undefined &&
|
|
66
|
+
(!Number.isSafeInteger(limits.maxFrameChars) || limits.maxFrameChars < 1)))
|
|
45
67
|
throw new TypeError('Invalid JSON frame limits');
|
|
46
68
|
const frames = [];
|
|
47
69
|
let extraClosings = 0;
|
|
@@ -49,6 +71,8 @@ export function parseJsonFrames(text, limits) {
|
|
|
49
71
|
if (part.kind === 'frame') {
|
|
50
72
|
if (frames.length >= limits.maxFrames)
|
|
51
73
|
throw new Error('JSON frame limit exceeded');
|
|
74
|
+
if (limits.maxFrameChars !== undefined && part.text.length > limits.maxFrameChars)
|
|
75
|
+
throw new Error('JSON frame size exceeded');
|
|
52
76
|
frames.push(JSON.parse(part.text));
|
|
53
77
|
}
|
|
54
78
|
else if (part.text === '}') {
|
|
@@ -1,10 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-sent event transport: encode frames, write them with backpressure, and re-export readers.
|
|
3
|
+
*
|
|
4
|
+
* The host owns its HTTP response and lifecycle; these helpers only format frames and wait in a
|
|
5
|
+
* cancellable way. Reading is delegated to the shared streaming package so Core and Support use
|
|
6
|
+
* one parser.
|
|
7
|
+
*
|
|
8
|
+
* Main exports: `encodeSseEvent`, `writeSseFrame`, plus `readSse`, `abortableStream` and their
|
|
9
|
+
* types.
|
|
10
|
+
*/
|
|
1
11
|
import type { SseWriter, SseOutputEvent } from '../../structs/support/transport/sse.js';
|
|
2
12
|
/** Public transport facade. Applications depend on core; streaming remains an implementation dependency. */
|
|
3
13
|
export { readSse, SseIdleTimeoutError } from '@jangts/streaming/sse';
|
|
4
14
|
export type { SseEvent, SseReadOptions } from '../../structs/support/transport/sse.js';
|
|
5
15
|
export { abortableStream } from '@jangts/streaming/abortable-stream';
|
|
16
|
+
/**
|
|
17
|
+
* Encode one event in the server-sent events wire format.
|
|
18
|
+
*
|
|
19
|
+
* Every line of `data` gets its own `data:` field, because a raw newline would start a new field.
|
|
20
|
+
*
|
|
21
|
+
* @param event Event name and payload to encode.
|
|
22
|
+
* @returns The complete frame, terminated by a blank line.
|
|
23
|
+
* @throws {TypeError} When the event name contains a newline, which would corrupt the frame.
|
|
24
|
+
*/
|
|
6
25
|
export declare function encodeSseEvent(event: SseOutputEvent): string;
|
|
7
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Write one encoded frame and wait for drain when the writer reports backpressure.
|
|
28
|
+
*
|
|
29
|
+
* The signal is re-checked around the write and the drain wait, so cancellation does not leave a
|
|
30
|
+
* pending write considered successful.
|
|
31
|
+
*
|
|
32
|
+
* @param request Writer plus the already encoded frame.
|
|
33
|
+
* @param context Execution context carrying the abort signal.
|
|
34
|
+
* @returns Resolves once the frame is accepted or the writer drains.
|
|
35
|
+
* @throws The signal's abort reason, or {@link TypeError} when `write` does not return a boolean
|
|
36
|
+
* synchronously.
|
|
37
|
+
*/
|
|
8
38
|
export declare function writeSseFrame({ writer, frame }: {
|
|
9
39
|
writer: SseWriter;
|
|
10
40
|
frame: string;
|
|
@@ -3,12 +3,35 @@ import { booleanResult } from '../../utils/synchronous.js';
|
|
|
3
3
|
/** Public transport facade. Applications depend on core; streaming remains an implementation dependency. */
|
|
4
4
|
export { readSse, SseIdleTimeoutError } from '@jangts/streaming/sse';
|
|
5
5
|
export { abortableStream } from '@jangts/streaming/abortable-stream';
|
|
6
|
+
/**
|
|
7
|
+
* Encode one event in the server-sent events wire format.
|
|
8
|
+
*
|
|
9
|
+
* Every line of `data` gets its own `data:` field, because a raw newline would start a new field.
|
|
10
|
+
*
|
|
11
|
+
* @param event Event name and payload to encode.
|
|
12
|
+
* @returns The complete frame, terminated by a blank line.
|
|
13
|
+
* @throws {TypeError} When the event name contains a newline, which would corrupt the frame.
|
|
14
|
+
*/
|
|
6
15
|
export function encodeSseEvent(event) {
|
|
7
16
|
if (/[\r\n]/.test(event.event))
|
|
8
17
|
throw new TypeError('SSE event name cannot contain a newline');
|
|
9
|
-
return `event: ${event.event}\n${event.data
|
|
18
|
+
return `event: ${event.event}\n${event.data
|
|
19
|
+
.split(/\r\n|\r|\n/)
|
|
20
|
+
.map((line) => `data: ${line}\n`)
|
|
21
|
+
.join('')}\n`;
|
|
10
22
|
}
|
|
11
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Write one encoded frame and wait for drain when the writer reports backpressure.
|
|
25
|
+
*
|
|
26
|
+
* The signal is re-checked around the write and the drain wait, so cancellation does not leave a
|
|
27
|
+
* pending write considered successful.
|
|
28
|
+
*
|
|
29
|
+
* @param request Writer plus the already encoded frame.
|
|
30
|
+
* @param context Execution context carrying the abort signal.
|
|
31
|
+
* @returns Resolves once the frame is accepted or the writer drains.
|
|
32
|
+
* @throws The signal's abort reason, or {@link TypeError} when `write` does not return a boolean
|
|
33
|
+
* synchronously.
|
|
34
|
+
*/
|
|
12
35
|
export async function writeSseFrame({ writer, frame }, { signal }) {
|
|
13
36
|
signal.throwIfAborted();
|
|
14
37
|
const ready = booleanResult(writer.write(frame), 'SSE writes must return boolean synchronously');
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Type-only entry (`@jangts/agent-core/types`): every public declaration without runtime
|
|
3
|
+
* values, suitable for consumers that only need compile-time shapes.
|
|
4
|
+
*
|
|
5
|
+
* It mirrors the root surface plus Kit-specific structures, and re-exports `./index.js` as
|
|
6
|
+
* types so a single import satisfies both usage styles. Because nothing here executes, this
|
|
7
|
+
* entry cannot be used to reach registries or helpers; those stay on the root entry, the
|
|
8
|
+
* `Support` namespace, or individual Kit subpaths.
|
|
9
|
+
*/
|
|
2
10
|
export type * from './structs/index.js';
|
|
3
11
|
export type * from './structs/kits/answering/tasks.js';
|
|
4
12
|
export type * from './structs/kits/answering/checks.js';
|
|
@@ -1,5 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-wide diagnostic outlet for `breakWhile` rejections.
|
|
3
|
+
*
|
|
4
|
+
* `rules.ts` owns the decision itself; this module only reports the rejection a host
|
|
5
|
+
* asked to observe. Reporting is optional and strictly fire-and-forget, so a faulty
|
|
6
|
+
* observer cannot change validation semantics.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `configureBreakWhile` (install the observer) and `observeBreak` (notify it).
|
|
9
|
+
*/
|
|
1
10
|
import type { BreakCheck, BreakWhileConfig } from '../structs/utils/rules.js';
|
|
2
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Install the host-owned break observer.
|
|
13
|
+
*
|
|
14
|
+
* No logging or persistence is enabled by default; passing no argument (or an empty
|
|
15
|
+
* config) removes any previously installed observer.
|
|
16
|
+
*
|
|
17
|
+
* @param config - Observation configuration; `onBreak` receives one frozen event per rejection.
|
|
18
|
+
*/
|
|
3
19
|
export declare function configureBreakWhile(config?: BreakWhileConfig): void;
|
|
4
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Notify the installed observer about a rejection.
|
|
22
|
+
*
|
|
23
|
+
* The original interruption is authoritative: observer failures, and rejections of the
|
|
24
|
+
* promise an observer returns, are swallowed.
|
|
25
|
+
*
|
|
26
|
+
* @param error - The value that is about to be thrown by `breakWhile`.
|
|
27
|
+
* @param tags - Call-site tags supplied by the caller of `breakWhile`.
|
|
28
|
+
* @param rule - The failing check, whose own tags are merged into the reported set.
|
|
29
|
+
*/
|
|
5
30
|
export declare function observeBreak(error: unknown, tags: readonly string[], rule: Pick<BreakCheck, 'tags'>): void;
|