agent-customs 0.0.0-stage → 1.0.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.
Files changed (48) hide show
  1. package/LICENSE.md +341 -0
  2. package/README.md +592 -2
  3. package/bin/agent-customs.mjs +194 -0
  4. package/package.json +77 -4
  5. package/site/.well-known/agent-customs-key.json +13 -0
  6. package/site/certificate.js +944 -0
  7. package/site/customs/analyze.js +1224 -0
  8. package/site/customs/auto.js +44 -0
  9. package/site/customs/canary.js +270 -0
  10. package/site/customs/canonical.js +123 -0
  11. package/site/customs/capabilities.js +387 -0
  12. package/site/customs/diff.js +236 -0
  13. package/site/customs/english-words.js +153 -0
  14. package/site/customs/guard-notice.js +226 -0
  15. package/site/customs/guard-ui.js +105 -0
  16. package/site/customs/guard.js +259 -0
  17. package/site/customs/inspect.js +446 -0
  18. package/site/customs/judge.js +208 -0
  19. package/site/customs/languages.js +826 -0
  20. package/site/customs/locks.js +967 -0
  21. package/site/customs/pins.js +119 -0
  22. package/site/customs/protocols.js +621 -0
  23. package/site/customs/receipts.js +154 -0
  24. package/site/customs/rules.js +1470 -0
  25. package/site/customs/unicode.js +361 -0
  26. package/site/runtime/LICENSE.txt +176 -0
  27. package/site/runtime/generated/graph.gen.mjs +83 -0
  28. package/site/runtime/generated/validation.gen.mjs +70 -0
  29. package/site/runtime/hocon.js +262 -0
  30. package/site/runtime/kernel.js +237 -0
  31. package/site/runtime/model.js +44 -0
  32. package/tests/fixtures/official/NOTICE +3 -0
  33. package/tests/fixtures/official/guesthouse_agentified/agent-manifest.json +86 -0
  34. package/tests/fixtures/official/guesthouse_agentified/links.json +6 -0
  35. package/tests/fixtures/official/guesthouse_agentified/tidewhistle_guesthouse.network.json +56 -0
  36. package/tests/fixtures/official/harbor_tours_agentified/agent-manifest.json +86 -0
  37. package/tests/fixtures/official/harbor_tours_agentified/links.json +6 -0
  38. package/tests/fixtures/official/harbor_tours_agentified/marrow_point_harbor_tours.network.json +56 -0
  39. package/tests/fixtures/official/pizza_restaurant_agentified/agent-manifest.json +78 -0
  40. package/tests/fixtures/official/pizza_restaurant_agentified/links.json +6 -0
  41. package/tests/fixtures/official/pizza_restaurant_agentified/pizza_restaurant_website_assistant.network.json +156 -0
  42. package/tools/bench.mjs +731 -0
  43. package/tools/external-heldout.mjs +337 -0
  44. package/tools/fs-fetch.mjs +19 -0
  45. package/tools/heldout-corpus.mjs +135 -0
  46. package/tools/inspect-local.mjs +88 -0
  47. package/tools/round2-corpus.mjs +395 -0
  48. package/tools/round3-corpus.mjs +192 -0
