devframe 0.9.11 → 0.9.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/adapters/build.d.mts +4 -5
  2. package/dist/adapters/build.mjs +2 -2
  3. package/dist/adapters/cac.d.mts +4 -4
  4. package/dist/adapters/cac.mjs +1 -1
  5. package/dist/adapters/dev.d.mts +4 -4
  6. package/dist/adapters/dev.mjs +1 -1
  7. package/dist/adapters/embedded.d.mts +3 -4
  8. package/dist/adapters/initiate.d.mts +7 -8
  9. package/dist/adapters/initiate.mjs +1 -1
  10. package/dist/adapters/mcp.d.mts +4 -4
  11. package/dist/adapters/mcp.mjs +9 -15
  12. package/dist/cli/main.d.mts +2 -3
  13. package/dist/client/index.d.mts +133 -35
  14. package/dist/client/index.mjs +231 -57
  15. package/dist/constants.d.mts +20 -21
  16. package/dist/{context-Bq27SDK-.mjs → context-Cdj9z9m2.mjs} +39 -21
  17. package/dist/{dev-B32EVw5w.mjs → dev-SPZzBTrH.mjs} +2 -2
  18. package/dist/in-page-channel/index.d.mts +75 -37
  19. package/dist/in-page-channel/index.mjs +56 -22
  20. package/dist/index.d.mts +4 -4
  21. package/dist/{instance-shell-BWh0JQuo.d.mts → instance-shell-BUyYrKlu.d.mts} +9 -2
  22. package/dist/{instance-shell-DvYCwrDy.mjs → instance-shell-xuu6jg51.mjs} +7 -2
  23. package/dist/internal/index.d.mts +12 -12
  24. package/dist/internal/index.mjs +1 -1
  25. package/dist/node/index.d.mts +5 -5
  26. package/dist/node/index.mjs +1 -1
  27. package/dist/nostics-DD6gsDZA.mjs +108 -0
  28. package/dist/recipes/common-rpc-functions.d.mts +6 -7
  29. package/dist/recipes/interactive-auth.d.mts +36 -11
  30. package/dist/recipes/interactive-auth.mjs +47 -4
  31. package/dist/rpc/client.d.mts +2 -3
  32. package/dist/rpc/dump.d.mts +16 -17
  33. package/dist/rpc/dump.mjs +1 -1
  34. package/dist/rpc/server.d.mts +2 -3
  35. package/dist/rpc/transports/sse-server.d.mts +4 -5
  36. package/dist/rpc/transports/ws-bun.d.mts +5 -6
  37. package/dist/rpc/transports/ws-deno.d.mts +4 -5
  38. package/dist/{shared-state-CaxB1q0h.mjs → shared-state-eQVYHNqA.mjs} +4 -1
  39. package/dist/utils/agent-tool-name.d.mts +2 -3
  40. package/dist/utils/colors.d.mts +4 -5
  41. package/dist/utils/crypto-token.d.mts +4 -5
  42. package/dist/utils/events.d.mts +2 -3
  43. package/dist/utils/hash.d.mts +2 -3
  44. package/dist/utils/launch-editor.d.mts +2 -3
  45. package/dist/utils/nanoid.d.mts +2 -3
  46. package/dist/utils/open.d.mts +2 -3
  47. package/dist/utils/remote-assets.d.mts +2 -3
  48. package/dist/utils/serve-static.d.mts +6 -7
  49. package/dist/utils/shared-state.mjs +1 -1
  50. package/dist/utils/simple-schema.d.mts +17 -18
  51. package/dist/utils/streaming-channel.mjs +4 -1
  52. package/dist/utils/structured-clone.d.mts +5 -6
  53. package/dist/utils/when.d.mts +6 -7
  54. package/dist/{write-BuLCrn9h.mjs → write-D2AJqVT8.mjs} +1 -1
  55. package/package.json +4 -4
@@ -1,12 +1,10 @@
1
- import { t as DEVFRAME_EVENTS } from "../events-BV4Dj59a.mjs";
1
+ import { n as DEVFRAME_EVENTS, t as defineDiagnostics } from "../nostics-DD6gsDZA.mjs";
2
2
  import { t as hash } from "../hash-DdPnc4k3.mjs";
3
- import { colors } from "../utils/colors.mjs";
4
3
  import { createEventEmitter } from "../utils/events.mjs";
5
- import { t as createSharedState } from "../shared-state-CaxB1q0h.mjs";
4
+ import { t as createSharedState } from "../shared-state-eQVYHNqA.mjs";
6
5
  import { i as structuredCloneStringify, n as structuredCloneParse, t as structuredCloneDeserialize } from "../structured-clone-CgtQ61SA.mjs";
