@threaded/ai 1.0.12 → 1.0.14
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.cjs +137 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +134 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
IMAGE_MODEL_SCHEMA: () => IMAGE_MODEL_SCHEMA,
|
|
33
34
|
Inherit: () => Inherit,
|
|
34
35
|
appendToLastRequest: () => appendToLastRequest,
|
|
35
36
|
compose: () => compose,
|
|
@@ -42,7 +43,9 @@ __export(index_exports, {
|
|
|
42
43
|
everyNTokens: () => everyNTokens,
|
|
43
44
|
generateApprovalToken: () => generateApprovalToken,
|
|
44
45
|
generateImage: () => generateImage,
|
|
46
|
+
getDefaultConfig: () => getDefaultConfig,
|
|
45
47
|
getKey: () => getKey,
|
|
48
|
+
getModelConfig: () => getModelConfig,
|
|
46
49
|
getOrCreateThread: () => getOrCreateThread,
|
|
47
50
|
isStandardSchema: () => isStandardSchema,
|
|
48
51
|
maxCalls: () => maxCalls,
|
|
@@ -301,6 +304,7 @@ var generateOpenAICompatible = async (endpoint, modelName, prompt, apiKey, confi
|
|
|
301
304
|
if (config?.outputFormat) body.output_format = config.outputFormat;
|
|
302
305
|
if (config?.outputCompression != null) body.output_compression = config.outputCompression;
|
|
303
306
|
if (config?.background) body.background = config.background;
|
|
307
|
+
if (config?.moderation) body.moderation = config.moderation;
|
|
304
308
|
}
|
|
305
309
|
const response = await fetch(endpoint, {
|
|
306
310
|
method: "POST",
|
|
@@ -332,6 +336,9 @@ var generateGoogle = async (modelName, prompt, apiKey, config) => {
|
|
|
332
336
|
if (config?.aspectRatio) {
|
|
333
337
|
body.generationConfig.aspectRatio = config.aspectRatio;
|
|
334
338
|
}
|
|
339
|
+
if (config?.imageSize) {
|
|
340
|
+
body.generationConfig.imageSize = config.imageSize;
|
|
341
|
+
}
|
|
335
342
|
const response = await fetch(endpoint, {
|
|
336
343
|
method: "POST",
|
|
337
344
|
headers: {
|
|
@@ -384,6 +391,100 @@ var generateImage = async (model2, prompt, config) => {
|
|
|
384
391
|
}
|
|
385
392
|
};
|
|
386
393
|
|
|
394
|
+
// src/image-model-schema.ts
|
|
395
|
+
var IMAGE_MODEL_SCHEMA = {
|
|
396
|
+
openai: {
|
|
397
|
+
"dall-e-3": {
|
|
398
|
+
size: {
|
|
399
|
+
values: ["1024x1024", "1024x1792", "1792x1024"],
|
|
400
|
+
default: "1024x1024",
|
|
401
|
+
description: "Image dimensions"
|
|
402
|
+
},
|
|
403
|
+
quality: {
|
|
404
|
+
values: ["standard", "hd"],
|
|
405
|
+
default: "standard",
|
|
406
|
+
description: "Image quality level"
|
|
407
|
+
},
|
|
408
|
+
style: {
|
|
409
|
+
values: ["vivid", "natural"],
|
|
410
|
+
default: "vivid",
|
|
411
|
+
description: "Image style"
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
"gpt-image-1.5": {
|
|
415
|
+
size: {
|
|
416
|
+
values: ["1024x1024", "1536x1024", "1024x1536", "auto"],
|
|
417
|
+
default: "auto",
|
|
418
|
+
description: "Image dimensions"
|
|
419
|
+
},
|
|
420
|
+
quality: {
|
|
421
|
+
values: ["low", "medium", "high", "auto"],
|
|
422
|
+
default: "auto",
|
|
423
|
+
description: "Image quality level"
|
|
424
|
+
},
|
|
425
|
+
background: {
|
|
426
|
+
values: ["transparent", "opaque", "auto"],
|
|
427
|
+
default: "auto",
|
|
428
|
+
description: "Background type"
|
|
429
|
+
},
|
|
430
|
+
moderation: {
|
|
431
|
+
values: ["auto", "low"],
|
|
432
|
+
default: "auto",
|
|
433
|
+
description: "Content moderation level"
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
google: {
|
|
438
|
+
"gemini-2.5-flash-image": {
|
|
439
|
+
aspectRatio: {
|
|
440
|
+
values: ["1:1", "3:4", "4:3", "9:16", "16:9"],
|
|
441
|
+
default: "1:1",
|
|
442
|
+
description: "Image aspect ratio"
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
"gemini-3-pro-image-preview": {
|
|
446
|
+
aspectRatio: {
|
|
447
|
+
values: ["1:1", "3:4", "4:3", "9:16", "16:9"],
|
|
448
|
+
default: "1:1",
|
|
449
|
+
description: "Image aspect ratio"
|
|
450
|
+
},
|
|
451
|
+
imageSize: {
|
|
452
|
+
values: ["1K", "2K"],
|
|
453
|
+
default: "1K",
|
|
454
|
+
description: "Output image size"
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
"nano-banana-pro-preview": {
|
|
458
|
+
aspectRatio: {
|
|
459
|
+
values: ["1:1", "3:4", "4:3", "9:16", "16:9"],
|
|
460
|
+
default: "1:1",
|
|
461
|
+
description: "Image aspect ratio"
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
xai: {
|
|
466
|
+
"grok-2-image-1212": {
|
|
467
|
+
size: {
|
|
468
|
+
values: ["1024x1024"],
|
|
469
|
+
default: "1024x1024",
|
|
470
|
+
description: "Image dimensions"
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
function getModelConfig(provider, model2) {
|
|
476
|
+
return IMAGE_MODEL_SCHEMA[provider]?.[model2] || null;
|
|
477
|
+
}
|
|
478
|
+
function getDefaultConfig(provider, model2) {
|
|
479
|
+
const schema = getModelConfig(provider, model2);
|
|
480
|
+
if (!schema) return {};
|
|
481
|
+
const defaults = {};
|
|
482
|
+
for (const [key, option] of Object.entries(schema)) {
|
|
483
|
+
defaults[key] = option.default;
|
|
484
|
+
}
|
|
485
|
+
return defaults;
|
|
486
|
+
}
|
|
487
|
+
|
|
387
488
|
// src/providers/openai.ts
|
|
388
489
|
var getApiKey2 = (configApiKey) => {
|
|
389
490
|
if (configApiKey) return configApiKey;
|
|
@@ -760,23 +861,27 @@ var callGoogle = async (config, ctx) => {
|
|
|
760
861
|
for (let i = 0; i < ctx.history.length; i++) {
|
|
761
862
|
const msg2 = ctx.history[i];
|
|
762
863
|
if (msg2.role === "assistant") {
|
|
763
|
-
const
|
|
864
|
+
const parts2 = [];
|
|
764
865
|
if (msg2.content) {
|
|
765
|
-
|
|
866
|
+
parts2.push({ text: msg2.content });
|
|
766
867
|
}
|
|
767
868
|
if (msg2.tool_calls?.length) {
|
|
768
869
|
for (const tc of msg2.tool_calls) {
|
|
769
870
|
toolCallMap.set(tc.id, tc.function.name);
|
|
770
|
-
|
|
871
|
+
const part = {
|
|
771
872
|
functionCall: {
|
|
772
873
|
name: tc.function.name,
|
|
773
874
|
args: JSON.parse(tc.function.arguments)
|
|
774
875
|
}
|
|
775
|
-
}
|
|
876
|
+
};
|
|
877
|
+
if (tc.thoughtSignature) {
|
|
878
|
+
part.thoughtSignature = tc.thoughtSignature;
|
|
879
|
+
}
|
|
880
|
+
parts2.push(part);
|
|
776
881
|
}
|
|
777
882
|
}
|
|
778
|
-
if (
|
|
779
|
-
contents.push({ role: "model", parts });
|
|
883
|
+
if (parts2.length > 0) {
|
|
884
|
+
contents.push({ role: "model", parts: parts2 });
|
|
780
885
|
}
|
|
781
886
|
} else if (msg2.role === "tool") {
|
|
782
887
|
const responseParts = [];
|
|
@@ -845,22 +950,33 @@ var callGoogle = async (config, ctx) => {
|
|
|
845
950
|
}
|
|
846
951
|
const data = await response.json();
|
|
847
952
|
const candidate = data.candidates[0];
|
|
848
|
-
const
|
|
953
|
+
const parts = candidate.content.parts || [];
|
|
849
954
|
const msg = {
|
|
850
955
|
role: "assistant",
|
|
851
|
-
content:
|
|
956
|
+
content: ""
|
|
852
957
|
};
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
958
|
+
const toolCalls = [];
|
|
959
|
+
for (const part of parts) {
|
|
960
|
+
if (part.text) {
|
|
961
|
+
msg.content += part.text;
|
|
962
|
+
}
|
|
963
|
+
if (part.functionCall) {
|
|
964
|
+
const tc = {
|
|
856
965
|
id: Math.random().toString(36).substring(2, 9),
|
|
857
966
|
type: "function",
|
|
858
967
|
function: {
|
|
859
968
|
name: part.functionCall.name,
|
|
860
969
|
arguments: JSON.stringify(part.functionCall.args)
|
|
861
970
|
}
|
|
971
|
+
};
|
|
972
|
+
if (part.thoughtSignature) {
|
|
973
|
+
tc.thoughtSignature = part.thoughtSignature;
|
|
862
974
|
}
|
|
863
|
-
|
|
975
|
+
toolCalls.push(tc);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
if (toolCalls.length > 0) {
|
|
979
|
+
msg.tool_calls = toolCalls;
|
|
864
980
|
}
|
|
865
981
|
return {
|
|
866
982
|
...ctx,
|
|
@@ -900,14 +1016,18 @@ var handleGoogleStream = async (response, ctx) => {
|
|
|
900
1016
|
}
|
|
901
1017
|
}
|
|
902
1018
|
if (part?.functionCall) {
|
|
903
|
-
|
|
1019
|
+
const tc = {
|
|
904
1020
|
id: Math.random().toString(36).substring(2, 9),
|
|
905
1021
|
type: "function",
|
|
906
1022
|
function: {
|
|
907
1023
|
name: part.functionCall.name,
|
|
908
1024
|
arguments: JSON.stringify(part.functionCall.args)
|
|
909
1025
|
}
|
|
910
|
-
}
|
|
1026
|
+
};
|
|
1027
|
+
if (part.thoughtSignature) {
|
|
1028
|
+
tc.thoughtSignature = part.thoughtSignature;
|
|
1029
|
+
}
|
|
1030
|
+
toolCalls.push(tc);
|
|
911
1031
|
}
|
|
912
1032
|
}
|
|
913
1033
|
} catch (e) {
|
|
@@ -1693,6 +1813,7 @@ var rateLimited = (config) => (fn) => {
|
|
|
1693
1813
|
};
|
|
1694
1814
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1695
1815
|
0 && (module.exports = {
|
|
1816
|
+
IMAGE_MODEL_SCHEMA,
|
|
1696
1817
|
Inherit,
|
|
1697
1818
|
appendToLastRequest,
|
|
1698
1819
|
compose,
|
|
@@ -1705,7 +1826,9 @@ var rateLimited = (config) => (fn) => {
|
|
|
1705
1826
|
everyNTokens,
|
|
1706
1827
|
generateApprovalToken,
|
|
1707
1828
|
generateImage,
|
|
1829
|
+
getDefaultConfig,
|
|
1708
1830
|
getKey,
|
|
1831
|
+
getModelConfig,
|
|
1709
1832
|
getOrCreateThread,
|
|
1710
1833
|
isStandardSchema,
|
|
1711
1834
|
maxCalls,
|