@lobu/runtime-device 22.0.0 → 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.
Files changed (77) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +3 -3
  3. package/npm-shrinkwrap.json +15 -15
  4. package/package.json +1 -1
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +1 -1
  6. package/vendor/cli/dist/connectors/README.md +14 -1
  7. package/vendor/cli/dist/connectors/google_gmail.ts +1 -0
  8. package/vendor/cli/dist/connectors/jira-helpers.ts +313 -0
  9. package/vendor/cli/dist/connectors/jira.ts +29 -221
  10. package/vendor/cli/dist/connectors/linkedin-browser-script.ts +13 -0
  11. package/vendor/cli/dist/connectors/linkedin-draft-page.js +104 -0
  12. package/vendor/cli/dist/connectors/linkedin-drafts.ts +73 -0
  13. package/vendor/cli/dist/connectors/linkedin-identity.ts +32 -0
  14. package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +1185 -0
  15. package/vendor/cli/dist/connectors/linkedin-inbox.ts +156 -0
  16. package/vendor/cli/dist/connectors/linkedin-like.ts +114 -0
  17. package/vendor/cli/dist/connectors/linkedin-takeout.ts +577 -0
  18. package/vendor/cli/dist/connectors/linkedin.ts +3998 -0
  19. package/vendor/cli/dist/connectors/takeout-utils.ts +240 -0
  20. package/vendor/cli/dist/connectors/tiktok-inbox-page.js +9 -9
  21. package/vendor/cli/dist/connectors/tiktok-web-page.js +21 -15
  22. package/vendor/cli/dist/connectors/tiktok_web.ts +63 -30
  23. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +64 -564
  24. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +30 -444
  25. package/vendor/cli/dist/connectors/whatsapp-web-identity.ts +20 -6
  26. package/vendor/cli/dist/connectors/whatsapp_web.ts +45 -645
  27. package/vendor/cli/dist/connectors/x-dm-adapter.js +556 -0
  28. package/vendor/cli/dist/connectors/x-identity.ts +31 -2
  29. package/vendor/cli/dist/connectors/x.ts +266 -120
  30. package/vendor/cli/dist/runtime-components.json +4 -4
  31. package/vendor/cli/dist/templates/AGENTS.md.tmpl +2 -2
  32. package/vendor/cli/package.json +1 -1
  33. package/vendor/connector-sdk/dist/browser-handoff-banner.d.ts +39 -0
  34. package/vendor/connector-sdk/dist/browser-handoff-banner.js +175 -0
  35. package/vendor/connector-sdk/dist/browser-source-read.d.ts +52 -0
  36. package/vendor/connector-sdk/dist/browser-source-read.js +107 -0
  37. package/vendor/connector-sdk/dist/connector-types.d.ts +10 -0
  38. package/vendor/connector-sdk/dist/index.d.ts +3 -0
  39. package/vendor/connector-sdk/dist/index.js +2 -0
  40. package/vendor/connector-sdk/package.json +9 -1
  41. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +15 -6
  42. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +288 -148
  43. package/vendor/connector-worker/dist/daemon/automation.d.ts +4 -11
  44. package/vendor/connector-worker/dist/daemon/automation.js +6 -6
  45. package/vendor/connector-worker/dist/daemon/client.d.ts +2 -4
  46. package/vendor/connector-worker/dist/daemon/client.js +0 -3
  47. package/vendor/connector-worker/dist/daemon/executor.js +0 -3
  48. package/vendor/connector-worker/dist/daemon/mac-device-daemon.d.ts +4 -3
  49. package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +4 -10
  50. package/vendor/connector-worker/dist/daemon/native-bridge/executor.js +27 -25
  51. package/vendor/connector-worker/dist/daemon/start.js +3 -15
  52. package/vendor/connector-worker/dist/daemon/terminal-failure.js +0 -11
  53. package/vendor/connector-worker/dist/daemon/worker-id.d.ts +17 -0
  54. package/vendor/connector-worker/dist/daemon/worker-id.js +22 -0
  55. package/vendor/connector-worker/dist/mac-device-daemon.js +14 -26
  56. package/vendor/connector-worker/package.json +1 -1
  57. package/vendor/core/dist/capabilities.d.ts +1 -1
  58. package/vendor/core/dist/capabilities.js +0 -1
  59. package/vendor/core/dist/connector-query-errors.d.ts +32 -0
  60. package/vendor/core/dist/connector-query-errors.js +41 -1
  61. package/vendor/core/dist/contracts/tools/manage-conversations.js +2 -2
  62. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +14 -0
  63. package/vendor/core/dist/contracts/tools/manage-feeds.js +17 -0
  64. package/vendor/core/dist/contracts/worker/protocol.d.ts +8 -131
  65. package/vendor/core/dist/contracts/worker/protocol.js +9 -61
  66. package/vendor/core/dist/device-pin-tombstones.d.ts +44 -0
  67. package/vendor/core/dist/device-pin-tombstones.js +57 -0
  68. package/vendor/core/dist/index.d.ts +2 -1
  69. package/vendor/core/dist/index.js +1 -0
  70. package/vendor/core/dist/logger.js +10 -25
  71. package/vendor/core/dist/utils/diagnostic-scrubber.js +258 -21
  72. package/vendor/core/dist/worker/wire.d.ts +0 -10
  73. package/vendor/core/package.json +6 -6
  74. package/vendor/connector-worker/dist/daemon/device-chat.d.ts +0 -9
  75. package/vendor/connector-worker/dist/daemon/device-chat.js +0 -61
  76. package/vendor/core/dist/contracts/worker/device-chat.d.ts +0 -4
  77. package/vendor/core/dist/contracts/worker/device-chat.js +0 -26
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Shared in-page handoff banner for browser-staged drafts.
3
+ *
4
+ * Two connectors stage text in the user's own signed-in page and stop before
5
+ * submit (`x.prepare_reply`, `linkedin.prepare_comment`). Without a banner the
6
+ * staged page is context-free — a draft in a box with no record of why the
7
+ * agent thought the post mattered. Both banners are the same DOM shape (a
8
+ * fixed `#lobu-handoff-banner` status node, anchored above the composer when
9
+ * one is found, dismissible, never auto-submitted); only the title,
10
+ * instruction line, optional footer, and composer/host selectors differ per
11
+ * site. Callers pass those; this module owns the injection script.
12
+ *
13
+ * Pure (no `node:`, no `@lobu/core`): the root must stay loadable inside a V8
14
+ * isolate.
15
+ */
16
+ export function truncateHandoffReason(reason, maxLen = 120) {
17
+ if (reason == null)
18
+ return undefined;
19
+ const t = reason.replace(/\s+/g, " ").trim();
20
+ if (!t)
21
+ return undefined;
22
+ if (t.length <= maxLen)
23
+ return t;
24
+ return `${t.slice(0, Math.max(0, maxLen - 1)).trimEnd()}…`;
25
+ }
26
+ /**
27
+ * JS expression: inject the Lobu handoff banner on the page.
28
+ *
29
+ * Best-effort; the host page re-renders aggressively and may drop the node.
30
+ * Never fatal — the draft is already staged by the time this runs. No
31
+ * auto-dismiss: the draft lives in the user's page, so its context should
32
+ * still be present when the user returns later.
33
+ */
34
+ export function buildInjectHandoffBannerExpression(opts) {
35
+ const reason = truncateHandoffReason(opts.reason);
36
+ const title = opts.title ?? "Lobu staged this draft";
37
+ const instruction = opts.instruction ?? "Review the draft yourself — Lobu did not submit.";
38
+ const titleLit = JSON.stringify(title);
39
+ const instructionLit = JSON.stringify(instruction);
40
+ const reasonLit = JSON.stringify(reason ?? null);
41
+ const footerLit = JSON.stringify(opts.footer ?? null);
42
+ const composerSelectorsLit = JSON.stringify(opts.composerSelectors ?? ['div[role="textbox"][contenteditable="true"]']);
43
+ const hostSelectorsLit = JSON.stringify(opts.hostSelectors ?? ["form"]);
44
+ return `(async()=>{
45
+ const TITLE = ${titleLit};
46
+ const INSTRUCTION = ${instructionLit};
47
+ const REASON = ${reasonLit};
48
+ const FOOTER = ${footerLit};
49
+ const COMPOSER_SELECTORS = ${composerSelectorsLit};
50
+ const HOST_SELECTORS = ${hostSelectorsLit};
51
+ const ID = 'lobu-handoff-banner';
52
+ try {
53
+ const prev = document.getElementById(ID);
54
+ if (prev) prev.remove();
55
+ } catch (_) {}
56
+
57
+ const root = document.createElement('div');
58
+ root.id = ID;
59
+ root.setAttribute('role', 'status');
60
+ root.setAttribute('data-lobu', 'handoff-banner');
61
+ root.style.cssText = [
62
+ 'position:fixed',
63
+ 'top:12px',
64
+ 'left:50%',
65
+ 'transform:translateX(-50%)',
66
+ 'z-index:2147483646',
67
+ 'max-width:min(520px,calc(100vw - 24px))',
68
+ 'font:13px/1.4 -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif',
69
+ 'color:#0f172a',
70
+ 'background:#fff',
71
+ 'border:1px solid #cbd5e1',
72
+ 'border-left:4px solid #0ea5e9',
73
+ 'border-radius:10px',
74
+ 'box-shadow:0 8px 28px rgba(15,23,42,.18)',
75
+ 'padding:10px 12px',
76
+ 'display:flex',
77
+ 'gap:10px',
78
+ 'align-items:flex-start',
79
+ 'pointer-events:auto',
80
+ ].join(';');
81
+
82
+ const body = document.createElement('div');
83
+ body.style.cssText = 'flex:1;min-width:0';
84
+
85
+ const head = document.createElement('div');
86
+ head.style.cssText = 'font-weight:600;margin:0 0 2px;color:#0c4a6e';
87
+ head.textContent = TITLE;
88
+
89
+ const line = document.createElement('div');
90
+ line.style.cssText = 'color:#334155;margin:0 0 2px';
91
+ line.textContent = INSTRUCTION;
92
+
93
+ body.appendChild(head);
94
+ body.appendChild(line);
95
+
96
+ if (REASON) {
97
+ const why = document.createElement('div');
98
+ why.style.cssText = 'color:#64748b;margin:4px 0 0;font-size:12px';
99
+ why.textContent = 'Why: ' + REASON;
100
+ body.appendChild(why);
101
+ }
102
+
103
+ if (FOOTER) {
104
+ const foot = document.createElement('div');
105
+ foot.style.cssText = 'color:#64748b;margin:4px 0 0;font-size:12px';
106
+ foot.textContent = FOOTER;
107
+ body.appendChild(foot);
108
+ }
109
+
110
+ const close = document.createElement('button');
111
+ close.type = 'button';
112
+ close.setAttribute('aria-label', 'Dismiss');
113
+ close.textContent = '\\u00d7';
114
+ close.style.cssText = [
115
+ 'flex:none',
116
+ 'border:0',
117
+ 'background:transparent',
118
+ 'color:#64748b',
119
+ 'font:20px/1 sans-serif',
120
+ 'cursor:pointer',
121
+ 'padding:0 2px',
122
+ ].join(';');
123
+ close.onclick = function () { try { root.remove(); } catch (_) {} };
124
+
125
+ root.appendChild(body);
126
+ root.appendChild(close);
127
+
128
+ // Anchor above the composer when we can find it, so the reason sits
129
+ // next to the draft instead of floating over unrelated content.
130
+ let anchored = false;
131
+ try {
132
+ let composer = null;
133
+ for (const selector of COMPOSER_SELECTORS) {
134
+ try {
135
+ composer = document.querySelector(selector);
136
+ } catch (_) {
137
+ composer = null;
138
+ }
139
+ if (composer) break;
140
+ }
141
+ if (composer) {
142
+ let host = null;
143
+ for (const selector of HOST_SELECTORS) {
144
+ try {
145
+ host = composer.closest(selector);
146
+ } catch (_) {
147
+ host = null;
148
+ }
149
+ if (host) break;
150
+ }
151
+ host = host || composer.parentElement;
152
+ if (host && host.parentElement) {
153
+ root.style.position = 'relative';
154
+ root.style.top = '0';
155
+ root.style.left = '0';
156
+ root.style.transform = 'none';
157
+ root.style.margin = '8px 0 12px';
158
+ root.style.maxWidth = '100%';
159
+ host.parentElement.insertBefore(root, host);
160
+ anchored = true;
161
+ }
162
+ }
163
+ } catch (_) {}
164
+
165
+ if (!anchored) {
166
+ (document.body || document.documentElement).appendChild(root);
167
+ }
168
+
169
+ // No auto-dismiss: the draft lives in the user's page, so its context should
170
+ // still be present when the user returns later. The dismiss button remains.
171
+
172
+ return { ok: true, anchored: anchored, has_reason: !!REASON };
173
+ })()`;
174
+ }
175
+ //# sourceMappingURL=browser-handoff-banner.js.map
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Shared guards and reference-batch splitting for browser-source reads.
3
+ *
4
+ * Browser connectors observe references only (WhatsApp, TikTok inbox,
5
+ * LinkedIn inbox) or take bounded snapshots (TikTok timeline/search): the
6
+ * source owns order and pagination, so offsets, sorts, time windows, and
7
+ * exact-match filters are rejected before touching the page. Each durable
8
+ * browser record is limited to 128 KiB including its checkpoint, so reference
9
+ * batches are capped at 500 events and halved until they fit; only the final
10
+ * batch carries the checkpoint, so an interruption replays instead of
11
+ * skipping.
12
+ *
13
+ * Pure (no `node:`, no `@lobu/core`): the root must stay loadable inside a V8
14
+ * isolate.
15
+ */
16
+ import type { FeedReadContext } from "./connector-types.js";
17
+ /** Max references per durable browser record. */
18
+ export declare const SOURCE_REFERENCE_BATCH_MAX_EVENTS = 500;
19
+ /** Max serialized bytes per durable browser record, checkpoint included. */
20
+ export declare const SOURCE_RECORD_MAX_BYTES: number;
21
+ export declare function jsonByteLength(value: unknown): number;
22
+ /**
23
+ * Split references into ordered batches of at most `maxEvents` references and
24
+ * `maxBytes` serialized bytes. `buildBatch` shapes each record (id,
25
+ * checkpoint on the final batch, `more`); it receives the slice, whether it
26
+ * is the last batch, and the running offset. Throws when a single reference
27
+ * cannot fit even alone.
28
+ */
29
+ export declare function splitReferenceBatches<E>(events: E[], buildBatch: (slice: E[], isLast: boolean, offset: number) => Record<string, unknown>, opts?: {
30
+ maxEvents?: number;
31
+ maxBytes?: number;
32
+ }): Record<string, unknown>[];
33
+ type ReadShape = Pick<FeedReadContext, "offset" | "sort" | "window" | "match" | "query" | "cursor" | "limit">;
34
+ export declare function assertNoOffsetPaging(ctx: Pick<ReadShape, "offset">, message: string): void;
35
+ export declare function assertNoSort(ctx: Pick<ReadShape, "sort">, message: string): void;
36
+ export declare function assertNoWindow(ctx: Pick<ReadShape, "window">, message: string): void;
37
+ export declare function assertNoMatch(ctx: Pick<ReadShape, "match">, message: string): void;
38
+ export declare function assertNoQuery(ctx: Pick<ReadShape, "query">, message: string): void;
39
+ export declare function assertNoCursor(ctx: Pick<ReadShape, "cursor">, message: string): void;
40
+ export declare function assertPositiveReadLimit(ctx: Pick<ReadShape, "limit">, message?: string): void;
41
+ /**
42
+ * Inbox reads follow source order and the returned cursor; search, offsets,
43
+ * sorting, matching, and time windows are unsupported.
44
+ */
45
+ export declare function assertInboxSourceRead(ctx: ReadShape, sourceLabel: string): void;
46
+ /**
47
+ * Bounded snapshot reads support no pagination, sorting, time windows, or
48
+ * exact-match filters.
49
+ */
50
+ export declare function assertSnapshotSourceRead(ctx: ReadShape, sourceLabel: string): void;
51
+ export {};
52
+ //# sourceMappingURL=browser-source-read.d.ts.map
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Shared guards and reference-batch splitting for browser-source reads.
3
+ *
4
+ * Browser connectors observe references only (WhatsApp, TikTok inbox,
5
+ * LinkedIn inbox) or take bounded snapshots (TikTok timeline/search): the
6
+ * source owns order and pagination, so offsets, sorts, time windows, and
7
+ * exact-match filters are rejected before touching the page. Each durable
8
+ * browser record is limited to 128 KiB including its checkpoint, so reference
9
+ * batches are capped at 500 events and halved until they fit; only the final
10
+ * batch carries the checkpoint, so an interruption replays instead of
11
+ * skipping.
12
+ *
13
+ * Pure (no `node:`, no `@lobu/core`): the root must stay loadable inside a V8
14
+ * isolate.
15
+ */
16
+ /** Max references per durable browser record. */
17
+ export const SOURCE_REFERENCE_BATCH_MAX_EVENTS = 500;
18
+ /** Max serialized bytes per durable browser record, checkpoint included. */
19
+ export const SOURCE_RECORD_MAX_BYTES = 128 * 1024;
20
+ export function jsonByteLength(value) {
21
+ return new TextEncoder().encode(JSON.stringify(value)).length;
22
+ }
23
+ /**
24
+ * Split references into ordered batches of at most `maxEvents` references and
25
+ * `maxBytes` serialized bytes. `buildBatch` shapes each record (id,
26
+ * checkpoint on the final batch, `more`); it receives the slice, whether it
27
+ * is the last batch, and the running offset. Throws when a single reference
28
+ * cannot fit even alone.
29
+ */
30
+ export function splitReferenceBatches(events, buildBatch, opts) {
31
+ const maxEvents = opts?.maxEvents ?? SOURCE_REFERENCE_BATCH_MAX_EVENTS;
32
+ const maxBytes = opts?.maxBytes ?? SOURCE_RECORD_MAX_BYTES;
33
+ const batches = [];
34
+ for (let offset = 0;;) {
35
+ const through = (end) => buildBatch(events.slice(offset, end), end === events.length, offset);
36
+ let end = Math.min(offset + maxEvents, events.length);
37
+ let batch = through(end);
38
+ while (jsonByteLength(batch) > maxBytes && end - offset > 1) {
39
+ end = offset + Math.floor((end - offset) / 2);
40
+ batch = through(end);
41
+ }
42
+ if (jsonByteLength(batch) > maxBytes) {
43
+ throw new Error("Source reference or checkpoint exceeds the browser record limit");
44
+ }
45
+ batches.push(batch);
46
+ if (end === events.length)
47
+ return batches;
48
+ offset = end;
49
+ }
50
+ }
51
+ export function assertNoOffsetPaging(ctx, message) {
52
+ if (ctx.offset)
53
+ throw new Error(message);
54
+ }
55
+ export function assertNoSort(ctx, message) {
56
+ if (ctx.sort)
57
+ throw new Error(message);
58
+ }
59
+ export function assertNoWindow(ctx, message) {
60
+ if (ctx.window)
61
+ throw new Error(message);
62
+ }
63
+ export function assertNoMatch(ctx, message) {
64
+ if (ctx.match)
65
+ throw new Error(message);
66
+ }
67
+ export function assertNoQuery(ctx, message) {
68
+ if (ctx.query)
69
+ throw new Error(message);
70
+ }
71
+ export function assertNoCursor(ctx, message) {
72
+ if (ctx.cursor)
73
+ throw new Error(message);
74
+ }
75
+ export function assertPositiveReadLimit(ctx, message = "limit must be a positive integer") {
76
+ if (ctx.limit !== undefined &&
77
+ (!Number.isInteger(ctx.limit) || ctx.limit < 1)) {
78
+ throw new Error(message);
79
+ }
80
+ }
81
+ /**
82
+ * Inbox reads follow source order and the returned cursor; search, offsets,
83
+ * sorting, matching, and time windows are unsupported.
84
+ */
85
+ export function assertInboxSourceRead(ctx, sourceLabel) {
86
+ const message = `${sourceLabel} inbox reads use source order and the returned cursor; ` +
87
+ `search, offsets, sorting, matching, and time windows are unsupported`;
88
+ assertNoOffsetPaging(ctx, message);
89
+ assertNoSort(ctx, message);
90
+ assertNoWindow(ctx, message);
91
+ assertNoMatch(ctx, message);
92
+ assertNoQuery(ctx, message);
93
+ }
94
+ /**
95
+ * Bounded snapshot reads support no pagination, sorting, time windows, or
96
+ * exact-match filters.
97
+ */
98
+ export function assertSnapshotSourceRead(ctx, sourceLabel) {
99
+ const message = `${sourceLabel} snapshot feeds do not support pagination, sorting, ` +
100
+ `time windows, or exact-match filters`;
101
+ assertNoCursor(ctx, message);
102
+ assertNoOffsetPaging(ctx, message);
103
+ assertNoSort(ctx, message);
104
+ assertNoWindow(ctx, message);
105
+ assertNoMatch(ctx, message);
106
+ }
107
+ //# sourceMappingURL=browser-source-read.js.map
@@ -569,6 +569,16 @@ export interface FeedDefinition {
569
569
  eventKinds?: Record<string, {
570
570
  description?: string;
571
571
  metadataSchema?: Record<string, unknown>;
572
+ /**
573
+ * Opt in to a separate `<kind>.updated` Automation trigger when a sync
574
+ * supersedes this source item with changed durable content and strictly
575
+ * newer `occurred_at` activity. The original kind remains insert-only.
576
+ * Unchanged rows, volatile-only updates and cold-start backfills stay
577
+ * quiet. Use activity time for `occurred_at`, not a scheduled start time.
578
+ * A declared literal kind wins a collision; composite keys over 100
579
+ * characters are not derived. Persisted unchanged in feeds_schema.
580
+ */
581
+ updatedEvent?: boolean;
572
582
  /**
573
583
  * Generic event attribution declarations. New connector work should model
574
584
  * "who authored / what resource this event belongs to / what it is about"
@@ -34,6 +34,9 @@ export { calculateEngagementScore } from './scoring.js';
34
34
  export { ConnectorAutomationEventSchema, ConnectorAutomationSignalDraftSchema, SubscriptionCandidateSchema, } from './automation-triggers.js';
35
35
  export type { AutomationEventTrigger, AutomationScheduleTrigger, AutomationTrigger, AutomationWorkspaceEventTrigger, ConnectorAutomationEvent, ConnectorAutomationSignalDraft, ConnectorTriggerSignal, SubscriptionCandidate, } from './automation-triggers.js';
36
36
  export { applyLookbackCutoff } from './checkpoint/lookback.js';
37
+ export { buildInjectHandoffBannerExpression, truncateHandoffReason, } from './browser-handoff-banner.js';
38
+ export type { HandoffBannerOptions } from './browser-handoff-banner.js';
39
+ export { assertInboxSourceRead, assertNoCursor, assertNoMatch, assertNoOffsetPaging, assertNoQuery, assertNoSort, assertNoWindow, assertPositiveReadLimit, assertSnapshotSourceRead, jsonByteLength, SOURCE_RECORD_MAX_BYTES, SOURCE_REFERENCE_BATCH_MAX_EVENTS, splitReferenceBatches, } from './browser-source-read.js';
37
40
  export { buildTimestampCheckpoint, filterByCheckpoint, finalizeTimestampSync, } from './checkpoint/timestamp-watermark.js';
38
41
  export { validatePublicUrl, validateUrlDomain } from './url-guards.js';
39
42
  export { sleep } from './sleep.js';
@@ -33,6 +33,8 @@ export { ConnectorAutomationEventSchema, ConnectorAutomationSignalDraftSchema, S
33
33
  // The root must stay loadable inside a V8 isolate.
34
34
  // =============================================================================
35
35
  export { applyLookbackCutoff } from './checkpoint/lookback.js';
36
+ export { buildInjectHandoffBannerExpression, truncateHandoffReason, } from './browser-handoff-banner.js';
37
+ export { assertInboxSourceRead, assertNoCursor, assertNoMatch, assertNoOffsetPaging, assertNoQuery, assertNoSort, assertNoWindow, assertPositiveReadLimit, assertSnapshotSourceRead, jsonByteLength, SOURCE_RECORD_MAX_BYTES, SOURCE_REFERENCE_BATCH_MAX_EVENTS, splitReferenceBatches, } from './browser-source-read.js';
36
38
  export { buildTimestampCheckpoint, filterByCheckpoint, finalizeTimestampSync, } from './checkpoint/timestamp-watermark.js';
37
39
  export { validatePublicUrl, validateUrlDomain } from './url-guards.js';
38
40
  export { sleep } from './sleep.js';
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobu/connector-sdk",
3
- "version": "22.0.0",
3
+ "version": "23.0.0",
4
4
  "description": "Lobu memory SDK — build pluggable connectors for Lobu memory",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -20,6 +20,14 @@
20
20
  "types": "./dist/browser-requirement.d.ts",
21
21
  "import": "./dist/browser-requirement.js"
22
22
  },
23
+ "./browser-handoff-banner": {
24
+ "types": "./dist/browser-handoff-banner.d.ts",
25
+ "import": "./dist/browser-handoff-banner.js"
26
+ },
27
+ "./browser-source-read": {
28
+ "types": "./dist/browser-source-read.d.ts",
29
+ "import": "./dist/browser-source-read.js"
30
+ },
23
31
  "./define-connector": {
24
32
  "import": {
25
33
  "types": "./dist/define-connector.d.ts",
@@ -18,6 +18,7 @@
18
18
  * swaps it into the outbound header, the secret proxy accepts it as the
19
19
  * provider credential and the MCP route accepts it as the bearer.
20
20
  */
21
+ import { mcpToolResult, toolImageBudget } from '@lobu/plugin-toolkit';
21
22
  import { createGatewayTools } from './gateway-tools.js';
22
23
  import { createTurnMediaTools } from './media-tools.js';
23
24
  import { createTurnMemoryHooks } from './memory.js';
@@ -52,7 +53,7 @@ function joinText(content) {
52
53
  * result, so a blocked or approval-gated call reaches the model as text and the
53
54
  * turn goes on.
54
55
  */
55
- async function callMcpTool(gatewayUrl, credential, tool, args, timeoutMs = TOOL_CALL_TIMEOUT_MS) {
56
+ async function callMcpTool(gatewayUrl, credential, tool, args, timeoutMs = TOOL_CALL_TIMEOUT_MS, supportsImages = true, imageBudget) {
56
57
  const url = `${gatewayUrl}/mcp/${encodeURIComponent(tool.mcpId)}/tools/${encodeURIComponent(tool.name)}`;
57
58
  let response;
58
59
  try {
@@ -91,7 +92,7 @@ async function callMcpTool(gatewayUrl, credential, tool, args, timeoutMs = TOOL_
91
92
  // Ordinary agent tools render this same result below; no second transport.
92
93
  return {
93
94
  ...reply,
94
- content: [{ type: 'text', text: text || reply.error || '' }],
95
+ ...mcpToolResult(reply.isError === true ? reply.content?.filter(part => part?.type === 'text') : reply.content, reply.error || '', supportsImages, imageBudget),
95
96
  };
96
97
  }
97
98
  /**
@@ -102,9 +103,10 @@ async function callMcpTool(gatewayUrl, credential, tool, args, timeoutMs = TOOL_
102
103
  * `createGatewayTools`.
103
104
  */
104
105
  function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered, emit, runtimeExec) {
106
+ const imageBudget = toolImageBudget((input.images ?? []).map(image => ({ type: 'image', data: image.data })));
105
107
  const tools = input.tools;
106
108
  if (!tools)
107
- return { tools: [], workspace: null, canReadFiles: false };
109
+ return { tools: [], workspace: null, canReadFiles: false, imageBudget };
108
110
  // ONE workspace for the whole turn: the file tools act on it and
109
111
  // `upload_file` reads it, so the file the model just wrote is the file it can
110
112
  // show. Built even when no file tool was admitted but a media tool was, since
@@ -140,12 +142,14 @@ function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered,
140
142
  // A plain JSON schema: pi-ai validates arguments against it as-is.
141
143
  parameters: tool.inputSchema,
142
144
  execute: async (_toolCallId, args) => {
143
- const result = await callMcpTool(tools.gatewayUrl, credential, tool, args);
145
+ const result = await callMcpTool(tools.gatewayUrl, credential, tool, args, TOOL_CALL_TIMEOUT_MS, input.provider.input?.includes('image') === true, imageBudget);
144
146
  const text = joinText(result.content);
145
147
  if (result.isError === true)
146
148
  throw new Error(String(result.error || text || `${tool.name} failed`));
147
149
  return {
148
- content: [{ type: 'text', text: text || `${tool.name} completed.` }],
150
+ content: text || result.content.some((part) => part.type === 'image')
151
+ ? result.content
152
+ : [{ type: 'text', text: `${tool.name} completed.` }],
149
153
  details: {},
150
154
  };
151
155
  },
@@ -157,6 +161,7 @@ function buildTools(input, credential, onAskUserPosted, onInBandReplyDelivered,
157
161
  tools: [...mcp, ...gateway, ...media, ...(workspace?.tools ?? [])],
158
162
  workspace,
159
163
  canReadFiles,
164
+ imageBudget,
160
165
  };
161
166
  }
162
167
  /**
@@ -333,7 +338,7 @@ export async function runAgentTurn(input, emit, takeSteering = () => [], runtime
333
338
  agentId: input.memory.agentId,
334
339
  conversationId: input.tools.conversation?.conversationId ?? '',
335
340
  mcpId: input.memory.mcpId,
336
- callTool: (mcpId, toolName, args, options) => callMcpTool(input.tools.gatewayUrl, credential, { mcpId, name: toolName, description: '', inputSchema: {} }, args, options?.timeoutMs),
341
+ callTool: (mcpId, toolName, args, options) => callMcpTool(input.tools.gatewayUrl, credential, { mcpId, name: toolName, description: '', inputSchema: {} }, args, options?.timeoutMs).then((result) => ({ ...result, content: [{ type: 'text', text: joinText(result.content) }] })),
337
342
  logger: guestLogger,
338
343
  })
339
344
  : null;
@@ -434,6 +439,10 @@ export async function runAgentTurn(input, emit, takeSteering = () => [], runtime
434
439
  const text = messageText(message);
435
440
  return text === undefined ? undefined : messageContext.get(text);
436
441
  });
442
+ // Only the isolate must fit the full checkpoint through a bounded bridge.
443
+ // buildTools charged this prompt's images; add the already-hydrated history.
444
+ built.imageBudget.bytes += toolImageBudget(session.sessionManager.getEntries().flatMap(entry => entry.type === 'message' && 'content' in entry.message && Array.isArray(entry.message.content)
445
+ ? entry.message.content : [])).bytes;
437
446
  session.subscribe((event) => {
438
447
  if (event.type === 'compaction_end' && event.errorMessage)
439
448
  console.warn(event.errorMessage);