openany-cli-dev 0.1.2 → 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/README.md +23 -13
- package/package.json +1 -1
- package/skills/openany/calls.md +1 -1
- package/skills/openany/setup.md +88 -78
- package/skills/openany/topups.md +2 -2
- package/skills/openany-provider/SKILL.md +13 -5
- package/skills/openany-provider/SKILL.zh-CN.md +13 -5
- package/skills/openany-provider/references/apis.md +7 -5
- package/skills/openany-provider/references/apis.zh-CN.md +6 -4
- package/skills/openany-provider/references/application.md +2 -2
- package/skills/openany-provider/references/application.zh-CN.md +2 -2
- package/skills/openany-provider/references/connections.md +9 -9
- package/skills/openany-provider/references/connections.zh-CN.md +8 -8
- package/skills/openany-provider/references/hermes-files.md +131 -0
- package/skills/openany-provider/references/imports.md +5 -3
- package/skills/openany-provider/references/imports.zh-CN.md +5 -3
- package/skills/openany-provider/references/login.md +3 -3
- package/skills/openany-provider/references/login.zh-CN.md +3 -3
- package/skills/openany-provider/references/model-import.md +1 -1
- package/skills/openany-provider/references/model-import.zh-CN.md +1 -1
- package/skills/openany-provider/references/models.md +11 -9
- package/skills/openany-provider/references/models.zh-CN.md +8 -6
- package/skills/openany-provider/references/publishing.md +9 -5
- package/skills/openany-provider/references/publishing.zh-CN.md +9 -7
- package/skills/openany-provider/references/reviews.md +4 -2
- package/skills/openany-provider/references/reviews.zh-CN.md +2 -0
- package/skills/openany-provider/templates/bindings.json +1 -1
- package/skills/openany-provider/templates/models-v2.json +12 -12
- package/skills/openany-provider/templates/models.json +2 -2
- package/skills/openany-provider/templates/provider-agent-api-template.json +13 -13
- package/skills/openany-provider/templates/seller-agent-api-import-template.json +17 -17
- package/src/cli.js +15 -4
- package/src/http.js +7 -0
- package/src/poll-artifacts.js +77 -0
- package/src/provider-api-import-v2.js +1 -1
- package/src/provider-connections.js +2 -2
- package/src/provider-import-format.js +5 -5
- package/src/provider-imports.js +6 -5
- package/src/provider-model-import-v2.js +10 -1
- package/src/provider-models.js +3 -3
- package/src/provider-state.js +31 -14
- package/src/provider.js +9 -3
- package/src/seller-fields.js +57 -0
|
@@ -18,7 +18,7 @@ export function manifest(value, name, type) {
|
|
|
18
18
|
"IMPORT_FORMAT",
|
|
19
19
|
`${name} requires schemaVersion 1 and at most 100 items`,
|
|
20
20
|
);
|
|
21
|
-
assertNoSecrets(value);
|
|
21
|
+
assertNoSecrets(value, "$", type);
|
|
22
22
|
const seen = new Set();
|
|
23
23
|
for (const item of value.items) {
|
|
24
24
|
if (
|
|
@@ -77,7 +77,7 @@ export function parseImport(
|
|
|
77
77
|
document,
|
|
78
78
|
metadata = { schemaVersion: 1, items: [] },
|
|
79
79
|
) {
|
|
80
|
-
assertNoSecrets(document);
|
|
80
|
+
assertNoSecrets(document, "$", type);
|
|
81
81
|
const websiteModel = type === "model" && (document?.schemaVersion === modelImportVersion || document?.models !== undefined);
|
|
82
82
|
if (websiteModel)
|
|
83
83
|
document = modelImportV2(document);
|
|
@@ -86,13 +86,13 @@ export function parseImport(
|
|
|
86
86
|
);
|
|
87
87
|
let items = [];
|
|
88
88
|
if (type === "model") {
|
|
89
|
-
items = manifest(document, "Model manifest").map((item) => {
|
|
89
|
+
items = manifest(document, "Model manifest", type).map((item) => {
|
|
90
90
|
if (
|
|
91
91
|
Object.keys(item).some((k) => !["itemId", "configuration"].includes(k))
|
|
92
92
|
)
|
|
93
93
|
throw new CLIError("IMPORT_FORMAT", "Unexpected model item field");
|
|
94
94
|
const c = item.configuration;
|
|
95
|
-
checkConfiguration(c);
|
|
95
|
+
checkConfiguration(c, type);
|
|
96
96
|
if (!object(c.price) || !Array.isArray(c.routes) || !c.routes.length)
|
|
97
97
|
throw new CLIError(
|
|
98
98
|
"IMPORT_FORMAT",
|
|
@@ -183,7 +183,7 @@ export function parseImport(
|
|
|
183
183
|
"Metadata cannot override the source method or path",
|
|
184
184
|
{ itemId },
|
|
185
185
|
);
|
|
186
|
-
checkConfiguration(extra);
|
|
186
|
+
checkConfiguration(extra, type);
|
|
187
187
|
const security = operation.security ?? document.security;
|
|
188
188
|
items.push({
|
|
189
189
|
itemId,
|
package/src/provider-imports.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sellerInput } from "./seller-fields.js";
|
|
1
2
|
import { apiImportVersion, validateApiImportCategories } from "./provider-api-import-v2.js";
|
|
2
3
|
import { modelImportVersion } from "./provider-model-import-v2.js";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
@@ -219,11 +220,11 @@ export async function runImports(action, client, ctx) {
|
|
|
219
220
|
if (o.type === "model") await client.request("/schemas/model-import");
|
|
220
221
|
const document = await ctx.input();
|
|
221
222
|
const metadata = o["metadata-file"]
|
|
222
|
-
? await readProviderJSON(o["metadata-file"])
|
|
223
|
+
? sellerInput(await readProviderJSON(o["metadata-file"]))
|
|
223
224
|
: undefined;
|
|
224
225
|
let items = parseImport(o.type, document, metadata);
|
|
225
226
|
if (o["bindings-file"])
|
|
226
|
-
items = applyBindings(items, await readProviderJSON(o["bindings-file"]), o.type);
|
|
227
|
+
items = applyBindings(items, sellerInput(await readProviderJSON(o["bindings-file"])), o.type);
|
|
227
228
|
batch = {
|
|
228
229
|
id: randomUUID(),
|
|
229
230
|
userId: client.identity.userId,
|
|
@@ -259,7 +260,7 @@ export async function runImports(action, client, ctx) {
|
|
|
259
260
|
const changed = structuredClone(batch.items);
|
|
260
261
|
if (o["metadata-file"])
|
|
261
262
|
for (const entry of manifest(
|
|
262
|
-
await readProviderJSON(o["metadata-file"]),
|
|
263
|
+
sellerInput(await readProviderJSON(o["metadata-file"])),
|
|
263
264
|
"Metadata",
|
|
264
265
|
batch.type,
|
|
265
266
|
)) {
|
|
@@ -298,7 +299,7 @@ export async function runImports(action, client, ctx) {
|
|
|
298
299
|
validateApiImportCategories(item.configuration.categories, item.itemId);
|
|
299
300
|
}
|
|
300
301
|
const bound = o["bindings-file"]
|
|
301
|
-
? applyBindings(changed, await readProviderJSON(o["bindings-file"]), batch.type)
|
|
302
|
+
? applyBindings(changed, sellerInput(await readProviderJSON(o["bindings-file"])), batch.type)
|
|
302
303
|
: changed;
|
|
303
304
|
for (let i = 0; i < bound.length; i++)
|
|
304
305
|
if (
|
|
@@ -311,7 +312,7 @@ export async function runImports(action, client, ctx) {
|
|
|
311
312
|
"Completed or unknown items cannot change",
|
|
312
313
|
);
|
|
313
314
|
for (let i = 0; i < bound.length; i++) {
|
|
314
|
-
if (bound[i].configuration) checkConfiguration(bound[i].configuration);
|
|
315
|
+
if (bound[i].configuration) checkConfiguration(bound[i].configuration, batch.type);
|
|
315
316
|
if (
|
|
316
317
|
digest(bound[i].configuration) !==
|
|
317
318
|
digest(batch.items[i].configuration)
|
|
@@ -41,7 +41,16 @@ export function modelImportV2(document) {
|
|
|
41
41
|
if (!Object.hasOwn(price, key)) continue;
|
|
42
42
|
const sourceKey = key === "upstreamPath" ? "endpoints" : key;
|
|
43
43
|
if (!Array.isArray(price[key])) throw new CLIError("IMPORT_FORMAT", `${path}.${sourceKey} must be an array`);
|
|
44
|
-
price[key] = price[key].map((value, i) =>
|
|
44
|
+
price[key] = price[key].map((value, i) => {
|
|
45
|
+
const entryPath = `${path}.${sourceKey}[${i}]`;
|
|
46
|
+
if (group === "endpoint" && object(value) && Object.hasOwn(value, "servicePath")) {
|
|
47
|
+
if (Object.hasOwn(value, "upstreamPath"))
|
|
48
|
+
throw new CLIError("IMPORT_FORMAT", `${entryPath}: supply servicePath only once`);
|
|
49
|
+
const { servicePath, ...entry } = value;
|
|
50
|
+
value = { ...entry, upstreamPath: servicePath };
|
|
51
|
+
}
|
|
52
|
+
return rename(value, fields[group], entryPath);
|
|
53
|
+
});
|
|
45
54
|
}
|
|
46
55
|
const publicModel = Object.hasOwn(price, "publicModel") ? price.publicModel : price.model;
|
|
47
56
|
if (typeof price.model !== "string" || !price.model.trim() || typeof publicModel !== "string" || !publicModel.trim())
|
package/src/provider-models.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CLIError, requireValue } from "./errors.js";
|
|
2
2
|
import { assertNoSecrets, uuid } from "./provider-state.js";
|
|
3
|
-
export function checkConfiguration(value) {
|
|
4
|
-
assertNoSecrets(value);
|
|
3
|
+
export function checkConfiguration(value, kind) {
|
|
4
|
+
assertNoSecrets(value, "$", kind);
|
|
5
5
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
6
6
|
throw new CLIError("INVALID_INPUT", "Configuration must be an object");
|
|
7
7
|
for (const o of [value, value.price])
|
|
@@ -71,7 +71,7 @@ export async function runResource(kind, action, client, ctx) {
|
|
|
71
71
|
);
|
|
72
72
|
if (action === "create" || action === "update") {
|
|
73
73
|
const input = await ctx.input();
|
|
74
|
-
checkConfiguration(input);
|
|
74
|
+
checkConfiguration(input, kind);
|
|
75
75
|
const capabilities = await client.capabilities(kind);
|
|
76
76
|
let current;
|
|
77
77
|
if (action === "update") {
|
package/src/provider-state.js
CHANGED
|
@@ -13,13 +13,21 @@ export const uuid = (value, name = "id") => {
|
|
|
13
13
|
throw new CLIError("INVALID_INPUT", `${name} must be a UUID`);
|
|
14
14
|
return value;
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
const authorizationPlaceholder = /^Bearer[ \t]+(?:YOUR_API_KEY|\$[A-Za-z_]\w*|\$\{[A-Za-z_]\w*\})$/i;
|
|
17
|
+
const apiSampleHeaders = /^\$\.(?:(?:apis\[\d+\]|items\[\d+\]\.configuration)\.)?config\.(?:samples|requestResponseExamples)\[\d+\]\.request\.headers$/;
|
|
18
|
+
const apiDescription = /^\$\.(?:apis\[\d+\]\.apiDescription|(?:(?:items\[\d+\]\.configuration|info|paths\.\/.*\.(?:get|post|put|patch|delete))\.)?description)$/;
|
|
19
|
+
|
|
20
|
+
export function assertNoSecrets(value, path = "$", kind) {
|
|
17
21
|
if (Array.isArray(value)) {
|
|
18
|
-
value.forEach((v, i) => assertNoSecrets(v, `${path}[${i}]
|
|
22
|
+
value.forEach((v, i) => assertNoSecrets(v, `${path}[${i}]`, kind));
|
|
19
23
|
return;
|
|
20
24
|
}
|
|
21
25
|
if (value && typeof value === "object")
|
|
22
26
|
for (const [k, v] of Object.entries(value)) {
|
|
27
|
+
if (kind === "api" && /^authorization$/i.test(k) &&
|
|
28
|
+
apiSampleHeaders.test(path) && typeof v === "string" && authorizationPlaceholder.test(v)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
23
31
|
// OpenAPI uses arbitrary scheme names (including "apiKey") as map keys.
|
|
24
32
|
// Only schema declarations and scope arrays get this exception; their
|
|
25
33
|
// children are still inspected, and credential values remain forbidden.
|
|
@@ -46,19 +54,28 @@ export function assertNoSecrets(value, path = "$") {
|
|
|
46
54
|
"Local credential scan rejected this field. Remove authentication headers and credentials from documents; configure authentication through secure connection input.",
|
|
47
55
|
{ field: `${path}.${k}`, stage: "local" },
|
|
48
56
|
);
|
|
49
|
-
assertNoSecrets(v, `${path}.${k}
|
|
57
|
+
assertNoSecrets(v, `${path}.${k}`, kind);
|
|
50
58
|
}
|
|
51
|
-
else if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
else if (typeof value === "string") {
|
|
60
|
+
const modelCurl = kind === "model" &&
|
|
61
|
+
/^\$\.(?:price\.curlExample|items\[\d+\]\.configuration\.price\.curlExample|models\[\d+\]\.requestCurlExample)$/.test(path);
|
|
62
|
+
const curlExample = modelCurl || (kind === "api" && apiDescription.test(path));
|
|
63
|
+
// Ignore only a complete placeholder header while scanning. Send the original example.
|
|
64
|
+
const scanned = curlExample
|
|
65
|
+
? value.replace(/(?:^|\s)(?:-H\s*|--header(?:\s+|=))(["'])Authorization:[ \t]*Bearer[ \t]+(?:YOUR_API_KEY|\$[A-Za-z_]\w*|\$\{[A-Za-z_]\w*\})\1(?=\s|$)/gi, " ")
|
|
66
|
+
: value;
|
|
67
|
+
if (
|
|
68
|
+
/\bBearer\s+[\w.+\/-]+/i.test(scanned) ||
|
|
69
|
+
/[?&](?:api[_-]?key|token|secret|password|key)=/i.test(scanned) ||
|
|
70
|
+
/^https?:\/\/[^/]+:[^/]+@/i.test(scanned) ||
|
|
71
|
+
(curlExample && /(?:^|\s)(?:-H\s*|--header(?:\s+|=))["']?Authorization:/i.test(scanned))
|
|
72
|
+
)
|
|
73
|
+
throw new CLIError(
|
|
74
|
+
"SECRET_IN_DOCUMENT",
|
|
75
|
+
"Local credential scan rejected possible credentials. Use a supported Authorization placeholder in cURL examples and configure actual authentication through secure connection input.",
|
|
76
|
+
{ field: path, stage: "local" },
|
|
77
|
+
);
|
|
78
|
+
}
|
|
62
79
|
}
|
|
63
80
|
export function receipt(value) {
|
|
64
81
|
const out = value?.price?.id ? { id: value.price.id } : {};
|
package/src/provider.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sellerInput } from "./seller-fields.js";
|
|
1
2
|
import { ProviderClient } from "./provider-client.js";
|
|
2
3
|
import { CLIError } from "./errors.js";
|
|
3
4
|
import { runProfile } from "./provider-profile.js";
|
|
@@ -7,6 +8,10 @@ import { runReviews } from "./provider-reviews.js";
|
|
|
7
8
|
import { runImports } from "./provider-imports.js";
|
|
8
9
|
import { parseProviderJSON, readProviderJSON } from "./provider-json.js";
|
|
9
10
|
export async function runProvider(args, ctx) {
|
|
11
|
+
if (args[1] === "tasks") {
|
|
12
|
+
const { uploadPollArtifact } = await import("./poll-artifacts.js");
|
|
13
|
+
return uploadPollArtifact(args, ctx);
|
|
14
|
+
}
|
|
10
15
|
const group = args[1],
|
|
11
16
|
action = args[2] || "list";
|
|
12
17
|
if (ctx.options.public || ctx.options.workspace || ctx.options["dry-run"])
|
|
@@ -15,17 +20,18 @@ export async function runProvider(args, ctx) {
|
|
|
15
20
|
"Seller commands require an account session and do not accept public/workspace/dry-run flags",
|
|
16
21
|
);
|
|
17
22
|
const input = ctx.input;
|
|
23
|
+
const normalize = ["models", "apis", "imports"].includes(group) ? sellerInput : value => value;
|
|
18
24
|
ctx.input = async () => {
|
|
19
25
|
if (ctx.options.file !== undefined && ctx.options.input !== undefined)
|
|
20
26
|
throw new CLIError("INVALID_INPUT", "Choose --file or --input");
|
|
21
27
|
if (ctx.options.file !== undefined)
|
|
22
|
-
return readProviderJSON(ctx.options.file);
|
|
28
|
+
return normalize(await readProviderJSON(ctx.options.file));
|
|
23
29
|
if (ctx.options.input !== undefined)
|
|
24
|
-
return parseProviderJSON(ctx.options.input);
|
|
30
|
+
return normalize(parseProviderJSON(ctx.options.input));
|
|
25
31
|
const value = await input();
|
|
26
32
|
if (value === undefined)
|
|
27
33
|
throw new CLIError("INPUT_REQUIRED", "Supply JSON configuration with --file PATH or --input JSON (choose one)");
|
|
28
|
-
return value;
|
|
34
|
+
return normalize(value);
|
|
29
35
|
};
|
|
30
36
|
let client;
|
|
31
37
|
try {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { CLIError } from "./errors.js";
|
|
2
|
+
|
|
3
|
+
const fields = {
|
|
4
|
+
expectedConnectionRevision: "expectedUpstreamRevision",
|
|
5
|
+
connectionId: "upstreamKeyId",
|
|
6
|
+
connectionRevision: "upstreamRevision",
|
|
7
|
+
servicePathTemplate: "upstreamPathTemplate",
|
|
8
|
+
servicePath: "upstreamPath",
|
|
9
|
+
serviceProtocol: "upstreamProtocol",
|
|
10
|
+
};
|
|
11
|
+
const displays = Object.fromEntries(Object.entries(fields).map(([seller, internal]) => [internal, seller]));
|
|
12
|
+
const inputContainers = ["price", "routes", "items", "data", "configuration"];
|
|
13
|
+
|
|
14
|
+
export function sellerInput(value) {
|
|
15
|
+
if (Array.isArray(value)) return value.map(sellerInput);
|
|
16
|
+
if (!value || typeof value !== "object") return value;
|
|
17
|
+
const result = { ...value };
|
|
18
|
+
for (const [seller, internal] of Object.entries(fields)) {
|
|
19
|
+
if (!Object.hasOwn(value, seller)) continue;
|
|
20
|
+
if (Object.hasOwn(value, internal))
|
|
21
|
+
throw new CLIError("INVALID_INPUT", `Supply ${seller} only once`, { field: seller });
|
|
22
|
+
result[internal] = value[seller];
|
|
23
|
+
delete result[seller];
|
|
24
|
+
}
|
|
25
|
+
// Traverse configuration envelopes only. Request data, schemas, and samples
|
|
26
|
+
// can contain arbitrary business field names and must pass through unchanged.
|
|
27
|
+
for (const key of inputContainers) {
|
|
28
|
+
if (Object.hasOwn(value, key)) result[key] = sellerInput(value[key]);
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function sellerText(value) {
|
|
34
|
+
return value.replace(/\w*upstream\w*|上游(?:连接)?/gi, word => {
|
|
35
|
+
if (word.startsWith("上游")) return word === "上游连接" ? "连接" : "服务";
|
|
36
|
+
if (Object.hasOwn(displays, word)) return displays[word];
|
|
37
|
+
if (word === "OPENANY_DEV_UPSTREAM_API_KEY") return "OPENANY_CONNECTION_API_KEY";
|
|
38
|
+
return word
|
|
39
|
+
.replace(/UPSTREAM_KEY_/g, "CONNECTION_")
|
|
40
|
+
.replace(/upstream_key_/g, "connection_")
|
|
41
|
+
.replace(/upstreamKey/g, "connection")
|
|
42
|
+
.replace(/Upstream/g, "Service")
|
|
43
|
+
.replace(/UPSTREAM/g, "SERVICE")
|
|
44
|
+
.replace(/upstream/gi, "service");
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function sellerOutput(value) {
|
|
49
|
+
if (typeof value === "string") return sellerText(value);
|
|
50
|
+
if (Array.isArray(value)) return value.map(sellerOutput);
|
|
51
|
+
if (!value || typeof value !== "object") return value;
|
|
52
|
+
// Prefer an existing seller-facing name if a receipt contains both forms.
|
|
53
|
+
return Object.fromEntries(Object.entries(value).flatMap(([key, child]) => {
|
|
54
|
+
const label = sellerText(key);
|
|
55
|
+
return label !== key && Object.hasOwn(value, label) ? [] : [[label, sellerOutput(child)]];
|
|
56
|
+
}));
|
|
57
|
+
}
|