@cpajs/cpa 0.1.0-rc.5 → 0.1.0-rc.7
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/README.md +33 -85
- package/dist/client/errors.d.ts +0 -33
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +0 -47
- package/dist/client/errors.js.map +1 -1
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/resources/config.d.ts +13 -43
- package/dist/client/resources/config.d.ts.map +1 -1
- package/dist/client/resources/config.js +0 -149
- package/dist/client/resources/config.js.map +1 -1
- package/dist/client/resources/credentials.d.ts +0 -77
- package/dist/client/resources/credentials.d.ts.map +1 -1
- package/dist/client/resources/credentials.js +0 -476
- package/dist/client/resources/credentials.js.map +1 -1
- package/dist/client/resources/requests.d.ts +0 -12
- package/dist/client/resources/requests.d.ts.map +1 -1
- package/dist/client/resources/requests.js +0 -31
- package/dist/client/resources/requests.js.map +1 -1
- package/dist/client/transport.d.ts +0 -6
- package/dist/client/transport.d.ts.map +1 -1
- package/dist/client/transport.js +8 -24
- package/dist/client/transport.js.map +1 -1
- package/dist/client/types/config.d.ts +2 -0
- package/dist/client/types/config.d.ts.map +1 -1
- package/dist/server/errors.d.ts +0 -2
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js.map +1 -1
- package/dist/server/index.d.ts +0 -4
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +139 -359
- package/dist/server/index.js.map +1 -1
- package/dist/server/logs.d.ts +1 -3
- package/dist/server/logs.d.ts.map +1 -1
- package/dist/server/logs.js +2 -8
- package/dist/server/logs.js.map +1 -1
- package/dist/server/process.d.ts +1 -3
- package/dist/server/process.d.ts.map +1 -1
- package/dist/server/process.js +2 -5
- package/dist/server/process.js.map +1 -1
- package/dist/server/types.d.ts +16 -94
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/client/errors.ts +0 -50
- package/src/client/index.ts +1 -15
- package/src/client/resources/config.ts +20 -180
- package/src/client/resources/credentials.ts +0 -550
- package/src/client/resources/requests.ts +0 -35
- package/src/client/transport.ts +7 -28
- package/src/client/types/config.ts +3 -0
- package/src/server/errors.ts +0 -2
- package/src/server/index.ts +149 -376
- package/src/server/logs.ts +3 -9
- package/src/server/process.ts +3 -7
- package/src/server/types.ts +16 -99
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ Bundled CLIProxyAPI: **v8.0.43**.
|
|
|
15
15
|
- Upgrading: [CHANGELOG.md](CHANGELOG.md) and [docs/migration.md](docs/migration.md).
|
|
16
16
|
- Platforms, versions and the versioning policy: [docs/compatibility.md](docs/compatibility.md).
|
|
17
17
|
- Every management API route: [docs/api-coverage.md](docs/api-coverage.md).
|
|
18
|
+
- What cpajs does and does not do: [docs/scope.md](docs/scope.md).
|
|
18
19
|
|
|
19
20
|
```sh
|
|
20
21
|
npm install @cpajs/cpa
|
|
@@ -51,7 +52,7 @@ await server.stop();
|
|
|
51
52
|
`stop()` and `startServer()`. Pass `overwriteConfig: true` to replace it; when a file is kept, `config`, `host`
|
|
52
53
|
and `port` are not applied and a `configReused` warning is emitted. Credentials go to `<stateDir>/auths`
|
|
53
54
|
unless `oauth.auth-dir` is set. The server binds `127.0.0.1` unless you pass `host` or set `server.host`.
|
|
54
|
-
- A function is called before the first start and again before every restart
|
|
55
|
+
- A function is called before the first start and again before every manual `restart()`. It receives
|
|
55
56
|
`{ existing, reason }`: the parsed current `<stateDir>/config.yaml` (or `undefined`) and `'start'` or
|
|
56
57
|
`'restart'`. Its result replaces the file each time, like `overwriteConfig: true`, while cpajs still fills in
|
|
57
58
|
the listener, management secret and panel fields. It cannot be combined with `overwriteConfig`, and a
|
|
@@ -68,7 +69,7 @@ await server.stop();
|
|
|
68
69
|
`tls.enable`. When cpajs writes the file and no port is given, it picks a free port first; a reused file keeps
|
|
69
70
|
the port it already has.
|
|
70
71
|
- `startServer` resolves only once `/healthz` answers. It rejects with `CpaStartError` on early exit, port
|
|
71
|
-
conflict, timeout (`startupTimeoutMs`, default 30 s), `signal` abort, or an
|
|
72
|
+
conflict, timeout (`startupTimeoutMs`, default 30 s), `signal` abort, or an invalid config function. In every
|
|
72
73
|
failure case the process is stopped and the temporary directory removed.
|
|
73
74
|
- `stop()` is idempotent: on POSIX it sends SIGTERM and then SIGKILL after `stopTimeoutMs` (default 10 s). On
|
|
74
75
|
Windows Node cannot deliver a graceful shutdown signal, so `stop()` terminates the process forcefully (equivalent
|
|
@@ -78,37 +79,18 @@ await server.stop();
|
|
|
78
79
|
(`timeoutMs` defaults to `stopTimeoutMs`) and starts it again with the original options. The handle keeps
|
|
79
80
|
`origin`, `baseUrl`, `host`, `port`, `stateDir` and `configPath`; `pid`, `process` and `recentLogs` point at the
|
|
80
81
|
new process. With an object `config`, the existing `config.yaml` is reused and never rewritten, so changes made
|
|
81
|
-
through the management API survive. A function `config` is evaluated again before
|
|
82
|
-
replaces the file.
|
|
82
|
+
through the management API survive. A function `config` is evaluated again before the restart and its result
|
|
83
|
+
replaces the file. The original port is reused; if another process took it meanwhile, restart fails with
|
|
83
84
|
`CpaStartError` code `port-in-use` instead of changing `origin`. Concurrent `restart()` calls share one
|
|
84
|
-
operation, `stop()` during a restart aborts it, and `restart()` after
|
|
85
|
-
the handle stopped and cleans up a
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
server and settle `exited` (default `Infinity`); a manual `restart()` resets the count. `stop()` cancels a
|
|
93
|
-
pending wait, and `restart()` during one tries immediately. A port taken by another process makes that attempt
|
|
94
|
-
fail and retries after the next backoff instead of changing `origin`.
|
|
95
|
-
- `singleton: true` reuses one server per process for the same resolved `stateDir` (or absolute `configPath`),
|
|
96
|
-
so a dev server that evaluates a module more than once cannot start CPA twice. Concurrent calls share the
|
|
97
|
-
in-flight start and its promise; a handle that has not stopped yet is returned as-is, including while it is
|
|
98
|
-
backing off or restarting. Once the handle stops, the next call starts a new process. It requires an explicit
|
|
99
|
-
`stateDir` or `configPath`, and the options of the first call win: options on later calls are not compared.
|
|
100
|
-
The registry lives on `globalThis` (keyed by `Symbol.for('cpajs.servers')`), so duplicate module instances
|
|
101
|
-
in the same process share it.
|
|
102
|
-
- Lifecycle events: `server.on('exit' | 'restart' | 'restarted' | 'restart-failed', listener)` returns an
|
|
103
|
-
unsubscribe function. An `exit` payload has `code`, `signal`, `recentLogs` and `willRestart`; `restart` and
|
|
104
|
-
`restarted` carry `reason` (`'unexpected-exit' | 'manual'`) and `attempt`, and `restarted` also has
|
|
105
|
-
`originChanged` (currently always `false`); `restart-failed` has `error`, `attempt` and `willRetry`. A
|
|
85
|
+
operation, `stop()` during a restart aborts it, and `restart()` after the handle stopped (including after an
|
|
86
|
+
unexpected exit) rejects with code `stopped`. A failed restart leaves the handle stopped and cleans up a
|
|
87
|
+
temporary state directory like `startServer` does.
|
|
88
|
+
- There is no automatic restart. Use `server.exited` to observe an unexpected exit and call `startServer()`
|
|
89
|
+
again, or call `restart()` from your own supervisor.
|
|
90
|
+
- Lifecycle events: `server.on('exit', listener)` returns an unsubscribe function. An `exit` payload has
|
|
91
|
+
`code`, `signal`, `recentLogs`, `willRestart` and `reason`: `'stop'` when `stop()` stopped the process,
|
|
92
|
+
`'restart'` when a manual `restart()` replaced it, and `'unexpected'` when the process exited by itself. A
|
|
106
93
|
listener that throws is reported through `process.emitWarning` and never disturbs the server.
|
|
107
|
-
- `hooks.afterStart({ server, client, reason })` runs after each process is ready: the first start and every
|
|
108
|
-
restart, manual or automatic. `reason` is `'start'` or `'restart'`; `client` is `server.client()` when cpajs
|
|
109
|
-
knows the plaintext management key and `undefined` otherwise. If it throws, the first start rejects with
|
|
110
|
-
`CpaStartError` code `hook-failed` after stopping the process, while a restart fails like any other
|
|
111
|
-
(`restart-failed`, then backoff or a rejected `restart()`).
|
|
112
94
|
- Shutdown: CPA does not outlive your process, even if it is killed with SIGKILL, crashes, or is restarted by
|
|
113
95
|
`tsx watch` / `nodemon`. Each platform package ships a small `cpa-launcher` (pure Go, in `launcher/`) that
|
|
114
96
|
relies only on operating-system facilities:
|
|
@@ -139,15 +121,8 @@ await server.stop();
|
|
|
139
121
|
for CPA's `--------` placeholder) and `message` (the text after CPA's timestamp, request-id, level and caller
|
|
140
122
|
prefixes). Output that does not match the format still arrives, with only `stream` and `line`.
|
|
141
123
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
unknown output is never hidden.
|
|
145
|
-
|
|
146
|
-
```ts
|
|
147
|
-
await startServer({ config, logs: { minLevel: 'warn' }, onLog: ({ level, message, line }) => {
|
|
148
|
-
console.log(`[${level ?? 'raw'}] ${message ?? line}`);
|
|
149
|
-
} });
|
|
150
|
-
```
|
|
124
|
+
`onLog` receives every redacted line. Filter on `level` yourself when you only want some severities;
|
|
125
|
+
`recentLogs` always keeps everything.
|
|
151
126
|
- Management key: you usually don't need one. Without `management`, cpajs generates a random key for each start,
|
|
152
127
|
writes only its bcrypt hash into the managed config (remote management off), keeps the plaintext in memory,
|
|
153
128
|
and gives you `server.client()`: a management client bound to this server. The key is never exposed, and
|
|
@@ -248,28 +223,14 @@ const { data: config, etag } = await client.config.get();
|
|
|
248
223
|
await client.config.patch({ routing: { strategy: 'round-robin' } }, { ifMatch: etag });
|
|
249
224
|
await client.config.set('routing/retry/request-retry', 2); // value typed by path: number
|
|
250
225
|
|
|
251
|
-
// Read
|
|
252
|
-
|
|
253
|
-
await client.config.
|
|
254
|
-
|
|
255
|
-
// Deep-compares each top-level section and replaces only the ones that differ.
|
|
256
|
-
// A listed section is written wholesale, so nested keys absent from it are removed;
|
|
257
|
-
// sections not listed are untouched.
|
|
258
|
-
await client.config.reconcile({ routing: { strategy: 'fill-first' } });
|
|
226
|
+
// Read one node with its ETag, then write it back conditionally.
|
|
227
|
+
const read = await client.config.getPath('routing/strategy');
|
|
228
|
+
await client.config.set('routing/strategy', 'fill-first', { ifMatch: read.etag });
|
|
259
229
|
|
|
260
230
|
const { files } = await client.credentials.list();
|
|
231
|
+
// Upload a credential file. CPA returns the credential list, models and downloads as-is.
|
|
261
232
|
await client.credentials.upload({ name: 'codex-me.json', content: credentialJson });
|
|
262
233
|
|
|
263
|
-
// Files and config `api-keys` entries in one list, with the runtime auth_index.
|
|
264
|
-
const all = await client.credentials.listAll();
|
|
265
|
-
const models = await client.credentials.modelsFor({ auth_index: all[0]!.auth_index }, { details: true });
|
|
266
|
-
|
|
267
|
-
const synced = await client.credentials.reconcile({
|
|
268
|
-
owner: 'chat',
|
|
269
|
-
files: [{ name: 'chat-a.json', content: credentialJson, revision: '2026-10-27' }],
|
|
270
|
-
});
|
|
271
|
-
console.log(synced); // { uploaded: ['chat-a.json'], deleted: [], unchanged: [] }
|
|
272
|
-
|
|
273
234
|
const login = await client.oauth.start({ provider: 'claude' });
|
|
274
235
|
console.log('open', login.url);
|
|
275
236
|
await client.oauth.waitForCompletion(login.state);
|
|
@@ -281,43 +242,26 @@ try {
|
|
|
281
242
|
}
|
|
282
243
|
```
|
|
283
244
|
|
|
284
|
-
`credentials.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
in `files` are deleted; files owned by anyone else are never touched. The caller's content objects are not
|
|
288
|
-
mutated.
|
|
289
|
-
|
|
290
|
-
`credentials.listAll` merges credential files with the config's `api-keys` entries, which `/credentials` only
|
|
291
|
-
exposes as a runtime view. Select either a file by `name` or any credential by `auth_index` with
|
|
292
|
-
`credentials.modelsFor`. Config-key models follow CPA's own resolution (model aliases, `excluded-models` with
|
|
293
|
-
`*` wildcards, and per-key overrides); `details: true` adds the channel's static model definitions. Runtime
|
|
294
|
-
state such as cooldowns is only available for files.
|
|
245
|
+
`credentials.list`, `upload`, `uploadMany`, `download`, `delete`, `setStatus` and the other methods pass
|
|
246
|
+
through the matching upstream routes. `setStatus` and `delete` take file names (and arrays of names) only; config
|
|
247
|
+
`api-keys` entries are managed through `client.config` like any other config node.
|
|
295
248
|
|
|
296
249
|
| Group | Routes |
|
|
297
250
|
| --- | --- |
|
|
298
|
-
| `config` | `/config`, `/config.yaml`, `/config/*path`, with ETag / `If-Match
|
|
299
|
-
| `credentials` | list
|
|
251
|
+
| `config` | `/config`, `/config.yaml`, `/config/*path`, with ETag / `If-Match` |
|
|
252
|
+
| `credentials` | list, models, upload (raw or multipart), delete, status, download, fields, refresh, SIWC status |
|
|
300
253
|
| `oauth` | auth URL, status / wait, cancel, callback, Vertex import, SIWC bind |
|
|
301
254
|
| `logs` | main log with cursor, clear, error logs, request logs |
|
|
302
255
|
| `usage` | API-key counters, usage queue (destructive pop) |
|
|
303
256
|
| `routing` | cooldown reset, model definitions |
|
|
304
|
-
| `requests` | server-side `api-call` (`apiCall
|
|
257
|
+
| `requests` | server-side `api-call` (`apiCall`) |
|
|
305
258
|
| `plugins` | list, delete, store, install, quota |
|
|
306
259
|
| `server` | `/healthz`, version headers, latest release |
|
|
307
260
|
|
|
308
|
-
|
|
309
|
-
upstream status throws `CpaUpstreamError`, and an unresolvable `$TOKEN$` throws `CpaCredentialTokenError`.
|
|
310
|
-
|
|
311
|
-
Every method takes `{ signal, timeoutMs, headers }`. GET requests retry CPA's transient
|
|
312
|
-
`500 invalid_config` (a read landing while `config.yaml` is rewritten) up to three times after
|
|
313
|
-
100/200/400 ms; writes never retry. Pass `retryInvalidConfig: false` to `createClient` to disable it. Errors:
|
|
261
|
+
Every method takes `{ signal, timeoutMs, headers }`. Errors:
|
|
314
262
|
|
|
315
263
|
- `CpaHttpError` for a non-2xx response. It carries `status`, the raw `body`, parsed `data`, and `errorCode` /
|
|
316
264
|
`errorMessage`.
|
|
317
|
-
- `CpaUpstreamError` when `requests.apiCallJson` gets a non-2xx upstream status. It carries the upstream
|
|
318
|
-
`status`, `headers`, and `body` (parsed when JSON).
|
|
319
|
-
- `CpaCredentialTokenError` when `requests.apiCallJson` cannot resolve `$TOKEN$`. It carries `status` and
|
|
320
|
-
`errorCode`.
|
|
321
265
|
- `CpaNetworkError` when the request fails.
|
|
322
266
|
- `CpaTimeoutError` when the request times out.
|
|
323
267
|
- `CpaAbortError` when your `signal` aborts the request.
|
|
@@ -364,9 +308,12 @@ Nitro uses nft. Import the entry from the server code, and full-trace the platfo
|
|
|
364
308
|
directory is copied too (`pkg*` copies every file, not only the traced ones):
|
|
365
309
|
|
|
366
310
|
```ts
|
|
311
|
+
import { resolveBinary } from '@cpajs/cpa/server';
|
|
312
|
+
|
|
367
313
|
export default defineNitroConfig({
|
|
368
|
-
//
|
|
369
|
-
|
|
314
|
+
// The platform package installed on the build machine, e.g. @cpajs/linux-x64-gnu.
|
|
315
|
+
// Build on the platform you deploy to, or write the package name out instead.
|
|
316
|
+
traceDeps: ['@cpajs/cpa', `${resolveBinary().packageName}*`],
|
|
370
317
|
});
|
|
371
318
|
```
|
|
372
319
|
|
|
@@ -420,9 +367,10 @@ Release tooling, all in `scripts/` and run directly with Node's type stripping:
|
|
|
420
367
|
| `assemble-packages.ts` | Create the `@cpajs/*` platform packages. |
|
|
421
368
|
| `pack.ts` | Produce the tarballs. |
|
|
422
369
|
| `install-test.ts` | Install the tarballs through a local registry with npm, pnpm or bun, and run them. |
|
|
370
|
+
| `wait-for-packages.ts` | Poll the npm registry until every platform package resolves at a version; run it before publishing the main package. |
|
|
423
371
|
| `trust-publishers.ts` | Configure npm trusted publishing for all packages (run locally after the first publish). |
|
|
424
372
|
|
|
425
|
-
`.github/workflows/release.yml` runs these steps across the whole platform matrix and publishes on `v*` tags through npm trusted publishing (OIDC). Prerelease versions such as `0.0.1-alpha-1` go to a matching dist-tag (`alpha`). There is no npm token; `trust-publishers.ts` configures the trusted publisher for every package. A newly added platform package has to exist on npm before it can be trusted.
|
|
373
|
+
`.github/workflows/release.yml` runs these steps across the whole platform matrix and publishes on `v*` tags through npm trusted publishing (OIDC). Prerelease versions such as `0.0.1-alpha-1` go to a matching dist-tag (`alpha`). There is no npm token; `trust-publishers.ts` configures the trusted publisher for every package. A newly added platform package has to exist on npm before it can be trusted. The publish job runs `wait-for-packages.ts --version <version>` after publishing the platform packages and before the main package, so `@cpajs/cpa` is not published while one of its optional dependencies is still missing from the install packument that npm, pnpm and bun read (registry metadata is CDN-cached). It can be run locally against an already published release, e.g. `node scripts/wait-for-packages.ts --version 0.1.0-rc.5`; `--timeout` and `--interval` take seconds.
|
|
426
374
|
|
|
427
375
|
## License
|
|
428
376
|
|
package/dist/client/errors.d.ts
CHANGED
|
@@ -36,37 +36,6 @@ export declare class CpaHttpError extends CpaClientError {
|
|
|
36
36
|
/** The `message` field of a CPA error body, when present. */
|
|
37
37
|
get errorMessage(): string | undefined;
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
* The upstream call made through `requests.apiCallJson` returned a non-2xx status.
|
|
41
|
-
*
|
|
42
|
-
* `headers` and `body` are the upstream response's; `body` is parsed when it is
|
|
43
|
-
* JSON, the raw text when it is not, and `undefined` when it is empty.
|
|
44
|
-
*/
|
|
45
|
-
export declare class CpaUpstreamError extends CpaClientError {
|
|
46
|
-
readonly name = "CpaUpstreamError";
|
|
47
|
-
readonly status: number;
|
|
48
|
-
readonly headers: Record<string, string[]>;
|
|
49
|
-
readonly body: unknown;
|
|
50
|
-
constructor(request: {
|
|
51
|
-
method: string;
|
|
52
|
-
url: string;
|
|
53
|
-
}, response: {
|
|
54
|
-
status: number;
|
|
55
|
-
headers: Record<string, string[]>;
|
|
56
|
-
body: string;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* CPA answered 400 because it could not resolve the credential token behind
|
|
61
|
-
* `$TOKEN$`. `errorCode` is CPA's error, e.g. `"auth token not found"`;
|
|
62
|
-
* `cause` is the original `CpaHttpError`.
|
|
63
|
-
*/
|
|
64
|
-
export declare class CpaCredentialTokenError extends CpaClientError {
|
|
65
|
-
readonly name = "CpaCredentialTokenError";
|
|
66
|
-
readonly status: number;
|
|
67
|
-
readonly errorCode: string;
|
|
68
|
-
constructor(error: CpaHttpError);
|
|
69
|
-
}
|
|
70
39
|
/** The request could not be sent or the response could not be read. */
|
|
71
40
|
export declare class CpaNetworkError extends CpaClientError {
|
|
72
41
|
readonly name = "CpaNetworkError";
|
|
@@ -98,6 +67,4 @@ export declare class CpaResponseError extends CpaClientError {
|
|
|
98
67
|
cause?: unknown;
|
|
99
68
|
});
|
|
100
69
|
}
|
|
101
|
-
/** Parses an `api-call` body: JSON when possible, raw text otherwise, `undefined` when empty. */
|
|
102
|
-
export declare function parseApiCallBody(text: string): unknown;
|
|
103
70
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAkB,IAAI,EAAE,MAAM,CAAoB;IAClD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAInG;CACF;AAED;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,cAAc;IAC9C,SAAkB,IAAI,kBAAkB;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAEvB,YACE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EACxC,QAAQ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AAM,EAUb;IAED,+FAA+F;IAC/F,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAGlC;IAED,6DAA6D;IAC7D,IAAI,YAAY,IAAI,MAAM,GAAG,SAAS,CAGrC;CACF;AAED,uEAAuE;AACvE,qBAAa,eAAgB,SAAQ,cAAc;IACjD,SAAkB,IAAI,qBAAqB;CAC5C;AAED,wCAAwC;AACxC,qBAAa,eAAgB,SAAQ,cAAc;IACjD,SAAkB,IAAI,qBAAqB;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,YAAY,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAGrG;CACF;AAED,4EAA4E;AAC5E,qBAAa,aAAc,SAAQ,cAAc;IAC/C,SAAkB,IAAI,mBAAmB;CAC1C;AAED,iFAAiF;AACjF,qBAAa,gBAAiB,SAAQ,cAAc;IAClD,SAAkB,IAAI,sBAAsB;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAIjI;CACF"}
|
package/dist/client/errors.js
CHANGED
|
@@ -43,42 +43,6 @@ export class CpaHttpError extends CpaClientError {
|
|
|
43
43
|
return typeof value === 'string' ? value : undefined;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
/**
|
|
47
|
-
* The upstream call made through `requests.apiCallJson` returned a non-2xx status.
|
|
48
|
-
*
|
|
49
|
-
* `headers` and `body` are the upstream response's; `body` is parsed when it is
|
|
50
|
-
* JSON, the raw text when it is not, and `undefined` when it is empty.
|
|
51
|
-
*/
|
|
52
|
-
export class CpaUpstreamError extends CpaClientError {
|
|
53
|
-
name = 'CpaUpstreamError';
|
|
54
|
-
status;
|
|
55
|
-
headers;
|
|
56
|
-
body;
|
|
57
|
-
constructor(request, response) {
|
|
58
|
-
const body = parseApiCallBody(response.body);
|
|
59
|
-
const detail = describeErrorBody(body);
|
|
60
|
-
super(`${request.method} ${request.url} failed with upstream ${response.status}${detail ? `: ${detail}` : ''}`, request);
|
|
61
|
-
this.status = response.status;
|
|
62
|
-
this.headers = response.headers;
|
|
63
|
-
this.body = body;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* CPA answered 400 because it could not resolve the credential token behind
|
|
68
|
-
* `$TOKEN$`. `errorCode` is CPA's error, e.g. `"auth token not found"`;
|
|
69
|
-
* `cause` is the original `CpaHttpError`.
|
|
70
|
-
*/
|
|
71
|
-
export class CpaCredentialTokenError extends CpaClientError {
|
|
72
|
-
name = 'CpaCredentialTokenError';
|
|
73
|
-
status;
|
|
74
|
-
errorCode;
|
|
75
|
-
constructor(error) {
|
|
76
|
-
const code = error.errorCode ?? 'unknown error';
|
|
77
|
-
super(`${error.method} ${error.url} could not resolve a credential token: ${code}`, error, { cause: error });
|
|
78
|
-
this.status = error.status;
|
|
79
|
-
this.errorCode = code;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
46
|
/** The request could not be sent or the response could not be read. */
|
|
83
47
|
export class CpaNetworkError extends CpaClientError {
|
|
84
48
|
name = 'CpaNetworkError';
|
|
@@ -117,17 +81,6 @@ function parseJsonOrUndefined(text) {
|
|
|
117
81
|
return undefined;
|
|
118
82
|
}
|
|
119
83
|
}
|
|
120
|
-
/** Parses an `api-call` body: JSON when possible, raw text otherwise, `undefined` when empty. */
|
|
121
|
-
export function parseApiCallBody(text) {
|
|
122
|
-
if (text === '')
|
|
123
|
-
return undefined;
|
|
124
|
-
try {
|
|
125
|
-
return JSON.parse(text);
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
return text;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
84
|
function describeErrorBody(data) {
|
|
132
85
|
if (typeof data !== 'object' || data === null)
|
|
133
86
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,MAAM,OAAO,cAAe,SAAQ,KAAK;IACrB,IAAI,GAAW,gBAAgB,CAAC;IACzC,MAAM,CAAS;IACf,GAAG,CAAS;IAErB,YAAY,OAAe,EAAE,OAAwC,EAAE,OAA6B;QAClG,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACzB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,cAAc;IAC5B,IAAI,GAAG,cAAc,CAAC;IAC/B,MAAM,CAAS;IACf,UAAU,CAAS;IACnB,OAAO,CAAU;IACjB,IAAI,CAAS;IACb,IAAI,CAAU;IAEvB,YACE,OAAwC,EACxC,QAAkE,EAClE,IAAY;QAEZ,MAAM,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;QAC7F,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,gBAAgB,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC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AE,OAAO,EAAE,GAAG,IAA8C,CAAC;IAC1E,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAC7F,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrD,CAAC"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -8,10 +8,10 @@ import { RoutingResource } from './resources/routing.ts';
|
|
|
8
8
|
import { ServerResource } from './resources/server.ts';
|
|
9
9
|
import { UsageResource } from './resources/usage.ts';
|
|
10
10
|
import { type ClientOptions, type RawRequest, type TransportResponse } from './transport.ts';
|
|
11
|
-
export { CpaAbortError, CpaClientError,
|
|
11
|
+
export { CpaAbortError, CpaClientError, CpaHttpError, CpaNetworkError, CpaResponseError, CpaTimeoutError, } from './errors.ts';
|
|
12
12
|
export type { ClientOptions, FetchLike, Query, QueryValue, RawRequest, RequestOptions, ResponseType, TransportResponse } from './transport.ts';
|
|
13
|
-
export type {
|
|
14
|
-
export type { CredentialContent, CredentialFile, CredentialSelector
|
|
13
|
+
export type { ConfigPath, ConfigPathValue, ConfigWriteOptions, ConfigWriteResult, JsonInput, Versioned, } from './resources/config.ts';
|
|
14
|
+
export type { CredentialContent, CredentialFile, CredentialSelector } from './resources/credentials.ts';
|
|
15
15
|
export type { DownloadedFile } from './resources/download.ts';
|
|
16
16
|
export type { WaitForOAuthOptions } from './resources/oauth.ts';
|
|
17
17
|
export { ConfigResource, CredentialsResource, LogsResource, OAuthResource, PluginsResource, RequestsResource, RoutingResource, ServerResource, UsageResource, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAA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AI,MAAM,CAEzB;IAED,8FAA8F;IAC9F,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAEvE;CACF;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,CAE9D;AAED,+CAA+C;AAC/C,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAM7D"}
|
package/dist/client/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { RoutingResource } from './resources/routing.js';
|
|
|
8
8
|
import { ServerResource } from './resources/server.js';
|
|
9
9
|
import { UsageResource } from './resources/usage.js';
|
|
10
10
|
import { Transport } from './transport.js';
|
|
11
|
-
export { CpaAbortError, CpaClientError,
|
|
11
|
+
export { CpaAbortError, CpaClientError, CpaHttpError, CpaNetworkError, CpaResponseError, CpaTimeoutError, } from './errors.js';
|
|
12
12
|
export { ConfigResource, CredentialsResource, LogsResource, OAuthResource, PluginsResource, RequestsResource, RoutingResource, ServerResource, UsageResource, };
|
|
13
13
|
/** Typed client for the CLIProxyAPI v8 management API (`/v8/management`). */
|
|
14
14
|
export class CpaClient {
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,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AC;AAChC,CAAC;AAED,+CAA+C;AAC/C,MAAM,UAAU,eAAe,CAAC,OAAqB;IACnD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,GAAG,CAAC,QAAQ,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC;IACxD,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;IAChB,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;IACd,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -22,33 +22,23 @@ export interface ConfigWriteResult {
|
|
|
22
22
|
status: 'ok';
|
|
23
23
|
'config-version': 8;
|
|
24
24
|
}
|
|
25
|
-
export interface ConfigMutationOptions extends RequestOptions {
|
|
26
|
-
/**
|
|
27
|
-
* Read/write attempts before an optimistic-concurrency conflict is thrown.
|
|
28
|
-
* A 412 re-reads the node and calls the update function again. Defaults to 5.
|
|
29
|
-
*/
|
|
30
|
-
maxAttempts?: number | undefined;
|
|
31
|
-
}
|
|
32
|
-
export interface ConfigUpdateResult {
|
|
33
|
-
/** `false` when the update function returned `undefined`, so nothing was written. */
|
|
34
|
-
written: boolean;
|
|
35
|
-
/** ETag of the write, or of the read when nothing was written. */
|
|
36
|
-
etag: string | undefined;
|
|
37
|
-
}
|
|
38
|
-
export interface ConfigReconcileResult extends ConfigUpdateResult {
|
|
39
|
-
/** Top-level keys whose stored value differed and were written. */
|
|
40
|
-
changed: string[];
|
|
41
|
-
}
|
|
42
25
|
/**
|
|
43
26
|
* A config path: `'routing/retry'` or `['routing', 'retry']`. Segments are
|
|
44
27
|
* dash-case YAML keys; list indices are not addressable (lists are replaced whole).
|
|
45
28
|
*/
|
|
46
29
|
export type ConfigPath = string | readonly string[];
|
|
30
|
+
/** Joins a tuple path into the slash-separated form `CpaConfigPath` uses. */
|
|
31
|
+
type JoinConfigPath<T extends readonly string[]> = T extends readonly [infer Head extends string, ...infer Tail extends readonly string[]] ? Tail extends readonly [] ? Head : `${Head}/${JoinConfigPath<Tail>}` : T extends readonly [] ? '' : string;
|
|
32
|
+
/** A string path, or a tuple path joined into one; unions are preserved. */
|
|
33
|
+
type PathString<P extends ConfigPath> = P extends readonly string[] ? JoinConfigPath<P> : P extends string ? P : never;
|
|
34
|
+
type ConfigPathValueAt<S extends string> = S extends CpaConfigPath ? CpaConfigValue<S> : JsonInput;
|
|
47
35
|
/**
|
|
48
|
-
* The value accepted at `P`: the {@link CpaConfig} type for a known
|
|
49
|
-
*
|
|
36
|
+
* The value accepted at `P`: the {@link CpaConfig} type for a known path
|
|
37
|
+
* (`'api-keys/gemini'` or `['api-keys', 'gemini']`), any JSON-serialisable value
|
|
38
|
+
* otherwise (plugin options, computed strings, broad `string` / `string[]` paths).
|
|
39
|
+
* A union path takes the union of its branches' value types.
|
|
50
40
|
*/
|
|
51
|
-
export type ConfigPathValue<P extends ConfigPath> =
|
|
41
|
+
export type ConfigPathValue<P extends ConfigPath> = ConfigPathValueAt<PathString<P>>;
|
|
52
42
|
/** JSON-serialisable input. Unlike {@link JsonValue} it accepts interfaces such as `CpaConfig['routing']`. */
|
|
53
43
|
export type JsonInput = string | number | boolean | null | object;
|
|
54
44
|
/** `/v8/management/config*`: the native configuration document. */
|
|
@@ -75,32 +65,12 @@ export declare class ConfigResource {
|
|
|
75
65
|
replaceYaml(yaml: string, options?: ConfigWriteOptions): Promise<Versioned<ConfigWriteResult>>;
|
|
76
66
|
/** Reads one node, e.g. `getPath('server/port')`. A missing node is a 404 `CpaHttpError`. */
|
|
77
67
|
getPath<T = JsonValue>(path: ConfigPath, options?: RequestOptions): Promise<Versioned<T>>;
|
|
78
|
-
/**
|
|
79
|
-
* Reads a node, passes it to `fn`, and writes the result back with `If-Match`.
|
|
80
|
-
* A missing node (404) passes `undefined`. Returning `undefined` writes
|
|
81
|
-
* nothing. A 412 re-reads and calls `fn` again, up to `maxAttempts` times.
|
|
82
|
-
*
|
|
83
|
-
* The value handed to `fn` has the read-only `auth_index` fields removed
|
|
84
|
-
* (GET injects them into API keys), so it is safe to write back.
|
|
85
|
-
* Calls for the same path on one client instance run one at a time.
|
|
86
|
-
*/
|
|
87
|
-
update<P extends ConfigPath>(path: P, fn: (current: ConfigPathValue<P> | undefined) => ConfigPathValue<P> | undefined | Promise<ConfigPathValue<P> | undefined>, options?: ConfigMutationOptions): Promise<ConfigUpdateResult>;
|
|
88
|
-
/**
|
|
89
|
-
* Replaces each top-level section in `partial` whose stored value differs,
|
|
90
|
-
* after a deep comparison that ignores the injected `auth_index` fields.
|
|
91
|
-
* Each changed section is written wholesale with PUT `/config/<key>`, so
|
|
92
|
-
* nested keys absent from the target are removed. Sections not listed are
|
|
93
|
-
* left untouched, and a target value of `undefined` is skipped.
|
|
94
|
-
*
|
|
95
|
-
* The first write uses the read's ETag; each later write uses the previous
|
|
96
|
-
* write's ETag. A 412 at any point re-reads and recomputes from scratch.
|
|
97
|
-
*/
|
|
98
|
-
reconcile(partial: CpaConfig, options?: ConfigMutationOptions): Promise<ConfigReconcileResult>;
|
|
99
68
|
/** Replaces or creates one node. Missing parent objects are created. */
|
|
100
|
-
set<P extends ConfigPath>(path: P, value: ConfigPathValue<P>, options?: ConfigWriteOptions): Promise<Versioned<ConfigWriteResult>>;
|
|
69
|
+
set<const P extends ConfigPath>(path: P, value: ConfigPathValue<P>, options?: ConfigWriteOptions): Promise<Versioned<ConfigWriteResult>>;
|
|
101
70
|
/** Deep-merges into one node (see {@link patch}). */
|
|
102
|
-
patchPath<P extends ConfigPath>(path: P, value: ConfigPathValue<P>, options?: ConfigWriteOptions): Promise<Versioned<ConfigWriteResult>>;
|
|
71
|
+
patchPath<const P extends ConfigPath>(path: P, value: ConfigPathValue<P>, options?: ConfigWriteOptions): Promise<Versioned<ConfigWriteResult>>;
|
|
103
72
|
/** Removes one node and any parents left empty. A missing node is a 404 `CpaHttpError`. */
|
|
104
73
|
delete(path: ConfigPath, options?: ConfigWriteOptions): Promise<Versioned<ConfigWriteResult>>;
|
|
105
74
|
}
|
|
75
|
+
export {};
|
|
106
76
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/client/resources/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/client/resources/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAc,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAElF,wFAAwF;AACxF,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,IAAI,EAAE,CAAC,CAAC;IACR,wFAAwF;IACxF,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,IAAI,CAAC;IACb,gBAAgB,EAAE,CAAC,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;AAEpD,6EAA6E;AAC7E,KAAK,cAAc,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,IAAI,SAAS,MAAM,EAAE,GAAG,MAAM,IAAI,SAAS,SAAS,MAAM,EAAE,CAAC,GACtI,IAAI,SAAS,SAAS,EAAE,GACtB,IAAI,GACJ,GAAG,IAAI,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,GACnC,CAAC,SAAS,SAAS,E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