@agtlantis/core 0.5.0 → 0.5.1

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.
Files changed (265) hide show
  1. package/dist/errors/index.d.ts +4 -0
  2. package/dist/errors/index.d.ts.map +1 -0
  3. package/dist/errors/index.js +3 -0
  4. package/dist/errors/index.js.map +1 -0
  5. package/dist/errors/types.d.ts +69 -0
  6. package/dist/errors/types.d.ts.map +1 -0
  7. package/dist/errors/types.js +119 -0
  8. package/dist/errors/types.js.map +1 -0
  9. package/dist/errors/utils.d.ts +17 -0
  10. package/dist/errors/utils.d.ts.map +1 -0
  11. package/dist/errors/utils.js +16 -0
  12. package/dist/errors/utils.js.map +1 -0
  13. package/dist/execution/constants.d.ts +7 -0
  14. package/dist/execution/constants.d.ts.map +1 -0
  15. package/dist/execution/constants.js +7 -0
  16. package/dist/execution/constants.js.map +1 -0
  17. package/dist/execution/index.d.ts +8 -0
  18. package/dist/execution/index.d.ts.map +1 -0
  19. package/dist/execution/index.js +7 -0
  20. package/dist/execution/index.js.map +1 -0
  21. package/dist/execution/mapping.d.ts +17 -0
  22. package/dist/execution/mapping.d.ts.map +1 -0
  23. package/dist/execution/mapping.js +197 -0
  24. package/dist/execution/mapping.js.map +1 -0
  25. package/dist/execution/shared.d.ts +86 -0
  26. package/dist/execution/shared.d.ts.map +1 -0
  27. package/dist/execution/shared.js +100 -0
  28. package/dist/execution/shared.js.map +1 -0
  29. package/dist/execution/simple-host.d.ts +56 -0
  30. package/dist/execution/simple-host.d.ts.map +1 -0
  31. package/dist/execution/simple-host.js +126 -0
  32. package/dist/execution/simple-host.js.map +1 -0
  33. package/dist/execution/streaming-host.d.ts +79 -0
  34. package/dist/execution/streaming-host.d.ts.map +1 -0
  35. package/dist/execution/streaming-host.js +276 -0
  36. package/dist/execution/streaming-host.js.map +1 -0
  37. package/dist/execution/testing/fixtures.d.ts +67 -0
  38. package/dist/execution/testing/fixtures.d.ts.map +1 -0
  39. package/dist/execution/testing/fixtures.js +145 -0
  40. package/dist/execution/testing/fixtures.js.map +1 -0
  41. package/dist/execution/testing/helpers.d.ts +218 -0
  42. package/dist/execution/testing/helpers.d.ts.map +1 -0
  43. package/dist/execution/testing/helpers.js +327 -0
  44. package/dist/execution/testing/helpers.js.map +1 -0
  45. package/dist/execution/testing/host-configs.d.ts +56 -0
  46. package/dist/execution/testing/host-configs.d.ts.map +1 -0
  47. package/dist/execution/testing/host-configs.js +154 -0
  48. package/dist/execution/testing/host-configs.js.map +1 -0
  49. package/dist/execution/testing/vitest-assertions.d.ts +102 -0
  50. package/dist/execution/testing/vitest-assertions.d.ts.map +1 -0
  51. package/dist/execution/testing/vitest-assertions.js +142 -0
  52. package/dist/execution/testing/vitest-assertions.js.map +1 -0
  53. package/dist/execution/types.d.ts +432 -0
  54. package/dist/execution/types.d.ts.map +1 -0
  55. package/dist/execution/types.js +2 -0
  56. package/dist/execution/types.js.map +1 -0
  57. package/dist/execution/utils.d.ts +68 -0
  58. package/dist/execution/utils.d.ts.map +1 -0
  59. package/dist/execution/utils.js +93 -0
  60. package/dist/execution/utils.js.map +1 -0
  61. package/dist/index.d.ts +10 -1506
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +9 -2979
  64. package/dist/index.js.map +1 -1
  65. package/dist/observability/index.d.ts +4 -0
  66. package/dist/observability/index.d.ts.map +1 -0
  67. package/dist/observability/index.js +2 -0
  68. package/dist/observability/index.js.map +1 -0
  69. package/dist/observability/logger.d.ts +161 -0
  70. package/dist/observability/logger.d.ts.map +1 -0
  71. package/dist/observability/logger.js +31 -0
  72. package/dist/observability/logger.js.map +1 -0
  73. package/dist/observability/types.d.ts +46 -0
  74. package/dist/observability/types.d.ts.map +1 -0
  75. package/dist/observability/types.js +2 -0
  76. package/dist/observability/types.js.map +1 -0
  77. package/dist/patterns/index.d.ts +2 -0
  78. package/dist/patterns/index.d.ts.map +1 -0
  79. package/dist/patterns/index.js +2 -0
  80. package/dist/patterns/index.js.map +1 -0
  81. package/dist/patterns/progressive/index.d.ts +2 -0
  82. package/dist/patterns/progressive/index.d.ts.map +1 -0
  83. package/dist/patterns/progressive/index.js +2 -0
  84. package/dist/patterns/progressive/index.js.map +1 -0
  85. package/dist/patterns/progressive/progressive-pattern.d.ts +174 -0
  86. package/dist/patterns/progressive/progressive-pattern.d.ts.map +1 -0
  87. package/dist/patterns/progressive/progressive-pattern.js +260 -0
  88. package/dist/patterns/progressive/progressive-pattern.js.map +1 -0
  89. package/dist/pricing/calculator.d.ts +71 -0
  90. package/dist/pricing/calculator.d.ts.map +1 -0
  91. package/dist/pricing/calculator.js +127 -0
  92. package/dist/pricing/calculator.js.map +1 -0
  93. package/dist/pricing/config.d.ts +61 -0
  94. package/dist/pricing/config.d.ts.map +1 -0
  95. package/dist/pricing/config.js +87 -0
  96. package/dist/pricing/config.js.map +1 -0
  97. package/dist/pricing/defaults.d.ts +29 -0
  98. package/dist/pricing/defaults.d.ts.map +1 -0
  99. package/dist/pricing/defaults.js +139 -0
  100. package/dist/pricing/defaults.js.map +1 -0
  101. package/dist/pricing/index.d.ts +40 -0
  102. package/dist/pricing/index.d.ts.map +1 -0
  103. package/dist/pricing/index.js +43 -0
  104. package/dist/pricing/index.js.map +1 -0
  105. package/dist/pricing/types.d.ts +96 -0
  106. package/dist/pricing/types.d.ts.map +1 -0
  107. package/dist/pricing/types.js +7 -0
  108. package/dist/pricing/types.js.map +1 -0
  109. package/dist/pricing/validator.d.ts +55 -0
  110. package/dist/pricing/validator.d.ts.map +1 -0
  111. package/dist/pricing/validator.js +84 -0
  112. package/dist/pricing/validator.js.map +1 -0
  113. package/dist/prompt/errors.d.ts +112 -0
  114. package/dist/prompt/errors.d.ts.map +1 -0
  115. package/dist/prompt/errors.js +175 -0
  116. package/dist/prompt/errors.js.map +1 -0
  117. package/dist/prompt/file-prompt-repository.d.ts +80 -0
  118. package/dist/prompt/file-prompt-repository.d.ts.map +1 -0
  119. package/dist/prompt/file-prompt-repository.js +287 -0
  120. package/dist/prompt/file-prompt-repository.js.map +1 -0
  121. package/dist/prompt/index.d.ts +34 -0
  122. package/dist/prompt/index.d.ts.map +1 -0
  123. package/dist/prompt/index.js +37 -0
  124. package/dist/prompt/index.js.map +1 -0
  125. package/dist/prompt/prompt-template.d.ts +64 -0
  126. package/dist/prompt/prompt-template.d.ts.map +1 -0
  127. package/dist/prompt/prompt-template.js +90 -0
  128. package/dist/prompt/prompt-template.js.map +1 -0
  129. package/dist/prompt/template.d.ts +23 -0
  130. package/dist/prompt/template.d.ts.map +1 -0
  131. package/dist/prompt/template.js +70 -0
  132. package/dist/prompt/template.js.map +1 -0
  133. package/dist/prompt/types.d.ts +148 -0
  134. package/dist/prompt/types.d.ts.map +1 -0
  135. package/dist/prompt/types.js +7 -0
  136. package/dist/prompt/types.js.map +1 -0
  137. package/dist/provider/base-provider.d.ts +41 -0
  138. package/dist/provider/base-provider.d.ts.map +1 -0
  139. package/dist/provider/base-provider.js +21 -0
  140. package/dist/provider/base-provider.js.map +1 -0
  141. package/dist/provider/file-cache.d.ts +14 -0
  142. package/dist/provider/file-cache.d.ts.map +1 -0
  143. package/dist/provider/file-cache.js +29 -0
  144. package/dist/provider/file-cache.js.map +1 -0
  145. package/dist/provider/file-source.d.ts +32 -0
  146. package/dist/provider/file-source.d.ts.map +1 -0
  147. package/dist/provider/file-source.js +180 -0
  148. package/dist/provider/file-source.js.map +1 -0
  149. package/dist/provider/google/factory.d.ts +107 -0
  150. package/dist/provider/google/factory.d.ts.map +1 -0
  151. package/dist/provider/google/factory.js +143 -0
  152. package/dist/provider/google/factory.js.map +1 -0
  153. package/dist/provider/google/file-manager.d.ts +14 -0
  154. package/dist/provider/google/file-manager.d.ts.map +1 -0
  155. package/dist/provider/google/file-manager.js +183 -0
  156. package/dist/provider/google/file-manager.js.map +1 -0
  157. package/dist/provider/google/index.d.ts +8 -0
  158. package/dist/provider/google/index.d.ts.map +1 -0
  159. package/dist/provider/google/index.js +10 -0
  160. package/dist/provider/google/index.js.map +1 -0
  161. package/dist/provider/hash.d.ts +3 -0
  162. package/dist/provider/hash.d.ts.map +1 -0
  163. package/dist/provider/hash.js +34 -0
  164. package/dist/provider/hash.js.map +1 -0
  165. package/dist/provider/index.d.ts +9 -0
  166. package/dist/provider/index.d.ts.map +1 -0
  167. package/dist/provider/index.js +11 -0
  168. package/dist/provider/index.js.map +1 -0
  169. package/dist/provider/noop-file-manager.d.ts +9 -0
  170. package/dist/provider/noop-file-manager.d.ts.map +1 -0
  171. package/dist/provider/noop-file-manager.js +28 -0
  172. package/dist/provider/noop-file-manager.js.map +1 -0
  173. package/dist/provider/openai/factory.d.ts +67 -0
  174. package/dist/provider/openai/factory.d.ts.map +1 -0
  175. package/dist/provider/openai/factory.js +95 -0
  176. package/dist/provider/openai/factory.js.map +1 -0
  177. package/dist/provider/openai/index.d.ts +7 -0
  178. package/dist/provider/openai/index.d.ts.map +1 -0
  179. package/dist/provider/openai/index.js +7 -0
  180. package/dist/provider/openai/index.js.map +1 -0
  181. package/dist/provider/types.d.ts +105 -0
  182. package/dist/provider/types.d.ts.map +1 -0
  183. package/dist/provider/types.js +19 -0
  184. package/dist/provider/types.js.map +1 -0
  185. package/dist/session/index.d.ts +7 -0
  186. package/dist/session/index.d.ts.map +1 -0
  187. package/dist/session/index.js +5 -0
  188. package/dist/session/index.js.map +1 -0
  189. package/dist/session/simple-session.d.ts +98 -0
  190. package/dist/session/simple-session.d.ts.map +1 -0
  191. package/dist/session/simple-session.js +299 -0
  192. package/dist/session/simple-session.js.map +1 -0
  193. package/dist/session/streaming-session.d.ts +90 -0
  194. package/dist/session/streaming-session.d.ts.map +1 -0
  195. package/dist/session/streaming-session.js +151 -0
  196. package/dist/session/streaming-session.js.map +1 -0
  197. package/dist/session/test-utils.d.ts +19 -0
  198. package/dist/session/test-utils.d.ts.map +1 -0
  199. package/dist/session/test-utils.js +65 -0
  200. package/dist/session/test-utils.js.map +1 -0
  201. package/dist/session/types.d.ts +219 -0
  202. package/dist/session/types.d.ts.map +1 -0
  203. package/dist/session/types.js +181 -0
  204. package/dist/session/types.js.map +1 -0
  205. package/dist/session/usage-extractors.d.ts +7 -0
  206. package/dist/session/usage-extractors.d.ts.map +1 -0
  207. package/dist/session/usage-extractors.js +71 -0
  208. package/dist/session/usage-extractors.js.map +1 -0
  209. package/dist/testing/fixtures.d.ts +34 -0
  210. package/dist/testing/fixtures.d.ts.map +1 -0
  211. package/dist/testing/fixtures.js +65 -0
  212. package/dist/testing/fixtures.js.map +1 -0
  213. package/dist/testing/helpers.d.ts +20 -0
  214. package/dist/testing/helpers.d.ts.map +1 -0
  215. package/dist/testing/helpers.js +32 -0
  216. package/dist/testing/helpers.js.map +1 -0
  217. package/dist/testing/index.d.ts +7 -519
  218. package/dist/testing/index.d.ts.map +1 -0
  219. package/dist/testing/index.js +21 -2123
  220. package/dist/testing/index.js.map +1 -1
  221. package/dist/testing/mock-provider.d.ts +79 -0
  222. package/dist/testing/mock-provider.d.ts.map +1 -0
  223. package/dist/testing/mock-provider.js +152 -0
  224. package/dist/testing/mock-provider.js.map +1 -0
  225. package/dist/testing/mock.d.ts +29 -0
  226. package/dist/testing/mock.d.ts.map +1 -0
  227. package/dist/testing/mock.js +154 -0
  228. package/dist/testing/mock.js.map +1 -0
  229. package/dist/testing/test-execution.d.ts +14 -0
  230. package/dist/testing/test-execution.d.ts.map +1 -0
  231. package/dist/testing/test-execution.js +108 -0
  232. package/dist/testing/test-execution.js.map +1 -0
  233. package/dist/utils/deep-merge.d.ts +6 -0
  234. package/dist/utils/deep-merge.d.ts.map +1 -0
  235. package/dist/utils/deep-merge.js +24 -0
  236. package/dist/utils/deep-merge.js.map +1 -0
  237. package/dist/validation/errors.d.ts +28 -0
  238. package/dist/validation/errors.d.ts.map +1 -0
  239. package/dist/validation/errors.js +39 -0
  240. package/dist/validation/errors.js.map +1 -0
  241. package/dist/validation/index.d.ts +5 -0
  242. package/dist/validation/index.d.ts.map +1 -0
  243. package/dist/validation/index.js +4 -0
  244. package/dist/validation/index.js.map +1 -0
  245. package/dist/validation/types.d.ts +49 -0
  246. package/dist/validation/types.d.ts.map +1 -0
  247. package/dist/validation/types.js +2 -0
  248. package/dist/validation/types.js.map +1 -0
  249. package/dist/validation/validation-history.d.ts +12 -0
  250. package/dist/validation/validation-history.d.ts.map +1 -0
  251. package/dist/validation/validation-history.js +29 -0
  252. package/dist/validation/validation-history.js.map +1 -0
  253. package/dist/validation/with-validation.d.ts +38 -0
  254. package/dist/validation/with-validation.d.ts.map +1 -0
  255. package/dist/validation/with-validation.js +58 -0
  256. package/dist/validation/with-validation.js.map +1 -0
  257. package/package.json +72 -76
  258. package/dist/base-provider-2TTw5HAa.d.cts +0 -1254
  259. package/dist/base-provider-2TTw5HAa.d.ts +0 -1254
  260. package/dist/index.cjs +0 -3085
  261. package/dist/index.cjs.map +0 -1
  262. package/dist/index.d.cts +0 -1506
  263. package/dist/testing/index.cjs +0 -2167
  264. package/dist/testing/index.cjs.map +0 -1
  265. package/dist/testing/index.d.cts +0 -520
