@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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createToolCallCollector } from './calls.js';
|
|
2
|
+
/** Read the specific-function form: `{ type: 'function', function: { name } }`. */
|
|
3
|
+
function namedTool(choice) {
|
|
4
|
+
if (!choice || typeof choice !== 'object' || Array.isArray(choice))
|
|
5
|
+
return undefined;
|
|
6
|
+
const value = choice;
|
|
7
|
+
if (value.type !== 'function')
|
|
8
|
+
return undefined;
|
|
9
|
+
const fn = value.function;
|
|
10
|
+
if (!fn || typeof fn !== 'object' || Array.isArray(fn))
|
|
11
|
+
return undefined;
|
|
12
|
+
const name = fn.name;
|
|
13
|
+
return typeof name === 'string' && name ? name : undefined;
|
|
14
|
+
}
|
|
15
|
+
const policy = {
|
|
16
|
+
id: 'session',
|
|
17
|
+
begin(facts, fail) {
|
|
18
|
+
const choice = facts.toolChoice;
|
|
19
|
+
let mode;
|
|
20
|
+
let named;
|
|
21
|
+
if (choice === undefined)
|
|
22
|
+
mode = 'inherit';
|
|
23
|
+
else if (choice === 'auto' || choice === 'required' || choice === 'none')
|
|
24
|
+
mode = choice;
|
|
25
|
+
else {
|
|
26
|
+
named = namedTool(choice);
|
|
27
|
+
if (!named)
|
|
28
|
+
throw fail('MODEL_CONFIG');
|
|
29
|
+
mode = 'named';
|
|
30
|
+
}
|
|
31
|
+
const collector = createToolCallCollector(() => {
|
|
32
|
+
throw fail('MODEL_PROTOCOL');
|
|
33
|
+
});
|
|
34
|
+
let finished = false;
|
|
35
|
+
let hasText = false;
|
|
36
|
+
let hasCall = false;
|
|
37
|
+
const textSatisfied = () => hasText || facts.allowEmptyText;
|
|
38
|
+
const calls = () => {
|
|
39
|
+
const completed = collector.complete();
|
|
40
|
+
if (!completed.length)
|
|
41
|
+
throw fail('MODEL_INCOMPLETE');
|
|
42
|
+
if (named && completed.some((call) => call.name !== named))
|
|
43
|
+
throw fail('MODEL_PROTOCOL');
|
|
44
|
+
return completed;
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
part(part) {
|
|
48
|
+
if (typeof part === 'string') {
|
|
49
|
+
hasText = true;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
hasCall = true;
|
|
53
|
+
if (mode === 'none')
|
|
54
|
+
throw fail('MODEL_PROTOCOL');
|
|
55
|
+
if (mode === 'inherit' && !facts.functions)
|
|
56
|
+
throw fail('MODEL_PROTOCOL');
|
|
57
|
+
collector.push(part);
|
|
58
|
+
},
|
|
59
|
+
finish(reason) {
|
|
60
|
+
if (mode === 'inherit') {
|
|
61
|
+
if (reason !== (facts.functions ? 'tool_calls' : 'stop'))
|
|
62
|
+
throw fail(reason === 'length' ? 'MODEL_OUTPUT_LIMIT' : 'MODEL_INCOMPLETE');
|
|
63
|
+
finished = true;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (reason === 'length')
|
|
67
|
+
throw fail('MODEL_OUTPUT_LIMIT');
|
|
68
|
+
if (mode === 'none') {
|
|
69
|
+
if (reason !== 'stop' || !textSatisfied())
|
|
70
|
+
throw fail('MODEL_INCOMPLETE');
|
|
71
|
+
}
|
|
72
|
+
else if (mode === 'auto') {
|
|
73
|
+
if (reason === 'tool_calls')
|
|
74
|
+
calls();
|
|
75
|
+
else if (reason === 'stop') {
|
|
76
|
+
if (hasCall)
|
|
77
|
+
throw fail('MODEL_PROTOCOL');
|
|
78
|
+
if (!textSatisfied())
|
|
79
|
+
throw fail('MODEL_INCOMPLETE');
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
throw fail('MODEL_INCOMPLETE');
|
|
83
|
+
}
|
|
84
|
+
else if (reason === 'tool_calls')
|
|
85
|
+
calls();
|
|
86
|
+
else
|
|
87
|
+
throw fail('MODEL_INCOMPLETE');
|
|
88
|
+
finished = true;
|
|
89
|
+
},
|
|
90
|
+
end() {
|
|
91
|
+
if (!finished)
|
|
92
|
+
throw fail('MODEL_INCOMPLETE');
|
|
93
|
+
if (mode === 'inherit' && (facts.functions ? !hasCall : !textSatisfied()))
|
|
94
|
+
throw fail('MODEL_INCOMPLETE');
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
export const sessionCompletionPolicy = Object.freeze(policy);
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model support: recommended transports, providers and strategies for Core model calls.
|
|
3
|
+
*
|
|
4
|
+
* Applications compose these implementations and hand them to a Core `ModelRunner`. This module
|
|
5
|
+
* owns wire adaptation and local admission budgets only; credentials, HTTP hosting and business
|
|
6
|
+
* policy stay with the application, and Core does not import this code.
|
|
7
|
+
*
|
|
8
|
+
* Main exports: transport creators, `CompatibleModelProvider`, stage transport projection,
|
|
9
|
+
* capability/interaction catalogs, child-task execution, reply preview helpers, provider
|
|
10
|
+
* observation scopes and `createModelStrategy` with its budget presets.
|
|
11
|
+
*/
|
|
1
12
|
export * from './transports.js';
|
|
2
13
|
export * from './compatible-provider.js';
|
|
14
|
+
export * from './completion/index.js';
|
|
3
15
|
export * from './interactions/index.js';
|
|
4
16
|
export * from './chat-completions.js';
|
|
17
|
+
export type * from '../../structs/support/model/completion.js';
|
|
18
|
+
export type * from '../../structs/support/model/messages.js';
|
|
5
19
|
export type * from '../../structs/support/model/interactions.js';
|
|
6
20
|
export type * from '../../structs/support/model/provider.js';
|
|
7
21
|
export * from './capabilities.js';
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model support: recommended transports, providers and strategies for Core model calls.
|
|
3
|
+
*
|
|
4
|
+
* Applications compose these implementations and hand them to a Core `ModelRunner`. This module
|
|
5
|
+
* owns wire adaptation and local admission budgets only; credentials, HTTP hosting and business
|
|
6
|
+
* policy stay with the application, and Core does not import this code.
|
|
7
|
+
*
|
|
8
|
+
* Main exports: transport creators, `CompatibleModelProvider`, stage transport projection,
|
|
9
|
+
* capability/interaction catalogs, child-task execution, reply preview helpers, provider
|
|
10
|
+
* observation scopes and `createModelStrategy` with its budget presets.
|
|
11
|
+
*/
|
|
1
12
|
export * from './transports.js';
|
|
2
13
|
export * from './compatible-provider.js';
|
|
14
|
+
export * from './completion/index.js';
|
|
3
15
|
export * from './interactions/index.js';
|
|
4
16
|
export * from './chat-completions.js';
|
|
5
17
|
export * from './capabilities.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { nativeFunctionInteraction } from './native-functions.js';
|
|
2
2
|
export { jsonObjectInteraction } from './json-object.js';
|
|
3
|
-
export type { ModelResponseCollector, PreparedModelInteraction } from '../../../structs/model/interactions.js';
|
|
3
|
+
export type { ModelResponseCollector, PreparedModelInteraction, } from '../../../structs/model/interactions.js';
|
|
4
4
|
export type { ModelInteractionAdapter } from '../../../structs/support/model/interactions.js';
|
|
5
5
|
/** Registered adapters selected only from explicit App capability metadata. */
|
|
6
6
|
export declare const modelInteractionCatalog: Readonly<{
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model interaction catalog: adapters that convert model output into Core model parts.
|
|
3
|
+
*
|
|
4
|
+
* Adapters are selected only from explicit application capability metadata, never inferred from
|
|
5
|
+
* arbitrary text. Each adapter is registered under the same ID it reports, and the catalog is
|
|
6
|
+
* frozen so later imports cannot widen the available interactions.
|
|
7
|
+
*
|
|
8
|
+
* Main exports: `modelInteractionCatalog`, the two adapter re-exports and their contract types.
|
|
9
|
+
*/
|
|
1
10
|
import { nativeFunctionInteraction } from './native-functions.js';
|
|
2
11
|
import { jsonObjectInteraction } from './json-object.js';
|
|
3
12
|
import { breakWhile } from '../../../utils/rules.js';
|
|
@@ -5,7 +14,9 @@ export { nativeFunctionInteraction } from './native-functions.js';
|
|
|
5
14
|
export { jsonObjectInteraction } from './json-object.js';
|
|
6
15
|
/** Registered adapters selected only from explicit App capability metadata. */
|
|
7
16
|
export const modelInteractionCatalog = Object.freeze({
|
|
8
|
-
'native-functions': nativeFunctionInteraction,
|
|
17
|
+
'native-functions': nativeFunctionInteraction,
|
|
18
|
+
'json-object': jsonObjectInteraction,
|
|
9
19
|
});
|
|
20
|
+
// Fail at module load rather than let a mismatched key register an adapter under a false ID.
|
|
10
21
|
for (const [id, adapter] of Object.entries(modelInteractionCatalog))
|
|
11
22
|
breakWhile(id !== adapter.id, 'Model interaction ID does not match its registered adapter');
|
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export barrel: the JSON-object model interaction adapter.
|
|
3
|
+
*
|
|
4
|
+
* Applications reference it through the Support interaction catalog; the implementation lives in
|
|
5
|
+
* the Core model layer and is not duplicated here.
|
|
6
|
+
*/
|
|
1
7
|
export { jsonObjectInteraction } from '../../../model/interactions/json-object.js';
|
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export barrel: the JSON-object model interaction adapter.
|
|
3
|
+
*
|
|
4
|
+
* Applications reference it through the Support interaction catalog; the implementation lives in
|
|
5
|
+
* the Core model layer and is not duplicated here.
|
|
6
|
+
*/
|
|
1
7
|
export { jsonObjectInteraction } from '../../../model/interactions/json-object.js';
|
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export barrel: the native-function-call model interaction adapter.
|
|
3
|
+
*
|
|
4
|
+
* Applications reference it through the Support interaction catalog; the implementation lives in
|
|
5
|
+
* the Core model layer and is not duplicated here.
|
|
6
|
+
*/
|
|
1
7
|
export { nativeFunctionInteraction } from '../../../model/interactions/native-functions.js';
|
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export barrel: the native-function-call model interaction adapter.
|
|
3
|
+
*
|
|
4
|
+
* Applications reference it through the Support interaction catalog; the implementation lives in
|
|
5
|
+
* the Core model layer and is not duplicated here.
|
|
6
|
+
*/
|
|
1
7
|
export { nativeFunctionInteraction } from '../../../model/interactions/native-functions.js';
|
|
@@ -1,11 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider observation support: optional, caller-owned logging around provider calls.
|
|
3
|
+
*
|
|
4
|
+
* Observations are best effort and silent: an absent or throwing observer never changes provider
|
|
5
|
+
* results, cancellation or retry behavior. Payloads are built lazily, so disabled events cost
|
|
6
|
+
* nothing, and body capture only happens when explicitly accepted.
|
|
7
|
+
*
|
|
8
|
+
* Main exports: `providerObservation` and `createProviderObservationScope`.
|
|
9
|
+
*/
|
|
1
10
|
import type { ModelProviderContext } from '../../structs/model/chat-provider.js';
|
|
2
11
|
import type { ProviderEventName, ProviderEventPayloads, ProviderObservation, ProviderObserver } from '../../structs/support/model/provider-observer.js';
|
|
3
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Create the emit/enabled pair used inside the provider.
|
|
14
|
+
*
|
|
15
|
+
* @param observer Caller-owned observer; when absent, every event is disabled.
|
|
16
|
+
* @param options Provider context passed to the observer's acceptance check.
|
|
17
|
+
* @returns `enabled(event)` and `emit(event, payload)`; both never throw.
|
|
18
|
+
*/
|
|
4
19
|
export declare function providerObservation(observer: ProviderObserver | undefined, options: ModelProviderContext): {
|
|
5
20
|
enabled: (event: ProviderEventName) => boolean;
|
|
6
21
|
emit<K extends ProviderEventName>(event: K, payload: () => ProviderEventPayloads[K]): void;
|
|
7
22
|
};
|
|
8
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Bind provider observations to a caller-owned destination across diagnostic child spans.
|
|
25
|
+
*
|
|
26
|
+
* `attach` returns a scoped diagnostic context; contexts that were not attached through this scope
|
|
27
|
+
* produce no observations. Child contexts inherit the owner and a `parent/child` span path.
|
|
28
|
+
*
|
|
29
|
+
* @param sink Destination implementing optional `accepts` and required `write`.
|
|
30
|
+
* @returns A frozen `{ attach, observer }` pair to install on a provider.
|
|
31
|
+
*/
|
|
9
32
|
export declare function createProviderObservationScope<Owner>(sink: {
|
|
10
33
|
accepts?(owner: Owner, descriptor: import('../../structs/support/model/provider-observer.js').ProviderEventDescriptor): boolean;
|
|
11
34
|
write(owner: Owner, observation: ProviderObservation, spanId: string, content: 'metadata' | 'content'): void | Promise<void>;
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classify each provider event.
|
|
3
|
+
*
|
|
4
|
+
* `content` events may contain prompt or response data and need explicit acceptance; `metadata`
|
|
5
|
+
* events only describe the call.
|
|
6
|
+
*/
|
|
1
7
|
const events = {
|
|
2
|
-
'provider.request': 'content',
|
|
3
|
-
'provider.
|
|
8
|
+
'provider.request': 'content',
|
|
9
|
+
'provider.response': 'metadata',
|
|
10
|
+
'provider.frame': 'content',
|
|
11
|
+
'provider.error-body': 'content',
|
|
12
|
+
'provider.end': 'metadata',
|
|
4
13
|
};
|
|
5
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Create the emit/enabled pair used inside the provider.
|
|
16
|
+
*
|
|
17
|
+
* @param observer Caller-owned observer; when absent, every event is disabled.
|
|
18
|
+
* @param options Provider context passed to the observer's acceptance check.
|
|
19
|
+
* @returns `enabled(event)` and `emit(event, payload)`; both never throw.
|
|
20
|
+
*/
|
|
6
21
|
export function providerObservation(observer, options) {
|
|
7
22
|
const enabled = (event) => {
|
|
8
23
|
if (!observer || !Object.hasOwn(events, event))
|
|
@@ -24,11 +39,21 @@ export function providerObservation(observer, options) {
|
|
|
24
39
|
if (pending)
|
|
25
40
|
void Promise.resolve(pending).catch(() => { });
|
|
26
41
|
}
|
|
27
|
-
catch {
|
|
42
|
+
catch {
|
|
43
|
+
/* Observation cannot change provider results, cancellation or retry behavior. */
|
|
44
|
+
}
|
|
28
45
|
},
|
|
29
46
|
};
|
|
30
47
|
}
|
|
31
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Bind provider observations to a caller-owned destination across diagnostic child spans.
|
|
50
|
+
*
|
|
51
|
+
* `attach` returns a scoped diagnostic context; contexts that were not attached through this scope
|
|
52
|
+
* produce no observations. Child contexts inherit the owner and a `parent/child` span path.
|
|
53
|
+
*
|
|
54
|
+
* @param sink Destination implementing optional `accepts` and required `write`.
|
|
55
|
+
* @returns A frozen `{ attach, observer }` pair to install on a provider.
|
|
56
|
+
*/
|
|
32
57
|
export function createProviderObservationScope(sink) {
|
|
33
58
|
const owners = new WeakMap();
|
|
34
59
|
const accepts = sink.accepts?.bind(sink);
|
|
@@ -40,8 +65,9 @@ export function createProviderObservationScope(sink) {
|
|
|
40
65
|
emit: context.emit.bind(context),
|
|
41
66
|
deliver: context.deliver.bind(context),
|
|
42
67
|
child: (id, fields) => attach(context.child(id, fields), owner, `${spanId}/${id}`),
|
|
43
|
-
withObserver: observer => attach(context.withObserver(observer), owner, spanId),
|
|
68
|
+
withObserver: (observer) => attach(context.withObserver(observer), owner, spanId),
|
|
44
69
|
};
|
|
70
|
+
// Prefer the real span identity so the log matches diagnostics rather than the local label.
|
|
45
71
|
owners.set(scoped, { owner, spanId: context.identity?.spanId ?? spanId });
|
|
46
72
|
return scoped;
|
|
47
73
|
}
|
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
import type { JsonSchema } from '../../structs/common.js';
|
|
2
2
|
import type { ReplyPreviewRule } from './reply-preview.js';
|
|
3
3
|
export interface ReplyPreviewCapability {
|
|
4
|
+
/** Capability ID, which must equal the native function wire name used for transport. */
|
|
4
5
|
readonly id: string;
|
|
6
|
+
/** Input schema used to prove that preview and eligibility paths really exist. */
|
|
5
7
|
readonly jsonSchema: JsonSchema;
|
|
6
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Explicit preview opt-in: `true` uses the default text/bubble paths, an object narrows the
|
|
10
|
+
* paths and eligibility, and omission means the capability never previews.
|
|
11
|
+
*/
|
|
7
12
|
readonly preview?: true | Omit<ReplyPreviewRule, 'stageId' | 'capabilityId'>;
|
|
8
13
|
}
|
|
9
14
|
export interface ReplyPreviewStage {
|
|
15
|
+
/** Stage ID used by the workflow and transport projection. */
|
|
10
16
|
readonly id: string;
|
|
17
|
+
/** Capabilities exposed at this stage; must be unique and registered. */
|
|
11
18
|
readonly capabilityIds?: readonly string[];
|
|
19
|
+
/** `text` previews plain model text; `capabilities` previews opted-in capability arguments. */
|
|
12
20
|
readonly preview?: 'text' | 'capabilities';
|
|
13
21
|
}
|
|
14
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Generate frozen preview rules from capability and stage declarations.
|
|
24
|
+
*
|
|
25
|
+
* Capabilities without preview metadata are skipped even when their stage opts in. Default paths
|
|
26
|
+
* are `text` and `bubbles[*]`, each kept only when the capability schema declares it.
|
|
27
|
+
*
|
|
28
|
+
* @param options Stage declarations and the capabilities they may reference.
|
|
29
|
+
* @returns Frozen rules in stage order, each with deep-frozen paths and eligibility.
|
|
30
|
+
* @throws {Error} When a capability or stage ID repeats, a stage references an unknown capability,
|
|
31
|
+
* a preview mode is unknown, or a preview path or eligibility field is absent from the schema.
|
|
32
|
+
*/
|
|
15
33
|
export declare function createReplyPreviewRules(options: {
|
|
16
34
|
readonly stages: readonly ReplyPreviewStage[];
|
|
17
35
|
readonly capabilities: readonly ReplyPreviewCapability[];
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reply preview rule generation from capability and stage declarations.
|
|
3
|
+
*
|
|
4
|
+
* Previews are presentation only: rules are derived from the same capability schemas and stage
|
|
5
|
+
* references used for transport, so a capability cannot preview a field it does not accept.
|
|
6
|
+
* Declarations are snapshotted; application objects are never frozen or mutated.
|
|
7
|
+
*
|
|
8
|
+
* Main exports: `createReplyPreviewRules` and the capability/stage declaration types.
|
|
9
|
+
*/
|
|
1
10
|
import { breakWhile } from '../../utils/rules.js';
|
|
2
11
|
import { wireName } from '../../model/interactions/arguments.js';
|
|
12
|
+
/**
|
|
13
|
+
* Check whether a schema path exists, following local `$ref`, composition keywords and `items`.
|
|
14
|
+
*
|
|
15
|
+
* Rules are only emitted for declared fields, so a renamed or removed field fails generation
|
|
16
|
+
* instead of silently producing an empty preview.
|
|
17
|
+
*/
|
|
3
18
|
function fieldExists(root, path) {
|
|
4
19
|
const visit = (schema, remaining, depth) => {
|
|
5
20
|
if (!schema || typeof schema !== 'object' || depth > 64)
|
|
@@ -8,20 +23,33 @@ function fieldExists(root, path) {
|
|
|
8
23
|
return true;
|
|
9
24
|
const current = schema;
|
|
10
25
|
if (typeof current.$ref === 'string' && current.$ref.startsWith('#/')) {
|
|
11
|
-
const target = current.$ref
|
|
12
|
-
|
|
26
|
+
const target = current.$ref
|
|
27
|
+
.slice(2)
|
|
28
|
+
.split('/')
|
|
29
|
+
.reduce((value, part) => value && typeof value === 'object'
|
|
30
|
+
? (() => {
|
|
31
|
+
const key = part.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
32
|
+
return Object.hasOwn(value, key)
|
|
33
|
+
? value[key]
|
|
34
|
+
: undefined;
|
|
35
|
+
})()
|
|
36
|
+
: undefined, root);
|
|
13
37
|
if (visit(target, remaining, depth + 1))
|
|
14
38
|
return true;
|
|
15
39
|
}
|
|
16
40
|
for (const keyword of ['anyOf', 'oneOf', 'allOf']) {
|
|
17
41
|
const alternatives = current[keyword];
|
|
18
|
-
if (Array.isArray(alternatives) &&
|
|
42
|
+
if (Array.isArray(alternatives) &&
|
|
43
|
+
alternatives.some((value) => visit(value, remaining, depth + 1)))
|
|
19
44
|
return true;
|
|
20
45
|
}
|
|
21
46
|
const [key, ...rest] = remaining;
|
|
22
47
|
const properties = current.properties;
|
|
23
|
-
if (key !== '*' &&
|
|
24
|
-
|
|
48
|
+
if (key !== '*' &&
|
|
49
|
+
properties &&
|
|
50
|
+
typeof properties === 'object' &&
|
|
51
|
+
Object.hasOwn(properties, key) &&
|
|
52
|
+
visit(properties[key], rest, depth + 1))
|
|
25
53
|
return true;
|
|
26
54
|
return (key === '*' || /^\d+$/.test(key)) && visit(current.items, rest, depth + 1);
|
|
27
55
|
};
|
|
@@ -30,18 +58,33 @@ function fieldExists(root, path) {
|
|
|
30
58
|
function stringList(value, label) {
|
|
31
59
|
breakWhile(!Array.isArray(value), `Invalid preview ${label}`);
|
|
32
60
|
const snapshot = Array.from(value);
|
|
33
|
-
breakWhile(snapshot.some(item => typeof item !== 'string'), `Invalid preview ${label}`);
|
|
61
|
+
breakWhile(snapshot.some((item) => typeof item !== 'string'), `Invalid preview ${label}`);
|
|
34
62
|
return snapshot;
|
|
35
63
|
}
|
|
36
64
|
function previewSnapshot(preview) {
|
|
37
65
|
if (!preview || preview === true)
|
|
38
66
|
return preview || undefined;
|
|
39
67
|
const { paths, when } = preview;
|
|
40
|
-
const pathSnapshot = paths === undefined ? undefined : Array.from(paths, path => stringList(path, 'path'));
|
|
41
|
-
const eligibility = when === undefined
|
|
68
|
+
const pathSnapshot = paths === undefined ? undefined : Array.from(paths, (path) => stringList(path, 'path'));
|
|
69
|
+
const eligibility = when === undefined
|
|
70
|
+
? undefined
|
|
71
|
+
: {
|
|
72
|
+
path: stringList(when.path, 'eligibility path'),
|
|
73
|
+
values: stringList(when.values, 'eligibility values'),
|
|
74
|
+
};
|
|
42
75
|
return { paths: pathSnapshot, when: eligibility };
|
|
43
76
|
}
|
|
44
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* Generate frozen preview rules from capability and stage declarations.
|
|
79
|
+
*
|
|
80
|
+
* Capabilities without preview metadata are skipped even when their stage opts in. Default paths
|
|
81
|
+
* are `text` and `bubbles[*]`, each kept only when the capability schema declares it.
|
|
82
|
+
*
|
|
83
|
+
* @param options Stage declarations and the capabilities they may reference.
|
|
84
|
+
* @returns Frozen rules in stage order, each with deep-frozen paths and eligibility.
|
|
85
|
+
* @throws {Error} When a capability or stage ID repeats, a stage references an unknown capability,
|
|
86
|
+
* a preview mode is unknown, or a preview path or eligibility field is absent from the schema.
|
|
87
|
+
*/
|
|
45
88
|
export function createReplyPreviewRules(options) {
|
|
46
89
|
const capabilities = new Map();
|
|
47
90
|
for (const capability of options.capabilities) {
|
|
@@ -58,7 +101,7 @@ export function createReplyPreviewRules(options) {
|
|
|
58
101
|
breakWhile(!stageId || stages.has(stageId), 'Duplicate preview stage declaration');
|
|
59
102
|
stages.add(stageId);
|
|
60
103
|
const ids = capabilityIds === undefined ? [] : stringList(capabilityIds, 'capability IDs');
|
|
61
|
-
breakWhile(new Set(ids).size !== ids.length || ids.some(id => !capabilities.has(id)), 'Preview stage references an unknown capability');
|
|
104
|
+
breakWhile(new Set(ids).size !== ids.length || ids.some((id) => !capabilities.has(id)), 'Preview stage references an unknown capability');
|
|
62
105
|
breakWhile(preview !== undefined && !['text', 'capabilities'].includes(preview), 'Unknown preview stage mode');
|
|
63
106
|
if (!preview)
|
|
64
107
|
continue;
|
|
@@ -73,14 +116,21 @@ export function createReplyPreviewRules(options) {
|
|
|
73
116
|
continue;
|
|
74
117
|
const source = capability.preview === true ? {} : capability.preview;
|
|
75
118
|
const { paths, when } = source;
|
|
76
|
-
const checkedPaths = paths ??
|
|
77
|
-
|
|
119
|
+
const checkedPaths = paths ??
|
|
120
|
+
[['text'], ['bubbles', '*']].filter((path) => fieldExists(capability.jsonSchema, path));
|
|
121
|
+
breakWhile(!checkedPaths.length ||
|
|
122
|
+
checkedPaths.some((path) => !fieldExists(capability.jsonSchema, path)), `Invalid preview field: ${id}`);
|
|
78
123
|
breakWhile(!!when && !fieldExists(capability.jsonSchema, when.path), `Invalid preview eligibility field: ${id}`);
|
|
79
124
|
// Only generator-owned snapshots are frozen; App declarations remain untouched.
|
|
80
|
-
const emittedPaths = Object.freeze(checkedPaths.map(path => Object.freeze(path)));
|
|
81
|
-
const emittedWhen = when &&
|
|
82
|
-
|
|
83
|
-
|
|
125
|
+
const emittedPaths = Object.freeze(checkedPaths.map((path) => Object.freeze(path)));
|
|
126
|
+
const emittedWhen = when &&
|
|
127
|
+
Object.freeze({ path: Object.freeze(when.path), values: Object.freeze(when.values) });
|
|
128
|
+
rules.push(Object.freeze({
|
|
129
|
+
stageId,
|
|
130
|
+
capabilityId: wireName(id),
|
|
131
|
+
paths: emittedPaths,
|
|
132
|
+
...(emittedWhen ? { when: emittedWhen } : {}),
|
|
133
|
+
}));
|
|
84
134
|
}
|
|
85
135
|
}
|
|
86
136
|
return Object.freeze(rules);
|
|
@@ -2,7 +2,9 @@ import type { ModelOutputEvent } from '../../structs/model/runtime.js';
|
|
|
2
2
|
export interface ReplyPreviewRule {
|
|
3
3
|
/** Native function wire name. Omit only for a registered plain-text stage. */
|
|
4
4
|
capabilityId?: string;
|
|
5
|
+
/** Restrict the rule to one stage; omitted matches any stage producing this capability. */
|
|
5
6
|
stageId?: string;
|
|
7
|
+
/** JSON paths to project, where `*` matches any array index; defaults to text/bubble paths. */
|
|
6
8
|
paths?: readonly (readonly string[])[];
|
|
7
9
|
/** Presentation eligibility from a complete string field in the same proposal. */
|
|
8
10
|
when?: {
|
|
@@ -14,10 +16,22 @@ export interface ReplyPreviewSettings {
|
|
|
14
16
|
rules: readonly ReplyPreviewRule[];
|
|
15
17
|
/** Presentation only; must not authorize, persist or execute a proposal. */
|
|
16
18
|
render?(text: string): string;
|
|
19
|
+
/** Streamed characters tolerated before preview is disabled; default 16000. */
|
|
17
20
|
maxChars?: number;
|
|
18
21
|
}
|
|
19
22
|
export interface ReplyPreviewOptions extends ReplyPreviewSettings {
|
|
23
|
+
/** Receives the current bubble list; rejection propagates to the event caller. */
|
|
20
24
|
readonly sink: (bubbles: string[]) => void | Promise<void>;
|
|
21
25
|
}
|
|
22
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Create a model-output event handler that publishes preview bubbles.
|
|
28
|
+
*
|
|
29
|
+
* The handler resets on `model.start`, ignores other invocations, disables itself on unexpected
|
|
30
|
+
* output, and clears the preview when a call ends unsuccessfully. Rules are snapshotted at
|
|
31
|
+
* creation, and only explicitly registered prose fields are projected.
|
|
32
|
+
*
|
|
33
|
+
* @param options Rules, optional renderer, character budget and the bubble sink.
|
|
34
|
+
* @returns An async handler for `ModelOutputEvent`.
|
|
35
|
+
* @throws {TypeError} When the sink is missing or `maxChars` is not a positive integer.
|
|
36
|
+
*/
|
|
23
37
|
export declare function createReplyPreview(options: ReplyPreviewOptions): (event: ModelOutputEvent) => Promise<void>;
|