@assistant-ui/react 0.10.22 → 0.10.24
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/cloud/AssistantCloudThreadHistoryAdapter.d.ts +1 -1
- package/dist/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/cloud/auiV0.d.ts +1 -1
- package/dist/cloud/auiV0.d.ts.map +1 -1
- package/dist/cloud/auiV0.js.map +1 -1
- package/dist/cloud/index.d.ts +1 -1
- package/dist/cloud/index.d.ts.map +1 -1
- package/dist/cloud/index.js +1 -1
- package/dist/cloud/index.js.map +1 -1
- package/dist/cloud/useCloudThreadListRuntime.d.ts +1 -1
- package/dist/cloud/useCloudThreadListRuntime.d.ts.map +1 -1
- package/dist/cloud/useCloudThreadListRuntime.js.map +1 -1
- package/dist/context/react/AssistantContext.d.ts +23 -0
- package/dist/context/react/AssistantContext.d.ts.map +1 -1
- package/dist/context/react/AssistantContext.js.map +1 -1
- package/dist/context/react/ComposerContext.d.ts +64 -0
- package/dist/context/react/ComposerContext.d.ts.map +1 -1
- package/dist/context/react/ComposerContext.js.map +1 -1
- package/dist/context/react/MessageContext.d.ts +56 -0
- package/dist/context/react/MessageContext.d.ts.map +1 -1
- package/dist/context/react/MessageContext.js.map +1 -1
- package/dist/context/react/ThreadContext.d.ts +42 -0
- package/dist/context/react/ThreadContext.d.ts.map +1 -1
- package/dist/context/react/ThreadContext.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.d.ts +42 -0
- package/dist/primitives/actionBar/ActionBarCopy.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarEdit.d.ts +38 -0
- package/dist/primitives/actionBar/ActionBarEdit.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarEdit.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarReload.d.ts +39 -0
- package/dist/primitives/actionBar/ActionBarReload.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarReload.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarRoot.d.ts +56 -0
- package/dist/primitives/actionBar/ActionBarRoot.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarRoot.js.map +1 -1
- package/dist/primitives/attachment/AttachmentRoot.d.ts +18 -0
- package/dist/primitives/attachment/AttachmentRoot.d.ts.map +1 -1
- package/dist/primitives/attachment/AttachmentRoot.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerCount.d.ts +17 -0
- package/dist/primitives/branchPicker/BranchPickerCount.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerCount.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerNext.d.ts +17 -0
- package/dist/primitives/branchPicker/BranchPickerNext.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerNext.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerPrevious.d.ts +38 -0
- package/dist/primitives/branchPicker/BranchPickerPrevious.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerPrevious.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerRoot.d.ts +27 -0
- package/dist/primitives/branchPicker/BranchPickerRoot.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerRoot.js.map +1 -1
- package/dist/primitives/composer/ComposerAttachments.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerAttachments.js +11 -8
- package/dist/primitives/composer/ComposerAttachments.js.map +1 -1
- package/dist/primitives/composer/ComposerCancel.d.ts +17 -0
- package/dist/primitives/composer/ComposerCancel.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerCancel.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.d.ts +72 -0
- package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerRoot.d.ts +19 -0
- package/dist/primitives/composer/ComposerRoot.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerRoot.js.map +1 -1
- package/dist/primitives/composer/ComposerSend.d.ts +18 -0
- package/dist/primitives/composer/ComposerSend.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerSend.js.map +1 -1
- package/dist/primitives/contentPart/ContentPartImage.d.ts +19 -0
- package/dist/primitives/contentPart/ContentPartImage.d.ts.map +1 -1
- package/dist/primitives/contentPart/ContentPartImage.js.map +1 -1
- package/dist/primitives/contentPart/ContentPartText.d.ts +34 -0
- package/dist/primitives/contentPart/ContentPartText.d.ts.map +1 -1
- package/dist/primitives/contentPart/ContentPartText.js.map +1 -1
- package/dist/primitives/message/MessageAttachments.d.ts.map +1 -1
- package/dist/primitives/message/MessageAttachments.js +11 -8
- package/dist/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/primitives/message/MessageContent.d.ts +41 -0
- package/dist/primitives/message/MessageContent.d.ts.map +1 -1
- package/dist/primitives/message/MessageContent.js +14 -11
- package/dist/primitives/message/MessageContent.js.map +1 -1
- package/dist/primitives/message/MessageRoot.d.ts +22 -0
- package/dist/primitives/message/MessageRoot.d.ts.map +1 -1
- package/dist/primitives/message/MessageRoot.js.map +1 -1
- package/dist/primitives/thread/ThreadMessages.d.ts +44 -0
- package/dist/primitives/thread/ThreadMessages.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadMessages.js +5 -2
- package/dist/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/primitives/thread/ThreadRoot.d.ts +19 -0
- package/dist/primitives/thread/ThreadRoot.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadRoot.js.map +1 -1
- package/dist/primitives/thread/ThreadViewport.d.ts +24 -0
- package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadViewport.js.map +1 -1
- package/dist/primitives/threadList/ThreadListItems.d.ts.map +1 -1
- package/dist/primitives/threadList/ThreadListItems.js +12 -9
- package/dist/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/runtimes/adapters/attachment/AttachmentAdapter.d.ts +54 -0
- package/dist/runtimes/adapters/attachment/AttachmentAdapter.d.ts.map +1 -1
- package/dist/runtimes/adapters/feedback/FeedbackAdapter.d.ts +33 -0
- package/dist/runtimes/adapters/feedback/FeedbackAdapter.d.ts.map +1 -1
- package/dist/runtimes/adapters/speech/SpeechAdapterTypes.d.ts +47 -0
- package/dist/runtimes/adapters/speech/SpeechAdapterTypes.d.ts.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.d.ts +2 -2
- package/dist/runtimes/local/LocalRuntimeOptions.d.ts.map +1 -1
- package/dist/runtimes/local/LocalRuntimeOptions.js.map +1 -1
- package/dist/runtimes/local/index.d.ts +1 -1
- package/dist/runtimes/local/index.d.ts.map +1 -1
- package/dist/runtimes/local/index.js +3 -2
- package/dist/runtimes/local/index.js.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/cloud.d.ts +1 -1
- package/dist/runtimes/remote-thread-list/adapter/cloud.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/cloud.js +1 -1
- package/dist/runtimes/remote-thread-list/adapter/cloud.js.map +1 -1
- package/dist/tests/setup.js +8 -8
- package/dist/tests/setup.js.map +1 -1
- package/package.json +8 -7
- package/src/cloud/AssistantCloudThreadHistoryAdapter.tsx +1 -1
- package/src/cloud/auiV0.ts +1 -1
- package/src/cloud/index.ts +1 -1
- package/src/cloud/useCloudThreadListRuntime.tsx +1 -1
- package/src/context/react/AssistantContext.ts +23 -0
- package/src/context/react/ComposerContext.ts +64 -0
- package/src/context/react/MessageContext.ts +56 -0
- package/src/context/react/ThreadContext.ts +42 -0
- package/src/primitives/actionBar/ActionBarCopy.tsx +42 -0
- package/src/primitives/actionBar/ActionBarEdit.tsx +38 -0
- package/src/primitives/actionBar/ActionBarReload.tsx +39 -0
- package/src/primitives/actionBar/ActionBarRoot.tsx +38 -0
- package/src/primitives/attachment/AttachmentRoot.tsx +18 -0
- package/src/primitives/branchPicker/BranchPickerCount.tsx +17 -0
- package/src/primitives/branchPicker/BranchPickerNext.tsx +17 -0
- package/src/primitives/branchPicker/BranchPickerPrevious.tsx +38 -0
- package/src/primitives/branchPicker/BranchPickerRoot.tsx +22 -0
- package/src/primitives/composer/ComposerAttachments.tsx +11 -7
- package/src/primitives/composer/ComposerCancel.tsx +17 -0
- package/src/primitives/composer/ComposerInput.tsx +44 -0
- package/src/primitives/composer/ComposerRoot.tsx +19 -0
- package/src/primitives/composer/ComposerSend.tsx +18 -0
- package/src/primitives/contentPart/ContentPartImage.tsx +19 -0
- package/src/primitives/contentPart/ContentPartText.tsx +25 -0
- package/src/primitives/message/MessageAttachments.tsx +11 -7
- package/src/primitives/message/MessageContent.tsx +54 -18
- package/src/primitives/message/MessageRoot.tsx +22 -0
- package/src/primitives/thread/ThreadMessages.tsx +52 -4
- package/src/primitives/thread/ThreadRoot.tsx +19 -0
- package/src/primitives/thread/ThreadViewport.tsx +19 -0
- package/src/primitives/threadList/ThreadListItems.tsx +12 -8
- package/src/runtimes/adapters/attachment/AttachmentAdapter.ts +56 -0
- package/src/runtimes/adapters/feedback/FeedbackAdapter.ts +33 -0
- package/src/runtimes/adapters/speech/SpeechAdapterTypes.ts +47 -0
- package/src/runtimes/local/LocalRuntimeOptions.tsx +1 -1
- package/src/runtimes/local/index.ts +1 -1
- package/src/runtimes/remote-thread-list/adapter/cloud.tsx +1 -1
- package/dist/cloud/AssistantCloud.d.ts +0 -15
- package/dist/cloud/AssistantCloud.d.ts.map +0 -1
- package/dist/cloud/AssistantCloud.js +0 -25
- package/dist/cloud/AssistantCloud.js.map +0 -1
- package/dist/cloud/AssistantCloudAPI.d.ts +0 -28
- package/dist/cloud/AssistantCloudAPI.d.ts.map +0 -1
- package/dist/cloud/AssistantCloudAPI.js +0 -87
- package/dist/cloud/AssistantCloudAPI.js.map +0 -1
- package/dist/cloud/AssistantCloudAuthStrategy.d.ts +0 -30
- package/dist/cloud/AssistantCloudAuthStrategy.d.ts.map +0 -1
- package/dist/cloud/AssistantCloudAuthStrategy.js +0 -139
- package/dist/cloud/AssistantCloudAuthStrategy.js.map +0 -1
- package/dist/cloud/AssistantCloudAuthTokens.d.ts +0 -11
- package/dist/cloud/AssistantCloudAuthTokens.d.ts.map +0 -1
- package/dist/cloud/AssistantCloudAuthTokens.js +0 -13
- package/dist/cloud/AssistantCloudAuthTokens.js.map +0 -1
- package/dist/cloud/AssistantCloudFiles.d.ts +0 -27
- package/dist/cloud/AssistantCloudFiles.d.ts.map +0 -1
- package/dist/cloud/AssistantCloudFiles.js +0 -22
- package/dist/cloud/AssistantCloudFiles.js.map +0 -1
- package/dist/cloud/AssistantCloudRuns.d.ts +0 -26
- package/dist/cloud/AssistantCloudRuns.d.ts.map +0 -1
- package/dist/cloud/AssistantCloudRuns.js +0 -39
- package/dist/cloud/AssistantCloudRuns.js.map +0 -1
- package/dist/cloud/AssistantCloudThreadMessages.d.ts +0 -30
- package/dist/cloud/AssistantCloudThreadMessages.d.ts.map +0 -1
- package/dist/cloud/AssistantCloudThreadMessages.js +0 -21
- package/dist/cloud/AssistantCloudThreadMessages.js.map +0 -1
- package/dist/cloud/AssistantCloudThreads.d.ts +0 -48
- package/dist/cloud/AssistantCloudThreads.d.ts.map +0 -1
- package/dist/cloud/AssistantCloudThreads.js +0 -30
- package/dist/cloud/AssistantCloudThreads.js.map +0 -1
- package/src/cloud/AssistantCloud.tsx +0 -22
- package/src/cloud/AssistantCloudAPI.tsx +0 -121
- package/src/cloud/AssistantCloudAuthStrategy.tsx +0 -193
- package/src/cloud/AssistantCloudAuthTokens.tsx +0 -13
- package/src/cloud/AssistantCloudFiles.tsx +0 -45
- package/src/cloud/AssistantCloudRuns.tsx +0 -45
- package/src/cloud/AssistantCloudThreadMessages.tsx +0 -48
- package/src/cloud/AssistantCloudThreads.tsx +0 -79
- package/src/tests/AssistantCloudFiles.test.ts +0 -521
@@ -1,5 +1,5 @@
|
|
1
1
|
import { RefObject } from "react";
|
2
2
|
import { ThreadHistoryAdapter } from "../runtimes/adapters/thread-history/ThreadHistoryAdapter";
|
3
|
-
import { AssistantCloud } from "
|
3
|
+
import { AssistantCloud } from "assistant-cloud";
|
4
4
|
export declare const useAssistantCloudThreadHistoryAdapter: (cloudRef: RefObject<AssistantCloud>) => ThreadHistoryAdapter;
|
5
5
|
//# sourceMappingURL=AssistantCloudThreadHistoryAdapter.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AssistantCloudThreadHistoryAdapter.d.ts","sourceRoot":"","sources":["../../src/cloud/AssistantCloudThreadHistoryAdapter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0DAA0D,CAAC;AAEhG,OAAO,EAAE,cAAc,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"AssistantCloudThreadHistoryAdapter.d.ts","sourceRoot":"","sources":["../../src/cloud/AssistantCloudThreadHistoryAdapter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0DAA0D,CAAC;AAEhG,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAiDjD,eAAO,MAAM,qCAAqC,GAChD,UAAU,SAAS,CAAC,cAAc,CAAC,KAClC,oBAQF,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/cloud/AssistantCloudThreadHistoryAdapter.tsx"],"sourcesContent":["import { RefObject, useState } from \"react\";\nimport { useThreadListItemRuntime } from \"../context\";\nimport { ThreadHistoryAdapter } from \"../runtimes/adapters/thread-history/ThreadHistoryAdapter\";\nimport { ExportedMessageRepositoryItem } from \"../runtimes/utils/MessageRepository\";\nimport { AssistantCloud } from \"
|
1
|
+
{"version":3,"sources":["../../src/cloud/AssistantCloudThreadHistoryAdapter.tsx"],"sourcesContent":["import { RefObject, useState } from \"react\";\nimport { useThreadListItemRuntime } from \"../context\";\nimport { ThreadHistoryAdapter } from \"../runtimes/adapters/thread-history/ThreadHistoryAdapter\";\nimport { ExportedMessageRepositoryItem } from \"../runtimes/utils/MessageRepository\";\nimport { AssistantCloud } from \"assistant-cloud\";\nimport { auiV0Decode, auiV0Encode } from \"./auiV0\";\nimport { ThreadListItemRuntime } from \"../api\";\n\nclass AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {\n constructor(\n private cloudRef: RefObject<AssistantCloud>,\n private threadListItemRuntime: ThreadListItemRuntime,\n ) {}\n\n private _getIdForLocalId: Record<string, string | Promise<string>> = {};\n\n async append({ parentId, message }: ExportedMessageRepositoryItem) {\n const { remoteId } = await this.threadListItemRuntime.initialize();\n const task = this.cloudRef.current.threads.messages\n .create(remoteId, {\n parent_id: parentId\n ? ((await this._getIdForLocalId[parentId]) ?? parentId)\n : null,\n format: \"aui/v0\",\n content: auiV0Encode(message),\n })\n .then(({ message_id }) => {\n this._getIdForLocalId[message.id] = message_id;\n return message_id;\n });\n\n this._getIdForLocalId[message.id] = task;\n\n return task.then(() => {});\n }\n\n async load() {\n const remoteId = this.threadListItemRuntime.getState().remoteId;\n if (!remoteId) return { messages: [] };\n const { messages } =\n await this.cloudRef.current.threads.messages.list(remoteId);\n const payload = {\n messages: messages\n .filter(\n (m): m is typeof m & { format: \"aui/v0\" } => m.format === \"aui/v0\",\n )\n .map(auiV0Decode)\n .reverse(),\n };\n return payload;\n }\n}\n\nexport const useAssistantCloudThreadHistoryAdapter = (\n cloudRef: RefObject<AssistantCloud>,\n): ThreadHistoryAdapter => {\n const threadListItemRuntime = useThreadListItemRuntime();\n const [adapter] = useState(\n () =>\n new AssistantCloudThreadHistoryAdapter(cloudRef, threadListItemRuntime),\n );\n\n return adapter;\n};\n"],"mappings":";AAAA,SAAoB,gBAAgB;AACpC,SAAS,gCAAgC;AAIzC,SAAS,aAAa,mBAAmB;AAGzC,IAAM,qCA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} from "../types/AssistantTypes";
|
3
|
-
import { CloudMessage } from "
|
3
|
+
import { CloudMessage } from "assistant-cloud";
|
4
4
|
import { ReadonlyJSONObject, ReadonlyJSONValue } from "assistant-stream/utils";
|
5
5
|
import { ExportedMessageRepositoryItem } from "../runtimes/utils/MessageRepository";
|
6
6
|
type AuiV0MessageContentPart = {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"auiV0.d.ts","sourceRoot":"","sources":["../../src/cloud/auiV0.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"auiV0.d.ts","sourceRoot":"","sources":["../../src/cloud/auiV0.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,6BAA6B,EAAE,MAAM,qCAAqC,CAAC;AAEpF,KAAK,uBAAuB,GACxB;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,CAA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C,MAAM,EAAE,kBAAkB,CAAC;KACrC,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,SAAS,aAAa,KAAG,YA2EpD,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,cAAc,YAAY,GAAG;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,KAChD,6BAmBF,CAAC"}
|
package/dist/cloud/auiV0.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/cloud/auiV0.ts"],"sourcesContent":["import { ThreadMessage } from \"../types\";\nimport { MessageStatus } from \"../types/AssistantTypes\";\nimport { fromThreadMessageLike } from \"../runtimes/external-store/ThreadMessageLike\";\nimport { CloudMessage } from \"
|
1
|
+
{"version":3,"sources":["../../src/cloud/auiV0.ts"],"sourcesContent":["import { ThreadMessage } from \"../types\";\nimport { MessageStatus } from \"../types/AssistantTypes\";\nimport { fromThreadMessageLike } from \"../runtimes/external-store/ThreadMessageLike\";\nimport { CloudMessage } from \"assistant-cloud\";\nimport { isJSONValue } from \"../utils/json/is-json\";\nimport { ReadonlyJSONObject, ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport { ExportedMessageRepositoryItem } from \"../runtimes/utils/MessageRepository\";\n\ntype AuiV0MessageContentPart =\n | {\n readonly type: \"text\";\n readonly text: string;\n }\n | {\n readonly type: \"reasoning\";\n readonly text: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: ReadonlyJSONObject;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly argsText: string;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n };\n\ntype AuiV0Message = {\n readonly role: \"assistant\" | \"user\" | \"system\";\n readonly status?: MessageStatus;\n readonly content: readonly AuiV0MessageContentPart[];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly {\n readonly usage?: {\n readonly promptTokens: number;\n readonly completionTokens: number;\n };\n }[];\n readonly custom: ReadonlyJSONObject;\n };\n};\n\nexport const auiV0Encode = (message: ThreadMessage): AuiV0Message => {\n // TODO attachments are currently intentionally ignored\n // info: ID and createdAt are ignored (we use the server value instead)\n return {\n role: message.role,\n content: message.content.map((part) => {\n const type = part.type;\n switch (type) {\n case \"text\": {\n return {\n type: \"text\",\n text: part.text,\n };\n }\n\n case \"reasoning\": {\n return {\n type: \"reasoning\",\n text: part.text,\n };\n }\n\n case \"source\": {\n return {\n type: \"source\",\n sourceType: part.sourceType,\n id: part.id,\n url: part.url,\n ...(part.title ? { title: part.title } : undefined),\n };\n }\n\n case \"tool-call\": {\n if (!isJSONValue(part.result)) {\n console.warn(\n \"tool-call result is not JSON! \" + JSON.stringify(part),\n );\n }\n return {\n type: \"tool-call\",\n toolCallId: part.toolCallId,\n toolName: part.toolName,\n ...(JSON.stringify(part.args) === part.argsText\n ? {\n args: part.args,\n }\n : { argsText: part.argsText }),\n ...(part.result\n ? { result: part.result as ReadonlyJSONValue }\n : {}),\n ...(part.isError ? { isError: true } : {}),\n };\n }\n\n default: {\n const unhandledType: \"image\" | \"file\" | \"audio\" = type;\n throw new Error(\n `Content part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n }),\n metadata: message.metadata as AuiV0Message[\"metadata\"],\n ...(message.status\n ? {\n status:\n message.status?.type === \"running\"\n ? {\n type: \"incomplete\",\n reason: \"cancelled\",\n }\n : message.status,\n }\n : undefined),\n };\n};\n\nexport const auiV0Decode = (\n cloudMessage: CloudMessage & { format: \"aui/v0\" },\n): ExportedMessageRepositoryItem => {\n const payload = cloudMessage.content as unknown as AuiV0Message;\n const message = fromThreadMessageLike(\n {\n id: cloudMessage.id,\n createdAt: cloudMessage.created_at,\n ...payload,\n },\n cloudMessage.id,\n {\n type: \"complete\",\n reason: \"unknown\",\n },\n );\n\n return {\n parentId: cloudMessage.parent_id,\n message,\n };\n};\n"],"mappings":";AAEA,SAAS,6BAA6B;AAEtC,SAAS,mBAAmB;AAuDrB,IAAM,cAAc,CAAC,YAAyC;AAGnE,SAAO;AAAA,IACL,MAAM,QAAQ;AAAA,IACd,SAAS,QAAQ,QAAQ,IAAI,CAAC,SAAS;AACrC,YAAM,OAAO,KAAK;AAClB,cAAQ,MAAM;AAAA,QACZ,KAAK,QAAQ;AACX,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,MAAM,KAAK;AAAA,UACb;AAAA,QACF;AAAA,QAEA,KAAK,aAAa;AAChB,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,MAAM,KAAK;AAAA,UACb;AAAA,QACF;AAAA,QAEA,KAAK,UAAU;AACb,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,YAAY,KAAK;AAAA,YACjB,IAAI,KAAK;AAAA,YACT,KAAK,KAAK;AAAA,YACV,GAAI,KAAK,QAAQ,EAAE,OAAO,KAAK,MAAM,IAAI;AAAA,UAC3C;AAAA,QACF;AAAA,QAEA,KAAK,aAAa;AAChB,cAAI,CAAC,YAAY,KAAK,MAAM,GAAG;AAC7B,oBAAQ;AAAA,cACN,mCAAmC,KAAK,UAAU,IAAI;AAAA,YACxD;AAAA,UACF;AACA,iBAAO;AAAA,YACL,MAAM;AAAA,YACN,YAAY,KAAK;AAAA,YACjB,UAAU,KAAK;AAAA,YACf,GAAI,KAAK,UAAU,KAAK,IAAI,MAAM,KAAK,WACnC;AAAA,cACE,MAAM,KAAK;AAAA,YACb,IACA,EAAE,UAAU,KAAK,SAAS;AAAA,YAC9B,GAAI,KAAK,SACL,EAAE,QAAQ,KAAK,OAA4B,IAC3C,CAAC;AAAA,YACL,GAAI,KAAK,UAAU,EAAE,SAAS,KAAK,IAAI,CAAC;AAAA,UAC1C;AAAA,QACF;AAAA,QAEA,SAAS;AACP,gBAAM,gBAA4C;AAClD,gBAAM,IAAI;AAAA,YACR,8CAA8C,aAAa;AAAA,UAC7D;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,IACD,UAAU,QAAQ;AAAA,IAClB,GAAI,QAAQ,SACR;AAAA,MACE,QACE,QAAQ,QAAQ,SAAS,YACrB;AAAA,QACE,MAAM;AAAA,QACN,QAAQ;AAAA,MACV,IACA,QAAQ;AAAA,IAChB,IACA;AAAA,EACN;AACF;AAEO,IAAM,cAAc,CACzB,iBACkC;AAClC,QAAM,UAAU,aAAa;AAC7B,QAAM,UAAU;AAAA,IACd;AAAA,MACE,IAAI,aAAa;AAAA,MACjB,WAAW,aAAa;AAAA,MACxB,GAAG;AAAA,IACL;AAAA,IACA,aAAa;AAAA,IACb;AAAA,MACE,MAAM;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF;AAEA,SAAO;AAAA,IACL,UAAU,aAAa;AAAA,IACvB;AAAA,EACF;AACF;","names":[]}
|
package/dist/cloud/index.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cloud/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cloud/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/cloud/index.js
CHANGED
package/dist/cloud/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/cloud/index.ts"],"sourcesContent":["export { useCloudThreadListRuntime } from \"./useCloudThreadListRuntime\";\nexport { AssistantCloud } from \"
|
1
|
+
{"version":3,"sources":["../../src/cloud/index.ts"],"sourcesContent":["export { useCloudThreadListRuntime } from \"./useCloudThreadListRuntime\";\nexport { AssistantCloud } from \"assistant-cloud\";\n"],"mappings":";AAAA,SAAS,iCAAiC;AAC1C,SAAS,sBAAsB;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useCloudThreadListRuntime.d.ts","sourceRoot":"","sources":["../../src/cloud/useCloudThreadListRuntime.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"useCloudThreadListRuntime.d.ts","sourceRoot":"","sources":["../../src/cloud/useCloudThreadListRuntime.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAI1C,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAC;IAEtB,WAAW,EAAE,MAAM,gBAAgB,CAAC;IAEpC,MAAM,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/B,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,oCAGvC,sBAAsB,+CAQxB,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/cloud/useCloudThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { AssistantCloud } from \"
|
1
|
+
{"version":3,"sources":["../../src/cloud/useCloudThreadListRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport { AssistantCloud } from \"assistant-cloud\";\nimport { AssistantRuntime } from \"../api\";\nimport { useRemoteThreadListRuntime } from \"../runtimes/remote-thread-list/useRemoteThreadListRuntime\";\nimport { useCloudThreadListAdapter } from \"../runtimes/remote-thread-list/adapter/cloud\";\n\ntype ThreadData = {\n externalId: string;\n};\n\ntype CloudThreadListAdapter = {\n cloud: AssistantCloud;\n\n runtimeHook: () => AssistantRuntime;\n\n create?(): Promise<ThreadData>;\n delete?(threadId: string): Promise<void>;\n};\n\nexport const useCloudThreadListRuntime = ({\n runtimeHook,\n ...adapterOptions\n}: CloudThreadListAdapter) => {\n const adapter = useCloudThreadListAdapter(adapterOptions);\n const runtime = useRemoteThreadListRuntime({\n runtimeHook: runtimeHook,\n adapter,\n });\n\n return runtime;\n};\n"],"mappings":";;;AAIA,SAAS,kCAAkC;AAC3C,SAAS,iCAAiC;AAenC,IAAM,4BAA4B,CAAC;AAAA,EACxC;AAAA,EACA,GAAG;AACL,MAA8B;AAC5B,QAAM,UAAU,0BAA0B,cAAc;AACxD,QAAM,UAAU,2BAA2B;AAAA,IACzC;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":[]}
|
@@ -10,6 +10,29 @@ export declare const AssistantContext: import("react").Context<AssistantContextV
|
|
10
10
|
export declare const useAssistantContext: (options?: {
|
11
11
|
optional?: boolean | undefined;
|
12
12
|
} | undefined) => AssistantContextValue | null;
|
13
|
+
/**
|
14
|
+
* Hook to access the AssistantRuntime from the current context.
|
15
|
+
*
|
16
|
+
* The AssistantRuntime provides access to the top-level assistant state and actions,
|
17
|
+
* including thread management, tool registration, and configuration.
|
18
|
+
*
|
19
|
+
* @param options Configuration options
|
20
|
+
* @param options.optional Whether the hook should return null if no context is found
|
21
|
+
* @returns The AssistantRuntime instance, or null if optional is true and no context exists
|
22
|
+
*
|
23
|
+
* @example
|
24
|
+
* ```tsx
|
25
|
+
* function MyComponent() {
|
26
|
+
* const runtime = useAssistantRuntime();
|
27
|
+
*
|
28
|
+
* const handleNewThread = () => {
|
29
|
+
* runtime.switchToNewThread();
|
30
|
+
* };
|
31
|
+
*
|
32
|
+
* return <button onClick={handleNewThread}>New Thread</button>;
|
33
|
+
* }
|
34
|
+
* ```
|
35
|
+
*/
|
13
36
|
export declare function useAssistantRuntime(options?: {
|
14
37
|
optional?: false | undefined;
|
15
38
|
}): AssistantRuntime;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AssistantContext.d.ts","sourceRoot":"","sources":["../../../src/context/react/AssistantContext.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAI9D,MAAM,MAAM,qBAAqB,GAAG;IAClC,mBAAmB,EAAE,aAAa,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACpE,UAAU,EAAE,aAAa,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC,CAAC;CACjE,CAAC;AAEF,eAAO,MAAM,gBAAgB,uDAE5B,CAAC;AAEF,eAAO,MAAM,mBAAmB;;8CAG/B,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE;IAC5C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,gBAAgB,CAAC;AACrB,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE;IAC5C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,gBAAgB,GAAG,IAAI,CAAC;AAS5B,eAAO,MAAQ,UAAU;;;;;;;;;;GAAE,eAAe;;;;;CAGzC,CAAC;AAKF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;CAAkD,CAAC"}
|
1
|
+
{"version":3,"file":"AssistantContext.d.ts","sourceRoot":"","sources":["../../../src/context/react/AssistantContext.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAI9D,MAAM,MAAM,qBAAqB,GAAG;IAClC,mBAAmB,EAAE,aAAa,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACpE,UAAU,EAAE,aAAa,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC,CAAC;CACjE,CAAC;AAEF,eAAO,MAAM,gBAAgB,uDAE5B,CAAC;AAEF,eAAO,MAAM,mBAAmB;;8CAG/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE;IAC5C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,gBAAgB,CAAC;AACrB,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE;IAC5C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,gBAAgB,GAAG,IAAI,CAAC;AAS5B,eAAO,MAAQ,UAAU;;;;;;;;;;GAAE,eAAe;;;;;CAGzC,CAAC;AAKF,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;CAAkD,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/context/react/AssistantContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport type { AssistantToolUIsState } from \"../stores/AssistantToolUIs\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { createContextStoreHook } from \"./utils/createContextStoreHook\";\nimport { UseBoundStore } from \"zustand\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { ThreadListRuntime } from \"../../api/ThreadListRuntime\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\n\nexport type AssistantContextValue = {\n useAssistantRuntime: UseBoundStore<ReadonlyStore<AssistantRuntime>>;\n useToolUIs: UseBoundStore<ReadonlyStore<AssistantToolUIsState>>;\n};\n\nexport const AssistantContext = createContext<AssistantContextValue | null>(\n null,\n);\n\nexport const useAssistantContext = createContextHook(\n AssistantContext,\n \"AssistantRuntimeProvider\",\n);\n\nexport function useAssistantRuntime(options?: {\n optional?: false | undefined;\n}): AssistantRuntime;\nexport function useAssistantRuntime(options?: {\n optional?: boolean | undefined;\n}): AssistantRuntime | null;\nexport function useAssistantRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const context = useAssistantContext(options);\n if (!context) return null;\n return context.useAssistantRuntime();\n}\n\nexport const { useToolUIs, useToolUIsStore } = createContextStoreHook(\n useAssistantContext,\n \"useToolUIs\",\n);\n\nconst useThreadListRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadListRuntime | null => useAssistantRuntime(opt)?.threads ?? null;\nexport const useThreadList = createStateHookForRuntime(useThreadListRuntime);\n"],"mappings":";;;AAEA,SAAS,qBAAqB;AAG9B,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AAIvC,SAAS,iCAAiC;AAOnC,IAAM,mBAAmB;AAAA,EAC9B;AACF;AAEO,IAAM,sBAAsB;AAAA,EACjC;AAAA,EACA;AACF;
|
1
|
+
{"version":3,"sources":["../../../src/context/react/AssistantContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport type { AssistantToolUIsState } from \"../stores/AssistantToolUIs\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { createContextStoreHook } from \"./utils/createContextStoreHook\";\nimport { UseBoundStore } from \"zustand\";\nimport { AssistantRuntime } from \"../../api/AssistantRuntime\";\nimport { ThreadListRuntime } from \"../../api/ThreadListRuntime\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\n\nexport type AssistantContextValue = {\n useAssistantRuntime: UseBoundStore<ReadonlyStore<AssistantRuntime>>;\n useToolUIs: UseBoundStore<ReadonlyStore<AssistantToolUIsState>>;\n};\n\nexport const AssistantContext = createContext<AssistantContextValue | null>(\n null,\n);\n\nexport const useAssistantContext = createContextHook(\n AssistantContext,\n \"AssistantRuntimeProvider\",\n);\n\n/**\n * Hook to access the AssistantRuntime from the current context.\n *\n * The AssistantRuntime provides access to the top-level assistant state and actions,\n * including thread management, tool registration, and configuration.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The AssistantRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const runtime = useAssistantRuntime();\n *\n * const handleNewThread = () => {\n * runtime.switchToNewThread();\n * };\n *\n * return <button onClick={handleNewThread}>New Thread</button>;\n * }\n * ```\n */\nexport function useAssistantRuntime(options?: {\n optional?: false | undefined;\n}): AssistantRuntime;\nexport function useAssistantRuntime(options?: {\n optional?: boolean | undefined;\n}): AssistantRuntime | null;\nexport function useAssistantRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const context = useAssistantContext(options);\n if (!context) return null;\n return context.useAssistantRuntime();\n}\n\nexport const { useToolUIs, useToolUIsStore } = createContextStoreHook(\n useAssistantContext,\n \"useToolUIs\",\n);\n\nconst useThreadListRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadListRuntime | null => useAssistantRuntime(opt)?.threads ?? null;\nexport const useThreadList = createStateHookForRuntime(useThreadListRuntime);\n"],"mappings":";;;AAEA,SAAS,qBAAqB;AAG9B,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AAIvC,SAAS,iCAAiC;AAOnC,IAAM,mBAAmB;AAAA,EAC9B;AACF;AAEO,IAAM,sBAAsB;AAAA,EACjC;AAAA,EACA;AACF;AA+BO,SAAS,oBAAoB,SAEjC;AACD,QAAM,UAAU,oBAAoB,OAAO;AAC3C,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,oBAAoB;AACrC;AAEO,IAAM,EAAE,YAAY,gBAAgB,IAAI;AAAA,EAC7C;AAAA,EACA;AACF;AAEA,IAAM,uBAAuB,CAAC,QAEE,oBAAoB,GAAG,GAAG,WAAW;AAC9D,IAAM,gBAAgB,0BAA0B,oBAAoB;","names":[]}
|
@@ -1,10 +1,74 @@
|
|
1
1
|
import { ComposerRuntime } from "../../api/ComposerRuntime";
|
2
|
+
/**
|
3
|
+
* Hook to access the ComposerRuntime from the current context.
|
4
|
+
*
|
5
|
+
* The ComposerRuntime provides access to composer state and actions for message
|
6
|
+
* composition, including text input, attachments, and sending functionality.
|
7
|
+
* This hook automatically resolves to either the message's edit composer or
|
8
|
+
* the thread's main composer depending on the context.
|
9
|
+
*
|
10
|
+
* @param options Configuration options
|
11
|
+
* @param options.optional Whether the hook should return null if no context is found
|
12
|
+
* @returns The ComposerRuntime instance, or null if optional is true and no context exists
|
13
|
+
*
|
14
|
+
* @example
|
15
|
+
* ```tsx
|
16
|
+
* function ComposerActions() {
|
17
|
+
* const runtime = useComposerRuntime();
|
18
|
+
*
|
19
|
+
* const handleSend = () => {
|
20
|
+
* if (runtime.getState().canSend) {
|
21
|
+
* runtime.send();
|
22
|
+
* }
|
23
|
+
* };
|
24
|
+
*
|
25
|
+
* const handleCancel = () => {
|
26
|
+
* if (runtime.getState().canCancel) {
|
27
|
+
* runtime.cancel();
|
28
|
+
* }
|
29
|
+
* };
|
30
|
+
*
|
31
|
+
* return (
|
32
|
+
* <div>
|
33
|
+
* <button onClick={handleSend}>Send</button>
|
34
|
+
* <button onClick={handleCancel}>Cancel</button>
|
35
|
+
* </div>
|
36
|
+
* );
|
37
|
+
* }
|
38
|
+
* ```
|
39
|
+
*/
|
2
40
|
export declare function useComposerRuntime(options?: {
|
3
41
|
optional?: false | undefined;
|
4
42
|
}): ComposerRuntime;
|
5
43
|
export declare function useComposerRuntime(options?: {
|
6
44
|
optional?: boolean | undefined;
|
7
45
|
}): ComposerRuntime | null;
|
46
|
+
/**
|
47
|
+
* Hook to access the current composer state.
|
48
|
+
*
|
49
|
+
* This hook provides reactive access to the composer's state, including text content,
|
50
|
+
* attachments, editing status, and send/cancel capabilities.
|
51
|
+
*
|
52
|
+
* @param selector Optional selector function to pick specific state properties
|
53
|
+
* @returns The selected composer state or the entire composer state if no selector provided
|
54
|
+
*
|
55
|
+
* @example
|
56
|
+
* ```tsx
|
57
|
+
* function ComposerStatus() {
|
58
|
+
* const text = useComposer((state) => state.text);
|
59
|
+
* const canSend = useComposer((state) => state.canSend);
|
60
|
+
* const attachmentCount = useComposer((state) => state.attachments.length);
|
61
|
+
*
|
62
|
+
* return (
|
63
|
+
* <div>
|
64
|
+
* Text: {text.length} chars,
|
65
|
+
* Attachments: {attachmentCount},
|
66
|
+
* Can send: {canSend}
|
67
|
+
* </div>
|
68
|
+
* );
|
69
|
+
* }
|
70
|
+
* ```
|
71
|
+
*/
|
8
72
|
export declare const useComposer: {
|
9
73
|
(): import("../..").ComposerState;
|
10
74
|
<TSelected>(selector: (state: import("../..").ComposerState) => TSelected): TSelected;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ComposerContext.d.ts","sourceRoot":"","sources":["../../../src/context/react/ComposerContext.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5D,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAC3C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,eAAe,CAAC;AACpB,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAC3C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,eAAe,GAAG,IAAI,CAAC;AAW3B,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;CAAgD,CAAC"}
|
1
|
+
{"version":3,"file":"ComposerContext.d.ts","sourceRoot":"","sources":["../../../src/context/react/ComposerContext.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAC3C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,eAAe,CAAC;AACpB,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAC3C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,eAAe,GAAG,IAAI,CAAC;AAW3B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;CAAgD,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/context/react/ComposerContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useMessageRuntime } from \"./MessageContext\";\nimport { useThreadRuntime } from \"./ThreadContext\";\nimport { ComposerRuntime } from \"../../api/ComposerRuntime\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\n\nexport function useComposerRuntime(options?: {\n optional?: false | undefined;\n}): ComposerRuntime;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null {\n const messageRuntime = useMessageRuntime({ optional: true });\n const threadRuntime = useThreadRuntime(options);\n return messageRuntime\n ? messageRuntime.composer\n : (threadRuntime?.composer ?? null);\n}\n\nexport const useComposer = createStateHookForRuntime(useComposerRuntime);\n"],"mappings":";;;AAEA,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AAEjC,SAAS,iCAAiC;
|
1
|
+
{"version":3,"sources":["../../../src/context/react/ComposerContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useMessageRuntime } from \"./MessageContext\";\nimport { useThreadRuntime } from \"./ThreadContext\";\nimport { ComposerRuntime } from \"../../api/ComposerRuntime\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\n\n/**\n * Hook to access the ComposerRuntime from the current context.\n *\n * The ComposerRuntime provides access to composer state and actions for message\n * composition, including text input, attachments, and sending functionality.\n * This hook automatically resolves to either the message's edit composer or\n * the thread's main composer depending on the context.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The ComposerRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function ComposerActions() {\n * const runtime = useComposerRuntime();\n *\n * const handleSend = () => {\n * if (runtime.getState().canSend) {\n * runtime.send();\n * }\n * };\n *\n * const handleCancel = () => {\n * if (runtime.getState().canCancel) {\n * runtime.cancel();\n * }\n * };\n *\n * return (\n * <div>\n * <button onClick={handleSend}>Send</button>\n * <button onClick={handleCancel}>Cancel</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useComposerRuntime(options?: {\n optional?: false | undefined;\n}): ComposerRuntime;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null {\n const messageRuntime = useMessageRuntime({ optional: true });\n const threadRuntime = useThreadRuntime(options);\n return messageRuntime\n ? messageRuntime.composer\n : (threadRuntime?.composer ?? null);\n}\n\n/**\n * Hook to access the current composer state.\n *\n * This hook provides reactive access to the composer's state, including text content,\n * attachments, editing status, and send/cancel capabilities.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected composer state or the entire composer state if no selector provided\n *\n * @example\n * ```tsx\n * function ComposerStatus() {\n * const text = useComposer((state) => state.text);\n * const canSend = useComposer((state) => state.canSend);\n * const attachmentCount = useComposer((state) => state.attachments.length);\n *\n * return (\n * <div>\n * Text: {text.length} chars,\n * Attachments: {attachmentCount},\n * Can send: {canSend}\n * </div>\n * );\n * }\n * ```\n */\nexport const useComposer = createStateHookForRuntime(useComposerRuntime);\n"],"mappings":";;;AAEA,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AAEjC,SAAS,iCAAiC;AA8CnC,SAAS,mBAAmB,SAER;AACzB,QAAM,iBAAiB,kBAAkB,EAAE,UAAU,KAAK,CAAC;AAC3D,QAAM,gBAAgB,iBAAiB,OAAO;AAC9C,SAAO,iBACH,eAAe,WACd,eAAe,YAAY;AAClC;AA4BO,IAAM,cAAc,0BAA0B,kBAAkB;","names":[]}
|
@@ -7,12 +7,68 @@ export type MessageContextValue = {
|
|
7
7
|
useMessageUtils: UseBoundStore<ReadonlyStore<MessageUtilsState>>;
|
8
8
|
};
|
9
9
|
export declare const MessageContext: import("react").Context<MessageContextValue | null>;
|
10
|
+
/**
|
11
|
+
* Hook to access the MessageRuntime from the current context.
|
12
|
+
*
|
13
|
+
* The MessageRuntime provides access to message-level state and actions,
|
14
|
+
* including message content, status, editing capabilities, and branching.
|
15
|
+
*
|
16
|
+
* @param options Configuration options
|
17
|
+
* @param options.optional Whether the hook should return null if no context is found
|
18
|
+
* @returns The MessageRuntime instance, or null if optional is true and no context exists
|
19
|
+
*
|
20
|
+
* @example
|
21
|
+
* ```tsx
|
22
|
+
* function MessageActions() {
|
23
|
+
* const runtime = useMessageRuntime();
|
24
|
+
*
|
25
|
+
* const handleReload = () => {
|
26
|
+
* runtime.reload();
|
27
|
+
* };
|
28
|
+
*
|
29
|
+
* const handleEdit = () => {
|
30
|
+
* runtime.startEdit();
|
31
|
+
* };
|
32
|
+
*
|
33
|
+
* return (
|
34
|
+
* <div>
|
35
|
+
* <button onClick={handleReload}>Reload</button>
|
36
|
+
* <button onClick={handleEdit}>Edit</button>
|
37
|
+
* </div>
|
38
|
+
* );
|
39
|
+
* }
|
40
|
+
* ```
|
41
|
+
*/
|
10
42
|
export declare function useMessageRuntime(options?: {
|
11
43
|
optional?: false | undefined;
|
12
44
|
}): MessageRuntime;
|
13
45
|
export declare function useMessageRuntime(options?: {
|
14
46
|
optional?: boolean | undefined;
|
15
47
|
}): MessageRuntime | null;
|
48
|
+
/**
|
49
|
+
* Hook to access the current message state.
|
50
|
+
*
|
51
|
+
* This hook provides reactive access to the message's state, including content,
|
52
|
+
* role, status, and other message-level properties.
|
53
|
+
*
|
54
|
+
* @param selector Optional selector function to pick specific state properties
|
55
|
+
* @returns The selected message state or the entire message state if no selector provided
|
56
|
+
*
|
57
|
+
* @example
|
58
|
+
* ```tsx
|
59
|
+
* function MessageContent() {
|
60
|
+
* const role = useMessage((state) => state.role);
|
61
|
+
* const content = useMessage((state) => state.content);
|
62
|
+
* const isLoading = useMessage((state) => state.status.type === "running");
|
63
|
+
*
|
64
|
+
* return (
|
65
|
+
* <div className={`message-${role}`}>
|
66
|
+
* {isLoading ? "Loading..." : content.map(part => part.text).join("")}
|
67
|
+
* </div>
|
68
|
+
* );
|
69
|
+
* }
|
70
|
+
* ```
|
71
|
+
*/
|
16
72
|
export declare const useMessage: {
|
17
73
|
(): import("../..").MessageState;
|
18
74
|
<TSelected>(selector: (state: import("../..").MessageState) => TSelected): TSelected;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MessageContext.d.ts","sourceRoot":"","sources":["../../../src/context/react/MessageContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAI1D,MAAM,MAAM,mBAAmB,GAAG;IAChC,iBAAiB,EAAE,aAAa,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;IAChE,eAAe,EAAE,aAAa,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC;CAClE,CAAC;AAEF,eAAO,MAAM,cAAc,qDAAkD,CAAC;AAO9E,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE;IAC1C,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B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;CAA+C,CAAC;AAKvE,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;CAE3B,CAAC;AAEF,eAAO,MAAQ,eAAe;;;;;;;;;;GAAE,oBAAoB;;;;;CAGnD,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/context/react/MessageContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { MessageUtilsState } from \"../stores/MessageUtils\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { createContextStoreHook } from \"./utils/createContextStoreHook\";\nimport { UseBoundStore } from \"zustand\";\nimport { MessageRuntime } from \"../../api/MessageRuntime\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\nimport { EditComposerRuntime } from \"../../api\";\n\nexport type MessageContextValue = {\n useMessageRuntime: UseBoundStore<ReadonlyStore<MessageRuntime>>;\n useMessageUtils: UseBoundStore<ReadonlyStore<MessageUtilsState>>;\n};\n\nexport const MessageContext = createContext<MessageContextValue | null>(null);\n\nconst useMessageContext = createContextHook(\n MessageContext,\n \"a component passed to <ThreadPrimitive.Messages components={...} />\",\n);\n\nexport function useMessageRuntime(options?: {\n optional?: false | undefined;\n}): MessageRuntime;\nexport function useMessageRuntime(options?: {\n optional?: boolean | undefined;\n}): MessageRuntime | null;\nexport function useMessageRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const context = useMessageContext(options);\n if (!context) return null;\n return context.useMessageRuntime();\n}\n\nexport const useMessage = createStateHookForRuntime(useMessageRuntime);\n\nconst useEditComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): EditComposerRuntime | null => useMessageRuntime(opt)?.composer ?? null;\nexport const useEditComposer = createStateHookForRuntime(\n useEditComposerRuntime,\n);\n\nexport const { useMessageUtils, useMessageUtilsStore } = createContextStoreHook(\n useMessageContext,\n \"useMessageUtils\",\n);\n"],"mappings":";;;AAEA,SAAS,qBAAqB;AAG9B,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AAGvC,SAAS,iCAAiC;AAQnC,IAAM,iBAAiB,cAA0C,IAAI;AAE5E,IAAM,oBAAoB;AAAA,EACxB;AAAA,EACA;AACF;
|
1
|
+
{"version":3,"sources":["../../../src/context/react/MessageContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { MessageUtilsState } from \"../stores/MessageUtils\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { createContextStoreHook } from \"./utils/createContextStoreHook\";\nimport { UseBoundStore } from \"zustand\";\nimport { MessageRuntime } from \"../../api/MessageRuntime\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\nimport { EditComposerRuntime } from \"../../api\";\n\nexport type MessageContextValue = {\n useMessageRuntime: UseBoundStore<ReadonlyStore<MessageRuntime>>;\n useMessageUtils: UseBoundStore<ReadonlyStore<MessageUtilsState>>;\n};\n\nexport const MessageContext = createContext<MessageContextValue | null>(null);\n\nconst useMessageContext = createContextHook(\n MessageContext,\n \"a component passed to <ThreadPrimitive.Messages components={...} />\",\n);\n\n/**\n * Hook to access the MessageRuntime from the current context.\n *\n * The MessageRuntime provides access to message-level state and actions,\n * including message content, status, editing capabilities, and branching.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The MessageRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function MessageActions() {\n * const runtime = useMessageRuntime();\n *\n * const handleReload = () => {\n * runtime.reload();\n * };\n *\n * const handleEdit = () => {\n * runtime.startEdit();\n * };\n *\n * return (\n * <div>\n * <button onClick={handleReload}>Reload</button>\n * <button onClick={handleEdit}>Edit</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useMessageRuntime(options?: {\n optional?: false | undefined;\n}): MessageRuntime;\nexport function useMessageRuntime(options?: {\n optional?: boolean | undefined;\n}): MessageRuntime | null;\nexport function useMessageRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const context = useMessageContext(options);\n if (!context) return null;\n return context.useMessageRuntime();\n}\n\n/**\n * Hook to access the current message state.\n *\n * This hook provides reactive access to the message's state, including content,\n * role, status, and other message-level properties.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected message state or the entire message state if no selector provided\n *\n * @example\n * ```tsx\n * function MessageContent() {\n * const role = useMessage((state) => state.role);\n * const content = useMessage((state) => state.content);\n * const isLoading = useMessage((state) => state.status.type === \"running\");\n *\n * return (\n * <div className={`message-${role}`}>\n * {isLoading ? \"Loading...\" : content.map(part => part.text).join(\"\")}\n * </div>\n * );\n * }\n * ```\n */\nexport const useMessage = createStateHookForRuntime(useMessageRuntime);\n\nconst useEditComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): EditComposerRuntime | null => useMessageRuntime(opt)?.composer ?? null;\nexport const useEditComposer = createStateHookForRuntime(\n useEditComposerRuntime,\n);\n\nexport const { useMessageUtils, useMessageUtilsStore } = createContextStoreHook(\n useMessageContext,\n \"useMessageUtils\",\n);\n"],"mappings":";;;AAEA,SAAS,qBAAqB;AAG9B,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AAGvC,SAAS,iCAAiC;AAQnC,IAAM,iBAAiB,cAA0C,IAAI;AAE5E,IAAM,oBAAoB;AAAA,EACxB;AAAA,EACA;AACF;AAwCO,SAAS,kBAAkB,SAE/B;AACD,QAAM,UAAU,kBAAkB,OAAO;AACzC,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,kBAAkB;AACnC;AA0BO,IAAM,aAAa,0BAA0B,iBAAiB;AAErE,IAAM,yBAAyB,CAAC,QAEE,kBAAkB,GAAG,GAAG,YAAY;AAC/D,IAAM,kBAAkB;AAAA,EAC7B;AACF;AAEO,IAAM,EAAE,iBAAiB,qBAAqB,IAAI;AAAA,EACvD;AAAA,EACA;AACF;","names":[]}
|
@@ -6,12 +6,54 @@ export type ThreadContextValue = {
|
|
6
6
|
useThreadRuntime: UseBoundStore<ReadonlyStore<ThreadRuntime>>;
|
7
7
|
};
|
8
8
|
export declare const ThreadContext: import("react").Context<ThreadContextValue | null>;
|
9
|
+
/**
|
10
|
+
* Hook to access the ThreadRuntime from the current context.
|
11
|
+
*
|
12
|
+
* The ThreadRuntime provides access to thread-level state and actions,
|
13
|
+
* including message management, thread state, and composer functionality.
|
14
|
+
*
|
15
|
+
* @param options Configuration options
|
16
|
+
* @param options.optional Whether the hook should return null if no context is found
|
17
|
+
* @returns The ThreadRuntime instance, or null if optional is true and no context exists
|
18
|
+
*
|
19
|
+
* @example
|
20
|
+
* ```tsx
|
21
|
+
* function MyComponent() {
|
22
|
+
* const runtime = useThreadRuntime();
|
23
|
+
*
|
24
|
+
* const handleSendMessage = (text: string) => {
|
25
|
+
* runtime.append({ role: "user", content: [{ type: "text", text }] });
|
26
|
+
* };
|
27
|
+
*
|
28
|
+
* return <button onClick={() => handleSendMessage("Hello!")}>Send</button>;
|
29
|
+
* }
|
30
|
+
* ```
|
31
|
+
*/
|
9
32
|
export declare function useThreadRuntime(options?: {
|
10
33
|
optional?: false | undefined;
|
11
34
|
}): ThreadRuntime;
|
12
35
|
export declare function useThreadRuntime(options?: {
|
13
36
|
optional?: boolean | undefined;
|
14
37
|
}): ThreadRuntime | null;
|
38
|
+
/**
|
39
|
+
* Hook to access the current thread state.
|
40
|
+
*
|
41
|
+
* This hook provides reactive access to the thread's state, including messages,
|
42
|
+
* running status, capabilities, and other thread-level properties.
|
43
|
+
*
|
44
|
+
* @param selector Optional selector function to pick specific state properties
|
45
|
+
* @returns The selected thread state or the entire thread state if no selector provided
|
46
|
+
*
|
47
|
+
* @example
|
48
|
+
* ```tsx
|
49
|
+
* function ThreadStatus() {
|
50
|
+
* const isRunning = useThread((state) => state.isRunning);
|
51
|
+
* const messageCount = useThread((state) => state.messages.length);
|
52
|
+
*
|
53
|
+
* return <div>Running: {isRunning}, Messages: {messageCount}</div>;
|
54
|
+
* }
|
55
|
+
* ```
|
56
|
+
*/
|
15
57
|
export declare const useThread: {
|
16
58
|
(): import("../..").ThreadState;
|
17
59
|
<TSelected>(selector: (state: import("../..").ThreadState) => TSelected): TSelected;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ThreadContext.d.ts","sourceRoot":"","sources":["../../../src/context/react/ThreadContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gBAAgB,EAAE,aAAa,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC;CAC/D,CAAC;AAEF,eAAO,MAAM,aAAa,oDAAiD,CAAC;AAO5E,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,aAAa,CAAC;AAClB,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,aAAa,GAAG,IAAI,CAAC;AAOzB,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;CAA8C,CAAC;AAKrE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;CAE7B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,YAAY,CAAC;AACjB,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAA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AI,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/context/react/ThreadContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext, useEffect, useState } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { UseBoundStore } from \"zustand\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { ThreadRuntime } from \"../../api/ThreadRuntime\";\nimport { ModelContext } from \"../../model-context\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\nimport { ThreadComposerRuntime } from \"../../api\";\n\nexport type ThreadContextValue = {\n useThreadRuntime: UseBoundStore<ReadonlyStore<ThreadRuntime>>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nconst useThreadContext = createContextHook(\n ThreadContext,\n \"AssistantRuntimeProvider\",\n);\n\nexport function useThreadRuntime(options?: {\n optional?: false | undefined;\n}): ThreadRuntime;\nexport function useThreadRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadRuntime | null;\nexport function useThreadRuntime(options?: { optional?: boolean | undefined }) {\n const context = useThreadContext(options);\n if (!context) return null;\n return context.useThreadRuntime();\n}\n\nexport const useThread = createStateHookForRuntime(useThreadRuntime);\n\nconst useThreadComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;\nexport const useThreadComposer = createStateHookForRuntime(\n useThreadComposerRuntime,\n);\n\nexport function useThreadModelContext(options?: {\n optional?: false | undefined;\n}): ModelContext;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null {\n const [, rerender] = useState({});\n\n const runtime = useThreadRuntime(options);\n useEffect(() => {\n return runtime?.unstable_on(\"model-context-update\", () => rerender({}));\n }, [runtime]);\n\n if (!runtime) return null;\n return runtime?.getModelContext();\n}\n"],"mappings":";;;AAEA,SAAS,eAAe,WAAW,gBAAgB;AAGnD,SAAS,yBAAyB;AAGlC,SAAS,iCAAiC;AAOnC,IAAM,gBAAgB,cAAyC,IAAI;AAE1E,IAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AACF;
|
1
|
+
{"version":3,"sources":["../../../src/context/react/ThreadContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext, useEffect, useState } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { UseBoundStore } from \"zustand\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { ThreadRuntime } from \"../../api/ThreadRuntime\";\nimport { ModelContext } from \"../../model-context\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\nimport { ThreadComposerRuntime } from \"../../api\";\n\nexport type ThreadContextValue = {\n useThreadRuntime: UseBoundStore<ReadonlyStore<ThreadRuntime>>;\n};\n\nexport const ThreadContext = createContext<ThreadContextValue | null>(null);\n\nconst useThreadContext = createContextHook(\n ThreadContext,\n \"AssistantRuntimeProvider\",\n);\n\n/**\n * Hook to access the ThreadRuntime from the current context.\n *\n * The ThreadRuntime provides access to thread-level state and actions,\n * including message management, thread state, and composer functionality.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The ThreadRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const runtime = useThreadRuntime();\n *\n * const handleSendMessage = (text: string) => {\n * runtime.append({ role: \"user\", content: [{ type: \"text\", text }] });\n * };\n *\n * return <button onClick={() => handleSendMessage(\"Hello!\")}>Send</button>;\n * }\n * ```\n */\nexport function useThreadRuntime(options?: {\n optional?: false | undefined;\n}): ThreadRuntime;\nexport function useThreadRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadRuntime | null;\nexport function useThreadRuntime(options?: { optional?: boolean | undefined }) {\n const context = useThreadContext(options);\n if (!context) return null;\n return context.useThreadRuntime();\n}\n\n/**\n * Hook to access the current thread state.\n *\n * This hook provides reactive access to the thread's state, including messages,\n * running status, capabilities, and other thread-level properties.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected thread state or the entire thread state if no selector provided\n *\n * @example\n * ```tsx\n * function ThreadStatus() {\n * const isRunning = useThread((state) => state.isRunning);\n * const messageCount = useThread((state) => state.messages.length);\n *\n * return <div>Running: {isRunning}, Messages: {messageCount}</div>;\n * }\n * ```\n */\nexport const useThread = createStateHookForRuntime(useThreadRuntime);\n\nconst useThreadComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;\nexport const useThreadComposer = createStateHookForRuntime(\n useThreadComposerRuntime,\n);\n\nexport function useThreadModelContext(options?: {\n optional?: false | undefined;\n}): ModelContext;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null {\n const [, rerender] = useState({});\n\n const runtime = useThreadRuntime(options);\n useEffect(() => {\n return runtime?.unstable_on(\"model-context-update\", () => rerender({}));\n }, [runtime]);\n\n if (!runtime) return null;\n return runtime?.getModelContext();\n}\n"],"mappings":";;;AAEA,SAAS,eAAe,WAAW,gBAAgB;AAGnD,SAAS,yBAAyB;AAGlC,SAAS,iCAAiC;AAOnC,IAAM,gBAAgB,cAAyC,IAAI;AAE1E,IAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AACF;AA+BO,SAAS,iBAAiB,SAA8C;AAC7E,QAAM,UAAU,iBAAiB,OAAO;AACxC,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,iBAAiB;AAClC;AAqBO,IAAM,YAAY,0BAA0B,gBAAgB;AAEnE,IAAM,2BAA2B,CAAC,QAEE,iBAAiB,GAAG,GAAG,YAAY;AAChE,IAAM,oBAAoB;AAAA,EAC/B;AACF;AAQO,SAAS,sBAAsB,SAEd;AACtB,QAAM,CAAC,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC;AAEhC,QAAM,UAAU,iBAAiB,OAAO;AACxC,YAAU,MAAM;AACd,WAAO,SAAS,YAAY,wBAAwB,MAAM,SAAS,CAAC,CAAC,CAAC;AAAA,EACxE,GAAG,CAAC,OAAO,CAAC;AAEZ,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,SAAS,gBAAgB;AAClC;","names":[]}
|
@@ -1,11 +1,53 @@
|
|
1
1
|
import { ActionButtonProps } from "../../utils/createActionButton";
|
2
|
+
/**
|
3
|
+
* Hook that provides copy functionality for action bar buttons.
|
4
|
+
*
|
5
|
+
* This hook returns a callback function that copies message content to the clipboard,
|
6
|
+
* or null if copying is not available. It handles both regular message content and
|
7
|
+
* composer text when in editing mode.
|
8
|
+
*
|
9
|
+
* @param options Configuration options
|
10
|
+
* @param options.copiedDuration Duration in milliseconds to show the copied state
|
11
|
+
* @returns A copy callback function, or null if copying is disabled
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* ```tsx
|
15
|
+
* function CustomCopyButton() {
|
16
|
+
* const copy = useActionBarPrimitiveCopy({ copiedDuration: 2000 });
|
17
|
+
*
|
18
|
+
* return (
|
19
|
+
* <button onClick={copy} disabled={!copy}>
|
20
|
+
* {copy ? "Copy" : "Cannot Copy"}
|
21
|
+
* </button>
|
22
|
+
* );
|
23
|
+
* }
|
24
|
+
* ```
|
25
|
+
*/
|
2
26
|
declare const useActionBarPrimitiveCopy: ({ copiedDuration, }?: {
|
3
27
|
copiedDuration?: number | undefined;
|
4
28
|
}) => (() => void) | null;
|
5
29
|
export declare namespace ActionBarPrimitiveCopy {
|
6
30
|
type Element = HTMLButtonElement;
|
31
|
+
/**
|
32
|
+
* Props for the ActionBarPrimitive.Copy component.
|
33
|
+
* Inherits all button element props and action button functionality.
|
34
|
+
*/
|
7
35
|
type Props = ActionButtonProps<typeof useActionBarPrimitiveCopy>;
|
8
36
|
}
|
37
|
+
/**
|
38
|
+
* A button component that copies message content to the clipboard.
|
39
|
+
*
|
40
|
+
* This component automatically handles copying message text to the clipboard
|
41
|
+
* and provides visual feedback through the data-copied attribute. It's disabled
|
42
|
+
* when there's no copyable content available.
|
43
|
+
*
|
44
|
+
* @example
|
45
|
+
* ```tsx
|
46
|
+
* <ActionBarPrimitive.Copy copiedDuration={2000}>
|
47
|
+
* Copy Message
|
48
|
+
* </ActionBarPrimitive.Copy>
|
49
|
+
* ```
|
50
|
+
*/
|
9
51
|
export declare const ActionBarPrimitiveCopy: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
|
10
52
|
asChild?: boolean;
|
11
53
|
}, "ref"> & {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ActionBarCopy.d.ts","sourceRoot":"","sources":["../../../src/primitives/actionBar/ActionBarCopy.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAWnE,QAAA,MAAM,yBAAyB,GAAI,sBAEhC;IAAE,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAO,wBA0B9C,CAAC;AAEF,yBAAiB,sBAAsB,CAAC;IACtC,KAAY,OAAO,GAAG,iBAAiB,CAAC;IACxC,KAAY,KAAK,GAAG,iBAAiB,CAAC,OAAO,yBAAyB,CAAC,CAAC;CACzE;AAED,eAAO,MAAM,sBAAsB;;;
|
1
|
+
{"version":3,"file":"ActionBarCopy.d.ts","sourceRoot":"","sources":["../../../src/primitives/actionBar/ActionBarCopy.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAWnE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,QAAA,MAAM,yBAAyB,GAAI,sBAEhC;IAAE,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAO,wBA0B9C,CAAC;AAEF,yBAAiB,sBAAsB,CAAC;IACtC,KAAY,OAAO,GAAG,iBAAiB,CAAC;IACxC;;;OAGG;IACH,KAAY,KAAK,GAAG,iBAAiB,CAAC,OAAO,yBAAyB,CAAC,CAAC;CACzE;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB;;;qBAnDb,MAAM,GAAG,SAAS;qDAqEtC,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/actionBar/ActionBarCopy.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef } from \"react\";\nimport { ActionButtonProps } from \"../../utils/createActionButton\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { useMessageUtils } from \"../../context\";\nimport { useCallback } from \"react\";\nimport {\n useMessage,\n useMessageRuntime,\n} from \"../../context/react/MessageContext\";\nimport { useComposerRuntime } from \"../../context\";\n\nconst useActionBarPrimitiveCopy = ({\n copiedDuration = 3000,\n}: { copiedDuration?: number | undefined } = {}) => {\n const messageRuntime = useMessageRuntime();\n const composerRuntime = useComposerRuntime();\n const setIsCopied = useMessageUtils((s) => s.setIsCopied);\n const hasCopyableContent = useMessage((message) => {\n return (\n (message.role !== \"assistant\" || message.status.type !== \"running\") &&\n message.content.some((c) => c.type === \"text\" && c.text.length > 0)\n );\n });\n\n const callback = useCallback(() => {\n const { isEditing, text: composerValue } = composerRuntime.getState();\n\n const valueToCopy = isEditing\n ? composerValue\n : messageRuntime.unstable_getCopyText();\n\n navigator.clipboard.writeText(valueToCopy).then(() => {\n setIsCopied(true);\n setTimeout(() => setIsCopied(false), copiedDuration);\n });\n }, [messageRuntime, setIsCopied, composerRuntime, copiedDuration]);\n\n if (!hasCopyableContent) return null;\n return callback;\n};\n\nexport namespace ActionBarPrimitiveCopy {\n export type Element = HTMLButtonElement;\n export type Props = ActionButtonProps<typeof useActionBarPrimitiveCopy>;\n}\n\nexport const ActionBarPrimitiveCopy = forwardRef<\n ActionBarPrimitiveCopy.Element,\n ActionBarPrimitiveCopy.Props\n>(({ copiedDuration, onClick, disabled, ...props }, forwardedRef) => {\n const isCopied = useMessageUtils((u) => u.isCopied);\n const callback = useActionBarPrimitiveCopy({ copiedDuration });\n return (\n <Primitive.button\n type=\"button\"\n {...(isCopied ? { \"data-copied\": \"true\" } : {})}\n {...props}\n ref={forwardedRef}\n disabled={disabled || !callback}\n onClick={composeEventHandlers(onClick, () => {\n callback?.();\n })}\n />\n );\n});\n\nActionBarPrimitiveCopy.displayName = \"ActionBarPrimitive.Copy\";\n"],"mappings":";;;AAEA,SAAS,kBAAkB;AAE3B,SAAS,4BAA4B;AACrC,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;
|
1
|
+
{"version":3,"sources":["../../../src/primitives/actionBar/ActionBarCopy.tsx"],"sourcesContent":["\"use client\";\n\nimport { forwardRef } from \"react\";\nimport { ActionButtonProps } from \"../../utils/createActionButton\";\nimport { composeEventHandlers } from \"@radix-ui/primitive\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport { useMessageUtils } from \"../../context\";\nimport { useCallback } from \"react\";\nimport {\n useMessage,\n useMessageRuntime,\n} from \"../../context/react/MessageContext\";\nimport { useComposerRuntime } from \"../../context\";\n\n/**\n * Hook that provides copy functionality for action bar buttons.\n *\n * This hook returns a callback function that copies message content to the clipboard,\n * or null if copying is not available. It handles both regular message content and\n * composer text when in editing mode.\n *\n * @param options Configuration options\n * @param options.copiedDuration Duration in milliseconds to show the copied state\n * @returns A copy callback function, or null if copying is disabled\n *\n * @example\n * ```tsx\n * function CustomCopyButton() {\n * const copy = useActionBarPrimitiveCopy({ copiedDuration: 2000 });\n *\n * return (\n * <button onClick={copy} disabled={!copy}>\n * {copy ? \"Copy\" : \"Cannot Copy\"}\n * </button>\n * );\n * }\n * ```\n */\nconst useActionBarPrimitiveCopy = ({\n copiedDuration = 3000,\n}: { copiedDuration?: number | undefined } = {}) => {\n const messageRuntime = useMessageRuntime();\n const composerRuntime = useComposerRuntime();\n const setIsCopied = useMessageUtils((s) => s.setIsCopied);\n const hasCopyableContent = useMessage((message) => {\n return (\n (message.role !== \"assistant\" || message.status.type !== \"running\") &&\n message.content.some((c) => c.type === \"text\" && c.text.length > 0)\n );\n });\n\n const callback = useCallback(() => {\n const { isEditing, text: composerValue } = composerRuntime.getState();\n\n const valueToCopy = isEditing\n ? composerValue\n : messageRuntime.unstable_getCopyText();\n\n navigator.clipboard.writeText(valueToCopy).then(() => {\n setIsCopied(true);\n setTimeout(() => setIsCopied(false), copiedDuration);\n });\n }, [messageRuntime, setIsCopied, composerRuntime, copiedDuration]);\n\n if (!hasCopyableContent) return null;\n return callback;\n};\n\nexport namespace ActionBarPrimitiveCopy {\n export type Element = HTMLButtonElement;\n /**\n * Props for the ActionBarPrimitive.Copy component.\n * Inherits all button element props and action button functionality.\n */\n export type Props = ActionButtonProps<typeof useActionBarPrimitiveCopy>;\n}\n\n/**\n * A button component that copies message content to the clipboard.\n *\n * This component automatically handles copying message text to the clipboard\n * and provides visual feedback through the data-copied attribute. It's disabled\n * when there's no copyable content available.\n *\n * @example\n * ```tsx\n * <ActionBarPrimitive.Copy copiedDuration={2000}>\n * Copy Message\n * </ActionBarPrimitive.Copy>\n * ```\n */\nexport const ActionBarPrimitiveCopy = forwardRef<\n ActionBarPrimitiveCopy.Element,\n ActionBarPrimitiveCopy.Props\n>(({ copiedDuration, onClick, disabled, ...props }, forwardedRef) => {\n const isCopied = useMessageUtils((u) => u.isCopied);\n const callback = useActionBarPrimitiveCopy({ copiedDuration });\n return (\n <Primitive.button\n type=\"button\"\n {...(isCopied ? { \"data-copied\": \"true\" } : {})}\n {...props}\n ref={forwardedRef}\n disabled={disabled || !callback}\n onClick={composeEventHandlers(onClick, () => {\n callback?.();\n })}\n />\n );\n});\n\nActionBarPrimitiveCopy.displayName = \"ActionBarPrimitive.Copy\";\n"],"mappings":";;;AAEA,SAAS,kBAAkB;AAE3B,SAAS,4BAA4B;AACrC,S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MACvB,SAAS,qBAAqB,SAAS,MAAM;AAC3C,mBAAW;AAAA,MACb,CAAC;AAAA;AAAA,EACH;AAEJ,CAAC;AAED,uBAAuB,cAAc;","names":[]}
|
@@ -1,9 +1,47 @@
|
|
1
1
|
import { ActionButtonElement, ActionButtonProps } from "../../utils/createActionButton";
|
2
|
+
/**
|
3
|
+
* Hook that provides edit functionality for action bar buttons.
|
4
|
+
*
|
5
|
+
* This hook returns a callback function that starts editing the current message,
|
6
|
+
* or null if editing is not available (e.g., already in editing mode).
|
7
|
+
*
|
8
|
+
* @returns An edit callback function, or null if editing is disabled
|
9
|
+
*
|
10
|
+
* @example
|
11
|
+
* ```tsx
|
12
|
+
* function CustomEditButton() {
|
13
|
+
* const edit = useActionBarEdit();
|
14
|
+
*
|
15
|
+
* return (
|
16
|
+
* <button onClick={edit} disabled={!edit}>
|
17
|
+
* {edit ? "Edit Message" : "Cannot Edit"}
|
18
|
+
* </button>
|
19
|
+
* );
|
20
|
+
* }
|
21
|
+
* ```
|
22
|
+
*/
|
2
23
|
declare const useActionBarEdit: () => (() => void) | null;
|
3
24
|
export declare namespace ActionBarPrimitiveEdit {
|
4
25
|
type Element = ActionButtonElement;
|
26
|
+
/**
|
27
|
+
* Props for the ActionBarPrimitive.Edit component.
|
28
|
+
* Inherits all button element props and action button functionality.
|
29
|
+
*/
|
5
30
|
type Props = ActionButtonProps<typeof useActionBarEdit>;
|
6
31
|
}
|
32
|
+
/**
|
33
|
+
* A button component that starts editing the current message.
|
34
|
+
*
|
35
|
+
* This component automatically handles starting the edit mode for the current message
|
36
|
+
* and is disabled when editing is not available (e.g., already in editing mode).
|
37
|
+
*
|
38
|
+
* @example
|
39
|
+
* ```tsx
|
40
|
+
* <ActionBarPrimitive.Edit>
|
41
|
+
* Edit Message
|
42
|
+
* </ActionBarPrimitive.Edit>
|
43
|
+
* ```
|
44
|
+
*/
|
7
45
|
export declare const ActionBarPrimitiveEdit: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
|
8
46
|
asChild?: boolean;
|
9
47
|
}, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ActionBarEdit.d.ts","sourceRoot":"","sources":["../../../src/primitives/actionBar/ActionBarEdit.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EAElB,MAAM,gCAAgC,CAAC;AAIxC,QAAA,MAAM,gBAAgB,2BAUrB,CAAC;AAEF,yBAAiB,sBAAsB,CAAC;IACtC,KAAY,OAAO,GAAG,mBAAmB,CAAC;IAC1C,KAAY,KAAK,GAAG,iBAAiB,CAAC,OAAO,gBAAgB,CAAC,CAAC;CAChE;AAED,eAAO,MAAM,sBAAsB;;6DAGlC,CAAC"}
|
1
|
+
{"version":3,"file":"ActionBarEdit.d.ts","sourceRoot":"","sources":["../../../src/primitives/actionBar/ActionBarEdit.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EAElB,MAAM,gCAAgC,CAAC;AAIxC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,QAAA,MAAM,gBAAgB,2BAUrB,CAAC;AAEF,yBAAiB,sBAAsB,CAAC;IACtC,KAAY,OAAO,GAAG,mBAAmB,CAAC;IAC1C;;;OAGG;IACH,KAAY,KAAK,GAAG,iBAAiB,CAAC,OAAO,gBAAgB,CAAC,CAAC;CAChE;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,sBAAsB;;6DAGlC,CAAC"}
|