@lobu/runtime-device 22.0.0 → 24.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +33 -30
  3. package/npm-shrinkwrap.json +140 -124
  4. package/package.json +2 -1
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +74 -1
  6. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +9 -11
  7. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +3 -11
  8. package/vendor/cli/dist/commands/_lib/apply/client.js +3 -3
  9. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +0 -6
  10. package/vendor/cli/dist/commands/_lib/apply/desired-state.js +6 -15
  11. package/vendor/cli/dist/commands/_lib/apply/diff.js +1 -0
  12. package/vendor/cli/dist/commands/_lib/apply/map-config.js +8 -0
  13. package/vendor/cli/dist/commands/_lib/view-bundler.d.ts +2 -9
  14. package/vendor/cli/dist/commands/_lib/view-bundler.js +25 -97
  15. package/vendor/cli/dist/config/define.d.ts +8 -0
  16. package/vendor/cli/dist/connectors/README.md +15 -2
  17. package/vendor/cli/dist/connectors/google_gmail.ts +1 -0
  18. package/vendor/cli/dist/connectors/jira-helpers.ts +313 -0
  19. package/vendor/cli/dist/connectors/jira.ts +29 -221
  20. package/vendor/cli/dist/connectors/linkedin-browser-script.ts +13 -0
  21. package/vendor/cli/dist/connectors/linkedin-draft-page.js +104 -0
  22. package/vendor/cli/dist/connectors/linkedin-drafts.ts +73 -0
  23. package/vendor/cli/dist/connectors/linkedin-identity.ts +32 -0
  24. package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +1182 -0
  25. package/vendor/cli/dist/connectors/linkedin-inbox.ts +156 -0
  26. package/vendor/cli/dist/connectors/linkedin-like.ts +114 -0
  27. package/vendor/cli/dist/connectors/linkedin-takeout.ts +577 -0
  28. package/vendor/cli/dist/connectors/linkedin.ts +4017 -0
  29. package/vendor/cli/dist/connectors/reddit.ts +92 -20
  30. package/vendor/cli/dist/connectors/slack.ts +1 -0
  31. package/vendor/cli/dist/connectors/takeout-utils.ts +240 -0
  32. package/vendor/cli/dist/connectors/tiktok-inbox-page.js +9 -9
  33. package/vendor/cli/dist/connectors/tiktok-web-page.js +21 -15
  34. package/vendor/cli/dist/connectors/tiktok_web.ts +63 -30
  35. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +104 -574
  36. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +30 -444
  37. package/vendor/cli/dist/connectors/whatsapp-web-identity.ts +20 -6
  38. package/vendor/cli/dist/connectors/whatsapp_web.ts +46 -646
  39. package/vendor/cli/dist/connectors/x-dm-adapter.js +556 -0
  40. package/vendor/cli/dist/connectors/x-identity.ts +33 -2
  41. package/vendor/cli/dist/connectors/x.ts +266 -120
  42. package/vendor/cli/dist/runtime-components.json +4 -4
  43. package/vendor/cli/dist/templates/AGENTS.md.tmpl +12 -5
  44. package/vendor/cli/package.json +1 -1
  45. package/vendor/connector-sdk/dist/browser-handoff-banner.d.ts +39 -0
  46. package/vendor/connector-sdk/dist/browser-handoff-banner.js +175 -0
  47. package/vendor/connector-sdk/dist/browser-source-read.d.ts +52 -0
  48. package/vendor/connector-sdk/dist/browser-source-read.js +107 -0
  49. package/vendor/connector-sdk/dist/connector-types.d.ts +10 -0
  50. package/vendor/connector-sdk/dist/index.d.ts +3 -0
  51. package/vendor/connector-sdk/dist/index.js +2 -0
  52. package/vendor/connector-sdk/package.json +9 -1
  53. package/vendor/connector-worker/dist/agent-turn/gateway-tools.d.ts +2 -2
  54. package/vendor/connector-worker/dist/agent-turn/gateway-tools.js +2 -2
  55. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +49 -8
  56. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +650 -448
  57. package/vendor/connector-worker/dist/agent-turn/native-session.d.ts +12 -0
  58. package/vendor/connector-worker/dist/agent-turn/native-session.js +32 -6
  59. package/vendor/connector-worker/dist/agent-turn/types.d.ts +24 -3
  60. package/vendor/connector-worker/dist/daemon/agent-turn.js +5 -1
  61. package/vendor/connector-worker/dist/daemon/automation.d.ts +4 -11
  62. package/vendor/connector-worker/dist/daemon/automation.js +26 -21
  63. package/vendor/connector-worker/dist/daemon/client.d.ts +2 -4
  64. package/vendor/connector-worker/dist/daemon/client.js +0 -3
  65. package/vendor/connector-worker/dist/daemon/executor.js +0 -3
  66. package/vendor/connector-worker/dist/daemon/mac-device-daemon.d.ts +4 -3
  67. package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +4 -10
  68. package/vendor/connector-worker/dist/daemon/native-bridge/executor.js +27 -25
  69. package/vendor/connector-worker/dist/daemon/start.js +3 -15
  70. package/vendor/connector-worker/dist/daemon/terminal-failure.js +0 -11
  71. package/vendor/connector-worker/dist/daemon/worker-id.d.ts +17 -0
  72. package/vendor/connector-worker/dist/daemon/worker-id.js +22 -0
  73. package/vendor/connector-worker/dist/isolate/prelude.js +93 -44
  74. package/vendor/connector-worker/dist/mac-device-daemon.js +14 -26
  75. package/vendor/connector-worker/package.json +1 -1
  76. package/vendor/core/dist/agent-policy.js +0 -3
  77. package/vendor/core/dist/agent-tooling.d.ts +1 -1
  78. package/vendor/core/dist/agent-tooling.js +3 -1
  79. package/vendor/core/dist/capabilities.d.ts +1 -1
  80. package/vendor/core/dist/capabilities.js +0 -1
  81. package/vendor/core/dist/connector-query-errors.d.ts +32 -0
  82. package/vendor/core/dist/connector-query-errors.js +41 -1
  83. package/vendor/core/dist/contracts/agent-settings.d.ts +6 -2
  84. package/vendor/core/dist/contracts/agent-settings.js +12 -1
  85. package/vendor/core/dist/contracts/tools/manage-conversations.js +2 -2
  86. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +14 -0
  87. package/vendor/core/dist/contracts/tools/manage-feeds.js +17 -0
  88. package/vendor/core/dist/contracts/tools/manage-views.d.ts +53 -234
  89. package/vendor/core/dist/contracts/tools/manage-views.js +50 -76
  90. package/vendor/core/dist/contracts/tools/view-attach.d.ts +5 -8
  91. package/vendor/core/dist/contracts/tools/view-attach.js +14 -31
  92. package/vendor/core/dist/contracts/tools/view-definition.d.ts +21 -0
  93. package/vendor/core/dist/contracts/tools/view-definition.js +165 -0
  94. package/vendor/core/dist/contracts/worker/protocol.d.ts +47 -133
  95. package/vendor/core/dist/contracts/worker/protocol.js +33 -62
  96. package/vendor/core/dist/device-pin-tombstones.d.ts +44 -0
  97. package/vendor/core/dist/device-pin-tombstones.js +57 -0
  98. package/vendor/core/dist/index.d.ts +3 -2
  99. package/vendor/core/dist/index.js +3 -1
  100. package/vendor/core/dist/logger.js +10 -25
  101. package/vendor/core/dist/suggestions.d.ts +15 -2
  102. package/vendor/core/dist/suggestions.js +48 -3
  103. package/vendor/core/dist/types.d.ts +26 -0
  104. package/vendor/core/dist/types.js +5 -0
  105. package/vendor/core/dist/utils/diagnostic-scrubber.js +258 -21
  106. package/vendor/core/dist/worker/wire.d.ts +0 -10
  107. package/vendor/core/package.json +16 -10
  108. package/vendor/postgres/cf/src/connection.js +18 -0
  109. package/vendor/postgres/cjs/src/connection.js +18 -0
  110. package/vendor/postgres/src/connection.js +18 -0
  111. package/vendor/connector-worker/dist/daemon/device-chat.d.ts +0 -9
  112. package/vendor/connector-worker/dist/daemon/device-chat.js +0 -61
  113. package/vendor/core/dist/contracts/worker/device-chat.d.ts +0 -4
  114. package/vendor/core/dist/contracts/worker/device-chat.js +0 -26
  115. /package/vendor/postgres/{.bun-tag-f39dafdb2305d504 → .bun-tag-2f292c6554a8475e} +0 -0