@@ -0,0 +1,180 @@
1
+ import { readFile, stat } from 'node:fs/promises';
2
+ import * as path from 'node:path';
3
+ import { FileError, FileErrorCode } from '../errors/index.js';
4
+ import { isFileSource, isFileSourcePath } from './types.js';
5
+ export const EXTENSION_TO_MIME = {
6
+ '.pdf': 'application/pdf',
7
+ '.html': 'text/html',
8
+ '.htm': 'text/html',
9
+ '.txt': 'text/plain',
10
+ '.json': 'application/json',
11
+ '.xml': 'application/xml',
12
+ '.csv': 'text/csv',
13
+ '.png': 'image/png',
14
+ '.jpg': 'image/jpeg',
15
+ '.jpeg': 'image/jpeg',
16
+ '.gif': 'image/gif',
17
+ '.webp': 'image/webp',
18
+ '.svg': 'image/svg+xml',
19
+ '.bmp': 'image/bmp',
20
+ '.zip': 'application/zip',
21
+ };
22
+ /** Infers MIME type from file extension (case-insensitive) */
23
+ export function inferMediaType(filePath) {
24
+ const ext = path.extname(filePath).toLowerCase();
25
+ return EXTENSION_TO_MIME[ext];
26
+ }
27
+ /** Recursively scans an input for FileSources and returns them with their JSON paths */
28
+ export function scanForFileSources(input, currentPath = []) {
29
+ if (isFileSource(input)) {
30
+ return [{ part: input, path: currentPath }];
31
+ }
32
+ if (input === null || typeof input !== 'object') {
33
+ return [];
34
+ }
35
+ if (Buffer.isBuffer(input) || input instanceof Uint8Array || input instanceof URL) {
36
+ return [];
37
+ }
38
+ const results = [];
39
+ if (Array.isArray(input)) {
40
+ for (let i = 0; i < input.length; i++) {
41
+ results.push(...scanForFileSources(input[i], [...currentPath, i]));
42
+ }
43
+ }
44
+ else {
45
+ for (const key of Object.keys(input)) {
46
+ results.push(...scanForFileSources(input[key], [
47
+ ...currentPath,
48
+ key,
49
+ ]));
50
+ }
51
+ }
52
+ return results;
53
+ }
54
+ export const DEFAULT_MAX_SIZE = 50 * 1024 * 1024;
55
+ /**
56
+ * Resolves a FileSource to AI SDK compatible format.
57
+ * Path-based parts are read into Buffer; others returned unchanged.
58
+ */
59
+ export async function resolveFileSource(part, options = {}) {
60
+ const { basePath = process.cwd(), maxSize = DEFAULT_MAX_SIZE } = options;
61
+ if (!isFileSourcePath(part)) {
62
+ // data, base64, url - return as-is
63
+ return part;
64
+ }
65
+ // path source - read file and convert to data
66
+ const fullPath = path.isAbsolute(part.path) ? part.path : path.resolve(basePath, part.path);
67
+ const stats = await stat(fullPath).catch((err) => {
68
+ throw new FileError(`File not found: ${part.path}`, {
69
+ code: FileErrorCode.NOT_FOUND,
70
+ context: { path: part.path, fullPath },
71
+ cause: err,
72
+ });
73
+ });
74
+ if (stats.size > maxSize) {
75
+ throw new FileError(`File too large: ${stats.size} bytes > ${maxSize} bytes`, {
76
+ code: FileErrorCode.TOO_LARGE,
77
+ context: { path: part.path, size: stats.size, maxSize },
78
+ });
79
+ }
80
+ const buffer = await readFile(fullPath);
81
+ const mediaType = part.mediaType ?? inferMediaType(part.path) ?? 'application/octet-stream';
82
+ const filename = part.filename ?? path.basename(part.path);
83
+ const result = {
84
+ source: 'data',
85
+ data: buffer,
86
+ mediaType,
87
+ filename,
88
+ };
89
+ return result;
90
+ }
91
+ function deepClone(value) {
92
+ if (value === null || typeof value !== 'object')
93
+ return value;
94
+ if (Buffer.isBuffer(value))
95
+ return Buffer.from(value);
96
+ if (value instanceof URL)
97
+ return new URL(value.href);
98
+ if (value instanceof Uint8Array)
99
+ return new Uint8Array(value);
100
+ if (Array.isArray(value))
101
+ return value.map(deepClone);
102
+ const result = {};
103
+ for (const key of Object.keys(value)) {
104
+ result[key] = deepClone(value[key]);
105
+ }
106
+ return result;
107
+ }
108
+ function setAtPath(obj, targetPath, value) {
109
+ if (targetPath.length === 0) {
110
+ return value;
111
+ }
112
+ let current = obj;
113
+ for (let i = 0; i < targetPath.length - 1; i++) {
114
+ current = current[targetPath[i]];
115
+ }
116
+ current[targetPath[targetPath.length - 1]] = value;
117
+ return obj;
118
+ }
119
+ /** Resolves all FileSources in an input (returns new object, original unchanged) */
120
+ export async function resolveFileSourcesInInput(input, options = {}) {
121
+ const found = scanForFileSources(input);
122
+ if (found.length === 0) {
123
+ return input;
124
+ }
125
+ // Resolve all parts in parallel
126
+ const resolved = await Promise.all(found.map(({ part }) => resolveFileSource(part, options)));
127
+ // Special case: if input itself is a FileSource (path = [])
128
+ if (found.length === 1 && found[0].path.length === 0) {
129
+ return resolved[0];
130
+ }
131
+ // Clone and replace in-place
132
+ const result = deepClone(input);
133
+ for (let i = 0; i < found.length; i++) {
134
+ setAtPath(result, found[i].path, resolved[i]);
135
+ }
136
+ return result;
137
+ }
138
+ /** Extracts display info from a FileSource for reporting (excludes raw data) */
139
+ export function getFileSourceDisplayInfo(part) {
140
+ switch (part.source) {
141
+ case 'path':
142
+ return {
143
+ source: 'path',
144
+ description: part.path,
145
+ mediaType: part.mediaType ?? inferMediaType(part.path) ?? 'unknown',
146
+ filename: part.filename ?? path.basename(part.path),
147
+ };
148
+ case 'url':
149
+ return {
150
+ source: 'url',
151
+ description: part.url,
152
+ mediaType: part.mediaType ?? 'unknown',
153
+ filename: part.filename,
154
+ };
155
+ case 'base64': {
156
+ const sizeKB = ((part.data.length * 3) / 4 / 1024).toFixed(1);
157
+ return {
158
+ source: 'base64',
159
+ description: `[base64 data, ~${sizeKB}KB]`,
160
+ mediaType: part.mediaType,
161
+ filename: part.filename,
162
+ };
163
+ }
164
+ case 'data': {
165
+ const size = Buffer.isBuffer(part.data) ? part.data.length : part.data.length;
166
+ const sizeKB = (size / 1024).toFixed(1);
167
+ return {
168
+ source: 'data',
169
+ description: `[Buffer, ${sizeKB}KB]`,
170
+ mediaType: part.mediaType,
171
+ filename: part.filename,
172
+ };
173
+ }
174
+ }
175
+ }
176
+ export function getFileSourcesDisplayInfo(input) {
177
+ const found = scanForFileSources(input);
178
+ return found.map(({ part }) => getFileSourceDisplayInfo(part));
179
+ }
180
+ //# sourceMappingURL=file-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-source.js","sourceRoot":"","sources":["../../src/provider/file-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAA8B,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAExF,MAAM,CAAC,MAAM,iBAAiB,GAA2B;IACrD,MAAM,EAAE,iBAAiB;IACzB,OAAO,EAAE,WAAW;IACpB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,kBAAkB;IAC3B,MAAM,EAAE,iBAAiB;IACzB,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,WAAW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C,QAAQ;aAC1B,CAAC;QACN,CAAC;QAED,KAAK,MAAM,EAAE,CAAC;YACV,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;YAC9E,MAAM,MAAM,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACxC,OAAO;gBACH,MAAM,EAAE,MAAM;gBACd,WAAW,EAAE,YAAY,MAAM,KAAK;gBACpC,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;aAC1B,CAAC;QACN,CAAC;IACL,CAAC;AAAA,CACJ;AAED,MAAM,UAAU,yBAAyB,CAAC,KAAc,EAA2B;IAC/E,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACxC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC;AAAA,CAClE"}
@@ -0,0 +1,107 @@
1
+ import { type GoogleGenerativeAIProviderOptions } from '@ai-sdk/google';
2
+ import type { Logger } from '../../observability/logger.js';
3
+ import type { ProviderPricing } from '../../pricing/index.js';
4
+ import type { GenerationOptions } from '../../session/index.js';
5
+ import { SimpleSession } from '../../session/simple-session.js';
6
+ import { StreamingSession } from '../../session/streaming-session.js';
7
+ import { BaseProvider } from '../base-provider.js';
8
+ import type { FileCache } from '../types.js';
9
+ export type HarmCategory = 'HARM_CATEGORY_HATE_SPEECH' | 'HARM_CATEGORY_SEXUALLY_EXPLICIT' | 'HARM_CATEGORY_DANGEROUS_CONTENT' | 'HARM_CATEGORY_HARASSMENT' | 'HARM_CATEGORY_CIVIC_INTEGRITY';
10
+ export type HarmBlockThreshold = 'BLOCK_NONE' | 'BLOCK_ONLY_HIGH' | 'BLOCK_MEDIUM_AND_ABOVE' | 'BLOCK_LOW_AND_ABOVE' | 'OFF';
11
+ export interface SafetySetting {
12
+ category: HarmCategory;
13
+ threshold: HarmBlockThreshold;
14
+ }
15
+ export interface GoogleProviderConfig {
16
+ apiKey: string;
17
+ safetySettings?: SafetySetting[];
18
+ }
19
+ interface GoogleProviderState {
20
+ apiKey: string;
21
+ defaultModelId: string | null;
22
+ logger: Logger;
23
+ safetySettings?: SafetySetting[];
24
+ pricingConfig?: ProviderPricing;
25
+ defaultOptions?: GoogleGenerativeAIProviderOptions;
26
+ searchEnabled: boolean;
27
+ urlContextEnabled: boolean;
28
+ fileCache?: FileCache;
29
+ defaultGenOptions?: GenerationOptions;
30
+ }
31
+ export declare class GoogleProvider extends BaseProvider {
32
+ private readonly config;
33
+ private readonly google;
34
+ constructor(config: GoogleProviderState);
35
+ withDefaultModel(modelId: string): GoogleProvider;
36
+ withLogger(newLogger: Logger): GoogleProvider;
37
+ withPricing(pricing: ProviderPricing): GoogleProvider;
38
+ /**
39
+ * Set default provider-specific options for all LLM calls.
40
+ * These options will be deep-merged with per-call providerOptions.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * createGoogleProvider({ apiKey: 'xxx' })
45
+ * .withDefaultModel('gemini-2.0-flash-thinking-exp')
46
+ * .withDefaultOptions({
47
+ * thinkingConfig: { includeThoughts: true, thinkingLevel: 'low' }
48
+ * })
49
+ * ```
50
+ */
51
+ withDefaultOptions(options: GoogleGenerativeAIProviderOptions): GoogleProvider;
52
+ withDefaultGenerationOptions(options: GenerationOptions): GoogleProvider;
53
+ /**
54
+ * Enable Google Search grounding for all LLM calls.
55
+ * Allows the model to access real-time web information.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * createGoogleProvider({ apiKey: 'xxx' })
60
+ * .withDefaultModel('gemini-2.5-flash')
61
+ * .withSearchEnabled()
62
+ * ```
63
+ */
64
+ withSearchEnabled(): GoogleProvider;
65
+ /**
66
+ * Enable URL Context grounding for all LLM calls.
67
+ * Allows the model to retrieve and use content from URLs in the prompt.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * createGoogleProvider({ apiKey: 'xxx' })
72
+ * .withDefaultModel('gemini-2.5-flash')
73
+ * .withUrlContextEnabled()
74
+ * ```
75
+ */
76
+ withUrlContextEnabled(): GoogleProvider;
77
+ /**
78
+ * Set a file cache for reusing uploaded files across sessions.
79
+ * If no cache is provided, creates a new InMemoryFileCache.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // Use default InMemoryFileCache
84
+ * createGoogleProvider({ apiKey: 'xxx' })
85
+ * .withFileCache()
86
+ *
87
+ * // Use custom cache with TTL
88
+ * const cache = new InMemoryFileCache({ defaultTTL: 3600000 });
89
+ * createGoogleProvider({ apiKey: 'xxx' })
90
+ * .withFileCache(cache)
91
+ * ```
92
+ */
93
+ withFileCache(cache?: FileCache): GoogleProvider;
94
+ private getSessionConfig;
95
+ protected createStreamingSession<TEvent extends {
96
+ type: string;
97
+ }>(signal?: AbortSignal): StreamingSession<TEvent>;
98
+ protected createSimpleSession(signal?: AbortSignal): SimpleSession;
99
+ /**
100
+ * Type assertion needed because @ai-sdk/google's type signature doesn't
101
+ * include the second parameter, but it's supported at runtime.
102
+ */
103
+ private createModel;
104
+ }
105
+ export declare function createGoogleProvider(config: GoogleProviderConfig): GoogleProvider;
106
+ export type { GoogleGenerativeAIProviderOptions } from '@ai-sdk/google';
107
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/provider/google/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAE5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,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,GAAG,cAAc,CAEhD;IAED,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,CAE5C;IAED,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc,CAGpD;IAED;;;;;;;;;;;;OAYG;IACH,kBAAkB,CAAC,OAAO,EAAE,iCAAiC,GAAG,cAAc,CAE7E;IAED,4BAA4B,CAAC,OAAO,EAAE,iBAAiB,GAAG,cAAc,CAEvE;IAED;;;;;;;;;;OAUG;IACH,iBAAiB,IAAI,cAAc,CAElC;IAED;;;;;;;;;;OAUG;IACH,qBAAqB,IAAI,cAAc,CAEtC;IAED;;;;;;;;;;;;;;;OAeG;IACH,aAAa,CAAC,KAAK,CAAC,EAAE,SAAS,GAAG,cAAc,CAE/C;IAED,OAAO,CAAC,gBAAgB;IA0BxB,SAAS,CAAC,sBAAsB,CAC5B,MAAM,SAAS;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EACjC,MAAM,CAAC,EAAE,WAAW,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAEhD;IAED,SAAS,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,aAAa,CAEjE;IAED;;;OAGG;IACH,OAAO,CAAC,WAAW;CAWtB;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,cAAc,CASjF;AAGD,YAAY,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,143 @@
1
+ import { createGoogleGenerativeAI } from '@ai-sdk/google';
2
+ import { noopLogger } from '../../observability/logger.js';
3
+ import { validateProviderPricing } from '../../pricing/index.js';
4
+ import { GoogleFileManager } from './file-manager.js';
5
+ import { SimpleSession } from '../../session/simple-session.js';
6
+ import { StreamingSession } from '../../session/streaming-session.js';
7
+ import { BaseProvider } from '../base-provider.js';
8
+ import { InMemoryFileCache } from '../file-cache.js';
9
+ export class GoogleProvider extends BaseProvider {
10
+ config;
11
+ google;
12
+ constructor(config) {
13
+ super();
14
+ this.config = config;
15
+ this.google = createGoogleGenerativeAI({ apiKey: config.apiKey });
16
+ }
17
+ withDefaultModel(modelId) {
18
+ return new GoogleProvider({ ...this.config, defaultModelId: modelId });
19
+ }
20
+ withLogger(newLogger) {
21
+ return new GoogleProvider({ ...this.config, logger: newLogger });
22
+ }
23
+ withPricing(pricing) {
24
+ validateProviderPricing(pricing, 'google');
25
+ return new GoogleProvider({ ...this.config, pricingConfig: pricing });
26
+ }
27
+ /**
28
+ * Set default provider-specific options for all LLM calls.
29
+ * These options will be deep-merged with per-call providerOptions.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * createGoogleProvider({ apiKey: 'xxx' })
34
+ * .withDefaultModel('gemini-2.0-flash-thinking-exp')
35
+ * .withDefaultOptions({
36
+ * thinkingConfig: { includeThoughts: true, thinkingLevel: 'low' }
37
+ * })
38
+ * ```
39
+ */
40
+ withDefaultOptions(options) {
41
+ return new GoogleProvider({ ...this.config, defaultOptions: options });
42
+ }
43
+ withDefaultGenerationOptions(options) {
44
+ return new GoogleProvider({ ...this.config, defaultGenOptions: options });
45
+ }
46
+ /**
47
+ * Enable Google Search grounding for all LLM calls.
48
+ * Allows the model to access real-time web information.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * createGoogleProvider({ apiKey: 'xxx' })
53
+ * .withDefaultModel('gemini-2.5-flash')
54
+ * .withSearchEnabled()
55
+ * ```
56
+ */
57
+ withSearchEnabled() {
58
+ return new GoogleProvider({ ...this.config, searchEnabled: true });
59
+ }
60
+ /**
61
+ * Enable URL Context grounding for all LLM calls.
62
+ * Allows the model to retrieve and use content from URLs in the prompt.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * createGoogleProvider({ apiKey: 'xxx' })
67
+ * .withDefaultModel('gemini-2.5-flash')
68
+ * .withUrlContextEnabled()
69
+ * ```
70
+ */
71
+ withUrlContextEnabled() {
72
+ return new GoogleProvider({ ...this.config, urlContextEnabled: true });
73
+ }
74
+ /**
75
+ * Set a file cache for reusing uploaded files across sessions.
76
+ * If no cache is provided, creates a new InMemoryFileCache.
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * // Use default InMemoryFileCache
81
+ * createGoogleProvider({ apiKey: 'xxx' })
82
+ * .withFileCache()
83
+ *
84
+ * // Use custom cache with TTL
85
+ * const cache = new InMemoryFileCache({ defaultTTL: 3600000 });
86
+ * createGoogleProvider({ apiKey: 'xxx' })
87
+ * .withFileCache(cache)
88
+ * ```
89
+ */
90
+ withFileCache(cache) {
91
+ return new GoogleProvider({ ...this.config, fileCache: cache ?? new InMemoryFileCache() });
92
+ }
93
+ getSessionConfig() {
94
+ const { searchEnabled, urlContextEnabled } = this.config;
95
+ const defaultTools = {
96
+ ...(searchEnabled && { google_search: this.google.tools.googleSearch({}) }),
97
+ ...(urlContextEnabled && { url_context: this.google.tools.urlContext({}) }),
98
+ };
99
+ const hasDefaultTools = searchEnabled || urlContextEnabled;
100
+ return {
101
+ defaultLanguageModel: this.config.defaultModelId
102
+ ? this.createModel(this.config.defaultModelId)
103
+ : null,
104
+ modelFactory: (modelId) => this.createModel(modelId),
105
+ providerType: 'google',
106
+ providerPricing: this.config.pricingConfig,
107
+ fileManager: new GoogleFileManager(this.config.apiKey, { cache: this.config.fileCache }),
108
+ logger: this.config.logger,
109
+ defaultProviderOptions: this.config.defaultOptions
110
+ ? { google: this.config.defaultOptions }
111
+ : undefined,
112
+ defaultTools: hasDefaultTools ? defaultTools : undefined,
113
+ defaultGenerationOptions: this.config.defaultGenOptions,
114
+ };
115
+ }
116
+ createStreamingSession(signal) {
117
+ return new StreamingSession({ ...this.getSessionConfig(), signal });
118
+ }
119
+ createSimpleSession(signal) {
120
+ return new SimpleSession({ ...this.getSessionConfig(), signal });
121
+ }
122
+ /**
123
+ * Type assertion needed because @ai-sdk/google's type signature doesn't
124
+ * include the second parameter, but it's supported at runtime.
125
+ */
126
+ createModel(modelId) {
127
+ if (this.config.safetySettings) {
128
+ return this.google(modelId, { safetySettings: this.config.safetySettings });
129
+ }
130
+ return this.google(modelId);
131
+ }
132
+ }
133
+ export function createGoogleProvider(config) {
134
+ return new GoogleProvider({
135
+ apiKey: config.apiKey,
136
+ defaultModelId: null,
137
+ logger: noopLogger,
138
+ safetySettings: config.safetySettings,
139
+ searchEnabled: false,
140
+ urlContextEnabled: false,
141
+ });
142
+ }
143
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/provider/google/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAA0C,MAAM,gBAAgB,CAAC;AAElG,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAuCrD,MAAM,OAAO,cAAe,SAAQ,YAAY;IAGf,MAAM;IAFlB,MAAM,CAA8C;IAErE,YAA6B,MAA2B,EAAE;QACtD,KAAK,EAAE,CAAC;sBADiB,MAAM;QAE/B,IAAI,CAAC,MAAM,GAAG,wBAAwB,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAAA,CACrE;IAED,gBAAgB,CAAC,OAAe,EAAkB;QAC9C,OAAO,IAAI,cAAc,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC;IAAA,CAC1E;IAED,UAAU,CAAC,SAAiB,EAAkB;QAC1C,OAAO,IAAI,cAAc,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,E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C,CAAC;IAAA,CAC/E;IAES,mBAAmB,CAAC,MAAoB,EAAiB;QAC/D,OAAO,IAAI,aAAa,CAAC,EAAE,GAAG,IAAI,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAAA,CACpE;IAED;;;OAGG;IACK,WAAW,CAAC,OAAe,EAAiB;QAChD,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YAC7B,OACI,IAAI,CAAC,MAIR,CAAC,OAAO,EAAE,EAAE,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAAA,CAC/B;CACJ;AAED,MAAM,UAAU,oBAAoB,CAAC,MAA4B,EAAkB;IAC/E,OAAO,IAAI,cAAc,CAAC;QACtB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,cAAc,EAAE,IAAI;QACpB,MAAM,EAAE,UAAU;QAClB,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,aAAa,EAAE,KAAK;QACpB,iBAAiB,EAAE,KAAK;KAC3B,CAAC,CAAC;AAAA,CACN"}
@@ -0,0 +1,14 @@
1
+ import type { FileManager, FileManagerOptions, FileSource, UploadedFile } from '../types.js';
2
+ /** Google GenAI File API implementation with automatic session cleanup */
3
+ export declare class GoogleFileManager implements FileManager {
4
+ private uploadedFiles;
5
+ private client;
6
+ private cache;
7
+ constructor(apiKey: string, options?: FileManagerOptions);
8
+ private uploadOne;
9
+ upload(files: FileSource[]): Promise<UploadedFile[]>;
10
+ delete(fileId: string): Promise<void>;
11
+ clear(): Promise<void>;
12
+ getUploadedFiles(): UploadedFile[];
13
+ }
14
+ //# sourceMappingURL=file-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-manager.d.ts","sourceRoot":"","sources":["../../../src/provider/google/file-manager.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAa,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAqCxG,0EAA0E;AAC1E,qBAAa,iBAAkB,YAAW,WAAW;IACjD,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,KAAK,CAAmB;IAEhC,YAAY,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,EAGvD;YAEa,SAAS;IAkGjB,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAgDzD;IAEK,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAS1C;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAO3B;IAED,gBAAgB,IAAI,YAAY,EAAE,CAEjC;CACJ"}
@@ -0,0 +1,183 @@
1
+ import path from 'node:path';
2
+ import { GoogleGenAI } from '@google/genai';
3
+ import { FileError, FileErrorCode } from '../../errors/index.js';
4
+ import { computeFileSourceHash } from '../hash.js';
5
+ function assertValidUploadResponse(response, context) {
6
+ if (!response.name || !response.uri || !response.mimeType) {
7
+ throw new FileError('Invalid upload response from Google API: missing required fields', {
8
+ code: FileErrorCode.UPLOAD_ERROR,
9
+ context: {
10
+ ...context,
11
+ hasName: !!response.name,
12
+ hasUri: !!response.uri,
13
+ hasMediaType: !!response.mimeType,
14
+ },
15
+ });
16
+ }
17
+ }
18
+ function isImageMediaType(mediaType) {
19
+ return mediaType.startsWith('image/');
20
+ }
21
+ function createPart(uri, mediaType) {
22
+ const url = new URL(uri);
23
+ if (isImageMediaType(mediaType)) {
24
+ return { type: 'image', image: url, mediaType: mediaType };
25
+ }
26
+ return { type: 'file', data: url, mediaType: mediaType };
27
+ }
28
+ /** Google GenAI File API implementation with automatic session cleanup */
29
+ export class GoogleFileManager {
30
+ uploadedFiles = [];
31
+ client;
32
+ cache;
33
+ constructor(apiKey, options) {
34
+ this.client = new GoogleGenAI({ apiKey });
35
+ this.cache = options?.cache ?? null;
36
+ }
37
+ async uploadOne(fileSource, index, hash) {
38
+ if (this.cache) {
39
+ const cached = this.cache.get(hash);
40
+ if (cached)
41
+ return cached;
42
+ }
43
+ if (fileSource.source === 'url') {
44
+ const mediaType = fileSource.mediaType ?? 'application/octet-stream';
45
+ const result = {
46
+ id: null,
47
+ part: createPart(fileSource.url, mediaType),
48
+ };
49
+ if (this.cache) {
50
+ this.cache.set(hash, result);
51
+ }
52
+ return result;
53
+ }
54
+ if (fileSource.source === 'path') {
55
+ const fullPath = path.isAbsolute(fileSource.path)
56
+ ? fileSource.path
57
+ : path.resolve(process.cwd(), fileSource.path);
58
+ try {
59
+ const uploaded = await this.client.files.upload({
60
+ file: fullPath,
61
+ config: {
62
+ mimeType: fileSource.mediaType,
63
+ displayName: fileSource.filename ?? path.basename(fileSource.path),
64
+ },
65
+ });
66
+ assertValidUploadResponse(uploaded, {
67
+ source: 'path',
68
+ path: fileSource.path,
69
+ });
70
+ const result = {
71
+ id: uploaded.name,
72
+ part: createPart(uploaded.uri, uploaded.mimeType),
73
+ };
74
+ if (this.cache) {
75
+ this.cache.set(hash, result);
76
+ }
77
+ return result;
78
+ }
79
+ catch (error) {
80
+ if (error instanceof FileError)
81
+ throw error;
82
+ throw FileError.from(error, FileErrorCode.UPLOAD_ERROR, {
83
+ source: 'path',
84
+ path: fileSource.path,
85
+ mediaType: fileSource.mediaType,
86
+ });
87
+ }
88
+ }
89
+ const buffer = fileSource.source === 'base64'
90
+ ? Buffer.from(fileSource.data, 'base64')
91
+ : fileSource.data;
92
+ const arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
93
+ const blob = new Blob([arrayBuffer], { type: fileSource.mediaType });
94
+ try {
95
+ const uploaded = await this.client.files.upload({
96
+ file: blob,
97
+ config: {
98
+ mimeType: fileSource.mediaType,
99
+ displayName: fileSource.filename ?? `upload-${Date.now()}-${index}`,
100
+ },
101
+ });
102
+ assertValidUploadResponse(uploaded, {
103
+ source: fileSource.source,
104
+ mediaType: fileSource.mediaType,
105
+ });
106
+ const result = {
107
+ id: uploaded.name,
108
+ part: createPart(uploaded.uri, uploaded.mimeType),
109
+ };
110
+ if (this.cache) {
111
+ this.cache.set(hash, result);
112
+ }
113
+ return result;
114
+ }
115
+ catch (error) {
116
+ if (error instanceof FileError)
117
+ throw error;
118
+ throw FileError.from(error, FileErrorCode.UPLOAD_ERROR, {
119
+ source: fileSource.source,
120
+ mediaType: fileSource.mediaType,
121
+ filename: fileSource.filename,
122
+ });
123
+ }
124
+ }
125
+ async upload(files) {
126
+ const hashes = await Promise.all(files.map((file) => computeFileSourceHash(file)));
127
+ const results = await Promise.allSettled(files.map((file, i) => this.uploadOne(file, i, hashes[i])));
128
+ const successful = [];
129
+ const failed = [];
130
+ for (let i = 0; i < results.length; i++) {
131
+ const result = results[i];
132
+ if (result.status === 'fulfilled') {
133
+ successful.push({ file: result.value, hash: hashes[i] });
134
+ }
135
+ else {
136
+ failed.push(result);
137
+ }
138
+ }
139
+ if (failed.length > 0) {
140
+ await Promise.all(successful
141
+ .filter(({ file }) => file.id !== null)
142
+ .map(async ({ file, hash }) => {
143
+ await this.client.files.delete({ name: file.id }).catch(() => { });
144
+ if (this.cache) {
145
+ this.cache.delete(hash);
146
+ }
147
+ }));
148
+ const firstError = failed[0].reason;
149
+ throw new FileError(`Failed to upload ${failed.length} file(s): ${firstError instanceof Error ? firstError.message : String(firstError)}`, {
150
+ code: FileErrorCode.UPLOAD_ERROR,
151
+ cause: firstError instanceof Error ? firstError : undefined,
152
+ context: {
153
+ totalFiles: files.length,
154
+ failedCount: failed.length,
155
+ successCount: successful.length,
156
+ },
157
+ });
158
+ }
159
+ this.uploadedFiles.push(...successful.filter(({ file }) => file.id !== null).map(({ file }) => file));
160
+ return successful.map(({ file }) => file);
161
+ }
162
+ async delete(fileId) {
163
+ try {
164
+ await this.client.files.delete({ name: fileId });
165
+ this.uploadedFiles = this.uploadedFiles.filter((f) => f.id !== fileId);
166
+ }
167
+ catch (error) {
168
+ throw FileError.from(error, FileErrorCode.DELETE_ERROR, {
169
+ fileId,
170
+ });
171
+ }
172
+ }
173
+ async clear() {
174
+ await Promise.all(this.uploadedFiles
175
+ .filter((f) => f.id !== null)
176
+ .map((f) => this.delete(f.id).catch(() => { })));
177
+ this.uploadedFiles = [];
178
+ }
179
+ getUploadedFiles() {
180
+ return [...this.uploadedFiles];
181
+ }
182
+ }
183
+ //# sourceMappingURL=file-manager.js.map