@jangts/agent-core 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/development/docs/api/reference.md +1907 -1874
- package/development/docs/api/support.md +27 -0
- package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
- package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
- package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
- package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
- package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
- package/development/skills/agent-core-app/scripts/resources.mjs +45 -17
- package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
- package/development/skills/agent-core-app/templates/catalog.json +36 -22
- package/dist/cjs/capabilities/index.js +13 -0
- package/dist/cjs/capabilities/invocation.js +80 -10
- package/dist/cjs/capabilities/model.js +126 -13
- package/dist/cjs/capabilities/tool-runtime.js +64 -12
- package/dist/cjs/capabilities/tools.js +266 -31
- package/dist/cjs/context/assembly.js +46 -5
- package/dist/cjs/context/audit.js +31 -6
- package/dist/cjs/context/fragments.js +54 -11
- package/dist/cjs/context/index.js +12 -0
- package/dist/cjs/context/journal.js +84 -7
- package/dist/cjs/context/plan.js +30 -2
- package/dist/cjs/diagnostics/catalog.js +11 -3
- package/dist/cjs/diagnostics/index.js +149 -29
- package/dist/cjs/diagnostics/sub-flow.js +240 -40
- package/dist/cjs/errors.js +99 -17
- package/dist/cjs/execution/branch.js +20 -4
- package/dist/cjs/execution/engine.js +470 -56
- package/dist/cjs/execution/events.js +136 -18
- package/dist/cjs/execution/index.js +7 -0
- package/dist/cjs/execution/reporting.js +75 -6
- package/dist/cjs/execution/state.js +161 -22
- package/dist/cjs/execution/workflow.js +224 -32
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/kits/aggregation.js +45 -3
- package/dist/cjs/kits/answering/batch.js +23 -4
- package/dist/cjs/kits/answering/check-result.js +31 -8
- package/dist/cjs/kits/answering/checks.js +24 -3
- package/dist/cjs/kits/answering/flow.js +192 -36
- package/dist/cjs/kits/answering/index.js +19 -1
- package/dist/cjs/kits/answering/tasks.js +88 -13
- package/dist/cjs/kits/artifacts.js +36 -4
- package/dist/cjs/kits/candidates.js +47 -5
- package/dist/cjs/kits/delivery.js +40 -5
- package/dist/cjs/kits/durable.js +155 -31
- package/dist/cjs/kits/evidence.js +66 -15
- package/dist/cjs/kits/family.js +152 -22
- package/dist/cjs/kits/index.js +12 -1
- package/dist/cjs/kits/inference.js +104 -16
- package/dist/cjs/kits/intents/catalog.js +67 -16
- package/dist/cjs/kits/intents/index.js +11 -0
- package/dist/cjs/kits/intents/registry.js +188 -43
- package/dist/cjs/kits/intents/scopes.js +215 -46
- package/dist/cjs/kits/interaction/command.js +140 -36
- package/dist/cjs/kits/interaction/commands.js +86 -11
- package/dist/cjs/kits/interaction/handlers.js +27 -10
- package/dist/cjs/kits/interaction/index.js +10 -0
- package/dist/cjs/kits/interaction/transfer.js +80 -14
- package/dist/cjs/kits/knowledge/catalog.js +62 -11
- package/dist/cjs/kits/knowledge/index.js +16 -1
- package/dist/cjs/kits/knowledge/publication.js +99 -23
- package/dist/cjs/kits/knowledge/sections.js +33 -4
- package/dist/cjs/kits/normalization.js +51 -7
- package/dist/cjs/kits/policies.js +79 -15
- package/dist/cjs/kits/presentation/events.js +54 -10
- package/dist/cjs/kits/presentation/index.js +24 -1
- package/dist/cjs/kits/presentation/outputs.js +176 -38
- package/dist/cjs/kits/presentation/templates.js +33 -5
- package/dist/cjs/kits/presentation/variants.js +31 -2
- package/dist/cjs/kits/projection.js +63 -8
- package/dist/cjs/kits/rank-fusion.js +27 -4
- package/dist/cjs/kits/reflection-log-source.js +89 -16
- package/dist/cjs/kits/reflection.js +234 -60
- package/dist/cjs/kits/retrieval.js +98 -18
- package/dist/cjs/kits/search.js +180 -27
- package/dist/cjs/kits/text-skills.js +104 -19
- package/dist/cjs/kits/tools.js +415 -74
- package/dist/cjs/kits/vector-search.js +50 -16
- package/dist/cjs/mock/node.js +7 -1
- package/dist/cjs/mock/web.js +7 -1
- package/dist/cjs/mock.js +7 -1
- package/dist/cjs/model/binding.js +68 -17
- package/dist/cjs/model/call-budget.js +45 -4
- package/dist/cjs/model/decision-retry.js +19 -1
- package/dist/cjs/model/defaults.js +27 -4
- package/dist/cjs/model/index.js +7 -0
- package/dist/cjs/model/interactions/arguments.js +36 -1
- package/dist/cjs/model/interactions/json-object.js +48 -12
- package/dist/cjs/model/interactions/native-functions.js +52 -10
- package/dist/cjs/model/message-diagnostics.js +17 -4
- package/dist/cjs/model/options.js +9 -1
- package/dist/cjs/model/preparation.js +86 -12
- package/dist/cjs/model/runner.js +413 -79
- package/dist/cjs/model/selection-transport.js +48 -8
- package/dist/cjs/model/settings.js +67 -13
- package/dist/cjs/model/token-budget.js +69 -11
- package/dist/cjs/model/transports.js +59 -6
- package/dist/cjs/structs/common.js +11 -0
- package/dist/cjs/structs/debug.js +34 -5
- package/dist/cjs/structs/errors.js +26 -1
- package/dist/cjs/structs/index.js +11 -1
- package/dist/cjs/structs/kits/durable.js +7 -0
- package/dist/cjs/structs/kits/family.js +1 -0
- package/dist/cjs/structs/kits/interaction.js +8 -1
- package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
- package/dist/cjs/structs/kits/reflection.js +18 -3
- package/dist/cjs/structs/model/chat-provider.js +6 -0
- package/dist/cjs/structs/support/model/completion.js +2 -0
- package/dist/cjs/structs/support/model/messages.js +2 -0
- package/dist/cjs/support/capabilities.js +43 -6
- package/dist/cjs/support/context/assembly.js +88 -16
- package/dist/cjs/support/context/compression.js +48 -6
- package/dist/cjs/support/context/fragments.js +6 -0
- package/dist/cjs/support/context/history.js +36 -1
- package/dist/cjs/support/context/index.js +11 -0
- package/dist/cjs/support/context/nodes.js +164 -35
- package/dist/cjs/support/context/processing.js +319 -61
- package/dist/cjs/support/context/selection-policy.js +98 -21
- package/dist/cjs/support/context/selection.js +61 -10
- package/dist/cjs/support/context/snapshot.js +29 -7
- package/dist/cjs/support/context/strategies.js +120 -28
- package/dist/cjs/support/index.js +9 -1
- package/dist/cjs/support/model/capabilities.js +20 -1
- package/dist/cjs/support/model/chat-completions.js +92 -20
- package/dist/cjs/support/model/children.js +34 -6
- package/dist/cjs/support/model/compatible-provider.js +189 -59
- package/dist/cjs/support/model/completion/calls.js +61 -0
- package/dist/cjs/support/model/completion/default.js +32 -0
- package/dist/cjs/support/model/completion/index.js +28 -0
- package/dist/cjs/support/model/completion/session.js +102 -0
- package/dist/cjs/support/model/index.js +12 -0
- package/dist/cjs/support/model/interactions/index.js +12 -1
- package/dist/cjs/support/model/interactions/json-object.js +6 -0
- package/dist/cjs/support/model/interactions/native-functions.js +6 -0
- package/dist/cjs/support/model/observer.js +32 -6
- package/dist/cjs/support/model/preview-rules.js +66 -16
- package/dist/cjs/support/model/reply-preview.js +77 -17
- package/dist/cjs/support/model/stage-transport.js +33 -7
- package/dist/cjs/support/model/strategies.js +75 -14
- package/dist/cjs/support/model/transports.js +53 -11
- package/dist/cjs/support/registration.js +49 -7
- package/dist/cjs/support/schema.js +46 -4
- package/dist/cjs/support/stream-events.js +60 -8
- package/dist/cjs/support/tool-runtime.js +6 -0
- package/dist/cjs/support/tools.js +79 -10
- package/dist/cjs/support/transport/index.js +7 -0
- package/dist/cjs/support/transport/json.js +28 -4
- package/dist/cjs/support/transport/sse.js +25 -2
- package/dist/cjs/utils/break-observer.js +20 -2
- package/dist/cjs/utils/cancellation.js +77 -9
- package/dist/cjs/utils/catalog.js +19 -4
- package/dist/cjs/utils/debug.js +14 -2
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/interaction-definition.js +26 -6
- package/dist/cjs/utils/invocation.js +42 -4
- package/dist/cjs/utils/model-protocol.js +20 -1
- package/dist/cjs/utils/object.js +16 -0
- package/dist/cjs/utils/observer.js +22 -2
- package/dist/cjs/utils/protocol-registry.js +47 -4
- package/dist/cjs/utils/query-key.js +21 -2
- package/dist/cjs/utils/registration.js +18 -2
- package/dist/cjs/utils/rules.js +39 -11
- package/dist/cjs/utils/schema-adapter.js +25 -2
- package/dist/cjs/utils/synchronous.js +64 -7
- package/dist/cjs/utils/text.js +15 -1
- package/dist/esm/capabilities/index.d.ts +13 -0
- package/dist/esm/capabilities/index.js +13 -0
- package/dist/esm/capabilities/invocation.d.ts +16 -2
- package/dist/esm/capabilities/invocation.js +80 -10
- package/dist/esm/capabilities/model.d.ts +68 -1
- package/dist/esm/capabilities/model.js +126 -13
- package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
- package/dist/esm/capabilities/tool-runtime.js +64 -12
- package/dist/esm/capabilities/tools.d.ts +96 -3
- package/dist/esm/capabilities/tools.js +267 -32
- package/dist/esm/context/assembly.d.ts +13 -2
- package/dist/esm/context/assembly.js +46 -5
- package/dist/esm/context/audit.d.ts +23 -1
- package/dist/esm/context/audit.js +31 -6
- package/dist/esm/context/fragments.d.ts +37 -3
- package/dist/esm/context/fragments.js +54 -11
- package/dist/esm/context/index.d.ts +12 -0
- package/dist/esm/context/index.js +12 -0
- package/dist/esm/context/journal.d.ts +32 -1
- package/dist/esm/context/journal.js +84 -7
- package/dist/esm/context/plan.d.ts +11 -1
- package/dist/esm/context/plan.js +30 -2
- package/dist/esm/diagnostics/catalog.js +11 -3
- package/dist/esm/diagnostics/index.d.ts +30 -2
- package/dist/esm/diagnostics/index.js +149 -29
- package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
- package/dist/esm/diagnostics/sub-flow.js +240 -40
- package/dist/esm/errors.d.ts +22 -2
- package/dist/esm/errors.js +99 -17
- package/dist/esm/execution/branch.d.ts +19 -1
- package/dist/esm/execution/branch.js +20 -4
- package/dist/esm/execution/engine.d.ts +291 -5
- package/dist/esm/execution/engine.js +471 -57
- package/dist/esm/execution/events.d.ts +16 -2
- package/dist/esm/execution/events.js +136 -18
- package/dist/esm/execution/index.d.ts +7 -0
- package/dist/esm/execution/index.js +7 -0
- package/dist/esm/execution/reporting.d.ts +49 -1
- package/dist/esm/execution/reporting.js +75 -6
- package/dist/esm/execution/state.d.ts +126 -10
- package/dist/esm/execution/state.js +161 -22
- package/dist/esm/execution/workflow.d.ts +121 -3
- package/dist/esm/execution/workflow.js +224 -32
- package/dist/esm/index.d.ts +17 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/kits/aggregation.d.ts +34 -2
- package/dist/esm/kits/aggregation.js +45 -3
- package/dist/esm/kits/answering/batch.d.ts +17 -0
- package/dist/esm/kits/answering/batch.js +23 -4
- package/dist/esm/kits/answering/check-result.d.ts +18 -1
- package/dist/esm/kits/answering/check-result.js +31 -8
- package/dist/esm/kits/answering/checks.d.ts +11 -0
- package/dist/esm/kits/answering/checks.js +24 -3
- package/dist/esm/kits/answering/flow.d.ts +25 -2
- package/dist/esm/kits/answering/flow.js +192 -36
- package/dist/esm/kits/answering/index.d.ts +12 -0
- package/dist/esm/kits/answering/index.js +19 -1
- package/dist/esm/kits/answering/tasks.d.ts +32 -1
- package/dist/esm/kits/answering/tasks.js +88 -13
- package/dist/esm/kits/artifacts.d.ts +11 -0
- package/dist/esm/kits/artifacts.js +36 -4
- package/dist/esm/kits/candidates.d.ts +23 -1
- package/dist/esm/kits/candidates.js +47 -5
- package/dist/esm/kits/delivery.d.ts +34 -0
- package/dist/esm/kits/delivery.js +40 -5
- package/dist/esm/kits/durable.d.ts +19 -0
- package/dist/esm/kits/durable.js +155 -31
- package/dist/esm/kits/evidence.d.ts +28 -5
- package/dist/esm/kits/evidence.js +66 -15
- package/dist/esm/kits/family.d.ts +17 -1
- package/dist/esm/kits/family.js +152 -22
- package/dist/esm/kits/index.d.ts +12 -1
- package/dist/esm/kits/index.js +12 -1
- package/dist/esm/kits/inference.d.ts +64 -0
- package/dist/esm/kits/inference.js +104 -16
- package/dist/esm/kits/intents/catalog.d.ts +13 -1
- package/dist/esm/kits/intents/catalog.js +67 -16
- package/dist/esm/kits/intents/index.d.ts +11 -0
- package/dist/esm/kits/intents/index.js +11 -0
- package/dist/esm/kits/intents/registry.d.ts +61 -3
- package/dist/esm/kits/intents/registry.js +188 -43
- package/dist/esm/kits/intents/scopes.d.ts +73 -3
- package/dist/esm/kits/intents/scopes.js +215 -46
- package/dist/esm/kits/interaction/command.d.ts +38 -4
- package/dist/esm/kits/interaction/command.js +140 -36
- package/dist/esm/kits/interaction/commands.d.ts +66 -2
- package/dist/esm/kits/interaction/commands.js +86 -11
- package/dist/esm/kits/interaction/handlers.d.ts +19 -2
- package/dist/esm/kits/interaction/handlers.js +27 -10
- package/dist/esm/kits/interaction/index.d.ts +10 -0
- package/dist/esm/kits/interaction/index.js +10 -0
- package/dist/esm/kits/interaction/transfer.d.ts +39 -2
- package/dist/esm/kits/interaction/transfer.js +80 -14
- package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
- package/dist/esm/kits/knowledge/catalog.js +62 -11
- package/dist/esm/kits/knowledge/index.d.ts +11 -0
- package/dist/esm/kits/knowledge/index.js +16 -1
- package/dist/esm/kits/knowledge/publication.d.ts +15 -1
- package/dist/esm/kits/knowledge/publication.js +99 -23
- package/dist/esm/kits/knowledge/sections.d.ts +31 -1
- package/dist/esm/kits/knowledge/sections.js +33 -4
- package/dist/esm/kits/normalization.d.ts +25 -2
- package/dist/esm/kits/normalization.js +51 -7
- package/dist/esm/kits/policies.d.ts +26 -3
- package/dist/esm/kits/policies.js +79 -15
- package/dist/esm/kits/presentation/events.d.ts +51 -4
- package/dist/esm/kits/presentation/events.js +54 -10
- package/dist/esm/kits/presentation/index.d.ts +12 -0
- package/dist/esm/kits/presentation/index.js +25 -2
- package/dist/esm/kits/presentation/outputs.d.ts +30 -1
- package/dist/esm/kits/presentation/outputs.js +176 -38
- package/dist/esm/kits/presentation/templates.d.ts +32 -3
- package/dist/esm/kits/presentation/templates.js +33 -5
- package/dist/esm/kits/presentation/variants.d.ts +29 -0
- package/dist/esm/kits/presentation/variants.js +31 -2
- package/dist/esm/kits/projection.d.ts +42 -5
- package/dist/esm/kits/projection.js +63 -8
- package/dist/esm/kits/rank-fusion.d.ts +21 -1
- package/dist/esm/kits/rank-fusion.js +28 -5
- package/dist/esm/kits/reflection-log-source.d.ts +28 -1
- package/dist/esm/kits/reflection-log-source.js +89 -16
- package/dist/esm/kits/reflection.d.ts +17 -1
- package/dist/esm/kits/reflection.js +235 -61
- package/dist/esm/kits/retrieval.d.ts +18 -2
- package/dist/esm/kits/retrieval.js +98 -18
- package/dist/esm/kits/search.d.ts +56 -3
- package/dist/esm/kits/search.js +180 -27
- package/dist/esm/kits/text-skills.d.ts +16 -2
- package/dist/esm/kits/text-skills.js +104 -19
- package/dist/esm/kits/tools.d.ts +122 -2
- package/dist/esm/kits/tools.js +416 -74
- package/dist/esm/kits/vector-search.d.ts +47 -1
- package/dist/esm/kits/vector-search.js +51 -17
- package/dist/esm/mock/node.d.ts +7 -0
- package/dist/esm/mock/node.js +7 -1
- package/dist/esm/mock/web.d.ts +7 -0
- package/dist/esm/mock/web.js +7 -1
- package/dist/esm/mock.d.ts +7 -0
- package/dist/esm/mock.js +7 -1
- package/dist/esm/model/binding.d.ts +32 -3
- package/dist/esm/model/binding.js +68 -17
- package/dist/esm/model/call-budget.d.ts +30 -2
- package/dist/esm/model/call-budget.js +45 -4
- package/dist/esm/model/decision-retry.d.ts +10 -1
- package/dist/esm/model/decision-retry.js +19 -1
- package/dist/esm/model/defaults.d.ts +13 -2
- package/dist/esm/model/defaults.js +27 -4
- package/dist/esm/model/index.d.ts +7 -0
- package/dist/esm/model/index.js +7 -0
- package/dist/esm/model/interactions/arguments.d.ts +27 -0
- package/dist/esm/model/interactions/arguments.js +36 -1
- package/dist/esm/model/interactions/json-object.d.ts +7 -1
- package/dist/esm/model/interactions/json-object.js +48 -12
- package/dist/esm/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/model/interactions/native-functions.js +52 -10
- package/dist/esm/model/message-diagnostics.d.ts +17 -1
- package/dist/esm/model/message-diagnostics.js +17 -4
- package/dist/esm/model/options.d.ts +18 -1
- package/dist/esm/model/options.js +9 -1
- package/dist/esm/model/preparation.d.ts +30 -2
- package/dist/esm/model/preparation.js +86 -12
- package/dist/esm/model/runner.d.ts +129 -5
- package/dist/esm/model/runner.js +414 -80
- package/dist/esm/model/selection-transport.d.ts +14 -1
- package/dist/esm/model/selection-transport.js +48 -8
- package/dist/esm/model/settings.d.ts +11 -0
- package/dist/esm/model/settings.js +67 -13
- package/dist/esm/model/token-budget.d.ts +59 -1
- package/dist/esm/model/token-budget.js +69 -11
- package/dist/esm/model/transports.d.ts +20 -2
- package/dist/esm/model/transports.js +59 -6
- package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
- package/dist/esm/structs/capabilities/model.d.ts +27 -0
- package/dist/esm/structs/capabilities/tools.d.ts +38 -0
- package/dist/esm/structs/common.d.ts +62 -2
- package/dist/esm/structs/common.js +11 -0
- package/dist/esm/structs/context/fragments.d.ts +28 -0
- package/dist/esm/structs/context/journal.d.ts +28 -3
- package/dist/esm/structs/context/processing.d.ts +11 -0
- package/dist/esm/structs/debug.d.ts +58 -1
- package/dist/esm/structs/debug.js +34 -5
- package/dist/esm/structs/diagnostics.d.ts +119 -1
- package/dist/esm/structs/errors.d.ts +42 -1
- package/dist/esm/structs/errors.js +26 -1
- package/dist/esm/structs/execution/engine.d.ts +24 -1
- package/dist/esm/structs/execution/events.d.ts +12 -0
- package/dist/esm/structs/execution/workflow.d.ts +71 -0
- package/dist/esm/structs/index.d.ts +11 -1
- package/dist/esm/structs/index.js +11 -1
- package/dist/esm/structs/invocation.d.ts +30 -0
- package/dist/esm/structs/kits/aggregation.d.ts +12 -0
- package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
- package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
- package/dist/esm/structs/kits/answering/state.d.ts +21 -0
- package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
- package/dist/esm/structs/kits/artifacts.d.ts +14 -0
- package/dist/esm/structs/kits/candidates.d.ts +19 -0
- package/dist/esm/structs/kits/delivery.d.ts +22 -0
- package/dist/esm/structs/kits/durable.d.ts +56 -3
- package/dist/esm/structs/kits/durable.js +7 -0
- package/dist/esm/structs/kits/evidence.d.ts +23 -0
- package/dist/esm/structs/kits/family.d.ts +49 -1
- package/dist/esm/structs/kits/family.js +1 -0
- package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
- package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
- package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
- package/dist/esm/structs/kits/interaction.d.ts +64 -0
- package/dist/esm/structs/kits/interaction.js +8 -1
- package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
- package/dist/esm/structs/kits/knowledge-publication.js +1 -0
- package/dist/esm/structs/kits/knowledge.d.ts +39 -2
- package/dist/esm/structs/kits/normalization.d.ts +15 -0
- package/dist/esm/structs/kits/policies.d.ts +25 -1
- package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
- package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
- package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
- package/dist/esm/structs/kits/projection.d.ts +21 -0
- package/dist/esm/structs/kits/reflection.d.ts +61 -2
- package/dist/esm/structs/kits/reflection.js +18 -3
- package/dist/esm/structs/kits/retrieval.d.ts +38 -0
- package/dist/esm/structs/kits/search.d.ts +22 -0
- package/dist/esm/structs/kits/text-skills.d.ts +36 -0
- package/dist/esm/structs/kits/tools.d.ts +87 -0
- package/dist/esm/structs/model/chat-provider.d.ts +24 -1
- package/dist/esm/structs/model/chat-provider.js +6 -0
- package/dist/esm/structs/model/interactions.d.ts +38 -0
- package/dist/esm/structs/model/messages.d.ts +30 -0
- package/dist/esm/structs/model/runtime.d.ts +104 -6
- package/dist/esm/structs/support/capabilities.d.ts +19 -2
- package/dist/esm/structs/support/context-processing.d.ts +88 -9
- package/dist/esm/structs/support/context.d.ts +29 -1
- package/dist/esm/structs/support/model/completion.d.ts +50 -0
- package/dist/esm/structs/support/model/completion.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +13 -1
- package/dist/esm/structs/support/model/messages.d.ts +52 -0
- package/dist/esm/structs/support/model/messages.js +1 -0
- package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
- package/dist/esm/structs/support/model/provider.d.ts +71 -6
- package/dist/esm/structs/support/registration.d.ts +13 -0
- package/dist/esm/structs/support/schema.d.ts +14 -0
- package/dist/esm/structs/support/tools.d.ts +28 -0
- package/dist/esm/structs/support/transport/json.d.ts +16 -0
- package/dist/esm/structs/support/transport/sse.d.ts +15 -0
- package/dist/esm/structs/utils/rules.d.ts +19 -0
- package/dist/esm/support/capabilities.d.ts +25 -2
- package/dist/esm/support/capabilities.js +43 -6
- package/dist/esm/support/context/assembly.d.ts +35 -4
- package/dist/esm/support/context/assembly.js +88 -16
- package/dist/esm/support/context/compression.d.ts +17 -1
- package/dist/esm/support/context/compression.js +48 -6
- package/dist/esm/support/context/fragments.d.ts +6 -0
- package/dist/esm/support/context/fragments.js +6 -0
- package/dist/esm/support/context/history.d.ts +43 -0
- package/dist/esm/support/context/history.js +36 -1
- package/dist/esm/support/context/index.d.ts +13 -2
- package/dist/esm/support/context/index.js +12 -1
- package/dist/esm/support/context/nodes.d.ts +49 -3
- package/dist/esm/support/context/nodes.js +165 -36
- package/dist/esm/support/context/processing.d.ts +145 -1
- package/dist/esm/support/context/processing.js +320 -62
- package/dist/esm/support/context/selection-policy.d.ts +42 -2
- package/dist/esm/support/context/selection-policy.js +98 -21
- package/dist/esm/support/context/selection.d.ts +14 -1
- package/dist/esm/support/context/selection.js +61 -10
- package/dist/esm/support/context/snapshot.d.ts +23 -1
- package/dist/esm/support/context/snapshot.js +29 -7
- package/dist/esm/support/context/strategies.d.ts +35 -2
- package/dist/esm/support/context/strategies.js +120 -28
- package/dist/esm/support/index.d.ts +9 -1
- package/dist/esm/support/index.js +9 -1
- package/dist/esm/support/model/capabilities.d.ts +10 -0
- package/dist/esm/support/model/capabilities.js +20 -1
- package/dist/esm/support/model/chat-completions.d.ts +44 -15
- package/dist/esm/support/model/chat-completions.js +92 -20
- package/dist/esm/support/model/children.d.ts +32 -2
- package/dist/esm/support/model/children.js +34 -6
- package/dist/esm/support/model/compatible-provider.d.ts +29 -3
- package/dist/esm/support/model/compatible-provider.js +190 -60
- package/dist/esm/support/model/completion/calls.d.ts +40 -0
- package/dist/esm/support/model/completion/calls.js +58 -0
- package/dist/esm/support/model/completion/default.d.ts +10 -0
- package/dist/esm/support/model/completion/default.js +29 -0
- package/dist/esm/support/model/completion/index.d.ts +10 -0
- package/dist/esm/support/model/completion/index.js +22 -0
- package/dist/esm/support/model/completion/session.d.ts +11 -0
- package/dist/esm/support/model/completion/session.js +99 -0
- package/dist/esm/support/model/index.d.ts +14 -0
- package/dist/esm/support/model/index.js +12 -0
- package/dist/esm/support/model/interactions/index.d.ts +1 -1
- package/dist/esm/support/model/interactions/index.js +12 -1
- package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
- package/dist/esm/support/model/interactions/json-object.js +6 -0
- package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
- package/dist/esm/support/model/interactions/native-functions.js +6 -0
- package/dist/esm/support/model/observer.d.ts +25 -2
- package/dist/esm/support/model/observer.js +32 -6
- package/dist/esm/support/model/preview-rules.d.ts +20 -2
- package/dist/esm/support/model/preview-rules.js +66 -16
- package/dist/esm/support/model/reply-preview.d.ts +15 -1
- package/dist/esm/support/model/reply-preview.js +77 -17
- package/dist/esm/support/model/stage-transport.d.ts +9 -1
- package/dist/esm/support/model/stage-transport.js +33 -7
- package/dist/esm/support/model/strategies.d.ts +24 -2
- package/dist/esm/support/model/strategies.js +75 -14
- package/dist/esm/support/model/transports.d.ts +17 -1
- package/dist/esm/support/model/transports.js +53 -11
- package/dist/esm/support/registration.d.ts +20 -1
- package/dist/esm/support/registration.js +49 -7
- package/dist/esm/support/schema.d.ts +31 -1
- package/dist/esm/support/schema.js +46 -4
- package/dist/esm/support/stream-events.d.ts +22 -1
- package/dist/esm/support/stream-events.js +60 -8
- package/dist/esm/support/tool-runtime.d.ts +6 -0
- package/dist/esm/support/tool-runtime.js +6 -0
- package/dist/esm/support/tools.d.ts +22 -0
- package/dist/esm/support/tools.js +79 -10
- package/dist/esm/support/transport/index.d.ts +7 -0
- package/dist/esm/support/transport/index.js +7 -0
- package/dist/esm/support/transport/json.d.ts +29 -2
- package/dist/esm/support/transport/json.js +28 -4
- package/dist/esm/support/transport/sse.d.ts +31 -1
- package/dist/esm/support/transport/sse.js +25 -2
- package/dist/esm/types.d.ts +9 -1
- package/dist/esm/utils/break-observer.d.ts +27 -2
- package/dist/esm/utils/break-observer.js +20 -2
- package/dist/esm/utils/cancellation.d.ts +56 -5
- package/dist/esm/utils/cancellation.js +77 -9
- package/dist/esm/utils/catalog.d.ts +20 -1
- package/dist/esm/utils/catalog.js +19 -4
- package/dist/esm/utils/debug.d.ts +20 -1
- package/dist/esm/utils/debug.js +14 -2
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/interaction-definition.d.ts +18 -1
- package/dist/esm/utils/interaction-definition.js +26 -6
- package/dist/esm/utils/invocation.d.ts +36 -1
- package/dist/esm/utils/invocation.js +42 -4
- package/dist/esm/utils/model-protocol.d.ts +8 -0
- package/dist/esm/utils/model-protocol.js +20 -1
- package/dist/esm/utils/object.d.ts +16 -0
- package/dist/esm/utils/object.js +16 -0
- package/dist/esm/utils/observer.d.ts +19 -1
- package/dist/esm/utils/observer.js +22 -2
- package/dist/esm/utils/protocol-registry.d.ts +38 -1
- package/dist/esm/utils/protocol-registry.js +47 -4
- package/dist/esm/utils/query-key.d.ts +11 -1
- package/dist/esm/utils/query-key.js +21 -2
- package/dist/esm/utils/registration.d.ts +34 -2
- package/dist/esm/utils/registration.js +18 -2
- package/dist/esm/utils/rules.d.ts +81 -4
- package/dist/esm/utils/rules.js +39 -11
- package/dist/esm/utils/schema-adapter.d.ts +12 -1
- package/dist/esm/utils/schema-adapter.js +25 -2
- package/dist/esm/utils/synchronous.d.ts +60 -4
- package/dist/esm/utils/synchronous.js +64 -7
- package/dist/esm/utils/text.d.ts +15 -1
- package/dist/esm/utils/text.js +15 -1
- package/package.json +3 -2
|
@@ -1,17 +1,34 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Capability module catalog contract.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: Support-side composition only. Applications declare modules and the tools
|
|
5
|
+
* they contribute; the catalog validates those declarations once so Core can receive a stable
|
|
6
|
+
* description. It creates no Core execution entity and owns no domain lifecycle.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `CapabilityToolReferences`, `CapabilityModule`, `CapabilityCatalogOptions`.
|
|
9
|
+
*/
|
|
10
|
+
/** Tool references declared by one owner module. */
|
|
2
11
|
export interface CapabilityToolReferences {
|
|
12
|
+
/** Owner id; must be non-blank and is used in rejection messages. */
|
|
3
13
|
readonly id: string;
|
|
14
|
+
/** Tools the module cannot work without; every id must be registered somewhere. */
|
|
4
15
|
readonly requiredToolIds: readonly string[];
|
|
16
|
+
/** Tools the module uses when available; every id must be registered somewhere. */
|
|
5
17
|
readonly optionalToolIds?: readonly string[];
|
|
6
18
|
}
|
|
7
|
-
/** Minimal composition contract;
|
|
19
|
+
/** Minimal composition contract; lifecycle and domain fields remain application-owned. */
|
|
8
20
|
export interface CapabilityModule {
|
|
21
|
+
/** Unique module id; also the catalog key. */
|
|
9
22
|
readonly id: string;
|
|
23
|
+
/** Non-blank description of what the module contributes. */
|
|
10
24
|
readonly description: string;
|
|
25
|
+
/** Tools contributed by this module; ids must be unique across all modules. */
|
|
11
26
|
readonly tools: readonly {
|
|
12
27
|
readonly id: string;
|
|
13
28
|
}[];
|
|
14
29
|
}
|
|
30
|
+
/** Catalog construction options. */
|
|
15
31
|
export interface CapabilityCatalogOptions<Module extends CapabilityModule> {
|
|
32
|
+
/** Projects a module's tool references; must be synchronous and is checked at construction. */
|
|
16
33
|
readonly toolReferences?: (module: Readonly<Module>) => readonly CapabilityToolReferences[];
|
|
17
34
|
}
|
|
@@ -1,22 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context processing contract used by Support's context engine.
|
|
3
|
+
*
|
|
4
|
+
* Core keeps the trust, budget and structural-audit guarantees; these declarations describe the
|
|
5
|
+
* App-supplied policies, reductions, compressors and selectors that the engine applies in a fixed
|
|
6
|
+
* order. Each mode, kind and handler is a registered entry, so validation and execution read the
|
|
7
|
+
* same declaration.
|
|
8
|
+
*
|
|
9
|
+
* Exports: `ContextHistoryGrouping`, `ContextRecentHistory`, `ContextHandlerReference`,
|
|
10
|
+
* `ContextReduction`, `ContextSelection`, `ContextSelectionCandidate`, `ContextTokenMeasurement`,
|
|
11
|
+
* `ContextSelectionCall`, `ContextSelector`, `ContextPolicy`, `ContextCompressionCall`,
|
|
12
|
+
* `ContextCompressor`, `ContextProcessingReport`, `ContextModelRequest`, `ContextModelCall`,
|
|
13
|
+
* `ContextProcessingOptions`.
|
|
14
|
+
*/
|
|
1
15
|
import type { ContextFragment, BuiltContext } from '../context/fragments.js';
|
|
2
16
|
import type { ExecutionContext } from '../common.js';
|
|
3
17
|
import type { ModelResult } from '../invocation.js';
|
|
4
18
|
import type { ModelMessage } from '../model/messages.js';
|
|
19
|
+
/** How a message history is split into groups for trimming. */
|
|
5
20
|
export type ContextHistoryGrouping = {
|
|
6
21
|
kind: 'fixed';
|
|
7
22
|
size: number;
|
|
8
23
|
} | {
|
|
9
24
|
kind: 'user-turn';
|
|
10
25
|
};
|
|
26
|
+
/** Recent history that compression must keep verbatim. */
|
|
11
27
|
export interface ContextRecentHistory {
|
|
28
|
+
/** Field holding the history value inside the fragment. */
|
|
12
29
|
field: string;
|
|
30
|
+
/** Number of trailing groups to keep. */
|
|
13
31
|
keepGroups: number;
|
|
32
|
+
/** Grouping rule; `user-turn` keeps whole conversational turns together. */
|
|
14
33
|
grouping: ContextHistoryGrouping;
|
|
15
34
|
}
|
|
35
|
+
/** Reference to a registered compressor or selector handler. */
|
|
16
36
|
export interface ContextHandlerReference {
|
|
37
|
+
/** Registered handler id; an unknown id is rejected before execution. */
|
|
17
38
|
readonly handlerId: string;
|
|
18
39
|
}
|
|
19
|
-
|
|
40
|
+
/** One declared reduction step. */
|
|
41
|
+
export type ContextReduction =
|
|
42
|
+
/** Trims a history field to `targetChars`, dropping whole groups beyond `keepGroups`. */
|
|
43
|
+
{
|
|
20
44
|
id: string;
|
|
21
45
|
kind: 'trim';
|
|
22
46
|
fragmentId: string;
|
|
@@ -24,17 +48,24 @@ export type ContextReduction = {
|
|
|
24
48
|
targetChars: number;
|
|
25
49
|
grouping: ContextHistoryGrouping;
|
|
26
50
|
keepGroups: number;
|
|
27
|
-
}
|
|
51
|
+
}
|
|
52
|
+
/** Rewrites one fragment through a registered compressor down to `targetChars`. */
|
|
53
|
+
| ({
|
|
28
54
|
id: string;
|
|
29
55
|
kind: 'compress';
|
|
30
56
|
fragmentId: string;
|
|
31
57
|
targetChars: number;
|
|
58
|
+
/** Recent history the compressor must preserve verbatim. */
|
|
32
59
|
preserve?: ContextRecentHistory;
|
|
33
60
|
} & ContextHandlerReference);
|
|
34
61
|
/** Selection is independent of ownership; omitted selection preserves ordered execution. */
|
|
35
|
-
export type ContextSelection =
|
|
62
|
+
export type ContextSelection =
|
|
63
|
+
/** Apply every declared step in order. */
|
|
64
|
+
{
|
|
36
65
|
mode: 'sequence';
|
|
37
|
-
}
|
|
66
|
+
}
|
|
67
|
+
/** Apply only steps of the given kind. */
|
|
68
|
+
| {
|
|
38
69
|
mode: 'fixed';
|
|
39
70
|
kind: ContextReduction['kind'];
|
|
40
71
|
}
|
|
@@ -43,47 +74,75 @@ export type ContextSelection = {
|
|
|
43
74
|
mode: 'auto';
|
|
44
75
|
maxTrimLossRatio?: number;
|
|
45
76
|
reserveCalls?: number;
|
|
46
|
-
}
|
|
77
|
+
}
|
|
78
|
+
/** Ask a registered model selector; `reserveCalls` keeps calls for later stages. */
|
|
79
|
+
| ({
|
|
47
80
|
mode: 'model';
|
|
48
81
|
reserveCalls?: number;
|
|
49
82
|
} & ContextHandlerReference);
|
|
83
|
+
/** Candidate step considered by selection, with its measured cost. */
|
|
50
84
|
export interface ContextSelectionCandidate {
|
|
51
85
|
id: string;
|
|
52
86
|
kind: ContextReduction['kind'];
|
|
53
87
|
fragmentId: string;
|
|
88
|
+
/** Current size of the candidate fragment, in JSON characters. */
|
|
54
89
|
chars: number;
|
|
90
|
+
/** Size the step would reduce the fragment to. */
|
|
55
91
|
targetChars: number;
|
|
92
|
+
/** Model calls required to apply the step; 0 for local steps. */
|
|
56
93
|
requiredCalls: number;
|
|
57
94
|
/** Exact dry-run result for trim. Compression size is not predicted. */
|
|
58
95
|
projectedChars?: number;
|
|
96
|
+
/** Fraction of characters removed by a trim step; meaningless for compression. */
|
|
59
97
|
trimLossRatio?: number;
|
|
60
98
|
}
|
|
99
|
+
/** Injected token measurement for token-triggered policies. */
|
|
61
100
|
export interface ContextTokenMeasurement {
|
|
101
|
+
/** Tokenizer identity, reported in the processing report. */
|
|
62
102
|
counterId: string;
|
|
103
|
+
/** Input token ceiling the measurement is compared against. */
|
|
63
104
|
inputLimit: number;
|
|
64
105
|
measure(messages: readonly ModelMessage[]): number;
|
|
65
106
|
}
|
|
107
|
+
/** Everything a selector may inspect for one decision. */
|
|
66
108
|
export interface ContextSelectionCall {
|
|
67
109
|
readonly stageId: string;
|
|
110
|
+
/** Reducible candidates, already filtered and measured. */
|
|
68
111
|
candidates: readonly ContextSelectionCandidate[];
|
|
69
112
|
/** Only reducible fragments; never protected request or system fragments. */
|
|
70
113
|
fragments: readonly ContextFragment[];
|
|
114
|
+
/** Current input tokens, when a token budget applies. */
|
|
71
115
|
currentTokens?: number;
|
|
116
|
+
/** Tokens that must be removed to satisfy the token budget. */
|
|
72
117
|
requiredReductionTokens?: number;
|
|
73
118
|
currentChars: number;
|
|
119
|
+
/** Characters that must be removed to satisfy the character budget. */
|
|
74
120
|
requiredReductionChars: number;
|
|
121
|
+
/** Calls the selector may still spend through `callModel`. */
|
|
75
122
|
remainingCalls: number;
|
|
76
123
|
callModel: ContextModelCall;
|
|
77
124
|
}
|
|
125
|
+
/** Model or local selector that chooses which reductions to apply. */
|
|
78
126
|
export interface ContextSelector {
|
|
79
127
|
id: string;
|
|
80
128
|
/** Maximum model calls made through callModel, default 1; 0 permits a local selector. */
|
|
81
129
|
maxCalls?: number;
|
|
130
|
+
/** Returns selected reduction ids; unknown ids are rejected. */
|
|
82
131
|
select(call: ContextSelectionCall, context: ExecutionContext): Promise<readonly string[]>;
|
|
83
132
|
}
|
|
84
|
-
|
|
133
|
+
/** Declared context policy for one stage. */
|
|
134
|
+
export type ContextPolicy =
|
|
135
|
+
/** Validate trust and budgets without changing content. */
|
|
136
|
+
{
|
|
85
137
|
mode: 'validate';
|
|
86
|
-
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Reduce content when a trigger is exceeded.
|
|
141
|
+
*
|
|
142
|
+
* Character and token triggers/targets may be combined; `targetInputChars`/`targetInputTokens`
|
|
143
|
+
* define the size the reduction must reach.
|
|
144
|
+
*/
|
|
145
|
+
| {
|
|
87
146
|
mode: 'reduce';
|
|
88
147
|
triggerChars?: number;
|
|
89
148
|
targetInputChars?: number;
|
|
@@ -91,39 +150,52 @@ export type ContextPolicy = {
|
|
|
91
150
|
targetInputTokens?: number;
|
|
92
151
|
selection?: ContextSelection;
|
|
93
152
|
steps: readonly ContextReduction[];
|
|
94
|
-
}
|
|
153
|
+
}
|
|
154
|
+
/** Verify that only the listed fragments changed value, without reducing anything. */
|
|
155
|
+
| {
|
|
95
156
|
mode: 'audit';
|
|
96
157
|
mutableFragmentIds: readonly string[];
|
|
97
158
|
};
|
|
159
|
+
/** One compression request. */
|
|
98
160
|
export interface ContextCompressionCall {
|
|
99
161
|
readonly stageId: string;
|
|
162
|
+
/** Fragment to compress; its `targetChars` bound is enforced by the engine. */
|
|
100
163
|
fragment: ContextFragment;
|
|
101
164
|
targetChars: number;
|
|
102
|
-
/**
|
|
165
|
+
/** Same runner's budget, timeout, transports and diagnostics. No recursive processing. */
|
|
103
166
|
callModel: ContextModelCall;
|
|
104
167
|
}
|
|
168
|
+
/** Registered compressor handler. */
|
|
105
169
|
export interface ContextCompressor {
|
|
106
170
|
id: string;
|
|
107
171
|
/** Maximum model calls through callModel, default 1; declare 0 for local compression. */
|
|
108
172
|
maxCalls?: number;
|
|
173
|
+
/** Produces a replacement value no larger than the requested target where possible. */
|
|
109
174
|
compress(call: ContextCompressionCall, context: ExecutionContext): Promise<ContextFragment['value']>;
|
|
110
175
|
}
|
|
176
|
+
/** Facts recorded for one processing run. */
|
|
111
177
|
export interface ContextProcessingReport {
|
|
178
|
+
/** Policy mode that ran. */
|
|
112
179
|
mode: ContextPolicy['mode'];
|
|
180
|
+
/** Selection mode applied, when the policy reduced content. */
|
|
113
181
|
selection?: ContextSelection['mode'];
|
|
182
|
+
/** Per-step selection decisions, kept for auditing `auto` and `model` choices. */
|
|
114
183
|
decisions?: {
|
|
115
184
|
mode: ContextSelection['mode'];
|
|
116
185
|
stepIds: string[];
|
|
117
186
|
reason: string;
|
|
118
187
|
}[];
|
|
188
|
+
/** Total characters before and after processing. */
|
|
119
189
|
beforeChars: number;
|
|
120
190
|
afterChars: number;
|
|
191
|
+
/** Token measurement, present only when a token budget was supplied. */
|
|
121
192
|
tokens?: {
|
|
122
193
|
counterId: string;
|
|
123
194
|
before: number;
|
|
124
195
|
after: number;
|
|
125
196
|
inputLimit: number;
|
|
126
197
|
};
|
|
198
|
+
/** Applied changes in execution order; `app` marks an App-supplied mutation. */
|
|
127
199
|
changes: {
|
|
128
200
|
id: string;
|
|
129
201
|
kind: 'trim' | 'compress' | 'app';
|
|
@@ -132,6 +204,7 @@ export interface ContextProcessingReport {
|
|
|
132
204
|
afterChars: number;
|
|
133
205
|
}[];
|
|
134
206
|
}
|
|
207
|
+
/** One model call made on behalf of a selector or compressor. */
|
|
135
208
|
export interface ContextModelRequest {
|
|
136
209
|
readonly modelId?: string;
|
|
137
210
|
readonly stageId: string;
|
|
@@ -143,11 +216,17 @@ export interface ContextModelRequest {
|
|
|
143
216
|
export interface ContextModelCall {
|
|
144
217
|
(request: ContextModelRequest): Promise<ModelResult<unknown>>;
|
|
145
218
|
}
|
|
219
|
+
/** Runtime inputs for one processing run. */
|
|
146
220
|
export interface ContextProcessingOptions extends ExecutionContext {
|
|
221
|
+
/** Stage the processing belongs to; reported in diagnostics and selection calls. */
|
|
147
222
|
readonly stageId: string;
|
|
223
|
+
/** Compressors available by handler id. */
|
|
148
224
|
readonly compressors: readonly ContextCompressor[];
|
|
225
|
+
/** Selectors available by handler id; required only for model selection. */
|
|
149
226
|
readonly selectors?: readonly ContextSelector[];
|
|
150
227
|
readonly callModel: ContextModelCall;
|
|
228
|
+
/** Remaining model calls; used to reject unaffordable selections. */
|
|
151
229
|
readonly remainingCalls?: () => number;
|
|
230
|
+
/** Token measurement; without it, token triggers and targets cannot apply. */
|
|
152
231
|
readonly tokenBudget?: ContextTokenMeasurement;
|
|
153
232
|
}
|
|
@@ -1,31 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context builder contract.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: Support-side assembly helpers. A builder turns App fragment declarations
|
|
5
|
+
* into a `ContextPlan` or an assembled `BuiltContext`; ordering and metadata are compiled once,
|
|
6
|
+
* while values are produced per request. Reduction, selection and model execution stay with Core.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `ContextProjection`, `ContextBuilderOptions`, `ContextAssemblyOptions`,
|
|
9
|
+
* `ContextFragmentConfig`, `ContextBuilder`.
|
|
10
|
+
*/
|
|
1
11
|
import type { ContextPlan } from '../context/processing.js';
|
|
2
12
|
import type { ContextFragment, BuiltContext } from '../context/fragments.js';
|
|
13
|
+
/** One declared projection: a single fragment or a placement expanded into fragments. */
|
|
3
14
|
export type ContextProjection<Input, Id extends string = string, Placement extends string = string> = {
|
|
4
15
|
readonly kind: 'fragment';
|
|
16
|
+
/** Fragment id; must be unique across all projections. */
|
|
5
17
|
readonly id: Id;
|
|
18
|
+
/** Produces the fragment value; must be synchronous. */
|
|
6
19
|
readonly format: (input: Input) => ContextFragment['value'];
|
|
7
|
-
}
|
|
20
|
+
}
|
|
21
|
+
/** Expands to the fragments supplied for this placement; ids use a separate prefix. */
|
|
22
|
+
| {
|
|
8
23
|
readonly kind: 'contributions';
|
|
9
24
|
readonly placement: Placement;
|
|
10
25
|
};
|
|
26
|
+
/** Shared builder options. */
|
|
11
27
|
export interface ContextBuilderOptions<Input> {
|
|
28
|
+
/** Character budget, constant or derived from the request; at least one of these is required. */
|
|
12
29
|
readonly maxInputChars?: number | ((input: Input) => number);
|
|
30
|
+
/** Applied to every produced fragment before assembly; must be synchronous. */
|
|
13
31
|
readonly transform?: (fragment: ContextFragment, input: Input) => ContextFragment;
|
|
14
32
|
}
|
|
33
|
+
/** Assembly options for placement-based projections. */
|
|
15
34
|
export interface ContextAssemblyOptions<Input, Id extends string, Placement extends string> extends ContextBuilderOptions<Input> {
|
|
35
|
+
/** Builds a fragment for a single-fragment projection. */
|
|
16
36
|
readonly fragment: (id: Id, value: ContextFragment['value']) => ContextFragment;
|
|
37
|
+
/** Contribution handlers keyed by placement; each expands to zero or more fragments. */
|
|
17
38
|
readonly contributions?: Readonly<Record<Placement, (input: Input) => readonly ContextFragment[]>>;
|
|
18
39
|
}
|
|
40
|
+
/** Self-describing fragment declaration: metadata plus a formatter. */
|
|
19
41
|
export interface ContextFragmentConfig<Input> extends Omit<ContextFragment, 'value'> {
|
|
42
|
+
/** Documentation only; not sent to the model. */
|
|
20
43
|
readonly description?: string;
|
|
44
|
+
/** Produces the value; must be synchronous. */
|
|
21
45
|
readonly format: (input: Input) => ContextFragment['value'];
|
|
22
46
|
}
|
|
47
|
+
/** Compiled builder. It holds no request state and may be shared across invocations. */
|
|
23
48
|
export interface ContextBuilder<Input> {
|
|
49
|
+
/** Produces the fragments for one input, after transforms. */
|
|
24
50
|
fragments(input: Input): ContextFragment[];
|
|
51
|
+
/** Assembles and validates the plan into messages with usage accounting. */
|
|
25
52
|
build(request: {
|
|
26
53
|
input: Input;
|
|
27
54
|
maxInputChars?: number;
|
|
28
55
|
} & Omit<ContextPlan, 'fragments' | 'maxInputChars'>): BuiltContext;
|
|
56
|
+
/** Produces the unassembled plan without running the budget boundary. */
|
|
29
57
|
plan(request: {
|
|
30
58
|
input: Input;
|
|
31
59
|
maxInputChars?: number;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Completion policy contract for the compatible provider.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: Support-side protocol decision. A policy decides whether one finished
|
|
5
|
+
* stream satisfies the request it answered. It owns no HTTP, cancellation, request building or
|
|
6
|
+
* tool execution, and a session exists per request so concurrent calls never share state.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `CompletionRequestFacts`, `CompletionFailure`, `CompletionSession`, `CompletionPolicy`.
|
|
9
|
+
*/
|
|
10
|
+
import type { ModelPart } from '../../model/messages.js';
|
|
11
|
+
import type { ModelProviderErrorCode } from './provider.js';
|
|
12
|
+
/**
|
|
13
|
+
* Facts the provider reads from the request it actually sends.
|
|
14
|
+
*
|
|
15
|
+
* `functions` reports the Core call options and keeps the default policy equivalent to the
|
|
16
|
+
* behavior that existed before policies were configurable. `toolChoice` is the effective field of
|
|
17
|
+
* the serialized body, so a host override, or a field dropped for being `undefined`, is visible
|
|
18
|
+
* exactly as the upstream receives it.
|
|
19
|
+
*/
|
|
20
|
+
export interface CompletionRequestFacts {
|
|
21
|
+
/** Whether the call declared native functions through Core options. */
|
|
22
|
+
readonly functions: boolean;
|
|
23
|
+
/** Effective `tool_choice` of the request body; an absent field reads as `undefined`. */
|
|
24
|
+
readonly toolChoice?: unknown;
|
|
25
|
+
/** Whether an empty response is allowed because JSON mode permits it. */
|
|
26
|
+
readonly allowEmptyText: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** Build the classified failure a policy throws; the provider records it like its own failures. */
|
|
29
|
+
export type CompletionFailure = (code: ModelProviderErrorCode) => Error;
|
|
30
|
+
/** Per-request completion state observed by one policy. */
|
|
31
|
+
export interface CompletionSession {
|
|
32
|
+
/** Observe one part immediately before the provider yields it. */
|
|
33
|
+
part(part: ModelPart): void;
|
|
34
|
+
/** Observe the stream's single `finish_reason`. */
|
|
35
|
+
finish(reason: string): void;
|
|
36
|
+
/** Complete the response when the end-of-stream marker arrives. */
|
|
37
|
+
end(): void;
|
|
38
|
+
}
|
|
39
|
+
/** Decision whether a finished stream satisfies the request. */
|
|
40
|
+
export interface CompletionPolicy {
|
|
41
|
+
/** Registered identifier; the catalog key must match it. */
|
|
42
|
+
readonly id: string;
|
|
43
|
+
/**
|
|
44
|
+
* Start one request.
|
|
45
|
+
*
|
|
46
|
+
* Throwing here rejects the request before it is sent, which is how a policy refuses a request
|
|
47
|
+
* shape it cannot judge after the fact.
|
|
48
|
+
*/
|
|
49
|
+
begin(facts: CompletionRequestFacts, fail: CompletionFailure): CompletionSession;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage-scoped model transport contract.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: Support-side registration for transports that expose only the capabilities
|
|
5
|
+
* declared for each stage. Static sources are projected once; dynamic sources are re-projected at
|
|
6
|
+
* the model boundary. Either way, an undeclared stage or capability is rejected rather than
|
|
7
|
+
* silently omitted.
|
|
8
|
+
*
|
|
9
|
+
* Exports: `ModelInteractionAdapter`, `ModelTransportRegistration`, `NativeFunctionCall` (type
|
|
10
|
+
* re-exports) and `ModelStageTransportRegistration`.
|
|
11
|
+
*/
|
|
1
12
|
import type { ModelTransportRegistration } from '../../model/interactions.js';
|
|
2
|
-
export type { ModelInteractionAdapter, ModelTransportRegistration, NativeFunctionCall } from '../../model/interactions.js';
|
|
13
|
+
export type { ModelInteractionAdapter, ModelTransportRegistration, NativeFunctionCall, } from '../../model/interactions.js';
|
|
3
14
|
/** Stage IDs and capability references are App-owned; this adapter only compiles their relation. */
|
|
4
15
|
export interface ModelStageTransportRegistration<Result = unknown> extends ModelTransportRegistration<Result> {
|
|
16
|
+
/** Declared stages; each id is unique and lists non-empty, unique capability ids. */
|
|
5
17
|
readonly stages: readonly {
|
|
6
18
|
readonly id: string;
|
|
7
19
|
readonly capabilityIds: readonly string[];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-level message shapes for direct compatible-provider use.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: Support-side input for hosts that keep their own tool thread. `ModelMessage`
|
|
5
|
+
* stays the Core contract and is unchanged; these shapes add the assistant tool declaration and the
|
|
6
|
+
* tool result, with role and field association enforced by the union and re-checked at runtime.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `ProviderToolCall`, `ProviderSystemMessage`, `ProviderUserMessage`,
|
|
9
|
+
* `ProviderAssistantMessage`, `ProviderToolMessage`, `ProviderMessage`.
|
|
10
|
+
*/
|
|
11
|
+
import type { ModelImage } from '../../model/messages.js';
|
|
12
|
+
/** One tool call the assistant declared, in wire order. */
|
|
13
|
+
export interface ProviderToolCall {
|
|
14
|
+
/** Provider call ID, echoed by the matching tool result. */
|
|
15
|
+
readonly id: string;
|
|
16
|
+
/** Declared function name. */
|
|
17
|
+
readonly name: string;
|
|
18
|
+
/** Raw JSON arguments exactly as the provider produced them. */
|
|
19
|
+
readonly arguments: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ProviderSystemMessage {
|
|
22
|
+
readonly role: 'system';
|
|
23
|
+
readonly content: string;
|
|
24
|
+
readonly images?: never;
|
|
25
|
+
readonly toolCallId?: never;
|
|
26
|
+
readonly toolCalls?: never;
|
|
27
|
+
}
|
|
28
|
+
export interface ProviderUserMessage {
|
|
29
|
+
readonly role: 'user';
|
|
30
|
+
readonly content: string;
|
|
31
|
+
readonly images?: readonly ModelImage[];
|
|
32
|
+
readonly toolCallId?: never;
|
|
33
|
+
readonly toolCalls?: never;
|
|
34
|
+
}
|
|
35
|
+
/** Assistant turn; `content` may be empty when the turn is only a tool declaration. */
|
|
36
|
+
export interface ProviderAssistantMessage {
|
|
37
|
+
readonly role: 'assistant';
|
|
38
|
+
readonly content: string;
|
|
39
|
+
readonly images?: never;
|
|
40
|
+
readonly toolCallId?: never;
|
|
41
|
+
readonly toolCalls?: readonly ProviderToolCall[];
|
|
42
|
+
}
|
|
43
|
+
/** Tool result answering one declared call. */
|
|
44
|
+
export interface ProviderToolMessage {
|
|
45
|
+
readonly role: 'tool';
|
|
46
|
+
readonly content: string;
|
|
47
|
+
readonly toolCallId: string;
|
|
48
|
+
readonly images?: never;
|
|
49
|
+
readonly toolCalls?: never;
|
|
50
|
+
}
|
|
51
|
+
/** Message list a host may pass to the compatible provider directly. */
|
|
52
|
+
export type ProviderMessage = ProviderSystemMessage | ProviderUserMessage | ProviderAssistantMessage | ProviderToolMessage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,33 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider observation contract.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: optional, caller-owned logging around provider calls. Observations are
|
|
5
|
+
* best effort and never change provider results, cancellation or retry behaviour; payloads are
|
|
6
|
+
* built lazily and body capture happens only for explicitly accepted events.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `ProviderEventPayloads`, `ProviderEventName`, `ProviderEventDescriptor`,
|
|
9
|
+
* `ProviderObservation`, `ProviderObserver`, `ProviderErrorCapture`.
|
|
10
|
+
*/
|
|
1
11
|
import type { ModelProviderContext } from '../../model/chat-provider.js';
|
|
2
|
-
/**
|
|
12
|
+
/** Payload of each provider event. Content-bearing events are accepted explicitly. */
|
|
3
13
|
export interface ProviderEventPayloads {
|
|
14
|
+
/** Outbound request; contains prompt content. */
|
|
4
15
|
'provider.request': {
|
|
5
16
|
url: string;
|
|
6
17
|
body: unknown;
|
|
7
18
|
};
|
|
19
|
+
/** Response head; metadata only. */
|
|
8
20
|
'provider.response': {
|
|
9
21
|
status: number;
|
|
10
22
|
requestId: string | null;
|
|
11
23
|
contentType: string | null;
|
|
12
24
|
};
|
|
25
|
+
/** One raw streamed frame; contains response content. */
|
|
13
26
|
'provider.frame': {
|
|
14
27
|
data: string;
|
|
15
28
|
};
|
|
29
|
+
/** Upstream error body, captured only when accepted. */
|
|
16
30
|
'provider.error-body': {
|
|
17
31
|
status: number;
|
|
18
32
|
body: string;
|
|
19
33
|
truncated?: boolean;
|
|
20
34
|
};
|
|
35
|
+
/** End of the call; `complete` is false when the stream ended without a payload. */
|
|
21
36
|
'provider.end': {
|
|
22
37
|
complete: boolean;
|
|
23
38
|
error?: unknown;
|
|
24
39
|
};
|
|
25
40
|
}
|
|
41
|
+
/** Union of provider event names. */
|
|
26
42
|
export type ProviderEventName = keyof ProviderEventPayloads;
|
|
43
|
+
/** Provider event name plus its content class. */
|
|
27
44
|
export interface ProviderEventDescriptor {
|
|
28
45
|
readonly event: ProviderEventName;
|
|
29
46
|
readonly content: 'metadata' | 'content';
|
|
30
47
|
}
|
|
48
|
+
/** One observation: event name with its payload. */
|
|
31
49
|
export type ProviderObservation = {
|
|
32
50
|
[K in ProviderEventName]: {
|
|
33
51
|
readonly event: K;
|
|
@@ -36,9 +54,12 @@ export type ProviderObservation = {
|
|
|
36
54
|
}[ProviderEventName];
|
|
37
55
|
/** The caller can correlate each observation using the original, request-local model options. */
|
|
38
56
|
export interface ProviderObserver {
|
|
57
|
+
/** Returns false to skip an event; absent means accept every event. */
|
|
39
58
|
accepts?(descriptor: ProviderEventDescriptor, options: Readonly<ModelProviderContext>): boolean;
|
|
59
|
+
/** Handles one observation. Throwing or rejecting never affects the provider call. */
|
|
40
60
|
write(event: ProviderObservation, options: Readonly<ModelProviderContext>): void | Promise<void>;
|
|
41
61
|
}
|
|
62
|
+
/** Captured upstream error body and whether it had to be truncated. */
|
|
42
63
|
export interface ProviderErrorCapture {
|
|
43
64
|
body: string;
|
|
44
65
|
truncated: boolean;
|
|
@@ -1,34 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-compatible provider contract.
|
|
3
|
+
*
|
|
4
|
+
* Place in the package: Support-side adapter configuration. Request identity, input, streaming and
|
|
5
|
+
* budgets belong to the adapter; these types only declare what the App may configure and which
|
|
6
|
+
* failures the adapter reports. Nothing here performs I/O.
|
|
7
|
+
*
|
|
8
|
+
* Exports: `ModelProviderErrorCode`, `ModelProviderFailure`, `ProviderReasoningLevel`,
|
|
9
|
+
* `ProviderReasoningStrategy`, `CompatibleModelConfig`, `CompatibleModelPorts`, `ModelChoiceIndex`,
|
|
10
|
+
* `CompatibleModelProviderOptions`, plus the provider observation type re-exports.
|
|
11
|
+
*/
|
|
12
|
+
import type { CompletionPolicy } from './completion.js';
|
|
1
13
|
import type { ProviderObserver } from './provider-observer.js';
|
|
2
|
-
|
|
14
|
+
/** Stable failure classification reported by the compatible provider adapter. */
|
|
15
|
+
export type ModelProviderErrorCode =
|
|
16
|
+
/** Required configuration is missing, for example an empty API key. */
|
|
17
|
+
'MODEL_NOT_CONFIGURED'
|
|
18
|
+
/** Upstream rejected the credentials (HTTP 401/403). */
|
|
19
|
+
| 'MODEL_AUTH'
|
|
20
|
+
/** Upstream reported exhausted balance or quota (HTTP 402). */
|
|
21
|
+
| 'MODEL_BALANCE'
|
|
22
|
+
/** Upstream is rate limiting or overloaded (HTTP 429). */
|
|
23
|
+
| 'MODEL_BUSY'
|
|
24
|
+
/** The request itself is invalid (HTTP 400/404 or configuration validation). */
|
|
25
|
+
| 'MODEL_CONFIG'
|
|
26
|
+
/** Unclassified upstream failure. */
|
|
27
|
+
| 'MODEL_UPSTREAM'
|
|
28
|
+
/** Response body could not be parsed as the expected wire format. */
|
|
29
|
+
| 'MODEL_FORMAT'
|
|
30
|
+
/** The stream violated the protocol, for example data after the finish marker. */
|
|
31
|
+
| 'MODEL_PROTOCOL'
|
|
32
|
+
/** The provider stopped because the output token limit was reached. */
|
|
33
|
+
| 'MODEL_OUTPUT_LIMIT'
|
|
34
|
+
/** The stream ended without a usable payload. */
|
|
35
|
+
| 'MODEL_INCOMPLETE';
|
|
36
|
+
/** Failure detail passed to the App's error factory. */
|
|
3
37
|
export interface ModelProviderFailure {
|
|
4
38
|
code: ModelProviderErrorCode;
|
|
39
|
+
/** HTTP status when the failure came from a response. */
|
|
5
40
|
status?: number;
|
|
41
|
+
/** `eof` marks a stream that ended before the finish marker. */
|
|
6
42
|
reason?: 'eof';
|
|
7
43
|
}
|
|
8
44
|
/** Supplier wire shape is explicit; levels express requested effort, not measured quality. */
|
|
9
45
|
export type ProviderReasoningLevel = 'off' | 'low' | 'medium' | 'high';
|
|
46
|
+
/**
|
|
47
|
+
* How a reasoning level is translated into request fields.
|
|
48
|
+
*
|
|
49
|
+
* `requestBody` entries override generated fields, so a host can correct a provider that expects
|
|
50
|
+
* a different shape.
|
|
51
|
+
*/
|
|
10
52
|
export type ProviderReasoningStrategy = {
|
|
11
53
|
readonly level: ProviderReasoningLevel;
|
|
12
|
-
} &
|
|
54
|
+
} &
|
|
55
|
+
/** Uses the fixed field shape of the named format, with no extra mapping or budgets. */
|
|
56
|
+
({
|
|
13
57
|
readonly format: 'reasoning-effort' | 'thinking' | 'enable-thinking';
|
|
14
58
|
readonly map?: never;
|
|
15
59
|
readonly budgets?: never;
|
|
16
|
-
}
|
|
60
|
+
}
|
|
61
|
+
/** Sends `thinking.budget_tokens`; defaults are 1024/4096/8192 for low/medium/high. */
|
|
62
|
+
| {
|
|
17
63
|
readonly format: 'thinking-budget';
|
|
18
64
|
readonly budgets?: Readonly<Partial<Record<Exclude<ProviderReasoningLevel, 'off'>, number>>>;
|
|
19
65
|
readonly map?: never;
|
|
20
|
-
}
|
|
66
|
+
}
|
|
67
|
+
/** Delegates field generation to the App mapper; must be synchronous. */
|
|
68
|
+
| {
|
|
21
69
|
readonly format: 'custom';
|
|
22
70
|
map(level: ProviderReasoningLevel): Readonly<Record<string, unknown>>;
|
|
23
71
|
readonly budgets?: never;
|
|
24
72
|
});
|
|
73
|
+
/** Configuration of one OpenAI-compatible endpoint. */
|
|
25
74
|
export interface CompatibleModelConfig {
|
|
75
|
+
/** Endpoint base URL, for example the chat-completions root. */
|
|
26
76
|
baseUrl: string;
|
|
77
|
+
/** Credential sent as a bearer token; must be non-empty at request time. */
|
|
27
78
|
apiKey: string;
|
|
79
|
+
/** Model name sent with the request. */
|
|
28
80
|
model: string;
|
|
29
81
|
/** Optional provider ceiling; otherwise use the call's limit or the Core default. */
|
|
30
82
|
maxOutputTokens?: number;
|
|
31
|
-
/** Provider
|
|
83
|
+
/** Provider extensions. Identity, input, streaming and budget stay in the adapter. */
|
|
32
84
|
requestBody?: Readonly<Record<string, unknown>> & {
|
|
33
85
|
readonly model?: never;
|
|
34
86
|
readonly messages?: never;
|
|
@@ -37,15 +89,23 @@ export interface CompatibleModelConfig {
|
|
|
37
89
|
readonly max_completion_tokens?: never;
|
|
38
90
|
readonly toJSON?: never;
|
|
39
91
|
};
|
|
92
|
+
/** Sampling temperature forwarded to the provider. */
|
|
40
93
|
temperature?: number;
|
|
41
94
|
/** Generated reasoning fields are overridden by explicit requestBody fields. */
|
|
42
95
|
reasoning?: ProviderReasoningStrategy;
|
|
43
96
|
}
|
|
97
|
+
/** Adapter ports the App may override without replacing the provider. */
|
|
44
98
|
export interface CompatibleModelPorts {
|
|
99
|
+
/** Fetch implementation; defaults to the global `fetch`. */
|
|
45
100
|
request?: typeof fetch;
|
|
101
|
+
/** Builds the thrown error for a classified failure. */
|
|
46
102
|
error?(failure: ModelProviderFailure): Error;
|
|
103
|
+
/** Prefix a JSON instruction when the prompt does not already mention JSON. */
|
|
47
104
|
ensureJsonInstruction?: boolean;
|
|
105
|
+
/** Accept an empty JSON response instead of reporting `MODEL_INCOMPLETE`. */
|
|
48
106
|
allowEmptyJson?: boolean;
|
|
107
|
+
/** Decide whether a finished stream satisfies the request; defaults to the legacy rules. */
|
|
108
|
+
completionPolicy?: CompletionPolicy;
|
|
49
109
|
/** Optional Support observations, collected by the caller independently of Core diagnostics. */
|
|
50
110
|
observer?: ProviderObserver;
|
|
51
111
|
}
|
|
@@ -53,13 +113,18 @@ export interface CompatibleModelPorts {
|
|
|
53
113
|
export interface ModelChoiceIndex {
|
|
54
114
|
index: number;
|
|
55
115
|
}
|
|
56
|
-
export type { ProviderObserver, ProviderObservation, ProviderEventName, ProviderEventPayloads, ProviderEventDescriptor, ProviderErrorCapture } from './provider-observer.js';
|
|
116
|
+
export type { ProviderObserver, ProviderObservation, ProviderEventName, ProviderEventPayloads, ProviderEventDescriptor, ProviderErrorCapture, } from './provider-observer.js';
|
|
117
|
+
/** Construction options for a compatible provider. */
|
|
57
118
|
export interface CompatibleModelProviderOptions {
|
|
119
|
+
/** Static configuration, or a factory evaluated at each request boundary. */
|
|
58
120
|
readonly config: CompatibleModelConfig | (() => CompatibleModelConfig);
|
|
121
|
+
/** Port overrides other than observation and error mapping, which have their own keys. */
|
|
59
122
|
readonly ports?: Omit<CompatibleModelPorts, 'observer' | 'error'>;
|
|
123
|
+
/** Provider observation sink. */
|
|
60
124
|
readonly observe?: {
|
|
61
125
|
readonly provider?: ProviderObserver;
|
|
62
126
|
};
|
|
127
|
+
/** Error factory for classified failures. */
|
|
63
128
|
readonly errors?: {
|
|
64
129
|
readonly failure?: (failure: ModelProviderFailure) => Error;
|
|
65
130
|
};
|