@lobu/runtime-device 20.2.0 → 21.0.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/dist/component.json +1 -1
- package/dist/dependencies.bun.lock +42 -36
- package/npm-shrinkwrap.json +270 -224
- package/package.json +1 -1
- package/vendor/cli/dist/commands/_lib/apply/apply-cmd.d.ts +7 -2
- package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +77 -75
- package/vendor/cli/dist/commands/_lib/apply/client.d.ts +40 -25
- package/vendor/cli/dist/commands/_lib/apply/client.js +31 -39
- package/vendor/cli/dist/commands/_lib/apply/deployment.d.ts +1 -1
- package/vendor/cli/dist/commands/_lib/apply/deployment.js +2 -2
- package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +47 -11
- package/vendor/cli/dist/commands/_lib/apply/desired-state.js +106 -7
- package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +14 -6
- package/vendor/cli/dist/commands/_lib/apply/diff.js +42 -23
- package/vendor/cli/dist/commands/_lib/apply/map-config.js +2 -3
- package/vendor/cli/dist/commands/_lib/apply/render.js +2 -0
- package/vendor/cli/dist/commands/_lib/apply/rollback-cmd.js +3 -3
- package/vendor/cli/dist/commands/_lib/connector-loader.d.ts +5 -1
- package/vendor/cli/dist/commands/_lib/connector-loader.js +1 -1
- package/vendor/cli/dist/commands/_lib/ensure-deps-installed.d.ts +15 -26
- package/vendor/cli/dist/commands/_lib/ensure-deps-installed.js +227 -136
- package/vendor/cli/dist/commands/_lib/view-bundler.d.ts +33 -0
- package/vendor/cli/dist/commands/_lib/view-bundler.js +207 -0
- package/vendor/cli/dist/commands/_lib/view-reapply.d.ts +60 -0
- package/vendor/cli/dist/commands/_lib/view-reapply.js +182 -0
- package/vendor/cli/dist/commands/dev.d.ts +14 -5
- package/vendor/cli/dist/commands/dev.js +56 -8
- package/vendor/cli/dist/commands/init.d.ts +1 -1
- package/vendor/cli/dist/commands/init.js +4 -4
- package/vendor/cli/dist/config/define.d.ts +25 -8
- package/vendor/cli/dist/config/define.js +24 -0
- package/vendor/cli/dist/connectors/README.md +15 -16
- package/vendor/cli/dist/connectors/github.ts +15 -9
- package/vendor/cli/dist/connectors/google_calendar.ts +21 -31
- package/vendor/cli/dist/connectors/google_drive.ts +106 -131
- package/vendor/cli/dist/connectors/google_gmail.ts +53 -30
- package/vendor/cli/dist/connectors/hackernews.ts +2 -5
- package/vendor/cli/dist/connectors/jira.ts +62 -27
- package/vendor/cli/dist/connectors/linear.ts +55 -21
- package/vendor/cli/dist/connectors/microsoft_outlook.ts +151 -110
- package/vendor/cli/dist/connectors/postgres.ts +19 -11
- package/vendor/cli/dist/connectors/producthunt.ts +8 -6
- package/vendor/cli/dist/connectors/reddit.ts +2 -2
- package/vendor/cli/dist/connectors/rss.ts +2 -2
- package/vendor/cli/dist/connectors/whatsapp_web.ts +5 -4
- package/vendor/cli/dist/connectors/x.ts +32 -17
- package/vendor/cli/dist/connectors/youtube.ts +18 -5
- package/vendor/cli/dist/internal/connector-compiler.d.ts +1 -1
- package/vendor/cli/dist/internal/connector-compiler.js +216 -17
- package/vendor/cli/dist/runtime-components.json +4 -4
- package/vendor/cli/package.json +2 -1
- package/vendor/connector-sdk/dist/connector-runtime.d.ts +4 -6
- package/vendor/connector-sdk/dist/connector-runtime.js +3 -5
- package/vendor/connector-sdk/dist/connector-types.d.ts +28 -13
- package/vendor/connector-sdk/dist/define-connector.d.ts +4 -1
- package/vendor/connector-sdk/dist/define-connector.js +4 -1
- package/vendor/connector-sdk/dist/http-client.d.ts +18 -7
- package/vendor/connector-sdk/dist/http-client.js +15 -13
- package/vendor/connector-sdk/dist/index.d.ts +1 -1
- package/vendor/connector-sdk/dist/retry.d.ts +15 -3
- package/vendor/connector-sdk/dist/retry.js +40 -64
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/connector-worker/dist/agent-turn/guest-entry.js +122 -10
- package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +78 -10
- package/vendor/connector-worker/dist/agent-turn/types.d.ts +34 -4
- package/vendor/connector-worker/dist/compile/index.d.ts +21 -2
- package/vendor/connector-worker/dist/compile/index.js +41 -8
- package/vendor/connector-worker/dist/compile/source-capture.d.ts +10 -0
- package/vendor/connector-worker/dist/compile/source-capture.js +108 -0
- package/vendor/connector-worker/dist/daemon/agent-turn.js +97 -10
- package/vendor/connector-worker/dist/daemon/automation.d.ts +1 -1
- package/vendor/connector-worker/dist/daemon/executor.d.ts +0 -1
- package/vendor/connector-worker/dist/daemon/executor.js +42 -51
- package/vendor/connector-worker/dist/daemon/start.js +5 -1
- package/vendor/connector-worker/dist/executor/interface.d.ts +12 -8
- package/vendor/connector-worker/dist/executor/isolate.js +45 -28
- package/vendor/connector-worker/dist/self-check/index.js +15 -13
- package/vendor/connector-worker/package.json +1 -1
- package/vendor/core/dist/agent-policy.js +3 -0
- package/vendor/core/dist/connector-query-errors.d.ts +3 -3
- package/vendor/core/dist/connector-query-errors.js +8 -3
- package/vendor/core/dist/contracts/tools/manage-connections.d.ts +24 -0
- package/vendor/core/dist/contracts/tools/manage-connections.js +13 -0
- package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +15 -25
- package/vendor/core/dist/contracts/tools/manage-entity-schema.js +3 -5
- package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +11 -0
- package/vendor/core/dist/contracts/tools/manage-feeds.js +12 -1
- package/vendor/core/dist/contracts/tools/manage-operations.d.ts +47 -6
- package/vendor/core/dist/contracts/tools/manage-operations.js +36 -1
- package/vendor/core/dist/contracts/tools/manage-views.d.ts +293 -0
- package/vendor/core/dist/contracts/tools/manage-views.js +203 -0
- package/vendor/core/dist/contracts/tools/source-files-schema.d.ts +7 -0
- package/vendor/core/dist/contracts/tools/source-files-schema.js +19 -0
- package/vendor/core/dist/contracts/tools/source-files.d.ts +14 -0
- package/vendor/core/dist/contracts/tools/source-files.js +55 -0
- package/vendor/core/dist/contracts/tools/view-content-hash.d.ts +37 -0
- package/vendor/core/dist/contracts/tools/view-content-hash.js +58 -0
- package/vendor/core/dist/contracts/tools/view-path.d.ts +18 -0
- package/vendor/core/dist/contracts/tools/view-path.js +24 -0
- package/vendor/core/dist/contracts/worker/protocol.d.ts +73 -8
- package/vendor/core/dist/contracts/worker/protocol.js +58 -9
- package/vendor/core/dist/reserved.d.ts +3 -3
- package/vendor/core/dist/reserved.js +9 -1
- package/vendor/core/dist/utils/secret-redaction.js +2 -0
- package/vendor/core/package.json +25 -5
- package/vendor/core/dist/contracts/tools/manage-view-templates.d.ts +0 -165
- package/vendor/core/dist/contracts/tools/manage-view-templates.js +0 -130
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import { assertSourcePath, SOURCE_MAX_BYTES, validateRetainedSource, } from '@lobu/core/contracts/tools/source-files';
|
|
4
|
+
function within(root, file) {
|
|
5
|
+
const path = relative(root, file);
|
|
6
|
+
return path !== '..' && !path.startsWith(`..${sep}`) && !isAbsolute(path);
|
|
7
|
+
}
|
|
8
|
+
function packageAt(file) {
|
|
9
|
+
let root = dirname(file);
|
|
10
|
+
for (;;) {
|
|
11
|
+
try {
|
|
12
|
+
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
13
|
+
if (typeof pkg.name === 'string' && typeof pkg.version === 'string') {
|
|
14
|
+
return { root, name: pkg.name, version: pkg.version };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch { /* Continue to the package root. */ }
|
|
18
|
+
const parent = dirname(root);
|
|
19
|
+
if (parent === root)
|
|
20
|
+
return null;
|
|
21
|
+
root = parent;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Exact installed versions for runtime-provided source imports. */
|
|
25
|
+
export function sourceDependencies(files) {
|
|
26
|
+
return Object.fromEntries(files.map((file) => {
|
|
27
|
+
const pkg = packageAt(file);
|
|
28
|
+
if (!pkg)
|
|
29
|
+
throw new Error('Cannot determine source dependency version');
|
|
30
|
+
return [pkg.name, pkg.version];
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
/** The onLoad bytes are both compiled and retained; no post-build file reread. */
|
|
34
|
+
export function createSourceCapture(entry, projectRoot) {
|
|
35
|
+
const root = realpathSync(projectRoot);
|
|
36
|
+
const entrypoint = relative(root, realpathSync(entry)).split(sep).join('/');
|
|
37
|
+
assertSourcePath(entrypoint);
|
|
38
|
+
const files = Object.create(null);
|
|
39
|
+
const dependencies = Object.create(null);
|
|
40
|
+
const packageRoots = new Set();
|
|
41
|
+
const resolving = Symbol('source-capture-resolve');
|
|
42
|
+
const isDependency = (file) => [...packageRoots].some((base) => within(base, file));
|
|
43
|
+
const isProjectFile = (file) => within(root, file) && !isDependency(file);
|
|
44
|
+
const source = () => {
|
|
45
|
+
const sourceFiles = { entrypoint, files: { ...files } };
|
|
46
|
+
validateRetainedSource(files[entrypoint] ?? '', sourceFiles, dependencies);
|
|
47
|
+
return { sourceFiles, dependencies: { ...dependencies } };
|
|
48
|
+
};
|
|
49
|
+
const plugin = {
|
|
50
|
+
name: 'retain-project-source',
|
|
51
|
+
setup(build) {
|
|
52
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
53
|
+
if (args.pluginData?.[resolving])
|
|
54
|
+
return;
|
|
55
|
+
const found = await build.resolve(args.path, {
|
|
56
|
+
importer: args.importer,
|
|
57
|
+
resolveDir: args.resolveDir,
|
|
58
|
+
kind: args.kind,
|
|
59
|
+
namespace: args.namespace,
|
|
60
|
+
pluginData: { ...args.pluginData, [resolving]: true },
|
|
61
|
+
});
|
|
62
|
+
if (found.pluginData?.[resolving]) {
|
|
63
|
+
found.pluginData = { ...found.pluginData };
|
|
64
|
+
delete found.pluginData[resolving];
|
|
65
|
+
}
|
|
66
|
+
if (found.errors.length || found.external || found.namespace !== 'file')
|
|
67
|
+
return found;
|
|
68
|
+
const file = realpathSync(found.path);
|
|
69
|
+
const fromProject = !args.importer || isProjectFile(args.importer);
|
|
70
|
+
const bare = !isAbsolute(args.path) && !args.path.startsWith('.');
|
|
71
|
+
if (bare) {
|
|
72
|
+
const pkg = packageAt(file);
|
|
73
|
+
if (pkg && pkg.root !== root) {
|
|
74
|
+
packageRoots.add(pkg.root);
|
|
75
|
+
if (fromProject) {
|
|
76
|
+
if (dependencies[pkg.name] && dependencies[pkg.name] !== pkg.version) {
|
|
77
|
+
throw new Error(`Conflicting source dependency versions: ${pkg.name}`);
|
|
78
|
+
}
|
|
79
|
+
dependencies[pkg.name] = pkg.version;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (fromProject && !within(root, file)) {
|
|
84
|
+
throw new Error(`Source import leaves the project: ${args.path}`);
|
|
85
|
+
}
|
|
86
|
+
return found;
|
|
87
|
+
});
|
|
88
|
+
build.onLoad({ filter: /.*/, namespace: 'file' }, (args) => {
|
|
89
|
+
const file = realpathSync(args.path);
|
|
90
|
+
if (isDependency(file))
|
|
91
|
+
return;
|
|
92
|
+
if (!within(root, file))
|
|
93
|
+
throw new Error('Source file leaves the project');
|
|
94
|
+
const path = relative(root, file).split(sep).join('/');
|
|
95
|
+
assertSourcePath(path);
|
|
96
|
+
// Reuse these same bytes when the view's metadata pass loads the module.
|
|
97
|
+
const contents = files[path] ?? readFileSync(file, 'utf8');
|
|
98
|
+
files[path] = contents;
|
|
99
|
+
if (Buffer.byteLength(JSON.stringify(files), 'utf8') > SOURCE_MAX_BYTES) {
|
|
100
|
+
throw new Error(`Source files exceed ${SOURCE_MAX_BYTES} bytes`);
|
|
101
|
+
}
|
|
102
|
+
return { contents, loader: 'default', resolveDir: dirname(resolve(file)) };
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
return { plugin, source };
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=source-capture.js.map
|
|
@@ -39,12 +39,16 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
39
39
|
const runId = job.run_id;
|
|
40
40
|
if (!runId)
|
|
41
41
|
return { itemsCollected: 0, error: 'agent turn run missing its run id' };
|
|
42
|
-
const fail = async (error) => {
|
|
42
|
+
const fail = async (error, trailing) => {
|
|
43
43
|
const receipt = await client.completeAgentTurn({
|
|
44
44
|
run_id: runId,
|
|
45
45
|
worker_id: client.id,
|
|
46
46
|
status: 'failed',
|
|
47
47
|
error,
|
|
48
|
+
// Whatever evidence was retained rides the failure, so the server holds
|
|
49
|
+
// the prefix that explains the turn. Bounded by construction (the queue
|
|
50
|
+
// below never exceeds the cap); the overflow error names what did not fit.
|
|
51
|
+
...(trailing?.length ? { turn_tool_events: trailing } : {}),
|
|
48
52
|
exit_reason: 'error_message',
|
|
49
53
|
});
|
|
50
54
|
return { itemsCollected: 0, ...(receipt.status === 'completed' ? {} : { error }) };
|
|
@@ -80,11 +84,26 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
80
84
|
let deltaSequence = 0;
|
|
81
85
|
let sending = false;
|
|
82
86
|
// Tool traces waiting for the next beat, oldest first.
|
|
87
|
+
//
|
|
88
|
+
// Bounded and fail-closed: a trace is mandatory external-effect evidence,
|
|
89
|
+
// not a view the turn may shed. The queue (plus the batch in flight) never
|
|
90
|
+
// exceeds `TURN_TOOL_EVENT_QUEUE_MAX`; a turn that would need more latches
|
|
91
|
+
// `toolReceiptOverflow` and fails honestly instead of silently dropping the
|
|
92
|
+
// oldest (the previous `shift()`) or the newest (the previous tail slice).
|
|
83
93
|
let toolEvents = [];
|
|
84
94
|
// Traces handed to a beat that has not answered yet. A beat is fire-and-
|
|
85
95
|
// forget from the delta timer, so one can still be in flight when the turn
|
|
86
96
|
// completes; these come back rather than vanishing in that window.
|
|
87
97
|
let tracesInFlight = [];
|
|
98
|
+
/**
|
|
99
|
+
* Latched when the turn produces more unacknowledged tool traces than the
|
|
100
|
+
* retained receipt capacity holds. The first trace that did not fit is named
|
|
101
|
+
* (its call id and tool), with how many traces could not be retained after
|
|
102
|
+
* it. Once latched the turn cannot complete: the evidence prefix stays
|
|
103
|
+
* queued for the failure report, and the error states that external effects
|
|
104
|
+
* past it are unknown.
|
|
105
|
+
*/
|
|
106
|
+
let toolReceiptOverflow = null;
|
|
88
107
|
/** The delta timer's most recent beat, awaited before the turn completes. */
|
|
89
108
|
let beatInFlight = Promise.resolve();
|
|
90
109
|
/** Arguments of the calls still running, by call id, for the trace their end produces. */
|
|
@@ -139,8 +158,18 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
139
158
|
if (ack?.continue === false)
|
|
140
159
|
stopTurn(ack.stop_reason);
|
|
141
160
|
queueSteering(ack?.steer);
|
|
142
|
-
// The beat was answered,
|
|
143
|
-
|
|
161
|
+
// The beat was answered, but its traces are the server's only when the
|
|
162
|
+
// server says so: `turn_tool_ack.received` names how many of the sent
|
|
163
|
+
// traces it durably stored. Anything unacknowledged stays queued for the
|
|
164
|
+
// next beat (or the completion below) instead of being dropped — a
|
|
165
|
+
// liveness-only beat carries no ack and retires nothing.
|
|
166
|
+
const received = ack?.turn_tool_ack?.received;
|
|
167
|
+
if (received !== undefined && received >= traces.length) {
|
|
168
|
+
tracesInFlight = [];
|
|
169
|
+
}
|
|
170
|
+
else if (received !== undefined && received > 0) {
|
|
171
|
+
tracesInFlight = traces.slice(received);
|
|
172
|
+
}
|
|
144
173
|
}
|
|
145
174
|
catch (err) {
|
|
146
175
|
// The batch stays in flight and is re-sent under the same sequence, and
|
|
@@ -152,11 +181,17 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
152
181
|
finally {
|
|
153
182
|
// Anything this beat could not retire goes back to the front of the
|
|
154
183
|
// queue: it is older than whatever arrived while the beat was in flight.
|
|
184
|
+
// Never truncated silently: the push-time capacity check below keeps the
|
|
185
|
+
// retained total within the cap, so an excess here is a bookkeeping
|
|
186
|
+
// surprise — latch it as overflow (fail closed) rather than slicing it
|
|
187
|
+
// away.
|
|
155
188
|
if (tracesInFlight.length) {
|
|
156
189
|
toolEvents = [...tracesInFlight, ...toolEvents];
|
|
157
190
|
tracesInFlight = [];
|
|
158
191
|
if (toolEvents.length > TURN_TOOL_EVENT_QUEUE_MAX) {
|
|
159
|
-
|
|
192
|
+
const excess = toolEvents.length - TURN_TOOL_EVENT_QUEUE_MAX;
|
|
193
|
+
toolEvents = toolEvents.slice(0, TURN_TOOL_EVENT_QUEUE_MAX);
|
|
194
|
+
noteToolReceiptOverflow("(requeued)", "requeued tool traces", excess);
|
|
160
195
|
}
|
|
161
196
|
}
|
|
162
197
|
sending = false;
|
|
@@ -244,6 +279,28 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
244
279
|
log.info(`[agent-turn] run ${runId} stopping: ${reason ?? 'the gateway said stop'}`);
|
|
245
280
|
cancel.abort();
|
|
246
281
|
};
|
|
282
|
+
/**
|
|
283
|
+
* Latch receipt-capacity overflow and stop the turn. The queue itself stays
|
|
284
|
+
* bounded (the trace that did not fit is NOT queued); its identity and the
|
|
285
|
+
* running dropped count are retained here so the failure report names the
|
|
286
|
+
* evidence that is missing instead of dropping it silently.
|
|
287
|
+
*/
|
|
288
|
+
const noteToolReceiptOverflow = (toolCallId, name, dropped = 1) => {
|
|
289
|
+
if (toolReceiptOverflow)
|
|
290
|
+
toolReceiptOverflow.dropped += dropped;
|
|
291
|
+
else
|
|
292
|
+
toolReceiptOverflow = { toolCallId, name, dropped };
|
|
293
|
+
stopTurn('tool receipt capacity exceeded');
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* The honest failure for a turn that outgrew its retained receipt capacity:
|
|
297
|
+
* the retained prefix is the evidence, and the error states that external
|
|
298
|
+
* effects past it are unknown — never a completed turn with a hole in it.
|
|
299
|
+
*/
|
|
300
|
+
const toolOverflowError = () => `agent turn exceeded its retained tool receipt capacity (${TURN_TOOL_EVENT_QUEUE_MAX} traces): ` +
|
|
301
|
+
`${toolReceiptOverflow?.dropped ?? 0} trace(s) could not be retained, starting with ` +
|
|
302
|
+
`${toolReceiptOverflow?.toolCallId ?? 'unknown'} (${toolReceiptOverflow?.name ?? 'unknown'}); ` +
|
|
303
|
+
`external effects past the retained prefix are unknown`;
|
|
247
304
|
try {
|
|
248
305
|
const guestCode = await agentGuestBundle();
|
|
249
306
|
// Same executor seam every other lane uses (`resolveJobExecution`): an
|
|
@@ -443,21 +500,31 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
443
500
|
// The server turns it into the established `tool_use` custom event,
|
|
444
501
|
// so the SPA, promptfoo provider and menubar keep one trace shape.
|
|
445
502
|
//
|
|
446
|
-
// Bounded
|
|
447
|
-
//
|
|
448
|
-
//
|
|
503
|
+
// Bounded and fail-closed: the queue plus the batch in flight never
|
|
504
|
+
// exceed the cap. A trace that would not fit latches overflow and
|
|
505
|
+
// stops the turn instead of dropping evidence — the retained prefix
|
|
506
|
+
// rides the failure report, and the error names what is missing.
|
|
507
|
+
// Traces already latched as overflow are counted, not queued, so
|
|
508
|
+
// the queue stays bounded after the latch too.
|
|
449
509
|
const input = toolArgs.get(event.toolCallId);
|
|
450
510
|
toolArgs.delete(event.toolCallId);
|
|
511
|
+
if (toolReceiptOverflow) {
|
|
512
|
+
toolReceiptOverflow.dropped += 1;
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
if (toolEvents.length + tracesInFlight.length >= TURN_TOOL_EVENT_QUEUE_MAX) {
|
|
516
|
+
noteToolReceiptOverflow(event.toolCallId, event.name);
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
451
519
|
toolEvents.push({
|
|
452
520
|
tool_call_id: event.toolCallId,
|
|
453
521
|
name: event.name,
|
|
522
|
+
...(event.inputRunId !== undefined ? { input_run_id: event.inputRunId } : {}),
|
|
454
523
|
...(input !== undefined ? { input } : {}),
|
|
455
524
|
is_error: event.isError,
|
|
456
525
|
output: event.output,
|
|
457
526
|
...(event.resultSummary ? { result_summary: event.resultSummary } : {}),
|
|
458
527
|
});
|
|
459
|
-
if (toolEvents.length > TURN_TOOL_EVENT_QUEUE_MAX)
|
|
460
|
-
toolEvents.shift();
|
|
461
528
|
}
|
|
462
529
|
},
|
|
463
530
|
});
|
|
@@ -479,6 +546,16 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
479
546
|
clearInterval(heartbeat);
|
|
480
547
|
await beatInFlight;
|
|
481
548
|
await drainDeltas();
|
|
549
|
+
// A turn that outgrew its retained receipt capacity cannot complete: the
|
|
550
|
+
// retained prefix rides a FAILED completion whose error states that
|
|
551
|
+
// external effects past it are unknown. Completing it would deliver an
|
|
552
|
+
// answer with a hole in its evidence.
|
|
553
|
+
if (toolReceiptOverflow) {
|
|
554
|
+
const retained = [...tracesInFlight, ...toolEvents].slice(0, TURN_TOOL_EVENT_QUEUE_MAX);
|
|
555
|
+
tracesInFlight = [];
|
|
556
|
+
toolEvents = [];
|
|
557
|
+
return fail(toolOverflowError(), retained);
|
|
558
|
+
}
|
|
482
559
|
// Whatever drainDeltas could not place rides the completion instead of
|
|
483
560
|
// being dropped. A trace can remain when no text delta triggered a drain
|
|
484
561
|
// or its beat could not deliver. Heartbeat publishing requires the run
|
|
@@ -497,8 +574,12 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
497
574
|
usage: result.turn.usage,
|
|
498
575
|
session_jsonl: result.turn.sessionJsonl,
|
|
499
576
|
tools_used: result.turn.toolsUsed,
|
|
577
|
+
...(result.turn.firstError ? { first_error: result.turn.firstError } : {}),
|
|
500
578
|
consumed_inputs: result.turn.consumedInputs.map((input) => ({
|
|
501
579
|
run_id: input.runId, session_entry_id: input.sessionEntryId,
|
|
580
|
+
response_text: input.responseText,
|
|
581
|
+
tools_used: input.toolsUsed,
|
|
582
|
+
...(input.firstError ? { first_error: input.firstError } : {}),
|
|
502
583
|
})),
|
|
503
584
|
...(result.turn.repliedInBand ? { replied_in_band: true } : {}),
|
|
504
585
|
exit_reason: 'ok',
|
|
@@ -509,7 +590,13 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
509
590
|
return { itemsCollected: 0 };
|
|
510
591
|
}
|
|
511
592
|
catch (error) {
|
|
512
|
-
|
|
593
|
+
// Any failure reports the retained receipt prefix. A provider/runtime
|
|
594
|
+
// error after a tool finished must not erase mandatory external-effect
|
|
595
|
+
// evidence merely because the queue did not overflow.
|
|
596
|
+
const retained = [...tracesInFlight, ...toolEvents].slice(0, TURN_TOOL_EVENT_QUEUE_MAX);
|
|
597
|
+
if (toolReceiptOverflow)
|
|
598
|
+
return fail(toolOverflowError(), retained);
|
|
599
|
+
return fail(error instanceof Error ? error.message : String(error), retained);
|
|
513
600
|
}
|
|
514
601
|
finally {
|
|
515
602
|
clearInterval(deltaTimer);
|
|
@@ -34,7 +34,7 @@ import { type AutomationAcpAdapters } from './automation-acp.js';
|
|
|
34
34
|
*
|
|
35
35
|
* Declared narrowly so a caller that only executes automations — the one-shot
|
|
36
36
|
* `executeClaimedAutomationRun` entry point — does not have to fabricate
|
|
37
|
-
* connector-sync fields (`
|
|
37
|
+
* connector-sync fields (`generateEmbeddings`)
|
|
38
38
|
* that this arm never touches. The daemon's full `ExecutorConfig` is
|
|
39
39
|
* structurally assignable to it.
|
|
40
40
|
*/
|
|
@@ -36,7 +36,6 @@ type JobCodeResult = {
|
|
|
36
36
|
};
|
|
37
37
|
export declare function resolveJobCode(job: PollResponse): Promise<JobCodeResult>;
|
|
38
38
|
export interface ExecutorConfig {
|
|
39
|
-
batchSize: number;
|
|
40
39
|
heartbeatIntervalMs: number;
|
|
41
40
|
/** Test-only override; production deliberately uses the 15-second default. */
|
|
42
41
|
terminalHeartbeatGraceMs?: number;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Executes sync and action runs in a V8 isolate from compiled connector code.
|
|
5
5
|
* Generates embeddings and streams results.
|
|
6
6
|
*/
|
|
7
|
+
import { stableStringify } from '@lobu/core/contracts/tools/view-content-hash';
|
|
7
8
|
import { executeAutomationRun } from './automation.js';
|
|
8
9
|
import { executeDaemonBuiltin, hasDaemonBuiltin, hasDaemonBuiltinConnector, } from './builtins/index.js';
|
|
9
10
|
import { executeAgentTurnRun } from './agent-turn.js';
|
|
@@ -90,7 +91,6 @@ async function resolveJobExecution(select, job, timeoutMs, customExecutor) {
|
|
|
90
91
|
* copy of these numbers that is free to drift away from them.
|
|
91
92
|
*/
|
|
92
93
|
export const DEFAULT_CONFIG = {
|
|
93
|
-
batchSize: 10,
|
|
94
94
|
heartbeatIntervalMs: 30000,
|
|
95
95
|
generateEmbeddings: true,
|
|
96
96
|
timeoutMs: 600000,
|
|
@@ -135,6 +135,24 @@ export function resolveEffectiveEnv(env, job) {
|
|
|
135
135
|
};
|
|
136
136
|
return effective === 'block-private' && job.compiled_code ? withoutDeploymentProviderKeys(merged) : merged;
|
|
137
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Whether a sync pass moved the feed's cursor. `more` asks for an immediate
|
|
140
|
+
* rerun, which is progress only when this pass committed a checkpoint other
|
|
141
|
+
* than the one it started from; a pass that re-committed its starting cursor
|
|
142
|
+
* would otherwise rerun forever. `source_ack` is the platform's record, not the
|
|
143
|
+
* connector's cursor, so it does not count.
|
|
144
|
+
*/
|
|
145
|
+
function cursorAdvanced(started, committed) {
|
|
146
|
+
if (committed === null)
|
|
147
|
+
return false;
|
|
148
|
+
const cursor = (value) => {
|
|
149
|
+
if (!value || typeof value !== 'object')
|
|
150
|
+
return stableStringify(value);
|
|
151
|
+
const { source_ack: _ack, ...rest } = value;
|
|
152
|
+
return stableStringify(rest);
|
|
153
|
+
};
|
|
154
|
+
return cursor(committed) !== cursor(started);
|
|
155
|
+
}
|
|
138
156
|
/**
|
|
139
157
|
* Execute a run (sync, action, automation, embed_backfill, or auth).
|
|
140
158
|
*
|
|
@@ -255,28 +273,10 @@ async function executeSyncRun(client, job, env, cfg) {
|
|
|
255
273
|
};
|
|
256
274
|
startHeartbeat();
|
|
257
275
|
try {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
return;
|
|
263
|
-
try {
|
|
264
|
-
await client.stream({
|
|
265
|
-
type: 'batch',
|
|
266
|
-
run_id,
|
|
267
|
-
worker_id: client.id,
|
|
268
|
-
items: batch,
|
|
269
|
-
checkpoint: lastCheckpoint ?? undefined,
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
catch (streamErr) {
|
|
273
|
-
const batchIds = batch.map((b) => b.id);
|
|
274
|
-
log.debug(`[executor] Stream batch failed for run ${run_id} (${batchIds.length} items lost: ${batchIds.join(', ')}):`, streamErr);
|
|
275
|
-
const msg = streamErr instanceof Error ? streamErr.message : String(streamErr);
|
|
276
|
-
throw new Error(`Stream batch failed: ${msg} (lost ${batchIds.length} items: ${batchIds.join(', ')})`);
|
|
277
|
-
}
|
|
278
|
-
batch = [];
|
|
279
|
-
};
|
|
276
|
+
// The last checkpoint a commit made durable. Completion re-sends it so the
|
|
277
|
+
// feed's `source_ack`, which only a successful completion may advance,
|
|
278
|
+
// moves with it.
|
|
279
|
+
let committedCheckpoint = null;
|
|
280
280
|
const result = await executeCompiledConnector({
|
|
281
281
|
compiledCode: compiled_code,
|
|
282
282
|
executor: laneExecutor,
|
|
@@ -292,32 +292,24 @@ async function executeSyncRun(client, job, env, cfg) {
|
|
|
292
292
|
entityIds: job.entity_ids ?? [],
|
|
293
293
|
},
|
|
294
294
|
hooks: {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
295
|
+
// One chunk of a `ctx.commit`, sent as one page: the gateway stores its
|
|
296
|
+
// events and checkpoint in one transaction or not at all. Any failure
|
|
297
|
+
// propagates and ends the run; the next run resumes from the last
|
|
298
|
+
// checkpoint that did land.
|
|
299
|
+
onCommit: async (events, nextCheckpoint) => {
|
|
300
|
+
const items = await processEventChunk(events, cfg.generateEmbeddings);
|
|
301
|
+
if (items.length === 0 && !nextCheckpoint)
|
|
298
302
|
return;
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
log.debug('[executor] Checkpoint flush failed:', err);
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
onEventChunk: async (events) => {
|
|
313
|
-
const contentItems = await processEventChunk(events, cfg.generateEmbeddings);
|
|
314
|
-
for (const contentItem of contentItems) {
|
|
315
|
-
batch.push(contentItem);
|
|
316
|
-
itemsCollectedSoFar++;
|
|
317
|
-
if (batch.length >= cfg.batchSize) {
|
|
318
|
-
await flushBatch();
|
|
319
|
-
}
|
|
320
|
-
}
|
|
303
|
+
await client.stream({
|
|
304
|
+
type: 'batch',
|
|
305
|
+
run_id,
|
|
306
|
+
worker_id: client.id,
|
|
307
|
+
items,
|
|
308
|
+
...(nextCheckpoint ? { checkpoint: nextCheckpoint } : {}),
|
|
309
|
+
});
|
|
310
|
+
itemsCollectedSoFar += items.length;
|
|
311
|
+
if (nextCheckpoint)
|
|
312
|
+
committedCheckpoint = nextCheckpoint;
|
|
321
313
|
},
|
|
322
314
|
onChromeDispatch: async (actionKey, actionInput) => {
|
|
323
315
|
// Forward to the gateway's dispatch endpoint. The endpoint
|
|
@@ -337,15 +329,14 @@ async function executeSyncRun(client, job, env, cfg) {
|
|
|
337
329
|
if (result.mode !== 'sync') {
|
|
338
330
|
throw new Error(`Expected sync result, got mode=${result.mode}`);
|
|
339
331
|
}
|
|
340
|
-
lastCheckpoint = result.checkpoint;
|
|
341
|
-
await flushBatch();
|
|
342
332
|
stopHeartbeat();
|
|
343
333
|
await client.complete({
|
|
344
334
|
run_id,
|
|
345
335
|
worker_id: client.id,
|
|
346
336
|
status: 'success',
|
|
347
337
|
items_collected: itemsCollectedSoFar,
|
|
348
|
-
checkpoint:
|
|
338
|
+
checkpoint: committedCheckpoint ?? undefined,
|
|
339
|
+
...(result.status === 'more' && cursorAdvanced(checkpoint, committedCheckpoint) ? { more: true } : {}),
|
|
349
340
|
auth_update: result.auth_update ?? undefined,
|
|
350
341
|
error_message: partialFetchFailureMessage(result.metadata),
|
|
351
342
|
});
|
|
@@ -91,9 +91,13 @@ export async function startDaemonCommand(opts) {
|
|
|
91
91
|
// new run type from handing one to a worker binary that predates the lane:
|
|
92
92
|
// the two sides agree by string equality, so an old worker never matches and
|
|
93
93
|
// its dispatch default (a connector sync) is never reached.
|
|
94
|
+
// `agent_turn_per_input_responses` marks per-input attribution (#3662): one
|
|
95
|
+
// terminal reply, tool ledger, and verbatim first error per consumed input.
|
|
96
|
+
// The server negotiates by receipt presence, not by this flag, so old claims
|
|
97
|
+
// keep draining under the single-reply contract they were admitted with.
|
|
94
98
|
const workerCapabilities = platform
|
|
95
99
|
? Object.fromEntries(capabilities.map((name) => [name, true]))
|
|
96
|
-
: { db_egress_hardening: true, agent_turn: true };
|
|
100
|
+
: { db_egress_hardening: true, agent_turn: true, agent_turn_per_input_responses: true };
|
|
97
101
|
// Auto-discover device identity from the host when not passed: a device
|
|
98
102
|
// worker defaults to `<platform>:<short-hostname>` and a hostname label. An
|
|
99
103
|
// interactive daemon instead derives its id from the exact inherited
|
|
@@ -87,13 +87,13 @@ export type ExecutorJob = {
|
|
|
87
87
|
/**
|
|
88
88
|
* Result shape returned by the executor. One discriminated union per mode
|
|
89
89
|
* mirrors the SDK's `ActionResult` / `AuthResult` directly. Sync is
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* hook (see e.g. `packages/cli/src/commands/_lib/connector-run-cmd.ts`).
|
|
90
|
+
* commit-only: events and checkpoints leave through `hooks.onCommit` as the
|
|
91
|
+
* connector commits them, never collected onto the result.
|
|
93
92
|
*/
|
|
94
93
|
export type ExecutorResult = {
|
|
95
94
|
mode: 'sync';
|
|
96
|
-
|
|
95
|
+
/** How the pass ended; see the SDK's `SyncResult.status`. */
|
|
96
|
+
status: 'complete' | 'more';
|
|
97
97
|
auth_update?: Record<string, unknown> | null;
|
|
98
98
|
metadata?: Record<string, unknown>;
|
|
99
99
|
} | {
|
|
@@ -166,10 +166,14 @@ export interface ExecutionHooks {
|
|
|
166
166
|
* turn's own token — so the guest never holds a credential or an egress.
|
|
167
167
|
*/
|
|
168
168
|
onRuntimeExec?: (request: RuntimeExecRequest) => Promise<RuntimeExecResult>;
|
|
169
|
-
/**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Sync runs: persist one chunk of a `ctx.commit` — its events and, on the
|
|
171
|
+
* chunk that completes the commit, the checkpoint (`null` otherwise, and
|
|
172
|
+
* when the connector left the checkpoint unchanged). Resolve only once both
|
|
173
|
+
* are durable; a rejection terminates the run, so the connector never
|
|
174
|
+
* proceeds past a commit that did not land.
|
|
175
|
+
*/
|
|
176
|
+
onCommit?: (events: EventEnvelope[], checkpoint: Record<string, unknown> | null) => Promise<void> | void;
|
|
173
177
|
/** Auth runs: connector emitted an artifact (QR/redirect/prompt/status). */
|
|
174
178
|
onAuthArtifact?: (artifact: Record<string, unknown>) => Promise<void> | void;
|
|
175
179
|
/** Auth runs: connector paused until a named signal arrives. */
|
|
@@ -115,14 +115,30 @@ const GUEST_RUNNER = String.raw `
|
|
|
115
115
|
return out;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
// One commit may carry more events than one bridge message should. Every
|
|
119
|
+
// chunk but the last travels without a checkpoint, so the cursor moves only
|
|
120
|
+
// with the chunk that completes the page: an earlier chunk that lands alone
|
|
121
|
+
// is re-sent by the next run and superseded by origin_id.
|
|
122
|
+
// Serialized: a commit waits for the one before it, so checkpoints land in
|
|
123
|
+
// call order even when a connector does not await.
|
|
124
|
+
var commitTail = Promise.resolve();
|
|
125
|
+
function commit(events, checkpoint) {
|
|
126
|
+
if (!Array.isArray(events)) {
|
|
127
|
+
return Promise.reject(new TypeError('ctx.commit(events, checkpoint): events must be an array'));
|
|
121
128
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
129
|
+
var checkpointJson = JSON.stringify(checkpoint === undefined ? null : checkpoint);
|
|
130
|
+
var run = commitTail.then(async function () {
|
|
131
|
+
if (events.length === 0) {
|
|
132
|
+
await H.async('commitPage', '[]', checkpointJson);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
for (var index = 0; index < events.length; index += EVENT_CHUNK_SIZE) {
|
|
136
|
+
var last = index + EVENT_CHUNK_SIZE >= events.length;
|
|
137
|
+
await H.async('commitPage', JSON.stringify(events.slice(index, index + EVENT_CHUNK_SIZE)), last ? checkpointJson : 'null');
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
commitTail = run.catch(function () {});
|
|
141
|
+
return run;
|
|
126
142
|
}
|
|
127
143
|
|
|
128
144
|
async function executeConnectorRuntime(instance) {
|
|
@@ -204,20 +220,25 @@ const GUEST_RUNNER = String.raw `
|
|
|
204
220
|
credentials: job.credentials,
|
|
205
221
|
entityIds: job.entityIds,
|
|
206
222
|
sessionState: withDispatcher(job.sessionState),
|
|
207
|
-
|
|
208
|
-
updateCheckpoint: updateCheckpoint
|
|
223
|
+
commit: commit
|
|
209
224
|
});
|
|
210
|
-
|
|
211
|
-
await
|
|
225
|
+
// A commit the connector fired without awaiting still belongs to this pass.
|
|
226
|
+
await commitTail;
|
|
227
|
+
if (syncResult && ('events' in syncResult || 'checkpoint' in syncResult)) {
|
|
228
|
+
// Returned events were never committed; reporting success would store
|
|
229
|
+
// nothing while the run looked healthy.
|
|
230
|
+
throw new Error('sync() returned events/checkpoint: commit each page with ctx.commit(events, checkpoint) and return { status }');
|
|
231
|
+
}
|
|
232
|
+
var status = syncResult && syncResult.status;
|
|
233
|
+
if (status !== 'complete' && status !== 'more') {
|
|
234
|
+
throw new Error("sync() must return { status: 'complete' | 'more' }, got " + JSON.stringify(status));
|
|
235
|
+
}
|
|
212
236
|
var meta = (syncResult && syncResult.metadata) || {};
|
|
213
237
|
return {
|
|
214
238
|
mode: 'sync',
|
|
215
|
-
|
|
216
|
-
auth_update: syncResult
|
|
217
|
-
metadata:
|
|
218
|
-
items_found: typeof meta.items_found === 'number' ? meta.items_found : trailingEvents.length,
|
|
219
|
-
items_skipped: typeof meta.items_skipped === 'number' ? meta.items_skipped : 0
|
|
220
|
-
}, meta)
|
|
239
|
+
status: status,
|
|
240
|
+
auth_update: syncResult.auth_update !== undefined ? syncResult.auth_update : null,
|
|
241
|
+
metadata: meta
|
|
221
242
|
};
|
|
222
243
|
}
|
|
223
244
|
|
|
@@ -653,11 +674,15 @@ export class IsolateExecutor {
|
|
|
653
674
|
pendingSleeps.add(timer);
|
|
654
675
|
});
|
|
655
676
|
},
|
|
656
|
-
|
|
657
|
-
|
|
677
|
+
commitPage: async (eventsJson, checkpointJson) => {
|
|
678
|
+
if (!hooks?.onCommit)
|
|
679
|
+
throw new Error('ctx.commit is not available in this execution context');
|
|
680
|
+
const parsed = parseGuestJson(eventsJson, 'commitPage');
|
|
658
681
|
const events = Array.isArray(parsed) ? parsed : [];
|
|
682
|
+
const next = parseGuestJson(checkpointJson, 'commitPage');
|
|
683
|
+
const checkpoint = next && typeof next === 'object' ? next : null;
|
|
659
684
|
await queueHook(async () => {
|
|
660
|
-
await hooks?.
|
|
685
|
+
await hooks.onCommit?.(events, checkpoint);
|
|
661
686
|
});
|
|
662
687
|
return undefined;
|
|
663
688
|
},
|
|
@@ -681,14 +706,6 @@ export class IsolateExecutor {
|
|
|
681
706
|
});
|
|
682
707
|
return undefined;
|
|
683
708
|
},
|
|
684
|
-
updateCheckpoint: async (json) => {
|
|
685
|
-
const parsed = parseGuestJson(json, 'updateCheckpoint');
|
|
686
|
-
const checkpoint = parsed && typeof parsed === 'object' ? parsed : null;
|
|
687
|
-
await queueHook(async () => {
|
|
688
|
-
await hooks?.onCheckpointUpdate?.(checkpoint);
|
|
689
|
-
});
|
|
690
|
-
return undefined;
|
|
691
|
-
},
|
|
692
709
|
emitAuthArtifact: async (json) => {
|
|
693
710
|
const parsed = parseGuestJson(json, 'emitAuthArtifact');
|
|
694
711
|
const artifact = parsed && typeof parsed === 'object' ? parsed : {};
|