@xiaozhiclaw/provider-core 0.1.1 → 0.1.4
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/media-client.js
CHANGED
|
@@ -150,6 +150,7 @@ function createMediaTransport(providerDef) {
|
|
|
150
150
|
case "volcengine":
|
|
151
151
|
return new VolcengineMediaTransport({ baseUrl: rawUrl });
|
|
152
152
|
case "openai":
|
|
153
|
+
case "llmrouter":
|
|
153
154
|
return new OpenAIMediaTransport({ baseUrl: rawUrl });
|
|
154
155
|
case "minimax":
|
|
155
156
|
return new MiniMaxMediaTransport({ baseUrl: rawUrl });
|
|
@@ -117,6 +117,8 @@ export interface MediaRequest {
|
|
|
117
117
|
export interface MediaResult {
|
|
118
118
|
/** URLs of generated media files */
|
|
119
119
|
mediaUrls: string[];
|
|
120
|
+
/** Provider actually used */
|
|
121
|
+
provider?: string;
|
|
120
122
|
/** Model actually used */
|
|
121
123
|
model?: string;
|
|
122
124
|
/** Output dimensions / format info */
|
|
@@ -61,9 +61,13 @@ export class OpenAIMediaTransport {
|
|
|
61
61
|
throw new Error(`OpenAI images API error ${res.status}: ${text}`);
|
|
62
62
|
}
|
|
63
63
|
const data = await res.json();
|
|
64
|
-
const mediaUrls = (data.data ?? [])
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const mediaUrls = (data.data ?? []).flatMap(d => {
|
|
65
|
+
if (d.url)
|
|
66
|
+
return [d.url];
|
|
67
|
+
if (d.b64_json)
|
|
68
|
+
return [`data:image/webp;base64,${d.b64_json}`];
|
|
69
|
+
return [];
|
|
70
|
+
});
|
|
67
71
|
return {
|
|
68
72
|
mediaUrls,
|
|
69
73
|
model: request.model,
|
|
@@ -140,9 +140,7 @@ export class VolcengineMediaTransport {
|
|
|
140
140
|
return this.parseStreamingImage(res.body, request, start);
|
|
141
141
|
}
|
|
142
142
|
const data = await res.json();
|
|
143
|
-
const mediaUrls = (data.data ??
|
|
144
|
-
.map(d => d.url)
|
|
145
|
-
.filter((u) => !!u);
|
|
143
|
+
const mediaUrls = extractVolcengineImageUrls(data.data ?? data);
|
|
146
144
|
return {
|
|
147
145
|
mediaUrls,
|
|
148
146
|
model: request.model,
|
|
@@ -770,6 +768,43 @@ export class VolcengineMediaTransport {
|
|
|
770
768
|
throw new Error("Volcengine task timed out after polling");
|
|
771
769
|
}
|
|
772
770
|
}
|
|
771
|
+
function extractVolcengineImageUrls(value) {
|
|
772
|
+
const urls = [];
|
|
773
|
+
const visit = (node) => {
|
|
774
|
+
if (!node)
|
|
775
|
+
return;
|
|
776
|
+
if (Array.isArray(node)) {
|
|
777
|
+
for (const item of node)
|
|
778
|
+
visit(item);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
if (typeof node !== "object")
|
|
782
|
+
return;
|
|
783
|
+
const record = node;
|
|
784
|
+
for (const key of ["url", "image_url", "output_url"]) {
|
|
785
|
+
const url = record[key];
|
|
786
|
+
if (typeof url === "string" && url.trim())
|
|
787
|
+
urls.push(url);
|
|
788
|
+
}
|
|
789
|
+
const b64 = record.b64_json;
|
|
790
|
+
if (typeof b64 === "string" && b64.trim())
|
|
791
|
+
urls.push(`data:image/webp;base64,${b64}`);
|
|
792
|
+
for (const key of ["image_urls", "urls", "output_urls"]) {
|
|
793
|
+
const value = record[key];
|
|
794
|
+
if (Array.isArray(value)) {
|
|
795
|
+
for (const item of value) {
|
|
796
|
+
if (typeof item === "string" && item.trim())
|
|
797
|
+
urls.push(item);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
for (const child of Object.values(record)) {
|
|
802
|
+
visit(child);
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
visit(value);
|
|
806
|
+
return [...new Set(urls)];
|
|
807
|
+
}
|
|
773
808
|
function extractGeneratedTokenUsage(result) {
|
|
774
809
|
const usage = (result.usage ?? result.data?.usage);
|
|
775
810
|
const completionTokens = numericUsage(usage?.completion_tokens)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiaozhiclaw/provider-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Shared QLogic LLM provider adaptation layer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22.0.0"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {},
|
|
24
28
|
"scripts": {
|
|
25
29
|
"build": "tsc -p tsconfig.json",
|
|
26
30
|
"test": "vitest run",
|
|
27
31
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
"node": ">=22.0.0"
|
|
31
|
-
},
|
|
32
|
-
"dependencies": {}
|
|
33
|
-
}
|
|
32
|
+
}
|
|
33
|
+
}
|