@lobu/runtime-device 24.1.0 → 24.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component.json +1 -1
- package/dist/dependencies.bun.lock +26 -28
- package/npm-shrinkwrap.json +155 -172
- package/package.json +1 -1
- package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +14 -5
- package/vendor/cli/dist/chrome-extension/accessibility-tree.js +834 -0
- package/vendor/cli/dist/chrome-extension/ambient-context.js +53 -0
- package/vendor/cli/dist/chrome-extension/auth-refresh.js +167 -0
- package/vendor/cli/dist/chrome-extension/automation-run.js +13 -0
- package/vendor/cli/dist/chrome-extension/background.js +1155 -0
- package/vendor/cli/dist/chrome-extension/bridge.js +140 -0
- package/vendor/cli/dist/chrome-extension/browser-origin-policy.js +62 -0
- package/vendor/cli/dist/chrome-extension/browser-recovery.js +260 -0
- package/vendor/cli/dist/chrome-extension/browser-url-sanitizer.js +284 -0
- package/vendor/cli/dist/chrome-extension/completion-response.js +12 -0
- package/vendor/cli/dist/chrome-extension/config.js +144 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome.json +1516 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_bookmarks.json +84 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_downloads.json +86 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_history.json +78 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests.js +1767 -0
- package/vendor/cli/dist/chrome-extension/console-capture.js +627 -0
- package/vendor/cli/dist/chrome-extension/control-activity.js +70 -0
- package/vendor/cli/dist/chrome-extension/debugger-lease.js +439 -0
- package/vendor/cli/dist/chrome-extension/feed-listener.js +488 -0
- package/vendor/cli/dist/chrome-extension/feed-transaction.js +48 -0
- package/vendor/cli/dist/chrome-extension/feeds.js +632 -0
- package/vendor/cli/dist/chrome-extension/focus-tab.js +25 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-mono-latin-500-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-400-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-600-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/heartbeat.js +140 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-128-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-128.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-16-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-16.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-32-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-32.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-48-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-48.png +0 -0
- package/vendor/cli/dist/chrome-extension/lens-page.js +135 -0
- package/vendor/cli/dist/chrome-extension/lens-target.js +20 -0
- package/vendor/cli/dist/chrome-extension/manifest.json +76 -0
- package/vendor/cli/dist/chrome-extension/network-intercept.js +657 -0
- package/vendor/cli/dist/chrome-extension/page-activation.js +120 -0
- package/vendor/cli/dist/chrome-extension/page-dialogs.js +125 -0
- package/vendor/cli/dist/chrome-extension/page-url.js +11 -0
- package/vendor/cli/dist/chrome-extension/panel-session.js +184 -0
- package/vendor/cli/dist/chrome-extension/poll-auth.js +85 -0
- package/vendor/cli/dist/chrome-extension/poll-backoff.js +22 -0
- package/vendor/cli/dist/chrome-extension/run-fence.js +117 -0
- package/vendor/cli/dist/chrome-extension/setup-status.js +71 -0
- package/vendor/cli/dist/chrome-extension/side-panel-action-click.js +65 -0
- package/vendor/cli/dist/chrome-extension/sidepanel-context.js +50 -0
- package/vendor/cli/dist/chrome-extension/sidepanel.html +680 -0
- package/vendor/cli/dist/chrome-extension/sidepanel.js +1643 -0
- package/vendor/cli/dist/chrome-extension/tab-labels.js +233 -0
- package/vendor/cli/dist/chrome-extension/tools.js +3354 -0
- package/vendor/cli/dist/chrome-extension/watch-observer.js +354 -0
- package/vendor/cli/dist/chrome-extension/watch-redact.js +96 -0
- package/vendor/cli/dist/chrome-extension/watch.js +348 -0
- package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +6 -4
- package/vendor/cli/dist/commands/_lib/apply/desired-state.js +5 -3
- package/vendor/cli/dist/commands/_lib/apply/diff.js +4 -3
- package/vendor/cli/dist/commands/_lib/apply/render.js +4 -14
- package/vendor/cli/dist/commands/_lib/chrome-for-testing.d.ts +13 -0
- package/vendor/cli/dist/commands/_lib/chrome-for-testing.js +226 -0
- package/vendor/cli/dist/commands/_lib/device-credential.d.ts +34 -0
- package/vendor/cli/dist/commands/_lib/device-credential.js +157 -0
- package/vendor/cli/dist/commands/_lib/device-wizard.d.ts +17 -0
- package/vendor/cli/dist/commands/_lib/device-wizard.js +11 -2
- package/vendor/cli/dist/commands/_lib/native-messaging.d.ts +7 -0
- package/vendor/cli/dist/commands/_lib/native-messaging.js +40 -0
- package/vendor/cli/dist/commands/browser.d.ts +23 -0
- package/vendor/cli/dist/commands/browser.js +492 -0
- package/vendor/cli/dist/commands/call.d.ts +12 -0
- package/vendor/cli/dist/commands/call.js +48 -26
- package/vendor/cli/dist/commands/context.d.ts +3 -1
- package/vendor/cli/dist/commands/context.js +13 -2
- package/vendor/cli/dist/commands/daemon.js +2 -152
- package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +4 -1
- package/vendor/cli/dist/commands/memory/_lib/errors.js +9 -1
- package/vendor/cli/dist/commands/memory/_lib/mcp.d.ts +0 -9
- package/vendor/cli/dist/commands/memory/_lib/mcp.js +1 -23
- package/vendor/cli/dist/commands/memory/_lib/memory-auth.d.ts +20 -4
- package/vendor/cli/dist/commands/memory/_lib/memory-auth.js +21 -17
- package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +6 -17
- package/vendor/cli/dist/commands/memory/run.js +4 -25
- package/vendor/cli/dist/connectors/google_gmail.ts +70 -41
- package/vendor/cli/dist/connectors/google_gmail_references.ts +406 -0
- package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +107 -36
- package/vendor/cli/dist/connectors/linkedin-inbox.ts +13 -0
- package/vendor/cli/dist/connectors/linkedin.ts +1 -1
- package/vendor/cli/dist/connectors/postgres.ts +5 -3
- package/vendor/cli/dist/connectors/reddit.ts +171 -5
- package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +147 -61
- package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +6 -2
- package/vendor/cli/dist/connectors/whatsapp_web.ts +48 -17
- package/vendor/cli/dist/connectors/x-dm-adapter.js +252 -35
- package/vendor/cli/dist/connectors/x.ts +189 -13
- package/vendor/cli/dist/index.js +46 -6
- package/vendor/cli/dist/internal/device-state.d.ts +2 -0
- package/vendor/cli/dist/internal/device-state.js +4 -0
- package/vendor/cli/dist/runtime-components.json +4 -4
- package/vendor/cli/dist/templates/AGENTS.md.tmpl +3 -1
- package/vendor/cli/dist/templates/TESTING.md.tmpl +8 -8
- package/vendor/cli/package.json +1 -1
- package/vendor/connector-sdk/dist/browser-requirement.js +1 -1
- package/vendor/connector-sdk/dist/connector-types.d.ts +5 -1
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/connector-worker/dist/agent-turn/gateway-tools.d.ts +9 -0
- package/vendor/connector-worker/dist/agent-turn/gateway-tools.js +23 -2
- package/vendor/connector-worker/dist/agent-turn/guest-entry.js +14 -6
- package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +62 -25
- package/vendor/connector-worker/dist/agent-turn/media-tools.d.ts +1 -0
- package/vendor/connector-worker/dist/agent-turn/media-tools.js +5 -2
- package/vendor/connector-worker/dist/bin.js +2 -0
- package/vendor/connector-worker/dist/daemon/agent-turn.js +52 -17
- package/vendor/connector-worker/dist/daemon/automation.js +2 -12
- package/vendor/connector-worker/dist/daemon/client.d.ts +8 -2
- package/vendor/connector-worker/dist/daemon/client.js +8 -1
- package/vendor/connector-worker/dist/daemon/interactive-session.js +29 -6
- package/vendor/connector-worker/dist/daemon/poll-loop.js +23 -1
- package/vendor/connector-worker/dist/daemon/terminal-delivery.d.ts +5 -10
- package/vendor/connector-worker/dist/daemon/terminal-delivery.js +55 -23
- package/vendor/connector-worker/dist/daemon/terminal-failure.js +2 -2
- package/vendor/connector-worker/dist/executor/isolate.js +3 -0
- package/vendor/connector-worker/package.json +1 -1
- package/vendor/core/dist/agent-tooling.d.ts +8 -0
- package/vendor/core/dist/agent-tooling.js +9 -1
- package/vendor/core/dist/capabilities.d.ts +1 -1
- package/vendor/core/dist/capabilities.js +5 -0
- package/vendor/core/dist/contracts/entity-reference.d.ts +3 -0
- package/vendor/core/dist/contracts/entity-reference.js +31 -0
- package/vendor/core/dist/contracts/tools/manage-automations.d.ts +3 -0
- package/vendor/core/dist/contracts/tools/manage-automations.js +3 -0
- package/vendor/core/dist/contracts/tools/manage-connections.js +1 -1
- package/vendor/core/dist/contracts/tools/manage-entity-schema.js +1 -1
- package/vendor/core/dist/contracts/tools/manage-entity.d.ts +113 -34
- package/vendor/core/dist/contracts/tools/manage-entity.js +41 -14
- package/vendor/core/dist/contracts/tools/manage-operations.d.ts +13 -4
- package/vendor/core/dist/contracts/tools/manage-operations.js +19 -7
- package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +6 -1
- package/vendor/core/dist/contracts/tools/read-knowledge.js +20 -1
- package/vendor/core/dist/contracts/tools/view-attach.d.ts +1 -1
- package/vendor/core/dist/contracts/tools/view-runtime.d.ts +2 -0
- package/vendor/core/dist/contracts/tools/view-runtime.js +3 -1
- package/vendor/core/dist/contracts/worker/device-automation.d.ts +4 -9
- package/vendor/core/dist/contracts/worker/device-automation.js +10 -15
- package/vendor/core/dist/contracts/worker/protocol.d.ts +20 -0
- package/vendor/core/dist/contracts/worker/protocol.js +20 -0
- package/vendor/core/dist/reserved.d.ts +6 -3
- package/vendor/core/dist/reserved.js +6 -3
- package/vendor/core/dist/worker/auth.d.ts +3 -2
- package/vendor/core/package.json +6 -1
- package/vendor/postgres/cf/src/query.js +3 -1
- package/vendor/postgres/cjs/src/query.js +3 -1
- package/vendor/postgres/src/query.js +3 -1
- /package/vendor/postgres/{.bun-tag-2f292c6554a8475e → .bun-tag-22d644c2873790db} +0 -0
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* provider credential and the MCP route accepts it as the bearer.
|
|
20
20
|
*/
|
|
21
21
|
import { mcpToolResult, toolImageBudget } from '@lobu/plugin-toolkit';
|
|
22
|
-
import { FOLLOW_UP_SUGGESTIONS_PROMPT, parseFollowUpSuggestions } from '@lobu/core/agent-tooling';
|
|
22
|
+
import { FOLLOW_UP_SUGGESTIONS_PROMPT, parseFollowUpSuggestions, TURN_INPUT_RUN_HEADER } from '@lobu/core/agent-tooling';
|
|
23
23
|
import { createGatewayTools } from './gateway-tools.js';
|
|
24
24
|
import { createTurnMediaTools } from './media-tools.js';
|
|
25
25
|
import { createTurnMemoryHooks } from './memory.js';
|
|
@@ -62,7 +62,7 @@ function joinText(content) {
|
|
|
62
62
|
* result, so a blocked or approval-gated call reaches the model as text and the
|
|
63
63
|
* turn goes on.
|
|
64
64
|
*/
|
|
65
|
-
async function callMcpTool(gatewayUrl, credential, tool, args, timeoutMs = TOOL_CALL_TIMEOUT_MS, supportsImages = true, imageBudget) {
|
|
65
|
+
async function callMcpTool(gatewayUrl, credential, tool, args, timeoutMs = TOOL_CALL_TIMEOUT_MS, supportsImages = true, imageBudget, inputRunId) {
|
|
66
66
|
const url = `${gatewayUrl}/mcp/${encodeURIComponent(tool.mcpId)}/tools/${encodeURIComponent(tool.name)}`;
|
|
67
67
|
let response;
|
|
68
68
|
try {
|
|
@@ -75,6 +75,10 @@ async function callMcpTool(gatewayUrl, credential, tool, args, timeoutMs = TOOL_
|
|
|
75
75
|
// structured body; capture validates the save receipt. The gateway
|
|
76
76
|
// renders markdown unless asked.
|
|
77
77
|
...(isRetrievalTool(tool.name) || tool.name === 'save_memory' ? { 'x-mcp-format': 'json' } : {}),
|
|
78
|
+
// The steered input this call answers. The gateway verifies it against
|
|
79
|
+
// the turn's stored inputs before a write keys on its message; absent
|
|
80
|
+
// means the turn's own (owner) input.
|
|
81
|
+
...(inputRunId !== undefined ? { [TURN_INPUT_RUN_HEADER]: String(inputRunId) } : {}),
|
|
78
82
|
},
|
|
79
83
|
body: JSON.stringify(args ?? {}),
|
|
80
84
|
signal: AbortSignal.timeout(timeoutMs),
|
|
@@ -111,7 +115,7 @@ async function callMcpTool(gatewayUrl, credential, tool, args, timeoutMs = TOOL_
|
|
|
111
115
|
* `onAskUserPosted` is threaded through because `ask_user` ends the turn — see
|
|
112
116
|
* `createGatewayTools`.
|
|
113
117
|
*/
|
|
114
|
-
function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered, emit, runtimeExec) {
|
|
118
|
+
function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered, emit, inputRunFor, runtimeExec) {
|
|
115
119
|
const imageBudget = toolImageBudget((input.images ?? []).map(image => ({ type: 'image', data: image.data })));
|
|
116
120
|
const tools = input.tools;
|
|
117
121
|
if (!tools)
|
|
@@ -131,6 +135,7 @@ function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered,
|
|
|
131
135
|
conversation: tools.conversation,
|
|
132
136
|
onAskUserPosted,
|
|
133
137
|
onInBandReplyDelivered,
|
|
138
|
+
inputRunFor,
|
|
134
139
|
})
|
|
135
140
|
: [];
|
|
136
141
|
const media = tools.media && tools.media.length > 0 && tools.conversation
|
|
@@ -142,6 +147,7 @@ function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered,
|
|
|
142
147
|
// The isolate has one channel out — its event stream — so the upload
|
|
143
148
|
// notification rides that and the host decides what to do with it.
|
|
144
149
|
onFileUploaded: (data) => emit({ type: 'file_uploaded', data }),
|
|
150
|
+
inputRunFor,
|
|
145
151
|
})
|
|
146
152
|
: [];
|
|
147
153
|
const mcp = tools.definitions.map((tool) => ({
|
|
@@ -150,8 +156,8 @@ function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered,
|
|
|
150
156
|
description: tool.description,
|
|
151
157
|
// A plain JSON schema: pi-ai validates arguments against it as-is.
|
|
152
158
|
parameters: tool.inputSchema,
|
|
153
|
-
execute: async (
|
|
154
|
-
const result = await callMcpTool(tools.gatewayUrl, credential, tool, args, TOOL_CALL_TIMEOUT_MS, input.provider.input?.includes('image') === true, imageBudget);
|
|
159
|
+
execute: async (toolCallId, args) => {
|
|
160
|
+
const result = await callMcpTool(tools.gatewayUrl, credential, tool, args, TOOL_CALL_TIMEOUT_MS, input.provider.input?.includes('image') === true, imageBudget, inputRunFor(toolCallId));
|
|
155
161
|
const text = joinText(result.content);
|
|
156
162
|
if (result.isError === true)
|
|
157
163
|
throw new Error(String(result.error || text || `${tool.name} failed`));
|
|
@@ -437,7 +443,9 @@ export async function runAgentTurn(input, emit, takeSteering = () => [], runtime
|
|
|
437
443
|
* survive.
|
|
438
444
|
*/
|
|
439
445
|
const messageContext = new Map();
|
|
440
|
-
const built = buildTools(input, credential, () => { askedUser = true; }, () => { repliedInBand = true; }, emit,
|
|
446
|
+
const built = buildTools(input, credential, () => { askedUser = true; }, () => { repliedInBand = true; }, emit,
|
|
447
|
+
// Bound at `tool_execution_start`, which Pi emits before `execute`.
|
|
448
|
+
(toolCallId) => toolInputRun.get(toolCallId), runtimeExec);
|
|
441
449
|
const tools = built.tools;
|
|
442
450
|
const session = createNativeSession(input, tools, (message) => {
|
|
443
451
|
// The context of THIS message, or nothing. No per-turn fallback: the
|
|
@@ -4472,6 +4472,7 @@ __export(agent_tooling_exports, {
|
|
|
4472
4472
|
CUSTOM_TOOL_METADATA: () => CUSTOM_TOOL_METADATA,
|
|
4473
4473
|
FOLLOW_UP_SUGGESTIONS_PROMPT: () => FOLLOW_UP_SUGGESTIONS_PROMPT,
|
|
4474
4474
|
SUGGESTION_LIMITS: () => SUGGESTION_LIMITS,
|
|
4475
|
+
TURN_INPUT_RUN_HEADER: () => TURN_INPUT_RUN_HEADER,
|
|
4475
4476
|
getCustomToolDescription: () => getCustomToolDescription,
|
|
4476
4477
|
parseFollowUpSuggestions: () => parseFollowUpSuggestions,
|
|
4477
4478
|
renderAlwaysOnToolPolicyRulesFor: () => renderAlwaysOnToolPolicyRulesFor,
|
|
@@ -4502,13 +4503,14 @@ function withLobuFileParameters(tool, kind) {
|
|
|
4502
4503
|
}
|
|
4503
4504
|
};
|
|
4504
4505
|
}
|
|
4505
|
-
var fileToolSchemas;
|
|
4506
|
+
var TURN_INPUT_RUN_HEADER, fileToolSchemas;
|
|
4506
4507
|
var init_agent_tooling = __esm({
|
|
4507
4508
|
"../core/src/agent-tooling.ts"() {
|
|
4508
4509
|
"use strict";
|
|
4509
4510
|
init_esm();
|
|
4510
4511
|
init_agent_policy();
|
|
4511
4512
|
init_suggestions();
|
|
4513
|
+
TURN_INPUT_RUN_HEADER = "x-lobu-turn-input-run";
|
|
4512
4514
|
fileToolSchemas = {
|
|
4513
4515
|
read: Type.Object({
|
|
4514
4516
|
file_path: Type.String({ description: "Path to the file" }),
|
|
@@ -4743,6 +4745,7 @@ var require_dist = __commonJS({
|
|
|
4743
4745
|
token: gateway.workerToken
|
|
4744
4746
|
}).request(path6, {
|
|
4745
4747
|
...options,
|
|
4748
|
+
headers: { ...gateway.headers, ...options.headers },
|
|
4746
4749
|
timeoutMs: options.timeoutMs ?? 6e4
|
|
4747
4750
|
});
|
|
4748
4751
|
} catch (error) {
|
|
@@ -12268,9 +12271,10 @@ var require_agent_tooling = __commonJS({
|
|
|
12268
12271
|
"../core/dist/agent-tooling.js"(exports2) {
|
|
12269
12272
|
"use strict";
|
|
12270
12273
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
12271
|
-
exports2.SUGGESTION_LIMITS = exports2.sanitizeSuggestionPrompts = exports2.parseFollowUpSuggestions = exports2.FOLLOW_UP_SUGGESTIONS_PROMPT = exports2.renderAlwaysOnToolPolicyRulesFor = exports2.getCustomToolDescription = exports2.CUSTOM_TOOL_METADATA = void 0;
|
|
12274
|
+
exports2.SUGGESTION_LIMITS = exports2.sanitizeSuggestionPrompts = exports2.parseFollowUpSuggestions = exports2.FOLLOW_UP_SUGGESTIONS_PROMPT = exports2.renderAlwaysOnToolPolicyRulesFor = exports2.getCustomToolDescription = exports2.CUSTOM_TOOL_METADATA = exports2.TURN_INPUT_RUN_HEADER = void 0;
|
|
12272
12275
|
exports2.withLobuFileParameters = withLobuFileParameters3;
|
|
12273
12276
|
var typebox_1 = require_cjs();
|
|
12277
|
+
exports2.TURN_INPUT_RUN_HEADER = "x-lobu-turn-input-run";
|
|
12274
12278
|
var agent_policy_1 = require_agent_policy();
|
|
12275
12279
|
Object.defineProperty(exports2, "CUSTOM_TOOL_METADATA", { enumerable: true, get: function() {
|
|
12276
12280
|
return agent_policy_1.CUSTOM_TOOL_METADATA;
|
|
@@ -17134,6 +17138,7 @@ var require_multipart = __commonJS({
|
|
|
17134
17138
|
Authorization: `Bearer ${gw2.workerToken}`,
|
|
17135
17139
|
"X-Channel-Id": gw2.channelId,
|
|
17136
17140
|
"X-Conversation-Id": gw2.conversationId,
|
|
17141
|
+
...gw2.headers,
|
|
17137
17142
|
...options.extraHeaders
|
|
17138
17143
|
},
|
|
17139
17144
|
body: form,
|
|
@@ -17188,6 +17193,7 @@ var require_generation = __commonJS({
|
|
|
17188
17193
|
}).request(config.endpoint, {
|
|
17189
17194
|
method: "POST",
|
|
17190
17195
|
body: JSON.stringify(config.requestBody),
|
|
17196
|
+
headers: gw2.headers,
|
|
17191
17197
|
// Generation can take a while at high quality, but never minutes — cap
|
|
17192
17198
|
// the wait so a stalled upstream provider doesn't hang the agent turn.
|
|
17193
17199
|
timeoutMs: 12e4
|
|
@@ -36927,31 +36933,45 @@ __export(guest_entry_exports, {
|
|
|
36927
36933
|
});
|
|
36928
36934
|
module.exports = __toCommonJS(guest_entry_exports);
|
|
36929
36935
|
var import_plugin_toolkit = __toESM(require_dist(), 1);
|
|
36930
|
-
var
|
|
36936
|
+
var import_agent_tooling3 = __toESM(require_agent_tooling(), 1);
|
|
36931
36937
|
|
|
36932
36938
|
// dist/agent-turn/gateway-tools.js
|
|
36939
|
+
var import_agent_tooling = __toESM(require_agent_tooling(), 1);
|
|
36933
36940
|
var import_plugin_conversations = __toESM(require_dist3(), 1);
|
|
36941
|
+
function perCallInputRun(tools, build, inputRunFor) {
|
|
36942
|
+
return tools.map((tool) => ({
|
|
36943
|
+
...tool,
|
|
36944
|
+
execute: (toolCallId, ...rest) => {
|
|
36945
|
+
const inputRunId = inputRunFor(toolCallId);
|
|
36946
|
+
if (inputRunId === void 0)
|
|
36947
|
+
return tool.execute(toolCallId, ...rest);
|
|
36948
|
+
const forCall = build({ [import_agent_tooling.TURN_INPUT_RUN_HEADER]: String(inputRunId) }).find((t) => t.name === tool.name);
|
|
36949
|
+
return forCall.execute(toolCallId, ...rest);
|
|
36950
|
+
}
|
|
36951
|
+
}));
|
|
36952
|
+
}
|
|
36934
36953
|
function createGatewayTools(allowed, args) {
|
|
36935
36954
|
const wanted = new Set(allowed);
|
|
36936
36955
|
if (wanted.size === 0)
|
|
36937
36956
|
return [];
|
|
36938
|
-
const
|
|
36957
|
+
const build = (headers) => (0, import_plugin_conversations.createConversationTools)({
|
|
36939
36958
|
gatewayUrl: args.gatewayUrl,
|
|
36940
36959
|
workerToken: args.credential,
|
|
36941
36960
|
channelId: args.conversation.channelId,
|
|
36942
36961
|
conversationId: args.conversation.conversationId,
|
|
36943
36962
|
platform: args.conversation.platform,
|
|
36963
|
+
...headers ? { headers } : {},
|
|
36944
36964
|
onAskUserPosted: args.onAskUserPosted,
|
|
36945
36965
|
onInBandReplyDelivered: args.onInBandReplyDelivered
|
|
36946
36966
|
});
|
|
36947
|
-
return
|
|
36967
|
+
return perCallInputRun(build().filter((tool) => wanted.has(tool.name)), build, args.inputRunFor);
|
|
36948
36968
|
}
|
|
36949
36969
|
|
|
36950
36970
|
// dist/agent-turn/media-tools.js
|
|
36951
36971
|
var import_portable = __toESM(require_portable(), 1);
|
|
36952
36972
|
|
|
36953
36973
|
// dist/agent-turn/workspace.js
|
|
36954
|
-
var
|
|
36974
|
+
var import_agent_tooling2 = __toESM(require_agent_tooling(), 1);
|
|
36955
36975
|
|
|
36956
36976
|
// ../../node_modules/@mariozechner/pi-coding-agent/dist/core/tools/read.js
|
|
36957
36977
|
var import_node_path2 = __toESM(require_dist4(), 1);
|
|
@@ -79672,14 +79692,14 @@ function createWorkspace(names, remote) {
|
|
|
79672
79692
|
await fs2.writeFile(absolute, file.data !== void 0 ? new Uint8Array(Buffer.from(file.data, "base64")) : file.text);
|
|
79673
79693
|
}
|
|
79674
79694
|
};
|
|
79675
|
-
const write = (0,
|
|
79695
|
+
const write = (0, import_agent_tooling2.withLobuFileParameters)(createWriteTool(WORKSPACE_ROOT, { operations: {
|
|
79676
79696
|
writeFile,
|
|
79677
79697
|
mkdir: async (path6) => {
|
|
79678
79698
|
await ready;
|
|
79679
79699
|
await fs2.mkdir(resolve7(path6), { recursive: true });
|
|
79680
79700
|
}
|
|
79681
79701
|
} }), "write");
|
|
79682
|
-
const edit = (0,
|
|
79702
|
+
const edit = (0, import_agent_tooling2.withLobuFileParameters)(createEditTool(WORKSPACE_ROOT, { operations: {
|
|
79683
79703
|
writeFile,
|
|
79684
79704
|
readFile: async (path6) => {
|
|
79685
79705
|
await ready;
|
|
@@ -79690,7 +79710,7 @@ function createWorkspace(names, remote) {
|
|
|
79690
79710
|
await fs2.stat(resolve7(path6));
|
|
79691
79711
|
}
|
|
79692
79712
|
} }), "edit");
|
|
79693
|
-
const piRead = (0,
|
|
79713
|
+
const piRead = (0, import_agent_tooling2.withLobuFileParameters)(createReadTool(WORKSPACE_ROOT, { operations: {
|
|
79694
79714
|
access: async (path6) => {
|
|
79695
79715
|
await ready;
|
|
79696
79716
|
const absolute = resolve7(path6);
|
|
@@ -79953,7 +79973,8 @@ function createTurnMediaTools(allowed, args) {
|
|
|
79953
79973
|
const wanted = new Set(allowed);
|
|
79954
79974
|
if (wanted.size === 0)
|
|
79955
79975
|
return [];
|
|
79956
|
-
const
|
|
79976
|
+
const build = (headers) => (0, import_portable.createMediaTools)({
|
|
79977
|
+
...headers ? { headers } : {},
|
|
79957
79978
|
gatewayUrl: args.gatewayUrl,
|
|
79958
79979
|
workerToken: args.credential,
|
|
79959
79980
|
channelId: args.conversation.channelId,
|
|
@@ -79968,7 +79989,8 @@ function createTurnMediaTools(allowed, args) {
|
|
|
79968
79989
|
// tool that always fails.
|
|
79969
79990
|
filePort: args.workspace ? createWorkspaceFilePort(args.workspace) : { resolve: async () => ({ ok: false, reason: "no-workspace" }), read: async () => new Uint8Array(0) }
|
|
79970
79991
|
});
|
|
79971
|
-
|
|
79992
|
+
const offered = build().filter((tool) => wanted.has(tool.name) && (tool.name !== "upload_file" || args.workspace !== null));
|
|
79993
|
+
return perCallInputRun(offered, build, args.inputRunFor);
|
|
79972
79994
|
}
|
|
79973
79995
|
|
|
79974
79996
|
// dist/agent-turn/memory.js
|
|
@@ -132393,7 +132415,7 @@ var TOOL_EVENT_OUTPUT_CHARS = 2e3;
|
|
|
132393
132415
|
function joinText(content) {
|
|
132394
132416
|
return (content ?? []).filter((part) => part && part.type === "text" && typeof part.text === "string").map((part) => part.text).join("\n");
|
|
132395
132417
|
}
|
|
132396
|
-
async function callMcpTool(gatewayUrl, credential, tool, args, timeoutMs = TOOL_CALL_TIMEOUT_MS, supportsImages = true, imageBudget) {
|
|
132418
|
+
async function callMcpTool(gatewayUrl, credential, tool, args, timeoutMs = TOOL_CALL_TIMEOUT_MS, supportsImages = true, imageBudget, inputRunId) {
|
|
132397
132419
|
const url = `${gatewayUrl}/mcp/${encodeURIComponent(tool.mcpId)}/tools/${encodeURIComponent(tool.name)}`;
|
|
132398
132420
|
let response;
|
|
132399
132421
|
try {
|
|
@@ -132405,7 +132427,11 @@ async function callMcpTool(gatewayUrl, credential, tool, args, timeoutMs = TOOL_
|
|
|
132405
132427
|
// A retrieval result is summarised into the tool trace from its
|
|
132406
132428
|
// structured body; capture validates the save receipt. The gateway
|
|
132407
132429
|
// renders markdown unless asked.
|
|
132408
|
-
...(0, import_tool_trace_summary.isRetrievalTool)(tool.name) || tool.name === "save_memory" ? { "x-mcp-format": "json" } : {}
|
|
132430
|
+
...(0, import_tool_trace_summary.isRetrievalTool)(tool.name) || tool.name === "save_memory" ? { "x-mcp-format": "json" } : {},
|
|
132431
|
+
// The steered input this call answers. The gateway verifies it against
|
|
132432
|
+
// the turn's stored inputs before a write keys on its message; absent
|
|
132433
|
+
// means the turn's own (owner) input.
|
|
132434
|
+
...inputRunId !== void 0 ? { [import_agent_tooling3.TURN_INPUT_RUN_HEADER]: String(inputRunId) } : {}
|
|
132409
132435
|
},
|
|
132410
132436
|
body: JSON.stringify(args ?? {}),
|
|
132411
132437
|
signal: AbortSignal.timeout(timeoutMs)
|
|
@@ -132431,7 +132457,7 @@ async function callMcpTool(gatewayUrl, credential, tool, args, timeoutMs = TOOL_
|
|
|
132431
132457
|
...(0, import_plugin_toolkit.mcpToolResult)(reply.isError === true ? reply.content?.filter((part) => part?.type === "text") : reply.content, reply.error || "", supportsImages, imageBudget)
|
|
132432
132458
|
};
|
|
132433
132459
|
}
|
|
132434
|
-
function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered, emit, runtimeExec) {
|
|
132460
|
+
function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered, emit, inputRunFor, runtimeExec) {
|
|
132435
132461
|
const imageBudget = (0, import_plugin_toolkit.toolImageBudget)((input.images ?? []).map((image) => ({ type: "image", data: image.data })));
|
|
132436
132462
|
const tools = input.tools;
|
|
132437
132463
|
if (!tools)
|
|
@@ -132443,7 +132469,8 @@ function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered,
|
|
|
132443
132469
|
credential,
|
|
132444
132470
|
conversation: tools.conversation,
|
|
132445
132471
|
onAskUserPosted,
|
|
132446
|
-
onInBandReplyDelivered
|
|
132472
|
+
onInBandReplyDelivered,
|
|
132473
|
+
inputRunFor
|
|
132447
132474
|
}) : [];
|
|
132448
132475
|
const media = tools.media && tools.media.length > 0 && tools.conversation ? createTurnMediaTools(tools.media, {
|
|
132449
132476
|
gatewayUrl: tools.gatewayUrl,
|
|
@@ -132452,7 +132479,8 @@ function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered,
|
|
|
132452
132479
|
workspace,
|
|
132453
132480
|
// The isolate has one channel out — its event stream — so the upload
|
|
132454
132481
|
// notification rides that and the host decides what to do with it.
|
|
132455
|
-
onFileUploaded: (data) => emit({ type: "file_uploaded", data })
|
|
132482
|
+
onFileUploaded: (data) => emit({ type: "file_uploaded", data }),
|
|
132483
|
+
inputRunFor
|
|
132456
132484
|
}) : [];
|
|
132457
132485
|
const mcp = tools.definitions.map((tool) => ({
|
|
132458
132486
|
name: tool.name,
|
|
@@ -132460,8 +132488,8 @@ function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered,
|
|
|
132460
132488
|
description: tool.description,
|
|
132461
132489
|
// A plain JSON schema: pi-ai validates arguments against it as-is.
|
|
132462
132490
|
parameters: tool.inputSchema,
|
|
132463
|
-
execute: async (
|
|
132464
|
-
const result = await callMcpTool(tools.gatewayUrl, credential, tool, args, TOOL_CALL_TIMEOUT_MS, input.provider.input?.includes("image") === true, imageBudget);
|
|
132491
|
+
execute: async (toolCallId, args) => {
|
|
132492
|
+
const result = await callMcpTool(tools.gatewayUrl, credential, tool, args, TOOL_CALL_TIMEOUT_MS, input.provider.input?.includes("image") === true, imageBudget, inputRunFor(toolCallId));
|
|
132465
132493
|
const text2 = joinText(result.content);
|
|
132466
132494
|
if (result.isError === true)
|
|
132467
132495
|
throw new Error(String(result.error || text2 || `${tool.name} failed`));
|
|
@@ -132601,11 +132629,20 @@ async function runAgentTurn(input, emit, takeSteering = () => [], runtimeExec) {
|
|
|
132601
132629
|
let repliedInBand = false;
|
|
132602
132630
|
let transientContext;
|
|
132603
132631
|
const messageContext = /* @__PURE__ */ new Map();
|
|
132604
|
-
const built = buildTools(
|
|
132605
|
-
|
|
132606
|
-
|
|
132607
|
-
|
|
132608
|
-
|
|
132632
|
+
const built = buildTools(
|
|
132633
|
+
input,
|
|
132634
|
+
credential,
|
|
132635
|
+
() => {
|
|
132636
|
+
askedUser = true;
|
|
132637
|
+
},
|
|
132638
|
+
() => {
|
|
132639
|
+
repliedInBand = true;
|
|
132640
|
+
},
|
|
132641
|
+
emit,
|
|
132642
|
+
// Bound at `tool_execution_start`, which Pi emits before `execute`.
|
|
132643
|
+
(toolCallId) => toolInputRun.get(toolCallId),
|
|
132644
|
+
runtimeExec
|
|
132645
|
+
);
|
|
132609
132646
|
const tools = built.tools;
|
|
132610
132647
|
const session = createNativeSession(input, tools, (message) => {
|
|
132611
132648
|
const text2 = messageText(message);
|
|
@@ -132814,11 +132851,11 @@ ${flush.prompt}`);
|
|
|
132814
132851
|
let suggestions = [];
|
|
132815
132852
|
if (input.tools?.followUps && !askedUser && !repliedInBand && steeredMessages.size === 0 && finalText.trim()) {
|
|
132816
132853
|
try {
|
|
132817
|
-
const reply = await askAside(session, credential,
|
|
132854
|
+
const reply = await askAside(session, credential, import_agent_tooling3.FOLLOW_UP_SUGGESTIONS_PROMPT, {
|
|
132818
132855
|
maxTokens: FOLLOW_UPS_MAX_TOKENS,
|
|
132819
132856
|
signal: AbortSignal.timeout(FOLLOW_UPS_TIMEOUT_MS)
|
|
132820
132857
|
});
|
|
132821
|
-
suggestions = (0,
|
|
132858
|
+
suggestions = (0, import_agent_tooling3.parseFollowUpSuggestions)(reply);
|
|
132822
132859
|
} catch (error) {
|
|
132823
132860
|
console.warn("follow-up suggestions failed; the turn completes without them", {
|
|
132824
132861
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -35,5 +35,6 @@ export declare function createTurnMediaTools(allowed: readonly AgentTurnMediaToo
|
|
|
35
35
|
conversation: AgentTurnConversation;
|
|
36
36
|
workspace: AgentWorkspace | null;
|
|
37
37
|
onFileUploaded: (data: Record<string, unknown>) => void;
|
|
38
|
+
inputRunFor: (toolCallId: string) => number | undefined;
|
|
38
39
|
}): AgentTool[];
|
|
39
40
|
//# sourceMappingURL=media-tools.d.ts.map
|
|
@@ -20,6 +20,7 @@ import { createMediaTools,
|
|
|
20
20
|
// port to the `node:fs` one, and a Node builtin anywhere in an isolate
|
|
21
21
|
// bundle is rejected outright by `assertIsolateEligible`.
|
|
22
22
|
} from '@lobu/plugin-media/portable';
|
|
23
|
+
import { perCallInputRun } from './gateway-tools.js';
|
|
23
24
|
import { WORKSPACE_ROOT } from './workspace.js';
|
|
24
25
|
/**
|
|
25
26
|
* `upload_file`'s view of the turn's in-memory workspace.
|
|
@@ -76,7 +77,8 @@ export function createTurnMediaTools(allowed, args) {
|
|
|
76
77
|
const wanted = new Set(allowed);
|
|
77
78
|
if (wanted.size === 0)
|
|
78
79
|
return [];
|
|
79
|
-
const
|
|
80
|
+
const build = (headers) => createMediaTools({
|
|
81
|
+
...(headers ? { headers } : {}),
|
|
80
82
|
gatewayUrl: args.gatewayUrl,
|
|
81
83
|
workerToken: args.credential,
|
|
82
84
|
channelId: args.conversation.channelId,
|
|
@@ -93,6 +95,7 @@ export function createTurnMediaTools(allowed, args) {
|
|
|
93
95
|
? createWorkspaceFilePort(args.workspace)
|
|
94
96
|
: { resolve: async () => ({ ok: false, reason: 'no-workspace' }), read: async () => new Uint8Array(0) },
|
|
95
97
|
});
|
|
96
|
-
|
|
98
|
+
const offered = build().filter((tool) => wanted.has(tool.name) && (tool.name !== 'upload_file' || args.workspace !== null));
|
|
99
|
+
return perCallInputRun(offered, build, args.inputRunFor);
|
|
97
100
|
}
|
|
98
101
|
//# sourceMappingURL=media-tools.js.map
|
|
@@ -52,6 +52,8 @@ Environment Variables:
|
|
|
52
52
|
WORKER_CAPABILITIES Comma-separated capabilities (same as --capabilities)
|
|
53
53
|
WORKER_LABEL Human-readable device name (same as --label)
|
|
54
54
|
LOBU_ORG Active org slug (same as --active-org)
|
|
55
|
+
WORKER_SHUTDOWN_GRACE_SECONDS Seconds before a force-kill after SIGTERM;
|
|
56
|
+
in-flight runs drain for this minus 15s (default drain 30s)
|
|
55
57
|
|
|
56
58
|
Examples:
|
|
57
59
|
# Worker daemon
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
import { AGENT_TURN_BRIDGE_BYTES, AGENT_TURN_INPUT_MAX, TURN_DELTA_MAX_CHARS, TURN_TOOL_EVENT_QUEUE_MAX, } from '@lobu/core/contracts/worker/protocol';
|
|
11
11
|
import { agentGuestBundle } from '../agent-turn/bundle.js';
|
|
12
12
|
import { selectExecutor } from '../executor/select.js';
|
|
13
|
-
import { trimTrailingSlashes } from './client.js';
|
|
13
|
+
import { trimTrailingSlashes, WorkerHttpError } from './client.js';
|
|
14
14
|
import { log } from './log.js';
|
|
15
|
+
import { completeAgentTurnOnce } from './terminal-delivery.js';
|
|
15
16
|
/**
|
|
16
17
|
* How often a streaming turn pushes what it has produced.
|
|
17
18
|
*
|
|
@@ -39,19 +40,32 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
39
40
|
const runId = job.run_id;
|
|
40
41
|
if (!runId)
|
|
41
42
|
return { itemsCollected: 0, error: 'agent turn run missing its run id' };
|
|
43
|
+
// The attempt identity every report carries: the gateway refuses (409) a
|
|
44
|
+
// report whose credential no longer names the run's current attempt, which is
|
|
45
|
+
// how a stalled attempt learns the reaper re-queued its turn.
|
|
46
|
+
const turnCredential = job.credentials?.accessToken;
|
|
42
47
|
const fail = async (error, trailing) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
try {
|
|
49
|
+
const receipt = await completeAgentTurnOnce(client, {
|
|
50
|
+
run_id: runId,
|
|
51
|
+
worker_id: client.id,
|
|
52
|
+
...(turnCredential ? { turn_credential: turnCredential } : {}),
|
|
53
|
+
status: 'failed',
|
|
54
|
+
error,
|
|
55
|
+
// Whatever evidence was retained rides the failure, so the server holds
|
|
56
|
+
// the prefix that explains the turn. Bounded by construction (the queue
|
|
57
|
+
// below never exceeds the cap); the overflow error names what did not fit.
|
|
58
|
+
...(trailing?.length ? { turn_tool_events: trailing } : {}),
|
|
59
|
+
exit_reason: 'error_message',
|
|
60
|
+
});
|
|
61
|
+
return { itemsCollected: 0, ...(receipt.status === 'completed' ? {} : { error }) };
|
|
62
|
+
}
|
|
63
|
+
catch (deliveryError) {
|
|
64
|
+
// The outer executor must not replace this failure's evidence with a
|
|
65
|
+
// second terminal payload describing only the transport error.
|
|
66
|
+
log.info(`[agent-turn] run ${runId} failure delivery uncertain:`, deliveryError);
|
|
67
|
+
return { itemsCollected: 0, error };
|
|
68
|
+
}
|
|
55
69
|
};
|
|
56
70
|
// The run is already claimed, so a rejected envelope must be REPORTED, not
|
|
57
71
|
// returned: a local return leaves the turn parked until the stale sweep.
|
|
@@ -147,7 +161,7 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
147
161
|
toolEvents = [];
|
|
148
162
|
tracesInFlight = traces;
|
|
149
163
|
try {
|
|
150
|
-
const ack = await client.heartbeat(runId, { items_collected_so_far: deltaSequence }, undefined, batch ?? undefined, traces.length > 0 ? traces : undefined);
|
|
164
|
+
const ack = await client.heartbeat(runId, { items_collected_so_far: deltaSequence }, undefined, batch ?? undefined, traces.length > 0 ? traces : undefined, turnCredential);
|
|
151
165
|
// Retire the batch only on a positive ack for ITS sequence. `published:
|
|
152
166
|
// false` is an ack too — an already-passed sequence is an answer, and
|
|
153
167
|
// there is nothing more the worker can do about it. No ack at all (an
|
|
@@ -177,6 +191,7 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
177
191
|
// Whatever is still queued when the turn ends rides the completion,
|
|
178
192
|
// which is the one write that cannot lose the lease fence to itself.
|
|
179
193
|
log.debug('[agent-turn] delta beat failed:', err);
|
|
194
|
+
stopIfSuperseded(err);
|
|
180
195
|
}
|
|
181
196
|
finally {
|
|
182
197
|
// Anything this beat could not retire goes back to the front of the
|
|
@@ -243,13 +258,16 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
243
258
|
if (sending || inFlight || pending || toolEvents.length > 0)
|
|
244
259
|
return;
|
|
245
260
|
void client
|
|
246
|
-
.heartbeat(runId, { items_collected_so_far: deltaSequence })
|
|
261
|
+
.heartbeat(runId, { items_collected_so_far: deltaSequence }, undefined, undefined, undefined, turnCredential)
|
|
247
262
|
.then((ack) => {
|
|
248
263
|
if (ack?.continue === false)
|
|
249
264
|
stopTurn(ack.stop_reason);
|
|
250
265
|
queueSteering(ack?.steer);
|
|
251
266
|
})
|
|
252
|
-
.catch((err) =>
|
|
267
|
+
.catch((err) => {
|
|
268
|
+
log.debug('[agent-turn] heartbeat failed:', err);
|
|
269
|
+
stopIfSuperseded(err);
|
|
270
|
+
});
|
|
253
271
|
}, cfg.heartbeatIntervalMs);
|
|
254
272
|
// The heartbeat's answer is the gateway's only way to reach a turn in
|
|
255
273
|
// flight. `continue: false` means the human cancelled: the guest is torn
|
|
@@ -279,6 +297,13 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
279
297
|
log.info(`[agent-turn] run ${runId} stopping: ${reason ?? 'the gateway said stop'}`);
|
|
280
298
|
cancel.abort();
|
|
281
299
|
};
|
|
300
|
+
// A 409 on a beat means this attempt no longer owns the run: the reaper
|
|
301
|
+
// re-queued it, or another claim holds it. Spending the rest of the turn
|
|
302
|
+
// would only produce output the gateway refuses, so stop like a cancel.
|
|
303
|
+
const stopIfSuperseded = (err) => {
|
|
304
|
+
if (err instanceof WorkerHttpError && err.status === 409)
|
|
305
|
+
stopTurn('this attempt no longer owns the run');
|
|
306
|
+
};
|
|
282
307
|
/**
|
|
283
308
|
* Latch receipt-capacity overflow and stop the turn. The queue itself stays
|
|
284
309
|
* bounded (the trace that did not fit is NOT queued); its identity and the
|
|
@@ -301,6 +326,7 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
301
326
|
`${toolReceiptOverflow?.dropped ?? 0} trace(s) could not be retained, starting with ` +
|
|
302
327
|
`${toolReceiptOverflow?.toolCallId ?? 'unknown'} (${toolReceiptOverflow?.name ?? 'unknown'}); ` +
|
|
303
328
|
`external effects past the retained prefix are unknown`;
|
|
329
|
+
let terminalPayloadStarted = false;
|
|
304
330
|
try {
|
|
305
331
|
const guestCode = await agentGuestBundle();
|
|
306
332
|
// Same executor seam every other lane uses (`resolveJobExecution`): an
|
|
@@ -558,9 +584,13 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
558
584
|
const trailingTraces = [...tracesInFlight, ...toolEvents];
|
|
559
585
|
tracesInFlight = [];
|
|
560
586
|
toolEvents = [];
|
|
561
|
-
|
|
587
|
+
// Exact retries share the gateway's completion hash. Once delivery starts,
|
|
588
|
+
// even an exhausted retry budget must not replace this terminal outcome.
|
|
589
|
+
terminalPayloadStarted = true;
|
|
590
|
+
const receipt = await completeAgentTurnOnce(client, {
|
|
562
591
|
run_id: runId,
|
|
563
592
|
worker_id: client.id,
|
|
593
|
+
...(turnCredential ? { turn_credential: turnCredential } : {}),
|
|
564
594
|
status: 'completed',
|
|
565
595
|
text: result.turn.text,
|
|
566
596
|
...(trailingTraces.length ? { turn_tool_events: trailingTraces } : {}),
|
|
@@ -585,6 +615,11 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
585
615
|
return { itemsCollected: 0 };
|
|
586
616
|
}
|
|
587
617
|
catch (error) {
|
|
618
|
+
if (terminalPayloadStarted) {
|
|
619
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
620
|
+
log.info(`[agent-turn] run ${runId} completion delivery uncertain:`, message);
|
|
621
|
+
return { itemsCollected: 0, error: message };
|
|
622
|
+
}
|
|
588
623
|
// Any failure reports the retained receipt prefix. A provider/runtime
|
|
589
624
|
// error after a tool finished must not erase mandatory external-effect
|
|
590
625
|
// evidence merely because the queue did not overflow.
|
|
@@ -32,7 +32,8 @@ import { buildDeviceAutomationPrompt, DEVICE_AGENT_SPECS_BY_KIND, } from '@lobu/
|
|
|
32
32
|
import { redactOutput } from '../executor/redact.js';
|
|
33
33
|
import { locateBinary, searchDirs } from './agent-binaries.js';
|
|
34
34
|
import { releaseSupervisor, spawnSupervisedCli, terminateChild, waitForTargetExit, waitForTargetExitAfterTermination, } from './automation-process.js';
|
|
35
|
-
import {
|
|
35
|
+
import { WorkerHttpError } from './client.js';
|
|
36
|
+
import { isRetriableDeliveryFailure } from './terminal-delivery.js';
|
|
36
37
|
import { log } from './log.js';
|
|
37
38
|
import { attachedInteractiveSession, handoffToInteractiveSession, } from './interactive-session.js';
|
|
38
39
|
import { AcpTranscript, runAcpTurn, } from './automation-acp.js';
|
|
@@ -570,17 +571,6 @@ export async function runCli(spec, prompt, config, access, timeoutMs, binaryPath
|
|
|
570
571
|
cleanup();
|
|
571
572
|
}
|
|
572
573
|
}
|
|
573
|
-
/**
|
|
574
|
-
* A delivery failure's retry classification: HTTP 5xx/429 and transport errors
|
|
575
|
-
* are retriable; a server answer we could not read (decode) or a 4xx is not.
|
|
576
|
-
*/
|
|
577
|
-
function isRetriableDeliveryFailure(err) {
|
|
578
|
-
if (err instanceof WorkerHttpError)
|
|
579
|
-
return err.status >= 500 || err.status === 429;
|
|
580
|
-
if (err instanceof WorkerDecodeError)
|
|
581
|
-
return false;
|
|
582
|
-
return true;
|
|
583
|
-
}
|
|
584
574
|
/**
|
|
585
575
|
* Execute a device automation run: spawn the local CLI per its AgentSpec, then
|
|
586
576
|
* post the exit report and honour the server's `resume` decision.
|
|
@@ -24,7 +24,7 @@ export interface ExecutorClient {
|
|
|
24
24
|
items_collected_so_far?: number;
|
|
25
25
|
current_page?: number;
|
|
26
26
|
elapsed_ms?: number;
|
|
27
|
-
}, agentSession?: NonNullable<HeartbeatRequest['agent_session']>, turnDelta?: NonNullable<HeartbeatRequest['turn_delta']>, turnToolEvents?: NonNullable<HeartbeatRequest['turn_tool_events']
|
|
27
|
+
}, agentSession?: NonNullable<HeartbeatRequest['agent_session']>, turnDelta?: NonNullable<HeartbeatRequest['turn_delta']>, turnToolEvents?: NonNullable<HeartbeatRequest['turn_tool_events']>, turnCredential?: string): Promise<HeartbeatResponse>;
|
|
28
28
|
stream(batch: StreamBatch): Promise<void>;
|
|
29
29
|
complete(req: CompleteRequest): Promise<void>;
|
|
30
30
|
completeAction(req: CompleteActionRequest): Promise<void>;
|
|
@@ -191,7 +191,13 @@ export declare class WorkerClient implements ExecutorClient {
|
|
|
191
191
|
*/
|
|
192
192
|
turnDelta?: NonNullable<HeartbeatRequest['turn_delta']>,
|
|
193
193
|
/** Tool calls the turn finished since the last beat. */
|
|
194
|
-
turnToolEvents?: NonNullable<HeartbeatRequest['turn_tool_events']
|
|
194
|
+
turnToolEvents?: NonNullable<HeartbeatRequest['turn_tool_events']>,
|
|
195
|
+
/**
|
|
196
|
+
* The agent turn credential this attempt was claimed with, so the gateway
|
|
197
|
+
* can refuse a stalled attempt's beat (409) after the run was re-queued and
|
|
198
|
+
* re-claimed — see `HeartbeatRequestSchema.turn_credential`.
|
|
199
|
+
*/
|
|
200
|
+
turnCredential?: string): Promise<HeartbeatResponse>;
|
|
195
201
|
writeAutomationTranscript(runId: number, bearer: string, terminalStatus: 'completed' | 'failed' | 'timeout' | 'cancelled', snapshotJsonl: string): Promise<void>;
|
|
196
202
|
/**
|
|
197
203
|
* Stream content batch to backend
|
|
@@ -217,7 +217,13 @@ export class WorkerClient {
|
|
|
217
217
|
*/
|
|
218
218
|
turnDelta,
|
|
219
219
|
/** Tool calls the turn finished since the last beat. */
|
|
220
|
-
turnToolEvents
|
|
220
|
+
turnToolEvents,
|
|
221
|
+
/**
|
|
222
|
+
* The agent turn credential this attempt was claimed with, so the gateway
|
|
223
|
+
* can refuse a stalled attempt's beat (409) after the run was re-queued and
|
|
224
|
+
* re-claimed — see `HeartbeatRequestSchema.turn_credential`.
|
|
225
|
+
*/
|
|
226
|
+
turnCredential) {
|
|
221
227
|
// A stalled response must release the turn's serialized delta beat before
|
|
222
228
|
// the next 30s liveness interval. The deadline covers the response body too.
|
|
223
229
|
return this.requestJson('/api/workers/heartbeat', {
|
|
@@ -229,6 +235,7 @@ export class WorkerClient {
|
|
|
229
235
|
...(turnToolEvents && turnToolEvents.length > 0
|
|
230
236
|
? { turn_tool_events: turnToolEvents }
|
|
231
237
|
: {}),
|
|
238
|
+
...(turnCredential ? { turn_credential: turnCredential } : {}),
|
|
232
239
|
}, AbortSignal.timeout(15_000));
|
|
233
240
|
}
|
|
234
241
|
async writeAutomationTranscript(runId, bearer, terminalStatus, snapshotJsonl) {
|