@assistant-ui/react 0.10.48 → 0.10.50
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.map +1 -1
- package/dist/cloud/AssistantCloudThreadHistoryAdapter.js +7 -1
- package/dist/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/runtimes/adapters/RuntimeAdapterProvider.d.ts +2 -0
- package/dist/runtimes/adapters/RuntimeAdapterProvider.d.ts.map +1 -1
- package/dist/runtimes/adapters/RuntimeAdapterProvider.js.map +1 -1
- package/dist/runtimes/adapters/attachment/CloudFileAttachmentAdapter.d.ts +15 -0
- package/dist/runtimes/adapters/attachment/CloudFileAttachmentAdapter.d.ts.map +1 -0
- package/dist/runtimes/adapters/attachment/CloudFileAttachmentAdapter.js +83 -0
- package/dist/runtimes/adapters/attachment/CloudFileAttachmentAdapter.js.map +1 -0
- package/dist/runtimes/adapters/attachment/index.d.ts +1 -0
- package/dist/runtimes/adapters/attachment/index.d.ts.map +1 -1
- package/dist/runtimes/adapters/attachment/index.js +2 -0
- package/dist/runtimes/adapters/attachment/index.js.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/cloud.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/adapter/cloud.js +14 -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 +1 -1
- package/src/cloud/AssistantCloudThreadHistoryAdapter.tsx +12 -1
- package/src/runtimes/adapters/RuntimeAdapterProvider.tsx +2 -0
- package/src/runtimes/adapters/attachment/CloudFileAttachmentAdapter.ts +101 -0
- package/src/runtimes/adapters/attachment/index.ts +1 -0
- package/src/runtimes/remote-thread-list/adapter/cloud.tsx +16 -1
@@ -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,iBAAiB,CAAC;
|
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;AAwKjD,eAAO,MAAM,qCAAqC,GAChD,UAAU,SAAS,CAAC,cAAc,CAAC,KAClC,oBAQF,CAAC"}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
import { useState } from "react";
|
3
3
|
import { useThreadListItemRuntime } from "../context/index.js";
|
4
4
|
import { auiV0Decode, auiV0Encode } from "./auiV0.js";
|
5
|
+
var globalMessageIdMapping = /* @__PURE__ */ new WeakMap();
|
5
6
|
var FormattedThreadHistoryAdapter = class {
|
6
7
|
constructor(parent, formatAdapter) {
|
7
8
|
this.parent = parent;
|
@@ -29,7 +30,12 @@ var AssistantCloudThreadHistoryAdapter = class {
|
|
29
30
|
this.cloudRef = cloudRef;
|
30
31
|
this.threadListItemRuntime = threadListItemRuntime;
|
31
32
|
}
|
32
|
-
_getIdForLocalId
|
33
|
+
get _getIdForLocalId() {
|
34
|
+
if (!globalMessageIdMapping.has(this.threadListItemRuntime)) {
|
35
|
+
globalMessageIdMapping.set(this.threadListItemRuntime, {});
|
36
|
+
}
|
37
|
+
return globalMessageIdMapping.get(this.threadListItemRuntime);
|
38
|
+
}
|
33
39
|
withFormat(formatAdapter) {
|
34
40
|
return new FormattedThreadHistoryAdapter(this, formatAdapter);
|
35
41
|
}
|
@@ -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 \"assistant-cloud\";\nimport { auiV0Decode, auiV0Encode } from \"./auiV0\";\nimport { ThreadListItemRuntime } from \"../api\";\nimport {\n MessageFormatAdapter,\n MessageFormatItem,\n MessageFormatRepository,\n MessageStorageEntry,\n} from \"../runtimes/adapters/thread-history/MessageFormatAdapter\";\nimport { GenericThreadHistoryAdapter } from \"../runtimes/adapters/thread-history/ThreadHistoryAdapter\";\nimport { ReadonlyJSONObject } from \"assistant-stream/utils\";\n\nclass FormattedThreadHistoryAdapter<TMessage, TStorageFormat>\n implements GenericThreadHistoryAdapter<TMessage>\n{\n constructor(\n private parent: AssistantCloudThreadHistoryAdapter,\n private formatAdapter: MessageFormatAdapter<TMessage, TStorageFormat>,\n ) {}\n\n async append(item: MessageFormatItem<TMessage>) {\n // Encode the message using the format adapter\n const encoded = this.formatAdapter.encode(item);\n const messageId = this.formatAdapter.getId(item.message);\n\n // Delegate to parent's internal append method with the encoded format\n return this.parent._appendWithFormat(\n item.parentId,\n messageId,\n this.formatAdapter.format,\n encoded,\n );\n }\n\n async load(): Promise<MessageFormatRepository<TMessage>> {\n // Delegate to parent's internal load method with format filter\n return this.parent._loadWithFormat(\n this.formatAdapter.format,\n (message: MessageStorageEntry<TStorageFormat>) =>\n this.formatAdapter.decode(message),\n );\n }\n}\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>>
|
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\";\nimport {\n MessageFormatAdapter,\n MessageFormatItem,\n MessageFormatRepository,\n MessageStorageEntry,\n} from \"../runtimes/adapters/thread-history/MessageFormatAdapter\";\nimport { GenericThreadHistoryAdapter } from \"../runtimes/adapters/thread-history/ThreadHistoryAdapter\";\nimport { ReadonlyJSONObject } from \"assistant-stream/utils\";\n\n// Global WeakMap to store message ID mappings across adapter instances\nconst globalMessageIdMapping = new WeakMap<\n ThreadListItemRuntime,\n Record<string, string | Promise<string>>\n>();\n\nclass FormattedThreadHistoryAdapter<TMessage, TStorageFormat>\n implements GenericThreadHistoryAdapter<TMessage>\n{\n constructor(\n private parent: AssistantCloudThreadHistoryAdapter,\n private formatAdapter: MessageFormatAdapter<TMessage, TStorageFormat>,\n ) {}\n\n async append(item: MessageFormatItem<TMessage>) {\n // Encode the message using the format adapter\n const encoded = this.formatAdapter.encode(item);\n const messageId = this.formatAdapter.getId(item.message);\n\n // Delegate to parent's internal append method with the encoded format\n return this.parent._appendWithFormat(\n item.parentId,\n messageId,\n this.formatAdapter.format,\n encoded,\n );\n }\n\n async load(): Promise<MessageFormatRepository<TMessage>> {\n // Delegate to parent's internal load method with format filter\n return this.parent._loadWithFormat(\n this.formatAdapter.format,\n (message: MessageStorageEntry<TStorageFormat>) =>\n this.formatAdapter.decode(message),\n );\n }\n}\n\nclass AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {\n constructor(\n private cloudRef: RefObject<AssistantCloud>,\n private threadListItemRuntime: ThreadListItemRuntime,\n ) {}\n\n private get _getIdForLocalId(): Record<string, string | Promise<string>> {\n if (!globalMessageIdMapping.has(this.threadListItemRuntime)) {\n globalMessageIdMapping.set(this.threadListItemRuntime, {});\n }\n return globalMessageIdMapping.get(this.threadListItemRuntime)!;\n }\n\n withFormat<TMessage, TStorageFormat>(\n formatAdapter: MessageFormatAdapter<TMessage, TStorageFormat>,\n ): GenericThreadHistoryAdapter<TMessage> {\n return new FormattedThreadHistoryAdapter(this, formatAdapter);\n }\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 } = await this.cloudRef.current.threads.messages.list(\n remoteId,\n {\n format: \"aui/v0\",\n },\n );\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 // Internal methods for FormattedThreadHistoryAdapter\n async _appendWithFormat<T>(\n parentId: string | null,\n messageId: string,\n format: string,\n content: T,\n ) {\n const { remoteId } = await this.threadListItemRuntime.initialize();\n\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,\n content: content as ReadonlyJSONObject,\n })\n .then(({ message_id }) => {\n this._getIdForLocalId[messageId] = message_id;\n return message_id;\n });\n\n this._getIdForLocalId[messageId] = task;\n\n return task.then(() => {});\n }\n\n async _loadWithFormat<TMessage, TStorageFormat>(\n format: string,\n decoder: (\n message: MessageStorageEntry<TStorageFormat>,\n ) => MessageFormatItem<TMessage>,\n ): Promise<MessageFormatRepository<TMessage>> {\n const remoteId = this.threadListItemRuntime.getState().remoteId;\n if (!remoteId) return { messages: [] };\n\n const { messages } = await this.cloudRef.current.threads.messages.list(\n remoteId,\n {\n format,\n },\n );\n\n return {\n messages: messages\n .filter((m) => m.format === format)\n .map((m) =>\n decoder({\n id: m.id,\n parent_id: m.parent_id,\n format: m.format,\n content: m.content as TStorageFormat,\n }),\n )\n .reverse(),\n };\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":"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","names":[]}
|
@@ -1,9 +1,11 @@
|
|
1
1
|
import { FC, ReactNode } from "react";
|
2
2
|
import { ThreadHistoryAdapter } from "./thread-history/ThreadHistoryAdapter";
|
3
|
+
import { AttachmentAdapter } from "./attachment/AttachmentAdapter";
|
3
4
|
import { ModelContextProvider } from "../../model-context";
|
4
5
|
export type RuntimeAdapters = {
|
5
6
|
modelContext?: ModelContextProvider;
|
6
7
|
history?: ThreadHistoryAdapter;
|
8
|
+
attachments?: AttachmentAdapter;
|
7
9
|
};
|
8
10
|
declare namespace RuntimeAdapterProvider {
|
9
11
|
type Props = {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"RuntimeAdapterProvider.d.ts","sourceRoot":"","sources":["../../../src/runtimes/adapters/RuntimeAdapterProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,EAAE,EAAE,SAAS,EAAc,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC,OAAO,CAAC,EAAE,oBAAoB,CAAC;
|
1
|
+
{"version":3,"file":"RuntimeAdapterProvider.d.ts","sourceRoot":"","sources":["../../../src/runtimes/adapters/RuntimeAdapterProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,EAAE,EAAE,SAAS,EAAc,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,CAAC;AAIF,kBAAU,sBAAsB,CAAC;IAC/B,KAAY,KAAK,GAAG;QAClB,QAAQ,EAAE,eAAe,CAAC;QAC1B,QAAQ,EAAE,SAAS,CAAC;KACrB,CAAC;CACH;AAED,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,CAAC,KAAK,CAenE,CAAC;AAEF,eAAO,MAAM,kBAAkB,8BAG9B,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/adapters/RuntimeAdapterProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext, FC, ReactNode, useContext } from \"react\";\nimport { ThreadHistoryAdapter } from \"./thread-history/ThreadHistoryAdapter\";\nimport { ModelContextProvider } from \"../../model-context\";\n\nexport type RuntimeAdapters = {\n modelContext?: ModelContextProvider;\n history?: ThreadHistoryAdapter;\n};\n\nconst RuntimeAdaptersContext = createContext<RuntimeAdapters | null>(null);\n\nnamespace RuntimeAdapterProvider {\n export type Props = {\n adapters: RuntimeAdapters;\n children: ReactNode;\n };\n}\n\nexport const RuntimeAdapterProvider: FC<RuntimeAdapterProvider.Props> = ({\n adapters,\n children,\n}) => {\n const context = useContext(RuntimeAdaptersContext);\n return (\n <RuntimeAdaptersContext.Provider\n value={{\n ...context,\n ...adapters,\n }}\n >\n {children}\n </RuntimeAdaptersContext.Provider>\n );\n};\n\nexport const useRuntimeAdapters = () => {\n const adapters = useContext(RuntimeAdaptersContext);\n return adapters;\n};\n"],"mappings":";;;AAEA,SAAS,eAA8B,kBAAkB;
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/adapters/RuntimeAdapterProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext, FC, ReactNode, useContext } from \"react\";\nimport { ThreadHistoryAdapter } from \"./thread-history/ThreadHistoryAdapter\";\nimport { AttachmentAdapter } from \"./attachment/AttachmentAdapter\";\nimport { ModelContextProvider } from \"../../model-context\";\n\nexport type RuntimeAdapters = {\n modelContext?: ModelContextProvider;\n history?: ThreadHistoryAdapter;\n attachments?: AttachmentAdapter;\n};\n\nconst RuntimeAdaptersContext = createContext<RuntimeAdapters | null>(null);\n\nnamespace RuntimeAdapterProvider {\n export type Props = {\n adapters: RuntimeAdapters;\n children: ReactNode;\n };\n}\n\nexport const RuntimeAdapterProvider: FC<RuntimeAdapterProvider.Props> = ({\n adapters,\n children,\n}) => {\n const context = useContext(RuntimeAdaptersContext);\n return (\n <RuntimeAdaptersContext.Provider\n value={{\n ...context,\n ...adapters,\n }}\n >\n {children}\n </RuntimeAdaptersContext.Provider>\n );\n};\n\nexport const useRuntimeAdapters = () => {\n const adapters = useContext(RuntimeAdaptersContext);\n return adapters;\n};\n"],"mappings":";;;AAEA,SAAS,eAA8B,kBAAkB;AA0BrD;AAfJ,IAAM,yBAAyB,cAAsC,IAAI;AASlE,IAAM,yBAA2D,CAAC;AAAA,EACvE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,UAAU,WAAW,sBAAsB;AACjD,SACE;AAAA,IAAC,uBAAuB;AAAA,IAAvB;AAAA,MACC,OAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,qBAAqB,MAAM;AACtC,QAAM,WAAW,WAAW,sBAAsB;AAClD,SAAO;AACT;","names":[]}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import type { AssistantCloud } from "assistant-cloud";
|
2
|
+
import { Attachment, PendingAttachment, CompleteAttachment } from "../../../types/AttachmentTypes";
|
3
|
+
import { AttachmentAdapter } from "./AttachmentAdapter";
|
4
|
+
export declare class CloudFileAttachmentAdapter implements AttachmentAdapter {
|
5
|
+
private cloud;
|
6
|
+
accept: string;
|
7
|
+
constructor(cloud: AssistantCloud);
|
8
|
+
private uploadedUrls;
|
9
|
+
add({ file, }: {
|
10
|
+
file: File;
|
11
|
+
}): AsyncGenerator<PendingAttachment, void>;
|
12
|
+
remove(attachment: Attachment): Promise<void>;
|
13
|
+
send(attachment: PendingAttachment): Promise<CompleteAttachment>;
|
14
|
+
}
|
15
|
+
//# sourceMappingURL=CloudFileAttachmentAdapter.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"CloudFileAttachmentAdapter.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/adapters/attachment/CloudFileAttachmentAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAUxD,qBAAa,0BAA2B,YAAW,iBAAiB;IAGtD,OAAO,CAAC,KAAK;IAFlB,MAAM,SAAO;gBAEA,KAAK,EAAE,cAAc;IAEzC,OAAO,CAAC,YAAY,CAA6B;IAEnC,GAAG,CAAC,EAChB,IAAI,GACL,EAAE;QACD,IAAI,EAAE,IAAI,CAAC;KACZ,GAAG,cAAc,CAAC,iBAAiB,EAAE,IAAI,CAAC;IAyC9B,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C,IAAI,CACf,UAAU,EAAE,iBAAiB,GAC5B,OAAO,CAAC,kBAAkB,CAAC;CAyB/B"}
|
@@ -0,0 +1,83 @@
|
|
1
|
+
// src/runtimes/adapters/attachment/CloudFileAttachmentAdapter.ts
|
2
|
+
var guessAttachmentType = (contentType) => {
|
3
|
+
if (contentType.startsWith("image/")) return "image";
|
4
|
+
if (contentType.startsWith("text/")) return "document";
|
5
|
+
return "file";
|
6
|
+
};
|
7
|
+
var CloudFileAttachmentAdapter = class {
|
8
|
+
constructor(cloud) {
|
9
|
+
this.cloud = cloud;
|
10
|
+
}
|
11
|
+
accept = "*";
|
12
|
+
uploadedUrls = /* @__PURE__ */ new Map();
|
13
|
+
async *add({
|
14
|
+
file
|
15
|
+
}) {
|
16
|
+
const id = crypto.randomUUID();
|
17
|
+
const type = guessAttachmentType(file.type);
|
18
|
+
let attachment = {
|
19
|
+
id,
|
20
|
+
type,
|
21
|
+
name: file.name,
|
22
|
+
contentType: file.type,
|
23
|
+
file,
|
24
|
+
status: { type: "running", reason: "uploading", progress: 0 }
|
25
|
+
};
|
26
|
+
yield attachment;
|
27
|
+
try {
|
28
|
+
const { signedUrl, publicUrl } = await this.cloud.files.generatePresignedUploadUrl({
|
29
|
+
filename: file.name
|
30
|
+
});
|
31
|
+
await fetch(signedUrl, {
|
32
|
+
method: "PUT",
|
33
|
+
body: file,
|
34
|
+
headers: {
|
35
|
+
"Content-Type": file.type
|
36
|
+
},
|
37
|
+
mode: "cors"
|
38
|
+
});
|
39
|
+
this.uploadedUrls.set(id, publicUrl);
|
40
|
+
attachment = {
|
41
|
+
...attachment,
|
42
|
+
status: { type: "requires-action", reason: "composer-send" }
|
43
|
+
};
|
44
|
+
yield attachment;
|
45
|
+
} catch {
|
46
|
+
attachment = {
|
47
|
+
...attachment,
|
48
|
+
status: { type: "incomplete", reason: "error" }
|
49
|
+
};
|
50
|
+
yield attachment;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
async remove(attachment) {
|
54
|
+
this.uploadedUrls.delete(attachment.id);
|
55
|
+
}
|
56
|
+
async send(attachment) {
|
57
|
+
const url = this.uploadedUrls.get(attachment.id);
|
58
|
+
if (!url) throw new Error("Attachment not uploaded");
|
59
|
+
this.uploadedUrls.delete(attachment.id);
|
60
|
+
let content;
|
61
|
+
if (attachment.type === "image") {
|
62
|
+
content = [{ type: "image", image: url, filename: attachment.name }];
|
63
|
+
} else {
|
64
|
+
content = [
|
65
|
+
{
|
66
|
+
type: "file",
|
67
|
+
data: url,
|
68
|
+
mimeType: attachment.contentType,
|
69
|
+
filename: attachment.name
|
70
|
+
}
|
71
|
+
];
|
72
|
+
}
|
73
|
+
return {
|
74
|
+
...attachment,
|
75
|
+
status: { type: "complete" },
|
76
|
+
content
|
77
|
+
};
|
78
|
+
}
|
79
|
+
};
|
80
|
+
export {
|
81
|
+
CloudFileAttachmentAdapter
|
82
|
+
};
|
83
|
+
//# sourceMappingURL=CloudFileAttachmentAdapter.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/adapters/attachment/CloudFileAttachmentAdapter.ts"],"sourcesContent":["import type { AssistantCloud } from \"assistant-cloud\";\nimport {\n Attachment,\n PendingAttachment,\n CompleteAttachment,\n} from \"../../../types/AttachmentTypes\";\nimport { ThreadUserMessagePart } from \"../../../types/MessagePartTypes\";\nimport { AttachmentAdapter } from \"./AttachmentAdapter\";\n\nconst guessAttachmentType = (\n contentType: string,\n): \"image\" | \"document\" | \"file\" => {\n if (contentType.startsWith(\"image/\")) return \"image\";\n if (contentType.startsWith(\"text/\")) return \"document\";\n return \"file\";\n};\n\nexport class CloudFileAttachmentAdapter implements AttachmentAdapter {\n public accept = \"*\";\n\n constructor(private cloud: AssistantCloud) {}\n\n private uploadedUrls = new Map<string, string>();\n\n public async *add({\n file,\n }: {\n file: File;\n }): AsyncGenerator<PendingAttachment, void> {\n const id = crypto.randomUUID();\n const type = guessAttachmentType(file.type);\n let attachment: PendingAttachment = {\n id,\n type,\n name: file.name,\n contentType: file.type,\n file,\n status: { type: \"running\", reason: \"uploading\", progress: 0 },\n };\n yield attachment;\n\n try {\n const { signedUrl, publicUrl } =\n await this.cloud.files.generatePresignedUploadUrl({\n filename: file.name,\n });\n await fetch(signedUrl, {\n method: \"PUT\",\n body: file,\n headers: {\n \"Content-Type\": file.type,\n },\n mode: \"cors\",\n });\n this.uploadedUrls.set(id, publicUrl);\n attachment = {\n ...attachment,\n status: { type: \"requires-action\", reason: \"composer-send\" },\n };\n yield attachment;\n } catch {\n attachment = {\n ...attachment,\n status: { type: \"incomplete\", reason: \"error\" },\n };\n yield attachment;\n }\n }\n\n public async remove(attachment: Attachment): Promise<void> {\n this.uploadedUrls.delete(attachment.id);\n }\n\n public async send(\n attachment: PendingAttachment,\n ): Promise<CompleteAttachment> {\n const url = this.uploadedUrls.get(attachment.id);\n if (!url) throw new Error(\"Attachment not uploaded\");\n this.uploadedUrls.delete(attachment.id);\n\n let content: ThreadUserMessagePart[];\n if (attachment.type === \"image\") {\n content = [{ type: \"image\", image: url, filename: attachment.name }];\n } else {\n content = [\n {\n type: \"file\",\n data: url,\n mimeType: attachment.contentType,\n filename: attachment.name,\n },\n ];\n }\n\n return {\n ...attachment,\n status: { type: \"complete\" },\n content,\n };\n }\n}\n"],"mappings":";AASA,IAAM,sBAAsB,CAC1B,gBACkC;AAClC,MAAI,YAAY,WAAW,QAAQ,EAAG,QAAO;AAC7C,MAAI,YAAY,WAAW,OAAO,EAAG,QAAO;AAC5C,SAAO;AACT;AAEO,IAAM,6BAAN,MAA8D;AAAA,EAGnE,YAAoB,OAAuB;AAAvB;AAAA,EAAwB;AAAA,EAFrC,SAAS;AAAA,EAIR,eAAe,oBAAI,IAAoB;AAAA,EAE/C,OAAc,IAAI;AAAA,IAChB;AAAA,EACF,GAE4C;AAC1C,UAAM,KAAK,OAAO,WAAW;AAC7B,UAAM,OAAO,oBAAoB,KAAK,IAAI;AAC1C,QAAI,aAAgC;AAAA,MAClC;AAAA,MACA;AAAA,MACA,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB;AAAA,MACA,QAAQ,EAAE,MAAM,WAAW,QAAQ,aAAa,UAAU,EAAE;AAAA,IAC9D;AACA,UAAM;AAEN,QAAI;AACF,YAAM,EAAE,WAAW,UAAU,IAC3B,MAAM,KAAK,MAAM,MAAM,2BAA2B;AAAA,QAChD,UAAU,KAAK;AAAA,MACjB,CAAC;AACH,YAAM,MAAM,WAAW;AAAA,QACrB,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,SAAS;AAAA,UACP,gBAAgB,KAAK;AAAA,QACvB;AAAA,QACA,MAAM;AAAA,MACR,CAAC;AACD,WAAK,aAAa,IAAI,IAAI,SAAS;AACnC,mBAAa;AAAA,QACX,GAAG;AAAA,QACH,QAAQ,EAAE,MAAM,mBAAmB,QAAQ,gBAAgB;AAAA,MAC7D;AACA,YAAM;AAAA,IACR,QAAQ;AACN,mBAAa;AAAA,QACX,GAAG;AAAA,QACH,QAAQ,EAAE,MAAM,cAAc,QAAQ,QAAQ;AAAA,MAChD;AACA,YAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,MAAa,OAAO,YAAuC;AACzD,SAAK,aAAa,OAAO,WAAW,EAAE;AAAA,EACxC;AAAA,EAEA,MAAa,KACX,YAC6B;AAC7B,UAAM,MAAM,KAAK,aAAa,IAAI,WAAW,EAAE;AAC/C,QAAI,CAAC,IAAK,OAAM,IAAI,MAAM,yBAAyB;AACnD,SAAK,aAAa,OAAO,WAAW,EAAE;AAEtC,QAAI;AACJ,QAAI,WAAW,SAAS,SAAS;AAC/B,gBAAU,CAAC,EAAE,MAAM,SAAS,OAAO,KAAK,UAAU,WAAW,KAAK,CAAC;AAAA,IACrE,OAAO;AACL,gBAAU;AAAA,QACR;AAAA,UACE,MAAM;AAAA,UACN,MAAM;AAAA,UACN,UAAU,WAAW;AAAA,UACrB,UAAU,WAAW;AAAA,QACvB;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH,QAAQ,EAAE,MAAM,WAAW;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
@@ -2,4 +2,5 @@ export type { AttachmentAdapter } from "./AttachmentAdapter";
|
|
2
2
|
export { SimpleImageAttachmentAdapter } from "./SimpleImageAttachmentAdapter";
|
3
3
|
export { SimpleTextAttachmentAdapter } from "./SimpleTextAttachmentAdapter";
|
4
4
|
export { CompositeAttachmentAdapter } from "./CompositeAttachmentAdapter";
|
5
|
+
export { CloudFileAttachmentAdapter } from "./CloudFileAttachmentAdapter";
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/adapters/attachment/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/adapters/attachment/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC"}
|
@@ -2,7 +2,9 @@
|
|
2
2
|
import { SimpleImageAttachmentAdapter } from "./SimpleImageAttachmentAdapter.js";
|
3
3
|
import { SimpleTextAttachmentAdapter } from "./SimpleTextAttachmentAdapter.js";
|
4
4
|
import { CompositeAttachmentAdapter } from "./CompositeAttachmentAdapter.js";
|
5
|
+
import { CloudFileAttachmentAdapter } from "./CloudFileAttachmentAdapter.js";
|
5
6
|
export {
|
7
|
+
CloudFileAttachmentAdapter,
|
6
8
|
CompositeAttachmentAdapter,
|
7
9
|
SimpleImageAttachmentAdapter,
|
8
10
|
SimpleTextAttachmentAdapter
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/adapters/attachment/index.ts"],"sourcesContent":["export type { AttachmentAdapter } from \"./AttachmentAdapter\";\nexport { SimpleImageAttachmentAdapter } from \"./SimpleImageAttachmentAdapter\";\nexport { SimpleTextAttachmentAdapter } from \"./SimpleTextAttachmentAdapter\";\nexport { CompositeAttachmentAdapter } from \"./CompositeAttachmentAdapter\";\
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/adapters/attachment/index.ts"],"sourcesContent":["export type { AttachmentAdapter } from \"./AttachmentAdapter\";\nexport { SimpleImageAttachmentAdapter } from \"./SimpleImageAttachmentAdapter\";\nexport { SimpleTextAttachmentAdapter } from \"./SimpleTextAttachmentAdapter\";\nexport { CompositeAttachmentAdapter } from \"./CompositeAttachmentAdapter\";\nexport { CloudFileAttachmentAdapter } from \"./CloudFileAttachmentAdapter\";"],"mappings":";AACA,SAAS,oCAAoC;AAC7C,SAAS,mCAAmC;AAC5C,SAAS,kCAAkC;AAC3C,SAAS,kCAAkC;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/remote-thread-list/adapter/cloud.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;
|
1
|
+
{"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/remote-thread-list/adapter/cloud.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAMnD,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,6BAA6B,GAAG;IACnC,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IAEnC,MAAM,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/B,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C,CAAC;AASF,eAAO,MAAM,yBAAyB,GACpC,SAAS,6BAA6B,KACrC,uBA0FF,CAAC"}
|
@@ -11,6 +11,7 @@ import { AssistantCloud } from "assistant-cloud";
|
|
11
11
|
import { useAssistantCloudThreadHistoryAdapter } from "../../../cloud/AssistantCloudThreadHistoryAdapter.js";
|
12
12
|
import { RuntimeAdapterProvider } from "../../adapters/RuntimeAdapterProvider.js";
|
13
13
|
import { InMemoryThreadListAdapter } from "./in-memory.js";
|
14
|
+
import { CloudFileAttachmentAdapter } from "../../adapters/index.js";
|
14
15
|
import { jsx } from "react/jsx-runtime";
|
15
16
|
var baseUrl = typeof process !== "undefined" && process?.env?.["NEXT_PUBLIC_ASSISTANT_BASE_URL"];
|
16
17
|
var autoCloud = baseUrl ? new AssistantCloud({ baseUrl, anonymous: true }) : void 0;
|
@@ -26,7 +27,19 @@ var useCloudThreadListAdapter = (adapter) => {
|
|
26
27
|
return adapterRef.current.cloud ?? autoCloud;
|
27
28
|
}
|
28
29
|
});
|
29
|
-
const
|
30
|
+
const attachments = useMemo(
|
31
|
+
() => new CloudFileAttachmentAdapter(
|
32
|
+
adapterRef.current.cloud ?? autoCloud
|
33
|
+
),
|
34
|
+
[adapterRef.current.cloud]
|
35
|
+
);
|
36
|
+
const adapters = useMemo(
|
37
|
+
() => ({
|
38
|
+
history,
|
39
|
+
attachments
|
40
|
+
}),
|
41
|
+
[history]
|
42
|
+
);
|
30
43
|
return /* @__PURE__ */ jsx(RuntimeAdapterProvider, { adapters, children });
|
31
44
|
},
|
32
45
|
[]
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/remote-thread-list/adapter/cloud.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n FC,\n PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { AssistantCloud } from \"assistant-cloud\";\nimport { RemoteThreadListAdapter } from \"../types\";\nimport { useAssistantCloudThreadHistoryAdapter } from \"../../../cloud/AssistantCloudThreadHistoryAdapter\";\nimport { RuntimeAdapterProvider } from \"../../adapters/RuntimeAdapterProvider\";\nimport { InMemoryThreadListAdapter } from \"./in-memory\";\n\ntype ThreadData = {\n externalId: string;\n};\n\ntype CloudThreadListAdapterOptions = {\n cloud?: AssistantCloud | undefined;\n\n create?(): Promise<ThreadData>;\n delete?(threadId: string): Promise<void>;\n};\n\nconst baseUrl =\n typeof process !== \"undefined\" &&\n process?.env?.[\"NEXT_PUBLIC_ASSISTANT_BASE_URL\"];\nconst autoCloud = baseUrl\n ? new AssistantCloud({ baseUrl, anonymous: true })\n : undefined;\n\nexport const useCloudThreadListAdapter = (\n adapter: CloudThreadListAdapterOptions,\n): RemoteThreadListAdapter => {\n const adapterRef = useRef(adapter);\n useEffect(() => {\n adapterRef.current = adapter;\n }, [adapter]);\n\n const unstable_Provider = useCallback<FC<PropsWithChildren>>(\n function Provider({ children }) {\n const history = useAssistantCloudThreadHistoryAdapter({\n get current() {\n return adapterRef.current.cloud ?? autoCloud!;\n },\n });\n const adapters = useMemo(() => ({
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/remote-thread-list/adapter/cloud.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n FC,\n PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { AssistantCloud } from \"assistant-cloud\";\nimport { RemoteThreadListAdapter } from \"../types\";\nimport { useAssistantCloudThreadHistoryAdapter } from \"../../../cloud/AssistantCloudThreadHistoryAdapter\";\nimport { RuntimeAdapterProvider } from \"../../adapters/RuntimeAdapterProvider\";\nimport { InMemoryThreadListAdapter } from \"./in-memory\";\nimport { CloudFileAttachmentAdapter } from \"../../adapters\";\n\ntype ThreadData = {\n externalId: string;\n};\n\ntype CloudThreadListAdapterOptions = {\n cloud?: AssistantCloud | undefined;\n\n create?(): Promise<ThreadData>;\n delete?(threadId: string): Promise<void>;\n};\n\nconst baseUrl =\n typeof process !== \"undefined\" &&\n process?.env?.[\"NEXT_PUBLIC_ASSISTANT_BASE_URL\"];\nconst autoCloud = baseUrl\n ? new AssistantCloud({ baseUrl, anonymous: true })\n : undefined;\n\nexport const useCloudThreadListAdapter = (\n adapter: CloudThreadListAdapterOptions,\n): RemoteThreadListAdapter => {\n const adapterRef = useRef(adapter);\n useEffect(() => {\n adapterRef.current = adapter;\n }, [adapter]);\n\n const unstable_Provider = useCallback<FC<PropsWithChildren>>(\n function Provider({ children }) {\n const history = useAssistantCloudThreadHistoryAdapter({\n get current() {\n return adapterRef.current.cloud ?? autoCloud!;\n },\n });\n const attachments = useMemo(\n () =>\n new CloudFileAttachmentAdapter(\n adapterRef.current.cloud ?? autoCloud!,\n ),\n [adapterRef.current.cloud],\n );\n\n const adapters = useMemo(\n () => ({\n history,\n attachments,\n }),\n [history],\n );\n\n return (\n <RuntimeAdapterProvider adapters={adapters}>\n {children}\n </RuntimeAdapterProvider>\n );\n },\n [],\n );\n\n const cloud = adapter.cloud ?? autoCloud;\n if (!cloud) return new InMemoryThreadListAdapter();\n\n return {\n list: async () => {\n const { threads } = await cloud.threads.list();\n return {\n threads: threads.map((t) => ({\n status: t.is_archived ? \"archived\" : \"regular\",\n remoteId: t.id,\n title: t.title,\n externalId: t.external_id ?? undefined,\n })),\n };\n },\n\n initialize: async () => {\n const createTask = adapter.create?.() ?? Promise.resolve();\n const t = await createTask;\n const external_id = t ? t.externalId : undefined;\n const { thread_id: remoteId } = await cloud.threads.create({\n last_message_at: new Date(),\n external_id,\n });\n\n return { externalId: external_id, remoteId: remoteId };\n },\n\n rename: async (threadId, newTitle) => {\n return cloud.threads.update(threadId, { title: newTitle });\n },\n archive: async (threadId) => {\n return cloud.threads.update(threadId, { is_archived: true });\n },\n unarchive: async (threadId) => {\n return cloud.threads.update(threadId, { is_archived: false });\n },\n delete: async (threadId) => {\n await adapter.delete?.(threadId);\n return cloud.threads.delete(threadId);\n },\n\n generateTitle: async (threadId, messages) => {\n return cloud.runs.stream({\n thread_id: threadId,\n assistant_id: \"system/thread_title\",\n messages: messages, // TODO serialize these to a more efficient format\n });\n },\n\n unstable_Provider,\n };\n};\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAE/B,SAAS,6CAA6C;AACtD,SAAS,8BAA8B;AACvC,SAAS,iCAAiC;AAC1C,SAAS,kCAAkC;AAoDnC;AAvCR,IAAM,UACJ,OAAO,YAAY,eACnB,SAAS,MAAM,gCAAgC;AACjD,IAAM,YAAY,UACd,IAAI,eAAe,EAAE,SAAS,WAAW,KAAK,CAAC,IAC/C;AAEG,IAAM,4BAA4B,CACvC,YAC4B;AAC5B,QAAM,aAAa,OAAO,OAAO;AACjC,YAAU,MAAM;AACd,eAAW,UAAU;AAAA,EACvB,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,oBAAoB;AAAA,IACxB,SAAS,SAAS,EAAE,SAAS,GAAG;AAC9B,YAAM,UAAU,sCAAsC;AAAA,QACpD,IAAI,UAAU;AACZ,iBAAO,WAAW,QAAQ,SAAS;AAAA,QACrC;AAAA,MACF,CAAC;AACD,YAAM,cAAc;AAAA,QAClB,MACE,IAAI;AAAA,UACF,WAAW,QAAQ,SAAS;AAAA,QAC9B;AAAA,QACF,CAAC,WAAW,QAAQ,KAAK;AAAA,MAC3B;AAEA,YAAM,WAAW;AAAA,QACf,OAAO;AAAA,UACL;AAAA,UACA;AAAA,QACF;AAAA,QACA,CAAC,OAAO;AAAA,MACV;AAEA,aACE,oBAAC,0BAAuB,UACrB,UACH;AAAA,IAEJ;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,QAAQ,QAAQ,SAAS;AAC/B,MAAI,CAAC,MAAO,QAAO,IAAI,0BAA0B;AAEjD,SAAO;AAAA,IACL,MAAM,YAAY;AAChB,YAAM,EAAE,QAAQ,IAAI,MAAM,MAAM,QAAQ,KAAK;AAC7C,aAAO;AAAA,QACL,SAAS,QAAQ,IAAI,CAAC,OAAO;AAAA,UAC3B,QAAQ,EAAE,cAAc,aAAa;AAAA,UACrC,UAAU,EAAE;AAAA,UACZ,OAAO,EAAE;AAAA,UACT,YAAY,EAAE,eAAe;AAAA,QAC/B,EAAE;AAAA,MACJ;AAAA,IACF;AAAA,IAEA,YAAY,YAAY;AACtB,YAAM,aAAa,QAAQ,SAAS,KAAK,QAAQ,QAAQ;AACzD,YAAM,IAAI,MAAM;AAChB,YAAM,cAAc,IAAI,EAAE,aAAa;AACvC,YAAM,EAAE,WAAW,SAAS,IAAI,MAAM,MAAM,QAAQ,OAAO;AAAA,QACzD,iBAAiB,oBAAI,KAAK;AAAA,QAC1B;AAAA,MACF,CAAC;AAED,aAAO,EAAE,YAAY,aAAa,SAAmB;AAAA,IACvD;AAAA,IAEA,QAAQ,OAAO,UAAU,aAAa;AACpC,aAAO,MAAM,QAAQ,OAAO,UAAU,EAAE,OAAO,SAAS,CAAC;AAAA,IAC3D;AAAA,IACA,SAAS,OAAO,aAAa;AAC3B,aAAO,MAAM,QAAQ,OAAO,UAAU,EAAE,aAAa,KAAK,CAAC;AAAA,IAC7D;AAAA,IACA,WAAW,OAAO,aAAa;AAC7B,aAAO,MAAM,QAAQ,OAAO,UAAU,EAAE,aAAa,MAAM,CAAC;AAAA,IAC9D;AAAA,IACA,QAAQ,OAAO,aAAa;AAC1B,YAAM,QAAQ,SAAS,QAAQ;AAC/B,aAAO,MAAM,QAAQ,OAAO,QAAQ;AAAA,IACtC;AAAA,IAEA,eAAe,OAAO,UAAU,aAAa;AAC3C,aAAO,MAAM,KAAK,OAAO;AAAA,QACvB,WAAW;AAAA,QACX,cAAc;AAAA,QACd;AAAA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IAEA;AAAA,EACF;AACF;","names":[]}
|
package/dist/tests/setup.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.
|
1
|
+
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.1_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.5/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
|
2
2
|
import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers } from "@vitest/expect.js";
|
3
3
|
import { getCurrentTest } from "@vitest/runner.js";
|
4
4
|
import { getNames, getTestName } from "@vitest/runner/utils.js";
|
5
5
|
import * as chai$1 from "chai.js";
|
6
6
|
|
7
|
-
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.
|
7
|
+
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.1_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.5/node_modules/vitest/dist/chunks/utils.XdZDrNZV.js
|
8
8
|
import { getSafeTimers } from "@vitest/utils.js";
|
9
9
|
var NAME_WORKER_STATE = "__vitest_worker__";
|
10
10
|
function getWorkerState() {
|
@@ -53,22 +53,22 @@ async function waitForImportsToResolve() {
|
|
53
53
|
await waitForImportsToResolve();
|
54
54
|
}
|
55
55
|
|
56
|
-
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.
|
56
|
+
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.1_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.5/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
|
57
57
|
import { getSafeTimers as getSafeTimers2, assertTypes, createSimpleStackTrace } from "@vitest/utils.js";
|
58
58
|
|
59
|
-
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.
|
59
|
+
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.1_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.5/node_modules/vitest/dist/chunks/_commonjsHelpers.BFTU3MAI.js
|
60
60
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
61
61
|
function getDefaultExportFromCjs(x) {
|
62
62
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
63
63
|
}
|
64
64
|
|
65
|
-
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.
|
65
|
+
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.1_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.5/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
|
66
66
|
import { stripSnapshotIndentation, addSerializer, SnapshotClient } from "@vitest/snapshot.js";
|
67
67
|
import "@vitest/utils/error.js";
|
68
68
|
import { fn, spyOn, mocks, isMockFunction } from "@vitest/spy.js";
|
69
69
|
import { parseSingleStack } from "@vitest/utils/source-map.js";
|
70
70
|
|
71
|
-
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.
|
71
|
+
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.1_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.5/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.js
|
72
72
|
var RealDate = Date;
|
73
73
|
var now = null;
|
74
74
|
var MockDate = class _MockDate extends RealDate {
|
@@ -116,7 +116,7 @@ function resetDate() {
|
|
116
116
|
globalThis.Date = RealDate;
|
117
117
|
}
|
118
118
|
|
119
|
-
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.
|
119
|
+
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.1_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.5/node_modules/vitest/dist/chunks/vi.bdSIJ99Y.js
|
120
120
|
var unsupported = [
|
121
121
|
"matchSnapshot",
|
122
122
|
"toMatchSnapshot",
|
@@ -2800,7 +2800,7 @@ function getImporter(name) {
|
|
2800
2800
|
return stack?.file || "";
|
2801
2801
|
}
|
2802
2802
|
|
2803
|
-
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.
|
2803
|
+
// ../../node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@24.3.1_jiti@2.5.1_jsdom@26.1.0_lightningcss@1.30.1_tsx@4.20.5/node_modules/vitest/dist/index.js
|
2804
2804
|
import { expectTypeOf } from "expect-type.js";
|
2805
2805
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from "@vitest/runner.js";
|
2806
2806
|
import * as chai2 from "chai.js";
|