@lobu/runtime-device 21.2.1 → 22.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/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 +7 -5
- 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 +51 -33
- package/vendor/cli/dist/connectors/herdr.ts +406 -0
- package/vendor/cli/dist/connectors/jira.ts +6 -6
- package/vendor/cli/dist/connectors/linear.ts +7 -4
- package/vendor/cli/dist/connectors/postgres.ts +27 -2
- package/vendor/cli/dist/connectors/tiktok-inbox-page.js +230 -0
- package/vendor/cli/dist/connectors/tiktok-web-page.js +211 -0
- package/vendor/cli/dist/connectors/tiktok_web.ts +286 -0
- package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +228 -10
- package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +47 -14
- package/vendor/cli/dist/connectors/whatsapp-web-identity.ts +121 -0
- package/vendor/cli/dist/connectors/whatsapp_web.ts +170 -29
- package/vendor/cli/dist/connectors/x.ts +276 -136
- 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 +11 -4
- 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-requirement.d.ts +36 -0
- package/vendor/connector-sdk/dist/browser-requirement.js +60 -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 +159 -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 +5 -2
- package/vendor/connector-sdk/dist/index.js +1 -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 +5 -1
- package/vendor/connector-worker/dist/agent-turn/guest-entry.js +31 -27
- package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +131 -185
- 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/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 +5 -1
- package/vendor/connector-worker/dist/daemon/client.js +3 -0
- 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 -117
- 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 +20 -4
- package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +53 -13
- 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 +2 -0
- 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 +12 -5
- 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 +10 -3
- 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.js +2 -0
- 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-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-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 +122 -28
- package/vendor/core/dist/contracts/worker/protocol.js +81 -17
- package/vendor/core/dist/index.d.ts +3 -4
- package/vendor/core/dist/index.js +3 -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 +11 -5
- 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/{sentry-scrubber.js → diagnostic-scrubber.js} +25 -53
- package/vendor/core/dist/worker/auth.d.ts +44 -6
- package/vendor/core/dist/worker/auth.js +44 -11
- package/vendor/core/package.json +15 -6
- 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/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
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import type { EventEnvelope } from "@lobu/connector-sdk";
|
|
17
17
|
|
|
18
|
-
export const WHATSAPP_ADAPTER_VERSION =
|
|
18
|
+
export const WHATSAPP_ADAPTER_VERSION = 22;
|
|
19
19
|
export const WHATSAPP_ORIGIN = "https://web.whatsapp.com";
|
|
20
20
|
const WHATSAPP_SOURCE = "whatsapp_web";
|
|
21
21
|
const RECENT_OVERLAP_SECONDS = 15 * 60;
|
|
@@ -106,6 +106,8 @@ export interface BrowserCheckpoint {
|
|
|
106
106
|
dirty?: DirtyMarker[];
|
|
107
107
|
diagnostics?: Record<string, unknown>;
|
|
108
108
|
last_run_at?: string;
|
|
109
|
+
/** Reference-only observation position in WhatsApp's own local message store. */
|
|
110
|
+
observation?: { after: number; started_at: number; chat_filter: ChatFilter };
|
|
109
111
|
/** Exact buffered revisions included in the last successful sync. */
|
|
110
112
|
source_ack?: {
|
|
111
113
|
binding_id: string;
|
|
@@ -479,28 +481,59 @@ function isInlineThumbnail(body: string): boolean {
|
|
|
479
481
|
);
|
|
480
482
|
}
|
|
481
483
|
|
|
482
|
-
|
|
484
|
+
const MEDIA_PLACEHOLDERS: Record<string, string> = {
|
|
485
|
+
ptt: "[voice note]",
|
|
486
|
+
audio: "[voice note]",
|
|
487
|
+
image: "[image]",
|
|
488
|
+
video: "[video]",
|
|
489
|
+
document: "[document]",
|
|
490
|
+
sticker: "[sticker]",
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
function messageBodyText(message: WhatsAppMessage): string {
|
|
483
494
|
const body =
|
|
484
495
|
typeof message.body === "string" &&
|
|
485
496
|
message.body.length > 0 &&
|
|
486
497
|
!isInlineThumbnail(message.body)
|
|
487
498
|
? message.body
|
|
488
499
|
: "";
|
|
489
|
-
|
|
500
|
+
return (
|
|
490
501
|
body ||
|
|
491
502
|
(typeof message.caption === "string" && message.caption.length > 0
|
|
492
503
|
? message.caption
|
|
493
|
-
: "")
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
+
: "")
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function mediaKind(message: WhatsAppMessage): string {
|
|
509
|
+
return String(message.media_kind ?? message.media_type ?? message.message_type ?? "");
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* What a message carries, decided from its fields rather than from the
|
|
514
|
+
* placeholder text `messagePayloadText` renders for it: readers that must
|
|
515
|
+
* not answer a revocation or a bare image key on this.
|
|
516
|
+
*/
|
|
517
|
+
export type MessageContentKind = "text" | "media" | "revoked" | "system";
|
|
518
|
+
|
|
519
|
+
export function messageContentKind(message: WhatsAppMessage): MessageContentKind {
|
|
520
|
+
if (message.revoked) return "revoked";
|
|
521
|
+
if (message.is_system_event) return "system";
|
|
522
|
+
if (messageBodyText(message)) return "text";
|
|
523
|
+
return Object.hasOwn(MEDIA_PLACEHOLDERS, mediaKind(message)) ? "media" : "system";
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export function messagePayloadText(message: WhatsAppMessage): string {
|
|
527
|
+
switch (messageContentKind(message)) {
|
|
528
|
+
case "revoked":
|
|
529
|
+
return "[revoked message]";
|
|
530
|
+
case "text":
|
|
531
|
+
return messageBodyText(message);
|
|
532
|
+
case "media":
|
|
533
|
+
return MEDIA_PLACEHOLDERS[mediaKind(message)];
|
|
534
|
+
default:
|
|
535
|
+
return messageBodyText(message) || "[system event]";
|
|
536
|
+
}
|
|
504
537
|
}
|
|
505
538
|
|
|
506
539
|
export function messageTitle(message: WhatsAppMessage): string {
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WhatsApp Web chat-sender identity: namespace and normalization.
|
|
3
|
+
*
|
|
4
|
+
* A WhatsApp person is addressed by one of two unrelated JIDs: the phone-number
|
|
5
|
+
* JID (`<digits>@s.whatsapp.net`, which the web client also spells `@c.us`) and
|
|
6
|
+
* the privacy LID (`<digits>@lid`). The SAME human can arrive under either, but
|
|
7
|
+
* nothing in a message proves that a given LID and a given phone JID belong to
|
|
8
|
+
* one person — the page's own LID→phone migration is best-effort and silent on
|
|
9
|
+
* a miss. So the stored key KEEPS its server suffix: a phone JID and a LID are
|
|
10
|
+
* two distinct keys that never compare equal, and a member who wants to be
|
|
11
|
+
* recognised under both carries both, each written by an explicit link. This
|
|
12
|
+
* module never derives one from the other.
|
|
13
|
+
*
|
|
14
|
+
* Group JIDs (`@g.us`), broadcasts and newsletters name a conversation, not a
|
|
15
|
+
* person, so they are not user keys at all.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { ChatUserIdentity } from "./chat-user-identity.js";
|
|
19
|
+
import type { ConnectorIdentityModule } from "./connector-identity-module.js";
|
|
20
|
+
|
|
21
|
+
/** Connector-owned identity namespaces (not SDK-global). */
|
|
22
|
+
export const WHATSAPP_WEB_IDENTITY = {
|
|
23
|
+
/**
|
|
24
|
+
* A WhatsApp person JID, server suffix included: `<digits>@s.whatsapp.net`
|
|
25
|
+
* or `<digits>@lid`. Distinct from the connector's `wa_jid` person-entity
|
|
26
|
+
* attribution key, so a chat link on a `$member` never collides with the
|
|
27
|
+
* contact entity the same sender's messages auto-create.
|
|
28
|
+
*/
|
|
29
|
+
USER_JID: "whatsapp_user_jid",
|
|
30
|
+
} as const;
|
|
31
|
+
|
|
32
|
+
const PHONE_SERVER = "s.whatsapp.net";
|
|
33
|
+
const LEGACY_PHONE_SERVER = "c.us";
|
|
34
|
+
const LID_SERVER = "lid";
|
|
35
|
+
|
|
36
|
+
/** True when `value` is only ASCII digits, with a length in [min, max]. */
|
|
37
|
+
function isDigits(value: string, min: number, max: number): boolean {
|
|
38
|
+
if (value.length < min || value.length > max) return false;
|
|
39
|
+
for (const ch of value) {
|
|
40
|
+
if (ch < "0" || ch > "9") return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Canonicalize a WhatsApp person JID, or null when the value is not one.
|
|
47
|
+
*
|
|
48
|
+
* - `@c.us` is the web client's spelling of the phone server and becomes
|
|
49
|
+
* `@s.whatsapp.net`, matching the connector's own canonical form.
|
|
50
|
+
* - A multi-device suffix (`<user>:<device>@server`) addresses one of the
|
|
51
|
+
* person's devices, not a different person, so it is dropped.
|
|
52
|
+
* - Group, broadcast, newsletter and any other server return null.
|
|
53
|
+
*
|
|
54
|
+
* The user part is digits only and bounded, so an arbitrary string can never
|
|
55
|
+
* become an indexed identity value.
|
|
56
|
+
*/
|
|
57
|
+
export function normalizeWhatsAppUserJid(
|
|
58
|
+
raw: string | null | undefined,
|
|
59
|
+
): string | null {
|
|
60
|
+
if (typeof raw !== "string") return null;
|
|
61
|
+
const value = raw.trim().toLowerCase();
|
|
62
|
+
const at = value.indexOf("@");
|
|
63
|
+
if (at <= 0 || at !== value.lastIndexOf("@")) return null;
|
|
64
|
+
const server = value.slice(at + 1);
|
|
65
|
+
const userPart = value.slice(0, at);
|
|
66
|
+
const colon = userPart.indexOf(":");
|
|
67
|
+
const user = colon === -1 ? userPart : userPart.slice(0, colon);
|
|
68
|
+
if (colon !== -1 && !isDigits(userPart.slice(colon + 1), 1, 4)) return null;
|
|
69
|
+
if (!isDigits(user, 5, 32)) return null;
|
|
70
|
+
if (server === PHONE_SERVER || server === LEGACY_PHONE_SERVER) {
|
|
71
|
+
return `${user}@${PHONE_SERVER}`;
|
|
72
|
+
}
|
|
73
|
+
if (server === LID_SERVER) return `${user}@${LID_SERVER}`;
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Normalize a WhatsApp Web identity namespace value. Returns `undefined` when
|
|
79
|
+
* the namespace is not owned here (caller falls back to generic hygiene).
|
|
80
|
+
*/
|
|
81
|
+
export function normalizeWhatsAppWebIdentityValue(
|
|
82
|
+
namespace: string,
|
|
83
|
+
raw: string,
|
|
84
|
+
): string | null | undefined {
|
|
85
|
+
switch (namespace) {
|
|
86
|
+
case WHATSAPP_WEB_IDENTITY.USER_JID:
|
|
87
|
+
return normalizeWhatsAppUserJid(raw);
|
|
88
|
+
default:
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The WhatsApp Web connector's contribution to the server identity wiring. */
|
|
94
|
+
export const whatsAppWebIdentityModule: ConnectorIdentityModule = {
|
|
95
|
+
key: "whatsapp.web",
|
|
96
|
+
// Links a chat sender to a member; not an event-recall key.
|
|
97
|
+
recallNamespaces: [],
|
|
98
|
+
normalize: normalizeWhatsAppWebIdentityValue,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* WhatsApp Web's sender-identity model. JIDs are unique across all of WhatsApp,
|
|
103
|
+
* so there is no tenant axis: `teamId` is ignored and the scope is global.
|
|
104
|
+
*
|
|
105
|
+
* `providerId` names no sign-in provider Lobu configures — WhatsApp has no OAuth
|
|
106
|
+
* login — so no web sign-in can ever stamp this namespace. A link has to come
|
|
107
|
+
* from an explicit, sender-proven linking step.
|
|
108
|
+
*/
|
|
109
|
+
export const whatsAppWebChatUserIdentity: ChatUserIdentity = {
|
|
110
|
+
platform: "whatsapp.web",
|
|
111
|
+
providerId: "whatsapp",
|
|
112
|
+
namespace: WHATSAPP_WEB_IDENTITY.USER_JID,
|
|
113
|
+
buildUserKey(_teamId, platformUserId) {
|
|
114
|
+
return normalizeWhatsAppUserJid(platformUserId);
|
|
115
|
+
},
|
|
116
|
+
userKeyScope: () => ({ kind: "global" }),
|
|
117
|
+
// The stored key is already the JID the device's `send_message` addresses.
|
|
118
|
+
platformUserIdFromKey(key) {
|
|
119
|
+
return normalizeWhatsAppUserJid(key);
|
|
120
|
+
},
|
|
121
|
+
};
|
|
@@ -10,11 +10,15 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
|
+
requireBrowser,
|
|
13
14
|
type ActionContext,
|
|
14
15
|
type ActionResult,
|
|
15
16
|
type ChromeActionDispatcher,
|
|
16
17
|
ConnectorRuntime,
|
|
17
18
|
type EventEnvelope,
|
|
19
|
+
type FeedReadContext,
|
|
20
|
+
type FeedReadResult,
|
|
21
|
+
type FeedObserveContext,
|
|
18
22
|
type RuntimeConnectorDefinition,
|
|
19
23
|
type SyncContext,
|
|
20
24
|
type SyncResult,
|
|
@@ -32,6 +36,7 @@ import {
|
|
|
32
36
|
type MediaStatus,
|
|
33
37
|
mergeBrowserCheckpoint,
|
|
34
38
|
mergeCollectedMessages,
|
|
39
|
+
messageContentKind,
|
|
35
40
|
messagePayloadText,
|
|
36
41
|
messageRevision,
|
|
37
42
|
messageTitle,
|
|
@@ -44,6 +49,8 @@ import {
|
|
|
44
49
|
import { whatsAppWebAdapterProgram } from "./whatsapp-web-adapter.js";
|
|
45
50
|
|
|
46
51
|
const SOURCE_OBSERVATION_ERROR_ID = "whatsapp-web:source-observation-error";
|
|
52
|
+
// Each durable browser record is limited to 128 KiB, including its checkpoint.
|
|
53
|
+
const SOURCE_RECORD_MAX_BYTES = 128 * 1024;
|
|
47
54
|
|
|
48
55
|
/**
|
|
49
56
|
* How long a run waits for WhatsApp Web to finish hydrating before giving up.
|
|
@@ -120,26 +127,6 @@ class WhatsAppAdapterError extends Error {
|
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
129
|
|
|
123
|
-
/**
|
|
124
|
-
* Pull the chrome action dispatcher off sessionState. The connector-worker
|
|
125
|
-
* host splices a live `chrome_dispatcher` onto every sync AND action context;
|
|
126
|
-
* its `dispatch()` rides a host capability up to the daemon and out to the
|
|
127
|
-
* gateway's chrome-action bridge.
|
|
128
|
-
*/
|
|
129
|
-
function requireExtensionDispatcher(ctx: {
|
|
130
|
-
sessionState?: Record<string, unknown> | null;
|
|
131
|
-
}): ChromeActionDispatcher {
|
|
132
|
-
const handle = ctx.sessionState?.chrome_dispatcher as
|
|
133
|
-
| ChromeActionDispatcher
|
|
134
|
-
| undefined;
|
|
135
|
-
if (!handle || typeof handle.dispatch !== "function") {
|
|
136
|
-
throw new Error(
|
|
137
|
-
"WhatsApp Web connector requires a paired Owletto Chrome extension. No chrome_dispatcher was injected into sessionState — pin this connection to a chrome-extension device."
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
return handle;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
130
|
/**
|
|
144
131
|
* A hydrated WhatsApp Web tab in the extension's persistent agent window.
|
|
145
132
|
*
|
|
@@ -593,9 +580,13 @@ function normalizedSearchResults(
|
|
|
593
580
|
chat_name: message.chat_name ?? null,
|
|
594
581
|
title: messageTitle(message),
|
|
595
582
|
text: messagePayloadText(message),
|
|
583
|
+
content_kind: messageContentKind(message),
|
|
596
584
|
occurred_at: message.occurred_at,
|
|
597
585
|
from_me: message.from_me,
|
|
598
586
|
sender_jid: message.sender_jid ?? null,
|
|
587
|
+
sender_phone: message.sender_phone ?? null,
|
|
588
|
+
push_name: message.push_name ?? null,
|
|
589
|
+
is_group: message.is_group,
|
|
599
590
|
quoted_id: message.quoted_id ?? null,
|
|
600
591
|
});
|
|
601
592
|
}
|
|
@@ -622,15 +613,60 @@ export default class WhatsAppWebConnector extends ConnectorRuntime<
|
|
|
622
613
|
name: "WhatsApp",
|
|
623
614
|
description:
|
|
624
615
|
"Personal WhatsApp messages read from WhatsApp Web in the paired Owletto Chrome. Syncs one-to-one and group chats, progressively hydrates history, and can search, draft, send, edit, react to, and revoke messages.",
|
|
625
|
-
version: "1.0.
|
|
616
|
+
version: "1.0.9",
|
|
626
617
|
faviconDomain: "whatsapp.com",
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
618
|
+
authSchema: { methods: [{ type: "browser", mode: "live" }] },
|
|
619
|
+
browser: {
|
|
620
|
+
origins: [WHATSAPP_ORIGIN],
|
|
621
|
+
accountProbe: {
|
|
622
|
+
url: `${WHATSAPP_ORIGIN}/`,
|
|
623
|
+
expression: `(async () => {
|
|
624
|
+
(${whatsAppWebAdapterProgram.toString()})();
|
|
625
|
+
for (let i = 0; i < 40; i++) {
|
|
626
|
+
const identity = await globalThis.__owlettoWhatsAppAdapterV1.invoke({ op: "account_identity", adapter_version: ${WHATSAPP_ADAPTER_VERSION} });
|
|
627
|
+
if (identity?.accountId) return identity;
|
|
628
|
+
await new Promise(resolve => setTimeout(resolve, 250));
|
|
629
|
+
}
|
|
630
|
+
return null;
|
|
631
|
+
})()`,
|
|
632
|
+
},
|
|
633
|
+
},
|
|
634
|
+
automationEvents: [{
|
|
635
|
+
key: "message.created", label: "New message", resourceType: "message",
|
|
636
|
+
description: "A new message reference from WhatsApp Web. The Automation can read its content from the live messages feed, or reply in the chat it came from.",
|
|
637
|
+
filterSchema: {
|
|
638
|
+
type: "object",
|
|
639
|
+
properties: {
|
|
640
|
+
channel_id: {
|
|
641
|
+
type: "string",
|
|
642
|
+
title: "Chat",
|
|
643
|
+
description: "WhatsApp chat ID. Replies into a group need this set to that group.",
|
|
644
|
+
},
|
|
645
|
+
},
|
|
646
|
+
},
|
|
647
|
+
capabilities: { replyToSource: true },
|
|
648
|
+
}],
|
|
633
649
|
feeds: {
|
|
650
|
+
live_messages: {
|
|
651
|
+
key: "live_messages",
|
|
652
|
+
name: "Live messages",
|
|
653
|
+
description:
|
|
654
|
+
"Read messages directly from WhatsApp Web without importing history, using literal text search or id:<message ID>. Active Automations can subscribe to new-message references. Requires the paired browser to be online and signed in; reconnects replay messages still available in WhatsApp's local history.",
|
|
655
|
+
read: (ctx) => this.readMessages(ctx),
|
|
656
|
+
observe: (ctx) => this.observeMessages(ctx),
|
|
657
|
+
webhook: { mode: "trigger", events: ["message.created"] },
|
|
658
|
+
configSchema: {
|
|
659
|
+
type: "object",
|
|
660
|
+
properties: {
|
|
661
|
+
chat_filter: {
|
|
662
|
+
type: "string",
|
|
663
|
+
enum: ["all", "individual", "group"],
|
|
664
|
+
default: "all",
|
|
665
|
+
description: "Which chats to include.",
|
|
666
|
+
},
|
|
667
|
+
},
|
|
668
|
+
},
|
|
669
|
+
},
|
|
634
670
|
messages: {
|
|
635
671
|
sync: (ctx) => this.syncMessages(ctx),
|
|
636
672
|
webhook: { events: ["message"], mode: "trigger" },
|
|
@@ -929,10 +965,72 @@ export default class WhatsAppWebConnector extends ConnectorRuntime<
|
|
|
929
965
|
},
|
|
930
966
|
};
|
|
931
967
|
|
|
968
|
+
private async observeMessages(ctx: FeedObserveContext<BrowserCheckpoint, WhatsAppWebConfig>): Promise<void> {
|
|
969
|
+
const dispatcher = requireBrowser(ctx);
|
|
970
|
+
const tabId = await readyWhatsAppTab(dispatcher);
|
|
971
|
+
const chatFilter = ctx.config.chat_filter ?? "all";
|
|
972
|
+
const previous = ctx.checkpoint?.observation?.chat_filter === chatFilter ? ctx.checkpoint.observation : undefined;
|
|
973
|
+
const startedAt = previous?.started_at ?? Math.floor(Date.now() / 1000);
|
|
974
|
+
// Snapshot before attaching so replay covers messages arriving during setup.
|
|
975
|
+
let after = previous?.after ?? (await invokeAdapter<{ after: number }>(
|
|
976
|
+
dispatcher, tabId, { op: "observe_messages", input: {} })).after;
|
|
977
|
+
const binding = await dispatcher.dispatch<{
|
|
978
|
+
bridge_id: string; token: string; listening?: boolean; subscription?: { scope_key: string };
|
|
979
|
+
}>("feed_listen", { tab_id: tabId });
|
|
980
|
+
if (!binding.bridge_id || !binding.token || !binding.subscription || binding.listening === false) {
|
|
981
|
+
throw new Error("A browser supporting source subscriptions is required for WhatsApp");
|
|
982
|
+
}
|
|
983
|
+
await invokeAdapter(dispatcher, tabId, {
|
|
984
|
+
op: "listen", bridge_id: binding.bridge_id, token: binding.token, references_only: true,
|
|
985
|
+
chat_filter: chatFilter, recent_since: startedAt, minimum_timestamp: startedAt,
|
|
986
|
+
});
|
|
987
|
+
let cursor = ctx.checkpoint ?? null;
|
|
988
|
+
for (let page = 0; page < 10; page++) {
|
|
989
|
+
const replay = await invokeAdapter<{
|
|
990
|
+
after: number; references: Array<{ id: string; timestamp: number }>; hasMore: boolean;
|
|
991
|
+
}>(dispatcher, tabId, { op: "observe_messages", input: { after, started_at: startedAt, chat_filter: chatFilter } });
|
|
992
|
+
const next: BrowserCheckpoint = {
|
|
993
|
+
schema: "owletto.whatsapp.browser.v1", adapter_version: WHATSAPP_ADAPTER_VERSION,
|
|
994
|
+
head: {}, backfill: { complete: true, cursor_chat_jid: null, inventory: [], chats: {} },
|
|
995
|
+
observation: { after: replay.after, started_at: startedAt, chat_filter: chatFilter },
|
|
996
|
+
};
|
|
997
|
+
const events = replay.references.map(reference => ({
|
|
998
|
+
id: reference.id, event_type: "message.created", resource_type: "message",
|
|
999
|
+
resource_ref: reference.id, occurred_at: new Date(reference.timestamp * 1000).toISOString(),
|
|
1000
|
+
}));
|
|
1001
|
+
for (let offset = 0; ;) {
|
|
1002
|
+
const batchThrough = (end: number) => ({
|
|
1003
|
+
id: `replay:${chatFilter}:${startedAt}:${after}:${replay.after}:${offset}`,
|
|
1004
|
+
events: events.slice(offset, end),
|
|
1005
|
+
// Earlier chunks may be replayed after interruption; existing signal
|
|
1006
|
+
// dedupe handles them. Advance only after the entire page is accepted.
|
|
1007
|
+
...(end === events.length ? { checkpoint: { previous: cursor, next } } : {}),
|
|
1008
|
+
more: end === events.length && replay.hasMore && page === 9,
|
|
1009
|
+
});
|
|
1010
|
+
let end = Math.min(offset + 500, events.length);
|
|
1011
|
+
let batch = batchThrough(end);
|
|
1012
|
+
const size = () => new TextEncoder().encode(JSON.stringify(batch)).length;
|
|
1013
|
+
while (size() > SOURCE_RECORD_MAX_BYTES && end - offset > 1) {
|
|
1014
|
+
end = offset + Math.floor((end - offset) / 2);
|
|
1015
|
+
batch = batchThrough(end);
|
|
1016
|
+
}
|
|
1017
|
+
if (size() > SOURCE_RECORD_MAX_BYTES) throw new Error("Source reference or checkpoint exceeds the browser record limit");
|
|
1018
|
+
await invokeAdapter(dispatcher, tabId, {
|
|
1019
|
+
op: "publish_changes", bridge_id: binding.bridge_id, token: binding.token, batch,
|
|
1020
|
+
});
|
|
1021
|
+
if (end === events.length) break;
|
|
1022
|
+
offset = end;
|
|
1023
|
+
}
|
|
1024
|
+
if (!replay.hasMore) return;
|
|
1025
|
+
cursor = next;
|
|
1026
|
+
after = replay.after;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
|
|
932
1030
|
private async syncMessages(
|
|
933
1031
|
ctx: SyncContext<BrowserCheckpoint, WhatsAppWebConfig>
|
|
934
1032
|
): Promise<SyncResult> {
|
|
935
|
-
const dispatcher =
|
|
1033
|
+
const dispatcher = requireBrowser(ctx);
|
|
936
1034
|
const tabId = await readyWhatsAppTab(dispatcher);
|
|
937
1035
|
return await this.collectMessages(ctx, dispatcher, tabId);
|
|
938
1036
|
}
|
|
@@ -1142,13 +1240,56 @@ export default class WhatsAppWebConnector extends ConnectorRuntime<
|
|
|
1142
1240
|
return { status: "complete" };
|
|
1143
1241
|
}
|
|
1144
1242
|
|
|
1243
|
+
private async readMessages(ctx: FeedReadContext<WhatsAppWebConfig>): Promise<FeedReadResult> {
|
|
1244
|
+
if (ctx.offset) throw new Error("WhatsApp live reads paginate with the returned cursor, not an offset.");
|
|
1245
|
+
if (ctx.sort) throw new Error("WhatsApp live reads use source storage order; explicit sorting is not supported.");
|
|
1246
|
+
// Source message time cannot represent edits, revokes, or delayed arrivals.
|
|
1247
|
+
// Keep Automation change consumption on the existing durable event path.
|
|
1248
|
+
if (ctx.window) throw new Error("WhatsApp live reads do not support change-time windows; use message events for Automation changes.");
|
|
1249
|
+
const dispatcher = requireBrowser(ctx);
|
|
1250
|
+
const tabId = await readyWhatsAppTab(dispatcher);
|
|
1251
|
+
const response = await invokeAdapter<{
|
|
1252
|
+
results: unknown[];
|
|
1253
|
+
nextCursor?: string;
|
|
1254
|
+
hasMore: boolean;
|
|
1255
|
+
}>(dispatcher, tabId, {
|
|
1256
|
+
op: "read_messages",
|
|
1257
|
+
input: {
|
|
1258
|
+
query: ctx.query,
|
|
1259
|
+
cursor: ctx.cursor,
|
|
1260
|
+
limit: ctx.limit,
|
|
1261
|
+
chat_filter: ctx.config.chat_filter ?? "all",
|
|
1262
|
+
},
|
|
1263
|
+
});
|
|
1264
|
+
return {
|
|
1265
|
+
rows: normalizedSearchResults(response.results),
|
|
1266
|
+
columns: [
|
|
1267
|
+
{ name: "id", type: "string" },
|
|
1268
|
+
{ name: "chat_jid", type: "string" },
|
|
1269
|
+
{ name: "chat_name", type: "string" },
|
|
1270
|
+
{ name: "title", type: "string" },
|
|
1271
|
+
{ name: "text", type: "string" },
|
|
1272
|
+
{ name: "content_kind", type: "string" },
|
|
1273
|
+
{ name: "occurred_at", type: "string" },
|
|
1274
|
+
{ name: "from_me", type: "boolean" },
|
|
1275
|
+
{ name: "sender_jid", type: "string" },
|
|
1276
|
+
{ name: "sender_phone", type: "string" },
|
|
1277
|
+
{ name: "push_name", type: "string" },
|
|
1278
|
+
{ name: "is_group", type: "boolean" },
|
|
1279
|
+
{ name: "quoted_id", type: "string" },
|
|
1280
|
+
],
|
|
1281
|
+
nextCursor: response.nextCursor,
|
|
1282
|
+
hasMore: response.hasMore,
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1145
1286
|
async execute(ctx: ActionContext): Promise<ActionResult> {
|
|
1146
1287
|
const action = ctx.actionKey;
|
|
1147
1288
|
if (action !== "search_messages" && !WRITE_ACTIONS.has(action)) {
|
|
1148
1289
|
return { success: false, error: `Unknown action: ${action}` };
|
|
1149
1290
|
}
|
|
1150
1291
|
try {
|
|
1151
|
-
const dispatcher =
|
|
1292
|
+
const dispatcher = requireBrowser(ctx);
|
|
1152
1293
|
const tabId = await readyWhatsAppTab(dispatcher);
|
|
1153
1294
|
const response = await invokeAdapter<Record<string, unknown>>(
|
|
1154
1295
|
dispatcher,
|