@0gfoundation/0g-agentdna 0.0.0-stage → 0.2.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/GUIDE.md +975 -0
- package/LICENSE +21 -0
- package/MIGRATION.md +84 -0
- package/MIGRATION.zh.md +70 -0
- package/PROVIDERS.md +273 -0
- package/PROVIDERS.zh.md +234 -0
- package/README.md +334 -2
- package/dist/AgentClient.d.ts +312 -0
- package/dist/AgentClient.d.ts.map +1 -0
- package/dist/AgentClient.js +715 -0
- package/dist/AgentClient.js.map +1 -0
- package/dist/AgenticID.d.ts +823 -0
- package/dist/AgenticID.d.ts.map +1 -0
- package/dist/AgenticID.js +1188 -0
- package/dist/AgenticID.js.map +1 -0
- package/dist/AgenticIDClient.d.ts +68 -0
- package/dist/AgenticIDClient.d.ts.map +1 -0
- package/dist/AgenticIDClient.js +198 -0
- package/dist/AgenticIDClient.js.map +1 -0
- package/dist/AttestorClient.d.ts +465 -0
- package/dist/AttestorClient.d.ts.map +1 -0
- package/dist/AttestorClient.js +1030 -0
- package/dist/AttestorClient.js.map +1 -0
- package/dist/Providers.d.ts +72 -0
- package/dist/Providers.d.ts.map +1 -0
- package/dist/Providers.js +182 -0
- package/dist/Providers.js.map +1 -0
- package/dist/ReputationClient.d.ts +213 -0
- package/dist/ReputationClient.d.ts.map +1 -0
- package/dist/ReputationClient.js +708 -0
- package/dist/ReputationClient.js.map +1 -0
- package/dist/SandboxClient.d.ts +107 -0
- package/dist/SandboxClient.d.ts.map +1 -0
- package/dist/SandboxClient.js +200 -0
- package/dist/SandboxClient.js.map +1 -0
- package/dist/ServeProof.d.ts +161 -0
- package/dist/ServeProof.d.ts.map +1 -0
- package/dist/ServeProof.js +230 -0
- package/dist/ServeProof.js.map +1 -0
- package/dist/ServeSession.d.ts +180 -0
- package/dist/ServeSession.d.ts.map +1 -0
- package/dist/ServeSession.js +336 -0
- package/dist/ServeSession.js.map +1 -0
- package/dist/Settings.d.ts +179 -0
- package/dist/Settings.d.ts.map +1 -0
- package/dist/Settings.js +247 -0
- package/dist/Settings.js.map +1 -0
- package/dist/abi.d.ts +2216 -0
- package/dist/abi.d.ts.map +1 -0
- package/dist/abi.js +1248 -0
- package/dist/abi.js.map +1 -0
- package/dist/cli/commands/cells.d.ts +34 -0
- package/dist/cli/commands/cells.d.ts.map +1 -0
- package/dist/cli/commands/cells.js +66 -0
- package/dist/cli/commands/cells.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +15 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +236 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/interactive.d.ts +107 -0
- package/dist/cli/commands/interactive.d.ts.map +1 -0
- package/dist/cli/commands/interactive.js +3034 -0
- package/dist/cli/commands/interactive.js.map +1 -0
- package/dist/cli/commands/list.d.ts +31 -0
- package/dist/cli/commands/list.d.ts.map +1 -0
- package/dist/cli/commands/list.js +115 -0
- package/dist/cli/commands/list.js.map +1 -0
- package/dist/cli/commands/providers.d.ts +3 -0
- package/dist/cli/commands/providers.d.ts.map +1 -0
- package/dist/cli/commands/providers.js +21 -0
- package/dist/cli/commands/providers.js.map +1 -0
- package/dist/cli/commands/settings.d.ts +22 -0
- package/dist/cli/commands/settings.d.ts.map +1 -0
- package/dist/cli/commands/settings.js +188 -0
- package/dist/cli/commands/settings.js.map +1 -0
- package/dist/cli/commands/status.d.ts +16 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +148 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/update.d.ts +21 -0
- package/dist/cli/commands/update.d.ts.map +1 -0
- package/dist/cli/commands/update.js +95 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/config.d.ts +73 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +239 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/env.d.ts +36 -0
- package/dist/cli/env.d.ts.map +1 -0
- package/dist/cli/env.js +74 -0
- package/dist/cli/env.js.map +1 -0
- package/dist/cli/envelope.d.ts +33 -0
- package/dist/cli/envelope.d.ts.map +1 -0
- package/dist/cli/envelope.js +62 -0
- package/dist/cli/envelope.js.map +1 -0
- package/dist/cli/errors.d.ts +48 -0
- package/dist/cli/errors.d.ts.map +1 -0
- package/dist/cli/errors.js +81 -0
- package/dist/cli/errors.js.map +1 -0
- package/dist/cli/inference.d.ts +21 -0
- package/dist/cli/inference.d.ts.map +1 -0
- package/dist/cli/inference.js +60 -0
- package/dist/cli/inference.js.map +1 -0
- package/dist/cli/logo.d.ts +21 -0
- package/dist/cli/logo.d.ts.map +1 -0
- package/dist/cli/logo.js +131 -0
- package/dist/cli/logo.js.map +1 -0
- package/dist/cli/main.d.ts +14 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +223 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/proofs.d.ts +67 -0
- package/dist/cli/proofs.d.ts.map +1 -0
- package/dist/cli/proofs.js +133 -0
- package/dist/cli/proofs.js.map +1 -0
- package/dist/cli/ref.d.ts +39 -0
- package/dist/cli/ref.d.ts.map +1 -0
- package/dist/cli/ref.js +48 -0
- package/dist/cli/ref.js.map +1 -0
- package/dist/cli/sdk.d.ts +24 -0
- package/dist/cli/sdk.d.ts.map +1 -0
- package/dist/cli/sdk.js +65 -0
- package/dist/cli/sdk.js.map +1 -0
- package/dist/cli/settings.d.ts +66 -0
- package/dist/cli/settings.d.ts.map +1 -0
- package/dist/cli/settings.js +137 -0
- package/dist/cli/settings.js.map +1 -0
- package/dist/cli/tokenize.d.ts +61 -0
- package/dist/cli/tokenize.d.ts.map +1 -0
- package/dist/cli/tokenize.js +157 -0
- package/dist/cli/tokenize.js.map +1 -0
- package/dist/cli/types.d.ts +25 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +8 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/constants.d.ts +107 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +74 -0
- package/dist/constants.js.map +1 -0
- package/dist/context.d.ts +108 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +64 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -0
- package/dist/provider-catalog.json +23 -0
- package/dist/seal.d.ts +47 -0
- package/dist/seal.d.ts.map +1 -0
- package/dist/seal.js +145 -0
- package/dist/seal.js.map +1 -0
- package/dist/secretEnv.d.ts +119 -0
- package/dist/secretEnv.d.ts.map +1 -0
- package/dist/secretEnv.js +199 -0
- package/dist/secretEnv.js.map +1 -0
- package/dist/taskHash.d.ts +39 -0
- package/dist/taskHash.d.ts.map +1 -0
- package/dist/taskHash.js +119 -0
- package/dist/taskHash.js.map +1 -0
- package/dist/types.d.ts +336 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/package.json +75 -4
- package/scripts/sync-providers.cjs +8 -0
- package/src/AgentClient.ts +897 -0
- package/src/AgenticID.ts +1382 -0
- package/src/AgenticIDClient.ts +238 -0
- package/src/AttestorClient.ts +1306 -0
- package/src/Providers.ts +176 -0
- package/src/ReputationClient.ts +821 -0
- package/src/SandboxClient.ts +227 -0
- package/src/ServeProof.ts +290 -0
- package/src/ServeSession.ts +421 -0
- package/src/Settings.ts +296 -0
- package/src/abi.ts +1282 -0
- package/src/cli/commands/cells.ts +61 -0
- package/src/cli/commands/doctor.ts +235 -0
- package/src/cli/commands/interactive.ts +2715 -0
- package/src/cli/commands/list.ts +117 -0
- package/src/cli/commands/providers.ts +16 -0
- package/src/cli/commands/settings.ts +197 -0
- package/src/cli/commands/status.ts +170 -0
- package/src/cli/commands/update.ts +86 -0
- package/src/cli/config.ts +225 -0
- package/src/cli/env.ts +90 -0
- package/src/cli/envelope.ts +57 -0
- package/src/cli/errors.ts +114 -0
- package/src/cli/inference.ts +57 -0
- package/src/cli/logo.ts +125 -0
- package/src/cli/main.ts +235 -0
- package/src/cli/proofs.ts +160 -0
- package/src/cli/ref.ts +58 -0
- package/src/cli/sdk.ts +65 -0
- package/src/cli/settings.ts +153 -0
- package/src/cli/tokenize.ts +131 -0
- package/src/cli/types.ts +27 -0
- package/src/constants.ts +106 -0
- package/src/context.ts +161 -0
- package/src/index.ts +129 -0
- package/src/provider-catalog.json +23 -0
- package/src/seal.ts +163 -0
- package/src/secretEnv.ts +250 -0
- package/src/taskHash.ts +100 -0
- package/src/types.ts +357 -0
package/dist/Settings.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SettingsConflictError = exports.SETTINGS_FIELDS = exports.ZG_COMPUTE_PROVIDER = exports.ROUTER_MODELS_URL = exports.SETTINGS_DOMAIN = exports.THINKING_LEVELS = void 0;
|
|
4
|
+
exports.canonicalSettings = canonicalSettings;
|
|
5
|
+
exports.sha256Hex = sha256Hex;
|
|
6
|
+
exports.settingsAuthMessage = settingsAuthMessage;
|
|
7
|
+
exports.modelAdvisory = modelAdvisory;
|
|
8
|
+
exports.fetchRouterModelIds = fetchRouterModelIds;
|
|
9
|
+
const Providers_1 = require("./Providers");
|
|
10
|
+
/**
|
|
11
|
+
* @file Settings.ts
|
|
12
|
+
* @description The owner's configuration document — the one blob that says
|
|
13
|
+
* which model an agent thinks with, and how hard.
|
|
14
|
+
*
|
|
15
|
+
* Where it lives and who understands it:
|
|
16
|
+
* - the OWNER authors it (this file's {@link SettingsDoc});
|
|
17
|
+
* - the ATTESTOR stores it opaquely: it never parses the contents, never
|
|
18
|
+
* validates them, and gains no knowledge of what a setting means. Its
|
|
19
|
+
* only jobs are store / serve to the container / refuse a write that is
|
|
20
|
+
* not signed by the agent's current on-chain owner;
|
|
21
|
+
* - the CONTAINER (`sealed/internal/settings`) is where all meaning lives
|
|
22
|
+
* and is the real gate.
|
|
23
|
+
*
|
|
24
|
+
* That layering is the point: widening the vocabulary — a new field, a new
|
|
25
|
+
* framework knob — is a container change only. Nothing here or in the
|
|
26
|
+
* attestor has to learn about it. {@link SettingsDoc} therefore mirrors the
|
|
27
|
+
* Go `settings.Doc` exactly, and `others` stays deliberately opaque.
|
|
28
|
+
*
|
|
29
|
+
* It is NOT on chain. Configuration is re-suppliable (an owner re-picks a
|
|
30
|
+
* model in ten seconds); memory is not, and only memory earns chain storage.
|
|
31
|
+
*
|
|
32
|
+
* THE SIGNATURE COVERS A DIGEST, NOT THE DOCUMENT. `POST /settings` carries
|
|
33
|
+
* the signed statement in an HTTP header, which must stay short and ASCII,
|
|
34
|
+
* while the document is large and may be non-ASCII. So the owner signs
|
|
35
|
+
* `AgenticID.Settings.v1:<sealId>:<ts>:<base_version>:<sha256 of the bytes sent>`
|
|
36
|
+
* and the bytes themselves ride the body. For that to mean anything, the
|
|
37
|
+
* digest and the body must come from ONE serialization — see
|
|
38
|
+
* {@link canonicalSettings}, whose output is BOTH hashed and spliced
|
|
39
|
+
* verbatim into the request body.
|
|
40
|
+
*
|
|
41
|
+
* EVERY WRITE IS A COMPARE-AND-SWAP. `base_version` is the version the writer
|
|
42
|
+
* read before editing (0 = "I believe there is no document yet"); the attestor
|
|
43
|
+
* refuses with HTTP 409 when it no longer matches the stored one. Three holes
|
|
44
|
+
* close at once: a captured request cannot be replayed to roll the document
|
|
45
|
+
* back to a superseded one, two clients editing the same agent cannot silently
|
|
46
|
+
* overwrite each other, and a client that never read cannot blind-write over a
|
|
47
|
+
* document it has not seen. {@link SettingsConflictError} is what the SDK
|
|
48
|
+
* raises for that 409 — re-read, re-apply the edit, write again. Never retry
|
|
49
|
+
* the same bytes in a loop: the point of the refusal is that a human decides
|
|
50
|
+
* what survives.
|
|
51
|
+
*
|
|
52
|
+
* READS ARE OWNER-GATED TOO. The document is the owner's, so `GET /settings`
|
|
53
|
+
* carries the same owner signature, minus the digest (there is no body): the
|
|
54
|
+
* message ends at `base_version`, which a reader sends as 0. It is NOT on the
|
|
55
|
+
* public deployment row or in any listing.
|
|
56
|
+
*/
|
|
57
|
+
/** The reasoning-depth vocabulary (Go: `settings.Levels`). */
|
|
58
|
+
exports.THINKING_LEVELS = ['low', 'high', 'max'];
|
|
59
|
+
/** Signed-message domain for `POST /settings`. */
|
|
60
|
+
exports.SETTINGS_DOMAIN = 'AgenticID.Settings.v1';
|
|
61
|
+
/** The 0G router's public model catalog — no auth. */
|
|
62
|
+
exports.ROUTER_MODELS_URL = (0, Providers_1.inferenceProvider)('0g-compute').modelCatalog;
|
|
63
|
+
/** `'0g-compute'` — the provider for which the platform routes the model. */
|
|
64
|
+
exports.ZG_COMPUTE_PROVIDER = '0g-compute';
|
|
65
|
+
/** The fields the PLATFORM names and guarantees, in Go declaration order.
|
|
66
|
+
* Everything else in a document belongs to the container. */
|
|
67
|
+
exports.SETTINGS_FIELDS = ['provider', 'model', 'thinking', 'others'];
|
|
68
|
+
/**
|
|
69
|
+
* THE serialization. Its output is what gets hashed into the signed header
|
|
70
|
+
* AND what is spliced verbatim into the request body, so the two can never
|
|
71
|
+
* disagree — two independent `JSON.stringify` calls would be one refactor
|
|
72
|
+
* away from a bogus "signer mismatch".
|
|
73
|
+
*
|
|
74
|
+
* Field order follows the Go struct's declaration order and empty fields are
|
|
75
|
+
* dropped, matching `encoding/json` + `omitempty`. `others` is passed
|
|
76
|
+
* through as raw JSON — the platform does not interpret it.
|
|
77
|
+
*
|
|
78
|
+
* It is NOT byte-identical to Go's `settings.Doc.Marshal`, and does not have
|
|
79
|
+
* to be: Go's encoder escapes `<`, `>`, `&` (and U+2028/U+2029) by default,
|
|
80
|
+
* where `JSON.stringify` emits them literally — so any document containing
|
|
81
|
+
* one of those serializes differently on the two sides. Nothing rests on the
|
|
82
|
+
* two agreeing byte-for-byte. The digest covers the bytes ACTUALLY SENT, the
|
|
83
|
+
* attestor stores those bytes, and the container parses the document rather
|
|
84
|
+
* than re-hashing it. What must match across the two is the VALUE: same
|
|
85
|
+
* fields, same types, same omissions.
|
|
86
|
+
*/
|
|
87
|
+
function canonicalSettings(doc) {
|
|
88
|
+
const parts = [];
|
|
89
|
+
const put = (key, value) => {
|
|
90
|
+
if (value !== undefined && value !== '')
|
|
91
|
+
parts.push(`"${key}":${JSON.stringify(value)}`);
|
|
92
|
+
};
|
|
93
|
+
put('provider', doc.provider);
|
|
94
|
+
put('model', doc.model);
|
|
95
|
+
put('thinking', doc.thinking);
|
|
96
|
+
// Go's `omitempty` on a json.RawMessage drops only a nil/empty member — an
|
|
97
|
+
// explicit `{}` is content and stays. null/undefined here mean "no section".
|
|
98
|
+
if (doc.others !== undefined && doc.others !== null) {
|
|
99
|
+
const raw = JSON.stringify(doc.others);
|
|
100
|
+
if (raw !== undefined)
|
|
101
|
+
parts.push(`"others":${raw}`);
|
|
102
|
+
}
|
|
103
|
+
// Anything this SDK version has never heard of goes through untouched, in
|
|
104
|
+
// its own order. The container owns the vocabulary, so a field newer than
|
|
105
|
+
// this build is legitimate — and a read-modify-write that dropped it would
|
|
106
|
+
// let an old client silently erase a new setting, which is exactly the loss
|
|
107
|
+
// the "widening the vocabulary never touches the platform" design forbids.
|
|
108
|
+
for (const [key, value] of Object.entries(doc)) {
|
|
109
|
+
if (exports.SETTINGS_FIELDS.includes(key) || value === undefined)
|
|
110
|
+
continue;
|
|
111
|
+
const raw = JSON.stringify(value);
|
|
112
|
+
if (raw !== undefined)
|
|
113
|
+
parts.push(`${JSON.stringify(key)}:${raw}`);
|
|
114
|
+
}
|
|
115
|
+
return `{${parts.join(',')}}`;
|
|
116
|
+
}
|
|
117
|
+
/** WebCrypto, wherever we are: browsers and Node >= 19 expose it globally;
|
|
118
|
+
* Node 18 (the `engines` floor) needs the node:crypto fallback. */
|
|
119
|
+
function subtleCrypto() {
|
|
120
|
+
let c = globalThis.crypto;
|
|
121
|
+
if (!c?.subtle && typeof require === 'function') {
|
|
122
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
123
|
+
c = require('crypto').webcrypto;
|
|
124
|
+
}
|
|
125
|
+
if (!c?.subtle) {
|
|
126
|
+
throw new Error('Settings: no WebCrypto SubtleCrypto available (need a browser or Node >= 18)');
|
|
127
|
+
}
|
|
128
|
+
return c.subtle;
|
|
129
|
+
}
|
|
130
|
+
/** sha256 of a string's UTF-8 bytes, lowercase hex, no `0x`. */
|
|
131
|
+
async function sha256Hex(s) {
|
|
132
|
+
const digest = await subtleCrypto().digest('SHA-256', new TextEncoder().encode(s));
|
|
133
|
+
return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, '0')).join('');
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The exact statement the owner signs. ASCII and short by construction — it
|
|
137
|
+
* travels in `X-Auth-Message`. Two forms, one grammar:
|
|
138
|
+
*
|
|
139
|
+
* write `AgenticID.Settings.v1:0x<sealId>:<unix seconds>:<base_version>:<sha256-hex>`
|
|
140
|
+
* read `AgenticID.Settings.v1:0x<sealId>:<unix seconds>:<base_version>`
|
|
141
|
+
*
|
|
142
|
+
* `baseVersion` is the version the writer read before editing — the
|
|
143
|
+
* compare-and-swap term. A read has no body and therefore no digest, and
|
|
144
|
+
* nothing to swap against, so it ends at `baseVersion` and sends 0.
|
|
145
|
+
*/
|
|
146
|
+
function settingsAuthMessage(sealId, unixSeconds, baseVersion, digestHex) {
|
|
147
|
+
const head = `${exports.SETTINGS_DOMAIN}:${sealId.toLowerCase()}:${unixSeconds}:${baseVersion}`;
|
|
148
|
+
return digestHex === undefined ? head : `${head}:${digestHex}`;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A write whose `base_version` no longer matches what the attestor holds
|
|
152
|
+
* (HTTP 409): somebody else changed the document between the read and the
|
|
153
|
+
* write, or the request is a replay of a superseded one.
|
|
154
|
+
*
|
|
155
|
+
* The SDK re-reads before throwing, so {@link current} / {@link currentVersion}
|
|
156
|
+
* are the live document — enough for a caller to show what it would have
|
|
157
|
+
* overwritten. It deliberately does NOT retry: re-applying the same edit
|
|
158
|
+
* blindly is how the other writer's change disappears, which is the whole
|
|
159
|
+
* thing the version guard exists to prevent. Re-apply the edit onto
|
|
160
|
+
* {@link current} and write again against {@link currentVersion} — as a human
|
|
161
|
+
* decision, not a loop.
|
|
162
|
+
*/
|
|
163
|
+
class SettingsConflictError extends Error {
|
|
164
|
+
constructor(args) {
|
|
165
|
+
super(`settings: version conflict on ${args.sealId} — you edited version ${args.baseVersion}, ` +
|
|
166
|
+
`the attestor now holds version ${args.currentVersion}. ` +
|
|
167
|
+
'Someone else changed this agent\'s configuration; re-read it, re-apply your change, and write again.' +
|
|
168
|
+
(args.detail ? ` (${args.detail})` : ''));
|
|
169
|
+
this.name = 'SettingsConflictError';
|
|
170
|
+
this.sealId = args.sealId;
|
|
171
|
+
this.baseVersion = args.baseVersion;
|
|
172
|
+
this.currentVersion = args.currentVersion;
|
|
173
|
+
this.current = args.current;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.SettingsConflictError = SettingsConflictError;
|
|
177
|
+
/**
|
|
178
|
+
* The advisory model check: is `model` in the 0G router's public catalog?
|
|
179
|
+
*
|
|
180
|
+
* ADVISORY ONLY, in both directions. A framework built-in
|
|
181
|
+
* (`anthropic/claude-…`) is legitimately absent from a catalog that covers
|
|
182
|
+
* the 0G router alone, and the container is the real gate — so an absence is
|
|
183
|
+
* a warning, never a refusal. An unreachable catalog produces no warning at
|
|
184
|
+
* all rather than a false one.
|
|
185
|
+
*
|
|
186
|
+
* Never throws.
|
|
187
|
+
*
|
|
188
|
+
* @returns human-readable warnings; empty when everything looked fine, the
|
|
189
|
+
* catalog was unreachable, or there was nothing to check.
|
|
190
|
+
*/
|
|
191
|
+
async function modelAdvisory(doc, resolvedProvider) {
|
|
192
|
+
const model = doc.model?.trim();
|
|
193
|
+
if (!model)
|
|
194
|
+
return [];
|
|
195
|
+
const provider = doc.provider?.trim() || exports.ZG_COMPUTE_PROVIDER;
|
|
196
|
+
const definition = resolvedProvider ?? (0, Providers_1.inferenceProvider)(provider);
|
|
197
|
+
if (!definition.modelCatalog && !definition.models?.length)
|
|
198
|
+
return [];
|
|
199
|
+
let ids;
|
|
200
|
+
try {
|
|
201
|
+
ids = (await (0, Providers_1.modelsForProvider)(definition)).map((model) => model.id);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
ids = null;
|
|
205
|
+
}
|
|
206
|
+
if (!ids)
|
|
207
|
+
return []; // catalog unreachable — say nothing rather than something wrong
|
|
208
|
+
if (ids.some((id) => id.toLowerCase() === model.toLowerCase()))
|
|
209
|
+
return [];
|
|
210
|
+
// Typo help, cheap and predictable: a substring either way, or a shared
|
|
211
|
+
// prefix long enough to be a family rather than a coincidence
|
|
212
|
+
// ("glm-4.7" → "glm-4.6"; "claude-opus-4" → nothing).
|
|
213
|
+
const needle = model.toLowerCase().split('/').pop() ?? model.toLowerCase();
|
|
214
|
+
const shared = (a, b) => {
|
|
215
|
+
let i = 0;
|
|
216
|
+
while (i < a.length && i < b.length && a[i] === b[i])
|
|
217
|
+
i++;
|
|
218
|
+
return i;
|
|
219
|
+
};
|
|
220
|
+
const near = ids
|
|
221
|
+
.filter((id) => {
|
|
222
|
+
const lid = id.toLowerCase();
|
|
223
|
+
return lid.includes(needle) || needle.includes(lid) || shared(lid, needle) >= 4;
|
|
224
|
+
})
|
|
225
|
+
.slice(0, 3);
|
|
226
|
+
// provider '0g-compute' = the platform routes this model, so the router
|
|
227
|
+
// catalog IS authoritative there; any other provider is a framework
|
|
228
|
+
// built-in whose models the catalog never lists.
|
|
229
|
+
const routed = !!doc.provider?.trim() && !definition.native;
|
|
230
|
+
return [
|
|
231
|
+
`model "${model}" is not in the ${provider === exports.ZG_COMPUTE_PROVIDER ? '0G router' : provider} catalog` +
|
|
232
|
+
(routed
|
|
233
|
+
? ` — and provider "${provider}" means the platform routes it there, so this one probably will not resolve.`
|
|
234
|
+
: ' — expected for a framework built-in; the container decides.') +
|
|
235
|
+
(near.length ? ` Close matches: ${near.join(', ')}.` : ''),
|
|
236
|
+
];
|
|
237
|
+
}
|
|
238
|
+
/** The router catalog's model ids, or null when it could not be read. */
|
|
239
|
+
async function fetchRouterModelIds(provider = exports.ZG_COMPUTE_PROVIDER) {
|
|
240
|
+
try {
|
|
241
|
+
return (await (0, Providers_1.inferenceModels)(provider)).map((model) => model.id);
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=Settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Settings.js","sourceRoot":"","sources":["../src/Settings.ts"],"names":[],"mappings":";;;AA0HA,8CAyBC;AAsBD,8BAGC;AAaD,kDAQC;AA4DD,sCAoCC;AAGD,kDAGC;AAvSD,2CAA4G;AAC5G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,8DAA8D;AACjD,QAAA,eAAe,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAU,CAAC;AAG/D,kDAAkD;AACrC,QAAA,eAAe,GAAG,uBAAuB,CAAC;AAEvD,sDAAsD;AACzC,QAAA,iBAAiB,GAAG,IAAA,6BAAiB,EAAC,YAAY,CAAC,CAAC,YAAa,CAAC;AAuC/E,6EAA6E;AAChE,QAAA,mBAAmB,GAAG,YAAY,CAAC;AAEhD;8DAC8D;AACjD,QAAA,eAAe,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAU,CAAC;AAEpF;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,iBAAiB,CAAC,GAAgB;IAChD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,CAAC,GAAW,EAAE,KAAyB,EAAQ,EAAE;QAC3D,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,K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