@jangts/agent-core 0.1.0 → 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/README.md +59 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.md +27 -0
- package/development/docs/assets/agent-core-icon.png +0 -0
- package/development/docs/assets/agent-core-logo.png +0 -0
- package/development/docs/assets/character-agent-core.png +0 -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 +23 -3
|
@@ -1,7 +1,44 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Strict id-keyed registry for model output protocols.
|
|
3
|
+
*
|
|
4
|
+
* Registration is the only source of schema and terminal semantics: the core never
|
|
5
|
+
* knows protocol names. Writes are checked eagerly so a duplicate or blank id fails at
|
|
6
|
+
* wiring time instead of at dispatch time.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `ProtocolRegistry`.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Append-only protocol registry.
|
|
12
|
+
*
|
|
13
|
+
* Extending `Map` keeps lookup semantics familiar while `set` rejects every invalid
|
|
14
|
+
* registration, which makes the instance effectively immutable after wiring.
|
|
15
|
+
*/
|
|
2
16
|
export declare class ProtocolRegistry<Protocol> extends Map<string, Protocol> {
|
|
17
|
+
/**
|
|
18
|
+
* @param definitions - Initial id/protocol pairs, applied through the validating `set`.
|
|
19
|
+
* @throws TypeError When any initial entry is invalid or duplicated.
|
|
20
|
+
*/
|
|
3
21
|
constructor(definitions?: Iterable<readonly [string, Protocol]>);
|
|
22
|
+
/**
|
|
23
|
+
* @returns A frozen array of registered ids in insertion order.
|
|
24
|
+
*/
|
|
4
25
|
ids(): readonly string[];
|
|
26
|
+
/**
|
|
27
|
+
* Look up a protocol that must exist.
|
|
28
|
+
*
|
|
29
|
+
* @param id - Protocol id.
|
|
30
|
+
* @returns The registered protocol.
|
|
31
|
+
* @throws TypeError When the id is unknown.
|
|
32
|
+
*/
|
|
5
33
|
require(id: string): Protocol;
|
|
34
|
+
/**
|
|
35
|
+
* Register a protocol.
|
|
36
|
+
*
|
|
37
|
+
* @param id - Non-blank protocol id.
|
|
38
|
+
* @param protocol - Protocol implementation.
|
|
39
|
+
* @returns This registry, for chaining.
|
|
40
|
+
* @throws TypeError When the id is blank or the protocol is nullish.
|
|
41
|
+
* @throws Error When the id is already registered.
|
|
42
|
+
*/
|
|
6
43
|
set(id: string, protocol: Protocol): this;
|
|
7
44
|
}
|
|
@@ -1,13 +1,56 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Strict id-keyed registry for model output protocols.
|
|
3
|
+
*
|
|
4
|
+
* Registration is the only source of schema and terminal semantics: the core never
|
|
5
|
+
* knows protocol names. Writes are checked eagerly so a duplicate or blank id fails at
|
|
6
|
+
* wiring time instead of at dispatch time.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `ProtocolRegistry`.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Append-only protocol registry.
|
|
12
|
+
*
|
|
13
|
+
* Extending `Map` keeps lookup semantics familiar while `set` rejects every invalid
|
|
14
|
+
* registration, which makes the instance effectively immutable after wiring.
|
|
15
|
+
*/
|
|
2
16
|
export class ProtocolRegistry extends Map {
|
|
17
|
+
/**
|
|
18
|
+
* @param definitions - Initial id/protocol pairs, applied through the validating `set`.
|
|
19
|
+
* @throws TypeError When any initial entry is invalid or duplicated.
|
|
20
|
+
*/
|
|
3
21
|
constructor(definitions = []) {
|
|
4
22
|
super();
|
|
5
23
|
for (const [id, protocol] of definitions)
|
|
6
24
|
this.set(id, protocol);
|
|
7
25
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
26
|
+
/**
|
|
27
|
+
* @returns A frozen array of registered ids in insertion order.
|
|
28
|
+
*/
|
|
29
|
+
ids() {
|
|
30
|
+
return Object.freeze([...this.keys()]);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Look up a protocol that must exist.
|
|
34
|
+
*
|
|
35
|
+
* @param id - Protocol id.
|
|
36
|
+
* @returns The registered protocol.
|
|
37
|
+
* @throws TypeError When the id is unknown.
|
|
38
|
+
*/
|
|
39
|
+
require(id) {
|
|
40
|
+
const value = this.get(id);
|
|
41
|
+
if (value === undefined)
|
|
42
|
+
throw new TypeError(`Unknown protocol: ${id}`);
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Register a protocol.
|
|
47
|
+
*
|
|
48
|
+
* @param id - Non-blank protocol id.
|
|
49
|
+
* @param protocol - Protocol implementation.
|
|
50
|
+
* @returns This registry, for chaining.
|
|
51
|
+
* @throws TypeError When the id is blank or the protocol is nullish.
|
|
52
|
+
* @throws Error When the id is already registered.
|
|
53
|
+
*/
|
|
11
54
|
set(id, protocol) {
|
|
12
55
|
if (!id.trim() || protocol === null || protocol === undefined)
|
|
13
56
|
throw new TypeError('Invalid protocol registration');
|
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Serialize a query into a stable structural key.
|
|
3
|
+
*
|
|
4
|
+
* Object keys are sorted recursively while array positions are preserved. Values that
|
|
5
|
+
* JSON cannot represent, such as functions or `undefined`, make `JSON.stringify`
|
|
6
|
+
* return undefined and therefore produce an error instead of a colliding key.
|
|
7
|
+
*
|
|
8
|
+
* @param value - Query value to canonicalize.
|
|
9
|
+
* @returns A JSON string usable as a map key.
|
|
10
|
+
* @throws TypeError When the value cannot be serialized.
|
|
11
|
+
*/
|
|
2
12
|
export declare function retrievalQueryKey(value: unknown): string;
|
|
@@ -1,5 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable identity for retrieval queries.
|
|
3
|
+
*
|
|
4
|
+
* Retrieval caches need a key that is insensitive to property order but sensitive to
|
|
5
|
+
* array order, because a query's result list is order-dependent.
|
|
6
|
+
*
|
|
7
|
+
* Exports: `retrievalQueryKey`.
|
|
8
|
+
*/
|
|
1
9
|
import { breakWhile } from './rules.js';
|
|
2
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Serialize a query into a stable structural key.
|
|
12
|
+
*
|
|
13
|
+
* Object keys are sorted recursively while array positions are preserved. Values that
|
|
14
|
+
* JSON cannot represent, such as functions or `undefined`, make `JSON.stringify`
|
|
15
|
+
* return undefined and therefore produce an error instead of a colliding key.
|
|
16
|
+
*
|
|
17
|
+
* @param value - Query value to canonicalize.
|
|
18
|
+
* @returns A JSON string usable as a map key.
|
|
19
|
+
* @throws TypeError When the value cannot be serialized.
|
|
20
|
+
*/
|
|
3
21
|
export function retrievalQueryKey(value) {
|
|
4
22
|
const serialized = JSON.stringify(canonical(value));
|
|
5
23
|
breakWhile(serialized === undefined, () => new TypeError('Query cannot be serialized'));
|
|
@@ -9,7 +27,8 @@ function canonical(value) {
|
|
|
9
27
|
if (Array.isArray(value))
|
|
10
28
|
return value.map(canonical);
|
|
11
29
|
if (value && typeof value === 'object') {
|
|
12
|
-
return Object.fromEntries(Object.entries(value)
|
|
30
|
+
return Object.fromEntries(Object.entries(value)
|
|
31
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
13
32
|
.map(([key, item]) => [key, canonical(item)]));
|
|
14
33
|
}
|
|
15
34
|
return value;
|
|
@@ -1,9 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registration projections for App-provided definitions.
|
|
3
|
+
*
|
|
4
|
+
* A registered definition may carry executable helpers alongside its data contract.
|
|
5
|
+
* Only public data survives registration, so the runtime contract cannot silently grow
|
|
6
|
+
* when an implementation adds a helper.
|
|
7
|
+
*
|
|
8
|
+
* Exports: the `RegistrationData` and `RegistrationProjection` types plus
|
|
9
|
+
* `registrationData`.
|
|
10
|
+
*/
|
|
1
11
|
type Handler = (...args: any[]) => unknown;
|
|
2
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Keys of `Value` whose type contains no callable member.
|
|
14
|
+
*
|
|
15
|
+
* Functions are excluded so a definition's implementation helpers never become part of
|
|
16
|
+
* the public registration contract.
|
|
17
|
+
*/
|
|
3
18
|
export type RegistrationData<Value> = Pick<Value, {
|
|
4
19
|
[Key in keyof Value]-?: [Extract<Value[Key], Handler>] extends [never] ? Key : never;
|
|
5
20
|
}[keyof Value]>;
|
|
21
|
+
/**
|
|
22
|
+
* Data-only view of a registered value, intersected with the declared contract.
|
|
23
|
+
*
|
|
24
|
+
* The contract keys are kept even when the implementation narrows them, so consumers
|
|
25
|
+
* type against the published interface rather than one implementation.
|
|
26
|
+
*/
|
|
6
27
|
export type RegistrationProjection<Value, Contract> = Readonly<Contract & RegistrationData<Value> & Pick<Value, Extract<keyof Value, keyof Contract>>>;
|
|
7
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Copy the inherited, non-function data of a definition.
|
|
30
|
+
*
|
|
31
|
+
* The walk starts at the source and moves up the prototype chain while reading every
|
|
32
|
+
* accessor with the source as receiver, so getters keep observing their own instance
|
|
33
|
+
* without the snapshot retaining the mutable prototype. `constructor` is skipped for
|
|
34
|
+
* inherited levels because it describes the class rather than the definition.
|
|
35
|
+
*
|
|
36
|
+
* @param source - Definition to snapshot.
|
|
37
|
+
* @param excluded - Keys that must not appear in the result.
|
|
38
|
+
* @returns A plain object containing enumerable, writable non-function data.
|
|
39
|
+
*/
|
|
8
40
|
export declare function registrationData<Value extends object, Key extends PropertyKey = never>(source: Value, excluded?: readonly Key[]): Omit<RegistrationData<Value>, Key>;
|
|
9
41
|
export {};
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Copy the inherited, non-function data of a definition.
|
|
3
|
+
*
|
|
4
|
+
* The walk starts at the source and moves up the prototype chain while reading every
|
|
5
|
+
* accessor with the source as receiver, so getters keep observing their own instance
|
|
6
|
+
* without the snapshot retaining the mutable prototype. `constructor` is skipped for
|
|
7
|
+
* inherited levels because it describes the class rather than the definition.
|
|
8
|
+
*
|
|
9
|
+
* @param source - Definition to snapshot.
|
|
10
|
+
* @param excluded - Keys that must not appear in the result.
|
|
11
|
+
* @returns A plain object containing enumerable, writable non-function data.
|
|
12
|
+
*/
|
|
2
13
|
export function registrationData(source, excluded = []) {
|
|
3
14
|
const result = {};
|
|
4
15
|
const seen = new Set(excluded);
|
|
@@ -10,7 +21,12 @@ export function registrationData(source, excluded = []) {
|
|
|
10
21
|
const descriptor = Object.getOwnPropertyDescriptor(owner, key);
|
|
11
22
|
const value = descriptor.get ? descriptor.get.call(source) : descriptor.value;
|
|
12
23
|
if (typeof value !== 'function')
|
|
13
|
-
Object.defineProperty(result, key, {
|
|
24
|
+
Object.defineProperty(result, key, {
|
|
25
|
+
value,
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
});
|
|
14
30
|
}
|
|
15
31
|
}
|
|
16
32
|
return result;
|
|
@@ -1,14 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative rule primitives.
|
|
3
|
+
*
|
|
4
|
+
* Three shapes cover the enumerable decisions in this package: first-match dispatch
|
|
5
|
+
* (`matchRule`), ordered mutation of shared input (`walkRules`) and reject-on-failure
|
|
6
|
+
* validation (`breakWhile`). Ordinary single-condition code stays an `if`; these helpers
|
|
7
|
+
* exist so multi-branch tables stay readable and their ordering is explicit.
|
|
8
|
+
*
|
|
9
|
+
* Exports: `matchRule`, `walkRules`, `breakWhile`, the re-exported
|
|
10
|
+
* `configureBreakWhile`, and the rule types from `structs/utils/rules`.
|
|
11
|
+
*/
|
|
1
12
|
import type { MatchRule, WalkRule, BreakReason, BreakCheck, BreakPredicate } from '../structs/utils/rules.js';
|
|
2
13
|
export { configureBreakWhile } from './break-observer.js';
|
|
3
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Dispatch to the first matching rule.
|
|
16
|
+
*
|
|
17
|
+
* A rule without a pattern matches unconditionally, so the table's order decides
|
|
18
|
+
* precedence. The first match owns the result even when its handler returns undefined,
|
|
19
|
+
* and later rules are not consulted.
|
|
20
|
+
*
|
|
21
|
+
* @param rules - Ordered rules; only the first match is executed.
|
|
22
|
+
* @param input - Value passed to the pattern and handler.
|
|
23
|
+
* @returns The handler result, or undefined when nothing matched.
|
|
24
|
+
* @throws TypeError When a pattern returns a thenable or a non-boolean.
|
|
25
|
+
*/
|
|
4
26
|
export declare function matchRule<Input, Result>(rules: readonly MatchRule<Input, Result>[], input: Input): Result | undefined;
|
|
5
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Walk every rule in order, mutating the shared input.
|
|
29
|
+
*
|
|
30
|
+
* Later rules observe the mutations of earlier ones, which is why traversal is strictly
|
|
31
|
+
* sequential and every participant must be synchronous. Throwing stops the walk
|
|
32
|
+
* immediately; remaining rules are skipped.
|
|
33
|
+
*
|
|
34
|
+
* @param rules - Ordered rules.
|
|
35
|
+
*/
|
|
6
36
|
export declare function walkRules(rules: readonly WalkRule[]): void;
|
|
37
|
+
/**
|
|
38
|
+
* Walk every rule in order, mutating the shared input.
|
|
39
|
+
*
|
|
40
|
+
* @param rules - Ordered rules.
|
|
41
|
+
* @param input - Mutable input shared by all hooks and handlers.
|
|
42
|
+
*/
|
|
7
43
|
export declare function walkRules<Input>(rules: readonly WalkRule<Input>[], input: Input): void;
|
|
8
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Reject as soon as one of several conditions holds.
|
|
46
|
+
*
|
|
47
|
+
* Ordinary processing stays an ordinary `if`; this helper is for validation tables
|
|
48
|
+
* whose entries are evaluated in order and stop at the first failure. Behaviour that
|
|
49
|
+
* depends on earlier entries is expressed with a callback form.
|
|
50
|
+
*
|
|
51
|
+
* @param occur - Predicates, or a single predicate/array of predicates.
|
|
52
|
+
* @param error - Reason thrown on the first match; defaults to an empty Error.
|
|
53
|
+
* @param tags - Tags reported to the installed break observer.
|
|
54
|
+
* @throws The configured reason of the first matching check.
|
|
55
|
+
*/
|
|
9
56
|
export declare function breakWhile(occur: readonly BreakPredicate[], error?: BreakReason, tags?: readonly string[]): void;
|
|
57
|
+
/**
|
|
58
|
+
* Reject when any predicate holds, reporting the given observer tags.
|
|
59
|
+
*
|
|
60
|
+
* @param occur - Predicates evaluated in order.
|
|
61
|
+
* @param tags - Tags reported to the installed break observer.
|
|
62
|
+
*/
|
|
10
63
|
export declare function breakWhile(occur: readonly BreakPredicate[], tags: readonly string[]): void;
|
|
64
|
+
/**
|
|
65
|
+
* Reject when any structured check holds.
|
|
66
|
+
*
|
|
67
|
+
* Each check may carry its own reason and tags; the first match stops the evaluation.
|
|
68
|
+
*
|
|
69
|
+
* @param checks - Checks evaluated in order.
|
|
70
|
+
* @param tags - Call-site tags merged with each check's own tags.
|
|
71
|
+
*/
|
|
11
72
|
export declare function breakWhile(checks: readonly BreakCheck[], tags?: readonly string[]): void;
|
|
73
|
+
/**
|
|
74
|
+
* Reject when a single value is truthy.
|
|
75
|
+
*
|
|
76
|
+
* Ordinary truthiness applies, so a function passed as a value counts as a failure;
|
|
77
|
+
* use the predicate form to evaluate it instead.
|
|
78
|
+
*
|
|
79
|
+
* @param occur - Value tested with JavaScript truthiness.
|
|
80
|
+
* @param error - Reason thrown when the value is truthy.
|
|
81
|
+
* @param tags - Tags reported to the installed break observer.
|
|
82
|
+
*/
|
|
12
83
|
export declare function breakWhile(occur: unknown, error?: BreakReason, tags?: readonly string[]): void;
|
|
84
|
+
/**
|
|
85
|
+
* Reject when a single value is truthy, reporting the given observer tags.
|
|
86
|
+
*
|
|
87
|
+
* @param occur - Value tested with JavaScript truthiness.
|
|
88
|
+
* @param tags - Tags reported to the installed break observer.
|
|
89
|
+
*/
|
|
13
90
|
export declare function breakWhile(occur: unknown, tags: readonly string[]): void;
|
|
14
|
-
export type { MatchRule, WalkRule, BreakReason, BreakCheck, BreakPredicate, BreakEvent, BreakWhileConfig } from '../structs/utils/rules.js';
|
|
91
|
+
export type { MatchRule, WalkRule, BreakReason, BreakCheck, BreakPredicate, BreakEvent, BreakWhileConfig, } from '../structs/utils/rules.js';
|
package/dist/esm/utils/rules.js
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import { synchronous, booleanResult } from './synchronous.js';
|
|
2
2
|
import { observeBreak } from './break-observer.js';
|
|
3
3
|
export { configureBreakWhile } from './break-observer.js';
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Dispatch to the first matching rule.
|
|
6
|
+
*
|
|
7
|
+
* A rule without a pattern matches unconditionally, so the table's order decides
|
|
8
|
+
* precedence. The first match owns the result even when its handler returns undefined,
|
|
9
|
+
* and later rules are not consulted.
|
|
10
|
+
*
|
|
11
|
+
* @param rules - Ordered rules; only the first match is executed.
|
|
12
|
+
* @param input - Value passed to the pattern and handler.
|
|
13
|
+
* @returns The handler result, or undefined when nothing matched.
|
|
14
|
+
* @throws TypeError When a pattern returns a thenable or a non-boolean.
|
|
15
|
+
*/
|
|
5
16
|
export function matchRule(rules, input) {
|
|
6
|
-
return rules
|
|
17
|
+
return rules
|
|
18
|
+
.find((rule) => rule.pattern === undefined ||
|
|
19
|
+
booleanResult(rule.pattern(input), 'Rule patterns must return boolean synchronously'))
|
|
20
|
+
?.handle(input);
|
|
7
21
|
}
|
|
8
22
|
export function walkRules(rules, input = undefined) {
|
|
9
23
|
for (const rule of rules) {
|
|
10
24
|
synchronous(rule.before?.(input), 'Rule traversal hooks must be synchronous');
|
|
11
|
-
if (rule.pattern === undefined ||
|
|
25
|
+
if (rule.pattern === undefined ||
|
|
26
|
+
booleanResult(rule.pattern(input), 'Rule patterns must return boolean synchronously'))
|
|
12
27
|
synchronous(rule.handle(input), 'Rule traversal handlers must be synchronous');
|
|
13
28
|
}
|
|
14
29
|
}
|
|
@@ -17,24 +32,37 @@ export function breakWhile(occur, errorOrTags, tags = []) {
|
|
|
17
32
|
const callTags = Array.isArray(errorOrTags) ? errorOrTags : tags;
|
|
18
33
|
// A single value keeps ordinary JS truthiness, including a function used as a value.
|
|
19
34
|
const checks = Array.isArray(occur)
|
|
20
|
-
? typeof occur[0] === 'function' && occur.every(item => typeof item === 'function')
|
|
35
|
+
? typeof occur[0] === 'function' && occur.every((item) => typeof item === 'function')
|
|
21
36
|
? [{ occur, error }]
|
|
22
37
|
: occur
|
|
23
38
|
: [{ occur: () => occur, error }];
|
|
24
39
|
for (const check of checks) {
|
|
25
40
|
try {
|
|
26
|
-
if (!check ||
|
|
27
|
-
|
|
41
|
+
if (!check ||
|
|
42
|
+
typeof check !== 'object' ||
|
|
43
|
+
Array.isArray(check) ||
|
|
44
|
+
!Object.hasOwn(check, 'occur') ||
|
|
45
|
+
'condition' in check ||
|
|
46
|
+
'conditions' in check)
|
|
28
47
|
throw new TypeError('A break check requires occur; condition and conditions were renamed to occur');
|
|
29
48
|
const occur = check.occur;
|
|
30
|
-
if (Array.isArray(occur) && occur.some(predicate => typeof predicate !== 'function'))
|
|
49
|
+
if (Array.isArray(occur) && occur.some((predicate) => typeof predicate !== 'function'))
|
|
31
50
|
throw new TypeError('An occur array requires predicates');
|
|
32
|
-
const matched = Array.isArray(occur)
|
|
33
|
-
|
|
51
|
+
const matched = Array.isArray(occur)
|
|
52
|
+
? occur.some((predicate) => synchronous(predicate(), 'Occur predicates must be synchronous'))
|
|
53
|
+
: typeof occur === 'function'
|
|
54
|
+
? synchronous(occur(), 'Occur predicates must be synchronous')
|
|
55
|
+
: occur;
|
|
34
56
|
if (!matched)
|
|
35
57
|
continue;
|
|
36
|
-
const reason = typeof check.error === 'function'
|
|
37
|
-
|
|
58
|
+
const reason = typeof check.error === 'function'
|
|
59
|
+
? synchronous(check.error(), 'Break reasons must be synchronous')
|
|
60
|
+
: check.error;
|
|
61
|
+
throw reason === undefined
|
|
62
|
+
? new Error()
|
|
63
|
+
: typeof reason === 'string'
|
|
64
|
+
? new Error(reason)
|
|
65
|
+
: reason;
|
|
38
66
|
}
|
|
39
67
|
catch (failure) {
|
|
40
68
|
observeBreak(failure, callTags, check);
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import type { SchemaAdapter } from '../structs/common.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Detach a schema adapter into a frozen, synchronous definition.
|
|
4
|
+
*
|
|
5
|
+
* The JSON schema is cloned and deep-frozen; the parser is bound to the original
|
|
6
|
+
* definition so a method keeps its receiver, then wrapped so a thenable result is
|
|
7
|
+
* rejected rather than awaited.
|
|
8
|
+
*
|
|
9
|
+
* @param definition - Adapter to snapshot.
|
|
10
|
+
* @param asyncError - Message used when the parser returns a thenable.
|
|
11
|
+
* @returns A frozen adapter with a cloned schema and a synchronous parser.
|
|
12
|
+
* @throws TypeError When `jsonSchema` is missing or not a plain object.
|
|
13
|
+
*/
|
|
3
14
|
export declare function snapshotSchemaAdapter<Value>(definition: SchemaAdapter<Value>, asyncError?: string): SchemaAdapter<Value>;
|
|
@@ -1,6 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapshot helper for registered schema adapters.
|
|
3
|
+
*
|
|
4
|
+
* An adapter owns a JSON schema and a parser. Both must be detached from the App object
|
|
5
|
+
* that supplied them, both must be immutable afterwards, and the parser must stay
|
|
6
|
+
* synchronous, because schema snapshots are reused across requests and diagnostics.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `snapshotSchemaAdapter`.
|
|
9
|
+
*/
|
|
1
10
|
import { freezeSchema } from './object.js';
|
|
2
11
|
import { synchronous } from './synchronous.js';
|
|
3
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Detach a schema adapter into a frozen, synchronous definition.
|
|
14
|
+
*
|
|
15
|
+
* The JSON schema is cloned and deep-frozen; the parser is bound to the original
|
|
16
|
+
* definition so a method keeps its receiver, then wrapped so a thenable result is
|
|
17
|
+
* rejected rather than awaited.
|
|
18
|
+
*
|
|
19
|
+
* @param definition - Adapter to snapshot.
|
|
20
|
+
* @param asyncError - Message used when the parser returns a thenable.
|
|
21
|
+
* @returns A frozen adapter with a cloned schema and a synchronous parser.
|
|
22
|
+
* @throws TypeError When `jsonSchema` is missing or not a plain object.
|
|
23
|
+
*/
|
|
4
24
|
export function snapshotSchemaAdapter(definition, asyncError = 'Schema parsers must be synchronous') {
|
|
5
25
|
const { jsonSchema } = definition;
|
|
6
26
|
if (!jsonSchema || typeof jsonSchema !== 'object' || Array.isArray(jsonSchema)) {
|
|
@@ -9,5 +29,8 @@ export function snapshotSchemaAdapter(definition, asyncError = 'Schema parsers m
|
|
|
9
29
|
const snapshot = structuredClone(jsonSchema);
|
|
10
30
|
freezeSchema(snapshot);
|
|
11
31
|
const parse = definition.parse.bind(definition);
|
|
12
|
-
return Object.freeze({
|
|
32
|
+
return Object.freeze({
|
|
33
|
+
jsonSchema: snapshot,
|
|
34
|
+
parse: (input) => synchronous(parse(input), asyncError),
|
|
35
|
+
});
|
|
13
36
|
}
|
|
@@ -1,9 +1,65 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Guards for contracts that require synchronous participants.
|
|
3
|
+
*
|
|
4
|
+
* Handlers, predicates and parsers are declared synchronous by contract. Detecting an
|
|
5
|
+
* accidental async implementation early is cheaper than debugging an interleaved
|
|
6
|
+
* execution, so every such call site passes its result through these helpers.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `isPromiseLike`, `synchronous`, `assertion`, `maybeAssertion` and
|
|
9
|
+
* `booleanResult`.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Test for a thenable without invoking it.
|
|
13
|
+
*
|
|
14
|
+
* @param value - Candidate value.
|
|
15
|
+
* @returns True when the value carries a callable `then`.
|
|
16
|
+
*/
|
|
2
17
|
export declare function isPromiseLike(value: unknown): value is PromiseLike<unknown>;
|
|
3
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Reject an accidentally asynchronous callback.
|
|
20
|
+
*
|
|
21
|
+
* A thenable is consumed before throwing so its eventual rejection cannot surface as an
|
|
22
|
+
* unhandled rejection. Any side effects the callback already started cannot be undone.
|
|
23
|
+
*
|
|
24
|
+
* @param value - Result of the callback.
|
|
25
|
+
* @param message - Message for the TypeError raised when the result is thenable.
|
|
26
|
+
* @returns The same value, narrowed to a non-thenable.
|
|
27
|
+
* @throws TypeError When the value is a thenable.
|
|
28
|
+
*/
|
|
4
29
|
export declare function synchronous<Value>(value: Value, message: string): Value;
|
|
5
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Require an assertion hook to finish with `undefined`.
|
|
32
|
+
*
|
|
33
|
+
* Returning a boolean is a common mistake that would silently pass; requiring `void`
|
|
34
|
+
* makes a discarded decision fail loudly.
|
|
35
|
+
*
|
|
36
|
+
* @param value - Result of the assertion hook.
|
|
37
|
+
* @param message - Message for the TypeError.
|
|
38
|
+
* @throws TypeError When the result is thenable or not `undefined`.
|
|
39
|
+
*/
|
|
6
40
|
export declare function assertion(value: unknown, message: string): void;
|
|
7
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Accept a synchronous assertion or await an actually asynchronous one.
|
|
43
|
+
*
|
|
44
|
+
* Only a thenable is awaited; synchronous results are validated immediately so callers
|
|
45
|
+
* that rely on ordering do not yield to the event loop unnecessarily.
|
|
46
|
+
*
|
|
47
|
+
* @param value - Result of the assertion hook.
|
|
48
|
+
* @param message - Message for the TypeError.
|
|
49
|
+
* @returns Nothing, or a promise resolved once the awaited assertion passed.
|
|
50
|
+
* @throws TypeError When the hook does not finish with `undefined`.
|
|
51
|
+
*/
|
|
8
52
|
export declare function maybeAssertion(value: unknown, message: string): void | Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Require a synchronous boolean decision.
|
|
55
|
+
*
|
|
56
|
+
* Truthiness is not accepted: routing must receive an explicit `true` or `false` so a
|
|
57
|
+
* predicate that forgets to return a value is reported instead of silently skipping.
|
|
58
|
+
*
|
|
59
|
+
* @param value - Result of the predicate.
|
|
60
|
+
* @param message - Message for the thenable TypeError.
|
|
61
|
+
* @param invalidMessage - Message for the non-boolean TypeError; defaults to `message`.
|
|
62
|
+
* @returns The validated boolean.
|
|
63
|
+
* @throws TypeError When the result is thenable or not boolean.
|
|
64
|
+
*/
|
|
9
65
|
export declare function booleanResult(value: unknown, message: string, invalidMessage?: string): boolean;
|
|
@@ -1,9 +1,35 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Guards for contracts that require synchronous participants.
|
|
3
|
+
*
|
|
4
|
+
* Handlers, predicates and parsers are declared synchronous by contract. Detecting an
|
|
5
|
+
* accidental async implementation early is cheaper than debugging an interleaved
|
|
6
|
+
* execution, so every such call site passes its result through these helpers.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `isPromiseLike`, `synchronous`, `assertion`, `maybeAssertion` and
|
|
9
|
+
* `booleanResult`.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Test for a thenable without invoking it.
|
|
13
|
+
*
|
|
14
|
+
* @param value - Candidate value.
|
|
15
|
+
* @returns True when the value carries a callable `then`.
|
|
16
|
+
*/
|
|
2
17
|
export function isPromiseLike(value) {
|
|
3
|
-
return value !== null &&
|
|
4
|
-
|
|
18
|
+
return (value !== null &&
|
|
19
|
+
(typeof value === 'object' || typeof value === 'function') &&
|
|
20
|
+
typeof value.then === 'function');
|
|
5
21
|
}
|
|
6
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Reject an accidentally asynchronous callback.
|
|
24
|
+
*
|
|
25
|
+
* A thenable is consumed before throwing so its eventual rejection cannot surface as an
|
|
26
|
+
* unhandled rejection. Any side effects the callback already started cannot be undone.
|
|
27
|
+
*
|
|
28
|
+
* @param value - Result of the callback.
|
|
29
|
+
* @param message - Message for the TypeError raised when the result is thenable.
|
|
30
|
+
* @returns The same value, narrowed to a non-thenable.
|
|
31
|
+
* @throws TypeError When the value is a thenable.
|
|
32
|
+
*/
|
|
7
33
|
export function synchronous(value, message) {
|
|
8
34
|
if (isPromiseLike(value)) {
|
|
9
35
|
void Promise.resolve(value).catch(() => { });
|
|
@@ -11,17 +37,48 @@ export function synchronous(value, message) {
|
|
|
11
37
|
}
|
|
12
38
|
return value;
|
|
13
39
|
}
|
|
14
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Require an assertion hook to finish with `undefined`.
|
|
42
|
+
*
|
|
43
|
+
* Returning a boolean is a common mistake that would silently pass; requiring `void`
|
|
44
|
+
* makes a discarded decision fail loudly.
|
|
45
|
+
*
|
|
46
|
+
* @param value - Result of the assertion hook.
|
|
47
|
+
* @param message - Message for the TypeError.
|
|
48
|
+
* @throws TypeError When the result is thenable or not `undefined`.
|
|
49
|
+
*/
|
|
15
50
|
export function assertion(value, message) {
|
|
16
51
|
if (synchronous(value, message) !== undefined)
|
|
17
52
|
throw new TypeError(message);
|
|
18
53
|
}
|
|
19
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* Accept a synchronous assertion or await an actually asynchronous one.
|
|
56
|
+
*
|
|
57
|
+
* Only a thenable is awaited; synchronous results are validated immediately so callers
|
|
58
|
+
* that rely on ordering do not yield to the event loop unnecessarily.
|
|
59
|
+
*
|
|
60
|
+
* @param value - Result of the assertion hook.
|
|
61
|
+
* @param message - Message for the TypeError.
|
|
62
|
+
* @returns Nothing, or a promise resolved once the awaited assertion passed.
|
|
63
|
+
* @throws TypeError When the hook does not finish with `undefined`.
|
|
64
|
+
*/
|
|
20
65
|
export function maybeAssertion(value, message) {
|
|
21
66
|
if (isPromiseLike(value))
|
|
22
|
-
return Promise.resolve(value).then(result => assertion(result, message));
|
|
67
|
+
return Promise.resolve(value).then((result) => assertion(result, message));
|
|
23
68
|
assertion(value, message);
|
|
24
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Require a synchronous boolean decision.
|
|
72
|
+
*
|
|
73
|
+
* Truthiness is not accepted: routing must receive an explicit `true` or `false` so a
|
|
74
|
+
* predicate that forgets to return a value is reported instead of silently skipping.
|
|
75
|
+
*
|
|
76
|
+
* @param value - Result of the predicate.
|
|
77
|
+
* @param message - Message for the thenable TypeError.
|
|
78
|
+
* @param invalidMessage - Message for the non-boolean TypeError; defaults to `message`.
|
|
79
|
+
* @returns The validated boolean.
|
|
80
|
+
* @throws TypeError When the result is thenable or not boolean.
|
|
81
|
+
*/
|
|
25
82
|
export function booleanResult(value, message, invalidMessage = message) {
|
|
26
83
|
const result = synchronous(value, message);
|
|
27
84
|
if (typeof result !== 'boolean')
|
package/dist/esm/utils/text.d.ts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Small string helpers used for prompt accounting.
|
|
3
|
+
*
|
|
4
|
+
* Exports: `commonPrefixLength`.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Length of the longest common prefix of two strings.
|
|
8
|
+
*
|
|
9
|
+
* Implemented as a binary search over slice comparisons so long prompts stay on the
|
|
10
|
+
* native string comparison path instead of running a JavaScript character loop.
|
|
11
|
+
*
|
|
12
|
+
* @param left - First string.
|
|
13
|
+
* @param right - Second string.
|
|
14
|
+
* @returns Number of leading characters both strings share, bounded by the shorter length.
|
|
15
|
+
*/
|
|
2
16
|
export declare function commonPrefixLength(left: string, right: string): number;
|
package/dist/esm/utils/text.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Small string helpers used for prompt accounting.
|
|
3
|
+
*
|
|
4
|
+
* Exports: `commonPrefixLength`.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Length of the longest common prefix of two strings.
|
|
8
|
+
*
|
|
9
|
+
* Implemented as a binary search over slice comparisons so long prompts stay on the
|
|
10
|
+
* native string comparison path instead of running a JavaScript character loop.
|
|
11
|
+
*
|
|
12
|
+
* @param left - First string.
|
|
13
|
+
* @param right - Second string.
|
|
14
|
+
* @returns Number of leading characters both strings share, bounded by the shorter length.
|
|
15
|
+
*/
|
|
2
16
|
export function commonPrefixLength(left, right) {
|
|
3
17
|
let low = 0;
|
|
4
18
|
let high = Math.min(left.length, right.length);
|