@escapeaihq/client-core 0.139.0 → 0.141.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/api.d.ts +122 -0
  2. package/dist/api.d.ts.map +1 -1
  3. package/dist/api.js +71 -0
  4. package/dist/api.js.map +1 -1
  5. package/dist/domains/adventureDefinitions.d.ts +14 -4
  6. package/dist/domains/adventureDefinitions.d.ts.map +1 -1
  7. package/dist/domains/adventureDefinitions.js +14 -4
  8. package/dist/domains/adventureDefinitions.js.map +1 -1
  9. package/dist/domains/personas.d.ts +3 -0
  10. package/dist/domains/personas.d.ts.map +1 -1
  11. package/dist/domains/personas.js +6 -0
  12. package/dist/domains/personas.js.map +1 -1
  13. package/dist/domains/runtime.d.ts +25 -0
  14. package/dist/domains/runtime.d.ts.map +1 -0
  15. package/dist/domains/runtime.js +29 -0
  16. package/dist/domains/runtime.js.map +1 -0
  17. package/dist/domains/showcase.d.ts +16 -1
  18. package/dist/domains/showcase.d.ts.map +1 -1
  19. package/dist/domains/showcase.js +15 -0
  20. package/dist/domains/showcase.js.map +1 -1
  21. package/dist/generated/contract.d.ts +7 -1
  22. package/dist/generated/contract.d.ts.map +1 -1
  23. package/dist/generated/contract.js.map +1 -1
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +3 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/runtimeEvents.d.ts +111 -0
  29. package/dist/runtimeEvents.d.ts.map +1 -0
  30. package/dist/runtimeEvents.js +55 -0
  31. package/dist/runtimeEvents.js.map +1 -0
  32. package/dist/sceneBridge.d.ts +193 -0
  33. package/dist/sceneBridge.d.ts.map +1 -0
  34. package/dist/sceneBridge.js +329 -0
  35. package/dist/sceneBridge.js.map +1 -0
  36. package/dist/voiceCloneCaption.d.ts +7 -1
  37. package/dist/voiceCloneCaption.d.ts.map +1 -1
  38. package/dist/voiceCloneCaption.js +26 -1
  39. package/dist/voiceCloneCaption.js.map +1 -1
  40. package/dist/websocket.d.ts +18 -1
  41. package/dist/websocket.d.ts.map +1 -1
  42. package/dist/websocket.js +16 -0
  43. package/dist/websocket.js.map +1 -1
  44. package/package.json +1 -1
  45. package/src/__tests__/api.adventure-definitions.test.ts +16 -0
  46. package/src/__tests__/castFramePipelinePending.test.ts +56 -1
  47. package/src/__tests__/persona-generation.test.ts +26 -0
  48. package/src/__tests__/scene-bridge.test.ts +314 -0
  49. package/src/__tests__/voiceCloneCaption.test.ts +56 -0
  50. package/src/api.ts +156 -0
  51. package/src/domains/adventureDefinitions.ts +14 -4
  52. package/src/domains/personas.ts +7 -0
  53. package/src/domains/runtime.ts +38 -0
  54. package/src/domains/showcase.ts +24 -1
  55. package/src/generated/contract.ts +10 -0
  56. package/src/index.ts +3 -0
  57. package/src/runtimeEvents.ts +127 -0
  58. package/src/sceneBridge.ts +433 -0
  59. package/src/voiceCloneCaption.ts +36 -2
  60. package/src/websocket.ts +25 -1
@@ -3,6 +3,7 @@ import {
3
3
  recloneIneligibleMessage,
4
4
  voiceCloneCaption,
5
5
  VOICE_CLONE_CAPTION_REASON_MAX_CHARS,
6
+ VOICE_CLONE_SKIP_CAPTIONS,
6
7
  } from '../voiceCloneCaption';
7
8
 
8
9
  // §Q DM.68 — a default voice standing in for a REFUSED clone must not read
@@ -38,6 +39,61 @@ describe('voiceCloneCaption', () => {
38
39
  );
39
40
  });
40
41
 
