@lobu/runtime-device 20.2.0 → 21.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/dist/component.json +1 -1
- package/dist/dependencies.bun.lock +44 -38
- package/npm-shrinkwrap.json +277 -231
- 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 -79
- package/vendor/cli/dist/commands/_lib/apply/client.d.ts +41 -29
- package/vendor/cli/dist/commands/_lib/apply/client.js +33 -47
- package/vendor/cli/dist/commands/_lib/apply/deployment.d.ts +1 -1
- package/vendor/cli/dist/commands/_lib/apply/deployment.js +2 -3
- package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +47 -13
- package/vendor/cli/dist/commands/_lib/apply/desired-state.js +106 -7
- package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +14 -7
- package/vendor/cli/dist/commands/_lib/apply/diff.js +42 -29
- 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 +211 -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/commands/memory/_lib/schema.d.ts +0 -1
- package/vendor/cli/dist/commands/memory/_lib/schema.js +0 -9
- package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +0 -2
- 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 +274 -193
- package/vendor/cli/dist/connectors/google_calendar.ts +54 -160
- 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 +71 -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 +11 -7
- package/vendor/cli/dist/connectors/reddit.ts +36 -6
- 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/providers.json +0 -1
- 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 -15
- 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/client.d.ts +4 -1
- package/vendor/connector-worker/dist/daemon/client.js +3 -0
- package/vendor/connector-worker/dist/daemon/executor.d.ts +0 -1
- package/vendor/connector-worker/dist/daemon/executor.js +46 -51
- package/vendor/connector-worker/dist/daemon/start.js +6 -2
- package/vendor/connector-worker/dist/executor/interface.d.ts +19 -9
- package/vendor/connector-worker/dist/executor/isolate.js +85 -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-auth-profiles.d.ts +14 -0
- package/vendor/core/dist/contracts/tools/manage-auth-profiles.js +12 -1
- package/vendor/core/dist/contracts/tools/manage-automations.d.ts +0 -10
- package/vendor/core/dist/contracts/tools/manage-automations.js +0 -33
- package/vendor/core/dist/contracts/tools/manage-classifiers.d.ts +4 -34
- package/vendor/core/dist/contracts/tools/manage-classifiers.js +13 -44
- 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-entity.d.ts +0 -9
- package/vendor/core/dist/contracts/tools/manage-entity.js +0 -6
- 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-attach.d.ts +20 -0
- package/vendor/core/dist/contracts/tools/view-attach.js +45 -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 +90 -8
- package/vendor/core/dist/contracts/worker/protocol.js +70 -10
- package/vendor/core/dist/index.d.ts +1 -1
- package/vendor/core/dist/provider-config-types.d.ts +0 -9
- package/vendor/core/dist/reserved.d.ts +3 -3
- package/vendor/core/dist/reserved.js +9 -1
- package/vendor/core/dist/sdk-compat.d.ts +1 -1
- package/vendor/core/dist/utils/secret-redaction.js +2 -0
- package/vendor/core/package.json +30 -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
|
@@ -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
|
*/
|
|
@@ -40,6 +40,8 @@ export interface ExecutorClient {
|
|
|
40
40
|
* — multi-replica safe because the wait is Postgres-mediated.
|
|
41
41
|
*/
|
|
42
42
|
dispatchChromeAction(req: DispatchChromeActionRequest): Promise<Record<string, unknown>>;
|
|
43
|
+
/** Spend only the current run's gateway-held HTTP credentials. */
|
|
44
|
+
httpFetch(runId: number, request: ConnectorHttpRequest, signal?: AbortSignal): Promise<ConnectorHttpResponse>;
|
|
43
45
|
/**
|
|
44
46
|
* Post a device-side automation exit report and read the server's decision.
|
|
45
47
|
* `status: "resume"` means the run is still claimed and the caller should
|
|
@@ -67,7 +69,7 @@ export interface ExecutorClient {
|
|
|
67
69
|
* its request-body reads with the same shapes from that file.
|
|
68
70
|
*/
|
|
69
71
|
export type { CompleteActionRequest, CompleteAgentTurnRequest, CompleteAgentTurnResponse, CompleteAuthRequest, CompleteAutomationRequest, CompleteAutomationResponse, CompleteDeviceChatRequest, CompleteDeviceChatResponse, CompleteEmbeddingsRequest, CompleteRequest, ContentItem, DispatchChromeActionRequest, DispatchChromeActionResponse, EmbedEvent, EmitAuthArtifactRequest, HeartbeatRequest, HeartbeatResponse, OAuthCredentials, PollAuthSignalRequest, PollAuthSignalResponse, PollResponse, StreamBatch, } from "@lobu/core/contracts/worker/protocol";
|
|
70
|
-
import type { CompleteActionRequest, CompleteAgentTurnRequest, CompleteAgentTurnResponse, CompleteAuthRequest, CompleteAutomationRequest, CompleteAutomationResponse, CompleteDeviceChatRequest, CompleteDeviceChatResponse, CompleteEmbeddingsRequest, CompleteRequest, DispatchChromeActionRequest, EmbedEvent, EmitAuthArtifactRequest, HeartbeatRequest, HeartbeatResponse, PollAuthSignalRequest, PollAuthSignalResponse, PollResponse, StreamBatch } from "@lobu/core/contracts/worker/protocol";
|
|
72
|
+
import type { ConnectorHttpRequest, ConnectorHttpResponse, CompleteActionRequest, CompleteAgentTurnRequest, CompleteAgentTurnResponse, CompleteAuthRequest, CompleteAutomationRequest, CompleteAutomationResponse, CompleteDeviceChatRequest, CompleteDeviceChatResponse, CompleteEmbeddingsRequest, CompleteRequest, DispatchChromeActionRequest, EmbedEvent, EmitAuthArtifactRequest, HeartbeatRequest, HeartbeatResponse, PollAuthSignalRequest, PollAuthSignalResponse, PollResponse, StreamBatch } from "@lobu/core/contracts/worker/protocol";
|
|
71
73
|
import type { AgentKind } from "@lobu/core/contracts/worker/device-automation";
|
|
72
74
|
/** Capability strings the worker advertises, keyed by name (e.g. `browser.debugger`). */
|
|
73
75
|
export type WorkerCapabilities = Record<string, boolean>;
|
|
@@ -227,6 +229,7 @@ export declare class WorkerClient implements ExecutorClient {
|
|
|
227
229
|
* times out. Throws on failure/timeout with the gateway's error message.
|
|
228
230
|
*/
|
|
229
231
|
dispatchChromeAction(req: DispatchChromeActionRequest): Promise<Record<string, unknown>>;
|
|
232
|
+
httpFetch(runId: number, request: ConnectorHttpRequest, signal?: AbortSignal): Promise<ConnectorHttpResponse>;
|
|
230
233
|
/**
|
|
231
234
|
* Health check
|
|
232
235
|
*/
|
|
@@ -311,6 +311,9 @@ export class WorkerClient {
|
|
|
311
311
|
throw new Error(result.error_message ??
|
|
312
312
|
`Chrome action '${req.action_key}' ${result.status === 'timeout' ? 'timed out' : 'failed'}`);
|
|
313
313
|
}
|
|
314
|
+
async httpFetch(runId, request, signal) {
|
|
315
|
+
return this.requestJson('/api/workers/http-fetch', { worker_id: this.id, run_id: runId, request }, signal);
|
|
316
|
+
}
|
|
314
317
|
/**
|
|
315
318
|
* Health check
|
|
316
319
|
*/
|
|
@@ -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,33 +273,16 @@ 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,
|
|
283
283
|
job: {
|
|
284
284
|
mode: 'sync',
|
|
285
|
+
httpAuth: job.http_auth,
|
|
285
286
|
config: mergeEnv(env, job.connection_credentials, feedConfig),
|
|
286
287
|
checkpoint: checkpoint,
|
|
287
288
|
env,
|
|
@@ -292,32 +293,25 @@ async function executeSyncRun(client, job, env, cfg) {
|
|
|
292
293
|
entityIds: job.entity_ids ?? [],
|
|
293
294
|
},
|
|
294
295
|
hooks: {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
296
|
+
...(job.http_auth ? { onHttpFetch: (request, signal) => client.httpFetch(run_id, request, signal) } : {}),
|
|
297
|
+
// One chunk of a `ctx.commit`, sent as one page: the gateway stores its
|
|
298
|
+
// events and checkpoint in one transaction or not at all. Any failure
|
|
299
|
+
// propagates and ends the run; the next run resumes from the last
|
|
300
|
+
// checkpoint that did land.
|
|
301
|
+
onCommit: async (events, nextCheckpoint) => {
|
|
302
|
+
const items = await processEventChunk(events, cfg.generateEmbeddings);
|
|
303
|
+
if (items.length === 0 && !nextCheckpoint)
|
|
298
304
|
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
|
-
}
|
|
305
|
+
await client.stream({
|
|
306
|
+
type: 'batch',
|
|
307
|
+
run_id,
|
|
308
|
+
worker_id: client.id,
|
|
309
|
+
items,
|
|
310
|
+
...(nextCheckpoint ? { checkpoint: nextCheckpoint } : {}),
|
|
311
|
+
});
|
|
312
|
+
itemsCollectedSoFar += items.length;
|
|
313
|
+
if (nextCheckpoint)
|
|
314
|
+
committedCheckpoint = nextCheckpoint;
|
|
321
315
|
},
|
|
322
316
|
onChromeDispatch: async (actionKey, actionInput) => {
|
|
323
317
|
// Forward to the gateway's dispatch endpoint. The endpoint
|
|
@@ -337,15 +331,14 @@ async function executeSyncRun(client, job, env, cfg) {
|
|
|
337
331
|
if (result.mode !== 'sync') {
|
|
338
332
|
throw new Error(`Expected sync result, got mode=${result.mode}`);
|
|
339
333
|
}
|
|
340
|
-
lastCheckpoint = result.checkpoint;
|
|
341
|
-
await flushBatch();
|
|
342
334
|
stopHeartbeat();
|
|
343
335
|
await client.complete({
|
|
344
336
|
run_id,
|
|
345
337
|
worker_id: client.id,
|
|
346
338
|
status: 'success',
|
|
347
339
|
items_collected: itemsCollectedSoFar,
|
|
348
|
-
checkpoint:
|
|
340
|
+
checkpoint: committedCheckpoint ?? undefined,
|
|
341
|
+
...(result.status === 'more' && cursorAdvanced(checkpoint, committedCheckpoint) ? { more: true } : {}),
|
|
349
342
|
auth_update: result.auth_update ?? undefined,
|
|
350
343
|
error_message: partialFetchFailureMessage(result.metadata),
|
|
351
344
|
});
|
|
@@ -453,6 +446,7 @@ async function executeActionRun(client, job, env, cfg) {
|
|
|
453
446
|
executor: laneExecutor,
|
|
454
447
|
job: {
|
|
455
448
|
mode: 'action',
|
|
449
|
+
httpAuth: job.http_auth,
|
|
456
450
|
// NOTE: unlike the gateway's inline action path (manage_operations
|
|
457
451
|
// `executeLocalActionInline`, which merges the connection's own config
|
|
458
452
|
// so an action can read e.g. a `restaurants_url`), this worker-fleet
|
|
@@ -472,6 +466,7 @@ async function executeActionRun(client, job, env, cfg) {
|
|
|
472
466
|
credentials: credentials ?? null,
|
|
473
467
|
},
|
|
474
468
|
hooks: {
|
|
469
|
+
...(job.http_auth ? { onHttpFetch: (request, signal) => client.httpFetch(run_id, request, signal) } : {}),
|
|
475
470
|
onChromeDispatch: async (actionKey, actionInput) => {
|
|
476
471
|
return client.dispatchChromeAction({
|
|
477
472
|
parent_run_id: run_id,
|
|
@@ -7,7 +7,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
7
7
|
import { createRequire } from 'node:module';
|
|
8
8
|
import { hostname } from 'node:os';
|
|
9
9
|
import { isKnownPlatform } from '@lobu/core';
|
|
10
|
-
import { EXECUTION_BACKENDS, } from '@lobu/core/contracts/worker/protocol';
|
|
10
|
+
import { CONNECTOR_HTTP_AUTH_CAPABILITY, EXECUTION_BACKENDS, } from '@lobu/core/contracts/worker/protocol';
|
|
11
11
|
import { assertExternalDepsResolvable } from '../compile/index.js';
|
|
12
12
|
import { buildConnectorWorkerEnv } from '../env.js';
|
|
13
13
|
import { assertConnectorRuntimeLoadable } from '../self-check/index.js';
|
|
@@ -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, [CONNECTOR_HTTP_AUTH_CAPABILITY]: 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
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { AgentTurnEvent, AgentTurnInput, AgentTurnOutput, AgentTurnSteer, RuntimeExecRequest, RuntimeExecResult } from '../agent-turn/types.js';
|
|
2
2
|
import type { AuthResult, ConnectorWebhookSchema, EventEnvelope, SyncCredentials, WebhookRegistration } from '@lobu/connector-sdk';
|
|
3
|
+
import type { ConnectorHttpRequest, ConnectorHttpResponse } from '@lobu/core/contracts/worker/protocol';
|
|
3
4
|
/**
|
|
4
5
|
* Executor mode discriminator. The executor speaks the same V1 SDK shapes
|
|
5
6
|
* the connector code expects: `SyncContext` / `ActionContext` / `AuthContext`
|
|
6
7
|
* in, `SyncResult` / `ActionResult` / `AuthResult` out, no envelope.
|
|
7
8
|
*/
|
|
8
9
|
export type ExecutorJob = {
|
|
10
|
+
/** HTTP credentials stay in the gateway; every fetch uses the host hook. */
|
|
11
|
+
httpAuth?: boolean;
|
|
12
|
+
} & ({
|
|
9
13
|
mode: 'sync';
|
|
10
14
|
feedKey?: string | null;
|
|
11
15
|
/** Feed-instance id (feeds.id) — namespaces emitted origin_ids per feed. */
|
|
@@ -83,17 +87,17 @@ export type ExecutorJob = {
|
|
|
83
87
|
sessionState: Record<string, unknown> | null;
|
|
84
88
|
externalId: string;
|
|
85
89
|
env: Record<string, string | undefined>;
|
|
86
|
-
};
|
|
90
|
+
});
|
|
87
91
|
/**
|
|
88
92
|
* Result shape returned by the executor. One discriminated union per mode
|
|
89
93
|
* 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`).
|
|
94
|
+
* commit-only: events and checkpoints leave through `hooks.onCommit` as the
|
|
95
|
+
* connector commits them, never collected onto the result.
|
|
93
96
|
*/
|
|
94
97
|
export type ExecutorResult = {
|
|
95
98
|
mode: 'sync';
|
|
96
|
-
|
|
99
|
+
/** How the pass ended; see the SDK's `SyncResult.status`. */
|
|
100
|
+
status: 'complete' | 'more';
|
|
97
101
|
auth_update?: Record<string, unknown> | null;
|
|
98
102
|
metadata?: Record<string, unknown>;
|
|
99
103
|
} | {
|
|
@@ -144,6 +148,8 @@ export type ExecutorResult = {
|
|
|
144
148
|
mode: 'webhook_unregister';
|
|
145
149
|
};
|
|
146
150
|
export interface ExecutionHooks {
|
|
151
|
+
/** Gateway-bound HTTP execution. The callback and its authority never enter the guest. */
|
|
152
|
+
onHttpFetch?: (request: ConnectorHttpRequest, signal?: AbortSignal) => Promise<ConnectorHttpResponse>;
|
|
147
153
|
/**
|
|
148
154
|
* Stop the run from outside: the guest is terminated and `execute` rejects
|
|
149
155
|
* with the abort as its error. An agent turn arms this when the gateway's
|
|
@@ -166,10 +172,14 @@ export interface ExecutionHooks {
|
|
|
166
172
|
* turn's own token — so the guest never holds a credential or an egress.
|
|
167
173
|
*/
|
|
168
174
|
onRuntimeExec?: (request: RuntimeExecRequest) => Promise<RuntimeExecResult>;
|
|
169
|
-
/**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Sync runs: persist one chunk of a `ctx.commit` — its events and, on the
|
|
177
|
+
* chunk that completes the commit, the checkpoint (`null` otherwise, and
|
|
178
|
+
* when the connector left the checkpoint unchanged). Resolve only once both
|
|
179
|
+
* are durable; a rejection terminates the run, so the connector never
|
|
180
|
+
* proceeds past a commit that did not land.
|
|
181
|
+
*/
|
|
182
|
+
onCommit?: (events: EventEnvelope[], checkpoint: Record<string, unknown> | null) => Promise<void> | void;
|
|
173
183
|
/** Auth runs: connector emitted an artifact (QR/redirect/prompt/status). */
|
|
174
184
|
onAuthArtifact?: (artifact: Record<string, unknown>) => Promise<void> | void;
|
|
175
185
|
/** Auth runs: connector paused until a named signal arrives. */
|