@ogment-ai/cli 0.5.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.
Files changed (111) hide show
  1. package/dist/cli.js +21382 -4
  2. package/dist/cli.js.map +1 -0
  3. package/package.json +46 -55
  4. package/README.md +0 -143
  5. package/dist/cli/commands.d.ts +0 -38
  6. package/dist/cli/commands.d.ts.map +0 -1
  7. package/dist/cli/commands.js +0 -57
  8. package/dist/cli/execute.d.ts +0 -11
  9. package/dist/cli/execute.d.ts.map +0 -1
  10. package/dist/cli/execute.js +0 -487
  11. package/dist/cli/invocations.d.ts +0 -32
  12. package/dist/cli/invocations.d.ts.map +0 -1
  13. package/dist/cli/invocations.js +0 -1
  14. package/dist/cli/parse-errors.d.ts +0 -17
  15. package/dist/cli/parse-errors.d.ts.map +0 -1
  16. package/dist/cli/parse-errors.js +0 -184
  17. package/dist/cli/program.d.ts +0 -10
  18. package/dist/cli/program.d.ts.map +0 -1
  19. package/dist/cli/program.js +0 -183
  20. package/dist/cli/run.d.ts +0 -6
  21. package/dist/cli/run.d.ts.map +0 -1
  22. package/dist/cli/run.js +0 -83
  23. package/dist/cli/runtime.d.ts +0 -22
  24. package/dist/cli/runtime.d.ts.map +0 -1
  25. package/dist/cli/runtime.js +0 -86
  26. package/dist/cli.d.ts +0 -4
  27. package/dist/cli.d.ts.map +0 -1
  28. package/dist/commands/auth.d.ts +0 -22
  29. package/dist/commands/auth.d.ts.map +0 -1
  30. package/dist/commands/auth.js +0 -29
  31. package/dist/commands/catalog.d.ts +0 -31
  32. package/dist/commands/catalog.d.ts.map +0 -1
  33. package/dist/commands/catalog.js +0 -167
  34. package/dist/commands/context.d.ts +0 -15
  35. package/dist/commands/context.d.ts.map +0 -1
  36. package/dist/commands/context.js +0 -1
  37. package/dist/commands/invoke.d.ts +0 -17
  38. package/dist/commands/invoke.d.ts.map +0 -1
  39. package/dist/commands/invoke.js +0 -173
  40. package/dist/commands/server-context.d.ts +0 -14
  41. package/dist/commands/server-context.d.ts.map +0 -1
  42. package/dist/commands/server-context.js +0 -26
  43. package/dist/commands/status.d.ts +0 -12
  44. package/dist/commands/status.d.ts.map +0 -1
  45. package/dist/commands/status.js +0 -5
  46. package/dist/index.d.ts +0 -4
  47. package/dist/index.d.ts.map +0 -1
  48. package/dist/index.js +0 -3
  49. package/dist/infra/browser.d.ts +0 -12
  50. package/dist/infra/browser.d.ts.map +0 -1
  51. package/dist/infra/browser.js +0 -20
  52. package/dist/infra/credentials.d.ts +0 -22
  53. package/dist/infra/credentials.d.ts.map +0 -1
  54. package/dist/infra/credentials.js +0 -81
  55. package/dist/infra/env.d.ts +0 -15
  56. package/dist/infra/env.d.ts.map +0 -1
  57. package/dist/infra/env.js +0 -100
  58. package/dist/infra/http.d.ts +0 -16
  59. package/dist/infra/http.d.ts.map +0 -1
  60. package/dist/infra/http.js +0 -84
  61. package/dist/output/envelope.d.ts +0 -22
  62. package/dist/output/envelope.d.ts.map +0 -1
  63. package/dist/output/envelope.js +0 -67
  64. package/dist/output/manager.d.ts +0 -49
  65. package/dist/output/manager.d.ts.map +0 -1
  66. package/dist/output/manager.js +0 -128
  67. package/dist/services/account.d.ts +0 -16
  68. package/dist/services/account.d.ts.map +0 -1
  69. package/dist/services/account.js +0 -75
  70. package/dist/services/auth.d.ts +0 -49
  71. package/dist/services/auth.d.ts.map +0 -1
  72. package/dist/services/auth.js +0 -739
  73. package/dist/services/info.d.ts +0 -24
  74. package/dist/services/info.d.ts.map +0 -1
  75. package/dist/services/info.js +0 -316
  76. package/dist/services/mcp-error-mapping.d.ts +0 -9
  77. package/dist/services/mcp-error-mapping.d.ts.map +0 -1
  78. package/dist/services/mcp-error-mapping.js +0 -129
  79. package/dist/services/mcp.d.ts +0 -39
  80. package/dist/services/mcp.d.ts.map +0 -1
  81. package/dist/services/mcp.js +0 -169
  82. package/dist/shared/constants.d.ts +0 -7
  83. package/dist/shared/constants.d.ts.map +0 -1
  84. package/dist/shared/constants.js +0 -8
  85. package/dist/shared/error-codes.d.ts +0 -31
  86. package/dist/shared/error-codes.d.ts.map +0 -1
  87. package/dist/shared/error-codes.js +0 -25
  88. package/dist/shared/error-presentation.d.ts +0 -17
  89. package/dist/shared/error-presentation.d.ts.map +0 -1
  90. package/dist/shared/error-presentation.js +0 -151
  91. package/dist/shared/errors.d.ts +0 -146
  92. package/dist/shared/errors.d.ts.map +0 -1
  93. package/dist/shared/errors.js +0 -233
  94. package/dist/shared/exit-codes.d.ts +0 -15
  95. package/dist/shared/exit-codes.d.ts.map +0 -1
  96. package/dist/shared/exit-codes.js +0 -44
  97. package/dist/shared/guards.d.ts +0 -11
  98. package/dist/shared/guards.d.ts.map +0 -1
  99. package/dist/shared/guards.js +0 -29
  100. package/dist/shared/recovery.d.ts +0 -5
  101. package/dist/shared/recovery.d.ts.map +0 -1
  102. package/dist/shared/recovery.js +0 -123
  103. package/dist/shared/schema-example.d.ts +0 -3
  104. package/dist/shared/schema-example.d.ts.map +0 -1
  105. package/dist/shared/schema-example.js +0 -105
  106. package/dist/shared/schemas.d.ts +0 -15
  107. package/dist/shared/schemas.d.ts.map +0 -1
  108. package/dist/shared/schemas.js +0 -15
  109. package/dist/shared/types.d.ts +0 -225
  110. package/dist/shared/types.d.ts.map +0 -1
  111. package/dist/shared/types.js +0 -1
