@chat-lab/ui 0.1.0-beta.64 → 0.1.0-beta.66
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.
- package/dist/components/Chatkit/index.cjs +68 -61
- package/dist/components/Chatkit/index.cjs.map +1 -1
- package/dist/components/Chatkit/index.d.ts.map +1 -1
- package/dist/components/Chatkit/index.js +68 -61
- package/dist/components/Chatkit/index.js.map +1 -1
- package/dist/components/assistant-ui/thread.cjs +38 -16
- package/dist/components/assistant-ui/thread.cjs.map +1 -1
- package/dist/components/assistant-ui/thread.d.ts.map +1 -1
- package/dist/components/assistant-ui/thread.js +38 -16
- package/dist/components/assistant-ui/thread.js.map +1 -1
- package/dist/core/dist/index.cjs +3 -1
- package/dist/core/dist/index.cjs.map +1 -1
- package/dist/core/dist/index.js +3 -1
- package/dist/core/dist/index.js.map +1 -1
- package/dist/hooks/useClawChat/convertHistoryMessage.cjs +41 -22
- package/dist/hooks/useClawChat/convertHistoryMessage.cjs.map +1 -1
- package/dist/hooks/useClawChat/convertHistoryMessage.d.ts.map +1 -1
- package/dist/hooks/useClawChat/convertHistoryMessage.js +41 -22
- package/dist/hooks/useClawChat/convertHistoryMessage.js.map +1 -1
- package/dist/hooks/useClawChat/index.cjs +9 -3
- package/dist/hooks/useClawChat/index.cjs.map +1 -1
- package/dist/hooks/useClawChat/index.d.ts.map +1 -1
- package/dist/hooks/useClawChat/index.js +11 -5
- package/dist/hooks/useClawChat/index.js.map +1 -1
- package/dist/hooks/useClawChat/types.cjs.map +1 -1
- package/dist/hooks/useClawChat/types.d.ts +4 -2
- package/dist/hooks/useClawChat/types.d.ts.map +1 -1
- package/dist/hooks/useClawChat/types.js.map +1 -1
- package/dist/index.css +1 -1
- package/dist/utils/convertToAssistantMessage.cjs +2 -2
- package/dist/utils/convertToAssistantMessage.cjs.map +1 -1
- package/dist/utils/convertToAssistantMessage.d.ts.map +1 -1
- package/dist/utils/convertToAssistantMessage.js +2 -2
- package/dist/utils/convertToAssistantMessage.js.map +1 -1
- package/package.json +1 -1
|
@@ -42,28 +42,47 @@ const getStatus = (item) => {
|
|
|
42
42
|
return index.MessageStatus.ABORTED;
|
|
43
43
|
return item.errorMessage ? index.MessageStatus.ERROR : index.MessageStatus.SUCCESS;
|
|
44
44
|
};
|
|
45
|
-
const convertHistoryMessage = (history) =>
|
|
46
|
-
|
|
47
|
-
history.payload.messages.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
45
|
+
const convertHistoryMessage = (history) => {
|
|
46
|
+
const result = [];
|
|
47
|
+
history.payload.messages.forEach((item, index$1) => {
|
|
48
|
+
// 如果是 assistant 或 toolResult,且上一条也是 assistant,合并到同一个 message
|
|
49
|
+
const isAssistantContent = item.role === 'assistant' || item.role === 'toolResult';
|
|
50
|
+
if (isAssistantContent && result.length > 0) {
|
|
51
|
+
const lastMessage = result[result.length - 1];
|
|
52
|
+
if (lastMessage.role === 'assistant') {
|
|
53
|
+
// 将当前内容添加到上一条 assistant 消息的 content 中
|
|
54
|
+
const newContent = item.content.map(convertInnerContentToMessage);
|
|
55
|
+
lastMessage.content = [...lastMessage.content, ...newContent];
|
|
56
|
+
// 更新状态(如果有错误,使用错误状态)
|
|
57
|
+
const status = getStatus(item);
|
|
58
|
+
if (status === index.MessageStatus.ERROR) {
|
|
59
|
+
lastMessage.status = status;
|
|
60
|
+
lastMessage.error = item.errorMessage;
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const status = getStatus(item);
|
|
66
|
+
result.push({
|
|
67
|
+
id: `${history.id}-${index$1}`,
|
|
68
|
+
role: item.role === 'toolResult' ? 'assistant' : item.role,
|
|
69
|
+
threadId: history.payload.sessionId || history.payload.sessionKey,
|
|
70
|
+
metadata: {
|
|
71
|
+
api: item.api,
|
|
72
|
+
provider: item.provider,
|
|
73
|
+
model: item.model,
|
|
74
|
+
stopReason: item.stopReason,
|
|
75
|
+
errorMessage: item.errorMessage,
|
|
76
|
+
},
|
|
77
|
+
status: getStatus(item),
|
|
78
|
+
error: status === index.MessageStatus.ERROR ? item.errorMessage : undefined,
|
|
79
|
+
content: item.content.map(convertInnerContentToMessage),
|
|
80
|
+
createdAt: item.timestamp || Date.now(),
|
|
81
|
+
updatedAt: item.timestamp || Date.now(),
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
67
86
|
|
|
68
87
|
module.exports = convertHistoryMessage;
|
|
69
88
|
//# sourceMappingURL=convertHistoryMessage.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertHistoryMessage.cjs","sources":["../../../src/hooks/useClawChat/convertHistoryMessage.ts"],"sourcesContent":["import { ChatMessage, MessageStatus } from '@chat-lab/core';\nimport {\n PushHistory,\n TextContent,\n ThinkContent,\n ToolCallContent,\n ToolResultContent,\n} from './types';\n\nconst convertInnerContentToMessage = (\n innerContent:\n | TextContent\n | ThinkContent\n | ToolCallContent\n | ToolResultContent,\n): ChatMessage['content'][number] => {\n switch (innerContent.type) {\n case 'text':\n return {\n type: 'text',\n text: innerContent.text,\n };\n case 'thinking':\n return {\n type: 'reasoning',\n text: innerContent.thinking,\n };\n case 'toolCall':\n return {\n type: 'tool_call',\n toolCallId: innerContent.id,\n toolCallName: innerContent.name,\n toolCallArgs: innerContent.arguments,\n content: null,\n };\n case 'toolResult':\n return {\n type: 'tool_call',\n toolCallId: innerContent.toolCallId,\n toolCallName: innerContent.toolName,\n toolCallArgs: {},\n content: innerContent.content.map((c) => c.text).join(''),\n };\n default:\n return {\n type: 'text',\n text: '',\n };\n }\n};\n\nconst getStatus = (item: PushHistory['payload']['messages'][number]) => {\n if (item.stopReason === 'aborted') return MessageStatus.ABORTED;\n return item.errorMessage ? MessageStatus.ERROR : MessageStatus.SUCCESS;\n};\n\nconst convertHistoryMessage = (history: PushHistory): ChatMessage[]
|
|
1
|
+
{"version":3,"file":"convertHistoryMessage.cjs","sources":["../../../src/hooks/useClawChat/convertHistoryMessage.ts"],"sourcesContent":["import { ChatMessage, MessageStatus } from '@chat-lab/core';\nimport {\n PushHistory,\n TextContent,\n ThinkContent,\n ToolCallContent,\n ToolResultContent,\n} from './types';\n\nconst convertInnerContentToMessage = (\n innerContent:\n | TextContent\n | ThinkContent\n | ToolCallContent\n | ToolResultContent,\n): ChatMessage['content'][number] => {\n switch (innerContent.type) {\n case 'text':\n return {\n type: 'text',\n text: innerContent.text,\n };\n case 'thinking':\n return {\n type: 'reasoning',\n text: innerContent.thinking,\n };\n case 'toolCall':\n return {\n type: 'tool_call',\n toolCallId: innerContent.id,\n toolCallName: innerContent.name,\n toolCallArgs: innerContent.arguments,\n content: null,\n };\n case 'toolResult':\n return {\n type: 'tool_call',\n toolCallId: innerContent.toolCallId,\n toolCallName: innerContent.toolName,\n toolCallArgs: {},\n content: innerContent.content.map((c) => c.text).join(''),\n };\n default:\n return {\n type: 'text',\n text: '',\n };\n }\n};\n\nconst getStatus = (item: PushHistory['payload']['messages'][number]) => {\n if (item.stopReason === 'aborted') return MessageStatus.ABORTED;\n return item.errorMessage ? MessageStatus.ERROR : MessageStatus.SUCCESS;\n};\n\nconst convertHistoryMessage = (history: PushHistory): ChatMessage[] => {\n const result: ChatMessage[] = [];\n\n history.payload.messages.forEach((item, index) => {\n // 如果是 assistant 或 toolResult,且上一条也是 assistant,合并到同一个 message\n const isAssistantContent = item.role === 'assistant' || item.role === 'toolResult';\n if (isAssistantContent && result.length > 0) {\n const lastMessage = result[result.length - 1];\n if (lastMessage.role === 'assistant') {\n // 将当前内容添加到上一条 assistant 消息的 content 中\n const newContent = item.content.map(convertInnerContentToMessage);\n lastMessage.content = [...lastMessage.content, ...newContent];\n // 更新状态(如果有错误,使用错误状态)\n const status = getStatus(item);\n if (status === MessageStatus.ERROR) {\n lastMessage.status = status;\n lastMessage.error = item.errorMessage;\n }\n return;\n }\n }\n\n const status = getStatus(item);\n result.push({\n id: `${history.id}-${index}`,\n role: item.role === 'toolResult' ? 'assistant' : item.role,\n threadId: history.payload.sessionId || history.payload.sessionKey,\n metadata: {\n api: item.api,\n provider: item.provider,\n model: item.model,\n stopReason: item.stopReason,\n errorMessage: item.errorMessage,\n },\n status: getStatus(item),\n error: status === MessageStatus.ERROR ? item.errorMessage : undefined,\n content: item.content.map(convertInnerContentToMessage),\n createdAt: item.timestamp || Date.now(),\n updatedAt: item.timestamp || Date.now(),\n });\n });\n\n return result;\n};\nexport default convertHistoryMessage;\n"],"names":["MessageStatus","index"],"mappings":";;;;AASA,MAAM,4BAA4B,GAAG,CACnC,YAIqB,KACa;AAClC,IAAA,QAAQ,YAAY,CAAC,IAAI;AACvB,QAAA,KAAK,MAAM;YACT,OAAO;AACL,gBAAA,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,YAAY,CAAC,IAAI;aACxB,CAAC;AACJ,QAAA,KAAK,UAAU;YACb,OAAO;AACL,gBAAA,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,YAAY,CAAC,QAAQ;aAC5B,CAAC;AACJ,QAAA,KAAK,UAAU;YACb,OAAO;AACL,gBAAA,IAAI,EAAE,WAAW;gBACjB,UAAU,EAAE,YAAY,CAAC,EAAE;gBAC3B,YAAY,EAAE,YAAY,CAAC,IAAI;gBAC/B,YAAY,EAAE,YAAY,CAAC,SAAS;AACpC,gBAAA,OAAO,EAAE,IAAI;aACd,CAAC;AACJ,QAAA,KAAK,YAAY;YACf,OAAO;AACL,gBAAA,IAAI,EAAE,WAAW;gBACjB,UAAU,EAAE,YAAY,CAAC,UAAU;gBACnC,YAAY,EAAE,YAAY,CAAC,QAAQ;AACnC,gBAAA,YAAY,EAAE,EAA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|
|
|
1
|
-
{"version":3,"file":"convertHistoryMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/useClawChat/convertHistoryMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,WAAW,EAKZ,MAAM,SAAS,CAAC;AAiDjB,QAAA,MAAM,qBAAqB,GAAI,SAAS,WAAW,KAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"convertHistoryMessage.d.ts","sourceRoot":"","sources":["../../../src/hooks/useClawChat/convertHistoryMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,WAAW,EAKZ,MAAM,SAAS,CAAC;AAiDjB,QAAA,MAAM,qBAAqB,GAAI,SAAS,WAAW,KAAG,WAAW,EA2ChE,CAAC;AACF,eAAe,qBAAqB,CAAC"}
|
|
@@ -40,28 +40,47 @@ const getStatus = (item) => {
|
|
|
40
40
|
return MessageStatus.ABORTED;
|
|
41
41
|
return item.errorMessage ? MessageStatus.ERROR : MessageStatus.SUCCESS;
|
|
42
42
|
};
|
|
43
|
-
const convertHistoryMessage = (history) =>
|
|
44
|
-
|
|
45
|
-
history.payload.messages.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
43
|
+
const convertHistoryMessage = (history) => {
|
|
44
|
+
const result = [];
|
|
45
|
+
history.payload.messages.forEach((item, index) => {
|
|
46
|
+
// 如果是 assistant 或 toolResult,且上一条也是 assistant,合并到同一个 message
|
|
47
|
+
const isAssistantContent = item.role === 'assistant' || item.role === 'toolResult';
|
|
48
|
+
if (isAssistantContent && result.length > 0) {
|
|
49
|
+
const lastMessage = result[result.length - 1];
|
|
50
|
+
if (lastMessage.role === 'assistant') {
|
|
51
|
+
// 将当前内容添加到上一条 assistant 消息的 content 中
|
|
52
|
+
const newContent = item.content.map(convertInnerContentToMessage);
|
|
53
|
+
lastMessage.content = [...lastMessage.content, ...newContent];
|
|
54
|
+
// 更新状态(如果有错误,使用错误状态)
|
|
55
|
+
const status = getStatus(item);
|
|
56
|
+
if (status === MessageStatus.ERROR) {
|
|
57
|
+
lastMessage.status = status;
|
|
58
|
+
lastMessage.error = item.errorMessage;
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const status = getStatus(item);
|
|
64
|
+
result.push({
|
|
65
|
+
id: `${history.id}-${index}`,
|
|
66
|
+
role: item.role === 'toolResult' ? 'assistant' : item.role,
|
|
67
|
+
threadId: history.payload.sessionId || history.payload.sessionKey,
|
|
68
|
+
metadata: {
|
|
69
|
+
api: item.api,
|
|
70
|
+
provider: item.provider,
|
|
71
|
+
model: item.model,
|
|
72
|
+
stopReason: item.stopReason,
|
|
73
|
+
errorMessage: item.errorMessage,
|
|
74
|
+
},
|
|
75
|
+
status: getStatus(item),
|
|
76
|
+
error: status === MessageStatus.ERROR ? item.errorMessage : undefined,
|
|
77
|
+
content: item.content.map(convertInnerContentToMessage),
|
|
78
|
+
createdAt: item.timestamp || Date.now(),
|
|
79
|
+
updatedAt: item.timestamp || Date.now(),
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
65
84
|
|
|
66
85
|
export { convertHistoryMessage as default };
|
|
67
86
|
//# sourceMappingURL=convertHistoryMessage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertHistoryMessage.js","sources":["../../../src/hooks/useClawChat/convertHistoryMessage.ts"],"sourcesContent":["import { ChatMessage, MessageStatus } from '@chat-lab/core';\nimport {\n PushHistory,\n TextContent,\n ThinkContent,\n ToolCallContent,\n ToolResultContent,\n} from './types';\n\nconst convertInnerContentToMessage = (\n innerContent:\n | TextContent\n | ThinkContent\n | ToolCallContent\n | ToolResultContent,\n): ChatMessage['content'][number] => {\n switch (innerContent.type) {\n case 'text':\n return {\n type: 'text',\n text: innerContent.text,\n };\n case 'thinking':\n return {\n type: 'reasoning',\n text: innerContent.thinking,\n };\n case 'toolCall':\n return {\n type: 'tool_call',\n toolCallId: innerContent.id,\n toolCallName: innerContent.name,\n toolCallArgs: innerContent.arguments,\n content: null,\n };\n case 'toolResult':\n return {\n type: 'tool_call',\n toolCallId: innerContent.toolCallId,\n toolCallName: innerContent.toolName,\n toolCallArgs: {},\n content: innerContent.content.map((c) => c.text).join(''),\n };\n default:\n return {\n type: 'text',\n text: '',\n };\n }\n};\n\nconst getStatus = (item: PushHistory['payload']['messages'][number]) => {\n if (item.stopReason === 'aborted') return MessageStatus.ABORTED;\n return item.errorMessage ? MessageStatus.ERROR : MessageStatus.SUCCESS;\n};\n\nconst convertHistoryMessage = (history: PushHistory): ChatMessage[]
|
|
1
|
+
{"version":3,"file":"convertHistoryMessage.js","sources":["../../../src/hooks/useClawChat/convertHistoryMessage.ts"],"sourcesContent":["import { ChatMessage, MessageStatus } from '@chat-lab/core';\nimport {\n PushHistory,\n TextContent,\n ThinkContent,\n ToolCallContent,\n ToolResultContent,\n} from './types';\n\nconst convertInnerContentToMessage = (\n innerContent:\n | TextContent\n | ThinkContent\n | ToolCallContent\n | ToolResultContent,\n): ChatMessage['content'][number] => {\n switch (innerContent.type) {\n case 'text':\n return {\n type: 'text',\n text: innerContent.text,\n };\n case 'thinking':\n return {\n type: 'reasoning',\n text: innerContent.thinking,\n };\n case 'toolCall':\n return {\n type: 'tool_call',\n toolCallId: innerContent.id,\n toolCallName: innerContent.name,\n toolCallArgs: innerContent.arguments,\n content: null,\n };\n case 'toolResult':\n return {\n type: 'tool_call',\n toolCallId: innerContent.toolCallId,\n toolCallName: innerContent.toolName,\n toolCallArgs: {},\n content: innerContent.content.map((c) => c.text).join(''),\n };\n default:\n return {\n type: 'text',\n text: '',\n };\n }\n};\n\nconst getStatus = (item: PushHistory['payload']['messages'][number]) => {\n if (item.stopReason === 'aborted') return MessageStatus.ABORTED;\n return item.errorMessage ? MessageStatus.ERROR : MessageStatus.SUCCESS;\n};\n\nconst convertHistoryMessage = (history: PushHistory): ChatMessage[] => {\n const result: ChatMessage[] = [];\n\n history.payload.messages.forEach((item, index) => {\n // 如果是 assistant 或 toolResult,且上一条也是 assistant,合并到同一个 message\n const isAssistantContent = item.role === 'assistant' || item.role === 'toolResult';\n if (isAssistantContent && result.length > 0) {\n const lastMessage = result[result.length - 1];\n if (lastMessage.role === 'assistant') {\n // 将当前内容添加到上一条 assistant 消息的 content 中\n const newContent = item.content.map(convertInnerContentToMessage);\n lastMessage.content = [...lastMessage.content, ...newContent];\n // 更新状态(如果有错误,使用错误状态)\n const status = getStatus(item);\n if (status === MessageStatus.ERROR) {\n lastMessage.status = status;\n lastMessage.error = item.errorMessage;\n }\n return;\n }\n }\n\n const status = getStatus(item);\n result.push({\n id: `${history.id}-${index}`,\n role: item.role === 'toolResult' ? 'assistant' : item.role,\n threadId: history.payload.sessionId || history.payload.sessionKey,\n metadata: {\n api: item.api,\n provider: item.provider,\n model: item.model,\n stopReason: item.stopReason,\n errorMessage: item.errorMessage,\n },\n status: getStatus(item),\n error: status === MessageStatus.ERROR ? item.errorMessage : undefined,\n content: item.content.map(convertInnerContentToMessage),\n createdAt: item.timestamp || Date.now(),\n updatedAt: item.timestamp || Date.now(),\n });\n });\n\n return result;\n};\nexport default convertHistoryMessage;\n"],"names":[],"mappings":";;AASA,MAAM,4BAA4B,GAAG,CACnC,YAIqB,KACa;AAClC,IAAA,QAAQ,YAAY,CAAC,IAAI;AACvB,QAAA,KAAK,MAAM;YACT,OAAO;AACL,gBAAA,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,YAAY,CAAC,IAAI;aACxB,CAAC;AACJ,QAAA,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AE,IAAI,CAAC,YAAY;AAChC,aAAA;AACD,YAAA,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC;AACvB,YAAA,KAAK,EAAE,MAAM,KAAK,aAAa,CAAC,KAAK,GAAG,IAAI,CAAC,YAAY,GAAG,SAAS;YACrE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC;YACvD,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE;YACvC,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE;AACxC,SAAA,CAAC,CAAC;AACL,KAAC,CAAC,CAAC;AAEH,IAAA,OAAO,MAAM,CAAC;AAChB;;;;"}
|
|
@@ -18,7 +18,6 @@ var convertHistoryMessage = require('./convertHistoryMessage.cjs');
|
|
|
18
18
|
const useClawChat = ({ onAction, onAbort, }) => {
|
|
19
19
|
const controllerRef = React.useRef(null);
|
|
20
20
|
const currentRunIdRef = React.useRef(null);
|
|
21
|
-
const [clawChatStatus, setClawChatStatus] = React.useState('idle');
|
|
22
21
|
const pushMessageImplRef = React.useRef(() => { });
|
|
23
22
|
/**
|
|
24
23
|
* 推送消息到 Chat 组件
|
|
@@ -99,14 +98,21 @@ const useClawChat = ({ onAction, onAbort, }) => {
|
|
|
99
98
|
protocolAdaptor: clawProtocolAdaptor,
|
|
100
99
|
},
|
|
101
100
|
storeManager,
|
|
101
|
+
metaData: index.createMetaData({
|
|
102
|
+
clawStatus: { status: false, reason: 'uninitialized' },
|
|
103
|
+
}),
|
|
102
104
|
});
|
|
103
105
|
}
|
|
106
|
+
const handleClawChatStatus = ahooks.useMemoizedFn((status) => {
|
|
107
|
+
if (controllerRef.current) {
|
|
108
|
+
controllerRef.current.metaData.clawStatus = status;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
104
111
|
return {
|
|
105
112
|
controllerRef,
|
|
106
113
|
pushMessage,
|
|
107
114
|
pushHistory,
|
|
108
|
-
setClawChatStatus,
|
|
109
|
-
clawChatStatus,
|
|
115
|
+
setClawChatStatus: handleClawChatStatus,
|
|
110
116
|
};
|
|
111
117
|
};
|
|
112
118
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../src/hooks/useClawChat/index.ts"],"sourcesContent":["import {\n ChatController,\n createThreadManagerStateWithDefault,\n ThreadMessageManager,\n ProtocolEnum,\n} from '@chat-lab/core';\nimport { useRef, useState } from 'react';\nimport { useMemoizedFn } from 'ahooks';\nimport {\n UseClawChatReturn,\n OnAction,\n ClawChatStatus,\n PushMessageImpl,\n PushHistory,\n isPushStreamStart,\n isPushStreamDone,\n isPushStreamError,\n isPushStreamAborted,\n} from './types';\nimport { createClawCompletion } from './clawCompletion';\nimport ClawProtocolAdaptor from './ClawProtocolAdaptor';\nimport convertHistoryMessage from './convertHistoryMessage';\n\nexport * from './types';\nexport { default as ClawProtocolAdaptor } from './ClawProtocolAdaptor';\nexport * from './ClawProtocolAdaptor';\n\n/**\n * useClawChat Hook\n * 用于与 ClawClient 进行双向通信\n *\n * @param onAction - 处理来自 Chat 组件的用户操作\n * @returns {UseClawChatReturn} - 包含 controller、pushMessage 和 setClawChatStatus\n */\nexport const useClawChat = ({\n onAction,\n onAbort,\n}: {\n onAction: OnAction;\n onAbort: (runId: string) => void;\n}): UseClawChatReturn => {\n const controllerRef = useRef<ChatController | null>(null);\n const currentRunIdRef = useRef<string | null>(null);\n
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/hooks/useClawChat/index.ts"],"sourcesContent":["import {\n ChatController,\n createThreadManagerStateWithDefault,\n ThreadMessageManager,\n ProtocolEnum,\n createMetaData,\n} from '@chat-lab/core';\nimport { useRef, useState } from 'react';\nimport { useMemoizedFn } from 'ahooks';\nimport {\n UseClawChatReturn,\n OnAction,\n ClawChatStatus,\n PushMessageImpl,\n PushHistory,\n isPushStreamStart,\n isPushStreamDone,\n isPushStreamError,\n isPushStreamAborted,\n} from './types';\nimport { createClawCompletion } from './clawCompletion';\nimport ClawProtocolAdaptor from './ClawProtocolAdaptor';\nimport convertHistoryMessage from './convertHistoryMessage';\n\nexport * from './types';\nexport { default as ClawProtocolAdaptor } from './ClawProtocolAdaptor';\nexport * from './ClawProtocolAdaptor';\n\n/**\n * useClawChat Hook\n * 用于与 ClawClient 进行双向通信\n *\n * @param onAction - 处理来自 Chat 组件的用户操作\n * @returns {UseClawChatReturn} - 包含 controller、pushMessage 和 setClawChatStatus\n */\n\nexport const useClawChat = ({\n onAction,\n onAbort,\n}: {\n onAction: OnAction;\n onAbort: (runId: string) => void;\n}): UseClawChatReturn => {\n const controllerRef = useRef<ChatController | null>(null);\n const currentRunIdRef = useRef<string | null>(null);\n\n const pushMessageImplRef = useRef<(msg: PushMessageImpl) => void>(() => {});\n /**\n * 推送消息到 Chat 组件\n * 由 ClawClient 调用\n */\n const pushMessage = useMemoizedFn((msg: PushMessageImpl) => {\n // 获取当前线程\n const thread = controllerRef.current?.getCurrentThread();\n // 更新整个消息历史\n if (isPushStreamStart(msg)) {\n currentRunIdRef.current = msg.payload.runId;\n // 手动设置 sending 状态,显示小圆圈\n if (thread) {\n controllerRef.current?.setSending(thread.id, true);\n }\n const assistantMessage = thread?.messages.findLast(\n (message) => message.role === 'assistant',\n );\n controllerRef.current?.triggerCompletion({\n assistantMessage,\n extraRequestOptions: {\n meta: { shouldSendMessage: false },\n },\n });\n }\n if (\n isPushStreamAborted(msg)\n || isPushStreamDone(msg)\n || isPushStreamError(msg)\n ) {\n currentRunIdRef.current = null;\n // 手动设置 sending 状态,显示小圆圈\n if (thread) {\n controllerRef.current?.setSending(thread.id, false);\n controllerRef.current?.setLoading(thread.id, false);\n }\n }\n\n pushMessageImplRef.current(msg);\n });\n\n const pushHistory = useMemoizedFn((msg: PushHistory) => {\n // 更新整个消息历史\n // pushMessageImplRef.current(msg);\n const thread = controllerRef.current?.getCurrentThread();\n if (thread) {\n controllerRef.current?.updateThread(thread.id, {\n messages: convertHistoryMessage(msg),\n });\n }\n });\n\n // 初始化 ChatController\n if (!controllerRef.current) {\n const state = createThreadManagerStateWithDefault();\n const storeManager = new ThreadMessageManager(state);\n\n // 创建 completion 函数\n const { clawCompletion, pushMessageImpl } = createClawCompletion(\n onAction,\n () => {\n if (currentRunIdRef.current) {\n onAbort(currentRunIdRef.current);\n }\n },\n );\n pushMessageImplRef.current = pushMessageImpl;\n\n // 创建 Claw Protocol Adaptor\n const clawProtocolAdaptor = new ClawProtocolAdaptor({\n protocol: ProtocolEnum.CUSTOM,\n protocolName: 'Claw',\n } as any);\n\n controllerRef.current = new ChatController({\n requestOptions: {\n api: 'default',\n headers: {\n Authorization: 'Bearer ',\n },\n meta: {\n shouldSendMessage: true,\n shouldReceived: true,\n },\n // 使用自定义 completion\n completions: clawCompletion,\n },\n protocolOptions: {\n protocol: ProtocolEnum.CUSTOM,\n protocolName: 'Claw',\n protocolAdaptor: clawProtocolAdaptor,\n } as any,\n storeManager,\n metaData: createMetaData({\n clawStatus: { status: false, reason: 'uninitialized' },\n }),\n });\n }\n\n const handleClawChatStatus = useMemoizedFn((status: ClawChatStatus) => {\n if (controllerRef.current) {\n controllerRef.current.metaData.clawStatus = status;\n }\n });\n\n return {\n controllerRef,\n pushMessage,\n pushHistory,\n setClawChatStatus: handleClawChatStatus,\n };\n};\n"],"names":["useRef","useMemoizedFn","isPushStreamStart","isPushStreamAborted","isPushStreamDone","isPushStreamError","createThreadManagerStateWithDefault","ThreadMessageManager","clawCompletion","createClawCompletion","ProtocolEnum","ChatController","createMetaData"],"mappings":";;;;;;;;;;AA4BA;;;;;;AAMG;AAEU,MAAA,WAAW,GAAG,CAAC,EAC1B,QAAQ,EACR,OAAO,GAIR,KAAuB;AACtB,IAAA,MAAM,aAAa,GAAGA,YAAM,CAAwB,IAAI,CAAC,CAAC;AAC1D,IAAA,MAAM,eAAe,GAAGA,YAAM,CAAgB,IAAI,CAAC,CAAC;IAEpD,MAAM,kBAAkB,GAAGA,YAAM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ACf,QAAQ,EAAEE,kBAAY,CAAC,MAAM;AAC7B,gBAAA,YAAY,EAAE,MAAM;AACpB,gBAAA,eAAe,EAAE,mBAAmB;AAC9B,aAAA;YACR,YAAY;YACZ,QAAQ,EAAEE,oBAAc,CAAC;gBACvB,UAAU,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE;aACvD,CAAC;AACH,SAAA,CAAC,CAAC;KACJ;AAED,IAAA,MAAM,oBAAoB,GAAGX,oBAAa,CAAC,CAAC,MAAsB,KAAI;AACpE,QAAA,IAAI,aAAa,CAAC,OAAO,EAAE;YACzB,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC;SACpD;AACH,KAAC,CAAC,CAAC;IAEH,OAAO;QACL,aAAa;QACb,WAAW;QACX,WAAW;AACX,QAAA,iBAAiB,EAAE,oBAAoB;KACxC,CAAC;AACJ;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useClawChat/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useClawChat/index.ts"],"names":[],"mappings":"AASA,OAAO,EACL,iBAAiB,EACjB,QAAQ,EAQT,MAAM,SAAS,CAAC;AAKjB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACvE,cAAc,uBAAuB,CAAC;AAEtC;;;;;;GAMG;AAEH,eAAO,MAAM,WAAW,GAAI,wBAGzB;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC,KAAG,iBAmHH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createThreadManagerStateWithDefault, ProtocolEnum, ChatController, ThreadMessageManager } from '../../core/dist/index.js';
|
|
2
|
-
import { useRef
|
|
1
|
+
import { createThreadManagerStateWithDefault, ProtocolEnum, ChatController, createMetaData, ThreadMessageManager } from '../../core/dist/index.js';
|
|
2
|
+
import { useRef } from 'react';
|
|
3
3
|
import { useMemoizedFn } from 'ahooks';
|
|
4
4
|
import { isPushStreamStart, isPushStreamAborted, isPushStreamDone, isPushStreamError } from './types.js';
|
|
5
5
|
export { isPushSteamDelta } from './types.js';
|
|
@@ -17,7 +17,6 @@ import convertHistoryMessage from './convertHistoryMessage.js';
|
|
|
17
17
|
const useClawChat = ({ onAction, onAbort, }) => {
|
|
18
18
|
const controllerRef = useRef(null);
|
|
19
19
|
const currentRunIdRef = useRef(null);
|
|
20
|
-
const [clawChatStatus, setClawChatStatus] = useState('idle');
|
|
21
20
|
const pushMessageImplRef = useRef(() => { });
|
|
22
21
|
/**
|
|
23
22
|
* 推送消息到 Chat 组件
|
|
@@ -98,14 +97,21 @@ const useClawChat = ({ onAction, onAbort, }) => {
|
|
|
98
97
|
protocolAdaptor: clawProtocolAdaptor,
|
|
99
98
|
},
|
|
100
99
|
storeManager,
|
|
100
|
+
metaData: createMetaData({
|
|
101
|
+
clawStatus: { status: false, reason: 'uninitialized' },
|
|
102
|
+
}),
|
|
101
103
|
});
|
|
102
104
|
}
|
|
105
|
+
const handleClawChatStatus = useMemoizedFn((status) => {
|
|
106
|
+
if (controllerRef.current) {
|
|
107
|
+
controllerRef.current.metaData.clawStatus = status;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
103
110
|
return {
|
|
104
111
|
controllerRef,
|
|
105
112
|
pushMessage,
|
|
106
113
|
pushHistory,
|
|
107
|
-
setClawChatStatus,
|
|
108
|
-
clawChatStatus,
|
|
114
|
+
setClawChatStatus: handleClawChatStatus,
|
|
109
115
|
};
|
|
110
116
|
};
|
|
111
117
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/hooks/useClawChat/index.ts"],"sourcesContent":["import {\n ChatController,\n createThreadManagerStateWithDefault,\n ThreadMessageManager,\n ProtocolEnum,\n} from '@chat-lab/core';\nimport { useRef, useState } from 'react';\nimport { useMemoizedFn } from 'ahooks';\nimport {\n UseClawChatReturn,\n OnAction,\n ClawChatStatus,\n PushMessageImpl,\n PushHistory,\n isPushStreamStart,\n isPushStreamDone,\n isPushStreamError,\n isPushStreamAborted,\n} from './types';\nimport { createClawCompletion } from './clawCompletion';\nimport ClawProtocolAdaptor from './ClawProtocolAdaptor';\nimport convertHistoryMessage from './convertHistoryMessage';\n\nexport * from './types';\nexport { default as ClawProtocolAdaptor } from './ClawProtocolAdaptor';\nexport * from './ClawProtocolAdaptor';\n\n/**\n * useClawChat Hook\n * 用于与 ClawClient 进行双向通信\n *\n * @param onAction - 处理来自 Chat 组件的用户操作\n * @returns {UseClawChatReturn} - 包含 controller、pushMessage 和 setClawChatStatus\n */\nexport const useClawChat = ({\n onAction,\n onAbort,\n}: {\n onAction: OnAction;\n onAbort: (runId: string) => void;\n}): UseClawChatReturn => {\n const controllerRef = useRef<ChatController | null>(null);\n const currentRunIdRef = useRef<string | null>(null);\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/hooks/useClawChat/index.ts"],"sourcesContent":["import {\n ChatController,\n createThreadManagerStateWithDefault,\n ThreadMessageManager,\n ProtocolEnum,\n createMetaData,\n} from '@chat-lab/core';\nimport { useRef, useState } from 'react';\nimport { useMemoizedFn } from 'ahooks';\nimport {\n UseClawChatReturn,\n OnAction,\n ClawChatStatus,\n PushMessageImpl,\n PushHistory,\n isPushStreamStart,\n isPushStreamDone,\n isPushStreamError,\n isPushStreamAborted,\n} from './types';\nimport { createClawCompletion } from './clawCompletion';\nimport ClawProtocolAdaptor from './ClawProtocolAdaptor';\nimport convertHistoryMessage from './convertHistoryMessage';\n\nexport * from './types';\nexport { default as ClawProtocolAdaptor } from './ClawProtocolAdaptor';\nexport * from './ClawProtocolAdaptor';\n\n/**\n * useClawChat Hook\n * 用于与 ClawClient 进行双向通信\n *\n * @param onAction - 处理来自 Chat 组件的用户操作\n * @returns {UseClawChatReturn} - 包含 controller、pushMessage 和 setClawChatStatus\n */\n\nexport const useClawChat = ({\n onAction,\n onAbort,\n}: {\n onAction: OnAction;\n onAbort: (runId: string) => void;\n}): UseClawChatReturn => {\n const controllerRef = useRef<ChatController | null>(null);\n const currentRunIdRef = useRef<string | null>(null);\n\n const pushMessageImplRef = useRef<(msg: PushMessageImpl) => void>(() => {});\n /**\n * 推送消息到 Chat 组件\n * 由 ClawClient 调用\n */\n const pushMessage = useMemoizedFn((msg: PushMessageImpl) => {\n // 获取当前线程\n const thread = controllerRef.current?.getCurrentThread();\n // 更新整个消息历史\n if (isPushStreamStart(msg)) {\n currentRunIdRef.current = msg.payload.runId;\n // 手动设置 sending 状态,显示小圆圈\n if (thread) {\n controllerRef.current?.setSending(thread.id, true);\n }\n const assistantMessage = thread?.messages.findLast(\n (message) => message.role === 'assistant',\n );\n controllerRef.current?.triggerCompletion({\n assistantMessage,\n extraRequestOptions: {\n meta: { shouldSendMessage: false },\n },\n });\n }\n if (\n isPushStreamAborted(msg)\n || isPushStreamDone(msg)\n || isPushStreamError(msg)\n ) {\n currentRunIdRef.current = null;\n // 手动设置 sending 状态,显示小圆圈\n if (thread) {\n controllerRef.current?.setSending(thread.id, false);\n controllerRef.current?.setLoading(thread.id, false);\n }\n }\n\n pushMessageImplRef.current(msg);\n });\n\n const pushHistory = useMemoizedFn((msg: PushHistory) => {\n // 更新整个消息历史\n // pushMessageImplRef.current(msg);\n const thread = controllerRef.current?.getCurrentThread();\n if (thread) {\n controllerRef.current?.updateThread(thread.id, {\n messages: convertHistoryMessage(msg),\n });\n }\n });\n\n // 初始化 ChatController\n if (!controllerRef.current) {\n const state = createThreadManagerStateWithDefault();\n const storeManager = new ThreadMessageManager(state);\n\n // 创建 completion 函数\n const { clawCompletion, pushMessageImpl } = createClawCompletion(\n onAction,\n () => {\n if (currentRunIdRef.current) {\n onAbort(currentRunIdRef.current);\n }\n },\n );\n pushMessageImplRef.current = pushMessageImpl;\n\n // 创建 Claw Protocol Adaptor\n const clawProtocolAdaptor = new ClawProtocolAdaptor({\n protocol: ProtocolEnum.CUSTOM,\n protocolName: 'Claw',\n } as any);\n\n controllerRef.current = new ChatController({\n requestOptions: {\n api: 'default',\n headers: {\n Authorization: 'Bearer ',\n },\n meta: {\n shouldSendMessage: true,\n shouldReceived: true,\n },\n // 使用自定义 completion\n completions: clawCompletion,\n },\n protocolOptions: {\n protocol: ProtocolEnum.CUSTOM,\n protocolName: 'Claw',\n protocolAdaptor: clawProtocolAdaptor,\n } as any,\n storeManager,\n metaData: createMetaData({\n clawStatus: { status: false, reason: 'uninitialized' },\n }),\n });\n }\n\n const handleClawChatStatus = useMemoizedFn((status: ClawChatStatus) => {\n if (controllerRef.current) {\n controllerRef.current.metaData.clawStatus = status;\n }\n });\n\n return {\n controllerRef,\n pushMessage,\n pushHistory,\n setClawChatStatus: handleClawChatStatus,\n };\n};\n"],"names":[],"mappings":";;;;;;;;;AA4BA;;;;;;AAMG;AAEU,MAAA,WAAW,GAAG,CAAC,EAC1B,QAAQ,EACR,OAAO,GAIR,KAAuB;AACtB,IAAA,MAAM,aAAa,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;AAC1D,IAAA,MAAM,eAAe,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAC;IAEpD,MAAM,kBAAkB,GAAG,MAAM,CAAiC,MAAK,GAAG,CAAC,CAAC;AAC5E;;;AAGG;AACH,IAAA,MAAM,WAAW,GAAG,aAAa,CAAC,CAAC,GAAoB,KAAI;;QAEzD,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,EAAE,gBAAgB,EAAE,CAAC;;AAEzD,QAAA,IAAI,iBAAiB,CAAC,GAAG,CAAC,EAAE;YAC1B,eAAe,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC;;YAE5C,IAAI,MAAM,EAAE;gBACV,aAAa,CAAC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,EAAE;YACzB,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC;SACpD;AACH,KAAC,CAAC,CAAC;IAEH,OAAO;QACL,aAAa;QACb,WAAW;QACX,WAAW;AACX,QAAA,iBAAiB,EAAE,oBAAoB;KACxC,CAAC;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sources":["../../../src/hooks/useClawChat/types.ts"],"sourcesContent":["import { ChatController } from '@chat-lab/core';\nimport { RefObject } from 'react';\n\nexport interface TextContent {\n type: 'text';\n text: string;\n}\nexport interface ThinkContent {\n type: 'thinking';\n thinking: string;\n}\nexport interface ToolCallContent {\n type: 'toolCall';\n id: string;\n name: string;\n arguments: Record<string, any>;\n}\n\nexport interface ToolResultContent {\n type: 'toolResult';\n toolCallId: string;\n toolName: string;\n content: TextContent[];\n isError: boolean;\n timestamp: number;\n}\n\ninterface ChatMessageContent {\n type: string; // text thinking toolCall image\n // text 类型特有字段\n text?: string; // 文本内容\n // thinking 类型特有字段\n thinking?: string; // 思考内容\n // toolCall 类型特有字段\n name?: string; // 工具名称\n id?: string; // 工具调用 ID\n arguments?: string; // 工具调用参数\n // image 类型特有字段\n content?: string; // 图片 Base64 编码\n uri?: string; // 图片 URI\n}\n\nexport type Content = {\n role: string; // user assistant toolResult\n content: ChatMessageContent[];\n timestamp: number;\n};\nexport interface ActionSend {\n type: 'send';\n message: string;\n thinking?: 'none' | 'low' | 'medium' | 'high';\n attachments?: Array<{\n type: 'image';\n mimeType: string;\n content: string; // base64 or uri\n }>;\n}\n\nexport interface ActionAbort {\n type: 'abort';\n runId?: string;\n}\n// ===== ChatAction Types =====\nexport type ChatAction = {\n message: string;\n thinking?: 'none' | 'low' | 'medium' | 'high';\n attachments?: Array<{\n type: 'image';\n mimeType: string;\n content: string;\n }>;\n};\n\nexport interface PushHistory {\n type: 'res';\n id: string;\n payload: {\n sessionKey: string;\n sessionId: string;\n messages: Content[];\n };\n thinkingLevel?: string;\n}\n\nexport interface PushStreamStart {\n type: 'res';\n id: string;\n ok: true;\n payload: {\n runId: string;\n status: 'started';\n };\n}\n\nexport interface PushStreamDelta {\n type: 'event';\n event: 'agent';\n payload: {\n runId: string;\n stream: 'assistant' | 'lifecycle';\n data: {\n text?: string; // 全量\n delta?: string; // 增量\n phase?: 'end';\n endedAt?: number;\n };\n sessionKey: string;\n seq: number;\n ts: number;\n };\n seq: number;\n}\nexport interface PushStreamDone {\n type: 'event';\n event: 'chat';\n seq: number;\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'final';\n message: {\n role: string;\n content: TextContent[];\n timestamp: number;\n stopReason?: 'stop';\n };\n };\n}\n\nexport interface PushStreamAborted {\n type: 'event';\n event: 'chat';\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'aborted';\n message: {\n role: string;\n content: TextContent[];\n timestamp?: number;\n };\n };\n}\n\nexport interface PushStreamError {\n type: 'event';\n event: 'chat';\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'error';\n errorMessage: string;\n };\n}\n\n// ===== PushMessage Types =====\nexport type PushMessage =\n | PushHistory\n | PushStreamDelta\n | PushStreamDone\n | PushStreamAborted\n | PushStreamError;\n\nexport type PushMessageImpl =\n | PushStreamStart\n | PushStreamDelta\n | PushStreamDone\n | PushStreamAborted\n | PushStreamError;\n\nexport const isPushStreamStart = (\n msg: PushMessageImpl,\n): msg is PushStreamStart => msg.type === 'res' && msg.payload.status === 'started';\n\nexport const isPushSteamDelta = (\n msg: PushMessageImpl,\n): msg is PushStreamDelta => msg.type === 'event'\n && msg.event === 'agent'\n && msg.payload.stream === 'assistant'\n && msg.payload.data.delta !== '';\n\nexport const isPushStreamDone = (msg: PushMessageImpl): msg is PushStreamDone => msg.type === 'event' && msg.event === 'chat' && msg.payload.state === 'final';\n\nexport const isPushStreamAborted = (\n msg: PushMessageImpl,\n): msg is PushStreamAborted => msg.type === 'event'\n && msg.event === 'chat'\n && msg.payload.state === 'aborted';\n\nexport const isPushStreamError = (\n msg: PushMessageImpl,\n): msg is PushStreamError => msg.type === 'event' && msg.event === 'chat' && msg.payload.state === 'error';\n\
|
|
1
|
+
{"version":3,"file":"types.cjs","sources":["../../../src/hooks/useClawChat/types.ts"],"sourcesContent":["import { ChatController } from '@chat-lab/core';\nimport { RefObject } from 'react';\n\nexport interface TextContent {\n type: 'text';\n text: string;\n}\nexport interface ThinkContent {\n type: 'thinking';\n thinking: string;\n}\nexport interface ToolCallContent {\n type: 'toolCall';\n id: string;\n name: string;\n arguments: Record<string, any>;\n}\n\nexport interface ToolResultContent {\n type: 'toolResult';\n toolCallId: string;\n toolName: string;\n content: TextContent[];\n isError: boolean;\n timestamp: number;\n}\n\ninterface ChatMessageContent {\n type: string; // text thinking toolCall image\n // text 类型特有字段\n text?: string; // 文本内容\n // thinking 类型特有字段\n thinking?: string; // 思考内容\n // toolCall 类型特有字段\n name?: string; // 工具名称\n id?: string; // 工具调用 ID\n arguments?: string; // 工具调用参数\n // image 类型特有字段\n content?: string; // 图片 Base64 编码\n uri?: string; // 图片 URI\n}\n\nexport type Content = {\n role: string; // user assistant toolResult\n content: ChatMessageContent[];\n timestamp: number;\n};\nexport interface ActionSend {\n type: 'send';\n message: string;\n thinking?: 'none' | 'low' | 'medium' | 'high';\n attachments?: Array<{\n type: 'image';\n mimeType: string;\n content: string; // base64 or uri\n }>;\n}\n\nexport interface ActionAbort {\n type: 'abort';\n runId?: string;\n}\n// ===== ChatAction Types =====\nexport type ChatAction = {\n message: string;\n thinking?: 'none' | 'low' | 'medium' | 'high';\n attachments?: Array<{\n type: 'image';\n mimeType: string;\n content: string;\n }>;\n};\n\nexport interface PushHistory {\n type: 'res';\n id: string;\n payload: {\n sessionKey: string;\n sessionId: string;\n messages: Content[];\n };\n thinkingLevel?: string;\n}\n\nexport interface PushStreamStart {\n type: 'res';\n id: string;\n ok: true;\n payload: {\n runId: string;\n status: 'started';\n };\n}\n\nexport interface PushStreamDelta {\n type: 'event';\n event: 'agent';\n payload: {\n runId: string;\n stream: 'assistant' | 'lifecycle';\n data: {\n text?: string; // 全量\n delta?: string; // 增量\n phase?: 'end';\n endedAt?: number;\n };\n sessionKey: string;\n seq: number;\n ts: number;\n };\n seq: number;\n}\nexport interface PushStreamDone {\n type: 'event';\n event: 'chat';\n seq: number;\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'final';\n message: {\n role: string;\n content: TextContent[];\n timestamp: number;\n stopReason?: 'stop';\n };\n };\n}\n\nexport interface PushStreamAborted {\n type: 'event';\n event: 'chat';\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'aborted';\n message: {\n role: string;\n content: TextContent[];\n timestamp?: number;\n };\n };\n}\n\nexport interface PushStreamError {\n type: 'event';\n event: 'chat';\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'error';\n errorMessage: string;\n };\n}\n\n// ===== PushMessage Types =====\nexport type PushMessage =\n | PushHistory\n | PushStreamDelta\n | PushStreamDone\n | PushStreamAborted\n | PushStreamError;\n\nexport type PushMessageImpl =\n | PushStreamStart\n | PushStreamDelta\n | PushStreamDone\n | PushStreamAborted\n | PushStreamError;\n\nexport const isPushStreamStart = (\n msg: PushMessageImpl,\n): msg is PushStreamStart => msg.type === 'res' && msg.payload.status === 'started';\n\nexport const isPushSteamDelta = (\n msg: PushMessageImpl,\n): msg is PushStreamDelta => msg.type === 'event'\n && msg.event === 'agent'\n && msg.payload.stream === 'assistant'\n && msg.payload.data.delta !== '';\n\nexport const isPushStreamDone = (msg: PushMessageImpl): msg is PushStreamDone => msg.type === 'event' && msg.event === 'chat' && msg.payload.state === 'final';\n\nexport const isPushStreamAborted = (\n msg: PushMessageImpl,\n): msg is PushStreamAborted => msg.type === 'event'\n && msg.event === 'chat'\n && msg.payload.state === 'aborted';\n\nexport const isPushStreamError = (\n msg: PushMessageImpl,\n): msg is PushStreamError => msg.type === 'event' && msg.event === 'chat' && msg.payload.state === 'error';\n\nexport interface ClawChatStatus {\n status: boolean;\n reason?: string;\n}\n// ===== Hook Return Type =====\nexport interface UseClawChatReturn {\n controllerRef: RefObject<ChatController | null>;\n pushMessage: (msg: PushMessageImpl) => void;\n pushHistory: (msg: PushHistory) => void;\n setClawChatStatus: (status: ClawChatStatus) => void;\n}\n\nexport type OnAction = (action: ChatAction) => void;\n"],"names":[],"mappings":";;MA6Ka,iBAAiB,GAAG,CAC/B,GAAoB,KACO,GAAG,CAAC,IAAI,KAAK,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,UAAU;AAE7E,MAAM,gBAAgB,GAAG,CAC9B,GAAoB,KACO,GAAG,CAAC,IAAI,KAAK,OAAO;OAC5C,GAAG,CAAC,KAAK,KAAK,OAAO;AACrB,OAAA,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,WAAW;OAClC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,GAAG;AAE5B,MAAM,gBAAgB,GAAG,CAAC,GAAoB,KAA4B,GAAG,CAAC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,KAAK,KAAK,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ;AAExJ,MAAM,mBAAmB,GAAG,CACjC,GAAoB,KACS,GAAG,CAAC,IAAI,KAAK,OAAO;OAC9C,GAAG,CAAC,KAAK,KAAK,MAAM;AACpB,OAAA,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,UAAU;AAE9B,MAAM,iBAAiB,GAAG,CAC/B,GAAoB,KACO,GAAG,CAAC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,KAAK,KAAK,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK;;;;;;;;"}
|
|
@@ -147,13 +147,15 @@ export declare const isPushSteamDelta: (msg: PushMessageImpl) => msg is PushStre
|
|
|
147
147
|
export declare const isPushStreamDone: (msg: PushMessageImpl) => msg is PushStreamDone;
|
|
148
148
|
export declare const isPushStreamAborted: (msg: PushMessageImpl) => msg is PushStreamAborted;
|
|
149
149
|
export declare const isPushStreamError: (msg: PushMessageImpl) => msg is PushStreamError;
|
|
150
|
-
export
|
|
150
|
+
export interface ClawChatStatus {
|
|
151
|
+
status: boolean;
|
|
152
|
+
reason?: string;
|
|
153
|
+
}
|
|
151
154
|
export interface UseClawChatReturn {
|
|
152
155
|
controllerRef: RefObject<ChatController | null>;
|
|
153
156
|
pushMessage: (msg: PushMessageImpl) => void;
|
|
154
157
|
pushHistory: (msg: PushHistory) => void;
|
|
155
158
|
setClawChatStatus: (status: ClawChatStatus) => void;
|
|
156
|
-
clawChatStatus: ClawChatStatus;
|
|
157
159
|
}
|
|
158
160
|
export type OnAction = (action: ChatAction) => void;
|
|
159
161
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/hooks/useClawChat/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AACD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IAC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,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../src/hooks/useClawChat/types.ts"],"sourcesContent":["import { ChatController } from '@chat-lab/core';\nimport { RefObject } from 'react';\n\nexport interface TextContent {\n type: 'text';\n text: string;\n}\nexport interface ThinkContent {\n type: 'thinking';\n thinking: string;\n}\nexport interface ToolCallContent {\n type: 'toolCall';\n id: string;\n name: string;\n arguments: Record<string, any>;\n}\n\nexport interface ToolResultContent {\n type: 'toolResult';\n toolCallId: string;\n toolName: string;\n content: TextContent[];\n isError: boolean;\n timestamp: number;\n}\n\ninterface ChatMessageContent {\n type: string; // text thinking toolCall image\n // text 类型特有字段\n text?: string; // 文本内容\n // thinking 类型特有字段\n thinking?: string; // 思考内容\n // toolCall 类型特有字段\n name?: string; // 工具名称\n id?: string; // 工具调用 ID\n arguments?: string; // 工具调用参数\n // image 类型特有字段\n content?: string; // 图片 Base64 编码\n uri?: string; // 图片 URI\n}\n\nexport type Content = {\n role: string; // user assistant toolResult\n content: ChatMessageContent[];\n timestamp: number;\n};\nexport interface ActionSend {\n type: 'send';\n message: string;\n thinking?: 'none' | 'low' | 'medium' | 'high';\n attachments?: Array<{\n type: 'image';\n mimeType: string;\n content: string; // base64 or uri\n }>;\n}\n\nexport interface ActionAbort {\n type: 'abort';\n runId?: string;\n}\n// ===== ChatAction Types =====\nexport type ChatAction = {\n message: string;\n thinking?: 'none' | 'low' | 'medium' | 'high';\n attachments?: Array<{\n type: 'image';\n mimeType: string;\n content: string;\n }>;\n};\n\nexport interface PushHistory {\n type: 'res';\n id: string;\n payload: {\n sessionKey: string;\n sessionId: string;\n messages: Content[];\n };\n thinkingLevel?: string;\n}\n\nexport interface PushStreamStart {\n type: 'res';\n id: string;\n ok: true;\n payload: {\n runId: string;\n status: 'started';\n };\n}\n\nexport interface PushStreamDelta {\n type: 'event';\n event: 'agent';\n payload: {\n runId: string;\n stream: 'assistant' | 'lifecycle';\n data: {\n text?: string; // 全量\n delta?: string; // 增量\n phase?: 'end';\n endedAt?: number;\n };\n sessionKey: string;\n seq: number;\n ts: number;\n };\n seq: number;\n}\nexport interface PushStreamDone {\n type: 'event';\n event: 'chat';\n seq: number;\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'final';\n message: {\n role: string;\n content: TextContent[];\n timestamp: number;\n stopReason?: 'stop';\n };\n };\n}\n\nexport interface PushStreamAborted {\n type: 'event';\n event: 'chat';\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'aborted';\n message: {\n role: string;\n content: TextContent[];\n timestamp?: number;\n };\n };\n}\n\nexport interface PushStreamError {\n type: 'event';\n event: 'chat';\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'error';\n errorMessage: string;\n };\n}\n\n// ===== PushMessage Types =====\nexport type PushMessage =\n | PushHistory\n | PushStreamDelta\n | PushStreamDone\n | PushStreamAborted\n | PushStreamError;\n\nexport type PushMessageImpl =\n | PushStreamStart\n | PushStreamDelta\n | PushStreamDone\n | PushStreamAborted\n | PushStreamError;\n\nexport const isPushStreamStart = (\n msg: PushMessageImpl,\n): msg is PushStreamStart => msg.type === 'res' && msg.payload.status === 'started';\n\nexport const isPushSteamDelta = (\n msg: PushMessageImpl,\n): msg is PushStreamDelta => msg.type === 'event'\n && msg.event === 'agent'\n && msg.payload.stream === 'assistant'\n && msg.payload.data.delta !== '';\n\nexport const isPushStreamDone = (msg: PushMessageImpl): msg is PushStreamDone => msg.type === 'event' && msg.event === 'chat' && msg.payload.state === 'final';\n\nexport const isPushStreamAborted = (\n msg: PushMessageImpl,\n): msg is PushStreamAborted => msg.type === 'event'\n && msg.event === 'chat'\n && msg.payload.state === 'aborted';\n\nexport const isPushStreamError = (\n msg: PushMessageImpl,\n): msg is PushStreamError => msg.type === 'event' && msg.event === 'chat' && msg.payload.state === 'error';\n\
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../src/hooks/useClawChat/types.ts"],"sourcesContent":["import { ChatController } from '@chat-lab/core';\nimport { RefObject } from 'react';\n\nexport interface TextContent {\n type: 'text';\n text: string;\n}\nexport interface ThinkContent {\n type: 'thinking';\n thinking: string;\n}\nexport interface ToolCallContent {\n type: 'toolCall';\n id: string;\n name: string;\n arguments: Record<string, any>;\n}\n\nexport interface ToolResultContent {\n type: 'toolResult';\n toolCallId: string;\n toolName: string;\n content: TextContent[];\n isError: boolean;\n timestamp: number;\n}\n\ninterface ChatMessageContent {\n type: string; // text thinking toolCall image\n // text 类型特有字段\n text?: string; // 文本内容\n // thinking 类型特有字段\n thinking?: string; // 思考内容\n // toolCall 类型特有字段\n name?: string; // 工具名称\n id?: string; // 工具调用 ID\n arguments?: string; // 工具调用参数\n // image 类型特有字段\n content?: string; // 图片 Base64 编码\n uri?: string; // 图片 URI\n}\n\nexport type Content = {\n role: string; // user assistant toolResult\n content: ChatMessageContent[];\n timestamp: number;\n};\nexport interface ActionSend {\n type: 'send';\n message: string;\n thinking?: 'none' | 'low' | 'medium' | 'high';\n attachments?: Array<{\n type: 'image';\n mimeType: string;\n content: string; // base64 or uri\n }>;\n}\n\nexport interface ActionAbort {\n type: 'abort';\n runId?: string;\n}\n// ===== ChatAction Types =====\nexport type ChatAction = {\n message: string;\n thinking?: 'none' | 'low' | 'medium' | 'high';\n attachments?: Array<{\n type: 'image';\n mimeType: string;\n content: string;\n }>;\n};\n\nexport interface PushHistory {\n type: 'res';\n id: string;\n payload: {\n sessionKey: string;\n sessionId: string;\n messages: Content[];\n };\n thinkingLevel?: string;\n}\n\nexport interface PushStreamStart {\n type: 'res';\n id: string;\n ok: true;\n payload: {\n runId: string;\n status: 'started';\n };\n}\n\nexport interface PushStreamDelta {\n type: 'event';\n event: 'agent';\n payload: {\n runId: string;\n stream: 'assistant' | 'lifecycle';\n data: {\n text?: string; // 全量\n delta?: string; // 增量\n phase?: 'end';\n endedAt?: number;\n };\n sessionKey: string;\n seq: number;\n ts: number;\n };\n seq: number;\n}\nexport interface PushStreamDone {\n type: 'event';\n event: 'chat';\n seq: number;\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'final';\n message: {\n role: string;\n content: TextContent[];\n timestamp: number;\n stopReason?: 'stop';\n };\n };\n}\n\nexport interface PushStreamAborted {\n type: 'event';\n event: 'chat';\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'aborted';\n message: {\n role: string;\n content: TextContent[];\n timestamp?: number;\n };\n };\n}\n\nexport interface PushStreamError {\n type: 'event';\n event: 'chat';\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'error';\n errorMessage: string;\n };\n}\n\n// ===== PushMessage Types =====\nexport type PushMessage =\n | PushHistory\n | PushStreamDelta\n | PushStreamDone\n | PushStreamAborted\n | PushStreamError;\n\nexport type PushMessageImpl =\n | PushStreamStart\n | PushStreamDelta\n | PushStreamDone\n | PushStreamAborted\n | PushStreamError;\n\nexport const isPushStreamStart = (\n msg: PushMessageImpl,\n): msg is PushStreamStart => msg.type === 'res' && msg.payload.status === 'started';\n\nexport const isPushSteamDelta = (\n msg: PushMessageImpl,\n): msg is PushStreamDelta => msg.type === 'event'\n && msg.event === 'agent'\n && msg.payload.stream === 'assistant'\n && msg.payload.data.delta !== '';\n\nexport const isPushStreamDone = (msg: PushMessageImpl): msg is PushStreamDone => msg.type === 'event' && msg.event === 'chat' && msg.payload.state === 'final';\n\nexport const isPushStreamAborted = (\n msg: PushMessageImpl,\n): msg is PushStreamAborted => msg.type === 'event'\n && msg.event === 'chat'\n && msg.payload.state === 'aborted';\n\nexport const isPushStreamError = (\n msg: PushMessageImpl,\n): msg is PushStreamError => msg.type === 'event' && msg.event === 'chat' && msg.payload.state === 'error';\n\nexport interface ClawChatStatus {\n status: boolean;\n reason?: string;\n}\n// ===== Hook Return Type =====\nexport interface UseClawChatReturn {\n controllerRef: RefObject<ChatController | null>;\n pushMessage: (msg: PushMessageImpl) => void;\n pushHistory: (msg: PushHistory) => void;\n setClawChatStatus: (status: ClawChatStatus) => void;\n}\n\nexport type OnAction = (action: ChatAction) => void;\n"],"names":[],"mappings":"MA6Ka,iBAAiB,GAAG,CAC/B,GAAoB,KACO,GAAG,CAAC,IAAI,KAAK,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,UAAU;AAE7E,MAAM,gBAAgB,GAAG,CAC9B,GAAoB,KACO,GAAG,CAAC,IAAI,KAAK,OAAO;OAC5C,GAAG,CAAC,KAAK,KAAK,OAAO;AACrB,OAAA,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,WAAW;OAClC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,GAAG;AAE5B,MAAM,gBAAgB,GAAG,CAAC,GAAoB,KAA4B,GAAG,CAAC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,KAAK,KAAK,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ;AAExJ,MAAM,mBAAmB,GAAG,CACjC,GAAoB,KACS,GAAG,CAAC,IAAI,KAAK,OAAO;OAC9C,GAAG,CAAC,KAAK,KAAK,MAAM;AACpB,OAAA,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,UAAU;AAE9B,MAAM,iBAAiB,GAAG,CAC/B,GAAoB,KACO,GAAG,CAAC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,KAAK,KAAK,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK;;;;"}
|