@@ -0,0 +1,70 @@
1
+ // GENERATED by nsxc from neuro_san/kernel/validation.py. Do not edit by hand.
2
+ // Regenerate with: python -m nsxc.transpile neuro_san/kernel/validation.py
3
+
4
+ import { classify_tool, find_front_man } from "./graph.gen.mjs";
5
+ const _get = (o, k, d) => (o != null && Object.prototype.hasOwnProperty.call(o, k) ? o[k] : (d !== undefined ? d : null));
6
+ const _contains = (needle, hay) => (typeof hay === "string" ? hay.includes(needle) : Array.isArray(hay) ? hay.includes(needle) : (hay && typeof hay === "object") ? Object.prototype.hasOwnProperty.call(hay, needle) : false);
7
+
8
+ export function validate_shape(config) {
9
+ let errors = [];
10
+ let tools = _get(config, "tools");
11
+ if (tools === null) {
12
+ errors.push("Network must have a 'tools' array.");
13
+ return errors;
14
+ }
15
+ if ((tools).length === 0) {
16
+ errors.push("Network 'tools' array must not be empty.");
17
+ return errors;
18
+ }
19
+ for (const agent of tools) {
20
+ let name = _get(agent, "name");
21
+ if (name === null) {
22
+ errors.push("Every agent must have a 'name'.");
23
+ }
24
+ }
25
+ return errors;
26
+ }
27
+
28
+ export function validate_missing_nodes(config) {
29
+ let errors = [];
30
+ let tools = _get(config, "tools");
31
+ if (tools === null) {
32
+ return errors;
33
+ }
34
+ for (const agent of tools) {
35
+ let refs = _get(agent, "tools");
36
+ if (refs === null) {
37
+ continue;
38
+ }
39
+ let owner = _get(agent, "name");
40
+ for (const ref of refs) {
41
+ let kind = classify_tool(config, ref);
42
+ if (kind === "missing") {
43
+ errors.push((((("Agent '" + String(owner)) + "' references missing tool '") + String(ref)) + "'."));
44
+ }
45
+ }
46
+ }
47
+ return errors;
48
+ }
49
+
50
+ export function validate_front_man(config) {
51
+ let errors = [];
52
+ if (find_front_man(config) === null) {
53
+ errors.push("No front-man agent found.");
54
+ }
55
+ return errors;
56
+ }
57
+
58
+ export function validate_network(config) {
59
+ let errors = [];
60
+ for (const e of validate_shape(config)) {
61
+ errors.push(e);
62
+ }
63
+ for (const e of validate_front_man(config)) {
64
+ errors.push(e);
65
+ }
66
+ for (const e of validate_missing_nodes(config)) {
67
+ errors.push(e);
68
+ }
69
+ return errors;
70
+ }
@@ -0,0 +1,262 @@
1
+ // hocon.js — a tolerant HOCON-subset parser.
2
+ //
3
+ // This is the browser-side "HOCON-parse shim" referenced in the plan. It parses
4
+ // the subset of HOCON that neuro-san agent networks use: // / # / block comments,
5
+ // quoted + unquoted keys, ':' or '=' separators, triple-quoted multi-line strings,
6
+ // objects, arrays, optional commas (newline as separator), trailing commas, and the
7
+ // JSON scalar types. `include` directives are handled by the loader (engine.js),
8
+ // not here.
9
+ //
10
+ // In the full design this parser is part of the cross-compiled kernel; here it is a
11
+ // faithful hand-written reference so the demo runs end to end.
12
+
13
+ export function parseHocon(text) {
14
+ return new HoconParser(text).parseDocument();
15
+ }
16
+
17
+ class HoconParser {
18
+ constructor(text) {
19
+ this.s = text;
20
+ this.i = 0;
21
+ this.n = text.length;
22
+ }
23
+
24
+ error(msg) {
25
+ const upto = this.s.slice(0, this.i);
26
+ const line = upto.split("\n").length;
27
+ const col = this.i - upto.lastIndexOf("\n");
28
+ return new Error(`HOCON parse error at line ${line}:${col}: ${msg}`);
29
+ }
30
+
31
+ parseDocument() {
32
+ this.skipTrivia();
33
+ let value;
34
+ if (this.peek() === "{") {
35
+ value = this.parseObject();
36
+ } else {
37
+ // Top-level object without surrounding braces is legal in HOCON.
38
+ value = this.parseObjectBody(/* braced */ false);
39
+ }
40
+ this.skipTrivia();
41
+ if (this.i < this.n) throw this.error(`unexpected trailing content '${this.peek()}'`);
42
+ return value;
43
+ }
44
+
45
+ parseValue() {
46
+ this.skipTrivia();
47
+ const c = this.peek();
48
+ if (c === "{") return this.parseObject();
49
+ if (c === "[") return this.parseArray();
50
+ if (c === '"') return this.parseStringValue();
51
+ return this.parseUnquoted();
52
+ }
53
+
54
+ parseObject() {
55
+ this.expect("{");
56
+ const obj = this.parseObjectBody(true);
57
+ return obj;
58
+ }
59
+
60
+ parseObjectBody(braced) {
61
+ const obj = {};
62
+ for (;;) {
63
+ this.skipTrivia();
64
+ const c = this.peek();
65
+ if (c === null) {
66
+ if (braced) throw this.error("unexpected end of input inside object");
67
+ break;
68
+ }
69
+ if (c === "}") {
70
+ if (!braced) throw this.error("unexpected '}'");
71
+ this.i++; // consume }
72
+ break;
73
+ }
74
+ // key
75
+ let key;
76
+ if (c === '"') key = this.parseQuotedString();
77
+ else key = this.parseBareKey();
78
+ this.skipTrivia();
79
+ const sep = this.peek();
80
+ let value;
81
+ if (sep === ":" || sep === "=") {
82
+ this.i++;
83
+ value = this.parseValue();
84
+ } else if (sep === "{") {
85
+ // "key { ... }" object-merge shorthand
86
+ value = this.parseObject();
87
+ } else {
88
+ throw this.error(`expected ':' or '=' after key '${key}'`);
89
+ }
90
+ // deep-merge on duplicate object keys (HOCON semantics)
91
+ if (
92
+ Object.prototype.hasOwnProperty.call(obj, key) &&
93
+ isPlainObject(obj[key]) &&
94
+ isPlainObject(value)
95
+ ) {
96
+ obj[key] = deepMerge(obj[key], value);
97
+ } else {
98
+ obj[key] = value;
99
+ }
100
+ this.skipSeparators();
101
+ }
102
+ return obj;
103
+ }
104
+
105
+ parseArray() {
106
+ this.expect("[");
107
+ const arr = [];
108
+ for (;;) {
109
+ this.skipTrivia();
110
+ const c = this.peek();
111
+ if (c === null) throw this.error("unexpected end of input inside array");
112
+ if (c === "]") {
113
+ this.i++;
114
+ break;
115
+ }
116
+ arr.push(this.parseValue());
117
+ this.skipSeparators();
118
+ }
119
+ return arr;
120
+ }
121
+
122
+ parseStringValue() {
123
+ // either triple-quoted or normal quoted
124
+ if (this.s.startsWith('"""', this.i)) return this.parseTripleQuoted();
125
+ return this.parseQuotedString();
126
+ }
127
+
128
+ parseTripleQuoted() {
129
+ this.i += 3;
130
+ const end = this.s.indexOf('"""', this.i);
131
+ if (end < 0) throw this.error("unterminated triple-quoted string");
132
+ const str = this.s.slice(this.i, end);
133
+ this.i = end + 3;
134
+ return str;
135
+ }
136
+
137
+ parseQuotedString() {
138
+ if (this.s.startsWith('"""', this.i)) return this.parseTripleQuoted();
139
+ this.expect('"');
140
+ let out = "";
141
+ for (;;) {
142
+ const c = this.s[this.i];
143
+ if (c === undefined) throw this.error("unterminated string");
144
+ if (c === '"') {
145
+ this.i++;
146
+ break;
147
+ }
148
+ if (c === "\\") {
149
+ const e = this.s[this.i + 1];
150
+ const map = { n: "\n", t: "\t", r: "\r", '"': '"', "\\": "\\", "/": "/" };
151
+ if (e === "u") {
152
+ out += String.fromCharCode(parseInt(this.s.slice(this.i + 2, this.i + 6), 16));
153
+ this.i += 6;
154
+ } else if (e in map) {
155
+ out += map[e];
156
+ this.i += 2;
157
+ } else {
158
+ out += e;
159
+ this.i += 2;
160
+ }
161
+ } else {
162
+ out += c;
163
+ this.i++;
164
+ }
165
+ }
166
+ return out;
167
+ }
168
+
169
+ parseBareKey() {
170
+ // bare key up to whitespace, ':', '=', or '{'
171
+ const start = this.i;
172
+ while (this.i < this.n && !/[\s:={}]/.test(this.s[this.i])) this.i++;
173
+ if (this.i === start) throw this.error("expected a key");
174
+ return this.s.slice(start, this.i);
175
+ }
176
+
177
+ parseUnquoted() {
178
+ // read until a value terminator at the current nesting (newline, comma, ] } or comment)
179
+ const start = this.i;
180
+ while (this.i < this.n) {
181
+ const c = this.s[this.i];
182
+ if (c === "\n" || c === "," || c === "}" || c === "]") break;
183
+ if (c === "/" && (this.s[this.i + 1] === "/" || this.s[this.i + 1] === "*")) break;
184
+ if (c === "#") break;
185
+ this.i++;
186
+ }
187
+ const raw = this.s.slice(start, this.i).trim();
188
+ return coerceScalar(raw);
189
+ }
190
+
191
+ // --- trivia handling -------------------------------------------------------
192
+
193
+ skipTrivia() {
194
+ for (;;) {
195
+ const c = this.s[this.i];
196
+ if (c === undefined) return;
197
+ if (c === " " || c === "\t" || c === "\r" || c === "\n") {
198
+ this.i++;
199
+ continue;
200
+ }
201
+ if (c === "#" || (c === "/" && this.s[this.i + 1] === "/")) {
202
+ const nl = this.s.indexOf("\n", this.i);
203
+ this.i = nl < 0 ? this.n : nl;
204
+ continue;
205
+ }
206
+ if (c === "/" && this.s[this.i + 1] === "*") {
207
+ const end = this.s.indexOf("*/", this.i + 2);
208
+ this.i = end < 0 ? this.n : end + 2;
209
+ continue;
210
+ }
211
+ return;
212
+ }
213
+ }
214
+
215
+ // separators between members: commas and/or newlines, plus comments
216
+ skipSeparators() {
217
+ for (;;) {
218
+ const c = this.s[this.i];
219
+ if (c === " " || c === "\t" || c === "\r" || c === "\n" || c === ",") {
220
+ this.i++;
221
+ continue;
222
+ }
223
+ if (c === "#" || (c === "/" && (this.s[this.i + 1] === "/" || this.s[this.i + 1] === "*"))) {
224
+ this.skipTrivia();
225
+ continue;
226
+ }
227
+ return;
228
+ }
229
+ }
230
+
231
+ peek() {
232
+ return this.i < this.n ? this.s[this.i] : null;
233
+ }
234
+
235
+ expect(ch) {
236
+ if (this.s[this.i] !== ch) throw this.error(`expected '${ch}'`);
237
+ this.i++;
238
+ }
239
+ }
240
+
241
+ function coerceScalar(raw) {
242
+ if (raw === "true") return true;
243
+ if (raw === "false") return false;
244
+ if (raw === "null") return null;
245
+ if (raw !== "" && !Number.isNaN(Number(raw)) && /^[-+0-9.eE]+$/.test(raw)) {
246
+ return Number(raw);
247
+ }
248
+ return raw;
249
+ }
250
+
251
+ export function isPlainObject(v) {
252
+ return v !== null && typeof v === "object" && !Array.isArray(v);
253
+ }
254
+
255
+ export function deepMerge(a, b) {
256
+ const out = { ...a };
257
+ for (const [k, v] of Object.entries(b)) {
258
+ if (isPlainObject(out[k]) && isPlainObject(v)) out[k] = deepMerge(out[k], v);
259
+ else out[k] = v;
260
+ }
261
+ return out;
262
+ }
@@ -0,0 +1,237 @@
1
+ // kernel.js — the pure, framework-free orchestration logic.
2
+ //
3
+ // This module is the browser-side reference for what the plan calls the
4
+ // "cross-compilable kernel": config filter chain, AgentNetwork, the activation
5
+ // taxonomy (wiring only — NOT the agentic loop), validators, sly_data redaction,
6
+ // the ChatMessage envelope, and external/MCP URL parsing. It imports nothing
7
+ // browser-specific and nothing framework-specific, so it is exactly the surface
8
+ // `nsxc` would generate from neuro_san/kernel/. It is hand-written here so the demo
9
+ // runs today; behavioral parity tests (see nsxc/) pin it to the Python source.
10
+
11
+ import { deepMerge, isPlainObject } from "./hocon.js";
12
+ import { normalizeModelName } from "./model.js";
13
+ // Cross-compiled from neuro_san/kernel by nsxc (regenerated every build, drift-gated).
14
+ import { find_front_man, classify_tool } from "./generated/graph.gen.mjs";
15
+ import { validate_network } from "./generated/validation.gen.mjs";
16
+
17
+ // --- ChatMessage envelope (mirrors neuro_san/api/grpc/chat.proto) ------------
18
+
19
+ export const ChatMessageType = {
20
+ UNKNOWN: 0,
21
+ SYSTEM: 1,
22
+ HUMAN: 2,
23
+ AI: 4,
24
+ AGENT: 100,
25
+ AGENT_FRAMEWORK: 101,
26
+ AGENT_TOOL_RESULT: 103,
27
+ AGENT_PROGRESS: 104,
28
+ };
29
+
30
+ export function chatMessage(type, text, origin = [], extra = {}) {
31
+ return { type, text, origin, ...extra };
32
+ }
33
+
34
+ // --- sly_data redaction (mirrors AgentFrameworkMessage.translate_for_trace) --
35
+
36
+ // Keep keys, drop values, when sly_data crosses an origin/trust boundary.
37
+ export function redactSlyData(slyData) {
38
+ if (!slyData) return slyData;
39
+ const out = {};
40
+ for (const k of Object.keys(slyData)) out[k] = "<redacted>";
41
+ return out;
42
+ }
43
+
44
+ // Filter sly_data to the subset an `allow` block permits to cross a boundary.
45
+ export function filterSlyData(slyData, allowedKeys) {
46
+ if (!slyData) return {};
47
+ if (!allowedKeys || allowedKeys.length === 0) return {};
48
+ if (allowedKeys.includes("*")) return { ...slyData };
49
+ const out = {};
50
+ for (const k of allowedKeys) if (k in slyData) out[k] = slyData[k];
51
+ return out;
52
+ }
53
+
54
+ export function allowedDownstreamSly(agentSpec) {
55
+ return agentSpec?.allow?.to_downstream?.sly_data ?? null;
56
+ }
57
+ export function allowedUpstreamSly(agentSpec) {
58
+ return agentSpec?.allow?.to_upstream?.sly_data ?? null;
59
+ }
60
+
61
+ // --- external / MCP URL parsing (mirrors external_agent_parsing.py) ----------
62
+
63
+ export function isExternalAgent(ref) {
64
+ if (typeof ref !== "string") return false;
65
+ return /^https?:\/\//i.test(ref) || ref.startsWith("/");
66
+ }
67
+
68
+ export function isMcpTool(ref) {
69
+ if (isPlainObject(ref)) return true;
70
+ if (typeof ref !== "string") return false;
71
+ if (!/^https?:\/\//i.test(ref)) return false;
72
+ try {
73
+ const u = new URL(ref);
74
+ const hostLabels = u.hostname.toLowerCase().split(".");
75
+ const pathSegs = u.pathname.split("/").filter(Boolean).map((s) => s.toLowerCase());
76
+ return hostLabels.includes("mcp") || pathSegs.includes("mcp");
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+
82
+ // Parse "https://host:port/agents/name" or "/name" into its parts.
83
+ export function parseExternalAgent(ref, baseOrigin) {
84
+ if (ref.startsWith("/")) {
85
+ const origin = baseOrigin || (typeof location !== "undefined" ? location.origin : "");
86
+ return { origin, agentName: ref.replace(/^\//, ""), url: origin + ref };
87
+ }
88
+ const u = new URL(ref);
89
+ return { origin: u.origin, agentName: u.pathname.replace(/^\//, ""), url: ref };
90
+ }
91
+
92
+ // --- config filter chain (mirrors the *ConfigFilter classes) -----------------
93
+
94
+ // Expand commondefs.replacement_strings ({token}) and replacement_values, then
95
+ // push top-level defaults down onto each agent spec, mirroring DefaultsConfigFilter.
96
+ const DEFAULT_KEYS = [
97
+ "llm_config",
98
+ "verbose",
99
+ "max_steps",
100
+ "max_iterations",
101
+ "max_execution_seconds",
102
+ "max_attempts",
103
+ "error_formatter",
104
+ "error_fragments",
105
+ ];
106
+
107
+ export function filterConfig(rawConfig) {
108
+ let config = deepClone(rawConfig);
109
+ const commondefs = config.commondefs || {};
110
+ const strs = commondefs.replacement_strings || {};
111
+ const vals = commondefs.replacement_values || {};
112
+
113
+ config = walkReplace(config, (v) => {
114
+ if (typeof v === "string") {
115
+ // full-value replacement_values match first
116
+ if (Object.prototype.hasOwnProperty.call(vals, v)) return vals[v];
117
+ // {token} string substitution
118
+ return v.replace(/\{([A-Za-z0-9_]+)\}/g, (m, key) =>
119
+ Object.prototype.hasOwnProperty.call(strs, key) ? strs[key] : m
120
+ );
121
+ }
122
+ return v;
123
+ });
124
+
125
+ // push down defaults
126
+ const tools = Array.isArray(config.tools) ? config.tools : [];
127
+ for (const agent of tools) {
128
+ for (const key of DEFAULT_KEYS) {
129
+ if (key in config) {
130
+ if (isPlainObject(config[key]) && isPlainObject(agent[key])) {
131
+ agent[key] = deepMerge(config[key], agent[key]);
132
+ } else if (!(key in agent)) {
133
+ agent[key] = deepClone(config[key]);
134
+ }
135
+ }
136
+ }
137
+ // name correction: trim whitespace
138
+ if (typeof agent.name === "string") agent.name = agent.name.trim();
139
+ normalizeConfiguredModel(agent.llm_config);
140
+ }
141
+ normalizeConfiguredModel(config.llm_config);
142
+ return config;
143
+ }
144
+
145
+ // A blank or quoted-empty model_name (" ", '""') becomes "", so it counts as not set
146
+ // and falls back to the network's model. Both runners and the settings panel read
147
+ // this config, so they all fall back the same way.
148
+ function normalizeConfiguredModel(llmConfig) {
149
+ if (isPlainObject(llmConfig) && typeof llmConfig.model_name === "string") {
150
+ llmConfig.model_name = normalizeModelName(llmConfig.model_name);
151
+ }
152
+ }
153
+
154
+ function walkReplace(v, fn) {
155
+ if (Array.isArray(v)) return v.map((x) => walkReplace(x, fn));
156
+ if (isPlainObject(v)) {
157
+ const out = {};
158
+ for (const [k, val] of Object.entries(v)) out[k] = walkReplace(val, fn);
159
+ return out;
160
+ }
161
+ return fn(v);
162
+ }
163
+
164
+ function deepClone(v) {
165
+ return typeof structuredClone === "function"
166
+ ? structuredClone(v)
167
+ : JSON.parse(JSON.stringify(v));
168
+ }
169
+
170
+ // --- AgentNetwork (mirrors internals/graph/registry/agent_network.py) --------
171
+
172
+ export class AgentNetwork {
173
+ constructor(config, name) {
174
+ this.config = filterConfig(config);
175
+ this.name = name;
176
+ this.linkSlots = new Set(Object.keys(this.config.link_slots || {}));
177
+ this.links = { ...(this.config.links || {}) };
178
+ this.linkLabels = { ...(this.config.link_labels || {}) };
179
+ this.specMap = new Map();
180
+ for (const agent of this.config.tools || []) {
181
+ if (agent && typeof agent.name === "string") this.specMap.set(agent.name, agent);
182
+ }
183
+ }
184
+
185
+ getAgentSpec(name) {
186
+ return this.specMap.get(name) || null;
187
+ }
188
+
189
+ // Delegates to the cross-compiled kernel (neuro_san/kernel/graph.py).
190
+ findFrontMan() {
191
+ return find_front_man(this.config);
192
+ }
193
+
194
+ // Delegates classification to the cross-compiled kernel, then attaches the
195
+ // local agent spec (needed by the runner) for non-remote/non-mcp kinds.
196
+ classifyTool(ref) {
197
+ let kind = classify_tool(this.config, ref);
198
+ if (kind === "missing" && typeof ref === "string" && this.linkSlots.has(ref)) kind = "link";
199
+ const spec = typeof ref === "string" ? this.specMap.get(ref) : undefined;
200
+ return { kind, ref, spec };
201
+ }
202
+
203
+ getLink(ref) {
204
+ return this.links[ref] || null;
205
+ }
206
+
207
+ setLink(ref, target) {
208
+ if (this.linkSlots.has(ref)) this.links[ref] = target;
209
+ }
210
+
211
+ metadata() {
212
+ return this.config.metadata || {};
213
+ }
214
+ }
215
+
216
+ // --- validators (mirrors the validator chain) --------------------------------
217
+
218
+ export function validateNetwork(network) {
219
+ // Errors come from the cross-compiled kernel (neuro_san/kernel/validation.py).
220
+ const errors = validate_network(network.config).filter((message) =>
221
+ ![...network.linkSlots].some((ref) => message.includes(`references missing tool '${ref}'.`))
222
+ );
223
+ const warnings = [];
224
+
225
+ // The externals/mcps list (for the trace's cross-origin permission view) is a
226
+ // browser-side concern, scanned here.
227
+ const externals = [];
228
+ const mcps = [];
229
+ for (const agent of network.config.tools || []) {
230
+ for (const ref of agent.tools || []) {
231
+ const c = network.classifyTool(ref);
232
+ if (c.kind === "remote") externals.push(ref);
233
+ else if (c.kind === "mcp") mcps.push(typeof ref === "string" ? ref : ref.url);
234
+ }
235
+ }
236
+ return { errors, warnings, externals, mcps };
237
+ }
@@ -0,0 +1,44 @@
1
+ // Placeholder model name for the mock routers, which ignore the model. Other modules
2
+ // use fallbackModel and isPlaceholderModel instead of this name.
3
+ const MOCK_MODEL_NAME = "mock-1";
4
+
5
+ // Canonicalize model identifiers entered through profiles or forms.
6
+ export function normalizeModelName(value) {
7
+ let model = String(value ?? "").trim();
8
+ while (model.length >= 2) {
9
+ const first = model[0];
10
+ const last = model[model.length - 1];
11
+ if (!((first === '"' && last === '"') || (first === "'" && last === "'"))) break;
12
+ model = model.slice(1, -1).trim();
13
+ }
14
+ return model;
15
+ }
16
+
17
+ // True for a model a real provider cannot use: an empty name, or the mock placeholder.
18
+ export function isPlaceholderModel(model) {
19
+ const name = normalizeModelName(model);
20
+ return !name || name === MOCK_MODEL_NAME;
21
+ }
22
+
23
+ // The model an agent sends when neither the visitor nor the agent names one: the
24
+ // network's model, or else the mock placeholder.
25
+ export function fallbackModel(networkModel) {
26
+ return networkModel || MOCK_MODEL_NAME;
27
+ }
28
+
29
+ // The model an agent sends: the visitor's choice, then the agent's declared model,
30
+ // then fallbackModel. The runners and the settings panel both use this, so the panel
31
+ // checks exactly what a turn would send.
32
+ export function effectiveModel(override, agentModel, networkModel) {
33
+ return override || agentModel || fallbackModel(networkModel);
34
+ }
35
+
36
+ // Fail closed before a real (non-mock) router gets an empty model or the mock
37
+ // placeholder. A real provider rejects both (for example with 404 model_not_found),
38
+ // so the visitor gets a setup error instead and no request is sent.
39
+ export function assertModelForRouter(model, mock, routerHost) {
40
+ if (mock || !isPlaceholderModel(model)) return;
41
+ throw new Error(`A model is required for ${routerHost || "the configured provider"}. `
42
+ + "Open ⚙ AI model settings, enter a model your provider supports in the Model field, "
43
+ + "then select Save and start.");
44
+ }
@@ -0,0 +1,3 @@
1
+ These folders copy the public files of three examples from
2
+ https://github.com/cognizant-ai-labs/agentic-web (examples/*_agentified), Apache License 2.0.
3
+ The tests check that Agent Customs clears them.