@runtypelabs/persona 3.37.0 → 4.0.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 (50) hide show
  1. package/README.md +0 -1
  2. package/dist/animations/glyph-cycle.d.cts +1 -1
  3. package/dist/animations/glyph-cycle.d.ts +1 -1
  4. package/dist/animations/{types-DgYsuwXL.d.cts → types-B_xbfvR0.d.cts} +263 -181
  5. package/dist/animations/{types-DgYsuwXL.d.ts → types-B_xbfvR0.d.ts} +263 -181
  6. package/dist/animations/wipe.d.cts +1 -1
  7. package/dist/animations/wipe.d.ts +1 -1
  8. package/dist/codegen.cjs +1 -1
  9. package/dist/codegen.js +1 -1
  10. package/dist/index.cjs +52 -52
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +327 -838
  13. package/dist/index.d.ts +327 -838
  14. package/dist/index.global.js +39 -39
  15. package/dist/index.global.js.map +1 -1
  16. package/dist/index.js +52 -52
  17. package/dist/index.js.map +1 -1
  18. package/dist/install.global.js +1 -1
  19. package/dist/install.global.js.map +1 -1
  20. package/dist/smart-dom-reader.d.cts +268 -191
  21. package/dist/smart-dom-reader.d.ts +268 -191
  22. package/dist/theme-editor-preview.cjs +53 -53
  23. package/dist/theme-editor-preview.d.cts +268 -191
  24. package/dist/theme-editor-preview.d.ts +268 -191
  25. package/dist/theme-editor-preview.js +55 -55
  26. package/dist/theme-editor.d.cts +268 -191
  27. package/dist/theme-editor.d.ts +268 -191
  28. package/package.json +1 -1
  29. package/src/client.test.ts +446 -1041
  30. package/src/client.ts +684 -967
  31. package/src/components/tool-bubble.ts +46 -33
  32. package/src/generated/runtype-openapi-contract.ts +210 -714
  33. package/src/index-core.ts +2 -3
  34. package/src/install.test.ts +1 -34
  35. package/src/install.ts +1 -26
  36. package/src/runtime/init.test.ts +8 -67
  37. package/src/runtime/init.ts +2 -17
  38. package/src/session.test.ts +8 -8
  39. package/src/session.ts +1 -1
  40. package/src/types.ts +11 -12
  41. package/src/ui.postprocess.test.ts +107 -0
  42. package/src/ui.ts +40 -5
  43. package/src/utils/__fixtures__/unified-translator.oracle.ts +62 -14
  44. package/src/utils/copy-selection.test.ts +37 -0
  45. package/src/utils/copy-selection.ts +19 -0
  46. package/src/utils/event-stream-capture.test.ts +9 -64
  47. package/src/utils/sequence-buffer.test.ts +0 -256
  48. package/src/utils/sequence-buffer.ts +0 -130
  49. package/src/utils/unified-event-bridge.test.ts +0 -263
  50. package/src/utils/unified-event-bridge.ts +0 -431
@@ -1018,57 +1018,80 @@ type DeepPartial<T> = T extends object ? {
1018
1018
  [P in keyof T]?: DeepPartial<T[P]>;
1019
1019
  } : T;
1020
1020
 
