@rise-x/apps-sdk 0.11.1 → 0.15.1

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 (86) hide show
  1. package/README.md +915 -19
  2. package/build/_internal.d.ts +4 -1
  3. package/build/_internal.js +67 -0
  4. package/build/cli/index.d.ts +7 -1
  5. package/build/cli/index.js +68 -14
  6. package/build/cli/scan.d.ts +60 -0
  7. package/build/cli/scan.js +725 -0
  8. package/build/cli/validate.d.ts +33 -0
  9. package/build/cli/validate.js +169 -0
  10. package/build/connectors/agents.d.ts +10 -6
  11. package/build/connectors/agents.js +59 -44
  12. package/build/connectors/attachments.d.ts +51 -0
  13. package/build/connectors/attachments.js +76 -0
  14. package/build/connectors/errors.js +24 -0
  15. package/build/connectors/flows.d.ts +13 -2
  16. package/build/connectors/flows.js +64 -19
  17. package/build/connectors/index.d.ts +5 -1
  18. package/build/connectors/index.js +14 -2
  19. package/build/connectors/integrations.d.ts +29 -0
  20. package/build/connectors/integrations.js +32 -0
  21. package/build/connectors/offline.d.ts +34 -0
  22. package/build/connectors/offline.js +135 -0
  23. package/build/connectors/readPolicy.d.ts +29 -0
  24. package/build/connectors/readPolicy.js +105 -0
  25. package/build/connectors/types.d.ts +75 -0
  26. package/build/connectors/types.js +128 -0
  27. package/build/connectors/vectorStores.d.ts +45 -0
  28. package/build/connectors/vectorStores.js +199 -0
  29. package/build/connectors/work.d.ts +14 -2
  30. package/build/connectors/work.js +43 -19
  31. package/build/dependencies/bound.d.ts +87 -0
  32. package/build/dependencies/bound.js +207 -0
  33. package/build/dependencies/index.d.ts +2 -0
  34. package/build/dependencies/index.js +13 -0
  35. package/build/dependencyRegistry.d.ts +15 -0
  36. package/build/dependencyRegistry.js +28 -0
  37. package/build/index.d.ts +2 -1
  38. package/build/index.js +12 -1
  39. package/build/lifecycle.d.ts +10 -1
  40. package/build/manifest.d.ts +69 -0
  41. package/build/manifest.js +229 -0
  42. package/build/manifestSource.d.ts +27 -0
  43. package/build/manifestSource.js +99 -0
  44. package/build/mockShell.d.ts +2 -0
  45. package/build/mockShell.js +13 -0
  46. package/build/query/client.js +9 -1
  47. package/build/query/dependencies.d.ts +22 -0
  48. package/build/query/dependencies.js +73 -0
  49. package/build/query/flows.d.ts +8 -8
  50. package/build/query/index.d.ts +1 -0
  51. package/build/query/index.js +4 -2
  52. package/build/query/layer.d.ts +9 -9
  53. package/build/query/shared.js +10 -0
  54. package/build/query/work.d.ts +4 -4
  55. package/build/rsbuild/index.d.ts +3 -1
  56. package/build/rsbuild/index.js +35 -1
  57. package/build/rsbuild/riseAppManifestPlugin.d.ts +19 -0
  58. package/build/rsbuild/riseAppManifestPlugin.js +79 -0
  59. package/build/shell/installShellBridge.d.ts +2 -0
  60. package/build/shell/installShellBridge.js +3 -1
  61. package/build/shellBridge.d.ts +233 -1
  62. package/build/shellBridge.js +8 -7
  63. package/build/ui/classes.json +2 -2
  64. package/build/ui/components/app-frame.d.ts +1 -1
  65. package/build/ui/components/data-table.d.ts +39 -4
  66. package/build/ui/components/statistic.d.ts +1 -1
  67. package/build/ui/demo.html +671 -543
  68. package/build/ui/shadcn.css +629 -0
  69. package/build/ui/standalone.js +45 -44
  70. package/build/ui/styles.css +1 -1
  71. package/build/ui/tailwind.css +12 -0
  72. package/build/ui/theme.css +412 -0
  73. package/build/ui/tw-animate.css +1 -0
  74. package/build/webpack/index.d.ts +1 -0
  75. package/build/webpack/index.js +7 -0
  76. package/build/webpack/riseAppManifestPlugin.d.ts +61 -0
  77. package/build/webpack/riseAppManifestPlugin.js +103 -0
  78. package/dependencies/package.json +8 -0
  79. package/package.json +17 -4
  80. package/template/AGENTS.md +34 -4
  81. package/template/README.md +85 -2
  82. package/template/package.json +4 -0
  83. package/template/rise-x-app.json +4 -0
  84. package/template/src/App.tsx +7 -17
  85. package/template/src/styles.css +5 -0
  86. package/webpack/package.json +8 -0
package/README.md CHANGED
@@ -3,12 +3,37 @@
3
3
  SDK for building federated apps on top of the Rise-X Diana shell.
4
4
 
5
5
  - **Runtime hooks/accessors** — `useShellUser`, `useShellEnvironment`, `useShellNavigate`, `getShellApi`, `getShellApiV4`, `getShellAi`.
6
- - **Connectors** — `@rise-x/apps-sdk/connectors` exposes typed, higher-level API wrappers (`flows`, `work`, `assets`, `agents`) so apps don't hand-roll multi-step API calls.
6
+ - **App dependencies** — `rise-x-app.json` declares the flows, asset types, agents, and integration endpoints the app depends on, one id (or id pair) per environment; `@rise-x/apps-sdk/dependencies` reads them back as `deps.<alias>`, with the connector calls that take that ref pre-filled. This is the first choice for any Rise-X object the app knows at authoring time.
7
+ - **Connectors** — `@rise-x/apps-sdk/connectors` exposes typed, higher-level API wrappers (`flows`, `work`, `assets`, `agents`, `integrations`) so apps don't hand-roll multi-step API calls. Use them for what a declared dependency can't express.
7
8
  - **Lifecycle hooks** — `onInstall`, `onUpdate`, `onUninstall` that apps export from a federated `./lifecycle` module; the shell invokes them best-effort.
8
9
  - **Standalone-dev mock** — `createMockShell` for running an app outside the shell.
9
10
  - **Shell-side installer** — `@rise-x/apps-sdk/shell` exposes `installShellBridge` for the host to wire the bridge.
10
11
  - **Scaffolder CLI** — `npx @rise-x/apps-sdk init <name>` to create a new app in the current directory.
11
12
 