@@ -0,0 +1,313 @@
1
+ /**
2
+ * Shared Jira helpers, connector-owned.
3
+ *
4
+ * The bundled Jira connector (`jira.ts`) and the server's Atlassian Rovo MCP
5
+ * feed adapter (`packages/server/src/operations/atlassian-mcp-feed.ts`) read
6
+ * the same source (Jira Cloud issues via JQL) and must agree on the JQL
7
+ * builder, the stable row shape, and ADF-to-text conversion. This module owns
8
+ * that shared knowledge; transport (REST vs MCP tool call) stays with each
9
+ * consumer. Server imports it as `@lobu/connectors/jira-helpers`.
10
+ */
11
+
12
+ /** Stable column set returned by Jira direct source reads. */
13
+ export const JIRA_ISSUE_COLUMNS = [
14
+ { name: 'id', type: 'string' },
15
+ { name: 'key', type: 'string' },
16
+ { name: 'summary', type: 'string' },
17
+ { name: 'status', type: 'string' },
18
+ { name: 'assignee', type: 'string' },
19
+ { name: 'reporter', type: 'string' },
20
+ { name: 'priority', type: 'string' },
21
+ { name: 'project_key', type: 'string' },
22
+ { name: 'project_name', type: 'string' },
23
+ { name: 'labels', type: 'string' },
24
+ { name: 'created_at', type: 'string' },
25
+ { name: 'updated_at', type: 'string' },
26
+ { name: 'description', type: 'string' },
27
+ { name: 'url', type: 'string' },
28
+ ] as const;
29
+
30
+ /** Issue fields requested from `/rest/api/3/search/jql`. */
31
+ export const JIRA_ISSUE_FIELDS =
32
+ 'summary,description,status,assignee,reporter,priority,project,labels,created,updated';
33
+
34
+ /** Sort columns the live path can honor by rewriting ORDER BY. */
35
+ export const JIRA_SORT_COLUMNS: Record<string, string> = {
36
+ updated: 'updated',
37
+ updated_at: 'updated',
38
+ created: 'created',
39
+ created_at: 'created',
40
+ key: 'key',
41
+ priority: 'priority',
42
+ status: 'status',
43
+ };
44
+
45
+ const ADF_BLOCK_TYPES = new Set([
46
+ 'blockquote',
47
+ 'bulletList',
48
+ 'codeBlock',
49
+ 'heading',
50
+ 'listItem',
51
+ 'orderedList',
52
+ 'paragraph',
53
+ 'rule',
54
+ 'table',
55
+ 'tableCell',
56
+ 'tableHeader',
57
+ 'tableRow',
58
+ ]);
59
+
60
+ export function jiraAsString(value: unknown): string | undefined {
61
+ return typeof value === 'string' && value.trim().length > 0
62
+ ? value.trim()
63
+ : undefined;
64
+ }
65
+
66
+ export function jiraActorName(user: unknown): string | undefined {
67
+ if (!user || typeof user !== 'object') {
68
+ return typeof user === 'string' && user.trim() ? user.trim() : undefined;
69
+ }
70
+ const record = user as Record<string, unknown>;
71
+ return (
72
+ jiraAsString(record.displayName) ??
73
+ jiraAsString(record.emailAddress) ??
74
+ jiraAsString(record.name)
75
+ );
76
+ }
77
+
78
+ export function jiraNamedField(value: unknown): string | undefined {
79
+ if (typeof value === 'string') return jiraAsString(value);
80
+ if (!value || typeof value !== 'object') return undefined;
81
+ return jiraAsString((value as Record<string, unknown>).name);
82
+ }
83
+
84
+ /**
85
+ * Jira v3 descriptions/comment bodies use the Atlassian Document Format (ADF) —
86
+ * a nested JSON node tree. Flatten its text nodes to plain text. Strings (older
87
+ * payloads) pass through unchanged.
88
+ *
89
+ * Block nodes join with `"\n"` so paragraphs do not glue together; inline
90
+ * nodes (and `hardBreak`, which already contributes its own newline) join
91
+ * cleanly.
92
+ */
93
+ export function adfToText(value: unknown): string {
94
+ if (typeof value === 'string') return value;
95
+ if (!value || typeof value !== 'object') return '';
96
+ const node = value as { type?: string; text?: string; content?: unknown[] };
97
+ // Soft line break inside a paragraph (not a block boundary).
98
+ if (node.type === 'hardBreak') return '\n';
99
+ if (typeof node.text === 'string') return node.text;
100
+ if (Array.isArray(node.content)) {
101
+ let out = '';
102
+ for (const child of node.content) {
103
+ const text = adfToText(child);
104
+ if (!text) continue;
105
+ const childType =
106
+ child && typeof child === 'object'
107
+ ? (child as { type?: string }).type
108
+ : undefined;
109
+ // hardBreak already contributes '\n' as its text; don't insert a second.
110
+ if (out && childType && ADF_BLOCK_TYPES.has(childType)) out += '\n';
111
+ out += text;
112
+ }
113
+ return out.trim();
114
+ }
115
+ return '';
116
+ }
117
+
118
+ /**
119
+ * Peel a trailing `ORDER BY …` so caller JQL can be AND-composed without
120
+ * wrapping the sort clause.
121
+ */
122
+ export function splitTrailingOrderBy(jql: string): {
123
+ body: string;
124
+ orderBy: string | null;
125
+ } {
126
+ let quote: '"' | "'" | null = null;
127
+ let escaped = false;
128
+ let depth = 0;
129
+ for (let i = 0; i < jql.length; i += 1) {
130
+ const char = jql[i];
131
+ if (quote) {
132
+ if (escaped) {
133
+ escaped = false;
134
+ } else if (char === '\\') {
135
+ escaped = true;
136
+ } else if (char === quote) {
137
+ quote = null;
138
+ }
139
+ continue;
140
+ }
141
+ if (char === '"' || char === "'") {
142
+ quote = char;
143
+ continue;
144
+ }
145
+ if (char === '(') {
146
+ depth += 1;
147
+ continue;
148
+ }
149
+ if (char === ')') {
150
+ depth = Math.max(0, depth - 1);
151
+ continue;
152
+ }
153
+ if (
154
+ depth === 0 &&
155
+ (i === 0 || /\s/.test(jql[i - 1])) &&
156
+ /^order\s+by\b/i.test(jql.slice(i))
157
+ ) {
158
+ return { body: jql.slice(0, i).trim(), orderBy: jql.slice(i).trim() };
159
+ }
160
+ }
161
+ return { body: jql.trim(), orderBy: null };
162
+ }
163
+
164
+ export function buildJiraJql(args: {
165
+ baseQuery: string;
166
+ query?: string;
167
+ sort?: { column: string; order: 'asc' | 'desc' };
168
+ defaultWhenEmpty?: string;
169
+ window?: { start: string; end: string };
170
+ }): string {
171
+ const trimmed = args.baseQuery.trim();
172
+ // Keep an omitted scope bounded instead of scanning the whole site.
173
+ const jql =
174
+ trimmed.length > 0
175
+ ? trimmed
176
+ : (args.defaultWhenEmpty ?? 'updated >= -90d');
177
+
178
+ // If the base is only ORDER BY, treat the restriction as empty and keep sort.
179
+ let { body, orderBy } = splitTrailingOrderBy(jql);
180
+ if (!body && orderBy) {
181
+ body = args.window
182
+ ? (args.defaultWhenEmpty ?? '')
183
+ : (args.defaultWhenEmpty ?? 'updated >= -90d');
184
+ }
185
+
186
+ const callerQuery = args.query?.trim() ?? '';
187
+ if (callerQuery) {
188
+ const caller = splitTrailingOrderBy(callerQuery);
189
+ if (caller.body) {
190
+ body = body.length > 0 ? `(${body}) AND (${caller.body})` : caller.body;
191
+ }
192
+ if (caller.orderBy) {
193
+ throw new Error(
194
+ 'Jira source read query cannot contain ORDER BY; use the separate sort field',
195
+ );
196
+ }
197
+ }
198
+
199
+ if (args.window) {
200
+ const bounds = `updated >= ${Date.parse(args.window.start)} AND updated < ${Date.parse(args.window.end)}`;
201
+ body = body ? `(${body}) AND (${bounds})` : bounds;
202
+ }
203
+
204
+ if (orderBy) {
205
+ if (args.sort) {
206
+ throw new Error(
207
+ 'Jira source read: cannot apply sort when the base JQL already contains ORDER BY',
208
+ );
209
+ }
210
+ return body.length > 0 ? `${body} ${orderBy}` : orderBy;
211
+ }
212
+
213
+ if (args.sort) {
214
+ const field = JIRA_SORT_COLUMNS[args.sort.column];
215
+ if (!field) {
216
+ throw new Error(
217
+ `Jira source read sort column '${args.sort.column}' is unsupported; ` +
218
+ `use one of: ${Object.keys(JIRA_SORT_COLUMNS).join(', ')}`,
219
+ );
220
+ }
221
+ const dir = args.sort.order === 'asc' ? 'ASC' : 'DESC';
222
+ return body.length > 0
223
+ ? `${body} ORDER BY ${field} ${dir}`
224
+ : `ORDER BY ${field} ${dir}`;
225
+ }
226
+
227
+ return body.length > 0
228
+ ? `${body} ORDER BY updated DESC`
229
+ : `${args.defaultWhenEmpty || 'updated >= -90d'} ORDER BY updated DESC`;
230
+ }
231
+
232
+ function jiraIssueUrl(
233
+ issue: Record<string, unknown>,
234
+ fields: Record<string, unknown>,
235
+ config: Record<string, unknown>,
236
+ ): string | undefined {
237
+ const key = jiraAsString(issue.key);
238
+ const siteUrl = jiraAsString(config.site_url);
239
+ const cloudId = jiraAsString(config.cloud_id);
240
+ const siteCloudId = jiraAsString(config.site_cloud_id);
241
+ // Only rewrite to /browse when site_url was discovered for THIS cloud_id.
242
+ // A feed-level cloud_id override must not inherit another site's host.
243
+ if (siteUrl && key && cloudId && siteCloudId && cloudId === siteCloudId) {
244
+ return `${siteUrl.replace(/\/+$/, '')}/browse/${encodeURIComponent(key)}`;
245
+ }
246
+ return (
247
+ jiraAsString(issue.self) ??
248
+ jiraAsString(fields.url) ??
249
+ jiraAsString(issue.url)
250
+ );
251
+ }
252
+
253
+ /**
254
+ * Map one Jira issue (REST-shaped `{ id, key, fields }` or flattened MCP
255
+ * payload) onto the stable issue row. Returns null when the payload carries
256
+ * no usable issue identity.
257
+ */
258
+ export function mapJiraIssueToRow(
259
+ raw: unknown,
260
+ config: Record<string, unknown> = {},
261
+ ): Record<string, unknown> | null {
262
+ if (!raw || typeof raw !== 'object') return null;
263
+ const issue = raw as Record<string, unknown>;
264
+ const fields =
265
+ issue.fields && typeof issue.fields === 'object'
266
+ ? (issue.fields as Record<string, unknown>)
267
+ : issue;
268
+ const id =
269
+ jiraAsString(issue.id) ??
270
+ jiraAsString(issue.key) ??
271
+ jiraAsString(fields.id);
272
+ if (!id) return null;
273
+ const labelsRaw = fields.labels ?? issue.labels;
274
+ const labels = Array.isArray(labelsRaw)
275
+ ? labelsRaw
276
+ .filter((label): label is string => typeof label === 'string')
277
+ .join(', ') || null
278
+ : (jiraAsString(labelsRaw) ?? null);
279
+ const project =
280
+ fields.project && typeof fields.project === 'object'
281
+ ? (fields.project as Record<string, unknown>)
282
+ : undefined;
283
+ return {
284
+ id,
285
+ key: jiraAsString(issue.key) ?? jiraAsString(fields.key) ?? null,
286
+ summary:
287
+ jiraAsString(fields.summary) ?? jiraAsString(issue.summary) ?? null,
288
+ status:
289
+ jiraNamedField(fields.status) ?? jiraNamedField(issue.status) ?? null,
290
+ assignee:
291
+ jiraActorName(fields.assignee ?? issue.assignee) ?? null,
292
+ reporter:
293
+ jiraActorName(fields.reporter ?? issue.reporter) ?? null,
294
+ priority:
295
+ jiraNamedField(fields.priority) ?? jiraNamedField(issue.priority) ?? null,
296
+ project_key:
297
+ jiraAsString(project?.key) ??
298
+ jiraAsString(fields.projectKey) ??
299
+ jiraAsString(issue.project_key) ??
300
+ null,
301
+ project_name:
302
+ jiraAsString(project?.name) ??
303
+ jiraAsString(fields.projectName) ??
304
+ null,
305
+ labels,
306
+ created_at:
307
+ jiraAsString(fields.created) ?? jiraAsString(issue.created) ?? null,
308
+ updated_at:
309
+ jiraAsString(fields.updated) ?? jiraAsString(issue.updated) ?? null,
310
+ description: adfToText(fields.description ?? issue.description) || null,
311
+ url: jiraIssueUrl(issue, fields, config) ?? null,
312
+ };
313
+ }
@@ -21,6 +21,15 @@ import {
21
21
  type WebhookRegistration,
22
22
  type WebhookRegistrationContext,
23
23
  } from '@lobu/connector-sdk';