1021
- type RuntypeAgentSSEEvent = {
1022
- agentId: string;
1023
- agentName: string;
1024
- config?: {
1025
- enableReflection?: boolean;
1026
- model?: string;
1027
- };
1021
+ type RuntypeExecutionStreamEvent = ({
1022
+ agentId?: string;
1023
+ agentName?: string;
1024
+ config?: Record<string, unknown>;
1028
1025
  executionId: string;
1029
- maxTurns: number;
1026
+ flowId?: string;
1027
+ flowName?: string;
1028
+ kind: "agent" | "flow";
1029
+ maxTurns?: number;
1030
1030
  seq: number;
1031
+ source?: string;
1031
1032
  startedAt: string;
1032
- type: "agent_start";
1033
- } | {
1033
+ totalSteps?: number;
1034
+ type: "execution_start";
1035
+ }) | ({
1036
+ completedAt?: string;
1037
+ durationMs?: number;
1034
1038
  executionId: string;
1035
- iteration: number;
1036
- maxTurns: number;
1039
+ failedSteps?: number;
1040
+ finalOutput?: string;
1041
+ iterations?: number;
1042
+ kind: "agent" | "flow";
1037
1043
  seq: number;
1038
- startedAt: string;
1044
+ stopReason?: string;
1045
+ success: boolean;
1046
+ successfulSteps?: number;
1039
1047
  totalCost?: number;
1040
- type: "agent_iteration_start";
1041
- } | ({
1048
+ totalSteps?: number;
1049
+ totalTokens?: {
1050
+ input: number;
1051
+ output: number;
1052
+ };
1053
+ type: "execution_complete";
1054
+ }) | ({
1055
+ code?: string;
1056
+ completedAt?: string;
1057
+ error: string | {
1058
+ code: string;
1059
+ details?: Record<string, unknown>;
1060
+ message: string;
1061
+ };
1042
1062
  executionId: string;
1043
- iteration: number;
1044
- role: "user" | "assistant" | "system";
1063
+ kind: "agent" | "flow";
1045
1064
  seq: number;
1046
- turnId: string;
1047
- turnIndex: number;
1048
- type: "agent_turn_start";
1065
+ type: "execution_error";
1066
+ upgradeUrl?: string;
1049
1067
  }) | ({
1050
- contentType: "text" | "thinking" | "tool_input";
1051
- delta: string;
1052
1068
  executionId: string;
1053
- iteration: number;
1069
+ id: string;
1070
+ iteration?: number;
1071
+ role: "user" | "assistant" | "system";
1054
1072
  seq: number;
1055
- turnId: string;
1056
- type: "agent_turn_delta";
1073
+ turnIndex?: number;
1074
+ type: "turn_start";
1057
1075
  }) | ({
1058
- completedAt: string;
1076
+ completedAt?: string;
1059
1077
  content?: string;
1060
1078
  cost?: number;
1061
- estimatedContextBreakdown?: {
1062
- categories: Record<string, {
1063
- chars: number;
1064
- estimatedTokens: number;
1079
+ executionId: string;
1080
+ fallback?: {
1081
+ attempts: Array<{
1082
+ attempt: number;
1083
+ error?: string;
1084
+ model?: string;
1085
+ success: boolean;
1086
+ type: "retry" | "model" | "message" | "flow";
1065
1087
  }>;
1066
- contextWindowSize?: number;
1067
- estimatedTotalTokens: number;
1068
- estimatedUtilizationPercent?: number;
1088
+ exhausted: boolean;
1089
+ model?: string;
1090
+ reason?: string | null;
1091
+ used: boolean;
1069
1092
  };
1070
- executionId: string;
1071
- iteration: number;
1093
+ id: string;
1094
+ iteration?: number;
1072
1095
  role: "user" | "assistant" | "system";
1073
1096
  seq: number;
1074
1097
  stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
@@ -1076,207 +1099,260 @@ type RuntypeAgentSSEEvent = {
1076
1099
  input: number;
1077
1100
  output: number;
1078
1101
  };
1079
- turnId: string;
1080
- type: "agent_turn_complete";
1102
+ type: "turn_complete";
1103
+ }) | {
1104
+ executionId: string;
1105
+ id: string;
1106
+ index?: number;
1107
+ name?: string;
1108
+ outputVariable?: string;
1109
+ seq: number;
1110
+ startedAt?: string;
1111
+ stepType?: string;
1112
+ totalSteps?: number;
1113
+ type: "step_start";
1114
+ } | ({
1115
+ completedAt?: string;
1116
+ durationMs?: number;
1117
+ error?: string;
1118
+ executionId: string;
1119
+ fallback?: {
1120
+ attempts: Array<{
1121
+ attempt: number;
1122
+ error?: string;
1123
+ model?: string;
1124
+ success: boolean;
1125
+ type: "retry" | "model" | "message" | "flow";
1126
+ }>;
1127
+ exhausted: boolean;
1128
+ model?: string;
1129
+ reason?: string | null;
1130
+ used: boolean;
1131
+ };
1132
+ id: string;
1133
+ name?: string;
1134
+ result?: unknown;
1135
+ seq: number;
1136
+ stepType?: string;
1137
+ stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
1138
+ success?: boolean;
1139
+ tokensUsed?: number;
1140
+ type: "step_complete";
1141
+ unresolvedVariables?: Array<string>;
1142
+ }) | {
1143
+ executionId: string;
1144
+ id: string;
1145
+ index?: number;
1146
+ name?: string;
1147
+ seq: number;
1148
+ skippedAt?: string;
1149
+ stepType?: string;
1150
+ totalSteps?: number;
1151
+ type: "step_skip";
1152
+ when?: string;
1153
+ } | ({
1154
+ executionId: string;
1155
+ id: string;
1156
+ parentToolCallId?: string;
1157
+ role?: "user" | "assistant" | "system";
1158
+ seq: number;
1159
+ stepId?: string;
1160
+ turnId?: string;
1161
+ type: "text_start";
1162
+ }) | {
1163
+ delta: string;
1164
+ executionId: string;
1165
+ id: string;
1166
+ seq: number;
1167
+ type: "text_delta";
1168
+ } | {
1169
+ executionId: string;
1170
+ id: string;
1171
+ seq: number;
1172
+ text?: string;
1173
+ type: "text_complete";
1174
+ } | ({
1175
+ executionId: string;
1176
+ id: string;
1177
+ parentToolCallId?: string;
1178
+ scope?: "turn" | "loop";
1179
+ seq: number;
1180
+ type: "reasoning_start";
1181
+ }) | {
1182
+ delta: string;
1183
+ executionId: string;
1184
+ id: string;
1185
+ seq: number;
1186
+ type: "reasoning_delta";
1187
+ } | ({
1188
+ executionId: string;
1189
+ id: string;
1190
+ scope?: "turn" | "loop";
1191
+ seq: number;
1192
+ text?: string;
1193
+ type: "reasoning_complete";
1081
1194
  }) | ({
1082
1195
  executionId: string;
1083
- iteration: number;
1196
+ id: string;
1197
+ mediaType: string;
1198
+ role?: "user" | "assistant" | "system";
1199
+ seq: number;
1200
+ toolCallId?: string;
1201
+ type: "media_start";
1202
+ }) | {
1203
+ delta: string;
1204
+ executionId: string;
1205
+ id: string;
1206
+ seq: number;
1207
+ type: "media_delta";
1208
+ } | {
1209
+ data?: string;
1210
+ executionId: string;
1211
+ id: string;
1212
+ mediaType?: string;
1213
+ seq: number;
1214
+ toolCallId?: string;
1215
+ type: "media_complete";
1216
+ url?: string;
1217
+ } | ({
1218
+ artifactType: "markdown" | "component";
1219
+ component?: string;
1220
+ executionId?: string;
1221
+ id: string;
1222
+ seq?: number;
1223
+ title?: string;
1224
+ type: "artifact_start";
1225
+ }) | {
1226
+ delta: string;
1227
+ executionId?: string;
1228
+ id: string;
1229
+ seq?: number;
1230
+ type: "artifact_delta";
1231
+ } | {
1232
+ component: string;
1233
+ executionId?: string;
1234
+ id: string;
1235
+ props: Record<string, unknown>;
1236
+ seq?: number;
1237
+ type: "artifact_update";
1238
+ } | {
1239
+ executionId?: string;
1240
+ id: string;
1241
+ seq?: number;
1242
+ type: "artifact_complete";
1243
+ } | {
1244
+ executionId: string;
1245
+ id?: string;
1246
+ seq: number;
1247
+ sourceType?: string;
1248
+ title?: string;
1249
+ type: "source";
1250
+ url?: string;
1251
+ [key: string]: unknown;
1252
+ } | ({
1253
+ executionId: string;
1254
+ hiddenParameterNames?: Array<string>;
1255
+ iteration?: number;
1084
1256
  origin?: "webmcp" | "sdk";
1085
1257
  pageOrigin?: string;
1086
1258
  parameters?: Record<string, unknown>;
1087
1259
  seq: number;
1260
+ startedAt?: string;
1261
+ stepId?: string;
1088
1262
  toolCallId: string;
1089
1263
  toolName: string;
1090
- toolType: "flow" | "mcp" | "builtin" | "custom" | "external" | "advisor" | "subagent" | "local";
1091
- type: "agent_tool_start";
1264
+ toolType: string;
1265
+ type: "tool_start";
1092
1266
  }) | {
1093
1267
  delta: string;
1094
1268
  executionId: string;
1095
- iteration: number;
1096
1269
  seq: number;
1097
1270
  toolCallId: string;
1098
- type: "agent_tool_delta";
1271
+ type: "tool_input_delta";
1099
1272
  } | {
1100
- delta: string;
1101
1273
  executionId: string;
1102
- iteration: number;
1274
+ hiddenParameterNames?: Array<string>;
1275
+ parameters: Record<string, unknown>;
1103
1276
  seq: number;
1104
1277
  toolCallId: string;
1105
- type: "agent_tool_input_delta";
1278
+ toolName?: string;
1279
+ type: "tool_input_complete";
1106
1280
  } | {
1281
+ delta: string;
1107
1282
  executionId: string;
1108
- hiddenParameterNames?: Array<string>;
1109
- iteration: number;
1110
- parameters: Record<string, unknown>;
1111
1283
  seq: number;
1112
1284
  toolCallId: string;
1113
- toolName: string;
1114
- type: "agent_tool_input_complete";
1285
+ type: "tool_output_delta";
1115
1286
  } | {
1287
+ error?: string;
1116
1288
  executionId: string;
1117
1289
  executionTime?: number;
1118
- iteration: number;
1290
+ iteration?: number;
1119
1291
  result?: unknown;
1120
1292
  seq: number;
1293
+ stepId?: string;
1121
1294
  success: boolean;
1122
1295
  toolCallId: string;
1123
- toolName: string;
1124
- type: "agent_tool_complete";
1125
- } | ({
1126
- executionId?: string;
1127
- iteration: number;
1128
- media: Array<({
1129
- annotations?: {
1130
- audience?: Array<"user" | "assistant">;
1131
- };
1132
- data: string;
1133
- mediaType: string;
1134
- type: "media";
1135
- }) | ({
1136
- annotations?: {
1137
- audience?: Array<"user" | "assistant">;
1138
- };
1139
- mediaType?: string;
1140
- type: "image-url";
1141
- url: string;
1142
- }) | ({
1143
- annotations?: {
1144
- audience?: Array<"user" | "assistant">;
1145
- };
1146
- mediaType: string;
1147
- type: "file-url";
1148
- url: string;
1149
- })>;
1150
- seq?: number;
1151
- toolCallId: string;
1152
- toolName: string;
1153
- type: "agent_media";
1154
- }) | {
1296
+ toolName?: string;
1297
+ type: "tool_complete";
1298
+ } | {
1155
1299
  approvalId: string;
1156
- description: string;
1300
+ description?: string;
1157
1301
  executionId: string;
1158
- externalAgent?: {
1159
- contextId?: string;
1160
- taskId?: string;
1161
- };
1162
1302
  iteration?: number;
1163
1303
  parameters?: Record<string, unknown>;
1164
1304
  reason?: string;
1165
1305
  seq: number;
1166
- startedAt: string;
1167
- timeout: number;
1168
- toolCallId: string;
1306
+ startedAt?: string;
1307
+ subagent?: {
1308
+ agentName?: string;
1309
+ toolName: string;
1310
+ };
1311
+ timeout?: number;
1312
+ toolCallId?: string;
1169
1313
  toolName: string;
1170
- toolType: string;
1171
- type: "agent_approval_start";
1314
+ toolType?: string;
1315
+ type: "approval_start";
1172
1316
  } | ({
1173
1317
  approvalId: string;
1174
- completedAt: string;
1318
+ completedAt?: string;
1175
1319
  decision: "approved" | "denied" | "timeout";
1176
1320
  executionId: string;
1177
- resolvedBy: "user" | "system";
1321
+ resolvedBy?: "user" | "system";
1178
1322
  seq: number;
1179
- type: "agent_approval_complete";
1323
+ type: "approval_complete";
1180
1324
  }) | ({
1181
- awaitedAt: string;
1325
+ awaitedAt?: string;
1182
1326
  executionId: string;
1183
1327
  origin?: "webmcp" | "sdk";
1184
1328
  pageOrigin?: string;
1185
1329
  parameters?: Record<string, unknown>;
1186
1330
  seq: number;
1187
1331
  toolCallId?: string;
1188
- toolId: string;
1189
- toolName: string;
1190
- type: "agent_await";
1191
- }) | {
1192
- completedAt: string;
1193
- cost?: number;
1194
- duration?: number;
1195
- estimatedContextBreakdown?: {
1196
- categories: Record<string, {
1197
- chars: number;
1198
- estimatedTokens: number;
1199
- }>;
1200
- contextWindowSize?: number;
1201
- estimatedTotalTokens: number;
1202
- estimatedUtilizationPercent?: number;
1203
- };
1204
- executionId: string;
1205
- iteration: number;
1206
- output?: string;
1207
- runningTotalCost?: number;
1208
- seq: number;
1209
- stopConditionMet: boolean;
1210
- tokens?: {
1211
- input: number;
1212
- output: number;
1213
- };
1214
- toolCallsMade: number;
1215
- type: "agent_iteration_complete";
1216
- } | {
1217
- executionId: string;
1218
- iteration: number;
1219
- reflection?: string;
1220
- seq: number;
1221
- timestamp?: string;
1222
- type: "agent_reflection";
1223
- } | {
1224
- activatedCapabilities: Array<string>;
1225
- executionId: string;
1226
- iteration: number;
1227
- seq: number;
1228
- skill: string;
1229
- timestamp?: string;
1230
- toolCallId: string;
1231
- type: "agent_skill_loaded";
1232
- } | ({
1233
- executionId: string;
1234
- iteration: number;
1235
- outcome: "pending_approval" | "auto_published";
1236
- proposalId?: string;
1237
- seq: number;
1238
- skill: string;
1239
- timestamp?: string;
1240
- toolCallId: string;
1241
- type: "agent_skill_proposed";
1332
+ toolId?: string;
1333
+ toolName?: string;
1334
+ type: "await";
1242
1335
  }) | ({
1243
- agentId: string;
1244
- completedAt: string;
1245
- duration?: number;
1246
- error?: string;
1247
- executionId: string;
1248
- externalAgent?: {
1249
- contextId?: string;
1250
- taskId?: string;
1251
- };
1252
- finalOutput?: string;
1253
- iterations: number;
1254
- seq: number;
1255
- stopReason: "complete" | "end_turn" | "max_turns" | "max_cost" | "timeout" | "error";
1256
- success: boolean;
1257
- totalCost?: number;
1258
- totalTokens?: {
1259
- input: number;
1260
- output: number;
1261
- };
1262
- type: "agent_complete";
1263
- }) | {
1264
- error: {
1336
+ error: string | {
1265
1337
  code: string;
1266
1338
  details?: Record<string, unknown>;
1267
1339
  message: string;
1268
1340
  };
1269
1341
  executionId: string;
1270
- iteration?: number;
1271
- recoverable: boolean;
1342
+ recoverable?: boolean;
1272
1343
  seq: number;
1273
- timestamp?: string;
1274
- type: "agent_error";
1275
- } | {
1344
+ type: "error";
1345
+ }) | {
1276
1346
  executionId: string;
1277
1347
  seq: number;
1278
1348
  timestamp: string;
1279
- type: "agent_ping";
1349
+ type: "ping";
1350
+ } | {
1351
+ executionId?: string;
1352
+ name: string;
1353
+ seq?: number;
1354
+ type: "custom";
1355
+ value?: unknown;
1280
1356
  };
1281
1357
  type RuntypeFlowSSEEvent = {
1282
1358
  executionContext?: Record<string, unknown>;
@@ -1574,9 +1650,9 @@ type RuntypeFlowSSEEvent = {
1574
1650
  type RuntypeStreamEventOf<U, T extends string> = Extract<U, {
1575
1651
  type: T;
1576
1652
  }>;
1577
- type RuntypeAgentTurnCompleteEvent = RuntypeStreamEventOf<RuntypeAgentSSEEvent, "agent_turn_complete">;
1653
+ type RuntypeTurnCompleteEvent = RuntypeStreamEventOf<RuntypeExecutionStreamEvent, "turn_complete">;
1578
1654
  type RuntypeStepCompleteEvent = RuntypeStreamEventOf<RuntypeFlowSSEEvent, "step_complete">;
1579
- type RuntypeStopReasonKind = NonNullable<RuntypeAgentTurnCompleteEvent["stopReason"] | RuntypeStepCompleteEvent["stopReason"]>;
1655
+ type RuntypeStopReasonKind = NonNullable<RuntypeTurnCompleteEvent["stopReason"] | RuntypeStepCompleteEvent["stopReason"]>;
1580
1656
 
1581
1657
  /**
1582
1658
  * Text content part for multi-modal messages
@@ -4690,6 +4766,11 @@ type AgentWidgetConfig = {
4690
4766
  * When provided, the widget uses agent loop execution instead of flow dispatch.
4691
4767
  * Mutually exclusive with `flowId`.
4692
4768
  *
4769
+ * Note: `@runtypelabs/persona-proxy` rejects a client-supplied `agent` (it was
4770
+ * an open relay). This option is only for endpoints authorized to accept a
4771
+ * client agent — your own backend, or token-scoped direct-to-Runtype dispatch.
4772
+ * For the proxy, pin the agent server-side with `agentConfig`/`agentId`.
4773
+ *
4693
4774
  * @example
4694
4775
  * ```typescript
4695
4776
  * config: {
@@ -5160,16 +5241,6 @@ type AgentWidgetConfig = {
5160
5241
  * ```
5161
5242
  */
5162
5243
  parseSSEEvent?: AgentWidgetSSEEventParser;
5163
- /**
5164
- * Wire vocabulary requested from the dispatch endpoint.
5165
- * - `'legacy'` (default): the current `agent_*` / `flow_*` SSE events.
5166
- * - `'unified'`: opt into the API's neutral unified event vocabulary by sending
5167
- * `?events=unified`; incoming frames are transparently bridged back to the same
5168
- * handlers, so rendering is unchanged. Requires an upstream that honors the
5169
- * param — the widget detects the actual wire mode from the first stream frame
5170
- * and falls back to legacy automatically if the param was ignored.
5171
- */
5172
- events?: "legacy" | "unified";
5173
5244
  /**
5174
5245
  * Called for every parsed SSE frame (after JSON parse), before native handling.
5175
5246
  * Use for lightweight side effects (e.g. telemetry). Does not replace native
@@ -5349,6 +5420,12 @@ type AgentWidgetReasoning = {
5349
5420
  id: string;
5350
5421
  status: "pending" | "streaming" | "complete";
5351
5422
  chunks: string[];
5423
+ /**
5424
+ * Reasoning channel scope (unified spec). `"turn"` is ordinary per-turn
5425
+ * thinking; `"loop"` is a cross-iteration agent reflection (the fold that
5426
+ * replaced the legacy `agent_reflection` event). Absent for legacy streams.
5427
+ */
5428
+ scope?: "turn" | "loop";
5352
5429
  startedAt?: number;
5353
5430
  completedAt?: number;
5354
5431
  durationMs?: number;