eve 0.71.2 → 0.72.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 +47 -0
- package/README.md +22 -6
- package/dist/src/acp/adapter.js +1 -1
- package/dist/src/ai/decide.d.ts +7 -0
- package/dist/src/ai/decide.js +1 -0
- package/dist/src/channel/conversation-context.d.ts +4 -1
- package/dist/src/channel/invoke-tool.d.ts +41 -0
- package/dist/src/channel/invoke-tool.js +1 -0
- package/dist/src/channel/routes.d.ts +3 -0
- package/dist/src/chunks/{use-eve-agent-CFCaYnrI.js → use-eve-agent-C1GYGCtb.js} +698 -388
- package/dist/src/chunks/{use-eve-agent-DcDhXNv1.js → use-eve-agent-hZJ7CB8t.js} +698 -388
- package/dist/src/cli/commands/integration-setup.js +1 -1
- package/dist/src/cli/commands/registry.js +1 -1
- package/dist/src/cli/commands/trace-detail.d.ts +1 -1
- package/dist/src/cli/commands/trace-detail.js +1 -1
- package/dist/src/cli/dev/tui/runner.js +1 -1
- package/dist/src/cli/dev/tui/setup-flow.d.ts +1 -0
- package/dist/src/cli/dev/tui/setup-panel.d.ts +1 -0
- package/dist/src/cli/dev/tui/setup-panel.js +2 -1
- package/dist/src/cli/dev/tui/traces/trace-conversation.d.ts +2 -2
- package/dist/src/cli/dev/tui/traces/trace-conversation.js +2 -2
- package/dist/src/cli/dev/tui/transcript-parts.d.ts +2 -1
- package/dist/src/cli/dev/tui/transcript-parts.js +1 -1
- package/dist/src/cli/dev/tui/transcript.js +1 -1
- package/dist/src/cli/dev/tui/tui-prompter.js +1 -1
- package/dist/src/client/conversation-projection.d.ts +4 -0
- package/dist/src/client/conversation-projection.js +1 -0
- package/dist/src/client/conversation-reducer.js +1 -1
- package/dist/src/client/conversation-state.d.ts +5 -26
- package/dist/src/client/conversation-state.js +1 -1
- package/dist/src/client/index.d.ts +1 -0
- package/dist/src/client/index.js +1 -1
- package/dist/src/client/message-action-parts.d.ts +1 -11
- package/dist/src/client/message-action-parts.js +1 -1
- package/dist/src/client/message-reducer.d.ts +3 -1
- package/dist/src/client/message-reducer.js +1 -1
- package/dist/src/client/session-utils.js +1 -1
- package/dist/src/client/session.js +1 -1
- package/dist/src/client/tool-call-state.d.ts +23 -0
- package/dist/src/client/tool-call-state.js +1 -0
- package/dist/src/client/tool-part-state.d.ts +7 -0
- package/dist/src/client/tool-part-state.js +1 -0
- package/dist/src/compiled/.vendor-stamp.json +10 -10
- package/dist/src/compiled/@ai-sdk/anthropic/index.d.ts +1453 -1358
- package/dist/src/compiled/@ai-sdk/anthropic/index.js +1 -2
- package/dist/src/compiled/@ai-sdk/code-mode/index.d.ts +172 -163
- package/dist/src/compiled/@ai-sdk/code-mode/index.js +15 -20
- package/dist/src/compiled/@ai-sdk/google/index.d.ts +772 -733
- package/dist/src/compiled/@ai-sdk/google/index.js +6 -8
- package/dist/src/compiled/@ai-sdk/mcp/index.d.ts +887 -790
- package/dist/src/compiled/@ai-sdk/mcp/index.js +1 -1
- package/dist/src/compiled/@ai-sdk/openai/index.d.ts +1722 -1691
- package/dist/src/compiled/@ai-sdk/openai/index.js +3 -14
- package/dist/src/compiled/@ai-sdk/otel/index.d.ts +216 -159
- package/dist/src/compiled/@ai-sdk/otel/index.js +3 -3
- package/dist/src/compiled/@ai-sdk/provider/index.d.ts +7542 -7271
- package/dist/src/compiled/@ai-sdk/provider/index.js +1 -3
- package/dist/src/compiled/@ai-sdk/provider-utils/index.d.ts +1799 -1600
- package/dist/src/compiled/@eve/catalog/index.js +1 -1
- package/dist/src/compiled/_chunks/workflow/dist-DXLdlucM.js +15 -0
- package/dist/src/compiled/_chunks/workflow/experimental-decision-BrfWf6-n.js +3 -0
- package/dist/src/compiler/extension-compatibility.d.ts +36 -20
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/manifest.js +1 -1
- package/dist/src/context/build-dynamic-tools.js +1 -1
- package/dist/src/context/caller-scope.d.ts +7 -0
- package/dist/src/context/caller-scope.js +1 -0
- package/dist/src/context/dynamic-tool-lifecycle.js +1 -1
- package/dist/src/context/dynamic-tool-metadata.d.ts +1 -0
- package/dist/src/context/providers/session.js +1 -1
- package/dist/src/evals/define-eval.d.ts +1 -1
- package/dist/src/evals/judge.d.ts +1 -1
- package/dist/src/evals/judge.js +2 -2
- package/dist/src/evals/types.d.ts +8 -8
- package/dist/src/execution/cancel-descendant-turns-step.d.ts +1 -0
- package/dist/src/execution/cancel-descendant-turns-step.js +1 -1
- package/dist/src/execution/cancelled-model-call-batch.js +1 -1
- package/dist/src/execution/coordination-dispatch-shared.d.ts +2 -1
- package/dist/src/execution/coordination-dispatch-shared.js +1 -1
- package/dist/src/execution/coordination-dispatch-step.js +1 -1
- package/dist/src/execution/durable-session-read.d.ts +5 -0
- package/dist/src/execution/durable-session-read.js +1 -0
- package/dist/src/execution/durable-session-store.d.ts +4 -10
- package/dist/src/execution/durable-session-store.js +1 -1
- package/dist/src/execution/dynamic-connections.d.ts +3 -3
- package/dist/src/execution/dynamic-connections.js +1 -1
- package/dist/src/execution/dynamic-workflow/tool.js +1 -1
- package/dist/src/execution/invoke-tool.d.ts +35 -0
- package/dist/src/execution/invoke-tool.js +1 -0
- package/dist/src/execution/legacy-session/interrupt-step.js +1 -1
- package/dist/src/execution/legacy-session/snapshot.d.ts +3 -0
- package/dist/src/execution/legacy-session/snapshot.js +1 -1
- package/dist/src/execution/model-call-batching.js +1 -1
- package/dist/src/execution/node-step.d.ts +2 -0
- package/dist/src/execution/node-step.js +1 -1
- package/dist/src/execution/proxied-deliver-step.js +1 -1
- package/dist/src/execution/publish-session-events.d.ts +8 -0
- package/dist/src/execution/publish-session-events.js +1 -1
- package/dist/src/execution/sandbox/active-handles.d.ts +6 -0
- package/dist/src/execution/sandbox/active-handles.js +1 -1
- package/dist/src/execution/sandbox/ensure.js +1 -1
- package/dist/src/execution/session/active-turn.js +1 -1
- package/dist/src/execution/session/answer-caller.d.ts +15 -0
- package/dist/src/execution/session/answer-caller.js +1 -0
- package/dist/src/execution/session/checkpoint-migrations.js +1 -1
- package/dist/src/execution/session/finalization.js +1 -1
- package/dist/src/execution/session/handoff-steps.d.ts +3 -1
- package/dist/src/execution/session/handoff-steps.js +1 -1
- package/dist/src/execution/session/handoff.d.ts +1 -1
- package/dist/src/execution/session/handoff.js +1 -1
- package/dist/src/execution/session/pending-turn-state.d.ts +8 -3
- package/dist/src/execution/session/pending-turn-state.js +1 -1
- package/dist/src/execution/session/task-tool-tracing-step.d.ts +5 -0
- package/dist/src/execution/session/task-tool-tracing-step.js +1 -0
- package/dist/src/execution/session/turn-step-result.js +1 -1
- package/dist/src/execution/session/turn-step.js +1 -1
- package/dist/src/execution/session/turn-waiting-step.js +1 -1
- package/dist/src/execution/session/turn.d.ts +1 -0
- package/dist/src/execution/session/turn.js +1 -1
- package/dist/src/execution/settle-cancelled-turn-step.d.ts +4 -6
- package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
- package/dist/src/execution/tasks/start.d.ts +3 -3
- package/dist/src/execution/tasks/start.js +1 -1
- package/dist/src/execution/tasks/steps.d.ts +1 -1
- package/dist/src/execution/tasks/steps.js +1 -1
- package/dist/src/execution/terminal-session-completion-step.d.ts +7 -0
- package/dist/src/execution/terminal-session-completion-step.js +1 -1
- package/dist/src/execution/terminal-session-failure-step.js +1 -1
- package/dist/src/execution/tools/agent-router-workflow.js +1 -1
- package/dist/src/execution/tools/connection-tools.js +1 -1
- package/dist/src/execution/tools/workflow/authorization-completion.js +1 -1
- package/dist/src/execution/tools/workflow/harness-definition.js +1 -1
- package/dist/src/execution/tools/workflow/step-execution.js +1 -1
- package/dist/src/execution/tools/workflow/step.js +1 -1
- package/dist/src/execution/tools/workflow/withdraw-step.d.ts +7 -9
- package/dist/src/execution/tools/workflow/withdraw-step.js +1 -1
- package/dist/src/execution/workflow-runtime.js +1 -1
- package/dist/src/execution/workflow-trace-context.d.ts +2 -2
- package/dist/src/harness/authorization.d.ts +4 -2
- package/dist/src/harness/authorization.js +1 -1
- package/dist/src/harness/{compaction.js → compaction/engine.js} +1 -1
- package/dist/src/harness/compaction/step.d.ts +46 -0
- package/dist/src/harness/compaction/step.js +1 -0
- package/dist/src/harness/coordination.d.ts +32 -64
- package/dist/src/harness/coordination.js +1 -1
- package/dist/src/harness/current-messages.d.ts +1 -3
- package/dist/src/harness/current-messages.js +1 -1
- package/dist/src/harness/emission.d.ts +4 -52
- package/dist/src/harness/emission.js +1 -1
- package/dist/src/harness/execute-tool.d.ts +1 -0
- package/dist/src/harness/final-output.d.ts +5 -0
- package/dist/src/harness/final-output.js +1 -1
- package/dist/src/harness/hitl/approvals.d.ts +115 -0
- package/dist/src/harness/hitl/approvals.js +1 -0
- package/dist/src/harness/hitl/approved-call-callers.d.ts +14 -0
- package/dist/src/harness/hitl/approved-call-callers.js +1 -0
- package/dist/src/harness/hitl/approved-calls.d.ts +37 -0
- package/dist/src/harness/hitl/approved-calls.js +1 -0
- package/dist/src/harness/{session-limit-continuation.d.ts → hitl/budget-request.d.ts} +3 -1
- package/dist/src/harness/hitl/budget-request.js +1 -0
- package/dist/src/harness/hitl/budget.d.ts +21 -0
- package/dist/src/harness/hitl/budget.js +1 -0
- package/dist/src/harness/{approval-candidates.d.ts → hitl/candidates.d.ts} +13 -18
- package/dist/src/harness/hitl/candidates.js +1 -0
- package/dist/src/harness/hitl/coordinator.js +1 -0
- package/dist/src/harness/hitl/delivery.d.ts +37 -0
- package/dist/src/harness/hitl/delivery.js +1 -0
- package/dist/src/harness/hitl/index.d.ts +49 -0
- package/dist/src/harness/hitl/index.js +1 -0
- package/dist/src/harness/hitl/intake.d.ts +67 -0
- package/dist/src/harness/hitl/intake.js +1 -0
- package/dist/src/harness/{stale-input-responses.d.ts → hitl/stale-responses.d.ts} +5 -3
- package/dist/src/harness/hitl/stale-responses.js +3 -0
- package/dist/src/harness/inline-tool-authorization.d.ts +4 -0
- package/dist/src/harness/inline-tool-authorization.js +1 -1
- package/dist/src/harness/input-extraction.d.ts +1 -10
- package/dist/src/harness/input-extraction.js +1 -1
- package/dist/src/harness/input-request-resolution.d.ts +1 -5
- package/dist/src/harness/input-request-resolution.js +1 -1
- package/dist/src/harness/messages.js +1 -1
- package/dist/src/harness/model-call/call.d.ts +78 -0
- package/dist/src/harness/model-call/call.js +1 -0
- package/dist/src/harness/{model-call-error.d.ts → model-call/errors.d.ts} +1 -1
- package/dist/src/harness/model-call/failure.d.ts +52 -0
- package/dist/src/harness/model-call/failure.js +1 -0
- package/dist/src/harness/model-call/model.d.ts +18 -0
- package/dist/src/harness/model-call/model.js +1 -0
- package/dist/src/harness/model-call/recovery.d.ts +52 -0
- package/dist/src/harness/model-call/recovery.js +1 -0
- package/dist/src/harness/model-call/request.d.ts +30 -0
- package/dist/src/harness/model-call/request.js +3 -0
- package/dist/src/harness/model-call/response.d.ts +39 -0
- package/dist/src/harness/model-call/response.js +1 -0
- package/dist/src/harness/model-call/retry.d.ts +11 -0
- package/dist/src/harness/model-call/retry.js +1 -0
- package/dist/src/harness/model-call/run.d.ts +38 -0
- package/dist/src/harness/model-call/run.js +1 -0
- package/dist/src/harness/model-call/tools.d.ts +48 -0
- package/dist/src/harness/model-call/tools.js +1 -0
- package/dist/src/harness/model-call/usage.d.ts +23 -0
- package/dist/src/harness/model-call/usage.js +1 -0
- package/dist/src/harness/nested-actions.d.ts +2 -2
- package/dist/src/harness/provider-tools.d.ts +7 -3
- package/dist/src/harness/provider-tools.js +1 -1
- package/dist/src/harness/proxy-input-requests.d.ts +4 -12
- package/dist/src/harness/proxy-input-requests.js +1 -1
- package/dist/src/harness/session-machine/commit.d.ts +28 -0
- package/dist/src/harness/session-machine/commit.js +1 -0
- package/dist/src/harness/session-machine/current.d.ts +29 -0
- package/dist/src/harness/session-machine/current.js +1 -0
- package/dist/src/harness/session-machine/events.d.ts +6 -0
- package/dist/src/harness/session-machine/events.js +1 -0
- package/dist/src/harness/session-machine/resolver-events.d.ts +12 -0
- package/dist/src/harness/session-machine/resolver-events.js +1 -0
- package/dist/src/harness/session-machine/state.d.ts +47 -0
- package/dist/src/harness/session-machine/state.js +1 -0
- package/dist/src/harness/session-machine/transitions.d.ts +188 -0
- package/dist/src/harness/session-machine/transitions.js +1 -0
- package/dist/src/harness/session-machine/view.d.ts +58 -0
- package/dist/src/harness/session-machine/view.js +1 -0
- package/dist/src/harness/step/after-model.d.ts +7 -0
- package/dist/src/harness/step/after-model.js +1 -0
- package/dist/src/harness/step/context.d.ts +59 -0
- package/dist/src/harness/step/context.js +1 -0
- package/dist/src/harness/step/intake.d.ts +34 -0
- package/dist/src/harness/step/intake.js +1 -0
- package/dist/src/harness/step/prompt.d.ts +37 -0
- package/dist/src/harness/step/prompt.js +1 -0
- package/dist/src/harness/step-hooks.d.ts +8 -13
- package/dist/src/harness/step-hooks.js +1 -1
- package/dist/src/harness/tool-call-io.d.ts +25 -0
- package/dist/src/harness/tool-call-io.js +1 -0
- package/dist/src/harness/tool-loop.d.ts +7 -22
- package/dist/src/harness/tool-loop.js +1 -3
- package/dist/src/harness/tool-model-output.d.ts +1 -2
- package/dist/src/harness/tools.d.ts +14 -0
- package/dist/src/harness/tools.js +1 -1
- package/dist/src/harness/turn-tag-state.d.ts +1 -1
- package/dist/src/harness/types.d.ts +6 -0
- package/dist/src/instrumentation/ai-sdk-hook-bridge.d.ts +1 -1
- package/dist/src/instrumentation/ai-sdk-hook-bridge.js +1 -1
- package/dist/src/instrumentation/content.js +1 -1
- package/dist/src/instrumentation/dispatch.js +1 -1
- package/dist/src/instrumentation/lifecycle.d.ts +28 -52
- package/dist/src/instrumentation/native-events.d.ts +2 -1
- package/dist/src/instrumentation/native-events.js +1 -1
- package/dist/src/instrumentation/provider.d.ts +1 -1
- package/dist/src/instrumentation/runtime-context.d.ts +2 -3
- package/dist/src/instrumentation/runtime-context.js +1 -1
- package/dist/src/instrumentation/runtime.d.ts +11 -1
- package/dist/src/instrumentation/runtime.js +1 -1
- package/dist/src/instrumentation/state.d.ts +6 -1
- package/dist/src/instrumentation/state.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/attachments/limited-read.d.ts +16 -0
- package/dist/src/internal/attachments/limited-read.js +1 -0
- package/dist/src/internal/authored-definition/schema-backed.d.ts +2 -1
- package/dist/src/internal/authored-definition/schema-backed.js +1 -1
- package/dist/src/internal/gateway.d.ts +2 -0
- package/dist/src/internal/gateway.js +1 -1
- package/dist/src/internal/mcp/published-tools.d.ts +13 -0
- package/dist/src/internal/mcp/published-tools.js +1 -0
- package/dist/src/internal/mcp/request-trace-context.d.ts +12 -0
- package/dist/src/internal/mcp/request-trace-context.js +1 -0
- package/dist/src/internal/mcp/streamable-http-server.d.ts +7 -3
- package/dist/src/internal/mcp/streamable-http-server.js +1 -1
- package/dist/src/internal/model-auth/transport.d.ts +3 -3
- package/dist/src/internal/model-auth/transport.js +1 -1
- package/dist/src/internal/nitro/host/instrumentation-entry.js +2 -2
- package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
- package/dist/src/internal/nitro/routes/channel-request-instrumentation.js +1 -1
- package/dist/src/internal/nitro/routes/route-invoke-tool.d.ts +24 -0
- package/dist/src/internal/nitro/routes/route-invoke-tool.js +1 -0
- package/dist/src/models/auto.d.ts +5 -5
- package/dist/src/models/auto.js +2 -2
- package/dist/src/protocol/message.d.ts +7 -0
- package/dist/src/protocol/message.js +1 -1
- package/dist/src/protocol/session-projection.d.ts +159 -0
- package/dist/src/protocol/session-projection.js +1 -0
- package/dist/src/public/ai/index.d.ts +1 -1
- package/dist/src/public/ai/index.js +1 -1
- package/dist/src/public/channels/chat-sdk/attachment-refs.d.ts +15 -0
- package/dist/src/public/channels/chat-sdk/attachment-refs.js +1 -0
- package/dist/src/public/channels/chat-sdk/chatSdkChannel.js +2 -2
- package/dist/src/public/channels/chat-sdk/messageToUserContent.d.ts +11 -5
- package/dist/src/public/channels/chat-sdk/messageToUserContent.js +1 -1
- package/dist/src/public/channels/discord/attachments.d.ts +15 -0
- package/dist/src/public/channels/discord/attachments.js +1 -0
- package/dist/src/public/channels/discord/discordChannel.js +1 -1
- package/dist/src/public/channels/discord/inbound.d.ts +13 -0
- package/dist/src/public/channels/discord/inbound.js +1 -1
- package/dist/src/public/channels/index.d.ts +1 -1
- package/dist/src/public/channels/linear/inbound-uploads.d.ts +21 -0
- package/dist/src/public/channels/linear/inbound-uploads.js +1 -0
- package/dist/src/public/channels/linear/linearChannel.js +1 -1
- package/dist/src/public/channels/linq/inboundContent.d.ts +7 -1
- package/dist/src/public/channels/linq/inboundContent.js +1 -1
- package/dist/src/public/channels/linq/linqChannel.js +1 -1
- package/dist/src/public/channels/mcp.d.ts +17 -2
- package/dist/src/public/channels/mcp.js +1 -1
- package/dist/src/public/channels/photon/attachments.d.ts +21 -0
- package/dist/src/public/channels/photon/attachments.js +1 -0
- package/dist/src/public/channels/photon/photonIMessageChannel.js +1 -1
- package/dist/src/public/channels/slack/attachments.d.ts +3 -1
- package/dist/src/public/channels/slack/attachments.js +1 -1
- package/dist/src/public/channels/slack/slackChannel.js +1 -1
- package/dist/src/public/channels/teams/attachments.d.ts +4 -4
- package/dist/src/public/channels/teams/attachments.js +1 -1
- package/dist/src/public/channels/telegram/attachments.js +1 -1
- package/dist/src/public/channels/twilio/api.d.ts +7 -0
- package/dist/src/public/channels/twilio/api.js +1 -1
- package/dist/src/public/channels/twilio/inbound.d.ts +7 -0
- package/dist/src/public/channels/twilio/inbound.js +2 -2
- package/dist/src/public/channels/twilio/twilioChannel.js +1 -1
- package/dist/src/public/definitions/channel.d.ts +1 -0
- package/dist/src/public/definitions/connections/mcp.d.ts +1 -1
- package/dist/src/public/definitions/connections/openapi.d.ts +1 -1
- package/dist/src/public/models/openai/chatgpt/model.js +1 -1
- package/dist/src/react/index.d.ts +1 -0
- package/dist/src/react/index.js +1 -1
- package/dist/src/runtime/agent/mock-model-adapter.js +2 -2
- package/dist/src/runtime/connections/mcp-client.js +1 -1
- package/dist/src/runtime/connections/scoped-authorization.js +1 -1
- package/dist/src/runtime/resolve-tool.js +1 -1
- package/dist/src/setup/boxes/resolve-provisioning.d.ts +2 -0
- package/dist/src/setup/boxes/resolve-provisioning.js +1 -1
- package/dist/src/setup/cli/prompt-ui.d.ts +3 -0
- package/dist/src/setup/cli/prompt-ui.js +3 -1
- package/dist/src/setup/cli/select-component.d.ts +1 -0
- package/dist/src/setup/cli/select-component.js +1 -1
- package/dist/src/setup/flows/ensure-vercel-project.d.ts +2 -0
- package/dist/src/setup/flows/ensure-vercel-project.js +1 -1
- package/dist/src/setup/integrations/discord/api.js +1 -1
- package/dist/src/setup/integrations/web/auth-options.d.ts +4 -0
- package/dist/src/setup/integrations/web/auth-options.js +1 -0
- package/dist/src/setup/integrations/web/auth-scaffold.d.ts +7 -0
- package/dist/src/setup/integrations/web/auth-scaffold.js +1 -0
- package/dist/src/setup/integrations/web/provision-auth.d.ts +3 -0
- package/dist/src/setup/integrations/web/provision-auth.js +1 -0
- package/dist/src/setup/integrations/web/setup.d.ts +11 -6
- package/dist/src/setup/integrations/web/setup.js +3 -3
- package/dist/src/setup/prompter.d.ts +2 -0
- package/dist/src/setup/prompter.js +1 -1
- package/dist/src/setup/scaffold/create/add-to-project.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +2 -2
- package/dist/src/setup/scaffold/create/web-template.d.ts +3 -3
- package/dist/src/setup/scaffold/create/web-template.js +26 -8
- package/dist/src/setup/scaffold/update/web-options.js +1 -1
- package/dist/src/setup/vercel-project-api.d.ts +9 -0
- package/dist/src/setup/vercel-project-api.js +1 -1
- package/dist/src/setup/vercel-project.d.ts +4 -2
- package/dist/src/setup/vercel-project.js +0 -0
- package/dist/src/shared/web-search.d.ts +1 -1
- package/dist/src/subagents/adapter.js +1 -1
- package/dist/src/subagents/event-proxy-step.js +1 -1
- package/dist/src/subagents/hitl-proxy.d.ts +4 -28
- package/dist/src/subagents/hitl-proxy.js +1 -1
- package/dist/src/svelte/index.d.ts +2 -0
- package/dist/src/svelte/index.js +39 -2
- package/dist/src/svelte/use-eve-agent.js +1 -1
- package/dist/src/tools/approval/policies.d.ts +5 -5
- package/dist/src/tools/approval/policies.js +1 -1
- package/dist/src/tools/framework/agent.js +1 -1
- package/dist/src/tools/provided/agent-router.js +1 -1
- package/dist/src/tools/provided/ask-question-workflow.js +1 -1
- package/dist/src/tools/provided/ask-question.js +2 -2
- package/dist/src/tools/provided/bash.js +1 -1
- package/dist/src/tools/provided/framework-tool.d.ts +3 -0
- package/dist/src/tools/provided/framework-tool.js +1 -0
- package/dist/src/tools/provided/glob.js +2 -2
- package/dist/src/tools/provided/grep.js +2 -2
- package/dist/src/tools/provided/load-skill.js +1 -1
- package/dist/src/tools/provided/no-reply.js +1 -1
- package/dist/src/tools/provided/read-file.js +2 -2
- package/dist/src/tools/provided/sleep-workflow.js +1 -1
- package/dist/src/tools/provided/sleep.js +1 -1
- package/dist/src/tools/provided/task-cancel.js +1 -1
- package/dist/src/tools/provided/task-wait.js +1 -1
- package/dist/src/tools/provided/web-fetch.js +2 -2
- package/dist/src/tools/provided/web-search.js +1 -1
- package/dist/src/tools/provided/workflow.js +1 -1
- package/dist/src/tools/provided/write-file.js +2 -2
- package/dist/src/tracing/agent-approval-instrumentation.d.ts +2 -2
- package/dist/src/tracing/agent-approval-instrumentation.js +1 -1
- package/dist/src/tracing/agent-otel-provider.js +2 -2
- package/dist/src/tracing/agent-otel-usage.d.ts +1 -1
- package/dist/src/tracing/agent-otel-usage.js +1 -1
- package/dist/src/tracing/agent-span-contract.d.ts +8 -1
- package/dist/src/tracing/agent-span-contract.js +1 -1
- package/dist/src/tracing/agent-tool-instrumentation.d.ts +16 -5
- package/dist/src/tracing/agent-tool-instrumentation.js +1 -1
- package/dist/src/tracing/agent-trace-context-codec.js +1 -1
- package/dist/src/tracing/agent-trace-span-processor.js +1 -1
- package/dist/src/tracing/agent-trace-state.d.ts +8 -3
- package/dist/src/tracing/install-instrumentation-runtime.js +1 -1
- package/dist/src/tracing/invoke-tool-span.d.ts +61 -0
- package/dist/src/tracing/invoke-tool-span.js +1 -0
- package/dist/src/tracing/local-trace-analysis.js +1 -1
- package/dist/src/vue/index.d.ts +2 -0
- package/dist/src/vue/index.js +39 -2
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/agent-config.md +2 -2
- package/docs/channels/chat-sdk.mdx +3 -1
- package/docs/channels/custom.mdx +3 -0
- package/docs/channels/discord.mdx +5 -4
- package/docs/channels/eve.mdx +65 -0
- package/docs/channels/linear.mdx +1 -1
- package/docs/channels/linq.mdx +2 -0
- package/docs/channels/mcp.mdx +39 -1
- package/docs/channels/photon.mdx +5 -0
- package/docs/channels/teams.mdx +4 -7
- package/docs/channels/twilio.mdx +1 -1
- package/docs/concepts/built-in-tools.md +12 -0
- package/docs/concepts/sessions-runs-and-streaming.md +3 -3
- package/docs/connections/overview.mdx +1 -1
- package/docs/dynamic-configuration/meta.json +1 -1
- package/docs/evals/judge.mdx +16 -16
- package/docs/evals/overview.mdx +1 -1
- package/docs/guides/{evaluate.md → decide.md} +35 -35
- package/docs/guides/dynamic-capabilities.md +1 -1
- package/docs/guides/frontend/overview.mdx +3 -1
- package/docs/guides/hooks.md +1 -1
- package/docs/guides/instrumentation/instrumentation.mdx +23 -22
- package/docs/guides/instrumentation/otel.mdx +13 -2
- package/docs/reference/cli.md +4 -2
- package/docs/reference/typescript-api.md +4 -2
- package/docs/tools/human-in-the-loop.md +8 -4
- package/docs/tools/workflows.mdx +4 -4
- package/package.json +13 -11
- package/dist/src/ai/evaluate.d.ts +0 -7
- package/dist/src/ai/evaluate.js +0 -1
- package/dist/src/client/message-task-parts.d.ts +0 -8
- package/dist/src/client/message-task-parts.js +0 -1
- package/dist/src/compiled/_chunks/workflow/dist-C3ZE62yI.js +0 -25
- package/dist/src/compiled/_chunks/workflow/experimental-evaluation-Dm32egEG.js +0 -5
- package/dist/src/harness/active-turn-id.d.ts +0 -11
- package/dist/src/harness/active-turn-id.js +0 -1
- package/dist/src/harness/approval-candidates.js +0 -1
- package/dist/src/harness/approval-delivery-coordinator.js +0 -1
- package/dist/src/harness/cancelled-turn-emission.d.ts +0 -12
- package/dist/src/harness/cancelled-turn-emission.js +0 -1
- package/dist/src/harness/emission-state.d.ts +0 -26
- package/dist/src/harness/emission-state.js +0 -1
- package/dist/src/harness/held-requests.d.ts +0 -18
- package/dist/src/harness/held-requests.js +0 -1
- package/dist/src/harness/hitl/approval-input-requests.d.ts +0 -27
- package/dist/src/harness/hitl/approval-input-requests.js +0 -1
- package/dist/src/harness/hitl/pending-input-resolution.d.ts +0 -54
- package/dist/src/harness/hitl/pending-input-resolution.js +0 -1
- package/dist/src/harness/hitl/session-limit-input-requests.d.ts +0 -12
- package/dist/src/harness/hitl/session-limit-input-requests.js +0 -1
- package/dist/src/harness/input-requests.d.ts +0 -31
- package/dist/src/harness/input-requests.js +0 -1
- package/dist/src/harness/pending-input-batches.d.ts +0 -81
- package/dist/src/harness/pending-input-batches.js +0 -1
- package/dist/src/harness/session-limit-continuation.js +0 -1
- package/dist/src/harness/session-limit-enforcement.d.ts +0 -45
- package/dist/src/harness/session-limit-enforcement.js +0 -1
- package/dist/src/harness/stale-input-responses.js +0 -3
- package/dist/src/harness/workflow-dispatch.d.ts +0 -30
- package/dist/src/harness/workflow-dispatch.js +0 -1
- package/dist/src/public/channels/linear/inbound-images.d.ts +0 -19
- package/dist/src/public/channels/linear/inbound-images.js +0 -1
- package/dist/src/tracing/agent-action-instrumentation.d.ts +0 -25
- package/dist/src/tracing/agent-action-instrumentation.js +0 -1
- /package/dist/src/harness/{compaction.d.ts → compaction/engine.d.ts} +0 -0
- /package/dist/src/harness/{compaction-prompt.d.ts → compaction/prompt.d.ts} +0 -0
- /package/dist/src/harness/{compaction-prompt.js → compaction/prompt.js} +0 -0
- /package/dist/src/harness/{approval-delivery-coordinator.d.ts → hitl/coordinator.d.ts} +0 -0
- /package/dist/src/harness/{model-call-error.js → model-call/errors.js} +0 -0
|
@@ -1,76 +1,44 @@
|
|
|
1
1
|
import type { ModelMessage } from "ai";
|
|
2
|
-
import type { RuntimeActionRequest, RuntimeWorkflowTaskRequest, WorkflowToolCallEntry } from "#shared/action-types.js";
|
|
2
|
+
import type { RuntimeActionRequest, RuntimeActionResult, RuntimeWorkflowTaskRequest, WorkflowToolCallEntry } from "#shared/action-types.js";
|
|
3
3
|
import { type JsonObject } from "#shared/json.js";
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
interface PendingCoordinationEventMetadata {
|
|
12
|
-
readonly sequence: number;
|
|
13
|
-
readonly stepIndex: number;
|
|
14
|
-
readonly turnId: string;
|
|
15
|
-
}
|
|
16
|
-
/** Serializable pending coordination batch stored on `session.state`. */
|
|
17
|
-
export interface PendingCoordinationBatch {
|
|
18
|
-
/** Workflow tool runs pending coordination, including agent tools. */
|
|
19
|
-
readonly tasks: readonly RuntimeWorkflowTaskRequest[];
|
|
20
|
-
readonly event: PendingCoordinationEventMetadata;
|
|
21
|
-
readonly responseMessages: readonly ModelMessage[];
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Outcome of resolving a pending coordination batch.
|
|
25
|
-
*/
|
|
26
|
-
interface ResolvePendingCoordinationResult {
|
|
27
|
-
readonly messages: ModelMessage[];
|
|
28
|
-
readonly outcome: "continue" | "resolved" | "unresolved";
|
|
29
|
-
readonly session: HarnessSession;
|
|
30
|
-
}
|
|
31
|
-
/** Returns the pending coordination batch stored on the session, if any. */
|
|
32
|
-
export declare function getPendingCoordinationBatch(state: SessionStateMap | undefined): PendingCoordinationBatch | undefined;
|
|
33
|
-
export declare function clearPendingCoordinationBatch(session: HarnessSession): HarnessSession;
|
|
34
|
-
/** What the model reads for a call its turn's cancellation stopped before the call settled. */
|
|
35
|
-
export declare const CANCELLED_CALL_RESULT = "The turn was cancelled before this call finished.";
|
|
36
|
-
/**
|
|
37
|
-
* Moves a cancelled turn's pending batch into history instead of dropping it.
|
|
38
|
-
* The model keeps the calls it made, each answered as cancelled, so it sees
|
|
39
|
-
* that the work started and stopped rather than a request left unanswered.
|
|
40
|
-
*/
|
|
41
|
-
export declare function commitCancelledCoordinationBatch(session: HarnessSession): HarnessSession;
|
|
42
|
-
/**
|
|
43
|
-
* Stores one pending coordination batch on the session.
|
|
44
|
-
*/
|
|
45
|
-
export declare function setPendingCoordinationBatch<T extends {
|
|
46
|
-
readonly state?: SessionStateMap;
|
|
47
|
-
}>(input: {
|
|
48
|
-
readonly tasks: readonly RuntimeWorkflowTaskRequest[];
|
|
49
|
-
readonly event: PendingCoordinationEventMetadata;
|
|
50
|
-
readonly responseMessages: readonly ModelMessage[];
|
|
51
|
-
readonly session: T;
|
|
52
|
-
}): T;
|
|
4
|
+
import type { HarnessSession, HarnessToolMap } from "#harness/types.js";
|
|
5
|
+
type ToolResponsePart = Extract<ModelMessage, {
|
|
6
|
+
role: "tool";
|
|
7
|
+
}>["content"][number];
|
|
8
|
+
type ToolResultPart = Extract<ToolResponsePart, {
|
|
9
|
+
type: "tool-result";
|
|
10
|
+
}>;
|
|
53
11
|
/** Rejects a batch before any result or side effect can bind ambiguously by call id. */
|
|
54
12
|
export declare function assertUniqueCoordinationCallIds(requests: readonly {
|
|
55
13
|
readonly callId: string;
|
|
56
14
|
}[]): void;
|
|
57
|
-
/** Every call a pending batch waits on: workflow runs and task tool calls. */
|
|
58
|
-
export declare function pendingCoordinationCallIds(batch: PendingCoordinationBatch): readonly string[];
|
|
59
15
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
16
|
+
* Forgets the workflow runs whose results arrived. Nobody can answer what a finished run asked,
|
|
17
|
+
* so its relayed requests are returned for the machine to withdraw.
|
|
18
|
+
*/
|
|
19
|
+
export declare function forgetFinishedRuns(session: HarnessSession, results: readonly RuntimeActionResult[], turnId: string): {
|
|
20
|
+
readonly requestIds: readonly string[];
|
|
21
|
+
readonly session: HarnessSession;
|
|
22
|
+
};
|
|
23
|
+
/** Each runtime result as the model reads it, beside the result the stream reports. */
|
|
24
|
+
export declare function runtimeResultCalls(results: readonly RuntimeActionResult[], tools: HarnessToolMap | undefined): Promise<{
|
|
25
|
+
readonly part: ToolResultPart;
|
|
26
|
+
readonly result: RuntimeActionResult;
|
|
27
|
+
}[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Turns a step's deferred calls into workflow runs, committing a task record
|
|
30
|
+
* for each call that starts a task. Task tool calls stay in the response
|
|
31
|
+
* alone: the session reads them from there.
|
|
66
32
|
*/
|
|
67
|
-
export declare function
|
|
68
|
-
readonly
|
|
33
|
+
export declare function collectDeferredCalls(input: {
|
|
34
|
+
readonly session: HarnessSession;
|
|
35
|
+
readonly toolCalls: readonly CoordinationToolCall[];
|
|
36
|
+
readonly tools: HarnessToolMap;
|
|
37
|
+
readonly turnId: string;
|
|
38
|
+
}): {
|
|
69
39
|
readonly session: HarnessSession;
|
|
70
|
-
readonly
|
|
71
|
-
|
|
72
|
-
readonly tools?: HarnessToolMap;
|
|
73
|
-
}): Promise<ResolvePendingCoordinationResult>;
|
|
40
|
+
readonly workflowRequests: readonly RuntimeWorkflowTaskRequest[];
|
|
41
|
+
};
|
|
74
42
|
/** The parts of a model tool call that coordination turns into a runtime request. */
|
|
75
43
|
export interface CoordinationToolCall {
|
|
76
44
|
readonly input: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{parseJsonObject}from"#shared/json.js";import{findBlockingWorkflowToolRun,removeBlockingWorkflowToolRuns}from"#harness/workflow-tool-runs.js";import{getProxyInputRequests}from"#harness/proxy-input-requests.js";import{normalizeToolModelOutput}from"#harness/tool-model-output.js";import{startsTasks}from"#execution/tasks/tool-entry-point.js";import{markRuntimeWorkflowToolAction}from"#shared/action-types.js";import{commitCallEntry,isTaskTool}from"#execution/tasks/model-step.js";function assertUniqueCoordinationCallIds(e){let t=new Set;for(let n of e){if(t.has(n.callId))throw Error(`Coordination batch contains duplicate callId "${n.callId}".`);t.add(n.callId)}}function forgetFinishedRuns(e,t,n){let r=e,i=[];for(let e of t){if(e.kind!==`tool-result`)continue;let t=findBlockingWorkflowToolRun(r.state,e.callId,n);if(t!==void 0){for(let[e,n]of getProxyInputRequests(r.state))n.runId===t.address.runId&&i.push(e);r=removeBlockingWorkflowToolRuns(r,n,t.callId)}}return{requestIds:i,session:r}}async function runtimeResultCalls(e,t){let n=[];for(let r of e){switch(r.kind){case`load-skill-result`:n.push({part:toolResult(r,`load_skill`,toToolResultOutput(r)),result:r});continue;case`subagent-result`:n.push({part:toolResult(r,r.subagentName,toToolResultOutput(r)),result:r});continue;case`tool-result`:n.push({part:toolResult(r,r.toolName,await projectToolResultOutput(r,t?.get(r.toolName))),result:r});continue}throw Error(`Unsupported runtime action result kind "${String(r)}".`)}return n}function toolResult(e,t,n){return{output:n,toolCallId:e.callId,toolName:t,type:`tool-result`}}function collectDeferredCalls(e){let{session:t}=e,n=[];for(let r of e.toolCalls){let i=e.tools.get(r.toolName);if(isTaskTool(i))continue;let a=commitCallEntry(t,{callId:r.toolCallId,definition:i,input:resolveToolCallInputObject(r.input,{callId:r.toolCallId,toolName:r.toolName}),toolName:r.toolName,turnId:e.turnId});t=a.session,n.push(createCoordinationRequestFromToolCall({entry:a.entry,input:a.input,toolCall:r,tools:e.tools}))}return{session:t,workflowRequests:n}}function createRuntimeActionRequestFromToolCall(e){let t=e.tools.get(e.toolCall.toolName),n=resolveToolCallInputObject(e.toolCall.input,{callId:e.toolCall.toolCallId,toolName:e.toolCall.toolName});if(t?.frameworkAction===`load-skill`)return{callId:e.toolCall.toolCallId,input:n,kind:`load-skill`};let r=t?.behavior?.handling;if(t!==void 0&&r?.kind===`dispatch`&&r.target.kind!==`workflow-tool-call`){let i=r.target,a={callId:e.toolCall.toolCallId,description:t.description,input:n,name:e.toolCall.toolName,nodeId:i.nodeId};return i.kind===`remote-agent-call`?{...a,kind:`remote-agent-call`,remoteAgentName:i.remoteAgentName}:{...a,kind:`subagent-call`,subagentName:i.subagentName}}let i={callId:e.toolCall.toolCallId,input:n,kind:`tool-call`,toolName:e.toolCall.toolName};return t?.workflowId===void 0?i:markRuntimeWorkflowToolAction(i)}function createCoordinationRequestFromToolCall(e){let t=e.tools.get(e.toolCall.toolName);if(t?.workflowId===void 0)throw Error(`Deferred tool "${e.toolCall.toolName}" has no workflow.`);return{callId:e.toolCall.toolCallId,entry:e.entry,executeInput:t.executeInput?.(e.input),input:e.input,kind:`workflow-task`,toolName:e.toolCall.toolName,workflowId:t.workflowId}}function resolveToolCallInputObject(e,t){if(e==null||typeof e==`string`&&e.trim()===``)return{};try{return parseJsonObject(typeof e==`string`?parseJsonStringInput(e):e)}catch(e){let n=e instanceof Error?e.message:String(e);throw TypeError(`Failed to parse tool-call arguments for "${t.toolName}" (${t.callId}): ${n}`,{cause:e})}}function parseJsonStringInput(e){return JSON.parse(e)}async function projectToolResultOutput(e,t){return e.isError===!0||t?.toModelOutput===void 0||startsTasks(t)?toToolResultOutput(e):normalizeToolModelOutput({output:await t.toModelOutput(e.output),toolCallId:e.callId,toolName:e.toolName})}function toToolResultOutput(e){return typeof e.output==`string`?e.isError===!0?{type:`error-text`,value:e.output}:{type:`text`,value:e.output}:e.isError===!0?{type:`error-json`,value:toMutableJsonValue(e.output)}:{type:`json`,value:toMutableJsonValue(e.output)}}function toMutableJsonValue(e){if(e===null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e;if(Array.isArray(e))return e.map(e=>toMutableJsonValue(e));let t={};for(let[n,r]of Object.entries(e))t[n]=toMutableJsonValue(r);return t}export{assertUniqueCoordinationCallIds,collectDeferredCalls,createCoordinationRequestFromToolCall,createRuntimeActionRequestFromToolCall,forgetFinishedRuns,resolveToolCallInputObject,runtimeResultCalls};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SystemModelMessage } from "ai";
|
|
2
2
|
import type { HistoryState } from "#context/keys.js";
|
|
3
3
|
import type { Announcement } from "#harness/announcements.js";
|
|
4
4
|
import { type FrameworkMessageKind, type HarnessModelMessage } from "#harness/messages.js";
|
|
@@ -24,6 +24,4 @@ export declare function createCurrentMessages(history: readonly HarnessModelMess
|
|
|
24
24
|
addAnnouncements(announcements: CurrentAnnouncements): void;
|
|
25
25
|
addSystem(messages: SystemModelMessage | readonly SystemModelMessage[]): void;
|
|
26
26
|
};
|
|
27
|
-
/** True when the history ends with a tool message carrying a tool-approval-response. */
|
|
28
|
-
export declare function hasTailApprovalResponse(messages: readonly ModelMessage[]): boolean;
|
|
29
27
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createFrameworkUserMessage}from"#harness/messages.js";function createCurrentMessages(e,t={}){let n=[...e],r={...t.historyState},i=[],a=[],o=new Set(t.currentTurnMessages),s;for(let n of t.projectedMessages??e)s===void 0&&o.has(n)&&(s=a.length),n.role===`system`?i.push(n):a.push(n);let c=s??a.length,l=e.findIndex(e=>o.has(e)),u=l===-1?e.length:l
|
|
1
|
+
import{createFrameworkUserMessage}from"#harness/messages.js";function createCurrentMessages(e,t={}){let n=[...e],r={...t.historyState},i=[],a=[],o=new Set(t.currentTurnMessages),s;for(let n of t.projectedMessages??e)s===void 0&&o.has(n)&&(s=a.length),n.role===`system`?i.push(n):a.push(n);let c=s??a.length,l=e.findIndex(e=>o.has(e)),u=l===-1?e.length:l;function appendUserMessage(e,t){let r=createFrameworkUserMessage(t,e);a.splice(c,0,r),n.splice(u,0,r),c+=1,u+=1}function add(e,t,{cacheFriendly:n=!0}={}){if(n){appendUserMessage(e,t);return}i.push({role:`system`,content:e})}return{add,addAnnouncements(e){let t=e.availableSkills;t!==void 0&&t.length>0&&r.availableSkills!==t&&(appendUserMessage(t,`context.state`),r.availableSkills=t);let n=e.keyed??{};for(let e of Object.keys(n).sort()){let t=n[e],i=r.announcements?.[e];if(i===t.value)continue;let a=t.render(i);a!==void 0&&appendUserMessage(a,`context.state`),r.announcements={...r.announcements,[e]:t.value}}},addSystem(e){i.push(...Array.isArray(e)?e:[e])},get nonSystemMessages(){return[...a]},get history(){return[...n]},get historyState(){return{...r}},get systemMessages(){return[...i]}}}export{createCurrentMessages};
|
|
@@ -5,57 +5,8 @@ type ToolResponsePart = Extract<ModelMessage, {
|
|
|
5
5
|
type InlineToolResultPart = Extract<ToolResponsePart, {
|
|
6
6
|
type: "tool-result";
|
|
7
7
|
}>;
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
10
|
-
import type { TokenUsage } from "#shared/token-usage.js";
|
|
11
|
-
import type { HarnessEmissionState } from "#harness/emission-state.js";
|
|
12
|
-
import type { HarnessEmitFn, HarnessToolMap, StepInput } from "#harness/types.js";
|
|
13
|
-
export { getHarnessEmissionState, isHarnessBetweenTurns, setHarnessEmissionState, } from "#harness/emission-state.js";
|
|
14
|
-
export type { HarnessEmissionState } from "#harness/emission-state.js";
|
|
15
|
-
/**
|
|
16
|
-
* Emits `session.started` (once), `turn.started`, and `message.received` at the
|
|
17
|
-
* beginning of a new turn. Returns updated emission state.
|
|
18
|
-
*/
|
|
19
|
-
export declare function emitTurnPreamble(emitFn: HarnessEmitFn, input: StepInput, state: HarnessEmissionState, messages: readonly ModelMessage[], runtimeIdentity?: RuntimeIdentity, traceContext?: RuntimeTraceContext): Promise<HarnessEmissionState>;
|
|
20
|
-
/**
|
|
21
|
-
* Emits `step.started` for one model call.
|
|
22
|
-
*/
|
|
23
|
-
export declare function emitStepStarted(emitFn: HarnessEmitFn, state: HarnessEmissionState, modelId: string, messages?: readonly import("ai").ModelMessage[]): Promise<void>;
|
|
24
|
-
interface FailedStepPayload {
|
|
25
|
-
readonly code: string;
|
|
26
|
-
readonly details?: JsonObject;
|
|
27
|
-
readonly message: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Emits the full terminal failure cascade: `step.failed` →
|
|
31
|
-
* `turn.failed` → `session.failed`.
|
|
32
|
-
*
|
|
33
|
-
* Use this when the session cannot be salvaged (structural config
|
|
34
|
-
* error, auth misconfig, non-recoverable provider response). The
|
|
35
|
-
* `session.failed` tail tells adapters the session is dead and no
|
|
36
|
-
* further follow-up is possible on the same continuation token.
|
|
37
|
-
*/
|
|
38
|
-
export declare function emitFailedStep(emitFn: HarnessEmitFn, state: HarnessEmissionState, input: FailedStepPayload & {
|
|
39
|
-
readonly sessionId: string;
|
|
40
|
-
readonly usage: TokenUsage;
|
|
41
|
-
}): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Emits the recoverable failure cascade: `step.failed` →
|
|
44
|
-
* `turn.failed` → `session.waiting`.
|
|
45
|
-
*/
|
|
46
|
-
export declare function emitRecoverableFailedTurn(emitFn: HarnessEmitFn, state: HarnessEmissionState, input: FailedStepPayload & {
|
|
47
|
-
readonly continuationToken: string;
|
|
48
|
-
readonly usage: TokenUsage;
|
|
49
|
-
}): Promise<HarnessEmissionState>;
|
|
50
|
-
/**
|
|
51
|
-
* Returns updated emission state for the next step in the current turn.
|
|
52
|
-
*/
|
|
53
|
-
export declare function advanceStep(state: HarnessEmissionState): HarnessEmissionState;
|
|
54
|
-
/**
|
|
55
|
-
* Emits `turn.completed` and `session.waiting` with the session's `usage`.
|
|
56
|
-
* Returns updated emission state with an incremented sequence.
|
|
57
|
-
*/
|
|
58
|
-
export declare function emitTurnEpilogue(emitFn: HarnessEmitFn, state: HarnessEmissionState, messages: readonly ModelMessage[], usage: TokenUsage): Promise<HarnessEmissionState>;
|
|
8
|
+
import type { TurnPosition } from "#harness/session-machine/view.js";
|
|
9
|
+
import type { HarnessEmitFn, HarnessToolMap } from "#harness/types.js";
|
|
59
10
|
/**
|
|
60
11
|
* Result of consuming one step's `fullStream`.
|
|
61
12
|
*
|
|
@@ -87,4 +38,5 @@ interface StreamActionEmissionOptions {
|
|
|
87
38
|
* stream batch into one request event before their first result. A result
|
|
88
39
|
* without a streamed call resumes a call from an earlier step.
|
|
89
40
|
*/
|
|
90
|
-
export declare function emitStreamContent(emitFn: HarnessEmitFn, state:
|
|
41
|
+
export declare function emitStreamContent(emitFn: HarnessEmitFn, state: TurnPosition, fullStream: AsyncIterable<TextStreamPart<ToolSet>>, options?: StreamActionEmissionOptions): Promise<EmittedStreamContent>;
|
|
42
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createActionInputAppendedEvent,createActionPartialEvent,createActionResultEvent,createActionsRequestedEvent,createMessageAppendedEvent,createMessageCompletedEvent,
|
|
1
|
+
import{createActionInputAppendedEvent,createActionPartialEvent,createActionResultEvent,createActionsRequestedEvent,createMessageAppendedEvent,createMessageCompletedEvent,createReasoningAppendedEvent,createReasoningCompletedEvent}from"#protocol/message.js";import{createRuntimeToolResultFromStepResult,createRuntimeToolResultFromToolError,createToolResultMessagePartFromToolError}from"#harness/action-result-helpers.js";import{emitNestedToolActions}from"#harness/nested-actions.js";import{createInvalidToolCallInputError,isInvalidToolCall,resolveProviderToolCallRequest}from"#harness/tool-call-input-errors.js";import{collectActionPresentation,createPresentedRuntimeActionRequestFromToolCall}from"#harness/action-presentation.js";import{projectDeltaPresentation,projectResultPresentation}from"#harness/tool-presentation.js";import{createProviderStreamActionBatch}from"#harness/stream-actions.js";import{normalizeModelStreamError}from"#harness/model-call/errors.js";import{createOrderedStreamEmitter}from"#harness/ordered-stream-emitter.js";import{interruptStreamOnFailure}from"#harness/interruptible-stream.js";import{isInlineAuthorizationToolResult}from"#harness/inline-tool-authorization.js";import{normalizeAssistantStepFinishReason}from"#harness/finish-reason.js";async function emitStreamContent(e,t,n,r){let i=createOrderedStreamEmitter(e),a=createProviderStreamActionBatch({emitFn:i.emit,state:t});try{return await consumeStreamContent(i.emit,t,interruptStreamOnFailure(n,i.failureSignal),a,r)}finally{try{await a.cancel()}finally{await i.closeAndDrain()}}}function reportedFinishReason(e,t){return t&&e===`stop`?`tool-calls`:e}async function consumeStreamContent(e,t,n,r,i){let a=``,o=``,s=`stop`,c,l=new Set,u=new Set,d=new Set,f=new Set,p=new Set,m=new Set,h=[],g=[],_=new Map,v=new Map,flushCurrentMessage=async()=>{o.length!==0&&(await e(createMessageCompletedEvent({finishReason:`tool-calls`,message:o,sequence:t.sequence,stepIndex:t.stepIndex,turnId:t.turnId})),o=``)},emitActionInput=async(n,r,i)=>e(createActionInputAppendedEvent({callId:n,inputTextDelta:i,sequence:t.sequence,stepIndex:t.stepIndex,toolName:r,turnId:t.turnId})),emitActionRequest=async n=>{let{action:r}=n;u.has(r.callId)||(o.trim().length>0&&await flushCurrentMessage(),u.add(r.callId),_.set(r.callId,r.input),await e(createActionsRequestedEvent({actions:[r],presentation:collectActionPresentation([n]),sequence:t.sequence,stepIndex:t.stepIndex,turnId:t.turnId})))},collectProviderToolCall=async e=>{if(f.has(e.toolCallId)||(f.add(e.toolCallId),u.has(e.toolCallId)))return;u.add(e.toolCallId),o.trim().length>0&&await flushCurrentMessage();let t=resolveProviderToolCallRequest(e,i?.tools??new Map);if(t.toolError!==void 0){m.add(e.toolCallId),await emitActionResult(createRuntimeToolResultFromToolError(t.toolError)),p.add(e.toolCallId),g.push(createToolResultMessagePartFromToolError(t.toolError));return}_.set(t.request.action.callId,t.request.action.input),r.observe(t.request)},emitActionResult=async n=>{if(d.has(n.callId))return;d.add(n.callId),await emitNestedToolActions(e,t,n.callId);let r=n.isError===!0?void 0:projectResultPresentation(i?.tools.get(n.toolName),n.callId,_.get(n.callId),n.output);await e(createActionResultEvent({presentation:r,result:n,sequence:t.sequence,stepIndex:t.stepIndex,turnId:t.turnId}))},emitActionPartial=async n=>{let r=projectDeltaPresentation(i?.tools.get(n.toolName),n.callId,_.get(n.callId),n.output);await e(createActionPartialEvent({presentation:r,result:n,sequence:t.sequence,stepIndex:t.stepIndex,turnId:t.turnId}))},emitToolCall=async e=>{if(isInvalidToolCall(e)){m.add(e.toolCallId);return}if(!(i===void 0||i.excludedActionToolNames.has(e.toolName)))try{await emitActionRequest(createPresentedRuntimeActionRequestFromToolCall({toolCall:e,tools:i.tools}))}catch(t){if(t instanceof TypeError){let n=createInvalidToolCallInputError({error:t,toolCall:e});m.add(e.toolCallId),o.trim().length>0&&await flushCurrentMessage(),await emitActionResult(createRuntimeToolResultFromToolError(n)),p.add(e.toolCallId),g.push(createToolResultMessagePartFromToolError(n));return}throw t}};for await(let d of n)if(c===void 0)switch(d.type){case`reasoning-delta`:await r.flush(),a+=d.text,await e(createReasoningAppendedEvent({reasoningDelta:d.text,sequence:t.sequence,stepIndex:t.stepIndex,turnId:t.turnId}));break;case`text-delta`:await r.flush(),a.trim().length>0&&(await e(createReasoningCompletedEvent({reasoning:a,sequence:t.sequence,stepIndex:t.stepIndex,turnId:t.turnId})),a=``),o+=d.text,await e(createMessageAppendedEvent({messageDelta:d.text,sequence:t.sequence,stepIndex:t.stepIndex,turnId:t.turnId}));break;case`tool-input-start`:if(i===void 0||d.providerExecuted===!0||i.excludedActionToolNames.has(d.toolName)){v.delete(d.id);break}await r.flush(),o.trim().length>0&&await flushCurrentMessage(),v.set(d.id,{toolName:d.toolName});break;case`tool-input-delta`:{let e=v.get(d.id);if(e===void 0)break;await r.flush(),await emitActionInput(d.id,e.toolName,d.delta);break}case`tool-input-end`:v.delete(d.id);break;case`tool-call`:{let e=d;v.delete(e.toolCallId),l.add(e.toolCallId),e.providerExecuted===!0?await collectProviderToolCall(e):(await r.flush(),await emitToolCall(e));break}case`tool-result`:{let e=d;if(e.preliminary===!0){e.providerExecuted!==!0&&await emitActionPartial(createRuntimeToolResultFromStepResult(e));break}if(e.providerExecuted===!0){await collectProviderToolCall({input:`input`in e?e.input:void 0,toolCallId:e.toolCallId,toolName:e.toolName}),await r.flush(),await emitActionResult(createRuntimeToolResultFromStepResult(e));break}if(l.has(d.toolCallId)){if(isInlineAuthorizationToolResult(e))break;u.has(d.toolCallId)&&(await emitActionResult(createRuntimeToolResultFromStepResult(e)),p.add(d.toolCallId));break}if(await r.flush(),await flushCurrentMessage(),isInlineAuthorizationToolResult(e)){p.add(d.toolCallId),h.push(e);break}await emitActionResult(createRuntimeToolResultFromStepResult(e)),p.add(d.toolCallId);break}case`tool-error`:{let e=d;e.providerExecuted===!0?(await collectProviderToolCall(e),await r.flush(),await emitActionResult(createRuntimeToolResultFromToolError(e))):u.has(e.toolCallId)&&(await emitActionResult(createRuntimeToolResultFromToolError(e)),p.add(e.toolCallId),g.push(createToolResultMessagePartFromToolError(e)));break}case`finish-step`:s=normalizeAssistantStepFinishReason(d.finishReason),await r.flush();break;case`error`:c=normalizeModelStreamError(d.error);break;case`abort`:throw new DOMException(d.reason??`The model stream was aborted.`,`AbortError`)}if(await r.flush(),c!==void 0)throw c;return a.trim().length>0&&await e(createReasoningCompletedEvent({reasoning:a,sequence:t.sequence,stepIndex:t.stepIndex,turnId:t.turnId})),s!==`content-filter`&&o.trim().length>0&&await e(createMessageCompletedEvent({finishReason:reportedFinishReason(s,i?.hidesHeldText===!0),message:o,sequence:t.sequence,stepIndex:t.stepIndex,turnId:t.turnId})),{emittedActionCallIds:u,handledInlineToolResultCallIds:p,invalidInputToolCallIds:m,inlineAuthorizationResults:h,trailingInlineToolResultParts:g}}export{emitStreamContent};
|
|
@@ -17,6 +17,7 @@ export interface HarnessToolDefinition {
|
|
|
17
17
|
readonly execute?: (input: any, options: ToolExecuteOptions) => any;
|
|
18
18
|
/** Optional JSON input substituted when this tool starts its workflow body. */
|
|
19
19
|
readonly executeInput?: (input: unknown) => JsonValue;
|
|
20
|
+
readonly frameworkTool?: boolean;
|
|
20
21
|
readonly frameworkAction?: "load-skill" | "task-cancel" | "task-wait";
|
|
21
22
|
readonly inputSchema: FlexibleSchema;
|
|
22
23
|
readonly name: string;
|
|
@@ -4,6 +4,11 @@ import type { JsonObject } from "#shared/json.js";
|
|
|
4
4
|
* Stable model-visible name for the kernel structured-output interception.
|
|
5
5
|
*/
|
|
6
6
|
export declare const FINAL_OUTPUT_TOOL_NAME = "final_output";
|
|
7
|
+
/**
|
|
8
|
+
* What the model reads when it gives its final output beside calls whose results it hasn't seen:
|
|
9
|
+
* the turn can't end on an answer written before them, so it answers again once they arrive.
|
|
10
|
+
*/
|
|
11
|
+
export declare const FINAL_OUTPUT_BESIDE_PENDING_CALLS = "Your final output wasn't delivered because other calls in this response were still running. Use their results, then call final_output again.";
|
|
7
12
|
/**
|
|
8
13
|
* Builds the model-facing `final_output` tool from a lowered output schema.
|
|
9
14
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineJsonSchema,toModelSchema}from"#tools/schema.js";const FINAL_OUTPUT_TOOL_NAME=`final_output
|
|
1
|
+
import{defineJsonSchema,toModelSchema}from"#tools/schema.js";const FINAL_OUTPUT_TOOL_NAME=`final_output`,FINAL_OUTPUT_BESIDE_PENDING_CALLS=`Your final output wasn't delivered because other calls in this response were still running. Use their results, then call final_output again.`;function buildFinalOutputTool(e){let t=toModelSchema(defineJsonSchema(e),`input`);return{description:`Deliver your final answer in the required structure by calling this tool. Call it exactly once, when you are done; do not answer in prose.`,inputSchema:t,outputSchema:t}}export{FINAL_OUTPUT_BESIDE_PENDING_CALLS,FINAL_OUTPUT_TOOL_NAME,buildFinalOutputTool};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { SessionAuthContext } from "#channel/types.js";
|
|
2
|
+
import type { ModelMessage } from "ai";
|
|
3
|
+
import type { getApprovalAuditState } from "#harness/hitl/candidates.js";
|
|
4
|
+
import { type AuthorizationChallenge } from "#harness/authorization.js";
|
|
5
|
+
import { type ResolvedInputBatch } from "#harness/input-request-resolution.js";
|
|
6
|
+
import type { StepInput } from "#harness/types.js";
|
|
7
|
+
import type { RuntimeWorkflowTaskRequest } from "#shared/action-types.js";
|
|
8
|
+
import type { InputRequest } from "#shared/input.js";
|
|
9
|
+
import type { Transition } from "#harness/session-machine/commit.js";
|
|
10
|
+
import { type ResolvedStepInput } from "./delivery.js";
|
|
11
|
+
import type { StepCoordinates, SuspendedStep } from "#harness/session-machine/view.js";
|
|
12
|
+
import { type SessionView } from "#harness/session-machine/view.js";
|
|
13
|
+
/**
|
|
14
|
+
* A model response made calls that need a person's approval. The response waits in a suspended
|
|
15
|
+
* step, beside any runtime calls it made, and the turn holds until the answers arrive.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parkOnApprovals(view: SessionView, input: {
|
|
18
|
+
readonly event: StepCoordinates;
|
|
19
|
+
readonly messages: readonly ModelMessage[];
|
|
20
|
+
readonly requests: readonly InputRequest[];
|
|
21
|
+
readonly tasks: readonly RuntimeWorkflowTaskRequest[];
|
|
22
|
+
readonly responseAuthRequiredRequestIds?: readonly string[];
|
|
23
|
+
readonly requester?: SuspendedStep["requester"];
|
|
24
|
+
}): Transition;
|
|
25
|
+
/** Approved workflow and agent calls join the runs their steps wait on, as their approvers. */
|
|
26
|
+
export declare function dispatch(view: SessionView, input: {
|
|
27
|
+
readonly approvers: Readonly<Record<string, SessionAuthContext>>;
|
|
28
|
+
readonly tasks: readonly RuntimeWorkflowTaskRequest[];
|
|
29
|
+
}): Transition;
|
|
30
|
+
/**
|
|
31
|
+
* Approved calls run before the delivery's own input, as the AI SDK ran them: the model reads
|
|
32
|
+
* their results first. The input waits in the queue, unreceived, for the step after.
|
|
33
|
+
*/
|
|
34
|
+
export declare function deferInput(view: SessionView, input: StepInput): Transition;
|
|
35
|
+
/** What the approval-response policies did with a delivery, before `answer` reads it. */
|
|
36
|
+
export interface ResponsePolicyPass {
|
|
37
|
+
readonly kind: "continue" | "continue-coordination" | "authorization-required" | "responses-completed" | "park";
|
|
38
|
+
readonly challenges: readonly AuthorizationChallenge[];
|
|
39
|
+
readonly feedback: readonly string[];
|
|
40
|
+
/** The delivery minus the answers the policies took, plus the settlements they reached. */
|
|
41
|
+
readonly stepInput?: StepInput;
|
|
42
|
+
readonly audit: ReturnType<typeof getApprovalAuditState>;
|
|
43
|
+
/** Responder sign-ins pending when the pass began. */
|
|
44
|
+
readonly challengesAtStart: readonly AuthorizationChallenge[];
|
|
45
|
+
}
|
|
46
|
+
/** What `answer` concluded, beyond the events and state it changed. */
|
|
47
|
+
export interface Answered extends Transition {
|
|
48
|
+
/**
|
|
49
|
+
* `continue`: the step goes on. `park`: nothing can run until more input arrives.
|
|
50
|
+
* `repeat`: a policy pass committed, so the next pass runs in a fresh step. `sign-in`: a
|
|
51
|
+
* responder must sign in first. `defer-message`: a message arrived while the session-limit
|
|
52
|
+
* prompt is open; it waits in its turn for the prompt.
|
|
53
|
+
*/
|
|
54
|
+
readonly next: "continue" | "park" | "repeat" | "sign-in" | "defer-message";
|
|
55
|
+
/** The turn's input, without the answers `answer` consumed. */
|
|
56
|
+
readonly input?: StepInput;
|
|
57
|
+
/** Whether a plain-text answer consumed the message. */
|
|
58
|
+
readonly consumedMessage?: boolean;
|
|
59
|
+
/** The batches the delivery resolved, in order. */
|
|
60
|
+
readonly resolved: readonly ResolvedInputBatch[];
|
|
61
|
+
/** A decision on the session-limit prompt. */
|
|
62
|
+
readonly limit?: {
|
|
63
|
+
readonly granted: boolean;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A delivery answers what the session asked. An approval batch resolves once every request in it
|
|
68
|
+
* has a decision: approved calls become ready to run, denied ones get their denial as a result,
|
|
69
|
+
* and `once()` approvals grant their key. A message steers the held turn instead: the first
|
|
70
|
+
* pending batch resolves with the answers it has, and the rest are ignored. A session-limit
|
|
71
|
+
* answer grants or declines a fresh budget. A partial answer waits, queued, for the rest.
|
|
72
|
+
*/
|
|
73
|
+
export declare function answer(view: SessionView, input: {
|
|
74
|
+
readonly delivery: ResolvedStepInput | undefined;
|
|
75
|
+
readonly policy: ResponsePolicyPass;
|
|
76
|
+
/** The delivery merged the queue in, so the queue empties. */
|
|
77
|
+
readonly takeQueued: boolean;
|
|
78
|
+
readonly approvalKey: (request: InputRequest) => string | undefined;
|
|
79
|
+
}): Answered;
|
|
80
|
+
/** Queued input that can run now, rather than wait for more answers. */
|
|
81
|
+
export declare function hasRunnableQueue(view: SessionView): boolean;
|
|
82
|
+
/** Keys `once()` approvals granted, except those a pending approval still asks about. */
|
|
83
|
+
export declare function grantedApprovalKeys(view: SessionView, approvalKey: (request: InputRequest) => string | undefined): ReadonlySet<string>;
|
|
84
|
+
/**
|
|
85
|
+
* The steps a delivery approves calls of, whose tools the calls run with: those it answers in
|
|
86
|
+
* full, approving at least one call, or the only pending step a plain-text answer approves.
|
|
87
|
+
*/
|
|
88
|
+
export declare function approvingSteps(view: SessionView, stepInput: StepInput | undefined): readonly SuspendedStep[];
|
|
89
|
+
/** The suspended step that holds `requestId`. */
|
|
90
|
+
export declare function stepForRequest(view: SessionView, requestId: string): SuspendedStep | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* The held turn moves on, steered or cancelled: the sign-ins it waits on end, declined, including
|
|
93
|
+
* a responder's for one of its approvals.
|
|
94
|
+
*/
|
|
95
|
+
export declare function withdrawSignIns(view: SessionView, reason: string): Transition;
|
|
96
|
+
/**
|
|
97
|
+
* The session spent its budget: it asks whether to continue instead of calling the model, and
|
|
98
|
+
* the turn ends. The prompt is the projection's open request; `answer` grants a
|
|
99
|
+
* fresh budget or declines it.
|
|
100
|
+
*/
|
|
101
|
+
export declare function requestLimit(view: SessionView, input: {
|
|
102
|
+
readonly request: InputRequest;
|
|
103
|
+
}): Transition;
|
|
104
|
+
/**
|
|
105
|
+
* Work needs a sign-in. The calls that need it stop, settling `cancelled` until it completes;
|
|
106
|
+
* an attempt it replaces fails; and each sign-in is asked for and recorded. The turn holds until
|
|
107
|
+
* every sign-in calls back. Input that waited on a responder's sign-in stays queued for it. An
|
|
108
|
+
* approved call that needs the sign-in leaves its step, so the model calls it again once the
|
|
109
|
+
* sign-in completes.
|
|
110
|
+
*/
|
|
111
|
+
export declare function requireSignIn(view: SessionView, input: {
|
|
112
|
+
readonly challenges: readonly AuthorizationChallenge[];
|
|
113
|
+
readonly callIdsByName?: ReadonlyMap<string, readonly string[]>;
|
|
114
|
+
readonly queued?: StepInput;
|
|
115
|
+
}): Transition;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{canonicalize,compactInput,hasInput,isEmptyInput,resolveTextInput,withoutResponses,withoutTurnInput}from"./delivery.js";import{openInputs,turnCoordinates}from"#protocol/session-projection.js";import{readClientContext}from"#internal/client-context.js";import{createActionResultEvent,createApprovalCandidateEvent,createApprovalSettledEvent,createAuthorizationCompletedEvent,createAuthorizationRequiredEvent,createInputRequestedEvent,createInputResolvedEvent,createMessageCompletedEvent}from"#protocol/message.js";import{coalesceTurnInputs,createFrameworkUserMessage}from"#harness/messages.js";import{turnPosition}from"#harness/session-machine/view.js";import{renderPendingApprovalsSnippet}from"#harness/hitl/approval-prompt.js";import{finishTurn,hold,ownOpenRequestIds,settle,stepCallIds,suspend,withResult,withoutApproved}from"#harness/session-machine/transitions.js";import{supersededChallenges,withSignIns}from"#harness/authorization.js";import{withoutCalls}from"#harness/inline-tool-authorization.js";import{isApprovalRequest}from"#harness/input-request-class.js";import{authorizationEventFields}from"#harness/authorization-event-fields.js";import{TOOL_EXECUTION_DENIED_MESSAGE,resolveApprovalOutcome,resolveInputOutcome}from"#harness/input-request-resolution.js";import{resolveSessionLimitContinuation}from"#harness/hitl/budget-request.js";import{signInWithdrawn}from"#harness/session-machine/events.js";function parkOnApprovals(e,t){let n=t.requester?.principalType===`anonymous`?null:t.requester,r=t.messages.findIndex(e=>e.role!==`tool`),i=r===-1?t.messages:t.messages.slice(0,r),a=renderPendingApprovalsSnippet(t.requests),o=suspend(e.turn,{event:t.event,messages:t.messages.slice(i.length),requester:n,requests:t.requests,responseAuthRequiredRequestIds:t.responseAuthRequiredRequestIds,tasks:t.tasks});return{commit:[...i,...a===void 0?[]:[createFrameworkUserMessage(`context.state`,a)]],events:[createInputRequestedEvent({requests:t.requests,...t.event})],turn:o}}function dispatch(e,t){let n=e.turn.suspended.map(e=>{let n=stepCallIds(e),r=t.tasks.filter(e=>n.has(e.callId));if(r.length===0)return e;let i=withoutApproved(e,new Set(r.map(e=>e.callId))),a={...e.approvers};for(let{callId:e}of r){let n=t.approvers[e];n!==void 0&&(a[e]=n)}return{...i,tasks:[...e.tasks,...r],...Object.keys(a).length>0&&{approvers:a}}});return{events:[],turn:{...e.turn,suspended:n}}}function deferInput(e,t){return{events:[],turn:withQueued(e.turn,t)}}function withQueued(e,t){return t===void 0||isEmptyInput(t)?e:{...e,queued:e.queued===void 0?t:coalesceTurnInputs(e.queued,t)}}function answer(e,t){let{policy:n}=t,{projection:r}=e,i=turnPosition(r),a=[...n.feedback.map(e=>createMessageCompletedEvent({message:e,sequence:i.sequence,stepIndex:i.stepIndex,turnId:i.turnId})),...reportApprovalProgress(r,n.audit,n.challengesAtStart)],o=t.takeQueued?{...e.turn,queued:void 0}:e.turn,done=e=>({events:a,resolved:[],turn:o,...e}),queue=e=>{o=withQueued(o,e)};if(n.kind===`park`)return done({next:`park`});if(n.kind===`continue-coordination`)return queue(n.stepInput),done({next:`repeat`});if(n.challenges.length>0)return done({next:`sign-in`});let s=t.delivery,c=openInputs(r).find(t=>t.request.kind===`session-limit`&&ownOpenRequestIds(e).has(t.request.requestId)),l=o.suspended.filter(e=>e.requests.length>0);if(c===void 0&&l.length===0)return done({input:s,next:`continue`});let u=c===void 0?l.length===1?l[0]:void 0:{requests:[c.request]},d=u===void 0?s:resolveTextInput(u,s),f=canonicalize(d?.inputResponses??[]),p=new Map(f.map(e=>[e.requestId,e])),m=l.filter(e=>e.requests.every(e=>p.has(e.requestId))),leftoverFor=e=>f.filter(t=>e.some(e=>e.requests.some(e=>e.requestId===t.requestId))),park=()=>(queue(compactInput(d)),done({next:`park`}));if(f.length===0&&d?.message===void 0)return park();if(c!==void 0){let e=p.get(c.request.requestId);if(e===void 0)return hasInput(s)?(queue(withoutTurnInput(d)),done({input:d,next:`defer-message`})):(queue(compactInput(d)),done({next:`park`}));let t={event:{sequence:c.sequence,stepIndex:c.stepIndex,turnId:c.turnId},inputs:[{outcome:resolveInputOutcome(c.request.kind,e),request:c.request,response:e}]};a.push(resolvedEvent(t));let n=leftoverFor(l);return n.length>0&&queue({inputResponses:n}),done({consumedMessage:d?.messageConsumed,input:withoutResponses(d),limit:resolveSessionLimitContinuation({requests:[c.request],responses:f}),next:`continue`,resolved:[t]})}if(m.length===0&&d?.message===void 0)return park();m.length===0&&m.push(l[0]);let h=leftoverFor(l.filter(e=>!m.includes(e)));h.length>0&&queue({inputResponses:h});let g=new Set(o.grants),_=[],v=[],y=o.suspended.map(e=>{if(!m.includes(e))return e;let n=e.messages,r=[];for(let i of e.requests){let{approved:a,reason:o,status:s}=resolveApprovalOutcome(p.get(i.requestId));if(a){g.add(t.approvalKey(i)??i.action.toolName),r.push(i);continue}n=withResult(n,{output:{reason:o,type:`execution-denied`},toolCallId:i.action.callId,toolName:i.action.toolName,type:`tool-result`}),v.push(createActionResultEvent({rejected:!0,result:{callId:i.action.callId,isError:!0,kind:`tool-result`,output:{approval:{requestId:i.requestId,status:s},code:`TOOL_EXECUTION_DENIED`,message:o??TOOL_EXECUTION_DENIED_MESSAGE,tool:{result:`not_run`}},toolName:i.action.toolName},...e.event}))}_.push({event:e.event,inputs:e.requests.map(e=>{let t=p.get(e.requestId);return{outcome:resolveInputOutcome(e.kind,t),request:e,response:t}})});let i=[...e.approved??[],...r];return{...e,messages:n,requests:[],...i.length>0&&{approved:i}}});return a.push(..._.map(resolvedEvent),...v),o={...o,grants:[...g],suspended:y},done({consumedMessage:d?.messageConsumed,input:withoutResponses(d),next:`continue`,resolved:_})}function resolvedEvent(e){return createInputResolvedEvent({resolutions:e.inputs.map(e=>{let t={kind:e.request.kind,outcome:e.outcome,requestId:e.request.requestId};return e.response===void 0?t:{...t,response:e.response}}),...e.event})}function reportApprovalProgress(e,t,n){let r=turnCoordinates(e),isOpen=t=>{let n=e.inputs[t];return n!==void 0&&n.status!==`settled`},i=[];for(let a of n){let n=t.candidateHistory.some(e=>e.candidateId===a.candidateId&&e.status===`timed-out`),o=e.authorizations[a.attemptId??a.name];n&&o?.status===`required`&&i.push(createAuthorizationCompletedEvent({...authorizationEventFields(a),outcome:`failed`,reason:`The approval response expired. Please submit a new response.`,...r}))}for(let n of t.activeCandidates)e.candidates[n.candidateId]===void 0&&isOpen(n.requestId)&&i.push(createApprovalCandidateEvent({candidateId:n.candidateId,outcome:`pending`,requestId:n.requestId,responderPrincipalId:n.responder.principalId,...r}));for(let n of t.candidateHistory)n.status!==`allowed`&&n.status!==`authorization-required`&&e.inputs[n.requestId]!==void 0&&e.candidates[n.candidateId]?.outcome!==n.status&&i.push(createApprovalCandidateEvent({candidateId:n.candidateId,outcome:n.status,requestId:n.requestId,responderPrincipalId:n.responder.principalId,reason:n.reason,...r}));for(let e of t.settlements)isOpen(e.requestId)&&i.push(createApprovalSettledEvent({outcome:e.outcome===`allowed`?`approved`:`cancelled`,requestId:e.requestId,responderPrincipalId:e.actor.principalId,...r}));return i}function hasRunnableQueue(e){let t=e.turn.queued;if(t===void 0)return!1;if(t.message!==void 0||(t.context?.length??0)>0||readClientContext(t)!==void 0||t.outputSchema!==void 0||(t.runtimeActionResults?.length??0)>0)return!0;let n=[...t.inputResponses??[],...(t.attributedInputResponses??[]).map(({response:e})=>e)];if(n.length===0)return!1;let r=new Set(n.map(e=>e.requestId)),i=openInputs(e.projection).find(e=>e.request.kind===`session-limit`);return i===void 0?e.turn.suspended.some(e=>e.requests.length>0&&e.requests.every(e=>r.has(e.requestId))):r.has(i.request.requestId)}function grantedApprovalKeys(e,t){let n=new Set(e.turn.grants);for(let r of e.turn.suspended)for(let e of r.requests)isApprovalRequest(e)&&n.delete(t(e)??e.action.toolName);return n}function approvingSteps(e,t){let n=e.turn.suspended.filter(e=>e.requests.length>0),r=n.length===1?resolveTextInput(n[0],t):t,i=new Map((r?.inputResponses??[]).map(e=>[e.requestId,e.optionId]));return n.filter(e=>e.requests.every(e=>i.has(e.requestId))&&e.requests.some(e=>isApprovalRequest(e)&&i.get(e.requestId)===`approve`))}function stepForRequest(e,t){return e.turn.suspended.find(e=>e.requests.some(e=>e.requestId===t))}function withdrawSignIns(e,t){return{events:e.signIns.flatMap(n=>{let r=e.projection.authorizations[n.attemptId??n.name];return r?.status===`required`?[signInWithdrawn(r,t)]:[]}),signIns:[],turn:e.turn}}function requestLimit(e,t){let n=turnPosition(e.projection);return{events:[createInputRequestedEvent({requests:[t.request],sequence:n.sequence,stepIndex:n.stepIndex,turnId:n.turnId}),...finishTurn(e).events],turn:e.turn}}function requireSignIn(e,t){let n=turnPosition(e.projection),r={sequence:n.sequence,stepIndex:n.stepIndex,turnId:n.turnId},i=[...supersededChallenges(e.signIns,t.challenges).map(e=>createAuthorizationCompletedEvent({...authorizationEventFields(e),outcome:`failed`,reason:`Superseded by a newer authorization attempt.`,...r})),...t.challenges.map(e=>createAuthorizationRequiredEvent({...authorizationEventFields(e),description:e.challenge.instructions??`Authorization required for ${e.name}`,webhookUrl:e.hookUrl,...r}))];i.push(...hold(e,{on:`input`}).events);let a=t.queued===void 0?e.turn.queued:e.turn.queued===void 0?t.queued:coalesceTurnInputs(e.turn.queued,t.queued),o=withSignIns(e.signIns,t.challenges),s=new Set([...t.callIdsByName?.values()??[]].flat()),c=e.turn.suspended.map(e=>[...stepCallIds(e)].some(e=>s.has(e))?{...e,messages:withoutCalls(e.messages,s)}:e);if(c.every((t,n)=>t===e.turn.suspended[n]))return{events:i,signIns:o,turn:{...e.turn,queued:a}};let l=settle({...e,turn:{...e.turn,queued:a,suspended:c}},{results:[]});return{commit:l.commit,events:i,signIns:o,turn:l.turn}}export{answer,approvingSteps,deferInput,dispatch,grantedApprovalKeys,hasRunnableQueue,parkOnApprovals,requestLimit,requireSignIn,stepForRequest,withdrawSignIns};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SessionAuthContext } from "#channel/types.js";
|
|
2
|
+
import type { InputRequest } from "#shared/input.js";
|
|
3
|
+
import type { SessionStateMap } from "#harness/types.js";
|
|
4
|
+
/** Who approved each of the `approved` calls, by call id. */
|
|
5
|
+
export declare function approversOf(approved: readonly InputRequest[], state: SessionStateMap | undefined): Readonly<Record<string, SessionAuthContext>>;
|
|
6
|
+
/**
|
|
7
|
+
* Records who approved each of the `approved` calls, so each runs as its approver while the rest
|
|
8
|
+
* of the turn keeps the turn's own caller.
|
|
9
|
+
*/
|
|
10
|
+
export declare function setApprovedCallCallers(approved: readonly InputRequest[], state: SessionStateMap | undefined): void;
|
|
11
|
+
/** Runs `fn` as the call's approver when `callId` is an approved call; otherwise as is. */
|
|
12
|
+
export declare function runAsApprover<T>(callId: string | undefined, fn: () => T): T;
|
|
13
|
+
/** A streaming call's body runs on each `next()`, so each one runs as the approver too. */
|
|
14
|
+
export declare function iterateAsApprover<T>(callId: string | undefined, iterable: AsyncIterable<T>): AsyncIterable<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{approverOfRequest}from"./candidates.js";import{contextStorage}from"#context/container.js";import{ContextKey}from"#context/key.js";import{runAsCaller}from"#context/caller-scope.js";const ApprovedCallCallersKey=new ContextKey(`eve.approvedCallCallers`);function approversOf(e,t){let n={};for(let r of e){if(r.action===void 0)continue;let e=approverOfRequest(t,r.requestId);e!==void 0&&(n[r.action.callId]=e)}return n}function setApprovedCallCallers(e,t){let n=contextStorage.getStore();n!==void 0&&n.setVirtualContext(ApprovedCallCallersKey,new Map(Object.entries(approversOf(e,t))))}function runAsApprover(e,t){let n=e===void 0?void 0:contextStorage.getStore()?.get(ApprovedCallCallersKey)?.get(e);return n===void 0?t():runAsCaller(n,t)}async function*iterateAsApprover(e,t){let n=t[Symbol.asyncIterator]();try{for(;;){let t=await runAsApprover(e,()=>n.next());if(t.done===!0)return;yield t.value}}finally{await n.return?.()}}export{approversOf,iterateAsApprover,runAsApprover,setApprovedCallCallers};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ModelMessage, type TelemetryOptions, type ToolSet, type TypedToolResult } from "ai";
|
|
2
|
+
import type { HarnessToolMap } from "#harness/types.js";
|
|
3
|
+
import type { InputRequest } from "#shared/input.js";
|
|
4
|
+
import type { HandleEventFn } from "#harness/types.js";
|
|
5
|
+
type ToolResponsePart = Extract<ModelMessage, {
|
|
6
|
+
role: "tool";
|
|
7
|
+
}>["content"][number];
|
|
8
|
+
export interface ApprovedCallResult {
|
|
9
|
+
readonly part: Extract<ToolResponsePart, {
|
|
10
|
+
type: "tool-result";
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Runs approved local calls before the model reads their results. Like the calls a model step
|
|
15
|
+
* runs inline, each streams its progress and result as it goes. The lifecycle owner places the
|
|
16
|
+
* results in the steps that made the calls.
|
|
17
|
+
*/
|
|
18
|
+
export declare function runApprovedCalls(input: {
|
|
19
|
+
readonly requests: readonly InputRequest[];
|
|
20
|
+
readonly tools: HarnessToolMap;
|
|
21
|
+
readonly approvedTools?: ReadonlySet<string>;
|
|
22
|
+
/** The conversation the tools read as `ctx.messages`. */
|
|
23
|
+
readonly messages: readonly ModelMessage[];
|
|
24
|
+
readonly position: {
|
|
25
|
+
readonly sequence: number;
|
|
26
|
+
readonly stepIndex: number;
|
|
27
|
+
readonly turnId: string;
|
|
28
|
+
};
|
|
29
|
+
readonly publish: HandleEventFn;
|
|
30
|
+
readonly abortSignal: AbortSignal | undefined;
|
|
31
|
+
/** The step attempt's telemetry, which hears each execution as the AI SDK reports it. */
|
|
32
|
+
readonly telemetry?: TelemetryOptions;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
readonly settled: readonly ApprovedCallResult[];
|
|
35
|
+
readonly toolResults: readonly TypedToolResult<ToolSet>[];
|
|
36
|
+
}>;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{asSchema}from"ai";import{createLogger,logError}from"#internal/logging.js";import{toError}from"#shared/errors.js";import{createActionPartialEvent,createActionResultEvent}from"#protocol/message.js";import{parseJsonObject}from"#shared/json.js";import{isAsyncIterable}from"#shared/async-iterable.js";import{throwIfTurnAborted}from"#harness/turn-cancellation.js";import{createRuntimeToolResultFromValue}from"#harness/action-result-helpers.js";import{emitNestedToolActions}from"#harness/nested-actions.js";import{projectDeltaPresentation,projectResultPresentation}from"#harness/tool-presentation.js";import{isInlineAuthorizationToolResult}from"#harness/inline-tool-authorization.js";import{TOOL_EXECUTION_DENIED_MESSAGE}from"#harness/input-request-resolution.js";import{buildToolSet,recheckApprovedCall}from"#harness/tools.js";const log=createLogger(`harness.tool-loop`);async function runApprovedCalls(e){let t=buildToolSet({tools:e.tools,approvedTools:e.approvedTools}),n=e.requests.map(n=>{let r=e.tools.get(n.action.toolName),i=t[n.action.toolName];if(r?.execute===void 0||i?.execute===void 0||i.toModelOutput===void 0)throw Error(`The approved tool is no longer available. Request a new tool call and approval.`);return{request:n,definition:r,tool:i}}),r={sequence:e.position.sequence,stepIndex:e.position.stepIndex,turnId:e.position.turnId},i=await Promise.allSettled(n.map(async({request:t,definition:n,tool:i})=>{let a=[],o=[],{callId:s,toolName:c,input:l}=t.action;try{if(throwIfTurnAborted(e.abortSignal),(await asSchema(i.inputSchema).validate?.(l))?.success===!1){let t=`The approved input is no longer valid for tool "${c}". Request a new tool call and approval.`;return await e.publish(createActionResultEvent({...r,result:createRuntimeToolResultFromValue({callId:s,isError:!0,output:t,toolName:c})})),{settled:[{part:{type:`tool-result`,toolCallId:s,toolName:c,output:{type:`error-text`,value:t}}}],toolResults:o}}let t=await recheckApprovedCall(n,{abortSignal:e.abortSignal,callId:s,input:l,approvedTools:e.approvedTools});if(t.denied)return await e.publish(createActionResultEvent({...r,rejected:!0,result:{callId:s,isError:!0,kind:`tool-result`,output:{code:`TOOL_EXECUTION_DENIED`,message:t.reason??TOOL_EXECUTION_DENIED_MESSAGE,tool:{result:`not_run`}},toolName:c}})),a.push({part:{output:{reason:t.reason,type:`execution-denied`},toolCallId:s,toolName:c,type:`tool-result`}}),{settled:a,toolResults:o};let u,d=!1,f=toolTelemetry(e.telemetry,{messages:[...e.messages],toolCall:{input:l,toolCallId:s,toolName:c,type:`tool-call`}});await f.started();let p=0;try{await f.execute(async()=>{let t=performance.now();try{let t=i.execute(l,{abortSignal:e.abortSignal,context:void 0,messages:[...e.messages],toolCallId:s});if(isAsyncIterable(t))for await(let i of t)u=i,await e.publish(createActionPartialEvent({...r,presentation:projectDeltaPresentation(n,s,parseJsonObject(l),i),result:createRuntimeToolResultFromValue({callId:s,output:i,toolName:c})}));else u=await t}finally{p=performance.now()-t}})}catch(t){await f.ended({error:t,input:l,toolCallId:s,toolName:c,type:`tool-error`},p),throwIfTurnAborted(e.abortSignal),logError(log,`tool execution failed`,t,{toolName:c,toolCallId:s}),d=!0,u=toError(t).message}d||await f.ended({input:l,output:u,toolCallId:s,toolName:c,type:`tool-result`},p);let m={input:l,output:u,toolCallId:s,toolName:c,type:`tool-result`};return o.push(m),isInlineAuthorizationToolResult(m)?{settled:a,toolResults:o}:(await emitNestedToolActions(e.publish,e.position,s),a.push({part:{output:d?{type:`error-text`,value:String(u)}:await i.toModelOutput({input:l,output:u,toolCallId:s}),toolCallId:s,toolName:c,type:`tool-result`}}),await e.publish(createActionResultEvent({...r,presentation:d?void 0:projectResultPresentation(n,s,parseJsonObject(l),u),result:createRuntimeToolResultFromValue({callId:s,isError:d,output:u,toolName:c})})),{settled:a,toolResults:o})}catch(t){throwIfTurnAborted(e.abortSignal);let n=toError(t).message;return logError(log,`approved tool failed`,t,{toolName:c,toolCallId:s}),await e.publish(createActionResultEvent({...r,result:createRuntimeToolResultFromValue({callId:s,isError:!0,output:n,toolName:c})})),{settled:[{part:{type:`tool-result`,toolCallId:s,toolName:c,output:{type:`error-text`,value:n}}}],toolResults:o}}})),a=i.find(e=>e.status===`rejected`);if(a?.status===`rejected`)throw a.reason;let o=i.flatMap(e=>e.status===`fulfilled`?[e.value]:[]);return{settled:o.flatMap(e=>e.settled),toolResults:o.flatMap(e=>e.toolResults)}}function toolTelemetry(e,t){let n=e===void 0||e.isEnabled===!1?[]:[e.integrations??[]].flat(),r={...t,callId:`approved:${t.toolCall.toolCallId}`,functionId:e?.functionId,recordInputs:e?.recordInputs,recordOutputs:e?.recordOutputs,toolContext:void 0},notify=async e=>{await Promise.allSettled(n.map(async t=>await e(t)))};return{started:()=>notify(e=>e.onToolExecutionStart?.(r)),execute:async e=>{let wrapped=e;for(let e of n){if(e.executeTool===void 0)continue;let n=wrapped;wrapped=()=>e.executeTool({...r,execute:n,toolCallId:t.toolCall.toolCallId})}await wrapped()},ended:(e,t)=>notify(n=>n.onToolExecutionEnd?.({...r,toolExecutionMs:t,toolOutput:e}))}}export{runApprovedCalls};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* When a durable session reaches its configured token or token-cost budget, the harness
|
|
5
5
|
* parks on a harness-authored input request instead of failing the session.
|
|
6
|
-
* The request is derived only from the session
|
|
6
|
+
* The request is derived only from the session, turn, and violation, so
|
|
7
7
|
* identical session state always produces an identical prompt — no model call
|
|
8
8
|
* is involved.
|
|
9
9
|
*/
|
|
@@ -17,6 +17,8 @@ export declare const SESSION_LIMIT_STOP_OPTION_ID = "stop";
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function createSessionLimitContinuationRequest(input: {
|
|
19
19
|
readonly sessionId: string;
|
|
20
|
+
/** The turn's `sequence`, which tells its prompt apart from another turn's at the same usage. */
|
|
21
|
+
readonly turnSequence: number;
|
|
20
22
|
readonly violation: SessionUsageLimitViolation;
|
|
21
23
|
}): InputRequest;
|
|
22
24
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const SESSION_LIMIT_CONTINUE_OPTION_ID=`continue`,SESSION_LIMIT_STOP_OPTION_ID=`stop`;function createSessionLimitContinuationRequest(e){let{sessionId:t,turnSequence:n,violation:r}=e,i=r.kind===`token-cost`?r.usedCostUsd:r.usedTokens,a=`${t}:${String(n)}:limit:${r.kind}:${String(i)}`;return{action:{callId:a,input:r.kind===`token-cost`?{kind:r.kind,limitUsd:r.limitUsd,usedCostUsd:r.usedCostUsd}:{kind:r.kind,limit:r.limit,usedTokens:r.usedTokens},kind:`tool-call`,toolName:`session_limit_continuation`},allowFreeform:!1,display:`confirmation`,kind:`session-limit`,options:[{description:r.kind===`token-cost`?`Grant a fresh model token-cost budget`:`Grant a fresh token budget`,id:SESSION_LIMIT_CONTINUE_OPTION_ID,label:`Approve`,style:`primary`},{description:`Stop now`,id:SESSION_LIMIT_STOP_OPTION_ID,label:`Stop`,style:`danger`}],prompt:formatSessionLimitPrompt(r),requestId:a}}function formatCompactTokenCount(e){return e>=1e6?`${trimTrailingZero(e/1e6)}M`:e>=1e3?`${trimTrailingZero(e/1e3)}K`:String(e)}function trimTrailingZero(e){let t=e.toFixed(1);return t.endsWith(`.0`)?t.slice(0,-2):t}function formatSessionLimitPrompt(e){return`This session has hit the ${e.kind===`token-cost`?`${formatUsd(e.limitUsd)} model token-cost limit per session`:`${e.kind}-token limit (${formatCompactTokenCount(e.limit)}) per session`}. This is a guardrail against defective long-running sessions. If session activity looks fine, just approve to keep going.`}function formatUsd(e){return`$${(e<1e-6?String(e):e.toFixed(6)).replace(/0+$/u,``).replace(/\.$/u,``)}`}function isSessionLimitContinuationRequest(e){return e.kind===`session-limit`}function isSessionLimitContinuationRequestId(e){return/:limit:(?:input|output):\d+$/u.test(e)||/:limit:token-cost:\d+(?:\.\d+)?(?:e[+-]?\d+)?$/iu.test(e)}function resolveSessionLimitContinuation(e){let t=e.requests.find(isSessionLimitContinuationRequest);if(t===void 0)return;let n=e.responses.find(e=>e.requestId===t.requestId);if(n!==void 0){if(n.optionId===SESSION_LIMIT_CONTINUE_OPTION_ID)return{granted:!0};if(n.optionId===`stop`)return{granted:!1}}}export{SESSION_LIMIT_STOP_OPTION_ID,createSessionLimitContinuationRequest,isSessionLimitContinuationRequest,isSessionLimitContinuationRequestId,resolveSessionLimitContinuation};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HarnessSession } from "#harness/types.js";
|
|
2
|
+
import type { InputRequest } from "#shared/input.js";
|
|
3
|
+
import type { JsonObject } from "#shared/json.js";
|
|
4
|
+
export { bumpSessionRuntimeUsageLimits } from "#harness/turn-tag-state.js";
|
|
5
|
+
export type SessionUsageLimitCheck = {
|
|
6
|
+
readonly kind: "within";
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: "ask";
|
|
9
|
+
readonly request: InputRequest;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: "fail";
|
|
12
|
+
readonly code: string;
|
|
13
|
+
readonly details: JsonObject;
|
|
14
|
+
readonly message: string;
|
|
15
|
+
};
|
|
16
|
+
/** Whether the session may call the model, may ask to continue, or must fail. */
|
|
17
|
+
export declare function checkSessionUsageLimit(input: {
|
|
18
|
+
readonly canAsk: boolean;
|
|
19
|
+
readonly session: HarnessSession;
|
|
20
|
+
readonly turnSequence: number;
|
|
21
|
+
}): SessionUsageLimitCheck;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{bumpSessionRuntimeUsageLimits,getSessionTokenUsage,getSessionUsageLimitViolation}from"#harness/turn-tag-state.js";import{createSessionLimitContinuationRequest}from"#harness/hitl/budget-request.js";function checkSessionUsageLimit(e){let t=getSessionUsageLimitViolation(e.session);if(t===null)return{kind:`within`};if(violationWindow(t)>0&&e.canAsk)return{kind:`ask`,request:createSessionLimitContinuationRequest({sessionId:e.session.sessionId,turnSequence:e.turnSequence,violation:t})};let n=getSessionTokenUsage(e.session);return{code:t.kind===`token-cost`?`SESSION_TOKEN_COST_LIMIT_REACHED`:`SESSION_TOKEN_LIMIT_REACHED`,details:t.kind===`token-cost`?{costUsd:n.costUsd,kind:t.kind,limitUsd:t.limitUsd,usedCostUsd:t.usedCostUsd}:{inputTokens:n.inputTokens,kind:t.kind,limit:t.limit,outputTokens:n.outputTokens,usedTokens:t.usedTokens},kind:`fail`,message:formatSessionLimitMessage(t.kind)}}function violationWindow(e){return e.kind===`token-cost`?e.limitUsd:e.limit}function formatSessionLimitMessage(e){return e===`token-cost`?`The session reached its configured model token-cost limit.`:`The session reached its configured ${e} token limit.`}export{bumpSessionRuntimeUsageLimits,checkSessionUsageLimit};
|