@assistant-ui/react 0.10.22 → 0.10.23
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/AssistantCloudFiles.d.ts.map +1 -1
- package/dist/cloud/AssistantCloudFiles.js +7 -4
- package/dist/cloud/AssistantCloudFiles.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/package.json +1 -1
- package/src/cloud/AssistantCloudFiles.tsx +8 -5
- package/src/runtimes/local/index.ts +1 -1
- package/src/tests/AssistantCloudFiles.test.ts +122 -79
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AssistantCloudFiles.d.ts","sourceRoot":"","sources":["../../src/cloud/AssistantCloudFiles.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,KAAK,sBAAsB,GAAG;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,qCAAqC,GAAG;IAC3C,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,kCAAkC,GAAG;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,qBAAa,mBAAmB;IAClB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,iBAAiB;IAE/B,WAAW,CACtB,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAAC,mBAAmB,CAAC;IAOlB,0BAA0B,CACrC,IAAI,EAAE,qCAAqC,GAC1C,OAAO,CAAC,kCAAkC,CAAC;
|
1
|
+
{"version":3,"file":"AssistantCloudFiles.d.ts","sourceRoot":"","sources":["../../src/cloud/AssistantCloudFiles.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,KAAK,sBAAsB,GAAG;IAC5B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,qCAAqC,GAAG;IAC3C,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,kCAAkC,GAAG;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,qBAAa,mBAAmB;IAClB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,iBAAiB;IAE/B,WAAW,CACtB,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAAC,mBAAmB,CAAC;IAOlB,0BAA0B,CACrC,IAAI,EAAE,qCAAqC,GAC1C,OAAO,CAAC,kCAAkC,CAAC;CAS/C"}
|
@@ -10,10 +10,13 @@ var AssistantCloudFiles = class {
|
|
10
10
|
});
|
11
11
|
}
|
12
12
|
async generatePresignedUploadUrl(body) {
|
13
|
-
return this.cloud.makeRequest(
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
return this.cloud.makeRequest(
|
14
|
+
"/files/attachments/generate-presigned-upload-url",
|
15
|
+
{
|
16
|
+
method: "POST",
|
17
|
+
body
|
18
|
+
}
|
19
|
+
);
|
17
20
|
}
|
18
21
|
};
|
19
22
|
export {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/cloud/AssistantCloudFiles.tsx"],"sourcesContent":["import { AssistantCloudAPI } from \"./AssistantCloudAPI\";\n\ntype PdfToImagesRequestBody = {\n file_blob?: string | undefined;\n file_url?: string | undefined;\n};\n\ntype PdfToImagesResponse = {\n success: boolean;\n urls: string[];\n message: string;\n};\n\ntype GeneratePresignedUploadUrlRequestBody = {\n filename: string;\n};\n\ntype GeneratePresignedUploadUrlResponse = {\n success: boolean;\n signedUrl: string;\n expiresAt: string;\n publicUrl: string;\n};\n\nexport class AssistantCloudFiles {\n constructor(private cloud: AssistantCloudAPI) {}\n\n public async pdfToImages(\n body: PdfToImagesRequestBody,\n ): Promise<PdfToImagesResponse> {\n return this.cloud.makeRequest(\"/files/pdf-to-images\", {\n method: \"POST\",\n body,\n });\n }\n\n public async generatePresignedUploadUrl(\n body: GeneratePresignedUploadUrlRequestBody,\n ): Promise<GeneratePresignedUploadUrlResponse> {\n return this.cloud.makeRequest(\"/files/attachments/generate-presigned-upload-url\"
|
1
|
+
{"version":3,"sources":["../../src/cloud/AssistantCloudFiles.tsx"],"sourcesContent":["import { AssistantCloudAPI } from \"./AssistantCloudAPI\";\n\ntype PdfToImagesRequestBody = {\n file_blob?: string | undefined;\n file_url?: string | undefined;\n};\n\ntype PdfToImagesResponse = {\n success: boolean;\n urls: string[];\n message: string;\n};\n\ntype GeneratePresignedUploadUrlRequestBody = {\n filename: string;\n};\n\ntype GeneratePresignedUploadUrlResponse = {\n success: boolean;\n signedUrl: string;\n expiresAt: string;\n publicUrl: string;\n};\n\nexport class AssistantCloudFiles {\n constructor(private cloud: AssistantCloudAPI) {}\n\n public async pdfToImages(\n body: PdfToImagesRequestBody,\n ): Promise<PdfToImagesResponse> {\n return this.cloud.makeRequest(\"/files/pdf-to-images\", {\n method: \"POST\",\n body,\n });\n }\n\n public async generatePresignedUploadUrl(\n body: GeneratePresignedUploadUrlRequestBody,\n ): Promise<GeneratePresignedUploadUrlResponse> {\n return this.cloud.makeRequest(\n \"/files/attachments/generate-presigned-upload-url\",\n {\n method: \"POST\",\n body,\n },\n );\n }\n}\n"],"mappings":";AAwBO,IAAM,sBAAN,MAA0B;AAAA,EAC/B,YAAoB,OAA0B;AAA1B;AAAA,EAA2B;AAAA,EAE/C,MAAa,YACX,MAC8B;AAC9B,WAAO,KAAK,MAAM,YAAY,wBAAwB;AAAA,MACpD,QAAQ;AAAA,MACR;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAAa,2BACX,MAC6C;AAC7C,WAAO,KAAK,MAAM;AAAA,MAChB;AAAA,MACA;AAAA,QACE,QAAQ;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export { useLocalRuntime } from "./useLocalRuntime";
|
1
|
+
export { useLocalRuntime, useLocalThreadRuntime } from "./useLocalRuntime";
|
2
2
|
export type { LocalRuntimeOptions } from "./LocalRuntimeOptions";
|
3
3
|
export type { ChatModelAdapter, ChatModelRunOptions, ChatModelRunResult, ChatModelRunUpdate, } from "./ChatModelAdapter";
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtimes/local/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
// src/runtimes/local/index.ts
|
2
|
-
import { useLocalRuntime } from "./useLocalRuntime.js";
|
2
|
+
import { useLocalRuntime, useLocalThreadRuntime } from "./useLocalRuntime.js";
|
3
3
|
export {
|
4
|
-
useLocalRuntime
|
4
|
+
useLocalRuntime,
|
5
|
+
useLocalThreadRuntime
|
5
6
|
};
|
6
7
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/local/index.ts"],"sourcesContent":["export { useLocalRuntime } from \"./useLocalRuntime\";\nexport type { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nexport type {\n ChatModelAdapter,\n ChatModelRunOptions,\n ChatModelRunResult,\n ChatModelRunUpdate,\n} from \"./ChatModelAdapter\";\n"],"mappings":";AAAA,SAAS,
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/local/index.ts"],"sourcesContent":["export { useLocalRuntime, useLocalThreadRuntime } from \"./useLocalRuntime\";\nexport type { LocalRuntimeOptions } from \"./LocalRuntimeOptions\";\nexport type {\n ChatModelAdapter,\n ChatModelRunOptions,\n ChatModelRunResult,\n ChatModelRunUpdate,\n} from \"./ChatModelAdapter\";\n"],"mappings":";AAAA,SAAS,iBAAiB,6BAA6B;","names":[]}
|
package/package.json
CHANGED
@@ -37,9 +37,12 @@ export class AssistantCloudFiles {
|
|
37
37
|
public async generatePresignedUploadUrl(
|
38
38
|
body: GeneratePresignedUploadUrlRequestBody,
|
39
39
|
): Promise<GeneratePresignedUploadUrlResponse> {
|
40
|
-
return this.cloud.makeRequest(
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
return this.cloud.makeRequest(
|
41
|
+
"/files/attachments/generate-presigned-upload-url",
|
42
|
+
{
|
43
|
+
method: "POST",
|
44
|
+
body,
|
45
|
+
},
|
46
|
+
);
|
44
47
|
}
|
45
|
-
}
|
48
|
+
}
|
@@ -37,16 +37,16 @@ describe("AssistantCloudFiles", () => {
|
|
37
37
|
urls: [
|
38
38
|
"https://aui-pdf-processing.5c52327048f352f85fb041947c406ab4.r2.cloudflarestorage.com/images/8eb81c61-dc76-48fd-ab66-25cd84a28c97/page-1.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=8698a7e98d990c6edd11fee3a9d0f3f0%2F20250606%2Fauto%2Fs3%2Faws4_request&X-Amz-Date=20250606T035428Z&X-Amz-Expires=3600&X-Amz-Signature=ea26cdd5ff7dc85eba12970137606484b9a8ab2c520f31ddba9cbe5941b20793&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject",
|
39
39
|
"https://aui-pdf-processing.5c52327048f352f85fb041947c406ab4.r2.cloudflarestorage.com/images/8eb81c61-dc76-48fd-ab66-25cd84a28c97/page-2.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=8698a7e98d990c6edd11fee3a9d0f3f0%2F20250606%2Fauto%2Fs3%2Faws4_request&X-Amz-Date=20250606T035428Z&X-Amz-Expires=3600&X-Amz-Signature=3499237770cc4402a60e6cc9b8ce8bd460faade9adf456d2773009f7d07af9cb&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject",
|
40
|
-
"https://aui-pdf-processing.5c52327048f352f85fb041947c406ab4.r2.cloudflarestorage.com/images/8eb81c61-dc76-48fd-ab66-25cd84a28c97/page-3.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=8698a7e98d990c6edd11fee3a9d0f3f0%2F20250606%2Fauto%2Fs3%2Faws4_request&X-Amz-Date=20250606T035429Z&X-Amz-Expires=3600&X-Amz-Signature=663ee073972f1b7b82cede9039ed4bc0a6c08118533a9586e871807baf032bc2&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject"
|
40
|
+
"https://aui-pdf-processing.5c52327048f352f85fb041947c406ab4.r2.cloudflarestorage.com/images/8eb81c61-dc76-48fd-ab66-25cd84a28c97/page-3.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=8698a7e98d990c6edd11fee3a9d0f3f0%2F20250606%2Fauto%2Fs3%2Faws4_request&X-Amz-Date=20250606T035429Z&X-Amz-Expires=3600&X-Amz-Signature=663ee073972f1b7b82cede9039ed4bc0a6c08118533a9586e871807baf032bc2&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject",
|
41
41
|
],
|
42
|
-
message: "PDF successfully converted to images"
|
42
|
+
message: "PDF successfully converted to images",
|
43
43
|
};
|
44
44
|
|
45
45
|
// Mock the API call to return our expected response
|
46
46
|
vi.mocked(mockApi.makeRequest).mockResolvedValue(mockResponse);
|
47
47
|
|
48
48
|
const requestBody = {
|
49
|
-
file_url: "https://files.testfile.org/PDF/10MB-TESTFILE.ORG.pdf"
|
49
|
+
file_url: "https://files.testfile.org/PDF/10MB-TESTFILE.ORG.pdf",
|
50
50
|
};
|
51
51
|
|
52
52
|
const result = await cloudFiles.pdfToImages(requestBody);
|
@@ -75,15 +75,16 @@ describe("AssistantCloudFiles", () => {
|
|
75
75
|
success: true,
|
76
76
|
urls: [
|
77
77
|
"https://example.com/converted-image-1.png",
|
78
|
-
"https://example.com/converted-image-2.png"
|
78
|
+
"https://example.com/converted-image-2.png",
|
79
79
|
],
|
80
|
-
message: "PDF successfully converted to images"
|
80
|
+
message: "PDF successfully converted to images",
|
81
81
|
};
|
82
82
|
|
83
83
|
vi.mocked(mockApi.makeRequest).mockResolvedValue(mockResponse);
|
84
84
|
|
85
85
|
const requestBody = {
|
86
|
-
file_blob:
|
86
|
+
file_blob:
|
87
|
+
"data:application/pdf;base64,JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKL01lZGlhQm94IFswIDAgNTk1IDg0Ml0KPj4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3ggWzAgMCA1OTUgODQyXQovQ29udGVudHMgNCAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL0xlbmd0aCA0NAo+PgpzdHJlYW0KQlQKL0YxIDEyIFRmCjEwMCA3MDAgVGQKKFRlc3QgUERGKSBUagoKRVQKZW5kc3RyZWFtCmVuZG9iago1IDAgb2JqCjw8Ci9UeXBlIC9Gb250Ci9CYXNlRm9udCAvSGVsdmV0aWNhCi9TdWJ0eXBlIC9UeXBlMQo+PgplbmRvYmoKNiAwIG9iago8PAovVHlwZSAvRm9udERlc2NyaXB0b3IKL0ZvbnROYW1lIC9IZWx2ZXRpY2EKPj4KZW5kb2JqCnhyZWYKMCA3CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAwOSAwMDAwMCBuIAowMDAwMDAwMDc0IDAwMDAwIG4gCjAwMDAwMDAxMzMgMDAwMDAgbiAKMDAwMDAwMDIwNCAwMDAwMCBuIAowMDAwMDAwMjk5IDAwMDAwIG4gCjAwMDAwMDAzNzYgMDAwMDAgbiAKdHJhaWxlcgo8PAovU2l6ZSA3Ci9Sb290IDEgMCBSCj4+CnN0YXJ0eHJlZgo0MzQKJSVFT0YK",
|
87
88
|
};
|
88
89
|
|
89
90
|
const result = await cloudFiles.pdfToImages(requestBody);
|
@@ -106,10 +107,12 @@ describe("AssistantCloudFiles", () => {
|
|
106
107
|
vi.mocked(mockApi.makeRequest).mockRejectedValue(new Error(errorMessage));
|
107
108
|
|
108
109
|
const requestBody = {
|
109
|
-
file_url: "https://invalid-url.com/not-a-pdf.txt"
|
110
|
+
file_url: "https://invalid-url.com/not-a-pdf.txt",
|
110
111
|
};
|
111
112
|
|
112
|
-
await expect(cloudFiles.pdfToImages(requestBody)).rejects.toThrow(
|
113
|
+
await expect(cloudFiles.pdfToImages(requestBody)).rejects.toThrow(
|
114
|
+
errorMessage,
|
115
|
+
);
|
113
116
|
|
114
117
|
expect(mockApi.makeRequest).toHaveBeenCalledWith("/files/pdf-to-images", {
|
115
118
|
method: "POST",
|
@@ -124,13 +127,13 @@ describe("AssistantCloudFiles", () => {
|
|
124
127
|
const mockResponse = {
|
125
128
|
success: false,
|
126
129
|
urls: [],
|
127
|
-
message: "Failed to convert PDF: File too large"
|
130
|
+
message: "Failed to convert PDF: File too large",
|
128
131
|
};
|
129
132
|
|
130
133
|
vi.mocked(mockApi.makeRequest).mockResolvedValue(mockResponse);
|
131
134
|
|
132
135
|
const requestBody = {
|
133
|
-
file_url: "https://example.com/huge-file.pdf"
|
136
|
+
file_url: "https://example.com/huge-file.pdf",
|
134
137
|
};
|
135
138
|
|
136
139
|
const result = await cloudFiles.pdfToImages(requestBody);
|
@@ -147,7 +150,7 @@ describe("AssistantCloudFiles", () => {
|
|
147
150
|
const mockResponse = {
|
148
151
|
success: false,
|
149
152
|
urls: [],
|
150
|
-
message: "No file provided"
|
153
|
+
message: "No file provided",
|
151
154
|
};
|
152
155
|
|
153
156
|
vi.mocked(mockApi.makeRequest).mockResolvedValue(mockResponse);
|
@@ -173,13 +176,13 @@ describe("AssistantCloudFiles", () => {
|
|
173
176
|
const mockResponse = {
|
174
177
|
success: true,
|
175
178
|
urls: ["https://example.com/image.png"],
|
176
|
-
message: "Success"
|
179
|
+
message: "Success",
|
177
180
|
};
|
178
181
|
|
179
182
|
vi.mocked(mockApi.makeRequest).mockResolvedValue(mockResponse);
|
180
183
|
|
181
184
|
const requestBody = {
|
182
|
-
file_url: "https://files.testfile.org/PDF/10MB-TESTFILE.ORG.pdf"
|
185
|
+
file_url: "https://files.testfile.org/PDF/10MB-TESTFILE.ORG.pdf",
|
183
186
|
};
|
184
187
|
|
185
188
|
await cloudFiles.pdfToImages(requestBody);
|
@@ -201,14 +204,14 @@ describe("AssistantCloudFiles", () => {
|
|
201
204
|
const mockResponse = {
|
202
205
|
success: true,
|
203
206
|
urls: ["https://example.com/image.png"],
|
204
|
-
message: "Success"
|
207
|
+
message: "Success",
|
205
208
|
};
|
206
209
|
|
207
210
|
vi.mocked(mockApi.makeRequest).mockResolvedValue(mockResponse);
|
208
211
|
|
209
212
|
const requestBody = {
|
210
213
|
file_url: "https://example.com/file.pdf",
|
211
|
-
file_blob: "base64data..."
|
214
|
+
file_blob: "base64data...",
|
212
215
|
};
|
213
216
|
|
214
217
|
const result = await cloudFiles.pdfToImages(requestBody);
|
@@ -230,25 +233,30 @@ describe("AssistantCloudFiles", () => {
|
|
230
233
|
it("should successfully generate presigned upload URL", async () => {
|
231
234
|
const mockResponse = {
|
232
235
|
success: true,
|
233
|
-
signedUrl:
|
236
|
+
signedUrl:
|
237
|
+
"https://aui-cloud-attachments.5c52327048f352f85fb041947c406ab4.r2.cloudflarestorage.com/attachments/0204c5a7-cd09-470c-9488-96cf0be9db92.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=8698a7e98d990c6edd11fee3a9d0f3f0%2F20250606%2Fauto%2Fs3%2Faws4_request&X-Amz-Date=20250606T051813Z&X-Amz-Expires=900&X-Amz-Signature=b0d27e7bee6200eb1964ad1d7f4a8ad76db15a3d99bd4fb47ff4b0b08fee5ca5&X-Amz-SignedHeaders=content-length%3Bhost&x-amz-checksum-crc32=AAAAAA%3D%3D&x-amz-meta-original-filename=hello.pdf&x-amz-meta-project-id=proj_09369w56dnge&x-amz-meta-user-id=676767&x-amz-sdk-checksum-algorithm=CRC32&x-id=PutObject",
|
234
238
|
expiresAt: "2025-06-06T05:33:13.322Z",
|
235
|
-
publicUrl:
|
239
|
+
publicUrl:
|
240
|
+
"https://storage.assistant-api.com/attachments/0204c5a7-cd09-470c-9488-96cf0be9db92.pdf",
|
236
241
|
};
|
237
242
|
|
238
243
|
// Mock the API call to return our expected response
|
239
244
|
vi.mocked(mockApi.makeRequest).mockResolvedValue(mockResponse);
|
240
245
|
|
241
246
|
const requestBody = {
|
242
|
-
filename: "hello.pdf"
|
247
|
+
filename: "hello.pdf",
|
243
248
|
};
|
244
249
|
|
245
250
|
const result = await cloudFiles.generatePresignedUploadUrl(requestBody);
|
246
251
|
|
247
252
|
// Verify the API was called correctly
|
248
|
-
expect(mockApi.makeRequest).toHaveBeenCalledWith(
|
249
|
-
|
250
|
-
|
251
|
-
|
253
|
+
expect(mockApi.makeRequest).toHaveBeenCalledWith(
|
254
|
+
"/files/attachments/generate-presigned-upload-url",
|
255
|
+
{
|
256
|
+
method: "POST",
|
257
|
+
body: requestBody,
|
258
|
+
},
|
259
|
+
);
|
252
260
|
|
253
261
|
// Verify the response structure
|
254
262
|
expect(result).toEqual(mockResponse);
|
@@ -256,7 +264,9 @@ describe("AssistantCloudFiles", () => {
|
|
256
264
|
expect(result.signedUrl).toContain("aui-cloud-attachments");
|
257
265
|
expect(result.signedUrl).toContain("X-Amz-Algorithm=AWS4-HMAC-SHA256");
|
258
266
|
expect(result.expiresAt).toBe("2025-06-06T05:33:13.322Z");
|
259
|
-
expect(result.publicUrl).toBe(
|
267
|
+
expect(result.publicUrl).toBe(
|
268
|
+
"https://storage.assistant-api.com/attachments/0204c5a7-cd09-470c-9488-96cf0be9db92.pdf",
|
269
|
+
);
|
260
270
|
});
|
261
271
|
|
262
272
|
/**
|
@@ -265,23 +275,28 @@ describe("AssistantCloudFiles", () => {
|
|
265
275
|
it("should successfully generate presigned upload URL for different file types", async () => {
|
266
276
|
const mockResponse = {
|
267
277
|
success: true,
|
268
|
-
signedUrl:
|
278
|
+
signedUrl:
|
279
|
+
"https://aui-cloud-attachments.5c52327048f352f85fb041947c406ab4.r2.cloudflarestorage.com/attachments/test-image.png",
|
269
280
|
expiresAt: "2025-06-06T05:33:13.322Z",
|
270
|
-
publicUrl:
|
281
|
+
publicUrl:
|
282
|
+
"https://storage.assistant-api.com/attachments/test-image.png",
|
271
283
|
};
|
272
284
|
|
273
285
|
vi.mocked(mockApi.makeRequest).mockResolvedValue(mockResponse);
|
274
286
|
|
275
287
|
const requestBody = {
|
276
|
-
filename: "test-image.png"
|
288
|
+
filename: "test-image.png",
|
277
289
|
};
|
278
290
|
|
279
291
|
const result = await cloudFiles.generatePresignedUploadUrl(requestBody);
|
280
292
|
|
281
|
-
expect(mockApi.makeRequest).toHaveBeenCalledWith(
|
282
|
-
|
283
|
-
|
284
|
-
|
293
|
+
expect(mockApi.makeRequest).toHaveBeenCalledWith(
|
294
|
+
"/files/attachments/generate-presigned-upload-url",
|
295
|
+
{
|
296
|
+
method: "POST",
|
297
|
+
body: requestBody,
|
298
|
+
},
|
299
|
+
);
|
285
300
|
|
286
301
|
expect(result).toEqual(mockResponse);
|
287
302
|
expect(result.success).toBe(true);
|
@@ -296,15 +311,20 @@ describe("AssistantCloudFiles", () => {
|
|
296
311
|
vi.mocked(mockApi.makeRequest).mockRejectedValue(new Error(errorMessage));
|
297
312
|
|
298
313
|
const requestBody = {
|
299
|
-
filename: ""
|
314
|
+
filename: "",
|
300
315
|
};
|
301
316
|
|
302
|
-
await expect(
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
317
|
+
await expect(
|
318
|
+
cloudFiles.generatePresignedUploadUrl(requestBody),
|
319
|
+
).rejects.toThrow(errorMessage);
|
320
|
+
|
321
|
+
expect(mockApi.makeRequest).toHaveBeenCalledWith(
|
322
|
+
"/files/attachments/generate-presigned-upload-url",
|
323
|
+
{
|
324
|
+
method: "POST",
|
325
|
+
body: requestBody,
|
326
|
+
},
|
327
|
+
);
|
308
328
|
});
|
309
329
|
|
310
330
|
/**
|
@@ -315,13 +335,13 @@ describe("AssistantCloudFiles", () => {
|
|
315
335
|
success: false,
|
316
336
|
signedUrl: "",
|
317
337
|
expiresAt: "",
|
318
|
-
publicUrl: ""
|
338
|
+
publicUrl: "",
|
319
339
|
};
|
320
340
|
|
321
341
|
vi.mocked(mockApi.makeRequest).mockResolvedValue(mockResponse);
|
322
342
|
|
323
343
|
const requestBody = {
|
324
|
-
filename: "invalid-file-type.exe"
|
344
|
+
filename: "invalid-file-type.exe",
|
325
345
|
};
|
326
346
|
|
327
347
|
const result = await cloudFiles.generatePresignedUploadUrl(requestBody);
|
@@ -339,22 +359,25 @@ describe("AssistantCloudFiles", () => {
|
|
339
359
|
success: true,
|
340
360
|
signedUrl: "https://example.com/signed-url",
|
341
361
|
expiresAt: "2025-06-06T05:33:13.322Z",
|
342
|
-
publicUrl: "https://example.com/public-url"
|
362
|
+
publicUrl: "https://example.com/public-url",
|
343
363
|
};
|
344
364
|
|
345
365
|
vi.mocked(mockApi.makeRequest).mockResolvedValue(mockResponse);
|
346
366
|
|
347
367
|
const requestBody = {
|
348
|
-
filename: "document.pdf"
|
368
|
+
filename: "document.pdf",
|
349
369
|
};
|
350
370
|
|
351
371
|
await cloudFiles.generatePresignedUploadUrl(requestBody);
|
352
372
|
|
353
373
|
// Verify the endpoint and method are correct
|
354
|
-
expect(mockApi.makeRequest).toHaveBeenCalledWith(
|
355
|
-
|
356
|
-
|
357
|
-
|
374
|
+
expect(mockApi.makeRequest).toHaveBeenCalledWith(
|
375
|
+
"/files/attachments/generate-presigned-upload-url",
|
376
|
+
{
|
377
|
+
method: "POST",
|
378
|
+
body: requestBody,
|
379
|
+
},
|
380
|
+
);
|
358
381
|
|
359
382
|
// Verify it was called exactly once
|
360
383
|
expect(mockApi.makeRequest).toHaveBeenCalledTimes(1);
|
@@ -368,22 +391,25 @@ describe("AssistantCloudFiles", () => {
|
|
368
391
|
success: true,
|
369
392
|
signedUrl: "https://example.com/signed-url",
|
370
393
|
expiresAt: "2025-06-06T05:33:13.322Z",
|
371
|
-
publicUrl: "https://example.com/public-url"
|
394
|
+
publicUrl: "https://example.com/public-url",
|
372
395
|
};
|
373
396
|
|
374
397
|
vi.mocked(mockApi.makeRequest).mockResolvedValue(mockResponse);
|
375
398
|
|
376
399
|
// Test with filename containing spaces and special characters
|
377
400
|
const requestBody = {
|
378
|
-
filename: "my document (final version).pdf"
|
401
|
+
filename: "my document (final version).pdf",
|
379
402
|
};
|
380
403
|
|
381
404
|
const result = await cloudFiles.generatePresignedUploadUrl(requestBody);
|
382
405
|
|
383
|
-
expect(mockApi.makeRequest).toHaveBeenCalledWith(
|
384
|
-
|
385
|
-
|
386
|
-
|
406
|
+
expect(mockApi.makeRequest).toHaveBeenCalledWith(
|
407
|
+
"/files/attachments/generate-presigned-upload-url",
|
408
|
+
{
|
409
|
+
method: "POST",
|
410
|
+
body: requestBody,
|
411
|
+
},
|
412
|
+
);
|
387
413
|
|
388
414
|
expect(result).toEqual(mockResponse);
|
389
415
|
});
|
@@ -395,21 +421,28 @@ describe("AssistantCloudFiles", () => {
|
|
395
421
|
* Integration test that actually calls the real API endpoint
|
396
422
|
* This test requires real API credentials to be set in environment variables:
|
397
423
|
* - AUI_API_KEY: Your API key (e.g., sk_aui_proj_...)
|
398
|
-
* - AUI_USER_ID: Your user ID
|
424
|
+
* - AUI_USER_ID: Your user ID
|
399
425
|
* - AUI_WORKSPACE_ID: Your workspace ID
|
400
426
|
*/
|
401
|
-
it.skipIf(
|
402
|
-
|
427
|
+
it.skipIf(
|
428
|
+
!process.env.AUI_API_KEY ||
|
429
|
+
!process.env.AUI_USER_ID ||
|
430
|
+
!process.env.AUI_WORKSPACE_ID,
|
431
|
+
)(
|
432
|
+
"should actually convert PDF to images using real API",
|
433
|
+
async () => {
|
403
434
|
// Unmock all modules for this test to use real implementations
|
404
435
|
vi.doUnmock("../cloud/AssistantCloudAPI");
|
405
436
|
vi.doUnmock("../cloud/AssistantCloudFiles");
|
406
437
|
vi.doUnmock("../cloud/AssistantCloud");
|
407
|
-
|
438
|
+
|
408
439
|
// Clear all mocks and reload modules
|
409
440
|
vi.resetModules();
|
410
|
-
|
441
|
+
|
411
442
|
// Import real modules
|
412
|
-
const { AssistantCloud: RealAssistantCloud } = await import(
|
443
|
+
const { AssistantCloud: RealAssistantCloud } = await import(
|
444
|
+
"../cloud/AssistantCloud"
|
445
|
+
);
|
413
446
|
|
414
447
|
const realCloud = new RealAssistantCloud({
|
415
448
|
apiKey: process.env.AUI_API_KEY!,
|
@@ -418,13 +451,13 @@ describe("AssistantCloudFiles", () => {
|
|
418
451
|
});
|
419
452
|
|
420
453
|
const requestBody = {
|
421
|
-
file_url: "https://files.testfile.org/PDF/10MB-TESTFILE.ORG.pdf"
|
454
|
+
file_url: "https://files.testfile.org/PDF/10MB-TESTFILE.ORG.pdf",
|
422
455
|
};
|
423
456
|
|
424
457
|
console.log("Making API call to convert PDF...");
|
425
458
|
const result = await realCloud.files.pdfToImages(requestBody);
|
426
459
|
console.log("API call result:", result);
|
427
|
-
|
460
|
+
|
428
461
|
// Verify the response structure
|
429
462
|
expect(result).toHaveProperty("success");
|
430
463
|
expect(result).toHaveProperty("urls");
|
@@ -434,9 +467,9 @@ describe("AssistantCloudFiles", () => {
|
|
434
467
|
expect(Array.isArray(result.urls)).toBe(true);
|
435
468
|
expect(result.urls.length).toBeGreaterThan(0);
|
436
469
|
expect(typeof result.message).toBe("string");
|
437
|
-
|
470
|
+
|
438
471
|
// Verify URLs are valid image URLs
|
439
|
-
result.urls.forEach(url => {
|
472
|
+
result.urls.forEach((url) => {
|
440
473
|
expect(url).toMatch(/^https:\/\/.+\.(png|jpg|jpeg)(\?.*)?$/i);
|
441
474
|
});
|
442
475
|
} else {
|
@@ -444,32 +477,39 @@ describe("AssistantCloudFiles", () => {
|
|
444
477
|
expect(typeof result.message).toBe("string");
|
445
478
|
console.log("API call failed:", result.message);
|
446
479
|
}
|
447
|
-
|
480
|
+
|
448
481
|
// Restore mocks after the test
|
449
482
|
vi.doMock("../cloud/AssistantCloudAPI");
|
450
483
|
},
|
451
|
-
60000 // 60 second timeout for real API calls
|
484
|
+
60000, // 60 second timeout for real API calls
|
452
485
|
);
|
453
486
|
|
454
487
|
/**
|
455
488
|
* Integration test for generatePresignedUploadUrl that actually calls the real API endpoint
|
456
489
|
* This test requires real API credentials to be set in environment variables:
|
457
490
|
* - AUI_API_KEY: Your API key (e.g., sk_aui_proj_...)
|
458
|
-
* - AUI_USER_ID: Your user ID
|
491
|
+
* - AUI_USER_ID: Your user ID
|
459
492
|
* - AUI_WORKSPACE_ID: Your workspace ID
|
460
493
|
*/
|
461
|
-
it.skipIf(
|
462
|
-
|
494
|
+
it.skipIf(
|
495
|
+
!process.env.AUI_API_KEY ||
|
496
|
+
!process.env.AUI_USER_ID ||
|
497
|
+
!process.env.AUI_WORKSPACE_ID,
|
498
|
+
)(
|
499
|
+
"should actually generate presigned upload URL using real API",
|
500
|
+
async () => {
|
463
501
|
// Unmock all modules for this test to use real implementations
|
464
502
|
vi.doUnmock("../cloud/AssistantCloudAPI");
|
465
503
|
vi.doUnmock("../cloud/AssistantCloudFiles");
|
466
504
|
vi.doUnmock("../cloud/AssistantCloud");
|
467
|
-
|
505
|
+
|
468
506
|
// Clear all mocks and reload modules
|
469
507
|
vi.resetModules();
|
470
|
-
|
508
|
+
|
471
509
|
// Import real modules
|
472
|
-
const { AssistantCloud: RealAssistantCloud } = await import(
|
510
|
+
const { AssistantCloud: RealAssistantCloud } = await import(
|
511
|
+
"../cloud/AssistantCloud"
|
512
|
+
);
|
473
513
|
|
474
514
|
const realCloud = new RealAssistantCloud({
|
475
515
|
apiKey: process.env.AUI_API_KEY!,
|
@@ -478,13 +518,14 @@ describe("AssistantCloudFiles", () => {
|
|
478
518
|
});
|
479
519
|
|
480
520
|
const requestBody = {
|
481
|
-
filename: "test-upload.pdf"
|
521
|
+
filename: "test-upload.pdf",
|
482
522
|
};
|
483
523
|
|
484
524
|
console.log("Making API call to generate presigned upload URL...");
|
485
|
-
const result =
|
525
|
+
const result =
|
526
|
+
await realCloud.files.generatePresignedUploadUrl(requestBody);
|
486
527
|
console.log("API call result:", result);
|
487
|
-
|
528
|
+
|
488
529
|
// Verify the response structure
|
489
530
|
expect(result).toHaveProperty("success");
|
490
531
|
expect(result).toHaveProperty("signedUrl");
|
@@ -497,25 +538,27 @@ describe("AssistantCloudFiles", () => {
|
|
497
538
|
expect(typeof result.publicUrl).toBe("string");
|
498
539
|
expect(result.signedUrl.length).toBeGreaterThan(0);
|
499
540
|
expect(result.publicUrl.length).toBeGreaterThan(0);
|
500
|
-
|
541
|
+
|
501
542
|
// Verify URLs are valid HTTPS URLs
|
502
543
|
expect(result.signedUrl).toMatch(/^https:\/\/.+/);
|
503
544
|
expect(result.publicUrl).toMatch(/^https:\/\/.+/);
|
504
|
-
|
545
|
+
|
505
546
|
// Verify the signed URL contains expected AWS signature parameters
|
506
547
|
expect(result.signedUrl).toContain("X-Amz-Algorithm");
|
507
548
|
expect(result.signedUrl).toContain("X-Amz-Signature");
|
508
|
-
|
549
|
+
|
509
550
|
// Verify expiresAt is a valid ISO date string
|
510
551
|
expect(() => new Date(result.expiresAt)).not.toThrow();
|
511
552
|
} else {
|
512
|
-
console.log(
|
553
|
+
console.log(
|
554
|
+
"API call failed - this may be expected for some test cases",
|
555
|
+
);
|
513
556
|
}
|
514
|
-
|
557
|
+
|
515
558
|
// Restore mocks after the test
|
516
559
|
vi.doMock("../cloud/AssistantCloudAPI");
|
517
560
|
},
|
518
|
-
30000 // 30 second timeout for real API calls
|
561
|
+
30000, // 30 second timeout for real API calls
|
519
562
|
);
|
520
563
|
});
|
521
|
-
});
|
564
|
+
});
|