@valbuild/mcp 0.150.23 → 0.152.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -0
- package/dist/declarations/src/tools/createValTools.d.ts +6 -6
- package/dist/valbuild-mcp.cjs.dev.js +112 -128
- package/dist/valbuild-mcp.cjs.prod.js +112 -128
- package/dist/valbuild-mcp.esm.js +112 -128
- package/package.json +4 -4
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var asyncToGenerator = require('./asyncToGenerator-8e5c36c8.cjs.prod.js');
|
|
6
6
|
var zod = require('zod');
|
|
7
|
-
var
|
|
7
|
+
var internal$1 = require('@valbuild/server/internal');
|
|
8
8
|
var core = require('@valbuild/core');
|
|
9
9
|
var internal = require('@valbuild/shared/internal');
|
|
10
10
|
var minimatch = require('minimatch');
|
|
@@ -13,6 +13,7 @@ var patch = require('@valbuild/core/patch');
|
|
|
13
13
|
var fp = require('@valbuild/core/fp');
|
|
14
14
|
var fs = require('node:fs/promises');
|
|
15
15
|
var path = require('node:path');
|
|
16
|
+
var server = require('@valbuild/server');
|
|
16
17
|
|
|
17
18
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
18
19
|
|
|
@@ -1439,7 +1440,7 @@ function _savePatch() {
|
|
|
1439
1440
|
attempt = 0;
|
|
1440
1441
|
case 10:
|
|
1441
1442
|
if (!(attempt < 2)) {
|
|
1442
|
-
_context4.n =
|
|
1443
|
+
_context4.n = 20;
|
|
1443
1444
|
break;
|
|
1444
1445
|
}
|
|
1445
1446
|
if (!(attempt > 0)) {
|
|
@@ -1480,7 +1481,7 @@ function _savePatch() {
|
|
|
1480
1481
|
_context4.n = 16;
|
|
1481
1482
|
break;
|
|
1482
1483
|
}
|
|
1483
|
-
return _context4.a(3,
|
|
1484
|
+
return _context4.a(3, 19);
|
|
1484
1485
|
case 16:
|
|
1485
1486
|
if (!(saved.error.errorType === "plan-refused")) {
|
|
1486
1487
|
_context4.n = 17;
|
|
@@ -1492,6 +1493,16 @@ function _savePatch() {
|
|
|
1492
1493
|
message: saved.error.error.message
|
|
1493
1494
|
});
|
|
1494
1495
|
case 17:
|
|
1496
|
+
if (!(saved.error.errorType === "service-error")) {
|
|
1497
|
+
_context4.n = 18;
|
|
1498
|
+
break;
|
|
1499
|
+
}
|
|
1500
|
+
return _context4.a(2, {
|
|
1501
|
+
status: "error",
|
|
1502
|
+
code: "internal",
|
|
1503
|
+
message: "".concat(saved.error.message, " (").concat(saved.error.details, ")")
|
|
1504
|
+
});
|
|
1505
|
+
case 18:
|
|
1495
1506
|
return _context4.a(2, {
|
|
1496
1507
|
status: "error",
|
|
1497
1508
|
code: "internal",
|
|
@@ -1499,11 +1510,11 @@ function _savePatch() {
|
|
|
1499
1510
|
// `{ errorType: "other", error: <that> }`.
|
|
1500
1511
|
message: saved.error.error.message
|
|
1501
1512
|
});
|
|
1502
|
-
case
|
|
1513
|
+
case 19:
|
|
1503
1514
|
attempt++;
|
|
1504
1515
|
_context4.n = 10;
|
|
1505
1516
|
break;
|
|
1506
|
-
case
|
|
1517
|
+
case 20:
|
|
1507
1518
|
return _context4.a(2, {
|
|
1508
1519
|
status: "error",
|
|
1509
1520
|
code: "conflict",
|
|
@@ -1865,7 +1876,13 @@ var _excluded = ["handler"],
|
|
|
1865
1876
|
*/
|
|
1866
1877
|
function createValTools(valModules, options) {
|
|
1867
1878
|
var extraTools = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
1868
|
-
|
|
1879
|
+
/*
|
|
1880
|
+
* The runtime every reader in this process shares (`valRuntime`): the API's,
|
|
1881
|
+
* the draft readers' and this registry's, so a write through any of them
|
|
1882
|
+
* is read by all, and the content is the head's -- made once per version,
|
|
1883
|
+
* not rebuilt per call.
|
|
1884
|
+
*/
|
|
1885
|
+
var ops = internal$1.valRuntime(valModules, options).ops;
|
|
1869
1886
|
var tools = [].concat(_toConsumableArray(readTools()), _toConsumableArray(writeTools()), _toConsumableArray(extraTools));
|
|
1870
1887
|
var byName = new Map();
|
|
1871
1888
|
var _iterator = _createForOfIteratorHelper(tools),
|
|
@@ -1912,7 +1929,7 @@ function createValTools(valModules, options) {
|
|
|
1912
1929
|
},
|
|
1913
1930
|
call: function call(name, args, ctx) {
|
|
1914
1931
|
return asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee() {
|
|
1915
|
-
var tool, parsed, insufficient,
|
|
1932
|
+
var tool, parsed, insufficient, refused, state, deps, _t;
|
|
1916
1933
|
return asyncToGenerator._regenerator().w(function (_context) {
|
|
1917
1934
|
while (1) switch (_context.p = _context.n) {
|
|
1918
1935
|
case 0:
|
|
@@ -1947,37 +1964,36 @@ function createValTools(valModules, options) {
|
|
|
1947
1964
|
}
|
|
1948
1965
|
return _context.a(2, insufficient);
|
|
1949
1966
|
case 3:
|
|
1950
|
-
|
|
1951
|
-
if (!(
|
|
1967
|
+
refused = refuseCaller(ctx, options);
|
|
1968
|
+
if (!(refused !== null)) {
|
|
1952
1969
|
_context.n = 4;
|
|
1953
1970
|
break;
|
|
1954
1971
|
}
|
|
1955
|
-
return _context.a(2,
|
|
1972
|
+
return _context.a(2, refused);
|
|
1956
1973
|
case 4:
|
|
1957
|
-
|
|
1958
|
-
_context.
|
|
1959
|
-
_context.n = 6;
|
|
1974
|
+
_context.p = 4;
|
|
1975
|
+
_context.n = 5;
|
|
1960
1976
|
return loadState(ops);
|
|
1961
|
-
case
|
|
1977
|
+
case 5:
|
|
1962
1978
|
state = _context.v;
|
|
1963
1979
|
if (!(state.status === "error")) {
|
|
1964
|
-
_context.n =
|
|
1980
|
+
_context.n = 6;
|
|
1965
1981
|
break;
|
|
1966
1982
|
}
|
|
1967
1983
|
return _context.a(2, state.result);
|
|
1968
|
-
case
|
|
1984
|
+
case 6:
|
|
1969
1985
|
deps = {
|
|
1970
1986
|
ops: ops,
|
|
1971
1987
|
config: options,
|
|
1972
1988
|
ctx: ctx,
|
|
1973
1989
|
state: state.state
|
|
1974
1990
|
};
|
|
1975
|
-
_context.n =
|
|
1991
|
+
_context.n = 7;
|
|
1976
1992
|
return tool.handler(parsed.data, deps);
|
|
1977
|
-
case
|
|
1993
|
+
case 7:
|
|
1978
1994
|
return _context.a(2, _context.v);
|
|
1979
|
-
case
|
|
1980
|
-
_context.p =
|
|
1995
|
+
case 8:
|
|
1996
|
+
_context.p = 8;
|
|
1981
1997
|
_t = _context.v;
|
|
1982
1998
|
return _context.a(2, {
|
|
1983
1999
|
status: "error",
|
|
@@ -1985,7 +2001,7 @@ function createValTools(valModules, options) {
|
|
|
1985
2001
|
message: _t instanceof Error ? _t.message : String(_t)
|
|
1986
2002
|
});
|
|
1987
2003
|
}
|
|
1988
|
-
}, _callee, null, [[
|
|
2004
|
+
}, _callee, null, [[4, 8]]);
|
|
1989
2005
|
}))();
|
|
1990
2006
|
},
|
|
1991
2007
|
dispose: function dispose() {
|
|
@@ -2005,8 +2021,9 @@ function createValTools(valModules, options) {
|
|
|
2005
2021
|
}
|
|
2006
2022
|
|
|
2007
2023
|
/**
|
|
2008
|
-
*
|
|
2009
|
-
* credential the backend will
|
|
2024
|
+
* Whether this caller may reach the data layer at all, which in proxy mode
|
|
2025
|
+
* means whether there is a credential the backend will act on. `null`: it
|
|
2026
|
+
* may.
|
|
2010
2027
|
*
|
|
2011
2028
|
* This is the one place authorization is decided, and in proxy mode there is
|
|
2012
2029
|
* exactly one credential it will act on: an access token whose signature,
|
|
@@ -2027,97 +2044,64 @@ function createValTools(valModules, options) {
|
|
|
2027
2044
|
* profile has to be one the host checked cryptographically, never one it was
|
|
2028
2045
|
* handed. An `authenticate()` that decided a credential's rights inside the app
|
|
2029
2046
|
* would make every bug in it full access to every project that key can reach.
|
|
2047
|
+
*
|
|
2048
|
+
* Every allowed caller reads the same data layer, and that is correct rather
|
|
2049
|
+
* than a shortcut: in fs mode it is a developer's own working tree, with no
|
|
2050
|
+
* credential to vary by, and in proxy mode it authenticates with the app's own
|
|
2051
|
+
* API key, so there is nothing per-caller in it to keep apart.
|
|
2030
2052
|
*/
|
|
2031
|
-
function
|
|
2053
|
+
function refuseCaller(ctx, options) {
|
|
2054
|
+
var _ctx$auth;
|
|
2032
2055
|
if (options.mode === "fs") {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
// only exists because this app advertised an authorization server, so
|
|
2045
|
-
// the developer seeing this did not do anything wrong — a config file
|
|
2046
|
-
// did, and naming it is the difference between a two-minute fix and an
|
|
2047
|
-
// afternoon.
|
|
2048
|
-
return {
|
|
2049
|
-
status: "error",
|
|
2050
|
-
result: {
|
|
2051
|
-
status: "error",
|
|
2052
|
-
code: "unsupported",
|
|
2053
|
-
message: "This Val project is running in local filesystem mode, so there is nothing to authenticate against, but it is configured with an `oauth` issuer and is therefore asking clients for an access token it cannot use. Remove the `oauth` config (or `VAL_OAUTH_ISSUER` from your local `.env`) for local development."
|
|
2054
|
-
}
|
|
2055
|
-
};
|
|
2056
|
-
}
|
|
2057
|
-
return {
|
|
2058
|
-
status: "ok",
|
|
2059
|
-
ops: ops
|
|
2060
|
-
};
|
|
2061
|
-
};
|
|
2062
|
-
}
|
|
2063
|
-
|
|
2064
|
-
/**
|
|
2065
|
-
* One instance for every verified caller, and that is correct rather than a
|
|
2066
|
-
* shortcut: this instance authenticates with the app's own API key, so there
|
|
2067
|
-
* is nothing per-caller in it to keep apart. Who did what travels as the
|
|
2068
|
-
* patch's `authorId` instead — see `writePath`.
|
|
2069
|
-
*
|
|
2070
|
-
* One instance is also all proxy mode keeps now. It could not share while a
|
|
2071
|
-
* personal access token reached this function: each token needed its own
|
|
2072
|
-
* `ValOpsHttp` to hold it, each of those cached the project's evaluated
|
|
2073
|
-
* modules, and the bounded cache that kept that memory in check turned an
|
|
2074
|
-
* eviction into a re-evaluation of every module on the next call.
|
|
2075
|
-
*/
|
|
2076
|
-
var sharedOps = null;
|
|
2077
|
-
return function (ctx) {
|
|
2078
|
-
var _ctx$auth;
|
|
2079
|
-
if (((_ctx$auth = ctx.auth) === null || _ctx$auth === void 0 ? void 0 : _ctx$auth.type) !== "verified-profile") {
|
|
2056
|
+
if (ctx.auth) {
|
|
2057
|
+
// Refused rather than ignored. A host that thinks it is passing a
|
|
2058
|
+
// credential should not silently get local filesystem access instead —
|
|
2059
|
+
// and the difference matters, because fs mode writes straight to disk
|
|
2060
|
+
// with no backend permission check at all.
|
|
2061
|
+
//
|
|
2062
|
+
// A verified access token is not something the caller chose to send: it
|
|
2063
|
+
// only exists because this app advertised an authorization server, so
|
|
2064
|
+
// the developer seeing this did not do anything wrong — a config file
|
|
2065
|
+
// did, and naming it is the difference between a two-minute fix and an
|
|
2066
|
+
// afternoon.
|
|
2080
2067
|
return {
|
|
2081
2068
|
status: "error",
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
code: "forbidden",
|
|
2085
|
-
message: "This Val project talks to the Val content backend, so every call needs an access token from the Val authorization server. If this endpoint is not asking clients to authorize, it has no `oauth` config — give `initValMcp` one, or run the project in local filesystem mode for development."
|
|
2086
|
-
}
|
|
2069
|
+
code: "unsupported",
|
|
2070
|
+
message: "This Val project is running in local filesystem mode, so there is nothing to authenticate against, but it is configured with an `oauth` issuer and is therefore asking clients for an access token it cannot use. Remove the `oauth` config (or `VAL_OAUTH_ISSUER` from your local `.env`) for local development."
|
|
2087
2071
|
};
|
|
2088
2072
|
}
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
// alternative to refusing is building ops with no credential at all.
|
|
2093
|
-
return {
|
|
2094
|
-
status: "error",
|
|
2095
|
-
result: {
|
|
2096
|
-
status: "error",
|
|
2097
|
-
code: "forbidden",
|
|
2098
|
-
message: "This Val project has no API key configured, so a verified access token cannot be exchanged for backend access."
|
|
2099
|
-
}
|
|
2100
|
-
};
|
|
2101
|
-
}
|
|
2102
|
-
if (!sharedOps) {
|
|
2103
|
-
sharedOps = server.createValOps(valModules, options);
|
|
2104
|
-
}
|
|
2073
|
+
return null;
|
|
2074
|
+
}
|
|
2075
|
+
if (((_ctx$auth = ctx.auth) === null || _ctx$auth === void 0 ? void 0 : _ctx$auth.type) !== "verified-profile") {
|
|
2105
2076
|
return {
|
|
2106
|
-
status: "
|
|
2107
|
-
|
|
2077
|
+
status: "error",
|
|
2078
|
+
code: "forbidden",
|
|
2079
|
+
message: "This Val project talks to the Val content backend, so every call needs an access token from the Val authorization server. If this endpoint is not asking clients to authorize, it has no `oauth` config — give `initValMcp` one, or run the project in local filesystem mode for development."
|
|
2108
2080
|
};
|
|
2109
|
-
}
|
|
2081
|
+
}
|
|
2082
|
+
if (!options.apiKey) {
|
|
2083
|
+
// Proxy mode is inferred from the api key being present, so this is
|
|
2084
|
+
// unreachable through `initHandlerOptions`. It stays because the
|
|
2085
|
+
// alternative to refusing is acting with no credential at all.
|
|
2086
|
+
return {
|
|
2087
|
+
status: "error",
|
|
2088
|
+
code: "forbidden",
|
|
2089
|
+
message: "This Val project has no API key configured, so a verified access token cannot be exchanged for backend access."
|
|
2090
|
+
};
|
|
2091
|
+
}
|
|
2092
|
+
return null;
|
|
2110
2093
|
}
|
|
2094
|
+
|
|
2111
2095
|
/**
|
|
2112
|
-
* The content as the caller should see it
|
|
2096
|
+
* The content as the caller should see it: the head's (`ValHead.tree`).
|
|
2113
2097
|
*
|
|
2114
2098
|
* Pending patches are applied, because an agent looking at a project mid-edit
|
|
2115
2099
|
* should see what the Studio would show rather than the last published state.
|
|
2116
|
-
*
|
|
2117
|
-
*
|
|
2118
|
-
*
|
|
2119
|
-
*
|
|
2120
|
-
*
|
|
2100
|
+
* The head re-reads the chain only when it moved (`seq`), and makes each
|
|
2101
|
+
* patched module once per version, so a call after nothing changed costs one
|
|
2102
|
+
* "has it moved?" -- and a call after a write (a save in fs mode moves the
|
|
2103
|
+
* base too) sees it, so an agent never writes against content that has
|
|
2104
|
+
* already moved.
|
|
2121
2105
|
*
|
|
2122
2106
|
* Exported for `toolsFixture`, not for consumers: `tools/index.ts` re-exports by
|
|
2123
2107
|
* name, so this stays inside the package. A test that assembled its own state
|
|
@@ -2128,17 +2112,19 @@ function loadState(_x) {
|
|
|
2128
2112
|
}
|
|
2129
2113
|
function _loadState() {
|
|
2130
2114
|
_loadState = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee3(ops) {
|
|
2131
|
-
var
|
|
2115
|
+
var tree, _yield$Promise$all, _yield$Promise$all2, schemas, serialized, serializedSchemas, isModuleFilePath, _i, _Object$entries, _Object$entries$_i, path, schema;
|
|
2132
2116
|
return asyncToGenerator._regenerator().w(function (_context3) {
|
|
2133
2117
|
while (1) switch (_context3.n) {
|
|
2134
2118
|
case 0:
|
|
2135
2119
|
_context3.n = 1;
|
|
2136
|
-
return ops.
|
|
2137
|
-
excludePatchOps: false
|
|
2138
|
-
});
|
|
2120
|
+
return ops.head.tree();
|
|
2139
2121
|
case 1:
|
|
2140
|
-
|
|
2141
|
-
if (!
|
|
2122
|
+
tree = _context3.v;
|
|
2123
|
+
if (!("error" in tree)) {
|
|
2124
|
+
_context3.n = 4;
|
|
2125
|
+
break;
|
|
2126
|
+
}
|
|
2127
|
+
if (!tree.error.unauthorized) {
|
|
2142
2128
|
_context3.n = 2;
|
|
2143
2129
|
break;
|
|
2144
2130
|
}
|
|
@@ -2151,7 +2137,7 @@ function _loadState() {
|
|
|
2151
2137
|
}
|
|
2152
2138
|
});
|
|
2153
2139
|
case 2:
|
|
2154
|
-
if (!
|
|
2140
|
+
if (!tree.error.networkError) {
|
|
2155
2141
|
_context3.n = 3;
|
|
2156
2142
|
break;
|
|
2157
2143
|
}
|
|
@@ -2164,48 +2150,46 @@ function _loadState() {
|
|
|
2164
2150
|
}
|
|
2165
2151
|
});
|
|
2166
2152
|
case 3:
|
|
2167
|
-
if (!patches.error) {
|
|
2168
|
-
_context3.n = 4;
|
|
2169
|
-
break;
|
|
2170
|
-
}
|
|
2171
2153
|
return _context3.a(2, {
|
|
2172
2154
|
status: "error",
|
|
2173
2155
|
result: {
|
|
2174
2156
|
status: "error",
|
|
2175
2157
|
code: "internal",
|
|
2176
|
-
message:
|
|
2158
|
+
message: tree.error.message
|
|
2177
2159
|
}
|
|
2178
2160
|
});
|
|
2179
2161
|
case 4:
|
|
2180
|
-
analysis = ops.analyzePatches(patches.patches); // getSourcesWithPatchesApplied, not getSources(analysis): the latter returns
|
|
2181
|
-
// only the modules that had patches, and validating that subset reports
|
|
2182
|
-
// spurious errors for anything that looks across modules, like keyOf or a
|
|
2183
|
-
// router.
|
|
2184
2162
|
_context3.n = 5;
|
|
2185
|
-
return ops.
|
|
2163
|
+
return Promise.all([ops.getSchemas(), ops.head.serializedSchemas()]);
|
|
2186
2164
|
case 5:
|
|
2187
|
-
sourcesRes = _context3.v;
|
|
2188
|
-
_context3.n = 6;
|
|
2189
|
-
return Promise.all([ops.getSchemas(), ops.getSerializedSchemas()]);
|
|
2190
|
-
case 6:
|
|
2191
2165
|
_yield$Promise$all = _context3.v;
|
|
2192
2166
|
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
2193
2167
|
schemas = _yield$Promise$all2[0];
|
|
2194
|
-
|
|
2168
|
+
serialized = _yield$Promise$all2[1];
|
|
2169
|
+
serializedSchemas = {}; // Keys of `serialized` are the module paths it was written under.
|
|
2170
|
+
isModuleFilePath = function isModuleFilePath(key) {
|
|
2171
|
+
return Object.prototype.hasOwnProperty.call(serialized, key);
|
|
2172
|
+
};
|
|
2173
|
+
for (_i = 0, _Object$entries = Object.entries(serialized); _i < _Object$entries.length; _i++) {
|
|
2174
|
+
_Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), path = _Object$entries$_i[0], schema = _Object$entries$_i[1];
|
|
2175
|
+
if (schema !== undefined && isModuleFilePath(path)) {
|
|
2176
|
+
serializedSchemas[path] = schema;
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2195
2179
|
return _context3.a(2, {
|
|
2196
2180
|
status: "ok",
|
|
2197
2181
|
state: {
|
|
2198
2182
|
schemas: schemas,
|
|
2199
2183
|
serializedSchemas: serializedSchemas,
|
|
2200
|
-
sources:
|
|
2201
|
-
patches:
|
|
2202
|
-
analysis: analysis,
|
|
2184
|
+
sources: tree.ok.sources,
|
|
2185
|
+
patches: tree.ok.chain.fetched,
|
|
2186
|
+
analysis: tree.ok.chain.analysis,
|
|
2203
2187
|
// Which modules hold a pending patch that would not apply. Carried rather
|
|
2204
2188
|
// than discarded because their `sources` silently lack that change: the
|
|
2205
2189
|
// content here is not what publishing would produce, so a write against
|
|
2206
2190
|
// it would be based on a state that does not exist. See
|
|
2207
2191
|
// `unappliedPatchesFor`.
|
|
2208
|
-
unappliedPatches:
|
|
2192
|
+
unappliedPatches: tree.ok.errors
|
|
2209
2193
|
}
|
|
2210
2194
|
});
|
|
2211
2195
|
}
|
|
@@ -3374,7 +3358,7 @@ var packageJson = {
|
|
|
3374
3358
|
"./package.json": "./package.json"
|
|
3375
3359
|
},
|
|
3376
3360
|
types: "dist/valbuild-mcp.cjs.d.ts",
|
|
3377
|
-
version: "0.
|
|
3361
|
+
version: "0.152.0",
|
|
3378
3362
|
scripts: {
|
|
3379
3363
|
typecheck: "tsc --noEmit",
|
|
3380
3364
|
test: "jest",
|