@e2edev/e2e 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +104 -0
- package/dist/agent/act-validation.d.ts +27 -0
- package/dist/agent/act-validation.d.ts.map +1 -0
- package/dist/agent/act-validation.js +121 -0
- package/dist/agent/act-validation.js.map +1 -0
- package/dist/agent/act.d.ts +27 -0
- package/dist/agent/act.d.ts.map +1 -0
- package/dist/agent/act.js +775 -0
- package/dist/agent/act.js.map +1 -0
- package/dist/agent/actions.d.ts +66 -0
- package/dist/agent/actions.d.ts.map +1 -0
- package/dist/agent/actions.js +82 -0
- package/dist/agent/actions.js.map +1 -0
- package/dist/agent/ai-sdk.d.ts +16 -0
- package/dist/agent/ai-sdk.d.ts.map +1 -0
- package/dist/agent/ai-sdk.js +59 -0
- package/dist/agent/ai-sdk.js.map +1 -0
- package/dist/agent/call-options.d.ts +10 -0
- package/dist/agent/call-options.d.ts.map +1 -0
- package/dist/agent/call-options.js +28 -0
- package/dist/agent/call-options.js.map +1 -0
- package/dist/agent/default-agent.d.ts +22 -0
- package/dist/agent/default-agent.d.ts.map +1 -0
- package/dist/agent/default-agent.js +354 -0
- package/dist/agent/default-agent.js.map +1 -0
- package/dist/agent/error.d.ts +53 -0
- package/dist/agent/error.d.ts.map +1 -0
- package/dist/agent/error.js +94 -0
- package/dist/agent/error.js.map +1 -0
- package/dist/agent/executor.d.ts +238 -0
- package/dist/agent/executor.d.ts.map +1 -0
- package/dist/agent/executor.js +56 -0
- package/dist/agent/executor.js.map +1 -0
- package/dist/agent/index.d.ts +15 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +304 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/invocation.d.ts +194 -0
- package/dist/agent/invocation.d.ts.map +1 -0
- package/dist/agent/invocation.js +389 -0
- package/dist/agent/invocation.js.map +1 -0
- package/dist/agent/ledger.d.ts +24 -0
- package/dist/agent/ledger.d.ts.map +1 -0
- package/dist/agent/ledger.js +48 -0
- package/dist/agent/ledger.js.map +1 -0
- package/dist/agent/loop-guards.d.ts +35 -0
- package/dist/agent/loop-guards.d.ts.map +1 -0
- package/dist/agent/loop-guards.js +110 -0
- package/dist/agent/loop-guards.js.map +1 -0
- package/dist/agent/model/adapter.d.ts +97 -0
- package/dist/agent/model/adapter.d.ts.map +1 -0
- package/dist/agent/model/adapter.js +40 -0
- package/dist/agent/model/adapter.js.map +1 -0
- package/dist/agent/model/router.d.ts +36 -0
- package/dist/agent/model/router.d.ts.map +1 -0
- package/dist/agent/model/router.js +45 -0
- package/dist/agent/model/router.js.map +1 -0
- package/dist/agent/model/schema.d.ts +16 -0
- package/dist/agent/model/schema.d.ts.map +1 -0
- package/dist/agent/model/schema.js +37 -0
- package/dist/agent/model/schema.js.map +1 -0
- package/dist/agent/model/sdk.d.ts +28 -0
- package/dist/agent/model/sdk.d.ts.map +1 -0
- package/dist/agent/model/sdk.js +258 -0
- package/dist/agent/model/sdk.js.map +1 -0
- package/dist/agent/observation.d.ts +70 -0
- package/dist/agent/observation.d.ts.map +1 -0
- package/dist/agent/observation.js +174 -0
- package/dist/agent/observation.js.map +1 -0
- package/dist/agent/phases.d.ts +71 -0
- package/dist/agent/phases.d.ts.map +1 -0
- package/dist/agent/phases.js +124 -0
- package/dist/agent/phases.js.map +1 -0
- package/dist/agent/prompts.d.ts +40 -0
- package/dist/agent/prompts.d.ts.map +1 -0
- package/dist/agent/prompts.js +104 -0
- package/dist/agent/prompts.js.map +1 -0
- package/dist/agent/protocol.d.ts +31 -0
- package/dist/agent/protocol.d.ts.map +1 -0
- package/dist/agent/protocol.js +67 -0
- package/dist/agent/protocol.js.map +1 -0
- package/dist/agent/public.d.ts +12 -0
- package/dist/agent/public.d.ts.map +1 -0
- package/dist/agent/public.js +12 -0
- package/dist/agent/public.js.map +1 -0
- package/dist/agent/replay.d.ts +61 -0
- package/dist/agent/replay.d.ts.map +1 -0
- package/dist/agent/replay.js +185 -0
- package/dist/agent/replay.js.map +1 -0
- package/dist/agent/secrets.d.ts +22 -0
- package/dist/agent/secrets.d.ts.map +1 -0
- package/dist/agent/secrets.js +63 -0
- package/dist/agent/secrets.js.map +1 -0
- package/dist/agent/step-cache.d.ts +156 -0
- package/dist/agent/step-cache.d.ts.map +1 -0
- package/dist/agent/step-cache.js +301 -0
- package/dist/agent/step-cache.js.map +1 -0
- package/dist/agent/tool-loop.d.ts +51 -0
- package/dist/agent/tool-loop.d.ts.map +1 -0
- package/dist/agent/tool-loop.js +331 -0
- package/dist/agent/tool-loop.js.map +1 -0
- package/dist/agent/tool.d.ts +39 -0
- package/dist/agent/tool.d.ts.map +1 -0
- package/dist/agent/tool.js +52 -0
- package/dist/agent/tool.js.map +1 -0
- package/dist/backend/contract.d.ts +186 -0
- package/dist/backend/contract.d.ts.map +1 -0
- package/dist/backend/contract.js +65 -0
- package/dist/backend/contract.js.map +1 -0
- package/dist/backend/index.d.ts +316 -0
- package/dist/backend/index.d.ts.map +1 -0
- package/dist/backend/index.js +219 -0
- package/dist/backend/index.js.map +1 -0
- package/dist/backend/session.d.ts +23 -0
- package/dist/backend/session.d.ts.map +1 -0
- package/dist/backend/session.js +213 -0
- package/dist/backend/session.js.map +1 -0
- package/dist/backend/surface.d.ts +83 -0
- package/dist/backend/surface.d.ts.map +1 -0
- package/dist/backend/surface.js +11 -0
- package/dist/backend/surface.js.map +1 -0
- package/dist/cache/anchors.d.ts +37 -0
- package/dist/cache/anchors.d.ts.map +1 -0
- package/dist/cache/anchors.js +89 -0
- package/dist/cache/anchors.js.map +1 -0
- package/dist/cache/context.d.ts +74 -0
- package/dist/cache/context.d.ts.map +1 -0
- package/dist/cache/context.js +82 -0
- package/dist/cache/context.js.map +1 -0
- package/dist/cache/decide.d.ts +42 -0
- package/dist/cache/decide.d.ts.map +1 -0
- package/dist/cache/decide.js +47 -0
- package/dist/cache/decide.js.map +1 -0
- package/dist/cache/identity.d.ts +113 -0
- package/dist/cache/identity.d.ts.map +1 -0
- package/dist/cache/identity.js +109 -0
- package/dist/cache/identity.js.map +1 -0
- package/dist/cache/recorder.d.ts +76 -0
- package/dist/cache/recorder.d.ts.map +1 -0
- package/dist/cache/recorder.js +143 -0
- package/dist/cache/recorder.js.map +1 -0
- package/dist/cache/relocate.d.ts +69 -0
- package/dist/cache/relocate.d.ts.map +1 -0
- package/dist/cache/relocate.js +125 -0
- package/dist/cache/relocate.js.map +1 -0
- package/dist/cache/store.d.ts +68 -0
- package/dist/cache/store.d.ts.map +1 -0
- package/dist/cache/store.js +106 -0
- package/dist/cache/store.js.map +1 -0
- package/dist/cache/trace.d.ts +146 -0
- package/dist/cache/trace.d.ts.map +1 -0
- package/dist/cache/trace.js +249 -0
- package/dist/cache/trace.js.map +1 -0
- package/dist/cli/bin.d.ts +3 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +4 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/index.d.ts +4 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +108 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +6 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +101 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/collect/collect.d.ts +44 -0
- package/dist/collect/collect.d.ts.map +1 -0
- package/dist/collect/collect.js +89 -0
- package/dist/collect/collect.js.map +1 -0
- package/dist/collect/registry.d.ts +47 -0
- package/dist/collect/registry.d.ts.map +1 -0
- package/dist/collect/registry.js +262 -0
- package/dist/collect/registry.js.map +1 -0
- package/dist/collect/select.d.ts +54 -0
- package/dist/collect/select.d.ts.map +1 -0
- package/dist/collect/select.js +230 -0
- package/dist/collect/select.js.map +1 -0
- package/dist/config/agent.d.ts +91 -0
- package/dist/config/agent.d.ts.map +1 -0
- package/dist/config/agent.js +232 -0
- package/dist/config/agent.js.map +1 -0
- package/dist/config/load.d.ts +23 -0
- package/dist/config/load.d.ts.map +1 -0
- package/dist/config/load.js +75 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/resolve.d.ts +94 -0
- package/dist/config/resolve.d.ts.map +1 -0
- package/dist/config/resolve.js +500 -0
- package/dist/config/resolve.js.map +1 -0
- package/dist/config/validate.d.ts +6 -0
- package/dist/config/validate.d.ts.map +1 -0
- package/dist/config/validate.js +21 -0
- package/dist/config/validate.js.map +1 -0
- package/dist/credentials.d.ts +7 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +42 -0
- package/dist/credentials.js.map +1 -0
- package/dist/expect/async.d.ts +5 -0
- package/dist/expect/async.d.ts.map +1 -0
- package/dist/expect/async.js +186 -0
- package/dist/expect/async.js.map +1 -0
- package/dist/expect/index.d.ts +7 -0
- package/dist/expect/index.d.ts.map +1 -0
- package/dist/expect/index.js +23 -0
- package/dist/expect/index.js.map +1 -0
- package/dist/expect/values.d.ts +4 -0
- package/dist/expect/values.d.ts.map +1 -0
- package/dist/expect/values.js +108 -0
- package/dist/expect/values.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/ai-trace.d.ts +151 -0
- package/dist/internal/ai-trace.d.ts.map +1 -0
- package/dist/internal/ai-trace.js +360 -0
- package/dist/internal/ai-trace.js.map +1 -0
- package/dist/internal/brands.d.ts +9 -0
- package/dist/internal/brands.d.ts.map +1 -0
- package/dist/internal/brands.js +9 -0
- package/dist/internal/brands.js.map +1 -0
- package/dist/internal/debug.d.ts +43 -0
- package/dist/internal/debug.d.ts.map +1 -0
- package/dist/internal/debug.js +102 -0
- package/dist/internal/debug.js.map +1 -0
- package/dist/internal/errors.d.ts +98 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +212 -0
- package/dist/internal/errors.js.map +1 -0
- package/dist/internal/globs.d.ts +29 -0
- package/dist/internal/globs.d.ts.map +1 -0
- package/dist/internal/globs.js +126 -0
- package/dist/internal/globs.js.map +1 -0
- package/dist/internal/ids.d.ts +32 -0
- package/dist/internal/ids.d.ts.map +1 -0
- package/dist/internal/ids.js +124 -0
- package/dist/internal/ids.js.map +1 -0
- package/dist/internal/json-value.d.ts +15 -0
- package/dist/internal/json-value.d.ts.map +1 -0
- package/dist/internal/json-value.js +61 -0
- package/dist/internal/json-value.js.map +1 -0
- package/dist/internal/package-version.d.ts +6 -0
- package/dist/internal/package-version.d.ts.map +1 -0
- package/dist/internal/package-version.js +14 -0
- package/dist/internal/package-version.js.map +1 -0
- package/dist/internal/realm-slot.d.ts +13 -0
- package/dist/internal/realm-slot.d.ts.map +1 -0
- package/dist/internal/realm-slot.js +23 -0
- package/dist/internal/realm-slot.js.map +1 -0
- package/dist/internal/redact.d.ts +33 -0
- package/dist/internal/redact.d.ts.map +1 -0
- package/dist/internal/redact.js +56 -0
- package/dist/internal/redact.js.map +1 -0
- package/dist/internal/regexp.d.ts +10 -0
- package/dist/internal/regexp.d.ts.map +1 -0
- package/dist/internal/regexp.js +27 -0
- package/dist/internal/regexp.js.map +1 -0
- package/dist/internal/text.d.ts +39 -0
- package/dist/internal/text.d.ts.map +1 -0
- package/dist/internal/text.js +66 -0
- package/dist/internal/text.js.map +1 -0
- package/dist/internal/time.d.ts +37 -0
- package/dist/internal/time.d.ts.map +1 -0
- package/dist/internal/time.js +91 -0
- package/dist/internal/time.js.map +1 -0
- package/dist/internal/trace.d.ts +18 -0
- package/dist/internal/trace.d.ts.map +1 -0
- package/dist/internal/trace.js +46 -0
- package/dist/internal/trace.js.map +1 -0
- package/dist/internal/urls.d.ts +31 -0
- package/dist/internal/urls.d.ts.map +1 -0
- package/dist/internal/urls.js +95 -0
- package/dist/internal/urls.js.map +1 -0
- package/dist/locator/engine.d.ts +65 -0
- package/dist/locator/engine.d.ts.map +1 -0
- package/dist/locator/engine.js +164 -0
- package/dist/locator/engine.js.map +1 -0
- package/dist/locator/expression.d.ts +19 -0
- package/dist/locator/expression.d.ts.map +1 -0
- package/dist/locator/expression.js +85 -0
- package/dist/locator/expression.js.map +1 -0
- package/dist/locator/screen.d.ts +36 -0
- package/dist/locator/screen.d.ts.map +1 -0
- package/dist/locator/screen.js +281 -0
- package/dist/locator/screen.js.map +1 -0
- package/dist/report/build.d.ts +214 -0
- package/dist/report/build.d.ts.map +1 -0
- package/dist/report/build.js +346 -0
- package/dist/report/build.js.map +1 -0
- package/dist/report/code-frame.d.ts +20 -0
- package/dist/report/code-frame.d.ts.map +1 -0
- package/dist/report/code-frame.js +73 -0
- package/dist/report/code-frame.js.map +1 -0
- package/dist/report/debug-steps.d.ts +14 -0
- package/dist/report/debug-steps.d.ts.map +1 -0
- package/dist/report/debug-steps.js +85 -0
- package/dist/report/debug-steps.js.map +1 -0
- package/dist/report/list.d.ts +80 -0
- package/dist/report/list.d.ts.map +1 -0
- package/dist/report/list.js +372 -0
- package/dist/report/list.js.map +1 -0
- package/dist/report/live-status.d.ts +51 -0
- package/dist/report/live-status.d.ts.map +1 -0
- package/dist/report/live-status.js +162 -0
- package/dist/report/live-status.js.map +1 -0
- package/dist/report/write.d.ts +4 -0
- package/dist/report/write.d.ts.map +1 -0
- package/dist/report/write.js +13 -0
- package/dist/report/write.js.map +1 -0
- package/dist/run/app-process.d.ts +18 -0
- package/dist/run/app-process.d.ts.map +1 -0
- package/dist/run/app-process.js +112 -0
- package/dist/run/app-process.js.map +1 -0
- package/dist/run/artifacts.d.ts +51 -0
- package/dist/run/artifacts.d.ts.map +1 -0
- package/dist/run/artifacts.js +114 -0
- package/dist/run/artifacts.js.map +1 -0
- package/dist/run/events.d.ts +100 -0
- package/dist/run/events.d.ts.map +1 -0
- package/dist/run/events.js +59 -0
- package/dist/run/events.js.map +1 -0
- package/dist/run/execute.d.ts +119 -0
- package/dist/run/execute.d.ts.map +1 -0
- package/dist/run/execute.js +555 -0
- package/dist/run/execute.js.map +1 -0
- package/dist/run/fixtures.d.ts +40 -0
- package/dist/run/fixtures.d.ts.map +1 -0
- package/dist/run/fixtures.js +408 -0
- package/dist/run/fixtures.js.map +1 -0
- package/dist/run/in-process.d.ts +24 -0
- package/dist/run/in-process.d.ts.map +1 -0
- package/dist/run/in-process.js +120 -0
- package/dist/run/in-process.js.map +1 -0
- package/dist/run/public.d.ts +19 -0
- package/dist/run/public.d.ts.map +1 -0
- package/dist/run/public.js +11 -0
- package/dist/run/public.js.map +1 -0
- package/dist/run/realm.d.ts +52 -0
- package/dist/run/realm.d.ts.map +1 -0
- package/dist/run/realm.js +101 -0
- package/dist/run/realm.js.map +1 -0
- package/dist/run/records.d.ts +87 -0
- package/dist/run/records.d.ts.map +1 -0
- package/dist/run/records.js +3 -0
- package/dist/run/records.js.map +1 -0
- package/dist/run/retry.d.ts +18 -0
- package/dist/run/retry.d.ts.map +1 -0
- package/dist/run/retry.js +33 -0
- package/dist/run/retry.js.map +1 -0
- package/dist/run/runner.d.ts +49 -0
- package/dist/run/runner.d.ts.map +1 -0
- package/dist/run/runner.js +375 -0
- package/dist/run/runner.js.map +1 -0
- package/dist/run/scheduler.d.ts +45 -0
- package/dist/run/scheduler.d.ts.map +1 -0
- package/dist/run/scheduler.js +512 -0
- package/dist/run/scheduler.js.map +1 -0
- package/dist/run/serial.d.ts +52 -0
- package/dist/run/serial.d.ts.map +1 -0
- package/dist/run/serial.js +247 -0
- package/dist/run/serial.js.map +1 -0
- package/dist/run/sessions.d.ts +54 -0
- package/dist/run/sessions.d.ts.map +1 -0
- package/dist/run/sessions.js +221 -0
- package/dist/run/sessions.js.map +1 -0
- package/dist/run/steps.d.ts +196 -0
- package/dist/run/steps.d.ts.map +1 -0
- package/dist/run/steps.js +151 -0
- package/dist/run/steps.js.map +1 -0
- package/dist/run/unit-runner.d.ts +30 -0
- package/dist/run/unit-runner.d.ts.map +1 -0
- package/dist/run/unit-runner.js +11 -0
- package/dist/run/unit-runner.js.map +1 -0
- package/dist/run/units.d.ts +50 -0
- package/dist/run/units.d.ts.map +1 -0
- package/dist/run/units.js +103 -0
- package/dist/run/units.js.map +1 -0
- package/dist/run/worker/entry.d.ts +8 -0
- package/dist/run/worker/entry.d.ts.map +1 -0
- package/dist/run/worker/entry.js +137 -0
- package/dist/run/worker/entry.js.map +1 -0
- package/dist/run/worker/handle.d.ts +10 -0
- package/dist/run/worker/handle.d.ts.map +1 -0
- package/dist/run/worker/handle.js +74 -0
- package/dist/run/worker/handle.js.map +1 -0
- package/dist/run/worker/protocol.d.ts +129 -0
- package/dist/run/worker/protocol.d.ts.map +1 -0
- package/dist/run/worker/protocol.js +18 -0
- package/dist/run/worker/protocol.js.map +1 -0
- package/dist/run/worker/session.d.ts +69 -0
- package/dist/run/worker/session.d.ts.map +1 -0
- package/dist/run/worker/session.js +123 -0
- package/dist/run/worker/session.js.map +1 -0
- package/dist/types.d.ts +630 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One bounded agent invocation (spec 02-test-api.md, 10-determinism.md).
|
|
3
|
+
*
|
|
4
|
+
* Every `agent.*` call is a separate invocation with a fresh observation, an
|
|
5
|
+
* explicit deadline, a model-call budget, and no shared model transcript.
|
|
6
|
+
*/
|
|
7
|
+
import type { StepExecutorContext } from './executor.ts';
|
|
8
|
+
import type { JSONSchema7 } from 'ai';
|
|
9
|
+
import type { AgentCacheContext } from '../cache/context.ts';
|
|
10
|
+
import type { ResolvedConfig } from '../config/resolve.ts';
|
|
11
|
+
import type { TargetSession } from '../backend/surface.ts';
|
|
12
|
+
import type { DebugTrace } from '../internal/debug.ts';
|
|
13
|
+
import { Deadline } from '../internal/time.ts';
|
|
14
|
+
import type { LocatorEngine } from '../locator/engine.ts';
|
|
15
|
+
import type { SecretResolver } from '../locator/screen.ts';
|
|
16
|
+
import type { ArtifactSink } from '../run/fixtures.ts';
|
|
17
|
+
import type { StepRecord, StepRecorder } from '../run/steps.ts';
|
|
18
|
+
import type { VisionMode } from '../types.ts';
|
|
19
|
+
import type { StepExecutor } from './executor.ts';
|
|
20
|
+
import type { ModelRouter } from './model/router.ts';
|
|
21
|
+
import { type AgentObservation } from './observation.ts';
|
|
22
|
+
import type { ProtocolValidation } from './protocol.ts';
|
|
23
|
+
import { type PromptInput } from './prompts.ts';
|
|
24
|
+
/** Attempt-scoped services one agent fixture needs. */
|
|
25
|
+
export interface AgentContext {
|
|
26
|
+
readonly engine: LocatorEngine;
|
|
27
|
+
readonly steps: StepRecorder;
|
|
28
|
+
/** The step executor `agent.act()` dispatches to (RFC0001 layer 4). */
|
|
29
|
+
readonly executor: StepExecutor;
|
|
30
|
+
/**
|
|
31
|
+
* True when the executor came from config rather than the built-in default.
|
|
32
|
+
* A custom executor also judges `agent.assert` through the socket; the
|
|
33
|
+
* default path keeps the optimized single-judgment tier.
|
|
34
|
+
*/
|
|
35
|
+
readonly customExecutor: boolean;
|
|
36
|
+
/** Chooses the model for a call; a vision call may use a pinned one. */
|
|
37
|
+
readonly models: ModelRouter;
|
|
38
|
+
readonly config: ResolvedConfig;
|
|
39
|
+
/** The target this attempt runs on. */
|
|
40
|
+
readonly target: StepExecutorContext['target'];
|
|
41
|
+
/** Completed steps quoted as prior context; serial members see the whole group. */
|
|
42
|
+
readonly priorSteps: () => readonly StepRecord[];
|
|
43
|
+
/** Trusted project context: config.agent.context then test/group agentContext. */
|
|
44
|
+
readonly agentContext: string | undefined;
|
|
45
|
+
readonly secrets: SecretResolver;
|
|
46
|
+
/** The attempt's live redactor (SecretLedger); sees values the moment they exist. */
|
|
47
|
+
readonly redact: (text: string) => string;
|
|
48
|
+
/** Set once any secret is filled; the viewport stays pixel-tainted after. */
|
|
49
|
+
readonly taint: {
|
|
50
|
+
value: boolean;
|
|
51
|
+
};
|
|
52
|
+
readonly artifacts: ArtifactSink;
|
|
53
|
+
readonly signal: AbortSignal;
|
|
54
|
+
/** The attempt's trace cache, or undefined when caching is off. */
|
|
55
|
+
readonly cache?: AgentCacheContext;
|
|
56
|
+
/** `--debug` phase timings; absent when the caller collects none. */
|
|
57
|
+
readonly debug?: DebugTrace;
|
|
58
|
+
}
|
|
59
|
+
export interface InvocationOptions {
|
|
60
|
+
/** Public API name, e.g. `agent.assert`. */
|
|
61
|
+
readonly api: string;
|
|
62
|
+
/** Caller's instruction, e.g. the target phrase, used for debug step labels. */
|
|
63
|
+
readonly label?: string;
|
|
64
|
+
/** Short task description placed in the system message. */
|
|
65
|
+
readonly task: string;
|
|
66
|
+
readonly timeoutMs: number;
|
|
67
|
+
readonly maxModelCalls: number;
|
|
68
|
+
/**
|
|
69
|
+
* Whether masked viewport pixels travel alongside the semantic tree.
|
|
70
|
+
* Additive in every mode: the tree is always sent, and pixel evidence
|
|
71
|
+
* degrades away under taint or unprovable masking rather than failing the
|
|
72
|
+
* call. `'fallback'` behaves as `false` for the judgment methods.
|
|
73
|
+
*/
|
|
74
|
+
readonly vision: VisionMode;
|
|
75
|
+
}
|
|
76
|
+
/** Model-call accounting plus observation/ledger metrics for one invocation. */
|
|
77
|
+
export declare class Invocation {
|
|
78
|
+
private readonly runtime;
|
|
79
|
+
private readonly options;
|
|
80
|
+
readonly deadline: Deadline;
|
|
81
|
+
private readonly metrics;
|
|
82
|
+
/**
|
|
83
|
+
* Trusted system message and serialized prior-step ledger. Both are
|
|
84
|
+
* invariant for the invocation's lifetime — steps complete only between
|
|
85
|
+
* invocations — so they are computed exactly once.
|
|
86
|
+
*/
|
|
87
|
+
private readonly system;
|
|
88
|
+
private readonly ledger;
|
|
89
|
+
private inputTokens;
|
|
90
|
+
private outputTokens;
|
|
91
|
+
private peakTokensPerCall;
|
|
92
|
+
private accounting;
|
|
93
|
+
private estimatedCostUsd;
|
|
94
|
+
private observationRevision;
|
|
95
|
+
private explanation;
|
|
96
|
+
private visionInput;
|
|
97
|
+
private visionDegraded;
|
|
98
|
+
/**
|
|
99
|
+
* Whether this invocation asks for pixel evidence. Readable so a caller can
|
|
100
|
+
* tell that comparing successive observation trees is meaningless here: an
|
|
101
|
+
* animation the tree cannot see is still a change a vision call must judge.
|
|
102
|
+
*/
|
|
103
|
+
readonly pixelTier: boolean;
|
|
104
|
+
/** Byte size of the invariant system message, measured once. */
|
|
105
|
+
private readonly systemBytes;
|
|
106
|
+
constructor(runtime: AgentContext, options: InvocationOptions);
|
|
107
|
+
get session(): TargetSession;
|
|
108
|
+
/**
|
|
109
|
+
* The model this invocation talks to. It follows the pixel tier, so an
|
|
110
|
+
* escalated fallback invocation asks the pinned vision model — the reason
|
|
111
|
+
* for escalating is that the cheaper model's tree-only answer missed.
|
|
112
|
+
*/
|
|
113
|
+
private get adapter();
|
|
114
|
+
/**
|
|
115
|
+
* Whether the semantic tree reaches the model.
|
|
116
|
+
*
|
|
117
|
+
* `'only'` withholds it: a tree sent next to pixels is a cheaper path to an
|
|
118
|
+
* answer than looking at them. The observation is still captured, because the
|
|
119
|
+
* runner hit-tests and reports against it.
|
|
120
|
+
*/
|
|
121
|
+
get treeWithheld(): boolean;
|
|
122
|
+
/** Runs one phase through the shared accounting core (see phases.ts). */
|
|
123
|
+
private instrument;
|
|
124
|
+
/** Captures and redacts one fresh observation. */
|
|
125
|
+
observe(): Promise<AgentObservation>;
|
|
126
|
+
/** Captures one raw observation through the shared race-hardened path. */
|
|
127
|
+
private captureObservation;
|
|
128
|
+
/**
|
|
129
|
+
* Whether this observation should carry pixels. A tainted viewport degrades
|
|
130
|
+
* the call to tree-only input instead of failing it: the tree is still fully
|
|
131
|
+
* redacted, and only the unprovable evidence is dropped.
|
|
132
|
+
*/
|
|
133
|
+
private pixelsRequested;
|
|
134
|
+
/** Records whether requested pixels actually became model input. */
|
|
135
|
+
private recordPixels;
|
|
136
|
+
/**
|
|
137
|
+
* Records that requested pixels did not become model input.
|
|
138
|
+
*
|
|
139
|
+
* Every mode that also sends the tree degrades to it. `'only'` has nothing to
|
|
140
|
+
* degrade to: continuing would answer a question about what the screen presents
|
|
141
|
+
* from the tree the caller deliberately excluded, so it fails instead.
|
|
142
|
+
*/
|
|
143
|
+
private loseVision;
|
|
144
|
+
/**
|
|
145
|
+
* Bytes one observation may contribute to a request.
|
|
146
|
+
*
|
|
147
|
+
* `agent.maxObservationBytes` is the configured ceiling, but the per-call
|
|
148
|
+
* token limit binds first on a large screen. Deriving the budget from what the
|
|
149
|
+
* rest of the request actually costs makes a big screen truncate visibly rather
|
|
150
|
+
* than fail the adapter's pre-flight check.
|
|
151
|
+
*/
|
|
152
|
+
private observationByteBudget;
|
|
153
|
+
/**
|
|
154
|
+
* Performs one model call, retrying invalid output while budget and deadline
|
|
155
|
+
* remain. Exhaustion is MODEL_OUTPUT_INVALID, never a guessed success.
|
|
156
|
+
*/
|
|
157
|
+
ask<Value>(request: {
|
|
158
|
+
schemaName: string;
|
|
159
|
+
/** Closed response grammar, or undefined for runner-validated text mode. */
|
|
160
|
+
schema: JSONSchema7 | undefined;
|
|
161
|
+
validate: (value: unknown) => ProtocolValidation<Value>;
|
|
162
|
+
prompt: PromptInput;
|
|
163
|
+
}): Promise<Value>;
|
|
164
|
+
/** Records one rejected response payload as a child event. */
|
|
165
|
+
recordSchemaRejection(name: string): void;
|
|
166
|
+
/** Records one policy decision as a child event. */
|
|
167
|
+
recordPolicy(name: string, decision: 'allowed' | 'denied', code?: string): void;
|
|
168
|
+
/** Records one polling round as a child event. */
|
|
169
|
+
recordPoll(name: string, round: number): void;
|
|
170
|
+
/**
|
|
171
|
+
* Builds a backend operation context: `actionTimeout`, capped by this
|
|
172
|
+
* invocation's deadline. Each backend call is bounded independently so one
|
|
173
|
+
* hung observation cannot consume the invocation's whole clock.
|
|
174
|
+
*/
|
|
175
|
+
operation(): ReturnType<LocatorEngine['operation']>;
|
|
176
|
+
/** Fails when the invocation deadline has elapsed (see checkStepClock). */
|
|
177
|
+
checkDeadline(cause?: unknown): void;
|
|
178
|
+
/** True while the model-call budget and deadline still allow one more call. */
|
|
179
|
+
canAsk(): boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Records the judgment explanation that must survive a later failure, such
|
|
182
|
+
* as the one `agent.assert` reports. The observation revision is recorded by
|
|
183
|
+
* `observe()` itself.
|
|
184
|
+
*/
|
|
185
|
+
note(details: {
|
|
186
|
+
explanation?: string;
|
|
187
|
+
}): void;
|
|
188
|
+
/** Attaches metrics, provenance, and cache status to the enclosing step. */
|
|
189
|
+
finish(): void;
|
|
190
|
+
private modelInfo;
|
|
191
|
+
private consumeModelCall;
|
|
192
|
+
private recordUsage;
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=invocation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invocation.d.ts","sourceRoot":"","sources":["../../src/agent/invocation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,uBAAuB,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAIV,UAAU,EACV,YAAY,EAEb,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAiBlD,OAAO,KAAK,EAA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;KAAE,GAAG,IAAI,CAE5C;IAED,4EAA4E;IAC5E,MAAM,IAAI,IAAI,CAYb;IAED,OAAO,CAAC,SAAS;IAiBjB,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,WAAW;CAiBpB"}
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One bounded agent invocation (spec 02-test-api.md, 10-determinism.md).
|
|
3
|
+
*
|
|
4
|
+
* Every `agent.*` call is a separate invocation with a fresh observation, an
|
|
5
|
+
* explicit deadline, a model-call budget, and no shared model transcript.
|
|
6
|
+
*/
|
|
7
|
+
import { timestamp } from '../internal/ids.js';
|
|
8
|
+
import { Deadline } from '../internal/time.js';
|
|
9
|
+
import { agentTrace, observationTrace } from '../internal/trace.js';
|
|
10
|
+
import { AgentError } from './error.js';
|
|
11
|
+
import { boundedOperation, checkStepClock, instrumentPhase, recordPolicyEvent, retryingObserve, } from './phases.js';
|
|
12
|
+
import { serializeLedger } from './ledger.js';
|
|
13
|
+
import { imageTokenUpperBound, ModelOutputInvalidError, tokenUpperBound, } from './model/adapter.js';
|
|
14
|
+
import { prepareObservation } from './observation.js';
|
|
15
|
+
import { POLICY_VERSION, buildPrompt, buildSystem } from './prompts.js';
|
|
16
|
+
const MAX_OUTPUT_TOKENS = 2048;
|
|
17
|
+
/**
|
|
18
|
+
* Headroom reserved for the method instruction and parameters, in the
|
|
19
|
+
* byte-scaled units `tokenUpperBound` works in.
|
|
20
|
+
*/
|
|
21
|
+
const INSTRUCTION_RESERVE = 4_096;
|
|
22
|
+
/**
|
|
23
|
+
* Headroom reserved for one attached screenshot on a vision call, in the same
|
|
24
|
+
* units.
|
|
25
|
+
*
|
|
26
|
+
* The exact cost is only known once the observation reports its viewport, which
|
|
27
|
+
* is after the observation budget has to be fixed, so this reserves for the
|
|
28
|
+
* largest viewport worth planning for. It is derived through the same function
|
|
29
|
+
* the adapter bills with, rather than guessed, so the two cannot drift: a
|
|
30
|
+
* hard-coded 4,096 was already short of a 1440p capture at 4,784.
|
|
31
|
+
*
|
|
32
|
+
* Reserving too much only costs observation bytes when the per-call token ceiling
|
|
33
|
+
* binds, and there a truncated tree the model can see is better than the
|
|
34
|
+
* adapter's pre-flight rejecting the call outright. A viewport beyond this is
|
|
35
|
+
* still safe for that reason: the pre-flight computes the real figure.
|
|
36
|
+
*/
|
|
37
|
+
const PIXEL_RESERVE = imageTokenUpperBound({ width: 2_560, height: 1_440 });
|
|
38
|
+
/** Model-call accounting plus observation/ledger metrics for one invocation. */
|
|
39
|
+
export class Invocation {
|
|
40
|
+
runtime;
|
|
41
|
+
options;
|
|
42
|
+
deadline;
|
|
43
|
+
metrics = {
|
|
44
|
+
modelCalls: 0,
|
|
45
|
+
actionSteps: 0,
|
|
46
|
+
observationBytes: 0,
|
|
47
|
+
contextBytes: 0,
|
|
48
|
+
ledgerBytes: 0,
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Trusted system message and serialized prior-step ledger. Both are
|
|
52
|
+
* invariant for the invocation's lifetime — steps complete only between
|
|
53
|
+
* invocations — so they are computed exactly once.
|
|
54
|
+
*/
|
|
55
|
+
system;
|
|
56
|
+
ledger;
|
|
57
|
+
inputTokens = 0;
|
|
58
|
+
outputTokens = 0;
|
|
59
|
+
peakTokensPerCall = 0;
|
|
60
|
+
accounting = 'provider';
|
|
61
|
+
estimatedCostUsd;
|
|
62
|
+
observationRevision;
|
|
63
|
+
explanation;
|
|
64
|
+
visionInput = false;
|
|
65
|
+
visionDegraded;
|
|
66
|
+
/**
|
|
67
|
+
* Whether this invocation asks for pixel evidence. Readable so a caller can
|
|
68
|
+
* tell that comparing successive observation trees is meaningless here: an
|
|
69
|
+
* animation the tree cannot see is still a change a vision call must judge.
|
|
70
|
+
*/
|
|
71
|
+
pixelTier;
|
|
72
|
+
/** Byte size of the invariant system message, measured once. */
|
|
73
|
+
systemBytes;
|
|
74
|
+
constructor(runtime, options) {
|
|
75
|
+
this.runtime = runtime;
|
|
76
|
+
this.options = options;
|
|
77
|
+
this.deadline = runtime.engine.deadline(options.timeoutMs);
|
|
78
|
+
this.pixelTier = options.vision === true || options.vision === 'only';
|
|
79
|
+
this.system = buildSystem(options.task, runtime.agentContext);
|
|
80
|
+
this.systemBytes = tokenUpperBound(this.system);
|
|
81
|
+
this.ledger = serializeLedger(runtime.priorSteps(), runtime.config.limits.maxLedgerBytes);
|
|
82
|
+
agentTrace(() => `${options.api} ${JSON.stringify(options.label ?? '')} start ` +
|
|
83
|
+
`(timeout ${options.timeoutMs}ms, budget ${options.maxModelCalls} calls, ledger ${this.ledger.bytes}B)`);
|
|
84
|
+
}
|
|
85
|
+
get session() {
|
|
86
|
+
return this.runtime.engine.session;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The model this invocation talks to. It follows the pixel tier, so an
|
|
90
|
+
* escalated fallback invocation asks the pinned vision model — the reason
|
|
91
|
+
* for escalating is that the cheaper model's tree-only answer missed.
|
|
92
|
+
*/
|
|
93
|
+
get adapter() {
|
|
94
|
+
return this.runtime.models.select(this.pixelTier);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Whether the semantic tree reaches the model.
|
|
98
|
+
*
|
|
99
|
+
* `'only'` withholds it: a tree sent next to pixels is a cheaper path to an
|
|
100
|
+
* answer than looking at them. The observation is still captured, because the
|
|
101
|
+
* runner hit-tests and reports against it.
|
|
102
|
+
*/
|
|
103
|
+
get treeWithheld() {
|
|
104
|
+
return this.options.vision === 'only';
|
|
105
|
+
}
|
|
106
|
+
/** Runs one phase through the shared accounting core (see phases.ts). */
|
|
107
|
+
instrument(spec, body, detail) {
|
|
108
|
+
return instrumentPhase(this.runtime, { ...spec, api: this.options.api }, body, detail);
|
|
109
|
+
}
|
|
110
|
+
/** Captures and redacts one fresh observation. */
|
|
111
|
+
async observe() {
|
|
112
|
+
this.checkDeadline();
|
|
113
|
+
const pixels = this.pixelsRequested();
|
|
114
|
+
const observation = await this.instrument({ kind: 'observation', phase: 'agent.observe' }, async () => {
|
|
115
|
+
const raw = await this.captureObservation(pixels);
|
|
116
|
+
return prepareObservation(raw, {
|
|
117
|
+
redact: this.runtime.redact,
|
|
118
|
+
maxBytes: this.observationByteBudget(),
|
|
119
|
+
testIdAttribute: this.runtime.config.testIdAttribute,
|
|
120
|
+
});
|
|
121
|
+
}, (prepared) => ({ count: prepared.nodes.size, bytes: prepared.bytes }));
|
|
122
|
+
// Bytes the request carried, so a withheld tree reads as the zero it is.
|
|
123
|
+
if (!this.treeWithheld) {
|
|
124
|
+
this.metrics.observationBytes = Math.max(this.metrics.observationBytes, observation.bytes);
|
|
125
|
+
}
|
|
126
|
+
this.observationRevision = observation.revision;
|
|
127
|
+
if (pixels)
|
|
128
|
+
this.recordPixels(observation);
|
|
129
|
+
observationTrace(() => `${this.options.api} ${observation.revision} (${observation.nodes.size} nodes, ${observation.bytes}B${observation.truncated ? ', truncated' : ''}${describePixels(observation)})`, observation.text);
|
|
130
|
+
return observation;
|
|
131
|
+
}
|
|
132
|
+
/** Captures one raw observation through the shared race-hardened path. */
|
|
133
|
+
captureObservation(pixels) {
|
|
134
|
+
return retryingObserve({
|
|
135
|
+
observe: (operation) => this.session.observe(operation, { pixels }),
|
|
136
|
+
operation: () => this.operation(),
|
|
137
|
+
guard: (cause) => this.checkDeadline(cause),
|
|
138
|
+
signal: this.runtime.signal,
|
|
139
|
+
api: this.options.api,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Whether this observation should carry pixels. A tainted viewport degrades
|
|
144
|
+
* the call to tree-only input instead of failing it: the tree is still fully
|
|
145
|
+
* redacted, and only the unprovable evidence is dropped.
|
|
146
|
+
*/
|
|
147
|
+
pixelsRequested() {
|
|
148
|
+
if (!this.pixelTier)
|
|
149
|
+
return false;
|
|
150
|
+
if (this.runtime.taint.value) {
|
|
151
|
+
this.loseVision('PIXEL_TAINTED');
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
/** Records whether requested pixels actually became model input. */
|
|
157
|
+
recordPixels(observation) {
|
|
158
|
+
const pixels = observation.pixels;
|
|
159
|
+
if (pixels === undefined) {
|
|
160
|
+
this.loseVision(observation.pixelsWithheld ?? 'UNSUPPORTED_CAPABILITY');
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
this.visionInput = true;
|
|
164
|
+
this.metrics.pixelBytes = Math.max(this.metrics.pixelBytes ?? 0, pixels.bytes);
|
|
165
|
+
this.recordPolicy('vision.pixels', 'allowed');
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Records that requested pixels did not become model input.
|
|
169
|
+
*
|
|
170
|
+
* Every mode that also sends the tree degrades to it. `'only'` has nothing to
|
|
171
|
+
* degrade to: continuing would answer a question about what the screen presents
|
|
172
|
+
* from the tree the caller deliberately excluded, so it fails instead.
|
|
173
|
+
*/
|
|
174
|
+
loseVision(code) {
|
|
175
|
+
if (this.visionDegraded !== code) {
|
|
176
|
+
this.visionDegraded = code;
|
|
177
|
+
this.recordPolicy('vision.pixels', 'denied', code);
|
|
178
|
+
}
|
|
179
|
+
if (this.options.vision !== 'only')
|
|
180
|
+
return;
|
|
181
|
+
throw new AgentError('POLICY_DENIED', `${this.options.api} was called with vision: 'only', so the screenshot is its only ` +
|
|
182
|
+
`evidence, but pixel evidence is unavailable (${code}); it will not answer from the ` +
|
|
183
|
+
'semantic tree instead');
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Bytes one observation may contribute to a request.
|
|
187
|
+
*
|
|
188
|
+
* `agent.maxObservationBytes` is the configured ceiling, but the per-call
|
|
189
|
+
* token limit binds first on a large screen. Deriving the budget from what the
|
|
190
|
+
* rest of the request actually costs makes a big screen truncate visibly rather
|
|
191
|
+
* than fail the adapter's pre-flight check.
|
|
192
|
+
*/
|
|
193
|
+
observationByteBudget() {
|
|
194
|
+
const { config } = this.runtime;
|
|
195
|
+
// Nothing of the tree reaches the request, so the per-call token ceiling
|
|
196
|
+
// does not bind it. The configured ceiling still bounds the walk, and a
|
|
197
|
+
// fuller node map means a better hit-test for the point that comes back.
|
|
198
|
+
if (this.treeWithheld)
|
|
199
|
+
return config.agent.maxObservationBytes;
|
|
200
|
+
const overhead = this.systemBytes +
|
|
201
|
+
this.ledger.bytes +
|
|
202
|
+
INSTRUCTION_RESERVE +
|
|
203
|
+
(this.pixelTier ? PIXEL_RESERVE : 0);
|
|
204
|
+
const withinTokenCeiling = Math.max(1_024, config.limits.maxModelTokensPerCall - overhead);
|
|
205
|
+
return Math.min(config.agent.maxObservationBytes, withinTokenCeiling);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Performs one model call, retrying invalid output while budget and deadline
|
|
209
|
+
* remain. Exhaustion is MODEL_OUTPUT_INVALID, never a guessed success.
|
|
210
|
+
*/
|
|
211
|
+
async ask(request) {
|
|
212
|
+
let repair = request.prompt.repair;
|
|
213
|
+
this.metrics.contextBytes = tokenUpperBound(this.runtime.agentContext ?? '');
|
|
214
|
+
this.metrics.ledgerBytes = this.ledger.bytes;
|
|
215
|
+
for (;;) {
|
|
216
|
+
this.checkDeadline();
|
|
217
|
+
this.consumeModelCall();
|
|
218
|
+
const prompt = buildPrompt({
|
|
219
|
+
...request.prompt,
|
|
220
|
+
...(this.treeWithheld ? { withholdTree: true } : {}),
|
|
221
|
+
ledger: this.ledger.text,
|
|
222
|
+
...(repair === undefined ? {} : { repair }),
|
|
223
|
+
});
|
|
224
|
+
// Pixels travel with the observation they were captured for, so the
|
|
225
|
+
// image and the tree in one request always describe one revision.
|
|
226
|
+
const images = imagesFor(request.prompt.observation);
|
|
227
|
+
try {
|
|
228
|
+
const result = await this.instrument({ kind: 'model', phase: 'agent.model', name: request.schemaName }, () => this.adapter.generate({
|
|
229
|
+
system: this.system,
|
|
230
|
+
prompt,
|
|
231
|
+
...(images === undefined ? {} : { images }),
|
|
232
|
+
schemaName: request.schemaName,
|
|
233
|
+
schema: request.schema,
|
|
234
|
+
validate: request.validate,
|
|
235
|
+
maxOutputTokens: MAX_OUTPUT_TOKENS,
|
|
236
|
+
maxInputTokens: this.runtime.config.limits.maxModelTokensPerCall,
|
|
237
|
+
signal: this.runtime.signal,
|
|
238
|
+
timeoutMs: Math.max(1, this.deadline.remaining()),
|
|
239
|
+
}), (generated) => ({
|
|
240
|
+
count: generated.usage.inputTokens + generated.usage.outputTokens,
|
|
241
|
+
}));
|
|
242
|
+
this.recordUsage(result.usage);
|
|
243
|
+
return result.value;
|
|
244
|
+
}
|
|
245
|
+
catch (cause) {
|
|
246
|
+
if (cause instanceof ModelOutputInvalidError &&
|
|
247
|
+
this.metrics.modelCalls < this.options.maxModelCalls &&
|
|
248
|
+
!this.deadline.expired()) {
|
|
249
|
+
this.recordSchemaRejection(request.schemaName);
|
|
250
|
+
agentTrace(() => `${this.options.api} repair round: ${cause.explanation}`);
|
|
251
|
+
repair = {
|
|
252
|
+
issue: cause.explanation,
|
|
253
|
+
rawText: cause.rawText,
|
|
254
|
+
};
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
throw cause;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/** Records one rejected response payload as a child event. */
|
|
262
|
+
recordSchemaRejection(name) {
|
|
263
|
+
this.runtime.steps.recordEvent({
|
|
264
|
+
kind: 'schema',
|
|
265
|
+
startedAt: timestamp(),
|
|
266
|
+
durationMs: 0,
|
|
267
|
+
status: 'failed',
|
|
268
|
+
name,
|
|
269
|
+
code: 'MODEL_OUTPUT_INVALID',
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/** Records one policy decision as a child event. */
|
|
273
|
+
recordPolicy(name, decision, code) {
|
|
274
|
+
recordPolicyEvent(this.runtime.steps, name, decision, code);
|
|
275
|
+
}
|
|
276
|
+
/** Records one polling round as a child event. */
|
|
277
|
+
recordPoll(name, round) {
|
|
278
|
+
this.runtime.steps.recordEvent({
|
|
279
|
+
kind: 'poll',
|
|
280
|
+
startedAt: timestamp(),
|
|
281
|
+
durationMs: 0,
|
|
282
|
+
status: 'passed',
|
|
283
|
+
name,
|
|
284
|
+
count: round,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Builds a backend operation context: `actionTimeout`, capped by this
|
|
289
|
+
* invocation's deadline. Each backend call is bounded independently so one
|
|
290
|
+
* hung observation cannot consume the invocation's whole clock.
|
|
291
|
+
*/
|
|
292
|
+
operation() {
|
|
293
|
+
return boundedOperation(this.runtime.engine, this.runtime.config.actionTimeout, this.deadline);
|
|
294
|
+
}
|
|
295
|
+
/** Fails when the invocation deadline has elapsed (see checkStepClock). */
|
|
296
|
+
checkDeadline(cause) {
|
|
297
|
+
checkStepClock({
|
|
298
|
+
signal: this.runtime.signal,
|
|
299
|
+
deadline: this.deadline,
|
|
300
|
+
api: this.options.api,
|
|
301
|
+
timeoutMs: this.options.timeoutMs,
|
|
302
|
+
...(cause === undefined ? {} : { cause }),
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
/** True while the model-call budget and deadline still allow one more call. */
|
|
306
|
+
canAsk() {
|
|
307
|
+
return this.metrics.modelCalls < this.options.maxModelCalls && !this.deadline.expired();
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Records the judgment explanation that must survive a later failure, such
|
|
311
|
+
* as the one `agent.assert` reports. The observation revision is recorded by
|
|
312
|
+
* `observe()` itself.
|
|
313
|
+
*/
|
|
314
|
+
note(details) {
|
|
315
|
+
if (details.explanation !== undefined)
|
|
316
|
+
this.explanation = details.explanation;
|
|
317
|
+
}
|
|
318
|
+
/** Attaches metrics, provenance, and cache status to the enclosing step. */
|
|
319
|
+
finish() {
|
|
320
|
+
this.runtime.steps.attachAgentDetails({
|
|
321
|
+
metrics: { ...this.metrics },
|
|
322
|
+
...(this.metrics.modelCalls > 0 ? { model: this.modelInfo() } : {}),
|
|
323
|
+
...(this.observationRevision !== undefined
|
|
324
|
+
? { observationRevision: this.observationRevision }
|
|
325
|
+
: {}),
|
|
326
|
+
...(this.explanation !== undefined ? { explanation: this.explanation } : {}),
|
|
327
|
+
...(this.visionInput ? { visionInput: true } : {}),
|
|
328
|
+
...(this.treeWithheld ? { visionOnly: true } : {}),
|
|
329
|
+
...(this.visionDegraded !== undefined ? { visionDegraded: this.visionDegraded } : {}),
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
modelInfo() {
|
|
333
|
+
const provenance = this.adapter.provenance;
|
|
334
|
+
return {
|
|
335
|
+
provider: provenance.provider,
|
|
336
|
+
model: provenance.model,
|
|
337
|
+
endpoint: provenance.endpoint,
|
|
338
|
+
adapterVersion: provenance.adapterVersion,
|
|
339
|
+
policyVersion: POLICY_VERSION,
|
|
340
|
+
calls: this.metrics.modelCalls,
|
|
341
|
+
tokenAccounting: this.accounting,
|
|
342
|
+
peakTokensPerCall: this.peakTokensPerCall,
|
|
343
|
+
inputTokens: this.inputTokens,
|
|
344
|
+
outputTokens: this.outputTokens,
|
|
345
|
+
...(this.estimatedCostUsd !== undefined ? { estimatedCostUsd: this.estimatedCostUsd } : {}),
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
consumeModelCall() {
|
|
349
|
+
if (this.metrics.modelCalls >= this.options.maxModelCalls) {
|
|
350
|
+
throw new AgentError('STEP_BUDGET_EXHAUSTED', `${this.options.api} exhausted its model-call budget of ${this.options.maxModelCalls}`);
|
|
351
|
+
}
|
|
352
|
+
this.metrics.modelCalls += 1;
|
|
353
|
+
}
|
|
354
|
+
recordUsage(usage) {
|
|
355
|
+
this.inputTokens += usage.inputTokens;
|
|
356
|
+
this.outputTokens += usage.outputTokens;
|
|
357
|
+
this.peakTokensPerCall = Math.max(this.peakTokensPerCall, usage.inputTokens + usage.outputTokens);
|
|
358
|
+
if (usage.accounting === 'adapter-upper-bound')
|
|
359
|
+
this.accounting = 'adapter-upper-bound';
|
|
360
|
+
if (usage.estimatedCostUsd !== undefined) {
|
|
361
|
+
this.estimatedCostUsd = (this.estimatedCostUsd ?? 0) + usage.estimatedCostUsd;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/** Trace fragment describing what pixel evidence an observation carried. */
|
|
366
|
+
function describePixels(observation) {
|
|
367
|
+
if (observation.pixels !== undefined) {
|
|
368
|
+
const { width, height, bytes, maskedRegionCount } = observation.pixels;
|
|
369
|
+
return `, pixels ${width}x${height} ${bytes}B, ${maskedRegionCount} masked`;
|
|
370
|
+
}
|
|
371
|
+
return observation.pixelsWithheld === undefined
|
|
372
|
+
? ''
|
|
373
|
+
: `, pixels withheld (${observation.pixelsWithheld})`;
|
|
374
|
+
}
|
|
375
|
+
/** Image parts for one request, derived from the observation it quotes. */
|
|
376
|
+
function imagesFor(observation) {
|
|
377
|
+
const pixels = observation?.pixels;
|
|
378
|
+
if (pixels === undefined)
|
|
379
|
+
return undefined;
|
|
380
|
+
return [
|
|
381
|
+
{
|
|
382
|
+
data: pixels.data,
|
|
383
|
+
mediaType: pixels.mediaType,
|
|
384
|
+
width: pixels.width,
|
|
385
|
+
height: pixels.height,
|
|
386
|
+
},
|
|
387
|
+
];
|
|
388
|
+
}
|
|
389
|
+
//# sourceMappingURL=invocation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invocation.js","sourceRoot":"","sources":["../../src/agent/invocation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAapE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,eAAe,GAEhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAsB,MA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IAAI,KAAK,CAAC,UAAU,KAAK,qBAAqB;YAAE,IAAI,CAAC,UAAU,GAAG,qBAAqB,CAAC;QACxF,IAAI,KAAK,CAAC,gBAAgB,KAAK,SAAS,EAAE,CAAC;YACzC,IAAI,CAAC,gBAAgB,GAAG,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,gBAAgB,CAAC;QAChF,CAAC;IACH,CAAC;CACF;AAED,4EAA4E;AAC5E,SAAS,cAAc,CAAC,WAA6B;IACnD,IAAI,WAAW,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC;QACvE,OAAO,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,MAAM,iBAAiB,SAAS,CAAC;IAC9E,CAAC;IACD,OAAO,WAAW,CAAC,cAAc,KAAK,SAAS;QAC7C,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,sBAAsB,WAAW,CAAC,cAAc,GAAG,CAAC;AAC1D,CAAC;AAED,2EAA2E;AAC3E,SAAS,SAAS,CAAC,WAAyC;IAC1D,MAAM,MAAM,GAAG,WAAW,EAAE,MAAM,CAAC;IACnC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC3C,OAAO;QACL;YACE,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prior-step context for agent prompts (spec 10-determinism.md).
|
|
3
|
+
*
|
|
4
|
+
* The ledger is not stored anywhere: it is derived on demand from the step
|
|
5
|
+
* timeline the run layer already records, so there is exactly one account of
|
|
6
|
+
* what happened. Serial-group members see each other's prior steps through the
|
|
7
|
+
* shared accumulator the run layer maintains; independent tests never do.
|
|
8
|
+
* Entries are untrusted quoted evidence and never carry policy authority.
|
|
9
|
+
*/
|
|
10
|
+
import type { StepRecord } from '../run/steps.ts';
|
|
11
|
+
/** Maximum size of one handoff, before ledger-wide compaction. */
|
|
12
|
+
export declare const MAX_HANDOFF_BYTES = 700;
|
|
13
|
+
export interface LedgerContext {
|
|
14
|
+
readonly text: string;
|
|
15
|
+
readonly bytes: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Serializes completed steps as prompt context: newest entries first until the
|
|
19
|
+
* byte budget is reached, then emitted chronologically with the dropped count
|
|
20
|
+
* prepended. Labels and handoffs are sanitized and bounded here, at the trust
|
|
21
|
+
* boundary where they become model input.
|
|
22
|
+
*/
|
|
23
|
+
export declare function serializeLedger(steps: readonly StepRecord[], maxBytes: number): LedgerContext;
|
|
24
|
+
//# sourceMappingURL=ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../src/agent/ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,kEAAkE;AAClE,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAIrC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,aAAa,CAiB7F"}
|