24
+ import {
25
+ adfToText,
26
+ buildJiraJql,
27
+ JIRA_ISSUE_COLUMNS,
28
+ JIRA_ISSUE_FIELDS,
29
+ jiraActorName,
30
+ jiraAsString,
31
+ mapJiraIssueToRow,
32
+ } from './jira-helpers.js';
24
33
 
25
34
  // ---------------------------------------------------------------------------
26
35
  // Types
@@ -108,193 +117,6 @@ interface JiraSearchResponse {
108
117
  isLast?: boolean;
109
118
  }
110
119
 
111
- /** Stable column set returned by direct source reads. */
112
- const JIRA_ISSUE_COLUMNS = [
113
- { name: 'id', type: 'string' },
114
- { name: 'key', type: 'string' },
115
- { name: 'summary', type: 'string' },
116
- { name: 'status', type: 'string' },
117
- { name: 'assignee', type: 'string' },
118
- { name: 'reporter', type: 'string' },
119
- { name: 'priority', type: 'string' },
120
- { name: 'project_key', type: 'string' },
121
- { name: 'project_name', type: 'string' },
122
- { name: 'labels', type: 'string' },
123
- { name: 'created_at', type: 'string' },
124
- { name: 'updated_at', type: 'string' },
125
- { name: 'description', type: 'string' },
126
- { name: 'url', type: 'string' },
127
- ] as const;
128
-
129
- const ISSUE_FIELDS =
130
- 'summary,description,status,assignee,reporter,priority,project,labels,created,updated';
131
-
132
- /** Sort columns the live path can honor by rewriting ORDER BY. */
133
- const SORT_COLUMNS: Record<string, string> = {
134
- updated: 'updated',
135
- updated_at: 'updated',
136
- created: 'created',
137
- created_at: 'created',
138
- key: 'key',
139
- priority: 'priority',
140
- status: 'status',
141
- };
142
-
143
- const ADF_BLOCK_TYPES = new Set([
144
- 'blockquote',
145
- 'bulletList',
146
- 'codeBlock',
147
- 'heading',
148
- 'listItem',
149
- 'orderedList',
150
- 'paragraph',
151
- 'rule',
152
- 'table',
153
- 'tableCell',
154
- 'tableHeader',
155
- 'tableRow',
156
- ]);
157
-
158
- function asString(value: unknown): string | undefined {
159
- return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
160
- }
161
-
162
- function actorName(user: JiraUser | null | undefined): string | undefined {
163
- return user?.displayName ?? user?.emailAddress ?? undefined;
164
- }
165
-
166
- /**
167
- * Jira v3 descriptions/comment bodies use the Atlassian Document Format (ADF) —
168
- * a nested JSON node tree. Flatten its text nodes to plain text. Strings (older
169
- * payloads) pass through unchanged.
170
- */
171
- function adfToText(value: unknown): string {
172
- if (typeof value === 'string') return value;
173
- if (!value || typeof value !== 'object') return '';
174
- const node = value as { type?: string; text?: string; content?: unknown[] };
175
- // Soft line break inside a paragraph (not a block boundary).
176
- if (node.type === 'hardBreak') return '\n';
177
- if (typeof node.text === 'string') return node.text;
178
- if (Array.isArray(node.content)) {
179
- let out = '';
180
- for (const child of node.content) {
181
- const text = adfToText(child);
182
- if (!text) continue;
183
- const childType =
184
- child && typeof child === 'object' ? (child as { type?: string }).type : undefined;
185
- // hardBreak already contributes '\n' as its text; don't insert a second.
186
- if (out && childType && ADF_BLOCK_TYPES.has(childType)) out += '\n';
187
- out += text;
188
- }
189
- return out.trim();
190
- }
191
- return '';
192
- }
193
-
194
- /**
195
- * Peel a trailing `ORDER BY …` so caller JQL can be AND-composed without
196
- * wrapping the sort clause.
197
- */
198
- function splitTrailingOrderBy(jql: string): { body: string; orderBy: string | null } {
199
- let quote: '"' | "'" | null = null;
200
- let escaped = false;
201
- let depth = 0;
202
- for (let i = 0; i < jql.length; i += 1) {
203
- const char = jql[i];
204
- if (quote) {
205
- if (escaped) {
206
- escaped = false;
207
- } else if (char === '\\') {
208
- escaped = true;
209
- } else if (char === quote) {
210
- quote = null;
211
- }
212
- continue;
213
- }
214
- if (char === '"' || char === "'") {
215
- quote = char;
216
- continue;
217
- }
218
- if (char === '(') {
219
- depth += 1;
220
- continue;
221
- }
222
- if (char === ')') {
223
- depth = Math.max(0, depth - 1);
224
- continue;
225
- }
226
- if (
227
- depth === 0 &&
228
- (i === 0 || /\s/.test(jql[i - 1])) &&
229
- /^order\s+by\b/i.test(jql.slice(i))
230
- ) {
231
- return { body: jql.slice(0, i).trim(), orderBy: jql.slice(i).trim() };
232
- }
233
- }
234
- return { body: jql.trim(), orderBy: null };
235
- }
236
-
237
- function buildJiraJql(args: {
238
- baseQuery: string;
239
- query?: string;
240
- sort?: { column: string; order: 'asc' | 'desc' };
241
- defaultWhenEmpty?: string;
242
- window?: { start: string; end: string };
243
- }): string {
244
- const trimmed = args.baseQuery.trim();
245
- // Keep an omitted scope bounded instead of scanning the whole site.
246
- const jql = trimmed.length > 0 ? trimmed : (args.defaultWhenEmpty ?? 'updated >= -90d');
247
-
248
- // If the base is only ORDER BY, treat the restriction as empty and keep sort.
249
- let { body, orderBy } = splitTrailingOrderBy(jql);
250
- if (!body && orderBy) {
251
- body = args.defaultWhenEmpty ?? 'updated >= -90d';
252
- }
253
-
254
- const callerQuery = args.query?.trim() ?? '';
255
- if (callerQuery) {
256
- const caller = splitTrailingOrderBy(callerQuery);
257
- if (caller.body) {
258
- body = body.length > 0 ? `(${body}) AND (${caller.body})` : caller.body;
259
- }
260
- if (caller.orderBy) {
261
- throw new Error(
262
- 'Jira source read query cannot contain ORDER BY; use the separate sort field',
263
- );
264
- }
265
- }
266
-
267
- if (args.window) {
268
- const bounds = `updated >= ${Date.parse(args.window.start)} AND updated < ${Date.parse(args.window.end)}`;
269
- body = body ? `(${body}) AND (${bounds})` : bounds;
270
- }
271
-
272
- // `body` is non-empty from here on: an empty base fell back to
273
- // `defaultWhenEmpty`, and the caller query can further restrict it.
274
- if (orderBy) {
275
- if (args.sort) {
276
- throw new Error(
277
- 'Jira source read: cannot apply sort when the base JQL already contains ORDER BY',
278
- );
279
- }
280
- return `${body} ${orderBy}`;
281
- }
282
-
283
- if (args.sort) {
284
- const field = SORT_COLUMNS[args.sort.column];
285
- if (!field) {
286
- throw new Error(
287
- `Jira source read sort column '${args.sort.column}' is unsupported; ` +
288
- `use one of: ${Object.keys(SORT_COLUMNS).join(', ')}`,
289
- );
290
- }
291
- const dir = args.sort.order === 'asc' ? 'ASC' : 'DESC';
292
- return `${body} ORDER BY ${field} ${dir}`;
293
- }
294
-
295
- return `${body} ORDER BY updated DESC`;
296
- }
297
-
298
120
  // ---------------------------------------------------------------------------
