@chat-lab/ui 0.1.0-beta.74 → 0.1.0-beta.75
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/assistant-ui/thread.cjs +3 -3
- package/dist/components/assistant-ui/thread.cjs.map +1 -1
- package/dist/components/assistant-ui/thread.js +3 -3
- package/dist/components/assistant-ui/thread.js.map +1 -1
- package/dist/hooks/useClawChat/index.cjs +12 -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 +14 -6
- package/dist/hooks/useClawChat/index.js.map +1 -1
- package/dist/hooks/useClawChat/types.cjs +10 -1
- package/dist/hooks/useClawChat/types.cjs.map +1 -1
- package/dist/hooks/useClawChat/types.d.ts +27 -1
- package/dist/hooks/useClawChat/types.d.ts.map +1 -1
- package/dist/hooks/useClawChat/types.js +10 -2
- package/dist/hooks/useClawChat/types.js.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { createThreadManagerStateWithDefault, ProtocolEnum, ChatController, createMetaData, ThreadMessageManager } from '../../core/dist/index.js';
|
|
1
|
+
import { MessageStatus, createThreadManagerStateWithDefault, ProtocolEnum, ChatController, createMetaData, ThreadMessageManager } from '../../core/dist/index.js';
|
|
2
2
|
import { useRef } from 'react';
|
|
3
3
|
import { useMemoizedFn } from 'ahooks';
|
|
4
4
|
import { uniq, without } from 'lodash-es';
|
|
5
|
-
import {
|
|
5
|
+
import { v4 } from 'uuid';
|
|
6
|
+
import { isPushStreamStart, isPushStreamAborted, isPushStreamDone, isPushStreamError, isPushGatewayEvent } from './types.js';
|
|
6
7
|
export { isPushSteamDelta } from './types.js';
|
|
7
8
|
import { createClawCompletion } from './clawCompletion.js';
|
|
8
9
|
import ClawProtocolAdaptor from './ClawProtocolAdaptor.js';
|
|
@@ -38,7 +39,6 @@ const useClawChat = ({ onAction, onAbort, }) => {
|
|
|
38
39
|
if (thread) {
|
|
39
40
|
controllerRef.current?.setSending(thread.id, true);
|
|
40
41
|
}
|
|
41
|
-
debugger;
|
|
42
42
|
controllerRef.current?.triggerCompletion({
|
|
43
43
|
extraRequestOptions: {
|
|
44
44
|
meta: { shouldSendMessage: false, runId: msg.payload.runId },
|
|
@@ -48,7 +48,6 @@ const useClawChat = ({ onAction, onAbort, }) => {
|
|
|
48
48
|
if (isPushStreamAborted(msg)
|
|
49
49
|
|| isPushStreamDone(msg)
|
|
50
50
|
|| isPushStreamError(msg)) {
|
|
51
|
-
debugger;
|
|
52
51
|
currentRunIdRef.current = without(currentRunIdRef.current, msg.payload.runId);
|
|
53
52
|
// 手动设置 sending 状态,显示小圆圈
|
|
54
53
|
if (thread) {
|
|
@@ -56,6 +55,16 @@ const useClawChat = ({ onAction, onAbort, }) => {
|
|
|
56
55
|
controllerRef.current?.setLoading(thread.id, false);
|
|
57
56
|
}
|
|
58
57
|
}
|
|
58
|
+
if (isPushGatewayEvent(msg)) {
|
|
59
|
+
controllerRef.current?.addMessage(thread?.id, {
|
|
60
|
+
id: v4(),
|
|
61
|
+
content: msg.payload.message.content,
|
|
62
|
+
role: 'assistant',
|
|
63
|
+
threadId: thread?.id,
|
|
64
|
+
metadata: {},
|
|
65
|
+
status: MessageStatus.SUCCESS,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
59
68
|
pushMessageImplRef.current(msg);
|
|
60
69
|
});
|
|
61
70
|
const pushHistory = useMemoizedFn((msg) => {
|
|
@@ -83,7 +92,6 @@ const useClawChat = ({ onAction, onAbort, }) => {
|
|
|
83
92
|
// 创建 completion 函数
|
|
84
93
|
const { clawCompletion, pushMessageImpl } = createClawCompletion(onAction, () => {
|
|
85
94
|
if (currentRunIdRef.current) {
|
|
86
|
-
debugger;
|
|
87
95
|
currentRunIdRef.current.forEach((runId) => onAbort(runId));
|
|
88
96
|
}
|
|
89
97
|
});
|
|
@@ -131,5 +139,5 @@ const useClawChat = ({ onAction, onAbort, }) => {
|
|
|
131
139
|
};
|
|
132
140
|
};
|
|
133
141
|
|
|
134
|
-
export { ClawProtocolAdaptor, isPushStreamAborted, isPushStreamDone, isPushStreamError, isPushStreamStart, useClawChat };
|
|
142
|
+
export { ClawProtocolAdaptor, isPushGatewayEvent, isPushStreamAborted, isPushStreamDone, isPushStreamError, isPushStreamStart, useClawChat };
|
|
135
143
|
//# sourceMappingURL=index.js.map
|
|
@@ -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 createMetaData,\n} from '@chat-lab/core';\nimport { useRef, useState } from 'react';\nimport { useMemoizedFn } from 'ahooks';\nimport { uniq, without } from 'lodash-es';\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';\nimport { ClawPlugin } from './clawPlugin';\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[]>([]);\n\n const clawPluginRef = useRef<ClawPlugin>();\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 = uniq([\n ...currentRunIdRef.current,\n msg.payload.runId,\n ]);\n // 手动设置 sending 状态,显示小圆圈\n if (thread) {\n controllerRef.current?.setSending(thread.id, true);\n }\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 MessageStatus,\n} from '@chat-lab/core';\nimport { useRef, useState } from 'react';\nimport { useMemoizedFn } from 'ahooks';\nimport { uniq, without } from 'lodash-es';\nimport { v4 as uuid } from 'uuid';\nimport {\n UseClawChatReturn,\n OnAction,\n ClawChatStatus,\n PushMessageImpl,\n PushHistory,\n isPushStreamStart,\n isPushStreamDone,\n isPushStreamError,\n isPushStreamAborted,\n isPushGatewayEvent,\n} from './types';\nimport { createClawCompletion } from './clawCompletion';\nimport ClawProtocolAdaptor from './ClawProtocolAdaptor';\nimport convertHistoryMessage from './convertHistoryMessage';\nimport { ClawPlugin } from './clawPlugin';\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[]>([]);\n\n const clawPluginRef = useRef<ClawPlugin>();\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 = uniq([\n ...currentRunIdRef.current,\n msg.payload.runId,\n ]);\n // 手动设置 sending 状态,显示小圆圈\n if (thread) {\n controllerRef.current?.setSending(thread.id, true);\n }\n controllerRef.current?.triggerCompletion({\n extraRequestOptions: {\n meta: { shouldSendMessage: false, runId: msg.payload.runId },\n },\n });\n }\n if (\n isPushStreamAborted(msg)\n || isPushStreamDone(msg)\n || isPushStreamError(msg)\n ) {\n currentRunIdRef.current = without(\n currentRunIdRef.current,\n msg.payload.runId,\n );\n // 手动设置 sending 状态,显示小圆圈\n if (thread) {\n controllerRef.current?.setSending(thread.id, false);\n controllerRef.current?.setLoading(thread.id, false);\n }\n }\n if (isPushGatewayEvent(msg)) {\n controllerRef.current?.addMessage(thread?.id, {\n id: uuid(),\n content: msg.payload.message.content,\n role: 'assistant',\n threadId: thread?.id,\n metadata: {},\n status: MessageStatus.SUCCESS,\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 const clawPlugin = new ClawPlugin({\n onSend: async (text) => {\n await onAction({\n message: text,\n });\n },\n });\n clawPluginRef.current = clawPlugin;\n // 创建 completion 函数\n const { clawCompletion, pushMessageImpl } = createClawCompletion(\n onAction,\n () => {\n if (currentRunIdRef.current) {\n currentRunIdRef.current.forEach((runId) => onAbort(runId));\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: false,\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 plugins: [clawPlugin],\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":["uuid"],"mappings":";;;;;;;;;;;;AAiCA;;;;;;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,CAAW,EAAE,CAAC,CAAC;AAE7C,IAAA,MAAM,aAAa,GAAG,MAAM,EAAc,CAAC;IAE3C,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;AAC1B,YAAA,eAA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.payload.state === 'final'
|
|
6
|
+
&& msg.payload.message.role === 'assistant'
|
|
7
|
+
&& msg.payload.model === 'gateway-injected';
|
|
8
|
+
const isPushStreamStart = (msg) => msg.type === 'event'
|
|
9
|
+
&& msg.event === 'agent'
|
|
10
|
+
&& msg.payload.stream === 'lifecycle'
|
|
11
|
+
&& msg.payload.data.phase === 'start';
|
|
4
12
|
const isPushSteamDelta = (msg) => msg.type === 'event'
|
|
5
13
|
&& msg.event === 'agent'
|
|
6
14
|
&& msg.payload.stream === 'assistant'
|
|
@@ -11,6 +19,7 @@ const isPushStreamAborted = (msg) => msg.type === 'event'
|
|
|
11
19
|
&& msg.payload.state === 'aborted';
|
|
12
20
|
const isPushStreamError = (msg) => msg.type === 'event' && msg.event === 'chat' && msg.payload.state === 'error';
|
|
13
21
|
|
|
22
|
+
exports.isPushGatewayEvent = isPushGatewayEvent;
|
|
14
23
|
exports.isPushSteamDelta = isPushSteamDelta;
|
|
15
24
|
exports.isPushStreamAborted = isPushStreamAborted;
|
|
16
25
|
exports.isPushStreamDone = isPushStreamDone;
|
|
@@ -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: 'event';\n event: 'agent';\n payload: {\n runId: string;\n stream: 'lifecycle';\n data: {\n phase: 'end';\n endedAt: number;\n };\n sessionKey: string;\n seq: number;\n ts: number;\n };\n seq: number;\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?: 'start';\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 === 'event'
|
|
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: 'event';\n event: 'agent';\n payload: {\n runId: string;\n stream: 'lifecycle';\n data: {\n phase: 'end';\n endedAt: number;\n };\n sessionKey: string;\n seq: number;\n ts: number;\n };\n seq: number;\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?: 'start';\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\nexport interface PushGatewayEvent {\n type: 'event';\n event: 'chat';\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'final';\n message: {\n role: 'assistant';\n content: [\n {\n type: 'text';\n text: string;\n },\n ];\n timestamp: number;\n stopReason: 'stop';\n api: 'openai-responses';\n provider: 'openclaw';\n model: 'gateway-injected';\n };\n };\n seq: 91074;\n}\n\n// ===== PushMessage Types =====\nexport type PushMessage =\n | PushHistory\n | PushStreamDelta\n | PushStreamDone\n | PushStreamAborted\n | PushStreamError\n | PushGatewayEvent;\n\nexport type PushMessageImpl =\n | PushStreamStart\n | PushStreamDelta\n | PushStreamDone\n | PushStreamAborted\n | PushStreamError;\n\nexport const isPushGatewayEvent = (\n msg: PushMessageImpl,\n): msg is PushGatewayEvent => msg.type === 'event'\n && msg.event === 'chat'\n && msg.payload.state === 'final'\n && msg.payload.message.role === 'assistant'\n && (msg.payload as any).model === 'gateway-injected';\n\nexport const isPushStreamStart = (\n msg: PushMessageImpl,\n): msg is PushStreamStart => msg.type === 'event'\n && msg.event === 'agent'\n && msg.payload.stream === 'lifecycle'\n && msg.payload.data.phase === 'start';\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":";;AA+MO,MAAM,kBAAkB,GAAG,CAChC,GAAoB,KACQ,GAAG,CAAC,IAAI,KAAK,OAAO;OAC7C,GAAG,CAAC,KAAK,KAAK,MAAM;AACpB,OAAA,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,OAAO;AAC7B,OAAA,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW;AACvC,OAAA,GAAG,CAAC,OAAe,CAAC,KAAK,KAAK,mBAAmB;AAEhD,MAAM,iBAAiB,GAAG,CAC/B,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,QAAQ;AAEjC,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,8 +147,34 @@ export interface PushStreamError {
|
|
|
147
147
|
errorMessage: string;
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
|
-
export
|
|
150
|
+
export interface PushGatewayEvent {
|
|
151
|
+
type: 'event';
|
|
152
|
+
event: 'chat';
|
|
153
|
+
payload: {
|
|
154
|
+
runId: string;
|
|
155
|
+
sessionKey: string;
|
|
156
|
+
seq: number;
|
|
157
|
+
state: 'final';
|
|
158
|
+
message: {
|
|
159
|
+
role: 'assistant';
|
|
160
|
+
content: [
|
|
161
|
+
{
|
|
162
|
+
type: 'text';
|
|
163
|
+
text: string;
|
|
164
|
+
}
|
|
165
|
+
];
|
|
166
|
+
timestamp: number;
|
|
167
|
+
stopReason: 'stop';
|
|
168
|
+
api: 'openai-responses';
|
|
169
|
+
provider: 'openclaw';
|
|
170
|
+
model: 'gateway-injected';
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
seq: 91074;
|
|
174
|
+
}
|
|
175
|
+
export type PushMessage = PushHistory | PushStreamDelta | PushStreamDone | PushStreamAborted | PushStreamError | PushGatewayEvent;
|
|
151
176
|
export type PushMessageImpl = PushStreamStart | PushStreamDelta | PushStreamDone | PushStreamAborted | PushStreamError;
|
|
177
|
+
export declare const isPushGatewayEvent: (msg: PushMessageImpl) => msg is PushGatewayEvent;
|
|
152
178
|
export declare const isPushStreamStart: (msg: PushMessageImpl) => msg is PushStreamStart;
|
|
153
179
|
export declare const isPushSteamDelta: (msg: PushMessageImpl) => msg is PushStreamDelta;
|
|
154
180
|
export declare const isPushStreamDone: (msg: PushMessageImpl) => msg is PushStreamDone;
|
|
@@ -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,iBAA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W,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,OAAO,CAAC;QACf,OAAO,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,WAAW,EAAE,CAAC;YACvB,SAAS,EAAE,MAAM,CAAC;YAClB,UAAU,CAAC,EAAE,MAAM,CAAC;SACrB,CAAC;KACH,CAAC;CACH;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,SAAS,CAAC;QACjB,OAAO,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,WAAW,EAAE,CAAC;YACvB,SAAS,CAAC,EAAE,MAAM,CAAC;SACpB,CAAC;KACH,CAAC;CACH;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,OAAO,CAAC;QACf,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAGD,MAAM,MAAM,WAAW,GACnB,WAAW,GACX,eAAe,GACf,cAAc,GACd,iBAAiB,GACjB,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/hooks/useClawChat/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,c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,eAAe,KACnB,GAAG,IAAI,eAGwB,CAAC;AAEnC,eAAO,MAAM,gBAAgB,GAAI,KAAK,eAAe,KAAG,GAAG,IAAI,cAA+F,CAAC;AAE/J,eAAO,MAAM,mBAAmB,GAC9B,KAAK,eAAe,KACnB,GAAG,IAAI,iBAE0B,CAAC;AAErC,eAAO,MAAM,iBAAiB,GAC5B,KAAK,eAAe,KACnB,GAAG,IAAI,eAAgG,CAAC;AAE3G,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAChD,WAAW,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,CAAC;IAC5C,WAAW,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,IAAI,CAAC;IACxC,iBAAiB,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;CACrD;AAED,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
const
|
|
1
|
+
const isPushGatewayEvent = (msg) => msg.type === 'event'
|
|
2
|
+
&& msg.event === 'chat'
|
|
3
|
+
&& msg.payload.state === 'final'
|
|
4
|
+
&& msg.payload.message.role === 'assistant'
|
|
5
|
+
&& msg.payload.model === 'gateway-injected';
|
|
6
|
+
const isPushStreamStart = (msg) => msg.type === 'event'
|
|
7
|
+
&& msg.event === 'agent'
|
|
8
|
+
&& msg.payload.stream === 'lifecycle'
|
|
9
|
+
&& msg.payload.data.phase === 'start';
|
|
2
10
|
const isPushSteamDelta = (msg) => msg.type === 'event'
|
|
3
11
|
&& msg.event === 'agent'
|
|
4
12
|
&& msg.payload.stream === 'assistant'
|
|
@@ -9,5 +17,5 @@ const isPushStreamAborted = (msg) => msg.type === 'event'
|
|
|
9
17
|
&& msg.payload.state === 'aborted';
|
|
10
18
|
const isPushStreamError = (msg) => msg.type === 'event' && msg.event === 'chat' && msg.payload.state === 'error';
|
|
11
19
|
|
|
12
|
-
export { isPushSteamDelta, isPushStreamAborted, isPushStreamDone, isPushStreamError, isPushStreamStart };
|
|
20
|
+
export { isPushGatewayEvent, isPushSteamDelta, isPushStreamAborted, isPushStreamDone, isPushStreamError, isPushStreamStart };
|
|
13
21
|
//# sourceMappingURL=types.js.map
|
|
@@ -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: 'event';\n event: 'agent';\n payload: {\n runId: string;\n stream: 'lifecycle';\n data: {\n phase: 'end';\n endedAt: number;\n };\n sessionKey: string;\n seq: number;\n ts: number;\n };\n seq: number;\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?: 'start';\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 === 'event'
|
|
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: 'event';\n event: 'agent';\n payload: {\n runId: string;\n stream: 'lifecycle';\n data: {\n phase: 'end';\n endedAt: number;\n };\n sessionKey: string;\n seq: number;\n ts: number;\n };\n seq: number;\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?: 'start';\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\nexport interface PushGatewayEvent {\n type: 'event';\n event: 'chat';\n payload: {\n runId: string;\n sessionKey: string;\n seq: number;\n state: 'final';\n message: {\n role: 'assistant';\n content: [\n {\n type: 'text';\n text: string;\n },\n ];\n timestamp: number;\n stopReason: 'stop';\n api: 'openai-responses';\n provider: 'openclaw';\n model: 'gateway-injected';\n };\n };\n seq: 91074;\n}\n\n// ===== PushMessage Types =====\nexport type PushMessage =\n | PushHistory\n | PushStreamDelta\n | PushStreamDone\n | PushStreamAborted\n | PushStreamError\n | PushGatewayEvent;\n\nexport type PushMessageImpl =\n | PushStreamStart\n | PushStreamDelta\n | PushStreamDone\n | PushStreamAborted\n | PushStreamError;\n\nexport const isPushGatewayEvent = (\n msg: PushMessageImpl,\n): msg is PushGatewayEvent => msg.type === 'event'\n && msg.event === 'chat'\n && msg.payload.state === 'final'\n && msg.payload.message.role === 'assistant'\n && (msg.payload as any).model === 'gateway-injected';\n\nexport const isPushStreamStart = (\n msg: PushMessageImpl,\n): msg is PushStreamStart => msg.type === 'event'\n && msg.event === 'agent'\n && msg.payload.stream === 'lifecycle'\n && msg.payload.data.phase === 'start';\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":"AA+MO,MAAM,kBAAkB,GAAG,CAChC,GAAoB,KACQ,GAAG,CAAC,IAAI,KAAK,OAAO;OAC7C,GAAG,CAAC,KAAK,KAAK,MAAM;AACpB,OAAA,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,OAAO;AAC7B,OAAA,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW;AACvC,OAAA,GAAG,CAAC,OAAe,CAAC,KAAK,KAAK,mBAAmB;AAEhD,MAAM,iBAAiB,GAAG,CAC/B,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,QAAQ;AAEjC,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;;;;"}
|
package/dist/index.cjs
CHANGED
|
@@ -62,6 +62,7 @@ Object.defineProperty(exports, 'useSnapshot', {
|
|
|
62
62
|
enumerable: true,
|
|
63
63
|
get: function () { return valtio.useSnapshot; }
|
|
64
64
|
});
|
|
65
|
+
exports.isPushGatewayEvent = types.isPushGatewayEvent;
|
|
65
66
|
exports.isPushSteamDelta = types.isPushSteamDelta;
|
|
66
67
|
exports.isPushStreamAborted = types.isPushStreamAborted;
|
|
67
68
|
exports.isPushStreamDone = types.isPushStreamDone;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|