@jangts/agent-core 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/LICENSE +55 -0
- package/NOTICE +6 -0
- package/README.md +8 -0
- package/development/docs/README.en.md +70 -0
- package/development/docs/README.md +1 -1
- package/development/docs/acceptance.en.md +34 -0
- package/development/docs/agent-development.en.md +42 -0
- package/development/docs/api/README.en.md +62 -0
- package/development/docs/api/advanced-agents.en.md +135 -0
- package/development/docs/api/context-processing.en.md +110 -0
- package/development/docs/api/core.en.md +274 -0
- package/development/docs/api/examples.en.md +118 -0
- package/development/docs/api/kits.en.md +183 -0
- package/development/docs/api/knowledge-answering.en.md +166 -0
- package/development/docs/api/mock.en.md +186 -0
- package/development/docs/api/observability.en.md +166 -0
- package/development/docs/api/reference.en.md +2235 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.en.md +252 -0
- package/development/docs/api/support.md +27 -0
- package/development/docs/api/types.en.md +181 -0
- package/development/docs/api/workflow.en.md +188 -0
- package/development/docs/basic-usage.en.md +78 -0
- package/development/docs/create-app.en.md +76 -0
- package/development/docs/examples/offline-agent.en.md +273 -0
- package/development/docs/examples.en.md +36 -0
- package/development/docs/flows/knowledge-maintenance.en.md +38 -0
- package/development/docs/getting-started.en.md +71 -0
- package/development/docs/knowledge.en.md +89 -0
- package/development/docs/maintenance.en.md +62 -0
- package/development/docs/materials.en.md +38 -0
- package/development/docs/mechanisms.en.md +227 -0
- package/development/docs/memory-and-learning.en.md +42 -0
- package/development/docs/operations.en.md +51 -0
- package/development/docs/records.en.md +63 -0
- package/development/docs/registration.en.md +63 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +286 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +77 -16
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +46 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +62 -17
- package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
- package/development/skills/agent-core-app/templates/catalog.json +36 -22
- package/dist/cjs/capabilities/index.js +13 -0
- package/dist/cjs/capabilities/invocation.js +80 -10
- package/dist/cjs/capabilities/model.js +126 -13
- package/dist/cjs/capabilities/tool-runtime.js +64 -12
- package/dist/cjs/capabilities/tools.js +266 -31
- package/dist/cjs/context/assembly.js +46 -5
- package/dist/cjs/context/audit.js +31 -6
- package/dist/cjs/context/fragments.js +54 -11
- package/dist/cjs/context/index.js +12 -0
- package/dist/cjs/context/journal.js +84 -7
- package/dist/cjs/context/plan.js +30 -2
- package/dist/cjs/diagnostics/catalog.js +17 -3
- package/dist/cjs/diagnostics/index.js +149 -29
- package/dist/cjs/diagnostics/sub-flow.js +240 -40
- package/dist/cjs/errors.js +99 -17
- package/dist/cjs/execution/branch.js +20 -4
- package/dist/cjs/execution/engine.js +470 -56
- package/dist/cjs/execution/events.js +136 -18
- package/dist/cjs/execution/index.js +7 -0
- package/dist/cjs/execution/reporting.js +75 -6
- package/dist/cjs/execution/state.js +161 -22
- package/dist/cjs/execution/workflow.js +224 -32
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/kits/aggregation.js +45 -3
- package/dist/cjs/kits/answering/batch.js +23 -4
- package/dist/cjs/kits/answering/check-result.js +31 -8
- package/dist/cjs/kits/answering/checks.js +24 -3
- package/dist/cjs/kits/answering/flow.js +192 -36
- package/dist/cjs/kits/answering/index.js +19 -1
- package/dist/cjs/kits/answering/tasks.js +88 -13
- package/dist/cjs/kits/artifacts.js +36 -4
- package/dist/cjs/kits/candidates.js +47 -5
- package/dist/cjs/kits/delivery.js +40 -5
- package/dist/cjs/kits/durable.js +155 -31
- package/dist/cjs/kits/evidence.js +66 -15
- package/dist/cjs/kits/family.js +152 -22
- package/dist/cjs/kits/index.js +12 -1
- package/dist/cjs/kits/inference.js +104 -16
- package/dist/cjs/kits/intents/catalog.js +67 -16
- package/dist/cjs/kits/intents/index.js +11 -0
- package/dist/cjs/kits/intents/registry.js +188 -43
- package/dist/cjs/kits/intents/scopes.js +215 -46
- package/dist/cjs/kits/interaction/command.js +140 -36
- package/dist/cjs/kits/interaction/commands.js +86 -11
- package/dist/cjs/kits/interaction/handlers.js +27 -10
- package/dist/cjs/kits/interaction/index.js +10 -0
- package/dist/cjs/kits/interaction/transfer.js +80 -14
- package/dist/cjs/kits/knowledge/catalog.js +62 -11
- package/dist/cjs/kits/knowledge/index.js +16 -1
- package/dist/cjs/kits/knowledge/publication.js +99 -23
- package/dist/cjs/kits/knowledge/sections.js +33 -4
- package/dist/cjs/kits/normalization.js +51 -7
- package/dist/cjs/kits/policies.js +79 -15
- package/dist/cjs/kits/presentation/events.js +54 -10
- package/dist/cjs/kits/presentation/index.js +24 -1
- package/dist/cjs/kits/presentation/outputs.js +176 -38
- package/dist/cjs/kits/presentation/templates.js +33 -5
- package/dist/cjs/kits/presentation/variants.js +31 -2
- package/dist/cjs/kits/projection.js +63 -8
- package/dist/cjs/kits/rank-fusion.js +27 -4
- package/dist/cjs/kits/reflection-log-source.js +89 -16
- package/dist/cjs/kits/reflection.js +234 -60
- package/dist/cjs/kits/retrieval.js +98 -18
- package/dist/cjs/kits/search.js +180 -27
- package/dist/cjs/kits/text-skills.js +104 -19
- package/dist/cjs/kits/tools.js +415 -74
- package/dist/cjs/kits/vector-search.js +50 -16
- package/dist/cjs/mock/node.js +7 -1
- package/dist/cjs/mock/web.js +7 -1
- package/dist/cjs/mock.js +7 -1
- package/dist/cjs/model/binding.js +68 -17
- package/dist/cjs/model/call-budget.js +45 -4
- package/dist/cjs/model/decision-retry.js +19 -1
- package/dist/cjs/model/defaults.js +27 -4
- package/dist/cjs/model/index.js +7 -0
- package/dist/cjs/model/interactions/arguments.js +36 -1
- package/dist/cjs/model/interactions/json-object.js +48 -12
- package/dist/cjs/model/interactions/native-functions.js +52 -10
- package/dist/cjs/model/message-diagnostics.js +17 -4
- package/dist/cjs/model/options.js +9 -1
- package/dist/cjs/model/preparation.js +86 -12
- package/dist/cjs/model/runner.js +413 -79
- package/dist/cjs/model/selection-transport.js +48 -8
- package/dist/cjs/model/settings.js +67 -13
- package/dist/cjs/model/token-budget.js +69 -11
- package/dist/cjs/model/transports.js +59 -6
- package/dist/cjs/structs/common.js +11 -0
- package/dist/cjs/structs/debug.js +34 -5
- package/dist/cjs/structs/errors.js +26 -1
- package/dist/cjs/structs/index.js +11 -1
- package/dist/cjs/structs/kits/durable.js +7 -0
- package/dist/cjs/structs/kits/family.js +1 -0
- package/dist/cjs/structs/kits/interaction.js +8 -1
- package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
- package/dist/cjs/structs/kits/reflection.js +18 -3
- package/dist/cjs/structs/model/chat-provider.js +6 -0
- package/dist/cjs/structs/support/model/completion.js +2 -0
- package/dist/cjs/structs/support/model/messages.js +2 -0
- package/dist/cjs/support/capabilities.js +43 -6
- package/dist/cjs/support/context/assembly.js +88 -16
- package/dist/cjs/support/context/compression.js +48 -6
- package/dist/cjs/support/context/fragments.js +6 -0
- package/dist/cjs/support/context/history.js +36 -1
- package/dist/cjs/support/context/index.js +11 -0
- package/dist/cjs/support/context/nodes.js +164 -35
- package/dist/cjs/support/context/processing.js +319 -61
- package/dist/cjs/support/context/selection-policy.js +98 -21
- package/dist/cjs/support/context/selection.js +61 -10
- package/dist/cjs/support/context/snapshot.js +29 -7
- package/dist/cjs/support/context/strategies.js +120 -28
- package/dist/cjs/support/index.js +9 -1
- package/dist/cjs/support/model/capabilities.js +20 -1
- package/dist/cjs/support/model/chat-completions.js +92 -20
- package/dist/cjs/support/model/children.js +34 -6
- package/dist/cjs/support/model/compatible-provider.js +189 -59
- package/dist/cjs/support/model/completion/calls.js +61 -0
- package/dist/cjs/support/model/completion/default.js +33 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +107 -0
- package/dist/cjs/support/model/index.js +12 -0
- package/dist/cjs/support/model/interactions/index.js +12 -1
- package/dist/cjs/support/model/interactions/json-object.js +6 -0
- package/dist/cjs/support/model/interactions/native-functions.js +6 -0
- package/dist/cjs/support/model/observer.js +32 -6
- package/dist/cjs/support/model/preview-rules.js +66 -16
- package/dist/cjs/support/model/reply-preview.js +77 -17
- package/dist/cjs/support/model/stage-transport.js +33 -7
- package/dist/cjs/support/model/strategies.js +75 -14
- package/dist/cjs/support/model/transports.js +53 -11
- package/dist/cjs/support/registration.js +49 -7
- package/dist/cjs/support/schema.js +46 -4
- package/dist/cjs/support/stream-events.js +60 -8
- package/dist/cjs/support/tool-runtime.js +6 -0
- package/dist/cjs/support/tools.js +79 -10
- package/dist/cjs/support/transport/index.js +7 -0
- package/dist/cjs/support/transport/json.js +28 -4
- package/dist/cjs/support/transport/sse.js +25 -2
- package/dist/cjs/utils/break-observer.js +20 -2
- package/dist/cjs/utils/cancellation.js +77 -9
- package/dist/cjs/utils/catalog.js +19 -4
- package/dist/cjs/utils/debug.js +14 -2
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/interaction-definition.js +26 -6
- package/dist/cjs/utils/invocation.js +42 -4
- package/dist/cjs/utils/model-protocol.js +20 -1
- package/dist/cjs/utils/object.js +16 -0
- package/dist/cjs/utils/observer.js +22 -2
- package/dist/cjs/utils/protocol-registry.js +47 -4
- package/dist/cjs/utils/query-key.js +21 -2
- package/dist/cjs/utils/registration.js +18 -2
- package/dist/cjs/utils/rules.js +39 -11
- package/dist/cjs/utils/schema-adapter.js +25 -2
- package/dist/cjs/utils/synchronous.js +64 -7
- package/dist/cjs/utils/text.js +15 -1
- package/dist/esm/capabilities/index.d.ts +13 -0
- package/dist/esm/capabilities/index.js +13 -0
- package/dist/esm/capabilities/invocation.d.ts +16 -2
- package/dist/esm/capabilities/invocation.js +80 -10
- package/dist/esm/capabilities/model.d.ts +68 -1
- package/dist/esm/capabilities/model.js +126 -13
- package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
- package/dist/esm/capabilities/tool-runtime.js +64 -12
- package/dist/esm/capabilities/tools.d.ts +96 -3
- package/dist/esm/capabilities/tools.js +267 -32
- package/dist/esm/context/assembly.d.ts +13 -2
- package/dist/esm/context/assembly.js +46 -5
- package/dist/esm/context/audit.d.ts +23 -1
- package/dist/esm/context/audit.js +31 -6
- package/dist/esm/context/fragments.d.ts +37 -3
- package/dist/esm/context/fragments.js +54 -11
- package/dist/esm/context/index.d.ts +12 -0
- package/dist/esm/context/index.js +12 -0
- package/dist/esm/context/journal.d.ts +32 -1
- package/dist/esm/context/journal.js +84 -7
- package/dist/esm/context/plan.d.ts +11 -1
- package/dist/esm/context/plan.js +30 -2
- package/dist/esm/diagnostics/catalog.d.ts +6 -0
- package/dist/esm/diagnostics/catalog.js +17 -3
- package/dist/esm/diagnostics/index.d.ts +30 -2
- package/dist/esm/diagnostics/index.js +149 -29
- package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
- package/dist/esm/diagnostics/sub-flow.js +240 -40
- package/dist/esm/errors.d.ts +22 -2
- package/dist/esm/errors.js +99 -17
- package/dist/esm/execution/branch.d.ts +19 -1
- package/dist/esm/execution/branch.js +20 -4
- package/dist/esm/execution/engine.d.ts +291 -5
- package/dist/esm/execution/engine.js +471 -57
- package/dist/esm/execution/events.d.ts +16 -2
- package/dist/esm/execution/events.js +136 -18
- package/dist/esm/execution/index.d.ts +7 -0
- package/dist/esm/execution/index.js +7 -0
- package/dist/esm/execution/reporting.d.ts +49 -1
- package/dist/esm/execution/reporting.js +75 -6
- package/dist/esm/execution/state.d.ts +126 -10
- package/dist/esm/execution/state.js +161 -22
- package/dist/esm/execution/workflow.d.ts +121 -3
- package/dist/esm/execution/workflow.js +224 -32
- package/dist/esm/index.d.ts +17 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/kits/aggregation.d.ts +34 -2
- package/dist/esm/kits/aggregation.js +45 -3
- package/dist/esm/kits/answering/batch.d.ts +17 -0
- package/dist/esm/kits/answering/batch.js +23 -4
- package/dist/esm/kits/answering/check-result.d.ts +18 -1
- package/dist/esm/kits/answering/check-result.js +31 -8
- package/dist/esm/kits/answering/checks.d.ts +11 -0
- package/dist/esm/kits/answering/checks.js +24 -3
- package/dist/esm/kits/answering/flow.d.ts +25 -2
- package/dist/esm/kits/answering/flow.js +192 -36
- package/dist/esm/kits/answering/index.d.ts +12 -0
- package/dist/esm/kits/answering/index.js +19 -1
- package/dist/esm/kits/answering/tasks.d.ts +32 -1
- package/dist/esm/kits/answering/tasks.js +88 -13
- package/dist/esm/kits/artifacts.d.ts +11 -0
- package/dist/esm/kits/artifacts.js +36 -4
- package/dist/esm/kits/candidates.d.ts +23 -1
- package/dist/esm/kits/candidates.js +47 -5
- package/dist/esm/kits/delivery.d.ts +34 -0
- package/dist/esm/kits/delivery.js +40 -5
- package/dist/esm/kits/durable.d.ts +19 -0
- package/dist/esm/kits/durable.js +155 -31
- package/dist/esm/kits/evidence.d.ts +28 -5
- package/dist/esm/kits/evidence.js +66 -15
- package/dist/esm/kits/family.d.ts +17 -1
- package/dist/esm/kits/family.js +152 -22
- package/dist/esm/kits/index.d.ts +12 -1
- package/dist/esm/kits/index.js +12 -1
- package/dist/esm/kits/inference.d.ts +64 -0
- package/dist/esm/kits/inference.js +104 -16
- package/dist/esm/kits/intents/catalog.d.ts +13 -1
- package/dist/esm/kits/intents/catalog.js +67 -16
- package/dist/esm/kits/intents/index.d.ts +11 -0
- package/dist/esm/kits/intents/index.js +11 -0
- package/dist/esm/kits/intents/registry.d.ts +61 -3
- package/dist/esm/kits/intents/registry.js +188 -43
- package/dist/esm/kits/intents/scopes.d.ts +73 -3
- package/dist/esm/kits/intents/scopes.js +215 -46
- package/dist/esm/kits/interaction/command.d.ts +38 -4
- package/dist/esm/kits/interaction/command.js +140 -36
- package/dist/esm/kits/interaction/commands.d.ts +66 -2
- package/dist/esm/kits/interaction/commands.js +86 -11
- package/dist/esm/kits/interaction/handlers.d.ts +19 -2
- package/dist/esm/kits/interaction/handlers.js +27 -10
- package/dist/esm/kits/interaction/index.d.ts +10 -0
- package/dist/esm/kits/interaction/index.js +10 -0
- package/dist/esm/kits/interaction/transfer.d.ts +39 -2
- package/dist/esm/kits/interaction/transfer.js +80 -14
- package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
- package/dist/esm/kits/knowledge/catalog.js +62 -11
- package/dist/esm/kits/knowledge/index.d.ts +11 -0
- package/dist/esm/kits/knowledge/index.js +16 -1
- package/dist/esm/kits/knowledge/publication.d.ts +15 -1
- package/dist/esm/kits/knowledge/publication.js +99 -23
- package/dist/esm/kits/knowledge/sections.d.ts +31 -1
- package/dist/esm/kits/knowledge/sections.js +33 -4
- package/dist/esm/kits/normalization.d.ts +25 -2
- package/dist/esm/kits/normalization.js +51 -7
- package/dist/esm/kits/policies.d.ts +26 -3
- package/dist/esm/kits/policies.js +79 -15
- package/dist/esm/kits/presentation/events.d.ts +51 -4
- package/dist/esm/kits/presentation/events.js +54 -10
- package/dist/esm/kits/presentation/index.d.ts +12 -0
- package/dist/esm/kits/presentation/index.js +25 -2
- package/dist/esm/kits/presentation/outputs.d.ts +30 -1
- package/dist/esm/kits/presentation/outputs.js +176 -38
- package/dist/esm/kits/presentation/templates.d.ts +32 -3
- package/dist/esm/kits/presentation/templates.js +33 -5
- package/dist/esm/kits/presentation/variants.d.ts +29 -0
- package/dist/esm/kits/presentation/variants.js +31 -2
- package/dist/esm/kits/projection.d.ts +42 -5
- package/dist/esm/kits/projection.js +63 -8
- package/dist/esm/kits/rank-fusion.d.ts +21 -1
- package/dist/esm/kits/rank-fusion.js +28 -5
- package/dist/esm/kits/reflection-log-source.d.ts +28 -1
- package/dist/esm/kits/reflection-log-source.js +89 -16
- package/dist/esm/kits/reflection.d.ts +17 -1
- package/dist/esm/kits/reflection.js +235 -61
- package/dist/esm/kits/retrieval.d.ts +18 -2
- package/dist/esm/kits/retrieval.js +98 -18
- package/dist/esm/kits/search.d.ts +56 -3
- package/dist/esm/kits/search.js +180 -27
- package/dist/esm/kits/text-skills.d.ts +16 -2
- package/dist/esm/kits/text-skills.js +104 -19
- package/dist/esm/kits/tools.d.ts +122 -2
- package/dist/esm/kits/tools.js +416 -74
- package/dist/esm/kits/vector-search.d.ts +47 -1
- package/dist/esm/kits/vector-search.js +51 -17
- package/dist/esm/mock/node.d.ts +7 -0
- package/dist/esm/mock/node.js +7 -1
- package/dist/esm/mock/web.d.ts +7 -0
- package/dist/esm/mock/web.js +7 -1
- package/dist/esm/mock.d.ts +7 -0
- package/dist/esm/mock.js +7 -1
- package/dist/esm/model/binding.d.ts +32 -3
- package/dist/esm/model/binding.js +68 -17
- package/dist/esm/model/call-budget.d.ts +30 -2
- package/dist/esm/model/call-budget.js +45 -4
- package/dist/esm/model/decision-retry.d.ts +10 -1
- package/dist/esm/model/decision-retry.js +19 -1
- package/dist/esm/model/defaults.d.ts +13 -2
- package/dist/esm/model/defaults.js +27 -4
- package/dist/esm/model/index.d.ts +7 -0
- package/dist/esm/model/index.js +7 -0
- package/dist/esm/model/interactions/arguments.d.ts +27 -0
- package/dist/esm/model/interactions/arguments.js +36 -1
- package/dist/esm/model/interactions/json-object.d.ts +7 -1
- package/dist/esm/model/interactions/json-object.js +48 -12
- package/dist/esm/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/model/interactions/native-functions.js +52 -10
- package/dist/esm/model/message-diagnostics.d.ts +17 -1
- package/dist/esm/model/message-diagnostics.js +17 -4
- package/dist/esm/model/options.d.ts +18 -1
- package/dist/esm/model/options.js +9 -1
- package/dist/esm/model/preparation.d.ts +30 -2
- package/dist/esm/model/preparation.js +86 -12
- package/dist/esm/model/runner.d.ts +129 -5
- package/dist/esm/model/runner.js +414 -80
- package/dist/esm/model/selection-transport.d.ts +14 -1
- package/dist/esm/model/selection-transport.js +48 -8
- package/dist/esm/model/settings.d.ts +11 -0
- package/dist/esm/model/settings.js +67 -13
- package/dist/esm/model/token-budget.d.ts +59 -1
- package/dist/esm/model/token-budget.js +69 -11
- package/dist/esm/model/transports.d.ts +20 -2
- package/dist/esm/model/transports.js +59 -6
- package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
- package/dist/esm/structs/capabilities/model.d.ts +27 -0
- package/dist/esm/structs/capabilities/tools.d.ts +38 -0
- package/dist/esm/structs/common.d.ts +62 -2
- package/dist/esm/structs/common.js +11 -0
- package/dist/esm/structs/context/fragments.d.ts +28 -0
- package/dist/esm/structs/context/journal.d.ts +28 -3
- package/dist/esm/structs/context/processing.d.ts +11 -0
- package/dist/esm/structs/debug.d.ts +58 -1
- package/dist/esm/structs/debug.js +34 -5
- package/dist/esm/structs/diagnostics.d.ts +119 -1
- package/dist/esm/structs/errors.d.ts +42 -1
- package/dist/esm/structs/errors.js +26 -1
- package/dist/esm/structs/execution/engine.d.ts +24 -1
- package/dist/esm/structs/execution/events.d.ts +12 -0
- package/dist/esm/structs/execution/workflow.d.ts +71 -0
- package/dist/esm/structs/index.d.ts +11 -1
- package/dist/esm/structs/index.js +11 -1
- package/dist/esm/structs/invocation.d.ts +30 -0
- package/dist/esm/structs/kits/aggregation.d.ts +12 -0
- package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
- package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
- package/dist/esm/structs/kits/answering/state.d.ts +21 -0
- package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
- package/dist/esm/structs/kits/artifacts.d.ts +14 -0
- package/dist/esm/structs/kits/candidates.d.ts +19 -0
- package/dist/esm/structs/kits/delivery.d.ts +22 -0
- package/dist/esm/structs/kits/durable.d.ts +56 -3
- package/dist/esm/structs/kits/durable.js +7 -0
- package/dist/esm/structs/kits/evidence.d.ts +23 -0
- package/dist/esm/structs/kits/family.d.ts +49 -1
- package/dist/esm/structs/kits/family.js +1 -0
- package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
- package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
- package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
- package/dist/esm/structs/kits/interaction.d.ts +64 -0
- package/dist/esm/structs/kits/interaction.js +8 -1
- package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
- package/dist/esm/structs/kits/knowledge-publication.js +1 -0
- package/dist/esm/structs/kits/knowledge.d.ts +39 -2
- package/dist/esm/structs/kits/normalization.d.ts +15 -0
- package/dist/esm/structs/kits/policies.d.ts +25 -1
- package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
- package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
- package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
- package/dist/esm/structs/kits/projection.d.ts +21 -0
- package/dist/esm/structs/kits/reflection.d.ts +61 -2
- package/dist/esm/structs/kits/reflection.js +18 -3
- package/dist/esm/structs/kits/retrieval.d.ts +39 -0
- package/dist/esm/structs/kits/search.d.ts +24 -0
- package/dist/esm/structs/kits/text-skills.d.ts +36 -0
- package/dist/esm/structs/kits/tools.d.ts +87 -0
- package/dist/esm/structs/model/chat-provider.d.ts +24 -1
- package/dist/esm/structs/model/chat-provider.js +6 -0
- package/dist/esm/structs/model/interactions.d.ts +38 -0
- package/dist/esm/structs/model/messages.d.ts +34 -0
- package/dist/esm/structs/model/runtime.d.ts +104 -6
- package/dist/esm/structs/support/capabilities.d.ts +19 -2
- package/dist/esm/structs/support/context-processing.d.ts +88 -9
- package/dist/esm/structs/support/context.d.ts +29 -1
- package/dist/esm/structs/support/model/completion.d.ts +50 -0
- package/dist/esm/structs/support/model/completion.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +13 -1
- package/dist/esm/structs/support/model/messages.d.ts +54 -0
- package/dist/esm/structs/support/model/messages.js +1 -0
- package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
- package/dist/esm/structs/support/model/provider.d.ts +71 -6
- package/dist/esm/structs/support/registration.d.ts +13 -0
- package/dist/esm/structs/support/schema.d.ts +14 -0
- package/dist/esm/structs/support/tools.d.ts +28 -0
- package/dist/esm/structs/support/transport/json.d.ts +16 -0
- package/dist/esm/structs/support/transport/sse.d.ts +15 -0
- package/dist/esm/structs/utils/rules.d.ts +19 -0
- package/dist/esm/support/capabilities.d.ts +25 -2
- package/dist/esm/support/capabilities.js +43 -6
- package/dist/esm/support/context/assembly.d.ts +35 -4
- package/dist/esm/support/context/assembly.js +88 -16
- package/dist/esm/support/context/compression.d.ts +17 -1
- package/dist/esm/support/context/compression.js +48 -6
- package/dist/esm/support/context/fragments.d.ts +6 -0
- package/dist/esm/support/context/fragments.js +6 -0
- package/dist/esm/support/context/history.d.ts +43 -0
- package/dist/esm/support/context/history.js +36 -1
- package/dist/esm/support/context/index.d.ts +13 -2
- package/dist/esm/support/context/index.js +12 -1
- package/dist/esm/support/context/nodes.d.ts +65 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +152 -1
- package/dist/esm/support/context/processing.js +320 -62
- package/dist/esm/support/context/selection-policy.d.ts +42 -2
- package/dist/esm/support/context/selection-policy.js +98 -21
- package/dist/esm/support/context/selection.d.ts +14 -1
- package/dist/esm/support/context/selection.js +61 -10
- package/dist/esm/support/context/snapshot.d.ts +23 -1
- package/dist/esm/support/context/snapshot.js +29 -7
- package/dist/esm/support/context/strategies.d.ts +35 -2
- package/dist/esm/support/context/strategies.js +120 -28
- package/dist/esm/support/index.d.ts +9 -1
- package/dist/esm/support/index.js +9 -1
- package/dist/esm/support/model/capabilities.d.ts +10 -0
- package/dist/esm/support/model/capabilities.js +20 -1
- package/dist/esm/support/model/chat-completions.d.ts +44 -15
- package/dist/esm/support/model/chat-completions.js +92 -20
- package/dist/esm/support/model/children.d.ts +34 -2
- package/dist/esm/support/model/children.js +34 -6
- package/dist/esm/support/model/compatible-provider.d.ts +29 -3
- package/dist/esm/support/model/compatible-provider.js +190 -60
- package/dist/esm/support/model/completion/calls.d.ts +40 -0
- package/dist/esm/support/model/completion/calls.js +58 -0
- package/dist/esm/support/model/completion/default.d.ts +11 -0
- package/dist/esm/support/model/completion/default.js +30 -0
- package/dist/esm/support/model/completion/index.d.ts +10 -0
- package/dist/esm/support/model/completion/index.js +22 -0
- package/dist/esm/support/model/completion/session.d.ts +16 -0
- package/dist/esm/support/model/completion/session.js +104 -0
- package/dist/esm/support/model/index.d.ts +14 -0
- package/dist/esm/support/model/index.js +12 -0
- package/dist/esm/support/model/interactions/index.d.ts +1 -1
- package/dist/esm/support/model/interactions/index.js +12 -1
- package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
- package/dist/esm/support/model/interactions/json-object.js +6 -0
- package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/support/model/interactions/native-functions.js +6 -0
- package/dist/esm/support/model/observer.d.ts +25 -2
- package/dist/esm/support/model/observer.js +32 -6
- package/dist/esm/support/model/preview-rules.d.ts +26 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +22 -1
- package/dist/esm/support/model/reply-preview.js +77 -17
- package/dist/esm/support/model/stage-transport.d.ts +9 -1
- package/dist/esm/support/model/stage-transport.js +33 -7
- package/dist/esm/support/model/strategies.d.ts +28 -2
- package/dist/esm/support/model/strategies.js +75 -14
- package/dist/esm/support/model/transports.d.ts +17 -1
- package/dist/esm/support/model/transports.js +53 -11
- package/dist/esm/support/registration.d.ts +20 -1
- package/dist/esm/support/registration.js +49 -7
- package/dist/esm/support/schema.d.ts +31 -1
- package/dist/esm/support/schema.js +46 -4
- package/dist/esm/support/stream-events.d.ts +22 -1
- package/dist/esm/support/stream-events.js +60 -8
- package/dist/esm/support/tool-runtime.d.ts +6 -0
- package/dist/esm/support/tool-runtime.js +6 -0
- package/dist/esm/support/tools.d.ts +22 -0
- package/dist/esm/support/tools.js +79 -10
- package/dist/esm/support/transport/index.d.ts +7 -0
- package/dist/esm/support/transport/index.js +7 -0
- package/dist/esm/support/transport/json.d.ts +29 -2
- package/dist/esm/support/transport/json.js +28 -4
- package/dist/esm/support/transport/sse.d.ts +31 -1
- package/dist/esm/support/transport/sse.js +25 -2
- package/dist/esm/types.d.ts +9 -1
- package/dist/esm/utils/break-observer.d.ts +27 -2
- package/dist/esm/utils/break-observer.js +20 -2
- package/dist/esm/utils/cancellation.d.ts +56 -5
- package/dist/esm/utils/cancellation.js +77 -9
- package/dist/esm/utils/catalog.d.ts +20 -1
- package/dist/esm/utils/catalog.js +19 -4
- package/dist/esm/utils/debug.d.ts +20 -1
- package/dist/esm/utils/debug.js +14 -2
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/interaction-definition.d.ts +18 -1
- package/dist/esm/utils/interaction-definition.js +26 -6
- package/dist/esm/utils/invocation.d.ts +36 -1
- package/dist/esm/utils/invocation.js +42 -4
- package/dist/esm/utils/model-protocol.d.ts +8 -0
- package/dist/esm/utils/model-protocol.js +20 -1
- package/dist/esm/utils/object.d.ts +16 -0
- package/dist/esm/utils/object.js +16 -0
- package/dist/esm/utils/observer.d.ts +19 -1
- package/dist/esm/utils/observer.js +22 -2
- package/dist/esm/utils/protocol-registry.d.ts +38 -1
- package/dist/esm/utils/protocol-registry.js +47 -4
- package/dist/esm/utils/query-key.d.ts +11 -1
- package/dist/esm/utils/query-key.js +21 -2
- package/dist/esm/utils/registration.d.ts +34 -2
- package/dist/esm/utils/registration.js +18 -2
- package/dist/esm/utils/rules.d.ts +81 -4
- package/dist/esm/utils/rules.js +39 -11
- package/dist/esm/utils/schema-adapter.d.ts +12 -1
- package/dist/esm/utils/schema-adapter.js +25 -2
- package/dist/esm/utils/synchronous.d.ts +60 -4
- package/dist/esm/utils/synchronous.js +64 -7
- package/dist/esm/utils/text.d.ts +15 -1
- package/dist/esm/utils/text.js +15 -1
- package/package.json +7 -3
|
@@ -1,19 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Projection Kit: fit structured values into a character budget without losing valid JSON.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: an optional App-side helper for context and preview budgets. Callers
|
|
5
|
+
* choose the budget, the rendering strategy and the fallback text; this module only shrinks
|
|
6
|
+
* values and verifies the result still fits.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `defineContentProjection`, `projectContinuousExcerpt`, `defineTreeProjection`,
|
|
9
|
+
* `Projection`, and the projection option/result types.
|
|
10
|
+
*/
|
|
1
11
|
import { booleanResult, synchronous } from '../utils/synchronous.js';
|
|
2
12
|
import { validateContextBudget } from '../context/fragments.js';
|
|
3
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Compile a JSON-preserving projector.
|
|
15
|
+
*
|
|
16
|
+
* Keep valid JSON while reducing prose before dropping records; budgets are caller policy.
|
|
17
|
+
* The candidate list is tried in order (outer `counts`, inner `lengths`), so callers control
|
|
18
|
+
* whether trimming text or dropping items is preferred, and the configured fallback is used
|
|
19
|
+
* only when no candidate fits.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Candidate bounds, a synchronous renderer and a synchronous fallback factory.
|
|
22
|
+
* @returns A frozen object whose `project({ value, maxChars })` returns `{ text, truncated }`.
|
|
23
|
+
* @throws TypeError For a negative or non-integer `maxChars`, or a non-synchronous renderer;
|
|
24
|
+
* a `CONTEXT_BUDGET` `ValidationError` from the budget check when even the fallback is long.
|
|
25
|
+
*/
|
|
4
26
|
export function defineContentProjection(options) {
|
|
5
27
|
const counts = [...options.counts], lengths = [...options.lengths];
|
|
6
28
|
const render = options.render.bind(options), fallback = options.fallback.bind(options);
|
|
7
29
|
function shorten(value, length, count) {
|
|
30
|
+
// The ellipsis is explicit so a reader can tell truncated text from original text.
|
|
8
31
|
if (typeof value === 'string')
|
|
9
32
|
return value.length <= length ? value : value.slice(0, length) + '…';
|
|
10
33
|
if (Array.isArray(value))
|
|
11
|
-
return value.slice(0, count).map(child => shorten(child, length, count));
|
|
34
|
+
return value.slice(0, count).map((child) => shorten(child, length, count));
|
|
12
35
|
if (value && typeof value === 'object')
|
|
13
36
|
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, shorten(child, length, count)]));
|
|
14
37
|
return value;
|
|
15
38
|
}
|
|
16
|
-
function project({ value, maxChars: limit }) {
|
|
39
|
+
function project({ value, maxChars: limit, }) {
|
|
17
40
|
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
18
41
|
throw new TypeError('Invalid projection maxChars');
|
|
19
42
|
const original = JSON.stringify(value);
|
|
@@ -31,7 +54,19 @@ export function defineContentProjection(options) {
|
|
|
31
54
|
}
|
|
32
55
|
return Object.freeze({ project });
|
|
33
56
|
}
|
|
34
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Project a continuous excerpt of a body by binary-searching the longest prefix that fits.
|
|
59
|
+
*
|
|
60
|
+
* Binary-search a continuous prefix and keep an existing surrogate pair intact. `render`
|
|
61
|
+
* receives the prefix length, not the text, so the caller decides how the excerpt is framed.
|
|
62
|
+
*
|
|
63
|
+
* @param body - Source text whose length bounds the search.
|
|
64
|
+
* @param limit - Maximum rendered length in characters.
|
|
65
|
+
* @param render - Synchronous renderer for a given prefix length.
|
|
66
|
+
* @returns The fitting projection, or `undefined` when even the empty excerpt does not fit.
|
|
67
|
+
* @throws TypeError For an invalid limit or a non-synchronous renderer; a `CONTEXT_BUDGET`
|
|
68
|
+
* `ValidationError` when the chosen excerpt still exceeds the budget.
|
|
69
|
+
*/
|
|
35
70
|
export function projectContinuousExcerpt(body, limit, render) {
|
|
36
71
|
validateContextBudget(0, limit);
|
|
37
72
|
const excerpt = (length) => synchronous(render(length), 'Excerpt renderers must be synchronous');
|
|
@@ -51,7 +86,19 @@ export function projectContinuousExcerpt(body, limit, render) {
|
|
|
51
86
|
validateContextBudget(text.length, limit);
|
|
52
87
|
return { text, truncated: true };
|
|
53
88
|
}
|
|
54
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* Compile a depth-limited tree transform.
|
|
91
|
+
*
|
|
92
|
+
* Traverse synchronously in property/array order; only undefined omits a result. Because a
|
|
93
|
+
* visitor returns a new value instead of mutating, an omitted branch disappears from arrays
|
|
94
|
+
* and objects the same way, and `maxDepth` bounds both cycles and cost.
|
|
95
|
+
*
|
|
96
|
+
* @param options - Maximum depth (0 keeps only the root), optional omit predicate and optional
|
|
97
|
+
* record visitor.
|
|
98
|
+
* @returns A frozen object whose `visit(value, context)` returns the projected value.
|
|
99
|
+
* @throws TypeError For a negative or non-integer `maxDepth`; a predicate that is not
|
|
100
|
+
* synchronous boolean; a visitor that returns a thenable.
|
|
101
|
+
*/
|
|
55
102
|
export function defineTreeProjection(options) {
|
|
56
103
|
const { maxDepth } = options, omit = options.omit?.bind(options), visitRecord = options.visitRecord?.bind(options);
|
|
57
104
|
if (!Number.isSafeInteger(maxDepth) || maxDepth < 0)
|
|
@@ -59,10 +106,13 @@ export function defineTreeProjection(options) {
|
|
|
59
106
|
function visit(value, depth, context) {
|
|
60
107
|
if (depth > maxDepth)
|
|
61
108
|
return undefined;
|
|
62
|
-
if (omit &&
|
|
109
|
+
if (omit &&
|
|
110
|
+
booleanResult(omit(value, depth, context), 'Tree omit predicates must return boolean synchronously'))
|
|
63
111
|
return undefined;
|
|
64
112
|
if (Array.isArray(value))
|
|
65
|
-
return value
|
|
113
|
+
return value
|
|
114
|
+
.map((item) => visit(item, depth + 1, context))
|
|
115
|
+
.filter((item) => item !== undefined);
|
|
66
116
|
if (value === null || typeof value !== 'object')
|
|
67
117
|
return value;
|
|
68
118
|
const record = value;
|
|
@@ -75,4 +125,9 @@ export function defineTreeProjection(options) {
|
|
|
75
125
|
const project = (value, context) => visit(value, 0, context);
|
|
76
126
|
return Object.freeze({ visit: project });
|
|
77
127
|
}
|
|
78
|
-
|
|
128
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
129
|
+
export const Projection = Object.freeze({
|
|
130
|
+
defineContentProjection,
|
|
131
|
+
projectContinuousExcerpt,
|
|
132
|
+
defineTreeProjection,
|
|
133
|
+
});
|
|
@@ -1,18 +1,38 @@
|
|
|
1
|
+
/** One retriever's ordered result, optionally weighted. */
|
|
1
2
|
export interface RankedList {
|
|
3
|
+
/** Unique source name; duplicate names are rejected because they would double-count. */
|
|
2
4
|
readonly sourceId: string;
|
|
5
|
+
/** Ids in descending relevance; duplicates inside one list are ignored after the first. */
|
|
3
6
|
readonly ids: readonly string[];
|
|
7
|
+
/** Relative source weight, strictly positive; defaults to 1. */
|
|
4
8
|
readonly weight?: number;
|
|
5
9
|
}
|
|
10
|
+
/** One fused result with the per-source ranks that produced its score. */
|
|
6
11
|
export interface FusedRank {
|
|
12
|
+
/** Fused document id. */
|
|
7
13
|
id: string;
|
|
14
|
+
/** Sum of `weight / (k + rank)` over contributing sources; higher is better. */
|
|
8
15
|
score: number;
|
|
16
|
+
/** Contributions in source order, using one-based ranks. */
|
|
9
17
|
contributions: {
|
|
10
18
|
sourceId: string;
|
|
11
19
|
rank: number;
|
|
12
20
|
weight: number;
|
|
13
21
|
}[];
|
|
14
22
|
}
|
|
15
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Fuse ranked lists with one-based reciprocal rank fusion.
|
|
25
|
+
*
|
|
26
|
+
* Raw retriever scores are intentionally not mixed. Ties break on id, so the output is
|
|
27
|
+
* deterministic for a given input.
|
|
28
|
+
*
|
|
29
|
+
* @param lists - Ranked lists with unique source ids and positive weights.
|
|
30
|
+
* @param options - `limit` is the maximum number of fused results (1..1000); `k` smooths the
|
|
31
|
+
* contribution of the top ranks and defaults to the conventional value 60.
|
|
32
|
+
* @returns At most `limit` fused ranks, best first.
|
|
33
|
+
* @throws A configured error for invalid options, a duplicate/blank source id, non-string ids,
|
|
34
|
+
* or a non-positive weight.
|
|
35
|
+
*/
|
|
16
36
|
export declare function reciprocalRankFusion(lists: readonly RankedList[], options: {
|
|
17
37
|
limit: number;
|
|
18
38
|
k?: number;
|
|
@@ -1,20 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Reciprocal rank fusion for several ranked id lists.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: an optional App-side helper for merging retrieval or search results.
|
|
5
|
+
* Only ranks are combined, never raw scores, so lists produced by incomparable scorers stay
|
|
6
|
+
* comparable. Storage and source selection belong to the App.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `reciprocalRankFusion`, `RankedList`, `FusedRank`.
|
|
9
|
+
*/
|
|
10
|
+
import { breakWhile } from '../utils/rules.js';
|
|
11
|
+
/**
|
|
12
|
+
* Fuse ranked lists with one-based reciprocal rank fusion.
|
|
13
|
+
*
|
|
14
|
+
* Raw retriever scores are intentionally not mixed. Ties break on id, so the output is
|
|
15
|
+
* deterministic for a given input.
|
|
16
|
+
*
|
|
17
|
+
* @param lists - Ranked lists with unique source ids and positive weights.
|
|
18
|
+
* @param options - `limit` is the maximum number of fused results (1..1000); `k` smooths the
|
|
19
|
+
* contribution of the top ranks and defaults to the conventional value 60.
|
|
20
|
+
* @returns At most `limit` fused ranks, best first.
|
|
21
|
+
* @throws A configured error for invalid options, a duplicate/blank source id, non-string ids,
|
|
22
|
+
* or a non-positive weight.
|
|
23
|
+
*/
|
|
3
24
|
export function reciprocalRankFusion(lists, options) {
|
|
25
|
+
// 60 is the smoothing constant popularised by the original RRF paper and keeps rank
|
|
26
|
+
// differences meaningful without letting the top hit dominate.
|
|
4
27
|
const k = options.k ?? 60, sources = new Set(), candidates = new Map();
|
|
5
28
|
breakWhile(!Number.isFinite(k) ||
|
|
6
29
|
k < 0 ||
|
|
7
30
|
!Number.isSafeInteger(options.limit) ||
|
|
8
31
|
options.limit < 1 ||
|
|
9
|
-
options.limit > 1000,
|
|
32
|
+
options.limit > 1000, 'Invalid RRF options');
|
|
10
33
|
for (const list of lists) {
|
|
11
34
|
const weight = list.weight ?? 1, sourceId = list.sourceId;
|
|
12
35
|
breakWhile(!sourceId?.trim() ||
|
|
13
36
|
sources.has(sourceId) ||
|
|
14
37
|
!Array.isArray(list.ids) ||
|
|
15
|
-
list.ids.some((id) => typeof id !==
|
|
38
|
+
list.ids.some((id) => typeof id !== 'string' || !id.trim()) ||
|
|
16
39
|
!Number.isFinite(weight) ||
|
|
17
|
-
weight <= 0,
|
|
40
|
+
weight <= 0, 'Invalid ranked source');
|
|
18
41
|
sources.add(sourceId);
|
|
19
42
|
const seen = new Set();
|
|
20
43
|
for (const id of list.ids) {
|
|
@@ -13,8 +13,17 @@ interface Page<T> {
|
|
|
13
13
|
captureIncomplete?: boolean;
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Structural port: the App supplies its own FileLogReader, trusted scope and current
|
|
18
|
+
* authorization.
|
|
19
|
+
*/
|
|
17
20
|
export interface ReflectionLogReader {
|
|
21
|
+
/**
|
|
22
|
+
* List runs the caller may inspect.
|
|
23
|
+
*
|
|
24
|
+
* @param query - Optional trace filter, pagination cursor, page limit and abort signal.
|
|
25
|
+
* @returns A page of runs with their file path and manifest.
|
|
26
|
+
*/
|
|
18
27
|
listRuns(query: {
|
|
19
28
|
traceId?: string;
|
|
20
29
|
cursor?: string;
|
|
@@ -24,6 +33,12 @@ export interface ReflectionLogReader {
|
|
|
24
33
|
path: string;
|
|
25
34
|
manifest: Readonly<Record<string, unknown>>;
|
|
26
35
|
}>>;
|
|
36
|
+
/**
|
|
37
|
+
* Read the events of one run.
|
|
38
|
+
*
|
|
39
|
+
* @param query - Run id, optional source/type filters, pagination cursor, limit and signal.
|
|
40
|
+
* @returns A page of raw event records.
|
|
41
|
+
*/
|
|
27
42
|
readEvents(query: {
|
|
28
43
|
run: string;
|
|
29
44
|
sources?: readonly ('app' | 'core' | 'client')[];
|
|
@@ -33,6 +48,18 @@ export interface ReflectionLogReader {
|
|
|
33
48
|
signal?: AbortSignal;
|
|
34
49
|
}): Promise<Page<Record<string, unknown>>>;
|
|
35
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Build a reflection source over a log reader.
|
|
53
|
+
*
|
|
54
|
+
* Coverage is reported as `best-effort`: a page is only `complete` when the reader exhausted the
|
|
55
|
+
* run without capture gaps or omitted issues, and every gap or issue code is surfaced instead of
|
|
56
|
+
* being silently dropped.
|
|
57
|
+
*
|
|
58
|
+
* @param options - Reader, source id, optional fixed trace id and the authorization hook.
|
|
59
|
+
* @returns A frozen source whose `query` returns reflection evidence.
|
|
60
|
+
* @throws A configured or authorization error for a malformed page, an expired run or event, or
|
|
61
|
+
* a run that this source has not discovered yet; `TypeError` when authorization returns a value.
|
|
62
|
+
*/
|
|
36
63
|
export declare function defineReflectionLogSource<App>(options: {
|
|
37
64
|
reader: ReflectionLogReader;
|
|
38
65
|
id: string;
|
|
@@ -1,34 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reflection Kit: adapt an App-owned execution log reader into an authorized reflection source.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: part of the `reflection` Kit. It projects metadata only — no payloads,
|
|
5
|
+
* text, file paths or replay — and remembers which runs a caller discovered, so a guessed run
|
|
6
|
+
* cannot be read in a later call.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `defineReflectionLogSource`, `ReflectionLogReader`.
|
|
9
|
+
*/
|
|
1
10
|
import { breakWhile } from '../utils/rules.js';
|
|
2
11
|
import { reflectionIdentityFields } from '../structs/kits/reflection.js';
|
|
3
12
|
import { awaitAssertion, awaitWithSignal } from '../utils/cancellation.js';
|
|
4
|
-
const object = (value) => value && typeof value === 'object' && !Array.isArray(value)
|
|
13
|
+
const object = (value) => value && typeof value === 'object' && !Array.isArray(value)
|
|
14
|
+
? value
|
|
15
|
+
: {};
|
|
5
16
|
const eventMetrics = {
|
|
6
17
|
'model.end': (payload) => object(payload.state),
|
|
7
18
|
'workflow.event': (payload) => object(payload.event),
|
|
8
19
|
};
|
|
9
20
|
const workflowStatuses = {
|
|
10
|
-
enter: 'running',
|
|
21
|
+
enter: 'running',
|
|
22
|
+
transition: 'running',
|
|
23
|
+
continue: 'running',
|
|
24
|
+
complete: 'success',
|
|
25
|
+
error: 'error',
|
|
11
26
|
};
|
|
12
27
|
const cancellationCodes = new Set(['CANCELLED', 'TIMEOUT', 'CALL_TIMEOUT', 'ROUND_TIMEOUT']);
|
|
28
|
+
/**
|
|
29
|
+
* Build a reflection source over a log reader.
|
|
30
|
+
*
|
|
31
|
+
* Coverage is reported as `best-effort`: a page is only `complete` when the reader exhausted the
|
|
32
|
+
* run without capture gaps or omitted issues, and every gap or issue code is surfaced instead of
|
|
33
|
+
* being silently dropped.
|
|
34
|
+
*
|
|
35
|
+
* @param options - Reader, source id, optional fixed trace id and the authorization hook.
|
|
36
|
+
* @returns A frozen source whose `query` returns reflection evidence.
|
|
37
|
+
* @throws A configured or authorization error for a malformed page, an expired run or event, or
|
|
38
|
+
* a run that this source has not discovered yet; `TypeError` when authorization returns a value.
|
|
39
|
+
*/
|
|
13
40
|
export function defineReflectionLogSource(options) {
|
|
14
41
|
const reader = options.reader, traceId = options.traceId, authorize = options.authorize.bind(options), allowed = new Map();
|
|
15
42
|
const checkAuthorization = (context) => awaitAssertion(() => authorize(context), context.signal, 'Reflection log authorization must return void');
|
|
16
|
-
const coverage = (page) => ({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
43
|
+
const coverage = (page) => ({
|
|
44
|
+
consistency: 'best-effort',
|
|
45
|
+
complete: page.coverage.exhausted &&
|
|
46
|
+
!page.coverage.captureIncomplete &&
|
|
47
|
+
!page.issues.length &&
|
|
48
|
+
!page.issuesOmitted,
|
|
49
|
+
gaps: [
|
|
50
|
+
...new Set([
|
|
51
|
+
...(page.status === 'end' ? [] : [page.status]),
|
|
52
|
+
...page.issues.map((item) => item.code),
|
|
53
|
+
...(page.issuesOmitted ? ['issues omitted'] : []),
|
|
54
|
+
...(page.coverage.captureIncomplete ? ['capture incomplete'] : []),
|
|
55
|
+
]),
|
|
56
|
+
].slice(0, 32),
|
|
57
|
+
});
|
|
58
|
+
return Object.freeze({
|
|
59
|
+
id: options.id,
|
|
60
|
+
description: 'Explicitly authorized execution metadata; no payloads, text, file paths or replay.',
|
|
21
61
|
authorize: (_query, context) => checkAuthorization(context),
|
|
22
62
|
async query(query, context) {
|
|
23
63
|
await checkAuthorization(context);
|
|
24
64
|
if (!query.run) {
|
|
25
|
-
const page = await awaitWithSignal(reader.listRuns({
|
|
65
|
+
const page = await awaitWithSignal(reader.listRuns({
|
|
66
|
+
traceId,
|
|
67
|
+
cursor: query.cursor,
|
|
68
|
+
limit: query.limit,
|
|
69
|
+
signal: context.signal,
|
|
70
|
+
}), context.signal);
|
|
26
71
|
context.signal.throwIfAborted();
|
|
27
72
|
const items = page.items.map(({ path, manifest }) => {
|
|
28
73
|
const expiresAtMs = Number(manifest.expiresAt);
|
|
29
74
|
breakWhile(!Number.isFinite(expiresAtMs) || expiresAtMs <= Date.now(), 'Log evidence expired');
|
|
30
|
-
return {
|
|
31
|
-
|
|
75
|
+
return {
|
|
76
|
+
id: `run:${String(manifest.runId)}`,
|
|
77
|
+
runId: path,
|
|
78
|
+
type: 'run',
|
|
79
|
+
expiresAtMs,
|
|
80
|
+
...(typeof manifest.outcome === 'string' ? { status: manifest.outcome } : {}),
|
|
81
|
+
};
|
|
32
82
|
});
|
|
33
83
|
const result = { items, cursor: page.cursor, coverage: coverage(page) };
|
|
34
84
|
context.signal.throwIfAborted();
|
|
@@ -39,14 +89,29 @@ export function defineReflectionLogSource(options) {
|
|
|
39
89
|
}
|
|
40
90
|
const expiresAtMs = allowed.get(query.run);
|
|
41
91
|
breakWhile(!expiresAtMs || expiresAtMs <= Date.now(), 'Run was not discovered in this authorized review');
|
|
42
|
-
const page = await awaitWithSignal(reader.readEvents({
|
|
92
|
+
const page = await awaitWithSignal(reader.readEvents({
|
|
93
|
+
run: query.run,
|
|
94
|
+
sources: ['core'],
|
|
95
|
+
types: query.types,
|
|
96
|
+
cursor: query.cursor,
|
|
97
|
+
limit: query.limit,
|
|
98
|
+
signal: context.signal,
|
|
99
|
+
}), context.signal);
|
|
43
100
|
context.signal.throwIfAborted();
|
|
44
101
|
breakWhile(expiresAtMs <= Date.now(), 'Log evidence expired');
|
|
45
102
|
const items = page.items.map((event) => {
|
|
46
103
|
const state = object(event.payload), type = String(event.type ?? event.event);
|
|
47
|
-
const select = Object.hasOwn(eventMetrics, type)
|
|
104
|
+
const select = Object.hasOwn(eventMetrics, type)
|
|
105
|
+
? eventMetrics[type]
|
|
106
|
+
: undefined;
|
|
48
107
|
const metrics = select ? select(state) : state;
|
|
49
|
-
const item = {
|
|
108
|
+
const item = {
|
|
109
|
+
id: `${String(event.runId)}:${String(event.sequence)}`,
|
|
110
|
+
runId: query.run,
|
|
111
|
+
type: event.type ?? event.event,
|
|
112
|
+
sequence: event.sequence,
|
|
113
|
+
expiresAtMs,
|
|
114
|
+
};
|
|
50
115
|
for (const key of reflectionIdentityFields)
|
|
51
116
|
if (typeof event[key] === 'string')
|
|
52
117
|
item[key] = event[key];
|
|
@@ -57,11 +122,19 @@ export function defineReflectionLogSource(options) {
|
|
|
57
122
|
if (typeof value === 'string')
|
|
58
123
|
item[key] = value;
|
|
59
124
|
}
|
|
60
|
-
const code = metrics.errorCode ??
|
|
125
|
+
const code = metrics.errorCode ??
|
|
126
|
+
state.errorCode ??
|
|
127
|
+
(Array.isArray(metrics.codes) ? metrics.codes[0] : undefined) ??
|
|
128
|
+
object(metrics.error).code;
|
|
61
129
|
if (typeof code === 'string')
|
|
62
130
|
item.code = code;
|
|
63
|
-
if ((type === 'workflow.event' || type === 'loop.event') &&
|
|
64
|
-
|
|
131
|
+
if ((type === 'workflow.event' || type === 'loop.event') &&
|
|
132
|
+
typeof metrics.type === 'string' &&
|
|
133
|
+
Object.hasOwn(workflowStatuses, metrics.type)) {
|
|
134
|
+
item.status =
|
|
135
|
+
metrics.type === 'error' && typeof code === 'string' && cancellationCodes.has(code)
|
|
136
|
+
? 'cancelled'
|
|
137
|
+
: workflowStatuses[metrics.type];
|
|
65
138
|
}
|
|
66
139
|
for (const key of ['durationMs', 'inputChars', 'outputChars', 'calls'])
|
|
67
140
|
if (typeof metrics[key] === 'number')
|
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import { type ReflectionDefinition, type ReflectionTask } from '../structs/kits/reflection.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Compile a reflection task.
|
|
4
|
+
*
|
|
5
|
+
* Model-driven investigation through ordinary registered tools and the existing Core loop. The
|
|
6
|
+
* task always reports `persisted: false`: storing a report is the App's decision. Observed
|
|
7
|
+
* findings must cite evidence ids that were actually returned in this run, which is what keeps
|
|
8
|
+
* the report tied to real observations instead of model recall.
|
|
9
|
+
*
|
|
10
|
+
* @param definition - Model child factory, authorized source, extra read-only tools and limits.
|
|
11
|
+
* @returns A frozen task whose `run(question, context)` returns a report.
|
|
12
|
+
* @throws TypeError For a non-read-only extra tool, invalid limits or an oversized question;
|
|
13
|
+
* an authorization error from the App hook. Budget exhaustion returns an `incomplete` report
|
|
14
|
+
* rather than throwing.
|
|
15
|
+
*/
|
|
3
16
|
export declare function defineReflection<App>(definition: ReflectionDefinition<App>): ReflectionTask<App>;
|
|
17
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
4
18
|
export declare const Reflection: Readonly<{
|
|
5
19
|
defineReflection: typeof defineReflection;
|
|
6
20
|
}>;
|
|
7
21
|
export type * from '../structs/kits/reflection.js';
|
|
22
|
+
/** Finding kinds and the identity fields copied into evidence metadata. */
|
|
8
23
|
export { reflectionFindingKinds, reflectionIdentityFields } from '../structs/kits/reflection.js';
|
|
24
|
+
/** Adapter that turns an App log reader into a reflection source. */
|
|
9
25
|
export { defineReflectionLogSource, type ReflectionLogReader } from './reflection-log-source.js';
|