diff --git a/extensions/qa-channel/src/protocol.ts b/extensions/qa-channel/src/protocol.ts index a6bc175be89..8be30daea7f 100644 --- a/extensions/qa-channel/src/protocol.ts +++ b/extensions/qa-channel/src/protocol.ts @@ -1,198 +1 @@ -export type QaBusConversationKind = "direct" | "channel"; - -export type QaBusConversation = { - id: string; - kind: QaBusConversationKind; - title?: string; -}; - -export type QaBusAttachment = { - id: string; - kind: "image" | "video" | "audio" | "file"; - mimeType: string; - fileName?: string; - inline?: boolean; - url?: string; - contentBase64?: string; - width?: number; - height?: number; - durationMs?: number; - altText?: string; - transcript?: string; -}; - -export type QaBusMessage = { - id: string; - accountId: string; - direction: "inbound" | "outbound"; - conversation: QaBusConversation; - senderId: string; - senderName?: string; - text: string; - timestamp: number; - threadId?: string; - threadTitle?: string; - replyToId?: string; - deleted?: boolean; - editedAt?: number; - attachments?: QaBusAttachment[]; - reactions: Array<{ - emoji: string; - senderId: string; - timestamp: number; - }>; -}; - -export type QaBusThread = { - id: string; - accountId: string; - conversationId: string; - title: string; - createdAt: number; - createdBy: string; -}; - -export type QaBusEvent = - | { - cursor: number; - kind: "inbound-message"; - accountId: string; - message: QaBusMessage; - } - | { - cursor: number; - kind: "outbound-message"; - accountId: string; - message: QaBusMessage; - } - | { - cursor: number; - kind: "thread-created"; - accountId: string; - thread: QaBusThread; - } - | { - cursor: number; - kind: "message-edited"; - accountId: string; - message: QaBusMessage; - } - | { - cursor: number; - kind: "message-deleted"; - accountId: string; - message: QaBusMessage; - } - | { - cursor: number; - kind: "reaction-added"; - accountId: string; - message: QaBusMessage; - emoji: string; - senderId: string; - }; - -export type QaBusInboundMessageInput = { - accountId?: string; - conversation: QaBusConversation; - senderId: string; - senderName?: string; - text: string; - timestamp?: number; - threadId?: string; - threadTitle?: string; - replyToId?: string; - attachments?: QaBusAttachment[]; -}; - -export type QaBusOutboundMessageInput = { - accountId?: string; - to: string; - senderId?: string; - senderName?: string; - text: string; - timestamp?: number; - threadId?: string; - replyToId?: string; - attachments?: QaBusAttachment[]; -}; - -export type QaBusCreateThreadInput = { - accountId?: string; - conversationId: string; - title: string; - createdBy?: string; - timestamp?: number; -}; - -export type QaBusReactToMessageInput = { - accountId?: string; - messageId: string; - emoji: string; - senderId?: string; - timestamp?: number; -}; - -export type QaBusEditMessageInput = { - accountId?: string; - messageId: string; - text: string; - timestamp?: number; -}; - -export type QaBusDeleteMessageInput = { - accountId?: string; - messageId: string; - timestamp?: number; -}; - -export type QaBusSearchMessagesInput = { - accountId?: string; - query?: string; - conversationId?: string; - threadId?: string; - limit?: number; -}; - -export type QaBusReadMessageInput = { - accountId?: string; - messageId: string; -}; - -export type QaBusPollInput = { - accountId?: string; - cursor?: number; - timeoutMs?: number; - limit?: number; -}; - -export type QaBusPollResult = { - cursor: number; - events: QaBusEvent[]; -}; - -export type QaBusStateSnapshot = { - cursor: number; - conversations: QaBusConversation[]; - threads: QaBusThread[]; - messages: QaBusMessage[]; - events: QaBusEvent[]; -}; - -export type QaBusWaitForInput = - | { - timeoutMs?: number; - kind: "event-kind"; - eventKind: QaBusEvent["kind"]; - } - | { - timeoutMs?: number; - kind: "message-text"; - textIncludes: string; - direction?: QaBusMessage["direction"]; - } - | { - timeoutMs?: number; - kind: "thread-id"; - threadId: string; - }; +export type * from "openclaw/plugin-sdk/qa-channel-protocol"; diff --git a/package.json b/package.json index 17b56c76e75..14c1ef19132 100644 --- a/package.json +++ b/package.json @@ -989,6 +989,10 @@ "types": "./dist/plugin-sdk/qa-channel.d.ts", "default": "./dist/plugin-sdk/qa-channel.js" }, + "./plugin-sdk/qa-channel-protocol": { + "types": "./dist/plugin-sdk/qa-channel-protocol.d.ts", + "default": "./dist/plugin-sdk/qa-channel-protocol.js" + }, "./plugin-sdk/provider-auth": { "types": "./dist/plugin-sdk/provider-auth.d.ts", "default": "./dist/plugin-sdk/provider-auth.js" diff --git a/scripts/lib/plugin-sdk-entrypoints.json b/scripts/lib/plugin-sdk-entrypoints.json index 067dea65b84..2a83e4d4c46 100644 --- a/scripts/lib/plugin-sdk-entrypoints.json +++ b/scripts/lib/plugin-sdk-entrypoints.json @@ -233,6 +233,7 @@ "nextcloud-talk", "nostr", "qa-channel", + "qa-channel-protocol", "provider-auth", "provider-auth-runtime", "provider-auth-api-key", diff --git a/src/plugin-sdk/qa-channel-protocol.ts b/src/plugin-sdk/qa-channel-protocol.ts new file mode 100644 index 00000000000..6ded2033ae1 --- /dev/null +++ b/src/plugin-sdk/qa-channel-protocol.ts @@ -0,0 +1,173 @@ +export type QaBusConversationKind = "direct" | "channel"; + +export type QaBusConversation = { + id: string; + kind: QaBusConversationKind; + title?: string; +}; + +export type QaBusAttachment = { + id: string; + kind: "image" | "video" | "audio" | "file"; + mimeType: string; + fileName?: string; + inline?: boolean; + url?: string; + contentBase64?: string; + width?: number; + height?: number; + durationMs?: number; + altText?: string; + transcript?: string; +}; + +export type QaBusMessage = { + id: string; + accountId: string; + direction: "inbound" | "outbound"; + conversation: QaBusConversation; + senderId: string; + senderName?: string; + text: string; + timestamp: number; + threadId?: string; + threadTitle?: string; + replyToId?: string; + deleted?: boolean; + editedAt?: number; + attachments?: QaBusAttachment[]; + reactions: Array<{ + emoji: string; + senderId: string; + timestamp: number; + }>; +}; + +export type QaBusThread = { + id: string; + accountId: string; + conversationId: string; + title: string; + createdAt: number; + createdBy: string; +}; + +export type QaBusEvent = + | { cursor: number; kind: "inbound-message"; accountId: string; message: QaBusMessage } + | { cursor: number; kind: "outbound-message"; accountId: string; message: QaBusMessage } + | { cursor: number; kind: "thread-created"; accountId: string; thread: QaBusThread } + | { cursor: number; kind: "message-edited"; accountId: string; message: QaBusMessage } + | { cursor: number; kind: "message-deleted"; accountId: string; message: QaBusMessage } + | { + cursor: number; + kind: "reaction-added"; + accountId: string; + message: QaBusMessage; + emoji: string; + senderId: string; + }; + +export type QaBusInboundMessageInput = { + accountId?: string; + conversation: QaBusConversation; + senderId: string; + senderName?: string; + text: string; + timestamp?: number; + threadId?: string; + threadTitle?: string; + replyToId?: string; + attachments?: QaBusAttachment[]; +}; + +export type QaBusOutboundMessageInput = { + accountId?: string; + to: string; + senderId?: string; + senderName?: string; + text: string; + timestamp?: number; + threadId?: string; + replyToId?: string; + attachments?: QaBusAttachment[]; +}; + +export type QaBusCreateThreadInput = { + accountId?: string; + conversationId: string; + title: string; + createdBy?: string; + timestamp?: number; +}; + +export type QaBusReactToMessageInput = { + accountId?: string; + messageId: string; + emoji: string; + senderId?: string; + timestamp?: number; +}; + +export type QaBusEditMessageInput = { + accountId?: string; + messageId: string; + text: string; + timestamp?: number; +}; + +export type QaBusDeleteMessageInput = { + accountId?: string; + messageId: string; + timestamp?: number; +}; + +export type QaBusSearchMessagesInput = { + accountId?: string; + query?: string; + conversationId?: string; + threadId?: string; + limit?: number; +}; + +export type QaBusReadMessageInput = { + accountId?: string; + messageId: string; +}; + +export type QaBusPollInput = { + accountId?: string; + cursor?: number; + timeoutMs?: number; + limit?: number; +}; + +export type QaBusPollResult = { + cursor: number; + events: QaBusEvent[]; +}; + +export type QaBusStateSnapshot = { + cursor: number; + conversations: QaBusConversation[]; + threads: QaBusThread[]; + messages: QaBusMessage[]; + events: QaBusEvent[]; +}; + +export type QaBusWaitForInput = + | { + timeoutMs?: number; + kind: "event-kind"; + eventKind: QaBusEvent["kind"]; + } + | { + timeoutMs?: number; + kind: "message-text"; + textIncludes: string; + direction?: QaBusMessage["direction"]; + } + | { + timeoutMs?: number; + kind: "thread-id"; + threadId: string; + }; diff --git a/src/plugin-sdk/qa-channel.ts b/src/plugin-sdk/qa-channel.ts index e6a9ac293c9..ab5cb11de35 100644 --- a/src/plugin-sdk/qa-channel.ts +++ b/src/plugin-sdk/qa-channel.ts @@ -4,180 +4,17 @@ import { createLazyFacadeObjectValue, loadBundledPluginPublicSurfaceModuleSync, } from "./facade-loader.js"; +import type { + QaBusAttachment, + QaBusInboundMessageInput, + QaBusMessage, + QaBusPollResult, + QaBusSearchMessagesInput, + QaBusStateSnapshot, + QaBusThread, +} from "./qa-channel-protocol.js"; -export type QaBusConversationKind = "direct" | "channel"; - -export type QaBusConversation = { - id: string; - kind: QaBusConversationKind; - title?: string; -}; - -export type QaBusAttachment = { - id: string; - kind: "image" | "video" | "audio" | "file"; - mimeType: string; - fileName?: string; - inline?: boolean; - url?: string; - contentBase64?: string; - width?: number; - height?: number; - durationMs?: number; - altText?: string; - transcript?: string; -}; - -export type QaBusMessage = { - id: string; - accountId: string; - direction: "inbound" | "outbound"; - conversation: QaBusConversation; - senderId: string; - senderName?: string; - text: string; - timestamp: number; - threadId?: string; - threadTitle?: string; - replyToId?: string; - deleted?: boolean; - editedAt?: number; - attachments?: QaBusAttachment[]; - reactions: Array<{ - emoji: string; - senderId: string; - timestamp: number; - }>; -}; - -export type QaBusThread = { - id: string; - accountId: string; - conversationId: string; - title: string; - createdAt: number; - createdBy: string; -}; - -export type QaBusEvent = - | { cursor: number; kind: "inbound-message"; accountId: string; message: QaBusMessage } - | { cursor: number; kind: "outbound-message"; accountId: string; message: QaBusMessage } - | { cursor: number; kind: "thread-created"; accountId: string; thread: QaBusThread } - | { cursor: number; kind: "message-edited"; accountId: string; message: QaBusMessage } - | { cursor: number; kind: "message-deleted"; accountId: string; message: QaBusMessage } - | { - cursor: number; - kind: "reaction-added"; - accountId: string; - message: QaBusMessage; - emoji: string; - senderId: string; - }; - -export type QaBusInboundMessageInput = { - accountId?: string; - conversation: QaBusConversation; - senderId: string; - senderName?: string; - text: string; - timestamp?: number; - threadId?: string; - threadTitle?: string; - replyToId?: string; - attachments?: QaBusAttachment[]; -}; - -export type QaBusOutboundMessageInput = { - accountId?: string; - to: string; - senderId?: string; - senderName?: string; - text: string; - timestamp?: number; - threadId?: string; - replyToId?: string; - attachments?: QaBusAttachment[]; -}; - -export type QaBusCreateThreadInput = { - accountId?: string; - conversationId: string; - title: string; - createdBy?: string; - timestamp?: number; -}; - -export type QaBusReactToMessageInput = { - accountId?: string; - messageId: string; - emoji: string; - senderId?: string; - timestamp?: number; -}; - -export type QaBusEditMessageInput = { - accountId?: string; - messageId: string; - text: string; - timestamp?: number; -}; - -export type QaBusDeleteMessageInput = { - accountId?: string; - messageId: string; - timestamp?: number; -}; - -export type QaBusSearchMessagesInput = { - accountId?: string; - query?: string; - conversationId?: string; - threadId?: string; - limit?: number; -}; - -export type QaBusReadMessageInput = { - accountId?: string; - messageId: string; -}; - -export type QaBusPollInput = { - accountId?: string; - cursor?: number; - timeoutMs?: number; - limit?: number; -}; - -export type QaBusPollResult = { - cursor: number; - events: QaBusEvent[]; -}; - -export type QaBusStateSnapshot = { - cursor: number; - conversations: QaBusConversation[]; - threads: QaBusThread[]; - messages: QaBusMessage[]; - events: QaBusEvent[]; -}; - -export type QaBusWaitForInput = - | { - timeoutMs?: number; - kind: "event-kind"; - eventKind: QaBusEvent["kind"]; - } - | { - timeoutMs?: number; - kind: "message-text"; - textIncludes: string; - direction?: QaBusMessage["direction"]; - } - | { - timeoutMs?: number; - kind: "thread-id"; - threadId: string; - }; +export type * from "./qa-channel-protocol.js"; type QaTargetParts = { chatType: "direct" | "channel";