7
6
  import { createStreamReader, createStreamSink } from "../utils/streaming-channel.mjs";
8
- import { defineDiagnostics } from "nostics";
9
- import { ansiFormatter } from "nostics/formatters/ansi";
7
+ import { toAgentToolName } from "../utils/agent-tool-name.mjs";
10
8
  import { withBase, withProtocol } from "ufo";
11
9
  import { createBirpc } from "birpc";
12
10
  //#region src/constants.ts
@@ -96,34 +94,8 @@ var RpcCacheManager = class {
96
94
  }
97
95
  };
98
96
  //#endregion
99
- //#region src/utils/nostics.ts
100
- const formatAnsi = ansiFormatter(colors);
101
- /**
102
- * The reporter every {@link defineDiagnostics} call below wires in ahead of
103
- * any caller-supplied ones: prints the diagnostic through devframe's own
104
- * ANSI colors via `console[method]` (default `'warn'`).
105
- */
106
- function devframeReporter(d, { method = "warn" } = {}) {
107
- console[method](formatAnsi(d));
108
- }
109
- /**
110
- * Drop-in replacement for `nostics`'s `defineDiagnostics()` with devframe's
111
- * ANSI console reporter pre-wired ahead of any `reporters` passed in. Every
112
- * `diagnostics.ts` in devframe core, `@devframes/hub`, `@devframes/json-render`,
113
- * and the built-in plugins defines its codes through this instead of
114
- * `nostics`'s own `defineDiagnostics`; the reporter registration lives
115
- * here, once, so none of them need to build their own reporter (`colors`,
116
- * `ansiFormatter`) or take a direct dependency on `nostics` themselves.
117
- */
118
- function defineDiagnostics$1(options) {
119
- return defineDiagnostics({
120
- ...options,
121
- reporters: [devframeReporter, ...options.reporters ?? []]
122
- });
123
- }
124
- //#endregion
125
97
  //#region src/rpc/diagnostics.ts
