@usesotto/cli 0.1.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/bin.js +1619 -0
- package/dist/bin.js.map +1 -0
- package/dist/index.cjs +1625 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +183 -0
- package/dist/index.d.ts +183 -0
- package/dist/index.js +1600 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { FetchLike, SottoClient, CatalogResource } from '@sotto/purchase-client';
|
|
2
|
+
|
|
3
|
+
type CliConfig = Readonly<{
|
|
4
|
+
apiOrigin?: string;
|
|
5
|
+
token?: string;
|
|
6
|
+
walletUrl?: string;
|
|
7
|
+
}>;
|
|
8
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
9
|
+
declare function configPath(env: Env): string;
|
|
10
|
+
/** Malformed config fails closed: the CLI treats it as absent and says so. */
|
|
11
|
+
declare function readConfig(env: Env): CliConfig;
|
|
12
|
+
/**
|
|
13
|
+
* Persists the config with owner-only permissions: 0700 directory, 0600
|
|
14
|
+
* file — the session token never becomes group- or world-readable, and an
|
|
15
|
+
* existing looser mode is tightened on every write.
|
|
16
|
+
*/
|
|
17
|
+
declare function writeConfig(env: Env, config: CliConfig): string;
|
|
18
|
+
declare function deleteConfig(env: Env): void;
|
|
19
|
+
type ResolvedSettings = Readonly<{
|
|
20
|
+
apiOrigin: string | undefined;
|
|
21
|
+
token: string | undefined;
|
|
22
|
+
walletUrl: string | undefined;
|
|
23
|
+
tokenSource: "env" | "config" | "absent";
|
|
24
|
+
}>;
|
|
25
|
+
/** Environment overrides config; explicit flags override both. */
|
|
26
|
+
declare function resolveSettings(env: Env, flags?: Readonly<{
|
|
27
|
+
apiOrigin?: string;
|
|
28
|
+
}>): ResolvedSettings;
|
|
29
|
+
declare function isValidToken(candidate: string): boolean;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* One exit code per distinct terminal fact, so scripts can branch on the
|
|
33
|
+
* paired settlement/delivery outcome without parsing copy. Ambiguous
|
|
34
|
+
* outcomes (8) must never be auto-retried — the CLI prints reconcile
|
|
35
|
+
* guidance instead of spending twice.
|
|
36
|
+
*/
|
|
37
|
+
declare const EXIT: Readonly<{
|
|
38
|
+
/** Read succeeded, or the purchase settled AND delivered. */
|
|
39
|
+
readonly ok: 0;
|
|
40
|
+
/** Transport failure, API failure, or an unexpected error. */
|
|
41
|
+
readonly failure: 1;
|
|
42
|
+
/** The command line itself was invalid. */
|
|
43
|
+
readonly usage: 2;
|
|
44
|
+
/** No usable owner session (token absent, expired, or revoked). */
|
|
45
|
+
readonly auth: 3;
|
|
46
|
+
/** The human wallet rejected this exact prepared call. */
|
|
47
|
+
readonly walletRejected: 4;
|
|
48
|
+
/** The wallet cannot sign this prepared transaction shape. */
|
|
49
|
+
readonly walletUnsupported: 5;
|
|
50
|
+
/** Canton rejected the settlement; no value moved. */
|
|
51
|
+
readonly settlementRejected: 6;
|
|
52
|
+
/** The execute-before deadline passed without a terminal journal event. */
|
|
53
|
+
readonly expired: 7;
|
|
54
|
+
/** Settled but not delivered, or otherwise ambiguous — reconcile, never retry. */
|
|
55
|
+
readonly ambiguous: 8;
|
|
56
|
+
}>;
|
|
57
|
+
type ExitCode = (typeof EXIT)[keyof typeof EXIT];
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Terminal output helpers bound to DESIGN.md §6: truncation keeps hint +
|
|
61
|
+
* tail for party IDs and first-8 + last-4 for update IDs, amounts always
|
|
62
|
+
* carry the asset, and `--json` returns the full untruncated values.
|
|
63
|
+
* NO_COLOR or a non-TTY stream turns every escape sequence off.
|
|
64
|
+
*/
|
|
65
|
+
type Io = Readonly<{
|
|
66
|
+
stdout: (line: string) => void;
|
|
67
|
+
stderr: (line: string) => void;
|
|
68
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
69
|
+
isTTY: boolean;
|
|
70
|
+
}>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Minimal MCP stdio server: newline-delimited JSON-RPC 2.0. Implemented by
|
|
74
|
+
* hand so the published CLI carries zero runtime dependencies; stdout
|
|
75
|
+
* carries JSON-RPC frames only, and every log goes to stderr.
|
|
76
|
+
*/
|
|
77
|
+
declare const MCP_PROTOCOL_VERSION = "2025-06-18";
|
|
78
|
+
type JsonRpcId = string | number | null;
|
|
79
|
+
type JsonRpcMessage = Readonly<{
|
|
80
|
+
jsonrpc: "2.0";
|
|
81
|
+
id?: JsonRpcId;
|
|
82
|
+
method?: string;
|
|
83
|
+
params?: Readonly<Record<string, unknown>>;
|
|
84
|
+
result?: unknown;
|
|
85
|
+
error?: unknown;
|
|
86
|
+
}>;
|
|
87
|
+
type MethodHandler = (params: Readonly<Record<string, unknown>>) => Promise<unknown> | unknown;
|
|
88
|
+
type McpServerDefinition = Readonly<{
|
|
89
|
+
serverInfo: Readonly<{
|
|
90
|
+
name: string;
|
|
91
|
+
version: string;
|
|
92
|
+
}>;
|
|
93
|
+
methods: Readonly<Record<string, MethodHandler>>;
|
|
94
|
+
}>;
|
|
95
|
+
declare class JsonRpcError extends Error {
|
|
96
|
+
readonly code: number;
|
|
97
|
+
constructor(code: number, message: string);
|
|
98
|
+
}
|
|
99
|
+
declare function parseMessage(line: string): JsonRpcMessage | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Handles one incoming message. Returns the serialized response frame, or
|
|
102
|
+
* undefined for notifications (which never get a response).
|
|
103
|
+
*/
|
|
104
|
+
declare function handleMessage(definition: McpServerDefinition, message: JsonRpcMessage): Promise<string | undefined>;
|
|
105
|
+
type StreamLike = Readonly<{
|
|
106
|
+
input: AsyncIterable<string | Uint8Array>;
|
|
107
|
+
write: (frame: string) => void;
|
|
108
|
+
logError: (line: string) => void;
|
|
109
|
+
}>;
|
|
110
|
+
/** Reads newline-delimited frames until the input ends. */
|
|
111
|
+
declare function serveJsonRpc(definition: McpServerDefinition, streams: StreamLike): Promise<void>;
|
|
112
|
+
|
|
113
|
+
type RunOptions = Readonly<{
|
|
114
|
+
io: Io;
|
|
115
|
+
env: Env;
|
|
116
|
+
fetchImpl?: FetchLike;
|
|
117
|
+
mcpStreams?: StreamLike;
|
|
118
|
+
}>;
|
|
119
|
+
/** Parses argv, dispatches one command, and maps every error to an exit code. */
|
|
120
|
+
declare function run(argv: readonly string[], options: RunOptions): Promise<ExitCode>;
|
|
121
|
+
|
|
122
|
+
/** Kept in lockstep with package.json; scripts/verify-package.mjs asserts it. */
|
|
123
|
+
declare const CLI_VERSION = "0.1.0";
|
|
124
|
+
|
|
125
|
+
declare class CliUsageError extends Error {
|
|
126
|
+
}
|
|
127
|
+
declare class CliAuthError extends Error {
|
|
128
|
+
}
|
|
129
|
+
type ClientContext = Readonly<{
|
|
130
|
+
client: SottoClient;
|
|
131
|
+
settings: ResolvedSettings;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Builds the shared purchasing-core client from resolved settings. Every
|
|
135
|
+
* CLI command and MCP tool goes through this one construction — there is
|
|
136
|
+
* no second HTTP path and no signing capability anywhere behind it.
|
|
137
|
+
*/
|
|
138
|
+
declare function buildClient(env: Env, flags?: Readonly<{
|
|
139
|
+
apiOrigin?: string;
|
|
140
|
+
}>, fetchImpl?: FetchLike): ClientContext;
|
|
141
|
+
type SearchFilters = Readonly<{
|
|
142
|
+
query?: string;
|
|
143
|
+
method?: string;
|
|
144
|
+
maxPriceAtomic?: bigint;
|
|
145
|
+
}>;
|
|
146
|
+
/** Case-insensitive text match over the verified catalog's own fields. */
|
|
147
|
+
declare function filterResources(resources: readonly CatalogResource[], filters: SearchFilters): readonly CatalogResource[];
|
|
148
|
+
/**
|
|
149
|
+
* Resolves a listing ID or a canonical resource URL to its verified
|
|
150
|
+
* catalog listing — the `sotto try <resource-url>` path. A URL matches
|
|
151
|
+
* when origin and route equal a published resource exactly.
|
|
152
|
+
*/
|
|
153
|
+
declare function resolveResource(client: SottoClient, reference: string, signal?: AbortSignal): Promise<CatalogResource>;
|
|
154
|
+
declare function parseMaxPrice(raw: string | undefined): bigint | undefined;
|
|
155
|
+
|
|
156
|
+
type ToolDefinition = Readonly<{
|
|
157
|
+
name: string;
|
|
158
|
+
title: string;
|
|
159
|
+
description: string;
|
|
160
|
+
inputSchema: Readonly<Record<string, unknown>>;
|
|
161
|
+
annotations: Readonly<Record<string, unknown>>;
|
|
162
|
+
}>;
|
|
163
|
+
type ToolResult = Readonly<{
|
|
164
|
+
content: readonly Readonly<{
|
|
165
|
+
type: "text";
|
|
166
|
+
text: string;
|
|
167
|
+
}>[];
|
|
168
|
+
isError?: boolean;
|
|
169
|
+
}>;
|
|
170
|
+
declare const TOOL_DEFINITIONS: readonly ToolDefinition[];
|
|
171
|
+
/** Executes one tool call against the shared purchasing core. */
|
|
172
|
+
declare function callTool(client: SottoClient, name: string, args: Readonly<Record<string, unknown>>): Promise<ToolResult>;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* `sotto mcp serve` — the buyer MCP server over stdio. Auth is the same
|
|
176
|
+
* stored session token (or SOTTO_SESSION_TOKEN) the CLI uses; there is no
|
|
177
|
+
* key material anywhere in this process and no generic signing tool in
|
|
178
|
+
* the tool list. Stdout stays pure JSON-RPC; diagnostics go to stderr.
|
|
179
|
+
*/
|
|
180
|
+
declare function buildMcpDefinition(env: Env, fetchImpl?: FetchLike): McpServerDefinition;
|
|
181
|
+
declare function serveMcp(env: Env, streams: StreamLike): Promise<void>;
|
|
182
|
+
|
|
183
|
+
export { CLI_VERSION, CliAuthError, type CliConfig, CliUsageError, type ClientContext, EXIT, type Env, type ExitCode, JsonRpcError, type JsonRpcMessage, MCP_PROTOCOL_VERSION, type McpServerDefinition, type ResolvedSettings, type RunOptions, type SearchFilters, type StreamLike, TOOL_DEFINITIONS, type ToolDefinition, type ToolResult, buildClient, buildMcpDefinition, callTool, configPath, deleteConfig, filterResources, handleMessage, isValidToken, parseMaxPrice, parseMessage, readConfig, resolveResource, resolveSettings, run, serveJsonRpc, serveMcp, writeConfig };
|