@convai/web-sdk 1.8.0-beta.7 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +44 -194
  2. package/dist/core/ConvaiClient.d.ts +1 -190
  3. package/dist/core/ConvaiClient.d.ts.map +1 -1
  4. package/dist/core/ConvaiClient.js +286 -1306
  5. package/dist/core/ConvaiClient.js.map +1 -1
  6. package/dist/core/MessageHandler.d.ts +1 -19
  7. package/dist/core/MessageHandler.d.ts.map +1 -1
  8. package/dist/core/MessageHandler.js +27 -378
  9. package/dist/core/MessageHandler.js.map +1 -1
  10. package/dist/core/connectRequest.d.ts +4 -17
  11. package/dist/core/connectRequest.d.ts.map +1 -1
  12. package/dist/core/connectRequest.js +17 -28
  13. package/dist/core/connectRequest.js.map +1 -1
  14. package/dist/core/index.d.ts +1 -6
  15. package/dist/core/index.d.ts.map +1 -1
  16. package/dist/core/index.js +1 -7
  17. package/dist/core/index.js.map +1 -1
  18. package/dist/core/logicalTurn.d.ts +6 -4
  19. package/dist/core/logicalTurn.d.ts.map +1 -1
  20. package/dist/core/logicalTurn.js +4 -29
  21. package/dist/core/logicalTurn.js.map +1 -1
  22. package/dist/core/modelOutput.d.ts.map +1 -1
  23. package/dist/core/modelOutput.js +2 -2
  24. package/dist/core/modelOutput.js.map +1 -1
  25. package/dist/core/types.d.ts +22 -860
  26. package/dist/core/types.d.ts.map +1 -1
  27. package/dist/core/types.js.map +1 -1
  28. package/dist/embed/chat-embed-v1.js +9 -10
  29. package/dist/embed/chat-embed-v1.js.map +4 -4
  30. package/dist/react/components/ConvaiWidget.d.ts.map +1 -1
  31. package/dist/react/components/ConvaiWidget.js +1 -6
  32. package/dist/react/components/ConvaiWidget.js.map +1 -1
  33. package/dist/react/components/rtc-widget/components/AudioVisualizer.d.ts.map +1 -1
  34. package/dist/react/components/rtc-widget/components/AudioVisualizer.js +1 -28
  35. package/dist/react/components/rtc-widget/components/AudioVisualizer.js.map +1 -1
  36. package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -1
  37. package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +44 -39
  38. package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +1 -1
  39. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts.map +1 -1
  40. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +49 -93
  41. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js.map +1 -1
  42. package/dist/react/hooks/useConvaiClient.d.ts.map +1 -1
  43. package/dist/react/hooks/useConvaiClient.js +2 -17
  44. package/dist/react/hooks/useConvaiClient.js.map +1 -1
  45. package/dist/react/index.d.ts +1 -1
  46. package/dist/react/index.d.ts.map +1 -1
  47. package/dist/react/index.js +1 -1
  48. package/dist/react/index.js.map +1 -1
  49. package/dist/vanilla/AudioRenderer.d.ts +1 -3
  50. package/dist/vanilla/AudioRenderer.d.ts.map +1 -1
  51. package/dist/vanilla/AudioRenderer.js +2 -8
  52. package/dist/vanilla/AudioRenderer.js.map +1 -1
  53. package/dist/vanilla/ConvaiWidget.d.ts.map +1 -1
  54. package/dist/vanilla/ConvaiWidget.js +300 -994
  55. package/dist/vanilla/ConvaiWidget.js.map +1 -1
  56. package/dist/vanilla/WidgetEventSubscriptions.d.ts +1 -1
  57. package/dist/vanilla/WidgetEventSubscriptions.d.ts.map +1 -1
  58. package/dist/vanilla/WidgetEventSubscriptions.js +0 -5
  59. package/dist/vanilla/WidgetEventSubscriptions.js.map +1 -1
  60. package/dist/vanilla/icons.d.ts.map +1 -1
  61. package/dist/vanilla/icons.js +15 -62
  62. package/dist/vanilla/icons.js.map +1 -1
  63. package/dist/vanilla/index.d.ts +2 -4
  64. package/dist/vanilla/index.d.ts.map +1 -1
  65. package/dist/vanilla/index.js +1 -3
  66. package/dist/vanilla/index.js.map +1 -1
  67. package/dist/vanilla/styles.d.ts +1 -18
  68. package/dist/vanilla/styles.d.ts.map +1 -1
  69. package/dist/vanilla/styles.js +29 -129
  70. package/dist/vanilla/styles.js.map +1 -1
  71. package/dist/vanilla/types.d.ts +0 -74
  72. package/dist/vanilla/types.d.ts.map +1 -1
  73. package/dist/vanilla/types.js.map +1 -1
  74. package/dist/version.d.ts +1 -1
  75. package/dist/version.d.ts.map +1 -1
  76. package/dist/version.js +1 -1
  77. package/dist/version.js.map +1 -1
  78. package/package.json +8 -13
  79. package/dist/core/CharacterRoster.d.ts +0 -84
  80. package/dist/core/CharacterRoster.d.ts.map +0 -1
  81. package/dist/core/CharacterRoster.js +0 -348
  82. package/dist/core/CharacterRoster.js.map +0 -1
  83. package/dist/core/CharacterVersionManager.d.ts +0 -100
  84. package/dist/core/CharacterVersionManager.d.ts.map +0 -1
  85. package/dist/core/CharacterVersionManager.js +0 -227
  86. package/dist/core/CharacterVersionManager.js.map +0 -1
  87. package/dist/core/ConvaiRoomError.d.ts +0 -48
  88. package/dist/core/ConvaiRoomError.d.ts.map +0 -1
  89. package/dist/core/ConvaiRoomError.js +0 -111
  90. package/dist/core/ConvaiRoomError.js.map +0 -1
  91. package/dist/core/SSESession.d.ts +0 -59
  92. package/dist/core/SSESession.d.ts.map +0 -1
  93. package/dist/core/SSESession.js +0 -289
  94. package/dist/core/SSESession.js.map +0 -1
  95. package/dist/core/characterReference.d.ts +0 -40
  96. package/dist/core/characterReference.d.ts.map +0 -1
  97. package/dist/core/characterReference.js +0 -72
  98. package/dist/core/characterReference.js.map +0 -1
  99. package/dist/core/rosterRequest.d.ts +0 -57
  100. package/dist/core/rosterRequest.d.ts.map +0 -1
  101. package/dist/core/rosterRequest.js +0 -210
  102. package/dist/core/rosterRequest.js.map +0 -1
  103. package/dist/utils/inlineMarkdown.d.ts +0 -38
  104. package/dist/utils/inlineMarkdown.d.ts.map +0 -1
  105. package/dist/utils/inlineMarkdown.js +0 -106
  106. package/dist/utils/inlineMarkdown.js.map +0 -1
