@agentscope-ai/chat 1.1.37 → 1.1.38-beta.1764311106381

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 (145) hide show
  1. package/components/AgentScopeRuntimeWebUI/index.tsx +2 -2
  2. package/components/AgentScopeRuntimeWebUI/starter/sessionApi/index.ts +1 -1
  3. package/components/ChatAnywhere/Input/index.tsx +110 -0
  4. package/components/Sender/index.tsx +18 -6
  5. package/components/index.ts +1 -1
  6. package/lib/AgentScopeRuntimeWebUI/index.d.ts +2 -2
  7. package/lib/AgentScopeRuntimeWebUI/index.js +2 -2
  8. package/lib/AgentScopeRuntimeWebUI/starter/sessionApi/index.d.ts +1 -1
  9. package/lib/ChatAnywhere/Input/index.js +132 -1
  10. package/lib/Sender/index.js +24 -5
  11. package/lib/index.d.ts +1 -1
  12. package/lib/index.js +1 -1
  13. package/package.json +2 -2
  14. /package/components/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Request/Builder.tsx +0 -0
  15. /package/components/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Request/Card.tsx +0 -0
  16. /package/components/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Actions.tsx +0 -0
  17. /package/components/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Builder.tsx +0 -0
  18. /package/components/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Card.tsx +0 -0
  19. /package/components/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Error.tsx +0 -0
  20. /package/components/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Message.tsx +0 -0
  21. /package/components/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Reasoning.tsx +0 -0
  22. /package/components/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Tool.tsx +0 -0
  23. /package/components/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/index.tsx +0 -0
  24. /package/components/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/types.tsx +0 -0
  25. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Chat/Input/index.tsx +0 -0
  26. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Chat/Input/useAttachments.tsx +0 -0
  27. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Chat/MessageList/index.tsx +0 -0
  28. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Chat/Welcome/index.tsx +0 -0
  29. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Chat/Welcome/styles.ts +0 -0
  30. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/index.tsx +0 -0
  31. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/useChatController.tsx +0 -0
  32. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/useChatMessageHandler.tsx +0 -0
  33. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/useChatRequest.tsx +0 -0
  34. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/useChatSessionHandler.tsx +0 -0
  35. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Chat/index.tsx +0 -0
  36. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Chat/styles.tsx +0 -0
  37. /package/components/AgentScopeRuntimeWebUI/{lib → core}/ChatAnywhere/ComposedProvider.tsx +0 -0
  38. /package/components/AgentScopeRuntimeWebUI/{lib → core}/ChatAnywhere/index.tsx +0 -0
  39. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereControl.tsx +0 -0
  40. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereInputContext.tsx +0 -0
  41. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereLayoutContext.tsx +0 -0
  42. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereMessagesContext.tsx +0 -0
  43. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereOptionsContext.tsx +0 -0
  44. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereSessionsContext.tsx +0 -0
  45. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Context/useChatAnywhereEventEmitter.tsx +0 -0
  46. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Header/index.tsx +0 -0
  47. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Header/styles.ts +0 -0
  48. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Layout/index.tsx +0 -0
  49. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Layout/styles.tsx +0 -0
  50. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Sessions/index.tsx +0 -0
  51. /package/components/AgentScopeRuntimeWebUI/{lib → core}/Sessions/styles.tsx +0 -0
  52. /package/components/AgentScopeRuntimeWebUI/{lib → core}/demo/OptionsPanel/FormItem.tsx +0 -0
  53. /package/components/AgentScopeRuntimeWebUI/{lib → core}/demo/OptionsPanel/OptionsEditor.tsx +0 -0
  54. /package/components/AgentScopeRuntimeWebUI/{lib → core}/demo/OptionsPanel/defaultConfig.ts +0 -0
  55. /package/components/AgentScopeRuntimeWebUI/{lib → core}/demo/OptionsPanel/index.tsx +0 -0
  56. /package/components/AgentScopeRuntimeWebUI/{lib → core}/demo/index.tsx +0 -0
  57. /package/components/AgentScopeRuntimeWebUI/{lib → core}/demo/sessionApi/index.ts +0 -0
  58. /package/components/AgentScopeRuntimeWebUI/{lib → core}/types/IChatAnywhere.ts +0 -0
  59. /package/components/AgentScopeRuntimeWebUI/{lib → core}/types/IMessages.tsx +0 -0
  60. /package/components/AgentScopeRuntimeWebUI/{lib → core}/types/ISessions.tsx +0 -0
  61. /package/components/AgentScopeRuntimeWebUI/{lib → core}/types/index.tsx +0 -0
  62. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Request/Builder.d.ts +0 -0
  63. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Request/Builder.js +0 -0
  64. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Request/Card.d.ts +0 -0
  65. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Request/Card.js +0 -0
  66. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Actions.d.ts +0 -0
  67. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Actions.js +0 -0
  68. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Builder.d.ts +0 -0
  69. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Builder.js +0 -0
  70. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Card.d.ts +0 -0
  71. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Card.js +0 -0
  72. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Error.d.ts +0 -0
  73. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Error.js +0 -0
  74. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Message.d.ts +0 -0
  75. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Message.js +0 -0
  76. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Reasoning.d.ts +0 -0
  77. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Reasoning.js +0 -0
  78. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Tool.d.ts +0 -0
  79. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/Response/Tool.js +0 -0
  80. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/index.d.ts +0 -0
  81. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/index.js +0 -0
  82. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/types.d.ts +0 -0
  83. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/AgentScopeRuntime/types.js +0 -0
  84. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/Input/index.d.ts +0 -0
  85. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/Input/index.js +0 -0
  86. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/Input/useAttachments.d.ts +0 -0
  87. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/Input/useAttachments.js +0 -0
  88. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/MessageList/index.d.ts +0 -0
  89. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/MessageList/index.js +0 -0
  90. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/Welcome/index.d.ts +0 -0
  91. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/Welcome/index.js +0 -0
  92. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/Welcome/styles.d.ts +0 -0
  93. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/Welcome/styles.js +0 -0
  94. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/index.d.ts +0 -0
  95. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/index.js +0 -0
  96. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/useChatController.d.ts +0 -0
  97. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/useChatController.js +0 -0
  98. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/useChatMessageHandler.d.ts +0 -0
  99. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/useChatMessageHandler.js +0 -0
  100. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/useChatRequest.d.ts +0 -0
  101. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/useChatRequest.js +0 -0
  102. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/useChatSessionHandler.d.ts +0 -0
  103. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/hooks/useChatSessionHandler.js +0 -0
  104. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/index.d.ts +0 -0
  105. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/index.js +0 -0
  106. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/styles.d.ts +0 -0
  107. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Chat/styles.js +0 -0
  108. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/ChatAnywhere/ComposedProvider.d.ts +0 -0
  109. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/ChatAnywhere/ComposedProvider.js +0 -0
  110. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/ChatAnywhere/index.d.ts +0 -0
  111. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/ChatAnywhere/index.js +0 -0
  112. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereControl.d.ts +0 -0
  113. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereControl.js +0 -0
  114. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereInputContext.d.ts +0 -0
  115. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereInputContext.js +0 -0
  116. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereLayoutContext.d.ts +0 -0
  117. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereLayoutContext.js +0 -0
  118. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereMessagesContext.d.ts +0 -0
  119. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereMessagesContext.js +0 -0
  120. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereOptionsContext.d.ts +0 -0
  121. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereOptionsContext.js +0 -0
  122. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereSessionsContext.d.ts +0 -0
  123. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/ChatAnywhereSessionsContext.js +0 -0
  124. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/useChatAnywhereEventEmitter.d.ts +0 -0
  125. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Context/useChatAnywhereEventEmitter.js +0 -0
  126. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Header/index.d.ts +0 -0
  127. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Header/index.js +0 -0
  128. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Header/styles.d.ts +0 -0
  129. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Header/styles.js +0 -0
  130. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Layout/index.d.ts +0 -0
  131. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Layout/index.js +0 -0
  132. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Layout/styles.d.ts +0 -0
  133. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Layout/styles.js +0 -0
  134. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Sessions/index.d.ts +0 -0
  135. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Sessions/index.js +0 -0
  136. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Sessions/styles.d.ts +0 -0
  137. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/Sessions/styles.js +0 -0
  138. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/types/IChatAnywhere.d.ts +0 -0
  139. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/types/IChatAnywhere.js +0 -0
  140. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/types/IMessages.d.ts +0 -0
  141. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/types/IMessages.js +0 -0
  142. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/types/ISessions.d.ts +0 -0
  143. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/types/ISessions.js +0 -0
  144. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/types/index.d.ts +0 -0
  145. /package/lib/AgentScopeRuntimeWebUI/{lib → core}/types/index.js +0 -0
