@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,7 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bounded event plumbing for applications that must forward streamed output under cancellation.
|
|
4
|
+
*
|
|
5
|
+
* A producer pushes events one at a time and waits for each to be consumed; the consumer pulls
|
|
6
|
+
* from an async iterable. There is no unbounded queue, so a slow consumer slows the producer
|
|
7
|
+
* instead of growing memory, and aborting the signal closes both sides.
|
|
8
|
+
*
|
|
9
|
+
* Main export: `streamEvents`.
|
|
10
|
+
*/
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.streamEvents = streamEvents;
|
|
4
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Bridge a push-style producer to a pull-style async iterable with a one-slot rendezvous.
|
|
15
|
+
*
|
|
16
|
+
* The producer must await every `emit` call before emitting again; concurrent emissions are
|
|
17
|
+
* rejected rather than buffered. The slot is released only after the consumer receives the event,
|
|
18
|
+
* so backpressure is exact.
|
|
19
|
+
*
|
|
20
|
+
* @param operation Producer that receives an `emit` callback and runs to completion.
|
|
21
|
+
* @param context Execution context carrying the abort signal used to close the rendezvous.
|
|
22
|
+
* @returns An async iterable yielding each event in production order.
|
|
23
|
+
* @throws The producer's error, or the signal's abort reason when cancelled. Also rejects an
|
|
24
|
+
* `emit` that overlaps another, occurs after close, or is never consumed by the consumer.
|
|
25
|
+
*/
|
|
5
26
|
async function* streamEvents(operation, { signal }) {
|
|
6
27
|
let slot;
|
|
7
28
|
let wake;
|
|
@@ -9,24 +30,53 @@ async function* streamEvents(operation, { signal }) {
|
|
|
9
30
|
let sending = false;
|
|
10
31
|
let failure;
|
|
11
32
|
let rejectSend;
|
|
12
|
-
const notify = () => {
|
|
13
|
-
|
|
33
|
+
const notify = () => {
|
|
34
|
+
wake?.();
|
|
35
|
+
wake = undefined;
|
|
36
|
+
};
|
|
37
|
+
const abort = () => {
|
|
38
|
+
closed = true;
|
|
39
|
+
rejectSend?.(signal.reason ?? new Error('Stream closed'));
|
|
40
|
+
notify();
|
|
41
|
+
};
|
|
14
42
|
signal.addEventListener('abort', abort, { once: true });
|
|
15
43
|
if (signal.aborted)
|
|
16
44
|
abort();
|
|
17
|
-
const producer = Promise.resolve()
|
|
45
|
+
const producer = Promise.resolve()
|
|
46
|
+
.then(() => {
|
|
18
47
|
signal.throwIfAborted();
|
|
19
48
|
// Before the producer starts, only abort can close this rendezvous; the
|
|
20
49
|
// signal check above already rejects it with the original reason.
|
|
21
|
-
return operation(event => {
|
|
50
|
+
return operation((event) => {
|
|
22
51
|
if (closed || signal.aborted)
|
|
23
52
|
return Promise.reject(signal.reason ?? new Error('Stream closed'));
|
|
24
53
|
if (sending)
|
|
25
54
|
return Promise.reject(new Error('Event producers must await delivery'));
|
|
26
55
|
sending = true;
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
rejectSend = reject;
|
|
58
|
+
slot = {
|
|
59
|
+
event,
|
|
60
|
+
release: () => {
|
|
61
|
+
sending = false;
|
|
62
|
+
resolve();
|
|
63
|
+
},
|
|
64
|
+
cancel: () => {
|
|
65
|
+
sending = false;
|
|
66
|
+
reject(new Error('Stream closed before event consumption'));
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
notify();
|
|
70
|
+
});
|
|
28
71
|
});
|
|
29
|
-
})
|
|
72
|
+
})
|
|
73
|
+
.catch((error) => {
|
|
74
|
+
failure = { error };
|
|
75
|
+
})
|
|
76
|
+
.finally(() => {
|
|
77
|
+
done = true;
|
|
78
|
+
notify();
|
|
79
|
+
});
|
|
30
80
|
try {
|
|
31
81
|
while (true) {
|
|
32
82
|
signal.throwIfAborted();
|
|
@@ -51,7 +101,9 @@ async function* streamEvents(operation, { signal }) {
|
|
|
51
101
|
return;
|
|
52
102
|
}
|
|
53
103
|
else
|
|
54
|
-
await new Promise(resolve => {
|
|
104
|
+
await new Promise((resolve) => {
|
|
105
|
+
wake = resolve;
|
|
106
|
+
});
|
|
55
107
|
}
|
|
56
108
|
}
|
|
57
109
|
finally {
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createToolRegistry = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Re-export barrel: exposes the Core tool registry factory to Support consumers.
|
|
6
|
+
*
|
|
7
|
+
* Core owns the registry implementation; Support only re-exports it so applications can bind a
|
|
8
|
+
* `ToolCatalog` without importing internal paths. No behavior is added here.
|
|
9
|
+
*/
|
|
4
10
|
var tool_runtime_js_1 = require("../capabilities/tool-runtime.js");
|
|
5
11
|
Object.defineProperty(exports, "createToolRegistry", { enumerable: true, get: function () { return tool_runtime_js_1.createToolRegistry; } });
|
|
@@ -2,42 +2,111 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineTool = defineTool;
|
|
4
4
|
exports.defineToolCatalog = defineToolCatalog;
|
|
5
|
+
/**
|
|
6
|
+
* Tool support: turn typed application tool definitions into a Core-schedulable tool catalog.
|
|
7
|
+
*
|
|
8
|
+
* A tool declaration pairs an input schema with authorization, execution and output parsing. The
|
|
9
|
+
* catalog projects those tools into model capabilities and binds them to the Core tool registry
|
|
10
|
+
* when a runtime request supplies the application. Support only assembles the registration; Core
|
|
11
|
+
* still performs authorization, invocation, budgets and cancellation.
|
|
12
|
+
*
|
|
13
|
+
* Main exports: `defineTool` and `defineToolCatalog`.
|
|
14
|
+
*/
|
|
5
15
|
const model_js_1 = require("../capabilities/model.js");
|
|
6
16
|
const tool_runtime_js_1 = require("./tool-runtime.js");
|
|
7
17
|
const schema_js_1 = require("./schema.js");
|
|
8
18
|
const catalog_js_1 = require("../utils/catalog.js");
|
|
9
19
|
const synchronous_js_1 = require("../utils/synchronous.js");
|
|
20
|
+
/**
|
|
21
|
+
* Validate one tool declaration and freeze a detached copy of it.
|
|
22
|
+
*
|
|
23
|
+
* `authorize` must settle with `void`; a rejection has to be thrown, so a returned `false` cannot
|
|
24
|
+
* silently pass. Handlers are bound to the declaration object, and the input schema is
|
|
25
|
+
* re-snapshotted so later mutation cannot widen the accepted input.
|
|
26
|
+
*
|
|
27
|
+
* @param definition Tool declaration whose `id` is preserved as a literal type.
|
|
28
|
+
* @returns A frozen tool definition with a snapshotted `inputSchema`.
|
|
29
|
+
* @throws {TypeError} When `id`, `kind` or `description` is blank, when a handler is missing, or
|
|
30
|
+
* when `authorize` returns a value instead of throwing.
|
|
31
|
+
*/
|
|
10
32
|
function defineTool(definition) {
|
|
11
33
|
const { id, kind, description } = definition;
|
|
12
34
|
if (!id?.trim() || !kind?.trim() || !description?.trim())
|
|
13
35
|
throw new TypeError('Invalid tool identity');
|
|
14
|
-
if (typeof definition.authorize !== 'function' ||
|
|
36
|
+
if (typeof definition.authorize !== 'function' ||
|
|
37
|
+
typeof definition.execute !== 'function' ||
|
|
38
|
+
typeof definition.parseOutput !== 'function')
|
|
15
39
|
throw new TypeError('Missing tool handler');
|
|
16
40
|
const inputSchema = (0, schema_js_1.defineSchema)(definition.inputSchema);
|
|
17
41
|
const authorize = definition.authorize.bind(definition);
|
|
18
|
-
return Object.freeze({
|
|
42
|
+
return Object.freeze({
|
|
43
|
+
id,
|
|
44
|
+
kind,
|
|
45
|
+
description,
|
|
46
|
+
inputSchema,
|
|
19
47
|
authorize(input, context) {
|
|
20
48
|
return (0, synchronous_js_1.maybeAssertion)(authorize(input, context), 'Authorization must return void; rejection must throw');
|
|
21
49
|
},
|
|
22
50
|
execute: definition.execute.bind(definition),
|
|
23
51
|
debugSteps: definition.debugSteps?.bind(definition),
|
|
24
|
-
parseOutput: definition.parseOutput.bind(definition),
|
|
52
|
+
parseOutput: definition.parseOutput.bind(definition),
|
|
53
|
+
});
|
|
25
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Compile tool declarations into a frozen catalog with model capabilities and runtime binding.
|
|
57
|
+
*
|
|
58
|
+
* Each tool becomes a model capability whose resolver returns `{ toolId, input }`; the model only
|
|
59
|
+
* chooses among registered tools, it never invokes them directly.
|
|
60
|
+
*
|
|
61
|
+
* @param definitions Tool declarations in catalog order.
|
|
62
|
+
* @returns A frozen catalog with `capabilities`, `select` and `bind`.
|
|
63
|
+
* @throws {TypeError} When a tool declaration is invalid or a tool ID is duplicated.
|
|
64
|
+
*/
|
|
26
65
|
function defineToolCatalog(definitions) {
|
|
27
|
-
const entries = definitions.map(definition => defineTool(definition));
|
|
28
|
-
const view = (0, catalog_js_1.readonlyCatalog)(entries, id => new TypeError(`Unknown tool: ${id}`));
|
|
29
|
-
const capabilities = new model_js_1.ModelCapabilityRegistry(entries.map(tool => ({
|
|
66
|
+
const entries = definitions.map((definition) => defineTool(definition));
|
|
67
|
+
const view = (0, catalog_js_1.readonlyCatalog)(entries, (id) => new TypeError(`Unknown tool: ${id}`));
|
|
68
|
+
const capabilities = new model_js_1.ModelCapabilityRegistry(entries.map((tool) => ({
|
|
69
|
+
id: tool.id,
|
|
70
|
+
description: tool.description,
|
|
71
|
+
inputSchema: (0, schema_js_1.defineSchema)({
|
|
72
|
+
jsonSchema: tool.inputSchema.jsonSchema,
|
|
73
|
+
parse: (input) => input,
|
|
74
|
+
}),
|
|
30
75
|
resolve: (input) => ({ toolId: tool.id, input }),
|
|
31
76
|
}))).seal();
|
|
32
|
-
return Object.freeze({
|
|
33
|
-
|
|
77
|
+
return Object.freeze({
|
|
78
|
+
...view,
|
|
79
|
+
capabilities,
|
|
80
|
+
/**
|
|
81
|
+
* Narrow the catalog to the given tool IDs, preserving their declaration order.
|
|
82
|
+
*
|
|
83
|
+
* @param ids Registered tool IDs to keep.
|
|
84
|
+
* @returns A new catalog containing only the selected tools.
|
|
85
|
+
* @throws {TypeError} When an ID is not registered in this catalog.
|
|
86
|
+
*/
|
|
87
|
+
select(ids) {
|
|
88
|
+
capabilities.select(ids);
|
|
89
|
+
return defineToolCatalog(ids.map((id) => view.require(id)));
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Bind the catalog to one application runtime request.
|
|
93
|
+
*
|
|
94
|
+
* @param request Runtime request supplying the app and optional execution/error ports.
|
|
95
|
+
* @returns A frozen runtime whose `invoke`/`invokeSync` delegate to the Core tool registry.
|
|
96
|
+
* @throws {TypeError} When the request does not carry an `app`.
|
|
97
|
+
*/
|
|
34
98
|
bind(request) {
|
|
35
99
|
if (!request || !('app' in request))
|
|
36
100
|
throw new TypeError('A runtime request requires app');
|
|
37
101
|
const registry = (0, tool_runtime_js_1.createToolRegistry)(entries, request.app, {
|
|
38
|
-
execution: request.execution,
|
|
102
|
+
execution: request.execution,
|
|
103
|
+
errors: request.errors,
|
|
39
104
|
});
|
|
40
|
-
return Object.freeze({
|
|
105
|
+
return Object.freeze({
|
|
106
|
+
capabilities,
|
|
107
|
+
get events() {
|
|
108
|
+
return registry.events;
|
|
109
|
+
},
|
|
41
110
|
invokeSync: registry.invoke.bind(registry),
|
|
42
111
|
invoke: registry.invokeAsync.bind(registry),
|
|
43
112
|
});
|
|
@@ -14,5 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/**
|
|
18
|
+
* Transport helpers for hosts that own their own HTTP response lifecycle.
|
|
19
|
+
*
|
|
20
|
+
* `./sse.js` covers server-sent events (reading, encoding and cancellable writes) and
|
|
21
|
+
* `./json.js` covers framed JSON scanning. Both are mechanical utilities: the host decides which
|
|
22
|
+
* traffic, frames and content are acceptable.
|
|
23
|
+
*/
|
|
17
24
|
__exportStar(require("./sse.js"), exports);
|
|
18
25
|
__exportStar(require("./json.js"), exports);
|
|
@@ -34,7 +34,13 @@ function* scan(text) {
|
|
|
34
34
|
if (depth || quoted)
|
|
35
35
|
throw new Error('Incomplete JSON transport');
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Extract complete object-shaped spans from surrounding text, without parsing or selecting them.
|
|
39
|
+
*
|
|
40
|
+
* @param text Streamed text possibly containing JSON objects and unrelated content.
|
|
41
|
+
* @returns Raw object spans in source order.
|
|
42
|
+
* @throws {Error} When the text ends inside an unterminated object or string.
|
|
43
|
+
*/
|
|
38
44
|
function scanJsonObjectFrames(text) {
|
|
39
45
|
const frames = [];
|
|
40
46
|
for (const part of scan(text))
|
|
@@ -42,10 +48,26 @@ function scanJsonObjectFrames(text) {
|
|
|
42
48
|
frames.push(part.text);
|
|
43
49
|
return frames;
|
|
44
50
|
}
|
|
45
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Parse complete object frames under explicit count and size limits.
|
|
53
|
+
*
|
|
54
|
+
* Only whitespace may appear outside frames; a stray closing brace is tolerated only up to
|
|
55
|
+
* `maxExtraClosings`, which covers transports that repeat the delimiter after the payload.
|
|
56
|
+
*
|
|
57
|
+
* @param text Streamed text to scan.
|
|
58
|
+
* @param limits Frame count, size and stray-closer allowances; validated before scanning.
|
|
59
|
+
* @returns Parsed frames in source order.
|
|
60
|
+
* @throws {TypeError} When a limit is not a safe integer or falls outside its allowed range.
|
|
61
|
+
* @throws {Error} When a limit is exceeded, content outside a frame is not whitespace, or the
|
|
62
|
+
* transport ends before at least one complete frame exists.
|
|
63
|
+
*/
|
|
46
64
|
function parseJsonFrames(text, limits) {
|
|
47
|
-
if (!Number.isSafeInteger(limits.maxFrames) ||
|
|
48
|
-
|
|
65
|
+
if (!Number.isSafeInteger(limits.maxFrames) ||
|
|
66
|
+
limits.maxFrames < 1 ||
|
|
67
|
+
!Number.isSafeInteger(limits.maxExtraClosings) ||
|
|
68
|
+
limits.maxExtraClosings < 0 ||
|
|
69
|
+
(limits.maxFrameChars !== undefined &&
|
|
70
|
+
(!Number.isSafeInteger(limits.maxFrameChars) || limits.maxFrameChars < 1)))
|
|
49
71
|
throw new TypeError('Invalid JSON frame limits');
|
|
50
72
|
const frames = [];
|
|
51
73
|
let extraClosings = 0;
|
|
@@ -53,6 +75,8 @@ function parseJsonFrames(text, limits) {
|
|
|
53
75
|
if (part.kind === 'frame') {
|
|
54
76
|
if (frames.length >= limits.maxFrames)
|
|
55
77
|
throw new Error('JSON frame limit exceeded');
|
|
78
|
+
if (limits.maxFrameChars !== undefined && part.text.length > limits.maxFrameChars)
|
|
79
|
+
throw new Error('JSON frame size exceeded');
|
|
56
80
|
frames.push(JSON.parse(part.text));
|
|
57
81
|
}
|
|
58
82
|
else if (part.text === '}') {
|
|
@@ -11,12 +11,35 @@ Object.defineProperty(exports, "readSse", { enumerable: true, get: function () {
|
|
|
11
11
|
Object.defineProperty(exports, "SseIdleTimeoutError", { enumerable: true, get: function () { return sse_1.SseIdleTimeoutError; } });
|
|
12
12
|
var abortable_stream_1 = require("@jangts/streaming/abortable-stream");
|
|
13
13
|
Object.defineProperty(exports, "abortableStream", { enumerable: true, get: function () { return abortable_stream_1.abortableStream; } });
|
|
14
|
+
/**
|
|
15
|
+
* Encode one event in the server-sent events wire format.
|
|
16
|
+
*
|
|
17
|
+
* Every line of `data` gets its own `data:` field, because a raw newline would start a new field.
|
|
18
|
+
*
|
|
19
|
+
* @param event Event name and payload to encode.
|
|
20
|
+
* @returns The complete frame, terminated by a blank line.
|
|
21
|
+
* @throws {TypeError} When the event name contains a newline, which would corrupt the frame.
|
|
22
|
+
*/
|
|
14
23
|
function encodeSseEvent(event) {
|
|
15
24
|
if (/[\r\n]/.test(event.event))
|
|
16
25
|
throw new TypeError('SSE event name cannot contain a newline');
|
|
17
|
-
return `event: ${event.event}\n${event.data
|
|
26
|
+
return `event: ${event.event}\n${event.data
|
|
27
|
+
.split(/\r\n|\r|\n/)
|
|
28
|
+
.map((line) => `data: ${line}\n`)
|
|
29
|
+
.join('')}\n`;
|
|
18
30
|
}
|
|
19
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Write one encoded frame and wait for drain when the writer reports backpressure.
|
|
33
|
+
*
|
|
34
|
+
* The signal is re-checked around the write and the drain wait, so cancellation does not leave a
|
|
35
|
+
* pending write considered successful.
|
|
36
|
+
*
|
|
37
|
+
* @param request Writer plus the already encoded frame.
|
|
38
|
+
* @param context Execution context carrying the abort signal.
|
|
39
|
+
* @returns Resolves once the frame is accepted or the writer drains.
|
|
40
|
+
* @throws The signal's abort reason, or {@link TypeError} when `write` does not return a boolean
|
|
41
|
+
* synchronously.
|
|
42
|
+
*/
|
|
20
43
|
async function writeSseFrame({ writer, frame }, { signal }) {
|
|
21
44
|
signal.throwIfAborted();
|
|
22
45
|
const ready = (0, synchronous_js_1.booleanResult)(writer.write(frame), 'SSE writes must return boolean synchronously');
|
|
@@ -3,12 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.configureBreakWhile = configureBreakWhile;
|
|
4
4
|
exports.observeBreak = observeBreak;
|
|
5
5
|
let onBreak;
|
|
6
|
+
// Re-entrancy guard: an observer that itself calls breakWhile would otherwise recurse
|
|
7
|
+
// until the stack overflows.
|
|
6
8
|
let notifying = false;
|
|
7
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Install the host-owned break observer.
|
|
11
|
+
*
|
|
12
|
+
* No logging or persistence is enabled by default; passing no argument (or an empty
|
|
13
|
+
* config) removes any previously installed observer.
|
|
14
|
+
*
|
|
15
|
+
* @param config - Observation configuration; `onBreak` receives one frozen event per rejection.
|
|
16
|
+
*/
|
|
8
17
|
function configureBreakWhile(config = {}) {
|
|
9
18
|
onBreak = config.onBreak;
|
|
10
19
|
}
|
|
11
|
-
/**
|
|
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
|
+
*/
|
|
12
30
|
function observeBreak(error, tags, rule) {
|
|
13
31
|
if (!onBreak || notifying)
|
|
14
32
|
return;
|
|
@@ -5,8 +5,24 @@ exports.combineSignals = combineSignals;
|
|
|
5
5
|
exports.awaitWithSignal = awaitWithSignal;
|
|
6
6
|
exports.awaitAssertion = awaitAssertion;
|
|
7
7
|
exports.createDeadlineSignal = createDeadlineSignal;
|
|
8
|
+
/**
|
|
9
|
+
* Cancellation and deadline plumbing shared by the model runner and the engine.
|
|
10
|
+
*
|
|
11
|
+
* Every helper here treats an abort signal as a pure lifetime bound: it may only
|
|
12
|
+
* shorten waiting, never extend it, and it never replaces a caller-supplied parent
|
|
13
|
+
* signal. Exports: `isTimeoutReason`, `combineSignals`, `awaitWithSignal`,
|
|
14
|
+
* `awaitAssertion` and `createDeadlineSignal`.
|
|
15
|
+
*/
|
|
8
16
|
const synchronous_js_1 = require("./synchronous.js");
|
|
9
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Detect a deadline expiry as opposed to any other cancellation.
|
|
19
|
+
*
|
|
20
|
+
* The reason of an aborted signal is an arbitrary thrown value, including hostile
|
|
21
|
+
* objects whose `name` getter throws, so the lookup is guarded.
|
|
22
|
+
*
|
|
23
|
+
* @param reason - Value delivered as `signal.reason`.
|
|
24
|
+
* @returns True when the reason is named `TimeoutError`.
|
|
25
|
+
*/
|
|
10
26
|
function isTimeoutReason(reason) {
|
|
11
27
|
try {
|
|
12
28
|
return reason?.name === 'TimeoutError';
|
|
@@ -15,12 +31,36 @@ function isTimeoutReason(reason) {
|
|
|
15
31
|
return false;
|
|
16
32
|
}
|
|
17
33
|
}
|
|
18
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Merge optional signals into one lifetime bound.
|
|
36
|
+
*
|
|
37
|
+
* Duplicates are removed first so a signal appearing both as an execution parent and
|
|
38
|
+
* as a request signal does not allocate a redundant composite. When nothing is
|
|
39
|
+
* supplied a fresh, never-aborting signal is returned, which keeps callers free of
|
|
40
|
+
* undefined checks.
|
|
41
|
+
*
|
|
42
|
+
* @param sources - Candidate signals in precedence-free order; `undefined` entries are ignored.
|
|
43
|
+
* @returns A signal that aborts as soon as any supplied signal aborts.
|
|
44
|
+
*/
|
|
19
45
|
function combineSignals(...sources) {
|
|
20
|
-
const signals = [
|
|
21
|
-
|
|
46
|
+
const signals = [
|
|
47
|
+
...new Set(sources.filter((signal) => signal !== undefined)),
|
|
48
|
+
];
|
|
49
|
+
return signals.length > 1
|
|
50
|
+
? AbortSignal.any(signals)
|
|
51
|
+
: (signals[0] ?? new AbortController().signal);
|
|
22
52
|
}
|
|
23
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Race a pending value against an abort signal.
|
|
55
|
+
*
|
|
56
|
+
* Abandoning the wait does not cancel the underlying work: a late rejection is still
|
|
57
|
+
* consumed to avoid an unhandled rejection, and the abort listener is always removed.
|
|
58
|
+
*
|
|
59
|
+
* @param value - Value or promise to await; `undefined` keeps the same await semantics.
|
|
60
|
+
* @param signal - Optional lifetime bound; without it the value is awaited unchanged.
|
|
61
|
+
* @returns The resolved value.
|
|
62
|
+
* @throws The signal reason when aborted, or the rejection of `value`.
|
|
63
|
+
*/
|
|
24
64
|
async function awaitWithSignal(value, signal) {
|
|
25
65
|
if (!signal)
|
|
26
66
|
return value;
|
|
@@ -38,14 +78,37 @@ async function awaitWithSignal(value, signal) {
|
|
|
38
78
|
signal.removeEventListener('abort', abort);
|
|
39
79
|
}
|
|
40
80
|
}
|
|
41
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Run an assertion that may be asynchronous, bounded by a signal.
|
|
83
|
+
*
|
|
84
|
+
* Only a `void` result counts as success, so a hook that discards its decision as a
|
|
85
|
+
* boolean is rejected rather than silently treated as passing. The signal is checked
|
|
86
|
+
* before and after the hook so a decision produced after cancellation is discarded.
|
|
87
|
+
*
|
|
88
|
+
* @param check - Hook invoked once; may return a promise.
|
|
89
|
+
* @param signal - Lifetime bound for the hook and its result.
|
|
90
|
+
* @param message - Message for the TypeError raised when the hook does not return void.
|
|
91
|
+
* @returns A promise resolved once the assertion passed.
|
|
92
|
+
* @throws The signal reason when aborted, the hook's rejection, or the assertion TypeError.
|
|
93
|
+
*/
|
|
42
94
|
async function awaitAssertion(check, signal, message) {
|
|
43
95
|
signal.throwIfAborted();
|
|
44
96
|
const result = await awaitWithSignal(check(), signal);
|
|
45
97
|
signal.throwIfAborted();
|
|
46
98
|
(0, synchronous_js_1.assertion)(result, message);
|
|
47
99
|
}
|
|
48
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* Abort at an absolute wall-clock deadline, combined with a parent signal.
|
|
102
|
+
*
|
|
103
|
+
* Timers above the platform maximum are chunked instead of being clamped, so the
|
|
104
|
+
* persisted deadline is never shortened. The deadline is recomputed from the clock on
|
|
105
|
+
* each chunk, which keeps the effective expiry correct across timer drift.
|
|
106
|
+
*
|
|
107
|
+
* @param deadline - Absolute deadline in epoch milliseconds.
|
|
108
|
+
* @param parent - Additional lifetime bound, typically the execution signal.
|
|
109
|
+
* @param now - Clock source; injectable for tests.
|
|
110
|
+
* @returns The combined `signal` and a `dispose` function that cancels the pending timer.
|
|
111
|
+
*/
|
|
49
112
|
function createDeadlineSignal(deadline, parent, now = Date.now) {
|
|
50
113
|
const controller = new AbortController();
|
|
51
114
|
let timer;
|
|
@@ -57,6 +120,11 @@ function createDeadlineSignal(deadline, parent, now = Date.now) {
|
|
|
57
120
|
timer = setTimeout(schedule, Math.min(remaining, 2147483647));
|
|
58
121
|
};
|
|
59
122
|
schedule();
|
|
60
|
-
return {
|
|
61
|
-
|
|
123
|
+
return {
|
|
124
|
+
signal: combineSignals(parent, controller.signal),
|
|
125
|
+
dispose() {
|
|
126
|
+
if (timer !== undefined)
|
|
127
|
+
clearTimeout(timer);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
62
130
|
}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readonlyCatalog = readonlyCatalog;
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Build a frozen catalog from an iterable of definitions.
|
|
6
|
+
*
|
|
7
|
+
* Ids must be non-empty after trimming and unique; both violations surface as a
|
|
8
|
+
* TypeError during construction rather than on first lookup.
|
|
9
|
+
*
|
|
10
|
+
* @param definitions - Definitions to snapshot; iteration order is preserved in `definitions`.
|
|
11
|
+
* @param missing - Factory for the error thrown by `require` when an id is absent.
|
|
12
|
+
* @returns A frozen catalog; `get` is unguarded while `require` throws via `missing`.
|
|
13
|
+
* @throws TypeError When an id is blank or duplicated.
|
|
14
|
+
*/
|
|
5
15
|
function readonlyCatalog(definitions, missing) {
|
|
6
16
|
const byId = new Map();
|
|
7
17
|
for (const definition of definitions) {
|
|
@@ -10,9 +20,14 @@ function readonlyCatalog(definitions, missing) {
|
|
|
10
20
|
byId.set(definition.id, definition);
|
|
11
21
|
}
|
|
12
22
|
const snapshot = Object.freeze([...byId.values()]);
|
|
13
|
-
return Object.freeze({
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
return Object.freeze({
|
|
24
|
+
definitions: snapshot,
|
|
25
|
+
ids: () => Object.freeze([...byId.keys()]),
|
|
26
|
+
values: () => byId.values(),
|
|
27
|
+
entries: () => byId.entries(),
|
|
28
|
+
has: (id) => byId.has(id),
|
|
29
|
+
get: (id) => byId.get(id),
|
|
30
|
+
require(id) {
|
|
16
31
|
const value = byId.get(id);
|
|
17
32
|
if (value === undefined)
|
|
18
33
|
throw missing(id);
|
package/dist/cjs/utils/debug.js
CHANGED
|
@@ -3,14 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.captureSubSteps = captureSubSteps;
|
|
4
4
|
const sub_flow_js_1 = require("../diagnostics/sub-flow.js");
|
|
5
5
|
const synchronous_js_1 = require("./synchronous.js");
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Read the current sub-step log of one execution visit.
|
|
8
|
+
*
|
|
9
|
+
* A missing reader or a logger that yields nothing produces the empty shape, which
|
|
10
|
+
* lets callers spread the result unconditionally. Failures are reported as one
|
|
11
|
+
* dropped step instead of propagating, because diagnostics must not break execution.
|
|
12
|
+
*
|
|
13
|
+
* @param read - Getter for the current logger; omitted when the caller has no logger.
|
|
14
|
+
* @param identity - Diagnostic identity copied onto each captured step.
|
|
15
|
+
* @returns Frozen `subSteps`, the number of dropped steps and whether the log was truncated.
|
|
16
|
+
*/
|
|
7
17
|
function captureSubSteps(read, identity) {
|
|
8
18
|
const empty = { subSteps: Object.freeze([]), subStepsDropped: 0, subStepsTruncated: false };
|
|
9
19
|
if (!read)
|
|
10
20
|
return empty;
|
|
11
21
|
try {
|
|
12
22
|
const logger = (0, synchronous_js_1.synchronous)(read(), 'Debug steps must be synchronous');
|
|
13
|
-
return logger === undefined
|
|
23
|
+
return logger === undefined
|
|
24
|
+
? empty
|
|
25
|
+
: { ...empty, subSteps: (0, sub_flow_js_1.readSubFlowLogger)(logger, undefined, identity) };
|
|
14
26
|
}
|
|
15
27
|
catch {
|
|
16
28
|
return { ...empty, subStepsDropped: 1 };
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -15,6 +15,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.retrievalQueryKey = exports.modelProtocolError = exports.commonPrefixLength = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Generic helpers shared by every other module of `@jangts/agent-core`.
|
|
20
|
+
*
|
|
21
|
+
* Nothing here knows about business prompts, stages or transports: this barrel only
|
|
22
|
+
* re-exports rule traversal, text comparison, model protocol errors and retrieval
|
|
23
|
+
* query keys. Consumers inside the package import the concrete module directly;
|
|
24
|
+
* this entry exists so cross-module reuse has one stable surface.
|
|
25
|
+
*/
|
|
18
26
|
__exportStar(require("./rules.js"), exports);
|
|
19
27
|
var text_js_1 = require("./text.js");
|
|
20
28
|
Object.defineProperty(exports, "commonPrefixLength", { enumerable: true, get: function () { return text_js_1.commonPrefixLength; } });
|
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pinCommandDefinition = pinCommandDefinition;
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Produce a detached copy of the contract fields of a command definition.
|
|
6
|
+
*
|
|
7
|
+
* Callbacks are rebound to the original definition so `this` keeps pointing at the
|
|
8
|
+
* source object; `undefined` entries are dropped so optional fields stay absent.
|
|
9
|
+
*
|
|
10
|
+
* @param definition - Source definition, possibly carrying inherited members.
|
|
11
|
+
* @returns A new partial definition containing only the declared contract fields.
|
|
12
|
+
*/
|
|
5
13
|
function pinCommandDefinition(definition) {
|
|
6
|
-
const snapshot = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
const snapshot = {
|
|
15
|
+
...definition,
|
|
16
|
+
fields: definition.fields,
|
|
17
|
+
category: definition.category,
|
|
18
|
+
version: definition.version,
|
|
19
|
+
description: definition.description,
|
|
20
|
+
terminal: definition.terminal,
|
|
21
|
+
discriminator: definition.discriminator,
|
|
22
|
+
ownedFields: definition.ownedFields,
|
|
23
|
+
additionalProperties: definition.additionalProperties,
|
|
24
|
+
optionalPresence: definition.optionalPresence,
|
|
25
|
+
modes: definition.modes,
|
|
26
|
+
tags: definition.tags,
|
|
27
|
+
checks: definition.checks,
|
|
10
28
|
error: typeof definition.error === 'function' ? definition.error.bind(definition) : definition.error,
|
|
11
|
-
refine: definition.refine?.bind(definition),
|
|
29
|
+
refine: definition.refine?.bind(definition),
|
|
30
|
+
format: definition.format?.bind(definition),
|
|
31
|
+
};
|
|
12
32
|
return Object.fromEntries(Object.entries(snapshot).filter(([, value]) => value !== undefined));
|
|
13
33
|
}
|