@lobu/runtime-device 22.0.0 → 24.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 +33 -30
- package/npm-shrinkwrap.json +140 -124
- package/package.json +2 -1
- package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +74 -1
- package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +9 -11
- package/vendor/cli/dist/commands/_lib/apply/client.d.ts +3 -11
- package/vendor/cli/dist/commands/_lib/apply/client.js +3 -3
- package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +0 -6
- package/vendor/cli/dist/commands/_lib/apply/desired-state.js +6 -15
- package/vendor/cli/dist/commands/_lib/apply/diff.js +1 -0
- package/vendor/cli/dist/commands/_lib/apply/map-config.js +8 -0
- package/vendor/cli/dist/commands/_lib/view-bundler.d.ts +2 -9
- package/vendor/cli/dist/commands/_lib/view-bundler.js +25 -97
- package/vendor/cli/dist/config/define.d.ts +8 -0
- package/vendor/cli/dist/connectors/README.md +15 -2
- package/vendor/cli/dist/connectors/google_gmail.ts +1 -0
- package/vendor/cli/dist/connectors/jira-helpers.ts +313 -0
- package/vendor/cli/dist/connectors/jira.ts +29 -221
- package/vendor/cli/dist/connectors/linkedin-browser-script.ts +13 -0
- package/vendor/cli/dist/connectors/linkedin-draft-page.js +104 -0
- package/vendor/cli/dist/connectors/linkedin-drafts.ts +73 -0
- package/vendor/cli/dist/connectors/linkedin-identity.ts +32 -0
- package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +1182 -0
- package/vendor/cli/dist/connectors/linkedin-inbox.ts +156 -0
- package/vendor/cli/dist/connectors/linkedin-like.ts +114 -0
- package/vendor/cli/dist/connectors/linkedin-takeout.ts +577 -0
- package/vendor/cli/dist/connectors/linkedin.ts +4017 -0
- package/vendor/cli/dist/connectors/reddit.ts +92 -20
- package/vendor/cli/dist/connectors/slack.ts +1 -0
- package/vendor/cli/dist/connectors/takeout-utils.ts +240 -0
- package/vendor/cli/dist/connectors/tiktok-inbox-page.js +9 -9
- package/vendor/cli/dist/connectors/tiktok-web-page.js +21 -15
- package/vendor/cli/dist/connectors/tiktok_web.ts +63 -30
- package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +104 -574
- package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +30 -444
- package/vendor/cli/dist/connectors/whatsapp-web-identity.ts +20 -6
- package/vendor/cli/dist/connectors/whatsapp_web.ts +46 -646
- package/vendor/cli/dist/connectors/x-dm-adapter.js +556 -0
- package/vendor/cli/dist/connectors/x-identity.ts +33 -2
- package/vendor/cli/dist/connectors/x.ts +266 -120
- package/vendor/cli/dist/runtime-components.json +4 -4
- package/vendor/cli/dist/templates/AGENTS.md.tmpl +12 -5
- package/vendor/cli/package.json +1 -1
- package/vendor/connector-sdk/dist/browser-handoff-banner.d.ts +39 -0
- package/vendor/connector-sdk/dist/browser-handoff-banner.js +175 -0
- package/vendor/connector-sdk/dist/browser-source-read.d.ts +52 -0
- package/vendor/connector-sdk/dist/browser-source-read.js +107 -0
- package/vendor/connector-sdk/dist/connector-types.d.ts +10 -0
- package/vendor/connector-sdk/dist/index.d.ts +3 -0
- package/vendor/connector-sdk/dist/index.js +2 -0
- package/vendor/connector-sdk/package.json +9 -1
- package/vendor/connector-worker/dist/agent-turn/gateway-tools.d.ts +2 -2
- package/vendor/connector-worker/dist/agent-turn/gateway-tools.js +2 -2
- package/vendor/connector-worker/dist/agent-turn/guest-entry.js +49 -8
- package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +650 -448
- package/vendor/connector-worker/dist/agent-turn/native-session.d.ts +12 -0
- package/vendor/connector-worker/dist/agent-turn/native-session.js +32 -6
- package/vendor/connector-worker/dist/agent-turn/types.d.ts +24 -3
- package/vendor/connector-worker/dist/daemon/agent-turn.js +5 -1
- package/vendor/connector-worker/dist/daemon/automation.d.ts +4 -11
- package/vendor/connector-worker/dist/daemon/automation.js +26 -21
- package/vendor/connector-worker/dist/daemon/client.d.ts +2 -4
- package/vendor/connector-worker/dist/daemon/client.js +0 -3
- package/vendor/connector-worker/dist/daemon/executor.js +0 -3
- package/vendor/connector-worker/dist/daemon/mac-device-daemon.d.ts +4 -3
- package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +4 -10
- package/vendor/connector-worker/dist/daemon/native-bridge/executor.js +27 -25
- package/vendor/connector-worker/dist/daemon/start.js +3 -15
- package/vendor/connector-worker/dist/daemon/terminal-failure.js +0 -11
- package/vendor/connector-worker/dist/daemon/worker-id.d.ts +17 -0
- package/vendor/connector-worker/dist/daemon/worker-id.js +22 -0
- package/vendor/connector-worker/dist/isolate/prelude.js +93 -44
- package/vendor/connector-worker/dist/mac-device-daemon.js +14 -26
- package/vendor/connector-worker/package.json +1 -1
- package/vendor/core/dist/agent-policy.js +0 -3
- package/vendor/core/dist/agent-tooling.d.ts +1 -1
- package/vendor/core/dist/agent-tooling.js +3 -1
- package/vendor/core/dist/capabilities.d.ts +1 -1
- package/vendor/core/dist/capabilities.js +0 -1
- package/vendor/core/dist/connector-query-errors.d.ts +32 -0
- package/vendor/core/dist/connector-query-errors.js +41 -1
- package/vendor/core/dist/contracts/agent-settings.d.ts +6 -2
- package/vendor/core/dist/contracts/agent-settings.js +12 -1
- package/vendor/core/dist/contracts/tools/manage-conversations.js +2 -2
- package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +14 -0
- package/vendor/core/dist/contracts/tools/manage-feeds.js +17 -0
- package/vendor/core/dist/contracts/tools/manage-views.d.ts +53 -234
- package/vendor/core/dist/contracts/tools/manage-views.js +50 -76
- package/vendor/core/dist/contracts/tools/view-attach.d.ts +5 -8
- package/vendor/core/dist/contracts/tools/view-attach.js +14 -31
- package/vendor/core/dist/contracts/tools/view-definition.d.ts +21 -0
- package/vendor/core/dist/contracts/tools/view-definition.js +165 -0
- package/vendor/core/dist/contracts/worker/protocol.d.ts +47 -133
- package/vendor/core/dist/contracts/worker/protocol.js +33 -62
- package/vendor/core/dist/device-pin-tombstones.d.ts +44 -0
- package/vendor/core/dist/device-pin-tombstones.js +57 -0
- package/vendor/core/dist/index.d.ts +3 -2
- package/vendor/core/dist/index.js +3 -1
- package/vendor/core/dist/logger.js +10 -25
- package/vendor/core/dist/suggestions.d.ts +15 -2
- package/vendor/core/dist/suggestions.js +48 -3
- package/vendor/core/dist/types.d.ts +26 -0
- package/vendor/core/dist/types.js +5 -0
- package/vendor/core/dist/utils/diagnostic-scrubber.js +258 -21
- package/vendor/core/dist/worker/wire.d.ts +0 -10
- package/vendor/core/package.json +16 -10
- package/vendor/postgres/cf/src/connection.js +18 -0
- package/vendor/postgres/cjs/src/connection.js +18 -0
- package/vendor/postgres/src/connection.js +18 -0
- package/vendor/connector-worker/dist/daemon/device-chat.d.ts +0 -9
- package/vendor/connector-worker/dist/daemon/device-chat.js +0 -61
- package/vendor/core/dist/contracts/worker/device-chat.d.ts +0 -4
- package/vendor/core/dist/contracts/worker/device-chat.js +0 -26
- /package/vendor/postgres/{.bun-tag-f39dafdb2305d504 → .bun-tag-2f292c6554a8475e} +0 -0
|
@@ -12,4 +12,16 @@ export declare function createNativeSession(input: AgentTurnInput, tools: AgentT
|
|
|
12
12
|
*/
|
|
13
13
|
export declare function promptNativeSession(session: AgentSession, text: string, images?: AgentTurnInput['images']): Promise<void>;
|
|
14
14
|
export declare function nativeSessionJsonl(session: AgentSession): string;
|
|
15
|
+
/**
|
|
16
|
+
* One side request on the session's own model, system prompt, tools and
|
|
17
|
+
* history, with `text` as a final user message. Nothing is appended to the
|
|
18
|
+
* session, so the question and its answer never reach the transcript; sending
|
|
19
|
+
* the same prefix the turn just sent is what lets the provider's prompt cache
|
|
20
|
+
* cover it. The side request does not inherit the session's thinking level.
|
|
21
|
+
* Resolves with the reply's text, '' when it has none.
|
|
22
|
+
*/
|
|
23
|
+
export declare function askAside(session: AgentSession, apiKey: string, text: string, options: {
|
|
24
|
+
maxTokens: number;
|
|
25
|
+
signal: AbortSignal;
|
|
26
|
+
}): Promise<string>;
|
|
15
27
|
//# sourceMappingURL=native-session.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Agent } from '@mariozechner/pi-agent-core';
|
|
2
|
-
import { registerApiProvider, streamSimple } from '@mariozechner/pi-ai';
|
|
2
|
+
import { completeSimple, registerApiProvider, streamSimple } from '@mariozechner/pi-ai';
|
|
3
3
|
import { streamAnthropic, streamSimpleAnthropic } from '@mariozechner/pi-ai/anthropic';
|
|
4
4
|
import { streamOpenAICompletions, streamSimpleOpenAICompletions } from '@mariozechner/pi-ai/openai-completions';
|
|
5
5
|
import { streamOpenAICodexResponses, streamSimpleOpenAICodexResponses } from '@mariozechner/pi-ai/openai-codex-responses';
|
|
@@ -7,6 +7,15 @@ import { streamOpenAIResponses, streamSimpleOpenAIResponses } from '@mariozechne
|
|
|
7
7
|
import { AgentSession, SessionManager, SettingsManager, convertToLlm, CURRENT_SESSION_VERSION } from '@mariozechner/pi-coding-agent';
|
|
8
8
|
import { createLobuResourceLoader } from '@lobu/plugin-toolkit/pi-resources';
|
|
9
9
|
import { SESSION_PATH, withSessionSnapshot } from './pi-session-fs.js';
|
|
10
|
+
/**
|
|
11
|
+
* Keep native custom/summary conversion. Pi stores an empty text block for
|
|
12
|
+
* image-only prompts; omit it only on the wire, where OpenAI rejects it.
|
|
13
|
+
*/
|
|
14
|
+
function toLlm(messages) {
|
|
15
|
+
return convertToLlm(messages).map((message) => message.role === 'user' && Array.isArray(message.content)
|
|
16
|
+
? { ...message, content: message.content.filter((part) => part.type !== 'text' || part.text.trim().length > 0) }
|
|
17
|
+
: message);
|
|
18
|
+
}
|
|
10
19
|
/** Pi owns session state and lifecycle; Lobu supplies only admitted host capabilities. */
|
|
11
20
|
export function createNativeSession(input, tools, getTransientContext) {
|
|
12
21
|
// Exhaustive over Pi's `ThinkingLevel`, so a level added or renamed upstream
|
|
@@ -55,6 +64,7 @@ export function createNativeSession(input, tools, getTransientContext) {
|
|
|
55
64
|
// For a model absent from the registry, an explicit effort is the user's
|
|
56
65
|
// request to try reasoning; known non-reasoning models are rejected above.
|
|
57
66
|
reasoning: input.provider.reasoning ?? (thinkingLevel !== 'off'),
|
|
67
|
+
...(input.provider.thinkingLevelMap ? { thinkingLevelMap: input.provider.thinkingLevelMap } : {}),
|
|
58
68
|
input: input.provider.input ?? ['text'],
|
|
59
69
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
60
70
|
contextWindow: input.compaction?.contextWindow ?? 200_000,
|
|
@@ -115,11 +125,7 @@ export function createNativeSession(input, tools, getTransientContext) {
|
|
|
115
125
|
let session;
|
|
116
126
|
const agent = new Agent({
|
|
117
127
|
initialState: { model, messages: context.messages, thinkingLevel },
|
|
118
|
-
|
|
119
|
-
// image-only prompts; omit it only on the wire, where OpenAI rejects it.
|
|
120
|
-
convertToLlm: (messages) => convertToLlm(messages).map((message) => message.role === 'user' && Array.isArray(message.content)
|
|
121
|
-
? { ...message, content: message.content.filter((part) => part.type !== 'text' || part.text.trim().length > 0) }
|
|
122
|
-
: message),
|
|
128
|
+
convertToLlm: toLlm,
|
|
123
129
|
transformContext: (messages) => session.extensionRunner.emitContext(messages),
|
|
124
130
|
streamFn: (selected, context, options) => streamSimple(selected, context, {
|
|
125
131
|
...settings.getProviderRetrySettings(), ...options, apiKey: input.provider.apiKey,
|
|
@@ -229,4 +235,24 @@ export function nativeSessionJsonl(session) {
|
|
|
229
235
|
return [session.sessionManager.getHeader(), ...session.sessionManager.getEntries()]
|
|
230
236
|
.map((entry) => JSON.stringify(entry)).join('\n') + '\n';
|
|
231
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* One side request on the session's own model, system prompt, tools and
|
|
240
|
+
* history, with `text` as a final user message. Nothing is appended to the
|
|
241
|
+
* session, so the question and its answer never reach the transcript; sending
|
|
242
|
+
* the same prefix the turn just sent is what lets the provider's prompt cache
|
|
243
|
+
* cover it. The side request does not inherit the session's thinking level.
|
|
244
|
+
* Resolves with the reply's text, '' when it has none.
|
|
245
|
+
*/
|
|
246
|
+
export async function askAside(session, apiKey, text, options) {
|
|
247
|
+
const { model, systemPrompt, tools, messages } = session.agent.state;
|
|
248
|
+
// Apply transient context before appending the ask: the extension attaches
|
|
249
|
+
// it to the latest real user message, preserving the answer request's prefix.
|
|
250
|
+
const contextMessages = await session.extensionRunner.emitContext(messages);
|
|
251
|
+
const reply = await completeSimple(model, {
|
|
252
|
+
systemPrompt,
|
|
253
|
+
tools,
|
|
254
|
+
messages: toLlm([...contextMessages, { role: 'user', content: [{ type: 'text', text }], timestamp: Date.now() }]),
|
|
255
|
+
}, { apiKey, maxTokens: options.maxTokens, signal: options.signal });
|
|
256
|
+
return reply.content.flatMap((block) => block.type === 'text' ? [block.text] : []).join('');
|
|
257
|
+
}
|
|
232
258
|
//# sourceMappingURL=native-session.js.map
|
|
@@ -45,6 +45,14 @@ export interface AgentTurnProvider {
|
|
|
45
45
|
* anything else gets `'off'`.
|
|
46
46
|
*/
|
|
47
47
|
reasoning?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* pi-ai's `Model.thinkingLevelMap` from its registry: the provider's name
|
|
50
|
+
* for each thinking level, `null` where the model does not serve it. pi-ai
|
|
51
|
+
* reads `off: null` as "send no effort", which is what a model that cannot
|
|
52
|
+
* turn reasoning off (gpt-5-mini) needs; without it pi-ai sends
|
|
53
|
+
* `effort: "none"` and the provider rejects the request.
|
|
54
|
+
*/
|
|
55
|
+
thinkingLevelMap?: Partial<Record<string, string | null>>;
|
|
48
56
|
/**
|
|
49
57
|
* The modalities the model accepts, in pi-ai's `Model.input` vocabulary. The
|
|
50
58
|
* gateway resolves it from pi-ai's registry; the guest only passes it
|
|
@@ -98,8 +106,8 @@ export interface AgentTurnTool {
|
|
|
98
106
|
/** The guest's own workspace tools, by name. */
|
|
99
107
|
export type AgentTurnBuiltinTool = 'bash' | 'read' | 'write' | 'edit' | 'grep' | 'ls' | 'find';
|
|
100
108
|
/**
|
|
101
|
-
* A gateway tool the turn may call — `ask_user`, `send_message
|
|
102
|
-
*
|
|
109
|
+
* A gateway tool the turn may call — `ask_user`, `send_message` and the
|
|
110
|
+
* rest of `@lobu/plugin-conversations`.
|
|
103
111
|
*
|
|
104
112
|
* The producer names them; the guest runs the plugin package's OWN
|
|
105
113
|
* implementation, bundled in. They are not reimplemented here and not proxied
|
|
@@ -108,7 +116,7 @@ export type AgentTurnBuiltinTool = 'bash' | 'read' | 'write' | 'edit' | 'grep' |
|
|
|
108
116
|
* so the turn still carries exactly one credential and reaches exactly one
|
|
109
117
|
* host.
|
|
110
118
|
*/
|
|
111
|
-
export type AgentTurnGatewayTool = 'list_conversations' | 'read_conversation' | 'send_message' | 'present_event' | 'schedule_followup' | 'react' | 'edit_message' | 'delete_message' | 'ask_user'
|
|
119
|
+
export type AgentTurnGatewayTool = 'list_conversations' | 'read_conversation' | 'send_message' | 'present_event' | 'schedule_followup' | 'react' | 'edit_message' | 'delete_message' | 'ask_user';
|
|
112
120
|
/**
|
|
113
121
|
* A media tool the turn may call — `@lobu/plugin-media`'s own.
|
|
114
122
|
*
|
|
@@ -155,6 +163,11 @@ export interface AgentTurnTools {
|
|
|
155
163
|
* whenever `gateway` or `media` is non-empty.
|
|
156
164
|
*/
|
|
157
165
|
conversation?: AgentTurnConversation;
|
|
166
|
+
/**
|
|
167
|
+
* After the answer, ask the same model for follow-up chips and return them
|
|
168
|
+
* with the turn result. Set only for a human-facing turn.
|
|
169
|
+
*/
|
|
170
|
+
followUps?: true;
|
|
158
171
|
}
|
|
159
172
|
/**
|
|
160
173
|
* What `@lobu/plugin-conversations` calls `GatewayParams` minus the two the
|
|
@@ -385,5 +398,13 @@ export interface AgentTurnOutput {
|
|
|
385
398
|
* suppression does the rest.
|
|
386
399
|
*/
|
|
387
400
|
repliedInBand?: boolean;
|
|
401
|
+
/**
|
|
402
|
+
* Follow-up chips the same model proposed for the owner's answer, already
|
|
403
|
+
* sanitized. Absent when the turn was not offered them or proposed none.
|
|
404
|
+
*/
|
|
405
|
+
suggestions?: Array<{
|
|
406
|
+
title: string;
|
|
407
|
+
message: string;
|
|
408
|
+
}>;
|
|
388
409
|
}
|
|
389
410
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -329,6 +329,7 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
329
329
|
baseUrl: turn.provider.base_url,
|
|
330
330
|
...(turn.provider.max_tokens !== undefined ? { maxTokens: turn.provider.max_tokens } : {}),
|
|
331
331
|
...(turn.provider.reasoning !== undefined ? { reasoning: turn.provider.reasoning } : {}),
|
|
332
|
+
...(turn.provider.thinking_level_map ? { thinkingLevelMap: turn.provider.thinking_level_map } : {}),
|
|
332
333
|
// pi-ai's own `Model.input`, resolved by the gateway from pi-ai's
|
|
333
334
|
// model registry. Passed through untouched: pi is what enforces it.
|
|
334
335
|
...(turn.provider.input ? { input: turn.provider.input } : {}),
|
|
@@ -393,8 +394,10 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
393
394
|
...(turn.tools.media && turn.tools.media.length > 0
|
|
394
395
|
? { media: turn.tools.media }
|
|
395
396
|
: {}),
|
|
397
|
+
...(turn.tools.follow_ups ? { followUps: true } : {}),
|
|
396
398
|
...((turn.tools.gateway && turn.tools.gateway.length > 0) ||
|
|
397
|
-
(turn.tools.media && turn.tools.media.length > 0)
|
|
399
|
+
(turn.tools.media && turn.tools.media.length > 0) ||
|
|
400
|
+
turn.tools.follow_ups
|
|
398
401
|
? {
|
|
399
402
|
conversation: {
|
|
400
403
|
channelId: turn.tools.conversation.channel_id,
|
|
@@ -573,6 +576,7 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
|
|
|
573
576
|
...(input.firstError ? { first_error: input.firstError } : {}),
|
|
574
577
|
})),
|
|
575
578
|
...(result.turn.repliedInBand ? { replied_in_band: true } : {}),
|
|
579
|
+
...(result.turn.suggestions ? { suggestions: result.turn.suggestions } : {}),
|
|
576
580
|
exit_reason: 'ok',
|
|
577
581
|
});
|
|
578
582
|
if (receipt.status !== 'completed')
|
|
@@ -67,13 +67,6 @@ export interface AutomationExecutorConfig {
|
|
|
67
67
|
/** Maintained ACP entrypoints keyed by the local agent kind they drive. */
|
|
68
68
|
acpAdapters?: AutomationAcpAdapters;
|
|
69
69
|
}
|
|
70
|
-
/** Shared liveness/cancellation control for every device-local agent run. */
|
|
71
|
-
export declare function monitorDeviceAgentRun(client: ExecutorClient, runId: number, cfg: AutomationExecutorConfig, label: string): {
|
|
72
|
-
abortController: AbortController;
|
|
73
|
-
terminalSignal: AbortSignal;
|
|
74
|
-
shutdownRequested: () => boolean;
|
|
75
|
-
stop: () => void;
|
|
76
|
-
};
|
|
77
70
|
/** Local-CLI run result, mirrored from the Mac app's `ExecutorResult`. */
|
|
78
71
|
export interface ExecutorResult {
|
|
79
72
|
output: string;
|
|
@@ -100,10 +93,10 @@ export interface DeviceAgentRunAccess {
|
|
|
100
93
|
env: Record<string, string>;
|
|
101
94
|
}
|
|
102
95
|
/**
|
|
103
|
-
* Resolve what credential the spawned CLI runs with
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
96
|
+
* Resolve what credential the spawned Automation CLI runs with. When the poll
|
|
97
|
+
* envelope carries a per-run `agent_session`, the CLI authenticates as the
|
|
98
|
+
* run's assigned agent for exactly this run: the session token goes into the
|
|
99
|
+
* MCP wiring AND into
|
|
107
100
|
* LOBU_API_TOKEN/LOBU_MEMORY_URL, which `lobu memory` prefers
|
|
108
101
|
* over the device's ambient CLI session — so an unattended run never acts as
|
|
109
102
|
* the human user or the daemon. Without a session (older server, or a run with
|
|
@@ -36,8 +36,8 @@ import { WorkerDecodeError, WorkerHttpError } from './client.js';
|
|
|
36
36
|
import { log } from './log.js';
|
|
37
37
|
import { attachedInteractiveSession, handoffToInteractiveSession, } from './interactive-session.js';
|
|
38
38
|
import { AcpTranscript, runAcpTurn, } from './automation-acp.js';
|
|
39
|
-
/**
|
|
40
|
-
|
|
39
|
+
/** Liveness and cancellation control for a device Automation run. */
|
|
40
|
+
function monitorDeviceAgentRun(client, runId, cfg, label) {
|
|
41
41
|
const abortController = new AbortController();
|
|
42
42
|
const terminalController = new AbortController();
|
|
43
43
|
let shutdownRequested = false;
|
|
@@ -48,20 +48,23 @@ export function monitorDeviceAgentRun(client, runId, cfg, label) {
|
|
|
48
48
|
cfg.shutdownSignal?.addEventListener('abort', onShutdown, { once: true });
|
|
49
49
|
if (cfg.shutdownSignal?.aborted)
|
|
50
50
|
onShutdown();
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
// Beat once at start: the server's fast stale reaper only covers a run that
|
|
52
|
+
// has beaten since its claim, and a CLI that exits before the first interval
|
|
53
|
+
// would otherwise wait out the coarse TTL if its exit report is lost.
|
|
54
|
+
const beat = () => client.heartbeat(runId).catch((error) => {
|
|
55
|
+
if (error instanceof WorkerHttpError && error.status === 409) {
|
|
56
|
+
if (!abortController.signal.aborted) {
|
|
57
|
+
log.info(`[executor] ${label} run ${runId} is no longer active; stopping the local CLI`);
|
|
58
|
+
terminalController.abort();
|
|
59
|
+
abortController.abort();
|
|
60
|
+
clearInterval(heartbeat);
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
log.debug(`[executor] ${label} heartbeat failed:`, error);
|
|
65
|
+
});
|
|
66
|
+
const heartbeat = setInterval(beat, cfg.heartbeatIntervalMs ?? 30_000);
|
|
67
|
+
void beat();
|
|
65
68
|
return {
|
|
66
69
|
abortController,
|
|
67
70
|
terminalSignal: terminalController.signal,
|
|
@@ -90,7 +93,9 @@ export const DEFAULT_DEVICE_AGENT_TIMEOUT_MS = 600_000;
|
|
|
90
93
|
/** Cap on the CLI-output tail folded into `runs.error_message`. */
|
|
91
94
|
const DETAIL_TAIL_CHARS = 500;
|
|
92
95
|
const LOCAL_MAX_ROUNDS = 8;
|
|
93
|
-
|
|
96
|
+
/** Backoff doubles from 2s, so retries span ~1 min, outlasting a heartbeat
|
|
97
|
+
* interval and a brief gateway outage. */
|
|
98
|
+
const EXIT_REPORT_DELIVERY_ATTEMPTS = 6;
|
|
94
99
|
const EXIT_REPORT_RETRY_DELAY_MS = 2000;
|
|
95
100
|
const TRANSCRIPT_DELIVERY_ATTEMPTS = 3;
|
|
96
101
|
const TRANSCRIPT_RETRY_DELAY_MS = 250;
|
|
@@ -292,10 +297,10 @@ function claudeSessionMeta(base, maxBudgetUsd) {
|
|
|
292
297
|
};
|
|
293
298
|
}
|
|
294
299
|
/**
|
|
295
|
-
* Resolve what credential the spawned CLI runs with
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
300
|
+
* Resolve what credential the spawned Automation CLI runs with. When the poll
|
|
301
|
+
* envelope carries a per-run `agent_session`, the CLI authenticates as the
|
|
302
|
+
* run's assigned agent for exactly this run: the session token goes into the
|
|
303
|
+
* MCP wiring AND into
|
|
299
304
|
* LOBU_API_TOKEN/LOBU_MEMORY_URL, which `lobu memory` prefers
|
|
300
305
|
* over the device's ambient CLI session — so an unattended run never acts as
|
|
301
306
|
* the human user or the daemon. Without a session (older server, or a run with
|
|
@@ -865,7 +870,7 @@ export async function deliverExitReport(client, runId, result, finalizeAttempt)
|
|
|
865
870
|
if (!retriable)
|
|
866
871
|
return null;
|
|
867
872
|
if (attempt + 1 < EXIT_REPORT_DELIVERY_ATTEMPTS) {
|
|
868
|
-
await sleep(EXIT_REPORT_RETRY_DELAY_MS *
|
|
873
|
+
await sleep(EXIT_REPORT_RETRY_DELAY_MS * 2 ** attempt);
|
|
869
874
|
}
|
|
870
875
|
}
|
|
871
876
|
}
|
|
@@ -50,7 +50,6 @@ export interface ExecutorClient {
|
|
|
50
50
|
* re-spawn with the returned nudge.
|
|
51
51
|
*/
|
|
52
52
|
completeAutomation(runId: number, req: CompleteAutomationRequest): Promise<CompleteAutomationResponse>;
|
|
53
|
-
completeDeviceChat(runId: number, req: CompleteDeviceChatRequest): Promise<CompleteDeviceChatResponse>;
|
|
54
53
|
/**
|
|
55
54
|
* Report an agent turn. Fleet-only, so it posts to the shared worker route
|
|
56
55
|
* rather than the device-scoped `/me/runs/...` family.
|
|
@@ -70,8 +69,8 @@ export interface ExecutorClient {
|
|
|
70
69
|
* module's public surface is unchanged for importers, while the server annotates
|
|
71
70
|
* its request-body reads with the same shapes from that file.
|
|
72
71
|
*/
|
|
73
|
-
export type { CompleteActionRequest, CompleteAgentTurnRequest, CompleteAgentTurnResponse, CompleteAuthRequest, CompleteAutomationRequest, CompleteAutomationResponse,
|
|
74
|
-
import type { ConnectorHttpRequest, ConnectorHttpResponse, CompleteActionRequest, CompleteAgentTurnRequest, CompleteAgentTurnResponse, CompleteAuthRequest, CompleteAutomationRequest, CompleteAutomationResponse,
|
|
72
|
+
export type { CompleteActionRequest, CompleteAgentTurnRequest, CompleteAgentTurnResponse, CompleteAuthRequest, CompleteAutomationRequest, CompleteAutomationResponse, CompleteEmbeddingsRequest, CompleteRequest, ContentItem, DispatchChromeActionRequest, DispatchChromeActionResponse, EmbedEvent, EmitAuthArtifactRequest, HeartbeatRequest, HeartbeatResponse, OAuthCredentials, PollAuthSignalRequest, PollAuthSignalResponse, PollResponse, StreamBatch, } from "@lobu/core/contracts/worker/protocol";
|
|
73
|
+
import type { ConnectorHttpRequest, ConnectorHttpResponse, CompleteActionRequest, CompleteAgentTurnRequest, CompleteAgentTurnResponse, CompleteAuthRequest, CompleteAutomationRequest, CompleteAutomationResponse, CompleteEmbeddingsRequest, CompleteRequest, DispatchChromeActionRequest, EmbedEvent, EmitAuthArtifactRequest, ExecuteConnectorOperationRequest, HeartbeatRequest, HeartbeatResponse, PollAuthSignalRequest, PollAuthSignalResponse, PollResponse, StreamBatch } from "@lobu/core/contracts/worker/protocol";
|
|
75
74
|
import type { ConnectorOperationResult } from "@lobu/core/contracts/tools/manage-operations";
|
|
76
75
|
import type { AgentKind } from "@lobu/core/contracts/worker/device-automation";
|
|
77
76
|
/** Capability strings the worker advertises, keyed by name (e.g. `browser.debugger`). */
|
|
@@ -246,7 +245,6 @@ export declare class WorkerClient implements ExecutorClient {
|
|
|
246
245
|
*/
|
|
247
246
|
completeAutomation(runId: number, req: CompleteAutomationRequest): Promise<CompleteAutomationResponse>;
|
|
248
247
|
completeAgentTurn(req: CompleteAgentTurnRequest): Promise<CompleteAgentTurnResponse>;
|
|
249
|
-
completeDeviceChat(runId: number, req: CompleteDeviceChatRequest): Promise<CompleteDeviceChatResponse>;
|
|
250
248
|
get mcpWiring(): {
|
|
251
249
|
url: string;
|
|
252
250
|
bearer?: string;
|
|
@@ -363,9 +363,6 @@ export class WorkerClient {
|
|
|
363
363
|
async completeAgentTurn(req) {
|
|
364
364
|
return this.requestJson('/api/workers/complete-agent-turn', req);
|
|
365
365
|
}
|
|
366
|
-
async completeDeviceChat(runId, req) {
|
|
367
|
-
return this.requestJson(`/api/workers/me/runs/${runId}/complete-chat`, req);
|
|
368
|
-
}
|
|
369
366
|
get mcpWiring() {
|
|
370
367
|
if (!this.authToken)
|
|
371
368
|
return undefined;
|
|
@@ -10,7 +10,6 @@ import { executeAutomationRun } from './automation.js';
|
|
|
10
10
|
import { monitorActionRun } from './action-monitor.js';
|
|
11
11
|
import { executeDaemonBuiltinActionRun, hasDaemonBuiltin, hasDaemonBuiltinConnector, } from './builtins/index.js';
|
|
12
12
|
import { executeAgentTurnRun } from './agent-turn.js';
|
|
13
|
-
import { executeDeviceChatRun } from './device-chat.js';
|
|
14
13
|
import { attachedInteractiveSession, attachInteractiveSession } from './interactive-session.js';
|
|
15
14
|
import { log } from './log.js';
|
|
16
15
|
import { reportTerminalFailure } from './terminal-failure.js';
|
|
@@ -217,8 +216,6 @@ export async function executeRun(client, job, workerEnv, config = {}) {
|
|
|
217
216
|
// unreachable for them — but if a run does slip through (deploy skew), the
|
|
218
217
|
// dispatcher reports the failure rather than stomping the run.
|
|
219
218
|
return await executeAutomationRun(client, job, cfg);
|
|
220
|
-
case 'chat_message':
|
|
221
|
-
return await executeDeviceChatRun(client, job, cfg);
|
|
222
219
|
case 'agent_turn':
|
|
223
220
|
return await executeAgentTurnRun(client, job, env, cfg);
|
|
224
221
|
case 'embed_backfill':
|
|
@@ -5,6 +5,7 @@ import { WorkerPollLoop } from './poll-loop.js';
|
|
|
5
5
|
import { NativeBridgeClient } from './native-bridge/client.js';
|
|
6
6
|
import { NATIVE_BRIDGE_PROTOCOL } from './native-bridge/protocol.js';
|
|
7
7
|
export declare const MAC_DEVICE_PLATFORM = "macos";
|
|
8
|
+
export type ValidatedMacDeviceDaemonOptions = Required<Pick<MacDeviceDaemonOptions, 'apiUrl' | 'workerId' | 'workerApiToken'>> & Omit<MacDeviceDaemonOptions, 'apiUrl' | 'workerId' | 'workerApiToken'>;
|
|
8
9
|
export declare const INTERNAL_ACP_ADAPTER_ARG = "--internal-acp-adapter";
|
|
9
10
|
export interface MacDeviceDaemonOptions {
|
|
10
11
|
apiUrl?: string;
|
|
@@ -40,7 +41,7 @@ export declare function macDeviceDaemonMetadata(version: string): MacDeviceDaemo
|
|
|
40
41
|
export declare function packagedDaemonArgs(...args: string[]): string[];
|
|
41
42
|
export declare function selectMacDeviceDaemonAgentKind(runnableAgentKinds: readonly AgentKind[], explicitAgentKind?: AgentKind): AgentKind | undefined;
|
|
42
43
|
export declare function createMacDeviceDaemonShutdown(controller: AbortController, loop: WorkerPollLoop, bridge?: NativeBridgeClient, shutdownTimeoutMs?: number): () => Promise<void>;
|
|
43
|
-
export declare function validateMacDeviceDaemonOptions(options: MacDeviceDaemonOptions, hostThreads?: number):
|
|
44
|
+
export declare function validateMacDeviceDaemonOptions(options: MacDeviceDaemonOptions, hostThreads?: number): ValidatedMacDeviceDaemonOptions;
|
|
44
45
|
/**
|
|
45
46
|
* Whether the app advertised a local implementation of this run's connector.
|
|
46
47
|
*
|
|
@@ -66,10 +67,10 @@ export declare function executeAdvertisedConnectorRun(client: WorkerClient, job:
|
|
|
66
67
|
bridge: NativeBridgeClient | undefined;
|
|
67
68
|
shutdownSignal?: AbortSignal;
|
|
68
69
|
}): Promise<unknown>;
|
|
69
|
-
export declare function createMacDeviceDaemon(options:
|
|
70
|
+
export declare function createMacDeviceDaemon(options: ValidatedMacDeviceDaemonOptions, dependencies?: {
|
|
70
71
|
advertisementProvider?: MutableWorkerAdvertisementProvider;
|
|
71
72
|
bridge?: NativeBridgeClient;
|
|
72
73
|
shutdownController?: AbortController;
|
|
73
74
|
}): WorkerPollLoop;
|
|
74
|
-
export declare function runMacDeviceDaemon(options:
|
|
75
|
+
export declare function runMacDeviceDaemon(options: ValidatedMacDeviceDaemonOptions): Promise<void>;
|
|
75
76
|
//# sourceMappingURL=mac-device-daemon.d.ts.map
|
|
@@ -3,7 +3,6 @@ import { AGENT_KINDS, } from '@lobu/core/contracts/worker/device-automation';
|
|
|
3
3
|
import { executeAutomationRun } from './automation.js';
|
|
4
4
|
import { executeDaemonBuiltinActionRun, hasDaemonBuiltin } from './builtins/index.js';
|
|
5
5
|
import { defaultDeviceMaxConcurrentJobs } from './device-concurrency.js';
|
|
6
|
-
import { executeDeviceChatRun } from './device-chat.js';
|
|
7
6
|
import { locateBinary, resolveRunnableAgentKinds, supportsOpenCodeAcp, } from './agent-binaries.js';
|
|
8
7
|
import { MutableWorkerAdvertisementProvider, WorkerClient, WorkerHttpError, } from './client.js';
|
|
9
8
|
import { installWorkerPollLoopSignals, WorkerPollLoop } from './poll-loop.js';
|
|
@@ -12,8 +11,8 @@ import { NativeBridgeClient } from './native-bridge/client.js';
|
|
|
12
11
|
import { executeNativeBridgeRun } from './native-bridge/executor.js';
|
|
13
12
|
import { NATIVE_BRIDGE_PROTOCOL } from './native-bridge/protocol.js';
|
|
14
13
|
import { reportTerminalFailure } from './terminal-failure.js';
|
|
14
|
+
import { assertValidWorkerId } from './worker-id.js';
|
|
15
15
|
export const MAC_DEVICE_PLATFORM = 'macos';
|
|
16
|
-
const WORKER_ID_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
17
16
|
const WORKER_PAT_PATTERN = /^owl_pat_[A-Za-z0-9_-]{32}$/;
|
|
18
17
|
const DEFAULT_POLL_INTERVAL_MS = 10000;
|
|
19
18
|
// Source reads default to a ten-second end-to-end deadline. Keep the signed
|
|
@@ -120,9 +119,7 @@ function withTimeout(promise, timeoutMs, label) {
|
|
|
120
119
|
}
|
|
121
120
|
export function validateMacDeviceDaemonOptions(options, hostThreads) {
|
|
122
121
|
const workerId = options.workerId?.trim() || defaultWorkerId();
|
|
123
|
-
|
|
124
|
-
throw new Error(`invalid --worker-id '${workerId}': expected 1-128 characters of letters, digits, dot, underscore, colon or hyphen`);
|
|
125
|
-
}
|
|
122
|
+
assertValidWorkerId(workerId);
|
|
126
123
|
const pollIntervalMs = validateNumber(options.pollIntervalMs, '--poll-interval-ms');
|
|
127
124
|
const maxConcurrentJobs = validateNumber(options.maxConcurrentJobs, '--max-concurrent-jobs');
|
|
128
125
|
const defaultAgentKind = validateAgentKind(options.defaultAgentKind);
|
|
@@ -220,7 +217,7 @@ export async function executeAdvertisedConnectorRun(client, job, dependencies) {
|
|
|
220
217
|
return executeNativeBridgeRun(client, dependencies.bridge, job);
|
|
221
218
|
}
|
|
222
219
|
export function createMacDeviceDaemon(options, dependencies = {}) {
|
|
223
|
-
const validated =
|
|
220
|
+
const validated = options;
|
|
224
221
|
if (validated.noPoll)
|
|
225
222
|
throw new Error('cannot create a polling daemon with --no-poll');
|
|
226
223
|
const discoveredAgentKinds = resolveRunnableAgentKinds();
|
|
@@ -317,9 +314,6 @@ export function createMacDeviceDaemon(options, dependencies = {}) {
|
|
|
317
314
|
if (job.run_type === 'automation') {
|
|
318
315
|
return executeAutomationRun(client, job, automationConfig);
|
|
319
316
|
}
|
|
320
|
-
if (job.run_type === 'chat_message') {
|
|
321
|
-
return executeDeviceChatRun(client, job, automationConfig);
|
|
322
|
-
}
|
|
323
317
|
if (job.run_type === 'sync' || job.run_type === 'action' || job.run_type === 'auth') {
|
|
324
318
|
return executeAdvertisedConnectorRun(client, job, {
|
|
325
319
|
advertisementProvider: dependencies.advertisementProvider,
|
|
@@ -337,7 +331,7 @@ export function createMacDeviceDaemon(options, dependencies = {}) {
|
|
|
337
331
|
}
|
|
338
332
|
export async function runMacDeviceDaemon(options) {
|
|
339
333
|
setDebug(options.debug === true);
|
|
340
|
-
const validated =
|
|
334
|
+
const validated = options;
|
|
341
335
|
if (validated.noPoll)
|
|
342
336
|
return;
|
|
343
337
|
if (validated.supervisedStdio) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { log } from '../log.js';
|
|
3
|
+
import { reportTerminalFailure } from '../terminal-failure.js';
|
|
3
4
|
const FEED_READ_ACTION = '__lobu_feed_read';
|
|
4
5
|
const NATIVE_BRIDGE_HEARTBEAT_INTERVAL_MS = 30_000;
|
|
5
6
|
export const NATIVE_BRIDGE_EXECUTION_TIMEOUT_MS = 600_000;
|
|
@@ -8,7 +9,7 @@ export async function executeNativeBridgeRun(client, bridge, job, timeoutMs = NA
|
|
|
8
9
|
throw new Error('native bridge run is missing run_id');
|
|
9
10
|
const runId = job.run_id;
|
|
10
11
|
const requestId = randomUUID();
|
|
11
|
-
let
|
|
12
|
+
let currentOperation;
|
|
12
13
|
let itemsCollected = 0;
|
|
13
14
|
let checkpoint = asRecord(job.checkpoint);
|
|
14
15
|
let terminalDelivered = false;
|
|
@@ -70,8 +71,7 @@ export async function executeNativeBridgeRun(client, bridge, job, timeoutMs = NA
|
|
|
70
71
|
await deliverTerminal(() => client.completeAuth(payload));
|
|
71
72
|
};
|
|
72
73
|
try {
|
|
73
|
-
|
|
74
|
-
operation = currentOperation;
|
|
74
|
+
currentOperation = nativeOperation(job);
|
|
75
75
|
heartbeatInterval = setInterval(() => {
|
|
76
76
|
void client.heartbeat(runId).catch((error) => {
|
|
77
77
|
log.debug(`[native-bridge] Heartbeat for run ${runId} failed:`, error);
|
|
@@ -116,27 +116,32 @@ export async function executeNativeBridgeRun(client, bridge, job, timeoutMs = NA
|
|
|
116
116
|
catch (error) {
|
|
117
117
|
const message = error instanceof Error ? error.message : String(error);
|
|
118
118
|
log.info(`[native-bridge] Run ${runId} failed:`, message);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
119
|
+
if (terminalReporter !== undefined) {
|
|
120
|
+
// A success terminal was already selected but its delivery budget is
|
|
121
|
+
// exhausted. Its outcome is immutable: never flip an executed run to
|
|
122
|
+
// failed and drop its output — leave it for stale-run handling.
|
|
123
|
+
log.info(`[native-bridge] Terminal report for run ${runId} failed:`, message);
|
|
124
|
+
}
|
|
125
|
+
else if (currentOperation === 'sync' || currentOperation === 'auth') {
|
|
126
|
+
// No terminal was selected yet and the run is a sync/auth: keep its
|
|
127
|
+
// own completion, preserving the bounded retry and partial progress.
|
|
128
|
+
const complete = currentOperation === 'sync' ? completeSync : completeAuth;
|
|
129
|
+
try {
|
|
130
|
+
await complete({}, message);
|
|
131
|
+
}
|
|
132
|
+
catch (completionError) {
|
|
133
|
+
log.info(`[native-bridge] Terminal report for run ${runId} failed:`, completionError);
|
|
132
134
|
}
|
|
133
|
-
else if (job.run_type === 'embed_backfill')
|
|
134
|
-
await completeSync({}, message);
|
|
135
|
-
else
|
|
136
|
-
await completeAction({}, message);
|
|
137
135
|
}
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
else {
|
|
137
|
+
// No terminal was selected yet (bridge, stream, or timeout failure on
|
|
138
|
+
// any other run shape): report it under the run's own type.
|
|
139
|
+
try {
|
|
140
|
+
await reportTerminalFailure(client, job, message, 'error_message');
|
|
141
|
+
}
|
|
142
|
+
catch (completionError) {
|
|
143
|
+
log.info(`[native-bridge] Terminal report for run ${runId} failed:`, completionError);
|
|
144
|
+
}
|
|
140
145
|
}
|
|
141
146
|
return { itemsCollected, error: message };
|
|
142
147
|
}
|
|
@@ -165,9 +170,6 @@ async function runWithTimeout(bridge, requestId, runId, timeoutMs, run) {
|
|
|
165
170
|
}
|
|
166
171
|
}
|
|
167
172
|
function nativeOperation(job) {
|
|
168
|
-
if (job.run_type === 'automation' || job.run_type === 'embed_backfill') {
|
|
169
|
-
throw new Error('native bridge does not execute run_type ' + String(job.run_type));
|
|
170
|
-
}
|
|
171
173
|
if (job.run_type === 'sync')
|
|
172
174
|
return 'sync';
|
|
173
175
|
if (job.run_type === 'auth')
|
|
@@ -16,13 +16,7 @@ import { DEVICE_MANIFESTS_BY_PLATFORM } from './device-manifests.js';
|
|
|
16
16
|
import { startDaemon } from './index.js';
|
|
17
17
|
import { log, setDebug } from './log.js';
|
|
18
18
|
import { attachInteractiveSession, deriveInteractiveWorkerId, detectInteractiveSession, } from './interactive-session.js';
|
|
19
|
-
|
|
20
|
-
* Accepted `--worker-id` shape. Deliberately narrow: the default is
|
|
21
|
-
* `<platform>:<short-hostname>` (or a session-derived id in a supported
|
|
22
|
-
* interactive agent), and anything a shell, a URL path, or a JSON payload
|
|
23
|
-
* would mangle has no business being a durable device identity.
|
|
24
|
-
*/
|
|
25
|
-
const WORKER_ID_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
19
|
+
import { assertValidWorkerId } from './worker-id.js';
|
|
26
20
|
export function resolveDaemonWorkerId(opts, platform, shortHostname, interactiveSession) {
|
|
27
21
|
return (opts.workerId ??
|
|
28
22
|
(interactiveSession
|
|
@@ -72,14 +66,8 @@ export async function startDaemonCommand(opts) {
|
|
|
72
66
|
if (platform && !isKnownPlatform(platform)) {
|
|
73
67
|
throw new Error(`unknown device platform '${platform}'`);
|
|
74
68
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// An unusable value therefore does not fail loudly — it mints a second device
|
|
78
|
-
// and the pinned Automations go quiet on this one. Reject it at boot instead.
|
|
79
|
-
if (opts.workerId !== undefined && !WORKER_ID_PATTERN.test(opts.workerId)) {
|
|
80
|
-
throw new Error(`invalid --worker-id '${opts.workerId}': expected 1-128 characters of ` +
|
|
81
|
-
'letters, digits, dot, underscore, colon or hyphen');
|
|
82
|
-
}
|
|
69
|
+
if (opts.workerId !== undefined)
|
|
70
|
+
assertValidWorkerId(opts.workerId);
|
|
83
71
|
if (capabilities.length > 0 && !platform) {
|
|
84
72
|
throw new Error('--capabilities requires --platform so the server can authorize the device capability set');
|
|
85
73
|
}
|
|
@@ -20,17 +20,6 @@ export async function reportTerminalFailure(client, job, message, exitReason = '
|
|
|
20
20
|
});
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
if (job.run_type === 'chat_message') {
|
|
24
|
-
// Device chat completes through its adapter so the waiting Activity turn
|
|
25
|
-
// receives a thread_response. Generic sync completion would finalize the
|
|
26
|
-
// row without publishing that response.
|
|
27
|
-
await client.completeDeviceChat(job.run_id, {
|
|
28
|
-
worker_id: client.id,
|
|
29
|
-
error: message,
|
|
30
|
-
exit_reason: exitReason,
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
23
|
if (job.run_type === 'agent_turn') {
|
|
35
24
|
// The generic route refuses an agent turn with a 409, so a failure that
|
|
36
25
|
// fell through to it would leave the run parked until the stale sweep.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared device-daemon worker-id shape.
|
|
3
|
+
*
|
|
4
|
+
* Accepted `--worker-id` shape. Deliberately narrow: the default is
|
|
5
|
+
* `<platform>:<short-hostname>` (or a session-derived id in a supported
|
|
6
|
+
* interactive agent), and anything a shell, a URL path, or a JSON payload
|
|
7
|
+
* would mangle has no business being a durable device identity.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* `worker_id` is the device's identity: the server upserts on
|
|
11
|
+
* (user_id, worker_id) and Automation pins resolve the device row through it.
|
|
12
|
+
* An unusable value therefore does not fail loudly — it mints a second device
|
|
13
|
+
* and the pinned Automations go quiet on this one. Reject it at boot instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare const WORKER_ID_PATTERN: RegExp;
|
|
16
|
+
export declare function assertValidWorkerId(workerId: string): void;
|
|
17
|
+
//# sourceMappingURL=worker-id.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared device-daemon worker-id shape.
|
|
3
|
+
*
|
|
4
|
+
* Accepted `--worker-id` shape. Deliberately narrow: the default is
|
|
5
|
+
* `<platform>:<short-hostname>` (or a session-derived id in a supported
|
|
6
|
+
* interactive agent), and anything a shell, a URL path, or a JSON payload
|
|
7
|
+
* would mangle has no business being a durable device identity.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* `worker_id` is the device's identity: the server upserts on
|
|
11
|
+
* (user_id, worker_id) and Automation pins resolve the device row through it.
|
|
12
|
+
* An unusable value therefore does not fail loudly — it mints a second device
|
|
13
|
+
* and the pinned Automations go quiet on this one. Reject it at boot instead.
|
|
14
|
+
*/
|
|
15
|
+
export const WORKER_ID_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
16
|
+
export function assertValidWorkerId(workerId) {
|
|
17
|
+
if (!WORKER_ID_PATTERN.test(workerId)) {
|
|
18
|
+
throw new Error(`invalid --worker-id '${workerId}': expected 1-128 characters of ` +
|
|
19
|
+
'letters, digits, dot, underscore, colon or hyphen');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=worker-id.js.map
|