openany-cli-dev 0.1.2 → 0.1.3
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 +13 -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 +6 -2
- package/skills/openany-provider/SKILL.zh-CN.md +6 -2
- package/skills/openany-provider/references/apis.md +5 -5
- package/skills/openany-provider/references/apis.zh-CN.md +4 -4
- package/skills/openany-provider/references/application.md +1 -1
- package/skills/openany-provider/references/application.zh-CN.md +1 -1
- package/skills/openany-provider/references/connections.md +8 -8
- package/skills/openany-provider/references/connections.zh-CN.md +7 -7
- package/skills/openany-provider/references/imports.md +3 -3
- package/skills/openany-provider/references/imports.zh-CN.md +3 -3
- package/skills/openany-provider/references/models.md +8 -8
- package/skills/openany-provider/references/models.zh-CN.md +5 -5
- package/skills/openany-provider/references/publishing.md +3 -3
- package/skills/openany-provider/references/publishing.zh-CN.md +4 -4
- package/skills/openany-provider/references/reviews.md +2 -2
- 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 +12 -12
- package/skills/openany-provider/templates/seller-agent-api-import-template.json +16 -16
- package/src/cli.js +12 -4
- package/src/provider-connections.js +2 -2
- package/src/provider-imports.js +5 -4
- package/src/provider-model-import-v2.js +10 -1
- package/src/provider.js +5 -3
- package/src/seller-fields.js +57 -0
package/src/cli.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sellerOutput, sellerText } from "./seller-fields.js";
|
|
1
2
|
import packageInfo from "../package.json" with { type: "json" };
|
|
2
3
|
import { tmpdir } from "node:os";
|
|
3
4
|
import { join } from "node:path";
|
|
@@ -45,7 +46,7 @@ Model execution uses the OpenAny gateway with the path and query from curlExampl
|
|
|
45
46
|
seller status [--application ID]
|
|
46
47
|
seller applications list|create --file REGISTRATION_JSON --operation NAME
|
|
47
48
|
seller connections list|get|create --application ID [--id ID]
|
|
48
|
-
create --file JSON --operation NAME [--stdin] (or
|
|
49
|
+
create --file JSON --operation NAME [--stdin] (or OPENANY_CONNECTION_API_KEY)
|
|
49
50
|
create --gui --operation NAME [-j] (native connection dialog; macOS/Windows)
|
|
50
51
|
seller models|apis list|get|create|update|verify|publish|unpublish --application ID
|
|
51
52
|
[--id ID] [--file PATH | --input JSON] [--operation NAME] [--verification-id ID]
|
|
@@ -492,15 +493,23 @@ export async function main(
|
|
|
492
493
|
stdin = process.stdin,
|
|
493
494
|
} = {},
|
|
494
495
|
) {
|
|
496
|
+
let seller = argv[0] === "seller";
|
|
495
497
|
const secrets = [
|
|
496
498
|
env.OPENANY_DEV_API_KEY,
|
|
499
|
+
env.OPENANY_CONNECTION_API_KEY,
|
|
497
500
|
env.OPENANY_DEV_UPSTREAM_API_KEY,
|
|
498
501
|
env.OPENANY_DEV_ACCESS_TOKEN,
|
|
499
502
|
env.OPENANY_DEV_SESSION_TOKEN,
|
|
500
503
|
env.OPENANY_DEV_WALLET_PRIVATE_KEY,
|
|
501
504
|
].filter(Boolean);
|
|
505
|
+
const format = (value, space) => {
|
|
506
|
+
if (!seller) return redact(value, secrets, space);
|
|
507
|
+
const sellerSecrets = secrets.filter(secret => typeof secret === "string").map(sellerText);
|
|
508
|
+
return redact(sellerOutput(value), [...secrets, ...sellerSecrets], space);
|
|
509
|
+
};
|
|
502
510
|
try {
|
|
503
511
|
const { args, options } = parseArgs(argv);
|
|
512
|
+
seller = args[0] === "seller";
|
|
504
513
|
if (options.version || options.help || !args.length) {
|
|
505
514
|
const value = options.version ? { version: packageInfo.version } : { help: HELP };
|
|
506
515
|
const text = options.json
|
|
@@ -589,8 +598,7 @@ export async function main(
|
|
|
589
598
|
);
|
|
590
599
|
return 0;
|
|
591
600
|
}
|
|
592
|
-
const content =
|
|
593
|
-
bytes ?? redact(result, secrets, options.json ? 0 : 2) + "\n";
|
|
601
|
+
const content = bytes ?? format(result, options.json ? 0 : 2) + "\n";
|
|
594
602
|
if (options.output) {
|
|
595
603
|
await writeFile(options.output, content, { flag: "wx", mode: 0o600 });
|
|
596
604
|
stdout.write(
|
|
@@ -599,7 +607,7 @@ export async function main(
|
|
|
599
607
|
} else stdout.write(content);
|
|
600
608
|
return 0;
|
|
601
609
|
} catch (error) {
|
|
602
|
-
stderr.write(
|
|
610
|
+
stderr.write(format(errorRecord(error)) + "\n");
|
|
603
611
|
return 1;
|
|
604
612
|
}
|
|
605
613
|
}
|
|
@@ -126,7 +126,7 @@ export async function runConnections(action, client, ctx) {
|
|
|
126
126
|
"Specify a supported authentication type explicitly",
|
|
127
127
|
);
|
|
128
128
|
if (input.authType.toLowerCase() !== "none") {
|
|
129
|
-
let key = gui ? gui.secret : ctx.env.OPENANY_DEV_UPSTREAM_API_KEY;
|
|
129
|
+
let key = gui ? gui.secret : (ctx.env.OPENANY_CONNECTION_API_KEY || ctx.env.OPENANY_DEV_UPSTREAM_API_KEY);
|
|
130
130
|
if (ctx.options.stdin) {
|
|
131
131
|
key = "";
|
|
132
132
|
for await (const chunk of ctx.stdin) {
|
|
@@ -143,7 +143,7 @@ export async function runConnections(action, client, ctx) {
|
|
|
143
143
|
if (!key)
|
|
144
144
|
throw new CLIError(
|
|
145
145
|
"UPSTREAM_CREDENTIAL_REQUIRED",
|
|
146
|
-
"Set
|
|
146
|
+
"Set OPENANY_CONNECTION_API_KEY or provide the key with --stdin; never put it in configuration files",
|
|
147
147
|
);
|
|
148
148
|
ctx.secrets.push(key);
|
|
149
149
|
input.apiKey = key;
|
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 (
|
|
@@ -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.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";
|
|
@@ -15,17 +16,18 @@ export async function runProvider(args, ctx) {
|
|
|
15
16
|
"Seller commands require an account session and do not accept public/workspace/dry-run flags",
|
|
16
17
|
);
|
|
17
18
|
const input = ctx.input;
|
|
19
|
+
const normalize = ["models", "apis", "imports"].includes(group) ? sellerInput : value => value;
|
|
18
20
|
ctx.input = async () => {
|
|
19
21
|
if (ctx.options.file !== undefined && ctx.options.input !== undefined)
|
|
20
22
|
throw new CLIError("INVALID_INPUT", "Choose --file or --input");
|
|
21
23
|
if (ctx.options.file !== undefined)
|
|
22
|
-
return readProviderJSON(ctx.options.file);
|
|
24
|
+
return normalize(await readProviderJSON(ctx.options.file));
|
|
23
25
|
if (ctx.options.input !== undefined)
|
|
24
|
-
return parseProviderJSON(ctx.options.input);
|
|
26
|
+
return normalize(parseProviderJSON(ctx.options.input));
|
|
25
27
|
const value = await input();
|
|
26
28
|
if (value === undefined)
|
|
27
29
|
throw new CLIError("INPUT_REQUIRED", "Supply JSON configuration with --file PATH or --input JSON (choose one)");
|
|
28
|
-
return value;
|
|
30
|
+
return normalize(value);
|
|
29
31
|
};
|
|
30
32
|
let client;
|
|
31
33
|
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
|
+
}
|