@lobu/runtime-device 21.2.1 → 23.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 +91 -83
- package/npm-shrinkwrap.json +492 -438
- package/package.json +12 -2
- package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +1 -1
- package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +5 -6
- package/vendor/cli/dist/commands/_lib/apply/client.d.ts +1 -0
- package/vendor/cli/dist/commands/_lib/apply/client.js +26 -7
- package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +9 -1
- package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +1 -0
- package/vendor/cli/dist/commands/_lib/apply/diff.js +46 -4
- package/vendor/cli/dist/commands/_lib/apply/map-config.js +18 -38
- package/vendor/cli/dist/commands/_lib/init-from-org/bootstrap.js +5 -17
- package/vendor/cli/dist/commands/init.d.ts +0 -2
- package/vendor/cli/dist/commands/init.js +0 -27
- package/vendor/cli/dist/commands/login.d.ts +17 -0
- package/vendor/cli/dist/commands/login.js +43 -17
- package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +0 -8
- package/vendor/cli/dist/commands/memory/_lib/errors.js +0 -12
- package/vendor/cli/dist/commands/memory/_lib/mcp.js +6 -6
- package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +4 -10
- package/vendor/cli/dist/config/define.d.ts +21 -15
- package/vendor/cli/dist/config/define.js +2 -2
- package/vendor/cli/dist/connectors/README.md +21 -6
- package/vendor/cli/dist/connectors/_google/actions.ts +270 -0
- package/vendor/cli/dist/connectors/_google/discovery/calendar_v3.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/chat_v1.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/docs_v1.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/drive_v3.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/gmail_v1.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/people_v1.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/sheets_v4.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/tasks_v1.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery/youtube_v3.json +1 -0
- package/vendor/cli/dist/connectors/_google/discovery.ts +442 -0
- package/vendor/cli/dist/connectors/_google/errors.ts +91 -0
- package/vendor/cli/dist/connectors/_google/list-feed.ts +223 -0
- package/vendor/cli/dist/connectors/_google/policies.ts +127 -0
- package/vendor/cli/dist/connectors/agentid.ts +43 -0
- package/vendor/cli/dist/connectors/chat-user-identity.ts +2 -1
- package/vendor/cli/dist/connectors/github-automation-events.ts +9 -0
- package/vendor/cli/dist/connectors/github-identity.ts +28 -3
- package/vendor/cli/dist/connectors/github.ts +101 -59
- package/vendor/cli/dist/connectors/google_calendar.ts +207 -719
- package/vendor/cli/dist/connectors/google_drive.ts +16 -2
- package/vendor/cli/dist/connectors/google_gmail.ts +52 -33
- package/vendor/cli/dist/connectors/herdr.ts +406 -0
- package/vendor/cli/dist/connectors/jira-helpers.ts +313 -0
- package/vendor/cli/dist/connectors/jira.ts +35 -227
- package/vendor/cli/dist/connectors/linear.ts +7 -4
- 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 +1185 -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 +3998 -0
- package/vendor/cli/dist/connectors/postgres.ts +27 -2
- package/vendor/cli/dist/connectors/takeout-utils.ts +240 -0
- package/vendor/cli/dist/connectors/tiktok-inbox-page.js +230 -0
- package/vendor/cli/dist/connectors/tiktok-web-page.js +217 -0
- package/vendor/cli/dist/connectors/tiktok_web.ts +319 -0
- package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +285 -567
- package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +74 -455
- package/vendor/cli/dist/connectors/whatsapp-web-identity.ts +135 -0
- package/vendor/cli/dist/connectors/whatsapp_web.ts +159 -618
- package/vendor/cli/dist/connectors/x-dm-adapter.js +556 -0
- package/vendor/cli/dist/connectors/x-identity.ts +31 -2
- package/vendor/cli/dist/connectors/x.ts +539 -253
- package/vendor/cli/dist/index.js +1 -37
- package/vendor/cli/dist/internal/context.d.ts +10 -0
- package/vendor/cli/dist/internal/context.js +26 -16
- package/vendor/cli/dist/internal/node-version.d.ts +1 -1
- package/vendor/cli/dist/internal/node-version.js +1 -1
- package/vendor/cli/dist/internal/oauth.d.ts +3 -1
- package/vendor/cli/dist/internal/oauth.js +4 -3
- package/vendor/cli/dist/internal/runtime-components.d.ts +9 -0
- package/vendor/cli/dist/internal/runtime-components.js +67 -2
- package/vendor/cli/dist/mac-auth.js +17 -1
- package/vendor/cli/dist/providers.json +1 -1
- package/vendor/cli/dist/runtime-components.json +4 -4
- package/vendor/cli/dist/templates/AGENTS.md.tmpl +12 -5
- package/vendor/cli/dist/templates/README.md.tmpl +1 -1
- package/vendor/cli/dist/vendor/ora/.bun-tag-fde20e9a6df212fa +0 -0
- package/vendor/cli/dist/vendor/ora/index.d.ts +332 -0
- package/vendor/cli/dist/vendor/ora/index.js +424 -0
- package/vendor/cli/dist/vendor/ora/license +9 -0
- package/vendor/cli/dist/vendor/ora/package.json +64 -0
- package/vendor/cli/dist/vendor/ora/readme.md +329 -0
- package/vendor/cli/package.json +2 -2
- 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-requirement.d.ts +36 -0
- package/vendor/connector-sdk/dist/browser-requirement.js +60 -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-runtime.d.ts +3 -1
- package/vendor/connector-sdk/dist/connector-runtime.js +10 -0
- package/vendor/connector-sdk/dist/connector-types.d.ts +169 -45
- package/vendor/connector-sdk/dist/define-connector.d.ts +4 -2
- package/vendor/connector-sdk/dist/define-connector.js +3 -0
- package/vendor/connector-sdk/dist/index.d.ts +8 -2
- package/vendor/connector-sdk/dist/index.js +3 -0
- package/vendor/connector-sdk/dist/reaction-client-types.d.ts +16 -21
- package/vendor/connector-sdk/dist/reaction-client-types.typecheck.d.ts +5 -0
- package/vendor/connector-sdk/package.json +13 -1
- package/vendor/connector-worker/dist/agent-turn/guest-entry.js +43 -30
- package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +416 -330
- package/vendor/connector-worker/dist/agent-turn/memory.d.ts +3 -2
- package/vendor/connector-worker/dist/agent-turn/memory.js +3 -20
- package/vendor/connector-worker/dist/agent-turn/types.d.ts +3 -15
- package/vendor/connector-worker/dist/agent-turn/workspace.d.ts +2 -2
- package/vendor/connector-worker/dist/agent-turn/workspace.js +2 -4
- package/vendor/connector-worker/dist/daemon/action-monitor.d.ts +12 -0
- package/vendor/connector-worker/dist/daemon/action-monitor.js +25 -0
- package/vendor/connector-worker/dist/daemon/agent-turn.js +0 -9
- package/vendor/connector-worker/dist/daemon/automation.d.ts +4 -11
- package/vendor/connector-worker/dist/daemon/automation.js +6 -6
- package/vendor/connector-worker/dist/daemon/builtins/index.d.ts +12 -0
- package/vendor/connector-worker/dist/daemon/builtins/index.js +61 -1
- package/vendor/connector-worker/dist/daemon/builtins/os-shell.d.ts +2 -1
- package/vendor/connector-worker/dist/daemon/builtins/os-shell.js +40 -27
- package/vendor/connector-worker/dist/daemon/client.d.ts +6 -4
- package/vendor/connector-worker/dist/daemon/client.js +3 -3
- package/vendor/connector-worker/dist/daemon/device-concurrency.d.ts +8 -0
- package/vendor/connector-worker/dist/daemon/device-concurrency.js +13 -0
- package/vendor/connector-worker/dist/daemon/executor.d.ts +1 -1
- package/vendor/connector-worker/dist/daemon/executor.js +48 -120
- package/vendor/connector-worker/dist/daemon/log.d.ts +2 -0
- package/vendor/connector-worker/dist/daemon/log.js +23 -2
- package/vendor/connector-worker/dist/daemon/mac-device-daemon.d.ts +23 -6
- package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +57 -23
- package/vendor/connector-worker/dist/daemon/native-bridge/client.d.ts +6 -0
- package/vendor/connector-worker/dist/daemon/native-bridge/client.js +15 -0
- package/vendor/connector-worker/dist/daemon/native-bridge/executor.js +29 -25
- package/vendor/connector-worker/dist/daemon/native-bridge/protocol.d.ts +1 -1
- package/vendor/connector-worker/dist/daemon/native-bridge/protocol.js +1 -0
- package/vendor/connector-worker/dist/daemon/poll-loop.d.ts +3 -0
- package/vendor/connector-worker/dist/daemon/poll-loop.js +5 -1
- package/vendor/connector-worker/dist/daemon/start.d.ts +1 -0
- package/vendor/connector-worker/dist/daemon/start.js +15 -20
- 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/executor/interface.d.ts +34 -2
- package/vendor/connector-worker/dist/executor/isolate.js +66 -15
- package/vendor/connector-worker/dist/executor/redact.d.ts +1 -0
- package/vendor/connector-worker/dist/executor/redact.js +97 -26
- package/vendor/connector-worker/dist/executor/runtime.d.ts +7 -0
- package/vendor/connector-worker/dist/executor/runtime.js +26 -0
- package/vendor/connector-worker/dist/isolate/bridge.js +3 -1
- package/vendor/connector-worker/dist/mac-device-daemon.js +24 -29
- package/vendor/connector-worker/package.json +2 -2
- package/vendor/core/dist/agent-policy.js +1 -1
- package/vendor/core/dist/agent-store.d.ts +2 -0
- package/vendor/core/dist/agent-tooling.d.ts +1 -1
- package/vendor/core/dist/agent-tooling.js +1 -1
- package/vendor/core/dist/capabilities.d.ts +1 -1
- package/vendor/core/dist/capabilities.js +2 -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 +0 -11
- package/vendor/core/dist/contracts/agent-settings.js +1 -7
- package/vendor/core/dist/contracts/tools/collection-presentation.d.ts +93 -0
- package/vendor/core/dist/contracts/tools/collection-presentation.js +88 -0
- package/vendor/core/dist/contracts/tools/collection-selection.d.ts +47 -0
- package/vendor/core/dist/contracts/tools/collection-selection.js +74 -0
- package/vendor/core/dist/contracts/tools/manage-agents.d.ts +10 -4
- package/vendor/core/dist/contracts/tools/manage-auth-profiles.d.ts +1 -1
- package/vendor/core/dist/contracts/tools/manage-auth-profiles.js +5 -1
- package/vendor/core/dist/contracts/tools/manage-automations.d.ts +19 -4
- package/vendor/core/dist/contracts/tools/manage-automations.js +25 -8
- package/vendor/core/dist/contracts/tools/manage-connections.d.ts +1 -0
- package/vendor/core/dist/contracts/tools/manage-connections.js +3 -0
- package/vendor/core/dist/contracts/tools/manage-conversations.js +2 -2
- package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +11 -0
- package/vendor/core/dist/contracts/tools/manage-entity-schema.js +42 -3
- package/vendor/core/dist/contracts/tools/manage-entity.d.ts +181 -152
- package/vendor/core/dist/contracts/tools/manage-entity.js +118 -162
- 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-operations.d.ts +41 -3
- package/vendor/core/dist/contracts/tools/manage-operations.js +40 -2
- package/vendor/core/dist/contracts/tools/manage-views.d.ts +182 -7
- package/vendor/core/dist/contracts/tools/manage-views.js +49 -13
- package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +11 -2
- package/vendor/core/dist/contracts/tools/read-knowledge.js +23 -3
- package/vendor/core/dist/contracts/tools/save-memory.d.ts +3 -6
- package/vendor/core/dist/contracts/tools/save-memory.js +2 -6
- package/vendor/core/dist/contracts/tools/view-attach.d.ts +2 -1
- package/vendor/core/dist/contracts/tools/view-attach.js +7 -2
- package/vendor/core/dist/contracts/worker/protocol.d.ts +130 -159
- package/vendor/core/dist/contracts/worker/protocol.js +88 -76
- 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 +5 -5
- package/vendor/core/dist/index.js +4 -6
- package/vendor/core/dist/json-template.d.ts +6 -10
- package/vendor/core/dist/json-template.js +5 -9
- package/vendor/core/dist/logger.js +17 -26
- package/vendor/core/dist/shell-safety.d.ts +9 -0
- package/vendor/core/dist/shell-safety.js +154 -0
- package/vendor/core/dist/suggestions.d.ts +1 -1
- package/vendor/core/dist/suggestions.js +1 -1
- package/vendor/core/dist/tool-trace-summary.d.ts +1 -1
- package/vendor/core/dist/tool-trace-summary.js +1 -1
- package/vendor/core/dist/types.d.ts +1 -3
- package/vendor/core/dist/utils/diagnostic-scrubber.d.ts +7 -0
- package/vendor/core/dist/utils/diagnostic-scrubber.js +437 -0
- package/vendor/core/dist/worker/auth.d.ts +44 -6
- package/vendor/core/dist/worker/auth.js +44 -11
- package/vendor/core/dist/worker/wire.d.ts +0 -10
- package/vendor/core/package.json +20 -11
- package/vendor/ora/.bun-tag-fde20e9a6df212fa +0 -0
- package/vendor/ora/index.d.ts +332 -0
- package/vendor/ora/index.js +424 -0
- package/vendor/ora/license +9 -0
- package/vendor/ora/package.json +53 -0
- package/vendor/ora/readme.md +329 -0
- package/vendor/cli/dist/commands/telemetry.d.ts +0 -10
- package/vendor/cli/dist/commands/telemetry.js +0 -66
- 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/core/dist/sentry.d.ts +0 -26
- package/vendor/core/dist/sentry.js +0 -133
- package/vendor/core/dist/tool-policy.d.ts +0 -74
- package/vendor/core/dist/tool-policy.js +0 -305
- package/vendor/core/dist/utils/sentry-scrubber.d.ts +0 -29
- package/vendor/core/dist/utils/sentry-scrubber.js +0 -228
|
@@ -40,6 +40,19 @@ import {
|
|
|
40
40
|
type SyncContext,
|
|
41
41
|
type SyncResult,
|
|
42
42
|
} from '@lobu/connector-sdk';
|
|
43
|
+
import { compileGoogleActions, executeGoogleAction, oauthScopes } from './_google/actions';
|
|
44
|
+
import type { DiscoveryDocument } from './_google/discovery';
|
|
45
|
+
import driveDiscovery from './_google/discovery/drive_v3.json';
|
|
46
|
+
import { GOOGLE_API_POLICIES } from './_google/policies';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Supported Drive API methods as actions, compiled from the pinned Discovery
|
|
50
|
+
* document. `download_file` and `get_file` stay hand-written: the first picks
|
|
51
|
+
* `files.export` or `alt=media` by MIME type, the second returns the feed's row
|
|
52
|
+
* shape — work the raw methods leave to the caller.
|
|
53
|
+
*/
|
|
54
|
+
const DRIVE_POLICY = GOOGLE_API_POLICIES.drive_v3;
|
|
55
|
+
const DRIVE = compileGoogleActions(driveDiscovery as unknown as DiscoveryDocument, DRIVE_POLICY);
|
|
43
56
|
|
|
44
57
|
// ---------------------------------------------------------------------------
|
|
45
58
|
// Drive API types
|
|
@@ -325,7 +338,7 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
|
|
|
325
338
|
{
|
|
326
339
|
type: 'oauth',
|
|
327
340
|
provider: 'google',
|
|
328
|
-
|
|
341
|
+
...oauthScopes(DRIVE_POLICY),
|
|
329
342
|
loginScopes: ['openid', 'email', 'profile'],
|
|
330
343
|
clientIdKey: 'GOOGLE_CLIENT_ID',
|
|
331
344
|
clientSecretKey: 'GOOGLE_CLIENT_SECRET',
|
|
@@ -405,6 +418,7 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
|
|
|
405
418
|
},
|
|
406
419
|
},
|
|
407
420
|
actions: {
|
|
421
|
+
...DRIVE.actions,
|
|
408
422
|
download_file: {
|
|
409
423
|
key: 'download_file',
|
|
410
424
|
kind: 'read',
|
|
@@ -831,7 +845,7 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
|
|
|
831
845
|
case 'get_file':
|
|
832
846
|
return await this.getFile(http, ctx.input);
|
|
833
847
|
default:
|
|
834
|
-
return
|
|
848
|
+
return await executeGoogleAction(DRIVE, ctx, http);
|
|
835
849
|
}
|
|
836
850
|
} catch (error) {
|
|
837
851
|
return {
|
|
@@ -23,8 +23,21 @@ import {
|
|
|
23
23
|
type SyncContext,
|
|
24
24
|
type SyncResult,
|
|
25
25
|
} from '@lobu/connector-sdk';
|
|
26
|
+
import { compileGoogleActions, executeGoogleAction, oauthScopes } from './_google/actions';
|
|
27
|
+
import type { DiscoveryDocument } from './_google/discovery';
|
|
28
|
+
import gmailDiscovery from './_google/discovery/gmail_v1.json';
|
|
29
|
+
import { GOOGLE_API_POLICIES } from './_google/policies';
|
|
26
30
|
import TurndownService from 'turndown';
|
|
27
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Supported Gmail API methods as actions, compiled from the pinned Discovery
|
|
34
|
+
* document. The hand-written actions below stay: they compose several calls
|
|
35
|
+
* or decode MIME (`get_thread` returns readable bodies, `send_email` builds the
|
|
36
|
+
* RFC 2822 message) — work the raw methods leave to the caller.
|
|
37
|
+
*/
|
|
38
|
+
const GMAIL_POLICY = GOOGLE_API_POLICIES.gmail_v1;
|
|
39
|
+
const GMAIL = compileGoogleActions(gmailDiscovery as unknown as DiscoveryDocument, GMAIL_POLICY);
|
|
40
|
+
|
|
28
41
|
function createEmailBodyConverter(): TurndownService {
|
|
29
42
|
const converter = new TurndownService({
|
|
30
43
|
headingStyle: 'atx',
|
|
@@ -167,15 +180,7 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
|
|
|
167
180
|
{
|
|
168
181
|
type: 'oauth',
|
|
169
182
|
provider: 'google',
|
|
170
|
-
|
|
171
|
-
'https://www.googleapis.com/auth/gmail.readonly',
|
|
172
|
-
// compose covers drafts.create AND messages.send, so it is the single
|
|
173
|
-
// write scope for create_draft/reply/send_email. It must be required
|
|
174
|
-
// (not optional) — optional scopes are only requested when the caller
|
|
175
|
-
// explicitly asks for them, so an unadorned connect() would omit it
|
|
176
|
-
// and every write op would 403 insufficient-scope.
|
|
177
|
-
'https://www.googleapis.com/auth/gmail.compose',
|
|
178
|
-
],
|
|
183
|
+
...oauthScopes(GMAIL_POLICY),
|
|
179
184
|
loginScopes: ['openid', 'email', 'profile'],
|
|
180
185
|
clientIdKey: 'GOOGLE_CLIENT_ID',
|
|
181
186
|
clientSecretKey: 'GOOGLE_CLIENT_SECRET',
|
|
@@ -241,6 +246,7 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
|
|
|
241
246
|
eventKinds: {
|
|
242
247
|
thread: {
|
|
243
248
|
description: 'A Gmail email thread',
|
|
249
|
+
updatedEvent: true,
|
|
244
250
|
metadataSchema: {
|
|
245
251
|
type: 'object',
|
|
246
252
|
properties: {
|
|
@@ -323,6 +329,7 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
|
|
|
323
329
|
},
|
|
324
330
|
},
|
|
325
331
|
actions: {
|
|
332
|
+
...GMAIL.actions,
|
|
326
333
|
send_email: {
|
|
327
334
|
key: 'send_email',
|
|
328
335
|
name: 'Send Email',
|
|
@@ -535,16 +542,10 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
|
|
|
535
542
|
for (const threadStub of threads) {
|
|
536
543
|
inspected++;
|
|
537
544
|
try {
|
|
538
|
-
const
|
|
539
|
-
// A thread deleted between list and
|
|
540
|
-
//
|
|
541
|
-
|
|
542
|
-
if (response.status === 404) continue;
|
|
543
|
-
if (!response.ok) {
|
|
544
|
-
throw new Error(`Gmail threads.get error (${response.status}): ${await response.text()}`);
|
|
545
|
-
}
|
|
546
|
-
const thread = (await response.json()) as GmailThreadGetResponse;
|
|
547
|
-
if (!thread.messages?.length) throw new Error('Gmail returned a thread without messages');
|
|
545
|
+
const thread = await this.loadThread(http, threadStub.id);
|
|
546
|
+
// A thread deleted between list and index has nothing left to sync.
|
|
547
|
+
// A failure fetching any indexed message must retry the whole thread.
|
|
548
|
+
if (!thread) continue;
|
|
548
549
|
const messages = [...thread.messages].sort((a, b) => Number(a.internalDate) - Number(b.internalDate));
|
|
549
550
|
const firstMessage = messages[0];
|
|
550
551
|
const latestMessage = messages[messages.length - 1];
|
|
@@ -637,7 +638,7 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
|
|
|
637
638
|
case 'download_attachment':
|
|
638
639
|
return await this.downloadAttachment(http, ctx.input);
|
|
639
640
|
default:
|
|
640
|
-
return
|
|
641
|
+
return await executeGoogleAction(GMAIL, ctx, http);
|
|
641
642
|
}
|
|
642
643
|
} catch (error) {
|
|
643
644
|
return {
|
|
@@ -1009,19 +1010,9 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
|
|
|
1009
1010
|
return { success: false, error: 'thread_id is required.' };
|
|
1010
1011
|
}
|
|
1011
1012
|
|
|
1012
|
-
const
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
if (!response.ok) {
|
|
1016
|
-
const errText = await response.text();
|
|
1017
|
-
return { success: false, error: `Gmail thread error (${response.status}): ${errText}` };
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
const thread = (await response.json()) as GmailThreadGetResponse;
|
|
1021
|
-
const subject =
|
|
1022
|
-
thread.messages.length > 0
|
|
1023
|
-
? this.getHeader(thread.messages[0], 'Subject') || '(no subject)'
|
|
1024
|
-
: '(no subject)';
|
|
1013
|
+
const thread = await this.loadThread(http, threadId);
|
|
1014
|
+
if (!thread) return { success: false, error: 'Gmail thread error (404): thread not found' };
|
|
1015
|
+
const subject = this.getHeader(thread.messages[0], 'Subject') || '(no subject)';
|
|
1025
1016
|
|
|
1026
1017
|
const messages = [];
|
|
1027
1018
|
for (const msg of thread.messages) {
|
|
@@ -1055,6 +1046,34 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
|
|
|
1055
1046
|
// Helpers
|
|
1056
1047
|
// -------------------------------------------------------------------------
|
|
1057
1048
|
|
|
1049
|
+
/** Keep each HTTP response bounded by one message, even for long threads. */
|
|
1050
|
+
private async loadThread(http: HttpClient, threadId: string): Promise<GmailThreadGetResponse | null> {
|
|
1051
|
+
const params = new URLSearchParams({ format: 'minimal', fields: 'id,historyId,messages(id)' });
|
|
1052
|
+
const response = await http.raw(`${this.BASE_URL}/threads/${encodeURIComponent(threadId)}?${params}`);
|
|
1053
|
+
if (response.status === 404) return null;
|
|
1054
|
+
if (!response.ok) throw new Error(`Gmail threads.get error (${response.status}): ${await response.text()}`);
|
|
1055
|
+
const index = await response.json() as { id: string; historyId: string; messages?: Array<{ id: string }> };
|
|
1056
|
+
if (index.id !== threadId || !index.messages?.length) throw new Error('Gmail returned a thread without valid identity or messages');
|
|
1057
|
+
const ids = index.messages.map(message => message.id);
|
|
1058
|
+
if (ids.some(id => typeof id !== 'string' || !id) || new Set(ids).size !== ids.length) {
|
|
1059
|
+
throw new Error('Gmail returned malformed message identities');
|
|
1060
|
+
}
|
|
1061
|
+
const messages: GmailMessage[] = [];
|
|
1062
|
+
// Bound provider concurrency without serializing dozens of independent reads.
|
|
1063
|
+
for (let start = 0; start < ids.length; start += 4) {
|
|
1064
|
+
messages.push(...await Promise.all(ids.slice(start, start + 4).map(async id => {
|
|
1065
|
+
const result = await http.raw(`${this.BASE_URL}/messages/${encodeURIComponent(id)}?format=full`);
|
|
1066
|
+
if (!result.ok) throw new Error(`Gmail messages.get error (${result.status}): ${await result.text()}`);
|
|
1067
|
+
const message = await result.json() as GmailMessage;
|
|
1068
|
+
if (message.id !== id || message.threadId !== threadId || !message.payload) {
|
|
1069
|
+
throw new Error('Gmail returned malformed message identity or payload');
|
|
1070
|
+
}
|
|
1071
|
+
return message;
|
|
1072
|
+
})));
|
|
1073
|
+
}
|
|
1074
|
+
return { id: index.id, historyId: index.historyId, messages };
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1058
1077
|
private feedScope(config: GmailConfig): string {
|
|
1059
1078
|
const labels = Array.isArray(config.labels)
|
|
1060
1079
|
? config.labels.filter((label) => typeof label === 'string' && label.trim()).map((label) => label.trim())
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConnectorRuntime,
|
|
3
|
+
type ActionContext,
|
|
4
|
+
type ActionDefinition,
|
|
5
|
+
type ActionResult,
|
|
6
|
+
type RuntimeConnectorDefinition,
|
|
7
|
+
} from '@lobu/connector-sdk';
|
|
8
|
+
|
|
9
|
+
const target = {
|
|
10
|
+
type: 'string',
|
|
11
|
+
minLength: 1,
|
|
12
|
+
maxLength: 128,
|
|
13
|
+
pattern: '^[a-zA-Z0-9][a-zA-Z0-9:_-]*$',
|
|
14
|
+
description:
|
|
15
|
+
'Explicit agent name or pane id returned by Herdr. Never targets the focused pane implicitly.',
|
|
16
|
+
};
|
|
17
|
+
const pane = { ...target, description: 'Explicit pane id returned by Herdr.' };
|
|
18
|
+
const workspace = { ...target, description: 'Explicit workspace id returned by Herdr.' };
|
|
19
|
+
const timeout = { type: 'integer', minimum: 100, maximum: 120000, default: 30000 };
|
|
20
|
+
const until = {
|
|
21
|
+
type: 'array',
|
|
22
|
+
maxItems: 5,
|
|
23
|
+
items: { type: 'string', enum: ['idle', 'working', 'blocked', 'done', 'unknown'] },
|
|
24
|
+
};
|
|
25
|
+
const read = {
|
|
26
|
+
source: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
enum: ['visible', 'recent', 'recent-unwrapped', 'detection'],
|
|
29
|
+
default: 'visible',
|
|
30
|
+
},
|
|
31
|
+
lines: { type: 'integer', minimum: 1, maximum: 500, default: 80 },
|
|
32
|
+
};
|
|
33
|
+
function action(
|
|
34
|
+
key: string,
|
|
35
|
+
name: string,
|
|
36
|
+
description: string,
|
|
37
|
+
kind: 'read' | 'write',
|
|
38
|
+
properties: Record<string, unknown> = {},
|
|
39
|
+
required: string[] = [],
|
|
40
|
+
): ActionDefinition {
|
|
41
|
+
return {
|
|
42
|
+
key,
|
|
43
|
+
name,
|
|
44
|
+
description,
|
|
45
|
+
kind,
|
|
46
|
+
inputSchema: { type: 'object', properties, required, additionalProperties: false },
|
|
47
|
+
annotations: {
|
|
48
|
+
destructiveHint: kind === 'write',
|
|
49
|
+
openWorldHint: kind === 'write',
|
|
50
|
+
idempotentHint: kind === 'read',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Shell only transports argv; all Herdr protocol and command semantics stay here. */
|
|
56
|
+
function quote(value: unknown): string {
|
|
57
|
+
if (typeof value !== 'string' || value.includes('\0'))
|
|
58
|
+
throw new Error('Expected a string without NUL bytes');
|
|
59
|
+
return "'" + value.replaceAll("'", "'\\''") + "'";
|
|
60
|
+
}
|
|
61
|
+
function text(input: Record<string, unknown>, key: string): string {
|
|
62
|
+
const value = input[key];
|
|
63
|
+
if (typeof value !== 'string' || !value.length || value.includes('\0'))
|
|
64
|
+
throw new Error(`${key} is required`);
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
function id(input: Record<string, unknown>, key = 'target'): string {
|
|
68
|
+
const value = text(input, key);
|
|
69
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9:_-]{0,127}$/.test(value))
|
|
70
|
+
throw new Error(`${key} must be an explicit Herdr identifier`);
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
function integer(value: unknown, fallback: number, maximum: number, minimum = 1): number {
|
|
74
|
+
if (value === undefined) return fallback;
|
|
75
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < minimum || value > maximum)
|
|
76
|
+
throw new Error('Invalid numeric limit');
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
function waitOptions(input: Record<string, unknown>): string[] {
|
|
80
|
+
const states = input.until ?? [];
|
|
81
|
+
if (
|
|
82
|
+
!Array.isArray(states) ||
|
|
83
|
+
states.length > 5 ||
|
|
84
|
+
states.some((s) => !['idle', 'working', 'blocked', 'done', 'unknown'].includes(s))
|
|
85
|
+
)
|
|
86
|
+
throw new Error('Invalid wait states');
|
|
87
|
+
return [
|
|
88
|
+
'--timeout',
|
|
89
|
+
String(integer(input.timeout_ms, 30000, 120000)),
|
|
90
|
+
...states.flatMap((s) => ['--until', s]),
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
function readOptions(input: Record<string, unknown>): string[] {
|
|
94
|
+
const source = input.source ?? 'visible';
|
|
95
|
+
if (!['visible', 'recent', 'recent-unwrapped', 'detection'].includes(String(source)))
|
|
96
|
+
throw new Error('Invalid snapshot source');
|
|
97
|
+
return [
|
|
98
|
+
'--source',
|
|
99
|
+
String(source),
|
|
100
|
+
'--lines',
|
|
101
|
+
String(integer(input.lines, 80, 500)),
|
|
102
|
+
'--format',
|
|
103
|
+
'text',
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
function commandFor(
|
|
107
|
+
key: string,
|
|
108
|
+
input: Record<string, unknown>,
|
|
109
|
+
): { argv: string[]; json: boolean; budget: number } {
|
|
110
|
+
let argv: string[];
|
|
111
|
+
let budget = 15000;
|
|
112
|
+
let json = true;
|
|
113
|
+
switch (key) {
|
|
114
|
+
case 'snapshot':
|
|
115
|
+
argv = ['api', 'snapshot'];
|
|
116
|
+
break;
|
|
117
|
+
case 'process_info':
|
|
118
|
+
argv = ['pane', 'process-info', '--pane', id(input, 'pane_id')];
|
|
119
|
+
break;
|
|
120
|
+
case 'pane_read':
|
|
121
|
+
argv = ['pane', 'read', id(input, 'pane_id'), ...readOptions(input)];
|
|
122
|
+
json = false;
|
|
123
|
+
break;
|
|
124
|
+
case 'workspace_create': {
|
|
125
|
+
const cwd = text(input, 'cwd');
|
|
126
|
+
if (!cwd.startsWith('/'))
|
|
127
|
+
throw new Error('cwd must be an absolute path on the selected device');
|
|
128
|
+
argv = ['workspace', 'create', '--cwd', cwd, '--label', text(input, 'label'), '--no-focus'];
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case 'workspace_close':
|
|
132
|
+
argv = ['workspace', 'close', id(input, 'workspace_id')];
|
|
133
|
+
break;
|
|
134
|
+
case 'agent_list':
|
|
135
|
+
argv = ['agent', 'list'];
|
|
136
|
+
break;
|
|
137
|
+
case 'agent_get':
|
|
138
|
+
argv = ['agent', 'get', id(input)];
|
|
139
|
+
break;
|
|
140
|
+
case 'agent_start': {
|
|
141
|
+
const name = text(input, 'name');
|
|
142
|
+
if (!/^[a-z][a-z0-9_-]{0,31}$/.test(name)) throw new Error('Invalid agent name');
|
|
143
|
+
const args = input.args ?? [];
|
|
144
|
+
if (
|
|
145
|
+
!Array.isArray(args) ||
|
|
146
|
+
args.length > 16 ||
|
|
147
|
+
args.some((a) => typeof a !== 'string' || a.length > 512)
|
|
148
|
+
)
|
|
149
|
+
throw new Error('Invalid agent arguments');
|
|
150
|
+
budget = integer(input.timeout_ms, 30000, 120000, 3001) + 5000;
|
|
151
|
+
argv = [
|
|
152
|
+
'agent',
|
|
153
|
+
'start',
|
|
154
|
+
name,
|
|
155
|
+
'--kind',
|
|
156
|
+
id(input, 'kind'),
|
|
157
|
+
'--pane',
|
|
158
|
+
id(input, 'pane_id'),
|
|
159
|
+
'--timeout',
|
|
160
|
+
String(budget - 5000),
|
|
161
|
+
'--',
|
|
162
|
+
...args,
|
|
163
|
+
];
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case 'agent_prompt': {
|
|
167
|
+
if (input.wait !== true && (input.timeout_ms !== undefined || input.until !== undefined))
|
|
168
|
+
throw new Error('timeout_ms and until require wait: true');
|
|
169
|
+
// Herdr takes positionals literally and accepts --timeout/--until only with --wait.
|
|
170
|
+
const wait = input.wait === true;
|
|
171
|
+
if (wait) budget = integer(input.timeout_ms, 30000, 120000) + 5000;
|
|
172
|
+
argv = [
|
|
173
|
+
'agent',
|
|
174
|
+
'prompt',
|
|
175
|
+
id(input),
|
|
176
|
+
text(input, 'text'),
|
|
177
|
+
...(wait ? ['--wait', ...waitOptions(input)] : []),
|
|
178
|
+
];
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
case 'agent_wait':
|
|
182
|
+
budget = integer(input.timeout_ms, 30000, 120000) + 5000;
|
|
183
|
+
argv = ['agent', 'wait', id(input), ...waitOptions(input)];
|
|
184
|
+
break;
|
|
185
|
+
case 'agent_read':
|
|
186
|
+
argv = ['agent', 'read', id(input), ...readOptions(input)];
|
|
187
|
+
json = false;
|
|
188
|
+
break;
|
|
189
|
+
case 'agent_interrupt':
|
|
190
|
+
argv = ['agent', 'send-keys', id(input), 'ctrl+c'];
|
|
191
|
+
break;
|
|
192
|
+
default:
|
|
193
|
+
throw new Error(`Unknown Herdr operation: ${key}`);
|
|
194
|
+
}
|
|
195
|
+
return { argv, json, budget };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export default class HerdrConnector extends ConnectorRuntime {
|
|
199
|
+
readonly definition: RuntimeConnectorDefinition = {
|
|
200
|
+
key: 'herdr',
|
|
201
|
+
name: 'Herdr',
|
|
202
|
+
version: '1.0.0',
|
|
203
|
+
faviconDomain: 'herdr.dev',
|
|
204
|
+
description:
|
|
205
|
+
'Inspect terminal workspaces and create, prompt, monitor or interrupt agents through an existing Shell connection. Requires Herdr 0.9+ installed and running on that device. Select shell_connection_id in connection settings; leave this connector on the server.',
|
|
206
|
+
authSchema: { methods: [{ type: 'none' }] },
|
|
207
|
+
feeds: {},
|
|
208
|
+
optionsSchema: {
|
|
209
|
+
type: 'object',
|
|
210
|
+
required: ['shell_connection_id'],
|
|
211
|
+
properties: {
|
|
212
|
+
shell_connection_id: {
|
|
213
|
+
type: 'integer',
|
|
214
|
+
minimum: 1,
|
|
215
|
+
title: 'Shell connection ID',
|
|
216
|
+
description:
|
|
217
|
+
'Discover the existing os.shell connection with operations.listAvailable. Its device and policies govern all commands.',
|
|
218
|
+
},
|
|
219
|
+
binary: {
|
|
220
|
+
type: 'string',
|
|
221
|
+
minLength: 1,
|
|
222
|
+
title: 'Herdr executable',
|
|
223
|
+
default: 'herdr',
|
|
224
|
+
description: 'Executable name or absolute path on the selected device.',
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
additionalProperties: false,
|
|
228
|
+
},
|
|
229
|
+
actions: {
|
|
230
|
+
snapshot: action(
|
|
231
|
+
'snapshot',
|
|
232
|
+
'Workspace snapshot',
|
|
233
|
+
'Structured workspaces, panes and agents from the running Herdr instance.',
|
|
234
|
+
'read',
|
|
235
|
+
),
|
|
236
|
+
process_info: action(
|
|
237
|
+
'process_info',
|
|
238
|
+
'Pane process',
|
|
239
|
+
'Inspect the foreground process in an explicit pane.',
|
|
240
|
+
'read',
|
|
241
|
+
{ pane_id: pane },
|
|
242
|
+
['pane_id'],
|
|
243
|
+
),
|
|
244
|
+
pane_read: action(
|
|
245
|
+
'pane_read',
|
|
246
|
+
'Read pane',
|
|
247
|
+
'Read bounded terminal output. Visible is passive; recent history may temporarily scroll idle terminals.',
|
|
248
|
+
'read',
|
|
249
|
+
{ pane_id: pane, ...read },
|
|
250
|
+
['pane_id'],
|
|
251
|
+
),
|
|
252
|
+
workspace_create: action(
|
|
253
|
+
'workspace_create',
|
|
254
|
+
'Create workspace',
|
|
255
|
+
'Create an unfocused workspace and return its root pane. Start an agent in that pane with agent_start.',
|
|
256
|
+
'write',
|
|
257
|
+
{
|
|
258
|
+
cwd: { type: 'string', pattern: '^/' },
|
|
259
|
+
label: { type: 'string', minLength: 1, maxLength: 100 },
|
|
260
|
+
},
|
|
261
|
+
['cwd', 'label'],
|
|
262
|
+
),
|
|
263
|
+
workspace_close: action(
|
|
264
|
+
'workspace_close',
|
|
265
|
+
'Close workspace',
|
|
266
|
+
'Close the specified workspace and its running processes. Use only for a workspace you intend to tear down.',
|
|
267
|
+
'write',
|
|
268
|
+
{ workspace_id: workspace },
|
|
269
|
+
['workspace_id'],
|
|
270
|
+
),
|
|
271
|
+
agent_list: action(
|
|
272
|
+
'agent_list',
|
|
273
|
+
'List agents',
|
|
274
|
+
'List registered agents and their state.',
|
|
275
|
+
'read',
|
|
276
|
+
),
|
|
277
|
+
agent_get: action(
|
|
278
|
+
'agent_get',
|
|
279
|
+
'Agent status',
|
|
280
|
+
'Inspect one agent by its returned name or pane id.',
|
|
281
|
+
'read',
|
|
282
|
+
{ target },
|
|
283
|
+
['target'],
|
|
284
|
+
),
|
|
285
|
+
agent_start: action(
|
|
286
|
+
'agent_start',
|
|
287
|
+
'Start agent',
|
|
288
|
+
'Start an installed interactive agent in an existing idle shell pane. Returns when that agent is detected and ready.',
|
|
289
|
+
'write',
|
|
290
|
+
{
|
|
291
|
+
name: { type: 'string', pattern: '^[a-z][a-z0-9_-]{0,31}$' },
|
|
292
|
+
kind: { ...target, description: 'Installed Herdr agent kind to start.' },
|
|
293
|
+
pane_id: pane,
|
|
294
|
+
timeout_ms: { ...timeout, minimum: 3001 },
|
|
295
|
+
args: { type: 'array', maxItems: 16, items: { type: 'string', maxLength: 512 } },
|
|
296
|
+
},
|
|
297
|
+
['name', 'kind', 'pane_id'],
|
|
298
|
+
),
|
|
299
|
+
agent_prompt: action(
|
|
300
|
+
'agent_prompt',
|
|
301
|
+
'Prompt agent',
|
|
302
|
+
'Submit a prompt or follow-up. timeout_ms and until require wait: true. Start from idle for reliable wait semantics: Herdr tracks terminal states, not turns. After timeout/stall, inspect before retrying; input may already have been delivered.',
|
|
303
|
+
'write',
|
|
304
|
+
{
|
|
305
|
+
target,
|
|
306
|
+
text: { type: 'string', minLength: 1, maxLength: 10000 },
|
|
307
|
+
wait: { type: 'boolean', default: false },
|
|
308
|
+
timeout_ms: timeout,
|
|
309
|
+
until,
|
|
310
|
+
},
|
|
311
|
+
['target', 'text'],
|
|
312
|
+
),
|
|
313
|
+
agent_wait: action(
|
|
314
|
+
'agent_wait',
|
|
315
|
+
'Wait for agent',
|
|
316
|
+
'Bounded state wait; already matching states return immediately. Cancelling this wait does not interrupt the persistent agent.',
|
|
317
|
+
'read',
|
|
318
|
+
{ target, timeout_ms: timeout, until },
|
|
319
|
+
['target'],
|
|
320
|
+
),
|
|
321
|
+
agent_read: action(
|
|
322
|
+
'agent_read',
|
|
323
|
+
'Read agent',
|
|
324
|
+
'Read bounded terminal output to verify the actual result of a turn.',
|
|
325
|
+
'read',
|
|
326
|
+
{ target, ...read },
|
|
327
|
+
['target'],
|
|
328
|
+
),
|
|
329
|
+
agent_interrupt: action(
|
|
330
|
+
'agent_interrupt',
|
|
331
|
+
'Interrupt agent',
|
|
332
|
+
'Send Ctrl+C to the explicitly selected agent. Inspect its state afterward.',
|
|
333
|
+
'write',
|
|
334
|
+
{ target },
|
|
335
|
+
['target'],
|
|
336
|
+
),
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
async execute(ctx: ActionContext): Promise<ActionResult> {
|
|
341
|
+
if (!ctx.operations)
|
|
342
|
+
return {
|
|
343
|
+
success: false,
|
|
344
|
+
error:
|
|
345
|
+
'This Lobu host does not support connector operation delegation. Update the Lobu server.',
|
|
346
|
+
};
|
|
347
|
+
const connectionId = ctx.config.shell_connection_id;
|
|
348
|
+
if (typeof connectionId !== 'number' || !Number.isSafeInteger(connectionId) || connectionId < 1)
|
|
349
|
+
return {
|
|
350
|
+
success: false,
|
|
351
|
+
error: 'Configure shell_connection_id with an existing os.shell connection.',
|
|
352
|
+
};
|
|
353
|
+
const command = commandFor(ctx.actionKey, ctx.input);
|
|
354
|
+
const binary = ctx.config.binary ?? 'herdr';
|
|
355
|
+
const receipt = await ctx.operations.execute({
|
|
356
|
+
connection_id: connectionId,
|
|
357
|
+
operation_key: 'run',
|
|
358
|
+
idempotency_key: 'herdr-command',
|
|
359
|
+
input: {
|
|
360
|
+
command: [binary, ...command.argv].map(quote).join(' '),
|
|
361
|
+
timeout_ms: command.budget,
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
if ('error' in receipt) return { success: false, error: receipt.error };
|
|
365
|
+
if (receipt.status === 'pending_approval' || receipt.status === 'in_progress')
|
|
366
|
+
return { success: true, output: { ...receipt } };
|
|
367
|
+
if (receipt.status !== 'completed') return { success: false, error: JSON.stringify(receipt) };
|
|
368
|
+
const shell = receipt.output as {
|
|
369
|
+
exit_code?: number;
|
|
370
|
+
timed_out?: boolean;
|
|
371
|
+
stdout?: string;
|
|
372
|
+
stderr?: string;
|
|
373
|
+
};
|
|
374
|
+
let result: unknown = shell?.stdout ?? '';
|
|
375
|
+
if (command.json && typeof result === 'string' && shell?.exit_code === 0 && !shell?.timed_out) {
|
|
376
|
+
try {
|
|
377
|
+
result = JSON.parse(result);
|
|
378
|
+
} catch {
|
|
379
|
+
return {
|
|
380
|
+
success: false,
|
|
381
|
+
error: `Herdr returned invalid JSON (shell run ${receipt.run_id}); inspect that run before retrying.`,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (
|
|
386
|
+
!shell ||
|
|
387
|
+
shell.exit_code !== 0 ||
|
|
388
|
+
shell.timed_out ||
|
|
389
|
+
(typeof result === 'object' && result !== null && 'error' in result)
|
|
390
|
+
) {
|
|
391
|
+
return {
|
|
392
|
+
success: false,
|
|
393
|
+
error: JSON.stringify({
|
|
394
|
+
run_id: receipt.run_id,
|
|
395
|
+
exit_code: shell?.exit_code,
|
|
396
|
+
timed_out: shell?.timed_out,
|
|
397
|
+
result,
|
|
398
|
+
stderr: shell?.stderr?.slice(-2000),
|
|
399
|
+
message:
|
|
400
|
+
'Inspect this run before retrying. A command or prompt may already have been delivered.',
|
|
401
|
+
}),
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
return { success: true, output: { status: 'completed', run_id: receipt.run_id, result } };
|
|
405
|
+
}
|
|
406
|
+
}
|