@ogment-ai/cli 0.6.0 → 0.7.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/dist/cli.js +21382 -4
- package/dist/cli.js.map +1 -0
- package/package.json +46 -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/commands/catalog.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { Result } from "better-result";
|
|
2
|
-
import { ERROR_CODE } from "../shared/error-codes.js";
|
|
3
|
-
import { presentCatalogFailureError } from "../shared/error-presentation.js";
|
|
4
|
-
import { NotFoundError, ValidationError } from "../shared/errors.js";
|
|
5
|
-
import { findServerByPath, resolveServerState, } from "./server-context.js";
|
|
6
|
-
const toServerSummary = (server, toolCount) => {
|
|
7
|
-
return {
|
|
8
|
-
capabilities: [],
|
|
9
|
-
description: server.description,
|
|
10
|
-
name: server.name,
|
|
11
|
-
orgSlug: server.orgSlug,
|
|
12
|
-
serverId: server.path,
|
|
13
|
-
toolCount,
|
|
14
|
-
version: null,
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
const toToolSummaries = (tools) => {
|
|
18
|
-
return tools.map((tool) => {
|
|
19
|
-
return {
|
|
20
|
-
description: tool.description,
|
|
21
|
-
name: tool.name,
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
const listServerTools = async (context, apiKey, server) => {
|
|
26
|
-
return context.services.mcp.listTools({
|
|
27
|
-
orgSlug: server.orgSlug,
|
|
28
|
-
serverPath: server.path,
|
|
29
|
-
}, apiKey);
|
|
30
|
-
};
|
|
31
|
-
const TOOL_COUNT_CONCURRENCY = 4;
|
|
32
|
-
const toCatalogServerFailure = (server, error, includeDebug) => {
|
|
33
|
-
return {
|
|
34
|
-
error: presentCatalogFailureError(error, {
|
|
35
|
-
includeDebug,
|
|
36
|
-
}),
|
|
37
|
-
orgSlug: server.orgSlug,
|
|
38
|
-
serverId: server.path,
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
const mapWithConcurrency = async (items, concurrency, mapItem) => {
|
|
42
|
-
if (items.length === 0) {
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
const results = Array.from({ length: items.length });
|
|
46
|
-
let nextIndex = 0;
|
|
47
|
-
const worker = async () => {
|
|
48
|
-
while (true) {
|
|
49
|
-
const currentIndex = nextIndex;
|
|
50
|
-
nextIndex += 1;
|
|
51
|
-
if (currentIndex >= items.length) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
results[currentIndex] = await mapItem(items[currentIndex], currentIndex);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const workerCount = Math.min(concurrency, items.length);
|
|
58
|
-
await Promise.all(Array.from({ length: workerCount }, async () => worker()));
|
|
59
|
-
return results;
|
|
60
|
-
};
|
|
61
|
-
export const runCatalogCommand = async (context, options) => {
|
|
62
|
-
const stateResult = await resolveServerState(context);
|
|
63
|
-
if (Result.isError(stateResult)) {
|
|
64
|
-
return stateResult;
|
|
65
|
-
}
|
|
66
|
-
let targetServers = stateResult.value.servers;
|
|
67
|
-
if (options.serverId !== undefined) {
|
|
68
|
-
const serverResult = findServerByPath(stateResult.value.servers, options.serverId);
|
|
69
|
-
if (Result.isError(serverResult)) {
|
|
70
|
-
return serverResult;
|
|
71
|
-
}
|
|
72
|
-
targetServers = [serverResult.value];
|
|
73
|
-
}
|
|
74
|
-
const serverSummaries = await mapWithConcurrency(targetServers, TOOL_COUNT_CONCURRENCY, async (server) => {
|
|
75
|
-
const toolsResult = await listServerTools(context, stateResult.value.apiKey, server);
|
|
76
|
-
return {
|
|
77
|
-
server,
|
|
78
|
-
toolsResult,
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
const summaries = [];
|
|
82
|
-
const failures = [];
|
|
83
|
-
for (const serverSummary of serverSummaries) {
|
|
84
|
-
if (Result.isError(serverSummary.toolsResult)) {
|
|
85
|
-
if (options.serverId !== undefined) {
|
|
86
|
-
return serverSummary.toolsResult;
|
|
87
|
-
}
|
|
88
|
-
failures.push(toCatalogServerFailure(serverSummary.server, serverSummary.toolsResult.error, options.includeDebug === true));
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
summaries.push(toServerSummary(serverSummary.server, serverSummary.toolsResult.value.length));
|
|
92
|
-
}
|
|
93
|
-
if (options.serverId !== undefined) {
|
|
94
|
-
return Result.ok({
|
|
95
|
-
failures: [],
|
|
96
|
-
nextCursor: null,
|
|
97
|
-
servers: summaries,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
const limit = Math.max(1, options.limit ?? 20);
|
|
101
|
-
let startIndex = 0;
|
|
102
|
-
if (options.cursor !== undefined) {
|
|
103
|
-
const cursorIndex = summaries.findIndex((server) => server.serverId === options.cursor);
|
|
104
|
-
if (cursorIndex === -1) {
|
|
105
|
-
return Result.err(new ValidationError({
|
|
106
|
-
code: ERROR_CODE.validationInvalidInput,
|
|
107
|
-
message: `Invalid --cursor value: "${options.cursor}"`,
|
|
108
|
-
recovery: { command: "ogment catalog" },
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
startIndex = cursorIndex + 1;
|
|
112
|
-
}
|
|
113
|
-
const servers = summaries.slice(startIndex, startIndex + limit);
|
|
114
|
-
const hasMore = startIndex + limit < summaries.length;
|
|
115
|
-
const nextCursor = hasMore ? (servers.at(-1)?.serverId ?? null) : null;
|
|
116
|
-
return Result.ok({
|
|
117
|
-
failures,
|
|
118
|
-
nextCursor,
|
|
119
|
-
servers,
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
export const runCatalogToolsCommand = async (context, options) => {
|
|
123
|
-
const stateResult = await resolveServerState(context);
|
|
124
|
-
if (Result.isError(stateResult)) {
|
|
125
|
-
return stateResult;
|
|
126
|
-
}
|
|
127
|
-
const serverResult = findServerByPath(stateResult.value.servers, options.serverId);
|
|
128
|
-
if (Result.isError(serverResult)) {
|
|
129
|
-
return serverResult;
|
|
130
|
-
}
|
|
131
|
-
const toolsResult = await listServerTools(context, stateResult.value.apiKey, serverResult.value);
|
|
132
|
-
if (Result.isError(toolsResult)) {
|
|
133
|
-
return toolsResult;
|
|
134
|
-
}
|
|
135
|
-
return Result.ok({
|
|
136
|
-
server: toServerSummary(serverResult.value, toolsResult.value.length),
|
|
137
|
-
tools: toToolSummaries(toolsResult.value),
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
export const runCatalogToolDetailsCommand = async (context, options) => {
|
|
141
|
-
const stateResult = await resolveServerState(context);
|
|
142
|
-
if (Result.isError(stateResult)) {
|
|
143
|
-
return stateResult;
|
|
144
|
-
}
|
|
145
|
-
const serverResult = findServerByPath(stateResult.value.servers, options.serverId);
|
|
146
|
-
if (Result.isError(serverResult)) {
|
|
147
|
-
return serverResult;
|
|
148
|
-
}
|
|
149
|
-
const toolsResult = await listServerTools(context, stateResult.value.apiKey, serverResult.value);
|
|
150
|
-
if (Result.isError(toolsResult)) {
|
|
151
|
-
return toolsResult;
|
|
152
|
-
}
|
|
153
|
-
const tool = toolsResult.value.find((item) => item.name === options.toolName);
|
|
154
|
-
if (tool === undefined) {
|
|
155
|
-
return Result.err(new NotFoundError({
|
|
156
|
-
message: `Tool "${options.toolName}" not found`,
|
|
157
|
-
resource: options.toolName,
|
|
158
|
-
}));
|
|
159
|
-
}
|
|
160
|
-
return Result.ok({
|
|
161
|
-
description: tool.description,
|
|
162
|
-
inputSchema: tool.inputSchema,
|
|
163
|
-
name: tool.name,
|
|
164
|
-
outputSchema: tool.outputSchema ?? null,
|
|
165
|
-
server: toServerSummary(serverResult.value, toolsResult.value.length),
|
|
166
|
-
});
|
|
167
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { OutputManager } from "../output/manager.js";
|
|
2
|
-
import type { AccountService } from "../services/account.js";
|
|
3
|
-
import type { AuthService } from "../services/auth.js";
|
|
4
|
-
import type { McpService } from "../services/mcp.js";
|
|
5
|
-
export interface CommandServices {
|
|
6
|
-
account: AccountService;
|
|
7
|
-
auth: AuthService;
|
|
8
|
-
mcp: McpService;
|
|
9
|
-
}
|
|
10
|
-
export interface CommandContext {
|
|
11
|
-
apiKeyOverride: string | undefined;
|
|
12
|
-
output: OutputManager;
|
|
13
|
-
services: CommandServices;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/commands/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,cAAc,CAAC;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,GAAG,EAAE,UAAU,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,eAAe,CAAC;CAC3B"}
|
package/dist/commands/context.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Result as ResultType } from "better-result";
|
|
2
|
-
import type { McpServiceError } from "../services/mcp.js";
|
|
3
|
-
import { NotFoundError, UnexpectedError, ValidationError } from "../shared/errors.js";
|
|
4
|
-
import type { InvokeSuccess } from "../shared/types.js";
|
|
5
|
-
import type { CommandContext } from "./context.js";
|
|
6
|
-
import { type ResolveServerStateError } from "./server-context.js";
|
|
7
|
-
export interface InvokeCommandOptions {
|
|
8
|
-
input: string | undefined;
|
|
9
|
-
target: string;
|
|
10
|
-
}
|
|
11
|
-
interface InvokeCommandDeps {
|
|
12
|
-
readStdin?: () => Promise<ResultType<string, UnexpectedError>>;
|
|
13
|
-
}
|
|
14
|
-
export type InvokeCommandError = McpServiceError | NotFoundError | ResolveServerStateError | UnexpectedError | ValidationError;
|
|
15
|
-
export declare const runInvokeCommand: (context: CommandContext, options: InvokeCommandOptions, deps?: InvokeCommandDeps) => Promise<ResultType<InvokeSuccess, InvokeCommandError>>;
|
|
16
|
-
export {};
|
|
17
|
-
//# sourceMappingURL=invoke.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../src/commands/invoke.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EACL,aAAa,EAEb,eAAe,EACf,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,iBAAiB;IACzB,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CAChE;AAED,MAAM,MAAM,kBAAkB,GAC1B,eAAe,GACf,aAAa,GACb,uBAAuB,GACvB,eAAe,GACf,eAAe,CAAC;AAmKpB,eAAO,MAAM,gBAAgB,GAC3B,SAAS,cAAc,EACvB,SAAS,oBAAoB,EAC7B,OAAM,iBAAsB,KAC3B,OAAO,CAAC,UAAU,CAAC,aAAa,EAAE,kBAAkB,CAAC,CA0EvD,CAAC"}
|
package/dist/commands/invoke.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { Result } from "better-result";
|
|
3
|
-
import { NotFoundError, RemoteRequestError, UnexpectedError, ValidationError, } from "../shared/errors.js";
|
|
4
|
-
import { findServerByPath, resolveServerState, } from "./server-context.js";
|
|
5
|
-
const parseToolErrorDetails = (payload) => {
|
|
6
|
-
if (typeof payload !== "object" || payload === null) {
|
|
7
|
-
return {};
|
|
8
|
-
}
|
|
9
|
-
const record = payload;
|
|
10
|
-
const directCode = record["code"];
|
|
11
|
-
const directMessage = record["message"];
|
|
12
|
-
if (typeof directCode === "number" || typeof directMessage === "string") {
|
|
13
|
-
return {
|
|
14
|
-
...(typeof directCode === "number" ? { mcpCode: directCode } : {}),
|
|
15
|
-
...(typeof directMessage === "string" ? { message: directMessage } : {}),
|
|
16
|
-
...(Object.hasOwn(record, "data") ? { mcpData: record["data"] } : {}),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
const nestedError = record["error"];
|
|
20
|
-
if (typeof nestedError !== "object" || nestedError === null) {
|
|
21
|
-
return {};
|
|
22
|
-
}
|
|
23
|
-
const nestedRecord = nestedError;
|
|
24
|
-
return {
|
|
25
|
-
...(typeof nestedRecord["code"] === "number" ? { mcpCode: nestedRecord["code"] } : {}),
|
|
26
|
-
...(typeof nestedRecord["message"] === "string" ? { message: nestedRecord["message"] } : {}),
|
|
27
|
-
...(Object.hasOwn(nestedRecord, "data") ? { mcpData: nestedRecord["data"] } : {}),
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
const parseTarget = (target) => {
|
|
31
|
-
const separatorIndex = target.lastIndexOf("/");
|
|
32
|
-
if (separatorIndex <= 0 || separatorIndex >= target.length - 1) {
|
|
33
|
-
return Result.err(new ValidationError({
|
|
34
|
-
details: target,
|
|
35
|
-
message: "Invoke target must be in format <server-id>/<tool-name>",
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
const serverId = target.slice(0, separatorIndex);
|
|
39
|
-
const toolName = target.slice(separatorIndex + 1);
|
|
40
|
-
return Result.ok({
|
|
41
|
-
serverId,
|
|
42
|
-
toolName,
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
const parseInputObject = (raw, context) => {
|
|
46
|
-
const parsed = Result.try({
|
|
47
|
-
catch: () => new ValidationError({
|
|
48
|
-
details: raw,
|
|
49
|
-
message: `Invalid JSON in ${context}`,
|
|
50
|
-
}),
|
|
51
|
-
try: () => JSON.parse(raw),
|
|
52
|
-
});
|
|
53
|
-
if (Result.isError(parsed)) {
|
|
54
|
-
return parsed;
|
|
55
|
-
}
|
|
56
|
-
if (typeof parsed.value !== "object" || parsed.value === null || Array.isArray(parsed.value)) {
|
|
57
|
-
return Result.err(new ValidationError({
|
|
58
|
-
message: "Invoke input must be a JSON object",
|
|
59
|
-
}));
|
|
60
|
-
}
|
|
61
|
-
return Result.ok(parsed.value);
|
|
62
|
-
};
|
|
63
|
-
const readStdin = async () => {
|
|
64
|
-
return Result.tryPromise({
|
|
65
|
-
catch: (cause) => new UnexpectedError({
|
|
66
|
-
cause,
|
|
67
|
-
message: "Failed to read stdin",
|
|
68
|
-
}),
|
|
69
|
-
try: async () => {
|
|
70
|
-
return new Promise((resolve, reject) => {
|
|
71
|
-
let data = "";
|
|
72
|
-
process.stdin.setEncoding("utf8");
|
|
73
|
-
process.stdin.on("data", (chunk) => {
|
|
74
|
-
data += chunk.toString();
|
|
75
|
-
});
|
|
76
|
-
process.stdin.on("end", () => {
|
|
77
|
-
resolve(data);
|
|
78
|
-
});
|
|
79
|
-
process.stdin.on("error", (error) => {
|
|
80
|
-
reject(error);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
const parseInvokeArgs = async (options, deps) => {
|
|
87
|
-
if (options.input === undefined) {
|
|
88
|
-
return Result.ok({});
|
|
89
|
-
}
|
|
90
|
-
if (options.input === "-") {
|
|
91
|
-
const stdinResult = await (deps.readStdin ?? readStdin)();
|
|
92
|
-
if (Result.isError(stdinResult)) {
|
|
93
|
-
return stdinResult;
|
|
94
|
-
}
|
|
95
|
-
return parseInputObject(stdinResult.value, "--input (-)");
|
|
96
|
-
}
|
|
97
|
-
if (options.input.startsWith("@")) {
|
|
98
|
-
const inputFile = options.input.slice(1);
|
|
99
|
-
if (inputFile.length === 0) {
|
|
100
|
-
return Result.err(new ValidationError({
|
|
101
|
-
details: options.input,
|
|
102
|
-
message: "Invalid --input value. Use @<path>, -, or an inline JSON object.",
|
|
103
|
-
}));
|
|
104
|
-
}
|
|
105
|
-
const fileReadResult = await Result.tryPromise({
|
|
106
|
-
catch: (cause) => new UnexpectedError({
|
|
107
|
-
cause,
|
|
108
|
-
message: `Failed to read input file: ${inputFile}`,
|
|
109
|
-
}),
|
|
110
|
-
try: async () => readFile(inputFile, "utf8"),
|
|
111
|
-
});
|
|
112
|
-
if (Result.isError(fileReadResult)) {
|
|
113
|
-
return fileReadResult;
|
|
114
|
-
}
|
|
115
|
-
return parseInputObject(fileReadResult.value, "--input (@file)");
|
|
116
|
-
}
|
|
117
|
-
return parseInputObject(options.input, "--input");
|
|
118
|
-
};
|
|
119
|
-
export const runInvokeCommand = async (context, options, deps = {}) => {
|
|
120
|
-
const targetResult = parseTarget(options.target);
|
|
121
|
-
if (Result.isError(targetResult)) {
|
|
122
|
-
return targetResult;
|
|
123
|
-
}
|
|
124
|
-
const argsResult = await parseInvokeArgs(options, deps);
|
|
125
|
-
if (Result.isError(argsResult)) {
|
|
126
|
-
return argsResult;
|
|
127
|
-
}
|
|
128
|
-
const stateResult = await resolveServerState(context);
|
|
129
|
-
if (Result.isError(stateResult)) {
|
|
130
|
-
return stateResult;
|
|
131
|
-
}
|
|
132
|
-
const serverResult = findServerByPath(stateResult.value.servers, targetResult.value.serverId);
|
|
133
|
-
if (Result.isError(serverResult)) {
|
|
134
|
-
return serverResult;
|
|
135
|
-
}
|
|
136
|
-
const mcpTarget = {
|
|
137
|
-
orgSlug: serverResult.value.orgSlug,
|
|
138
|
-
serverPath: serverResult.value.path,
|
|
139
|
-
};
|
|
140
|
-
const callResult = await context.services.mcp.callTool(mcpTarget, stateResult.value.apiKey, targetResult.value.toolName, argsResult.value);
|
|
141
|
-
if (Result.isError(callResult)) {
|
|
142
|
-
if (callResult.error._tag === "RemoteRequestError") {
|
|
143
|
-
const toolsResult = await context.services.mcp.listTools(mcpTarget, stateResult.value.apiKey);
|
|
144
|
-
if (Result.isOk(toolsResult)) {
|
|
145
|
-
const toolExists = toolsResult.value.some((tool) => tool.name === targetResult.value.toolName);
|
|
146
|
-
if (!toolExists) {
|
|
147
|
-
return Result.err(new NotFoundError({
|
|
148
|
-
message: `Tool "${targetResult.value.toolName}" not found`,
|
|
149
|
-
resource: targetResult.value.toolName,
|
|
150
|
-
}));
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return callResult;
|
|
155
|
-
}
|
|
156
|
-
if (callResult.value.isError) {
|
|
157
|
-
const details = parseToolErrorDetails(callResult.value.structuredContent);
|
|
158
|
-
return Result.err(new RemoteRequestError({
|
|
159
|
-
...(details.mcpCode === undefined ? {} : { mcpCode: details.mcpCode }),
|
|
160
|
-
...(details.mcpData === undefined ? {} : { mcpData: details.mcpData }),
|
|
161
|
-
message: details.message ?? "MCP tool call returned an error result",
|
|
162
|
-
operation: "tools/call",
|
|
163
|
-
raw: callResult.value.structuredContent,
|
|
164
|
-
retryable: false,
|
|
165
|
-
source: "mcp_jsonrpc",
|
|
166
|
-
}));
|
|
167
|
-
}
|
|
168
|
-
return Result.ok({
|
|
169
|
-
result: callResult.value.structuredContent,
|
|
170
|
-
serverId: targetResult.value.serverId,
|
|
171
|
-
toolName: targetResult.value.toolName,
|
|
172
|
-
});
|
|
173
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Result as ResultType } from "better-result";
|
|
2
|
-
import type { FetchAccountError } from "../services/account.js";
|
|
3
|
-
import type { ResolveApiKeyError } from "../services/auth.js";
|
|
4
|
-
import { NotFoundError } from "../shared/errors.js";
|
|
5
|
-
import type { ServerWithOrg } from "../shared/types.js";
|
|
6
|
-
import type { CommandContext } from "./context.js";
|
|
7
|
-
export interface ResolvedServerState {
|
|
8
|
-
apiKey: string;
|
|
9
|
-
servers: ServerWithOrg[];
|
|
10
|
-
}
|
|
11
|
-
export type ResolveServerStateError = FetchAccountError | ResolveApiKeyError;
|
|
12
|
-
export declare const resolveServerState: (context: CommandContext) => Promise<ResultType<ResolvedServerState, ResolveServerStateError>>;
|
|
13
|
-
export declare const findServerByPath: (servers: readonly ServerWithOrg[], path: string) => ResultType<ServerWithOrg, NotFoundError>;
|
|
14
|
-
//# sourceMappingURL=server-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server-context.d.ts","sourceRoot":"","sources":["../../src/commands/server-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,MAAM,MAAM,uBAAuB,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;AAE7E,eAAO,MAAM,kBAAkB,GAC7B,SAAS,cAAc,KACtB,OAAO,CAAC,UAAU,CAAC,mBAAmB,EAAE,uBAAuB,CAAC,CAelE,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,SAAS,SAAS,aAAa,EAAE,EACjC,MAAM,MAAM,KACX,UAAU,CAAC,aAAa,EAAE,aAAa,CAazC,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Result } from "better-result";
|
|
2
|
-
import { NotFoundError } from "../shared/errors.js";
|
|
3
|
-
export const resolveServerState = async (context) => {
|
|
4
|
-
const apiKeyResult = await context.services.auth.resolveApiKey(context.apiKeyOverride);
|
|
5
|
-
if (Result.isError(apiKeyResult)) {
|
|
6
|
-
return apiKeyResult;
|
|
7
|
-
}
|
|
8
|
-
const serversResult = await context.services.account.listServers(apiKeyResult.value);
|
|
9
|
-
if (Result.isError(serversResult)) {
|
|
10
|
-
return serversResult;
|
|
11
|
-
}
|
|
12
|
-
return Result.ok({
|
|
13
|
-
apiKey: apiKeyResult.value,
|
|
14
|
-
servers: serversResult.value,
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
export const findServerByPath = (servers, path) => {
|
|
18
|
-
const server = servers.find((item) => item.path === path);
|
|
19
|
-
if (server === undefined) {
|
|
20
|
-
return Result.err(new NotFoundError({
|
|
21
|
-
message: `Server \"${path}\" not found`,
|
|
22
|
-
resource: path,
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
return Result.ok(server);
|
|
26
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Result as ResultType } from "better-result";
|
|
2
|
-
import type { InfoService } from "../services/info.js";
|
|
3
|
-
import type { InfoPayload } from "../shared/types.js";
|
|
4
|
-
export interface StatusCommandOptions {
|
|
5
|
-
apiKeyOverride: string | undefined;
|
|
6
|
-
}
|
|
7
|
-
interface RunStatusCommandDeps {
|
|
8
|
-
infoService: InfoService;
|
|
9
|
-
}
|
|
10
|
-
export declare const runStatusCommand: (options: StatusCommandOptions, deps: RunStatusCommandDeps) => Promise<ResultType<InfoPayload, never>>;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=status.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAED,UAAU,oBAAoB;IAC5B,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,eAAO,MAAM,gBAAgB,GAC3B,SAAS,oBAAoB,EAC7B,MAAM,oBAAoB,KACzB,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC,CAGxC,CAAC"}
|
package/dist/commands/status.js
DELETED
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { existsSync, lstatSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { Result } from "better-result";
|
|
3
|
-
import { UnexpectedError } from "../shared/errors.js";
|
|
4
|
-
import type { Credentials } from "../shared/types.js";
|
|
5
|
-
export interface CredentialsStore {
|
|
6
|
-
delete(): Result<void, UnexpectedError>;
|
|
7
|
-
load(): Result<Credentials | null, UnexpectedError>;
|
|
8
|
-
save(credentials: Credentials): Result<void, UnexpectedError>;
|
|
9
|
-
}
|
|
10
|
-
interface CredentialsStoreDeps {
|
|
11
|
-
credentialsPath: string;
|
|
12
|
-
configDir: string;
|
|
13
|
-
existsSyncFn?: typeof existsSync;
|
|
14
|
-
lstatSyncFn?: typeof lstatSync;
|
|
15
|
-
mkdirSyncFn?: typeof mkdirSync;
|
|
16
|
-
readFileSyncFn?: typeof readFileSync;
|
|
17
|
-
unlinkSyncFn?: typeof unlinkSync;
|
|
18
|
-
writeFileSyncFn?: typeof writeFileSync;
|
|
19
|
-
}
|
|
20
|
-
export declare const createFileCredentialsStore: (deps: CredentialsStoreDeps) => CredentialsStore;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/infra/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEpG,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACxC,IAAI,IAAI,MAAM,CAAC,WAAW,GAAG,IAAI,EAAE,eAAe,CAAC,CAAC;IACpD,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;CAC/D;AAED,UAAU,oBAAoB;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,UAAU,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,SAAS,CAAC;IAC/B,WAAW,CAAC,EAAE,OAAO,SAAS,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,YAAY,CAAC;IACrC,YAAY,CAAC,EAAE,OAAO,UAAU,CAAC;IACjC,eAAe,CAAC,EAAE,OAAO,aAAa,CAAC;CACxC;AA8BD,eAAO,MAAM,0BAA0B,GAAI,MAAM,oBAAoB,KAAG,gBAyDvE,CAAC"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { existsSync, lstatSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { Result } from "better-result";
|
|
3
|
-
import { UnexpectedError } from "../shared/errors.js";
|
|
4
|
-
import { parseWithSchema } from "../shared/guards.js";
|
|
5
|
-
import { credentialsFileSchema } from "../shared/schemas.js";
|
|
6
|
-
const deleteIfExists = (path, existsSyncFn, unlinkSyncFn) => {
|
|
7
|
-
if (existsSyncFn(path)) {
|
|
8
|
-
unlinkSyncFn(path);
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
const normalizeCredentials = (value) => {
|
|
12
|
-
const parsed = parseWithSchema(credentialsFileSchema, value, "credentials file");
|
|
13
|
-
if (Result.isError(parsed)) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
if (typeof parsed.value.apiKey === "string" && parsed.value.apiKey.length > 0) {
|
|
17
|
-
const credentials = { apiKey: parsed.value.apiKey };
|
|
18
|
-
if (typeof parsed.value.agentName === "string") {
|
|
19
|
-
credentials.agentName = parsed.value.agentName;
|
|
20
|
-
}
|
|
21
|
-
return credentials;
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
};
|
|
25
|
-
export const createFileCredentialsStore = (deps) => {
|
|
26
|
-
const existsSyncFn = deps.existsSyncFn ?? existsSync;
|
|
27
|
-
const lstatSyncFn = deps.lstatSyncFn ?? lstatSync;
|
|
28
|
-
const mkdirSyncFn = deps.mkdirSyncFn ?? mkdirSync;
|
|
29
|
-
const readFileSyncFn = deps.readFileSyncFn ?? readFileSync;
|
|
30
|
-
const unlinkSyncFn = deps.unlinkSyncFn ?? unlinkSync;
|
|
31
|
-
const writeFileSyncFn = deps.writeFileSyncFn ?? writeFileSync;
|
|
32
|
-
return {
|
|
33
|
-
delete: () => {
|
|
34
|
-
return Result.try({
|
|
35
|
-
catch: (cause) => new UnexpectedError({ cause, message: "Failed to delete credentials" }),
|
|
36
|
-
try: () => {
|
|
37
|
-
deleteIfExists(deps.credentialsPath, existsSyncFn, unlinkSyncFn);
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
load: () => {
|
|
42
|
-
return Result.try({
|
|
43
|
-
catch: (cause) => new UnexpectedError({ cause, message: "Failed to load credentials" }),
|
|
44
|
-
try: () => {
|
|
45
|
-
if (!existsSyncFn(deps.credentialsPath)) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
const raw = readFileSyncFn(deps.credentialsPath, "utf8");
|
|
49
|
-
const parsed = JSON.parse(raw);
|
|
50
|
-
const normalized = normalizeCredentials(parsed);
|
|
51
|
-
if (normalized === null) {
|
|
52
|
-
deleteIfExists(deps.credentialsPath, existsSyncFn, unlinkSyncFn);
|
|
53
|
-
}
|
|
54
|
-
return normalized;
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
},
|
|
58
|
-
save: (credentials) => {
|
|
59
|
-
return Result.try({
|
|
60
|
-
catch: (cause) => new UnexpectedError({ cause, message: "Failed to save credentials" }),
|
|
61
|
-
try: () => {
|
|
62
|
-
mkdirSyncFn(deps.configDir, { recursive: true });
|
|
63
|
-
if (existsSyncFn(deps.credentialsPath) &&
|
|
64
|
-
lstatSyncFn(deps.credentialsPath).isSymbolicLink()) {
|
|
65
|
-
unlinkSyncFn(deps.credentialsPath);
|
|
66
|
-
}
|
|
67
|
-
writeFileSyncFn(deps.credentialsPath, JSON.stringify(credentials, null, 2), {
|
|
68
|
-
mode: 0o600,
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
};
|
package/dist/infra/env.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { BaseUrlSource } from "../shared/types.js";
|
|
2
|
-
export interface RuntimeConfig {
|
|
3
|
-
baseUrl: string;
|
|
4
|
-
baseUrlSource: BaseUrlSource;
|
|
5
|
-
configDir: string;
|
|
6
|
-
credentialsPath: string;
|
|
7
|
-
envApiKey: string | undefined;
|
|
8
|
-
version: string;
|
|
9
|
-
}
|
|
10
|
-
export declare const createRuntimeConfig: (env?: NodeJS.ProcessEnv, homeDirectory?: string) => RuntimeConfig;
|
|
11
|
-
export declare const isInteractiveOutput: (stdout?: NodeJS.WriteStream) => boolean;
|
|
12
|
-
type AncestorProcessReader = () => string[];
|
|
13
|
-
export declare const detectExecutionEnvironment: (env?: NodeJS.ProcessEnv, getAncestors?: AncestorProcessReader) => string;
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=env.d.ts.map
|
package/dist/infra/env.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/infra/env.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,mBAAmB,GAC9B,MAAK,MAAM,CAAC,UAAwB,EACpC,gBAAe,MAAkB,KAChC,aAYF,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,SAAQ,MAAM,CAAC,WAA4B,KAAG,OAEjF,CAAC;AA+BF,KAAK,qBAAqB,GAAG,MAAM,MAAM,EAAE,CAAC;AAE5C,eAAO,MAAM,0BAA0B,GACrC,MAAK,MAAM,CAAC,UAAwB,EACpC,eAAc,qBAA4C,KACzD,MA+DF,CAAC"}
|