@zeroxyz/sdk 0.9.0 → 0.11.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/CHANGELOG.md +22 -0
- package/README.md +58 -8
- package/dist/{chunk-O7QJMY3Y.cjs → chunk-HKF4TRC6.cjs} +571 -144
- package/dist/chunk-HKF4TRC6.cjs.map +1 -0
- package/dist/{chunk-T6JT5NV5.js → chunk-T77VVLOM.js} +566 -144
- package/dist/chunk-T77VVLOM.js.map +1 -0
- package/dist/{client-Du4zQHef.d.cts → client-DKbrAo9Z.d.cts} +196 -19
- package/dist/{client-Du4zQHef.d.ts → client-DKbrAo9Z.d.ts} +196 -19
- package/dist/index.cjs +303 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +109 -3
- package/dist/index.d.ts +109 -3
- package/dist/index.js +232 -2
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +2 -2
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-O7QJMY3Y.cjs.map +0 -1
- package/dist/chunk-T6JT5NV5.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkHKF4TRC6_cjs = require('./chunk-HKF4TRC6.cjs');
|
|
4
4
|
|
|
5
5
|
// src/status.ts
|
|
6
6
|
var AVAILABILITY_BADGES = {
|
|
@@ -23,148 +23,415 @@ var sortByHealth = (items) => [...items].sort(
|
|
|
23
23
|
);
|
|
24
24
|
var preferHealthy = sortByHealth;
|
|
25
25
|
|
|
26
|
+
// src/utils/agent-host.ts
|
|
27
|
+
var detectAgentHost = (env = process.env) => {
|
|
28
|
+
if (env.ZERO_AGENT) return env.ZERO_AGENT;
|
|
29
|
+
if (env.CLAUDECODE === "1") return "claude-code";
|
|
30
|
+
if (env.CURSOR_TRACE_ID) return "cursor";
|
|
31
|
+
if (env.TERM_PROGRAM === "vscode") return "vscode";
|
|
32
|
+
return "unknown";
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/utils/format-count.ts
|
|
36
|
+
var formatReviewCount = (count) => {
|
|
37
|
+
if (count >= 1e3) return `${(count / 1e3).toFixed(1)}k`;
|
|
38
|
+
return count.toString();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/utils/format-price.ts
|
|
42
|
+
var centsToDollars = (cents) => {
|
|
43
|
+
const value = Number.parseFloat(cents) / 100;
|
|
44
|
+
if (!Number.isFinite(value) || value === 0) return "0.00";
|
|
45
|
+
if (value < 1e-4) return value.toFixed(6);
|
|
46
|
+
if (value < 1e-3) return value.toFixed(5);
|
|
47
|
+
if (value < 0.01) return value.toFixed(4);
|
|
48
|
+
if (value < 1) return value.toFixed(3);
|
|
49
|
+
return value.toFixed(2);
|
|
50
|
+
};
|
|
51
|
+
var formatCostLabel = (amount) => {
|
|
52
|
+
if (amount === "0") return "Free";
|
|
53
|
+
if (amount === "unknown") return "variable pricing";
|
|
54
|
+
return `$${amount}/call`;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/utils/format-rating.ts
|
|
58
|
+
var formatRatingBadge = (rating) => {
|
|
59
|
+
if (rating.state === "unrated") return "unrated";
|
|
60
|
+
const successPct = `${Math.round(Number.parseFloat(rating.successRate) * 100)}%`;
|
|
61
|
+
const reviews = formatReviewCount(rating.reviews);
|
|
62
|
+
if (rating.stars) {
|
|
63
|
+
return `\u2605 ${rating.stars}/5 (${successPct} success, ${reviews} reviews)`;
|
|
64
|
+
}
|
|
65
|
+
return `${successPct} success \xB7 ${reviews} reviews`;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/utils/format-time.ts
|
|
69
|
+
var formatRelativeTimestamp = (iso) => {
|
|
70
|
+
if (!iso) return "never";
|
|
71
|
+
const then = new Date(iso).getTime();
|
|
72
|
+
if (Number.isNaN(then)) return "never";
|
|
73
|
+
const diffSec = Math.max(0, Math.round((Date.now() - then) / 1e3));
|
|
74
|
+
if (diffSec < 60) return `${diffSec}s ago`;
|
|
75
|
+
const diffMin = Math.round(diffSec / 60);
|
|
76
|
+
if (diffMin < 60) return `${diffMin}m ago`;
|
|
77
|
+
const diffHr = Math.round(diffMin / 60);
|
|
78
|
+
if (diffHr < 24) return `${diffHr}h ago`;
|
|
79
|
+
const diffDay = Math.round(diffHr / 24);
|
|
80
|
+
if (diffDay < 30) return `${diffDay}d ago`;
|
|
81
|
+
const diffMo = Math.round(diffDay / 30);
|
|
82
|
+
if (diffMo < 12) return `${diffMo}mo ago`;
|
|
83
|
+
return `${Math.round(diffMo / 12)}y ago`;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/utils/infer-schema.ts
|
|
87
|
+
var inferSchema = (value, depth = 0) => {
|
|
88
|
+
if (depth > 6) return { type: typeOf(value) };
|
|
89
|
+
if (value === null) return { type: "null" };
|
|
90
|
+
if (Array.isArray(value)) {
|
|
91
|
+
const itemSchemas = value.slice(0, 3).map((v) => inferSchema(v, depth + 1));
|
|
92
|
+
return {
|
|
93
|
+
type: "array",
|
|
94
|
+
items: itemSchemas[0] ?? { type: "unknown" }
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === "object") {
|
|
98
|
+
const obj = value;
|
|
99
|
+
const properties = {};
|
|
100
|
+
const required = [];
|
|
101
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
102
|
+
properties[k] = inferSchema(v, depth + 1);
|
|
103
|
+
required.push(k);
|
|
104
|
+
}
|
|
105
|
+
return { type: "object", properties, required };
|
|
106
|
+
}
|
|
107
|
+
return { type: typeOf(value) };
|
|
108
|
+
};
|
|
109
|
+
var typeOf = (v) => {
|
|
110
|
+
if (v === null) return "null";
|
|
111
|
+
if (Array.isArray(v)) return "array";
|
|
112
|
+
return typeof v;
|
|
113
|
+
};
|
|
114
|
+
var tryParseJson = (text) => {
|
|
115
|
+
try {
|
|
116
|
+
return JSON.parse(text);
|
|
117
|
+
} catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/utils/redact.ts
|
|
123
|
+
var ERROR_MAX = 500;
|
|
124
|
+
var redactUrl = (raw) => {
|
|
125
|
+
try {
|
|
126
|
+
const parsed = new URL(raw);
|
|
127
|
+
return `${parsed.origin}${parsed.pathname}`;
|
|
128
|
+
} catch {
|
|
129
|
+
return raw;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var truncateError = (raw) => raw.length > ERROR_MAX ? `${raw.slice(0, ERROR_MAX)}\u2026` : raw;
|
|
133
|
+
|
|
134
|
+
// src/utils/schema-describe.ts
|
|
135
|
+
var schemaTypeLabel = (node) => {
|
|
136
|
+
const t = node.type;
|
|
137
|
+
if (typeof t === "string") return t;
|
|
138
|
+
if (Array.isArray(t)) {
|
|
139
|
+
const parts = t.filter((x) => typeof x === "string");
|
|
140
|
+
return parts.length > 0 ? parts.join(" | ") : "any";
|
|
141
|
+
}
|
|
142
|
+
return "any";
|
|
143
|
+
};
|
|
144
|
+
var constraintHint = (node) => {
|
|
145
|
+
const num = (k) => typeof node[k] === "number" ? node[k] : void 0;
|
|
146
|
+
const hints = [];
|
|
147
|
+
const min = num("minimum");
|
|
148
|
+
const max = num("maximum");
|
|
149
|
+
if (min !== void 0 && max !== void 0)
|
|
150
|
+
hints.push(`range: ${min}..${max}`);
|
|
151
|
+
else if (min !== void 0) hints.push(`min: ${min}`);
|
|
152
|
+
else if (max !== void 0) hints.push(`max: ${max}`);
|
|
153
|
+
const exMin = num("exclusiveMinimum");
|
|
154
|
+
const exMax = num("exclusiveMaximum");
|
|
155
|
+
if (exMin !== void 0) hints.push(`> ${exMin}`);
|
|
156
|
+
if (exMax !== void 0) hints.push(`< ${exMax}`);
|
|
157
|
+
const minLen = num("minLength");
|
|
158
|
+
const maxLen = num("maxLength");
|
|
159
|
+
if (minLen !== void 0 && maxLen !== void 0)
|
|
160
|
+
hints.push(`length: ${minLen}..${maxLen}`);
|
|
161
|
+
else if (maxLen !== void 0) hints.push(`maxLength: ${maxLen}`);
|
|
162
|
+
else if (minLen !== void 0) hints.push(`minLength: ${minLen}`);
|
|
163
|
+
const minItems = num("minItems");
|
|
164
|
+
const maxItems = num("maxItems");
|
|
165
|
+
if (minItems !== void 0 && maxItems !== void 0)
|
|
166
|
+
hints.push(`items: ${minItems}..${maxItems}`);
|
|
167
|
+
else if (maxItems !== void 0) hints.push(`maxItems: ${maxItems}`);
|
|
168
|
+
else if (minItems !== void 0) hints.push(`minItems: ${minItems}`);
|
|
169
|
+
if (typeof node.pattern === "string") hints.push(`pattern: ${node.pattern}`);
|
|
170
|
+
return hints.length > 0 ? hints.join(", ") : null;
|
|
171
|
+
};
|
|
172
|
+
var paramAttrs = (node, required) => {
|
|
173
|
+
const attrs = [schemaTypeLabel(node)];
|
|
174
|
+
if (required) attrs.push("required");
|
|
175
|
+
if (node.const !== void 0)
|
|
176
|
+
attrs.push(`const: ${JSON.stringify(node.const)}`);
|
|
177
|
+
if (node.default !== void 0)
|
|
178
|
+
attrs.push(`default: ${JSON.stringify(node.default)}`);
|
|
179
|
+
if (Array.isArray(node.enum))
|
|
180
|
+
attrs.push(`one of: ${node.enum.map((v) => String(v)).join(" | ")}`);
|
|
181
|
+
if (typeof node.format === "string") attrs.push(`format: ${node.format}`);
|
|
182
|
+
const hint = constraintHint(node);
|
|
183
|
+
if (hint) attrs.push(hint);
|
|
184
|
+
return attrs.join(", ");
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// src/utils/schema-sample.ts
|
|
188
|
+
var schemaType = (node) => {
|
|
189
|
+
const t = node?.type;
|
|
190
|
+
if (typeof t === "string") return t;
|
|
191
|
+
if (Array.isArray(t)) {
|
|
192
|
+
const first = t.find((x) => typeof x === "string" && x !== "null");
|
|
193
|
+
return typeof first === "string" ? first : void 0;
|
|
194
|
+
}
|
|
195
|
+
return void 0;
|
|
196
|
+
};
|
|
197
|
+
var coerceToType = (value, type) => {
|
|
198
|
+
if (typeof value !== "string") return value;
|
|
199
|
+
if (type === "number" || type === "integer") {
|
|
200
|
+
const n = Number(value);
|
|
201
|
+
return value.trim() !== "" && Number.isFinite(n) ? n : value;
|
|
202
|
+
}
|
|
203
|
+
if (type === "boolean") {
|
|
204
|
+
if (value === "true") return true;
|
|
205
|
+
if (value === "false") return false;
|
|
206
|
+
}
|
|
207
|
+
return value;
|
|
208
|
+
};
|
|
209
|
+
var MAX_SCHEMA_DEPTH = 5;
|
|
210
|
+
var sampleValueFor = (fieldName, propSchema, depth = 0) => {
|
|
211
|
+
const node = chunkHKF4TRC6_cjs.asSchemaNode(propSchema);
|
|
212
|
+
const type = schemaType(node);
|
|
213
|
+
const enumFirst = Array.isArray(node?.enum) && node.enum.length > 0 ? node.enum[0] : void 0;
|
|
214
|
+
const fixed = node?.const ?? node?.example ?? node?.default ?? enumFirst;
|
|
215
|
+
if (fixed !== void 0 && fixed !== null) {
|
|
216
|
+
return coerceToType(fixed, type);
|
|
217
|
+
}
|
|
218
|
+
if (node && depth < MAX_SCHEMA_DEPTH) {
|
|
219
|
+
const props = chunkHKF4TRC6_cjs.asSchemaNode(node.properties);
|
|
220
|
+
if (props && (type === "object" || type === void 0)) {
|
|
221
|
+
const obj = {};
|
|
222
|
+
for (const [k, sub] of Object.entries(props)) {
|
|
223
|
+
obj[k] = sampleValueFor(k, sub, depth + 1);
|
|
224
|
+
}
|
|
225
|
+
return obj;
|
|
226
|
+
}
|
|
227
|
+
if (type === "array") {
|
|
228
|
+
const items = chunkHKF4TRC6_cjs.asSchemaNode(node.items);
|
|
229
|
+
return items ? [sampleValueFor(fieldName, items, depth + 1)] : [];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
switch (type) {
|
|
233
|
+
case "number":
|
|
234
|
+
case "integer":
|
|
235
|
+
return 0;
|
|
236
|
+
case "boolean":
|
|
237
|
+
return false;
|
|
238
|
+
case "array":
|
|
239
|
+
return [];
|
|
240
|
+
case "object":
|
|
241
|
+
return {};
|
|
242
|
+
default:
|
|
243
|
+
return `<${fieldName.toUpperCase()}>`;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
var placeholderFor = (fieldName, propSchema) => String(sampleValueFor(fieldName, propSchema));
|
|
247
|
+
|
|
248
|
+
// src/utils/url-template.ts
|
|
249
|
+
var urlMatchesTemplate = (url, template) => {
|
|
250
|
+
const escaped = template.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
251
|
+
const withCaptures = escaped.replace(/\\\{[^/\\}]+\\\}/g, "[^/]+");
|
|
252
|
+
return new RegExp(`^${withCaptures}$`).test(url);
|
|
253
|
+
};
|
|
254
|
+
|
|
26
255
|
Object.defineProperty(exports, "Auth", {
|
|
27
256
|
enumerable: true,
|
|
28
|
-
get: function () { return
|
|
257
|
+
get: function () { return chunkHKF4TRC6_cjs.Auth; }
|
|
258
|
+
});
|
|
259
|
+
Object.defineProperty(exports, "AuthAgent", {
|
|
260
|
+
enumerable: true,
|
|
261
|
+
get: function () { return chunkHKF4TRC6_cjs.AuthAgent; }
|
|
29
262
|
});
|
|
30
263
|
Object.defineProperty(exports, "AuthDevice", {
|
|
31
264
|
enumerable: true,
|
|
32
|
-
get: function () { return
|
|
265
|
+
get: function () { return chunkHKF4TRC6_cjs.AuthDevice; }
|
|
33
266
|
});
|
|
34
267
|
Object.defineProperty(exports, "BUG_REPORT_CATEGORIES", {
|
|
35
268
|
enumerable: true,
|
|
36
|
-
get: function () { return
|
|
269
|
+
get: function () { return chunkHKF4TRC6_cjs.BUG_REPORT_CATEGORIES; }
|
|
37
270
|
});
|
|
38
271
|
Object.defineProperty(exports, "BugReports", {
|
|
39
272
|
enumerable: true,
|
|
40
|
-
get: function () { return
|
|
273
|
+
get: function () { return chunkHKF4TRC6_cjs.BugReports; }
|
|
41
274
|
});
|
|
42
275
|
Object.defineProperty(exports, "Capabilities", {
|
|
43
276
|
enumerable: true,
|
|
44
|
-
get: function () { return
|
|
277
|
+
get: function () { return chunkHKF4TRC6_cjs.Capabilities; }
|
|
45
278
|
});
|
|
46
279
|
Object.defineProperty(exports, "DEFAULT_BASE_URL", {
|
|
47
280
|
enumerable: true,
|
|
48
|
-
get: function () { return
|
|
281
|
+
get: function () { return chunkHKF4TRC6_cjs.DEFAULT_BASE_URL; }
|
|
49
282
|
});
|
|
50
283
|
Object.defineProperty(exports, "DEFAULT_MAX_RETRIES", {
|
|
51
284
|
enumerable: true,
|
|
52
|
-
get: function () { return
|
|
285
|
+
get: function () { return chunkHKF4TRC6_cjs.DEFAULT_MAX_RETRIES; }
|
|
53
286
|
});
|
|
54
287
|
Object.defineProperty(exports, "DEFAULT_TIMEOUT_MS", {
|
|
55
288
|
enumerable: true,
|
|
56
|
-
get: function () { return
|
|
289
|
+
get: function () { return chunkHKF4TRC6_cjs.DEFAULT_TIMEOUT_MS; }
|
|
57
290
|
});
|
|
58
291
|
Object.defineProperty(exports, "FETCH_SKIP_REASONS", {
|
|
59
292
|
enumerable: true,
|
|
60
|
-
get: function () { return
|
|
293
|
+
get: function () { return chunkHKF4TRC6_cjs.FETCH_SKIP_REASONS; }
|
|
61
294
|
});
|
|
62
295
|
Object.defineProperty(exports, "FETCH_WARNINGS", {
|
|
63
296
|
enumerable: true,
|
|
64
|
-
get: function () { return
|
|
297
|
+
get: function () { return chunkHKF4TRC6_cjs.FETCH_WARNINGS; }
|
|
65
298
|
});
|
|
66
299
|
Object.defineProperty(exports, "Payments", {
|
|
67
300
|
enumerable: true,
|
|
68
|
-
get: function () { return
|
|
301
|
+
get: function () { return chunkHKF4TRC6_cjs.Payments; }
|
|
69
302
|
});
|
|
70
303
|
Object.defineProperty(exports, "Runs", {
|
|
71
304
|
enumerable: true,
|
|
72
|
-
get: function () { return
|
|
305
|
+
get: function () { return chunkHKF4TRC6_cjs.Runs; }
|
|
73
306
|
});
|
|
74
307
|
Object.defineProperty(exports, "SDK_VERSION", {
|
|
75
308
|
enumerable: true,
|
|
76
|
-
get: function () { return
|
|
309
|
+
get: function () { return chunkHKF4TRC6_cjs.SDK_VERSION; }
|
|
77
310
|
});
|
|
78
311
|
Object.defineProperty(exports, "TEMPO_CHAIN_ID", {
|
|
79
312
|
enumerable: true,
|
|
80
|
-
get: function () { return
|
|
313
|
+
get: function () { return chunkHKF4TRC6_cjs.TEMPO_CHAIN_ID; }
|
|
81
314
|
});
|
|
82
315
|
Object.defineProperty(exports, "TEMPO_TESTNET_CHAIN_ID", {
|
|
83
316
|
enumerable: true,
|
|
84
|
-
get: function () { return
|
|
317
|
+
get: function () { return chunkHKF4TRC6_cjs.TEMPO_TESTNET_CHAIN_ID; }
|
|
318
|
+
});
|
|
319
|
+
Object.defineProperty(exports, "USDC_BASE", {
|
|
320
|
+
enumerable: true,
|
|
321
|
+
get: function () { return chunkHKF4TRC6_cjs.USDC_BASE; }
|
|
322
|
+
});
|
|
323
|
+
Object.defineProperty(exports, "USDC_DECIMALS", {
|
|
324
|
+
enumerable: true,
|
|
325
|
+
get: function () { return chunkHKF4TRC6_cjs.USDC_DECIMALS; }
|
|
326
|
+
});
|
|
327
|
+
Object.defineProperty(exports, "USDC_TEMPO", {
|
|
328
|
+
enumerable: true,
|
|
329
|
+
get: function () { return chunkHKF4TRC6_cjs.USDC_TEMPO; }
|
|
85
330
|
});
|
|
86
331
|
Object.defineProperty(exports, "Wallet", {
|
|
87
332
|
enumerable: true,
|
|
88
|
-
get: function () { return
|
|
333
|
+
get: function () { return chunkHKF4TRC6_cjs.Wallet; }
|
|
334
|
+
});
|
|
335
|
+
Object.defineProperty(exports, "ZeroAgentAuthError", {
|
|
336
|
+
enumerable: true,
|
|
337
|
+
get: function () { return chunkHKF4TRC6_cjs.ZeroAgentAuthError; }
|
|
89
338
|
});
|
|
90
339
|
Object.defineProperty(exports, "ZeroApiError", {
|
|
91
340
|
enumerable: true,
|
|
92
|
-
get: function () { return
|
|
341
|
+
get: function () { return chunkHKF4TRC6_cjs.ZeroApiError; }
|
|
93
342
|
});
|
|
94
343
|
Object.defineProperty(exports, "ZeroAuthError", {
|
|
95
344
|
enumerable: true,
|
|
96
|
-
get: function () { return
|
|
345
|
+
get: function () { return chunkHKF4TRC6_cjs.ZeroAuthError; }
|
|
97
346
|
});
|
|
98
347
|
Object.defineProperty(exports, "ZeroClient", {
|
|
99
348
|
enumerable: true,
|
|
100
|
-
get: function () { return
|
|
349
|
+
get: function () { return chunkHKF4TRC6_cjs.ZeroClient; }
|
|
101
350
|
});
|
|
102
351
|
Object.defineProperty(exports, "ZeroConfigurationError", {
|
|
103
352
|
enumerable: true,
|
|
104
|
-
get: function () { return
|
|
353
|
+
get: function () { return chunkHKF4TRC6_cjs.ZeroConfigurationError; }
|
|
105
354
|
});
|
|
106
355
|
Object.defineProperty(exports, "ZeroError", {
|
|
107
356
|
enumerable: true,
|
|
108
|
-
get: function () { return
|
|
357
|
+
get: function () { return chunkHKF4TRC6_cjs.ZeroError; }
|
|
109
358
|
});
|
|
110
359
|
Object.defineProperty(exports, "ZeroPaymentError", {
|
|
111
360
|
enumerable: true,
|
|
112
|
-
get: function () { return
|
|
361
|
+
get: function () { return chunkHKF4TRC6_cjs.ZeroPaymentError; }
|
|
113
362
|
});
|
|
114
363
|
Object.defineProperty(exports, "ZeroSessionCloseFailedError", {
|
|
115
364
|
enumerable: true,
|
|
116
|
-
get: function () { return
|
|
365
|
+
get: function () { return chunkHKF4TRC6_cjs.ZeroSessionCloseFailedError; }
|
|
117
366
|
});
|
|
118
367
|
Object.defineProperty(exports, "ZeroTimeoutError", {
|
|
119
368
|
enumerable: true,
|
|
120
|
-
get: function () { return
|
|
369
|
+
get: function () { return chunkHKF4TRC6_cjs.ZeroTimeoutError; }
|
|
121
370
|
});
|
|
122
371
|
Object.defineProperty(exports, "ZeroValidationError", {
|
|
123
372
|
enumerable: true,
|
|
124
|
-
get: function () { return
|
|
373
|
+
get: function () { return chunkHKF4TRC6_cjs.ZeroValidationError; }
|
|
125
374
|
});
|
|
126
375
|
Object.defineProperty(exports, "ZeroWalletError", {
|
|
127
376
|
enumerable: true,
|
|
128
|
-
get: function () { return
|
|
377
|
+
get: function () { return chunkHKF4TRC6_cjs.ZeroWalletError; }
|
|
129
378
|
});
|
|
130
379
|
Object.defineProperty(exports, "asSchemaNode", {
|
|
131
380
|
enumerable: true,
|
|
132
|
-
get: function () { return
|
|
381
|
+
get: function () { return chunkHKF4TRC6_cjs.asSchemaNode; }
|
|
133
382
|
});
|
|
134
383
|
Object.defineProperty(exports, "coerceTempoChainId", {
|
|
135
384
|
enumerable: true,
|
|
136
|
-
get: function () { return
|
|
385
|
+
get: function () { return chunkHKF4TRC6_cjs.coerceTempoChainId; }
|
|
137
386
|
});
|
|
138
387
|
Object.defineProperty(exports, "createManagedAccount", {
|
|
139
388
|
enumerable: true,
|
|
140
|
-
get: function () { return
|
|
389
|
+
get: function () { return chunkHKF4TRC6_cjs.createManagedAccount; }
|
|
141
390
|
});
|
|
142
391
|
Object.defineProperty(exports, "extractInputEnvelope", {
|
|
143
392
|
enumerable: true,
|
|
144
|
-
get: function () { return
|
|
393
|
+
get: function () { return chunkHKF4TRC6_cjs.extractInputEnvelope; }
|
|
145
394
|
});
|
|
146
395
|
Object.defineProperty(exports, "isShortToken", {
|
|
147
396
|
enumerable: true,
|
|
148
|
-
get: function () { return
|
|
397
|
+
get: function () { return chunkHKF4TRC6_cjs.isShortToken; }
|
|
149
398
|
});
|
|
150
399
|
Object.defineProperty(exports, "normalizeTransportEnvelopeRequest", {
|
|
151
400
|
enumerable: true,
|
|
152
|
-
get: function () { return
|
|
401
|
+
get: function () { return chunkHKF4TRC6_cjs.normalizeTransportEnvelopeRequest; }
|
|
153
402
|
});
|
|
154
403
|
Object.defineProperty(exports, "paymentHasAnchor", {
|
|
155
404
|
enumerable: true,
|
|
156
|
-
get: function () { return
|
|
405
|
+
get: function () { return chunkHKF4TRC6_cjs.paymentHasAnchor; }
|
|
157
406
|
});
|
|
158
407
|
Object.defineProperty(exports, "tempoChainLabelFromId", {
|
|
159
408
|
enumerable: true,
|
|
160
|
-
get: function () { return
|
|
409
|
+
get: function () { return chunkHKF4TRC6_cjs.tempoChainLabelFromId; }
|
|
161
410
|
});
|
|
162
411
|
Object.defineProperty(exports, "unwrapTransportEnvelope", {
|
|
163
412
|
enumerable: true,
|
|
164
|
-
get: function () { return
|
|
413
|
+
get: function () { return chunkHKF4TRC6_cjs.unwrapTransportEnvelope; }
|
|
165
414
|
});
|
|
166
415
|
exports.AVAILABILITY_BADGES = AVAILABILITY_BADGES;
|
|
416
|
+
exports.centsToDollars = centsToDollars;
|
|
417
|
+
exports.coerceToType = coerceToType;
|
|
418
|
+
exports.constraintHint = constraintHint;
|
|
419
|
+
exports.detectAgentHost = detectAgentHost;
|
|
420
|
+
exports.formatCostLabel = formatCostLabel;
|
|
421
|
+
exports.formatRatingBadge = formatRatingBadge;
|
|
422
|
+
exports.formatRelativeTimestamp = formatRelativeTimestamp;
|
|
423
|
+
exports.formatReviewCount = formatReviewCount;
|
|
424
|
+
exports.inferSchema = inferSchema;
|
|
425
|
+
exports.paramAttrs = paramAttrs;
|
|
426
|
+
exports.placeholderFor = placeholderFor;
|
|
167
427
|
exports.preferHealthy = preferHealthy;
|
|
428
|
+
exports.redactUrl = redactUrl;
|
|
429
|
+
exports.sampleValueFor = sampleValueFor;
|
|
430
|
+
exports.schemaType = schemaType;
|
|
431
|
+
exports.schemaTypeLabel = schemaTypeLabel;
|
|
168
432
|
exports.sortByHealth = sortByHealth;
|
|
433
|
+
exports.truncateError = truncateError;
|
|
434
|
+
exports.tryParseJson = tryParseJson;
|
|
435
|
+
exports.urlMatchesTemplate = urlMatchesTemplate;
|
|
169
436
|
//# sourceMappingURL=index.cjs.map
|
|
170
437
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/status.ts"],"names":[],"mappings":";;;;;AAoCO,IAAM,mBAAA,GAAsB;AAAA,EAClC,SAAS,EAAE,MAAA,EAAQ,UAAK,KAAA,EAAO,OAAA,EAAS,OAAO,SAAA,EAAU;AAAA,EACzD,SAAS,EAAE,MAAA,EAAQ,KAAK,KAAA,EAAO,QAAA,EAAU,OAAO,SAAA,EAAU;AAAA,EAC1D,MAAM,EAAE,MAAA,EAAQ,UAAK,KAAA,EAAO,KAAA,EAAO,OAAO,MAAA;AAC3C;AAGA,IAAM,WAAA,GAAkD;AAAA,EACvD,OAAA,EAAS,CAAA;AAAA,EACT,OAAA,EAAS,CAAA;AAAA,EACT,IAAA,EAAM;AACP,CAAA;AAEA,IAAM,SAAS,CAAC,MAAA;AAAA;AAAA;AAAA,EAGf,MAAA,IAAU,IAAA,GAAO,WAAA,CAAY,OAAA,GAAU,YAAY,MAAM;AAAA,CAAA;AAUnD,IAAM,eAAe,CAG3B,KAAA,KAEA,CAAC,GAAG,KAAK,CAAA,CAAE,IAAA;AAAA,EACV,CAAC,GAAG,CAAA,KAAM,MAAA,CAAO,EAAE,kBAAkB,CAAA,GAAI,MAAA,CAAO,CAAA,CAAE,kBAAkB;AACrE;AAMM,IAAM,aAAA,GAAgB","file":"index.cjs","sourcesContent":["/**\n * Capability availability status — the single, consolidated health signal\n * Zero surfaces to clients (ZERO-89 / ZERO-92).\n *\n * - `healthy` — proven live and executable; safe to call.\n * - `unknown` — insufficient evidence either way; usable as a fallback.\n * - `down` — confirmed dead / failing; avoid.\n *\n * Preference rule for agents: PREFER `healthy`. Fall back to `unknown` only\n * when nothing `healthy` fits the task. Avoid `down`. This is the same rule the\n * server-side visibility filter enforces, surfaced here so agents and UIs can\n * rank consistently.\n */\nexport type AvailabilityStatus = \"healthy\" | \"unknown\" | \"down\";\n\n/** A renderable badge for an {@link AvailabilityStatus}. */\nexport type AvailabilityBadge = {\n\t/** A short glyph suitable for terminals/UI (✓ / ? / ✗). */\n\tsymbol: string;\n\t/**\n\t * A color *name* (not ANSI/hex) — this SDK is environment-agnostic, so\n\t * consumers map the name to whatever their renderer needs.\n\t */\n\tcolor: \"green\" | \"yellow\" | \"red\";\n\t/** Human-readable label. */\n\tlabel: string;\n};\n\n/**\n * Badge metadata for each {@link AvailabilityStatus}. Exhaustively keyed via\n * `satisfies` so adding/removing a status value is a compile error here.\n *\n * - healthy → green check\n * - unknown → yellow question\n * - down → red cross\n */\nexport const AVAILABILITY_BADGES = {\n\thealthy: { symbol: \"✓\", color: \"green\", label: \"Healthy\" },\n\tunknown: { symbol: \"?\", color: \"yellow\", label: \"Unknown\" },\n\tdown: { symbol: \"✗\", color: \"red\", label: \"Down\" },\n} as const satisfies Record<AvailabilityStatus, AvailabilityBadge>;\n\n// Lower rank sorts first: healthy ahead of unknown ahead of down.\nconst STATUS_RANK: Record<AvailabilityStatus, number> = {\n\thealthy: 0,\n\tunknown: 1,\n\tdown: 2,\n};\n\nconst rankOf = (status: AvailabilityStatus | null | undefined): number =>\n\t// Missing/null status is treated as `unknown` — \"we don't know\" ranks\n\t// above a confirmed `down` but below a proven `healthy`.\n\tstatus == null ? STATUS_RANK.unknown : STATUS_RANK[status];\n\n/**\n * Stable-sort capabilities by health: `healthy` > `unknown` > `down`.\n *\n * Agents should PREFER `healthy` and fall back to `unknown` only when nothing\n * `healthy` fits; `down` is last. A missing/null status is ranked as\n * `unknown`. Returns a NEW array — the input is not mutated. Items of equal\n * rank keep their original relative order (stable).\n */\nexport const sortByHealth = <\n\tT extends { availabilityStatus?: AvailabilityStatus | null },\n>(\n\titems: readonly T[],\n): T[] =>\n\t[...items].sort(\n\t\t(a, b) => rankOf(a.availabilityStatus) - rankOf(b.availabilityStatus),\n\t);\n\n/**\n * Alias for {@link sortByHealth}. The preference rule is \"prefer healthy, fall\n * back to unknown\" — applying it to a list means sorting healthy-first.\n */\nexport const preferHealthy = sortByHealth;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/status.ts","../src/utils/agent-host.ts","../src/utils/format-count.ts","../src/utils/format-price.ts","../src/utils/format-rating.ts","../src/utils/format-time.ts","../src/utils/infer-schema.ts","../src/utils/redact.ts","../src/utils/schema-describe.ts","../src/utils/schema-sample.ts","../src/utils/url-template.ts"],"names":["asSchemaNode"],"mappings":";;;;;AAoCO,IAAM,mBAAA,GAAsB;AAAA,EAClC,SAAS,EAAE,MAAA,EAAQ,UAAK,KAAA,EAAO,OAAA,EAAS,OAAO,SAAA,EAAU;AAAA,EACzD,SAAS,EAAE,MAAA,EAAQ,KAAK,KAAA,EAAO,QAAA,EAAU,OAAO,SAAA,EAAU;AAAA,EAC1D,MAAM,EAAE,MAAA,EAAQ,UAAK,KAAA,EAAO,KAAA,EAAO,OAAO,MAAA;AAC3C;AAGA,IAAM,WAAA,GAAkD;AAAA,EACvD,OAAA,EAAS,CAAA;AAAA,EACT,OAAA,EAAS,CAAA;AAAA,EACT,IAAA,EAAM;AACP,CAAA;AAEA,IAAM,SAAS,CAAC,MAAA;AAAA;AAAA;AAAA,EAGf,MAAA,IAAU,IAAA,GAAO,WAAA,CAAY,OAAA,GAAU,YAAY,MAAM;AAAA,CAAA;AAUnD,IAAM,eAAe,CAG3B,KAAA,KAEA,CAAC,GAAG,KAAK,CAAA,CAAE,IAAA;AAAA,EACV,CAAC,GAAG,CAAA,KAAM,MAAA,CAAO,EAAE,kBAAkB,CAAA,GAAI,MAAA,CAAO,CAAA,CAAE,kBAAkB;AACrE;AAMM,IAAM,aAAA,GAAgB;;;ACzDtB,IAAM,eAAA,GAAkB,CAC9B,GAAA,GAAyB,OAAA,CAAQ,GAAA,KAClB;AACf,EAAA,IAAI,GAAA,CAAI,UAAA,EAAY,OAAO,GAAA,CAAI,UAAA;AAC/B,EAAA,IAAI,GAAA,CAAI,UAAA,KAAe,GAAA,EAAK,OAAO,aAAA;AACnC,EAAA,IAAI,GAAA,CAAI,iBAAiB,OAAO,QAAA;AAChC,EAAA,IAAI,GAAA,CAAI,YAAA,KAAiB,QAAA,EAAU,OAAO,QAAA;AAC1C,EAAA,OAAO,SAAA;AACR;;;ACvBO,IAAM,i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e,SAAA,EAAW,UAAU,CAAC;;;AChFlD,IAAM,kBAAA,GAAqB,CAAC,GAAA,EAAa,QAAA,KAA8B;AAC7E,EAAA,MAAM,OAAA,GAAU,QAAA,CAAS,OAAA,CAAQ,qBAAA,EAAuB,MAAM,CAAA;AAC9D,EAAA,MAAM,YAAA,GAAe,OAAA,CAAQ,OAAA,CAAQ,mBAAA,EAAqB,OAAO,CAAA;AACjE,EAAA,OAAO,IAAI,MAAA,CAAO,CAAA,CAAA,EAAI,YAAY,CAAA,CAAA,CAAG,CAAA,CAAE,KAAK,GAAG,CAAA;AAChD","file":"index.cjs","sourcesContent":["/**\n * Capability availability status — the single, consolidated health signal\n * Zero surfaces to clients (ZERO-89 / ZERO-92).\n *\n * - `healthy` — proven live and executable; safe to call.\n * - `unknown` — insufficient evidence either way; usable as a fallback.\n * - `down` — confirmed dead / failing; avoid.\n *\n * Preference rule for agents: PREFER `healthy`. Fall back to `unknown` only\n * when nothing `healthy` fits the task. Avoid `down`. This is the same rule the\n * server-side visibility filter enforces, surfaced here so agents and UIs can\n * rank consistently.\n */\nexport type AvailabilityStatus = \"healthy\" | \"unknown\" | \"down\";\n\n/** A renderable badge for an {@link AvailabilityStatus}. */\nexport type AvailabilityBadge = {\n\t/** A short glyph suitable for terminals/UI (✓ / ? / ✗). */\n\tsymbol: string;\n\t/**\n\t * A color *name* (not ANSI/hex) — this SDK is environment-agnostic, so\n\t * consumers map the name to whatever their renderer needs.\n\t */\n\tcolor: \"green\" | \"yellow\" | \"red\";\n\t/** Human-readable label. */\n\tlabel: string;\n};\n\n/**\n * Badge metadata for each {@link AvailabilityStatus}. Exhaustively keyed via\n * `satisfies` so adding/removing a status value is a compile error here.\n *\n * - healthy → green check\n * - unknown → yellow question\n * - down → red cross\n */\nexport const AVAILABILITY_BADGES = {\n\thealthy: { symbol: \"✓\", color: \"green\", label: \"Healthy\" },\n\tunknown: { symbol: \"?\", color: \"yellow\", label: \"Unknown\" },\n\tdown: { symbol: \"✗\", color: \"red\", label: \"Down\" },\n} as const satisfies Record<AvailabilityStatus, AvailabilityBadge>;\n\n// Lower rank sorts first: healthy ahead of unknown ahead of down.\nconst STATUS_RANK: Record<AvailabilityStatus, number> = {\n\thealthy: 0,\n\tunknown: 1,\n\tdown: 2,\n};\n\nconst rankOf = (status: AvailabilityStatus | null | undefined): number =>\n\t// Missing/null status is treated as `unknown` — \"we don't know\" ranks\n\t// above a confirmed `down` but below a proven `healthy`.\n\tstatus == null ? STATUS_RANK.unknown : STATUS_RANK[status];\n\n/**\n * Stable-sort capabilities by health: `healthy` > `unknown` > `down`.\n *\n * Agents should PREFER `healthy` and fall back to `unknown` only when nothing\n * `healthy` fits; `down` is last. A missing/null status is ranked as\n * `unknown`. Returns a NEW array — the input is not mutated. Items of equal\n * rank keep their original relative order (stable).\n */\nexport const sortByHealth = <\n\tT extends { availabilityStatus?: AvailabilityStatus | null },\n>(\n\titems: readonly T[],\n): T[] =>\n\t[...items].sort(\n\t\t(a, b) => rankOf(a.availabilityStatus) - rankOf(b.availabilityStatus),\n\t);\n\n/**\n * Alias for {@link sortByHealth}. The preference rule is \"prefer healthy, fall\n * back to unknown\" — applying it to a list means sorting healthy-first.\n */\nexport const preferHealthy = sortByHealth;\n","// Detect which agent host is invoking the SDK at runtime.\n//\n// Resolution is deliberately stateless — no persisted config. Anything\n// long-lived risks going stale when an agent moves between sandboxes.\n//\n// Resolution order (highest priority first):\n// 1. ZERO_AGENT env var (per-invocation prefix or per-session export)\n// 2. Host-specific env signals (CLAUDECODE=1, CURSOR_TRACE_ID,\n// TERM_PROGRAM=vscode) that the host sets per-session\n// 3. \"unknown\"\n//\n// Canonical names: claude-code, cursor, vscode, claude-web, codex, opencode.\n// Arbitrary strings are accepted (self-identified); dashboards group by value.\n\n/** @internal Zero-surface helper — not part of the supported partner contract. */\nexport type AgentHost = string;\n\n/** @internal Zero-surface helper — not part of the supported partner contract. */\nexport const detectAgentHost = (\n\tenv: NodeJS.ProcessEnv = process.env,\n): AgentHost => {\n\tif (env.ZERO_AGENT) return env.ZERO_AGENT;\n\tif (env.CLAUDECODE === \"1\") return \"claude-code\";\n\tif (env.CURSOR_TRACE_ID) return \"cursor\";\n\tif (env.TERM_PROGRAM === \"vscode\") return \"vscode\";\n\treturn \"unknown\";\n};\n","// Compact number formatter for review/run counts. Collapses ≥1000 to one\n// decimal \"k\" (e.g. 1234 → \"1.2k\") so result lists stay scannable.\n/** @internal Zero-surface helper — not part of the supported partner contract. */\nexport const formatReviewCount = (count: number): string => {\n\tif (count >= 1000) return `${(count / 1000).toFixed(1)}k`;\n\treturn count.toString();\n};\n","/**\n * Convert a cents string (4-decimal precision per the API's `microsToCents`)\n * to a dollar-amount string with enough decimal places that sub-cent\n * token-metered charges don't silently round to zero or get overstated.\n *\n * Precision ladder (matches `services/web/src/app/c/[slug]/page.tsx`):\n * value >= 1 → toFixed(2) — normal dollar amounts (\"5.00\")\n * value >= 0.01 → toFixed(3) — sub-dollar (\"0.500\")\n * value >= 0.001 → toFixed(4) — sub-cent (\"0.0050\")\n * value >= 0.0001 → toFixed(5) — sub-millicent (\"0.00050\")\n * else → toFixed(6) — micro-dollar floor (\"0.000005\")\n *\n * Honest signal beats pretty zeros. We accept the ugly trailing decimals\n * because the alternative — `.toFixed(4)` flooring at $0.0001 — silently\n * misreports per-token LLM charges as ~2× their actual cost (or as zero).\n *\n * All price-rendering surfaces (CLI, web, SDK consumers) should use this\n * function so the same capability never shows a different price depending\n * on which surface the agent uses.\n */\nexport const centsToDollars = (cents: string): string => {\n\tconst value = Number.parseFloat(cents) / 100;\n\tif (!Number.isFinite(value) || value === 0) return \"0.00\";\n\tif (value < 0.0001) return value.toFixed(6);\n\tif (value < 0.001) return value.toFixed(5);\n\tif (value < 0.01) return value.toFixed(4);\n\tif (value < 1) return value.toFixed(3);\n\treturn value.toFixed(2);\n};\n\n/**\n * Human-readable label for a search-row cost amount, interpreting the\n * server's sentinel values: `\"0\"` means the cap is free, `\"unknown\"` means\n * the upstream advertised dynamic/per-token pricing without revealing a\n * concrete number. Any other value is a decimal USD amount per call.\n *\n * The sentinel interpretation is part of the server contract — every\n * consumer (CLI, MCP plugin, QA harness) must map them the same way or an\n * agent sees \"$unknown\" for a variable-priced cap on one surface and\n * \"variable pricing\" on another.\n */\n/** @internal Zero-surface helper — not part of the supported partner contract. */\nexport const formatCostLabel = (amount: string): string => {\n\tif (amount === \"0\") return \"Free\";\n\tif (amount === \"unknown\") return \"variable pricing\";\n\treturn `$${amount}/call`;\n};\n","import { formatReviewCount } from \"./format-count\";\n\n// Structural subset of the API's rating shape shared by search rows and the\n// capability detail response. `score` (present on the full Rating) isn't\n// needed to render the badge, so it's not required here.\n/** @internal Zero-surface helper — not part of the supported partner contract. */\nexport type RatingBadgeInput = {\n\tsuccessRate: string;\n\treviews: number;\n\tstars?: string | null;\n\tstate?: \"unrated\" | \"rated\";\n};\n\n/**\n * One-line rating badge: `★ 4.1/5 (91% success, 42 reviews)` when a star\n * score exists, `91% success · 42 reviews` otherwise, `unrated` when the cap\n * has no rating yet. Shared so all consumers render the same rating for the\n * same capability.\n */\n/** @internal Zero-surface helper — not part of the supported partner contract. */\nexport const formatRatingBadge = (rating: RatingBadgeInput): string => {\n\tif (rating.state === \"unrated\") return \"unrated\";\n\tconst successPct = `${Math.round(Number.parseFloat(rating.successRate) * 100)}%`;\n\tconst reviews = formatReviewCount(rating.reviews);\n\tif (rating.stars) {\n\t\treturn `★ ${rating.stars}/5 (${successPct} success, ${reviews} reviews)`;\n\t}\n\treturn `${successPct} success · ${reviews} reviews`;\n};\n","// Converts an ISO timestamp (or null/undefined) to a compact relative string\n// (\"5m ago\", \"3d ago\", \"never\"). No terminal I/O — safe for any consumer.\n/** @internal Zero-surface helper — not part of the supported partner contract. */\nexport const formatRelativeTimestamp = (\n\tiso: string | null | undefined,\n): string => {\n\tif (!iso) return \"never\";\n\tconst then = new Date(iso).getTime();\n\tif (Number.isNaN(then)) return \"never\";\n\tconst diffSec = Math.max(0, Math.round((Date.now() - then) / 1000));\n\tif (diffSec < 60) return `${diffSec}s ago`;\n\tconst diffMin = Math.round(diffSec / 60);\n\tif (diffMin < 60) return `${diffMin}m ago`;\n\tconst diffHr = Math.round(diffMin / 60);\n\tif (diffHr < 24) return `${diffHr}h ago`;\n\tconst diffDay = Math.round(diffHr / 24);\n\tif (diffDay < 30) return `${diffDay}d ago`;\n\tconst diffMo = Math.round(diffDay / 30);\n\tif (diffMo < 12) return `${diffMo}mo ago`;\n\treturn `${Math.round(diffMo / 12)}y ago`;\n};\n","/**\n * Deterministic structural walk of a JSON value → JSON-schema-ish draft.\n *\n * Used to send anonymized shape information (field names + types, no values)\n * to the server after a capability execution. Mirrors the server-side\n * inference in services/api.\n */\nexport const inferSchema = (\n\tvalue: unknown,\n\tdepth = 0,\n): Record<string, unknown> => {\n\tif (depth > 6) return { type: typeOf(value) };\n\tif (value === null) return { type: \"null\" };\n\tif (Array.isArray(value)) {\n\t\tconst itemSchemas = value.slice(0, 3).map((v) => inferSchema(v, depth + 1));\n\t\treturn {\n\t\t\ttype: \"array\",\n\t\t\titems: itemSchemas[0] ?? { type: \"unknown\" },\n\t\t};\n\t}\n\tif (typeof value === \"object\") {\n\t\tconst obj = value as Record<string, unknown>;\n\t\tconst properties: Record<string, unknown> = {};\n\t\tconst required: string[] = [];\n\t\tfor (const [k, v] of Object.entries(obj)) {\n\t\t\tproperties[k] = inferSchema(v, depth + 1);\n\t\t\trequired.push(k);\n\t\t}\n\t\treturn { type: \"object\", properties, required };\n\t}\n\treturn { type: typeOf(value) };\n};\n\nconst typeOf = (v: unknown): string => {\n\tif (v === null) return \"null\";\n\tif (Array.isArray(v)) return \"array\";\n\treturn typeof v;\n};\n\nexport const tryParseJson = (text: string): unknown => {\n\ttry {\n\t\treturn JSON.parse(text);\n\t} catch {\n\t\treturn null;\n\t}\n};\n","// PII-reduction helpers for analytics and logging. These constants and\n// functions apply the same policy regardless of which surface (CLI, MCP,\n// raw SDK) is building the event payload.\n\nconst ERROR_MAX = 500;\n\n// Strip query string + hash from a URL. Keeps protocol + host + pathname so\n// events can still be attributed to the right endpoint, but drops any\n// `?api_key=...` / user-supplied params that might be PII.\n/** @internal Zero-surface helper — not part of the supported partner contract. */\nexport const redactUrl = (raw: string): string => {\n\ttry {\n\t\tconst parsed = new URL(raw);\n\t\treturn `${parsed.origin}${parsed.pathname}`;\n\t} catch {\n\t\treturn raw;\n\t}\n};\n\n// Error messages are low-risk (usually stack traces / HTTP bodies) but can\n// leak absolute paths or inline data. Hard-cap at 500 chars.\n/** @internal Zero-surface helper — not part of the supported partner contract. */\nexport const truncateError = (raw: string): string =>\n\traw.length > ERROR_MAX ? `${raw.slice(0, ERROR_MAX)}…` : raw;\n","import type { JsonSchemaNode } from \"../input-envelope\";\n\n// Human/agent-readable type label, preserving unions (e.g. \"string | null\").\nexport const schemaTypeLabel = (node: JsonSchemaNode): string => {\n\tconst t = node.type;\n\tif (typeof t === \"string\") return t;\n\tif (Array.isArray(t)) {\n\t\tconst parts = t.filter((x): x is string => typeof x === \"string\");\n\t\treturn parts.length > 0 ? parts.join(\" | \") : \"any\";\n\t}\n\treturn \"any\";\n};\n\n// Compact constraint hints (numeric range, exclusive bounds, string/array\n// length, regex pattern) — every constraint the agent must satisfy to avoid a\n// charged 400. Collects ALL applicable hints, not just the first.\nexport const constraintHint = (node: JsonSchemaNode): string | null => {\n\tconst num = (k: string): number | undefined =>\n\t\ttypeof node[k] === \"number\" ? (node[k] as number) : undefined;\n\tconst hints: string[] = [];\n\tconst min = num(\"minimum\");\n\tconst max = num(\"maximum\");\n\tif (min !== undefined && max !== undefined)\n\t\thints.push(`range: ${min}..${max}`);\n\telse if (min !== undefined) hints.push(`min: ${min}`);\n\telse if (max !== undefined) hints.push(`max: ${max}`);\n\tconst exMin = num(\"exclusiveMinimum\");\n\tconst exMax = num(\"exclusiveMaximum\");\n\tif (exMin !== undefined) hints.push(`> ${exMin}`);\n\tif (exMax !== undefined) hints.push(`< ${exMax}`);\n\tconst minLen = num(\"minLength\");\n\tconst maxLen = num(\"maxLength\");\n\tif (minLen !== undefined && maxLen !== undefined)\n\t\thints.push(`length: ${minLen}..${maxLen}`);\n\telse if (maxLen !== undefined) hints.push(`maxLength: ${maxLen}`);\n\telse if (minLen !== undefined) hints.push(`minLength: ${minLen}`);\n\tconst minItems = num(\"minItems\");\n\tconst maxItems = num(\"maxItems\");\n\tif (minItems !== undefined && maxItems !== undefined)\n\t\thints.push(`items: ${minItems}..${maxItems}`);\n\telse if (maxItems !== undefined) hints.push(`maxItems: ${maxItems}`);\n\telse if (minItems !== undefined) hints.push(`minItems: ${minItems}`);\n\tif (typeof node.pattern === \"string\") hints.push(`pattern: ${node.pattern}`);\n\treturn hints.length > 0 ? hints.join(\", \") : null;\n};\n\n// The single-field attrs line: type, required, const (exact value the agent\n// MUST send), default, enum, format, and numeric/length constraints.\nexport const paramAttrs = (node: JsonSchemaNode, required: boolean): string => {\n\tconst attrs: string[] = [schemaTypeLabel(node)];\n\tif (required) attrs.push(\"required\");\n\tif (node.const !== undefined)\n\t\tattrs.push(`const: ${JSON.stringify(node.const)}`);\n\tif (node.default !== undefined)\n\t\tattrs.push(`default: ${JSON.stringify(node.default)}`);\n\tif (Array.isArray(node.enum))\n\t\tattrs.push(`one of: ${node.enum.map((v) => String(v)).join(\" | \")}`);\n\tif (typeof node.format === \"string\") attrs.push(`format: ${node.format}`);\n\tconst hint = constraintHint(node);\n\tif (hint) attrs.push(hint);\n\treturn attrs.join(\", \");\n};\n","import { asSchemaNode, type JsonSchemaNode } from \"../input-envelope\";\n\n// JSON Schema `type` may be a string (\"number\") or an array ([\"string\",\"null\"]).\n// Return the first concrete, non-null type.\nexport const schemaType = (node: JsonSchemaNode | null): string | undefined => {\n\tconst t = node?.type;\n\tif (typeof t === \"string\") return t;\n\tif (Array.isArray(t)) {\n\t\tconst first = t.find((x) => typeof x === \"string\" && x !== \"null\");\n\t\treturn typeof first === \"string\" ? first : undefined;\n\t}\n\treturn undefined;\n};\n\n// Coerce a stored example/default to its declared schema type. Some capabilities\n// store typed examples as strings (e.g. boolean `suggest` as \"false\"); without\n// this an agent copies the over-quoted value verbatim and gets a charged HTTP 400.\nexport const coerceToType = (\n\tvalue: unknown,\n\ttype: string | undefined,\n): unknown => {\n\tif (typeof value !== \"string\") return value;\n\tif (type === \"number\" || type === \"integer\") {\n\t\tconst n = Number(value);\n\t\treturn value.trim() !== \"\" && Number.isFinite(n) ? n : value;\n\t}\n\tif (type === \"boolean\") {\n\t\tif (value === \"true\") return true;\n\t\tif (value === \"false\") return false;\n\t}\n\treturn value;\n};\n\nconst MAX_SCHEMA_DEPTH = 5;\n\n// Build a correctly-typed sample value for a field. Prefers const → example/default\n// → first enum option → per-type placeholder. Recurses into nested objects/arrays.\n// Used to render \"Try it:\" request bodies so JSON.stringify emits numbers/booleans\n// unquoted, avoiding the charged HTTP 400s caused by over-quoted values (ZERO-339).\nexport const sampleValueFor = (\n\tfieldName: string,\n\tpropSchema: unknown,\n\tdepth = 0,\n): unknown => {\n\tconst node = asSchemaNode(propSchema);\n\tconst type = schemaType(node);\n\tconst enumFirst =\n\t\tArray.isArray(node?.enum) && node.enum.length > 0\n\t\t\t? node.enum[0]\n\t\t\t: undefined;\n\tconst fixed = node?.const ?? node?.example ?? node?.default ?? enumFirst;\n\tif (fixed !== undefined && fixed !== null) {\n\t\treturn coerceToType(fixed, type);\n\t}\n\tif (node && depth < MAX_SCHEMA_DEPTH) {\n\t\tconst props = asSchemaNode(node.properties);\n\t\tif (props && (type === \"object\" || type === undefined)) {\n\t\t\tconst obj: Record<string, unknown> = {};\n\t\t\tfor (const [k, sub] of Object.entries(props)) {\n\t\t\t\tobj[k] = sampleValueFor(k, sub, depth + 1);\n\t\t\t}\n\t\t\treturn obj;\n\t\t}\n\t\tif (type === \"array\") {\n\t\t\tconst items = asSchemaNode(node.items);\n\t\t\treturn items ? [sampleValueFor(fieldName, items, depth + 1)] : [];\n\t\t}\n\t}\n\tswitch (type) {\n\t\tcase \"number\":\n\t\tcase \"integer\":\n\t\t\treturn 0;\n\t\tcase \"boolean\":\n\t\t\treturn false;\n\t\tcase \"array\":\n\t\t\treturn [];\n\t\tcase \"object\":\n\t\t\treturn {};\n\t\tdefault:\n\t\t\treturn `<${fieldName.toUpperCase()}>`;\n\t}\n};\n\n// String form for URL query params, which are always strings on the wire.\nexport const placeholderFor = (\n\tfieldName: string,\n\tpropSchema: unknown,\n): string => String(sampleValueFor(fieldName, propSchema));\n","/**\n * Match a fetched URL against a urlTemplate like `/users/{handle}`.\n * `{name}` placeholders match a single non-`/` segment. Everything else is\n * regex-escaped so dots in hosts can't act as wildcards. Mirrors the\n * server-side `templateToRegex` in capability-service.ts so CLI and SDK\n * consumers agree on what counts as a match.\n */\nexport const urlMatchesTemplate = (url: string, template: string): boolean => {\n\tconst escaped = template.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\tconst withCaptures = escaped.replace(/\\\\\\{[^/\\\\}]+\\\\\\}/g, \"[^/]+\");\n\treturn new RegExp(`^${withCaptures}$`).test(url);\n};\n"]}
|