@assistant-ui/core 0.3.3 → 0.3.4

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 (127) hide show
  1. package/dist/internal.d.ts +4 -2
  2. package/dist/internal.js +4 -2
  3. package/dist/react/primitive-hooks/useSuggestionTrigger.js +29 -25
  4. package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
  5. package/dist/react/primitives/message/MessageParts.d.ts +6 -1
  6. package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
  7. package/dist/react/primitives/message/MessageParts.js.map +1 -1
  8. package/dist/react/providers/ReadonlyThreadProvider.d.ts.map +1 -1
  9. package/dist/react/providers/ReadonlyThreadProvider.js +1 -0
  10. package/dist/react/providers/ReadonlyThreadProvider.js.map +1 -1
  11. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +67 -0
  12. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
  13. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +76 -15
  14. package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
  15. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +4 -0
  16. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
  17. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +21 -0
  18. package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
  19. package/dist/react/runtimes/cloud/auiV0.d.ts +2 -0
  20. package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
  21. package/dist/react/runtimes/cloud/auiV0.js +6 -4
  22. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  23. package/dist/react/types/MessagePartComponentTypes.d.ts +8 -0
  24. package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
  25. package/dist/runtime/api/bindings.d.ts +5 -0
  26. package/dist/runtime/api/bindings.d.ts.map +1 -1
  27. package/dist/runtime/api/thread-list-runtime.d.ts +14 -1
  28. package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
  29. package/dist/runtime/api/thread-list-runtime.js +6 -1
  30. package/dist/runtime/api/thread-list-runtime.js.map +1 -1
  31. package/dist/runtime/api/thread-runtime.d.ts +7 -1
  32. package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
  33. package/dist/runtime/api/thread-runtime.js +11 -3
  34. package/dist/runtime/api/thread-runtime.js.map +1 -1
  35. package/dist/runtime/base/base-composer-runtime-core.d.ts +3 -0
  36. package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
  37. package/dist/runtime/base/base-composer-runtime-core.js +54 -12
  38. package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
  39. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +10 -0
  40. package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
  41. package/dist/runtime/interfaces/thread-runtime-core.d.ts +14 -0
  42. package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
  43. package/dist/runtimes/external-store/external-store-adapter.d.ts +9 -0
  44. package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
  45. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +1 -0
  46. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
  47. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +4 -0
  48. package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
  49. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +1 -0
  50. package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
  51. package/dist/runtimes/external-store/external-store-thread-runtime-core.js +6 -0
  52. package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
  53. package/dist/runtimes/local/local-thread-runtime-core.d.ts +1 -0
  54. package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
  55. package/dist/runtimes/local/local-thread-runtime-core.js +1 -0
  56. package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
  57. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +1 -0
  58. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
  59. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +1 -0
  60. package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
  61. package/dist/runtimes/remote-thread-list/empty-thread-core.js +1 -0
  62. package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
  63. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts +1 -0
  64. package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
  65. package/dist/store/runtime-clients/thread-list-item-runtime-client.js +66 -45
  66. package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
  67. package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
  68. package/dist/store/runtime-clients/thread-list-runtime-client.js +91 -75
  69. package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
  70. package/dist/store/scopes/thread-list-item.d.ts +7 -0
  71. package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
  72. package/dist/store/scopes/threads.d.ts +1 -0
  73. package/dist/store/scopes/threads.d.ts.map +1 -1
  74. package/dist/types/message.d.ts +11 -0
  75. package/dist/types/message.d.ts.map +1 -1
  76. package/dist/types/message.js.map +1 -1
  77. package/dist/utils/data-url.d.ts +14 -1
  78. package/dist/utils/data-url.d.ts.map +1 -1
  79. package/dist/utils/data-url.js +23 -1
  80. package/dist/utils/data-url.js.map +1 -1
  81. package/dist/utils/image-media-type.d.ts +13 -0
  82. package/dist/utils/image-media-type.d.ts.map +1 -0
  83. package/dist/utils/image-media-type.js +141 -0
  84. package/dist/utils/image-media-type.js.map +1 -0
  85. package/dist/utils/wire-media.d.ts +35 -0
  86. package/dist/utils/wire-media.d.ts.map +1 -0
  87. package/dist/utils/wire-media.js +55 -0
  88. package/dist/utils/wire-media.js.map +1 -0
  89. package/package.json +3 -3
  90. package/src/internal.ts +12 -1
  91. package/src/react/primitive-hooks/useSuggestionTrigger.test.ts +148 -0
  92. package/src/react/primitive-hooks/useSuggestionTrigger.ts +10 -4
  93. package/src/react/primitives/message/MessageParts.tsx +6 -1
  94. package/src/react/providers/ReadonlyThreadProvider.tsx +1 -0
  95. package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +157 -0
  96. package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +160 -0
  97. package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +135 -32
  98. package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +37 -0
  99. package/src/react/runtimes/cloud/auiV0.ts +8 -2
  100. package/src/react/types/MessagePartComponentTypes.ts +8 -0
  101. package/src/runtime/api/bindings.ts +5 -0
  102. package/src/runtime/api/thread-list-runtime.ts +22 -1
  103. package/src/runtime/api/thread-runtime.ts +15 -6
  104. package/src/runtime/base/base-composer-runtime-core.ts +72 -19
  105. package/src/runtime/interfaces/thread-list-runtime-core.ts +11 -0
  106. package/src/runtime/interfaces/thread-runtime-core.ts +15 -0
  107. package/src/runtimes/external-store/external-store-adapter.ts +9 -0
  108. package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +9 -0
  109. package/src/runtimes/external-store/external-store-thread-runtime-core.ts +8 -0
  110. package/src/runtimes/local/local-thread-runtime-core.ts +1 -0
  111. package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +1 -0
  112. package/src/runtimes/remote-thread-list/empty-thread-core.ts +1 -0
  113. package/src/store/runtime-clients/thread-list-item-runtime-client.ts +13 -2
  114. package/src/store/runtime-clients/thread-list-runtime-client.ts +13 -1
  115. package/src/store/scopes/thread-list-item.ts +7 -0
  116. package/src/store/scopes/threads.ts +1 -0
  117. package/src/tests/RemoteThreadListThreadListRuntimeCore-reloadMainThread.test.ts +257 -0
  118. package/src/tests/auiV0Encode.test.ts +125 -1
  119. package/src/tests/base-composer-runtime-core-addAttachment.test.ts +296 -0
  120. package/src/tests/event-subscription-listener-errors.test.ts +1 -0
  121. package/src/tests/external-store-thread-list-runtime-core.test.ts +39 -1
  122. package/src/types/message.ts +11 -0
  123. package/src/utils/data-url.ts +24 -0
  124. package/src/utils/image-media-type.test.ts +96 -0
  125. package/src/utils/image-media-type.ts +118 -0
  126. package/src/utils/wire-media.test.ts +96 -0
  127. package/src/utils/wire-media.ts +70 -0
@@ -7,8 +7,8 @@ import { useClientLookup, useClientResource } from "@assistant-ui/store";
7
7
  import { resource, useResource, withKey } from "@assistant-ui/tap";
8
8
  //#region src/store/runtime-clients/thread-list-runtime-client.ts
9
9
  const useThreadListItemClientById = (t0) => {
10
- const $ = c(5);
11
- const { runtime, id } = t0;
10
+ const $ = c(6);
11
+ const { runtime, id, mainThreadIsRunning } = t0;
12
12
  let t1;
13
13
  if ($[0] !== id || $[1] !== runtime) {
14
14
  t1 = runtime.getItemById(id);
@@ -18,16 +18,20 @@ const useThreadListItemClientById = (t0) => {
18
18
  } else t1 = $[2];
19
19
  const threadListItemRuntime = t1;
20
20
  let t2;
21
- if ($[3] !== threadListItemRuntime) {
22
- t2 = ThreadListItemClient({ runtime: threadListItemRuntime });
23
- $[3] = threadListItemRuntime;
24
- $[4] = t2;
25
- } else t2 = $[4];
21
+ if ($[3] !== mainThreadIsRunning || $[4] !== threadListItemRuntime) {
22
+ t2 = ThreadListItemClient({
23
+ runtime: threadListItemRuntime,
24
+ mainThreadIsRunning
25
+ });
26
+ $[3] = mainThreadIsRunning;
27
+ $[4] = threadListItemRuntime;
28
+ $[5] = t2;
29
+ } else t2 = $[5];
26
30
  return useResource(t2);
27
31
  };
28
32
  const ThreadListItemClientById = resource(useThreadListItemClientById);
29
33
  const useThreadListClient = (t0) => {
30
- const $ = c(40);
34
+ const $ = c(43);
31
35
  const { runtime, __internal_assistantRuntime } = t0;
32
36
  const runtimeState = useSubscribable(runtime);
33
37
  let t1;
@@ -38,19 +42,25 @@ const useThreadListClient = (t0) => {
38
42
  } else t1 = $[1];
39
43
  const main = useClientResource(t1);
40
44
  let t2;
41
- if ($[2] !== runtime || $[3] !== runtimeState.threadItems) {
45
+ if ($[2] !== main.state || $[3] !== runtime || $[4] !== runtimeState.threadItems) {
42
46
  t2 = Object.keys(runtimeState.threadItems).map((id) => withKey(id, ThreadListItemClientById({
43
47
  runtime,
44
- id
45
- }), [runtime, id]));
46
- $[2] = runtime;
47
- $[3] = runtimeState.threadItems;
48
- $[4] = t2;
49
- } else t2 = $[4];
48
+ id,
49
+ mainThreadIsRunning: main.state.isRunning
50
+ }), [
51
+ runtime,
52
+ id,
53
+ main.state.isRunning
54
+ ]));
55
+ $[2] = main.state;
56
+ $[3] = runtime;
57
+ $[4] = runtimeState.threadItems;
58
+ $[5] = t2;
59
+ } else t2 = $[5];
50
60
  const threadItems = useClientLookup(t2);
