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
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { CLIError, requireValue } from "./errors.js";
|
|
2
|
+
import { assertNoSecrets, uuid } from "./provider-state.js";
|
|
3
|
+
export function checkConfiguration(value) {
|
|
4
|
+
assertNoSecrets(value);
|
|
5
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
6
|
+
throw new CLIError("INVALID_INPUT", "Configuration must be an object");
|
|
7
|
+
for (const o of [value, value.price])
|
|
8
|
+
if (o)
|
|
9
|
+
for (const k of [
|
|
10
|
+
"active",
|
|
11
|
+
"isActive",
|
|
12
|
+
"is_active",
|
|
13
|
+
"status",
|
|
14
|
+
"publicationPolicy",
|
|
15
|
+
"applicationId",
|
|
16
|
+
"providerId",
|
|
17
|
+
"provider",
|
|
18
|
+
"providerKind",
|
|
19
|
+
"firstPublishedAt",
|
|
20
|
+
])
|
|
21
|
+
if (k in o)
|
|
22
|
+
throw new CLIError(
|
|
23
|
+
"FORBIDDEN_FIELD",
|
|
24
|
+
"Server controls ownership and publication",
|
|
25
|
+
{ field: k },
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
export const resourceContentFields = ["includedContentHtml", "usageInstructionsHtml", "effectContentHtml"];
|
|
29
|
+
export const isResourceApi = (catalogType) => Boolean(catalogType && catalogType !== "api");
|
|
30
|
+
export const hasText = (value) => typeof value === "string" && value.trim().length > 0;
|
|
31
|
+
// Detect empty editor markup locally. The server validates supported HTML.
|
|
32
|
+
export const hasArticleContent = (value) => hasText(value) &&
|
|
33
|
+
(/<hr\s*\/?>/i.test(value) || hasText(value.replace(/<[^>]*>|&(?:nbsp|#0*(?:160|8203|65279)|#x0*(?:a0|200b|feff));|[\u200b\ufeff]/gi, "")));
|
|
34
|
+
export const hasSellerDescription = (value) => hasText(value) && Array.from(value.trim()).length >= 150;
|
|
35
|
+
|
|
36
|
+
export function asyncConfigurationFields(input) {
|
|
37
|
+
if (input.executionMode !== "async") return [];
|
|
38
|
+
const config = input.asyncConfig;
|
|
39
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) return ["asyncConfig"];
|
|
40
|
+
const fields = [];
|
|
41
|
+
if (!["webhook", "grok_bot", "http_json"].includes(config.adapter_type)) fields.push("asyncConfig.adapter_type");
|
|
42
|
+
if (!["callback", "poll"].includes(config.delivery_mode)) fields.push("asyncConfig.delivery_mode");
|
|
43
|
+
if (!Number.isInteger(config.timeout_secs) || config.timeout_secs < 1 || config.timeout_secs > 604800)
|
|
44
|
+
fields.push("asyncConfig.timeout_secs");
|
|
45
|
+
if (!config.output_contract || typeof config.output_contract !== "object" || Array.isArray(config.output_contract))
|
|
46
|
+
fields.push("asyncConfig.output_contract");
|
|
47
|
+
if ((input.catalogType === "bot" || config.adapter_type === "grok_bot") && config.policy_version !== "openany-bot-v1")
|
|
48
|
+
fields.push("asyncConfig.policy_version");
|
|
49
|
+
return fields;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const query = (options) =>
|
|
53
|
+
Object.fromEntries(
|
|
54
|
+
["limit", "offset", "cursor", "search", "status"]
|
|
55
|
+
.filter((k) => options[k] !== undefined)
|
|
56
|
+
.map((k) => [k, options[k]]),
|
|
57
|
+
);
|
|
58
|
+
export async function runResource(kind, action, client, ctx) {
|
|
59
|
+
const root = kind === "model" ? "/models" : "/agent-apis",
|
|
60
|
+
o = ctx.options;
|
|
61
|
+
if (action === "list") return client.request(root, { query: query(o) });
|
|
62
|
+
const path = ["create"].includes(action)
|
|
63
|
+
? root
|
|
64
|
+
: root + "/" + uuid(requireValue(o.id, "--id"));
|
|
65
|
+
if (action === "get")
|
|
66
|
+
return client.request(
|
|
67
|
+
path +
|
|
68
|
+
(o["verification-id"]
|
|
69
|
+
? "/verifications/" + uuid(o["verification-id"])
|
|
70
|
+
: ""),
|
|
71
|
+
);
|
|
72
|
+
if (action === "create" || action === "update") {
|
|
73
|
+
const input = await ctx.input();
|
|
74
|
+
checkConfiguration(input);
|
|
75
|
+
const capabilities = await client.capabilities(kind);
|
|
76
|
+
let current;
|
|
77
|
+
if (action === "update") {
|
|
78
|
+
current = await client.request(
|
|
79
|
+
path + (kind === "model" ? "/publication" : ""),
|
|
80
|
+
);
|
|
81
|
+
if (current.firstPublishedAt && capabilities.reviewPolicy !== "seller_application")
|
|
82
|
+
throw new CLIError(
|
|
83
|
+
"PROVIDER_RESOURCE_ALREADY_PUBLISHED",
|
|
84
|
+
"First release supports only unpublished resources",
|
|
85
|
+
);
|
|
86
|
+
requireValue(
|
|
87
|
+
input[kind === "model" ? "expectedVersion" : "expectedRevision"],
|
|
88
|
+
"expected version",
|
|
89
|
+
);
|
|
90
|
+
if (kind === "api") requireValue(input.expectedUpstreamRevision, "expectedUpstreamRevision");
|
|
91
|
+
}
|
|
92
|
+
const validate = async () => {
|
|
93
|
+
const descriptionField = kind === "model" ? "price.description" : "description";
|
|
94
|
+
const description = kind === "model" ? input.price?.description : input.description;
|
|
95
|
+
if ((kind === "api" || action === "create" || description !== undefined) && !hasSellerDescription(description))
|
|
96
|
+
throw new CLIError("INVALID_INPUT", "Description must contain at least 150 characters", { field: descriptionField });
|
|
97
|
+
if (kind === "api" && isResourceApi(input.catalogType ?? current?.catalogType)) {
|
|
98
|
+
const missing = ["overviewHtml", ...resourceContentFields].filter(field =>
|
|
99
|
+
!hasArticleContent(Object.hasOwn(input, field) ? input[field] : current?.[field]),
|
|
100
|
+
);
|
|
101
|
+
if (missing.length)
|
|
102
|
+
throw new CLIError("INVALID_INPUT", "Resource rich text is required", { fields: missing });
|
|
103
|
+
}
|
|
104
|
+
if (kind === "api") {
|
|
105
|
+
const fields = asyncConfigurationFields({ ...current, ...input });
|
|
106
|
+
if (fields.length)
|
|
107
|
+
throw new CLIError("INVALID_INPUT", "Async delivery configuration is incomplete or invalid", { fields });
|
|
108
|
+
}
|
|
109
|
+
if (kind === "model" && action === "create") {
|
|
110
|
+
for (const [index, route] of (input.routes ?? []).entries()) {
|
|
111
|
+
if (!hasText(route.publicModel) || route.familyId) continue;
|
|
112
|
+
const families = await client.request("/model-families", { query: { publicModel: route.publicModel.trim() } });
|
|
113
|
+
if (!Array.isArray(families) || !families.some(family => family?.assigned === true))
|
|
114
|
+
throw new CLIError("INVALID_INPUT", "Select an existing family for the public model", { field: `routes[${index}].familyId` });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
return client.write(
|
|
119
|
+
path,
|
|
120
|
+
action === "create" ? "POST" : "PUT",
|
|
121
|
+
input,
|
|
122
|
+
o.operation,
|
|
123
|
+
{ validate },
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (action === "publish" || action === "unpublish") {
|
|
127
|
+
const input = await ctx.input();
|
|
128
|
+
assertNoSecrets(input);
|
|
129
|
+
await client.capabilities(kind);
|
|
130
|
+
requireValue(input[kind === "model" ? "expectedVersion" : "expectedRevision"], "expected version");
|
|
131
|
+
if (kind === "api" && action === "publish")
|
|
132
|
+
requireValue(input.expectedUpstreamRevision, "expectedUpstreamRevision");
|
|
133
|
+
return client.write(path + "/" + action, "POST", input, o.operation);
|
|
134
|
+
}
|
|
135
|
+
if (action === "verify") {
|
|
136
|
+
const input = await ctx.input();
|
|
137
|
+
assertNoSecrets(input);
|
|
138
|
+
const requestPath = input.request?.path;
|
|
139
|
+
if (kind === "model" && requestPath !== undefined &&
|
|
140
|
+
(requestPath === null || typeof requestPath !== "object" ||
|
|
141
|
+
Array.isArray(requestPath) || Object.keys(requestPath).length > 0))
|
|
142
|
+
throw new CLIError(
|
|
143
|
+
"INVALID_INPUT",
|
|
144
|
+
"Model verification request.path must be an empty object {} when supplied, not a URL or path parameters. Use endpointIndex to select the saved price.upstreamPath endpoint.",
|
|
145
|
+
{ field: "request.path" },
|
|
146
|
+
);
|
|
147
|
+
const capabilities = await client.capabilities(kind);
|
|
148
|
+
if (!capabilities.resources[kind].verification)
|
|
149
|
+
throw new CLIError(
|
|
150
|
+
"VERIFICATION_UNAVAILABLE",
|
|
151
|
+
"Verification is unavailable for this resource type",
|
|
152
|
+
);
|
|
153
|
+
requireValue(
|
|
154
|
+
input[kind === "model" ? "expectedVersion" : "expectedRevision"],
|
|
155
|
+
"expected version",
|
|
156
|
+
);
|
|
157
|
+
requireValue(input.expectedUpstreamRevision, "expectedUpstreamRevision");
|
|
158
|
+
return client.write(path + "/verifications", "POST", input, o.operation, {
|
|
159
|
+
verification: true,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (action === "submit") {
|
|
163
|
+
const capabilities = await client.capabilities(kind);
|
|
164
|
+
if (capabilities.reviewPolicy === "seller_application")
|
|
165
|
+
throw new CLIError("RESOURCE_REVIEW_RETIRED", "Publish verified resources directly with the publish command after provider admission");
|
|
166
|
+
if (!capabilities.reviewReady || !capabilities.runtimeReady)
|
|
167
|
+
throw new CLIError(
|
|
168
|
+
"PROVIDER_REVIEW_UNAVAILABLE",
|
|
169
|
+
"Review service is not ready",
|
|
170
|
+
);
|
|
171
|
+
const current = await client.request(
|
|
172
|
+
path + (kind === "model" ? "/publication" : ""),
|
|
173
|
+
);
|
|
174
|
+
if (current.firstPublishedAt)
|
|
175
|
+
throw new CLIError(
|
|
176
|
+
"PROVIDER_RESOURCE_ALREADY_PUBLISHED",
|
|
177
|
+
"Published resources cannot be resubmitted",
|
|
178
|
+
);
|
|
179
|
+
let input;
|
|
180
|
+
if (kind === "api") {
|
|
181
|
+
const v = current.verification;
|
|
182
|
+
const currentPass = v?.state === "passed" &&
|
|
183
|
+
!v.stale &&
|
|
184
|
+
v.apiId === o.id &&
|
|
185
|
+
v.apiRevision === current.revision &&
|
|
186
|
+
v.upstreamKeyId === current.upstreamKeyId &&
|
|
187
|
+
v.upstreamRevision === current.upstreamRevision;
|
|
188
|
+
const verificationId = current.passedVerificationId ?? (currentPass ? v.id : null);
|
|
189
|
+
if (!verificationId)
|
|
190
|
+
throw new CLIError(
|
|
191
|
+
"PROVIDER_RESOURCE_NOT_READY",
|
|
192
|
+
"A passed verification is required",
|
|
193
|
+
);
|
|
194
|
+
input = {
|
|
195
|
+
expectedRevision: current.revision,
|
|
196
|
+
connections: [
|
|
197
|
+
{
|
|
198
|
+
connectionId: current.upstreamKeyId,
|
|
199
|
+
revision: current.upstreamRevision,
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
verificationIds: [verificationId],
|
|
203
|
+
};
|
|
204
|
+
} else {
|
|
205
|
+
const connections = new Map(),
|
|
206
|
+
ids = [];
|
|
207
|
+
if (!current.routes?.length)
|
|
208
|
+
throw new CLIError(
|
|
209
|
+
"PROVIDER_RESOURCE_NOT_READY",
|
|
210
|
+
"Model routes are required",
|
|
211
|
+
);
|
|
212
|
+
for (const route of current.routes) {
|
|
213
|
+
const v = route.verification;
|
|
214
|
+
if (
|
|
215
|
+
!route.upstreamKeyId ||
|
|
216
|
+
!v ||
|
|
217
|
+
v.state !== "passed" ||
|
|
218
|
+
v.stale ||
|
|
219
|
+
v.modelId !== o.id ||
|
|
220
|
+
v.modelVersion !== current.version ||
|
|
221
|
+
v.routeId !== route.routeId ||
|
|
222
|
+
v.upstreamKeyId !== route.upstreamKeyId ||
|
|
223
|
+
v.upstreamRevision !== route.upstreamRevision
|
|
224
|
+
)
|
|
225
|
+
throw new CLIError(
|
|
226
|
+
"PROVIDER_RESOURCE_NOT_READY",
|
|
227
|
+
"Every saved route requires current passed verification",
|
|
228
|
+
{ routeId: route.routeId },
|
|
229
|
+
);
|
|
230
|
+
connections.set(route.upstreamKeyId, route.upstreamRevision);
|
|
231
|
+
ids.push(v.id);
|
|
232
|
+
}
|
|
233
|
+
input = {
|
|
234
|
+
expectedVersion: current.version,
|
|
235
|
+
connections: [...connections].map(([connectionId, revision]) => ({
|
|
236
|
+
connectionId,
|
|
237
|
+
revision,
|
|
238
|
+
})),
|
|
239
|
+
verificationIds: ids,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
return client.write(
|
|
243
|
+
path + "/review-submissions",
|
|
244
|
+
"POST",
|
|
245
|
+
input,
|
|
246
|
+
o.operation,
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
throw new CLIError(
|
|
250
|
+
"UNKNOWN_COMMAND",
|
|
251
|
+
"Resource commands: list|get|create|update|verify|publish|unpublish|submit",
|
|
252
|
+
);
|
|
253
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CLIError } from "./errors.js";
|
|
2
|
+
import { assertNoSecrets, receipt } from "./provider-state.js";
|
|
3
|
+
export async function runProfile(action, client, ctx) {
|
|
4
|
+
if (action === "list") return client.request("", {}, true);
|
|
5
|
+
if (action === "create") {
|
|
6
|
+
const input = await ctx.input();
|
|
7
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
8
|
+
throw new CLIError(
|
|
9
|
+
"INVALID_INPUT",
|
|
10
|
+
"Supplier registration must be a website registration JSON object",
|
|
11
|
+
);
|
|
12
|
+
assertNoSecrets(input);
|
|
13
|
+
if (Object.hasOwn(input, "provider") || Object.hasOwn(input, "provider_types"))
|
|
14
|
+
throw new CLIError("INVALID_INPUT", "Use seller and seller_types in the registration file", { field: "seller" });
|
|
15
|
+
if (!input.seller || typeof input.seller !== "object" || Array.isArray(input.seller) ||
|
|
16
|
+
typeof input.seller.slug !== "string" || input.seller.slug.length > 63 ||
|
|
17
|
+
!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(input.seller.slug))
|
|
18
|
+
throw new CLIError("INVALID_INPUT", "Enter seller.slug using 1–63 lowercase letters, digits, and single hyphens", { field: "seller.slug" });
|
|
19
|
+
if (!Array.isArray(input.seller_types) || input.seller_types.length < 1 ||
|
|
20
|
+
input.seller_types.length > 2 || new Set(input.seller_types).size !== input.seller_types.length ||
|
|
21
|
+
input.seller_types.some(type => !["model", "api"].includes(type)))
|
|
22
|
+
throw new CLIError("INVALID_INPUT", "Explicitly select seller_types: [\"model\"], [\"api\"], or [\"model\", \"api\"]. Missing types must not default to API-only.", { field: "seller_types" });
|
|
23
|
+
for (const key of [
|
|
24
|
+
"modelsUrl",
|
|
25
|
+
"modelsURL",
|
|
26
|
+
"active",
|
|
27
|
+
"publicationPolicy",
|
|
28
|
+
"applicantUserId",
|
|
29
|
+
]) {
|
|
30
|
+
if (Object.hasOwn(input, key))
|
|
31
|
+
throw new CLIError(
|
|
32
|
+
"FORBIDDEN_FIELD",
|
|
33
|
+
"Create supplier information only; configure connections and resources separately",
|
|
34
|
+
{ field: key },
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const { seller, seller_types, ...rest } = input;
|
|
38
|
+
const provider = { ...seller };
|
|
39
|
+
if (Object.hasOwn(provider, "bio")) {
|
|
40
|
+
if (typeof provider.bio !== "string" || [...provider.bio.trim()].length > 280)
|
|
41
|
+
throw new CLIError("INVALID_INPUT", "Enter seller.bio as text with at most 280 characters", { field: "seller.bio" });
|
|
42
|
+
provider.bio = provider.bio.trim();
|
|
43
|
+
}
|
|
44
|
+
const registration = { ...rest, provider, provider_types: seller_types };
|
|
45
|
+
return receipt(await client.write("", "POST", registration, ctx.options.operation, {
|
|
46
|
+
registration: true,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
if (action === "status") {
|
|
50
|
+
const result = {
|
|
51
|
+
local: {
|
|
52
|
+
configured: true,
|
|
53
|
+
email: client.identity.email,
|
|
54
|
+
userId: client.identity.userId,
|
|
55
|
+
mailboxAccess: "agent_must_verify",
|
|
56
|
+
applicationId: client.application || null,
|
|
57
|
+
},
|
|
58
|
+
remote: null,
|
|
59
|
+
};
|
|
60
|
+
if (client.application) result.remote = await client.capabilities();
|
|
61
|
+
else result.missing = ["application"];
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
throw new CLIError("UNKNOWN_COMMAND", "Applications support list|create");
|
|
65
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CLIError, requireValue } from "./errors.js";
|
|
2
|
+
import { uuid } from "./provider-state.js";
|
|
3
|
+
export async function runReviews(action, client, ctx) {
|
|
4
|
+
const o = ctx.options;
|
|
5
|
+
if (action === "list")
|
|
6
|
+
return client.request("/review-submissions", {
|
|
7
|
+
query: {
|
|
8
|
+
resourceType: o.type,
|
|
9
|
+
resourceId: o["resource-id"],
|
|
10
|
+
status: o.status,
|
|
11
|
+
limit: o.limit,
|
|
12
|
+
cursor: o.cursor,
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
const path = "/review-submissions/" + uuid(requireValue(o.id, "--id"));
|
|
16
|
+
if (action === "get") return client.request(path);
|
|
17
|
+
if (action === "withdraw") {
|
|
18
|
+
const input = await ctx.input();
|
|
19
|
+
if (
|
|
20
|
+
!Number.isInteger(input.expectedReviewVersion) ||
|
|
21
|
+
input.expectedReviewVersion < 1
|
|
22
|
+
)
|
|
23
|
+
throw new CLIError("INVALID_INPUT", "expectedReviewVersion is required");
|
|
24
|
+
return client.write(path + "/withdraw", "POST", input, o.operation);
|
|
25
|
+
}
|
|
26
|
+
if (action === "wait") {
|
|
27
|
+
const seconds = Number(o["timeout-seconds"] ?? 120);
|
|
28
|
+
if (!Number.isFinite(seconds) || seconds < 0 || seconds > 600)
|
|
29
|
+
throw new CLIError(
|
|
30
|
+
"INVALID_INPUT",
|
|
31
|
+
"timeout-seconds must be between 0 and 600",
|
|
32
|
+
);
|
|
33
|
+
const now = ctx.now || Date.now,
|
|
34
|
+
sleep = ctx.sleep || ((ms) => new Promise((r) => setTimeout(r, ms))),
|
|
35
|
+
deadline = now() + seconds * 1000;
|
|
36
|
+
let delay = 1000,
|
|
37
|
+
last;
|
|
38
|
+
while (true) {
|
|
39
|
+
try {
|
|
40
|
+
last = await client.request(path);
|
|
41
|
+
if (
|
|
42
|
+
last.status !== "pending_review" &&
|
|
43
|
+
!(
|
|
44
|
+
last.status === "approved" &&
|
|
45
|
+
["pending", "syncing"].includes(last.publication?.state)
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
return last;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (Number(e.details?.status) !== 429) throw e;
|
|
51
|
+
}
|
|
52
|
+
if (now() >= deadline) return { reviewId: o.id, ...last, timedOut: true };
|
|
53
|
+
await sleep(Math.min(delay, deadline - now()));
|
|
54
|
+
delay = Math.min(delay * 2, 10000);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
throw new CLIError(
|
|
58
|
+
"UNKNOWN_COMMAND",
|
|
59
|
+
"Reviews support list|get|withdraw|wait",
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { CLIError } from "./errors.js";
|
|
3
|
+
export const CONTRACT_VERSION = "seller-resource-reviews-v1";
|
|
4
|
+
export const digest = (value) =>
|
|
5
|
+
createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
6
|
+
export const uuid = (value, name = "id") => {
|
|
7
|
+
if (
|
|
8
|
+
typeof value !== "string" ||
|
|
9
|
+
!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
|
|
10
|
+
value,
|
|
11
|
+
)
|
|
12
|
+
)
|
|
13
|
+
throw new CLIError("INVALID_INPUT", `${name} must be a UUID`);
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
export function assertNoSecrets(value, path = "$") {
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
value.forEach((v, i) => assertNoSecrets(v, `${path}[${i}]`));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (value && typeof value === "object")
|
|
22
|
+
for (const [k, v] of Object.entries(value)) {
|
|
23
|
+
// OpenAPI uses arbitrary scheme names (including "apiKey") as map keys.
|
|
24
|
+
// Only schema declarations and scope arrays get this exception; their
|
|
25
|
+
// children are still inspected, and credential values remain forbidden.
|
|
26
|
+
const schemeDeclaration =
|
|
27
|
+
path === "$.components.securitySchemes" &&
|
|
28
|
+
v &&
|
|
29
|
+
typeof v === "object" &&
|
|
30
|
+
["apiKey", "http", "oauth2", "openIdConnect", "mutualTLS"].includes(
|
|
31
|
+
v.type,
|
|
32
|
+
);
|
|
33
|
+
const securityReference =
|
|
34
|
+
/\.security\[\d+\]$/.test(path) &&
|
|
35
|
+
Array.isArray(v) &&
|
|
36
|
+
v.every((scope) => typeof scope === "string");
|
|
37
|
+
if (
|
|
38
|
+
!schemeDeclaration &&
|
|
39
|
+
!securityReference &&
|
|
40
|
+
/^(authorization|proxy-authorization|api[-_]?key|x-api-key|access[-_]?token|refresh[-_]?token|password|secret|cookie|set-cookie)$/i.test(
|
|
41
|
+
k,
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
throw new CLIError(
|
|
45
|
+
"SECRET_IN_DOCUMENT",
|
|
46
|
+
"Local credential scan rejected this field. Remove authentication headers and credentials from documents; configure authentication through secure connection input.",
|
|
47
|
+
{ field: `${path}.${k}`, stage: "local" },
|
|
48
|
+
);
|
|
49
|
+
assertNoSecrets(v, `${path}.${k}`);
|
|
50
|
+
}
|
|
51
|
+
else if (
|
|
52
|
+
typeof value === "string" &&
|
|
53
|
+
(/\bBearer\s+[\w.+\/-]+/i.test(value) ||
|
|
54
|
+
/[?&](?:api[_-]?key|token|secret|password|key)=/i.test(value) ||
|
|
55
|
+
/^https?:\/\/[^/]+:[^/]+@/i.test(value))
|
|
56
|
+
)
|
|
57
|
+
throw new CLIError(
|
|
58
|
+
"SECRET_IN_DOCUMENT",
|
|
59
|
+
"Local credential scan rejected possible credentials, including placeholder credentials. Omit authentication headers from curlExample and configure authentication through secure connection input.",
|
|
60
|
+
{ field: path, stage: "local" },
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
export function receipt(value) {
|
|
64
|
+
const out = value?.price?.id ? { id: value.price.id } : {};
|
|
65
|
+
for (const k of [
|
|
66
|
+
"id",
|
|
67
|
+
"applicationId",
|
|
68
|
+
"resourceId",
|
|
69
|
+
"resourceType",
|
|
70
|
+
"version",
|
|
71
|
+
"revision",
|
|
72
|
+
"upstreamRevision",
|
|
73
|
+
"status",
|
|
74
|
+
"state",
|
|
75
|
+
"stale",
|
|
76
|
+
"modelVersion",
|
|
77
|
+
"modelId",
|
|
78
|
+
"apiId",
|
|
79
|
+
"apiRevision",
|
|
80
|
+
"routeId",
|
|
81
|
+
"upstreamKeyId",
|
|
82
|
+
"reviewId",
|
|
83
|
+
"reviewStatus",
|
|
84
|
+
"reviewVersion",
|
|
85
|
+
"providerTypes",
|
|
86
|
+
"sourceVersion",
|
|
87
|
+
"publication",
|
|
88
|
+
"verificationIds",
|
|
89
|
+
"connections",
|
|
90
|
+
])
|
|
91
|
+
if (value?.[k] !== undefined) out[k] = value[k];
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
export const uncertain = (e) =>
|
|
95
|
+
[
|
|
96
|
+
"NETWORK_ERROR",
|
|
97
|
+
"REQUEST_TIMEOUT",
|
|
98
|
+
"INVALID_RESPONSE",
|
|
99
|
+
"OPERATION_UNCERTAIN",
|
|
100
|
+
"SESSION_CHANGED",
|
|
101
|
+
].includes(e.code) ||
|
|
102
|
+
Number(e.details?.status) >= 500 ||
|
|
103
|
+
[408, 0].includes(Number(e.details?.status));
|
|
104
|
+
export async function reserve(store, identity, operation, request) {
|
|
105
|
+
if (
|
|
106
|
+
typeof operation !== "string" ||
|
|
107
|
+
!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(operation) ||
|
|
108
|
+
["__proto__", "constructor", "prototype"].includes(operation)
|
|
109
|
+
)
|
|
110
|
+
throw new CLIError(
|
|
111
|
+
"INVALID_INPUT",
|
|
112
|
+
"operation must use 1–128 letters, digits, dots, underscores or hyphens",
|
|
113
|
+
);
|
|
114
|
+
const hash = digest(request);
|
|
115
|
+
return store.update((s) => {
|
|
116
|
+
s.provider ??= { operations: {}, batches: {} };
|
|
117
|
+
s.provider.operations ??= {};
|
|
118
|
+
const previous = s.provider.operations[operation];
|
|
119
|
+
if (previous) {
|
|
120
|
+
if (
|
|
121
|
+
previous.userId !== identity.userId ||
|
|
122
|
+
previous.application !== identity.application
|
|
123
|
+
)
|
|
124
|
+
throw new CLIError(
|
|
125
|
+
"SESSION_CHANGED",
|
|
126
|
+
"Operation belongs to a different account or supplier",
|
|
127
|
+
);
|
|
128
|
+
if (previous.hash !== hash)
|
|
129
|
+
throw new CLIError(
|
|
130
|
+
"IDEMPOTENCY_CONFLICT",
|
|
131
|
+
"This operation belongs to a different request. Reconcile the original outcome first; do not switch names to retry an unknown result. Use a new operation only for an independent write or corrected input after the original outcome is known.",
|
|
132
|
+
{ operation, state: previous.state, resourceId: previous.resourceId },
|
|
133
|
+
);
|
|
134
|
+
return previous;
|
|
135
|
+
}
|
|
136
|
+
return (s.provider.operations[operation] = {
|
|
137
|
+
...identity,
|
|
138
|
+
operation,
|
|
139
|
+
path: request.path,
|
|
140
|
+
method: request.method,
|
|
141
|
+
resourceId:
|
|
142
|
+
request.path.match(/\/(?:models|agent-apis)\/([^/]+)/)?.[1] || null,
|
|
143
|
+
hash,
|
|
144
|
+
key: randomUUID(),
|
|
145
|
+
state: "ready",
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
export async function updateOperation(store, operation, change) {
|
|
150
|
+
return store.update((s) => {
|
|
151
|
+
const op = s.provider?.operations?.[operation];
|
|
152
|
+
if (!op) throw new CLIError("OPERATION_NOT_FOUND", "Operation not found");
|
|
153
|
+
Object.assign(op, change);
|
|
154
|
+
if (change.state === "completed" && op.resourceId && change.result?.id) {
|
|
155
|
+
for (const batch of Object.values(s.provider.batches || {})) {
|
|
156
|
+
if (batch.userId !== op.userId || batch.application !== op.application)
|
|
157
|
+
continue;
|
|
158
|
+
const item = batch.items.find(
|
|
159
|
+
(entry) => entry.resourceId === op.resourceId,
|
|
160
|
+
);
|
|
161
|
+
if (!item) continue;
|
|
162
|
+
const field = op.path.endsWith("/verifications")
|
|
163
|
+
? "verifications"
|
|
164
|
+
: op.path.endsWith("/review-submissions")
|
|
165
|
+
? "reviews"
|
|
166
|
+
: null;
|
|
167
|
+
if (field) {
|
|
168
|
+
item[field] ??= [];
|
|
169
|
+
if (!item[field].some((entry) => entry.id === change.result.id))
|
|
170
|
+
item[field].push(change.result);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return op;
|
|
175
|
+
});
|
|
176
|
+
}
|
package/src/provider.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ProviderClient } from "./provider-client.js";
|
|
2
|
+
import { CLIError } from "./errors.js";
|
|
3
|
+
import { runProfile } from "./provider-profile.js";
|
|
4
|
+
import { runConnections } from "./provider-connections.js";
|
|
5
|
+
import { runResource } from "./provider-models.js";
|
|
6
|
+
import { runReviews } from "./provider-reviews.js";
|
|
7
|
+
import { runImports } from "./provider-imports.js";
|
|
8
|
+
import { parseProviderJSON, readProviderJSON } from "./provider-json.js";
|
|
9
|
+
export async function runProvider(args, ctx) {
|
|
10
|
+
const group = args[1],
|
|
11
|
+
action = args[2] || "list";
|
|
12
|
+
if (ctx.options.public || ctx.options.workspace || ctx.options["dry-run"])
|
|
13
|
+
throw new CLIError(
|
|
14
|
+
"INVALID_INPUT",
|
|
15
|
+
"Seller commands require an account session and do not accept public/workspace/dry-run flags",
|
|
16
|
+
);
|
|
17
|
+
const input = ctx.input;
|
|
18
|
+
ctx.input = async () => {
|
|
19
|
+
if (ctx.options.file !== undefined && ctx.options.input !== undefined)
|
|
20
|
+
throw new CLIError("INVALID_INPUT", "Choose --file or --input");
|
|
21
|
+
if (ctx.options.file !== undefined)
|
|
22
|
+
return readProviderJSON(ctx.options.file);
|
|
23
|
+
if (ctx.options.input !== undefined)
|
|
24
|
+
return parseProviderJSON(ctx.options.input);
|
|
25
|
+
const value = await input();
|
|
26
|
+
if (value === undefined)
|
|
27
|
+
throw new CLIError("INPUT_REQUIRED", "Supply JSON configuration with --file PATH or --input JSON (choose one)");
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
let client;
|
|
31
|
+
try {
|
|
32
|
+
client = await ProviderClient.connect(ctx);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (group === "status" && error.code === "CONFIG_REQUIRED")
|
|
35
|
+
return {
|
|
36
|
+
local: { configured: false, mailboxAccess: "agent_must_verify" },
|
|
37
|
+
remote: null,
|
|
38
|
+
missing: ["email_session"],
|
|
39
|
+
};
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
if (group === "status") return runProfile("status", client, ctx);
|
|
43
|
+
if (group === "applications") return runProfile(action, client, ctx);
|
|
44
|
+
if (group === "connections") return runConnections(action, client, ctx);
|
|
45
|
+
if (group === "models" || group === "apis")
|
|
46
|
+
return runResource(
|
|
47
|
+
group === "models" ? "model" : "api",
|
|
48
|
+
action,
|
|
49
|
+
client,
|
|
50
|
+
ctx,
|
|
51
|
+
);
|
|
52
|
+
if (group === "reviews") return runReviews(action, client, ctx);
|
|
53
|
+
if (group === "imports") return runImports(action, client, ctx);
|
|
54
|
+
if (group === "schema") {
|
|
55
|
+
if (
|
|
56
|
+
![
|
|
57
|
+
"model",
|
|
58
|
+
"api",
|
|
59
|
+
"connection",
|
|
60
|
+
"review-model",
|
|
61
|
+
"review-api",
|
|
62
|
+
"model-import",
|
|
63
|
+
].includes(ctx.options.type)
|
|
64
|
+
)
|
|
65
|
+
throw new CLIError(
|
|
66
|
+
"INVALID_INPUT",
|
|
67
|
+
"Select a seller schema with --type",
|
|
68
|
+
);
|
|
69
|
+
return client.request("/schemas/" + ctx.options.type);
|
|
70
|
+
}
|
|
71
|
+
throw new CLIError(
|
|
72
|
+
"UNKNOWN_COMMAND",
|
|
73
|
+
"Seller commands: status|applications|connections|models|apis|reviews|imports|schema",
|
|
74
|
+
);
|
|
75
|
+
}
|