mayura 0.1.0-dev.0 → 1.0.0-rc.2
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/README.md +152 -35
- package/docs/README.md +82 -0
- package/docs/ai-agents.md +73 -0
- package/docs/cli/dev.md +111 -0
- package/docs/cli/init.md +192 -0
- package/docs/cli/operations.md +235 -0
- package/docs/cli/overview.md +129 -0
- package/docs/cli/run.md +182 -0
- package/docs/concepts/agent.md +197 -0
- package/docs/concepts/costs-and-budgets.md +177 -0
- package/docs/concepts/outcomes.md +154 -0
- package/docs/concepts/permissions.md +155 -0
- package/docs/concepts/runtime.md +172 -0
- package/docs/concepts/tools.md +202 -0
- package/docs/concepts/workflows.md +134 -0
- package/docs/guides/approvals-and-human-input.md +278 -0
- package/docs/guides/artifacts.md +123 -0
- package/docs/guides/child-agents.md +158 -0
- package/docs/guides/code-mode.md +233 -0
- package/docs/guides/deployment.md +644 -0
- package/docs/guides/durable-workflows.md +463 -0
- package/docs/guides/guardrails.md +205 -0
- package/docs/guides/helpers.md +176 -0
- package/docs/guides/lifecycle-hooks.md +187 -0
- package/docs/guides/mcp.md +123 -0
- package/docs/guides/memory-and-context.md +293 -0
- package/docs/guides/model-providers.md +371 -0
- package/docs/guides/model-routing.md +138 -0
- package/docs/guides/observability.md +238 -0
- package/docs/guides/operator-console.md +140 -0
- package/docs/guides/react.md +276 -0
- package/docs/guides/sagas-and-loops.md +212 -0
- package/docs/guides/server-and-client.md +559 -0
- package/docs/guides/skills.md +152 -0
- package/docs/guides/storage.md +251 -0
- package/docs/guides/streaming.md +146 -0
- package/docs/guides/terminal.md +166 -0
- package/docs/guides/testing.md +220 -0
- package/docs/guides/vision.md +155 -0
- package/docs/guides/webhooks.md +172 -0
- package/docs/guides/workflow-composition.md +141 -0
- package/docs/guides/workflow-operations.md +269 -0
- package/docs/installation.md +90 -0
- package/docs/introduction.md +74 -0
- package/docs/project/credits.md +78 -0
- package/docs/project/security.md +178 -0
- package/docs/project/support.md +91 -0
- package/docs/project/versioning.md +122 -0
- package/docs/quickstart.md +190 -0
- package/docs/reference/entry-points.md +146 -0
- package/lib/adapter-code-docker/dist/index.d.ts +8 -1
- package/lib/adapter-code-docker/dist/index.d.ts.map +1 -1
- package/lib/adapter-code-docker/dist/index.js +64 -67
- package/lib/adapter-code-docker/dist/index.js.map +1 -1
- package/lib/adapter-code-docker/dist/options.d.ts +15 -0
- package/lib/adapter-code-docker/dist/options.d.ts.map +1 -0
- package/lib/adapter-code-docker/dist/options.js +56 -0
- package/lib/adapter-code-docker/dist/options.js.map +1 -0
- package/lib/adapter-code-docker/image/Dockerfile +4 -2
- package/lib/adapter-code-docker/package.json +1 -1
- package/lib/adapter-code-docker/src/index.ts +63 -65
- package/lib/adapter-code-docker/src/options.ts +51 -0
- package/lib/adapter-code-quickjs/dist/index.d.ts +16 -4
- package/lib/adapter-code-quickjs/dist/index.d.ts.map +1 -1
- package/lib/adapter-code-quickjs/dist/index.js +94 -50
- package/lib/adapter-code-quickjs/dist/index.js.map +1 -1
- package/lib/adapter-code-quickjs/dist/worker-command.d.ts +27 -0
- package/lib/adapter-code-quickjs/dist/worker-command.d.ts.map +1 -0
- package/lib/adapter-code-quickjs/dist/worker-command.js +66 -0
- package/lib/adapter-code-quickjs/dist/worker-command.js.map +1 -0
- package/lib/adapter-code-quickjs/dist/worker.js +421 -104
- package/lib/adapter-code-quickjs/dist/worker.js.map +1 -1
- package/lib/adapter-code-quickjs/package.json +1 -1
- package/lib/adapter-code-quickjs/src/index.ts +88 -44
- package/lib/adapter-code-quickjs/src/worker-command.ts +68 -0
- package/lib/adapter-code-quickjs/src/worker.ts +315 -89
- package/lib/adapter-mcp/package.json +1 -1
- package/lib/artifacts/dist/contracts.d.ts +6 -2
- package/lib/artifacts/dist/contracts.d.ts.map +1 -1
- package/lib/artifacts/dist/contracts.js.map +1 -1
- package/lib/artifacts/dist/index.d.ts +1 -0
- package/lib/artifacts/dist/index.d.ts.map +1 -1
- package/lib/artifacts/dist/index.js +1 -0
- package/lib/artifacts/dist/index.js.map +1 -1
- package/lib/artifacts/dist/local-store.d.ts.map +1 -1
- package/lib/artifacts/dist/local-store.js +4 -7
- package/lib/artifacts/dist/local-store.js.map +1 -1
- package/lib/artifacts/dist/media.d.ts +11 -0
- package/lib/artifacts/dist/media.d.ts.map +1 -0
- package/lib/artifacts/dist/media.js +18 -0
- package/lib/artifacts/dist/media.js.map +1 -0
- package/lib/artifacts/package.json +1 -1
- package/lib/artifacts/src/contracts.ts +6 -2
- package/lib/artifacts/src/index.ts +1 -0
- package/lib/artifacts/src/local-store.ts +5 -7
- package/lib/artifacts/src/media.ts +20 -0
- package/lib/cli/dist/agent-guide.d.ts +10 -0
- package/lib/cli/dist/agent-guide.d.ts.map +1 -0
- package/lib/cli/dist/agent-guide.js +48 -0
- package/lib/cli/dist/agent-guide.js.map +1 -0
- package/lib/cli/dist/application.d.ts +24 -0
- package/lib/cli/dist/application.d.ts.map +1 -1
- package/lib/cli/dist/application.js +21 -0
- package/lib/cli/dist/application.js.map +1 -1
- package/lib/cli/dist/bin.js +26 -6
- package/lib/cli/dist/bin.js.map +1 -1
- package/lib/cli/dist/dev.d.ts.map +1 -1
- package/lib/cli/dist/dev.js +7 -1
- package/lib/cli/dist/dev.js.map +1 -1
- package/lib/cli/dist/index.d.ts +3 -3
- package/lib/cli/dist/index.d.ts.map +1 -1
- package/lib/cli/dist/index.js +19 -9
- package/lib/cli/dist/index.js.map +1 -1
- package/lib/cli/dist/interactive.d.ts.map +1 -1
- package/lib/cli/dist/interactive.js +52 -11
- package/lib/cli/dist/interactive.js.map +1 -1
- package/lib/cli/dist/operations.d.ts +25 -2
- package/lib/cli/dist/operations.d.ts.map +1 -1
- package/lib/cli/dist/operations.js +125 -12
- package/lib/cli/dist/operations.js.map +1 -1
- package/lib/cli/dist/output.d.ts.map +1 -1
- package/lib/cli/dist/output.js +3 -0
- package/lib/cli/dist/output.js.map +1 -1
- package/lib/cli/dist/providers.d.ts +34 -4
- package/lib/cli/dist/providers.d.ts.map +1 -1
- package/lib/cli/dist/providers.js +26 -5
- package/lib/cli/dist/providers.js.map +1 -1
- package/lib/cli/package.json +1 -1
- package/lib/cli/src/agent-guide.ts +47 -0
- package/lib/cli/src/application.ts +24 -0
- package/lib/cli/src/bin.ts +22 -5
- package/lib/cli/src/dev.ts +5 -1
- package/lib/cli/src/index.ts +18 -10
- package/lib/cli/src/interactive.ts +44 -12
- package/lib/cli/src/operations.ts +82 -12
- package/lib/cli/src/output.ts +3 -0
- package/lib/cli/src/providers.ts +45 -10
- package/lib/cli/starters/approval-workflow/dot-env.example +11 -0
- package/lib/cli/starters/approval-workflow/package.json +1 -2
- package/lib/cli/starters/approval-workflow/src/config.ts +25 -7
- package/lib/cli/starters/approval-workflow/src/intake.ts +1 -2
- package/lib/cli/starters/approval-workflow/src/model.ts +11 -4
- package/lib/cli/starters/approval-workflow/src/workflow.ts +1 -2
- package/lib/cli/starters/cli-agent/README.md +121 -0
- package/lib/cli/starters/cli-agent/dot-env.example +37 -0
- package/lib/cli/starters/cli-agent/dot-github/workflows/ci.yml +13 -0
- package/lib/cli/starters/cli-agent/dot-gitignore +10 -0
- package/lib/cli/starters/cli-agent/mayura.project.json +15 -0
- package/lib/cli/starters/cli-agent/package.json +28 -0
- package/lib/cli/starters/cli-agent/skills/release-notes/SKILL.md +18 -0
- package/lib/cli/starters/cli-agent/skills/release-notes/references/example.md +12 -0
- package/lib/cli/starters/cli-agent/src/assistant.ts +124 -0
- package/lib/cli/starters/cli-agent/src/cli.ts +72 -0
- package/lib/cli/starters/cli-agent/src/config.ts +117 -0
- package/lib/cli/starters/cli-agent/src/model.ts +34 -0
- package/lib/cli/starters/cli-agent/src/workspace.ts +170 -0
- package/lib/cli/starters/cli-agent/test/assistant.test.ts +205 -0
- package/lib/cli/starters/cli-agent/tsconfig.json +20 -0
- package/lib/cli/starters/event-automation/README.md +4 -3
- package/lib/cli/starters/event-automation/dot-env.example +11 -0
- package/lib/cli/starters/event-automation/package.json +1 -2
- package/lib/cli/starters/event-automation/src/config.ts +25 -7
- package/lib/cli/starters/event-automation/src/ingress.ts +3 -5
- package/lib/cli/starters/event-automation/src/model.ts +11 -4
- package/lib/cli/starters/event-automation/src/send-sample.ts +1 -1
- package/lib/cli/starters/event-automation/src/tracker/main.ts +1 -1
- package/lib/cli/starters/event-automation/src/tracker/mcp-server.ts +1 -1
- package/lib/cli/starters/event-automation/src/tracker/tickets.ts +1 -1
- package/lib/cli/starters/event-automation/src/tracker-tools.ts +1 -1
- package/lib/cli/starters/event-automation/src/triage.ts +15 -22
- package/lib/cli/starters/event-automation/src/workflows.ts +1 -1
- package/lib/cli/starters/event-automation/test/automation.test.ts +3 -3
- package/lib/cli/starters/research-team/README.md +2 -2
- package/lib/cli/starters/research-team/dot-env.example +11 -0
- package/lib/cli/starters/research-team/package.json +1 -2
- package/lib/cli/starters/research-team/src/config.ts +25 -7
- package/lib/cli/starters/research-team/src/desk.ts +1 -2
- package/lib/cli/starters/research-team/src/library/index.ts +1 -2
- package/lib/cli/starters/research-team/src/model.ts +11 -4
- package/lib/cli/starters/research-team/src/services.ts +1 -1
- package/lib/cli/starters/research-team/src/team.ts +1 -2
- package/lib/cli/starters/research-team/src/workflow.ts +45 -59
- package/lib/cli/starters/support-agent/dot-env.example +11 -0
- package/lib/cli/starters/support-agent/package.json +1 -2
- package/lib/cli/starters/support-agent/src/assistant.ts +5 -5
- package/lib/cli/starters/support-agent/src/config.ts +25 -7
- package/lib/cli/starters/support-agent/src/guardrails.ts +3 -1
- package/lib/cli/starters/support-agent/src/model.ts +11 -4
- package/lib/cli/starters/support-agent/src/returns.ts +1 -2
- package/lib/cli/starters/support-agent/test/support.test.ts +25 -1
- package/lib/cli/templates/basic-agent.ts +1 -2
- package/lib/cli/templates/capability-policy.ts +1 -2
- package/lib/cli/templates/code-mode-workflow.ts +1 -1
- package/lib/cli/templates/durable-approval.ts +1 -1
- package/lib/cli/templates/parallel-research.ts +1 -2
- package/lib/cli/templates/typed-tool-runner.ts +1 -2
- package/lib/client/dist/forms.d.ts.map +1 -1
- package/lib/client/dist/forms.js +3 -4
- package/lib/client/dist/forms.js.map +1 -1
- package/lib/client/dist/headless.d.ts +3 -1
- package/lib/client/dist/headless.d.ts.map +1 -1
- package/lib/client/dist/headless.js +10 -6
- package/lib/client/dist/headless.js.map +1 -1
- package/lib/client/dist/index.d.ts +95 -6
- package/lib/client/dist/index.d.ts.map +1 -1
- package/lib/client/dist/index.js +397 -124
- package/lib/client/dist/index.js.map +1 -1
- package/lib/client/dist/workflows.d.ts +1 -1
- package/lib/client/dist/workflows.d.ts.map +1 -1
- package/lib/client/dist/workflows.js +7 -6
- package/lib/client/dist/workflows.js.map +1 -1
- package/lib/client/package.json +1 -1
- package/lib/client/src/forms.ts +3 -4
- package/lib/client/src/headless.ts +13 -7
- package/lib/client/src/index.ts +344 -74
- package/lib/client/src/workflows.ts +8 -7
- package/lib/client-react/package.json +1 -1
- package/lib/code-mode/dist/index.d.ts +32 -1
- package/lib/code-mode/dist/index.d.ts.map +1 -1
- package/lib/code-mode/dist/index.js +289 -221
- package/lib/code-mode/dist/index.js.map +1 -1
- package/lib/code-mode/package.json +1 -1
- package/lib/code-mode/src/index.ts +288 -184
- package/lib/code-mode-workflows/package.json +1 -1
- package/lib/context/package.json +1 -1
- package/lib/core/dist/budget.d.ts.map +1 -1
- package/lib/core/dist/budget.js +17 -2
- package/lib/core/dist/budget.js.map +1 -1
- package/lib/core/dist/contracts.d.ts +57 -0
- package/lib/core/dist/contracts.d.ts.map +1 -1
- package/lib/core/dist/contracts.js +36 -0
- package/lib/core/dist/contracts.js.map +1 -1
- package/lib/core/dist/destination.d.ts +12 -0
- package/lib/core/dist/destination.d.ts.map +1 -0
- package/lib/core/dist/destination.js +37 -0
- package/lib/core/dist/destination.js.map +1 -0
- package/lib/core/dist/event-stream.d.ts +1 -1
- package/lib/core/dist/event-stream.d.ts.map +1 -1
- package/lib/core/dist/event-stream.js +7 -0
- package/lib/core/dist/event-stream.js.map +1 -1
- package/lib/core/dist/host.d.ts +3 -0
- package/lib/core/dist/host.d.ts.map +1 -1
- package/lib/core/dist/host.js +3 -0
- package/lib/core/dist/host.js.map +1 -1
- package/lib/core/dist/index.d.ts +2 -0
- package/lib/core/dist/index.d.ts.map +1 -1
- package/lib/core/dist/index.js +2 -0
- package/lib/core/dist/index.js.map +1 -1
- package/lib/core/dist/media.d.ts +98 -0
- package/lib/core/dist/media.d.ts.map +1 -0
- package/lib/core/dist/media.js +227 -0
- package/lib/core/dist/media.js.map +1 -0
- package/lib/core/dist/model-schema.d.ts +37 -0
- package/lib/core/dist/model-schema.d.ts.map +1 -0
- package/lib/core/dist/model-schema.js +154 -0
- package/lib/core/dist/model-schema.js.map +1 -0
- package/lib/core/package.json +1 -1
- package/lib/core/src/budget.ts +17 -2
- package/lib/core/src/contracts.ts +71 -3
- package/lib/core/src/destination.ts +33 -0
- package/lib/core/src/event-stream.ts +5 -1
- package/lib/core/src/host.ts +3 -0
- package/lib/core/src/index.ts +2 -0
- package/lib/core/src/media.ts +228 -0
- package/lib/core/src/model-schema.ts +129 -0
- package/lib/exporter-otlp/dist/otlp-http-json.js +1 -1
- package/lib/exporter-otlp/dist/otlp-http-json.js.map +1 -1
- package/lib/exporter-otlp/dist/signals.js +2 -2
- package/lib/exporter-otlp/dist/signals.js.map +1 -1
- package/lib/exporter-otlp/package.json +1 -1
- package/lib/exporter-otlp/src/otlp-http-json.ts +1 -1
- package/lib/exporter-otlp/src/signals.ts +2 -2
- package/lib/guardrails/package.json +1 -1
- package/lib/helpers/package.json +1 -1
- package/lib/memory/dist/index.js +1 -1
- package/lib/memory/dist/index.js.map +1 -1
- package/lib/memory/dist/native.d.ts.map +1 -1
- package/lib/memory/dist/native.js +4 -3
- package/lib/memory/dist/native.js.map +1 -1
- package/lib/memory/package.json +1 -1
- package/lib/memory/src/index.ts +1 -1
- package/lib/memory/src/native.ts +4 -3
- package/lib/memory-remote/package.json +1 -1
- package/lib/observability/package.json +1 -1
- package/lib/provider-anthropic/dist/index.d.ts +36 -3
- package/lib/provider-anthropic/dist/index.d.ts.map +1 -1
- package/lib/provider-anthropic/dist/index.js +128 -78
- package/lib/provider-anthropic/dist/index.js.map +1 -1
- package/lib/provider-anthropic/package.json +1 -1
- package/lib/provider-anthropic/src/index.ts +152 -76
- package/lib/provider-openai/dist/index.d.ts +71 -4
- package/lib/provider-openai/dist/index.d.ts.map +1 -1
- package/lib/provider-openai/dist/index.js +259 -96
- package/lib/provider-openai/dist/index.js.map +1 -1
- package/lib/provider-openai/package.json +1 -1
- package/lib/provider-openai/src/index.ts +282 -84
- package/lib/runtime/dist/agent.d.ts +18 -1
- package/lib/runtime/dist/agent.d.ts.map +1 -1
- package/lib/runtime/dist/agent.js +59 -3
- package/lib/runtime/dist/agent.js.map +1 -1
- package/lib/runtime/dist/composition.d.ts.map +1 -1
- package/lib/runtime/dist/composition.js +2 -1
- package/lib/runtime/dist/composition.js.map +1 -1
- package/lib/runtime/dist/hooks.d.ts +15 -3
- package/lib/runtime/dist/hooks.d.ts.map +1 -1
- package/lib/runtime/dist/hooks.js.map +1 -1
- package/lib/runtime/dist/index.d.ts +1 -1
- package/lib/runtime/dist/index.d.ts.map +1 -1
- package/lib/runtime/dist/index.js.map +1 -1
- package/lib/runtime/dist/response.d.ts +7 -1
- package/lib/runtime/dist/response.d.ts.map +1 -1
- package/lib/runtime/dist/response.js +23 -2
- package/lib/runtime/dist/response.js.map +1 -1
- package/lib/runtime/dist/router.d.ts +10 -3
- package/lib/runtime/dist/router.d.ts.map +1 -1
- package/lib/runtime/dist/router.js +45 -8
- package/lib/runtime/dist/router.js.map +1 -1
- package/lib/runtime/dist/runtime.d.ts +9 -1
- package/lib/runtime/dist/runtime.d.ts.map +1 -1
- package/lib/runtime/dist/runtime.js +50 -22
- package/lib/runtime/dist/runtime.js.map +1 -1
- package/lib/runtime/package.json +1 -1
- package/lib/runtime/src/agent.ts +69 -3
- package/lib/runtime/src/composition.ts +2 -1
- package/lib/runtime/src/hooks.ts +10 -4
- package/lib/runtime/src/index.ts +1 -1
- package/lib/runtime/src/response.ts +20 -2
- package/lib/runtime/src/router.ts +43 -10
- package/lib/runtime/src/runtime.ts +58 -27
- package/lib/sdk/dist/index.d.ts +9 -1
- package/lib/sdk/dist/index.d.ts.map +1 -1
- package/lib/sdk/dist/index.js +9 -1
- package/lib/sdk/dist/index.js.map +1 -1
- package/lib/sdk/package.json +1 -1
- package/lib/sdk/src/index.ts +9 -1
- package/lib/server/dist/index.d.ts +201 -3
- package/lib/server/dist/index.d.ts.map +1 -1
- package/lib/server/dist/index.js +701 -149
- package/lib/server/dist/index.js.map +1 -1
- package/lib/server/dist/inspector-bundle.d.ts +1 -1
- package/lib/server/dist/inspector-bundle.d.ts.map +1 -1
- package/lib/server/dist/inspector-bundle.js +4 -4
- package/lib/server/dist/inspector-bundle.js.map +1 -1
- package/lib/server/package.json +1 -1
- package/lib/server/src/index.ts +611 -135
- package/lib/server/src/inspector-bundle.ts +4 -4
- package/lib/server-node/dist/hardening.d.ts +1 -1
- package/lib/server-node/dist/hardening.d.ts.map +1 -1
- package/lib/server-node/dist/hardening.js +4 -2
- package/lib/server-node/dist/hardening.js.map +1 -1
- package/lib/server-node/dist/index.d.ts +2 -1
- package/lib/server-node/dist/index.d.ts.map +1 -1
- package/lib/server-node/dist/index.js.map +1 -1
- package/lib/server-node/dist/probe.js +2 -2
- package/lib/server-node/dist/probe.js.map +1 -1
- package/lib/server-node/dist/production.d.ts +8 -1
- package/lib/server-node/dist/production.d.ts.map +1 -1
- package/lib/server-node/dist/production.js +15 -2
- package/lib/server-node/dist/production.js.map +1 -1
- package/lib/server-node/package.json +1 -1
- package/lib/server-node/src/hardening.ts +5 -3
- package/lib/server-node/src/index.ts +2 -1
- package/lib/server-node/src/probe.ts +2 -2
- package/lib/server-node/src/production.ts +23 -3
- package/lib/skills/dist/index.d.ts +81 -0
- package/lib/skills/dist/index.d.ts.map +1 -0
- package/lib/skills/dist/index.js +311 -0
- package/lib/skills/dist/index.js.map +1 -0
- package/lib/skills/package.json +5 -0
- package/lib/skills/src/index.ts +260 -0
- package/lib/storage/dist/index.d.ts +1 -1
- package/lib/storage/dist/index.d.ts.map +1 -1
- package/lib/storage/dist/index.js.map +1 -1
- package/lib/storage/package.json +1 -1
- package/lib/storage/src/index.ts +1 -1
- package/lib/storage-contracts/dist/contracts.d.ts +12 -5
- package/lib/storage-contracts/dist/contracts.d.ts.map +1 -1
- package/lib/storage-contracts/dist/contracts.js +24 -6
- package/lib/storage-contracts/dist/contracts.js.map +1 -1
- package/lib/storage-contracts/dist/index.d.ts +2 -0
- package/lib/storage-contracts/dist/index.d.ts.map +1 -1
- package/lib/storage-contracts/dist/index.js +2 -0
- package/lib/storage-contracts/dist/index.js.map +1 -1
- package/lib/storage-contracts/dist/memory-contracts.js +1 -1
- package/lib/storage-contracts/dist/memory-contracts.js.map +1 -1
- package/lib/storage-contracts/dist/run-records.d.ts +100 -0
- package/lib/storage-contracts/dist/run-records.d.ts.map +1 -0
- package/lib/storage-contracts/dist/run-records.js +464 -0
- package/lib/storage-contracts/dist/run-records.js.map +1 -0
- package/lib/storage-contracts/dist/schema-digest.d.ts +17 -0
- package/lib/storage-contracts/dist/schema-digest.d.ts.map +1 -0
- package/lib/storage-contracts/dist/schema-digest.js +94 -0
- package/lib/storage-contracts/dist/schema-digest.js.map +1 -0
- package/lib/storage-contracts/dist/submission-journal.js +1 -1
- package/lib/storage-contracts/dist/submission-journal.js.map +1 -1
- package/lib/storage-contracts/dist/workflow-format5.d.ts +30 -2
- package/lib/storage-contracts/dist/workflow-format5.d.ts.map +1 -1
- package/lib/storage-contracts/dist/workflow-format5.js +57 -5
- package/lib/storage-contracts/dist/workflow-format5.js.map +1 -1
- package/lib/storage-contracts/package.json +1 -1
- package/lib/storage-contracts/src/contracts.ts +29 -5
- package/lib/storage-contracts/src/index.ts +2 -0
- package/lib/storage-contracts/src/memory-contracts.ts +1 -1
- package/lib/storage-contracts/src/run-records.ts +365 -0
- package/lib/storage-contracts/src/schema-digest.ts +71 -0
- package/lib/storage-contracts/src/submission-journal.ts +1 -1
- package/lib/storage-contracts/src/workflow-format5.ts +70 -6
- package/lib/storage-postgres/dist/index.d.ts +1 -1
- package/lib/storage-postgres/dist/index.d.ts.map +1 -1
- package/lib/storage-postgres/dist/index.js.map +1 -1
- package/lib/storage-postgres/dist/postgres.d.ts +15 -0
- package/lib/storage-postgres/dist/postgres.d.ts.map +1 -1
- package/lib/storage-postgres/dist/postgres.js +18 -7
- package/lib/storage-postgres/dist/postgres.js.map +1 -1
- package/lib/storage-postgres/package.json +1 -1
- package/lib/storage-postgres/src/index.ts +1 -1
- package/lib/storage-postgres/src/postgres.ts +34 -8
- package/lib/storage-sql/dist/aggregate-session.js +1 -1
- package/lib/storage-sql/dist/aggregate-session.js.map +1 -1
- package/lib/storage-sql/dist/scheduled-database.js +1 -1
- package/lib/storage-sql/dist/scheduled-database.js.map +1 -1
- package/lib/storage-sql/dist/workflow-tree-validation.js +1 -1
- package/lib/storage-sql/dist/workflow-tree-validation.js.map +1 -1
- package/lib/storage-sql/package.json +1 -1
- package/lib/storage-sql/src/aggregate-session.ts +1 -1
- package/lib/storage-sql/src/scheduled-database.ts +1 -1
- package/lib/storage-sql/src/workflow-tree-validation.ts +1 -1
- package/lib/storage-sqlite/dist/sqlite-database.js +4 -4
- package/lib/storage-sqlite/dist/sqlite-database.js.map +1 -1
- package/lib/storage-sqlite/dist/sqlite-worker.js +2 -2
- package/lib/storage-sqlite/dist/sqlite-worker.js.map +1 -1
- package/lib/storage-sqlite/dist/sqlite.js +1 -1
- package/lib/storage-sqlite/dist/sqlite.js.map +1 -1
- package/lib/storage-sqlite/package.json +1 -1
- package/lib/storage-sqlite/src/sqlite-database.ts +4 -4
- package/lib/storage-sqlite/src/sqlite-worker.ts +2 -2
- package/lib/storage-sqlite/src/sqlite.ts +1 -1
- package/lib/terminal/dist/index.d.ts +92 -0
- package/lib/terminal/dist/index.d.ts.map +1 -0
- package/lib/terminal/dist/index.js +397 -0
- package/lib/terminal/dist/index.js.map +1 -0
- package/lib/terminal/package.json +5 -0
- package/lib/terminal/src/index.ts +273 -0
- package/lib/testing/dist/index.d.ts +44 -1
- package/lib/testing/dist/index.d.ts.map +1 -1
- package/lib/testing/dist/index.js +63 -10
- package/lib/testing/dist/index.js.map +1 -1
- package/lib/testing/package.json +1 -1
- package/lib/testing/src/index.ts +83 -10
- package/lib/tools/dist/index.d.ts +32 -4
- package/lib/tools/dist/index.d.ts.map +1 -1
- package/lib/tools/dist/index.js +64 -11
- package/lib/tools/dist/index.js.map +1 -1
- package/lib/tools/package.json +1 -1
- package/lib/tools/src/index.ts +74 -13
- package/lib/workflows/dist/abandoned.d.ts +15 -0
- package/lib/workflows/dist/abandoned.d.ts.map +1 -0
- package/lib/workflows/dist/abandoned.js +33 -0
- package/lib/workflows/dist/abandoned.js.map +1 -0
- package/lib/workflows/dist/agent-step.d.ts +83 -0
- package/lib/workflows/dist/agent-step.d.ts.map +1 -0
- package/lib/workflows/dist/agent-step.js +161 -0
- package/lib/workflows/dist/agent-step.js.map +1 -0
- package/lib/workflows/dist/children-runtime.js +8 -8
- package/lib/workflows/dist/children-runtime.js.map +1 -1
- package/lib/workflows/dist/composite-fleet.js +2 -2
- package/lib/workflows/dist/composite-fleet.js.map +1 -1
- package/lib/workflows/dist/composite-host.d.ts.map +1 -1
- package/lib/workflows/dist/composite-host.js +26 -2
- package/lib/workflows/dist/composite-host.js.map +1 -1
- package/lib/workflows/dist/hook-relay.js +2 -2
- package/lib/workflows/dist/hook-relay.js.map +1 -1
- package/lib/workflows/dist/index.d.ts +1 -1
- package/lib/workflows/dist/index.d.ts.map +1 -1
- package/lib/workflows/dist/index.js.map +1 -1
- package/lib/workflows/dist/leadership.js +3 -3
- package/lib/workflows/dist/leadership.js.map +1 -1
- package/lib/workflows/dist/lifecycle-definition.d.ts +26 -4
- package/lib/workflows/dist/lifecycle-definition.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-definition.js +31 -6
- package/lib/workflows/dist/lifecycle-definition.js.map +1 -1
- package/lib/workflows/dist/lifecycle-fleet.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-fleet.js +9 -11
- package/lib/workflows/dist/lifecycle-fleet.js.map +1 -1
- package/lib/workflows/dist/lifecycle-host.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-host.js +26 -2
- package/lib/workflows/dist/lifecycle-host.js.map +1 -1
- package/lib/workflows/dist/lifecycle-human-transport.d.ts +22 -2
- package/lib/workflows/dist/lifecycle-human-transport.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-human-transport.js +115 -33
- package/lib/workflows/dist/lifecycle-human-transport.js.map +1 -1
- package/lib/workflows/dist/lifecycle-runtime.d.ts +62 -1
- package/lib/workflows/dist/lifecycle-runtime.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle-runtime.js +268 -64
- package/lib/workflows/dist/lifecycle-runtime.js.map +1 -1
- package/lib/workflows/dist/lifecycle.d.ts +6 -4
- package/lib/workflows/dist/lifecycle.d.ts.map +1 -1
- package/lib/workflows/dist/lifecycle.js +2 -0
- package/lib/workflows/dist/lifecycle.js.map +1 -1
- package/lib/workflows/dist/loop-runtime.d.ts.map +1 -1
- package/lib/workflows/dist/loop-runtime.js +38 -26
- package/lib/workflows/dist/loop-runtime.js.map +1 -1
- package/lib/workflows/dist/migration.d.ts +1 -1
- package/lib/workflows/dist/migration.d.ts.map +1 -1
- package/lib/workflows/dist/migration.js +3 -3
- package/lib/workflows/dist/migration.js.map +1 -1
- package/lib/workflows/dist/operator-transports.d.ts +24 -2
- package/lib/workflows/dist/operator-transports.d.ts.map +1 -1
- package/lib/workflows/dist/operator-transports.js +49 -3
- package/lib/workflows/dist/operator-transports.js.map +1 -1
- package/lib/workflows/dist/runtime.d.ts.map +1 -1
- package/lib/workflows/dist/runtime.js +34 -22
- package/lib/workflows/dist/runtime.js.map +1 -1
- package/lib/workflows/dist/saga-runtime.d.ts.map +1 -1
- package/lib/workflows/dist/saga-runtime.js +44 -30
- package/lib/workflows/dist/saga-runtime.js.map +1 -1
- package/lib/workflows/dist/scheduled-helpers.d.ts.map +1 -1
- package/lib/workflows/dist/scheduled-helpers.js +3 -3
- package/lib/workflows/dist/scheduled-helpers.js.map +1 -1
- package/lib/workflows/dist/storage-failure.d.ts +16 -0
- package/lib/workflows/dist/storage-failure.d.ts.map +1 -0
- package/lib/workflows/dist/storage-failure.js +38 -0
- package/lib/workflows/dist/storage-failure.js.map +1 -0
- package/lib/workflows/dist/sweep-position.d.ts +22 -0
- package/lib/workflows/dist/sweep-position.d.ts.map +1 -0
- package/lib/workflows/dist/sweep-position.js +45 -0
- package/lib/workflows/dist/sweep-position.js.map +1 -0
- package/lib/workflows/dist/traces.js +2 -2
- package/lib/workflows/dist/traces.js.map +1 -1
- package/lib/workflows/dist/worker.d.ts +31 -0
- package/lib/workflows/dist/worker.d.ts.map +1 -1
- package/lib/workflows/dist/worker.js +94 -0
- package/lib/workflows/dist/worker.js.map +1 -1
- package/lib/workflows/package.json +1 -1
- package/lib/workflows/src/abandoned.ts +32 -0
- package/lib/workflows/src/agent-step.ts +199 -0
- package/lib/workflows/src/children-runtime.ts +8 -8
- package/lib/workflows/src/composite-fleet.ts +2 -2
- package/lib/workflows/src/composite-host.ts +21 -3
- package/lib/workflows/src/hook-relay.ts +2 -2
- package/lib/workflows/src/index.ts +2 -1
- package/lib/workflows/src/leadership.ts +3 -3
- package/lib/workflows/src/lifecycle-definition.ts +50 -9
- package/lib/workflows/src/lifecycle-fleet.ts +7 -8
- package/lib/workflows/src/lifecycle-host.ts +21 -5
- package/lib/workflows/src/lifecycle-human-transport.ts +110 -26
- package/lib/workflows/src/lifecycle-runtime.ts +270 -60
- package/lib/workflows/src/lifecycle.ts +7 -0
- package/lib/workflows/src/loop-runtime.ts +34 -25
- package/lib/workflows/src/migration.ts +2 -2
- package/lib/workflows/src/operator-transports.ts +48 -4
- package/lib/workflows/src/runtime.ts +28 -22
- package/lib/workflows/src/saga-runtime.ts +38 -28
- package/lib/workflows/src/scheduled-helpers.ts +3 -3
- package/lib/workflows/src/storage-failure.ts +37 -0
- package/lib/workflows/src/sweep-position.ts +52 -0
- package/lib/workflows/src/traces.ts +2 -2
- package/lib/workflows/src/worker.ts +79 -1
- package/lib/workstream/dist/humans.d.ts +7 -3
- package/lib/workstream/dist/humans.d.ts.map +1 -1
- package/lib/workstream/dist/humans.js +13 -2
- package/lib/workstream/dist/humans.js.map +1 -1
- package/lib/workstream/dist/index.js +2 -2
- package/lib/workstream/dist/index.js.map +1 -1
- package/lib/workstream/dist/timers.js +2 -2
- package/lib/workstream/dist/timers.js.map +1 -1
- package/lib/workstream/dist/webhooks.d.ts +6 -2
- package/lib/workstream/dist/webhooks.d.ts.map +1 -1
- package/lib/workstream/dist/webhooks.js +17 -7
- package/lib/workstream/dist/webhooks.js.map +1 -1
- package/lib/workstream/package.json +1 -1
- package/lib/workstream/src/humans.ts +15 -5
- package/lib/workstream/src/index.ts +2 -2
- package/lib/workstream/src/timers.ts +2 -2
- package/lib/workstream/src/webhooks.ts +21 -8
- package/llms-full.txt +9766 -0
- package/llms.txt +92 -0
- package/package.json +18 -6
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
import { assertPositiveInteger,
|
|
2
|
-
import { readServerSentEvents, streamModelCall } from '../../core/dist/host.js';
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { assertPositiveInteger, jsonValue, MayuraError, MEDIA_TYPES, ModelProviderError } from '../../core/dist/index.js';
|
|
2
|
+
import { checkStrictDefinition, encodedMediaBytes, mediaDataUrl, modelToolNames, providerEndpoint, providerHeaders, providerHttpFailure, readServerSentEvents, streamModelCall, strictJsonSchema } from '../../core/dist/host.js';
|
|
3
|
+
/** Request fields the compatible adapter owns; `body` cannot set them. */
|
|
4
|
+
const ownedFields = new Set(['model', 'messages', 'tools', 'tool_choice', 'parallel_tool_calls', 'stream', 'stream_options', 'response_format', 'max_tokens', 'max_completion_tokens', 'n']);
|
|
5
|
+
/** Headers the compatible adapter owns; `headers` cannot set them. */
|
|
6
|
+
const ownedHeaders = new Set(['authorization', 'api-key', 'content-type', 'content-length', 'host', 'cookie', 'transfer-encoding', 'connection']);
|
|
7
|
+
/** A failed call, for a reason Mayura reports in its own words. The default is a response the adapter cannot use. */
|
|
8
|
+
const failed = (reason = 'invalid_response') => { throw new ModelProviderError(reason); };
|
|
9
|
+
/** The reason a caught failure carries, for charging known usage without losing why the call failed. */
|
|
10
|
+
const reasonOf = (error) => error instanceof ModelProviderError ? error.reason : 'invalid_response';
|
|
11
|
+
/** The adapter's own output schema, or the one sent with the request. */
|
|
12
|
+
function outputSchemaFor(fixed, requested) {
|
|
13
|
+
if (fixed !== undefined)
|
|
14
|
+
return fixed;
|
|
15
|
+
return requested === undefined ? failed('configuration') : strictJsonSchema(requested, 'The output schema');
|
|
16
|
+
}
|
|
17
|
+
function toolSchema(tool) {
|
|
18
|
+
if (!tool.inputJsonSchema)
|
|
19
|
+
throw new MayuraError('INVALID_CONFIG', `Tool "${tool.id}" has no inputJsonSchema.`);
|
|
20
|
+
return strictJsonSchema(tool.inputJsonSchema, `Tool "${tool.id}" input schema`);
|
|
5
21
|
}
|
|
6
|
-
const failed = (message) => { throw new ProviderFailure(message); };
|
|
7
22
|
function object(value) {
|
|
8
23
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
9
24
|
return failed();
|
|
@@ -14,34 +29,6 @@ function integer(value) {
|
|
|
14
29
|
return failed();
|
|
15
30
|
return value;
|
|
16
31
|
}
|
|
17
|
-
function strictSchema(schema) {
|
|
18
|
-
const copy = jsonValue(schema);
|
|
19
|
-
if (copy['type'] !== 'object')
|
|
20
|
-
throw new MayuraError('INVALID_CONFIG', 'Provider schemas require a root JSON object.');
|
|
21
|
-
const visit = (item) => {
|
|
22
|
-
if (item['type'] === 'object' || (Array.isArray(item['type']) && item['type'].includes('object'))) {
|
|
23
|
-
const properties = object(item['properties']);
|
|
24
|
-
const required = item['required'];
|
|
25
|
-
if (item['additionalProperties'] !== false || !Array.isArray(required) || required.some(key => typeof key !== 'string') || new Set(required).size !== required.length || Object.keys(properties).length !== required.length || Object.keys(properties).some(key => !required.includes(key))) {
|
|
26
|
-
throw new MayuraError('INVALID_CONFIG', 'Strict object schemas must require every property and prohibit additional properties.');
|
|
27
|
-
}
|
|
28
|
-
for (const child of Object.values(properties))
|
|
29
|
-
visit(object(child));
|
|
30
|
-
}
|
|
31
|
-
if (item['items'] !== undefined)
|
|
32
|
-
visit(object(item['items']));
|
|
33
|
-
for (const key of ['anyOf', 'allOf', 'oneOf'])
|
|
34
|
-
if (Array.isArray(item[key]))
|
|
35
|
-
for (const child of item[key])
|
|
36
|
-
visit(object(child));
|
|
37
|
-
for (const key of ['$defs', 'definitions'])
|
|
38
|
-
if (item[key] !== undefined)
|
|
39
|
-
for (const child of Object.values(object(item[key])))
|
|
40
|
-
visit(object(child));
|
|
41
|
-
};
|
|
42
|
-
visit(copy);
|
|
43
|
-
return freezeJson(copy);
|
|
44
|
-
}
|
|
45
32
|
async function abortable(operation, signal) {
|
|
46
33
|
if (signal.aborted) {
|
|
47
34
|
void operation.catch(() => undefined);
|
|
@@ -65,12 +52,10 @@ async function responseBody(response, limit, signal) {
|
|
|
65
52
|
if (!response.ok || response.redirected || !response.body) {
|
|
66
53
|
// Rejected responses still own a stream; release it without reading or exposing its contents.
|
|
67
54
|
void response.body?.cancel().catch(() => undefined);
|
|
68
|
-
if (
|
|
69
|
-
return failed('
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return failed('The model provider rate limit was reached. Retry only under the application retry and budget policy.');
|
|
73
|
-
}
|
|
55
|
+
if (response.redirected)
|
|
56
|
+
return failed('rejected');
|
|
57
|
+
if (!response.ok)
|
|
58
|
+
throw providerHttpFailure(response.status);
|
|
74
59
|
return failed();
|
|
75
60
|
}
|
|
76
61
|
const length = response.headers.get('content-length');
|
|
@@ -104,13 +89,44 @@ async function responseBody(response, limit, signal) {
|
|
|
104
89
|
reader.releaseLock();
|
|
105
90
|
}
|
|
106
91
|
}
|
|
107
|
-
|
|
92
|
+
/** A declared media capability, checked; undefined for none. */
|
|
93
|
+
function mediaOption(value, fallback) {
|
|
94
|
+
const capability = value === false ? undefined : value ?? fallback;
|
|
95
|
+
if (capability === undefined)
|
|
96
|
+
return undefined;
|
|
97
|
+
if (!capability || !Array.isArray(capability.types) || capability.types.some(type => !MEDIA_TYPES.includes(type)) || typeof capability.urls !== 'boolean') {
|
|
98
|
+
throw new MayuraError('INVALID_CONFIG', 'media must list media types and say whether URLs are taken.');
|
|
99
|
+
}
|
|
100
|
+
return Object.freeze({ types: Object.freeze([...new Set(capability.types)]), urls: capability.urls });
|
|
101
|
+
}
|
|
102
|
+
const ALL_MEDIA = Object.freeze({ types: MEDIA_TYPES, urls: true });
|
|
103
|
+
/** Tool-returned media follows the tool results in one user turn, since tool results themselves are text. */
|
|
104
|
+
const TOOL_MEDIA_NOTE = 'Media returned by the tool calls above:';
|
|
105
|
+
/**
|
|
106
|
+
* Responses input for `messages`, whose first is `request.messages[offset]`. Media appears as placeholders
|
|
107
|
+
* (`{ type: 'mayura_media', message, item }`) that `hydrateResponsesInput` replaces with the real parts, so the stored
|
|
108
|
+
* continuation never holds media bytes.
|
|
109
|
+
*/
|
|
110
|
+
function messagesToInput(messages, offset, hasContinuation, aliases) {
|
|
108
111
|
const result = [];
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
let pending = [];
|
|
113
|
+
const marker = (message, count) => Array.from({ length: count }, (_, item) => ({ type: 'mayura_media', message, item }));
|
|
114
|
+
const flush = () => { if (pending.length > 0) {
|
|
115
|
+
result.push({ role: 'user', content: [{ type: 'input_text', text: TOOL_MEDIA_NOTE }, ...pending] });
|
|
116
|
+
pending = [];
|
|
117
|
+
} };
|
|
118
|
+
for (const [index, message] of messages.entries()) {
|
|
119
|
+
if (message.role !== 'tool')
|
|
120
|
+
flush();
|
|
121
|
+
if (message.role === 'user') {
|
|
122
|
+
const count = message.media?.length ?? 0;
|
|
123
|
+
result.push(count === 0 ? { role: 'user', content: JSON.stringify(message.content) }
|
|
124
|
+
: { role: 'user', content: [{ type: 'input_text', text: JSON.stringify(message.content) }, ...marker(offset + index, count)] });
|
|
125
|
+
}
|
|
126
|
+
else if (message.role === 'tool') {
|
|
113
127
|
result.push({ type: 'function_call_output', call_id: message.callId, output: JSON.stringify(message.result) });
|
|
128
|
+
pending.push(...marker(offset + index, message.media?.length ?? 0));
|
|
129
|
+
}
|
|
114
130
|
else if (!hasContinuation)
|
|
115
131
|
for (const call of message.calls) {
|
|
116
132
|
const name = aliases.get(call.toolId);
|
|
@@ -120,15 +136,47 @@ function messagesToInput(messages, hasContinuation, aliases) {
|
|
|
120
136
|
}
|
|
121
137
|
// Continuation already includes the provider's original function calls and reasoning items.
|
|
122
138
|
}
|
|
139
|
+
flush();
|
|
123
140
|
return result;
|
|
124
141
|
}
|
|
142
|
+
/** The Responses part for one piece of media. */
|
|
143
|
+
function responsesMediaPart(item) {
|
|
144
|
+
if (item.mediaType === 'application/pdf') {
|
|
145
|
+
return 'data' in item ? { type: 'input_file', filename: item.name ?? 'document.pdf', file_data: mediaDataUrl(item) } : { type: 'input_file', file_url: item.url };
|
|
146
|
+
}
|
|
147
|
+
return { type: 'input_image', image_url: 'data' in item ? mediaDataUrl(item) : item.url, detail: 'auto' };
|
|
148
|
+
}
|
|
149
|
+
/** Replace media placeholders in our own user turns with the real parts, from the request's messages. */
|
|
150
|
+
function hydrateResponsesInput(input, messages) {
|
|
151
|
+
return input.map(entry => {
|
|
152
|
+
const item = entry;
|
|
153
|
+
if (!item || typeof item !== 'object' || item['role'] !== 'user' || !Array.isArray(item['content']))
|
|
154
|
+
return entry;
|
|
155
|
+
return { ...item, content: item['content'].map(part => {
|
|
156
|
+
const marker = part;
|
|
157
|
+
if (!marker || typeof marker !== 'object' || marker['type'] !== 'mayura_media')
|
|
158
|
+
return part;
|
|
159
|
+
const message = messages[marker['message']];
|
|
160
|
+
const media = message && 'media' in message ? message.media : undefined;
|
|
161
|
+
const found = typeof marker['item'] === 'number' ? media?.[marker['item']] : undefined;
|
|
162
|
+
return found ? responsesMediaPart(found) : failed();
|
|
163
|
+
}) };
|
|
164
|
+
});
|
|
165
|
+
}
|
|
125
166
|
/** Explicit, stateless-per-call Responses adapter. No credential discovery, retries or public raw deltas. */
|
|
126
167
|
export function openAIResponses(options) {
|
|
127
|
-
if (typeof options.
|
|
168
|
+
if (typeof options.model !== 'string' || !options.model.trim() || options.model.length > 128)
|
|
128
169
|
throw new MayuraError('INVALID_CONFIG', 'A model ID and bounded API key are required.');
|
|
170
|
+
const endpoint = options.endpoint === undefined ? 'https://api.openai.com/v1/responses' : providerEndpoint(options.endpoint, '/responses', 'openAIResponses');
|
|
171
|
+
const extraHeaders = providerHeaders(options.headers, ['Authorization'], 'openAIResponses');
|
|
172
|
+
// The key may be left out only behind a gateway that authenticates the request and holds the provider key itself.
|
|
173
|
+
const keyless = options.apiKey === undefined && options.endpoint !== undefined && Object.keys(extraHeaders).length > 0;
|
|
174
|
+
if (!keyless && (typeof options.apiKey !== 'string' || !options.apiKey.trim() || /[\r\n]/.test(options.apiKey) || options.apiKey.length > 4096)) {
|
|
175
|
+
throw new MayuraError('INVALID_CONFIG', 'A model ID and bounded API key are required (behind a gateway that holds the key: an endpoint and its credential header).');
|
|
176
|
+
}
|
|
129
177
|
const apiKey = options.apiKey;
|
|
130
178
|
const model = options.model;
|
|
131
|
-
const
|
|
179
|
+
const fixedOutput = options.outputJsonSchema === undefined ? undefined : strictJsonSchema(options.outputJsonSchema, `The adapter's outputJsonSchema`);
|
|
132
180
|
const priceInput = options.pricing.inputMicrosPerMillionTokens;
|
|
133
181
|
const priceOutput = options.pricing.outputMicrosPerMillionTokens;
|
|
134
182
|
for (const amount of [options.maxCostMicros, priceInput, priceOutput])
|
|
@@ -145,6 +193,7 @@ export function openAIResponses(options) {
|
|
|
145
193
|
const transport = options.fetch ?? globalThis.fetch;
|
|
146
194
|
if (typeof transport !== 'function')
|
|
147
195
|
throw new MayuraError('INVALID_CONFIG', 'A fetch-compatible transport is required.');
|
|
196
|
+
const media = mediaOption(options.media, ALL_MEDIA);
|
|
148
197
|
/** One Responses call. With `onDelta` it streams, reporting final-output text as it arrives; the parsing is shared. */
|
|
149
198
|
const call = async (request, onDelta, consumer) => {
|
|
150
199
|
const controller = new AbortController();
|
|
@@ -155,7 +204,7 @@ export function openAIResponses(options) {
|
|
|
155
204
|
if (signal.aborted)
|
|
156
205
|
throw new MayuraError('CANCELLED', 'Provider request was cancelled.');
|
|
157
206
|
assertPositiveInteger(request.maxOutputTokens, 'maxOutputTokens');
|
|
158
|
-
const aliases = new Map(request.tools.map(
|
|
207
|
+
const aliases = new Map(modelToolNames(request.tools.map(tool => tool.id)));
|
|
159
208
|
const ids = new Map([...aliases].map(([id, name]) => [name, id]));
|
|
160
209
|
if (aliases.size !== request.tools.length || request.tools.length > 128)
|
|
161
210
|
return failed();
|
|
@@ -170,22 +219,20 @@ export function openAIResponses(options) {
|
|
|
170
219
|
return failed();
|
|
171
220
|
history = previous['history'];
|
|
172
221
|
}
|
|
173
|
-
const additions = messagesToInput(request.messages.slice(consumed), request.continuation !== undefined, aliases);
|
|
222
|
+
const additions = messagesToInput(request.messages.slice(consumed), consumed, request.continuation !== undefined, aliases);
|
|
174
223
|
const input = [...history, ...additions];
|
|
175
|
-
const tools = request.tools.map(tool => {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
180
|
-
const body = JSON.stringify(jsonValue({ model, instructions: request.instructions, input, tools,
|
|
224
|
+
const tools = request.tools.map(tool => ({ type: 'function', name: aliases.get(tool.id), description: tool.description, parameters: toolSchema(tool), strict: true }));
|
|
225
|
+
const outputSchema = outputSchemaFor(fixedOutput, request.outputJsonSchema);
|
|
226
|
+
// Media placeholders become real parts only in the request body; encoded media is allowed on top of the JSON limit.
|
|
227
|
+
const body = JSON.stringify(jsonValue({ model, instructions: request.instructions, input: hydrateResponsesInput(input, request.messages), tools,
|
|
181
228
|
store: false, stream: onDelta !== undefined, include: ['reasoning.encrypted_content'], parallel_tool_calls: true,
|
|
182
229
|
max_output_tokens: request.maxOutputTokens,
|
|
183
230
|
text: { format: { type: 'json_schema', name: 'mayura_output', schema: outputSchema, strict: true } },
|
|
184
|
-
}, { maxBytes: maxRequestBytes }));
|
|
185
|
-
const response = await abortable(transport(
|
|
186
|
-
method: 'POST', headers: { Authorization: `Bearer ${apiKey}
|
|
231
|
+
}, { maxBytes: maxRequestBytes + encodedMediaBytes(request.messages) }));
|
|
232
|
+
const response = await abortable(transport(endpoint, {
|
|
233
|
+
method: 'POST', headers: { ...extraHeaders, ...(apiKey === undefined ? {} : { Authorization: `Bearer ${apiKey}` }), 'Content-Type': 'application/json' },
|
|
187
234
|
body, signal, redirect: 'error',
|
|
188
|
-
}), signal);
|
|
235
|
+
}).catch(() => failed('unavailable')), signal);
|
|
189
236
|
const payload = onDelta ? await completedStream(response, signal, onDelta) : await responseBody(response, maxResponseBytes, signal);
|
|
190
237
|
const usage = object(payload['usage']);
|
|
191
238
|
const inputTokens = integer(usage['input_tokens']);
|
|
@@ -195,6 +242,8 @@ export function openAIResponses(options) {
|
|
|
195
242
|
if (computedCost > BigInt(Number.MAX_SAFE_INTEGER))
|
|
196
243
|
return failed();
|
|
197
244
|
knownCost = Number(computedCost);
|
|
245
|
+
if (payload['status'] === 'incomplete')
|
|
246
|
+
return failed('refused');
|
|
198
247
|
if (payload['status'] !== 'completed' || !Array.isArray(payload['output']) || payload['output'].length > 256)
|
|
199
248
|
return failed();
|
|
200
249
|
const calls = [];
|
|
@@ -221,6 +270,8 @@ export function openAIResponses(options) {
|
|
|
221
270
|
return failed();
|
|
222
271
|
for (const rawContent of item['content']) {
|
|
223
272
|
const content = object(rawContent);
|
|
273
|
+
if (content['type'] === 'refusal')
|
|
274
|
+
return failed('refused');
|
|
224
275
|
if (content['type'] !== 'output_text' || typeof content['text'] !== 'string')
|
|
225
276
|
return failed();
|
|
226
277
|
text.push(content['text']);
|
|
@@ -241,11 +292,14 @@ export function openAIResponses(options) {
|
|
|
241
292
|
catch (error) {
|
|
242
293
|
// HTTP status/body, credentials, model output and arbitrary transport exceptions are private.
|
|
243
294
|
if (knownCost !== undefined)
|
|
244
|
-
throw new
|
|
295
|
+
throw new ModelProviderError(reasonOf(error), { costMicros: knownCost });
|
|
245
296
|
if (request.signal.aborted || controller.signal.aborted || consumer?.aborted)
|
|
246
297
|
throw new MayuraError('CANCELLED', 'Provider request was cancelled or timed out.');
|
|
247
|
-
if (error instanceof
|
|
298
|
+
if (error instanceof ModelProviderError)
|
|
248
299
|
throw error;
|
|
300
|
+
// A schema the provider would refuse, or no output schema at all, is the agent's configuration.
|
|
301
|
+
if (error instanceof MayuraError && error.code === 'INVALID_CONFIG')
|
|
302
|
+
return failed('configuration');
|
|
249
303
|
return failed();
|
|
250
304
|
}
|
|
251
305
|
finally {
|
|
@@ -271,30 +325,79 @@ export function openAIResponses(options) {
|
|
|
271
325
|
}
|
|
272
326
|
else if (type === 'response.completed')
|
|
273
327
|
completed = object(data['response']);
|
|
274
|
-
else if (type === 'response.
|
|
275
|
-
return failed();
|
|
328
|
+
else if (type === 'response.incomplete')
|
|
329
|
+
return failed('refused');
|
|
330
|
+
else if (type === 'response.failed' || type === 'error')
|
|
331
|
+
return failed('unavailable');
|
|
276
332
|
}
|
|
277
333
|
return completed ?? failed();
|
|
278
334
|
};
|
|
279
335
|
return Object.freeze({
|
|
280
|
-
id: 'openai.responses', capabilities: Object.freeze({ tools: true, structuredOutput: true }), maxCostMicros: options.maxCostMicros,
|
|
336
|
+
id: 'openai.responses', capabilities: Object.freeze({ tools: true, structuredOutput: true, ...(media ? { media } : {}) }), maxCostMicros: options.maxCostMicros,
|
|
337
|
+
checkDefinition: (definition) => checkStrictDefinition(definition, fixedOutput),
|
|
281
338
|
generate: (request) => call(request),
|
|
282
339
|
stream: (request) => streamModelCall((onDelta, consumer) => call(request, onDelta, consumer)),
|
|
283
340
|
});
|
|
284
341
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
342
|
+
/**
|
|
343
|
+
* The conversation in Chat Completions form. `assistants` are the provider's own earlier assistant turns in this run (from
|
|
344
|
+
* the continuation), in order: they carry fields such as DeepSeek's `reasoning_content` that a thinking model requires
|
|
345
|
+
* back, and each must match the calls Mayura recorded for that turn.
|
|
346
|
+
*/
|
|
347
|
+
/** The Chat Completions part for one piece of media: an `image_url`, or a `file` for a PDF (bytes only). */
|
|
348
|
+
function chatMediaPart(item) {
|
|
349
|
+
if (item.mediaType === 'application/pdf') {
|
|
350
|
+
if (!('data' in item))
|
|
351
|
+
throw new MayuraError('INVALID_CONFIG', 'Chat Completions providers take PDFs only as bytes, not URLs.');
|
|
352
|
+
return { type: 'file', file: { filename: item.name ?? 'document.pdf', file_data: mediaDataUrl(item) } };
|
|
353
|
+
}
|
|
354
|
+
return { type: 'image_url', image_url: { url: 'data' in item ? mediaDataUrl(item) : item.url } };
|
|
355
|
+
}
|
|
356
|
+
function compatibleMessages(messages, aliases, assistants) {
|
|
357
|
+
const result = [];
|
|
358
|
+
let pending = [];
|
|
359
|
+
let turn = 0;
|
|
360
|
+
const flush = () => { if (pending.length > 0) {
|
|
361
|
+
result.push({ role: 'user', content: [{ type: 'text', text: TOOL_MEDIA_NOTE }, ...pending] });
|
|
362
|
+
pending = [];
|
|
363
|
+
} };
|
|
364
|
+
for (const message of messages) {
|
|
365
|
+
if (message.role !== 'tool')
|
|
366
|
+
flush();
|
|
367
|
+
if (message.role === 'tool')
|
|
368
|
+
pending.push(...(message.media ?? []).map(chatMediaPart));
|
|
369
|
+
result.push(compatibleMessage(message));
|
|
370
|
+
}
|
|
371
|
+
flush();
|
|
372
|
+
return result;
|
|
373
|
+
function compatibleMessage(message) {
|
|
374
|
+
if (message.role === 'user') {
|
|
375
|
+
const media = message.media ?? [];
|
|
376
|
+
return media.length === 0 ? { role: 'user', content: JSON.stringify(message.content) }
|
|
377
|
+
: { role: 'user', content: [{ type: 'text', text: JSON.stringify(message.content) }, ...media.map(chatMediaPart)] };
|
|
378
|
+
}
|
|
289
379
|
if (message.role === 'tool')
|
|
290
380
|
return { role: 'tool', tool_call_id: message.callId, content: JSON.stringify(message.result) };
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
381
|
+
const calls = message.calls.map(call => {
|
|
382
|
+
const name = aliases.get(call.toolId);
|
|
383
|
+
if (!name)
|
|
384
|
+
return failed();
|
|
385
|
+
return { id: call.id, type: 'function', function: { name, arguments: JSON.stringify(call.input) } };
|
|
386
|
+
});
|
|
387
|
+
const own = assistants[turn++];
|
|
388
|
+
if (!own)
|
|
389
|
+
return { role: 'assistant', content: null, tool_calls: calls };
|
|
390
|
+
const ownCalls = own['tool_calls'];
|
|
391
|
+
if (!Array.isArray(ownCalls) || ownCalls.length !== calls.length || ownCalls.some((call, index) => call['id'] !== calls[index].id))
|
|
392
|
+
return failed();
|
|
393
|
+
return own;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/** The fields of a provider assistant turn worth sending back: its text, reasoning and tool calls, nothing else. */
|
|
397
|
+
function assistantTurn(message) {
|
|
398
|
+
return { role: 'assistant', content: typeof message['content'] === 'string' ? message['content'] : null,
|
|
399
|
+
...(typeof message['reasoning_content'] === 'string' ? { reasoning_content: message['reasoning_content'] } : {}),
|
|
400
|
+
tool_calls: message['tool_calls'] };
|
|
298
401
|
}
|
|
299
402
|
/** Loopback-only Chat Completions adapter for explicitly selected compatible local model servers. */
|
|
300
403
|
export function openAICompatibleChat(options) {
|
|
@@ -328,8 +431,43 @@ export function openAICompatibleChat(options) {
|
|
|
328
431
|
if (options.token !== undefined && (typeof options.token !== 'function' || options.apiKey !== undefined)) {
|
|
329
432
|
throw new MayuraError('INVALID_CONFIG', 'Give either an apiKey or a token source, not both.');
|
|
330
433
|
}
|
|
331
|
-
|
|
332
|
-
|
|
434
|
+
const extraHeaders = {};
|
|
435
|
+
if (options.headers !== undefined) {
|
|
436
|
+
const entries = options.headers && typeof options.headers === 'object' ? Object.entries(options.headers) : undefined;
|
|
437
|
+
if (!entries || entries.length > 8 || entries.some(([name, value]) => !/^[A-Za-z0-9-]{1,64}$/u.test(name) || ownedHeaders.has(name.toLowerCase())
|
|
438
|
+
|| typeof value !== 'string' || !value || /[\r\n]/u.test(value) || value.length > 8_192)) {
|
|
439
|
+
throw new MayuraError('INVALID_CONFIG', 'headers must be at most 8 extra header values; they cannot replace Authorization, api-key, Content-Type, Host or cookies.');
|
|
440
|
+
}
|
|
441
|
+
for (const [name, value] of entries)
|
|
442
|
+
extraHeaders[name] = value;
|
|
443
|
+
}
|
|
444
|
+
if (remote !== undefined && options.apiKey === undefined && options.token === undefined && Object.keys(extraHeaders).length === 0) {
|
|
445
|
+
throw new MayuraError('INVALID_CONFIG', 'Remote compatible providers require an apiKey, a token source, or a credential header (such as a gateway token in headers).');
|
|
446
|
+
}
|
|
447
|
+
const outputMode = options.output ?? 'json_schema';
|
|
448
|
+
if (outputMode !== 'json_schema' && outputMode !== 'json_object')
|
|
449
|
+
throw new MayuraError('INVALID_CONFIG', 'output must be "json_schema" or "json_object".');
|
|
450
|
+
if (options.strictTools !== undefined && typeof options.strictTools !== 'boolean')
|
|
451
|
+
throw new MayuraError('INVALID_CONFIG', 'strictTools must be true or false.');
|
|
452
|
+
const media = mediaOption(options.media, undefined);
|
|
453
|
+
const tokenLimitField = options.tokenLimitField ?? 'max_tokens';
|
|
454
|
+
if (tokenLimitField !== 'max_tokens' && tokenLimitField !== 'max_completion_tokens')
|
|
455
|
+
throw new MayuraError('INVALID_CONFIG', 'tokenLimitField must be "max_tokens" or "max_completion_tokens".');
|
|
456
|
+
let extraBody = {};
|
|
457
|
+
if (options.body !== undefined) {
|
|
458
|
+
let copy;
|
|
459
|
+
try {
|
|
460
|
+
copy = jsonValue(options.body, { maxBytes: 16_384 });
|
|
461
|
+
}
|
|
462
|
+
catch {
|
|
463
|
+
throw new MayuraError('INVALID_CONFIG', 'body must be plain JSON of at most 16 KiB.');
|
|
464
|
+
}
|
|
465
|
+
if (!copy || typeof copy !== 'object' || Array.isArray(copy))
|
|
466
|
+
throw new MayuraError('INVALID_CONFIG', 'body must be a JSON object of extra request fields.');
|
|
467
|
+
const owned = Object.keys(copy).find(key => ownedFields.has(key));
|
|
468
|
+
if (owned !== undefined)
|
|
469
|
+
throw new MayuraError('INVALID_CONFIG', `body cannot set "${owned}"; the adapter sets it.`);
|
|
470
|
+
extraBody = copy;
|
|
333
471
|
}
|
|
334
472
|
if (typeof options.model !== 'string' || !options.model.trim() || options.model.length > 128)
|
|
335
473
|
throw new MayuraError('INVALID_CONFIG', 'A bounded local model ID is required.');
|
|
@@ -337,7 +475,7 @@ export function openAICompatibleChat(options) {
|
|
|
337
475
|
const apiKey = options.apiKey;
|
|
338
476
|
const tokenSource = options.token;
|
|
339
477
|
const model = options.model;
|
|
340
|
-
const
|
|
478
|
+
const fixedOutput = options.outputJsonSchema === undefined ? undefined : strictJsonSchema(options.outputJsonSchema, `The adapter's outputJsonSchema`);
|
|
341
479
|
const authHeader = remote?.auth === 'api-key' ? 'api-key' : 'Authorization';
|
|
342
480
|
const credential = async () => {
|
|
343
481
|
const value = tokenSource ? await tokenSource() : apiKey;
|
|
@@ -370,27 +508,38 @@ export function openAICompatibleChat(options) {
|
|
|
370
508
|
const signal = AbortSignal.any([request.signal, controller.signal, ...(consumer ? [consumer] : [])]);
|
|
371
509
|
if (signal.aborted)
|
|
372
510
|
throw new MayuraError('CANCELLED', 'Provider request was cancelled.');
|
|
373
|
-
|
|
511
|
+
// The run's private state: the provider's own earlier assistant turns, for the model and endpoint that made them.
|
|
512
|
+
let assistants = [];
|
|
513
|
+
if (request.continuation !== undefined) {
|
|
514
|
+
const previous = object(jsonValue(request.continuation, { maxBytes: maxRequestBytes }));
|
|
515
|
+
if (previous['provider'] !== 'openai-compatible.chat.v1' || previous['model'] !== model || previous['endpoint'] !== url || !Array.isArray(previous['assistants']))
|
|
516
|
+
return failed();
|
|
517
|
+
assistants = previous['assistants'].map(item => object(item));
|
|
518
|
+
}
|
|
519
|
+
if (assistants.length > request.messages.filter(message => message.role === 'assistant').length)
|
|
374
520
|
return failed();
|
|
375
521
|
assertPositiveInteger(request.maxOutputTokens, 'maxOutputTokens');
|
|
376
|
-
const aliases = new Map(request.tools.map(
|
|
522
|
+
const aliases = new Map(modelToolNames(request.tools.map(tool => tool.id)));
|
|
377
523
|
const ids = new Map([...aliases].map(([toolId, alias]) => [alias, toolId]));
|
|
378
524
|
if (aliases.size !== request.tools.length || aliases.size > 128)
|
|
379
525
|
return failed();
|
|
380
|
-
const tools = request.tools.map(tool => {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
526
|
+
const tools = request.tools.map(tool => ({ type: 'function', function: { name: aliases.get(tool.id), description: tool.description, parameters: toolSchema(tool),
|
|
527
|
+
...(options.strictTools ? { strict: true } : {}) } }));
|
|
528
|
+
const outputSchema = outputSchemaFor(fixedOutput, request.outputJsonSchema);
|
|
529
|
+
// JSON mode has no schema parameter, so the schema goes into the instructions; the answer is validated anyway.
|
|
530
|
+
const instructions = outputMode === 'json_object'
|
|
531
|
+
? `${request.instructions}\n\nAnswer with one JSON object, and nothing else, that matches this JSON Schema:\n${JSON.stringify(outputSchema)}`
|
|
532
|
+
: request.instructions;
|
|
533
|
+
const body = JSON.stringify(jsonValue({ ...extraBody, model, stream: onDelta !== undefined, ...(onDelta ? { stream_options: { include_usage: true } } : {}),
|
|
534
|
+
messages: [{ role: 'system', content: instructions }, ...compatibleMessages(request.messages, aliases, assistants)],
|
|
535
|
+
...(tools.length > 0 ? { tools, parallel_tool_calls: true } : {}), [tokenLimitField]: request.maxOutputTokens,
|
|
536
|
+
response_format: outputMode === 'json_object' ? { type: 'json_object' } : { type: 'json_schema', json_schema: { name: 'mayura_output', strict: true, schema: outputSchema } },
|
|
537
|
+
}, { maxBytes: maxRequestBytes + encodedMediaBytes(request.messages) }));
|
|
538
|
+
const headers = { ...extraHeaders, 'Content-Type': 'application/json' };
|
|
390
539
|
const authorization = await credential();
|
|
391
540
|
if (authorization !== undefined)
|
|
392
541
|
headers[authHeader] = authorization;
|
|
393
|
-
const response = await abortable(transport(url, { method: 'POST', headers, body, signal, redirect: 'error' }), signal);
|
|
542
|
+
const response = await abortable(transport(url, { method: 'POST', headers, body, signal, redirect: 'error' }).catch(() => failed('unavailable')), signal);
|
|
394
543
|
const payload = onDelta ? await assembledCompletion(response, signal, onDelta) : await responseBody(response, maxResponseBytes, signal);
|
|
395
544
|
const usage = object(payload['usage']);
|
|
396
545
|
const inputTokens = integer(usage['prompt_tokens']);
|
|
@@ -420,19 +569,28 @@ export function openAICompatibleChat(options) {
|
|
|
420
569
|
seen.add(callId);
|
|
421
570
|
return { id: callId, toolId: ids.get(alias), input: jsonValue(JSON.parse(fn['arguments'])) };
|
|
422
571
|
});
|
|
423
|
-
|
|
572
|
+
// Keep this turn as the provider sent it (with any reasoning) for the next call of the run.
|
|
573
|
+
const continuation = jsonValue({ provider: 'openai-compatible.chat.v1', model, endpoint: url, assistants: [...assistants, assistantTurn(message)] }, { maxBytes: maxRequestBytes });
|
|
574
|
+
return { type: 'tool_calls', calls, usage: { costMicros: knownCost }, continuation };
|
|
424
575
|
}
|
|
576
|
+
if (choice['finish_reason'] === 'length' || choice['finish_reason'] === 'content_filter' || typeof message['refusal'] === 'string')
|
|
577
|
+
return failed('refused');
|
|
578
|
+
if (choice['finish_reason'] === 'insufficient_system_resource' || choice['finish_reason'] === 'aborted')
|
|
579
|
+
return failed('unavailable');
|
|
425
580
|
if (choice['finish_reason'] !== 'stop' || typeof message['content'] !== 'string')
|
|
426
581
|
return failed();
|
|
427
582
|
return { type: 'final', output: jsonValue(JSON.parse(message['content']), { maxBytes: maxResponseBytes }), usage: { costMicros: knownCost } };
|
|
428
583
|
}
|
|
429
584
|
catch (error) {
|
|
430
585
|
if (knownCost !== undefined)
|
|
431
|
-
throw new
|
|
586
|
+
throw new ModelProviderError(reasonOf(error), { costMicros: knownCost });
|
|
432
587
|
if (request.signal.aborted || controller.signal.aborted || consumer?.aborted)
|
|
433
588
|
throw new MayuraError('CANCELLED', 'Provider request was cancelled or timed out.');
|
|
434
|
-
if (error instanceof
|
|
589
|
+
if (error instanceof ModelProviderError)
|
|
435
590
|
throw error;
|
|
591
|
+
// A schema the provider would refuse, or no output schema at all, is the agent's configuration.
|
|
592
|
+
if (error instanceof MayuraError && error.code === 'INVALID_CONFIG')
|
|
593
|
+
return failed('configuration');
|
|
436
594
|
return failed();
|
|
437
595
|
}
|
|
438
596
|
finally {
|
|
@@ -445,6 +603,7 @@ export function openAICompatibleChat(options) {
|
|
|
445
603
|
*/
|
|
446
604
|
const assembledCompletion = async (response, signal, onDelta) => {
|
|
447
605
|
let content = '';
|
|
606
|
+
let reasoning = '';
|
|
448
607
|
let finish = null;
|
|
449
608
|
let usage;
|
|
450
609
|
let finished = false;
|
|
@@ -474,6 +633,9 @@ export function openAICompatibleChat(options) {
|
|
|
474
633
|
content += delta['content'];
|
|
475
634
|
onDelta(delta['content']);
|
|
476
635
|
}
|
|
636
|
+
// Reasoning is kept only to send back with the turn; it is never released as output.
|
|
637
|
+
if (typeof delta['reasoning_content'] === 'string')
|
|
638
|
+
reasoning += delta['reasoning_content'];
|
|
477
639
|
if (delta['tool_calls'] !== undefined && delta['tool_calls'] !== null) {
|
|
478
640
|
if (!Array.isArray(delta['tool_calls']))
|
|
479
641
|
return failed();
|
|
@@ -495,11 +657,12 @@ export function openAICompatibleChat(options) {
|
|
|
495
657
|
}
|
|
496
658
|
if (!finished || usage === undefined)
|
|
497
659
|
return failed();
|
|
498
|
-
const message = { role: 'assistant', content: calls.length > 0 && !content ? null : content,
|
|
660
|
+
const message = { role: 'assistant', content: calls.length > 0 && !content ? null : content, ...(reasoning ? { reasoning_content: reasoning } : {}),
|
|
499
661
|
...(calls.length > 0 ? { tool_calls: calls.map(entry => ({ type: 'function', id: entry.id ?? null, function: { name: entry.name, arguments: entry.arguments } })) } : {}) };
|
|
500
662
|
return { choices: [{ message, finish_reason: finish }], usage };
|
|
501
663
|
};
|
|
502
|
-
return Object.freeze({ id: remote ? `openai-compatible.${remote.id}` : 'openai-compatible.chat', capabilities: Object.freeze({ tools: true, structuredOutput: true }), maxCostMicros: options.maxCostMicros,
|
|
664
|
+
return Object.freeze({ id: remote ? `openai-compatible.${remote.id}` : 'openai-compatible.chat', capabilities: Object.freeze({ tools: true, structuredOutput: true, ...(media ? { media } : {}) }), maxCostMicros: options.maxCostMicros,
|
|
665
|
+
checkDefinition: (definition) => checkStrictDefinition(definition, fixedOutput),
|
|
503
666
|
generate: (request) => call(request),
|
|
504
667
|
stream: (request) => streamModelCall((onDelta, consumer) => call(request, onDelta, consumer)),
|
|
505
668
|
});
|
|
@@ -566,7 +729,7 @@ export function openAIEmbeddings(options) {
|
|
|
566
729
|
catch (error) {
|
|
567
730
|
if (error instanceof MayuraError)
|
|
568
731
|
throw error;
|
|
569
|
-
|
|
732
|
+
return failed(error instanceof TypeError ? 'unavailable' : 'invalid_response');
|
|
570
733
|
}
|
|
571
734
|
finally {
|
|
572
735
|
clearTimeout(timer);
|