@apilift/cli 1.10.2 → 1.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apilift-capture-server.js +51 -69
- package/dist/apilift-collector.js +18 -0
- package/dist/apilift.js +583 -467
- package/dist/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/plugin/.codex-plugin/plugin.json +1 -1
- package/dist/plugin/skills/discover/references/html-forms-navigation.md +1 -1
- package/dist/plugin/skills/discover/references/operation-contract.md +1 -1
- package/package.json +3 -2
package/dist/apilift.js
CHANGED
|
@@ -210,9 +210,9 @@ function floatSafeRemainder(val2, step) {
|
|
|
210
210
|
return 0;
|
|
211
211
|
return ratio - roundedRatio;
|
|
212
212
|
}
|
|
213
|
-
function defineLazy(
|
|
213
|
+
function defineLazy(object16, key2, getter) {
|
|
214
214
|
let value = void 0;
|
|
215
|
-
Object.defineProperty(
|
|
215
|
+
Object.defineProperty(object16, key2, {
|
|
216
216
|
get() {
|
|
217
217
|
if (value === EVALUATING) {
|
|
218
218
|
return void 0;
|
|
@@ -224,7 +224,7 @@ function defineLazy(object15, key2, getter) {
|
|
|
224
224
|
return value;
|
|
225
225
|
},
|
|
226
226
|
set(v) {
|
|
227
|
-
Object.defineProperty(
|
|
227
|
+
Object.defineProperty(object16, key2, {
|
|
228
228
|
value: v
|
|
229
229
|
// configurable: true,
|
|
230
230
|
});
|
|
@@ -2217,11 +2217,11 @@ function isValidCIDRv6(value) {
|
|
|
2217
2217
|
const parts2 = value.split("/");
|
|
2218
2218
|
if (parts2.length !== 2)
|
|
2219
2219
|
return false;
|
|
2220
|
-
const [address,
|
|
2221
|
-
if (!
|
|
2220
|
+
const [address, prefix3] = parts2;
|
|
2221
|
+
if (!prefix3)
|
|
2222
2222
|
return false;
|
|
2223
|
-
const prefixNum = Number(
|
|
2224
|
-
if (`${prefixNum}` !==
|
|
2223
|
+
const prefixNum = Number(prefix3);
|
|
2224
|
+
if (`${prefixNum}` !== prefix3)
|
|
2225
2225
|
return false;
|
|
2226
2226
|
if (prefixNum < 0 || prefixNum > 128)
|
|
2227
2227
|
return false;
|
|
@@ -13420,8 +13420,8 @@ function generateStringFormatCheck(doc, ctx, def, accessor, needsValue = true) {
|
|
|
13420
13420
|
doc.write(`if (!${accessor}.includes(${esc(def.includes)})) return INVALID;`);
|
|
13421
13421
|
break;
|
|
13422
13422
|
case "starts_with": {
|
|
13423
|
-
const
|
|
13424
|
-
doc.write(`if (${accessor}.slice(0, ${
|
|
13423
|
+
const prefix3 = def.prefix;
|
|
13424
|
+
doc.write(`if (${accessor}.slice(0, ${prefix3.length}) !== ${esc(prefix3)}) return INVALID;`);
|
|
13425
13425
|
break;
|
|
13426
13426
|
}
|
|
13427
13427
|
case "ends_with": {
|
|
@@ -14159,8 +14159,8 @@ function generateDiscriminatedUnionCheck(doc, ctx, def, accessor) {
|
|
|
14159
14159
|
claimed.add(value);
|
|
14160
14160
|
}
|
|
14161
14161
|
const conditions = Array.from(values, (value) => literalEquality(ctx, discVar, value));
|
|
14162
|
-
const
|
|
14163
|
-
doc.write(`${
|
|
14162
|
+
const prefix3 = firstBranch ? "if" : "else if";
|
|
14163
|
+
doc.write(`${prefix3} (${conditions.join(" || ")}) {`);
|
|
14164
14164
|
doc.indented((d) => {
|
|
14165
14165
|
const branchOutput = generateCheck(d, ctx, option, accessor);
|
|
14166
14166
|
d.write(`${outputVar} = ${branchOutput};`);
|
|
@@ -15159,12 +15159,12 @@ function _includes(includes, params) {
|
|
|
15159
15159
|
});
|
|
15160
15160
|
}
|
|
15161
15161
|
// @__NO_SIDE_EFFECTS__
|
|
15162
|
-
function _startsWith(
|
|
15162
|
+
function _startsWith(prefix3, params) {
|
|
15163
15163
|
return new $ZodCheckStartsWith({
|
|
15164
15164
|
check: "string_format",
|
|
15165
15165
|
format: "starts_with",
|
|
15166
15166
|
...normalizeParams(params),
|
|
15167
|
-
prefix:
|
|
15167
|
+
prefix: prefix3
|
|
15168
15168
|
});
|
|
15169
15169
|
}
|
|
15170
15170
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -15838,8 +15838,8 @@ function foldObjects(members2) {
|
|
|
15838
15838
|
}
|
|
15839
15839
|
const properties = {};
|
|
15840
15840
|
const required2 = /* @__PURE__ */ new Set();
|
|
15841
|
-
for (const
|
|
15842
|
-
for (const key2 in
|
|
15841
|
+
for (const object16 of objects2) {
|
|
15842
|
+
for (const key2 in object16.properties) {
|
|
15843
15843
|
if (Object.prototype.hasOwnProperty.call(properties, key2))
|
|
15844
15844
|
continue;
|
|
15845
15845
|
const parts2 = [];
|
|
@@ -15853,18 +15853,18 @@ function foldObjects(members2) {
|
|
|
15853
15853
|
const merged = parts2.length === 1 ? parts2[0] : foldObjects(parts2) ?? { allOf: parts2 };
|
|
15854
15854
|
assignProp(properties, key2, merged);
|
|
15855
15855
|
}
|
|
15856
|
-
for (const key2 of
|
|
15856
|
+
for (const key2 of object16.required ?? [])
|
|
15857
15857
|
required2.add(key2);
|
|
15858
15858
|
}
|
|
15859
15859
|
const folded = { type: "object", properties };
|
|
15860
15860
|
if (required2.size)
|
|
15861
15861
|
folded.required = [...required2];
|
|
15862
|
-
if (objects2.every((
|
|
15862
|
+
if (objects2.every((object16) => object16.additionalProperties === false)) {
|
|
15863
15863
|
folded.additionalProperties = false;
|
|
15864
15864
|
} else {
|
|
15865
15865
|
const constraints = [];
|
|
15866
|
-
for (const
|
|
15867
|
-
const constraint = undeclaredConstraint(
|
|
15866
|
+
for (const object16 of objects2) {
|
|
15867
|
+
const constraint = undeclaredConstraint(object16);
|
|
15868
15868
|
if (constraint && !constraints.some((seen) => JSON.stringify(seen) === JSON.stringify(constraint)))
|
|
15869
15869
|
constraints.push(constraint);
|
|
15870
15870
|
}
|
|
@@ -20722,26 +20722,26 @@ var require_scope = __commonJS({
|
|
|
20722
20722
|
toName(nameOrPrefix) {
|
|
20723
20723
|
return nameOrPrefix instanceof code_1.Name ? nameOrPrefix : this.name(nameOrPrefix);
|
|
20724
20724
|
}
|
|
20725
|
-
name(
|
|
20726
|
-
return new code_1.Name(this._newName(
|
|
20725
|
+
name(prefix3) {
|
|
20726
|
+
return new code_1.Name(this._newName(prefix3));
|
|
20727
20727
|
}
|
|
20728
|
-
_newName(
|
|
20729
|
-
const ng = this._names[
|
|
20730
|
-
return `${
|
|
20728
|
+
_newName(prefix3) {
|
|
20729
|
+
const ng = this._names[prefix3] || this._nameGroup(prefix3);
|
|
20730
|
+
return `${prefix3}${ng.index++}`;
|
|
20731
20731
|
}
|
|
20732
|
-
_nameGroup(
|
|
20732
|
+
_nameGroup(prefix3) {
|
|
20733
20733
|
var _a6, _b;
|
|
20734
|
-
if (((_b = (_a6 = this._parent) === null || _a6 === void 0 ? void 0 : _a6._prefixes) === null || _b === void 0 ? void 0 : _b.has(
|
|
20735
|
-
throw new Error(`CodeGen: prefix "${
|
|
20734
|
+
if (((_b = (_a6 = this._parent) === null || _a6 === void 0 ? void 0 : _a6._prefixes) === null || _b === void 0 ? void 0 : _b.has(prefix3)) || this._prefixes && !this._prefixes.has(prefix3)) {
|
|
20735
|
+
throw new Error(`CodeGen: prefix "${prefix3}" is not allowed in this scope`);
|
|
20736
20736
|
}
|
|
20737
|
-
return this._names[
|
|
20737
|
+
return this._names[prefix3] = { prefix: prefix3, index: 0 };
|
|
20738
20738
|
}
|
|
20739
20739
|
};
|
|
20740
20740
|
exports.Scope = Scope;
|
|
20741
20741
|
var ValueScopeName = class extends code_1.Name {
|
|
20742
|
-
constructor(
|
|
20742
|
+
constructor(prefix3, nameStr) {
|
|
20743
20743
|
super(nameStr);
|
|
20744
|
-
this.prefix =
|
|
20744
|
+
this.prefix = prefix3;
|
|
20745
20745
|
}
|
|
20746
20746
|
setValue(value, { property, itemIndex }) {
|
|
20747
20747
|
this.value = value;
|
|
@@ -20760,33 +20760,33 @@ var require_scope = __commonJS({
|
|
|
20760
20760
|
get() {
|
|
20761
20761
|
return this._scope;
|
|
20762
20762
|
}
|
|
20763
|
-
name(
|
|
20764
|
-
return new ValueScopeName(
|
|
20763
|
+
name(prefix3) {
|
|
20764
|
+
return new ValueScopeName(prefix3, this._newName(prefix3));
|
|
20765
20765
|
}
|
|
20766
20766
|
value(nameOrPrefix, value) {
|
|
20767
20767
|
var _a6;
|
|
20768
20768
|
if (value.ref === void 0)
|
|
20769
20769
|
throw new Error("CodeGen: ref must be passed in value");
|
|
20770
20770
|
const name = this.toName(nameOrPrefix);
|
|
20771
|
-
const { prefix:
|
|
20771
|
+
const { prefix: prefix3 } = name;
|
|
20772
20772
|
const valueKey = (_a6 = value.key) !== null && _a6 !== void 0 ? _a6 : value.ref;
|
|
20773
|
-
let vs = this._values[
|
|
20773
|
+
let vs = this._values[prefix3];
|
|
20774
20774
|
if (vs) {
|
|
20775
20775
|
const _name = vs.get(valueKey);
|
|
20776
20776
|
if (_name)
|
|
20777
20777
|
return _name;
|
|
20778
20778
|
} else {
|
|
20779
|
-
vs = this._values[
|
|
20779
|
+
vs = this._values[prefix3] = /* @__PURE__ */ new Map();
|
|
20780
20780
|
}
|
|
20781
20781
|
vs.set(valueKey, name);
|
|
20782
|
-
const s = this._scope[
|
|
20782
|
+
const s = this._scope[prefix3] || (this._scope[prefix3] = []);
|
|
20783
20783
|
const itemIndex = s.length;
|
|
20784
20784
|
s[itemIndex] = value.ref;
|
|
20785
|
-
name.setValue(value, { property:
|
|
20785
|
+
name.setValue(value, { property: prefix3, itemIndex });
|
|
20786
20786
|
return name;
|
|
20787
20787
|
}
|
|
20788
|
-
getValue(
|
|
20789
|
-
const vs = this._values[
|
|
20788
|
+
getValue(prefix3, keyOrRef) {
|
|
20789
|
+
const vs = this._values[prefix3];
|
|
20790
20790
|
if (!vs)
|
|
20791
20791
|
return;
|
|
20792
20792
|
return vs.get(keyOrRef);
|
|
@@ -20807,11 +20807,11 @@ var require_scope = __commonJS({
|
|
|
20807
20807
|
}
|
|
20808
20808
|
_reduceValues(values, valueCode, usedValues = {}, getCode) {
|
|
20809
20809
|
let code = code_1.nil;
|
|
20810
|
-
for (const
|
|
20811
|
-
const vs = values[
|
|
20810
|
+
for (const prefix3 in values) {
|
|
20811
|
+
const vs = values[prefix3];
|
|
20812
20812
|
if (!vs)
|
|
20813
20813
|
continue;
|
|
20814
|
-
const nameSet = usedValues[
|
|
20814
|
+
const nameSet = usedValues[prefix3] = usedValues[prefix3] || /* @__PURE__ */ new Map();
|
|
20815
20815
|
vs.forEach((name) => {
|
|
20816
20816
|
if (nameSet.has(name))
|
|
20817
20817
|
return;
|
|
@@ -21244,12 +21244,12 @@ var require_codegen = __commonJS({
|
|
|
21244
21244
|
return this._root.render(this.opts);
|
|
21245
21245
|
}
|
|
21246
21246
|
// returns unique name in the internal scope
|
|
21247
|
-
name(
|
|
21248
|
-
return this._scope.name(
|
|
21247
|
+
name(prefix3) {
|
|
21248
|
+
return this._scope.name(prefix3);
|
|
21249
21249
|
}
|
|
21250
21250
|
// reserves unique name in the external scope
|
|
21251
|
-
scopeName(
|
|
21252
|
-
return this._extScope.name(
|
|
21251
|
+
scopeName(prefix3) {
|
|
21252
|
+
return this._extScope.name(prefix3);
|
|
21253
21253
|
}
|
|
21254
21254
|
// reserves unique name in the external scope and assigns value to it
|
|
21255
21255
|
scopeValue(prefixOrName, value) {
|
|
@@ -21258,8 +21258,8 @@ var require_codegen = __commonJS({
|
|
|
21258
21258
|
vs.add(name);
|
|
21259
21259
|
return name;
|
|
21260
21260
|
}
|
|
21261
|
-
getScopeValue(
|
|
21262
|
-
return this._extScope.getValue(
|
|
21261
|
+
getScopeValue(prefix3, keyOrRef) {
|
|
21262
|
+
return this._extScope.getValue(prefix3, keyOrRef);
|
|
21263
21263
|
}
|
|
21264
21264
|
// return code that assigns values in the external scope to the names that are used internally
|
|
21265
21265
|
// (same names that were returned by gen.scopeName or gen.scopeValue)
|
|
@@ -28138,12 +28138,12 @@ function enterValue(value, seen) {
|
|
|
28138
28138
|
wrappers
|
|
28139
28139
|
};
|
|
28140
28140
|
}
|
|
28141
|
-
function canonicalize(
|
|
28142
|
-
if (
|
|
28143
|
-
return serializePrimitive(
|
|
28141
|
+
function canonicalize(object16) {
|
|
28142
|
+
if (object16 === null || typeof object16 !== "object") {
|
|
28143
|
+
return serializePrimitive(object16);
|
|
28144
28144
|
}
|
|
28145
28145
|
const seen = /* @__PURE__ */ new Set();
|
|
28146
|
-
const root2 = enterValue(
|
|
28146
|
+
const root2 = enterValue(object16, seen);
|
|
28147
28147
|
if (typeof root2 !== "object") {
|
|
28148
28148
|
return root2;
|
|
28149
28149
|
}
|
|
@@ -29521,24 +29521,24 @@ function schemaSelection(schema, pointer8) {
|
|
|
29521
29521
|
const tail = child(obj, "items");
|
|
29522
29522
|
const firstClosed = tuple2.indexOf(false);
|
|
29523
29523
|
const limit = Math.min(typeof obj.maxItems === "number" ? obj.maxItems : Infinity, tail === false ? tuple2.length : Infinity, firstClosed < 0 ? Infinity : firstClosed);
|
|
29524
|
-
const
|
|
29524
|
+
const prefix3 = tuple2.slice(0, limit);
|
|
29525
29525
|
const items = limit <= tuple2.length ? false : tail;
|
|
29526
29526
|
if (segment !== "*") {
|
|
29527
29527
|
const index2 = Number(segment);
|
|
29528
29528
|
if (!Number.isSafeInteger(index2) || index2 >= limit)
|
|
29529
29529
|
return void 0;
|
|
29530
|
-
current = index2 <
|
|
29530
|
+
current = index2 < prefix3.length ? prefix3[index2] : items;
|
|
29531
29531
|
if (resolveLocalSchema(schema, current) === false)
|
|
29532
29532
|
return void 0;
|
|
29533
29533
|
} else {
|
|
29534
29534
|
if (!limit)
|
|
29535
29535
|
return void 0;
|
|
29536
29536
|
wildcard = true;
|
|
29537
|
-
if (!
|
|
29537
|
+
if (!prefix3.length)
|
|
29538
29538
|
current = items;
|
|
29539
29539
|
else {
|
|
29540
|
-
const common = resolveLocalSchema(schema, items === false ?
|
|
29541
|
-
if (common === void 0 || !
|
|
29540
|
+
const common = resolveLocalSchema(schema, items === false ? prefix3[0] : items);
|
|
29541
|
+
if (common === void 0 || !prefix3.every((item) => {
|
|
29542
29542
|
const resolved = resolveLocalSchema(schema, item);
|
|
29543
29543
|
return resolved !== void 0 && assignable(resolved, common) && (items !== false || assignable(common, resolved));
|
|
29544
29544
|
}))
|
|
@@ -29692,12 +29692,12 @@ function essentialOutputSchema(source, paths2, declared = /* @__PURE__ */ new Ma
|
|
|
29692
29692
|
if (segments.length > 128)
|
|
29693
29693
|
throw new Error("Essential output path exceeds 128 segments");
|
|
29694
29694
|
let node2 = selection;
|
|
29695
|
-
let
|
|
29695
|
+
let prefix3 = "";
|
|
29696
29696
|
for (const segment of segments) {
|
|
29697
|
-
|
|
29698
|
-
prefixes.add(
|
|
29697
|
+
prefix3 += `/${segment}`;
|
|
29698
|
+
prefixes.add(prefix3);
|
|
29699
29699
|
if (requiredPaths.has(path2))
|
|
29700
|
-
required2.add(
|
|
29700
|
+
required2.add(prefix3);
|
|
29701
29701
|
const key2 = segment.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
29702
29702
|
if (!node2.has(key2))
|
|
29703
29703
|
node2.set(key2, /* @__PURE__ */ new Map());
|
|
@@ -29792,6 +29792,60 @@ var init_essential_output = __esm({
|
|
|
29792
29792
|
}
|
|
29793
29793
|
});
|
|
29794
29794
|
|
|
29795
|
+
// ../../packages/core/dist/definitions/html-response-authoring.js
|
|
29796
|
+
function object4(value) {
|
|
29797
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
29798
|
+
}
|
|
29799
|
+
function htmlActionResponseIssues(definition2) {
|
|
29800
|
+
if (!("request" in definition2))
|
|
29801
|
+
return [];
|
|
29802
|
+
const response = definition2.response;
|
|
29803
|
+
if (!response?.html || response.fields || response.path || response.continue?.length)
|
|
29804
|
+
return [];
|
|
29805
|
+
const issues = [];
|
|
29806
|
+
function check2(fields, schema2, path3, requiredSelector) {
|
|
29807
|
+
const properties = object4(object4(schema2)?.properties);
|
|
29808
|
+
if (!properties)
|
|
29809
|
+
return;
|
|
29810
|
+
for (const [name, field] of Object.entries(fields)) {
|
|
29811
|
+
if (!Object.hasOwn(properties, name))
|
|
29812
|
+
continue;
|
|
29813
|
+
const property = object4(properties[name]);
|
|
29814
|
+
if (!property || field.many && property.prefixItems)
|
|
29815
|
+
continue;
|
|
29816
|
+
const result3 = field.many ? object4(property.items) : property;
|
|
29817
|
+
if (!result3)
|
|
29818
|
+
continue;
|
|
29819
|
+
const escapedName = name.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
29820
|
+
const resultPath = `${path3}/properties/${escapedName}${field.many ? "/items" : ""}`;
|
|
29821
|
+
const canMissMatch = !field.many && field.selector && field.selector !== requiredSelector;
|
|
29822
|
+
const canReturnNull = field.optional && (field.read === "attribute" || field.read === "value" || canMissMatch);
|
|
29823
|
+
const types3 = typeof result3.type === "string" ? [result3.type] : result3.type;
|
|
29824
|
+
if (canReturnNull && Array.isArray(types3) && !types3.includes("null")) {
|
|
29825
|
+
issues.push({
|
|
29826
|
+
path: resultPath,
|
|
29827
|
+
message: "This optional HTML field can return null. Allow null in its schema or require the extraction."
|
|
29828
|
+
});
|
|
29829
|
+
}
|
|
29830
|
+
if (field.fields)
|
|
29831
|
+
check2(field.fields, result3, resultPath);
|
|
29832
|
+
}
|
|
29833
|
+
}
|
|
29834
|
+
let schema = response.schema;
|
|
29835
|
+
let path2 = "/response/schema";
|
|
29836
|
+
if (response.headers) {
|
|
29837
|
+
schema = object4(object4(schema)?.properties)?.body;
|
|
29838
|
+
path2 += "/properties/body";
|
|
29839
|
+
}
|
|
29840
|
+
check2(response.html.fields, schema, path2, response.html.marker);
|
|
29841
|
+
return issues;
|
|
29842
|
+
}
|
|
29843
|
+
var init_html_response_authoring = __esm({
|
|
29844
|
+
"../../packages/core/dist/definitions/html-response-authoring.js"() {
|
|
29845
|
+
"use strict";
|
|
29846
|
+
}
|
|
29847
|
+
});
|
|
29848
|
+
|
|
29795
29849
|
// ../../packages/core/dist/definitions/categories.js
|
|
29796
29850
|
var labels, descriptions, categories;
|
|
29797
29851
|
var init_categories = __esm({
|
|
@@ -29830,6 +29884,7 @@ var init_definitions = __esm({
|
|
|
29830
29884
|
init_rules();
|
|
29831
29885
|
init_analysis();
|
|
29832
29886
|
init_metadata();
|
|
29887
|
+
init_html_response_authoring();
|
|
29833
29888
|
init_categories();
|
|
29834
29889
|
init_credential_contract();
|
|
29835
29890
|
}
|
|
@@ -30103,12 +30158,12 @@ function retainFeedback(state, session, registry2, body) {
|
|
|
30103
30158
|
prepareFeedback(state);
|
|
30104
30159
|
const authored = Object.fromEntries(Object.entries(body).filter(([key2]) => !["id", "metadata"].includes(key2)));
|
|
30105
30160
|
const fingerprint2 = createHash("sha256").update(JSON.stringify(authored)).digest("hex");
|
|
30106
|
-
const
|
|
30107
|
-
const existing = state.db.prepare("SELECT id FROM feedback_outbox WHERE session_id=? AND owner IS ? AND registry=? AND fingerprint=?").get(
|
|
30161
|
+
const worker = session?.id ?? "unbound", owner = feedbackOwner(state);
|
|
30162
|
+
const existing = state.db.prepare("SELECT id FROM feedback_outbox WHERE session_id=? AND owner IS ? AND registry=? AND fingerprint=?").get(worker, owner, registry2, fingerprint2);
|
|
30108
30163
|
if (existing) return existing.id;
|
|
30109
30164
|
const count = state.db.prepare("SELECT count(*) AS n FROM feedback_outbox WHERE delivered=0").get();
|
|
30110
30165
|
if (count.n >= 100) throw new Error("Feedback queue is full. Retry retained reports before adding more.");
|
|
30111
|
-
state.db.prepare("INSERT INTO feedback_outbox (id,session_id,registry,owner,fingerprint,body,created_at) VALUES (?,?,?,?,?,?,?)").run(body.id,
|
|
30166
|
+
state.db.prepare("INSERT INTO feedback_outbox (id,session_id,registry,owner,fingerprint,body,created_at) VALUES (?,?,?,?,?,?,?)").run(body.id, worker, registry2, owner, fingerprint2, JSON.stringify(body), Date.now());
|
|
30112
30167
|
return body.id;
|
|
30113
30168
|
}
|
|
30114
30169
|
async function deliverFeedback(state, api, id2) {
|
|
@@ -30242,8 +30297,8 @@ function readFeedbackAttachment(path2, ordinal) {
|
|
|
30242
30297
|
}
|
|
30243
30298
|
async function handleFeedback(invocation, api, state, session) {
|
|
30244
30299
|
const fail6 = (stderr, exitCode = 2) => ({ stdout: "", stderr: stderr + "\n", exitCode });
|
|
30245
|
-
const
|
|
30246
|
-
if (invocation.key === "feedback") return fail6(`Feedback syntax changed. Use ${
|
|
30300
|
+
const prefix3 = commandPrefix(invocation.sessionLabel);
|
|
30301
|
+
if (invocation.key === "feedback") return fail6(`Feedback syntax changed. Use ${prefix3} feedback report or ${prefix3} feedback action <app> <action> with --blocked, --repro, --expected and --actual. Add --incorrect for an incorrect result; do not repeat a write.`);
|
|
30247
30302
|
prepareFeedback(state);
|
|
30248
30303
|
let id2;
|
|
30249
30304
|
if (invocation.key === "feedbackRetry") {
|
|
@@ -30300,9 +30355,9 @@ async function handleFeedback(invocation, api, state, session) {
|
|
|
30300
30355
|
return fail6("Feedback could not be saved locally. Check local storage and retry retained reports if the queue is full.", 5);
|
|
30301
30356
|
}
|
|
30302
30357
|
}
|
|
30303
|
-
if (!state.installation()) return fail6(`Saved feedback ${id2} locally; not submitted. Link this installation, then run ${
|
|
30358
|
+
if (!state.installation()) return fail6(`Saved feedback ${id2} locally; not submitted. Link this installation, then run ${prefix3} feedback retry ${id2}.`, 9);
|
|
30304
30359
|
await flushExecutionReports(api, state, 100);
|
|
30305
|
-
if (!await deliverFeedback(state, api, id2)) return fail6(`Saved feedback ${id2} locally; delivery pending. Do not resubmit. Retry with ${
|
|
30360
|
+
if (!await deliverFeedback(state, api, id2)) return fail6(`Saved feedback ${id2} locally; delivery pending. Do not resubmit. Retry with ${prefix3} feedback retry ${id2}. Continue independent safe work.`, 5);
|
|
30306
30361
|
return { stdout: `Submitted feedback ${id2}.
|
|
30307
30362
|
`, stderr: "", exitCode: 0 };
|
|
30308
30363
|
}
|
|
@@ -30329,61 +30384,52 @@ var init_receipts = __esm({
|
|
|
30329
30384
|
});
|
|
30330
30385
|
|
|
30331
30386
|
// src/capture-server/windows-owner.ts
|
|
30332
|
-
import {
|
|
30333
|
-
function
|
|
30334
|
-
if (
|
|
30335
|
-
|
|
30336
|
-
|
|
30337
|
-
|
|
30338
|
-
|
|
30339
|
-
|
|
30387
|
+
import { createRequire as createNativeRequire } from "node:module";
|
|
30388
|
+
function windowsProcessApi() {
|
|
30389
|
+
if (cachedApi) return cachedApi;
|
|
30390
|
+
const koffi = requireNative("koffi");
|
|
30391
|
+
const kernel = koffi.load("kernel32.dll");
|
|
30392
|
+
const open4 = kernel.func("void * __stdcall OpenProcess(uint32_t access, int inherit, uint32_t pid)");
|
|
30393
|
+
const times = kernel.func("int __stdcall GetProcessTimes(void *process, void *created, void *exited, void *kernel, void *user)");
|
|
30394
|
+
const wait = kernel.func("uint32_t __stdcall WaitForSingleObject(void *handle, uint32_t milliseconds)");
|
|
30395
|
+
const close = kernel.func("int __stdcall CloseHandle(void *handle)");
|
|
30396
|
+
cachedApi = {
|
|
30397
|
+
open: (pid) => open4(queryAndSynchronize, 0, pid),
|
|
30398
|
+
query(handle2) {
|
|
30399
|
+
const values = Buffer.alloc(32);
|
|
30400
|
+
if (!times(handle2, values.subarray(0, 8), values.subarray(8, 16), values.subarray(16, 24), values.subarray(24))) return null;
|
|
30401
|
+
return { created: values.readBigUInt64LE(), running: wait(handle2, 0) === waitTimeout };
|
|
30402
|
+
},
|
|
30403
|
+
close
|
|
30404
|
+
};
|
|
30405
|
+
return cachedApi;
|
|
30406
|
+
}
|
|
30407
|
+
function windowsProcessStart(pid, load2 = windowsProcessApi) {
|
|
30408
|
+
if (!Number.isInteger(pid) || pid <= 0 || pid > 4294967295) return null;
|
|
30409
|
+
try {
|
|
30410
|
+
const api = load2();
|
|
30411
|
+
const handle2 = api.open(pid);
|
|
30412
|
+
if (!handle2) return null;
|
|
30413
|
+
try {
|
|
30414
|
+
const info = api.query(handle2);
|
|
30415
|
+
if (!info?.running || info.created <= unixEpochFileTime) return null;
|
|
30416
|
+
const created = Number((info.created - unixEpochFileTime) / 10000n);
|
|
30417
|
+
return Number.isSafeInteger(created) ? created : null;
|
|
30418
|
+
} finally {
|
|
30419
|
+
api.close(handle2);
|
|
30420
|
+
}
|
|
30421
|
+
} catch {
|
|
30422
|
+
return null;
|
|
30340
30423
|
}
|
|
30341
|
-
const state = new Int32Array(memory, 0, 4), value = new Float64Array(memory, 16, 1);
|
|
30342
|
-
const deadline = performance.now() + 8e3;
|
|
30343
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
30344
|
-
if (!isAlive()) return null;
|
|
30345
|
-
const remaining = deadline - performance.now();
|
|
30346
|
-
if (remaining <= 0) break;
|
|
30347
|
-
const id2 = ++sequence;
|
|
30348
|
-
Atomics.store(state, 1, id2);
|
|
30349
|
-
Atomics.store(state, 0, 1);
|
|
30350
|
-
worker.postMessage({ id: id2, pid });
|
|
30351
|
-
const result3 = Atomics.wait(state, 0, 1, Math.min(4e3, remaining));
|
|
30352
|
-
const status = Atomics.load(state, 0);
|
|
30353
|
-
if (status === 2) return Atomics.load(state, 2) === id2 && Number.isFinite(value[0]) && value[0] > 0 && isAlive() ? value[0] : null;
|
|
30354
|
-
if (result3 !== "timed-out" || status !== 1) break;
|
|
30355
|
-
}
|
|
30356
|
-
void worker.terminate();
|
|
30357
|
-
worker = void 0;
|
|
30358
|
-
return null;
|
|
30359
30424
|
}
|
|
30360
|
-
var
|
|
30425
|
+
var requireNative, queryAndSynchronize, waitTimeout, unixEpochFileTime, cachedApi;
|
|
30361
30426
|
var init_windows_owner = __esm({
|
|
30362
30427
|
"src/capture-server/windows-owner.ts"() {
|
|
30363
30428
|
"use strict";
|
|
30364
|
-
|
|
30365
|
-
|
|
30366
|
-
|
|
30367
|
-
|
|
30368
|
-
const state=new Int32Array(workerData.memory,0,4), value=new Float64Array(workerData.memory,16,1);
|
|
30369
|
-
const child=spawn('powershell.exe',['-NoLogo','-NoProfile','-NonInteractive','-Command',workerData.script],{windowsHide:true,stdio:['pipe','pipe','ignore']});
|
|
30370
|
-
const fail=()=>{Atomics.store(state,0,3);Atomics.notify(state,0);};
|
|
30371
|
-
child.on('error',fail);child.on('exit',fail);
|
|
30372
|
-
let text='';
|
|
30373
|
-
child.stdout.on('data',chunk=>{
|
|
30374
|
-
text+=chunk.toString();
|
|
30375
|
-
let end;
|
|
30376
|
-
while((end=text.indexOf('\\n'))>=0){
|
|
30377
|
-
const [id,stamp]=text.slice(0,end).trim().split('|').map(Number);text=text.slice(end+1);
|
|
30378
|
-
if(id!==Atomics.load(state,1)||Atomics.load(state,0)!==1)continue;
|
|
30379
|
-
value[0]=Number.isFinite(stamp)?stamp:0;Atomics.store(state,2,id);Atomics.store(state,0,2);Atomics.notify(state,0);
|
|
30380
|
-
}
|
|
30381
|
-
if(text.length>1024){child.kill();fail();}
|
|
30382
|
-
});
|
|
30383
|
-
const {parentPort}=require('node:worker_threads');
|
|
30384
|
-
parentPort.on('message',({id,pid})=>{try{child.stdin.write(id+'|'+pid+'\\n');}catch{fail();}});
|
|
30385
|
-
`;
|
|
30386
|
-
sequence = 0;
|
|
30429
|
+
requireNative = createNativeRequire(import.meta.url);
|
|
30430
|
+
queryAndSynchronize = 1052672;
|
|
30431
|
+
waitTimeout = 258;
|
|
30432
|
+
unixEpochFileTime = 116444736000000000n;
|
|
30387
30433
|
}
|
|
30388
30434
|
});
|
|
30389
30435
|
|
|
@@ -30671,9 +30717,6 @@ function inspectOwner(pid, expectedStartedAt, probe) {
|
|
|
30671
30717
|
const alive = probe.alive ?? pidAlive;
|
|
30672
30718
|
const inspect2 = probe.inspect ?? inspectProcess;
|
|
30673
30719
|
const platform5 = probe.platform ?? process.platform;
|
|
30674
|
-
const now = probe.now ?? Date.now;
|
|
30675
|
-
const started = now();
|
|
30676
|
-
const windows = platform5 === "win32";
|
|
30677
30720
|
if (platform5 === "linux") {
|
|
30678
30721
|
try {
|
|
30679
30722
|
const read = probe.read ?? ((path2) => readFileSync2(path2, "utf8"));
|
|
@@ -30687,23 +30730,18 @@ function inspectOwner(pid, expectedStartedAt, probe) {
|
|
|
30687
30730
|
return false;
|
|
30688
30731
|
}
|
|
30689
30732
|
}
|
|
30690
|
-
if (
|
|
30691
|
-
const observed =
|
|
30733
|
+
if (platform5 === "win32") {
|
|
30734
|
+
const observed = (probe.readWindows ?? windowsProcessStart)(pid);
|
|
30692
30735
|
return observed !== null && Math.abs(observed - expectedStartedAt) <= 5e3;
|
|
30693
30736
|
}
|
|
30694
|
-
|
|
30695
|
-
|
|
30696
|
-
const
|
|
30697
|
-
|
|
30698
|
-
|
|
30699
|
-
|
|
30700
|
-
|
|
30701
|
-
return Number.isFinite(observed) && Math.abs(observed - expectedStartedAt) <= 5e3;
|
|
30702
|
-
} catch (error62) {
|
|
30703
|
-
if (!windows || error62.code !== "ETIMEDOUT") return false;
|
|
30704
|
-
}
|
|
30737
|
+
if (!alive(pid)) return false;
|
|
30738
|
+
try {
|
|
30739
|
+
const raw = inspect2("ps", ["-o", "lstart=", "-p", String(pid)], 2e3);
|
|
30740
|
+
const observed = Date.parse(`${raw.trim()} UTC`);
|
|
30741
|
+
return Number.isFinite(observed) && Math.abs(observed - expectedStartedAt) <= 5e3;
|
|
30742
|
+
} catch {
|
|
30743
|
+
return false;
|
|
30705
30744
|
}
|
|
30706
|
-
return false;
|
|
30707
30745
|
}
|
|
30708
30746
|
var pidAlive, inspectProcess, linuxClockTicks, defaultOwnerVerifier;
|
|
30709
30747
|
var init_store = __esm({
|
|
@@ -32179,10 +32217,10 @@ function parse3(text5, errors = [], options2 = ParseOptions.DEFAULT) {
|
|
|
32179
32217
|
}
|
|
32180
32218
|
const visitor = {
|
|
32181
32219
|
onObjectBegin: () => {
|
|
32182
|
-
const
|
|
32183
|
-
onValue(
|
|
32220
|
+
const object16 = {};
|
|
32221
|
+
onValue(object16);
|
|
32184
32222
|
previousParents.push(currentParent);
|
|
32185
|
-
currentParent =
|
|
32223
|
+
currentParent = object16;
|
|
32186
32224
|
currentProperty = null;
|
|
32187
32225
|
},
|
|
32188
32226
|
onObjectProperty: (name) => {
|
|
@@ -32932,13 +32970,13 @@ function inspectBatch(draft) {
|
|
|
32932
32970
|
const review = Array.isArray(raw.review) ? raw.review : [];
|
|
32933
32971
|
const validated = review.length ? Object.fromEntries(Object.entries(value).filter(([field]) => field !== "review")) : value;
|
|
32934
32972
|
const checked = legacy ? validateDefinition(kind, name, validated) : validateAuthoredDefinition(kind, name, legacyHash ? authorableAction(validated) : validated);
|
|
32935
|
-
const
|
|
32973
|
+
const prefix3 = `/${kind === "entity" ? "entities" : "actions"}/${escape3(name)}`;
|
|
32936
32974
|
for (const issue2 of review) if (isObject2(issue2) && typeof issue2.path === "string" && typeof issue2.message === "string") {
|
|
32937
|
-
issues.push({ path:
|
|
32975
|
+
issues.push({ path: prefix3 + issue2.path, message: issue2.message });
|
|
32938
32976
|
}
|
|
32939
|
-
if (review.length) issues.push({ path:
|
|
32940
|
-
const diagnostics = checked.definition && !legacy ? [...checked.issues, ...documentationIssues(kind, checked.definition)] : checked.issues;
|
|
32941
|
-
issues.push(...diagnostics.map((issue2) => ({ path:
|
|
32977
|
+
if (review.length) issues.push({ path: prefix3 + "/review", message: "Resolve each listed finding, then remove review" });
|
|
32978
|
+
const diagnostics = checked.definition && !legacy ? [...checked.issues, ...htmlActionResponseIssues(checked.definition), ...documentationIssues(kind, checked.definition)] : checked.issues;
|
|
32979
|
+
issues.push(...diagnostics.map((issue2) => ({ path: prefix3 + (issue2.path === "/" ? "" : issue2.path), message: issue2.message })));
|
|
32942
32980
|
if (checked.definition) members2.push({ kind, name, definition: checked.definition });
|
|
32943
32981
|
}
|
|
32944
32982
|
}
|
|
@@ -35883,9 +35921,9 @@ var init_Tokenizer = __esm({
|
|
|
35883
35921
|
isTagStartChar(c) {
|
|
35884
35922
|
return this.xmlMode ? !isEndOfTagSection(c) : isASCIIAlpha(c);
|
|
35885
35923
|
}
|
|
35886
|
-
startSpecial(
|
|
35924
|
+
startSpecial(sequence, offset) {
|
|
35887
35925
|
this.isSpecial = true;
|
|
35888
|
-
this.currentSequence =
|
|
35926
|
+
this.currentSequence = sequence;
|
|
35889
35927
|
this.sequenceIndex = offset;
|
|
35890
35928
|
this.state = State.SpecialStartSequence;
|
|
35891
35929
|
}
|
|
@@ -37187,7 +37225,7 @@ var init_attributes = __esm({
|
|
|
37187
37225
|
init_esm5();
|
|
37188
37226
|
init_esm6();
|
|
37189
37227
|
hasOwn = // @ts-expect-error `hasOwn` is a standard object method
|
|
37190
|
-
(_a5 = Object.hasOwn) !== null && _a5 !== void 0 ? _a5 : ((
|
|
37228
|
+
(_a5 = Object.hasOwn) !== null && _a5 !== void 0 ? _a5 : ((object16, prop2) => Object.prototype.hasOwnProperty.call(object16, prop2));
|
|
37191
37229
|
rspace = /\s+/;
|
|
37192
37230
|
dataAttrPrefix = "data-";
|
|
37193
37231
|
rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i;
|
|
@@ -40091,6 +40129,49 @@ var init_file_artifacts = __esm({
|
|
|
40091
40129
|
}
|
|
40092
40130
|
});
|
|
40093
40131
|
|
|
40132
|
+
// src/execution/response-framing.ts
|
|
40133
|
+
function responseFramingDescription(text5) {
|
|
40134
|
+
if (!text5.startsWith(prefix) || text5.length > maxInspectionBytes || Buffer.byteLength(text5) > maxInspectionBytes) return;
|
|
40135
|
+
let count = 0;
|
|
40136
|
+
let start = prefix.length;
|
|
40137
|
+
if (text5[start] === "[" || text5[start] === "{") {
|
|
40138
|
+
try {
|
|
40139
|
+
JSON.parse(text5.slice(start));
|
|
40140
|
+
} catch {
|
|
40141
|
+
return;
|
|
40142
|
+
}
|
|
40143
|
+
return "The response contains a JSON document behind a guard prefix. The JSON contract expects a single unprefixed JSON value.";
|
|
40144
|
+
}
|
|
40145
|
+
while (start < text5.length) {
|
|
40146
|
+
if (++count > maxFrames) return;
|
|
40147
|
+
const lengthEnd = text5.indexOf("\n", start);
|
|
40148
|
+
if (lengthEnd < 0 || lengthEnd - start > 7) return;
|
|
40149
|
+
const length = text5.slice(start, lengthEnd);
|
|
40150
|
+
if (!/^[1-9]\d*$/u.test(length)) return;
|
|
40151
|
+
const end2 = text5.indexOf("\n", lengthEnd + 1);
|
|
40152
|
+
if (end2 < 0 || text5[lengthEnd + 1] !== "[") return;
|
|
40153
|
+
const frame = text5.slice(lengthEnd + 1, end2);
|
|
40154
|
+
if (Buffer.byteLength(frame) + 2 !== Number(length)) return;
|
|
40155
|
+
try {
|
|
40156
|
+
JSON.parse(frame);
|
|
40157
|
+
} catch {
|
|
40158
|
+
return;
|
|
40159
|
+
}
|
|
40160
|
+
start = end2 + 1;
|
|
40161
|
+
}
|
|
40162
|
+
if (!count) return;
|
|
40163
|
+
return `The response contains ${count} length-delimited JSON ${count === 1 ? "frame" : "frames"}. The JSON contract expects a single unframed JSON value.`;
|
|
40164
|
+
}
|
|
40165
|
+
var prefix, maxInspectionBytes, maxFrames;
|
|
40166
|
+
var init_response_framing = __esm({
|
|
40167
|
+
"src/execution/response-framing.ts"() {
|
|
40168
|
+
"use strict";
|
|
40169
|
+
prefix = ")]}'\n\n";
|
|
40170
|
+
maxInspectionBytes = 4 * 1024 * 1024;
|
|
40171
|
+
maxFrames = 256;
|
|
40172
|
+
}
|
|
40173
|
+
});
|
|
40174
|
+
|
|
40094
40175
|
// src/execution/web-response.ts
|
|
40095
40176
|
import { createHash as createHash8 } from "node:crypto";
|
|
40096
40177
|
function acceptsResponse(status, contract) {
|
|
@@ -40281,7 +40362,7 @@ function decodeBody(result3, contract) {
|
|
|
40281
40362
|
try {
|
|
40282
40363
|
return JSON.parse(result3.rawText);
|
|
40283
40364
|
} catch {
|
|
40284
|
-
throw new ResponseContractFailure("The app returned non-JSON data for a JSON response contract");
|
|
40365
|
+
throw new ResponseContractFailure(responseFramingDescription(result3.rawText) ?? "The app returned non-JSON data for a JSON response contract");
|
|
40285
40366
|
}
|
|
40286
40367
|
}
|
|
40287
40368
|
async function continueResponse(initial, contract, send2, effect2, initialUrl, deadline = Date.now() + 2e4, onHop, completedUrls = []) {
|
|
@@ -40326,6 +40407,7 @@ var init_web_response = __esm({
|
|
|
40326
40407
|
init_file_artifacts();
|
|
40327
40408
|
init_slim();
|
|
40328
40409
|
init_definitions();
|
|
40410
|
+
init_response_framing();
|
|
40329
40411
|
init_html_secrets();
|
|
40330
40412
|
ResponseContractFailure = class extends Error {
|
|
40331
40413
|
};
|
|
@@ -40988,7 +41070,7 @@ function selectComparisonPointer(value, path2) {
|
|
|
40988
41070
|
if (path2 === "") return { found: true, value };
|
|
40989
41071
|
for (const raw of path2.slice(1).split("/")) {
|
|
40990
41072
|
const key2 = raw.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
40991
|
-
if (!
|
|
41073
|
+
if (!object5(value) && !Array.isArray(value) || !own2(value, key2) || Array.isArray(value) && !/^(?:0|[1-9][0-9]*)$/u.test(key2)) return { found: false };
|
|
40992
41074
|
value = value[key2];
|
|
40993
41075
|
}
|
|
40994
41076
|
return { found: true, value };
|
|
@@ -40999,18 +41081,18 @@ function differsOnlyInArrayOrder(left, right) {
|
|
|
40999
41081
|
if (--budget < 0 || depth > 64) return false;
|
|
41000
41082
|
if (isDeepStrictEqual(a, b)) return true;
|
|
41001
41083
|
if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && isDeepStrictEqual(a.map(canonicalJson).sort(), b.map(canonicalJson).sort());
|
|
41002
|
-
if (!
|
|
41084
|
+
if (!object5(a) || !object5(b) || Object.keys(a).length !== Object.keys(b).length) return false;
|
|
41003
41085
|
return Object.keys(a).every((key2) => own2(b, key2) && equivalent(a[key2], b[key2], depth + 1));
|
|
41004
41086
|
};
|
|
41005
41087
|
return equivalent(left, right, 0);
|
|
41006
41088
|
}
|
|
41007
41089
|
function parseExpectedResults(value) {
|
|
41008
41090
|
if (value === void 0) return { comparisons: [], issues: [] };
|
|
41009
|
-
if (!Array.isArray(value)) return { issues: [{ path:
|
|
41091
|
+
if (!Array.isArray(value)) return { issues: [{ path: prefix2, message: "Expected-result comparisons must be an array" }] };
|
|
41010
41092
|
const issues = [];
|
|
41011
41093
|
value.forEach((entry2, index2) => {
|
|
41012
|
-
const path2 = `${
|
|
41013
|
-
if (!
|
|
41094
|
+
const path2 = `${prefix2}/${index2}`;
|
|
41095
|
+
if (!object5(entry2)) {
|
|
41014
41096
|
issues.push({ path: path2, message: "Expected-result comparison must be an object" });
|
|
41015
41097
|
return;
|
|
41016
41098
|
}
|
|
@@ -41019,7 +41101,7 @@ function parseExpectedResults(value) {
|
|
|
41019
41101
|
if (entry2.unorderedAt !== void 0 && (!validPointer(entry2.unorderedAt) || entry2.unordered)) issues.push({ path: `${path2}/unorderedAt`, message: "Name one array within the selected value; do not combine unorderedAt with unordered" });
|
|
41020
41102
|
if (entry2.select !== void 0 && (!Array.isArray(entry2.select) || !entry2.select.length || entry2.select.length > 128 || !entry2.select.every(validPointer) || entry2.ignore !== void 0)) issues.push({ path: `${path2}/select`, message: "Select 1\u2013128 essential output paths relative to the comparison. Do not combine select and ignore" });
|
|
41021
41103
|
if (entry2.selectWhole !== void 0 && (entry2.selectWhole !== true || entry2.select === void 0)) issues.push({ path: `${path2}/selectWhole`, message: "Use selectWhole: true with select to compare the complete value at each selected path" });
|
|
41022
|
-
if (entry2.ignore !== void 0 && (!Array.isArray(entry2.ignore) || !entry2.ignore.length || entry2.ignore.length > 16 || entry2.ignore.some((item) => !
|
|
41104
|
+
if (entry2.ignore !== void 0 && (!Array.isArray(entry2.ignore) || !entry2.ignore.length || entry2.ignore.length > 16 || entry2.ignore.some((item) => !object5(item) || Object.keys(item).some((key2) => !["path", "reason"].includes(key2)) || !validPointer(item.path) || !item.path || item.path.endsWith("/*") || typeof item.reason !== "string" || item.reason.trim().length < 10 || item.reason.length > 600))) issues.push({ path: `${path2}/ignore`, message: "Declare at most 16 scalar field paths relative to the comparison, each with an evidence-based volatility reason; use * only for array members" });
|
|
41023
41105
|
if (!validPointer(entry2.path)) issues.push({ path: `${path2}/path`, message: "Use a JSON Pointer into the saved output" });
|
|
41024
41106
|
if (["value", "input", "file"].filter((key2) => own2(entry2, key2)).length !== 1) issues.push({ path: path2, message: "Choose exactly one expected source: value, input or file" });
|
|
41025
41107
|
if (own2(entry2, "value") && !json3(entry2.value)) issues.push({ path: `${path2}/value`, message: "Expected value must be JSON" });
|
|
@@ -41066,7 +41148,7 @@ function selectComparisonFields(value, paths2, selectWhole = false) {
|
|
|
41066
41148
|
});
|
|
41067
41149
|
return whole ? node2 : projected2;
|
|
41068
41150
|
}
|
|
41069
|
-
if (
|
|
41151
|
+
if (object5(node2)) {
|
|
41070
41152
|
const projected2 = Object.fromEntries([...children2].map(([key2, child2]) => {
|
|
41071
41153
|
const next2 = `${path2}/${escape5(key2)}`;
|
|
41072
41154
|
if (!own2(node2, key2)) throw new Error(`Essential comparison field is missing at ${next2}`);
|
|
@@ -41089,7 +41171,7 @@ function withoutVolatileFields(value, fields) {
|
|
|
41089
41171
|
if (!Array.isArray(node2)) throw new Error("Volatile field wildcard must select array members");
|
|
41090
41172
|
for (const item of node2) visit4(item, index2 + 1);
|
|
41091
41173
|
} else {
|
|
41092
|
-
if (!
|
|
41174
|
+
if (!object5(node2) && !Array.isArray(node2) || !Object.hasOwn(node2, key2)) throw new Error("Volatile field is missing; both responses must retain every declared field");
|
|
41093
41175
|
const parent2 = node2;
|
|
41094
41176
|
if (index2 === parts2.length - 1) {
|
|
41095
41177
|
if (Array.isArray(node2) || parent2[key2] !== null && typeof parent2[key2] === "object") throw new Error("Only scalar object fields can be excluded, never records, arrays or collection members");
|
|
@@ -41132,7 +41214,7 @@ function checkExpectedResults(output2, inputs, comparisons, resultPath) {
|
|
|
41132
41214
|
if (parsed.issues.length) return parsed.issues;
|
|
41133
41215
|
const issues = [];
|
|
41134
41216
|
for (const [index2, entry2] of parsed.comparisons.entries()) {
|
|
41135
|
-
const path2 = `${
|
|
41217
|
+
const path2 = `${prefix2}/${index2}`;
|
|
41136
41218
|
const actual = selectComparisonPointer(output2, entry2.path);
|
|
41137
41219
|
if (!actual.found) {
|
|
41138
41220
|
issues.push({ path: `${path2}/path`, message: "Expected-result path is missing from the saved output" });
|
|
@@ -41187,15 +41269,15 @@ function checkExpectedResults(output2, inputs, comparisons, resultPath) {
|
|
|
41187
41269
|
}
|
|
41188
41270
|
return issues;
|
|
41189
41271
|
}
|
|
41190
|
-
var
|
|
41272
|
+
var object5, own2, validPointer, prefix2, fileLimit, escape5;
|
|
41191
41273
|
var init_semantic_review = __esm({
|
|
41192
41274
|
"src/discovery/semantic-review.ts"() {
|
|
41193
41275
|
"use strict";
|
|
41194
41276
|
init_json();
|
|
41195
|
-
|
|
41277
|
+
object5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
41196
41278
|
own2 = (value, key2) => Object.hasOwn(value, key2);
|
|
41197
41279
|
validPointer = (value) => typeof value === "string" && (value === "" || value.startsWith("/") && !/~(?![01])/u.test(value));
|
|
41198
|
-
|
|
41280
|
+
prefix2 = "/verification/expect";
|
|
41199
41281
|
fileLimit = 2 * 1024 * 1024;
|
|
41200
41282
|
escape5 = (value) => value.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
41201
41283
|
}
|
|
@@ -41227,25 +41309,25 @@ function parseDraftEnvelope(source, legacy = false) {
|
|
|
41227
41309
|
const errors = [];
|
|
41228
41310
|
const value = parse4(source, errors, { allowTrailingComma: true, disallowComments: false });
|
|
41229
41311
|
for (const error62 of errors) issues.push({ path: `@${error62.offset}`, message: "Invalid JSONC syntax" });
|
|
41230
|
-
if (!
|
|
41231
|
-
if (issues.length || !
|
|
41312
|
+
if (!object6(value)) issues.push({ path: "/", message: "The draft must be a JSON object" });
|
|
41313
|
+
if (issues.length || !object6(value)) return { issues };
|
|
41232
41314
|
for (const key2 of Object.keys(value)) if (!names.has(key2)) issues.push({ path: `/${key2}`, message: "Unknown draft field" });
|
|
41233
|
-
if (!
|
|
41315
|
+
if (!object6(value.definition)) issues.push({ path: "/definition", message: "The published definition must be an object" });
|
|
41234
41316
|
if (legacy && !issues.length) return { envelope: value, issues };
|
|
41235
|
-
if (value.creation !== void 0 && !
|
|
41236
|
-
if (value.dependencies !== void 0 && !
|
|
41237
|
-
if (value.verification !== void 0 && !
|
|
41238
|
-
if (
|
|
41317
|
+
if (value.creation !== void 0 && !object6(value.creation)) issues.push({ path: "/creation", message: "Creation settings must be an object" });
|
|
41318
|
+
if (value.dependencies !== void 0 && !object6(value.dependencies)) issues.push({ path: "/dependencies", message: "Dependencies must be an object" });
|
|
41319
|
+
if (value.verification !== void 0 && !object6(value.verification)) issues.push({ path: "/verification", message: "Verification settings must be an object" });
|
|
41320
|
+
if (object6(value.verification)) {
|
|
41239
41321
|
const verification = value.verification;
|
|
41240
41322
|
issues.push(...unknownVerificationFields(verification, ["inputs", "probeOrigin", "review", "notes", "expect"]));
|
|
41241
|
-
if (verification.inputs !== void 0 && !
|
|
41323
|
+
if (verification.inputs !== void 0 && !object6(verification.inputs)) issues.push({ path: "/verification/inputs", message: "Verification inputs must be an object" });
|
|
41242
41324
|
if (verification.probeOrigin !== void 0 && typeof verification.probeOrigin !== "string") issues.push({ path: "/verification/probeOrigin", message: "Probe origin must be a string" });
|
|
41243
41325
|
if (verification.review !== void 0 && verification.review !== "pending" && verification.review !== "accepted" && verification.review !== "rejected") issues.push({ path: "/verification/review", message: "Choose pending, accepted or rejected" });
|
|
41244
41326
|
if (verification.notes !== void 0 && typeof verification.notes !== "string") issues.push({ path: "/verification/notes", message: "Verification notes must be a string" });
|
|
41245
41327
|
if (verification.expect !== void 0) issues.push(...parseExpectedResults(verification.expect).issues);
|
|
41246
41328
|
}
|
|
41247
|
-
if (value.capture !== void 0 && !
|
|
41248
|
-
if (
|
|
41329
|
+
if (value.capture !== void 0 && !object6(value.capture)) issues.push({ path: "/capture", message: "Capture settings must be an object" });
|
|
41330
|
+
if (object6(value.capture) && value.capture.tab !== void 0 && (typeof value.capture.tab !== "string" || value.capture.tab.length > 160)) issues.push({ path: "/capture/tab", message: "Use a tab selector returned by browser tabs, or leave it empty to use the session selection" });
|
|
41249
41331
|
if (issues.length) return { issues };
|
|
41250
41332
|
return { envelope: value, issues };
|
|
41251
41333
|
}
|
|
@@ -41314,7 +41396,7 @@ function draftTemplate(kind) {
|
|
|
41314
41396
|
return `${head}${metadataGuidance(kind)}${visibilityGuidance}${probeGuidance}${tabGuidance}${JSON.stringify(templates[kind], null, 2)}
|
|
41315
41397
|
`;
|
|
41316
41398
|
}
|
|
41317
|
-
var browserLocatorExample, names,
|
|
41399
|
+
var browserLocatorExample, names, object6, pointer4, browserIdentityGuidance;
|
|
41318
41400
|
var init_envelope = __esm({
|
|
41319
41401
|
"src/discovery/envelope.ts"() {
|
|
41320
41402
|
"use strict";
|
|
@@ -41323,7 +41405,7 @@ var init_envelope = __esm({
|
|
|
41323
41405
|
init_semantic_review();
|
|
41324
41406
|
browserLocatorExample = { inject: [{ from: { kind: "locator", in: "localStorage", key: "rivet_notes_session", prefix: "Bearer " }, to: { in: "header", name: "Authorization" } }] };
|
|
41325
41407
|
names = /* @__PURE__ */ new Set(["definition", "creation", "dependencies", "verification", "capture", "notes", "app", "appId", "kind", "name", "expectedVersion"]);
|
|
41326
|
-
|
|
41408
|
+
object6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
41327
41409
|
pointer4 = (parts2) => `/${parts2.map((part) => String(part).replaceAll("~", "~0").replaceAll("/", "~1")).join("/")}`;
|
|
41328
41410
|
browserIdentityGuidance = "Select documented or observed identity of the authenticated principal and applicable account, tenant or workspace. It must stay stable across task-resource changes. Record IDs, selected list positions and mutable content are not account identity. If unavailable, report the identity gap; never invent a selector.";
|
|
41329
41411
|
}
|
|
@@ -41366,8 +41448,8 @@ import { spawn } from "node:child_process";
|
|
|
41366
41448
|
function backgroundOptions(env) {
|
|
41367
41449
|
return { detached: true, windowsHide: true, stdio: "ignore", env };
|
|
41368
41450
|
}
|
|
41369
|
-
function startBackground(
|
|
41370
|
-
const child2 = spawn(process.execPath, [
|
|
41451
|
+
function startBackground(script, env, onError) {
|
|
41452
|
+
const child2 = spawn(process.execPath, [script], backgroundOptions(env));
|
|
41371
41453
|
child2.once("error", onError);
|
|
41372
41454
|
child2.unref();
|
|
41373
41455
|
return child2;
|
|
@@ -41467,9 +41549,9 @@ function nativeRestartVersion(root2) {
|
|
|
41467
41549
|
return null;
|
|
41468
41550
|
}
|
|
41469
41551
|
}
|
|
41470
|
-
function installedCaptureVersion(
|
|
41552
|
+
function installedCaptureVersion(script) {
|
|
41471
41553
|
try {
|
|
41472
|
-
const pkg = JSON.parse(readFileSync6(join9(dirname2(
|
|
41554
|
+
const pkg = JSON.parse(readFileSync6(join9(dirname2(script), "..", "package.json"), "utf8"));
|
|
41473
41555
|
return ["apilift", "@apilift/cli"].includes(String(pkg.name)) && typeof pkg.version === "string" && /^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?$/u.test(pkg.version) ? pkg.version : null;
|
|
41474
41556
|
} catch {
|
|
41475
41557
|
return null;
|
|
@@ -41693,18 +41775,18 @@ async function releaseStoppedCaptureForUse(state, sessionId, appId, client, sess
|
|
|
41693
41775
|
}
|
|
41694
41776
|
}
|
|
41695
41777
|
}
|
|
41696
|
-
async function checkTabOwnership(client, origin, tab, app2,
|
|
41778
|
+
async function checkTabOwnership(client, origin, tab, app2, prefix3, retry) {
|
|
41697
41779
|
const state = await client.scopes();
|
|
41698
41780
|
const active2 = state.scopes.filter((scope2) => scope2.pageOrigin === origin && scope2.kind !== "inspect");
|
|
41699
41781
|
const held = active2.find((scope2) => !scope2.tabSelector || scope2.tabSelector === tab);
|
|
41700
|
-
if (held && retry) throw new BrowserControlError(`The selected tab is busy with another worker's ${held.kind} command. Leave its tab open. Wait for that worker to finish, then retry ${retry}. To choose another existing signed-in tab, use ${
|
|
41782
|
+
if (held && retry) throw new BrowserControlError(`The selected tab is busy with another worker's ${held.kind} command. Leave its tab open. Wait for that worker to finish, then retry ${retry}. To choose another existing signed-in tab, use ${prefix3} browser tabs ${app2}, then ${prefix3} browser tabs ${app2} --select <returned-tab-id>`, "tab-owned");
|
|
41701
41783
|
if (held) {
|
|
41702
41784
|
const ownerLabel = held.ownerSession?.split(":label:")[1];
|
|
41703
41785
|
const settlement = held.kind === "capture" ? ownerLabel ? `Ask the owner to run apilift --session ${ownerLabel} discover capture stop or apilift --session ${ownerLabel} discover capture cancel` : "Ask the owning session to stop or cancel its recording" : "Wait for the owning command to finish or its lease to expire";
|
|
41704
41786
|
throw new BrowserControlError(`The selected tab has a live ${held.kind} lease${held.ownerSession ? ` owned by ${held.ownerSession}` : ""}, started ${new Date(held.activatedAt).toISOString()}, expires ${held.expiresAt}. ${settlement}; leave its tab open. For independent work, open another signed-in Chrome tab, start a distinct worker with apilift --session <new-worker-label> apps update ${app2}, list tabs with apilift --session <new-worker-label> browser tabs ${app2}, then bind a returned selector with apilift --session <new-worker-label> browser tabs ${app2} --select <returned-tab-id>. Capture and execution use that worker's selected tab`, "tab-owned");
|
|
41705
41787
|
}
|
|
41706
|
-
if (active2.length && !state.extensionCapabilities?.includes("tab-scopes-v1") && retry) throw new BrowserControlError(`Independent tabs require an updated browser bridge. Run ${
|
|
41707
|
-
if (active2.length && !state.extensionCapabilities?.includes("tab-scopes-v1")) throw new BrowserControlError(`The browser bridge has not advertised independent-tab support. Update the CLI with apilift update and Apilift Companion in Chrome. Leave the other session's tab open; after its command finishes, retry ${
|
|
41788
|
+
if (active2.length && !state.extensionCapabilities?.includes("tab-scopes-v1") && retry) throw new BrowserControlError(`Independent tabs require an updated browser bridge. Run ${prefix3} update; ask the user to update Apilift Companion. Leave other workers' tabs open. After their commands finish, retry ${retry}`, "extension-update-required");
|
|
41789
|
+
if (active2.length && !state.extensionCapabilities?.includes("tab-scopes-v1")) throw new BrowserControlError(`The browser bridge has not advertised independent-tab support. Update the CLI with apilift update and Apilift Companion in Chrome. Leave the other session's tab open; after its command finishes, retry ${prefix3} browser check ${app2} and your original command`, "extension-update-required");
|
|
41708
41790
|
}
|
|
41709
41791
|
async function browserContext(api, appId, initial) {
|
|
41710
41792
|
let app2 = initial ?? await api.call("getApp", { params: { app: appId } });
|
|
@@ -41735,12 +41817,12 @@ function captureServerScript(entry2 = process.argv[1]) {
|
|
|
41735
41817
|
}
|
|
41736
41818
|
async function captureClient(root2, requireBridge = true, timings) {
|
|
41737
41819
|
const startedAt = Date.now();
|
|
41738
|
-
const
|
|
41739
|
-
const client = await timed(timings, "brokerMs", () => ensureCaptureServer({ root: root2, script
|
|
41820
|
+
const script = process.env.APILIFT_CAPTURE_SERVER_SCRIPT ?? captureServerScript();
|
|
41821
|
+
const client = await timed(timings, "brokerMs", () => ensureCaptureServer({ root: root2, script, version: cliVersion }));
|
|
41740
41822
|
if (requireBridge && !client.legacyBridge) await timed(timings, "bridgeMs", () => waitForBridge(root2, cliVersion, Math.max(0, 9e4 - (Date.now() - startedAt)), () => client.bridgeDemand(), client.receipt.version));
|
|
41741
41823
|
return client;
|
|
41742
41824
|
}
|
|
41743
|
-
async function inspectTabs(client, appId, contextId, pageOrigin) {
|
|
41825
|
+
async function inspectTabs(client, appId, contextId, pageOrigin, prefix3 = "apilift") {
|
|
41744
41826
|
const scope2 = await client.openScope({ kind: "inspect", appId, contextId, pageOrigin, ownerPid: process.pid, ownerStartedAt: Date.now() - process.uptime() * 1e3 });
|
|
41745
41827
|
try {
|
|
41746
41828
|
const deadline = Date.now() + (client.legacyBridge ? 9e4 : 1e4);
|
|
@@ -41750,7 +41832,7 @@ async function inspectTabs(client, appId, contextId, pageOrigin) {
|
|
|
41750
41832
|
if (candidates.length || reported === true) return candidates;
|
|
41751
41833
|
if (Date.now() < deadline) await new Promise((resolve17) => setTimeout(resolve17, client.legacyBridge ? 250 : 10));
|
|
41752
41834
|
} while (Date.now() < deadline);
|
|
41753
|
-
|
|
41835
|
+
throw new BrowserControlError(`Companion did not report the Chrome tab inventory before the deadline. Recheck the browser connection: ${prefix3} setup continue`, "tab-inventory-unavailable");
|
|
41754
41836
|
} finally {
|
|
41755
41837
|
await client.closeScope(scope2.id);
|
|
41756
41838
|
}
|
|
@@ -41765,8 +41847,10 @@ async function handleBrowser(invocation, api, state, session, root2) {
|
|
|
41765
41847
|
let client;
|
|
41766
41848
|
try {
|
|
41767
41849
|
client = await captureClient(root2);
|
|
41768
|
-
candidates = await inspectTabs(client, app2.id, context.name, context.pageOrigin);
|
|
41850
|
+
candidates = await inspectTabs(client, app2.id, context.name, context.pageOrigin, command(invocation, "").trim());
|
|
41769
41851
|
} catch (error62) {
|
|
41852
|
+
if (error62 instanceof BrowserControlError && error62.code === "tab-inventory-unavailable") return fail(`${error62.code} \u2014 ${error62.message}. No app request was sent.
|
|
41853
|
+
`);
|
|
41770
41854
|
return fail(`extension-unavailable \u2014 ${error62 instanceof Error ? error62.message : "Chrome did not respond"}. Check native host and extension setup with ${command(invocation, "doctor")}.
|
|
41771
41855
|
`);
|
|
41772
41856
|
}
|
|
@@ -42329,20 +42413,20 @@ function bind(value, inputs, generated, output2, preserveEmptyObject = false, pr
|
|
|
42329
42413
|
return resolved;
|
|
42330
42414
|
});
|
|
42331
42415
|
if (typeof value === "object" && value !== null) {
|
|
42332
|
-
const
|
|
42333
|
-
if (!literalKeys && Object.keys(
|
|
42334
|
-
if (Object.hasOwn(
|
|
42335
|
-
if (Object.hasOwn(
|
|
42336
|
-
const resolved = bind(
|
|
42416
|
+
const object16 = value;
|
|
42417
|
+
if (!literalKeys && Object.keys(object16).length === 1) {
|
|
42418
|
+
if (Object.hasOwn(object16, "$object")) return bind(object16.$object, inputs, generated, output2, preserveEmptyObject, preparedValues, true);
|
|
42419
|
+
if (Object.hasOwn(object16, "$json")) {
|
|
42420
|
+
const resolved = bind(object16.$json, inputs, generated, output2, true, preparedValues);
|
|
42337
42421
|
return resolved === omit2 ? omit2 : JSON.stringify(resolved);
|
|
42338
42422
|
}
|
|
42339
|
-
if (typeof
|
|
42340
|
-
if (typeof
|
|
42341
|
-
if (typeof
|
|
42342
|
-
if (typeof
|
|
42423
|
+
if (typeof object16.$prepared === "string") return preparedValues === void 0 ? omit2 : pointer5(preparedValues, object16.$prepared);
|
|
42424
|
+
if (typeof object16.$input === "string") return Object.hasOwn(inputs, object16.$input) ? inputs[object16.$input] : omit2;
|
|
42425
|
+
if (typeof object16.$generated === "string") return generated[object16.$generated];
|
|
42426
|
+
if (typeof object16.$result === "string") return pointer5(output2, object16.$result);
|
|
42343
42427
|
}
|
|
42344
42428
|
const target = /* @__PURE__ */ Object.create(null);
|
|
42345
|
-
for (const [name, item] of Object.entries(
|
|
42429
|
+
for (const [name, item] of Object.entries(object16)) {
|
|
42346
42430
|
const resolved = bind(item, inputs, generated, output2, false, preparedValues);
|
|
42347
42431
|
if (resolved !== omit2) {
|
|
42348
42432
|
const key2 = name.replace(/\{(input|generated|result)\.([^{}]*)\}/gu, (_, kind, ref) => {
|
|
@@ -42354,7 +42438,7 @@ function bind(value, inputs, generated, output2, preserveEmptyObject = false, pr
|
|
|
42354
42438
|
target[key2] = resolved;
|
|
42355
42439
|
}
|
|
42356
42440
|
}
|
|
42357
|
-
if (!Object.keys(target).length && Object.keys(
|
|
42441
|
+
if (!Object.keys(target).length && Object.keys(object16).length && !preserveEmptyObject) return omit2;
|
|
42358
42442
|
return target;
|
|
42359
42443
|
}
|
|
42360
42444
|
if (typeof value === "string") return value.replace(/\{(input|generated|result)\.([^{}]*)\}/gu, (_, kind, ref) => {
|
|
@@ -42630,17 +42714,17 @@ async function send(fetcher, prepared, allowNonJsonProbe = false) {
|
|
|
42630
42714
|
async function sendBrowser(root2, appId, contextName, pageOrigin, effect2, transportName, transport, prepared, dispatched, credentialId, credentialDraftId, allowNonJsonProbe = false, dispatchBefore, selection = {}) {
|
|
42631
42715
|
if (prepared.inputUrl && prepared.url.origin !== pageOrigin && !prepared.anonymous) throw new Error("A cross-origin URL input requires anonymous: true");
|
|
42632
42716
|
const client = selection.client ?? await captureClient(root2, true, selection.timings);
|
|
42633
|
-
const app2 = selection.appSlug ?? appId,
|
|
42717
|
+
const app2 = selection.appSlug ?? appId, prefix3 = selection.prefix ?? "apilift";
|
|
42634
42718
|
let scope2 = selection.execution?.scope;
|
|
42635
42719
|
let tabSelector = selection.execution?.tabSelector ?? scope2?.tabSelector;
|
|
42636
42720
|
if (!scope2) {
|
|
42637
42721
|
const bindingStarted = performance.now();
|
|
42638
|
-
const candidates = await inspectTabs(client, appId, contextName, pageOrigin);
|
|
42722
|
+
const candidates = await inspectTabs(client, appId, contextName, pageOrigin, prefix3);
|
|
42639
42723
|
const tab = selection.tab ? candidates.find((candidate2) => candidate2.selector === selection.tab) : candidates.length === 1 ? candidates[0] : void 0;
|
|
42640
|
-
if (!tab && selection.retry) throw new BrowserControlError(candidates.length ? `No unambiguous current tab is selected. Run ${
|
|
42641
|
-
if (!tab) throw new BrowserControlError(selection.tab ? `Configured capture.tab is not present. Inspect ${
|
|
42724
|
+
if (!tab && selection.retry) throw new BrowserControlError(candidates.length ? `No unambiguous current tab is selected. Run ${prefix3} browser tabs ${app2}, then ${prefix3} browser tabs ${app2} --select <returned-tab-id>. Retry: ${selection.retry}` : `No matching Chrome tab was reported. Browser fallback: open ${selection.startUrl ?? pageOrigin} in the Chrome profile with Apilift Companion; ask the user to sign in if needed. Then retry: ${selection.retry}`, "tab-unselected");
|
|
42725
|
+
if (!tab) throw new BrowserControlError(selection.tab ? `Configured capture.tab is not present. Inspect ${prefix3} browser tabs ${app2} and select a reported tab in the current draft` : candidates.length ? `Several matching Chrome tabs were reported. Use ${prefix3} browser tabs ${app2} and set capture.tab in the current draft for both capture and execution; leave other sessions' tabs open` : `No matching Chrome tab was reported. Open ${pageOrigin} in the Chrome profile with Apilift Companion, then retry the probe with the same file`, "tab-unselected");
|
|
42642
42726
|
tabSelector = tab.selector;
|
|
42643
|
-
await checkTabOwnership(client, pageOrigin, tab.selector, app2,
|
|
42727
|
+
await checkTabOwnership(client, pageOrigin, tab.selector, app2, prefix3, selection.retry);
|
|
42644
42728
|
scope2 = await client.openScope({ kind: "execute", appId, contextId: contextName, pageOrigin, tabSelector: tab.selector, ownerPid: process.pid, ownerStartedAt: Date.now() - process.uptime() * 1e3, ownerSession: selection.ownerSession });
|
|
42645
42729
|
if (selection.execution) {
|
|
42646
42730
|
selection.execution.scope = scope2;
|
|
@@ -42673,18 +42757,20 @@ async function sendBrowser(root2, appId, contextName, pageOrigin, effect2, trans
|
|
|
42673
42757
|
dispatched(tabSelector);
|
|
42674
42758
|
await client.enqueueJob(scope2.id, envelope);
|
|
42675
42759
|
const deadline = prepared.appDeadline ?? Date.now() + 45e3;
|
|
42760
|
+
let lastStatus;
|
|
42676
42761
|
do {
|
|
42677
|
-
const held = await client.jobResult(id2, client.legacyBridge ? 0 : 1e3);
|
|
42762
|
+
const held = await client.jobResult(id2, client.legacyBridge ? 0 : Math.max(0, Math.min(1e3, deadline - Date.now())));
|
|
42763
|
+
lastStatus = held.status;
|
|
42678
42764
|
if (held.status === "delivered") {
|
|
42679
42765
|
await client.acknowledgeJob(id2);
|
|
42680
42766
|
const value = held.result;
|
|
42681
42767
|
if (value.transportError) {
|
|
42682
42768
|
if (value.executionState === "not-dispatched" && value.mutationDispatched !== true) {
|
|
42683
42769
|
let message2 = value.transportError.replace(/[.\s]+$/u, "");
|
|
42684
|
-
if (message2.includes("still recording") && selection.retry) message2 = `The selected tab is still recording. Leave other workers' tabs open. Wait for the recording to finish, or select another existing tab through ${
|
|
42770
|
+
if (message2.includes("still recording") && selection.retry) message2 = `The selected tab is still recording. Leave other workers' tabs open. Wait for the recording to finish, or select another existing tab through ${prefix3} browser tabs ${app2} and ${prefix3} browser tabs ${app2} --select <returned-tab-id>. Retry: ${selection.retry}`;
|
|
42685
42771
|
else if (message2.includes("still recording")) {
|
|
42686
42772
|
const peers = (await client.scopes()).scopes.filter((peer) => peer.kind !== "inspect" && peer.id !== scope2.id);
|
|
42687
|
-
message2 = peers.length ? `Chrome reports a recording on this tab. Inspect ${
|
|
42773
|
+
message2 = peers.length ? `Chrome reports a recording on this tab. Inspect ${prefix3} browser tabs ${app2}; ask the owning session to stop/cancel, or bind another signed-in tab with capture.tab` : `Chrome retained a stale recording after its recorder lease ended. No live recorder owns it. Open another signed-in Chrome tab, list it with ${prefix3} browser tabs ${app2}, bind its returned ID with ${prefix3} browser tabs ${app2} --select <returned-tab-id>, then retry your command. To recover the original tab, if no other agent is using Companion, turn Apilift Companion off and on in Chrome's Extensions page`;
|
|
42688
42774
|
}
|
|
42689
42775
|
throw new BrowserJobNotDispatched(message2, value.code ?? "browser-not-dispatched");
|
|
42690
42776
|
}
|
|
@@ -42718,9 +42804,10 @@ async function sendBrowser(root2, appId, contextName, pageOrigin, effect2, trans
|
|
|
42718
42804
|
return { response, body: decoded, ...retained ? { preparedFields: value.preparedFields } : {}, ...!allowNonJsonProbe ? { rawText: evidence ?? "" } : {}, finalUrl: typeof value.url === "string" ? value.url : prepared.url.href, redirected: value.redirected === true, ...value.profileId ? { profileId: value.profileId } : {} };
|
|
42719
42805
|
}
|
|
42720
42806
|
if (held.status === "uncertain") throw new Error("Chrome execution outcome is uncertain");
|
|
42721
|
-
|
|
42807
|
+
const delay = Math.min(client.legacyBridge ? 200 : 10, deadline - Date.now());
|
|
42808
|
+
if (delay > 0) await new Promise((resolve17) => setTimeout(resolve17, delay));
|
|
42722
42809
|
} while (Date.now() < deadline);
|
|
42723
|
-
throw new
|
|
42810
|
+
throw new BrowserJobDeadlineExceeded(lastStatus);
|
|
42724
42811
|
} finally {
|
|
42725
42812
|
if (selection.timings) selection.timings.replayMs += performance.now() - replayStarted;
|
|
42726
42813
|
if (!selection.execution) await client.closeScope(scope2.id);
|
|
@@ -42728,16 +42815,16 @@ async function sendBrowser(root2, appId, contextName, pageOrigin, effect2, trans
|
|
|
42728
42815
|
}
|
|
42729
42816
|
async function handleRun(invocation, api, state, session, fetcher, root2, stdin = () => readFileSync7(0, "utf8"), onReport) {
|
|
42730
42817
|
const [appName, actionName] = invocation.positionals;
|
|
42731
|
-
const
|
|
42818
|
+
const prefix3 = (suffix) => `apilift${invocation.sessionLabel ? ` --session ${invocation.sessionLabel}` : ""} ${suffix}`;
|
|
42732
42819
|
const operationId = invocation.operationId;
|
|
42733
42820
|
const testing = invocation.flags.includes("test");
|
|
42734
42821
|
if (operationId && invocation.flags.includes("check")) return failure2("operation-mutation-required", "operation-mutation-required \u2014 --operation-id applies to mutation execution. Remove --check or omit --operation-id. No app request was sent.\n");
|
|
42735
42822
|
if (!session) return fail2(`No stable agent identity is available. No app request was sent. Use apilift --session <worker-label> ${operationId ? `--operation-id ${operationId} ` : ""}run ${testing ? "--test " : ""}${appName} ${actionName} and keep the same label.
|
|
42736
42823
|
`);
|
|
42737
42824
|
const shell = (value) => /^[A-Za-z0-9_./:-]+$/u.test(value) ? value : `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
42738
|
-
const runPrefix = (suffix) =>
|
|
42825
|
+
const runPrefix = (suffix) => prefix3(`${operationId ? `--operation-id ${operationId} ` : ""}run ${testing ? "--test " : ""}${suffix}`);
|
|
42739
42826
|
let retry = runPrefix([...invocation.positionals, ...invocation.actionArgs, ...Object.entries(invocation.options).flatMap(([key2, value]) => [`--${key2}`, value]), ...invocation.flags.filter((flag) => flag !== "test").map((flag) => `--${flag}`), ...Object.entries(invocation.repeats).flatMap(([key2, values]) => values.flatMap((value) => [`--${key2}`, value]))].map(shell).join(" "));
|
|
42740
|
-
const readRecovery = `Do not repeat a possibly applied mutation. Find a published read: ${
|
|
42827
|
+
const readRecovery = `Do not repeat a possibly applied mutation. Find a published read: ${prefix3(`actions search ${appName} ${shell(actionName.split(".")[0])}`)}; inspect its inputs and use it to check the intended record. Use browser inspection only if published reads cannot resolve the outcome.
|
|
42741
42828
|
`;
|
|
42742
42829
|
const commandStarted = performance.now(), timings = executionTimings();
|
|
42743
42830
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -42759,7 +42846,7 @@ async function handleRun(invocation, api, state, session, fetcher, root2, stdin
|
|
|
42759
42846
|
fromJson = jsonInput(invocation.options.input, stdin);
|
|
42760
42847
|
} catch (error62) {
|
|
42761
42848
|
return failure2("invalid-input", `invalid-input \u2014 ${error62 instanceof Error ? error62.message : "Inputs are invalid"}. No app request was sent.
|
|
42762
|
-
Inspect the action: ${
|
|
42849
|
+
Inspect the action: ${prefix3(`actions show ${appName} ${actionName}`)}
|
|
42763
42850
|
`);
|
|
42764
42851
|
}
|
|
42765
42852
|
const installationAtStart = state.installation();
|
|
@@ -42811,7 +42898,7 @@ No app request was sent.
|
|
|
42811
42898
|
if (operationId && action.effect === "read") return failure2("operation-mutation-required", "operation-mutation-required \u2014 --operation-id applies to mutations. Omit it for reads. No app request was sent.\n");
|
|
42812
42899
|
if (action.effect !== "read" && !action.proof && action.verificationPolicy === void 0 && !usesBatchDiscovery(action)) return failure2("execution-bundle-invalid", "execution-bundle-invalid \u2014 A mutating action has no discovery proof specification. No app request was sent.\n", 5);
|
|
42813
42900
|
const selectedCredential = state.useSession(session.id, bundle2.app.id)?.credentials[action.transport];
|
|
42814
|
-
if (transport.credentials?.length && !selectedCredential && !(typeof action.request.url !== "string" && action.request.anonymous)) return fail2(`credential-required \u2014 ${actionName} needs a selected credential for ${action.transport}. Run ${
|
|
42901
|
+
if (transport.credentials?.length && !selectedCredential && !(typeof action.request.url !== "string" && action.request.anonymous)) return fail2(`credential-required \u2014 ${actionName} needs a selected credential for ${action.transport}. Run ${prefix3(`credentials list ${appName} ${action.transport}`)}, then credentials use or add. No app request was sent.
|
|
42815
42902
|
`, 5);
|
|
42816
42903
|
const connectBrowser = async () => {
|
|
42817
42904
|
if (!liveBrowser) {
|
|
@@ -42843,7 +42930,7 @@ No app request was sent.
|
|
|
42843
42930
|
inputs = effectiveInputs(action.inputs ?? { type: "object", properties: {}, additionalProperties: false }, explicit, state.useSession(session.id, bundle2.app.id)?.context ?? {}, invocation.flags.includes("no-context"));
|
|
42844
42931
|
} catch (error62) {
|
|
42845
42932
|
return failure2("invalid-input", `invalid-input \u2014 ${error62 instanceof Error ? error62.message : "Input contract changed"}. No app request was sent.
|
|
42846
|
-
Inspect current action documentation: ${
|
|
42933
|
+
Inspect current action documentation: ${prefix3(`actions show ${appName} ${actionName}`)}
|
|
42847
42934
|
`);
|
|
42848
42935
|
}
|
|
42849
42936
|
const generated = Object.fromEntries(Object.entries(action.generated ?? {}).map(([name, spec]) => [name, `${spec.prefix ?? ""}${randomUUID12()}`]));
|
|
@@ -42921,7 +43008,7 @@ Private historical result: ${error62.path}
|
|
|
42921
43008
|
if (transport.mode === "browser") {
|
|
42922
43009
|
const prior = dispatchedAt;
|
|
42923
43010
|
try {
|
|
42924
|
-
return await sendBrowser(root2, bundle2.app.id, transport.browserContext, browserPage.pageOrigin, effect2, action.transport, transport, request2, markPrimary, selectedCredential, void 0, false, bundle2.receipt?.dispatchBefore, { tab: operation2 ? selectedTab : state.browserTab(session.id, bundle2.app.id), appSlug: bundle2.app.slug, prefix:
|
|
43011
|
+
return await sendBrowser(root2, bundle2.app.id, transport.browserContext, browserPage.pageOrigin, effect2, action.transport, transport, request2, markPrimary, selectedCredential, void 0, false, bundle2.receipt?.dispatchBefore, { tab: operation2 ? selectedTab : state.browserTab(session.id, bundle2.app.id), appSlug: bundle2.app.slug, prefix: prefix3("").trim(), ownerSession: session.id, client: liveBrowser, timings, execution: browserExecution, retry, startUrl: browserPage?.startUrl, responseContract });
|
|
42925
43012
|
} catch (error62) {
|
|
42926
43013
|
if (error62 instanceof BrowserControlError && !error62.dispatched) {
|
|
42927
43014
|
if (prior) throw new BrowserControlError("The mutation was already dispatched; its browser readback could not run. Use a published read instead of rerunning the mutation", error62.code, true);
|
|
@@ -43028,7 +43115,7 @@ ${action.effect !== "read" && (primary.response.status >= 500 || operation2) ? r
|
|
|
43028
43115
|
evidence = "The rejected response could not be saved locally.\n";
|
|
43029
43116
|
}
|
|
43030
43117
|
}
|
|
43031
|
-
const exportDraft = observationSaved ? `Export the action with its observed result shape: ${
|
|
43118
|
+
const exportDraft = observationSaved ? `Export the action with its observed result shape: ${prefix3(`discover draft --app ${bundle2.app.slug} --include action:${actionName}`)}
|
|
43032
43119
|
` : "";
|
|
43033
43120
|
output2 = failure2("response-contract", `response-contract \u2014 ${actionName} was sent, but its response did not match the published contract. ${error62.message}
|
|
43034
43121
|
${evidence}${action.effect !== "read" ? readRecovery : exportDraft || "Inspect this saved case and the published result contract; unrelated cases remain callable.\n"}`, 12, true);
|
|
@@ -43040,15 +43127,18 @@ ${evidence}${action.effect !== "read" ? readRecovery : exportDraft || "Inspect t
|
|
|
43040
43127
|
outcome = "credential-error";
|
|
43041
43128
|
const status = dispatchedAt ? "The read did not return a usable result." : "No app request was sent.";
|
|
43042
43129
|
output2 = failure2("credential-unavailable", `credential-unavailable \u2014 ${error62.message}. ${status}
|
|
43043
|
-
Inspect saved entries: ${
|
|
43130
|
+
Inspect saved entries: ${prefix3(`credentials list ${appName} ${action.transport}`)}
|
|
43044
43131
|
`, 5, !!dispatchedAt);
|
|
43045
43132
|
}
|
|
43046
43133
|
} else {
|
|
43047
43134
|
outcome = dispatchedAt ? "uncertain" : "network-error";
|
|
43048
43135
|
const browserUnavailable = !dispatchedAt && ["extension-unavailable", "capture-server-unavailable", "native-host-upgrade-required"].includes(error62?.code ?? "");
|
|
43049
|
-
if (!dispatchedAt && error62 instanceof BrowserControlError && !error62.dispatched && ["tab-unselected", "extension-upgrade-required"].includes(error62.code)) {
|
|
43136
|
+
if (!dispatchedAt && error62 instanceof BrowserControlError && !error62.dispatched && ["tab-unselected", "tab-inventory-unavailable", "extension-upgrade-required"].includes(error62.code)) {
|
|
43050
43137
|
output2 = failure2(error62.code, `${error62.code} \u2014 ${error62.message.replace(/; no app request was sent$/u, "")}. No app request was sent.
|
|
43051
43138
|
`, 5);
|
|
43139
|
+
} else if (error62 instanceof BrowserJobDeadlineExceeded) {
|
|
43140
|
+
const next2 = action.effect === "read" ? "The read did not return a usable result.\n" : dispatchedAt ? `The request may have reached the app. ${readRecovery}` : "No target mutation was sent.\n";
|
|
43141
|
+
output2 = failure2(error62.code, `app-request-uncertain \u2014 ${error62.message}. ${next2}`, 5, !!dispatchedAt);
|
|
43052
43142
|
} else {
|
|
43053
43143
|
output2 = browserUnavailable ? failure2("browser-transport-unavailable", `browser-transport-unavailable \u2014 ${error62 instanceof Error ? error62.message : "The browser connection did not respond"}. No app request was sent.
|
|
43054
43144
|
`, 5) : failure2("app-request-uncertain", `app-request-uncertain \u2014 ${error62 instanceof Error ? error62.message : "The request did not return"}. ${dispatchedAt ? action.effect !== "read" ? `The request may have reached the app. ${readRecovery}` : "The read did not return a usable result." : "No app request was sent."}
|
|
@@ -43109,9 +43199,9 @@ Inspect saved entries: ${prefix2(`credentials list ${appName} ${action.transport
|
|
|
43109
43199
|
`, 12, true), ...saved2 ? {} : { stdout: completeResult, stdoutJson: true } };
|
|
43110
43200
|
}
|
|
43111
43201
|
}
|
|
43112
|
-
if (bundle2.selection.fallback && !["prefer-verified", "pinned-selection"].includes(bundle2.selection.replaced?.reason ?? "")) output2.stderr += `Using a previously working revision (${bundle2.selection.replaced?.reason ?? "compatible-fallback"}). Selection recovers automatically when an eligible revision is available.${bundle2.selection.replaced?.until ? ` Protective pause ends ${bundle2.selection.replaced.until}.` : ""} Inspect distribution with ${
|
|
43202
|
+
if (bundle2.selection.fallback && !["prefer-verified", "pinned-selection"].includes(bundle2.selection.replaced?.reason ?? "")) output2.stderr += `Using a previously working revision (${bundle2.selection.replaced?.reason ?? "compatible-fallback"}). Selection recovers automatically when an eligible revision is available.${bundle2.selection.replaced?.until ? ` Protective pause ends ${bundle2.selection.replaced.until}.` : ""} Inspect distribution with ${prefix3(`apps history ${appName}`)}.
|
|
43113
43203
|
`;
|
|
43114
|
-
if (!testing && dispatchedAt && bundle2.suggestTest) output2.stderr += `For future tests of your published action, use ${
|
|
43204
|
+
if (!testing && dispatchedAt && bundle2.suggestTest) output2.stderr += `For future tests of your published action, use ${prefix3(`run --test ${bundle2.app.slug} ${actionName}`)} to keep tests out of usage.
|
|
43115
43205
|
`;
|
|
43116
43206
|
if (runPurpose) output2.analytics = { ...output2.analytics, purpose: runPurpose };
|
|
43117
43207
|
output2.analytics = { ...output2.analytics, app_id: bundle2.app.id, action_id: actionName, action_version: actionVersion.version, transport: transport.mode, fallback: !!bundle2.selection.fallback, ...Object.fromEntries(Object.entries(timings).map(([key2, value]) => [key2.replace(/Ms$/u, "_ms").replace(/[A-Z]/gu, (c) => `_${c.toLowerCase()}`), Math.round(value)])), ...httpStatus !== void 0 ? { http_status: httpStatus } : {} };
|
|
@@ -43411,7 +43501,7 @@ async function executeDraftVerification(input2) {
|
|
|
43411
43501
|
});
|
|
43412
43502
|
}
|
|
43413
43503
|
}
|
|
43414
|
-
var import__4, import_ajv_formats2, ajv3, result, fail2, failure2, ExecutionAuthorizationExpired, BrowserJobNotDispatched, omit2;
|
|
43504
|
+
var import__4, import_ajv_formats2, ajv3, result, fail2, failure2, ExecutionAuthorizationExpired, BrowserJobNotDispatched, BrowserJobDeadlineExceeded, omit2;
|
|
43415
43505
|
var init_run = __esm({
|
|
43416
43506
|
"src/commands/run.ts"() {
|
|
43417
43507
|
"use strict";
|
|
@@ -43448,6 +43538,13 @@ var init_run = __esm({
|
|
|
43448
43538
|
};
|
|
43449
43539
|
BrowserJobNotDispatched = class extends BrowserControlError {
|
|
43450
43540
|
};
|
|
43541
|
+
BrowserJobDeadlineExceeded = class extends Error {
|
|
43542
|
+
code;
|
|
43543
|
+
constructor(lastStatus) {
|
|
43544
|
+
super(lastStatus === "queued" ? "The browser job was still queued at the last check before the deadline" : lastStatus === "dispatched" ? "The broker released the job for browser execution but no result arrived before the deadline" : "Chrome did not return a result before the deadline");
|
|
43545
|
+
this.code = lastStatus === "queued" ? "browser-job-queue-timeout" : "browser-job-result-timeout";
|
|
43546
|
+
}
|
|
43547
|
+
};
|
|
43451
43548
|
omit2 = Symbol("omit");
|
|
43452
43549
|
}
|
|
43453
43550
|
});
|
|
@@ -43507,17 +43604,17 @@ ${formatContext(app2.title, context)}`);
|
|
|
43507
43604
|
`;
|
|
43508
43605
|
}
|
|
43509
43606
|
if (invocation.key !== "contextShow") state.saveUseSession({ ...existing, context });
|
|
43510
|
-
const
|
|
43607
|
+
const prefix3 = (suffix) => command2(invocation.sessionLabel, suffix);
|
|
43511
43608
|
if (invocation.key === "contextSet") return ok2(`${first2}${formatContext(app2.title, context)}
|
|
43512
43609
|
Every ${app2.title} action declaring ${name} uses this value when that input is
|
|
43513
43610
|
omitted. An explicit --${name.replaceAll("_", "-")} overrides it for one call without changing it.
|
|
43514
43611
|
The value stays in this agent's app session until changed, cleared or released;
|
|
43515
43612
|
choosing a different credential also clears it. No app request was sent.
|
|
43516
43613
|
|
|
43517
|
-
Replace it: ${
|
|
43518
|
-
Remove it: ${
|
|
43519
|
-
Clear all: ${
|
|
43520
|
-
Inspect all: ${
|
|
43614
|
+
Replace it: ${prefix3(`context set ${name} <different-id>`)}
|
|
43615
|
+
Remove it: ${prefix3(`context unset ${name}`)}
|
|
43616
|
+
Clear all: ${prefix3("context clear")}
|
|
43617
|
+
Inspect all: ${prefix3("context show")}
|
|
43521
43618
|
Use --app <app> to address another app's context. Values never cross apps.
|
|
43522
43619
|
Pass values directly as arguments; quote spaces. No JSON/file input is supported.
|
|
43523
43620
|
Each action parses a saved value like its own scalar command flag; objects and
|
|
@@ -43525,25 +43622,25 @@ arrays must be passed directly to run, not saved in context.
|
|
|
43525
43622
|
`);
|
|
43526
43623
|
if (invocation.key === "contextUnset") return ok2(`${first2}${formatContext(app2.title, context)}
|
|
43527
43624
|
Actions requiring ${name} now need an explicit value or a new saved value.
|
|
43528
|
-
Set one with: ${
|
|
43625
|
+
Set one with: ${prefix3(`context set ${name} <chosen-id>`)}
|
|
43529
43626
|
No record inside ${app2.title} was changed.
|
|
43530
43627
|
`);
|
|
43531
43628
|
if (invocation.key === "contextClear") return ok2(`${first2}${formatContext(app2.title, context)}
|
|
43532
43629
|
Future calls use explicit inputs and the action's own defaults.
|
|
43533
|
-
Save a value: ${
|
|
43630
|
+
Save a value: ${prefix3("context set <name> <value>")}
|
|
43534
43631
|
Close the app session and clear credential selections too:
|
|
43535
|
-
${
|
|
43632
|
+
${prefix3(`apps release ${app2.slug}`)}
|
|
43536
43633
|
`);
|
|
43537
43634
|
return ok2(`${formatContext(app2.title, context)}
|
|
43538
43635
|
Values supply matching omitted inputs on every ${app2.title} action in this session.
|
|
43539
43636
|
They do not apply to other apps. Explicit action arguments override one call.
|
|
43540
43637
|
|
|
43541
|
-
Set or replace: ${
|
|
43542
|
-
Remove one: ${
|
|
43543
|
-
Clear all: ${
|
|
43638
|
+
Set or replace: ${prefix3("context set <name> <value>")}
|
|
43639
|
+
Remove one: ${prefix3("context unset <name>")}
|
|
43640
|
+
Clear all: ${prefix3("context clear")}
|
|
43544
43641
|
Use --app <app> on a context command to select another app.
|
|
43545
43642
|
Preview a specific action's resolved inputs without sending a request:
|
|
43546
|
-
${
|
|
43643
|
+
${prefix3(`run ${app2.slug} <action-name> <required-flags> --check`)}
|
|
43547
43644
|
`);
|
|
43548
43645
|
}
|
|
43549
43646
|
function propertyLines(schema, context, sessionLabel) {
|
|
@@ -43644,10 +43741,10 @@ ${lines.join("\n")}${lines.length ? "\n" : ""}}
|
|
|
43644
43741
|
}
|
|
43645
43742
|
async function handleCatalog(invocation, api, state, session) {
|
|
43646
43743
|
const [appName, second] = invocation.positionals;
|
|
43647
|
-
const
|
|
43744
|
+
const prefix3 = (suffix) => command2(invocation.sessionLabel, suffix);
|
|
43648
43745
|
if (invocation.key === "appsSearch") {
|
|
43649
43746
|
const query = appName.trim();
|
|
43650
|
-
if (!query) return fail3(`Enter an app name or website host, for example: ${
|
|
43747
|
+
if (!query) return fail3(`Enter an app name or website host, for example: ${prefix3('apps search "<app name>"')}
|
|
43651
43748
|
`);
|
|
43652
43749
|
const limit = numberOption(invocation.options.limit, 10, 50);
|
|
43653
43750
|
if (!limit) return fail3("--limit must be an integer from 1 to 50.\n");
|
|
@@ -43658,10 +43755,10 @@ async function handleCatalog(invocation, api, state, session) {
|
|
|
43658
43755
|
${app2.actionCount} published actions. Your access is checked when you select an action.
|
|
43659
43756
|
|
|
43660
43757
|
Open this app to see its requirements and how to find an action:
|
|
43661
|
-
${
|
|
43758
|
+
${prefix3(`apps use ${app2.slug}`)}`).join("\n\n");
|
|
43662
43759
|
const next2 = page2.nextCursor ? `
|
|
43663
43760
|
More matching apps remain. Continue with the exact cursor returned here:
|
|
43664
|
-
${
|
|
43761
|
+
${prefix3(`apps search ${quote(query)}${invocation.options.domain ? ` --domain ${invocation.options.domain}` : ""} --limit ${limit} --cursor ${page2.nextCursor}`)}
|
|
43665
43762
|
Keep the same query and domain filter. A page does not describe the entire catalog.
|
|
43666
43763
|
` : "";
|
|
43667
43764
|
const exampleHost = page2.items[0] ? new URL(page2.items[0].origin).host : "<host>";
|
|
@@ -43671,16 +43768,16 @@ ${cards}
|
|
|
43671
43768
|
${next2}
|
|
43672
43769
|
If this is not the app you meant, search again with its name or website.
|
|
43673
43770
|
If your app has no matching entry, create its interface:
|
|
43674
|
-
${
|
|
43771
|
+
${prefix3("apps new <app-slug>")}
|
|
43675
43772
|
|
|
43676
43773
|
An app slug is the short name you will use in commands, such as ${page2.items[0].slug}.
|
|
43677
43774
|
|
|
43678
43775
|
To narrow results by the app website, add --domain <host>, for example:
|
|
43679
|
-
${
|
|
43776
|
+
${prefix3(`apps search ${quote(query)} --domain ${exampleHost}`)}
|
|
43680
43777
|
Choose page size with --limit <number> (default 10; maximum 50).
|
|
43681
43778
|
` : `No accessible app matched ${quote(query)}. This search does not prove the app is unavailable.
|
|
43682
43779
|
Try its website host or create its interface:
|
|
43683
|
-
${
|
|
43780
|
+
${prefix3("apps new <app-slug>")}
|
|
43684
43781
|
`);
|
|
43685
43782
|
}
|
|
43686
43783
|
if (invocation.key === "appsUse") {
|
|
@@ -43698,16 +43795,16 @@ Choose a unique worker label and keep it on every command:
|
|
|
43698
43795
|
return ok2(`${app2.title} (${app2.visibility}) \u2014 ${app2.origin}
|
|
43699
43796
|
${app2.actionCount} published actions; access is checked per action. Connections are resolved by run.
|
|
43700
43797
|
${page2.items.map((item) => ` ${item.name} \u2014 ${item.title} (${item.availability === "unavailable" ? "unavailable" : item.effect ?? "action"}; ${item.policy})${item.summary && item.summary !== item.title ? `: ${item.summary}` : ""}`).join("\n")}
|
|
43701
|
-
${page2.nextCursor ? `More actions: ${
|
|
43798
|
+
${page2.nextCursor ? `More actions: ${prefix3(`actions list ${app2.slug} --limit 8 --cursor ${page2.nextCursor}`)}
|
|
43702
43799
|
` : ""}
|
|
43703
|
-
Inspect arguments and run syntax: ${
|
|
43704
|
-
Search names/titles: ${
|
|
43705
|
-
${formatContext(app2.title, context)}Set a recurring scalar: ${
|
|
43706
|
-
Inspect: ${
|
|
43800
|
+
Inspect arguments and run syntax: ${prefix3(`actions show ${app2.slug} ${page2.items[0]?.name ?? "<action>"}`)}
|
|
43801
|
+
Search names/titles: ${prefix3(`actions search ${app2.slug} "<keyword>"`)}
|
|
43802
|
+
${formatContext(app2.title, context)}Set a recurring scalar: ${prefix3("context set <name> <value>")}; explicit flags override it.
|
|
43803
|
+
Inspect: ${prefix3("context show")}; remove one: ${prefix3("context unset <name>")}; clear: ${prefix3("context clear")}.
|
|
43707
43804
|
Values persist across requests; credential changes clear them. Reopening resumes the session.
|
|
43708
|
-
Credentials: ${
|
|
43709
|
-
Missing coverage: ${
|
|
43710
|
-
Finish: ${
|
|
43805
|
+
Credentials: ${prefix3(`credentials list ${app2.slug}`)}; connection instructions: ${prefix3(`transports show ${app2.slug}`)}.
|
|
43806
|
+
Missing coverage: ${prefix3(`apps update ${app2.slug}`)}.
|
|
43807
|
+
Finish: ${prefix3(`apps release ${app2.slug}`)} clears defaults and credential selections, keeping saved secrets.
|
|
43711
43808
|
`);
|
|
43712
43809
|
}
|
|
43713
43810
|
if (invocation.key === "appsRelease") {
|
|
@@ -43720,7 +43817,7 @@ Finish: ${prefix2(`apps release ${app2.slug}`)} clears defaults and credential s
|
|
|
43720
43817
|
const released = await api.call("releaseSession", { params: { id: apiSessionId(installation.id, session) }, query: { appId: app2.id, purpose: "execution" } });
|
|
43721
43818
|
if (released.released !== true) throw new Error("Release not confirmed");
|
|
43722
43819
|
} catch {
|
|
43723
|
-
return fail3(`session-release-unconfirmed \u2014 Server release was not confirmed. Local state was retained. Retry: ${
|
|
43820
|
+
return fail3(`session-release-unconfirmed \u2014 Server release was not confirmed. Local state was retained. Retry: ${prefix3(`apps release ${app2.slug}`)}
|
|
43724
43821
|
`, 5);
|
|
43725
43822
|
}
|
|
43726
43823
|
state.releaseUseSession(session.id, app2.id);
|
|
@@ -43731,11 +43828,11 @@ The saved credentials themselves remain in the secure store.
|
|
|
43731
43828
|
Other agents' sessions and published action definitions were not changed.
|
|
43732
43829
|
|
|
43733
43830
|
To start working with ${app2.title} again:
|
|
43734
|
-
${
|
|
43831
|
+
${prefix3(`apps use ${app2.slug}`)}
|
|
43735
43832
|
`);
|
|
43736
43833
|
}
|
|
43737
43834
|
if (invocation.key === "appsRefresh") return ok2(`No cached app documentation is currently retained for ${appName}; the next selected read will fetch current documentation.
|
|
43738
|
-
Inspect it: ${
|
|
43835
|
+
Inspect it: ${prefix3(`actions show ${appName} ${invocation.options.action ?? "<action-name>"}`)}
|
|
43739
43836
|
`);
|
|
43740
43837
|
if (invocation.key.startsWith("context")) {
|
|
43741
43838
|
if (!session) return fail3(`No stable agent identity is available. No session state was changed.
|
|
@@ -43743,8 +43840,8 @@ Choose --session <worker-label> and keep it on every command.
|
|
|
43743
43840
|
`);
|
|
43744
43841
|
const app2 = await appForContext(invocation, session, state, api);
|
|
43745
43842
|
if (!app2) return fail3(`No app session is active, so no input value was saved.
|
|
43746
|
-
Choose the app first: ${
|
|
43747
|
-
Or address it explicitly: ${
|
|
43843
|
+
Choose the app first: ${prefix3("apps use <app>")}
|
|
43844
|
+
Or address it explicitly: ${prefix3("context set <name> <value> --app <app>")}
|
|
43748
43845
|
`);
|
|
43749
43846
|
return contextCommands(app2, invocation, state);
|
|
43750
43847
|
}
|
|
@@ -43776,7 +43873,7 @@ Or address it explicitly: ${prefix2("context set <name> <value> --app <app>")}
|
|
|
43776
43873
|
return complete ? ok2(`Saved the complete accessible action index (${rows.length} actions) to ${file3}.
|
|
43777
43874
|
Search this file with ordinary file tools. No app request was sent.
|
|
43778
43875
|
`) : { stdout: "", stderr: `Action index collection is incomplete. ${rows.length} actions were saved to ${file3}.
|
|
43779
|
-
${cursor ? `Continue listing with: ${
|
|
43876
|
+
${cursor ? `Continue listing with: ${prefix3(`actions list ${appName} --limit 100 --cursor ${cursor}`)}
|
|
43780
43877
|
` : "Retry listing when the registry is available.\n"}`, exitCode: 5 };
|
|
43781
43878
|
}
|
|
43782
43879
|
const page2 = await api.call("listActions", { params: { app: appName }, query: { q: search ? second : void 0, entity: invocation.options.entity, limit, cursor: invocation.options.cursor } });
|
|
@@ -43785,34 +43882,34 @@ ${cursor ? `Continue listing with: ${prefix2(`actions list ${appName} --limit 10
|
|
|
43785
43882
|
const suffix = search ? `actions search ${appName} ${quote(second)}` : `actions list ${appName}`;
|
|
43786
43883
|
const next2 = page2.nextCursor ? search ? `
|
|
43787
43884
|
More matching actions remain:
|
|
43788
|
-
${
|
|
43885
|
+
${prefix3(`${suffix}${invocation.options.entity ? ` --entity ${invocation.options.entity}` : ""} --limit ${limit} --cursor ${page2.nextCursor}`)}
|
|
43789
43886
|
Keep the query and any --entity filter. To page an unfiltered action list instead,
|
|
43790
43887
|
use the continuation returned by actions list; cursors are not interchangeable.
|
|
43791
43888
|
` : `
|
|
43792
43889
|
More actions remain${invocation.options.entity ? ` in ${invocation.options.entity}` : ""}:
|
|
43793
|
-
${
|
|
43890
|
+
${prefix3(`${suffix}${invocation.options.entity ? ` --entity ${invocation.options.entity}` : ""} --limit ${limit} --cursor ${page2.nextCursor}`)}
|
|
43794
43891
|
To collect the complete ${invocation.options.entity ? "group" : "index"} into a local file instead:
|
|
43795
|
-
${
|
|
43892
|
+
${prefix3(`actions list ${appName}${invocation.options.entity ? ` --entity ${invocation.options.entity}` : ""} --all`)}
|
|
43796
43893
|
` : "";
|
|
43797
43894
|
if (search) return ok2(page2.items.length ? `Found ${page2.items.length} action${page2.items.length === 1 ? "" : "s"} matching ${quote(second)}.
|
|
43798
43895
|
|
|
43799
43896
|
${list}
|
|
43800
43897
|
|
|
43801
43898
|
Read the complete arguments, input sources and execution example:
|
|
43802
|
-
${
|
|
43899
|
+
${prefix3(`actions show ${appName} ${page2.items[0].name}`)}
|
|
43803
43900
|
|
|
43804
43901
|
This search did not call the app or list any actual records.
|
|
43805
43902
|
|
|
43806
43903
|
Search matches names and titles, not natural-language intent. Try a shorter term
|
|
43807
43904
|
if nothing fits, or browse the published names:
|
|
43808
|
-
${
|
|
43905
|
+
${prefix3(`actions list ${appName}`)}
|
|
43809
43906
|
Limit to a known group with --entity <group-name>.
|
|
43810
43907
|
Choose page size with --limit <number> (default 8; maximum 25).
|
|
43811
43908
|
${next2}` : `No accessible action name or title matched ${quote(second)}.
|
|
43812
43909
|
This does not prove the app cannot perform it. Inspect published action names:
|
|
43813
|
-
${
|
|
43910
|
+
${prefix3(`actions list ${appName}`)}
|
|
43814
43911
|
If the operation is missing, investigate it:
|
|
43815
|
-
${
|
|
43912
|
+
${prefix3(`apps update ${appName}`)}
|
|
43816
43913
|
`);
|
|
43817
43914
|
return ok2(page2.items.length ? `${page2.items.length} action${page2.items.length === 1 ? "" : "s"}${invocation.options.entity ? ` in the ${invocation.options.entity} group` : ""}. ${page2.nextCursor ? "This is one page of the list." : invocation.options.entity ? "This is the complete list for that group." : "This is the complete list."}
|
|
43818
43915
|
|
|
@@ -43820,20 +43917,20 @@ ${list}
|
|
|
43820
43917
|
|
|
43821
43918
|
These are action names, not commands to run on their own.
|
|
43822
43919
|
Inspect one to see its required inputs and execution command:
|
|
43823
|
-
${
|
|
43920
|
+
${prefix3(`actions show ${appName} ${page2.items[0].name}`)}
|
|
43824
43921
|
|
|
43825
43922
|
To search names and titles across all action groups:
|
|
43826
|
-
${
|
|
43923
|
+
${prefix3(`actions search ${appName} "<keyword>"`)}
|
|
43827
43924
|
|
|
43828
43925
|
Inspect several named actions together by appending their names:
|
|
43829
|
-
${
|
|
43926
|
+
${prefix3(`actions show ${appName} ${page2.items.map((item) => item.name).slice(0, 2).join(" ")}`)}
|
|
43830
43927
|
List another group with --entity <group-name>; omit it to list all groups.
|
|
43831
43928
|
Choose page size with --limit <number> (default 50; maximum 100).
|
|
43832
43929
|
For an explicit complete index, save all accessible pages locally:
|
|
43833
|
-
${
|
|
43930
|
+
${prefix3(`actions list ${appName} --all`)}
|
|
43834
43931
|
The response gives the file path and reports whether collection completed.
|
|
43835
43932
|
${next2}` : `No published actions are visible in this selection.
|
|
43836
|
-
If the interface needs an operation: ${
|
|
43933
|
+
If the interface needs an operation: ${prefix3(`apps update ${appName}`)}
|
|
43837
43934
|
`);
|
|
43838
43935
|
}
|
|
43839
43936
|
if (invocation.key === "actionsShow") {
|
|
@@ -43847,7 +43944,7 @@ If the interface needs an operation: ${prefix2(`apps update ${appName}`)}
|
|
|
43847
43944
|
const path2 = resolve7(invocation.options["input-template"]);
|
|
43848
43945
|
writeFileSync7(path2, inputTemplate(docs[0].inputs), { flag: "wx", mode: 384 });
|
|
43849
43946
|
return ok2(`Wrote an editable input template to ${path2}. Replace examples with real values before running:
|
|
43850
|
-
${
|
|
43947
|
+
${prefix3(`run ${appName} ${names3[0]} --input @${path2} --check`)}
|
|
43851
43948
|
`);
|
|
43852
43949
|
}
|
|
43853
43950
|
const context = await savedContextForApp(api, state, session, appName);
|
|
@@ -43855,7 +43952,7 @@ If the interface needs an operation: ${prefix2(`apps update ${appName}`)}
|
|
|
43855
43952
|
if (doc.availability === "unavailable") return `${doc.name} \u2014 ${doc.title}
|
|
43856
43953
|
${doc.description}
|
|
43857
43954
|
Unavailable: ${doc.unavailable?.reason ?? "No executable definition"}. ${doc.unavailable?.evidence ?? ""}
|
|
43858
|
-
Investigate: ${
|
|
43955
|
+
Investigate: ${prefix3(`apps update ${appName}`)}
|
|
43859
43956
|
`;
|
|
43860
43957
|
const inputs = propertyLines(doc.inputs, context, invocation.sessionLabel);
|
|
43861
43958
|
const flags = inputs.runArgs;
|
|
@@ -43871,7 +43968,7 @@ ${inputs.optional.join("\n")}
|
|
|
43871
43968
|
` : ""}Returned JSON contract
|
|
43872
43969
|
${outputLines(doc.output)}${doc.observedOutput ? `Descriptive fields (not guaranteed):
|
|
43873
43970
|
${outputLines(doc.observedOutput, false)}` : ""}${doc.verificationScope ? `Discovery scope: ${JSON.stringify(doc.verificationScope)}
|
|
43874
|
-
` : ""}Run: ${
|
|
43971
|
+
` : ""}Run: ${prefix3(`${operation2}run ${appName} ${doc.name}${flags}`)}
|
|
43875
43972
|
`;
|
|
43876
43973
|
});
|
|
43877
43974
|
const executable = docs.filter((doc) => doc.availability === "executable");
|
|
@@ -43888,15 +43985,15 @@ Connections and credentials are resolved before dispatch; run returns any requir
|
|
|
43888
43985
|
${operationGuidance}${hasInputs ? `${inputExample(schemaProperties(inputDoc.inputs))} --input @./input.json reads JSON/JSONC; --input - reads stdin. Do not duplicate inputs between JSON and flags.
|
|
43889
43986
|
Booleans take true/false; null is allowed only by the input schema.
|
|
43890
43987
|
--check previews effective inputs and sources without an app request.
|
|
43891
|
-
${hasScalar ? ` Save a recurring scalar: ${
|
|
43892
|
-
${
|
|
43988
|
+
${hasScalar ? ` Save a recurring scalar: ${prefix3("context set <name> <value>")}. Explicit flags override saved values.
|
|
43989
|
+
${prefix3("context show")}; ${prefix3("context unset <name>")}; ${prefix3("context clear")}.
|
|
43893
43990
|
--no-context ignores saved values; action defaults still apply. Values are app/session-local and cleared on credential changes.
|
|
43894
|
-
` : ""} Input template: ${
|
|
43991
|
+
` : ""} Input template: ${prefix3(`actions show ${appName} ${inputDoc.name} --input-template ./input.jsonc`)}
|
|
43895
43992
|
` : ""} --output ./result.json saves this invocation's complete result.
|
|
43896
43993
|
${selectable ? ` --select ${shellArgument(selectable.pointer)} selects that field of ${selectable.doc}; repeat --select for more fields. JSON Pointers refer to returned JSON.
|
|
43897
43994
|
` : ""}${paginated.length ? ` Pagination (${paginated.join(", ")}): nextCursor may indicate another page. Follow the navigation inputs documented above; --select retains nextCursor, and --output saves only fetched pages.
|
|
43898
|
-
` : ""} Schemas: ${
|
|
43899
|
-
Stale docs: ${
|
|
43995
|
+
` : ""} Schemas: ${prefix3(`actions show ${appName} ${names3.join(" ")} --schema`)}
|
|
43996
|
+
Stale docs: ${prefix3(`apps refresh ${appName} --action ${sample.name}`)}, then inspect again.
|
|
43900
43997
|
` : ""}`);
|
|
43901
43998
|
}
|
|
43902
43999
|
return fail3(`No catalog handler for ${invocation.key}.
|
|
@@ -43928,9 +44025,9 @@ async function connectionRevisionConflict(api, appId, name, transport) {
|
|
|
43928
44025
|
if (!("revision" in published) || !published.revision?.credentialContractHash || published.revision.credentialContractHash === await hashJson(credentialContractKey(transport))) return null;
|
|
43929
44026
|
return published.revision.canRecreate ? "unused-connection" : "used-connection";
|
|
43930
44027
|
}
|
|
43931
|
-
function connectionRevisionRecovery(conflict, name,
|
|
43932
|
-
if (conflict === "used-connection") return `Published action history still needs this connection's credential contract. Keep it unchanged, or create a distinct connection with ${
|
|
43933
|
-
return `To replace this unused connection, keep the edited file, then ${
|
|
44028
|
+
function connectionRevisionRecovery(conflict, name, prefix3, appSlug) {
|
|
44029
|
+
if (conflict === "used-connection") return `Published action history still needs this connection's credential contract. Keep it unchanged, or create a distinct connection with ${prefix3} discover draft transport <new-name> --app ${appSlug} --out connection.jsonc.`;
|
|
44030
|
+
return `To replace this unused connection, keep the edited file, then ${prefix3} discover remove transport ${name} --app ${appSlug} --out removal.jsonc and ${prefix3} discover publish removal.jsonc. Generate a new file with ${prefix3} discover draft transport ${name} --app ${appSlug} --out connection.jsonc, restore the corrected definition, then ${prefix3} credentials add ${appSlug} ${name} --file connection.jsonc for secure setup. Existing saved entries are not rebound.`;
|
|
43934
44031
|
}
|
|
43935
44032
|
var init_connection_revision = __esm({
|
|
43936
44033
|
"src/discovery/connection-revision.ts"() {
|
|
@@ -44474,8 +44571,10 @@ function draftCapturedAction(item, name, transport, protectedFields, candidates
|
|
|
44474
44571
|
const observedSchema = publicShape(result3, samples);
|
|
44475
44572
|
response = { schema: typeof observedSchema.type === "string" ? { type: observedSchema.type } : unknownType(), ...Object.keys(observedSchema).length ? { observedSchema } : {} };
|
|
44476
44573
|
} else {
|
|
44477
|
-
const
|
|
44478
|
-
|
|
44574
|
+
const framing = typeof entry2.resBody === "string" ? responseFramingDescription(entry2.resBody) : void 0;
|
|
44575
|
+
const file3 = framing ? void 0 : wholeResponseContract(entry2);
|
|
44576
|
+
if (framing) review("/response", framing);
|
|
44577
|
+
else if (!file3 && entry2.resBodyState !== "absent") review("/response", "Review the retained response and declare its output format");
|
|
44479
44578
|
response = file3 ?? { schema: unknownType() };
|
|
44480
44579
|
}
|
|
44481
44580
|
}
|
|
@@ -44500,6 +44599,7 @@ var init_batch_capture = __esm({
|
|
|
44500
44599
|
"use strict";
|
|
44501
44600
|
init_definitions();
|
|
44502
44601
|
init_capture_derivation();
|
|
44602
|
+
init_response_framing();
|
|
44503
44603
|
init_capture_form();
|
|
44504
44604
|
init_batch_draft();
|
|
44505
44605
|
init_observed_shape();
|
|
@@ -44846,17 +44946,17 @@ var init_legacy_capture_import = __esm({
|
|
|
44846
44946
|
|
|
44847
44947
|
// src/discovery/api-collection.ts
|
|
44848
44948
|
function responseGuards(definition2) {
|
|
44849
|
-
const response = definition2.response, root2 =
|
|
44850
|
-
if (!
|
|
44949
|
+
const response = definition2.response, root2 = object7(response) ? response.schema : void 0;
|
|
44950
|
+
if (!object7(root2)) throw Error("Collection guarantees require a documented response schema");
|
|
44851
44951
|
let budget = 1e4;
|
|
44852
44952
|
const nodes = (raw, seen = /* @__PURE__ */ new Set()) => {
|
|
44853
44953
|
if (--budget < 0) throw Error("Collection schema traversal exceeds its bound");
|
|
44854
|
-
if (!
|
|
44954
|
+
if (!object7(raw) || seen.has(raw) || seen.size > 64) return [];
|
|
44855
44955
|
const next2 = new Set(seen).add(raw), result3 = [raw];
|
|
44856
44956
|
if (typeof raw.$ref === "string") {
|
|
44857
44957
|
if (!raw.$ref.startsWith("#/")) throw Error("Collection fields need local schema references");
|
|
44858
44958
|
let target = root2;
|
|
44859
|
-
for (const key2 of parts(raw.$ref.slice(1))) target =
|
|
44959
|
+
for (const key2 of parts(raw.$ref.slice(1))) target = object7(target) ? target[key2] : void 0;
|
|
44860
44960
|
result3.push(...nodes(target, next2));
|
|
44861
44961
|
}
|
|
44862
44962
|
for (const key2 of ["oneOf", "anyOf", "allOf"]) if (Array.isArray(raw[key2])) for (const branch of raw[key2]) result3.push(...nodes(branch, next2));
|
|
@@ -44864,7 +44964,7 @@ function responseGuards(definition2) {
|
|
|
44864
44964
|
};
|
|
44865
44965
|
const targets = (segments) => {
|
|
44866
44966
|
let current = nodes(root2);
|
|
44867
|
-
for (const key2 of segments) current = current.flatMap((node2) => key2 === "*" ? nodes(node2.items) :
|
|
44967
|
+
for (const key2 of segments) current = current.flatMap((node2) => key2 === "*" ? nodes(node2.items) : object7(node2.properties) && Object.hasOwn(node2.properties, key2) ? nodes(node2.properties[key2]) : []);
|
|
44868
44968
|
if (!current.length) throw Error(`Collection guarantee names an undocumented result path: /${segments.join("/")}`);
|
|
44869
44969
|
return current;
|
|
44870
44970
|
};
|
|
@@ -44885,13 +44985,13 @@ function compileRequiredOutputs(definition2, paths2) {
|
|
|
44885
44985
|
}
|
|
44886
44986
|
}
|
|
44887
44987
|
function compileCollection(definition2, raw) {
|
|
44888
|
-
if (!
|
|
44988
|
+
if (!object7(raw) || Object.keys(raw).some((key2) => !["path", "identity", "requiredFields", "optionalFields", "completePresence", "completeEnvelope", "optionalOutputs", "pagination", "projection", "ordering", "order"].includes(key2))) throw Error("collection accepts path, identity, requiredFields, optionalFields, completePresence, completeEnvelope, optionalOutputs, pagination, projection, ordering and order");
|
|
44889
44989
|
if (raw.order !== void 0 && !["significant", "unspecified"].includes(String(raw.order))) throw Error("collection.order is significant or unspecified");
|
|
44890
|
-
if (raw.order === "unspecified" && (raw.ordering !== void 0 ||
|
|
44990
|
+
if (raw.order === "unspecified" && (raw.ordering !== void 0 || object7(raw.pagination) && ["page", "offset", "limit", "pages"].some((key2) => raw.pagination && Object.hasOwn(raw.pagination, key2)))) throw Error("Sorted or paginated collections retain significant order");
|
|
44891
44991
|
const path2 = parts(raw.path), identity3 = raw.identity === void 0 ? void 0 : parts(raw.identity);
|
|
44892
44992
|
if (identity3 && !identity3.length) throw Error("Collection identity must name a field within each record");
|
|
44893
44993
|
const pagination = raw.pagination ?? {};
|
|
44894
|
-
if (!
|
|
44994
|
+
if (!object7(pagination) || Object.keys(pagination).some((key2) => !["total", "page", "limit", "offset", "pages"].includes(key2))) throw Error("pagination maps total/page/limit/offset/pages to result paths");
|
|
44895
44995
|
const { root: root2, targets, guard } = responseGuards(definition2);
|
|
44896
44996
|
const guards = [];
|
|
44897
44997
|
if (!targets(path2).some((node2) => node2.type === "array" || Array.isArray(node2.type) && node2.type.includes("array") || node2.items !== void 0)) throw Error("Collection path must select a documented array");
|
|
@@ -44905,7 +45005,7 @@ function compileCollection(definition2, raw) {
|
|
|
44905
45005
|
if (raw.requiredFields === "all") {
|
|
44906
45006
|
const optional2 = raw.optionalFields ?? [];
|
|
44907
45007
|
if (!Array.isArray(optional2) || optional2.some((x2) => typeof x2 !== "string" || parts(x2).length !== 1)) throw Error("optionalFields names direct record fields excluded from requiredFields: all");
|
|
44908
|
-
const fields = new Set(targets([...path2, "*"]).flatMap((node2) =>
|
|
45008
|
+
const fields = new Set(targets([...path2, "*"]).flatMap((node2) => object7(node2.properties) ? Object.keys(node2.properties) : []));
|
|
44909
45009
|
if (!fields.size) throw Error("requiredFields: all needs documented record properties");
|
|
44910
45010
|
for (const field of optional2) if (!fields.has(parts(field)[0])) throw Error(`Unknown optional record field: ${field}`);
|
|
44911
45011
|
requiredFields = [...fields].map((key2) => "/" + key2.replaceAll("~", "~0").replaceAll("/", "~1")).filter((key2) => !optional2.includes(key2));
|
|
@@ -44924,7 +45024,7 @@ function compileCollection(definition2, raw) {
|
|
|
44924
45024
|
const optional2 = raw.optionalFields ?? [];
|
|
44925
45025
|
if (!Array.isArray(optional2) || optional2.some((x2) => typeof x2 !== "string" || parts(x2).length !== 1)) throw Error("optionalFields lists optional direct record fields");
|
|
44926
45026
|
const records = targets([...path2, "*"]);
|
|
44927
|
-
const fields = new Set(records.flatMap((node2) =>
|
|
45027
|
+
const fields = new Set(records.flatMap((node2) => object7(node2.properties) ? Object.keys(node2.properties) : []));
|
|
44928
45028
|
const required2 = /* @__PURE__ */ new Set([...requiredFields.map((x2) => parts(x2)[0]), ...records.flatMap((node2) => Array.isArray(node2.required) ? node2.required : []), ...identity3 ? [identity3[0]] : []]);
|
|
44929
45029
|
for (const field of optional2) {
|
|
44930
45030
|
const key2 = parts(field)[0];
|
|
@@ -44935,27 +45035,27 @@ function compileCollection(definition2, raw) {
|
|
|
44935
45035
|
}
|
|
44936
45036
|
const meanings = { total: "Total matching records.", page: "Current page number.", limit: "Page size reported by the app.", offset: "Number of matching records skipped.", pages: "Total pages reported by the app." };
|
|
44937
45037
|
for (const [name, value] of Object.entries(pagination)) {
|
|
44938
|
-
const mapping =
|
|
45038
|
+
const mapping = object7(value) ? value : { path: value };
|
|
44939
45039
|
if (Object.keys(mapping).some((k) => !["path", "input"].includes(k))) throw Error("Pagination values accept a result path or {path,input}");
|
|
44940
45040
|
const segments = parts(mapping.path);
|
|
44941
45041
|
if (!segments.length) throw Error("Pagination values must name fields within the response");
|
|
44942
45042
|
targets(segments);
|
|
44943
45043
|
guards.push(guard(segments, { description: meanings[name] }));
|
|
44944
45044
|
if (mapping.input !== void 0 && mapping.input !== null) {
|
|
44945
|
-
const inputs = definition2.inputs, field =
|
|
44946
|
-
if (typeof mapping.input !== "string" || !
|
|
44947
|
-
const mandatory =
|
|
45045
|
+
const inputs = definition2.inputs, field = object7(inputs) && object7(inputs.properties) ? inputs.properties[String(mapping.input)] : void 0;
|
|
45046
|
+
if (typeof mapping.input !== "string" || !object7(field)) throw Error("Pagination input must name a selected argument, or null for no caller control");
|
|
45047
|
+
const mandatory = object7(inputs) && Array.isArray(inputs.required) && inputs.required.includes(mapping.input);
|
|
44948
45048
|
field.description = [field.description, mandatory ? "" : `Omit to use the app's default ${name}; the response reports the value at ${String(mapping.path)}.`].filter(Boolean).join(" ");
|
|
44949
45049
|
}
|
|
44950
45050
|
}
|
|
44951
45051
|
if (raw.projection !== void 0) {
|
|
44952
45052
|
const projection = typeof raw.projection === "string" ? { input: raw.projection } : raw.projection;
|
|
44953
|
-
if (!
|
|
44954
|
-
const inputs = definition2.inputs, field =
|
|
44955
|
-
if (!
|
|
45053
|
+
if (!object7(projection) || typeof projection.input !== "string" || !identity3 || Object.keys(projection).some((k) => !["input", "format", "empty", "extras", "notes"].includes(k))) throw Error("projection names input, format, empty behavior, optional extras/notes and requires record identity");
|
|
45054
|
+
const inputs = definition2.inputs, field = object7(inputs) && object7(inputs.properties) ? inputs.properties[projection.input] : void 0;
|
|
45055
|
+
if (!object7(field)) throw Error("projection must name an existing selected input");
|
|
44956
45056
|
if (projection.format !== void 0) {
|
|
44957
45057
|
if (!["comma", "array"].includes(String(projection.format)) || !["default", "none", "unsupported"].includes(String(projection.empty))) throw Error("projection needs format comma/array and empty behavior default/none/unsupported");
|
|
44958
|
-
const required2 =
|
|
45058
|
+
const required2 = object7(inputs) && Array.isArray(inputs.required) && inputs.required.includes(projection.input);
|
|
44959
45059
|
const extras = projection.extras ?? [];
|
|
44960
45060
|
if (!Array.isArray(extras) || extras.some((x2) => typeof x2 !== "string")) throw Error("Projection extras must name relative record paths");
|
|
44961
45061
|
for (const extra of extras) targets([...path2, "*", ...parts(extra)]);
|
|
@@ -44965,7 +45065,7 @@ function compileCollection(definition2, raw) {
|
|
|
44965
45065
|
const note = `The app retains record identity ${String(raw.identity)} even when it is not selected. Callers do not need to add it to the projection.`;
|
|
44966
45066
|
field.description = [field.description, note].filter(Boolean).join(" ");
|
|
44967
45067
|
}
|
|
44968
|
-
const detail = [`Returned collection: ${raw.path === "" ? "the root array" : String(raw.path)}.`, ...identity3 ? [`Every record includes identity ${String(raw.identity)}.`] : [], ...requiredFields.length ? [`Every record includes ${requiredFields.join(", ")}; nullable values remain distinct from omitted fields.`] : [], ...Object.entries(pagination).map(([name, value]) => `Required ${String(
|
|
45068
|
+
const detail = [`Returned collection: ${raw.path === "" ? "the root array" : String(raw.path)}.`, ...identity3 ? [`Every record includes identity ${String(raw.identity)}.`] : [], ...requiredFields.length ? [`Every record includes ${requiredFields.join(", ")}; nullable values remain distinct from omitted fields.`] : [], ...Object.entries(pagination).map(([name, value]) => `Required ${String(object7(value) ? value.path : value)}: ${meanings[name]}`)].join(" ");
|
|
44969
45069
|
definition2.details = [definition2.details, detail, raw.order === "unspecified" ? "Record order is unspecified; do not depend on catalogue position." : ""].filter(Boolean).join("\n\n");
|
|
44970
45070
|
root2.allOf = [...Array.isArray(root2.allOf) ? root2.allOf : [], ...guards];
|
|
44971
45071
|
if (raw.completeEnvelope) {
|
|
@@ -44974,7 +45074,7 @@ function compileCollection(definition2, raw) {
|
|
|
44974
45074
|
const siblings2 = [], missing2 = [];
|
|
44975
45075
|
for (let level = 0; level < path2.length; level++) {
|
|
44976
45076
|
const parent2 = path2.slice(0, level);
|
|
44977
|
-
const fields = new Set(targets(parent2).flatMap((node2) =>
|
|
45077
|
+
const fields = new Set(targets(parent2).flatMap((node2) => object7(node2.properties) ? Object.keys(node2.properties) : []));
|
|
44978
45078
|
for (const field of fields) if (field !== path2[level]) {
|
|
44979
45079
|
const segments = [...parent2, field], pointer9 = "/" + segments.map((key2) => key2.replaceAll("~", "~0").replaceAll("/", "~1")).join("/");
|
|
44980
45080
|
siblings2.push(pointer9);
|
|
@@ -44990,27 +45090,27 @@ function compileCollection(definition2, raw) {
|
|
|
44990
45090
|
pointer8(path2),
|
|
44991
45091
|
...identity3 ? [pointer8([...path2, "*", ...identity3])] : [],
|
|
44992
45092
|
...requiredFields.map((field) => pointer8([...path2, "*", ...parts(field)])),
|
|
44993
|
-
...Object.values(pagination).map((value) => pointer8(parts(
|
|
45093
|
+
...Object.values(pagination).map((value) => pointer8(parts(object7(value) ? value.path : value)))
|
|
44994
45094
|
])];
|
|
44995
45095
|
}
|
|
44996
45096
|
function guaranteesPath(node2, path2, root2, seen = /* @__PURE__ */ new Set()) {
|
|
44997
45097
|
if (!path2.length) return true;
|
|
44998
|
-
if (!
|
|
45098
|
+
if (!object7(node2) || seen.has(node2) || seen.size > 64) return false;
|
|
44999
45099
|
const next2 = new Set(seen).add(node2);
|
|
45000
|
-
if (Array.isArray(node2.required) && node2.required.includes(path2[0]) &&
|
|
45100
|
+
if (Array.isArray(node2.required) && node2.required.includes(path2[0]) && object7(node2.properties) && guaranteesPath(node2.properties[path2[0]], path2.slice(1), root2, next2)) return true;
|
|
45001
45101
|
if (typeof node2.$ref === "string" && node2.$ref.startsWith("#/")) {
|
|
45002
45102
|
let target = root2;
|
|
45003
|
-
for (const key2 of parts(node2.$ref.slice(1))) target =
|
|
45103
|
+
for (const key2 of parts(node2.$ref.slice(1))) target = object7(target) ? target[key2] : void 0;
|
|
45004
45104
|
if (guaranteesPath(target, path2, root2, next2)) return true;
|
|
45005
45105
|
}
|
|
45006
45106
|
if (Array.isArray(node2.allOf) && node2.allOf.some((branch) => guaranteesPath(branch, path2, root2, next2))) return true;
|
|
45007
45107
|
return ["anyOf", "oneOf"].some((key2) => Array.isArray(node2[key2]) && node2[key2].length > 0 && node2[key2].every((branch) => guaranteesPath(branch, path2, root2, next2)));
|
|
45008
45108
|
}
|
|
45009
|
-
var
|
|
45109
|
+
var object7, parts;
|
|
45010
45110
|
var init_api_collection = __esm({
|
|
45011
45111
|
"src/discovery/api-collection.ts"() {
|
|
45012
45112
|
"use strict";
|
|
45013
|
-
|
|
45113
|
+
object7 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
45014
45114
|
parts = (path2) => {
|
|
45015
45115
|
if (typeof path2 !== "string" || path2 !== "" && !path2.startsWith("/") || /~(?![01])/u.test(String(path2))) throw Error("Collection paths must be result JSON Pointers");
|
|
45016
45116
|
const result3 = path2 === "" ? [] : path2.slice(1).split("/").map((key2) => key2.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
@@ -45022,7 +45122,7 @@ var init_api_collection = __esm({
|
|
|
45022
45122
|
|
|
45023
45123
|
// src/discovery/api-examples.ts
|
|
45024
45124
|
function normalizeImportedExamples(root2) {
|
|
45025
|
-
if (!
|
|
45125
|
+
if (!object8(root2)) return;
|
|
45026
45126
|
const ajv4 = new import__5.default({ strict: false, validateFormats: true });
|
|
45027
45127
|
(0, import_ajv_formats3.default)(ajv4);
|
|
45028
45128
|
let budget = 3e4;
|
|
@@ -45036,42 +45136,42 @@ function normalizeImportedExamples(root2) {
|
|
|
45036
45136
|
}
|
|
45037
45137
|
};
|
|
45038
45138
|
const visit4 = (node2, depth) => {
|
|
45039
|
-
if (!
|
|
45139
|
+
if (!object8(node2) || depth > 64 || --budget < 0) return;
|
|
45040
45140
|
if (Array.isArray(node2.examples)) try {
|
|
45041
|
-
const validate2 = ajv4.compile({ ...
|
|
45141
|
+
const validate2 = ajv4.compile({ ...object8(root2.$defs) ? { $defs: root2.$defs } : {}, ...node2 });
|
|
45042
45142
|
node2.examples = node2.examples.map((value) => validate2(value) ? value : validate2(typed(value)) ? typed(value) : value);
|
|
45043
45143
|
} catch {
|
|
45044
45144
|
}
|
|
45045
|
-
for (const keyword of ["properties", "$defs", "definitions", "patternProperties", "dependentSchemas"]) if (
|
|
45145
|
+
for (const keyword of ["properties", "$defs", "definitions", "patternProperties", "dependentSchemas"]) if (object8(node2[keyword])) Object.values(node2[keyword]).forEach((child2) => visit4(child2, depth + 1));
|
|
45046
45146
|
for (const keyword of ["items", "additionalProperties", "contains", "not", "if", "then", "else"]) visit4(node2[keyword], depth + 1);
|
|
45047
45147
|
for (const keyword of ["allOf", "anyOf", "oneOf", "prefixItems"]) if (Array.isArray(node2[keyword])) node2[keyword].forEach((child2) => visit4(child2, depth + 1));
|
|
45048
45148
|
};
|
|
45049
45149
|
visit4(root2, 0);
|
|
45050
45150
|
}
|
|
45051
45151
|
function retainCompatibleExamples(previous, replacement, root2) {
|
|
45052
|
-
if (!
|
|
45152
|
+
if (!object8(previous) || !Array.isArray(previous.examples) || replacement.examples !== void 0) return;
|
|
45053
45153
|
try {
|
|
45054
45154
|
const ajv4 = new import__5.default({ strict: false, validateFormats: true });
|
|
45055
45155
|
(0, import_ajv_formats3.default)(ajv4);
|
|
45056
|
-
const validate2 = ajv4.compile({ ...
|
|
45156
|
+
const validate2 = ajv4.compile({ ...object8(root2.$defs) ? { $defs: root2.$defs } : {}, ...object8(root2.definitions) ? { definitions: root2.definitions } : {}, ...replacement });
|
|
45057
45157
|
const examples = previous.examples.filter((value) => validate2(value));
|
|
45058
45158
|
if (examples.length) replacement.examples = structuredClone(examples);
|
|
45059
45159
|
} catch {
|
|
45060
45160
|
}
|
|
45061
45161
|
}
|
|
45062
|
-
var import__5, import_ajv_formats3,
|
|
45162
|
+
var import__5, import_ajv_formats3, object8;
|
|
45063
45163
|
var init_api_examples = __esm({
|
|
45064
45164
|
"src/discovery/api-examples.ts"() {
|
|
45065
45165
|
"use strict";
|
|
45066
45166
|
import__5 = __toESM(require__(), 1);
|
|
45067
45167
|
import_ajv_formats3 = __toESM(require_dist(), 1);
|
|
45068
|
-
|
|
45168
|
+
object8 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
45069
45169
|
}
|
|
45070
45170
|
});
|
|
45071
45171
|
|
|
45072
45172
|
// src/discovery/api-fields.ts
|
|
45073
45173
|
function pruneUnusedSharedTypes(root2, injected) {
|
|
45074
|
-
if (!
|
|
45174
|
+
if (!object9(root2.$defs) || !injected.length) return;
|
|
45075
45175
|
const definitions = root2.$defs, candidates = new Set(injected), used = /* @__PURE__ */ new Set();
|
|
45076
45176
|
let budget = 3e4, ambiguous = false;
|
|
45077
45177
|
const visit4 = (value, depth = 0) => {
|
|
@@ -45083,7 +45183,7 @@ function pruneUnusedSharedTypes(root2, injected) {
|
|
|
45083
45183
|
value.forEach((child2) => visit4(child2, depth + 1));
|
|
45084
45184
|
return;
|
|
45085
45185
|
}
|
|
45086
|
-
if (!
|
|
45186
|
+
if (!object9(value)) return;
|
|
45087
45187
|
if (value.$id || value.$dynamicRef || value.$recursiveRef || value.$anchor || value.$dynamicAnchor) ambiguous = true;
|
|
45088
45188
|
if (typeof value.$ref === "string") {
|
|
45089
45189
|
if (!value.$ref.startsWith("#/")) ambiguous = true;
|
|
@@ -45108,7 +45208,7 @@ function pruneUnusedSharedTypes(root2, injected) {
|
|
|
45108
45208
|
if (!Object.keys(definitions).length) delete root2.$defs;
|
|
45109
45209
|
}
|
|
45110
45210
|
function patchResponseFields(root2, fields) {
|
|
45111
|
-
if (!
|
|
45211
|
+
if (!object9(root2) || !object9(fields) || Object.keys(fields).length > 128) throw Error("outputFields requires a response schema and at most 128 result-path schema corrections");
|
|
45112
45212
|
const resolve17 = (value) => {
|
|
45113
45213
|
const seen = /* @__PURE__ */ new Set();
|
|
45114
45214
|
while (typeof value.$ref === "string") {
|
|
@@ -45116,31 +45216,31 @@ function patchResponseFields(root2, fields) {
|
|
|
45116
45216
|
if (!ref.startsWith("#/") || seen.has(ref)) throw Error("Output field correction needs an acyclic local schema reference");
|
|
45117
45217
|
seen.add(ref);
|
|
45118
45218
|
let target = root2;
|
|
45119
|
-
for (const segment of ref.slice(2).split("/").map((s) => s.replaceAll("~1", "/").replaceAll("~0", "~"))) target =
|
|
45120
|
-
if (!
|
|
45219
|
+
for (const segment of ref.slice(2).split("/").map((s) => s.replaceAll("~1", "/").replaceAll("~0", "~"))) target = object9(target) && Object.hasOwn(target, segment) ? target[segment] : void 0;
|
|
45220
|
+
if (!object9(target)) throw Error(`Output field schema reference is unavailable: ${ref}`);
|
|
45121
45221
|
value = target;
|
|
45122
45222
|
}
|
|
45123
45223
|
return value;
|
|
45124
45224
|
};
|
|
45125
45225
|
const merge3 = (node2, correction) => {
|
|
45126
45226
|
for (const [key2, value] of Object.entries(correction)) {
|
|
45127
|
-
if (["properties", "$defs", "definitions"].includes(key2) &&
|
|
45227
|
+
if (["properties", "$defs", "definitions"].includes(key2) && object9(node2[key2]) && object9(value)) {
|
|
45128
45228
|
const target = node2[key2];
|
|
45129
45229
|
for (const [name, schema] of Object.entries(value)) {
|
|
45130
|
-
if (Object.hasOwn(target, name) &&
|
|
45230
|
+
if (Object.hasOwn(target, name) && object9(target[name]) && object9(schema)) merge3(target[name], schema);
|
|
45131
45231
|
else assign(target, name, structuredClone(schema));
|
|
45132
45232
|
}
|
|
45133
45233
|
} else assign(node2, key2, structuredClone(value));
|
|
45134
45234
|
}
|
|
45135
45235
|
};
|
|
45136
45236
|
for (const [path2, correction] of Object.entries(fields)) {
|
|
45137
|
-
if (!path2.startsWith("/") || /~(?![01])/u.test(path2) || !
|
|
45237
|
+
if (!path2.startsWith("/") || /~(?![01])/u.test(path2) || !object9(correction)) throw Error("outputFields maps non-root result JSON Pointers to schema objects; use * for array members");
|
|
45138
45238
|
const parts2 = path2.slice(1).split("/").map((s) => s.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
45139
45239
|
let budget = 1e4, matches = 0;
|
|
45140
45240
|
const active2 = /* @__PURE__ */ new Map();
|
|
45141
45241
|
const visit4 = (raw, index2) => {
|
|
45142
45242
|
if (--budget < 0 || index2 > 64) throw Error(`Output field correction exceeds traversal limits: ${path2}`);
|
|
45143
|
-
if (!
|
|
45243
|
+
if (!object9(raw)) return;
|
|
45144
45244
|
const node2 = resolve17(raw), positions = active2.get(node2) ?? /* @__PURE__ */ new Set();
|
|
45145
45245
|
if (positions.has(index2)) return;
|
|
45146
45246
|
positions.add(index2);
|
|
@@ -45157,7 +45257,7 @@ function patchResponseFields(root2, fields) {
|
|
|
45157
45257
|
visit4(node2.items, index2 + 1);
|
|
45158
45258
|
return;
|
|
45159
45259
|
}
|
|
45160
|
-
const properties =
|
|
45260
|
+
const properties = object9(node2.properties) ? node2.properties : void 0;
|
|
45161
45261
|
if (properties && Object.hasOwn(properties, key2)) {
|
|
45162
45262
|
visit4(properties[key2], index2 + 1);
|
|
45163
45263
|
return;
|
|
@@ -45182,44 +45282,44 @@ function patchResponseFields(root2, fields) {
|
|
|
45182
45282
|
}
|
|
45183
45283
|
}
|
|
45184
45284
|
function documentServerDefaults(inputs) {
|
|
45185
|
-
if (!
|
|
45186
|
-
for (const property of Object.values(inputs.properties)) if (
|
|
45285
|
+
if (!object9(inputs) || !object9(inputs.properties)) return;
|
|
45286
|
+
for (const property of Object.values(inputs.properties)) if (object9(property) && Object.hasOwn(property, "default")) {
|
|
45187
45287
|
property.description = `${typeof property.description === "string" ? `${property.description.trim()} ` : ""}Server default when omitted: ${JSON.stringify(property.default)}.`;
|
|
45188
45288
|
if (property.examples === void 0) property.examples = [structuredClone(property.default)];
|
|
45189
45289
|
delete property.default;
|
|
45190
45290
|
}
|
|
45191
45291
|
}
|
|
45192
|
-
var
|
|
45292
|
+
var object9, assign;
|
|
45193
45293
|
var init_api_fields = __esm({
|
|
45194
45294
|
"src/discovery/api-fields.ts"() {
|
|
45195
45295
|
"use strict";
|
|
45196
|
-
|
|
45296
|
+
object9 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
45197
45297
|
assign = (node2, key2, value) => Object.defineProperty(node2, key2, { value, enumerable: true, writable: true, configurable: true });
|
|
45198
45298
|
}
|
|
45199
45299
|
});
|
|
45200
45300
|
|
|
45201
45301
|
// src/discovery/api-filter-tree.ts
|
|
45202
45302
|
function compileFilterTree(raw, inputs, name) {
|
|
45203
|
-
if (!
|
|
45303
|
+
if (!object10(raw) || Object.keys(raw).some((k) => !["condition", "group", "operators", "catalogue", "metadata", "requiredMetadata", "maxDepth", "maxConditions"].includes(k))) throw Error("filterTree needs condition, group, catalogue and explicit unary/value operator lists");
|
|
45204
45304
|
const catalogue = raw.catalogue;
|
|
45205
|
-
if (!
|
|
45305
|
+
if (!object10(catalogue) || Object.keys(catalogue).some((key2) => !["action", "path", "field", "operators", "type", "booleanType"].includes(key2)) || !["action", "path", "field", "operators", "type", "booleanType"].every((key2) => typeof catalogue[key2] === "string" && (key2 === "path" || String(catalogue[key2]).length > 0))) throw Error("filterTree.catalogue needs action, path, field, operators, type and booleanType: map the selected filter-catalogue read so Boolean operand arities can be checked independently. Without a catalogue, use an explicit json grammar with independent cases.");
|
|
45206
45306
|
const { condition: c, group: g, operators: ops } = raw;
|
|
45207
45307
|
const tag = (v) => {
|
|
45208
|
-
if (!
|
|
45308
|
+
if (!object10(v) || Object.keys(v).length !== 1 || Object.values(v).some((x2) => typeof x2 !== "string" || !x2)) throw Error("Each node tag maps one discriminator field to its literal value");
|
|
45209
45309
|
return Object.entries(v)[0];
|
|
45210
45310
|
};
|
|
45211
|
-
if (!
|
|
45212
|
-
if (!
|
|
45213
|
-
if (!
|
|
45311
|
+
if (!object10(c) || Object.keys(c).some((k) => !["tag", "field", "operator", "value"].includes(k)) || ![c.field, c.operator, c.value].every((x2) => typeof x2 === "string" && x2.length)) throw Error("condition needs tag, field, operator and value field names");
|
|
45312
|
+
if (!object10(g) || Object.keys(g).some((k) => !["tag", "join", "children", "values"].includes(k)) || ![g.join, g.children].every((x2) => typeof x2 === "string" && x2.length) || !names2(g.values) || !g.values.length) throw Error("group needs tag, join, children and documented join values");
|
|
45313
|
+
if (!object10(ops) || Object.keys(ops).some((k) => !["unary", "value"].includes(k)) || !names2(ops.unary) || !names2(ops.value) || !ops.unary.length && !ops.value.length || ops.unary.some((op) => ops.value.includes(op))) throw Error("operators.unary and operators.value must be disjoint explicit lists; classify every supported operator by operand arity, including Boolean tests");
|
|
45214
45314
|
const ct = tag(c.tag), gt = tag(g.tag);
|
|
45215
45315
|
if (ct[0] !== gt[0] || ct[1] === gt[1]) throw Error("Condition and group need distinct values of the same discriminator");
|
|
45216
45316
|
if ((/* @__PURE__ */ new Set([ct[0], c.field, c.operator, c.value])).size !== 4 || (/* @__PURE__ */ new Set([gt[0], g.join, g.children])).size !== 3) throw Error("Node structure field names must be distinct within each node");
|
|
45217
45317
|
const metadata = raw.metadata ?? {}, required2 = raw.requiredMetadata ?? [];
|
|
45218
|
-
if (!
|
|
45318
|
+
if (!object10(metadata) || Object.values(metadata).some((v) => !object10(v)) || !names2(required2) || required2.some((k) => !Object.hasOwn(metadata, k))) throw Error("metadata maps optional node fields to schemas; requiredMetadata names only documented mandatory metadata");
|
|
45219
45319
|
const structural = [ct[0], c.field, c.operator, c.value, g.join, g.children];
|
|
45220
45320
|
if (Object.keys(metadata).some((k) => structural.includes(k))) throw Error("Metadata cannot override node structure");
|
|
45221
45321
|
for (const k of ["maxDepth", "maxConditions"]) if (raw[k] !== void 0 && (!Number.isSafeInteger(raw[k]) || Number(raw[k]) < 1)) throw Error(`${k} must be a positive documented limit`);
|
|
45222
|
-
const label2 = `filter_${name}`, defs =
|
|
45322
|
+
const label2 = `filter_${name}`, defs = object10(inputs.$defs) ? inputs.$defs : {};
|
|
45223
45323
|
if (Object.hasOwn(defs, label2)) throw Error(`Generated filter type ${label2} conflicts with an existing definition`);
|
|
45224
45324
|
const operand = { description: "Operand for the selected field and operator: text/enum strings, numeric numbers, Boolean values, arrays for sets/ranges, date strings or documented structured operands.", type: ["string", "number", "boolean", "null", "array", "object"], items: {}, additionalProperties: true };
|
|
45225
45325
|
const condition = (operators, takesValue) => ({ type: "object", additionalProperties: false, required: [ct[0], c.field, c.operator, ...takesValue ? [c.value] : [], ...required2], properties: { ...structuredClone(metadata), [ct[0]]: { const: ct[1], description: "Condition node discriminator." }, [String(c.field)]: { type: "string", description: "Field from the published filter catalogue; choose its compatible operator." }, [String(c.operator)]: { type: "string", enum: operators, description: takesValue ? "Comparison operator requiring an operand." : "Operand-free operator; omit the operand, or supply an ignored value if the API permits it." }, [String(c.value)]: operand } });
|
|
@@ -45232,11 +45332,11 @@ function compileFilterTree(raw, inputs, name) {
|
|
|
45232
45332
|
inputs.$defs = { ...defs, [label2]: { oneOf: branches, description: `Filter tree. Node metadata is optional unless explicitly documented as required. ${limits}`.trim() } };
|
|
45233
45333
|
return { $ref: `#/$defs/${pointer7(label2)}`, description: `Choose field and operator together from ${catalogue.action} at ${catalogue.path || "the root array"}. Operand-free operators: ${ops.unary.join(", ") || "none"}. Other listed operators require an operand. ${limits}`.trim() };
|
|
45234
45334
|
}
|
|
45235
|
-
var
|
|
45335
|
+
var object10, names2, pointer7;
|
|
45236
45336
|
var init_api_filter_tree = __esm({
|
|
45237
45337
|
"src/discovery/api-filter-tree.ts"() {
|
|
45238
45338
|
"use strict";
|
|
45239
|
-
|
|
45339
|
+
object10 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
45240
45340
|
names2 = (v) => Array.isArray(v) && v.every((x2) => typeof x2 === "string" && x2.length > 0) && new Set(v).size === v.length;
|
|
45241
45341
|
pointer7 = (v) => v.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
45242
45342
|
}
|
|
@@ -45257,7 +45357,7 @@ function documentSelectedInputScope(description2, omitted) {
|
|
|
45257
45357
|
}
|
|
45258
45358
|
function documentReferencedInputMeaning(definition2) {
|
|
45259
45359
|
const inputs = definition2.inputs, response = definition2.response;
|
|
45260
|
-
if (!
|
|
45360
|
+
if (!object11(inputs) || !object11(inputs.properties) || !object11(response)) return;
|
|
45261
45361
|
const descriptions2 = /* @__PURE__ */ new Set();
|
|
45262
45362
|
let budget = 3e4;
|
|
45263
45363
|
const visit4 = (node2, depth = 0) => {
|
|
@@ -45266,25 +45366,25 @@ function documentReferencedInputMeaning(definition2) {
|
|
|
45266
45366
|
node2.forEach((child2) => visit4(child2, depth + 1));
|
|
45267
45367
|
return;
|
|
45268
45368
|
}
|
|
45269
|
-
if (!
|
|
45369
|
+
if (!object11(node2)) return;
|
|
45270
45370
|
if (typeof node2.description === "string") descriptions2.add(node2.description);
|
|
45271
45371
|
Object.values(node2).forEach((child2) => {
|
|
45272
|
-
if (
|
|
45372
|
+
if (object11(child2) || Array.isArray(child2)) visit4(child2, depth + 1);
|
|
45273
45373
|
});
|
|
45274
45374
|
};
|
|
45275
45375
|
visit4(response.schema);
|
|
45276
45376
|
const prefixes = (text5) => [...text5.matchAll(/`([^`*\s]+)\*`/gu)].map((match) => match[1]);
|
|
45277
45377
|
for (const [name, field] of Object.entries(inputs.properties)) {
|
|
45278
|
-
if (!
|
|
45378
|
+
if (!object11(field) || typeof field.description !== "string" || !Array.isArray(field.enum) || !field.enum.length || field.enum.some((value) => typeof value !== "string")) continue;
|
|
45279
45379
|
const values = field.enum;
|
|
45280
45380
|
const link = `Same values accepted by \`${name}\` query param.`;
|
|
45281
|
-
const matches = [...descriptions2].filter((text6) => text6.includes(link) && prefixes(text6).length > 1 && values.every((value) => prefixes(text6).some((
|
|
45381
|
+
const matches = [...descriptions2].filter((text6) => text6.includes(link) && prefixes(text6).length > 1 && values.every((value) => prefixes(text6).some((prefix3) => String(value).startsWith(prefix3))));
|
|
45282
45382
|
if (matches.length !== 1) continue;
|
|
45283
45383
|
const meaning = matches[0].replace(link, "").trim();
|
|
45284
45384
|
if (meaning.length > 1200) continue;
|
|
45285
45385
|
let corrected = false;
|
|
45286
|
-
const text5 = field.description.replace(/, raised during [^.!?\n]+ \(`([^`*\s]+)\*`\)(?=\.)/gu, (clause,
|
|
45287
|
-
if (values.some((value) => !String(value).startsWith(
|
|
45386
|
+
const text5 = field.description.replace(/, raised during [^.!?\n]+ \(`([^`*\s]+)\*`\)(?=\.)/gu, (clause, prefix3) => {
|
|
45387
|
+
if (values.some((value) => !String(value).startsWith(prefix3))) {
|
|
45288
45388
|
corrected = true;
|
|
45289
45389
|
return "";
|
|
45290
45390
|
}
|
|
@@ -45295,19 +45395,19 @@ function documentReferencedInputMeaning(definition2) {
|
|
|
45295
45395
|
}
|
|
45296
45396
|
function documentInputVocabulary(definition2, collection) {
|
|
45297
45397
|
const inputs = definition2.inputs, response = definition2.response;
|
|
45298
|
-
if (!
|
|
45398
|
+
if (!object11(inputs) || !object11(inputs.properties) || !object11(response) || !object11(response.schema) || typeof collection !== "string") return;
|
|
45299
45399
|
const notes = /* @__PURE__ */ new Map(), root2 = response.schema;
|
|
45300
45400
|
const choices = (schema, depth = 0) => {
|
|
45301
|
-
if (!
|
|
45401
|
+
if (!object11(schema) || depth > 24) return [];
|
|
45302
45402
|
if (typeof schema.$ref === "string" && schema.$ref.startsWith("#/")) {
|
|
45303
45403
|
let value = root2;
|
|
45304
|
-
for (const key2 of schema.$ref.slice(2).split("/")) value =
|
|
45404
|
+
for (const key2 of schema.$ref.slice(2).split("/")) value = object11(value) ? value[key2.replaceAll("~1", "/").replaceAll("~0", "~")] : void 0;
|
|
45305
45405
|
return choices(value, depth + 1);
|
|
45306
45406
|
}
|
|
45307
45407
|
return [...Array.isArray(schema.enum) ? schema.enum.filter((v) => typeof v === "string") : [], ...["anyOf", "oneOf", "allOf"].flatMap((key2) => Array.isArray(schema[key2]) ? schema[key2].flatMap((child2) => choices(child2, depth + 1)) : [])];
|
|
45308
45408
|
};
|
|
45309
45409
|
for (const [name, field] of Object.entries(inputs.properties)) {
|
|
45310
|
-
if (!
|
|
45410
|
+
if (!object11(field) || !/\bsame vocabulary as\b/iu.test(String(field.description ?? ""))) continue;
|
|
45311
45411
|
const match = String(field.description).match(/\bsame vocabulary as[^.!?\n]*/iu)[0];
|
|
45312
45412
|
const referenced = match.match(/`([^`]+)`/u)?.[1] ?? name;
|
|
45313
45413
|
const schema = selectSchema(root2, `${collection}/*/${referenced.replaceAll("~", "~0").replaceAll("/", "~1")}`);
|
|
@@ -45316,14 +45416,14 @@ function documentInputVocabulary(definition2, collection) {
|
|
|
45316
45416
|
notes.set(name, { text: `Known documented ${referenced} values include: ${values.map((value) => JSON.stringify(value)).join(", ")}.`, values });
|
|
45317
45417
|
}
|
|
45318
45418
|
for (const [name, field] of Object.entries(inputs.properties)) {
|
|
45319
|
-
if (!
|
|
45419
|
+
if (!object11(field)) continue;
|
|
45320
45420
|
const note = notes.get(name) ?? [...notes].find(([referenced]) => String(field.description ?? "").includes("`" + referenced + "`") && /\bvalues\b/iu.test(String(field.description)))?.[1];
|
|
45321
45421
|
if (!note) continue;
|
|
45322
45422
|
if (!String(field.description).includes(note.text)) field.description = [field.description, note.text].filter(Boolean).join(" ");
|
|
45323
45423
|
if (field.examples === void 0) try {
|
|
45324
45424
|
const ajv4 = new import__6.default({ strict: false, validateFormats: true });
|
|
45325
45425
|
(0, import_ajv_formats4.default)(ajv4);
|
|
45326
|
-
const validate2 = ajv4.compile({ ...
|
|
45426
|
+
const validate2 = ajv4.compile({ ...object11(inputs.$defs) ? { $defs: inputs.$defs } : {}, ...field });
|
|
45327
45427
|
const examples = [note.values[0], note.values.slice(0, 2)].filter((value) => validate2(value));
|
|
45328
45428
|
if (examples.length) field.examples = examples;
|
|
45329
45429
|
} catch {
|
|
@@ -45335,9 +45435,9 @@ function translateArrayNotation(description2, name) {
|
|
|
45335
45435
|
return description2.replace(new RegExp(`\\b(?:using|via)\\s+\`?${escaped2}\\[\\]\\x60?\\s+notation\\b`, "gu"), "passed as a JSON array");
|
|
45336
45436
|
}
|
|
45337
45437
|
function applyDocumentedStringBounds(inputs) {
|
|
45338
|
-
if (!
|
|
45438
|
+
if (!object11(inputs) || !object11(inputs.properties)) return;
|
|
45339
45439
|
for (const field of Object.values(inputs.properties)) {
|
|
45340
|
-
if (!
|
|
45440
|
+
if (!object11(field) || field.type !== "string" || typeof field.description !== "string") continue;
|
|
45341
45441
|
for (const [phrase, keyword] of [["least", "minLength"], ["most", "maxLength"]]) {
|
|
45342
45442
|
const match = field.description.match(new RegExp(`(?:^|[.!?]\\s+)Must be at ${phrase} ([0-9]+) characters(?:[.!?](?:\\s|$)|$)`, "iu"));
|
|
45343
45443
|
if (field[keyword] === void 0 && match && Number.isSafeInteger(Number(match[1]))) field[keyword] = Number(match[1]);
|
|
@@ -45346,24 +45446,24 @@ function applyDocumentedStringBounds(inputs) {
|
|
|
45346
45446
|
}
|
|
45347
45447
|
function documentInputBindings(definition2) {
|
|
45348
45448
|
const inputs = definition2.inputs, request2 = definition2.request;
|
|
45349
|
-
if (!
|
|
45449
|
+
if (!object11(inputs) || !object11(inputs.properties)) return;
|
|
45350
45450
|
const types3 = (node2, seen = /* @__PURE__ */ new Set(), depth = 0) => {
|
|
45351
|
-
if (!
|
|
45451
|
+
if (!object11(node2) || depth > 32) return /* @__PURE__ */ new Set();
|
|
45352
45452
|
if (typeof node2.$ref === "string" && node2.$ref.startsWith("#/") && !seen.has(node2.$ref)) {
|
|
45353
45453
|
let target = inputs;
|
|
45354
|
-
for (const part of node2.$ref.slice(2).split("/")) target =
|
|
45454
|
+
for (const part of node2.$ref.slice(2).split("/")) target = object11(target) ? target[part.replaceAll("~1", "/").replaceAll("~0", "~")] : void 0;
|
|
45355
45455
|
return types3(target, /* @__PURE__ */ new Set([...seen, node2.$ref]), depth + 1);
|
|
45356
45456
|
}
|
|
45357
45457
|
return /* @__PURE__ */ new Set([...typeof node2.type === "string" ? [node2.type] : Array.isArray(node2.type) ? node2.type.filter((v) => typeof v === "string") : [], ...["anyOf", "oneOf", "allOf"].flatMap((key2) => Array.isArray(node2[key2]) ? node2[key2].flatMap((branch) => [...types3(branch, seen, depth + 1)]) : [])]);
|
|
45358
45458
|
};
|
|
45359
45459
|
for (const [name, field] of Object.entries(inputs.properties)) {
|
|
45360
|
-
if (!
|
|
45460
|
+
if (!object11(field)) continue;
|
|
45361
45461
|
const notes = [], description2 = typeof field.description === "string" ? field.description : "";
|
|
45362
45462
|
const source = field["x-source"];
|
|
45363
|
-
if (
|
|
45463
|
+
if (object11(source) && typeof source.action === "string" && typeof source.path === "string" && !(description2.includes(source.action) && description2.includes(source.path))) notes.push(`Choose values from ${source.action} at ${source.path}.`);
|
|
45364
45464
|
const kinds = types3(field);
|
|
45365
|
-
if (
|
|
45366
|
-
if (!
|
|
45465
|
+
if (object11(request2) && object11(request2.query) && object11(request2.queryEncoding)) for (const [wire, binding2] of Object.entries(request2.query)) {
|
|
45466
|
+
if (!object11(binding2) || binding2.$input !== name) continue;
|
|
45367
45467
|
const encoding = request2.queryEncoding[wire];
|
|
45368
45468
|
if (kinds.has("array") && /repeated/iu.test(description2.split("Pass an array as JSON;")[0]) && ["comma", "space", "pipe", "json"].includes(String(encoding))) notes.push("References to repeated query parameters describe wire syntax, not repeated CLI flags.");
|
|
45369
45469
|
if (kinds.has("array") && ["comma", "space", "pipe"].includes(String(encoding))) notes.push(`Pass an array as JSON; the CLI sends its items as a ${encoding}-separated query value. Use one flag per argument; repeated values belong in the array, not repeated flags.`);
|
|
@@ -45374,26 +45474,26 @@ function documentInputBindings(definition2) {
|
|
|
45374
45474
|
field.description = [description2, ...[...new Set(notes)].filter((note) => !description2.includes(note))].filter(Boolean).join(" ");
|
|
45375
45475
|
}
|
|
45376
45476
|
}
|
|
45377
|
-
var import__6, import_ajv_formats4,
|
|
45477
|
+
var import__6, import_ajv_formats4, object11;
|
|
45378
45478
|
var init_api_input_docs = __esm({
|
|
45379
45479
|
"src/discovery/api-input-docs.ts"() {
|
|
45380
45480
|
"use strict";
|
|
45381
45481
|
init_definitions();
|
|
45382
45482
|
import__6 = __toESM(require__(), 1);
|
|
45383
45483
|
import_ajv_formats4 = __toESM(require_dist(), 1);
|
|
45384
|
-
|
|
45484
|
+
object11 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
45385
45485
|
}
|
|
45386
45486
|
});
|
|
45387
45487
|
|
|
45388
45488
|
// src/discovery/api-input-json.ts
|
|
45389
45489
|
function compileInputJson(previous, raw, root2) {
|
|
45390
|
-
if (!
|
|
45490
|
+
if (!object12(raw)) throw Error("json needs the documented object/array schema, optionally a local reference");
|
|
45391
45491
|
const kinds = (node2, seen = /* @__PURE__ */ new Set(), depth = 0) => {
|
|
45392
|
-
if (!
|
|
45492
|
+
if (!object12(node2) || depth > 32) throw Error("JSON input needs a bounded object/array grammar");
|
|
45393
45493
|
if (typeof node2.$ref === "string") {
|
|
45394
45494
|
if (!node2.$ref.startsWith("#/") || seen.has(node2.$ref)) throw Error("JSON input root must resolve to an object or array");
|
|
45395
45495
|
let target = root2;
|
|
45396
|
-
for (const key2 of node2.$ref.slice(2).split("/")) target =
|
|
45496
|
+
for (const key2 of node2.$ref.slice(2).split("/")) target = object12(target) ? target[key2.replaceAll("~1", "/").replaceAll("~0", "~")] : void 0;
|
|
45397
45497
|
return kinds(target, /* @__PURE__ */ new Set([...seen, node2.$ref]), depth + 1);
|
|
45398
45498
|
}
|
|
45399
45499
|
if (typeof node2.type === "string") return [node2.type];
|
|
@@ -45404,7 +45504,7 @@ function compileInputJson(previous, raw, root2) {
|
|
|
45404
45504
|
if (kinds(raw).some((type) => !["object", "array"].includes(type))) throw Error("json accepts only object/array grammars; scalar JSON uses an explicit native contract");
|
|
45405
45505
|
const ajv4 = new import__7.default({ strict: false, validateFormats: true });
|
|
45406
45506
|
(0, import_ajv_formats5.default)(ajv4);
|
|
45407
|
-
const validate2 = ajv4.compile({ ...
|
|
45507
|
+
const validate2 = ajv4.compile({ ...object12(root2.$defs) ? { $defs: root2.$defs } : {}, ...object12(root2.definitions) ? { definitions: root2.definitions } : {}, ...raw });
|
|
45408
45508
|
const inherited = Object.fromEntries(Object.entries(previous).filter(([key2]) => ["title", "description", "x-source", "deprecated", "$comment"].includes(key2)));
|
|
45409
45509
|
const examples = [];
|
|
45410
45510
|
for (const value of Array.isArray(previous.examples) ? previous.examples : []) {
|
|
@@ -45418,29 +45518,29 @@ function compileInputJson(previous, raw, root2) {
|
|
|
45418
45518
|
}
|
|
45419
45519
|
return { ...inherited, contentMediaType: "application/json", contentSchema: structuredClone(raw), oneOf: [{ type: "string", description: "JSON text conforming to contentSchema." }, structuredClone(raw)], ...examples.length ? { examples } : {} };
|
|
45420
45520
|
}
|
|
45421
|
-
var import__7, import_ajv_formats5,
|
|
45521
|
+
var import__7, import_ajv_formats5, object12;
|
|
45422
45522
|
var init_api_input_json = __esm({
|
|
45423
45523
|
"src/discovery/api-input-json.ts"() {
|
|
45424
45524
|
"use strict";
|
|
45425
45525
|
import__7 = __toESM(require__(), 1);
|
|
45426
45526
|
import_ajv_formats5 = __toESM(require_dist(), 1);
|
|
45427
|
-
|
|
45527
|
+
object12 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
45428
45528
|
}
|
|
45429
45529
|
});
|
|
45430
45530
|
|
|
45431
45531
|
// src/discovery/api-input-lists.ts
|
|
45432
45532
|
function compileInputList(previous, raw, root2, overrideEncoding) {
|
|
45433
|
-
if (!
|
|
45533
|
+
if (!object13(raw) || Object.keys(raw).some((k) => !["items", "encoding"].includes(k))) throw Error("list accepts items (optional scalar schema) and encoding (comma, space or pipe)");
|
|
45434
45534
|
const encoding = overrideEncoding ?? raw.encoding;
|
|
45435
45535
|
if (!["comma", "space", "pipe"].includes(String(encoding))) throw Error("Declare list.encoding as comma, space or pipe from documented or observed serialization");
|
|
45436
45536
|
const separator = encoding === "comma" ? "," : encoding === "space" ? " " : "|";
|
|
45437
45537
|
const resolve17 = (node2, depth = 0) => {
|
|
45438
|
-
if (!
|
|
45538
|
+
if (!object13(node2) || depth > 16) throw Error("List items need a bounded scalar schema");
|
|
45439
45539
|
if (typeof node2.$ref !== "string") return node2;
|
|
45440
45540
|
if (!node2.$ref.startsWith("#/")) throw Error("List item references must be local");
|
|
45441
45541
|
if (Object.keys(node2).some((k) => k !== "$ref" && k !== "x-source" && !annotations2.has(k))) throw Error("List item references with sibling constraints need an explicit item schema");
|
|
45442
45542
|
let target = root2;
|
|
45443
|
-
for (const part of node2.$ref.slice(2).split("/")) target =
|
|
45543
|
+
for (const part of node2.$ref.slice(2).split("/")) target = object13(target) ? target[part.replaceAll("~1", "/").replaceAll("~0", "~")] : void 0;
|
|
45444
45544
|
return resolve17(target, depth + 1);
|
|
45445
45545
|
};
|
|
45446
45546
|
const base2 = resolve17(previous), branches = [base2, ...["oneOf", "anyOf"].flatMap((key2) => Array.isArray(base2[key2]) ? base2[key2].map((b) => resolve17(b)) : [])];
|
|
@@ -45486,13 +45586,13 @@ function compileInputList(previous, raw, root2, overrideEncoding) {
|
|
|
45486
45586
|
inherited.description = [inherited.description, `Accepts one value, ${encoding}-separated text, or a JSON array of values.`].filter(Boolean).join(" ");
|
|
45487
45587
|
return { encoding: String(encoding), schema: { ...inherited, anyOf: [scalar2, { type: "array", minItems: minimumItems, items: arrayItem }, { type: "string", pattern: `^${atom}(?:${escaped(separator)}${atom})*$` }] } };
|
|
45488
45588
|
}
|
|
45489
|
-
var import__8, import_ajv_formats6,
|
|
45589
|
+
var import__8, import_ajv_formats6, object13, annotations2, escaped;
|
|
45490
45590
|
var init_api_input_lists = __esm({
|
|
45491
45591
|
"src/discovery/api-input-lists.ts"() {
|
|
45492
45592
|
"use strict";
|
|
45493
45593
|
import__8 = __toESM(require__(), 1);
|
|
45494
45594
|
import_ajv_formats6 = __toESM(require_dist(), 1);
|
|
45495
|
-
|
|
45595
|
+
object13 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
45496
45596
|
annotations2 = /* @__PURE__ */ new Set(["title", "description", "examples", "deprecated", "$comment", "readOnly", "writeOnly"]);
|
|
45497
45597
|
escaped = (value) => value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
45498
45598
|
}
|
|
@@ -45508,22 +45608,22 @@ function checkFixedQuery(name, value, schema, defs) {
|
|
|
45508
45608
|
function checkLookupOutputModes(schema, omitted, query, omissions) {
|
|
45509
45609
|
let budget = 3e4;
|
|
45510
45610
|
const visit4 = (node2) => {
|
|
45511
|
-
if (!
|
|
45611
|
+
if (!object14(node2) || --budget < 0) return;
|
|
45512
45612
|
const prose = String(node2.description ?? "");
|
|
45513
45613
|
if (/\bonly\s+returned\s+(?:when|if)\b/iu.test(prose)) for (const name of omitted) {
|
|
45514
|
-
if (
|
|
45614
|
+
if (object14(omissions) && Object.hasOwn(omissions, name)) continue;
|
|
45515
45615
|
const escaped2 = name.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
45516
45616
|
const match = prose.match(new RegExp(`\\b${escaped2}\\s*=\\s*[\`'"]?([^\\s\`'",;.)]+)`, "u"));
|
|
45517
45617
|
if (match && String(query[name]) !== match[1]) throw Error(`Lookup output requires excluded query ${name}=${match[1]}. Use fixedQuery with matching independent observations to preserve meaningful identifier choices without another caller parameter. If this output mode is unrelated to identifier choice, explain that in lookupOmissions.${name}.`);
|
|
45518
45618
|
}
|
|
45519
45619
|
for (const value of Object.values(node2)) if (Array.isArray(value)) value.forEach(visit4);
|
|
45520
|
-
else if (
|
|
45620
|
+
else if (object14(value)) visit4(value);
|
|
45521
45621
|
};
|
|
45522
45622
|
visit4(schema);
|
|
45523
45623
|
}
|
|
45524
45624
|
function checkLookupTraversal(parameters, selected, omissions, schema) {
|
|
45525
|
-
if (omissions !== void 0 && (!
|
|
45526
|
-
const omitted =
|
|
45625
|
+
if (omissions !== void 0 && (!object14(omissions) || Object.values(omissions).some((reason) => typeof reason !== "string" || reason.trim().length < 20))) throw Error("lookupOmissions needs documented parameter names with substantive reasons why they are not needed for traversal");
|
|
45626
|
+
const omitted = object14(omissions) ? omissions : {};
|
|
45527
45627
|
for (const name of Object.keys(omitted)) if (!parameters.some((parameter) => parameter.in === "query" && parameter.name === name) || selected.includes(name)) throw Error(`lookupOmissions.${name} must identify an excluded documented query parameter`);
|
|
45528
45628
|
const candidates = parameters.filter((parameter) => {
|
|
45529
45629
|
if (parameter.in !== "query" || parameter.required === true || selected.includes(parameter.name)) return false;
|
|
@@ -45541,13 +45641,13 @@ function omittedQueryDefault(parameter, shape2) {
|
|
|
45541
45641
|
const value = prose ?? (Object.hasOwn(shape2, "default") ? JSON.stringify(shape2.default) : void 0);
|
|
45542
45642
|
return value ? `Lookup scope (${String(parameter.name)} omitted): ${value}.` : void 0;
|
|
45543
45643
|
}
|
|
45544
|
-
var import__9, import_ajv_formats7,
|
|
45644
|
+
var import__9, import_ajv_formats7, object14;
|
|
45545
45645
|
var init_api_lookup = __esm({
|
|
45546
45646
|
"src/discovery/api-lookup.ts"() {
|
|
45547
45647
|
"use strict";
|
|
45548
45648
|
import__9 = __toESM(require__(), 1);
|
|
45549
45649
|
import_ajv_formats7 = __toESM(require_dist(), 1);
|
|
45550
|
-
|
|
45650
|
+
object14 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
45551
45651
|
}
|
|
45552
45652
|
});
|
|
45553
45653
|
|
|
@@ -45555,10 +45655,10 @@ var init_api_lookup = __esm({
|
|
|
45555
45655
|
import { createHash as createHash15 } from "node:crypto";
|
|
45556
45656
|
function importOperation(document, selector, responseTypes, omittedInputs = [], omittedDefaults = []) {
|
|
45557
45657
|
const method = String(selector.method).toUpperCase(), path2 = String(selector.path);
|
|
45558
|
-
const paths2 =
|
|
45559
|
-
const item =
|
|
45658
|
+
const paths2 = object15(document.paths) ? document.paths : {};
|
|
45659
|
+
const item = object15(paths2[path2]) ? paths2[path2] : {};
|
|
45560
45660
|
const operation2 = item[method.toLowerCase()];
|
|
45561
|
-
if (!methods.has(method) || !
|
|
45661
|
+
if (!methods.has(method) || !object15(operation2)) throw Error(`Documented operation ${method} ${path2} is missing`);
|
|
45562
45662
|
let budget = 3e4;
|
|
45563
45663
|
const defs = /* @__PURE__ */ Object.create(null);
|
|
45564
45664
|
function reference(ref) {
|
|
@@ -45566,13 +45666,13 @@ function importOperation(document, selector, responseTypes, omittedInputs = [],
|
|
|
45566
45666
|
let node2 = document;
|
|
45567
45667
|
for (const raw of ref.slice(2).split("/")) {
|
|
45568
45668
|
const key2 = raw.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
45569
|
-
if (!
|
|
45669
|
+
if (!object15(node2) && !Array.isArray(node2) || !Object.hasOwn(node2, key2)) throw Error(`Unresolved reference ${ref}`);
|
|
45570
45670
|
node2 = node2[key2];
|
|
45571
45671
|
}
|
|
45572
45672
|
return node2;
|
|
45573
45673
|
}
|
|
45574
45674
|
function deref(node2, seen = /* @__PURE__ */ new Set()) {
|
|
45575
|
-
if (!
|
|
45675
|
+
if (!object15(node2)) throw Error("Documented contract must be an object");
|
|
45576
45676
|
if (typeof node2.$ref !== "string") return node2;
|
|
45577
45677
|
if (seen.has(node2.$ref)) throw Error("Cyclic operation reference");
|
|
45578
45678
|
return { ...deref(reference(node2.$ref), new Set(seen).add(node2.$ref)), ...Object.fromEntries(Object.entries(node2).filter(([key2]) => key2 !== "$ref")) };
|
|
@@ -45580,16 +45680,16 @@ function importOperation(document, selector, responseTypes, omittedInputs = [],
|
|
|
45580
45680
|
function schema(raw, direction = "input", label2 = "") {
|
|
45581
45681
|
if (--budget < 0) throw Error("Selected schema exceeds the 30,000-node compilation budget; split the selection");
|
|
45582
45682
|
if (typeof raw === "boolean") return raw;
|
|
45583
|
-
if (!
|
|
45683
|
+
if (!object15(raw)) throw Error("Expected a documented JSON Schema");
|
|
45584
45684
|
const opaque = (raw.type === "object" || Array.isArray(raw.type) && raw.type.includes("object")) && !raw.properties && raw.additionalProperties === void 0 && !raw.$ref && !["anyOf", "oneOf", "allOf"].some((k) => Array.isArray(raw[k]));
|
|
45585
45685
|
if (direction === "output" && label2 && opaque) {
|
|
45586
|
-
const components =
|
|
45587
|
-
const candidates = Object.entries(components).filter(([name, value]) => [label2, `${label2}ListItem`, `${label2}Record`].some((candidate2) => candidate2.toLowerCase() === name.toLowerCase()) &&
|
|
45686
|
+
const components = object15(document.components) && object15(document.components.schemas) ? document.components.schemas : {};
|
|
45687
|
+
const candidates = Object.entries(components).filter(([name, value]) => [label2, `${label2}ListItem`, `${label2}Record`].some((candidate2) => candidate2.toLowerCase() === name.toLowerCase()) && object15(value) && object15(value.properties) && Object.keys(value.properties).length).map(([name]) => `/components/schemas/${esc2(name)}`);
|
|
45588
45688
|
const selected2 = responseTypes === "documented" ? candidates.length ? candidates : void 0 : responseTypes && Object.hasOwn(responseTypes, label2) ? responseTypes[label2] : void 0;
|
|
45589
45689
|
if (selected2 !== void 0) {
|
|
45590
|
-
const refs =
|
|
45591
|
-
const excluded =
|
|
45592
|
-
if (
|
|
45690
|
+
const refs = object15(selected2) ? selected2.include : Array.isArray(selected2) ? selected2 : [selected2];
|
|
45691
|
+
const excluded = object15(selected2) ? selected2.exclude ?? {} : {};
|
|
45692
|
+
if (object15(selected2) && Object.keys(selected2).some((key2) => !["include", "exclude"].includes(key2)) || !object15(excluded) || Object.entries(excluded).some(([ref, reason]) => !candidates.includes(ref.replace(/^#/u, "")) || typeof reason !== "string" || reason.trim().length < 20)) throw Error(`responseTypes.${label2}: exclusions name candidate pointers with evidence-based reasons; use {include:[...],exclude:{pointer:reason}}`);
|
|
45593
45693
|
if (!Array.isArray(refs)) throw Error(`responseTypes.${label2}.include must list documented type pointers`);
|
|
45594
45694
|
const selectedPaths = refs.map((ref) => typeof ref === "string" ? ref.replace(/^#/u, "") : ref);
|
|
45595
45695
|
const excludedPaths = Object.keys(excluded).map((ref) => ref.replace(/^#/u, ""));
|
|
@@ -45600,7 +45700,7 @@ function importOperation(document, selector, responseTypes, omittedInputs = [],
|
|
|
45600
45700
|
const fields = /* @__PURE__ */ new Map();
|
|
45601
45701
|
const variants = refs.map((ref) => {
|
|
45602
45702
|
const value = deref(reference(ref.startsWith("#") ? ref : `#${ref}`));
|
|
45603
|
-
if (!
|
|
45703
|
+
if (!object15(value.properties) || !Object.keys(value.properties).length) throw Error(`Response type ${ref} must define record properties`);
|
|
45604
45704
|
for (const [name, field] of Object.entries(value.properties)) {
|
|
45605
45705
|
const choices = fields.get(name) ?? [];
|
|
45606
45706
|
if (!choices.some((choice) => JSON.stringify(choice) === JSON.stringify(field))) choices.push(field);
|
|
@@ -45637,11 +45737,11 @@ function importOperation(document, selector, responseTypes, omittedInputs = [],
|
|
|
45637
45737
|
}
|
|
45638
45738
|
if (typeof result3.exclusiveMinimum === "boolean") delete result3.exclusiveMinimum;
|
|
45639
45739
|
if (typeof result3.exclusiveMaximum === "boolean") delete result3.exclusiveMaximum;
|
|
45640
|
-
for (const key2 of ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]) if (
|
|
45740
|
+
for (const key2 of ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]) if (object15(result3[key2])) result3[key2] = Object.fromEntries(Object.entries(result3[key2]).map(([name, v]) => [name, schema(v, direction, key2 === "properties" ? name : "")]));
|
|
45641
45741
|
for (const key2 of ["items", "additionalProperties", "not", "if", "then", "else", "contains", "contentSchema", "propertyNames", "unevaluatedProperties"]) if (result3[key2] !== void 0) result3[key2] = schema(result3[key2], direction);
|
|
45642
45742
|
for (const key2 of ["allOf", "anyOf", "oneOf", "prefixItems"]) if (Array.isArray(result3[key2])) result3[key2] = result3[key2].map((v) => schema(v, direction, label2));
|
|
45643
|
-
if (
|
|
45644
|
-
const omitted = Object.entries(
|
|
45743
|
+
if (object15(result3.properties)) {
|
|
45744
|
+
const omitted = Object.entries(object15(raw.properties) ? raw.properties : {}).filter(([, field]) => object15(field) && deref(field)[direction === "input" ? "readOnly" : "writeOnly"] === true).map(([name]) => name);
|
|
45645
45745
|
for (const name of omitted) delete result3.properties[name];
|
|
45646
45746
|
if (Array.isArray(result3.required)) result3.required = result3.required.filter((name) => !omitted.includes(String(name)));
|
|
45647
45747
|
}
|
|
@@ -45654,7 +45754,7 @@ function importOperation(document, selector, responseTypes, omittedInputs = [],
|
|
|
45654
45754
|
const localServers = operation2.servers ?? item.servers;
|
|
45655
45755
|
if (Array.isArray(localServers) && localServers.length) {
|
|
45656
45756
|
const server = localServers[0];
|
|
45657
|
-
if (localServers.length !== 1 || !
|
|
45757
|
+
if (localServers.length !== 1 || !object15(server) || typeof server.url !== "string" || !server.url || /[{}?#\\]/u.test(server.url)) {
|
|
45658
45758
|
throw Error("Choose a documented operation server and author its URL explicitly in a native definition");
|
|
45659
45759
|
}
|
|
45660
45760
|
const base2 = server.url.replace(/\/$/u, "");
|
|
@@ -45677,13 +45777,13 @@ function importOperation(document, selector, responseTypes, omittedInputs = [],
|
|
|
45677
45777
|
parameters.set(`${p.in}:${p.name}`, p);
|
|
45678
45778
|
}
|
|
45679
45779
|
let selected = selector.parameters;
|
|
45680
|
-
if (selector.fixedQuery !== void 0 && (!
|
|
45681
|
-
const fixed =
|
|
45780
|
+
if (selector.fixedQuery !== void 0 && (!object15(selector.fixedQuery) || selector.lookup === void 0)) throw Error("fixedQuery requires a prerequisite lookup and documented literal query values");
|
|
45781
|
+
const fixed = object15(selector.fixedQuery) ? selector.fixedQuery : {};
|
|
45682
45782
|
for (const name of Object.keys(fixed)) if (![...parameters.values()].some((parameter) => parameter.in === "query" && parameter.name === name)) throw Error(`fixedQuery.${name} must name a documented query parameter`);
|
|
45683
45783
|
if (selector.lookupOmissions !== void 0 && selector.lookup === void 0) throw Error("lookupOmissions requires a prerequisite lookup");
|
|
45684
45784
|
if (selector.lookup !== void 0) {
|
|
45685
45785
|
if (method !== "GET") throw Error("lookup is limited to documented GET prerequisites");
|
|
45686
|
-
if (selected !== void 0 || !
|
|
45786
|
+
if (selected !== void 0 || !object15(selector.lookup) || Object.keys(selector.lookup).some((k) => !["page", "limit", "offset", "cursor"].includes(k))) throw Error("lookup selects only named page/limit/offset/cursor inputs plus required parameters; do not combine it with parameters");
|
|
45687
45787
|
for (const [role, name] of Object.entries(selector.lookup)) {
|
|
45688
45788
|
const p = [...parameters.values()].find((p2) => p2.name === name && p2.in === "query");
|
|
45689
45789
|
if (typeof name !== "string" || !p) throw Error(`lookup.${role} must name a documented query parameter`);
|
|
@@ -45716,13 +45816,13 @@ function importOperation(document, selector, responseTypes, omittedInputs = [],
|
|
|
45716
45816
|
const name = String(p.name);
|
|
45717
45817
|
if (!inputNameSchema.safeParse(name).success || Object.hasOwn(properties, name)) throw Error(`Parameter ${name} needs an explicit native contract to resolve its input name`);
|
|
45718
45818
|
if (!["path", "query", "header"].includes(String(p.in))) throw Error(`Parameter ${name}: unsupported location ${p.in}; credentials belong in the connection`);
|
|
45719
|
-
const jsonContent =
|
|
45819
|
+
const jsonContent = object15(p.content) && object15(p.content["application/json"]) ? p.content["application/json"] : void 0;
|
|
45720
45820
|
if (p.content !== void 0 && (!jsonContent || p.in !== "query")) throw Error(`Parameter ${name}: unsupported content encoding`);
|
|
45721
45821
|
const rawSchema = jsonContent?.schema ?? p.schema;
|
|
45722
45822
|
const input2 = schema(rawSchema);
|
|
45723
|
-
const shape2 =
|
|
45823
|
+
const shape2 = object15(rawSchema) ? deref(rawSchema) : {};
|
|
45724
45824
|
const parameterTypes = (value, depth = 0) => {
|
|
45725
|
-
if (!
|
|
45825
|
+
if (!object15(value) || depth > 32) throw Error(`Parameter ${name}: ambiguous parameter shape needs an explicit native contract`);
|
|
45726
45826
|
const node2 = deref(value), types3 = new Set(Array.isArray(node2.type) ? node2.type : typeof node2.type === "string" ? [node2.type] : []);
|
|
45727
45827
|
for (const key2 of ["oneOf", "anyOf", "allOf"]) if (Array.isArray(node2[key2])) for (const branch of node2[key2]) for (const type of parameterTypes(branch, depth + 1)) types3.add(type);
|
|
45728
45828
|
if (!types3.size && Array.isArray(node2.enum)) for (const value2 of node2.enum) types3.add(value2 === null ? "null" : typeof value2);
|
|
@@ -45741,8 +45841,8 @@ function importOperation(document, selector, responseTypes, omittedInputs = [],
|
|
|
45741
45841
|
} else throw Error(`Parameter ${name}: unsupported query style ${p.style}`);
|
|
45742
45842
|
if (p.allowReserved === true) throw Error(`Parameter ${name}: reserved query characters need an explicit native contract`);
|
|
45743
45843
|
} else if (kinds.has("object") || kinds.has("array") || p.style !== void 0 && p.style !== "simple") throw Error(`Parameter ${name}: non-scalar path/header needs an explicit native contract`);
|
|
45744
|
-
const namedExamples =
|
|
45745
|
-
properties[name] =
|
|
45844
|
+
const namedExamples = object15(p.examples) ? Object.values(p.examples).map((value) => deref(value)).filter((value) => Object.hasOwn(value, "value")).map((value) => value.value) : [];
|
|
45845
|
+
properties[name] = object15(input2) ? { ...input2, ...typeof p.description === "string" ? { description: p.description } : {}, ...p.example !== void 0 ? { examples: [p.example] } : namedExamples.length ? { examples: namedExamples } : {} } : input2;
|
|
45746
45846
|
if (p.required === true || p.in === "path") required2.push(name);
|
|
45747
45847
|
if (p.in === "path") url3 = url3.replaceAll(`{${name}}`, `{input.${name}}`);
|
|
45748
45848
|
else (p.in === "query" ? query : headers)[name] = { $input: name };
|
|
@@ -45750,20 +45850,20 @@ function importOperation(document, selector, responseTypes, omittedInputs = [],
|
|
|
45750
45850
|
let body, form;
|
|
45751
45851
|
if (operation2.requestBody !== void 0) {
|
|
45752
45852
|
const requestBody = deref(operation2.requestBody), content = requestBody.content;
|
|
45753
|
-
if (!
|
|
45754
|
-
const media =
|
|
45755
|
-
if (!
|
|
45853
|
+
if (!object15(content)) throw Error("Request body needs documented content");
|
|
45854
|
+
const media = object15(content["application/json"]) ? content["application/json"] : object15(content["application/x-www-form-urlencoded"]) ? content["application/x-www-form-urlencoded"] : void 0;
|
|
45855
|
+
if (!object15(media) || media.encoding) throw Error("Unsupported request media or encoding; supply an explicit native contract");
|
|
45756
45856
|
const normalized = schema(media.schema);
|
|
45757
|
-
const bodySchema =
|
|
45857
|
+
const bodySchema = object15(normalized) && typeof normalized.$ref === "string" ? defs[normalized.$ref.slice("#/$defs/".length)] : normalized;
|
|
45758
45858
|
const json4 = content["application/json"] !== void 0;
|
|
45759
|
-
const flatten = requestBody.required === true &&
|
|
45859
|
+
const flatten = requestBody.required === true && object15(bodySchema) && bodySchema.type === "object" && object15(bodySchema.properties) && bodySchema.additionalProperties === false && Object.keys(bodySchema).every((key2) => flattenableKeywords.has(key2));
|
|
45760
45860
|
if (!flatten && json4) {
|
|
45761
45861
|
if (Object.hasOwn(properties, "body")) throw Error("Body input conflicts with a parameter; supply an explicit native contract");
|
|
45762
|
-
properties.body = { ...
|
|
45862
|
+
properties.body = { ...object15(normalized) ? normalized : { allOf: [normalized] }, description: requestBody.description ?? "JSON request body; omitted members retain the documented API semantics." };
|
|
45763
45863
|
if (requestBody.required === true) required2.push("body");
|
|
45764
45864
|
body = { $input: "body" };
|
|
45765
45865
|
} else {
|
|
45766
|
-
if (!flatten || !
|
|
45866
|
+
if (!flatten || !object15(bodySchema) || !object15(bodySchema.properties)) throw Error("Form body needs a required flat object contract");
|
|
45767
45867
|
body = /* @__PURE__ */ Object.create(null);
|
|
45768
45868
|
for (const [name, field] of Object.entries(bodySchema.properties)) {
|
|
45769
45869
|
if (!inputNameSchema.safeParse(name).success || Object.hasOwn(properties, name)) throw Error(`Body member ${name} conflicts with an input; supply an explicit native contract`);
|
|
@@ -45777,7 +45877,7 @@ function importOperation(document, selector, responseTypes, omittedInputs = [],
|
|
|
45777
45877
|
}
|
|
45778
45878
|
}
|
|
45779
45879
|
}
|
|
45780
|
-
const responses =
|
|
45880
|
+
const responses = object15(operation2.responses) ? operation2.responses : {};
|
|
45781
45881
|
const responseKeys = Object.keys(responses).filter((key2) => /^2(?:[0-9]{2}|XX)$/u.test(key2));
|
|
45782
45882
|
const selectedStatuses = selector.response === void 0 ? responseKeys : [String(selector.response)];
|
|
45783
45883
|
if (!selectedStatuses.length || selectedStatuses.some((key2) => !Object.hasOwn(responses, key2))) throw Error("The operation needs a documented successful response status");
|
|
@@ -45785,12 +45885,12 @@ function importOperation(document, selector, responseTypes, omittedInputs = [],
|
|
|
45785
45885
|
const contentTypes = /* @__PURE__ */ new Set();
|
|
45786
45886
|
for (const status of selectedStatuses) {
|
|
45787
45887
|
const response = deref(responses[status]);
|
|
45788
|
-
if (!
|
|
45888
|
+
if (!object15(response.content) || !Object.keys(response.content).length) {
|
|
45789
45889
|
outputs.push({ type: "null" });
|
|
45790
45890
|
continue;
|
|
45791
45891
|
}
|
|
45792
45892
|
const json4 = response.content["application/json"] ?? Object.entries(response.content).find(([media]) => media.endsWith("+json"))?.[1];
|
|
45793
|
-
if (
|
|
45893
|
+
if (object15(json4) && json4.schema !== void 0) {
|
|
45794
45894
|
outputs.push(schema(selector.responsePointer === void 0 ? json4.schema : reference(String(selector.responsePointer).replace(/^#?/u, "#")), "output"));
|
|
45795
45895
|
continue;
|
|
45796
45896
|
}
|
|
@@ -45805,20 +45905,20 @@ function importOperation(document, selector, responseTypes, omittedInputs = [],
|
|
|
45805
45905
|
const output2 = distinct.length > 1 ? { anyOf: distinct } : distinct[0];
|
|
45806
45906
|
const attach = (value, direction) => {
|
|
45807
45907
|
const selected2 = Object.fromEntries(Object.entries(defs).filter(([key2]) => key2.startsWith(`${direction}-`)));
|
|
45808
|
-
return
|
|
45908
|
+
return object15(value) ? { ...value, ...Object.keys(selected2).length ? { $defs: clone3(selected2) } : {} } : value;
|
|
45809
45909
|
};
|
|
45810
45910
|
if (selector.lookup !== void 0) checkLookupOutputModes(attach(output2, "output"), omittedInputs, query, selector.lookupOmissions);
|
|
45811
45911
|
const explicitEffect = operation2["x-apilift-effect"];
|
|
45812
45912
|
const effect2 = ["read", "create", "update", "delete"].includes(String(explicitEffect)) && typeof explicitEffect === "string" ? explicitEffect : "";
|
|
45813
45913
|
return { effect: effect2, title: operation2.summary ?? "", description: operation2.description ?? operation2.summary ?? "", inputs: attach({ type: "object", properties, required: [...new Set(required2)], additionalProperties: false }, "input"), request: { method, url: url3, ...Object.keys(query).length ? { query } : {}, ...Object.keys(queryEncoding).length ? { queryEncoding } : {}, ...Object.keys(headers).length ? { headers } : {}, ...body ? { body } : {}, ...form ? { form } : {} }, response: contentTypes.size ? { format: "file", file: { name: "response", contentTypes: [...contentTypes] } } : { schema: attach(output2, "output") } };
|
|
45814
45914
|
}
|
|
45815
|
-
var
|
|
45915
|
+
var object15, esc2, clone3, flattenableKeywords, methods;
|
|
45816
45916
|
var init_openapi_operation = __esm({
|
|
45817
45917
|
"src/discovery/openapi-operation.ts"() {
|
|
45818
45918
|
"use strict";
|
|
45819
45919
|
init_definitions();
|
|
45820
45920
|
init_api_lookup();
|
|
45821
|
-
|
|
45921
|
+
object15 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
45822
45922
|
esc2 = (value) => value.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
45823
45923
|
clone3 = (value) => structuredClone(value);
|
|
45824
45924
|
flattenableKeywords = /* @__PURE__ */ new Set(["type", "title", "description", "properties", "required", "additionalProperties", "examples", "default", "deprecated", "$comment"]);
|
|
@@ -47320,7 +47420,8 @@ function safeLocation(raw) {
|
|
|
47320
47420
|
}
|
|
47321
47421
|
function candidateLine(item) {
|
|
47322
47422
|
const value = item.entry;
|
|
47323
|
-
|
|
47423
|
+
const status = Number.isInteger(value.status) ? value.status : value.pending === true ? "pending" : "unavailable";
|
|
47424
|
+
return `c${item.seq} \u2014 ${/^(GET|HEAD|OPTIONS|POST|PUT|PATCH|DELETE)$/.test(String(value.method)) ? value.method : "?"} ${safeLocation(value.url)} \u2014 response ${status}${value.bodyUnavailable ? ` (${String(value.bodyUnavailable).slice(0, 80)})` : ""}`;
|
|
47324
47425
|
}
|
|
47325
47426
|
function requestHeaderNames(entry2) {
|
|
47326
47427
|
return Object.keys(entry2.reqHeaders ?? {}).filter((name) => /^[!#$%&'*+.^_`|~0-9A-Za-z-]{1,120}$/u.test(name)).map((name) => name.toLowerCase());
|
|
@@ -47493,6 +47594,10 @@ ${redactionReason}${captureFailureReceipt(entry2) ? `${captureFailureReceipt(ent
|
|
|
47493
47594
|
} else try {
|
|
47494
47595
|
parsed = JSON.parse(body);
|
|
47495
47596
|
} catch {
|
|
47597
|
+
const framing = part === "response" ? responseFramingDescription(body) : void 0;
|
|
47598
|
+
if (framing) return fail5(`${framing} For structured fields, use a documented API or look for a related structured read.
|
|
47599
|
+
Metadata: ${candidateLine(item)}
|
|
47600
|
+
`);
|
|
47496
47601
|
const headers = entry2[part === "request" ? "reqHeaders" : "resHeaders"] ?? {};
|
|
47497
47602
|
const mime2 = String(Object.entries(headers).find(([name]) => name.toLowerCase() === "content-type")?.[1] ?? "");
|
|
47498
47603
|
if (part === "request" && mime2.includes("application/x-www-form-urlencoded")) {
|
|
@@ -47511,8 +47616,11 @@ ${/html/i.test(mime2) ? "Only if the task needs extracted HTML fields, inspect t
|
|
|
47511
47616
|
${JSON.stringify(maskCaptureUrls(inspectHtml(body, invocation.options.selector)), null, 2)}
|
|
47512
47617
|
Inspect at most 20 matching elements with --selector <CSS-selector>. This reads retained evidence; it sends no app request.
|
|
47513
47618
|
`);
|
|
47514
|
-
} else {
|
|
47515
|
-
|
|
47619
|
+
} else if (part === "response") return fail5(`Captured response for c${item.seq} has no supported structured format.
|
|
47620
|
+
Metadata: ${candidateLine(item)}
|
|
47621
|
+
`);
|
|
47622
|
+
else {
|
|
47623
|
+
const encoding = requestEncoding(entry2);
|
|
47516
47624
|
return fail5(`Captured ${part} for c${item.seq} cannot be authored. Media type: ${encoding.mediaType}; encoding: ${encoding.encoding}. ${encoding.reason}.
|
|
47517
47625
|
Metadata: ${candidateLine(item)}
|
|
47518
47626
|
`);
|
|
@@ -47619,7 +47727,14 @@ async function captureDraft(invocation, api, state, store, session, root2) {
|
|
|
47619
47727
|
if (!installation) return fail5("Link this installation before recording.\n");
|
|
47620
47728
|
const client = await captureClient(root2);
|
|
47621
47729
|
const contextId = "session-capture";
|
|
47622
|
-
|
|
47730
|
+
let tabs;
|
|
47731
|
+
try {
|
|
47732
|
+
tabs = await inspectTabs(client, app2.id, contextId, origin, command4(invocation, "").trim());
|
|
47733
|
+
} catch (error62) {
|
|
47734
|
+
if (error62 instanceof BrowserControlError && error62.code === "tab-inventory-unavailable") return fail5(`${error62.code} \u2014 ${error62.message}. No recording started.
|
|
47735
|
+
`, 5);
|
|
47736
|
+
throw error62;
|
|
47737
|
+
}
|
|
47623
47738
|
const intended = invocation.options.tab ?? state.browserTab(session.id, app2.id);
|
|
47624
47739
|
const tab = intended ? tabs.find((item2) => item2.selector === intended) : tabs.length === 1 ? tabs[0] : void 0;
|
|
47625
47740
|
if (!tab) return fail5(tabs.length ? `Select the app tab with --tab <selector>: ${tabs.map((item2) => item2.selector).join(", ")}. No recording started.
|
|
@@ -47848,8 +47963,8 @@ async function selectBatchCapture(invocation, api, row, root2, state) {
|
|
|
47848
47963
|
const published = transportName ? await currentResource(api, row.app_id, "transport", transportName) : null;
|
|
47849
47964
|
const transport = published?.definition;
|
|
47850
47965
|
const origin = new URL(String(item.entry.url)).origin;
|
|
47851
|
-
const
|
|
47852
|
-
if (!transport || !transport.allowedOrigins.includes(origin)) repairs.push({ path: `${
|
|
47966
|
+
const prefix3 = `/actions/${name}`;
|
|
47967
|
+
if (!transport || !transport.allowedOrigins.includes(origin)) repairs.push({ path: `${prefix3}/transport`, message: `${candidate2} requires a published connection that permits its destination.` });
|
|
47853
47968
|
const protectedFields = { query: /* @__PURE__ */ new Set(), form: /* @__PURE__ */ new Set(), body: /* @__PURE__ */ new Set(), headers: new Set((transport?.credentials ?? []).map((field) => field.header.toLowerCase())) };
|
|
47854
47969
|
for (const injection of transport?.inject ?? []) {
|
|
47855
47970
|
const target = injection.to;
|
|
@@ -47859,8 +47974,8 @@ async function selectBatchCapture(invocation, api, row, root2, state) {
|
|
|
47859
47974
|
}
|
|
47860
47975
|
const generated = draftCapturedAction(item, name, transportName, protectedFields, evidence);
|
|
47861
47976
|
Object.defineProperty(draft.actions, name, { value: generated.definition, writable: true, enumerable: true, configurable: true });
|
|
47862
|
-
repairs.push(...(generated.issues ?? []).map((issue2) => ({ path:
|
|
47863
|
-
if (!generated.definition.effect) repairs.push({ path: `${
|
|
47977
|
+
repairs.push(...(generated.issues ?? []).map((issue2) => ({ path: prefix3 + issue2.path, message: issue2.message })));
|
|
47978
|
+
if (!generated.definition.effect) repairs.push({ path: `${prefix3}/effect`, message: "Set the observed effect: read, create, update or delete." });
|
|
47864
47979
|
}
|
|
47865
47980
|
const path2 = invocation.options.out;
|
|
47866
47981
|
writeBatch(path2, draft);
|
|
@@ -48354,6 +48469,7 @@ var init_discover = __esm({
|
|
|
48354
48469
|
init_session_capture();
|
|
48355
48470
|
init_session();
|
|
48356
48471
|
init_prepared_fields();
|
|
48472
|
+
init_response_framing();
|
|
48357
48473
|
init_version();
|
|
48358
48474
|
init_baselines();
|
|
48359
48475
|
init_discovery_attribution();
|
|
@@ -49672,15 +49788,15 @@ var require_diff = __commonJS({
|
|
|
49672
49788
|
return "patch";
|
|
49673
49789
|
}
|
|
49674
49790
|
}
|
|
49675
|
-
const
|
|
49791
|
+
const prefix3 = highHasPre ? "pre" : "";
|
|
49676
49792
|
if (v1.major !== v2.major) {
|
|
49677
|
-
return
|
|
49793
|
+
return prefix3 + "major";
|
|
49678
49794
|
}
|
|
49679
49795
|
if (v1.minor !== v2.minor) {
|
|
49680
|
-
return
|
|
49796
|
+
return prefix3 + "minor";
|
|
49681
49797
|
}
|
|
49682
49798
|
if (v1.patch !== v2.patch) {
|
|
49683
|
-
return
|
|
49799
|
+
return prefix3 + "patch";
|
|
49684
49800
|
}
|
|
49685
49801
|
return "prerelease";
|
|
49686
49802
|
};
|
|
@@ -51166,7 +51282,7 @@ ${Object.entries(environment).map(([key2, value]) => `${key2}=${posixQuote(value
|
|
|
51166
51282
|
}
|
|
51167
51283
|
function readWindowsHostValues(hostName, run2 = execFileSync2) {
|
|
51168
51284
|
if (!/^[a-z0-9_]+(?:\.[a-z0-9_]+)*$/u.test(hostName)) throw new Error("Invalid native host name");
|
|
51169
|
-
const
|
|
51285
|
+
const script = `$ErrorActionPreference='Stop'; $results=@(); foreach($view in @('32','64')) {
|
|
51170
51286
|
$base=[Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::CurrentUser,[Microsoft.Win32.RegistryView]('Registry'+$view));
|
|
51171
51287
|
try {
|
|
51172
51288
|
$key=$base.OpenSubKey('Software\\Google\\Chrome\\NativeMessagingHosts\\${hostName}');
|
|
@@ -51179,7 +51295,7 @@ function readWindowsHostValues(hostName, run2 = execFileSync2) {
|
|
|
51179
51295
|
} finally { $base.Dispose(); }
|
|
51180
51296
|
}; ConvertTo-Json -InputObject @($results) -Compress`;
|
|
51181
51297
|
try {
|
|
51182
|
-
const output2 = run2("powershell.exe", ["-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand", Buffer.from(
|
|
51298
|
+
const output2 = run2("powershell.exe", ["-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand", Buffer.from(script, "utf16le").toString("base64")], { encoding: "utf8", timeout: 1e4, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
51183
51299
|
const values = JSON.parse(String(output2));
|
|
51184
51300
|
if (!Array.isArray(values) || values.length !== 2) throw new Error("Invalid registry snapshot");
|
|
51185
51301
|
return ["32", "64"].map((view) => {
|
|
@@ -51302,11 +51418,11 @@ import { dirname as dirname10, join as join22, resolve as resolve15 } from "node
|
|
|
51302
51418
|
function repairWindowsNpmLauncher(entrypoint, platform5 = process.platform) {
|
|
51303
51419
|
if (platform5 !== "win32") return;
|
|
51304
51420
|
const packageRoot = dirname10(dirname10(resolve15(entrypoint)));
|
|
51305
|
-
const
|
|
51306
|
-
const expected = join22(
|
|
51421
|
+
const prefix3 = resolve15(packageRoot, "../../..");
|
|
51422
|
+
const expected = join22(prefix3, "node_modules", "@apilift", "cli", "dist", "apilift.js");
|
|
51307
51423
|
const pkg = JSON.parse(readFileSync10(join22(packageRoot, "package.json"), "utf8"));
|
|
51308
51424
|
if (expected.toLowerCase() !== resolve15(entrypoint).toLowerCase() || pkg.name !== "@apilift/cli" || pkg.bin?.apilift?.replace(/^\.\//u, "") !== "dist/apilift.js") throw new Error("The owned Windows npm launcher could not be verified");
|
|
51309
|
-
writeFileSync14(join22(
|
|
51425
|
+
writeFileSync14(join22(prefix3, "apilift.cmd"), [
|
|
51310
51426
|
"@echo off",
|
|
51311
51427
|
"setlocal DisableDelayedExpansion",
|
|
51312
51428
|
'if exist "%~dp0node.exe" goto local_node',
|
|
@@ -51317,7 +51433,7 @@ function repairWindowsNpmLauncher(entrypoint, platform5 = process.platform) {
|
|
|
51317
51433
|
"exit /b %errorlevel%",
|
|
51318
51434
|
""
|
|
51319
51435
|
].join("\r\n"));
|
|
51320
|
-
rmSync7(join22(
|
|
51436
|
+
rmSync7(join22(prefix3, "apilift.ps1"), { force: true });
|
|
51321
51437
|
}
|
|
51322
51438
|
var init_windows_launcher = __esm({
|
|
51323
51439
|
"src/windows-launcher.ts"() {
|
|
@@ -51330,7 +51446,7 @@ import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
|
51330
51446
|
import { dirname as dirname11, join as join23, resolve as resolve16, sep, isAbsolute as isAbsolute7 } from "node:path";
|
|
51331
51447
|
import { mkdirSync as mkdirSync15, realpathSync as realpathSync5, writeFileSync as writeFileSync15, readFileSync as readFileSync11 } from "node:fs";
|
|
51332
51448
|
import { DatabaseSync as DatabaseSync8 } from "node:sqlite";
|
|
51333
|
-
function globalPackage(
|
|
51449
|
+
function globalPackage(script, prefix3) {
|
|
51334
51450
|
const canonical = (path2) => {
|
|
51335
51451
|
try {
|
|
51336
51452
|
return realpathSync5(path2);
|
|
@@ -51338,8 +51454,8 @@ function globalPackage(script2, prefix2) {
|
|
|
51338
51454
|
return resolve16(path2);
|
|
51339
51455
|
}
|
|
51340
51456
|
};
|
|
51341
|
-
const normalized = canonical(
|
|
51342
|
-
const base2 = canonical(
|
|
51457
|
+
const normalized = canonical(script).toLowerCase();
|
|
51458
|
+
const base2 = canonical(prefix3).toLowerCase();
|
|
51343
51459
|
return [join23(base2, "lib", "node_modules", "@apilift", "cli"), join23(base2, "node_modules", "@apilift", "cli")].some((path2) => normalized.startsWith(`${path2}${sep}`));
|
|
51344
51460
|
}
|
|
51345
51461
|
async function pnpmInstallations(runner, env) {
|
|
@@ -51356,9 +51472,9 @@ async function pnpmInstallations(runner, env) {
|
|
|
51356
51472
|
return [];
|
|
51357
51473
|
}
|
|
51358
51474
|
}
|
|
51359
|
-
async function installationManager(
|
|
51360
|
-
const
|
|
51361
|
-
if (
|
|
51475
|
+
async function installationManager(script, runner, env) {
|
|
51476
|
+
const prefix3 = await runner("npm", ["prefix", "-g"], 1e4, env).catch(() => null);
|
|
51477
|
+
if (prefix3?.exitCode === 0 && globalPackage(script, prefix3.stdout.trim())) return { manager: "npm", entrypoint: script };
|
|
51362
51478
|
const canonical = (path2) => {
|
|
51363
51479
|
try {
|
|
51364
51480
|
return realpathSync5(path2);
|
|
@@ -51366,18 +51482,18 @@ async function installationManager(script2, runner, env) {
|
|
|
51366
51482
|
return resolve16(path2);
|
|
51367
51483
|
}
|
|
51368
51484
|
};
|
|
51369
|
-
const selected = (await pnpmInstallations(runner, env)).find((candidate2) => canonical(candidate2.entrypoint) === canonical(
|
|
51485
|
+
const selected = (await pnpmInstallations(runner, env)).find((candidate2) => canonical(candidate2.entrypoint) === canonical(script));
|
|
51370
51486
|
return selected ? { manager: "pnpm", entrypoint: selected.entrypoint } : null;
|
|
51371
51487
|
}
|
|
51372
51488
|
async function maybeAutoUpdate(options2) {
|
|
51373
51489
|
if (options2.env.APILIFT_AUTO_UPDATE === "0" || options2.env.CI || options2.env.APILIFT_DEV_PLUGIN_ROOT || options2.env.APILIFT_UPDATE_REEXEC === "1") return null;
|
|
51374
|
-
const current = options2.current || CURRENT, runner = options2.runner || run,
|
|
51490
|
+
const current = options2.current || CURRENT, runner = options2.runner || run, script = options2.script || fileURLToPath4(import.meta.url);
|
|
51375
51491
|
if (!shouldCheckUpdate(options2.state, current)) return null;
|
|
51376
51492
|
markUpdateChecked(options2.state, current);
|
|
51377
|
-
const installation = await installationManager(
|
|
51493
|
+
const installation = await installationManager(script, runner, options2.env);
|
|
51378
51494
|
if (!installation) return null;
|
|
51379
51495
|
let updatedEntry = installation.entrypoint;
|
|
51380
|
-
const update2 = await updateCli({ ...options2, current, runner, script
|
|
51496
|
+
const update2 = await updateCli({ ...options2, current, runner, script, manual: false }, (entrypoint) => {
|
|
51381
51497
|
updatedEntry = entrypoint;
|
|
51382
51498
|
});
|
|
51383
51499
|
if (update2.stderr.startsWith("update-incomplete")) return update2;
|
|
@@ -51423,8 +51539,8 @@ No installation changes were made. Continue the app work you were working on.
|
|
|
51423
51539
|
`);
|
|
51424
51540
|
if (!options2.manual && (options2.env.APILIFT_AUTO_UPDATE === "0" || options2.env.CI || options2.env.APILIFT_DEV_PLUGIN_ROOT || options2.env.npm_execpath?.includes("npx"))) return message("", 5, `client-upgrade-required \u2014 Install Apilift ${latest} through the supported package installation, then retry.
|
|
51425
51541
|
`);
|
|
51426
|
-
const
|
|
51427
|
-
const installation = await installationManager(
|
|
51542
|
+
const script = options2.script || fileURLToPath4(import.meta.url);
|
|
51543
|
+
const installation = await installationManager(script, runner, options2.env);
|
|
51428
51544
|
if (!installation) return message("", 5, `client-upgrade-required \u2014 This CLI is not a global npm or pnpm installation. Install Apilift ${latest} through your installation method, then retry.
|
|
51429
51545
|
`);
|
|
51430
51546
|
const { manager } = installation;
|
|
@@ -51536,10 +51652,10 @@ var init_windows_installation = __esm({
|
|
|
51536
51652
|
"src/windows-installation.ts"() {
|
|
51537
51653
|
"use strict";
|
|
51538
51654
|
init_version();
|
|
51539
|
-
inspect = (
|
|
51655
|
+
inspect = (script, env) => new Promise((done, fail6) => {
|
|
51540
51656
|
const executable = `${env.SystemRoot || "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
51541
51657
|
const failures = { 11: "path-unavailable", 12: "cli-unavailable", 13: "node-unavailable", 14: "cli-failed", 15: "json-unavailable" };
|
|
51542
|
-
execFile(executable, ["-NoProfile", "-NonInteractive", "-Command",
|
|
51658
|
+
execFile(executable, ["-NoProfile", "-NonInteractive", "-Command", script], { env, windowsHide: true, timeout: 1e4, maxBuffer: 16384 }, (error62, stdout) => error62 ? fail6(new Error(error62.killed ? "fresh-shell-timeout" : `fresh-shell-${failures[Number(error62.code)] ?? `failed-${error62.code ?? "unknown"}`}`)) : done(stdout));
|
|
51543
51659
|
});
|
|
51544
51660
|
}
|
|
51545
51661
|
});
|
|
@@ -51556,8 +51672,8 @@ async function setupCheckBody(client, scopeId, value) {
|
|
|
51556
51672
|
}
|
|
51557
51673
|
}
|
|
51558
51674
|
async function registerSetupHost(root2, site, env) {
|
|
51559
|
-
const
|
|
51560
|
-
const hostScript = join24(dirname12(
|
|
51675
|
+
const script = realpathSync7(process.argv[1]);
|
|
51676
|
+
const hostScript = join24(dirname12(script), "apilift-native-host.js");
|
|
51561
51677
|
if (!existsSync9(hostScript)) throw new Error("The native host binary is missing beside the Apilift CLI");
|
|
51562
51678
|
await registerNativeHost({ root: root2, hostScript, extensionId: env.APILIFT_DEV_EXTENSION_ID || storeExtensionId, hostName: env.APILIFT_NATIVE_HOST_NAME, siteUrl: site, env });
|
|
51563
51679
|
}
|
|
@@ -51577,8 +51693,8 @@ function setupChallenge(root2, agent2, site) {
|
|
|
51577
51693
|
}
|
|
51578
51694
|
async function setupBridge(root2) {
|
|
51579
51695
|
const startedAt = Date.now();
|
|
51580
|
-
const
|
|
51581
|
-
const client = await ensureCaptureServer({ root: root2, script
|
|
51696
|
+
const script = join24(dirname12(realpathSync7(process.argv[1])), "apilift-capture-server.js");
|
|
51697
|
+
const client = await ensureCaptureServer({ root: root2, script, version: cliVersion });
|
|
51582
51698
|
if (!client.legacyBridge) await waitForBridge(root2, cliVersion, Math.max(0, 9e4 - (Date.now() - startedAt)), () => client.bridgeDemand(), client.receipt.version);
|
|
51583
51699
|
return client;
|
|
51584
51700
|
}
|
|
@@ -51796,7 +51912,7 @@ async function handle(invocation, env, fetcher, pluginInstaller, hostRegistrar,
|
|
|
51796
51912
|
}
|
|
51797
51913
|
return result2(invocation.helpTarget ? focusedCommandHelp(invocation.helpTarget) : commandHelp(Boolean(agentSession(env, invocation.sessionLabel))));
|
|
51798
51914
|
}
|
|
51799
|
-
const
|
|
51915
|
+
const prefix3 = commandPrefix(invocation.sessionLabel);
|
|
51800
51916
|
const site = siteUrl(env);
|
|
51801
51917
|
const session = agentSession(env, invocation.sessionLabel);
|
|
51802
51918
|
if (invocation.key === "setup" && invocation.options.code && !session) {
|
|
@@ -51831,12 +51947,12 @@ ${continuation}
|
|
|
51831
51947
|
if (invocation.key === "setup") {
|
|
51832
51948
|
const code = invocation.options.code;
|
|
51833
51949
|
if (!code) {
|
|
51834
|
-
if (installed) return result2(`This installation is linked. View CLI commands: ${
|
|
51835
|
-
To verify agent integration: ${
|
|
51950
|
+
if (installed) return result2(`This installation is linked. View CLI commands: ${prefix3} help commands
|
|
51951
|
+
To verify agent integration: ${prefix3} setup continue
|
|
51836
51952
|
`);
|
|
51837
51953
|
return result2(`This installation is not linked. Open ${site}/dashboard/get-started and sign in.
|
|
51838
51954
|
The page supplies a one-time code. Finish linking with that exact code:
|
|
51839
|
-
${
|
|
51955
|
+
${prefix3} setup --code <code>
|
|
51840
51956
|
`);
|
|
51841
51957
|
}
|
|
51842
51958
|
const api2 = createCliApi(site, fetcher, installed?.token, installed ? apiSessionId(installed.id, session) : void 0);
|
|
@@ -51844,7 +51960,7 @@ The page supplies a one-time code. Finish linking with that exact code:
|
|
|
51844
51960
|
const attached = await api2.call("attachAgent", { body: { code, agent: session.agent } });
|
|
51845
51961
|
new CliAnalytics(state, cliVersion, fetcher).saveOnboardingAttempt(attached.onboardingAttemptId);
|
|
51846
51962
|
return result2(`This agent is ${attached.mode} to the linked installation. Continue setup:
|
|
51847
|
-
${
|
|
51963
|
+
${prefix3} setup continue
|
|
51848
51964
|
`, 0, "", true);
|
|
51849
51965
|
}
|
|
51850
51966
|
const linked = await api2.call("createInstallation", { body: { code, agent: session.agent, machine: { label: hostname3().slice(0, 80), os: platform4(), arch: arch() } } });
|
|
@@ -51855,13 +51971,13 @@ The page supplies a one-time code. Finish linking with that exact code:
|
|
|
51855
51971
|
return result2("", 5, "local-state-failed \u2014 The linking request was sent and its one-time code may be used. The installation token could not be saved. Do not repeat the code; ask the user to revoke this machine and create a new link code.\n", true);
|
|
51856
51972
|
}
|
|
51857
51973
|
return result2(`This machine is linked to Apilift. Continue setup:
|
|
51858
|
-
${
|
|
51974
|
+
${prefix3} setup continue
|
|
51859
51975
|
`, 0, "", true);
|
|
51860
51976
|
}
|
|
51861
51977
|
if (invocation.key.startsWith("feedback")) return await handleFeedback(invocation, createCliApi(site, fetcher, installed?.token, installed ? apiSessionId(installed.id, session) : void 0), state, session);
|
|
51862
51978
|
if (!installed) return result2("", 9, `installation-required \u2014 This machine is not linked. No app request was sent.
|
|
51863
51979
|
Open ${site}/dashboard/get-started and then run:
|
|
51864
|
-
${
|
|
51980
|
+
${prefix3} setup --code <code>
|
|
51865
51981
|
`);
|
|
51866
51982
|
const api = createCliApi(site, fetcher, installed.token, apiSessionId(installed.id, session), (path2, method, value, retries) => {
|
|
51867
51983
|
metadata.registry_retries = (Number(metadata.registry_retries) || 0) + retries;
|
|
@@ -51909,16 +52025,16 @@ Keep one label for this worker, then run:
|
|
|
51909
52025
|
} catch (error62) {
|
|
51910
52026
|
return { ...result2("", 5, `plugin-install-failed \u2014 ${error62 instanceof Error ? error62.message : "The setup skill could not be installed"}.
|
|
51911
52027
|
Fix the agent plugin installation and retry:
|
|
51912
|
-
${
|
|
52028
|
+
${prefix3} setup continue
|
|
51913
52029
|
`), analytics: { code: "plugin-install-failed", stage: "setup" } };
|
|
51914
52030
|
}
|
|
51915
52031
|
if (!plugin.ready) {
|
|
51916
52032
|
const checkCommand = session.agent === "codex" ? "codex plugin list --marketplace personal --json" : "claude plugin list --json";
|
|
51917
52033
|
const next2 = plugin.checkFailed ? `Activation is unknown. Diagnose the check before changing the installation:
|
|
51918
52034
|
${checkCommand}
|
|
51919
|
-
Then retry: ${
|
|
52035
|
+
Then retry: ${prefix3} setup continue` : "To finish agent integration, verify plugin activation before continuing setup.";
|
|
51920
52036
|
return result2("", 5, `${plugin.checkFailed ? "plugin-check-failed" : "plugin-not-ready"} \u2014 ${plugin.detail}.
|
|
51921
|
-
This installation is linked. View CLI commands: ${
|
|
52037
|
+
This installation is linked. View CLI commands: ${prefix3} help commands
|
|
51922
52038
|
${next2}
|
|
51923
52039
|
`);
|
|
51924
52040
|
}
|
|
@@ -51928,11 +52044,11 @@ ${next2}
|
|
|
51928
52044
|
} catch (error62) {
|
|
51929
52045
|
return result2("", 5, `native-host-registration-failed \u2014 ${error62 instanceof Error ? error62.message : "Could not register the native host"}.
|
|
51930
52046
|
Fix the local Chrome registration and retry:
|
|
51931
|
-
${
|
|
52047
|
+
${prefix3} setup continue
|
|
51932
52048
|
`);
|
|
51933
52049
|
}
|
|
51934
52050
|
if (state.db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='discovery_capture'").get() && state.db.prepare("SELECT 1 FROM discovery_capture c JOIN discovery_draft d ON d.id=c.draft_id WHERE d.owner_session_id=? AND c.scope_id IS NOT NULL AND c.phase IN ('starting','stopping')").get(session.id) || ["starting", "stopping"].includes(new SessionCaptureStore(state).active(session.id)?.phase ?? "")) {
|
|
51935
|
-
return { ...result2(`${JSON.stringify({ action: "agent", instruction: "Settle this session's pending recording with repairCommand, then run resumeCommand. This preserves drafts and captured evidence. Do not repeat an app operation or ask the user to toggle the extension.", repairCommand: `${
|
|
52051
|
+
return { ...result2(`${JSON.stringify({ action: "agent", instruction: "Settle this session's pending recording with repairCommand, then run resumeCommand. This preserves drafts and captured evidence. Do not repeat an app operation or ask the user to toggle the extension.", repairCommand: `${prefix3} discover capture cancel`, resumeCommand: `${prefix3} setup continue` })}
|
|
51936
52052
|
`), stdoutJson: true };
|
|
51937
52053
|
}
|
|
51938
52054
|
let bridgeError, connected = false;
|
|
@@ -51942,11 +52058,11 @@ Fix the local Chrome registration and retry:
|
|
|
51942
52058
|
bridgeError = error62;
|
|
51943
52059
|
}
|
|
51944
52060
|
const readiness2 = await setupReadiness(api, connected);
|
|
51945
|
-
if (connected && (!readiness2.machine.nativeHostReady || !readiness2.machine.extensionReady)) return result2("", 5, `registry-readiness-pending \u2014 Chrome connected, but this installation's readiness report is still pending. Keep Chrome open and retry ${
|
|
52061
|
+
if (connected && (!readiness2.machine.nativeHostReady || !readiness2.machine.extensionReady)) return result2("", 5, `registry-readiness-pending \u2014 Chrome connected, but this installation's readiness report is still pending. Keep Chrome open and retry ${prefix3} setup continue.
|
|
51946
52062
|
`);
|
|
51947
|
-
if (!readiness2.machine.nativeHostReady || !readiness2.machine.extensionReady) return { ...result2(`${JSON.stringify({ action: "user", userMessage: extensionUserMessage(env.APILIFT_DEV_EXTENSION_PATH), resumeCommand: `${
|
|
52063
|
+
if (!readiness2.machine.nativeHostReady || !readiness2.machine.extensionReady) return { ...result2(`${JSON.stringify({ action: "user", userMessage: extensionUserMessage(env.APILIFT_DEV_EXTENSION_PATH), resumeCommand: `${prefix3} setup continue` })}
|
|
51948
52064
|
`), stdoutJson: true };
|
|
51949
|
-
if (bridgeError) return result2("", 5, `extension-unavailable \u2014 ${bridgeError instanceof Error ? bridgeError.message : "Chrome did not respond"}. Check native host and extension setup with ${
|
|
52065
|
+
if (bridgeError) return result2("", 5, `extension-unavailable \u2014 ${bridgeError instanceof Error ? bridgeError.message : "Chrome did not respond"}. Check native host and extension setup with ${prefix3} doctor.
|
|
51950
52066
|
`);
|
|
51951
52067
|
const challenge = setupChallenge(dataRoot(env), session.agent, site);
|
|
51952
52068
|
let check2;
|
|
@@ -51957,7 +52073,7 @@ Fix the local Chrome registration and retry:
|
|
|
51957
52073
|
}
|
|
51958
52074
|
if (!check2.ok) {
|
|
51959
52075
|
await api.call("updateReadiness", { body: { agent: session.agent, agentState: { browserReady: false, verified: false } } });
|
|
51960
|
-
return { ...result2(`${JSON.stringify({ action: "agent", reason: check2.reason, instruction: "Use this agent's browser tool to open the exact check URL in Chrome, wait for it to load, keep the tab open, then run resumeCommand. The check uses one safe GET request and changes no app state.", browserUrl: challenge.url, resumeCommand: `${
|
|
52076
|
+
return { ...result2(`${JSON.stringify({ action: "agent", reason: check2.reason, instruction: "Use this agent's browser tool to open the exact check URL in Chrome, wait for it to load, keep the tab open, then run resumeCommand. The check uses one safe GET request and changes no app state.", browserUrl: challenge.url, resumeCommand: `${prefix3} setup continue`, onBrowserUnavailable: { action: "user", userMessage: browserUserMessage(session.agent) } })}
|
|
51961
52077
|
`), stdoutJson: true };
|
|
51962
52078
|
}
|
|
51963
52079
|
await recordVerified(api, session.agent);
|
|
@@ -51985,10 +52101,10 @@ Fix the local Chrome registration and retry:
|
|
|
51985
52101
|
`Agent browser control: ${agentState?.browserReady ? "recorded ready" : "not verified"}.`,
|
|
51986
52102
|
`Stored setup verification: ${agentState?.verified && plugin?.ready ? "verified" : "incomplete"}.`
|
|
51987
52103
|
];
|
|
51988
|
-
return result2(`The Apilift registry responded. This installation is linked. View CLI commands: ${
|
|
52104
|
+
return result2(`The Apilift registry responded. This installation is linked. View CLI commands: ${prefix3} help commands
|
|
51989
52105
|
Agent integration status:
|
|
51990
52106
|
${checks.join("\n")}
|
|
51991
|
-
For browser work, check the live connection with ${
|
|
52107
|
+
For browser work, check the live connection with ${prefix3} browser check ${app2 ?? "<app>"}.
|
|
51992
52108
|
No ${app2 ? `${app2} ` : ""}app request was sent, so app credentials and browser access are not verified.
|
|
51993
52109
|
Use a browser-capable runtime for browser work. API-only work does not require a browser connection.
|
|
51994
52110
|
`);
|