51
61
  const t3 = runtimeState.newThreadId ?? null;
52
62
  let t4;
53
- if ($[5] !== main.state || $[6] !== runtimeState.archivedThreadIds || $[7] !== runtimeState.hasMore || $[8] !== runtimeState.isLoading || $[9] !== runtimeState.isLoadingMore || $[10] !== runtimeState.mainThreadId || $[11] !== runtimeState.threadIds || $[12] !== t3 || $[13] !== threadItems.state) {
63
+ if ($[6] !== main.state || $[7] !== runtimeState.archivedThreadIds || $[8] !== runtimeState.hasMore || $[9] !== runtimeState.isLoading || $[10] !== runtimeState.isLoadingMore || $[11] !== runtimeState.mainThreadId || $[12] !== runtimeState.threadIds || $[13] !== t3 || $[14] !== threadItems.state) {
54
64
  t4 = {
55
65
  mainThreadId: runtimeState.mainThreadId,
56
66
  newThreadId: t3,
@@ -62,32 +72,32 @@ const useThreadListClient = (t0) => {
62
72
  threadItems: threadItems.state,
63
73
  main: main.state
64
74
  };
65
- $[5] = main.state;
66
- $[6] = runtimeState.archivedThreadIds;
67
- $[7] = runtimeState.hasMore;
68
- $[8] = runtimeState.isLoading;
69
- $[9] = runtimeState.isLoadingMore;
70
- $[10] = runtimeState.mainThreadId;
71
- $[11] = runtimeState.threadIds;
72
- $[12] = t3;
73
- $[13] = threadItems.state;
74
- $[14] = t4;
75
- } else t4 = $[14];
75
+ $[6] = main.state;
76
+ $[7] = runtimeState.archivedThreadIds;
77
+ $[8] = runtimeState.hasMore;
78
+ $[9] = runtimeState.isLoading;
79
+ $[10] = runtimeState.isLoadingMore;
80
+ $[11] = runtimeState.mainThreadId;
81
+ $[12] = runtimeState.threadIds;
82
+ $[13] = t3;
83
+ $[14] = threadItems.state;
84
+ $[15] = t4;
85
+ } else t4 = $[15];
76
86
  const state = t4;
77
87
  let t5;
78
- if ($[15] !== state) {
88
+ if ($[16] !== state) {
79
89
  t5 = () => state;
80
- $[15] = state;
81
- $[16] = t5;
82
- } else t5 = $[16];
90
+ $[16] = state;
91
+ $[17] = t5;
92
+ } else t5 = $[17];
83
93
  let t6;
84
- if ($[17] !== main.methods) {
94
+ if ($[18] !== main.methods) {
85
95
  t6 = () => main.methods;
86
- $[17] = main.methods;
87
- $[18] = t6;
88
- } else t6 = $[18];
96
+ $[18] = main.methods;
97
+ $[19] = t6;
98
+ } else t6 = $[19];
89
99
  let t7;
90
- if ($[19] !== state || $[20] !== threadItems) {
100
+ if ($[20] !== state || $[21] !== threadItems) {
91
101
  t7 = (threadIdOrOptions) => {
92
102
  if (threadIdOrOptions === "main") return threadItems.get({ key: state.mainThreadId });
93
103
  if ("id" in threadIdOrOptions) return threadItems.get({ key: threadIdOrOptions.id });
@@ -95,16 +105,17 @@ const useThreadListClient = (t0) => {
95
105
  const id_0 = (t8 === void 0 ? false : t8) ? state.archivedThreadIds[index] : state.threadIds[index];
96
106
  return threadItems.get({ key: id_0 });
97
107
  };
98
- $[19] = state;
99
- $[20] = threadItems;
100
- $[21] = t7;
101
- } else t7 = $[21];
108
+ $[20] = state;
109
+ $[21] = threadItems;
110
+ $[22] = t7;
111
+ } else t7 = $[22];
102
112
  let t10;
103
113
  let t11;
104
114
  let t12;
115
+ let t13;
105
116
  let t8;
106
117
  let t9;
107
- if ($[22] !== runtime) {
118
+ if ($[23] !== runtime) {
108
119
  t8 = async (threadId, options) => {
109
120
  await runtime.switchToThread(threadId, options);
110
121
  };
@@ -113,29 +124,32 @@ const useThreadListClient = (t0) => {
113
124
  };
114
125
  t10 = () => runtime.getLoadThreadsPromise();
115
126
  t11 = () => runtime.reload();
116
- t12 = () => runtime.loadMore();
117
- $[22] = runtime;
118
- $[23] = t10;
119
- $[24] = t11;
120
- $[25] = t12;
121
- $[26] = t8;
122
- $[27] = t9;
127
+ t12 = () => runtime.reloadMainThread();
128
+ t13 = () => runtime.loadMore();
129
+ $[23] = runtime;
130
+ $[24] = t10;
131
+ $[25] = t11;
132
+ $[26] = t12;
133
+ $[27] = t13;
134
+ $[28] = t8;
135
+ $[29] = t9;
123
136
  } else {
124
- t10 = $[23];
125
- t11 = $[24];
126
- t12 = $[25];
127
- t8 = $[26];
128
- t9 = $[27];
137
+ t10 = $[24];
138
+ t11 = $[25];
139
+ t12 = $[26];
140
+ t13 = $[27];
141
+ t8 = $[28];
142
+ t9 = $[29];
129
143
  }
130
- let t13;
131
- if ($[28] !== __internal_assistantRuntime) {
132
- t13 = () => __internal_assistantRuntime;
133
- $[28] = __internal_assistantRuntime;
134
- $[29] = t13;
135
- } else t13 = $[29];
136
144
  let t14;
137
- if ($[30] !== t10 || $[31] !== t11 || $[32] !== t12 || $[33] !== t13 || $[34] !== t5 || $[35] !== t6 || $[36] !== t7 || $[37] !== t8 || $[38] !== t9) {
138
- t14 = {
145
+ if ($[30] !== __internal_assistantRuntime) {
146
+ t14 = () => __internal_assistantRuntime;
147
+ $[30] = __internal_assistantRuntime;
148
+ $[31] = t14;
149
+ } else t14 = $[31];
150
+ let t15;
151
+ if ($[32] !== t10 || $[33] !== t11 || $[34] !== t12 || $[35] !== t13 || $[36] !== t14 || $[37] !== t5 || $[38] !== t6 || $[39] !== t7 || $[40] !== t8 || $[41] !== t9) {
152
+ t15 = {
139
153
  getState: t5,
140
154
  thread: t6,
141
155
  item: t7,
@@ -143,21 +157,23 @@ const useThreadListClient = (t0) => {
143
157
  switchToNewThread: t9,
144
158
  getLoadThreadsPromise: t10,
145
159
  reload: t11,
146
- loadMore: t12,
147
- __internal_getAssistantRuntime: t13
160
+ reloadMainThread: t12,
161
+ loadMore: t13,
162
+ __internal_getAssistantRuntime: t14
148
163
  };
149
- $[30] = t10;
150
- $[31] = t11;
151
- $[32] = t12;
152
- $[33] = t13;
153
- $[34] = t5;
154
- $[35] = t6;
155
- $[36] = t7;
156
- $[37] = t8;
157
- $[38] = t9;
158
- $[39] = t14;
159
- } else t14 = $[39];
160
- return t14;
164
+ $[32] = t10;
165
+ $[33] = t11;
166
+ $[34] = t12;
167
+ $[35] = t13;
168
+ $[36] = t14;
169
+ $[37] = t5;
170
+ $[38] = t6;
171
+ $[39] = t7;
172
+ $[40] = t8;
173
+ $[41] = t9;
174
+ $[42] = t15;
175
+ } else t15 = $[42];
176
+ return t15;
161
177
  };
162
178
  const ThreadListClient = resource(useThreadListClient);
163
179
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"thread-list-runtime-client.js","names":["useMemo","useResource","withKey","resource","ClientOutput","useClientLookup","useClientResource","ThreadListRuntime","AssistantRuntime","useSubscribable","ThreadListItemClient","ThreadClient","ThreadsState","useThreadListItemClientById","t0","$","_c","runtime","id","t1","getItemById","threadListItemRuntime","t2","ThreadListItemClientById","useThreadListClient","__internal_assistantRuntime","runtimeState","main","threadItems","Object","keys","map","t3","newThreadId","t4","state","archivedThreadIds","hasMore","isLoading","isLoadingMore","mainThreadId","threadIds","t5","t6","methods","t7","threadIdOrOptions","get","key","index","archived","t8","undefined","id_0","t10","t11","t12","t9","threadId","options","switchToThread","switchToNewThread","getLoadThreadsPromise","reload","loadMore","t13","t14","getState","thread","item","__internal_getAssistantRuntime","ThreadListClient"],"sources":["../../../src/store/runtime-clients/thread-list-runtime-client.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { useResource, withKey, resource } from \"@assistant-ui/tap\";\nimport {\n type ClientOutput,\n useClientLookup,\n useClientResource,\n} from \"@assistant-ui/store\";\nimport type { ThreadListRuntime } from \"../../runtime/api/thread-list-runtime\";\nimport type { AssistantRuntime } from \"../../runtime/api/assistant-runtime\";\nimport { useSubscribable } from \"./useSubscribable\";\nimport { ThreadListItemClient } from \"./thread-list-item-runtime-client\";\nimport { ThreadClient } from \"./thread-runtime-client\";\nimport type { ThreadsState } from \"../scopes/threads\";\n\nconst useThreadListItemClientById = ({\n runtime,\n id,\n}: {\n runtime: ThreadListRuntime;\n id: string;\n}) => {\n const threadListItemRuntime = useMemo(\n () => runtime.getItemById(id),\n [runtime, id],\n );\n return useResource(\n ThreadListItemClient({\n runtime: threadListItemRuntime,\n }),\n );\n};\n\nconst ThreadListItemClientById = resource(useThreadListItemClientById);\n\nconst useThreadListClient = ({\n runtime,\n __internal_assistantRuntime,\n}: {\n runtime: ThreadListRuntime;\n __internal_assistantRuntime: AssistantRuntime;\n}): ClientOutput<\"threads\"> => {\n const runtimeState = useSubscribable(runtime);\n\n const main = useClientResource(\n ThreadClient({\n runtime: runtime.main,\n }),\n );\n const threadItems = useClientLookup(\n Object.keys(runtimeState.threadItems).map((id) =>\n withKey(id, ThreadListItemClientById({ runtime, id }), [runtime, id]),\n ),\n );\n\n const state = useMemo<ThreadsState>(() => {\n return {\n mainThreadId: runtimeState.mainThreadId,\n newThreadId: runtimeState.newThreadId ?? null,\n isLoading: runtimeState.isLoading,\n isLoadingMore: runtimeState.isLoadingMore,\n hasMore: runtimeState.hasMore,\n threadIds: runtimeState.threadIds,\n archivedThreadIds: runtimeState.archivedThreadIds,\n threadItems: threadItems.state,\n\n main: main.state,\n };\n }, [runtimeState, threadItems.state, main.state]);\n\n return {\n getState: () => state,\n thread: () => main.methods,\n item: (threadIdOrOptions) => {\n if (threadIdOrOptions === \"main\") {\n return threadItems.get({ key: state.mainThreadId });\n }\n\n if (\"id\" in threadIdOrOptions) {\n return threadItems.get({ key: threadIdOrOptions.id });\n }\n\n const { index, archived = false } = threadIdOrOptions;\n const id = archived\n ? state.archivedThreadIds[index]!\n : state.threadIds[index]!;\n return threadItems.get({ key: id });\n },\n switchToThread: async (threadId, options) => {\n await runtime.switchToThread(threadId, options);\n },\n switchToNewThread: async () => {\n await runtime.switchToNewThread();\n },\n getLoadThreadsPromise: () => runtime.getLoadThreadsPromise(),\n reload: () => runtime.reload(),\n loadMore: () => runtime.loadMore(),\n __internal_getAssistantRuntime: () => __internal_assistantRuntime,\n };\n};\n\nexport const ThreadListClient = resource(useThreadListClient);\n"],"mappings":";;;;;;;;AAcA,MAAMa,+BAA8BC,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAC,SAAAC,OAAAJ;CAMpC,IAAAK;CAAA,IAAAJ,EAAA,OAAAG,MAAAH,EAAA,OAAAE,SAAA;EAESE,KAAAF,QAAOG,YAAaF,EAAE;EAACH,EAAA,KAAAG;EAAAH,EAAA,KAAAE;EAAAF,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAD/B,MAAAM,wBACQF;CAEN,IAAAG;CAAA,IAAAP,EAAA,OAAAM,uBAAA;EAEAC,KAAAZ,qBAAqB,EAAAO,SACVI,sBACX,CAAC;EAACN,EAAA,KAAAM;EAAAN,EAAA,KAAAO;CAAA,OAAAA,KAAAP,EAAA;CAAA,OAHGd,YACLqB,EAGF;AAAC;AAGH,MAAMC,2BAA2BpB,SAASU,2BAA2B;AAErE,MAAMW,uBAAsBV,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAC,MAAA,EAAAC,SAAAQ,gCAAAX;CAO3B,MAAAY,eAAqBjB,gBAAgBQ,OAAO;CAAE,IAAAE;CAAA,IAAAJ,EAAA,OAAAE,QAAAU,MAAA;EAG5CR,KAAAR,aAAa,EAAAM,SACFA,QAAOU,KAClB,CAAC;EAACZ,EAAA,KAAAE,QAAAU;EAAAZ,EAA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vC,QAAO+C,SAAU;EAACjD,EAAA,MAAAE;EAAAF,EAAA,MAAAuC;EAAAvC,EAAA,MAAAwC;EAAAxC,EAAA,MAAAyC;EAAAzC,EAAA,MAAAoC;EAAApC,EAAA,MAAA0C;CAAA,OAAA;EAAAH,MAAAvC,EAAA;EAAAwC,MAAAxC,EAAA;EAAAyC,MAAAzC,EAAA;EAAAoC,KAAApC,EAAA;EAAA0C,KAAA1C,EAAA;CAAA;CAAA,IAAAkD;CAAA,IAAAlD,EAAA,QAAAU,6BAAA;EACFwC,YAAMxC;EAA2BV,EAAA,MAAAU;EAAAV,EAAA,MAAAkD;CAAA,OAAAA,MAAAlD,EAAA;CAAA,IAAAmD;CAAA,IAAAnD,EAAA,QAAAuC,OAAAvC,EAAA,QAAAwC,OAAAxC,EAAA,QAAAyC,OAAAzC,EAAA,QAAAkD,OAAAlD,EAAA,QAAA2B,MAAA3B,EAAA,QAAA4B,MAAA5B,EAAA,QAAA8B,MAAA9B,EAAA,QAAAoC,MAAApC,EAAA,QAAA0C,IAAA;EA3B5DS,MAAA;GAAAC,UACKzB;GAAW0B,QACbzB;GAAkB0B,MACpBxB;GAcLe,gBACeT;GAEfU,mBACkBJ;GAElBK,uBACsBR;GAAqCS,QACpDR;GAAsBS,UACpBR;GAAwBc,gCACFL;EAClC;EAAClD,EAAA,MAAAuC;EAAAvC,EAAA,MAAAwC;EAAAxC,EAAA,MAAAyC;EAAAzC,EAAA,MAAAkD;EAAAlD,EAAA,MAAA2B;EAAA3B,EAAA,MAAA4B;EAAA5B,EAAA,MAAA8B;EAAA9B,EAAA,MAAAoC;EAAApC,EAAA,MAAA0C;EAAA1C,EAAA,MAAAmD;CAAA,OAAAA,MAAAnD,EAAA;CAAA,OA5BMmD;AA4BN;AAGH,MAAaK,mBAAmBpE,SAASqB,mBAAmB"}
1
+ {"version":3,"file":"thread-list-runtime-client.js","names":["useMemo","useResource","withKey","resource","ClientOutput","useClientLookup","useClientResource","ThreadListRuntime","AssistantRuntime","useSubscribable","ThreadListItemClient","ThreadClient","ThreadsState","useThreadListItemClientById","t0","$","_c","runtime","id","mainThreadIsRunning","t1","getItemById","threadListItemRuntime","t2","ThreadListItemClientById","useThreadListClient","__internal_assistantRuntime","runtimeState","main","state","threadItems","Object","keys","map","isRunning","t3","newThreadId","t4","archivedThreadIds","hasMore","isLoading","isLoadingMore","mainThreadId","threadIds","t5","t6","methods","t7","threadIdOrOptions","get","key","index","archived","t8","undefined","id_0","t10","t11","t12","t13","t9","threadId","options","switchToThread","switchToNewThread","getLoadThreadsPromise","reload","reloadMainThread","loadMore","t14","t15","getState","thread","item","__internal_getAssistantRuntime","ThreadListClient"],"sources":["../../../src/store/runtime-clients/thread-list-runtime-client.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { useResource, withKey, resource } from \"@assistant-ui/tap\";\nimport {\n type ClientOutput,\n useClientLookup,\n useClientResource,\n} from \"@assistant-ui/store\";\nimport type { ThreadListRuntime } from \"../../runtime/api/thread-list-runtime\";\nimport type { AssistantRuntime } from \"../../runtime/api/assistant-runtime\";\nimport { useSubscribable } from \"./useSubscribable\";\nimport { ThreadListItemClient } from \"./thread-list-item-runtime-client\";\nimport { ThreadClient } from \"./thread-runtime-client\";\nimport type { ThreadsState } from \"../scopes/threads\";\n\nconst useThreadListItemClientById = ({\n runtime,\n id,\n mainThreadIsRunning,\n}: {\n runtime: ThreadListRuntime;\n id: string;\n mainThreadIsRunning: boolean;\n}) => {\n const threadListItemRuntime = useMemo(\n () => runtime.getItemById(id),\n [runtime, id],\n );\n return useResource(\n ThreadListItemClient({\n runtime: threadListItemRuntime,\n mainThreadIsRunning,\n }),\n );\n};\n\nconst ThreadListItemClientById = resource(useThreadListItemClientById);\n\nconst useThreadListClient = ({\n runtime,\n __internal_assistantRuntime,\n}: {\n runtime: ThreadListRuntime;\n __internal_assistantRuntime: AssistantRuntime;\n}): ClientOutput<\"threads\"> => {\n const runtimeState = useSubscribable(runtime);\n\n const main = useClientResource(\n ThreadClient({\n runtime: runtime.main,\n }),\n );\n const threadItems = useClientLookup(\n Object.keys(runtimeState.threadItems).map((id) =>\n withKey(\n id,\n ThreadListItemClientById({\n runtime,\n id,\n mainThreadIsRunning: main.state.isRunning,\n }),\n [runtime, id, main.state.isRunning],\n ),\n ),\n );\n\n const state = useMemo<ThreadsState>(() => {\n return {\n mainThreadId: runtimeState.mainThreadId,\n newThreadId: runtimeState.newThreadId ?? null,\n isLoading: runtimeState.isLoading,\n isLoadingMore: runtimeState.isLoadingMore,\n hasMore: runtimeState.hasMore,\n threadIds: runtimeState.threadIds,\n archivedThreadIds: runtimeState.archivedThreadIds,\n threadItems: threadItems.state,\n\n main: main.state,\n };\n }, [runtimeState, threadItems.state, main.state]);\n\n return {\n getState: () => state,\n thread: () => main.methods,\n item: (threadIdOrOptions) => {\n if (threadIdOrOptions === \"main\") {\n return threadItems.get({ key: state.mainThreadId });\n }\n\n if (\"id\" in threadIdOrOptions) {\n return threadItems.get({ key: threadIdOrOptions.id });\n }\n\n const { index, archived = false } = threadIdOrOptions;\n const id = archived\n ? state.archivedThreadIds[index]!\n : state.threadIds[index]!;\n return threadItems.get({ key: id });\n },\n switchToThread: async (threadId, options) => {\n await runtime.switchToThread(threadId, options);\n },\n switchToNewThread: async () => {\n await runtime.switchToNewThread();\n },\n getLoadThreadsPromise: () => runtime.getLoadThreadsPromise(),\n reload: () => runtime.reload(),\n reloadMainThread: () => runtime.reloadMainThread(),\n loadMore: () => runtime.loadMore(),\n __internal_getAssistantRuntime: () => __internal_assistantRuntime,\n };\n};\n\nexport const ThreadListClient = resource(useThreadListClient);\n"],"mappings":";;;;;;;;AAcA,MAAMa,+BAA8BC,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAC,SAAAC,IAAAC,wBAAAL;CAQpC,IAAAM;CAAA,IAAAL,EAAA,OAAAG,MAAAH,EAAA,OAAAE,SAAA;EAESG,KAAAH,QAAOI,YAAaH,EAAE;EAACH,EAAA,KAAAG;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EAAA,MAAAsD;CAAA,OAAAA,MAAAtD,EAAA;CAAA,IAAAuD;CAAA,IAAAvD,EAAA,QAAAyC,OAAAzC,EAAA,QAAA0C,OAAA1C,EAAA,QAAA2C,OAAA3C,EAAA,QAAA4C,OAAA5C,EAAA,QAAAsD,OAAAtD,EAAA,QAAA6B,MAAA7B,EAAA,QAAA8B,MAAA9B,EAAA,QAAAgC,MAAAhC,EAAA,QAAAsC,MAAAtC,EAAA,QAAA6C,IAAA;EA5B5DU,MAAA;GAAAC,UACK3B;GAAW4B,QACb3B;GAAkB4B,MACpB1B;GAcLgB,gBACeV;GAEfW,mBACkBJ;GAElBK,uBACsBT;GAAqCU,QACpDT;GAAsBU,kBACZT;GAAgCU,UACxCT;GAAwBe,gCACFL;EAClC;EAACtD,EAAA,MAAAyC;EAAAzC,EAAA,MAAA0C;EAAA1C,EAAA,MAAA2C;EAAA3C,EAAA,MAAA4C;EAAA5C,EAAA,MAAAsD;EAAAtD,EAAA,MAAA6B;EAAA7B,EAAA,MAAA8B;EAAA9B,EAAA,MAAAgC;EAAAhC,EAAA,MAAAsC;EAAAtC,EAAA,MAAA6C;EAAA7C,EAAA,MAAAuD;CAAA,OAAAA,MAAAvD,EAAA;CAAA,OA7BMuD;AA6BN;AAGH,MAAaK,mBAAmBxE,SAASsB,mBAAmB"}
@@ -9,6 +9,13 @@ type ThreadListItemState = {
9
9
  readonly lastMessageAt?: Date | undefined;
10
10
  readonly status: ThreadListItemStatus;
11
11
  readonly custom?: Record<string, unknown> | undefined;
12
+ /**
13
+ * Whether this thread has a run in progress, including a run that continues
14
+ * after the user switches to another thread. A thread list that mounts only
15
+ * the open thread has no runtime to run the others, so they read as not
16
+ * running rather than as unknown.
17
+ */
18
+ readonly isRunning: boolean;
12
19
  };
13
20
  type ThreadListItemMethods = {
14
21
  getState(): ThreadListItemState;
@@ -1 +1 @@
1
- {"version":3,"file":"thread-list-item.d.ts","names":[],"sources":["../../../src/store/scopes/thread-list-item.ts"],"mappings":";;;KAGY;WACD;WACA;WACA;WACA;WACA,gBAAgB;WAChB,QAAQ;WACR,SAAS;;KAGR;EACV,YAAY;EACZ,SAAS;IAAY;;EACrB,OAAO;EACP,aAAa,QAAQ;EACrB;EACA;EACA;EACA;EACA,cAAc;IAAU;IAAkB;;EAC1C;EACA,0BAA0B;;KAGhB;EACV;EACA;IACM;;IACA;IAAY;;IACZ;IAAe;IAAe;;;KAG1B;;;;;;EAMV;IAA+B;;;;;;;EAM/B;IAAiC;;;KAGvB;EACV,SAAS;EACT,MAAM;EACN,QAAQ"}
1
+ {"version":3,"file":"thread-list-item.d.ts","names":[],"sources":["../../../src/store/scopes/thread-list-item.ts"],"mappings":";;;KAGY;WACD;WACA;WACA;WACA;WACA,gBAAgB;WAChB,QAAQ;WACR,SAAS;;;;;;;WAOT;;KAGC;EACV,YAAY;EACZ,SAAS;IAAY;;EACrB,OAAO;EACP,aAAa,QAAQ;EACrB;EACA;EACA;EACA;EACA,cAAc;IAAU;IAAkB;;EAC1C;EACA,0BAA0B;;KAGhB;EACV;EACA;IACM;;IACA;IAAY;;IACZ;IAAe;IAAe;;;KAG1B;;;;;;EAMV;IAA+B;;;;;;;EAM/B;IAAiC;;;KAGvB;EACV,SAAS;EACT,MAAM;EACN,QAAQ"}
@@ -28,6 +28,7 @@ type ThreadsMethods = {
28
28
  thread(selector: "main"): ThreadMethods;
29
29
  getLoadThreadsPromise(): Promise<void>;
30
30
  reload(): Promise<void>;
31
+ reloadMainThread(): Promise<void>;
31
32
  loadMore(): Promise<void>;
32
33
  __internal_getAssistantRuntime?(): AssistantRuntime;
33
34
  };
@@ -1 +1 @@
1
- {"version":3,"file":"threads.d.ts","names":[],"sources":["../../../src/store/scopes/threads.ts"],"mappings":";;;;KAOY;WACD;WACA;WACA;WACA;WACA;WACA;WACA;WACA,sBAAsB;WACtB,MAAM;;KAGL;EACV,YAAY;EACZ,eAAe,kBAAkB;IAAY;;EAC7C;EACA,KACE;IAEM;;IACA;IAAe;MACpB;EACH,OAAO,mBAAmB;EAC1B,yBAAyB;EACzB,UAAU;EACV,YAAY;EACZ,mCAAmC;;KAGzB;EACV,SAAS"}
1
+ {"version":3,"file":"threads.d.ts","names":[],"sources":["../../../src/store/scopes/threads.ts"],"mappings":";;;;KAOY;WACD;WACA;WACA;WACA;WACA;WACA;WACA;WACA,sBAAsB;WACtB,MAAM;;KAGL;EACV,YAAY;EACZ,eAAe,kBAAkB;IAAY;;EAC7C;EACA,KACE;IAEM;;IACA;IAAe;MACpB;EACH,OAAO,mBAAmB;EAC1B,yBAAyB;EACzB,UAAU;EACV,oBAAoB;EACpB,YAAY;EACZ,mCAAmC;;KAGzB;EACV,SAAS"}
@@ -49,8 +49,19 @@ type FileMessagePart = {
49
49
  readonly filename?: string;
50
50
  readonly data: string;
51
51
  readonly mimeType: string;
52
+ /** How `data` goes on the wire: a url or id reference; omitted = inferred (http(s) → url, else base64). "url" is honored by the LangChain-family, A2A, AG-UI, and Google ADK runtimes; "id" by the LangChain family only. */
53
+ readonly sourceType?: "url" | "id";
52
54
  readonly parentId?: string;
53
55
  };
56
+ /**
57
+ * @deprecated Use {@link FileMessagePart} with an `audio/*` mime type. `file`
58
+ * is the carrier for every non-image binary modality: it is a member of both
59
+ * the user and assistant unions, carries a filename, and can declare how its
60
+ * payload goes on the wire, none of which this shape can express. The payload
61
+ * form a `file` part needs is still adapter specific; see the Part Types
62
+ * section of the message primitive docs. Honored everywhere it is accepted; it
63
+ * will not gain fields.
64
+ */
54
65
  type Unstable_AudioMessagePart = {
55
66
  readonly type: "audio";
56
67
  readonly audio: {
@@ -1 +1 @@
1
- {"version":3,"file":"message.d.ts","names":[],"sources":["../../src/types/message.ts"],"mappings":";;;;KASY;YACA,uBAAuB;;KAGvB;WACD;WACA;WACA,SAAS;WACT,mBAAmB;WACnB;;KAGC;WACD;WACA;WACA,SAAS;WACT,mBAAmB;WACnB;;KAGC,yBAAyB;KAEzB;WAEG;WACA;WACA;WACA;WACA;WACA,mBAAmB;WACnB;;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WACA,kBAAkB;WAClB,sBAAsB;WACtB;aACE;aACA;aACA;aACA;aACA;aACA;aACA;aACA,QAAQ;;;KAIT,yBAAyB;WAC1B;WACA,kBAAkB;WAClB,QAAQ;WACR;aACE,gBAAgB;aAChB,+BAA+B;aAC/B,wBAAwB;aACxB,gBAAgB;aAChB;eAA+B;;aAC/B,SAAS;;;;;aAKT;aACA,QAAQ;;;KAIhB;WACM,SAAS;WACT;aACE,iBAAiB;aACjB,gCAAgC;aAChC,yBAAyB;aACzB,iBAAiB;aACjB;eAA+B;;aAC/B,SAAS;aACT;aACA,QAAQ;;WAEV,cAAc;;KAGb,gBAAgB,qBACzB,sBAAsB,oBAAoB;KAEjC,cAAc;KAEd;WACD,SAAS;;KAGR,gBAAgB,KAAK;EAC/B;;EAGA;EACA,WAAW;EACX;;EAEA"}
1
+ {"version":3,"file":"message.d.ts","names":[],"sources":["../../src/types/message.ts"],"mappings":";;;;KASY;YACA,uBAAuB;;KAGvB;WACD;WACA;WACA,SAAS;WACT,mBAAmB;WACnB;;KAGC;WACD;WACA;WACA,SAAS;WACT,mBAAmB;WACnB;;KAGC,yBAAyB;KAEzB;WAEG;WACA;WACA;WACA;WACA;WACA,mBAAmB;WACnB;;WAGA;WACA;WACA;WACA;WACA;WACA;WACA;WACA,mBAAmB;WACnB;;KAGH;WACD;WACA;WACA;;KAGC;WACD;WACA;WACA;WACA;;WAEA;WACA;;;;;;;;;;;KAYC;WACD;WACA;aACE;aACA;;;KAID,gBAAgB;WACjB;WACA;WACA,MAAM;;;;;;;;;;;KAYL;;WAIG;;WAEA,QAAQ;;WAER,oBAAoB;;WAEpB;;;;;KAMH;;WAED,MAAM,4BAA4B;;;;;;;;;;KAWjC;WACD;;WAEA,MAAM;;WAEN;WACA;;KAGC;WACD;WACA;WACA;;WAEA;;cAGE;cAEA,cAAe;KAGhB;WACD,MAAM;;KAGL;KAMA;;WAED;;;;;;;WAOA,MAAM;;WAEN;WACA;;WAEA;;WAEA;IAAsB;IAAgB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R,gBAAgB,KAAK;EAC/B;;EAGA;EACA,WAAW;EACX;;EAEA"}
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","names":["ReadonlyJSONObject","ReadonlyJSONValue","ToolCallTiming","ToolModelContentPart","CompleteAttachment","PartProviderMetadata","providerName","TextMessagePart","type","text","status","MessagePartStreamStatus","providerMetadata","parentId","ReasoningMessagePart","SourceProviderMetadata","SourceMessagePart","sourceType","id","url","title","mediaType","filename","ImageMessagePart","image","FileMessagePart","data","mimeType","Unstable_AudioMessagePart","audio","format","DataMessagePart","name","T","GenerativeUINode","component","props","Record","children","key","GenerativeUISpec","root","GenerativeUIMessagePart","spec","McpAppMetadata","resourceUri","visibility","serverId","MCP_APP_URI_SCHEME","isMcpAppUri","uri","startsWith","ToolCallMessagePartMcpMetadata","app","ToolApprovalOptionKind","ToolApprovalOption","kind","label","description","grants","confirm","ToolApprovalResponse","approved","reason","optionId","ToolCallMessagePart","toolCallId","toolName","args","TArgs","result","TResult","isError","argsText","artifact","timing","mcp","modelContent","interrupt","payload","approval","isAutomatic","options","resolution","messages","ThreadMessage","ThreadUserMessagePart","ThreadAssistantMessagePart","MessagePartStatus","error","ToolCallMessagePartStatus","MessageStatus","MessageTiming","streamStartTime","firstTokenTime","totalStreamTime","tokenCount","tokensPerSecond","totalChunks","toolCallCount","ThreadStep","messageId","usage","inputTokens","outputTokens","MessageCommonProps","createdAt","Date","ThreadSystemMessage","role","content","metadata","unstable_state","unstable_annotations","unstable_data","steps","submittedFeedback","custom","ThreadUserMessage","attachments","isOptimistic","ThreadAssistantMessage","BaseThreadMessage","MessageRole","RunConfig","AppendMessage","Omit","sourceId","runConfig","startRun","steer"],"sources":["../../src/types/message.ts"],"sourcesContent":["import type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ToolCallTiming, ToolModelContentPart } from \"assistant-stream\";\nimport type { CompleteAttachment } from \"./attachment\";\n\nexport type { ToolCallTiming, ToolModelContentPart };\n\nexport type PartProviderMetadata = {\n readonly [providerName: string]: ReadonlyJSONObject;\n};\n\nexport type TextMessagePart = {\n readonly type: \"text\";\n readonly text: string;\n readonly status?: MessagePartStreamStatus;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type ReasoningMessagePart = {\n readonly type: \"reasoning\";\n readonly text: string;\n readonly status?: MessagePartStreamStatus;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type SourceProviderMetadata = PartProviderMetadata;\n\nexport type SourceMessagePart =\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly url?: undefined;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n };\n\nexport type ImageMessagePart = {\n readonly type: \"image\";\n readonly image: string;\n readonly filename?: string;\n};\n\nexport type FileMessagePart = {\n readonly type: \"file\";\n readonly filename?: string;\n readonly data: string;\n readonly mimeType: string;\n readonly parentId?: string;\n};\n\nexport type Unstable_AudioMessagePart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\nexport type DataMessagePart<T = any> = {\n readonly type: \"data\";\n readonly name: string;\n readonly data: T;\n};\n\n/**\n * A JSON spec describing a tree of UI components to render.\n *\n * The agent emits a {@link GenerativeUIMessagePart} containing this spec, and\n * the consumer-provided component allowlist is used to resolve `component`\n * names. Any component referenced that is not present in the allowlist is\n * rejected with a typed error — the allowlist is the security boundary in the\n * default same-realm rendering path.\n */\nexport type GenerativeUINode =\n | string\n | {\n /** Allowlisted component name (resolved against the consumer registry). */\n readonly component: string;\n /** Props passed to the resolved component (must be JSON-serializable). */\n readonly props?: Record<string, unknown>;\n /** Optional children — strings render as text, objects recurse. */\n readonly children?: readonly GenerativeUINode[];\n /** Optional stable key for React reconciliation. */\n readonly key?: string;\n };\n\n/**\n * The root spec for a generative UI tree.\n */\nexport type GenerativeUISpec = {\n /** Root node(s) to render. */\n readonly root: GenerativeUINode | readonly GenerativeUINode[];\n};\n\n/**\n * A message part that carries a JSON spec describing UI to render.\n *\n * Render with `<MessagePrimitive.GenerativeUI components={...} />`. The\n * primitive resolves component names against the consumer-provided allowlist\n * — any unknown name throws a typed error rather than rendering. Stream-\n * friendly: a partially-streamed spec renders progressively.\n */\nexport type GenerativeUIMessagePart = {\n readonly type: \"generative-ui\";\n /** The JSON spec describing the UI tree. */\n readonly spec: GenerativeUISpec;\n /** Optional id (useful for replays / stable keys). */\n readonly id?: string;\n readonly parentId?: string;\n};\n\nexport type McpAppMetadata = {\n readonly resourceUri: string;\n readonly mimeType?: string;\n readonly visibility?: readonly (\"model\" | \"app\")[];\n /** Routable server identity emitted by the agent stack when multiple MCP servers back one agent; for @ag-ui/mcp-apps-middleware this is the configured serverId, falling back to its serverHash. */\n readonly serverId?: string;\n};\n\nexport const MCP_APP_URI_SCHEME = \"ui://\";\n\nexport const isMcpAppUri = (uri: string | undefined): boolean =>\n !!uri?.startsWith(MCP_APP_URI_SCHEME);\n\nexport type ToolCallMessagePartMcpMetadata = {\n readonly app?: McpAppMetadata;\n};\n\nexport type ToolApprovalOptionKind =\n | \"allow-once\"\n | \"allow-always\"\n | \"reject-once\"\n | \"reject-always\";\n\nexport type ToolApprovalOption = {\n /** Opaque, host-defined identifier. Scope semantics (session vs project vs global) belong to the option supplier. */\n readonly id: string;\n /**\n * Decision class. Drives approved-resolution and default rendering.\n * Open union: `_`-prefixed custom kinds are never auto-resolved and the\n * default kit skips them; they must be answered with an explicit\n * `approved` value (optionally alongside the `optionId`).\n */\n readonly kind: ToolApprovalOptionKind | (string & {});\n /** Human label. Renderers supply defaults per kind when omitted. */\n readonly label?: string;\n readonly description?: string;\n /** Patterns or rules this option would persist, shown before the user commits. Supplied by the host; never derived by the library. */\n readonly grants?: readonly string[];\n /** Opt-in confirmation step before this option resolves. */\n readonly confirm?: boolean | { title?: string; description?: string };\n};\n\nexport type ToolApprovalResponse =\n | { readonly approved: boolean; readonly reason?: string }\n | { readonly optionId: string; readonly reason?: string }\n | {\n readonly approved: boolean;\n readonly optionId: string;\n readonly reason?: string;\n };\n\nexport type ToolCallMessagePart<\n TArgs = ReadonlyJSONObject,\n TResult = unknown,\n> = {\n /** Identifies this part as a tool call. */\n readonly type: \"tool-call\";\n /** Stable identifier for this invocation of the tool. */\n readonly toolCallId: string;\n /** Name of the tool requested by the model. */\n readonly toolName: string;\n /**\n * Arguments supplied by the model. During streaming this is a partial parse:\n * fields may be missing or incomplete. From a tool-call renderer, use\n * `useToolArgsStatus` to detect which fields are still arriving.\n */\n readonly args: TArgs;\n /** Result returned by the tool, if it has completed. */\n readonly result?: TResult | undefined;\n /** Whether the result represents a tool execution error. */\n readonly isError?: boolean | undefined;\n /** Raw JSON argument text streamed by the model. */\n readonly argsText: string;\n /** UI-only artifact associated with the tool result. */\n readonly artifact?: unknown;\n /** Wall-clock timing for this call, when the runtime or host tracks it. */\n readonly timing?: ToolCallTiming;\n /** MCP app metadata associated with this tool call, when present. */\n readonly mcp?: ToolCallMessagePartMcpMetadata;\n /** Provider metadata associated with this tool call, when present. */\n readonly providerMetadata?: PartProviderMetadata;\n /** Content returned to the model for this tool result. */\n readonly modelContent?: readonly ToolModelContentPart[] | undefined;\n /** Human-input request that must be resolved before the run can continue. */\n readonly interrupt?: { type: \"human\"; payload: unknown };\n /** Server-side approval gate. `respondToApproval` may only be called while `approved` is undefined and no `resolution` is recorded. */\n readonly approval?: {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n /** Available decisions for this call. Absent: a plain allow / deny pair. */\n readonly options?: readonly ToolApprovalOption[];\n /** The option chosen at resolution, when options were present. */\n readonly optionId?: string;\n /** Terminal non-decision state: the request was cancelled or expired without a user decision. Set by the host. */\n readonly resolution?: \"cancelled\" | \"expired\";\n };\n /** Parent message-part ID when this part belongs to a nested structure. */\n readonly parentId?: string;\n /**\n * Nested thread messages produced by this tool call, for example a sub-agent\n * conversation.\n */\n readonly messages?: readonly ThreadMessage[];\n};\n\nexport type ThreadUserMessagePart =\n | TextMessagePart\n | ImageMessagePart\n | FileMessagePart\n | DataMessagePart\n | Unstable_AudioMessagePart;\n\nexport type ThreadAssistantMessagePart =\n | TextMessagePart\n | ReasoningMessagePart\n | ToolCallMessagePart\n | SourceMessagePart\n | FileMessagePart\n | ImageMessagePart\n | DataMessagePart\n | GenerativeUIMessagePart;\n\nexport type MessagePartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type MessagePartStreamStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n };\n\nexport type ToolCallMessagePartStatus =\n | {\n /** The tool call is waiting for UI or human input before continuing. */\n readonly type: \"requires-action\";\n /** Reason the tool call requires action. */\n readonly reason: \"interrupt\";\n }\n | MessagePartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\" | \"interrupt\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: ReadonlyJSONValue;\n };\n\nexport type MessageTiming = {\n readonly streamStartTime: number;\n readonly firstTokenTime?: number;\n readonly totalStreamTime?: number;\n readonly tokenCount?: number;\n readonly tokensPerSecond?: number;\n readonly totalChunks: number;\n readonly toolCallCount: number;\n};\n\nexport type ThreadStep = {\n readonly messageId?: string;\n readonly usage?:\n | {\n readonly inputTokens: number;\n readonly outputTokens: number;\n }\n | undefined;\n};\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: readonly [TextMessagePart];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: readonly ThreadUserMessagePart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: readonly ThreadAssistantMessagePart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly unstable_state: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n /**\n * Marks a client-side optimistic placeholder. Such messages are evicted\n * once off the head branch and are never persisted.\n */\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations?: readonly ReadonlyJSONValue[];\n readonly unstable_data?: readonly ReadonlyJSONValue[];\n readonly steps?: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\nexport type MessageRole = ThreadMessage[\"role\"];\n\nexport type RunConfig = {\n readonly custom?: Record<string, unknown>;\n};\n\nexport type AppendMessage = Omit<ThreadMessage, \"id\"> & {\n parentId: string | null;\n\n /** The ID of the message that was edited or undefined. */\n sourceId: string | null;\n runConfig: RunConfig | undefined;\n startRun?: boolean | undefined;\n /** Process this message next; only meaningful for queue-capable runtimes. */\n steer?: boolean | undefined;\n};\n"],"mappings":";AAwIA,MAAagD,qBAAqB;AAElC,MAAaC,eAAeC,QAC1B,CAAC,CAACA,KAAKC,WAAWH,kBAAkB"}
1
+ {"version":3,"file":"message.js","names":["ReadonlyJSONObject","ReadonlyJSONValue","ToolCallTiming","ToolModelContentPart","CompleteAttachment","PartProviderMetadata","providerName","TextMessagePart","type","text","status","MessagePartStreamStatus","providerMetadata","parentId","ReasoningMessagePart","SourceProviderMetadata","SourceMessagePart","sourceType","id","url","title","mediaType","filename","ImageMessagePart","image","FileMessagePart","data","mimeType","Unstable_AudioMessagePart","audio","format","DataMessagePart","name","T","GenerativeUINode","component","props","Record","children","key","GenerativeUISpec","root","GenerativeUIMessagePart","spec","McpAppMetadata","resourceUri","visibility","serverId","MCP_APP_URI_SCHEME","isMcpAppUri","uri","startsWith","ToolCallMessagePartMcpMetadata","app","ToolApprovalOptionKind","ToolApprovalOption","kind","label","description","grants","confirm","ToolApprovalResponse","approved","reason","optionId","ToolCallMessagePart","toolCallId","toolName","args","TArgs","result","TResult","isError","argsText","artifact","timing","mcp","modelContent","interrupt","payload","approval","isAutomatic","options","resolution","messages","ThreadMessage","ThreadUserMessagePart","ThreadAssistantMessagePart","MessagePartStatus","error","ToolCallMessagePartStatus","MessageStatus","MessageTiming","streamStartTime","firstTokenTime","totalStreamTime","tokenCount","tokensPerSecond","totalChunks","toolCallCount","ThreadStep","messageId","usage","inputTokens","outputTokens","MessageCommonProps","createdAt","Date","ThreadSystemMessage","role","content","metadata","unstable_state","unstable_annotations","unstable_data","steps","submittedFeedback","custom","ThreadUserMessage","attachments","isOptimistic","ThreadAssistantMessage","BaseThreadMessage","MessageRole","RunConfig","AppendMessage","Omit","sourceId","runConfig","startRun","steer"],"sources":["../../src/types/message.ts"],"sourcesContent":["import type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ToolCallTiming, ToolModelContentPart } from \"assistant-stream\";\nimport type { CompleteAttachment } from \"./attachment\";\n\nexport type { ToolCallTiming, ToolModelContentPart };\n\nexport type PartProviderMetadata = {\n readonly [providerName: string]: ReadonlyJSONObject;\n};\n\nexport type TextMessagePart = {\n readonly type: \"text\";\n readonly text: string;\n readonly status?: MessagePartStreamStatus;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type ReasoningMessagePart = {\n readonly type: \"reasoning\";\n readonly text: string;\n readonly status?: MessagePartStreamStatus;\n readonly providerMetadata?: PartProviderMetadata;\n readonly parentId?: string;\n};\n\nexport type SourceProviderMetadata = PartProviderMetadata;\n\nexport type SourceMessagePart =\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly url?: undefined;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n readonly parentId?: string;\n };\n\nexport type ImageMessagePart = {\n readonly type: \"image\";\n readonly image: string;\n readonly filename?: string;\n};\n\nexport type FileMessagePart = {\n readonly type: \"file\";\n readonly filename?: string;\n readonly data: string;\n readonly mimeType: string;\n /** How `data` goes on the wire: a url or id reference; omitted = inferred (http(s) → url, else base64). \"url\" is honored by the LangChain-family, A2A, AG-UI, and Google ADK runtimes; \"id\" by the LangChain family only. */\n readonly sourceType?: \"url\" | \"id\";\n readonly parentId?: string;\n};\n\n/**\n * @deprecated Use {@link FileMessagePart} with an `audio/*` mime type. `file`\n * is the carrier for every non-image binary modality: it is a member of both\n * the user and assistant unions, carries a filename, and can declare how its\n * payload goes on the wire, none of which this shape can express. The payload\n * form a `file` part needs is still adapter specific; see the Part Types\n * section of the message primitive docs. Honored everywhere it is accepted; it\n * will not gain fields.\n */\nexport type Unstable_AudioMessagePart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\nexport type DataMessagePart<T = any> = {\n readonly type: \"data\";\n readonly name: string;\n readonly data: T;\n};\n\n/**\n * A JSON spec describing a tree of UI components to render.\n *\n * The agent emits a {@link GenerativeUIMessagePart} containing this spec, and\n * the consumer-provided component allowlist is used to resolve `component`\n * names. Any component referenced that is not present in the allowlist is\n * rejected with a typed error — the allowlist is the security boundary in the\n * default same-realm rendering path.\n */\nexport type GenerativeUINode =\n | string\n | {\n /** Allowlisted component name (resolved against the consumer registry). */\n readonly component: string;\n /** Props passed to the resolved component (must be JSON-serializable). */\n readonly props?: Record<string, unknown>;\n /** Optional children — strings render as text, objects recurse. */\n readonly children?: readonly GenerativeUINode[];\n /** Optional stable key for React reconciliation. */\n readonly key?: string;\n };\n\n/**\n * The root spec for a generative UI tree.\n */\nexport type GenerativeUISpec = {\n /** Root node(s) to render. */\n readonly root: GenerativeUINode | readonly GenerativeUINode[];\n};\n\n/**\n * A message part that carries a JSON spec describing UI to render.\n *\n * Render with `<MessagePrimitive.GenerativeUI components={...} />`. The\n * primitive resolves component names against the consumer-provided allowlist\n * — any unknown name throws a typed error rather than rendering. Stream-\n * friendly: a partially-streamed spec renders progressively.\n */\nexport type GenerativeUIMessagePart = {\n readonly type: \"generative-ui\";\n /** The JSON spec describing the UI tree. */\n readonly spec: GenerativeUISpec;\n /** Optional id (useful for replays / stable keys). */\n readonly id?: string;\n readonly parentId?: string;\n};\n\nexport type McpAppMetadata = {\n readonly resourceUri: string;\n readonly mimeType?: string;\n readonly visibility?: readonly (\"model\" | \"app\")[];\n /** Routable server identity emitted by the agent stack when multiple MCP servers back one agent; for @ag-ui/mcp-apps-middleware this is the configured serverId, falling back to its serverHash. */\n readonly serverId?: string;\n};\n\nexport const MCP_APP_URI_SCHEME = \"ui://\";\n\nexport const isMcpAppUri = (uri: string | undefined): boolean =>\n !!uri?.startsWith(MCP_APP_URI_SCHEME);\n\nexport type ToolCallMessagePartMcpMetadata = {\n readonly app?: McpAppMetadata;\n};\n\nexport type ToolApprovalOptionKind =\n | \"allow-once\"\n | \"allow-always\"\n | \"reject-once\"\n | \"reject-always\";\n\nexport type ToolApprovalOption = {\n /** Opaque, host-defined identifier. Scope semantics (session vs project vs global) belong to the option supplier. */\n readonly id: string;\n /**\n * Decision class. Drives approved-resolution and default rendering.\n * Open union: `_`-prefixed custom kinds are never auto-resolved and the\n * default kit skips them; they must be answered with an explicit\n * `approved` value (optionally alongside the `optionId`).\n */\n readonly kind: ToolApprovalOptionKind | (string & {});\n /** Human label. Renderers supply defaults per kind when omitted. */\n readonly label?: string;\n readonly description?: string;\n /** Patterns or rules this option would persist, shown before the user commits. Supplied by the host; never derived by the library. */\n readonly grants?: readonly string[];\n /** Opt-in confirmation step before this option resolves. */\n readonly confirm?: boolean | { title?: string; description?: string };\n};\n\nexport type ToolApprovalResponse =\n | { readonly approved: boolean; readonly reason?: string }\n | { readonly optionId: string; readonly reason?: string }\n | {\n readonly approved: boolean;\n readonly optionId: string;\n readonly reason?: string;\n };\n\nexport type ToolCallMessagePart<\n TArgs = ReadonlyJSONObject,\n TResult = unknown,\n> = {\n /** Identifies this part as a tool call. */\n readonly type: \"tool-call\";\n /** Stable identifier for this invocation of the tool. */\n readonly toolCallId: string;\n /** Name of the tool requested by the model. */\n readonly toolName: string;\n /**\n * Arguments supplied by the model. During streaming this is a partial parse:\n * fields may be missing or incomplete. From a tool-call renderer, use\n * `useToolArgsStatus` to detect which fields are still arriving.\n */\n readonly args: TArgs;\n /** Result returned by the tool, if it has completed. */\n readonly result?: TResult | undefined;\n /** Whether the result represents a tool execution error. */\n readonly isError?: boolean | undefined;\n /** Raw JSON argument text streamed by the model. */\n readonly argsText: string;\n /** UI-only artifact associated with the tool result. */\n readonly artifact?: unknown;\n /** Wall-clock timing for this call, when the runtime or host tracks it. */\n readonly timing?: ToolCallTiming;\n /** MCP app metadata associated with this tool call, when present. */\n readonly mcp?: ToolCallMessagePartMcpMetadata;\n /** Provider metadata associated with this tool call, when present. */\n readonly providerMetadata?: PartProviderMetadata;\n /** Content returned to the model for this tool result. */\n readonly modelContent?: readonly ToolModelContentPart[] | undefined;\n /** Human-input request that must be resolved before the run can continue. */\n readonly interrupt?: { type: \"human\"; payload: unknown };\n /** Server-side approval gate. `respondToApproval` may only be called while `approved` is undefined and no `resolution` is recorded. */\n readonly approval?: {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n /** Available decisions for this call. Absent: a plain allow / deny pair. */\n readonly options?: readonly ToolApprovalOption[];\n /** The option chosen at resolution, when options were present. */\n readonly optionId?: string;\n /** Terminal non-decision state: the request was cancelled or expired without a user decision. Set by the host. */\n readonly resolution?: \"cancelled\" | \"expired\";\n };\n /** Parent message-part ID when this part belongs to a nested structure. */\n readonly parentId?: string;\n /**\n * Nested thread messages produced by this tool call, for example a sub-agent\n * conversation.\n */\n readonly messages?: readonly ThreadMessage[];\n};\n\nexport type ThreadUserMessagePart =\n | TextMessagePart\n | ImageMessagePart\n | FileMessagePart\n | DataMessagePart\n | Unstable_AudioMessagePart;\n\nexport type ThreadAssistantMessagePart =\n | TextMessagePart\n | ReasoningMessagePart\n | ToolCallMessagePart\n | SourceMessagePart\n | FileMessagePart\n | ImageMessagePart\n | DataMessagePart\n | GenerativeUIMessagePart;\n\nexport type MessagePartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type MessagePartStreamStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n };\n\nexport type ToolCallMessagePartStatus =\n | {\n /** The tool call is waiting for UI or human input before continuing. */\n readonly type: \"requires-action\";\n /** Reason the tool call requires action. */\n readonly reason: \"interrupt\";\n }\n | MessagePartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\" | \"interrupt\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: ReadonlyJSONValue;\n };\n\nexport type MessageTiming = {\n readonly streamStartTime: number;\n readonly firstTokenTime?: number;\n readonly totalStreamTime?: number;\n readonly tokenCount?: number;\n readonly tokensPerSecond?: number;\n readonly totalChunks: number;\n readonly toolCallCount: number;\n};\n\nexport type ThreadStep = {\n readonly messageId?: string;\n readonly usage?:\n | {\n readonly inputTokens: number;\n readonly outputTokens: number;\n }\n | undefined;\n};\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: readonly [TextMessagePart];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: readonly ThreadUserMessagePart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly unstable_state?: undefined;\n readonly unstable_annotations?: undefined;\n readonly unstable_data?: undefined;\n readonly steps?: undefined;\n readonly submittedFeedback?: undefined;\n readonly timing?: undefined;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: readonly ThreadAssistantMessagePart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly unstable_state: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n /**\n * Marks a client-side optimistic placeholder. Such messages are evicted\n * once off the head branch and are never persisted.\n */\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations?: readonly ReadonlyJSONValue[];\n readonly unstable_data?: readonly ReadonlyJSONValue[];\n readonly steps?: readonly ThreadStep[];\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly timing?: MessageTiming;\n readonly isOptimistic?: boolean;\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\nexport type MessageRole = ThreadMessage[\"role\"];\n\nexport type RunConfig = {\n readonly custom?: Record<string, unknown>;\n};\n\nexport type AppendMessage = Omit<ThreadMessage, \"id\"> & {\n parentId: string | null;\n\n /** The ID of the message that was edited or undefined. */\n sourceId: string | null;\n runConfig: RunConfig | undefined;\n startRun?: boolean | undefined;\n /** Process this message next; only meaningful for queue-capable runtimes. */\n steer?: boolean | undefined;\n};\n"],"mappings":";AAmJA,MAAagD,qBAAqB;AAElC,MAAaC,eAAeC,QAC1B,CAAC,CAACA,KAAKC,WAAWH,kBAAkB"}
@@ -4,6 +4,19 @@ declare function parseDataUrl(value: string): {
4
4
  mimeType: string;
5
5
  data: string;
6
6
  } | null;
7
+ /**
8
+ * Whether a payload is something `new URL()` accepts. Adapters that place a
9
+ * `FileMessagePart` payload into a url-typed wire field use this to decide
10
+ * whether it has to be wrapped in a data URL envelope first; base64 cannot
11
+ * contain a colon, so a real payload is never misread as a url.
12
+ */
13
+ declare function isParsableUrl(value: string): boolean;
14
+ /**
15
+ * The media type a data URL declares, whether or not its payload is base64.
16
+ * `parseDataUrl` only matches base64 payloads because it also returns the
17
+ * bytes; this reads the declaration alone.
18
+ */
19
+ declare function dataUrlMediaType(value: string): string | undefined;
7
20
  //#endregion
8
- export { httpUrlPattern, parseDataUrl };
21
+ export { dataUrlMediaType, httpUrlPattern, isParsableUrl, parseDataUrl };
9
22
  //# sourceMappingURL=data-url.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"data-url.d.ts","names":[],"sources":["../../src/utils/data-url.ts"],"mappings":";cAAa,gBAAc;iBAEX,aACd;EACG;EAAkB"}
1
+ {"version":3,"file":"data-url.d.ts","names":[],"sources":["../../src/utils/data-url.ts"],"mappings":";cAAa,gBAAc;iBAEX,aACd;EACG;EAAkB;;;;;;;;iBAYP,cAAc;;;;;;iBAcd,iBAAiB"}
@@ -8,7 +8,29 @@ function parseDataUrl(value) {
8
8
  data: match[2]
9
9
  };
10
10
  }
11
+ /**
12
+ * Whether a payload is something `new URL()` accepts. Adapters that place a
13
+ * `FileMessagePart` payload into a url-typed wire field use this to decide
14
+ * whether it has to be wrapped in a data URL envelope first; base64 cannot
15
+ * contain a colon, so a real payload is never misread as a url.
16
+ */
17
+ function isParsableUrl(value) {
18
+ try {
19
+ new URL(value);
20
+ return true;
21
+ } catch {
22
+ return false;
23
+ }
24
+ }
25
+ /**
26
+ * The media type a data URL declares, whether or not its payload is base64.
27
+ * `parseDataUrl` only matches base64 payloads because it also returns the
28
+ * bytes; this reads the declaration alone.
29
+ */
30
+ function dataUrlMediaType(value) {
31
+ return /^data:([^;,]+)(?:[;,])/i.exec(value)?.[1]?.toLowerCase();
32
+ }
11
33
  //#endregion
12
- export { httpUrlPattern, parseDataUrl };
34
+ export { dataUrlMediaType, httpUrlPattern, isParsableUrl, parseDataUrl };
13
35
 
14
36
  //# sourceMappingURL=data-url.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"data-url.js","names":["httpUrlPattern","parseDataUrl","value","mimeType","data","match","toLowerCase"],"sources":["../../src/utils/data-url.ts"],"sourcesContent":["export const httpUrlPattern = /^https?:\\/\\//i;\n\nexport function parseDataUrl(\n value: string,\n): { mimeType: string; data: string } | null {\n const match = value.match(/^data:([^;,]+)(?:;[^;,]+)*;base64,(.*)$/i);\n if (!match) return null;\n return { mimeType: match[1]!.toLowerCase(), data: match[2]! };\n}\n"],"mappings":";AAAA,MAAaA,iBAAiB;AAE9B,SAAgBC,aACdC,OAC2C;CAC3C,MAAMG,QAAQH,MAAMG,MAAM,0CAA0C;CACpE,IAAI,CAACA,OAAO,OAAO;CACnB,OAAO;EAAEF,UAAUE,MAAM,EAAE,CAAEC,YAAY;EAAGF,MAAMC,MAAM;CAAI;AAC9D"}
1
+ {"version":3,"file":"data-url.js","names":["httpUrlPattern","parseDataUrl","value","mimeType","data","match","toLowerCase","isParsableUrl","URL","dataUrlMediaType","exec"],"sources":["../../src/utils/data-url.ts"],"sourcesContent":["export const httpUrlPattern = /^https?:\\/\\//i;\n\nexport function parseDataUrl(\n value: string,\n): { mimeType: string; data: string } | null {\n const match = value.match(/^data:([^;,]+)(?:;[^;,]+)*;base64,(.*)$/i);\n if (!match) return null;\n return { mimeType: match[1]!.toLowerCase(), data: match[2]! };\n}\n\n/**\n * Whether a payload is something `new URL()` accepts. Adapters that place a\n * `FileMessagePart` payload into a url-typed wire field use this to decide\n * whether it has to be wrapped in a data URL envelope first; base64 cannot\n * contain a colon, so a real payload is never misread as a url.\n */\nexport function isParsableUrl(value: string): boolean {\n try {\n new URL(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * The media type a data URL declares, whether or not its payload is base64.\n * `parseDataUrl` only matches base64 payloads because it also returns the\n * bytes; this reads the declaration alone.\n */\nexport function dataUrlMediaType(value: string): string | undefined {\n return /^data:([^;,]+)(?:[;,])/i.exec(value)?.[1]?.toLowerCase();\n}\n"],"mappings":";AAAA,MAAaA,iBAAiB;AAE9B,SAAgBC,aACdC,OAC2C;CAC3C,MAAMG,QAAQH,MAAMG,MAAM,0CAA0C;CACpE,IAAI,CAACA,OAAO,OAAO;CACnB,OAAO;EAAEF,UAAUE,MAAM,EAAE,CAAEC,YAAY;EAAGF,MAAMC,MAAM;CAAI;AAC9D;;;;;;;AAQA,SAAgBE,cAAcL,OAAwB;CACpD,IAAI;EACF,IAAIM,IAAIN,KAAK;EACb,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;;;;AAOA,SAAgBO,iBAAiBP,OAAmC;CAClE,OAAO,0BAA0BQ,KAAKR,KAAK,CAAC,GAAG,EAAE,EAAEI,YAAY;AACjE"}
@@ -0,0 +1,13 @@
1
+ //#region src/utils/image-media-type.d.ts
2
+ /**
3
+ * The image media type a base64 payload's leading bytes identify, or
4
+ * `undefined` when they match no known signature or the input is not base64.
5
+ *
6
+ * An `ImageMessagePart` carries no media type, so an adapter that must declare
7
+ * one on the wire reads it from the bytes rather than assuming a format. Never
8
+ * throws: the input is whatever a caller put on the part.
9
+ */
10
+ declare function detectImageMediaType(base64: string): string | undefined;
11
+ //#endregion
12
+ export { detectImageMediaType };
13
+ //# sourceMappingURL=image-media-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-media-type.d.ts","names":[],"sources":["../../src/utils/image-media-type.ts"],"mappings":";;;;;;;;;iBA4GgB,qBAAqB"}