@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,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
@@ -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"}
package/dist/infra/env.js DELETED
@@ -1,100 +0,0 @@
1
- import { execSync } from "node:child_process";
2
- import { homedir } from "node:os";
3
- import { join } from "node:path";
4
- import { DEFAULT_OGMENT_BASE_URL, VERSION } from "../shared/constants.js";
5
- export const createRuntimeConfig = (env = process.env, homeDirectory = homedir()) => {
6
- const configDir = join(homeDirectory, ".config", "ogment");
7
- const hasBaseUrlOverride = typeof env["OGMENT_BASE_URL"] === "string";
8
- return {
9
- baseUrl: env["OGMENT_BASE_URL"] ?? DEFAULT_OGMENT_BASE_URL,
10
- baseUrlSource: hasBaseUrlOverride ? "env" : "default",
11
- configDir,
12
- credentialsPath: join(configDir, "credentials.json"),
13
- envApiKey: env["OGMENT_API_KEY"],
14
- version: VERSION,
15
- };
16
- };
17
- export const isInteractiveOutput = (stdout = process.stdout) => {
18
- return Boolean(stdout.isTTY);
19
- };
20
- const getAncestorProcesses = () => {
21
- try {
22
- let pid = process.ppid;
23
- const ancestors = [];
24
- for (let depth = 0; depth < 5; depth += 1) {
25
- const command = execSync(`ps -p ${pid} -o comm=`, { timeout: 500 }).toString().trim().split("/").pop() ??
26
- "";
27
- if (command.length === 0) {
28
- break;
29
- }
30
- ancestors.push(command);
31
- const parentPid = execSync(`ps -p ${pid} -o ppid=`, { timeout: 500 }).toString().trim();
32
- if (parentPid.length === 0 || parentPid === "0" || parentPid === "1") {
33
- break;
34
- }
35
- pid = Number(parentPid);
36
- }
37
- return ancestors;
38
- }
39
- catch {
40
- return [];
41
- }
42
- };
43
- export const detectExecutionEnvironment = (env = process.env, getAncestors = getAncestorProcesses) => {
44
- if (env["CURSOR_TRACE_ID"] !== undefined || env["CURSOR_SESSION_ID"] !== undefined) {
45
- return "Cursor";
46
- }
47
- if (env["VSCODE_PID"] !== undefined || env["VSCODE_IPC_HOOK"] !== undefined) {
48
- return "VS Code";
49
- }
50
- if (env["WINDSURF_SESSION_ID"] !== undefined) {
51
- return "Windsurf";
52
- }
53
- if (typeof env["JETBRAINS_IDE"] === "string" && env["JETBRAINS_IDE"].length > 0) {
54
- return env["JETBRAINS_IDE"];
55
- }
56
- if (env["CLAUDE_CODE_DISABLE_TELEMETRY"] !== undefined ||
57
- env["CLAUDE_CODE_MAX_TOKENS"] !== undefined ||
58
- env["CLAUDE_CODE_AUTO_APPROVE"] !== undefined) {
59
- return "Claude Code";
60
- }
61
- if (env["CI"] !== undefined) {
62
- return "CI";
63
- }
64
- const ancestors = getAncestors();
65
- const ancestorNames = ancestors.join(" ").toLowerCase();
66
- if (ancestorNames.includes("claude")) {
67
- return "Claude Code";
68
- }
69
- if (ancestorNames.includes("codex")) {
70
- return "Codex";
71
- }
72
- if (ancestorNames.includes("cursor")) {
73
- return "Cursor";
74
- }
75
- if (ancestorNames.includes("windsurf")) {
76
- return "Windsurf";
77
- }
78
- if (ancestorNames.includes("warp")) {
79
- return "Warp";
80
- }
81
- if (ancestors.some((value) => value.toLowerCase() === "code")) {
82
- return "VS Code";
83
- }
84
- if (env["TERM_PROGRAM"] === "iTerm.app") {
85
- return "iTerm";
86
- }
87
- if (env["TERM_PROGRAM"] === "Apple_Terminal") {
88
- return "Terminal.app";
89
- }
90
- if (env["TERM_PROGRAM"] === "WezTerm") {
91
- return "WezTerm";
92
- }
93
- if (env["TERM_PROGRAM"] === "Hyper") {
94
- return "Hyper";
95
- }
96
- if (typeof env["TERM_PROGRAM"] === "string" && env["TERM_PROGRAM"].length > 0) {
97
- return env["TERM_PROGRAM"];
98
- }
99
- return "unknown";
100
- };
@@ -1,16 +0,0 @@
1
- import { Result } from "better-result";
2
- import { RemoteRequestError } from "../shared/errors.js";
3
- export interface HttpClient {
4
- request(input: RequestInfo | URL, init?: RequestInit, options?: {
5
- operation?: string;
6
- timeoutMs?: number;
7
- }): Promise<Result<Response, RemoteRequestError>>;
8
- }
9
- interface HttpClientDeps {
10
- defaultTimeoutMs?: number;
11
- fetchFn?: typeof fetch;
12
- }
13
- export declare const createHttpClient: (deps?: HttpClientDeps) => HttpClient;
14
- export declare const readResponseText: (response: Response) => Promise<string>;
15
- export {};
16
- //# sourceMappingURL=http.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/infra/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAIzD,MAAM,WAAW,UAAU;IACzB,OAAO,CACL,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE;QACR,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GACA,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC;CAClD;AAED,UAAU,cAAc;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;CACxB;AAcD,eAAO,MAAM,gBAAgB,GAAI,OAAM,cAAmB,KAAG,UAoE5D,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAU,UAAU,QAAQ,KAAG,OAAO,CAAC,MAAM,CAWzE,CAAC"}
@@ -1,84 +0,0 @@
1
- import { Result } from "better-result";
2
- import { RemoteRequestError } from "../shared/errors.js";
3
- const DEFAULT_HTTP_TIMEOUT_MS = 10_000;
4
- const isAbortError = (cause) => {
5
- if (cause instanceof DOMException) {
6
- return cause.name === "AbortError" || cause.name === "TimeoutError";
7
- }
8
- if (cause instanceof Error) {
9
- return cause.name === "AbortError" || cause.name === "TimeoutError";
10
- }
11
- return false;
12
- };
13
- export const createHttpClient = (deps = {}) => {
14
- const defaultTimeoutMs = deps.defaultTimeoutMs ?? DEFAULT_HTTP_TIMEOUT_MS;
15
- const fetchFn = deps.fetchFn ?? fetch;
16
- return {
17
- request: async (input, init, options) => {
18
- const abortController = new AbortController();
19
- const timeoutMs = options?.timeoutMs ?? defaultTimeoutMs;
20
- const cleanupCallbacks = [];
21
- const abortWithReason = (reason) => {
22
- if (!abortController.signal.aborted) {
23
- abortController.abort(reason);
24
- }
25
- };
26
- const upstreamSignal = init?.signal ?? undefined;
27
- if (upstreamSignal !== undefined) {
28
- if (upstreamSignal.aborted) {
29
- abortWithReason(upstreamSignal.reason);
30
- }
31
- else {
32
- const onAbort = () => {
33
- abortWithReason(upstreamSignal.reason);
34
- };
35
- upstreamSignal.addEventListener("abort", onAbort);
36
- cleanupCallbacks.push(() => {
37
- upstreamSignal.removeEventListener("abort", onAbort);
38
- });
39
- }
40
- }
41
- const timeoutId = setTimeout(() => {
42
- abortWithReason(new DOMException("HTTP request timed out", "TimeoutError"));
43
- }, timeoutMs);
44
- cleanupCallbacks.push(() => {
45
- clearTimeout(timeoutId);
46
- });
47
- const requestPromise = Result.tryPromise({
48
- catch: (cause) => new RemoteRequestError({
49
- message: isAbortError(cause) ? "HTTP request timed out" : "HTTP request failed",
50
- ...(options?.operation === undefined ? {} : { operation: options.operation }),
51
- raw: cause instanceof Error
52
- ? {
53
- message: cause.message,
54
- name: cause.name,
55
- stack: cause.stack,
56
- }
57
- : cause,
58
- retryable: isAbortError(cause),
59
- source: "network",
60
- }),
61
- try: async () => fetchFn(input, {
62
- ...init,
63
- signal: abortController.signal,
64
- }),
65
- });
66
- return requestPromise.finally(() => {
67
- for (const cleanup of cleanupCallbacks) {
68
- cleanup();
69
- }
70
- });
71
- },
72
- };
73
- };
74
- export const readResponseText = async (response) => {
75
- return Result.tryPromise({
76
- catch: () => "",
77
- try: async () => response.text(),
78
- }).then((result) => {
79
- if (Result.isError(result)) {
80
- return "";
81
- }
82
- return result.value;
83
- });
84
- };
@@ -1,22 +0,0 @@
1
- import type { AppError } from "../shared/errors.js";
2
- import type { CliErrorEnvelope, CliNextAction, CliParseErrorPayload, CliPaginationMeta, CliSuccessEnvelope } from "../shared/types.js";
3
- export interface EnvelopeContext {
4
- command: string;
5
- diagnostics?: Record<string, unknown>;
6
- entity?: Record<string, unknown> | null;
7
- includeDebug?: boolean;
8
- nextActions?: CliNextAction[];
9
- pagination?: CliPaginationMeta;
10
- }
11
- interface EnvelopeBuilderDeps {
12
- createRequestId?: () => string;
13
- now?: () => Date;
14
- }
15
- export interface EnvelopeBuilder {
16
- error: (error: AppError, context: EnvelopeContext) => CliErrorEnvelope;
17
- parseError: (payload: CliParseErrorPayload, context: EnvelopeContext) => CliErrorEnvelope;
18
- success: <T>(data: T, context: EnvelopeContext) => CliSuccessEnvelope<T>;
19
- }
20
- export declare const createEnvelopeBuilder: (deps?: EnvelopeBuilderDeps) => EnvelopeBuilder;
21
- export {};
22
- //# sourceMappingURL=envelope.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/output/envelope.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACxC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,aAAa,EAAE,CAAC;IAC9B,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC;AAED,UAAU,mBAAmB;IAC3B,eAAe,CAAC,EAAE,MAAM,MAAM,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,KAAK,gBAAgB,CAAC;IACvE,UAAU,EAAE,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,eAAe,KAAK,gBAAgB,CAAC;IAC1F,OAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,KAAK,kBAAkB,CAAC,CAAC,CAAC,CAAC;CAC1E;AAED,eAAO,MAAM,qBAAqB,GAAI,OAAM,mBAAwB,KAAG,eAqEtE,CAAC"}
@@ -1,67 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { presentRuntimeErrorPayload } from "../shared/error-presentation.js";
3
- export const createEnvelopeBuilder = (deps = {}) => {
4
- const createRequestId = deps.createRequestId ?? randomUUID;
5
- const now = deps.now ?? (() => new Date());
6
- const toMeta = (context) => {
7
- const base = {
8
- command: context.command,
9
- };
10
- if (context.pagination !== undefined) {
11
- return {
12
- ...base,
13
- pagination: context.pagination,
14
- ...(context.includeDebug === true
15
- ? {
16
- entity: context.entity ?? null,
17
- requestId: createRequestId(),
18
- timestamp: now().toISOString(),
19
- }
20
- : {}),
21
- };
22
- }
23
- return {
24
- ...base,
25
- ...(context.includeDebug === true
26
- ? {
27
- entity: context.entity ?? null,
28
- requestId: createRequestId(),
29
- timestamp: now().toISOString(),
30
- }
31
- : {}),
32
- };
33
- };
34
- return {
35
- error: (error, context) => {
36
- const payload = presentRuntimeErrorPayload(error, {
37
- ...(context.diagnostics === undefined ? {} : { contextDiagnostics: context.diagnostics }),
38
- includeDebug: context.includeDebug === true,
39
- });
40
- return {
41
- data: null,
42
- error: payload,
43
- meta: toMeta(context),
44
- next_actions: context.nextActions ?? [],
45
- ok: false,
46
- };
47
- },
48
- parseError: (payload, context) => {
49
- return {
50
- data: null,
51
- error: payload,
52
- meta: toMeta(context),
53
- next_actions: context.nextActions ?? [],
54
- ok: false,
55
- };
56
- },
57
- success: (data, context) => {
58
- return {
59
- data,
60
- error: null,
61
- meta: toMeta(context),
62
- next_actions: context.nextActions ?? [],
63
- ok: true,
64
- };
65
- },
66
- };
67
- };
@@ -1,49 +0,0 @@
1
- import { type AppError } from "../shared/errors.js";
2
- import type { CliErrorEnvelope, CliNextAction, CliPaginationMeta, CliParseErrorPayload } from "../shared/types.js";
3
- export type OutputMode = "human" | "json" | "quiet";
4
- export interface OutputInitOptions {
5
- debug?: boolean | undefined;
6
- human: boolean | undefined;
7
- json?: boolean | undefined;
8
- nonInteractive: boolean | undefined;
9
- quiet: boolean | undefined;
10
- yes: boolean | undefined;
11
- }
12
- interface WritableLike {
13
- write(chunk: string): boolean;
14
- }
15
- interface OutputManagerDeps {
16
- createRequestId?: () => string;
17
- isTty?: boolean;
18
- noColor?: boolean;
19
- now?: () => Date;
20
- stderr?: WritableLike;
21
- stdout?: WritableLike;
22
- }
23
- interface EnvelopeOptions {
24
- command: string;
25
- diagnostics?: Record<string, unknown>;
26
- entity?: Record<string, unknown> | null;
27
- nextActions?: CliNextAction[];
28
- pagination?: CliPaginationMeta;
29
- }
30
- interface SuccessOptions extends EnvelopeOptions {
31
- humanMessage?: string;
32
- }
33
- export declare class OutputManager {
34
- #private;
35
- constructor(deps?: OutputManagerDeps);
36
- configure(options: OutputInitOptions): void;
37
- get mode(): OutputMode;
38
- get nonInteractive(): boolean;
39
- get debug(): boolean;
40
- error(error: AppError, options: EnvelopeOptions): CliErrorEnvelope;
41
- parseError(payload: CliParseErrorPayload, options: EnvelopeOptions): CliErrorEnvelope;
42
- info(message: string): void;
43
- json(value: unknown): void;
44
- success<T>(data: T, options: SuccessOptions): void;
45
- writeStdout(chunk: string): void;
46
- writeStderr(chunk: string): void;
47
- }
48
- export {};
49
- //# sourceMappingURL=manager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/output/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,oBAAoB,CAAC;AAG5B,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;AAEpD,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,cAAc,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,GAAG,EAAE,OAAO,GAAG,SAAS,CAAC;CAC1B;AAED,UAAU,YAAY;IACpB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CAC/B;AAED,UAAU,iBAAiB;IACzB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I;CAGxC"}
@@ -1,128 +0,0 @@
1
- import { appErrorMeta } from "../shared/errors.js";
2
- import { createEnvelopeBuilder } from "./envelope.js";
3
- const toJson = (value) => {
4
- return `${JSON.stringify(value, null, 2)}\n`;
5
- };
6
- const mergeNextActions = (recovery, contextActions) => {
7
- const merged = [
8
- ...(recovery === undefined || recovery === null ? [] : [recovery]),
9
- ...(contextActions ?? []),
10
- ];
11
- const deduped = [];
12
- const seen = new Set();
13
- for (const action of merged) {
14
- const key = `${action.id}::${action.command}`;
15
- if (seen.has(key)) {
16
- continue;
17
- }
18
- seen.add(key);
19
- deduped.push(action);
20
- }
21
- return deduped;
22
- };
23
- export class OutputManager {
24
- #envelopeBuilder;
25
- #isTty;
26
- #mode;
27
- #debug = false;
28
- #nonInteractive = false;
29
- #stderr;
30
- #stdout;
31
- constructor(deps = {}) {
32
- this.#isTty = deps.isTty ?? Boolean(process.stdout.isTTY);
33
- this.#stderr = deps.stderr ?? process.stderr;
34
- this.#stdout = deps.stdout ?? process.stdout;
35
- this.#mode = "json";
36
- this.#envelopeBuilder = createEnvelopeBuilder({
37
- ...(deps.createRequestId === undefined ? {} : { createRequestId: deps.createRequestId }),
38
- ...(deps.now === undefined ? {} : { now: deps.now }),
39
- });
40
- }
41
- configure(options) {
42
- if (options.quiet === true) {
43
- this.#mode = "quiet";
44
- }
45
- else if (options.human === true && options.json !== true) {
46
- this.#mode = "human";
47
- }
48
- else {
49
- this.#mode = "json";
50
- }
51
- this.#nonInteractive =
52
- options.nonInteractive === true || options.yes === true || this.#isTty === false;
53
- this.#debug = options.debug === true;
54
- }
55
- get mode() {
56
- return this.#mode;
57
- }
58
- get nonInteractive() {
59
- return this.#nonInteractive;
60
- }
61
- get debug() {
62
- return this.#debug;
63
- }
64
- error(error, options) {
65
- const envelope = this.#envelopeBuilder.error(error, {
66
- ...options,
67
- includeDebug: this.#debug,
68
- nextActions: mergeNextActions(appErrorMeta(error).recovery, options.nextActions),
69
- });
70
- if (this.#mode === "json") {
71
- this.#stdout.write(toJson(envelope));
72
- return envelope;
73
- }
74
- if (this.#mode === "quiet") {
75
- return envelope;
76
- }
77
- this.#stderr.write(`${envelope.error.code}: ${envelope.error.detail}\n`);
78
- return envelope;
79
- }
80
- parseError(payload, options) {
81
- const envelope = this.#envelopeBuilder.parseError(payload, {
82
- ...options,
83
- includeDebug: this.#debug,
84
- });
85
- if (this.#mode === "json") {
86
- this.#stdout.write(toJson(envelope));
87
- return envelope;
88
- }
89
- if (this.#mode === "quiet") {
90
- return envelope;
91
- }
92
- this.#stderr.write(`${envelope.error.code}: ${envelope.error.detail}\n`);
93
- return envelope;
94
- }
95
- info(message) {
96
- if (this.#mode !== "human") {
97
- return;
98
- }
99
- this.#stdout.write(`${message}\n`);
100
- }
101
- json(value) {
102
- this.#stdout.write(toJson(value));
103
- }
104
- success(data, options) {
105
- const envelope = this.#envelopeBuilder.success(data, {
106
- ...options,
107
- includeDebug: this.#debug,
108
- });
109
- if (this.#mode === "json") {
110
- this.#stdout.write(toJson(envelope));
111
- return;
112
- }
113
- if (this.#mode === "quiet") {
114
- return;
115
- }
116
- if (typeof options.humanMessage === "string" && options.humanMessage.length > 0) {
117
- this.#stdout.write(`${options.humanMessage}\n`);
118
- return;
119
- }
120
- this.#stdout.write(toJson(data));
121
- }
122
- writeStdout(chunk) {
123
- this.#stdout.write(chunk);
124
- }
125
- writeStderr(chunk) {
126
- this.#stderr.write(chunk);
127
- }
128
- }
@@ -1,16 +0,0 @@
1
- import type { Result as ResultType } from "better-result";
2
- import type { HttpClient } from "../infra/http.js";
3
- import { AuthError, RemoteRequestError, type ValidationError } from "../shared/errors.js";
4
- import type { AccountProfile, ServerWithOrg } from "../shared/types.js";
5
- export type FetchAccountError = AuthError | RemoteRequestError | ValidationError;
6
- export interface AccountService {
7
- fetchAccount(apiKey: string): Promise<ResultType<AccountProfile, FetchAccountError>>;
8
- listServers(apiKey: string): Promise<ResultType<ServerWithOrg[], FetchAccountError>>;
9
- }
10
- interface AccountServiceDeps {
11
- baseUrl: string;
12
- httpClient: HttpClient;
13
- }
14
- export declare const createAccountService: (deps: AccountServiceDeps) => AccountService;
15
- export {};
16
- //# sourceMappingURL=account.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/services/account.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG1F,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExE,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,kBAAkB,GAAG,eAAe,CAAC;AAEjF,MAAM,WAAW,cAAc;IAC7B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC,CAAC;IACrF,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,aAAa,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC;CACtF;AAED,UAAU,kBAAkB;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,UAAU,CAAC;CACxB;AAQD,eAAO,MAAM,oBAAoB,GAAI,MAAM,kBAAkB,KAAG,cAoF/D,CAAC"}
@@ -1,75 +0,0 @@
1
- import { Result } from "better-result";
2
- import { readResponseText } from "../infra/http.js";
3
- import { ERROR_CODE } from "../shared/error-codes.js";
4
- import { AuthError, RemoteRequestError } from "../shared/errors.js";
5
- import { parseWithSchema } from "../shared/guards.js";
6
- import { accountMeSchema } from "../shared/schemas.js";
7
- const authHeader = (apiKey) => {
8
- return {
9
- Authorization: `Bearer ${apiKey}`,
10
- };
11
- };
12
- export const createAccountService = (deps) => {
13
- const fetchAccountOnce = async (apiKey) => {
14
- const responseResult = await deps.httpClient.request(`${deps.baseUrl}/api/v1/mcp-auth/me`, {
15
- headers: authHeader(apiKey),
16
- });
17
- if (Result.isError(responseResult)) {
18
- return responseResult;
19
- }
20
- if (!responseResult.value.ok) {
21
- if (responseResult.value.status === 401) {
22
- return Result.err(new AuthError({
23
- code: ERROR_CODE.authInvalidCredentials,
24
- message: "Authentication failed. Run `ogment auth login` again.",
25
- recovery: { command: "ogment auth login" },
26
- }));
27
- }
28
- const body = await readResponseText(responseResult.value);
29
- return Result.err(new RemoteRequestError({
30
- body,
31
- httpStatus: responseResult.value.status,
32
- message: "Failed to fetch account details",
33
- operation: "account/fetch",
34
- raw: body,
35
- source: "http",
36
- }));
37
- }
38
- const jsonResult = await Result.tryPromise({
39
- catch: () => new RemoteRequestError({
40
- httpStatus: responseResult.value.status,
41
- message: "Failed to parse account response JSON",
42
- operation: "account/fetch",
43
- source: "http",
44
- }),
45
- try: async () => responseResult.value.json(),
46
- });
47
- if (Result.isError(jsonResult)) {
48
- return jsonResult;
49
- }
50
- const parsed = parseWithSchema(accountMeSchema, jsonResult.value, "account response");
51
- if (Result.isError(parsed)) {
52
- return parsed;
53
- }
54
- return Result.ok(parsed.value.data);
55
- };
56
- const fetchAccount = async (apiKey) => fetchAccountOnce(apiKey);
57
- return {
58
- fetchAccount,
59
- listServers: async (apiKey) => {
60
- const profileResult = await fetchAccount(apiKey);
61
- if (Result.isError(profileResult)) {
62
- return profileResult;
63
- }
64
- const servers = profileResult.value.orgs.flatMap((organization) => {
65
- return organization.servers.map((server) => {
66
- return {
67
- ...server,
68
- orgSlug: organization.orgSlug,
69
- };
70
- });
71
- });
72
- return Result.ok(servers);
73
- },
74
- };
75
- };
@@ -1,49 +0,0 @@
1
- import { createServer } from "node:http";
2
- import type { Result as ResultType } from "better-result";
3
- import type { BrowserOpener } from "../infra/browser.js";
4
- import type { CredentialsStore } from "../infra/credentials.js";
5
- import type { HttpClient } from "../infra/http.js";
6
- import { AuthError, RemoteRequestError, UnexpectedError, ValidationError } from "../shared/errors.js";
7
- import type { AuthStatusSuccess, LoginSuccess, LogoutSuccess } from "../shared/types.js";
8
- export interface LoginPendingInfo {
9
- userCode: string;
10
- verificationUri: string;
11
- }
12
- interface BaseLoginOptions {
13
- nonInteractive: boolean;
14
- }
15
- interface DeviceLoginOptions extends BaseLoginOptions {
16
- mode: "device";
17
- onPending?: (info: LoginPendingInfo) => void;
18
- }
19
- interface BrowserLoginOptions extends BaseLoginOptions {
20
- mode: "browser";
21
- }
22
- interface ApiKeyLoginOptions extends BaseLoginOptions {
23
- apiKey: string;
24
- mode: "apiKey";
25
- }
26
- export type LoginOptions = ApiKeyLoginOptions | BrowserLoginOptions | DeviceLoginOptions;
27
- export type LoginError = AuthError | RemoteRequestError | UnexpectedError | ValidationError;
28
- export type ResolveApiKeyError = AuthError | UnexpectedError;
29
- export interface AuthService {
30
- login(options: LoginOptions): Promise<ResultType<LoginSuccess, LoginError>>;
31
- logout(): Promise<ResultType<LogoutSuccess, UnexpectedError>>;
32
- resolveApiKey(overrideApiKey?: string): Promise<ResultType<string, ResolveApiKeyError>>;
33
- status(overrideApiKey?: string): Promise<ResultType<AuthStatusSuccess, UnexpectedError>>;
34
- }
35
- interface AuthServiceDeps {
36
- baseUrl: string;
37
- browserOpener: BrowserOpener;
38
- credentialsStore: CredentialsStore;
39
- createServerFn?: typeof createServer;
40
- detectEnvironment?: () => string;
41
- envApiKey: string | undefined;
42
- hostnameFn?: () => string;
43
- httpClient: HttpClient;
44
- now?: () => number;
45
- sleep?: (milliseconds: number) => Promise<void>;
46
- }
47
- export declare const createAuthService: (deps: AuthServiceDeps) => AuthService;
48
- export {};
49
- //# sourceMappingURL=auth.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/services/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC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