@guren/server 2.13.0 → 2.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Hash-CzrwKeDp.js → Hash-C8aejmi8.js} +5 -0
- package/dist/{McpServiceProvider-D6D9nhgn.js → McpServiceProvider-BawsYjgN.js} +72 -0
- package/dist/agent/AgentApprovalRequested.d.ts +59 -0
- package/dist/agent/approval.d.ts +295 -0
- package/dist/agent/audit-emitter.d.ts +64 -0
- package/dist/agent/audit.d.ts +103 -0
- package/dist/agent/derive.d.ts +155 -0
- package/dist/agent/dispatch.d.ts +165 -0
- package/dist/agent/events.d.ts +80 -0
- package/dist/agent/meta-tools.d.ts +62 -0
- package/dist/agent/public.d.ts +33 -0
- package/dist/agent/public.js +2 -0
- package/dist/agent/redact.d.ts +55 -0
- package/dist/agent/scopes.d.ts +115 -0
- package/dist/auth/AuthManager.d.ts +64 -0
- package/dist/auth/RequestAuthContext.d.ts +3 -5
- package/dist/auth/TokenGuard.d.ts +61 -0
- package/dist/auth/api-token.d.ts +25 -5
- package/dist/auth/context.d.ts +24 -0
- package/dist/auth/index.d.ts +5 -2
- package/dist/auth/index.js +2 -2
- package/dist/auth/password/DefaultHasher.d.ts +18 -5
- package/dist/auth/password/PasswordHasher.d.ts +15 -0
- package/dist/auth/password/hash-format.d.ts +19 -0
- package/dist/auth/providers/UserProvider.d.ts +7 -0
- package/dist/auth/types.d.ts +6 -0
- package/dist/{auth-C7sVmYgc.js → auth-DkYoAPVn.js} +431 -151
- package/dist/authorization/index.js +1 -1
- package/dist/authorization/middleware.d.ts +28 -1
- package/dist/{authorization-Dbcuc5ZK.js → authorization-CdfbCj8J.js} +119 -12
- package/dist/broadcasting/index.js +1 -1
- package/dist/{broadcasting-Dw-FhyjN.js → broadcasting-BwodCA4q.js} +2 -45
- package/dist/container/bindings.d.ts +19 -0
- package/dist/context-DoD0c7J_.js +26 -0
- package/dist/dispatch-erOS9epZ.js +285 -0
- package/dist/encryption/index.js +2 -2
- package/dist/{encryption-DJtkkhiw.js → encryption-D99Vmls3.js} +4 -1
- package/dist/http/dev-assets.d.ts +16 -0
- package/dist/http/middleware/auth.d.ts +2 -2
- package/dist/http/middleware/capabilities.d.ts +57 -0
- package/dist/http/middleware/csrf.d.ts +3 -0
- package/dist/http/public-assets.d.ts +10 -0
- package/dist/http/request.d.ts +139 -3
- package/dist/http/static-documents.d.ts +31 -0
- package/dist/index.d.ts +21 -4
- package/dist/index.js +1302 -118
- package/dist/internal/agent-preflight.d.ts +28 -0
- package/dist/internal/request.d.ts +25 -0
- package/dist/internal/request.js +2 -0
- package/dist/internal/route-path.d.ts +28 -0
- package/dist/internal/route-path.js +33 -0
- package/dist/internal/zod-compat.d.ts +201 -0
- package/dist/internal/zod-compat.js +193 -0
- package/dist/internal/zod-json-schema.d.ts +102 -0
- package/dist/internal/zod-json-schema.js +461 -0
- package/dist/logging/channels/DailyFileChannel.d.ts +0 -2
- package/dist/logging/daily-file-path.d.ts +24 -0
- package/dist/logging/index.d.ts +1 -0
- package/dist/logging/index.js +2 -2
- package/dist/{logging-CPaRMuPP.js → logging-B-kngi3q.js} +61 -18
- package/dist/mcp/create-mcp-server.d.ts +29 -0
- package/dist/mcp/index.js +1 -1
- package/dist/mvc/Controller.d.ts +20 -0
- package/dist/mvc/Router.d.ts +53 -0
- package/dist/request-CVQwpu2J.js +129 -0
- package/dist/runtime/index.js +94 -15
- package/dist/{vite-manifest-gdONBsM3.js → vite-manifest-w_RSOvQW.js} +1 -1
- package/package.json +22 -2
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import { SINGLE_CHILD_WRAPPERS, ZOD3_UNSUPPORTED_MESSAGE, arrayElement, enumValues, getTypeName, innerSchema, isZod3Schema, literalValues, objectShape, pipeSides, recordValueType, schemaChecks, schemaFormat, typeOf, unwrapSingleChild } from "./zod-compat.js";
|
|
2
|
+
//#region src/internal/zod-json-schema.ts
|
|
3
|
+
/**
|
|
4
|
+
* The one Zod → JSON Schema rule, shared by every surface that has to describe
|
|
5
|
+
* an application's contracts to something outside the process: `@guren/openapi`
|
|
6
|
+
* renders it as OpenAPI 3.1 schema objects (which *are* JSON Schema 2020-12),
|
|
7
|
+
* and RFC 0016's agent tools advertise it as MCP input/output schemas.
|
|
8
|
+
*
|
|
9
|
+
* Internal by the rules in `contributing/api-stability.md`: reachable only
|
|
10
|
+
* through a deep import under `internal/`, never re-exported from
|
|
11
|
+
* `@guren/server`'s or `@guren/core`'s index. No stability guarantee — it
|
|
12
|
+
* exists so two derivations of the same schema cannot disagree, not as a
|
|
13
|
+
* public extension point. That is the whole reason it was promoted out of
|
|
14
|
+
* `@guren/openapi`: a second walker is how an agent tool comes to advertise a
|
|
15
|
+
* schema the documented API contradicts.
|
|
16
|
+
*
|
|
17
|
+
* It lives in `@guren/server` rather than `@guren/core` (where RFC 0016 §2
|
|
18
|
+
* first placed it) for a build-order reason, not a layering one. Core's index
|
|
19
|
+
* is `export * from '@guren/server'`, so core builds *after* server and a
|
|
20
|
+
* server module cannot import a core one — the edge would close a cycle, and
|
|
21
|
+
* server's declaration build (`tsc -p tsconfig.build.json`, `paths: {}`)
|
|
22
|
+
* would look for a core `dist/` that does not exist yet. `deriveAgentTools`
|
|
23
|
+
* lives in `@guren/server`, so the walker had to move down to the package
|
|
24
|
+
* both it and the OpenAPI generator can see. `@guren/core/internal/*`
|
|
25
|
+
* re-exports this module, which keeps that the specifier every consumer
|
|
26
|
+
* outside this package writes.
|
|
27
|
+
*
|
|
28
|
+
* Every `_def` read goes through `zod-compat.ts`, including the check reads
|
|
29
|
+
* this module added. Reaching into `_def` here would put zod-layout knowledge
|
|
30
|
+
* in two places, which is exactly the split `zod-compat` exists to prevent.
|
|
31
|
+
*
|
|
32
|
+
* Zod 4 only, and a v3 node is *refused* rather than walked — on v3 `_def.type`
|
|
33
|
+
* holds a nested schema where v4 keeps the type name, so every read below would
|
|
34
|
+
* misfire and produce a confidently wrong document. The refusal is re-checked
|
|
35
|
+
* at each recursion, because a v3 node can hide inside a v4 wrapper.
|
|
36
|
+
*
|
|
37
|
+
* What this module does not decide: what a caller does with the warnings, and
|
|
38
|
+
* how the result is embedded (a `requestBody` content map, an MCP `inputSchema`).
|
|
39
|
+
* Warnings are appended to a caller-owned array so a document generator can
|
|
40
|
+
* surface them per request and a codegen step can fail on them.
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* Zod's string formats mapped to the JSON Schema `format` names that mean the
|
|
44
|
+
* same thing, matched against zod's own `z.toJSONSchema()` output so the two
|
|
45
|
+
* cannot disagree about, say, whether `z.url()` is `"url"` or `"uri"`.
|
|
46
|
+
*
|
|
47
|
+
* The line is "registered by JSON Schema 2020-12", not "short". Zod carries
|
|
48
|
+
* plenty of formats the spec has never registered (`cuid`, `nanoid`, `emoji`,
|
|
49
|
+
* `ulid`, `jwt`, `base64`…), and emitting those verbatim advertises a
|
|
50
|
+
* constraint no consumer can interpret — an agent reading `format: "cuid"`
|
|
51
|
+
* learns nothing it can act on, while the `type: "string"` it already had stays
|
|
52
|
+
* true. Unmapped formats are dropped, not warned about: the schema is still
|
|
53
|
+
* correct, just less specific.
|
|
54
|
+
*
|
|
55
|
+
* `time` is the one registered format deliberately left out, and zod omits it
|
|
56
|
+
* from its own output for the same reason: JSON Schema's `time` is an RFC 3339
|
|
57
|
+
* `full-time`, which requires an offset, while `z.iso.time()` accepts a local
|
|
58
|
+
* wall-clock time. Claiming the format would assert an offset the schema does
|
|
59
|
+
* not require.
|
|
60
|
+
*/
|
|
61
|
+
const JSON_SCHEMA_STRING_FORMATS = {
|
|
62
|
+
email: "email",
|
|
63
|
+
url: "uri",
|
|
64
|
+
uuid: "uuid",
|
|
65
|
+
datetime: "date-time",
|
|
66
|
+
date: "date",
|
|
67
|
+
duration: "duration",
|
|
68
|
+
hostname: "hostname",
|
|
69
|
+
ipv4: "ipv4",
|
|
70
|
+
ipv6: "ipv6"
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The `number_format` values that describe an integer. JSON Schema says this
|
|
74
|
+
* with a *type*, not a format, so these change `type: "number"` to
|
|
75
|
+
* `type: "integer"` — a `z.int()` that documents as `number` advertises a
|
|
76
|
+
* contract admitting `3.14`, which the route then rejects.
|
|
77
|
+
*
|
|
78
|
+
* `float32` / `float64` are the other half of the same zod vocabulary and stay
|
|
79
|
+
* plain numbers. The bounds each of these formats implies (zod's own emitter
|
|
80
|
+
* adds `minimum: -2147483648` for `int32`, and the safe-integer range for
|
|
81
|
+
* `safeint`) are deliberately not emitted: they are the representation's
|
|
82
|
+
* limits rather than the application's contract, and they bury the constraints
|
|
83
|
+
* an author actually wrote. `int64` / `uint64` need no entry — they sit on
|
|
84
|
+
* `bigint` nodes, which this walker already renders as `integer`.
|
|
85
|
+
*/
|
|
86
|
+
const INTEGER_NUMBER_FORMATS = /* @__PURE__ */ new Set([
|
|
87
|
+
"safeint",
|
|
88
|
+
"int32",
|
|
89
|
+
"uint32"
|
|
90
|
+
]);
|
|
91
|
+
/**
|
|
92
|
+
* The string formats whose zod-supplied regex is worth carrying as `pattern` —
|
|
93
|
+
* the ones a user *wrote as a pattern* (`.regex()`) or as a prefix/suffix/
|
|
94
|
+
* substring test, which zod stores only as a compiled regex.
|
|
95
|
+
*
|
|
96
|
+
* The registered formats above are excluded on purpose even though zod exposes
|
|
97
|
+
* a pattern for them too: their regexes run to hundreds of characters (the
|
|
98
|
+
* `datetime` one alone is ~300), they are zod's parsing implementation rather
|
|
99
|
+
* than the contract, and `format` already says the same thing in a word.
|
|
100
|
+
*/
|
|
101
|
+
const PATTERN_BEARING_FORMATS = /* @__PURE__ */ new Set([
|
|
102
|
+
"regex",
|
|
103
|
+
"starts_with",
|
|
104
|
+
"ends_with",
|
|
105
|
+
"includes"
|
|
106
|
+
]);
|
|
107
|
+
/**
|
|
108
|
+
* Turn a Zod schema into a JSON Schema object, appending a line to `warnings`
|
|
109
|
+
* for anything it cannot express. `label` names the schema in those warnings
|
|
110
|
+
* (`"POST /posts body.title"`); `io` picks the side of coercing and piped
|
|
111
|
+
* schemas to describe — `input` is what a caller sends, `output` what a parse
|
|
112
|
+
* produces.
|
|
113
|
+
*
|
|
114
|
+
* Returns `undefined` when the node contributes nothing (a bare `z.undefined()`)
|
|
115
|
+
* or could not be read; a caller treats that as "omit this property".
|
|
116
|
+
*/
|
|
117
|
+
function toJsonSchema(schema, warnings, label, io) {
|
|
118
|
+
if (warnIfZod3(schema, warnings, label)) return;
|
|
119
|
+
if (!isZodSchema(schema)) {
|
|
120
|
+
warnings.push(`${label}: skipped because schema is not a supported Zod schema.`);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const typeName = typeOf(schema);
|
|
124
|
+
const def = schema._def ?? {};
|
|
125
|
+
if (typeName !== "nullable" && SINGLE_CHILD_WRAPPERS.has(typeName)) {
|
|
126
|
+
const nested = unwrapSingleChild(schema, io);
|
|
127
|
+
if (!nested) {
|
|
128
|
+
warnings.push(`${label}: the contents of a "${typeName}" schema could not be read, so it is omitted.`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
return toJsonSchema(nested, warnings, label, io);
|
|
132
|
+
}
|
|
133
|
+
switch (typeName) {
|
|
134
|
+
case "string": return {
|
|
135
|
+
type: "string",
|
|
136
|
+
...stringConstraints(schema)
|
|
137
|
+
};
|
|
138
|
+
case "number": return numberSchema(schema);
|
|
139
|
+
case "boolean": return { type: "boolean" };
|
|
140
|
+
case "bigint": return { type: "integer" };
|
|
141
|
+
case "date": return {
|
|
142
|
+
type: "string",
|
|
143
|
+
format: "date-time"
|
|
144
|
+
};
|
|
145
|
+
case "undefined": return;
|
|
146
|
+
case "null": return { type: "null" };
|
|
147
|
+
case "literal": return literalSchema(def);
|
|
148
|
+
case "array": return {
|
|
149
|
+
type: "array",
|
|
150
|
+
items: toJsonSchema(arrayElement(def), warnings, `${label}[]`, io) ?? {},
|
|
151
|
+
...lengthConstraints(schemaChecks(schema), "minItems", "maxItems")
|
|
152
|
+
};
|
|
153
|
+
case "object": {
|
|
154
|
+
const details = readObjectSchemaDetails(schema, warnings, label, io);
|
|
155
|
+
if (!details) return { type: "object" };
|
|
156
|
+
return {
|
|
157
|
+
type: "object",
|
|
158
|
+
properties: details.properties,
|
|
159
|
+
required: details.required.size > 0 ? Array.from(details.required) : void 0
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
case "nullable": {
|
|
163
|
+
const nested = unwrapSingleChild(schema, io);
|
|
164
|
+
const nestedSchema = nested ? toJsonSchema(nested, warnings, label, io) : void 0;
|
|
165
|
+
return nestedSchema ? { anyOf: [nestedSchema, { type: "null" }] } : { type: ["null"] };
|
|
166
|
+
}
|
|
167
|
+
case "transform":
|
|
168
|
+
warnings.push(`${label}: transform schemas are documented as generic objects.`);
|
|
169
|
+
return { type: "object" };
|
|
170
|
+
case "union": {
|
|
171
|
+
const oneOf = (def.options ?? []).map((option, index) => toJsonSchema(option, warnings, `${label}.option${index}`, io)).filter((option) => Boolean(option));
|
|
172
|
+
return oneOf.length > 0 ? { oneOf } : void 0;
|
|
173
|
+
}
|
|
174
|
+
case "intersection": {
|
|
175
|
+
const allOf = [toJsonSchema(def.left, warnings, `${label}.left`, io), toJsonSchema(def.right, warnings, `${label}.right`, io)].filter((value) => Boolean(value));
|
|
176
|
+
return allOf.length > 0 ? { allOf } : void 0;
|
|
177
|
+
}
|
|
178
|
+
case "record": return {
|
|
179
|
+
type: "object",
|
|
180
|
+
additionalProperties: toJsonSchema(recordValueType(def), warnings, `${label}.value`, io) ?? true
|
|
181
|
+
};
|
|
182
|
+
case "enum": {
|
|
183
|
+
const values = enumValues(schema);
|
|
184
|
+
if (values.length === 0) return { type: "string" };
|
|
185
|
+
const hasNumber = values.some((value) => typeof value === "number");
|
|
186
|
+
const hasString = values.some((value) => typeof value === "string");
|
|
187
|
+
if (hasNumber && hasString) return {
|
|
188
|
+
type: ["string", "number"],
|
|
189
|
+
enum: values
|
|
190
|
+
};
|
|
191
|
+
return {
|
|
192
|
+
type: hasNumber ? "number" : "string",
|
|
193
|
+
enum: values
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
case "tuple": {
|
|
197
|
+
const items = (def.items ?? []).map((item, index) => toJsonSchema(item, warnings, `${label}[${index}]`, io)).filter((item) => Boolean(item));
|
|
198
|
+
return {
|
|
199
|
+
type: "array",
|
|
200
|
+
prefixItems: items,
|
|
201
|
+
minItems: items.length,
|
|
202
|
+
maxItems: items.length
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
case "promise": {
|
|
206
|
+
const nested = innerSchema(def);
|
|
207
|
+
return nested ? toJsonSchema(nested, warnings, label, io) : void 0;
|
|
208
|
+
}
|
|
209
|
+
default:
|
|
210
|
+
warnings.push(`${label}: unsupported Zod type "${typeName}".`);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Take an object schema apart into its properties and the set of keys a caller
|
|
216
|
+
* must supply, looking through any wrappers around it. Warns and returns
|
|
217
|
+
* `undefined` when the schema is absent, not Zod, or not an object once
|
|
218
|
+
* unwrapped — a caller that expands properties into something else (query
|
|
219
|
+
* parameters, merged tool input) has nothing to expand otherwise.
|
|
220
|
+
*/
|
|
221
|
+
function readObjectSchema(schema, warnings, label, io) {
|
|
222
|
+
if (!schema) return;
|
|
223
|
+
if (warnIfZod3(schema, warnings, label)) return;
|
|
224
|
+
if (!isZodSchema(schema)) {
|
|
225
|
+
warnings.push(`${label}: skipped because schema is not a supported Zod schema.`);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const details = readObjectSchemaDetails(schema, warnings, label, io);
|
|
229
|
+
if (!details) warnings.push(`${label}: expected an object schema for parameter expansion.`);
|
|
230
|
+
return details;
|
|
231
|
+
}
|
|
232
|
+
/** Whether this value looks like a Zod schema at all — the gate every walk opens with. */
|
|
233
|
+
function isZodSchema(schema) {
|
|
234
|
+
if (!schema || typeof schema !== "object") return false;
|
|
235
|
+
return Boolean(getTypeName(schema));
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Push the v3 refusal warning and report whether it fired. One helper so the
|
|
239
|
+
* composed message cannot drift between the entry points, and so the recursive
|
|
240
|
+
* walks re-check nested nodes — a v3 schema can sit inside a v4 object, and an
|
|
241
|
+
* ungated recursion would document it wrong instead of refusing it.
|
|
242
|
+
*/
|
|
243
|
+
function warnIfZod3(schema, warnings, label) {
|
|
244
|
+
if (schema && typeof schema === "object" && isZod3Schema(schema)) {
|
|
245
|
+
warnings.push(`${label}: skipped — ${ZOD3_UNSUPPORTED_MESSAGE}`);
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
function readObjectSchemaDetails(schema, warnings, label, io) {
|
|
251
|
+
if (warnIfZod3(schema, warnings, label)) return;
|
|
252
|
+
if (typeOf(schema) !== "object") {
|
|
253
|
+
const nested = unwrapSingleChild(schema, io);
|
|
254
|
+
return nested ? readObjectSchemaDetails(nested, warnings, label, io) : void 0;
|
|
255
|
+
}
|
|
256
|
+
const shape = objectShape(schema);
|
|
257
|
+
if (!shape) {
|
|
258
|
+
warnings.push(`${label}: object schema shape could not be read.`);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const properties = {};
|
|
262
|
+
const required = /* @__PURE__ */ new Set();
|
|
263
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
264
|
+
const propertySchema = toJsonSchema(value, warnings, `${label}.${key}`, io);
|
|
265
|
+
if (!propertySchema) continue;
|
|
266
|
+
properties[key] = propertySchema;
|
|
267
|
+
if (!isOptional(value, io)) required.add(key);
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
properties,
|
|
271
|
+
required
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Whether a caller may leave this property out — the `required` half of an
|
|
276
|
+
* object schema.
|
|
277
|
+
*
|
|
278
|
+
* Stays here rather than joining `unwrapSingleChild` in `zod-compat`: applying
|
|
279
|
+
* the wrapper vocabulary is schema-reading, but what to *conclude* from a
|
|
280
|
+
* wrapper is a policy each caller sets — see the `pipe` case.
|
|
281
|
+
*/
|
|
282
|
+
function isOptional(schema, io) {
|
|
283
|
+
switch (typeOf(schema)) {
|
|
284
|
+
case "optional": return true;
|
|
285
|
+
case "default":
|
|
286
|
+
case "prefault": return io === "input";
|
|
287
|
+
case "catch": return io === "input";
|
|
288
|
+
case "nonoptional": return false;
|
|
289
|
+
case "pipe": {
|
|
290
|
+
const { from, to } = pipeSides(schema._def ?? {});
|
|
291
|
+
if (!from) return false;
|
|
292
|
+
return to ? isOptional(from, io) && isOptional(to, io) : isOptional(from, io);
|
|
293
|
+
}
|
|
294
|
+
default: {
|
|
295
|
+
const nested = unwrapSingleChild(schema, io);
|
|
296
|
+
return nested ? isOptional(nested, io) : false;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function literalSchema(def) {
|
|
301
|
+
const value = literalValues(def)[0];
|
|
302
|
+
if (typeof value === "string") return {
|
|
303
|
+
type: "string",
|
|
304
|
+
const: value
|
|
305
|
+
};
|
|
306
|
+
if (typeof value === "number") return {
|
|
307
|
+
type: "number",
|
|
308
|
+
const: value
|
|
309
|
+
};
|
|
310
|
+
if (typeof value === "boolean") return {
|
|
311
|
+
type: "boolean",
|
|
312
|
+
const: value
|
|
313
|
+
};
|
|
314
|
+
if (value === null) return {
|
|
315
|
+
type: "null",
|
|
316
|
+
const: null
|
|
317
|
+
};
|
|
318
|
+
return {};
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* A check value that JSON Schema can carry. The guard is not ceremonial: the
|
|
322
|
+
* same `greater_than` / `min_length` check kinds are attached to `z.date()` and
|
|
323
|
+
* `z.bigint()`, where the bound is a `Date` or a `bigint` — emitting either
|
|
324
|
+
* would produce a keyword whose value is not a JSON number (and, for bigint,
|
|
325
|
+
* one that `JSON.stringify` throws on).
|
|
326
|
+
*/
|
|
327
|
+
function numeric(value) {
|
|
328
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
329
|
+
}
|
|
330
|
+
/** The tighter of two lower bounds — a schema may carry `.min(2).min(5)`. */
|
|
331
|
+
function tightenLower(current, candidate) {
|
|
332
|
+
return current === void 0 ? candidate : Math.max(current, candidate);
|
|
333
|
+
}
|
|
334
|
+
/** The tighter of two upper bounds. */
|
|
335
|
+
function tightenUpper(current, candidate) {
|
|
336
|
+
return current === void 0 ? candidate : Math.min(current, candidate);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* `min_length` / `max_length` / `length_equals` under whichever pair of
|
|
340
|
+
* keywords the type spells them: strings count characters (`minLength`), arrays
|
|
341
|
+
* count elements (`minItems`). Zod uses the same three check kinds for both.
|
|
342
|
+
*/
|
|
343
|
+
function lengthConstraints(checks, minKey, maxKey) {
|
|
344
|
+
const constraints = {};
|
|
345
|
+
for (const check of checks) switch (check.check) {
|
|
346
|
+
case "min_length": {
|
|
347
|
+
const minimum = numeric(check.minimum);
|
|
348
|
+
if (minimum !== void 0) constraints[minKey] = tightenLower(constraints[minKey], minimum);
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
case "max_length": {
|
|
352
|
+
const maximum = numeric(check.maximum);
|
|
353
|
+
if (maximum !== void 0) constraints[maxKey] = tightenUpper(constraints[maxKey], maximum);
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
case "length_equals": {
|
|
357
|
+
const length = numeric(check.length);
|
|
358
|
+
if (length !== void 0) {
|
|
359
|
+
constraints[minKey] = tightenLower(constraints[minKey], length);
|
|
360
|
+
constraints[maxKey] = tightenUpper(constraints[maxKey], length);
|
|
361
|
+
}
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return constraints;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Every format this node declares, in the order a reader should prefer them.
|
|
369
|
+
*
|
|
370
|
+
* Two sources, because zod has two spellings: the top-level constructors
|
|
371
|
+
* (`z.email()`, `z.int()`) record the format on the node, while the equivalent
|
|
372
|
+
* methods (`z.string().email()`, `z.number().int()`) attach it as a check and
|
|
373
|
+
* leave the node's own field empty. Reading one source loses half the formats
|
|
374
|
+
* an app writes, so both are collected here once rather than in each caller.
|
|
375
|
+
*
|
|
376
|
+
* Takes the node's checks rather than re-reading them: every caller has already
|
|
377
|
+
* walked `_def.checks` for something else, and this walker is on RFC 0016's
|
|
378
|
+
* tool-derivation path as well as the document one.
|
|
379
|
+
*/
|
|
380
|
+
function declaredFormats(schema, checks) {
|
|
381
|
+
const onNode = schemaFormat(schema);
|
|
382
|
+
const onChecks = checks.flatMap((check) => typeof check.format === "string" ? [check.format] : []);
|
|
383
|
+
return onNode ? [onNode, ...onChecks] : onChecks;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* The whole rendering of a `number` node, because its *type* and its
|
|
387
|
+
* constraints are read from the same check list — `z.int()` is a format, and
|
|
388
|
+
* splitting the two would walk `_def.checks` twice per node.
|
|
389
|
+
*/
|
|
390
|
+
function numberSchema(schema) {
|
|
391
|
+
const checks = schemaChecks(schema);
|
|
392
|
+
return {
|
|
393
|
+
type: declaredFormats(schema, checks).some((format) => INTEGER_NUMBER_FORMATS.has(format)) ? "integer" : "number",
|
|
394
|
+
...numericConstraints(checks)
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
function stringConstraints(schema) {
|
|
398
|
+
const checks = schemaChecks(schema);
|
|
399
|
+
const constraints = lengthConstraints(checks, "minLength", "maxLength");
|
|
400
|
+
const format = declaredFormats(schema, checks).map((declared) => JSON_SCHEMA_STRING_FORMATS[declared]).find(Boolean);
|
|
401
|
+
if (format) constraints.format = format;
|
|
402
|
+
assignWithSurplus(constraints, "pattern", checks.flatMap((check) => {
|
|
403
|
+
if (check.check !== "string_format") return [];
|
|
404
|
+
if (typeof check.format !== "string" || !PATTERN_BEARING_FORMATS.has(check.format)) return [];
|
|
405
|
+
const pattern = patternSource(check);
|
|
406
|
+
return pattern ? [pattern] : [];
|
|
407
|
+
}));
|
|
408
|
+
return constraints;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Put the first value under `keyword` and fold any remainder into `allOf`.
|
|
412
|
+
*
|
|
413
|
+
* JSON Schema allows one `pattern` and one `multipleOf` per schema object, so a
|
|
414
|
+
* node carrying two of either (`z.string().regex(/^a/).startsWith('b')`,
|
|
415
|
+
* `z.number().multipleOf(2).multipleOf(3)`) cannot state both in place. Keeping
|
|
416
|
+
* only the first is not a lesser answer, it is a wrong one: the emitted schema
|
|
417
|
+
* then *accepts values the route rejects*, which is the one direction a derived
|
|
418
|
+
* contract must never be wrong in — an agent handed it will send input that
|
|
419
|
+
* fails validation. `allOf` conjoins, so the surplus stays enforceable.
|
|
420
|
+
*
|
|
421
|
+
* The first value stays on the node rather than going into `allOf` with the
|
|
422
|
+
* rest, so the overwhelmingly common single-constraint case emits flat.
|
|
423
|
+
* (zod's own emitter drops the surplus `multipleOf` outright here.)
|
|
424
|
+
*/
|
|
425
|
+
function assignWithSurplus(constraints, keyword, values) {
|
|
426
|
+
const [first, ...surplus] = values;
|
|
427
|
+
if (first === void 0) return;
|
|
428
|
+
constraints[keyword] = first;
|
|
429
|
+
if (surplus.length > 0) constraints.allOf = surplus.map((value) => ({ [keyword]: value }));
|
|
430
|
+
}
|
|
431
|
+
/** A check's regex as a JSON Schema `pattern` — the source, never the `/…/` literal form. */
|
|
432
|
+
function patternSource(check) {
|
|
433
|
+
return check.pattern instanceof RegExp ? check.pattern.source : void 0;
|
|
434
|
+
}
|
|
435
|
+
function numericConstraints(checks) {
|
|
436
|
+
const constraints = {};
|
|
437
|
+
for (const check of checks) switch (check.check) {
|
|
438
|
+
case "greater_than": {
|
|
439
|
+
const value = numeric(check.value);
|
|
440
|
+
if (value === void 0) break;
|
|
441
|
+
if (check.inclusive === true) constraints.minimum = tightenLower(constraints.minimum, value);
|
|
442
|
+
else constraints.exclusiveMinimum = tightenLower(constraints.exclusiveMinimum, value);
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
case "less_than": {
|
|
446
|
+
const value = numeric(check.value);
|
|
447
|
+
if (value === void 0) break;
|
|
448
|
+
if (check.inclusive === true) constraints.maximum = tightenUpper(constraints.maximum, value);
|
|
449
|
+
else constraints.exclusiveMaximum = tightenUpper(constraints.exclusiveMaximum, value);
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
assignWithSurplus(constraints, "multipleOf", checks.flatMap((check) => {
|
|
454
|
+
if (check.check !== "multiple_of") return [];
|
|
455
|
+
const value = numeric(check.value);
|
|
456
|
+
return value === void 0 ? [] : [value];
|
|
457
|
+
}));
|
|
458
|
+
return constraints;
|
|
459
|
+
}
|
|
460
|
+
//#endregion
|
|
461
|
+
export { isZodSchema, readObjectSchema, toJsonSchema };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `YYYY-MM-DD` stamp a file rotated at `date` carries.
|
|
3
|
+
*
|
|
4
|
+
* UTC, from the ISO form, because the rotation boundary has to be the same
|
|
5
|
+
* instant for every process appending to the same directory — a fleet split
|
|
6
|
+
* across time zones would otherwise write two different files for one day and
|
|
7
|
+
* roll over at as many moments as it has zones.
|
|
8
|
+
*/
|
|
9
|
+
export declare function dailyFileDateStamp(date: Date): string;
|
|
10
|
+
/** The dated file a base path rotates to on `date`. */
|
|
11
|
+
export declare function dailyFilePath(basePath: string, date: Date): string;
|
|
12
|
+
/**
|
|
13
|
+
* The date stamp of `fileName` if it is one of `basePath`'s dated files, and
|
|
14
|
+
* `null` if it is anything else in the same directory.
|
|
15
|
+
*
|
|
16
|
+
* The inverse of {@link dailyFilePath}, and the reason a caller listing a
|
|
17
|
+
* directory does not need to know the shape it is matching. The base path's
|
|
18
|
+
* own name and extension are escaped before they enter the pattern: a log
|
|
19
|
+
* called `app.v1.log` parses to the name `app.v1`, whose dots would otherwise
|
|
20
|
+
* match any character and let a *different* app's files into another's
|
|
21
|
+
* rotation set — which, for the cleanup that consumes this, means deleting
|
|
22
|
+
* them.
|
|
23
|
+
*/
|
|
24
|
+
export declare function matchDailyFileDate(basePath: string, fileName: string): string | null;
|
package/dist/logging/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { LOG_LEVEL_PRIORITY } from './types.js';
|
|
|
3
3
|
export { Logger, filterSensitiveData } from './Logger.js';
|
|
4
4
|
export type { LoggerOptions } from './Logger.js';
|
|
5
5
|
export { LogManager, createLogManager, setLogManager, getLogManager, } from './LogManager.js';
|
|
6
|
+
export { dailyFileDateStamp, dailyFilePath, matchDailyFileDate } from './daily-file-path.js';
|
|
6
7
|
export { ConsoleChannel } from './channels/ConsoleChannel.js';
|
|
7
8
|
export { FileChannel } from './channels/FileChannel.js';
|
|
8
9
|
export { DailyFileChannel } from './channels/DailyFileChannel.js';
|
package/dist/logging/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as DailyFileChannel, c as Logger, i as setLogManager, l as
|
|
2
|
-
export { ConsoleChannel, DailyFileChannel, FileChannel, LOG_LEVEL_PRIORITY, LogManager, Logger, createLogManager, filterSensitiveData, getLogManager, setLogManager };
|
|
1
|
+
import { a as DailyFileChannel, c as matchDailyFileDate, d as Logger, f as filterSensitiveData, i as setLogManager, l as FileChannel, n as createLogManager, o as dailyFileDateStamp, p as LOG_LEVEL_PRIORITY, r as getLogManager, s as dailyFilePath, t as LogManager, u as ConsoleChannel } from "../logging-B-kngi3q.js";
|
|
2
|
+
export { ConsoleChannel, DailyFileChannel, FileChannel, LOG_LEVEL_PRIORITY, LogManager, Logger, createLogManager, dailyFileDateStamp, dailyFilePath, filterSensitiveData, getLogManager, matchDailyFileDate, setLogManager };
|
|
@@ -268,6 +268,59 @@ var FileChannel = class {
|
|
|
268
268
|
close() {}
|
|
269
269
|
};
|
|
270
270
|
//#endregion
|
|
271
|
+
//#region src/logging/daily-file-path.ts
|
|
272
|
+
/**
|
|
273
|
+
* The one rule for what a daily-rotated log file is called: `dir/name-YYYY-MM-DD.ext`.
|
|
274
|
+
*
|
|
275
|
+
* {@link DailyFileChannel} names the file it appends to through this module,
|
|
276
|
+
* and the agent audit reader behind `guren tool:log` decides which files to
|
|
277
|
+
* read through the same one. A second copy of the rule is how a writer and a
|
|
278
|
+
* reader drift apart, and the drift is silent in the worst direction: the
|
|
279
|
+
* writer keeps appending, the reader stops recognising, and what the operator
|
|
280
|
+
* sees is an empty audit trail rather than an error.
|
|
281
|
+
*
|
|
282
|
+
* Naming only — nothing here touches the filesystem. The reader has to tell
|
|
283
|
+
* "this directory does not exist" apart from "this directory could not be
|
|
284
|
+
* read", and a helper that swallowed the difference on its behalf would put
|
|
285
|
+
* that distinction back out of reach.
|
|
286
|
+
*/
|
|
287
|
+
/**
|
|
288
|
+
* The `YYYY-MM-DD` stamp a file rotated at `date` carries.
|
|
289
|
+
*
|
|
290
|
+
* UTC, from the ISO form, because the rotation boundary has to be the same
|
|
291
|
+
* instant for every process appending to the same directory — a fleet split
|
|
292
|
+
* across time zones would otherwise write two different files for one day and
|
|
293
|
+
* roll over at as many moments as it has zones.
|
|
294
|
+
*/
|
|
295
|
+
function dailyFileDateStamp(date) {
|
|
296
|
+
return date.toISOString().slice(0, 10);
|
|
297
|
+
}
|
|
298
|
+
/** The dated file a base path rotates to on `date`. */
|
|
299
|
+
function dailyFilePath(basePath, date) {
|
|
300
|
+
const { dir, name, ext } = path$1.parse(basePath);
|
|
301
|
+
return path$1.join(dir, `${name}-${dailyFileDateStamp(date)}${ext}`);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* The date stamp of `fileName` if it is one of `basePath`'s dated files, and
|
|
305
|
+
* `null` if it is anything else in the same directory.
|
|
306
|
+
*
|
|
307
|
+
* The inverse of {@link dailyFilePath}, and the reason a caller listing a
|
|
308
|
+
* directory does not need to know the shape it is matching. The base path's
|
|
309
|
+
* own name and extension are escaped before they enter the pattern: a log
|
|
310
|
+
* called `app.v1.log` parses to the name `app.v1`, whose dots would otherwise
|
|
311
|
+
* match any character and let a *different* app's files into another's
|
|
312
|
+
* rotation set — which, for the cleanup that consumes this, means deleting
|
|
313
|
+
* them.
|
|
314
|
+
*/
|
|
315
|
+
function matchDailyFileDate(basePath, fileName) {
|
|
316
|
+
const { name, ext } = path$1.parse(basePath);
|
|
317
|
+
return new RegExp(`^${escapeRegExp(name)}-(\\d{4}-\\d{2}-\\d{2})${escapeRegExp(ext)}$`, "u").exec(fileName)?.[1] ?? null;
|
|
318
|
+
}
|
|
319
|
+
/** Every character with meaning inside a regular expression, made literal. */
|
|
320
|
+
function escapeRegExp(text) {
|
|
321
|
+
return text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
322
|
+
}
|
|
323
|
+
//#endregion
|
|
271
324
|
//#region src/logging/channels/DailyFileChannel.ts
|
|
272
325
|
/**
|
|
273
326
|
* Daily rotating file log channel.
|
|
@@ -287,43 +340,33 @@ var DailyFileChannel = class {
|
|
|
287
340
|
}
|
|
288
341
|
log(entry) {
|
|
289
342
|
if (LOG_LEVEL_PRIORITY[entry.level] > this.minLevel) return;
|
|
290
|
-
const dateStr =
|
|
291
|
-
if (this.currentDate !== dateStr) this.rotate(dateStr);
|
|
343
|
+
const dateStr = dailyFileDateStamp(entry.timestamp);
|
|
344
|
+
if (this.currentDate !== dateStr) this.rotate(entry.timestamp, dateStr);
|
|
292
345
|
const line = this.format(entry) + "\n";
|
|
293
346
|
this.write(line);
|
|
294
347
|
}
|
|
295
348
|
write(data) {
|
|
296
349
|
if (this.currentFilePath) fs.appendFileSync(this.currentFilePath, data);
|
|
297
350
|
}
|
|
298
|
-
rotate(dateStr) {
|
|
351
|
+
rotate(date, dateStr) {
|
|
299
352
|
this.currentDate = dateStr;
|
|
300
|
-
this.currentFilePath = this.
|
|
353
|
+
this.currentFilePath = dailyFilePath(this.config.path, date);
|
|
301
354
|
this.ensureDirectory(this.currentFilePath);
|
|
302
355
|
this.cleanup();
|
|
303
356
|
}
|
|
304
|
-
getFilePath(dateStr) {
|
|
305
|
-
const { dir, name, ext } = path$1.parse(this.config.path);
|
|
306
|
-
return path$1.join(dir, `${name}-${dateStr}${ext}`);
|
|
307
|
-
}
|
|
308
|
-
getDateString(date) {
|
|
309
|
-
return date.toISOString().split("T")[0];
|
|
310
|
-
}
|
|
311
357
|
ensureDirectory(filePath) {
|
|
312
358
|
const dir = path$1.dirname(filePath);
|
|
313
359
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
314
360
|
}
|
|
315
361
|
cleanup() {
|
|
316
|
-
const
|
|
362
|
+
const dir = path$1.dirname(this.config.path);
|
|
317
363
|
if (!fs.existsSync(dir)) return;
|
|
318
364
|
const files = fs.readdirSync(dir);
|
|
319
|
-
const pattern = new RegExp(`^${name}-(\\d{4}-\\d{2}-\\d{2})${ext.replace(".", "\\.")}$`);
|
|
320
365
|
const cutoff = /* @__PURE__ */ new Date();
|
|
321
366
|
cutoff.setDate(cutoff.getDate() - (this.config.days ?? 14));
|
|
322
367
|
for (const file of files) {
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
325
|
-
if (new Date(match[1]) < cutoff) fs.unlinkSync(path$1.join(dir, file));
|
|
326
|
-
}
|
|
368
|
+
const stamp = matchDailyFileDate(this.config.path, file);
|
|
369
|
+
if (stamp !== null && new Date(stamp) < cutoff) fs.unlinkSync(path$1.join(dir, file));
|
|
327
370
|
}
|
|
328
371
|
}
|
|
329
372
|
format(entry) {
|
|
@@ -515,4 +558,4 @@ function getLogManager() {
|
|
|
515
558
|
return globalLogManager;
|
|
516
559
|
}
|
|
517
560
|
//#endregion
|
|
518
|
-
export { DailyFileChannel as a,
|
|
561
|
+
export { DailyFileChannel as a, matchDailyFileDate as c, Logger as d, filterSensitiveData as f, setLogManager as i, FileChannel as l, createLogManager as n, dailyFileDateStamp as o, LOG_LEVEL_PRIORITY as p, getLogManager as r, dailyFilePath as s, LogManager as t, ConsoleChannel as u };
|
|
@@ -64,6 +64,8 @@ export interface GurenCliApi {
|
|
|
64
64
|
className: string;
|
|
65
65
|
}>;
|
|
66
66
|
routes: Array<unknown>;
|
|
67
|
+
/** Why `routes` is empty, when it is empty because the load failed. */
|
|
68
|
+
routesError?: string;
|
|
67
69
|
pages: string[];
|
|
68
70
|
controllers: string[];
|
|
69
71
|
resources: string[];
|
|
@@ -139,12 +141,39 @@ export interface GurenCliApi {
|
|
|
139
141
|
generateApiClientTypes(definitions: unknown[], opts: CodegenOptions & {
|
|
140
142
|
resources?: unknown[];
|
|
141
143
|
}): Promise<CodegenResult | void>;
|
|
144
|
+
/**
|
|
145
|
+
* Agent tools derived from the route manifest (RFC 0016), so it runs after
|
|
146
|
+
* `generateRouteTypes` and — because a `resource` hint's payload type is
|
|
147
|
+
* embedded in a tool description — after `generateDataTypes` too. Optional
|
|
148
|
+
* because `@guren/cli` is resolved from the app at runtime and may predate
|
|
149
|
+
* it; an older CLI simply generates no agent manifest.
|
|
150
|
+
*/
|
|
151
|
+
generateAgentTypes?(definitions: unknown[], opts: CodegenOptions & {
|
|
152
|
+
resources?: unknown[];
|
|
153
|
+
}): Promise<CodegenResult | void>;
|
|
142
154
|
/**
|
|
143
155
|
* Route-dependent context generation that re-runs the CLI in a fresh
|
|
144
156
|
* process. Optional because `@guren/cli` is resolved from the app at
|
|
145
157
|
* runtime and may predate it — see `McpServiceProvider`.
|
|
146
158
|
*/
|
|
147
159
|
createFreshContextApi?: () => Pick<GurenCliApi, 'generateContext' | 'generateEntityContext'>;
|
|
160
|
+
/**
|
|
161
|
+
* Optional fields the CLI's context routes populate. Spelled exactly as
|
|
162
|
+
* `@guren/cli` exports it — this interface describes that module namespace,
|
|
163
|
+
* so a prettier camelCase name here would read `undefined` off every real
|
|
164
|
+
* CLI and silently answer "unsupported" forever.
|
|
165
|
+
*
|
|
166
|
+
* Optional for the same runtime-resolution reason as the members above, and
|
|
167
|
+
* read for exactly that reason: an older CLI emits routes with no `agent`
|
|
168
|
+
* field at all, which reads identically to an app exposing no agent tools.
|
|
169
|
+
*/
|
|
170
|
+
CONTEXT_ROUTE_FEATURES?: readonly string[];
|
|
171
|
+
/**
|
|
172
|
+
* Every route as a context route, without building the rest of the project
|
|
173
|
+
* context. Optional like the above; `guren_agent_surface` falls back to
|
|
174
|
+
* `generateContext` when an older CLI does not provide it.
|
|
175
|
+
*/
|
|
176
|
+
loadContextRoutes?(cwd: string, routesFile?: string, loadErrors?: string[]): Promise<unknown[]>;
|
|
148
177
|
/**
|
|
149
178
|
* The OKF docs relation graph (RFC 0005). Optional for the same
|
|
150
179
|
* runtime-resolution reason as above.
|
package/dist/mcp/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { r as createMcpServer, t as McpServiceProvider } from "../McpServiceProvider-
|
|
1
|
+
import { r as createMcpServer, t as McpServiceProvider } from "../McpServiceProvider-BawsYjgN.js";
|
|
2
2
|
export { McpServiceProvider, createMcpServer };
|