@ogment-ai/cli 0.6.0 → 0.7.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/dist/cli.js +21382 -4
- package/dist/cli.js.map +1 -0
- package/package.json +44 -53
- package/README.md +0 -134
- package/dist/cli/commands.d.ts +0 -37
- package/dist/cli/commands.d.ts.map +0 -1
- package/dist/cli/commands.js +0 -56
- package/dist/cli/execute.d.ts +0 -11
- package/dist/cli/execute.d.ts.map +0 -1
- package/dist/cli/execute.js +0 -468
- package/dist/cli/invocations.d.ts +0 -31
- package/dist/cli/invocations.d.ts.map +0 -1
- package/dist/cli/invocations.js +0 -1
- package/dist/cli/parse-errors.d.ts +0 -17
- package/dist/cli/parse-errors.d.ts.map +0 -1
- package/dist/cli/parse-errors.js +0 -184
- package/dist/cli/program.d.ts +0 -10
- package/dist/cli/program.d.ts.map +0 -1
- package/dist/cli/program.js +0 -174
- package/dist/cli/run.d.ts +0 -6
- package/dist/cli/run.d.ts.map +0 -1
- package/dist/cli/run.js +0 -83
- package/dist/cli/runtime.d.ts +0 -21
- package/dist/cli/runtime.d.ts.map +0 -1
- package/dist/cli/runtime.js +0 -80
- package/dist/cli.d.ts +0 -4
- package/dist/cli.d.ts.map +0 -1
- package/dist/commands/auth.d.ts +0 -19
- package/dist/commands/auth.d.ts.map +0 -1
- package/dist/commands/auth.js +0 -21
- package/dist/commands/catalog.d.ts +0 -31
- package/dist/commands/catalog.d.ts.map +0 -1
- package/dist/commands/catalog.js +0 -167
- package/dist/commands/context.d.ts +0 -15
- package/dist/commands/context.d.ts.map +0 -1
- package/dist/commands/context.js +0 -1
- package/dist/commands/invoke.d.ts +0 -17
- package/dist/commands/invoke.d.ts.map +0 -1
- package/dist/commands/invoke.js +0 -173
- package/dist/commands/server-context.d.ts +0 -14
- package/dist/commands/server-context.d.ts.map +0 -1
- package/dist/commands/server-context.js +0 -26
- package/dist/commands/status.d.ts +0 -12
- package/dist/commands/status.d.ts.map +0 -1
- package/dist/commands/status.js +0 -5
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3
- package/dist/infra/credentials.d.ts +0 -22
- package/dist/infra/credentials.d.ts.map +0 -1
- package/dist/infra/credentials.js +0 -74
- package/dist/infra/env.d.ts +0 -15
- package/dist/infra/env.d.ts.map +0 -1
- package/dist/infra/env.js +0 -100
- package/dist/infra/http.d.ts +0 -16
- package/dist/infra/http.d.ts.map +0 -1
- package/dist/infra/http.js +0 -84
- package/dist/output/envelope.d.ts +0 -22
- package/dist/output/envelope.d.ts.map +0 -1
- package/dist/output/envelope.js +0 -67
- package/dist/output/manager.d.ts +0 -47
- package/dist/output/manager.d.ts.map +0 -1
- package/dist/output/manager.js +0 -120
- package/dist/services/account.d.ts +0 -16
- package/dist/services/account.d.ts.map +0 -1
- package/dist/services/account.js +0 -75
- package/dist/services/auth.d.ts +0 -37
- package/dist/services/auth.d.ts.map +0 -1
- package/dist/services/auth.js +0 -270
- package/dist/services/info.d.ts +0 -24
- package/dist/services/info.d.ts.map +0 -1
- package/dist/services/info.js +0 -316
- package/dist/services/mcp-error-mapping.d.ts +0 -9
- package/dist/services/mcp-error-mapping.d.ts.map +0 -1
- package/dist/services/mcp-error-mapping.js +0 -129
- package/dist/services/mcp.d.ts +0 -39
- package/dist/services/mcp.d.ts.map +0 -1
- package/dist/services/mcp.js +0 -169
- package/dist/shared/constants.d.ts +0 -5
- package/dist/shared/constants.d.ts.map +0 -1
- package/dist/shared/constants.js +0 -6
- package/dist/shared/error-codes.d.ts +0 -31
- package/dist/shared/error-codes.d.ts.map +0 -1
- package/dist/shared/error-codes.js +0 -25
- package/dist/shared/error-presentation.d.ts +0 -17
- package/dist/shared/error-presentation.d.ts.map +0 -1
- package/dist/shared/error-presentation.js +0 -151
- package/dist/shared/errors.d.ts +0 -146
- package/dist/shared/errors.d.ts.map +0 -1
- package/dist/shared/errors.js +0 -233
- package/dist/shared/exit-codes.d.ts +0 -15
- package/dist/shared/exit-codes.d.ts.map +0 -1
- package/dist/shared/exit-codes.js +0 -44
- package/dist/shared/guards.d.ts +0 -11
- package/dist/shared/guards.d.ts.map +0 -1
- package/dist/shared/guards.js +0 -29
- package/dist/shared/recovery.d.ts +0 -5
- package/dist/shared/recovery.d.ts.map +0 -1
- package/dist/shared/recovery.js +0 -123
- package/dist/shared/schema-example.d.ts +0 -3
- package/dist/shared/schema-example.d.ts.map +0 -1
- package/dist/shared/schema-example.js +0 -105
- package/dist/shared/schemas.d.ts +0 -14
- package/dist/shared/schemas.d.ts.map +0 -1
- package/dist/shared/schemas.js +0 -14
- package/dist/shared/types.d.ts +0 -225
- package/dist/shared/types.d.ts.map +0 -1
- package/dist/shared/types.js +0 -1
package/dist/cli/execute.js
DELETED
|
@@ -1,468 +0,0 @@
|
|
|
1
|
-
import { runAuthLoginCommand, runAuthLogoutCommand, runAuthStatusCommand, } from "../commands/auth.js";
|
|
2
|
-
import { runCatalogCommand, runCatalogToolDetailsCommand, runCatalogToolsCommand, } from "../commands/catalog.js";
|
|
3
|
-
import { runInvokeCommand } from "../commands/invoke.js";
|
|
4
|
-
import { runStatusCommand } from "../commands/status.js";
|
|
5
|
-
import { buildJsonSchemaExample, EXAMPLE_PLACEHOLDER } from "../shared/schema-example.js";
|
|
6
|
-
import { AuthError, ContractMismatchError, NotFoundError, RemoteRequestError, UnexpectedError, ValidationError, } from "../shared/errors.js";
|
|
7
|
-
import { exitCodeForError } from "../shared/exit-codes.js";
|
|
8
|
-
import { cliCommands } from "./commands.js";
|
|
9
|
-
export class CliExitError extends Error {
|
|
10
|
-
exitCode;
|
|
11
|
-
constructor(exitCode) {
|
|
12
|
-
super("CLI exit");
|
|
13
|
-
this.exitCode = exitCode;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
const throwCommandError = (error) => {
|
|
17
|
-
throw new CliExitError(exitCodeForError(error));
|
|
18
|
-
};
|
|
19
|
-
const nextAction = (id, title, command, reason, when = null) => {
|
|
20
|
-
return {
|
|
21
|
-
command,
|
|
22
|
-
id,
|
|
23
|
-
reason,
|
|
24
|
-
title,
|
|
25
|
-
when,
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
const ensureSuccess = (result, runtime, context) => {
|
|
29
|
-
if (result.status === "error") {
|
|
30
|
-
runtime.output.error(result.error, {
|
|
31
|
-
command: context.command,
|
|
32
|
-
entity: context.entity ?? null,
|
|
33
|
-
});
|
|
34
|
-
throwCommandError(result.error);
|
|
35
|
-
}
|
|
36
|
-
return result.value;
|
|
37
|
-
};
|
|
38
|
-
const nextActionsForLogin = (payload, mode) => {
|
|
39
|
-
return [
|
|
40
|
-
nextAction("check_auth_status", "Check auth status", cliCommands.auth.status(), `Verify persisted credentials after ${mode} login for ${payload.agentName}.`, "immediate"),
|
|
41
|
-
nextAction("discover_servers", "Discover servers", cliCommands.catalog.command(), `Logged in as ${payload.agentName} via ${mode}; discover available servers.`, "after_auth"),
|
|
42
|
-
];
|
|
43
|
-
};
|
|
44
|
-
const nextActionsForAuthStatus = (payload) => {
|
|
45
|
-
if (!payload.loggedIn) {
|
|
46
|
-
return [
|
|
47
|
-
nextAction("login", "Authenticate", cliCommands.auth.login(), "No API key is configured locally; login is required.", "immediate"),
|
|
48
|
-
];
|
|
49
|
-
}
|
|
50
|
-
return [
|
|
51
|
-
nextAction("discover_servers", "Discover servers", cliCommands.catalog.command(), `Authenticated via ${payload.apiKeySource}; discover servers next.`, "after_auth"),
|
|
52
|
-
];
|
|
53
|
-
};
|
|
54
|
-
const nextActionsForCatalogSummary = (payload, context) => {
|
|
55
|
-
const actions = [];
|
|
56
|
-
const targetServer = payload.servers.find((server) => server.toolCount > 0);
|
|
57
|
-
if (targetServer !== undefined) {
|
|
58
|
-
actions.push(nextAction("inspect_tools", "Inspect tools", cliCommands.catalog.server(targetServer.serverId), `${targetServer.serverId} has ${targetServer.toolCount} available tools.`, "if_tool_count_gt_0"));
|
|
59
|
-
}
|
|
60
|
-
if (context.nextCursor !== null) {
|
|
61
|
-
actions.push(nextAction("next_catalog_page", "Load next page", cliCommands.catalog.summary({
|
|
62
|
-
cursor: context.nextCursor,
|
|
63
|
-
limit: context.limit ?? undefined,
|
|
64
|
-
}), `More servers are available after cursor ${context.nextCursor}.`, "if_more_servers"));
|
|
65
|
-
}
|
|
66
|
-
return actions;
|
|
67
|
-
};
|
|
68
|
-
const nextActionsForCatalogTools = (payload) => {
|
|
69
|
-
const firstTool = payload.tools[0];
|
|
70
|
-
if (firstTool === undefined) {
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
return [
|
|
74
|
-
nextAction("inspect_tool", "Inspect tool details", cliCommands.catalog.tool(payload.server.serverId, firstTool.name, {
|
|
75
|
-
example: false,
|
|
76
|
-
}), `Inspect schema for ${payload.server.serverId}/${firstTool.name} before invoking.`, "if_tools_available"),
|
|
77
|
-
];
|
|
78
|
-
};
|
|
79
|
-
const toInlineJsonTemplateArgument = (value) => {
|
|
80
|
-
const placeholderLiteral = JSON.stringify(EXAMPLE_PLACEHOLDER);
|
|
81
|
-
const serialized = JSON.stringify(value).replaceAll(placeholderLiteral, " ... ");
|
|
82
|
-
const escaped = serialized.replaceAll("'", String.raw `'\''`);
|
|
83
|
-
return `'${escaped}'`;
|
|
84
|
-
};
|
|
85
|
-
const nextActionsForCatalogToolDetails = (payload, exampleInput) => {
|
|
86
|
-
const inputArgument = toInlineJsonTemplateArgument(exampleInput);
|
|
87
|
-
return [
|
|
88
|
-
nextAction("invoke_tool", "Invoke this tool", cliCommands.invoke.withInputValue(`${payload.server.serverId}/${payload.name}`, inputArgument), `Replace every ... placeholder with real JSON values, then invoke ${payload.server.serverId}/${payload.name}.`, "after_tool_inspection"),
|
|
89
|
-
];
|
|
90
|
-
};
|
|
91
|
-
const nextActionsForInvoke = (payload) => {
|
|
92
|
-
return [
|
|
93
|
-
nextAction("inspect_tool", "Inspect tool schema", cliCommands.catalog.tool(payload.serverId, payload.toolName, { example: false }), `Review ${payload.serverId}/${payload.toolName} schema for the next invocation.`, "after_invoke"),
|
|
94
|
-
];
|
|
95
|
-
};
|
|
96
|
-
const nextActionsForStatus = (payload) => {
|
|
97
|
-
if (!payload.auth.apiKeyPresent) {
|
|
98
|
-
return [
|
|
99
|
-
nextAction("login", "Authenticate", cliCommands.auth.login(), "Status detected no API key; authenticate first.", "immediate"),
|
|
100
|
-
];
|
|
101
|
-
}
|
|
102
|
-
return [
|
|
103
|
-
nextAction("discover_servers", "Discover servers", cliCommands.catalog.command(), `Connectivity is ${payload.summary.status}; discover available servers.`, "after_status"),
|
|
104
|
-
];
|
|
105
|
-
};
|
|
106
|
-
const runLoginFlow = async (runtime, mode, apiKey) => {
|
|
107
|
-
const loginInvocation = (() => {
|
|
108
|
-
if (mode === "api_key") {
|
|
109
|
-
return {
|
|
110
|
-
commandOptions: {
|
|
111
|
-
apiKey: apiKey ?? "",
|
|
112
|
-
mode: "apiKey",
|
|
113
|
-
},
|
|
114
|
-
invokedCommand: cliCommands.auth.loginWithApiKeyRedacted(),
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
const deviceCommand = cliCommands.auth.login();
|
|
118
|
-
return {
|
|
119
|
-
commandOptions: {
|
|
120
|
-
mode: "device",
|
|
121
|
-
onPending: ({ userCode, verificationUri }) => {
|
|
122
|
-
const pendingNextActions = [
|
|
123
|
-
nextAction("check_login_status", "Check login status", cliCommands.auth.status(), `Approve ${userCode} at ${verificationUri}, then verify local auth state.`, "immediate"),
|
|
124
|
-
nextAction("restart_device_login", "Restart login", cliCommands.auth.login(), `Restart login if code ${userCode} expires before approval.`, "if_expired"),
|
|
125
|
-
];
|
|
126
|
-
runtime.output.success({
|
|
127
|
-
event: "auth_login.pending",
|
|
128
|
-
loggedIn: false,
|
|
129
|
-
verification: {
|
|
130
|
-
userCode,
|
|
131
|
-
verificationUri,
|
|
132
|
-
},
|
|
133
|
-
}, {
|
|
134
|
-
command: deviceCommand,
|
|
135
|
-
entity: {
|
|
136
|
-
event: "auth_login.pending",
|
|
137
|
-
mode,
|
|
138
|
-
verification: {
|
|
139
|
-
userCode,
|
|
140
|
-
verificationUri,
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
humanMessage: `Open ${verificationUri} and enter code ${userCode}`,
|
|
144
|
-
nextActions: pendingNextActions,
|
|
145
|
-
});
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
invokedCommand: deviceCommand,
|
|
149
|
-
};
|
|
150
|
-
})();
|
|
151
|
-
const { commandOptions, invokedCommand } = loginInvocation;
|
|
152
|
-
const result = await runAuthLoginCommand(runtime.context, commandOptions);
|
|
153
|
-
const data = ensureSuccess(result, runtime, {
|
|
154
|
-
command: invokedCommand,
|
|
155
|
-
entity: {
|
|
156
|
-
mode,
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
let humanMessage = `Logged in as ${data.agentName}.`;
|
|
160
|
-
if (data.outcome === "already_authenticated") {
|
|
161
|
-
humanMessage = `Already logged in as ${data.agentName}.`;
|
|
162
|
-
}
|
|
163
|
-
else if (mode === "api_key") {
|
|
164
|
-
humanMessage = `Imported API key for ${data.agentName}.`;
|
|
165
|
-
}
|
|
166
|
-
const outputData = {
|
|
167
|
-
...data,
|
|
168
|
-
event: "auth_login.completed",
|
|
169
|
-
};
|
|
170
|
-
runtime.output.success(outputData, {
|
|
171
|
-
command: invokedCommand,
|
|
172
|
-
entity: {
|
|
173
|
-
agentName: data.agentName,
|
|
174
|
-
event: "auth_login.completed",
|
|
175
|
-
loggedIn: data.loggedIn,
|
|
176
|
-
mode,
|
|
177
|
-
outcome: data.outcome,
|
|
178
|
-
},
|
|
179
|
-
humanMessage,
|
|
180
|
-
nextActions: nextActionsForLogin(data, mode),
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
const executeAuthLoginInvocation = async (runtime, invocation) => {
|
|
184
|
-
if (invocation.apiKey !== undefined) {
|
|
185
|
-
await runLoginFlow(runtime, "api_key", invocation.apiKey);
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
await runLoginFlow(runtime, "device");
|
|
189
|
-
};
|
|
190
|
-
const executeAuthStatusInvocation = async (runtime) => {
|
|
191
|
-
const command = cliCommands.auth.status();
|
|
192
|
-
const result = await runAuthStatusCommand(runtime.context);
|
|
193
|
-
const data = ensureSuccess(result, runtime, {
|
|
194
|
-
command,
|
|
195
|
-
});
|
|
196
|
-
runtime.output.success(data, {
|
|
197
|
-
command,
|
|
198
|
-
entity: {
|
|
199
|
-
apiKeySource: data.apiKeySource,
|
|
200
|
-
loggedIn: data.loggedIn,
|
|
201
|
-
},
|
|
202
|
-
humanMessage: data.loggedIn ? `Authenticated (${data.apiKeySource}).` : "Not authenticated.",
|
|
203
|
-
nextActions: nextActionsForAuthStatus(data),
|
|
204
|
-
});
|
|
205
|
-
};
|
|
206
|
-
const executeAuthLogoutInvocation = async (runtime) => {
|
|
207
|
-
const command = cliCommands.auth.logout();
|
|
208
|
-
const result = await runAuthLogoutCommand(runtime.context);
|
|
209
|
-
const data = ensureSuccess(result, runtime, {
|
|
210
|
-
command,
|
|
211
|
-
});
|
|
212
|
-
let message = "Not logged in.";
|
|
213
|
-
if (data.localCredentialsDeleted) {
|
|
214
|
-
message = data.revoked
|
|
215
|
-
? "Logged out and revoked API key."
|
|
216
|
-
: "Logged out locally. Server revocation not confirmed.";
|
|
217
|
-
}
|
|
218
|
-
runtime.output.success(data, {
|
|
219
|
-
command,
|
|
220
|
-
entity: {
|
|
221
|
-
localCredentialsDeleted: data.localCredentialsDeleted,
|
|
222
|
-
revoked: data.revoked,
|
|
223
|
-
},
|
|
224
|
-
humanMessage: message,
|
|
225
|
-
nextActions: [
|
|
226
|
-
nextAction("login", "Authenticate again", cliCommands.auth.login(), "Logout completed; authenticate again before further tool calls.", "after_logout"),
|
|
227
|
-
],
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
const executeCatalogInvocation = async (runtime, invocation) => {
|
|
231
|
-
const parsedLimit = invocation.limit;
|
|
232
|
-
if (invocation.serverId === undefined) {
|
|
233
|
-
if (invocation.example) {
|
|
234
|
-
throw new ValidationError({
|
|
235
|
-
details: "--example without <server-id> <tool-name>",
|
|
236
|
-
message: "Invalid catalog options. --example requires <server-id> <tool-name>.",
|
|
237
|
-
recovery: { command: cliCommands.catalog.command() },
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
const command = cliCommands.catalog.summary({
|
|
241
|
-
cursor: invocation.cursor,
|
|
242
|
-
limit: parsedLimit,
|
|
243
|
-
});
|
|
244
|
-
const result = await runCatalogCommand(runtime.context, {
|
|
245
|
-
cursor: invocation.cursor,
|
|
246
|
-
includeDebug: runtime.output.debug,
|
|
247
|
-
limit: parsedLimit,
|
|
248
|
-
});
|
|
249
|
-
const data = ensureSuccess(result, runtime, {
|
|
250
|
-
command,
|
|
251
|
-
entity: {
|
|
252
|
-
cursor: invocation.cursor ?? null,
|
|
253
|
-
limit: parsedLimit ?? null,
|
|
254
|
-
},
|
|
255
|
-
});
|
|
256
|
-
const outputData = {
|
|
257
|
-
failures: data.failures,
|
|
258
|
-
servers: data.servers,
|
|
259
|
-
};
|
|
260
|
-
runtime.output.success(outputData, {
|
|
261
|
-
command,
|
|
262
|
-
entity: {
|
|
263
|
-
cursor: invocation.cursor ?? null,
|
|
264
|
-
failedServerCount: data.failures.length,
|
|
265
|
-
limit: parsedLimit ?? null,
|
|
266
|
-
serverCount: data.servers.length,
|
|
267
|
-
},
|
|
268
|
-
humanMessage: (() => {
|
|
269
|
-
const baseMessage = data.nextCursor === null
|
|
270
|
-
? `${data.servers.length} server(s) available.`
|
|
271
|
-
: `${data.servers.length} server(s) shown. More available with --cursor ${data.nextCursor}.`;
|
|
272
|
-
if (data.failures.length === 0) {
|
|
273
|
-
return baseMessage;
|
|
274
|
-
}
|
|
275
|
-
return `${baseMessage} ${data.failures.length} server(s) failed to load.`;
|
|
276
|
-
})(),
|
|
277
|
-
nextActions: nextActionsForCatalogSummary(outputData, {
|
|
278
|
-
limit: parsedLimit ?? null,
|
|
279
|
-
nextCursor: data.nextCursor,
|
|
280
|
-
}),
|
|
281
|
-
pagination: {
|
|
282
|
-
nextCursor: data.nextCursor,
|
|
283
|
-
},
|
|
284
|
-
});
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
if (invocation.toolName === undefined) {
|
|
288
|
-
if (invocation.cursor !== undefined || parsedLimit !== undefined) {
|
|
289
|
-
throw new ValidationError({
|
|
290
|
-
details: `${invocation.cursor === undefined ? "" : `--cursor ${invocation.cursor} `}${parsedLimit === undefined ? "" : `--limit ${parsedLimit}`}`.trim(),
|
|
291
|
-
message: "Invalid catalog options. --cursor and --limit are only valid for `ogment catalog`.",
|
|
292
|
-
recovery: { command: cliCommands.catalog.command() },
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
if (invocation.example) {
|
|
296
|
-
throw new ValidationError({
|
|
297
|
-
details: `--example without tool name for ${invocation.serverId}`,
|
|
298
|
-
message: "Invalid catalog options. --example requires <tool-name>.",
|
|
299
|
-
recovery: { command: cliCommands.catalog.server(invocation.serverId) },
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
const serverId = invocation.serverId;
|
|
303
|
-
const command = cliCommands.catalog.server(serverId);
|
|
304
|
-
const result = await runCatalogToolsCommand(runtime.context, { serverId });
|
|
305
|
-
const data = ensureSuccess(result, runtime, {
|
|
306
|
-
command,
|
|
307
|
-
entity: {
|
|
308
|
-
serverId,
|
|
309
|
-
},
|
|
310
|
-
});
|
|
311
|
-
runtime.output.success(data, {
|
|
312
|
-
command,
|
|
313
|
-
entity: {
|
|
314
|
-
serverId: data.server.serverId,
|
|
315
|
-
toolCount: data.tools.length,
|
|
316
|
-
},
|
|
317
|
-
humanMessage: `${data.tools.length} tool(s) available on ${data.server.serverId}.`,
|
|
318
|
-
nextActions: nextActionsForCatalogTools(data),
|
|
319
|
-
});
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
if (invocation.cursor !== undefined || parsedLimit !== undefined) {
|
|
323
|
-
throw new ValidationError({
|
|
324
|
-
details: `${invocation.cursor === undefined ? "" : `--cursor ${invocation.cursor} `}${parsedLimit === undefined ? "" : `--limit ${parsedLimit}`}`.trim(),
|
|
325
|
-
message: "Invalid catalog options. --cursor and --limit are only valid for `ogment catalog`.",
|
|
326
|
-
recovery: {
|
|
327
|
-
command: cliCommands.catalog.tool(invocation.serverId, invocation.toolName, {
|
|
328
|
-
example: invocation.example,
|
|
329
|
-
}),
|
|
330
|
-
},
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
const serverId = invocation.serverId;
|
|
334
|
-
const toolName = invocation.toolName;
|
|
335
|
-
const command = cliCommands.catalog.tool(serverId, toolName, {
|
|
336
|
-
example: invocation.example,
|
|
337
|
-
});
|
|
338
|
-
const result = await runCatalogToolDetailsCommand(runtime.context, { serverId, toolName });
|
|
339
|
-
const data = ensureSuccess(result, runtime, {
|
|
340
|
-
command,
|
|
341
|
-
entity: {
|
|
342
|
-
serverId,
|
|
343
|
-
toolName,
|
|
344
|
-
},
|
|
345
|
-
});
|
|
346
|
-
const exampleInput = buildJsonSchemaExample(data.inputSchema);
|
|
347
|
-
const outputData = invocation.example ? { ...data, exampleInput } : data;
|
|
348
|
-
runtime.output.success(outputData, {
|
|
349
|
-
command,
|
|
350
|
-
entity: {
|
|
351
|
-
serverId: data.server.serverId,
|
|
352
|
-
toolName: data.name,
|
|
353
|
-
},
|
|
354
|
-
humanMessage: `Loaded schema for ${data.server.serverId}/${data.name}.`,
|
|
355
|
-
nextActions: nextActionsForCatalogToolDetails(data, exampleInput),
|
|
356
|
-
});
|
|
357
|
-
};
|
|
358
|
-
const executeInvokeInvocation = async (runtime, invocation) => {
|
|
359
|
-
let inputSource = "none";
|
|
360
|
-
let command = cliCommands.invoke.command(invocation.target);
|
|
361
|
-
if (invocation.input !== undefined) {
|
|
362
|
-
if (invocation.input === "-") {
|
|
363
|
-
inputSource = "stdin";
|
|
364
|
-
command = cliCommands.invoke.stdin(invocation.target);
|
|
365
|
-
}
|
|
366
|
-
else if (invocation.input.startsWith("@")) {
|
|
367
|
-
inputSource = "file";
|
|
368
|
-
command = cliCommands.invoke.withInputValue(invocation.target, invocation.input);
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
inputSource = "inline_json";
|
|
372
|
-
command = cliCommands.invoke.inlineJson(invocation.target);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
const result = await runInvokeCommand(runtime.context, {
|
|
376
|
-
input: invocation.input,
|
|
377
|
-
target: invocation.target,
|
|
378
|
-
});
|
|
379
|
-
const data = ensureSuccess(result, runtime, {
|
|
380
|
-
command,
|
|
381
|
-
entity: {
|
|
382
|
-
inputSource,
|
|
383
|
-
target: invocation.target,
|
|
384
|
-
},
|
|
385
|
-
});
|
|
386
|
-
runtime.output.success(data, {
|
|
387
|
-
command,
|
|
388
|
-
entity: {
|
|
389
|
-
inputSource,
|
|
390
|
-
serverId: data.serverId,
|
|
391
|
-
toolName: data.toolName,
|
|
392
|
-
},
|
|
393
|
-
humanMessage: `Invoked ${data.serverId}/${data.toolName}.`,
|
|
394
|
-
nextActions: nextActionsForInvoke(data),
|
|
395
|
-
});
|
|
396
|
-
};
|
|
397
|
-
const executeStatusInvocation = async (runtime) => {
|
|
398
|
-
const command = cliCommands.status.command();
|
|
399
|
-
if (runtime.infoService === undefined) {
|
|
400
|
-
throw new UnexpectedError({
|
|
401
|
-
message: "Info service is not configured",
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
const result = await runStatusCommand({
|
|
405
|
-
apiKeyOverride: runtime.context.apiKeyOverride,
|
|
406
|
-
}, {
|
|
407
|
-
infoService: runtime.infoService,
|
|
408
|
-
});
|
|
409
|
-
const data = ensureSuccess(result, runtime, {
|
|
410
|
-
command,
|
|
411
|
-
});
|
|
412
|
-
runtime.output.success(data, {
|
|
413
|
-
command,
|
|
414
|
-
entity: {
|
|
415
|
-
summaryStatus: data.summary.status,
|
|
416
|
-
},
|
|
417
|
-
humanMessage: `Diagnostics status: ${data.summary.status.toUpperCase()}`,
|
|
418
|
-
nextActions: nextActionsForStatus(data),
|
|
419
|
-
});
|
|
420
|
-
};
|
|
421
|
-
const executeRootInvocation = (runtime) => {
|
|
422
|
-
runtime.output.success({
|
|
423
|
-
commands: cliCommands.root.commandsSurface(),
|
|
424
|
-
}, {
|
|
425
|
-
command: cliCommands.root.command(),
|
|
426
|
-
entity: null,
|
|
427
|
-
humanMessage: "Select a command to continue.",
|
|
428
|
-
nextActions: [
|
|
429
|
-
nextAction("login", "Authenticate", cliCommands.auth.login(), "Authenticate first so catalog and invoke commands can run.", "immediate"),
|
|
430
|
-
nextAction("catalog", "Discover servers", cliCommands.catalog.command(), "List accessible servers and tool counts.", "after_auth"),
|
|
431
|
-
],
|
|
432
|
-
});
|
|
433
|
-
};
|
|
434
|
-
const invocationHandlers = {
|
|
435
|
-
auth_login: executeAuthLoginInvocation,
|
|
436
|
-
auth_logout: async (runtime) => executeAuthLogoutInvocation(runtime),
|
|
437
|
-
auth_status: async (runtime) => executeAuthStatusInvocation(runtime),
|
|
438
|
-
catalog: executeCatalogInvocation,
|
|
439
|
-
invoke: executeInvokeInvocation,
|
|
440
|
-
root: async (runtime) => {
|
|
441
|
-
executeRootInvocation(runtime);
|
|
442
|
-
},
|
|
443
|
-
status: async (runtime) => executeStatusInvocation(runtime),
|
|
444
|
-
};
|
|
445
|
-
export const executeInvocation = async (runtime, invocation) => {
|
|
446
|
-
const handler = invocationHandlers[invocation.kind];
|
|
447
|
-
await handler(runtime, invocation);
|
|
448
|
-
};
|
|
449
|
-
export const normalizeCliRuntimeError = (error) => {
|
|
450
|
-
if (error instanceof AuthError ||
|
|
451
|
-
error instanceof ContractMismatchError ||
|
|
452
|
-
error instanceof NotFoundError ||
|
|
453
|
-
error instanceof RemoteRequestError ||
|
|
454
|
-
error instanceof UnexpectedError ||
|
|
455
|
-
error instanceof ValidationError) {
|
|
456
|
-
return error;
|
|
457
|
-
}
|
|
458
|
-
if (error instanceof Error) {
|
|
459
|
-
return new UnexpectedError({
|
|
460
|
-
cause: error,
|
|
461
|
-
message: error.message,
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
return new UnexpectedError({
|
|
465
|
-
cause: error,
|
|
466
|
-
message: "Unexpected CLI failure",
|
|
467
|
-
});
|
|
468
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export interface AuthLoginInvocation {
|
|
2
|
-
apiKey: string | undefined;
|
|
3
|
-
kind: "auth_login";
|
|
4
|
-
}
|
|
5
|
-
export interface AuthStatusInvocation {
|
|
6
|
-
kind: "auth_status";
|
|
7
|
-
}
|
|
8
|
-
export interface AuthLogoutInvocation {
|
|
9
|
-
kind: "auth_logout";
|
|
10
|
-
}
|
|
11
|
-
export interface CatalogInvocation {
|
|
12
|
-
cursor: string | undefined;
|
|
13
|
-
example: boolean;
|
|
14
|
-
kind: "catalog";
|
|
15
|
-
limit: number | undefined;
|
|
16
|
-
serverId: string | undefined;
|
|
17
|
-
toolName: string | undefined;
|
|
18
|
-
}
|
|
19
|
-
export interface InvokeInvocation {
|
|
20
|
-
input: string | undefined;
|
|
21
|
-
kind: "invoke";
|
|
22
|
-
target: string;
|
|
23
|
-
}
|
|
24
|
-
export interface StatusInvocation {
|
|
25
|
-
kind: "status";
|
|
26
|
-
}
|
|
27
|
-
export interface RootInvocation {
|
|
28
|
-
kind: "root";
|
|
29
|
-
}
|
|
30
|
-
export type CliInvocation = AuthLoginInvocation | AuthLogoutInvocation | AuthStatusInvocation | CatalogInvocation | InvokeInvocation | RootInvocation | StatusInvocation;
|
|
31
|
-
//# sourceMappingURL=invocations.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invocations.d.ts","sourceRoot":"","sources":["../../src/cli/invocations.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,aAAa,GACrB,mBAAmB,GACnB,oBAAoB,GACpB,oBAAoB,GACpB,iBAAiB,GACjB,gBAAgB,GAChB,cAAc,GACd,gBAAgB,CAAC"}
|
package/dist/cli/invocations.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { CommanderError } from "commander";
|
|
2
|
-
import type { CliNextAction, CliParseErrorPayload } from "../shared/types.js";
|
|
3
|
-
export interface CommanderParseState {
|
|
4
|
-
stderrChunks: string[];
|
|
5
|
-
stdoutChunks: string[];
|
|
6
|
-
}
|
|
7
|
-
export interface ParseCliErrorResult {
|
|
8
|
-
nextActions: CliNextAction[];
|
|
9
|
-
payload: CliParseErrorPayload;
|
|
10
|
-
}
|
|
11
|
-
interface ParseCliErrorOptions {
|
|
12
|
-
includeDebug?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export declare const createCommanderParseState: () => CommanderParseState;
|
|
15
|
-
export declare const toParseCliError: (error: CommanderError, parseState: CommanderParseState, options?: ParseCliErrorOptions) => ParseCliErrorResult;
|
|
16
|
-
export {};
|
|
17
|
-
//# sourceMappingURL=parse-errors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-errors.d.ts","sourceRoot":"","sources":["../../src/cli/parse-errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAqB,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAGjG,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,aAAa,EAAE,CAAC;IAC7B,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AAED,UAAU,oBAAoB;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAsLD,eAAO,MAAM,yBAAyB,QAAO,mBAK5C,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,OAAO,cAAc,EACrB,YAAY,mBAAmB,EAC/B,UAAS,oBAAyB,KACjC,mBAwBF,CAAC"}
|