@@ -1,31 +0,0 @@
1
- import type { Result as ResultType } from "better-result";
2
- import type { McpServiceError } from "../services/mcp.js";
3
- import { NotFoundError, ValidationError } from "../shared/errors.js";
4
- import type { CatalogServerFailure, CatalogSummarySuccess, CatalogToolDetailsSuccess, CatalogToolsSuccess } from "../shared/types.js";
5
- import type { CommandContext } from "./context.js";
6
- import { type ResolveServerStateError } from "./server-context.js";
7
- export interface CatalogCommandOptions {
8
- cursor?: string | undefined;
9
- includeDebug?: boolean | undefined;
10
- limit?: number | undefined;
11
- serverId?: string | undefined;
12
- }
13
- export interface CatalogToolsCommandOptions {
14
- serverId: string;
15
- }
16
- export interface CatalogToolDetailsCommandOptions {
17
- serverId: string;
18
- toolName: string;
19
- }
20
- export interface CatalogSummaryPage {
21
- failures: CatalogServerFailure[];
22
- nextCursor: string | null;
23
- servers: CatalogSummarySuccess["servers"];
24
- }
25
- export type CatalogCommandError = McpServiceError | NotFoundError | ResolveServerStateError | ValidationError;
26
- export type CatalogToolsCommandError = McpServiceError | NotFoundError | ResolveServerStateError;
27
- export type CatalogToolDetailsCommandError = McpServiceError | NotFoundError | ResolveServerStateError;
28
- export declare const runCatalogCommand: (context: CommandContext, options: CatalogCommandOptions) => Promise<ResultType<CatalogSummaryPage, CatalogCommandError>>;
29
- export declare const runCatalogToolsCommand: (context: CommandContext, options: CatalogToolsCommandOptions) => Promise<ResultType<CatalogToolsSuccess, CatalogToolsCommandError>>;
30
- export declare const runCatalogToolDetailsCommand: (context: CommandContext, options: CatalogToolDetailsCommandOptions) => Promise<ResultType<CatalogToolDetailsSuccess, CatalogToolDetailsCommandError>>;
31
- //# sourceMappingURL=catalog.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/commands/catalog.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,KAAK,EACV,oBAAoB,EAEpB,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,qBAAqB,CAAC;AA0B7B,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,oBAAoB,EAAE,CAAC;IACjC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAC;CAC3C;AAED,MAAM,MAAM,mBAAmB,GAC3B,eAAe,GACf,aAAa,GACb,uBAAuB,GACvB,eAAe,CAAC;AAEpB,MAAM,MAAM,wBAAwB,GAAG,eAAe,GAAG,aAAa,GAAG,uBAAuB,CAAC;AAEjG,MAAM,MAAM,8BAA8B,GACtC,eAAe,GACf,aAAa,GACb,uBAAuB,CAAC;AA+D5B,eAAO,MAAM,iBAAiB,GAC5B,SAAS,cAAc,EACvB,SAAS,qBAAqB,KAC7B,OAAO,CAAC,UAAU,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,CAmF7D,CAAC;AAEF,eAAO,MAAM,sBAAsB,GACjC,SAAS,cAAc,EACvB,SAAS,0BAA0B,KAClC,OAAO,CAAC,UAAU,CAAC,mBAAmB,EAAE,wBAAwB,CAAC,CAoBnE,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,SAAS,cAAc,EACvB,SAAS,gCAAgC,KACxC,OAAO,CAAC,UAAU,CAAC,yBAAyB,EAAE,8BAA8B,CAAC,CAiC/E,CAAC"}
@@ -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"}
@@ -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"}
@@ -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"}
@@ -1,5 +0,0 @@
1
- import { Result } from "better-result";
2
- export const runStatusCommand = async (options, deps) => {
3
- const payload = await deps.infoService.collect(options.apiKeyOverride);
4
- return Result.ok(payload);
5
- };
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export { executeCli, runCli } from "./cli.js";
2
- export { createRuntimeConfig } from "./infra/env.js";
3
- export { OutputManager } from "./output/manager.js";
4
- //# sourceMappingURL=index.d.ts.map
@@ -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,3 +0,0 @@
1
- export { executeCli, runCli } from "./cli.js";
2
- export { createRuntimeConfig } from "./infra/env.js";
3
- export { OutputManager } from "./output/manager.js";
@@ -1,12 +0,0 @@
1
- import open from "open";
2
- import { Result } from "better-result";
3
- import { UnexpectedError } from "../shared/errors.js";
4
- export interface BrowserOpener {
5
- open(url: string): Promise<Result<void, UnexpectedError>>;
6
- }
7
- interface BrowserOpenerDeps {
8
- openFn?: typeof open;
9
- }
10
- export declare const createBrowserOpener: (deps?: BrowserOpenerDeps) => BrowserOpener;
11
- export {};
12
- //# sourceMappingURL=browser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/infra/browser.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC;CAC3D;AAED,UAAU,iBAAiB;IACzB,MAAM,CAAC,EAAE,OAAO,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,mBAAmB,GAAI,OAAM,iBAAsB,KAAG,aAkBlE,CAAC"}
@@ -1,20 +0,0 @@
1
- import open from "open";
2
- import { Result } from "better-result";
3
- import { UnexpectedError } from "../shared/errors.js";
4
- export const createBrowserOpener = (deps = {}) => {
5
- const openFn = deps.openFn ?? open;
6
- return {
7
- open: async (url) => {
8
- return Result.tryPromise({
9
- catch: (cause) => new UnexpectedError({
10
- cause,
11
- message: "Failed to open browser for authentication",
12
- }),
13
- try: async () => {
14
- const childProcess = await openFn(url);
15
- childProcess.unref();
16
- },
17
- });
18
- },
19
- };
20
- };
@@ -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;AAsCD,eAAO,MAAM,0BAA0B,GAAI,MAAM,oBAAoB,KAAG,gBAyDvE,CAAC"}
@@ -1,81 +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
- if (typeof parsed.value.accessToken === "string" && parsed.value.accessToken.length > 0) {
24
- const credentials = { apiKey: parsed.value.accessToken };
25
- if (typeof parsed.value.agentName === "string") {
26
- credentials.agentName = parsed.value.agentName;
27
- }
28
- return credentials;
29
- }
30
- return null;
31
- };
32
- export const createFileCredentialsStore = (deps) => {
33
- const existsSyncFn = deps.existsSyncFn ?? existsSync;
34
- const lstatSyncFn = deps.lstatSyncFn ?? lstatSync;
35
- const mkdirSyncFn = deps.mkdirSyncFn ?? mkdirSync;
36
- const readFileSyncFn = deps.readFileSyncFn ?? readFileSync;
37
- const unlinkSyncFn = deps.unlinkSyncFn ?? unlinkSync;
38
- const writeFileSyncFn = deps.writeFileSyncFn ?? writeFileSync;
39
- return {
40
- delete: () => {
41
- return Result.try({
42
- catch: (cause) => new UnexpectedError({ cause, message: "Failed to delete credentials" }),
43
- try: () => {
44
- deleteIfExists(deps.credentialsPath, existsSyncFn, unlinkSyncFn);
45
- },
46
- });
47
- },
48
- load: () => {
49
- return Result.try({
50
- catch: (cause) => new UnexpectedError({ cause, message: "Failed to load credentials" }),
51
- try: () => {
52
- if (!existsSyncFn(deps.credentialsPath)) {
53
- return null;
54
- }
55
- const raw = readFileSyncFn(deps.credentialsPath, "utf8");
56
- const parsed = JSON.parse(raw);
57
- const normalized = normalizeCredentials(parsed);
58
- if (normalized === null) {
59
- deleteIfExists(deps.credentialsPath, existsSyncFn, unlinkSyncFn);
60
- }
61
- return normalized;
62
- },
63
- });
64
- },
65
- save: (credentials) => {
66
- return Result.try({
67
- catch: (cause) => new UnexpectedError({ cause, message: "Failed to save credentials" }),
68
- try: () => {
69
- mkdirSyncFn(deps.configDir, { recursive: true });
70
- if (existsSyncFn(deps.credentialsPath) &&
71
- lstatSyncFn(deps.credentialsPath).isSymbolicLink()) {
72
- unlinkSyncFn(deps.credentialsPath);
73
- }
74
- writeFileSyncFn(deps.credentialsPath, JSON.stringify(credentials, null, 2), {
75
- mode: 0o600,
76
- });
77
- },
78
- });
79
- },
80
- };
81
- };