126
- const diagnostics = defineDiagnostics$1({
98
+ const diagnostics = defineDiagnostics({
127
99
  docsBase: "https://devfra.me/errors",
128
100
  codes: {
129
101
  DF0019: {
@@ -968,20 +940,6 @@ function createRpcClient(functions, options) {
968
940
  });
969
941
  }
970
942
  //#endregion
971
- //#region src/utils/promise.ts
972
- function promiseWithResolver() {
973
- let resolve;
974
- let reject;
975
- return {
976
- promise: new Promise((_resolve, _reject) => {
977
- resolve = _resolve;
978
- reject = _reject;
979
- }),
980
- resolve,
981
- reject
982
- };
983
- }
984
- //#endregion
985
943
  //#region src/client/rpc-live.ts
986
944
  /**
987
945
  * The transport-independent half of a live RPC client mode (connection
@@ -993,7 +951,7 @@ function createLiveRpcClientMode(options) {
993
951
  let isTrusted = false;
994
952
  let status = "connecting";
995
953
  let connectionError = null;
996
- const trustedPromise = promiseWithResolver();
954
+ const trustedPromise = Promise.withResolvers();
997
955
  function setStatus(next, error = null) {
998
956
  if (error) connectionError = error;
999
957
  else if (next === "connected") connectionError = null;
@@ -1604,14 +1562,14 @@ function qualifyName(namespace, name) {
1604
1562
  return isQualifiedName(name) ? name : `${namespace}:${name}`;
1605
1563
  }
1606
1564
  //#endregion
1607
- //#region src/client/settings.ts
1608
- function createClientSettingsStore(rpc, namespace, scope) {
1609
- const stateKey = `devframe:settings:${scope}:${namespace}`;
1610
- let statePromise;
1611
- function store() {
1612
- if (!statePromise) statePromise = rpc.sharedState.get(stateKey, { initialValue: {} });
1613
- return statePromise;
1614
- }
1565
+ //#region src/settings-store.ts
1566
+ /**
1567
+ * The key-value store surface over a lazily-resolved shared state, shared by
1568
+ * the node-side (file-backed) and client-side (RPC-mirrored) settings stores.
1569
+ * Each side supplies its own `store()` resolver; the read/write/subscribe
1570
+ * behavior on top of it is identical.
1571
+ */
1572
+ function createSettingsStore(store) {
1615
1573
  return {
1616
1574
  async get(key) {
1617
1575
  return (await store()).value()[key];
@@ -1634,6 +1592,17 @@ function createClientSettingsStore(rpc, namespace, scope) {
1634
1592
  }
1635
1593
  };
1636
1594
  }
1595
+ //#endregion
1596
+ //#region src/client/settings.ts
1597
+ function createClientSettingsStore(rpc, namespace, scope) {
1598
+ const stateKey = `devframe:settings:${scope}:${namespace}`;
1599
+ let statePromise;
1600
+ function store() {
1601
+ if (!statePromise) statePromise = rpc.sharedState.get(stateKey, { initialValue: {} });
1602
+ return statePromise;
1603
+ }
1604
+ return createSettingsStore(store);
1605
+ }
1637
1606
  /**
1638
1607
  * Build the client-side `settings` surface for a scope namespace. Mirrors
1639
1608
  * the node-side stores over the shared-state sync protocol.
@@ -1678,6 +1647,207 @@ function createScopedClientContext(rpc, namespace) {
1678
1647
  };
1679
1648
  }
1680
1649
  //#endregion
1650
+ //#region src/adapters/mcp/to-json-schema.ts
1651
+ const FALLBACK_OBJECT_SCHEMA = Object.freeze({
1652
+ type: "object",
1653
+ additionalProperties: true
1654
+ });
1655
+ /**
1656
+ * Convert a Standard Schema to JSON Schema for the agent/MCP surface.
1657
+ *
1658
+ * Devframe stays validator-neutral, so conversion uses the schema's own
1659
+ * [Standard JSON Schema](https://standardschema.dev/) converter
1660
+ * (`~standard.jsonSchema`) when the validator provides one; zod 4 does,
1661
+ * for example. Validators without a native converter (e.g. valibot) degrade
1662
+ * to a permissive object schema rather than pulling in a converter library.
1663
+ */
1664
+ function safeToJsonSchema(schema) {
1665
+ const standard = schema["~standard"];
1666
+ if (standard.jsonSchema) try {
1667
+ return standard.jsonSchema.input({ target: "draft-2020-12" });
1668
+ } catch {
1669
+ return FALLBACK_OBJECT_SCHEMA;
1670
+ }
1671
+ return FALLBACK_OBJECT_SCHEMA;
1672
+ }
1673
+ /**
1674
+ * JSON Schema for an RPC function's positional args on the agent/MCP
1675
+ * surface. Each positional arg is advertised under `arg0` / `arg1` / …,
1676
+ * matching how the agent bridge coerces the incoming object payload back
1677
+ * into positional arguments.
1678
+ *
1679
+ * Returns `{ type: 'object', properties: {} }` when there are no args.
1680
+ * @internal
1681
+ */
1682
+ function argsToJsonSchema(args) {
1683
+ if (!args || args.length === 0) return {
1684
+ type: "object",
1685
+ properties: {}
1686
+ };
1687
+ const properties = {};
1688
+ const required = [];
1689
+ for (let i = 0; i < args.length; i++) {
1690
+ const key = `arg${i}`;
1691
+ properties[key] = safeToJsonSchema(args[i]);
1692
+ required.push(key);
1693
+ }
1694
+ return {
1695
+ type: "object",
1696
+ properties,
1697
+ required,
1698
+ additionalProperties: false
1699
+ };
1700
+ }
1701
+ //#endregion
1702
+ //#region src/node/agent-args.ts
1703
+ /**
1704
+ * Map the args payload an agent surface receives (MCP sends an object
1705
+ * keyed `arg0`/`arg1`/…, matching the schema the adapter advertises) onto
1706
+ * a handler's positional parameters. Shared by the agent host's RPC
1707
+ * bridge and the hub's command-derived tools so the coercion cannot
1708
+ * drift between them.
1709
+ *
1710
+ * - an array passes through as-is
1711
+ * - `null`/`undefined` become a zero-argument call
1712
+ * - with declared schemas, each schema reads its own `argN` key, in order
1713
+ * - without schemas, `arg0`/`arg1`/… keys are collected when present
1714
+ * - an empty object becomes a zero-argument call
1715
+ * - anything else follows the {@link AgentArgsFallback}
1716
+ */
1717
+ function coerceAgentPositionalArgs(args, schemas, fallback = "wrap") {
1718
+ if (Array.isArray(args)) return args;
1719
+ if (args === void 0 || args === null) return [];
1720
+ if (typeof args === "object") {
1721
+ const obj = args;
1722
+ if (schemas && schemas.length) return schemas.map((_, i) => obj[`arg${i}`]);
1723
+ if ("arg0" in obj) {
1724
+ const out = [];
1725
+ let i = 0;
1726
+ while (`arg${i}` in obj) {
1727
+ out.push(obj[`arg${i}`]);
1728
+ i++;
1729
+ }
1730
+ return out;
1731
+ }
1732
+ if (Object.keys(obj).length === 0) return [];
1733
+ }
1734
+ return fallback === "drop" ? [] : [args];
1735
+ }
1736
+ //#endregion
1737
+ //#region src/client/webmcp.ts
1738
+ /**
1739
+ * The page's WebMCP model context, when the browser (or a polyfill)
1740
+ * provides one. Checks `document.modelContext` (current draft) first,
1741
+ * then `navigator.modelContext` (earlier drafts and polyfills).
1742
+ */
1743
+ function resolveWebMcpModelContext() {
1744
+ if (typeof document !== "undefined") {
1745
+ const context = document.modelContext;
1746
+ if (context) return context;
1747
+ }
1748
+ if (typeof navigator !== "undefined") {
1749
+ const context = navigator.modelContext;
1750
+ if (context) return context;
1751
+ }
1752
+ }
1753
+ /**
1754
+ * Mirror the `agent`-flagged RPC functions of a browser-side collector
1755
+ * (`rpc.client`) onto the page's WebMCP model context as callable tools,
1756
+ * using the same `agent` signature, wire names, and `arg0`/`arg1`/… input
1757
+ * schema as the node-side MCP adapter. Functions without an `agent` field
1758
+ * stay unexposed (default-deny), and the tool set follows later
1759
+ * `register`/`update` calls. Returns a dispose that unregisters every tool.
1760
+ */
1761
+ function registerWebMcpTools(clientRpc, options = {}) {
1762
+ const resolved = options.modelContext ?? resolveWebMcpModelContext();
1763
+ if (!resolved) return () => {};
1764
+ const modelContext = resolved;
1765
+ /** Unregister callbacks keyed by definition name. */
1766
+ const registered = /* @__PURE__ */ new Map();
1767
+ /** Wire name → definition name, to detect sanitization collisions. */
1768
+ const wireNames = /* @__PURE__ */ new Map();
1769
+ function register(def, agent) {
1770
+ const name = toAgentToolName(def.name);
1771
+ const owner = wireNames.get(name);
1772
+ if (owner && owner !== def.name) {
1773
+ console.warn(`[devframe] WebMCP tool name "${name}" (from "${def.name}") collides with "${owner}"; keeping the first registration.`);
1774
+ return;
1775
+ }
1776
+ const controller = new AbortController();
1777
+ const result = modelContext.registerTool({
1778
+ name,
1779
+ description: agent.description,
1780
+ inputSchema: argsToJsonSchema(def.args),
1781
+ annotations: {
1782
+ title: agent.title ?? def.name,
1783
+ readOnlyHint: resolveSafety(def, agent) === "read",
1784
+ destructiveHint: resolveSafety(def, agent) === "destructive"
1785
+ },
1786
+ execute: (args) => executeRpcTool(def, clientRpc.context, args)
1787
+ }, { signal: controller.signal });
1788
+ if (result && "then" in result) result.then(() => {}, () => {});
1789
+ wireNames.set(name, def.name);
1790
+ registered.set(def.name, () => {
1791
+ controller.abort();
1792
+ if (result && "unregister" in result && typeof result.unregister === "function") result.unregister();
1793
+ wireNames.delete(name);
1794
+ });
1795
+ }
1796
+ function sync(id) {
1797
+ const names = id ? [id] : [...clientRpc.definitions.keys()];
1798
+ for (const name of names) {
1799
+ registered.get(name)?.();
1800
+ registered.delete(name);
1801
+ const def = clientRpc.definitions.get(name);
1802
+ const agent = def?.agent;
1803
+ if (def && agent) register(def, agent);
1804
+ }
1805
+ }
1806
+ sync();
1807
+ const unsubscribe = clientRpc.onChanged((id) => sync(id));
1808
+ return () => {
1809
+ unsubscribe();
1810
+ for (const unregister of registered.values()) unregister();
1811
+ registered.clear();
1812
+ };
1813
+ }
1814
+ function resolveSafety(def, agent) {
1815
+ if (agent.safety) return agent.safety;
1816
+ const type = def.type ?? "query";
1817
+ return type === "static" || type === "query" ? "read" : "action";
1818
+ }
1819
+ async function executeRpcTool(def, context, args) {
1820
+ try {
1821
+ const positional = coerceAgentPositionalArgs(args, def.args, "wrap");
1822
+ return { content: [{
1823
+ type: "text",
1824
+ text: stringifyResult(await (await getRpcHandler(def, context))(...positional))
1825
+ }] };
1826
+ } catch (error) {
1827
+ return {
1828
+ isError: true,
1829
+ content: [{
1830
+ type: "text",
1831
+ text: formatError(error)
1832
+ }]
1833
+ };
1834
+ }
1835
+ }
1836
+ /**
1837
+ * Agent-exposed functions are strict-JSON by contract (`jsonSerializable:
1838
+ * true` is enforced at registration), so plain `JSON.stringify` suffices.
1839
+ */
1840
+ function stringifyResult(value) {
1841
+ if (value === void 0) return "undefined";
1842
+ if (typeof value === "string") return value;
1843
+ return JSON.stringify(value, null, 2);
1844
+ }
1845
+ function formatError(error) {
1846
+ if (!(error instanceof Error)) return String(error);
1847
+ const cause = error.cause instanceof Error ? ` (cause: ${error.cause.message})` : "";
1848
+ return `${error.name}: ${error.message}${cause}`;
1849
+ }
1850
+ //#endregion
1681
1851
  //#region src/client/rpc.ts
1682
1852
  /**
1683
1853
  * Resolve the requested `transport` option against what the server
@@ -1719,6 +1889,7 @@ async function getDevframeRpcClient(options = {}) {
1719
1889
  });
1720
1890
  const context = { rpc: void 0 };
1721
1891
  const clientRpc = new RpcFunctionsCollectorBase(context);
1892
+ const disposeWebMcp = options.webmcp === false ? void 0 : registerWebMcpTools(clientRpc);
1722
1893
  async function fetchJsonFromBases(path) {
1723
1894
  const candidates = [resolvedBaseURL, ...bases.filter((base) => base !== resolvedBaseURL)].filter((x) => x != null);
1724
1895
  const errors = [];
@@ -1824,7 +1995,10 @@ async function getDevframeRpcClient(options = {}) {
1824
1995
  streaming: void 0,
1825
1996
  cacheManager,
1826
1997
  scope: void 0,
1827
- close: () => mode.close?.()
1998
+ close: () => {
1999
+ disposeWebMcp?.();
2000
+ mode.close?.();
2001
+ }
1828
2002
  };
1829
2003
  rpc.sharedState = createRpcSharedStateClientHost(rpc);
1830
2004
  rpc.streaming = createRpcStreamingClientHost(rpc);
@@ -1879,4 +2053,4 @@ async function getDevframeRpcClient(options = {}) {
1879
2053
  //#region src/client/index.ts
1880
2054
  const connectDevframe = getDevframeRpcClient;
1881
2055
  //#endregion
1882
- export { DevframeConnectionError, authenticateWithUrlOtp, connectDevframe, consumeOtpFromUrl, createClientSettings, createRpcStreamingClientHost, createScopedClientContext, getDevframeConnection, getDevframeRpcClient, isCallableStatus, readOtpFromUrl, registerDevframeViewerOrigin, resolveClientTransport, resolveSseUrl, resolveWsUrl, setupDevframeConnection };
2056
+ export { DevframeConnectionError, authenticateWithUrlOtp, connectDevframe, consumeOtpFromUrl, createClientSettings, createRpcStreamingClientHost, createScopedClientContext, getDevframeConnection, getDevframeRpcClient, isCallableStatus, readOtpFromUrl, registerDevframeViewerOrigin, registerWebMcpTools, resolveClientTransport, resolveSseUrl, resolveWebMcpModelContext, resolveWsUrl, setupDevframeConnection };
@@ -22,7 +22,7 @@
22
22
  * keys (a literal is unavoidable in a type position); those declarations mirror
23
23
  * this map and move with it.
24
24
  */
25
- declare const DEVFRAME_EVENTS: {
25
+ export declare const DEVFRAME_EVENTS: {
26
26
  /**
27
27
  * Node-side host `EventEmitter` events. The agent host (`ctx.agent.events`)
28
28
  * emits these as its tool/resource surface changes; protocol adapters (e.g.
@@ -78,13 +78,13 @@ declare const DEVFRAME_EVENTS: {
78
78
  //#endregion
79
79
  //#region src/constants.d.ts
80
80
  /** Devframe runtime routes and static output conventions. */
81
- declare const DEVFRAME_CONNECTION_META_FILENAME = "__connection.json";
81
+ export declare const DEVFRAME_CONNECTION_META_FILENAME = "__connection.json";
82
82
  /**
83
83
  * Global key holding the serializable connection prepared by
84
84
  * `setupDevframeConnection()`. External viewers can use this key to read the
85
85
  * connection from another JavaScript realm.
86
86
  */
87
- declare const DEVFRAME_CONNECTION_KEY = "__DEVFRAME_CONNECTION__";
87
+ export declare const DEVFRAME_CONNECTION_KEY = "__DEVFRAME_CONNECTION__";
88
88
  /**
89
89
  * Route the WebSocket RPC endpoint is bound to, relative to a devframe's
90
90
  * base path. Sits next to `__connection.json` so the deployed SPA can reach
@@ -92,7 +92,7 @@ declare const DEVFRAME_CONNECTION_KEY = "__DEVFRAME_CONNECTION__";
92
92
  * both HTTP and WS, and a host server (Vite, etc.) can mount the WS upgrade
93
93
  * handler here without colliding with its own routes (HMR, asset serving).
94
94
  */
95
- declare const DEVFRAME_WS_ROUTE = "__ws";
95
+ export declare const DEVFRAME_WS_ROUTE = "__ws";
96
96
  /**
97
97
  * Route the SSE RPC endpoint is bound to, relative to a devframe's base
98
98
  * path. A single method-dispatched route: `GET` opens the event stream
@@ -101,36 +101,36 @@ declare const DEVFRAME_WS_ROUTE = "__ws";
101
101
  * loaded from; the transport for hosts and proxies where the WebSocket
102
102
  * upgrade isn't available.
103
103
  */
104
- declare const DEVFRAME_SSE_ROUTE = "__sse";
104
+ export declare const DEVFRAME_SSE_ROUTE = "__sse";
105
105
  /**
106
106
  * Request header carrying the SSE session id on every RPC `POST`. The
107
107
  * server mints the id as the stream's first event (`event: session`);
108
108
  * the client echoes it here so the POST joins that stream's birpc
109
109
  * channel. Mirrors birpc's own SSE helpers for wire compatibility.
110
110
  */
111
- declare const DEVFRAME_SSE_SESSION_HEADER = "x-birpc-session";
111
+ export declare const DEVFRAME_SSE_SESSION_HEADER = "x-birpc-session";
112
112
  /**
113
113
  * Route the Streamable-HTTP MCP endpoint is bound to, relative to a
114
114
  * devframe's base path. Sits next to `__connection.json` and the WS route
115
115
  * so an MCP client reaches it on the same origin the SPA loaded from; the
116
116
  * dev server shares one port for HTTP, WS, and MCP. Opt-in via `cli.mcp`.
117
117
  */
118
- declare const DEVFRAME_MCP_ROUTE = "__mcp";
119
- declare const DEVFRAME_RPC_DUMP_MANIFEST_FILENAME = "__rpc-dump/index.json";
120
- declare const DEVFRAME_DOCK_IMPORTS_FILENAME = "__client-imports.js";
121
- declare const DEVFRAME_RPC_DUMP_DIRNAME = "__rpc-dump";
118
+ export declare const DEVFRAME_MCP_ROUTE = "__mcp";
119
+ export declare const DEVFRAME_RPC_DUMP_MANIFEST_FILENAME = "__rpc-dump/index.json";
120
+ export declare const DEVFRAME_DOCK_IMPORTS_FILENAME = "__client-imports.js";
121
+ export declare const DEVFRAME_RPC_DUMP_DIRNAME = "__rpc-dump";
122
122
  /**
123
123
  * Shared-state key carrying the wire-service advertisements (package name →
124
124
  * `DevframeServiceMeta`). Written by the node services host; mirrored to
125
125
  * clients for feature-detection via `client.services`.
126
126
  */
127
- declare const DEVFRAME_SERVICES_STATE_KEY = "devframe:services";
127
+ export declare const DEVFRAME_SERVICES_STATE_KEY = "devframe:services";
128
128
  /**
129
129
  * URL fragment / query parameter name carrying the remote dock
130
130
  * connection descriptor (defined as `RemoteConnectionInfo` in
131
131
  * `@vitejs/devtools-kit`) injected into remote-UI iframe dock URLs.
132
132
  */
133
- declare const REMOTE_CONNECTION_KEY = "devframe-remote-connection";
133
+ export declare const REMOTE_CONNECTION_KEY = "devframe-remote-connection";
134
134
  /**
135
135
  * Page-URL **fragment** parameter carrying a one-time authentication code (OTP)
136
136
  * for "magic link" auth. A host can print a link like
@@ -141,7 +141,7 @@ declare const REMOTE_CONNECTION_KEY = "devframe-remote-connection";
141
141
  * (node) and the `authenticateWithUrlOtp` / `consumeOtpFromUrl` client utilities
142
142
  * (or `connectDevframe`'s `otpParam`).
143
143
  */
144
- declare const DEVFRAME_OTP_URL_PARAM = "devframe_otp";
144
+ export declare const DEVFRAME_OTP_URL_PARAM = "devframe_otp";
145
145
  /**
146
146
  * WS upgrade-URL query parameter carrying a previously-issued bearer token.
147
147
  * Set by `createWsRpcChannel` (browser transport) whenever `authToken` is
@@ -149,11 +149,11 @@ declare const DEVFRAME_OTP_URL_PARAM = "devframe_otp";
149
149
  * `recipes/interactive-auth`'s `onConnect`) so a returning client can be
150
150
  * trusted before its own `anonymous:devframe:auth` handshake call arrives.
151
151
  */
152
- declare const DEVFRAME_AUTH_TOKEN_QUERY_PARAM = "devframe_auth_token";
152
+ export declare const DEVFRAME_AUTH_TOKEN_QUERY_PARAM = "devframe_auth_token";
153
153
  /** External viewer origin requested during connection bootstrap. */
154
- declare const DEVFRAME_VIEWER_ORIGIN_QUERY_PARAM = "devframe_viewer_origin";
154
+ export declare const DEVFRAME_VIEWER_ORIGIN_QUERY_PARAM = "devframe_viewer_origin";
155
155
  /** Token that authorizes an external viewer origin registration. */
156
- declare const DEVFRAME_VIEWER_ORIGIN_TOKEN_QUERY_PARAM = "devframe_viewer_origin_token";
156
+ export declare const DEVFRAME_VIEWER_ORIGIN_TOKEN_QUERY_PARAM = "devframe_viewer_origin_token";
157
157
  /**
158
158
  * `postMessage` type the remote-assets fallback page posts to `window.parent`
159
159
  * on load. That page is what a devframe serves (with a 502) when its client
@@ -162,7 +162,7 @@ declare const DEVFRAME_VIEWER_ORIGIN_TOKEN_QUERY_PARAM = "devframe_viewer_origin
162
162
  * (`@devframes/hub-ui` does, in its iframe view). Payload shape:
163
163
  * `RemoteAssetsErrorMessage` (`devframe/types`).
164
164
  */
165
- declare const DEVFRAME_REMOTE_ASSETS_ERROR_MESSAGE_TYPE: string;
165
+ export declare const DEVFRAME_REMOTE_ASSETS_ERROR_MESSAGE_TYPE: string;
166
166
  /**
167
167
  * Prefix that marks an RPC method as callable before a connection is
168
168
  * trusted. This is the *only* rule the pre-trust gate applies; there is no
@@ -170,13 +170,12 @@ declare const DEVFRAME_REMOTE_ASSETS_ERROR_MESSAGE_TYPE: string;
170
170
  * before authentication must be named `anonymous:<rest>` (e.g.
171
171
  * `anonymous:devframe:auth`).
172
172
  */
173
- declare const ANONYMOUS_RPC_PREFIX = "anonymous:";
173
+ export declare const ANONYMOUS_RPC_PREFIX = "anonymous:";
174
174
  /**
175
175
  * Whether `name` is callable before a connection is trusted, i.e. it starts
176
176
  * with {@link ANONYMOUS_RPC_PREFIX}. Used by the resolver gate in
177
177
  * the RPC server binding (via an `authorize` function) and by host adapters that
178
178
  * implement their own transport.
179
179
  */
180
- declare function isAnonymousRpcMethod(name: string): boolean;
181
- //#endregion
182
- export { ANONYMOUS_RPC_PREFIX, DEVFRAME_AUTH_TOKEN_QUERY_PARAM, DEVFRAME_CONNECTION_KEY, DEVFRAME_CONNECTION_META_FILENAME, DEVFRAME_DOCK_IMPORTS_FILENAME, DEVFRAME_EVENTS, DEVFRAME_MCP_ROUTE, DEVFRAME_OTP_URL_PARAM, DEVFRAME_REMOTE_ASSETS_ERROR_MESSAGE_TYPE, DEVFRAME_RPC_DUMP_DIRNAME, DEVFRAME_RPC_DUMP_MANIFEST_FILENAME, DEVFRAME_SERVICES_STATE_KEY, DEVFRAME_SSE_ROUTE, DEVFRAME_SSE_SESSION_HEADER, DEVFRAME_VIEWER_ORIGIN_QUERY_PARAM, DEVFRAME_VIEWER_ORIGIN_TOKEN_QUERY_PARAM, DEVFRAME_WS_ROUTE, REMOTE_CONNECTION_KEY, isAnonymousRpcMethod };
180
+ export declare function isAnonymousRpcMethod(name: string): boolean;
181
+ //#endregion
@@ -143,7 +143,11 @@ function createRpcSharedStateServerHost(rpc) {
143
143
  name: "devframe:rpc:server-state:set",
144
144
  type: "query",
145
145
  handler: async (key, value, syncId) => {
146
- (await host.get(key, { initialValue: value })).mutate(() => value, syncId);
146
+ (await host.get(key, { initialValue: value })).patch([{
147
+ op: "replace",
148
+ path: [],
149
+ value
150
+ }], syncId);
147
151
  }
148
152
  });
149
153
  rpc.register({
@@ -192,7 +196,10 @@ function createStreamSink(options = {}) {
192
196
  seq: lastSeq,
193
197
  chunk
194
198
  });
195
- if (buffer.length > replayWindow) buffer.splice(0, buffer.length - replayWindow);
199
+ if (buffer.length > replayWindow) {
200
+ if (buffer.length - replayWindow === 1) buffer.shift();
201
+ else buffer.splice(0, buffer.length - replayWindow);
202
+ }
196
203
  }
197
204
  events.emit("chunk", lastSeq, chunk);
198
205
  }
@@ -1134,25 +1141,14 @@ function qualifyName(namespace, name) {
1134
1141
  return isQualifiedName(name) ? name : `${namespace}:${name}`;
1135
1142
  }
1136
1143
  //#endregion
1137
- //#region src/node/settings.ts
1138
- const STORAGE_SCOPE = {
1139
- global: "global",
1140
- project: "project"
1141
- };
1142
- function createNodeSettingsStore(context, namespace, scope) {
1143
- const stateKey = `devframe:settings:${scope}:${namespace}`;
1144
- let statePromise;
1145
- function store() {
1146
- if (!statePromise) {
1147
- const dir = context.host.getStorageDir(STORAGE_SCOPE[scope]);
1148
- const filepath = join(dir, "settings", `${namespace}.json`);
1149
- statePromise = context.rpc.sharedState.get(stateKey, { sharedState: createStorage({
1150
- filepath,
1151
- initialValue: {}
1152
- }) });
1153
- }
1154
- return statePromise;
1155
- }
1144
+ //#region src/settings-store.ts
1145
+ /**
1146
+ * The key-value store surface over a lazily-resolved shared state, shared by
1147
+ * the node-side (file-backed) and client-side (RPC-mirrored) settings stores.
1148
+ * Each side supplies its own `store()` resolver; the read/write/subscribe
1149
+ * behavior on top of it is identical.
1150
+ */
1151
+ function createSettingsStore(store) {
1156
1152
  return {
1157
1153
  async get(key) {
1158
1154
  return (await store()).value()[key];
@@ -1175,6 +1171,28 @@ function createNodeSettingsStore(context, namespace, scope) {
1175
1171
  }
1176
1172
  };
1177
1173
  }
1174
+ //#endregion
1175
+ //#region src/node/settings.ts
1176
+ const STORAGE_SCOPE = {
1177
+ global: "global",
1178
+ project: "project"
1179
+ };
1180
+ function createNodeSettingsStore(context, namespace, scope) {
1181
+ const stateKey = `devframe:settings:${scope}:${namespace}`;
1182
+ let statePromise;
1183
+ function store() {
1184
+ if (!statePromise) {
1185
+ const dir = context.host.getStorageDir(STORAGE_SCOPE[scope]);
1186
+ const filepath = join(dir, "settings", `${namespace}.json`);
1187
+ statePromise = context.rpc.sharedState.get(stateKey, { sharedState: createStorage({
1188
+ filepath,
1189
+ initialValue: {}
1190
+ }) });
1191
+ }
1192
+ return statePromise;
1193
+ }
1194
+ return createSettingsStore(store);
1195
+ }
1178
1196
  /**
1179
1197
  * Build the node-side `settings` surface for a scope namespace. `project`
1180
1198
  * persists under the host's `workspace` storage dir, `global` under its
@@ -1,11 +1,11 @@
1
1
  import { t as resolveClientAssets } from "./client-assets-DNdhagGm.mjs";
2
2
  import { DEVFRAME_CONNECTION_META_FILENAME } from "./constants.mjs";
3
3
  import { t as diagnostics } from "./diagnostics-DZA6KQ_Z.mjs";
4
- import { t as createHostContext } from "./context-Bq27SDK-.mjs";
4
+ import { t as createHostContext } from "./context-Cdj9z9m2.mjs";
5
5
  import { t as resolveStaticAssetsSource } from "./remote-assets-DMFzLSoH.mjs";
6
6
  import { a as resolveMcpConfig, i as resolveDevServerPort, n as normalizeBasePath, r as resolveBasePath, s as importRuntimeModule, t as loadAutoMcpAdapter } from "./_shared-U8D-xzrp.mjs";
7
7
  import { t as createH3DevframeHost } from "./host-h3-BROI6SQ4.mjs";
8
- import { i as normalizeHttpServerUrl, n as resolveInstanceRegister, t as createInstanceShell } from "./instance-shell-DvYCwrDy.mjs";
8
+ import { i as normalizeHttpServerUrl, n as resolveInstanceRegister, t as createInstanceShell } from "./instance-shell-xuu6jg51.mjs";
9
9
  import { open } from "./utils/open.mjs";
10
10
  import { mountStaticHandler } from "./utils/serve-static.mjs";
11
11
  import { resolve } from "pathe";