@jangts/agent-core 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.md +27 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +45 -17
- package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
- package/development/skills/agent-core-app/templates/catalog.json +36 -22
- package/dist/cjs/capabilities/index.js +13 -0
- package/dist/cjs/capabilities/invocation.js +80 -10
- package/dist/cjs/capabilities/model.js +126 -13
- package/dist/cjs/capabilities/tool-runtime.js +64 -12
- package/dist/cjs/capabilities/tools.js +266 -31
- package/dist/cjs/context/assembly.js +46 -5
- package/dist/cjs/context/audit.js +31 -6
- package/dist/cjs/context/fragments.js +54 -11
- package/dist/cjs/context/index.js +12 -0
- package/dist/cjs/context/journal.js +84 -7
- package/dist/cjs/context/plan.js +30 -2
- package/dist/cjs/diagnostics/catalog.js +11 -3
- package/dist/cjs/diagnostics/index.js +149 -29
- package/dist/cjs/diagnostics/sub-flow.js +240 -40
- package/dist/cjs/errors.js +99 -17
- package/dist/cjs/execution/branch.js +20 -4
- package/dist/cjs/execution/engine.js +470 -56
- package/dist/cjs/execution/events.js +136 -18
- package/dist/cjs/execution/index.js +7 -0
- package/dist/cjs/execution/reporting.js +75 -6
- package/dist/cjs/execution/state.js +161 -22
- package/dist/cjs/execution/workflow.js +224 -32
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/kits/aggregation.js +45 -3
- package/dist/cjs/kits/answering/batch.js +23 -4
- package/dist/cjs/kits/answering/check-result.js +31 -8
- package/dist/cjs/kits/answering/checks.js +24 -3
- package/dist/cjs/kits/answering/flow.js +192 -36
- package/dist/cjs/kits/answering/index.js +19 -1
- package/dist/cjs/kits/answering/tasks.js +88 -13
- package/dist/cjs/kits/artifacts.js +36 -4
- package/dist/cjs/kits/candidates.js +47 -5
- package/dist/cjs/kits/delivery.js +40 -5
- package/dist/cjs/kits/durable.js +155 -31
- package/dist/cjs/kits/evidence.js +66 -15
- package/dist/cjs/kits/family.js +152 -22
- package/dist/cjs/kits/index.js +12 -1
- package/dist/cjs/kits/inference.js +104 -16
- package/dist/cjs/kits/intents/catalog.js +67 -16
- package/dist/cjs/kits/intents/index.js +11 -0
- package/dist/cjs/kits/intents/registry.js +188 -43
- package/dist/cjs/kits/intents/scopes.js +215 -46
- package/dist/cjs/kits/interaction/command.js +140 -36
- package/dist/cjs/kits/interaction/commands.js +86 -11
- package/dist/cjs/kits/interaction/handlers.js +27 -10
- package/dist/cjs/kits/interaction/index.js +10 -0
- package/dist/cjs/kits/interaction/transfer.js +80 -14
- package/dist/cjs/kits/knowledge/catalog.js +62 -11
- package/dist/cjs/kits/knowledge/index.js +16 -1
- package/dist/cjs/kits/knowledge/publication.js +99 -23
- package/dist/cjs/kits/knowledge/sections.js +33 -4
- package/dist/cjs/kits/normalization.js +51 -7
- package/dist/cjs/kits/policies.js +79 -15
- package/dist/cjs/kits/presentation/events.js +54 -10
- package/dist/cjs/kits/presentation/index.js +24 -1
- package/dist/cjs/kits/presentation/outputs.js +176 -38
- package/dist/cjs/kits/presentation/templates.js +33 -5
- package/dist/cjs/kits/presentation/variants.js +31 -2
- package/dist/cjs/kits/projection.js +63 -8
- package/dist/cjs/kits/rank-fusion.js +27 -4
- package/dist/cjs/kits/reflection-log-source.js +89 -16
- package/dist/cjs/kits/reflection.js +234 -60
- package/dist/cjs/kits/retrieval.js +98 -18
- package/dist/cjs/kits/search.js +180 -27
- package/dist/cjs/kits/text-skills.js +104 -19
- package/dist/cjs/kits/tools.js +415 -74
- package/dist/cjs/kits/vector-search.js +50 -16
- package/dist/cjs/mock/node.js +7 -1
- package/dist/cjs/mock/web.js +7 -1
- package/dist/cjs/mock.js +7 -1
- package/dist/cjs/model/binding.js +68 -17
- package/dist/cjs/model/call-budget.js +45 -4
- package/dist/cjs/model/decision-retry.js +19 -1
- package/dist/cjs/model/defaults.js +27 -4
- package/dist/cjs/model/index.js +7 -0
- package/dist/cjs/model/interactions/arguments.js +36 -1
- package/dist/cjs/model/interactions/json-object.js +48 -12
- package/dist/cjs/model/interactions/native-functions.js +52 -10
- package/dist/cjs/model/message-diagnostics.js +17 -4
- package/dist/cjs/model/options.js +9 -1
- package/dist/cjs/model/preparation.js +86 -12
- package/dist/cjs/model/runner.js +413 -79
- package/dist/cjs/model/selection-transport.js +48 -8
- package/dist/cjs/model/settings.js +67 -13
- package/dist/cjs/model/token-budget.js +69 -11
- package/dist/cjs/model/transports.js +59 -6
- package/dist/cjs/structs/common.js +11 -0
- package/dist/cjs/structs/debug.js +34 -5
- package/dist/cjs/structs/errors.js +26 -1
- package/dist/cjs/structs/index.js +11 -1
- package/dist/cjs/structs/kits/durable.js +7 -0
- package/dist/cjs/structs/kits/family.js +1 -0
- package/dist/cjs/structs/kits/interaction.js +8 -1
- package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
- package/dist/cjs/structs/kits/reflection.js +18 -3
- package/dist/cjs/structs/model/chat-provider.js +6 -0
- package/dist/cjs/structs/support/model/completion.js +2 -0
- package/dist/cjs/structs/support/model/messages.js +2 -0
- package/dist/cjs/support/capabilities.js +43 -6
- package/dist/cjs/support/context/assembly.js +88 -16
- package/dist/cjs/support/context/compression.js +48 -6
- package/dist/cjs/support/context/fragments.js +6 -0
- package/dist/cjs/support/context/history.js +36 -1
- package/dist/cjs/support/context/index.js +11 -0
- package/dist/cjs/support/context/nodes.js +164 -35
- package/dist/cjs/support/context/processing.js +319 -61
- package/dist/cjs/support/context/selection-policy.js +98 -21
- package/dist/cjs/support/context/selection.js +61 -10
- package/dist/cjs/support/context/snapshot.js +29 -7
- package/dist/cjs/support/context/strategies.js +120 -28
- package/dist/cjs/support/index.js +9 -1
- package/dist/cjs/support/model/capabilities.js +20 -1
- package/dist/cjs/support/model/chat-completions.js +92 -20
- package/dist/cjs/support/model/children.js +34 -6
- package/dist/cjs/support/model/compatible-provider.js +189 -59
- package/dist/cjs/support/model/completion/calls.js +61 -0
- package/dist/cjs/support/model/completion/default.js +32 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +102 -0
- package/dist/cjs/support/model/index.js +12 -0
- package/dist/cjs/support/model/interactions/index.js +12 -1
- package/dist/cjs/support/model/interactions/json-object.js +6 -0
- package/dist/cjs/support/model/interactions/native-functions.js +6 -0
- package/dist/cjs/support/model/observer.js +32 -6
- package/dist/cjs/support/model/preview-rules.js +66 -16
- package/dist/cjs/support/model/reply-preview.js +77 -17
- package/dist/cjs/support/model/stage-transport.js +33 -7
- package/dist/cjs/support/model/strategies.js +75 -14
- package/dist/cjs/support/model/transports.js +53 -11
- package/dist/cjs/support/registration.js +49 -7
- package/dist/cjs/support/schema.js +46 -4
- package/dist/cjs/support/stream-events.js +60 -8
- package/dist/cjs/support/tool-runtime.js +6 -0
- package/dist/cjs/support/tools.js +79 -10
- package/dist/cjs/support/transport/index.js +7 -0
- package/dist/cjs/support/transport/json.js +28 -4
- package/dist/cjs/support/transport/sse.js +25 -2
- package/dist/cjs/utils/break-observer.js +20 -2
- package/dist/cjs/utils/cancellation.js +77 -9
- package/dist/cjs/utils/catalog.js +19 -4
- package/dist/cjs/utils/debug.js +14 -2
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/interaction-definition.js +26 -6
- package/dist/cjs/utils/invocation.js +42 -4
- package/dist/cjs/utils/model-protocol.js +20 -1
- package/dist/cjs/utils/object.js +16 -0
- package/dist/cjs/utils/observer.js +22 -2
- package/dist/cjs/utils/protocol-registry.js +47 -4
- package/dist/cjs/utils/query-key.js +21 -2
- package/dist/cjs/utils/registration.js +18 -2
- package/dist/cjs/utils/rules.js +39 -11
- package/dist/cjs/utils/schema-adapter.js +25 -2
- package/dist/cjs/utils/synchronous.js +64 -7
- package/dist/cjs/utils/text.js +15 -1
- package/dist/esm/capabilities/index.d.ts +13 -0
- package/dist/esm/capabilities/index.js +13 -0
- package/dist/esm/capabilities/invocation.d.ts +16 -2
- package/dist/esm/capabilities/invocation.js +80 -10
- package/dist/esm/capabilities/model.d.ts +68 -1
- package/dist/esm/capabilities/model.js +126 -13
- package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
- package/dist/esm/capabilities/tool-runtime.js +64 -12
- package/dist/esm/capabilities/tools.d.ts +96 -3
- package/dist/esm/capabilities/tools.js +267 -32
- package/dist/esm/context/assembly.d.ts +13 -2
- package/dist/esm/context/assembly.js +46 -5
- package/dist/esm/context/audit.d.ts +23 -1
- package/dist/esm/context/audit.js +31 -6
- package/dist/esm/context/fragments.d.ts +37 -3
- package/dist/esm/context/fragments.js +54 -11
- package/dist/esm/context/index.d.ts +12 -0
- package/dist/esm/context/index.js +12 -0
- package/dist/esm/context/journal.d.ts +32 -1
- package/dist/esm/context/journal.js +84 -7
- package/dist/esm/context/plan.d.ts +11 -1
- package/dist/esm/context/plan.js +30 -2
- package/dist/esm/diagnostics/catalog.js +11 -3
- package/dist/esm/diagnostics/index.d.ts +30 -2
- package/dist/esm/diagnostics/index.js +149 -29
- package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
- package/dist/esm/diagnostics/sub-flow.js +240 -40
- package/dist/esm/errors.d.ts +22 -2
- package/dist/esm/errors.js +99 -17
- package/dist/esm/execution/branch.d.ts +19 -1
- package/dist/esm/execution/branch.js +20 -4
- package/dist/esm/execution/engine.d.ts +291 -5
- package/dist/esm/execution/engine.js +471 -57
- package/dist/esm/execution/events.d.ts +16 -2
- package/dist/esm/execution/events.js +136 -18
- package/dist/esm/execution/index.d.ts +7 -0
- package/dist/esm/execution/index.js +7 -0
- package/dist/esm/execution/reporting.d.ts +49 -1
- package/dist/esm/execution/reporting.js +75 -6
- package/dist/esm/execution/state.d.ts +126 -10
- package/dist/esm/execution/state.js +161 -22
- package/dist/esm/execution/workflow.d.ts +121 -3
- package/dist/esm/execution/workflow.js +224 -32
- package/dist/esm/index.d.ts +17 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/kits/aggregation.d.ts +34 -2
- package/dist/esm/kits/aggregation.js +45 -3
- package/dist/esm/kits/answering/batch.d.ts +17 -0
- package/dist/esm/kits/answering/batch.js +23 -4
- package/dist/esm/kits/answering/check-result.d.ts +18 -1
- package/dist/esm/kits/answering/check-result.js +31 -8
- package/dist/esm/kits/answering/checks.d.ts +11 -0
- package/dist/esm/kits/answering/checks.js +24 -3
- package/dist/esm/kits/answering/flow.d.ts +25 -2
- package/dist/esm/kits/answering/flow.js +192 -36
- package/dist/esm/kits/answering/index.d.ts +12 -0
- package/dist/esm/kits/answering/index.js +19 -1
- package/dist/esm/kits/answering/tasks.d.ts +32 -1
- package/dist/esm/kits/answering/tasks.js +88 -13
- package/dist/esm/kits/artifacts.d.ts +11 -0
- package/dist/esm/kits/artifacts.js +36 -4
- package/dist/esm/kits/candidates.d.ts +23 -1
- package/dist/esm/kits/candidates.js +47 -5
- package/dist/esm/kits/delivery.d.ts +34 -0
- package/dist/esm/kits/delivery.js +40 -5
- package/dist/esm/kits/durable.d.ts +19 -0
- package/dist/esm/kits/durable.js +155 -31
- package/dist/esm/kits/evidence.d.ts +28 -5
- package/dist/esm/kits/evidence.js +66 -15
- package/dist/esm/kits/family.d.ts +17 -1
- package/dist/esm/kits/family.js +152 -22
- package/dist/esm/kits/index.d.ts +12 -1
- package/dist/esm/kits/index.js +12 -1
- package/dist/esm/kits/inference.d.ts +64 -0
- package/dist/esm/kits/inference.js +104 -16
- package/dist/esm/kits/intents/catalog.d.ts +13 -1
- package/dist/esm/kits/intents/catalog.js +67 -16
- package/dist/esm/kits/intents/index.d.ts +11 -0
- package/dist/esm/kits/intents/index.js +11 -0
- package/dist/esm/kits/intents/registry.d.ts +61 -3
- package/dist/esm/kits/intents/registry.js +188 -43
- package/dist/esm/kits/intents/scopes.d.ts +73 -3
- package/dist/esm/kits/intents/scopes.js +215 -46
- package/dist/esm/kits/interaction/command.d.ts +38 -4
- package/dist/esm/kits/interaction/command.js +140 -36
- package/dist/esm/kits/interaction/commands.d.ts +66 -2
- package/dist/esm/kits/interaction/commands.js +86 -11
- package/dist/esm/kits/interaction/handlers.d.ts +19 -2
- package/dist/esm/kits/interaction/handlers.js +27 -10
- package/dist/esm/kits/interaction/index.d.ts +10 -0
- package/dist/esm/kits/interaction/index.js +10 -0
- package/dist/esm/kits/interaction/transfer.d.ts +39 -2
- package/dist/esm/kits/interaction/transfer.js +80 -14
- package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
- package/dist/esm/kits/knowledge/catalog.js +62 -11
- package/dist/esm/kits/knowledge/index.d.ts +11 -0
- package/dist/esm/kits/knowledge/index.js +16 -1
- package/dist/esm/kits/knowledge/publication.d.ts +15 -1
- package/dist/esm/kits/knowledge/publication.js +99 -23
- package/dist/esm/kits/knowledge/sections.d.ts +31 -1
- package/dist/esm/kits/knowledge/sections.js +33 -4
- package/dist/esm/kits/normalization.d.ts +25 -2
- package/dist/esm/kits/normalization.js +51 -7
- package/dist/esm/kits/policies.d.ts +26 -3
- package/dist/esm/kits/policies.js +79 -15
- package/dist/esm/kits/presentation/events.d.ts +51 -4
- package/dist/esm/kits/presentation/events.js +54 -10
- package/dist/esm/kits/presentation/index.d.ts +12 -0
- package/dist/esm/kits/presentation/index.js +25 -2
- package/dist/esm/kits/presentation/outputs.d.ts +30 -1
- package/dist/esm/kits/presentation/outputs.js +176 -38
- package/dist/esm/kits/presentation/templates.d.ts +32 -3
- package/dist/esm/kits/presentation/templates.js +33 -5
- package/dist/esm/kits/presentation/variants.d.ts +29 -0
- package/dist/esm/kits/presentation/variants.js +31 -2
- package/dist/esm/kits/projection.d.ts +42 -5
- package/dist/esm/kits/projection.js +63 -8
- package/dist/esm/kits/rank-fusion.d.ts +21 -1
- package/dist/esm/kits/rank-fusion.js +28 -5
- package/dist/esm/kits/reflection-log-source.d.ts +28 -1
- package/dist/esm/kits/reflection-log-source.js +89 -16
- package/dist/esm/kits/reflection.d.ts +17 -1
- package/dist/esm/kits/reflection.js +235 -61
- package/dist/esm/kits/retrieval.d.ts +18 -2
- package/dist/esm/kits/retrieval.js +98 -18
- package/dist/esm/kits/search.d.ts +56 -3
- package/dist/esm/kits/search.js +180 -27
- package/dist/esm/kits/text-skills.d.ts +16 -2
- package/dist/esm/kits/text-skills.js +104 -19
- package/dist/esm/kits/tools.d.ts +122 -2
- package/dist/esm/kits/tools.js +416 -74
- package/dist/esm/kits/vector-search.d.ts +47 -1
- package/dist/esm/kits/vector-search.js +51 -17
- package/dist/esm/mock/node.d.ts +7 -0
- package/dist/esm/mock/node.js +7 -1
- package/dist/esm/mock/web.d.ts +7 -0
- package/dist/esm/mock/web.js +7 -1
- package/dist/esm/mock.d.ts +7 -0
- package/dist/esm/mock.js +7 -1
- package/dist/esm/model/binding.d.ts +32 -3
- package/dist/esm/model/binding.js +68 -17
- package/dist/esm/model/call-budget.d.ts +30 -2
- package/dist/esm/model/call-budget.js +45 -4
- package/dist/esm/model/decision-retry.d.ts +10 -1
- package/dist/esm/model/decision-retry.js +19 -1
- package/dist/esm/model/defaults.d.ts +13 -2
- package/dist/esm/model/defaults.js +27 -4
- package/dist/esm/model/index.d.ts +7 -0
- package/dist/esm/model/index.js +7 -0
- package/dist/esm/model/interactions/arguments.d.ts +27 -0
- package/dist/esm/model/interactions/arguments.js +36 -1
- package/dist/esm/model/interactions/json-object.d.ts +7 -1
- package/dist/esm/model/interactions/json-object.js +48 -12
- package/dist/esm/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/model/interactions/native-functions.js +52 -10
- package/dist/esm/model/message-diagnostics.d.ts +17 -1
- package/dist/esm/model/message-diagnostics.js +17 -4
- package/dist/esm/model/options.d.ts +18 -1
- package/dist/esm/model/options.js +9 -1
- package/dist/esm/model/preparation.d.ts +30 -2
- package/dist/esm/model/preparation.js +86 -12
- package/dist/esm/model/runner.d.ts +129 -5
- package/dist/esm/model/runner.js +414 -80
- package/dist/esm/model/selection-transport.d.ts +14 -1
- package/dist/esm/model/selection-transport.js +48 -8
- package/dist/esm/model/settings.d.ts +11 -0
- package/dist/esm/model/settings.js +67 -13
- package/dist/esm/model/token-budget.d.ts +59 -1
- package/dist/esm/model/token-budget.js +69 -11
- package/dist/esm/model/transports.d.ts +20 -2
- package/dist/esm/model/transports.js +59 -6
- package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
- package/dist/esm/structs/capabilities/model.d.ts +27 -0
- package/dist/esm/structs/capabilities/tools.d.ts +38 -0
- package/dist/esm/structs/common.d.ts +62 -2
- package/dist/esm/structs/common.js +11 -0
- package/dist/esm/structs/context/fragments.d.ts +28 -0
- package/dist/esm/structs/context/journal.d.ts +28 -3
- package/dist/esm/structs/context/processing.d.ts +11 -0
- package/dist/esm/structs/debug.d.ts +58 -1
- package/dist/esm/structs/debug.js +34 -5
- package/dist/esm/structs/diagnostics.d.ts +119 -1
- package/dist/esm/structs/errors.d.ts +42 -1
- package/dist/esm/structs/errors.js +26 -1
- package/dist/esm/structs/execution/engine.d.ts +24 -1
- package/dist/esm/structs/execution/events.d.ts +12 -0
- package/dist/esm/structs/execution/workflow.d.ts +71 -0
- package/dist/esm/structs/index.d.ts +11 -1
- package/dist/esm/structs/index.js +11 -1
- package/dist/esm/structs/invocation.d.ts +30 -0
- package/dist/esm/structs/kits/aggregation.d.ts +12 -0
- package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
- package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
- package/dist/esm/structs/kits/answering/state.d.ts +21 -0
- package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
- package/dist/esm/structs/kits/artifacts.d.ts +14 -0
- package/dist/esm/structs/kits/candidates.d.ts +19 -0
- package/dist/esm/structs/kits/delivery.d.ts +22 -0
- package/dist/esm/structs/kits/durable.d.ts +56 -3
- package/dist/esm/structs/kits/durable.js +7 -0
- package/dist/esm/structs/kits/evidence.d.ts +23 -0
- package/dist/esm/structs/kits/family.d.ts +49 -1
- package/dist/esm/structs/kits/family.js +1 -0
- package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
- package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
- package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
- package/dist/esm/structs/kits/interaction.d.ts +64 -0
- package/dist/esm/structs/kits/interaction.js +8 -1
- package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
- package/dist/esm/structs/kits/knowledge-publication.js +1 -0
- package/dist/esm/structs/kits/knowledge.d.ts +39 -2
- package/dist/esm/structs/kits/normalization.d.ts +15 -0
- package/dist/esm/structs/kits/policies.d.ts +25 -1
- package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
- package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
- package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
- package/dist/esm/structs/kits/projection.d.ts +21 -0
- package/dist/esm/structs/kits/reflection.d.ts +61 -2
- package/dist/esm/structs/kits/reflection.js +18 -3
- package/dist/esm/structs/kits/retrieval.d.ts +38 -0
- package/dist/esm/structs/kits/search.d.ts +22 -0
- package/dist/esm/structs/kits/text-skills.d.ts +36 -0
- package/dist/esm/structs/kits/tools.d.ts +87 -0
- package/dist/esm/structs/model/chat-provider.d.ts +24 -1
- package/dist/esm/structs/model/chat-provider.js +6 -0
- package/dist/esm/structs/model/interactions.d.ts +38 -0
- package/dist/esm/structs/model/messages.d.ts +30 -0
- package/dist/esm/structs/model/runtime.d.ts +104 -6
- package/dist/esm/structs/support/capabilities.d.ts +19 -2
- package/dist/esm/structs/support/context-processing.d.ts +88 -9
- package/dist/esm/structs/support/context.d.ts +29 -1
- package/dist/esm/structs/support/model/completion.d.ts +50 -0
- package/dist/esm/structs/support/model/completion.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +13 -1
- package/dist/esm/structs/support/model/messages.d.ts +52 -0
- package/dist/esm/structs/support/model/messages.js +1 -0
- package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
- package/dist/esm/structs/support/model/provider.d.ts +71 -6
- package/dist/esm/structs/support/registration.d.ts +13 -0
- package/dist/esm/structs/support/schema.d.ts +14 -0
- package/dist/esm/structs/support/tools.d.ts +28 -0
- package/dist/esm/structs/support/transport/json.d.ts +16 -0
- package/dist/esm/structs/support/transport/sse.d.ts +15 -0
- package/dist/esm/structs/utils/rules.d.ts +19 -0
- package/dist/esm/support/capabilities.d.ts +25 -2
- package/dist/esm/support/capabilities.js +43 -6
- package/dist/esm/support/context/assembly.d.ts +35 -4
- package/dist/esm/support/context/assembly.js +88 -16
- package/dist/esm/support/context/compression.d.ts +17 -1
- package/dist/esm/support/context/compression.js +48 -6
- package/dist/esm/support/context/fragments.d.ts +6 -0
- package/dist/esm/support/context/fragments.js +6 -0
- package/dist/esm/support/context/history.d.ts +43 -0
- package/dist/esm/support/context/history.js +36 -1
- package/dist/esm/support/context/index.d.ts +13 -2
- package/dist/esm/support/context/index.js +12 -1
- package/dist/esm/support/context/nodes.d.ts +49 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +145 -1
- package/dist/esm/support/context/processing.js +320 -62
- package/dist/esm/support/context/selection-policy.d.ts +42 -2
- package/dist/esm/support/context/selection-policy.js +98 -21
- package/dist/esm/support/context/selection.d.ts +14 -1
- package/dist/esm/support/context/selection.js +61 -10
- package/dist/esm/support/context/snapshot.d.ts +23 -1
- package/dist/esm/support/context/snapshot.js +29 -7
- package/dist/esm/support/context/strategies.d.ts +35 -2
- package/dist/esm/support/context/strategies.js +120 -28
- package/dist/esm/support/index.d.ts +9 -1
- package/dist/esm/support/index.js +9 -1
- package/dist/esm/support/model/capabilities.d.ts +10 -0
- package/dist/esm/support/model/capabilities.js +20 -1
- package/dist/esm/support/model/chat-completions.d.ts +44 -15
- package/dist/esm/support/model/chat-completions.js +92 -20
- package/dist/esm/support/model/children.d.ts +32 -2
- package/dist/esm/support/model/children.js +34 -6
- package/dist/esm/support/model/compatible-provider.d.ts +29 -3
- package/dist/esm/support/model/compatible-provider.js +190 -60
- package/dist/esm/support/model/completion/calls.d.ts +40 -0
- package/dist/esm/support/model/completion/calls.js +58 -0
- package/dist/esm/support/model/completion/default.d.ts +10 -0
- package/dist/esm/support/model/completion/default.js +29 -0
- package/dist/esm/support/model/completion/index.d.ts +10 -0
- package/dist/esm/support/model/completion/index.js +22 -0
- package/dist/esm/support/model/completion/session.d.ts +11 -0
- package/dist/esm/support/model/completion/session.js +99 -0
- package/dist/esm/support/model/index.d.ts +14 -0
- package/dist/esm/support/model/index.js +12 -0
- package/dist/esm/support/model/interactions/index.d.ts +1 -1
- package/dist/esm/support/model/interactions/index.js +12 -1
- package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
- package/dist/esm/support/model/interactions/json-object.js +6 -0
- package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/support/model/interactions/native-functions.js +6 -0
- package/dist/esm/support/model/observer.d.ts +25 -2
- package/dist/esm/support/model/observer.js +32 -6
- package/dist/esm/support/model/preview-rules.d.ts +20 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +15 -1
- package/dist/esm/support/model/reply-preview.js +77 -17
- package/dist/esm/support/model/stage-transport.d.ts +9 -1
- package/dist/esm/support/model/stage-transport.js +33 -7
- package/dist/esm/support/model/strategies.d.ts +24 -2
- package/dist/esm/support/model/strategies.js +75 -14
- package/dist/esm/support/model/transports.d.ts +17 -1
- package/dist/esm/support/model/transports.js +53 -11
- package/dist/esm/support/registration.d.ts +20 -1
- package/dist/esm/support/registration.js +49 -7
- package/dist/esm/support/schema.d.ts +31 -1
- package/dist/esm/support/schema.js +46 -4
- package/dist/esm/support/stream-events.d.ts +22 -1
- package/dist/esm/support/stream-events.js +60 -8
- package/dist/esm/support/tool-runtime.d.ts +6 -0
- package/dist/esm/support/tool-runtime.js +6 -0
- package/dist/esm/support/tools.d.ts +22 -0
- package/dist/esm/support/tools.js +79 -10
- package/dist/esm/support/transport/index.d.ts +7 -0
- package/dist/esm/support/transport/index.js +7 -0
- package/dist/esm/support/transport/json.d.ts +29 -2
- package/dist/esm/support/transport/json.js +28 -4
- package/dist/esm/support/transport/sse.d.ts +31 -1
- package/dist/esm/support/transport/sse.js +25 -2
- package/dist/esm/types.d.ts +9 -1
- package/dist/esm/utils/break-observer.d.ts +27 -2
- package/dist/esm/utils/break-observer.js +20 -2
- package/dist/esm/utils/cancellation.d.ts +56 -5
- package/dist/esm/utils/cancellation.js +77 -9
- package/dist/esm/utils/catalog.d.ts +20 -1
- package/dist/esm/utils/catalog.js +19 -4
- package/dist/esm/utils/debug.d.ts +20 -1
- package/dist/esm/utils/debug.js +14 -2
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/interaction-definition.d.ts +18 -1
- package/dist/esm/utils/interaction-definition.js +26 -6
- package/dist/esm/utils/invocation.d.ts +36 -1
- package/dist/esm/utils/invocation.js +42 -4
- package/dist/esm/utils/model-protocol.d.ts +8 -0
- package/dist/esm/utils/model-protocol.js +20 -1
- package/dist/esm/utils/object.d.ts +16 -0
- package/dist/esm/utils/object.js +16 -0
- package/dist/esm/utils/observer.d.ts +19 -1
- package/dist/esm/utils/observer.js +22 -2
- package/dist/esm/utils/protocol-registry.d.ts +38 -1
- package/dist/esm/utils/protocol-registry.js +47 -4
- package/dist/esm/utils/query-key.d.ts +11 -1
- package/dist/esm/utils/query-key.js +21 -2
- package/dist/esm/utils/registration.d.ts +34 -2
- package/dist/esm/utils/registration.js +18 -2
- package/dist/esm/utils/rules.d.ts +81 -4
- package/dist/esm/utils/rules.js +39 -11
- package/dist/esm/utils/schema-adapter.d.ts +12 -1
- package/dist/esm/utils/schema-adapter.js +25 -2
- package/dist/esm/utils/synchronous.d.ts +60 -4
- package/dist/esm/utils/synchronous.js +64 -7
- package/dist/esm/utils/text.d.ts +15 -1
- package/dist/esm/utils/text.js +15 -1
- package/package.json +3 -2
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineKnowledgeCatalog = defineKnowledgeCatalog;
|
|
4
|
+
/**
|
|
5
|
+
* Knowledge Kit: compile documents into a sectioned catalog and read budgeted snapshots.
|
|
6
|
+
*
|
|
7
|
+
* Place in the package: part of the `knowledge` Kit. A snapshot carries text, revision and an
|
|
8
|
+
* opaque id; this module never fetches, authorizes or persists — it only resolves declared
|
|
9
|
+
* documents and sections.
|
|
10
|
+
*
|
|
11
|
+
* Exports: `defineKnowledgeCatalog`, and the knowledge document/read/snapshot types.
|
|
12
|
+
*/
|
|
4
13
|
const catalog_js_1 = require("../../utils/catalog.js");
|
|
5
14
|
const sections_js_1 = require("./sections.js");
|
|
6
15
|
const observer_js_1 = require("../../utils/observer.js");
|
|
16
|
+
/**
|
|
17
|
+
* Compile a knowledge catalog from document declarations.
|
|
18
|
+
*
|
|
19
|
+
* Reads are declarative: `document` returns the whole text, `self` returns exactly the named
|
|
20
|
+
* sections and `subtree` includes their nested sections. Section ids are validated up front,
|
|
21
|
+
* so a typo fails at read time instead of silently returning partial content.
|
|
22
|
+
*
|
|
23
|
+
* @param documents - Unique-id documents, each compiled into an immutable section tree.
|
|
24
|
+
* @param options - Optional `maxChars` budget and an observer for successful reads.
|
|
25
|
+
* @returns A frozen catalog extended with `sectionIds`, `assertSelection` and `read`.
|
|
26
|
+
* @throws TypeError For a duplicate document id, an invalid budget, an unknown document or
|
|
27
|
+
* section, or a malformed selection; `RangeError` when the content exceeds `maxChars`.
|
|
28
|
+
*/
|
|
7
29
|
function defineKnowledgeCatalog(documents, options = {}) {
|
|
8
30
|
const { maxChars } = options, observe = options.observe?.bind(options);
|
|
9
31
|
const catalog = new Map();
|
|
@@ -23,7 +45,9 @@ function defineKnowledgeCatalog(documents, options = {}) {
|
|
|
23
45
|
if (!read.selection || !['document', 'self', 'subtree'].includes(read.selection.mode))
|
|
24
46
|
throw new TypeError('Invalid knowledge selection');
|
|
25
47
|
if (read.selection.mode !== 'document') {
|
|
26
|
-
if (!Array.isArray(read.selection.sectionIds) ||
|
|
48
|
+
if (!Array.isArray(read.selection.sectionIds) ||
|
|
49
|
+
!read.selection.sectionIds.length ||
|
|
50
|
+
new Set(read.selection.sectionIds).size !== read.selection.sectionIds.length)
|
|
27
51
|
throw new TypeError('Invalid knowledge section selection');
|
|
28
52
|
for (const id of read.selection.sectionIds)
|
|
29
53
|
if (!entry.sections.has(id))
|
|
@@ -31,21 +55,48 @@ function defineKnowledgeCatalog(documents, options = {}) {
|
|
|
31
55
|
}
|
|
32
56
|
return { read, entry };
|
|
33
57
|
};
|
|
34
|
-
const sectionIds = (id) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
const sectionIds = (id) => {
|
|
59
|
+
const entry = catalog.get(id);
|
|
60
|
+
if (!entry)
|
|
61
|
+
throw new TypeError(`Unknown knowledge document: ${id}`);
|
|
62
|
+
return Object.freeze([...entry.sections.keys()]);
|
|
63
|
+
};
|
|
64
|
+
const assertSelection = (read) => {
|
|
65
|
+
resolve(read);
|
|
66
|
+
};
|
|
67
|
+
return Object.freeze({
|
|
68
|
+
...(0, catalog_js_1.readonlyCatalog)([...catalog.values()].map((entry) => entry.document), (id) => new TypeError(`Unknown knowledge document: ${id}`)),
|
|
69
|
+
sectionIds,
|
|
70
|
+
assertSelection,
|
|
39
71
|
read(input) {
|
|
40
72
|
const { read, entry } = resolve(input), raw = read.selection;
|
|
41
|
-
const selection = raw.mode === 'document'
|
|
42
|
-
|
|
73
|
+
const selection = raw.mode === 'document'
|
|
74
|
+
? Object.freeze({ mode: 'document' })
|
|
75
|
+
: Object.freeze({ mode: raw.mode, sectionIds: Object.freeze([...raw.sectionIds]) });
|
|
76
|
+
const content = (selection.mode === 'document'
|
|
77
|
+
? (0, sections_js_1.knowledgeText)(entry.document.parts)
|
|
78
|
+
: selection.sectionIds
|
|
79
|
+
.map((id) => (0, sections_js_1.knowledgeText)(entry.sections.get(id).parts, selection.mode === 'subtree'))
|
|
80
|
+
.join('\n\n')).trim();
|
|
43
81
|
if (maxChars !== undefined && content.length > maxChars)
|
|
44
82
|
throw new RangeError('Knowledge selection exceeds its budget');
|
|
45
83
|
// Preserve the existing opaque snapshot identity format.
|
|
46
|
-
const identitySelection = selection.mode === 'document'
|
|
47
|
-
|
|
48
|
-
|
|
84
|
+
const identitySelection = selection.mode === 'document'
|
|
85
|
+
? selection
|
|
86
|
+
: { mode: selection.mode, sections: selection.sectionIds };
|
|
87
|
+
const snapshot = Object.freeze({
|
|
88
|
+
documentId: read.documentId,
|
|
89
|
+
selection,
|
|
90
|
+
revision: entry.document.revision,
|
|
91
|
+
locale: entry.document.locale,
|
|
92
|
+
content,
|
|
93
|
+
id: JSON.stringify([
|
|
94
|
+
read.documentId,
|
|
95
|
+
entry.document.revision,
|
|
96
|
+
entry.document.locale,
|
|
97
|
+
identitySelection,
|
|
98
|
+
]),
|
|
99
|
+
});
|
|
49
100
|
(0, observer_js_1.observeSafely)(observe, snapshot);
|
|
50
101
|
return snapshot;
|
|
51
102
|
},
|
|
@@ -15,6 +15,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.Knowledge = exports.parseKnowledgeDocument = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Knowledge Kit entry: sectioned knowledge documents, snapshot reads and candidate publication.
|
|
20
|
+
*
|
|
21
|
+
* Place in the package: an optional App-side library. Documents, storage, authorization and
|
|
22
|
+
* provenance are App-owned; this directory owns the section tree, budgeted reads, opaque
|
|
23
|
+
* snapshot identity and the candidate/publish lifecycle over an atomic store revision.
|
|
24
|
+
*
|
|
25
|
+
* Exports: everything from `./catalog.js` and `./publication.js`, `parseKnowledgeDocument`, and
|
|
26
|
+
* the `Knowledge` namespace object.
|
|
27
|
+
*/
|
|
18
28
|
__exportStar(require("./catalog.js"), exports);
|
|
19
29
|
var sections_js_1 = require("./sections.js");
|
|
20
30
|
Object.defineProperty(exports, "parseKnowledgeDocument", { enumerable: true, get: function () { return sections_js_1.parseKnowledgeDocument; } });
|
|
@@ -22,4 +32,9 @@ const catalog_js_1 = require("./catalog.js");
|
|
|
22
32
|
const sections_js_2 = require("./sections.js");
|
|
23
33
|
const publication_js_1 = require("./publication.js");
|
|
24
34
|
__exportStar(require("./publication.js"), exports);
|
|
25
|
-
|
|
35
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
36
|
+
exports.Knowledge = Object.freeze({
|
|
37
|
+
defineKnowledgeCatalog: catalog_js_1.defineKnowledgeCatalog,
|
|
38
|
+
parseKnowledgeDocument: sections_js_2.parseKnowledgeDocument,
|
|
39
|
+
defineKnowledgePublication: publication_js_1.defineKnowledgePublication,
|
|
40
|
+
});
|
|
@@ -1,17 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineKnowledgePublication = defineKnowledgePublication;
|
|
4
|
+
/**
|
|
5
|
+
* Knowledge Kit: candidate preparation, verification and atomic publication of documents.
|
|
6
|
+
*
|
|
7
|
+
* Place in the package: part of the `knowledge` Kit. The store, authorization and provenance
|
|
8
|
+
* checks are App ports; this module owns revision checking, candidate expiry and capacity,
|
|
9
|
+
* compilation of proposed documents and the compare-and-swap commit.
|
|
10
|
+
*
|
|
11
|
+
* Exports: `defineKnowledgePublication`, and the publication record/candidate/source types.
|
|
12
|
+
*/
|
|
4
13
|
const catalog_js_1 = require("./catalog.js");
|
|
5
14
|
const invocation_js_1 = require("../../utils/invocation.js");
|
|
6
15
|
const cancellation_js_1 = require("../../utils/cancellation.js");
|
|
7
16
|
const rules_js_1 = require("../../utils/rules.js");
|
|
8
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Compile a publication lifecycle over one App-owned atomic record.
|
|
19
|
+
*
|
|
20
|
+
* Candidate preparation and publication share the same compiler and an App-owned atomic
|
|
21
|
+
* revision. `propose` compiles and validates a candidate but leaves published documents alone;
|
|
22
|
+
* `publish` re-verifies sources and the base revision before swapping, so a stale candidate can
|
|
23
|
+
* never overwrite newer content.
|
|
24
|
+
*
|
|
25
|
+
* @param options - Store, authorization, provenance verification, clock, optional required
|
|
26
|
+
* reads, capacity and retention bounds; handlers are bound to this options object.
|
|
27
|
+
* @returns A frozen publication exposing `read`, `propose`, `publish` and `reject`.
|
|
28
|
+
* @throws A configured error for invalid bounds, a malformed record or candidate, a revision
|
|
29
|
+
* conflict, an expired candidate, exhausted capacity, a changed base revision, or a public
|
|
30
|
+
* document whose content changed without a new revision.
|
|
31
|
+
*/
|
|
9
32
|
function defineKnowledgePublication(options) {
|
|
10
33
|
const load = options.store.load.bind(options.store), swap = options.store.compareAndSwap.bind(options.store);
|
|
11
34
|
const authorize = options.authorize.bind(options), verify = options.verifySources.bind(options), now = options.now?.bind(options) ?? Date.now;
|
|
35
|
+
// Defaults keep one record small: at most 32 pending candidates, each valid for seven days.
|
|
12
36
|
const maxCandidates = options.maxCandidates ?? 32, retention = options.candidateRetentionMs ?? 7 * 86400_000;
|
|
13
37
|
const maxChars = options.maxReadChars, reads = structuredClone(options.requiredReads ?? []);
|
|
14
|
-
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(maxCandidates) ||
|
|
38
|
+
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(maxCandidates) ||
|
|
39
|
+
maxCandidates < 1 ||
|
|
40
|
+
!Number.isSafeInteger(retention) ||
|
|
41
|
+
retention < 1, 'Invalid publication bounds');
|
|
15
42
|
const compile = (documents) => {
|
|
16
43
|
const catalog = (0, catalog_js_1.defineKnowledgeCatalog)(documents, { maxChars });
|
|
17
44
|
for (const read of reads)
|
|
@@ -24,24 +51,53 @@ function defineKnowledgePublication(options) {
|
|
|
24
51
|
const sourceSnapshot = (sources) => {
|
|
25
52
|
const invalid = 'Invalid or expired knowledge provenance';
|
|
26
53
|
(0, rules_js_1.breakWhile)(!Array.isArray(sources) || !sources.length || sources.length > 32, invalid);
|
|
27
|
-
const snapshot = Array.from(sources, source => ({
|
|
28
|
-
|
|
29
|
-
|
|
54
|
+
const snapshot = Array.from(sources, (source) => ({
|
|
55
|
+
id: source?.id,
|
|
56
|
+
revision: source?.revision,
|
|
57
|
+
expiresAtMs: source?.expiresAtMs,
|
|
58
|
+
}));
|
|
59
|
+
(0, rules_js_1.breakWhile)(snapshot.some((source) => typeof source.id !== 'string' ||
|
|
60
|
+
!source.id.trim() ||
|
|
61
|
+
typeof source.revision !== 'string' ||
|
|
62
|
+
!source.revision.trim() ||
|
|
63
|
+
(source.expiresAtMs !== undefined &&
|
|
64
|
+
(!Number.isFinite(source.expiresAtMs) || source.expiresAtMs <= now()))), invalid);
|
|
30
65
|
return snapshot;
|
|
31
66
|
};
|
|
32
67
|
const read = async (context) => {
|
|
33
68
|
context.signal.throwIfAborted();
|
|
34
69
|
const record = structuredClone(await (0, cancellation_js_1.awaitWithSignal)(load(), context.signal));
|
|
35
|
-
(0, rules_js_1.breakWhile)(!record ||
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
70
|
+
(0, rules_js_1.breakWhile)(!record ||
|
|
71
|
+
!Number.isSafeInteger(record.revision) ||
|
|
72
|
+
record.revision < 0 ||
|
|
73
|
+
!Number.isSafeInteger(record.publishedRevision) ||
|
|
74
|
+
record.publishedRevision < 0 ||
|
|
75
|
+
record.publishedRevision > record.revision ||
|
|
76
|
+
!Array.isArray(record.documents) ||
|
|
77
|
+
!Array.isArray(record.candidates) ||
|
|
78
|
+
record.candidates.length > maxCandidates, 'Invalid publication record');
|
|
79
|
+
(0, rules_js_1.breakWhile)(new Set(record.candidates.map((item) => item?.id)).size !== record.candidates.length ||
|
|
80
|
+
record.candidates.some((item) => !item ||
|
|
81
|
+
typeof item.id !== 'string' ||
|
|
82
|
+
!item.id ||
|
|
83
|
+
!Number.isSafeInteger(item.baseRevision) ||
|
|
84
|
+
item.baseRevision < 0 ||
|
|
85
|
+
item.baseRevision > record.publishedRevision ||
|
|
86
|
+
!Number.isFinite(item.createdAtMs) ||
|
|
87
|
+
!Number.isFinite(item.expiresAtMs) ||
|
|
88
|
+
item.expiresAtMs <= item.createdAtMs ||
|
|
89
|
+
!Array.isArray(item.sources) ||
|
|
90
|
+
!item.sources.length ||
|
|
91
|
+
item.sources.length > 32), 'Invalid knowledge candidate');
|
|
92
|
+
const compilationKey = JSON.stringify([
|
|
93
|
+
record.revision,
|
|
94
|
+
record.publishedRevision,
|
|
95
|
+
record.documents,
|
|
96
|
+
record.candidates.map((item) => item.document),
|
|
97
|
+
]);
|
|
42
98
|
if (compilationKey !== compiledRecord) {
|
|
43
99
|
for (const item of record.candidates)
|
|
44
|
-
compile([...record.documents.filter(doc => doc.id !== item.document.id), item.document]);
|
|
100
|
+
compile([...record.documents.filter((doc) => doc.id !== item.document.id), item.document]);
|
|
45
101
|
compile(record.documents);
|
|
46
102
|
compiledRecord = compilationKey;
|
|
47
103
|
}
|
|
@@ -64,14 +120,19 @@ function defineKnowledgePublication(options) {
|
|
|
64
120
|
return record;
|
|
65
121
|
};
|
|
66
122
|
const replacement = (record, document) => {
|
|
67
|
-
const previous = record.documents.find(item => item.id === document.id);
|
|
68
|
-
(0, rules_js_1.breakWhile)(!!previous &&
|
|
69
|
-
|
|
123
|
+
const previous = record.documents.find((item) => item.id === document.id);
|
|
124
|
+
(0, rules_js_1.breakWhile)(!!previous &&
|
|
125
|
+
previous.revision === document.revision &&
|
|
126
|
+
JSON.stringify(previous) !== JSON.stringify(document), 'Changed knowledge needs a new document revision');
|
|
127
|
+
const documents = [
|
|
128
|
+
...record.documents.filter((item) => item.id !== document.id),
|
|
129
|
+
structuredClone(document),
|
|
130
|
+
];
|
|
70
131
|
compile(documents);
|
|
71
132
|
return documents;
|
|
72
133
|
};
|
|
73
134
|
const candidate = (record, id) => {
|
|
74
|
-
const item = record.candidates.find(value => value.id === id);
|
|
135
|
+
const item = record.candidates.find((value) => value.id === id);
|
|
75
136
|
(0, rules_js_1.breakWhile)(!item || item.expiresAtMs <= now(), 'Knowledge candidate unavailable');
|
|
76
137
|
return item;
|
|
77
138
|
};
|
|
@@ -86,10 +147,16 @@ function defineKnowledgePublication(options) {
|
|
|
86
147
|
replacement(record, document);
|
|
87
148
|
await (0, cancellation_js_1.awaitAssertion)(() => verify(structuredClone(sources), context), context.signal, 'Knowledge provenance validation must return void');
|
|
88
149
|
sourceSnapshot(sources);
|
|
89
|
-
const candidates = record.candidates.filter(item => item.expiresAtMs > now());
|
|
150
|
+
const candidates = record.candidates.filter((item) => item.expiresAtMs > now());
|
|
90
151
|
(0, rules_js_1.breakWhile)(candidates.length >= maxCandidates, 'Knowledge candidate capacity exhausted');
|
|
91
|
-
const item = {
|
|
92
|
-
|
|
152
|
+
const item = {
|
|
153
|
+
id: (0, invocation_js_1.invocationId)(),
|
|
154
|
+
baseRevision: record.publishedRevision,
|
|
155
|
+
document,
|
|
156
|
+
sources,
|
|
157
|
+
createdAtMs: now(),
|
|
158
|
+
expiresAtMs: Math.min(now() + retention, ...sources.map((source) => source.expiresAtMs ?? Infinity)),
|
|
159
|
+
};
|
|
93
160
|
return commit(record, { ...record, revision: record.revision + 1, candidates: [...candidates, item] }, context, () => {
|
|
94
161
|
sourceSnapshot(sources);
|
|
95
162
|
(0, rules_js_1.breakWhile)(item.expiresAtMs <= now(), 'Knowledge candidate expired');
|
|
@@ -104,8 +171,13 @@ function defineKnowledgePublication(options) {
|
|
|
104
171
|
await (0, cancellation_js_1.awaitAssertion)(() => verify(structuredClone(sources), context), context.signal, 'Knowledge provenance validation must return void');
|
|
105
172
|
sourceSnapshot(sources);
|
|
106
173
|
const documents = replacement(record, item.document);
|
|
107
|
-
return commit(record, {
|
|
108
|
-
|
|
174
|
+
return commit(record, {
|
|
175
|
+
...record,
|
|
176
|
+
revision: record.revision + 1,
|
|
177
|
+
publishedRevision: record.publishedRevision + 1,
|
|
178
|
+
documents,
|
|
179
|
+
candidates: record.candidates.filter((value) => value.id !== item.id),
|
|
180
|
+
}, context, () => {
|
|
109
181
|
candidate(record, item.id);
|
|
110
182
|
sourceSnapshot(sources);
|
|
111
183
|
});
|
|
@@ -115,7 +187,11 @@ function defineKnowledgePublication(options) {
|
|
|
115
187
|
await (0, cancellation_js_1.awaitAssertion)(() => authorize('reject', context), context.signal, 'Knowledge publication authorization must return void');
|
|
116
188
|
const record = await checked(revision, context);
|
|
117
189
|
candidate(record, candidateId);
|
|
118
|
-
return commit(record, {
|
|
190
|
+
return commit(record, {
|
|
191
|
+
...record,
|
|
192
|
+
revision: record.revision + 1,
|
|
193
|
+
candidates: record.candidates.filter((item) => item.id !== candidateId),
|
|
194
|
+
}, context);
|
|
119
195
|
},
|
|
120
196
|
});
|
|
121
197
|
}
|
|
@@ -3,7 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseKnowledgeDocument = parseKnowledgeDocument;
|
|
4
4
|
exports.compileKnowledgeDocument = compileKnowledgeDocument;
|
|
5
5
|
exports.knowledgeText = knowledgeText;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Paired, nestable anchors are one text adapter. Other sources supply the same document
|
|
8
|
+
* contract directly.
|
|
9
|
+
*
|
|
10
|
+
* @param input - Document identity, revision, optional locale and the anchored text.
|
|
11
|
+
* @returns A document whose parts alternate text strings and section objects.
|
|
12
|
+
* @throws TypeError For an unmatched closing anchor or an anchor left open at the end.
|
|
13
|
+
*/
|
|
7
14
|
function parseKnowledgeDocument(input) {
|
|
8
15
|
const parts = [];
|
|
9
16
|
const stack = [];
|
|
@@ -29,6 +36,14 @@ function parseKnowledgeDocument(input) {
|
|
|
29
36
|
parts.push(input.text.slice(offset));
|
|
30
37
|
return { id: input.id, revision: input.revision, locale: input.locale, parts };
|
|
31
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Deep-copy and freeze a document while indexing its sections by id.
|
|
41
|
+
*
|
|
42
|
+
* @param document - Declared document, possibly sharing arrays or containing cycles.
|
|
43
|
+
* @returns The frozen document plus a map from section id to its frozen section.
|
|
44
|
+
* @throws TypeError For a missing identity or parts array, a sparse or cyclic tree, a blank
|
|
45
|
+
* section id, or a duplicate section id.
|
|
46
|
+
*/
|
|
32
47
|
function compileKnowledgeDocument(document) {
|
|
33
48
|
if (!document.id?.trim() || !document.revision?.trim() || !Array.isArray(document.parts))
|
|
34
49
|
throw new TypeError('Invalid knowledge document');
|
|
@@ -40,7 +55,7 @@ function compileKnowledgeDocument(document) {
|
|
|
40
55
|
ancestors.add(parts);
|
|
41
56
|
// Visit empty array slots too: a sparse tree is not valid knowledge, and
|
|
42
57
|
// must not share a serialized cache identity with an explicit null part.
|
|
43
|
-
const result = Array.from(parts, part => {
|
|
58
|
+
const result = Array.from(parts, (part) => {
|
|
44
59
|
if (typeof part === 'string')
|
|
45
60
|
return part;
|
|
46
61
|
if (!part || typeof part.id !== 'string' || !part.id.trim() || sections.has(part.id))
|
|
@@ -54,9 +69,23 @@ function compileKnowledgeDocument(document) {
|
|
|
54
69
|
ancestors.delete(parts);
|
|
55
70
|
return Object.freeze(result);
|
|
56
71
|
}
|
|
57
|
-
const value = Object.freeze({
|
|
72
|
+
const value = Object.freeze({
|
|
73
|
+
id: document.id,
|
|
74
|
+
revision: document.revision,
|
|
75
|
+
locale: document.locale,
|
|
76
|
+
parts: copy(document.parts),
|
|
77
|
+
});
|
|
58
78
|
return { document: value, sections };
|
|
59
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Flatten parts into text.
|
|
82
|
+
*
|
|
83
|
+
* @param parts - Document parts; nested sections are traversed in order.
|
|
84
|
+
* @param subtree - When false, nested section text is skipped and only top-level text remains.
|
|
85
|
+
* @returns Concatenated text with separators left to the caller.
|
|
86
|
+
*/
|
|
60
87
|
function knowledgeText(parts, subtree = true) {
|
|
61
|
-
return parts
|
|
88
|
+
return parts
|
|
89
|
+
.map((part) => (typeof part === 'string' ? part : subtree ? knowledgeText(part.parts) : ''))
|
|
90
|
+
.join('');
|
|
62
91
|
}
|
|
@@ -3,20 +3,53 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Normalization = void 0;
|
|
4
4
|
exports.defineNormalization = defineNormalization;
|
|
5
5
|
exports.uniqueBy = uniqueBy;
|
|
6
|
+
/**
|
|
7
|
+
* Normalization Kit: ordered synchronous value transformations and stable deduplication.
|
|
8
|
+
*
|
|
9
|
+
* Place in the package: an optional App-side helper for cleaning model or transport input
|
|
10
|
+
* before it reaches business logic. Replacement, completion detection and input ownership stay
|
|
11
|
+
* explicit; this module never mutates the caller's arrays.
|
|
12
|
+
*
|
|
13
|
+
* Exports: `defineNormalization`, `uniqueBy`, `Normalization`, and the step/option types.
|
|
14
|
+
*/
|
|
6
15
|
const synchronous_js_1 = require("../utils/synchronous.js");
|
|
7
16
|
const rules_js_1 = require("../utils/rules.js");
|
|
8
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Compile an ordered normalization pipeline.
|
|
19
|
+
*
|
|
20
|
+
* Steps run in declaration order. Each step may be skipped by its `when` predicate, receives
|
|
21
|
+
* the value produced by the previous step, and `isComplete` can stop the walk early, so the
|
|
22
|
+
* usual contract is "first completion wins" rather than "always run everything".
|
|
23
|
+
*
|
|
24
|
+
* @param definitions - Steps with unique non-blank ids and a synchronous `normalize` handler.
|
|
25
|
+
* @param options - Optional completion predicate; bound to the options object.
|
|
26
|
+
* @returns A frozen pipeline exposing `steps` (ids plus handlers) and `normalize`.
|
|
27
|
+
* @throws TypeError At construction for blank/duplicate ids or a missing handler; from
|
|
28
|
+
* `normalize` when a predicate or handler returns a thenable or a non-boolean.
|
|
29
|
+
*/
|
|
9
30
|
function defineNormalization(definitions, options = {}) {
|
|
10
31
|
const isComplete = options.isComplete?.bind(options);
|
|
11
32
|
const predicate = (value) => (0, synchronous_js_1.booleanResult)(value, 'Normalization predicates must be synchronous', 'Normalization predicates must return boolean');
|
|
12
33
|
const ids = new Set();
|
|
13
|
-
const steps = Object.freeze(definitions.map(step => {
|
|
34
|
+
const steps = Object.freeze(definitions.map((step) => {
|
|
14
35
|
(0, rules_js_1.breakWhile)([
|
|
15
|
-
{
|
|
16
|
-
|
|
36
|
+
{
|
|
37
|
+
occur: () => !step.id.trim() || ids.has(step.id),
|
|
38
|
+
error: 'Invalid or duplicate normalization step',
|
|
39
|
+
tags: ['id'],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
occur: () => typeof step.normalize !== 'function',
|
|
43
|
+
error: 'Missing normalization handler',
|
|
44
|
+
tags: ['handler'],
|
|
45
|
+
},
|
|
17
46
|
]);
|
|
18
47
|
ids.add(step.id);
|
|
19
|
-
return Object.freeze({
|
|
48
|
+
return Object.freeze({
|
|
49
|
+
id: step.id,
|
|
50
|
+
when: step.when?.bind(step),
|
|
51
|
+
normalize: step.normalize.bind(step),
|
|
52
|
+
});
|
|
20
53
|
}));
|
|
21
54
|
return Object.freeze({
|
|
22
55
|
steps,
|
|
@@ -32,10 +65,20 @@ function defineNormalization(definitions, options = {}) {
|
|
|
32
65
|
},
|
|
33
66
|
});
|
|
34
67
|
}
|
|
35
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Stable deduplication preserves the original values; the host chooses equivalence.
|
|
70
|
+
*
|
|
71
|
+
* The first occurrence of each key wins and the input order is kept, so callers can rely on
|
|
72
|
+
* deduplication never reordering their list.
|
|
73
|
+
*
|
|
74
|
+
* @param values - Values in the order to retain.
|
|
75
|
+
* @param key - Equivalence selector.
|
|
76
|
+
* @param initial - Keys already treated as seen, for example those owned by another batch.
|
|
77
|
+
* @returns The retained values as a new array.
|
|
78
|
+
*/
|
|
36
79
|
function uniqueBy(values, key, initial = []) {
|
|
37
80
|
const seen = new Set(initial);
|
|
38
|
-
return values.filter(value => {
|
|
81
|
+
return values.filter((value) => {
|
|
39
82
|
const id = key(value);
|
|
40
83
|
if (seen.has(id))
|
|
41
84
|
return false;
|
|
@@ -43,4 +86,5 @@ function uniqueBy(values, key, initial = []) {
|
|
|
43
86
|
return true;
|
|
44
87
|
});
|
|
45
88
|
}
|
|
89
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
46
90
|
exports.Normalization = Object.freeze({ defineNormalization, uniqueBy });
|
|
@@ -3,30 +3,72 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Policies = void 0;
|
|
4
4
|
exports.definePolicySet = definePolicySet;
|
|
5
5
|
exports.defineRecoveryChain = defineRecoveryChain;
|
|
6
|
+
/**
|
|
7
|
+
* Policies Kit: assess which declared policies apply, and run ordered recovery handlers.
|
|
8
|
+
*
|
|
9
|
+
* Place in the package: an optional App-side library for policy and recovery tables. Policy
|
|
10
|
+
* predicates, recovery handlers, kinds and descriptions are App configuration; this module
|
|
11
|
+
* owns registration checks, evaluation order and outcome validation.
|
|
12
|
+
*
|
|
13
|
+
* Exports: `definePolicySet`, `defineRecoveryChain`, `Policies`, and the policy types.
|
|
14
|
+
*/
|
|
6
15
|
const catalog_js_1 = require("../utils/catalog.js");
|
|
7
16
|
const synchronous_js_1 = require("../utils/synchronous.js");
|
|
8
17
|
const rules_js_1 = require("../utils/rules.js");
|
|
9
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Compile a policy set that reports every matching reason.
|
|
20
|
+
*
|
|
21
|
+
* Collect every matching reason; a configured mode cannot silently override a mandatory
|
|
22
|
+
* policy. `assess` returns the matched ids and deduplicated kinds rather than a single verdict,
|
|
23
|
+
* so callers keep the ordering information they need for messages and diagnostics.
|
|
24
|
+
*
|
|
25
|
+
* @param definitions - Policies with unique ids, descriptions and a synchronous `when`.
|
|
26
|
+
* @returns A frozen catalog extended with `assess(input)`.
|
|
27
|
+
* @throws TypeError For blank/duplicate ids, a blank description, a missing `when`, or a
|
|
28
|
+
* predicate that is not synchronous boolean.
|
|
29
|
+
*/
|
|
10
30
|
function definePolicySet(definitions) {
|
|
11
31
|
const catalog = registerPolicies(definitions, 'when');
|
|
12
32
|
return Object.freeze({
|
|
13
|
-
...(0, catalog_js_1.readonlyCatalog)(catalog, id => new TypeError(`Unknown policy: ${id}`)),
|
|
33
|
+
...(0, catalog_js_1.readonlyCatalog)(catalog, (id) => new TypeError(`Unknown policy: ${id}`)),
|
|
14
34
|
assess(input) {
|
|
15
|
-
const matched = catalog.filter(policy => booleanMatch(policy.when(input)));
|
|
16
|
-
return {
|
|
35
|
+
const matched = catalog.filter((policy) => booleanMatch(policy.when(input)));
|
|
36
|
+
return {
|
|
37
|
+
required: matched.length > 0,
|
|
38
|
+
reasons: matched.map((policy) => policy.id),
|
|
39
|
+
kinds: [...new Set(matched.map((policy) => policy.kind))],
|
|
40
|
+
};
|
|
17
41
|
},
|
|
18
42
|
});
|
|
19
43
|
}
|
|
20
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Compile an ordered recovery chain.
|
|
46
|
+
*
|
|
47
|
+
* A handler reports whether it handled the input; handled undefined values remain explicit.
|
|
48
|
+
* The first handler that reports `handled` ends the walk, so declaration order is the
|
|
49
|
+
* precedence, and `{ handled: false }` is the only way to fall through.
|
|
50
|
+
*
|
|
51
|
+
* @param definitions - Recovery handlers with unique ids, descriptions and `tryRecover`.
|
|
52
|
+
* @returns A frozen catalog extended with `tryRecover(input)`.
|
|
53
|
+
* @throws TypeError For blank/duplicate ids, a missing handler, or an outcome that lacks a
|
|
54
|
+
* boolean `handled` or omits `value` while claiming to have handled the input.
|
|
55
|
+
*/
|
|
21
56
|
function defineRecoveryChain(definitions) {
|
|
22
|
-
const catalog = registerPolicies(definitions, 'tryRecover').map(definition => {
|
|
23
|
-
return Object.freeze({
|
|
57
|
+
const catalog = registerPolicies(definitions, 'tryRecover').map((definition) => {
|
|
58
|
+
return Object.freeze({
|
|
59
|
+
id: definition.id,
|
|
60
|
+
description: definition.description,
|
|
61
|
+
tryRecover(input) {
|
|
24
62
|
const value = (0, synchronous_js_1.synchronous)(definition.tryRecover(input), 'Recovery handlers must be synchronous');
|
|
25
63
|
const result = value;
|
|
26
|
-
if (!result ||
|
|
64
|
+
if (!result ||
|
|
65
|
+
typeof result !== 'object' ||
|
|
66
|
+
typeof result.handled !== 'boolean' ||
|
|
67
|
+
(result.handled && !('value' in result)))
|
|
27
68
|
throw new TypeError('Invalid recovery outcome');
|
|
28
69
|
return result;
|
|
29
|
-
}
|
|
70
|
+
},
|
|
71
|
+
});
|
|
30
72
|
});
|
|
31
73
|
const tryRecover = (input) => {
|
|
32
74
|
for (const policy of catalog) {
|
|
@@ -36,20 +78,42 @@ function defineRecoveryChain(definitions) {
|
|
|
36
78
|
}
|
|
37
79
|
return { handled: false };
|
|
38
80
|
};
|
|
39
|
-
return Object.freeze({
|
|
81
|
+
return Object.freeze({
|
|
82
|
+
...(0, catalog_js_1.readonlyCatalog)(catalog, (id) => new TypeError(`Unknown recovery policy: ${id}`)),
|
|
83
|
+
tryRecover,
|
|
84
|
+
});
|
|
40
85
|
}
|
|
41
86
|
function registerPolicies(definitions, handler) {
|
|
42
87
|
const ids = new Set();
|
|
43
|
-
return Object.freeze(definitions.map(definition => {
|
|
88
|
+
return Object.freeze(definitions.map((definition) => {
|
|
44
89
|
(0, rules_js_1.breakWhile)([
|
|
45
|
-
{
|
|
46
|
-
|
|
47
|
-
|
|
90
|
+
{
|
|
91
|
+
occur: () => !definition.id.trim() || !definition.description.trim(),
|
|
92
|
+
error: 'Invalid policy declaration',
|
|
93
|
+
tags: ['metadata'],
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
occur: () => ids.has(definition.id),
|
|
97
|
+
error: () => `Duplicate policy: ${definition.id}`,
|
|
98
|
+
tags: ['id'],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
occur: () => typeof definition[handler] !== 'function',
|
|
102
|
+
error: () => `Missing policy handler: ${definition.id}`,
|
|
103
|
+
tags: ['handler'],
|
|
104
|
+
},
|
|
48
105
|
], ['agent-core', 'policy-registration']);
|
|
49
106
|
ids.add(definition.id);
|
|
50
|
-
return Object.freeze({
|
|
107
|
+
return Object.freeze({
|
|
108
|
+
...definition,
|
|
109
|
+
id: definition.id,
|
|
110
|
+
description: definition.description,
|
|
111
|
+
...('kind' in definition ? { kind: definition.kind } : {}),
|
|
112
|
+
[handler]: definition[handler].bind(definition),
|
|
113
|
+
});
|
|
51
114
|
}));
|
|
52
115
|
}
|
|
116
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
53
117
|
exports.Policies = Object.freeze({ definePolicySet, defineRecoveryChain });
|
|
54
118
|
function booleanMatch(value) {
|
|
55
119
|
return (0, synchronous_js_1.booleanResult)(value, 'Policy predicates must be synchronous', 'Policy predicates must return boolean');
|