@rise-x/apps-sdk 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +192 -10
  2. package/build/connectors/agents.js +1 -1
  3. package/build/connectors/assets.d.ts +9 -3
  4. package/build/connectors/assets.js +32 -1
  5. package/build/connectors/index.d.ts +3 -2
  6. package/build/connectors/index.js +4 -1
  7. package/build/connectors/search.d.ts +34 -0
  8. package/build/connectors/search.js +63 -0
  9. package/build/connectors/types.d.ts +51 -0
  10. package/build/connectors/types.js +71 -0
  11. package/build/connectors/work.d.ts +7 -1
  12. package/build/connectors/work.js +13 -0
  13. package/build/index.d.ts +1 -1
  14. package/build/mockShell.d.ts +11 -0
  15. package/build/mockShell.js +159 -2
  16. package/build/query/assets.d.ts +19 -6
  17. package/build/query/assets.js +35 -3
  18. package/build/query/context.d.ts +14 -0
  19. package/build/query/context.js +16 -0
  20. package/build/query/index.d.ts +4 -3
  21. package/build/query/index.js +14 -2
  22. package/build/query/keys.d.ts +4 -0
  23. package/build/query/keys.js +7 -0
  24. package/build/query/layer.d.ts +25 -3
  25. package/build/query/work.d.ts +14 -1
  26. package/build/query/work.js +32 -1
  27. package/build/shellBridge.d.ts +1 -1
  28. package/build/ui/components/accordion.d.ts +7 -0
  29. package/build/ui/components/aspect-ratio.d.ts +4 -0
  30. package/build/ui/components/button-group.d.ts +7 -0
  31. package/build/ui/components/carousel.d.ts +18 -0
  32. package/build/ui/components/chart.d.ts +45 -94
  33. package/build/ui/components/collapsible.d.ts +6 -0
  34. package/build/ui/components/combobox.d.ts +19 -0
  35. package/build/ui/components/command.d.ts +18 -0
  36. package/build/ui/components/context-menu.d.ts +29 -0
  37. package/build/ui/components/data-table.d.ts +13 -2
  38. package/build/ui/components/date-picker.d.ts +16 -0
  39. package/build/ui/components/direction.d.ts +6 -0
  40. package/build/ui/components/field.d.ts +25 -0
  41. package/build/ui/components/hover-card.d.ts +6 -0
  42. package/build/ui/components/input-group.d.ts +13 -0
  43. package/build/ui/components/input-otp.d.ts +34 -0
  44. package/build/ui/components/input.d.ts +1 -3
  45. package/build/ui/components/item.d.ts +23 -0
  46. package/build/ui/components/kbd.d.ts +4 -0
  47. package/build/ui/components/menubar.d.ts +26 -0
  48. package/build/ui/components/message-scroller.d.ts +15 -0
  49. package/build/ui/components/navigation-menu.d.ts +13 -0
  50. package/build/ui/components/page-header.d.ts +7 -1
  51. package/build/ui/components/table.d.ts +7 -1
  52. package/build/ui/index.d.ts +19 -0
  53. package/build/ui/reference/components/accordion.tsx +85 -0
  54. package/build/ui/reference/components/alert-dialog.tsx +7 -2
  55. package/build/ui/reference/components/aspect-ratio.tsx +28 -0
  56. package/build/ui/reference/components/button-group.tsx +77 -0
  57. package/build/ui/reference/components/button.tsx +8 -1
  58. package/build/ui/reference/components/carousel.tsx +248 -0
  59. package/build/ui/reference/components/chart.tsx +441 -1131
  60. package/build/ui/reference/components/collapsible.tsx +43 -0
  61. package/build/ui/reference/components/combobox.tsx +141 -0
  62. package/build/ui/reference/components/command.tsx +181 -0
  63. package/build/ui/reference/components/context-menu.tsx +243 -0
  64. package/build/ui/reference/components/data-table.tsx +199 -29
  65. package/build/ui/reference/components/date-picker.tsx +218 -0
  66. package/build/ui/reference/components/dialog.tsx +2 -2
  67. package/build/ui/reference/components/direction.tsx +22 -0
  68. package/build/ui/reference/components/dropdown-menu.tsx +2 -2
  69. package/build/ui/reference/components/field.tsx +252 -0
  70. package/build/ui/reference/components/hover-card.tsx +64 -0
  71. package/build/ui/reference/components/input-group.tsx +157 -0
  72. package/build/ui/reference/components/input-otp.tsx +106 -0
  73. package/build/ui/reference/components/input.tsx +4 -32
  74. package/build/ui/reference/components/item.tsx +188 -0
  75. package/build/ui/reference/components/kbd.tsx +43 -0
  76. package/build/ui/reference/components/label.tsx +1 -1
  77. package/build/ui/reference/components/menubar.tsx +275 -0
  78. package/build/ui/reference/components/message-scroller.tsx +141 -0
  79. package/build/ui/reference/components/nav.tsx +9 -0
  80. package/build/ui/reference/components/navigation-menu.tsx +191 -0
  81. package/build/ui/reference/components/page-header.tsx +32 -0
  82. package/build/ui/reference/components/popover.tsx +2 -2
  83. package/build/ui/reference/components/select.tsx +11 -8
  84. package/build/ui/reference/components/sheet.tsx +14 -3
  85. package/build/ui/reference/components/table.tsx +15 -2
  86. package/build/ui/reference/components/timeline.tsx +7 -0
  87. package/build/ui/reference/components/toggle.tsx +1 -1
  88. package/build/ui/reference/index.ts +19 -0
  89. package/build/ui/standalone.js +167 -28
  90. package/build/ui/styles.css +1 -1
  91. package/package.json +15 -9
  92. package/template/README.md +6 -0
  93. package/template/src/App.tsx +10 -1
