@lotics/app-sdk 0.133.49 → 0.134.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/AGENTS.md +1 -1
- package/dist/{chunk-NS3BIL73.js → chunk-R5BQBUDK.js} +1 -103
- package/dist/index.d.ts +0 -3
- package/dist/index.js +10 -74
- package/dist/mock.d.ts +0 -4
- package/dist/router.js +1 -1
- package/dist/rpc.d.ts +1 -6
- package/dist/shared_types.d.ts +1 -1
- package/dist/viewer.d.ts +0 -1
- package/docs/mutations.md +1 -73
- package/docs/runtime.md +3 -10
- package/docs/workflows.md +0 -46
- package/package.json +1 -1
- package/dist/recording.d.ts +0 -65
- package/dist/recording_state.d.ts +0 -44
package/docs/mutations.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Writing data from an app: `useWorkflow` and its result contract, typed inputs and outputs, how a
|
|
4
4
|
write shows on every read from the press, the re-read a successful write triggers,
|
|
5
|
-
diff-before-update, locked records
|
|
5
|
+
diff-before-update, locked records and `useNewRecord`. What may be written **inside** the workflow body — the JS subset, steps, helpers,
|
|
6
6
|
traps — is [workflows](./workflows.md). Reading data is [queries](./queries.md) +
|
|
7
7
|
[data_fetching](./data_fetching.md); uploads are [files](./files.md); who a write runs as is
|
|
8
8
|
[security](./security.md).
|
|
@@ -626,75 +626,3 @@ Use `newRecordId()` directly if you need the id outside a hook (routing to the s
|
|
|
626
626
|
mounting it, say). It mints the same `rec_*` shape the server validates. A create made in one press
|
|
627
627
|
needs neither: the SDK mints the id itself (above).
|
|
628
628
|
|
|
629
|
-
## Recording into a workflow: `useRecording`
|
|
630
|
-
|
|
631
|
-
A recording act — record a site visit, a call, a meeting, and file it on the row it is about —
|
|
632
|
-
is a workflow whose run waits for the transcript. Exact signature: `dist/recording.d.ts`.
|
|
633
|
-
|
|
634
|
-
```tsx
|
|
635
|
-
import { useRecording } from "@lotics/app-sdk";
|
|
636
|
-
|
|
637
|
-
const visit = useRecording("log_visit");
|
|
638
|
-
if (!visit.available) return null; // draw nothing that cannot record
|
|
639
|
-
const mine = visit.state.phase !== "idle" && visit.state.inputs.site === siteId;
|
|
640
|
-
|
|
641
|
-
const { started } = await visit.start({ site: siteId }); // false: the member closed the dialog
|
|
642
|
-
await visit.stop();
|
|
643
|
-
```
|
|
644
|
-
|
|
645
|
-
- **The alias names a receiving workflow** — one that declares the platform's `recording` input
|
|
646
|
-
([workflows](./workflows.md#a-workflow-that-receives-a-recording)). `start` takes the rest of
|
|
647
|
-
its declared inputs, typed from the declaration without `recording`; passing `recording` is a
|
|
648
|
-
`tsc` error and a refusal. Such a workflow runs only from a recording: `useWorkflow` on its
|
|
649
|
-
alias is refused, because the platform alone fills `recording`.
|
|
650
|
-
- **The host records, never the app.** `start` asks the Lotics host, which opens its own capture
|
|
651
|
-
dialog — microphone, and where the browser supports it system sound and the screen — named
|
|
652
|
-
with the app's name. Nothing records until the member presses Start there. The app touches no
|
|
653
|
-
media device and needs no permission. The recording belongs to the tab, not the frame: the
|
|
654
|
-
member may leave the app, and a bar in the product carries the recording until it is filed.
|
|
655
|
-
- **`start` resolves `{ started: true }`** once capture runs and **`{ started: false }`** when the
|
|
656
|
-
member closed the dialog. It **rejects with the host's reason** when refused: a recording is
|
|
657
|
-
already running (one per tab, across every app and the chat), the member has three recordings
|
|
658
|
-
still open, the inputs fail the workflow's declaration (a deleted record is refused before
|
|
659
|
-
anything is recorded, not after), or recording is unavailable. Show the reason.
|
|
660
|
-
- **`stop`** stops this alias's live recording, and resolves whether or not one was live. The
|
|
661
|
-
member can also stop from the product's bar.
|
|
662
|
-
- **Filing.** Once transcribed, the host runs the workflow **once** with `{ ...inputs,
|
|
663
|
-
recording }`, under the app owner's authority with the recording member as
|
|
664
|
-
`runtime.triggered_by_member_id` ([security](./security.md)). A silent recording files with
|
|
665
|
-
`transcript: ""`. Filing is re-checked at run time: the member still holds the app, the alias
|
|
666
|
-
is still bound, and its declaration still receives recordings. A refused or failed filing is
|
|
667
|
-
never retried by itself and the recording is never lost: the member retries from the
|
|
668
|
-
product's bar, and a failed run also sends the app's owner the failed-run notice.
|
|
669
|
-
- **`available`** is what the host states — false standalone, in a host
|
|
670
|
-
that predates recording, on an instance without transcription, and until the context has
|
|
671
|
-
answered. A standalone app has no member to record as; both calls reject there.
|
|
672
|
-
|
|
673
|
-
`state` is the most recent recording this app started through the alias (a second recording
|
|
674
|
-
replaces the first's state):
|
|
675
|
-
|
|
676
|
-
| `phase` | Carries | Means |
|
|
677
|
-
|---|---|---|
|
|
678
|
-
| `idle` | — | nothing through this alias is running or waiting |
|
|
679
|
-
| `live` | `elapsed_seconds`, `inputs` | capturing; the host updates it each second |
|
|
680
|
-
| `interrupted` | `elapsed_seconds`, `inputs` | the tab closed mid-recording; the member resumes or finishes it from the product's bar |
|
|
681
|
-
| `processing` | `inputs` | stopped; the transcript is on its way |
|
|
682
|
-
| `filed` | `execution_id`, `inputs` | the workflow ran and succeeded |
|
|
683
|
-
| `failed` | `message`, `inputs` | transcription failed, or filing was refused or its run failed |
|
|
684
|
-
|
|
685
|
-
A screen drawing a number of recording acts it only learns at run time reads them together with
|
|
686
|
-
**`useRecordings(aliases)`**: `available` and `busy` as above, `states` (each alias's latest
|
|
687
|
-
recording, idle where none ran), and `start(alias, inputs)` / `stop(alias)` — the same calls, by
|
|
688
|
-
alias.
|
|
689
|
-
|
|
690
|
-
`inputs` is what `start` was passed, so a screen with one act per row can tell which row the
|
|
691
|
-
recording is about. **`busy`** is true while any recording this app started is live, through
|
|
692
|
-
any alias: stand the other acts down, since the host would refuse them. A recording in another
|
|
693
|
-
app or the chat is invisible to this app, so `start` can still be refused while `busy` is false.
|
|
694
|
-
|
|
695
|
-
**Filed means written.** When `state` becomes `filed`, every mounted query re-reads, exactly as
|
|
696
|
-
after a successful `useWorkflow` call ([refetch](#refetch-after-a-mutation)), and the filed row's
|
|
697
|
-
files and transcript read like any other.
|
|
698
|
-
|
|
699
|
-
A mock fixture's `recordings` map (alias → `state`) draws each phase without a host
|
|
700
|
-
([runtime](./runtime.md#the-mock-harness-optionsfixture--__mock1)).
|
package/docs/runtime.md
CHANGED
|
@@ -68,7 +68,7 @@ Activation is a **two-step gate** — both must hold, so demo data shipping in t
|
|
|
68
68
|
bundle never leaks into normal traffic:
|
|
69
69
|
|
|
70
70
|
1. A fixture is registered via `mount({ fixture })` (`AppFixture` type:
|
|
71
|
-
`dist/mock.d.ts` — `{ queries?, workflows?, agents?, exports?, exportApps?,
|
|
71
|
+
`dist/mock.d.ts` — `{ queries?, workflows?, agents?, exports?, exportApps?, agentBeatMs? }`;
|
|
72
72
|
`agentBeatMs` paces each line a mocked agent run streams, a real run's pace when unset, `0` in a test).
|
|
73
73
|
2. The page URL carries `?__mock=1` (exactly `1`). Without the flag the fixture
|
|
74
74
|
is completely inert.
|
|
@@ -111,10 +111,6 @@ pending state; `fixture.exportApps[list]` answers `exportApp(list, narrowing)` t
|
|
|
111
111
|
`error` — through the same stream reader a real run goes through, so the pane's
|
|
112
112
|
live, done and failed states are reviewable with no spend. It never parks on a
|
|
113
113
|
question, and there is no run to cancel on the server.
|
|
114
|
-
- **A mocked recording is a canned state.** `recordings: { log_visit: { phase:
|
|
115
|
-
"live", elapsed_seconds: 754, inputs: { site: "rec_1" } } }` makes
|
|
116
|
-
`useRecording("log_visit")` available with that `state`; `start` and `stop`
|
|
117
|
-
resolve without recording anything or moving the state.
|
|
118
114
|
- **Not mocked:** uploads, `useFieldOptions`, members. In mock mode
|
|
119
115
|
those still hit the real transport.
|
|
120
116
|
- **Analytics is disabled** whenever `?__mock=1` is present, fixture or not — a
|
|
@@ -228,7 +224,6 @@ surfaces:
|
|
|
228
224
|
| `agentRun.get`, `agentRun.cancel` | yes | yes |
|
|
229
225
|
| `agentRuns` (session history) | **no** — the product host doesn't implement it either (`"Unknown RPC op: agentRuns"`) | rejects — a standalone caller is anonymous, and a history is its member's (`"App agent runs require an authenticated member …"`) |
|
|
230
226
|
| `askAi` | yes | rejects — `"askAi is only available when the app runs inside Lotics"` |
|
|
231
|
-
| `recording.start`, `recording.stop` | yes, when the context states `recording_enabled` | rejects — `"Recording needs the Lotics host and a signed-in member …"` |
|
|
232
227
|
|
|
233
228
|
**Limitation:** Don't build a session-log UI on `useAgentRuns`; keep the log in app
|
|
234
229
|
state from live `useAgentRun` results (see [ai](./ai.md)). The standalone `query` transport forwards only
|
|
@@ -275,7 +270,6 @@ semantics are documented:
|
|
|
275
270
|
| `agentRun.get` | `{ run_id }` | `{ run }` | [ai](./ai.md) |
|
|
276
271
|
| `agentRun.cancel` | `{ run_id }` | `{ ok: true }` | [ai](./ai.md) |
|
|
277
272
|
| `urlState.get` / `urlState.set` | — / `{ params }` | `UrlParams` / `void` | [navigation & state](./navigation_and_state.md) |
|
|
278
|
-
| `recording.start` / `recording.stop` | `{ alias, inputs }` / `{ alias }` | `{ started }` / `void` | [mutations](./mutations.md#recording-into-a-workflow-userecording) |
|
|
279
273
|
| `outsideLink.list/create/revoke` | `{ record_id }` / `{ record_id, outside }` / `{ record_id, link_id }` | links / link or `null` / `{ id }` or `null` | [members & options](./members_and_options.md#outside-links-useoutsidelinks) |
|
|
280
274
|
|
|
281
275
|
`installPageHost(host)` makes one `PageHost` answer a page that is never an app's own (the page a person with no seat
|
|
@@ -299,14 +293,13 @@ The **streaming** agent-run op is *not* reachable through `rpc()` — its
|
|
|
299
293
|
response is a chunk stream, not a single value; it's internal to `useAgentRun`.
|
|
300
294
|
|
|
301
295
|
`rpc("context", {})` resolves the viewer and the workspace:
|
|
302
|
-
`{ member_id, timezone, language, default_currency
|
|
296
|
+
`{ member_id, timezone, language, default_currency }`. `member_id` is the
|
|
303
297
|
signed-in member when embedded, `null` standalone; `timezone` is the workspace's
|
|
304
298
|
IANA zone, `language` its organization's (`vi` or `en`: the form `formatDate` prints with no pattern) and `default_currency` its ISO 4217 code, from the host when embedded
|
|
305
299
|
and from `/v1/apps/by-subdomain/{subdomain}` standalone. Read them through
|
|
306
300
|
`useViewer()`, `useWorkspaceTimezone()`, `useWorkspaceCurrency()` and `useAppContext()` (the language)
|
|
307
301
|
([members & options](./members_and_options.md)) rather than this op. A host that
|
|
308
|
-
predates these workspace facts answers without them — with no language, a `formatDate` with no pattern is refused and a press's effects are not predicted
|
|
309
|
-
`useRecording`'s. **Limitation:** the
|
|
302
|
+
predates these workspace facts answers without them — with no language, a `formatDate` with no pattern is refused and a press's effects are not predicted. **Limitation:** the
|
|
310
303
|
context type is not exported from the package root, so type the result yourself
|
|
311
304
|
via the `rpc<T>` generic.
|
|
312
305
|
|
package/docs/workflows.md
CHANGED
|
@@ -858,52 +858,6 @@ said, not made, and a document a step renders is made as a paper no listing show
|
|
|
858
858
|
receives). A draft it cannot rehearse — a step that reads what a call before it answers, a wait, a bound the
|
|
859
859
|
walk reaches — answers `preview.available: false` and the reason. Nothing is written.
|
|
860
860
|
|
|
861
|
-
## A workflow that receives a recording
|
|
862
|
-
|
|
863
|
-
A workflow that files a recording ([mutations](./mutations.md#recording-into-a-workflow-userecording))
|
|
864
|
-
declares the platform's `recording` input in exactly this shape, beside its own inputs:
|
|
865
|
-
|
|
866
|
-
```jsonc
|
|
867
|
-
// the header of a set_workflow source: on({ type: "app", app_id, alias: "log_visit", inputs: … })
|
|
868
|
-
"inputs": {
|
|
869
|
-
"site": { "type": "record_link", "table_id": "tbl_sites" },
|
|
870
|
-
"recording": { "type": "object", "fields": {
|
|
871
|
-
"session_id": { "type": "text" },
|
|
872
|
-
"audio": { "type": "file" },
|
|
873
|
-
"video": { "type": "file", "required": false },
|
|
874
|
-
"transcript": { "type": "text" },
|
|
875
|
-
"duration_seconds": { "type": "number" },
|
|
876
|
-
"recorded_at": { "type": "datetime" }
|
|
877
|
-
} }
|
|
878
|
-
}
|
|
879
|
-
```
|
|
880
|
-
|
|
881
|
-
A declaration that differs in any field, type or `required` is not a receiver: the host refuses
|
|
882
|
-
to start a recording for it, naming the first difference. The platform alone fills `recording`,
|
|
883
|
-
so a call through `useWorkflow` is refused.
|
|
884
|
-
|
|
885
|
-
- `audio` and `video` are file ids in the workspace. `video` is absent when the screen was not
|
|
886
|
-
recorded or its video failed to assemble. Both carry the same sound, so file **one**: the
|
|
887
|
-
video when present, else the audio.
|
|
888
|
-
- `transcript` is the verbatim text, one `Speaker A: …` line per turn, and `""` for a silent
|
|
889
|
-
recording. A text field holds it whole, with no length limit: three hours is about 200,000
|
|
890
|
-
characters.
|
|
891
|
-
- `recorded_at` is when capture started; `duration_seconds` is how long it ran.
|
|
892
|
-
|
|
893
|
-
```js
|
|
894
|
-
const i = trigger.app_workflow.inputs;
|
|
895
|
-
const r = i.recording;
|
|
896
|
-
await create_records({
|
|
897
|
-
table_id: "tbl_visits",
|
|
898
|
-
records: [{
|
|
899
|
-
fld_site: [i.site],
|
|
900
|
-
fld_recording: [r.video ?? r.audio],
|
|
901
|
-
fld_transcript: r.transcript,
|
|
902
|
-
fld_visited_at: r.recorded_at,
|
|
903
|
-
}],
|
|
904
|
-
});
|
|
905
|
-
```
|
|
906
|
-
|
|
907
861
|
## A worked body
|
|
908
862
|
|
|
909
863
|
An app action that creates an order after checking for a duplicate, then returns the new id.
|
package/package.json
CHANGED
package/dist/recording.d.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { type RecordingState } from "./recording_state.js";
|
|
2
|
-
import type { AppWorkflows } from "./types.js";
|
|
3
|
-
/** The platform fills `recording`; the app passes the rest. */
|
|
4
|
-
type ActInputsOf<K extends keyof AppWorkflows & string> = AppWorkflows[K] extends Record<string, unknown> ? Omit<AppWorkflows[K], "recording"> : Record<string, unknown>;
|
|
5
|
-
export interface UseRecording<I> {
|
|
6
|
-
/**
|
|
7
|
-
* False standalone, in an older host, without transcription, and until the
|
|
8
|
-
* context answers. Draw a start control only when true.
|
|
9
|
-
*/
|
|
10
|
-
available: boolean;
|
|
11
|
-
/** The latest recording through this alias. */
|
|
12
|
-
state: RecordingState;
|
|
13
|
-
/** Any of this app's recordings is live; the host records one at a time. */
|
|
14
|
-
busy: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Opens the host's capture dialog. `{ started: false }` when the member
|
|
17
|
-
* closes it; rejects with the host's reason. Once transcribed, the host runs
|
|
18
|
-
* the workflow with these inputs plus `recording`.
|
|
19
|
-
*/
|
|
20
|
-
start: {} extends I ? (inputs?: I) => Promise<{
|
|
21
|
-
started: boolean;
|
|
22
|
-
}> : (inputs: I) => Promise<{
|
|
23
|
-
started: boolean;
|
|
24
|
-
}>;
|
|
25
|
-
/** Resolves whether or not one was live. */
|
|
26
|
-
stop: () => Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Record through the host and file it by `alias`, a workflow declaring the
|
|
30
|
-
* `recording` input, run once when the transcript is ready.
|
|
31
|
-
*
|
|
32
|
-
* ```tsx
|
|
33
|
-
* const visit = useRecording("log_visit");
|
|
34
|
-
* if (!visit.available) return null;
|
|
35
|
-
* if (visit.state.phase === "live" && visit.state.inputs.site === siteId) {
|
|
36
|
-
* return <button onClick={() => visit.stop()}>Stop</button>;
|
|
37
|
-
* }
|
|
38
|
-
* return (
|
|
39
|
-
* <button disabled={visit.busy} onClick={() => visit.start({ site: siteId })}>
|
|
40
|
-
* Record the visit
|
|
41
|
-
* </button>
|
|
42
|
-
* );
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export declare function useRecording<K extends keyof AppWorkflows & string>(alias: K): UseRecording<ActInputsOf<K>>;
|
|
46
|
-
export declare function useRecording(alias: string): UseRecording<Record<string, unknown>>;
|
|
47
|
-
export interface UseRecordings {
|
|
48
|
-
/** As {@link UseRecording}'s: whether the host records here at all. */
|
|
49
|
-
available: boolean;
|
|
50
|
-
/** The latest recording through each alias asked, idle where none ran. */
|
|
51
|
-
states: Readonly<Record<string, RecordingState>>;
|
|
52
|
-
/** Any of this app's recordings is live, through any alias. */
|
|
53
|
-
busy: boolean;
|
|
54
|
-
start: (alias: string, inputs: Record<string, unknown>) => Promise<{
|
|
55
|
-
started: boolean;
|
|
56
|
-
}>;
|
|
57
|
-
stop: (alias: string) => Promise<void>;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* {@link useRecording} over several aliases at once — for a screen drawing an
|
|
61
|
-
* unknown number of recording acts, which cannot call a hook per alias. One
|
|
62
|
-
* snapshot per change: the host's every-second push while live redraws once.
|
|
63
|
-
*/
|
|
64
|
-
export declare function useRecordings(aliases: readonly string[]): UseRecordings;
|
|
65
|
-
export {};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The latest recording per workflow alias this app started. A leaf module:
|
|
3
|
-
* `rpc.ts` applies pushes, `viewer.ts` the context snapshot, both in order on
|
|
4
|
-
* one channel, so the later arrival is newer.
|
|
5
|
-
*/
|
|
6
|
-
/** The `start` inputs echoed back, so a per-row act can tell which row is recording. */
|
|
7
|
-
export type RecordingInputs = Record<string, unknown>;
|
|
8
|
-
/**
|
|
9
|
-
* `interrupted`: the tab closed mid-call, resumable from the recording bar.
|
|
10
|
-
* `processing`: transcribing. `failed`: transcription, filing or the run
|
|
11
|
-
* failed; kept, and retried from the recording bar.
|
|
12
|
-
*/
|
|
13
|
-
export type RecordingState = {
|
|
14
|
-
phase: "idle";
|
|
15
|
-
} | {
|
|
16
|
-
phase: "live";
|
|
17
|
-
elapsed_seconds: number;
|
|
18
|
-
inputs: RecordingInputs;
|
|
19
|
-
} | {
|
|
20
|
-
phase: "interrupted";
|
|
21
|
-
elapsed_seconds: number;
|
|
22
|
-
inputs: RecordingInputs;
|
|
23
|
-
} | {
|
|
24
|
-
phase: "processing";
|
|
25
|
-
inputs: RecordingInputs;
|
|
26
|
-
} | {
|
|
27
|
-
phase: "filed";
|
|
28
|
-
execution_id: string;
|
|
29
|
-
inputs: RecordingInputs;
|
|
30
|
-
} | {
|
|
31
|
-
phase: "failed";
|
|
32
|
-
message: string;
|
|
33
|
-
inputs: RecordingInputs;
|
|
34
|
-
};
|
|
35
|
-
export declare const IDLE_RECORDING: RecordingState;
|
|
36
|
-
export declare function recordingsVersion(): number;
|
|
37
|
-
export declare function subscribeRecordings(listener: () => void): () => void;
|
|
38
|
-
export declare function recordingStateOf(alias: string): RecordingState;
|
|
39
|
-
export declare function anyRecordingLive(): boolean;
|
|
40
|
-
export declare function applyRecordingChange(alias: string, state: RecordingState): void;
|
|
41
|
-
/** The snapshot `context` carries: every alias it omits is idle. */
|
|
42
|
-
export declare function replaceRecordings(snapshot: Record<string, RecordingState>): void;
|
|
43
|
-
export declare function readRecordingState(raw: unknown): RecordingState | null;
|
|
44
|
-
export declare function readRecordingSnapshot(raw: unknown): Record<string, RecordingState>;
|