@agentage/cli 0.65.1 → 0.66.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/commands/daemon/installer.js +4 -2
- package/dist/commands/extension/lifecycle-list.d.ts +2 -2
- package/dist/commands/extension/lifecycle-list.js +6 -2
- package/dist/lib/net/fetch.d.ts +1 -0
- package/dist/lib/net/fetch.js +7 -0
- package/dist/lib/net/market-error.d.ts +0 -1
- package/dist/lib/net/market-error.js +1 -1
- package/dist/lib/net/market.d.ts +11 -14
- package/dist/lib/net/market.js +45 -101
- package/package.json +2 -2
|
@@ -7,7 +7,7 @@ import { isRange } from '../../core/semver-range.js';
|
|
|
7
7
|
import { DIST_TAG, isVersionSpec } from '../../core/installer/version-spec.js';
|
|
8
8
|
import { editableProfile } from '../../core/profile/profile.js';
|
|
9
9
|
import { isRecord, readJson } from '../../lib/fs/json-file.js';
|
|
10
|
-
import { messageOf } from '../../lib/json-output.js';
|
|
10
|
+
import { CliError, messageOf } from '../../lib/json-output.js';
|
|
11
11
|
import {} from '../../lib/net/market.js';
|
|
12
12
|
import { npmFallbackLine, noSiteMarket } from '../../lib/net/market-error.js';
|
|
13
13
|
import { siteFqdn } from '../../lib/net/origins.js';
|
|
@@ -19,7 +19,9 @@ const marketDown = (id, why) => installError(why.code.toUpperCase(), 502, `${id}
|
|
|
19
19
|
const npmName = (id, down) => noSiteMarket(down) ? (installedName(id) ?? id) : `@agentage/extension-${id}`;
|
|
20
20
|
// The market names the package and its newest version; without it npm alone decides.
|
|
21
21
|
const inputOf = async (id, version, market) => {
|
|
22
|
-
const latest = await market.latest(id)
|
|
22
|
+
const latest = await market.latest(id).catch((err) => {
|
|
23
|
+
throw err instanceof CliError ? marketDown(id, err) : err;
|
|
24
|
+
});
|
|
23
25
|
if (latest?.package === null)
|
|
24
26
|
throw installError('PRIVATE_ENTRY', 400, `${id}: private entry, no npm package to install`);
|
|
25
27
|
if (latest)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HostRow } from '../../lib/daemon/host-client.js';
|
|
2
2
|
import { WithMeta } from '../../lib/json-output.js';
|
|
3
|
-
import { type
|
|
3
|
+
import { type Market, type MarketListing } from '../../lib/net/market.js';
|
|
4
4
|
import { type LifecycleDeps } from './lifecycle.js';
|
|
5
5
|
export interface ListOptions {
|
|
6
6
|
available?: boolean;
|
|
@@ -12,7 +12,7 @@ export interface ExtensionUpdateOptions {
|
|
|
12
12
|
json?: boolean;
|
|
13
13
|
}
|
|
14
14
|
export interface ListDeps extends LifecycleDeps {
|
|
15
|
-
available: () => Promise<
|
|
15
|
+
available: () => Promise<MarketListing>;
|
|
16
16
|
market: () => Market;
|
|
17
17
|
npmNewest: (id: string) => Promise<string>;
|
|
18
18
|
}
|
|
@@ -20,9 +20,13 @@ const printRows = (rows) => {
|
|
|
20
20
|
for (const line of rows.length > 0 ? lines : ['no extensions'])
|
|
21
21
|
console.log(line);
|
|
22
22
|
};
|
|
23
|
-
// A
|
|
23
|
+
// A silent market is one stderr line and an empty list (exit 0), never a failed command.
|
|
24
24
|
const available = async (deps) => {
|
|
25
|
-
const { offered, skipped } = await deps.available();
|
|
25
|
+
const { offered, skipped, down } = await deps.available();
|
|
26
|
+
if (down) {
|
|
27
|
+
console.error(down.message);
|
|
28
|
+
return new WithMeta([], { skipped, down: { code: down.code, message: down.message } });
|
|
29
|
+
}
|
|
26
30
|
const lines = table([['ID', 'VERSION'], ...offered.map((o) => [o.id, o.version])]);
|
|
27
31
|
for (const line of offered.length > 0 ? lines : ['the market lists nothing'])
|
|
28
32
|
console.log(line);
|
package/dist/lib/net/fetch.d.ts
CHANGED
|
@@ -7,4 +7,5 @@ export interface CliFetchOptions {
|
|
|
7
7
|
timeoutMs?: number;
|
|
8
8
|
}
|
|
9
9
|
export declare const cliFetch: (url: string, init?: CliRequestInit, opts?: CliFetchOptions) => Promise<Response>;
|
|
10
|
+
export declare const headedFetch: typeof fetch;
|
|
10
11
|
export declare const isRedirect: (res: Response) => boolean;
|
package/dist/lib/net/fetch.js
CHANGED
|
@@ -10,4 +10,11 @@ export const cliFetch = (url, init = {}, opts = {}) => baseFetch(url, {
|
|
|
10
10
|
redirect: 'manual',
|
|
11
11
|
signal: AbortSignal.timeout(opts.timeoutMs ?? DEFAULT_TIMEOUT_MS),
|
|
12
12
|
});
|
|
13
|
+
// The core client sets its own signal and redirect; this adds only the cli headers.
|
|
14
|
+
export const headedFetch = (input, init) => {
|
|
15
|
+
const headers = new Headers(init?.headers);
|
|
16
|
+
for (const [name, value] of Object.entries(requestHeaders()))
|
|
17
|
+
headers.set(name, value);
|
|
18
|
+
return baseFetch(input, { ...init, headers });
|
|
19
|
+
};
|
|
13
20
|
export const isRedirect = (res) => res.type === 'opaqueredirect' || (res.status >= 300 && res.status < 400);
|
|
@@ -7,6 +7,5 @@ export declare const npmFallbackLine: (fqdn: string, id: string, what: string, d
|
|
|
7
7
|
export declare const noDiscovery: (fqdn: string, url: string, why: string) => CliError;
|
|
8
8
|
export declare const noMarket: (fqdn: string, url: string) => CliError;
|
|
9
9
|
export declare const notTheDocument: (url: string, why: string) => CliError;
|
|
10
|
-
export declare const isTimeout: (err: unknown) => boolean;
|
|
11
10
|
export declare const unreached: (url: string, err: unknown, timeoutMs: number) => CliError;
|
|
12
11
|
export declare const answered: (url: string, status: number, why?: string) => CliError;
|
|
@@ -17,7 +17,7 @@ export const noDiscovery = (fqdn, url, why) => marketError('no_discovery', `${fq
|
|
|
17
17
|
export const noMarket = (fqdn, url) => marketError('no_market', `${fqdn} has no extension market: ${url} names none; ${CHOOSE}`);
|
|
18
18
|
// An answer, but not the discovery document: the network, not the site, may be the cause.
|
|
19
19
|
export const notTheDocument = (url, why) => marketError('market_unreachable', `${url} ${why}: not the discovery document; check the network`);
|
|
20
|
-
|
|
20
|
+
const isTimeout = (err) => err instanceof Error && (err.name === 'TimeoutError' || err.name === 'AbortError');
|
|
21
21
|
// A fetch that threw: no answer in time, or no connection (the cause names why).
|
|
22
22
|
export const unreached = (url, err, timeoutMs) => {
|
|
23
23
|
if (isTimeout(err))
|
package/dist/lib/net/market.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { CoreReason, Fetch, Listing } from '@agentage/extension/core';
|
|
1
2
|
import { CliError } from '../json-output.js';
|
|
3
|
+
export type { Listing, Offered, Skipped } from '@agentage/extension/core';
|
|
2
4
|
type Get = (url: string) => Promise<Response>;
|
|
3
5
|
export interface Latest {
|
|
4
6
|
version: string;
|
|
@@ -8,19 +10,14 @@ export interface Market {
|
|
|
8
10
|
latest: (id: string) => Promise<Latest | null>;
|
|
9
11
|
down: () => CliError | null;
|
|
10
12
|
}
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
id: string;
|
|
14
|
-
version: string;
|
|
15
|
-
}
|
|
16
|
-
export declare const MAX_PAGES = 20;
|
|
17
|
-
export interface Skipped {
|
|
18
|
-
id: string;
|
|
19
|
-
reason: string;
|
|
13
|
+
export interface MarketListing extends Listing {
|
|
14
|
+
down: CliError | null;
|
|
20
15
|
}
|
|
21
|
-
export interface
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
export interface MarketDeps {
|
|
17
|
+
get: Get;
|
|
18
|
+
fetch: Fetch;
|
|
19
|
+
timeoutMs: number;
|
|
24
20
|
}
|
|
25
|
-
export declare const
|
|
26
|
-
export
|
|
21
|
+
export declare const marketDownError: (down: CoreReason) => CliError;
|
|
22
|
+
export declare const openMarket: (fqdn?: string, deps?: Partial<MarketDeps>) => Market;
|
|
23
|
+
export declare const listMarket: (fqdn?: string, deps?: Partial<MarketDeps>) => Promise<MarketListing>;
|
package/dist/lib/net/market.js
CHANGED
|
@@ -1,37 +1,16 @@
|
|
|
1
1
|
import { isRecord } from '../fs/json-file.js';
|
|
2
|
-
import { CliError
|
|
3
|
-
import { cliFetch } from './fetch.js';
|
|
4
|
-
import { answered,
|
|
2
|
+
import { CliError } from '../json-output.js';
|
|
3
|
+
import { cliFetch, headedFetch } from './fetch.js';
|
|
4
|
+
import { answered, marketError, noSiteMarket, noDiscovery, noMarket, notTheDocument, unreached, } from './market-error.js';
|
|
5
5
|
import { links, siteFqdn } from './origins.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const timed = (url) => cliFetch(url, {}, { timeoutMs:
|
|
6
|
+
const DISCOVERY_TIMEOUT_MS = 5_000;
|
|
7
|
+
// An install or a list in a terminal: the client's 2 s default suits a page, not npm work.
|
|
8
|
+
const MARKET_TIMEOUT_MS = 10_000;
|
|
9
|
+
const timed = (url) => cliFetch(url, {}, { timeoutMs: DISCOVERY_TIMEOUT_MS });
|
|
10
|
+
const DEFAULTS = { get: timed, fetch: headedFetch, timeoutMs: MARKET_TIMEOUT_MS };
|
|
10
11
|
const fetched = (get, url) => get(url).catch((err) => {
|
|
11
|
-
throw unreached(url, err,
|
|
12
|
+
throw unreached(url, err, DISCOVERY_TIMEOUT_MS);
|
|
12
13
|
});
|
|
13
|
-
const bodyOf = (res, url) => res.json().catch((err) => {
|
|
14
|
-
throw isTimeout(err) ? unreached(url, err, TIMEOUT_MS) : answered(url, res.status, 'no JSON');
|
|
15
|
-
});
|
|
16
|
-
// Every market answers 404 NOT_FOUND for an unknown id and for a route it lacks alike.
|
|
17
|
-
const anyNotFound = (res) => Promise.resolve(res.status === 404);
|
|
18
|
-
// `/api/market/extensions` (one-image host) first, else the v13 `/api/v1/extensions`.
|
|
19
|
-
const json = async (get, origin, path) => {
|
|
20
|
-
const bases = {
|
|
21
|
-
primary: `${origin}/api/market/extensions`,
|
|
22
|
-
fallback: `${origin}/api/v1/extensions`,
|
|
23
|
-
};
|
|
24
|
-
const at = { url: '' };
|
|
25
|
-
const call = (url) => fetched(get, (at.url = url));
|
|
26
|
-
const res = await routeCall(bases, path, call, anyNotFound);
|
|
27
|
-
const url = at.url;
|
|
28
|
-
if (res.status === 404)
|
|
29
|
-
return null;
|
|
30
|
-
if (!res.ok)
|
|
31
|
-
throw answered(url, res.status);
|
|
32
|
-
const body = await bodyOf(res, url);
|
|
33
|
-
return isRecord(body) ? body : null;
|
|
34
|
-
};
|
|
35
14
|
// Only the site's own 404 means it has none. A redirect or a page that is no JSON object (a
|
|
36
15
|
// network's sign-in page) is not the site's answer; another status is a failure.
|
|
37
16
|
const discovery = async (fqdn, get) => {
|
|
@@ -61,81 +40,46 @@ const marketUrl = async (fqdn, get) => {
|
|
|
61
40
|
throw noMarket(fqdn, `${site}/.well-known/agentage.json`);
|
|
62
41
|
return url.origin;
|
|
63
42
|
};
|
|
64
|
-
//
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
43
|
+
// The client calls url() on each call: one discovery read for each client.
|
|
44
|
+
const once = (make) => {
|
|
45
|
+
let made;
|
|
46
|
+
return () => (made ??= make());
|
|
47
|
+
};
|
|
48
|
+
const CODES = { unreachable: 'market_unreachable', timeout: 'market_timeout' };
|
|
49
|
+
const textOf = (down) => down.detail.startsWith(down.message) ? down.detail : `${down.message}: ${down.detail}`;
|
|
50
|
+
// The client's reason as the cli's error; a site with no market (the npm fallback) stays itself.
|
|
51
|
+
export const marketDownError = (down) => {
|
|
52
|
+
const { cause } = down;
|
|
53
|
+
if (cause instanceof CliError)
|
|
54
|
+
return noSiteMarket(cause)
|
|
55
|
+
? cause
|
|
56
|
+
: marketError(cause.code, `${down.message}: ${cause.message}`);
|
|
57
|
+
const code = down.code === 'unreachable' || down.code === 'timeout' ? CODES[down.code] : null;
|
|
58
|
+
return marketError(code ?? 'market_failed', textOf(down));
|
|
59
|
+
};
|
|
60
|
+
// Loaded on the first market call: a cold start never loads the kit's logs client.
|
|
61
|
+
const clientOf = async (fqdn, deps) => {
|
|
62
|
+
const { coreUrlOf, createCoreClient } = await import('@agentage/extension/core');
|
|
63
|
+
// The core address of the env wins; else the market the site's discovery names.
|
|
64
|
+
const url = coreUrlOf(process.env) ?? once(() => marketUrl(fqdn, deps.get));
|
|
65
|
+
return createCoreClient({ url, timeoutMs: deps.timeoutMs, fetch: deps.fetch });
|
|
72
66
|
};
|
|
73
|
-
//
|
|
74
|
-
export const openMarket = (fqdn = siteFqdn(),
|
|
75
|
-
|
|
67
|
+
// Null for a silent market (`down` keeps the first reason); a refused answer throws, never installed.
|
|
68
|
+
export const openMarket = (fqdn = siteFqdn(), deps = {}) => {
|
|
69
|
+
const client = once(() => clientOf(fqdn, { ...DEFAULTS, ...deps }));
|
|
76
70
|
let failure = null;
|
|
77
71
|
const latest = async (id) => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
85
|
-
failure ??= err instanceof CliError ? err : marketError('market_failed', messageOf(err));
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
return isRecord(data) ? accept(id, data) : null;
|
|
72
|
+
const { data, down } = await (await client()).market.latest(id);
|
|
73
|
+
if (down?.code === 'refused')
|
|
74
|
+
throw marketError('market_failed', textOf(down));
|
|
75
|
+
if (down)
|
|
76
|
+
failure ??= marketDownError(down);
|
|
77
|
+
return data && { version: data.version, package: data.package };
|
|
89
78
|
};
|
|
90
79
|
return { latest, down: () => failure };
|
|
91
80
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
export const MAX_PAGES = 20;
|
|
97
|
-
// Every row of the market list, page after page while `meta.nextCursor` names one.
|
|
98
|
-
const pages = async (get, base, cursor, page = 1) => {
|
|
99
|
-
if (page > MAX_PAGES)
|
|
100
|
-
throw marketError('market_failed', `the market list has more than ${MAX_PAGES} pages of ${PAGE}; stopped there`);
|
|
101
|
-
const query = `?limit=${PAGE}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ''}`;
|
|
102
|
-
const body = await json(get, base, query);
|
|
103
|
-
const data = Array.isArray(body?.['data']) ? body['data'] : [];
|
|
104
|
-
const meta = body?.['meta'];
|
|
105
|
-
const next = isRecord(meta) && typeof meta['nextCursor'] === 'string' ? meta['nextCursor'] : '';
|
|
106
|
-
return next && data.length > 0 ? [...data, ...(await pages(get, base, next, page + 1))] : data;
|
|
107
|
-
};
|
|
108
|
-
// A row without an exact version (the market of today lists none) asks /latest for it.
|
|
109
|
-
const offered = async (row, market) => {
|
|
110
|
-
if (!isRecord(row) || typeof row['id'] !== 'string')
|
|
111
|
-
return null;
|
|
112
|
-
const id = row['id'];
|
|
113
|
-
if (typeof row['version'] === 'string' && EXACT.test(row['version']))
|
|
114
|
-
return { id, version: row['version'] };
|
|
115
|
-
try {
|
|
116
|
-
const version = (await market.latest(id))?.version;
|
|
117
|
-
const down = market.down();
|
|
118
|
-
if (down)
|
|
119
|
-
return { id, reason: down.message };
|
|
120
|
-
return version ? { id, version } : { id, reason: 'the market has no version of it' };
|
|
121
|
-
}
|
|
122
|
-
catch (err) {
|
|
123
|
-
return { id, reason: messageOf(err) };
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
// `extension list --available`: each listed id with its newest version. Only a failed list call
|
|
127
|
-
// fails it; a row that cannot be read is skipped with its reason.
|
|
128
|
-
export const listMarket = async (fqdn = siteFqdn(), get = timed) => {
|
|
129
|
-
const base = await marketUrl(fqdn, get);
|
|
130
|
-
const rows = await pages(get, base);
|
|
131
|
-
const found = [];
|
|
132
|
-
for (let i = 0; i < rows.length; i += AT_ONCE) {
|
|
133
|
-
const batch = rows.slice(i, i + AT_ONCE);
|
|
134
|
-
found.push(...(await Promise.all(batch.map((r) => offered(r, openMarket(fqdn, get, base))))));
|
|
135
|
-
}
|
|
136
|
-
const listing = { offered: [], skipped: [] };
|
|
137
|
-
for (const row of found)
|
|
138
|
-
if (row)
|
|
139
|
-
'version' in row ? listing.offered.push(row) : listing.skipped.push(row);
|
|
140
|
-
return listing;
|
|
81
|
+
// `extension list --available`: each listed id with its newest version, or why there is none.
|
|
82
|
+
export const listMarket = async (fqdn = siteFqdn(), deps = {}) => {
|
|
83
|
+
const { data, down } = await (await clientOf(fqdn, { ...DEFAULTS, ...deps })).market.list();
|
|
84
|
+
return { ...data, down: down && marketDownError(down) };
|
|
141
85
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentage/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.66.0",
|
|
4
4
|
"description": "The agentage CLI - connect this machine to agentage from the terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"prepublishOnly": "npm run verify"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@agentage/extension": "0.
|
|
57
|
+
"@agentage/extension": "0.20.0",
|
|
58
58
|
"@electric-sql/pglite": "^0.5.16",
|
|
59
59
|
"@tailwindcss/postcss": "^4.3.5",
|
|
60
60
|
"chalk": "^6.0.0",
|