@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
package/dist/cjs/kits/family.js
CHANGED
|
@@ -2,39 +2,92 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.familyOperations = exports.Family = void 0;
|
|
4
4
|
exports.defineAgentFamily = defineAgentFamily;
|
|
5
|
+
/**
|
|
6
|
+
* Family Kit: version App state that hangs off Core branches, with fork, merge and promote.
|
|
7
|
+
*
|
|
8
|
+
* Place in the package: an optional App-side library. A family is a bounded, expiring record
|
|
9
|
+
* of immutable versions; each version pairs a branch snapshot with App state. The Kit owns
|
|
10
|
+
* revision checks, capacity, retention and lineage rules; the store, authorization, validation
|
|
11
|
+
* and merge policy stay with the App. No executable function or authority is restored here.
|
|
12
|
+
*
|
|
13
|
+
* Exports: `defineAgentFamily`, `Family`, the family record/version/operation types and
|
|
14
|
+
* `familyOperations`.
|
|
15
|
+
*/
|
|
5
16
|
const invocation_js_1 = require("../utils/invocation.js");
|
|
6
17
|
const cancellation_js_1 = require("../utils/cancellation.js");
|
|
7
18
|
const synchronous_js_1 = require("../utils/synchronous.js");
|
|
8
19
|
const rules_js_1 = require("../utils/rules.js");
|
|
9
20
|
const branch_js_1 = require("../execution/branch.js");
|
|
10
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Compile a versioned family backed by an App-owned compare-and-swap store.
|
|
23
|
+
*
|
|
24
|
+
* Every mutation reads the record, verifies the caller's expected revision, then commits with
|
|
25
|
+
* a compare-and-swap, so concurrent writers fail with a revision conflict rather than
|
|
26
|
+
* overwriting each other. Reads are also treated as policy checks because the App binds its
|
|
27
|
+
* read rules into the store it supplies.
|
|
28
|
+
*
|
|
29
|
+
* @param definition - Store, authorization, validation, state predicate, branch/state snapshots
|
|
30
|
+
* and optional merge handler, clock and bounds.
|
|
31
|
+
* @returns A frozen family with `read`, `create`, `fork`, `merge` and `promote`.
|
|
32
|
+
* @throws A configured error (often `TypeError`) for an invalid id, expired or unknown record,
|
|
33
|
+
* revision conflict, exhausted capacity, lineage mismatch, missing merge configuration,
|
|
34
|
+
* invalid merge result, or changed active version.
|
|
35
|
+
*/
|
|
11
36
|
function defineAgentFamily(definition) {
|
|
12
|
-
const store = {
|
|
37
|
+
const store = {
|
|
38
|
+
load: definition.store.load.bind(definition.store),
|
|
39
|
+
compareAndSwap: definition.store.compareAndSwap.bind(definition.store),
|
|
40
|
+
};
|
|
13
41
|
const authorize = definition.authorize.bind(definition), validate = definition.validate.bind(definition);
|
|
14
42
|
const isState = definition.isState.bind(definition), merge = definition.merge?.bind(definition), now = definition.now?.bind(definition) ?? Date.now;
|
|
43
|
+
// Bounds are encoded in the record itself: 32 versions and seven days of retention keep the
|
|
44
|
+
// snapshot small enough to clone and compare on every operation.
|
|
15
45
|
const maxVersions = definition.maxVersions ?? 32, retentionMs = definition.retentionMs ?? 7 * 86400_000;
|
|
16
|
-
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(maxVersions) ||
|
|
46
|
+
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(maxVersions) ||
|
|
47
|
+
maxVersions < 1 ||
|
|
48
|
+
!Number.isSafeInteger(retentionMs) ||
|
|
49
|
+
retentionMs < 1, 'Invalid family bounds');
|
|
17
50
|
const validId = (id) => typeof id === 'string' && !!id.trim() && id.length <= 200;
|
|
18
51
|
const stateSnapshot = (value) => {
|
|
19
52
|
(0, rules_js_1.breakWhile)(!(0, synchronous_js_1.booleanResult)(isState(value), 'Family state predicates must be synchronous'), 'Invalid family state');
|
|
20
53
|
return structuredClone(value);
|
|
21
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Load, validate and clone a family record.
|
|
57
|
+
*
|
|
58
|
+
* @param id - Family id, at most 200 characters.
|
|
59
|
+
* @param context - Operation context supplying the abort signal.
|
|
60
|
+
* @returns A cloned record whose versions, branches and states all passed validation.
|
|
61
|
+
* @throws A configured error for an invalid id, a missing/expired record, or an inconsistent
|
|
62
|
+
* version.
|
|
63
|
+
*/
|
|
22
64
|
const read = async (id, context) => {
|
|
23
65
|
context.signal.throwIfAborted();
|
|
24
66
|
(0, rules_js_1.breakWhile)(!validId(id), 'Invalid family id');
|
|
25
67
|
const record = structuredClone(await (0, cancellation_js_1.awaitWithSignal)(store.load(id), context.signal));
|
|
26
68
|
context.signal.throwIfAborted();
|
|
27
|
-
(0, rules_js_1.breakWhile)(!record ||
|
|
28
|
-
|
|
29
|
-
|
|
69
|
+
(0, rules_js_1.breakWhile)(!record ||
|
|
70
|
+
record.id !== id ||
|
|
71
|
+
!Number.isFinite(record.expiresAtMs) ||
|
|
72
|
+
record.expiresAtMs <= now() ||
|
|
73
|
+
!Number.isSafeInteger(record.revision) ||
|
|
74
|
+
record.revision < 1 ||
|
|
75
|
+
!Array.isArray(record.versions) ||
|
|
76
|
+
!record.versions.length ||
|
|
77
|
+
record.versions.length > maxVersions ||
|
|
78
|
+
!record.versions.some((version) => version.id === record.activeId), 'Family unavailable');
|
|
79
|
+
const ids = new Set(record.versions.map((version) => version.id));
|
|
30
80
|
(0, rules_js_1.breakWhile)(ids.size !== record.versions.length, 'Duplicate family version');
|
|
31
81
|
for (const item of record.versions) {
|
|
32
|
-
(0, rules_js_1.breakWhile)(!validId(item.id) ||
|
|
33
|
-
|
|
82
|
+
(0, rules_js_1.breakWhile)(!validId(item.id) ||
|
|
83
|
+
!Number.isFinite(item.createdAtMs) ||
|
|
84
|
+
item.createdAtMs < 0 ||
|
|
85
|
+
[item.parentId, item.baseId, item.mergeSourceId].some((value) => value !== undefined && !ids.has(value)), 'Invalid family version');
|
|
34
86
|
(0, branch_js_1.snapshotBranch)(item.branch);
|
|
35
87
|
stateSnapshot(item.state);
|
|
36
88
|
}
|
|
37
|
-
// Reading policy is part of the App's bound store. Mutations also require their explicit
|
|
89
|
+
// Reading policy is part of the App's bound store. Mutations also require their explicit
|
|
90
|
+
// operation grant.
|
|
38
91
|
context.signal.throwIfAborted();
|
|
39
92
|
return structuredClone(record);
|
|
40
93
|
};
|
|
@@ -54,7 +107,7 @@ function defineAgentFamily(definition) {
|
|
|
54
107
|
return record;
|
|
55
108
|
};
|
|
56
109
|
const version = (record, id) => {
|
|
57
|
-
const selected = record.versions.find(item => item.id === id);
|
|
110
|
+
const selected = record.versions.find((item) => item.id === id);
|
|
58
111
|
(0, rules_js_1.breakWhile)(!selected, 'Unknown family version');
|
|
59
112
|
return selected;
|
|
60
113
|
};
|
|
@@ -64,50 +117,127 @@ function defineAgentFamily(definition) {
|
|
|
64
117
|
return commit({ ...record, revision: record.revision + 1, versions: [...record.versions, candidate] }, record.revision, context);
|
|
65
118
|
};
|
|
66
119
|
return Object.freeze({
|
|
120
|
+
/** Clone and validate one family record through the same read path used by mutations. */
|
|
67
121
|
read,
|
|
122
|
+
/**
|
|
123
|
+
* Create a family with one initial version.
|
|
124
|
+
*
|
|
125
|
+
* @param request - Family id plus its first branch and state.
|
|
126
|
+
* @param context - Operation context; authorization receives `'create'` and no record.
|
|
127
|
+
* @returns The committed record at revision 1.
|
|
128
|
+
* @throws A configured error for an invalid or existing id, or failed authorization or
|
|
129
|
+
* validation.
|
|
130
|
+
*/
|
|
68
131
|
async create(request, context) {
|
|
69
132
|
context.signal.throwIfAborted();
|
|
70
133
|
const { id } = request;
|
|
71
134
|
(0, rules_js_1.breakWhile)(!validId(id), 'Invalid family id');
|
|
72
135
|
const branch = (0, branch_js_1.snapshotBranch)(request.branch), state = structuredClone(request.state);
|
|
73
|
-
(0, rules_js_1.breakWhile)(!!await (0, cancellation_js_1.awaitWithSignal)(store.load(id), context.signal), 'Family already exists');
|
|
136
|
+
(0, rules_js_1.breakWhile)(!!(await (0, cancellation_js_1.awaitWithSignal)(store.load(id), context.signal)), 'Family already exists');
|
|
74
137
|
await (0, cancellation_js_1.awaitAssertion)(() => authorize('create', undefined, context), context.signal, 'Family authorization must return void');
|
|
75
|
-
const candidate = {
|
|
138
|
+
const candidate = {
|
|
139
|
+
id: (0, invocation_js_1.invocationId)(),
|
|
140
|
+
branch,
|
|
141
|
+
state: stateSnapshot(state),
|
|
142
|
+
createdAtMs: now(),
|
|
143
|
+
};
|
|
76
144
|
await (0, cancellation_js_1.awaitAssertion)(() => validate(structuredClone(candidate), context), context.signal, 'Family validation must return void');
|
|
77
|
-
return commit({
|
|
145
|
+
return commit({
|
|
146
|
+
id,
|
|
147
|
+
revision: 1,
|
|
148
|
+
activeId: candidate.id,
|
|
149
|
+
expiresAtMs: now() + retentionMs,
|
|
150
|
+
versions: [candidate],
|
|
151
|
+
}, undefined, context);
|
|
78
152
|
},
|
|
153
|
+
/**
|
|
154
|
+
* Add a child version derived from one existing version.
|
|
155
|
+
*
|
|
156
|
+
* @param request - Family id, expected revision, parent version id, new branch and state.
|
|
157
|
+
* @param context - Operation context; authorization receives `'fork'` and the record.
|
|
158
|
+
* @returns The committed record with the new version appended.
|
|
159
|
+
* @throws A configured error for a stale revision, unknown parent, broken lineage or full
|
|
160
|
+
* capacity.
|
|
161
|
+
*/
|
|
79
162
|
async fork(request, context) {
|
|
80
163
|
context.signal.throwIfAborted();
|
|
81
164
|
const { id, revision, parentId } = request, state = structuredClone(request.state);
|
|
82
165
|
const branch = (0, branch_js_1.snapshotBranch)(request.branch);
|
|
83
166
|
const record = await check('fork', id, revision, context), parent = version(record, parentId);
|
|
84
|
-
(0, rules_js_1.breakWhile)(branch.agentId !== parent.branch.agentId ||
|
|
85
|
-
|
|
86
|
-
|
|
167
|
+
(0, rules_js_1.breakWhile)(branch.agentId !== parent.branch.agentId ||
|
|
168
|
+
branch.parentBranchId !== parent.branch.branchId ||
|
|
169
|
+
branch.parentAgentVersionId !== parent.branch.agentVersionId ||
|
|
170
|
+
branch.branchId === parent.branch.branchId, 'Fork lineage mismatch');
|
|
171
|
+
return add(record, {
|
|
172
|
+
id: (0, invocation_js_1.invocationId)(),
|
|
173
|
+
parentId: parent.id,
|
|
174
|
+
baseId: parent.id,
|
|
175
|
+
branch,
|
|
176
|
+
state: stateSnapshot(state),
|
|
177
|
+
createdAtMs: now(),
|
|
178
|
+
}, context);
|
|
87
179
|
},
|
|
180
|
+
/**
|
|
181
|
+
* Merge a source version into a target version over their shared base.
|
|
182
|
+
*
|
|
183
|
+
* Conflicts are reported, never resolved here: a non-empty conflict list returns
|
|
184
|
+
* `saved: false` with the unchanged record, so the App decides how to reconcile.
|
|
185
|
+
*
|
|
186
|
+
* @param request - Family id, expected revision and the base, target and source version ids.
|
|
187
|
+
* @param context - Operation context; authorization receives `'merge'` and the record.
|
|
188
|
+
* @returns `{ saved, record, conflicts }`.
|
|
189
|
+
* @throws A configured error for a stale revision, missing versions, no merge handler, a
|
|
190
|
+
* missing shared base, or an invalid merge result.
|
|
191
|
+
*/
|
|
88
192
|
async merge(request, context) {
|
|
89
193
|
const { id, revision, baseId, targetId, sourceId } = request;
|
|
90
194
|
const record = await check('merge', id, revision, context);
|
|
91
195
|
(0, rules_js_1.breakWhile)(!merge, 'Family merge is not configured');
|
|
92
196
|
const base = version(record, baseId), target = version(record, targetId), source = version(record, sourceId);
|
|
93
|
-
(0, rules_js_1.breakWhile)(source.baseId !== base.id || target.id !== base.id && target.baseId !== base.id, 'Merge requires a shared base');
|
|
94
|
-
const result = await (0, cancellation_js_1.awaitWithSignal)(merge({
|
|
95
|
-
|
|
197
|
+
(0, rules_js_1.breakWhile)(source.baseId !== base.id || (target.id !== base.id && target.baseId !== base.id), 'Merge requires a shared base');
|
|
198
|
+
const result = await (0, cancellation_js_1.awaitWithSignal)(merge({
|
|
199
|
+
base: stateSnapshot(base.state),
|
|
200
|
+
target: stateSnapshot(target.state),
|
|
201
|
+
source: stateSnapshot(source.state),
|
|
202
|
+
}, context), context.signal);
|
|
203
|
+
(0, rules_js_1.breakWhile)(!result ||
|
|
204
|
+
!Array.isArray(result.conflicts) ||
|
|
205
|
+
result.conflicts.some((value) => typeof value !== 'string'), 'Invalid merge result');
|
|
96
206
|
if (result.conflicts.length)
|
|
97
207
|
return { saved: false, record, conflicts: [...result.conflicts] };
|
|
98
|
-
const candidate = {
|
|
99
|
-
|
|
208
|
+
const candidate = {
|
|
209
|
+
id: (0, invocation_js_1.invocationId)(),
|
|
210
|
+
parentId: target.id,
|
|
211
|
+
baseId: target.id,
|
|
212
|
+
mergeSourceId: source.id,
|
|
213
|
+
branch: (0, branch_js_1.snapshotBranch)(source.branch),
|
|
214
|
+
state: stateSnapshot(result.value),
|
|
215
|
+
createdAtMs: now(),
|
|
216
|
+
};
|
|
100
217
|
return { saved: true, record: await add(record, candidate, context), conflicts: [] };
|
|
101
218
|
},
|
|
219
|
+
/**
|
|
220
|
+
* Make an existing version the active one.
|
|
221
|
+
*
|
|
222
|
+
* @param request - Family id, expected revision, candidate id and the active id the caller
|
|
223
|
+
* believes is current.
|
|
224
|
+
* @param context - Operation context; authorization receives `'promote'` and the record.
|
|
225
|
+
* @returns The committed record pointing at the candidate.
|
|
226
|
+
* @throws A configured error for a stale revision or active id, an unrelated candidate, or
|
|
227
|
+
* failed validation.
|
|
228
|
+
*/
|
|
102
229
|
async promote(request, context) {
|
|
103
230
|
const { id, revision, candidateId, expectedActiveId } = request;
|
|
104
231
|
const record = await check('promote', id, revision, context), candidate = version(record, candidateId);
|
|
105
|
-
(0, rules_js_1.breakWhile)(record.activeId !== expectedActiveId ||
|
|
232
|
+
(0, rules_js_1.breakWhile)(record.activeId !== expectedActiveId ||
|
|
233
|
+
(candidate.id !== record.activeId && candidate.baseId !== record.activeId), 'Active family version changed');
|
|
106
234
|
await (0, cancellation_js_1.awaitAssertion)(() => validate(structuredClone(candidate), context), context.signal, 'Family validation must return void');
|
|
107
235
|
return commit({ ...record, revision: record.revision + 1, activeId: candidate.id }, record.revision, context);
|
|
108
236
|
},
|
|
109
237
|
});
|
|
110
238
|
}
|
|
239
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
111
240
|
exports.Family = Object.freeze({ defineAgentFamily });
|
|
241
|
+
/** Operation names accepted by the family `authorize` hook. */
|
|
112
242
|
var family_js_1 = require("../structs/kits/family.js");
|
|
113
243
|
Object.defineProperty(exports, "familyOperations", { enumerable: true, get: function () { return family_js_1.familyOperations; } });
|
package/dist/cjs/kits/index.js
CHANGED
|
@@ -15,7 +15,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.reciprocalRankFusion = exports.VectorSearch = exports.ModelCalls = exports.TextSearch = exports.TextSkills = exports.Candidates = exports.Policies = exports.Evidence = exports.Retrieval = exports.Aggregation = exports.Projection = exports.Delivery = exports.Normalization = exports.Presentation = exports.Answering = exports.Knowledge = exports.Tools = exports.Intents = exports.Interaction = void 0;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Explicit bulk Kit entry.
|
|
20
|
+
*
|
|
21
|
+
* Kits are optional, App-side business libraries. An application may consume a single Kit
|
|
22
|
+
* path; this file only exists for callers that prefer one import for the whole set. Core
|
|
23
|
+
* never imports from this directory, so nothing here becomes a runtime requirement.
|
|
24
|
+
*
|
|
25
|
+
* Exports: the Kit namespaces (`Interaction`, `Intents`, `Tools`, `Knowledge`, `Answering`,
|
|
26
|
+
* `Presentation`, `Normalization`, `Delivery`, `Projection`, `Aggregation`, `Retrieval`,
|
|
27
|
+
* `Evidence`, `Policies`, `Candidates`, `TextSkills`, `TextSearch`, `ModelCalls`,
|
|
28
|
+
* `VectorSearch`) plus every Kit type. Individual Kit paths stay the default.
|
|
29
|
+
*/
|
|
19
30
|
var index_js_1 = require("./interaction/index.js");
|
|
20
31
|
Object.defineProperty(exports, "Interaction", { enumerable: true, get: function () { return index_js_1.Interaction; } });
|
|
21
32
|
var index_js_2 = require("./intents/index.js");
|
|
@@ -8,35 +8,97 @@ const cancellation_js_1 = require("../utils/cancellation.js");
|
|
|
8
8
|
const invocation_js_1 = require("../utils/invocation.js");
|
|
9
9
|
const errors_js_2 = require("../errors.js");
|
|
10
10
|
const protocol_registry_js_1 = require("../utils/protocol-registry.js");
|
|
11
|
+
/**
|
|
12
|
+
* Frozen catalog of model bindings plus a checked invocation entry point.
|
|
13
|
+
*
|
|
14
|
+
* Registration happens once in the constructor; the catalog is never mutated afterwards, so a
|
|
15
|
+
* caller cannot swap a provider in the middle of a run.
|
|
16
|
+
*/
|
|
11
17
|
class ModelCalls {
|
|
12
18
|
sequence = 0;
|
|
13
19
|
bindings = new protocol_registry_js_1.ProtocolRegistry();
|
|
20
|
+
/**
|
|
21
|
+
* @param bindings - Bindings to register; each needs a non-blank `identity` and an `invoke`.
|
|
22
|
+
* @throws TypeError When a binding is malformed or two bindings share an id.
|
|
23
|
+
*/
|
|
14
24
|
constructor(bindings) {
|
|
15
25
|
for (const binding of bindings) {
|
|
16
26
|
if (!binding.identity?.trim() || typeof binding.invoke !== 'function')
|
|
17
27
|
throw new TypeError('Invalid model binding');
|
|
18
|
-
this.bindings.set(binding.id, Object.freeze({
|
|
19
|
-
|
|
28
|
+
this.bindings.set(binding.id, Object.freeze({
|
|
29
|
+
id: binding.id,
|
|
30
|
+
identity: binding.identity,
|
|
31
|
+
invoke: binding.invoke.bind(binding),
|
|
32
|
+
assertInput: binding.assertInput?.bind(binding),
|
|
33
|
+
assertOutput: binding.assertOutput?.bind(binding),
|
|
34
|
+
}));
|
|
20
35
|
}
|
|
21
36
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
/** Registered bindings in declaration order, with methods already bound to their owner. */
|
|
38
|
+
get definitions() {
|
|
39
|
+
return Object.freeze([...this.bindings.values()]);
|
|
40
|
+
}
|
|
41
|
+
/** Registered binding ids in declaration order. */
|
|
42
|
+
ids() {
|
|
43
|
+
return this.bindings.ids();
|
|
44
|
+
}
|
|
45
|
+
/** Whether a binding id is registered. */
|
|
46
|
+
has(id) {
|
|
47
|
+
return this.bindings.has(id);
|
|
48
|
+
}
|
|
49
|
+
/** Registered binding for `id`, or `undefined` when it is absent. */
|
|
50
|
+
get(id) {
|
|
51
|
+
return this.bindings.get(id);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Registered binding for `id`.
|
|
55
|
+
*
|
|
56
|
+
* @throws TypeError When the id is not registered.
|
|
57
|
+
*/
|
|
58
|
+
require(id) {
|
|
59
|
+
return this.bindings.require(id);
|
|
60
|
+
}
|
|
61
|
+
/** Iterate the registered bindings. */
|
|
62
|
+
values() {
|
|
63
|
+
return this.bindings.values();
|
|
64
|
+
}
|
|
65
|
+
/** Iterate `[id, binding]` pairs. */
|
|
66
|
+
entries() {
|
|
67
|
+
return this.bindings.entries();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Implementation identity of one binding.
|
|
71
|
+
*
|
|
72
|
+
* @throws TypeError When the id is not registered.
|
|
73
|
+
*/
|
|
74
|
+
identity(id) {
|
|
75
|
+
return this.require(id).identity;
|
|
76
|
+
}
|
|
30
77
|
async invoke(request, context) {
|
|
31
78
|
if (!request || typeof request !== 'object' || !('input' in request))
|
|
32
79
|
throw new TypeError('Use one model request and execution context');
|
|
33
80
|
const { modelId: id, input, timeoutMs } = request;
|
|
34
|
-
if (!context?.signal ||
|
|
81
|
+
if (!context?.signal ||
|
|
82
|
+
typeof id !== 'string' ||
|
|
83
|
+
!id.trim() ||
|
|
84
|
+
!Number.isSafeInteger(timeoutMs) ||
|
|
85
|
+
timeoutMs < 1 ||
|
|
86
|
+
// 2147483647 is the largest delay `setTimeout`/`AbortSignal.timeout` accept reliably.
|
|
87
|
+
timeoutMs > 2147483647)
|
|
35
88
|
throw new TypeError('A modelId, signal and positive supported timeoutMs are required');
|
|
36
89
|
const sourceBudget = context.attemptBudget;
|
|
37
90
|
const take = sourceBudget?.take.bind(sourceBudget);
|
|
38
91
|
const callId = (0, invocation_js_1.invocationId)(), startedAtMs = Date.now();
|
|
39
|
-
const diagnostics = context.diagnostics?.child(callId, {
|
|
92
|
+
const diagnostics = context.diagnostics?.child(callId, {
|
|
93
|
+
invocationId: callId,
|
|
94
|
+
modelId: id,
|
|
95
|
+
nodeRole: 'invocation',
|
|
96
|
+
definitionKind: 'model-binding',
|
|
97
|
+
definitionId: id,
|
|
98
|
+
nodeId: id,
|
|
99
|
+
nodeName: id,
|
|
100
|
+
nodeKind: 'model-binding',
|
|
101
|
+
});
|
|
40
102
|
const signal = (0, cancellation_js_1.combineSignals)(context.signal, AbortSignal.timeout(timeoutMs));
|
|
41
103
|
let phase = 'input';
|
|
42
104
|
try {
|
|
@@ -51,7 +113,12 @@ class ModelCalls {
|
|
|
51
113
|
}
|
|
52
114
|
const callSequence = ++this.sequence;
|
|
53
115
|
phase = 'invoke';
|
|
54
|
-
diagnostics?.emit('model.binding', () => ({
|
|
116
|
+
diagnostics?.emit('model.binding', () => ({
|
|
117
|
+
modelId: id,
|
|
118
|
+
invocationId: callId,
|
|
119
|
+
status: 'running',
|
|
120
|
+
phase,
|
|
121
|
+
}));
|
|
55
122
|
// Hand off checked inputs before yielding. Arbitrary App inputs may be
|
|
56
123
|
// class instances or services, so Core must not silently clone them.
|
|
57
124
|
signal.throwIfAborted();
|
|
@@ -60,11 +127,32 @@ class ModelCalls {
|
|
|
60
127
|
phase = 'output';
|
|
61
128
|
(0, synchronous_js_1.assertion)(binding.assertOutput?.(output), 'Model output assertions must be synchronous');
|
|
62
129
|
signal.throwIfAborted();
|
|
63
|
-
diagnostics?.emit('model.binding', () => ({
|
|
64
|
-
|
|
130
|
+
diagnostics?.emit('model.binding', () => ({
|
|
131
|
+
modelId: id,
|
|
132
|
+
invocationId: callId,
|
|
133
|
+
status: 'success',
|
|
134
|
+
phase,
|
|
135
|
+
durationMs: Date.now() - startedAtMs,
|
|
136
|
+
}));
|
|
137
|
+
return (0, invocation_js_1.invocationResult)(output, {
|
|
138
|
+
...diagnostics?.identity,
|
|
139
|
+
invocationId: callId,
|
|
140
|
+
modelId: id,
|
|
141
|
+
startedAtMs,
|
|
142
|
+
durationMs: Date.now() - startedAtMs,
|
|
143
|
+
callSequence,
|
|
144
|
+
status: 'success',
|
|
145
|
+
});
|
|
65
146
|
}
|
|
66
147
|
catch (error) {
|
|
67
|
-
diagnostics?.emit('model.binding', () => ({
|
|
148
|
+
diagnostics?.emit('model.binding', () => ({
|
|
149
|
+
modelId: id,
|
|
150
|
+
invocationId: callId,
|
|
151
|
+
status: signal.aborted ? 'cancelled' : 'error',
|
|
152
|
+
phase,
|
|
153
|
+
durationMs: Date.now() - startedAtMs,
|
|
154
|
+
errorCode: (0, errors_js_2.getErrorInfo)(error).code,
|
|
155
|
+
}));
|
|
68
156
|
throw error;
|
|
69
157
|
}
|
|
70
158
|
}
|
|
@@ -1,31 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineAgentCatalog = defineAgentCatalog;
|
|
4
|
+
/**
|
|
5
|
+
* Intents Kit: project registered intents, scopes and tools into one task-facing catalog.
|
|
6
|
+
*
|
|
7
|
+
* Place in the package: part of the `intents` Kit. It reads the actual registries supplied by
|
|
8
|
+
* the App instead of maintaining a parallel capability list, so an intent is only advertised
|
|
9
|
+
* when its tools, scopes and availability agree.
|
|
10
|
+
*
|
|
11
|
+
* Exports: `defineAgentCatalog`, and the catalog intent/scope/port types.
|
|
12
|
+
*/
|
|
4
13
|
const synchronous_js_1 = require("../../utils/synchronous.js");
|
|
5
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Compile a catalog projection over the App's live registries.
|
|
16
|
+
*
|
|
17
|
+
* The actual registries determine availability and relationships. No parallel capability list
|
|
18
|
+
* exists: `intentIds` filters by tool support, `modelCatalog` narrows to the currently accepted
|
|
19
|
+
* task when `restrictToTask` is enabled, and scope tool ids are filtered to tools that exist.
|
|
20
|
+
*
|
|
21
|
+
* @param ports - Sources for intent ids, intents, scopes, the current task, the tool registry
|
|
22
|
+
* and the `restrictToTask` switch.
|
|
23
|
+
* @returns A frozen projection with `intentIds`, `intentSteps`, `intentCatalog`,
|
|
24
|
+
* `scopeCatalog` and `modelCatalog`.
|
|
25
|
+
* @throws TypeError When a supplied predicate does not return a boolean synchronously.
|
|
26
|
+
*/
|
|
6
27
|
function defineAgentCatalog(ports) {
|
|
7
28
|
const ids = ports.intentIds.bind(ports), intents = ports.intents.bind(ports), scopes = ports.scopes.bind(ports), task = ports.currentTask.bind(ports);
|
|
8
|
-
const tools = {
|
|
29
|
+
const tools = {
|
|
30
|
+
values: ports.tools.values.bind(ports.tools),
|
|
31
|
+
has: ports.tools.has.bind(ports.tools),
|
|
32
|
+
supports: ports.tools.supportsIntent.bind(ports.tools),
|
|
33
|
+
describe: ports.tools.describe.bind(ports.tools),
|
|
34
|
+
};
|
|
9
35
|
const restrict = ports.restrictToTask !== false;
|
|
10
36
|
const boolean = (value) => (0, synchronous_js_1.booleanResult)(value, 'Catalog predicates must be synchronous', 'Catalog predicates must return boolean');
|
|
11
|
-
const intentIds = (app) => ids().filter(id => boolean(tools.supports(id, app)));
|
|
12
|
-
const intentSteps = (app) => new Map(intents().map(intent => [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
37
|
+
const intentIds = (app) => ids().filter((id) => boolean(tools.supports(id, app)));
|
|
38
|
+
const intentSteps = (app) => new Map(intents().map((intent) => [
|
|
39
|
+
intent.id,
|
|
40
|
+
[
|
|
41
|
+
...new Set([
|
|
42
|
+
...intent.steps,
|
|
43
|
+
...[...tools.values()]
|
|
44
|
+
.filter((tool) => tool.invocation &&
|
|
45
|
+
(!tool.available || app === undefined || boolean(tool.available(app))) &&
|
|
46
|
+
(tool.intentIds === 'all' || tool.intentIds.includes(intent.id)))
|
|
47
|
+
.map((tool) => tool.invocation.step),
|
|
48
|
+
]),
|
|
49
|
+
],
|
|
50
|
+
]));
|
|
16
51
|
const intentCatalog = (app) => {
|
|
17
52
|
const selected = intentIds(app), described = tools.describe('model', app), steps = intentSteps(app);
|
|
18
|
-
return intents(selected).map(intent => ({
|
|
19
|
-
|
|
53
|
+
return intents(selected).map((intent) => ({
|
|
54
|
+
...intent,
|
|
55
|
+
steps: steps.get(intent.id) ?? [...intent.steps],
|
|
56
|
+
scopeIds: scopes([intent.id]).map((scope) => scope.id),
|
|
57
|
+
toolIds: described
|
|
58
|
+
.filter((tool) => tool.intentIds.includes(intent.id))
|
|
59
|
+
.map((tool) => tool.id),
|
|
60
|
+
}));
|
|
20
61
|
};
|
|
21
|
-
const scopeCatalog = (app) => scopes(intentIds(app)).map(scope => ({ ...scope, toolIds: scope.toolIds.filter(tools.has) }));
|
|
22
|
-
return Object.freeze({
|
|
62
|
+
const scopeCatalog = (app) => scopes(intentIds(app)).map((scope) => ({ ...scope, toolIds: scope.toolIds.filter(tools.has) }));
|
|
63
|
+
return Object.freeze({
|
|
64
|
+
intentIds,
|
|
65
|
+
intentSteps,
|
|
66
|
+
intentCatalog,
|
|
67
|
+
scopeCatalog,
|
|
23
68
|
modelCatalog(app) {
|
|
24
|
-
const accepted = restrict ? task(app) : undefined, selected = intentIds(app).filter(id => !accepted || id === accepted.intentId);
|
|
25
|
-
return {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
69
|
+
const accepted = restrict ? task(app) : undefined, selected = intentIds(app).filter((id) => !accepted || id === accepted.intentId);
|
|
70
|
+
return {
|
|
71
|
+
availableIntentIds: selected,
|
|
72
|
+
availableIntents: intentCatalog(app)
|
|
73
|
+
.filter((intent) => selected.includes(intent.id))
|
|
74
|
+
.map((intent) => accepted ? { ...intent, scopeIds: accepted.scopeId ? [accepted.scopeId] : [] } : intent),
|
|
75
|
+
availableScopes: scopeCatalog(app).filter((scope) => !accepted || scope.id === accepted.scopeId),
|
|
76
|
+
availableTools: tools
|
|
77
|
+
.describe('model', app)
|
|
78
|
+
.filter((tool) => !accepted || tool.intentIds.includes(accepted.intentId)),
|
|
79
|
+
};
|
|
29
80
|
},
|
|
30
81
|
});
|
|
31
82
|
}
|
|
@@ -15,10 +15,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.Intents = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Intents Kit entry: intent and scope registries plus the task-facing catalog projection.
|
|
20
|
+
*
|
|
21
|
+
* Place in the package: an optional App-side library for declaring what the agent may do.
|
|
22
|
+
* Applications register their own intents and scopes; this directory owns registration
|
|
23
|
+
* checks, aliases, relationship lookups and the model-visible projection. Core never imports it.
|
|
24
|
+
*
|
|
25
|
+
* Exports: everything from `./registry.js`, `./scopes.js` and `./catalog.js`, plus the
|
|
26
|
+
* `Intents` namespace object.
|
|
27
|
+
*/
|
|
18
28
|
__exportStar(require("./registry.js"), exports);
|
|
19
29
|
__exportStar(require("./scopes.js"), exports);
|
|
20
30
|
__exportStar(require("./catalog.js"), exports);
|
|
21
31
|
const registry_js_1 = require("./registry.js");
|
|
22
32
|
const scopes_js_1 = require("./scopes.js");
|
|
23
33
|
const catalog_js_1 = require("./catalog.js");
|
|
34
|
+
/** Namespace object for callers that prefer one import over named helpers. */
|
|
24
35
|
exports.Intents = Object.freeze({ IntentRegistry: registry_js_1.IntentRegistry, ScopeRegistry: scopes_js_1.ScopeRegistry, defineAgentCatalog: catalog_js_1.defineAgentCatalog });
|