@vectorlingo/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/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/cli-bin.d.ts +3 -0
- package/dist/cli-bin.d.ts.map +1 -0
- package/dist/cli-bin.js +4 -0
- package/dist/cli-bin.js.map +1 -0
- package/dist/cli.d.ts +16 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +405 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +28 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +103 -0
- package/dist/client.js.map +1 -0
- package/dist/contracts.d.ts +127 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +105 -0
- package/dist/contracts.js.map +1 -0
- package/dist/credential-store.d.ts +112 -0
- package/dist/credential-store.d.ts.map +1 -0
- package/dist/credential-store.js +528 -0
- package/dist/credential-store.js.map +1 -0
- package/dist/http.d.ts +7 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +92 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +27 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +180 -0
- package/dist/mcp.js.map +1 -0
- package/dist/oauth.d.ts +43 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +369 -0
- package/dist/oauth.js.map +1 -0
- package/dist/safe-files.d.ts +26 -0
- package/dist/safe-files.d.ts.map +1 -0
- package/dist/safe-files.js +203 -0
- package/dist/safe-files.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 VectorLingo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @vectorlingo/cli
|
|
2
|
+
|
|
3
|
+
The `vectorlingo` command line tool, plus a Node.js SDK and MCP adapter, for VectorLingo agent access. You need a VectorLingo account with agent access enabled.
|
|
4
|
+
|
|
5
|
+
Node.js 20 or later is required.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install -g @vectorlingo/cli
|
|
9
|
+
vectorlingo login
|
|
10
|
+
vectorlingo --help
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`vectorlingo login` opens your browser to sign in to `https://app.vectorlingo.com`. For another deployment, pass `--base-url URL`. On a headless or SSH machine, pass `--no-browser` and open the printed URL yourself.
|
|
14
|
+
|
|
15
|
+
Without a global install: `npx @vectorlingo/cli --help`.
|
|
16
|
+
|
|
17
|
+
## SDK
|
|
18
|
+
|
|
19
|
+
The root export contains the HTTP client, OAuth PKCE client, credential stores and safe file transfer helpers. `@vectorlingo/cli/contracts` is a dependency-light contracts entry point. `@vectorlingo/cli/mcp` provides the official MCP SDK v2 fetch handler.
|
|
20
|
+
|
|
21
|
+
## Licence
|
|
22
|
+
|
|
23
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-bin.d.ts","sourceRoot":"","sources":["../src/cli-bin.ts"],"names":[],"mappings":""}
|
package/dist/cli-bin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-bin.js","sourceRoot":"","sources":["../src/cli-bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,CAAC,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export interface CliIo {
|
|
3
|
+
stdout(value: string): void;
|
|
4
|
+
stderr(value: string): void;
|
|
5
|
+
}
|
|
6
|
+
interface ParsedArguments {
|
|
7
|
+
command: string[];
|
|
8
|
+
options: Map<string, string | true>;
|
|
9
|
+
json: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function runCli(argv: string[], io?: CliIo): Promise<number>;
|
|
12
|
+
export declare const valueOptions: ReadonlySet<string>;
|
|
13
|
+
export declare const booleanOptions: ReadonlySet<string>;
|
|
14
|
+
export declare function parseArguments(argv: string[]): ParsedArguments;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAUA,MAAM,WAAW,KAAK;IACpB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5B;AAED,UAAU,eAAe;IACvB,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;IACnC,IAAI,EAAE,OAAO,CAAA;CACd;AA4BD,wBAAsB,MAAM,CAC1B,IAAI,EAAE,MAAM,EAAE,EACd,EAAE,GAAE,KAGH,GACA,OAAO,CAAC,MAAM,CAAC,CAkBjB;AA0KD,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,MAAM,CAI3C,CAAA;AACF,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,MAAM,CAAoD,CAAA;AAEnG,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,eAAe,CAwB9D"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { AgentAccessClient } from './client.js';
|
|
5
|
+
import { AgentError, isUuid, isWriteOperation } from './contracts.js';
|
|
6
|
+
import { createCredentialStore } from './credential-store.js';
|
|
7
|
+
import { createStoredTokenProvider, OAuthClient, openSystemBrowser } from './oauth.js';
|
|
8
|
+
import { downloadArtifact, uploadFile } from './safe-files.js';
|
|
9
|
+
import { validateServiceUrl } from './http.js';
|
|
10
|
+
const DEFAULT_BASE_URL = 'https://app.vectorlingo.com';
|
|
11
|
+
const HELP = `VectorLingo agent access
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
vectorlingo login [--base-url URL (default ${DEFAULT_BASE_URL})] [--issuer URL] [--resource URL] [--client-id ID] [--scope SCOPES]
|
|
15
|
+
[--no-browser]
|
|
16
|
+
vectorlingo logout [--local]
|
|
17
|
+
vectorlingo tenant list
|
|
18
|
+
vectorlingo tenant select TENANT_ID
|
|
19
|
+
vectorlingo discover
|
|
20
|
+
vectorlingo help [FAMILY]
|
|
21
|
+
vectorlingo execute OPERATION --input JSON|@FILE [--tenant TENANT_ID] [--request-id UUID]
|
|
22
|
+
[--source-namespace NAMESPACE --source-id ID]
|
|
23
|
+
vectorlingo operation get OPERATION_ID
|
|
24
|
+
vectorlingo upload FILE --mime-type TYPE --attachment-kind KIND [--tenant TENANT_ID]
|
|
25
|
+
[--init-request-id UUID] [--complete-request-id UUID]
|
|
26
|
+
vectorlingo download ARTIFACT_ID --destination FILE [--tenant TENANT_ID]
|
|
27
|
+
|
|
28
|
+
Global options:
|
|
29
|
+
--help
|
|
30
|
+
--json
|
|
31
|
+
--credential-store auto|keychain|file
|
|
32
|
+
--credential-file PATH (explicitly selects file storage)
|
|
33
|
+
`;
|
|
34
|
+
export async function runCli(argv, io = {
|
|
35
|
+
stdout: (value) => process.stdout.write(`${value}\n`),
|
|
36
|
+
stderr: (value) => process.stderr.write(`${value}\n`),
|
|
37
|
+
}) {
|
|
38
|
+
let parsed;
|
|
39
|
+
try {
|
|
40
|
+
parsed = parseArguments(argv);
|
|
41
|
+
if (parsed.command.length === 0 || flag(parsed, 'help') || parsed.command[0] === '-h') {
|
|
42
|
+
io.stdout(HELP.trimEnd());
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
const store = credentialStore(parsed);
|
|
46
|
+
const output = await dispatch(parsed, store, io);
|
|
47
|
+
if (output !== undefined)
|
|
48
|
+
io.stdout(formatOutput(output, parsed.json));
|
|
49
|
+
return resultExitCode(output);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const safe = safeError(error);
|
|
53
|
+
if (parsed?.json)
|
|
54
|
+
io.stderr(stableJson({ error: safe }));
|
|
55
|
+
else
|
|
56
|
+
io.stderr(humanError(safe));
|
|
57
|
+
return errorExitCode(error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function dispatch(parsed, store, io) {
|
|
61
|
+
const [command, subcommand, ...positionals] = parsed.command;
|
|
62
|
+
if (command === 'login')
|
|
63
|
+
return login(parsed, store, io);
|
|
64
|
+
if (command === 'logout')
|
|
65
|
+
return logout(parsed, store);
|
|
66
|
+
if (command === 'tenant' && subcommand === 'select') {
|
|
67
|
+
const tenantId = requiredValue(positionals[0], 'tenant ID');
|
|
68
|
+
assertUuid(tenantId, 'tenant ID');
|
|
69
|
+
const updated = await store.update(async (profile) => {
|
|
70
|
+
if (!profile)
|
|
71
|
+
throw new AgentError('authentication_required', 'Run vectorlingo login first');
|
|
72
|
+
return { ...profile, selectedTenantId: tenantId.toLowerCase() };
|
|
73
|
+
});
|
|
74
|
+
return { selected_tenant_id: updated?.selectedTenantId };
|
|
75
|
+
}
|
|
76
|
+
const { client, profile } = await authenticatedClient(store);
|
|
77
|
+
if (command === 'tenant' && subcommand === 'list')
|
|
78
|
+
return client.listTenants();
|
|
79
|
+
if (command === 'discover')
|
|
80
|
+
return client.getCapabilities();
|
|
81
|
+
if (command === 'help')
|
|
82
|
+
return operationHelp(await client.getCapabilities(), subcommand);
|
|
83
|
+
if (command === 'operation' && subcommand === 'get') {
|
|
84
|
+
return client.getOperation(requiredValue(positionals[0], 'operation ID'), tenant(parsed, profile.selectedTenantId));
|
|
85
|
+
}
|
|
86
|
+
if (command === 'execute') {
|
|
87
|
+
const operation = requiredValue(subcommand, 'operation');
|
|
88
|
+
const tenantId = tenant(parsed, profile.selectedTenantId);
|
|
89
|
+
const manifest = await client.getCapabilities();
|
|
90
|
+
const descriptor = manifest.operations.find((candidate) => candidate.name === operation);
|
|
91
|
+
if (!descriptor)
|
|
92
|
+
throw new AgentError('unknown_operation', `Unknown operation: ${operation}`);
|
|
93
|
+
const requestId = isWriteOperation(descriptor) ? option(parsed, 'request-id') ?? randomUUID() : option(parsed, 'request-id');
|
|
94
|
+
const envelope = {
|
|
95
|
+
tenant_id: tenantId,
|
|
96
|
+
operation,
|
|
97
|
+
input: await jsonInput(requiredOption(parsed, 'input')),
|
|
98
|
+
...(requestId ? { request_id: requestId } : {}),
|
|
99
|
+
...sourceReference(parsed),
|
|
100
|
+
};
|
|
101
|
+
return withRetryIds(client.execute(envelope), requestId ? { request_id: requestId } : {});
|
|
102
|
+
}
|
|
103
|
+
if (command === 'upload') {
|
|
104
|
+
const initRequestId = option(parsed, 'init-request-id') ?? randomUUID();
|
|
105
|
+
const completeRequestId = option(parsed, 'complete-request-id') ?? randomUUID();
|
|
106
|
+
return withRetryIds(uploadFile(client, {
|
|
107
|
+
tenantId: tenant(parsed, profile.selectedTenantId),
|
|
108
|
+
path: requiredValue(subcommand, 'file'),
|
|
109
|
+
mimeType: requiredOption(parsed, 'mime-type'),
|
|
110
|
+
attachmentKind: requiredOption(parsed, 'attachment-kind'),
|
|
111
|
+
initRequestId,
|
|
112
|
+
completeRequestId,
|
|
113
|
+
}), { init_request_id: initRequestId, complete_request_id: completeRequestId });
|
|
114
|
+
}
|
|
115
|
+
if (command === 'download') {
|
|
116
|
+
const downloaded = await downloadArtifact(client, {
|
|
117
|
+
tenantId: tenant(parsed, profile.selectedTenantId),
|
|
118
|
+
artifactId: requiredValue(subcommand, 'artifact ID'),
|
|
119
|
+
destination: requiredOption(parsed, 'destination'),
|
|
120
|
+
});
|
|
121
|
+
return { path: downloaded.path, descriptor: withoutCapabilityUrls(downloaded.descriptor) };
|
|
122
|
+
}
|
|
123
|
+
throw new AgentError('usage_error', 'Unknown command. Run vectorlingo --help.');
|
|
124
|
+
}
|
|
125
|
+
async function login(parsed, store, io) {
|
|
126
|
+
const base = validateServiceUrl(option(parsed, 'base-url') ?? DEFAULT_BASE_URL, 'base URL');
|
|
127
|
+
const baseUrl = base.href;
|
|
128
|
+
const issuer = option(parsed, 'issuer') ?? new URL('/api/agent-auth', base).href;
|
|
129
|
+
const resource = option(parsed, 'resource') ?? new URL('/api/agent/v1', base).href;
|
|
130
|
+
const scopes = (option(parsed, 'scope') ?? 'openid profile offline_access agent:access')
|
|
131
|
+
.split(/[ ,]+/)
|
|
132
|
+
.filter(Boolean);
|
|
133
|
+
// Reuse the stored client for the same issuer + resource: a pilot grant is per client ID,
|
|
134
|
+
// so registering again on every login would orphan it. --client-id always wins.
|
|
135
|
+
const explicitClientId = option(parsed, 'client-id');
|
|
136
|
+
const deployment = {
|
|
137
|
+
issuer: validateServiceUrl(issuer, 'OAuth issuer').href,
|
|
138
|
+
resource: validateServiceUrl(resource, 'OAuth resource').href,
|
|
139
|
+
};
|
|
140
|
+
const stored = explicitClientId ? undefined : await store.load(deployment);
|
|
141
|
+
const storedClientId = stored && stored.issuer === deployment.issuer && stored.resource === deployment.resource
|
|
142
|
+
? stored.clientId
|
|
143
|
+
: undefined;
|
|
144
|
+
const clientId = explicitClientId ?? storedClientId;
|
|
145
|
+
// The URL always goes to stderr (never stdout, which carries the result). It holds no secret:
|
|
146
|
+
// the PKCE verifier stays in this process. A launch failure is reported, not fatal: the user
|
|
147
|
+
// can still open the URL by hand while the loopback callback waits.
|
|
148
|
+
const openBrowser = async (url) => {
|
|
149
|
+
io.stderr(`Open this URL in a browser to sign in (over SSH, forward the port in its redirect_uri):\n${url.href}`);
|
|
150
|
+
if (flag(parsed, 'no-browser'))
|
|
151
|
+
return;
|
|
152
|
+
try {
|
|
153
|
+
await openSystemBrowser(url);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
io.stderr(`Could not open a browser (${error instanceof Error ? error.message : String(error)}). Open the URL above instead.`);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const oauth = new OAuthClient({ issuer, resource, scopes, openBrowser, ...(clientId ? { clientId } : {}) });
|
|
160
|
+
let profile;
|
|
161
|
+
try {
|
|
162
|
+
profile = await oauth.login(baseUrl);
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
if (!storedClientId || !(error instanceof AgentError))
|
|
166
|
+
throw error;
|
|
167
|
+
// The server shows an unknown or disabled client on its own error page, not our callback,
|
|
168
|
+
// so this usually surfaces as a timeout. Never re-register silently.
|
|
169
|
+
throw new AgentError(error.code, `${error.message}. Login reused the stored OAuth client ${storedClientId}; if the server rejected it ` +
|
|
170
|
+
'(for example invalid_client), pass --client-id ID or run vectorlingo logout --local and log in again.', { cause: error, details: { client_id: storedClientId }, ...(error.httpStatus ? { httpStatus: error.httpStatus } : {}) });
|
|
171
|
+
}
|
|
172
|
+
await store.save(profile);
|
|
173
|
+
return {
|
|
174
|
+
authenticated: true,
|
|
175
|
+
base_url: profile.baseUrl,
|
|
176
|
+
issuer: profile.issuer,
|
|
177
|
+
client_id: profile.clientId,
|
|
178
|
+
client_id_source: explicitClientId ? 'option' : storedClientId ? 'stored' : 'registered',
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
async function logout(parsed, store) {
|
|
182
|
+
const profile = await store.load();
|
|
183
|
+
if (!profile)
|
|
184
|
+
return { authenticated: false };
|
|
185
|
+
if (!flag(parsed, 'local')) {
|
|
186
|
+
const oauth = new OAuthClient({
|
|
187
|
+
issuer: profile.issuer,
|
|
188
|
+
resource: profile.resource,
|
|
189
|
+
clientId: profile.clientId,
|
|
190
|
+
scopes: profile.tokens.scope?.split(' ').filter(Boolean) ?? ['openid'],
|
|
191
|
+
});
|
|
192
|
+
await oauth.revoke(profile);
|
|
193
|
+
}
|
|
194
|
+
await store.update(async () => undefined);
|
|
195
|
+
return { authenticated: false };
|
|
196
|
+
}
|
|
197
|
+
async function authenticatedClient(store) {
|
|
198
|
+
const profile = await store.load();
|
|
199
|
+
if (!profile)
|
|
200
|
+
throw new AgentError('authentication_required', 'Run vectorlingo login first');
|
|
201
|
+
const oauth = new OAuthClient({
|
|
202
|
+
issuer: profile.issuer,
|
|
203
|
+
resource: profile.resource,
|
|
204
|
+
clientId: profile.clientId,
|
|
205
|
+
scopes: profile.tokens.scope?.split(' ').filter(Boolean) ?? ['openid'],
|
|
206
|
+
});
|
|
207
|
+
return {
|
|
208
|
+
profile,
|
|
209
|
+
client: new AgentAccessClient({
|
|
210
|
+
baseUrl: profile.baseUrl,
|
|
211
|
+
tokenProvider: createStoredTokenProvider(store, oauth),
|
|
212
|
+
}),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function credentialStore(parsed) {
|
|
216
|
+
const filePath = option(parsed, 'credential-file');
|
|
217
|
+
const rawMode = option(parsed, 'credential-store');
|
|
218
|
+
if (rawMode && !['auto', 'keychain', 'file'].includes(rawMode)) {
|
|
219
|
+
throw new AgentError('usage_error', '--credential-store must be auto, keychain or file');
|
|
220
|
+
}
|
|
221
|
+
if (filePath && rawMode && rawMode !== 'file') {
|
|
222
|
+
throw new AgentError('usage_error', '--credential-file requires --credential-store file');
|
|
223
|
+
}
|
|
224
|
+
return createCredentialStore({
|
|
225
|
+
mode: (filePath ? 'file' : rawMode ?? 'auto'),
|
|
226
|
+
...(filePath ? { filePath } : {}),
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
export const valueOptions = new Set([
|
|
230
|
+
'credential-store', 'credential-file', 'base-url', 'issuer', 'resource', 'client-id', 'scope',
|
|
231
|
+
'tenant', 'request-id', 'source-namespace', 'source-id', 'input', 'mime-type',
|
|
232
|
+
'attachment-kind', 'init-request-id', 'complete-request-id', 'destination',
|
|
233
|
+
]);
|
|
234
|
+
export const booleanOptions = new Set(['json', 'local', 'help', 'no-browser']);
|
|
235
|
+
export function parseArguments(argv) {
|
|
236
|
+
const options = new Map();
|
|
237
|
+
const command = [];
|
|
238
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
239
|
+
const token = argv[index];
|
|
240
|
+
if (!token)
|
|
241
|
+
continue;
|
|
242
|
+
if (!token.startsWith('--')) {
|
|
243
|
+
command.push(token);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const equals = token.indexOf('=');
|
|
247
|
+
const key = token.slice(2, equals === -1 ? undefined : equals);
|
|
248
|
+
if (!key || options.has(key))
|
|
249
|
+
throw new AgentError('usage_error', `Invalid or duplicate option: ${token}`);
|
|
250
|
+
if (!valueOptions.has(key)) {
|
|
251
|
+
if (!booleanOptions.has(key))
|
|
252
|
+
throw new AgentError('usage_error', `Unknown option: --${key}`);
|
|
253
|
+
if (equals !== -1)
|
|
254
|
+
throw new AgentError('usage_error', `Option --${key} does not take a value`);
|
|
255
|
+
options.set(key, true);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const value = equals === -1 ? argv[++index] : token.slice(equals + 1);
|
|
259
|
+
if (!value || value.startsWith('--'))
|
|
260
|
+
throw new AgentError('usage_error', `Option --${key} requires a value`);
|
|
261
|
+
options.set(key, value);
|
|
262
|
+
}
|
|
263
|
+
return { command, options, json: options.get('json') === true };
|
|
264
|
+
}
|
|
265
|
+
function option(parsed, key) {
|
|
266
|
+
const value = parsed.options.get(key);
|
|
267
|
+
return typeof value === 'string' ? value : undefined;
|
|
268
|
+
}
|
|
269
|
+
function flag(parsed, key) { return parsed.options.get(key) === true; }
|
|
270
|
+
function requiredOption(parsed, key) {
|
|
271
|
+
const value = option(parsed, key);
|
|
272
|
+
if (!value)
|
|
273
|
+
throw new AgentError('usage_error', `Missing required option --${key}`);
|
|
274
|
+
return value;
|
|
275
|
+
}
|
|
276
|
+
function requiredValue(value, label) {
|
|
277
|
+
if (!value)
|
|
278
|
+
throw new AgentError('usage_error', `Missing ${label}`);
|
|
279
|
+
return value;
|
|
280
|
+
}
|
|
281
|
+
function tenant(parsed, selected) {
|
|
282
|
+
const value = option(parsed, 'tenant') ?? selected;
|
|
283
|
+
if (!value)
|
|
284
|
+
throw new AgentError('tenant_required', 'Select a tenant or pass --tenant');
|
|
285
|
+
assertUuid(value, 'tenant');
|
|
286
|
+
return value.toLowerCase();
|
|
287
|
+
}
|
|
288
|
+
function sourceReference(parsed) {
|
|
289
|
+
const namespace = option(parsed, 'source-namespace');
|
|
290
|
+
const id = option(parsed, 'source-id');
|
|
291
|
+
if (!namespace && !id)
|
|
292
|
+
return {};
|
|
293
|
+
if (!namespace || !id)
|
|
294
|
+
throw new AgentError('usage_error', '--source-namespace and --source-id must be supplied together');
|
|
295
|
+
return { source_reference: { namespace, id } };
|
|
296
|
+
}
|
|
297
|
+
async function jsonInput(raw) {
|
|
298
|
+
const text = raw.startsWith('@') ? await readFile(raw.slice(1), 'utf8') : raw;
|
|
299
|
+
try {
|
|
300
|
+
return JSON.parse(text);
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
throw new AgentError('invalid_json', 'Operation input is not valid JSON', { cause: error });
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function operationHelp(manifest, family) {
|
|
307
|
+
const operations = [...manifest.operations]
|
|
308
|
+
.filter((operation) => !family || operation.name === family || operation.name.startsWith(`${family}.`))
|
|
309
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
310
|
+
if (operations.length === 0)
|
|
311
|
+
throw new AgentError('unknown_operation_family', `No operations match ${family}`);
|
|
312
|
+
return { schema_version: manifest.schema_version, operations };
|
|
313
|
+
}
|
|
314
|
+
/** A failed write reports the request IDs it used, so a retry can replay rather than repeat it. */
|
|
315
|
+
async function withRetryIds(pending, ids) {
|
|
316
|
+
try {
|
|
317
|
+
return await pending;
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
if (!(error instanceof AgentError) || Object.keys(ids).length === 0)
|
|
321
|
+
throw error;
|
|
322
|
+
const { details, ...payload } = error.toJSON();
|
|
323
|
+
const merged = details === undefined ? ids
|
|
324
|
+
: typeof details === 'object' && details !== null && !Array.isArray(details) ? { ...details, ...ids }
|
|
325
|
+
: { server_details: details, ...ids };
|
|
326
|
+
throw new AgentError(payload.code, payload.message, {
|
|
327
|
+
details: merged, cause: error,
|
|
328
|
+
...(error.httpStatus === undefined ? {} : { httpStatus: error.httpStatus }),
|
|
329
|
+
...(payload.operation_id === undefined ? {} : { operationId: payload.operation_id }),
|
|
330
|
+
...(payload.retry_after_seconds === undefined ? {} : { retryAfterSeconds: payload.retry_after_seconds }),
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function withoutCapabilityUrls(value) {
|
|
335
|
+
const copy = { ...value };
|
|
336
|
+
delete copy.download_url;
|
|
337
|
+
delete copy.upload_url;
|
|
338
|
+
return copy;
|
|
339
|
+
}
|
|
340
|
+
function safeError(error) {
|
|
341
|
+
if (error instanceof AgentError)
|
|
342
|
+
return redact(error.toJSON());
|
|
343
|
+
return { code: 'internal_error', message: 'The command failed unexpectedly' };
|
|
344
|
+
}
|
|
345
|
+
function humanError(error) {
|
|
346
|
+
const lines = [`${error.code}: ${error.message}`];
|
|
347
|
+
if (error.operation_id)
|
|
348
|
+
lines.push(`operation_id: ${error.operation_id}`);
|
|
349
|
+
if (error.details !== undefined)
|
|
350
|
+
lines.push(`details: ${stableJson(error.details)}`);
|
|
351
|
+
return lines.join('\n');
|
|
352
|
+
}
|
|
353
|
+
function formatOutput(value, json) {
|
|
354
|
+
const safe = redact(value);
|
|
355
|
+
return json ? stableJson(safe) : stableJson(safe, 2);
|
|
356
|
+
}
|
|
357
|
+
function redact(value) {
|
|
358
|
+
if (Array.isArray(value))
|
|
359
|
+
return value.map(redact);
|
|
360
|
+
if (!value || typeof value !== 'object')
|
|
361
|
+
return value;
|
|
362
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
363
|
+
key,
|
|
364
|
+
/^(access_token|refresh_token|token|authorization|upload_url|download_url)$/i.test(key) ? '[redacted]' : redact(item),
|
|
365
|
+
]));
|
|
366
|
+
}
|
|
367
|
+
function stableJson(value, space) {
|
|
368
|
+
return JSON.stringify(sortValue(value), undefined, space);
|
|
369
|
+
}
|
|
370
|
+
function sortValue(value) {
|
|
371
|
+
if (Array.isArray(value))
|
|
372
|
+
return value.map(sortValue);
|
|
373
|
+
if (!value || typeof value !== 'object')
|
|
374
|
+
return value;
|
|
375
|
+
return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => [key, sortValue(item)]));
|
|
376
|
+
}
|
|
377
|
+
function resultExitCode(value) {
|
|
378
|
+
if (!value || typeof value !== 'object')
|
|
379
|
+
return 0;
|
|
380
|
+
const status = value.status;
|
|
381
|
+
return status === 'failed' || status === 'reconciliation_required' || status === 'in_progress' ? 8 : 0;
|
|
382
|
+
}
|
|
383
|
+
function errorExitCode(error) {
|
|
384
|
+
if (!(error instanceof AgentError))
|
|
385
|
+
return 1;
|
|
386
|
+
if (/auth|oauth|keychain|credential|reauth/i.test(error.code))
|
|
387
|
+
return 3;
|
|
388
|
+
if (/file|path|destination|integrity|upload|download/i.test(error.code))
|
|
389
|
+
return 9;
|
|
390
|
+
if (error.code === 'reconciliation_required')
|
|
391
|
+
return 8;
|
|
392
|
+
if (error.httpStatus === 403 || error.code === 'forbidden')
|
|
393
|
+
return 5;
|
|
394
|
+
if (error.httpStatus === 409 || /conflict/i.test(error.code))
|
|
395
|
+
return 6;
|
|
396
|
+
if ((error.httpStatus && [429, 502, 503, 504].includes(error.httpStatus)) || error.code === 'network_error')
|
|
397
|
+
return 7;
|
|
398
|
+
return 2;
|
|
399
|
+
}
|
|
400
|
+
function assertUuid(value, label) {
|
|
401
|
+
if (!isUuid(value)) {
|
|
402
|
+
throw new AgentError('invalid_request', `${label} must be a UUID`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,EAA2E,MAAM,gBAAgB,CA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,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,CAAA;IACtE,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe;QAAE,OAAO,CAAC,CAAA;IACrH,OAAO,CAAC,CAAA;AACV,CAAC;AAED,SAAS,UAAU,CAAC,KAAa,EAAE,KAAa;IAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,UAAU,CAAC,iBAAiB,EAAE,GAAG,KAAK,iBAAiB,CAAC,CAAA;IACpE,CAAC;AACH,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type CapabilityManifest, type OperationEnvelope, type OperationResult, type TenantListResponse } from './contracts.js';
|
|
2
|
+
import { type FetchLike } from './http.js';
|
|
3
|
+
export interface TokenProviderOptions {
|
|
4
|
+
forceRefresh?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export type TokenProvider = (options?: TokenProviderOptions) => Promise<string>;
|
|
7
|
+
export interface RetryOptions {
|
|
8
|
+
baseDelayMs?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface AgentAccessClientOptions {
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
tokenProvider: TokenProvider;
|
|
13
|
+
fetch?: FetchLike;
|
|
14
|
+
retry?: RetryOptions;
|
|
15
|
+
}
|
|
16
|
+
export declare class AgentAccessClient {
|
|
17
|
+
readonly baseUrl: URL;
|
|
18
|
+
private readonly tokenProvider;
|
|
19
|
+
private readonly fetch;
|
|
20
|
+
private readonly baseDelayMs;
|
|
21
|
+
constructor(options: AgentAccessClientOptions);
|
|
22
|
+
getCapabilities(): Promise<CapabilityManifest>;
|
|
23
|
+
listTenants(): Promise<TenantListResponse>;
|
|
24
|
+
execute<TInput = unknown, TResult = unknown>(envelope: OperationEnvelope<TInput>): Promise<OperationResult<TResult>>;
|
|
25
|
+
getOperation<TResult = unknown>(operationId: string, tenantId: string): Promise<OperationResult<TResult>>;
|
|
26
|
+
private request;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAA+B,KAAK,SAAS,EAAsB,MAAM,WAAW,CAAA;AAE3F,MAAM,WAAW,oBAAoB;IACnC,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;AAE/E,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,EAAE,aAAa,CAAA;IAC5B,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB;AAMD,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAA;IACrB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAC7C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAW;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;gBAExB,OAAO,EAAE,wBAAwB;IAOvC,eAAe,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAI9C,WAAW,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAI1C,OAAO,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAC/C,QAAQ,EAAE,iBAAiB,CAAC,MAAM,CAAC,GAClC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAU9B,YAAY,CAAC,OAAO,GAAG,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;YAWjG,OAAO;CAqDtB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { AgentError, isUuid, parseOperationEnvelope, } from './contracts.js';
|
|
2
|
+
import { joinUrl, parseAgentResponse, validateServiceUrl } from './http.js';
|
|
3
|
+
const MAX_ATTEMPTS = 3;
|
|
4
|
+
const MAX_DELAY_MS = 2_000;
|
|
5
|
+
const USER_AGENT = '@vectorlingo/cli/0.1.0';
|
|
6
|
+
export class AgentAccessClient {
|
|
7
|
+
baseUrl;
|
|
8
|
+
tokenProvider;
|
|
9
|
+
fetch;
|
|
10
|
+
baseDelayMs;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.baseUrl = validateServiceUrl(options.baseUrl, 'VectorLingo base URL');
|
|
13
|
+
this.tokenProvider = options.tokenProvider;
|
|
14
|
+
this.fetch = options.fetch ?? globalThis.fetch;
|
|
15
|
+
this.baseDelayMs = options.retry?.baseDelayMs ?? 250;
|
|
16
|
+
}
|
|
17
|
+
async getCapabilities() {
|
|
18
|
+
return this.request('GET', 'api/agent/v1/capabilities', undefined, true);
|
|
19
|
+
}
|
|
20
|
+
async listTenants() {
|
|
21
|
+
return this.request('GET', 'api/agent/v1/tenants', undefined, true);
|
|
22
|
+
}
|
|
23
|
+
async execute(envelope) {
|
|
24
|
+
const validated = parseOperationEnvelope(envelope);
|
|
25
|
+
return this.request('POST', 'api/agent/v1/operations', validated, validated.request_id !== undefined);
|
|
26
|
+
}
|
|
27
|
+
async getOperation(operationId, tenantId) {
|
|
28
|
+
assertUuid(operationId, 'operationId');
|
|
29
|
+
assertUuid(tenantId, 'tenantId');
|
|
30
|
+
return this.request('GET', `api/agent/v1/operations/${encodeURIComponent(operationId)}?tenant_id=${encodeURIComponent(tenantId)}`, undefined, true);
|
|
31
|
+
}
|
|
32
|
+
async request(method, path, body, retryable) {
|
|
33
|
+
let refreshed = false;
|
|
34
|
+
let forceRefreshNext = false;
|
|
35
|
+
let lastError;
|
|
36
|
+
const attempts = retryable ? MAX_ATTEMPTS : 1;
|
|
37
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
38
|
+
try {
|
|
39
|
+
const token = await this.tokenProvider(forceRefreshNext ? { forceRefresh: true } : undefined);
|
|
40
|
+
forceRefreshNext = false;
|
|
41
|
+
if (!token)
|
|
42
|
+
throw new AgentError('authentication_required', 'No access token is available');
|
|
43
|
+
const response = await this.fetch(joinUrl(this.baseUrl, path), {
|
|
44
|
+
method,
|
|
45
|
+
redirect: 'manual',
|
|
46
|
+
headers: {
|
|
47
|
+
accept: 'application/json',
|
|
48
|
+
authorization: `Bearer ${token}`,
|
|
49
|
+
'user-agent': USER_AGENT,
|
|
50
|
+
...(body === undefined ? {} : { 'content-type': 'application/json' }),
|
|
51
|
+
},
|
|
52
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
53
|
+
});
|
|
54
|
+
if (response.status >= 300 && response.status < 400) {
|
|
55
|
+
throw new AgentError('unexpected_redirect', 'VectorLingo API returned an unexpected redirect', {
|
|
56
|
+
httpStatus: response.status,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (response.status === 401 && !refreshed) {
|
|
60
|
+
refreshed = true;
|
|
61
|
+
forceRefreshNext = true;
|
|
62
|
+
attempt -= 1;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (isRetryableStatus(response.status) && attempt < attempts) {
|
|
66
|
+
const retryAfter = retryDelay(response.headers.get('retry-after'), attempt, this.baseDelayMs, MAX_DELAY_MS);
|
|
67
|
+
await wait(retryAfter);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
return await parseAgentResponse(response);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
lastError = error;
|
|
74
|
+
if (error instanceof AgentError)
|
|
75
|
+
throw error;
|
|
76
|
+
if (attempt >= attempts)
|
|
77
|
+
break;
|
|
78
|
+
await wait(Math.min(MAX_DELAY_MS, this.baseDelayMs * 2 ** (attempt - 1)));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
throw new AgentError('network_error', 'Unable to reach VectorLingo', { cause: lastError });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function assertUuid(value, field) {
|
|
85
|
+
if (!isUuid(value)) {
|
|
86
|
+
throw new AgentError('invalid_request', `${field} must be a UUID`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function isRetryableStatus(status) {
|
|
90
|
+
return status === 429 || status === 502 || status === 503 || status === 504;
|
|
91
|
+
}
|
|
92
|
+
function retryDelay(value, attempt, base, max) {
|
|
93
|
+
if (value !== null) {
|
|
94
|
+
const seconds = Number(value);
|
|
95
|
+
if (Number.isFinite(seconds) && seconds >= 0)
|
|
96
|
+
return Math.min(max, seconds * 1_000);
|
|
97
|
+
}
|
|
98
|
+
return Math.min(max, base * 2 ** (attempt - 1));
|
|
99
|
+
}
|
|
100
|
+
function wait(ms) {
|
|
101
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=client.js.map
|