@ai-sdk/prodia 0.0.3 → 0.0.5

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/index.mjs CHANGED
@@ -11,14 +11,162 @@ import {
11
11
  // src/prodia-image-model.ts
12
12
  import {
13
13
  combineHeaders,
14
- createJsonErrorResponseHandler,
15
14
  lazySchema,
15
+ parseJSON,
16
16
  parseProviderOptions,
17
17
  postToApi,
18
18
  resolve,
19
19
  zodSchema
20
20
  } from "@ai-sdk/provider-utils";
21
+ import { z as z2 } from "zod/v4";
22
+
23
+ // src/prodia-api.ts
24
+ import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
21
25
  import { z } from "zod/v4";
26
+ var prodiaJobResultSchema = z.object({
27
+ id: z.string(),
28
+ created_at: z.string().optional(),
29
+ updated_at: z.string().optional(),
30
+ expires_at: z.string().optional(),
31
+ state: z.object({
32
+ current: z.string()
33
+ }).optional(),
34
+ config: z.object({
35
+ seed: z.number().optional()
36
+ }).passthrough().optional(),
37
+ metrics: z.object({
38
+ elapsed: z.number().optional(),
39
+ ips: z.number().optional()
40
+ }).optional(),
41
+ price: z.object({
42
+ product: z.string(),
43
+ dollars: z.number()
44
+ }).nullish()
45
+ });
46
+ function buildProdiaProviderMetadata(jobResult) {
47
+ var _a, _b, _c, _d;
48
+ return {
49
+ jobId: jobResult.id,
50
+ ...((_a = jobResult.config) == null ? void 0 : _a.seed) != null && {
51
+ seed: jobResult.config.seed
52
+ },
53
+ ...((_b = jobResult.metrics) == null ? void 0 : _b.elapsed) != null && {
54
+ elapsed: jobResult.metrics.elapsed
55
+ },
56
+ ...((_c = jobResult.metrics) == null ? void 0 : _c.ips) != null && {
57
+ iterationsPerSecond: jobResult.metrics.ips
58
+ },
59
+ ...jobResult.created_at != null && {
60
+ createdAt: jobResult.created_at
61
+ },
62
+ ...jobResult.updated_at != null && {
63
+ updatedAt: jobResult.updated_at
64
+ },
65
+ ...((_d = jobResult.price) == null ? void 0 : _d.dollars) != null && {
66
+ dollars: jobResult.price.dollars
67
+ }
68
+ };
69
+ }
70
+ function parseMultipart(data, boundary) {
71
+ const parts = [];
72
+ const boundaryBytes = new TextEncoder().encode(`--${boundary}`);
73
+ const endBoundaryBytes = new TextEncoder().encode(`--${boundary}--`);
74
+ const positions = [];
75
+ for (let i = 0; i <= data.length - boundaryBytes.length; i++) {
76
+ let match = true;
77
+ for (let j = 0; j < boundaryBytes.length; j++) {
78
+ if (data[i + j] !== boundaryBytes[j]) {
79
+ match = false;
80
+ break;
81
+ }
82
+ }
83
+ if (match) {
84
+ positions.push(i);
85
+ }
86
+ }
87
+ for (let i = 0; i < positions.length - 1; i++) {
88
+ const start = positions[i] + boundaryBytes.length;
89
+ const end = positions[i + 1];
90
+ let isEndBoundary = true;
91
+ for (let j = 0; j < endBoundaryBytes.length && isEndBoundary; j++) {
92
+ if (data[positions[i] + j] !== endBoundaryBytes[j]) {
93
+ isEndBoundary = false;
94
+ }
95
+ }
96
+ if (isEndBoundary && positions[i] + endBoundaryBytes.length <= data.length) {
97
+ continue;
98
+ }
99
+ let partStart = start;
100
+ if (data[partStart] === 13 && data[partStart + 1] === 10) {
101
+ partStart += 2;
102
+ } else if (data[partStart] === 10) {
103
+ partStart += 1;
104
+ }
105
+ let partEnd = end;
106
+ if (data[partEnd - 2] === 13 && data[partEnd - 1] === 10) {
107
+ partEnd -= 2;
108
+ } else if (data[partEnd - 1] === 10) {
109
+ partEnd -= 1;
110
+ }
111
+ const partData = data.slice(partStart, partEnd);
112
+ let headerEnd = -1;
113
+ for (let j = 0; j < partData.length - 3; j++) {
114
+ if (partData[j] === 13 && partData[j + 1] === 10 && partData[j + 2] === 13 && partData[j + 3] === 10) {
115
+ headerEnd = j;
116
+ break;
117
+ }
118
+ if (partData[j] === 10 && partData[j + 1] === 10) {
119
+ headerEnd = j;
120
+ break;
121
+ }
122
+ }
123
+ if (headerEnd === -1) {
124
+ continue;
125
+ }
126
+ const headerBytes = partData.slice(0, headerEnd);
127
+ const headerStr = new TextDecoder().decode(headerBytes);
128
+ const headers = {};
129
+ for (const line of headerStr.split(/\r?\n/)) {
130
+ const colonIdx = line.indexOf(":");
131
+ if (colonIdx > 0) {
132
+ const key = line.slice(0, colonIdx).trim().toLowerCase();
133
+ const value = line.slice(colonIdx + 1).trim();
134
+ headers[key] = value;
135
+ }
136
+ }
137
+ let bodyStart = headerEnd + 2;
138
+ if (partData[headerEnd] === 13) {
139
+ bodyStart = headerEnd + 4;
140
+ }
141
+ const body = partData.slice(bodyStart);
142
+ parts.push({ headers, body });
143
+ }
144
+ return parts;
145
+ }
146
+ var prodiaErrorSchema = z.object({
147
+ message: z.string().optional(),
148
+ detail: z.unknown().optional(),
149
+ error: z.string().optional()
150
+ });
151
+ var prodiaFailedResponseHandler = createJsonErrorResponseHandler({
152
+ errorSchema: prodiaErrorSchema,
153
+ errorToMessage: (error) => {
154
+ var _a;
155
+ const parsed = prodiaErrorSchema.safeParse(error);
156
+ if (!parsed.success) return "Unknown Prodia error";
157
+ const { message, detail, error: errorField } = parsed.data;
158
+ if (typeof detail === "string") return detail;
159
+ if (detail != null) {
160
+ try {
161
+ return JSON.stringify(detail);
162
+ } catch (e) {
163
+ }
164
+ }
165
+ return (_a = errorField != null ? errorField : message) != null ? _a : "Unknown Prodia error";
166
+ }
167
+ });
168
+
169
+ // src/prodia-image-model.ts
22
170
  var ProdiaImageModel = class {
23
171
  constructor(modelId, config) {
24
172
  this.modelId = modelId;
@@ -92,7 +240,7 @@ var ProdiaImageModel = class {
92
240
  return { body, warnings };
93
241
  }
94
242
  async doGenerate(options) {
95
- var _a, _b, _c, _d, _e, _f, _g;
243
+ var _a, _b, _c;
96
244
  const { body, warnings } = await this.getArgs(options);
97
245
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
98
246
  const combinedHeaders = combineHeaders(
@@ -121,29 +269,7 @@ var ProdiaImageModel = class {
121
269
  warnings,
122
270
  providerMetadata: {
123
271
  prodia: {
124
- images: [
125
- {
126
- jobId: jobResult.id,
127
- ...((_d = jobResult.config) == null ? void 0 : _d.seed) != null && {
128
- seed: jobResult.config.seed
129
- },
130
- ...((_e = jobResult.metrics) == null ? void 0 : _e.elapsed) != null && {
131
- elapsed: jobResult.metrics.elapsed
132
- },
133
- ...((_f = jobResult.metrics) == null ? void 0 : _f.ips) != null && {
134
- iterationsPerSecond: jobResult.metrics.ips
135
- },
136
- ...jobResult.created_at != null && {
137
- createdAt: jobResult.created_at
138
- },
139
- ...jobResult.updated_at != null && {
140
- updatedAt: jobResult.updated_at
141
- },
142
- ...((_g = jobResult.price) == null ? void 0 : _g.dollars) != null && {
143
- dollars: jobResult.price.dollars
144
- }
145
- }
146
- ]
272
+ images: [buildProdiaProviderMetadata(jobResult)]
147
273
  }
148
274
  },
149
275
  response: {
@@ -175,54 +301,34 @@ var stylePresets = [
175
301
  ];
176
302
  var prodiaImageProviderOptionsSchema = lazySchema(
177
303
  () => zodSchema(
178
- z.object({
304
+ z2.object({
179
305
  /**
180
306
  * Amount of computational iterations to run. More is typically higher quality.
181
307
  */
182
- steps: z.number().int().min(1).max(4).optional(),
308
+ steps: z2.number().int().min(1).max(4).optional(),
183
309
  /**
184
310
  * Width of the output image in pixels.
185
311
  */
186
- width: z.number().int().min(256).max(1920).optional(),
312
+ width: z2.number().int().min(256).max(1920).optional(),
187
313
  /**
188
314
  * Height of the output image in pixels.
189
315
  */
190
- height: z.number().int().min(256).max(1920).optional(),
316
+ height: z2.number().int().min(256).max(1920).optional(),
191
317
  /**
192
318
  * Apply a visual theme to your output image.
193
319
  */
194
- stylePreset: z.enum(stylePresets).optional(),
320
+ stylePreset: z2.enum(stylePresets).optional(),
195
321
  /**
196
322
  * Augment the output with a LoRa model.
197
323
  */
198
- loras: z.array(z.string()).max(3).optional(),
324
+ loras: z2.array(z2.string()).max(3).optional(),
199
325
  /**
200
326
  * When using JPEG output, return a progressive JPEG.
201
327
  */
202
- progressive: z.boolean().optional()
328
+ progressive: z2.boolean().optional()
203
329
  })
204
330
  )
205
331
  );
206
- var prodiaJobResultSchema = z.object({
207
- id: z.string(),
208
- created_at: z.string().optional(),
209
- updated_at: z.string().optional(),
210
- expires_at: z.string().optional(),
211
- state: z.object({
212
- current: z.string()
213
- }).optional(),
214
- config: z.object({
215
- seed: z.number().optional()
216
- }).passthrough().optional(),
217
- metrics: z.object({
218
- elapsed: z.number().optional(),
219
- ips: z.number().optional()
220
- }).optional(),
221
- price: z.object({
222
- product: z.string(),
223
- dollars: z.number()
224
- }).nullish()
225
- });
226
332
  function createMultipartResponseHandler() {
227
333
  return async ({
228
334
  response
@@ -250,7 +356,10 @@ function createMultipartResponseHandler() {
250
356
  const partContentType = (_c = part.headers["content-type"]) != null ? _c : "";
251
357
  if (contentDisposition.includes('name="job"')) {
252
358
  const jsonStr = new TextDecoder().decode(part.body);
253
- jobResult = prodiaJobResultSchema.parse(JSON.parse(jsonStr));
359
+ jobResult = await parseJSON({
360
+ text: jsonStr,
361
+ schema: zodSchema(prodiaJobResultSchema)
362
+ });
254
363
  } else if (contentDisposition.includes('name="output"')) {
255
364
  imageBytes = part.body;
256
365
  } else if (partContentType.startsWith("image/")) {
@@ -269,107 +378,321 @@ function createMultipartResponseHandler() {
269
378
  };
270
379
  };
271
380
  }
272
- function parseMultipart(data, boundary) {
273
- const parts = [];
274
- const boundaryBytes = new TextEncoder().encode(`--${boundary}`);
275
- const endBoundaryBytes = new TextEncoder().encode(`--${boundary}--`);
276
- const positions = [];
277
- for (let i = 0; i <= data.length - boundaryBytes.length; i++) {
278
- let match = true;
279
- for (let j = 0; j < boundaryBytes.length; j++) {
280
- if (data[i + j] !== boundaryBytes[j]) {
281
- match = false;
282
- break;
283
- }
381
+
382
+ // src/prodia-language-model.ts
383
+ import {
384
+ combineHeaders as combineHeaders2,
385
+ convertBase64ToUint8Array,
386
+ generateId,
387
+ lazySchema as lazySchema2,
388
+ parseJSON as parseJSON2,
389
+ parseProviderOptions as parseProviderOptions2,
390
+ postFormDataToApi,
391
+ resolve as resolve2,
392
+ zodSchema as zodSchema2
393
+ } from "@ai-sdk/provider-utils";
394
+ import { z as z3 } from "zod/v4";
395
+ var ProdiaLanguageModel = class {
396
+ constructor(modelId, config) {
397
+ this.modelId = modelId;
398
+ this.config = config;
399
+ this.specificationVersion = "v2";
400
+ this.supportedUrls = {};
401
+ }
402
+ get provider() {
403
+ return this.config.provider;
404
+ }
405
+ async doGenerate(options) {
406
+ var _a, _b, _c, _d;
407
+ const warnings = [];
408
+ if (options.temperature !== void 0) {
409
+ warnings.push({ type: "unsupported-setting", setting: "temperature" });
284
410
  }
285
- if (match) {
286
- positions.push(i);
411
+ if (options.topP !== void 0) {
412
+ warnings.push({ type: "unsupported-setting", setting: "topP" });
287
413
  }
288
- }
289
- for (let i = 0; i < positions.length - 1; i++) {
290
- const start = positions[i] + boundaryBytes.length;
291
- const end = positions[i + 1];
292
- let isEndBoundary = true;
293
- for (let j = 0; j < endBoundaryBytes.length && isEndBoundary; j++) {
294
- if (data[positions[i] + j] !== endBoundaryBytes[j]) {
295
- isEndBoundary = false;
296
- }
414
+ if (options.topK !== void 0) {
415
+ warnings.push({ type: "unsupported-setting", setting: "topK" });
297
416
  }
298
- if (isEndBoundary && positions[i] + endBoundaryBytes.length <= data.length) {
299
- continue;
417
+ if (options.maxOutputTokens !== void 0) {
418
+ warnings.push({
419
+ type: "unsupported-setting",
420
+ setting: "maxOutputTokens"
421
+ });
300
422
  }
301
- let partStart = start;
302
- if (data[partStart] === 13 && data[partStart + 1] === 10) {
303
- partStart += 2;
304
- } else if (data[partStart] === 10) {
305
- partStart += 1;
423
+ if (options.stopSequences !== void 0) {
424
+ warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
306
425
  }
307
- let partEnd = end;
308
- if (data[partEnd - 2] === 13 && data[partEnd - 1] === 10) {
309
- partEnd -= 2;
310
- } else if (data[partEnd - 1] === 10) {
311
- partEnd -= 1;
426
+ if (options.presencePenalty !== void 0) {
427
+ warnings.push({
428
+ type: "unsupported-setting",
429
+ setting: "presencePenalty"
430
+ });
312
431
  }
313
- const partData = data.slice(partStart, partEnd);
314
- let headerEnd = -1;
315
- for (let j = 0; j < partData.length - 3; j++) {
316
- if (partData[j] === 13 && partData[j + 1] === 10 && partData[j + 2] === 13 && partData[j + 3] === 10) {
317
- headerEnd = j;
432
+ if (options.frequencyPenalty !== void 0) {
433
+ warnings.push({
434
+ type: "unsupported-setting",
435
+ setting: "frequencyPenalty"
436
+ });
437
+ }
438
+ if (options.tools !== void 0 && options.tools.length > 0) {
439
+ warnings.push({ type: "unsupported-setting", setting: "tools" });
440
+ }
441
+ if (options.toolChoice !== void 0) {
442
+ warnings.push({ type: "unsupported-setting", setting: "toolChoice" });
443
+ }
444
+ if (options.responseFormat !== void 0 && options.responseFormat.type !== "text") {
445
+ warnings.push({ type: "unsupported-setting", setting: "responseFormat" });
446
+ }
447
+ const prodiaOptions = await parseProviderOptions2({
448
+ provider: "prodia",
449
+ providerOptions: options.providerOptions,
450
+ schema: prodiaLanguageModelOptionsSchema
451
+ });
452
+ let prompt = "";
453
+ let systemMessage = "";
454
+ for (const message of options.prompt) {
455
+ if (message.role === "system") {
456
+ systemMessage = message.content;
457
+ }
458
+ }
459
+ for (let i = options.prompt.length - 1; i >= 0; i--) {
460
+ const message = options.prompt[i];
461
+ if (message.role === "user") {
462
+ for (const part of message.content) {
463
+ if (part.type === "text") {
464
+ prompt += (prompt ? "\n" : "") + part.text;
465
+ }
466
+ }
318
467
  break;
319
468
  }
320
- if (partData[j] === 10 && partData[j + 1] === 10) {
321
- headerEnd = j;
469
+ }
470
+ if (systemMessage) {
471
+ prompt = systemMessage + "\n" + prompt;
472
+ }
473
+ let imageBytes;
474
+ let imageMediaType = "image/png";
475
+ for (let i = options.prompt.length - 1; i >= 0; i--) {
476
+ const message = options.prompt[i];
477
+ if (message.role === "user") {
478
+ for (const part of message.content) {
479
+ if (part.type === "file" && part.mediaType.startsWith("image/")) {
480
+ if (part.data instanceof Uint8Array) {
481
+ imageBytes = part.data;
482
+ } else if (typeof part.data === "string") {
483
+ imageBytes = convertBase64ToUint8Array(part.data);
484
+ } else if (part.data instanceof URL) {
485
+ const fetchFn = (_a = this.config.fetch) != null ? _a : globalThis.fetch;
486
+ const response = await fetchFn(part.data.toString());
487
+ const arrayBuffer = await response.arrayBuffer();
488
+ imageBytes = new Uint8Array(arrayBuffer);
489
+ }
490
+ imageMediaType = part.mediaType;
491
+ break;
492
+ }
493
+ }
322
494
  break;
323
495
  }
324
496
  }
325
- if (headerEnd === -1) {
326
- continue;
497
+ const jobConfig = {
498
+ prompt,
499
+ include_messages: true
500
+ };
501
+ if ((prodiaOptions == null ? void 0 : prodiaOptions.aspectRatio) !== void 0) {
502
+ jobConfig.aspect_ratio = prodiaOptions.aspectRatio;
327
503
  }
328
- const headerBytes = partData.slice(0, headerEnd);
329
- const headerStr = new TextDecoder().decode(headerBytes);
330
- const headers = {};
331
- for (const line of headerStr.split(/\r?\n/)) {
332
- const colonIdx = line.indexOf(":");
333
- if (colonIdx > 0) {
334
- const key = line.slice(0, colonIdx).trim().toLowerCase();
335
- const value = line.slice(colonIdx + 1).trim();
336
- headers[key] = value;
504
+ const body = {
505
+ type: this.modelId,
506
+ config: jobConfig
507
+ };
508
+ const currentDate = (_d = (_c = (_b = this.config._internal) == null ? void 0 : _b.currentDate) == null ? void 0 : _c.call(_b)) != null ? _d : /* @__PURE__ */ new Date();
509
+ const combinedHeaders = combineHeaders2(
510
+ await resolve2(this.config.headers),
511
+ options.headers
512
+ );
513
+ const formData = new FormData();
514
+ formData.append(
515
+ "job",
516
+ new Blob([JSON.stringify(body)], { type: "application/json" }),
517
+ "job.json"
518
+ );
519
+ if (imageBytes) {
520
+ const ext = imageMediaType === "image/png" ? ".png" : imageMediaType === "image/jpeg" ? ".jpg" : imageMediaType === "image/webp" ? ".webp" : "";
521
+ formData.append(
522
+ "input",
523
+ new Blob([imageBytes], { type: imageMediaType }),
524
+ "input" + ext
525
+ );
526
+ }
527
+ const { value: multipartResult, responseHeaders } = await postFormDataToApi(
528
+ {
529
+ url: `${this.config.baseURL}/job?price=true`,
530
+ headers: {
531
+ ...combinedHeaders,
532
+ Accept: "multipart/form-data"
533
+ },
534
+ formData,
535
+ failedResponseHandler: prodiaFailedResponseHandler,
536
+ successfulResponseHandler: createLanguageMultipartResponseHandler(),
537
+ abortSignal: options.abortSignal,
538
+ fetch: this.config.fetch
337
539
  }
540
+ );
541
+ const { jobResult, textContent, fileContent } = multipartResult;
542
+ const content = [];
543
+ if (textContent !== void 0) {
544
+ content.push({ type: "text", text: textContent });
338
545
  }
339
- let bodyStart = headerEnd + 2;
340
- if (partData[headerEnd] === 13) {
341
- bodyStart = headerEnd + 4;
546
+ for (const file of fileContent) {
547
+ content.push({
548
+ type: "file",
549
+ mediaType: file.mediaType,
550
+ data: file.data
551
+ });
342
552
  }
343
- const body = partData.slice(bodyStart);
344
- parts.push({ headers, body });
553
+ return {
554
+ content,
555
+ finishReason: "stop",
556
+ usage: {
557
+ inputTokens: void 0,
558
+ outputTokens: void 0,
559
+ totalTokens: void 0
560
+ },
561
+ warnings,
562
+ providerMetadata: {
563
+ prodia: buildProdiaProviderMetadata(jobResult)
564
+ },
565
+ response: {
566
+ modelId: this.modelId,
567
+ timestamp: currentDate,
568
+ headers: responseHeaders
569
+ }
570
+ };
345
571
  }
346
- return parts;
347
- }
348
- var prodiaErrorSchema = z.object({
349
- message: z.string().optional(),
350
- detail: z.unknown().optional(),
351
- error: z.string().optional()
352
- });
353
- var prodiaFailedResponseHandler = createJsonErrorResponseHandler({
354
- errorSchema: prodiaErrorSchema,
355
- errorToMessage: (error) => {
572
+ async doStream(options) {
356
573
  var _a;
357
- const parsed = prodiaErrorSchema.safeParse(error);
358
- if (!parsed.success) return "Unknown Prodia error";
359
- const { message, detail, error: errorField } = parsed.data;
360
- if (typeof detail === "string") return detail;
361
- if (detail != null) {
362
- try {
363
- return JSON.stringify(detail);
364
- } catch (e) {
574
+ const result = await this.doGenerate(options);
575
+ const stream = new ReadableStream({
576
+ start(controller) {
577
+ var _a2, _b;
578
+ controller.enqueue({
579
+ type: "stream-start",
580
+ warnings: result.warnings
581
+ });
582
+ controller.enqueue({
583
+ type: "response-metadata",
584
+ modelId: (_a2 = result.response) == null ? void 0 : _a2.modelId,
585
+ timestamp: (_b = result.response) == null ? void 0 : _b.timestamp
586
+ });
587
+ for (const part of result.content) {
588
+ if (part.type === "text") {
589
+ const id = generateId();
590
+ controller.enqueue({ type: "text-start", id });
591
+ controller.enqueue({
592
+ type: "text-delta",
593
+ id,
594
+ delta: part.text
595
+ });
596
+ controller.enqueue({ type: "text-end", id });
597
+ } else if (part.type === "file") {
598
+ controller.enqueue({
599
+ type: "file",
600
+ mediaType: part.mediaType,
601
+ data: part.data
602
+ });
603
+ }
604
+ }
605
+ controller.enqueue({
606
+ type: "finish",
607
+ usage: result.usage,
608
+ finishReason: result.finishReason,
609
+ providerMetadata: result.providerMetadata
610
+ });
611
+ controller.close();
365
612
  }
366
- }
367
- return (_a = errorField != null ? errorField : message) != null ? _a : "Unknown Prodia error";
613
+ });
614
+ return {
615
+ stream,
616
+ response: {
617
+ headers: (_a = result.response) == null ? void 0 : _a.headers
618
+ }
619
+ };
368
620
  }
369
- });
621
+ };
622
+ var prodiaLanguageModelOptionsSchema = lazySchema2(
623
+ () => zodSchema2(
624
+ z3.object({
625
+ aspectRatio: z3.enum([
626
+ "1:1",
627
+ "2:3",
628
+ "3:2",
629
+ "4:5",
630
+ "5:4",
631
+ "4:7",
632
+ "7:4",
633
+ "9:16",
634
+ "16:9",
635
+ "9:21",
636
+ "21:9"
637
+ ]).optional()
638
+ })
639
+ )
640
+ );
641
+ function createLanguageMultipartResponseHandler() {
642
+ return async ({
643
+ response
644
+ }) => {
645
+ var _a, _b, _c;
646
+ const contentType = (_a = response.headers.get("content-type")) != null ? _a : "";
647
+ const responseHeaders = {};
648
+ response.headers.forEach((value, key) => {
649
+ responseHeaders[key] = value;
650
+ });
651
+ const boundaryMatch = contentType.match(/boundary=([^\s;]+)/);
652
+ if (!boundaryMatch) {
653
+ throw new Error(
654
+ `Prodia response missing multipart boundary in content-type: ${contentType}`
655
+ );
656
+ }
657
+ const boundary = boundaryMatch[1];
658
+ const arrayBuffer = await response.arrayBuffer();
659
+ const bytes = new Uint8Array(arrayBuffer);
660
+ const parts = parseMultipart(bytes, boundary);
661
+ let jobResult;
662
+ let textContent;
663
+ const fileContent = [];
664
+ for (const part of parts) {
665
+ const contentDisposition = (_b = part.headers["content-disposition"]) != null ? _b : "";
666
+ const partContentType = (_c = part.headers["content-type"]) != null ? _c : "";
667
+ if (contentDisposition.includes('name="job"')) {
668
+ const jsonStr = new TextDecoder().decode(part.body);
669
+ jobResult = await parseJSON2({
670
+ text: jsonStr,
671
+ schema: zodSchema2(prodiaJobResultSchema)
672
+ });
673
+ } else if (contentDisposition.includes('name="output"')) {
674
+ if (partContentType.startsWith("text/") || contentDisposition.includes(".txt")) {
675
+ textContent = new TextDecoder().decode(part.body);
676
+ } else if (partContentType.startsWith("image/")) {
677
+ fileContent.push({
678
+ mediaType: partContentType,
679
+ data: part.body
680
+ });
681
+ }
682
+ }
683
+ }
684
+ if (!jobResult) {
685
+ throw new Error("Prodia multipart response missing job part");
686
+ }
687
+ return {
688
+ value: { jobResult, textContent, fileContent },
689
+ responseHeaders
690
+ };
691
+ };
692
+ }
370
693
 
371
694
  // src/version.ts
372
- var VERSION = true ? "0.0.3" : "0.0.0-test";
695
+ var VERSION = true ? "0.0.5" : "0.0.0-test";
373
696
 
374
697
  // src/prodia-provider.ts
375
698
  var defaultBaseURL = "https://inference.prodia.com/v2";
@@ -393,22 +716,22 @@ function createProdia(options = {}) {
393
716
  headers: getHeaders,
394
717
  fetch: options.fetch
395
718
  });
719
+ const createLanguageModel = (modelId) => new ProdiaLanguageModel(modelId, {
720
+ provider: "prodia.language",
721
+ baseURL: baseURL != null ? baseURL : defaultBaseURL,
722
+ headers: getHeaders,
723
+ fetch: options.fetch
724
+ });
396
725
  const textEmbeddingModel = (modelId) => {
397
726
  throw new NoSuchModelError({
398
727
  modelId,
399
728
  modelType: "textEmbeddingModel"
400
729
  });
401
730
  };
402
- const languageModel = (modelId) => {
403
- throw new NoSuchModelError({
404
- modelId,
405
- modelType: "languageModel"
406
- });
407
- };
408
731
  return {
732
+ languageModel: createLanguageModel,
409
733
  imageModel: createImageModel,
410
734
  image: createImageModel,
411
- languageModel,
412
735
  textEmbeddingModel
413
736
  };
414
737
  }