eve 0.74.0 → 0.75.1
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 +34 -0
- package/dist/src/channel/auth/result.d.ts +4 -0
- package/dist/src/channel/auth/result.js +1 -0
- package/dist/src/channel/types.d.ts +14 -2
- package/dist/src/chunks/{use-eve-agent-mP0M7SrL.js → use-eve-agent-B2Kne9z6.js} +7 -2
- package/dist/src/chunks/{use-eve-agent-DOOXadF0.js → use-eve-agent-DK_T88EP.js} +7 -2
- package/dist/src/cli/commands/deploy.js +1 -1
- package/dist/src/cli/commands/integration-connect.d.ts +2 -0
- package/dist/src/cli/commands/integration-connect.js +1 -1
- package/dist/src/cli/commands/integration-setup.js +1 -1
- package/dist/src/cli/commands/link.d.ts +2 -1
- package/dist/src/cli/commands/link.js +1 -1
- package/dist/src/cli/commands/registry-declared-setups.d.ts +19 -0
- package/dist/src/cli/commands/registry-declared-setups.js +1 -1
- package/dist/src/cli/commands/registry-recovery.d.ts +3 -1
- package/dist/src/cli/commands/registry-recovery.js +1 -1
- package/dist/src/cli/commands/registry.d.ts +12 -4
- package/dist/src/cli/commands/registry.js +1 -1
- package/dist/src/cli/commands/vercel-non-interactive.d.ts +6 -4
- package/dist/src/cli/commands/vercel-non-interactive.js +1 -1
- package/dist/src/cli/dev/tui/registry-result-message.js +1 -1
- package/dist/src/cli/dev/tui/setup-commands.d.ts +2 -0
- package/dist/src/cli/dev/tui/setup-commands.js +2 -2
- package/dist/src/client/index.d.ts +1 -0
- package/dist/src/client/session.d.ts +1 -1
- package/dist/src/client/session.js +1 -1
- package/dist/src/client/sessions.d.ts +1 -1
- package/dist/src/client/types.d.ts +6 -0
- package/dist/src/compiled/.vendor-stamp.json +8 -8
- package/dist/src/compiled/@eve/catalog/index.js +1 -1
- package/dist/src/compiled/@workflow/core/global.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/index.js +1 -1
- package/dist/src/compiled/@workflow/core/private.d.ts +11 -0
- package/dist/src/compiled/@workflow/core/private.js +1 -1
- package/dist/src/compiled/@workflow/core/runtime/constants.d.ts +36 -8
- package/dist/src/compiled/@workflow/core/runtime/helpers.js +1 -1
- package/dist/src/compiled/@workflow/core/runtime/lifecycle-hooks.d.ts +10 -6
- package/dist/src/compiled/@workflow/core/runtime/out-of-band-observation.d.ts +159 -0
- package/dist/src/compiled/@workflow/core/runtime/vm-mode.d.ts +28 -4
- package/dist/src/compiled/@workflow/core/runtime.js +4 -4
- package/dist/src/compiled/@workflow/core/serialization.js +1 -1
- package/dist/src/compiled/@workflow/core/version.d.ts +1 -1
- package/dist/src/compiled/@workflow/core/workflow.js +1 -1
- package/dist/src/compiled/@workflow/world-local/index.js +5 -5
- package/dist/src/compiled/@workflow/world-vercel/index.js +4 -4
- package/dist/src/compiled/_chunks/workflow/{attribute-changes-CSqvJx6j.js → attribute-changes-BW-kbMMn.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/dist-CyBgVS7g.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{helpers-BXCuoPUb.js → helpers-DlLD3ov_.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/private-tQUuwBoQ.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{resume-hook-CvENCrxc.js → resume-hook-DMsV_b4n.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{run-8pLWuR2U.js → run-DzdAqdb1.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{serialization-vDozzDhh.js → serialization-DPdYS_w2.js} +2 -2
- package/dist/src/compiled/_chunks/workflow/sleep-BY6leHh8.js +1 -0
- package/dist/src/compiled/_chunks/workflow/{token-BKeK6DmC.js → token-D5ugC3PI.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/{token-util-CddTZ_ef.js → token-util-Bla5Z0G9.js} +1 -1
- package/dist/src/compiled/_chunks/workflow/undici-D-ILjOKD.js +95 -0
- package/dist/src/compiled/_chunks/workflow/{wait-until-A344L2AG.js → wait-until-xbRRDuUf.js} +1 -1
- package/dist/src/compiler/extension-compatibility.d.ts +18 -12
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/context/dynamic-connection-lifecycle.d.ts +6 -0
- package/dist/src/context/dynamic-connection-lifecycle.js +1 -1
- package/dist/src/context/keys.d.ts +4 -1
- package/dist/src/context/keys.js +1 -1
- package/dist/src/context/providers/sandbox.js +1 -1
- package/dist/src/context/providers/tool-stubs-key.d.ts +8 -0
- package/dist/src/context/providers/tool-stubs-key.js +1 -0
- package/dist/src/context/providers/tool-stubs.d.ts +10 -0
- package/dist/src/context/providers/tool-stubs.js +1 -0
- package/dist/src/context/run-step.js +1 -1
- package/dist/src/evals/index.d.ts +1 -0
- package/dist/src/evals/runner/execute-task.js +1 -1
- package/dist/src/evals/session-manager.d.ts +2 -0
- package/dist/src/evals/session-manager.js +1 -1
- package/dist/src/eve-channel/create-request.d.ts +2 -0
- package/dist/src/eve-channel/index.js +1 -1
- package/dist/src/eve-channel/request.js +1 -1
- package/dist/src/execution/agent-sessions/context.d.ts +2 -0
- package/dist/src/execution/agent-sessions/context.js +1 -1
- package/dist/src/execution/agent-sessions/steps.js +1 -1
- package/dist/src/execution/cancelled-model-call-batch.js +1 -1
- package/dist/src/execution/dynamic-connection-recovery.d.ts +14 -0
- package/dist/src/execution/dynamic-connection-recovery.js +1 -0
- package/dist/src/execution/dynamic-workflow/tool.js +1 -1
- package/dist/src/execution/forward-session-input.js +1 -1
- package/dist/src/execution/legacy-session/authorization.js +1 -1
- package/dist/src/execution/legacy-session/completion-step.js +1 -1
- package/dist/src/execution/legacy-session/inbox.js +1 -1
- package/dist/src/execution/legacy-session/interrupt-step.js +1 -1
- package/dist/src/execution/ndjson-stream.d.ts +6 -6
- package/dist/src/execution/ndjson-stream.js +3 -3
- package/dist/src/execution/proxied-deliver-step.js +1 -1
- package/dist/src/execution/runtime-context.js +1 -1
- package/dist/src/execution/sandbox/bindings/docker.js +1 -1
- package/dist/src/execution/sandbox/bindings/just-bash-runtime.js +1 -1
- package/dist/src/execution/sandbox/bindings/just-bash.js +1 -1
- package/dist/src/execution/sandbox/bindings/microsandbox-lifecycle.js +1 -1
- package/dist/src/execution/sandbox/bindings/vercel.js +1 -1
- package/dist/src/execution/sandbox/ensure.d.ts +3 -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/admission.js +1 -1
- package/dist/src/execution/session/checkpoint-migrations.js +1 -1
- package/dist/src/execution/session/end-sandbox-step.d.ts +12 -0
- package/dist/src/execution/session/end-sandbox-step.js +1 -0
- package/dist/src/execution/session/finalization.js +1 -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/program.js +1 -1
- package/dist/src/execution/session/timeout-steps.js +1 -1
- package/dist/src/execution/session/turn-step.js +1 -1
- package/dist/src/execution/session-inbox/inbox.d.ts +6 -1
- package/dist/src/execution/session-inbox/inbox.js +1 -1
- package/dist/src/execution/session-inbox/release-step.js +1 -1
- package/dist/src/execution/session-inbox/resume.d.ts +2 -1
- package/dist/src/execution/session-inbox/resume.js +1 -1
- package/dist/src/execution/session-workflow-tool-run.js +1 -1
- package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
- package/dist/src/execution/tasks/model-step.js +1 -1
- package/dist/src/execution/tasks/steps.js +1 -1
- package/dist/src/execution/tasks/table.d.ts +7 -1
- package/dist/src/execution/tasks/table.js +1 -1
- package/dist/src/execution/tool-stubs/playback.d.ts +11 -0
- package/dist/src/execution/tool-stubs/playback.js +1 -0
- package/dist/src/execution/tool-stubs/steps.d.ts +18 -0
- package/dist/src/execution/tool-stubs/steps.js +1 -0
- package/dist/src/execution/tools/agent-router-workflow.js +1 -1
- package/dist/src/execution/tools/connection-tools.d.ts +0 -6
- package/dist/src/execution/tools/connection-tools.js +2 -2
- package/dist/src/execution/tools/workflow/authorization-completion.js +1 -1
- package/dist/src/execution/tools/workflow/body.js +1 -1
- package/dist/src/execution/tools/workflow/serve.js +1 -1
- 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-webhook-route.js +1 -1
- package/dist/src/harness/compaction/engine.d.ts +8 -19
- package/dist/src/harness/compaction/engine.js +1 -1
- package/dist/src/harness/compaction/step.d.ts +7 -1
- package/dist/src/harness/compaction/step.js +1 -1
- package/dist/src/harness/coordination.js +1 -1
- package/dist/src/harness/emission.js +1 -1
- package/dist/src/harness/hitl/approved-calls.d.ts +2 -0
- package/dist/src/harness/hitl/approved-calls.js +1 -1
- package/dist/src/harness/hitl/index.d.ts +9 -1
- package/dist/src/harness/hitl/index.js +1 -1
- package/dist/src/harness/hitl/intake.js +1 -1
- package/dist/src/harness/model-call/call.d.ts +2 -3
- package/dist/src/harness/model-call/call.js +1 -1
- package/dist/src/harness/model-call/model.d.ts +4 -5
- package/dist/src/harness/model-call/model.js +1 -1
- package/dist/src/harness/model-call/request.d.ts +1 -2
- package/dist/src/harness/model-call/request.js +1 -1
- package/dist/src/harness/model-call/retry.d.ts +1 -1
- package/dist/src/harness/model-call/retry.js +1 -1
- package/dist/src/harness/model-call/run.js +1 -1
- package/dist/src/harness/model-call/tools.d.ts +3 -4
- package/dist/src/harness/model-call/tools.js +1 -1
- package/dist/src/harness/model-call/usage.js +1 -1
- package/dist/src/harness/model-profile.d.ts +23 -0
- package/dist/src/harness/model-profile.js +1 -0
- package/dist/src/harness/prompt-cache.d.ts +5 -53
- package/dist/src/harness/prompt-cache.js +1 -1
- package/dist/src/harness/provider-safety.d.ts +3 -5
- package/dist/src/harness/provider-safety.js +1 -1
- package/dist/src/harness/provider-tools.d.ts +5 -13
- package/dist/src/harness/provider-tools.js +1 -1
- package/dist/src/harness/proxy-input-requests.d.ts +17 -6
- package/dist/src/harness/proxy-input-requests.js +1 -1
- package/dist/src/harness/session-machine/current.d.ts +4 -0
- package/dist/src/harness/session-machine/current.js +1 -1
- package/dist/src/harness/step/after-model.js +1 -1
- package/dist/src/harness/step/context.d.ts +7 -2
- package/dist/src/harness/step/context.js +1 -1
- package/dist/src/harness/step-hooks.d.ts +2 -3
- package/dist/src/harness/step-hooks.js +1 -1
- package/dist/src/harness/tool-call-io.js +1 -1
- package/dist/src/harness/tool-loop.js +1 -1
- package/dist/src/harness/tools.d.ts +2 -3
- package/dist/src/harness/tools.js +1 -1
- package/dist/src/harness/turn-tag-state.d.ts +12 -0
- package/dist/src/harness/turn-tag-state.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/gateway.d.ts +0 -13
- package/dist/src/internal/gateway.js +1 -1
- package/dist/src/internal/invocation/workflow-execution.js +1 -1
- package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
- package/dist/src/internal/workflow/cancel-expired-development-run.js +1 -1
- package/dist/src/protocol/routes.d.ts +4 -0
- package/dist/src/protocol/routes.js +1 -1
- package/dist/src/public/channels/auth.d.ts +21 -4
- package/dist/src/public/channels/auth.js +1 -1
- package/dist/src/public/channels/mcp.js +1 -1
- package/dist/src/public/schedules/providers/in-memory.js +1 -1
- package/dist/src/public/schedules/providers/vercel.js +1 -1
- package/dist/src/public/schedules/subscription.d.ts +0 -1
- package/dist/src/sandbox/state.d.ts +1 -0
- package/dist/src/self-modification/extension/subagents/agent/instructions.js +1 -1
- package/dist/src/self-modification/extension/subagents/agent/tools/registry_add.js +1 -1
- package/dist/src/setup/flows/registry-session.d.ts +10 -2
- package/dist/src/setup/flows/registry-session.js +1 -1
- package/dist/src/setup/flows/registry.d.ts +2 -0
- package/dist/src/setup/flows/registry.js +1 -1
- package/dist/src/setup/integrations/shared/prerequisite.d.ts +8 -0
- package/dist/src/setup/integrations/shared/prerequisite.js +1 -1
- package/dist/src/setup/registry-setup-client.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/setup/scaffold/create/web-template.d.ts +3 -2
- package/dist/src/setup/scaffold/create/web-template.js +383 -411
- package/dist/src/setup/scaffold/index.js +1 -1
- package/dist/src/setup/vercel-project.d.ts +2 -3
- package/dist/src/setup/vercel-project.js +0 -0
- package/dist/src/shared/sandbox-provider.d.ts +9 -2
- package/dist/src/subagents/adapter.d.ts +3 -2
- package/dist/src/subagents/adapter.js +1 -1
- package/dist/src/subagents/callback-route.js +1 -1
- package/dist/src/subagents/hitl-proxy.d.ts +4 -3
- package/dist/src/subagents/hitl-proxy.js +1 -1
- package/dist/src/subagents/parent-notification.js +1 -1
- package/dist/src/svelte/index.js +1 -1
- package/dist/src/svelte/use-eve-agent.js +1 -1
- package/dist/src/tool-stubs/execute.d.ts +13 -0
- package/dist/src/tool-stubs/execute.js +1 -0
- package/dist/src/tool-stubs/output.d.ts +4 -0
- package/dist/src/tool-stubs/output.js +1 -0
- package/dist/src/tool-stubs/playback.d.ts +15 -0
- package/dist/src/tool-stubs/playback.js +1 -0
- package/dist/src/tool-stubs/rules.d.ts +3 -0
- package/dist/src/tool-stubs/rules.js +1 -0
- package/dist/src/tool-stubs/schema.d.ts +4 -0
- package/dist/src/tool-stubs/schema.js +1 -0
- package/dist/src/tool-stubs/target.d.ts +8 -0
- package/dist/src/tool-stubs/target.js +1 -0
- package/dist/src/tool-stubs/types.d.ts +56 -0
- package/dist/src/tool-stubs/types.js +1 -0
- package/dist/src/tool-stubs/validate-targets.d.ts +6 -0
- package/dist/src/tool-stubs/validate-targets.js +1 -0
- package/dist/src/tools/provided/ask-question-workflow.js +1 -1
- package/dist/src/tools/provided/sleep-workflow.js +1 -1
- package/dist/src/vue/index.js +1 -1
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/concepts/sessions-runs-and-streaming.md +2 -2
- package/docs/evals/meta.json +10 -1
- package/docs/evals/overview.mdx +2 -0
- package/docs/evals/tool-stubs.mdx +257 -0
- package/docs/extensions.md +1 -1
- package/docs/guides/auth-and-route-protection.md +25 -0
- package/docs/guides/dynamic-capabilities.md +10 -3
- package/docs/guides/frontend/nextjs.mdx +17 -4
- package/docs/sandbox/index.mdx +10 -2
- package/docs/subagents/index.mdx +1 -1
- package/docs/tools/human-in-the-loop.md +1 -1
- package/docs/tools/overview.mdx +8 -4
- package/docs/tools/workflows.mdx +15 -7
- package/package.json +6 -6
- package/dist/src/compiled/_chunks/workflow/dist-DmXynLVH.js +0 -1
- package/dist/src/compiled/_chunks/workflow/private-Dlf90Zvn.js +0 -1
- package/dist/src/compiled/_chunks/workflow/signal-exit-iIdjQcCK.js +0 -95
- package/dist/src/compiled/_chunks/workflow/sleep-BMqbraZM.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{formatLanguageModelGatewayId}from"#internal/runtime-model.js";import{
|
|
1
|
+
import{formatLanguageModelGatewayId}from"#internal/runtime-model.js";import{addTurnUsage,getTurnUsageState}from"#harness/turn-tag-state.js";import{setEveAttributes}from"#runtime/attributes/emit.js";function gatewayModelId(e){try{return formatLanguageModelGatewayId(e)}catch{return}}function extractTokenUsageDelta(e){let t=e.usage;if(t!==void 0||e.costUsd!==void 0)return{cacheReadTokens:t?.inputTokenDetails?.cacheReadTokens,cacheWriteTokens:t?.inputTokenDetails?.cacheWriteTokens,costUsd:e.costUsd,inputTokens:t?.inputTokens,outputTokens:t?.outputTokens}}function extractGatewayCostUsd(e){let t=readGatewayMetadata(e)?.cost;if(typeof t==`number`&&Number.isFinite(t))return t;if(typeof t==`string`){let e=Number(t);return Number.isFinite(e)?e:void 0}}function readGatewayMetadata(e){let t=e?.gateway;return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}async function recordModelUsage(e,t){e.session=addTurnUsage(e.session,e.position().turnId,extractTokenUsageDelta({costUsd:extractGatewayCostUsd(t.result.providerMetadata),usage:t.result.usage}));let n=getTurnUsageState(e.session.state),r={"$eve.model":gatewayModelId(t.model),"$eve.input_tokens":n?.inputTokens,"$eve.output_tokens":n?.outputTokens,"$eve.cache_read_tokens":n?.cacheReadTokens,"$eve.cache_write_tokens":n?.cacheWriteTokens,"$eve.cost_usd":n?.sawCost?n.costUsd:void 0,"$eve.tool_count":e.config.tools.size};await e.config.titleAttributeWrite,await setEveAttributes(r)}export{extractGatewayCostUsd,extractTokenUsageDelta,gatewayModelId,recordModelUsage};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { LanguageModel } from "ai";
|
|
2
|
+
/**
|
|
3
|
+
* What eve assumes about the model serving one call. Every decision that shapes a request for
|
|
4
|
+
* its provider reads this record, so a step and its compaction agree about the model.
|
|
5
|
+
*/
|
|
6
|
+
export interface ModelProfile {
|
|
7
|
+
/** Routed through AI Gateway, which caches automatically and serves Gateway tools. */
|
|
8
|
+
readonly gateway: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Who serves the request: a Gateway id's vendor (`openai/gpt-5` → `openai`), which Gateway
|
|
11
|
+
* translates for whichever host it routes to, otherwise the SDK provider's top-level name
|
|
12
|
+
* (`anthropic`, `amazon-bedrock`, `vertex`, `azure`). It names the host, not the model family:
|
|
13
|
+
* hosts of the same family accept different things (Bedrock and Vertex reject Anthropic's web
|
|
14
|
+
* search tool), so a capability a host shares with its family gets its own flag, like
|
|
15
|
+
* `anthropicCache`.
|
|
16
|
+
*/
|
|
17
|
+
readonly provider: string;
|
|
18
|
+
/** Takes Anthropic prompt-cache breakpoints. */
|
|
19
|
+
readonly anthropicCache: boolean;
|
|
20
|
+
/** Chat Completions APIs can't carry files in tool results, so they move to user messages. */
|
|
21
|
+
readonly filesOutsideToolResults: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function resolveModelProfile(model: LanguageModel): ModelProfile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function resolveModelProfile(e){let t=typeof e==`string`?`gateway`:lowerCaseOrEmpty(e.provider),n=typeof e==`string`?e:lowerCaseOrEmpty(e.modelId),r=t.split(`.`)[0];return r===`gateway`?{anthropicCache:!1,filesOutsideToolResults:!1,gateway:!0,provider:n.split(`/`)[0]}:{anthropicCache:t.includes(`anthropic`)||t.includes(`bedrock`)&&n.includes(`anthropic`),filesOutsideToolResults:t.endsWith(`.chat`),gateway:!1,provider:r}}function lowerCaseOrEmpty(e){return typeof e==`string`?e.toLowerCase():``}export{resolveModelProfile};
|
|
@@ -1,52 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
* The caching strategy to apply for one harness step.
|
|
4
|
-
*/
|
|
5
|
-
export type PromptCachePath = {
|
|
6
|
-
readonly kind: "gateway-auto";
|
|
7
|
-
} | {
|
|
8
|
-
readonly kind: "anthropic-direct";
|
|
9
|
-
} | {
|
|
10
|
-
readonly kind: "none";
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Cache marker injected on the Anthropic-direct path.
|
|
14
|
-
*
|
|
15
|
-
* The marker carries two provider namespaces because Anthropic models are
|
|
16
|
-
* reachable through providers that read different provider-options keys:
|
|
17
|
-
*
|
|
18
|
-
* - `anthropic.cacheControl` — read by the AI SDK Anthropic provider and by
|
|
19
|
-
* `@ai-sdk/amazon-bedrock/anthropic` and `@ai-sdk/google-vertex/anthropic`,
|
|
20
|
-
* which implement the native Anthropic Messages API.
|
|
21
|
-
* - `bedrock.cachePoint` — read by the standard `@ai-sdk/amazon-bedrock`
|
|
22
|
-
* Converse provider, which does not understand `anthropic.cacheControl`.
|
|
23
|
-
*
|
|
24
|
-
* A provider ignores namespaces it does not own, so carrying both is safe on
|
|
25
|
-
* every Anthropic-direct request regardless of which provider serves it.
|
|
26
|
-
*/
|
|
27
|
-
export interface AnthropicCacheMarker {
|
|
28
|
-
readonly anthropic: {
|
|
29
|
-
readonly cacheControl: {
|
|
30
|
-
readonly type: "ephemeral";
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
readonly bedrock: {
|
|
34
|
-
readonly cachePoint: {
|
|
35
|
-
readonly type: "default";
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Detects which prompt caching path applies to a resolved model.
|
|
41
|
-
*
|
|
42
|
-
* Runs once per harness step right after `resolveModel()`.
|
|
43
|
-
*/
|
|
44
|
-
export declare function detectPromptCachePath(model: LanguageModel): PromptCachePath;
|
|
45
|
-
/**
|
|
46
|
-
* Returns the shared Anthropic cache marker used on the `anthropic-direct`
|
|
47
|
-
* path. Exposed for unit tests and for the harness wiring layer.
|
|
48
|
-
*/
|
|
49
|
-
export declare function getAnthropicCacheMarker(): AnthropicCacheMarker;
|
|
1
|
+
import type { ModelMessage, SystemModelMessage, ToolSet } from "ai";
|
|
50
2
|
/**
|
|
51
3
|
* Returns a new `providerOptions` object with
|
|
52
4
|
* `gateway.caching = "auto"` merged into the existing `gateway` sub-object.
|
|
@@ -60,14 +12,14 @@ export declare function getAnthropicCacheMarker(): AnthropicCacheMarker;
|
|
|
60
12
|
export declare function mergeGatewayAutoCaching(base: Readonly<Record<string, unknown>> | undefined): Record<string, unknown>;
|
|
61
13
|
/**
|
|
62
14
|
* Returns a new ToolSet where the last tool entry carries the Anthropic
|
|
63
|
-
* cache marker on `providerOptions`. Used
|
|
15
|
+
* cache marker on `providerOptions`. Used for Anthropic-cache models
|
|
64
16
|
* to place a stable breakpoint at the end of the tools block, caching the
|
|
65
17
|
* full tool definitions across every turn.
|
|
66
18
|
*
|
|
67
19
|
* No-op when `tools` has no entries. Preserves existing `providerOptions`
|
|
68
20
|
* on tools (merges the cache marker in via spread).
|
|
69
21
|
*/
|
|
70
|
-
export declare function applyLastToolCacheBreakpoint(tools: ToolSet
|
|
22
|
+
export declare function applyLastToolCacheBreakpoint(tools: ToolSet): ToolSet;
|
|
71
23
|
/**
|
|
72
24
|
* Marks the last system message in an instructions array with the Anthropic
|
|
73
25
|
* cache marker. This creates a cache breakpoint at the end of the system
|
|
@@ -77,7 +29,7 @@ export declare function applyLastToolCacheBreakpoint(tools: ToolSet, marker: Ant
|
|
|
77
29
|
* single-string system prompts don't support per-message providerOptions.
|
|
78
30
|
* No-op when the array is empty.
|
|
79
31
|
*/
|
|
80
|
-
export declare function applySystemCacheBreakpoint(instructions: readonly SystemModelMessage[]
|
|
32
|
+
export declare function applySystemCacheBreakpoint(instructions: readonly SystemModelMessage[]): SystemModelMessage[];
|
|
81
33
|
/**
|
|
82
34
|
* Attaches the Anthropic cache marker to the last message in `messages`
|
|
83
35
|
* (whatever its role) and, as a stable mid-history anchor, to the most
|
|
@@ -100,4 +52,4 @@ export declare function applySystemCacheBreakpoint(instructions: readonly System
|
|
|
100
52
|
* appends more content blocks than Anthropic's backward boundary scan
|
|
101
53
|
* covers.
|
|
102
54
|
*/
|
|
103
|
-
export declare function applyConversationCacheControl(messages: readonly ModelMessage[]
|
|
55
|
+
export declare function applyConversationCacheControl(messages: readonly ModelMessage[]): ModelMessage[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const ANTHROPIC_CACHE_MARKER=Object.freeze({anthropic:Object.freeze({cacheControl:Object.freeze({type:`ephemeral`})}),bedrock:Object.freeze({cachePoint:Object.freeze({type:`default`})})});function mergeGatewayAutoCaching(e){let t=e?.gateway!==void 0&&typeof e.gateway==`object`&&e.gateway!==null?e.gateway:void 0,n={...t,caching:t?.caching??`auto`};return{...e,gateway:n}}function applyLastToolCacheBreakpoint(e){let t=Object.entries(e);if(t.length===0)return e;let n={};for(let e=0;e<t.length;e++){let[r,i]=t[e];if(e===t.length-1){let e=i.providerOptions!==void 0&&typeof i.providerOptions==`object`?i.providerOptions:void 0;n[r]={...i,providerOptions:{...e,...ANTHROPIC_CACHE_MARKER}}}else n[r]=i}return n}function applySystemCacheBreakpoint(e){if(e.length===0)return[...e];let t=[...e],n=t[t.length-1];return t[t.length-1]={...n,providerOptions:{...n.providerOptions,...ANTHROPIC_CACHE_MARKER}},t}function applyConversationCacheControl(e){if(e.length===0)return[...e];let t=[...e],mark=e=>{let n=t[e];n!==void 0&&(t[e]={...n,providerOptions:{...n.providerOptions,...ANTHROPIC_CACHE_MARKER}})};mark(t.length-1);for(let e=t.length-2;e>=0;e--)if(t[e]?.role===`assistant`){mark(e);break}return t}export{applyConversationCacheControl,applyLastToolCacheBreakpoint,applySystemCacheBreakpoint,mergeGatewayAutoCaching};
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import type { LanguageModel } from "ai";
|
|
2
1
|
import type { SessionAuthContext } from "#channel/types.js";
|
|
3
|
-
import type {
|
|
2
|
+
import type { ModelProfile } from "#harness/model-profile.js";
|
|
4
3
|
/**
|
|
5
4
|
* Adds a provider-specific end-user safety identifier without disclosing the
|
|
6
5
|
* raw eve principal. Authored provider options take precedence over the default.
|
|
7
6
|
*/
|
|
8
|
-
export declare function mergeProviderSafetyIdentifier(
|
|
7
|
+
export declare function mergeProviderSafetyIdentifier(provider: string, providerOptions: Readonly<Record<string, unknown>> | undefined, auth: SessionAuthContext | null): Record<string, unknown> | undefined;
|
|
9
8
|
/** Composes the per-call defaults shared by model steps and compaction. */
|
|
10
9
|
export declare function resolveCallProviderOptions(input: {
|
|
11
10
|
readonly auth: SessionAuthContext | null;
|
|
12
11
|
readonly conversationId: string;
|
|
13
|
-
readonly
|
|
14
|
-
readonly modelReference: RuntimeModelReference;
|
|
12
|
+
readonly profile: ModelProfile;
|
|
15
13
|
readonly providerOptions: Readonly<Record<string, unknown>> | undefined;
|
|
16
14
|
}): Record<string, unknown> | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{invocationOwnerKey}from"#internal/invocation/metadata.js";import{mergeObjects}from"#shared/objects.js";function mergeProviderSafetyIdentifier(e,t,n){if(n===null)return t;let r=invocationOwnerKey(n),i=e===`openai`?{openai:{safetyIdentifier:r}}:e===`anthropic`?{anthropic:{metadata:{userId:r}}}:void 0;return i===void 0?t:mergeObjects(i,t)}function resolveCallProviderOptions(e){let t=mergeProviderSafetyIdentifier(e.profile.provider,e.providerOptions,e.auth);return e.profile.gateway?mergeGatewaySessionId(t,e.conversationId):t}function mergeGatewaySessionId(e,t){let n=e?.gateway,r=typeof n==`object`&&n&&!Array.isArray(n)?n:void 0;return typeof r?.sessionId==`string`&&r.sessionId.trim()?e:{...e,gateway:{...r,sessionId:t}}}export{mergeProviderSafetyIdentifier,resolveCallProviderOptions};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ToolSet } from "ai";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ModelProfile } from "#harness/model-profile.js";
|
|
3
3
|
import type { JsonObject } from "#shared/json.js";
|
|
4
4
|
import type { WebSearchProvider } from "#shared/web-search.js";
|
|
5
5
|
/**
|
|
@@ -21,19 +21,11 @@ export declare function resolveFrameworkToolFromUpstreamType(type: string): stri
|
|
|
21
21
|
*/
|
|
22
22
|
export declare function resolveWebSearchOutputSchema(backend: Exclude<WebSearchBackend, "browserbase">): JsonObject;
|
|
23
23
|
/**
|
|
24
|
-
* Determines the web search backend for a model
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* - Direct/BYO OpenAI models: native OpenAI search
|
|
28
|
-
* - Direct/BYO Anthropic models: native Anthropic search
|
|
29
|
-
* - Direct/BYO Google models: native Google search grounding
|
|
30
|
-
* - Other BYO models: not available (returns `null`)
|
|
31
|
-
*
|
|
32
|
-
* `modelProvider` is the provider of the resolved AI SDK model. It is needed
|
|
33
|
-
* for live dynamic selections because their runtime reference has no source
|
|
34
|
-
* metadata to distinguish a direct provider from AI Gateway.
|
|
24
|
+
* Determines the web search backend for a model: the configured search provider (Exa by
|
|
25
|
+
* default) on AI Gateway, the provider's native search for direct OpenAI, Anthropic, and Google
|
|
26
|
+
* models, and none (`null`) for any other direct model.
|
|
35
27
|
*/
|
|
36
|
-
export declare function resolveWebSearchBackend(
|
|
28
|
+
export declare function resolveWebSearchBackend(profile: ModelProfile, gatewayProvider?: WebSearchProvider): WebSearchBackend | null;
|
|
37
29
|
/**
|
|
38
30
|
* Constructs the AI SDK provider tool for web search based on the resolved
|
|
39
31
|
* backend. Called once per harness step when web search is enabled.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsonSchema}from"ai";import{WEB_SEARCH_ANTHROPIC_OUTPUT_SCHEMA,WEB_SEARCH_EXA_OUTPUT_SCHEMA,WEB_SEARCH_GOOGLE_OUTPUT_SCHEMA,WEB_SEARCH_OPENAI_OUTPUT_SCHEMA,WEB_SEARCH_PARALLEL_OUTPUT_SCHEMA,WEB_SEARCH_TOOL_NAME}from"#harness/provider-tool-schemas.js";const UPSTREAM_TOOL_TYPE_TO_FRAMEWORK_NAME={web_search_20250305:WEB_SEARCH_TOOL_NAME};function resolveFrameworkToolFromUpstreamType(e){return UPSTREAM_TOOL_TYPE_TO_FRAMEWORK_NAME[e]??null}function resolveWebSearchOutputSchema(e){switch(e){case`anthropic`:return WEB_SEARCH_ANTHROPIC_OUTPUT_SCHEMA;case`exa`:return WEB_SEARCH_EXA_OUTPUT_SCHEMA;case`google`:return WEB_SEARCH_GOOGLE_OUTPUT_SCHEMA;case`openai`:return WEB_SEARCH_OPENAI_OUTPUT_SCHEMA;case`parallel`:return WEB_SEARCH_PARALLEL_OUTPUT_SCHEMA}}function resolveWebSearchBackend(e,t=`exa
|
|
1
|
+
import{jsonSchema}from"ai";import{WEB_SEARCH_ANTHROPIC_OUTPUT_SCHEMA,WEB_SEARCH_EXA_OUTPUT_SCHEMA,WEB_SEARCH_GOOGLE_OUTPUT_SCHEMA,WEB_SEARCH_OPENAI_OUTPUT_SCHEMA,WEB_SEARCH_PARALLEL_OUTPUT_SCHEMA,WEB_SEARCH_TOOL_NAME}from"#harness/provider-tool-schemas.js";const UPSTREAM_TOOL_TYPE_TO_FRAMEWORK_NAME={web_search_20250305:WEB_SEARCH_TOOL_NAME};function resolveFrameworkToolFromUpstreamType(e){return UPSTREAM_TOOL_TYPE_TO_FRAMEWORK_NAME[e]??null}function resolveWebSearchOutputSchema(e){switch(e){case`anthropic`:return WEB_SEARCH_ANTHROPIC_OUTPUT_SCHEMA;case`exa`:return WEB_SEARCH_EXA_OUTPUT_SCHEMA;case`google`:return WEB_SEARCH_GOOGLE_OUTPUT_SCHEMA;case`openai`:return WEB_SEARCH_OPENAI_OUTPUT_SCHEMA;case`parallel`:return WEB_SEARCH_PARALLEL_OUTPUT_SCHEMA}}function resolveWebSearchBackend(e,t=`exa`){return e.gateway?t:NATIVE_WEB_SEARCH_PROVIDERS.has(e.provider)?e.provider:null}const NATIVE_WEB_SEARCH_PROVIDERS=new Set([`anthropic`,`google`,`openai`]);async function resolveWebSearchProviderTool(e){switch(e){case`browserbase`:{let{gateway:e}=await import(`ai`);return e.tools.browserbaseSearch()}case`openai`:{let{openai:t}=await import(`#compiled/@ai-sdk/openai/index.js`);return attachWebSearchOutputSchema(t.tools.webSearch({}),e)}case`anthropic`:{let{anthropic:t}=await import(`#compiled/@ai-sdk/anthropic/index.js`);return attachWebSearchOutputSchema(t.tools.webSearch_20250305(),e)}case`google`:{let{google:t}=await import(`#compiled/@ai-sdk/google/index.js`);return attachWebSearchOutputSchema(t.tools.googleSearch({}),e)}case`exa`:{let{gateway:t}=await import(`ai`);return attachWebSearchOutputSchema(t.tools.exaSearch({contents:{highlights:{maxCharacters:1e3}},numResults:10}),e)}case`parallel`:{let{gateway:t}=await import(`ai`);return attachWebSearchOutputSchema(t.tools.parallelSearch(),e)}}}function attachWebSearchOutputSchema(e,t){return{...e,outputSchema:jsonSchema(resolveWebSearchOutputSchema(t))}}export{resolveFrameworkToolFromUpstreamType,resolveWebSearchBackend,resolveWebSearchOutputSchema,resolveWebSearchProviderTool};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SubagentInputRequestHookPayload } from "#channel/types.js";
|
|
2
|
+
import type { InputResolvedStreamEvent } from "#protocol/message.js";
|
|
2
3
|
import type { StepCoordinates as PendingInputBatchEvent } from "#harness/session-machine/view.js";
|
|
3
4
|
import type { HarnessSessionBase, SessionStateMap } from "#harness/types.js";
|
|
4
5
|
import { type InputOption, type InputRequestKind } from "#shared/input.js";
|
|
@@ -11,11 +12,9 @@ import type { RemoteAgentBinding } from "#eve-channel/support.js";
|
|
|
11
12
|
*/
|
|
12
13
|
export interface WorkflowAskRoute {
|
|
13
14
|
readonly control: string;
|
|
14
|
-
/** What a plain-text message may answer. */
|
|
15
|
-
readonly question: ProxyInputQuestion;
|
|
16
15
|
}
|
|
17
|
-
/** The parts of a
|
|
18
|
-
export interface
|
|
16
|
+
/** The parts of a request a plain-text reply is resolved against. */
|
|
17
|
+
export interface ProxyInputReply {
|
|
19
18
|
readonly allowFreeform?: boolean;
|
|
20
19
|
readonly options?: readonly InputOption[];
|
|
21
20
|
}
|
|
@@ -42,13 +41,25 @@ export interface ProxyInputRequest {
|
|
|
42
41
|
*/
|
|
43
42
|
readonly event: PendingInputBatchEvent;
|
|
44
43
|
readonly kind: InputRequestKind;
|
|
45
|
-
/**
|
|
46
|
-
readonly
|
|
44
|
+
/** Lets the human-facing parent resolve a plain-text reply before proxying it by ID. */
|
|
45
|
+
readonly reply?: ProxyInputReply;
|
|
47
46
|
}
|
|
48
47
|
export interface ProxyInputRequestBatch {
|
|
49
48
|
readonly approvalRequestIds: readonly string[];
|
|
50
49
|
readonly requestIds: readonly string[];
|
|
51
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether the child, not this session, closes a relayed request. A child's tool approval can
|
|
53
|
+
* refuse the person who answered, so it stays open here until the child's own `input.resolved`
|
|
54
|
+
* or `approval.settled` arrives. This session closes every other relayed request once it
|
|
55
|
+
* forwards the answer.
|
|
56
|
+
*/
|
|
57
|
+
export declare function resolvedByChild(kind: InputRequestKind): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The part of a child's `input.resolved` its parent relays: the requests the parent leaves for
|
|
60
|
+
* the child to close. `undefined` when the parent already closed all of them.
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolvedForParent(data: InputResolvedStreamEvent["data"]): InputResolvedStreamEvent["data"] | undefined;
|
|
52
63
|
/**
|
|
53
64
|
* Returns the proxy-routing map as a fresh `Map`. Never returns a live
|
|
54
65
|
* reference so accidental mutation cannot corrupt session state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isSessionInboxAddress}from"#execution/session-inbox/address.js";import{inputOptionSchema}from"#shared/input.js";const PROXY_INPUT_REQUESTS_KEY=`eve.runtime.proxyInputRequests`,PROXY_INPUT_REQUEST_KINDS={question:!0,"session-limit":!0,"tool-approval":!0};function getProxyInputRequests(e){return new Map(Object.entries(readMap(e)))}function hasProxyInputRequests(e){for(let t of Object.keys(readMap(e)))return!0;return!1}function upsertProxyInputRequests(e){return{...e.session,state:upsertProxyInputRequestState({entries:e.entries,forChildContinuationToken:e.forChildContinuationToken,inputSource:e.inputSource,state:e.session.state})}}function upsertProxyInputRequestState(e){let t={};for(let[n,r]of Object.entries(readMap(e.state)))(r.childContinuationToken!==e.forChildContinuationToken||r.inputSource!==e.inputSource)&&(t[n]=r);for(let[n,r]of e.entries)t[n]=r;let n={...e.state};return Object.keys(t).length===0?delete n[PROXY_INPUT_REQUESTS_KEY]:n[PROXY_INPUT_REQUESTS_KEY]=t,Object.keys(n).length>0?n:void 0}function clearProxyInputRequestsWhere(e,t){return retireProxyInputRequests(e,Object.entries(readMap(e.state)).filter(([e,n])=>t(n,e)).map(([e])=>e))}function retireProxyInputRequests(e,t){let n={...readMap(e.state)},r=!1;for(let e of t)Object.hasOwn(n,e)&&(delete n[e],r=!0);return r?writeMap(e,n):e}function toProxyInputRequestEntries(e){let t={approvalRequestIds:e.event.requests.flatMap(e=>e.kind===`tool-approval`?[e.requestId]:[]),requestIds:e.event.requests.map(e=>e.requestId)},n={sequence:e.event.sequence,stepIndex:e.event.stepIndex,turnId:e.event.turnId};return e.event.requests.map(r=>{let i={batch:t,childContinuationToken:e.childContinuationToken,...e.inputSource!==void 0&&{inputSource:e.inputSource},...e.remote!==void 0&&{remote:e.remote},event:n,kind:r.kind
|
|
1
|
+
import{isSessionInboxAddress}from"#execution/session-inbox/address.js";import{inputOptionSchema}from"#shared/input.js";const PROXY_INPUT_REQUESTS_KEY=`eve.runtime.proxyInputRequests`,PROXY_INPUT_REQUEST_KINDS={question:!0,"session-limit":!0,"tool-approval":!0};function resolvedByChild(e){return e===`tool-approval`}function resolvedForParent(e){let t=e.resolutions.filter(({kind:e})=>resolvedByChild(e));return t.length===0?void 0:{...e,resolutions:t}}function getProxyInputRequests(e){return new Map(Object.entries(readMap(e)))}function hasProxyInputRequests(e){for(let t of Object.keys(readMap(e)))return!0;return!1}function upsertProxyInputRequests(e){return{...e.session,state:upsertProxyInputRequestState({entries:e.entries,forChildContinuationToken:e.forChildContinuationToken,inputSource:e.inputSource,state:e.session.state})}}function upsertProxyInputRequestState(e){let t={};for(let[n,r]of Object.entries(readMap(e.state)))(r.childContinuationToken!==e.forChildContinuationToken||r.inputSource!==e.inputSource)&&(t[n]=r);for(let[n,r]of e.entries)t[n]=r;let n={...e.state};return Object.keys(t).length===0?delete n[PROXY_INPUT_REQUESTS_KEY]:n[PROXY_INPUT_REQUESTS_KEY]=t,Object.keys(n).length>0?n:void 0}function clearProxyInputRequestsWhere(e,t){return retireProxyInputRequests(e,Object.entries(readMap(e.state)).filter(([e,n])=>t(n,e)).map(([e])=>e))}function retireProxyInputRequests(e,t){let n={...readMap(e.state)},r=!1;for(let e of t)Object.hasOwn(n,e)&&(delete n[e],r=!0);return r?writeMap(e,n):e}function toProxyInputRequestEntries(e){let t={approvalRequestIds:e.event.requests.flatMap(e=>e.kind===`tool-approval`?[e.requestId]:[]),requestIds:e.event.requests.map(e=>e.requestId)},n={sequence:e.event.sequence,stepIndex:e.event.stepIndex,turnId:e.event.turnId};return e.event.requests.map(r=>{let i={batch:t,childContinuationToken:e.childContinuationToken,...e.inputSource!==void 0&&{inputSource:e.inputSource},...e.remote!==void 0&&{remote:e.remote},event:n,kind:r.kind,reply:{...r.allowFreeform!==void 0&&{allowFreeform:r.allowFreeform},...r.options!==void 0&&{options:[...r.options]}}};return e.childSessionInbox?.sessionId===e.childSessionId&&(i.childSessionInbox=e.childSessionInbox),[r.requestId,i]})}function readMap(e){let t=e?.[PROXY_INPUT_REQUESTS_KEY];if(typeof t!=`object`||!t||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t)){let t=parseProxyInputRequest(r,e);t!==void 0&&(n[e]=t)}return n}function writeMap(e,t){let n={...e.state};return Object.keys(t).length===0?(delete n[PROXY_INPUT_REQUESTS_KEY],{...e,state:Object.keys(n).length>0?n:void 0}):(n[PROXY_INPUT_REQUESTS_KEY]=t,{...e,state:n})}function parseProxyInputRequest(e,t){if(typeof e!=`object`||!e||Array.isArray(e)||!(`childContinuationToken`in e)||!(`kind`in e)||typeof e.childContinuationToken!=`string`||!isInputRequestKind(e.kind))return;let n=`remote`in e?parseRemoteAgentBinding(e.remote):void 0;if(`remote`in e&&n===void 0)return;let r=`inputSource`in e?e.inputSource:void 0;if(r!==void 0&&(typeof r!=`string`||r.length===0))return;let i=`event`in e?parseInputRequestEvent(e.event):void 0;if(i===void 0)return;let a=`batch`in e?parseProxyInputRequestBatch(e.batch):void 0,o=`workflowAsk`in e?parseWorkflowAskRoute(e.workflowAsk):void 0;if(`workflowAsk`in e&&o===void 0)return;let s=`runId`in e?e.runId:void 0;if(s!==void 0&&(typeof s!=`string`||s.length===0))return;let c=`reply`in e?parseProxyInputReply(e.reply):void 0;if(`reply`in e&&c===void 0)return;let l=`childSessionInbox`in e?e.childSessionInbox:void 0;if(l!==void 0&&!isSessionInboxAddress(l))return;let u={childContinuationToken:e.childContinuationToken,event:i,kind:e.kind};return typeof r==`string`&&(u.inputSource=r),n!==void 0&&(u.remote=n),o!==void 0&&(u.workflowAsk=o),typeof s==`string`&&(u.runId=s),l!==void 0&&(u.childSessionInbox=l),a!==void 0&&a.requestIds.includes(t)&&(u.batch=a),c!==void 0&&(u.reply=c),u}function parseInputRequestEvent(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=Reflect.get(e,`sequence`),n=Reflect.get(e,`stepIndex`),r=Reflect.get(e,`turnId`);if(typeof t==`number`&&typeof n==`number`&&typeof r==`string`)return{sequence:t,stepIndex:n,turnId:r}}function parseWorkflowAskRoute(e){if(typeof e!=`object`||!e)return;let t=Reflect.get(e,`control`);if(typeof t==`string`&&t.length!==0)return{control:t}}function parseRemoteAgentBinding(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=Reflect.get(e,`name`),n=Reflect.get(e,`url`),r=Reflect.get(e,`resolverId`),i=Reflect.get(e,`forwardPrincipal`),a=Reflect.get(e,`sessionId`);if(typeof t==`string`&&t&&typeof n==`string`&&n&&typeof a==`string`&&a&&(r===void 0||typeof r==`string`&&r)&&(i===void 0||typeof i==`boolean`))return{name:t,url:n,sessionId:a,...r!==void 0&&{resolverId:r},...i!==void 0&&{forwardPrincipal:i}}}function parseProxyInputReply(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t={},n=Reflect.get(e,`allowFreeform`);if(n!==void 0){if(typeof n!=`boolean`)return;t.allowFreeform=n}let r=Reflect.get(e,`options`);if(r!==void 0){let e=inputOptionSchema.array().safeParse(r);if(!e.success)return;t.options=e.data}return t}function parseProxyInputRequestBatch(e){if(typeof e!=`object`||!e||Array.isArray(e)||!(`approvalRequestIds`in e)||!(`requestIds`in e)||!isStringArray(e.approvalRequestIds)||!isStringArray(e.requestIds))return;let t=new Set(e.requestIds);if(!(t.size!==e.requestIds.length||e.approvalRequestIds.some(e=>!t.has(e))))return{approvalRequestIds:e.approvalRequestIds,requestIds:e.requestIds}}function isStringArray(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function isInputRequestKind(e){return typeof e==`string`&&Object.hasOwn(PROXY_INPUT_REQUEST_KINDS,e)}export{clearProxyInputRequestsWhere,getProxyInputRequests,hasProxyInputRequests,resolvedByChild,resolvedForParent,retireProxyInputRequests,toProxyInputRequestEntries,upsertProxyInputRequestState,upsertProxyInputRequests};
|
|
@@ -10,6 +10,10 @@ export declare function currentProjection(ctx?: ContextReader | undefined): Sess
|
|
|
10
10
|
/** The step's live projection, or the session's stored one when no step entered it. */
|
|
11
11
|
export declare function projectionFor(ctx: ContextReader, state: SessionStateMap | undefined): SessionProjection;
|
|
12
12
|
export declare function recordPublishedEvent(ctx: ContextReader, event: MessageStreamEvent | UnstampedMessageStreamEvent): void;
|
|
13
|
+
/** Records the session a transition the step published produced. */
|
|
14
|
+
export declare function recordAppliedSession(ctx: ContextReader, session: HarnessSessionBase): void;
|
|
15
|
+
/** The session the step's last applied transition produced, if it applied any. */
|
|
16
|
+
export declare function appliedSession<T extends HarnessSessionBase>(ctx: ContextReader): T | undefined;
|
|
13
17
|
export declare function saveSessionProjection<T extends HarnessSessionBase>(session: T, ctx: ContextReader): T;
|
|
14
18
|
/**
|
|
15
19
|
* The session saves the lifecycle its steps read. Calls and tasks are for the stream's readers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SESSION_PROJECTION_STATE_KEY,storedProjection}from"./view.js";import{foldSession,pruneSessionProjection}from"#protocol/session-projection.js";import{contextStorage}from"#context/container.js";const LIVE_PROJECTIONS_GLOBAL_KEY=Symbol.for(`eve.live-session-projections`),liveProjections=globalThis[LIVE_PROJECTIONS_GLOBAL_KEY]??=new WeakMap;function enterSessionProjection(e,t){liveProjections.set(e,{projection:storedProjection(t)})}function ensureSessionProjection(e,t){liveProjections.has(e)||enterSessionProjection(e,t)}function currentProjection(e=contextStorage.getStore()){let t=e===void 0?void 0:liveProjections.get(e);if(t===void 0)throw Error(`Session lifecycle requires an initialized projection.`);return t.projection}function projectionFor(e,t){return liveProjections.get(e)?.projection??storedProjection(t)}function recordPublishedEvent(e,t){let n=liveProjections.get(e);if(n===void 0)throw Error(`Session publication requires an initialized projection.`);let r=foldSession(n.projection,t);n.projection=t.type===`session.waiting`?pruneSessionProjection(r):r}function saveSessionProjection(e,t){return saveProjection(e,currentProjection(t))}function saveProjection(e,t){let n={...t,calls:{},tasks:{}};return{...e,state:{...e.state,[SESSION_PROJECTION_STATE_KEY]:n}}}function stepProjection(e,t){if(e!==void 0)return ensureSessionProjection(e,t),{read:()=>currentProjection(e),record:t=>recordPublishedEvent(e,t)};let n=storedProjection(t);return{read:()=>n,record(e){let t=foldSession(n,e);n=e.type===`session.waiting`?pruneSessionProjection(t):t}}}export{currentProjection,ensureSessionProjection,enterSessionProjection,projectionFor,recordPublishedEvent,saveProjection,saveSessionProjection,stepProjection};
|
|
1
|
+
import{SESSION_PROJECTION_STATE_KEY,storedProjection}from"./view.js";import{foldSession,pruneSessionProjection}from"#protocol/session-projection.js";import{contextStorage}from"#context/container.js";const LIVE_PROJECTIONS_GLOBAL_KEY=Symbol.for(`eve.live-session-projections`),liveProjections=globalThis[LIVE_PROJECTIONS_GLOBAL_KEY]??=new WeakMap;function enterSessionProjection(e,t){liveProjections.set(e,{projection:storedProjection(t)})}function ensureSessionProjection(e,t){liveProjections.has(e)||enterSessionProjection(e,t)}function currentProjection(e=contextStorage.getStore()){let t=e===void 0?void 0:liveProjections.get(e);if(t===void 0)throw Error(`Session lifecycle requires an initialized projection.`);return t.projection}function projectionFor(e,t){return liveProjections.get(e)?.projection??storedProjection(t)}function recordPublishedEvent(e,t){let n=liveProjections.get(e);if(n===void 0)throw Error(`Session publication requires an initialized projection.`);let r=foldSession(n.projection,t);n.projection=t.type===`session.waiting`?pruneSessionProjection(r):r}const appliedSessions=new WeakMap;function recordAppliedSession(e,t){appliedSessions.set(e,t)}function appliedSession(e){return appliedSessions.get(e)}function saveSessionProjection(e,t){return saveProjection(e,currentProjection(t))}function saveProjection(e,t){let n={...t,calls:{},tasks:{}};return{...e,state:{...e.state,[SESSION_PROJECTION_STATE_KEY]:n}}}function stepProjection(e,t){if(e!==void 0)return ensureSessionProjection(e,t),{read:()=>currentProjection(e),record:t=>recordPublishedEvent(e,t)};let n=storedProjection(t);return{read:()=>n,record(e){let t=foldSession(n,e);n=e.type===`session.waiting`?pruneSessionProjection(t):t}}}export{appliedSession,currentProjection,ensureSessionProjection,enterSessionProjection,projectionFor,recordAppliedSession,recordPublishedEvent,saveProjection,saveSessionProjection,stepProjection};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createLogger}from"#internal/logging.js";import{resolveAssistantStepText,validateHarnessModelMessages}from"#harness/messages.js";import{renderFinalOutputWhileWorkingError}from"#execution/tasks/render.js";import{stageToolResultMedia}from"#harness/attachment-staging.js";import{collectDeferredCalls}from"#harness/coordination.js";import{fail,finishTurn,hold,suspendStep,withResult}from"#harness/session-machine/transitions.js";import{
|
|
1
|
+
import{createLogger}from"#internal/logging.js";import{resolveAssistantStepText,validateHarnessModelMessages}from"#harness/messages.js";import{renderFinalOutputWhileWorkingError}from"#execution/tasks/render.js";import{extractToolApprovalInputRequests,hasRunnableQueue,parkOnApprovals,stopForToolSignIn}from"#harness/hitl/index.js";import{stageToolResultMedia}from"#harness/attachment-staging.js";import{collectDeferredCalls}from"#harness/coordination.js";import{fail,finishTurn,hold,suspendStep,withResult}from"#harness/session-machine/transitions.js";import{createToolResultMessagePartFromToolError,isToolResultError}from"#harness/action-result-helpers.js";import{setRequestEnvelopeTokens}from"#harness/request-envelope.js";import{isTaskTool,workingTaskIds}from"#execution/tasks/model-step.js";import{getInvalidToolCallInputError,isInvalidToolCall}from"#harness/tool-call-input-errors.js";import{resolveInlineAuthorizationInterrupt}from"#harness/inline-tool-authorization.js";import{FINAL_OUTPUT_BESIDE_PENDING_CALLS,FINAL_OUTPUT_TOOL_NAME}from"#harness/final-output.js";import{getAdvertisedTools}from"#harness/advertised-tools.js";import{appendMissingToolResultMessages,extractToolResultCallIds}from"#harness/model-call/response.js";import{clearTurnClientContextState}from"#harness/turn-client-context.js";import{normalizeProviderToolHistory}from"#harness/provider-tool-history.js";const log=createLogger(`harness.tool-loop`);function getInvalidToolCallInputErrors(e){let t=[];for(let n of e.toolCalls){if(n.toolName===FINAL_OUTPUT_TOOL_NAME)continue;let e=getInvalidToolCallInputError({toolCall:n});e!==void 0&&t.push(e)}return t}async function handleStepResult(e,t){let{promptMessages:n,result:r}=t,i=resolveAssistantStepText(r.response.messages,r.text),a=getInvalidToolCallInputErrors({toolCalls:r.toolCalls}),o=new Set([...r.invalidInputToolCallIds??[],...r.toolCalls.filter(isInvalidToolCall).map(e=>e.toolCallId),...a.map(e=>e.toolCallId)]),s=appendMissingToolResultMessages({append:a.map(e=>createToolResultMessagePartFromToolError(e)),responseMessages:r.response.messages}),c=new Set;for(let e of[...r.content??[],...r.toolResults??[]])(e.type===`tool-result`||e.type===`tool-error`)&&e.providerExecuted===!0&&c.add(e.toolCallId);let l=normalizeProviderToolHistory({messages:s,providerExecutedOutcomeIds:c}),u=await stageToolResultMedia(withoutApprovalParts(l.messages));e.session=setRequestEnvelopeTokens({...e.session,compaction:createNextCompactionConfig(e.session.compaction,t.durableModelPromptMessageCount,r)},r.usage?.inputTokens!==void 0&&t.durableModelPromptMessageCount!==void 0?t.requestEnvelopeTokens:void 0);let d=extractToolApprovalInputRequests({content:r.content??[],excludedCallIds:o}),f=getAdvertisedTools({session:e.session,tools:t.coordinationTools}),p=new Set([...d.map(e=>e.action.callId),...extractToolResultCallIds(u)]),m=[],h=(r.toolCalls??[]).filter(e=>!o.has(e.toolCallId)).filter(e=>!p.has(e.toolCallId)).filter(e=>isDeferredHarnessTool(t.coordinationTools.get(e.toolName))).filter(t=>isDeferredHarnessTool(f.get(t.toolName))?!0:(log.warn(`deferred tool call blocked because tool is not advertised`,{callId:t.toolCallId,sessionId:e.session.sessionId,toolName:t.toolName}),m.push(t),!1));if(h.length>0||d.length>0){let{sequence:t,stepIndex:i,turnId:a}=e.position(),o=collectDeferredCalls({session:e.session,toolCalls:h,tools:f,turnId:a});e.session={...o.session,history:validateHarnessModelMessages(n)};let s={event:{sequence:t,stepIndex:i,turnId:a},messages:answerCallsThatWontRun(u,r,m),tasks:o.workflowRequests};return d.length>0?parkOnApprovals(e,{...s,requests:d,waitsOnRuntime:h.length>0}):(await e.apply(suspendStep(e.view(),s)),{next:null,session:e.session})}let g=resolveInlineAuthorizationInterrupt({messages:[...n,...u],toolResults:r.toolResults});if(g)return stopForToolSignIn(e,g);e.session={...e.session,history:validateHarnessModelMessages([...n,...u])};let _=e.session.outputSchema!==void 0&&extractFinalOutput(r)!==void 0,v=workingTaskIds(e.session),y=_&&v.length>0,b=u;y&&(b=rejectFinalOutput(u,r,v),e.session={...e.session,history:validateHarnessModelMessages([...n,...b])});let x=await stepEndsTurn(r,u,t.endsTurnTools);return(!_||y)&&(b.at(-1)?.role===`tool`&&!x||l.outcomeEndsResponse||hasRunnableQueue(e.view()))?{next:e.runStep,session:e.session}:v.length>0?(await e.apply(hold(e.view(),{on:`tasks`})),{held:{kind:`tasks`,taskIds:v},next:null,session:e.session}):settleTurn(e,{history:n,result:r,stepOutput:x?null:i})}function answerCallsThatWontRun(e,t,n){let r=extractToolResultCallIds(e);return[...(t.toolCalls??[]).filter(e=>e.toolName===FINAL_OUTPUT_TOOL_NAME).map(e=>({output:{type:`error-text`,value:FINAL_OUTPUT_BESIDE_PENDING_CALLS},toolCallId:e.toolCallId,toolName:e.toolName,type:`tool-result`})),...n.map(e=>({output:{type:`error-text`,value:`The tool "${e.toolName}" isn't available in this step, so the call didn't run.`},toolCallId:e.toolCallId,toolName:e.toolName,type:`tool-result`}))].filter(e=>!r.has(e.toolCallId)).reduce((e,t)=>withResult(e,t),[...e])}function withoutApprovalParts(e){return e.flatMap(e=>{if(e.role!==`assistant`&&e.role!==`tool`||!Array.isArray(e.content))return[e];let t=e.content.filter(e=>e.type!==`tool-approval-request`&&e.type!==`tool-approval-response`);return t.length===0?[]:[{...e,content:t}]})}async function stepEndsTurn(e,t,n){let r=e.toolCalls??[];if(r.length===0)return!1;let i=new Map;for(let e of t)if(e.role===`tool`)for(let t of e.content)t.type===`tool-result`&&i.set(t.toolCallId,t.output);if(!r.every(e=>{let t=i.get(e.toolCallId);return n.has(e.toolName)&&t!==void 0&&!isToolResultError(t)}))return!1;let a=new Map((e.toolResults??[]).map(e=>[e.toolCallId,e.output]));for(let e of r){let t=n.get(e.toolName);if(typeof t==`function`&&!await callEndsTurn(t,a.get(e.toolCallId),e))return!1}return!0}async function callEndsTurn(e,t,n){try{return await e(t)===!0}catch(e){return log.warn(`endsTurn threw; continuing the turn`,{callId:n.toolCallId,error:e,toolName:n.toolName}),!1}}function isDeferredHarnessTool(e){return e?.workflowId!==void 0||isTaskTool(e)}function rejectFinalOutput(e,t,n){let r=(t.toolCalls??[]).find(e=>e.toolName===FINAL_OUTPUT_TOOL_NAME);if(r===void 0)return[...e];let i={output:{type:`error-text`,value:renderFinalOutputWhileWorkingError(n)},toolCallId:r.toolCallId,toolName:FINAL_OUTPUT_TOOL_NAME,type:`tool-result`};return[...e,{content:[i],role:`tool`}]}const OUTPUT_SCHEMA_NOT_FULFILLED={code:`OUTPUT_SCHEMA_NOT_FULFILLED`,message:`The agent could not produce a result matching the requested schema.`};function extractFinalOutput(e){return(e.toolCalls??[]).find(e=>e.toolName===FINAL_OUTPUT_TOOL_NAME&&!isInvalidToolCall(e))?.input}async function settleTurn(e,t){let{history:n,result:r,stepOutput:i}=t,a=e.session.outputSchema;if(e.session=clearTurnClientContextState(e.session),a===void 0)return await e.apply(finishTurn(e.view()),e.session.history),{next:null,session:e.session,settledTurn:{output:i??``}};let o=extractFinalOutput(r);return o===void 0?(e.session={...e.session,outputSchema:void 0},await e.apply(fail(e.view(),OUTPUT_SCHEMA_NOT_FULFILLED)),{next:null,session:e.session,settledTurn:{isError:!0,output:OUTPUT_SCHEMA_NOT_FULFILLED.message}}):(e.session={...e.session,history:[...n,{content:JSON.stringify(o),role:`assistant`}],outputSchema:void 0},await e.apply(finishTurn(e.view(),{result:o}),e.session.history),{next:null,session:e.session,settledTurn:{output:o}})}function createNextCompactionConfig(e,t,n){let r={recentWindowSize:e.recentWindowSize,threshold:e.threshold,thresholdPercent:e.thresholdPercent};return n.usage?.inputTokens!==void 0&&t!==void 0&&(r.lastKnownInputTokens=n.usage.inputTokens,r.lastKnownPromptMessageCount=t),r}export{handleStepResult,withoutApprovalParts};
|
|
@@ -2,7 +2,7 @@ import type { ModelMessage } from "ai";
|
|
|
2
2
|
import type { AlsContext } from "#context/container.js";
|
|
3
3
|
import { type HarnessModelMessage } from "#harness/messages.js";
|
|
4
4
|
import { type Publish, type Transition } from "#harness/session-machine/commit.js";
|
|
5
|
-
import type
|
|
5
|
+
import { type StepProjection } from "#harness/session-machine/current.js";
|
|
6
6
|
import { type SessionView, type TurnPosition } from "#harness/session-machine/view.js";
|
|
7
7
|
import type { HarnessEmitFn, HarnessSession, StepFn, StepInput, StepResult, ToolLoopHarnessConfig } from "#harness/types.js";
|
|
8
8
|
import type { InstrumentationStepScope } from "#instrumentation/runtime.js";
|
|
@@ -52,8 +52,13 @@ export declare function openTurn(step: Step, opened: {
|
|
|
52
52
|
readonly input: readonly HarnessModelMessage[];
|
|
53
53
|
readonly message?: StepInput["message"];
|
|
54
54
|
}): Promise<StepResult | undefined>;
|
|
55
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* A lifecycle event failed to publish: a dynamic model selection failure ends the session, and a
|
|
57
|
+
* dynamic connection resolver failure parks it. Anything else throws.
|
|
58
|
+
*/
|
|
56
59
|
export declare function failBoundaryEvent(step: Step, error: unknown): Promise<StepResult>;
|
|
60
|
+
/** A dynamic connection resolver threw: the session parks so the next message can retry. */
|
|
61
|
+
export declare function failConnectionResolution(step: Step, error: unknown): Promise<StepResult>;
|
|
57
62
|
/** No model can serve the turn: the session fails. */
|
|
58
63
|
export declare function failModelSelection(step: Step, error: unknown): Promise<StepResult>;
|
|
59
64
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createErrorId,createLogger}from"#internal/logging.js";import{ParentSessionKey,SessionCallbackKey}from"#context/keys.js";import{toErrorMessage}from"#shared/errors.js";import{validateHarnessModelMessages}from"#harness/messages.js";import{drainMemoryCommit,prepareMemoryPreamble}from"#context/memory-lifecycle.js";import{activeTurnId,turnPosition}from"#harness/session-machine/view.js";import{applyTransition,sessionView}from"#harness/session-machine/commit.js";import{fail,receive}from"#harness/session-machine/transitions.js";import{isDynamicModelSelectionError}from"#context/dynamic-model-lifecycle.js";import{isTurnCancellation,throwIfTurnAborted}from"#harness/turn-cancellation.js";import{drainDynamicInstructionUserMessages,prepareDynamicInstructionPreamble}from"#context/dynamic-instruction-lifecycle.js";const log=createLogger(`harness.step`);function createStep(e){let{ctx:t,live:n}=e,r={session:e.session,frameworkToolNames:new Set,config:e.config,ctx:t,runStep:e.runStep,publish:e.publish,emit:e.emit,instrumentation:e.instrumentation,hasDelegatedCaller:t?.get(ParentSessionKey)!==void 0||t?.get(SessionCallbackKey)!==void 0,view:()=>sessionView(n.read(),r.session.state),position:()=>turnPosition(n.read()),async apply(
|
|
1
|
+
import{createErrorId,createLogger}from"#internal/logging.js";import{recordAppliedSession}from"#harness/session-machine/current.js";import{ParentSessionKey,SessionCallbackKey}from"#context/keys.js";import{toErrorMessage}from"#shared/errors.js";import{validateHarnessModelMessages}from"#harness/messages.js";import{drainMemoryCommit,prepareMemoryPreamble}from"#context/memory-lifecycle.js";import{activeTurnId,turnPosition}from"#harness/session-machine/view.js";import{applyTransition,sessionView}from"#harness/session-machine/commit.js";import{fail,receive}from"#harness/session-machine/transitions.js";import{isDynamicConnectionResolutionError}from"#context/dynamic-connection-lifecycle.js";import{isDynamicModelSelectionError}from"#context/dynamic-model-lifecycle.js";import{isTurnCancellation,throwIfTurnAborted}from"#harness/turn-cancellation.js";import{drainDynamicInstructionUserMessages,prepareDynamicInstructionPreamble}from"#context/dynamic-instruction-lifecycle.js";const log=createLogger(`harness.step`);function createStep(e){let{ctx:t,live:n}=e,r={session:e.session,frameworkToolNames:new Set,config:e.config,ctx:t,runStep:e.runStep,publish:e.publish,emit:e.emit,instrumentation:e.instrumentation,hasDelegatedCaller:t?.get(ParentSessionKey)!==void 0||t?.get(SessionCallbackKey)!==void 0,view:()=>sessionView(n.read(),r.session.state),position:()=>turnPosition(n.read()),async apply(n,i){r.session=await applyTransition(r.session,n,e.publish,i),t!==void 0&&recordAppliedSession(t,r.session)},projectHistory:(t,n=r.session.state)=>e.prepareHistory(t,n).messages};return r}async function openTurn(e,t){let{config:n,ctx:r}=e;r!==void 0&&(prepareDynamicInstructionPreamble(r,e.projectHistory(e.session.history)),prepareMemoryPreamble(r,{history:e.session.history,input:[...t.input],projector:n.historyProjector,state:e.session.state}));let i;try{let r=e.position(),i=await e.instrumentation?.preparePreamble({sequence:r.sequence,sessionStarted:r.sessionStarted,traceContext:e.instrumentation?.traceContext,turnId:activeTurnId(r)});await e.apply(receive(e.view(),{message:t.message,runtime:n.runtimeIdentity,trace:i}),e.projectHistory([...e.session.history,...t.input]))}catch(e){i={error:e}}let a=r===void 0?[]:drainDynamicInstructionUserMessages(r),o=r===void 0?void 0:drainMemoryCommit(r);if(e.session={...e.session,history:validateHarnessModelMessages([...e.session.history,...o?.recalledMessages??[],...a]),state:o?.state??e.session.state},i!==void 0)return failBoundaryEvent(e,i.error);e.instrumentation?.setTurnId(e.position().turnId)}async function failBoundaryEvent(e,t){if(throwIfTurnAborted(e.config.abortSignal),isTurnCancellation(t))throw t;if(isDynamicModelSelectionError(t))return failModelSelection(e,t);if(isDynamicConnectionResolutionError(t))return failConnectionResolution(e,t);throw t}async function failConnectionResolution(e,t){if(e.emit===void 0)throw t;e.instrumentation?.recordError(t);let n=createErrorId(),r=toErrorMessage(t);return log.error(`dynamic connection resolver failed — parking session`,{error:t,errorId:n,sessionId:e.session.sessionId,turnId:activeTurnId(e.position())}),await e.apply(fail(e.view(),{code:`EVENT_HANDLER_FAILED`,details:{errorId:n},message:r})),e.session={...e.session,outputSchema:void 0},{next:null,session:e.session,settledTurn:{isError:!0,output:r}}}async function failModelSelection(e,t){if(throwIfTurnAborted(e.config.abortSignal),e.instrumentation?.recordError(t),e.emit===void 0)throw t;let n=createErrorId(),r=toErrorMessage(t),{session:i}=e;return log.error(`model selection failed terminally`,{error:t,errorId:n,sessionId:i.sessionId,turnId:activeTurnId(e.position())}),await e.apply(fail(e.view(),{code:`MODEL_SELECTION_FAILED`,details:{errorId:n},message:r,terminal:{sessionId:i.sessionId}})),{next:e.hasDelegatedCaller?{done:!0,isError:!0,output:r}:{done:!0,output:``},session:e.session}}export{createStep,failBoundaryEvent,failConnectionResolution,failModelSelection,openTurn};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GenerateTextOnStepStartCallback, ModelMessage, PrepareStepFunction, ProviderMetadata, StepResult, ToolSet } from "ai";
|
|
2
2
|
import type { TurnPosition } from "#harness/session-machine/view.js";
|
|
3
|
-
import
|
|
3
|
+
import type { ModelProfile } from "#harness/model-profile.js";
|
|
4
4
|
import { type HarnessEmitFn, type HarnessSession, type ToolLoopHarnessConfig } from "#harness/types.js";
|
|
5
5
|
/**
|
|
6
6
|
* The subset of `StepResult` that the harness reads after a step completes.
|
|
@@ -16,13 +16,12 @@ export type HarnessStepResult = Pick<StepResult<ToolSet>, "content" | "finishRea
|
|
|
16
16
|
*/
|
|
17
17
|
interface StepHooksInput {
|
|
18
18
|
readonly auth?: import("#channel/types.js").SessionAuthContext | null;
|
|
19
|
-
readonly
|
|
19
|
+
readonly profile: ModelProfile;
|
|
20
20
|
/**
|
|
21
21
|
* Starts the model step the SDK is about to run. Omitted when the step already started, as
|
|
22
22
|
* it has for a retry of the same step.
|
|
23
23
|
*/
|
|
24
24
|
readonly startStep?: (messages: readonly ModelMessage[]) => Promise<void>;
|
|
25
|
-
readonly marker: AnthropicCacheMarker | undefined;
|
|
26
25
|
readonly session: HarnessSession;
|
|
27
26
|
}
|
|
28
27
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{contextStorage}from"#context/container.js";import{AuthKey}from"#context/keys.js";import{createActionResultEvent,createActionsRequestedEvent,createStepCompletedEvent}from"#protocol/message.js";import{resolveConversationId}from"#shared/conversation-identity.js";import{isAuthorizationSignal,isPendingAuthorizationToolOutput}from"#harness/authorization.js";import{createRuntimeToolResultFromMessagePart,createRuntimeToolResultFromStepResult,createRuntimeToolResultFromToolError}from"#harness/action-result-helpers.js";import{emitNestedToolActions}from"#harness/nested-actions.js";import{requireSessionModelReference}from"#harness/types.js";import{resolveCallProviderOptions}from"#harness/provider-safety.js";import{isInvalidToolCall}from"#harness/tool-call-input-errors.js";import{collectActionPresentation,createPresentedRuntimeActionRequestFromToolCall}from"#harness/action-presentation.js";import{normalizeAssistantStepFinishReason}from"#harness/finish-reason.js";import{extractToolApprovalInputRequests}from"#harness/input-extraction.js";import{readToolInterrupt}from"#harness/tool-interrupts.js";import{applyConversationCacheControl,mergeGatewayAutoCaching}from"#harness/prompt-cache.js";function buildStepHooks(e){let t=e.session,n;return{onStepEnd:async e=>{n(e)},onStepStart:async({messages:t})=>{await e.startStep?.(t)},prepareStep:async({messages:n
|
|
1
|
+
import{contextStorage}from"#context/container.js";import{AuthKey}from"#context/keys.js";import{createActionResultEvent,createActionsRequestedEvent,createStepCompletedEvent}from"#protocol/message.js";import{resolveConversationId}from"#shared/conversation-identity.js";import{isAuthorizationSignal,isPendingAuthorizationToolOutput}from"#harness/authorization.js";import{createRuntimeToolResultFromMessagePart,createRuntimeToolResultFromStepResult,createRuntimeToolResultFromToolError}from"#harness/action-result-helpers.js";import{emitNestedToolActions}from"#harness/nested-actions.js";import{requireSessionModelReference}from"#harness/types.js";import{resolveCallProviderOptions}from"#harness/provider-safety.js";import{isInvalidToolCall}from"#harness/tool-call-input-errors.js";import{collectActionPresentation,createPresentedRuntimeActionRequestFromToolCall}from"#harness/action-presentation.js";import{normalizeAssistantStepFinishReason}from"#harness/finish-reason.js";import{extractToolApprovalInputRequests}from"#harness/input-extraction.js";import{readToolInterrupt}from"#harness/tool-interrupts.js";import{applyConversationCacheControl,mergeGatewayAutoCaching}from"#harness/prompt-cache.js";function buildStepHooks(e){let t=e.session,n;return{onStepEnd:async e=>{n(e)},onStepStart:async({messages:t})=>{await e.startStep?.(t)},prepareStep:async({messages:n})=>{let{profile:r}=e,i={messages:r.anthropicCache?applyConversationCacheControl(n):n},a=requireSessionModelReference(t),o=resolveCallProviderOptions({auth:e.auth??contextStorage.getStore()?.get(AuthKey)??null,conversationId:resolveConversationId(t.rootSessionId??t.sessionId),profile:r,providerOptions:a.providerOptions});return r.gateway?i.providerOptions=mergeGatewayAutoCaching(o):o!==void 0&&(i.providerOptions=o),i},stepResult:new Promise(e=>{n=e})}}async function emitStepActions(e,t,n,r){let i=new Set(n.toolCalls.filter(isProviderExecutedToolCall).map(e=>e.toolCallId)),a=new Set([...r.excludedActionCallIds??[],...i,...extractToolApprovalInputRequests({content:n.content??[],excludedCallIds:r.excludedActionCallIds}).map(e=>e.action.callId),...n.toolCalls.filter(isInvalidToolCall).map(e=>e.toolCallId)]),isExcluded=(e,t)=>a.has(e)||r.excludedActionToolNames.has(t),o=n.toolCalls.filter(e=>!isExcluded(e.toolCallId,e.toolName)&&!r.emittedActionCallIds?.has(e.toolCallId)).map(e=>createPresentedRuntimeActionRequestFromToolCall({toolCall:e,tools:r.tools}));o.length>0&&await e(createActionsRequestedEvent({actions:o.map(({action:e})=>e),presentation:collectActionPresentation(o),sequence:t.sequence,stepIndex:t.stepIndex,turnId:t.turnId}));let s=r.handledInlineToolResultCallIds,c=new Map(n.toolResults.map(e=>[e.toolCallId,e.output]));for(let r of reconcileToolResults(n)){if(isExcluded(r.callId,r.toolName)||s?.has(r.callId))continue;let n=c.get(r.callId);shouldSkipAuthorizationActionResult(r.callId,n)||(await emitNestedToolActions(e,t,r.callId),await e(createActionResultEvent({result:r,sequence:t.sequence,stepIndex:t.stepIndex,turnId:t.turnId})))}await e(createStepCompletedEvent({finishReason:normalizeAssistantStepFinishReason(n.finishReason),providerMetadata:extractStepProviderMetadata(n.providerMetadata),sequence:t.sequence,stepIndex:t.stepIndex,turnId:t.turnId,usage:extractStepUsage({costUsd:extractGatewayCostUsd(n.providerMetadata),usage:n.usage})}))}function isProviderExecutedToolCall(e){return e.providerExecuted===!0}function reconcileToolResults(e){let t=new Map;for(let n of e.toolResults)n.providerExecuted!==!0&&t.set(n.toolCallId,createRuntimeToolResultFromStepResult(n));for(let n of e.content??[])n.type===`tool-error`&&n.providerExecuted!==!0&&(t.has(n.toolCallId)||t.set(n.toolCallId,createRuntimeToolResultFromToolError(n)));for(let n of extractToolResultParts(e.response.messages))n.providerExecuted!==!0&&(t.has(n.toolCallId)||t.set(n.toolCallId,createRuntimeToolResultFromMessagePart(n)));return[...t.values()]}function shouldSkipAuthorizationActionResult(e,t){if(t!==void 0&&isPendingAuthorizationToolOutput(t))return!0;let n=contextStorage.getStore();if(n===void 0)return!1;let r=readToolInterrupt(n,e);return r!==void 0&&isAuthorizationSignal(r)}function extractToolResultParts(e){let t=[];for(let n of e)if(n.role===`tool`&&Array.isArray(n.content))for(let e of n.content)e.type===`tool-result`&&t.push(e);return t}function extractStepUsage(e){let t={};e.costUsd!==void 0&&(t.costUsd=e.costUsd);let n=e.usage;return n===void 0?Object.keys(t).length>0?t:void 0:(n.inputTokens!==void 0&&(t.inputTokens=n.inputTokens),n.outputTokens!==void 0&&(t.outputTokens=n.outputTokens),n.inputTokenDetails?.cacheReadTokens!==void 0&&(t.cacheReadTokens=n.inputTokenDetails.cacheReadTokens),n.inputTokenDetails?.cacheWriteTokens!==void 0&&(t.cacheWriteTokens=n.inputTokenDetails.cacheWriteTokens),Object.keys(t).length>0?t:void 0)}function extractStepProviderMetadata(e){let t=readGatewayGenerationId(e);return t===void 0?void 0:{gateway:{generationId:t}}}function extractGatewayCostUsd(e){let t=readGatewayMetadata(e)?.cost;if(typeof t==`number`&&Number.isFinite(t))return t;if(typeof t==`string`){let e=Number(t);return Number.isFinite(e)?e:void 0}}function readGatewayGenerationId(e){let t=readGatewayMetadata(e)?.generationId;return typeof t==`string`&&t.length>0?t:void 0}function readGatewayMetadata(e){let t=e?.gateway;return t&&typeof t==`object`&&!Array.isArray(t)?t:void 0}export{buildStepHooks,emitStepActions,readGatewayGenerationId};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{asSchema}from"ai";import{toErrorMessage}from"#shared/errors.js";import{toModelSchema}from"#tools/schema.js";import{resolveToolCallInputObject}from"#harness/coordination.js";import{authorizationPendingModelText,isAuthorizationPendingModelOutput}from"#harness/authorization.js";import{normalizeToolModelOutput}from"#harness/tool-model-output.js";async function checkToolCallInput(e,t,n){let r;try{r=resolveToolCallInputObject(t,{callId:n,toolName:e.name})}catch(t){return{kind:`invalid`,message:`Invalid input for tool "${e.name}": ${toErrorMessage(t)}`}}let i;try{let t=asSchema(toModelSchema(e.inputSchema,`input`));if(t.validate===void 0)return{kind:`valid`,value:r};i=await t.validate(r)}catch(e){return{error:e,kind:`threw`}}return i.success?{kind:`valid`,value:i.value}:{kind:`invalid`,message:`Invalid input for tool "${e.name}": ${toErrorMessage(i.error)}`}}async function toolCallModelOutput(e,t,n){return isAuthorizationPendingModelOutput(t)?{type:`text`,value:authorizationPendingModelText(t.connections)}:e.toModelOutput===void 0?typeof t==`string`?{type:`text`,value:t}:normalizeToolModelOutput({output:{type:`json`,value:t??null},toolCallId:n,toolName:e.name}):normalizeToolModelOutput({output:await e.toModelOutput(t),toolCallId:n,toolName:e.name})}export{checkToolCallInput,toolCallModelOutput};
|
|
1
|
+
import{asSchema}from"ai";import{toErrorMessage}from"#shared/errors.js";import{toModelSchema}from"#tools/schema.js";import{resolveToolCallInputObject}from"#harness/coordination.js";import{authorizationPendingModelText,isAuthorizationPendingModelOutput}from"#harness/authorization.js";import{normalizeToolModelOutput}from"#harness/tool-model-output.js";import{observeToolOutput}from"#tool-stubs/execute.js";async function checkToolCallInput(e,t,n){let r;try{r=resolveToolCallInputObject(t,{callId:n,toolName:e.name})}catch(t){return{kind:`invalid`,message:`Invalid input for tool "${e.name}": ${toErrorMessage(t)}`}}let i;try{let t=asSchema(toModelSchema(e.inputSchema,`input`));if(t.validate===void 0)return{kind:`valid`,value:r};i=await t.validate(r)}catch(e){return{error:e,kind:`threw`}}return i.success?{kind:`valid`,value:i.value}:{kind:`invalid`,message:`Invalid input for tool "${e.name}": ${toErrorMessage(i.error)}`}}async function toolCallModelOutput(e,t,n){return await observeToolOutput(e.name,n===void 0?[]:[{callId:n}],async()=>isAuthorizationPendingModelOutput(t)?{type:`text`,value:authorizationPendingModelText(t.connections)}:e.toModelOutput===void 0?typeof t==`string`?{type:`text`,value:t}:normalizeToolModelOutput({output:{type:`json`,value:t??null},toolCallId:n,toolName:e.name}):normalizeToolModelOutput({output:await e.toModelOutput(t),toolCallId:n,toolName:e.name}))}export{checkToolCallInput,toolCallModelOutput};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{contextStorage}from"#context/container.js";import{saveProjection,stepProjection}from"#harness/session-machine/current.js";import{ScheduleIdKey,StaticModelReferenceKey}from"#context/keys.js";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{clearMemorySessionState}from"#shared/memory-state.js";import{activeTurnId,turnPosition}from"#harness/session-machine/view.js";import{
|
|
1
|
+
import{contextStorage}from"#context/container.js";import{saveProjection,stepProjection}from"#harness/session-machine/current.js";import{ScheduleIdKey,StaticModelReferenceKey}from"#context/keys.js";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{clearMemorySessionState}from"#shared/memory-state.js";import{activeTurnId,turnPosition}from"#harness/session-machine/view.js";import{acceptHumanInput,admitApprovedWork,discardClearedHumanInput}from"#harness/hitl/index.js";import{clear}from"#harness/session-machine/transitions.js";import{createHistoryViewPreparer}from"#shared/history-view.js";import{createStep,openTurn}from"#harness/step/context.js";import{prepareTurnInput,settleRuntimeWork}from"#harness/step/intake.js";import{compactHistory,replaceSessionHistory}from"#harness/compaction/step.js";import{GenerationSteering}from"#harness/generation-steering.js";import{runModelStep}from"#harness/model-call/run.js";import{handleStepResult}from"#harness/step/after-model.js";const environment=process.env.NODE_ENV??`unknown`,eveVersion=resolveInstalledPackageInfo().version;function createToolLoopHarness(e){e.instrumentation?.installAiSdkWarningLogger();async function runStep(t,n){let executeStep=async r=>{let i=r?.session??t,a=stepProjection(contextStorage.getStore(),i.state),o=new GenerationSteering({abortSignal:e.abortSignal,steeringSignal:e.steeringSignal,outputStarted:turnPosition(a.read()).assistantOutputStarted});try{let e=await executeStepBody(i,o,a,n,r);return{...e,session:saveProjection(e.session,a.read())}}finally{o.dispose()}};return e.instrumentation?.runStep({environment,eveVersion,hasInput:hasStepInput(n),session:t},executeStep)??executeStep()}async function executeStepBody(t,n,r,i,a){let o=createHistoryViewPreparer({previous:e.historyView,projector:e.historyProjector});o(t.history,t.state);let s=contextStorage.getStore();s!==void 0&&!s.has(StaticModelReferenceKey)&&s.setVirtualContext(StaticModelReferenceKey,t.agent.dynamicModel===!0?null:t.agent.modelReference??null);let c,l=a?.createHandleEvent({getAttemptScope:()=>c,isFrameworkTool:e=>u.frameworkToolNames.has(e),handleEvent:e.handleEvent,turnId:activeTurnId(turnPosition(r.read()))})??e.handleEvent,u=createStep({config:e,ctx:s,emit:l,instrumentation:a,live:r,prepareHistory:o,publish:async(e,t)=>{n.beforeEvent(e),l!==void 0&&await l(e,t),(l===void 0||s===void 0)&&r.record(e)},runStep,session:t});if(e.clearOnly===!0)return clearContext(u);if(e.compactOnly===!0)return compactHistory(u);let d=await settleRuntimeWork(u,i);if(d===void 0)return{next:null,session:u.session};let f=await acceptHumanInput(u,d.input,{takeQueued:!d.waited});if(f.kind===`stop`)return f.result;let p=await prepareTurnInput(u,f.input,{consumedMessage:f.consumedMessage});if(f.opensTurn){let e=await openTurn(u,{input:[...p.ephemeral,...p.messages],message:f.message});if(e!==void 0)return e}return await admitApprovedWork(u,f.approved),runModelStep(u,{approved:f.approved,onResponse:e=>handleStepResult(u,e),generation:n,hidesHeldText:u.hasDelegatedCaller||s?.get(ScheduleIdKey)!==void 0,setAttemptScope:e=>{c=e},turn:p})}return runStep}async function clearContext(e){await e.apply(clear(e.view(),{sessionId:e.session.sessionId}));let t=discardClearedHumanInput({...e.session,state:clearMemorySessionState(e.session.state)});return{next:null,session:replaceSessionHistory(t,[])}}function hasStepInput(e){return e===void 0?!1:e.message!==void 0||(e.inputResponses?.length??0)>0}export{createToolLoopHarness};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ToolApprovalConfiguration, type ToolSet } from "ai";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ModelProfile } from "#harness/model-profile.js";
|
|
3
3
|
import type { HarnessToolDefinition } from "#harness/execute-tool.js";
|
|
4
4
|
import type { HarnessToolMap } from "#harness/types.js";
|
|
5
5
|
import type { ToolExecuteOptions } from "#tools/definition.js";
|
|
@@ -60,8 +60,7 @@ export declare function wrapToolExecute(definition: HarnessToolDefinition): ((in
|
|
|
60
60
|
export declare function buildToolSetWithProviderTools(input: {
|
|
61
61
|
readonly approvedTools?: ReadonlySet<string>;
|
|
62
62
|
readonly disabledProviderTools?: ReadonlySet<string>;
|
|
63
|
-
readonly
|
|
64
|
-
readonly modelProvider?: string;
|
|
63
|
+
readonly profile: ModelProfile;
|
|
65
64
|
readonly tools: HarnessToolMap;
|
|
66
65
|
}): Promise<ToolSet>;
|
|
67
66
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{tool}from"ai";import{isObject}from"#shared/guards.js";import{loadContext}from"#context/container.js";import{toModelSchema}from"#tools/schema.js";import{buildCallbackContext}from"#context/build-callback-context.js";import{resolveApprovalPolicy}from"#approval/definition.js";import{isApprovedToolCall,markApprovalRecheck}from"#harness/approval-recheck.js";import{isAuthorizationSignal,modelFacingAuthorizationOutput}from"#harness/authorization.js";import{toolCallModelOutput}from"#harness/tool-call-io.js";import{normalizeToolJsonOutput}from"#harness/tool-model-output.js";import{isAsyncIterable}from"#shared/async-iterable.js";import{stashToolInterrupt}from"#harness/tool-interrupts.js";import{resolveWebSearchBackend,resolveWebSearchProviderTool}from"#harness/provider-tools.js";import{iterateAsApprover,runAsApprover}from"#harness/hitl/approved-call-callers.js";const toolApprovals=new WeakMap;function buildToolSet(e){let t={},n=e.disabledProviderTools;for(let r of e.tools.values()){if(n?.has(r.name))continue;let i=r.toModelOutput,a=buildApprovalFn(r,e),o=tool({description:r.description,execute:wrapToolExecute(r),inputSchema:toModelSchema(r.inputSchema,`input`),strict:!1,outputSchema:toModelSchema(r.outputSchema,`output`),...r.execute!==void 0||i!==void 0?{toModelOutput:({output:e,toolCallId:t})=>toolCallModelOutput(r,e,t)}:{}});t[r.name]=o,r.approval!==void 0&&toolApprovals.set(o,a)}return t}function buildToolSetFromDefinitions(e){let t=new Map;for(let n of e.tools)t.has(n.name)||t.set(n.name,n);return buildToolSet({approvedTools:e.approvedTools,disabledProviderTools:e.disabledProviderTools,tools:t})}function wrapToolExecute(e){let t=e.execute;if(t!==void 0)return(n,r)=>{let i;try{i=runAsApprover(r.toolCallId,()=>t(n,r))}catch(e){return Promise.reject(e)}return isAsyncIterable(i)?normalizeToolExecuteIterable(iterateAsApprover(r.toolCallId,i),e.name,r):Promise.resolve(i).then(t=>normalizeToolExecuteOutput(t,e.name,r))}}async function*normalizeToolExecuteIterable(e,t,n){for await(let r of e)yield normalizeToolExecuteOutput(r,t,n)}function normalizeToolExecuteOutput(e,t,n){return isAuthorizationSignal(e)?(stashToolInterrupt(loadContext(),n.toolCallId,e),modelFacingAuthorizationOutput(e)):normalizeToolJsonOutput({boundary:`execute`,output:e,toolCallId:n.toolCallId,toolName:t})}async function buildToolSetWithProviderTools(e){let t=e.disabledProviderTools,n={...buildToolSet({approvedTools:e.approvedTools,disabledProviderTools:t,tools:e.tools})};for(let r of e.tools.values()){let i=r.behavior?.handling;if(i?.kind===`provider-tool`&&r.execute===void 0&&!t?.has(r.name)){let t=resolveWebSearchBackend(e.
|
|
1
|
+
import{tool}from"ai";import{isObject}from"#shared/guards.js";import{loadContext}from"#context/container.js";import{toModelSchema}from"#tools/schema.js";import{buildCallbackContext}from"#context/build-callback-context.js";import{resolveApprovalPolicy}from"#approval/definition.js";import{isApprovedToolCall,markApprovalRecheck}from"#harness/approval-recheck.js";import{isAuthorizationSignal,modelFacingAuthorizationOutput}from"#harness/authorization.js";import{toolCallModelOutput}from"#harness/tool-call-io.js";import{normalizeToolJsonOutput}from"#harness/tool-model-output.js";import{isAsyncIterable}from"#shared/async-iterable.js";import{executeWithToolStub}from"#tool-stubs/execute.js";import{stashToolInterrupt}from"#harness/tool-interrupts.js";import{resolveWebSearchBackend,resolveWebSearchProviderTool}from"#harness/provider-tools.js";import{iterateAsApprover,runAsApprover}from"#harness/hitl/approved-call-callers.js";const toolApprovals=new WeakMap;function buildToolSet(e){let t={},n=e.disabledProviderTools;for(let r of e.tools.values()){if(n?.has(r.name))continue;let i=r.toModelOutput,a=buildApprovalFn(r,e),o=tool({description:r.description,execute:wrapToolExecute(r),inputSchema:toModelSchema(r.inputSchema,`input`),strict:!1,outputSchema:toModelSchema(r.outputSchema,`output`),...r.execute!==void 0||i!==void 0?{toModelOutput:({output:e,toolCallId:t})=>toolCallModelOutput(r,e,t)}:{}});t[r.name]=o,r.approval!==void 0&&toolApprovals.set(o,a)}return t}function buildToolSetFromDefinitions(e){let t=new Map;for(let n of e.tools)t.has(n.name)||t.set(n.name,n);return buildToolSet({approvedTools:e.approvedTools,disabledProviderTools:e.disabledProviderTools,tools:t})}function wrapToolExecute(e){let t=e.execute;if(t!==void 0)return(n,r)=>{let i;try{i=runAsApprover(r.toolCallId,()=>executeWithToolStub(e.name,n,r,()=>t(n,r)))}catch(e){return Promise.reject(e)}return isAsyncIterable(i)?normalizeToolExecuteIterable(iterateAsApprover(r.toolCallId,i),e.name,r):Promise.resolve(i).then(t=>normalizeToolExecuteOutput(t,e.name,r))}}async function*normalizeToolExecuteIterable(e,t,n){for await(let r of e)yield normalizeToolExecuteOutput(r,t,n)}function normalizeToolExecuteOutput(e,t,n){return isAuthorizationSignal(e)?(stashToolInterrupt(loadContext(),n.toolCallId,e),modelFacingAuthorizationOutput(e)):normalizeToolJsonOutput({boundary:`execute`,output:e,toolCallId:n.toolCallId,toolName:t})}async function buildToolSetWithProviderTools(e){let t=e.disabledProviderTools,n={...buildToolSet({approvedTools:e.approvedTools,disabledProviderTools:t,tools:e.tools})};for(let r of e.tools.values()){let i=r.behavior?.handling;if(i?.kind===`provider-tool`&&r.execute===void 0&&!t?.has(r.name)){let t=resolveWebSearchBackend(e.profile,i.provider);t===null?delete n[r.name]:n[r.name]=await resolveWebSearchProviderTool(t)}}return n}function buildApprovalFn(e,t){return async(n,r,i,a)=>{if(e.approval===void 0)return;let o=isObject(n)?n:void 0,s={...buildCallbackContext(),abortSignal:i??new AbortController().signal,approvedTools:t.approvedTools??new Set,callId:r,toolInput:o,toolName:e.name},c=await resolveApprovalPolicy(e.approval)(a?markApprovalRecheck(s):s);return typeof c==`boolean`?c?`user-approval`:`not-applicable`:c}}async function recheckApprovedCall(e,t){let n=await buildApprovalFn(e,{approvedTools:t.approvedTools})(t.input,t.callId,t.abortSignal,!0);return n===`denied`?{denied:!0}:typeof n==`object`&&n&&n.type===`denied`?{denied:!0,reason:n.reason}:{denied:!1}}function buildToolApproval(e,t){return async({toolCall:n,messages:r})=>{let i=e[n.toolName];return i===void 0?void 0:await toolApprovals.get(i)?.(n.input,n.toolCallId,t,isApprovedToolCall(r,n.toolCallId))}}export{buildToolApproval,buildToolSet,buildToolSetFromDefinitions,buildToolSetWithProviderTools,recheckApprovedCall,wrapToolExecute};
|
|
@@ -108,6 +108,18 @@ export declare function accumulateTurnUsage(input: {
|
|
|
108
108
|
readonly turnId: string;
|
|
109
109
|
readonly usage: TokenUsageDelta | undefined;
|
|
110
110
|
}): TurnUsageState;
|
|
111
|
+
/** Folds one model call's usage into the session's turn and session totals. */
|
|
112
|
+
export declare function addTurnUsage<T extends {
|
|
113
|
+
readonly state?: SessionStateMap;
|
|
114
|
+
}>(session: T, turnId: string, usage: TokenUsageDelta | undefined): T;
|
|
115
|
+
/**
|
|
116
|
+
* Counts usage that belongs to no turn, such as a manual compaction between turns. It adds to
|
|
117
|
+
* session totals, so session limits see it, and is marked reported so a later turn's usage delta
|
|
118
|
+
* doesn't claim it.
|
|
119
|
+
*/
|
|
120
|
+
export declare function addUsageOutsideTurns<T extends {
|
|
121
|
+
readonly state?: SessionStateMap;
|
|
122
|
+
}>(session: T, usage: TokenUsageDelta | undefined): T;
|
|
111
123
|
/**
|
|
112
124
|
* Adds usage to session totals without touching the in-flight turn totals:
|
|
113
125
|
* the delegated spend a parent counts, or a run's tally of what its
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{findRuntimeUsageLimitViolation,grantRuntimeUsageLimits,remainingRuntimeUsageQuota,resolveRuntimeUsageLimits}from"#harness/session-usage-limits.js";const HARNESS_TURN_USAGE_STATE_KEY=`eve.harness.turnUsage`,REPORTED_SESSION_USAGE_STATE_KEY=`eve.harness.reportedSessionUsage`,SESSION_RUNTIME_USAGE_LIMIT_KEY=`eve.harness.sessionRuntimeTokenLimit`,ZERO_TOKEN_USAGE={cacheReadTokens:0,cacheWriteTokens:0,costUsd:0,inputTokens:0,outputTokens:0,sawCost:!1};function getTurnUsageState(e){return e?.[HARNESS_TURN_USAGE_STATE_KEY]}function getSessionTokenUsage(e){return getTurnUsageState(e.state)?.session??ZERO_TOKEN_USAGE}function getSessionUsage(e){return toUsage(getSessionTokenUsage(e))}function toUsage(e){return{cacheReadTokens:e.cacheReadTokens,cacheWriteTokens:e.cacheWriteTokens,costUsd:e.sawCost?e.costUsd:void 0,inputTokens:e.inputTokens,outputTokens:e.outputTokens}}function getSessionRuntimeUsageLimits(e){let t=e.state?.[SESSION_RUNTIME_USAGE_LIMIT_KEY];return resolveRuntimeUsageLimits({configured:configuredSessionUsageLimits(e),stored:t})}function bumpSessionRuntimeUsageLimits(e){let t=getSessionTokenUsage(e),n=grantRuntimeUsageLimits({configured:configuredSessionUsageLimits(e),usage:t});return{...e,state:{...e.state,[SESSION_RUNTIME_USAGE_LIMIT_KEY]:n}}}function getSessionRemainingUsageQuota(e){let t=getSessionTokenUsage(e),n=getSessionRuntimeUsageLimits(e);return remainingRuntimeUsageQuota({runtime:n,usage:t})}function getSessionUsageLimitViolation(e){let t=getSessionTokenUsage(e),n=getSessionRuntimeUsageLimits(e);return findRuntimeUsageLimitViolation({configured:configuredSessionUsageLimits(e),runtime:n,usage:t})}function configuredSessionUsageLimits(e){return{costUsd:e.limits?.maxTokenCostUsdPerSession,inputTokens:e.limits?.maxInputTokensPerSession,outputTokens:e.limits?.maxOutputTokensPerSession}}function takeSessionUsageDelta(e){let t=getSessionTokenUsage(e),n=e.state?.[REPORTED_SESSION_USAGE_STATE_KEY]??ZERO_TOKEN_USAGE;return{delta:{cacheReadTokens:t.cacheReadTokens-n.cacheReadTokens,cacheWriteTokens:t.cacheWriteTokens-n.cacheWriteTokens,costUsd:t.sawCost||n.sawCost?t.costUsd-n.costUsd:void 0,inputTokens:t.inputTokens-n.inputTokens,outputTokens:t.outputTokens-n.outputTokens},session:{...e,state:{...e.state,[REPORTED_SESSION_USAGE_STATE_KEY]:t}}}}function setTurnUsageState(e,t){return{...e,state:{...e.state,[HARNESS_TURN_USAGE_STATE_KEY]:t}}}function accumulateTurnUsage(e){let t=toTokenUsageDelta(e.usage),n=e.previous?.session??ZERO_TOKEN_USAGE;return{...addTokenUsage(e.previous!==void 0&&e.previous.turnId===e.turnId?e.previous:ZERO_TOKEN_USAGE,t),turnId:e.turnId,session:addTokenUsage(n,t)}}function accumulateSessionUsage(e){let t=toTokenUsageDelta(e.usage),n=e.previous??{...ZERO_TOKEN_USAGE,session:ZERO_TOKEN_USAGE,turnId:``};return{...n,session:addTokenUsage(n.session,t)}}function addTokenUsage(e,t){return{cacheReadTokens:e.cacheReadTokens+t.cacheReadTokens,cacheWriteTokens:e.cacheWriteTokens+t.cacheWriteTokens,costUsd:e.costUsd+t.costUsd,inputTokens:e.inputTokens+t.inputTokens,outputTokens:e.outputTokens+t.outputTokens,sawCost:e.sawCost||t.sawCost}}function toTokenUsageDelta(e){if(e===void 0)return ZERO_TOKEN_USAGE;let t=e.inputTokens??0,n=e.outputTokens??0;return{cacheReadTokens:e.cacheReadTokens??0,cacheWriteTokens:e.cacheWriteTokens??0,costUsd:e.costUsd??0,inputTokens:t,outputTokens:n,sawCost:e.costUsd!==void 0}}export{accumulateSessionUsage,accumulateTurnUsage,bumpSessionRuntimeUsageLimits,getSessionRemainingUsageQuota,getSessionRuntimeUsageLimits,getSessionTokenUsage,getSessionUsage,getSessionUsageLimitViolation,getTurnUsageState,setTurnUsageState,takeSessionUsageDelta,toUsage};
|
|
1
|
+
import{findRuntimeUsageLimitViolation,grantRuntimeUsageLimits,remainingRuntimeUsageQuota,resolveRuntimeUsageLimits}from"#harness/session-usage-limits.js";const HARNESS_TURN_USAGE_STATE_KEY=`eve.harness.turnUsage`,REPORTED_SESSION_USAGE_STATE_KEY=`eve.harness.reportedSessionUsage`,SESSION_RUNTIME_USAGE_LIMIT_KEY=`eve.harness.sessionRuntimeTokenLimit`,ZERO_TOKEN_USAGE={cacheReadTokens:0,cacheWriteTokens:0,costUsd:0,inputTokens:0,outputTokens:0,sawCost:!1};function getTurnUsageState(e){return e?.[HARNESS_TURN_USAGE_STATE_KEY]}function getSessionTokenUsage(e){return getTurnUsageState(e.state)?.session??ZERO_TOKEN_USAGE}function getSessionUsage(e){return toUsage(getSessionTokenUsage(e))}function toUsage(e){return{cacheReadTokens:e.cacheReadTokens,cacheWriteTokens:e.cacheWriteTokens,costUsd:e.sawCost?e.costUsd:void 0,inputTokens:e.inputTokens,outputTokens:e.outputTokens}}function getSessionRuntimeUsageLimits(e){let t=e.state?.[SESSION_RUNTIME_USAGE_LIMIT_KEY];return resolveRuntimeUsageLimits({configured:configuredSessionUsageLimits(e),stored:t})}function bumpSessionRuntimeUsageLimits(e){let t=getSessionTokenUsage(e),n=grantRuntimeUsageLimits({configured:configuredSessionUsageLimits(e),usage:t});return{...e,state:{...e.state,[SESSION_RUNTIME_USAGE_LIMIT_KEY]:n}}}function getSessionRemainingUsageQuota(e){let t=getSessionTokenUsage(e),n=getSessionRuntimeUsageLimits(e);return remainingRuntimeUsageQuota({runtime:n,usage:t})}function getSessionUsageLimitViolation(e){let t=getSessionTokenUsage(e),n=getSessionRuntimeUsageLimits(e);return findRuntimeUsageLimitViolation({configured:configuredSessionUsageLimits(e),runtime:n,usage:t})}function configuredSessionUsageLimits(e){return{costUsd:e.limits?.maxTokenCostUsdPerSession,inputTokens:e.limits?.maxInputTokensPerSession,outputTokens:e.limits?.maxOutputTokensPerSession}}function takeSessionUsageDelta(e){let t=getSessionTokenUsage(e),n=e.state?.[REPORTED_SESSION_USAGE_STATE_KEY]??ZERO_TOKEN_USAGE;return{delta:{cacheReadTokens:t.cacheReadTokens-n.cacheReadTokens,cacheWriteTokens:t.cacheWriteTokens-n.cacheWriteTokens,costUsd:t.sawCost||n.sawCost?t.costUsd-n.costUsd:void 0,inputTokens:t.inputTokens-n.inputTokens,outputTokens:t.outputTokens-n.outputTokens},session:{...e,state:{...e.state,[REPORTED_SESSION_USAGE_STATE_KEY]:t}}}}function setTurnUsageState(e,t){return{...e,state:{...e.state,[HARNESS_TURN_USAGE_STATE_KEY]:t}}}function accumulateTurnUsage(e){let t=toTokenUsageDelta(e.usage),n=e.previous?.session??ZERO_TOKEN_USAGE;return{...addTokenUsage(e.previous!==void 0&&e.previous.turnId===e.turnId?e.previous:ZERO_TOKEN_USAGE,t),turnId:e.turnId,session:addTokenUsage(n,t)}}function addTurnUsage(e,t,n){return setTurnUsageState(e,accumulateTurnUsage({previous:getTurnUsageState(e.state),turnId:t,usage:n}))}function addUsageOutsideTurns(e,t){if(t===void 0)return e;let n=setTurnUsageState(e,accumulateSessionUsage({previous:getTurnUsageState(e.state),usage:t})),r=e.state?.[REPORTED_SESSION_USAGE_STATE_KEY]??ZERO_TOKEN_USAGE;return{...n,state:{...n.state,[REPORTED_SESSION_USAGE_STATE_KEY]:addTokenUsage(r,toTokenUsageDelta(t))}}}function accumulateSessionUsage(e){let t=toTokenUsageDelta(e.usage),n=e.previous??{...ZERO_TOKEN_USAGE,session:ZERO_TOKEN_USAGE,turnId:``};return{...n,session:addTokenUsage(n.session,t)}}function addTokenUsage(e,t){return{cacheReadTokens:e.cacheReadTokens+t.cacheReadTokens,cacheWriteTokens:e.cacheWriteTokens+t.cacheWriteTokens,costUsd:e.costUsd+t.costUsd,inputTokens:e.inputTokens+t.inputTokens,outputTokens:e.outputTokens+t.outputTokens,sawCost:e.sawCost||t.sawCost}}function toTokenUsageDelta(e){if(e===void 0)return ZERO_TOKEN_USAGE;let t=e.inputTokens??0,n=e.outputTokens??0;return{cacheReadTokens:e.cacheReadTokens??0,cacheWriteTokens:e.cacheWriteTokens??0,costUsd:e.costUsd??0,inputTokens:t,outputTokens:n,sawCost:e.costUsd!==void 0}}export{accumulateSessionUsage,accumulateTurnUsage,addTurnUsage,addUsageOutsideTurns,bumpSessionRuntimeUsageLimits,getSessionRemainingUsageQuota,getSessionRuntimeUsageLimits,getSessionTokenUsage,getSessionUsage,getSessionUsageLimitViolation,getTurnUsageState,setTurnUsageState,takeSessionUsageDelta,toUsage};
|