299
121
  // Connector
300
122
  // ---------------------------------------------------------------------------
@@ -463,11 +285,11 @@ export default class JiraConnector extends ConnectorRuntime<JiraCheckpoint, Jira
463
285
  throw new Error('Jira source reads require Atlassian OAuth credentials.');
464
286
  }
465
287
 
466
- const baseQuery = asString(ctx.config.query) ?? asString(ctx.config.jql) ?? '';
288
+ const baseQuery = jiraAsString(ctx.config.query) ?? jiraAsString(ctx.config.jql) ?? '';
467
289
 
468
290
  const jql = buildJiraJql({
469
291
  baseQuery,
470
- query: asString(ctx.query),
292
+ query: jiraAsString(ctx.query),
471
293
  window: ctx.window,
472
294
  ...(ctx.window ? { defaultWhenEmpty: '' } : {}),
473
295
  sort: ctx.sort,
@@ -492,7 +314,7 @@ export default class JiraConnector extends ConnectorRuntime<JiraCheckpoint, Jira
492
314
  const params = new URLSearchParams({
493
315
  jql,
494
316
  maxResults: String(Math.min(this.PAGE_SIZE, limit)),
495
- fields: ISSUE_FIELDS,
317
+ fields: JIRA_ISSUE_FIELDS,
496
318
  });
497
319
  if (ctx.cursor) params.set('nextPageToken', ctx.cursor);
498
320
  const data = await http.json<JiraSearchResponse>(
@@ -540,7 +362,7 @@ export default class JiraConnector extends ConnectorRuntime<JiraCheckpoint, Jira
540
362
  end: new Date().toISOString(),
541
363
  };
542
364
  const jql = buildJiraJql({
543
- baseQuery: asString(ctx.config.query) ?? asString(ctx.config.jql) ?? '',
365
+ baseQuery: jiraAsString(ctx.config.query) ?? jiraAsString(ctx.config.jql) ?? '',
544
366
  defaultWhenEmpty: `updated >= -${lookbackDays}d`,
545
367
  window,
546
368
  });
@@ -559,7 +381,7 @@ export default class JiraConnector extends ConnectorRuntime<JiraCheckpoint, Jira
559
381
  const params = new URLSearchParams({
560
382
  jql,
561
383
  maxResults: String(this.PAGE_SIZE),
562
- fields: ISSUE_FIELDS,
384
+ fields: JIRA_ISSUE_FIELDS,
563
385
  });
564
386
  if (pageToken) {
565
387
  seenTokens.add(pageToken);
@@ -675,24 +497,10 @@ export default class JiraConnector extends ConnectorRuntime<JiraCheckpoint, Jira
675
497
  config: JiraConfig,
676
498
  ): Record<string, unknown> | null {
677
499
  if (!issue?.id) return null;
678
- const fields = issue.fields ?? {};
679
- const labels = Array.isArray(fields.labels) ? fields.labels.join(', ') : null;
680
- return {
681
- id: issue.id,
682
- key: issue.key ?? null,
683
- summary: fields.summary ?? null,
684
- status: fields.status?.name ?? null,
685
- assignee: actorName(fields.assignee) ?? null,
686
- reporter: actorName(fields.reporter) ?? null,
687
- priority: fields.priority?.name ?? null,
688
- project_key: fields.project?.key ?? null,
689
- project_name: fields.project?.name ?? null,
690
- labels,
691
- created_at: fields.created ?? null,
692
- updated_at: fields.updated ?? null,
693
- description: adfToText(fields.description) || null,
694
- url: this.issueUrl(issue, config) ?? null,
695
- };
500
+ return mapJiraIssueToRow(
501
+ issue,
502
+ config as unknown as Record<string, unknown>,
503
+ );
696
504
  }
697
505
 
698
506
  private issueEvent(issue: JiraIssue | undefined, config: JiraConfig): EventEnvelope | null {
@@ -705,25 +513,25 @@ export default class JiraConnector extends ConnectorRuntime<JiraCheckpoint, Jira
705
513
  origin_id: `jira_issue_${issue.id}`,
706
514
  title: fields.summary ?? issue.key ?? undefined,
707
515
  payload_text: adfToText(fields.description),
708
- author_name: actorName(fields.reporter ?? fields.assignee),
516
+ author_name: jiraActorName(fields.reporter ?? fields.assignee),
709
517
  source_url: this.issueUrl(issue, config),
710
518
  occurred_at: createdAt,
711
519
  origin_type: 'issue',
712
520
  metadata: {
713
521
  key: issue.key ?? null,
714
522
  status: fields.status?.name ?? null,
715
- assignee: actorName(fields.assignee) ?? null,
716
- reporter: actorName(fields.reporter) ?? null,
523
+ assignee: jiraActorName(fields.assignee) ?? null,
524
+ reporter: jiraActorName(fields.reporter) ?? null,
717
525
  updated_at: fields.updated ?? null,
718
526
  },
719
527
  };
720
528
  }
721
529
 
722
530
  private issueUrl(issue: JiraIssue | undefined, config?: JiraConfig): string | undefined {
723
- const siteUrl = asString(config?.site_url);
724
- const key = asString(issue?.key);
725
- const cloudId = asString(config?.cloud_id);
726
- const siteCloudId = asString(config?.site_cloud_id);
531
+ const siteUrl = jiraAsString(config?.site_url);
532
+ const key = jiraAsString(issue?.key);
533
+ const cloudId = jiraAsString(config?.cloud_id);
534
+ const siteCloudId = jiraAsString(config?.site_cloud_id);
727
535
  // Only rewrite to /browse when site_url was discovered for THIS cloud_id.
728
536
  // A feed-level cloud_id override must not inherit another site's host.
729
537
  if (siteUrl && key && cloudId && siteCloudId && cloudId === siteCloudId) {
@@ -756,7 +564,7 @@ export default class JiraConnector extends ConnectorRuntime<JiraCheckpoint, Jira
756
564
  sessionState: Record<string, unknown> | null | undefined,
757
565
  credentials: SyncCredentials | null | undefined,
758
566
  ): Promise<string> {
759
- const fromConfig = asString(config.cloud_id) ?? asString(sessionState?.cloud_id);
567
+ const fromConfig = jiraAsString(config.cloud_id) ?? jiraAsString(sessionState?.cloud_id);
760
568
  if (fromConfig) return fromConfig;
761
569
 
762
570
  if (!credentials?.accessToken) {
@@ -804,7 +612,7 @@ export default class JiraConnector extends ConnectorRuntime<JiraCheckpoint, Jira
804
612
  ? distinctUsable[0]
805
613
  : null;
806
614
 
807
- const id = asString(site?.id);
615
+ const id = jiraAsString(site?.id);
808
616
  if (!id) {
809
617
  if (jiraScoped.length > 1 || distinctUsable.length > 1) {
810
618
  throw new Error(
@@ -819,8 +627,8 @@ export default class JiraConnector extends ConnectorRuntime<JiraCheckpoint, Jira
819
627
  // Cache on this job's config so subsequent calls in the same run skip the hop.
820
628
  config.cloud_id = id;
821
629
  config.site_cloud_id = id;
822
- const siteUrl = asString(site?.url);
823
- const siteName = asString(site?.name);
630
+ const siteUrl = jiraAsString(site?.url);
631
+ const siteName = jiraAsString(site?.name);
824
632
  if (siteUrl) config.site_url = siteUrl;
825
633
  else delete config.site_url;
826
634
  if (siteName) config.site_name = siteName;
@@ -0,0 +1,13 @@
1
+ export const LINKEDIN_HOME_URL = "https://www.linkedin.com/feed/foryou/";
2
+
3
+ /** Keep data inert in generated browser code, including an HTML script context. */
4
+ export function linkedInScriptArgument(value: unknown): string {
5
+ const json = JSON.stringify(value);
6
+ if (json === undefined) throw new Error("LinkedIn browser input is required");
7
+ const literal = JSON.stringify(json).replace(
8
+ /[<>\u2028\u2029]/g,
9
+ (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`
10
+ );
11
+ // Parsing also preserves JSON object keys such as __proto__ as plain data.
12
+ return `JSON.parse(${literal})`;
13
+ }