@orth/cli 0.3.0 → 0.4.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/CHANGELOG.md +41 -0
- package/README.md +113 -109
- package/dist/analytics.d.ts +37 -3
- package/dist/analytics.js +253 -39
- package/dist/api.d.ts +28 -2
- package/dist/api.js +67 -13
- package/dist/command-actions.d.ts +10 -0
- package/dist/command-actions.js +42 -0
- package/dist/commands/account.d.ts +9 -1
- package/dist/commands/account.js +26 -10
- package/dist/commands/api.d.ts +3 -0
- package/dist/commands/api.js +104 -114
- package/dist/commands/auth.d.ts +3 -1
- package/dist/commands/auth.js +53 -9
- package/dist/commands/onboard/flow.d.ts +22 -0
- package/dist/commands/onboard/flow.js +155 -0
- package/dist/commands/onboard/guide.d.ts +8 -0
- package/dist/commands/onboard/guide.js +73 -0
- package/dist/commands/onboard/listing.d.ts +18 -0
- package/dist/commands/onboard/listing.js +166 -0
- package/dist/commands/onboard/progress.d.ts +44 -0
- package/dist/commands/onboard/progress.js +108 -0
- package/dist/commands/onboard/register.d.ts +2 -0
- package/dist/commands/onboard/register.js +261 -0
- package/dist/commands/onboard/requests.d.ts +24 -0
- package/dist/commands/onboard/requests.js +96 -0
- package/dist/commands/onboard/review.d.ts +31 -0
- package/dist/commands/onboard/review.js +228 -0
- package/dist/commands/onboard/setup.d.ts +68 -0
- package/dist/commands/onboard/setup.js +215 -0
- package/dist/commands/onboard/shared.d.ts +41 -0
- package/dist/commands/onboard/shared.js +97 -0
- package/dist/commands/onboard/tools.d.ts +19 -0
- package/dist/commands/onboard/tools.js +104 -0
- package/dist/commands/org.d.ts +21 -0
- package/dist/commands/org.js +126 -0
- package/dist/commands/payouts.d.ts +44 -0
- package/dist/commands/payouts.js +125 -0
- package/dist/commands/run.d.ts +1 -1
- package/dist/commands/run.js +18 -26
- package/dist/commands/search.d.ts +8 -1
- package/dist/commands/search.js +26 -4
- package/dist/commands/skills/browse.d.ts +15 -0
- package/dist/commands/skills/browse.js +194 -0
- package/dist/commands/skills/create.d.ts +5 -0
- package/dist/commands/skills/create.js +62 -0
- package/dist/commands/skills/init.d.ts +4 -0
- package/dist/commands/skills/init.js +123 -0
- package/dist/commands/skills/install.d.ts +6 -0
- package/dist/commands/skills/install.js +191 -0
- package/dist/commands/skills/local-files.d.ts +15 -0
- package/dist/commands/skills/local-files.js +110 -0
- package/dist/commands/skills/register.d.ts +2 -0
- package/dist/commands/skills/register.js +130 -0
- package/dist/commands/skills/shared.d.ts +43 -0
- package/dist/commands/skills/shared.js +69 -0
- package/dist/commands/skills/upload.d.ts +9 -0
- package/dist/commands/skills/upload.js +223 -0
- package/dist/commands/skills/verification.d.ts +5 -0
- package/dist/commands/skills/verification.js +74 -0
- package/dist/commands/telemetry.d.ts +3 -0
- package/dist/commands/telemetry.js +38 -0
- package/dist/config.d.ts +48 -1
- package/dist/config.js +99 -3
- package/dist/http.d.ts +15 -0
- package/dist/http.js +41 -0
- package/dist/index.js +131 -165
- package/dist/organizations.d.ts +14 -0
- package/dist/organizations.js +77 -0
- package/dist/urls.d.ts +3 -0
- package/dist/urls.js +34 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.js +112 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +21 -0
- package/dist/x402.d.ts +7 -0
- package/dist/x402.js +27 -0
- package/package.json +23 -22
- package/dist/commands/skills.d.ts +0 -66
- package/dist/commands/skills.js +0 -821
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Organization } from "../../config.js";
|
|
2
|
+
import { type OnboardFlowOptions } from "./shared.js";
|
|
3
|
+
interface SetupSummary {
|
|
4
|
+
revision: number;
|
|
5
|
+
/** The listing version this setup is, or becomes once accepted. */
|
|
6
|
+
version: number;
|
|
7
|
+
liveVersion: number | null;
|
|
8
|
+
name: string;
|
|
9
|
+
baseUrl: string | null;
|
|
10
|
+
description: string | null;
|
|
11
|
+
key: {
|
|
12
|
+
location: string;
|
|
13
|
+
name: string;
|
|
14
|
+
prefix: string | null;
|
|
15
|
+
} | null;
|
|
16
|
+
endpoints: {
|
|
17
|
+
method: string;
|
|
18
|
+
path: string;
|
|
19
|
+
name: string;
|
|
20
|
+
priced: boolean;
|
|
21
|
+
/** A fixed price per call ("0" is free); null while unpriced or dynamic. */
|
|
22
|
+
price: string | null;
|
|
23
|
+
dynamic: boolean;
|
|
24
|
+
/** A dynamic endpoint's fallback, charged only when a response can't be priced. */
|
|
25
|
+
fallbackPrice?: string;
|
|
26
|
+
/** A dynamic endpoint's per-call maximum: larger calls are refused before charging. */
|
|
27
|
+
maxPrice?: string | null;
|
|
28
|
+
/** The price in plain words. */
|
|
29
|
+
pricing: string;
|
|
30
|
+
}[];
|
|
31
|
+
/** What was left out of the listing, by whom and why. */
|
|
32
|
+
leftOut: {
|
|
33
|
+
method: string;
|
|
34
|
+
path: string;
|
|
35
|
+
name: string;
|
|
36
|
+
by: "orth" | "provider";
|
|
37
|
+
reason: string;
|
|
38
|
+
}[];
|
|
39
|
+
finalReport: string | null;
|
|
40
|
+
}
|
|
41
|
+
export declare function fetchSetup(org: Organization, requestId: string): Promise<SetupSummary>;
|
|
42
|
+
/**
|
|
43
|
+
* orth api-onboarding setup [api] - The setup to review: base URL, key, endpoints, prices
|
|
44
|
+
*/
|
|
45
|
+
export declare function onboardSetupCommand(given: string | undefined, options: OnboardFlowOptions): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* orth api-onboarding base-url <url> [api] - The address the API is served from
|
|
48
|
+
*/
|
|
49
|
+
export declare function onboardBaseUrlCommand(url: string, given: string | undefined, options: OnboardFlowOptions): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* orth api-onboarding confirm [api] - Review the setup, then confirm it
|
|
52
|
+
*/
|
|
53
|
+
export declare function onboardConfirmCommand(given: string | undefined, options: OnboardFlowOptions & {
|
|
54
|
+
yes?: boolean;
|
|
55
|
+
}): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* orth api-onboarding key [api] - Add the API key, typed hidden (or piped)
|
|
58
|
+
*/
|
|
59
|
+
export declare function onboardKeyCommand(given: string | undefined, options: OnboardFlowOptions): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* orth api-onboarding price <endpoint> <usd|free> [api] - Your price per call
|
|
62
|
+
*/
|
|
63
|
+
export declare function onboardPriceCommand(endpoint: string, price: string, given: string | undefined, options: OnboardFlowOptions): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* orth api-onboarding leave-out <endpoint> [api] - Keep an endpoint out of the listing
|
|
66
|
+
*/
|
|
67
|
+
export declare function onboardLeaveOutCommand(endpoint: string, given: string | undefined, options: OnboardFlowOptions): Promise<void>;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fetchSetup = fetchSetup;
|
|
7
|
+
exports.onboardSetupCommand = onboardSetupCommand;
|
|
8
|
+
exports.onboardBaseUrlCommand = onboardBaseUrlCommand;
|
|
9
|
+
exports.onboardConfirmCommand = onboardConfirmCommand;
|
|
10
|
+
exports.onboardKeyCommand = onboardKeyCommand;
|
|
11
|
+
exports.onboardPriceCommand = onboardPriceCommand;
|
|
12
|
+
exports.onboardLeaveOutCommand = onboardLeaveOutCommand;
|
|
13
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const utils_js_1 = require("../../utils.js");
|
|
15
|
+
const requests_js_1 = require("./requests.js");
|
|
16
|
+
const shared_js_1 = require("./shared.js");
|
|
17
|
+
/** An endpoint's price; a dynamic one up to its maximum (its fallback is no minimum). */
|
|
18
|
+
function priceOf({ priced, price, dynamic, maxPrice }) {
|
|
19
|
+
if (!priced)
|
|
20
|
+
return "not priced";
|
|
21
|
+
if (dynamic)
|
|
22
|
+
return maxPrice ? `dynamic, up to $${(0, shared_js_1.clean)(maxPrice)}` : "dynamic";
|
|
23
|
+
return Number(price) === 0 ? "free" : `$${(0, shared_js_1.clean)(price ?? "")}/call`;
|
|
24
|
+
}
|
|
25
|
+
function keyPlace(key) {
|
|
26
|
+
const name = (0, shared_js_1.clean)(key.name);
|
|
27
|
+
if (key.location === "none")
|
|
28
|
+
return "none: every endpoint is public";
|
|
29
|
+
return key.location === "query"
|
|
30
|
+
? `query parameter "${name}"`
|
|
31
|
+
: `header "${name}"${key.prefix ? ` as "${(0, shared_js_1.clean)(key.prefix)}${/\s$/.test(key.prefix) ? " " : ""}<key>"` : ""}`;
|
|
32
|
+
}
|
|
33
|
+
function printSetup(setup, org) {
|
|
34
|
+
console.log(chalk_1.default.bold(`\n ${(0, shared_js_1.clean)(setup.name)}`) +
|
|
35
|
+
chalk_1.default.gray(` ${(0, utils_js_1.sanitizeForTerminal)(org.name)} · revision ${setup.revision}\n`));
|
|
36
|
+
console.log((0, shared_js_1.row)("Base URL", setup.baseUrl ? (0, shared_js_1.clean)(setup.baseUrl) : chalk_1.default.yellow("not set")));
|
|
37
|
+
console.log((0, shared_js_1.row)("API key", setup.key ? keyPlace(setup.key) : chalk_1.default.gray("not decided yet")));
|
|
38
|
+
const unpriced = setup.endpoints.filter((endpoint) => !endpoint.priced).length;
|
|
39
|
+
console.log((0, shared_js_1.row)("Endpoints", `${setup.endpoints.length}${unpriced ? chalk_1.default.yellow(` (${unpriced} not priced yet)`) : ""}` +
|
|
40
|
+
(setup.leftOut.length ? chalk_1.default.gray(` · ${setup.leftOut.length} left out`) : "")));
|
|
41
|
+
if (setup.endpoints.length)
|
|
42
|
+
console.log();
|
|
43
|
+
// Padded before they are colored, so the routes line up.
|
|
44
|
+
const priced = setup.endpoints.map((endpoint) => ({ endpoint, price: priceOf(endpoint) }));
|
|
45
|
+
const width = Math.max(16, ...priced.map(({ price }) => price.length));
|
|
46
|
+
for (const { endpoint, price } of priced) {
|
|
47
|
+
// One line each: the price first, then the route, then a short name.
|
|
48
|
+
const text = price.padEnd(width);
|
|
49
|
+
console.log(` ${endpoint.priced ? text : chalk_1.default.yellow(text)} ` +
|
|
50
|
+
chalk_1.default.cyan(`${(0, shared_js_1.clean)(endpoint.method)} ${(0, shared_js_1.clean)(endpoint.path)}`) +
|
|
51
|
+
chalk_1.default.gray(` ${(0, shared_js_1.shorten)(endpoint.name, 48)}`));
|
|
52
|
+
// Under the route, what a dynamic price charges (a response-priced
|
|
53
|
+
// fallback is a real charge) or why an endpoint is not priced yet.
|
|
54
|
+
if (endpoint.dynamic || !endpoint.priced) {
|
|
55
|
+
for (const line of (0, shared_js_1.wrapped)(endpoint.pricing, width + 3))
|
|
56
|
+
console.log(chalk_1.default.gray(line));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (setup.leftOut.length) {
|
|
60
|
+
console.log(chalk_1.default.bold("\n Left out"));
|
|
61
|
+
for (const endpoint of setup.leftOut) {
|
|
62
|
+
console.log(" " +
|
|
63
|
+
chalk_1.default.cyan(`${(0, shared_js_1.clean)(endpoint.method)} ${(0, shared_js_1.clean)(endpoint.path)}`) +
|
|
64
|
+
chalk_1.default.gray(` ${endpoint.by === "orth" ? "by the Agent" : "by you"}: ${(0, shared_js_1.shorten)(endpoint.reason, 160)}`));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (setup.endpoints.length) {
|
|
68
|
+
console.log(chalk_1.default.gray(`\n Change a price: ${(0, shared_js_1.cmd)('price "GET /path" <usd|free>')}`));
|
|
69
|
+
console.log(chalk_1.default.gray(` Leave one out: ${(0, shared_js_1.cmd)('leave-out "GET /path"')}`));
|
|
70
|
+
}
|
|
71
|
+
console.log();
|
|
72
|
+
}
|
|
73
|
+
async function fetchSetup(org, requestId) {
|
|
74
|
+
return (0, shared_js_1.runTool)("get_setup", org, requestId);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* orth api-onboarding setup [api] - The setup to review: base URL, key, endpoints, prices
|
|
78
|
+
*/
|
|
79
|
+
async function onboardSetupCommand(given, options) {
|
|
80
|
+
try {
|
|
81
|
+
const { org, requestId } = await (0, requests_js_1.stepContext)(given, options, "show", "setup");
|
|
82
|
+
const setup = await fetchSetup(org, requestId);
|
|
83
|
+
if (options.json) {
|
|
84
|
+
console.log(JSON.stringify(setup, null, 2));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
printSetup(setup, org);
|
|
88
|
+
if (setup.finalReport) {
|
|
89
|
+
console.log(chalk_1.default.bold(" Final report\n"));
|
|
90
|
+
console.log(`${(0, shared_js_1.indented)(setup.finalReport)}\n`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
(0, shared_js_1.fail)(error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* orth api-onboarding base-url <url> [api] - The address the API is served from
|
|
99
|
+
*/
|
|
100
|
+
async function onboardBaseUrlCommand(url, given, options) {
|
|
101
|
+
try {
|
|
102
|
+
const baseUrl = (0, shared_js_1.httpsUrl)(url, "The base URL");
|
|
103
|
+
const { org, requestId } = await (0, requests_js_1.stepContext)(given, options, "set the base URL of", `base-url ${baseUrl}`);
|
|
104
|
+
const result = await (0, shared_js_1.runTool)("set_base_url", org, requestId, { baseUrl });
|
|
105
|
+
if (options.json) {
|
|
106
|
+
console.log(JSON.stringify(result, null, 2));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
(0, shared_js_1.done)([
|
|
110
|
+
chalk_1.default.green(`Base URL set to ${(0, shared_js_1.clean)(result.baseUrl)}.`),
|
|
111
|
+
(0, shared_js_1.goesOn)(result.agent),
|
|
112
|
+
chalk_1.default.cyan((0, shared_js_1.cmd)("status --watch")),
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
(0, shared_js_1.fail)(error);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* orth api-onboarding confirm [api] - Review the setup, then confirm it
|
|
121
|
+
*/
|
|
122
|
+
async function onboardConfirmCommand(given, options) {
|
|
123
|
+
try {
|
|
124
|
+
const { org, requestId } = await (0, requests_js_1.stepContext)(given, options, "confirm", "confirm");
|
|
125
|
+
const setup = await fetchSetup(org, requestId);
|
|
126
|
+
if (!options.json)
|
|
127
|
+
printSetup(setup, org);
|
|
128
|
+
if (!options.yes) {
|
|
129
|
+
if (!(0, utils_js_1.isInteractive)())
|
|
130
|
+
throw new Error("Pass --yes to confirm without a question.");
|
|
131
|
+
if (!(await (0, utils_js_1.confirmYes)(`Confirm this setup (revision ${setup.revision})?`))) {
|
|
132
|
+
(0, shared_js_1.done)([chalk_1.default.gray("Not confirmed. Tell the Agent what to change:"), chalk_1.default.cyan((0, shared_js_1.cmd)('start -m "<what to change>"'))]);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const result = await (0, shared_js_1.runTool)("confirm_setup", org, requestId, { expectedRevision: setup.revision });
|
|
137
|
+
if (options.json) {
|
|
138
|
+
console.log(JSON.stringify(result, null, 2));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
(0, shared_js_1.done)([chalk_1.default.green(`Confirmed revision ${result.revision}.`), (0, shared_js_1.goesOn)(result.agent), chalk_1.default.cyan((0, shared_js_1.cmd)("status"))]);
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
(0, shared_js_1.fail)(error);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* orth api-onboarding key [api] - Add the API key, typed hidden (or piped)
|
|
149
|
+
*/
|
|
150
|
+
async function onboardKeyCommand(given, options) {
|
|
151
|
+
try {
|
|
152
|
+
const { org, requestId } = await (0, requests_js_1.stepContext)(given, options, "add the key of", "key");
|
|
153
|
+
const setup = await fetchSetup(org, requestId);
|
|
154
|
+
if (!setup.key) {
|
|
155
|
+
throw new Error("The Agent hasn't decided where the key goes yet. Check: " + (0, shared_js_1.cmd)("status"));
|
|
156
|
+
}
|
|
157
|
+
if (setup.key.location === "none") {
|
|
158
|
+
throw new Error("This API needs no key: every endpoint is public.");
|
|
159
|
+
}
|
|
160
|
+
// With --json, stdout carries only the result.
|
|
161
|
+
(options.json ? console.error : console.log)(`\n Orthogonal sends the key in the ${keyPlace(setup.key)} of every call to ${(0, shared_js_1.clean)(setup.baseUrl ?? "your API")}.`);
|
|
162
|
+
const key = await (0, utils_js_1.readSecret)(" API key (hidden): ");
|
|
163
|
+
if (!key)
|
|
164
|
+
throw new Error("No key entered.");
|
|
165
|
+
const result = await (0, shared_js_1.runTool)("add_key", org, requestId, { apiKey: key });
|
|
166
|
+
if (options.json) {
|
|
167
|
+
console.log(JSON.stringify(result, null, 2));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
(0, shared_js_1.done)([
|
|
171
|
+
chalk_1.default.green(`Key saved${result.keyHint ? ` (${(0, shared_js_1.clean)(result.keyHint)})` : ""}.`),
|
|
172
|
+
`${(0, shared_js_1.goesOn)(result.agent)} It prepares the checks next.`,
|
|
173
|
+
chalk_1.default.cyan((0, shared_js_1.cmd)("status --watch")),
|
|
174
|
+
]);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
(0, shared_js_1.fail)(error);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* orth api-onboarding price <endpoint> <usd|free> [api] - Your price per call
|
|
182
|
+
*/
|
|
183
|
+
async function onboardPriceCommand(endpoint, price, given, options) {
|
|
184
|
+
try {
|
|
185
|
+
const { org, requestId } = await (0, requests_js_1.stepContext)(given, options, "price", `price "${endpoint}" ${price}`);
|
|
186
|
+
const result = await (0, shared_js_1.runTool)("set_prices", org, requestId, { prices: [{ endpoint, price }] });
|
|
187
|
+
(0, shared_js_1.report)(options, result, () => [
|
|
188
|
+
...result.changed.map((change) => chalk_1.default.green(`${(0, shared_js_1.clean)(change.endpoint)}: `) +
|
|
189
|
+
(change.price === "free" ? "free" : `$${(0, shared_js_1.clean)(change.price)}/call`)),
|
|
190
|
+
result.unpriced
|
|
191
|
+
? chalk_1.default.yellow(`${result.unpriced} more ${result.unpriced === 1 ? "endpoint needs" : "endpoints need"} a price.`)
|
|
192
|
+
: `Every endpoint has a price. Review and confirm: ${chalk_1.default.cyan((0, shared_js_1.cmd)("confirm"))}`,
|
|
193
|
+
]);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
(0, shared_js_1.fail)(error);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* orth api-onboarding leave-out <endpoint> [api] - Keep an endpoint out of the listing
|
|
201
|
+
*/
|
|
202
|
+
async function onboardLeaveOutCommand(endpoint, given, options) {
|
|
203
|
+
try {
|
|
204
|
+
const { org, requestId } = await (0, requests_js_1.stepContext)(given, options, "change", `leave-out "${endpoint}"`);
|
|
205
|
+
const result = await (0, shared_js_1.runTool)("leave_out", org, requestId, { endpoints: [endpoint] });
|
|
206
|
+
(0, shared_js_1.report)(options, result, () => [
|
|
207
|
+
chalk_1.default.green(`Left out ${result.leftOut.map(shared_js_1.clean).join(", ")}.`) +
|
|
208
|
+
chalk_1.default.gray(` ${result.endpoints} ${result.endpoints === 1 ? "endpoint stays" : "endpoints stay"}; the dashboard can restore it.`),
|
|
209
|
+
chalk_1.default.cyan((0, shared_js_1.cmd)("setup")),
|
|
210
|
+
]);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
(0, shared_js_1.fail)(error);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Organization } from "../../config.js";
|
|
2
|
+
export declare function fail(error: unknown): never;
|
|
3
|
+
/** This command group as the person runs it (`orth`, `mono-dev`, …). */
|
|
4
|
+
export declare function cmd(rest: string): string;
|
|
5
|
+
export interface RequestSummary {
|
|
6
|
+
id: string;
|
|
7
|
+
apiName: string;
|
|
8
|
+
status: "pending" | "approved" | "rejected" | "cancelled";
|
|
9
|
+
setupPhase?: string;
|
|
10
|
+
setupPendingAction?: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface OnboardFlowOptions {
|
|
13
|
+
org?: string;
|
|
14
|
+
json?: boolean;
|
|
15
|
+
message?: string;
|
|
16
|
+
watch?: boolean;
|
|
17
|
+
name?: string;
|
|
18
|
+
website?: string;
|
|
19
|
+
useCase?: string;
|
|
20
|
+
docsUrl?: string;
|
|
21
|
+
/** More documentation URLs for `new`. */
|
|
22
|
+
moreDocs?: string[];
|
|
23
|
+
yes?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** Runs one tool of POST /v1/onboarding for the organization. */
|
|
26
|
+
export declare function runTool<T>(tool: string, org: Organization, requestId?: string, input?: Record<string, unknown>): Promise<T>;
|
|
27
|
+
export declare const clean: (text: string) => string;
|
|
28
|
+
export declare function shorten(text: string, max: number): string;
|
|
29
|
+
export declare const row: (label: string, value: string) => string;
|
|
30
|
+
export declare const UUID: RegExp;
|
|
31
|
+
export declare const stripAnsi: (text: string) => string;
|
|
32
|
+
/** A full https:// address, else the sentence that says what to type. */
|
|
33
|
+
export declare function httpsUrl(value: string, what: string): string;
|
|
34
|
+
/** A long text in lines of at most 100 columns, each indented by `indent` spaces. */
|
|
35
|
+
export declare function wrapped(text: string, indent: number): string[];
|
|
36
|
+
/** Prints the result as JSON, or the lines that say what happened. */
|
|
37
|
+
export declare function report(options: OnboardFlowOptions, result: unknown, lines: () => string[]): void;
|
|
38
|
+
export declare const goesOn: (agent: string | null | undefined) => "" | "The Agent goes on in the background." | "The Agent is working; it picks this up next.";
|
|
39
|
+
/** A multi-line text (the final report) indented, each line made safe. */
|
|
40
|
+
export declare const indented: (text: string) => string;
|
|
41
|
+
export declare function done(lines: string[]): void;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.indented = exports.goesOn = exports.stripAnsi = exports.UUID = exports.row = exports.clean = void 0;
|
|
7
|
+
exports.fail = fail;
|
|
8
|
+
exports.cmd = cmd;
|
|
9
|
+
exports.runTool = runTool;
|
|
10
|
+
exports.shorten = shorten;
|
|
11
|
+
exports.httpsUrl = httpsUrl;
|
|
12
|
+
exports.wrapped = wrapped;
|
|
13
|
+
exports.report = report;
|
|
14
|
+
exports.done = done;
|
|
15
|
+
const api_js_1 = require("../../api.js");
|
|
16
|
+
const utils_js_1 = require("../../utils.js");
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
function fail(error) {
|
|
19
|
+
(0, utils_js_1.printError)(error);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
23
|
+
// The background flow: request an API, start Orthogonal's Agent on it, and
|
|
24
|
+
// follow it here or in the dashboard (the same run either way). Nobody needs
|
|
25
|
+
// an id: the organization and the request are found or picked by name.
|
|
26
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
27
|
+
/** This command group as the person runs it (`orth`, `mono-dev`, …). */
|
|
28
|
+
function cmd(rest) {
|
|
29
|
+
return `${(0, utils_js_1.cliName)()} api-onboarding ${rest}`;
|
|
30
|
+
}
|
|
31
|
+
/** Runs one tool of POST /v1/onboarding for the organization. */
|
|
32
|
+
async function runTool(tool, org, requestId, input) {
|
|
33
|
+
const res = await (0, api_js_1.apiRequest)("/onboarding", {
|
|
34
|
+
method: "POST",
|
|
35
|
+
body: { tool, requestId, organizationId: org.id, input },
|
|
36
|
+
});
|
|
37
|
+
return res.result;
|
|
38
|
+
}
|
|
39
|
+
const clean = (text) => (0, utils_js_1.sanitizeForTerminal)(text.replace(/\s+/g, " ").trim());
|
|
40
|
+
exports.clean = clean;
|
|
41
|
+
function shorten(text, max) {
|
|
42
|
+
const line = (0, exports.clean)(text);
|
|
43
|
+
return line.length > max ? `${line.slice(0, max - 1)}…` : line;
|
|
44
|
+
}
|
|
45
|
+
const row = (label, value) => ` ${chalk_1.default.gray(label.padEnd(11))}${value}`;
|
|
46
|
+
exports.row = row;
|
|
47
|
+
exports.UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
48
|
+
// eslint-disable-next-line no-control-regex
|
|
49
|
+
const stripAnsi = (text) => text.replace(/\x1b\[[0-9;]*m/g, "");
|
|
50
|
+
exports.stripAnsi = stripAnsi;
|
|
51
|
+
/** A full https:// address, else the sentence that says what to type. */
|
|
52
|
+
function httpsUrl(value, what) {
|
|
53
|
+
try {
|
|
54
|
+
const url = new URL(value);
|
|
55
|
+
if (url.protocol === "https:")
|
|
56
|
+
return url.toString();
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Not a URL at all: the same answer.
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`${what} must be a full https:// address, like https://docs.example.com (got "${(0, utils_js_1.sanitizeForTerminal)(value)}").`);
|
|
62
|
+
}
|
|
63
|
+
/** A long text in lines of at most 100 columns, each indented by `indent` spaces. */
|
|
64
|
+
function wrapped(text, indent) {
|
|
65
|
+
const width = Math.max(40, 100 - indent);
|
|
66
|
+
const lines = [];
|
|
67
|
+
for (const word of (0, exports.clean)(text).split(" ").filter(Boolean)) {
|
|
68
|
+
const last = lines.at(-1);
|
|
69
|
+
if (last !== undefined && last.length + 1 + word.length <= width)
|
|
70
|
+
lines[lines.length - 1] = `${last} ${word}`;
|
|
71
|
+
else
|
|
72
|
+
lines.push(word);
|
|
73
|
+
}
|
|
74
|
+
return lines.map((line) => " ".repeat(indent) + line);
|
|
75
|
+
}
|
|
76
|
+
/** Prints the result as JSON, or the lines that say what happened. */
|
|
77
|
+
function report(options, result, lines) {
|
|
78
|
+
if (options.json)
|
|
79
|
+
console.log(JSON.stringify(result, null, 2));
|
|
80
|
+
else
|
|
81
|
+
done(lines());
|
|
82
|
+
}
|
|
83
|
+
const goesOn = (agent) => agent === "queued"
|
|
84
|
+
? "The Agent is working; it picks this up next."
|
|
85
|
+
: agent
|
|
86
|
+
? "The Agent goes on in the background."
|
|
87
|
+
: "";
|
|
88
|
+
exports.goesOn = goesOn;
|
|
89
|
+
/** A multi-line text (the final report) indented, each line made safe. */
|
|
90
|
+
const indented = (text) => text
|
|
91
|
+
.split("\n")
|
|
92
|
+
.map((line) => ` ${(0, utils_js_1.sanitizeForTerminal)(line)}`)
|
|
93
|
+
.join("\n");
|
|
94
|
+
exports.indented = indented;
|
|
95
|
+
function done(lines) {
|
|
96
|
+
console.log(`\n ${lines.filter(Boolean).join("\n ")}\n`);
|
|
97
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface OnboardCallOptions {
|
|
2
|
+
/** The request's API name (or part of one), or its id. */
|
|
3
|
+
request?: string;
|
|
4
|
+
org?: string;
|
|
5
|
+
input?: string;
|
|
6
|
+
approve?: boolean;
|
|
7
|
+
/** Retrying with the same id repeats no write. */
|
|
8
|
+
callId?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* orth api-onboarding tools [name] - List the onboarding tools, or show one
|
|
12
|
+
*/
|
|
13
|
+
export declare function onboardToolsCommand(name?: string, options?: {
|
|
14
|
+
json?: boolean;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* orth api-onboarding call <tool> - Run one onboarding tool; prints the result as JSON
|
|
18
|
+
*/
|
|
19
|
+
export declare function onboardCallCommand(tool: string, options: OnboardCallOptions): Promise<void>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.onboardToolsCommand = onboardToolsCommand;
|
|
7
|
+
exports.onboardCallCommand = onboardCallCommand;
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const ora_1 = __importDefault(require("ora"));
|
|
10
|
+
const api_js_1 = require("../../api.js");
|
|
11
|
+
const organizations_js_1 = require("../../organizations.js");
|
|
12
|
+
const utils_js_1 = require("../../utils.js");
|
|
13
|
+
const requests_js_1 = require("./requests.js");
|
|
14
|
+
const shared_js_1 = require("./shared.js");
|
|
15
|
+
function firstSentence(text) {
|
|
16
|
+
const match = text.match(/^.*?[.!?](\s|$)/s);
|
|
17
|
+
return (match ? match[0] : text).replace(/\s+/g, " ").trim();
|
|
18
|
+
}
|
|
19
|
+
async function readStdin() {
|
|
20
|
+
const chunks = [];
|
|
21
|
+
for await (const chunk of process.stdin)
|
|
22
|
+
chunks.push(Buffer.from(chunk));
|
|
23
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
24
|
+
}
|
|
25
|
+
// "-" reads stdin so secrets (save_credential's key) stay out of shell history.
|
|
26
|
+
async function parseInput(raw) {
|
|
27
|
+
const text = raw === "-" ? await readStdin() : raw;
|
|
28
|
+
let parsed;
|
|
29
|
+
try {
|
|
30
|
+
parsed = JSON.parse(text);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
throw new Error("--input must be valid JSON");
|
|
34
|
+
}
|
|
35
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
36
|
+
throw new Error("--input must be a JSON object");
|
|
37
|
+
}
|
|
38
|
+
return Object.fromEntries(Object.entries(parsed));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* orth api-onboarding tools [name] - List the onboarding tools, or show one
|
|
42
|
+
*/
|
|
43
|
+
async function onboardToolsCommand(name, options = {}) {
|
|
44
|
+
const spinner = options.json ? null : (0, ora_1.default)("Loading onboarding tools...").start();
|
|
45
|
+
try {
|
|
46
|
+
const catalog = await (0, api_js_1.apiRequest)("/onboarding");
|
|
47
|
+
spinner?.stop();
|
|
48
|
+
if (options.json && !name) {
|
|
49
|
+
console.log(JSON.stringify(catalog, null, 2));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (name) {
|
|
53
|
+
const tool = catalog.tools.find((t) => t.name === name);
|
|
54
|
+
if (!tool)
|
|
55
|
+
throw new Error(`Unknown onboarding tool '${name}'`);
|
|
56
|
+
const { description, inputSchema } = tool;
|
|
57
|
+
console.log(JSON.stringify({ name: tool.name, description, inputSchema }, null, 2));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
console.log(`${catalog.guide.trim()}\n`);
|
|
61
|
+
for (const tool of catalog.tools) {
|
|
62
|
+
const needs = tool.needsRequest ? chalk_1.default.yellow(" (needs --request)") : "";
|
|
63
|
+
console.log(chalk_1.default.cyan.bold(tool.name) +
|
|
64
|
+
needs +
|
|
65
|
+
chalk_1.default.gray(` ${(0, utils_js_1.sanitizeForTerminal)(firstSentence(tool.description))}`));
|
|
66
|
+
}
|
|
67
|
+
console.log(chalk_1.default.gray(`\nRun '${(0, shared_js_1.cmd)("tools <name>")}' for a tool's input schema, or '${(0, shared_js_1.cmd)("tools --json")}' for every tool`));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
spinner?.stop();
|
|
71
|
+
(0, shared_js_1.fail)(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* orth api-onboarding call <tool> - Run one onboarding tool; prints the result as JSON
|
|
76
|
+
*/
|
|
77
|
+
async function onboardCallCommand(tool, options) {
|
|
78
|
+
try {
|
|
79
|
+
const input = options.input === undefined ? undefined : await parseInput(options.input);
|
|
80
|
+
if (options.callId !== undefined && !shared_js_1.UUID.test(options.callId)) {
|
|
81
|
+
throw new Error(`--call-id must be a UUID, like 123e4567-e89b-42d3-a456-426614174000 (got "${(0, utils_js_1.sanitizeForTerminal)(options.callId)}").`);
|
|
82
|
+
}
|
|
83
|
+
const org = tool === "list_organizations" ? undefined : await (0, organizations_js_1.resolveOrganization)(options.org);
|
|
84
|
+
// --request names the API like every other command does, or gives the id.
|
|
85
|
+
const requestId = org && options.request
|
|
86
|
+
? (await (0, requests_js_1.resolveRequest)(org, options.request, () => true, "use", "call")).id
|
|
87
|
+
: options.request;
|
|
88
|
+
const res = await (0, api_js_1.apiRequest)("/onboarding", {
|
|
89
|
+
method: "POST",
|
|
90
|
+
body: {
|
|
91
|
+
tool,
|
|
92
|
+
requestId,
|
|
93
|
+
organizationId: org?.id,
|
|
94
|
+
input,
|
|
95
|
+
approved: options.approve ? true : undefined,
|
|
96
|
+
callId: options.callId,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
console.log(JSON.stringify(res.result, null, 2));
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
(0, shared_js_1.fail)(error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* orth org - The organizations you sell APIs with, and the default one for
|
|
3
|
+
* api-onboarding and payouts
|
|
4
|
+
*/
|
|
5
|
+
export declare function orgCommand(options: {
|
|
6
|
+
json?: boolean;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* orth org use [name] - Choose the default organization for api-onboarding
|
|
10
|
+
* and payouts (who pays for calls follows the key)
|
|
11
|
+
*/
|
|
12
|
+
export declare function orgUseCommand(query: string | undefined): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* orth team - The teams this machine holds a key for (one per team, from
|
|
15
|
+
* `orth login`), and the active one: its key is the one every command sends
|
|
16
|
+
*/
|
|
17
|
+
export declare function teamCommand(options: {
|
|
18
|
+
json?: boolean;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
/** orth team use [name] - Switch the active team to another one signed in to */
|
|
21
|
+
export declare function teamUseCommand(query: string | undefined): Promise<void>;
|