@jangts/agent-core 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +59 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.md +27 -0
- package/development/docs/assets/agent-core-icon.png +0 -0
- package/development/docs/assets/agent-core-logo.png +0 -0
- package/development/docs/assets/character-agent-core.png +0 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +45 -17
- package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
- package/development/skills/agent-core-app/templates/catalog.json +36 -22
- package/dist/cjs/capabilities/index.js +13 -0
- package/dist/cjs/capabilities/invocation.js +80 -10
- package/dist/cjs/capabilities/model.js +126 -13
- package/dist/cjs/capabilities/tool-runtime.js +64 -12
- package/dist/cjs/capabilities/tools.js +266 -31
- package/dist/cjs/context/assembly.js +46 -5
- package/dist/cjs/context/audit.js +31 -6
- package/dist/cjs/context/fragments.js +54 -11
- package/dist/cjs/context/index.js +12 -0
- package/dist/cjs/context/journal.js +84 -7
- package/dist/cjs/context/plan.js +30 -2
- package/dist/cjs/diagnostics/catalog.js +11 -3
- package/dist/cjs/diagnostics/index.js +149 -29
- package/dist/cjs/diagnostics/sub-flow.js +240 -40
- package/dist/cjs/errors.js +99 -17
- package/dist/cjs/execution/branch.js +20 -4
- package/dist/cjs/execution/engine.js +470 -56
- package/dist/cjs/execution/events.js +136 -18
- package/dist/cjs/execution/index.js +7 -0
- package/dist/cjs/execution/reporting.js +75 -6
- package/dist/cjs/execution/state.js +161 -22
- package/dist/cjs/execution/workflow.js +224 -32
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/kits/aggregation.js +45 -3
- package/dist/cjs/kits/answering/batch.js +23 -4
- package/dist/cjs/kits/answering/check-result.js +31 -8
- package/dist/cjs/kits/answering/checks.js +24 -3
- package/dist/cjs/kits/answering/flow.js +192 -36
- package/dist/cjs/kits/answering/index.js +19 -1
- package/dist/cjs/kits/answering/tasks.js +88 -13
- package/dist/cjs/kits/artifacts.js +36 -4
- package/dist/cjs/kits/candidates.js +47 -5
- package/dist/cjs/kits/delivery.js +40 -5
- package/dist/cjs/kits/durable.js +155 -31
- package/dist/cjs/kits/evidence.js +66 -15
- package/dist/cjs/kits/family.js +152 -22
- package/dist/cjs/kits/index.js +12 -1
- package/dist/cjs/kits/inference.js +104 -16
- package/dist/cjs/kits/intents/catalog.js +67 -16
- package/dist/cjs/kits/intents/index.js +11 -0
- package/dist/cjs/kits/intents/registry.js +188 -43
- package/dist/cjs/kits/intents/scopes.js +215 -46
- package/dist/cjs/kits/interaction/command.js +140 -36
- package/dist/cjs/kits/interaction/commands.js +86 -11
- package/dist/cjs/kits/interaction/handlers.js +27 -10
- package/dist/cjs/kits/interaction/index.js +10 -0
- package/dist/cjs/kits/interaction/transfer.js +80 -14
- package/dist/cjs/kits/knowledge/catalog.js +62 -11
- package/dist/cjs/kits/knowledge/index.js +16 -1
- package/dist/cjs/kits/knowledge/publication.js +99 -23
- package/dist/cjs/kits/knowledge/sections.js +33 -4
- package/dist/cjs/kits/normalization.js +51 -7
- package/dist/cjs/kits/policies.js +79 -15
- package/dist/cjs/kits/presentation/events.js +54 -10
- package/dist/cjs/kits/presentation/index.js +24 -1
- package/dist/cjs/kits/presentation/outputs.js +176 -38
- package/dist/cjs/kits/presentation/templates.js +33 -5
- package/dist/cjs/kits/presentation/variants.js +31 -2
- package/dist/cjs/kits/projection.js +63 -8
- package/dist/cjs/kits/rank-fusion.js +27 -4
- package/dist/cjs/kits/reflection-log-source.js +89 -16
- package/dist/cjs/kits/reflection.js +234 -60
- package/dist/cjs/kits/retrieval.js +98 -18
- package/dist/cjs/kits/search.js +180 -27
- package/dist/cjs/kits/text-skills.js +104 -19
- package/dist/cjs/kits/tools.js +415 -74
- package/dist/cjs/kits/vector-search.js +50 -16
- package/dist/cjs/mock/node.js +7 -1
- package/dist/cjs/mock/web.js +7 -1
- package/dist/cjs/mock.js +7 -1
- package/dist/cjs/model/binding.js +68 -17
- package/dist/cjs/model/call-budget.js +45 -4
- package/dist/cjs/model/decision-retry.js +19 -1
- package/dist/cjs/model/defaults.js +27 -4
- package/dist/cjs/model/index.js +7 -0
- package/dist/cjs/model/interactions/arguments.js +36 -1
- package/dist/cjs/model/interactions/json-object.js +48 -12
- package/dist/cjs/model/interactions/native-functions.js +52 -10
- package/dist/cjs/model/message-diagnostics.js +17 -4
- package/dist/cjs/model/options.js +9 -1
- package/dist/cjs/model/preparation.js +86 -12
- package/dist/cjs/model/runner.js +413 -79
- package/dist/cjs/model/selection-transport.js +48 -8
- package/dist/cjs/model/settings.js +67 -13
- package/dist/cjs/model/token-budget.js +69 -11
- package/dist/cjs/model/transports.js +59 -6
- package/dist/cjs/structs/common.js +11 -0
- package/dist/cjs/structs/debug.js +34 -5
- package/dist/cjs/structs/errors.js +26 -1
- package/dist/cjs/structs/index.js +11 -1
- package/dist/cjs/structs/kits/durable.js +7 -0
- package/dist/cjs/structs/kits/family.js +1 -0
- package/dist/cjs/structs/kits/interaction.js +8 -1
- package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
- package/dist/cjs/structs/kits/reflection.js +18 -3
- package/dist/cjs/structs/model/chat-provider.js +6 -0
- package/dist/cjs/structs/support/model/completion.js +2 -0
- package/dist/cjs/structs/support/model/messages.js +2 -0
- package/dist/cjs/support/capabilities.js +43 -6
- package/dist/cjs/support/context/assembly.js +88 -16
- package/dist/cjs/support/context/compression.js +48 -6
- package/dist/cjs/support/context/fragments.js +6 -0
- package/dist/cjs/support/context/history.js +36 -1
- package/dist/cjs/support/context/index.js +11 -0
- package/dist/cjs/support/context/nodes.js +164 -35
- package/dist/cjs/support/context/processing.js +319 -61
- package/dist/cjs/support/context/selection-policy.js +98 -21
- package/dist/cjs/support/context/selection.js +61 -10
- package/dist/cjs/support/context/snapshot.js +29 -7
- package/dist/cjs/support/context/strategies.js +120 -28
- package/dist/cjs/support/index.js +9 -1
- package/dist/cjs/support/model/capabilities.js +20 -1
- package/dist/cjs/support/model/chat-completions.js +92 -20
- package/dist/cjs/support/model/children.js +34 -6
- package/dist/cjs/support/model/compatible-provider.js +189 -59
- package/dist/cjs/support/model/completion/calls.js +61 -0
- package/dist/cjs/support/model/completion/default.js +32 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +102 -0
- package/dist/cjs/support/model/index.js +12 -0
- package/dist/cjs/support/model/interactions/index.js +12 -1
- package/dist/cjs/support/model/interactions/json-object.js +6 -0
- package/dist/cjs/support/model/interactions/native-functions.js +6 -0
- package/dist/cjs/support/model/observer.js +32 -6
- package/dist/cjs/support/model/preview-rules.js +66 -16
- package/dist/cjs/support/model/reply-preview.js +77 -17
- package/dist/cjs/support/model/stage-transport.js +33 -7
- package/dist/cjs/support/model/strategies.js +75 -14
- package/dist/cjs/support/model/transports.js +53 -11
- package/dist/cjs/support/registration.js +49 -7
- package/dist/cjs/support/schema.js +46 -4
- package/dist/cjs/support/stream-events.js +60 -8
- package/dist/cjs/support/tool-runtime.js +6 -0
- package/dist/cjs/support/tools.js +79 -10
- package/dist/cjs/support/transport/index.js +7 -0
- package/dist/cjs/support/transport/json.js +28 -4
- package/dist/cjs/support/transport/sse.js +25 -2
- package/dist/cjs/utils/break-observer.js +20 -2
- package/dist/cjs/utils/cancellation.js +77 -9
- package/dist/cjs/utils/catalog.js +19 -4
- package/dist/cjs/utils/debug.js +14 -2
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/interaction-definition.js +26 -6
- package/dist/cjs/utils/invocation.js +42 -4
- package/dist/cjs/utils/model-protocol.js +20 -1
- package/dist/cjs/utils/object.js +16 -0
- package/dist/cjs/utils/observer.js +22 -2
- package/dist/cjs/utils/protocol-registry.js +47 -4
- package/dist/cjs/utils/query-key.js +21 -2
- package/dist/cjs/utils/registration.js +18 -2
- package/dist/cjs/utils/rules.js +39 -11
- package/dist/cjs/utils/schema-adapter.js +25 -2
- package/dist/cjs/utils/synchronous.js +64 -7
- package/dist/cjs/utils/text.js +15 -1
- package/dist/esm/capabilities/index.d.ts +13 -0
- package/dist/esm/capabilities/index.js +13 -0
- package/dist/esm/capabilities/invocation.d.ts +16 -2
- package/dist/esm/capabilities/invocation.js +80 -10
- package/dist/esm/capabilities/model.d.ts +68 -1
- package/dist/esm/capabilities/model.js +126 -13
- package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
- package/dist/esm/capabilities/tool-runtime.js +64 -12
- package/dist/esm/capabilities/tools.d.ts +96 -3
- package/dist/esm/capabilities/tools.js +267 -32
- package/dist/esm/context/assembly.d.ts +13 -2
- package/dist/esm/context/assembly.js +46 -5
- package/dist/esm/context/audit.d.ts +23 -1
- package/dist/esm/context/audit.js +31 -6
- package/dist/esm/context/fragments.d.ts +37 -3
- package/dist/esm/context/fragments.js +54 -11
- package/dist/esm/context/index.d.ts +12 -0
- package/dist/esm/context/index.js +12 -0
- package/dist/esm/context/journal.d.ts +32 -1
- package/dist/esm/context/journal.js +84 -7
- package/dist/esm/context/plan.d.ts +11 -1
- package/dist/esm/context/plan.js +30 -2
- package/dist/esm/diagnostics/catalog.js +11 -3
- package/dist/esm/diagnostics/index.d.ts +30 -2
- package/dist/esm/diagnostics/index.js +149 -29
- package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
- package/dist/esm/diagnostics/sub-flow.js +240 -40
- package/dist/esm/errors.d.ts +22 -2
- package/dist/esm/errors.js +99 -17
- package/dist/esm/execution/branch.d.ts +19 -1
- package/dist/esm/execution/branch.js +20 -4
- package/dist/esm/execution/engine.d.ts +291 -5
- package/dist/esm/execution/engine.js +471 -57
- package/dist/esm/execution/events.d.ts +16 -2
- package/dist/esm/execution/events.js +136 -18
- package/dist/esm/execution/index.d.ts +7 -0
- package/dist/esm/execution/index.js +7 -0
- package/dist/esm/execution/reporting.d.ts +49 -1
- package/dist/esm/execution/reporting.js +75 -6
- package/dist/esm/execution/state.d.ts +126 -10
- package/dist/esm/execution/state.js +161 -22
- package/dist/esm/execution/workflow.d.ts +121 -3
- package/dist/esm/execution/workflow.js +224 -32
- package/dist/esm/index.d.ts +17 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/kits/aggregation.d.ts +34 -2
- package/dist/esm/kits/aggregation.js +45 -3
- package/dist/esm/kits/answering/batch.d.ts +17 -0
- package/dist/esm/kits/answering/batch.js +23 -4
- package/dist/esm/kits/answering/check-result.d.ts +18 -1
- package/dist/esm/kits/answering/check-result.js +31 -8
- package/dist/esm/kits/answering/checks.d.ts +11 -0
- package/dist/esm/kits/answering/checks.js +24 -3
- package/dist/esm/kits/answering/flow.d.ts +25 -2
- package/dist/esm/kits/answering/flow.js +192 -36
- package/dist/esm/kits/answering/index.d.ts +12 -0
- package/dist/esm/kits/answering/index.js +19 -1
- package/dist/esm/kits/answering/tasks.d.ts +32 -1
- package/dist/esm/kits/answering/tasks.js +88 -13
- package/dist/esm/kits/artifacts.d.ts +11 -0
- package/dist/esm/kits/artifacts.js +36 -4
- package/dist/esm/kits/candidates.d.ts +23 -1
- package/dist/esm/kits/candidates.js +47 -5
- package/dist/esm/kits/delivery.d.ts +34 -0
- package/dist/esm/kits/delivery.js +40 -5
- package/dist/esm/kits/durable.d.ts +19 -0
- package/dist/esm/kits/durable.js +155 -31
- package/dist/esm/kits/evidence.d.ts +28 -5
- package/dist/esm/kits/evidence.js +66 -15
- package/dist/esm/kits/family.d.ts +17 -1
- package/dist/esm/kits/family.js +152 -22
- package/dist/esm/kits/index.d.ts +12 -1
- package/dist/esm/kits/index.js +12 -1
- package/dist/esm/kits/inference.d.ts +64 -0
- package/dist/esm/kits/inference.js +104 -16
- package/dist/esm/kits/intents/catalog.d.ts +13 -1
- package/dist/esm/kits/intents/catalog.js +67 -16
- package/dist/esm/kits/intents/index.d.ts +11 -0
- package/dist/esm/kits/intents/index.js +11 -0
- package/dist/esm/kits/intents/registry.d.ts +61 -3
- package/dist/esm/kits/intents/registry.js +188 -43
- package/dist/esm/kits/intents/scopes.d.ts +73 -3
- package/dist/esm/kits/intents/scopes.js +215 -46
- package/dist/esm/kits/interaction/command.d.ts +38 -4
- package/dist/esm/kits/interaction/command.js +140 -36
- package/dist/esm/kits/interaction/commands.d.ts +66 -2
- package/dist/esm/kits/interaction/commands.js +86 -11
- package/dist/esm/kits/interaction/handlers.d.ts +19 -2
- package/dist/esm/kits/interaction/handlers.js +27 -10
- package/dist/esm/kits/interaction/index.d.ts +10 -0
- package/dist/esm/kits/interaction/index.js +10 -0
- package/dist/esm/kits/interaction/transfer.d.ts +39 -2
- package/dist/esm/kits/interaction/transfer.js +80 -14
- package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
- package/dist/esm/kits/knowledge/catalog.js +62 -11
- package/dist/esm/kits/knowledge/index.d.ts +11 -0
- package/dist/esm/kits/knowledge/index.js +16 -1
- package/dist/esm/kits/knowledge/publication.d.ts +15 -1
- package/dist/esm/kits/knowledge/publication.js +99 -23
- package/dist/esm/kits/knowledge/sections.d.ts +31 -1
- package/dist/esm/kits/knowledge/sections.js +33 -4
- package/dist/esm/kits/normalization.d.ts +25 -2
- package/dist/esm/kits/normalization.js +51 -7
- package/dist/esm/kits/policies.d.ts +26 -3
- package/dist/esm/kits/policies.js +79 -15
- package/dist/esm/kits/presentation/events.d.ts +51 -4
- package/dist/esm/kits/presentation/events.js +54 -10
- package/dist/esm/kits/presentation/index.d.ts +12 -0
- package/dist/esm/kits/presentation/index.js +25 -2
- package/dist/esm/kits/presentation/outputs.d.ts +30 -1
- package/dist/esm/kits/presentation/outputs.js +176 -38
- package/dist/esm/kits/presentation/templates.d.ts +32 -3
- package/dist/esm/kits/presentation/templates.js +33 -5
- package/dist/esm/kits/presentation/variants.d.ts +29 -0
- package/dist/esm/kits/presentation/variants.js +31 -2
- package/dist/esm/kits/projection.d.ts +42 -5
- package/dist/esm/kits/projection.js +63 -8
- package/dist/esm/kits/rank-fusion.d.ts +21 -1
- package/dist/esm/kits/rank-fusion.js +28 -5
- package/dist/esm/kits/reflection-log-source.d.ts +28 -1
- package/dist/esm/kits/reflection-log-source.js +89 -16
- package/dist/esm/kits/reflection.d.ts +17 -1
- package/dist/esm/kits/reflection.js +235 -61
- package/dist/esm/kits/retrieval.d.ts +18 -2
- package/dist/esm/kits/retrieval.js +98 -18
- package/dist/esm/kits/search.d.ts +56 -3
- package/dist/esm/kits/search.js +180 -27
- package/dist/esm/kits/text-skills.d.ts +16 -2
- package/dist/esm/kits/text-skills.js +104 -19
- package/dist/esm/kits/tools.d.ts +122 -2
- package/dist/esm/kits/tools.js +416 -74
- package/dist/esm/kits/vector-search.d.ts +47 -1
- package/dist/esm/kits/vector-search.js +51 -17
- package/dist/esm/mock/node.d.ts +7 -0
- package/dist/esm/mock/node.js +7 -1
- package/dist/esm/mock/web.d.ts +7 -0
- package/dist/esm/mock/web.js +7 -1
- package/dist/esm/mock.d.ts +7 -0
- package/dist/esm/mock.js +7 -1
- package/dist/esm/model/binding.d.ts +32 -3
- package/dist/esm/model/binding.js +68 -17
- package/dist/esm/model/call-budget.d.ts +30 -2
- package/dist/esm/model/call-budget.js +45 -4
- package/dist/esm/model/decision-retry.d.ts +10 -1
- package/dist/esm/model/decision-retry.js +19 -1
- package/dist/esm/model/defaults.d.ts +13 -2
- package/dist/esm/model/defaults.js +27 -4
- package/dist/esm/model/index.d.ts +7 -0
- package/dist/esm/model/index.js +7 -0
- package/dist/esm/model/interactions/arguments.d.ts +27 -0
- package/dist/esm/model/interactions/arguments.js +36 -1
- package/dist/esm/model/interactions/json-object.d.ts +7 -1
- package/dist/esm/model/interactions/json-object.js +48 -12
- package/dist/esm/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/model/interactions/native-functions.js +52 -10
- package/dist/esm/model/message-diagnostics.d.ts +17 -1
- package/dist/esm/model/message-diagnostics.js +17 -4
- package/dist/esm/model/options.d.ts +18 -1
- package/dist/esm/model/options.js +9 -1
- package/dist/esm/model/preparation.d.ts +30 -2
- package/dist/esm/model/preparation.js +86 -12
- package/dist/esm/model/runner.d.ts +129 -5
- package/dist/esm/model/runner.js +414 -80
- package/dist/esm/model/selection-transport.d.ts +14 -1
- package/dist/esm/model/selection-transport.js +48 -8
- package/dist/esm/model/settings.d.ts +11 -0
- package/dist/esm/model/settings.js +67 -13
- package/dist/esm/model/token-budget.d.ts +59 -1
- package/dist/esm/model/token-budget.js +69 -11
- package/dist/esm/model/transports.d.ts +20 -2
- package/dist/esm/model/transports.js +59 -6
- package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
- package/dist/esm/structs/capabilities/model.d.ts +27 -0
- package/dist/esm/structs/capabilities/tools.d.ts +38 -0
- package/dist/esm/structs/common.d.ts +62 -2
- package/dist/esm/structs/common.js +11 -0
- package/dist/esm/structs/context/fragments.d.ts +28 -0
- package/dist/esm/structs/context/journal.d.ts +28 -3
- package/dist/esm/structs/context/processing.d.ts +11 -0
- package/dist/esm/structs/debug.d.ts +58 -1
- package/dist/esm/structs/debug.js +34 -5
- package/dist/esm/structs/diagnostics.d.ts +119 -1
- package/dist/esm/structs/errors.d.ts +42 -1
- package/dist/esm/structs/errors.js +26 -1
- package/dist/esm/structs/execution/engine.d.ts +24 -1
- package/dist/esm/structs/execution/events.d.ts +12 -0
- package/dist/esm/structs/execution/workflow.d.ts +71 -0
- package/dist/esm/structs/index.d.ts +11 -1
- package/dist/esm/structs/index.js +11 -1
- package/dist/esm/structs/invocation.d.ts +30 -0
- package/dist/esm/structs/kits/aggregation.d.ts +12 -0
- package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
- package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
- package/dist/esm/structs/kits/answering/state.d.ts +21 -0
- package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
- package/dist/esm/structs/kits/artifacts.d.ts +14 -0
- package/dist/esm/structs/kits/candidates.d.ts +19 -0
- package/dist/esm/structs/kits/delivery.d.ts +22 -0
- package/dist/esm/structs/kits/durable.d.ts +56 -3
- package/dist/esm/structs/kits/durable.js +7 -0
- package/dist/esm/structs/kits/evidence.d.ts +23 -0
- package/dist/esm/structs/kits/family.d.ts +49 -1
- package/dist/esm/structs/kits/family.js +1 -0
- package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
- package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
- package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
- package/dist/esm/structs/kits/interaction.d.ts +64 -0
- package/dist/esm/structs/kits/interaction.js +8 -1
- package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
- package/dist/esm/structs/kits/knowledge-publication.js +1 -0
- package/dist/esm/structs/kits/knowledge.d.ts +39 -2
- package/dist/esm/structs/kits/normalization.d.ts +15 -0
- package/dist/esm/structs/kits/policies.d.ts +25 -1
- package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
- package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
- package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
- package/dist/esm/structs/kits/projection.d.ts +21 -0
- package/dist/esm/structs/kits/reflection.d.ts +61 -2
- package/dist/esm/structs/kits/reflection.js +18 -3
- package/dist/esm/structs/kits/retrieval.d.ts +38 -0
- package/dist/esm/structs/kits/search.d.ts +22 -0
- package/dist/esm/structs/kits/text-skills.d.ts +36 -0
- package/dist/esm/structs/kits/tools.d.ts +87 -0
- package/dist/esm/structs/model/chat-provider.d.ts +24 -1
- package/dist/esm/structs/model/chat-provider.js +6 -0
- package/dist/esm/structs/model/interactions.d.ts +38 -0
- package/dist/esm/structs/model/messages.d.ts +30 -0
- package/dist/esm/structs/model/runtime.d.ts +104 -6
- package/dist/esm/structs/support/capabilities.d.ts +19 -2
- package/dist/esm/structs/support/context-processing.d.ts +88 -9
- package/dist/esm/structs/support/context.d.ts +29 -1
- package/dist/esm/structs/support/model/completion.d.ts +50 -0
- package/dist/esm/structs/support/model/completion.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +13 -1
- package/dist/esm/structs/support/model/messages.d.ts +52 -0
- package/dist/esm/structs/support/model/messages.js +1 -0
- package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
- package/dist/esm/structs/support/model/provider.d.ts +71 -6
- package/dist/esm/structs/support/registration.d.ts +13 -0
- package/dist/esm/structs/support/schema.d.ts +14 -0
- package/dist/esm/structs/support/tools.d.ts +28 -0
- package/dist/esm/structs/support/transport/json.d.ts +16 -0
- package/dist/esm/structs/support/transport/sse.d.ts +15 -0
- package/dist/esm/structs/utils/rules.d.ts +19 -0
- package/dist/esm/support/capabilities.d.ts +25 -2
- package/dist/esm/support/capabilities.js +43 -6
- package/dist/esm/support/context/assembly.d.ts +35 -4
- package/dist/esm/support/context/assembly.js +88 -16
- package/dist/esm/support/context/compression.d.ts +17 -1
- package/dist/esm/support/context/compression.js +48 -6
- package/dist/esm/support/context/fragments.d.ts +6 -0
- package/dist/esm/support/context/fragments.js +6 -0
- package/dist/esm/support/context/history.d.ts +43 -0
- package/dist/esm/support/context/history.js +36 -1
- package/dist/esm/support/context/index.d.ts +13 -2
- package/dist/esm/support/context/index.js +12 -1
- package/dist/esm/support/context/nodes.d.ts +49 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +145 -1
- package/dist/esm/support/context/processing.js +320 -62
- package/dist/esm/support/context/selection-policy.d.ts +42 -2
- package/dist/esm/support/context/selection-policy.js +98 -21
- package/dist/esm/support/context/selection.d.ts +14 -1
- package/dist/esm/support/context/selection.js +61 -10
- package/dist/esm/support/context/snapshot.d.ts +23 -1
- package/dist/esm/support/context/snapshot.js +29 -7
- package/dist/esm/support/context/strategies.d.ts +35 -2
- package/dist/esm/support/context/strategies.js +120 -28
- package/dist/esm/support/index.d.ts +9 -1
- package/dist/esm/support/index.js +9 -1
- package/dist/esm/support/model/capabilities.d.ts +10 -0
- package/dist/esm/support/model/capabilities.js +20 -1
- package/dist/esm/support/model/chat-completions.d.ts +44 -15
- package/dist/esm/support/model/chat-completions.js +92 -20
- package/dist/esm/support/model/children.d.ts +32 -2
- package/dist/esm/support/model/children.js +34 -6
- package/dist/esm/support/model/compatible-provider.d.ts +29 -3
- package/dist/esm/support/model/compatible-provider.js +190 -60
- package/dist/esm/support/model/completion/calls.d.ts +40 -0
- package/dist/esm/support/model/completion/calls.js +58 -0
- package/dist/esm/support/model/completion/default.d.ts +10 -0
- package/dist/esm/support/model/completion/default.js +29 -0
- package/dist/esm/support/model/completion/index.d.ts +10 -0
- package/dist/esm/support/model/completion/index.js +22 -0
- package/dist/esm/support/model/completion/session.d.ts +11 -0
- package/dist/esm/support/model/completion/session.js +99 -0
- package/dist/esm/support/model/index.d.ts +14 -0
- package/dist/esm/support/model/index.js +12 -0
- package/dist/esm/support/model/interactions/index.d.ts +1 -1
- package/dist/esm/support/model/interactions/index.js +12 -1
- package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
- package/dist/esm/support/model/interactions/json-object.js +6 -0
- package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/support/model/interactions/native-functions.js +6 -0
- package/dist/esm/support/model/observer.d.ts +25 -2
- package/dist/esm/support/model/observer.js +32 -6
- package/dist/esm/support/model/preview-rules.d.ts +20 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +15 -1
- package/dist/esm/support/model/reply-preview.js +77 -17
- package/dist/esm/support/model/stage-transport.d.ts +9 -1
- package/dist/esm/support/model/stage-transport.js +33 -7
- package/dist/esm/support/model/strategies.d.ts +24 -2
- package/dist/esm/support/model/strategies.js +75 -14
- package/dist/esm/support/model/transports.d.ts +17 -1
- package/dist/esm/support/model/transports.js +53 -11
- package/dist/esm/support/registration.d.ts +20 -1
- package/dist/esm/support/registration.js +49 -7
- package/dist/esm/support/schema.d.ts +31 -1
- package/dist/esm/support/schema.js +46 -4
- package/dist/esm/support/stream-events.d.ts +22 -1
- package/dist/esm/support/stream-events.js +60 -8
- package/dist/esm/support/tool-runtime.d.ts +6 -0
- package/dist/esm/support/tool-runtime.js +6 -0
- package/dist/esm/support/tools.d.ts +22 -0
- package/dist/esm/support/tools.js +79 -10
- package/dist/esm/support/transport/index.d.ts +7 -0
- package/dist/esm/support/transport/index.js +7 -0
- package/dist/esm/support/transport/json.d.ts +29 -2
- package/dist/esm/support/transport/json.js +28 -4
- package/dist/esm/support/transport/sse.d.ts +31 -1
- package/dist/esm/support/transport/sse.js +25 -2
- package/dist/esm/types.d.ts +9 -1
- package/dist/esm/utils/break-observer.d.ts +27 -2
- package/dist/esm/utils/break-observer.js +20 -2
- package/dist/esm/utils/cancellation.d.ts +56 -5
- package/dist/esm/utils/cancellation.js +77 -9
- package/dist/esm/utils/catalog.d.ts +20 -1
- package/dist/esm/utils/catalog.js +19 -4
- package/dist/esm/utils/debug.d.ts +20 -1
- package/dist/esm/utils/debug.js +14 -2
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/interaction-definition.d.ts +18 -1
- package/dist/esm/utils/interaction-definition.js +26 -6
- package/dist/esm/utils/invocation.d.ts +36 -1
- package/dist/esm/utils/invocation.js +42 -4
- package/dist/esm/utils/model-protocol.d.ts +8 -0
- package/dist/esm/utils/model-protocol.js +20 -1
- package/dist/esm/utils/object.d.ts +16 -0
- package/dist/esm/utils/object.js +16 -0
- package/dist/esm/utils/observer.d.ts +19 -1
- package/dist/esm/utils/observer.js +22 -2
- package/dist/esm/utils/protocol-registry.d.ts +38 -1
- package/dist/esm/utils/protocol-registry.js +47 -4
- package/dist/esm/utils/query-key.d.ts +11 -1
- package/dist/esm/utils/query-key.js +21 -2
- package/dist/esm/utils/registration.d.ts +34 -2
- package/dist/esm/utils/registration.js +18 -2
- package/dist/esm/utils/rules.d.ts +81 -4
- package/dist/esm/utils/rules.js +39 -11
- package/dist/esm/utils/schema-adapter.d.ts +12 -1
- package/dist/esm/utils/schema-adapter.js +25 -2
- package/dist/esm/utils/synchronous.d.ts +60 -4
- package/dist/esm/utils/synchronous.js +64 -7
- package/dist/esm/utils/text.d.ts +15 -1
- package/dist/esm/utils/text.js +15 -1
- package/package.json +23 -3
|
@@ -1,37 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createModelTransport = createModelTransport;
|
|
4
|
+
/**
|
|
5
|
+
* Adapt an interaction adapter plus capability catalog into a transport.
|
|
6
|
+
*
|
|
7
|
+
* This is the seam between "how a provider expresses a call" and "what the core
|
|
8
|
+
* accepts": whatever the wire format, the transport must yield one capability id and
|
|
9
|
+
* one argument object. Capability availability is checked against the catalog captured
|
|
10
|
+
* at preparation time, so a late registration cannot be called.
|
|
11
|
+
*
|
|
12
|
+
* Exports: `createModelTransport`.
|
|
13
|
+
*/
|
|
4
14
|
const synchronous_js_1 = require("../utils/synchronous.js");
|
|
5
15
|
const native_functions_js_1 = require("./interactions/native-functions.js");
|
|
6
16
|
const options_js_1 = require("./options.js");
|
|
7
17
|
const model_protocol_js_1 = require("../utils/model-protocol.js");
|
|
8
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Compose a registered selection transport.
|
|
20
|
+
*
|
|
21
|
+
* The capability source may be a static catalog or a function of the stage id; the
|
|
22
|
+
* resulting definitions are captured when `prepare` runs and are used both to build
|
|
23
|
+
* the instruction and to reject unknown capability ids at finish time.
|
|
24
|
+
*
|
|
25
|
+
* `requireStrictArguments` is a registration-time assertion: a transport cannot demand
|
|
26
|
+
* strict arguments from an adapter that does not support them.
|
|
27
|
+
*
|
|
28
|
+
* @param registration - Adapter, capability source, options and the transport id.
|
|
29
|
+
* @returns A frozen transport definition whose result is the resolved capability output.
|
|
30
|
+
* @throws TypeError When strict arguments are unsupported or preparation is invalid.
|
|
31
|
+
*/
|
|
9
32
|
function createModelTransport(registration) {
|
|
10
33
|
const adapter = registration.adapter ?? native_functions_js_1.nativeFunctionInteraction;
|
|
11
34
|
if (registration.requireStrictArguments && !adapter.features.strictArguments)
|
|
12
35
|
throw new TypeError(`Model interaction does not support strict arguments: ${adapter.id}`);
|
|
13
36
|
const source = registration.capabilities, createSource = typeof source === 'function' ? source.bind(registration) : undefined;
|
|
14
37
|
const prepare = adapter.prepare.bind(adapter), options = Object.freeze((0, options_js_1.snapshotModelOptions)(registration.options));
|
|
15
|
-
return Object.freeze({
|
|
16
|
-
|
|
38
|
+
return Object.freeze({
|
|
39
|
+
id: registration.id,
|
|
40
|
+
prepare(stageId) {
|
|
41
|
+
const catalog = createSource
|
|
42
|
+
? (0, synchronous_js_1.synchronous)(createSource(stageId), 'Model capability sources must be synchronous')
|
|
43
|
+
: source;
|
|
17
44
|
const definitions = [...catalog.values()];
|
|
18
45
|
if (!definitions.length)
|
|
19
46
|
throw new TypeError('Model stage requires registered capabilities');
|
|
20
|
-
const capabilityIds = new Set(definitions.map(capability => capability.id));
|
|
47
|
+
const capabilityIds = new Set(definitions.map((capability) => capability.id));
|
|
21
48
|
const prepared = (0, synchronous_js_1.synchronous)(prepare(definitions), 'Model interaction preparation must be synchronous');
|
|
22
49
|
const createResponse = prepared.createResponse.bind(prepared), resolve = catalog.resolve.bind(catalog);
|
|
23
|
-
return {
|
|
50
|
+
return {
|
|
51
|
+
options: { ...options, ...(0, options_js_1.snapshotModelOptions)(prepared.options) },
|
|
52
|
+
schemaChars: prepared.schemaChars,
|
|
53
|
+
instruction: prepared.instruction,
|
|
24
54
|
createResponse() {
|
|
25
55
|
const buffer = createResponse();
|
|
26
56
|
let call;
|
|
27
|
-
return {
|
|
57
|
+
return {
|
|
58
|
+
get outputChars() {
|
|
59
|
+
return buffer.outputChars;
|
|
60
|
+
},
|
|
61
|
+
get call() {
|
|
62
|
+
return call;
|
|
63
|
+
},
|
|
64
|
+
push: buffer.push.bind(buffer),
|
|
65
|
+
finish() {
|
|
28
66
|
const selection = (0, synchronous_js_1.synchronous)(buffer.finish(), 'Model selection parsers must be synchronous');
|
|
29
67
|
call = selection.call;
|
|
30
68
|
if (!capabilityIds.has(selection.capabilityId))
|
|
31
69
|
(0, model_protocol_js_1.modelProtocolError)('Model capability is unavailable in this prepared call');
|
|
32
70
|
return (0, synchronous_js_1.synchronous)(resolve(selection, { stageId }), 'Model result parsers must be synchronous');
|
|
33
|
-
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
34
73
|
},
|
|
35
74
|
};
|
|
36
|
-
}
|
|
75
|
+
},
|
|
76
|
+
});
|
|
37
77
|
}
|
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveModelSettings = resolveModelSettings;
|
|
4
|
+
/**
|
|
5
|
+
* Validation and defaulting of model runner settings.
|
|
6
|
+
*
|
|
7
|
+
* This is the single place where App-supplied settings become trusted: removed option
|
|
8
|
+
* names are rejected with a migration hint, defaults are applied, and every numeric
|
|
9
|
+
* limit is range-checked before the runner binds its provider.
|
|
10
|
+
*
|
|
11
|
+
* Exports: `resolveModelSettings`.
|
|
12
|
+
*/
|
|
4
13
|
const defaults_js_1 = require("./defaults.js");
|
|
5
14
|
const rules_js_1 = require("../utils/rules.js");
|
|
6
15
|
const errors_js_1 = require("../errors.js");
|
|
16
|
+
/**
|
|
17
|
+
* Validate options and fill in baseline defaults.
|
|
18
|
+
*
|
|
19
|
+
* Legacy names (`config`, `ports`, `observe`, `signal`, `contextPolicy` and friends) are
|
|
20
|
+
* rejected rather than ignored, because silently dropping them would change behavior.
|
|
21
|
+
* Returned limits are frozen; ports keep live App callbacks with their receivers bound.
|
|
22
|
+
*
|
|
23
|
+
* @param options - Runner options as supplied by the App.
|
|
24
|
+
* @returns The bound provider, frozen runtime config, input limit, ports and token limit.
|
|
25
|
+
* @throws TypeError When any option is invalid, removed or out of range.
|
|
26
|
+
*/
|
|
7
27
|
function resolveModelSettings(options) {
|
|
8
28
|
const provider = options.provider;
|
|
9
29
|
const stream = provider?.stream;
|
|
@@ -14,8 +34,16 @@ function resolveModelSettings(options) {
|
|
|
14
34
|
};
|
|
15
35
|
(0, rules_js_1.breakWhile)([
|
|
16
36
|
{ occur: typeof stream !== 'function', error: () => invalid('provider.stream is required') },
|
|
17
|
-
{
|
|
18
|
-
|
|
37
|
+
{
|
|
38
|
+
occur: 'contextPolicy' in options ||
|
|
39
|
+
'contextCompressors' in options ||
|
|
40
|
+
'contextSelectors' in options,
|
|
41
|
+
error: () => invalid('Configure context processing with explicit Workflow nodes'),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
occur: 'config' in options || 'ports' in options || 'observe' in options,
|
|
45
|
+
error: () => invalid('Use named model settings and execution, sink, observe or errors'),
|
|
46
|
+
},
|
|
19
47
|
]);
|
|
20
48
|
const defaulted = (value, fallback) => value === undefined ? fallback : value;
|
|
21
49
|
const config = {
|
|
@@ -25,8 +53,10 @@ function resolveModelSettings(options) {
|
|
|
25
53
|
usage: options.usage,
|
|
26
54
|
};
|
|
27
55
|
const ports = {
|
|
28
|
-
transports: options.transports,
|
|
29
|
-
|
|
56
|
+
transports: options.transports,
|
|
57
|
+
diagnostics: options.execution?.diagnostics,
|
|
58
|
+
maxSchemaChars: options.maxSchemaChars,
|
|
59
|
+
tokenBudget: options.tokenBudget,
|
|
30
60
|
onOutput: options.sink?.output?.bind(options.sink),
|
|
31
61
|
inputBudgetError: options.errors?.inputBudget?.bind(options.errors),
|
|
32
62
|
outputBudgetError: options.errors?.outputBudget?.bind(options.errors),
|
|
@@ -35,15 +65,39 @@ function resolveModelSettings(options) {
|
|
|
35
65
|
ports.maxSchemaChars = defaulted(ports.maxSchemaChars, defaults_js_1.modelRunnerDefaults.maxSchemaChars);
|
|
36
66
|
const maxInputChars = defaulted(options.maxInputChars, defaults_js_1.modelRunnerDefaults.maxInputChars);
|
|
37
67
|
const maxOutputTokens = defaulted(options.maxOutputTokens, defaults_js_1.modelRunnerDefaults.maxOutputTokens);
|
|
38
|
-
const integer = (value, minimum, infinity = false) => infinity && value === Infinity
|
|
39
|
-
|
|
68
|
+
const integer = (value, minimum, infinity = false) => (infinity && value === Infinity) ||
|
|
69
|
+
(typeof value === 'number' && Number.isSafeInteger(value) && value >= minimum);
|
|
40
70
|
(0, rules_js_1.breakWhile)([
|
|
41
|
-
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
{
|
|
46
|
-
|
|
71
|
+
{
|
|
72
|
+
occur: !integer(config.maxCalls, 0),
|
|
73
|
+
error: () => invalid('maxCalls must be a nonnegative safe integer'),
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
occur: !integer(config.callTimeoutMs, 1) || config.callTimeoutMs > 2147483647,
|
|
77
|
+
error: () => invalid('callTimeoutMs must be a positive supported timeout'),
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
occur: !integer(maxInputChars, 0, true),
|
|
81
|
+
error: () => invalid('maxInputChars must be a nonnegative safe integer or Infinity'),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
occur: config.maxOutputChars !== undefined && !integer(config.maxOutputChars, 0, true),
|
|
85
|
+
error: () => invalid('maxOutputChars must be a nonnegative safe integer or Infinity'),
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
occur: ports.maxSchemaChars !== undefined && !integer(ports.maxSchemaChars, 1),
|
|
89
|
+
error: () => invalid('maxSchemaChars must be a positive safe integer'),
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
occur: !integer(maxOutputTokens, 1),
|
|
93
|
+
error: () => invalid('maxOutputTokens must be a positive safe integer'),
|
|
94
|
+
},
|
|
47
95
|
]);
|
|
48
|
-
return {
|
|
96
|
+
return {
|
|
97
|
+
provider: Object.freeze({ stream: stream.bind(provider) }),
|
|
98
|
+
maxOutputTokens,
|
|
99
|
+
config: Object.freeze(config),
|
|
100
|
+
maxInputChars,
|
|
101
|
+
ports,
|
|
102
|
+
};
|
|
49
103
|
}
|
|
@@ -8,34 +8,92 @@ exports.modelInputMessages = modelInputMessages;
|
|
|
8
8
|
const errors_js_1 = require("../structs/errors.js");
|
|
9
9
|
const rules_js_1 = require("../utils/rules.js");
|
|
10
10
|
const invalid = (message) => new errors_js_1.ValidationError([{ code: 'MODEL_TOKEN_BUDGET', message }]);
|
|
11
|
+
/**
|
|
12
|
+
* Validate a host-supplied token budget contract.
|
|
13
|
+
*
|
|
14
|
+
* @param budget - Budget to check: counter id, context window, optional safety margin, counter.
|
|
15
|
+
* @throws ValidationError When any field is missing or out of range.
|
|
16
|
+
*/
|
|
11
17
|
function validateModelTokenBudget(budget) {
|
|
12
|
-
(0, rules_js_1.breakWhile)(!budget.counterId ||
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
(0, rules_js_1.breakWhile)(!budget.counterId ||
|
|
19
|
+
!Number.isSafeInteger(budget.contextWindowTokens) ||
|
|
20
|
+
budget.contextWindowTokens < 1 ||
|
|
21
|
+
!Number.isSafeInteger(budget.safetyMarginTokens ?? 0) ||
|
|
22
|
+
(budget.safetyMarginTokens ?? 0) < 0 ||
|
|
23
|
+
typeof budget.countTokens !== 'function', invalid('Invalid model token budget'));
|
|
15
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Compute how many input tokens remain for one call.
|
|
27
|
+
*
|
|
28
|
+
* The requested output tokens and the safety margin are subtracted from the context
|
|
29
|
+
* window, so a call that reserves more than the window is rejected before counting.
|
|
30
|
+
*
|
|
31
|
+
* @param budget - Declared context window and safety margin.
|
|
32
|
+
* @param outputTokens - Tokens reserved for the completion.
|
|
33
|
+
* @returns The positive input token allowance.
|
|
34
|
+
* @throws ValidationError When the reservation is invalid or leaves no input capacity.
|
|
35
|
+
*/
|
|
16
36
|
function modelInputTokenLimit(budget, outputTokens) {
|
|
17
37
|
const limit = budget.contextWindowTokens - outputTokens - (budget.safetyMarginTokens ?? 0);
|
|
18
38
|
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(outputTokens) || outputTokens < 1 || limit < 1, invalid('No input capacity after reserving output and safety margin'));
|
|
19
39
|
return limit;
|
|
20
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Count the tokens of a prepared request.
|
|
43
|
+
*
|
|
44
|
+
* The counter observes a request, so both messages and declarations are cloned before
|
|
45
|
+
* being handed over: accidental mutations by the counter must not rewrite the provider
|
|
46
|
+
* input. The returned count must itself be a nonnegative safe integer.
|
|
47
|
+
*
|
|
48
|
+
* @param budget - Budget supplying the counter.
|
|
49
|
+
* @param messages - Effective messages, including the merged instruction.
|
|
50
|
+
* @param options - Function declarations and JSON mode as they will be sent.
|
|
51
|
+
* @returns The token count reported by the host counter.
|
|
52
|
+
* @throws ValidationError When the counter returns an unusable number.
|
|
53
|
+
*/
|
|
21
54
|
function countModelInput(budget, messages, options) {
|
|
22
55
|
// A counter observes a request; accidental mutations must not rewrite the provider input.
|
|
23
|
-
const snapshot = messages.map(message => ({
|
|
24
|
-
...
|
|
56
|
+
const snapshot = messages.map((message) => ({
|
|
57
|
+
...message,
|
|
58
|
+
...(message.images ? { images: message.images.map((image) => ({ ...image })) } : {}),
|
|
25
59
|
}));
|
|
26
|
-
const count = budget.countTokens({
|
|
27
|
-
|
|
60
|
+
const count = budget.countTokens({
|
|
61
|
+
messages: snapshot,
|
|
62
|
+
functions: options.functions ? structuredClone(options.functions) : undefined,
|
|
63
|
+
json: options.json,
|
|
64
|
+
});
|
|
28
65
|
(0, rules_js_1.breakWhile)(!Number.isSafeInteger(count) || count < 0, invalid('Token counter must return a nonnegative integer'));
|
|
29
66
|
return count;
|
|
30
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Enforce the measured input against its token allowance.
|
|
70
|
+
*
|
|
71
|
+
* @param count - Measured input tokens.
|
|
72
|
+
* @param limit - Allowance from `modelInputTokenLimit`.
|
|
73
|
+
* @throws ValidationError When the input exceeds the allowance.
|
|
74
|
+
*/
|
|
31
75
|
function enforceModelInputTokens(count, limit) {
|
|
32
76
|
(0, rules_js_1.breakWhile)(count > limit, invalid(`Model input uses ${count} tokens; available input budget is ${limit}`));
|
|
33
77
|
}
|
|
34
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Merge a transport instruction into the message list.
|
|
80
|
+
*
|
|
81
|
+
* An existing system message keeps its position and receives the instruction as a new
|
|
82
|
+
* paragraph; otherwise a system message is prepended. Reusing the same function for
|
|
83
|
+
* preflight measurement and the provider call is what makes instructions count exactly
|
|
84
|
+
* once.
|
|
85
|
+
*
|
|
86
|
+
* @param base - Caller messages; not mutated.
|
|
87
|
+
* @param instruction - Optional instruction to merge.
|
|
88
|
+
* @returns A new message array.
|
|
89
|
+
*/
|
|
35
90
|
function modelInputMessages(base, instruction) {
|
|
36
91
|
if (!instruction)
|
|
37
92
|
return [...base];
|
|
38
|
-
const index = base.findIndex(message => message.role === 'system');
|
|
39
|
-
return index < 0
|
|
40
|
-
|
|
93
|
+
const index = base.findIndex((message) => message.role === 'system');
|
|
94
|
+
return index < 0
|
|
95
|
+
? [{ role: 'system', content: instruction }, ...base]
|
|
96
|
+
: base.map((message, position) => position === index
|
|
97
|
+
? { ...message, content: `${message.content}\n\n${instruction}` }
|
|
98
|
+
: message);
|
|
41
99
|
}
|
|
@@ -2,23 +2,76 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPlainTextTransport = createPlainTextTransport;
|
|
4
4
|
exports.normalizeModelTransport = normalizeModelTransport;
|
|
5
|
+
/**
|
|
6
|
+
* Transport definitions and the built-in plain-text transport.
|
|
7
|
+
*
|
|
8
|
+
* A transport owns the wire-level request shape (options, declarations, instruction)
|
|
9
|
+
* and the collector that decodes streamed parts into one result. The runner never
|
|
10
|
+
* interprets provider output itself, so adding a protocol means adding a transport
|
|
11
|
+
* rather than branching in the core.
|
|
12
|
+
*
|
|
13
|
+
* Exports: `createPlainTextTransport` and `normalizeModelTransport`.
|
|
14
|
+
*/
|
|
5
15
|
const synchronous_js_1 = require("../utils/synchronous.js");
|
|
6
16
|
const errors_js_1 = require("../structs/errors.js");
|
|
7
17
|
const options_js_1 = require("./options.js");
|
|
18
|
+
/**
|
|
19
|
+
* Collector that concatenates plain text into one decoded value.
|
|
20
|
+
*
|
|
21
|
+
* A non-string part means the provider emitted a native call event, which a plain-text
|
|
22
|
+
* stage cannot represent; that is reported as a protocol violation instead of being
|
|
23
|
+
* stringified.
|
|
24
|
+
*
|
|
25
|
+
* @param decode - Final conversion from accumulated raw text to the result.
|
|
26
|
+
* @returns A collector reporting the buffered character count.
|
|
27
|
+
*/
|
|
8
28
|
function textResponse(decode) {
|
|
9
29
|
let raw = '';
|
|
10
|
-
return {
|
|
30
|
+
return {
|
|
31
|
+
get outputChars() {
|
|
32
|
+
return raw.length;
|
|
33
|
+
},
|
|
34
|
+
push(part) {
|
|
11
35
|
if (typeof part !== 'string')
|
|
12
|
-
throw new errors_js_1.ValidationError([
|
|
36
|
+
throw new errors_js_1.ValidationError([
|
|
37
|
+
{ code: 'MODEL_PROTOCOL', message: 'Text transport does not accept model calls' },
|
|
38
|
+
]);
|
|
13
39
|
raw += part;
|
|
14
|
-
},
|
|
40
|
+
},
|
|
41
|
+
finish: () => (0, synchronous_js_1.synchronous)(decode(raw), 'Model result parsers must be synchronous'),
|
|
42
|
+
};
|
|
15
43
|
}
|
|
16
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Build a transport that expects a single plain-text completion.
|
|
46
|
+
*
|
|
47
|
+
* JSON mode is forced off because a text stage has no envelope to parse, and the final
|
|
48
|
+
* text is trimmed so transport-specific whitespace never reaches the caller.
|
|
49
|
+
*
|
|
50
|
+
* @param id - Unique transport id, also used as the typed handle in `ModelRunner`.
|
|
51
|
+
* @param options - Optional request options; only `temperature` is honored.
|
|
52
|
+
* @returns A frozen transport definition.
|
|
53
|
+
*/
|
|
17
54
|
function createPlainTextTransport(id, options = {}) {
|
|
18
55
|
const settings = Object.freeze({ ...(0, options_js_1.snapshotModelOptions)(options), json: false });
|
|
19
|
-
return Object.freeze({
|
|
56
|
+
return Object.freeze({
|
|
57
|
+
id,
|
|
58
|
+
prepare: (_stageId) => ({
|
|
59
|
+
options: settings,
|
|
60
|
+
schemaChars: 0,
|
|
61
|
+
createResponse: () => textResponse((raw) => raw.trim()),
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
20
64
|
}
|
|
21
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* Freeze a transport and pin its preparation receiver.
|
|
67
|
+
*
|
|
68
|
+
* Binding at registration means a later caller cannot swap the definition's identity
|
|
69
|
+
* or detach `prepare` from the object that specializes it.
|
|
70
|
+
*
|
|
71
|
+
* @param definition - Transport supplied by the App or by a factory.
|
|
72
|
+
* @returns A frozen definition with a bound `prepare`.
|
|
73
|
+
* @throws TypeError When the id is blank or `prepare` is missing.
|
|
74
|
+
*/
|
|
22
75
|
function normalizeModelTransport(definition) {
|
|
23
76
|
if (!definition.id?.trim() || typeof definition.prepare !== 'function')
|
|
24
77
|
throw new TypeError('Invalid model transport');
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Package-wide vocabulary shared by every agent-core contract.
|
|
4
|
+
*
|
|
5
|
+
* These aliases and envelopes are the neutral layer between App-owned business types and the
|
|
6
|
+
* Core runtime modules: identifiers stay opaque, application identities are deliberately absent,
|
|
7
|
+
* and every catalog or result shape is read-only so a registered snapshot cannot be mutated later.
|
|
8
|
+
*
|
|
9
|
+
* Exports: `Id`, `TimestampMs`, `DurationMs`, `Observer`, `AsyncSink`, `InvocationStatus`,
|
|
10
|
+
* `JsonSchema`, `MaybePromise`, `SchemaAdapter`, `Issue`, `CheckResult`, `ReadonlyCatalog`,
|
|
11
|
+
* `Registry`, `ExecutionOptions`, `ExecutionContext`, `OperationContext`, `SearchHit`.
|
|
12
|
+
*/
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,12 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Self-reported execution detail supplied by App nodes and tools.
|
|
4
|
+
*
|
|
5
|
+
* The data here is optional evidence of what an App chose to report, never proof that Core
|
|
6
|
+
* performed the work, and it is collected only through the diagnostic context that owns the
|
|
7
|
+
* current node visit. The status catalog below is the single source of truth for legal reported
|
|
8
|
+
* statuses, their terminal flag and the transitions that `fix` may apply.
|
|
9
|
+
*
|
|
10
|
+
* Exports: `reportedStepStatusCatalog`, `reportedStepStatuses`, `ReportedStepStatus`,
|
|
11
|
+
* `ReportedStep`, `SubFlowValue`, `RecordedSubStep`, `SubFlowStepInput`, `SubFlowStepFix`,
|
|
12
|
+
* `SubFlowLogger`, `NodeReportingContext`, `SubStepProgress`, `DebugStepsOutput`.
|
|
13
|
+
*/
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.reportedStepStatuses = exports.reportedStepStatusCatalog = void 0;
|
|
4
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Legal self-reported step statuses and their transitions.
|
|
18
|
+
*
|
|
19
|
+
* `terminal: true` means the step is finished and its status can no longer change; `next` lists the
|
|
20
|
+
* statuses a later `fix` may assign to a non-terminal step.
|
|
21
|
+
*/
|
|
5
22
|
exports.reportedStepStatusCatalog = {
|
|
6
|
-
|
|
7
|
-
|
|
23
|
+
/** No status reported yet; only `fix` uses this as an intermediate state. */
|
|
24
|
+
unknown: {
|
|
25
|
+
terminal: false,
|
|
26
|
+
next: ['unknown', 'planned', 'running', 'success', 'error', 'cancelled', 'skipped'],
|
|
27
|
+
},
|
|
28
|
+
/** Declared by the node but not started. */
|
|
29
|
+
planned: {
|
|
30
|
+
terminal: false,
|
|
31
|
+
next: ['planned', 'running', 'success', 'error', 'cancelled', 'skipped'],
|
|
32
|
+
},
|
|
33
|
+
/** Started and still active; may only stay running or finish. */
|
|
8
34
|
running: { terminal: false, next: ['running', 'success', 'error', 'cancelled'] },
|
|
9
|
-
success: { terminal: true, next: [] },
|
|
10
|
-
|
|
35
|
+
success: { terminal: true, next: [] },
|
|
36
|
+
error: { terminal: true, next: [] },
|
|
37
|
+
cancelled: { terminal: true, next: [] },
|
|
38
|
+
skipped: { terminal: true, next: [] },
|
|
11
39
|
};
|
|
40
|
+
/** Frozen list of reported statuses in catalog order, used for membership validation. */
|
|
12
41
|
exports.reportedStepStatuses = Object.freeze(Object.keys(exports.reportedStepStatusCatalog));
|
|
@@ -1,20 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WorkflowContractError = exports.BudgetError = exports.ValidationError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Rejected input or output that failed one or more registered checks.
|
|
6
|
+
*
|
|
7
|
+
* The message is fixed; consumers should read `issues` for the actual reasons.
|
|
8
|
+
*/
|
|
4
9
|
class ValidationError extends Error {
|
|
5
10
|
issues;
|
|
11
|
+
/**
|
|
12
|
+
* @param issues - Validation problems, stored verbatim and exposed to the catcher.
|
|
13
|
+
*/
|
|
6
14
|
constructor(issues) {
|
|
7
15
|
super('Agent validation failed');
|
|
8
16
|
this.issues = issues;
|
|
9
17
|
}
|
|
10
18
|
}
|
|
11
19
|
exports.ValidationError = ValidationError;
|
|
20
|
+
/**
|
|
21
|
+
* A configured allowance (rounds, model calls, attempts) is exhausted.
|
|
22
|
+
*
|
|
23
|
+
* The optional message states which allowance ran out; `code` is the stable marker.
|
|
24
|
+
*/
|
|
12
25
|
class BudgetError extends Error {
|
|
13
26
|
code = 'BUDGET';
|
|
14
27
|
}
|
|
15
28
|
exports.BudgetError = BudgetError;
|
|
29
|
+
/**
|
|
30
|
+
* The workflow definition violates Core's execution contract, as opposed to failing business logic.
|
|
31
|
+
*
|
|
32
|
+
* Examples: unknown model binding, asynchronous predicate, unmatched route, missing state field.
|
|
33
|
+
* It is a programming error, so callers should not treat it as retryable.
|
|
34
|
+
*/
|
|
16
35
|
class WorkflowContractError extends Error {
|
|
17
36
|
code = 'WORKFLOW_CONTRACT';
|
|
18
|
-
|
|
37
|
+
/**
|
|
38
|
+
* @param message - Human-readable contract violation; preserved by `Error`.
|
|
39
|
+
*/
|
|
40
|
+
constructor(message) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.name = 'WorkflowContractError';
|
|
43
|
+
}
|
|
19
44
|
}
|
|
20
45
|
exports.WorkflowContractError = WorkflowContractError;
|
|
@@ -14,7 +14,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Public entry of the structs layer.
|
|
19
|
+
*
|
|
20
|
+
* Structs are the shape-only half of agent-core: declarations and frozen constant catalogs that the
|
|
21
|
+
* runtime modules (`capabilities`, `context`, `execution`, `model`, `kits`, `support`) both
|
|
22
|
+
* implement and consume. Runtime classes declared here only describe shape or initialize fields,
|
|
23
|
+
* so importing this barrel never starts execution.
|
|
24
|
+
*
|
|
25
|
+
* Exports: a curated re-export of the shared vocabulary, error classes, diagnostics/event
|
|
26
|
+
* envelopes, model and workflow contracts, and the optional Kit protocol definitions.
|
|
27
|
+
*/
|
|
18
28
|
__exportStar(require("./capabilities/model.js"), exports);
|
|
19
29
|
__exportStar(require("./model/chat-provider.js"), exports);
|
|
20
30
|
__exportStar(require("./context/fragments.js"), exports);
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.durableReplayPolicies = exports.durableStatuses = void 0;
|
|
4
|
+
/** Checkpoint lifecycle values, in the order a task passes through them. */
|
|
4
5
|
exports.durableStatuses = ['ready', 'running', 'completed', 'cancelled'];
|
|
6
|
+
/**
|
|
7
|
+
* How an interrupted step is resumed.
|
|
8
|
+
*
|
|
9
|
+
* `safe` re-runs `run` (the step must tolerate repeating its side effect); `reconcile` requires a
|
|
10
|
+
* `reconcile` handler because the previous attempt may have taken effect already.
|
|
11
|
+
*/
|
|
5
12
|
exports.durableReplayPolicies = ['safe', 'reconcile'];
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.INTERACTION_CATEGORIES = void 0;
|
|
4
|
-
|
|
4
|
+
/** Frozen list of accepted categories, used for validation and enumeration. */
|
|
5
|
+
exports.INTERACTION_CATEGORIES = Object.freeze([
|
|
6
|
+
'query',
|
|
7
|
+
'action',
|
|
8
|
+
'presentation',
|
|
9
|
+
'input',
|
|
10
|
+
'receipt',
|
|
11
|
+
]);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.knowledgePublicationOperations = void 0;
|
|
4
|
+
/** Operation names accepted by the publication `authorize` hook. */
|
|
4
5
|
exports.knowledgePublicationOperations = ['propose', 'publish', 'reject'];
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.reflectionFindingKinds = exports.reflectionIdentityFields = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
'
|
|
4
|
+
/** Identity fields an evidence item may project from the original diagnostic identity. */
|
|
5
|
+
exports.reflectionIdentityFields = Object.freeze([
|
|
6
|
+
'spanId',
|
|
7
|
+
'parentSpanId',
|
|
8
|
+
'invocationId',
|
|
9
|
+
'parentInvocationId',
|
|
10
|
+
'agentId',
|
|
11
|
+
'branchId',
|
|
12
|
+
'agentVersionId',
|
|
13
|
+
'parentBranchId',
|
|
14
|
+
'parentAgentVersionId',
|
|
15
|
+
'forkPointId',
|
|
16
|
+
'workflowInvocationId',
|
|
17
|
+
'workflowNodeId',
|
|
18
|
+
'nodeRole',
|
|
19
|
+
'definitionId',
|
|
20
|
+
]);
|
|
21
|
+
/** Allowed finding kinds, from observed facts to advisory conclusions. */
|
|
7
22
|
exports.reflectionFindingKinds = ['observed', 'hypothesis', 'recommendation'];
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChatProvider = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Streaming model provider.
|
|
6
|
+
*
|
|
7
|
+
* Implementations must stop producing when `context.signal` aborts and should surface transport
|
|
8
|
+
* failures by rejecting the iteration rather than ending it silently.
|
|
9
|
+
*/
|
|
4
10
|
class ChatProvider {
|
|
5
11
|
}
|
|
6
12
|
exports.ChatProvider = ChatProvider;
|