@myrialabs/clopen 0.4.20 → 0.4.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/backend/artifacts/generate.ts +11 -5
- package/backend/auth/permissions.ts +8 -8
- package/backend/bootstrap.ts +39 -0
- package/backend/chat/stream-manager.ts +15 -0
- package/backend/database/migrations/065_add_session_reasoning_effort.ts +28 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/session-queries.ts +10 -0
- package/backend/engine/README.md +11 -8
- package/backend/engine/adapters/claude/models.ts +46 -23
- package/backend/engine/adapters/claude/stream.ts +18 -4
- package/backend/engine/adapters/codex/error-handler.ts +1 -1
- package/backend/engine/adapters/codex/models.ts +19 -2
- package/backend/engine/adapters/codex/stream.ts +10 -3
- package/backend/engine/adapters/copilot/models.ts +20 -1
- package/backend/engine/adapters/copilot/stream.ts +11 -1
- package/backend/engine/adapters/cursor/models.ts +27 -3
- package/backend/engine/adapters/cursor/stream.ts +23 -3
- package/backend/engine/adapters/pi/models.ts +20 -2
- package/backend/engine/adapters/pi/stream.ts +6 -3
- package/backend/engine/adapters/qwen/error-handler.ts +1 -1
- package/backend/engine/bootstrap-default-engine.ts +18 -5
- package/backend/engine/docs/adapter-contract.md +66 -2
- package/backend/engine/docs/adding-an-engine.md +46 -7
- package/backend/engine/docs/frontend-and-chat.md +80 -17
- package/backend/engine/docs/lessons-learned.md +126 -7
- package/backend/engine/docs/quick-reference.md +12 -3
- package/backend/engine/docs/{system-tools.md → stack.md} +35 -6
- package/backend/engine/docs/websocket-routes.md +54 -15
- package/backend/engine/install-runner.ts +4 -4
- package/backend/engine/resolve-model.ts +87 -0
- package/backend/engine/structured-helpers.test.ts +64 -0
- package/backend/engine/structured-helpers.ts +105 -13
- package/backend/engine/types.ts +6 -0
- package/backend/index.ts +6 -9
- package/backend/mcp/README.md +32 -11
- package/backend/mcp/internal/config.ts +3 -20
- package/backend/mcp/internal/servers/browser-automation/actions/console.ts +65 -0
- package/backend/mcp/internal/servers/browser-automation/actions/dom-analyze.ts +202 -0
- package/backend/mcp/internal/servers/browser-automation/actions/index.ts +31 -0
- package/backend/mcp/internal/servers/browser-automation/actions/input.ts +332 -0
- package/backend/mcp/internal/servers/browser-automation/actions/inspect.ts +158 -0
- package/backend/mcp/internal/servers/browser-automation/actions/navigation.ts +157 -0
- package/backend/mcp/internal/servers/browser-automation/actions/shared.ts +60 -0
- package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +146 -0
- package/backend/mcp/internal/servers/browser-automation/actions/types.ts +63 -0
- package/backend/mcp/internal/servers/browser-automation/context.ts +82 -0
- package/backend/mcp/internal/servers/browser-automation/description.ts +59 -0
- package/backend/mcp/internal/servers/browser-automation/format.ts +56 -0
- package/backend/mcp/internal/servers/browser-automation/index.ts +36 -784
- package/backend/mcp/internal/servers/browser-automation/paths.ts +71 -0
- package/backend/mcp/internal/servers/browser-automation/runner.ts +260 -0
- package/backend/mcp/internal/servers/browser-automation/schema.ts +26 -0
- package/backend/preview/browser/browser-console-manager.ts +310 -156
- package/backend/preview/browser/browser-dialog-handler.ts +45 -16
- package/backend/preview/browser/browser-host-bridge.ts +471 -0
- package/backend/preview/browser/browser-interaction-handler.ts +868 -297
- package/backend/preview/browser/browser-mcp-control.ts +7 -2
- package/backend/preview/browser/browser-native-ui-handler.ts +455 -81
- package/backend/preview/browser/browser-navigation-tracker.ts +56 -0
- package/backend/preview/browser/browser-pool.ts +83 -9
- package/backend/preview/browser/browser-preview-service.ts +432 -53
- package/backend/preview/browser/browser-tab-manager.ts +16 -16
- package/backend/preview/browser/browser-video-capture.ts +1334 -386
- package/backend/preview/browser/capture-profile.ts +213 -0
- package/backend/preview/browser/element-locator.ts +357 -0
- package/backend/preview/browser/frame-targeting.ts +92 -0
- package/backend/preview/browser/scripts/audio-stream.ts +258 -78
- package/backend/preview/browser/scripts/host-bridge.ts +1277 -0
- package/backend/preview/browser/scripts/video-stream.ts +803 -177
- package/backend/preview/browser/types.ts +397 -37
- package/backend/utils/cli.ts +1 -1
- package/backend/utils/path-enrich.ts +2 -2
- package/backend/ws/README.md +1 -1
- package/backend/ws/artifacts/generate.ts +2 -1
- package/backend/ws/chat/stream.ts +38 -2
- package/backend/ws/engine/codex/accounts.ts +1 -1
- package/backend/ws/engine/codex/status.ts +1 -1
- package/backend/ws/git/branch-name.ts +11 -5
- package/backend/ws/git/commit-message.ts +11 -5
- package/backend/ws/index.ts +3 -3
- package/backend/ws/preview/browser/host.ts +95 -0
- package/backend/ws/preview/browser/interact.ts +204 -10
- package/backend/ws/preview/browser/native-ui.ts +31 -1
- package/backend/ws/preview/browser/tab-info.ts +10 -1
- package/backend/ws/preview/browser/tab.ts +43 -0
- package/backend/ws/preview/browser/webcodecs.ts +180 -53
- package/backend/ws/preview/index.ts +58 -1
- package/backend/ws/{system-tools → stack}/access.ts +1 -1
- package/backend/ws/stack/index.ts +16 -0
- package/backend/ws/{system-tools → stack}/install.ts +7 -7
- package/backend/ws/{system-tools → stack}/status.ts +7 -7
- package/backend/ws/system/device-info.ts +290 -0
- package/backend/ws/system/index.ts +2 -0
- package/backend/ws/system/operations.ts +7 -0
- package/backend/ws/user/crud.ts +6 -3
- package/dist/assets/{index-BqBxKeAv.js → index-DH_GO0Lf.js} +1 -1
- package/dist/assets/{index-DdrcY5TE.js → index-igSQ3JaM.js} +1 -1
- package/dist/assets/main-BD3-qPfT.css +1 -0
- package/dist/assets/main-D-d8SFfW.js +616 -0
- package/dist/assets/preview-video.worker-DcpDhCWL.js +1 -0
- package/dist/index.html +2 -2
- package/package.json +2 -1
- package/shared/constants/engines.ts +23 -0
- package/shared/types/database/schema.ts +1 -0
- package/shared/types/stores/settings.ts +12 -0
- package/shared/types/unified/engine.ts +33 -0
- package/shared/types/unified/index.ts +2 -0
- package/shared/types/unified/message.ts +6 -0
- package/shared/types/unified/stream.ts +6 -0
- package/backend/mcp/internal/servers/browser-automation/actions.ts +0 -159
- package/backend/mcp/internal/servers/browser-automation/browser.ts +0 -375
- package/backend/mcp/internal/servers/browser-automation/inspection.ts +0 -495
- package/backend/ws/system-tools/index.ts +0 -16
- package/dist/assets/main-BBxAj17T.js +0 -582
- package/dist/assets/main-Cry3pLcl.css +0 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project-scoped path resolution for actions that touch the filesystem
|
|
3
|
+
* (screenshot → file, file upload).
|
|
4
|
+
*
|
|
5
|
+
* Agent-supplied paths are resolved against the project directory and must
|
|
6
|
+
* stay inside it. Symlinks are followed on both sides before comparing, so a
|
|
7
|
+
* link inside the project cannot be used to reach out of it.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
11
|
+
import { mkdir, realpath, stat } from 'node:fs/promises';
|
|
12
|
+
import { projectQueries } from '$backend/database/queries/project-queries';
|
|
13
|
+
|
|
14
|
+
async function resolveRealPath(p: string): Promise<string> {
|
|
15
|
+
const abs = resolve(p);
|
|
16
|
+
try {
|
|
17
|
+
return await realpath(abs);
|
|
18
|
+
} catch {
|
|
19
|
+
// Not created yet — resolve the deepest existing ancestor and rejoin the
|
|
20
|
+
// tail, so a symlinked parent is still followed.
|
|
21
|
+
const parent = dirname(abs);
|
|
22
|
+
if (parent === abs) return abs;
|
|
23
|
+
return join(await resolveRealPath(parent), basename(abs));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function isPathInside(rootPath: string, candidatePath: string): Promise<boolean> {
|
|
28
|
+
const root = await resolveRealPath(rootPath);
|
|
29
|
+
const candidate = await resolveRealPath(candidatePath);
|
|
30
|
+
const rel = relative(root, candidate);
|
|
31
|
+
return rel === '' || (!!rel && !rel.startsWith('..') && !isAbsolute(rel));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function projectRoot(projectId: string): string {
|
|
35
|
+
const project = projectQueries.getById(projectId);
|
|
36
|
+
if (!project?.path) throw new Error(`Project ${projectId} has no directory on disk`);
|
|
37
|
+
return project.path;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Resolve one agent-supplied path inside the project. */
|
|
41
|
+
export async function resolveProjectPath(inputPath: string, projectId: string): Promise<string> {
|
|
42
|
+
const root = projectRoot(projectId);
|
|
43
|
+
const absolute = isAbsolute(inputPath) ? inputPath : resolve(root, inputPath);
|
|
44
|
+
|
|
45
|
+
if (!(await isPathInside(root, absolute))) {
|
|
46
|
+
throw new Error(`Path "${inputPath}" resolves outside the project directory`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return absolute;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Resolve paths that must already exist (uploads). */
|
|
53
|
+
export async function resolveProjectFiles(inputPaths: string[], projectId: string): Promise<string[]> {
|
|
54
|
+
const resolved: string[] = [];
|
|
55
|
+
|
|
56
|
+
for (const inputPath of inputPaths) {
|
|
57
|
+
const absolute = await resolveProjectPath(inputPath, projectId);
|
|
58
|
+
const info = await stat(absolute).catch(() => null);
|
|
59
|
+
if (!info?.isFile()) throw new Error(`File not found: ${inputPath}`);
|
|
60
|
+
resolved.push(absolute);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return resolved;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Resolve a write destination, creating its parent directory. */
|
|
67
|
+
export async function resolveWritePath(inputPath: string, projectId: string): Promise<string> {
|
|
68
|
+
const absolute = await resolveProjectPath(inputPath, projectId);
|
|
69
|
+
await mkdir(dirname(absolute), { recursive: true });
|
|
70
|
+
return absolute;
|
|
71
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch runner.
|
|
3
|
+
*
|
|
4
|
+
* Walks the requested actions in order and turns them into one honest report.
|
|
5
|
+
*
|
|
6
|
+
* Three things it owns, each of which was a bug when it lived somewhere else:
|
|
7
|
+
*
|
|
8
|
+
* - **Coalescing.** Consecutive input gestures go to the native engine in a
|
|
9
|
+
* single call, so pointer movement stays continuous and the engine's own
|
|
10
|
+
* pacing applies. Split per action, a five-click sequence looks like five
|
|
11
|
+
* unrelated jumps.
|
|
12
|
+
* - **Re-targeting.** Opening, switching or closing a tab changes what "the
|
|
13
|
+
* current tab" means; the target is resolved again before the next action
|
|
14
|
+
* rather than captured once at the start.
|
|
15
|
+
* - **Truthful reporting.** Interrupted and failed runs say how far they got.
|
|
16
|
+
* Claiming success for actions that never ran is worse than failing, because
|
|
17
|
+
* the agent then plans on top of a state that does not exist.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { BrowserAutonomousAction } from '$backend/preview/browser/types';
|
|
21
|
+
import { projectContextService } from '$backend/mcp/internal/project-context';
|
|
22
|
+
import { debug } from '$shared/utils/logger';
|
|
23
|
+
import { ACTIONS_BY_TYPE } from './actions';
|
|
24
|
+
import type { ActionContext, ActionImage } from './actions/types';
|
|
25
|
+
import { getActiveTabSession, getPreviewService } from './context';
|
|
26
|
+
|
|
27
|
+
interface ActionArgs {
|
|
28
|
+
type: string;
|
|
29
|
+
optional?: boolean;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface RunArgs {
|
|
34
|
+
actions: ActionArgs[];
|
|
35
|
+
onError?: 'stop' | 'continue';
|
|
36
|
+
projectId?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface StepReport {
|
|
40
|
+
index: number;
|
|
41
|
+
type: string;
|
|
42
|
+
ok: boolean;
|
|
43
|
+
summary?: string;
|
|
44
|
+
detail?: string;
|
|
45
|
+
error?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface RunReport {
|
|
49
|
+
steps: StepReport[];
|
|
50
|
+
images: ActionImage[];
|
|
51
|
+
/** Actions that never ran, because a failure or an interrupt stopped the batch. */
|
|
52
|
+
skipped: number;
|
|
53
|
+
aborted: boolean;
|
|
54
|
+
failed: boolean;
|
|
55
|
+
tabId?: string;
|
|
56
|
+
url?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Consecutive input gestures form one native run; control actions stand alone. */
|
|
60
|
+
function groupActions(actions: ActionArgs[]): Array<{ kind: 'input' | 'control'; items: Array<{ index: number; args: ActionArgs }> }> {
|
|
61
|
+
const groups: Array<{ kind: 'input' | 'control'; items: Array<{ index: number; args: ActionArgs }> }> = [];
|
|
62
|
+
|
|
63
|
+
actions.forEach((args, index) => {
|
|
64
|
+
const def = ACTIONS_BY_TYPE.get(args.type);
|
|
65
|
+
const kind = def?.kind ?? 'control';
|
|
66
|
+
const last = groups[groups.length - 1];
|
|
67
|
+
|
|
68
|
+
if (kind === 'input' && last?.kind === 'input') {
|
|
69
|
+
last.items.push({ index, args });
|
|
70
|
+
} else {
|
|
71
|
+
groups.push({ kind, items: [{ index, args }] });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return groups;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function runActions(args: RunArgs): Promise<RunReport> {
|
|
79
|
+
const signal = projectContextService.getCurrentSignal();
|
|
80
|
+
const service = getPreviewService(args.projectId);
|
|
81
|
+
const projectId = service.getProjectId();
|
|
82
|
+
|
|
83
|
+
const report: RunReport = { steps: [], images: [], skipped: 0, aborted: false, failed: false };
|
|
84
|
+
|
|
85
|
+
let tabStale = true;
|
|
86
|
+
let tab: Awaited<ReturnType<typeof getActiveTabSession>>['tab'] | null = null;
|
|
87
|
+
|
|
88
|
+
const resolveTab = async () => {
|
|
89
|
+
if (!tabStale && tab) return tab;
|
|
90
|
+
const resolved = await getActiveTabSession(args.projectId);
|
|
91
|
+
tab = resolved.tab;
|
|
92
|
+
tabStale = false;
|
|
93
|
+
return tab;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const groups = groupActions(args.actions);
|
|
97
|
+
let stopped = false;
|
|
98
|
+
let consumed = 0;
|
|
99
|
+
|
|
100
|
+
/** A failure only stops the batch if it was not asked to be tolerated. */
|
|
101
|
+
const tolerates = (step: StepReport) =>
|
|
102
|
+
args.actions[step.index]?.optional === true || args.onError === 'continue';
|
|
103
|
+
|
|
104
|
+
for (const group of groups) {
|
|
105
|
+
if (stopped || signal?.aborted) break;
|
|
106
|
+
|
|
107
|
+
const deps: RunDeps = { args, service, projectId, signal, resolveTab, markTabStale: () => (tabStale = true) };
|
|
108
|
+
const before = report.steps.length;
|
|
109
|
+
|
|
110
|
+
consumed += group.kind === 'input'
|
|
111
|
+
? await runInputGroup(group.items, deps, report)
|
|
112
|
+
: await runControl(group.items[0], deps, report);
|
|
113
|
+
|
|
114
|
+
if (signal?.aborted) {
|
|
115
|
+
report.aborted = true;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Check every step this group produced, not just the last: one native
|
|
120
|
+
// run can fail in the middle and still finish with a successful action.
|
|
121
|
+
stopped = report.steps.slice(before).some((step) => !step.ok && !tolerates(step));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
report.failed = report.steps.some((step) => !step.ok && !tolerates(step));
|
|
125
|
+
report.skipped = Math.max(0, args.actions.length - consumed);
|
|
126
|
+
if (signal?.aborted) report.aborted = true;
|
|
127
|
+
|
|
128
|
+
// Report where the batch left the browser: the next call's plan depends on
|
|
129
|
+
// it, and it is the cheapest way to notice a navigation nobody asked for.
|
|
130
|
+
try {
|
|
131
|
+
// Through the resolver, not the cached handle: a tab opened or closed
|
|
132
|
+
// mid-batch means the cached one is no longer where the agent is.
|
|
133
|
+
const current = await resolveTab();
|
|
134
|
+
report.tabId = current.id;
|
|
135
|
+
report.url = current.page.url();
|
|
136
|
+
} catch {
|
|
137
|
+
// No tab left (closed by the batch, or none was ever open).
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return report;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
interface RunDeps {
|
|
144
|
+
args: RunArgs;
|
|
145
|
+
service: ReturnType<typeof getPreviewService>;
|
|
146
|
+
projectId: string;
|
|
147
|
+
signal?: AbortSignal;
|
|
148
|
+
resolveTab: () => Promise<NonNullable<Awaited<ReturnType<typeof getActiveTabSession>>['tab']>>;
|
|
149
|
+
markTabStale: () => void;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Run one control action. Returns how many actions were consumed. */
|
|
153
|
+
async function runControl(item: { index: number; args: ActionArgs }, deps: RunDeps, report: RunReport): Promise<number> {
|
|
154
|
+
const def = ACTIONS_BY_TYPE.get(item.args.type);
|
|
155
|
+
if (!def?.run) {
|
|
156
|
+
report.steps.push({ index: item.index, type: item.args.type, ok: false, error: `Unknown action "${item.args.type}"` });
|
|
157
|
+
return 1;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
const tab = await deps.resolveTab();
|
|
162
|
+
const ctx: ActionContext = {
|
|
163
|
+
service: deps.service,
|
|
164
|
+
tab,
|
|
165
|
+
projectId: deps.projectId,
|
|
166
|
+
chatSessionId: projectContextService.getCurrentChatSessionId() ?? '',
|
|
167
|
+
signal: deps.signal,
|
|
168
|
+
invalidateTab: deps.markTabStale
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const output = await def.run(item.args, ctx);
|
|
172
|
+
report.steps.push({ index: item.index, type: def.type, ok: true, summary: output.summary, detail: output.detail });
|
|
173
|
+
if (output.images?.length) report.images.push(...output.images);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
176
|
+
debug.warn('mcp', `browser action ${item.args.type} failed: ${message}`);
|
|
177
|
+
report.steps.push({ index: item.index, type: item.args.type, ok: false, error: message });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return 1;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Run a run of input gestures as one native batch.
|
|
185
|
+
*
|
|
186
|
+
* The engine reports per action, so a partial run maps back onto the original
|
|
187
|
+
* indices — including which of them never happened.
|
|
188
|
+
*/
|
|
189
|
+
async function runInputGroup(items: Array<{ index: number; args: ActionArgs }>, deps: RunDeps, report: RunReport): Promise<number> {
|
|
190
|
+
let tab;
|
|
191
|
+
try {
|
|
192
|
+
tab = await deps.resolveTab();
|
|
193
|
+
} catch (error) {
|
|
194
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
195
|
+
report.steps.push({ index: items[0].index, type: items[0].args.type, ok: false, error: message });
|
|
196
|
+
return 1;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const ctx: ActionContext = {
|
|
200
|
+
service: deps.service,
|
|
201
|
+
tab,
|
|
202
|
+
projectId: deps.projectId,
|
|
203
|
+
chatSessionId: projectContextService.getCurrentChatSessionId() ?? '',
|
|
204
|
+
signal: deps.signal,
|
|
205
|
+
invalidateTab: deps.markTabStale
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// Translation can fail on its own (a path outside the project, a missing
|
|
209
|
+
// field). Those actions never reach the engine, so they are reported here
|
|
210
|
+
// and the rest of the group still runs.
|
|
211
|
+
const primitives: BrowserAutonomousAction[] = [];
|
|
212
|
+
const mapped: Array<{ index: number; type: string }> = [];
|
|
213
|
+
|
|
214
|
+
for (const item of items) {
|
|
215
|
+
const def = ACTIONS_BY_TYPE.get(item.args.type);
|
|
216
|
+
if (!def?.toInput) {
|
|
217
|
+
report.steps.push({ index: item.index, type: item.args.type, ok: false, error: `Unknown action "${item.args.type}"` });
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
primitives.push(await def.toInput(item.args, ctx));
|
|
223
|
+
mapped.push({ index: item.index, type: def.type });
|
|
224
|
+
} catch (error) {
|
|
225
|
+
report.steps.push({
|
|
226
|
+
index: item.index,
|
|
227
|
+
type: item.args.type,
|
|
228
|
+
ok: false,
|
|
229
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (primitives.length === 0) return items.length;
|
|
235
|
+
|
|
236
|
+
const outcome = await deps.service.performAutonomousActions(tab.id, primitives, deps.signal);
|
|
237
|
+
|
|
238
|
+
// One engine result per primitive, in order.
|
|
239
|
+
mapped.forEach((entry, position) => {
|
|
240
|
+
const result = outcome.results[position];
|
|
241
|
+
if (!result) {
|
|
242
|
+
// The engine stopped before reaching this one.
|
|
243
|
+
report.steps.push({ index: entry.index, type: entry.type, ok: false, error: 'did not run (batch stopped earlier)' });
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
report.steps.push({
|
|
248
|
+
index: entry.index,
|
|
249
|
+
type: entry.type,
|
|
250
|
+
ok: result.ok,
|
|
251
|
+
summary: result.detail,
|
|
252
|
+
detail: result.data !== undefined ? JSON.stringify(result.data, null, 2) : undefined,
|
|
253
|
+
error: result.error
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
if (outcome.aborted) report.aborted = true;
|
|
258
|
+
|
|
259
|
+
return items.length;
|
|
260
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool schema, assembled from the action registry.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { ALL_ACTIONS } from './actions';
|
|
7
|
+
|
|
8
|
+
const members = ALL_ACTIONS.map((action) => action.schema) as unknown as [
|
|
9
|
+
z.ZodObject<any>,
|
|
10
|
+
z.ZodObject<any>,
|
|
11
|
+
...z.ZodObject<any>[]
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
/** One action. Discriminated on `type`, so a wrong field is rejected up front. */
|
|
15
|
+
export const actionSchema = z.discriminatedUnion('type', members);
|
|
16
|
+
|
|
17
|
+
export const actionsToolSchema = {
|
|
18
|
+
actions: z
|
|
19
|
+
.array(actionSchema)
|
|
20
|
+
.min(1)
|
|
21
|
+
.describe('Actions to run in order. Batch everything that does not depend on what you would learn from the result.'),
|
|
22
|
+
onError: z
|
|
23
|
+
.enum(['stop', 'continue'])
|
|
24
|
+
.optional()
|
|
25
|
+
.describe('stop (default): remaining actions are skipped after a failure. continue: run them all. Per-action `optional: true` overrides this for that action.')
|
|
26
|
+
};
|