devframe 0.7.15 → 0.8.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/bin/devframe.mjs +8 -0
- package/dist/adapters/build.d.mts +8 -1
- package/dist/adapters/build.mjs +5 -3
- package/dist/adapters/cac.d.mts +1 -1
- package/dist/adapters/cac.mjs +1 -1
- package/dist/adapters/cli.d.mts +1 -1
- package/dist/adapters/cli.mjs +1 -1
- package/dist/adapters/dev.d.mts +2 -2
- package/dist/adapters/dev.mjs +1 -1
- package/dist/adapters/embedded.d.mts +1 -1
- package/dist/adapters/mcp.d.mts +45 -3
- package/dist/adapters/mcp.mjs +2 -2
- package/dist/agent-tool-name-C3b5vEwJ.mjs +34 -0
- package/dist/{cac-CjF0haJ6.mjs → cac-B-R_tDGJ.mjs} +19 -14
- package/dist/cli/main.d.mts +11 -0
- package/dist/cli/main.mjs +283 -0
- package/dist/client/index.d.mts +45 -9
- package/dist/client/index.mjs +266 -97
- package/dist/constants.d.mts +7 -1
- package/dist/constants.mjs +7 -1
- package/dist/{context-C_bqRR0i.d.mts → context-7BbaIUSI.d.mts} +1 -1
- package/dist/{context-C1Gr2BGB.mjs → context-C9Cgm1hP.mjs} +1 -1
- package/dist/{dev-OJFr4rx8.mjs → dev-D4M7Veo7.mjs} +22 -11
- package/dist/{devframe-BADsX91-.d.mts → devframe-Dsjn_Xtq.d.mts} +78 -15
- package/dist/diagnostics-B5-qHeqD.mjs +94 -0
- package/dist/{diagnostics-BXwBQmoN.mjs → diagnostics-hwjXp_UV.mjs} +8 -0
- package/dist/{dump-Cz7yVvsB.mjs → dump-CgZShDRB.mjs} +82 -6
- package/dist/{build-server-cANnMwg0.mjs → fetch-BZyK4v6W.mjs} +225 -51
- package/dist/helpers/vite.d.mts +1 -1
- package/dist/helpers/vite.mjs +2 -2
- package/dist/{host-h3-SjwRTwkE.mjs → host-h3-Kz7t5Xab.mjs} +83 -28
- package/dist/http-BghOqfTD.mjs +38 -0
- package/dist/{index-Brcd2V4t.d.mts → index-CeBbry0R.d.mts} +2 -2
- package/dist/{index-DgsLFhZg.d.mts → index-Dbw1p5ch.d.mts} +27 -3
- package/dist/{index-YDSJgsyG.d.mts → index-vAX6bYuc.d.mts} +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/instance-registry-D6fxYu36.mjs +190 -0
- package/dist/node/auth.d.mts +2 -2
- package/dist/node/hub-internals.d.mts +2 -2
- package/dist/node/hub-internals.mjs +1 -1
- package/dist/node/index.d.mts +104 -6
- package/dist/node/index.mjs +5 -4
- package/dist/recipes/common-rpc-functions.d.mts +33 -33
- package/dist/recipes/common-rpc-functions.mjs +6 -6
- package/dist/recipes/interactive-auth.d.mts +2 -2
- package/dist/recipes/interactive-auth.mjs +13 -13
- package/dist/rpc/dump.d.mts +1 -1
- package/dist/rpc/dump.mjs +1 -1
- package/dist/rpc/index.d.mts +3 -3
- package/dist/rpc/index.mjs +4 -4
- package/dist/rpc/transports/ws-client.d.mts +1 -1
- package/dist/rpc/transports/ws-client.mjs +1 -1
- package/dist/rpc/transports/ws-server.d.mts +1 -1
- package/dist/rpc/transports/ws-server.mjs +1 -1
- package/dist/{serialization-DpLXCy13.mjs → serialization-C8Mnw9hK.mjs} +1 -1
- package/dist/{server-BFsuZI9e.mjs → server-CcAPxuoT.mjs} +2 -2
- package/dist/{server-Bu5iB3aV.d.mts → server-VLQJouOO.d.mts} +2 -2
- package/dist/simple-schema-BDzLeJDk.d.mts +102 -0
- package/dist/simple-schema-DQPZrAaZ.mjs +154 -0
- package/dist/{storage-D_Xy9v1l.mjs → storage-Dzoc3NVC.mjs} +2 -62
- package/dist/{transports-BmDVn4SF.mjs → transports-vhizgqXM.mjs} +1 -1
- package/dist/types/index.d.mts +4 -4
- package/dist/{types-CrzNxXKq.d.mts → types-CnJSgRVa.d.mts} +33 -19
- package/dist/utils/agent-tool-name.d.mts +27 -0
- package/dist/utils/agent-tool-name.mjs +34 -0
- package/dist/utils/events.d.mts +1 -1
- package/dist/utils/shared-state.d.mts +1 -1
- package/dist/utils/simple-schema.d.mts +2 -0
- package/dist/utils/simple-schema.mjs +154 -0
- package/dist/utils/streaming-channel.d.mts +1 -1
- package/dist/{ws-client-DSXiI2h7.d.mts → ws-client-B6Tnr0ic.d.mts} +1 -1
- package/dist/{ws-server-9-wn7MNQ.d.mts → ws-server-D_Vjtums.d.mts} +1 -1
- package/package.json +18 -34
- package/skills/devframe/SKILL.md +1 -1
- package/dist/http-B2P55ZXg.mjs +0 -114
package/dist/client/index.mjs
CHANGED
|
@@ -12,6 +12,12 @@ import { withBase, withProtocol } from "ufo";
|
|
|
12
12
|
import { createBirpc } from "birpc";
|
|
13
13
|
//#region src/constants.ts
|
|
14
14
|
const DEVFRAME_CONNECTION_META_FILENAME = "__connection.json";
|
|
15
|
+
/**
|
|
16
|
+
* Global key holding the serializable connection prepared by
|
|
17
|
+
* `setupDevframeConnection()`. External viewers can use this key to read the
|
|
18
|
+
* connection from another JavaScript realm.
|
|
19
|
+
*/
|
|
20
|
+
const DEVFRAME_CONNECTION_KEY = "__DEVFRAME_CONNECTION__";
|
|
15
21
|
const DEVFRAME_RPC_DUMP_MANIFEST_FILENAME = "__rpc-dump/index.json";
|
|
16
22
|
/**
|
|
17
23
|
* Page-URL query parameter carrying a one-time authentication code (OTP) for
|
|
@@ -62,6 +68,14 @@ const diagnostics = defineDiagnostics({
|
|
|
62
68
|
DF0028: {
|
|
63
69
|
why: (p) => `Function "${p.name}" with type "${p.type}" cannot use \`snapshot: true\`. Only "query" functions support this sugar; "static" functions have equivalent default behavior already.`,
|
|
64
70
|
fix: "Remove `snapshot: true`, or change the function type to `query`."
|
|
71
|
+
},
|
|
72
|
+
DF0043: {
|
|
73
|
+
why: (p) => `RPC function "${p.name}" received an invalid argument at position ${p.index}: ${p.issues}`,
|
|
74
|
+
fix: "Pass a value that satisfies the `args` schema declared for this function."
|
|
75
|
+
},
|
|
76
|
+
DF0044: {
|
|
77
|
+
why: (p) => `RPC function "${p.name}" returned a value that failed its \`returns\` schema: ${p.issues}`,
|
|
78
|
+
fix: "Make the handler return a value that satisfies the `returns` schema, or relax the schema."
|
|
65
79
|
}
|
|
66
80
|
}
|
|
67
81
|
});
|
|
@@ -86,6 +100,70 @@ function isPlainErrorShape(value) {
|
|
|
86
100
|
return typeof value === "object" && value !== null && typeof value.message === "string" && typeof value.name === "string";
|
|
87
101
|
}
|
|
88
102
|
//#endregion
|
|
103
|
+
//#region src/rpc/validate-io.ts
|
|
104
|
+
/**
|
|
105
|
+
* Run a single [Standard Schema](https://standardschema.dev) validator,
|
|
106
|
+
* awaiting the result when the validator is asynchronous.
|
|
107
|
+
*/
|
|
108
|
+
async function runStandardSchema(schema, value) {
|
|
109
|
+
const result = schema["~standard"].validate(value);
|
|
110
|
+
return result instanceof Promise ? await result : result;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Render Standard Schema issues into a single human-readable line for a
|
|
114
|
+
* diagnostic message, prefixing each with its dotted path when present.
|
|
115
|
+
*/
|
|
116
|
+
function formatIssues(issues) {
|
|
117
|
+
return issues.map((issue) => {
|
|
118
|
+
const path = issue.path?.map((segment) => typeof segment === "object" ? segment.key : segment).join(".");
|
|
119
|
+
return path ? `${path}: ${issue.message}` : issue.message;
|
|
120
|
+
}).join("; ");
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Validate positional arguments against their declared schemas. Only
|
|
124
|
+
* indices with a schema are checked; extra arguments pass through
|
|
125
|
+
* untouched. Throws `DF0038` on the first failing argument.
|
|
126
|
+
*
|
|
127
|
+
* Validation guards the payload without rewriting it: the original values
|
|
128
|
+
* are handed to the handler unchanged, so a schema that describes a subset
|
|
129
|
+
* of an object never silently strips the sender's extra fields (and any
|
|
130
|
+
* declared transforms stay a purely type-level concern).
|
|
131
|
+
*
|
|
132
|
+
* @internal
|
|
133
|
+
*/
|
|
134
|
+
async function validateRpcArgs(name, argsSchema, args) {
|
|
135
|
+
const original = args.slice();
|
|
136
|
+
if (!argsSchema || argsSchema.length === 0) return original;
|
|
137
|
+
for (let index = 0; index < argsSchema.length; index++) {
|
|
138
|
+
const schema = argsSchema[index];
|
|
139
|
+
if (!schema) continue;
|
|
140
|
+
const result = await runStandardSchema(schema, args[index]);
|
|
141
|
+
if (result.issues) throw diagnostics.DF0043({
|
|
142
|
+
name,
|
|
143
|
+
index,
|
|
144
|
+
issues: formatIssues(result.issues)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return original;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Validate a handler's resolved return value against its declared schema.
|
|
151
|
+
* Throws `DF0039` when the value fails the schema, otherwise returns the
|
|
152
|
+
* original value unchanged (guard-only, never rewriting the payload — see
|
|
153
|
+
* {@link validateRpcArgs}). Passes through when no return schema is set.
|
|
154
|
+
*
|
|
155
|
+
* @internal
|
|
156
|
+
*/
|
|
157
|
+
async function validateRpcReturn(name, returnSchema, value) {
|
|
158
|
+
if (!returnSchema) return value;
|
|
159
|
+
const result = await runStandardSchema(returnSchema, value);
|
|
160
|
+
if (result.issues) throw diagnostics.DF0044({
|
|
161
|
+
name,
|
|
162
|
+
issues: formatIssues(result.issues)
|
|
163
|
+
});
|
|
164
|
+
return value;
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
89
167
|
//#region src/rpc/handler.ts
|
|
90
168
|
async function getRpcResolvedSetupResult(definition, context) {
|
|
91
169
|
if (!definition.setup) return {};
|
|
@@ -112,10 +190,22 @@ async function getRpcResolvedSetupResult(definition, context) {
|
|
|
112
190
|
return await definition.__promise;
|
|
113
191
|
}
|
|
114
192
|
async function getRpcHandler(definition, context) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
193
|
+
let handler = definition.handler;
|
|
194
|
+
if (!handler) {
|
|
195
|
+
const result = await getRpcResolvedSetupResult(definition, context);
|
|
196
|
+
if (!result.handler) throw diagnostics.DF0024({ name: definition.name });
|
|
197
|
+
handler = result.handler;
|
|
198
|
+
}
|
|
199
|
+
const argsSchema = definition.args;
|
|
200
|
+
const returnSchema = definition.returns;
|
|
201
|
+
if (!argsSchema && !returnSchema) return handler;
|
|
202
|
+
const inner = handler;
|
|
203
|
+
const validating = async (...args) => {
|
|
204
|
+
const validatedArgs = await validateRpcArgs(definition.name, argsSchema, args);
|
|
205
|
+
const output = await inner(...validatedArgs);
|
|
206
|
+
return await validateRpcReturn(definition.name, returnSchema, output);
|
|
207
|
+
};
|
|
208
|
+
return validating;
|
|
119
209
|
}
|
|
120
210
|
//#endregion
|
|
121
211
|
//#region src/rpc/cache.ts
|
|
@@ -289,6 +379,155 @@ function formatPath(parent, key) {
|
|
|
289
379
|
return key;
|
|
290
380
|
}
|
|
291
381
|
//#endregion
|
|
382
|
+
//#region src/client/connection-storage.ts
|
|
383
|
+
const CONNECTION_META_KEY = "__DEVFRAME_CONNECTION_META__";
|
|
384
|
+
const CONNECTION_AUTH_TOKEN_KEY = "__DEVFRAME_CONNECTION_AUTH_TOKEN__";
|
|
385
|
+
function readFromWindows(key) {
|
|
386
|
+
const getters = [
|
|
387
|
+
() => window?.[key],
|
|
388
|
+
() => globalThis?.[key],
|
|
389
|
+
() => parent.window?.[key]
|
|
390
|
+
];
|
|
391
|
+
for (const getter of getters) try {
|
|
392
|
+
const value = getter();
|
|
393
|
+
if (value) return value;
|
|
394
|
+
} catch {}
|
|
395
|
+
}
|
|
396
|
+
function readStoredConnection() {
|
|
397
|
+
return readFromWindows(DEVFRAME_CONNECTION_KEY);
|
|
398
|
+
}
|
|
399
|
+
function readStoredConnectionMeta() {
|
|
400
|
+
return readFromWindows(CONNECTION_META_KEY);
|
|
401
|
+
}
|
|
402
|
+
function readStoredAuthToken(userAuthToken) {
|
|
403
|
+
if (userAuthToken) return userAuthToken;
|
|
404
|
+
try {
|
|
405
|
+
const token = localStorage.getItem(CONNECTION_AUTH_TOKEN_KEY);
|
|
406
|
+
if (token) return token;
|
|
407
|
+
} catch {}
|
|
408
|
+
return readFromWindows(CONNECTION_AUTH_TOKEN_KEY);
|
|
409
|
+
}
|
|
410
|
+
function storeConnection(connection) {
|
|
411
|
+
globalThis[DEVFRAME_CONNECTION_KEY] = connection;
|
|
412
|
+
globalThis[CONNECTION_META_KEY] = {
|
|
413
|
+
...connection.connectionMeta,
|
|
414
|
+
baseUrl: connection.metaBaseUrl
|
|
415
|
+
};
|
|
416
|
+
if (connection.authToken) storeAuthToken(connection.authToken);
|
|
417
|
+
}
|
|
418
|
+
function storeAuthToken(token) {
|
|
419
|
+
try {
|
|
420
|
+
localStorage.setItem(CONNECTION_AUTH_TOKEN_KEY, token);
|
|
421
|
+
} catch {}
|
|
422
|
+
globalThis[CONNECTION_AUTH_TOKEN_KEY] = token;
|
|
423
|
+
const connection = readStoredConnection();
|
|
424
|
+
if (connection) globalThis[DEVFRAME_CONNECTION_KEY] = {
|
|
425
|
+
...connection,
|
|
426
|
+
authToken: token
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/client/connection.ts
|
|
431
|
+
function resolveMetaBaseUrl(baseURL) {
|
|
432
|
+
const metaPath = withBase(DEVFRAME_CONNECTION_META_FILENAME, baseURL);
|
|
433
|
+
try {
|
|
434
|
+
return new URL(metaPath, globalThis.location?.href).href;
|
|
435
|
+
} catch {
|
|
436
|
+
return metaPath;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
function withAuthToken(connection, authToken) {
|
|
440
|
+
return authToken && authToken !== connection.authToken ? {
|
|
441
|
+
...connection,
|
|
442
|
+
authToken
|
|
443
|
+
} : connection;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Return connection information previously prepared in this window or an
|
|
447
|
+
* accessible parent window.
|
|
448
|
+
*/
|
|
449
|
+
function getDevframeConnection() {
|
|
450
|
+
const connection = readStoredConnection();
|
|
451
|
+
if (connection) return withAuthToken(connection, readStoredAuthToken() ?? connection.authToken ?? connection.connectionMeta.authToken);
|
|
452
|
+
const connectionMeta = readStoredConnectionMeta();
|
|
453
|
+
if (!connectionMeta) return void 0;
|
|
454
|
+
return {
|
|
455
|
+
connectionMeta,
|
|
456
|
+
metaBaseUrl: connectionMeta.baseUrl ?? resolveMetaBaseUrl("./"),
|
|
457
|
+
authToken: readStoredAuthToken(connectionMeta.authToken)
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Prepare the connection information shared by a devframe client and external
|
|
462
|
+
* viewers. Reuses an explicit or previously prepared connection before
|
|
463
|
+
* fetching `__connection.json` from the configured base URLs.
|
|
464
|
+
*/
|
|
465
|
+
async function setupDevframeConnection(options = {}) {
|
|
466
|
+
if (options.connection) {
|
|
467
|
+
const connection = withAuthToken(options.connection, readStoredAuthToken(options.authToken ?? options.connection.authToken ?? options.connection.connectionMeta.authToken));
|
|
468
|
+
storeConnection(connection);
|
|
469
|
+
return connection;
|
|
470
|
+
}
|
|
471
|
+
const bases = Array.isArray(options.baseURL) ? options.baseURL : [options.baseURL ?? "./"];
|
|
472
|
+
if (options.connectionMeta) {
|
|
473
|
+
const connection = {
|
|
474
|
+
connectionMeta: options.connectionMeta,
|
|
475
|
+
metaBaseUrl: resolveMetaBaseUrl(bases[0] ?? "./"),
|
|
476
|
+
authToken: readStoredAuthToken(options.authToken ?? options.connectionMeta.authToken)
|
|
477
|
+
};
|
|
478
|
+
storeConnection(connection);
|
|
479
|
+
return connection;
|
|
480
|
+
}
|
|
481
|
+
const existing = getDevframeConnection();
|
|
482
|
+
if (existing) {
|
|
483
|
+
const connection = withAuthToken(existing, readStoredAuthToken(options.authToken ?? existing.authToken ?? existing.connectionMeta.authToken));
|
|
484
|
+
storeConnection(connection);
|
|
485
|
+
return connection;
|
|
486
|
+
}
|
|
487
|
+
const errors = [];
|
|
488
|
+
for (const base of bases) {
|
|
489
|
+
const metaPath = withBase(DEVFRAME_CONNECTION_META_FILENAME, base);
|
|
490
|
+
const metaUrl = resolveMetaBaseUrl(base);
|
|
491
|
+
try {
|
|
492
|
+
const response = await fetch(metaPath);
|
|
493
|
+
if (!response.ok) throw new Error(`Failed to fetch connection meta from ${metaUrl}: ${response.status}`);
|
|
494
|
+
const connectionMeta = await response.json();
|
|
495
|
+
const connection = {
|
|
496
|
+
connectionMeta,
|
|
497
|
+
metaBaseUrl: response.url || metaUrl,
|
|
498
|
+
authToken: readStoredAuthToken(options.authToken ?? connectionMeta.authToken)
|
|
499
|
+
};
|
|
500
|
+
storeConnection(connection);
|
|
501
|
+
return connection;
|
|
502
|
+
} catch (error) {
|
|
503
|
+
errors.push(error);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
throw new Error(`Failed to get connection meta from ${bases.join(", ")}`, { cause: errors });
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* The error rejected from `rpc.call(...)` (and carried on
|
|
510
|
+
* `rpc.connectionError`) when a call cannot be served because the connection is
|
|
511
|
+
* down, the client is unauthorized, or a call timed out. Its `kind` lets a UI
|
|
512
|
+
* tailor its message and recovery affordance without string-matching.
|
|
513
|
+
*/
|
|
514
|
+
var DevframeConnectionError = class extends Error {
|
|
515
|
+
name = "DevframeConnectionError";
|
|
516
|
+
kind;
|
|
517
|
+
constructor(kind, message, options) {
|
|
518
|
+
super(message, options);
|
|
519
|
+
this.kind = kind;
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
/**
|
|
523
|
+
* Whether a status means calls can be attempted. `connecting` counts because
|
|
524
|
+
* the transport queues outgoing calls until the socket opens; the terminal
|
|
525
|
+
* failure states short-circuit calls so a stuck socket never hangs the UI.
|
|
526
|
+
*/
|
|
527
|
+
function isCallableStatus(status) {
|
|
528
|
+
return status === "connected" || status === "connecting";
|
|
529
|
+
}
|
|
530
|
+
//#endregion
|
|
292
531
|
//#region src/client/otp.ts
|
|
293
532
|
/**
|
|
294
533
|
* Read a one-time authentication code (OTP) from the current page URL's query
|
|
@@ -1868,30 +2107,6 @@ function parseUA(uastringOrExtensions, extensions) {
|
|
|
1868
2107
|
};
|
|
1869
2108
|
}
|
|
1870
2109
|
//#endregion
|
|
1871
|
-
//#region src/client/connection.ts
|
|
1872
|
-
/**
|
|
1873
|
-
* The error rejected from `rpc.call(...)` (and carried on
|
|
1874
|
-
* `rpc.connectionError`) when a call cannot be served because the connection is
|
|
1875
|
-
* down, the client is unauthorized, or a call timed out. Its `kind` lets a UI
|
|
1876
|
-
* tailor its message and recovery affordance without string-matching.
|
|
1877
|
-
*/
|
|
1878
|
-
var DevframeConnectionError = class extends Error {
|
|
1879
|
-
name = "DevframeConnectionError";
|
|
1880
|
-
kind;
|
|
1881
|
-
constructor(kind, message, options) {
|
|
1882
|
-
super(message, options);
|
|
1883
|
-
this.kind = kind;
|
|
1884
|
-
}
|
|
1885
|
-
};
|
|
1886
|
-
/**
|
|
1887
|
-
* Whether a status means calls can be attempted. `connecting` counts because
|
|
1888
|
-
* the transport queues outgoing calls until the socket opens; the terminal
|
|
1889
|
-
* failure states short-circuit calls so a stuck socket never hangs the UI.
|
|
1890
|
-
*/
|
|
1891
|
-
function isCallableStatus(status) {
|
|
1892
|
-
return status === "connected" || status === "connecting";
|
|
1893
|
-
}
|
|
1894
|
-
//#endregion
|
|
1895
2110
|
//#region src/client/rpc-ws.ts
|
|
1896
2111
|
/**
|
|
1897
2112
|
* Resolve a {@link ConnectionMeta.websocket} descriptor into a concrete
|
|
@@ -1906,7 +2121,6 @@ function isCallableStatus(status) {
|
|
|
1906
2121
|
* endpoint, e.g. a side-car server on its own port.
|
|
1907
2122
|
*/
|
|
1908
2123
|
function resolveWsUrl(websocket, metaBaseUrl, loc) {
|
|
1909
|
-
const wsProtocol = loc.protocol === "https:" ? "wss:" : "ws:";
|
|
1910
2124
|
const base = (() => {
|
|
1911
2125
|
try {
|
|
1912
2126
|
return new URL(metaBaseUrl, loc.href);
|
|
@@ -1914,9 +2128,10 @@ function resolveWsUrl(websocket, metaBaseUrl, loc) {
|
|
|
1914
2128
|
return new URL(loc.href);
|
|
1915
2129
|
}
|
|
1916
2130
|
})();
|
|
2131
|
+
const wsProtocol = base.protocol === "https:" ? "wss:" : "ws:";
|
|
1917
2132
|
if (websocket && typeof websocket === "object") {
|
|
1918
2133
|
if (websocket.host != null || websocket.port != null) {
|
|
1919
|
-
const host = websocket.host ?? `${
|
|
2134
|
+
const host = websocket.host ?? `${base.hostname}:${websocket.port}`;
|
|
1920
2135
|
const target = new URL(websocket.path ?? "/", `${wsProtocol}//${host}`);
|
|
1921
2136
|
target.protocol = wsProtocol;
|
|
1922
2137
|
return target.href;
|
|
@@ -1925,7 +2140,7 @@ function resolveWsUrl(websocket, metaBaseUrl, loc) {
|
|
|
1925
2140
|
target.protocol = wsProtocol;
|
|
1926
2141
|
return target.href;
|
|
1927
2142
|
}
|
|
1928
|
-
if (typeof websocket === "number") return `${wsProtocol}//${
|
|
2143
|
+
if (typeof websocket === "number") return `${wsProtocol}//${base.hostname}:${websocket}`;
|
|
1929
2144
|
const str = websocket ?? "";
|
|
1930
2145
|
if (/^wss?:\/\//i.test(str)) return str;
|
|
1931
2146
|
if (/^https?:\/\//i.test(str)) return withProtocol(str, /^https/i.test(str) ? "wss://" : "ws://");
|
|
@@ -2210,78 +2425,21 @@ function createScopedClientContext(rpc, namespace) {
|
|
|
2210
2425
|
}
|
|
2211
2426
|
//#endregion
|
|
2212
2427
|
//#region src/client/rpc.ts
|
|
2213
|
-
const CONNECTION_META_KEY = "__DEVFRAME_CONNECTION_META__";
|
|
2214
|
-
const CONNECTION_AUTH_TOKEN_KEY = "__DEVFRAME_CONNECTION_AUTH_TOKEN__";
|
|
2215
|
-
function getStoredAuthToken(userAuthToken) {
|
|
2216
|
-
const getters = [
|
|
2217
|
-
() => userAuthToken,
|
|
2218
|
-
() => localStorage.getItem(CONNECTION_AUTH_TOKEN_KEY) ?? void 0,
|
|
2219
|
-
() => window?.[CONNECTION_AUTH_TOKEN_KEY],
|
|
2220
|
-
() => globalThis?.[CONNECTION_AUTH_TOKEN_KEY],
|
|
2221
|
-
() => parent.window?.[CONNECTION_AUTH_TOKEN_KEY]
|
|
2222
|
-
];
|
|
2223
|
-
for (const getter of getters) try {
|
|
2224
|
-
const value = getter();
|
|
2225
|
-
if (value) return value;
|
|
2226
|
-
} catch {}
|
|
2227
|
-
}
|
|
2228
|
-
function persistAuthToken(token) {
|
|
2229
|
-
try {
|
|
2230
|
-
localStorage.setItem(CONNECTION_AUTH_TOKEN_KEY, token);
|
|
2231
|
-
} catch {}
|
|
2232
|
-
globalThis[CONNECTION_AUTH_TOKEN_KEY] = token;
|
|
2233
|
-
}
|
|
2234
|
-
function findConnectionMetaFromWindows() {
|
|
2235
|
-
const getters = [
|
|
2236
|
-
() => window?.[CONNECTION_META_KEY],
|
|
2237
|
-
() => globalThis?.[CONNECTION_META_KEY],
|
|
2238
|
-
() => parent.window?.[CONNECTION_META_KEY]
|
|
2239
|
-
];
|
|
2240
|
-
for (const getter of getters) try {
|
|
2241
|
-
const value = getter();
|
|
2242
|
-
if (value) return value;
|
|
2243
|
-
} catch {}
|
|
2244
|
-
}
|
|
2245
2428
|
async function getDevframeRpcClient(options = {}) {
|
|
2246
2429
|
const { baseURL = "./", rpcOptions = {}, cacheOptions = false } = options;
|
|
2247
2430
|
const events = createEventEmitter();
|
|
2248
2431
|
const bases = Array.isArray(baseURL) ? baseURL : [baseURL];
|
|
2249
|
-
let
|
|
2432
|
+
let connection = await setupDevframeConnection(options);
|
|
2433
|
+
const { connectionMeta, metaBaseUrl, authToken } = connection;
|
|
2250
2434
|
let resolvedBaseURL = bases[0] ?? "./";
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
const metaPath = withBase(DEVFRAME_CONNECTION_META_FILENAME, resolvedBaseURL);
|
|
2255
|
-
try {
|
|
2256
|
-
return new URL(metaPath, globalThis.location?.href).href;
|
|
2257
|
-
} catch {
|
|
2258
|
-
return metaPath;
|
|
2259
|
-
}
|
|
2260
|
-
}
|
|
2261
|
-
if (!connectionMeta) {
|
|
2262
|
-
const errors = [];
|
|
2263
|
-
for (const base of bases) try {
|
|
2264
|
-
const response = await fetch(withBase(DEVFRAME_CONNECTION_META_FILENAME, base));
|
|
2265
|
-
if (!response.ok) throw new Error(`Failed to fetch connection meta: ${response.status}`);
|
|
2266
|
-
connectionMeta = await response.json();
|
|
2267
|
-
resolvedBaseURL = base;
|
|
2268
|
-
globalThis[CONNECTION_META_KEY] = {
|
|
2269
|
-
...connectionMeta,
|
|
2270
|
-
baseUrl: resolveMetaBaseUrl()
|
|
2271
|
-
};
|
|
2272
|
-
break;
|
|
2273
|
-
} catch (e) {
|
|
2274
|
-
errors.push(e);
|
|
2275
|
-
}
|
|
2276
|
-
if (!connectionMeta) throw new Error(`Failed to get connection meta from ${bases.join(", ")}`, { cause: errors });
|
|
2277
|
-
}
|
|
2435
|
+
try {
|
|
2436
|
+
resolvedBaseURL = new URL(".", metaBaseUrl).href;
|
|
2437
|
+
} catch {}
|
|
2278
2438
|
const cacheManager = new RpcCacheManager({
|
|
2279
2439
|
functions: [],
|
|
2280
2440
|
...typeof options.cacheOptions === "object" ? options.cacheOptions : {}
|
|
2281
2441
|
});
|
|
2282
2442
|
const context = { rpc: void 0 };
|
|
2283
|
-
const authToken = getStoredAuthToken(options.authToken || connectionMeta.authToken);
|
|
2284
|
-
if (authToken) persistAuthToken(authToken);
|
|
2285
2443
|
const clientRpc = new RpcFunctionsCollectorBase(context);
|
|
2286
2444
|
async function fetchJsonFromBases(path) {
|
|
2287
2445
|
const candidates = [resolvedBaseURL, ...bases.filter((base) => base !== resolvedBaseURL)].filter((x) => x != null);
|
|
@@ -2299,7 +2457,7 @@ async function getDevframeRpcClient(options = {}) {
|
|
|
2299
2457
|
const mode = connectionMeta.backend === "static" ? await createStaticRpcClientMode({ fetchJsonFromBases }) : createWsRpcClientMode({
|
|
2300
2458
|
authToken,
|
|
2301
2459
|
connectionMeta,
|
|
2302
|
-
metaBaseUrl
|
|
2460
|
+
metaBaseUrl,
|
|
2303
2461
|
events,
|
|
2304
2462
|
clientRpc,
|
|
2305
2463
|
callTimeout: options.callTimeout,
|
|
@@ -2339,17 +2497,28 @@ async function getDevframeRpcClient(options = {}) {
|
|
|
2339
2497
|
get connectionError() {
|
|
2340
2498
|
return mode.connectionError;
|
|
2341
2499
|
},
|
|
2500
|
+
get connection() {
|
|
2501
|
+
return connection;
|
|
2502
|
+
},
|
|
2342
2503
|
connectionMeta,
|
|
2343
2504
|
ensureTrusted: mode.ensureTrusted,
|
|
2344
2505
|
requestTrust: mode.requestTrust,
|
|
2345
2506
|
requestTrustWithToken: async (token) => {
|
|
2346
|
-
|
|
2507
|
+
storeAuthToken(token);
|
|
2508
|
+
connection = {
|
|
2509
|
+
...connection,
|
|
2510
|
+
authToken: token
|
|
2511
|
+
};
|
|
2347
2512
|
return mode.requestTrustWithToken(token);
|
|
2348
2513
|
},
|
|
2349
2514
|
requestTrustWithCode: async (code) => {
|
|
2350
2515
|
const token = await mode.requestTrustWithCode(code);
|
|
2351
2516
|
if (!token) return false;
|
|
2352
|
-
|
|
2517
|
+
storeAuthToken(token);
|
|
2518
|
+
connection = {
|
|
2519
|
+
...connection,
|
|
2520
|
+
authToken: token
|
|
2521
|
+
};
|
|
2353
2522
|
try {
|
|
2354
2523
|
authChannel?.postMessage({
|
|
2355
2524
|
type: "auth-update",
|
|
@@ -2419,4 +2588,4 @@ async function getDevframeRpcClient(options = {}) {
|
|
|
2419
2588
|
//#region src/client/index.ts
|
|
2420
2589
|
const connectDevframe = getDevframeRpcClient;
|
|
2421
2590
|
//#endregion
|
|
2422
|
-
export { DevframeConnectionError, authenticateWithUrlOtp, connectDevframe, consumeOtpFromUrl, createClientSettings, createRpcStreamingClientHost, createScopedClientContext, getDevframeRpcClient, isCallableStatus, readOtpFromUrl };
|
|
2591
|
+
export { DevframeConnectionError, authenticateWithUrlOtp, connectDevframe, consumeOtpFromUrl, createClientSettings, createRpcStreamingClientHost, createScopedClientContext, getDevframeConnection, getDevframeRpcClient, isCallableStatus, readOtpFromUrl, setupDevframeConnection };
|
package/dist/constants.d.mts
CHANGED
|
@@ -3,6 +3,12 @@ declare const DEVFRAME_MOUNT_PATH = "/__devframe/";
|
|
|
3
3
|
declare const DEVFRAME_MOUNT_PATH_NO_TRAILING_SLASH = "/__devframe";
|
|
4
4
|
declare const DEVFRAME_DIRNAME = "__devframe";
|
|
5
5
|
declare const DEVFRAME_CONNECTION_META_FILENAME = "__connection.json";
|
|
6
|
+
/**
|
|
7
|
+
* Global key holding the serializable connection prepared by
|
|
8
|
+
* `setupDevframeConnection()`. External viewers can use this key to read the
|
|
9
|
+
* connection from another JavaScript realm.
|
|
10
|
+
*/
|
|
11
|
+
declare const DEVFRAME_CONNECTION_KEY = "__DEVFRAME_CONNECTION__";
|
|
6
12
|
/**
|
|
7
13
|
* Route the WebSocket RPC endpoint is bound to, relative to a devframe's
|
|
8
14
|
* base path. Sits next to `__connection.json` so the deployed SPA can reach
|
|
@@ -60,4 +66,4 @@ declare const ANONYMOUS_RPC_PREFIX = "anonymous:";
|
|
|
60
66
|
*/
|
|
61
67
|
declare function isAnonymousRpcMethod(name: string): boolean;
|
|
62
68
|
//#endregion
|
|
63
|
-
export { ANONYMOUS_RPC_PREFIX, DEVFRAME_AUTH_TOKEN_QUERY_PARAM, DEVFRAME_CONNECTION_META_FILENAME, DEVFRAME_DIRNAME, DEVFRAME_DOCK_IMPORTS_FILENAME, DEVFRAME_DOCK_IMPORTS_VIRTUAL_ID, DEVFRAME_MCP_ROUTE, DEVFRAME_MOUNT_PATH, DEVFRAME_MOUNT_PATH_NO_TRAILING_SLASH, DEVFRAME_OTP_URL_PARAM, DEVFRAME_RPC_DUMP_DIRNAME, DEVFRAME_RPC_DUMP_MANIFEST_FILENAME, DEVFRAME_WS_ROUTE, REMOTE_CONNECTION_KEY, isAnonymousRpcMethod };
|
|
69
|
+
export { ANONYMOUS_RPC_PREFIX, DEVFRAME_AUTH_TOKEN_QUERY_PARAM, DEVFRAME_CONNECTION_KEY, DEVFRAME_CONNECTION_META_FILENAME, DEVFRAME_DIRNAME, DEVFRAME_DOCK_IMPORTS_FILENAME, DEVFRAME_DOCK_IMPORTS_VIRTUAL_ID, DEVFRAME_MCP_ROUTE, DEVFRAME_MOUNT_PATH, DEVFRAME_MOUNT_PATH_NO_TRAILING_SLASH, DEVFRAME_OTP_URL_PARAM, DEVFRAME_RPC_DUMP_DIRNAME, DEVFRAME_RPC_DUMP_MANIFEST_FILENAME, DEVFRAME_WS_ROUTE, REMOTE_CONNECTION_KEY, isAnonymousRpcMethod };
|
package/dist/constants.mjs
CHANGED
|
@@ -4,6 +4,12 @@ const DEVFRAME_MOUNT_PATH_NO_TRAILING_SLASH = "/__devframe";
|
|
|
4
4
|
const DEVFRAME_DIRNAME = "__devframe";
|
|
5
5
|
const DEVFRAME_CONNECTION_META_FILENAME = "__connection.json";
|
|
6
6
|
/**
|
|
7
|
+
* Global key holding the serializable connection prepared by
|
|
8
|
+
* `setupDevframeConnection()`. External viewers can use this key to read the
|
|
9
|
+
* connection from another JavaScript realm.
|
|
10
|
+
*/
|
|
11
|
+
const DEVFRAME_CONNECTION_KEY = "__DEVFRAME_CONNECTION__";
|
|
12
|
+
/**
|
|
7
13
|
* Route the WebSocket RPC endpoint is bound to, relative to a devframe's
|
|
8
14
|
* base path. Sits next to `__connection.json` so the deployed SPA can reach
|
|
9
15
|
* it on the same origin it loaded from — the dev server shares one port for
|
|
@@ -62,4 +68,4 @@ function isAnonymousRpcMethod(name) {
|
|
|
62
68
|
return name.startsWith(ANONYMOUS_RPC_PREFIX);
|
|
63
69
|
}
|
|
64
70
|
//#endregion
|
|
65
|
-
export { ANONYMOUS_RPC_PREFIX, DEVFRAME_AUTH_TOKEN_QUERY_PARAM, DEVFRAME_CONNECTION_META_FILENAME, DEVFRAME_DIRNAME, DEVFRAME_DOCK_IMPORTS_FILENAME, DEVFRAME_DOCK_IMPORTS_VIRTUAL_ID, DEVFRAME_MCP_ROUTE, DEVFRAME_MOUNT_PATH, DEVFRAME_MOUNT_PATH_NO_TRAILING_SLASH, DEVFRAME_OTP_URL_PARAM, DEVFRAME_RPC_DUMP_DIRNAME, DEVFRAME_RPC_DUMP_MANIFEST_FILENAME, DEVFRAME_WS_ROUTE, REMOTE_CONNECTION_KEY, isAnonymousRpcMethod };
|
|
71
|
+
export { ANONYMOUS_RPC_PREFIX, DEVFRAME_AUTH_TOKEN_QUERY_PARAM, DEVFRAME_CONNECTION_KEY, DEVFRAME_CONNECTION_META_FILENAME, DEVFRAME_DIRNAME, DEVFRAME_DOCK_IMPORTS_FILENAME, DEVFRAME_DOCK_IMPORTS_VIRTUAL_ID, DEVFRAME_MCP_ROUTE, DEVFRAME_MOUNT_PATH, DEVFRAME_MOUNT_PATH_NO_TRAILING_SLASH, DEVFRAME_OTP_URL_PARAM, DEVFRAME_RPC_DUMP_DIRNAME, DEVFRAME_RPC_DUMP_MANIFEST_FILENAME, DEVFRAME_WS_ROUTE, REMOTE_CONNECTION_KEY, isAnonymousRpcMethod };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as DevframeNodeContext, ht as SharedState } from "./devframe-
|
|
1
|
+
import { b as DevframeNodeContext, ht as SharedState } from "./devframe-Dsjn_Xtq.mjs";
|
|
2
2
|
//#region src/node/hub-internals/context.d.ts
|
|
3
3
|
interface InternalAnonymousAuthStorage {
|
|
4
4
|
trusted: Record<string, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createStorage } from "./storage-
|
|
1
|
+
import { t as createStorage } from "./storage-Dzoc3NVC.mjs";
|
|
2
2
|
import { i as randomToken, n as revokeAuthToken, t as revokeActiveConnectionsForToken } from "./revoke-BtQDKTp7.mjs";
|
|
3
3
|
import { join } from "pathe";
|
|
4
4
|
//#region src/node/hub-internals/context.ts
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { DEVFRAME_CONNECTION_META_FILENAME } from "./constants.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { n as createHostContext, t as createH3DevframeHost } from "./host-h3-Kz7t5Xab.mjs";
|
|
3
|
+
import { t as diagnostics } from "./diagnostics-B5-qHeqD.mjs";
|
|
4
|
+
import { r as registerDevframeInstance } from "./instance-registry-D6fxYu36.mjs";
|
|
5
|
+
import { i as normalizeHttpServerUrl, t as startHttpAndWs } from "./server-CcAPxuoT.mjs";
|
|
5
6
|
import { n as resolveBasePath, t as normalizeBasePath } from "./_shared-bWRzeSa0.mjs";
|
|
6
7
|
import { t as open } from "./open-Deb5xmIT.mjs";
|
|
7
8
|
import { mountStaticHandler } from "./utils/serve-static.mjs";
|
|
@@ -294,7 +295,7 @@ async function createDevServer(def, options = {}) {
|
|
|
294
295
|
const mcpPath = joinURL(basePath, mcpRoute);
|
|
295
296
|
let mountMcpHttp;
|
|
296
297
|
try {
|
|
297
|
-
({mountMcpHttp} = await import("./http-
|
|
298
|
+
({mountMcpHttp} = await import("./http-BghOqfTD.mjs"));
|
|
298
299
|
} catch (error) {
|
|
299
300
|
const reason = error instanceof Error ? error.message : String(error);
|
|
300
301
|
throw diagnostics.DF0017({
|
|
@@ -344,13 +345,23 @@ async function createDevServer(def, options = {}) {
|
|
|
344
345
|
await maybeOpenBrowser(def, flags, `${info.origin}${basePath}`, options.openBrowser, authHandler);
|
|
345
346
|
}
|
|
346
347
|
});
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
started.
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
348
|
+
const registration = registerDevframeInstance({
|
|
349
|
+
pid: process$1.pid,
|
|
350
|
+
port: started.port,
|
|
351
|
+
origin: normalizeHttpServerUrl(host, started.port),
|
|
352
|
+
basePath,
|
|
353
|
+
id: def.id,
|
|
354
|
+
name: def.name,
|
|
355
|
+
rootDir: process$1.cwd(),
|
|
356
|
+
mcp: mcpConfig ? { path: joinURL(basePath, withoutLeadingSlash(mcpConfig.path ?? "__mcp")) } : null,
|
|
357
|
+
startedAt: Date.now()
|
|
358
|
+
});
|
|
359
|
+
const closeServer = started.close;
|
|
360
|
+
started.close = async () => {
|
|
361
|
+
registration.unregister();
|
|
362
|
+
await mcpDispose?.();
|
|
363
|
+
await closeServer();
|
|
364
|
+
};
|
|
354
365
|
return started;
|
|
355
366
|
}
|
|
356
367
|
/**
|