@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
@@ -749,57 +749,80 @@ interface AgentWidgetPlugin {
749
749
  onUnregister?: () => void;
750
750
  }
751
751
 
752
- type RuntypeAgentSSEEvent = {
753
- agentId: string;
754
- agentName: string;
755
- config?: {
756
- enableReflection?: boolean;
757
- model?: string;
758
- };
752
+ type RuntypeExecutionStreamEvent = ({
753
+ agentId?: string;
754
+ agentName?: string;
755
+ config?: Record<string, unknown>;
759
756
  executionId: string;
760
- maxTurns: number;
757
+ flowId?: string;
758
+ flowName?: string;
759
+ kind: "agent" | "flow";
760
+ maxTurns?: number;
761
761
  seq: number;
762
+ source?: string;
762
763
  startedAt: string;
763
- type: "agent_start";
764
- } | {
764
+ totalSteps?: number;
765
+ type: "execution_start";
766
+ }) | ({
767
+ completedAt?: string;
768
+ durationMs?: number;
765
769
  executionId: string;
766
- iteration: number;
767
- maxTurns: number;
770
+ failedSteps?: number;
771
+ finalOutput?: string;
772
+ iterations?: number;
773
+ kind: "agent" | "flow";
768
774
  seq: number;
769
- startedAt: string;
775
+ stopReason?: string;
776
+ success: boolean;
777
+ successfulSteps?: number;
770
778
  totalCost?: number;
771
- type: "agent_iteration_start";
772
- } | ({
779
+ totalSteps?: number;
780
+ totalTokens?: {
781
+ input: number;
782
+ output: number;
783
+ };
784
+ type: "execution_complete";
785
+ }) | ({
786
+ code?: string;
787
+ completedAt?: string;
788
+ error: string | {
789
+ code: string;
790
+ details?: Record<string, unknown>;
791
+ message: string;
792
+ };
773
793
  executionId: string;
774
- iteration: number;
775
- role: "user" | "assistant" | "system";
794
+ kind: "agent" | "flow";
776
795
  seq: number;
777
- turnId: string;
778
- turnIndex: number;
779
- type: "agent_turn_start";
796
+ type: "execution_error";
797
+ upgradeUrl?: string;
780
798
  }) | ({
781
- contentType: "text" | "thinking" | "tool_input";
782
- delta: string;
783
799
  executionId: string;
784
- iteration: number;
800
+ id: string;
801
+ iteration?: number;
802
+ role: "user" | "assistant" | "system";
785
803
  seq: number;
786
- turnId: string;
787
- type: "agent_turn_delta";
804
+ turnIndex?: number;
805
+ type: "turn_start";
788
806
  }) | ({
789
- completedAt: string;
807
+ completedAt?: string;
790
808
  content?: string;
791
809
  cost?: number;
792
- estimatedContextBreakdown?: {
793
- categories: Record<string, {
794
- chars: number;
795
- estimatedTokens: number;
810
+ executionId: string;
811
+ fallback?: {
812
+ attempts: Array<{
813
+ attempt: number;
814
+ error?: string;
815
+ model?: string;
816
+ success: boolean;
817
+ type: "retry" | "model" | "message" | "flow";
796
818
  }>;
797
- contextWindowSize?: number;
798
- estimatedTotalTokens: number;
799
- estimatedUtilizationPercent?: number;
819
+ exhausted: boolean;
820
+ model?: string;
821
+ reason?: string | null;
822
+ used: boolean;
800
823
  };
801
- executionId: string;
802
- iteration: number;
824
+ id: string;
825
+ iteration?: number;
803
826
  role: "user" | "assistant" | "system";
804
827
  seq: number;
805
828
  stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
@@ -807,207 +830,260 @@ type RuntypeAgentSSEEvent = {
807
830
  input: number;
808
831
  output: number;
809
832
  };
810
- turnId: string;
811
- type: "agent_turn_complete";
833
+ type: "turn_complete";
834
+ }) | {
835
+ executionId: string;
836
+ id: string;
837
+ index?: number;
838
+ name?: string;
839
+ outputVariable?: string;
840
+ seq: number;
841
+ startedAt?: string;
842
+ stepType?: string;
843
+ totalSteps?: number;
844
+ type: "step_start";
845
+ } | ({
846
+ completedAt?: string;
847
+ durationMs?: number;
848
+ error?: string;
849
+ executionId: string;
850
+ fallback?: {
851
+ attempts: Array<{
852
+ attempt: number;
853
+ error?: string;
854
+ model?: string;
855
+ success: boolean;
856
+ type: "retry" | "model" | "message" | "flow";
857
+ }>;
858
+ exhausted: boolean;
859
+ model?: string;
860
+ reason?: string | null;
861
+ used: boolean;
862
+ };
863
+ id: string;
864
+ name?: string;
865
+ result?: unknown;
866
+ seq: number;
867
+ stepType?: string;
868
+ stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
869
+ success?: boolean;
870
+ tokensUsed?: number;
871
+ type: "step_complete";
872
+ unresolvedVariables?: Array<string>;
873
+ }) | {
874
+ executionId: string;
875
+ id: string;
876
+ index?: number;
877
+ name?: string;
878
+ seq: number;
879
+ skippedAt?: string;
880
+ stepType?: string;
881
+ totalSteps?: number;
882
+ type: "step_skip";
883
+ when?: string;
884
+ } | ({
885
+ executionId: string;
886
+ id: string;
887
+ parentToolCallId?: string;
888
+ role?: "user" | "assistant" | "system";
889
+ seq: number;
890
+ stepId?: string;
891
+ turnId?: string;
892
+ type: "text_start";
893
+ }) | {
894
+ delta: string;
895
+ executionId: string;
896
+ id: string;
897
+ seq: number;
898
+ type: "text_delta";
899
+ } | {
900
+ executionId: string;
901
+ id: string;
902
+ seq: number;
903
+ text?: string;
904
+ type: "text_complete";
905
+ } | ({
906
+ executionId: string;
907
+ id: string;
908
+ parentToolCallId?: string;
909
+ scope?: "turn" | "loop";
910
+ seq: number;
911
+ type: "reasoning_start";
912
+ }) | {
913
+ delta: string;
914
+ executionId: string;
915
+ id: string;
916
+ seq: number;
917
+ type: "reasoning_delta";
918
+ } | ({
919
+ executionId: string;
920
+ id: string;
921
+ scope?: "turn" | "loop";
922
+ seq: number;
923
+ text?: string;
924
+ type: "reasoning_complete";
812
925
  }) | ({
813
926
  executionId: string;
814
- iteration: number;
927
+ id: string;
928
+ mediaType: string;
929
+ role?: "user" | "assistant" | "system";
930
+ seq: number;
931
+ toolCallId?: string;
932
+ type: "media_start";
933
+ }) | {
934
+ delta: string;
935
+ executionId: string;
936
+ id: string;
937
+ seq: number;
938
+ type: "media_delta";
939
+ } | {
940
+ data?: string;
941
+ executionId: string;
942
+ id: string;
943
+ mediaType?: string;
944
+ seq: number;
945
+ toolCallId?: string;
946
+ type: "media_complete";
947
+ url?: string;
948
+ } | ({
949
+ artifactType: "markdown" | "component";
950
+ component?: string;
951
+ executionId?: string;
952
+ id: string;
953
+ seq?: number;
954
+ title?: string;
955
+ type: "artifact_start";
956
+ }) | {
957
+ delta: string;
958
+ executionId?: string;
959
+ id: string;
960
+ seq?: number;
961
+ type: "artifact_delta";
962
+ } | {
963
+ component: string;
964
+ executionId?: string;
965
+ id: string;
966
+ props: Record<string, unknown>;
967
+ seq?: number;
968
+ type: "artifact_update";
969
+ } | {
970
+ executionId?: string;
971
+ id: string;
972
+ seq?: number;
973
+ type: "artifact_complete";
974
+ } | {
975
+ executionId: string;
976
+ id?: string;
977
+ seq: number;
978
+ sourceType?: string;
979
+ title?: string;
980
+ type: "source";
981
+ url?: string;
982
+ [key: string]: unknown;
983
+ } | ({
984
+ executionId: string;
985
+ hiddenParameterNames?: Array<string>;
986
+ iteration?: number;
815
987
  origin?: "webmcp" | "sdk";
816
988
  pageOrigin?: string;
817
989
  parameters?: Record<string, unknown>;
818
990
  seq: number;
991
+ startedAt?: string;
992
+ stepId?: string;
819
993
  toolCallId: string;
820
994
  toolName: string;
821
- toolType: "flow" | "mcp" | "builtin" | "custom" | "external" | "advisor" | "subagent" | "local";
822
- type: "agent_tool_start";
995
+ toolType: string;
996
+ type: "tool_start";
823
997
  }) | {
824
998
  delta: string;
825
999
  executionId: string;
826
- iteration: number;
827
1000
  seq: number;
828
1001
  toolCallId: string;
829
- type: "agent_tool_delta";
1002
+ type: "tool_input_delta";
830
1003
  } | {
831
- delta: string;
832
1004
  executionId: string;
833
- iteration: number;
1005
+ hiddenParameterNames?: Array<string>;
1006
+ parameters: Record<string, unknown>;
834
1007
  seq: number;
835
1008
  toolCallId: string;
836
- type: "agent_tool_input_delta";
1009
+ toolName?: string;
1010
+ type: "tool_input_complete";
837
1011
  } | {
1012
+ delta: string;
838
1013
  executionId: string;
839
- hiddenParameterNames?: Array<string>;
840
- iteration: number;
841
- parameters: Record<string, unknown>;
842
1014
  seq: number;
843
1015
  toolCallId: string;
844
- toolName: string;
845
- type: "agent_tool_input_complete";
1016
+ type: "tool_output_delta";
846
1017
  } | {
1018
+ error?: string;
847
1019
  executionId: string;
848
1020
  executionTime?: number;
849
- iteration: number;
1021
+ iteration?: number;
850
1022
  result?: unknown;
851
1023
  seq: number;
1024
+ stepId?: string;
852
1025
  success: boolean;
853
1026
  toolCallId: string;
854
- toolName: string;
855
- type: "agent_tool_complete";
856
- } | ({
857
- executionId?: string;
858
- iteration: number;
859
- media: Array<({
860
- annotations?: {
861
- audience?: Array<"user" | "assistant">;
862
- };
863
- data: string;
864
- mediaType: string;
865
- type: "media";
866
- }) | ({
867
- annotations?: {
868
- audience?: Array<"user" | "assistant">;
869
- };
870
- mediaType?: string;
871
- type: "image-url";
872
- url: string;
873
- }) | ({
874
- annotations?: {
875
- audience?: Array<"user" | "assistant">;
876
- };
877
- mediaType: string;
878
- type: "file-url";
879
- url: string;
880
- })>;
881
- seq?: number;
882
- toolCallId: string;
883
- toolName: string;
884
- type: "agent_media";
885
- }) | {
1027
+ toolName?: string;
1028
+ type: "tool_complete";
1029
+ } | {
886
1030
  approvalId: string;
887
- description: string;
1031
+ description?: string;
888
1032
  executionId: string;
889
- externalAgent?: {
890
- contextId?: string;
891
- taskId?: string;
892
- };
893
1033
  iteration?: number;
894
1034
  parameters?: Record<string, unknown>;
895
1035
  reason?: string;
896
1036
  seq: number;
897
- startedAt: string;
898
- timeout: number;
899
- toolCallId: string;
1037
+ startedAt?: string;
1038
+ subagent?: {
1039
+ agentName?: string;
1040
+ toolName: string;
1041
+ };
1042
+ timeout?: number;
1043
+ toolCallId?: string;
900
1044
  toolName: string;
901
- toolType: string;
902
- type: "agent_approval_start";
1045
+ toolType?: string;
1046
+ type: "approval_start";
903
1047
  } | ({
904
1048
  approvalId: string;
905
- completedAt: string;
1049
+ completedAt?: string;
906
1050
  decision: "approved" | "denied" | "timeout";
907
1051
  executionId: string;
908
- resolvedBy: "user" | "system";
1052
+ resolvedBy?: "user" | "system";
909
1053
  seq: number;
910
- type: "agent_approval_complete";
1054
+ type: "approval_complete";
911
1055
  }) | ({
912
- awaitedAt: string;
1056
+ awaitedAt?: string;
913
1057
  executionId: string;
914
1058
  origin?: "webmcp" | "sdk";
915
1059
  pageOrigin?: string;
916
1060
  parameters?: Record<string, unknown>;
917
1061
  seq: number;
918
1062
  toolCallId?: string;
919
- toolId: string;
920
- toolName: string;
921
- type: "agent_await";
922
- }) | {
923
- completedAt: string;
924
- cost?: number;
925
- duration?: number;
926
- estimatedContextBreakdown?: {
927
- categories: Record<string, {
928
- chars: number;
929
- estimatedTokens: number;
930
- }>;
931
- contextWindowSize?: number;
932
- estimatedTotalTokens: number;
933
- estimatedUtilizationPercent?: number;
934
- };
935
- executionId: string;
936
- iteration: number;
937
- output?: string;
938
- runningTotalCost?: number;
939
- seq: number;
940
- stopConditionMet: boolean;
941
- tokens?: {
942
- input: number;
943
- output: number;
944
- };
945
- toolCallsMade: number;
946
- type: "agent_iteration_complete";
947
- } | {
948
- executionId: string;
949
- iteration: number;
950
- reflection?: string;
951
- seq: number;
952
- timestamp?: string;
953
- type: "agent_reflection";
954
- } | {
955
- activatedCapabilities: Array<string>;
956
- executionId: string;
957
- iteration: number;
958
- seq: number;
959
- skill: string;
960
- timestamp?: string;
961
- toolCallId: string;
962
- type: "agent_skill_loaded";
963
- } | ({
964
- executionId: string;
965
- iteration: number;
966
- outcome: "pending_approval" | "auto_published";
967
- proposalId?: string;
968
- seq: number;
969
- skill: string;
970
- timestamp?: string;
971
- toolCallId: string;
972
- type: "agent_skill_proposed";
1063
+ toolId?: string;
1064
+ toolName?: string;
1065
+ type: "await";
973
1066
  }) | ({
974
- agentId: string;
975
- completedAt: string;
976
- duration?: number;
977
- error?: string;
978
- executionId: string;
979
- externalAgent?: {
980
- contextId?: string;
981
- taskId?: string;
982
- };
983
- finalOutput?: string;
984
- iterations: number;
985
- seq: number;
986
- stopReason: "complete" | "end_turn" | "max_turns" | "max_cost" | "timeout" | "error";
987
- success: boolean;
988
- totalCost?: number;
989
- totalTokens?: {
990
- input: number;
991
- output: number;
992
- };
993
- type: "agent_complete";
994
- }) | {
995
- error: {
1067
+ error: string | {
996
1068
  code: string;
997
1069
  details?: Record<string, unknown>;
998
1070
  message: string;
999
1071
  };
1000
1072
  executionId: string;
1001
- iteration?: number;
1002
- recoverable: boolean;
1073
+ recoverable?: boolean;
1003
1074
  seq: number;
1004
- timestamp?: string;
1005
- type: "agent_error";
1006
- } | {
1075
+ type: "error";
1076
+ }) | {
1007
1077
  executionId: string;
1008
1078
  seq: number;
1009
1079
  timestamp: string;
1010
- type: "agent_ping";
1080
+ type: "ping";
1081
+ } | {
1082
+ executionId?: string;
1083
+ name: string;
1084
+ seq?: number;
1085
+ type: "custom";
1086
+ value?: unknown;
1011
1087
  };
1012
1088
  type RuntypeFlowSSEEvent = {
1013
1089
  executionContext?: Record<string, unknown>;
@@ -1305,9 +1381,9 @@ type RuntypeFlowSSEEvent = {
1305
1381
  type RuntypeStreamEventOf<U, T extends string> = Extract<U, {
1306
1382
  type: T;
1307
1383
  }>;
1308
- type RuntypeAgentTurnCompleteEvent = RuntypeStreamEventOf<RuntypeAgentSSEEvent, "agent_turn_complete">;
1384
+ type RuntypeTurnCompleteEvent = RuntypeStreamEventOf<RuntypeExecutionStreamEvent, "turn_complete">;
1309
1385
  type RuntypeStepCompleteEvent = RuntypeStreamEventOf<RuntypeFlowSSEEvent, "step_complete">;
1310
- type RuntypeStopReasonKind = NonNullable<RuntypeAgentTurnCompleteEvent["stopReason"] | RuntypeStepCompleteEvent["stopReason"]>;
1386
+ type RuntypeStopReasonKind = NonNullable<RuntypeTurnCompleteEvent["stopReason"] | RuntypeStepCompleteEvent["stopReason"]>;
1311
1387
 
1312
1388
  /**
1313
1389
  * Text content part for multi-modal messages
@@ -4421,6 +4497,11 @@ type AgentWidgetConfig = {
4421
4497
  * When provided, the widget uses agent loop execution instead of flow dispatch.
4422
4498
  * Mutually exclusive with `flowId`.
4423
4499
  *
4500
+ * Note: `@runtypelabs/persona-proxy` rejects a client-supplied `agent` (it was
4501
+ * an open relay). This option is only for endpoints authorized to accept a
4502
+ * client agent — your own backend, or token-scoped direct-to-Runtype dispatch.
4503
+ * For the proxy, pin the agent server-side with `agentConfig`/`agentId`.
4504
+ *
4424
4505
  * @example
4425
4506
  * ```typescript
4426
4507
  * config: {
@@ -4891,16 +4972,6 @@ type AgentWidgetConfig = {
4891
4972
  * ```
4892
4973
  */
4893
4974
  parseSSEEvent?: AgentWidgetSSEEventParser;
4894
- /**
4895
- * Wire vocabulary requested from the dispatch endpoint.
4896
- * - `'legacy'` (default): the current `agent_*` / `flow_*` SSE events.
4897
- * - `'unified'`: opt into the API's neutral unified event vocabulary by sending
4898
- * `?events=unified`; incoming frames are transparently bridged back to the same
4899
- * handlers, so rendering is unchanged. Requires an upstream that honors the
4900
- * param — the widget detects the actual wire mode from the first stream frame
4901
- * and falls back to legacy automatically if the param was ignored.
4902
- */
4903
- events?: "legacy" | "unified";
4904
4975
  /**
4905
4976
  * Called for every parsed SSE frame (after JSON parse), before native handling.
4906
4977
  * Use for lightweight side effects (e.g. telemetry). Does not replace native
@@ -5080,6 +5151,12 @@ type AgentWidgetReasoning = {
5080
5151
  id: string;
5081
5152
  status: "pending" | "streaming" | "complete";
5082
5153
  chunks: string[];
5154
+ /**
5155
+ * Reasoning channel scope (unified spec). `"turn"` is ordinary per-turn
5156
+ * thinking; `"loop"` is a cross-iteration agent reflection (the fold that
5157
+ * replaced the legacy `agent_reflection` event). Absent for legacy streams.
5158
+ */
5159
+ scope?: "turn" | "loop";
5083
5160
  startedAt?: number;
5084
5161
  completedAt?: number;
5085
5162
  durationMs?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtypelabs/persona",
3
- "version": "3.37.0",
3
+ "version": "4.0.0",
4
4
  "description": "Themeable, pluggable streaming agent widget for websites, in plain JS with support for voice input and reasoning / tool output.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",