package/README.md CHANGED
@@ -201,6 +201,17 @@ const hit = await flows.findTask({ flow: 'Risk Management', task: 'Submit Risk'
201
201
  if (hit) console.log(hit.task.id, hit.step.displayName);
202
202
  ```
203
203
 
204
+ **`flows.list()` lists WORK flows only.** Asset-type (Entity) flows are not in
205
+ it; those come from `assets.types()`, which also carries the `entityType`, the
206
+ item count and the image the asset APIs need. The two listings are **disjoint**,
207
+ so neither is a superset of the other and neither enumerates "all flows". Only
208
+ `flows.get()` / `findTask()` resolve a flow of either kind by id.
209
+
210
+ This matters when you need a `flowOriginId` to pin a search: take a work origin
211
+ id from `flows.list()`, and an asset origin id from `assets.types()`. Crossing
212
+ them gives a valid guid of the wrong flow family, which matches nothing and
213
+ returns an empty page with no error.
214
+
204
215
  ### Work — items (read + write)
205
216
 
206
217
  ```ts
@@ -242,17 +253,70 @@ for await (const row of work.iterate({
242
253
  const audit = await work.getAudit(created.id);
243
254
  ```
244
255
 
256
+ `work.search()` is the v4 index behind the same domain. Prefer it over
257
+ `work.list()`/`iterate()` for listings that need the platform's own status,
258
+ state, timestamps or assignees: those arrive **on the row**, so no per-item
259
+ fetch is needed, and a filter tree replaces client-side narrowing.
260
+
261
+ **Every search must pin `flowOriginId`** with an `equals` or `in` condition, at
262
+ the top level or inside `and` groups — a pin inside an `or` branch doesn't
263
+ narrow the search and is rejected the same way.
264
+ Environment-wide searches are what made the slow query paths possible, so the
265
+ server now rejects an unpinned search with a 400 whatever else the filter says. Both
266
+ `work.search()` and `assets.search()` therefore require `filter` in their types.
267
+
268
+ ```ts
269
+ const page = await work.search({
270
+ filter: {
271
+ and: [
272
+ // Required, always. `in` with several origin ids works too.
273
+ { field: 'flowOriginId', operator: 'equals', values: [flowOriginId] },
274
+ // `status` values are Open/Closed/Completed/Deleted/Ok. Step-level values
275
+ // like InProgress belong to `flowState` — a different field.
276
+ { field: 'status', operator: 'in', values: ['Open'] },
277
+ ],
278
+ },
279
+ // Projection: `data.*` paths resolve against the pinned flow's schema and
280
+ // arrive under `row.data` with the `data.` prefix stripped. `statusDisplay`
281
+ // carries the label and roleName.
282
+ fields: ['status', 'assignedUsers', 'statusDisplay', 'data.pricing.rate'],
283
+ // Sorting and the createdBy/lastModifiedBy filters need a pinned search; on
284
+ // an older API build they may fail, so pin first before assuming they're
285
+ // broken.
286
+ sort: [{ field: 'created', direction: 'desc' }],
287
+ pageSize: 50,
288
+ });
289
+
290
+ for (const row of page.items) {
291
+ console.log(row.workCode, row.status, row.created, row.assignedUsers, row.data?.pricing);
292
+ }
293
+ // page.hasMore drives the next page; pass includeTotalCount for an exact count.
294
+ // Caveat: `row.created`/`row.lastModified` are ISO strings, but date values
295
+ // inside `row.data` pass through as `{date, ticks, offset}` objects — don't
296
+ // feed them to `new Date()` directly; use the `date` property.
297
+ ```
298
+
245
299
  ### Assets — typed records
246
300
 
247
301
  Assets ("entities"/"things" in platform parlance) are typed records defined by
248
302
  an entity flow — the flow's origin id is the asset-type reference:
249
303
 
304
+ > **Breaking in 0.7.0:** what 0.6.0 called `assets.search()` — the v3 free-text
305
+ > search — is now `assets.quickSearch()`. `assets.search()` / `useAssetSearch`
306
+ > are the paged v4 index search below: `filter` is required and the hook is an
307
+ > infinite query.
308
+ >
309
+ > Also: asset search now asks the host for the `'asset'` v4 client rather than
310
+ > `'config'`. Inside a Rise-X shell this is transparent. If you pass your own
311
+ > `apiV4` handler to `createMockShell` and switch on the key strictly, add an
312
+ > `'asset'` case, or it will stop matching.
313
+
250
314
  ```ts
251
315
  const types = await assets.types(); // asset types in the current ecosystem
252
316
  const supplier = types.find((t) => t.entityType === 'Supplier')!;
253
317
 
254
- // Server-side free-text search within a type.
255
- const hits = await assets.search({ type: 'Supplier', search: 'acme', dataPaths: ['$.name'] });
318
+ // v3 free-text search within a type — fuzzy, but slow on large types.
319
+ const hits = await assets.quickSearch({ type: 'Supplier', search: 'acme', dataPaths: ['$.name'] });
256
320
 
257
321
  // Full detail: data document, relationships, edit draft, permissions flags.
258
322
  const detail = await assets.get(hits[0].id);
@@ -278,6 +342,45 @@ await assets.clone(detail.id);
278
342
  await assets.delete(detail.id);
279
343
  ```
280
344
 
345
+ `assets.search()` is the v4 index behind the same domain, and takes the same
346
+ filter grammar as `work.search()`. Prefer it over `quickSearch()`/`list()` for
347
+ listings: it filters and sorts on any whitelisted field or `data.*` path, the
348
+ platform's own status and timestamps arrive **on the row**, and it is the
349
+ indexed replacement for the timeout-prone v3 field search.
350
+
351
+ **The same mandatory `flowOriginId` pin applies** — see `work.search()` above.
352
+ Source it from `assets.types()` (`type.flow.flowOriginId`), **never** from
353
+ `flows.list()`: that lists work flows only, so its ids match nothing here.
354
+
355
+ ```ts
356
+ const page = await assets.search({
357
+ filter: {
358
+ and: [
359
+ // Required, always. `in` with several origin ids works too.
360
+ { field: 'flowOriginId', operator: 'equals', values: [supplier.flow!.flowOriginId] },
361
+ // Asset `status` values are Open/Closed/Deleted — a narrower vocabulary
362
+ // than work's, which also has Completed/Ok.
363
+ { field: 'status', operator: 'equals', values: ['Open'] },
364
+ { field: 'displayName', operator: 'contains', values: ['acme'] },
365
+ ],
366
+ },
367
+ // Projection. A `data.*` path must exist in the pinned flow's data schema or
368
+ // the request 400s naming it; values arrive under `row.data` with the
369
+ // `data.` prefix stripped (`data.supplier.rating` → `row.data.supplier.rating`).
370
+ // Bare `data` skips the schema check and returns the whole document.
371
+ fields: ['status', 'code', 'statusDisplay', 'data.supplier.rating'],
372
+ sort: [{ field: 'created', direction: 'desc' }],
373
+ pageSize: 50,
374
+ });
375
+
376
+ for (const row of page.items) {
377
+ console.log(row.code, row.status, row.created, row.data?.supplier);
378
+ }
379
+ // Same page envelope as work.search — hasMore drives the next page. `id` and
380
+ // `status` come back on every row even when `fields` omits them; the other
381
+ // scalars are present by default but drop out once `fields` is set.
382
+ ```
383
+
281
384
  ### Agents — configurable AI
282
385
 
283
386
  CRUD over the agent config registry (`/api/v4/config/agent`, rise-x-api) plus
@@ -287,7 +390,7 @@ streaming runs through the rise-x-ai gateway:
287
390
  const { items } = await agents.list({ search: 'support' });
288
391
  const agent = await agents.create({
289
392
  name: 'Platform Helper',
290
- model: 'gpt-5',
393
+ model: 'gpt-5.6-luna',
291
394
  systemPrompt: 'You help operators work with Rise-X flows.',
292
395
  mcpServers: [
293
396
  {
@@ -422,6 +525,44 @@ window.__DIANA_SHELL__ = createMockShell({
422
525
  });
423
526
  ```
424
527
 
528
+ Without a backend, seed `fixtures` instead so data-backed screens render their
529
+ real content paths under `pnpm start` — otherwise standalone dev only ever
530
+ exercises the empty/loading/error states, and a rendering bug in the content
531
+ path is invisible until the app is deployed into a host:
532
+
533
+ ```ts
534
+ window.__DIANA_SHELL__ = createMockShell({
535
+ fixtures: {
536
+ // Keyed by flowOriginId; '*' serves any flow. Paged with the request's
537
+ // skip/limit, so pagination and work.iterate() work as they would live.
538
+ workRows: { '*': [{ id: 'w1', displayName: 'Monthly Price Update', workCode: 'WPL-2026-884' }] },
539
+ // Both search fixtures are served only when the request pins flowOriginId,
540
+ // exactly as the live endpoints behave — an unpinned search throws here too.
541
+ workSearch: [{ id: 'w1', workCode: 'WPL-2026-884', status: 'Open', created: '2026-08-01T00:00:00Z' }],
542
+ workDetail: { w1: { id: 'w1', displayName: 'Monthly Price Update', actions: [] } },
543
+ workData: { w1: { pricing: { rate: 1.42 } } },
544
+ assetTypes: [{ id: 't1', entityType: 'Pump', flow: { flowOriginId: 'origin-a' } }],
545
+ assetRows: { '*': [{ id: 'a1', displayName: 'Pump 1' }] },
546
+ assetSearch: [{ id: 'a1', displayName: 'Pump 1', code: 'PMP-001', status: 'Open' }],
547
+ assetDetail: { a1: { id: 'a1', displayName: 'Pump 1' } },
548
+ },
549
+ });
550
+ ```
551
+
552
+ Only reads are served, and only the ones seeded: an unseeded call throws
553
+ `SHELL_UNAVAILABLE` naming the fixture key that would answer it, and writes
554
+ always throw. Both are deliberate — a fixture that returned empty data or
555
+ pretended to persist would make a broken app look like a working one.
556
+
557
+ **Seed real-world-shaped data, not `Item 1`/`foo`.** Fixtures are only worth
558
+ the effort if they exercise what live data will: real field names from the
559
+ flow's schema, plausible lengths (a supplier name that wraps, a code that
560
+ doesn't), the enum values the server actually returns (`status: 'Open'`, not
561
+ `'active'`), ISO timestamps, and enough rows to page. Placeholder values hide
562
+ exactly the bugs standalone dev exists to catch — truncation, overflow, empty
563
+ optional fields, date formatting. Copy a few rows from the real ecosystem
564
+ (via the search endpoints or the Rise-X MCP) when you can.
565
+
425
566
  ## Query layer (react-query)
426
567
 
427
568
  `@rise-x/apps-sdk/query` wraps the connectors in a
@@ -457,14 +598,36 @@ shared: {
457
598
  }
458
599
  ```
459
600
 
601
+ **Using react-query directly? Wrap the app in `AppQueryProvider`.** The SDK
602
+ hooks pass their client explicitly, so they never touch context — but plain
603
+ react-query APIs do, and standalone dev has no provider for them to find:
604
+ `useQuery(flowQueries.list(args))`, `useQueryClient()` and the devtools all
605
+ throw *"No QueryClient set"*. `AppQueryProvider` publishes the **resolved**
606
+ client, so it is safe in both worlds — inside a host it re-publishes the very
607
+ client the shell mounted (nothing shadowed, cache still shell-managed), and
608
+ standalone it publishes the per-bundle fallback. Mounting a client of your own
609
+ is the thing that breaks shell-managed caching:
610
+
611
+ ```tsx
612
+ import { AppQueryProvider } from '@rise-x/apps-sdk/query';
613
+
614
+ export default function App() {
615
+ return (
616
+ <AppQueryProvider>
617
+ <MyScreens />
618
+ </AppQueryProvider>
619
+ );
620
+ }
621
+ ```
622
+
460
623
  Read hooks (all take an optional trailing `SdkQueryOptions` — `enabled`,
461
624
  `staleTime`, `retry`, …):
462
625
 
463
626
  | Domain | Hooks |
464
627
  | --- | --- |
465
628
  | flows | `useFlows`, `useFlow`, `useFlowConfig`, `useFlowLayout`, `useFlowTask` |
466
- | work | `useWork`, `useWorkData`, `useWorkRows` *(infinite)*, `useRelatedWork`, `useWorkAudit` |
467
- | assets | `useAssetTypes`, `useAsset`, `useAssetSearch`, `useAssetRows` *(infinite)*, `useRelatedAssets` |
629
+ | work | `useWork`, `useWorkData`, `useWorkRows` *(infinite)*, `useWorkSearch` *(infinite)*, `useRelatedWork`, `useWorkAudit` |
630
+ | assets | `useAssetTypes`, `useAsset`, `useAssetSearch` *(infinite)*, `useAssetQuickSearch`, `useAssetRows` *(infinite)*, `useRelatedAssets` |
468
631
  | agents | `useAgents`, `useAgent`, `useAgentChats`, `useAgentChat`, `useAgentChatMessages` |
469
632
 
470
633
  Mutation hooks compose your `onSuccess` with built-in invalidation (e.g.
@@ -479,7 +642,20 @@ Details worth knowing:
479
642
  - **Keys are environment-scoped.** Every key is
480
643
  `['rise-apps-sdk', envId, …]` — switching ecosystem refetches automatically
481
644
  and the old environment's entries age out. `queryKeys` is exported for
482
- targeted manual invalidation with the exact shapes the hooks use.
645
+ manual invalidation.
646
+
647
+ Its **prefix** shapes take only `envId` (`queryKeys.work.searchAll(envId)`,
648
+ `allRows`, `relatedAll`, …) and are the reliable way to invalidate a whole
649
+ listing. For a **single entry**, don't rebuild the args by hand: every
650
+ args-carrying key normalises its input first, and each domain does it
651
+ differently — search keys off the request body via `searchCacheShape`, while
652
+ `work.rows` and `assets.rows` resolve a flow ref and an asset-type ref through
653
+ helpers that aren't part of the public API. Read the key off the factory
654
+ instead, which is always the one the hook used:
655
+
656
+ ```ts
657
+ queryClient.invalidateQueries({ queryKey: workQueries.search(args).queryKey });
658
+ ```
483
659
  - **Defaults**: `staleTime` 30 s, `gcTime` 5 min, no refetch-on-focus, up to 2
484
660
  retries that skip terminal `ConnectorError` codes (4xx, `NOT_FOUND`,
485
661
  `ABORTED`, …). Override per call or via `createAppQueryClient(overrides)`.
@@ -507,10 +683,16 @@ installShellBridge({
507
683
  });
508
684
  ```
509
685
 
510
- `getApiV4` takes a `V4ApiKey` (`'apps' | 'work' | 'config' | 'attachment'`) — guests
511
- choose which named v4 instance they want and the host forwards the key to
512
- `@diana/core`'s `axios.apiV4(key)`. The host must register every key it intends to
513
- expose via `setupApiV4(key, { baseURL })` before installing the bridge.
686
+ `getApiV4` takes a `V4ApiKey` (`'apps' | 'work' | 'config' | 'attachment' | 'asset'`) —
687
+ guests choose which named v4 instance they want and the host forwards the key to
688
+ `@diana/core`'s `axios.apiV4(key)`. The host registers each key it exposes via
689
+ `setupApiV4(key, { baseURL })` before installing the bridge.
690
+
691
+ `'asset'` is new in 0.7.0 and is the one key a host may leave unregistered: hosts
692
+ built before it either return nothing or throw for that key, so `assets.search()`
693
+ falls back to the `'config'` client, which is where the endpoint was routed
694
+ previously. Register it (pointing at `DIANA_API_V4_ASSET`, defaulting to the v4
695
+ endpoint) to route asset search independently.
514
696
 
515
697
  `ShellBridgeKeeper` (React component in the shell) pushes the current user, environment,
516
698
  and router `navigate` into the bridge via `getMutableShell` — also exported from
@@ -13,7 +13,7 @@ const sse_1 = require("./sse");
13
13
  const types_1 = require("./types");
14
14
  // Agent config registry (rise-x-api, v4 'config' scope).
15
15
  const AGENT_PATH = "/api/v4/config/agent";
16
- // Server-persisted chat store (rise-x-api Phase C). Served by the same
16
+ // Server-persisted chat store. Served by the same
17
17
  // api-config deployable as AGENT_PATH, so it rides the same getApiV4('config')
18
18
  // client — the ai/* prefix is just the AI-runtime data namespace.
19
19
  const AGENT_CHAT_PATH = "/api/v4/ai/agent-chat";
@@ -1,7 +1,8 @@
1
1
  import type { ConnectorDeps } from "./deps";
2
- import { type AssetDetail, type AssetSummary, type AssetType, type WorkDetail } from "./types";
2
+ import { type SearchArgs, type SearchFilter, type SearchPage } from "./search";
3
+ import { type AssetDetail, type AssetSearchSummary, type AssetSummary, type AssetType, type WorkDetail } from "./types";
3
4
  export type AssetTypeRef = string | AssetType;
4
- export interface SearchAssetsArgs {
5
+ export interface QuickSearchAssetsArgs {
5
6
  search?: string;
6
7
  type?: string;
7
8
  typeOriginId?: string;
@@ -10,6 +11,10 @@ export interface SearchAssetsArgs {
10
11
  skip?: number;
11
12
  signal?: AbortSignal;
12
13
  }
14
+ export type SearchAssetsArgs = SearchArgs & {
15
+ filter: SearchFilter;
16
+ };
17
+ export type AssetSearchPage = SearchPage<AssetSearchSummary>;
13
18
  export interface ListAssetRowsArgs {
14
19
  type: AssetTypeRef;
15
20
  properties?: Record<string, string>;
@@ -55,7 +60,8 @@ export interface AssetsConnector {
55
60
  get(assetId: string, opts?: {
56
61
  signal?: AbortSignal;
57
62
  }): Promise<AssetDetail>;
58
- search(args: SearchAssetsArgs): Promise<AssetSummary[]>;
63
+ search(args: SearchAssetsArgs): Promise<AssetSearchPage>;
64
+ quickSearch(args: QuickSearchAssetsArgs): Promise<AssetSummary[]>;
59
65
  list(args: ListAssetRowsArgs): Promise<AssetRowPage>;
60
66
  iterate(args: IterateAssetRowsArgs): AsyncIterable<AssetSummary>;
61
67
  listRelated(args: ListRelatedAssetsArgs): Promise<AssetSummary[]>;
@@ -12,6 +12,7 @@ exports.assets = exports.ASSET_TARGET_DATA_TYPES = void 0;
12
12
  exports.createAssetsConnector = createAssetsConnector;
13
13
  const _internal_1 = require("../_internal");
14
14
  const errors_1 = require("./errors");
15
+ const search_1 = require("./search");
15
16
  const work_1 = require("./work");
16
17
  const types_1 = require("./types");
17
18
  // DianaDataType wire codes for relationship targets.
@@ -49,9 +50,38 @@ function createAssetsConnector(deps = { shell: _internal_1.requireShell }) {
49
50
  throw (0, errors_1.toConnectorError)(e);
50
51
  }
51
52
  };
53
+ // Asset search gets its own client so a deployment can point it at a host
54
+ // other than config's. Hosts built before the 'asset' key either return
55
+ // nothing for it or throw — getApiV4 is typed non-nullable, so both are
56
+ // conforming, and createMockShell itself throws. Either way fall back to
57
+ // 'config', where this endpoint was routed before and which resolves to the
58
+ // same origin in every profile that doesn't override it.
59
+ const searchApi = () => {
60
+ const shell = deps.shell();
61
+ try {
62
+ const client = shell.getApiV4("asset");
63
+ if (client)
64
+ return client;
65
+ }
66
+ catch {
67
+ // Host doesn't know the key; the fallback below is the whole point.
68
+ }
69
+ return shell.getApiV4("config");
70
+ };
52
71
  const search = async (args) => {
72
+ try {
73
+ const page = args.page ?? 1;
74
+ const pageSize = args.pageSize ?? search_1.DEFAULT_SEARCH_PAGE_SIZE;
75
+ const { data } = await searchApi().post("/api/v4/asset/search", (0, search_1.buildSearchBody)(args, page, pageSize), { signal: args.signal });
76
+ return (0, search_1.toSearchPage)(data, types_1.mapAssetSearchSummary, page, pageSize);
77
+ }
78
+ catch (e) {
79
+ throw (0, errors_1.toConnectorError)(e);
80
+ }
81
+ };
82
+ const quickSearch = async (args) => {
53
83
  if (!args.type && !args.typeOriginId) {
54
- throw new errors_1.ConnectorError("INVALID_ARG", "assets.search needs a type or typeOriginId");
84
+ throw new errors_1.ConnectorError("INVALID_ARG", "assets.quickSearch needs a type or typeOriginId");
55
85
  }
56
86
  try {
57
87
  const { data } = await api().post(
@@ -186,6 +216,7 @@ function createAssetsConnector(deps = { shell: _internal_1.requireShell }) {
186
216
  types,
187
217
  get,
188
218
  search,
219
+ quickSearch,
189
220
  list,
190
221
  iterate,
191
222
  listRelated,
@@ -2,7 +2,8 @@ export type { ConnectorDeps } from "./deps";
2
2
  export { ConnectorError, toConnectorError, type ConnectorErrorCode, } from "./errors";
3
3
  export { createSseParser, iterateSseResponse, type SseEvent, type SseParser, } from "./sse";
4
4
  export * from "./types";
5
+ export { DEFAULT_SEARCH_PAGE_SIZE, searchCacheShape, type SearchArgs, type SearchCondition, type SearchFilter, type SearchOperator, type SearchPage, } from "./search";
5
6
  export { createFlowsConnector, findTaskIn, flattenLayoutFields, flows, type FindTaskArgs, type FindTaskResult, type FlowsConnector, type ListFlowsArgs, } from "./flows";
6
- export { createWorkConnector, work, type FlowRef, type IterateWorkRowsArgs, type ListRelatedWorkArgs, type ListWorkRowsArgs, type StartWorkArgs, type SubmitWorkArgs, type WorkConnector, type WorkDataPatch, type WorkPatchOperation, type WorkRowPage, } from "./work";
7
- export { ASSET_TARGET_DATA_TYPES, assets, createAssetsConnector, type AssetRowPage, type AssetsConnector, type AssetTypeRef, type CreateAssetArgs, type IterateAssetRowsArgs, type ListAssetRowsArgs, type ListRelatedAssetsArgs, type SearchAssetsArgs, type StartEditAssetArgs, } from "./assets";
7
+ export { createWorkConnector, work, type FlowRef, type IterateWorkRowsArgs, type ListRelatedWorkArgs, type ListWorkRowsArgs, type SearchWorkArgs, type StartWorkArgs, type SubmitWorkArgs, type WorkConnector, type WorkDataPatch, type WorkPatchOperation, type WorkRowPage, type WorkSearchPage, } from "./work";
8
+ export { ASSET_TARGET_DATA_TYPES, assets, createAssetsConnector, type AssetRowPage, type AssetSearchPage, type AssetsConnector, type AssetTypeRef, type CreateAssetArgs, type IterateAssetRowsArgs, type ListAssetRowsArgs, type ListRelatedAssetsArgs, type QuickSearchAssetsArgs, type SearchAssetsArgs, type StartEditAssetArgs, } from "./assets";
8
9
  export { agentEndReason, agentErrorText, agentMessageText, agents, collectAgentReply, createAgentsConnector, streamAgentReply, type AgentChatSession, type AgentReplyState, type AgentsConnector, type GetChatMessagesArgs, type ListAgentsArgs, type ListChatsArgs, type RunAgentArgs, type SendChatArgs, } from "./agents";
@@ -20,7 +20,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
20
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.streamAgentReply = exports.createAgentsConnector = exports.collectAgentReply = exports.agents = exports.agentMessageText = exports.agentErrorText = exports.agentEndReason = exports.createAssetsConnector = exports.assets = exports.ASSET_TARGET_DATA_TYPES = exports.work = exports.createWorkConnector = exports.flows = exports.flattenLayoutFields = exports.findTaskIn = exports.createFlowsConnector = exports.iterateSseResponse = exports.createSseParser = exports.toConnectorError = exports.ConnectorError = void 0;
23
+ exports.streamAgentReply = exports.createAgentsConnector = exports.collectAgentReply = exports.agents = exports.agentMessageText = exports.agentErrorText = exports.agentEndReason = exports.createAssetsConnector = exports.assets = exports.ASSET_TARGET_DATA_TYPES = exports.work = exports.createWorkConnector = exports.flows = exports.flattenLayoutFields = exports.findTaskIn = exports.createFlowsConnector = exports.searchCacheShape = exports.DEFAULT_SEARCH_PAGE_SIZE = exports.iterateSseResponse = exports.createSseParser = exports.toConnectorError = exports.ConnectorError = void 0;
24
24
  var errors_1 = require("./errors");
25
25
  Object.defineProperty(exports, "ConnectorError", { enumerable: true, get: function () { return errors_1.ConnectorError; } });
26
26
  Object.defineProperty(exports, "toConnectorError", { enumerable: true, get: function () { return errors_1.toConnectorError; } });
@@ -28,6 +28,9 @@ var sse_1 = require("./sse");
28
28
  Object.defineProperty(exports, "createSseParser", { enumerable: true, get: function () { return sse_1.createSseParser; } });
29
29
  Object.defineProperty(exports, "iterateSseResponse", { enumerable: true, get: function () { return sse_1.iterateSseResponse; } });
30
30
  __exportStar(require("./types"), exports);
31
+ var search_1 = require("./search");
32
+ Object.defineProperty(exports, "DEFAULT_SEARCH_PAGE_SIZE", { enumerable: true, get: function () { return search_1.DEFAULT_SEARCH_PAGE_SIZE; } });
33
+ Object.defineProperty(exports, "searchCacheShape", { enumerable: true, get: function () { return search_1.searchCacheShape; } });
31
34
  var flows_1 = require("./flows");
32
35
  Object.defineProperty(exports, "createFlowsConnector", { enumerable: true, get: function () { return flows_1.createFlowsConnector; } });
33
36
  Object.defineProperty(exports, "findTaskIn", { enumerable: true, get: function () { return flows_1.findTaskIn; } });
@@ -0,0 +1,34 @@
1
+ export type SearchOperator = "equals" | "notEquals" | "in" | "notIn" | "contains" | "startsWith" | "endsWith" | "greaterThan" | "greaterThanOrEqual" | "lessThan" | "lessThanOrEqual" | "between" | "exists" | "notExists";
2
+ export interface SearchCondition {
3
+ field: string;
4
+ operator: SearchOperator;
5
+ values?: unknown[];
6
+ }
7
+ export type SearchFilter = SearchCondition | {
8
+ and: SearchFilter[];
9
+ } | {
10
+ or: SearchFilter[];
11
+ };
12
+ export interface SearchArgs {
13
+ filter?: SearchFilter;
14
+ sort?: {
15
+ field: string;
16
+ direction?: "asc" | "desc";
17
+ }[];
18
+ page?: number;
19
+ pageSize?: number;
20
+ fields?: string[];
21
+ includeTotalCount?: boolean;
22
+ signal?: AbortSignal;
23
+ }
24
+ export interface SearchPage<TItem> {
25
+ items: TItem[];
26
+ page: number;
27
+ pageSize: number;
28
+ hasMore: boolean;
29
+ totalCount?: number;
30
+ }
31
+ export declare const DEFAULT_SEARCH_PAGE_SIZE = 25;
32
+ export declare function buildSearchBody(args: SearchArgs, page: number, pageSize: number): Record<string, unknown>;
33
+ export declare function searchCacheShape(args: SearchArgs): Record<string, unknown>;
34
+ export declare function toSearchPage<TItem>(data: Record<string, unknown> | undefined, mapItem: (raw: unknown) => TItem, page: number, pageSize: number): SearchPage<TItem>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ // The v4 search grammar, shared by every searchable resource. One search
3
+ // service on the server backs `/api/v4/work/search` and `/api/v4/asset/search`
4
+ // alike, so the operator set, filter tree, request body and page envelope are
5
+ // identical across domains — only the row type and the whitelist of field
6
+ // names differ.
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.DEFAULT_SEARCH_PAGE_SIZE = void 0;
9
+ exports.buildSearchBody = buildSearchBody;
10
+ exports.searchCacheShape = searchCacheShape;
11
+ exports.toSearchPage = toSearchPage;
12
+ // Server default for the v4 search endpoints; they cap pageSize at 100, so
13
+ // larger values are clamped there, not here.
14
+ exports.DEFAULT_SEARCH_PAGE_SIZE = 25;
15
+ function buildSearchBody(args, page, pageSize) {
16
+ const fields = args.fields ?? [];
17
+ return {
18
+ filter: args.filter,
19
+ sort: args.sort?.map((s) => ({
20
+ field: s.field,
21
+ order: s.direction ?? "desc",
22
+ })),
23
+ page,
24
+ pageSize,
25
+ fields: fields.length ? fields : undefined,
26
+ // The server ignores `fields` unless this is set.
27
+ enforceFields: fields.length > 0,
28
+ includeTotalCount: args.includeTotalCount ?? false,
29
+ };
30
+ }
31
+ // The cache shape of a search: the request body minus the page cursor. Any two
32
+ // arg sets that produce the same request therefore produce the same key, so a
33
+ // default `buildSearchBody` fills in can never split one request across two
34
+ // cache entries — `fields: []`, `includeTotalCount: false`, an explicit
35
+ // `pageSize: DEFAULT_SEARCH_PAGE_SIZE` and a `sort` entry spelling out the
36
+ // default `desc` all collapse here exactly as they do on the wire.
37
+ //
38
+ // Derived from the body on purpose: a hand-kept list of collapsible args in the
39
+ // query layer drifts silently the moment a default is added to buildSearchBody.
40
+ // `signal` never reaches the key either, since the body has no place for it.
41
+ //
42
+ // LOAD-BEARING: this is only equivalent to keying off the request while the body
43
+ // IS the whole request — every caller POSTs a constant path and passes nothing
44
+ // but `signal` in the axios config. Add an arg that changes the URL, a header or
45
+ // a query param without putting it in the body and two different searches start
46
+ // sharing one cache entry, which serves wrong rows rather than merely duplicating
47
+ // work — the opposite, and worse, failure mode to the over-keying this replaced.
48
+ function searchCacheShape(args) {
49
+ const { page: _page, ...body } = buildSearchBody(args, 1, args.pageSize ?? exports.DEFAULT_SEARCH_PAGE_SIZE);
50
+ return Object.fromEntries(Object.entries(body).filter(([, value]) => value !== undefined));
51
+ }
52
+ // `page`/`pageSize` are the values that were requested — used only when the
53
+ // response omits its own echo of them.
54
+ function toSearchPage(data, mapItem, page, pageSize) {
55
+ const items = Array.isArray(data?.items) ? data.items : [];
56
+ return {
57
+ items: items.map(mapItem),
58
+ page: typeof data?.page === "number" ? data.page : page,
59
+ pageSize: typeof data?.pageSize === "number" ? data.pageSize : pageSize,
60
+ hasMore: data?.hasMore === true,
61
+ totalCount: typeof data?.totalCount === "number" ? data.totalCount : undefined,
62
+ };
63
+ }
@@ -94,6 +94,37 @@ export interface WorkDetail {
94
94
  actions: WorkAction[];
95
95
  }
96
96
  export declare function mapWorkDetail(value: unknown): WorkDetail;
97
+ export interface WorkUser {
98
+ id?: string;
99
+ displayName?: string;
100
+ email?: string;
101
+ }
102
+ export interface ResourceStatusDisplay {
103
+ displayName?: string;
104
+ color?: string;
105
+ icon?: string;
106
+ stateName?: string;
107
+ roleName?: string;
108
+ }
109
+ export interface WorkSummary {
110
+ id: string;
111
+ displayName: string;
112
+ name?: string;
113
+ workCode?: string;
114
+ flowId?: string;
115
+ flowOriginId?: string;
116
+ flowDisplayName?: string;
117
+ status?: string;
118
+ flowState?: string;
119
+ statusDisplay?: ResourceStatusDisplay;
120
+ assignedUsers: WorkUser[];
121
+ created?: string;
122
+ lastModified?: string;
123
+ createdBy?: string;
124
+ lastModifiedBy?: string;
125
+ data?: Record<string, unknown>;
126
+ }
127
+ export declare function mapWorkSummary(value: unknown): WorkSummary;
97
128
  export interface WorkAuditFieldUpdate {
98
129
  path: string;
99
130
  fromValue?: string;
@@ -151,6 +182,26 @@ export interface AssetDetail extends AssetSummary {
151
182
  relationships: AssetRelationship[];
152
183
  }
153
184
  export declare function mapAssetDetail(value: unknown): AssetDetail;
185
+ export interface AssetSearchSummary {
186
+ id: string;
187
+ displayName: string;
188
+ normalisedName?: string;
189
+ entityType?: string;
190
+ code?: string;
191
+ status?: string;
192
+ flowId?: string;
193
+ flowOriginId?: string;
194
+ flowType?: string;
195
+ companyId?: string;
196
+ sequence?: number;
197
+ statusDisplay?: ResourceStatusDisplay;
198
+ created?: string;
199
+ lastModified?: string;
200
+ createdBy?: string;
201
+ lastModifiedBy?: string;
202
+ data?: Record<string, unknown>;
203
+ }
204
+ export declare function mapAssetSearchSummary(value: unknown): AssetSearchSummary;
154
205
  export type McpTransport = "Http" | "Sse" | "Stdio";
155
206
  export type McpAuthType = "None" | "Bearer" | "ApiKey" | "CallerToken";
156
207
  export interface McpServerConfig {
@@ -18,10 +18,12 @@ exports.mapFlowConfig = mapFlowConfig;
18
18
  exports.mapLayout = mapLayout;
19
19
  exports.mapWorkRow = mapWorkRow;
20
20
  exports.mapWorkDetail = mapWorkDetail;
21
+ exports.mapWorkSummary = mapWorkSummary;
21
22
  exports.mapWorkAuditEvent = mapWorkAuditEvent;
22
23
  exports.mapAssetType = mapAssetType;
23
24
  exports.mapAssetSummary = mapAssetSummary;
24
25
  exports.mapAssetDetail = mapAssetDetail;
26
+ exports.mapAssetSearchSummary = mapAssetSearchSummary;
25
27
  exports.mapMcpServerConfig = mapMcpServerConfig;
26
28
  exports.mapAgent = mapAgent;
27
29
  exports.mapAgentPage = mapAgentPage;
@@ -33,6 +35,11 @@ const str = (v) => typeof v === "string" && v !== "" ? v : undefined;
33
35
  // Mappers accept `unknown` so call sites can feed raw axios payloads directly;
34
36
  // anything non-object maps as an empty record (tolerant by contract).
35
37
  const asRecord = (value) => value !== null && typeof value === "object" ? value : {};
38
+ // Sub-documents only: an absent one can round-trip as `[]`, which `typeof` calls
39
+ // an object, so an array must not be mistaken for a populated sub-document.
40
+ const subDoc = (value) => value !== null && typeof value === "object" && !Array.isArray(value)
41
+ ? value
42
+ : undefined;
36
43
  function mapFlowSummary(value) {
37
44
  const raw = asRecord(value);
38
45
  const id = String(raw.id ?? "");
@@ -160,6 +167,47 @@ function mapWorkDetail(value) {
160
167
  })),
161
168
  };
162
169
  }
170
+ const mapStatusDisplay = (value) => {
171
+ const raw = subDoc(value);
172
+ if (!raw)
173
+ return undefined;
174
+ return {
175
+ displayName: str(raw.displayName),
176
+ color: str(raw.color),
177
+ icon: str(raw.icon),
178
+ stateName: str(raw.stateName),
179
+ roleName: str(raw.roleName),
180
+ };
181
+ };
182
+ function mapWorkSummary(value) {
183
+ const raw = asRecord(value);
184
+ const id = String(raw.id ?? "");
185
+ const users = Array.isArray(raw.assignedUsers)
186
+ ? raw.assignedUsers
187
+ : [];
188
+ return {
189
+ id,
190
+ displayName: str(raw?.displayName) ?? str(raw?.name) ?? str(raw?.workCode) ?? id,
191
+ name: str(raw?.name),
192
+ workCode: str(raw?.workCode),
193
+ flowId: str(raw?.flowId),
194
+ flowOriginId: str(raw?.flowOriginId),
195
+ flowDisplayName: str(raw?.flowDisplayName),
196
+ status: str(raw?.status),
197
+ flowState: str(raw?.flowState),
198
+ statusDisplay: mapStatusDisplay(raw?.statusDisplay),
199
+ assignedUsers: users.map((u) => ({
200
+ id: str(u?.id),
201
+ displayName: str(u?.displayName),
202
+ email: str(u?.email),
203
+ })),
204
+ created: str(raw?.created),
205
+ lastModified: str(raw?.lastModified),
206
+ createdBy: str(raw?.createdBy),
207
+ lastModifiedBy: str(raw?.lastModifiedBy),
208
+ data: subDoc(raw?.data),
209
+ };
210
+ }
163
211
  function mapWorkAuditEvent(value) {
164
212
  const raw = asRecord(value);
165
213
  const activity = raw.activity && typeof raw.activity === "object" ? raw.activity : {};
@@ -237,6 +285,29 @@ function mapAssetDetail(value) {
237
285
  })),
238
286
  };
239
287
  }
288
+ function mapAssetSearchSummary(value) {
289
+ const raw = asRecord(value);
290
+ const id = String(raw.id ?? "");
291
+ return {
292
+ id,
293
+ displayName: str(raw?.displayName) ?? str(raw?.normalisedName) ?? id,
294
+ normalisedName: str(raw?.normalisedName),
295
+ entityType: str(raw?.entityType),
296
+ code: str(raw?.code),
297
+ status: str(raw?.status),
298
+ flowId: str(raw?.flowId),
299
+ flowOriginId: str(raw?.flowOriginId),
300
+ flowType: str(raw?.flowType),
301
+ companyId: str(raw?.companyId),
302
+ sequence: typeof raw?.sequence === "number" ? raw.sequence : undefined,
303
+ statusDisplay: mapStatusDisplay(raw?.statusDisplay),
304
+ created: str(raw?.created),
305
+ lastModified: str(raw?.lastModified),
306
+ createdBy: str(raw?.createdBy),
307
+ lastModifiedBy: str(raw?.lastModifiedBy),
308
+ data: subDoc(raw?.data),
309
+ };
310
+ }
240
311
  function mapMcpServerConfig(value) {
241
312
  const raw = asRecord(value);
242
313
  return {