42
+ // §Q PERS.130 — one plain reason per skip cause the backend sends.
43
+ it.each([
44
+ ['no_character', 'voice: stock (not linked to a character in the video)'],
45
+ [
46
+ 'speech_unverified',
47
+ 'voice: stock (their voice was not confirmed as theirs; pick their voice sample to allow a clone)',
48
+ ],
49
+ ['speech_untimed', 'voice: stock (their confirmed speech has no usable timing to sample)'],
50
+ ['lines_unusable', 'voice: stock (their lines have no usable timing to sample)'],
51
+ ['lines_too_short', 'voice: stock (each of their lines is too short to sample)'],
52
+ ['lines_unreadable', 'voice: stock (their lines could not be read back from the video)'],
53
+ ['audio_unusable', 'voice: stock (no usable audio could be cut from their lines)'],
54
+ ['no_speech_matched', 'voice: stock (no speech in this video is matched to a speaker yet)'],
55
+ ['no_lines_matched', 'voice: stock (no lines in this video are matched to them)'],
56
+ ] as const)('captions the %s skip with its real reason', (cause, caption) => {
57
+ expect(
58
+ voiceCloneCaption({ voice_clone_outcome: { status: 'skipped_no_dialogue', cause } }),
59
+ ).toBe(caption);
60
+ });
61
+
62
+ it('⛔ KNOWN-BAD (Web-App 2026-11-26): a gate-refused clone never reads as "no dialogue"', () => {
63
+ const caption = voiceCloneCaption({
64
+ voice_clone_outcome: {
65
+ status: 'skipped_no_dialogue',
66
+ cause: 'speech_unverified',
67
+ reason: 'a voice clone was REFUSED for this character by the speech-grounding gate',
68
+ },
69
+ });
70
+ expect(caption).not.toContain('no dialogue');
71
+ });
72
+
73
+ it('every cause the type names has a caption, and an unknown one falls back', () => {
74
+ expect(Object.keys(VOICE_CLONE_SKIP_CAPTIONS).sort()).toEqual(
75
+ [
76
+ 'audio_unusable',
77
+ 'lines_too_short',
78
+ 'lines_unreadable',
79
+ 'lines_unusable',
80
+ 'no_character',
81
+ 'no_lines_matched',
82
+ 'no_speech_matched',
83
+ 'speech_untimed',
84
+ 'speech_unverified',
85
+ ],
86
+ );
87
+ expect(
88
+ voiceCloneCaption({
89
+ voice_clone_outcome: {
90
+ status: 'skipped_no_dialogue',
91
+ cause: 'toString' as unknown as 'no_character',
92
+ },
93
+ }),
94
+ ).toBe('voice: stock (no dialogue to clone)');
95
+ });
96
+
41
97
  it('says nothing for a clone, or for a persona without a record', () => {
42
98
  expect(voiceCloneCaption({ voice_clone_outcome: { status: 'cloned' } })).toBeNull();
43
99
  expect(voiceCloneCaption({ voice_clone_outcome: null })).toBeNull();
package/src/api.ts CHANGED
@@ -75,6 +75,8 @@ import { DecisionsApi } from './domains/decisions';
75
75
  import { ProjectsApi } from './domains/projects';
76
76
  import { ReactorApi } from './domains/reactor';
77
77
  import { ShowcaseApi } from './domains/showcase';
78
+ import { RuntimeApi } from './domains/runtime';
79
+ import type { RuntimeEventBatchRequest, RuntimeEventBatchResponse } from './runtimeEvents';
78
80
  import { AdventureDefinitionsApi } from './domains/adventureDefinitions';
79
81
  import { StudioSettingsApi } from './domains/studioSettings';
80
82
  import { UniversesApi } from './domains/universes';
@@ -221,6 +223,28 @@ export interface IngestionJob {
221
223
  * cast read returns is final. See {@link castFramePipelinePending}.
222
224
  */
223
225
  castFramesAt?: string | null;
226
+ /**
227
+ * §Q PERS.108 — the entity-typing tail ran with the presence spine ON, so this
228
+ * job's cast-frame/identity chain was OWED a dispatch
229
+ * (`shared/models.py::IngestionJob.presenceSpineAtIngest`). Informational: read
230
+ * readiness from {@link castFrameChain}, never by re-deriving it from this.
231
+ */
232
+ presenceSpineAtIngest?: boolean;
233
+ /**
234
+ * §Q PERS.125 — the typing tail took its classifier-failure arm (typed
235
+ * nothing); a stalled chain on such a job needs its cast re-typed
236
+ * (`shared/models.py::IngestionJob.entityTypingFailed`).
237
+ */
238
+ entityTypingFailed?: boolean;
239
+ /**
240
+ * §Q PERS.130 — where the cast-frame/identity chain stands, answered by the
241
+ * SERVER at read time with the persona job's own rule (it depends on the
242
+ * deployment's presence-spine switch and the server's clock, neither of which
243
+ * a client can see). Present on `GET /api/v1/ingestion/jobs/{videoId}`
244
+ * ({@link ApiClient.getJob}); absent on list rows and from a backend that
245
+ * predates it. Read it through {@link castFrameChainSettled}.
246
+ */
247
+ castFrameChain?: CastFrameChainState | null;
224
248
  /** Episode sequence number within {@link seriesId}, when applicable. */
225
249
  episodeNumber?: number | null;
226
250
  /** Human-readable episode title within {@link seriesId}, when applicable. */
@@ -252,6 +276,25 @@ export interface IngestionJob {
252
276
  visibility?: ResourceVisibility | null;
253
277
  }
254
278
 
279
+ /**
280
+ * §Q PERS.130 — the cast-frame/identity chain's state as the persona job reads
281
+ * it. Mirrors `shared/ingestion_jobs.py` `CastFrameChainState`:
282
+ * - `settled` — finished, or none will run: picks made now are final and a
283
+ * persona job reads the identity index without waiting;
284
+ * - `in_flight` — a persona job would wait for it, and its identity pass will
285
+ * re-read the cast;
286
+ * - `stalled` — it will not finish on its own; a persona job is refused until
287
+ * the chain is re-run (`POST /api/v1/ingestion/videos/{id}/cii-chain/rerun`).
288
+ */
289
+ export type CastFrameChainState = 'settled' | 'in_flight' | 'stalled';
290
+
291
+ /** Named constants for {@link CastFrameChainState}. */
292
+ export const CAST_FRAME_CHAIN_STATE = {
293
+ SETTLED: 'settled',
294
+ IN_FLIGHT: 'in_flight',
295
+ STALLED: 'stalled',
296
+ } as const satisfies Record<string, CastFrameChainState>;
297
+
255
298
  /**
256
299
  * Named constants for the {@link IngestionJob.status} values. Mirrors the
257
300
  * backend `JobStatus` (`shared/models.py`). Use these instead of bare string
@@ -497,6 +540,10 @@ export function castFramePipelinePending(job: IngestionJob): boolean {
497
540
  return false;
498
541
  }
499
542
  if (job.pegasusEnrichmentFailed) return false;
543
+ // §Q PERS.130 — the server's answer, when it sent one, is THE rule (the
544
+ // persona job's own): frames may still arrive exactly while it is in flight.
545
+ // The derivation below is the fallback for list rows and older backends.
546
+ if (job.castFrameChain) return job.castFrameChain === CAST_FRAME_CHAIN_STATE.IN_FLIGHT;
500
547
  // (2) the dispatch decision has not been taken yet.
501
548
  if (!job.entitiesTypedAt) return true;
502
549
  // (3) nothing was ever enqueued for this job — legacy, or a publish that
@@ -505,6 +552,27 @@ export function castFramePipelinePending(job: IngestionJob): boolean {
505
552
  return !job.castFramesAt || job.castFramesAt < job.castFramesRequestedAt;
506
553
  }
507
554
 
555
+ /**
556
+ * §Q PERS.130 — is the video's cast ready for a person to make picks, by the
557
+ * persona job's OWN rule? True only when the server says the cast-frame/identity
558
+ * chain is `settled` ({@link IngestionJob.castFrameChain}, from
559
+ * {@link ApiClient.getJob}).
560
+ *
561
+ * Use this, not {@link castFramePipelinePending}, to decide when to open cast
562
+ * review: a chain that is still owed reruns the identity pass over the cast, and
563
+ * a persona job started meanwhile waits for it.
564
+ *
565
+ * Takes no clock: the state is computed by the server when the job is read, with
566
+ * the clock and the presence-spine switch the persona job uses; re-read the job
567
+ * to refresh it. `false` when the field is absent (a list row, or a backend
568
+ * older than it): the caller cannot know, so it must not open picks on it. A
569
+ * `stalled` chain is also `false`; check
570
+ * `job.castFrameChain === CAST_FRAME_CHAIN_STATE.STALLED` to offer the re-run.
571
+ */
572
+ export function castFrameChainSettled(job: IngestionJob): boolean {
573
+ return job.castFrameChain === CAST_FRAME_CHAIN_STATE.SETTLED;
574
+ }
575
+
508
576
  export interface ListJobsResponse {
509
577
  traceId: string;
510
578
  results: IngestionJob[];
@@ -2837,6 +2905,16 @@ export interface ShowcaseExperiencesResponse {
2837
2905
  experiences: ShowcaseExperienceCard[];
2838
2906
  }
2839
2907
 
2908
+ /**
2909
+ * Response from `GET /api/v1/showcase/experiences/{definitionId}` (§Q ADV.37) —
2910
+ * ONE published experience, the same card the registry lists. This is how a
2911
+ * viewer reads a definition they did not author.
2912
+ */
2913
+ export interface ShowcaseExperienceResponse {
2914
+ traceId: string;
2915
+ experience: ShowcaseExperienceCard;
2916
+ }
2917
+
2840
2918
  // ===== Adventure definitions (§Q ADV.2/ADV.3/ADV.6 — the authored,
2841
2919
  // reusable, blessable DM-experience configuration; spec
2842
2920
  // `specs/2026-07-12-client-core-adventure-surface.md` D1/D2). Wire mirror of
@@ -3867,12 +3945,40 @@ export type VoiceCloneStatus =
3867
3945
  */
3868
3946
  export type RecloneIneligibleReason = 'voice_lineage_copy';
3869
3947
 
3948
+ /**
3949
+ * §Q PERS.130 — which empty harvest a `skipped_no_dialogue` outcome was.
3950
+ * Mirrors `shared/persona_models.py` `VoiceCloneSkipCause`:
3951
+ * - `no_character` — the persona is bound to no character;
3952
+ * - `speech_unverified` — the speech-grounding gate refused: the character's
3953
+ * speech was not verified as theirs and no person confirmed it by listening;
3954
+ * - `speech_untimed` — their verified speech has no usable time span;
3955
+ * - `lines_unusable` — every line has an unusable time range;
3956
+ * - `lines_too_short` — every line is too short to sample;
3957
+ * - `lines_unreadable` — two reads of the video's lines disagree;
3958
+ * - `audio_unusable` — their lines were cut and no usable audio came out;
3959
+ * - `no_speech_matched` — no speech in the video is matched to anyone yet;
3960
+ * - `no_lines_matched` — others have matched lines, this character has none.
3961
+ */
3962
+ export type VoiceCloneSkipCause =
3963
+ | 'no_character'
3964
+ | 'speech_unverified'
3965
+ | 'speech_untimed'
3966
+ | 'lines_unusable'
3967
+ | 'lines_too_short'
3968
+ | 'lines_unreadable'
3969
+ | 'audio_unusable'
3970
+ | 'no_speech_matched'
3971
+ | 'no_lines_matched';
3972
+
3870
3973
  /** §Q DM.68 — the persona-level clone record (`PersonaConfig.voice_clone_outcome`). */
3871
3974
  export interface VoiceCloneOutcome {
3872
3975
  status: VoiceCloneStatus;
3873
3976
  /** Inworld's own refusal message for `refused`; the skip/crash sentence
3874
3977
  * otherwise. Absent for `cloned`. Capped server-side at 300 characters. */
3875
3978
  reason?: string | null;
3979
+ /** §Q PERS.130 — which empty harvest a `skipped_no_dialogue` was; absent on
3980
+ * every other status and on rows written before the field. */
3981
+ cause?: VoiceCloneSkipCause | null;
3876
3982
  }
3877
3983
 
3878
3984
  export interface PersonaConfig {
@@ -8354,6 +8460,7 @@ export class ApiClient {
8354
8460
  private readonly chat: ChatApi;
8355
8461
  private readonly graph: GraphApi;
8356
8462
  private readonly showcase: ShowcaseApi;
8463
+ private readonly runtime: RuntimeApi;
8357
8464
  private readonly universes: UniversesApi;
8358
8465
  private readonly adventureDefinitions: AdventureDefinitionsApi;
8359
8466
  private readonly studioSettings: StudioSettingsApi;
@@ -8395,6 +8502,7 @@ export class ApiClient {
8395
8502
  this.chat = new ChatApi(this.transport);
8396
8503
  this.graph = new GraphApi(this.transport);
8397
8504
  this.showcase = new ShowcaseApi(this.transport);
8505
+ this.runtime = new RuntimeApi(this.transport);
8398
8506
  this.universes = new UniversesApi(this.transport);
8399
8507
  this.adventureDefinitions = new AdventureDefinitionsApi(this.transport);
8400
8508
  this.studioSettings = new StudioSettingsApi(this.transport);
@@ -10006,6 +10114,7 @@ export class ApiClient {
10006
10114
  status?: 'pending' | 'approved';
10007
10115
  sourceVideoId?: string;
10008
10116
  includeBlessed?: boolean;
10117
+ general?: boolean;
10009
10118
  }): Promise<PersonaListResponse> {
10010
10119
  return this.personas.listPersonas(params);
10011
10120
  }
@@ -10024,6 +10133,19 @@ export class ApiClient {
10024
10133
  return this.personas.listViewerPersonasByVideo(sourceVideoId);
10025
10134
  }
10026
10135
 
10136
+ /**
10137
+ * §Q SHOW.9: the VIEWER roster of GENERAL personas — the ones that name no
10138
+ * video (a site guide an admin made). The caller's own general personas,
10139
+ * plus other owners' general personas this caller may read (blessed and
10140
+ * approved), each shaped exactly like {@link getPersona}'s viewer copy (no
10141
+ * authored prompt). Sends `?general=true&includeBlessed=true`; not paginated
10142
+ * (`next_token` is always null). An older backend answers 400 (unknown
10143
+ * parameter).
10144
+ */
10145
+ async listViewerGeneralPersonas(): Promise<PersonaListResponse> {
10146
+ return this.personas.listViewerGeneralPersonas();
10147
+ }
10148
+
10027
10149
  /**
10028
10150
  * C3a: list the personas auto-generated from a given source video. Thin
10029
10151
  * wrapper over {@link listPersonas} with ``sourceVideoId`` — backs the review
@@ -10212,6 +10334,12 @@ export class ApiClient {
10212
10334
  * out — for a caller whose job output IS a whole roster (the workflow runner's
10213
10335
  * batch step). Omitted / false => the dedupe applies.
10214
10336
  *
10337
+ * Characters an approved story arc invents are cast members too: each is a
10338
+ * graph Entity with an `arcent-` id, `getCast` lists it, and the server builds
10339
+ * a persona for each one that has none by itself after the approval applies
10340
+ * (the cast-growth backfill). To build them on demand instead, pass their ids
10341
+ * in ``opts.entityIds``. There is no separate call for invented cast.
10342
+ *
10215
10343
  * @deprecated Facade delegation (§A9.2/A9.4) — implementation now lives on
10216
10344
  * {@link PersonasApi.generatePersonasForVideo} in `./domains/personas.ts`; prefer the
10217
10345
  * domain module directly in new client-core internal code. It is NOT
@@ -13290,6 +13418,34 @@ export class ApiClient {
13290
13418
  return this.showcase.listShowcaseExperiences(options);
13291
13419
  }
13292
13420
 
13421
+ /**
13422
+ * Read ONE published (BLESSED) experience as a viewer (§Q ADV.37) —
13423
+ * `GET /api/v1/showcase/experiences/{definitionId}`. 404 when the definition
13424
+ * is not BLESSED. See {@link ShowcaseApi.getShowcaseExperience}.
13425
+ * Additive — never remove/rename.
13426
+ */
13427
+ async getShowcaseExperience(
13428
+ definitionId: string,
13429
+ options: { signal?: AbortSignal } = {},
13430
+ ): Promise<ShowcaseExperienceResponse> {
13431
+ return this.showcase.getShowcaseExperience(definitionId, options);
13432
+ }
13433
+
13434
+ /**
13435
+ * §Q RUNTIME.3 — report a batch of external-runtime facts (zone reached,
13436
+ * object found, world predicate set, map area unlocked) into a running
13437
+ * adventure session the caller owns. `POST /api/v1/runtime/sessions/{id}/events`;
13438
+ * see {@link RuntimeApi.submitRuntimeEvents} for the status contract. The
13439
+ * WebSocket twin is {@link ChatWebSocket.sendRuntimeEvent}. Additive.
13440
+ */
13441
+ async submitRuntimeEvents(
13442
+ sessionId: string,
13443
+ request: RuntimeEventBatchRequest,
13444
+ options: { signal?: AbortSignal } = {},
13445
+ ): Promise<RuntimeEventBatchResponse> {
13446
+ return this.runtime.submitRuntimeEvents(sessionId, request, options);
13447
+ }
13448
+
13293
13449
  // AdventureDefinition control plane (§Q ADV.2/ADV.3/ADV.6 — spec
13294
13450
  // `specs/2026-07-12-client-core-adventure-surface.md` D1/D2). Facade
13295
13451
  // delegations to `./domains/adventureDefinitions.ts` (same additive facade
@@ -108,7 +108,14 @@ export class AdventureDefinitionsApi {
108
108
  );
109
109
  }
110
110
 
111
- /** Fetch one definition; 404 when missing or not owned. */
111
+ /**
112
+ * Fetch one definition for AUTHORING; 404 when missing or not owned — a
113
+ * BLESSED definition included. This read carries the owner's authoring
114
+ * internals (`dmPromptOverrides`, `readiness`, curation deltas), which
115
+ * blessing does not publish. A viewer reads a published definition with
116
+ * `ShowcaseApi.getShowcaseExperience(definitionId)` (§Q ADV.37) and plays it
117
+ * with `startAdventureFromDefinition`.
118
+ */
112
119
  async getDefinition(
113
120
  definitionId: string,
114
121
  options: { signal?: AbortSignal } = {},
@@ -164,9 +171,12 @@ export class AdventureDefinitionsApi {
164
171
 
165
172
  /**
166
173
  * Presigned cover render URL (§Q ADV.11 — B-8 ledger #11: the charter
167
- * masthead + the Showcase card glass). `GET /{id}/cover`. Visibility ==
168
- * the definition read authority (owner any status; non-owner only when
169
- * BLESSED). `coverImageUrl` is short-lived — re-fetch, don't persist; it
174
+ * masthead + the Showcase card glass). `GET /{id}/cover`. Readable by the
175
+ * owner at any status and by any other caller only while the definition is
176
+ * BLESSED — wider than {@link getDefinition}, which stays owner-only (a
177
+ * viewer reads the published definition with
178
+ * `ShowcaseApi.getShowcaseExperience`, §Q ADV.37). `coverImageUrl` is
179
+ * short-lived — re-fetch, don't persist; it
170
180
  * is `null` when the cover is unset or the referenced library image is
171
181
  * gone/incomplete (render degrades, never errors).
172
182
  * Additive — never remove/rename.
@@ -213,6 +213,7 @@ export class PersonasApi {
213
213
  status?: 'pending' | 'approved';
214
214
  sourceVideoId?: string;
215
215
  includeBlessed?: boolean;
216
+ general?: boolean;
216
217
  }): Promise<PersonaListResponse> {
217
218
  const searchParams = new URLSearchParams();
218
219
  if (params?.limit) searchParams.append('limit', params.limit.toString());
@@ -221,6 +222,7 @@ export class PersonasApi {
221
222
  // Wire param is snake_case (matches the backend Query alias).
222
223
  if (params?.sourceVideoId) searchParams.append('source_video_id', params.sourceVideoId);
223
224
  if (params?.includeBlessed) searchParams.append('includeBlessed', 'true');
225
+ if (params?.general) searchParams.append('general', 'true');
224
226
 
225
227
  const query = searchParams.toString();
226
228
  const endpoint = `/api/v1/personas${query ? `?${query}` : ''}`;
@@ -238,6 +240,11 @@ export class PersonasApi {
238
240
  return this.listPersonas({ sourceVideoId, includeBlessed: true });
239
241
  }
240
242
 
243
+ /** See {@link ApiClient.listViewerGeneralPersonas}. */
244
+ async listViewerGeneralPersonas(): Promise<PersonaListResponse> {
245
+ return this.listPersonas({ general: true, includeBlessed: true });
246
+ }
247
+
241
248
  /** See {@link ApiClient.getDefaultPersona}. */
242
249
  async getDefaultPersona(): Promise<PersonaConfig | null> {
243
250
  return this.transport.requestJson<PersonaConfig | null>(
@@ -0,0 +1,38 @@
1
+ /**
2
+ * External-runtime event intake domain module (§Q RUNTIME.3).
3
+ *
4
+ * `POST /api/v1/runtime/sessions/{sessionId}/events` — the REST door of the
5
+ * intake. Wire types live in `../runtimeEvents` (re-exported from `index.ts`).
6
+ */
7
+
8
+ import type { Transport } from '../transport';
9
+ import type { RuntimeEventBatchRequest, RuntimeEventBatchResponse } from '../runtimeEvents';
10
+
11
+ /** The external-runtime intake's REST door. */
12
+ export class RuntimeApi {
13
+ constructor(private readonly transport: Transport) {}
14
+
15
+ /**
16
+ * Report a batch of external-runtime facts into a running adventure session
17
+ * the caller owns, applied in order. Answers 200 with one result per event
18
+ * even when an event is refused (`accepted: false` + `rejectedReason`); a
19
+ * thrown `Error` means the batch itself was refused: 404 (intake off, or not
20
+ * the caller's session), 409 (the session was not started from an adventure
21
+ * definition), 422 (malformed, including a `clientToken` named twice).
22
+ */
23
+ async submitRuntimeEvents(
24
+ sessionId: string,
25
+ request: RuntimeEventBatchRequest,
26
+ options: { signal?: AbortSignal } = {},
27
+ ): Promise<RuntimeEventBatchResponse> {
28
+ return this.transport.requestJson<RuntimeEventBatchResponse>(
29
+ this.transport.baseUrl,
30
+ `/api/v1/runtime/sessions/${encodeURIComponent(sessionId)}/events`,
31
+ {
32
+ method: 'POST',
33
+ body: JSON.stringify(request),
34
+ signal: options.signal,
35
+ },
36
+ );
37
+ }
38
+ }
@@ -10,7 +10,7 @@
10
10
  */
11
11
 
12
12
  import type { Transport } from '../transport';
13
- import type { ShowcaseExperiencesResponse } from '../api';
13
+ import type { ShowcaseExperienceResponse, ShowcaseExperiencesResponse } from '../api';
14
14
 
15
15
  /** Showcase blessed-experience registry read. */
16
16
  export class ShowcaseApi {
@@ -32,4 +32,27 @@ export class ShowcaseApi {
32
32
  { signal: options.signal },
33
33
  );
34
34
  }
35
+
36
+ /**
37
+ * Read ONE published experience as a viewer (§Q ADV.37) —
38
+ * `GET /api/v1/showcase/experiences/{definitionId}` →
39
+ * {@link ShowcaseExperienceResponse}. Any signed-in caller may read a
40
+ * BLESSED definition this way, the owner included; it answers 404 for a
41
+ * definition that is not BLESSED (draft, playable, archived, missing or
42
+ * deleted alike). The card carries what a player needs (name, description,
43
+ * cover, DM and party personas, quest count) and never the authoring
44
+ * internals. To play it, pass `definitionId` to
45
+ * `startAdventureFromDefinition`. The authoring read
46
+ * (`getAdventureDefinition`) stays owner-only. Additive — never remove/rename.
47
+ */
48
+ async getShowcaseExperience(
49
+ definitionId: string,
50
+ options: { signal?: AbortSignal } = {},
51
+ ): Promise<ShowcaseExperienceResponse> {
52
+ return this.transport.requestJson<ShowcaseExperienceResponse>(
53
+ this.transport.baseUrl,
54
+ `/api/v1/showcase/experiences/${encodeURIComponent(definitionId)}`,
55
+ { signal: options.signal },
56
+ );
57
+ }
35
58
  }
@@ -42,6 +42,7 @@ import type {
42
42
  ArcGenerationStage,
43
43
  ArcProposalStatus,
44
44
  ArcVariantProgressState,
45
+ CastFrameChainState,
45
46
  CastMembershipAction,
46
47
  CurationAction,
47
48
  CutsceneAudioReason,
@@ -94,6 +95,7 @@ import type {
94
95
  VideoGenJobStatus,
95
96
  VisemeBundleStatus,
96
97
  VisemeRegenStatusValue,
98
+ VoiceCloneSkipCause,
97
99
  VoiceCloneStatus,
98
100
  WorkflowArtifactKind,
99
101
  WorkflowEpochStatus,
@@ -247,6 +249,10 @@ export type Assert_ArtifactStatus = Expect<MutuallyAssignable<ArtifactStatus, Ge
247
249
  export type Generated_ArtifactType = "video" | "image" | "document" | "audio" | "cutscene" | "storyboard";
248
250
  export type Assert_ArtifactType = Expect<MutuallyAssignable<ArtifactType, Generated_ArtifactType>>;
249
251
 
252
+ /** Backend single source: `shared/ingestion_jobs.py::CastFrameChainState`. */
253
+ export type Generated_CastFrameChainState = "settled" | "in_flight" | "stalled";
254
+ export type Assert_CastFrameChainState = Expect<MutuallyAssignable<CastFrameChainState, Generated_CastFrameChainState>>;
255
+
250
256
  /** Backend single source: `shared/cast_curation.py::DirectCastAction`. */
251
257
  export type Generated_CastMembershipAction = "keep" | "remove" | "reset" | "restore";
252
258
  export type Assert_CastMembershipAction = Expect<MutuallyAssignable<CastMembershipAction, Generated_CastMembershipAction>>;
@@ -583,6 +589,10 @@ export type Assert_VisemeRegenStatusValue = Expect<MutuallyAssignable<VisemeRege
583
589
  export type Generated_VisemeSymbol = "rest" | "aei" | "o" | "ee" | "bmp" | "fv" | "l" | "r" | "th" | "qw" | "cdgknstxyz";
584
590
  export type Assert_VisemeSymbol = Expect<MutuallyAssignable<VisemeSymbol, Generated_VisemeSymbol>>;
585
591
 
592
+ /** Backend single source: `shared/persona_models.py::VoiceCloneSkipCause`. */
593
+ export type Generated_VoiceCloneSkipCause = "no_character" | "speech_unverified" | "speech_untimed" | "lines_unusable" | "lines_too_short" | "lines_unreadable" | "audio_unusable" | "no_speech_matched" | "no_lines_matched";
594
+ export type Assert_VoiceCloneSkipCause = Expect<MutuallyAssignable<VoiceCloneSkipCause, Generated_VoiceCloneSkipCause>>;
595
+
586
596
  /** Backend single source: `shared/persona_models.py::VoiceCloneStatus`. */
587
597
  export type Generated_VoiceCloneStatus = "cloned" | "skipped_no_dialogue" | "skipped_insufficient_audio" | "refused" | "failed";
588
598
  export type Assert_VoiceCloneStatus = Expect<MutuallyAssignable<VoiceCloneStatus, Generated_VoiceCloneStatus>>;
package/src/index.ts CHANGED
@@ -26,6 +26,9 @@ export * from './opusTransport';
26
26
  export * from './visemeScheduler';
27
27
  export * from './visemeGeometry';
28
28
  export * from './websocket';
29
+ // §Q RUNTIME.3 — external-runtime event intake types + the scene bridge.
30
+ export * from './runtimeEvents';
31
+ export * from './sceneBridge';
29
32
  export * from './api';
30
33
  // §Q PERS.3 — the face-fallback reason vocabulary + its labels, so a renderer
31
34
  // can say WHY it is painting the generic face instead of degrading silently.
@@ -0,0 +1,127 @@
1
+ /**
2
+ * External-runtime event intake — the client half (§Q RUNTIME.3).
3
+ *
4
+ * An external runtime (whatever renders or simulates a scene outside Seer — a
5
+ * game, an XR app, an installation, a simulator) reports physical/gameplay
6
+ * FACTS into a running adventure session's quest ledger; Seer derives the
7
+ * narrative consequences. Two doors, one server ingress:
8
+ *
9
+ * - REST: `POST /api/v1/runtime/sessions/{sessionId}/events` (batched) —
10
+ * {@link RuntimeEventBatchRequest} → {@link RuntimeEventBatchResponse};
11
+ * - WebSocket: the chat socket's `runtime_event` action (one event per frame) —
12
+ * {@link RuntimeEventActionPayload} → a `runtime_event_ack` frame
13
+ * ({@link RuntimeEventAckFrame}).
14
+ *
15
+ * Mirrors `shared/runtime_events.py`. Seer-native, platform-neutral names; no
16
+ * engine or cross-platform-protocol import, by rule.
17
+ *
18
+ * **The clientToken contract.** Unique per genuine event across the session,
19
+ * stable across retries of that event (e.g. `${runtimeTick}:${ordinal}`). A
20
+ * retry with the same token answers `duplicate: true` and changes nothing; a
21
+ * batch naming one token twice is refused whole (HTTP 422).
22
+ */
23
+
24
+ /** The WebSocket action name. */
25
+ export const RUNTIME_EVENT_ACTION = 'runtime_event' as const;
26
+ /** The WebSocket acknowledgement frame type. */
27
+ export const RUNTIME_EVENT_ACK_FRAME = 'runtime_event_ack' as const;
28
+ /** Most events one REST batch may carry (`RUNTIME_EVENT_BATCH_MAX`). */
29
+ export const RUNTIME_EVENT_BATCH_MAX = 50;
30
+ /** The charset and bound a `clientToken` must satisfy. */
31
+ export const RUNTIME_CLIENT_TOKEN_PATTERN = /^[A-Za-z0-9_.:#-]{1,128}$/;
32
+
33
+ /**
34
+ * The event types the server accepts from an external runtime
35
+ * (`EXTERNAL_RUNTIME_COMMANDABLE_EVENT_TYPES`): facts, never outcomes. Any
36
+ * other type is answered `accepted: false` with a reason.
37
+ */
38
+ export const RUNTIME_COMMANDABLE_EVENT_TYPES = [
39
+ 'REACHED_SCENE',
40
+ 'FOUND_OBJECT',
41
+ 'GAMESTATE_SET',
42
+ 'MAP_AREA_UNLOCKED',
43
+ ] as const;
44
+
45
+ export type RuntimeCommandableEventType = (typeof RUNTIME_COMMANDABLE_EVENT_TYPES)[number];
46
+
47
+ /** One fact the external runtime reports (the quest event vocabulary's camelCase wire). */
48
+ export type RuntimeQuestEvent =
49
+ | { type: 'REACHED_SCENE'; sceneId: string; beatId?: string }
50
+ | { type: 'FOUND_OBJECT'; entityId: string; sceneId?: string }
51
+ | { type: 'GAMESTATE_SET'; key: string; value: string }
52
+ | { type: 'MAP_AREA_UNLOCKED'; locationId: string };
53
+
54
+ /** One event of a submission: its token and its fact. */
55
+ export interface RuntimeEventInput {
56
+ clientToken: string;
57
+ event: RuntimeQuestEvent;
58
+ }
59
+
60
+ /**
61
+ * What the runtime says is physically present in its scene. Authoritative for
62
+ * `FOUND_OBJECT`: a found object must be listed (an empty list means nothing
63
+ * is present). Omit it and the runtime's own report of the pickup stands.
64
+ */
65
+ export interface RuntimePresence {
66
+ presentEntityIds: string[];
67
+ }
68
+
69
+ /** `POST /api/v1/runtime/sessions/{sessionId}/events` body. */
70
+ export interface RuntimeEventBatchRequest {
71
+ events: RuntimeEventInput[];
72
+ presence?: RuntimePresence;
73
+ }
74
+
75
+ /** What the server did with one event. */
76
+ export interface RuntimeEventResult {
77
+ clientToken: string;
78
+ eventType: string | null;
79
+ accepted: boolean;
80
+ /** The event replayed an already-recorded one (same token): nothing changed. */
81
+ duplicate: boolean;
82
+ rejectedReason: string | null;
83
+ transitions: Array<Record<string, unknown>>;
84
+ }
85
+
86
+ /** The REST door's answer: one result per event, in request order. */
87
+ export interface RuntimeEventBatchResponse {
88
+ traceId: string;
89
+ sessionId: string;
90
+ results: RuntimeEventResult[];
91
+ /** The quest ledger's last seq after the batch. */
92
+ lastSeq: number;
93
+ }
94
+
95
+ /** The WebSocket `runtime_event` action (one event per frame). */
96
+ export interface RuntimeEventActionPayload {
97
+ adventureSessionId: string;
98
+ clientToken: string;
99
+ event: RuntimeQuestEvent;
100
+ /** Optional {@link RuntimePresence} for this event. */
101
+ presentEntityIds?: string[];
102
+ }
103
+
104
+ /** The WebSocket door's answer to one `runtime_event` action. */
105
+ export interface RuntimeEventAckFrame {
106
+ type: typeof RUNTIME_EVENT_ACK_FRAME;
107
+ traceId: string;
108
+ sessionId: string;
109
+ result: RuntimeEventResult;
110
+ lastSeq: number;
111
+ }
112
+
113
+ /** Narrow a parsed chat frame to a {@link RuntimeEventAckFrame}. */
114
+ export function isRuntimeEventAck(frame: unknown): frame is RuntimeEventAckFrame {
115
+ if (typeof frame !== 'object' || frame === null) return false;
116
+ const candidate = frame as { type?: unknown; result?: unknown };
117
+ return (
118
+ candidate.type === RUNTIME_EVENT_ACK_FRAME &&
119
+ typeof candidate.result === 'object' &&
120
+ candidate.result !== null
121
+ );
122
+ }
123
+
124
+ /** Whether `token` satisfies the server's `clientToken` charset and bound. */
125
+ export function isValidRuntimeClientToken(token: unknown): token is string {
126
+ return typeof token === 'string' && RUNTIME_CLIENT_TOKEN_PATTERN.test(token);
127
+ }