@rise-x/apps-sdk 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +11 -6
- package/README.md +111 -0
- package/build/connectors/agents.d.ts +5 -0
- package/build/connectors/agents.js +40 -0
- package/build/connectors/assets.js +2 -1
- package/build/connectors/index.d.ts +3 -2
- package/build/connectors/index.js +3 -1
- package/build/connectors/project.d.ts +7 -0
- package/build/connectors/project.js +58 -0
- package/build/connectors/types.d.ts +16 -0
- package/build/connectors/types.js +22 -8
- package/build/connectors/work.d.ts +37 -0
- package/build/connectors/work.js +89 -7
- package/build/dictation/index.d.ts +34 -0
- package/build/dictation/index.js +205 -0
- package/build/query/assets.js +25 -17
- package/build/query/shared.d.ts +16 -1
- package/build/query/shared.js +20 -2
- package/build/query/work.js +25 -17
- package/build/ui/demo.html +130 -130
- package/build/ui/standalone.js +12 -12
- package/dictation/package.json +8 -0
- package/package.json +6 -1
package/API.md
CHANGED
|
@@ -9,8 +9,9 @@ anything it leaves out, follow the pointers in "Where to look next".
|
|
|
9
9
|
- `@rise-x/apps-sdk`: shell hooks and accessors, lifecycle hook types, `createMockShell`.
|
|
10
10
|
- `@rise-x/apps-sdk/dependencies`: `useAppDependencies()`, the ids from `rise-x-app.json` with bound calls.
|
|
11
11
|
- `@rise-x/apps-sdk/query`: react-query hooks over the connectors. Mount no provider of your own.
|
|
12
|
-
- `@rise-x/apps-sdk/connectors`: `flows`, `work`, `assets`, `agents`, `attachments`, `integrations`, `vectorStores`, `ConnectorError`.
|
|
12
|
+
- `@rise-x/apps-sdk/connectors`: `flows`, `work`, `assets`, `agents`, `attachments`, `integrations`, `vectorStores`, `projectDataPaths`, `ConnectorError`.
|
|
13
13
|
- `@rise-x/apps-sdk/live`: live events and editor locks.
|
|
14
|
+
- `@rise-x/apps-sdk/dictation`: `useDictation()`, the user's speech as text, for a mic button.
|
|
14
15
|
- `@rise-x/apps-sdk/ui`: the design system components.
|
|
15
16
|
|
|
16
17
|
To reach the platform, use the first that fits: a declared dependency, a query
|
|
@@ -52,7 +53,7 @@ Read hooks take an optional last `SdkQueryOptions` (`enabled`, `staleTime`,
|
|
|
52
53
|
- Work: `useWork(workId)` (`WorkDetail | null`), `useWorkData(workId, { path? })`, `useWorkSearch(args)` and `useWorkRows(args)` (infinite), `useRelatedWork(args)`, `useWorkAudit(workId)`.
|
|
53
54
|
- Assets: `useAssetTypes()`, `useAsset(id)`, `useAssetSearch(args)` and `useAssetRows(args)` (infinite), `useAssetQuickSearch(args)`, `useRelatedAssets(args)`.
|
|
54
55
|
- Agents: `useAgents(args?)`, `useAgent(id)`, `useAgentChats(args?)`, `useAgentChat(id)`, `useAgentChatMessages(id, args?)`.
|
|
55
|
-
- Mutations: `useStartWork`, `usePatchWorkData` (`{ workId, originId, path, value }`), `useSubmitWork` (`{ workId, actionName, stepName? }`), `useDeleteWork` (`{ workId }`), and the asset and agent ones. On success they refresh the queries the write affects.
|
|
56
|
+
- Mutations: `useStartWork`, `usePatchWorkData` (`{ workId, originId, path, value }`), `useSubmitWork` (`{ workId, actionName, stepName?, to?, cc?, invitation? }`), `useDeleteWork` (`{ workId }`), and the asset and agent ones. On success they refresh the queries the write affects. Those that refresh cached searches take `invalidateSearches`: `true` (default), `false`, or `'unlessLive'`, which leaves `useWorkSearch` and `useAssetSearch` alone while live events are connected.
|
|
56
57
|
- Connector calls refresh nothing. Take `const client = useAppQueryClient()` in the component body, and after a raw connector write call `invalidateAppSdkQueries(client)`.
|
|
57
58
|
- `dedupeRows(query.data)` flattens the pages of an infinite hook and drops repeated rows.
|
|
58
59
|
- `useLiveInvalidation({ flowOriginIds? })` marks work and asset queries stale when a live event reports a change.
|
|
@@ -74,10 +75,11 @@ const rows = dedupeRows(search.data); // WorkSummary[]; key them by row.id
|
|
|
74
75
|
Work:
|
|
75
76
|
- `work.start({ flowId, stepName?, data? })` returns the new item's `WorkDetail`, the same as `work.get`, so its `actions` are ready for `work.submit`. `flowId` takes a flow id or a flow origin id.
|
|
76
77
|
If the SDK can't read the new item back, `start` still returns it, with `actions` empty and no `status`: call `work.get(id)` before you submit.
|
|
77
|
-
- `work.get(id)` returns `WorkDetail | null` (`null` only on a 404): `status`, `state`, `flowOriginId`, `actions`, `attachments`.
|
|
78
|
+
- `work.get(id)` returns `WorkDetail | null` (`null` only on a 404): `status`, `statusDisplay`, `state`, `flowOriginId`, `assignedUsers`, `created`, `lastModified`, `createdBy`, `lastModifiedBy`, `activeLocks`, `actions`, `attachments`.
|
|
79
|
+
- `work.getSummary(id, { fields })` reads one item now and returns a `WorkSummary` shaped like a search row, with `data` projected to the `data.*` paths in `fields`. `projectDataPaths(doc, paths)` is the projection on its own.
|
|
78
80
|
- `work.getData(id, { path? })` returns the data document, or the subtree at `path`.
|
|
79
81
|
- `work.patchData(id, { originId, path, value, operation? })` writes one field. `operation` defaults to `'Set'`.
|
|
80
|
-
- `work.submit({ workId, actionName, stepName? })` runs an action and returns the `WorkDetail` after the flow engine ran, the same as `work.get`. The same rule as `start` applies when the SDK can't read the item back. Leave `stepName` out: the SDK sends the name of the action set that offers the action.
|
|
82
|
+
- `work.submit({ workId, actionName, stepName?, to?, cc?, invitation? })` runs an action and returns the `WorkDetail` after the flow engine ran, the same as `work.get`. The same rule as `start` applies when the SDK can't read the item back. Leave `stepName` out: the SDK sends the name of the action set that offers the action.
|
|
81
83
|
- `work.delete(id)` soft-deletes the item.
|
|
82
84
|
- `work.search({ filter, fields?, sort?, page?, pageSize?, includeTotalCount? })` returns `{ items: WorkSummary[], page, pageSize, hasMore, totalCount? }`.
|
|
83
85
|
- `work.list({ flow, stepIds?, properties?, showCompleted?, sort?, pageSize?, skip? })` returns `{ items: WorkRow[], skip, pageSize, hasMore }`. `work.iterate({ ..., maxItems? })` yields every row.
|
|
@@ -97,12 +99,13 @@ and `assets.startEdit({ assetId, flowOriginId })` return an `AssetDraft`: the dr
|
|
|
97
99
|
work item as `work.get` returns it, plus `assetId`. Its `id` is the draft's, so fill
|
|
98
100
|
it with `work.patchData(draft.id, ...)` and save it with `work.submit` and one of its
|
|
99
101
|
`actions`. If the read of the draft fails, `actions` is empty: call `work.get(draft.id)`
|
|
100
|
-
before you submit. If the answer names no draft, the call throws `PARSE_ERROR
|
|
102
|
+
before you submit. If the answer names no draft, the call throws `PARSE_ERROR` with
|
|
103
|
+
the answered `AssetDetail` as its `cause`: after `create`, that asset exists, empty.
|
|
101
104
|
`assets.clone(id)` and `assets.delete(id)` complete the set.
|
|
102
105
|
|
|
103
106
|
Agents: `agents.run({ agentId, message, chatId?, context?, attachments?, vectorStoreIds? })`
|
|
104
107
|
streams `AgentRunEvent`s. `agents.createChat({ agentId })` returns a session whose
|
|
105
|
-
`send(message)` keeps the chat id between turns. `collectAgentReply(events)`
|
|
108
|
+
`send(message)` keeps the chat id between turns. `agents.transcribe(blob, { language?, signal? })` resolves with the speech in an audio clip as text. `collectAgentReply(events)`
|
|
106
109
|
resolves to `{ text, delta, done, reason, error, chatId }`, and `streamAgentReply(events)`
|
|
107
110
|
yields the same snapshot as the reply grows. `agents.list`, `get`, `create`,
|
|
108
111
|
`update`, `delete`, and the chat calls manage agents and their chats.
|
|
@@ -134,6 +137,8 @@ await work.submit({ workId, actionName: chosen.eventName ?? chosen.name! });
|
|
|
134
137
|
- `work.patchData` changes a field and runs no action. `work.submit` moves the step: approve, reject, send back, finish. Await `patchData` first: submit merges no data, and the platform checks the action's condition against the saved data.
|
|
135
138
|
- Take `actionName` from the item's own `actions`, as `eventName ?? name` of the action the user picked. Never guess a name or take `actions[0]`. The platform rejects a name that is not an action of the step with a 403 and leaves the item unchanged.
|
|
136
139
|
- `work.submit` reads the item and its flow config, finds the action set that offers the action, and sends that action set's name as `stepName`. Pass `stepName` only to pick between two action sets that offer the same action: the `name` of the entry in `flows.getConfig(detail.flowId)`'s `tasks[].actionSets` whose `id` is the picked action's `actionSetId`. Never pass a step or task name: with `Submit`, the platform answers 200 and the item doesn't move.
|
|
140
|
+
- Each action's `destinations` lists the steps it moves the item to and the default invitees: `toEmails`/`ccEmails`, and `toDataPaths`/`ccDataPaths` the platform resolves against the work data when the action runs. Show them before a submit to say who the item goes to next.
|
|
141
|
+
- `to`/`cc` on `work.submit` (`{ email?, id?, name?, partyName? }[]`) add invitees on top of those defaults, in every destination of the action. The SDK reads the item to find those destinations; if it can't, the call rejects and nothing is submitted. A CC invitee gets read-only access. A CC invite set on the target task does not invite anyone on its own: pass those people in `cc`. `invitation` sends the platform's raw `{ destinations }` body instead; it can't be combined with `to`/`cc`.
|
|
137
142
|
- `work.list` and `work.iterate` filter strictly by flow origin id. A concrete flow id returns an empty list, not an error. Pass the flow object or `dep.flowOriginId`.
|
|
138
143
|
- `work.search` and `assets.search` need a `flowOriginId` `equals` or `in` condition at the top level or under `and`. Without it the server returns a 400.
|
|
139
144
|
- `work.delete` is a soft delete: `status` and `flowState` become `Deleted`, and the record stays. A second delete rejects with `NOT_FOUND`. The SDK has no restore call. `work.search` leaves deleted items out unless the filter names `status`.
|
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ SDK for building federated apps on top of the Rise-X Diana shell.
|
|
|
6
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
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.
|
|
8
8
|
- **Live events and presence** — `@rise-x/apps-sdk/live` lets an app hear about other people's changes and see who is editing, over the host's own connection instead of polling; `useLiveInvalidation` on `@rise-x/apps-sdk/query` keeps the query cache current from the same events.
|
|
9
|
+
- **Dictation** — `useDictation` from `@rise-x/apps-sdk/dictation` records the microphone and returns the speech as text, for a mic button on a text field. See [Dictation](#dictation--speech-to-text).
|
|
9
10
|
- **Lifecycle hooks** — `onInstall`, `onUpdate`, `onUninstall` that apps export from a federated `./lifecycle` module; the shell invokes them best-effort.
|
|
10
11
|
- **Standalone-dev mock** — `createMockShell` for running an app outside the shell.
|
|
11
12
|
- **Shell-side installer** — `@rise-x/apps-sdk/shell` exposes `installShellBridge` for the host to wire the bridge.
|
|
@@ -1119,6 +1120,16 @@ const chosen = detail.actions.find((a) => a.id === pickedActionId);
|
|
|
1119
1120
|
if (!chosen) throw new Error(`Action ${pickedActionId} is not available on this item`);
|
|
1120
1121
|
await work.submit({ workId: created.id, actionName: chosen.eventName ?? chosen.name! });
|
|
1121
1122
|
|
|
1123
|
+
// Or, instead: chosen.destinations shows where the action sends the item and who it invites by
|
|
1124
|
+
// default (toEmails/ccEmails, plus toDataPaths/ccDataPaths resolved on submit).
|
|
1125
|
+
// Add invitees on top with `to`/`cc` — a CC invitee gets read-only access. A CC
|
|
1126
|
+
// invite configured on the target task invites nobody on its own: pass them here.
|
|
1127
|
+
await work.submit({
|
|
1128
|
+
workId: created.id,
|
|
1129
|
+
actionName: chosen.eventName ?? chosen.name!,
|
|
1130
|
+
cc: [{ email: 'viewer@example.com' }],
|
|
1131
|
+
});
|
|
1132
|
+
|
|
1122
1133
|
// Soft-delete a work item: its status becomes Deleted and the record stays.
|
|
1123
1134
|
// A second delete rejects with NOT_FOUND. The SDK has no restore call.
|
|
1124
1135
|
await work.delete(created.id);
|
|
@@ -1144,6 +1155,27 @@ so two different work items can render the same label. `workCode` is the stable
|
|
|
1144
1155
|
_human_ handle — show it, cross-reference it — but it is optional: a flow that
|
|
1145
1156
|
assigns none leaves it `undefined`, which collapses every such row onto one key.
|
|
1146
1157
|
|
|
1158
|
+
`work.get()` also carries what a list row shows: `statusDisplay` (the stage
|
|
1159
|
+
label), `assignedUsers`, `created`, `lastModified`, `createdBy`,
|
|
1160
|
+
`lastModifiedBy`, and `activeLocks` (who has an editor open on the work, see
|
|
1161
|
+
[Live updates](#live-updates-rise-xapps-sdklive)). To bring one row of a list
|
|
1162
|
+
up to date after a change, without reading the list again, use
|
|
1163
|
+
`work.getSummary(id, { fields })`: it reads the work and, for any `data.*` path in
|
|
1164
|
+
`fields`, its data document, straight from the platform (never the offline cache),
|
|
1165
|
+
and returns a `WorkSummary` shaped like a search row. `row.data` carries only the
|
|
1166
|
+
paths you asked for, as a search projection does. It resolves `null` when the
|
|
1167
|
+
work does not exist.
|
|
1168
|
+
|
|
1169
|
+
```ts
|
|
1170
|
+
const row = await work.getSummary(workId, {
|
|
1171
|
+
fields: ['status', 'statusDisplay', 'assignedUsers', 'data.pricing.rate'],
|
|
1172
|
+
});
|
|
1173
|
+
```
|
|
1174
|
+
|
|
1175
|
+
`projectDataPaths(document, paths)` (also from `/connectors`) is the projection
|
|
1176
|
+
on its own: it copies dotted paths (`section.field`, without the `data.` prefix)
|
|
1177
|
+
out of a data document, for rebuilding a row from a document you already hold.
|
|
1178
|
+
|
|
1147
1179
|
`WorkDetail.attachments` (from `work.get()`) lists the work's attachments as of
|
|
1148
1180
|
that read — links mapped from the v4 document, not the bytes themselves. Fetch
|
|
1149
1181
|
the bytes with `attachments.getBlob()`:
|
|
@@ -1401,6 +1433,76 @@ await agents.renameChat(one.id, 'Q3 risk review');
|
|
|
1401
1433
|
await agents.deleteChat(one.id); // removes the chat and its messages
|
|
1402
1434
|
```
|
|
1403
1435
|
|
|
1436
|
+
### Dictation — speech to text
|
|
1437
|
+
|
|
1438
|
+
`useDictation` records the user's default microphone and returns what they said
|
|
1439
|
+
as text. It uses the same speech-to-text as Ask Diana. Nothing is stored: no
|
|
1440
|
+
chat or run is created, and the audio is not kept.
|
|
1441
|
+
|
|
1442
|
+
```tsx
|
|
1443
|
+
import { useDictation } from '@rise-x/apps-sdk/dictation';
|
|
1444
|
+
|
|
1445
|
+
function NoteField() {
|
|
1446
|
+
const [note, setNote] = useState('');
|
|
1447
|
+
const { supported, state, error, start, stop, cancel } = useDictation({
|
|
1448
|
+
language: 'en', // optional ISO-639-1 hint; omit it to detect the language
|
|
1449
|
+
onText: (text) => setNote((current) => `${current} ${text}`.trim()),
|
|
1450
|
+
});
|
|
1451
|
+
|
|
1452
|
+
return (
|
|
1453
|
+
<>
|
|
1454
|
+
<textarea value={note} onChange={(e) => setNote(e.target.value)} />
|
|
1455
|
+
{supported && (
|
|
1456
|
+
<button
|
|
1457
|
+
disabled={state === 'transcribing'}
|
|
1458
|
+
onClick={() => (state === 'recording' ? stop() : start())}
|
|
1459
|
+
>
|
|
1460
|
+
{state === 'recording' ? 'Stop' : state === 'transcribing' ? 'Transcribing…' : 'Dictate'}
|
|
1461
|
+
</button>
|
|
1462
|
+
)}
|
|
1463
|
+
{error === 'denied' && <p>Allow microphone access in your browser to dictate.</p>}
|
|
1464
|
+
{error === 'failed' && <p>Dictation did not work. Try again.</p>}
|
|
1465
|
+
</>
|
|
1466
|
+
);
|
|
1467
|
+
}
|
|
1468
|
+
```
|
|
1469
|
+
|
|
1470
|
+
| Return | Meaning |
|
|
1471
|
+
| --- | --- |
|
|
1472
|
+
| `supported` | `false` when the browser cannot record audio, or the host has no AI configured. Hide the mic button then. |
|
|
1473
|
+
| `state` | `'idle'`, `'recording'` or `'transcribing'`. |
|
|
1474
|
+
| `error` | `'denied'` when microphone access was refused, `'failed'` for anything else. `null` otherwise. Cleared by the next `start()` or by `cancel()`. |
|
|
1475
|
+
| `start()` | Asks for the microphone and starts recording. Never rejects. Does nothing while recording or transcribing. |
|
|
1476
|
+
| `stop()` | Ends the recording, transcribes it and calls `onText` with the result. |
|
|
1477
|
+
| `cancel()` | Ends the recording and discards it, or abandons a transcription in flight. `onText` is not called. |
|
|
1478
|
+
|
|
1479
|
+
The text arrives in one piece after `stop()`. There are no interim words while
|
|
1480
|
+
the user speaks. The hook releases the microphone on `stop()`, `cancel()` and
|
|
1481
|
+
unmount.
|
|
1482
|
+
|
|
1483
|
+
Limits:
|
|
1484
|
+
|
|
1485
|
+
- Dictation records the browser's default microphone. There is no device picker.
|
|
1486
|
+
- A clip shorter than 600 ms is discarded without a request, and `onText` is not
|
|
1487
|
+
called. Near-silence makes the model invent words.
|
|
1488
|
+
- The host must have AI configured. In standalone dev, `supported` stays `false`
|
|
1489
|
+
until `createMockShell` is given an `ai` gateway (see [Standalone dev](#standalone-dev)).
|
|
1490
|
+
|
|
1491
|
+
To transcribe audio you already hold (a recorded or uploaded `Blob`), call the
|
|
1492
|
+
connector directly. It is stateless and returns `''` when the model heard no
|
|
1493
|
+
speech:
|
|
1494
|
+
|
|
1495
|
+
```ts
|
|
1496
|
+
import { agents } from '@rise-x/apps-sdk/connectors';
|
|
1497
|
+
|
|
1498
|
+
const text = await agents.transcribe(blob, { language: 'en', signal });
|
|
1499
|
+
```
|
|
1500
|
+
|
|
1501
|
+
It fails like `agents.run`: `AI_UNAVAILABLE` when the host has no AI configured,
|
|
1502
|
+
`SHELL_TOO_OLD` on a host that predates `getAi`, `HTTP_ERROR` for a rejected
|
|
1503
|
+
clip (for example one that is too large), `ABORTED` when `signal` fires, and
|
|
1504
|
+
`INVALID_ARG` for an empty `Blob`.
|
|
1505
|
+
|
|
1404
1506
|
### Vector stores
|
|
1405
1507
|
|
|
1406
1508
|
Search-ready document stores an agent's `file_search` tool reads from —
|
|
@@ -1800,6 +1902,15 @@ Details worth knowing:
|
|
|
1800
1902
|
queryOptions factories directly — `useQuery(flowQueries.list(args))`,
|
|
1801
1903
|
`queryClient.prefetchQuery(workQueries.detail(id))`. `useAppQueryClient()`
|
|
1802
1904
|
returns the same client the hooks use.
|
|
1905
|
+
- **Searches and live updates.** A search is cached on the platform for a couple
|
|
1906
|
+
of minutes, so reading one again right after a write can return the rows as
|
|
1907
|
+
they were, and overwrite a list you have already updated from live events.
|
|
1908
|
+
Every mutation hook that would invalidate cached searches (`useWorkSearch`,
|
|
1909
|
+
`useAssetSearch`) takes `invalidateSearches`: `true` (default), `false`, or
|
|
1910
|
+
`'unlessLive'`, which leaves the searches alone while `useLiveStatus()` is
|
|
1911
|
+
`connected` and invalidates them as before when it is not. Everything else
|
|
1912
|
+
the hook invalidates (the work's detail and data, row listings, the audit
|
|
1913
|
+
trail) is unaffected. See [Live updates](#live-updates-rise-xapps-sdklive).
|
|
1803
1914
|
- **Raw connector writes bypass the invalidation map** — after one, call
|
|
1804
1915
|
`invalidateAppSdkQueries(useAppQueryClient())`.
|
|
1805
1916
|
- **Out of scope**: the async iterators (`work.iterate`/`assets.iterate` —
|
|
@@ -44,6 +44,10 @@ export interface GetChatMessagesArgs {
|
|
|
44
44
|
pageSize?: number;
|
|
45
45
|
signal?: AbortSignal;
|
|
46
46
|
}
|
|
47
|
+
export interface TranscribeOptions {
|
|
48
|
+
language?: string;
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
}
|
|
47
51
|
export interface AgentsConnector {
|
|
48
52
|
list(args?: ListAgentsArgs): Promise<AgentPage>;
|
|
49
53
|
get(id: string, opts?: {
|
|
@@ -60,6 +64,7 @@ export interface AgentsConnector {
|
|
|
60
64
|
}): Promise<void>;
|
|
61
65
|
run(args: RunAgentArgs): AsyncIterable<AgentRunEvent>;
|
|
62
66
|
createChat(args: CreateAgentChatArgs): AgentChatSession;
|
|
67
|
+
transcribe(audio: Blob, options?: TranscribeOptions): Promise<string>;
|
|
63
68
|
listChats(args?: ListChatsArgs): Promise<AgentChatPage>;
|
|
64
69
|
getChat(id: string, opts?: {
|
|
65
70
|
signal?: AbortSignal;
|
|
@@ -17,6 +17,8 @@ const AGENT_PATH = "/api/v4/config/agent";
|
|
|
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";
|
|
20
|
+
// Stateless speech-to-text on the AI gateway: one clip in, one transcript out.
|
|
21
|
+
const TRANSCRIBE_PATH = "/api/v1/diana/transcribe";
|
|
20
22
|
function eventData(raw) {
|
|
21
23
|
// Tolerate non-JSON frames (keep-alive text, partial vendor events) — a bad
|
|
22
24
|
// frame must not kill the stream.
|
|
@@ -275,6 +277,43 @@ function createAgentsConnector(deps = { shell: _internal_1.requireShell }) {
|
|
|
275
277
|
};
|
|
276
278
|
}
|
|
277
279
|
};
|
|
280
|
+
const transcribe = async (audio, options = {}) => {
|
|
281
|
+
if (!audio || audio.size === 0) {
|
|
282
|
+
throw new errors_1.ConnectorError("INVALID_ARG", "agents.transcribe: audio must be a non-empty Blob");
|
|
283
|
+
}
|
|
284
|
+
const ai = (0, _internal_1.resolveAi)(deps.shell(), "agents.transcribe");
|
|
285
|
+
// The blob's type names the container the recorder produced, and the
|
|
286
|
+
// gateway reads the format from it. No Content-Type header: the browser
|
|
287
|
+
// derives it, boundary included, from the FormData body.
|
|
288
|
+
const form = new FormData();
|
|
289
|
+
form.append("audio", audio, "dictation");
|
|
290
|
+
if (options.language)
|
|
291
|
+
form.append("language", options.language);
|
|
292
|
+
let response;
|
|
293
|
+
try {
|
|
294
|
+
response = await fetch(`${ai.baseUrl}${TRANSCRIBE_PATH}`, {
|
|
295
|
+
method: "POST",
|
|
296
|
+
headers: (0, _internal_1.stripContentType)(ai.getHeaders()),
|
|
297
|
+
body: form,
|
|
298
|
+
signal: options.signal,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
catch (e) {
|
|
302
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
303
|
+
}
|
|
304
|
+
await (0, _internal_1.ensureOk)(response, "transcription");
|
|
305
|
+
let body;
|
|
306
|
+
try {
|
|
307
|
+
body = (await response.json());
|
|
308
|
+
}
|
|
309
|
+
catch (e) {
|
|
310
|
+
const error = (0, errors_1.toConnectorError)(e);
|
|
311
|
+
if (error.code === "ABORTED")
|
|
312
|
+
throw error;
|
|
313
|
+
throw new errors_1.ConnectorError("PARSE_ERROR", "transcription response is not valid JSON", { cause: e });
|
|
314
|
+
}
|
|
315
|
+
return typeof body?.text === "string" ? body.text : "";
|
|
316
|
+
};
|
|
278
317
|
const createChat = ({ agentId, chatId: initialChatId, sessionId, }) => {
|
|
279
318
|
let chatId = initialChatId;
|
|
280
319
|
return {
|
|
@@ -391,6 +430,7 @@ function createAgentsConnector(deps = { shell: _internal_1.requireShell }) {
|
|
|
391
430
|
delete: remove,
|
|
392
431
|
run,
|
|
393
432
|
createChat,
|
|
433
|
+
transcribe,
|
|
394
434
|
listChats,
|
|
395
435
|
getChat,
|
|
396
436
|
renameChat,
|
|
@@ -184,7 +184,8 @@ function createAssetsConnector(deps = { shell: _internal_1.requireShell }) {
|
|
|
184
184
|
const asset = (0, types_1.mapAssetDetail)(answer ?? {});
|
|
185
185
|
const draftWorkId = asset.draftWorkId;
|
|
186
186
|
if (!draftWorkId || draftWorkId === EMPTY_GUID) {
|
|
187
|
-
|
|
187
|
+
// After create() the asset exists by now, so the error carries it.
|
|
188
|
+
throw new errors_1.ConnectorError("PARSE_ERROR", `the answer for asset '${asset.id}' named no draft work item`, { cause: asset });
|
|
188
189
|
}
|
|
189
190
|
const written = (0, types_1.mapWorkDetail)(answer?.workDraft);
|
|
190
191
|
const draft = await (0, work_1.readWorkBack)(deps, draftWorkId, written, signal);
|
|
@@ -2,11 +2,12 @@ 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 { projectDataPaths } from "./project";
|
|
5
6
|
export { DEFAULT_SEARCH_PAGE_SIZE, searchCacheShape, type SearchArgs, type SearchCondition, type SearchFilter, type SearchOperator, type SearchPage, } from "./search";
|
|
6
7
|
export { createFlowsConnector, findTaskIn, flattenLayoutFields, flows, type FindTaskArgs, type FindTaskResult, type FlowsConnector, type ListFlowsArgs, } from "./flows";
|
|
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 { createWorkConnector, work, type FlowRef, type GetWorkSummaryOptions, type IterateWorkRowsArgs, type ListRelatedWorkArgs, type ListWorkRowsArgs, type SearchWorkArgs, type StartWorkArgs, type SubmitWorkArgs, type WorkConnector, type WorkDataPatch, type WorkInvitation, type WorkInvitationDestination, type WorkInvitee, type WorkPatchOperation, type WorkRowPage, type WorkSearchPage, } from "./work";
|
|
8
9
|
export { ASSET_TARGET_DATA_TYPES, assets, createAssetsConnector, type AssetDraft, type AssetRowPage, type AssetSearchPage, type AssetsConnector, type AssetTypeRef, type CreateAssetArgs, type IterateAssetRowsArgs, type ListAssetRowsArgs, type ListRelatedAssetsArgs, type QuickSearchAssetsArgs, type SearchAssetsArgs, type StartEditAssetArgs, } from "./assets";
|
|
9
|
-
export { agentEndReason, agentErrorText, agentMessageText, agents, collectAgentReply, createAgentsConnector, streamAgentReply, type AgentChatSession, type AgentReplyState, type AgentsConnector, type CreateAgentChatArgs, type GetChatMessagesArgs, type ListAgentsArgs, type ListChatsArgs, type RunAgentArgs, type SendChatArgs, } from "./agents";
|
|
10
|
+
export { agentEndReason, agentErrorText, agentMessageText, agents, collectAgentReply, createAgentsConnector, streamAgentReply, type AgentChatSession, type AgentReplyState, type AgentsConnector, type CreateAgentChatArgs, type GetChatMessagesArgs, type ListAgentsArgs, type ListChatsArgs, type RunAgentArgs, type SendChatArgs, type TranscribeOptions, } from "./agents";
|
|
10
11
|
export { attachments, createAttachmentsConnector, type AttachmentsConnector, type GetAttachmentBlobArgs, type UploadAttachmentArgs, } from "./attachments";
|
|
11
12
|
export { createIntegrationsConnector, integrations, type IntegrationsConnector, type InvokeIntegrationEndpointArgs, } from "./integrations";
|
|
12
13
|
export { createVectorStoresConnector, vectorStores, type AddVectorStoreFilesArgs, type CreateVectorStoreArgs, type RebuildVectorStoreArgs, type RenewVectorStoreArgs, type VectorStoresConnector, } from "./vectorStores";
|
|
@@ -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.offline = exports.createOfflineConnector = exports.vectorStores = exports.createVectorStoresConnector = exports.integrations = exports.createIntegrationsConnector = exports.createAttachmentsConnector = exports.attachments = 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;
|
|
23
|
+
exports.offline = exports.createOfflineConnector = exports.vectorStores = exports.createVectorStoresConnector = exports.integrations = exports.createIntegrationsConnector = exports.createAttachmentsConnector = exports.attachments = 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.projectDataPaths = 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,8 @@ 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 project_1 = require("./project");
|
|
32
|
+
Object.defineProperty(exports, "projectDataPaths", { enumerable: true, get: function () { return project_1.projectDataPaths; } });
|
|
31
33
|
var search_1 = require("./search");
|
|
32
34
|
Object.defineProperty(exports, "DEFAULT_SEARCH_PAGE_SIZE", { enumerable: true, get: function () { return search_1.DEFAULT_SEARCH_PAGE_SIZE; } });
|
|
33
35
|
Object.defineProperty(exports, "searchCacheShape", { enumerable: true, get: function () { return search_1.searchCacheShape; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copies the given dotted paths (without the `data.` prefix: `section.field`) out of a data
|
|
3
|
+
* document into a new object of the same shape. A path the document lacks is left out. Pass the
|
|
4
|
+
* `data.`-stripped entries of a search's `fields` to rebuild what that search would have
|
|
5
|
+
* returned for one record.
|
|
6
|
+
*/
|
|
7
|
+
export declare function projectDataPaths(doc: unknown, paths: readonly string[]): Record<string, unknown>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Projection of `data.*` field paths out of a work or asset data document, the way a search does
|
|
3
|
+
// for its `fields` option: only the requested paths come back, nested as they are stored. A
|
|
4
|
+
// missing field under an object that exists leaves that object empty, as a document store's
|
|
5
|
+
// inclusion projection does; a missing parent is left out.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.projectDataPaths = projectDataPaths;
|
|
8
|
+
// `a.b` and `a.c` share the `a` node; a path that names a node outright takes all of it, so
|
|
9
|
+
// `a` plus `a.b` is `a`.
|
|
10
|
+
function treeOf(paths) {
|
|
11
|
+
const root = {};
|
|
12
|
+
for (const path of paths) {
|
|
13
|
+
const segments = path.split(".").filter(Boolean);
|
|
14
|
+
let node = root;
|
|
15
|
+
for (let i = 0; i < segments.length; i++) {
|
|
16
|
+
const segment = segments[i];
|
|
17
|
+
if (i === segments.length - 1) {
|
|
18
|
+
node[segment] = true;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
const next = node[segment];
|
|
22
|
+
if (next === true)
|
|
23
|
+
break;
|
|
24
|
+
node = next ?? (node[segment] = {});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return root;
|
|
28
|
+
}
|
|
29
|
+
function project(value, tree) {
|
|
30
|
+
if (tree === true)
|
|
31
|
+
return value;
|
|
32
|
+
// Through an array a path applies to each element, as a document store projects it.
|
|
33
|
+
if (Array.isArray(value))
|
|
34
|
+
return value.map((item) => project(item, tree));
|
|
35
|
+
if (value === null || typeof value !== "object")
|
|
36
|
+
return undefined;
|
|
37
|
+
const out = {};
|
|
38
|
+
for (const [key, subtree] of Object.entries(tree)) {
|
|
39
|
+
if (!(key in value))
|
|
40
|
+
continue;
|
|
41
|
+
const picked = project(value[key], subtree);
|
|
42
|
+
if (picked !== undefined)
|
|
43
|
+
out[key] = picked;
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Copies the given dotted paths (without the `data.` prefix: `section.field`) out of a data
|
|
49
|
+
* document into a new object of the same shape. A path the document lacks is left out. Pass the
|
|
50
|
+
* `data.`-stripped entries of a search's `fields` to rebuild what that search would have
|
|
51
|
+
* returned for one record.
|
|
52
|
+
*/
|
|
53
|
+
function projectDataPaths(doc, paths) {
|
|
54
|
+
const picked = project(doc, treeOf(paths));
|
|
55
|
+
return picked !== null && typeof picked === "object" && !Array.isArray(picked)
|
|
56
|
+
? picked
|
|
57
|
+
: {};
|
|
58
|
+
}
|
|
@@ -92,6 +92,16 @@ export interface WorkAction {
|
|
|
92
92
|
eventName?: string;
|
|
93
93
|
canExecute?: boolean;
|
|
94
94
|
actionSetId?: string;
|
|
95
|
+
destinations: WorkActionDestination[];
|
|
96
|
+
}
|
|
97
|
+
export interface WorkActionDestination {
|
|
98
|
+
targetStep?: string;
|
|
99
|
+
targetStepId?: string;
|
|
100
|
+
targetStepDisplayName?: string;
|
|
101
|
+
toEmails: string[];
|
|
102
|
+
ccEmails: string[];
|
|
103
|
+
toDataPaths: string[];
|
|
104
|
+
ccDataPaths: string[];
|
|
95
105
|
}
|
|
96
106
|
export interface WorkAttachment {
|
|
97
107
|
id: string;
|
|
@@ -112,6 +122,12 @@ export interface WorkDetail {
|
|
|
112
122
|
flowOriginId?: string;
|
|
113
123
|
status?: string;
|
|
114
124
|
state?: string;
|
|
125
|
+
statusDisplay?: ResourceStatusDisplay;
|
|
126
|
+
assignedUsers: WorkUser[];
|
|
127
|
+
created?: string;
|
|
128
|
+
lastModified?: string;
|
|
129
|
+
createdBy?: string;
|
|
130
|
+
lastModifiedBy?: string;
|
|
115
131
|
activeLocks: WorkComponentLock[];
|
|
116
132
|
attachments: WorkAttachment[];
|
|
117
133
|
actions: WorkAction[];
|
|
@@ -38,6 +38,7 @@ exports.mapVectorStoreFileList = mapVectorStoreFileList;
|
|
|
38
38
|
exports.mapAddVectorStoreFilesResult = mapAddVectorStoreFilesResult;
|
|
39
39
|
exports.mapIntegrationInvokeResult = mapIntegrationInvokeResult;
|
|
40
40
|
const str = (v) => typeof v === "string" && v !== "" ? v : undefined;
|
|
41
|
+
const strList = (v) => Array.isArray(v) ? v.flatMap((x) => str(x) ?? []) : [];
|
|
41
42
|
// Mappers accept `unknown` so call sites can feed raw axios payloads directly;
|
|
42
43
|
// anything non-object maps as an empty record (tolerant by contract).
|
|
43
44
|
const asRecord = (value) => value !== null && typeof value === "object" ? value : {};
|
|
@@ -192,6 +193,12 @@ function mapWorkDetail(value) {
|
|
|
192
193
|
flowOriginId: str(raw?.flowOriginId),
|
|
193
194
|
status: str(raw?.status),
|
|
194
195
|
state: str(raw?.state),
|
|
196
|
+
statusDisplay: mapStatusDisplay(raw?.statusDisplay),
|
|
197
|
+
assignedUsers: mapWorkUsers(raw?.assignedUsers),
|
|
198
|
+
created: str(raw?.created),
|
|
199
|
+
lastModified: str(raw?.lastModified),
|
|
200
|
+
createdBy: str(raw?.createdBy),
|
|
201
|
+
lastModifiedBy: str(raw?.lastModifiedBy),
|
|
195
202
|
activeLocks: locks.flatMap((l) => str(l?.userId) && typeof l?.componentId === "string"
|
|
196
203
|
? [
|
|
197
204
|
{
|
|
@@ -220,6 +227,15 @@ function mapWorkDetail(value) {
|
|
|
220
227
|
eventName: str(a?.eventName),
|
|
221
228
|
canExecute: typeof a?.canExecute === "boolean" ? a.canExecute : undefined,
|
|
222
229
|
actionSetId: str(a?.stepId),
|
|
230
|
+
destinations: (Array.isArray(a?.destinations) ? a.destinations : []).map((d) => ({
|
|
231
|
+
targetStep: str(d?.targetStep),
|
|
232
|
+
targetStepId: str(d?.targetStepId),
|
|
233
|
+
targetStepDisplayName: str(d?.targetStepDisplayName),
|
|
234
|
+
toEmails: strList(d?.toUserEmail),
|
|
235
|
+
ccEmails: strList(d?.ccUserEmail),
|
|
236
|
+
toDataPaths: strList(d?.toDataPaths),
|
|
237
|
+
ccDataPaths: strList(d?.ccDataPaths),
|
|
238
|
+
})),
|
|
223
239
|
})),
|
|
224
240
|
};
|
|
225
241
|
}
|
|
@@ -235,12 +251,14 @@ const mapStatusDisplay = (value) => {
|
|
|
235
251
|
roleName: str(raw.roleName),
|
|
236
252
|
};
|
|
237
253
|
};
|
|
254
|
+
const mapWorkUsers = (value) => (Array.isArray(value) ? value : []).map((u) => ({
|
|
255
|
+
id: str(u?.id),
|
|
256
|
+
displayName: str(u?.displayName),
|
|
257
|
+
email: str(u?.email),
|
|
258
|
+
}));
|
|
238
259
|
function mapWorkSummary(value) {
|
|
239
260
|
const raw = asRecord(value);
|
|
240
261
|
const id = String(raw.id ?? "");
|
|
241
|
-
const users = Array.isArray(raw.assignedUsers)
|
|
242
|
-
? raw.assignedUsers
|
|
243
|
-
: [];
|
|
244
262
|
return {
|
|
245
263
|
id,
|
|
246
264
|
displayName: str(raw?.displayName) ?? str(raw?.name) ?? str(raw?.workCode) ?? id,
|
|
@@ -252,11 +270,7 @@ function mapWorkSummary(value) {
|
|
|
252
270
|
status: str(raw?.status),
|
|
253
271
|
flowState: str(raw?.flowState),
|
|
254
272
|
statusDisplay: mapStatusDisplay(raw?.statusDisplay),
|
|
255
|
-
assignedUsers:
|
|
256
|
-
id: str(u?.id),
|
|
257
|
-
displayName: str(u?.displayName),
|
|
258
|
-
email: str(u?.email),
|
|
259
|
-
})),
|
|
273
|
+
assignedUsers: mapWorkUsers(raw?.assignedUsers),
|
|
260
274
|
created: str(raw?.created),
|
|
261
275
|
lastModified: str(raw?.lastModified),
|
|
262
276
|
createdBy: str(raw?.createdBy),
|
|
@@ -11,8 +11,28 @@ export interface SubmitWorkArgs {
|
|
|
11
11
|
workId: string;
|
|
12
12
|
actionName: string;
|
|
13
13
|
stepName?: string;
|
|
14
|
+
to?: WorkInvitee[];
|
|
15
|
+
cc?: WorkInvitee[];
|
|
16
|
+
invitation?: WorkInvitation;
|
|
14
17
|
signal?: AbortSignal;
|
|
15
18
|
}
|
|
19
|
+
export interface WorkInvitee {
|
|
20
|
+
email?: string;
|
|
21
|
+
id?: string;
|
|
22
|
+
name?: string;
|
|
23
|
+
partyName?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface WorkInvitation {
|
|
26
|
+
destinations: WorkInvitationDestination[];
|
|
27
|
+
}
|
|
28
|
+
export interface WorkInvitationDestination {
|
|
29
|
+
targetStep?: string;
|
|
30
|
+
targetStepName?: string;
|
|
31
|
+
to?: WorkInvitee[];
|
|
32
|
+
cc?: WorkInvitee[];
|
|
33
|
+
message?: string;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
16
36
|
export type WorkPatchOperation = "Set" | "Push" | "Pull" | "Unset" | "AddToSet" | "Merge";
|
|
17
37
|
export interface WorkDataPatch {
|
|
18
38
|
originId: string;
|
|
@@ -53,6 +73,14 @@ export type SearchWorkArgs = SearchArgs & {
|
|
|
53
73
|
filter: SearchFilter;
|
|
54
74
|
};
|
|
55
75
|
export type WorkSearchPage = SearchPage<WorkSummary>;
|
|
76
|
+
export interface GetWorkSummaryOptions {
|
|
77
|
+
/**
|
|
78
|
+
* The projection to rebuild, as a search takes it: `data.<section>.<field>` paths select what
|
|
79
|
+
* lands in the row's `data`. Without any, `data` is left off and only the work itself is read.
|
|
80
|
+
*/
|
|
81
|
+
fields?: readonly string[];
|
|
82
|
+
signal?: AbortSignal;
|
|
83
|
+
}
|
|
56
84
|
export interface ListRelatedWorkArgs {
|
|
57
85
|
workId: string;
|
|
58
86
|
relationships: string[];
|
|
@@ -72,6 +100,15 @@ export interface WorkConnector {
|
|
|
72
100
|
get(workId: string, opts?: {
|
|
73
101
|
signal?: AbortSignal;
|
|
74
102
|
}): Promise<WorkDetail | null>;
|
|
103
|
+
/**
|
|
104
|
+
* One work as a search row, read from the platform now: the work itself, plus its data document
|
|
105
|
+
* when `fields` names any `data.*` path. A search is cached on the server for minutes, so this
|
|
106
|
+
* is how an app brings one row of a list up to date after a change it was told about, without
|
|
107
|
+
* reading the list again. `data` carries only the projected paths (see `projectDataPaths`),
|
|
108
|
+
* like a search row's. Resolves `null` when the work does not exist; never answers from the
|
|
109
|
+
* offline cache.
|
|
110
|
+
*/
|
|
111
|
+
getSummary(workId: string, opts?: GetWorkSummaryOptions): Promise<WorkSummary | null>;
|
|
75
112
|
getData(workId: string, opts?: {
|
|
76
113
|
path?: string;
|
|
77
114
|
signal?: AbortSignal;
|