openany-cli-dev 0.0.0-stage → 0.1.1
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 +472 -2
- package/bin/openany.js +3 -0
- package/package.json +27 -4
- package/skills/openany/SKILL.md +353 -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/apis.zh-CN.md +55 -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 +3 -0
- package/skills/openany-provider/references/auth.zh-CN.md +3 -0
- package/skills/openany-provider/references/connections.md +36 -0
- package/skills/openany-provider/references/connections.zh-CN.md +36 -0
- package/skills/openany-provider/references/imports.md +57 -0
- package/skills/openany-provider/references/imports.zh-CN.md +57 -0
- package/skills/openany-provider/references/listing.md +29 -0
- package/skills/openany-provider/references/listing.zh-CN.md +11 -0
- package/skills/openany-provider/references/login.md +57 -0
- package/skills/openany-provider/references/login.zh-CN.md +57 -0
- package/skills/openany-provider/references/model-import.md +11 -0
- package/skills/openany-provider/references/model-import.zh-CN.md +11 -0
- package/skills/openany-provider/references/models.md +107 -0
- package/skills/openany-provider/references/models.zh-CN.md +68 -0
- package/skills/openany-provider/references/publishing.md +40 -0
- package/skills/openany-provider/references/publishing.zh-CN.md +40 -0
- package/skills/openany-provider/references/reviews.md +22 -0
- package/skills/openany-provider/references/reviews.zh-CN.md +20 -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 +822 -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 +605 -0
- package/src/config.js +260 -0
- package/src/errors.js +53 -0
- package/src/http.js +238 -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/tasks.js +53 -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
package/src/setup.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { CLIError } from "./errors.js";
|
|
2
|
+
import { configurationStatus } from "./config.js";
|
|
3
|
+
import { terminalInput } from "./prompt.js";
|
|
4
|
+
import { walletAddressFromPrivateKey } from "./wallet.js";
|
|
5
|
+
|
|
6
|
+
export async function runSetup(ctx) {
|
|
7
|
+
const { stdin, stderr, store, options, secrets } = ctx;
|
|
8
|
+
if (options.gui) return runGuiSetup(ctx);
|
|
9
|
+
if (
|
|
10
|
+
!stdin.isTTY || options.json || options["non-interactive"] ||
|
|
11
|
+
options.prepare || options.scenario === "payment"
|
|
12
|
+
)
|
|
13
|
+
return configurationStatus(store, options);
|
|
14
|
+
|
|
15
|
+
const state = await store.read();
|
|
16
|
+
const local = state.settings || {};
|
|
17
|
+
const invalid = (message) => {
|
|
18
|
+
throw new CLIError("INVALID_INPUT", message);
|
|
19
|
+
};
|
|
20
|
+
async function ask(
|
|
21
|
+
label,
|
|
22
|
+
{ fallback = "", hidden = false, validate = (v) => v } = {},
|
|
23
|
+
) {
|
|
24
|
+
const hint = !fallback ? "" : hidden
|
|
25
|
+
? " (already configured; press Enter to keep)" : ` (press Enter to keep ${fallback})`;
|
|
26
|
+
for (;;) {
|
|
27
|
+
const entered = await terminalInput(stdin, stderr, label + hint, {
|
|
28
|
+
hidden,
|
|
29
|
+
});
|
|
30
|
+
const value = entered || fallback;
|
|
31
|
+
if (hidden && value) secrets.push(value);
|
|
32
|
+
try {
|
|
33
|
+
return validate(value);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (!(error instanceof CLIError)) throw error;
|
|
36
|
+
stderr.write(`${error.message}\n`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
let scenario = options.scenario;
|
|
41
|
+
if (!scenario) {
|
|
42
|
+
stderr.write("Choose what to configure:\n 1. API access\n 2. Wallet\n 3. Email\n");
|
|
43
|
+
scenario = await ask("Select 1/2/3", {
|
|
44
|
+
validate: (v) => ({ 1: "call", 2: "wallet", 3: "email" })[v] ||
|
|
45
|
+
invalid("Enter 1, 2 or 3."),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (!["call", "wallet", "email"].includes(scenario))
|
|
49
|
+
throw new CLIError("INVALID_INPUT", "Interactive setup scenario must be call, wallet or email.");
|
|
50
|
+
|
|
51
|
+
let values;
|
|
52
|
+
if (scenario === "call") {
|
|
53
|
+
const label = await ask("Key label", {
|
|
54
|
+
fallback: options.label || state.activeKey || "main",
|
|
55
|
+
validate: validateKeyLabel,
|
|
56
|
+
});
|
|
57
|
+
const previous = state.keys.find((key) => key.label === label);
|
|
58
|
+
const key = await ask("API key (hidden input)", {
|
|
59
|
+
hidden: true,
|
|
60
|
+
fallback: previous?.key || store.env.OPENANY_DEV_API_KEY?.trim() || "",
|
|
61
|
+
validate: validateApiKey,
|
|
62
|
+
});
|
|
63
|
+
const activate = await ask("Set as the active key? y/n", {
|
|
64
|
+
fallback: "y",
|
|
65
|
+
validate: (v) => {
|
|
66
|
+
if (["y", "yes"].includes(v.toLowerCase())) return true;
|
|
67
|
+
if (["n", "no"].includes(v.toLowerCase())) return false;
|
|
68
|
+
return invalid("Enter y or n.");
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
values = { label, key, activate };
|
|
72
|
+
} else if (scenario === "wallet") {
|
|
73
|
+
const privateKey = await ask("Wallet private key (hidden input)", {
|
|
74
|
+
hidden: true,
|
|
75
|
+
fallback: local.OPENANY_DEV_WALLET_PRIVATE_KEY ||
|
|
76
|
+
ctx.env.OPENANY_DEV_WALLET_PRIVATE_KEY || "",
|
|
77
|
+
validate: (v) => {
|
|
78
|
+
walletAddressFromPrivateKey(v);
|
|
79
|
+
return v;
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
const address = walletAddressFromPrivateKey(privateKey);
|
|
83
|
+
stderr.write(`Wallet address: ${address}\n`);
|
|
84
|
+
const agentId = await ask("Agent ID", {
|
|
85
|
+
fallback: local.OPENANY_DEV_AGENT_ID || ctx.env.OPENANY_DEV_AGENT_ID || "",
|
|
86
|
+
validate: validateAgentId,
|
|
87
|
+
});
|
|
88
|
+
values = { privateKey, address, agentId };
|
|
89
|
+
} else {
|
|
90
|
+
const email = await ask("Email address", {
|
|
91
|
+
fallback: local.OPENANY_DEV_EMAIL || ctx.env.OPENANY_DEV_EMAIL ||
|
|
92
|
+
state.sessions.email?.email || "",
|
|
93
|
+
validate: (v) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v) ?
|
|
94
|
+
v.toLowerCase() : invalid("Enter a valid email address."),
|
|
95
|
+
});
|
|
96
|
+
values = { email };
|
|
97
|
+
}
|
|
98
|
+
return persistSetup(ctx, scenario, values);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function persistSetup(ctx, scenario, values) {
|
|
102
|
+
const { store, options } = ctx;
|
|
103
|
+
let next;
|
|
104
|
+
await store.update(current => {
|
|
105
|
+
if (scenario === "call") {
|
|
106
|
+
const { label, key, activate } = values;
|
|
107
|
+
const existing = current.keys.find(item => item.label === label);
|
|
108
|
+
if (existing) {
|
|
109
|
+
if (existing.key !== key) delete existing.metadata;
|
|
110
|
+
existing.key = key;
|
|
111
|
+
} else current.keys.push({ label, key });
|
|
112
|
+
if (activate) current.activeKey = label;
|
|
113
|
+
next = [options.api_key || options.gui ? "openany-dev status_check api_key" : "openany-dev status --scenario call", "openany-dev balance"];
|
|
114
|
+
} else if (scenario === "wallet") {
|
|
115
|
+
current.settings = {
|
|
116
|
+
...current.settings,
|
|
117
|
+
OPENANY_DEV_WALLET_PRIVATE_KEY: values.privateKey,
|
|
118
|
+
OPENANY_DEV_WALLET_ADDRESS: values.address,
|
|
119
|
+
OPENANY_DEV_AGENT_ID: values.agentId,
|
|
120
|
+
};
|
|
121
|
+
next = [options.wallet_connect || options.gui ? "openany-dev status_check wallet" : "openany-dev status --scenario wallet", "openany-dev auth wallet"];
|
|
122
|
+
} else {
|
|
123
|
+
current.settings = { ...current.settings, OPENANY_DEV_EMAIL: values.email };
|
|
124
|
+
next = ["openany-dev auth email send", "openany-dev auth email verify --code SIX_DIGITS"];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
const fields = scenario === "call" ? ["OPENANY_DEV_API_KEY"] :
|
|
128
|
+
scenario === "wallet" ? [
|
|
129
|
+
"OPENANY_DEV_WALLET_PRIVATE_KEY", "OPENANY_DEV_WALLET_ADDRESS", "OPENANY_DEV_AGENT_ID",
|
|
130
|
+
] : ["OPENANY_DEV_EMAIL"];
|
|
131
|
+
return {
|
|
132
|
+
...(await configurationStatus(store, { scenario })),
|
|
133
|
+
saved: true,
|
|
134
|
+
path: store.path,
|
|
135
|
+
environmentOverrides: fields.filter((name) => store.env[name]?.trim()),
|
|
136
|
+
next,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Native helpers return credentials through a private pipe, never the CLI output.
|
|
141
|
+
async function runGuiSetup(ctx) {
|
|
142
|
+
const { scenario } = ctx.options;
|
|
143
|
+
if (!["call", "wallet"].includes(scenario) || ctx.options.prepare || ctx.options["non-interactive"])
|
|
144
|
+
throw new CLIError("INVALID_INPUT", "Choose API key or wallet setup for --gui.");
|
|
145
|
+
const { nativePrompt } = await import("./native-prompt.js");
|
|
146
|
+
const prompt = ctx.nativePrompt || nativePrompt;
|
|
147
|
+
const state = await ctx.store.read();
|
|
148
|
+
const defaults = scenario === "call"
|
|
149
|
+
? { label: ctx.options.label || state.activeKey || "main" }
|
|
150
|
+
: { agentId: state.settings?.OPENANY_DEV_AGENT_ID || ctx.env.OPENANY_DEV_AGENT_ID || "agent-main" };
|
|
151
|
+
const deadline = Date.now() + 300_000;
|
|
152
|
+
let errorMessage = "";
|
|
153
|
+
for (;;) {
|
|
154
|
+
const reply = await prompt({ mode: scenario, ...defaults, error: errorMessage }, { timeoutMs: deadline - Date.now() });
|
|
155
|
+
if (reply?.cancelled) throw new CLIError("CANCELLED", "Configuration cancelled; nothing was saved.");
|
|
156
|
+
if (typeof reply?.secret !== "string" || reply.secret.length > 4096)
|
|
157
|
+
throw new CLIError("GUI_PROTOCOL_ERROR", "The native dialog returned invalid input.");
|
|
158
|
+
ctx.secrets.push(reply.secret);
|
|
159
|
+
let values;
|
|
160
|
+
try {
|
|
161
|
+
if (scenario === "call") {
|
|
162
|
+
validateKeyLabel(reply.label);
|
|
163
|
+
validateApiKey(reply.secret);
|
|
164
|
+
values = { label: reply.label, key: reply.secret, activate: true };
|
|
165
|
+
} else {
|
|
166
|
+
validateAgentId(reply.agentId);
|
|
167
|
+
values = { privateKey: reply.secret, agentId: reply.agentId, address: walletAddressFromPrivateKey(reply.secret) };
|
|
168
|
+
}
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (!(error instanceof CLIError)) throw error;
|
|
171
|
+
// These validators use fixed messages and never embed credential values.
|
|
172
|
+
errorMessage = error.message;
|
|
173
|
+
ctx.stderr.write(errorMessage + "\n");
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (scenario === "wallet") {
|
|
177
|
+
const confirmation = await prompt({
|
|
178
|
+
mode: "confirm", address: values.address, agentId: values.agentId,
|
|
179
|
+
}, { timeoutMs: deadline - Date.now() });
|
|
180
|
+
if (confirmation?.confirmed !== true)
|
|
181
|
+
throw new CLIError("CANCELLED", "Wallet configuration cancelled; nothing was saved.");
|
|
182
|
+
}
|
|
183
|
+
return persistSetup(ctx, scenario, values);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function validateKeyLabel(value) {
|
|
188
|
+
if (typeof value !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(value))
|
|
189
|
+
throw new CLIError("INVALID_INPUT", "Key labels must use 1–64 letters, digits, dots, underscores or hyphens.");
|
|
190
|
+
return value;
|
|
191
|
+
}
|
|
192
|
+
function validateApiKey(value) {
|
|
193
|
+
if (typeof value !== "string" || !value || /\s/.test(value))
|
|
194
|
+
throw new CLIError("INVALID_INPUT", "API key must not be empty or contain whitespace.");
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
197
|
+
function validateAgentId(value) {
|
|
198
|
+
if (typeof value !== "string" || !/^[A-Za-z0-9._:-]{6,128}$/.test(value))
|
|
199
|
+
throw new CLIError("INVALID_INPUT", "Agent ID must use 6–128 letters, digits, dots, underscores, colons or hyphens.");
|
|
200
|
+
return value;
|
|
201
|
+
}
|
package/src/tasks.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
2
|
+
import { CLIError, requireValue } from "./errors.js";
|
|
3
|
+
|
|
4
|
+
const taskIdPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
5
|
+
const terminalStatuses = new Set(["completed", "failed", "timed_out"]);
|
|
6
|
+
|
|
7
|
+
export async function runTasks(args, { options, http }) {
|
|
8
|
+
const action = args[1];
|
|
9
|
+
const allowed = ["id", "json", "output"];
|
|
10
|
+
if (action === "wait") allowed.push("timeout-seconds");
|
|
11
|
+
if (args.length !== 2 || !["get", "wait"].includes(action) ||
|
|
12
|
+
Object.keys(options).some(key => !allowed.includes(key))) {
|
|
13
|
+
throw new CLIError("INVALID_INPUT", "Use tasks get|wait --id TASK_ID. Only wait accepts --timeout-seconds.");
|
|
14
|
+
}
|
|
15
|
+
const taskId = requireValue(options.id, "--id").toLowerCase();
|
|
16
|
+
if (!taskIdPattern.test(taskId))
|
|
17
|
+
throw new CLIError("INVALID_INPUT", "Task ID must be a UUID returned by run");
|
|
18
|
+
const path = "/v1/agent-api-tasks/" + taskId;
|
|
19
|
+
|
|
20
|
+
async function readTask(timeoutMs) {
|
|
21
|
+
const { body, requestId } = await http.gateway(path, { auth: "apiKey", timeoutMs });
|
|
22
|
+
if (body?.task_id !== taskId || typeof body.status !== "string" || !body.status)
|
|
23
|
+
throw new CLIError("INVALID_RESPONSE", "Gateway returned an invalid task record", { requestId, taskId });
|
|
24
|
+
return body;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (action === "get") return readTask();
|
|
28
|
+
|
|
29
|
+
const seconds = Number(options["timeout-seconds"] ?? 120);
|
|
30
|
+
if (!Number.isInteger(seconds) || seconds < 1 || seconds > 600)
|
|
31
|
+
throw new CLIError("INVALID_INPUT", "--timeout-seconds must be an integer between 1 and 600");
|
|
32
|
+
const deadline = performance.now() + seconds * 1000;
|
|
33
|
+
let delay = 1000;
|
|
34
|
+
let task;
|
|
35
|
+
while (performance.now() < deadline) {
|
|
36
|
+
try {
|
|
37
|
+
const remaining = Math.max(1, Math.ceil(deadline - performance.now()));
|
|
38
|
+
task = await readTask(remaining);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error.code === "REQUEST_TIMEOUT") break;
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
if (terminalStatuses.has(task.status)) return task;
|
|
44
|
+
const remaining = deadline - performance.now();
|
|
45
|
+
if (remaining <= delay) {
|
|
46
|
+
if (remaining > 0) await sleep(Math.ceil(remaining));
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
await sleep(delay);
|
|
50
|
+
delay = Math.min(delay * 2, 10000);
|
|
51
|
+
}
|
|
52
|
+
return { task_id: taskId, ...task, timedOut: true };
|
|
53
|
+
}
|