@ap3x/browser-agent 0.1.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 +34 -0
- package/dist/agent/agent.d.ts +160 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/backend.d.ts +38 -0
- package/dist/agent/backend.d.ts.map +1 -0
- package/dist/agent/captcha-watchdog.d.ts +31 -0
- package/dist/agent/captcha-watchdog.d.ts.map +1 -0
- package/dist/agent/context-builder.d.ts +24 -0
- package/dist/agent/context-builder.d.ts.map +1 -0
- package/dist/agent/event-stream.d.ts +104 -0
- package/dist/agent/event-stream.d.ts.map +1 -0
- package/dist/agent/executor.d.ts +37 -0
- package/dist/agent/executor.d.ts.map +1 -0
- package/dist/agent/gif.d.ts +23 -0
- package/dist/agent/gif.d.ts.map +1 -0
- package/dist/agent/history.d.ts +89 -0
- package/dist/agent/history.d.ts.map +1 -0
- package/dist/agent/judge.d.ts +36 -0
- package/dist/agent/judge.d.ts.map +1 -0
- package/dist/agent/message-manager.d.ts +94 -0
- package/dist/agent/message-manager.d.ts.map +1 -0
- package/dist/agent/output-schema.d.ts +26 -0
- package/dist/agent/output-schema.d.ts.map +1 -0
- package/dist/agent/png-decode.d.ts +9 -0
- package/dist/agent/png-decode.d.ts.map +1 -0
- package/dist/agent/rematch.d.ts +26 -0
- package/dist/agent/rematch.d.ts.map +1 -0
- package/dist/agent/replay.d.ts +155 -0
- package/dist/agent/replay.d.ts.map +1 -0
- package/dist/agent/step-loop.d.ts +124 -0
- package/dist/agent/step-loop.d.ts.map +1 -0
- package/dist/agent/variable-detector.d.ts +19 -0
- package/dist/agent/variable-detector.d.ts.map +1 -0
- package/dist/agent/video.d.ts +12 -0
- package/dist/agent/video.d.ts.map +1 -0
- package/dist/chunk-32HNRAQS.js +82 -0
- package/dist/chunk-UZALZUEE.js +2907 -0
- package/dist/filesystem/external-read.d.ts +18 -0
- package/dist/filesystem/external-read.d.ts.map +1 -0
- package/dist/filesystem/file-system.d.ts +61 -0
- package/dist/filesystem/file-system.d.ts.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1070 -0
- package/dist/mcp/bin.d.ts +3 -0
- package/dist/mcp/bin.d.ts.map +1 -0
- package/dist/mcp/bin.js +19 -0
- package/dist/mcp/client.d.ts +45 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/log.d.ts +6 -0
- package/dist/mcp/log.d.ts.map +1 -0
- package/dist/mcp/server.d.ts +36 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/observability/logger.d.ts +25 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/testing.d.ts +37 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +18 -0
- package/dist/tools/actions.d.ts +9 -0
- package/dist/tools/actions.d.ts.map +1 -0
- package/dist/tools/registry.d.ts +125 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/sensitive.d.ts +59 -0
- package/dist/tools/sensitive.d.ts.map +1 -0
- package/dist/tools/types.d.ts +117 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/usage/ledger.d.ts +27 -0
- package/dist/usage/ledger.d.ts.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Api, type Model, type ProviderStreamOptions, type Usage } from "@ap3x/ai";
|
|
2
|
+
import { type Static } from "@sinclair/typebox";
|
|
3
|
+
import type { AgentHistoryList } from "./history";
|
|
4
|
+
export declare const JudgementResultSchema: import("@sinclair/typebox").TObject<{
|
|
5
|
+
reasoning: import("@sinclair/typebox").TString;
|
|
6
|
+
verdict: import("@sinclair/typebox").TBoolean;
|
|
7
|
+
failureReason: import("@sinclair/typebox").TString;
|
|
8
|
+
impossibleTask: import("@sinclair/typebox").TBoolean;
|
|
9
|
+
reachedCaptcha: import("@sinclair/typebox").TBoolean;
|
|
10
|
+
}>;
|
|
11
|
+
/** The judge's structured verdict on a finished run. */
|
|
12
|
+
export type JudgementResult = Static<typeof JudgementResultSchema>;
|
|
13
|
+
export interface JudgeOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Ground-truth criteria or expected answer, when known. Takes precedence
|
|
16
|
+
* over every other signal the judge weighs.
|
|
17
|
+
*/
|
|
18
|
+
groundTruth?: string;
|
|
19
|
+
/** Attach up to this many of the run's most recent screenshots (default 10). */
|
|
20
|
+
maxImages?: number;
|
|
21
|
+
/** Attach screenshots at all (default true). */
|
|
22
|
+
vision?: boolean;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
/**
|
|
25
|
+
* Per-call overrides (apiKey/headers/etc.) merged into the judge's
|
|
26
|
+
* `generateObject` call — same seam as `AgentOptions.llm.streamOptions`.
|
|
27
|
+
*/
|
|
28
|
+
streamOptions?: ProviderStreamOptions;
|
|
29
|
+
}
|
|
30
|
+
export interface JudgeResult {
|
|
31
|
+
judgement: JudgementResult;
|
|
32
|
+
usage: Usage;
|
|
33
|
+
}
|
|
34
|
+
/** Evaluate a completed run. Never throws for a "the task failed" outcome — only for LLM/transport errors. */
|
|
35
|
+
export declare function judgeRun(model: Model<Api>, task: string, history: AgentHistoryList, options?: JudgeOptions): Promise<JudgeResult>;
|
|
36
|
+
//# sourceMappingURL=judge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"judge.d.ts","sourceRoot":"","sources":["../../src/agent/judge.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,GAAG,EAER,KAAK,KAAK,EACV,KAAK,qBAAqB,EAE1B,KAAK,KAAK,EAEX,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAElD,eAAO,MAAM,qBAAqB;;;;;;EAMhC,CAAC;AAEH,wDAAwD;AACxD,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEnE,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE,qBAAqB,CAAC;CACvC;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,eAAe,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;CACd;AAmED,8GAA8G;AAC9G,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,EACzB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,WAAW,CAAC,CA4BtB"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Message } from "@ap3x/ai";
|
|
2
|
+
import type { BrowserStateSummary } from "@ap3x/browser";
|
|
3
|
+
import { type SensitiveData } from "../tools/sensitive";
|
|
4
|
+
import { type ActionResult } from "../tools/types";
|
|
5
|
+
import type { AgentOutput } from "./output-schema";
|
|
6
|
+
/** Compaction gates (design/04b §4.2): BOTH must hold to compact. */
|
|
7
|
+
export declare const COMPACT_EVERY_N_STEPS = 25;
|
|
8
|
+
export declare const COMPACT_TRIGGER_CHARS = 40000;
|
|
9
|
+
/**
|
|
10
|
+
* One rendered history entry. `error` and `systemMessage` are mutually exclusive
|
|
11
|
+
* (a step is either a normal turn or a synthetic system note).
|
|
12
|
+
*/
|
|
13
|
+
export interface HistoryItem {
|
|
14
|
+
stepNumber?: number;
|
|
15
|
+
evaluationPreviousGoal?: string;
|
|
16
|
+
memory?: string;
|
|
17
|
+
nextGoal?: string;
|
|
18
|
+
/** Persistent per-result lines (longTermMemory / extractedContent / error text). */
|
|
19
|
+
actionResults?: string[];
|
|
20
|
+
error?: string;
|
|
21
|
+
systemMessage?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface MessageManagerOptions {
|
|
24
|
+
systemPrompt: string;
|
|
25
|
+
task: string;
|
|
26
|
+
sensitiveData?: SensitiveData;
|
|
27
|
+
fileSystemDescribe?: () => string;
|
|
28
|
+
todoContents?: () => string;
|
|
29
|
+
availableFilePaths?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export interface BuildMessagesOptions {
|
|
32
|
+
stepNumber: number;
|
|
33
|
+
maxSteps: number;
|
|
34
|
+
/** Transient nudges appended as context messages this step. */
|
|
35
|
+
nudges?: string[];
|
|
36
|
+
/** Attach the screenshot as an image part (vision on). */
|
|
37
|
+
attachScreenshot?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare class MessageManager {
|
|
40
|
+
private readonly systemPrompt;
|
|
41
|
+
private readonly task;
|
|
42
|
+
private readonly sensitiveData?;
|
|
43
|
+
private readonly fileSystemDescribe?;
|
|
44
|
+
private readonly todoContents?;
|
|
45
|
+
private readonly availableFilePaths;
|
|
46
|
+
private readonly items;
|
|
47
|
+
private readState;
|
|
48
|
+
private compactedMemory?;
|
|
49
|
+
private compactionCountValue;
|
|
50
|
+
private lastCompactionStep;
|
|
51
|
+
/**
|
|
52
|
+
* One-shot: set when a step's result asked for the screenshot to be shown
|
|
53
|
+
* next (the on-demand `screenshot` action's `metadata.includeScreenshot`,
|
|
54
|
+
* design/04b §4.3 — "the message manager attaches the *next* state
|
|
55
|
+
* screenshot even in use_vision='auto'"). Consumed by the following
|
|
56
|
+
* `buildMessages` call regardless of the caller's own `attachScreenshot`.
|
|
57
|
+
*/
|
|
58
|
+
private pendingScreenshotRequest;
|
|
59
|
+
/** The raw state text built for the most recent step (kept for history debugging). */
|
|
60
|
+
private lastStateText;
|
|
61
|
+
constructor(options: MessageManagerOptions);
|
|
62
|
+
get compactionCount(): number;
|
|
63
|
+
get stateMessageText(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Fold a completed step's output + results into the running history (the RECORD
|
|
66
|
+
* half of the loop as the LLM sees it). Once-only content becomes the next
|
|
67
|
+
* prompt's one-shot <read_state>; everything else becomes a persistent line.
|
|
68
|
+
*/
|
|
69
|
+
recordStep(stepNumber: number, output: AgentOutput | undefined, results: ActionResult[]): void;
|
|
70
|
+
/** Record a synthetic system note (e.g. "Failed to complete task in max steps"). */
|
|
71
|
+
recordSystemNote(stepNumber: number, message: string): void;
|
|
72
|
+
/** Full rendered history text (used for both the prompt and the compaction gate). */
|
|
73
|
+
private renderHistory;
|
|
74
|
+
/**
|
|
75
|
+
* Compaction (design/04b §4.2). Fires only when BOTH gates hold:
|
|
76
|
+
* `stepNumber - lastCompactionStep >= 25` AND rendered history `>= 40000` chars.
|
|
77
|
+
* Summarizes the dropped items into `compactedMemory`, keeps the first item and
|
|
78
|
+
* the last 6, and bumps the compaction count. Returns whether it fired.
|
|
79
|
+
*
|
|
80
|
+
* ponytail: deterministic join-summary rather than a summarizer LLM call — the
|
|
81
|
+
* gate + keep-window is the load-bearing behavior; upgrade path is to pass a
|
|
82
|
+
* compaction model and summarize `dropped` instead of joining their memories.
|
|
83
|
+
*/
|
|
84
|
+
maybeCompact(stepNumber: number): boolean;
|
|
85
|
+
/** Assemble `[system, state, ...context]` for one step. */
|
|
86
|
+
buildMessages(state: BrowserStateSummary, options: BuildMessagesOptions): Message[];
|
|
87
|
+
private buildStateMessage;
|
|
88
|
+
private buildStateText;
|
|
89
|
+
private buildAgentState;
|
|
90
|
+
private buildBrowserState;
|
|
91
|
+
}
|
|
92
|
+
/** True when a result set completed the task (a terminal `done`). */
|
|
93
|
+
export declare function resultsAreDone(results: ActionResult[]): boolean;
|
|
94
|
+
//# sourceMappingURL=message-manager.d.ts.map
|
|
@@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Ae;IAsBvB,OAAO,CAAC,iBAAiB;CAc1B;AAMD,qEAAqE;AACrE,wBAAgB,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,CAG/D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type TSchema } from "@sinclair/typebox";
|
|
2
|
+
/** Which brain fields the output schema carries. */
|
|
3
|
+
export type OutputVariant = "thinking" | "noThinking" | "flash";
|
|
4
|
+
/**
|
|
5
|
+
* Build the AgentOutput schema for a step. `actionUnion` is the registry's
|
|
6
|
+
* per-page union of single-key `{ actionName: params }` objects; it becomes the
|
|
7
|
+
* item type of the required, non-empty `action` array.
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildAgentOutputSchema(actionUnion: TSchema, variant: OutputVariant): TSchema;
|
|
10
|
+
/** One single-key action element as parsed out of {@link AgentOutput.action}. */
|
|
11
|
+
export interface ParsedAction {
|
|
12
|
+
name: string;
|
|
13
|
+
params: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
/** The parsed LLM output the step loop consumes (variant-agnostic superset). */
|
|
16
|
+
export interface AgentOutput {
|
|
17
|
+
thinking?: string;
|
|
18
|
+
evaluation_previous_goal?: string;
|
|
19
|
+
memory?: string;
|
|
20
|
+
next_goal?: string;
|
|
21
|
+
/** Non-empty list of single-key `{ name: params }` objects. */
|
|
22
|
+
action: Array<Record<string, unknown>>;
|
|
23
|
+
}
|
|
24
|
+
/** Split a single-key action object into `{ name, params }`. */
|
|
25
|
+
export declare function parseAction(entry: Record<string, unknown>): ParsedAction | undefined;
|
|
26
|
+
//# sourceMappingURL=output-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-schema.d.ts","sourceRoot":"","sources":["../../src/agent/output-schema.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,OAAO,EAAQ,MAAM,mBAAmB,CAAC;AAEvD,oDAAoD;AACpD,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,YAAY,GAAG,OAAO,CAAC;AAEhE;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAwB5F;AAED,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,gFAAgF;AAChF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACxC;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,GAAG,SAAS,CAMpF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface DecodedImage {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
/** width*height*4 bytes, RGBA, row-major. */
|
|
5
|
+
rgba: Uint8Array;
|
|
6
|
+
}
|
|
7
|
+
/** Decode a base64 PNG data string. Returns `undefined` for anything unsupported. */
|
|
8
|
+
export declare function decodePngBase64(base64: string): DecodedImage | undefined;
|
|
9
|
+
//# sourceMappingURL=png-decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"png-decode.d.ts","sourceRoot":"","sources":["../../src/agent/png-decode.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,IAAI,EAAE,UAAU,CAAC;CAClB;AAYD,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAMxE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type BackendNodeId, type DOMInteractedElement, type DomSelectorMap, type EnhancedDOMTreeNode, MatchLevel } from "@ap3x/browser";
|
|
2
|
+
export interface RematchSuccess {
|
|
3
|
+
level: MatchLevel;
|
|
4
|
+
backendNodeId: BackendNodeId;
|
|
5
|
+
node: EnhancedDOMTreeNode;
|
|
6
|
+
}
|
|
7
|
+
export interface RematchFailure {
|
|
8
|
+
level: undefined;
|
|
9
|
+
diagnostic: string;
|
|
10
|
+
}
|
|
11
|
+
export type RematchResult = RematchSuccess | RematchFailure;
|
|
12
|
+
/**
|
|
13
|
+
* Re-locate a recorded element in the current (live) selector map. Returns the
|
|
14
|
+
* live backendNodeId + match level on success, or a diagnostic on total miss.
|
|
15
|
+
*/
|
|
16
|
+
export declare function rematchElement(recorded: DOMInteractedElement, selectorMap: DomSelectorMap): RematchResult;
|
|
17
|
+
/**
|
|
18
|
+
* Heuristic: does this recorded element look like it OPENS a menu/dropdown
|
|
19
|
+
* (aria-haspopup / aria-expanded / a menu-ish class)? Used by the replay
|
|
20
|
+
* engine's menu-reopen fallback (design/04b §4.1) — when a menu-item element
|
|
21
|
+
* can't be found, re-clicking the opener before retrying often fixes it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function looksLikeMenuOpener(el: DOMInteractedElement): boolean;
|
|
24
|
+
/** Heuristic: does this recorded element look like a menu ITEM (as opposed to the opener)? */
|
|
25
|
+
export declare function looksLikeMenuItem(el: DOMInteractedElement): boolean;
|
|
26
|
+
//# sourceMappingURL=rematch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rematch.d.ts","sourceRoot":"","sources":["../../src/agent/rematch.ts"],"names":[],"mappings":"AAuBA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,UAAU,EAKX,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,UAAU,CAAC;IAClB,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,EAAE,mBAAmB,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,SAAS,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG,cAAc,CAAC;AA8C5D;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,oBAAoB,EAC9B,WAAW,EAAE,cAAc,GAC1B,aAAa,CA0Df;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,oBAAoB,GAAG,OAAO,CAKrE;AAED,8FAA8F;AAC9F,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,oBAAoB,GAAG,OAAO,CAKnE"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { type Api, type Model, type ProviderStreamOptions } from "@ap3x/ai";
|
|
2
|
+
import type { BrowserDriver, BrowserSession, MatchLevel } from "@ap3x/browser";
|
|
3
|
+
import type { FileSystem } from "../filesystem/file-system";
|
|
4
|
+
import { type Logger } from "../observability/logger";
|
|
5
|
+
import type { ExtractionLlm, Registry } from "../tools/registry";
|
|
6
|
+
import { type ActionResult } from "../tools/types";
|
|
7
|
+
import { AgentHistoryList } from "./history";
|
|
8
|
+
import { type DetectedVariable } from "./variable-detector";
|
|
9
|
+
/** The on-disk shape of a saved run (design/04b §4.1 `AgentHistory.json`). */
|
|
10
|
+
export declare const HistoryFileSchema: import("@sinclair/typebox").TObject<{
|
|
11
|
+
version: import("@sinclair/typebox").TLiteral<1>;
|
|
12
|
+
history: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
13
|
+
modelOutput: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
14
|
+
thinking: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
15
|
+
evaluation_previous_goal: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
16
|
+
memory: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
17
|
+
next_goal: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
18
|
+
action: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>;
|
|
19
|
+
}>>;
|
|
20
|
+
result: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
21
|
+
isDone: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
22
|
+
success: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
23
|
+
error: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
24
|
+
extractedContent: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
25
|
+
includeExtractedContentOnlyOnce: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
26
|
+
longTermMemory: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
27
|
+
attachments: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
|
|
28
|
+
images: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
29
|
+
name: import("@sinclair/typebox").TString;
|
|
30
|
+
data: import("@sinclair/typebox").TString;
|
|
31
|
+
}>>>;
|
|
32
|
+
metadata: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>;
|
|
33
|
+
includeInMemory: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
34
|
+
}>>;
|
|
35
|
+
state: import("@sinclair/typebox").TObject<{
|
|
36
|
+
url: import("@sinclair/typebox").TString;
|
|
37
|
+
title: import("@sinclair/typebox").TString;
|
|
38
|
+
tabs: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
39
|
+
id: import("@sinclair/typebox").TString;
|
|
40
|
+
url: import("@sinclair/typebox").TString;
|
|
41
|
+
title: import("@sinclair/typebox").TString;
|
|
42
|
+
parentId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
43
|
+
}>>;
|
|
44
|
+
screenshot: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
45
|
+
interactedElements: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
46
|
+
nodeId: import("@sinclair/typebox").TNumber;
|
|
47
|
+
backendNodeId: import("@sinclair/typebox").TNumber;
|
|
48
|
+
frameId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
49
|
+
nodeType: import("@sinclair/typebox").TNumber;
|
|
50
|
+
nodeValue: import("@sinclair/typebox").TString;
|
|
51
|
+
nodeName: import("@sinclair/typebox").TString;
|
|
52
|
+
attributes: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TString>;
|
|
53
|
+
bounds: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
54
|
+
x: import("@sinclair/typebox").TNumber;
|
|
55
|
+
y: import("@sinclair/typebox").TNumber;
|
|
56
|
+
width: import("@sinclair/typebox").TNumber;
|
|
57
|
+
height: import("@sinclair/typebox").TNumber;
|
|
58
|
+
}>>;
|
|
59
|
+
xpath: import("@sinclair/typebox").TString;
|
|
60
|
+
elementHash: import("@sinclair/typebox").TString;
|
|
61
|
+
stableHash: import("@sinclair/typebox").TString;
|
|
62
|
+
axName: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
63
|
+
parentBranchHash: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
64
|
+
}>, import("@sinclair/typebox").TNull]>>>;
|
|
65
|
+
}>;
|
|
66
|
+
metadata: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
67
|
+
stepStartTime: import("@sinclair/typebox").TNumber;
|
|
68
|
+
stepEndTime: import("@sinclair/typebox").TNumber;
|
|
69
|
+
stepNumber: import("@sinclair/typebox").TNumber;
|
|
70
|
+
stepInterval: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
71
|
+
}>>;
|
|
72
|
+
stateMessage: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
73
|
+
}>>;
|
|
74
|
+
terminationReason: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
75
|
+
}>;
|
|
76
|
+
/** Save a run's history to disk (design/04b §4.1 `save_to_file`). */
|
|
77
|
+
export declare function saveHistoryToFile(history: AgentHistoryList, filePath: string): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Load and validate a history file (the trust boundary). Throws a descriptive
|
|
80
|
+
* `Error` — never a bare JSON.parse crash — when the file is malformed.
|
|
81
|
+
*/
|
|
82
|
+
export declare function loadHistoryFromFile(filePath: string): Promise<AgentHistoryList>;
|
|
83
|
+
export type CompletionStatus = "full" | "partial" | "failed";
|
|
84
|
+
export type SummarySource = "llm" | "plain-text" | "fallback";
|
|
85
|
+
export interface RerunDeps {
|
|
86
|
+
session: BrowserSession;
|
|
87
|
+
driver: BrowserDriver;
|
|
88
|
+
registry: Registry;
|
|
89
|
+
fileSystem: FileSystem;
|
|
90
|
+
extractionLlm?: ExtractionLlm;
|
|
91
|
+
availableFilePaths?: readonly string[];
|
|
92
|
+
/** Rerun-summary LLM. Omit to always use the non-LLM fallback. */
|
|
93
|
+
model?: Model<Api>;
|
|
94
|
+
/**
|
|
95
|
+
* Per-call overrides (apiKey/headers/etc.) merged into the rerun-summary
|
|
96
|
+
* LLM call (and its plain-text fallback) — same seam as
|
|
97
|
+
* `AgentOptions.llm.streamOptions`.
|
|
98
|
+
*/
|
|
99
|
+
streamOptions?: ProviderStreamOptions;
|
|
100
|
+
/** Echoed into the rerun summary prompt. Defaults to "". */
|
|
101
|
+
task?: string;
|
|
102
|
+
logger?: Logger;
|
|
103
|
+
}
|
|
104
|
+
export interface RerunOptions {
|
|
105
|
+
maxRetries?: number;
|
|
106
|
+
retryBaseMs?: number;
|
|
107
|
+
retryCapMs?: number;
|
|
108
|
+
defaultStepDelayMs?: number;
|
|
109
|
+
maxStepIntervalMs?: number;
|
|
110
|
+
/**
|
|
111
|
+
* Skip steps that already had an error in the ORIGINAL run, AND continue the
|
|
112
|
+
* rerun past a step that fails during replay itself instead of aborting.
|
|
113
|
+
* Default false — a failed replay step stops the rerun (design/04b §4.1;
|
|
114
|
+
* a strict rerun aborts instead).
|
|
115
|
+
*/
|
|
116
|
+
skipFailures?: boolean;
|
|
117
|
+
/** Injectable sleep (tests pass a no-op / spy — fake-timer friendly). */
|
|
118
|
+
sleep?: (ms: number) => Promise<void>;
|
|
119
|
+
signal?: AbortSignal;
|
|
120
|
+
/** Per-attempt action cap, composed with `signal` (design/04b §4.8). Default 180s. */
|
|
121
|
+
stepTimeoutMs?: number;
|
|
122
|
+
}
|
|
123
|
+
export type StepReplayOutcome = "replayed" | "skipped-redundant" | "skipped-original-error" | "skipped-no-actions" | "failed";
|
|
124
|
+
export interface StepReplayResult {
|
|
125
|
+
stepNumber: number;
|
|
126
|
+
outcome: StepReplayOutcome;
|
|
127
|
+
matchLevels: Array<MatchLevel | undefined>;
|
|
128
|
+
results?: ActionResult[];
|
|
129
|
+
error?: string;
|
|
130
|
+
attempts: number;
|
|
131
|
+
}
|
|
132
|
+
export interface RerunReport {
|
|
133
|
+
steps: StepReplayResult[];
|
|
134
|
+
succeededSteps: number;
|
|
135
|
+
totalSteps: number;
|
|
136
|
+
summary: string;
|
|
137
|
+
success: boolean;
|
|
138
|
+
completionStatus: CompletionStatus;
|
|
139
|
+
summarySource: SummarySource;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Replay a recorded `AgentHistoryList` step by step against the LIVE browser,
|
|
143
|
+
* with no LLM driving decisions (design/04b §4.1, history rerun).
|
|
144
|
+
*/
|
|
145
|
+
export declare function rerunHistory(history: AgentHistoryList, deps: RerunDeps, options?: RerunOptions): Promise<RerunReport>;
|
|
146
|
+
/**
|
|
147
|
+
* Load a history file, optionally substitute detected variables, then replay
|
|
148
|
+
* it (design/04b §4.1, load-and-rerun).
|
|
149
|
+
*/
|
|
150
|
+
export declare function loadAndRerun(filePath: string, deps: RerunDeps, options?: RerunOptions & {
|
|
151
|
+
variables?: Readonly<Record<string, string>>;
|
|
152
|
+
}): Promise<RerunReport & {
|
|
153
|
+
detectedVariables: DetectedVariable[];
|
|
154
|
+
}>;
|
|
155
|
+
//# sourceMappingURL=replay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/agent/replay.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,KAAK,GAAG,EACR,KAAK,KAAK,EACV,KAAK,qBAAqB,EAG3B,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EAEd,UAAU,EACX,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,yBAAyB,CAAC;AACpE,OAAO,KAAK,EAAiB,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,KAAK,YAAY,EAAc,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAA4C,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAIvF,OAAO,EAAE,KAAK,gBAAgB,EAAwC,MAAM,qBAAqB,CAAC;AAkIlG,8EAA8E;AAC9E,eAAO,MAAM,iBAAiB;;;;;;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type Model, type ProviderStreamOptions } from "@ap3x/ai";
|
|
2
|
+
import { type BrowserDriver, type BrowserSession } from "@ap3x/browser";
|
|
3
|
+
import type { FileSystem } from "../filesystem/file-system";
|
|
4
|
+
import { type Logger } from "../observability/logger";
|
|
5
|
+
import type { ExtractionLlm, Registry } from "../tools/registry";
|
|
6
|
+
import { type SensitiveData } from "../tools/sensitive";
|
|
7
|
+
import type { UsageLedger } from "../usage/ledger";
|
|
8
|
+
import { type VisionMode } from "./context-builder";
|
|
9
|
+
import { type AgentStreamEvent } from "./event-stream";
|
|
10
|
+
import type { AgentHistoryList, BrowserStateHistory } from "./history";
|
|
11
|
+
import { type MessageManager } from "./message-manager";
|
|
12
|
+
import { type AgentOutput, type OutputVariant } from "./output-schema";
|
|
13
|
+
/** Numeric limits governing the loop. */
|
|
14
|
+
export interface StepLoopLimits {
|
|
15
|
+
maxSteps: number;
|
|
16
|
+
maxFailures: number;
|
|
17
|
+
maxActionsPerStep: number;
|
|
18
|
+
finalResponseAfterFailure: boolean;
|
|
19
|
+
stepTimeoutMs: number;
|
|
20
|
+
llmTimeoutMs: number;
|
|
21
|
+
/**
|
|
22
|
+
* Optional overall wall-clock ceiling for the whole run, in ms. OFF by default.
|
|
23
|
+
* Without it a run is bounded only by `maxSteps × stepTimeoutMs`, so a slow or
|
|
24
|
+
* heavy page (a live chart, an infinite feed) can grind for minutes with no
|
|
25
|
+
* total budget — the "stuck forever" failure. When set, the deadline both
|
|
26
|
+
* prevents a new step from starting AND aborts the in-flight step's LLM/CDP
|
|
27
|
+
* calls, so a run cannot overshoot it by a whole step. Latency-sensitive
|
|
28
|
+
* embedders (an interactive chat agent) should set it.
|
|
29
|
+
*/
|
|
30
|
+
runTimeoutMs?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface StepLoopHooks {
|
|
33
|
+
onStep?: (state: BrowserStateHistory, output: AgentOutput, step: number) => void | Promise<void>;
|
|
34
|
+
onDone?: (history: AgentHistoryList) => void | Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export interface StepLoopDeps {
|
|
37
|
+
model: Model<Api>;
|
|
38
|
+
driver: BrowserDriver;
|
|
39
|
+
session: BrowserSession;
|
|
40
|
+
/** The EFFECTIVE registry (already cloned + vision-filtered by the Agent). */
|
|
41
|
+
registry: Registry;
|
|
42
|
+
fileSystem: FileSystem;
|
|
43
|
+
messageManager: MessageManager;
|
|
44
|
+
history: AgentHistoryList;
|
|
45
|
+
ledger: UsageLedger;
|
|
46
|
+
vision: VisionMode;
|
|
47
|
+
variant: OutputVariant;
|
|
48
|
+
limits: StepLoopLimits;
|
|
49
|
+
sensitiveData?: SensitiveData;
|
|
50
|
+
availableFilePaths?: readonly string[];
|
|
51
|
+
extractionLlm?: ExtractionLlm;
|
|
52
|
+
/**
|
|
53
|
+
* Per-call overrides (apiKey/headers/etc.) merged into every `generateObject`
|
|
54
|
+
* call this loop makes — the seam an embedding host uses to authenticate with
|
|
55
|
+
* per-request credentials (e.g. OAuth headers) instead of a static env key.
|
|
56
|
+
* Call-specific fields (like the per-step abort signal) always win.
|
|
57
|
+
*/
|
|
58
|
+
llmStreamOptions?: ProviderStreamOptions;
|
|
59
|
+
/** Demo-mode: highlight each action's element before it runs (IMPROVEMENTS overlay). */
|
|
60
|
+
demoMode?: boolean;
|
|
61
|
+
hooks?: StepLoopHooks;
|
|
62
|
+
/** The task text, echoed on the `run-started` event. */
|
|
63
|
+
task?: string;
|
|
64
|
+
/** Sink for the O2 typed step-event stream (optional). */
|
|
65
|
+
emit?: (event: AgentStreamEvent) => void;
|
|
66
|
+
/** Structured logger (already carrying run identity as fields). */
|
|
67
|
+
logger?: Logger;
|
|
68
|
+
}
|
|
69
|
+
export interface RunOptions {
|
|
70
|
+
maxSteps?: number;
|
|
71
|
+
signal?: AbortSignal;
|
|
72
|
+
}
|
|
73
|
+
/** Combine the defined signals into one, or return undefined when none. */
|
|
74
|
+
export declare function anySignal(...signals: Array<AbortSignal | undefined>): AbortSignal | undefined;
|
|
75
|
+
export declare class StepLoop {
|
|
76
|
+
private readonly deps;
|
|
77
|
+
private readonly log;
|
|
78
|
+
private readonly loopDetector;
|
|
79
|
+
private readonly captchaWatchdog;
|
|
80
|
+
private nSteps;
|
|
81
|
+
private consecutiveFailures;
|
|
82
|
+
private lastStepDurationSeconds?;
|
|
83
|
+
private pendingNudges;
|
|
84
|
+
private done;
|
|
85
|
+
private stopped;
|
|
86
|
+
private paused;
|
|
87
|
+
private pauseGate?;
|
|
88
|
+
private pauseRelease?;
|
|
89
|
+
private maxSteps;
|
|
90
|
+
private runSignal?;
|
|
91
|
+
private runDeadline?;
|
|
92
|
+
constructor(deps: StepLoopDeps);
|
|
93
|
+
/** Fan an event out to the O2 stream (no-op when no sink is wired). */
|
|
94
|
+
private emit;
|
|
95
|
+
pause(): void;
|
|
96
|
+
resume(): void;
|
|
97
|
+
stop(): void;
|
|
98
|
+
get isDone(): boolean;
|
|
99
|
+
/** Current consecutive-failure count (observability / tests). */
|
|
100
|
+
get failures(): number;
|
|
101
|
+
/** The 1-based number of the step about to run (observability / tests). */
|
|
102
|
+
get currentStep(): number;
|
|
103
|
+
run(options?: RunOptions): Promise<AgentHistoryList>;
|
|
104
|
+
/**
|
|
105
|
+
* One perceive→decide→act→record cycle. Returns whether the task is now done.
|
|
106
|
+
* A no-op (returns false) when paused/stopped/already-done.
|
|
107
|
+
*/
|
|
108
|
+
step(): Promise<boolean>;
|
|
109
|
+
private waitWhilePaused;
|
|
110
|
+
/** Consecutive-failure accounting (design/07 §7.2.3). */
|
|
111
|
+
private accountFailures;
|
|
112
|
+
private handleLlmError;
|
|
113
|
+
/** A whole-step failure: increment the counter and record an error result. */
|
|
114
|
+
private recordWholeStepFailure;
|
|
115
|
+
/** Append a synthetic terminal failure entry (max steps / consecutive failures). */
|
|
116
|
+
private recordSyntheticFailure;
|
|
117
|
+
/** Fold a step into both the message-manager history and the AgentHistoryList. */
|
|
118
|
+
private recordStep;
|
|
119
|
+
private metadata;
|
|
120
|
+
private buildContext;
|
|
121
|
+
/** A single-key union carrying only `done` (forced-termination schema). */
|
|
122
|
+
private doneOnlyUnion;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=step-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-loop.d.ts","sourceRoot":"","sources":["../../src/agent/step-loop.ts"],"names":[],"mappings":"AAkBA,OAAO,EACL,KAAK,GAAG,EACR,KAAK,KAAK,EACV,KAAK,qBAAqB,EAG3B,MAAM,UAAU,CAAC;AAClB,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,cAAc,EAEpB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,yBAAyB,CAAC;AACpE,OAAO,KAAK,EAAiB,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,KAAK,aAAa,EAAsC,MAAM,oBAAoB,CAAC;AAE5F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAgB,KAAK,UAAU,EAAyB,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAAE,KAAK,gBAAgB,EAAqB,MAAM,gBAAgB,CAAC;AAE1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAgB,MAAM,WAAW,CAAC;AACrF,OAAO,EAAE,KAAK,cAAc,EAAkB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,aAAa,EAGnB,MAAM,iBAAiB,CAAC;AAEzB,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,yBAAyB,EAAE,OAAO,CAAC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,YAA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yDAAyD;IACzD,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,cAAc;IAmCtB,8EAA8E;IAC9E,OAAO,CAAC,sBAAsB;IAW9B,oFAAoF;IACpF,OAAO,CAAC,sBAAsB;IAU9B,kFAAkF;IAClF,OAAO,CAAC,UAAU;IAyBlB,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,YAAY;IAiBpB,2EAA2E;IAC3E,OAAO,CAAC,aAAa;CAKtB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AgentHistoryList } from "./history";
|
|
2
|
+
export interface DetectedVariable {
|
|
3
|
+
name: string;
|
|
4
|
+
value: string;
|
|
5
|
+
stepIndex: number;
|
|
6
|
+
actionIndex: number;
|
|
7
|
+
/** Which param carried the value ('text' on input_text, 'query' on extract_content). */
|
|
8
|
+
param: "text" | "query";
|
|
9
|
+
}
|
|
10
|
+
/** Scan a history for reusable variables. Deterministic — same history → same names. */
|
|
11
|
+
export declare function detectVariables(history: AgentHistoryList): DetectedVariable[];
|
|
12
|
+
/**
|
|
13
|
+
* Deep-copy `history` and exact-string-replace each detected variable's
|
|
14
|
+
* recorded value with the caller-supplied replacement (variables not present
|
|
15
|
+
* in `values` are left untouched). `structuredClone` is enough — every field
|
|
16
|
+
* on `AgentHistory` is JSON-safe (design/05 invariant).
|
|
17
|
+
*/
|
|
18
|
+
export declare function substituteVariables(history: AgentHistoryList, detected: readonly DetectedVariable[], values: Readonly<Record<string, string>>): AgentHistoryList;
|
|
19
|
+
//# sourceMappingURL=variable-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variable-detector.d.ts","sourceRoot":"","sources":["../../src/agent/variable-detector.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG7C,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,wFAAwF;IACxF,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AA8ED,wFAAwF;AACxF,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,EAAE,CA2C7E;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,SAAS,gBAAgB,EAAE,EACrC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACvC,gBAAgB,CAkBlB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ScreencastFrame } from "@ap3x/browser";
|
|
2
|
+
import { type GifOptions } from "./gif";
|
|
3
|
+
export type VideoOptions = GifOptions;
|
|
4
|
+
/**
|
|
5
|
+
* Build a video-as-GIF artifact from screencast frames. Frame duration
|
|
6
|
+
* defaults to a much shorter interval than the per-step run GIF (screencast
|
|
7
|
+
* frames are dense in time, not one per agent step) — override via
|
|
8
|
+
* `frameDurationMs` if the recorder's `everyNthFrame`/framerate warrants it.
|
|
9
|
+
* Returns `undefined` when there is nothing decodable to encode.
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateRunVideoGif(frames: readonly ScreencastFrame[], options?: VideoOptions): Uint8Array | undefined;
|
|
12
|
+
//# sourceMappingURL=video.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../src/agent/video.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,UAAU,EAAqB,MAAM,OAAO,CAAC;AAG3D,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC;AAkBtC;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,eAAe,EAAE,EAClC,OAAO,GAAE,YAAiB,GACzB,UAAU,GAAG,SAAS,CAMxB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// src/testing.ts
|
|
2
|
+
import {
|
|
3
|
+
fauxAssistantMessage,
|
|
4
|
+
fauxToolCall,
|
|
5
|
+
registerFauxProvider
|
|
6
|
+
} from "@ap3x/ai";
|
|
7
|
+
var RESPOND_TOOL = "respond";
|
|
8
|
+
function isAssistantMessage(step) {
|
|
9
|
+
return "role" in step && step.role === "assistant";
|
|
10
|
+
}
|
|
11
|
+
function toFaux(step) {
|
|
12
|
+
if (isAssistantMessage(step)) return step;
|
|
13
|
+
return fauxAssistantMessage(
|
|
14
|
+
fauxToolCall(RESPOND_TOOL, step),
|
|
15
|
+
{
|
|
16
|
+
stopReason: "stop"
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
function scriptedLlm(steps = []) {
|
|
21
|
+
const registration = registerFauxProvider();
|
|
22
|
+
registration.setResponses(steps.map(toFaux));
|
|
23
|
+
return {
|
|
24
|
+
model: registration.getModel(),
|
|
25
|
+
registration,
|
|
26
|
+
push(more) {
|
|
27
|
+
registration.appendResponses(more.map(toFaux));
|
|
28
|
+
},
|
|
29
|
+
unregister() {
|
|
30
|
+
registration.unregister();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function agentStep(actions, fields = {}) {
|
|
35
|
+
return {
|
|
36
|
+
evaluation_previous_goal: "",
|
|
37
|
+
memory: "",
|
|
38
|
+
next_goal: "",
|
|
39
|
+
...fields,
|
|
40
|
+
action: actions
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function emptyLlmResponse() {
|
|
44
|
+
return fauxAssistantMessage([], { stopReason: "stop" });
|
|
45
|
+
}
|
|
46
|
+
function truncatedLlmResponse() {
|
|
47
|
+
return fauxAssistantMessage(fauxToolCall(RESPOND_TOOL, {}), { stopReason: "length" });
|
|
48
|
+
}
|
|
49
|
+
function invalidLlmResponse() {
|
|
50
|
+
return fauxAssistantMessage(fauxToolCall(RESPOND_TOOL, { memory: "no action here" }), {
|
|
51
|
+
stopReason: "stop"
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function transportErrorResponse(message = "provider error") {
|
|
55
|
+
return fauxAssistantMessage([], { stopReason: "error", errorMessage: message });
|
|
56
|
+
}
|
|
57
|
+
function collectingLogger(base = {}) {
|
|
58
|
+
const lines = [];
|
|
59
|
+
const make = (fields) => {
|
|
60
|
+
const record = (level, message, extra) => {
|
|
61
|
+
lines.push({ level, message, fields: { ...fields, ...extra } });
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
debug: (message, extra) => record("debug", message, extra),
|
|
65
|
+
info: (message, extra) => record("info", message, extra),
|
|
66
|
+
warn: (message, extra) => record("warn", message, extra),
|
|
67
|
+
error: (message, extra) => record("error", message, extra),
|
|
68
|
+
child: (extra) => make({ ...fields, ...extra })
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
return { logger: make(base), lines };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export {
|
|
75
|
+
scriptedLlm,
|
|
76
|
+
agentStep,
|
|
77
|
+
emptyLlmResponse,
|
|
78
|
+
truncatedLlmResponse,
|
|
79
|
+
invalidLlmResponse,
|
|
80
|
+
transportErrorResponse,
|
|
81
|
+
collectingLogger
|
|
82
|
+
};
|