@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.
Files changed (80) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +113 -109
  3. package/dist/analytics.d.ts +37 -3
  4. package/dist/analytics.js +253 -39
  5. package/dist/api.d.ts +28 -2
  6. package/dist/api.js +67 -13
  7. package/dist/command-actions.d.ts +10 -0
  8. package/dist/command-actions.js +42 -0
  9. package/dist/commands/account.d.ts +9 -1
  10. package/dist/commands/account.js +26 -10
  11. package/dist/commands/api.d.ts +3 -0
  12. package/dist/commands/api.js +104 -114
  13. package/dist/commands/auth.d.ts +3 -1
  14. package/dist/commands/auth.js +53 -9
  15. package/dist/commands/onboard/flow.d.ts +22 -0
  16. package/dist/commands/onboard/flow.js +155 -0
  17. package/dist/commands/onboard/guide.d.ts +8 -0
  18. package/dist/commands/onboard/guide.js +73 -0
  19. package/dist/commands/onboard/listing.d.ts +18 -0
  20. package/dist/commands/onboard/listing.js +166 -0
  21. package/dist/commands/onboard/progress.d.ts +44 -0
  22. package/dist/commands/onboard/progress.js +108 -0
  23. package/dist/commands/onboard/register.d.ts +2 -0
  24. package/dist/commands/onboard/register.js +261 -0
  25. package/dist/commands/onboard/requests.d.ts +24 -0
  26. package/dist/commands/onboard/requests.js +96 -0
  27. package/dist/commands/onboard/review.d.ts +31 -0
  28. package/dist/commands/onboard/review.js +228 -0
  29. package/dist/commands/onboard/setup.d.ts +68 -0
  30. package/dist/commands/onboard/setup.js +215 -0
  31. package/dist/commands/onboard/shared.d.ts +41 -0
  32. package/dist/commands/onboard/shared.js +97 -0
  33. package/dist/commands/onboard/tools.d.ts +19 -0
  34. package/dist/commands/onboard/tools.js +104 -0
  35. package/dist/commands/org.d.ts +21 -0
  36. package/dist/commands/org.js +126 -0
  37. package/dist/commands/payouts.d.ts +44 -0
  38. package/dist/commands/payouts.js +125 -0
  39. package/dist/commands/run.d.ts +1 -1
  40. package/dist/commands/run.js +18 -26
  41. package/dist/commands/search.d.ts +8 -1
  42. package/dist/commands/search.js +26 -4
  43. package/dist/commands/skills/browse.d.ts +15 -0
  44. package/dist/commands/skills/browse.js +194 -0
  45. package/dist/commands/skills/create.d.ts +5 -0
  46. package/dist/commands/skills/create.js +62 -0
  47. package/dist/commands/skills/init.d.ts +4 -0
  48. package/dist/commands/skills/init.js +123 -0
  49. package/dist/commands/skills/install.d.ts +6 -0
  50. package/dist/commands/skills/install.js +191 -0
  51. package/dist/commands/skills/local-files.d.ts +15 -0
  52. package/dist/commands/skills/local-files.js +110 -0
  53. package/dist/commands/skills/register.d.ts +2 -0
  54. package/dist/commands/skills/register.js +130 -0
  55. package/dist/commands/skills/shared.d.ts +43 -0
  56. package/dist/commands/skills/shared.js +69 -0
  57. package/dist/commands/skills/upload.d.ts +9 -0
  58. package/dist/commands/skills/upload.js +223 -0
  59. package/dist/commands/skills/verification.d.ts +5 -0
  60. package/dist/commands/skills/verification.js +74 -0
  61. package/dist/commands/telemetry.d.ts +3 -0
  62. package/dist/commands/telemetry.js +38 -0
  63. package/dist/config.d.ts +48 -1
  64. package/dist/config.js +99 -3
  65. package/dist/http.d.ts +15 -0
  66. package/dist/http.js +41 -0
  67. package/dist/index.js +131 -165
  68. package/dist/organizations.d.ts +14 -0
  69. package/dist/organizations.js +77 -0
  70. package/dist/urls.d.ts +3 -0
  71. package/dist/urls.js +34 -0
  72. package/dist/utils.d.ts +20 -0
  73. package/dist/utils.js +112 -0
  74. package/dist/version.d.ts +5 -0
  75. package/dist/version.js +21 -0
  76. package/dist/x402.d.ts +7 -0
  77. package/dist/x402.js +27 -0
  78. package/package.json +23 -22
  79. package/dist/commands/skills.d.ts +0 -66
  80. package/dist/commands/skills.js +0 -821
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerOnboardCommands = registerOnboardCommands;
4
+ const analytics_js_1 = require("../../analytics.js");
5
+ const command_actions_js_1 = require("../../command-actions.js");
6
+ const tools_js_1 = require("./tools.js");
7
+ const flow_js_1 = require("./flow.js");
8
+ const setup_js_1 = require("./setup.js");
9
+ const review_js_1 = require("./review.js");
10
+ const listing_js_1 = require("./listing.js");
11
+ const guide_js_1 = require("./guide.js");
12
+ // ─────────────────────────────────────────────────────────────────────────────
13
+ // orth api-onboarding <subcommand> — list your own API: Orthogonal's Agent
14
+ // sets it up in the background, the same run the dashboard shows. Requests
15
+ // and organizations are picked by name; nobody needs an id.
16
+ // ─────────────────────────────────────────────────────────────────────────────
17
+ function registerOnboardCommands(program) {
18
+ const onboardGroup = program
19
+ .command("api-onboarding")
20
+ .description("List your API on Orthogonal: the Agent sets it up in the background (start with: guide)");
21
+ const requestArgument = "[api]";
22
+ onboardGroup
23
+ .command("list", { isDefault: true })
24
+ .description("Your organization's onboarding requests")
25
+ .option(...command_actions_js_1.orgOption)
26
+ .option("--json", "Print JSON")
27
+ .action((0, command_actions_js_1.asyncAction)(async (options) => {
28
+ (0, analytics_js_1.trackEvent)("api-onboarding.list", {});
29
+ await (0, flow_js_1.onboardListCommand)(options);
30
+ }));
31
+ onboardGroup
32
+ .command("new <docsUrl>")
33
+ .description("Ask Orthogonal to list your API (it approves the request first)")
34
+ .requiredOption("-n, --name <apiName>", "Your API's name")
35
+ .option("-u, --use-case <text>", "What agents use it for")
36
+ .option("-w, --website <url>", "Company website (default: the docs' site)")
37
+ .option("--more-docs <urls...>", "More documentation pages (https://, up to 5)")
38
+ .option(...command_actions_js_1.orgOption)
39
+ .option("--json", "Print JSON")
40
+ .action((0, command_actions_js_1.asyncAction)(async (docsUrl, options) => {
41
+ (0, analytics_js_1.trackEvent)("api-onboarding.new", { docsUrl });
42
+ await (0, flow_js_1.onboardNewCommand)(docsUrl, options);
43
+ }));
44
+ onboardGroup
45
+ .command(`start ${requestArgument}`)
46
+ .description("Start the Agent in the background, reply to it (-m), or resume it")
47
+ .option("-m, --message <text>", "Your reply to the Agent")
48
+ .option("-w, --watch", "Follow the Agent's work as it happens (with --json: print once)")
49
+ .option(...command_actions_js_1.orgOption)
50
+ .option("--json", "Print JSON")
51
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
52
+ (0, analytics_js_1.trackEvent)("api-onboarding.start", { reply: options.message ? "yes" : "no" });
53
+ await (0, flow_js_1.onboardStartCommand)(api, options);
54
+ }));
55
+ onboardGroup
56
+ .command(`status ${requestArgument}`)
57
+ .description("Where the onboarding is, what the Agent asks to run, and your next step")
58
+ .option("-w, --watch", "Follow the Agent's work until it stops (with --json: print once)")
59
+ .option(...command_actions_js_1.orgOption)
60
+ .option("--json", "Print JSON")
61
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
62
+ (0, analytics_js_1.trackEvent)("api-onboarding.status", {});
63
+ await (0, flow_js_1.onboardStatusCommand)(api, options);
64
+ }));
65
+ onboardGroup
66
+ .command(`stop ${requestArgument}`)
67
+ .description("Stop the Agent's background work (start resumes it)")
68
+ .option(...command_actions_js_1.orgOption)
69
+ .option("--json", "Print JSON")
70
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
71
+ (0, analytics_js_1.trackEvent)("api-onboarding.stop", {});
72
+ await (0, flow_js_1.onboardStopCommand)(api, options);
73
+ }));
74
+ onboardGroup
75
+ .command(`setup ${requestArgument}`)
76
+ .description("The setup to review: base URL, where the key goes, endpoints and prices")
77
+ .option(...command_actions_js_1.orgOption)
78
+ .option("--json", "Print JSON")
79
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
80
+ (0, analytics_js_1.trackEvent)("api-onboarding.setup", {});
81
+ await (0, setup_js_1.onboardSetupCommand)(api, options);
82
+ }));
83
+ onboardGroup
84
+ .command(`base-url <url> ${requestArgument}`)
85
+ .description("Set the https:// address the API is served from")
86
+ .option(...command_actions_js_1.orgOption)
87
+ .option("--json", "Print JSON")
88
+ .action((0, command_actions_js_1.asyncAction)(async (url, api, options) => {
89
+ (0, analytics_js_1.trackEvent)("api-onboarding.base-url", {});
90
+ await (0, setup_js_1.onboardBaseUrlCommand)(url, api, options);
91
+ }));
92
+ onboardGroup
93
+ .command(`price <endpoint> <price> ${requestArgument}`)
94
+ .description('Set an endpoint\'s price per call: USD (e.g. 0.002) or "free"')
95
+ .option(...command_actions_js_1.orgOption)
96
+ .option("--json", "Print JSON")
97
+ .action((0, command_actions_js_1.asyncAction)(async (endpoint, price, api, options) => {
98
+ (0, analytics_js_1.trackEvent)("api-onboarding.price", {});
99
+ await (0, setup_js_1.onboardPriceCommand)(endpoint, price, api, options);
100
+ }));
101
+ onboardGroup
102
+ .command(`leave-out <endpoint> ${requestArgument}`)
103
+ .description("Keep an endpoint out of the listing (e.g. \"DELETE /users/{id}\")")
104
+ .option(...command_actions_js_1.orgOption)
105
+ .option("--json", "Print JSON")
106
+ .action((0, command_actions_js_1.asyncAction)(async (endpoint, api, options) => {
107
+ (0, analytics_js_1.trackEvent)("api-onboarding.leave-out", {});
108
+ await (0, setup_js_1.onboardLeaveOutCommand)(endpoint, api, options);
109
+ }));
110
+ onboardGroup
111
+ .command(`confirm ${requestArgument}`)
112
+ .description("Review the setup, then confirm it so the Agent goes on")
113
+ .option("-y, --yes", "Confirm without asking")
114
+ .option(...command_actions_js_1.orgOption)
115
+ .option("--json", "Print JSON")
116
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
117
+ (0, analytics_js_1.trackEvent)("api-onboarding.confirm", {});
118
+ await (0, setup_js_1.onboardConfirmCommand)(api, options);
119
+ }));
120
+ onboardGroup
121
+ .command(`key ${requestArgument}`)
122
+ .description("Add the API key Orthogonal sends to your API (typed hidden, or piped in)")
123
+ .option(...command_actions_js_1.orgOption)
124
+ .option("--json", "Print JSON")
125
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
126
+ (0, analytics_js_1.trackEvent)("api-onboarding.key", {});
127
+ await (0, setup_js_1.onboardKeyCommand)(api, options);
128
+ }));
129
+ onboardGroup
130
+ .command(`approve ${requestArgument}`)
131
+ .description("Let the Agent run the calls it asks your approval for")
132
+ .option("-y, --yes", "Approve without asking")
133
+ .option(...command_actions_js_1.orgOption)
134
+ .option("--json", "Print JSON")
135
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
136
+ (0, analytics_js_1.trackEvent)("api-onboarding.approve", {});
137
+ await (0, review_js_1.onboardApproveCommand)(api, options);
138
+ }));
139
+ onboardGroup
140
+ .command(`deny ${requestArgument}`)
141
+ .description("Refuse the calls the Agent asks your approval for")
142
+ .option("-m, --message <why>", "Why, for the Agent")
143
+ .option(...command_actions_js_1.orgOption)
144
+ .option("--json", "Print JSON")
145
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
146
+ (0, analytics_js_1.trackEvent)("api-onboarding.deny", {});
147
+ await (0, review_js_1.onboardDenyCommand)(api, options);
148
+ }));
149
+ onboardGroup
150
+ .command(`test ${requestArgument}`)
151
+ .description("Run the checks: one real call to every endpoint")
152
+ .option(...command_actions_js_1.orgOption)
153
+ .option("--json", "Print JSON")
154
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
155
+ (0, analytics_js_1.trackEvent)("api-onboarding.test", {});
156
+ await (0, review_js_1.onboardTestCommand)(api, options);
157
+ }));
158
+ onboardGroup
159
+ .command(`submit ${requestArgument}`)
160
+ .description("Send the tested API for Orthogonal's review")
161
+ .option("-y, --yes", "Submit without asking")
162
+ .option(...command_actions_js_1.orgOption)
163
+ .option("--json", "Print JSON")
164
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
165
+ (0, analytics_js_1.trackEvent)("api-onboarding.submit", {});
166
+ await (0, review_js_1.onboardSubmitCommand)(api, options);
167
+ }));
168
+ onboardGroup
169
+ .command(`withdraw ${requestArgument}`)
170
+ .description("Take the submission back before Orthogonal reviews it")
171
+ .option("-y, --yes", "Withdraw without asking")
172
+ .option(...command_actions_js_1.orgOption)
173
+ .option("--json", "Print JSON")
174
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
175
+ (0, analytics_js_1.trackEvent)("api-onboarding.withdraw", {});
176
+ await (0, review_js_1.onboardWithdrawCommand)(api, options);
177
+ }));
178
+ onboardGroup
179
+ .command(`resubmit ${requestArgument}`)
180
+ .description("Change a declined request where Orthogonal asked, and send it again")
181
+ .option("-n, --name <apiName>", "New API name")
182
+ .option("-d, --docs-url <url>", "New documentation URL")
183
+ .option("-w, --website <url>", "New company website")
184
+ .option("-u, --use-case <text>", "New use case")
185
+ .option(...command_actions_js_1.orgOption)
186
+ .option("--json", "Print JSON")
187
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
188
+ (0, analytics_js_1.trackEvent)("api-onboarding.resubmit", {});
189
+ await (0, review_js_1.onboardResubmitCommand)(api, options);
190
+ }));
191
+ onboardGroup
192
+ .command(`cancel ${requestArgument}`)
193
+ .description("Cancel a request before its first version is published")
194
+ .option("-y, --yes", "Cancel without asking")
195
+ .option(...command_actions_js_1.orgOption)
196
+ .option("--json", "Print JSON")
197
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
198
+ (0, analytics_js_1.trackEvent)("api-onboarding.cancel", {});
199
+ await (0, review_js_1.onboardCancelCommand)(api, options);
200
+ }));
201
+ onboardGroup
202
+ .command(`listing ${requestArgument}`)
203
+ .description("Your live listing: its versions, the next one being prepared, and what it changes")
204
+ .option(...command_actions_js_1.orgOption)
205
+ .option("--json", "Print JSON")
206
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
207
+ (0, analytics_js_1.trackEvent)("api-onboarding.listing", {});
208
+ await (0, listing_js_1.onboardListingCommand)(api, options);
209
+ }));
210
+ onboardGroup
211
+ .command(`update ${requestArgument}`)
212
+ .description("Open the next version of your live listing with the Agent (buyers keep the live one)")
213
+ .option("-s, --sync", "Have the Agent check the live version against your API and its docs")
214
+ .option("-m, --message <text>", "What the next version should change, for the Agent")
215
+ .option("-w, --watch", "Follow the Agent's work as it happens (with --json: print once)")
216
+ .option(...command_actions_js_1.orgOption)
217
+ .option("--json", "Print JSON")
218
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
219
+ (0, analytics_js_1.trackEvent)("api-onboarding.update", { sync: options.sync ? "yes" : "no" });
220
+ await (0, listing_js_1.onboardUpdateCommand)(api, options);
221
+ }));
222
+ onboardGroup
223
+ .command(`discard ${requestArgument}`)
224
+ .description("Close the open version of your live listing and drop its changes (the live one stays)")
225
+ .option("-y, --yes", "Discard without asking")
226
+ .option(...command_actions_js_1.orgOption)
227
+ .option("--json", "Print JSON")
228
+ .action((0, command_actions_js_1.asyncAction)(async (api, options) => {
229
+ (0, analytics_js_1.trackEvent)("api-onboarding.discard", {});
230
+ await (0, listing_js_1.onboardDiscardCommand)(api, options);
231
+ }));
232
+ onboardGroup
233
+ .command("guide")
234
+ .description("How listing an API works, step by step (for you and your AI agent)")
235
+ .option("--json", "Print the guide as JSON")
236
+ .action((0, command_actions_js_1.asyncAction)(async (options) => {
237
+ (0, analytics_js_1.trackEvent)("api-onboarding.guide", {});
238
+ (0, guide_js_1.onboardGuideCommand)(options);
239
+ }));
240
+ onboardGroup
241
+ .command("tools [name]")
242
+ .description("Do the setup with your own agent: list the onboarding tools, or one's schema")
243
+ .option("--json", "Print the guide and every tool's schema as JSON")
244
+ .action((0, command_actions_js_1.asyncAction)(async (name, options) => {
245
+ (0, analytics_js_1.trackEvent)("api-onboarding.tools", { name });
246
+ await (0, tools_js_1.onboardToolsCommand)(name, options);
247
+ }));
248
+ onboardGroup
249
+ .command("call <tool>")
250
+ .description("Run an onboarding tool and print its result as JSON")
251
+ .option("-r, --request <api>", "The request: its API name (or part of one), or its id")
252
+ .option(...command_actions_js_1.orgOption)
253
+ .option("-i, --input <json>", "Tool input as a JSON object ('-' reads stdin)")
254
+ .option("--approve", "Approve the call; only after the user agreed to a call that changes data or costs money")
255
+ .option("--call-id <uuid>", "Your id for this call: a retry with the same id repeats no write")
256
+ .option("--json", "Print JSON (call always prints JSON)")
257
+ .action((0, command_actions_js_1.asyncAction)(async (tool, options) => {
258
+ (0, analytics_js_1.trackEvent)("api-onboarding.call", { tool });
259
+ await (0, tools_js_1.onboardCallCommand)(tool, options);
260
+ }));
261
+ }
@@ -0,0 +1,24 @@
1
+ import type { Organization } from "../../config.js";
2
+ import { type OnboardFlowOptions, type RequestSummary } from "./shared.js";
3
+ export declare const PHASES: Record<string, string>;
4
+ export declare function requestStatus(status: RequestSummary["status"]): string;
5
+ /** Approved and still being set up: what start, stop and status mean by default. */
6
+ export declare const inProgress: (request: RequestSummary) => boolean;
7
+ export declare function stateOf(request: RequestSummary): string;
8
+ /**
9
+ * The request a command acts on: an id or (part of) an API name; else the
10
+ * only one that fits; else the person picks; else the list to choose from.
11
+ */
12
+ export declare function resolveRequest(org: Organization, given: string | undefined, fits: (request: RequestSummary) => boolean, verb: string, command?: string): Promise<RequestSummary | {
13
+ id: string;
14
+ apiName: null;
15
+ }>;
16
+ /** One setup step: the org, the request, then the step. */
17
+ export declare function stepContext(given: string | undefined, options: OnboardFlowOptions, verb: string, command: string, fits?: (request: RequestSummary) => boolean): Promise<{
18
+ org: Organization;
19
+ requestId: string;
20
+ apiName: string | null;
21
+ label: string;
22
+ }>;
23
+ /** Requests that can have a listing: approved ones. */
24
+ export declare const approved: (request: RequestSummary) => boolean;
@@ -0,0 +1,96 @@
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.approved = exports.inProgress = exports.PHASES = void 0;
7
+ exports.requestStatus = requestStatus;
8
+ exports.stateOf = stateOf;
9
+ exports.resolveRequest = resolveRequest;
10
+ exports.stepContext = stepContext;
11
+ const chalk_1 = __importDefault(require("chalk"));
12
+ const organizations_js_1 = require("../../organizations.js");
13
+ const utils_js_1 = require("../../utils.js");
14
+ const shared_js_1 = require("./shared.js");
15
+ exports.PHASES = {
16
+ ready: "Approved, not started",
17
+ discovering: "Setting up",
18
+ awaiting_review: "Setup ready for your review",
19
+ awaiting_credential: "Needs your API key",
20
+ ready_to_test: "Ready to test",
21
+ testing: "Testing",
22
+ tests_need_attention: "Checks need attention",
23
+ ready_to_submit: "Ready to submit",
24
+ submitted: "Submitted",
25
+ failed: "Failed",
26
+ };
27
+ function requestStatus(status) {
28
+ return {
29
+ pending: () => chalk_1.default.yellow("Waiting for Orthogonal's approval"),
30
+ approved: () => chalk_1.default.green("Approved"),
31
+ rejected: () => chalk_1.default.red("Rejected"),
32
+ cancelled: () => chalk_1.default.gray("Cancelled"),
33
+ }[status]();
34
+ }
35
+ /** Approved and still being set up: what start, stop and status mean by default. */
36
+ const inProgress = (request) => request.status === "approved" && request.setupPhase !== "submitted";
37
+ exports.inProgress = inProgress;
38
+ function stateOf(request) {
39
+ return request.status === "approved"
40
+ ? (exports.PHASES[request.setupPhase ?? ""] ?? request.setupPhase ?? "")
41
+ : requestStatus(request.status);
42
+ }
43
+ /**
44
+ * The request a command acts on: an id or (part of) an API name; else the
45
+ * only one that fits; else the person picks; else the list to choose from.
46
+ */
47
+ async function resolveRequest(org, given, fits, verb, command = verb) {
48
+ if (given && shared_js_1.UUID.test(given))
49
+ return { id: given, apiName: null };
50
+ const { requests } = await (0, shared_js_1.runTool)("list_requests", org);
51
+ const open = requests.filter((request) => request.status !== "cancelled");
52
+ if (given) {
53
+ const wanted = given.trim().toLowerCase();
54
+ const matching = open.filter((request) => request.apiName.toLowerCase().includes(wanted));
55
+ // The exact name wins (of two alike, the one the command can act on);
56
+ // part of a name must name one request.
57
+ const exactly = matching.filter((request) => request.apiName.toLowerCase() === wanted);
58
+ const match = exactly.length
59
+ ? (exactly.find(fits) ?? exactly[0])
60
+ : matching.length === 1
61
+ ? matching[0]
62
+ : undefined;
63
+ if (match)
64
+ return match;
65
+ throw new Error(matching.length
66
+ ? `Several requests match "${(0, utils_js_1.sanitizeForTerminal)(given)}": ${matching.map((request) => `"${(0, shared_js_1.clean)(request.apiName)}"`).join(", ")}. Be more specific.`
67
+ : `No request matches "${(0, utils_js_1.sanitizeForTerminal)(given)}". See them with: ${(0, shared_js_1.cmd)("list")}`);
68
+ }
69
+ // Status reads any request when none is being set up.
70
+ const fitting = open.filter(fits);
71
+ const candidates = fitting.length || verb !== "check" ? fitting : open;
72
+ const [only] = candidates;
73
+ if (!only) {
74
+ throw new Error(open.length
75
+ ? `No request to ${verb}. See them with: ${(0, shared_js_1.cmd)("list")}`
76
+ : `No onboarding requests yet. Start one: ${(0, shared_js_1.cmd)("new <docsUrl> --name <api>")}`);
77
+ }
78
+ if (candidates.length === 1)
79
+ return only;
80
+ if (!(0, utils_js_1.isInteractive)()) {
81
+ throw new Error(`Which request? ${candidates.map((request) => `"${(0, shared_js_1.clean)(request.apiName)}"`).join(", ")}. Pass its name: ${(0, shared_js_1.cmd)(`${command} "<name>"`)}`);
82
+ }
83
+ const index = await (0, utils_js_1.choose)(`Which API do you want to ${verb}?`, candidates.map((request) => `${request.apiName} · ${(0, shared_js_1.stripAnsi)(stateOf(request))}`));
84
+ return candidates[index] ?? only;
85
+ }
86
+ /** One setup step: the org, the request, then the step. */
87
+ async function stepContext(given, options, verb, command, fits = exports.inProgress) {
88
+ const org = await (0, organizations_js_1.resolveOrganization)(options.org);
89
+ const request = await resolveRequest(org, given, fits, verb, command);
90
+ // Named by API, what the person sees: its name and where it is.
91
+ const label = request.apiName ? `${(0, shared_js_1.clean)(request.apiName)} (${(0, shared_js_1.stripAnsi)(stateOf(request))})` : "";
92
+ return { org, requestId: request.id, apiName: request.apiName, label };
93
+ }
94
+ /** Requests that can have a listing: approved ones. */
95
+ const approved = (request) => request.status === "approved";
96
+ exports.approved = approved;
@@ -0,0 +1,31 @@
1
+ import { type OnboardFlowOptions } from "./shared.js";
2
+ /**
3
+ * orth api-onboarding test [api] - One real call to every endpoint
4
+ */
5
+ export declare function onboardTestCommand(given: string | undefined, options: OnboardFlowOptions): Promise<void>;
6
+ /**
7
+ * orth api-onboarding submit [api] - Send the tested setup for Orthogonal's review
8
+ */
9
+ export declare function onboardSubmitCommand(given: string | undefined, options: OnboardFlowOptions & {
10
+ yes?: boolean;
11
+ }): Promise<void>;
12
+ /**
13
+ * orth api-onboarding approve [api] - Let the Agent run the calls it asks for
14
+ */
15
+ export declare function onboardApproveCommand(given: string | undefined, options: OnboardFlowOptions): Promise<void>;
16
+ /**
17
+ * orth api-onboarding deny [api] -m <why> - Refuse the calls the Agent asks for
18
+ */
19
+ export declare function onboardDenyCommand(given: string | undefined, options: OnboardFlowOptions): Promise<void>;
20
+ /**
21
+ * orth api-onboarding resubmit [api] - Change a declined request and send it again
22
+ */
23
+ export declare function onboardResubmitCommand(given: string | undefined, options: OnboardFlowOptions): Promise<void>;
24
+ /**
25
+ * orth api-onboarding cancel [api] - Drop a request before its first version is published
26
+ */
27
+ export declare function onboardCancelCommand(given: string | undefined, options: OnboardFlowOptions): Promise<void>;
28
+ /**
29
+ * orth api-onboarding withdraw [api] - Take a submission back before review
30
+ */
31
+ export declare function onboardWithdrawCommand(given: string | undefined, options: OnboardFlowOptions): Promise<void>;
@@ -0,0 +1,228 @@
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.onboardTestCommand = onboardTestCommand;
7
+ exports.onboardSubmitCommand = onboardSubmitCommand;
8
+ exports.onboardApproveCommand = onboardApproveCommand;
9
+ exports.onboardDenyCommand = onboardDenyCommand;
10
+ exports.onboardResubmitCommand = onboardResubmitCommand;
11
+ exports.onboardCancelCommand = onboardCancelCommand;
12
+ exports.onboardWithdrawCommand = onboardWithdrawCommand;
13
+ const chalk_1 = __importDefault(require("chalk"));
14
+ const ora_1 = __importDefault(require("ora"));
15
+ const utils_js_1 = require("../../utils.js");
16
+ const progress_js_1 = require("./progress.js");
17
+ const requests_js_1 = require("./requests.js");
18
+ const setup_js_1 = require("./setup.js");
19
+ const shared_js_1 = require("./shared.js");
20
+ const RESULT_MARK = {
21
+ passed: () => chalk_1.default.green("✓ passed"),
22
+ expected_response: () => chalk_1.default.green("✓ expected"),
23
+ failed: () => chalk_1.default.red("✗ failed"),
24
+ needs_input: () => chalk_1.default.yellow("? needs input"),
25
+ };
26
+ /**
27
+ * orth api-onboarding test [api] - One real call to every endpoint
28
+ */
29
+ async function onboardTestCommand(given, options) {
30
+ let spinner = null;
31
+ try {
32
+ const { org, requestId } = await (0, requests_js_1.stepContext)(given, options, "test", "test");
33
+ spinner = options.json ? null : (0, ora_1.default)("Calling the endpoints (up to a minute)...").start();
34
+ const result = await (0, shared_js_1.runTool)("run_checks", org, requestId, {});
35
+ spinner?.stop();
36
+ if (options.json) {
37
+ console.log(JSON.stringify(result, null, 2));
38
+ return;
39
+ }
40
+ console.log();
41
+ for (const check of result.checks) {
42
+ console.log(` ${RESULT_MARK[check.result]().padEnd(14)} ${chalk_1.default.cyan((0, shared_js_1.clean)(check.endpoint).padEnd(40))}` +
43
+ chalk_1.default.gray(`${check.httpStatus ? ` ${check.httpStatus}` : ""}${check.error ? ` ${(0, shared_js_1.clean)(check.error)}` : ""}${check.carried ? " (unchanged, not called again)" : ""}`));
44
+ }
45
+ const { counts } = result;
46
+ const carried = result.checks.filter((check) => check.carried).length;
47
+ (0, shared_js_1.done)([
48
+ `${counts.passed} of ${counts.total} passed` +
49
+ (carried
50
+ ? chalk_1.default.gray(` (${carried} unchanged since an earlier run, not called again)`)
51
+ : "") +
52
+ (counts.failed ? chalk_1.default.red(`, ${counts.failed} failed`) : "") +
53
+ (counts.needsInput ? chalk_1.default.yellow(`, ${counts.needsInput} need input`) : "") +
54
+ ".",
55
+ result.agent ? "The Agent reviews the results next." : "",
56
+ chalk_1.default.cyan((0, shared_js_1.cmd)("status --watch")),
57
+ ]);
58
+ }
59
+ catch (error) {
60
+ spinner?.stop();
61
+ (0, shared_js_1.fail)(error);
62
+ }
63
+ }
64
+ /**
65
+ * orth api-onboarding submit [api] - Send the tested setup for Orthogonal's review
66
+ */
67
+ async function onboardSubmitCommand(given, options) {
68
+ try {
69
+ const { org, requestId } = await (0, requests_js_1.stepContext)(given, options, "submit", "submit");
70
+ const setup = await (0, setup_js_1.fetchSetup)(org, requestId);
71
+ if (setup.finalReport && !options.yes && !options.json) {
72
+ console.log(chalk_1.default.bold("\n Final report\n"));
73
+ console.log((0, shared_js_1.indented)(setup.finalReport));
74
+ }
75
+ if (setup.finalReport && !options.yes) {
76
+ if (!(0, utils_js_1.isInteractive)())
77
+ throw new Error("Pass --yes to submit without a question.");
78
+ if (!(await (0, utils_js_1.confirmYes)(`Submit version ${setup.version} of ${(0, shared_js_1.clean)(setup.name)} for Orthogonal's review?`))) {
79
+ (0, shared_js_1.done)([chalk_1.default.gray("Not submitted.")]);
80
+ return;
81
+ }
82
+ }
83
+ const result = await (0, shared_js_1.runTool)("submit_for_review", org, requestId);
84
+ if (options.json) {
85
+ console.log(JSON.stringify(result, null, 2));
86
+ return;
87
+ }
88
+ (0, shared_js_1.done)(result.submitted
89
+ ? [
90
+ chalk_1.default.green(`Submitted version ${result.version}.`) +
91
+ (result.liveVersion === null
92
+ ? " Orthogonal reviews it; status says when it is live."
93
+ : ` Orthogonal reviews it; buyers keep version ${result.liveVersion} until it accepts it.`),
94
+ chalk_1.default.cyan((0, shared_js_1.cmd)("status")),
95
+ ]
96
+ : [(0, shared_js_1.clean)(result.reason ?? "Not submitted yet."), chalk_1.default.cyan((0, shared_js_1.cmd)("status --watch"))]);
97
+ }
98
+ catch (error) {
99
+ (0, shared_js_1.fail)(error);
100
+ }
101
+ }
102
+ /** Approve or deny everything the Agent waits on, after showing it. */
103
+ async function answerApproval(given, options, approved) {
104
+ const verb = approved ? "approve" : "deny";
105
+ const { org, requestId } = await (0, requests_js_1.stepContext)(given, options, verb, verb);
106
+ const progress = await (0, progress_js_1.fetchProgress)(requestId, org);
107
+ const approvals = progress.approvals ?? [];
108
+ if (!approvals.length)
109
+ throw new Error(`The Agent is not waiting for an approval. Check: ${(0, shared_js_1.cmd)("status")}`);
110
+ if (!options.json) {
111
+ console.log(chalk_1.default.bold(`\n The Agent asks to`));
112
+ for (const approval of approvals) {
113
+ console.log(` - ${(0, shared_js_1.clean)(approval.what)}`);
114
+ console.log(chalk_1.default.gray(` ${(0, shared_js_1.shorten)(JSON.stringify(approval.input ?? {}), 600)}`));
115
+ }
116
+ }
117
+ if (approved && !options.yes) {
118
+ if (!(0, utils_js_1.isInteractive)())
119
+ throw new Error("Pass --yes to approve without a question.");
120
+ if (!(await (0, utils_js_1.confirmYes)("Approve?"))) {
121
+ (0, shared_js_1.done)([chalk_1.default.gray("Not approved. Deny it with a reason:"), chalk_1.default.cyan((0, shared_js_1.cmd)('deny -m "<why>"'))]);
122
+ return;
123
+ }
124
+ }
125
+ const result = await (0, shared_js_1.runTool)("answer_approval", org, requestId, {
126
+ approvalIds: approvals.map(({ approvalId }) => approvalId),
127
+ approved,
128
+ ...(options.message ? { reason: options.message } : {}),
129
+ });
130
+ (0, shared_js_1.report)(options, result, () => [
131
+ approved ? chalk_1.default.green("Approved.") : chalk_1.default.yellow("Denied."),
132
+ "The Agent goes on in the background.",
133
+ chalk_1.default.cyan((0, shared_js_1.cmd)("status --watch")),
134
+ ]);
135
+ }
136
+ /**
137
+ * orth api-onboarding approve [api] - Let the Agent run the calls it asks for
138
+ */
139
+ async function onboardApproveCommand(given, options) {
140
+ try {
141
+ await answerApproval(given, options, true);
142
+ }
143
+ catch (error) {
144
+ (0, shared_js_1.fail)(error);
145
+ }
146
+ }
147
+ /**
148
+ * orth api-onboarding deny [api] -m <why> - Refuse the calls the Agent asks for
149
+ */
150
+ async function onboardDenyCommand(given, options) {
151
+ try {
152
+ await answerApproval(given, options, false);
153
+ }
154
+ catch (error) {
155
+ (0, shared_js_1.fail)(error);
156
+ }
157
+ }
158
+ /**
159
+ * orth api-onboarding resubmit [api] - Change a declined request and send it again
160
+ */
161
+ async function onboardResubmitCommand(given, options) {
162
+ try {
163
+ const changes = {
164
+ ...(options.name ? { apiName: options.name } : {}),
165
+ ...(options.docsUrl ? { documentationUrl: (0, shared_js_1.httpsUrl)(options.docsUrl, "--docs-url") } : {}),
166
+ ...(options.website ? { companyWebsite: (0, shared_js_1.httpsUrl)(options.website, "--website") } : {}),
167
+ ...(options.useCase ? { useCase: options.useCase } : {}),
168
+ };
169
+ const { org, requestId } = await (0, requests_js_1.stepContext)(given, options, "resubmit", "resubmit", (request) => request.status === "rejected");
170
+ const result = await (0, shared_js_1.runTool)("resubmit_request", org, requestId, changes);
171
+ (0, shared_js_1.report)(options, result, () => [
172
+ chalk_1.default.green(`Resubmitted ${(0, shared_js_1.clean)(result.request.apiName)}. Orthogonal reviews it again.`),
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 cancel [api] - Drop a request before its first version is published
182
+ */
183
+ async function onboardCancelCommand(given, options) {
184
+ try {
185
+ const { org, requestId, label } = await (0, requests_js_1.stepContext)(given, options, "cancel", "cancel", (request) => request.status === "pending" ||
186
+ request.status === "rejected" ||
187
+ (request.status === "approved" && request.setupPhase === "ready"));
188
+ if (!options.yes) {
189
+ if (!(0, utils_js_1.isInteractive)())
190
+ throw new Error("Pass --yes to cancel without a question.");
191
+ if (!(await (0, utils_js_1.confirmYes)(`Cancel the request${label ? ` for ${label}` : ""}? This can't be undone.`))) {
192
+ (0, shared_js_1.done)([chalk_1.default.gray("Not cancelled.")]);
193
+ return;
194
+ }
195
+ }
196
+ const result = await (0, shared_js_1.runTool)("cancel_request", org, requestId);
197
+ (0, shared_js_1.report)(options, result, () => [chalk_1.default.green(`Cancelled ${(0, shared_js_1.clean)(result.request.apiName)}.`)]);
198
+ }
199
+ catch (error) {
200
+ (0, shared_js_1.fail)(error);
201
+ }
202
+ }
203
+ /**
204
+ * orth api-onboarding withdraw [api] - Take a submission back before review
205
+ */
206
+ async function onboardWithdrawCommand(given, options) {
207
+ try {
208
+ const { org, requestId, apiName } = await (0, requests_js_1.stepContext)(given, options, "withdraw", "withdraw", (request) => request.status === "approved" && request.setupPhase === "submitted");
209
+ if (!options.yes) {
210
+ if (!(0, utils_js_1.isInteractive)())
211
+ throw new Error("Pass --yes to withdraw without a question.");
212
+ const { version } = await (0, setup_js_1.fetchSetup)(org, requestId);
213
+ if (!(await (0, utils_js_1.confirmYes)(`Withdraw version ${version}${apiName ? ` of ${(0, shared_js_1.clean)(apiName)}` : ""} from Orthogonal's review?`))) {
214
+ (0, shared_js_1.done)([chalk_1.default.gray("Still submitted.")]);
215
+ return;
216
+ }
217
+ }
218
+ const result = await (0, shared_js_1.runTool)("withdraw_submission", org, requestId);
219
+ (0, shared_js_1.report)(options, result, () => [
220
+ chalk_1.default.green(`Withdrew version ${result.version}.`) +
221
+ ` Change the setup, run the checks again, then submit.${result.liveVersion === null ? "" : ` Buyers keep version ${result.liveVersion}.`}`,
222
+ chalk_1.default.cyan((0, shared_js_1.cmd)("status")),
223
+ ]);
224
+ }
225
+ catch (error) {
226
+ (0, shared_js_1.fail)(error);
227
+ }
228
+ }