@langgraph-js/ui 1.1.0 → 1.2.0

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.
@@ -1,105 +1,105 @@
1
- /**
2
- * File Upload SDK - Base client for file upload services
3
- */
4
-
5
- // Base interfaces
6
- interface FileUploadClientOptions {
7
- apiUrl?: string;
8
- }
9
-
10
- interface FileUploadOptions {
11
- filename?: string;
12
- signal?: AbortSignal;
13
- }
14
-
15
- interface FileUploadResponse {
16
- status: string;
17
- data?: {
18
- url: string;
19
- delete_url?: string;
20
- expires_at?: string;
21
- size?: number;
22
- [key: string]: any;
23
- };
24
- [key: string]: any;
25
- }
26
-
27
- // Abstract base class for file upload clients
28
- abstract class FileUploadClient {
29
- protected apiUrl: string;
30
-
31
- constructor(options: FileUploadClientOptions = {}) {
32
- this.apiUrl = options.apiUrl || "";
33
- }
34
-
35
- protected abstract getUploadEndpoint(): string;
36
- protected abstract processResponse(response: FileUploadResponse): FileUploadResponse;
37
-
38
- protected createFormData(file: File | Blob | string, filename?: string): FormData {
39
- const formData = new FormData();
40
-
41
- if (typeof file === "string") {
42
- const blob = new Blob([file], { type: "text/plain" });
43
- formData.append("file", blob, filename || "file.txt");
44
- } else {
45
- formData.append("file", file, filename || (file instanceof File ? file.name : "file"));
46
- }
47
-
48
- return formData;
49
- }
50
-
51
- public async upload(file: File | Blob | string, options: FileUploadOptions = {}): Promise<FileUploadResponse> {
52
- const formData = this.createFormData(file, options.filename);
53
-
54
- const fetchOptions: RequestInit = {
55
- method: "POST",
56
- body: formData,
57
- };
58
-
59
- if (options.signal) {
60
- fetchOptions.signal = options.signal;
61
- }
62
-
63
- try {
64
- const response = await fetch(`${this.apiUrl}${this.getUploadEndpoint()}`, fetchOptions);
65
-
66
- if (!response.ok) {
67
- throw new Error(`Upload failed with status: ${response.status}`);
68
- }
69
-
70
- const result = (await response.json()) as FileUploadResponse;
71
- return this.processResponse(result);
72
- } catch (error) {
73
- throw new Error(`File upload failed: ${error instanceof Error ? error.message : String(error)}`);
74
- }
75
- }
76
- }
77
-
78
- /**
79
- * TmpFiles SDK - A client for uploading files to tmpfiles.org
80
- */
81
- export class TmpFilesClient extends FileUploadClient {
82
- constructor(options: FileUploadClientOptions = {}) {
83
- super({
84
- apiUrl: options.apiUrl || "https://tmpfiles.org/api/v1"
85
- });
86
- }
87
-
88
- protected getUploadEndpoint(): string {
89
- return "/upload";
90
- }
91
-
92
- protected processResponse(response: FileUploadResponse): FileUploadResponse {
93
- if (response.data?.url) {
94
- response.data.url = response.data.url.replace("https://tmpfiles.org/", "https://tmpfiles.org/dl/");
95
- }
96
- return response;
97
- }
98
- }
99
-
100
- // Export types for external use
101
- export type {
102
- FileUploadClientOptions,
103
- FileUploadOptions,
104
- FileUploadResponse
105
- };
1
+ /**
2
+ * File Upload SDK - Base client for file upload services
3
+ */
4
+
5
+ // Base interfaces
6
+ interface FileUploadClientOptions {
7
+ apiUrl?: string;
8
+ }
9
+
10
+ interface FileUploadOptions {
11
+ filename?: string;
12
+ signal?: AbortSignal;
13
+ }
14
+
15
+ interface FileUploadResponse {
16
+ status: string;
17
+ data?: {
18
+ url: string;
19
+ delete_url?: string;
20
+ expires_at?: string;
21
+ size?: number;
22
+ [key: string]: any;
23
+ };
24
+ [key: string]: any;
25
+ }
26
+
27
+ // Abstract base class for file upload clients
28
+ abstract class FileUploadClient {
29
+ protected apiUrl: string;
30
+
31
+ constructor(options: FileUploadClientOptions = {}) {
32
+ this.apiUrl = options.apiUrl || "";
33
+ }
34
+
35
+ protected abstract getUploadEndpoint(): string;
36
+ protected abstract processResponse(response: FileUploadResponse): FileUploadResponse;
37
+
38
+ protected createFormData(file: File | Blob | string, filename?: string): FormData {
39
+ const formData = new FormData();
40
+
41
+ if (typeof file === "string") {
42
+ const blob = new Blob([file], { type: "text/plain" });
43
+ formData.append("file", blob, filename || "file.txt");
44
+ } else {
45
+ formData.append("file", file, filename || (file instanceof File ? file.name : "file"));
46
+ }
47
+
48
+ return formData;
49
+ }
50
+
51
+ public async upload(file: File | Blob | string, options: FileUploadOptions = {}): Promise<FileUploadResponse> {
52
+ const formData = this.createFormData(file, options.filename);
53
+
54
+ const fetchOptions: RequestInit = {
55
+ method: "POST",
56
+ body: formData,
57
+ };
58
+
59
+ if (options.signal) {
60
+ fetchOptions.signal = options.signal;
61
+ }
62
+
63
+ try {
64
+ const response = await fetch(`${this.apiUrl}${this.getUploadEndpoint()}`, fetchOptions);
65
+
66
+ if (!response.ok) {
67
+ throw new Error(`Upload failed with status: ${response.status}`);
68
+ }
69
+
70
+ const result = (await response.json()) as FileUploadResponse;
71
+ return this.processResponse(result);
72
+ } catch (error) {
73
+ throw new Error(`File upload failed: ${error instanceof Error ? error.message : String(error)}`);
74
+ }
75
+ }
76
+ }
77
+
78
+ /**
79
+ * TmpFiles SDK - A client for uploading files to tmpfiles.org
80
+ */
81
+ export class TmpFilesClient extends FileUploadClient {
82
+ constructor(options: FileUploadClientOptions = {}) {
83
+ super({
84
+ apiUrl: options.apiUrl || "https://tmpfiles.org/api/v1"
85
+ });
86
+ }
87
+
88
+ protected getUploadEndpoint(): string {
89
+ return "/upload";
90
+ }
91
+
92
+ protected processResponse(response: FileUploadResponse): FileUploadResponse {
93
+ if (response.data?.url) {
94
+ response.data.url = response.data.url.replace("https://tmpfiles.org/", "https://tmpfiles.org/dl/");
95
+ }
96
+ return response;
97
+ }
98
+ }
99
+
100
+ // Export types for external use
101
+ export type {
102
+ FileUploadClientOptions,
103
+ FileUploadOptions,
104
+ FileUploadResponse
105
+ };