@jangts/agent-core 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.md +27 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +45 -17
- package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
- package/development/skills/agent-core-app/templates/catalog.json +36 -22
- package/dist/cjs/capabilities/index.js +13 -0
- package/dist/cjs/capabilities/invocation.js +80 -10
- package/dist/cjs/capabilities/model.js +126 -13
- package/dist/cjs/capabilities/tool-runtime.js +64 -12
- package/dist/cjs/capabilities/tools.js +266 -31
- package/dist/cjs/context/assembly.js +46 -5
- package/dist/cjs/context/audit.js +31 -6
- package/dist/cjs/context/fragments.js +54 -11
- package/dist/cjs/context/index.js +12 -0
- package/dist/cjs/context/journal.js +84 -7
- package/dist/cjs/context/plan.js +30 -2
- package/dist/cjs/diagnostics/catalog.js +11 -3
- package/dist/cjs/diagnostics/index.js +149 -29
- package/dist/cjs/diagnostics/sub-flow.js +240 -40
- package/dist/cjs/errors.js +99 -17
- package/dist/cjs/execution/branch.js +20 -4
- package/dist/cjs/execution/engine.js +470 -56
- package/dist/cjs/execution/events.js +136 -18
- package/dist/cjs/execution/index.js +7 -0
- package/dist/cjs/execution/reporting.js +75 -6
- package/dist/cjs/execution/state.js +161 -22
- package/dist/cjs/execution/workflow.js +224 -32
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/kits/aggregation.js +45 -3
- package/dist/cjs/kits/answering/batch.js +23 -4
- package/dist/cjs/kits/answering/check-result.js +31 -8
- package/dist/cjs/kits/answering/checks.js +24 -3
- package/dist/cjs/kits/answering/flow.js +192 -36
- package/dist/cjs/kits/answering/index.js +19 -1
- package/dist/cjs/kits/answering/tasks.js +88 -13
- package/dist/cjs/kits/artifacts.js +36 -4
- package/dist/cjs/kits/candidates.js +47 -5
- package/dist/cjs/kits/delivery.js +40 -5
- package/dist/cjs/kits/durable.js +155 -31
- package/dist/cjs/kits/evidence.js +66 -15
- package/dist/cjs/kits/family.js +152 -22
- package/dist/cjs/kits/index.js +12 -1
- package/dist/cjs/kits/inference.js +104 -16
- package/dist/cjs/kits/intents/catalog.js +67 -16
- package/dist/cjs/kits/intents/index.js +11 -0
- package/dist/cjs/kits/intents/registry.js +188 -43
- package/dist/cjs/kits/intents/scopes.js +215 -46
- package/dist/cjs/kits/interaction/command.js +140 -36
- package/dist/cjs/kits/interaction/commands.js +86 -11
- package/dist/cjs/kits/interaction/handlers.js +27 -10
- package/dist/cjs/kits/interaction/index.js +10 -0
- package/dist/cjs/kits/interaction/transfer.js +80 -14
- package/dist/cjs/kits/knowledge/catalog.js +62 -11
- package/dist/cjs/kits/knowledge/index.js +16 -1
- package/dist/cjs/kits/knowledge/publication.js +99 -23
- package/dist/cjs/kits/knowledge/sections.js +33 -4
- package/dist/cjs/kits/normalization.js +51 -7
- package/dist/cjs/kits/policies.js +79 -15
- package/dist/cjs/kits/presentation/events.js +54 -10
- package/dist/cjs/kits/presentation/index.js +24 -1
- package/dist/cjs/kits/presentation/outputs.js +176 -38
- package/dist/cjs/kits/presentation/templates.js +33 -5
- package/dist/cjs/kits/presentation/variants.js +31 -2
- package/dist/cjs/kits/projection.js +63 -8
- package/dist/cjs/kits/rank-fusion.js +27 -4
- package/dist/cjs/kits/reflection-log-source.js +89 -16
- package/dist/cjs/kits/reflection.js +234 -60
- package/dist/cjs/kits/retrieval.js +98 -18
- package/dist/cjs/kits/search.js +180 -27
- package/dist/cjs/kits/text-skills.js +104 -19
- package/dist/cjs/kits/tools.js +415 -74
- package/dist/cjs/kits/vector-search.js +50 -16
- package/dist/cjs/mock/node.js +7 -1
- package/dist/cjs/mock/web.js +7 -1
- package/dist/cjs/mock.js +7 -1
- package/dist/cjs/model/binding.js +68 -17
- package/dist/cjs/model/call-budget.js +45 -4
- package/dist/cjs/model/decision-retry.js +19 -1
- package/dist/cjs/model/defaults.js +27 -4
- package/dist/cjs/model/index.js +7 -0
- package/dist/cjs/model/interactions/arguments.js +36 -1
- package/dist/cjs/model/interactions/json-object.js +48 -12
- package/dist/cjs/model/interactions/native-functions.js +52 -10
- package/dist/cjs/model/message-diagnostics.js +17 -4
- package/dist/cjs/model/options.js +9 -1
- package/dist/cjs/model/preparation.js +86 -12
- package/dist/cjs/model/runner.js +413 -79
- package/dist/cjs/model/selection-transport.js +48 -8
- package/dist/cjs/model/settings.js +67 -13
- package/dist/cjs/model/token-budget.js +69 -11
- package/dist/cjs/model/transports.js +59 -6
- package/dist/cjs/structs/common.js +11 -0
- package/dist/cjs/structs/debug.js +34 -5
- package/dist/cjs/structs/errors.js +26 -1
- package/dist/cjs/structs/index.js +11 -1
- package/dist/cjs/structs/kits/durable.js +7 -0
- package/dist/cjs/structs/kits/family.js +1 -0
- package/dist/cjs/structs/kits/interaction.js +8 -1
- package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
- package/dist/cjs/structs/kits/reflection.js +18 -3
- package/dist/cjs/structs/model/chat-provider.js +6 -0
- package/dist/cjs/structs/support/model/completion.js +2 -0
- package/dist/cjs/structs/support/model/messages.js +2 -0
- package/dist/cjs/support/capabilities.js +43 -6
- package/dist/cjs/support/context/assembly.js +88 -16
- package/dist/cjs/support/context/compression.js +48 -6
- package/dist/cjs/support/context/fragments.js +6 -0
- package/dist/cjs/support/context/history.js +36 -1
- package/dist/cjs/support/context/index.js +11 -0
- package/dist/cjs/support/context/nodes.js +164 -35
- package/dist/cjs/support/context/processing.js +319 -61
- package/dist/cjs/support/context/selection-policy.js +98 -21
- package/dist/cjs/support/context/selection.js +61 -10
- package/dist/cjs/support/context/snapshot.js +29 -7
- package/dist/cjs/support/context/strategies.js +120 -28
- package/dist/cjs/support/index.js +9 -1
- package/dist/cjs/support/model/capabilities.js +20 -1
- package/dist/cjs/support/model/chat-completions.js +92 -20
- package/dist/cjs/support/model/children.js +34 -6
- package/dist/cjs/support/model/compatible-provider.js +189 -59
- package/dist/cjs/support/model/completion/calls.js +61 -0
- package/dist/cjs/support/model/completion/default.js +32 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +102 -0
- package/dist/cjs/support/model/index.js +12 -0
- package/dist/cjs/support/model/interactions/index.js +12 -1
- package/dist/cjs/support/model/interactions/json-object.js +6 -0
- package/dist/cjs/support/model/interactions/native-functions.js +6 -0
- package/dist/cjs/support/model/observer.js +32 -6
- package/dist/cjs/support/model/preview-rules.js +66 -16
- package/dist/cjs/support/model/reply-preview.js +77 -17
- package/dist/cjs/support/model/stage-transport.js +33 -7
- package/dist/cjs/support/model/strategies.js +75 -14
- package/dist/cjs/support/model/transports.js +53 -11
- package/dist/cjs/support/registration.js +49 -7
- package/dist/cjs/support/schema.js +46 -4
- package/dist/cjs/support/stream-events.js +60 -8
- package/dist/cjs/support/tool-runtime.js +6 -0
- package/dist/cjs/support/tools.js +79 -10
- package/dist/cjs/support/transport/index.js +7 -0
- package/dist/cjs/support/transport/json.js +28 -4
- package/dist/cjs/support/transport/sse.js +25 -2
- package/dist/cjs/utils/break-observer.js +20 -2
- package/dist/cjs/utils/cancellation.js +77 -9
- package/dist/cjs/utils/catalog.js +19 -4
- package/dist/cjs/utils/debug.js +14 -2
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/interaction-definition.js +26 -6
- package/dist/cjs/utils/invocation.js +42 -4
- package/dist/cjs/utils/model-protocol.js +20 -1
- package/dist/cjs/utils/object.js +16 -0
- package/dist/cjs/utils/observer.js +22 -2
- package/dist/cjs/utils/protocol-registry.js +47 -4
- package/dist/cjs/utils/query-key.js +21 -2
- package/dist/cjs/utils/registration.js +18 -2
- package/dist/cjs/utils/rules.js +39 -11
- package/dist/cjs/utils/schema-adapter.js +25 -2
- package/dist/cjs/utils/synchronous.js +64 -7
- package/dist/cjs/utils/text.js +15 -1
- package/dist/esm/capabilities/index.d.ts +13 -0
- package/dist/esm/capabilities/index.js +13 -0
- package/dist/esm/capabilities/invocation.d.ts +16 -2
- package/dist/esm/capabilities/invocation.js +80 -10
- package/dist/esm/capabilities/model.d.ts +68 -1
- package/dist/esm/capabilities/model.js +126 -13
- package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
- package/dist/esm/capabilities/tool-runtime.js +64 -12
- package/dist/esm/capabilities/tools.d.ts +96 -3
- package/dist/esm/capabilities/tools.js +267 -32
- package/dist/esm/context/assembly.d.ts +13 -2
- package/dist/esm/context/assembly.js +46 -5
- package/dist/esm/context/audit.d.ts +23 -1
- package/dist/esm/context/audit.js +31 -6
- package/dist/esm/context/fragments.d.ts +37 -3
- package/dist/esm/context/fragments.js +54 -11
- package/dist/esm/context/index.d.ts +12 -0
- package/dist/esm/context/index.js +12 -0
- package/dist/esm/context/journal.d.ts +32 -1
- package/dist/esm/context/journal.js +84 -7
- package/dist/esm/context/plan.d.ts +11 -1
- package/dist/esm/context/plan.js +30 -2
- package/dist/esm/diagnostics/catalog.js +11 -3
- package/dist/esm/diagnostics/index.d.ts +30 -2
- package/dist/esm/diagnostics/index.js +149 -29
- package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
- package/dist/esm/diagnostics/sub-flow.js +240 -40
- package/dist/esm/errors.d.ts +22 -2
- package/dist/esm/errors.js +99 -17
- package/dist/esm/execution/branch.d.ts +19 -1
- package/dist/esm/execution/branch.js +20 -4
- package/dist/esm/execution/engine.d.ts +291 -5
- package/dist/esm/execution/engine.js +471 -57
- package/dist/esm/execution/events.d.ts +16 -2
- package/dist/esm/execution/events.js +136 -18
- package/dist/esm/execution/index.d.ts +7 -0
- package/dist/esm/execution/index.js +7 -0
- package/dist/esm/execution/reporting.d.ts +49 -1
- package/dist/esm/execution/reporting.js +75 -6
- package/dist/esm/execution/state.d.ts +126 -10
- package/dist/esm/execution/state.js +161 -22
- package/dist/esm/execution/workflow.d.ts +121 -3
- package/dist/esm/execution/workflow.js +224 -32
- package/dist/esm/index.d.ts +17 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/kits/aggregation.d.ts +34 -2
- package/dist/esm/kits/aggregation.js +45 -3
- package/dist/esm/kits/answering/batch.d.ts +17 -0
- package/dist/esm/kits/answering/batch.js +23 -4
- package/dist/esm/kits/answering/check-result.d.ts +18 -1
- package/dist/esm/kits/answering/check-result.js +31 -8
- package/dist/esm/kits/answering/checks.d.ts +11 -0
- package/dist/esm/kits/answering/checks.js +24 -3
- package/dist/esm/kits/answering/flow.d.ts +25 -2
- package/dist/esm/kits/answering/flow.js +192 -36
- package/dist/esm/kits/answering/index.d.ts +12 -0
- package/dist/esm/kits/answering/index.js +19 -1
- package/dist/esm/kits/answering/tasks.d.ts +32 -1
- package/dist/esm/kits/answering/tasks.js +88 -13
- package/dist/esm/kits/artifacts.d.ts +11 -0
- package/dist/esm/kits/artifacts.js +36 -4
- package/dist/esm/kits/candidates.d.ts +23 -1
- package/dist/esm/kits/candidates.js +47 -5
- package/dist/esm/kits/delivery.d.ts +34 -0
- package/dist/esm/kits/delivery.js +40 -5
- package/dist/esm/kits/durable.d.ts +19 -0
- package/dist/esm/kits/durable.js +155 -31
- package/dist/esm/kits/evidence.d.ts +28 -5
- package/dist/esm/kits/evidence.js +66 -15
- package/dist/esm/kits/family.d.ts +17 -1
- package/dist/esm/kits/family.js +152 -22
- package/dist/esm/kits/index.d.ts +12 -1
- package/dist/esm/kits/index.js +12 -1
- package/dist/esm/kits/inference.d.ts +64 -0
- package/dist/esm/kits/inference.js +104 -16
- package/dist/esm/kits/intents/catalog.d.ts +13 -1
- package/dist/esm/kits/intents/catalog.js +67 -16
- package/dist/esm/kits/intents/index.d.ts +11 -0
- package/dist/esm/kits/intents/index.js +11 -0
- package/dist/esm/kits/intents/registry.d.ts +61 -3
- package/dist/esm/kits/intents/registry.js +188 -43
- package/dist/esm/kits/intents/scopes.d.ts +73 -3
- package/dist/esm/kits/intents/scopes.js +215 -46
- package/dist/esm/kits/interaction/command.d.ts +38 -4
- package/dist/esm/kits/interaction/command.js +140 -36
- package/dist/esm/kits/interaction/commands.d.ts +66 -2
- package/dist/esm/kits/interaction/commands.js +86 -11
- package/dist/esm/kits/interaction/handlers.d.ts +19 -2
- package/dist/esm/kits/interaction/handlers.js +27 -10
- package/dist/esm/kits/interaction/index.d.ts +10 -0
- package/dist/esm/kits/interaction/index.js +10 -0
- package/dist/esm/kits/interaction/transfer.d.ts +39 -2
- package/dist/esm/kits/interaction/transfer.js +80 -14
- package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
- package/dist/esm/kits/knowledge/catalog.js +62 -11
- package/dist/esm/kits/knowledge/index.d.ts +11 -0
- package/dist/esm/kits/knowledge/index.js +16 -1
- package/dist/esm/kits/knowledge/publication.d.ts +15 -1
- package/dist/esm/kits/knowledge/publication.js +99 -23
- package/dist/esm/kits/knowledge/sections.d.ts +31 -1
- package/dist/esm/kits/knowledge/sections.js +33 -4
- package/dist/esm/kits/normalization.d.ts +25 -2
- package/dist/esm/kits/normalization.js +51 -7
- package/dist/esm/kits/policies.d.ts +26 -3
- package/dist/esm/kits/policies.js +79 -15
- package/dist/esm/kits/presentation/events.d.ts +51 -4
- package/dist/esm/kits/presentation/events.js +54 -10
- package/dist/esm/kits/presentation/index.d.ts +12 -0
- package/dist/esm/kits/presentation/index.js +25 -2
- package/dist/esm/kits/presentation/outputs.d.ts +30 -1
- package/dist/esm/kits/presentation/outputs.js +176 -38
- package/dist/esm/kits/presentation/templates.d.ts +32 -3
- package/dist/esm/kits/presentation/templates.js +33 -5
- package/dist/esm/kits/presentation/variants.d.ts +29 -0
- package/dist/esm/kits/presentation/variants.js +31 -2
- package/dist/esm/kits/projection.d.ts +42 -5
- package/dist/esm/kits/projection.js +63 -8
- package/dist/esm/kits/rank-fusion.d.ts +21 -1
- package/dist/esm/kits/rank-fusion.js +28 -5
- package/dist/esm/kits/reflection-log-source.d.ts +28 -1
- package/dist/esm/kits/reflection-log-source.js +89 -16
- package/dist/esm/kits/reflection.d.ts +17 -1
- package/dist/esm/kits/reflection.js +235 -61
- package/dist/esm/kits/retrieval.d.ts +18 -2
- package/dist/esm/kits/retrieval.js +98 -18
- package/dist/esm/kits/search.d.ts +56 -3
- package/dist/esm/kits/search.js +180 -27
- package/dist/esm/kits/text-skills.d.ts +16 -2
- package/dist/esm/kits/text-skills.js +104 -19
- package/dist/esm/kits/tools.d.ts +122 -2
- package/dist/esm/kits/tools.js +416 -74
- package/dist/esm/kits/vector-search.d.ts +47 -1
- package/dist/esm/kits/vector-search.js +51 -17
- package/dist/esm/mock/node.d.ts +7 -0
- package/dist/esm/mock/node.js +7 -1
- package/dist/esm/mock/web.d.ts +7 -0
- package/dist/esm/mock/web.js +7 -1
- package/dist/esm/mock.d.ts +7 -0
- package/dist/esm/mock.js +7 -1
- package/dist/esm/model/binding.d.ts +32 -3
- package/dist/esm/model/binding.js +68 -17
- package/dist/esm/model/call-budget.d.ts +30 -2
- package/dist/esm/model/call-budget.js +45 -4
- package/dist/esm/model/decision-retry.d.ts +10 -1
- package/dist/esm/model/decision-retry.js +19 -1
- package/dist/esm/model/defaults.d.ts +13 -2
- package/dist/esm/model/defaults.js +27 -4
- package/dist/esm/model/index.d.ts +7 -0
- package/dist/esm/model/index.js +7 -0
- package/dist/esm/model/interactions/arguments.d.ts +27 -0
- package/dist/esm/model/interactions/arguments.js +36 -1
- package/dist/esm/model/interactions/json-object.d.ts +7 -1
- package/dist/esm/model/interactions/json-object.js +48 -12
- package/dist/esm/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/model/interactions/native-functions.js +52 -10
- package/dist/esm/model/message-diagnostics.d.ts +17 -1
- package/dist/esm/model/message-diagnostics.js +17 -4
- package/dist/esm/model/options.d.ts +18 -1
- package/dist/esm/model/options.js +9 -1
- package/dist/esm/model/preparation.d.ts +30 -2
- package/dist/esm/model/preparation.js +86 -12
- package/dist/esm/model/runner.d.ts +129 -5
- package/dist/esm/model/runner.js +414 -80
- package/dist/esm/model/selection-transport.d.ts +14 -1
- package/dist/esm/model/selection-transport.js +48 -8
- package/dist/esm/model/settings.d.ts +11 -0
- package/dist/esm/model/settings.js +67 -13
- package/dist/esm/model/token-budget.d.ts +59 -1
- package/dist/esm/model/token-budget.js +69 -11
- package/dist/esm/model/transports.d.ts +20 -2
- package/dist/esm/model/transports.js +59 -6
- package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
- package/dist/esm/structs/capabilities/model.d.ts +27 -0
- package/dist/esm/structs/capabilities/tools.d.ts +38 -0
- package/dist/esm/structs/common.d.ts +62 -2
- package/dist/esm/structs/common.js +11 -0
- package/dist/esm/structs/context/fragments.d.ts +28 -0
- package/dist/esm/structs/context/journal.d.ts +28 -3
- package/dist/esm/structs/context/processing.d.ts +11 -0
- package/dist/esm/structs/debug.d.ts +58 -1
- package/dist/esm/structs/debug.js +34 -5
- package/dist/esm/structs/diagnostics.d.ts +119 -1
- package/dist/esm/structs/errors.d.ts +42 -1
- package/dist/esm/structs/errors.js +26 -1
- package/dist/esm/structs/execution/engine.d.ts +24 -1
- package/dist/esm/structs/execution/events.d.ts +12 -0
- package/dist/esm/structs/execution/workflow.d.ts +71 -0
- package/dist/esm/structs/index.d.ts +11 -1
- package/dist/esm/structs/index.js +11 -1
- package/dist/esm/structs/invocation.d.ts +30 -0
- package/dist/esm/structs/kits/aggregation.d.ts +12 -0
- package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
- package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
- package/dist/esm/structs/kits/answering/state.d.ts +21 -0
- package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
- package/dist/esm/structs/kits/artifacts.d.ts +14 -0
- package/dist/esm/structs/kits/candidates.d.ts +19 -0
- package/dist/esm/structs/kits/delivery.d.ts +22 -0
- package/dist/esm/structs/kits/durable.d.ts +56 -3
- package/dist/esm/structs/kits/durable.js +7 -0
- package/dist/esm/structs/kits/evidence.d.ts +23 -0
- package/dist/esm/structs/kits/family.d.ts +49 -1
- package/dist/esm/structs/kits/family.js +1 -0
- package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
- package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
- package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
- package/dist/esm/structs/kits/interaction.d.ts +64 -0
- package/dist/esm/structs/kits/interaction.js +8 -1
- package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
- package/dist/esm/structs/kits/knowledge-publication.js +1 -0
- package/dist/esm/structs/kits/knowledge.d.ts +39 -2
- package/dist/esm/structs/kits/normalization.d.ts +15 -0
- package/dist/esm/structs/kits/policies.d.ts +25 -1
- package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
- package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
- package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
- package/dist/esm/structs/kits/projection.d.ts +21 -0
- package/dist/esm/structs/kits/reflection.d.ts +61 -2
- package/dist/esm/structs/kits/reflection.js +18 -3
- package/dist/esm/structs/kits/retrieval.d.ts +38 -0
- package/dist/esm/structs/kits/search.d.ts +22 -0
- package/dist/esm/structs/kits/text-skills.d.ts +36 -0
- package/dist/esm/structs/kits/tools.d.ts +87 -0
- package/dist/esm/structs/model/chat-provider.d.ts +24 -1
- package/dist/esm/structs/model/chat-provider.js +6 -0
- package/dist/esm/structs/model/interactions.d.ts +38 -0
- package/dist/esm/structs/model/messages.d.ts +30 -0
- package/dist/esm/structs/model/runtime.d.ts +104 -6
- package/dist/esm/structs/support/capabilities.d.ts +19 -2
- package/dist/esm/structs/support/context-processing.d.ts +88 -9
- package/dist/esm/structs/support/context.d.ts +29 -1
- package/dist/esm/structs/support/model/completion.d.ts +50 -0
- package/dist/esm/structs/support/model/completion.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +13 -1
- package/dist/esm/structs/support/model/messages.d.ts +52 -0
- package/dist/esm/structs/support/model/messages.js +1 -0
- package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
- package/dist/esm/structs/support/model/provider.d.ts +71 -6
- package/dist/esm/structs/support/registration.d.ts +13 -0
- package/dist/esm/structs/support/schema.d.ts +14 -0
- package/dist/esm/structs/support/tools.d.ts +28 -0
- package/dist/esm/structs/support/transport/json.d.ts +16 -0
- package/dist/esm/structs/support/transport/sse.d.ts +15 -0
- package/dist/esm/structs/utils/rules.d.ts +19 -0
- package/dist/esm/support/capabilities.d.ts +25 -2
- package/dist/esm/support/capabilities.js +43 -6
- package/dist/esm/support/context/assembly.d.ts +35 -4
- package/dist/esm/support/context/assembly.js +88 -16
- package/dist/esm/support/context/compression.d.ts +17 -1
- package/dist/esm/support/context/compression.js +48 -6
- package/dist/esm/support/context/fragments.d.ts +6 -0
- package/dist/esm/support/context/fragments.js +6 -0
- package/dist/esm/support/context/history.d.ts +43 -0
- package/dist/esm/support/context/history.js +36 -1
- package/dist/esm/support/context/index.d.ts +13 -2
- package/dist/esm/support/context/index.js +12 -1
- package/dist/esm/support/context/nodes.d.ts +49 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +145 -1
- package/dist/esm/support/context/processing.js +320 -62
- package/dist/esm/support/context/selection-policy.d.ts +42 -2
- package/dist/esm/support/context/selection-policy.js +98 -21
- package/dist/esm/support/context/selection.d.ts +14 -1
- package/dist/esm/support/context/selection.js +61 -10
- package/dist/esm/support/context/snapshot.d.ts +23 -1
- package/dist/esm/support/context/snapshot.js +29 -7
- package/dist/esm/support/context/strategies.d.ts +35 -2
- package/dist/esm/support/context/strategies.js +120 -28
- package/dist/esm/support/index.d.ts +9 -1
- package/dist/esm/support/index.js +9 -1
- package/dist/esm/support/model/capabilities.d.ts +10 -0
- package/dist/esm/support/model/capabilities.js +20 -1
- package/dist/esm/support/model/chat-completions.d.ts +44 -15
- package/dist/esm/support/model/chat-completions.js +92 -20
- package/dist/esm/support/model/children.d.ts +32 -2
- package/dist/esm/support/model/children.js +34 -6
- package/dist/esm/support/model/compatible-provider.d.ts +29 -3
- package/dist/esm/support/model/compatible-provider.js +190 -60
- package/dist/esm/support/model/completion/calls.d.ts +40 -0
- package/dist/esm/support/model/completion/calls.js +58 -0
- package/dist/esm/support/model/completion/default.d.ts +10 -0
- package/dist/esm/support/model/completion/default.js +29 -0
- package/dist/esm/support/model/completion/index.d.ts +10 -0
- package/dist/esm/support/model/completion/index.js +22 -0
- package/dist/esm/support/model/completion/session.d.ts +11 -0
- package/dist/esm/support/model/completion/session.js +99 -0
- package/dist/esm/support/model/index.d.ts +14 -0
- package/dist/esm/support/model/index.js +12 -0
- package/dist/esm/support/model/interactions/index.d.ts +1 -1
- package/dist/esm/support/model/interactions/index.js +12 -1
- package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
- package/dist/esm/support/model/interactions/json-object.js +6 -0
- package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/support/model/interactions/native-functions.js +6 -0
- package/dist/esm/support/model/observer.d.ts +25 -2
- package/dist/esm/support/model/observer.js +32 -6
- package/dist/esm/support/model/preview-rules.d.ts +20 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +15 -1
- package/dist/esm/support/model/reply-preview.js +77 -17
- package/dist/esm/support/model/stage-transport.d.ts +9 -1
- package/dist/esm/support/model/stage-transport.js +33 -7
- package/dist/esm/support/model/strategies.d.ts +24 -2
- package/dist/esm/support/model/strategies.js +75 -14
- package/dist/esm/support/model/transports.d.ts +17 -1
- package/dist/esm/support/model/transports.js +53 -11
- package/dist/esm/support/registration.d.ts +20 -1
- package/dist/esm/support/registration.js +49 -7
- package/dist/esm/support/schema.d.ts +31 -1
- package/dist/esm/support/schema.js +46 -4
- package/dist/esm/support/stream-events.d.ts +22 -1
- package/dist/esm/support/stream-events.js +60 -8
- package/dist/esm/support/tool-runtime.d.ts +6 -0
- package/dist/esm/support/tool-runtime.js +6 -0
- package/dist/esm/support/tools.d.ts +22 -0
- package/dist/esm/support/tools.js +79 -10
- package/dist/esm/support/transport/index.d.ts +7 -0
- package/dist/esm/support/transport/index.js +7 -0
- package/dist/esm/support/transport/json.d.ts +29 -2
- package/dist/esm/support/transport/json.js +28 -4
- package/dist/esm/support/transport/sse.d.ts +31 -1
- package/dist/esm/support/transport/sse.js +25 -2
- package/dist/esm/types.d.ts +9 -1
- package/dist/esm/utils/break-observer.d.ts +27 -2
- package/dist/esm/utils/break-observer.js +20 -2
- package/dist/esm/utils/cancellation.d.ts +56 -5
- package/dist/esm/utils/cancellation.js +77 -9
- package/dist/esm/utils/catalog.d.ts +20 -1
- package/dist/esm/utils/catalog.js +19 -4
- package/dist/esm/utils/debug.d.ts +20 -1
- package/dist/esm/utils/debug.js +14 -2
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/interaction-definition.d.ts +18 -1
- package/dist/esm/utils/interaction-definition.js +26 -6
- package/dist/esm/utils/invocation.d.ts +36 -1
- package/dist/esm/utils/invocation.js +42 -4
- package/dist/esm/utils/model-protocol.d.ts +8 -0
- package/dist/esm/utils/model-protocol.js +20 -1
- package/dist/esm/utils/object.d.ts +16 -0
- package/dist/esm/utils/object.js +16 -0
- package/dist/esm/utils/observer.d.ts +19 -1
- package/dist/esm/utils/observer.js +22 -2
- package/dist/esm/utils/protocol-registry.d.ts +38 -1
- package/dist/esm/utils/protocol-registry.js +47 -4
- package/dist/esm/utils/query-key.d.ts +11 -1
- package/dist/esm/utils/query-key.js +21 -2
- package/dist/esm/utils/registration.d.ts +34 -2
- package/dist/esm/utils/registration.js +18 -2
- package/dist/esm/utils/rules.d.ts +81 -4
- package/dist/esm/utils/rules.js +39 -11
- package/dist/esm/utils/schema-adapter.d.ts +12 -1
- package/dist/esm/utils/schema-adapter.js +25 -2
- package/dist/esm/utils/synchronous.d.ts +60 -4
- package/dist/esm/utils/synchronous.js +64 -7
- package/dist/esm/utils/text.d.ts +15 -1
- package/dist/esm/utils/text.js +15 -1
- package/package.json +3 -2
|
@@ -6,28 +6,51 @@ exports.publishReplyEvents = publishReplyEvents;
|
|
|
6
6
|
exports.serializeOutputEvents = serializeOutputEvents;
|
|
7
7
|
exports.textOutputEvents = textOutputEvents;
|
|
8
8
|
const rules_js_1 = require("../../utils/rules.js");
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Internal boundary between validated assistant bubbles. Never sent as visible text.
|
|
11
|
+
*
|
|
12
|
+
* U+001E (record separator) is a non-printing control character that ordinary replies do not
|
|
13
|
+
* contain, so splitting on it cannot truncate visible prose.
|
|
14
|
+
*/
|
|
10
15
|
exports.REPLY_BUBBLE_BOUNDARY = '\u001e';
|
|
16
|
+
/**
|
|
17
|
+
* Collect the non-empty-text parts of a reply.
|
|
18
|
+
*
|
|
19
|
+
* @param reply - Primary text plus optional extra bubbles.
|
|
20
|
+
* @returns The text and every string bubble; non-string entries are dropped.
|
|
21
|
+
*/
|
|
11
22
|
function replyBubbleTexts(reply) {
|
|
12
23
|
const { text, bubbles } = reply;
|
|
13
|
-
return [text, ...(Array.isArray(bubbles) ? bubbles : [])]
|
|
14
|
-
.filter((text) => typeof text === 'string');
|
|
24
|
+
return [text, ...(Array.isArray(bubbles) ? bubbles : [])].filter((text) => typeof text === 'string');
|
|
15
25
|
}
|
|
16
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Stream one reply as paced text chunks and bubble separators.
|
|
28
|
+
*
|
|
29
|
+
* Publish a validated reply without exposing its internal boundary to consumers. The pacing
|
|
30
|
+
* options are upper bounds, not exact timings: the pause and interval are clamped against
|
|
31
|
+
* `maxDurationMs`, so added delay never exceeds the budget while every chunk is still emitted.
|
|
32
|
+
*
|
|
33
|
+
* @param request - Reply text (bubbles separated by `REPLY_BUBBLE_BOUNDARY`) and pacing options.
|
|
34
|
+
* @param context - Execution context supplying the abort signal.
|
|
35
|
+
* @returns An async stream of `text` and `bubble` events, in order.
|
|
36
|
+
* @throws TypeError For a malformed request, missing signal, or invalid chunk/pacing values;
|
|
37
|
+
* aborts with the caller's signal.
|
|
38
|
+
*/
|
|
17
39
|
async function* publishReplyEvents(request, context) {
|
|
18
40
|
(0, rules_js_1.breakWhile)(!request || typeof request !== 'object', () => new TypeError('Use a named reply delivery request'));
|
|
19
41
|
const { text, delivery } = request, { signal } = context;
|
|
20
42
|
(0, rules_js_1.breakWhile)(typeof text !== 'string' || !signal, () => new TypeError('Reply delivery requires text and ExecutionContext'));
|
|
21
43
|
(0, rules_js_1.breakWhile)(delivery !== undefined && (!delivery || typeof delivery !== 'object'), () => new TypeError('Reply delivery requires named options'));
|
|
22
|
-
const { chunkSize = 240, intervalMs = 0, bubblePauseMs = 0, maxDurationMs = 3000 } = delivery ?? {};
|
|
44
|
+
const { chunkSize = 240, intervalMs = 0, bubblePauseMs = 0, maxDurationMs = 3000, } = delivery ?? {};
|
|
23
45
|
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(chunkSize) || chunkSize < 1, () => new TypeError('Invalid output chunk size'));
|
|
24
46
|
for (const [name, value] of Object.entries({ intervalMs, bubblePauseMs, maxDurationMs }))
|
|
25
47
|
(0, rules_js_1.breakWhile)(!Number.isFinite(value) || value < 0, () => new TypeError(`Invalid ${name}`));
|
|
26
48
|
signal.throwIfAborted();
|
|
27
|
-
const bubbles = text.split(exports.REPLY_BUBBLE_BOUNDARY).map(bubble => Array.from(bubble));
|
|
49
|
+
const bubbles = text.split(exports.REPLY_BUBBLE_BOUNDARY).map((bubble) => Array.from(bubble));
|
|
28
50
|
const chunkCount = bubbles.reduce((sum, bubble) => sum + Math.ceil(bubble.length / chunkSize), 0);
|
|
29
51
|
const pause = Math.min(bubblePauseMs, maxDurationMs / Math.max(1, bubbles.length - 1));
|
|
30
|
-
const interval = Math.min(intervalMs, Math.max(0, maxDurationMs - pause * (bubbles.length - 1)) /
|
|
52
|
+
const interval = Math.min(intervalMs, Math.max(0, maxDurationMs - pause * (bubbles.length - 1)) /
|
|
53
|
+
Math.max(1, chunkCount - bubbles.filter((bubble) => bubble.length).length));
|
|
31
54
|
const deadline = performance.now() + maxDurationMs;
|
|
32
55
|
for (let bubble = 0; bubble < bubbles.length; bubble++) {
|
|
33
56
|
if (bubble) {
|
|
@@ -50,14 +73,29 @@ async function wait(milliseconds, signal) {
|
|
|
50
73
|
if (!milliseconds)
|
|
51
74
|
return;
|
|
52
75
|
await new Promise((resolve, reject) => {
|
|
53
|
-
const stop = () => {
|
|
54
|
-
|
|
76
|
+
const stop = () => {
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
signal.removeEventListener('abort', stop);
|
|
79
|
+
reject(signal.reason);
|
|
80
|
+
};
|
|
81
|
+
const timer = setTimeout(() => {
|
|
82
|
+
signal.removeEventListener('abort', stop);
|
|
83
|
+
resolve();
|
|
84
|
+
}, milliseconds);
|
|
55
85
|
signal.addEventListener('abort', stop, { once: true });
|
|
56
86
|
if (signal.aborted)
|
|
57
87
|
stop();
|
|
58
88
|
});
|
|
59
89
|
}
|
|
60
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Serialize the event protocol for callers using a text stream.
|
|
92
|
+
*
|
|
93
|
+
* `preview` events are dropped because they are not final text; bubbles become the boundary
|
|
94
|
+
* character again, so a consumer can re-split the stream.
|
|
95
|
+
*
|
|
96
|
+
* @param events - Event stream carrying `text`, `bubble` or `preview` entries.
|
|
97
|
+
* @returns The equivalent string chunks.
|
|
98
|
+
*/
|
|
61
99
|
async function* serializeOutputEvents(events) {
|
|
62
100
|
for await (const event of events) {
|
|
63
101
|
if (event.type === 'preview')
|
|
@@ -65,6 +103,12 @@ async function* serializeOutputEvents(events) {
|
|
|
65
103
|
yield event.type === 'bubble' ? exports.REPLY_BUBBLE_BOUNDARY : event.text;
|
|
66
104
|
}
|
|
67
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Wrap already-chunked text as `text` events.
|
|
108
|
+
*
|
|
109
|
+
* @param chunks - Text chunks in delivery order.
|
|
110
|
+
* @returns The same chunks as events.
|
|
111
|
+
*/
|
|
68
112
|
async function* textOutputEvents(chunks) {
|
|
69
113
|
for await (const text of chunks)
|
|
70
114
|
yield { type: 'text', text };
|
|
@@ -15,6 +15,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.Presentation = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Presentation Kit entry: output contracts, text templates, semantic slots, variants and the
|
|
20
|
+
* reply/chunk event stream.
|
|
21
|
+
*
|
|
22
|
+
* Place in the package: an optional App-side library for shaping what the user finally sees.
|
|
23
|
+
* The App owns copy, styling and transport; this directory owns contract validation, template
|
|
24
|
+
* substitution, variant selection and the bubble/chunk protocol.
|
|
25
|
+
*
|
|
26
|
+
* Exports: everything from `./outputs.js`, `./variants.js`, `./templates.js` and `./events.js`,
|
|
27
|
+
* plus the `Presentation` namespace object.
|
|
28
|
+
*/
|
|
18
29
|
__exportStar(require("./outputs.js"), exports);
|
|
19
30
|
__exportStar(require("./variants.js"), exports);
|
|
20
31
|
__exportStar(require("./templates.js"), exports);
|
|
@@ -23,4 +34,16 @@ const outputs_js_1 = require("./outputs.js");
|
|
|
23
34
|
const templates_js_1 = require("./templates.js");
|
|
24
35
|
const variants_js_1 = require("./variants.js");
|
|
25
36
|
const events_js_1 = require("./events.js");
|
|
26
|
-
|
|
37
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
38
|
+
exports.Presentation = Object.freeze({
|
|
39
|
+
defineOutputCatalog: outputs_js_1.defineOutputCatalog,
|
|
40
|
+
defineTextTemplate: templates_js_1.defineTextTemplate,
|
|
41
|
+
defineSemanticSlots: templates_js_1.defineSemanticSlots,
|
|
42
|
+
selectVariant: variants_js_1.selectVariant,
|
|
43
|
+
resolvePreference: variants_js_1.resolvePreference,
|
|
44
|
+
REPLY_BUBBLE_BOUNDARY: events_js_1.REPLY_BUBBLE_BOUNDARY,
|
|
45
|
+
replyBubbleTexts: events_js_1.replyBubbleTexts,
|
|
46
|
+
publishReplyEvents: events_js_1.publishReplyEvents,
|
|
47
|
+
serializeOutputEvents: events_js_1.serializeOutputEvents,
|
|
48
|
+
textOutputEvents: events_js_1.textOutputEvents,
|
|
49
|
+
});
|
|
@@ -1,20 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineOutputCatalog = defineOutputCatalog;
|
|
4
|
+
/**
|
|
5
|
+
* Presentation Kit: declarative output contracts for text, master, record and group outputs.
|
|
6
|
+
*
|
|
7
|
+
* Place in the package: part of the `presentation` Kit. A definition decides which fields the
|
|
8
|
+
* model generates, which are bound to App providers, which are constants and which select a
|
|
9
|
+
* semantic key; this module validates those declarations and composes the final value.
|
|
10
|
+
*
|
|
11
|
+
* Exports: `defineOutputCatalog`, and the output definition/field/provider/result types.
|
|
12
|
+
*/
|
|
4
13
|
const schema_adapter_js_1 = require("../../utils/schema-adapter.js");
|
|
5
14
|
const catalog_js_1 = require("../../utils/catalog.js");
|
|
6
15
|
const synchronous_js_1 = require("../../utils/synchronous.js");
|
|
7
16
|
const templates_js_1 = require("./templates.js");
|
|
8
17
|
const object_js_1 = require("../../utils/object.js");
|
|
9
18
|
const observer_js_1 = require("../../utils/observer.js");
|
|
10
|
-
function snapshotValue(value) {
|
|
11
|
-
const
|
|
19
|
+
function snapshotValue(value) {
|
|
20
|
+
const copy = structuredClone(value);
|
|
21
|
+
(0, object_js_1.freezeSchema)(copy);
|
|
22
|
+
return copy;
|
|
23
|
+
}
|
|
24
|
+
const textValueSchema = (0, schema_adapter_js_1.snapshotSchemaAdapter)({
|
|
25
|
+
jsonSchema: { type: 'string' },
|
|
26
|
+
parse(value) {
|
|
12
27
|
if (typeof value !== 'string')
|
|
13
28
|
throw new TypeError('Invalid output field value');
|
|
14
29
|
return value;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
function parseField(field, value) {
|
|
33
|
+
return field.valueSchema.parse(value);
|
|
34
|
+
}
|
|
35
|
+
// Object-prototype names are excluded so a field id can never shadow `__proto__` or replace a
|
|
36
|
+
// prototype member when values are assembled into a dictionary.
|
|
37
|
+
const validId = (id) => typeof id === 'string' &&
|
|
38
|
+
/^[A-Za-z][A-Za-z0-9_.-]*$/.test(id) &&
|
|
39
|
+
!['__proto__', 'constructor', 'prototype'].includes(id);
|
|
40
|
+
/**
|
|
41
|
+
* Compile output definitions into one catalog.
|
|
42
|
+
*
|
|
43
|
+
* Compilation is where most mistakes surface: group membership is checked for cycles, master
|
|
44
|
+
* templates must have exactly one slot per field, and every `bound`/`semantic` field must name
|
|
45
|
+
* a registered provider. Composition then trusts the compiled catalog.
|
|
46
|
+
*
|
|
47
|
+
* @param definitions - Output definitions with unique ids and a supported `kind`.
|
|
48
|
+
* @param options - Provider list and an optional observer for composed results.
|
|
49
|
+
* @returns A frozen catalog extended with `toModelSchema`, `check` and `compose`.
|
|
50
|
+
* @throws TypeError For an invalid id or kind, a malformed group, mismatched master slots,
|
|
51
|
+
* an invalid field owner or semantic keys, or an unknown provider id.
|
|
52
|
+
*/
|
|
18
53
|
function defineOutputCatalog(definitions, options = {}) {
|
|
19
54
|
const providers = options.providers ?? [], observe = options.observe?.bind(options);
|
|
20
55
|
const providerMap = new Map();
|
|
@@ -30,42 +65,70 @@ function defineOutputCatalog(definitions, options = {}) {
|
|
|
30
65
|
const { id, kind, fields: fieldDefinitions, master, maxItems, allowedOutputIds } = definition;
|
|
31
66
|
if (!validId(id) || catalog.has(id) || !['text', 'master', 'record', 'group'].includes(kind))
|
|
32
67
|
throw new TypeError('Invalid output definition');
|
|
33
|
-
const fields = fieldDefinitions?.map(field => {
|
|
68
|
+
const fields = fieldDefinitions?.map((field) => {
|
|
34
69
|
const { id, owner, required, valueSchema, providerId, constantValue, semanticKeys } = field;
|
|
35
|
-
return Object.freeze({
|
|
36
|
-
|
|
37
|
-
|
|
70
|
+
return Object.freeze({
|
|
71
|
+
id,
|
|
72
|
+
owner,
|
|
73
|
+
required,
|
|
74
|
+
valueSchema: valueSchema === undefined ? textValueSchema : (0, schema_adapter_js_1.snapshotSchemaAdapter)(valueSchema),
|
|
75
|
+
providerId,
|
|
76
|
+
constantValue: owner === 'constant' ? snapshotValue(constantValue) : undefined,
|
|
77
|
+
semanticKeys: semanticKeys === undefined ? undefined : Object.freeze([...semanticKeys]),
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
const entry = Object.freeze({
|
|
81
|
+
id,
|
|
82
|
+
kind,
|
|
83
|
+
master,
|
|
84
|
+
maxItems,
|
|
85
|
+
fields: fields ? Object.freeze(fields) : undefined,
|
|
86
|
+
allowedOutputIds: allowedOutputIds === undefined ? undefined : Object.freeze([...allowedOutputIds]),
|
|
38
87
|
});
|
|
39
|
-
const entry = Object.freeze({ id, kind, master, maxItems, fields: fields ? Object.freeze(fields) : undefined,
|
|
40
|
-
allowedOutputIds: allowedOutputIds === undefined ? undefined : Object.freeze([...allowedOutputIds]) });
|
|
41
88
|
if (entry.kind === 'group') {
|
|
42
|
-
if (entry.fields?.length ||
|
|
89
|
+
if (entry.fields?.length ||
|
|
90
|
+
entry.master !== undefined ||
|
|
91
|
+
!entry.allowedOutputIds?.length ||
|
|
92
|
+
new Set(entry.allowedOutputIds).size !== entry.allowedOutputIds.length ||
|
|
93
|
+
!Number.isSafeInteger(entry.maxItems) ||
|
|
94
|
+
entry.maxItems < 1)
|
|
43
95
|
throw new TypeError('Invalid output group');
|
|
44
96
|
}
|
|
45
97
|
else {
|
|
46
|
-
if (!fields?.length ||
|
|
98
|
+
if (!fields?.length ||
|
|
99
|
+
new Set(fields.map((field) => field.id)).size !== fields.length ||
|
|
100
|
+
(entry.kind === 'text' && (fields.length !== 1 || fields[0].required === false)))
|
|
47
101
|
throw new TypeError('Invalid output fields');
|
|
48
102
|
for (const field of fields) {
|
|
49
|
-
if (!validId(field.id) ||
|
|
103
|
+
if (!validId(field.id) ||
|
|
104
|
+
!['generated', 'bound', 'constant', 'semantic'].includes(field.owner))
|
|
50
105
|
throw new TypeError('Invalid output ownership');
|
|
51
106
|
if (['bound', 'semantic'].includes(field.owner) && !providerMap.has(field.providerId))
|
|
52
107
|
throw new TypeError(`Unknown output provider: ${field.providerId}`);
|
|
53
|
-
if (field.owner === 'semantic' &&
|
|
108
|
+
if (field.owner === 'semantic' &&
|
|
109
|
+
(!field.semanticKeys?.length ||
|
|
110
|
+
new Set(field.semanticKeys).size !== field.semanticKeys.length ||
|
|
111
|
+
field.semanticKeys.some((key) => typeof key !== 'string' || !key)))
|
|
54
112
|
throw new TypeError('Invalid semantic output keys');
|
|
55
113
|
}
|
|
56
114
|
if (entry.kind === 'master') {
|
|
57
115
|
if (typeof entry.master !== 'string')
|
|
58
116
|
throw new TypeError('Missing output master');
|
|
59
117
|
const template = (0, templates_js_1.defineTextTemplate)(entry.master);
|
|
60
|
-
if (template.slots.length !== fields.length ||
|
|
118
|
+
if (template.slots.length !== fields.length ||
|
|
119
|
+
template.slots.some((id) => !fields.some((field) => field.id === id)))
|
|
61
120
|
throw new TypeError('Output master fields do not match slots');
|
|
62
121
|
masters.set(entry.id, template);
|
|
63
122
|
}
|
|
64
123
|
}
|
|
65
124
|
catalog.set(entry.id, entry);
|
|
66
125
|
}
|
|
67
|
-
const get = (id) => {
|
|
68
|
-
|
|
126
|
+
const get = (id) => {
|
|
127
|
+
const entry = catalog.get(id);
|
|
128
|
+
if (!entry)
|
|
129
|
+
throw new TypeError(`Unknown output: ${id}`);
|
|
130
|
+
return entry;
|
|
131
|
+
};
|
|
69
132
|
const visited = new Set(), visiting = new Set();
|
|
70
133
|
function checkRefs(id) {
|
|
71
134
|
if (visited.has(id))
|
|
@@ -81,13 +144,23 @@ function defineOutputCatalog(definitions, options = {}) {
|
|
|
81
144
|
for (const id of catalog.keys())
|
|
82
145
|
checkRefs(id);
|
|
83
146
|
// Both callers reject groups before asking for their validated nonempty fields.
|
|
84
|
-
const modelFields = (entry) => entry.fields.filter(field => ['generated', 'semantic'].includes(field.owner));
|
|
147
|
+
const modelFields = (entry) => entry.fields.filter((field) => ['generated', 'semantic'].includes(field.owner));
|
|
85
148
|
function toModelSchema(id) {
|
|
86
149
|
const entry = get(id);
|
|
87
150
|
if (entry.kind === 'group')
|
|
88
151
|
throw new TypeError('Output groups require program-assigned items');
|
|
89
152
|
const fields = modelFields(entry);
|
|
90
|
-
return {
|
|
153
|
+
return {
|
|
154
|
+
type: 'object',
|
|
155
|
+
properties: Object.fromEntries(fields.map((field) => [
|
|
156
|
+
field.id,
|
|
157
|
+
field.owner === 'semantic'
|
|
158
|
+
? { type: 'string', enum: [...field.semanticKeys] }
|
|
159
|
+
: field.valueSchema.jsonSchema,
|
|
160
|
+
])),
|
|
161
|
+
required: fields.filter((field) => field.required !== false).map((field) => field.id),
|
|
162
|
+
additionalProperties: false,
|
|
163
|
+
};
|
|
91
164
|
}
|
|
92
165
|
function inspect(id, value, signal) {
|
|
93
166
|
signal?.throwIfAborted();
|
|
@@ -96,16 +169,27 @@ function defineOutputCatalog(definitions, options = {}) {
|
|
|
96
169
|
throw new TypeError('Inspect individual group items');
|
|
97
170
|
const issues = [], values = Object.create(null);
|
|
98
171
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
99
|
-
return {
|
|
172
|
+
return {
|
|
173
|
+
values,
|
|
174
|
+
issues: [{ path: [id], code: 'OUTPUT_SHAPE', message: 'Expected an output object' }],
|
|
175
|
+
};
|
|
100
176
|
const input = value, fields = modelFields(entry);
|
|
101
177
|
for (const key of Object.keys(input))
|
|
102
|
-
if (!fields.some(field => field.id === key))
|
|
103
|
-
issues.push({
|
|
178
|
+
if (!fields.some((field) => field.id === key))
|
|
179
|
+
issues.push({
|
|
180
|
+
path: [id, key],
|
|
181
|
+
code: 'OUTPUT_FOREIGN_FIELD',
|
|
182
|
+
message: 'Unknown generated field',
|
|
183
|
+
});
|
|
104
184
|
for (const field of fields) {
|
|
105
185
|
signal?.throwIfAborted();
|
|
106
186
|
if (!Object.hasOwn(input, field.id)) {
|
|
107
187
|
if (field.required !== false)
|
|
108
|
-
issues.push({
|
|
188
|
+
issues.push({
|
|
189
|
+
path: [id, field.id],
|
|
190
|
+
code: 'OUTPUT_MISSING',
|
|
191
|
+
message: 'Required generated field is missing',
|
|
192
|
+
});
|
|
109
193
|
continue;
|
|
110
194
|
}
|
|
111
195
|
const value = input[field.id];
|
|
@@ -121,9 +205,16 @@ function defineOutputCatalog(definitions, options = {}) {
|
|
|
121
205
|
}
|
|
122
206
|
catch (error) {
|
|
123
207
|
signal?.throwIfAborted();
|
|
124
|
-
if (error &&
|
|
208
|
+
if (error &&
|
|
209
|
+
typeof error === 'object' &&
|
|
210
|
+
'name' in error &&
|
|
211
|
+
['AbortError', 'TimeoutError'].includes(String(error.name)))
|
|
125
212
|
throw error;
|
|
126
|
-
issues.push({
|
|
213
|
+
issues.push({
|
|
214
|
+
path: [id, field.id],
|
|
215
|
+
code: 'OUTPUT_VALUE',
|
|
216
|
+
message: 'Generated field does not match its schema',
|
|
217
|
+
});
|
|
127
218
|
}
|
|
128
219
|
signal?.throwIfAborted();
|
|
129
220
|
}
|
|
@@ -134,16 +225,25 @@ function defineOutputCatalog(definitions, options = {}) {
|
|
|
134
225
|
const entry = get(id), { generated, items } = input;
|
|
135
226
|
context.signal.throwIfAborted();
|
|
136
227
|
if (entry.kind === 'group') {
|
|
137
|
-
if (Object.keys(generated ?? {}).length ||
|
|
228
|
+
if (Object.keys(generated ?? {}).length ||
|
|
229
|
+
!Array.isArray(items) ||
|
|
230
|
+
items.length > entry.maxItems)
|
|
138
231
|
throw new TypeError('Invalid output group items');
|
|
139
|
-
const assigned = items.map((item) => ({
|
|
140
|
-
|
|
232
|
+
const assigned = items.map((item) => ({
|
|
233
|
+
id: item.id,
|
|
234
|
+
outputId: item.outputId,
|
|
235
|
+
input: item.input,
|
|
236
|
+
}));
|
|
237
|
+
if (new Set(assigned.map((item) => item.id)).size !== assigned.length)
|
|
141
238
|
throw new TypeError('Invalid output group items');
|
|
142
|
-
const value = assigned.map(item => {
|
|
239
|
+
const value = assigned.map((item) => {
|
|
143
240
|
context.signal.throwIfAborted();
|
|
144
241
|
if (!validId(item.id) || !entry.allowedOutputIds.includes(item.outputId))
|
|
145
242
|
throw new TypeError('Invalid output group reference');
|
|
146
|
-
return Object.freeze({
|
|
243
|
+
return Object.freeze({
|
|
244
|
+
id: item.id,
|
|
245
|
+
...composeInternal(item.outputId, item.input, context),
|
|
246
|
+
});
|
|
147
247
|
});
|
|
148
248
|
context.signal.throwIfAborted();
|
|
149
249
|
return Object.freeze({ outputId: id, kind: entry.kind, value: Object.freeze(value) });
|
|
@@ -151,17 +251,26 @@ function defineOutputCatalog(definitions, options = {}) {
|
|
|
151
251
|
const checked = inspect(id, generated ?? {}, context.signal);
|
|
152
252
|
context.signal.throwIfAborted();
|
|
153
253
|
if (checked.issues.length)
|
|
154
|
-
throw Object.assign(new TypeError('Output contract rejected generated fields'), {
|
|
254
|
+
throw Object.assign(new TypeError('Output contract rejected generated fields'), {
|
|
255
|
+
issues: checked.issues,
|
|
256
|
+
});
|
|
155
257
|
const values = Object.create(null);
|
|
156
258
|
for (const field of entry.fields) {
|
|
157
259
|
context.signal.throwIfAborted();
|
|
158
|
-
if (['generated', 'semantic'].includes(field.owner) &&
|
|
260
|
+
if (['generated', 'semantic'].includes(field.owner) &&
|
|
261
|
+
!Object.hasOwn(checked.values, field.id) &&
|
|
262
|
+
field.required === false) {
|
|
159
263
|
if (entry.kind === 'master')
|
|
160
264
|
values[field.id] = '';
|
|
161
265
|
continue;
|
|
162
266
|
}
|
|
163
|
-
const value = field.owner === 'constant'
|
|
164
|
-
?
|
|
267
|
+
const value = field.owner === 'constant'
|
|
268
|
+
? field.constantValue
|
|
269
|
+
: ['bound', 'semantic'].includes(field.owner)
|
|
270
|
+
? (0, synchronous_js_1.synchronous)(providerMap.get(field.providerId).resolve({
|
|
271
|
+
key: field.owner === 'semantic' ? checked.values[field.id] : undefined,
|
|
272
|
+
}, context), 'Output providers must be synchronous')
|
|
273
|
+
: checked.values[field.id];
|
|
165
274
|
context.signal.throwIfAborted();
|
|
166
275
|
if (value === undefined && field.required === false) {
|
|
167
276
|
if (entry.kind === 'master')
|
|
@@ -171,7 +280,11 @@ function defineOutputCatalog(definitions, options = {}) {
|
|
|
171
280
|
values[field.id] = field.owner === 'generated' ? value : parseField(field, value);
|
|
172
281
|
context.signal.throwIfAborted();
|
|
173
282
|
}
|
|
174
|
-
const value = entry.kind === 'master'
|
|
283
|
+
const value = entry.kind === 'master'
|
|
284
|
+
? masters.get(id).render(values)
|
|
285
|
+
: entry.kind === 'text'
|
|
286
|
+
? values[entry.fields[0].id]
|
|
287
|
+
: Object.freeze(values);
|
|
175
288
|
if ((entry.kind === 'text' || entry.kind === 'master') && typeof value !== 'string')
|
|
176
289
|
throw new TypeError('Text output requires a string value');
|
|
177
290
|
const result = Object.freeze({ outputId: id, kind: entry.kind, value });
|
|
@@ -179,8 +292,33 @@ function defineOutputCatalog(definitions, options = {}) {
|
|
|
179
292
|
(0, observer_js_1.observeSafely)(observe, result);
|
|
180
293
|
return result;
|
|
181
294
|
}
|
|
182
|
-
return Object.freeze({
|
|
183
|
-
|
|
295
|
+
return Object.freeze({
|
|
296
|
+
...(0, catalog_js_1.readonlyCatalog)(catalog.values(), (id) => new TypeError(`Unknown output: ${id}`)),
|
|
297
|
+
/** JSON schema of the fields a model must generate for this output. */
|
|
298
|
+
toModelSchema,
|
|
299
|
+
/**
|
|
300
|
+
* Validate a generated value without composing it.
|
|
301
|
+
*
|
|
302
|
+
* @param request - Output id and the candidate value.
|
|
303
|
+
* @returns `passed` or `failed` with the collected issues and accepted values.
|
|
304
|
+
*/
|
|
305
|
+
check(request) {
|
|
306
|
+
const result = inspect(request.outputId, request.value);
|
|
307
|
+
return {
|
|
308
|
+
status: result.issues.length ? 'failed' : 'passed',
|
|
309
|
+
value: result.values,
|
|
310
|
+
issues: result.issues,
|
|
311
|
+
};
|
|
312
|
+
},
|
|
313
|
+
/**
|
|
314
|
+
* Compose the final output value from generated fields, providers and constants.
|
|
315
|
+
*
|
|
316
|
+
* @param request - Output id and the generated/group input.
|
|
317
|
+
* @param context - Operation context; cancellation is checked between every step.
|
|
318
|
+
* @returns The frozen composed result, also forwarded to the observer.
|
|
319
|
+
* @throws TypeError For a malformed request, missing context, rejected generated fields
|
|
320
|
+
* (carrying `issues`), a non-synchronous provider, or a text output that is not a string.
|
|
321
|
+
*/
|
|
184
322
|
compose(request, context) {
|
|
185
323
|
if (!request || typeof request !== 'object')
|
|
186
324
|
throw new TypeError('Use a named output request');
|
|
@@ -4,9 +4,21 @@ exports.defineTextTemplate = defineTextTemplate;
|
|
|
4
4
|
exports.defineSemanticSlots = defineSemanticSlots;
|
|
5
5
|
const rules_js_1 = require("../../utils/rules.js");
|
|
6
6
|
const observer_js_1 = require("../../utils/observer.js");
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The program owns the master; inserted model text is a value and is substituted once only.
|
|
9
|
+
*
|
|
10
|
+
* Substitution is single-pass `String.replace`: a value that itself contains `{{slot}}` is
|
|
11
|
+
* left as literal text, so a slot value cannot inject further substitutions.
|
|
12
|
+
*
|
|
13
|
+
* @param master - Template text using `{{slot}}` placeholders; slot names may repeat.
|
|
14
|
+
* @param options - Error wording and an optional observer for rendered text.
|
|
15
|
+
* @returns A frozen template exposing the deduplicated `slots` and `render(values)`.
|
|
16
|
+
* @throws Error From `render` when a referenced slot is missing from `values`.
|
|
17
|
+
*/
|
|
8
18
|
function defineTextTemplate(master, options = {}) {
|
|
9
|
-
const slots = Object.freeze([
|
|
19
|
+
const slots = Object.freeze([
|
|
20
|
+
...new Set([...master.matchAll(/\{\{(\w+)\}\}/g)].map((match) => match[1])),
|
|
21
|
+
]);
|
|
10
22
|
const errors = options.errors, missingField = errors?.missingField?.bind(errors), observe = options.observe?.bind(options);
|
|
11
23
|
return Object.freeze({
|
|
12
24
|
slots,
|
|
@@ -20,12 +32,26 @@ function defineTextTemplate(master, options = {}) {
|
|
|
20
32
|
},
|
|
21
33
|
});
|
|
22
34
|
}
|
|
23
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Models select public semantic keys; hosts retain private values and selection policy.
|
|
37
|
+
*
|
|
38
|
+
* A text is valid when it uses at most `maxOccurrences` namespaced slots, every name is a
|
|
39
|
+
* declared key, and no malformed `{{namespace` remnant is left behind — the last check stops
|
|
40
|
+
* partial or misspelled placeholders from reaching the template engine.
|
|
41
|
+
*
|
|
42
|
+
* @param definition - Namespace (lower-case words joined by hyphens), allowed keys and the
|
|
43
|
+
* occurrence limit (a non-negative safe integer, 0 forbidding the slot entirely).
|
|
44
|
+
* @returns A frozen validator with the namespace and `isValid(text)`.
|
|
45
|
+
* @throws TypeError For an invalid namespace or occurrence limit.
|
|
46
|
+
*/
|
|
24
47
|
function defineSemanticSlots(definition) {
|
|
25
48
|
const { namespace, maxOccurrences } = definition;
|
|
26
49
|
(0, rules_js_1.breakWhile)([
|
|
27
50
|
{ occur: () => !/^[a-z][a-z0-9-]*$/.test(namespace), error: 'Invalid slot namespace' },
|
|
28
|
-
{
|
|
51
|
+
{
|
|
52
|
+
occur: () => !Number.isSafeInteger(maxOccurrences) || maxOccurrences < 0,
|
|
53
|
+
error: 'Invalid slot limit',
|
|
54
|
+
},
|
|
29
55
|
]);
|
|
30
56
|
const keys = new Set(definition.keys);
|
|
31
57
|
const pattern = new RegExp(`\\{\\{${namespace}:([^{}]*)\\}\\}`, 'g');
|
|
@@ -33,7 +59,9 @@ function defineSemanticSlots(definition) {
|
|
|
33
59
|
namespace,
|
|
34
60
|
isValid(text) {
|
|
35
61
|
const matches = [...text.matchAll(pattern)];
|
|
36
|
-
return matches.length <= maxOccurrences &&
|
|
62
|
+
return (matches.length <= maxOccurrences &&
|
|
63
|
+
matches.every((match) => keys.has(match[1])) &&
|
|
64
|
+
!text.replace(pattern, '').includes(`{{${namespace}`));
|
|
37
65
|
},
|
|
38
66
|
});
|
|
39
67
|
}
|
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Presentation Kit: variant selection and preference resolution over App-supplied values.
|
|
4
|
+
*
|
|
5
|
+
* Place in the package: part of the `presentation` Kit. Copy, priorities and randomness are
|
|
6
|
+
* App policy; this module only applies a deterministic rule to what it is given.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `selectVariant`, `resolvePreference`.
|
|
9
|
+
*/
|
|
2
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
11
|
exports.selectVariant = selectVariant;
|
|
4
12
|
exports.resolvePreference = resolvePreference;
|
|
13
|
+
/**
|
|
14
|
+
* Pick one variant, avoiding an immediate repeat when alternatives exist.
|
|
15
|
+
*
|
|
16
|
+
* When every candidate equals `previous`, the full list is used again, so a single-value set
|
|
17
|
+
* still yields a result instead of failing.
|
|
18
|
+
*
|
|
19
|
+
* @param values - Candidate variants; an empty list returns `undefined`.
|
|
20
|
+
* @param options - Previous value to avoid and a random index source in `[0, limit)`.
|
|
21
|
+
* @returns The selected value, or `undefined` when there are no candidates.
|
|
22
|
+
* @throws TypeError When `randomIndex` returns a non-integer or an out-of-range index.
|
|
23
|
+
*/
|
|
5
24
|
function selectVariant(values, options) {
|
|
6
25
|
if (!values.length)
|
|
7
26
|
return undefined;
|
|
8
|
-
const candidates = values.length > 1 ? values.filter(value => value !== options.previous) : [...values];
|
|
27
|
+
const candidates = values.length > 1 ? values.filter((value) => value !== options.previous) : [...values];
|
|
9
28
|
const pool = candidates.length ? candidates : [...values];
|
|
10
29
|
if (pool.length === 1)
|
|
11
30
|
return pool[0];
|
|
@@ -14,8 +33,18 @@ function selectVariant(values, options) {
|
|
|
14
33
|
throw new TypeError('Invalid variant index');
|
|
15
34
|
return pool[index];
|
|
16
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Resolve the preferred candidate.
|
|
38
|
+
*
|
|
39
|
+
* Highest `priority` wins; `order` breaks ties with the later entry first, so recency can be
|
|
40
|
+
* encoded without touching priority. The input array is copied before sorting.
|
|
41
|
+
*
|
|
42
|
+
* @param candidates - Values with a priority and an order marker.
|
|
43
|
+
* @returns The winning value, or `undefined` for an empty list.
|
|
44
|
+
* @throws TypeError When any priority or order is not finite.
|
|
45
|
+
*/
|
|
17
46
|
function resolvePreference(candidates) {
|
|
18
|
-
if (candidates.some(item => !Number.isFinite(item.priority) || !Number.isFinite(item.order)))
|
|
47
|
+
if (candidates.some((item) => !Number.isFinite(item.priority) || !Number.isFinite(item.order)))
|
|
19
48
|
throw new TypeError('Invalid preference priority');
|
|
20
49
|
return [...candidates].sort((left, right) => right.priority - left.priority || right.order - left.order)[0]?.value;
|
|
21
50
|
}
|