13
+ ## Choosing an API
14
+
15
+ Four layers reach the same backend. Work down this list and stop at the first one
16
+ that fits:
17
+
18
+ 1. **A declared dependency** (`deps.<alias>`, from `@rise-x/apps-sdk/dependencies`)
19
+ for every flow, asset type, agent, or integration endpoint the app knows when
20
+ you write it. The id (an id pair, for an integration) lives in
21
+ `rise-x-app.json`, one set per environment, so the same source builds for
22
+ test and for prod.
23
+ 2. **A query hook** (`@rise-x/apps-sdk/query`) for data a component renders, passing
24
+ `dep.flowOriginId` or `dep.agentId` as the ref. There is no query hook for an
25
+ integration dependency — it has nothing cacheable, so call
26
+ `dep.integration.invoke()` (step 1) directly from an event handler.
27
+ 3. **A generic connector** (`@rise-x/apps-sdk/connectors`) for what a dependency
28
+ can't express: a ref the user picks at runtime, discovery (`flows.list`,
29
+ `assets.types`), and the operations no bound surface carries.
30
+ 4. **`getShellApiV4(name)` or `getShellApi()`** for endpoints no connector covers.
31
+ Never instantiate your own axios.
32
+
33
+ A flow, asset-type, agent, or integration/endpoint GUID in app source means step 1
34
+ was skipped. For the manifest format, see
35
+ [App dependencies](#app-dependencies-rise-x-appjson).
36
+
12
37
  ## Quick start (scaffold)
13
38
 
14
39
  ```bash
@@ -17,7 +42,15 @@ cd my-thing
17
42
  pnpm start
18
43
  ```
19
44
 
20
- ### CLI flags
45
+ ### CLI
46
+
47
+ | Command | What it does |
48
+ | --- | --- |
49
+ | `apps-sdk init <name>` | scaffold a new app in the current directory |
50
+ | `apps-sdk validate [dir]` | check the app's `rise-x-app.json` against every environment it declares, and warn about hardcoded ids (see [Validating before a deploy](#validating-before-a-deploy)) |
51
+ | `apps-sdk scan [dir]` | report Rise-X ids hardcoded in app source that the manifest does not declare (see [Finding hardcoded ids](#finding-hardcoded-ids)) |
52
+
53
+ `init` flags:
21
54
 
22
55
  | Flag | Default | Meaning |
23
56
  | --- | --- | --- |
@@ -26,6 +59,510 @@ pnpm start
26
59
  | `--skip-install` | off | skip `<pm> install` after scaffolding |
27
60
  | `--json` | off | emit `{ path, slug, scope, pkgName, port, pm }` on stdout |
28
61
 
62
+ `validate` flags:
63
+
64
+ | Flag | Default | Meaning |
65
+ | --- | --- | --- |
66
+ | `--env=<name>` | every declared environment | check only this one |
67
+ | `--no-scan` | off | skip the hardcoded-id scan |
68
+ | `--show-ignored` | off | also list the ids the scan set aside, and on what grounds |
69
+ | `--json` | off | emit `{ ok, manifest, environments, scan }` on stdout |
70
+
71
+ `scan` flags:
72
+
73
+ | Flag | Default | Meaning |
74
+ | --- | --- | --- |
75
+ | `--strict` | off | exit non-zero when an undeclared id is found, the scan was skipped, or a file could not be read |
76
+ | `--show-ignored` | off | also list the ids set aside, and on what grounds |
77
+ | `--json` | off | emit `{ ok, filesScanned, findings, declared, dismissed, silenced, unreadable, skipped }` on stdout. `skipped` carries the reason when the scan could not run, and a finding carries `aliasCollision: true` when its suggestion was dropped for a collision |
78
+
79
+ ## App dependencies (`rise-x-app.json`)
80
+
81
+ An app declares the Rise-X objects it depends on in a `rise-x-app.json` at its
82
+ project root. Each dependency gets a stable **alias** the app code refers to,
83
+ and one id **per environment** — so the same source file describes the
84
+ app on every environment it ships to. Scaffolded apps start with an empty
85
+ manifest.
86
+
87
+ **The rule: a GUID literal in app source belongs in `rise-x-app.json`.** Declare
88
+ it once, read it through `useAppDependencies()`, and the app builds for every
89
+ environment from the same code.
90
+
91
+ ```json
92
+ {
93
+ "environments": ["test", "staging", "prod"],
94
+ "dependencies": {
95
+ "riskFlow": {
96
+ "kind": "flow",
97
+ "label": "Risk Management workflow",
98
+ "description": "Source of all risk work items",
99
+ "ids": {
100
+ "test": { "flowOriginId": "11111111-1111-1111-1111-111111111111" },
101
+ "staging": { "flowOriginId": "1a1a1a1a-1a1a-1a1a-1a1a-1a1a1a1a1a1a" },
102
+ "prod": { "flowOriginId": "22222222-2222-2222-2222-222222222222" }
103
+ }
104
+ },
105
+ "vesselType": {
106
+ "kind": "assetType",
107
+ "label": "Vessel",
108
+ "ids": {
109
+ "test": { "flowOriginId": "33333333-3333-3333-3333-333333333333" },
110
+ "staging": { "flowOriginId": "3a3a3a3a-3a3a-3a3a-3a3a-3a3a3a3a3a3a" },
111
+ "prod": { "flowOriginId": "44444444-4444-4444-4444-444444444444" }
112
+ }
113
+ },
114
+ "triageAgent": {
115
+ "kind": "agent",
116
+ "label": "Medication triage",
117
+ "ids": {
118
+ "test": { "agentId": "55555555-5555-5555-5555-555555555555" },
119
+ "staging": { "agentId": "5a5a5a5a-5a5a-5a5a-5a5a-5a5a5a5a5a5a" },
120
+ "prod": { "agentId": "66666666-6666-6666-6666-666666666666" }
121
+ }
122
+ },
123
+ "crmLookup": {
124
+ "kind": "integration",
125
+ "label": "CRM customer lookup",
126
+ "ids": {
127
+ "test": {
128
+ "integrationId": "77777777-7777-7777-7777-777777777777",
129
+ "endpointId": "cccccccc-cccc-cccc-cccc-cccccccccccc"
130
+ },
131
+ "staging": {
132
+ "integrationId": "7a7a7a7a-7a7a-7a7a-7a7a-7a7a7a7a7a7a",
133
+ "endpointId": "cacacaca-caca-caca-caca-cacacacacaca"
134
+ },
135
+ "prod": {
136
+ "integrationId": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
137
+ "endpointId": "dddddddd-dddd-dddd-dddd-dddddddddddd"
138
+ }
139
+ }
140
+ }
141
+ }
142
+ }
143
+ ```
144
+
145
+ **Declare only the environments you have ids for.** A scaffolded app starts at
146
+ `["test"]`, because that is where apps are built and first deployed. Add
147
+ `staging` or `prod` when you have their ids, not before: every dependency needs
148
+ an id for every environment listed here, so declaring one you cannot fill leaves
149
+ the manifest permanently invalid.
150
+
151
+ That is also the only way to skip an environment. Never leave a single
152
+ dependency's ids half-filled: the alias sits above `ids`, so the alias set is
153
+ identical everywhere and each alias must resolve in each declared environment. A
154
+ declared `prod` with one dependency missing its prod id fails the `prod` build,
155
+ naming the alias and the environment. But a `test` build says nothing about the
156
+ prod ids, because the build validates only its target environment, so only
157
+ `apps-sdk validate` catches the gap before someone ships prod.
158
+
159
+ | Field | Required | Meaning |
160
+ | --- | --- | --- |
161
+ | `environments` | yes | the environment names this app is built for; every `ids` key must appear here, and every dependency must supply an id for each |
162
+ | `dependencies.<alias>.kind` | yes | `flow`, `assetType`, `agent`, or `integration` |
163
+ | `dependencies.<alias>.label` | no | human-readable name |
164
+ | `dependencies.<alias>.description` | no | what the app uses it for |
165
+ | `dependencies.<alias>.ids.<env>.<idField>` | yes | the id(s) on that environment (GUID) — see below |
166
+
167
+ The id field name(s) follow the `kind`, and a field the kind doesn't take fails
168
+ the build rather than being ignored:
169
+
170
+ | `kind` | Id field(s) | Why |
171
+ | --- | --- | --- |
172
+ | `flow` | `flowOriginId` | the origin id, stable across the flow's versions |
173
+ | `assetType` | `flowOriginId` | an asset type is backed by a flow |
174
+ | `agent` | `agentId` | an agent has no origin id and no version chain — one agent is one document with one id, scoped to one ecosystem, so it still differs per environment |
175
+ | `integration` | `integrationId` **and** `endpointId` | an integration id alone does not name a callable operation — invoke needs the specific endpoint on it too, so both are required together |
176
+
177
+ ### Building for an environment
178
+
179
+ The build picks **one** environment, resolves the manifest to it, and emits the
180
+ result as `dist/rise-x-app.json`. Both build paths do it:
181
+
182
+ | Build path | Wiring |
183
+ | --- | --- |
184
+ | Rsbuild — `defineAppConfig` from `@rise-x/apps-sdk/rsbuild` | none, the preset includes it |
185
+ | webpack — an app not yet migrated to Rsbuild | `new RiseAppManifestPlugin()` from `@rise-x/apps-sdk/webpack` |
186
+
187
+ New apps scaffold on Rsbuild, so they need no wiring. The webpack plugin
188
+ exists for apps still on their own `webpack.config.js`.
189
+
190
+ The environment comes from `APP_ENV`, and defaults to `test`. Scaffolded apps
191
+ carry a script per environment:
192
+
193
+ ```bash
194
+ pnpm build # → environment "test"
195
+ pnpm build:staging # → environment "staging"
196
+ pnpm build:prod # → environment "prod"
197
+ ```
198
+
199
+ `pnpm build` is bare `rsbuild build`, relying on the default environment,
200
+ `test`. `pnpm build:staging` and `pnpm build:prod` are
201
+ `cross-env APP_ENV=<name> rsbuild build`. Go through `cross-env` (a template
202
+ devDependency) rather than an inline `APP_ENV=prod rsbuild build` — the inline
203
+ form does not work in PowerShell or cmd.exe. In CI, set `APP_ENV` in the job
204
+ environment instead.
205
+
206
+ The `staging` and `prod` scripts ship ready for the day you promote, ahead of the
207
+ environments themselves. Until you declare one, its script fails with the list of
208
+ what is declared:
209
+
210
+ ```
211
+ rise-x-app.json is invalid:
212
+ - unknown environment "prod" — declared environments: test
213
+ ```
214
+
215
+ For an environment beyond these three, add it to `environments` and copy a
216
+ script.
217
+
218
+ The emitted file is flat, and carries ids for that environment only:
219
+
220
+ ```json
221
+ {
222
+ "environment": "prod",
223
+ "dependencies": {
224
+ "riskFlow": {
225
+ "kind": "flow",
226
+ "label": "Risk Management workflow",
227
+ "description": "Source of all risk work items",
228
+ "flowOriginId": "22222222-2222-2222-2222-222222222222"
229
+ },
230
+ "triageAgent": {
231
+ "kind": "agent",
232
+ "label": "Medication triage",
233
+ "agentId": "66666666-6666-6666-6666-666666666666"
234
+ }
235
+ }
236
+ }
237
+ ```
238
+
239
+ Because it rides in `dist/`, it ends up at the root of the deployed zip, where
240
+ the backend reads it to learn what the app needs. A bundle therefore can never
241
+ carry another environment's ids.
242
+
243
+ The build fails — with the alias and environment named — on an unknown
244
+ environment, a dependency missing an id for the selected environment, an
245
+ unsupported `kind`, an id field that does not belong to the `kind`, an id that is
246
+ not a GUID or is the empty GUID, a `dependencies` value that is not an object, an alias or environment name that is not a 1-64
247
+ character identifier (letters, digits, `.`, `-`, `_`, starting with a letter or
248
+ digit), a `label` over 200 or a `description` over 1,000 characters, a control
249
+ character in either, two aliases differing only by case, or more than 100
250
+ dependencies. These are the deploy's own rules, so a manifest that builds also
251
+ passes the deploy's shape check.
252
+ An app with no `rise-x-app.json` builds as before, emitting nothing.
253
+
254
+ ### Validating before a deploy
255
+
256
+ A build only resolves the environment it targets, so `pnpm build` says nothing
257
+ about whether the `prod` ids are intact. `apps-sdk validate` checks **every**
258
+ declared environment at once, and scaffolded apps carry it as a script:
259
+
260
+ ```bash
261
+ pnpm validate # every environment the manifest declares
262
+ pnpm validate -- --env=prod # just one
263
+ npx @rise-x/apps-sdk validate apps/bwo-insights # any directory
264
+ ```
265
+
266
+ ```
267
+ /path/to/app/rise-x-app.json
268
+
269
+ OK test — 2 dependencies
270
+ riskFlow flow 11111111-1111-1111-1111-111111111111
271
+ triageAgent agent 55555555-5555-5555-5555-555555555555
272
+
273
+ FAIL prod
274
+ rise-x-app.json is invalid:
275
+ - "triageAgent": no ids for environment "prod"
276
+
277
+ No undeclared ids in 4 source files
278
+
279
+ 1 of 2 environments failed. Fix them before you deploy.
280
+ ```
281
+
282
+ It exits non-zero when any environment fails, so a release script can gate on it,
283
+ and `--json` emits `{ ok, manifest, environments, scan }` for one that wants to
284
+ read the result. An app with no manifest passes.
285
+
286
+ **What it does not check:** whether those ids still exist in the target
287
+ ecosystem. Validation is structural and offline, and the deploy is no different:
288
+ it checks the manifest's shape, stores the declarations, and never looks the ids
289
+ up. A stale or wrong-environment id surfaces in the running app, not at deploy.
290
+
291
+ ### Finding hardcoded ids
292
+
293
+ A manifest can be flawless and still be bypassed by a GUID pasted into a
294
+ component. `apps-sdk scan` reads the app's TypeScript and reports Rise-X ids that
295
+ `rise-x-app.json` does not declare:
296
+
297
+ ```
298
+ Hardcoded ids — declare these in rise-x-app.json:
299
+
300
+ 77777777-7777-7777-7777-777777777777 flow
301
+ alias? riskMgmtFlow
302
+ src/App.tsx:13 (RISK_MGMT_FLOW.id)
303
+ src/App.tsx:14 (flowOriginId)
304
+
305
+ 1 undeclared id (5 dismissed by rule)
306
+ ```
307
+
308
+ Each location names the identifier the verdict was read off — `RISK_MGMT_FLOW.id`
309
+ means the enclosing const decided it, `flowOriginId` means the property did — so
310
+ a classification can be checked against the right name.
311
+
312
+ **The suggested alias is a suggestion, and sometimes there isn't one.** It comes
313
+ from whatever in the source names the *object*, with the words that describe the
314
+ id trimmed off: `EXPENSE_FLOW_ORIGIN_ID` suggests `expenseFlow`, and an entry in a
315
+ map like `ASSET = { currency: … }` suggests `currency` rather than `asset`, which
316
+ every sibling would also claim. A bare id argument — `agents.get('<guid>')` —
317
+ gets **no** alias, because the source never named the object and inventing one
318
+ from the enclosing function would be worse than admitting it. A collision is the
319
+ second cause: when two findings claim one name, or the name is already a key in
320
+ `rise-x-app.json`, the report prints `alias? (riskFlow is already taken,
321
+ ignoring case, by another finding or by rise-x-app.json. Same object: add this
322
+ id under that alias. Different: pick another name.)`, sets `aliasCollision` on
323
+ the finding, and leaves the naming to you. The common case is the "same object"
324
+ one: `rise-x-app.json` already declares `riskFlow` with another environment's
325
+ id, and the fix is to add this id under that existing alias, not to invent a
326
+ second key for the same flow. Only pick a distinct name for a genuinely
327
+ different object, because applying the same suggestion twice writes one JSON
328
+ key twice and `JSON.parse` keeps only the last. Aliases are the app's permanent
329
+ handle on a dependency, so treat a missing one as a question for whoever knows
330
+ the object.
331
+
332
+ `validate` runs it on every call and prints the findings as **warnings** — they
333
+ never change its exit code, because the classification is a heuristic and a false
334
+ positive that blocked a deploy would just teach everyone to stop running
335
+ `validate`. Pass `--no-scan` to skip it. For a gate, `apps-sdk scan --strict`
336
+ exits non-zero on any finding, which is what CI should call. It also exits
337
+ non-zero when the scan never ran (a path that does not exist, a source root with
338
+ no `.ts` or `.tsx` files, or a missing `typescript` devDependency), and when a
339
+ file the walk found could not be read: a gate that passes because it could not
340
+ check is worse than no gate.
341
+
342
+ **How it classifies.** It parses with the TypeScript parser and reads *names* —
343
+ the property a GUID is assigned to, the connector or hook it is passed to, the
344
+ variable it is bound to. `flowOriginId:` is a flow, `agentId:` an agent,
345
+ `assets.list({ type })` an asset type. Deliberately not a list of SDK methods and
346
+ argument names: those change every release, and a stale list would silently stop
347
+ classifying. A connector method added tomorrow still classifies, because
348
+ `flows.anything(id)` is about a flow whatever the method is called.
349
+
350
+ **What it skips, and why that matters.** A GUID used as an **object key** is a
351
+ lookup table, not a dependency — the five step ids in
352
+ `apps/bwo-insights/src/lib/phases.ts` are the real example, and the manifest
353
+ carries no step or task ids at all. So are ids named `stepId`, `workId`,
354
+ `assetId`, `chatId`, a section or layout id, canned `sample`/`mock`/`fixture`
355
+ data, and a bare row id passed to `assets.get()` or `work.get()`. An
356
+ `integrationId` or `endpointId` is **not** on this list — an integration
357
+ dependency takes both, so a hardcoded one is reported like any other id.
358
+ Anything else it can't attribute is reported with the kind left blank rather
359
+ than guessed.
360
+
361
+ **Every dismissal is auditable, deliberately.** Those rules were tuned against
362
+ real apps, so they will meet code they were not written for, and a real
363
+ dependency named `seedFlow` would be dropped by one of them. `--show-ignored`
364
+ prints what was set aside and on what grounds:
365
+
366
+ ```
367
+ Set aside:
368
+ 88888888-8888-8888-8888-888888888888 not a dependency kind
369
+ src/data.ts:243 (sampleClaims.id)
370
+ 99999999-9999-9999-9999-999999999999 not a dependency kind
371
+ src/rise-x.ts:15 (CREATE_CLAIM_SECTION_ID)
372
+ aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa not a dependency kind
373
+ src/rise-x.ts:1084 (workId)
374
+ ```
375
+
376
+ The summary counts them separately — `dismissed by rule` is the scanner's own
377
+ judgement and worth checking, `silenced` is a human's, recorded in the source with
378
+ `rise-x-app-ignore`. Both arrive in full under `--json`.
379
+
380
+ **It is a lint, not a proof.** It cannot see an id assembled at runtime or read
381
+ from config, and it cannot know a GUID belongs to Rise-X at all. For a legitimate
382
+ GUID that is not a dependency, put `rise-x-app-ignore` in a comment on its line
383
+ or the line above:
384
+
385
+ ```ts
386
+ // rise-x-app-ignore — correlation id for the audit trace, not a Rise-X object
387
+ const TRACE_ROOT = '0f9c1e77-...';
388
+ ```
389
+
390
+ Editing `rise-x-app.json` re-resolves it: the webpack plugin watches the file
391
+ and rebuilds; the Rsbuild preset restarts `rsbuild dev` and
392
+ `rsbuild build --watch`, which re-evaluates the config. Rspack's `DefinePlugin`
393
+ has no `runtimeValue`, so the injected constant is fixed for the life of one
394
+ config.
395
+
396
+ To resolve a manifest outside a build, the root barrel exports the pure
397
+ function both paths use:
398
+
399
+ ```ts
400
+ import { resolveAppManifest, type ResolvedAppManifest } from '@rise-x/apps-sdk';
401
+
402
+ const resolved: ResolvedAppManifest = resolveAppManifest(source, 'prod');
403
+ ```
404
+
405
+ ### Reading dependencies at runtime
406
+
407
+ The same build step injects the resolved manifest into the code as a
408
+ **compile-time constant** substituted for `globalThis.__RISE_APP_MANIFEST__`
409
+ (webpack's `DefinePlugin`, Rsbuild's `source.define`), so the accessors are
410
+ synchronous and each app bundle carries only its own ids — several apps
411
+ federated into one shell page cannot read each other's.
412
+
413
+ ```ts
414
+ import {
415
+ getAppDependencies,
416
+ getAppDependency,
417
+ useAppDependencies,
418
+ } from '@rise-x/apps-sdk/dependencies';
419
+
420
+ const deps = useAppDependencies();
421
+ deps.riskFlow.flowOriginId; // '2222…' on a prod build
422
+ deps.riskFlow.kind; // 'flow'
423
+ deps.riskFlow.label; // 'Risk Management workflow'
424
+ deps.triageAgent.agentId; // '6666…' — an agent names its id field agentId
425
+ deps.crmLookup.integrationId; // 'bbbb…' on a prod build — an integration names both id fields
426
+ deps.crmLookup.endpointId; // 'dddd…'
427
+
428
+ getAppDependency('riskFlow'); // same object, outside a component
429
+ getAppDependencies(); // the whole map
430
+ ```
431
+
432
+ The map is referentially stable, so it is safe as a hook or effect dependency.
433
+ `useAppDependencies()` holds no state — it is a hook only for call-site
434
+ consistency with `useShellUser`.
435
+
436
+ Both accessors throw a `ConnectorError` naming the fix: when no manifest reached
437
+ the bundle (no `rise-x-app.json`, or a webpack build without the plugin), and
438
+ when an alias is not
439
+ declared — that error lists the aliases that are.
440
+
441
+ `AppDependency` is a union over `kind`, so narrow it, or declare your app's
442
+ aliases once and pass them as the type argument:
443
+
444
+ ```ts
445
+ import type {
446
+ BoundAgentDependency,
447
+ BoundAssetTypeDependency,
448
+ BoundFlowDependency,
449
+ BoundIntegrationDependency,
450
+ } from '@rise-x/apps-sdk/dependencies';
451
+
452
+ interface AppDeps {
453
+ riskFlow: BoundFlowDependency;
454
+ vesselType: BoundAssetTypeDependency;
455
+ triageAgent: BoundAgentDependency;
456
+ crmLookup: BoundIntegrationDependency;
457
+ }
458
+
459
+ const deps = useAppDependencies<AppDeps>();
460
+ await deps.riskFlow.work.list({ pageSize: 20 }); // typed, no narrowing
461
+ ```
462
+
463
+ ### Bound connectors
464
+
465
+ Every dependency also exposes the connector operations that take its ref, with
466
+ the ref pre-filled. Prefer these over the generic connectors wherever the table
467
+ below reaches: each one is a thin delegation that takes the same arguments minus
468
+ the ref, and it keeps the id out of the call site. The generic connectors
469
+ (`@rise-x/apps-sdk/connectors`) cover what the bound surfaces don't.
470
+
471
+ | `kind` | Bound surface |
472
+ | --- | --- |
473
+ | `flow` | `dep.flow.get()`, `dep.flow.getConfig()`, `dep.work.start()`, `dep.work.list()`, `dep.work.iterate()`, `dep.work.search()` |
474
+ | `assetType` | `dep.assets.list()`, `dep.assets.iterate()`, `dep.assets.search()`, `dep.assets.quickSearch()`, `dep.assets.create()` |
475
+ | `agent` | `dep.agent.get()`, `dep.agent.run()`, `dep.agent.createChat()`, `dep.agent.listChats()` |
476
+ | `integration` | `dep.integration.invoke()` |
477
+
478
+ ```ts
479
+ const page = await deps.riskFlow.work.list({ pageSize: 20 });
480
+ const open = await deps.riskFlow.work.search({
481
+ filter: { field: 'status', operator: 'equals', values: ['Open'] },
482
+ });
483
+ const vessels = await deps.vesselType.assets.list({ pageSize: 50 });
484
+ const chat = deps.triageAgent.agent.createChat();
485
+ for await (const event of chat.send('which tablet is this?')) { /* … */ }
486
+ const lookup = await deps.crmLookup.integration.invoke({ data: { customerId } });
487
+ ```
488
+
489
+ On the two `search()` methods `filter` is optional: the `flowOriginId` pin the
490
+ v4 search endpoints require **is** the dependency, so the bound call adds it and
491
+ `and`s your filter with it.
492
+
493
+ The agent surface binds only the agent-scoped operations. The chat operations
494
+ keyed by a **chat** id (`getChat`, `renameChat`, `deleteChat`,
495
+ `getChatMessages`) take a chat, not an agent, so they stay on the generic
496
+ `agents` connector.
497
+
498
+ Anything not on the bound surface takes the id: `useFlowConfig(dep.flowOriginId)`
499
+ works for a flow or an asset type, since an asset type is backed by a flow too,
500
+ and `useAgent(dep.agentId)` for an agent.
501
+
502
+ ### Prefetching
503
+
504
+ `prefetchAppDependencies()` warms react-query with what each declared dependency
505
+ needs: for a `flow` or an `assetType`, its flow config and the layouts that
506
+ config points at (the flow's data schema, as `flattenLayoutFields` sees it); for
507
+ an `agent`, its agent document — never its run stream, which is SSE and has
508
+ nothing to cache. An `integration` dependency warms nothing: there is no
509
+ config document a federated app can read (the integration's own definition
510
+ carries secret parameters), and `invoke()`'s result is per-call, not cacheable
511
+ app config. It uses the SDK's own query keys and whichever
512
+ client you hand it — **pass the client the SDK hooks use**, or the warm lands in
513
+ a cache they never read:
514
+
515
+ ```tsx
516
+ import { prefetchAppDependencies, useAppQueryClient } from '@rise-x/apps-sdk/query';
517
+
518
+ const client = useAppQueryClient();
519
+ useEffect(() => {
520
+ void prefetchAppDependencies(client);
521
+ }, [client]);
522
+ ```
523
+
524
+ Prefetch is explicit, never automatic: a screen that reads one dependency should
525
+ not pay for all of them. It no-ops when the app declares no manifest, and until
526
+ the shell reports an environment (the keys are environment-scoped). It lives on
527
+ the `/query` subpath — the root barrel stays react-query-free, which is also why
528
+ the bound dependencies carry no `.prefetch()`. `/dependencies` is separate for
529
+ the same reason: it binds the connector layer, and an app that declares no
530
+ dependencies should not bundle it.
531
+
532
+ ### Standalone dev and tests
533
+
534
+ Standalone dev needs no extra wiring: `defineAppConfig` runs the plugin in both
535
+ its modes, so `rsbuild dev --env-mode standalone` injects the same resolved
536
+ manifest a federated build does. Declare the dependency in `rise-x-app.json` and
537
+ `useAppDependencies()` works on the app's own port.
538
+
539
+ For a Jest suite, or an app with no `rise-x-app.json`, supply the resolved
540
+ dependencies by hand — through `createMockShell`:
541
+
542
+ ```ts
543
+ createMockShell({
544
+ dependencies: {
545
+ riskFlow: { kind: 'flow', flowOriginId: '1111…' },
546
+ vesselType: { kind: 'assetType', flowOriginId: '3333…' },
547
+ triageAgent: { kind: 'agent', agentId: '5555…' },
548
+ },
549
+ });
550
+ ```
551
+
552
+ or with `registerAppDependencies(manifest)` from `@rise-x/apps-sdk/dependencies`
553
+ directly, which is the same call
554
+ `createMockShell` makes and takes the environment name as well. Either one
555
+ **overrides** whatever the build injected, so do not hand-copy ids the manifest
556
+ already declares: they would shadow `rise-x-app.json` in dev and go stale the
557
+ next time it changes, while the deployed build used the manifest all along.
558
+
559
+ `createMockShell` registers the ids under the default environment (`test`), since
560
+ it has no way to know which one they were taken from. A shell environment slug is
561
+ not a manifest environment name.
562
+
563
+ Never assign to `globalThis.__RISE_APP_MANIFEST__`: under the plugin that
564
+ expression is a compile-time constant, so assigning to it does not compile.
565
+
29
566
  ## Design assets (static HTML mocks)
30
567
 
31
568
  The package ships what an agent needs to build **static single-file HTML
@@ -92,6 +629,11 @@ const apps = getShellApiV4('apps');
92
629
  const work = getShellApiV4('work');
93
630
  ```
94
631
 
632
+ `getShellApiV4` is the last rung: it returns a raw client, so nothing above it
633
+ types the payloads or handles paging. Before you call it, check that no declared
634
+ dependency, query hook, or connector covers the endpoint. For the full order, see
635
+ [Choosing an API](#choosing-an-api).
636
+
95
637
  ### UI components (`@rise-x/apps-sdk/ui`)
96
638
 
97
639
  The Rise-X design system (shadcn components on the shell's Tailwind theme) is
@@ -101,6 +643,54 @@ re-exported for apps:
101
643
  import { Button, Dialog, DialogContent, Input, cn } from '@rise-x/apps-sdk/ui';
102
644
  ```
103
645
 
646
+ #### Styling (Tailwind utilities)
647
+
648
+ Your app compiles its own Tailwind. The host's compiled CSS carries only the
649
+ classes the design system itself uses, so a utility you write in your own JSX
650
+ resolves to nothing there, with no build error. The scaffold gives every app its
651
+ own entry at `src/styles.css`:
652
+
653
+ ```css
654
+ @import '@rise-x/apps-sdk/ui/tailwind.css';
655
+ @source '.';
656
+ ```
657
+
658
+ The import brings in the design-system theme: the token mapping, the px-pinned
659
+ scale, the `dark` variant. `@source '.'` tells Tailwind which directory to scan for
660
+ class names, relative to the stylesheet. Add another `@source` line for each
661
+ directory of components outside `src/`.
662
+
663
+ `src/App.tsx` imports the stylesheet, because the shell loads that module over
664
+ Module Federation. Importing it from `src/bootstrap.tsx` styles nothing in a
665
+ host: bootstrap runs only in standalone dev.
666
+
667
+ The rsbuild preset wires `@tailwindcss/postcss` for you, so your app needs no
668
+ PostCSS config. Standalone dev works the same way. Two things stay out of the
669
+ app's stylesheet:
670
+
671
+ - **Tailwind preflight.** The host owns the page reset.
672
+ - **`tokens.css`.** The host publishes the runtime token values on the
673
+ document, and the app inherits them by cascade, live dark-mode switching
674
+ included. A second copy breaks single-source theming.
675
+
676
+ Your utilities compile into `utilities.app`, a sublayer of the host's
677
+ `utilities` layer, so a design-system rule wins any collision with a utility of
678
+ yours, whatever order the two sheets load. That protects the components: a
679
+ plain `flex-col` in your sheet cannot override the `@2xl/app-frame:flex-row`
680
+ that `AppFrame` relies on. To restyle a design-system component, pass the class
681
+ through its `className`, where `cn` drops the conflicting one.
682
+
683
+ The entry scans only the paths you declare, so an app bundle carries its own
684
+ utilities and no second copy of the design system's. It does re-emit the
685
+ theme's non-utility rules: the keyframes, `.ai-text-shimmer`, the
686
+ forced-colors block, and the px-scale `:root` variables. Those match the
687
+ host's at the same SDK version. An app built against an older SDK than the
688
+ host runs ships older copies, and they win because the app's sheet loads
689
+ later, so update the SDK before you release.
690
+
691
+ The apps still on webpack compile no Tailwind of their own until they move to
692
+ the rsbuild preset.
693
+
104
694
  #### App layout (`AppFrame` / `AppRail` / `AppContent`)
105
695
 
106
696
  The root layout contract, scaffolded into every new app:
@@ -126,6 +716,10 @@ The frame is responsive by default, and it measures **itself**, not the window:
126
716
  given (the shell's chrome takes space the app never gets). Below the frame's
127
717
  `2xl` container width (672px) it stacks and `NavSection` headers hide.
128
718
 
719
+ `className` on `AppFrame` lands on the inner flex body (`data-slot="app-frame-body"`),
720
+ not the outer container element, so layout and text-colour overrides work but
721
+ `overflow`/`rounded` on it will not clip the absolutely positioned mobile tab bar.
722
+
129
723
  Being a container also makes the frame the containing block for `position:
130
724
  fixed` descendants, in every mode: a fixed action bar or FAB you render inside
131
725
  `AppFrame` pins to the app's region, not to the browser window. That is
@@ -209,6 +803,18 @@ import { MapView, mapPin } from '@rise-x/apps-sdk/ui';
209
803
  `tiles` also takes a preset (`'light'`, `'dark'`, `'streets'`, `'satellite'`), a
210
804
  custom tile layer, or `null` for no basemap at all.
211
805
 
806
+ The built-in presets load tile images from third-party hosts, so the host
807
+ page's CSP `img-src` must allow `https://*.basemaps.cartocdn.com`,
808
+ `https://tile.openstreetmap.org` and `https://server.arcgisonline.com`. The
809
+ host page's CSP controls this, so an app can't lift a block from its own
810
+ code. The Rise-X shell already allows the built-in preset hosts; for any
811
+ other host, ask Rise-X to add it. If no tile loads,
812
+ `MapView` warns once and removes the layer so Leaflet stops re-requesting
813
+ blocked tiles on every pan and zoom — use `tiles={null}` or a custom
814
+ `MapTileSpec` on a permitted origin instead. `mapPin()` has no `aria-label` of
815
+ its own; set one via `marker.getElement()` after `addTo(map)` if the marker
816
+ needs an accessible name (see the JSDoc on `mapPin`).
817
+
212
818
  `center`/`zoom`/`bounds` set the **initial** view only — pan and zoom afterwards
213
819
  through the instance (`map.flyTo(...)`), so a re-render never yanks the map away
214
820
  from someone who is using it. The map fills its parent and re-fits itself
@@ -216,6 +822,18 @@ whenever the box changes size, so it can sit in a panel, a split or a tab
216
822
  without the usual grey gutters. `interactive={false}` gives a static preview for
217
823
  cards and list rows, and children render over the map as overlays.
218
824
 
825
+ #### Charts
826
+
827
+ `DonutChart`, `RadialChart` and `ChartLegendItem` were removed in 0.8.0 — see
828
+ the 0.8.0 entry in the package CHANGELOG for the full migration. Charts are now the
829
+ shadcn chart layer composed from Recharts primitives re-exported off
830
+ `@rise-x/apps-sdk/ui` (`ChartContainer`, `Bar`, `Line`, `Pie`, `ComposedChart`,
831
+ ...). Click handlers are Recharts' own `onClick` prop on `Bar`/`Line`/`Pie`, and
832
+ a combo chart (bars plus a line on one axis pair) is `ComposedChart` composing
833
+ both. Never import from `recharts` directly — take the primitives from
834
+ `@rise-x/apps-sdk/ui`, or the remote bundles a second Recharts instance that
835
+ `ChartContainer` cannot see.
836
+
219
837
  ### Lifecycle hooks
220
838
 
221
839
  Expose a `./lifecycle` module — the preset exposes it by default — and export any subset of the three hooks:
@@ -256,26 +874,40 @@ Bring your own — install `localforage` (or IndexedDB, Cache API, etc.) as a di
256
874
  ## Connectors
257
875
 
258
876
  `@rise-x/apps-sdk/connectors` wraps the raw clients with typed, framework-agnostic
259
- helpers. Prefer them over hand-rolled `getShellApi*` calls; fall back to the raw
260
- clients only for endpoints the connectors don't cover.
877
+ helpers.
878
+
879
+ For a flow, asset type, agent, or integration endpoint the app knows at authoring
880
+ time, use its declared dependency instead: `deps.<alias>` carries these same
881
+ operations with the ref pre-filled, and keeps the id out of app source (see
882
+ [Bound connectors](#bound-connectors)). Reach for the generic connectors when a
883
+ dependency can't express the call: a ref the user picks at runtime, discovery
884
+ (`flows.list`, `assets.types`), and the operations no bound surface carries. Fall
885
+ back to the raw clients only for endpoints the connectors don't cover.
261
886
 
262
887
  ```ts
263
- import { flows, work, assets, agents, ConnectorError } from '@rise-x/apps-sdk/connectors';
888
+ import { flows, work, assets, agents, integrations, attachments, ConnectorError } from '@rise-x/apps-sdk/connectors';
264
889
  ```
265
890
 
266
891
  ### Flows — discovery
267
892
 
268
893
  ```ts
269
894
  // Prefer ids over names: displayName is user-editable and name changes when a
270
- // flow is rebuilt, so hardcoded name strings silently break later. Bake the
271
- // flowOriginId into app config instead:
272
- const FLOW_ORIGIN_ID = '7732039e-6c5e-4bca-9a23-3bb67b1a1b22';
895
+ // flow is rebuilt, so hardcoded name strings silently break later. A literal like
896
+ // the one below belongs in rise-x-app.json, read back as
897
+ // `deps.riskFlow.flowOriginId`; it is inlined here only to keep the example
898
+ // self-contained:
899
+ const FLOW_ORIGIN_ID = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb';
900
+ // `getConfig`/`getLayout` answer `null` only for a 404. A server that could not be
901
+ // reached with nothing cached throws, so those two are never the same value — read
902
+ // paths that must survive offline need a catch, not just a null check. `get()` is
903
+ // network-only and throws on 404.
273
904
  const flow = await flows.get(FLOW_ORIGIN_ID); // flow + full step tree (merged)
274
905
  // get/getConfig accept a concrete flow id or a flowOriginId — either
275
906
  // resolves to the latest published version (steps and config included).
276
907
  const config = await flows.getConfig(flow.id); // v4 step/task/layout grouping + nameMap
277
- const layout = await flows.getLayout(config.steps[0].tasks[0].layoutId!);
278
- const fields = flows.flattenLayoutFields(layout); // leaf form fields with data paths
908
+ const layoutId = config?.steps[0]?.tasks[0]?.layoutId;
909
+ const layout = layoutId ? await flows.getLayout(layoutId) : null;
910
+ const fields = layout ? flows.flattenLayoutFields(layout) : []; // leaf fields with data paths
279
911
 
280
912
  // findTask/list's name-matching is for dev-time exploration or a user-facing
281
913
  // search box, not for a shipped id — displayName isn't a stable reference:
@@ -297,13 +929,23 @@ returns an empty page with no error.
297
929
 
298
930
  ### Work — items (read + write)
299
931
 
932
+ **Prefer `work.search()` over `work.list()`/`iterate()` plus a per-row
933
+ `work.get()`.** `search()` returns `status`, `statusDisplay`, `assignedUsers`,
934
+ `created` and `lastModified` directly on the row; `get()` is per-item metadata
935
+ and `getData()` is the data document. Fetching each row with `get()` to
936
+ backfill those fields is the N+1 pattern `search()` exists to avoid — see the
937
+ `work.search()` section that follows.
938
+
300
939
  ```ts
301
940
  // Create a work item by starting a flow (flow.id or a bare flowOriginId —
302
941
  // the platform resolves either to the latest published version).
303
942
  const created = await work.start({ flowId: flow.id, data: { title: 'New risk' } });
304
943
 
305
- // Connect to it.
944
+ // Connect to it. `get` answers `null` only for a 404 (deleted meanwhile); an
945
+ // unreachable server throws — the same rule as `getConfig`/`getLayout` above,
946
+ // and `getData`/`getMyAccess` follow it too.
306
947
  const detail = await work.get(created.id);
948
+ if (!detail) throw new Error('work item no longer exists');
307
949
  const data = await work.getData(created.id, { path: '$.identifyPotentialRisk' });
308
950
 
309
951
  // Update work data (operations: Set | Push | Pull | Unset | AddToSet | Merge).
@@ -336,6 +978,31 @@ for await (const row of work.iterate({
336
978
  const audit = await work.getAudit(created.id);
337
979
  ```
338
980
 
981
+ **Key rows by `id`, never by `displayName`.** `id` is the only field guaranteed
982
+ unique across rows, so it is the one safe React `key` and lookup key. `displayName` can be
983
+ a blank template like `'Monthly Price Update - '` before the flow fills it in,
984
+ so two different work items can render the same label. `workCode` is the stable
985
+ _human_ handle — show it, cross-reference it — but it is optional: a flow that
986
+ assigns none leaves it `undefined`, which collapses every such row onto one key.
987
+
988
+ `WorkDetail.attachments` (from `work.get()`) lists the work's attachments as of
989
+ that read — links mapped from the v4 document, not the bytes themselves. Fetch
990
+ the bytes with `attachments.getBlob()`:
991
+
992
+ ```ts
993
+ for (const attachment of detail.attachments) {
994
+ const blob = await attachments.getBlob({
995
+ id: attachment.id,
996
+ resourceId: detail.id,
997
+ });
998
+ console.log(
999
+ attachment.title ?? attachment.fileName,
1000
+ attachment.path,
1001
+ blob?.size
1002
+ );
1003
+ }
1004
+ ```
1005
+
339
1006
  `work.search()` is the v4 index behind the same domain. Prefer it over
340
1007
  `work.list()`/`iterate()` for listings that need the platform's own status,
341
1008
  state, timestamps or assignees: those arrive **on the row**, so no per-item
@@ -431,6 +1098,13 @@ listings: it filters and sorts on any whitelisted field or `data.*` path, the
431
1098
  platform's own status and timestamps arrive **on the row**, and it is the
432
1099
  indexed replacement for the timeout-prone v3 field search.
433
1100
 
1101
+ `assets.list()` (and the `useAssetRows` hook) reports `hasMore` as a heuristic —
1102
+ a full page suggests more rows may follow, but it mis-reports when the server
1103
+ caps `limit` below the requested `pageSize`. Reach for `assets.search()` (or
1104
+ `useAssetSearch`) whenever a listing needs exact paging or a `totalCount`: the
1105
+ v4 index reports `hasMore` exactly and, with `includeTotalCount: true`, the
1106
+ real count.
1107
+
434
1108
  **The same mandatory `flowOriginId` pin applies** — see `work.search()` above.
435
1109
  Source it from `assets.types()` (`type.flow.flowOriginId`), **never** from
436
1110
  `flows.list()`: that lists work flows only, so its ids match nothing here.
@@ -493,7 +1167,7 @@ import { streamAgentReply, collectAgentReply } from '@rise-x/apps-sdk/connectors
493
1167
 
494
1168
  try {
495
1169
  for await (const s of streamAgentReply(
496
- agents.run({ agentId: agent.id, message: 'Open risks?', useHistory: false }),
1170
+ agents.run({ agentId: agent.id, message: 'Open risks?' }),
497
1171
  )) {
498
1172
  setReply(s.text); // already accumulated — just render it
499
1173
  // Report once, when the stream ends: the agent's error message if there was
@@ -513,12 +1187,24 @@ try {
513
1187
  // agent errors come back as `error`; transport/abort failures throw — so catch.
514
1188
  try {
515
1189
  const { text, reason, error } = await collectAgentReply(
516
- agents.run({ agentId: agent.id, message: 'Open risks?', useHistory: false }),
1190
+ agents.run({ agentId: agent.id, message: 'Open risks?' }),
517
1191
  );
518
1192
  } catch (err) {
519
1193
  showError(String(err));
520
1194
  }
521
1195
 
1196
+ // Handing the agent documents — pass `attachments` and the request goes as
1197
+ // multipart. Each file is uploaded and attached to the user turn, so the agent
1198
+ // reads it WHOLE (PDFs included). This is the only way to give an agent a
1199
+ // document: `context` is capped at 16 KB of JSON and rejected past that, so a
1200
+ // bid pack or a spec sheet does not fit and must not be squeezed in.
1201
+ const files = Array.from(fileInput.files ?? []); // or new File([blob], 'bid.pdf')
1202
+ for await (const s of streamAgentReply(
1203
+ agents.run({ agentId: agent.id, message: 'Score this bid', attachments: files }),
1204
+ )) {
1205
+ setReply(s.text);
1206
+ }
1207
+
522
1208
  // Multi-turn chat — memory is server-persisted in Mongo (ZDR-safe, no OpenAI
523
1209
  // retention cliff). createChat() captures the chat_id from the first turn's
524
1210
  // end_of_stream and passes it back on every subsequent send().
@@ -526,6 +1212,10 @@ const chat = agents.createChat({ agentId: agent.id });
526
1212
  for await (const s of streamAgentReply(chat.send('Summarize the open risks'))) setReply(s.text);
527
1213
  for await (const s of streamAgentReply(chat.send('Now only the high-severity ones'))) setReply(s.text); // remembers
528
1214
  const chatId = chat.chatId; // stable server id — persist it to reopen later
1215
+
1216
+ // Attachments are per turn, not per chat — attach on the sends that need it.
1217
+ for await (const s of streamAgentReply(chat.send('And this revision?', { attachments: [revision] })))
1218
+ setReply(s.text);
529
1219
  ```
530
1220
 
531
1221
  Chats are listable, reopenable, renamable, and deletable — the transcript
@@ -549,6 +1239,84 @@ await agents.renameChat(one.id, 'Q3 risk review');
549
1239
  await agents.deleteChat(one.id); // removes the chat and its messages
550
1240
  ```
551
1241
 
1242
+ ### Vector stores
1243
+
1244
+ Search-ready document stores an agent's `file_search` tool reads from —
1245
+ created and managed through the AI gateway
1246
+ (`/api/v1/agent/vector-stores`), the same `getAi()` transport `agents.run`
1247
+ uses. The store id (`vs_…`, OpenAI's own) is the only handle — there is no
1248
+ Rise-X id and no registry, so save it yourself:
1249
+
1250
+ ```ts
1251
+ import { vectorStores, agents, streamAgentReply, work } from '@rise-x/apps-sdk/connectors';
1252
+
1253
+ // `item` is the work item this corpus belongs to (work.get() / assets.create()).
1254
+ const store = await vectorStores.create({ name: 'Tender 4021 corpus' });
1255
+ await work.patchData(item.id, {
1256
+ originId: item.flowOriginId!, // required by WorkDataPatch
1257
+ path: '$.vectorStoreId',
1258
+ value: store.id, // the only handle — save it on the work item or asset
1259
+ });
1260
+
1261
+ const { files } = await vectorStores.addFiles(store.id, {
1262
+ files: Array.from(fileInput.files ?? []),
1263
+ });
1264
+ for (const f of files) {
1265
+ // status: 'accepted' | 'converted' | 'rejected' | 'failed' | 'unknown'
1266
+ // ('unknown' = a status this SDK build predates — not an error)
1267
+ if (f.status === 'rejected') showWarning(`${f.filename}: ${f.reason}`);
1268
+ // 'failed' = converted fine but didn't reach OpenAI — lastError carries why.
1269
+ if (f.status === 'failed') showWarning(`${f.filename}: ${f.lastError?.message}`);
1270
+ }
1271
+
1272
+ // Poll until indexing settles before pointing a run at the store — bounded,
1273
+ // so a stuck store fails loudly instead of hanging the caller forever.
1274
+ let current = await vectorStores.get(store.id);
1275
+ let attempts = 0;
1276
+ const maxAttempts = 60; // ~2 min at 2s intervals
1277
+ while (current.fileCounts.inProgress > 0) {
1278
+ if (++attempts > maxAttempts) throw new Error('Vector store indexing timed out');
1279
+ await new Promise((r) => setTimeout(r, 2000));
1280
+ current = await vectorStores.get(store.id);
1281
+ }
1282
+
1283
+ for await (const s of streamAgentReply(
1284
+ agents.run({
1285
+ agentId,
1286
+ message: 'Summarize the corpus',
1287
+ vectorStoreIds: [store.id],
1288
+ }),
1289
+ )) {
1290
+ setReply(s.text);
1291
+ }
1292
+ ```
1293
+
1294
+ One `addFiles` request carries at most 500 files and 100 MB of expanded
1295
+ content; past either the gateway answers 413/400 after the whole upload has
1296
+ run, so bound the picker rather than discovering the cap late.
1297
+
1298
+ A store expires `expiresAfterDays` days after it was last used, default 90.
1299
+ Show `expiryNotice` to the user, renew before expiry with `renew`, and after
1300
+ expiry call `rebuild`, which returns a new id to save.
1301
+
1302
+ ```ts
1303
+ if (current.daysUntilExpiry !== undefined && current.daysUntilExpiry <= 7) {
1304
+ showNotice(current.expiryNotice); // server-composed — show it verbatim
1305
+ }
1306
+ await vectorStores.renew(store.id, { expiresAfterDays: 90 });
1307
+
1308
+ // After it actually expires, renew() 409s — rebuild instead and save the NEW id.
1309
+ const rebuilt = await vectorStores.rebuild(store.id);
1310
+ await work.patchData(item.id, {
1311
+ originId: item.flowOriginId!,
1312
+ path: '$.vectorStoreId',
1313
+ value: rebuilt.id,
1314
+ });
1315
+ ```
1316
+
1317
+ `listFiles`/`deleteFile`/`rename`/`delete` round out the connector — see
1318
+ `VectorStoresConnector` in `@rise-x/apps-sdk/connectors` for the full surface.
1319
+
552
1320
  Notes:
553
1321
 
554
1322
  - **Streaming contract.** `agents.run`/`chat.send` yield raw `AgentRunEvent`s
@@ -563,15 +1331,117 @@ Notes:
563
1331
  - `agents.run`/`createChat` need shell bridge **v3** (`getAi`) and a deployment
564
1332
  with `DIANA_AI_API_ENDPOINT` configured — otherwise they throw
565
1333
  `ConnectorError('SHELL_TOO_OLD' | 'AI_UNAVAILABLE')`.
566
- - Memory contract: clients only ever handle `chatId`. `useHistory` defaults to
567
- `true`; `useHistory:false` runs one-shot and persists nothing. Passing a
568
- `chatId` together with `useHistory:false` is illegal → `INVALID_ARG` (mirrors
569
- the gateway's 400) and makes no network call.
1334
+ - Memory contract: clients only ever handle `chatId`. Every run is logged —
1335
+ the gateway creates a chat when you pass no `chatId` and reports its id on
1336
+ `end_of_stream`, so there is no one-shot mode and no way to run an agent off
1337
+ the record. Pass the id back to continue that conversation, or ignore it for
1338
+ a fire-and-forget answer. A run that dies before the runtime resolves a chat
1339
+ (error, timeout, cancel) ends with `chat_id: null`, so check it before you
1340
+ store it.
570
1341
  - `listChats`/`getChat`/`renameChat`/`deleteChat`/`getChatMessages` hit the
571
1342
  server chat store via the same `config` v4 client (`/api/v4/ai/agent-chat`).
1343
+ - **Documents go in as `attachments`, never through `context`.** The gateway
1344
+ caps `context` at 16 KB of JSON and rejects anything larger, so the only way
1345
+ an agent reads a real document is a per-turn attachment. Attachments are
1346
+ uploaded and attached to the user message; the model reads each file in full,
1347
+ originals included (send the PDF rather than text you extracted in the
1348
+ browser). The gateway caps the count per run
1349
+ (`DIANA_AGENT_MAX_ATTACHMENTS`, 5 by default → HTTP 400) and 64 MB in total
1350
+ (→ HTTP 413); both surface as `ConnectorError`. A part sent under any field
1351
+ name other than `attachments`, or under `attachments` as text rather than a
1352
+ file, is an HTTP 400 rather than a run with the documents quietly missing.
1353
+ - **There is no per-FILE cap, so add your own.** Only the count and the 64 MB
1354
+ total are enforced, which means one 50 MB file clears every limit above and
1355
+ then fails late rather than cleanly, after the upload has already run. Reject
1356
+ oversized files in the composer instead: the Shell's own does, at
1357
+ `MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024`.
1358
+ - **Every turn needs a `message`, and it has a ceiling.** The gateway requires
1359
+ at least one character, so a composer that attaches files and sends no text
1360
+ gets an HTTP 422. The upper bound is 65,536 characters, also enforced
1361
+ server-side only. Send the files with whatever instruction they are for.
1362
+ - **`file_search` needs a vector store — create one with the `vectorStores`
1363
+ connector.** Supported hosted tools are `file_search`, `web_search`,
1364
+ `code_interpreter` and `image_generation`. Run-scoped `vectorStoreIds`
1365
+ (`RunAgentArgs`/`SendChatArgs`) work on an agent that declares no
1366
+ `file_search` tool — the runtime adds the tool for that run. If the agent
1367
+ does declare `file_search`, its own `config.vector_store_ids` must already
1368
+ be non-empty, or every run fails validation before the merge. An agent with
1369
+ neither simply runs without file search. The platform provisions no store
1370
+ for you — see the preceding "Vector stores" section for
1371
+ `vectorStores.create`/`addFiles`. For documents belonging to a single turn,
1372
+ `attachments` needs no setup at all.
572
1373
  - Stored MCP `apiKey`s are redacted to `"***"` on read; `agents.update()` strips
573
1374
  the sentinel so read-modify-write can't clobber the stored secret.
574
1375
 
1376
+ ### Integrations — runtime endpoint invoke
1377
+
1378
+ ```ts
1379
+ const result = await integrations.invoke({
1380
+ integrationId: '7732039e-6c5e-4bca-9a23-3bb67b1a1b22',
1381
+ endpointId: '2b8f1e4a-9c3d-4f7e-8a1b-5c6d7e8f9a0b',
1382
+ data: { customerId: '123' }, // free-form; the endpoint's own templates read it as {$.field}
1383
+ });
1384
+ if (result.success) console.log(result.response, result.items);
1385
+ ```
1386
+
1387
+ - **No work item involved.** `invoke()` never creates or mutates a work item, so
1388
+ work-scoped tokens (`{$.work.*}`) are unavailable to the endpoint's templates.
1389
+ - **Any HTTP method the endpoint is configured with** — `GET`, `POST`, `PUT`,
1390
+ `PATCH` or `DELETE` — can be invoked this way; `invoke()` itself has no method
1391
+ parameter, since the endpoint's own stored configuration decides what the
1392
+ call does. A write-method endpoint is a real, credentialed create/update/delete
1393
+ against the integration's third-party system.
1394
+ - **Wider audience than the other connectors — read this before wiring one up.**
1395
+ Any member of the integration's own environment may call it — no
1396
+ per-integration grant, no per-endpoint opt-in — and a caller outside that
1397
+ environment can still reach it if their company holds a subscription covering
1398
+ the integration. **Treat every invocation's response as readable, and every
1399
+ write-method endpoint as invocable, by the whole ecosystem the integration
1400
+ belongs to**; do not gate access on anything the app itself controls, since
1401
+ the platform already grants it more broadly than a typical app permission
1402
+ would suggest — and be deliberate about exposing a write-method endpoint
1403
+ dependency at all, since any caller with environment membership (or a
1404
+ covering subscription) can trigger it exactly as configured, with no
1405
+ additional permission check.
1406
+ - **`data` cannot override configured parameters.** A key colliding with one
1407
+ configured on the integration or endpoint is rejected outright (HTTP 400) —
1408
+ the server does not say which key, so don't rely on the error message to
1409
+ discover names.
1410
+ - **A reachable-but-failing external call is not a `ConnectorError` — it
1411
+ resolves.** `invoke()` only throws for things on this side of the wire: a bad
1412
+ id, no entitlement, the rate limit. If the external endpoint itself errored or
1413
+ returned a non-2xx, the promise still resolves, with `result.success: false`,
1414
+ `result.statusCode` set to whatever the endpoint returned (or `0` if it never
1415
+ responded), and a fixed `result.message` — the server deliberately withholds
1416
+ the underlying error/URI, which can carry secrets. **Check `result.success`
1417
+ before reading `result.response`/`result.items`** — a bare `try/catch` around
1418
+ the call treats a remote 500 as success.
1419
+ - **Retries are the caller's problem, and are not safe by default on a
1420
+ write-method endpoint.** `result.statusCode: 0` ("if it never responded",
1421
+ above) doesn't distinguish "the request never left" from "it landed and the
1422
+ response was lost" — for a `GET` that ambiguity is harmless, but retrying a
1423
+ non-idempotent `POST`/`PATCH`/`DELETE` on it can double-create or
1424
+ double-delete. `invoke()` performs no retry of its own, but it is not safe
1425
+ to assume nothing else will: a failed call throws
1426
+ `ConnectorError("NETWORK_ERROR")` when no response came back — meaning the
1427
+ write may or may not have landed — and the app query client retries that up
1428
+ to twice (`createAppQueryClient`), so wrapping `invoke()` in a `useQuery`
1429
+ silently re-invokes the endpoint. For a write-method endpoint, use a
1430
+ mutation — react-query defaults mutations to `retry: 0`, and a mutation
1431
+ only fires when you call it. Don't reach for a query with `retry: false`
1432
+ instead: `createAppQueryClient` leaves `refetchOnReconnect` at react-query's
1433
+ default `true` (the offline path depends on it), and a query whose fetch
1434
+ threw has no data and is stale immediately, so reconnecting — or simply
1435
+ remounting the component — re-invokes the endpoint even with retries off. A plain
1436
+ `await invoke(...)` in an event handler is fine too. Wrap it in a query
1437
+ only if the third-party operation is genuinely idempotent.
1438
+ - **Rate-limited per (user, integration).** A burst of calls can get an HTTP 429;
1439
+ it surfaces as `ConnectorError` like any other HTTP error, not folded into
1440
+ `result`.
1441
+ - **Network only.** Not an `offline.*` queue candidate — this triggers a live
1442
+ credentialed call through the integration's own auth, not a resource this app
1443
+ owns to replay later.
1444
+
575
1445
  ### Errors
576
1446
 
577
1447
  Every connector failure is normalized to `ConnectorError` with a `code`:
@@ -646,6 +1516,19 @@ exactly the bugs standalone dev exists to catch — truncation, overflow, empty
646
1516
  optional fields, date formatting. Copy a few rows from the real ecosystem
647
1517
  (via the search endpoints or the Rise-X MCP) when you can.
648
1518
 
1519
+ `isMockShell(shell)` answers whether the app is running on that mock rather than
1520
+ inside a real host. Use it to gate a dev-only affordance, or to skip a write the
1521
+ mock always throws on:
1522
+
1523
+ ```ts
1524
+ import { getShell, isMockShell } from '@rise-x/apps-sdk';
1525
+
1526
+ const shell = getShell();
1527
+ if (shell && isMockShell(shell)) {
1528
+ // standalone dev — seed local state instead of queueing a write the mock rejects
1529
+ }
1530
+ ```
1531
+
649
1532
  ## Query layer (react-query)
650
1533
 
651
1534
  `@rise-x/apps-sdk/query` wraps the connectors in a
@@ -739,9 +1622,14 @@ Details worth knowing:
739
1622
  ```ts
740
1623
  queryClient.invalidateQueries({ queryKey: workQueries.search(args).queryKey });
741
1624
  ```
742
- - **Defaults**: `staleTime` 30 s, `gcTime` 5 min, no refetch-on-focus, up to 2
1625
+ - **Defaults**: `staleTime` 30 s, `gcTime` 5 min, no refetch-on-focus,
1626
+ `networkMode: 'offlineFirst'` (hooks run while the browser is offline, so
1627
+ reads answer from the offline cache — no retries while offline), up to 2
743
1628
  retries that skip terminal `ConnectorError` codes (4xx, `NOT_FOUND`,
744
- `ABORTED`, …). Override per call or via `createAppQueryClient(overrides)`.
1629
+ `ABORTED`, …). Override per call or via `createAppQueryClient(overrides)` —
1630
+ except `networkMode`, which is not in `SdkQueryOptions` and only changes via
1631
+ the client overrides. A per-call `retry` count keeps the offline guard: the
1632
+ count caps online retries, and retries are still declined while offline.
745
1633
  - **Errors are `ConnectorError`** — `error.code` narrows exactly like the
746
1634
  connector table above.
747
1635
  - **Full react-query power** (select, suspense, prefetch): use the
@@ -852,6 +1740,14 @@ export default defineConfig(({ envMode }) =>
852
1740
  Passing `__APP_VERSION__` throws: it is derived from `pkg.version` so it always
853
1741
  matches the deployed manifest.
854
1742
 
1743
+ Both branches wire `@tailwindcss/postcss` through `tools.postcss`, so an app
1744
+ compiles its own utilities with no PostCSS config of its own, and both set
1745
+ `output.injectStyles` so that CSS rides inside the JS and a host needs no CSS
1746
+ chunk loading of its own to style a loaded app. Sheet order does not matter:
1747
+ the app's utilities compile into `utilities.app`, a sublayer of the host's
1748
+ `utilities` layer, so a design-system rule wins any collision. See
1749
+ [Styling](#styling-tailwind-utilities).
1750
+
855
1751
  What the federated branch sets, and why it matters:
856
1752
 
857
1753
  - **`ModuleFederationPluginV1`**, never the enhanced plugin — V1 emits the