@lobu/runtime-device 22.0.0 → 23.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component.json +1 -1
- package/dist/dependencies.bun.lock +3 -3
- package/npm-shrinkwrap.json +15 -15
- package/package.json +1 -1
- package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +1 -1
- package/vendor/cli/dist/connectors/README.md +14 -1
- package/vendor/cli/dist/connectors/google_gmail.ts +1 -0
- package/vendor/cli/dist/connectors/jira-helpers.ts +313 -0
- package/vendor/cli/dist/connectors/jira.ts +29 -221
- 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/takeout-utils.ts +240 -0
- package/vendor/cli/dist/connectors/tiktok-inbox-page.js +9 -9
- package/vendor/cli/dist/connectors/tiktok-web-page.js +21 -15
- package/vendor/cli/dist/connectors/tiktok_web.ts +63 -30
- package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +64 -564
- package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +30 -444
- package/vendor/cli/dist/connectors/whatsapp-web-identity.ts +20 -6
- package/vendor/cli/dist/connectors/whatsapp_web.ts +45 -645
- 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 +266 -120
- package/vendor/cli/dist/runtime-components.json +4 -4
- package/vendor/cli/dist/templates/AGENTS.md.tmpl +2 -2
- package/vendor/cli/package.json +1 -1
- 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-source-read.d.ts +52 -0
- package/vendor/connector-sdk/dist/browser-source-read.js +107 -0
- package/vendor/connector-sdk/dist/connector-types.d.ts +10 -0
- package/vendor/connector-sdk/dist/index.d.ts +3 -0
- package/vendor/connector-sdk/dist/index.js +2 -0
- package/vendor/connector-sdk/package.json +9 -1
- package/vendor/connector-worker/dist/agent-turn/guest-entry.js +15 -6
- package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +288 -148
- 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/client.d.ts +2 -4
- package/vendor/connector-worker/dist/daemon/client.js +0 -3
- package/vendor/connector-worker/dist/daemon/executor.js +0 -3
- package/vendor/connector-worker/dist/daemon/mac-device-daemon.d.ts +4 -3
- package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +4 -10
- package/vendor/connector-worker/dist/daemon/native-bridge/executor.js +27 -25
- package/vendor/connector-worker/dist/daemon/start.js +3 -15
- 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/mac-device-daemon.js +14 -26
- package/vendor/connector-worker/package.json +1 -1
- package/vendor/core/dist/capabilities.d.ts +1 -1
- package/vendor/core/dist/capabilities.js +0 -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/tools/manage-conversations.js +2 -2
- 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/worker/protocol.d.ts +8 -131
- package/vendor/core/dist/contracts/worker/protocol.js +9 -61
- 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 +2 -1
- package/vendor/core/dist/index.js +1 -0
- package/vendor/core/dist/logger.js +10 -25
- package/vendor/core/dist/utils/diagnostic-scrubber.js +258 -21
- package/vendor/core/dist/worker/wire.d.ts +0 -10
- package/vendor/core/package.json +6 -6
- 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/dist/component.json
CHANGED
|
@@ -546,7 +546,7 @@
|
|
|
546
546
|
|
|
547
547
|
"isolated-vm-next": ["isolated-vm@7.0.1", "", { "dependencies": { "node-gyp-build": "^4.8.4" } }, "sha512-nBCQ1hXEaYKYJ79wwfhaF44ITOJC30Hw0wPEsFeNsdD3hdeKK7FW1SGMQYBUA+qasvkqdOazI+iBuq0lcbN/aw=="],
|
|
548
548
|
|
|
549
|
-
"isomorphic-git": ["isomorphic-git@1.44.
|
|
549
|
+
"isomorphic-git": ["isomorphic-git@1.44.3", "", { "dependencies": { "async-lock": "^1.4.1", "clean-git-ref": "^2.0.1", "crc-32": "^1.2.0", "diff3": "0.0.3", "ignore": "^5.1.4", "minimisted": "^2.0.0", "pako": "^1.0.10", "pify": "^4.0.1", "readable-stream": "^4.0.0", "sha.js": "^2.4.12", "simple-get": "^4.0.1" }, "bin": { "isogit": "cli.cjs" } }, "sha512-xlEIMsVUrMfOR25F4jWB9He9s/rUHWsgfJJJ3zpdwFssv9X2QfoIUyYH9CEFok9yk2tx2UDipj2gJ+KVvV/qGA=="],
|
|
550
550
|
|
|
551
551
|
"jiti": ["jiti@2.7.0", "", { "bin": "lib/jiti-cli.mjs" }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="],
|
|
552
552
|
|
|
@@ -754,7 +754,7 @@
|
|
|
754
754
|
|
|
755
755
|
"strnum": ["strnum@2.5.1", "", { "dependencies": { "anynum": "^1.0.1" } }, "sha512-UM4nTLWzQiDBseVxUGxN0wJzIk0UU89Qi7pKXz9qISo+lhviJikTuikBsK/oFRlpvYHvSdz0TVoLyQ+sEpYwxA=="],
|
|
756
756
|
|
|
757
|
-
"strtok3": ["strtok3@10.
|
|
757
|
+
"strtok3": ["strtok3@10.6.2", "", { "dependencies": { "@tokenizer/token": "^0.3.0" } }, "sha512-BkdixFFUt7r7LsX6aGNPVyYMLjW+M1USLlKPNbZsrZEmLFh5tGqhdfckKo6xgsZIJqdDD0CZGkeCJJwNWQIKQA=="],
|
|
758
758
|
|
|
759
759
|
"supports-color": ["supports-color@7.2.0", "", { "dependencies": { "has-flag": "^4.0.0" } }, "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw=="],
|
|
760
760
|
|
|
@@ -788,7 +788,7 @@
|
|
|
788
788
|
|
|
789
789
|
"turndown": ["turndown@7.2.2", "", { "dependencies": { "@mixmark-io/domino": "^2.2.0" } }, "sha512-1F7db8BiExOKxjSMU2b7if62D/XOyQyZbPKq/nUwopfgnHlqXHqQ0lvfUTeUIr1lZJzOPFn43dODyMSIfvWRKQ=="],
|
|
790
790
|
|
|
791
|
-
"typebox": ["typebox@1.
|
|
791
|
+
"typebox": ["typebox@1.4.2", "", {}, "sha512-eSoZzgSIyOKDtTH9MI7XMAxMaiXq7UiSFWarysN1ka66baTLDxAVdQ6WkWn6qDqsJFVrcjzvuP+CqHo9yrlQpg=="],
|
|
792
792
|
|
|
793
793
|
"typed-array-buffer": ["typed-array-buffer@1.0.3", "", { "dependencies": { "call-bound": "^1.0.3", "es-errors": "^1.3.0", "is-typed-array": "^1.1.14" } }, "sha512-nAYYwfY3qnzX30IkA6AQZjVbtK6duGontcQm1WSG1MD94YLqK0515GNApXkoxKOWMusVssAHWLh9SeaoefYFGw=="],
|
|
794
794
|
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobu/runtime-device",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "23.0.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@lobu/runtime-device",
|
|
9
|
-
"version": "
|
|
9
|
+
"version": "23.0.0",
|
|
10
10
|
"license": "BUSL-1.1",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@lobu/cli": "file:vendor/cli",
|
|
@@ -3895,9 +3895,9 @@
|
|
|
3895
3895
|
}
|
|
3896
3896
|
},
|
|
3897
3897
|
"node_modules/isomorphic-git": {
|
|
3898
|
-
"version": "1.44.
|
|
3899
|
-
"resolved": "https://registry.npmjs.org/isomorphic-git/-/isomorphic-git-1.44.
|
|
3900
|
-
"integrity": "sha512-
|
|
3898
|
+
"version": "1.44.3",
|
|
3899
|
+
"resolved": "https://registry.npmjs.org/isomorphic-git/-/isomorphic-git-1.44.3.tgz",
|
|
3900
|
+
"integrity": "sha512-xlEIMsVUrMfOR25F4jWB9He9s/rUHWsgfJJJ3zpdwFssv9X2QfoIUyYH9CEFok9yk2tx2UDipj2gJ+KVvV/qGA==",
|
|
3901
3901
|
"license": "MIT",
|
|
3902
3902
|
"dependencies": {
|
|
3903
3903
|
"async-lock": "^1.4.1",
|
|
@@ -5212,9 +5212,9 @@
|
|
|
5212
5212
|
}
|
|
5213
5213
|
},
|
|
5214
5214
|
"node_modules/strtok3": {
|
|
5215
|
-
"version": "10.
|
|
5216
|
-
"resolved": "https://registry.npmjs.org/strtok3/-/strtok3-10.
|
|
5217
|
-
"integrity": "sha512-
|
|
5215
|
+
"version": "10.6.2",
|
|
5216
|
+
"resolved": "https://registry.npmjs.org/strtok3/-/strtok3-10.6.2.tgz",
|
|
5217
|
+
"integrity": "sha512-BkdixFFUt7r7LsX6aGNPVyYMLjW+M1USLlKPNbZsrZEmLFh5tGqhdfckKo6xgsZIJqdDD0CZGkeCJJwNWQIKQA==",
|
|
5218
5218
|
"license": "MIT",
|
|
5219
5219
|
"dependencies": {
|
|
5220
5220
|
"@tokenizer/token": "^0.3.0"
|
|
@@ -5442,9 +5442,9 @@
|
|
|
5442
5442
|
}
|
|
5443
5443
|
},
|
|
5444
5444
|
"node_modules/typebox": {
|
|
5445
|
-
"version": "1.
|
|
5446
|
-
"resolved": "https://registry.npmjs.org/typebox/-/typebox-1.
|
|
5447
|
-
"integrity": "sha512-
|
|
5445
|
+
"version": "1.4.2",
|
|
5446
|
+
"resolved": "https://registry.npmjs.org/typebox/-/typebox-1.4.2.tgz",
|
|
5447
|
+
"integrity": "sha512-eSoZzgSIyOKDtTH9MI7XMAxMaiXq7UiSFWarysN1ka66baTLDxAVdQ6WkWn6qDqsJFVrcjzvuP+CqHo9yrlQpg==",
|
|
5448
5448
|
"license": "MIT"
|
|
5449
5449
|
},
|
|
5450
5450
|
"node_modules/typed-array-buffer": {
|
|
@@ -5851,7 +5851,7 @@
|
|
|
5851
5851
|
},
|
|
5852
5852
|
"vendor/cli": {
|
|
5853
5853
|
"name": "@lobu/cli",
|
|
5854
|
-
"version": "
|
|
5854
|
+
"version": "23.0.0",
|
|
5855
5855
|
"license": "Apache-2.0",
|
|
5856
5856
|
"dependencies": {
|
|
5857
5857
|
"@clack/prompts": "^1.2.0",
|
|
@@ -5894,7 +5894,7 @@
|
|
|
5894
5894
|
},
|
|
5895
5895
|
"vendor/connector-sdk": {
|
|
5896
5896
|
"name": "@lobu/connector-sdk",
|
|
5897
|
-
"version": "
|
|
5897
|
+
"version": "23.0.0",
|
|
5898
5898
|
"license": "BUSL-1.1",
|
|
5899
5899
|
"dependencies": {
|
|
5900
5900
|
"@lobu/core": "file:../core",
|
|
@@ -5909,7 +5909,7 @@
|
|
|
5909
5909
|
},
|
|
5910
5910
|
"vendor/connector-worker": {
|
|
5911
5911
|
"name": "@lobu/connector-worker",
|
|
5912
|
-
"version": "
|
|
5912
|
+
"version": "23.0.0",
|
|
5913
5913
|
"license": "BUSL-1.1",
|
|
5914
5914
|
"dependencies": {
|
|
5915
5915
|
"@agentclientprotocol/sdk": "1.4.0",
|
|
@@ -5935,7 +5935,7 @@
|
|
|
5935
5935
|
},
|
|
5936
5936
|
"vendor/core": {
|
|
5937
5937
|
"name": "@lobu/core",
|
|
5938
|
-
"version": "
|
|
5938
|
+
"version": "23.0.0",
|
|
5939
5939
|
"license": "Apache-2.0",
|
|
5940
5940
|
"dependencies": {
|
|
5941
5941
|
"@opentelemetry/api": "^1.9.0",
|
package/package.json
CHANGED
|
@@ -60,7 +60,7 @@ Use ClientSDK through Lobu MCP or `lobu memory exec` with the explicit cloud con
|
|
|
60
60
|
|
|
61
61
|
If managed auth supplied a `local_bootstrap_command`, use the project it generated. Otherwise run `npx @lobu/cli@latest init` with the confirmed name and provider. Postgres is built in, so `lobu run` starts an embedded database; ask for `DATABASE_URL` only if the user chooses external Postgres. Read the generated `AGENTS.md` completely before editing `lobu.config.ts`. Use the canonical reference at `https://github.com/lobu-ai/lobu/blob/main/examples/lobu-crm/lobu.config.ts` when needed; do not assume that example exists in the new project's filesystem. Briefly explain how the chosen feed may use checkpoints to collect incrementally, emits events, builds shared entity memory, and gives both chat and Automations the same governed context.
|
|
62
62
|
|
|
63
|
-
`feeds_schema.<feed>.eventKinds` are the default Automation trigger catalog for feed connectors: every declared kind is a subscribable event type (`event_type` = the kind slug) for any feed that emits the kind. A feed's first successful non-dry sync establishes its baseline without activation; later inserts of a matching kind activate subscribers. Feed-scoped filtering is not yet available (events dedupe by connection + origin id, so a `feed_key` match would miss origins first seen by another feed). `automation_events` (now derived from eventKinds when a connector declares none) is the trigger picker's list. If no declared kind matches the use case, use a scheduled Automation with a bounded named SQL source and read event text from `payload_text`. Validate the query against the running local schema before relying on it. If `feeds_schema` is empty, do not invent or trigger a feed; chat integrations such as Slack can deliver incoming messages directly. For Slack or Telegram, prefer `defineConnection` with `credentialMode: "hosted"` so no bot token is required; `lobu run` prints the exact hosted-workspace join URL, own-workspace install URL when available, and short-lived link command. This hosted chat path requires a cloud session and the agent applied to that cloud workspace; the link targets the cloud agent. It does not create a local Slack data connection or prove local Slack search. Use those returned values instead of constructing URLs. A printed `/lobu link <code>` is one-time: redeem it in the first selected DM or channel. In an installed workspace whose installer is linked to Lobu, bind each additional surface with `/lobu link <agent-id>`; otherwise generate a fresh code for that surface. Mention Lobu in a channel test and verify the App Home separately. Lobu email login and Slack installation are separate: the email link authorizes Lobu CLI access, while an existing-workspace install requires the user or workspace admin to approve Slack's OAuth screen. Never describe Slack consent as an email approval. Use `credentialMode: "byo"` only if the user chooses their own app. Tell the user once which remaining secrets are required and add only `secret("ENV_NAME")` placeholders to config. Never open or request permission to read `.env`; inspect `.env.example` when present and declared secret placeholder names only. Never read, print, invent, or paste a real secret into source or chat.
|
|
63
|
+
`feeds_schema.<feed>.eventKinds` are the default Automation trigger catalog for feed connectors: every declared kind is a subscribable event type (`event_type` = the kind slug) for any feed that emits the kind. A feed's first successful non-dry sync establishes its baseline without activation; later inserts of a matching kind activate subscribers. A kind with `updatedEvent: true` also offers `<kind>.updated` for supersedes whose `occurred_at` strictly advances past the previous head. The original kind stays insert-only; unchanged rows, volatile-only updates and same-time reformats stay quiet. Subscribe to both types for new items and later activity. Feed-scoped filtering is not yet available (events dedupe by connection + origin id, so a `feed_key` match would miss origins first seen by another feed). `automation_events` (now derived from eventKinds when a connector declares none) is the trigger picker's list. If no declared kind matches the use case, use a scheduled Automation with a bounded named SQL source and read event text from `payload_text`. Validate the query against the running local schema before relying on it. If `feeds_schema` is empty, do not invent or trigger a feed; chat integrations such as Slack can deliver incoming messages directly. For Slack or Telegram, prefer `defineConnection` with `credentialMode: "hosted"` so no bot token is required; `lobu run` prints the exact hosted-workspace join URL, own-workspace install URL when available, and short-lived link command. This hosted chat path requires a cloud session and the agent applied to that cloud workspace; the link targets the cloud agent. It does not create a local Slack data connection or prove local Slack search. Use those returned values instead of constructing URLs. A printed `/lobu link <code>` is one-time: redeem it in the first selected DM or channel. In an installed workspace whose installer is linked to Lobu, bind each additional surface with `/lobu link <agent-id>`; otherwise generate a fresh code for that surface. Mention Lobu in a channel test and verify the App Home separately. Lobu email login and Slack installation are separate: the email link authorizes Lobu CLI access, while an existing-workspace install requires the user or workspace admin to approve Slack's OAuth screen. Never describe Slack consent as an email approval. Use `credentialMode: "byo"` only if the user chooses their own app. Tell the user once which remaining secrets are required and add only `secret("ENV_NAME")` placeholders to config. Never open or request permission to read `.env`; inspect `.env.example` when present and declared secret placeholder names only. Never read, print, invent, or paste a real secret into source or chat.
|
|
64
64
|
|
|
65
65
|
If the user wants the agent to know people in Slack, ask whether that means conversation participants, members of bound channels, or the full workspace directory. Installing the app proves none of those by itself. Verify the selected scope by inspecting the people or member entities Lobu actually materialized and by asking the agent a roster question. If human-readable names or non-participants are unavailable, identify that exact product gap; never claim the complete workspace directory was synced.
|
|
66
66
|
|
|
@@ -252,7 +252,19 @@ feeds: {
|
|
|
252
252
|
}
|
|
253
253
|
```
|
|
254
254
|
|
|
255
|
-
A feed's `eventKinds` are also the **default Automation trigger catalog**. The first successful non-dry sync establishes a baseline without activation; later inserts whose kind matches a declared `eventKinds` key activate subscribers. A non-empty `automationEvents` declaration (camelCase in `ConnectorDefinition`, persisted as `automation_events` in the catalog) replaces that derived catalog in the trigger picker. Keys
|
|
255
|
+
A feed's `eventKinds` are also the **default Automation trigger catalog**. The first successful non-dry sync establishes a baseline without activation; later inserts whose kind matches a declared `eventKinds` key activate subscribers. A non-empty `automationEvents` declaration (camelCase in `ConnectorDefinition`, persisted as `automation_events` in the catalog) replaces that derived catalog in the trigger picker. Keys outside the feed kinds and their opted-in updated types fire only when the emitted `EventEnvelope` carries matching `automation_signals`.
|
|
256
|
+
|
|
257
|
+
Set `eventKinds.<kind>.updatedEvent: true` to also expose a distinct `<kind>.updated`
|
|
258
|
+
trigger (for example, Gmail's `thread.updated`). After the baseline, it fires when
|
|
259
|
+
ingestion supersedes the source item with changed durable content and strictly
|
|
260
|
+
newer `occurred_at` than the previous head. Use source activity time, not a scheduled
|
|
261
|
+
start time. Unchanged rows, volatile-only counter updates and same-time reformats
|
|
262
|
+
stay quiet. The original `<kind>` trigger remains insert-only; subscribe to both
|
|
263
|
+
types for new items and later activity. Literal kinds declared by any feed of the
|
|
264
|
+
connector win slug collisions, and composite keys over 100 characters are omitted.
|
|
265
|
+
The optional boolean persists unchanged in `connector_definitions.feeds_schema`;
|
|
266
|
+
existing definitions without it retain their semantics. Explicit `automationEvents`
|
|
267
|
+
still replace the derived picker catalog, so include the updated key there if used.
|
|
256
268
|
|
|
257
269
|
## Syncing Data
|
|
258
270
|
|
|
@@ -544,6 +556,7 @@ For source-backed bundled connectors, the worker recompiles a `.ts` file after i
|
|
|
544
556
|
|-----------|------|-------|---------|
|
|
545
557
|
| `github` | app_installation/oauth/env_keys | issues, PRs, comments, discussions, commits, stargazers | create/comment/close/reopen issues; create/merge PRs |
|
|
546
558
|
| `hackernews` | none | stories, front page, comments | - |
|
|
559
|
+
| `linkedin` | browser/none | notifications, inbox messages, home feed, company updates, jobs; Data Export requires an injected CSV reader | send direct-message replies; like; prepare message/post/comment drafts |
|
|
547
560
|
| `market.quotes` | none | - | quote (read-only, quotes returned to the caller, never persisted) |
|
|
548
561
|
| `producthunt` | env_keys | posts & comments | - |
|
|
549
562
|
| `reddit` | oauth/none | posts, comments, user activity | - |
|
|
@@ -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
|
+
}
|