@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
|
@@ -4,16 +4,15 @@
|
|
|
4
4
|
* Supports two auth modes:
|
|
5
5
|
* - OAuth 2.0 user context against the X API v2 (preferred when a token is
|
|
6
6
|
* available — the ToS-compliant path).
|
|
7
|
-
* -
|
|
8
|
-
* connector: we attach the CDP Network domain
|
|
9
|
-
* x.com tab via the extension's `chrome.*` action
|
|
10
|
-
* pagination, and parse the GraphQL responses the
|
|
11
|
-
*
|
|
7
|
+
* - A separate, verified browser connection through the paired Owletto Chrome
|
|
8
|
+
* extension. Mirrors the LinkedIn connector: we attach the CDP Network domain
|
|
9
|
+
* in the user's signed-in x.com tab via the extension's `chrome.*` action
|
|
10
|
+
* dispatcher, drive scroll pagination, and parse the GraphQL responses the
|
|
11
|
+
* page emits. No Playwright, cookie cache, or `--remote-debugging-port` plumbing.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* with a clear "no paired Owletto extension" error.
|
|
13
|
+
* Browser access requires a verified browser-authenticated connection.
|
|
14
|
+
* An OAuth connection does not gain browser access from a device pin; API
|
|
15
|
+
* failures stay on the OAuth path when no browser grant is available.
|
|
17
16
|
*
|
|
18
17
|
* Feeds:
|
|
19
18
|
* - tweets: search by query or track a handle (API v2 or extension search)
|
|
@@ -21,8 +20,13 @@
|
|
|
21
20
|
* - liked_tweets: posts the user has liked (API v2 or signed-in extension backfill)
|
|
22
21
|
* - bookmarks: posts the user has bookmarked (API v2 or extension)
|
|
23
22
|
* - direct_messages: 1:1 and group DMs (OAuth API; extension fallback on /messages)
|
|
24
|
-
* -
|
|
25
|
-
*
|
|
23
|
+
* - live_messages: DMs read live from the signed-in browser without importing
|
|
24
|
+
* history; Automations subscribe to `message.created` and can
|
|
25
|
+
* answer through `send_message`
|
|
26
|
+
* - following_timeline: live chronological Following timeline (OAuth API,
|
|
27
|
+
* source reads only; does not import tweet events)
|
|
28
|
+
* - home_feed: personalized x.com home timeline (extension only — the
|
|
29
|
+
* API does not expose the algorithmic "For you" timeline;
|
|
26
30
|
* read via content-script scrape because CDP network capture
|
|
27
31
|
* blocks the feed from rendering, same as LinkedIn home_feed)
|
|
28
32
|
*/
|
|
@@ -30,23 +34,34 @@
|
|
|
30
34
|
import {
|
|
31
35
|
type ActionContext,
|
|
32
36
|
type ActionResult,
|
|
37
|
+
assertNoMatch,
|
|
38
|
+
assertNoOffsetPaging,
|
|
39
|
+
assertNoSort,
|
|
40
|
+
assertNoWindow,
|
|
41
|
+
buildInjectHandoffBannerExpression as buildSharedHandoffBannerExpression,
|
|
33
42
|
type ChromeActionDispatcher,
|
|
34
|
-
type RuntimeConnectorDefinition,
|
|
35
|
-
type EventAttributionRule,
|
|
36
|
-
type EventAttributionTargetSpec,
|
|
37
|
-
type EntityTraitSpec,
|
|
38
43
|
ConnectorRuntime,
|
|
39
44
|
calculateEngagementScore,
|
|
40
45
|
createHttpClient,
|
|
46
|
+
type EntityTraitSpec,
|
|
47
|
+
type EventAttributionRule,
|
|
48
|
+
type EventAttributionTargetSpec,
|
|
41
49
|
type EventEnvelope,
|
|
42
50
|
extensionDomScrape,
|
|
43
51
|
extensionNetworkSync,
|
|
44
|
-
|
|
52
|
+
type FeedObserveContext,
|
|
53
|
+
type FeedReadContext,
|
|
54
|
+
type FeedReadResult,
|
|
45
55
|
type HttpClient,
|
|
56
|
+
HttpStatusError,
|
|
46
57
|
paginateByCursor,
|
|
58
|
+
type RuntimeConnectorDefinition,
|
|
59
|
+
requireBrowser,
|
|
47
60
|
type SyncContext,
|
|
48
61
|
type SyncResult,
|
|
62
|
+
truncateHandoffReason as truncateSharedHandoffReason,
|
|
49
63
|
} from "@lobu/connector-sdk";
|
|
64
|
+
import { xDirectMessagesProgram } from "./x-dm-adapter.js";
|
|
50
65
|
|
|
51
66
|
/** What one X sync gathers before it is committed. */
|
|
52
67
|
type XSyncPage = {
|
|
@@ -54,7 +69,8 @@ type XSyncPage = {
|
|
|
54
69
|
checkpoint: Record<string, unknown>;
|
|
55
70
|
metadata?: SyncResult["metadata"];
|
|
56
71
|
};
|
|
57
|
-
|
|
72
|
+
|
|
73
|
+
import { normalizeXHandle, X_IDENTITY } from "./x-identity.js";
|
|
58
74
|
|
|
59
75
|
/** OAuth scopes needed per feed for the API path (not used to pause browser-capable feeds). */
|
|
60
76
|
const X_OAUTH_FEED_SCOPES: Record<string, readonly string[]> = {
|
|
@@ -353,12 +369,23 @@ const X_DM_COUNTERPARTY_ATTRIBUTIONS: EventAttributionRule[] = [
|
|
|
353
369
|
entityType: "person",
|
|
354
370
|
titlePath: "metadata.sender_name",
|
|
355
371
|
identities: [
|
|
356
|
-
{
|
|
357
|
-
|
|
372
|
+
{
|
|
373
|
+
namespace: X_IDENTITY.USER_ID,
|
|
374
|
+
eventPath: "metadata.sender_id",
|
|
375
|
+
primary: true,
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
namespace: X_IDENTITY.HANDLE,
|
|
379
|
+
eventPath: "metadata.sender_handle",
|
|
380
|
+
matchOnly: true,
|
|
381
|
+
},
|
|
358
382
|
],
|
|
359
383
|
},
|
|
360
384
|
traits: {
|
|
361
|
-
x_handle: {
|
|
385
|
+
x_handle: {
|
|
386
|
+
eventPath: "metadata.sender_handle",
|
|
387
|
+
mergeStrategy: "prefer_non_empty",
|
|
388
|
+
},
|
|
362
389
|
// Same trait key as X_PERSON_AUTHOR_TRAITS / DM counterparty — keep
|
|
363
390
|
// person metadata vocabulary consistent across X attribution paths.
|
|
364
391
|
x_display_name: {
|
|
@@ -526,8 +553,7 @@ function buildApiTweet(
|
|
|
526
553
|
)?.id;
|
|
527
554
|
|
|
528
555
|
const authorId = tweet.author_id;
|
|
529
|
-
const username =
|
|
530
|
-
usernameById.get(authorId ?? "") ?? defaultUsername ?? "";
|
|
556
|
+
const username = usernameById.get(authorId ?? "") ?? defaultUsername ?? "";
|
|
531
557
|
|
|
532
558
|
return {
|
|
533
559
|
id: tweet.id,
|
|
@@ -1230,28 +1256,11 @@ export function finalizeLikedTweetsResult(
|
|
|
1230
1256
|
|
|
1231
1257
|
// ── Extension dispatcher ───────────────────────────────────────
|
|
1232
1258
|
//
|
|
1233
|
-
//
|
|
1234
|
-
//
|
|
1235
|
-
//
|
|
1236
|
-
//
|
|
1237
|
-
// extension. When no extension is online in the connection's org, the bridge
|
|
1259
|
+
// Granted as ctx.browser only for the declared browser authentication mode.
|
|
1260
|
+
// The dispatcher's dispatch() rides a host capability up to the gateway's
|
|
1261
|
+
// /api/workers/dispatch-chrome-action bridge and out to the connection's
|
|
1262
|
+
// selected Owletto extension. When that browser is offline, the bridge
|
|
1238
1263
|
// returns `failed` and the dispatcher throws — we surface that verbatim.
|
|
1239
|
-
//
|
|
1240
|
-
// Structurally typed rather than taking SyncContext, so `execute()` can pass an
|
|
1241
|
-
// ActionContext without either context type having to know about the other.
|
|
1242
|
-
function requireExtensionDispatcher(ctx: {
|
|
1243
|
-
sessionState?: Record<string, unknown> | null;
|
|
1244
|
-
}): ChromeActionDispatcher {
|
|
1245
|
-
const handle = ctx.sessionState?.chrome_dispatcher as
|
|
1246
|
-
| ChromeActionDispatcher
|
|
1247
|
-
| undefined;
|
|
1248
|
-
if (!handle || typeof handle.dispatch !== "function") {
|
|
1249
|
-
throw new Error(
|
|
1250
|
-
"X connector requires a paired Owletto Chrome extension. No chrome_dispatcher was injected into sessionState — re-run on a connector-worker that has the dispatcher bridge.",
|
|
1251
|
-
);
|
|
1252
|
-
}
|
|
1253
|
-
return handle;
|
|
1254
|
-
}
|
|
1255
1264
|
|
|
1256
1265
|
// ── Sync paths ─────────────────────────────────────────────────
|
|
1257
1266
|
|
|
@@ -1430,6 +1439,17 @@ class XLikesPageTracker {
|
|
|
1430
1439
|
|
|
1431
1440
|
type XSyncBackend = "oauth_api" | "extension";
|
|
1432
1441
|
|
|
1442
|
+
function requireXBrowser(
|
|
1443
|
+
ctx: Pick<SyncContext, "browser">,
|
|
1444
|
+
): ChromeActionDispatcher {
|
|
1445
|
+
if (!ctx.browser) {
|
|
1446
|
+
throw new Error(
|
|
1447
|
+
"Use a separate X connection authenticated through your paired Chrome browser for browser-only feeds and actions.",
|
|
1448
|
+
);
|
|
1449
|
+
}
|
|
1450
|
+
return requireBrowser(ctx);
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1433
1453
|
function parseGrantedScopes(scope: string | null | undefined): Set<string> {
|
|
1434
1454
|
if (!scope) return new Set();
|
|
1435
1455
|
return new Set(
|
|
@@ -1461,8 +1481,7 @@ function readSyncBackendPreference(
|
|
|
1461
1481
|
}
|
|
1462
1482
|
|
|
1463
1483
|
/**
|
|
1464
|
-
*
|
|
1465
|
-
* paired extension instead of failing against the API.
|
|
1484
|
+
* Use browser fallback only when this connection has an authorized browser grant.
|
|
1466
1485
|
*/
|
|
1467
1486
|
function resolveSyncBackend(
|
|
1468
1487
|
ctx: SyncContext,
|
|
@@ -1470,13 +1489,12 @@ function resolveSyncBackend(
|
|
|
1470
1489
|
requiredScopes: readonly string[] | undefined,
|
|
1471
1490
|
): XSyncBackend {
|
|
1472
1491
|
const preference = readSyncBackendPreference(config);
|
|
1473
|
-
if (preference === "extension") return "extension";
|
|
1474
|
-
if (preference === "oauth_api" && ctx.credentials?.accessToken) {
|
|
1475
|
-
return "oauth_api";
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
1492
|
const accessToken = ctx.credentials?.accessToken;
|
|
1479
|
-
if (
|
|
1493
|
+
if (preference === "extension" || !accessToken) {
|
|
1494
|
+
requireXBrowser(ctx);
|
|
1495
|
+
return "extension";
|
|
1496
|
+
}
|
|
1497
|
+
if (preference === "oauth_api" || !ctx.browser) return "oauth_api";
|
|
1480
1498
|
|
|
1481
1499
|
const granted = parseGrantedScopes(ctx.credentials?.scope);
|
|
1482
1500
|
if (!hasGrantedScopes(granted, requiredScopes)) return "extension";
|
|
@@ -1517,13 +1535,14 @@ async function syncWithOAuthFallback<T extends XSyncPage>(
|
|
|
1517
1535
|
}
|
|
1518
1536
|
}
|
|
1519
1537
|
|
|
1520
|
-
/**
|
|
1538
|
+
/** Fall back only when the connection has a browser grant and OAuth is not forced. */
|
|
1521
1539
|
async function syncOAuthWithOptionalFallback<T extends XSyncPage>(
|
|
1540
|
+
ctx: SyncContext,
|
|
1522
1541
|
config: Record<string, unknown>,
|
|
1523
1542
|
oauthFn: () => Promise<T>,
|
|
1524
1543
|
extensionFn: () => Promise<T>,
|
|
1525
1544
|
): Promise<T> {
|
|
1526
|
-
if (isTruthyConfigFlag(config.use_oauth)) return oauthFn();
|
|
1545
|
+
if (!ctx.browser || isTruthyConfigFlag(config.use_oauth)) return oauthFn();
|
|
1527
1546
|
return syncWithOAuthFallback(oauthFn, extensionFn);
|
|
1528
1547
|
}
|
|
1529
1548
|
|
|
@@ -1535,8 +1554,9 @@ function extractViewerUserId(json: unknown): string | undefined {
|
|
|
1535
1554
|
(data?.data as Record<string, unknown> | undefined)?.user_result,
|
|
1536
1555
|
];
|
|
1537
1556
|
for (const node of candidates) {
|
|
1538
|
-
const result = (
|
|
1539
|
-
|
|
1557
|
+
const result = (
|
|
1558
|
+
node as { user_results?: { result?: { rest_id?: string } } }
|
|
1559
|
+
)?.user_results?.result;
|
|
1540
1560
|
if (result?.rest_id) return String(result.rest_id);
|
|
1541
1561
|
}
|
|
1542
1562
|
return undefined;
|
|
@@ -1562,9 +1582,7 @@ function buildBrowserDmMessage(
|
|
|
1562
1582
|
const createdAt = String(
|
|
1563
1583
|
messageData.time ?? messageData.created_at ?? messageData.timestamp ?? "",
|
|
1564
1584
|
);
|
|
1565
|
-
const senderId = String(
|
|
1566
|
-
messageData.sender_id ?? messageNode.sender_id ?? "",
|
|
1567
|
-
);
|
|
1585
|
+
const senderId = String(messageData.sender_id ?? messageNode.sender_id ?? "");
|
|
1568
1586
|
const conversationId = String(
|
|
1569
1587
|
messageNode.conversation_id ??
|
|
1570
1588
|
messageNode.conversationId ??
|
|
@@ -1641,17 +1659,13 @@ function extractDmMessagesFromNode(
|
|
|
1641
1659
|
|
|
1642
1660
|
const content = record.content;
|
|
1643
1661
|
if (content && typeof content === "object") {
|
|
1644
|
-
messages.push(
|
|
1645
|
-
...extractDmMessagesFromNode(content, authUserId, seen),
|
|
1646
|
-
);
|
|
1662
|
+
messages.push(...extractDmMessagesFromNode(content, authUserId, seen));
|
|
1647
1663
|
}
|
|
1648
1664
|
|
|
1649
1665
|
const entries = record.entries;
|
|
1650
1666
|
if (Array.isArray(entries)) {
|
|
1651
1667
|
for (const entry of entries) {
|
|
1652
|
-
messages.push(
|
|
1653
|
-
...extractDmMessagesFromNode(entry, authUserId, seen),
|
|
1654
|
-
);
|
|
1668
|
+
messages.push(...extractDmMessagesFromNode(entry, authUserId, seen));
|
|
1655
1669
|
}
|
|
1656
1670
|
}
|
|
1657
1671
|
|
|
@@ -1681,9 +1695,7 @@ function extractDmMessagesFromNode(
|
|
|
1681
1695
|
record.user_events,
|
|
1682
1696
|
];
|
|
1683
1697
|
for (const candidate of nestedCandidates) {
|
|
1684
|
-
messages.push(
|
|
1685
|
-
...extractDmMessagesFromNode(candidate, authUserId, seen),
|
|
1686
|
-
);
|
|
1698
|
+
messages.push(...extractDmMessagesFromNode(candidate, authUserId, seen));
|
|
1687
1699
|
}
|
|
1688
1700
|
|
|
1689
1701
|
return messages;
|
|
@@ -1729,6 +1741,99 @@ async function resolveAuthenticatedUser(
|
|
|
1729
1741
|
return { id, username };
|
|
1730
1742
|
}
|
|
1731
1743
|
|
|
1744
|
+
/** Read one source-owned page. No sync/commit path or browser fallback exists. */
|
|
1745
|
+
async function readFollowingTimeline(
|
|
1746
|
+
ctx: FeedReadContext,
|
|
1747
|
+
): Promise<FeedReadResult> {
|
|
1748
|
+
if (!ctx.credentials?.accessToken) {
|
|
1749
|
+
throw new Error("X Following source reads require OAuth credentials.");
|
|
1750
|
+
}
|
|
1751
|
+
if (ctx.query?.trim() || ctx.offset || ctx.match || ctx.window) {
|
|
1752
|
+
throw new Error(
|
|
1753
|
+
"X Following source reads support cursor pagination, not queries, offsets, matches, or window coverage.",
|
|
1754
|
+
);
|
|
1755
|
+
}
|
|
1756
|
+
if (
|
|
1757
|
+
ctx.sort &&
|
|
1758
|
+
!(ctx.sort.column === "occurred_at" && ctx.sort.order === "desc")
|
|
1759
|
+
) {
|
|
1760
|
+
throw new Error(
|
|
1761
|
+
"X Following source reads only support occurred_at descending.",
|
|
1762
|
+
);
|
|
1763
|
+
}
|
|
1764
|
+
const limit = ctx.limit ?? 50;
|
|
1765
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100) {
|
|
1766
|
+
throw new Error(
|
|
1767
|
+
"X Following source read limit must be an integer from 1 to 100.",
|
|
1768
|
+
);
|
|
1769
|
+
}
|
|
1770
|
+
const http = createOAuthHttpClient(ctx.credentials.accessToken);
|
|
1771
|
+
const user = await resolveAuthenticatedUser(http);
|
|
1772
|
+
const expected = ctx.config.expected_account_handle;
|
|
1773
|
+
if (
|
|
1774
|
+
typeof expected === "string" &&
|
|
1775
|
+
normalizeXHandle(expected) !== normalizeXHandle(user.username)
|
|
1776
|
+
) {
|
|
1777
|
+
throw new Error(
|
|
1778
|
+
`Authenticated X account @${user.username} does not match expected account ${expected}.`,
|
|
1779
|
+
);
|
|
1780
|
+
}
|
|
1781
|
+
const url = new URL(
|
|
1782
|
+
`https://api.x.com/2/users/${encodeURIComponent(user.id)}/timelines/reverse_chronological`,
|
|
1783
|
+
);
|
|
1784
|
+
url.searchParams.set("max_results", String(limit));
|
|
1785
|
+
url.searchParams.set("tweet.fields", `${TWEET_FIELDS},entities`);
|
|
1786
|
+
url.searchParams.set("expansions", "author_id");
|
|
1787
|
+
url.searchParams.set("user.fields", "username,name,protected");
|
|
1788
|
+
if (ctx.cursor) url.searchParams.set("pagination_token", ctx.cursor);
|
|
1789
|
+
const page = await http.get<
|
|
1790
|
+
Omit<XApiListResponse, "data" | "includes"> & {
|
|
1791
|
+
data?: Array<XApiTweetRecord & { entities?: { urls?: XExpandedUrl[] } }>;
|
|
1792
|
+
includes?: { users?: Array<XApiUserRecord & { protected?: boolean }> };
|
|
1793
|
+
}
|
|
1794
|
+
>(url.toString());
|
|
1795
|
+
if (
|
|
1796
|
+
page.errors?.length ||
|
|
1797
|
+
(!Array.isArray(page.data) && page.meta?.result_count !== 0)
|
|
1798
|
+
) {
|
|
1799
|
+
throw new Error("X Following API returned an incomplete or invalid page.");
|
|
1800
|
+
}
|
|
1801
|
+
const authors = new Map(
|
|
1802
|
+
(page.includes?.users ?? []).map((author) => [author.id, author]),
|
|
1803
|
+
);
|
|
1804
|
+
const handles = new Map(
|
|
1805
|
+
[...authors].map(([id, author]) => [id, author.username ?? ""]),
|
|
1806
|
+
);
|
|
1807
|
+
const rows: Record<string, unknown>[] = [];
|
|
1808
|
+
for (const record of page.data ?? []) {
|
|
1809
|
+
const tweet = buildApiTweet(record, handles);
|
|
1810
|
+
if (!tweet || !Number.isFinite(tweet.publishedAt.getTime())) {
|
|
1811
|
+
throw new Error(
|
|
1812
|
+
"X Following API returned a post without valid identity, content, or timestamp.",
|
|
1813
|
+
);
|
|
1814
|
+
}
|
|
1815
|
+
const author = authors.get(record.author_id ?? "");
|
|
1816
|
+
// A missing author/protection flag cannot establish public visibility.
|
|
1817
|
+
if (ctx.config.public_only === true && author?.protected !== false)
|
|
1818
|
+
continue;
|
|
1819
|
+
tweet.authorDisplayName = author?.name;
|
|
1820
|
+
tweet.urls = record.entities?.urls;
|
|
1821
|
+
const event = tweetToEvent(tweet);
|
|
1822
|
+
rows.push({
|
|
1823
|
+
...event,
|
|
1824
|
+
metadata: {
|
|
1825
|
+
...event.metadata,
|
|
1826
|
+
author_protected: author?.protected ?? null,
|
|
1827
|
+
},
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
return {
|
|
1831
|
+
rows,
|
|
1832
|
+
nextCursor: page.meta?.next_token,
|
|
1833
|
+
hasMore: Boolean(page.meta?.next_token),
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1732
1837
|
async function resolveAccountHandle(
|
|
1733
1838
|
config: Record<string, unknown>,
|
|
1734
1839
|
http?: HttpClient,
|
|
@@ -1887,7 +1992,7 @@ async function syncViaExtension(args: {
|
|
|
1887
1992
|
const { ctx, url, interceptPatterns, parseResponse, maxScrolls, checkpoint } =
|
|
1888
1993
|
args;
|
|
1889
1994
|
const result = await extensionNetworkSync<XTweet>({
|
|
1890
|
-
dispatcher:
|
|
1995
|
+
dispatcher: requireXBrowser(ctx),
|
|
1891
1996
|
config: {
|
|
1892
1997
|
interceptPatterns,
|
|
1893
1998
|
allowedOrigins: X_ALLOWED_ORIGINS,
|
|
@@ -2007,7 +2112,7 @@ async function syncLikedTweetsViaExtension(
|
|
|
2007
2112
|
): Promise<XSyncPage> {
|
|
2008
2113
|
const accountHandle = await resolveAccountHandle(config);
|
|
2009
2114
|
const likesUrl = `https://x.com/${encodeURIComponent(accountHandle)}/likes`;
|
|
2010
|
-
const dispatcher =
|
|
2115
|
+
const dispatcher = requireXBrowser(ctx);
|
|
2011
2116
|
const previouslyComplete = checkpoint.likes_backfill_status === "complete";
|
|
2012
2117
|
const pageBudget = previouslyComplete
|
|
2013
2118
|
? readLikesIncrementalPageBudget(config)
|
|
@@ -2061,15 +2166,15 @@ async function syncLikedTweetsViaExtension(
|
|
|
2061
2166
|
url: likesUrl,
|
|
2062
2167
|
parseResponse,
|
|
2063
2168
|
checkAuth: (currentUrl) => !isXAuthWall(currentUrl),
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2169
|
+
triggerNextPage: async (_tabId, browserDispatcher, sessionId) => {
|
|
2170
|
+
let requestUrl: string | undefined;
|
|
2171
|
+
try {
|
|
2172
|
+
requestUrl = pages.prepareReplay();
|
|
2173
|
+
} catch {
|
|
2174
|
+
parserErrors.push("X likes cursor rewrite failed");
|
|
2175
|
+
return;
|
|
2176
|
+
}
|
|
2177
|
+
if (!requestUrl) return;
|
|
2073
2178
|
let observation: { ok?: boolean; status?: number };
|
|
2074
2179
|
try {
|
|
2075
2180
|
observation = await browserDispatcher.dispatch<{
|
|
@@ -2236,11 +2341,16 @@ async function syncBookmarksViaOAuthApi(
|
|
|
2236
2341
|
maxPages,
|
|
2237
2342
|
);
|
|
2238
2343
|
|
|
2239
|
-
return finalizeSyncResult(
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2344
|
+
return finalizeSyncResult(
|
|
2345
|
+
tweets,
|
|
2346
|
+
checkpoint,
|
|
2347
|
+
{
|
|
2348
|
+
backend: "oauth_api",
|
|
2349
|
+
api_calls: pageCount,
|
|
2350
|
+
feed: "bookmarks",
|
|
2351
|
+
},
|
|
2352
|
+
{ originType: "bookmark" },
|
|
2353
|
+
);
|
|
2244
2354
|
}
|
|
2245
2355
|
|
|
2246
2356
|
async function syncBookmarksViaExtension(
|
|
@@ -2270,14 +2380,10 @@ function parseApiDmListResponse(
|
|
|
2270
2380
|
const usernameById = new Map(
|
|
2271
2381
|
users.map((user) => [user.id, user.username ?? ""]),
|
|
2272
2382
|
);
|
|
2273
|
-
const nameById = new Map(
|
|
2274
|
-
users.map((user) => [user.id, user.name ?? ""]),
|
|
2275
|
-
);
|
|
2383
|
+
const nameById = new Map(users.map((user) => [user.id, user.name ?? ""]));
|
|
2276
2384
|
|
|
2277
2385
|
return (json.data ?? [])
|
|
2278
|
-
.map((event) =>
|
|
2279
|
-
buildDmMessage(event, authUserId, usernameById, nameById),
|
|
2280
|
-
)
|
|
2386
|
+
.map((event) => buildDmMessage(event, authUserId, usernameById, nameById))
|
|
2281
2387
|
.filter((message): message is XDmMessage => message !== null);
|
|
2282
2388
|
}
|
|
2283
2389
|
|
|
@@ -2347,7 +2453,7 @@ async function syncDirectMessagesViaExtension(
|
|
|
2347
2453
|
: "";
|
|
2348
2454
|
|
|
2349
2455
|
const result = await extensionNetworkSync<XDmMessage>({
|
|
2350
|
-
dispatcher:
|
|
2456
|
+
dispatcher: requireXBrowser(ctx),
|
|
2351
2457
|
config: {
|
|
2352
2458
|
interceptPatterns: [
|
|
2353
2459
|
{ regex: "/i/api/graphql/\\w+/.*DM" },
|
|
@@ -2388,7 +2494,7 @@ async function syncHomeFeedViaDomScrape(
|
|
|
2388
2494
|
): Promise<XSyncPage> {
|
|
2389
2495
|
const maxScrolls = readScrollBudget(config, { defaultMax: 10, cap: 30 });
|
|
2390
2496
|
const { items: rows, loggedIn } = await extensionDomScrape<HomeFeedRow>({
|
|
2391
|
-
dispatcher:
|
|
2497
|
+
dispatcher: requireXBrowser(ctx),
|
|
2392
2498
|
url: "https://x.com/home",
|
|
2393
2499
|
config: {
|
|
2394
2500
|
...HOME_FEED_SCRAPE_CONFIG,
|
|
@@ -2420,7 +2526,7 @@ const backendPreferenceProperties = {
|
|
|
2420
2526
|
type: "boolean",
|
|
2421
2527
|
default: false,
|
|
2422
2528
|
description:
|
|
2423
|
-
"
|
|
2529
|
+
"Use the paired Chrome browser. Requires a separate X connection authenticated with the browser method.",
|
|
2424
2530
|
},
|
|
2425
2531
|
use_oauth: {
|
|
2426
2532
|
type: "boolean",
|
|
@@ -2612,16 +2718,16 @@ const dmMetadataSchema = {
|
|
|
2612
2718
|
// type it, so this drives the paired Owletto Chrome and stops before submit.
|
|
2613
2719
|
|
|
2614
2720
|
/** Cap the explanation shown in the in-page banner. Mirrors linkedin. */
|
|
2615
|
-
export
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2721
|
+
export const truncateHandoffReason = truncateSharedHandoffReason;
|
|
2722
|
+
|
|
2723
|
+
const X_HANDOFF_TITLE = "Lobu staged this reply";
|
|
2724
|
+
const X_HANDOFF_INSTRUCTION =
|
|
2725
|
+
"Review the draft and click Reply yourself — Lobu did not submit.";
|
|
2726
|
+
const X_HANDOFF_COMPOSER_SELECTORS = [
|
|
2727
|
+
'[data-testid="tweetTextarea_0"]',
|
|
2728
|
+
'div[role="textbox"][contenteditable="true"]',
|
|
2729
|
+
];
|
|
2730
|
+
const X_HANDOFF_HOST_SELECTORS = ["form"];
|
|
2625
2731
|
|
|
2626
2732
|
/**
|
|
2627
2733
|
* JS expression: inject a small Lobu handoff banner above X's reply composer,
|
|
@@ -2639,113 +2745,13 @@ export function truncateHandoffReason(
|
|
|
2639
2745
|
export function buildInjectHandoffBannerExpression(opts: {
|
|
2640
2746
|
reason?: string;
|
|
2641
2747
|
}): string {
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
try {
|
|
2650
|
-
const prev = document.getElementById(ID);
|
|
2651
|
-
if (prev) prev.remove();
|
|
2652
|
-
} catch (_) {}
|
|
2653
|
-
|
|
2654
|
-
const root = document.createElement('div');
|
|
2655
|
-
root.id = ID;
|
|
2656
|
-
root.setAttribute('role', 'status');
|
|
2657
|
-
root.setAttribute('data-lobu', 'handoff-banner');
|
|
2658
|
-
root.style.cssText = [
|
|
2659
|
-
'position:fixed',
|
|
2660
|
-
'top:12px',
|
|
2661
|
-
'left:50%',
|
|
2662
|
-
'transform:translateX(-50%)',
|
|
2663
|
-
'z-index:2147483646',
|
|
2664
|
-
'max-width:min(520px,calc(100vw - 24px))',
|
|
2665
|
-
'font:13px/1.4 -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif',
|
|
2666
|
-
'color:#0f172a',
|
|
2667
|
-
'background:#fff',
|
|
2668
|
-
'border:1px solid #cbd5e1',
|
|
2669
|
-
'border-left:4px solid #0ea5e9',
|
|
2670
|
-
'border-radius:10px',
|
|
2671
|
-
'box-shadow:0 8px 28px rgba(15,23,42,.18)',
|
|
2672
|
-
'padding:10px 12px',
|
|
2673
|
-
'display:flex',
|
|
2674
|
-
'gap:10px',
|
|
2675
|
-
'align-items:flex-start',
|
|
2676
|
-
'pointer-events:auto',
|
|
2677
|
-
].join(';');
|
|
2678
|
-
|
|
2679
|
-
const body = document.createElement('div');
|
|
2680
|
-
body.style.cssText = 'flex:1;min-width:0';
|
|
2681
|
-
|
|
2682
|
-
const head = document.createElement('div');
|
|
2683
|
-
head.style.cssText = 'font-weight:600;margin:0 0 2px;color:#0c4a6e';
|
|
2684
|
-
head.textContent = TITLE;
|
|
2685
|
-
|
|
2686
|
-
const line = document.createElement('div');
|
|
2687
|
-
line.style.cssText = 'color:#334155;margin:0 0 2px';
|
|
2688
|
-
line.textContent = 'Review the draft and click Reply yourself — Lobu did not submit.';
|
|
2689
|
-
|
|
2690
|
-
body.appendChild(head);
|
|
2691
|
-
body.appendChild(line);
|
|
2692
|
-
|
|
2693
|
-
if (REASON) {
|
|
2694
|
-
const why = document.createElement('div');
|
|
2695
|
-
why.style.cssText = 'color:#64748b;margin:4px 0 0;font-size:12px';
|
|
2696
|
-
why.textContent = 'Why: ' + REASON;
|
|
2697
|
-
body.appendChild(why);
|
|
2698
|
-
}
|
|
2699
|
-
|
|
2700
|
-
const close = document.createElement('button');
|
|
2701
|
-
close.type = 'button';
|
|
2702
|
-
close.setAttribute('aria-label', 'Dismiss');
|
|
2703
|
-
close.textContent = '\\u00d7';
|
|
2704
|
-
close.style.cssText = [
|
|
2705
|
-
'flex:none',
|
|
2706
|
-
'border:0',
|
|
2707
|
-
'background:transparent',
|
|
2708
|
-
'color:#64748b',
|
|
2709
|
-
'font:20px/1 sans-serif',
|
|
2710
|
-
'cursor:pointer',
|
|
2711
|
-
'padding:0 2px',
|
|
2712
|
-
].join(';');
|
|
2713
|
-
close.onclick = function () { try { root.remove(); } catch (_) {} };
|
|
2714
|
-
|
|
2715
|
-
root.appendChild(body);
|
|
2716
|
-
root.appendChild(close);
|
|
2717
|
-
|
|
2718
|
-
// Anchor above the reply composer when we can find it, so the reason sits
|
|
2719
|
-
// next to the draft instead of floating over unrelated timeline content.
|
|
2720
|
-
let anchored = false;
|
|
2721
|
-
try {
|
|
2722
|
-
const composer =
|
|
2723
|
-
document.querySelector('[data-testid="tweetTextarea_0"]') ||
|
|
2724
|
-
document.querySelector('div[role="textbox"][contenteditable="true"]');
|
|
2725
|
-
if (composer) {
|
|
2726
|
-
const host = composer.closest('form') || composer.parentElement;
|
|
2727
|
-
if (host && host.parentElement) {
|
|
2728
|
-
root.style.position = 'relative';
|
|
2729
|
-
root.style.top = '0';
|
|
2730
|
-
root.style.left = '0';
|
|
2731
|
-
root.style.transform = 'none';
|
|
2732
|
-
root.style.margin = '8px 0 12px';
|
|
2733
|
-
root.style.maxWidth = '100%';
|
|
2734
|
-
host.parentElement.insertBefore(root, host);
|
|
2735
|
-
anchored = true;
|
|
2736
|
-
}
|
|
2737
|
-
}
|
|
2738
|
-
} catch (_) {}
|
|
2739
|
-
|
|
2740
|
-
if (!anchored) {
|
|
2741
|
-
(document.body || document.documentElement).appendChild(root);
|
|
2742
|
-
}
|
|
2743
|
-
|
|
2744
|
-
// No auto-dismiss: the draft lives in the user's page, so its context should
|
|
2745
|
-
// still be present when the user returns later. The dismiss button remains.
|
|
2746
|
-
|
|
2747
|
-
return { ok: true, anchored: anchored };
|
|
2748
|
-
})()`;
|
|
2748
|
+
return buildSharedHandoffBannerExpression({
|
|
2749
|
+
reason: opts.reason,
|
|
2750
|
+
title: X_HANDOFF_TITLE,
|
|
2751
|
+
instruction: X_HANDOFF_INSTRUCTION,
|
|
2752
|
+
composerSelectors: X_HANDOFF_COMPOSER_SELECTORS,
|
|
2753
|
+
hostSelectors: X_HANDOFF_HOST_SELECTORS,
|
|
2754
|
+
});
|
|
2749
2755
|
}
|
|
2750
2756
|
|
|
2751
2757
|
export interface PrepareReplyResult {
|
|
@@ -3085,6 +3091,146 @@ export async function prepareXReply(
|
|
|
3085
3091
|
};
|
|
3086
3092
|
}
|
|
3087
3093
|
|
|
3094
|
+
// ── Live DMs (browser source program) ─────────────────────────
|
|
3095
|
+
|
|
3096
|
+
/**
|
|
3097
|
+
* A neutral signed-in route for the live DM program. Opening /messages marks
|
|
3098
|
+
* conversations read, so the program calls the DM endpoints from here instead.
|
|
3099
|
+
*/
|
|
3100
|
+
const X_LIVE_MESSAGES_TAB_URL = "https://x.com/home";
|
|
3101
|
+
|
|
3102
|
+
const X_LIVE_MESSAGE_COLUMNS = [
|
|
3103
|
+
{ name: "id", type: "string" },
|
|
3104
|
+
{ name: "message_id", type: "string" },
|
|
3105
|
+
{ name: "conversation_id", type: "string" },
|
|
3106
|
+
{ name: "conversation_name", type: "string" },
|
|
3107
|
+
{ name: "sender_id", type: "string" },
|
|
3108
|
+
{ name: "sender_handle", type: "string" },
|
|
3109
|
+
{ name: "sender_name", type: "string" },
|
|
3110
|
+
{ name: "from_me", type: "boolean" },
|
|
3111
|
+
{ name: "is_group", type: "boolean" },
|
|
3112
|
+
{ name: "is_request", type: "boolean" },
|
|
3113
|
+
{ name: "text", type: "string" },
|
|
3114
|
+
{ name: "content_kind", type: "string" },
|
|
3115
|
+
{ name: "occurred_at", type: "string" },
|
|
3116
|
+
];
|
|
3117
|
+
|
|
3118
|
+
/** Keep data inert in generated page code, including an HTML script context. */
|
|
3119
|
+
function xScriptArgument(value: unknown): string {
|
|
3120
|
+
const literal = JSON.stringify(JSON.stringify(value)).replace(
|
|
3121
|
+
/[<>\u2028\u2029]/g,
|
|
3122
|
+
(char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`,
|
|
3123
|
+
);
|
|
3124
|
+
return `JSON.parse(${literal})`;
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
async function readyXLiveTab(
|
|
3128
|
+
dispatcher: ChromeActionDispatcher,
|
|
3129
|
+
): Promise<number> {
|
|
3130
|
+
const nav = await dispatcher.dispatch<{
|
|
3131
|
+
tab_id?: number;
|
|
3132
|
+
current_url?: string;
|
|
3133
|
+
}>("navigate", {
|
|
3134
|
+
url: X_LIVE_MESSAGES_TAB_URL,
|
|
3135
|
+
persistent: true,
|
|
3136
|
+
wait_for_load: true,
|
|
3137
|
+
});
|
|
3138
|
+
if (isXAuthWall(nav.current_url)) {
|
|
3139
|
+
throw new Error(
|
|
3140
|
+
"X is not signed in on the paired Chrome. Sign in at https://x.com, then retry.",
|
|
3141
|
+
);
|
|
3142
|
+
}
|
|
3143
|
+
if (typeof nav.tab_id !== "number") {
|
|
3144
|
+
throw new Error("Chrome did not return an X tab id");
|
|
3145
|
+
}
|
|
3146
|
+
return nav.tab_id;
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
/** One call into the page program, installing it first when absent or stale. */
|
|
3150
|
+
async function invokeXDirectMessages<T>(
|
|
3151
|
+
dispatcher: ChromeActionDispatcher,
|
|
3152
|
+
tabId: number,
|
|
3153
|
+
op: "read" | "listen" | "send",
|
|
3154
|
+
input: Record<string, unknown>,
|
|
3155
|
+
): Promise<T> {
|
|
3156
|
+
const result = await dispatcher.dispatch<{
|
|
3157
|
+
value?: T;
|
|
3158
|
+
exception?: { description?: string } | unknown;
|
|
3159
|
+
}>("evaluate", {
|
|
3160
|
+
tab_id: tabId,
|
|
3161
|
+
expression: `(() => { (${xDirectMessagesProgram.toString()})(); return globalThis.__lobuXDirectMessagesV1.${op}(${xScriptArgument(input)}); })()`,
|
|
3162
|
+
await_promise: true,
|
|
3163
|
+
});
|
|
3164
|
+
if (result.exception || !result.value) {
|
|
3165
|
+
const description = (
|
|
3166
|
+
result.exception as { description?: unknown } | undefined
|
|
3167
|
+
)?.description;
|
|
3168
|
+
throw new Error(
|
|
3169
|
+
typeof description === "string"
|
|
3170
|
+
? description.split("\n")[0]
|
|
3171
|
+
: `X direct messages ${op} failed: ${JSON.stringify(result.exception ?? "empty response")}`,
|
|
3172
|
+
);
|
|
3173
|
+
}
|
|
3174
|
+
return result.value;
|
|
3175
|
+
}
|
|
3176
|
+
|
|
3177
|
+
async function readXLiveMessages(
|
|
3178
|
+
ctx: FeedReadContext,
|
|
3179
|
+
): Promise<FeedReadResult> {
|
|
3180
|
+
const message =
|
|
3181
|
+
"X live messages read the recent inbox in source order with the returned cursor, or one message by id:<message id>; search, offsets, sorting, matching, and time windows are unsupported";
|
|
3182
|
+
assertNoOffsetPaging(ctx, message);
|
|
3183
|
+
assertNoSort(ctx, message);
|
|
3184
|
+
assertNoWindow(ctx, message);
|
|
3185
|
+
assertNoMatch(ctx, message);
|
|
3186
|
+
const dispatcher = requireXBrowser(ctx);
|
|
3187
|
+
const tabId = await readyXLiveTab(dispatcher);
|
|
3188
|
+
const page = await invokeXDirectMessages<{
|
|
3189
|
+
rows: Array<Record<string, unknown>>;
|
|
3190
|
+
nextCursor?: string;
|
|
3191
|
+
hasMore: boolean;
|
|
3192
|
+
}>(dispatcher, tabId, "read", {
|
|
3193
|
+
query: ctx.query,
|
|
3194
|
+
cursor: ctx.cursor,
|
|
3195
|
+
limit: ctx.limit,
|
|
3196
|
+
});
|
|
3197
|
+
return {
|
|
3198
|
+
rows: page.rows,
|
|
3199
|
+
columns: X_LIVE_MESSAGE_COLUMNS,
|
|
3200
|
+
...(page.nextCursor ? { nextCursor: page.nextCursor } : {}),
|
|
3201
|
+
hasMore: page.hasMore,
|
|
3202
|
+
};
|
|
3203
|
+
}
|
|
3204
|
+
|
|
3205
|
+
/**
|
|
3206
|
+
* Attach the page program's listener. It checks for new DMs once a minute
|
|
3207
|
+
* while the browser is online and publishes `message.created` references
|
|
3208
|
+
* through the bridge; the checkpoint is X's own inbox update cursor.
|
|
3209
|
+
*/
|
|
3210
|
+
async function observeXLiveMessages(ctx: FeedObserveContext): Promise<void> {
|
|
3211
|
+
const dispatcher = requireXBrowser(ctx);
|
|
3212
|
+
const tabId = await readyXLiveTab(dispatcher);
|
|
3213
|
+
const binding = await dispatcher.dispatch<{
|
|
3214
|
+
bridge_id?: string;
|
|
3215
|
+
token?: string;
|
|
3216
|
+
listening?: boolean;
|
|
3217
|
+
subscription?: { scope_key: string };
|
|
3218
|
+
}>("feed_listen", { tab_id: tabId });
|
|
3219
|
+
if (
|
|
3220
|
+
!binding.bridge_id ||
|
|
3221
|
+
!binding.token ||
|
|
3222
|
+
!binding.subscription ||
|
|
3223
|
+
binding.listening === false
|
|
3224
|
+
) {
|
|
3225
|
+
throw new Error("The paired browser must support source subscriptions");
|
|
3226
|
+
}
|
|
3227
|
+
await invokeXDirectMessages(dispatcher, tabId, "listen", {
|
|
3228
|
+
checkpoint: ctx.checkpoint ?? null,
|
|
3229
|
+
bridge_id: binding.bridge_id,
|
|
3230
|
+
token: binding.token,
|
|
3231
|
+
});
|
|
3232
|
+
}
|
|
3233
|
+
|
|
3088
3234
|
// ── Connector ──────────────────────────────────────────────────
|
|
3089
3235
|
|
|
3090
3236
|
export default class XConnector extends ConnectorRuntime {
|
|
@@ -3092,9 +3238,28 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3092
3238
|
key: "x",
|
|
3093
3239
|
name: "X (Twitter)",
|
|
3094
3240
|
description:
|
|
3095
|
-
"Fetches tweets, browser-visible like history, bookmarks, and DMs through the X API v2 or the paired Owletto Chrome extension. Links social actors into the person graph.",
|
|
3096
|
-
version: "3.
|
|
3241
|
+
"Fetches tweets, browser-visible like history, bookmarks, and DMs through the X API v2 or the paired Owletto Chrome extension, reads the chronological Following timeline live through the X API, and reads and answers DMs live in the paired browser. Links social actors into the person graph.",
|
|
3242
|
+
version: "3.15.0",
|
|
3097
3243
|
faviconDomain: "x.com",
|
|
3244
|
+
browser: {
|
|
3245
|
+
origins: ["https://x.com", "https://twitter.com"],
|
|
3246
|
+
authMethods: ["browser"],
|
|
3247
|
+
accountProbe: {
|
|
3248
|
+
url: "https://x.com/home",
|
|
3249
|
+
// twid is the signed-in user id, not a bearer credential or mutable handle.
|
|
3250
|
+
expression: `(async () => {
|
|
3251
|
+
for (let i = 0; i < 40; i++) {
|
|
3252
|
+
const profile = document.querySelector('[data-testid=AppTabBar_Profile_Link]');
|
|
3253
|
+
const raw = document.cookie.split('; ').find(cookie => cookie.startsWith('twid='));
|
|
3254
|
+
const identity = raw ? decodeURIComponent(raw.slice(5)) : '';
|
|
3255
|
+
if (profile && /^u=[0-9]+$/.test(identity)) return { accountId: identity.slice(2) };
|
|
3256
|
+
if (/login|signup|account\\/access/.test(location.pathname)) return null;
|
|
3257
|
+
await new Promise(resolve => setTimeout(resolve, 250));
|
|
3258
|
+
}
|
|
3259
|
+
return null;
|
|
3260
|
+
})()`,
|
|
3261
|
+
},
|
|
3262
|
+
},
|
|
3098
3263
|
authSchema: {
|
|
3099
3264
|
methods: [
|
|
3100
3265
|
{
|
|
@@ -3108,18 +3273,13 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3108
3273
|
"bookmark.read",
|
|
3109
3274
|
"dm.read",
|
|
3110
3275
|
],
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
"tweet.read",
|
|
3114
|
-
"like.read",
|
|
3115
|
-
"bookmark.read",
|
|
3116
|
-
"dm.read",
|
|
3117
|
-
"offline.access",
|
|
3118
|
-
"users.email",
|
|
3119
|
-
],
|
|
3276
|
+
// X requires tweet.read for /2/users/me, even for identity-only login.
|
|
3277
|
+
loginScopes: ["users.read", "tweet.read", "users.email"],
|
|
3120
3278
|
authorizationUrl: "https://x.com/i/oauth2/authorize",
|
|
3121
3279
|
tokenUrl: "https://api.x.com/2/oauth2/token",
|
|
3122
|
-
userinfoUrl:
|
|
3280
|
+
// No userinfoUrl: declaring one routes sign-in through generic OIDC,
|
|
3281
|
+
// which cannot read X's nested profile. Connect gets it from the
|
|
3282
|
+
// server's built-in twitter provider config instead.
|
|
3123
3283
|
tokenEndpointAuthMethod: "client_secret_basic",
|
|
3124
3284
|
usePkce: true,
|
|
3125
3285
|
clientIdKey: "TWITTER_CLIENT_ID",
|
|
@@ -3129,16 +3289,85 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3129
3289
|
setupInstructions:
|
|
3130
3290
|
"Create an X OAuth 2.0 app, add {{redirect_uri}} as the callback URL, then paste the client ID and client secret below.",
|
|
3131
3291
|
loginProvisioning: {
|
|
3132
|
-
autoCreateConnection:
|
|
3292
|
+
autoCreateConnection: false,
|
|
3133
3293
|
},
|
|
3134
3294
|
},
|
|
3135
3295
|
{
|
|
3136
|
-
type: "
|
|
3137
|
-
|
|
3296
|
+
type: "browser",
|
|
3297
|
+
mode: "live",
|
|
3138
3298
|
},
|
|
3139
3299
|
],
|
|
3140
3300
|
},
|
|
3301
|
+
// Declaring automationEvents replaces the eventKinds-derived catalog, so
|
|
3302
|
+
// every kind the sync feeds emit is listed alongside the live DM event.
|
|
3303
|
+
automationEvents: [
|
|
3304
|
+
{
|
|
3305
|
+
key: "message.created",
|
|
3306
|
+
label: "New DM",
|
|
3307
|
+
resourceType: "message",
|
|
3308
|
+
description:
|
|
3309
|
+
"A new X direct message reference from the paired browser. The Automation reads its content from the live messages feed, or replies in the conversation it came from.",
|
|
3310
|
+
filterSchema: {
|
|
3311
|
+
type: "object",
|
|
3312
|
+
properties: {
|
|
3313
|
+
channel_id: {
|
|
3314
|
+
type: "string",
|
|
3315
|
+
title: "Conversation",
|
|
3316
|
+
description: "X DM conversation ID.",
|
|
3317
|
+
},
|
|
3318
|
+
},
|
|
3319
|
+
},
|
|
3320
|
+
capabilities: { replyToSource: true },
|
|
3321
|
+
},
|
|
3322
|
+
{ key: "tweet", label: "Tweet" },
|
|
3323
|
+
{ key: "reply", label: "Reply" },
|
|
3324
|
+
{ key: "liked_tweet", label: "Liked Tweet" },
|
|
3325
|
+
{ key: "bookmark", label: "Bookmark" },
|
|
3326
|
+
{ key: "dm_message", label: "DM Message" },
|
|
3327
|
+
],
|
|
3141
3328
|
feeds: {
|
|
3329
|
+
live_messages: {
|
|
3330
|
+
key: "live_messages",
|
|
3331
|
+
name: "Live messages",
|
|
3332
|
+
description:
|
|
3333
|
+
"Read recent X direct messages live from the paired browser without importing history or marking them read, page by the returned cursor, or read one message by id:<message id>. Message requests from accounts the user does not follow are included and marked is_request. Active Automations subscribe to new-message references; the browser checks once a minute while it is online and resumes from X's inbox update cursor after reconnecting. Requires a browser-authenticated X connection.",
|
|
3334
|
+
read: readXLiveMessages,
|
|
3335
|
+
observe: observeXLiveMessages,
|
|
3336
|
+
webhook: { mode: "trigger", events: ["message.created"] },
|
|
3337
|
+
},
|
|
3338
|
+
following_timeline: {
|
|
3339
|
+
key: "following_timeline",
|
|
3340
|
+
name: "Following Timeline (live)",
|
|
3341
|
+
description:
|
|
3342
|
+
"Read the authenticated account's chronological Following timeline through the X API without importing tweet events. Bounded by X's available recent history; does not provide window coverage or the algorithmic For You feed.",
|
|
3343
|
+
read: readFollowingTimeline,
|
|
3344
|
+
configSchema: {
|
|
3345
|
+
type: "object",
|
|
3346
|
+
additionalProperties: false,
|
|
3347
|
+
properties: {
|
|
3348
|
+
expected_account_handle: {
|
|
3349
|
+
type: "string",
|
|
3350
|
+
pattern: "^@?[A-Za-z0-9_]{1,15}$",
|
|
3351
|
+
description:
|
|
3352
|
+
"Optional account identity check. Reject reads when the authorized account has a different handle.",
|
|
3353
|
+
},
|
|
3354
|
+
public_only: {
|
|
3355
|
+
type: "boolean",
|
|
3356
|
+
default: false,
|
|
3357
|
+
description:
|
|
3358
|
+
"Return only posts whose expanded author is explicitly public. Protected or unknown authors are excluded; pagination is preserved.",
|
|
3359
|
+
},
|
|
3360
|
+
},
|
|
3361
|
+
},
|
|
3362
|
+
eventKinds: {
|
|
3363
|
+
tweet: {
|
|
3364
|
+
description: "A source-owned post from the Following timeline",
|
|
3365
|
+
},
|
|
3366
|
+
reply: {
|
|
3367
|
+
description: "A source-owned reply from the Following timeline",
|
|
3368
|
+
},
|
|
3369
|
+
},
|
|
3370
|
+
},
|
|
3142
3371
|
tweets: {
|
|
3143
3372
|
key: "tweets",
|
|
3144
3373
|
name: "Tweets",
|
|
@@ -3164,7 +3393,7 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3164
3393
|
name: "My Posts",
|
|
3165
3394
|
sync: (ctx) => this.syncFeed(ctx),
|
|
3166
3395
|
description:
|
|
3167
|
-
"Posts and replies authored by the connected account.
|
|
3396
|
+
"Posts and replies authored by the connected account. OAuth connections use the X API; browser-authenticated connections use the paired Chrome extension.",
|
|
3168
3397
|
configSchema: accountTimelineConfigSchema,
|
|
3169
3398
|
eventKinds: {
|
|
3170
3399
|
tweet: {
|
|
@@ -3184,7 +3413,7 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3184
3413
|
name: "Liked Posts",
|
|
3185
3414
|
sync: (ctx) => this.syncFeed(ctx),
|
|
3186
3415
|
description:
|
|
3187
|
-
"Posts the connected account has liked. OAuth
|
|
3416
|
+
"Posts the connected account has liked. OAuth connections use the X API; browser-authenticated connections use the paired Chrome extension for resumable cursor backfill and incremental collection.",
|
|
3188
3417
|
configSchema: likedTweetsConfigSchema,
|
|
3189
3418
|
eventKinds: {
|
|
3190
3419
|
liked_tweet: {
|
|
@@ -3199,7 +3428,7 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3199
3428
|
name: "Bookmarks",
|
|
3200
3429
|
sync: (ctx) => this.syncFeed(ctx),
|
|
3201
3430
|
description:
|
|
3202
|
-
"Posts bookmarked by the connected account.
|
|
3431
|
+
"Posts bookmarked by the connected account. OAuth connections use the X API; browser-authenticated connections use the paired Chrome extension.",
|
|
3203
3432
|
configSchema: bookmarksConfigSchema,
|
|
3204
3433
|
eventKinds: {
|
|
3205
3434
|
bookmark: {
|
|
@@ -3214,7 +3443,7 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3214
3443
|
name: "Direct Messages",
|
|
3215
3444
|
sync: (ctx) => this.syncFeed(ctx),
|
|
3216
3445
|
description:
|
|
3217
|
-
"Direct message events across all conversations.
|
|
3446
|
+
"Direct message events across all conversations. OAuth connections use the X API and require dm.read; browser-authenticated connections use the paired Chrome extension on /messages. Auto-creates person entities for 1:1 counterparts.",
|
|
3218
3447
|
configSchema: bookmarksConfigSchema,
|
|
3219
3448
|
eventKinds: {
|
|
3220
3449
|
dm_message: {
|
|
@@ -3229,7 +3458,7 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3229
3458
|
name: "Home Timeline",
|
|
3230
3459
|
sync: (ctx) => this.syncFeed(ctx),
|
|
3231
3460
|
description:
|
|
3232
|
-
"Your personalized x.com home timeline (For you + Following).
|
|
3461
|
+
"Your personalized x.com home timeline (For you + Following). Requires a separate X connection authenticated through your paired Chrome browser. Use following_timeline for source-only chronological reads through the official API.",
|
|
3233
3462
|
configSchema: homeFeedConfigSchema,
|
|
3234
3463
|
eventKinds: {
|
|
3235
3464
|
tweet: {
|
|
@@ -3241,12 +3470,56 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3241
3470
|
},
|
|
3242
3471
|
},
|
|
3243
3472
|
actions: {
|
|
3473
|
+
send_message: {
|
|
3474
|
+
key: "send_message",
|
|
3475
|
+
kind: "write",
|
|
3476
|
+
name: "Send DM reply",
|
|
3477
|
+
description:
|
|
3478
|
+
"Requires an X connection authenticated through your paired Chrome browser. Send a text reply into an exact existing X direct message conversation and confirm it appears there. This direct send is approved only for answering DMs on bot accounts the owner operates; public replies and posts stay draft-only through prepare_reply. On retry, reuse both this input's idempotency_key and the enclosing operations.execute idempotency_key. The browser can recognise an earlier send only while its request ID is on the latest conversation page; matching recent text without a request ID is refused.",
|
|
3479
|
+
annotations: {
|
|
3480
|
+
destructiveHint: false,
|
|
3481
|
+
idempotentHint: false,
|
|
3482
|
+
openWorldHint: true,
|
|
3483
|
+
},
|
|
3484
|
+
inputSchema: {
|
|
3485
|
+
type: "object",
|
|
3486
|
+
required: ["conversation_id", "text", "idempotency_key"],
|
|
3487
|
+
additionalProperties: false,
|
|
3488
|
+
properties: {
|
|
3489
|
+
conversation_id: {
|
|
3490
|
+
type: "string",
|
|
3491
|
+
pattern: "^[0-9]{1,20}(-[0-9]{1,20})?$",
|
|
3492
|
+
description:
|
|
3493
|
+
"Exact X DM conversation ID, the conversation_id of a live_messages row.",
|
|
3494
|
+
},
|
|
3495
|
+
text: { type: "string", minLength: 1, maxLength: 10000 },
|
|
3496
|
+
idempotency_key: {
|
|
3497
|
+
type: "string",
|
|
3498
|
+
minLength: 1,
|
|
3499
|
+
maxLength: 200,
|
|
3500
|
+
description:
|
|
3501
|
+
"Stable key used to derive X's client request ID. Reuse it and the enclosing operation's idempotency_key on retry; browser deduplication only checks the latest conversation page.",
|
|
3502
|
+
},
|
|
3503
|
+
},
|
|
3504
|
+
},
|
|
3505
|
+
outputSchema: {
|
|
3506
|
+
type: "object",
|
|
3507
|
+
properties: {
|
|
3508
|
+
sent: { type: "boolean" },
|
|
3509
|
+
deduplicated: { type: "boolean" },
|
|
3510
|
+
id: { type: "string" },
|
|
3511
|
+
message_id: { type: "string" },
|
|
3512
|
+
conversation_id: { type: "string" },
|
|
3513
|
+
occurred_at: { type: "string" },
|
|
3514
|
+
},
|
|
3515
|
+
},
|
|
3516
|
+
},
|
|
3244
3517
|
prepare_reply: {
|
|
3245
3518
|
key: "prepare_reply",
|
|
3246
3519
|
kind: "write",
|
|
3247
3520
|
name: "Prepare reply",
|
|
3248
3521
|
description:
|
|
3249
|
-
"Stage a reply draft after the user opens the exact X post (fill the reply composer). NEVER opens a tab or submits — the human must click Reply. No auto-post path exists.",
|
|
3522
|
+
"Requires an X connection authenticated through your paired Chrome browser. Stage a reply draft after the user opens the exact X post (fill the reply composer). NEVER opens a tab or submits — the human must click Reply. No auto-post path exists.",
|
|
3250
3523
|
annotations: {
|
|
3251
3524
|
destructiveHint: false,
|
|
3252
3525
|
idempotentHint: false,
|
|
@@ -3310,6 +3583,21 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3310
3583
|
|
|
3311
3584
|
async execute(ctx: ActionContext): Promise<ActionResult> {
|
|
3312
3585
|
try {
|
|
3586
|
+
if (ctx.actionKey === "send_message") {
|
|
3587
|
+
const dispatcher = requireXBrowser(ctx);
|
|
3588
|
+
const tabId = await readyXLiveTab(dispatcher);
|
|
3589
|
+
const output = await invokeXDirectMessages<Record<string, unknown>>(
|
|
3590
|
+
dispatcher,
|
|
3591
|
+
tabId,
|
|
3592
|
+
"send",
|
|
3593
|
+
{
|
|
3594
|
+
conversation_id: ctx.input.conversation_id,
|
|
3595
|
+
text: ctx.input.text,
|
|
3596
|
+
idempotency_key: ctx.input.idempotency_key,
|
|
3597
|
+
},
|
|
3598
|
+
);
|
|
3599
|
+
return { success: true, output };
|
|
3600
|
+
}
|
|
3313
3601
|
if (ctx.actionKey !== "prepare_reply") {
|
|
3314
3602
|
return { success: false, error: `Unknown action: ${ctx.actionKey}` };
|
|
3315
3603
|
}
|
|
@@ -3326,7 +3614,7 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3326
3614
|
if (!tweetRef) {
|
|
3327
3615
|
return { success: false, error: "tweet_url or tweet_id is required" };
|
|
3328
3616
|
}
|
|
3329
|
-
const output = await prepareXReply(
|
|
3617
|
+
const output = await prepareXReply(requireXBrowser(ctx), {
|
|
3330
3618
|
tweetUrl: tweetRef,
|
|
3331
3619
|
body,
|
|
3332
3620
|
banner: ctx.input.banner !== false,
|
|
@@ -3344,11 +3632,14 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3344
3632
|
}
|
|
3345
3633
|
|
|
3346
3634
|
private async syncFeed(ctx: SyncContext): Promise<SyncResult> {
|
|
3347
|
-
//
|
|
3348
|
-
//
|
|
3635
|
+
// Collect before committing so an authorized browser fallback cannot
|
|
3636
|
+
// duplicate events gathered by a partially failed OAuth attempt.
|
|
3349
3637
|
const page = await this.collectFeed(ctx);
|
|
3350
3638
|
await ctx.commit(page.events, page.checkpoint);
|
|
3351
|
-
return {
|
|
3639
|
+
return {
|
|
3640
|
+
status: "complete",
|
|
3641
|
+
...(page.metadata ? { metadata: page.metadata } : {}),
|
|
3642
|
+
};
|
|
3352
3643
|
}
|
|
3353
3644
|
|
|
3354
3645
|
private async collectFeed(ctx: SyncContext): Promise<XSyncPage> {
|
|
@@ -3357,17 +3648,16 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3357
3648
|
const feedKey = ctx.feedKey ?? "tweets";
|
|
3358
3649
|
const oauthScopes = X_OAUTH_FEED_SCOPES[feedKey];
|
|
3359
3650
|
|
|
3360
|
-
//
|
|
3361
|
-
//
|
|
3651
|
+
// This feed reads the home page through the browser, regardless of
|
|
3652
|
+
// whether an OAuth token is present.
|
|
3362
3653
|
if (feedKey === "home_feed") {
|
|
3363
3654
|
return syncHomeFeedViaDomScrape(ctx, config, checkpoint);
|
|
3364
3655
|
}
|
|
3365
3656
|
|
|
3366
3657
|
if (feedKey === "my_tweets") {
|
|
3367
|
-
if (
|
|
3368
|
-
resolveSyncBackend(ctx, config, oauthScopes) === "oauth_api"
|
|
3369
|
-
) {
|
|
3658
|
+
if (resolveSyncBackend(ctx, config, oauthScopes) === "oauth_api") {
|
|
3370
3659
|
return syncOAuthWithOptionalFallback(
|
|
3660
|
+
ctx,
|
|
3371
3661
|
config,
|
|
3372
3662
|
() => syncMyTweetsViaOAuthApi(ctx, config, checkpoint),
|
|
3373
3663
|
() => syncMyTweetsViaExtension(ctx, config, checkpoint),
|
|
@@ -3377,10 +3667,9 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3377
3667
|
}
|
|
3378
3668
|
|
|
3379
3669
|
if (feedKey === "liked_tweets") {
|
|
3380
|
-
if (
|
|
3381
|
-
resolveSyncBackend(ctx, config, oauthScopes) === "oauth_api"
|
|
3382
|
-
) {
|
|
3670
|
+
if (resolveSyncBackend(ctx, config, oauthScopes) === "oauth_api") {
|
|
3383
3671
|
return syncOAuthWithOptionalFallback(
|
|
3672
|
+
ctx,
|
|
3384
3673
|
config,
|
|
3385
3674
|
() => syncLikedTweetsViaOAuthApi(ctx, config, checkpoint),
|
|
3386
3675
|
() => syncLikedTweetsViaExtension(ctx, config, checkpoint),
|
|
@@ -3390,10 +3679,9 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3390
3679
|
}
|
|
3391
3680
|
|
|
3392
3681
|
if (feedKey === "bookmarks") {
|
|
3393
|
-
if (
|
|
3394
|
-
resolveSyncBackend(ctx, config, oauthScopes) === "oauth_api"
|
|
3395
|
-
) {
|
|
3682
|
+
if (resolveSyncBackend(ctx, config, oauthScopes) === "oauth_api") {
|
|
3396
3683
|
return syncOAuthWithOptionalFallback(
|
|
3684
|
+
ctx,
|
|
3397
3685
|
config,
|
|
3398
3686
|
() => syncBookmarksViaOAuthApi(ctx, config, checkpoint),
|
|
3399
3687
|
() => syncBookmarksViaExtension(ctx, config, checkpoint),
|
|
@@ -3403,10 +3691,9 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3403
3691
|
}
|
|
3404
3692
|
|
|
3405
3693
|
if (feedKey === "direct_messages") {
|
|
3406
|
-
if (
|
|
3407
|
-
resolveSyncBackend(ctx, config, oauthScopes) === "oauth_api"
|
|
3408
|
-
) {
|
|
3694
|
+
if (resolveSyncBackend(ctx, config, oauthScopes) === "oauth_api") {
|
|
3409
3695
|
return syncOAuthWithOptionalFallback(
|
|
3696
|
+
ctx,
|
|
3410
3697
|
config,
|
|
3411
3698
|
() => syncDirectMessagesViaOAuthApi(ctx, config, checkpoint),
|
|
3412
3699
|
() => syncDirectMessagesViaExtension(ctx, config, checkpoint),
|
|
@@ -3415,12 +3702,11 @@ export default class XConnector extends ConnectorRuntime {
|
|
|
3415
3702
|
return syncDirectMessagesViaExtension(ctx, config, checkpoint);
|
|
3416
3703
|
}
|
|
3417
3704
|
|
|
3418
|
-
//
|
|
3419
|
-
//
|
|
3420
|
-
if (
|
|
3421
|
-
resolveSyncBackend(ctx, config, oauthScopes) === "oauth_api"
|
|
3422
|
-
) {
|
|
3705
|
+
// OAuth connections stay on the API even when scopes are missing; browser
|
|
3706
|
+
// search requires this connection's browser grant.
|
|
3707
|
+
if (resolveSyncBackend(ctx, config, oauthScopes) === "oauth_api") {
|
|
3423
3708
|
return syncOAuthWithOptionalFallback(
|
|
3709
|
+
ctx,
|
|
3424
3710
|
config,
|
|
3425
3711
|
() => syncViaOAuthApi(ctx, config, checkpoint),
|
|
3426
3712
|
() => syncSearchViaExtension(ctx, config, checkpoint),
|