@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
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { TextSearchOptions, TextSearchQuery, TextSearchHit, TextSearchSnapshot } from '../structs/kits/search.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Optional App-side full-text index. No storage, identity, model calls or Core dependencies.
|
|
4
|
+
*
|
|
5
|
+
* Only declared fields are indexed and only `storedFields` come back with a hit, so a document
|
|
6
|
+
* never leaks extra properties into search results.
|
|
7
|
+
*/
|
|
3
8
|
export declare class TextSearch<Document extends {
|
|
4
9
|
id: string;
|
|
5
10
|
}> {
|
|
@@ -8,18 +13,66 @@ export declare class TextSearch<Document extends {
|
|
|
8
13
|
private readonly inputFields;
|
|
9
14
|
private readonly configurationFingerprint;
|
|
10
15
|
private index;
|
|
16
|
+
/**
|
|
17
|
+
* Compile the index configuration and validate it before any document is added.
|
|
18
|
+
*
|
|
19
|
+
* @param registration - Format revision, indexed and stored fields, optional tokenizer,
|
|
20
|
+
* boosts and combination mode; handlers are bound to this object.
|
|
21
|
+
* @throws TypeError For a missing revision, empty/duplicate/blank field declarations, stored
|
|
22
|
+
* fields that collide with search metadata, an invalid tokenizer or combination, or a
|
|
23
|
+
* boost for an undeclared field or with a non-positive value.
|
|
24
|
+
*/
|
|
11
25
|
constructor(registration: TextSearchOptions<Document>);
|
|
26
|
+
/**
|
|
27
|
+
* Insert or replace one document.
|
|
28
|
+
*
|
|
29
|
+
* @param document - Document carrying a non-blank string `id`; only declared fields are kept.
|
|
30
|
+
* @throws TypeError For a missing document, a blank/non-string id, or a non-string value in
|
|
31
|
+
* an indexed field.
|
|
32
|
+
*/
|
|
12
33
|
upsert(document: Document): void;
|
|
34
|
+
/**
|
|
35
|
+
* Search the index and return at most `limit` hits.
|
|
36
|
+
*
|
|
37
|
+
* @param options - Non-empty query text, limit (1..1000) and a synchronous filter that decides
|
|
38
|
+
* which stored documents may be returned.
|
|
39
|
+
* @returns Hits ordered by MiniSearch relevance, carrying the stored fields only.
|
|
40
|
+
* @throws TypeError For a blank query, an out-of-range limit, a missing filter, a filter
|
|
41
|
+
* result that is not synchronous boolean.
|
|
42
|
+
*/
|
|
13
43
|
search(options: TextSearchQuery<Document> & {
|
|
14
44
|
query: string;
|
|
15
45
|
}): TextSearchHit<Document>[];
|
|
16
46
|
private fields;
|
|
17
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Remove one document.
|
|
49
|
+
*
|
|
50
|
+
* Vacuum before returning so deleted terms do not survive the next serialized checkpoint.
|
|
51
|
+
*
|
|
52
|
+
* @param id - Document id; a non-blank string is required.
|
|
53
|
+
* @returns Whether a document was actually discarded.
|
|
54
|
+
* @throws TypeError For a blank or non-string id.
|
|
55
|
+
*/
|
|
18
56
|
remove(id: string): Promise<boolean>;
|
|
57
|
+
/** Drop every document while keeping the compiled configuration. */
|
|
19
58
|
clear(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Serialize the index together with the configuration used to build it.
|
|
61
|
+
*
|
|
62
|
+
* @returns A versioned snapshot; the fingerprint lets `restore` reject a mismatched setup.
|
|
63
|
+
*/
|
|
20
64
|
snapshot(): TextSearchSnapshot;
|
|
65
|
+
/**
|
|
66
|
+
* Rebuild an index from a snapshot.
|
|
67
|
+
*
|
|
68
|
+
* @param definition - The same configuration the snapshot was produced with.
|
|
69
|
+
* @param snapshot - Snapshot returned by `snapshot`.
|
|
70
|
+
* @returns A new populated `TextSearch`.
|
|
71
|
+
* @throws An error when the layout version, engine tag, configuration fingerprint or payload
|
|
72
|
+
* type does not match, because restoring an incompatible index would silently misanswer.
|
|
73
|
+
*/
|
|
21
74
|
static restore<Document extends {
|
|
22
75
|
id: string;
|
|
23
76
|
}>(definition: TextSearchOptions<Document>, snapshot: TextSearchSnapshot): TextSearch<Document>;
|
|
24
77
|
}
|
|
25
|
-
export type { TextSearchOptions, TextSearchQuery, TextSearchHit, TextSearchSnapshot } from '../structs/kits/search.js';
|
|
78
|
+
export type { TextSearchOptions, TextSearchQuery, TextSearchHit, TextSearchSnapshot, } from '../structs/kits/search.js';
|
package/dist/esm/kits/search.js
CHANGED
|
@@ -1,61 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text Search Kit: an in-memory MiniSearch index with explicit field declarations.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: an optional App-side full-text index. The Kit owns the index,
|
|
5
|
+
* declarative validation and snapshot compatibility; corpus, tokenization policy, storage,
|
|
6
|
+
* identity, filters and persistence stay with the App. No model call or Core dependency is
|
|
7
|
+
* involved, and nothing is written to disk here.
|
|
8
|
+
*
|
|
9
|
+
* Exports: `TextSearch` and the search option/query/hit/snapshot types.
|
|
10
|
+
*/
|
|
1
11
|
import { booleanResult } from '../utils/synchronous.js';
|
|
2
12
|
import MiniSearch from 'minisearch';
|
|
3
13
|
import { breakWhile } from '../utils/rules.js';
|
|
4
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Optional App-side full-text index. No storage, identity, model calls or Core dependencies.
|
|
16
|
+
*
|
|
17
|
+
* Only declared fields are indexed and only `storedFields` come back with a hit, so a document
|
|
18
|
+
* never leaks extra properties into search results.
|
|
19
|
+
*/
|
|
5
20
|
export class TextSearch {
|
|
6
21
|
options;
|
|
7
22
|
stored;
|
|
8
23
|
inputFields;
|
|
9
24
|
configurationFingerprint;
|
|
10
25
|
index;
|
|
26
|
+
/**
|
|
27
|
+
* Compile the index configuration and validate it before any document is added.
|
|
28
|
+
*
|
|
29
|
+
* @param registration - Format revision, indexed and stored fields, optional tokenizer,
|
|
30
|
+
* boosts and combination mode; handlers are bound to this object.
|
|
31
|
+
* @throws TypeError For a missing revision, empty/duplicate/blank field declarations, stored
|
|
32
|
+
* fields that collide with search metadata, an invalid tokenizer or combination, or a
|
|
33
|
+
* boost for an undeclared field or with a non-positive value.
|
|
34
|
+
*/
|
|
11
35
|
constructor(registration) {
|
|
12
|
-
const definition = {
|
|
13
|
-
|
|
36
|
+
const definition = {
|
|
37
|
+
indexRevision: registration.indexRevision,
|
|
38
|
+
fields: registration.fields,
|
|
39
|
+
storedFields: registration.storedFields,
|
|
40
|
+
tokenize: registration.tokenize,
|
|
41
|
+
boost: registration.boost,
|
|
42
|
+
combineWith: registration.combineWith,
|
|
43
|
+
};
|
|
14
44
|
const reserved = new Set(['id', 'score', 'terms', 'queryTerms', 'match']);
|
|
15
45
|
breakWhile([
|
|
16
|
-
{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
|
|
46
|
+
{
|
|
47
|
+
occur: () => !definition ||
|
|
48
|
+
typeof definition.indexRevision !== 'string' ||
|
|
49
|
+
!definition.indexRevision.trim(),
|
|
50
|
+
error: 'Text search requires an application format revision',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
occur: () => !Array.isArray(definition.fields) ||
|
|
54
|
+
!definition.fields.length ||
|
|
55
|
+
!Array.isArray(definition.storedFields),
|
|
56
|
+
error: 'Text search requires field declarations',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
occur: () => [...definition.fields, ...definition.storedFields].some((f) => typeof f !== 'string' || !f.trim()),
|
|
60
|
+
error: 'Invalid text search field',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
occur: () => new Set(definition.fields).size !== definition.fields.length ||
|
|
64
|
+
new Set(definition.storedFields).size !== definition.storedFields.length,
|
|
65
|
+
error: 'Duplicate text search field',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
occur: () => definition.storedFields.some((f) => reserved.has(f)),
|
|
69
|
+
error: 'Stored fields conflict with search metadata',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
occur: () => definition.tokenize !== undefined && typeof definition.tokenize !== 'function',
|
|
73
|
+
error: 'Invalid text search tokenizer',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
occur: () => definition.combineWith !== undefined && !['AND', 'OR'].includes(definition.combineWith),
|
|
77
|
+
error: 'Invalid text search combination',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
occur: () => Object.entries(definition.boost ?? {}).some(([field, value]) => !definition.fields.includes(field) ||
|
|
81
|
+
typeof value !== 'number' ||
|
|
82
|
+
!Number.isFinite(value) ||
|
|
83
|
+
value <= 0),
|
|
84
|
+
error: 'Invalid text search field boost',
|
|
85
|
+
},
|
|
24
86
|
], ['kit', 'text-search', 'registration']);
|
|
25
87
|
this.stored = Object.freeze([...definition.storedFields]);
|
|
26
88
|
this.inputFields = Object.freeze([...new Set([...definition.fields, ...this.stored])]);
|
|
27
89
|
// Object entries have distinct keys, so there is no equal-key ordering case.
|
|
28
|
-
const boost = Object.fromEntries(Object.entries(definition.boost ?? {}).sort(([a], [b]) => a < b ? -1 : 1));
|
|
29
|
-
this.options = {
|
|
30
|
-
|
|
31
|
-
|
|
90
|
+
const boost = Object.fromEntries(Object.entries(definition.boost ?? {}).sort(([a], [b]) => (a < b ? -1 : 1)));
|
|
91
|
+
this.options = {
|
|
92
|
+
fields: [...definition.fields],
|
|
93
|
+
storeFields: [...definition.storedFields],
|
|
94
|
+
...(definition.tokenize ? { tokenize: definition.tokenize.bind(registration) } : {}),
|
|
95
|
+
searchOptions: { boost, combineWith: definition.combineWith ?? 'OR' },
|
|
96
|
+
};
|
|
97
|
+
this.configurationFingerprint = JSON.stringify({
|
|
98
|
+
indexRevision: definition.indexRevision,
|
|
99
|
+
fields: this.options.fields,
|
|
100
|
+
storedFields: this.options.storeFields,
|
|
101
|
+
boost: this.options.searchOptions.boost,
|
|
102
|
+
combineWith: this.options.searchOptions.combineWith,
|
|
103
|
+
});
|
|
32
104
|
this.index = new MiniSearch(this.options);
|
|
33
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Insert or replace one document.
|
|
108
|
+
*
|
|
109
|
+
* @param document - Document carrying a non-blank string `id`; only declared fields are kept.
|
|
110
|
+
* @throws TypeError For a missing document, a blank/non-string id, or a non-string value in
|
|
111
|
+
* an indexed field.
|
|
112
|
+
*/
|
|
34
113
|
upsert(document) {
|
|
35
114
|
breakWhile(!document, 'Invalid text search document');
|
|
36
115
|
// Only declared fields belong to this index. Read inherited getters before
|
|
37
116
|
// cloning and do not retain caller-owned nested metadata or extra services.
|
|
38
|
-
const snapshot = structuredClone({
|
|
39
|
-
|
|
117
|
+
const snapshot = structuredClone({
|
|
118
|
+
...Object.fromEntries(this.inputFields.map((field) => [field, document[field]])),
|
|
119
|
+
id: document.id,
|
|
120
|
+
});
|
|
121
|
+
breakWhile(typeof snapshot.id !== 'string' ||
|
|
122
|
+
!snapshot.id.trim() ||
|
|
123
|
+
this.options.fields.some((field) => snapshot[field] !== undefined && typeof snapshot[field] !== 'string'), 'Invalid text search document');
|
|
40
124
|
if (this.index.has(snapshot.id))
|
|
41
125
|
this.index.replace(snapshot);
|
|
42
126
|
else
|
|
43
127
|
this.index.add(snapshot);
|
|
44
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Search the index and return at most `limit` hits.
|
|
131
|
+
*
|
|
132
|
+
* @param options - Non-empty query text, limit (1..1000) and a synchronous filter that decides
|
|
133
|
+
* which stored documents may be returned.
|
|
134
|
+
* @returns Hits ordered by MiniSearch relevance, carrying the stored fields only.
|
|
135
|
+
* @throws TypeError For a blank query, an out-of-range limit, a missing filter, a filter
|
|
136
|
+
* result that is not synchronous boolean.
|
|
137
|
+
*/
|
|
45
138
|
search(options) {
|
|
46
139
|
const { query } = options;
|
|
47
140
|
breakWhile([
|
|
48
|
-
{
|
|
49
|
-
|
|
50
|
-
|
|
141
|
+
{
|
|
142
|
+
occur: () => typeof query !== 'string' || !query.trim(),
|
|
143
|
+
error: 'Text search requires a nonempty query',
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
occur: () => !options ||
|
|
147
|
+
!Number.isSafeInteger(options.limit) ||
|
|
148
|
+
options.limit < 1 ||
|
|
149
|
+
options.limit > 1000,
|
|
150
|
+
error: 'Text search limit must be between 1 and 1000',
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
occur: () => typeof options.filter !== 'function',
|
|
154
|
+
error: 'Text search requires an application filter',
|
|
155
|
+
},
|
|
51
156
|
], ['kit', 'text-search', 'query']);
|
|
52
|
-
return this.index
|
|
53
|
-
.
|
|
157
|
+
return this.index
|
|
158
|
+
.search(query, {
|
|
159
|
+
filter: (hit) => booleanResult(options.filter({ ...this.fields(hit), id: String(hit.id) }), 'Text search filters must be synchronous', 'Text search filters must return boolean'),
|
|
160
|
+
})
|
|
161
|
+
.slice(0, options.limit)
|
|
162
|
+
.map((hit) => ({
|
|
163
|
+
id: String(hit.id),
|
|
164
|
+
score: hit.score,
|
|
165
|
+
terms: [...hit.terms],
|
|
166
|
+
document: this.fields(hit),
|
|
167
|
+
}));
|
|
54
168
|
}
|
|
55
169
|
fields(hit) {
|
|
56
|
-
return structuredClone(Object.fromEntries(this.stored
|
|
170
|
+
return structuredClone(Object.fromEntries(this.stored
|
|
171
|
+
.filter((field) => Object.hasOwn(hit, field))
|
|
172
|
+
.map((field) => [field, hit[field]])));
|
|
57
173
|
}
|
|
58
|
-
/**
|
|
174
|
+
/**
|
|
175
|
+
* Remove one document.
|
|
176
|
+
*
|
|
177
|
+
* Vacuum before returning so deleted terms do not survive the next serialized checkpoint.
|
|
178
|
+
*
|
|
179
|
+
* @param id - Document id; a non-blank string is required.
|
|
180
|
+
* @returns Whether a document was actually discarded.
|
|
181
|
+
* @throws TypeError For a blank or non-string id.
|
|
182
|
+
*/
|
|
59
183
|
async remove(id) {
|
|
60
184
|
breakWhile(typeof id !== 'string' || !id.trim(), 'Invalid text search document id');
|
|
61
185
|
if (!this.index.has(id))
|
|
@@ -64,11 +188,40 @@ export class TextSearch {
|
|
|
64
188
|
await this.index.vacuum();
|
|
65
189
|
return true;
|
|
66
190
|
}
|
|
67
|
-
|
|
68
|
-
|
|
191
|
+
/** Drop every document while keeping the compiled configuration. */
|
|
192
|
+
clear() {
|
|
193
|
+
this.index.removeAll();
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Serialize the index together with the configuration used to build it.
|
|
197
|
+
*
|
|
198
|
+
* @returns A versioned snapshot; the fingerprint lets `restore` reject a mismatched setup.
|
|
199
|
+
*/
|
|
200
|
+
snapshot() {
|
|
201
|
+
return {
|
|
202
|
+
// The layout version and engine tag pin the serialized format to MiniSearch 7 semantics.
|
|
203
|
+
version: 2,
|
|
204
|
+
engine: 'minisearch-7',
|
|
205
|
+
configurationFingerprint: this.configurationFingerprint,
|
|
206
|
+
serializedIndex: JSON.stringify(this.index),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Rebuild an index from a snapshot.
|
|
211
|
+
*
|
|
212
|
+
* @param definition - The same configuration the snapshot was produced with.
|
|
213
|
+
* @param snapshot - Snapshot returned by `snapshot`.
|
|
214
|
+
* @returns A new populated `TextSearch`.
|
|
215
|
+
* @throws An error when the layout version, engine tag, configuration fingerprint or payload
|
|
216
|
+
* type does not match, because restoring an incompatible index would silently misanswer.
|
|
217
|
+
*/
|
|
69
218
|
static restore(definition, snapshot) {
|
|
70
219
|
const search = new TextSearch(definition);
|
|
71
|
-
breakWhile(!snapshot ||
|
|
220
|
+
breakWhile(!snapshot ||
|
|
221
|
+
snapshot.version !== 2 ||
|
|
222
|
+
snapshot.engine !== 'minisearch-7' ||
|
|
223
|
+
snapshot.configurationFingerprint !== search.configurationFingerprint ||
|
|
224
|
+
typeof snapshot.serializedIndex !== 'string', 'Incompatible text search snapshot; rebuild from application records');
|
|
72
225
|
search.index = MiniSearch.loadJSON(snapshot.serializedIndex, search.options);
|
|
73
226
|
return search;
|
|
74
227
|
}
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import type { TextSkillLoaderDefinition } from '../structs/kits/text-skills.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Compile a loader that validates registrations and reads their documents.
|
|
4
|
+
*
|
|
5
|
+
* The default contract is narrow by design: ids are lower-case words joined by hyphens (up to
|
|
6
|
+
* `maxIdChars`, default 64), each entry lives at `<id>/SKILL.md`, the kind is `text-workflow`,
|
|
7
|
+
* and the document starts with `name`/`description` front matter.
|
|
8
|
+
*
|
|
9
|
+
* @param definition - Size limits, optional per-app entry/header overrides and error wording;
|
|
10
|
+
* handlers are bound to this object.
|
|
11
|
+
* @returns A frozen loader with `load({ entries }, ports)`.
|
|
12
|
+
* @throws TypeError At construction for non-integer or non-positive limits; from `load` for a
|
|
13
|
+
* malformed catalog, duplicate/invalid ids, a mismatched entry path or kind, duplicate tool
|
|
14
|
+
* ids, an oversized instruction body, or a header that is absent or disagrees with the id.
|
|
15
|
+
*/
|
|
3
16
|
export declare function defineTextSkillLoader(definition: TextSkillLoaderDefinition): import('../structs/kits/text-skills.js').TextSkillLoader;
|
|
4
|
-
export type { TextSkill, TextSkillRegistration, TextSkillHeader, TextSkillLoaderDefinition, TextSkillLoader, TextSkillReadPorts } from '../structs/kits/text-skills.js';
|
|
17
|
+
export type { TextSkill, TextSkillRegistration, TextSkillHeader, TextSkillLoaderDefinition, TextSkillLoader, TextSkillReadPorts, } from '../structs/kits/text-skills.js';
|
|
18
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
5
19
|
export declare const TextSkills: Readonly<{
|
|
6
20
|
defineTextSkillLoader: typeof defineTextSkillLoader;
|
|
7
21
|
}>;
|
|
@@ -1,18 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text Skills Kit: compile declarative, text-only skill registrations into readable skills.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: an optional App-side library for skill documents that are pure text.
|
|
5
|
+
* Documents are read through an App port; nothing here executes code, imports modules, binds
|
|
6
|
+
* tools or grants authority. Tool ids are only carried as declared references.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `defineTextSkillLoader`, `TextSkills`, and the skill document/port types.
|
|
9
|
+
*/
|
|
1
10
|
import { synchronous } from '../utils/synchronous.js';
|
|
2
11
|
import { breakWhile } from '../utils/rules.js';
|
|
3
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Compile a loader that validates registrations and reads their documents.
|
|
14
|
+
*
|
|
15
|
+
* The default contract is narrow by design: ids are lower-case words joined by hyphens (up to
|
|
16
|
+
* `maxIdChars`, default 64), each entry lives at `<id>/SKILL.md`, the kind is `text-workflow`,
|
|
17
|
+
* and the document starts with `name`/`description` front matter.
|
|
18
|
+
*
|
|
19
|
+
* @param definition - Size limits, optional per-app entry/header overrides and error wording;
|
|
20
|
+
* handlers are bound to this object.
|
|
21
|
+
* @returns A frozen loader with `load({ entries }, ports)`.
|
|
22
|
+
* @throws TypeError At construction for non-integer or non-positive limits; from `load` for a
|
|
23
|
+
* malformed catalog, duplicate/invalid ids, a mismatched entry path or kind, duplicate tool
|
|
24
|
+
* ids, an oversized instruction body, or a header that is absent or disagrees with the id.
|
|
25
|
+
*/
|
|
4
26
|
export function defineTextSkillLoader(definition) {
|
|
5
27
|
const { maxInstructionChars, maxDescriptionChars, maxIdChars = 64 } = definition;
|
|
6
28
|
breakWhile([
|
|
7
|
-
{
|
|
8
|
-
|
|
29
|
+
{
|
|
30
|
+
occur: () => ![maxInstructionChars, maxDescriptionChars, maxIdChars].every(Number.isSafeInteger),
|
|
31
|
+
error: 'Invalid text skill limits',
|
|
32
|
+
tags: ['integer'],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
occur: () => Math.min(maxInstructionChars, maxDescriptionChars, maxIdChars) < 1,
|
|
36
|
+
error: 'Invalid text skill limits',
|
|
37
|
+
tags: ['range'],
|
|
38
|
+
},
|
|
9
39
|
]);
|
|
10
40
|
const idPattern = new RegExp(`^[a-z][a-z0-9-]{0,${maxIdChars - 1}}$`);
|
|
11
|
-
const entryFor = definition.entryFor?.bind(definition) ?? (id => `${id}/SKILL.md`);
|
|
41
|
+
const entryFor = definition.entryFor?.bind(definition) ?? ((id) => `${id}/SKILL.md`);
|
|
12
42
|
const parseHeader = definition.parseHeader?.bind(definition) ?? strictHeader;
|
|
13
|
-
const catalogError = (typeof definition.errors?.catalog === 'function'
|
|
14
|
-
|
|
15
|
-
|
|
43
|
+
const catalogError = (typeof definition.errors?.catalog === 'function'
|
|
44
|
+
? definition.errors.catalog.bind(definition.errors)
|
|
45
|
+
: definition.errors?.catalog) ?? 'Text skill catalog must be an array';
|
|
46
|
+
const registrationError = (typeof definition.errors?.registration === 'function'
|
|
47
|
+
? definition.errors.registration.bind(definition.errors)
|
|
48
|
+
: definition.errors?.registration) ?? 'Invalid text skill registration';
|
|
49
|
+
const documentError = (typeof definition.errors?.document === 'function'
|
|
50
|
+
? definition.errors.document.bind(definition.errors)
|
|
51
|
+
: definition.errors?.document) ?? 'Invalid text skill document';
|
|
16
52
|
const tags = [...(definition.tags ?? [])];
|
|
17
53
|
return Object.freeze({
|
|
18
54
|
load(input, ports) {
|
|
@@ -20,16 +56,49 @@ export function defineTextSkillLoader(definition) {
|
|
|
20
56
|
const entries = input.entries, read = ports.read.bind(ports);
|
|
21
57
|
breakWhile(!Array.isArray(entries), catalogError);
|
|
22
58
|
const ids = new Set();
|
|
23
|
-
return Object.freeze(entries.map(raw => {
|
|
24
|
-
breakWhile(!raw || typeof raw !== 'object' || Array.isArray(raw), registrationError, [
|
|
25
|
-
|
|
59
|
+
return Object.freeze(entries.map((raw) => {
|
|
60
|
+
breakWhile(!raw || typeof raw !== 'object' || Array.isArray(raw), registrationError, [
|
|
61
|
+
...tags,
|
|
62
|
+
'registration',
|
|
63
|
+
'shape',
|
|
64
|
+
]);
|
|
65
|
+
const entry = {
|
|
66
|
+
id: raw.id,
|
|
67
|
+
entry: raw.entry,
|
|
68
|
+
kind: raw.kind,
|
|
69
|
+
toolIds: raw.toolIds,
|
|
70
|
+
};
|
|
26
71
|
breakWhile([
|
|
27
|
-
{ occur: () => !entry || typeof entry !== 'object', error: registrationError, tags: ['shape'] },
|
|
28
|
-
{ occur: [() => typeof entry.id !== 'string' || !idPattern.test(entry.id), () => ids.has(entry.id)], error: registrationError, tags: ['id'] },
|
|
29
|
-
{ occur: [() => entry.entry !== synchronous(entryFor(entry.id), 'Skill entry selectors must be synchronous'), () => entry.kind !== 'text-workflow'], error: registrationError, tags: ['workflow'] },
|
|
30
72
|
{
|
|
31
|
-
occur:
|
|
32
|
-
error: registrationError,
|
|
73
|
+
occur: () => !entry || typeof entry !== 'object',
|
|
74
|
+
error: registrationError,
|
|
75
|
+
tags: ['shape'],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
occur: [
|
|
79
|
+
() => typeof entry.id !== 'string' || !idPattern.test(entry.id),
|
|
80
|
+
() => ids.has(entry.id),
|
|
81
|
+
],
|
|
82
|
+
error: registrationError,
|
|
83
|
+
tags: ['id'],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
occur: [
|
|
87
|
+
() => entry.entry !==
|
|
88
|
+
synchronous(entryFor(entry.id), 'Skill entry selectors must be synchronous'),
|
|
89
|
+
() => entry.kind !== 'text-workflow',
|
|
90
|
+
],
|
|
91
|
+
error: registrationError,
|
|
92
|
+
tags: ['workflow'],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
occur: [
|
|
96
|
+
() => !Array.isArray(entry.toolIds),
|
|
97
|
+
() => entry.toolIds.some((tool) => typeof tool !== 'string' || !tool),
|
|
98
|
+
() => new Set(entry.toolIds).size !== entry.toolIds.length,
|
|
99
|
+
],
|
|
100
|
+
error: registrationError,
|
|
101
|
+
tags: ['tools'],
|
|
33
102
|
},
|
|
34
103
|
], [...tags, 'registration']);
|
|
35
104
|
ids.add(entry.id);
|
|
@@ -37,17 +106,33 @@ export function defineTextSkillLoader(definition) {
|
|
|
37
106
|
breakWhile(typeof instructions !== 'string' || instructions.length > maxInstructionChars, documentError, [...tags, 'document', 'instructions']);
|
|
38
107
|
const header = synchronous(parseHeader(instructions), 'Skill header parsing must be synchronous');
|
|
39
108
|
breakWhile([
|
|
40
|
-
{
|
|
41
|
-
|
|
109
|
+
{
|
|
110
|
+
occur: [() => !header, () => header.id !== entry.id],
|
|
111
|
+
error: documentError,
|
|
112
|
+
tags: ['identity'],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
occur: () => !header.description.trim() || header.description.length > maxDescriptionChars,
|
|
116
|
+
error: documentError,
|
|
117
|
+
tags: ['description'],
|
|
118
|
+
},
|
|
42
119
|
], [...tags, 'document']);
|
|
43
|
-
return Object.freeze({
|
|
44
|
-
|
|
120
|
+
return Object.freeze({
|
|
121
|
+
id: entry.id,
|
|
122
|
+
entry: entry.entry,
|
|
123
|
+
kind: entry.kind,
|
|
124
|
+
toolIds: Object.freeze([...entry.toolIds]),
|
|
125
|
+
description: header.description.trim(),
|
|
126
|
+
instructions,
|
|
127
|
+
});
|
|
45
128
|
}));
|
|
46
129
|
},
|
|
47
130
|
});
|
|
48
131
|
}
|
|
132
|
+
/** Default header parser: exactly the two front-matter keys, nothing else, in this order. */
|
|
49
133
|
function strictHeader(instructions) {
|
|
50
134
|
const header = instructions.match(/^---\r?\nname: ([a-z][a-z0-9-]*)\r?\ndescription: ([^\r\n]+)\r?\n---(?:\r?\n|$)/);
|
|
51
135
|
return header ? { id: header[1], description: header[2] } : undefined;
|
|
52
136
|
}
|
|
137
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
53
138
|
export const TextSkills = Object.freeze({ defineTextSkillLoader });
|