@jangts/agent-core 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +59 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.md +27 -0
- package/development/docs/assets/agent-core-icon.png +0 -0
- package/development/docs/assets/agent-core-logo.png +0 -0
- package/development/docs/assets/character-agent-core.png +0 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +45 -17
- package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
- package/development/skills/agent-core-app/templates/catalog.json +36 -22
- package/dist/cjs/capabilities/index.js +13 -0
- package/dist/cjs/capabilities/invocation.js +80 -10
- package/dist/cjs/capabilities/model.js +126 -13
- package/dist/cjs/capabilities/tool-runtime.js +64 -12
- package/dist/cjs/capabilities/tools.js +266 -31
- package/dist/cjs/context/assembly.js +46 -5
- package/dist/cjs/context/audit.js +31 -6
- package/dist/cjs/context/fragments.js +54 -11
- package/dist/cjs/context/index.js +12 -0
- package/dist/cjs/context/journal.js +84 -7
- package/dist/cjs/context/plan.js +30 -2
- package/dist/cjs/diagnostics/catalog.js +11 -3
- package/dist/cjs/diagnostics/index.js +149 -29
- package/dist/cjs/diagnostics/sub-flow.js +240 -40
- package/dist/cjs/errors.js +99 -17
- package/dist/cjs/execution/branch.js +20 -4
- package/dist/cjs/execution/engine.js +470 -56
- package/dist/cjs/execution/events.js +136 -18
- package/dist/cjs/execution/index.js +7 -0
- package/dist/cjs/execution/reporting.js +75 -6
- package/dist/cjs/execution/state.js +161 -22
- package/dist/cjs/execution/workflow.js +224 -32
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/kits/aggregation.js +45 -3
- package/dist/cjs/kits/answering/batch.js +23 -4
- package/dist/cjs/kits/answering/check-result.js +31 -8
- package/dist/cjs/kits/answering/checks.js +24 -3
- package/dist/cjs/kits/answering/flow.js +192 -36
- package/dist/cjs/kits/answering/index.js +19 -1
- package/dist/cjs/kits/answering/tasks.js +88 -13
- package/dist/cjs/kits/artifacts.js +36 -4
- package/dist/cjs/kits/candidates.js +47 -5
- package/dist/cjs/kits/delivery.js +40 -5
- package/dist/cjs/kits/durable.js +155 -31
- package/dist/cjs/kits/evidence.js +66 -15
- package/dist/cjs/kits/family.js +152 -22
- package/dist/cjs/kits/index.js +12 -1
- package/dist/cjs/kits/inference.js +104 -16
- package/dist/cjs/kits/intents/catalog.js +67 -16
- package/dist/cjs/kits/intents/index.js +11 -0
- package/dist/cjs/kits/intents/registry.js +188 -43
- package/dist/cjs/kits/intents/scopes.js +215 -46
- package/dist/cjs/kits/interaction/command.js +140 -36
- package/dist/cjs/kits/interaction/commands.js +86 -11
- package/dist/cjs/kits/interaction/handlers.js +27 -10
- package/dist/cjs/kits/interaction/index.js +10 -0
- package/dist/cjs/kits/interaction/transfer.js +80 -14
- package/dist/cjs/kits/knowledge/catalog.js +62 -11
- package/dist/cjs/kits/knowledge/index.js +16 -1
- package/dist/cjs/kits/knowledge/publication.js +99 -23
- package/dist/cjs/kits/knowledge/sections.js +33 -4
- package/dist/cjs/kits/normalization.js +51 -7
- package/dist/cjs/kits/policies.js +79 -15
- package/dist/cjs/kits/presentation/events.js +54 -10
- package/dist/cjs/kits/presentation/index.js +24 -1
- package/dist/cjs/kits/presentation/outputs.js +176 -38
- package/dist/cjs/kits/presentation/templates.js +33 -5
- package/dist/cjs/kits/presentation/variants.js +31 -2
- package/dist/cjs/kits/projection.js +63 -8
- package/dist/cjs/kits/rank-fusion.js +27 -4
- package/dist/cjs/kits/reflection-log-source.js +89 -16
- package/dist/cjs/kits/reflection.js +234 -60
- package/dist/cjs/kits/retrieval.js +98 -18
- package/dist/cjs/kits/search.js +180 -27
- package/dist/cjs/kits/text-skills.js +104 -19
- package/dist/cjs/kits/tools.js +415 -74
- package/dist/cjs/kits/vector-search.js +50 -16
- package/dist/cjs/mock/node.js +7 -1
- package/dist/cjs/mock/web.js +7 -1
- package/dist/cjs/mock.js +7 -1
- package/dist/cjs/model/binding.js +68 -17
- package/dist/cjs/model/call-budget.js +45 -4
- package/dist/cjs/model/decision-retry.js +19 -1
- package/dist/cjs/model/defaults.js +27 -4
- package/dist/cjs/model/index.js +7 -0
- package/dist/cjs/model/interactions/arguments.js +36 -1
- package/dist/cjs/model/interactions/json-object.js +48 -12
- package/dist/cjs/model/interactions/native-functions.js +52 -10
- package/dist/cjs/model/message-diagnostics.js +17 -4
- package/dist/cjs/model/options.js +9 -1
- package/dist/cjs/model/preparation.js +86 -12
- package/dist/cjs/model/runner.js +413 -79
- package/dist/cjs/model/selection-transport.js +48 -8
- package/dist/cjs/model/settings.js +67 -13
- package/dist/cjs/model/token-budget.js +69 -11
- package/dist/cjs/model/transports.js +59 -6
- package/dist/cjs/structs/common.js +11 -0
- package/dist/cjs/structs/debug.js +34 -5
- package/dist/cjs/structs/errors.js +26 -1
- package/dist/cjs/structs/index.js +11 -1
- package/dist/cjs/structs/kits/durable.js +7 -0
- package/dist/cjs/structs/kits/family.js +1 -0
- package/dist/cjs/structs/kits/interaction.js +8 -1
- package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
- package/dist/cjs/structs/kits/reflection.js +18 -3
- package/dist/cjs/structs/model/chat-provider.js +6 -0
- package/dist/cjs/structs/support/model/completion.js +2 -0
- package/dist/cjs/structs/support/model/messages.js +2 -0
- package/dist/cjs/support/capabilities.js +43 -6
- package/dist/cjs/support/context/assembly.js +88 -16
- package/dist/cjs/support/context/compression.js +48 -6
- package/dist/cjs/support/context/fragments.js +6 -0
- package/dist/cjs/support/context/history.js +36 -1
- package/dist/cjs/support/context/index.js +11 -0
- package/dist/cjs/support/context/nodes.js +164 -35
- package/dist/cjs/support/context/processing.js +319 -61
- package/dist/cjs/support/context/selection-policy.js +98 -21
- package/dist/cjs/support/context/selection.js +61 -10
- package/dist/cjs/support/context/snapshot.js +29 -7
- package/dist/cjs/support/context/strategies.js +120 -28
- package/dist/cjs/support/index.js +9 -1
- package/dist/cjs/support/model/capabilities.js +20 -1
- package/dist/cjs/support/model/chat-completions.js +92 -20
- package/dist/cjs/support/model/children.js +34 -6
- package/dist/cjs/support/model/compatible-provider.js +189 -59
- package/dist/cjs/support/model/completion/calls.js +61 -0
- package/dist/cjs/support/model/completion/default.js +32 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +102 -0
- package/dist/cjs/support/model/index.js +12 -0
- package/dist/cjs/support/model/interactions/index.js +12 -1
- package/dist/cjs/support/model/interactions/json-object.js +6 -0
- package/dist/cjs/support/model/interactions/native-functions.js +6 -0
- package/dist/cjs/support/model/observer.js +32 -6
- package/dist/cjs/support/model/preview-rules.js +66 -16
- package/dist/cjs/support/model/reply-preview.js +77 -17
- package/dist/cjs/support/model/stage-transport.js +33 -7
- package/dist/cjs/support/model/strategies.js +75 -14
- package/dist/cjs/support/model/transports.js +53 -11
- package/dist/cjs/support/registration.js +49 -7
- package/dist/cjs/support/schema.js +46 -4
- package/dist/cjs/support/stream-events.js +60 -8
- package/dist/cjs/support/tool-runtime.js +6 -0
- package/dist/cjs/support/tools.js +79 -10
- package/dist/cjs/support/transport/index.js +7 -0
- package/dist/cjs/support/transport/json.js +28 -4
- package/dist/cjs/support/transport/sse.js +25 -2
- package/dist/cjs/utils/break-observer.js +20 -2
- package/dist/cjs/utils/cancellation.js +77 -9
- package/dist/cjs/utils/catalog.js +19 -4
- package/dist/cjs/utils/debug.js +14 -2
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/interaction-definition.js +26 -6
- package/dist/cjs/utils/invocation.js +42 -4
- package/dist/cjs/utils/model-protocol.js +20 -1
- package/dist/cjs/utils/object.js +16 -0
- package/dist/cjs/utils/observer.js +22 -2
- package/dist/cjs/utils/protocol-registry.js +47 -4
- package/dist/cjs/utils/query-key.js +21 -2
- package/dist/cjs/utils/registration.js +18 -2
- package/dist/cjs/utils/rules.js +39 -11
- package/dist/cjs/utils/schema-adapter.js +25 -2
- package/dist/cjs/utils/synchronous.js +64 -7
- package/dist/cjs/utils/text.js +15 -1
- package/dist/esm/capabilities/index.d.ts +13 -0
- package/dist/esm/capabilities/index.js +13 -0
- package/dist/esm/capabilities/invocation.d.ts +16 -2
- package/dist/esm/capabilities/invocation.js +80 -10
- package/dist/esm/capabilities/model.d.ts +68 -1
- package/dist/esm/capabilities/model.js +126 -13
- package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
- package/dist/esm/capabilities/tool-runtime.js +64 -12
- package/dist/esm/capabilities/tools.d.ts +96 -3
- package/dist/esm/capabilities/tools.js +267 -32
- package/dist/esm/context/assembly.d.ts +13 -2
- package/dist/esm/context/assembly.js +46 -5
- package/dist/esm/context/audit.d.ts +23 -1
- package/dist/esm/context/audit.js +31 -6
- package/dist/esm/context/fragments.d.ts +37 -3
- package/dist/esm/context/fragments.js +54 -11
- package/dist/esm/context/index.d.ts +12 -0
- package/dist/esm/context/index.js +12 -0
- package/dist/esm/context/journal.d.ts +32 -1
- package/dist/esm/context/journal.js +84 -7
- package/dist/esm/context/plan.d.ts +11 -1
- package/dist/esm/context/plan.js +30 -2
- package/dist/esm/diagnostics/catalog.js +11 -3
- package/dist/esm/diagnostics/index.d.ts +30 -2
- package/dist/esm/diagnostics/index.js +149 -29
- package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
- package/dist/esm/diagnostics/sub-flow.js +240 -40
- package/dist/esm/errors.d.ts +22 -2
- package/dist/esm/errors.js +99 -17
- package/dist/esm/execution/branch.d.ts +19 -1
- package/dist/esm/execution/branch.js +20 -4
- package/dist/esm/execution/engine.d.ts +291 -5
- package/dist/esm/execution/engine.js +471 -57
- package/dist/esm/execution/events.d.ts +16 -2
- package/dist/esm/execution/events.js +136 -18
- package/dist/esm/execution/index.d.ts +7 -0
- package/dist/esm/execution/index.js +7 -0
- package/dist/esm/execution/reporting.d.ts +49 -1
- package/dist/esm/execution/reporting.js +75 -6
- package/dist/esm/execution/state.d.ts +126 -10
- package/dist/esm/execution/state.js +161 -22
- package/dist/esm/execution/workflow.d.ts +121 -3
- package/dist/esm/execution/workflow.js +224 -32
- package/dist/esm/index.d.ts +17 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/kits/aggregation.d.ts +34 -2
- package/dist/esm/kits/aggregation.js +45 -3
- package/dist/esm/kits/answering/batch.d.ts +17 -0
- package/dist/esm/kits/answering/batch.js +23 -4
- package/dist/esm/kits/answering/check-result.d.ts +18 -1
- package/dist/esm/kits/answering/check-result.js +31 -8
- package/dist/esm/kits/answering/checks.d.ts +11 -0
- package/dist/esm/kits/answering/checks.js +24 -3
- package/dist/esm/kits/answering/flow.d.ts +25 -2
- package/dist/esm/kits/answering/flow.js +192 -36
- package/dist/esm/kits/answering/index.d.ts +12 -0
- package/dist/esm/kits/answering/index.js +19 -1
- package/dist/esm/kits/answering/tasks.d.ts +32 -1
- package/dist/esm/kits/answering/tasks.js +88 -13
- package/dist/esm/kits/artifacts.d.ts +11 -0
- package/dist/esm/kits/artifacts.js +36 -4
- package/dist/esm/kits/candidates.d.ts +23 -1
- package/dist/esm/kits/candidates.js +47 -5
- package/dist/esm/kits/delivery.d.ts +34 -0
- package/dist/esm/kits/delivery.js +40 -5
- package/dist/esm/kits/durable.d.ts +19 -0
- package/dist/esm/kits/durable.js +155 -31
- package/dist/esm/kits/evidence.d.ts +28 -5
- package/dist/esm/kits/evidence.js +66 -15
- package/dist/esm/kits/family.d.ts +17 -1
- package/dist/esm/kits/family.js +152 -22
- package/dist/esm/kits/index.d.ts +12 -1
- package/dist/esm/kits/index.js +12 -1
- package/dist/esm/kits/inference.d.ts +64 -0
- package/dist/esm/kits/inference.js +104 -16
- package/dist/esm/kits/intents/catalog.d.ts +13 -1
- package/dist/esm/kits/intents/catalog.js +67 -16
- package/dist/esm/kits/intents/index.d.ts +11 -0
- package/dist/esm/kits/intents/index.js +11 -0
- package/dist/esm/kits/intents/registry.d.ts +61 -3
- package/dist/esm/kits/intents/registry.js +188 -43
- package/dist/esm/kits/intents/scopes.d.ts +73 -3
- package/dist/esm/kits/intents/scopes.js +215 -46
- package/dist/esm/kits/interaction/command.d.ts +38 -4
- package/dist/esm/kits/interaction/command.js +140 -36
- package/dist/esm/kits/interaction/commands.d.ts +66 -2
- package/dist/esm/kits/interaction/commands.js +86 -11
- package/dist/esm/kits/interaction/handlers.d.ts +19 -2
- package/dist/esm/kits/interaction/handlers.js +27 -10
- package/dist/esm/kits/interaction/index.d.ts +10 -0
- package/dist/esm/kits/interaction/index.js +10 -0
- package/dist/esm/kits/interaction/transfer.d.ts +39 -2
- package/dist/esm/kits/interaction/transfer.js +80 -14
- package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
- package/dist/esm/kits/knowledge/catalog.js +62 -11
- package/dist/esm/kits/knowledge/index.d.ts +11 -0
- package/dist/esm/kits/knowledge/index.js +16 -1
- package/dist/esm/kits/knowledge/publication.d.ts +15 -1
- package/dist/esm/kits/knowledge/publication.js +99 -23
- package/dist/esm/kits/knowledge/sections.d.ts +31 -1
- package/dist/esm/kits/knowledge/sections.js +33 -4
- package/dist/esm/kits/normalization.d.ts +25 -2
- package/dist/esm/kits/normalization.js +51 -7
- package/dist/esm/kits/policies.d.ts +26 -3
- package/dist/esm/kits/policies.js +79 -15
- package/dist/esm/kits/presentation/events.d.ts +51 -4
- package/dist/esm/kits/presentation/events.js +54 -10
- package/dist/esm/kits/presentation/index.d.ts +12 -0
- package/dist/esm/kits/presentation/index.js +25 -2
- package/dist/esm/kits/presentation/outputs.d.ts +30 -1
- package/dist/esm/kits/presentation/outputs.js +176 -38
- package/dist/esm/kits/presentation/templates.d.ts +32 -3
- package/dist/esm/kits/presentation/templates.js +33 -5
- package/dist/esm/kits/presentation/variants.d.ts +29 -0
- package/dist/esm/kits/presentation/variants.js +31 -2
- package/dist/esm/kits/projection.d.ts +42 -5
- package/dist/esm/kits/projection.js +63 -8
- package/dist/esm/kits/rank-fusion.d.ts +21 -1
- package/dist/esm/kits/rank-fusion.js +28 -5
- package/dist/esm/kits/reflection-log-source.d.ts +28 -1
- package/dist/esm/kits/reflection-log-source.js +89 -16
- package/dist/esm/kits/reflection.d.ts +17 -1
- package/dist/esm/kits/reflection.js +235 -61
- package/dist/esm/kits/retrieval.d.ts +18 -2
- package/dist/esm/kits/retrieval.js +98 -18
- package/dist/esm/kits/search.d.ts +56 -3
- package/dist/esm/kits/search.js +180 -27
- package/dist/esm/kits/text-skills.d.ts +16 -2
- package/dist/esm/kits/text-skills.js +104 -19
- package/dist/esm/kits/tools.d.ts +122 -2
- package/dist/esm/kits/tools.js +416 -74
- package/dist/esm/kits/vector-search.d.ts +47 -1
- package/dist/esm/kits/vector-search.js +51 -17
- package/dist/esm/mock/node.d.ts +7 -0
- package/dist/esm/mock/node.js +7 -1
- package/dist/esm/mock/web.d.ts +7 -0
- package/dist/esm/mock/web.js +7 -1
- package/dist/esm/mock.d.ts +7 -0
- package/dist/esm/mock.js +7 -1
- package/dist/esm/model/binding.d.ts +32 -3
- package/dist/esm/model/binding.js +68 -17
- package/dist/esm/model/call-budget.d.ts +30 -2
- package/dist/esm/model/call-budget.js +45 -4
- package/dist/esm/model/decision-retry.d.ts +10 -1
- package/dist/esm/model/decision-retry.js +19 -1
- package/dist/esm/model/defaults.d.ts +13 -2
- package/dist/esm/model/defaults.js +27 -4
- package/dist/esm/model/index.d.ts +7 -0
- package/dist/esm/model/index.js +7 -0
- package/dist/esm/model/interactions/arguments.d.ts +27 -0
- package/dist/esm/model/interactions/arguments.js +36 -1
- package/dist/esm/model/interactions/json-object.d.ts +7 -1
- package/dist/esm/model/interactions/json-object.js +48 -12
- package/dist/esm/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/model/interactions/native-functions.js +52 -10
- package/dist/esm/model/message-diagnostics.d.ts +17 -1
- package/dist/esm/model/message-diagnostics.js +17 -4
- package/dist/esm/model/options.d.ts +18 -1
- package/dist/esm/model/options.js +9 -1
- package/dist/esm/model/preparation.d.ts +30 -2
- package/dist/esm/model/preparation.js +86 -12
- package/dist/esm/model/runner.d.ts +129 -5
- package/dist/esm/model/runner.js +414 -80
- package/dist/esm/model/selection-transport.d.ts +14 -1
- package/dist/esm/model/selection-transport.js +48 -8
- package/dist/esm/model/settings.d.ts +11 -0
- package/dist/esm/model/settings.js +67 -13
- package/dist/esm/model/token-budget.d.ts +59 -1
- package/dist/esm/model/token-budget.js +69 -11
- package/dist/esm/model/transports.d.ts +20 -2
- package/dist/esm/model/transports.js +59 -6
- package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
- package/dist/esm/structs/capabilities/model.d.ts +27 -0
- package/dist/esm/structs/capabilities/tools.d.ts +38 -0
- package/dist/esm/structs/common.d.ts +62 -2
- package/dist/esm/structs/common.js +11 -0
- package/dist/esm/structs/context/fragments.d.ts +28 -0
- package/dist/esm/structs/context/journal.d.ts +28 -3
- package/dist/esm/structs/context/processing.d.ts +11 -0
- package/dist/esm/structs/debug.d.ts +58 -1
- package/dist/esm/structs/debug.js +34 -5
- package/dist/esm/structs/diagnostics.d.ts +119 -1
- package/dist/esm/structs/errors.d.ts +42 -1
- package/dist/esm/structs/errors.js +26 -1
- package/dist/esm/structs/execution/engine.d.ts +24 -1
- package/dist/esm/structs/execution/events.d.ts +12 -0
- package/dist/esm/structs/execution/workflow.d.ts +71 -0
- package/dist/esm/structs/index.d.ts +11 -1
- package/dist/esm/structs/index.js +11 -1
- package/dist/esm/structs/invocation.d.ts +30 -0
- package/dist/esm/structs/kits/aggregation.d.ts +12 -0
- package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
- package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
- package/dist/esm/structs/kits/answering/state.d.ts +21 -0
- package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
- package/dist/esm/structs/kits/artifacts.d.ts +14 -0
- package/dist/esm/structs/kits/candidates.d.ts +19 -0
- package/dist/esm/structs/kits/delivery.d.ts +22 -0
- package/dist/esm/structs/kits/durable.d.ts +56 -3
- package/dist/esm/structs/kits/durable.js +7 -0
- package/dist/esm/structs/kits/evidence.d.ts +23 -0
- package/dist/esm/structs/kits/family.d.ts +49 -1
- package/dist/esm/structs/kits/family.js +1 -0
- package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
- package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
- package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
- package/dist/esm/structs/kits/interaction.d.ts +64 -0
- package/dist/esm/structs/kits/interaction.js +8 -1
- package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
- package/dist/esm/structs/kits/knowledge-publication.js +1 -0
- package/dist/esm/structs/kits/knowledge.d.ts +39 -2
- package/dist/esm/structs/kits/normalization.d.ts +15 -0
- package/dist/esm/structs/kits/policies.d.ts +25 -1
- package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
- package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
- package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
- package/dist/esm/structs/kits/projection.d.ts +21 -0
- package/dist/esm/structs/kits/reflection.d.ts +61 -2
- package/dist/esm/structs/kits/reflection.js +18 -3
- package/dist/esm/structs/kits/retrieval.d.ts +38 -0
- package/dist/esm/structs/kits/search.d.ts +22 -0
- package/dist/esm/structs/kits/text-skills.d.ts +36 -0
- package/dist/esm/structs/kits/tools.d.ts +87 -0
- package/dist/esm/structs/model/chat-provider.d.ts +24 -1
- package/dist/esm/structs/model/chat-provider.js +6 -0
- package/dist/esm/structs/model/interactions.d.ts +38 -0
- package/dist/esm/structs/model/messages.d.ts +30 -0
- package/dist/esm/structs/model/runtime.d.ts +104 -6
- package/dist/esm/structs/support/capabilities.d.ts +19 -2
- package/dist/esm/structs/support/context-processing.d.ts +88 -9
- package/dist/esm/structs/support/context.d.ts +29 -1
- package/dist/esm/structs/support/model/completion.d.ts +50 -0
- package/dist/esm/structs/support/model/completion.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +13 -1
- package/dist/esm/structs/support/model/messages.d.ts +52 -0
- package/dist/esm/structs/support/model/messages.js +1 -0
- package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
- package/dist/esm/structs/support/model/provider.d.ts +71 -6
- package/dist/esm/structs/support/registration.d.ts +13 -0
- package/dist/esm/structs/support/schema.d.ts +14 -0
- package/dist/esm/structs/support/tools.d.ts +28 -0
- package/dist/esm/structs/support/transport/json.d.ts +16 -0
- package/dist/esm/structs/support/transport/sse.d.ts +15 -0
- package/dist/esm/structs/utils/rules.d.ts +19 -0
- package/dist/esm/support/capabilities.d.ts +25 -2
- package/dist/esm/support/capabilities.js +43 -6
- package/dist/esm/support/context/assembly.d.ts +35 -4
- package/dist/esm/support/context/assembly.js +88 -16
- package/dist/esm/support/context/compression.d.ts +17 -1
- package/dist/esm/support/context/compression.js +48 -6
- package/dist/esm/support/context/fragments.d.ts +6 -0
- package/dist/esm/support/context/fragments.js +6 -0
- package/dist/esm/support/context/history.d.ts +43 -0
- package/dist/esm/support/context/history.js +36 -1
- package/dist/esm/support/context/index.d.ts +13 -2
- package/dist/esm/support/context/index.js +12 -1
- package/dist/esm/support/context/nodes.d.ts +49 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +145 -1
- package/dist/esm/support/context/processing.js +320 -62
- package/dist/esm/support/context/selection-policy.d.ts +42 -2
- package/dist/esm/support/context/selection-policy.js +98 -21
- package/dist/esm/support/context/selection.d.ts +14 -1
- package/dist/esm/support/context/selection.js +61 -10
- package/dist/esm/support/context/snapshot.d.ts +23 -1
- package/dist/esm/support/context/snapshot.js +29 -7
- package/dist/esm/support/context/strategies.d.ts +35 -2
- package/dist/esm/support/context/strategies.js +120 -28
- package/dist/esm/support/index.d.ts +9 -1
- package/dist/esm/support/index.js +9 -1
- package/dist/esm/support/model/capabilities.d.ts +10 -0
- package/dist/esm/support/model/capabilities.js +20 -1
- package/dist/esm/support/model/chat-completions.d.ts +44 -15
- package/dist/esm/support/model/chat-completions.js +92 -20
- package/dist/esm/support/model/children.d.ts +32 -2
- package/dist/esm/support/model/children.js +34 -6
- package/dist/esm/support/model/compatible-provider.d.ts +29 -3
- package/dist/esm/support/model/compatible-provider.js +190 -60
- package/dist/esm/support/model/completion/calls.d.ts +40 -0
- package/dist/esm/support/model/completion/calls.js +58 -0
- package/dist/esm/support/model/completion/default.d.ts +10 -0
- package/dist/esm/support/model/completion/default.js +29 -0
- package/dist/esm/support/model/completion/index.d.ts +10 -0
- package/dist/esm/support/model/completion/index.js +22 -0
- package/dist/esm/support/model/completion/session.d.ts +11 -0
- package/dist/esm/support/model/completion/session.js +99 -0
- package/dist/esm/support/model/index.d.ts +14 -0
- package/dist/esm/support/model/index.js +12 -0
- package/dist/esm/support/model/interactions/index.d.ts +1 -1
- package/dist/esm/support/model/interactions/index.js +12 -1
- package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
- package/dist/esm/support/model/interactions/json-object.js +6 -0
- package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/support/model/interactions/native-functions.js +6 -0
- package/dist/esm/support/model/observer.d.ts +25 -2
- package/dist/esm/support/model/observer.js +32 -6
- package/dist/esm/support/model/preview-rules.d.ts +20 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +15 -1
- package/dist/esm/support/model/reply-preview.js +77 -17
- package/dist/esm/support/model/stage-transport.d.ts +9 -1
- package/dist/esm/support/model/stage-transport.js +33 -7
- package/dist/esm/support/model/strategies.d.ts +24 -2
- package/dist/esm/support/model/strategies.js +75 -14
- package/dist/esm/support/model/transports.d.ts +17 -1
- package/dist/esm/support/model/transports.js +53 -11
- package/dist/esm/support/registration.d.ts +20 -1
- package/dist/esm/support/registration.js +49 -7
- package/dist/esm/support/schema.d.ts +31 -1
- package/dist/esm/support/schema.js +46 -4
- package/dist/esm/support/stream-events.d.ts +22 -1
- package/dist/esm/support/stream-events.js +60 -8
- package/dist/esm/support/tool-runtime.d.ts +6 -0
- package/dist/esm/support/tool-runtime.js +6 -0
- package/dist/esm/support/tools.d.ts +22 -0
- package/dist/esm/support/tools.js +79 -10
- package/dist/esm/support/transport/index.d.ts +7 -0
- package/dist/esm/support/transport/index.js +7 -0
- package/dist/esm/support/transport/json.d.ts +29 -2
- package/dist/esm/support/transport/json.js +28 -4
- package/dist/esm/support/transport/sse.d.ts +31 -1
- package/dist/esm/support/transport/sse.js +25 -2
- package/dist/esm/types.d.ts +9 -1
- package/dist/esm/utils/break-observer.d.ts +27 -2
- package/dist/esm/utils/break-observer.js +20 -2
- package/dist/esm/utils/cancellation.d.ts +56 -5
- package/dist/esm/utils/cancellation.js +77 -9
- package/dist/esm/utils/catalog.d.ts +20 -1
- package/dist/esm/utils/catalog.js +19 -4
- package/dist/esm/utils/debug.d.ts +20 -1
- package/dist/esm/utils/debug.js +14 -2
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/interaction-definition.d.ts +18 -1
- package/dist/esm/utils/interaction-definition.js +26 -6
- package/dist/esm/utils/invocation.d.ts +36 -1
- package/dist/esm/utils/invocation.js +42 -4
- package/dist/esm/utils/model-protocol.d.ts +8 -0
- package/dist/esm/utils/model-protocol.js +20 -1
- package/dist/esm/utils/object.d.ts +16 -0
- package/dist/esm/utils/object.js +16 -0
- package/dist/esm/utils/observer.d.ts +19 -1
- package/dist/esm/utils/observer.js +22 -2
- package/dist/esm/utils/protocol-registry.d.ts +38 -1
- package/dist/esm/utils/protocol-registry.js +47 -4
- package/dist/esm/utils/query-key.d.ts +11 -1
- package/dist/esm/utils/query-key.js +21 -2
- package/dist/esm/utils/registration.d.ts +34 -2
- package/dist/esm/utils/registration.js +18 -2
- package/dist/esm/utils/rules.d.ts +81 -4
- package/dist/esm/utils/rules.js +39 -11
- package/dist/esm/utils/schema-adapter.d.ts +12 -1
- package/dist/esm/utils/schema-adapter.js +25 -2
- package/dist/esm/utils/synchronous.d.ts +60 -4
- package/dist/esm/utils/synchronous.js +64 -7
- package/dist/esm/utils/text.d.ts +15 -1
- package/dist/esm/utils/text.js +15 -1
- package/package.json +23 -3
|
@@ -2,7 +2,12 @@ import type { InteractionProtocolDefinition } from '../../structs/kits/interacti
|
|
|
2
2
|
import { CommandCatalog } from './commands.js';
|
|
3
3
|
import { defineCommand, commandSchema } from './command.js';
|
|
4
4
|
import { bindInteraction } from './handlers.js';
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Web/AI payload family. HTTP/SSE framing and actual command execution remain separate ports.
|
|
7
|
+
*
|
|
8
|
+
* Every command registered here gets the envelope's discriminator forced to its own id, so a
|
|
9
|
+
* payload cannot claim one command while carrying another command's data.
|
|
10
|
+
*/
|
|
6
11
|
export declare class InteractionProtocol<Value extends object = Record<string, unknown>, Result = Value, Args extends unknown[] = [], Id extends string = string> {
|
|
7
12
|
static readonly define: typeof defineInteractionProtocol;
|
|
8
13
|
static readonly Commands: typeof CommandCatalog;
|
|
@@ -10,20 +15,52 @@ export declare class InteractionProtocol<Value extends object = Record<string, u
|
|
|
10
15
|
static readonly commandSchema: typeof commandSchema;
|
|
11
16
|
static readonly bind: typeof bindInteraction;
|
|
12
17
|
static readonly categories: readonly import("./handlers.js").InteractionCategory[];
|
|
18
|
+
/** Field carrying the command id in a payload. */
|
|
13
19
|
readonly commandField: string;
|
|
20
|
+
/** Accepted selector names: the command field first, then any declared aliases. */
|
|
14
21
|
readonly commandSelectors: readonly string[];
|
|
22
|
+
/** Sealed catalog of the compiled commands. */
|
|
15
23
|
readonly commands: CommandCatalog<Value, Result, Args, Id>;
|
|
16
24
|
private readonly selectionError?;
|
|
25
|
+
/**
|
|
26
|
+
* @param definition - Command definitions plus envelope, selector aliases and error wording.
|
|
27
|
+
* @throws An error for a blank or duplicate selector, a conflicting per-command discriminator
|
|
28
|
+
* (it must match the envelope field and the command's own id).
|
|
29
|
+
*/
|
|
17
30
|
constructor(definition: InteractionProtocolDefinition<Value, Result, Args, Id>);
|
|
31
|
+
/** JSON schema for the model, expressed as a union of the per-command schemas. */
|
|
18
32
|
get modelJsonSchema(): Record<string, unknown>;
|
|
33
|
+
/** Strict JSON schema for transport input, expressed as a union of per-command schemas. */
|
|
19
34
|
get inputJsonSchema(): Record<string, unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* Parse a payload and return only the result.
|
|
37
|
+
*
|
|
38
|
+
* @param value - Raw payload.
|
|
39
|
+
* @param args - Extra arguments forwarded to the command parser.
|
|
40
|
+
* @throws The same errors as `receive`.
|
|
41
|
+
*/
|
|
20
42
|
parse(value: Value, ...args: Args): Result;
|
|
21
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Retain the selected command id separately from a formatter's output.
|
|
45
|
+
*
|
|
46
|
+
* @param value - Raw payload; aliases are normalized when more than one selector is allowed.
|
|
47
|
+
* @param args - Extra arguments forwarded to the command parser.
|
|
48
|
+
* @returns The selected command id and its parsed result.
|
|
49
|
+
* @throws A configured error for a malformed or ambiguous selector, or the catalog's
|
|
50
|
+
* command/mode/ownership errors.
|
|
51
|
+
*/
|
|
22
52
|
receive(value: Value, ...args: Args): {
|
|
23
53
|
id: Id;
|
|
24
54
|
result: Result;
|
|
25
55
|
};
|
|
26
56
|
private normalizeSelector;
|
|
27
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Construct a protocol from one definition.
|
|
60
|
+
*
|
|
61
|
+
* @param definition - Commands, envelope and selector configuration.
|
|
62
|
+
* @returns A new protocol instance.
|
|
63
|
+
* @throws The same errors as the constructor.
|
|
64
|
+
*/
|
|
28
65
|
export declare function defineInteractionProtocol<Value extends object = Record<string, unknown>, Result = Value, Args extends unknown[] = [], Id extends string = string>(definition: InteractionProtocolDefinition<Value, Result, Args, Id>): InteractionProtocol<Value, Result, Args, Id>;
|
|
29
66
|
export type { InteractionProtocolDefinition } from '../../structs/kits/interaction.js';
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interaction Kit: the web/AI payload family with selector normalization.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: part of the `interaction` Kit and its main entry. HTTP/SSE framing and
|
|
5
|
+
* the actual command execution remain separate ports; this class only validates the envelope,
|
|
6
|
+
* accepts selector aliases and delegates parsing to the sealed command catalog.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `InteractionProtocol`, `defineInteractionProtocol`, and its definition type.
|
|
9
|
+
*/
|
|
1
10
|
import { pinCommandDefinition } from '../../utils/interaction-definition.js';
|
|
2
11
|
import { breakWhile } from '../../utils/rules.js';
|
|
3
12
|
import { defineCommandCatalog, CommandCatalog } from './commands.js';
|
|
4
13
|
import { defineCommand, commandSchema } from './command.js';
|
|
5
14
|
import { bindInteraction } from './handlers.js';
|
|
6
15
|
import { INTERACTION_CATEGORIES } from '../../structs/kits/interaction.js';
|
|
7
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Web/AI payload family. HTTP/SSE framing and actual command execution remain separate ports.
|
|
18
|
+
*
|
|
19
|
+
* Every command registered here gets the envelope's discriminator forced to its own id, so a
|
|
20
|
+
* payload cannot claim one command while carrying another command's data.
|
|
21
|
+
*/
|
|
8
22
|
export class InteractionProtocol {
|
|
9
23
|
static define = defineInteractionProtocol;
|
|
10
24
|
static Commands = CommandCatalog;
|
|
@@ -12,39 +26,79 @@ export class InteractionProtocol {
|
|
|
12
26
|
static commandSchema = commandSchema;
|
|
13
27
|
static bind = bindInteraction;
|
|
14
28
|
static categories = INTERACTION_CATEGORIES;
|
|
29
|
+
/** Field carrying the command id in a payload. */
|
|
15
30
|
commandField;
|
|
31
|
+
/** Accepted selector names: the command field first, then any declared aliases. */
|
|
16
32
|
commandSelectors;
|
|
33
|
+
/** Sealed catalog of the compiled commands. */
|
|
17
34
|
commands;
|
|
18
35
|
selectionError;
|
|
36
|
+
/**
|
|
37
|
+
* @param definition - Command definitions plus envelope, selector aliases and error wording.
|
|
38
|
+
* @throws An error for a blank or duplicate selector, a conflicting per-command discriminator
|
|
39
|
+
* (it must match the envelope field and the command's own id).
|
|
40
|
+
*/
|
|
19
41
|
constructor(definition) {
|
|
20
|
-
const { commands, commandField, commandAliases, modeField, unknownError, modeError, ownershipError } = definition;
|
|
42
|
+
const { commands, commandField, commandAliases, modeField, unknownError, modeError, ownershipError, } = definition;
|
|
21
43
|
const { discriminator: _discriminator, modes: _modes, ownedFields: _ownedFields, ...envelope } = pinCommandDefinition(definition);
|
|
22
|
-
const selectionError = typeof definition.selectionError === 'function'
|
|
44
|
+
const selectionError = typeof definition.selectionError === 'function'
|
|
45
|
+
? definition.selectionError.bind(definition)
|
|
46
|
+
: definition.selectionError;
|
|
23
47
|
breakWhile(!commandField.trim(), 'Missing transfer command field');
|
|
24
48
|
this.commandField = commandField;
|
|
25
49
|
this.commandSelectors = Object.freeze([commandField, ...(commandAliases ?? [])]);
|
|
26
50
|
breakWhile([
|
|
27
|
-
{
|
|
28
|
-
|
|
51
|
+
{
|
|
52
|
+
occur: () => this.commandSelectors.some((field) => !field.trim()),
|
|
53
|
+
error: 'Missing transfer selector',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
occur: () => new Set(this.commandSelectors).size !== this.commandSelectors.length,
|
|
57
|
+
error: 'Duplicate transfer selector',
|
|
58
|
+
},
|
|
29
59
|
]);
|
|
30
60
|
this.selectionError = selectionError;
|
|
31
61
|
const registered = Object.fromEntries(Object.entries(commands).map(([id, value]) => {
|
|
32
62
|
const command = pinCommandDefinition(value);
|
|
33
|
-
breakWhile(command.discriminator &&
|
|
63
|
+
breakWhile(command.discriminator &&
|
|
64
|
+
(command.discriminator.field !== commandField || command.discriminator.value !== id), 'Conflicting transfer command discriminator');
|
|
34
65
|
return [id, { ...command, discriminator: { field: commandField, value: id } }];
|
|
35
66
|
}));
|
|
36
67
|
this.commands = defineCommandCatalog(registered, envelope, {
|
|
37
|
-
modeField,
|
|
68
|
+
modeField,
|
|
69
|
+
unknownError,
|
|
70
|
+
modeError,
|
|
71
|
+
ownershipError,
|
|
72
|
+
tags: envelope.tags,
|
|
38
73
|
});
|
|
39
74
|
}
|
|
75
|
+
/** JSON schema for the model, expressed as a union of the per-command schemas. */
|
|
40
76
|
get modelJsonSchema() {
|
|
41
|
-
return { anyOf: [...this.commands.values()].map(command => command.modelJsonSchema) };
|
|
77
|
+
return { anyOf: [...this.commands.values()].map((command) => command.modelJsonSchema) };
|
|
42
78
|
}
|
|
43
|
-
|
|
79
|
+
/** Strict JSON schema for transport input, expressed as a union of per-command schemas. */
|
|
80
|
+
get inputJsonSchema() {
|
|
81
|
+
return { anyOf: [...this.commands.values()].map((command) => command.inputJsonSchema) };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Parse a payload and return only the result.
|
|
85
|
+
*
|
|
86
|
+
* @param value - Raw payload.
|
|
87
|
+
* @param args - Extra arguments forwarded to the command parser.
|
|
88
|
+
* @throws The same errors as `receive`.
|
|
89
|
+
*/
|
|
44
90
|
parse(value, ...args) {
|
|
45
91
|
return this.receive(value, ...args).result;
|
|
46
92
|
}
|
|
47
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Retain the selected command id separately from a formatter's output.
|
|
95
|
+
*
|
|
96
|
+
* @param value - Raw payload; aliases are normalized when more than one selector is allowed.
|
|
97
|
+
* @param args - Extra arguments forwarded to the command parser.
|
|
98
|
+
* @returns The selected command id and its parsed result.
|
|
99
|
+
* @throws A configured error for a malformed or ambiguous selector, or the catalog's
|
|
100
|
+
* command/mode/ownership errors.
|
|
101
|
+
*/
|
|
48
102
|
receive(value, ...args) {
|
|
49
103
|
const normalized = this.normalizeSelector(value, args);
|
|
50
104
|
const id = normalized[this.commandField];
|
|
@@ -54,14 +108,19 @@ export class InteractionProtocol {
|
|
|
54
108
|
// Preserve the original no-alias parsing path; alias handling is an explicit host choice.
|
|
55
109
|
if (this.commandSelectors.length === 1)
|
|
56
110
|
return value;
|
|
57
|
-
const fail = () => typeof this.selectionError === 'function'
|
|
58
|
-
|
|
111
|
+
const fail = () => typeof this.selectionError === 'function'
|
|
112
|
+
? this.selectionError(value, ...args)
|
|
113
|
+
: (this.selectionError ?? new TypeError('Invalid transfer selector'));
|
|
59
114
|
breakWhile(!value || typeof value !== 'object' || Array.isArray(value), fail);
|
|
60
115
|
const record = value;
|
|
61
|
-
const selectors = this.commandSelectors.filter(field => Object.hasOwn(record, field));
|
|
116
|
+
const selectors = this.commandSelectors.filter((field) => Object.hasOwn(record, field));
|
|
62
117
|
breakWhile([
|
|
63
118
|
{ occur: () => selectors.length !== 1, error: fail, tags: ['selector-count'] },
|
|
64
|
-
{
|
|
119
|
+
{
|
|
120
|
+
occur: () => typeof record[selectors[0]] !== 'string',
|
|
121
|
+
error: fail,
|
|
122
|
+
tags: ['selector-value'],
|
|
123
|
+
},
|
|
65
124
|
]);
|
|
66
125
|
const normalized = { ...record, [this.commandField]: record[selectors[0]] };
|
|
67
126
|
if (selectors[0] !== this.commandField)
|
|
@@ -69,6 +128,13 @@ export class InteractionProtocol {
|
|
|
69
128
|
return normalized;
|
|
70
129
|
}
|
|
71
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Construct a protocol from one definition.
|
|
133
|
+
*
|
|
134
|
+
* @param definition - Commands, envelope and selector configuration.
|
|
135
|
+
* @returns A new protocol instance.
|
|
136
|
+
* @throws The same errors as the constructor.
|
|
137
|
+
*/
|
|
72
138
|
export function defineInteractionProtocol(definition) {
|
|
73
139
|
return new InteractionProtocol(definition);
|
|
74
140
|
}
|
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
import type { KnowledgeCatalogOptions, KnowledgeDocument, KnowledgeCatalog } from '../../structs/kits/knowledge.js';
|
|
2
|
+
/**
|
|
3
|
+
* Compile a knowledge catalog from document declarations.
|
|
4
|
+
*
|
|
5
|
+
* Reads are declarative: `document` returns the whole text, `self` returns exactly the named
|
|
6
|
+
* sections and `subtree` includes their nested sections. Section ids are validated up front,
|
|
7
|
+
* so a typo fails at read time instead of silently returning partial content.
|
|
8
|
+
*
|
|
9
|
+
* @param documents - Unique-id documents, each compiled into an immutable section tree.
|
|
10
|
+
* @param options - Optional `maxChars` budget and an observer for successful reads.
|
|
11
|
+
* @returns A frozen catalog extended with `sectionIds`, `assertSelection` and `read`.
|
|
12
|
+
* @throws TypeError For a duplicate document id, an invalid budget, an unknown document or
|
|
13
|
+
* section, or a malformed selection; `RangeError` when the content exceeds `maxChars`.
|
|
14
|
+
*/
|
|
2
15
|
export declare function defineKnowledgeCatalog(documents: readonly KnowledgeDocument[], options?: KnowledgeCatalogOptions): KnowledgeCatalog;
|
|
3
16
|
export type * from '../../structs/kits/knowledge.js';
|
|
@@ -1,6 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Kit: compile documents into a sectioned catalog and read budgeted snapshots.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: part of the `knowledge` Kit. A snapshot carries text, revision and an
|
|
5
|
+
* opaque id; this module never fetches, authorizes or persists — it only resolves declared
|
|
6
|
+
* documents and sections.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `defineKnowledgeCatalog`, and the knowledge document/read/snapshot types.
|
|
9
|
+
*/
|
|
1
10
|
import { readonlyCatalog } from '../../utils/catalog.js';
|
|
2
11
|
import { compileKnowledgeDocument, knowledgeText } from './sections.js';
|
|
3
12
|
import { observeSafely } from '../../utils/observer.js';
|
|
13
|
+
/**
|
|
14
|
+
* Compile a knowledge catalog from document declarations.
|
|
15
|
+
*
|
|
16
|
+
* Reads are declarative: `document` returns the whole text, `self` returns exactly the named
|
|
17
|
+
* sections and `subtree` includes their nested sections. Section ids are validated up front,
|
|
18
|
+
* so a typo fails at read time instead of silently returning partial content.
|
|
19
|
+
*
|
|
20
|
+
* @param documents - Unique-id documents, each compiled into an immutable section tree.
|
|
21
|
+
* @param options - Optional `maxChars` budget and an observer for successful reads.
|
|
22
|
+
* @returns A frozen catalog extended with `sectionIds`, `assertSelection` and `read`.
|
|
23
|
+
* @throws TypeError For a duplicate document id, an invalid budget, an unknown document or
|
|
24
|
+
* section, or a malformed selection; `RangeError` when the content exceeds `maxChars`.
|
|
25
|
+
*/
|
|
4
26
|
export function defineKnowledgeCatalog(documents, options = {}) {
|
|
5
27
|
const { maxChars } = options, observe = options.observe?.bind(options);
|
|
6
28
|
const catalog = new Map();
|
|
@@ -20,7 +42,9 @@ export function defineKnowledgeCatalog(documents, options = {}) {
|
|
|
20
42
|
if (!read.selection || !['document', 'self', 'subtree'].includes(read.selection.mode))
|
|
21
43
|
throw new TypeError('Invalid knowledge selection');
|
|
22
44
|
if (read.selection.mode !== 'document') {
|
|
23
|
-
if (!Array.isArray(read.selection.sectionIds) ||
|
|
45
|
+
if (!Array.isArray(read.selection.sectionIds) ||
|
|
46
|
+
!read.selection.sectionIds.length ||
|
|
47
|
+
new Set(read.selection.sectionIds).size !== read.selection.sectionIds.length)
|
|
24
48
|
throw new TypeError('Invalid knowledge section selection');
|
|
25
49
|
for (const id of read.selection.sectionIds)
|
|
26
50
|
if (!entry.sections.has(id))
|
|
@@ -28,21 +52,48 @@ export function defineKnowledgeCatalog(documents, options = {}) {
|
|
|
28
52
|
}
|
|
29
53
|
return { read, entry };
|
|
30
54
|
};
|
|
31
|
-
const sectionIds = (id) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
55
|
+
const sectionIds = (id) => {
|
|
56
|
+
const entry = catalog.get(id);
|
|
57
|
+
if (!entry)
|
|
58
|
+
throw new TypeError(`Unknown knowledge document: ${id}`);
|
|
59
|
+
return Object.freeze([...entry.sections.keys()]);
|
|
60
|
+
};
|
|
61
|
+
const assertSelection = (read) => {
|
|
62
|
+
resolve(read);
|
|
63
|
+
};
|
|
64
|
+
return Object.freeze({
|
|
65
|
+
...readonlyCatalog([...catalog.values()].map((entry) => entry.document), (id) => new TypeError(`Unknown knowledge document: ${id}`)),
|
|
66
|
+
sectionIds,
|
|
67
|
+
assertSelection,
|
|
36
68
|
read(input) {
|
|
37
69
|
const { read, entry } = resolve(input), raw = read.selection;
|
|
38
|
-
const selection = raw.mode === 'document'
|
|
39
|
-
|
|
70
|
+
const selection = raw.mode === 'document'
|
|
71
|
+
? Object.freeze({ mode: 'document' })
|
|
72
|
+
: Object.freeze({ mode: raw.mode, sectionIds: Object.freeze([...raw.sectionIds]) });
|
|
73
|
+
const content = (selection.mode === 'document'
|
|
74
|
+
? knowledgeText(entry.document.parts)
|
|
75
|
+
: selection.sectionIds
|
|
76
|
+
.map((id) => knowledgeText(entry.sections.get(id).parts, selection.mode === 'subtree'))
|
|
77
|
+
.join('\n\n')).trim();
|
|
40
78
|
if (maxChars !== undefined && content.length > maxChars)
|
|
41
79
|
throw new RangeError('Knowledge selection exceeds its budget');
|
|
42
80
|
// Preserve the existing opaque snapshot identity format.
|
|
43
|
-
const identitySelection = selection.mode === 'document'
|
|
44
|
-
|
|
45
|
-
|
|
81
|
+
const identitySelection = selection.mode === 'document'
|
|
82
|
+
? selection
|
|
83
|
+
: { mode: selection.mode, sections: selection.sectionIds };
|
|
84
|
+
const snapshot = Object.freeze({
|
|
85
|
+
documentId: read.documentId,
|
|
86
|
+
selection,
|
|
87
|
+
revision: entry.document.revision,
|
|
88
|
+
locale: entry.document.locale,
|
|
89
|
+
content,
|
|
90
|
+
id: JSON.stringify([
|
|
91
|
+
read.documentId,
|
|
92
|
+
entry.document.revision,
|
|
93
|
+
entry.document.locale,
|
|
94
|
+
identitySelection,
|
|
95
|
+
]),
|
|
96
|
+
});
|
|
46
97
|
observeSafely(observe, snapshot);
|
|
47
98
|
return snapshot;
|
|
48
99
|
},
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Kit entry: sectioned knowledge documents, snapshot reads and candidate publication.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: an optional App-side library. Documents, storage, authorization and
|
|
5
|
+
* provenance are App-owned; this directory owns the section tree, budgeted reads, opaque
|
|
6
|
+
* snapshot identity and the candidate/publish lifecycle over an atomic store revision.
|
|
7
|
+
*
|
|
8
|
+
* Exports: everything from `./catalog.js` and `./publication.js`, `parseKnowledgeDocument`, and
|
|
9
|
+
* the `Knowledge` namespace object.
|
|
10
|
+
*/
|
|
1
11
|
export * from './catalog.js';
|
|
2
12
|
export { parseKnowledgeDocument } from './sections.js';
|
|
3
13
|
import { defineKnowledgeCatalog } from './catalog.js';
|
|
4
14
|
import { parseKnowledgeDocument } from './sections.js';
|
|
5
15
|
import { defineKnowledgePublication } from './publication.js';
|
|
6
16
|
export * from './publication.js';
|
|
17
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
7
18
|
export declare const Knowledge: Readonly<{
|
|
8
19
|
defineKnowledgeCatalog: typeof defineKnowledgeCatalog;
|
|
9
20
|
parseKnowledgeDocument: typeof parseKnowledgeDocument;
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Kit entry: sectioned knowledge documents, snapshot reads and candidate publication.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: an optional App-side library. Documents, storage, authorization and
|
|
5
|
+
* provenance are App-owned; this directory owns the section tree, budgeted reads, opaque
|
|
6
|
+
* snapshot identity and the candidate/publish lifecycle over an atomic store revision.
|
|
7
|
+
*
|
|
8
|
+
* Exports: everything from `./catalog.js` and `./publication.js`, `parseKnowledgeDocument`, and
|
|
9
|
+
* the `Knowledge` namespace object.
|
|
10
|
+
*/
|
|
1
11
|
export * from './catalog.js';
|
|
2
12
|
export { parseKnowledgeDocument } from './sections.js';
|
|
3
13
|
import { defineKnowledgeCatalog } from './catalog.js';
|
|
4
14
|
import { parseKnowledgeDocument } from './sections.js';
|
|
5
15
|
import { defineKnowledgePublication } from './publication.js';
|
|
6
16
|
export * from './publication.js';
|
|
7
|
-
|
|
17
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
18
|
+
export const Knowledge = Object.freeze({
|
|
19
|
+
defineKnowledgeCatalog,
|
|
20
|
+
parseKnowledgeDocument,
|
|
21
|
+
defineKnowledgePublication,
|
|
22
|
+
});
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import type { KnowledgePublication, KnowledgePublicationOptions } from '../../structs/kits/knowledge-publication.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Compile a publication lifecycle over one App-owned atomic record.
|
|
4
|
+
*
|
|
5
|
+
* Candidate preparation and publication share the same compiler and an App-owned atomic
|
|
6
|
+
* revision. `propose` compiles and validates a candidate but leaves published documents alone;
|
|
7
|
+
* `publish` re-verifies sources and the base revision before swapping, so a stale candidate can
|
|
8
|
+
* never overwrite newer content.
|
|
9
|
+
*
|
|
10
|
+
* @param options - Store, authorization, provenance verification, clock, optional required
|
|
11
|
+
* reads, capacity and retention bounds; handlers are bound to this options object.
|
|
12
|
+
* @returns A frozen publication exposing `read`, `propose`, `publish` and `reject`.
|
|
13
|
+
* @throws A configured error for invalid bounds, a malformed record or candidate, a revision
|
|
14
|
+
* conflict, an expired candidate, exhausted capacity, a changed base revision, or a public
|
|
15
|
+
* document whose content changed without a new revision.
|
|
16
|
+
*/
|
|
3
17
|
export declare function defineKnowledgePublication<App>(options: KnowledgePublicationOptions<App>): KnowledgePublication<App>;
|
|
4
18
|
export type * from '../../structs/kits/knowledge-publication.js';
|
|
@@ -1,14 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Kit: candidate preparation, verification and atomic publication of documents.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: part of the `knowledge` Kit. The store, authorization and provenance
|
|
5
|
+
* checks are App ports; this module owns revision checking, candidate expiry and capacity,
|
|
6
|
+
* compilation of proposed documents and the compare-and-swap commit.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `defineKnowledgePublication`, and the publication record/candidate/source types.
|
|
9
|
+
*/
|
|
1
10
|
import { defineKnowledgeCatalog } from './catalog.js';
|
|
2
11
|
import { invocationId } from '../../utils/invocation.js';
|
|
3
12
|
import { awaitWithSignal, awaitAssertion } from '../../utils/cancellation.js';
|
|
4
13
|
import { breakWhile } from '../../utils/rules.js';
|
|
5
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Compile a publication lifecycle over one App-owned atomic record.
|
|
16
|
+
*
|
|
17
|
+
* Candidate preparation and publication share the same compiler and an App-owned atomic
|
|
18
|
+
* revision. `propose` compiles and validates a candidate but leaves published documents alone;
|
|
19
|
+
* `publish` re-verifies sources and the base revision before swapping, so a stale candidate can
|
|
20
|
+
* never overwrite newer content.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Store, authorization, provenance verification, clock, optional required
|
|
23
|
+
* reads, capacity and retention bounds; handlers are bound to this options object.
|
|
24
|
+
* @returns A frozen publication exposing `read`, `propose`, `publish` and `reject`.
|
|
25
|
+
* @throws A configured error for invalid bounds, a malformed record or candidate, a revision
|
|
26
|
+
* conflict, an expired candidate, exhausted capacity, a changed base revision, or a public
|
|
27
|
+
* document whose content changed without a new revision.
|
|
28
|
+
*/
|
|
6
29
|
export function defineKnowledgePublication(options) {
|
|
7
30
|
const load = options.store.load.bind(options.store), swap = options.store.compareAndSwap.bind(options.store);
|
|
8
31
|
const authorize = options.authorize.bind(options), verify = options.verifySources.bind(options), now = options.now?.bind(options) ?? Date.now;
|
|
32
|
+
// Defaults keep one record small: at most 32 pending candidates, each valid for seven days.
|
|
9
33
|
const maxCandidates = options.maxCandidates ?? 32, retention = options.candidateRetentionMs ?? 7 * 86400_000;
|
|
10
34
|
const maxChars = options.maxReadChars, reads = structuredClone(options.requiredReads ?? []);
|
|
11
|
-
breakWhile(!Number.isSafeInteger(maxCandidates) ||
|
|
35
|
+
breakWhile(!Number.isSafeInteger(maxCandidates) ||
|
|
36
|
+
maxCandidates < 1 ||
|
|
37
|
+
!Number.isSafeInteger(retention) ||
|
|
38
|
+
retention < 1, 'Invalid publication bounds');
|
|
12
39
|
const compile = (documents) => {
|
|
13
40
|
const catalog = defineKnowledgeCatalog(documents, { maxChars });
|
|
14
41
|
for (const read of reads)
|
|
@@ -21,24 +48,53 @@ export function defineKnowledgePublication(options) {
|
|
|
21
48
|
const sourceSnapshot = (sources) => {
|
|
22
49
|
const invalid = 'Invalid or expired knowledge provenance';
|
|
23
50
|
breakWhile(!Array.isArray(sources) || !sources.length || sources.length > 32, invalid);
|
|
24
|
-
const snapshot = Array.from(sources, source => ({
|
|
25
|
-
|
|
26
|
-
|
|
51
|
+
const snapshot = Array.from(sources, (source) => ({
|
|
52
|
+
id: source?.id,
|
|
53
|
+
revision: source?.revision,
|
|
54
|
+
expiresAtMs: source?.expiresAtMs,
|
|
55
|
+
}));
|
|
56
|
+
breakWhile(snapshot.some((source) => typeof source.id !== 'string' ||
|
|
57
|
+
!source.id.trim() ||
|
|
58
|
+
typeof source.revision !== 'string' ||
|
|
59
|
+
!source.revision.trim() ||
|
|
60
|
+
(source.expiresAtMs !== undefined &&
|
|
61
|
+
(!Number.isFinite(source.expiresAtMs) || source.expiresAtMs <= now()))), invalid);
|
|
27
62
|
return snapshot;
|
|
28
63
|
};
|
|
29
64
|
const read = async (context) => {
|
|
30
65
|
context.signal.throwIfAborted();
|
|
31
66
|
const record = structuredClone(await awaitWithSignal(load(), context.signal));
|
|
32
|
-
breakWhile(!record ||
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
67
|
+
breakWhile(!record ||
|
|
68
|
+
!Number.isSafeInteger(record.revision) ||
|
|
69
|
+
record.revision < 0 ||
|
|
70
|
+
!Number.isSafeInteger(record.publishedRevision) ||
|
|
71
|
+
record.publishedRevision < 0 ||
|
|
72
|
+
record.publishedRevision > record.revision ||
|
|
73
|
+
!Array.isArray(record.documents) ||
|
|
74
|
+
!Array.isArray(record.candidates) ||
|
|
75
|
+
record.candidates.length > maxCandidates, 'Invalid publication record');
|
|
76
|
+
breakWhile(new Set(record.candidates.map((item) => item?.id)).size !== record.candidates.length ||
|
|
77
|
+
record.candidates.some((item) => !item ||
|
|
78
|
+
typeof item.id !== 'string' ||
|
|
79
|
+
!item.id ||
|
|
80
|
+
!Number.isSafeInteger(item.baseRevision) ||
|
|
81
|
+
item.baseRevision < 0 ||
|
|
82
|
+
item.baseRevision > record.publishedRevision ||
|
|
83
|
+
!Number.isFinite(item.createdAtMs) ||
|
|
84
|
+
!Number.isFinite(item.expiresAtMs) ||
|
|
85
|
+
item.expiresAtMs <= item.createdAtMs ||
|
|
86
|
+
!Array.isArray(item.sources) ||
|
|
87
|
+
!item.sources.length ||
|
|
88
|
+
item.sources.length > 32), 'Invalid knowledge candidate');
|
|
89
|
+
const compilationKey = JSON.stringify([
|
|
90
|
+
record.revision,
|
|
91
|
+
record.publishedRevision,
|
|
92
|
+
record.documents,
|
|
93
|
+
record.candidates.map((item) => item.document),
|
|
94
|
+
]);
|
|
39
95
|
if (compilationKey !== compiledRecord) {
|
|
40
96
|
for (const item of record.candidates)
|
|
41
|
-
compile([...record.documents.filter(doc => doc.id !== item.document.id), item.document]);
|
|
97
|
+
compile([...record.documents.filter((doc) => doc.id !== item.document.id), item.document]);
|
|
42
98
|
compile(record.documents);
|
|
43
99
|
compiledRecord = compilationKey;
|
|
44
100
|
}
|
|
@@ -61,14 +117,19 @@ export function defineKnowledgePublication(options) {
|
|
|
61
117
|
return record;
|
|
62
118
|
};
|
|
63
119
|
const replacement = (record, document) => {
|
|
64
|
-
const previous = record.documents.find(item => item.id === document.id);
|
|
65
|
-
breakWhile(!!previous &&
|
|
66
|
-
|
|
120
|
+
const previous = record.documents.find((item) => item.id === document.id);
|
|
121
|
+
breakWhile(!!previous &&
|
|
122
|
+
previous.revision === document.revision &&
|
|
123
|
+
JSON.stringify(previous) !== JSON.stringify(document), 'Changed knowledge needs a new document revision');
|
|
124
|
+
const documents = [
|
|
125
|
+
...record.documents.filter((item) => item.id !== document.id),
|
|
126
|
+
structuredClone(document),
|
|
127
|
+
];
|
|
67
128
|
compile(documents);
|
|
68
129
|
return documents;
|
|
69
130
|
};
|
|
70
131
|
const candidate = (record, id) => {
|
|
71
|
-
const item = record.candidates.find(value => value.id === id);
|
|
132
|
+
const item = record.candidates.find((value) => value.id === id);
|
|
72
133
|
breakWhile(!item || item.expiresAtMs <= now(), 'Knowledge candidate unavailable');
|
|
73
134
|
return item;
|
|
74
135
|
};
|
|
@@ -83,10 +144,16 @@ export function defineKnowledgePublication(options) {
|
|
|
83
144
|
replacement(record, document);
|
|
84
145
|
await awaitAssertion(() => verify(structuredClone(sources), context), context.signal, 'Knowledge provenance validation must return void');
|
|
85
146
|
sourceSnapshot(sources);
|
|
86
|
-
const candidates = record.candidates.filter(item => item.expiresAtMs > now());
|
|
147
|
+
const candidates = record.candidates.filter((item) => item.expiresAtMs > now());
|
|
87
148
|
breakWhile(candidates.length >= maxCandidates, 'Knowledge candidate capacity exhausted');
|
|
88
|
-
const item = {
|
|
89
|
-
|
|
149
|
+
const item = {
|
|
150
|
+
id: invocationId(),
|
|
151
|
+
baseRevision: record.publishedRevision,
|
|
152
|
+
document,
|
|
153
|
+
sources,
|
|
154
|
+
createdAtMs: now(),
|
|
155
|
+
expiresAtMs: Math.min(now() + retention, ...sources.map((source) => source.expiresAtMs ?? Infinity)),
|
|
156
|
+
};
|
|
90
157
|
return commit(record, { ...record, revision: record.revision + 1, candidates: [...candidates, item] }, context, () => {
|
|
91
158
|
sourceSnapshot(sources);
|
|
92
159
|
breakWhile(item.expiresAtMs <= now(), 'Knowledge candidate expired');
|
|
@@ -101,8 +168,13 @@ export function defineKnowledgePublication(options) {
|
|
|
101
168
|
await awaitAssertion(() => verify(structuredClone(sources), context), context.signal, 'Knowledge provenance validation must return void');
|
|
102
169
|
sourceSnapshot(sources);
|
|
103
170
|
const documents = replacement(record, item.document);
|
|
104
|
-
return commit(record, {
|
|
105
|
-
|
|
171
|
+
return commit(record, {
|
|
172
|
+
...record,
|
|
173
|
+
revision: record.revision + 1,
|
|
174
|
+
publishedRevision: record.publishedRevision + 1,
|
|
175
|
+
documents,
|
|
176
|
+
candidates: record.candidates.filter((value) => value.id !== item.id),
|
|
177
|
+
}, context, () => {
|
|
106
178
|
candidate(record, item.id);
|
|
107
179
|
sourceSnapshot(sources);
|
|
108
180
|
});
|
|
@@ -112,7 +184,11 @@ export function defineKnowledgePublication(options) {
|
|
|
112
184
|
await awaitAssertion(() => authorize('reject', context), context.signal, 'Knowledge publication authorization must return void');
|
|
113
185
|
const record = await checked(revision, context);
|
|
114
186
|
candidate(record, candidateId);
|
|
115
|
-
return commit(record, {
|
|
187
|
+
return commit(record, {
|
|
188
|
+
...record,
|
|
189
|
+
revision: record.revision + 1,
|
|
190
|
+
candidates: record.candidates.filter((item) => item.id !== candidateId),
|
|
191
|
+
}, context);
|
|
116
192
|
},
|
|
117
193
|
});
|
|
118
194
|
}
|
|
@@ -1,11 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Kit: adapter and helpers for sectioned knowledge documents.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: part of the `knowledge` Kit. The anchor format is one text adapter;
|
|
5
|
+
* other sources build the same document contract directly. No I/O happens here.
|
|
6
|
+
*
|
|
7
|
+
* Exports: `parseKnowledgeDocument`, `compileKnowledgeDocument`, `knowledgeText`.
|
|
8
|
+
*/
|
|
1
9
|
import type { KnowledgeDocument, KnowledgePart, KnowledgeSection } from '../../structs/kits/knowledge.js';
|
|
2
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Paired, nestable anchors are one text adapter. Other sources supply the same document
|
|
12
|
+
* contract directly.
|
|
13
|
+
*
|
|
14
|
+
* @param input - Document identity, revision, optional locale and the anchored text.
|
|
15
|
+
* @returns A document whose parts alternate text strings and section objects.
|
|
16
|
+
* @throws TypeError For an unmatched closing anchor or an anchor left open at the end.
|
|
17
|
+
*/
|
|
3
18
|
export declare function parseKnowledgeDocument(input: {
|
|
4
19
|
id: string;
|
|
5
20
|
revision: string;
|
|
6
21
|
text: string;
|
|
7
22
|
locale?: string;
|
|
8
23
|
}): KnowledgeDocument;
|
|
24
|
+
/**
|
|
25
|
+
* Deep-copy and freeze a document while indexing its sections by id.
|
|
26
|
+
*
|
|
27
|
+
* @param document - Declared document, possibly sharing arrays or containing cycles.
|
|
28
|
+
* @returns The frozen document plus a map from section id to its frozen section.
|
|
29
|
+
* @throws TypeError For a missing identity or parts array, a sparse or cyclic tree, a blank
|
|
30
|
+
* section id, or a duplicate section id.
|
|
31
|
+
*/
|
|
9
32
|
export declare function compileKnowledgeDocument(document: KnowledgeDocument): {
|
|
10
33
|
document: Readonly<{
|
|
11
34
|
id: string;
|
|
@@ -15,4 +38,11 @@ export declare function compileKnowledgeDocument(document: KnowledgeDocument): {
|
|
|
15
38
|
}>;
|
|
16
39
|
sections: Map<string, KnowledgeSection>;
|
|
17
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Flatten parts into text.
|
|
43
|
+
*
|
|
44
|
+
* @param parts - Document parts; nested sections are traversed in order.
|
|
45
|
+
* @param subtree - When false, nested section text is skipped and only top-level text remains.
|
|
46
|
+
* @returns Concatenated text with separators left to the caller.
|
|
47
|
+
*/
|
|
18
48
|
export declare function knowledgeText(parts: readonly KnowledgePart[], subtree?: boolean): string;
|