@@ -1,3 +1,3 @@
1
- export { default } from './lib/ChatAnywhere';
1
+ export { default } from './core/ChatAnywhere';
2
2
  export { default as Demo } from './starter';
3
- export * from './lib/types';
3
+ export * from './core/types';
@@ -1,5 +1,5 @@
1
1
  import { IAgentScopeRuntimeWebUISessionAPI } from '@agentscope-ai/chat';
2
- import { IAgentScopeRuntimeWebUISession } from '../../lib/types/ISessions';
2
+ import { IAgentScopeRuntimeWebUISession } from '../../core/types/ISessions';
3
3
 
4
4
  class SessionApi implements IAgentScopeRuntimeWebUISessionAPI {
5
5
  private lsKey: string;
@@ -111,7 +111,115 @@ export default forwardRef(function (_, ref) {
111
111
  const submitFileList = attachedFiles.map(files => files.filter(file => file.status === 'done'));
112
112
  const fileLoading = attachedFiles.some(files => files.some(file => file.status === 'uploading'));
113
113
 
114
+ const handlePasteFile = (file: File) => {
115
+ if (!onUpload?.length) return;
114
116
 
117
+ const fileType = file.type || '';
118
+ const fileName = file.name || '';
119
+
120
+ // Match file type with accept pattern
121
+ const matchAcceptType = (accept?: string) => {
122
+ if (!accept) return true;
123
+
124
+ return accept.split(',').some(type => {
125
+ const trimmed = type.trim();
126
+ if (!trimmed) return false;
127
+
128
+ // Extension: .jpg, .png
129
+ if (trimmed.startsWith('.')) {
130
+ return fileName.toLowerCase().endsWith(trimmed.toLowerCase());
131
+ }
132
+
133
+ // Wildcard: image/*, */*
134
+ if (trimmed.includes('*')) {
135
+ if (trimmed === '*/*') return true;
136
+ const [acceptMain] = trimmed.split('/');
137
+ const [fileMain] = fileType.split('/');
138
+ return acceptMain === fileMain;
139
+ }
140
+
141
+ // Exact: image/jpeg
142
+ return fileType === trimmed;
143
+ });
144
+ };
145
+
146
+ // Find matching upload config
147
+ const uploadIndex = onUpload.findIndex(config => matchAcceptType(config.accept));
148
+ if (uploadIndex === -1) return;
149
+
150
+ const uploadConfig = onUpload[uploadIndex];
151
+
152
+ // Validate before upload
153
+ if (uploadConfig.beforeUpload) {
154
+ const result = uploadConfig.beforeUpload(file as any, [file as any]);
155
+ if (result === false) return;
156
+ }
157
+
158
+ // Extract extension from filename or MIME type
159
+ const getExtension = () => {
160
+ const nameMatch = fileName.match(/\.([^.]+)$/);
161
+ if (nameMatch) return nameMatch[1].toLowerCase();
162
+
163
+ const typeMatch = fileType.match(/\/([^/+]+)/);
164
+ return typeMatch ? typeMatch[1].toLowerCase() : 'bin';
165
+ };
166
+
167
+ // Create upload file object
168
+ const timestamp = Date.now();
169
+ const uploadFile: any = {
170
+ uid: `paste_${timestamp}_${Math.random().toString(36).slice(2, 11)}`,
171
+ name: fileName || `pasted-${timestamp}.${getExtension()}`,
172
+ size: file.size,
173
+ type: fileType,
174
+ status: 'uploading',
175
+ percent: 0,
176
+ originFileObj: file,
177
+ };
178
+
179
+ // Update file in list
180
+ const updateFile = (updates: any) => {
181
+ setAttachedFiles(prev => {
182
+ const updated = [...prev];
183
+ updated[uploadIndex] = (updated[uploadIndex] || []).map(f =>
184
+ f.uid === uploadFile.uid ? { ...f, ...updates } as any : f
185
+ );
186
+ return updated;
187
+ });
188
+ };
189
+
190
+ // Add file to list first
191
+ setAttachedFiles(prev => {
192
+ const updated = [...prev];
193
+ updated[uploadIndex] = [...(updated[uploadIndex] || []), uploadFile];
194
+ return updated;
195
+ });
196
+
197
+ // Handle image preview (async, don't block upload)
198
+ if (fileType && fileType.startsWith('image/')) {
199
+ const reader = new FileReader();
200
+ reader.onload = (e) => {
201
+ const result = e.target?.result;
202
+ if (typeof result === 'string') {
203
+ updateFile({ thumbUrl: result, url: result });
204
+ }
205
+ };
206
+ reader.readAsDataURL(file);
207
+ }
208
+
209
+ // Trigger upload via customRequest
210
+ uploadConfig.customRequest({
211
+ file: file as any,
212
+ onSuccess: (response: any) => {
213
+ updateFile({ status: 'done', response, percent: 100 });
214
+ },
215
+ onError: (error: any) => {
216
+ updateFile({ status: 'error', error });
217
+ },
218
+ onProgress: (event: any) => {
219
+ updateFile({ percent: event.percent });
220
+ },
221
+ } as any);
222
+ };
115
223
 
116
224
  return <>
117
225
  <Style />
@@ -149,6 +257,8 @@ export default forwardRef(function (_, ref) {
149
257
  onStop?.();
150
258
  inputContext.setLoading(false);
151
259
  }}
260
+ // @ts-ignore
261
+ onPasteFile={handlePasteFile}
152
262
  loading={inputContext.loading}
153
263
  />
154
264
  {
@@ -333,14 +333,26 @@ const ForwardSender = React.forwardRef<SenderRef, SenderProps>((props, ref) => {
333
333
  };
334
334
 
335
335
  const onInternalPaste: React.ClipboardEventHandler<HTMLElement> = (e) => {
336
- // Get file
337
- const file = e.clipboardData?.files[0];
338
- if (file && onPasteFile) {
339
- onPasteFile(file);
340
- e.preventDefault();
336
+ if (!onPasteFile) {
337
+ onPaste?.(e);
338
+ return;
341
339
  }
342
340
 
343
- onPaste?.(e);
341
+ // Try to get files from clipboardData.files
342
+ let files = Array.from(e.clipboardData?.files || []);
343
+ if (files.length === 0) {
344
+ const items = Array.from(e.clipboardData?.items || []);
345
+ files = items
346
+ .filter(item => item.kind === 'file')
347
+ .map(item => item.getAsFile())
348
+ .filter((file): file is File => file !== null);
349
+ }
350
+ if (files.length > 0) {
351
+ files.forEach(file => onPasteFile(file));
352
+ e.preventDefault();
353
+ } else {
354
+ onPaste?.(e);
355
+ }
344
356
  };
345
357
 
346
358
  // ============================ Focus =============================
@@ -30,7 +30,7 @@ export type { ChatAnywhereRef, TMessage, TSession } from './ChatAnywhere';
30
30
  export * as DefaultCards from './DefaultCards';
31
31
 
32
32
  export { default as AgentScopeRuntimeWebUI } from './AgentScopeRuntimeWebUI';
33
- export * from './AgentScopeRuntimeWebUI/lib/types';
33
+ export * from './AgentScopeRuntimeWebUI/core/types';
34
34
 
35
35
  export {
36
36
  Accordion,
@@ -1,3 +1,3 @@
1
- export { default } from './lib/ChatAnywhere';
1
+ export { default } from './core/ChatAnywhere';
2
2
  export { default as Demo } from './starter';
3
- export * from './lib/types';
3
+ export * from './core/types';
@@ -1,3 +1,3 @@
1
- export { default } from "./lib/ChatAnywhere";
1
+ export { default } from "./core/ChatAnywhere";
2
2
  export { default as Demo } from "./starter";
3
- export * from "./lib/types";
3
+ export * from "./core/types";
@@ -1,5 +1,5 @@
1
1
  import { IAgentScopeRuntimeWebUISessionAPI } from "../../..";
2
- import { IAgentScopeRuntimeWebUISession } from '../../lib/types/ISessions';
2
+ import { IAgentScopeRuntimeWebUISession } from '../../core/types/ISessions';
3
3
  declare class SessionApi implements IAgentScopeRuntimeWebUISessionAPI {
4
4
  private lsKey;
5
5
  private sessionList;
@@ -1,4 +1,8 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
2
6
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
7
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
8
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -141,6 +145,130 @@ export default /*#__PURE__*/forwardRef(function (_, ref) {
141
145
  return file.status === 'uploading';
142
146
  });
143
147
  });
148
+ var handlePasteFile = function handlePasteFile(file) {
149
+ if (!(onUpload !== null && onUpload !== void 0 && onUpload.length)) return;
150
+ var fileType = file.type || '';
151
+ var fileName = file.name || '';
152
+
153
+ // Match file type with accept pattern
154
+ var matchAcceptType = function matchAcceptType(accept) {
155
+ if (!accept) return true;
156
+ return accept.split(',').some(function (type) {
157
+ var trimmed = type.trim();
158
+ if (!trimmed) return false;
159
+
160
+ // Extension: .jpg, .png
161
+ if (trimmed.startsWith('.')) {
162
+ return fileName.toLowerCase().endsWith(trimmed.toLowerCase());
163
+ }
164
+
165
+ // Wildcard: image/*, */*
166
+ if (trimmed.includes('*')) {
167
+ if (trimmed === '*/*') return true;
168
+ var _trimmed$split = trimmed.split('/'),
169
+ _trimmed$split2 = _slicedToArray(_trimmed$split, 1),
170
+ acceptMain = _trimmed$split2[0];
171
+ var _fileType$split = fileType.split('/'),
172
+ _fileType$split2 = _slicedToArray(_fileType$split, 1),
173
+ fileMain = _fileType$split2[0];
174
+ return acceptMain === fileMain;
175
+ }
176
+
177
+ // Exact: image/jpeg
178
+ return fileType === trimmed;
179
+ });
180
+ };
181
+
182
+ // Find matching upload config
183
+ var uploadIndex = onUpload.findIndex(function (config) {
184
+ return matchAcceptType(config.accept);
185
+ });
186
+ if (uploadIndex === -1) return;
187
+ var uploadConfig = onUpload[uploadIndex];
188
+
189
+ // Validate before upload
190
+ if (uploadConfig.beforeUpload) {
191
+ var result = uploadConfig.beforeUpload(file, [file]);
192
+ if (result === false) return;
193
+ }
194
+
195
+ // Extract extension from filename or MIME type
196
+ var getExtension = function getExtension() {
197
+ var nameMatch = fileName.match(/\.([^.]+)$/);
198
+ if (nameMatch) return nameMatch[1].toLowerCase();
199
+ var typeMatch = fileType.match(/\/([^/+]+)/);
200
+ return typeMatch ? typeMatch[1].toLowerCase() : 'bin';
201
+ };
202
+
203
+ // Create upload file object
204
+ var timestamp = Date.now();
205
+ var uploadFile = {
206
+ uid: "paste_".concat(timestamp, "_").concat(Math.random().toString(36).slice(2, 11)),
207
+ name: fileName || "pasted-".concat(timestamp, ".").concat(getExtension()),
208
+ size: file.size,
209
+ type: fileType,
210
+ status: 'uploading',
211
+ percent: 0,
212
+ originFileObj: file
213
+ };
214
+
215
+ // Update file in list
216
+ var updateFile = function updateFile(updates) {
217
+ setAttachedFiles(function (prev) {
218
+ var updated = _toConsumableArray(prev);
219
+ updated[uploadIndex] = (updated[uploadIndex] || []).map(function (f) {
220
+ return f.uid === uploadFile.uid ? _objectSpread(_objectSpread({}, f), updates) : f;
221
+ });
222
+ return updated;
223
+ });
224
+ };
225
+
226
+ // Add file to list first
227
+ setAttachedFiles(function (prev) {
228
+ var updated = _toConsumableArray(prev);
229
+ updated[uploadIndex] = [].concat(_toConsumableArray(updated[uploadIndex] || []), [uploadFile]);
230
+ return updated;
231
+ });
232
+
233
+ // Handle image preview (async, don't block upload)
234
+ if (fileType && fileType.startsWith('image/')) {
235
+ var reader = new FileReader();
236
+ reader.onload = function (e) {
237
+ var _e$target;
238
+ var result = (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.result;
239
+ if (typeof result === 'string') {
240
+ updateFile({
241
+ thumbUrl: result,
242
+ url: result
243
+ });
244
+ }
245
+ };
246
+ reader.readAsDataURL(file);
247
+ }
248
+
249
+ // Trigger upload via customRequest
250
+ uploadConfig.customRequest({
251
+ file: file,
252
+ onSuccess: function onSuccess(response) {
253
+ updateFile({
254
+ status: 'done',
255
+ response: response,
256
+ percent: 100
257
+ });
258
+ },
259
+ onError: function onError(error) {
260
+ updateFile({
261
+ status: 'error',
262
+ error: error
263
+ });
264
+ },
265
+ onProgress: function onProgress(event) {
266
+ updateFile({
267
+ percent: event.percent
268
+ });
269
+ }
270
+ });
271
+ };
144
272
  return /*#__PURE__*/_jsxs(_Fragment, {
145
273
  children: [/*#__PURE__*/_jsx(Style, {}), /*#__PURE__*/_jsxs("div", {
146
274
  className: cls("".concat(prefixCls, "-wrapper")),
@@ -191,7 +319,10 @@ export default /*#__PURE__*/forwardRef(function (_, ref) {
191
319
  onCancel: function onCancel() {
192
320
  onStop === null || onStop === void 0 || onStop();
193
321
  inputContext.setLoading(false);
194
- },
322
+ }
323
+ // @ts-ignore
324
+ ,
325
+ onPasteFile: handlePasteFile,
195
326
  loading: inputContext.loading
196
327
  }), onInput.afterUI]
197
328
  })]
@@ -176,13 +176,32 @@ var ForwardSender = /*#__PURE__*/React.forwardRef(function (props, ref) {
176
176
  };
177
177
  var onInternalPaste = function onInternalPaste(e) {
178
178
  var _e$clipboardData;
179
- // Get file
180
- var file = (_e$clipboardData = e.clipboardData) === null || _e$clipboardData === void 0 ? void 0 : _e$clipboardData.files[0];
181
- if (file && onPasteFile) {
182
- onPasteFile(file);
179
+ if (!onPasteFile) {
180
+ onPaste === null || onPaste === void 0 || onPaste(e);
181
+ return;
182
+ }
183
+
184
+ // Try to get files from clipboardData.files
185
+ var files = Array.from(((_e$clipboardData = e.clipboardData) === null || _e$clipboardData === void 0 ? void 0 : _e$clipboardData.files) || []);
186
+ if (files.length === 0) {
187
+ var _e$clipboardData2;
188
+ var items = Array.from(((_e$clipboardData2 = e.clipboardData) === null || _e$clipboardData2 === void 0 ? void 0 : _e$clipboardData2.items) || []);
189
+ files = items.filter(function (item) {
190
+ return item.kind === 'file';
191
+ }).map(function (item) {
192
+ return item.getAsFile();
193
+ }).filter(function (file) {
194
+ return file !== null;
195
+ });
196
+ }
197
+ if (files.length > 0) {
198
+ files.forEach(function (file) {
199
+ return onPasteFile(file);
200
+ });
183
201
  e.preventDefault();
202
+ } else {
203
+ onPaste === null || onPaste === void 0 || onPaste(e);
184
204
  }
185
- onPaste === null || onPaste === void 0 || onPaste(e);
186
205
  };
187
206
 
188
207
  // ============================ Focus =============================
package/lib/index.d.ts CHANGED
@@ -10,7 +10,7 @@ export { default as ChatAnywhere, useChatAnywhere, useInput, useMessages, useSes
10
10
  export type { ChatAnywhereRef, TMessage, TSession } from './ChatAnywhere';
11
11
  export * as DefaultCards from './DefaultCards';
12
12
  export { default as AgentScopeRuntimeWebUI } from './AgentScopeRuntimeWebUI';
13
- export * from './AgentScopeRuntimeWebUI/lib/types';
13
+ export * from './AgentScopeRuntimeWebUI/core/types';
14
14
  export { Accordion, Accordion as Process, type IAccordionProps, type IAccordionProps as IProcess, } from './Accordion';
15
15
  export { default as DeepThink, default as DeepThinking, type IDeepThinking, } from './Accordion/DeepThinking';
16
16
  export { default as Attachments, type AttachmentsProps, type AttachmentsProps as IAttachmentsProps, } from './Attachments';
package/lib/index.js CHANGED
@@ -9,7 +9,7 @@ export { default as ChatAnywhere, useChatAnywhere, useInput, useMessages, useSes
9
9
  import * as _DefaultCards from "./DefaultCards";
10
10
  export { _DefaultCards as DefaultCards };
11
11
  export { default as AgentScopeRuntimeWebUI } from "./AgentScopeRuntimeWebUI";
12
- export * from "./AgentScopeRuntimeWebUI/lib/types";
12
+ export * from "./AgentScopeRuntimeWebUI/core/types";
13
13
  export { Accordion, Accordion as Process } from "./Accordion";
14
14
  export { default as DeepThink, default as DeepThinking } from "./Accordion/DeepThinking";
15
15
  export { default as Attachments } from "./Attachments";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentscope-ai/chat",
3
- "version": "1.1.37",
3
+ "version": "1.1.38-beta.1764311106381",
4
4
  "description": "a free and open-source chat framework for building excellent LLM-powered chat experiences",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": [
@@ -31,7 +31,7 @@
31
31
  "lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
32
32
  "lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
33
33
  "llms:build": "LLM=true dumi build",
34
- "prepare": "husky install && dumi setup",
34
+ "prepare": "dumi setup",
35
35
  "src:build": "father build",
36
36
  "start": "npm run dev"
37
37
  },