@jangts/agent-core 0.1.1 → 0.2.1
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 +25 -0
- package/LICENSE +55 -0
- package/NOTICE +6 -0
- package/README.md +8 -0
- package/development/docs/README.en.md +70 -0
- package/development/docs/README.md +1 -1
- package/development/docs/acceptance.en.md +34 -0
- package/development/docs/agent-development.en.md +42 -0
- package/development/docs/api/README.en.md +62 -0
- package/development/docs/api/advanced-agents.en.md +135 -0
- package/development/docs/api/context-processing.en.md +110 -0
- package/development/docs/api/core.en.md +274 -0
- package/development/docs/api/examples.en.md +118 -0
- package/development/docs/api/kits.en.md +183 -0
- package/development/docs/api/knowledge-answering.en.md +166 -0
- package/development/docs/api/mock.en.md +186 -0
- package/development/docs/api/observability.en.md +166 -0
- package/development/docs/api/reference.en.md +2235 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.en.md +252 -0
- package/development/docs/api/support.md +27 -0
- package/development/docs/api/types.en.md +181 -0
- package/development/docs/api/workflow.en.md +188 -0
- package/development/docs/basic-usage.en.md +78 -0
- package/development/docs/create-app.en.md +76 -0
- package/development/docs/examples/offline-agent.en.md +273 -0
- package/development/docs/examples.en.md +36 -0
- package/development/docs/flows/knowledge-maintenance.en.md +38 -0
- package/development/docs/getting-started.en.md +71 -0
- package/development/docs/knowledge.en.md +89 -0
- package/development/docs/maintenance.en.md +62 -0
- package/development/docs/materials.en.md +38 -0
- package/development/docs/mechanisms.en.md +227 -0
- package/development/docs/memory-and-learning.en.md +42 -0
- package/development/docs/operations.en.md +51 -0
- package/development/docs/records.en.md +63 -0
- package/development/docs/registration.en.md +63 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +286 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +77 -16
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +46 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +62 -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 +17 -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 +33 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +107 -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.d.ts +6 -0
- package/dist/esm/diagnostics/catalog.js +17 -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 +39 -0
- package/dist/esm/structs/kits/search.d.ts +24 -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 +34 -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 +54 -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 +65 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +152 -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 +34 -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 +11 -0
- package/dist/esm/support/model/completion/default.js +30 -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 +16 -0
- package/dist/esm/support/model/completion/session.js +104 -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 +26 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +22 -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 +28 -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 +7 -3
|
@@ -1,17 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presentation Kit: declarative output contracts for text, master, record and group outputs.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: part of the `presentation` Kit. A definition decides which fields the
|
|
5
|
+
* model generates, which are bound to App providers, which are constants and which select a
|
|
6
|
+
* semantic key; this module validates those declarations and composes the final value.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `defineOutputCatalog`, and the output definition/field/provider/result types.
|
|
9
|
+
*/
|
|
1
10
|
import { snapshotSchemaAdapter } from '../../utils/schema-adapter.js';
|
|
2
11
|
import { readonlyCatalog } from '../../utils/catalog.js';
|
|
3
12
|
import { synchronous } from '../../utils/synchronous.js';
|
|
4
13
|
import { defineTextTemplate } from './templates.js';
|
|
5
14
|
import { freezeSchema } from '../../utils/object.js';
|
|
6
15
|
import { observeSafely } from '../../utils/observer.js';
|
|
7
|
-
function snapshotValue(value) {
|
|
8
|
-
const
|
|
16
|
+
function snapshotValue(value) {
|
|
17
|
+
const copy = structuredClone(value);
|
|
18
|
+
freezeSchema(copy);
|
|
19
|
+
return copy;
|
|
20
|
+
}
|
|
21
|
+
const textValueSchema = snapshotSchemaAdapter({
|
|
22
|
+
jsonSchema: { type: 'string' },
|
|
23
|
+
parse(value) {
|
|
9
24
|
if (typeof value !== 'string')
|
|
10
25
|
throw new TypeError('Invalid output field value');
|
|
11
26
|
return value;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
function parseField(field, value) {
|
|
30
|
+
return field.valueSchema.parse(value);
|
|
31
|
+
}
|
|
32
|
+
// Object-prototype names are excluded so a field id can never shadow `__proto__` or replace a
|
|
33
|
+
// prototype member when values are assembled into a dictionary.
|
|
34
|
+
const validId = (id) => typeof id === 'string' &&
|
|
35
|
+
/^[A-Za-z][A-Za-z0-9_.-]*$/.test(id) &&
|
|
36
|
+
!['__proto__', 'constructor', 'prototype'].includes(id);
|
|
37
|
+
/**
|
|
38
|
+
* Compile output definitions into one catalog.
|
|
39
|
+
*
|
|
40
|
+
* Compilation is where most mistakes surface: group membership is checked for cycles, master
|
|
41
|
+
* templates must have exactly one slot per field, and every `bound`/`semantic` field must name
|
|
42
|
+
* a registered provider. Composition then trusts the compiled catalog.
|
|
43
|
+
*
|
|
44
|
+
* @param definitions - Output definitions with unique ids and a supported `kind`.
|
|
45
|
+
* @param options - Provider list and an optional observer for composed results.
|
|
46
|
+
* @returns A frozen catalog extended with `toModelSchema`, `check` and `compose`.
|
|
47
|
+
* @throws TypeError For an invalid id or kind, a malformed group, mismatched master slots,
|
|
48
|
+
* an invalid field owner or semantic keys, or an unknown provider id.
|
|
49
|
+
*/
|
|
15
50
|
export function defineOutputCatalog(definitions, options = {}) {
|
|
16
51
|
const providers = options.providers ?? [], observe = options.observe?.bind(options);
|
|
17
52
|
const providerMap = new Map();
|
|
@@ -27,42 +62,70 @@ export function defineOutputCatalog(definitions, options = {}) {
|
|
|
27
62
|
const { id, kind, fields: fieldDefinitions, master, maxItems, allowedOutputIds } = definition;
|
|
28
63
|
if (!validId(id) || catalog.has(id) || !['text', 'master', 'record', 'group'].includes(kind))
|
|
29
64
|
throw new TypeError('Invalid output definition');
|
|
30
|
-
const fields = fieldDefinitions?.map(field => {
|
|
65
|
+
const fields = fieldDefinitions?.map((field) => {
|
|
31
66
|
const { id, owner, required, valueSchema, providerId, constantValue, semanticKeys } = field;
|
|
32
|
-
return Object.freeze({
|
|
33
|
-
|
|
34
|
-
|
|
67
|
+
return Object.freeze({
|
|
68
|
+
id,
|
|
69
|
+
owner,
|
|
70
|
+
required,
|
|
71
|
+
valueSchema: valueSchema === undefined ? textValueSchema : snapshotSchemaAdapter(valueSchema),
|
|
72
|
+
providerId,
|
|
73
|
+
constantValue: owner === 'constant' ? snapshotValue(constantValue) : undefined,
|
|
74
|
+
semanticKeys: semanticKeys === undefined ? undefined : Object.freeze([...semanticKeys]),
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
const entry = Object.freeze({
|
|
78
|
+
id,
|
|
79
|
+
kind,
|
|
80
|
+
master,
|
|
81
|
+
maxItems,
|
|
82
|
+
fields: fields ? Object.freeze(fields) : undefined,
|
|
83
|
+
allowedOutputIds: allowedOutputIds === undefined ? undefined : Object.freeze([...allowedOutputIds]),
|
|
35
84
|
});
|
|
36
|
-
const entry = Object.freeze({ id, kind, master, maxItems, fields: fields ? Object.freeze(fields) : undefined,
|
|
37
|
-
allowedOutputIds: allowedOutputIds === undefined ? undefined : Object.freeze([...allowedOutputIds]) });
|
|
38
85
|
if (entry.kind === 'group') {
|
|
39
|
-
if (entry.fields?.length ||
|
|
86
|
+
if (entry.fields?.length ||
|
|
87
|
+
entry.master !== undefined ||
|
|
88
|
+
!entry.allowedOutputIds?.length ||
|
|
89
|
+
new Set(entry.allowedOutputIds).size !== entry.allowedOutputIds.length ||
|
|
90
|
+
!Number.isSafeInteger(entry.maxItems) ||
|
|
91
|
+
entry.maxItems < 1)
|
|
40
92
|
throw new TypeError('Invalid output group');
|
|
41
93
|
}
|
|
42
94
|
else {
|
|
43
|
-
if (!fields?.length ||
|
|
95
|
+
if (!fields?.length ||
|
|
96
|
+
new Set(fields.map((field) => field.id)).size !== fields.length ||
|
|
97
|
+
(entry.kind === 'text' && (fields.length !== 1 || fields[0].required === false)))
|
|
44
98
|
throw new TypeError('Invalid output fields');
|
|
45
99
|
for (const field of fields) {
|
|
46
|
-
if (!validId(field.id) ||
|
|
100
|
+
if (!validId(field.id) ||
|
|
101
|
+
!['generated', 'bound', 'constant', 'semantic'].includes(field.owner))
|
|
47
102
|
throw new TypeError('Invalid output ownership');
|
|
48
103
|
if (['bound', 'semantic'].includes(field.owner) && !providerMap.has(field.providerId))
|
|
49
104
|
throw new TypeError(`Unknown output provider: ${field.providerId}`);
|
|
50
|
-
if (field.owner === 'semantic' &&
|
|
105
|
+
if (field.owner === 'semantic' &&
|
|
106
|
+
(!field.semanticKeys?.length ||
|
|
107
|
+
new Set(field.semanticKeys).size !== field.semanticKeys.length ||
|
|
108
|
+
field.semanticKeys.some((key) => typeof key !== 'string' || !key)))
|
|
51
109
|
throw new TypeError('Invalid semantic output keys');
|
|
52
110
|
}
|
|
53
111
|
if (entry.kind === 'master') {
|
|
54
112
|
if (typeof entry.master !== 'string')
|
|
55
113
|
throw new TypeError('Missing output master');
|
|
56
114
|
const template = defineTextTemplate(entry.master);
|
|
57
|
-
if (template.slots.length !== fields.length ||
|
|
115
|
+
if (template.slots.length !== fields.length ||
|
|
116
|
+
template.slots.some((id) => !fields.some((field) => field.id === id)))
|
|
58
117
|
throw new TypeError('Output master fields do not match slots');
|
|
59
118
|
masters.set(entry.id, template);
|
|
60
119
|
}
|
|
61
120
|
}
|
|
62
121
|
catalog.set(entry.id, entry);
|
|
63
122
|
}
|
|
64
|
-
const get = (id) => {
|
|
65
|
-
|
|
123
|
+
const get = (id) => {
|
|
124
|
+
const entry = catalog.get(id);
|
|
125
|
+
if (!entry)
|
|
126
|
+
throw new TypeError(`Unknown output: ${id}`);
|
|
127
|
+
return entry;
|
|
128
|
+
};
|
|
66
129
|
const visited = new Set(), visiting = new Set();
|
|
67
130
|
function checkRefs(id) {
|
|
68
131
|
if (visited.has(id))
|
|
@@ -78,13 +141,23 @@ export function defineOutputCatalog(definitions, options = {}) {
|
|
|
78
141
|
for (const id of catalog.keys())
|
|
79
142
|
checkRefs(id);
|
|
80
143
|
// Both callers reject groups before asking for their validated nonempty fields.
|
|
81
|
-
const modelFields = (entry) => entry.fields.filter(field => ['generated', 'semantic'].includes(field.owner));
|
|
144
|
+
const modelFields = (entry) => entry.fields.filter((field) => ['generated', 'semantic'].includes(field.owner));
|
|
82
145
|
function toModelSchema(id) {
|
|
83
146
|
const entry = get(id);
|
|
84
147
|
if (entry.kind === 'group')
|
|
85
148
|
throw new TypeError('Output groups require program-assigned items');
|
|
86
149
|
const fields = modelFields(entry);
|
|
87
|
-
return {
|
|
150
|
+
return {
|
|
151
|
+
type: 'object',
|
|
152
|
+
properties: Object.fromEntries(fields.map((field) => [
|
|
153
|
+
field.id,
|
|
154
|
+
field.owner === 'semantic'
|
|
155
|
+
? { type: 'string', enum: [...field.semanticKeys] }
|
|
156
|
+
: field.valueSchema.jsonSchema,
|
|
157
|
+
])),
|
|
158
|
+
required: fields.filter((field) => field.required !== false).map((field) => field.id),
|
|
159
|
+
additionalProperties: false,
|
|
160
|
+
};
|
|
88
161
|
}
|
|
89
162
|
function inspect(id, value, signal) {
|
|
90
163
|
signal?.throwIfAborted();
|
|
@@ -93,16 +166,27 @@ export function defineOutputCatalog(definitions, options = {}) {
|
|
|
93
166
|
throw new TypeError('Inspect individual group items');
|
|
94
167
|
const issues = [], values = Object.create(null);
|
|
95
168
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
96
|
-
return {
|
|
169
|
+
return {
|
|
170
|
+
values,
|
|
171
|
+
issues: [{ path: [id], code: 'OUTPUT_SHAPE', message: 'Expected an output object' }],
|
|
172
|
+
};
|
|
97
173
|
const input = value, fields = modelFields(entry);
|
|
98
174
|
for (const key of Object.keys(input))
|
|
99
|
-
if (!fields.some(field => field.id === key))
|
|
100
|
-
issues.push({
|
|
175
|
+
if (!fields.some((field) => field.id === key))
|
|
176
|
+
issues.push({
|
|
177
|
+
path: [id, key],
|
|
178
|
+
code: 'OUTPUT_FOREIGN_FIELD',
|
|
179
|
+
message: 'Unknown generated field',
|
|
180
|
+
});
|
|
101
181
|
for (const field of fields) {
|
|
102
182
|
signal?.throwIfAborted();
|
|
103
183
|
if (!Object.hasOwn(input, field.id)) {
|
|
104
184
|
if (field.required !== false)
|
|
105
|
-
issues.push({
|
|
185
|
+
issues.push({
|
|
186
|
+
path: [id, field.id],
|
|
187
|
+
code: 'OUTPUT_MISSING',
|
|
188
|
+
message: 'Required generated field is missing',
|
|
189
|
+
});
|
|
106
190
|
continue;
|
|
107
191
|
}
|
|
108
192
|
const value = input[field.id];
|
|
@@ -118,9 +202,16 @@ export function defineOutputCatalog(definitions, options = {}) {
|
|
|
118
202
|
}
|
|
119
203
|
catch (error) {
|
|
120
204
|
signal?.throwIfAborted();
|
|
121
|
-
if (error &&
|
|
205
|
+
if (error &&
|
|
206
|
+
typeof error === 'object' &&
|
|
207
|
+
'name' in error &&
|
|
208
|
+
['AbortError', 'TimeoutError'].includes(String(error.name)))
|
|
122
209
|
throw error;
|
|
123
|
-
issues.push({
|
|
210
|
+
issues.push({
|
|
211
|
+
path: [id, field.id],
|
|
212
|
+
code: 'OUTPUT_VALUE',
|
|
213
|
+
message: 'Generated field does not match its schema',
|
|
214
|
+
});
|
|
124
215
|
}
|
|
125
216
|
signal?.throwIfAborted();
|
|
126
217
|
}
|
|
@@ -131,16 +222,25 @@ export function defineOutputCatalog(definitions, options = {}) {
|
|
|
131
222
|
const entry = get(id), { generated, items } = input;
|
|
132
223
|
context.signal.throwIfAborted();
|
|
133
224
|
if (entry.kind === 'group') {
|
|
134
|
-
if (Object.keys(generated ?? {}).length ||
|
|
225
|
+
if (Object.keys(generated ?? {}).length ||
|
|
226
|
+
!Array.isArray(items) ||
|
|
227
|
+
items.length > entry.maxItems)
|
|
135
228
|
throw new TypeError('Invalid output group items');
|
|
136
|
-
const assigned = items.map((item) => ({
|
|
137
|
-
|
|
229
|
+
const assigned = items.map((item) => ({
|
|
230
|
+
id: item.id,
|
|
231
|
+
outputId: item.outputId,
|
|
232
|
+
input: item.input,
|
|
233
|
+
}));
|
|
234
|
+
if (new Set(assigned.map((item) => item.id)).size !== assigned.length)
|
|
138
235
|
throw new TypeError('Invalid output group items');
|
|
139
|
-
const value = assigned.map(item => {
|
|
236
|
+
const value = assigned.map((item) => {
|
|
140
237
|
context.signal.throwIfAborted();
|
|
141
238
|
if (!validId(item.id) || !entry.allowedOutputIds.includes(item.outputId))
|
|
142
239
|
throw new TypeError('Invalid output group reference');
|
|
143
|
-
return Object.freeze({
|
|
240
|
+
return Object.freeze({
|
|
241
|
+
id: item.id,
|
|
242
|
+
...composeInternal(item.outputId, item.input, context),
|
|
243
|
+
});
|
|
144
244
|
});
|
|
145
245
|
context.signal.throwIfAborted();
|
|
146
246
|
return Object.freeze({ outputId: id, kind: entry.kind, value: Object.freeze(value) });
|
|
@@ -148,17 +248,26 @@ export function defineOutputCatalog(definitions, options = {}) {
|
|
|
148
248
|
const checked = inspect(id, generated ?? {}, context.signal);
|
|
149
249
|
context.signal.throwIfAborted();
|
|
150
250
|
if (checked.issues.length)
|
|
151
|
-
throw Object.assign(new TypeError('Output contract rejected generated fields'), {
|
|
251
|
+
throw Object.assign(new TypeError('Output contract rejected generated fields'), {
|
|
252
|
+
issues: checked.issues,
|
|
253
|
+
});
|
|
152
254
|
const values = Object.create(null);
|
|
153
255
|
for (const field of entry.fields) {
|
|
154
256
|
context.signal.throwIfAborted();
|
|
155
|
-
if (['generated', 'semantic'].includes(field.owner) &&
|
|
257
|
+
if (['generated', 'semantic'].includes(field.owner) &&
|
|
258
|
+
!Object.hasOwn(checked.values, field.id) &&
|
|
259
|
+
field.required === false) {
|
|
156
260
|
if (entry.kind === 'master')
|
|
157
261
|
values[field.id] = '';
|
|
158
262
|
continue;
|
|
159
263
|
}
|
|
160
|
-
const value = field.owner === 'constant'
|
|
161
|
-
?
|
|
264
|
+
const value = field.owner === 'constant'
|
|
265
|
+
? field.constantValue
|
|
266
|
+
: ['bound', 'semantic'].includes(field.owner)
|
|
267
|
+
? synchronous(providerMap.get(field.providerId).resolve({
|
|
268
|
+
key: field.owner === 'semantic' ? checked.values[field.id] : undefined,
|
|
269
|
+
}, context), 'Output providers must be synchronous')
|
|
270
|
+
: checked.values[field.id];
|
|
162
271
|
context.signal.throwIfAborted();
|
|
163
272
|
if (value === undefined && field.required === false) {
|
|
164
273
|
if (entry.kind === 'master')
|
|
@@ -168,7 +277,11 @@ export function defineOutputCatalog(definitions, options = {}) {
|
|
|
168
277
|
values[field.id] = field.owner === 'generated' ? value : parseField(field, value);
|
|
169
278
|
context.signal.throwIfAborted();
|
|
170
279
|
}
|
|
171
|
-
const value = entry.kind === 'master'
|
|
280
|
+
const value = entry.kind === 'master'
|
|
281
|
+
? masters.get(id).render(values)
|
|
282
|
+
: entry.kind === 'text'
|
|
283
|
+
? values[entry.fields[0].id]
|
|
284
|
+
: Object.freeze(values);
|
|
172
285
|
if ((entry.kind === 'text' || entry.kind === 'master') && typeof value !== 'string')
|
|
173
286
|
throw new TypeError('Text output requires a string value');
|
|
174
287
|
const result = Object.freeze({ outputId: id, kind: entry.kind, value });
|
|
@@ -176,8 +289,33 @@ export function defineOutputCatalog(definitions, options = {}) {
|
|
|
176
289
|
observeSafely(observe, result);
|
|
177
290
|
return result;
|
|
178
291
|
}
|
|
179
|
-
return Object.freeze({
|
|
180
|
-
|
|
292
|
+
return Object.freeze({
|
|
293
|
+
...readonlyCatalog(catalog.values(), (id) => new TypeError(`Unknown output: ${id}`)),
|
|
294
|
+
/** JSON schema of the fields a model must generate for this output. */
|
|
295
|
+
toModelSchema,
|
|
296
|
+
/**
|
|
297
|
+
* Validate a generated value without composing it.
|
|
298
|
+
*
|
|
299
|
+
* @param request - Output id and the candidate value.
|
|
300
|
+
* @returns `passed` or `failed` with the collected issues and accepted values.
|
|
301
|
+
*/
|
|
302
|
+
check(request) {
|
|
303
|
+
const result = inspect(request.outputId, request.value);
|
|
304
|
+
return {
|
|
305
|
+
status: result.issues.length ? 'failed' : 'passed',
|
|
306
|
+
value: result.values,
|
|
307
|
+
issues: result.issues,
|
|
308
|
+
};
|
|
309
|
+
},
|
|
310
|
+
/**
|
|
311
|
+
* Compose the final output value from generated fields, providers and constants.
|
|
312
|
+
*
|
|
313
|
+
* @param request - Output id and the generated/group input.
|
|
314
|
+
* @param context - Operation context; cancellation is checked between every step.
|
|
315
|
+
* @returns The frozen composed result, also forwarded to the observer.
|
|
316
|
+
* @throws TypeError For a malformed request, missing context, rejected generated fields
|
|
317
|
+
* (carrying `issues`), a non-synchronous provider, or a text output that is not a string.
|
|
318
|
+
*/
|
|
181
319
|
compose(request, context) {
|
|
182
320
|
if (!request || typeof request !== 'object')
|
|
183
321
|
throw new TypeError('Use a named output request');
|
|
@@ -1,12 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presentation Kit: text masters with substituted slots and semantic-slot validation.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: part of the `presentation` Kit. The program owns each master; model
|
|
5
|
+
* output only supplies slot values, so generated text can never introduce new template syntax.
|
|
6
|
+
*
|
|
7
|
+
* Exports: `defineTextTemplate`, `defineSemanticSlots`, and the template definition types.
|
|
8
|
+
*/
|
|
1
9
|
import type { SemanticSlotDefinition, TextTemplateOptions } from '../../structs/kits/presentation/templates.js';
|
|
2
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The program owns the master; inserted model text is a value and is substituted once only.
|
|
12
|
+
*
|
|
13
|
+
* Substitution is single-pass `String.replace`: a value that itself contains `{{slot}}` is
|
|
14
|
+
* left as literal text, so a slot value cannot inject further substitutions.
|
|
15
|
+
*
|
|
16
|
+
* @param master - Template text using `{{slot}}` placeholders; slot names may repeat.
|
|
17
|
+
* @param options - Error wording and an optional observer for rendered text.
|
|
18
|
+
* @returns A frozen template exposing the deduplicated `slots` and `render(values)`.
|
|
19
|
+
* @throws Error From `render` when a referenced slot is missing from `values`.
|
|
20
|
+
*/
|
|
3
21
|
export declare function defineTextTemplate(master: string, options?: TextTemplateOptions): Readonly<{
|
|
4
22
|
slots: readonly string[];
|
|
5
23
|
render(values: Readonly<Record<string, string>>): string;
|
|
6
24
|
}>;
|
|
7
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Models select public semantic keys; hosts retain private values and selection policy.
|
|
27
|
+
*
|
|
28
|
+
* A text is valid when it uses at most `maxOccurrences` namespaced slots, every name is a
|
|
29
|
+
* declared key, and no malformed `{{namespace` remnant is left behind — the last check stops
|
|
30
|
+
* partial or misspelled placeholders from reaching the template engine.
|
|
31
|
+
*
|
|
32
|
+
* @param definition - Namespace (lower-case words joined by hyphens), allowed keys and the
|
|
33
|
+
* occurrence limit (a non-negative safe integer, 0 forbidding the slot entirely).
|
|
34
|
+
* @returns A frozen validator with the namespace and `isValid(text)`.
|
|
35
|
+
* @throws TypeError For an invalid namespace or occurrence limit.
|
|
36
|
+
*/
|
|
8
37
|
export declare function defineSemanticSlots(definition: SemanticSlotDefinition): Readonly<{
|
|
9
38
|
namespace: string;
|
|
10
39
|
isValid(text: string): boolean;
|
|
11
40
|
}>;
|
|
12
|
-
export type { SemanticSlotDefinition, TextTemplateOptions } from '../../structs/kits/presentation/templates.js';
|
|
41
|
+
export type { SemanticSlotDefinition, TextTemplateOptions, } from '../../structs/kits/presentation/templates.js';
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { breakWhile } from '../../utils/rules.js';
|
|
2
2
|
import { observeSafely } from '../../utils/observer.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* The program owns the master; inserted model text is a value and is substituted once only.
|
|
5
|
+
*
|
|
6
|
+
* Substitution is single-pass `String.replace`: a value that itself contains `{{slot}}` is
|
|
7
|
+
* left as literal text, so a slot value cannot inject further substitutions.
|
|
8
|
+
*
|
|
9
|
+
* @param master - Template text using `{{slot}}` placeholders; slot names may repeat.
|
|
10
|
+
* @param options - Error wording and an optional observer for rendered text.
|
|
11
|
+
* @returns A frozen template exposing the deduplicated `slots` and `render(values)`.
|
|
12
|
+
* @throws Error From `render` when a referenced slot is missing from `values`.
|
|
13
|
+
*/
|
|
4
14
|
export function defineTextTemplate(master, options = {}) {
|
|
5
|
-
const slots = Object.freeze([
|
|
15
|
+
const slots = Object.freeze([
|
|
16
|
+
...new Set([...master.matchAll(/\{\{(\w+)\}\}/g)].map((match) => match[1])),
|
|
17
|
+
]);
|
|
6
18
|
const errors = options.errors, missingField = errors?.missingField?.bind(errors), observe = options.observe?.bind(options);
|
|
7
19
|
return Object.freeze({
|
|
8
20
|
slots,
|
|
@@ -16,12 +28,26 @@ export function defineTextTemplate(master, options = {}) {
|
|
|
16
28
|
},
|
|
17
29
|
});
|
|
18
30
|
}
|
|
19
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Models select public semantic keys; hosts retain private values and selection policy.
|
|
33
|
+
*
|
|
34
|
+
* A text is valid when it uses at most `maxOccurrences` namespaced slots, every name is a
|
|
35
|
+
* declared key, and no malformed `{{namespace` remnant is left behind — the last check stops
|
|
36
|
+
* partial or misspelled placeholders from reaching the template engine.
|
|
37
|
+
*
|
|
38
|
+
* @param definition - Namespace (lower-case words joined by hyphens), allowed keys and the
|
|
39
|
+
* occurrence limit (a non-negative safe integer, 0 forbidding the slot entirely).
|
|
40
|
+
* @returns A frozen validator with the namespace and `isValid(text)`.
|
|
41
|
+
* @throws TypeError For an invalid namespace or occurrence limit.
|
|
42
|
+
*/
|
|
20
43
|
export function defineSemanticSlots(definition) {
|
|
21
44
|
const { namespace, maxOccurrences } = definition;
|
|
22
45
|
breakWhile([
|
|
23
46
|
{ occur: () => !/^[a-z][a-z0-9-]*$/.test(namespace), error: 'Invalid slot namespace' },
|
|
24
|
-
{
|
|
47
|
+
{
|
|
48
|
+
occur: () => !Number.isSafeInteger(maxOccurrences) || maxOccurrences < 0,
|
|
49
|
+
error: 'Invalid slot limit',
|
|
50
|
+
},
|
|
25
51
|
]);
|
|
26
52
|
const keys = new Set(definition.keys);
|
|
27
53
|
const pattern = new RegExp(`\\{\\{${namespace}:([^{}]*)\\}\\}`, 'g');
|
|
@@ -29,7 +55,9 @@ export function defineSemanticSlots(definition) {
|
|
|
29
55
|
namespace,
|
|
30
56
|
isValid(text) {
|
|
31
57
|
const matches = [...text.matchAll(pattern)];
|
|
32
|
-
return matches.length <= maxOccurrences &&
|
|
58
|
+
return (matches.length <= maxOccurrences &&
|
|
59
|
+
matches.every((match) => keys.has(match[1])) &&
|
|
60
|
+
!text.replace(pattern, '').includes(`{{${namespace}`));
|
|
33
61
|
},
|
|
34
62
|
});
|
|
35
63
|
}
|
|
@@ -1,7 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presentation Kit: variant selection and preference resolution over App-supplied values.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: part of the `presentation` Kit. Copy, priorities and randomness are
|
|
5
|
+
* App policy; this module only applies a deterministic rule to what it is given.
|
|
6
|
+
*
|
|
7
|
+
* Exports: `selectVariant`, `resolvePreference`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Pick one variant, avoiding an immediate repeat when alternatives exist.
|
|
11
|
+
*
|
|
12
|
+
* When every candidate equals `previous`, the full list is used again, so a single-value set
|
|
13
|
+
* still yields a result instead of failing.
|
|
14
|
+
*
|
|
15
|
+
* @param values - Candidate variants; an empty list returns `undefined`.
|
|
16
|
+
* @param options - Previous value to avoid and a random index source in `[0, limit)`.
|
|
17
|
+
* @returns The selected value, or `undefined` when there are no candidates.
|
|
18
|
+
* @throws TypeError When `randomIndex` returns a non-integer or an out-of-range index.
|
|
19
|
+
*/
|
|
1
20
|
export declare function selectVariant<Value>(values: readonly Value[], options: {
|
|
2
21
|
previous?: Value;
|
|
3
22
|
randomIndex(limit: number): number;
|
|
4
23
|
}): Value | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the preferred candidate.
|
|
26
|
+
*
|
|
27
|
+
* Highest `priority` wins; `order` breaks ties with the later entry first, so recency can be
|
|
28
|
+
* encoded without touching priority. The input array is copied before sorting.
|
|
29
|
+
*
|
|
30
|
+
* @param candidates - Values with a priority and an order marker.
|
|
31
|
+
* @returns The winning value, or `undefined` for an empty list.
|
|
32
|
+
* @throws TypeError When any priority or order is not finite.
|
|
33
|
+
*/
|
|
5
34
|
export declare function resolvePreference<Value>(candidates: readonly {
|
|
6
35
|
value: Value;
|
|
7
36
|
priority: number;
|
|
@@ -1,7 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presentation Kit: variant selection and preference resolution over App-supplied values.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: part of the `presentation` Kit. Copy, priorities and randomness are
|
|
5
|
+
* App policy; this module only applies a deterministic rule to what it is given.
|
|
6
|
+
*
|
|
7
|
+
* Exports: `selectVariant`, `resolvePreference`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Pick one variant, avoiding an immediate repeat when alternatives exist.
|
|
11
|
+
*
|
|
12
|
+
* When every candidate equals `previous`, the full list is used again, so a single-value set
|
|
13
|
+
* still yields a result instead of failing.
|
|
14
|
+
*
|
|
15
|
+
* @param values - Candidate variants; an empty list returns `undefined`.
|
|
16
|
+
* @param options - Previous value to avoid and a random index source in `[0, limit)`.
|
|
17
|
+
* @returns The selected value, or `undefined` when there are no candidates.
|
|
18
|
+
* @throws TypeError When `randomIndex` returns a non-integer or an out-of-range index.
|
|
19
|
+
*/
|
|
1
20
|
export function selectVariant(values, options) {
|
|
2
21
|
if (!values.length)
|
|
3
22
|
return undefined;
|
|
4
|
-
const candidates = values.length > 1 ? values.filter(value => value !== options.previous) : [...values];
|
|
23
|
+
const candidates = values.length > 1 ? values.filter((value) => value !== options.previous) : [...values];
|
|
5
24
|
const pool = candidates.length ? candidates : [...values];
|
|
6
25
|
if (pool.length === 1)
|
|
7
26
|
return pool[0];
|
|
@@ -10,8 +29,18 @@ export function selectVariant(values, options) {
|
|
|
10
29
|
throw new TypeError('Invalid variant index');
|
|
11
30
|
return pool[index];
|
|
12
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Resolve the preferred candidate.
|
|
34
|
+
*
|
|
35
|
+
* Highest `priority` wins; `order` breaks ties with the later entry first, so recency can be
|
|
36
|
+
* encoded without touching priority. The input array is copied before sorting.
|
|
37
|
+
*
|
|
38
|
+
* @param candidates - Values with a priority and an order marker.
|
|
39
|
+
* @returns The winning value, or `undefined` for an empty list.
|
|
40
|
+
* @throws TypeError When any priority or order is not finite.
|
|
41
|
+
*/
|
|
13
42
|
export function resolvePreference(candidates) {
|
|
14
|
-
if (candidates.some(item => !Number.isFinite(item.priority) || !Number.isFinite(item.order)))
|
|
43
|
+
if (candidates.some((item) => !Number.isFinite(item.priority) || !Number.isFinite(item.order)))
|
|
15
44
|
throw new TypeError('Invalid preference priority');
|
|
16
45
|
return [...candidates].sort((left, right) => right.priority - left.priority || right.order - left.order)[0]?.value;
|
|
17
46
|
}
|
|
@@ -1,18 +1,55 @@
|
|
|
1
1
|
import type { ContentProjectionOptions, ContentProjection, TreeProjectionOptions } from '../structs/kits/projection.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Compile a JSON-preserving projector.
|
|
4
|
+
*
|
|
5
|
+
* Keep valid JSON while reducing prose before dropping records; budgets are caller policy.
|
|
6
|
+
* The candidate list is tried in order (outer `counts`, inner `lengths`), so callers control
|
|
7
|
+
* whether trimming text or dropping items is preferred, and the configured fallback is used
|
|
8
|
+
* only when no candidate fits.
|
|
9
|
+
*
|
|
10
|
+
* @param options - Candidate bounds, a synchronous renderer and a synchronous fallback factory.
|
|
11
|
+
* @returns A frozen object whose `project({ value, maxChars })` returns `{ text, truncated }`.
|
|
12
|
+
* @throws TypeError For a negative or non-integer `maxChars`, or a non-synchronous renderer;
|
|
13
|
+
* a `CONTEXT_BUDGET` `ValidationError` from the budget check when even the fallback is long.
|
|
14
|
+
*/
|
|
3
15
|
export declare function defineContentProjection(options: ContentProjectionOptions): Readonly<{
|
|
4
|
-
project: ({ value, maxChars: limit }: {
|
|
16
|
+
project: ({ value, maxChars: limit, }: {
|
|
5
17
|
value: unknown;
|
|
6
18
|
maxChars: number;
|
|
7
19
|
}) => ContentProjection;
|
|
8
20
|
}>;
|
|
9
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Project a continuous excerpt of a body by binary-searching the longest prefix that fits.
|
|
23
|
+
*
|
|
24
|
+
* Binary-search a continuous prefix and keep an existing surrogate pair intact. `render`
|
|
25
|
+
* receives the prefix length, not the text, so the caller decides how the excerpt is framed.
|
|
26
|
+
*
|
|
27
|
+
* @param body - Source text whose length bounds the search.
|
|
28
|
+
* @param limit - Maximum rendered length in characters.
|
|
29
|
+
* @param render - Synchronous renderer for a given prefix length.
|
|
30
|
+
* @returns The fitting projection, or `undefined` when even the empty excerpt does not fit.
|
|
31
|
+
* @throws TypeError For an invalid limit or a non-synchronous renderer; a `CONTEXT_BUDGET`
|
|
32
|
+
* `ValidationError` when the chosen excerpt still exceeds the budget.
|
|
33
|
+
*/
|
|
10
34
|
export declare function projectContinuousExcerpt(body: string, limit: number, render: (length: number) => string): ContentProjection | undefined;
|
|
11
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Compile a depth-limited tree transform.
|
|
37
|
+
*
|
|
38
|
+
* Traverse synchronously in property/array order; only undefined omits a result. Because a
|
|
39
|
+
* visitor returns a new value instead of mutating, an omitted branch disappears from arrays
|
|
40
|
+
* and objects the same way, and `maxDepth` bounds both cycles and cost.
|
|
41
|
+
*
|
|
42
|
+
* @param options - Maximum depth (0 keeps only the root), optional omit predicate and optional
|
|
43
|
+
* record visitor.
|
|
44
|
+
* @returns A frozen object whose `visit(value, context)` returns the projected value.
|
|
45
|
+
* @throws TypeError For a negative or non-integer `maxDepth`; a predicate that is not
|
|
46
|
+
* synchronous boolean; a visitor that returns a thenable.
|
|
47
|
+
*/
|
|
12
48
|
export declare function defineTreeProjection<Context>(options: TreeProjectionOptions<Context>): Readonly<{
|
|
13
49
|
visit: (value: unknown, context: Context) => unknown;
|
|
14
50
|
}>;
|
|
15
|
-
export type { ContentProjectionOptions, ContentProjection, TreeProjectionOptions } from '../structs/kits/projection.js';
|
|
51
|
+
export type { ContentProjectionOptions, ContentProjection, TreeProjectionOptions, } from '../structs/kits/projection.js';
|
|
52
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
16
53
|
export declare const Projection: Readonly<{
|
|
17
54
|
defineContentProjection: typeof defineContentProjection;
|
|
18
55
|
projectContinuousExcerpt: typeof projectContinuousExcerpt;
|