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,22 @@
|
|
|
1
|
+
export const MARKET_CATEGORIES = Object.freeze([
|
|
2
|
+
{ id: "social-media", label: "Social Media", icon: "MessageSquare" },
|
|
3
|
+
{ id: "lead-generation", label: "Lead Generation", icon: "BriefcaseBusiness" },
|
|
4
|
+
{ id: "search-research", label: "Search & Research", icon: "SearchCode" },
|
|
5
|
+
{ id: "news", label: "News", icon: "Globe2" },
|
|
6
|
+
{ id: "e-commerce", label: "E-commerce", icon: "Blocks" },
|
|
7
|
+
{ id: "travel", label: "Travel", icon: "Plane" },
|
|
8
|
+
{ id: "crypto-defi", label: "Crypto & DeFi", icon: "Coins" },
|
|
9
|
+
{ id: "finance", label: "Finance", icon: "BriefcaseBusiness" },
|
|
10
|
+
{ id: "ai-generation", label: "AI Generation", icon: "Sparkles" },
|
|
11
|
+
{ id: "compute-storage", label: "Compute & Storage", icon: "Database" },
|
|
12
|
+
{ id: "email-communication", label: "Email & Communication", icon: "Mail" },
|
|
13
|
+
{ id: "phone-messaging", label: "Phone & Messaging", icon: "Phone" },
|
|
14
|
+
{ id: "web-tools", label: "Web Tools", icon: "Globe2" },
|
|
15
|
+
{ id: "data", label: "Data", icon: "Database" },
|
|
16
|
+
{ id: "scrapers", label: "Scrapers", icon: "SearchCode" },
|
|
17
|
+
{ id: "developer", label: "Developer", icon: "Code2" },
|
|
18
|
+
{ id: "other", label: "Other", icon: "Wrench" },
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
export const CATEGORY_IDS = MARKET_CATEGORIES.map(({ id }) => id);
|
|
22
|
+
export const categoryLabel = (id) => MARKET_CATEGORIES.find((entry) => entry.id === id)?.label ?? id;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"repository": "https://github.com/openanysi/provider-apply",
|
|
3
|
+
"commit": "a46aae4a821b6ebe268e35376755b62769389b3a",
|
|
4
|
+
"files": {
|
|
5
|
+
"registration.mjs": "eefb78ddb5c7efdbafbbd1481481c45442b8afec809c1cf9bbbca2ff6dd89076",
|
|
6
|
+
"market-taxonomy.mjs": "6bdfb28b99e742b580248750ca94d5c177db59ac9437f6610dfbf61609a24c9f"
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { CATEGORY_IDS } from "./market-taxonomy.mjs";
|
|
2
|
+
|
|
3
|
+
const text = (maxLength = 200) => ({ type: "string", minLength: 1, maxLength });
|
|
4
|
+
const object = (properties, required = []) => ({ type: "object", additionalProperties: false, properties, required });
|
|
5
|
+
const category = { type: "string", enum: CATEGORY_IDS };
|
|
6
|
+
const secondary = { type: "array", items: category, maxItems: 3, uniqueItems: true };
|
|
7
|
+
const price = { type: ["string", "null"], pattern: "^(0|[1-9][0-9]*)(\\.[0-9]{1,8})?$", maxLength: 20 };
|
|
8
|
+
|
|
9
|
+
export const PROVIDER_SCHEMA = {
|
|
10
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
11
|
+
title: "OpenAny provider registration",
|
|
12
|
+
...object({
|
|
13
|
+
provider: object({ name: text(100), email: text(254), website: text(2048) }, ["name", "email"]),
|
|
14
|
+
resource: object({
|
|
15
|
+
name: text(100), description: text(2000),
|
|
16
|
+
type: { type: "string", enum: ["data", "model", "service"] },
|
|
17
|
+
primary_category: category, secondary_categories: secondary,
|
|
18
|
+
contains_personal_data: { type: "boolean" },
|
|
19
|
+
}, ["name", "description", "type", "primary_category", "secondary_categories", "contains_personal_data"]),
|
|
20
|
+
connection: object({
|
|
21
|
+
documentation_url: text(2048), base_url: text(2048),
|
|
22
|
+
authentication: object({ type: { type: "string", enum: ["none", "bearer", "api_key", "oauth2", "x402"] }, header_name: text(100) }, ["type"]),
|
|
23
|
+
}, ["authentication"]),
|
|
24
|
+
endpoints: { type: "array", maxItems: 20, items: object({
|
|
25
|
+
name: text(100), description: text(2000), method: { type: "string", enum: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"] },
|
|
26
|
+
path: text(1024), primary_category: category, secondary_categories: secondary,
|
|
27
|
+
billing: object({
|
|
28
|
+
model: { type: "string", enum: ["free", "per_call", "per_unit", "token"] }, currency: { type: "string", enum: ["USD"] },
|
|
29
|
+
price, input_price: price, output_price: price, unit: text(100), usage_path: text(200),
|
|
30
|
+
}, ["model", "currency", "price"]),
|
|
31
|
+
test: object({ input: { type: "object", maxProperties: 50 }, expected_status: { type: "integer", minimum: 200, maximum: 299 } }, ["input", "expected_status"]),
|
|
32
|
+
}, ["name", "description", "method", "path", "primary_category", "secondary_categories", "billing"]) },
|
|
33
|
+
consents: object({ authorized: { const: true }, automated_checks: { const: true } }, ["authorized", "automated_checks"]),
|
|
34
|
+
}, ["provider", "resource", "connection", "endpoints", "consents"]),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export function isPublicHttps(value) {
|
|
38
|
+
try {
|
|
39
|
+
const url = new URL(value);
|
|
40
|
+
const host = url.hostname.toLowerCase();
|
|
41
|
+
if (url.protocol !== "https:" || url.username || url.password || url.hash) return false;
|
|
42
|
+
if (!host.includes(".") || host.endsWith(".") || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal")) return false;
|
|
43
|
+
if (/^[\d.]+$/.test(host) || host.includes(":") || host.includes("[")) return false;
|
|
44
|
+
return ![...url.searchParams.keys()].some((key) => /^(key|api[-_]?key|token|access[-_]?token|secret|password)$/i.test(key));
|
|
45
|
+
} catch { return false; }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function check(schema, value, path, errors) {
|
|
49
|
+
if (schema.const !== undefined && value !== schema.const) errors.push({ path, message: "Confirmation is required." });
|
|
50
|
+
if (schema.type) {
|
|
51
|
+
const actual = value === null ? "null" : Array.isArray(value) ? "array" : typeof value;
|
|
52
|
+
const types = [].concat(schema.type);
|
|
53
|
+
if (!types.includes(actual) && !(types.includes("integer") && Number.isInteger(value))) {
|
|
54
|
+
errors.push({ path, message: `Expected ${types.join(" or ")}.` }); return;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (schema.enum && !schema.enum.includes(value)) errors.push({ path, message: "Choose a supported option." });
|
|
58
|
+
if (typeof value === "string") {
|
|
59
|
+
if ((schema.minLength && value.trim().length < schema.minLength) || (schema.maxLength && value.length > schema.maxLength)) errors.push({ path, message: "Enter a value within the allowed length." });
|
|
60
|
+
if (schema.pattern && !new RegExp(schema.pattern).test(value)) errors.push({ path, message: "Use a non-negative decimal with up to 8 decimal places." });
|
|
61
|
+
}
|
|
62
|
+
if (typeof value === "number" && (value < schema.minimum || value > schema.maximum)) errors.push({ path, message: "Value is outside the allowed range." });
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
if (value.length > schema.maxItems) errors.push({ path, message: `Choose at most ${schema.maxItems} items.` });
|
|
65
|
+
if (schema.uniqueItems && new Set(value).size !== value.length) errors.push({ path, message: "Remove duplicate items." });
|
|
66
|
+
value.forEach((item, i) => check(schema.items ?? {}, item, `${path}.${i}`, errors));
|
|
67
|
+
} else if (value && typeof value === "object") {
|
|
68
|
+
for (const key of schema.required ?? []) if (!(key in value)) errors.push({ path: `${path}.${key}`, message: "This field is required." });
|
|
69
|
+
for (const [key, item] of Object.entries(value)) {
|
|
70
|
+
if (schema.additionalProperties === false && !Object.hasOwn(schema.properties ?? {}, key)) errors.push({ path: `${path}.${key}`, message: "Unknown field. Do not submit credentials." });
|
|
71
|
+
else if (schema.properties?.[key]) check(schema.properties[key], item, `${path}.${key}`, errors);
|
|
72
|
+
}
|
|
73
|
+
if (schema.maxProperties && Object.keys(value).length > schema.maxProperties) errors.push({ path, message: "Too many input fields." });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function hasSecret(value, depth = 0) {
|
|
78
|
+
if (depth > 12) return true;
|
|
79
|
+
if (typeof value === "string") return /-----BEGIN .*PRIVATE KEY-----|\bBearer\s+\S+|\bsk-[A-Za-z0-9_-]{16,}/.test(value);
|
|
80
|
+
if (!value || typeof value !== "object") return false;
|
|
81
|
+
return Object.entries(value).some(([key, item]) => /^(password|authorization|api[-_]?key|access[-_]?token|refresh[-_]?token|private[-_]?key|secret)$/i.test(key) || hasSecret(item, depth + 1));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function validateRegistration(value) {
|
|
85
|
+
const errors = [];
|
|
86
|
+
check(PROVIDER_SCHEMA, value, "", errors);
|
|
87
|
+
if (errors.length) return errors;
|
|
88
|
+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value.provider.email)) errors.push({ path: "provider.email", message: "Enter a valid email address." });
|
|
89
|
+
if (!value.connection.base_url && !value.connection.documentation_url) errors.push({ path: "connection", message: "Provide API documentation or a base URL." });
|
|
90
|
+
for (const [path, url] of [["provider.website", value.provider.website], ["connection.base_url", value.connection.base_url], ["connection.documentation_url", value.connection.documentation_url]]) {
|
|
91
|
+
if (url && !isPublicHttps(url)) errors.push({ path, message: "Use a public HTTPS URL without credentials, IP addresses, or fragments." });
|
|
92
|
+
}
|
|
93
|
+
if (value.resource.secondary_categories.includes(value.resource.primary_category)) errors.push({ path: "resource.secondary_categories", message: "The primary category cannot also be secondary." });
|
|
94
|
+
const identities = new Set();
|
|
95
|
+
value.endpoints.forEach((endpoint, i) => {
|
|
96
|
+
const path = `endpoints.${i}`;
|
|
97
|
+
if (!/^\/(?!\/)[^?#\s\\]*$/.test(endpoint.path) || /(?:^|\/)\.\.(?:\/|$)/.test(endpoint.path)) errors.push({ path: `${path}.path`, message: "Use a relative API path starting with /, without a query string." });
|
|
98
|
+
const identity = `${endpoint.method} ${endpoint.path}`;
|
|
99
|
+
if (identities.has(identity)) errors.push({ path: `${path}.path`, message: "This method and path already exist." });
|
|
100
|
+
identities.add(identity);
|
|
101
|
+
if (endpoint.secondary_categories.includes(endpoint.primary_category)) errors.push({ path: `${path}.secondary_categories`, message: "The primary category cannot also be secondary." });
|
|
102
|
+
if (endpoint.billing.model === "free" && endpoint.billing.price !== "0") errors.push({ path: `${path}.billing.price`, message: "Free endpoints must have price 0." });
|
|
103
|
+
if (endpoint.test && hasSecret(endpoint.test.input)) errors.push({ path: `${path}.test.input`, message: "Remove credentials from the test input." });
|
|
104
|
+
});
|
|
105
|
+
if (hasSecret(value.resource.description)) errors.push({ path: "resource.description", message: "Remove credentials from the description." });
|
|
106
|
+
return errors;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function registrationChecks(value) {
|
|
110
|
+
const items = [
|
|
111
|
+
{ id: "definition", label: "Registration saved", state: "passed" },
|
|
112
|
+
{ id: "ownership", label: "Verify provider control and resource rights", state: "pending" },
|
|
113
|
+
];
|
|
114
|
+
if (!value.connection.base_url) items.push({ id: "base_url", label: "Add a callable API base URL", state: "missing" });
|
|
115
|
+
if (!value.endpoints.length) items.push({ id: "endpoints", label: "Add at least one endpoint", state: "missing" });
|
|
116
|
+
if (value.endpoints.some((entry) => !entry.test)) items.push({ id: "test", label: "Add a safe test request for each endpoint", state: "missing" });
|
|
117
|
+
if (value.endpoints.some(({ billing }) => billing.model !== "free" && (billing.model === "token" ? billing.input_price == null || billing.output_price == null : billing.price == null || (billing.model === "per_unit" && (!billing.unit || !billing.usage_path))))) items.push({ id: "pricing", label: "Complete endpoint pricing and metering", state: "missing" });
|
|
118
|
+
if (value.connection.authentication.type !== "none") items.push({ id: "credentials", label: "Bind credentials through a secure credential service", state: "pending" });
|
|
119
|
+
if (value.resource.contains_personal_data) items.push({ id: "data_rights", label: "Verify personal-data consent and access restrictions", state: "blocked" });
|
|
120
|
+
if (value.endpoints.some(({ billing }) => billing.model !== "free")) items.push({ id: "settlement", label: "Connect provider settlement", state: "pending" });
|
|
121
|
+
items.push({ id: "runtime", label: "Connect live verification and gateway publishing", state: "pending" });
|
|
122
|
+
return items;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function exampleRegistration() {
|
|
126
|
+
return {
|
|
127
|
+
provider: { name: "Example Research", email: "provider@example.com" },
|
|
128
|
+
resource: { name: "Company Research", description: "Search company profiles by domain. Returns public company information, not personal contact details.", type: "data", primary_category: "search-research", secondary_categories: ["data"], contains_personal_data: false },
|
|
129
|
+
connection: { documentation_url: "https://api.example.com/openapi.json", base_url: "https://api.example.com", authentication: { type: "none" } },
|
|
130
|
+
endpoints: [{ name: "Find a company", description: "Returns a company profile for a domain.", method: "GET", path: "/v1/company", primary_category: "search-research", secondary_categories: ["data"], billing: { model: "per_call", currency: "USD", price: "0.01" }, test: { input: { query: { domain: "example.com" } }, expected_status: 200 } }],
|
|
131
|
+
consents: { authorized: true, automated_checks: true },
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function importOpenApi(document) {
|
|
136
|
+
if (!document || typeof document.openapi !== "string" || !document.openapi.startsWith("3.") || !document.paths || typeof document.paths !== "object") throw new Error("Upload an OpenAPI 3.x JSON document with paths.");
|
|
137
|
+
const endpoints = [];
|
|
138
|
+
let total = 0;
|
|
139
|
+
for (const [path, operations] of Object.entries(document.paths)) {
|
|
140
|
+
if (!operations || typeof operations !== "object") continue;
|
|
141
|
+
for (const [method, operation] of Object.entries(operations)) {
|
|
142
|
+
if (!["get", "post", "put", "patch", "delete", "head"].includes(method) || !operation || typeof operation !== "object") continue;
|
|
143
|
+
total++;
|
|
144
|
+
if (endpoints.length >= 20) continue;
|
|
145
|
+
endpoints.push({ name: String(operation.summary ?? operation.operationId ?? `${method.toUpperCase()} ${path}`).slice(0, 100), description: String(operation.description ?? operation.summary ?? `${method.toUpperCase()} ${path}`).slice(0, 2000), method: method.toUpperCase(), path, primary_category: "other", secondary_categories: [], billing: { model: "per_call", currency: "USD", price: null } });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!total) throw new Error("No supported HTTP endpoints were found.");
|
|
149
|
+
const server = document.servers?.find((entry) => isPublicHttps(entry.url));
|
|
150
|
+
return { name: String(document.info?.title ?? "").slice(0, 100), description: String(document.info?.description ?? "").slice(0, 2000), baseUrl: server?.url ?? "", endpoints, total };
|
|
151
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[
|
|
2
|
+
"social-media",
|
|
3
|
+
"lead-generation",
|
|
4
|
+
"search-research",
|
|
5
|
+
"news",
|
|
6
|
+
"e-commerce",
|
|
7
|
+
"travel",
|
|
8
|
+
"crypto-defi",
|
|
9
|
+
"finance",
|
|
10
|
+
"ai-generation",
|
|
11
|
+
"compute-storage",
|
|
12
|
+
"email-communication",
|
|
13
|
+
"phone-messaging",
|
|
14
|
+
"web-tools",
|
|
15
|
+
"data",
|
|
16
|
+
"scrapers",
|
|
17
|
+
"developer",
|
|
18
|
+
"other",
|
|
19
|
+
"enrichment",
|
|
20
|
+
"seo-aeo",
|
|
21
|
+
"advertising",
|
|
22
|
+
"reviews-apps",
|
|
23
|
+
"community",
|
|
24
|
+
"market-data",
|
|
25
|
+
"document",
|
|
26
|
+
"media",
|
|
27
|
+
"tools",
|
|
28
|
+
"web"
|
|
29
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"apiName": "name",
|
|
4
|
+
"apiDescription": "description",
|
|
5
|
+
"httpMethod": "method",
|
|
6
|
+
"publicPath": "pathTemplate",
|
|
7
|
+
"upstreamPath": "upstreamPathTemplate"
|
|
8
|
+
},
|
|
9
|
+
"config": {
|
|
10
|
+
"requestParameters": "inputs",
|
|
11
|
+
"parameterMappings": "mappings",
|
|
12
|
+
"fixedHeaders": "fixed_headers",
|
|
13
|
+
"fixedBody": "fixed_body",
|
|
14
|
+
"crossFieldRules": "cross_field_rules",
|
|
15
|
+
"undeclaredParameterPolicy": "unknown_parameters",
|
|
16
|
+
"timeoutMs": "timeout_ms",
|
|
17
|
+
"maxRequestBytes": "max_request_bytes",
|
|
18
|
+
"maxResponseBytes": "max_response_bytes",
|
|
19
|
+
"billingSuccessCondition": "charge_condition",
|
|
20
|
+
"requestResponseExamples": "samples"
|
|
21
|
+
},
|
|
22
|
+
"billing": {
|
|
23
|
+
"pricePerBillingUnitMicroUsd": "price_micro_usd",
|
|
24
|
+
"responseUsageJsonPointer": "usage_pointer",
|
|
25
|
+
"usageDecimalPlaces": "quantity_scale",
|
|
26
|
+
"usageQuantityPerBillingUnit": "unit_quantity",
|
|
27
|
+
"costRoundingMode": "rounding"
|
|
28
|
+
},
|
|
29
|
+
"sample": {
|
|
30
|
+
"httpStatus": "http_status",
|
|
31
|
+
"responseBody": "response_body"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"model": {
|
|
3
|
+
"modelId": "model",
|
|
4
|
+
"publicModelId": "publicModel",
|
|
5
|
+
"modelDescription": "description",
|
|
6
|
+
"modelDescriptionTranslations": "descriptionTranslations",
|
|
7
|
+
"inputCapabilities": "modalities",
|
|
8
|
+
"outputCapabilities": "outModalities",
|
|
9
|
+
"maxContextTokens": "contextWindowTokens",
|
|
10
|
+
"endpoints": "upstreamPath",
|
|
11
|
+
"requestBodySchema": "bodySchema",
|
|
12
|
+
"requestCurlExample": "curlExample",
|
|
13
|
+
"priceCurrency": "currency",
|
|
14
|
+
"billingMode": "billingType",
|
|
15
|
+
"usageUnit": "billingUnit",
|
|
16
|
+
"tieredPricingRules": "pricingTiers",
|
|
17
|
+
"scheduledPricingRules": "timePricingRules",
|
|
18
|
+
"inputPrice": "actualPrompt",
|
|
19
|
+
"outputPrice": "actualCompletion",
|
|
20
|
+
"cacheWritePrice": "cacheCreationPrompt",
|
|
21
|
+
"cacheReadPrice": "cacheReadPrompt"
|
|
22
|
+
},
|
|
23
|
+
"prices": {
|
|
24
|
+
"inputPrice": "actualPrompt",
|
|
25
|
+
"outputPrice": "actualCompletion",
|
|
26
|
+
"cacheWritePrice": "cacheCreationPrompt",
|
|
27
|
+
"cacheReadPrice": "cacheReadPrompt"
|
|
28
|
+
},
|
|
29
|
+
"endpoint": {
|
|
30
|
+
"operationType": "type",
|
|
31
|
+
"upstreamPath": "path",
|
|
32
|
+
"httpMethod": "method"
|
|
33
|
+
},
|
|
34
|
+
"schedule": {
|
|
35
|
+
"ruleName": "label",
|
|
36
|
+
"applicableWeekdaysUtc": "daysOfWeekUtc",
|
|
37
|
+
"startMinuteOfDayUtc": "startMinuteUtc",
|
|
38
|
+
"endMinuteOfDayUtc": "endMinuteUtc",
|
|
39
|
+
"inputPrice": "actualPrompt",
|
|
40
|
+
"outputPrice": "actualCompletion",
|
|
41
|
+
"cacheWritePrice": "cacheCreationPrompt",
|
|
42
|
+
"cacheReadPrice": "cacheReadPrompt"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/wallet.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { createPrivateKey, createPublicKey, sign, verify } from "node:crypto";
|
|
2
|
+
import { Wallet, getAddress, verifyMessage } from "ethers";
|
|
3
|
+
import { Keypair, PublicKey, VersionedTransaction } from "@solana/web3.js";
|
|
4
|
+
import bs58 from "bs58";
|
|
5
|
+
import { CLIError } from "./errors.js";
|
|
6
|
+
|
|
7
|
+
const privatePrefix = Buffer.from("302e020100300506032b657004220420", "hex");
|
|
8
|
+
const publicPrefix = Buffer.from("302a300506032b6570032100", "hex");
|
|
9
|
+
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
10
|
+
export const isEVM = (address) =>
|
|
11
|
+
typeof address === "string" && /^0x[0-9a-f]{40}$/i.test(address);
|
|
12
|
+
export function normalizeWallet(address) {
|
|
13
|
+
try {
|
|
14
|
+
if (isEVM(address)) {
|
|
15
|
+
if (/^0x0{40}$/i.test(address)) throw new Error();
|
|
16
|
+
return getAddress(address).toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
const decoded = bs58.decode(address);
|
|
19
|
+
if (decoded.length !== 32 || !PublicKey.isOnCurve(decoded))
|
|
20
|
+
throw new Error();
|
|
21
|
+
return new PublicKey(decoded).toBase58();
|
|
22
|
+
} catch {
|
|
23
|
+
throw new CLIError("WALLET_INVALID", "Wallet address is invalid or does not support signing.");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export const sameWallet = (a, b) => normalizeWallet(a) === normalizeWallet(b);
|
|
27
|
+
function normalizePrivateKey(secret) {
|
|
28
|
+
return typeof secret === "string" && /^[0-9a-f]{64}$/i.test(secret)
|
|
29
|
+
? `0x${secret}` : secret;
|
|
30
|
+
}
|
|
31
|
+
export function walletAddressFromPrivateKey(secret) {
|
|
32
|
+
try {
|
|
33
|
+
secret = normalizePrivateKey(secret);
|
|
34
|
+
if (/^0x[0-9a-f]{64}$/i.test(secret))
|
|
35
|
+
return new Wallet(secret).address.toLowerCase();
|
|
36
|
+
const decoded = bs58.decode(secret);
|
|
37
|
+
if (decoded.length !== 64) throw new Error();
|
|
38
|
+
return Keypair.fromSecretKey(decoded).publicKey.toBase58();
|
|
39
|
+
} catch {
|
|
40
|
+
throw new CLIError(
|
|
41
|
+
"WALLET_KEY_INVALID",
|
|
42
|
+
"Invalid wallet private key. EVM requires a 32-byte hexadecimal key with or without a 0x prefix; Solana requires a Base58-encoded 64-byte private key.",
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function getWallet(env, { requirePrivateKey = true } = {}) {
|
|
47
|
+
const missing = [];
|
|
48
|
+
if (!env.OPENANY_DEV_WALLET_ADDRESS) missing.push("OPENANY_DEV_WALLET_ADDRESS");
|
|
49
|
+
if (requirePrivateKey && !env.OPENANY_DEV_WALLET_PRIVATE_KEY)
|
|
50
|
+
missing.push("OPENANY_DEV_WALLET_PRIVATE_KEY");
|
|
51
|
+
if (missing.length)
|
|
52
|
+
throw new CLIError(
|
|
53
|
+
"CONFIG_REQUIRED",
|
|
54
|
+
"Configure the required wallet details or use the external signing flow.",
|
|
55
|
+
{ missing },
|
|
56
|
+
);
|
|
57
|
+
const address = normalizeWallet(env.OPENANY_DEV_WALLET_ADDRESS);
|
|
58
|
+
if (!requirePrivateKey)
|
|
59
|
+
return { address, kind: isEVM(address) ? "evm" : "solana" };
|
|
60
|
+
const secret = normalizePrivateKey(env.OPENANY_DEV_WALLET_PRIVATE_KEY);
|
|
61
|
+
try {
|
|
62
|
+
if (isEVM(address)) {
|
|
63
|
+
if (!/^0x[0-9a-f]{64}$/i.test(secret)) throw new Error();
|
|
64
|
+
const signer = new Wallet(secret);
|
|
65
|
+
if (!sameWallet(signer.address, address))
|
|
66
|
+
throw new CLIError("WALLET_MISMATCH", "The private key does not match the configured wallet address.");
|
|
67
|
+
return {
|
|
68
|
+
address,
|
|
69
|
+
kind: "evm",
|
|
70
|
+
signMessage: (message) => signer.signMessage(message),
|
|
71
|
+
signTypedData: (domain, types, message) =>
|
|
72
|
+
signer.signTypedData(domain, types, message),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const decoded = bs58.decode(secret);
|
|
76
|
+
if (decoded.length !== 64) throw new Error();
|
|
77
|
+
const keypair = Keypair.fromSecretKey(decoded);
|
|
78
|
+
if (keypair.publicKey.toBase58() !== address)
|
|
79
|
+
throw new CLIError("WALLET_MISMATCH", "The private key does not match the configured wallet address.");
|
|
80
|
+
const key = createPrivateKey({
|
|
81
|
+
key: Buffer.concat([privatePrefix, Buffer.from(decoded.slice(0, 32))]),
|
|
82
|
+
format: "der",
|
|
83
|
+
type: "pkcs8",
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
address,
|
|
87
|
+
kind: "solana",
|
|
88
|
+
signMessage: async (message) =>
|
|
89
|
+
bs58.encode(sign(null, Buffer.from(message, "utf8"), key)),
|
|
90
|
+
signTransaction: async (bytes) => {
|
|
91
|
+
const tx = VersionedTransaction.deserialize(bytes);
|
|
92
|
+
tx.sign([keypair]);
|
|
93
|
+
return tx.serialize();
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (error instanceof CLIError) throw error;
|
|
98
|
+
throw new CLIError(
|
|
99
|
+
"WALLET_KEY_INVALID",
|
|
100
|
+
"Invalid wallet private key. EVM requires a 32-byte hexadecimal key with or without a 0x prefix; Solana requires a Base58-encoded 64-byte private key.",
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export function verifyWalletMessage(address, message, signature) {
|
|
105
|
+
try {
|
|
106
|
+
if (isEVM(address))
|
|
107
|
+
return (
|
|
108
|
+
/^0x[0-9a-f]{130}$/i.test(signature) &&
|
|
109
|
+
sameWallet(verifyMessage(message, signature), address)
|
|
110
|
+
);
|
|
111
|
+
const bytes = bs58.decode(signature);
|
|
112
|
+
return (
|
|
113
|
+
bytes.length === 64 &&
|
|
114
|
+
verify(
|
|
115
|
+
null,
|
|
116
|
+
Buffer.from(message, "utf8"),
|
|
117
|
+
createPublicKey({
|
|
118
|
+
key: Buffer.concat([
|
|
119
|
+
publicPrefix,
|
|
120
|
+
Buffer.from(bs58.decode(normalizeWallet(address))),
|
|
121
|
+
]),
|
|
122
|
+
type: "spki",
|
|
123
|
+
format: "der",
|
|
124
|
+
}),
|
|
125
|
+
bytes,
|
|
126
|
+
)
|
|
127
|
+
);
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export function validateChallenge(challenge, expected, now = Date.now()) {
|
|
133
|
+
const invalid = () => {
|
|
134
|
+
throw new CLIError(
|
|
135
|
+
"CHALLENGE_INVALID",
|
|
136
|
+
"The wallet challenge does not match the expected identity, operation, signing service origin or validity period; nothing was signed.",
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
if (
|
|
140
|
+
!challenge ||
|
|
141
|
+
!uuid.test(challenge.challengeId) ||
|
|
142
|
+
typeof challenge.message !== "string"
|
|
143
|
+
)
|
|
144
|
+
return invalid();
|
|
145
|
+
const lines = challenge.message.split("\n");
|
|
146
|
+
const fields = {};
|
|
147
|
+
for (const line of lines.slice(1)) {
|
|
148
|
+
const index = line.indexOf(": ");
|
|
149
|
+
if (index < 1) return invalid();
|
|
150
|
+
const k = line.slice(0, index);
|
|
151
|
+
if (Object.hasOwn(fields, k)) return invalid();
|
|
152
|
+
fields[k] = line.slice(index + 2);
|
|
153
|
+
}
|
|
154
|
+
const session = expected.operation === "session";
|
|
155
|
+
const names = session
|
|
156
|
+
? [
|
|
157
|
+
"Service Origin",
|
|
158
|
+
"Purpose",
|
|
159
|
+
"Wallet",
|
|
160
|
+
"Nonce",
|
|
161
|
+
"Issued At",
|
|
162
|
+
"Expires At",
|
|
163
|
+
]
|
|
164
|
+
: ["Wallet", "Agent ID", "Operation", "Nonce", "Issued At", "Expires At"];
|
|
165
|
+
if (expected.operation === "rotate_key") names.push("Expected Key ID");
|
|
166
|
+
if (
|
|
167
|
+
lines[0] !==
|
|
168
|
+
(session ? "OpenModels Agent Wallet Login" : "OpenModels Agent Key") ||
|
|
169
|
+
Object.keys(fields).length !== names.length ||
|
|
170
|
+
names.some((n) => !fields[n])
|
|
171
|
+
)
|
|
172
|
+
return invalid();
|
|
173
|
+
try {
|
|
174
|
+
if (!sameWallet(fields.Wallet, expected.walletAddress)) return invalid();
|
|
175
|
+
} catch {
|
|
176
|
+
return invalid();
|
|
177
|
+
}
|
|
178
|
+
if (session) {
|
|
179
|
+
if (
|
|
180
|
+
!expected.serviceOrigin ||
|
|
181
|
+
fields["Service Origin"] !== expected.serviceOrigin ||
|
|
182
|
+
fields.Purpose !== "agent_session"
|
|
183
|
+
)
|
|
184
|
+
return invalid();
|
|
185
|
+
} else {
|
|
186
|
+
if (
|
|
187
|
+
fields["Agent ID"] !== expected.agentId ||
|
|
188
|
+
fields.Operation !== expected.operation
|
|
189
|
+
)
|
|
190
|
+
return invalid();
|
|
191
|
+
if (
|
|
192
|
+
expected.operation === "rotate_key" &&
|
|
193
|
+
(!uuid.test(fields["Expected Key ID"]) ||
|
|
194
|
+
fields["Expected Key ID"] !== challenge.expectedKeyId ||
|
|
195
|
+
(expected.expectedKeyId &&
|
|
196
|
+
fields["Expected Key ID"] !== expected.expectedKeyId))
|
|
197
|
+
)
|
|
198
|
+
return invalid();
|
|
199
|
+
}
|
|
200
|
+
const issued = Date.parse(fields["Issued At"]),
|
|
201
|
+
expires = Date.parse(fields["Expires At"]);
|
|
202
|
+
if (
|
|
203
|
+
!Number.isFinite(issued) ||
|
|
204
|
+
!Number.isFinite(expires) ||
|
|
205
|
+
issued > now + 60000 ||
|
|
206
|
+
expires <= now ||
|
|
207
|
+
expires - issued > 300000 ||
|
|
208
|
+
expires <= issued ||
|
|
209
|
+
Date.parse(challenge.expiresAt) !== expires
|
|
210
|
+
)
|
|
211
|
+
return invalid();
|
|
212
|
+
return challenge;
|
|
213
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { encodedPowerShell } from "./native-prompt.js";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { CLIError } from "./errors.js";
|
|
6
|
+
|
|
7
|
+
// POSIX mode bits cannot enforce credential privacy on Windows.
|
|
8
|
+
export async function windowsPermissions(path, protect = false) {
|
|
9
|
+
const command = join(process.env.SystemRoot || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
10
|
+
const args = [
|
|
11
|
+
"-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand",
|
|
12
|
+
await encodedPowerShell(new URL("./native/config-acl.ps1", import.meta.url)),
|
|
13
|
+
];
|
|
14
|
+
const env = { OPENANY_ACL_TARGET: path, OPENANY_ACL_PROTECT: String(protect) };
|
|
15
|
+
for (const key of ["SystemRoot", "WINDIR", "USERPROFILE", "TEMP", "TMP"])
|
|
16
|
+
if (process.env[key]) env[key] = process.env[key];
|
|
17
|
+
try {
|
|
18
|
+
await promisify(execFile)(command, args, { env, windowsHide: true, timeout: 15_000, maxBuffer: 4096 });
|
|
19
|
+
} catch {
|
|
20
|
+
throw new CLIError("CONFIG_UNSAFE", "Cannot verify or secure the Windows credentials ACL. Check the configuration path permissions and PowerShell policy.");
|
|
21
|
+
}
|
|
22
|
+
}
|