openany-cli-dev 0.0.0-stage → 0.1.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.
- package/README.md +461 -2
- package/bin/openany.js +3 -0
- package/package.json +27 -4
- package/skills/openany/SKILL.md +347 -0
- package/skills/openany/SKILL.zh-CN.md +496 -0
- package/skills/openany-provider/SKILL.md +26 -0
- package/skills/openany-provider/SKILL.zh-CN.md +26 -0
- package/skills/openany-provider/references/apis.md +60 -0
- package/skills/openany-provider/references/application.md +49 -0
- package/skills/openany-provider/references/application.zh-CN.md +51 -0
- package/skills/openany-provider/references/auth.md +59 -0
- package/skills/openany-provider/references/connections.md +38 -0
- package/skills/openany-provider/references/connections.zh-CN.md +33 -0
- package/skills/openany-provider/references/imports.md +38 -0
- package/skills/openany-provider/references/imports.zh-CN.md +55 -0
- package/skills/openany-provider/references/listing.md +29 -0
- package/skills/openany-provider/references/login.md +58 -0
- package/skills/openany-provider/references/login.zh-CN.md +59 -0
- package/skills/openany-provider/references/model-import.zh-CN.md +12 -0
- package/skills/openany-provider/references/models.md +107 -0
- package/skills/openany-provider/references/publishing.md +83 -0
- package/skills/openany-provider/references/publishing.zh-CN.md +81 -0
- package/skills/openany-provider/references/reviews.md +22 -0
- package/skills/openany-provider/templates/api-metadata.json +27 -0
- package/skills/openany-provider/templates/bindings.json +1 -0
- package/skills/openany-provider/templates/models-v2.json +545 -0
- package/skills/openany-provider/templates/models.json +10 -0
- package/skills/openany-provider/templates/provider-agent-api-template.json +697 -0
- package/skills/openany-provider/templates/seller-agent-api-import-template.json +839 -0
- package/skills/openany-provider/templates/seller-registration.json +26 -0
- package/src/auth-recovery.js +179 -0
- package/src/auth.js +1001 -0
- package/src/catalog.js +306 -0
- package/src/cli.js +601 -0
- package/src/config.js +260 -0
- package/src/errors.js +53 -0
- package/src/http.js +237 -0
- package/src/model-curl.js +359 -0
- package/src/model-materials.js +58 -0
- package/src/model-request.js +402 -0
- package/src/model-validation.js +56 -0
- package/src/models.js +188 -0
- package/src/native/config-acl.ps1 +34 -0
- package/src/native/connection-macos.js +109 -0
- package/src/native/connection-windows.ps1 +98 -0
- package/src/native/setup-macos.js +72 -0
- package/src/native/setup-windows.ps1 +83 -0
- package/src/native-prompt.js +85 -0
- package/src/payment-signing.js +362 -0
- package/src/prompt.js +69 -0
- package/src/provider-api-import-v2.js +72 -0
- package/src/provider-apis.js +3 -0
- package/src/provider-client.js +153 -0
- package/src/provider-connections.js +152 -0
- package/src/provider-import-format.js +289 -0
- package/src/provider-imports.js +402 -0
- package/src/provider-json.js +49 -0
- package/src/provider-model-import-v2.js +61 -0
- package/src/provider-models.js +253 -0
- package/src/provider-profile.js +65 -0
- package/src/provider-reviews.js +61 -0
- package/src/provider-state.js +176 -0
- package/src/provider.js +75 -0
- package/src/setup.js +201 -0
- package/src/topups.js +845 -0
- package/src/vendor/provider-apply/market-taxonomy.mjs +22 -0
- package/src/vendor/provider-apply/provenance.json +8 -0
- package/src/vendor/provider-apply/registration.mjs +151 -0
- package/src/vendor/provider-import/api-categories.json +29 -0
- package/src/vendor/provider-import/api-fields.json +33 -0
- package/src/vendor/provider-import/model-fields.json +44 -0
- package/src/wallet.js +213 -0
- package/src/windows-permissions.js +22 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { CLIError } from "./errors.js";
|
|
2
|
+
import { modelUrl } from "./http.js";
|
|
3
|
+
import { isObject } from "./catalog.js";
|
|
4
|
+
|
|
5
|
+
const fail = (code, message, token = {}) => {
|
|
6
|
+
throw new CLIError(code, message, { line: token.line, column: token.column });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// Tokenize a deliberately limited shell syntax; nothing is expanded or executed.
|
|
10
|
+
function commands(source) {
|
|
11
|
+
const result = [];
|
|
12
|
+
let tokens = [],
|
|
13
|
+
token,
|
|
14
|
+
quote,
|
|
15
|
+
line = 1,
|
|
16
|
+
column = 1;
|
|
17
|
+
const advance = (c) => {
|
|
18
|
+
if (c === "\n") {
|
|
19
|
+
line++;
|
|
20
|
+
column = 1;
|
|
21
|
+
} else column++;
|
|
22
|
+
};
|
|
23
|
+
const start = () => {
|
|
24
|
+
token ??= { value: "", line, column, expansion: false };
|
|
25
|
+
};
|
|
26
|
+
const flush = () => {
|
|
27
|
+
if (token) tokens.push(token);
|
|
28
|
+
token = undefined;
|
|
29
|
+
};
|
|
30
|
+
const finish = () => {
|
|
31
|
+
flush();
|
|
32
|
+
if (tokens.length) result.push({ tokens });
|
|
33
|
+
tokens = [];
|
|
34
|
+
};
|
|
35
|
+
try {
|
|
36
|
+
for (let i = 0; i < source.length; i++) {
|
|
37
|
+
const c = source[i];
|
|
38
|
+
if (
|
|
39
|
+
!quote &&
|
|
40
|
+
!token &&
|
|
41
|
+
(c === "#" || (!tokens.length && source.slice(i, i + 2) === "//"))
|
|
42
|
+
) {
|
|
43
|
+
while (i < source.length && source[i] !== "\n") advance(source[i++]);
|
|
44
|
+
if (i < source.length) {
|
|
45
|
+
finish();
|
|
46
|
+
advance("\n");
|
|
47
|
+
}
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (c === "\\" && quote !== "'") {
|
|
51
|
+
const next = source[i + 1];
|
|
52
|
+
if (next === undefined || (!quote && !source.slice(i + 1).trim()))
|
|
53
|
+
fail("INVALID_CURL_SYNTAX", "Dangling line continuation", {
|
|
54
|
+
line,
|
|
55
|
+
column,
|
|
56
|
+
});
|
|
57
|
+
if (next === "\n" || (next === "\r" && source[i + 2] === "\n")) {
|
|
58
|
+
advance(c);
|
|
59
|
+
advance(source[++i]);
|
|
60
|
+
if (next === "\r") advance(source[++i]);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
start();
|
|
64
|
+
// In double quotes POSIX only unescapes these characters.
|
|
65
|
+
if (quote === '"' && !["$", "`", '"', "\\"].includes(next))
|
|
66
|
+
token.value += "\\";
|
|
67
|
+
token.value += next;
|
|
68
|
+
advance(c);
|
|
69
|
+
advance(next);
|
|
70
|
+
i++;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (!quote && /\s/.test(c)) {
|
|
74
|
+
if (c === "\n") finish();
|
|
75
|
+
else flush();
|
|
76
|
+
advance(c);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
start();
|
|
80
|
+
if (c === quote) {
|
|
81
|
+
quote = undefined;
|
|
82
|
+
advance(c);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (!quote && (c === "'" || c === '"')) {
|
|
86
|
+
quote = c;
|
|
87
|
+
advance(c);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (!quote && /[;&|<>]/.test(c))
|
|
91
|
+
fail("INVALID_CURL_SYNTAX", "Shell operators are not supported", {
|
|
92
|
+
line,
|
|
93
|
+
column,
|
|
94
|
+
});
|
|
95
|
+
if (quote !== "'" && (c === "$" || c === "`")) token.expansion = true;
|
|
96
|
+
token.value += c;
|
|
97
|
+
advance(c);
|
|
98
|
+
}
|
|
99
|
+
if (quote) fail("INVALID_CURL_SYNTAX", "Unclosed quote", token);
|
|
100
|
+
finish();
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (!(error instanceof CLIError)) throw error;
|
|
103
|
+
flush();
|
|
104
|
+
result.push({ tokens, error });
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parse(tokens) {
|
|
110
|
+
if (tokens[0]?.value !== "curl")
|
|
111
|
+
fail("INVALID_CURL_SYNTAX", "Expected a curl command", tokens[0]);
|
|
112
|
+
let url, method, data;
|
|
113
|
+
const headers = Object.create(null),
|
|
114
|
+
form = [],
|
|
115
|
+
notices = [];
|
|
116
|
+
const valueOptions = new Set([
|
|
117
|
+
"-X",
|
|
118
|
+
"--request",
|
|
119
|
+
"-H",
|
|
120
|
+
"--header",
|
|
121
|
+
"-d",
|
|
122
|
+
"--data",
|
|
123
|
+
"--data-raw",
|
|
124
|
+
"-F",
|
|
125
|
+
"--form",
|
|
126
|
+
"--url",
|
|
127
|
+
]);
|
|
128
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
129
|
+
const token = tokens[i];
|
|
130
|
+
let flag = token.value,
|
|
131
|
+
valueToken;
|
|
132
|
+
const eq = flag.startsWith("--") ? flag.indexOf("=") : -1;
|
|
133
|
+
if (eq >= 0) {
|
|
134
|
+
valueToken = { ...token, value: flag.slice(eq + 1) };
|
|
135
|
+
flag = flag.slice(0, eq);
|
|
136
|
+
}
|
|
137
|
+
if (
|
|
138
|
+
[
|
|
139
|
+
"--location",
|
|
140
|
+
"-L",
|
|
141
|
+
"--silent",
|
|
142
|
+
"-s",
|
|
143
|
+
"--show-error",
|
|
144
|
+
"-S",
|
|
145
|
+
"-sS",
|
|
146
|
+
].includes(flag)
|
|
147
|
+
) {
|
|
148
|
+
if (eq >= 0 || token.expansion)
|
|
149
|
+
fail("INVALID_CURL_SYNTAX", "Unexpected flag value", token);
|
|
150
|
+
if (flag === "--location" || flag === "-L")
|
|
151
|
+
notices.push(
|
|
152
|
+
"Redirects are not followed; the CLI reports redirect errors.",
|
|
153
|
+
);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (!flag.startsWith("-")) {
|
|
157
|
+
if (url)
|
|
158
|
+
fail(
|
|
159
|
+
"INVALID_CURL_SYNTAX",
|
|
160
|
+
"Only one URL per curl command is supported",
|
|
161
|
+
token,
|
|
162
|
+
);
|
|
163
|
+
if (token.expansion)
|
|
164
|
+
fail(
|
|
165
|
+
"UNSUPPORTED_SHELL_EXPANSION",
|
|
166
|
+
"URL shell expansion is not supported",
|
|
167
|
+
token,
|
|
168
|
+
);
|
|
169
|
+
url = flag;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (!valueOptions.has(flag))
|
|
173
|
+
fail(
|
|
174
|
+
"UNSUPPORTED_CURL_OPTION",
|
|
175
|
+
`Unsupported curl option: ${flag}`,
|
|
176
|
+
token,
|
|
177
|
+
);
|
|
178
|
+
valueToken ??= tokens[++i];
|
|
179
|
+
if (!valueToken)
|
|
180
|
+
fail("INVALID_CURL_SYNTAX", `Missing value for ${flag}`, token);
|
|
181
|
+
const value = valueToken.value;
|
|
182
|
+
const header = flag === "-H" || flag === "--header";
|
|
183
|
+
if (
|
|
184
|
+
valueToken.expansion &&
|
|
185
|
+
!(
|
|
186
|
+
header &&
|
|
187
|
+
/^Authorization:\s*Bearer\s+\$(?:[A-Za-z_][A-Za-z_0-9]*|\{[A-Za-z_][A-Za-z_0-9]*\})$/i.test(
|
|
188
|
+
value,
|
|
189
|
+
)
|
|
190
|
+
)
|
|
191
|
+
)
|
|
192
|
+
fail(
|
|
193
|
+
"UNSUPPORTED_SHELL_EXPANSION",
|
|
194
|
+
"Only a Bearer API key variable may be substituted",
|
|
195
|
+
valueToken,
|
|
196
|
+
);
|
|
197
|
+
if (flag === "--url") {
|
|
198
|
+
if (url)
|
|
199
|
+
fail(
|
|
200
|
+
"INVALID_CURL_SYNTAX",
|
|
201
|
+
"Only one URL per command is supported",
|
|
202
|
+
token,
|
|
203
|
+
);
|
|
204
|
+
url = value;
|
|
205
|
+
} else if (flag === "-X" || flag === "--request") {
|
|
206
|
+
if (method) fail("INVALID_CURL_SYNTAX", "Repeated request method", token);
|
|
207
|
+
method = value;
|
|
208
|
+
} else if (header) {
|
|
209
|
+
const split = value.indexOf(":");
|
|
210
|
+
const name = value.slice(0, split).trim().toLowerCase();
|
|
211
|
+
if (
|
|
212
|
+
split < 1 ||
|
|
213
|
+
!/^[!#$%&'*+.^_`|~0-9a-z-]+$/.test(name) ||
|
|
214
|
+
/[\r\n]/.test(value)
|
|
215
|
+
)
|
|
216
|
+
fail("INVALID_CURL_SYNTAX", "Invalid request header", valueToken);
|
|
217
|
+
if (Object.hasOwn(headers, name))
|
|
218
|
+
fail("INVALID_CURL_SYNTAX", `Repeated header: ${name}`, valueToken);
|
|
219
|
+
if (
|
|
220
|
+
[
|
|
221
|
+
"cookie",
|
|
222
|
+
"host",
|
|
223
|
+
"proxy-authorization",
|
|
224
|
+
"x-workspace-id",
|
|
225
|
+
"content-length",
|
|
226
|
+
"transfer-encoding",
|
|
227
|
+
"x-api-key",
|
|
228
|
+
].includes(name)
|
|
229
|
+
)
|
|
230
|
+
fail(
|
|
231
|
+
"UNSUPPORTED_CURL_HEADER",
|
|
232
|
+
`Unsupported example header: ${name}`,
|
|
233
|
+
valueToken,
|
|
234
|
+
);
|
|
235
|
+
if (name === "authorization") {
|
|
236
|
+
if (!/^Bearer(?:\s|$)/i.test(value.slice(split + 1).trim()))
|
|
237
|
+
fail(
|
|
238
|
+
"UNSUPPORTED_CURL_AUTH",
|
|
239
|
+
"Only Bearer API key authentication is supported",
|
|
240
|
+
valueToken,
|
|
241
|
+
);
|
|
242
|
+
headers[name] = "Bearer [REDACTED]";
|
|
243
|
+
} else headers[name] = value.slice(split + 1).trim();
|
|
244
|
+
} else if (flag === "-F" || flag === "--form") {
|
|
245
|
+
const split = value.indexOf("=");
|
|
246
|
+
if (split < 1)
|
|
247
|
+
fail("INVALID_CURL_SYNTAX", "Invalid multipart field", valueToken);
|
|
248
|
+
const name = value.slice(0, split);
|
|
249
|
+
let content = value.slice(split + 1);
|
|
250
|
+
const modelPlaceholder = name === "model" &&
|
|
251
|
+
["<model>", "<model-for-this-model>"].includes(content);
|
|
252
|
+
if (content.includes(";") || (content.startsWith("<") && !modelPlaceholder))
|
|
253
|
+
fail(
|
|
254
|
+
"UNSUPPORTED_CURL_FORM",
|
|
255
|
+
"Multipart modifiers and file-content expansion are not supported",
|
|
256
|
+
valueToken,
|
|
257
|
+
);
|
|
258
|
+
const file = content.startsWith("@");
|
|
259
|
+
if (file) content = content.slice(1);
|
|
260
|
+
if (content.startsWith('"') && content.endsWith('"'))
|
|
261
|
+
content = content.slice(1, -1);
|
|
262
|
+
if (file && !content)
|
|
263
|
+
fail("INVALID_CURL_SYNTAX", "Missing example file path", valueToken);
|
|
264
|
+
form.push(file ? { name, file: true } : { name, value: content });
|
|
265
|
+
} else {
|
|
266
|
+
if (data !== undefined)
|
|
267
|
+
fail(
|
|
268
|
+
"INVALID_CURL_SYNTAX",
|
|
269
|
+
"Repeated request data is not supported",
|
|
270
|
+
valueToken,
|
|
271
|
+
);
|
|
272
|
+
try {
|
|
273
|
+
data = JSON.parse(value);
|
|
274
|
+
} catch {
|
|
275
|
+
fail(
|
|
276
|
+
"INVALID_CURL_JSON",
|
|
277
|
+
"Example request data is not valid JSON; correct the source example",
|
|
278
|
+
valueToken,
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
if (!isObject(data))
|
|
282
|
+
fail(
|
|
283
|
+
"INVALID_CURL_JSON",
|
|
284
|
+
"Example JSON body must be an object",
|
|
285
|
+
valueToken,
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (!url) fail("INVALID_CURL_SYNTAX", "Missing request URL", tokens[0]);
|
|
290
|
+
modelUrl(url);
|
|
291
|
+
if (data !== undefined && form.length)
|
|
292
|
+
fail(
|
|
293
|
+
"INVALID_CURL_SYNTAX",
|
|
294
|
+
"Cannot mix JSON and multipart data",
|
|
295
|
+
tokens[0],
|
|
296
|
+
);
|
|
297
|
+
if (!headers.authorization)
|
|
298
|
+
fail("UNSUPPORTED_CURL_AUTH", "Missing Bearer API key header", tokens[0]);
|
|
299
|
+
method ??= data !== undefined || form.length ? "POST" : "GET";
|
|
300
|
+
if (!["GET", "POST"].includes(method))
|
|
301
|
+
fail(
|
|
302
|
+
"UNSUPPORTED_CURL_METHOD",
|
|
303
|
+
"Only GET and POST examples are supported",
|
|
304
|
+
tokens[0],
|
|
305
|
+
);
|
|
306
|
+
if (method === "GET" && (data !== undefined || form.length))
|
|
307
|
+
fail(
|
|
308
|
+
"INVALID_CURL_SYNTAX",
|
|
309
|
+
"GET examples cannot contain a request body",
|
|
310
|
+
tokens[0],
|
|
311
|
+
);
|
|
312
|
+
if (method === "POST" && data === undefined && !form.length)
|
|
313
|
+
fail("INVALID_CURL_SYNTAX", "POST example has no request body", tokens[0]);
|
|
314
|
+
if (
|
|
315
|
+
data !== undefined &&
|
|
316
|
+
!/^application\/json(?:\s*;|$)/i.test(headers["content-type"] || "")
|
|
317
|
+
)
|
|
318
|
+
fail(
|
|
319
|
+
"UNSUPPORTED_CURL_HEADER",
|
|
320
|
+
"JSON example requires Content-Type: application/json",
|
|
321
|
+
tokens[0],
|
|
322
|
+
);
|
|
323
|
+
if (form.length && headers["content-type"])
|
|
324
|
+
fail(
|
|
325
|
+
"UNSUPPORTED_CURL_HEADER",
|
|
326
|
+
"Multipart Content-Type must be generated with its boundary",
|
|
327
|
+
tokens[0],
|
|
328
|
+
);
|
|
329
|
+
return {
|
|
330
|
+
method,
|
|
331
|
+
url,
|
|
332
|
+
headers,
|
|
333
|
+
...(data !== undefined ? { json: data } : {}),
|
|
334
|
+
...(form.length ? { form } : {}),
|
|
335
|
+
notices,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function parseCurlExamples(source) {
|
|
340
|
+
if (typeof source !== "string" || !source.trim()) return [];
|
|
341
|
+
return commands(source).map(({ tokens, error }, index) => {
|
|
342
|
+
const base = { index: index + 1, line: tokens[0]?.line ?? 1 };
|
|
343
|
+
try {
|
|
344
|
+
if (error) throw error;
|
|
345
|
+
return { ...base, request: parse(tokens) };
|
|
346
|
+
} catch (error) {
|
|
347
|
+
if (!(error instanceof CLIError)) throw error;
|
|
348
|
+
return {
|
|
349
|
+
...base,
|
|
350
|
+
error: {
|
|
351
|
+
code: error.code,
|
|
352
|
+
message: error.message,
|
|
353
|
+
line: base.line,
|
|
354
|
+
...error.details,
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {parseCurlExamples} from './model-curl.js';
|
|
2
|
+
import {GATEWAY_ORIGIN, modelUrl} from './http.js';
|
|
3
|
+
import {isObject} from './catalog.js';
|
|
4
|
+
const canonical = path => path?.replace(/\/+$/, '').replace(/\/images\/edits$/, '/images/edit');
|
|
5
|
+
const paths = row => [...(row.operations ?? []).map(o=>o.endpoint), ...(row.upstreamPath ?? []).filter(p=>p.method?.toUpperCase()==='POST').map(p=>p.path)];
|
|
6
|
+
const scoped = (f,row) => f.active !== false && (!f.provider || f.provider.toLowerCase()===row.provider.toLowerCase()) && (!f.model || f.model===row.model);
|
|
7
|
+
function formats(f, row, source) {
|
|
8
|
+
let examples;
|
|
9
|
+
if (!f.curlExample?.trim() && !isObject(f.requestTemplate)) {
|
|
10
|
+
let body=f.requestBody;
|
|
11
|
+
const responseLike=v=>isObject(v) && ['choices','candidates','usage','output','data','response','result'].some(k=>k in v);
|
|
12
|
+
if (responseLike(body)) body=undefined;
|
|
13
|
+
if (!isObject(body) && f.prompt?.trim().startsWith('{')) {
|
|
14
|
+
try { body=JSON.parse(f.prompt); } catch { return [{index:1,line:1,source,playgroundId:f.id,error:{code:'INVALID_INPUT',message:'Configured Playground prompt contains invalid request JSON'}}]; }
|
|
15
|
+
if(responseLike(body)) body=undefined;
|
|
16
|
+
}
|
|
17
|
+
if(!isObject(body) && f.prompt?.trim() && !f.prompt.trim().startsWith('{')) {
|
|
18
|
+
if (/\/(chat\/completions|messages)$/.test(f.endpointPath ?? '')) body={messages:[{role:'user',content:f.prompt}]};
|
|
19
|
+
else if (/\/images(?:\/(?:generations|edits?))?$/.test(f.endpointPath ?? '')) body={prompt:f.prompt};
|
|
20
|
+
}
|
|
21
|
+
if(isObject(body)) f={...f,requestTemplate:body};
|
|
22
|
+
}
|
|
23
|
+
if (f.curlExample?.trim()) examples=parseCurlExamples(f.curlExample);
|
|
24
|
+
else if (isObject(f.requestTemplate) && f.endpointPath) {
|
|
25
|
+
const json=structuredClone(f.requestTemplate);
|
|
26
|
+
json.model ??= row.model;
|
|
27
|
+
examples=[{index:1,line:1,request:{method:'POST',url:GATEWAY_ORIGIN+f.endpointPath,headers:{'content-type':'application/json'},json,notices:[]}}];
|
|
28
|
+
} else return [];
|
|
29
|
+
if (f.queryEndpointPath && !examples.some(e=>e.request?.method==='GET')) examples.push({index:examples.length+1,line:1,request:{method:'GET',url:GATEWAY_ORIGIN+f.queryEndpointPath,headers:{},notices:[]}});
|
|
30
|
+
return examples.map(e=>({...e,source,playgroundId:f.id,
|
|
31
|
+
// Schemas belong to a specific request, never to a polling operation.
|
|
32
|
+
...(e.request && e.request.method!=='GET' && (!f.endpointPath || canonical(modelUrl(e.request.url).path)===canonical(f.endpointPath)) ? {jsonSchema:f.jsonSchema,parameterSchema:f.parameterSchema} : {})}));
|
|
33
|
+
}
|
|
34
|
+
export function resolveModelExamples(row, playgrounds) {
|
|
35
|
+
// Retain compatibility with older catalog servers without supplier metadata.
|
|
36
|
+
if (!row.providerKind && !row.modelSource && !row.importedInterface) return null;
|
|
37
|
+
const community=row.providerKind==='community'||row.modelSource==='p2p';
|
|
38
|
+
const candidate=row.importedInterface;
|
|
39
|
+
if (!community && candidate?.status==='available') {
|
|
40
|
+
const selected=(candidate.formats ?? []).filter(f=>scoped(f,row)).flatMap(f=>formats(f,row,'candidate'));
|
|
41
|
+
if(selected.length) return selected;
|
|
42
|
+
}
|
|
43
|
+
const configured=paths(row);
|
|
44
|
+
const pg=(row.playgrounds ?? playgrounds).filter(f=>scoped(f,row)).flatMap(f=>{
|
|
45
|
+
const examples=formats(f,row,'playground');
|
|
46
|
+
const compatible=(examples.some(e=>e.error) && configured.some(p=>canonical(p)===canonical(f.endpointPath))) || examples.some(e=>e.request?.method==='POST' && (configured.length
|
|
47
|
+
? configured.some(p=>canonical(p)===canonical(modelUrl(e.request.url).path))
|
|
48
|
+
: !!f.id && f.id!=='00000000-0000-0000-0000-000000000000'));
|
|
49
|
+
return compatible ? examples : [];
|
|
50
|
+
});
|
|
51
|
+
if(pg.length) return pg;
|
|
52
|
+
if(community) {
|
|
53
|
+
const parsed=parseCurlExamples(row.curlExample);
|
|
54
|
+
if(parsed.length) return parsed.map(e=>({...e,source:'price',...(e.request && e.request.method!=='GET' && configured.some(p=>canonical(p)===canonical(modelUrl(e.request.url).path)) && isObject(row.bodySchema?.properties) ? {jsonSchema:row.bodySchema}: {})}));
|
|
55
|
+
if(configured.length===1 && isObject(row.bodySchema) && !row.bodySchema.properties) return formats({endpointPath:configured[0],requestTemplate:row.bodySchema},row,'price');
|
|
56
|
+
}
|
|
57
|
+
return [{index:1,line:1,source:community?'price':'playground',error:{code:'EXAMPLE_NOT_FOUND',message:'No compatible executable model materials are configured for this supplier'}}];
|
|
58
|
+
}
|