@@ -1,210 +0,0 @@
1
- import { isCharacterUuid } from "./characterReference.js";
2
- /**
3
- * Validation and request-body construction for multi-character rooms.
4
- *
5
- * Pure: no transport, no client state. Every rule below runs before a request
6
- * is built, so an illegal topology costs nothing and reports the rule it broke
7
- * rather than a 422 from the runtime.
8
- */
9
- /**
10
- * Server-wide roster cap. Checked client-side only to fail fast with a clear
11
- * message — the server stays authoritative, and a plan may configure a lower
12
- * `max_characters` that surfaces as 403 `MULTI_CHARACTER_ROSTER_LIMIT_EXCEEDED`.
13
- * This is an operational limit, not a protocol maximum, so it must not leak
14
- * into any public type.
15
- */
16
- export const MULTI_CHARACTER_MAX_CHARACTERS = 50;
17
- /** `shared_session_key` and `connect_attempt_id` share one charset. */
18
- const KEY_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;
19
- /** True when this config asks for a multi-character room. */
20
- export function isRosterConfig(config) {
21
- return Array.isArray(config.characters) && config.characters.length > 0;
22
- }
23
- function assertKey(value, field) {
24
- if (value === undefined)
25
- return;
26
- if (!KEY_PATTERN.test(value)) {
27
- throw new Error(`${field} must be 1-128 characters of letters, digits, hyphen or underscore`);
28
- }
29
- }
30
- function nonblank(value) {
31
- return typeof value === "string" && value.trim().length > 0;
32
- }
33
- /**
34
- * Validate a roster create config.
35
- *
36
- * Throws on the first broken rule. Ordered so the most structural problems
37
- * (which topology did you mean?) report before the detail ones.
38
- */
39
- export function validateRosterConfig(config) {
40
- const characters = config.characters ?? [];
41
- if (config.characterId) {
42
- throw new Error("Pass either characterId or characters, not both");
43
- }
44
- if (characters.length === 0) {
45
- throw new Error("characters must contain at least one entry");
46
- }
47
- if (characters.length > MULTI_CHARACTER_MAX_CHARACTERS) {
48
- throw new Error(`characters accepts at most ${MULTI_CHARACTER_MAX_CHARACTERS} entries; ` +
49
- `your plan may allow fewer`);
50
- }
51
- const seenSessions = new Set();
52
- characters.forEach((spec, index) => {
53
- if (!spec || !nonblank(spec.characterId)) {
54
- throw new Error(`characters[${index}] requires a characterId`);
55
- }
56
- // A roster entry is typed as a bare UUID on the runtime. The version
57
- // selectors that single-character `characterId` has accepted since
58
- // 1.8.0-beta.5 are a 422 here, and the failure would otherwise only show
59
- // up as an opaque validation error from the server.
60
- if (!isCharacterUuid(spec.characterId.trim())) {
61
- throw new Error(`characters[${index}].characterId must be a bare character UUID; ` +
62
- `version selectors are not supported inside a roster`);
63
- }
64
- if (spec.characterSessionId !== undefined) {
65
- if (!nonblank(spec.characterSessionId)) {
66
- throw new Error(`characters[${index}].characterSessionId must be nonblank when supplied`);
67
- }
68
- if (seenSessions.has(spec.characterSessionId)) {
69
- throw new Error(`characters[${index}].characterSessionId is repeated; resume ids must be unique within the roster`);
70
- }
71
- seenSessions.add(spec.characterSessionId);
72
- }
73
- });
74
- if (config.characterSessionId) {
75
- throw new Error("characterSessionId is not valid with characters; use characters[].characterSessionId");
76
- }
77
- if (!nonblank(config.endUserId)) {
78
- throw new Error("characters requires a nonblank endUserId");
79
- }
80
- if (config.transport && config.transport !== "livekit") {
81
- throw new Error("Multi-character rooms require the LiveKit transport");
82
- }
83
- if (config.interactionApiUrl) {
84
- throw new Error("Multi-character rooms require the LiveKit transport; interactionApiUrl selects SSE");
85
- }
86
- if (config.characterVersion) {
87
- throw new Error("characterVersion applies to a single character; roster entries take bare UUIDs");
88
- }
89
- assertKey(config.sharedSessionKey, "sharedSessionKey");
90
- assertKey(config.connectAttemptId, "connectAttemptId");
91
- if (config.maxNumParticipants !== undefined &&
92
- (!Number.isInteger(config.maxNumParticipants) ||
93
- config.maxNumParticipants < 1)) {
94
- throw new Error("maxNumParticipants must be a positive integer");
95
- }
96
- }
97
- /**
98
- * Reject a config that negotiates v2 output protocols alongside room options
99
- * the runtime cannot combine them with.
100
- *
101
- * Verified against staging 2026-09-08: `capabilities.actionProtocolVersion: 2`
102
- * or `modelOutputVersion: 2` is answered with 422
103
- * `unsupported_action_protocol_topology` / `unsupported_model_output_topology`
104
- * unless the request uses `mode='create'`, a singular `characterId`, no
105
- * `sharedSessionKey`, and `maxNumParticipants` of 1. Version 1 carries no such
106
- * constraint.
107
- *
108
- * The published contract mentions only the multi-character half of this. The
109
- * `sharedSessionKey` and `maxNumParticipants` constraints bite in
110
- * single-character sessions too, which is why this runs on every connect
111
- * rather than only the roster path.
112
- */
113
- export function validateProtocolTopology(config) {
114
- const negotiatesV2 = config.capabilities?.actionProtocolVersion === 2 ||
115
- config.capabilities?.modelOutputVersion === 2;
116
- if (!negotiatesV2) {
117
- // Tools need v2, so without it they are refused whatever the topology.
118
- if (config.actionConfig?.tools?.length) {
119
- throw new Error("actionConfig.tools requires capabilities.actionProtocolVersion: 2");
120
- }
121
- return;
122
- }
123
- const offenders = [];
124
- if (isRosterConfig(config))
125
- offenders.push("characters");
126
- if (config.sharedSessionKey)
127
- offenders.push("sharedSessionKey");
128
- if (config.maxNumParticipants !== undefined && config.maxNumParticipants !== 1) {
129
- offenders.push("maxNumParticipants greater than 1");
130
- }
131
- if (offenders.length === 0)
132
- return;
133
- throw new Error(`Negotiated v2 output protocols require a single-character room: ` +
134
- `remove ${offenders.join(", ")}, or drop capabilities to version 1. ` +
135
- (offenders.includes("characters")
136
- ? "Multi-character rooms cannot use action protocol v2, and therefore cannot use client tools. "
137
- : "") +
138
- "The runtime rejects this combination with unsupported_action_protocol_topology.");
139
- }
140
- /** Validate join options. */
141
- export function validateJoinOptions(options) {
142
- const locators = Number(nonblank(options?.roomSessionId)) +
143
- Number(nonblank(options?.sharedSessionKey));
144
- if (locators !== 1) {
145
- throw new Error("joinRoom requires exactly one of roomSessionId or sharedSessionKey");
146
- }
147
- if (!nonblank(options.endUserId)) {
148
- throw new Error("joinRoom requires a nonblank endUserId");
149
- }
150
- // Guard the shape even though the type forbids it: a plain-JS caller, or a
151
- // config object spread in wholesale, would otherwise send topology that the
152
- // runtime rejects with a less specific message.
153
- const stray = options;
154
- if (stray.characters || stray.characterId || stray.characterSessionId) {
155
- throw new Error("joinRoom must not carry character topology; the room's roster is server-owned");
156
- }
157
- assertKey(options.sharedSessionKey, "sharedSessionKey");
158
- assertKey(options.connectAttemptId, "connectAttemptId");
159
- }
160
- /**
161
- * The roster half of a create request. Merged into the existing single-character
162
- * body by the caller, so every current option (blendshape, TTS/STT, dynamic
163
- * info, action, scene, VAD, vision) continues to apply to every member.
164
- */
165
- export function buildRosterConnectFields(config) {
166
- const characters = (config.characters ?? []).map((spec) => ({
167
- character_id: spec.characterId.trim(),
168
- ...(spec.characterSessionId
169
- ? { character_session_id: spec.characterSessionId }
170
- : {}),
171
- }));
172
- return {
173
- // Both carry server defaults that already match, but a roster room is
174
- // rejected outright without them, so they are stated rather than assumed.
175
- mode: "create",
176
- spawn_agent: true,
177
- characters,
178
- ...(config.sharedSessionKey
179
- ? { shared_session_key: config.sharedSessionKey }
180
- : {}),
181
- ...(config.connectAttemptId
182
- ? { connect_attempt_id: config.connectAttemptId }
183
- : {}),
184
- ...(config.maxNumParticipants !== undefined
185
- ? { max_num_participants: config.maxNumParticipants }
186
- : {}),
187
- };
188
- }
189
- /**
190
- * The complete join request body. A join carries a locator and the human, and
191
- * nothing else — the roster is loaded from persisted room state, and resending
192
- * topology is rejected.
193
- */
194
- export function buildJoinRequestBody(options) {
195
- return {
196
- mode: "join",
197
- transport: "livekit",
198
- ...(options.roomSessionId
199
- ? { room_session_id: options.roomSessionId }
200
- : { shared_session_key: options.sharedSessionKey }),
201
- end_user_id: options.endUserId,
202
- ...(options.endUserMetadata
203
- ? { end_user_metadata: options.endUserMetadata }
204
- : {}),
205
- ...(options.connectAttemptId
206
- ? { connect_attempt_id: options.connectAttemptId }
207
- : {}),
208
- };
209
- }
210
- //# sourceMappingURL=rosterRequest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rosterRequest.js","sourceRoot":"","sources":["../../src/core/rosterRequest.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAC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CAAC,CAAC,EAAE,iBAAiB,EAAE,OAAO,CAAC,eAAe,EAAE;YAChD,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,CAAC,gBAAgB;YAC1B,CAAC,CAAC,EAAE,kBAAkB,EAAE,OAAO,CAAC,gBAAgB,EAAE;YAClD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ConvaiCharacterSpec,\n ConvaiConfig,\n JoinRoomOptions,\n} from \"./types\";\nimport { isCharacterUuid } from \"./characterReference\";\n\n/**\n * Validation and request-body construction for multi-character rooms.\n *\n * Pure: no transport, no client state. Every rule below runs before a request\n * is built, so an illegal topology costs nothing and reports the rule it broke\n * rather than a 422 from the runtime.\n */\n\n/**\n * Server-wide roster cap. Checked client-side only to fail fast with a clear\n * message — the server stays authoritative, and a plan may configure a lower\n * `max_characters` that surfaces as 403 `MULTI_CHARACTER_ROSTER_LIMIT_EXCEEDED`.\n * This is an operational limit, not a protocol maximum, so it must not leak\n * into any public type.\n */\nexport const MULTI_CHARACTER_MAX_CHARACTERS = 50;\n\n/** `shared_session_key` and `connect_attempt_id` share one charset. */\nconst KEY_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;\n\n/** True when this config asks for a multi-character room. */\nexport function isRosterConfig(\n config: Pick<ConvaiConfig, \"characters\">,\n): boolean {\n return Array.isArray(config.characters) && config.characters.length > 0;\n}\n\nfunction assertKey(value: string | undefined, field: string): void {\n if (value === undefined) return;\n if (!KEY_PATTERN.test(value)) {\n throw new Error(\n `${field} must be 1-128 characters of letters, digits, hyphen or underscore`,\n );\n }\n}\n\nfunction nonblank(value: string | undefined | null): boolean {\n return typeof value === \"string\" && value.trim().length > 0;\n}\n\n/**\n * Validate a roster create config.\n *\n * Throws on the first broken rule. Ordered so the most structural problems\n * (which topology did you mean?) report before the detail ones.\n */\nexport function validateRosterConfig(config: ConvaiConfig): void {\n const characters = config.characters ?? [];\n\n if (config.characterId) {\n throw new Error(\"Pass either characterId or characters, not both\");\n }\n if (characters.length === 0) {\n throw new Error(\"characters must contain at least one entry\");\n }\n if (characters.length > MULTI_CHARACTER_MAX_CHARACTERS) {\n throw new Error(\n `characters accepts at most ${MULTI_CHARACTER_MAX_CHARACTERS} entries; ` +\n `your plan may allow fewer`,\n );\n }\n\n const seenSessions = new Set<string>();\n characters.forEach((spec, index) => {\n if (!spec || !nonblank(spec.characterId)) {\n throw new Error(\n `characters[${index}] requires a characterId`,\n );\n }\n // A roster entry is typed as a bare UUID on the runtime. The version\n // selectors that single-character `characterId` has accepted since\n // 1.8.0-beta.5 are a 422 here, and the failure would otherwise only show\n // up as an opaque validation error from the server.\n if (!isCharacterUuid(spec.characterId.trim())) {\n throw new Error(\n `characters[${index}].characterId must be a bare character UUID; ` +\n `version selectors are not supported inside a roster`,\n );\n }\n if (spec.characterSessionId !== undefined) {\n if (!nonblank(spec.characterSessionId)) {\n throw new Error(\n `characters[${index}].characterSessionId must be nonblank when supplied`,\n );\n }\n if (seenSessions.has(spec.characterSessionId)) {\n throw new Error(\n `characters[${index}].characterSessionId is repeated; resume ids must be unique within the roster`,\n );\n }\n seenSessions.add(spec.characterSessionId);\n }\n });\n\n if (config.characterSessionId) {\n throw new Error(\n \"characterSessionId is not valid with characters; use characters[].characterSessionId\",\n );\n }\n if (!nonblank(config.endUserId)) {\n throw new Error(\"characters requires a nonblank endUserId\");\n }\n if (config.transport && config.transport !== \"livekit\") {\n throw new Error(\"Multi-character rooms require the LiveKit transport\");\n }\n if (config.interactionApiUrl) {\n throw new Error(\n \"Multi-character rooms require the LiveKit transport; interactionApiUrl selects SSE\",\n );\n }\n if (config.characterVersion) {\n throw new Error(\n \"characterVersion applies to a single character; roster entries take bare UUIDs\",\n );\n }\n assertKey(config.sharedSessionKey, \"sharedSessionKey\");\n assertKey(config.connectAttemptId, \"connectAttemptId\");\n if (\n config.maxNumParticipants !== undefined &&\n (!Number.isInteger(config.maxNumParticipants) ||\n config.maxNumParticipants < 1)\n ) {\n throw new Error(\"maxNumParticipants must be a positive integer\");\n }\n}\n\n/**\n * Reject a config that negotiates v2 output protocols alongside room options\n * the runtime cannot combine them with.\n *\n * Verified against staging 2026-09-08: `capabilities.actionProtocolVersion: 2`\n * or `modelOutputVersion: 2` is answered with 422\n * `unsupported_action_protocol_topology` / `unsupported_model_output_topology`\n * unless the request uses `mode='create'`, a singular `characterId`, no\n * `sharedSessionKey`, and `maxNumParticipants` of 1. Version 1 carries no such\n * constraint.\n *\n * The published contract mentions only the multi-character half of this. The\n * `sharedSessionKey` and `maxNumParticipants` constraints bite in\n * single-character sessions too, which is why this runs on every connect\n * rather than only the roster path.\n */\nexport function validateProtocolTopology(config: ConvaiConfig): void {\n const negotiatesV2 =\n config.capabilities?.actionProtocolVersion === 2 ||\n config.capabilities?.modelOutputVersion === 2;\n\n if (!negotiatesV2) {\n // Tools need v2, so without it they are refused whatever the topology.\n if (config.actionConfig?.tools?.length) {\n throw new Error(\n \"actionConfig.tools requires capabilities.actionProtocolVersion: 2\",\n );\n }\n return;\n }\n\n const offenders: string[] = [];\n if (isRosterConfig(config)) offenders.push(\"characters\");\n if (config.sharedSessionKey) offenders.push(\"sharedSessionKey\");\n if (config.maxNumParticipants !== undefined && config.maxNumParticipants !== 1) {\n offenders.push(\"maxNumParticipants greater than 1\");\n }\n if (offenders.length === 0) return;\n\n throw new Error(\n `Negotiated v2 output protocols require a single-character room: ` +\n `remove ${offenders.join(\", \")}, or drop capabilities to version 1. ` +\n (offenders.includes(\"characters\")\n ? \"Multi-character rooms cannot use action protocol v2, and therefore cannot use client tools. \"\n : \"\") +\n \"The runtime rejects this combination with unsupported_action_protocol_topology.\",\n );\n}\n\n/** Validate join options. */\nexport function validateJoinOptions(options: JoinRoomOptions): void {\n const locators =\n Number(nonblank(options?.roomSessionId)) +\n Number(nonblank(options?.sharedSessionKey));\n if (locators !== 1) {\n throw new Error(\n \"joinRoom requires exactly one of roomSessionId or sharedSessionKey\",\n );\n }\n if (!nonblank(options.endUserId)) {\n throw new Error(\"joinRoom requires a nonblank endUserId\");\n }\n // Guard the shape even though the type forbids it: a plain-JS caller, or a\n // config object spread in wholesale, would otherwise send topology that the\n // runtime rejects with a less specific message.\n const stray = options as unknown as Record<string, unknown>;\n if (stray.characters || stray.characterId || stray.characterSessionId) {\n throw new Error(\n \"joinRoom must not carry character topology; the room's roster is server-owned\",\n );\n }\n assertKey(options.sharedSessionKey, \"sharedSessionKey\");\n assertKey(options.connectAttemptId, \"connectAttemptId\");\n}\n\n/**\n * The roster half of a create request. Merged into the existing single-character\n * body by the caller, so every current option (blendshape, TTS/STT, dynamic\n * info, action, scene, VAD, vision) continues to apply to every member.\n */\nexport function buildRosterConnectFields(\n config: ConvaiConfig,\n): Record<string, unknown> {\n const characters = (config.characters ?? []).map(\n (spec: ConvaiCharacterSpec) => ({\n character_id: spec.characterId.trim(),\n ...(spec.characterSessionId\n ? { character_session_id: spec.characterSessionId }\n : {}),\n }),\n );\n\n return {\n // Both carry server defaults that already match, but a roster room is\n // rejected outright without them, so they are stated rather than assumed.\n mode: \"create\",\n spawn_agent: true,\n characters,\n ...(config.sharedSessionKey\n ? { shared_session_key: config.sharedSessionKey }\n : {}),\n ...(config.connectAttemptId\n ? { connect_attempt_id: config.connectAttemptId }\n : {}),\n ...(config.maxNumParticipants !== undefined\n ? { max_num_participants: config.maxNumParticipants }\n : {}),\n };\n}\n\n/**\n * The complete join request body. A join carries a locator and the human, and\n * nothing else — the roster is loaded from persisted room state, and resending\n * topology is rejected.\n */\nexport function buildJoinRequestBody(\n options: JoinRoomOptions,\n): Record<string, unknown> {\n return {\n mode: \"join\",\n transport: \"livekit\",\n ...(options.roomSessionId\n ? { room_session_id: options.roomSessionId }\n : { shared_session_key: options.sharedSessionKey }),\n end_user_id: options.endUserId,\n ...(options.endUserMetadata\n ? { end_user_metadata: options.endUserMetadata }\n : {}),\n ...(options.connectAttemptId\n ? { connect_attempt_id: options.connectAttemptId }\n : {}),\n };\n}\n"]}
@@ -1,38 +0,0 @@
1
- /**
2
- * Inline markdown tokenizer shared by the React and vanilla chat bubbles.
3
- *
4
- * Core-service can hand the client bot text with links preserved
5
- * (`preserve_links_in_output` on /connect): `[text](url)`, `![alt](url)` and
6
- * bare `http(s)://` URLs arrive verbatim, everything else is still flattened
7
- * server-side. This turns one line of that text into nodes a renderer can
8
- * map onto DOM or JSX.
9
- *
10
- * Only `http:` and `https:` become links or images. Anything else — including
11
- * `javascript:` — stays literal text, regardless of what the server sent.
12
- * A link whose closing paren has not streamed in yet is left as text too, so
13
- * a bubble does not flicker between shapes mid-response.
14
- */
15
- export type MediaKind = "image" | "video";
16
- export type InlineNode = {
17
- kind: "text";
18
- text: string;
19
- } | {
20
- kind: "strong";
21
- text: string;
22
- } | {
23
- kind: "em";
24
- text: string;
25
- } | {
26
- kind: "link";
27
- href: string;
28
- label: string;
29
- media: MediaKind | null;
30
- } | {
31
- kind: "image";
32
- src: string;
33
- alt: string;
34
- };
35
- /** Classify a URL by its path extension; null for anything not previewable. */
36
- export declare function mediaKindForUrl(url: string): MediaKind | null;
37
- export declare function parseInlineMarkdown(line: string): InlineNode[];
38
- //# sourceMappingURL=inlineMarkdown.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inlineMarkdown.d.ts","sourceRoot":"","sources":["../../src/utils/inlineMarkdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAA;CAAE,GACtE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAKhD,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAU7D;AAqCD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,CAkC9D"}
@@ -1,106 +0,0 @@
1
- /**
2
- * Inline markdown tokenizer shared by the React and vanilla chat bubbles.
3
- *
4
- * Core-service can hand the client bot text with links preserved
5
- * (`preserve_links_in_output` on /connect): `[text](url)`, `![alt](url)` and
6
- * bare `http(s)://` URLs arrive verbatim, everything else is still flattened
7
- * server-side. This turns one line of that text into nodes a renderer can
8
- * map onto DOM or JSX.
9
- *
10
- * Only `http:` and `https:` become links or images. Anything else — including
11
- * `javascript:` — stays literal text, regardless of what the server sent.
12
- * A link whose closing paren has not streamed in yet is left as text too, so
13
- * a bubble does not flicker between shapes mid-response.
14
- */
15
- const IMAGE_EXT = /\.(png|jpe?g|gif|webp|avif)$/i;
16
- const VIDEO_EXT = /\.(mp4|webm|mov|ogg)$/i;
17
- /** Classify a URL by its path extension; null for anything not previewable. */
18
- export function mediaKindForUrl(url) {
19
- let pathname;
20
- try {
21
- pathname = new URL(url).pathname;
22
- }
23
- catch {
24
- return null;
25
- }
26
- if (IMAGE_EXT.test(pathname))
27
- return "image";
28
- if (VIDEO_EXT.test(pathname))
29
- return "video";
30
- return null;
31
- }
32
- // Alternatives are tried in this order at every position:
33
- // 1. ![alt](url) / [text](url) with an http(s) URL
34
- // 2. bare http(s) URL, unless it is the target of a link still streaming in
35
- // 3. **bold** / __bold__ / *em* / _em_
36
- // Matching URLs before emphasis is what keeps `_` inside a URL literal.
37
- const TOKEN = /(!?)\[([^\]]*)\]\((https?:\/\/[^\s)]+)\)|(?<!\]\()(https?:\/\/[^\s<>"'`]+)|(\*\*|__)(.*?)\5|\*([^*]+)\*|_([^_]+)_/g;
38
- const TRAILING_PUNCTUATION = ".,;:!?'\"";
39
- /**
40
- * Sentence punctuation after a bare URL belongs to the sentence, and an
41
- * unbalanced `)` belongs to the surrounding parenthetical.
42
- */
43
- function splitTrailingPunctuation(raw) {
44
- let url = raw;
45
- while (url.length > 0) {
46
- const last = url[url.length - 1];
47
- if (TRAILING_PUNCTUATION.includes(last)) {
48
- url = url.slice(0, -1);
49
- continue;
50
- }
51
- if (last === ")") {
52
- const opens = (url.match(/\(/g) ?? []).length;
53
- const closes = (url.match(/\)/g) ?? []).length;
54
- if (closes > opens) {
55
- url = url.slice(0, -1);
56
- continue;
57
- }
58
- }
59
- break;
60
- }
61
- return [url, raw.slice(url.length)];
62
- }
63
- export function parseInlineMarkdown(line) {
64
- const nodes = [];
65
- const pushText = (text) => {
66
- if (!text)
67
- return;
68
- const last = nodes[nodes.length - 1];
69
- if (last?.kind === "text")
70
- last.text += text;
71
- else
72
- nodes.push({ kind: "text", text });
73
- };
74
- let lastIndex = 0;
75
- TOKEN.lastIndex = 0;
76
- let match;
77
- while ((match = TOKEN.exec(line)) !== null) {
78
- pushText(line.slice(lastIndex, match.index));
79
- const [, bang, label, linkUrl, bareUrl, , boldText, starEm, underscoreEm] = match;
80
- if (linkUrl !== undefined) {
81
- if (bang)
82
- nodes.push({ kind: "image", src: linkUrl, alt: label });
83
- else
84
- nodes.push({ kind: "link", href: linkUrl, label, media: mediaKindForUrl(linkUrl) });
85
- }
86
- else if (bareUrl !== undefined) {
87
- const [href, rest] = splitTrailingPunctuation(bareUrl);
88
- if (href)
89
- nodes.push({ kind: "link", href, label: href, media: mediaKindForUrl(href) });
90
- pushText(rest);
91
- }
92
- else if (boldText !== undefined) {
93
- nodes.push({ kind: "strong", text: boldText });
94
- }
95
- else if (starEm !== undefined) {
96
- nodes.push({ kind: "em", text: starEm });
97
- }
98
- else if (underscoreEm !== undefined) {
99
- nodes.push({ kind: "em", text: underscoreEm });
100
- }
101
- lastIndex = match.index + match[0].length;
102
- }
103
- pushText(line.slice(lastIndex));
104
- return nodes;
105
- }
106
- //# sourceMappingURL=inlineMarkdown.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inlineMarkdown.js","sourceRoot":"","sources":["../../src/utils/inlineMarkdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAWH,MAAM,SAAS,GAAG,+BAA+B,CAAC;AAClD,MAAM,SAAS,GAAG,wBAAwB,CAAC;AAE3C,+EAA+E;AAC/E,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,IAAI,QAAgB,CAAC;IACrB,IAAI,CAAC;QACH,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,OAAO,CAAC;IAC7C,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC;QAAE,OAAO,OAAO,CAAC;IAC7C,OAAO,IAAI,CAAC;AACd,CAAC;AAED,0DAA0D;AAC1D,qDAAqD;AACrD,8EAA8E;AAC9E,yCAAyC;AACzC,wEAAwE;AACxE,MAAM,KAAK,GACT,oHAAoH,CAAC;AAEvH,MAAM,oBAAoB,GAAG,WAAW,CAAC;AAEzC;;;GAGG;AACH,SAAS,wBAAwB,CAAC,GAAW;IAC3C,IAAI,GAAG,GAAG,GAAG,CAAC;IACd,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACjC,IAAI,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,GAAG,GAAG,GAA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C;aAAM,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YACtC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;QACjD,CAAC;QACD,SAAS,GAAG,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC5C,CAAC;IACD,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IAChC,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Inline markdown tokenizer shared by the React and vanilla chat bubbles.\n *\n * Core-service can hand the client bot text with links preserved\n * (`preserve_links_in_output` on /connect): `[text](url)`, `![alt](url)` and\n * bare `http(s)://` URLs arrive verbatim, everything else is still flattened\n * server-side. This turns one line of that text into nodes a renderer can\n * map onto DOM or JSX.\n *\n * Only `http:` and `https:` become links or images. Anything else — including\n * `javascript:` — stays literal text, regardless of what the server sent.\n * A link whose closing paren has not streamed in yet is left as text too, so\n * a bubble does not flicker between shapes mid-response.\n */\n\nexport type MediaKind = \"image\" | \"video\";\n\nexport type InlineNode =\n | { kind: \"text\"; text: string }\n | { kind: \"strong\"; text: string }\n | { kind: \"em\"; text: string }\n | { kind: \"link\"; href: string; label: string; media: MediaKind | null }\n | { kind: \"image\"; src: string; alt: string };\n\nconst IMAGE_EXT = /\\.(png|jpe?g|gif|webp|avif)$/i;\nconst VIDEO_EXT = /\\.(mp4|webm|mov|ogg)$/i;\n\n/** Classify a URL by its path extension; null for anything not previewable. */\nexport function mediaKindForUrl(url: string): MediaKind | null {\n let pathname: string;\n try {\n pathname = new URL(url).pathname;\n } catch {\n return null;\n }\n if (IMAGE_EXT.test(pathname)) return \"image\";\n if (VIDEO_EXT.test(pathname)) return \"video\";\n return null;\n}\n\n// Alternatives are tried in this order at every position:\n// 1. ![alt](url) / [text](url) with an http(s) URL\n// 2. bare http(s) URL, unless it is the target of a link still streaming in\n// 3. **bold** / __bold__ / *em* / _em_\n// Matching URLs before emphasis is what keeps `_` inside a URL literal.\nconst TOKEN =\n /(!?)\\[([^\\]]*)\\]\\((https?:\\/\\/[^\\s)]+)\\)|(?<!\\]\\()(https?:\\/\\/[^\\s<>\"'`]+)|(\\*\\*|__)(.*?)\\5|\\*([^*]+)\\*|_([^_]+)_/g;\n\nconst TRAILING_PUNCTUATION = \".,;:!?'\\\"\";\n\n/**\n * Sentence punctuation after a bare URL belongs to the sentence, and an\n * unbalanced `)` belongs to the surrounding parenthetical.\n */\nfunction splitTrailingPunctuation(raw: string): [string, string] {\n let url = raw;\n while (url.length > 0) {\n const last = url[url.length - 1];\n if (TRAILING_PUNCTUATION.includes(last)) {\n url = url.slice(0, -1);\n continue;\n }\n if (last === \")\") {\n const opens = (url.match(/\\(/g) ?? []).length;\n const closes = (url.match(/\\)/g) ?? []).length;\n if (closes > opens) {\n url = url.slice(0, -1);\n continue;\n }\n }\n break;\n }\n return [url, raw.slice(url.length)];\n}\n\nexport function parseInlineMarkdown(line: string): InlineNode[] {\n const nodes: InlineNode[] = [];\n const pushText = (text: string) => {\n if (!text) return;\n const last = nodes[nodes.length - 1];\n if (last?.kind === \"text\") last.text += text;\n else nodes.push({ kind: \"text\", text });\n };\n\n let lastIndex = 0;\n TOKEN.lastIndex = 0;\n let match: RegExpExecArray | null;\n while ((match = TOKEN.exec(line)) !== null) {\n pushText(line.slice(lastIndex, match.index));\n const [, bang, label, linkUrl, bareUrl, , boldText, starEm, underscoreEm] = match;\n\n if (linkUrl !== undefined) {\n if (bang) nodes.push({ kind: \"image\", src: linkUrl, alt: label });\n else nodes.push({ kind: \"link\", href: linkUrl, label, media: mediaKindForUrl(linkUrl) });\n } else if (bareUrl !== undefined) {\n const [href, rest] = splitTrailingPunctuation(bareUrl);\n if (href) nodes.push({ kind: \"link\", href, label: href, media: mediaKindForUrl(href) });\n pushText(rest);\n } else if (boldText !== undefined) {\n nodes.push({ kind: \"strong\", text: boldText });\n } else if (starEm !== undefined) {\n nodes.push({ kind: \"em\", text: starEm });\n } else if (underscoreEm !== undefined) {\n nodes.push({ kind: \"em\", text: underscoreEm });\n }\n lastIndex = match.index + match[0].length;\n }\n pushText(line.slice(lastIndex));\n return nodes;\n}\n"]}