@mostra/react 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/form.js +1 -1
- package/dist/{hooks-C0SVZDl4.js → hooks-BfV824_7.js} +362 -20
- package/dist/hooks-BfV824_7.js.map +1 -0
- package/dist/index.d.ts +115 -36
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +100 -3
- package/dist/index.js.map +1 -1
- package/dist/{mount-BCj41qky.js → mount-DmfrLZvk.js} +2 -2
- package/dist/{mount-BCj41qky.js.map → mount-DmfrLZvk.js.map} +1 -1
- package/dist/router.js +1 -1
- package/package.json +4 -4
- package/src/hooks.ts +33 -10
- package/src/index.ts +17 -1
- package/src/runtime/server-client.ts +3 -1
- package/src/runtime/store.ts +27 -1
- package/src/runtime/team.ts +388 -0
- package/src/runtime/transport.ts +33 -0
- package/src/team-hooks.ts +151 -0
- package/dist/hooks-C0SVZDl4.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
|
-
import { ArtifactManifest, ArtifactManifest as ArtifactManifest$1, Bridge, DeliveryTarget, FieldScope, RunProgress, RunStatus, SubmissionSummary, SubmissionSummary as SubmissionSummary$1, SubmitBlocker, SubmitBlocker as SubmitBlocker$1, TallyValue, TallyValue as TallyValue$1, UiInitializeResult, Viewer, ViewerKind } from "@mostra/protocol";
|
|
1
|
+
import { ArtifactManifest, ArtifactManifest as ArtifactManifest$1, Bridge, DeliveryTarget, FieldScope, Peer, PresenceCursor, PresencePeer, PresencePeer as PresencePeer$1, PresenceSelection, RespondentForPage, RespondentForPage as RespondentForPage$1, RespondentStatus, RosterCounts, RosterCounts as RosterCounts$1, RunProgress, RunStatus, SubmissionSummary, SubmissionSummary as SubmissionSummary$1, SubmitBlocker, SubmitBlocker as SubmitBlocker$1, TallyValue, TallyValue as TallyValue$1, TeamVisibility, TeamVisibility as TeamVisibility$1, UiInitializeResult, Viewer, ViewerKind } from "@mostra/protocol";
|
|
2
2
|
import { ComponentType, ReactNode } from "react";
|
|
3
|
+
//#region src/runtime/errors.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Errors the client runtime throws: each carries the stable diagnostic code an artifact can switch
|
|
6
|
+
* on (INTERFACES §13), and the diagnostic itself when the gateway sent one.
|
|
7
|
+
*/
|
|
8
|
+
/** A diagnostic as the gateway sends it; only the fields the runtime reads. */
|
|
9
|
+
interface DiagnosticLike {
|
|
10
|
+
/** The stable diagnostic code, such as `MOSTRA_FIELD_TOO_LARGE`. */
|
|
11
|
+
readonly code: string;
|
|
12
|
+
/** What is wrong. */
|
|
13
|
+
readonly message: string;
|
|
14
|
+
/** What to do about it. */
|
|
15
|
+
readonly hint?: string;
|
|
16
|
+
/** The code's documentation page. */
|
|
17
|
+
readonly docs?: string;
|
|
18
|
+
}
|
|
19
|
+
/** An error with a Mostra diagnostic code, such as `MOSTRA_SUBMIT_CHANNEL_DENIED`. */
|
|
20
|
+
export declare class MostraError extends Error {
|
|
21
|
+
/** The stable diagnostic code. */
|
|
22
|
+
readonly code: string;
|
|
23
|
+
/** The HTTP status the gateway answered with, when the error came from it. */
|
|
24
|
+
readonly status: number | undefined;
|
|
25
|
+
/** The diagnostic, when the gateway sent one. */
|
|
26
|
+
readonly diagnostic: DiagnosticLike | undefined;
|
|
27
|
+
/** Extra data the refusal carried, such as the existing submission of `MOSTRA_SUBMIT_ALREADY`. */
|
|
28
|
+
readonly body: Readonly<Record<string, unknown>> | undefined;
|
|
29
|
+
constructor(code: string, message: string, options?: {
|
|
30
|
+
readonly status?: number;
|
|
31
|
+
readonly diagnostic?: DiagnosticLike;
|
|
32
|
+
readonly body?: Readonly<Record<string, unknown>>;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
3
36
|
//#region src/runtime/store.d.ts
|
|
4
37
|
/** The submission state `useSubmit` reports (INTERFACES §2.3). */
|
|
5
38
|
type SubmitState = "open" | "submitting" | "submitted" | "delivered" | "pending-delivery" | "undeliverable" | "closed";
|
|
@@ -56,10 +89,17 @@ interface FieldMeta<T> {
|
|
|
56
89
|
keepMine(): void;
|
|
57
90
|
takeTheirs(): void;
|
|
58
91
|
};
|
|
59
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Who last wrote the field and when (artifact scope, D63, D168): a viewer by name and by their
|
|
94
|
+
* key on this artifact (the same `key` `useRespondents` and `usePresence` give), an agent or a
|
|
95
|
+
* host; `self` when it was this viewer.
|
|
96
|
+
*/
|
|
60
97
|
readonly updatedBy?: {
|
|
61
98
|
readonly kind: "viewer" | "agent" | "host";
|
|
62
99
|
readonly name?: string;
|
|
100
|
+
readonly key?: string;
|
|
101
|
+
readonly self?: boolean;
|
|
102
|
+
readonly at?: string;
|
|
63
103
|
};
|
|
64
104
|
}
|
|
65
105
|
/**
|
|
@@ -136,6 +176,8 @@ export declare function useViewer(): {
|
|
|
136
176
|
readonly id: string;
|
|
137
177
|
readonly name?: string;
|
|
138
178
|
readonly source: ViewerKind;
|
|
179
|
+
/** On a hosted link: `true` for a signed-in account, `false` for an anonymous viewer's name. */
|
|
180
|
+
readonly verified?: boolean;
|
|
139
181
|
};
|
|
140
182
|
/** The artifact, the version and the view the page shows, and where it runs (D104, D111). */
|
|
141
183
|
export declare function useArtifact(): {
|
|
@@ -197,39 +239,6 @@ export declare function mountArtifact(options: {
|
|
|
197
239
|
readonly page: ComponentType;
|
|
198
240
|
}): Promise<void>;
|
|
199
241
|
//#endregion
|
|
200
|
-
//#region src/runtime/errors.d.ts
|
|
201
|
-
/**
|
|
202
|
-
* Errors the client runtime throws: each carries the stable diagnostic code an artifact can switch
|
|
203
|
-
* on (INTERFACES §13), and the diagnostic itself when the gateway sent one.
|
|
204
|
-
*/
|
|
205
|
-
/** A diagnostic as the gateway sends it; only the fields the runtime reads. */
|
|
206
|
-
interface DiagnosticLike {
|
|
207
|
-
/** The stable diagnostic code, such as `MOSTRA_FIELD_TOO_LARGE`. */
|
|
208
|
-
readonly code: string;
|
|
209
|
-
/** What is wrong. */
|
|
210
|
-
readonly message: string;
|
|
211
|
-
/** What to do about it. */
|
|
212
|
-
readonly hint?: string;
|
|
213
|
-
/** The code's documentation page. */
|
|
214
|
-
readonly docs?: string;
|
|
215
|
-
}
|
|
216
|
-
/** An error with a Mostra diagnostic code, such as `MOSTRA_SUBMIT_CHANNEL_DENIED`. */
|
|
217
|
-
export declare class MostraError extends Error {
|
|
218
|
-
/** The stable diagnostic code. */
|
|
219
|
-
readonly code: string;
|
|
220
|
-
/** The HTTP status the gateway answered with, when the error came from it. */
|
|
221
|
-
readonly status: number | undefined;
|
|
222
|
-
/** The diagnostic, when the gateway sent one. */
|
|
223
|
-
readonly diagnostic: DiagnosticLike | undefined;
|
|
224
|
-
/** Extra data the refusal carried, such as the existing submission of `MOSTRA_SUBMIT_ALREADY`. */
|
|
225
|
-
readonly body: Readonly<Record<string, unknown>> | undefined;
|
|
226
|
-
constructor(code: string, message: string, options?: {
|
|
227
|
-
readonly status?: number;
|
|
228
|
-
readonly diagnostic?: DiagnosticLike;
|
|
229
|
-
readonly body?: Readonly<Record<string, unknown>>;
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
//#endregion
|
|
233
242
|
//#region src/server-hooks.d.ts
|
|
234
243
|
/** What `useAction` shows of its run (INTERFACES §2.3). */
|
|
235
244
|
interface ActionHandle<A extends unknown[], R> {
|
|
@@ -416,6 +425,76 @@ declare global {
|
|
|
416
425
|
}
|
|
417
426
|
}
|
|
418
427
|
//#endregion
|
|
428
|
+
//#region src/team-hooks.d.ts
|
|
429
|
+
/** What `useRespondents` returns (CO-03). */
|
|
430
|
+
interface Respondents {
|
|
431
|
+
/** `loading` until the roster first arrives; `unavailable` outside a live page. */
|
|
432
|
+
readonly status: "loading" | "ready" | "unavailable";
|
|
433
|
+
/** What viewers see of each other on this artifact (its manifest's `team.visibility`). */
|
|
434
|
+
readonly visibility?: TeamVisibility$1;
|
|
435
|
+
/** Whether this viewer is the artifact's owner, who sees everyone whatever the visibility. */
|
|
436
|
+
readonly owner: boolean;
|
|
437
|
+
/** The roster's round: 1 under `once`; under `epochs`, one more after each time everyone answered. */
|
|
438
|
+
readonly round: number;
|
|
439
|
+
/** This viewer's own entry, when they are an expected respondent. */
|
|
440
|
+
readonly self?: RespondentForPage$1;
|
|
441
|
+
/** How many stand where; under `counts` and `names` visibility, and for the owner. */
|
|
442
|
+
readonly counts?: RosterCounts$1;
|
|
443
|
+
/** Whether everyone expected answered in this round; under `counts` and `names`, and for the owner. */
|
|
444
|
+
readonly complete?: boolean;
|
|
445
|
+
/** Every expected respondent, in the order they joined; under `names`, and for the owner. */
|
|
446
|
+
readonly respondents: readonly RespondentForPage$1[];
|
|
447
|
+
/** Why the roster couldn't be read, when it couldn't. */
|
|
448
|
+
readonly error?: {
|
|
449
|
+
readonly code: string;
|
|
450
|
+
readonly message: string;
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* The people this artifact expects answers from, and where each stands in the round: not opened,
|
|
455
|
+
* drafting or submitted (CO-03). It follows changes as they happen.
|
|
456
|
+
*
|
|
457
|
+
* ```tsx
|
|
458
|
+
* const { counts, respondents } = useRespondents();
|
|
459
|
+
* // "3 of 5 answered", and who is drafting, in the page's own design.
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
export declare function useRespondents(): Respondents;
|
|
463
|
+
/** What `usePresence` shares of this viewer (CO-04): nothing unless the page asks. */
|
|
464
|
+
interface PresenceOptions {
|
|
465
|
+
/** Share this viewer's pointer, in the page's document coordinates. */
|
|
466
|
+
readonly cursor?: boolean;
|
|
467
|
+
/**
|
|
468
|
+
* Share where this viewer is: the focused element's `data-presence-id`, `id` or `name`, and the
|
|
469
|
+
* selected range in a text input.
|
|
470
|
+
*/
|
|
471
|
+
readonly selection?: boolean;
|
|
472
|
+
}
|
|
473
|
+
/** What `usePresence` returns (CO-04). */
|
|
474
|
+
interface Presence {
|
|
475
|
+
/** `joining` until the first answer; `unavailable` outside a live page. */
|
|
476
|
+
readonly status: "joining" | "present" | "unavailable";
|
|
477
|
+
/** What viewers see of each other on this artifact (its manifest's `team.visibility`). */
|
|
478
|
+
readonly visibility?: TeamVisibility$1;
|
|
479
|
+
/** This viewer, as others see them. */
|
|
480
|
+
readonly self?: PresencePeer$1;
|
|
481
|
+
/** Everyone else here now, most recently active first; under `names`, and for the owner. */
|
|
482
|
+
readonly others: readonly PresencePeer$1[];
|
|
483
|
+
/** How many others are here now; under `counts` and `names`, and for the owner. */
|
|
484
|
+
readonly count?: number;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Who is viewing this artifact now (CO-04), as data for the page to draw. With `cursor` and
|
|
488
|
+
* `selection`, this viewer shares their pointer and where they are, ephemerally: never stored,
|
|
489
|
+
* at most 10 updates a second, gone when they leave. Without the hook, nothing is shared.
|
|
490
|
+
*
|
|
491
|
+
* ```tsx
|
|
492
|
+
* const { others } = usePresence({ cursor: true });
|
|
493
|
+
* return others.map((peer) => peer.cursor && <Cursor key={peer.key} name={peer.name} at={peer.cursor} />);
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
496
|
+
export declare function usePresence(options?: PresenceOptions): Presence;
|
|
497
|
+
//#endregion
|
|
419
498
|
//#region src/index.d.ts
|
|
420
499
|
/**
|
|
421
500
|
* Declares an artifact's manifest (INTERFACES §2.2, D51). Mostra reads the object statically
|
|
@@ -428,5 +507,5 @@ declare global {
|
|
|
428
507
|
*/
|
|
429
508
|
export declare function defineArtifact<const M extends ArtifactManifest$1>(manifest: M): M;
|
|
430
509
|
//#endregion
|
|
431
|
-
export type { ActionHandle, ArtifactManifest, ArtifactMode, CallServer, ChoiceCandidate, ClaudeCompatibleStorage, DiagnosticLike, FieldMeta, FieldOptions, LiveKey, LiveResult, LiveSources, LiveValue, LiveValuesOf, ServerReference, ShellConnection, StandardSchema, StorageEntry, SubmissionSummary, SubmitBlocker, SubmitHandle, SubmitState, TallyKey, TallyValue };
|
|
510
|
+
export type { ActionHandle, ArtifactManifest, ArtifactMode, CallServer, ChoiceCandidate, ClaudeCompatibleStorage, DiagnosticLike, FieldMeta, FieldOptions, LiveKey, LiveResult, LiveSources, LiveValue, LiveValuesOf, Peer, Presence, PresenceCursor, PresenceOptions, PresencePeer, PresenceSelection, RespondentForPage, RespondentStatus, Respondents, RosterCounts, ServerReference, ShellConnection, StandardSchema, StorageEntry, SubmissionSummary, SubmitBlocker, SubmitHandle, SubmitState, TallyKey, TallyValue, TeamVisibility };
|
|
432
511
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["SubmissionSummary","SubmitBlocker","TallyValue","ArtifactManifest"],"sources":["../src/runtime/store.ts","../src/hooks.ts","../src/shell-bridge.ts","../src/mount.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["SubmissionSummary","SubmitBlocker","TallyValue","TeamVisibility","RespondentForPage","RosterCounts","PresencePeer","ArtifactManifest"],"sources":["../src/runtime/errors.ts","../src/runtime/store.ts","../src/hooks.ts","../src/shell-bridge.ts","../src/mount.ts","../src/server-hooks.ts","../src/server-reference.ts","../src/storage.ts","../src/team-hooks.ts","../src/index.ts"],"mappings":";;;;;;;;UAMiB;;WAEN;;WAEA;;WAEA;;WAEA;;;qBAIE,oBAAoB;;WAEtB;;WAEA;;WAEA,YAAY;;WAEZ,MAAM,SAAS;EAExB,YACE,cACA,iBACA;aACW;aACA,aAAa;aACb,OAAO,SAAS;;;;;;KCoEnB;;;;KCnEA;;;;;UAsDK,eAAe;;WAErB;;IAEP,SACE;eACY;iBAA6B;;QAAwB;;aAE1D;eAAmB,OAAO;eAAY,QAAQ;;;;;UAK1C,aAAa;;WAEnB;;WAEA;;WAEA;;WAEA,WAAW,eAAe,OAAO,OAAO;;WAExC,QAAQ;;;UAIF,UAAU;;;;;;WAMhB;;WAEA;;WAEA;aAAsB,QA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,oBAAoB,UAAU,WAChDC,eACA,gBAAgB,cACd,YAAY;;UAID,WAAW;;WAEjB,MAAM;;WAEN;;WAEA,QAAQ;;EAEjB;;WAES;;WAEA;;;;;WAKA;;;;;;;;;;;;wBAgBK,QAAQ,UAAU,SAChC,KAAK,GACL;WAAoB;WAAyB;IAC5C,WAAW,UAAU;;wBAER,QAAQ,UAAU,SAChC,KAAK,GACL;WAAqB;WAA0B;IAC9C,WAAW,UAAU;;;;;;;;;;;;UC7QP,gBAAgB,iCAAiC;;MAE5D,MAAM,IAAI,QAAQ;;WAEb;;;KAIC,cAAc,YAAY,oBAAoB;;;;;;wBAiB1C,kBAAkB,UAAU;;;;;wBAY5B,sBAAsB,aAAa;;;;UC/BlC;;WAEN;;WAEA;;WAEA;;;UAIM;;EAEf,IAAI,aAAa,mBAAmB,QAAQ;;EAE5C,IAAI,aAAa,gBAAgB,mBAAmB,QAAQ;;EAE5D,OACE,aACA,mBACC;aAAmB;aAAsB;aAAwB;;;EAEpE,KACE,iBACA,mBACC;aAAmB;aAAyB;aAA0B;;;QA0G5D;YACH;;IAER,SAAS;;;;;;UCzHI;;WAEN;;WAEA,aAAaC;;WAEb;;WAEA;;WAEA,OAAOC;;WAEP,SAASC;;WAET;;WAEA,sBAAsBD;;WAEtB;aAAmB;aAAuB;;;;;;;;;;;;wBAYrC,kBAAkB;;UAiCjB;;WAEN;;;;;WAKA;;;UAIM;;WAEN;;WAEA,aAAaD;;WAEb,OAAOG;;WAEP,iBAAiBA;;WAEjB;;;;;;;;;;;;wBAaK,YAAY,UAAS,kBAAuB;;;;;;;;;;;;wBCjC5C,qBAAqB,UAAUC,oBAAkB,UAAU,IAAI"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { _ as serverFunctionId, a as useSignal, c as useSubmitControl, d as connectShell, i as useField, l as useViewer, m as reportReady, n as useArtifact, o as useStore, p as openLink, r as useChoice, s as useSubmit, x as MostraError } from "./hooks-
|
|
3
|
-
import { a as createServerReference, o as setServerCallback, t as mountArtifact } from "./mount-
|
|
2
|
+
import { _ as serverFunctionId, a as useSignal, c as useSubmitControl, d as connectShell, i as useField, l as useViewer, m as reportReady, n as useArtifact, o as useStore, p as openLink, r as useChoice, s as useSubmit, x as MostraError } from "./hooks-BfV824_7.js";
|
|
3
|
+
import { a as createServerReference, o as setServerCallback, t as mountArtifact } from "./mount-DmfrLZvk.js";
|
|
4
4
|
import { isFinalRunStatus } from "@mostra/protocol";
|
|
5
5
|
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
6
6
|
//#region src/server-hooks.ts
|
|
@@ -181,6 +181,103 @@ function useLive(key, options) {
|
|
|
181
181
|
]);
|
|
182
182
|
}
|
|
183
183
|
//#endregion
|
|
184
|
+
//#region src/team-hooks.ts
|
|
185
|
+
/**
|
|
186
|
+
* The people this artifact expects answers from, and where each stands in the round: not opened,
|
|
187
|
+
* drafting or submitted (CO-03). It follows changes as they happen.
|
|
188
|
+
*
|
|
189
|
+
* ```tsx
|
|
190
|
+
* const { counts, respondents } = useRespondents();
|
|
191
|
+
* // "3 of 5 answered", and who is drafting, in the page's own design.
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
function useRespondents() {
|
|
195
|
+
const team = useStore().team;
|
|
196
|
+
useSyncExternalStore(team.subscribe, team.version, team.version);
|
|
197
|
+
useEffect(() => team.available ? team.watchRespondents() : void 0, [team]);
|
|
198
|
+
const roster = team.roster();
|
|
199
|
+
const error = team.rosterError();
|
|
200
|
+
return useMemo(() => {
|
|
201
|
+
if (!team.available) return {
|
|
202
|
+
status: "unavailable",
|
|
203
|
+
owner: false,
|
|
204
|
+
round: 1,
|
|
205
|
+
respondents: []
|
|
206
|
+
};
|
|
207
|
+
if (!roster) return {
|
|
208
|
+
status: "loading",
|
|
209
|
+
owner: false,
|
|
210
|
+
round: 1,
|
|
211
|
+
respondents: [],
|
|
212
|
+
...error ? { error: {
|
|
213
|
+
code: error.code,
|
|
214
|
+
message: error.message
|
|
215
|
+
} } : {}
|
|
216
|
+
};
|
|
217
|
+
return {
|
|
218
|
+
status: "ready",
|
|
219
|
+
visibility: roster.visibility,
|
|
220
|
+
owner: roster.owner,
|
|
221
|
+
round: roster.round,
|
|
222
|
+
...roster.self ? { self: roster.self } : {},
|
|
223
|
+
...roster.counts ? { counts: roster.counts } : {},
|
|
224
|
+
...roster.complete !== void 0 ? { complete: roster.complete } : {},
|
|
225
|
+
respondents: roster.respondents ?? [],
|
|
226
|
+
...error ? { error: {
|
|
227
|
+
code: error.code,
|
|
228
|
+
message: error.message
|
|
229
|
+
} } : {}
|
|
230
|
+
};
|
|
231
|
+
}, [
|
|
232
|
+
team,
|
|
233
|
+
roster,
|
|
234
|
+
error
|
|
235
|
+
]);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Who is viewing this artifact now (CO-04), as data for the page to draw. With `cursor` and
|
|
239
|
+
* `selection`, this viewer shares their pointer and where they are, ephemerally: never stored,
|
|
240
|
+
* at most 10 updates a second, gone when they leave. Without the hook, nothing is shared.
|
|
241
|
+
*
|
|
242
|
+
* ```tsx
|
|
243
|
+
* const { others } = usePresence({ cursor: true });
|
|
244
|
+
* return others.map((peer) => peer.cursor && <Cursor key={peer.key} name={peer.name} at={peer.cursor} />);
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
function usePresence(options = {}) {
|
|
248
|
+
const team = useStore().team;
|
|
249
|
+
useSyncExternalStore(team.subscribe, team.version, team.version);
|
|
250
|
+
const cursor = options.cursor === true;
|
|
251
|
+
const selection = options.selection === true;
|
|
252
|
+
useEffect(() => team.available ? team.joinPresence({
|
|
253
|
+
cursor,
|
|
254
|
+
selection
|
|
255
|
+
}) : void 0, [
|
|
256
|
+
team,
|
|
257
|
+
cursor,
|
|
258
|
+
selection
|
|
259
|
+
]);
|
|
260
|
+
const state = team.presence();
|
|
261
|
+
return useMemo(() => {
|
|
262
|
+
if (!team.available) return {
|
|
263
|
+
status: "unavailable",
|
|
264
|
+
others: []
|
|
265
|
+
};
|
|
266
|
+
if (!state) return {
|
|
267
|
+
status: "joining",
|
|
268
|
+
others: []
|
|
269
|
+
};
|
|
270
|
+
const self = state.peers.find((peer) => peer.self);
|
|
271
|
+
return {
|
|
272
|
+
status: "present",
|
|
273
|
+
visibility: state.visibility,
|
|
274
|
+
...self ? { self } : {},
|
|
275
|
+
others: state.peers.filter((peer) => !peer.self),
|
|
276
|
+
...state.others !== void 0 ? { count: state.others } : {}
|
|
277
|
+
};
|
|
278
|
+
}, [team, state]);
|
|
279
|
+
}
|
|
280
|
+
//#endregion
|
|
184
281
|
//#region src/index.ts
|
|
185
282
|
/**
|
|
186
283
|
* Declares an artifact's manifest (INTERFACES §2.2, D51). Mostra reads the object statically
|
|
@@ -195,6 +292,6 @@ function defineArtifact(manifest) {
|
|
|
195
292
|
return manifest;
|
|
196
293
|
}
|
|
197
294
|
//#endregion
|
|
198
|
-
export { MostraError, connectShell, createServerReference, defineArtifact, mountArtifact, openLink, reportReady, setServerCallback, useAction, useArtifact, useChoice, useField, useLive, useSignal, useSubmit, useSubmitControl, useViewer };
|
|
295
|
+
export { MostraError, connectShell, createServerReference, defineArtifact, mountArtifact, openLink, reportReady, setServerCallback, useAction, useArtifact, useChoice, useField, useLive, usePresence, useRespondents, useSignal, useSubmit, useSubmitControl, useViewer };
|
|
199
296
|
|
|
200
297
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/server-hooks.ts","../src/index.ts"],"sourcesContent":["\"use client\";\n\n/**\n * Server functions and live data in the page (INTERFACES §2.3, D54, D56): `useAction` turns calls\n * of a `\"use server\"` function into durable action runs, and `useLive` reads a live source. Both\n * share the page's runtime, its view and its event stream, so a run started in one tab or before a\n * reload is followed the same way, and every component showing one source shares one value.\n */\nimport {\n isFinalRunStatus,\n type RunProgress,\n type RunStatus,\n type TallyValue,\n} from \"@mostra/protocol\";\nimport { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from \"react\";\nimport { useStore } from \"./hooks.ts\";\nimport { MostraError } from \"./runtime/errors.ts\";\nimport { serverFunctionId } from \"./runtime/server-client.ts\";\n\n// ── useAction ─────────────────────────────────────────────────────────────────────────────\n\n/** What `useAction` shows of its run (INTERFACES §2.3). */\nexport interface ActionHandle<A extends unknown[], R> {\n /**\n * Runs the action: a durable run (D24) whose result this resolves with, or whose failure it\n * rejects with as a `MostraError`. While this hook's run is in flight, another call joins it; with\n * a `key`, every call anywhere joins the one run of that key, so it happens at most once.\n */\n run(...args: A): Promise<R>;\n /**\n * `idle` before any run, then the run's state. `waiting` is reserved for a run waiting for its\n * owner's instance (a hosted artifact, WP-28).\n */\n readonly status: \"idle\" | RunStatus;\n /** Whether a run is starting or in flight. */\n readonly isPending: boolean;\n /** The result, once the run succeeded. */\n readonly data?: R;\n /** Why the run failed, was cancelled or couldn't start. */\n readonly error?: { readonly code: string; readonly message: string };\n /** The run's latest progress (`progress()` in the action). */\n readonly progress?: RunProgress;\n /** The run's log lines (`log()` and the console in the action), capped at 1 MB. */\n readonly log: readonly string[];\n /** For an action that returns an async iterable: the items it yielded so far. */\n readonly partial: readonly (R extends AsyncIterable<infer T> ? T : unknown)[];\n /** Cancels the run: the action's `abortSignal` fires (AC-04). */\n cancel(): void;\n /** The run's `run_` ID, once it has one. */\n readonly runId?: string;\n}\n\nconst NO_LOG: readonly string[] = [];\n\n/** What `useAction` knows of one function and key. */\ninterface IdentityState {\n readonly runId?: string | undefined;\n readonly starting: boolean;\n readonly startError?: { code: string; message: string } | undefined;\n}\n\nconst IDLE: IdentityState = { starting: false };\nconst NO_STATES: ReadonlyMap<string, IdentityState> = new Map();\n\n/**\n * Runs a `\"use server\"` function as durable action runs (D24, D54): each call is recorded before\n * it runs, streams progress, log lines and partial results, survives the tab closing, and is\n * found again after a reload. Without a `key`, a call while this hook's run is in flight joins it,\n * so a double click runs once; with a `key`, the run of that key happens at most once across\n * clicks, tabs, reloads and devices, and a page that opens later shows it.\n *\n * ```tsx\n * const send = useAction(sendReply, { key: `send.${message.id}` });\n * <button disabled={send.isPending || send.status === \"succeeded\"} onClick={() => send.run(message.id, reply)}>\n * {send.status === \"succeeded\" ? \"Sent\" : (send.progress?.message ?? \"Send\")}\n * </button>\n * ```\n */\nexport function useAction<A extends unknown[], R>(\n fn: (...args: A) => Promise<R>,\n options?: { readonly key?: string },\n): ActionHandle<A, Awaited<R>> {\n const store = useStore();\n const server = store.server;\n const fnId = serverFunctionId(fn);\n const key = options?.key;\n // Everything the hook knows belongs to one function and key: a component that changes either\n // shows the new one's run, never the old one's, and a late answer for the old one lands under\n // the old identity, where the hook no longer looks.\n const identity = `${fnId ?? \"\"}\\u0000${key ?? \"\"}`;\n const [states, setStates] = useState<ReadonlyMap<string, IdentityState>>(NO_STATES);\n const current = states.get(identity) ?? IDLE;\n const { runId, starting, startError } = current;\n const update = useCallback((of: string, patch: Partial<IdentityState>): void => {\n setStates((previous) => {\n const next = new Map(previous);\n next.set(of, { ...(previous.get(of) ?? IDLE), ...patch });\n return next;\n });\n }, []);\n const inFlight = useRef(new Map<string, Promise<unknown>>());\n useSyncExternalStore(server.subscribe, server.version, server.version);\n\n // A keyed run started earlier, in another tab or before a reload, is shown again (AC-02).\n useEffect(() => {\n if (key === undefined || fnId === undefined || store.mode !== \"live\") return;\n let active = true;\n server.attach({ keyed: [{ fnId, key }] }).then(\n (runs) => {\n const [found] = runs;\n if (active && found) update(identity, { runId: found.runId });\n },\n () => {},\n );\n return () => {\n active = false;\n };\n }, [server, store.mode, fnId, key, identity, update]);\n\n const view = runId === undefined ? undefined : server.run(runId);\n\n const run = useCallback(\n (...args: A): Promise<Awaited<R>> => {\n if (fnId === undefined) {\n return Promise.reject(\n new TypeError(\n 'useAction needs a server function: import it from a module that starts with \"use server\".',\n ),\n );\n }\n // One run in flight per hook instance and function and key (D54): a second click joins it.\n const joined = inFlight.current.get(identity);\n if (joined) return joined as Promise<Awaited<R>>;\n update(identity, { starting: true, startError: undefined });\n const started = (async () => {\n let state: Awaited<ReturnType<typeof server.startRun>>;\n try {\n state = await server.startRun(fnId, args, key);\n } catch (error) {\n // The run never started (a refused link, a parked worker, the network): say why.\n update(identity, {\n starting: false,\n startError:\n error instanceof MostraError\n ? { code: error.code, message: error.message }\n : { code: \"MOSTRA_ACTION_THREW\", message: (error as Error).message },\n });\n throw error;\n }\n update(identity, { starting: false, runId: state.runId });\n return server.settled(state.runId);\n })();\n inFlight.current.set(identity, started);\n const settle = (): void => {\n if (inFlight.current.get(identity) === started) inFlight.current.delete(identity);\n };\n started.then(settle, settle);\n return started as Promise<Awaited<R>>;\n },\n [server, fnId, key, identity, update],\n );\n\n const cancel = useCallback(() => {\n if (runId === undefined) return;\n const current = server.run(runId);\n if (current && !isFinalRunStatus(current.status)) void server.cancel(runId).catch(() => {});\n }, [server, runId]);\n\n return useMemo(() => {\n const status: ActionHandle<A, Awaited<R>>[\"status\"] = view?.status ?? \"idle\";\n const error =\n view?.error &&\n (view.status === \"failed\" || view.status === \"cancelled\" || view.status === \"unknown\")\n ? { code: view.error.code ?? \"MOSTRA_ACTION_THREW\", message: view.error.message }\n : view?.status === \"cancelled\"\n ? { code: \"MOSTRA_ACTION_CANCELLED\", message: \"The run was cancelled.\" }\n : startError;\n return {\n run,\n cancel,\n status,\n isPending: starting || status === \"queued\" || status === \"running\" || status === \"waiting\",\n ...(view?.status === \"succeeded\" && view.data !== undefined\n ? { data: view.data as Awaited<R> }\n : {}),\n ...(error ? { error } : {}),\n ...(view?.progress ? { progress: view.progress } : {}),\n log: view?.log ?? NO_LOG,\n partial: (view?.partial ?? []) as ActionHandle<A, Awaited<R>>[\"partial\"],\n ...(runId !== undefined ? { runId } : {}),\n };\n }, [run, cancel, view, starting, startError, runId]);\n}\n\n// ── useLive ───────────────────────────────────────────────────────────────────────────────\n\n/**\n * The live sources of the artifact, by key, with their value types. A generated declaration\n * (`mostra-env.d.ts`, written by `mostra new`) fills it from `live.ts`:\n *\n * ```ts\n * declare module \"@mostra/react\" {\n * interface LiveSources extends LiveValuesOf<typeof import(\"./live\")> {}\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noEmptyInterface: augmented by each artifact's declaration.\nexport interface LiveSources {}\n\n/** The value types of a `live.ts` module's sources, by export name (D56). */\nexport type LiveValuesOf<M> = {\n [K in keyof M as M[K] extends { readonly \"~mostra.live\": unknown } ? K : never]: M[K] extends {\n readonly __value?: infer T;\n }\n ? T\n : never;\n};\n\n/**\n * A tally's key, `$tally/<field>` (D165 item 12): the counts of a fixed-choice field the manifest's\n * `tally` names, which Mostra keeps and pushes itself.\n */\nexport type TallyKey = `$tally/${string}`;\n\n/**\n * A live source's key: one of `LiveSources`, or any string before the declaration exists, or a\n * tally's key.\n */\nexport type LiveKey =\n | ([keyof LiveSources] extends [never] ? string : keyof LiveSources & string)\n | TallyKey;\n\n/** A live source's value type; a tally's is `TallyValue`. */\nexport type LiveValue<K extends string> = K extends TallyKey\n ? TallyValue\n : K extends keyof LiveSources\n ? LiveSources[K]\n : unknown;\n\n/** What `useLive` shows (INTERFACES §2.3). */\nexport interface LiveResult<T> {\n /** The latest value; in append mode, the values kept, oldest first. */\n readonly data: T | undefined;\n /** Whether no value has arrived yet. */\n readonly isLoading: boolean;\n /** The producer's last failure; the last good value stays in `data` (FAILURE_MODEL §6). */\n readonly error?: Error;\n /** Asks the producer to load again now. */\n refresh(): void;\n /** The value's revision, which only grows. */\n readonly revision?: string;\n /** When the value was produced. */\n readonly at?: string;\n /**\n * On a hosted page, `true` while the page's owner is offline, so its producer can't refresh the\n * value: `data` is the last value, from `at` (D165 item 4).\n */\n readonly ownerOffline?: boolean;\n}\n\n/** How long append mode keeps values without a `window`. */\nconst DEFAULT_WINDOW = 1024;\n\n/**\n * Reads a live source of `live.ts`, or one an agent or host pushes to (D56): the latest value, or\n * in append mode the recent values for a high-rate chart. The value is shared by every component\n * that shows it and updates without a reload; nothing of it is a durable event (D63).\n *\n * ```tsx\n * const { data, isLoading, error } = useLive(\"inbox\");\n * const { data: points } = useLive(\"cpu\", { mode: \"append\", window: 600 });\n * ```\n */\nexport function useLive<K extends LiveKey>(\n key: K,\n options: { readonly mode: \"append\"; readonly window?: number },\n): LiveResult<LiveValue<K>[]>;\n/** Reads a live source's latest value (D56). See the first signature. */\nexport function useLive<K extends LiveKey>(\n key: K,\n options?: { readonly mode?: \"latest\"; readonly window?: number },\n): LiveResult<LiveValue<K>>;\nexport function useLive<K extends LiveKey>(\n key: K,\n options?: { readonly mode?: \"latest\" | \"append\"; readonly window?: number },\n): LiveResult<unknown> {\n const store = useStore();\n const server = store.server;\n const append = options?.mode === \"append\";\n const window = append ? (options?.window ?? DEFAULT_WINDOW) : undefined;\n useSyncExternalStore(server.subscribe, server.version, server.version);\n useEffect(() => server.watchLive(key, window), [server, key, window]);\n const view = server.liveView(key);\n const refresh = useCallback(() => server.refreshLive(key), [server, key]);\n return useMemo(() => {\n const data = append\n ? view?.ring.length\n ? view.ring.slice(-(window ?? 0))\n : undefined\n : view?.data;\n return {\n data,\n isLoading: data === undefined && (view?.loading ?? true),\n ...(view?.error\n ? {\n error: new MostraError(\n view.error.code ?? \"MOSTRA_LIVE_SOURCE_FAILED\",\n view.error.message,\n ),\n }\n : {}),\n refresh,\n ...(view?.revision !== undefined ? { revision: view.revision } : {}),\n ...(view?.at !== undefined ? { at: view.at } : {}),\n ...(view?.ownerOffline ? { ownerOffline: true } : {}),\n };\n }, [view, append, window, refresh]);\n}\n","\"use client\";\n\n/**\n * `@mostra/react`: the client runtime artifact authors import (INTERFACES §2.3). Fields that behave\n * like `useState` with a stable ID and persist as the viewer works, the artifact channel's\n * submit, the shell's trusted Submit label, signals, review-set choices, the viewer and the\n * artifact, a Claude-compatible `window.storage`, and the manifest helper. `@mostra/react/form`\n * adapts react-hook-form; `@mostra/react/router` mounts `pages/` artifacts.\n *\n * ```tsx\n * import { defineArtifact, useField, useSubmitControl } from \"@mostra/react\";\n *\n * export const artifact = defineArtifact({ title: \"Sidebar options\", family: \"review\" });\n *\n * export default function Page() {\n * const [layout, setLayout] = useField(\"layout\", \"left\", { label: \"Layout\", required: true });\n * useSubmitControl({ label: \"Send my choice\" });\n * return <select value={layout} onChange={(e) => setLayout(e.target.value)}>…</select>;\n * }\n * ```\n *\n * @packageDocumentation\n */\nimport type { ArtifactManifest } from \"@mostra/protocol\";\n\nexport type {\n ArtifactManifest,\n SubmissionSummary,\n SubmitBlocker,\n TallyValue,\n} from \"@mostra/protocol\";\nexport {\n type ArtifactMode,\n type ChoiceCandidate,\n type FieldMeta,\n type FieldOptions,\n type StandardSchema,\n type SubmitHandle,\n useArtifact,\n useChoice,\n useField,\n useSignal,\n useSubmit,\n useSubmitControl,\n useViewer,\n} from \"./hooks.ts\";\nexport { mountArtifact } from \"./mount.ts\";\nexport { type DiagnosticLike, MostraError } from \"./runtime/errors.ts\";\nexport type { SubmitState } from \"./runtime/store.ts\";\nexport {\n type ActionHandle,\n type LiveKey,\n type LiveResult,\n type LiveSources,\n type LiveValue,\n type LiveValuesOf,\n type TallyKey,\n useAction,\n useLive,\n} from \"./server-hooks.ts\";\nexport {\n type CallServer,\n createServerReference,\n type ServerReference,\n setServerCallback,\n} from \"./server-reference.ts\";\nexport { connectShell, openLink, reportReady, type ShellConnection } from \"./shell-bridge.ts\";\nexport type { ClaudeCompatibleStorage, StorageEntry } from \"./storage.ts\";\n\n/**\n * Declares an artifact's manifest (INTERFACES §2.2, D51). Mostra reads the object statically\n * without running the page, so write every value as a literal: strings, numbers, booleans, arrays\n * and objects. At run time it returns its argument unchanged.\n *\n * ```ts\n * export const artifact = defineArtifact({ title: \"Q3 plan\", family: \"proposal\" });\n * ```\n */\nexport function defineArtifact<const M extends ArtifactManifest>(manifest: M): M {\n return manifest;\n}\n"],"mappings":";;;;;;;;;;;;AAoDA,MAAM,SAA4B,CAAC;AASnC,MAAM,OAAsB,EAAE,UAA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U,KAAK,SAAS,IAAI,CAAC;GAClE,GAAI,MAAM,OAAO,KAAA,IAAY,EAAE,IAAI,KAAK,GAAG,IAAI,CAAC;GAChD,GAAI,MAAM,eAAe,EAAE,cAAc,KAAK,IAAI,CAAC;EACrD;CACF,GAAG;EAAC;EAAM;EAAQ;EAAQ;CAAO,CAAC;AACpC;;;;;;;;;;;;AC/OA,SAAgB,eAAiD,UAAgB;CAC/E,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/server-hooks.ts","../src/team-hooks.ts","../src/index.ts"],"sourcesContent":["\"use client\";\n\n/**\n * Server functions and live data in the page (INTERFACES §2.3, D54, D56): `useAction` turns calls\n * of a `\"use server\"` function into durable action runs, and `useLive` reads a live source. Both\n * share the page's runtime, its view and its event stream, so a run started in one tab or before a\n * reload is followed the same way, and every component showing one source shares one value.\n */\nimport {\n isFinalRunStatus,\n type RunProgress,\n type RunStatus,\n type TallyValue,\n} from \"@mostra/protocol\";\nimport { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from \"react\";\nimport { useStore } from \"./hooks.ts\";\nimport { MostraError } from \"./runtime/errors.ts\";\nimport { serverFunctionId } from \"./runtime/server-client.ts\";\n\n// ── useAction ─────────────────────────────────────────────────────────────────────────────\n\n/** What `useAction` shows of its run (INTERFACES §2.3). */\nexport interface ActionHandle<A extends unknown[], R> {\n /**\n * Runs the action: a durable run (D24) whose result this resolves with, or whose failure it\n * rejects with as a `MostraError`. While this hook's run is in flight, another call joins it; with\n * a `key`, every call anywhere joins the one run of that key, so it happens at most once.\n */\n run(...args: A): Promise<R>;\n /**\n * `idle` before any run, then the run's state. `waiting` is reserved for a run waiting for its\n * owner's instance (a hosted artifact, WP-28).\n */\n readonly status: \"idle\" | RunStatus;\n /** Whether a run is starting or in flight. */\n readonly isPending: boolean;\n /** The result, once the run succeeded. */\n readonly data?: R;\n /** Why the run failed, was cancelled or couldn't start. */\n readonly error?: { readonly code: string; readonly message: string };\n /** The run's latest progress (`progress()` in the action). */\n readonly progress?: RunProgress;\n /** The run's log lines (`log()` and the console in the action), capped at 1 MB. */\n readonly log: readonly string[];\n /** For an action that returns an async iterable: the items it yielded so far. */\n readonly partial: readonly (R extends AsyncIterable<infer T> ? T : unknown)[];\n /** Cancels the run: the action's `abortSignal` fires (AC-04). */\n cancel(): void;\n /** The run's `run_` ID, once it has one. */\n readonly runId?: string;\n}\n\nconst NO_LOG: readonly string[] = [];\n\n/** What `useAction` knows of one function and key. */\ninterface IdentityState {\n readonly runId?: string | undefined;\n readonly starting: boolean;\n readonly startError?: { code: string; message: string } | undefined;\n}\n\nconst IDLE: IdentityState = { starting: false };\nconst NO_STATES: ReadonlyMap<string, IdentityState> = new Map();\n\n/**\n * Runs a `\"use server\"` function as durable action runs (D24, D54): each call is recorded before\n * it runs, streams progress, log lines and partial results, survives the tab closing, and is\n * found again after a reload. Without a `key`, a call while this hook's run is in flight joins it,\n * so a double click runs once; with a `key`, the run of that key happens at most once across\n * clicks, tabs, reloads and devices, and a page that opens later shows it.\n *\n * ```tsx\n * const send = useAction(sendReply, { key: `send.${message.id}` });\n * <button disabled={send.isPending || send.status === \"succeeded\"} onClick={() => send.run(message.id, reply)}>\n * {send.status === \"succeeded\" ? \"Sent\" : (send.progress?.message ?? \"Send\")}\n * </button>\n * ```\n */\nexport function useAction<A extends unknown[], R>(\n fn: (...args: A) => Promise<R>,\n options?: { readonly key?: string },\n): ActionHandle<A, Awaited<R>> {\n const store = useStore();\n const server = store.server;\n const fnId = serverFunctionId(fn);\n const key = options?.key;\n // Everything the hook knows belongs to one function and key: a component that changes either\n // shows the new one's run, never the old one's, and a late answer for the old one lands under\n // the old identity, where the hook no longer looks.\n const identity = `${fnId ?? \"\"}\\u0000${key ?? \"\"}`;\n const [states, setStates] = useState<ReadonlyMap<string, IdentityState>>(NO_STATES);\n const current = states.get(identity) ?? IDLE;\n const { runId, starting, startError } = current;\n const update = useCallback((of: string, patch: Partial<IdentityState>): void => {\n setStates((previous) => {\n const next = new Map(previous);\n next.set(of, { ...(previous.get(of) ?? IDLE), ...patch });\n return next;\n });\n }, []);\n const inFlight = useRef(new Map<string, Promise<unknown>>());\n useSyncExternalStore(server.subscribe, server.version, server.version);\n\n // A keyed run started earlier, in another tab or before a reload, is shown again (AC-02).\n useEffect(() => {\n if (key === undefined || fnId === undefined || store.mode !== \"live\") return;\n let active = true;\n server.attach({ keyed: [{ fnId, key }] }).then(\n (runs) => {\n const [found] = runs;\n if (active && found) update(identity, { runId: found.runId });\n },\n () => {},\n );\n return () => {\n active = false;\n };\n }, [server, store.mode, fnId, key, identity, update]);\n\n const view = runId === undefined ? undefined : server.run(runId);\n\n const run = useCallback(\n (...args: A): Promise<Awaited<R>> => {\n if (fnId === undefined) {\n return Promise.reject(\n new TypeError(\n 'useAction needs a server function: import it from a module that starts with \"use server\".',\n ),\n );\n }\n // One run in flight per hook instance and function and key (D54): a second click joins it.\n const joined = inFlight.current.get(identity);\n if (joined) return joined as Promise<Awaited<R>>;\n update(identity, { starting: true, startError: undefined });\n const started = (async () => {\n let state: Awaited<ReturnType<typeof server.startRun>>;\n try {\n state = await server.startRun(fnId, args, key);\n } catch (error) {\n // The run never started (a refused link, a parked worker, the network): say why.\n update(identity, {\n starting: false,\n startError:\n error instanceof MostraError\n ? { code: error.code, message: error.message }\n : { code: \"MOSTRA_ACTION_THREW\", message: (error as Error).message },\n });\n throw error;\n }\n update(identity, { starting: false, runId: state.runId });\n return server.settled(state.runId);\n })();\n inFlight.current.set(identity, started);\n const settle = (): void => {\n if (inFlight.current.get(identity) === started) inFlight.current.delete(identity);\n };\n started.then(settle, settle);\n return started as Promise<Awaited<R>>;\n },\n [server, fnId, key, identity, update],\n );\n\n const cancel = useCallback(() => {\n if (runId === undefined) return;\n const current = server.run(runId);\n if (current && !isFinalRunStatus(current.status)) void server.cancel(runId).catch(() => {});\n }, [server, runId]);\n\n return useMemo(() => {\n const status: ActionHandle<A, Awaited<R>>[\"status\"] = view?.status ?? \"idle\";\n const error =\n view?.error &&\n (view.status === \"failed\" || view.status === \"cancelled\" || view.status === \"unknown\")\n ? { code: view.error.code ?? \"MOSTRA_ACTION_THREW\", message: view.error.message }\n : view?.status === \"cancelled\"\n ? { code: \"MOSTRA_ACTION_CANCELLED\", message: \"The run was cancelled.\" }\n : startError;\n return {\n run,\n cancel,\n status,\n isPending: starting || status === \"queued\" || status === \"running\" || status === \"waiting\",\n ...(view?.status === \"succeeded\" && view.data !== undefined\n ? { data: view.data as Awaited<R> }\n : {}),\n ...(error ? { error } : {}),\n ...(view?.progress ? { progress: view.progress } : {}),\n log: view?.log ?? NO_LOG,\n partial: (view?.partial ?? []) as ActionHandle<A, Awaited<R>>[\"partial\"],\n ...(runId !== undefined ? { runId } : {}),\n };\n }, [run, cancel, view, starting, startError, runId]);\n}\n\n// ── useLive ───────────────────────────────────────────────────────────────────────────────\n\n/**\n * The live sources of the artifact, by key, with their value types. A generated declaration\n * (`mostra-env.d.ts`, written by `mostra new`) fills it from `live.ts`:\n *\n * ```ts\n * declare module \"@mostra/react\" {\n * interface LiveSources extends LiveValuesOf<typeof import(\"./live\")> {}\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noEmptyInterface: augmented by each artifact's declaration.\nexport interface LiveSources {}\n\n/** The value types of a `live.ts` module's sources, by export name (D56). */\nexport type LiveValuesOf<M> = {\n [K in keyof M as M[K] extends { readonly \"~mostra.live\": unknown } ? K : never]: M[K] extends {\n readonly __value?: infer T;\n }\n ? T\n : never;\n};\n\n/**\n * A tally's key, `$tally/<field>` (D165 item 12): the counts of a fixed-choice field the manifest's\n * `tally` names, which Mostra keeps and pushes itself.\n */\nexport type TallyKey = `$tally/${string}`;\n\n/**\n * A live source's key: one of `LiveSources`, or any string before the declaration exists, or a\n * tally's key.\n */\nexport type LiveKey =\n | ([keyof LiveSources] extends [never] ? string : keyof LiveSources & string)\n | TallyKey;\n\n/** A live source's value type; a tally's is `TallyValue`. */\nexport type LiveValue<K extends string> = K extends TallyKey\n ? TallyValue\n : K extends keyof LiveSources\n ? LiveSources[K]\n : unknown;\n\n/** What `useLive` shows (INTERFACES §2.3). */\nexport interface LiveResult<T> {\n /** The latest value; in append mode, the values kept, oldest first. */\n readonly data: T | undefined;\n /** Whether no value has arrived yet. */\n readonly isLoading: boolean;\n /** The producer's last failure; the last good value stays in `data` (FAILURE_MODEL §6). */\n readonly error?: Error;\n /** Asks the producer to load again now. */\n refresh(): void;\n /** The value's revision, which only grows. */\n readonly revision?: string;\n /** When the value was produced. */\n readonly at?: string;\n /**\n * On a hosted page, `true` while the page's owner is offline, so its producer can't refresh the\n * value: `data` is the last value, from `at` (D165 item 4).\n */\n readonly ownerOffline?: boolean;\n}\n\n/** How long append mode keeps values without a `window`. */\nconst DEFAULT_WINDOW = 1024;\n\n/**\n * Reads a live source of `live.ts`, or one an agent or host pushes to (D56): the latest value, or\n * in append mode the recent values for a high-rate chart. The value is shared by every component\n * that shows it and updates without a reload; nothing of it is a durable event (D63).\n *\n * ```tsx\n * const { data, isLoading, error } = useLive(\"inbox\");\n * const { data: points } = useLive(\"cpu\", { mode: \"append\", window: 600 });\n * ```\n */\nexport function useLive<K extends LiveKey>(\n key: K,\n options: { readonly mode: \"append\"; readonly window?: number },\n): LiveResult<LiveValue<K>[]>;\n/** Reads a live source's latest value (D56). See the first signature. */\nexport function useLive<K extends LiveKey>(\n key: K,\n options?: { readonly mode?: \"latest\"; readonly window?: number },\n): LiveResult<LiveValue<K>>;\nexport function useLive<K extends LiveKey>(\n key: K,\n options?: { readonly mode?: \"latest\" | \"append\"; readonly window?: number },\n): LiveResult<unknown> {\n const store = useStore();\n const server = store.server;\n const append = options?.mode === \"append\";\n const window = append ? (options?.window ?? DEFAULT_WINDOW) : undefined;\n useSyncExternalStore(server.subscribe, server.version, server.version);\n useEffect(() => server.watchLive(key, window), [server, key, window]);\n const view = server.liveView(key);\n const refresh = useCallback(() => server.refreshLive(key), [server, key]);\n return useMemo(() => {\n const data = append\n ? view?.ring.length\n ? view.ring.slice(-(window ?? 0))\n : undefined\n : view?.data;\n return {\n data,\n isLoading: data === undefined && (view?.loading ?? true),\n ...(view?.error\n ? {\n error: new MostraError(\n view.error.code ?? \"MOSTRA_LIVE_SOURCE_FAILED\",\n view.error.message,\n ),\n }\n : {}),\n refresh,\n ...(view?.revision !== undefined ? { revision: view.revision } : {}),\n ...(view?.at !== undefined ? { at: view.at } : {}),\n ...(view?.ownerOffline ? { ownerOffline: true } : {}),\n };\n }, [view, append, window, refresh]);\n}\n","\"use client\";\n\n/**\n * Team hooks (D121, D168; INTERFACES §2.3): who is expected to answer and where each stands, and\n * who is here now with the cursor and selection they share. Both are data for the page to show in\n * its own design: the shell draws nothing (D121). What a viewer sees of others is the artifact's\n * `team.visibility` (`private` unless the manifest opts in); the artifact's owner sees everyone.\n * Outside a live page (a static export) both say `unavailable`.\n */\nimport type {\n PresencePeer,\n RespondentForPage,\n RosterCounts,\n TeamVisibility,\n} from \"@mostra/protocol\";\nimport { useEffect, useMemo, useSyncExternalStore } from \"react\";\nimport { useStore } from \"./hooks.ts\";\n\nexport type {\n Peer,\n PresenceCursor,\n PresencePeer,\n PresenceSelection,\n RespondentForPage,\n RespondentStatus,\n RosterCounts,\n TeamVisibility,\n} from \"@mostra/protocol\";\n\n/** What `useRespondents` returns (CO-03). */\nexport interface Respondents {\n /** `loading` until the roster first arrives; `unavailable` outside a live page. */\n readonly status: \"loading\" | \"ready\" | \"unavailable\";\n /** What viewers see of each other on this artifact (its manifest's `team.visibility`). */\n readonly visibility?: TeamVisibility;\n /** Whether this viewer is the artifact's owner, who sees everyone whatever the visibility. */\n readonly owner: boolean;\n /** The roster's round: 1 under `once`; under `epochs`, one more after each time everyone answered. */\n readonly round: number;\n /** This viewer's own entry, when they are an expected respondent. */\n readonly self?: RespondentForPage;\n /** How many stand where; under `counts` and `names` visibility, and for the owner. */\n readonly counts?: RosterCounts;\n /** Whether everyone expected answered in this round; under `counts` and `names`, and for the owner. */\n readonly complete?: boolean;\n /** Every expected respondent, in the order they joined; under `names`, and for the owner. */\n readonly respondents: readonly RespondentForPage[];\n /** Why the roster couldn't be read, when it couldn't. */\n readonly error?: { readonly code: string; readonly message: string };\n}\n\n/**\n * The people this artifact expects answers from, and where each stands in the round: not opened,\n * drafting or submitted (CO-03). It follows changes as they happen.\n *\n * ```tsx\n * const { counts, respondents } = useRespondents();\n * // \"3 of 5 answered\", and who is drafting, in the page's own design.\n * ```\n */\nexport function useRespondents(): Respondents {\n const store = useStore();\n const team = store.team;\n useSyncExternalStore(team.subscribe, team.version, team.version);\n useEffect(() => (team.available ? team.watchRespondents() : undefined), [team]);\n const roster = team.roster();\n const error = team.rosterError();\n return useMemo((): Respondents => {\n if (!team.available) return { status: \"unavailable\", owner: false, round: 1, respondents: [] };\n if (!roster) {\n return {\n status: \"loading\",\n owner: false,\n round: 1,\n respondents: [],\n ...(error ? { error: { code: error.code, message: error.message } } : {}),\n };\n }\n return {\n status: \"ready\",\n visibility: roster.visibility,\n owner: roster.owner,\n round: roster.round,\n ...(roster.self ? { self: roster.self } : {}),\n ...(roster.counts ? { counts: roster.counts } : {}),\n ...(roster.complete !== undefined ? { complete: roster.complete } : {}),\n respondents: roster.respondents ?? [],\n ...(error ? { error: { code: error.code, message: error.message } } : {}),\n };\n }, [team, roster, error]);\n}\n\n/** What `usePresence` shares of this viewer (CO-04): nothing unless the page asks. */\nexport interface PresenceOptions {\n /** Share this viewer's pointer, in the page's document coordinates. */\n readonly cursor?: boolean;\n /**\n * Share where this viewer is: the focused element's `data-presence-id`, `id` or `name`, and the\n * selected range in a text input.\n */\n readonly selection?: boolean;\n}\n\n/** What `usePresence` returns (CO-04). */\nexport interface Presence {\n /** `joining` until the first answer; `unavailable` outside a live page. */\n readonly status: \"joining\" | \"present\" | \"unavailable\";\n /** What viewers see of each other on this artifact (its manifest's `team.visibility`). */\n readonly visibility?: TeamVisibility;\n /** This viewer, as others see them. */\n readonly self?: PresencePeer;\n /** Everyone else here now, most recently active first; under `names`, and for the owner. */\n readonly others: readonly PresencePeer[];\n /** How many others are here now; under `counts` and `names`, and for the owner. */\n readonly count?: number;\n}\n\n/**\n * Who is viewing this artifact now (CO-04), as data for the page to draw. With `cursor` and\n * `selection`, this viewer shares their pointer and where they are, ephemerally: never stored,\n * at most 10 updates a second, gone when they leave. Without the hook, nothing is shared.\n *\n * ```tsx\n * const { others } = usePresence({ cursor: true });\n * return others.map((peer) => peer.cursor && <Cursor key={peer.key} name={peer.name} at={peer.cursor} />);\n * ```\n */\nexport function usePresence(options: PresenceOptions = {}): Presence {\n const store = useStore();\n const team = store.team;\n useSyncExternalStore(team.subscribe, team.version, team.version);\n const cursor = options.cursor === true;\n const selection = options.selection === true;\n useEffect(\n () => (team.available ? team.joinPresence({ cursor, selection }) : undefined),\n [team, cursor, selection],\n );\n const state = team.presence();\n return useMemo((): Presence => {\n if (!team.available) return { status: \"unavailable\", others: [] };\n if (!state) return { status: \"joining\", others: [] };\n const self = state.peers.find((peer) => peer.self);\n return {\n status: \"present\",\n visibility: state.visibility,\n ...(self ? { self } : {}),\n others: state.peers.filter((peer) => !peer.self),\n ...(state.others !== undefined ? { count: state.others } : {}),\n };\n }, [team, state]);\n}\n","\"use client\";\n\n/**\n * `@mostra/react`: the client runtime artifact authors import (INTERFACES §2.3). Fields that behave\n * like `useState` with a stable ID and persist as the viewer works, the artifact channel's\n * submit, the shell's trusted Submit label, signals, review-set choices, the viewer and the\n * artifact, expected respondents and presence, a Claude-compatible `window.storage`, and the\n * manifest helper. `@mostra/react/form`\n * adapts react-hook-form; `@mostra/react/router` mounts `pages/` artifacts.\n *\n * ```tsx\n * import { defineArtifact, useField, useSubmitControl } from \"@mostra/react\";\n *\n * export const artifact = defineArtifact({ title: \"Sidebar options\", family: \"review\" });\n *\n * export default function Page() {\n * const [layout, setLayout] = useField(\"layout\", \"left\", { label: \"Layout\", required: true });\n * useSubmitControl({ label: \"Send my choice\" });\n * return <select value={layout} onChange={(e) => setLayout(e.target.value)}>…</select>;\n * }\n * ```\n *\n * @packageDocumentation\n */\nimport type { ArtifactManifest } from \"@mostra/protocol\";\n\nexport type {\n ArtifactManifest,\n SubmissionSummary,\n SubmitBlocker,\n TallyValue,\n} from \"@mostra/protocol\";\nexport {\n type ArtifactMode,\n type ChoiceCandidate,\n type FieldMeta,\n type FieldOptions,\n type StandardSchema,\n type SubmitHandle,\n useArtifact,\n useChoice,\n useField,\n useSignal,\n useSubmit,\n useSubmitControl,\n useViewer,\n} from \"./hooks.ts\";\nexport { mountArtifact } from \"./mount.ts\";\nexport { type DiagnosticLike, MostraError } from \"./runtime/errors.ts\";\nexport type { SubmitState } from \"./runtime/store.ts\";\nexport {\n type ActionHandle,\n type LiveKey,\n type LiveResult,\n type LiveSources,\n type LiveValue,\n type LiveValuesOf,\n type TallyKey,\n useAction,\n useLive,\n} from \"./server-hooks.ts\";\nexport {\n type CallServer,\n createServerReference,\n type ServerReference,\n setServerCallback,\n} from \"./server-reference.ts\";\nexport { connectShell, openLink, reportReady, type ShellConnection } from \"./shell-bridge.ts\";\nexport type { ClaudeCompatibleStorage, StorageEntry } from \"./storage.ts\";\nexport {\n type Peer,\n type Presence,\n type PresenceCursor,\n type PresenceOptions,\n type PresencePeer,\n type PresenceSelection,\n type RespondentForPage,\n type RespondentStatus,\n type Respondents,\n type RosterCounts,\n type TeamVisibility,\n usePresence,\n useRespondents,\n} from \"./team-hooks.ts\";\n\n/**\n * Declares an artifact's manifest (INTERFACES §2.2, D51). Mostra reads the object statically\n * without running the page, so write every value as a literal: strings, numbers, booleans, arrays\n * and objects. At run time it returns its argument unchanged.\n *\n * ```ts\n * export const artifact = defineArtifact({ title: \"Q3 plan\", family: \"proposal\" });\n * ```\n */\nexport function defineArtifact<const M extends ArtifactManifest>(manifest: M): M {\n return manifest;\n}\n"],"mappings":";;;;;;;;;;;;AAoDA,MAAM,SAA4B,CAAC;AASnC,MAAM,OAAsB,EAAE,UAAU,MAAM;AAC9C,MAAM,4BAAgD,IAAI,IAAI;;;;;;;;;;;;;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ADQ,SACG,CAAC,CAAC;CACnB,qBAAqB,KAAK,WAAW,KAAK,SAAS,KAAK,OAAO;CAC/D,MAAM,SAAS,QAAQ,WAAW;CAClC,MAAM,YAAY,QAAQ,cAAc;CACxC,gBACS,KAAK,YAAY,KAAK,aAAa;EAAE;EAAQ;CAAU,CAAC,IAAI,KAAA,GACnE;EAAC;EAAM;EAAQ;CAAS,CAC1B;CACA,MAAM,QAAQ,KAAK,SAAS;CAC5B,OAAO,cAAwB;EAC7B,IAAI,CAAC,KAAK,WAAW,OAAO;GAAE,QAAQ;GAAe,QAAQ,CAAC;EAAE;EAChE,IAAI,CAAC,OAAO,OAAO;GAAE,QAAQ;GAAW,QAAQ,CAAC;EAAE;EACnD,MAAM,OAAO,MAAM,MAAM,MAAM,SAAS,KAAK,IAAI;EACjD,OAAO;GACL,QAAQ;GACR,YAAY,MAAM;GAClB,GAAI,OAAO,EAAE,KAAK,IAAI,CAAC;GACvB,QAAQ,MAAM,MAAM,QAAQ,SAAS,CAAC,KAAK,IAAI;GAC/C,GAAI,MAAM,WAAW,KAAA,IAAY,EAAE,OAAO,MAAM,OAAO,IAAI,CAAC;EAC9D;CACF,GAAG,CAAC,MAAM,KAAK,CAAC;AAClB;;;;;;;;;;;;ACxDA,SAAgB,eAAiD,UAAgB;CAC/E,OAAO;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as MemoryJournal, d as connectShell, f as listenShell, g as fieldKey, h as Store, m as reportReady, t as RuntimeProvider, u as builtVersion, v as HttpTransport, x as MostraError, y as IndexedDbJournal } from "./hooks-
|
|
1
|
+
import { b as MemoryJournal, d as connectShell, f as listenShell, g as fieldKey, h as Store, m as reportReady, t as RuntimeProvider, u as builtVersion, v as HttpTransport, x as MostraError, y as IndexedDbJournal } from "./hooks-BfV824_7.js";
|
|
2
2
|
import { BRIDGE_FIELDS_MAX, BRIDGE_TEXT_MAX, VERIFY_PROBE, VERIFY_REPORT, isFieldId, mostraFieldFocus, mostraFields, mostraFlush, mostraPage, mostraVersionAvailable, readViewContext } from "@mostra/protocol";
|
|
3
3
|
import { createElement } from "react";
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
@@ -565,4 +565,4 @@ async function mountArtifact(options) {
|
|
|
565
565
|
//#endregion
|
|
566
566
|
export { createServerReference as a, reportPage as i, prepareArtifact as n, setServerCallback as o, renderArtifact as r, mountArtifact as t };
|
|
567
567
|
|
|
568
|
-
//# sourceMappingURL=mount-
|
|
568
|
+
//# sourceMappingURL=mount-DmfrLZvk.js.map
|