@frontmcp/sdk 1.13.1 → 1.13.2
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/auth/auth-ui/auth-ui.render.d.ts +5 -2
- package/auth/auth-ui/auth-ui.render.d.ts.map +1 -1
- package/auth/auth-ui/index.d.ts +1 -1
- package/auth/auth-ui/index.d.ts.map +1 -1
- package/auth/flows/oauth.authorize.flow.d.ts +1 -0
- package/auth/flows/oauth.authorize.flow.d.ts.map +1 -1
- package/auth/flows/oauth.callback.flow.d.ts.map +1 -1
- package/auth/flows/oauth.register.flow.d.ts +18 -1
- package/auth/flows/oauth.register.flow.d.ts.map +1 -1
- package/auth/flows/well-known.prm.flow.d.ts +4 -0
- package/auth/flows/well-known.prm.flow.d.ts.map +1 -1
- package/auth/instances/instance.local-primary-auth.d.ts +4 -3
- package/auth/instances/instance.local-primary-auth.d.ts.map +1 -1
- package/auth/instances/instance.remote-primary-auth.d.ts.map +1 -1
- package/browser/auth/auth-ui/auth-ui.render.mjs +9 -8
- package/browser/auth/auth-ui/index.mjs +4 -2
- package/browser/auth/federated-steps.mjs +1 -1
- package/browser/auth/flows/oauth.authorize.flow.mjs +15 -8
- package/browser/auth/flows/oauth.callback.flow.mjs +10 -3
- package/browser/auth/flows/oauth.connect.flow.mjs +1 -1
- package/browser/auth/flows/oauth.provider-callback.flow.mjs +1 -1
- package/browser/auth/flows/oauth.register.flow.mjs +5 -1
- package/browser/auth/flows/well-known.prm.flow.mjs +22 -3
- package/browser/auth/instances/instance.local-primary-auth.mjs +20 -9
- package/browser/auth/instances/instance.remote-primary-auth.mjs +5 -0
- package/browser/common/decorators/http-route.decorator.mjs +9 -1
- package/browser/common/index.mjs +1 -1
- package/browser/common/metadata/index.mjs +1 -1
- package/browser/common/metadata/materialized.metadata.mjs +13 -0
- package/browser/common/metadata/resource.metadata.mjs +6 -5
- package/browser/common/tokens/resource.tokens.mjs +1 -0
- package/browser/common/types/options/http/schema.mjs +17 -1
- package/browser/common/types/options/transport/schema.mjs +11 -1
- package/browser/direct/direct-server.mjs +15 -11
- package/browser/errors/index.mjs +3 -1
- package/browser/errors/mcp.error.mjs +7 -0
- package/browser/errors/transport.errors.mjs +7 -1
- package/browser/event/event-scope.helper.mjs +4 -2
- package/browser/event/event-subscription-info.mjs +55 -0
- package/browser/event/event.registry.mjs +18 -0
- package/browser/event/flows/event-ended.flow.mjs +89 -0
- package/browser/event/flows/event-unsubscribe.flow.mjs +7 -1
- package/browser/event/poll/event-poll-leases.mjs +11 -0
- package/browser/event/stream/event-stream.mjs +4 -0
- package/browser/event/stream/event-streams.mjs +13 -0
- package/browser/event/subscription/event-subscription-termination.mjs +1 -0
- package/browser/event/subscription/event-subscriptions.mjs +18 -2
- package/browser/front-mcp/front-mcp.mjs +13 -0
- package/browser/http-route/flows/http.route.flow.mjs +71 -8
- package/browser/http-route/http-route.table.mjs +61 -15
- package/browser/http-route/people-session-store.mjs +47 -0
- package/browser/http-route/people-sign-in.routes.mjs +3 -2
- package/browser/http-route/sse-route.stream.mjs +19 -8
- package/browser/index.cjs +3011 -2017
- package/browser/index.mjs +24 -3
- package/browser/notification/notification.service.mjs +8 -1
- package/browser/resource/materialized/materialized-resource.context.mjs +3 -1
- package/browser/resource/materialized/materialized-resources.mjs +53 -27
- package/browser/resource/materialized/resource-store.mjs +269 -17
- package/browser/resource/resource.registry.mjs +31 -0
- package/browser/scope/http-scope.helper.mjs +2 -1
- package/browser/scope/scope.instance.mjs +2 -2
- package/browser/server/security/host-validation.mjs +4 -1
- package/browser/server/server.instance.mjs +22 -4
- package/browser/subsystems.mjs +21 -2
- package/browser/tool/flows/call-tool.flow.mjs +3 -3
- package/browser/tool/undeclared-arguments-message.mjs +10 -8
- package/browser/tool/undeclared-arguments.mjs +33 -0
- package/browser/transport/adapters/transport.sse.adapter.mjs +5 -2
- package/browser/transport/adapters/transport.streamable-http.adapter.mjs +3 -1
- package/browser/transport/flows/handle.mcp-20260728.flow.mjs +7 -2
- package/browser/transport/mcp-20260728/subscriptions.mjs +24 -4
- package/browser/transport/stream-keep-alive.mjs +70 -0
- package/browser/transport/transport.registry.mjs +9 -7
- package/browser/transport/web-standard-mcp.mjs +3 -1
- package/common/decorators/http-route.decorator.d.ts +2 -1
- package/common/decorators/http-route.decorator.d.ts.map +1 -1
- package/common/interfaces/http-route.interface.d.ts +9 -1
- package/common/interfaces/http-route.interface.d.ts.map +1 -1
- package/common/metadata/app.metadata.d.ts +8 -0
- package/common/metadata/app.metadata.d.ts.map +1 -1
- package/common/metadata/front-mcp.metadata.d.ts +197 -0
- package/common/metadata/front-mcp.metadata.d.ts.map +1 -1
- package/common/metadata/http-route.metadata.d.ts +11 -3
- package/common/metadata/http-route.metadata.d.ts.map +1 -1
- package/common/metadata/materialized.metadata.d.ts +21 -0
- package/common/metadata/materialized.metadata.d.ts.map +1 -1
- package/common/metadata/resource.metadata.d.ts +8 -1
- package/common/metadata/resource.metadata.d.ts.map +1 -1
- package/common/tokens/resource.tokens.d.ts +1 -0
- package/common/tokens/resource.tokens.d.ts.map +1 -1
- package/common/types/options/auth/index.d.ts +1 -1
- package/common/types/options/auth/index.d.ts.map +1 -1
- package/common/types/options/http/index.d.ts +1 -1
- package/common/types/options/http/index.d.ts.map +1 -1
- package/common/types/options/http/interfaces.d.ts +41 -1
- package/common/types/options/http/interfaces.d.ts.map +1 -1
- package/common/types/options/http/schema.d.ts +12 -0
- package/common/types/options/http/schema.d.ts.map +1 -1
- package/common/types/options/transport/index.d.ts +1 -1
- package/common/types/options/transport/index.d.ts.map +1 -1
- package/common/types/options/transport/interfaces.d.ts +24 -0
- package/common/types/options/transport/interfaces.d.ts.map +1 -1
- package/common/types/options/transport/schema.d.ts +3 -0
- package/common/types/options/transport/schema.d.ts.map +1 -1
- package/direct/direct-server.d.ts +4 -2
- package/direct/direct-server.d.ts.map +1 -1
- package/direct/direct.types.d.ts +7 -0
- package/direct/direct.types.d.ts.map +1 -1
- package/errors/index.d.ts +1 -1
- package/errors/index.d.ts.map +1 -1
- package/errors/mcp.error.d.ts +4 -0
- package/errors/mcp.error.d.ts.map +1 -1
- package/errors/transport.errors.d.ts +4 -0
- package/errors/transport.errors.d.ts.map +1 -1
- package/esm/index.mjs +42 -42
- package/event/event-scope.helper.d.ts.map +1 -1
- package/event/event-subscription-info.d.ts +72 -0
- package/event/event-subscription-info.d.ts.map +1 -0
- package/event/event.registry.d.ts +7 -0
- package/event/event.registry.d.ts.map +1 -1
- package/event/flows/event-ended.flow.d.ts +56 -0
- package/event/flows/event-ended.flow.d.ts.map +1 -0
- package/event/flows/event-unsubscribe.flow.d.ts +4 -1
- package/event/flows/event-unsubscribe.flow.d.ts.map +1 -1
- package/event/index.d.ts +3 -1
- package/event/index.d.ts.map +1 -1
- package/event/poll/event-poll-leases.d.ts +3 -0
- package/event/poll/event-poll-leases.d.ts.map +1 -1
- package/event/stream/event-stream.d.ts +2 -0
- package/event/stream/event-stream.d.ts.map +1 -1
- package/event/stream/event-streams.d.ts +3 -0
- package/event/stream/event-streams.d.ts.map +1 -1
- package/event/subscription/event-subscription-termination.d.ts +4 -1
- package/event/subscription/event-subscription-termination.d.ts.map +1 -1
- package/event/subscription/event-subscriptions.d.ts +19 -1
- package/event/subscription/event-subscriptions.d.ts.map +1 -1
- package/front-mcp/front-mcp.d.ts.map +1 -1
- package/http-route/flows/http.route.flow.d.ts +12 -4
- package/http-route/flows/http.route.flow.d.ts.map +1 -1
- package/http-route/http-route.table.d.ts +10 -3
- package/http-route/http-route.table.d.ts.map +1 -1
- package/http-route/people-session-store.d.ts +24 -0
- package/http-route/people-session-store.d.ts.map +1 -0
- package/http-route/people-sign-in.routes.d.ts +2 -2
- package/http-route/people-sign-in.routes.d.ts.map +1 -1
- package/http-route/sse-route.stream.d.ts +6 -1
- package/http-route/sse-route.stream.d.ts.map +1 -1
- package/index.d.ts +16 -8
- package/index.d.ts.map +1 -1
- package/index.js +43 -43
- package/notification/notification.service.d.ts.map +1 -1
- package/package.json +10 -10
- package/resource/materialized/index.d.ts +1 -1
- package/resource/materialized/index.d.ts.map +1 -1
- package/resource/materialized/materialized-resource.context.d.ts +1 -0
- package/resource/materialized/materialized-resource.context.d.ts.map +1 -1
- package/resource/materialized/materialized-resources.d.ts +11 -5
- package/resource/materialized/materialized-resources.d.ts.map +1 -1
- package/resource/materialized/resource-store.d.ts +31 -1
- package/resource/materialized/resource-store.d.ts.map +1 -1
- package/resource/resource.registry.d.ts +11 -0
- package/resource/resource.registry.d.ts.map +1 -1
- package/scope/http-scope.helper.d.ts +1 -1
- package/scope/http-scope.helper.d.ts.map +1 -1
- package/scope/scope.instance.d.ts.map +1 -1
- package/server/adapters/polyfills/browser-express-host.d.ts +3 -0
- package/server/adapters/polyfills/browser-express-host.d.ts.map +1 -1
- package/server/adapters/polyfills/node-express-host.d.ts +1 -0
- package/server/adapters/polyfills/node-express-host.d.ts.map +1 -1
- package/server/adapters/user-content.listener.d.ts +26 -0
- package/server/adapters/user-content.listener.d.ts.map +1 -0
- package/server/security/host-validation.d.ts.map +1 -1
- package/server/server.instance.d.ts +1 -0
- package/server/server.instance.d.ts.map +1 -1
- package/subsystems.d.ts +1 -1
- package/subsystems.d.ts.map +1 -1
- package/tool/undeclared-arguments-message.d.ts +8 -5
- package/tool/undeclared-arguments-message.d.ts.map +1 -1
- package/tool/undeclared-arguments.d.ts +2 -0
- package/tool/undeclared-arguments.d.ts.map +1 -1
- package/transport/adapters/base-sse-transport.d.ts +4 -0
- package/transport/adapters/base-sse-transport.d.ts.map +1 -1
- package/transport/adapters/polyfills/browser-sse-transport.d.ts +1 -0
- package/transport/adapters/polyfills/browser-sse-transport.d.ts.map +1 -1
- package/transport/adapters/streamable-http-transport.d.ts +2 -0
- package/transport/adapters/streamable-http-transport.d.ts.map +1 -1
- package/transport/adapters/transport.sse.adapter.d.ts.map +1 -1
- package/transport/adapters/transport.streamable-http.adapter.d.ts.map +1 -1
- package/transport/flows/handle.mcp-20260728.flow.d.ts.map +1 -1
- package/transport/mcp-20260728/subscriptions.d.ts +2 -0
- package/transport/mcp-20260728/subscriptions.d.ts.map +1 -1
- package/transport/stream-keep-alive.d.ts +13 -0
- package/transport/stream-keep-alive.d.ts.map +1 -0
- package/transport/transport.registry.d.ts +1 -1
- package/transport/transport.registry.d.ts.map +1 -1
- package/transport/web-standard-mcp.d.ts.map +1 -1
|
@@ -4,9 +4,32 @@ import {
|
|
|
4
4
|
createChangeFeed,
|
|
5
5
|
createStorage
|
|
6
6
|
} from "@frontmcp/utils";
|
|
7
|
-
import { InvalidResourceStoreError } from "../../errors/mcp.error.mjs";
|
|
7
|
+
import { InvalidResourceStoreError, ResourceStoreClosedError } from "../../errors/mcp.error.mjs";
|
|
8
8
|
import { refuseServerStoresInBrowser } from "../../scope/browser-stores.mjs";
|
|
9
9
|
var STORAGE_TYPES = ["memory", "redis", "sqlite"];
|
|
10
|
+
var DEFAULT_MIN_INTERVAL_MS = 50;
|
|
11
|
+
var DEFAULT_COST_FACTOR = 1;
|
|
12
|
+
var FAMILY_KEYS_KEPT = 1e3;
|
|
13
|
+
var producerOptionsSchema = z.object({
|
|
14
|
+
produce: z.custom((value) => typeof value === "function", {
|
|
15
|
+
message: "produce must be a function that returns the value"
|
|
16
|
+
}),
|
|
17
|
+
minIntervalMs: z.number().int().nonnegative().optional(),
|
|
18
|
+
costFactor: z.number().nonnegative().finite().optional()
|
|
19
|
+
}).strict();
|
|
20
|
+
function parseProducer(subject, options) {
|
|
21
|
+
const parsed = producerOptionsSchema.safeParse(options);
|
|
22
|
+
if (parsed.success) return;
|
|
23
|
+
const problems = parsed.error.issues.map((issue) => `${issue.path.join(".") || "options"}: ${issue.message}`);
|
|
24
|
+
throw new InvalidResourceStoreError(`${subject}: ${problems.join("; ")}`);
|
|
25
|
+
}
|
|
26
|
+
function isProducerOptions(options) {
|
|
27
|
+
return "produce" in options;
|
|
28
|
+
}
|
|
29
|
+
function memberName(family, params) {
|
|
30
|
+
const query = Object.keys(params).sort().map((name) => `${encodeURIComponent(name)}=${encodeURIComponent(params[name])}`).join("&");
|
|
31
|
+
return `${family}?${query}`;
|
|
32
|
+
}
|
|
10
33
|
var resourceStoreOptionsSchema = z.object({
|
|
11
34
|
storage: z.object({ type: z.enum(STORAGE_TYPES) }).passthrough().optional(),
|
|
12
35
|
pollIntervalMs: z.number().int().positive().optional(),
|
|
@@ -21,22 +44,44 @@ var ResourceStore = class {
|
|
|
21
44
|
options;
|
|
22
45
|
opened;
|
|
23
46
|
connections = 0;
|
|
47
|
+
closes = 0;
|
|
24
48
|
backend = {
|
|
25
|
-
storage: async () =>
|
|
49
|
+
storage: async (epoch) => {
|
|
50
|
+
if (epoch !== void 0 && epoch !== this.closes) throw new ResourceStoreClosedError();
|
|
51
|
+
return (await this.open()).storage;
|
|
52
|
+
},
|
|
53
|
+
publish: async (topic, epoch) => {
|
|
54
|
+
if (epoch === void 0 || epoch === this.closes) await this.publish(topic);
|
|
55
|
+
},
|
|
56
|
+
epoch: () => this.closes,
|
|
26
57
|
reportError: (error) => this.options.onError?.(error)
|
|
27
58
|
};
|
|
28
59
|
key(name, options = {}) {
|
|
29
|
-
|
|
30
|
-
|
|
60
|
+
requireName("key", name);
|
|
61
|
+
if (isProducerOptions(options)) {
|
|
62
|
+
parseProducer(`key "${name}"`, options);
|
|
63
|
+
const { produce, ...throttle } = options;
|
|
64
|
+
return new ProducedKey(this, this.backend, name, produce, throttle);
|
|
31
65
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
66
|
+
return new StoredResourceKey(this, this.backend, name, initialRecordOf(name, options.initial));
|
|
67
|
+
}
|
|
68
|
+
family(name, options = {}) {
|
|
69
|
+
requireName("family", name);
|
|
70
|
+
if (isProducerOptions(options)) {
|
|
71
|
+
parseProducer(`family "${name}"`, options);
|
|
72
|
+
const { produce, ...throttle } = options;
|
|
73
|
+
const family = new KeyFamily(
|
|
74
|
+
this,
|
|
75
|
+
name,
|
|
76
|
+
(memberKey, params) => new ProducedKey(this, this.backend, memberKey, () => produce(params), throttle),
|
|
77
|
+
(memberKey, params) => new FamilyKeyHandle(family, memberKey, params)
|
|
78
|
+
);
|
|
79
|
+
return family;
|
|
38
80
|
}
|
|
39
|
-
|
|
81
|
+
const initialRecord = initialRecordOf(name, options.initial);
|
|
82
|
+
return new KeyFamily(this, name, (memberKey) => {
|
|
83
|
+
return new StoredResourceKey(this, this.backend, memberKey, initialRecord);
|
|
84
|
+
});
|
|
40
85
|
}
|
|
41
86
|
/** Call `listener` when `topic` is published, in this process or in another one that shares the storage. */
|
|
42
87
|
subscribe(topic, listener) {
|
|
@@ -75,6 +120,7 @@ var ResourceStore = class {
|
|
|
75
120
|
return;
|
|
76
121
|
}
|
|
77
122
|
this.connections = 0;
|
|
123
|
+
this.closes++;
|
|
78
124
|
const opened = this.opened;
|
|
79
125
|
this.opened = void 0;
|
|
80
126
|
if (!opened) return;
|
|
@@ -107,6 +153,19 @@ var ResourceStore = class {
|
|
|
107
153
|
return { root, storage: namespaced, feed };
|
|
108
154
|
}
|
|
109
155
|
};
|
|
156
|
+
function requireName(kind, name) {
|
|
157
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
158
|
+
throw new InvalidResourceStoreError(`a ${kind} needs a name, such as ${kind}("board")`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function initialRecordOf(name, initial) {
|
|
162
|
+
try {
|
|
163
|
+
return JSON.stringify({ value: initial, revision: 0 });
|
|
164
|
+
} catch (error) {
|
|
165
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
166
|
+
throw new InvalidResourceStoreError(`the initial value of key "${name}" cannot be stored as JSON: ${reason}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
110
169
|
var StoredResourceKey = class {
|
|
111
170
|
constructor(store, backend, name, initialRecord) {
|
|
112
171
|
this.store = store;
|
|
@@ -124,11 +183,22 @@ var StoredResourceKey = class {
|
|
|
124
183
|
const storage = await this.backend.storage();
|
|
125
184
|
return this.parse(await storage.get(this.recordKey));
|
|
126
185
|
}
|
|
186
|
+
/** What a subscription reads to learn of a new revision. */
|
|
187
|
+
current() {
|
|
188
|
+
return this.get();
|
|
189
|
+
}
|
|
127
190
|
set(value) {
|
|
128
191
|
return this.update(() => value);
|
|
129
192
|
}
|
|
130
|
-
|
|
131
|
-
|
|
193
|
+
update(change) {
|
|
194
|
+
return this.write(change, false);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Store what `change` makes of the value; with `onlyIfChanged`, output with the same JSON keeps the revision. With
|
|
198
|
+
* the `epoch` it began in, a write the store closed during fails instead of opening the store again.
|
|
199
|
+
*/
|
|
200
|
+
async write(change, onlyIfChanged, epoch) {
|
|
201
|
+
const storage = await this.backend.storage(epoch);
|
|
132
202
|
for (; ; ) {
|
|
133
203
|
const raw = await storage.get(this.recordKey);
|
|
134
204
|
if (raw === null) {
|
|
@@ -136,20 +206,24 @@ var StoredResourceKey = class {
|
|
|
136
206
|
continue;
|
|
137
207
|
}
|
|
138
208
|
const current = this.parse(raw);
|
|
209
|
+
const value = await change(current.value);
|
|
210
|
+
if (onlyIfChanged && current.revision > 0 && JSON.stringify(value) === JSON.stringify(current.value)) {
|
|
211
|
+
return current;
|
|
212
|
+
}
|
|
139
213
|
const next = JSON.stringify({
|
|
140
|
-
value
|
|
214
|
+
value,
|
|
141
215
|
revision: current.revision + 1,
|
|
142
216
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
143
217
|
});
|
|
144
218
|
if (await storage.setIfEquals(this.recordKey, raw, next)) {
|
|
145
|
-
await this.
|
|
219
|
+
await this.backend.publish(this.name, epoch).catch((error) => this.backend.reportError(error));
|
|
146
220
|
return this.parse(next);
|
|
147
221
|
}
|
|
148
222
|
}
|
|
149
223
|
}
|
|
150
224
|
subscribe(listener) {
|
|
151
225
|
let active = true;
|
|
152
|
-
let seen = this.
|
|
226
|
+
let seen = this.current().then(
|
|
153
227
|
(snapshot) => snapshot.revision,
|
|
154
228
|
() => -1
|
|
155
229
|
);
|
|
@@ -157,7 +231,7 @@ var StoredResourceKey = class {
|
|
|
157
231
|
if (!active) return revision;
|
|
158
232
|
let snapshot;
|
|
159
233
|
try {
|
|
160
|
-
snapshot = await this.
|
|
234
|
+
snapshot = await this.current();
|
|
161
235
|
} catch (error) {
|
|
162
236
|
this.backend.reportError(error);
|
|
163
237
|
return revision;
|
|
@@ -183,6 +257,184 @@ var StoredResourceKey = class {
|
|
|
183
257
|
return record.updatedAt === void 0 ? { value: record.value, revision: record.revision } : { value: record.value, revision: record.revision, updatedAt: record.updatedAt };
|
|
184
258
|
}
|
|
185
259
|
};
|
|
260
|
+
var ProducedKey = class extends StoredResourceKey {
|
|
261
|
+
constructor(store, backend, name, produce, throttle) {
|
|
262
|
+
super(store, backend, name, initialRecordOf(name, void 0));
|
|
263
|
+
this.produce = produce;
|
|
264
|
+
this.minIntervalMs = throttle.minIntervalMs ?? DEFAULT_MIN_INTERVAL_MS;
|
|
265
|
+
this.costFactor = throttle.costFactor ?? DEFAULT_COST_FACTOR;
|
|
266
|
+
}
|
|
267
|
+
produce;
|
|
268
|
+
/** Moves on each `markDirty()`; the key is clean once a run that started at the current one has stored its output. */
|
|
269
|
+
generation = 1;
|
|
270
|
+
producedGeneration = 0;
|
|
271
|
+
/** The store's epoch the stored output was produced in: after a close, the reopened storage may not hold it. */
|
|
272
|
+
producedEpoch = -1;
|
|
273
|
+
run;
|
|
274
|
+
runGeneration = 0;
|
|
275
|
+
runEpoch = -1;
|
|
276
|
+
timer;
|
|
277
|
+
subscribers = 0;
|
|
278
|
+
lastEndedAt = -Infinity;
|
|
279
|
+
lastDurationMs = 0;
|
|
280
|
+
minIntervalMs;
|
|
281
|
+
costFactor;
|
|
282
|
+
/** No one subscribes and no run is due or running: what a family may forget. */
|
|
283
|
+
get idle() {
|
|
284
|
+
return this.subscribers === 0 && !this.run && !this.timer;
|
|
285
|
+
}
|
|
286
|
+
markDirty() {
|
|
287
|
+
this.generation++;
|
|
288
|
+
if (this.subscribers > 0) this.schedule();
|
|
289
|
+
}
|
|
290
|
+
async get() {
|
|
291
|
+
for (; ; ) {
|
|
292
|
+
if (!this.run) return this.dirty ? this.start() : super.get();
|
|
293
|
+
if (this.runGeneration === this.generation && this.runEpoch === this.backend.epoch()) return this.run;
|
|
294
|
+
await this.run.catch(() => void 0);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/** Marked dirty since the last stored run, or the store closed since then, so its storage may not hold the output. */
|
|
298
|
+
get dirty() {
|
|
299
|
+
return this.producedGeneration < this.generation || this.producedEpoch !== this.backend.epoch();
|
|
300
|
+
}
|
|
301
|
+
/** A subscription reads the stored value: only a read or the throttled timer runs the producer. */
|
|
302
|
+
current() {
|
|
303
|
+
return super.get();
|
|
304
|
+
}
|
|
305
|
+
subscribe(listener) {
|
|
306
|
+
this.subscribers++;
|
|
307
|
+
const stop = super.subscribe(listener);
|
|
308
|
+
this.schedule();
|
|
309
|
+
let subscribed = true;
|
|
310
|
+
return () => {
|
|
311
|
+
if (!subscribed) return;
|
|
312
|
+
subscribed = false;
|
|
313
|
+
stop();
|
|
314
|
+
if (--this.subscribers > 0) return;
|
|
315
|
+
clearTimeout(this.timer);
|
|
316
|
+
this.timer = void 0;
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
schedule() {
|
|
320
|
+
if (this.timer || this.run || !this.dirty) return;
|
|
321
|
+
const waitMs = Math.max(this.minIntervalMs, this.lastDurationMs * this.costFactor);
|
|
322
|
+
this.timer = setTimeout(
|
|
323
|
+
() => {
|
|
324
|
+
this.timer = void 0;
|
|
325
|
+
if (this.subscribers > 0 && !this.run && this.dirty) {
|
|
326
|
+
this.start().catch(() => void 0);
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
Math.max(0, this.lastEndedAt + waitMs - performance.now())
|
|
330
|
+
);
|
|
331
|
+
this.timer.unref?.();
|
|
332
|
+
}
|
|
333
|
+
start() {
|
|
334
|
+
clearTimeout(this.timer);
|
|
335
|
+
this.timer = void 0;
|
|
336
|
+
const generation = this.runGeneration = this.generation;
|
|
337
|
+
const epoch = this.runEpoch = this.backend.epoch();
|
|
338
|
+
const startedAt = performance.now();
|
|
339
|
+
const run = this.produceAndStore(generation, epoch);
|
|
340
|
+
this.run = run;
|
|
341
|
+
const settle = (produced) => {
|
|
342
|
+
this.lastEndedAt = performance.now();
|
|
343
|
+
this.lastDurationMs = this.lastEndedAt - startedAt;
|
|
344
|
+
if (this.run === run) this.run = void 0;
|
|
345
|
+
if (this.subscribers > 0 && (produced || this.generation !== generation)) this.schedule();
|
|
346
|
+
};
|
|
347
|
+
run.then(
|
|
348
|
+
() => settle(true),
|
|
349
|
+
(error) => {
|
|
350
|
+
settle(false);
|
|
351
|
+
if (!(error instanceof ResourceStoreClosedError)) this.backend.reportError(error);
|
|
352
|
+
}
|
|
353
|
+
);
|
|
354
|
+
return run;
|
|
355
|
+
}
|
|
356
|
+
async produceAndStore(generation, epoch) {
|
|
357
|
+
const value = await this.produce();
|
|
358
|
+
let snapshot;
|
|
359
|
+
try {
|
|
360
|
+
snapshot = await this.write(() => value, true, epoch);
|
|
361
|
+
} catch (error) {
|
|
362
|
+
throw error instanceof ResourceStoreClosedError ? new ResourceStoreClosedError(this.name) : error;
|
|
363
|
+
}
|
|
364
|
+
this.producedGeneration = Math.max(this.producedGeneration, generation);
|
|
365
|
+
this.producedEpoch = epoch;
|
|
366
|
+
return snapshot;
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
var FamilyKeyHandle = class {
|
|
370
|
+
constructor(family, name, params) {
|
|
371
|
+
this.family = family;
|
|
372
|
+
this.name = name;
|
|
373
|
+
this.params = params;
|
|
374
|
+
}
|
|
375
|
+
family;
|
|
376
|
+
name;
|
|
377
|
+
params;
|
|
378
|
+
get store() {
|
|
379
|
+
return this.family.store;
|
|
380
|
+
}
|
|
381
|
+
get() {
|
|
382
|
+
return this.family.liveKey(this.params).get();
|
|
383
|
+
}
|
|
384
|
+
set(value) {
|
|
385
|
+
return this.family.liveKey(this.params).set(value);
|
|
386
|
+
}
|
|
387
|
+
update(change) {
|
|
388
|
+
return this.family.liveKey(this.params).update(change);
|
|
389
|
+
}
|
|
390
|
+
subscribe(listener) {
|
|
391
|
+
return this.family.liveKey(this.params).subscribe(listener);
|
|
392
|
+
}
|
|
393
|
+
markDirty() {
|
|
394
|
+
this.family.liveKey(this.params).markDirty();
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
var KeyFamily = class {
|
|
398
|
+
constructor(store, name, create, handleOf) {
|
|
399
|
+
this.store = store;
|
|
400
|
+
this.name = name;
|
|
401
|
+
this.create = create;
|
|
402
|
+
this.handleOf = handleOf;
|
|
403
|
+
}
|
|
404
|
+
store;
|
|
405
|
+
name;
|
|
406
|
+
create;
|
|
407
|
+
handleOf;
|
|
408
|
+
members = /* @__PURE__ */ new Map();
|
|
409
|
+
key(params) {
|
|
410
|
+
return this.member(params).handle;
|
|
411
|
+
}
|
|
412
|
+
/** The key the family holds for `params` now, made again if it was forgotten. */
|
|
413
|
+
liveKey(params) {
|
|
414
|
+
return this.member(params).key;
|
|
415
|
+
}
|
|
416
|
+
member(params) {
|
|
417
|
+
const memberKey = memberName(this.name, params);
|
|
418
|
+
let member = this.members.get(memberKey);
|
|
419
|
+
if (member) {
|
|
420
|
+
this.members.delete(memberKey);
|
|
421
|
+
} else {
|
|
422
|
+
const key = this.create(memberKey, { ...params });
|
|
423
|
+
member = { key, handle: this.handleOf ? this.handleOf(memberKey, { ...params }) : key };
|
|
424
|
+
}
|
|
425
|
+
this.members.set(memberKey, member);
|
|
426
|
+
this.forgetIdleKeys(memberKey);
|
|
427
|
+
return member;
|
|
428
|
+
}
|
|
429
|
+
/** Forgets the oldest idle keys past the limit, never `returning`: its caller is about to use it, idle as it is. */
|
|
430
|
+
forgetIdleKeys(returning) {
|
|
431
|
+
for (const [memberKey, { key }] of this.members) {
|
|
432
|
+
if (this.members.size <= FAMILY_KEYS_KEPT) return;
|
|
433
|
+
if (memberKey === returning) continue;
|
|
434
|
+
if (!(key instanceof ProducedKey) || key.idle) this.members.delete(memberKey);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
};
|
|
186
438
|
function resourceStore(options = {}) {
|
|
187
439
|
const parsed = resourceStoreOptionsSchema.safeParse(options);
|
|
188
440
|
if (!parsed.success) {
|
|
@@ -50,6 +50,9 @@ var ResourceRegistry = class extends RegistryAbstract {
|
|
|
50
50
|
// version + emitter
|
|
51
51
|
version = 0;
|
|
52
52
|
emitter = new ResourceEmitter();
|
|
53
|
+
/** Subscribers by URI: a session's `resources/subscribe`, or a `subscriptions/listen` stream's URI prefix. */
|
|
54
|
+
watchers = /* @__PURE__ */ new Map();
|
|
55
|
+
watchListeners = /* @__PURE__ */ new Set();
|
|
53
56
|
/**
|
|
54
57
|
* When false, the registry holds only the entries registered into it and adopts nothing: it
|
|
55
58
|
* does not pull in the apps or the other registries visible on `providers`. A remote app's
|
|
@@ -416,6 +419,34 @@ var ResourceRegistry = class extends RegistryAbstract {
|
|
|
416
419
|
}
|
|
417
420
|
return this.emitter.on((e) => cb({ ...e, snapshot: this.listAllInstances().filter(filter) }));
|
|
418
421
|
}
|
|
422
|
+
/** Count a subscriber of `uri` until {@link unwatchUri}: a session's `resources/subscribe`, or a listen stream's prefix. */
|
|
423
|
+
watchUri(uri) {
|
|
424
|
+
const count = this.watchers.get(uri) ?? 0;
|
|
425
|
+
this.watchers.set(uri, count + 1);
|
|
426
|
+
if (count === 0) this.emitWatchChange();
|
|
427
|
+
}
|
|
428
|
+
unwatchUri(uri) {
|
|
429
|
+
const count = this.watchers.get(uri);
|
|
430
|
+
if (count === void 0) return;
|
|
431
|
+
if (count > 1) {
|
|
432
|
+
this.watchers.set(uri, count - 1);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
this.watchers.delete(uri);
|
|
436
|
+
this.emitWatchChange();
|
|
437
|
+
}
|
|
438
|
+
/** The URIs (or listen-stream prefixes) that have a subscriber now. */
|
|
439
|
+
watchedUris() {
|
|
440
|
+
return [...this.watchers.keys()];
|
|
441
|
+
}
|
|
442
|
+
/** Call `listener` when a URI gets its first subscriber or loses its last one. */
|
|
443
|
+
onWatchChange(listener) {
|
|
444
|
+
this.watchListeners.add(listener);
|
|
445
|
+
return () => this.watchListeners.delete(listener);
|
|
446
|
+
}
|
|
447
|
+
emitWatchChange() {
|
|
448
|
+
for (const listener of [...this.watchListeners]) listener();
|
|
449
|
+
}
|
|
419
450
|
/**
|
|
420
451
|
* Signal that a specific resource's content has changed without modifying the resource list.
|
|
421
452
|
* Emits an 'updated' event that NotificationService uses to notify subscribed sessions.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// libs/sdk/src/scope/http-scope.helper.ts
|
|
2
2
|
import { default as default2 } from "../http-route/flows/http.route.flow.mjs";
|
|
3
|
-
import { attachHttpRoutes } from "../http-route/http-route.table.mjs";
|
|
3
|
+
import { attachHttpRoutes, peopleKeepSessionsInSqlite } from "../http-route/http-route.table.mjs";
|
|
4
4
|
import { default as default3 } from "./flows/http.request.flow.mjs";
|
|
5
5
|
import { default as default4 } from "./flows/http.ip-filter.flow.mjs";
|
|
6
6
|
import { TransportService } from "../transport/transport.registry.mjs";
|
|
@@ -15,6 +15,7 @@ export {
|
|
|
15
15
|
TransportService,
|
|
16
16
|
attachHttpRoutes,
|
|
17
17
|
loadStreamableHttpTransportOnStart,
|
|
18
|
+
peopleKeepSessionsInSqlite,
|
|
18
19
|
registerCustomHttpRoutes,
|
|
19
20
|
servedHealthPaths
|
|
20
21
|
};
|
|
@@ -512,7 +512,7 @@ var Scope = class _Scope extends ScopeEntry {
|
|
|
512
512
|
if (this.transportService) this.logger.verbose("TransportService initialized");
|
|
513
513
|
this.logger.verbose("AuthRegistry initialized");
|
|
514
514
|
mark("batch1:parallel (hooks+flows+auth+apps)");
|
|
515
|
-
let topLevelSqliteUsed = this.transportService?.isSessionStoreConfigured() === true && this.transportService.getBackendKind() === "sqlite" || this.taskBackendType === "sqlite" || this.elicitationBackendType === "sqlite" || this._persistentQuestions?.type === "sqlite";
|
|
515
|
+
let topLevelSqliteUsed = this.transportService?.isSessionStoreConfigured() === true && this.transportService.getBackendKind() === "sqlite" || this.taskBackendType === "sqlite" || this.elicitationBackendType === "sqlite" || this._persistentQuestions?.type === "sqlite" || httpServing?.peopleKeepSessionsInSqlite(this, resolvedTopLevelSqlite) === true;
|
|
516
516
|
const serverPlugins = [...this.metadata.plugins ?? []];
|
|
517
517
|
const appPlugins = this.scopeApps.getApps().flatMap((app) => "plugins" in app.metadata ? app.metadata.plugins ?? [] : []);
|
|
518
518
|
const impliedObservability = this.metadata.observability === void 0 ? devEventsObservabilityConfig([...serverPlugins, ...appPlugins]) : void 0;
|
|
@@ -745,7 +745,7 @@ var Scope = class _Scope extends ScopeEntry {
|
|
|
745
745
|
});
|
|
746
746
|
}
|
|
747
747
|
if (httpServing) {
|
|
748
|
-
httpServing.attachHttpRoutes(this, this.globalProviders);
|
|
748
|
+
await httpServing.attachHttpRoutes(this, this.globalProviders, { sqlite: this.topLevelSqlite });
|
|
749
749
|
httpServing.registerCustomHttpRoutes({
|
|
750
750
|
routes: this.metadata.http?.routes,
|
|
751
751
|
server: this.httpRouteRegistrar,
|
|
@@ -18,6 +18,9 @@ function normalizeOrigin(value) {
|
|
|
18
18
|
return origin;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
function invalidOriginMessage(origin) {
|
|
22
|
+
return origin.trim() === "null" ? "Invalid Origin header: null (a form posted from a page served with Referrer-Policy: no-referrer, or from a sandboxed page, sends Origin: null)" : "Invalid Origin header";
|
|
23
|
+
}
|
|
21
24
|
function compileHostValidation(rules) {
|
|
22
25
|
return {
|
|
23
26
|
hosts: rules.allowedHosts ? new Set(rules.allowedHosts.map(normalizeHost)) : void 0,
|
|
@@ -41,7 +44,7 @@ function validateHostHeaders(headers, compiled) {
|
|
|
41
44
|
if (compiled.origins) {
|
|
42
45
|
const origin = headers.origin;
|
|
43
46
|
if (origin && !compiled.origins.has(normalizeOrigin(origin))) {
|
|
44
|
-
return { status: 403, error: "Forbidden", message:
|
|
47
|
+
return { status: 403, error: "Forbidden", message: invalidOriginMessage(origin) };
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
return void 0;
|
|
@@ -27,9 +27,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
27
27
|
// libs/sdk/src/server/adapters/polyfills/browser-express-host.ts
|
|
28
28
|
var browser_express_host_exports = {};
|
|
29
29
|
__export(browser_express_host_exports, {
|
|
30
|
-
ExpressHostAdapter: () => ExpressHostAdapter
|
|
30
|
+
ExpressHostAdapter: () => ExpressHostAdapter,
|
|
31
|
+
UserContentListener: () => UserContentListener
|
|
31
32
|
});
|
|
32
|
-
var ExpressHostAdapter;
|
|
33
|
+
var ExpressHostAdapter, UserContentListener;
|
|
33
34
|
var init_browser_express_host = __esm({
|
|
34
35
|
"libs/sdk/src/server/adapters/polyfills/browser-express-host.ts"() {
|
|
35
36
|
"use strict";
|
|
@@ -38,6 +39,11 @@ var init_browser_express_host = __esm({
|
|
|
38
39
|
throw new Error("ExpressHostAdapter is not available in browser environments");
|
|
39
40
|
}
|
|
40
41
|
};
|
|
42
|
+
UserContentListener = class {
|
|
43
|
+
constructor(_options) {
|
|
44
|
+
throw new Error("UserContentListener is not available in browser environments");
|
|
45
|
+
}
|
|
46
|
+
};
|
|
41
47
|
}
|
|
42
48
|
});
|
|
43
49
|
|
|
@@ -62,6 +68,7 @@ var FrontMcpServerInstance = class extends FrontMcpServer {
|
|
|
62
68
|
metricsRouteRegistered = false;
|
|
63
69
|
_metricsService;
|
|
64
70
|
_metricsConfig;
|
|
71
|
+
userContent;
|
|
65
72
|
constructor(httpConfig) {
|
|
66
73
|
super();
|
|
67
74
|
this.config = httpConfig;
|
|
@@ -162,10 +169,21 @@ var FrontMcpServerInstance = class extends FrontMcpServer {
|
|
|
162
169
|
isProduction()
|
|
163
170
|
);
|
|
164
171
|
logSecurityFindings(findings, console);
|
|
165
|
-
|
|
172
|
+
const mainListener = this.config.socketPath ?? this.config.port;
|
|
173
|
+
await this.host.start(mainListener, bindAddress);
|
|
174
|
+
if (this.config.userContent) {
|
|
175
|
+
const { UserContentListener: UserContentListener2 } = (init_browser_express_host(), __toCommonJS(browser_express_host_exports));
|
|
176
|
+
this.userContent = new UserContentListener2(this.config.userContent);
|
|
177
|
+
await this.userContent.start(mainListener, bindAddress);
|
|
178
|
+
}
|
|
166
179
|
}
|
|
167
180
|
async stop() {
|
|
168
|
-
await
|
|
181
|
+
const results = await Promise.allSettled([
|
|
182
|
+
(async () => this.host.stop())(),
|
|
183
|
+
(async () => this.userContent?.stop())()
|
|
184
|
+
]);
|
|
185
|
+
const failure = results.find((result) => result.status === "rejected");
|
|
186
|
+
if (failure) throw failure.reason;
|
|
169
187
|
}
|
|
170
188
|
};
|
|
171
189
|
export {
|
package/browser/subsystems.mjs
CHANGED
|
@@ -43,7 +43,18 @@ import {
|
|
|
43
43
|
ChannelEventBus,
|
|
44
44
|
ChannelReplyTool
|
|
45
45
|
} from "./channel/index.mjs";
|
|
46
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
EventInstance,
|
|
48
|
+
EventRegistry,
|
|
49
|
+
MAX_OPEN_STREAMS,
|
|
50
|
+
MAX_POLL_LEASES,
|
|
51
|
+
POLL_LEASE_INTERVALS,
|
|
52
|
+
POLL_LEASE_MIN_MS,
|
|
53
|
+
POLL_LEASE_SWEEP_INTERVAL_MS,
|
|
54
|
+
SUBSCRIPTION_SWEEP_INTERVAL_MS,
|
|
55
|
+
SUSPEND_AFTER_FAILURES,
|
|
56
|
+
pollLeaseMs
|
|
57
|
+
} from "./event/index.mjs";
|
|
47
58
|
export {
|
|
48
59
|
CancelJobTool,
|
|
49
60
|
ChannelEmitter,
|
|
@@ -67,8 +78,13 @@ export {
|
|
|
67
78
|
JobRunResource,
|
|
68
79
|
ListJobsTool,
|
|
69
80
|
ListWorkflowsTool,
|
|
81
|
+
MAX_OPEN_STREAMS,
|
|
82
|
+
MAX_POLL_LEASES,
|
|
70
83
|
McpStatelessClientAdapter,
|
|
71
84
|
MemoryEventStore,
|
|
85
|
+
POLL_LEASE_INTERVALS,
|
|
86
|
+
POLL_LEASE_MIN_MS,
|
|
87
|
+
POLL_LEASE_SWEEP_INTERVAL_MS,
|
|
72
88
|
RecreateableSSEServerTransport,
|
|
73
89
|
RecreateableStreamableHTTPServerTransport,
|
|
74
90
|
RedisEventStore,
|
|
@@ -77,6 +93,8 @@ export {
|
|
|
77
93
|
RemoveJobTool,
|
|
78
94
|
RemoveWorkflowTool,
|
|
79
95
|
SSEServerTransport,
|
|
96
|
+
SUBSCRIPTION_SWEEP_INTERVAL_MS,
|
|
97
|
+
SUSPEND_AFTER_FAILURES,
|
|
80
98
|
UpdateJobTool,
|
|
81
99
|
UpdateWorkflowTool,
|
|
82
100
|
WorkflowEmitter,
|
|
@@ -87,5 +105,6 @@ export {
|
|
|
87
105
|
createEventStore,
|
|
88
106
|
jobRunUri,
|
|
89
107
|
mayAccessRun,
|
|
90
|
-
negotiateRemoteProtocol
|
|
108
|
+
negotiateRemoteProtocol,
|
|
109
|
+
pollLeaseMs
|
|
91
110
|
};
|
|
@@ -841,9 +841,9 @@ var CallToolFlow = class extends FlowBase {
|
|
|
841
841
|
const keyPaths = findUndeclaredArguments(tool.inputSchema ?? {}, sent, parsed);
|
|
842
842
|
if (keyPaths.length === 0) return;
|
|
843
843
|
const messages = await import("../undeclared-arguments-message.mjs");
|
|
844
|
-
const
|
|
845
|
-
if (policy === "fail") throw new InvalidInputError(messages.undeclaredArgumentsRefusal(keyPaths,
|
|
846
|
-
this.state.set("undeclaredArgumentsNote", messages.undeclaredArgumentsNote(keyPaths,
|
|
844
|
+
const shape = tool.inputSchema ?? {};
|
|
845
|
+
if (policy === "fail") throw new InvalidInputError(messages.undeclaredArgumentsRefusal(keyPaths, shape));
|
|
846
|
+
this.state.set("undeclaredArgumentsNote", messages.undeclaredArgumentsNote(keyPaths, shape));
|
|
847
847
|
const newKeyPaths = unreportedKeyPaths(reportedUndeclaredArguments, tool, keyPaths.map(formatKeyPath));
|
|
848
848
|
if (newKeyPaths.length > 0) this.logger.warn(messages.undeclaredArgumentsWarning(tool.metadata.name, newKeyPaths));
|
|
849
849
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// libs/sdk/src/tool/undeclared-arguments-message.ts
|
|
2
|
-
import { formatKeyPath } from "./undeclared-arguments.mjs";
|
|
3
|
-
function undeclaredArgumentsRefusal(keyPaths,
|
|
4
|
-
return `Unknown arguments: ${describeUndeclaredArguments(keyPaths,
|
|
2
|
+
import { declaredKeysAt, formatKeyPath } from "./undeclared-arguments.mjs";
|
|
3
|
+
function undeclaredArgumentsRefusal(keyPaths, shape) {
|
|
4
|
+
return `Unknown arguments: ${describeUndeclaredArguments(keyPaths, shape)}`;
|
|
5
5
|
}
|
|
6
|
-
function undeclaredArgumentsNote(keyPaths,
|
|
7
|
-
return `These arguments are not declared and were ignored: ${describeUndeclaredArguments(keyPaths,
|
|
6
|
+
function undeclaredArgumentsNote(keyPaths, shape) {
|
|
7
|
+
return `These arguments are not declared and were ignored: ${describeUndeclaredArguments(keyPaths, shape)}.`;
|
|
8
8
|
}
|
|
9
9
|
function undeclaredArgumentsWarning(toolName, newKeyPaths) {
|
|
10
10
|
return `Tool "${toolName}" was called with arguments its inputSchema does not declare, so they were ignored: ${namedWithTheRestCounted(newKeyPaths.map(shortened))}. Declare them, or set input.undeclaredKeys to 'strip' or 'fail'.`;
|
|
@@ -12,11 +12,13 @@ function undeclaredArgumentsWarning(toolName, newKeyPaths) {
|
|
|
12
12
|
var MAX_NAMED_ARGUMENTS = 20;
|
|
13
13
|
var MAX_KEY_LENGTH = 64;
|
|
14
14
|
var MAX_COMPARED_KEYS = 200;
|
|
15
|
-
function describeUndeclaredArguments(keyPaths,
|
|
15
|
+
function describeUndeclaredArguments(keyPaths, shape) {
|
|
16
16
|
const described = keyPaths.slice(0, MAX_NAMED_ARGUMENTS).map((keyPath) => {
|
|
17
17
|
const shown = shortened(formatKeyPath(keyPath));
|
|
18
|
-
const
|
|
19
|
-
|
|
18
|
+
const parentPath = keyPath.slice(0, -1);
|
|
19
|
+
const closest = closestKey(keyPath[keyPath.length - 1], declaredKeysAt(shape, parentPath));
|
|
20
|
+
if (!closest) return `'${shown}'`;
|
|
21
|
+
return `'${shown}' (did you mean '${shortened(formatKeyPath([...parentPath, closest]))}'?)`;
|
|
20
22
|
});
|
|
21
23
|
return namedWithTheRestCounted(described, keyPaths.length);
|
|
22
24
|
}
|
|
@@ -20,6 +20,38 @@ function findUndeclaredArguments(shape, sent, parsed) {
|
|
|
20
20
|
walk(sent, parsed, []);
|
|
21
21
|
return [...dropped.values()].sort((left, right) => formatKeyPath(left).localeCompare(formatKeyPath(right)));
|
|
22
22
|
}
|
|
23
|
+
function declaredKeysAt(shape, parentPath) {
|
|
24
|
+
let level = [{ type: "object", shape }];
|
|
25
|
+
for (const segment of parentPath) {
|
|
26
|
+
const next = level.flatMap((definition) => {
|
|
27
|
+
if (segment === "[]") return definition["type"] === "array" ? definitionsOf(definition["element"]) : [];
|
|
28
|
+
const fields = definition["type"] === "object" ? definition["shape"] : {};
|
|
29
|
+
return Object.prototype.hasOwnProperty.call(fields, segment) ? definitionsOf(fields[segment]) : [];
|
|
30
|
+
});
|
|
31
|
+
level = [...new Set(next)];
|
|
32
|
+
}
|
|
33
|
+
const keys = level.flatMap(
|
|
34
|
+
(definition) => definition["type"] === "object" ? Object.keys(definition["shape"]) : []
|
|
35
|
+
);
|
|
36
|
+
return [...new Set(keys)];
|
|
37
|
+
}
|
|
38
|
+
var WRAPPER_TYPES = /* @__PURE__ */ new Set(["optional", "nullable", "default", "prefault", "nonoptional", "readonly", "catch"]);
|
|
39
|
+
function definitionsOf(schema, seen = /* @__PURE__ */ new Set()) {
|
|
40
|
+
const definition = schema?._zod?.def;
|
|
41
|
+
if (!definition || seen.has(definition)) return [];
|
|
42
|
+
seen.add(definition);
|
|
43
|
+
const type = definition["type"];
|
|
44
|
+
if (typeof type === "string" && WRAPPER_TYPES.has(type)) return definitionsOf(definition["innerType"], seen);
|
|
45
|
+
if (type === "lazy") {
|
|
46
|
+
const inner = schema._zod.innerType;
|
|
47
|
+
return definitionsOf(inner ?? definition["getter"](), seen);
|
|
48
|
+
}
|
|
49
|
+
if (type === "union") return definition["options"].flatMap((option) => definitionsOf(option, seen));
|
|
50
|
+
if (type === "intersection") {
|
|
51
|
+
return [definition["left"], definition["right"]].flatMap((side) => definitionsOf(side, seen));
|
|
52
|
+
}
|
|
53
|
+
return [definition];
|
|
54
|
+
}
|
|
23
55
|
function formatKeyPath(keyPath) {
|
|
24
56
|
return keyPath.reduce(
|
|
25
57
|
(text, segment) => segment === "[]" ? `${text}[]` : text ? `${text}.${segment}` : segment,
|
|
@@ -30,6 +62,7 @@ function isPlainRecord(value) {
|
|
|
30
62
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31
63
|
}
|
|
32
64
|
export {
|
|
65
|
+
declaredKeysAt,
|
|
33
66
|
findUndeclaredArguments,
|
|
34
67
|
formatKeyPath
|
|
35
68
|
};
|