@ancha-labs/cli 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ancha.mjs +5582 -3761
- package/lib/assets/harbor/companion.mjs +739 -275
- package/lib/mcp-entry.mjs +53 -1
- package/lib/worker.mjs +87855 -85279
- package/lib/world-server.mjs +738 -278
- package/package.json +1 -1
|
@@ -56519,6 +56519,8 @@ var EXECUTION_SUPPORT = {
|
|
|
56519
56519
|
"world_rules": sceneOnly,
|
|
56520
56520
|
"people": sceneOnly,
|
|
56521
56521
|
"until": sceneOnly,
|
|
56522
|
+
"trigger": sceneOnly,
|
|
56523
|
+
"tools": sceneOnly,
|
|
56522
56524
|
"deadline": sceneOnly,
|
|
56523
56525
|
"start.message": sceneOnly,
|
|
56524
56526
|
"pass": sceneOnly,
|
|
@@ -56557,7 +56559,8 @@ var EXECUTION_SUPPORT = {
|
|
|
56557
56559
|
"--pass-env": sceneOnly,
|
|
56558
56560
|
"--inherit-env": sceneOnly,
|
|
56559
56561
|
"--upload": sceneOnly,
|
|
56560
|
-
"--upload-required": sceneOnly
|
|
56562
|
+
"--upload-required": sceneOnly,
|
|
56563
|
+
"--allow-unwrapped": sceneOnly
|
|
56561
56564
|
};
|
|
56562
56565
|
|
|
56563
56566
|
// packages/core/src/relay.ts
|
|
@@ -57807,9 +57810,9 @@ function stringifyPrimitive(value4) {
|
|
|
57807
57810
|
return `"${value4}"`;
|
|
57808
57811
|
return `${value4}`;
|
|
57809
57812
|
}
|
|
57810
|
-
function optionalKeys(
|
|
57811
|
-
return Object.keys(
|
|
57812
|
-
return
|
|
57813
|
+
function optionalKeys(shape4) {
|
|
57814
|
+
return Object.keys(shape4).filter((k) => {
|
|
57815
|
+
return shape4[k]._zod.optin !== void 0 && shape4[k]._zod.optout === "optional";
|
|
57813
57816
|
});
|
|
57814
57817
|
}
|
|
57815
57818
|
var NUMBER_FORMAT_RANGES = /* @__PURE__ */ (() => ({
|
|
@@ -57858,33 +57861,33 @@ function omit(schema, mask2) {
|
|
|
57858
57861
|
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)).filter((key3) => !omitted.has(key3)));
|
|
57859
57862
|
return clone(schema, mergeDefs(currDef, { shape: newShape, checks: [] }));
|
|
57860
57863
|
}
|
|
57861
|
-
function extend(schema,
|
|
57862
|
-
if (!isPlainObject(
|
|
57864
|
+
function extend(schema, shape4) {
|
|
57865
|
+
if (!isPlainObject(shape4)) {
|
|
57863
57866
|
throw new Error("Invalid input to extend: expected a plain object");
|
|
57864
57867
|
}
|
|
57865
57868
|
const checks = schema._zod.def.checks;
|
|
57866
57869
|
const hasChecks = checks && checks.length > 0;
|
|
57867
57870
|
if (hasChecks) {
|
|
57868
57871
|
const existingShape = sourceShape(schema);
|
|
57869
|
-
for (const key3 of Reflect.ownKeys(
|
|
57872
|
+
for (const key3 of Reflect.ownKeys(shape4)) {
|
|
57870
57873
|
if (Object.getOwnPropertyDescriptor(existingShape, key3) !== void 0) {
|
|
57871
57874
|
throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
|
|
57872
57875
|
}
|
|
57873
57876
|
}
|
|
57874
57877
|
}
|
|
57875
|
-
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema,
|
|
57878
|
+
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema, shape4) }));
|
|
57876
57879
|
}
|
|
57877
|
-
function extended(schema,
|
|
57880
|
+
function extended(schema, shape4) {
|
|
57878
57881
|
const newShape = {};
|
|
57879
57882
|
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)));
|
|
57880
|
-
mirrorProps(newShape,
|
|
57883
|
+
mirrorProps(newShape, shape4);
|
|
57881
57884
|
return newShape;
|
|
57882
57885
|
}
|
|
57883
|
-
function safeExtend(schema,
|
|
57884
|
-
if (!isPlainObject(
|
|
57886
|
+
function safeExtend(schema, shape4) {
|
|
57887
|
+
if (!isPlainObject(shape4)) {
|
|
57885
57888
|
throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
57886
57889
|
}
|
|
57887
|
-
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema,
|
|
57890
|
+
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema, shape4) }));
|
|
57888
57891
|
}
|
|
57889
57892
|
function merge(a, b) {
|
|
57890
57893
|
if (!b?._zod?.def) {
|
|
@@ -60332,10 +60335,10 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
60332
60335
|
}
|
|
60333
60336
|
const _normalized = cached(() => normalizeDef(def));
|
|
60334
60337
|
defineLazyInternal(inst, "propValues", (zod) => {
|
|
60335
|
-
const
|
|
60338
|
+
const shape4 = zod.def.shape;
|
|
60336
60339
|
const propValues = {};
|
|
60337
|
-
for (const key3 in
|
|
60338
|
-
const field3 =
|
|
60340
|
+
for (const key3 in shape4) {
|
|
60341
|
+
const field3 = shape4[key3]._zod;
|
|
60339
60342
|
if (field3.values) {
|
|
60340
60343
|
if (!Object.prototype.hasOwnProperty.call(propValues, key3)) {
|
|
60341
60344
|
assignProp(propValues, key3, /* @__PURE__ */ new Set());
|
|
@@ -60367,7 +60370,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
60367
60370
|
}
|
|
60368
60371
|
payload2.value = memo3 ? memo3.alloc(inst, payload2, {}, ctx) : {};
|
|
60369
60372
|
const proms = [];
|
|
60370
|
-
const
|
|
60373
|
+
const shape4 = value4.shape;
|
|
60371
60374
|
const abortEarly = ctx?.abortEarly;
|
|
60372
60375
|
let seen = payload2.issues.length;
|
|
60373
60376
|
for (const key3 of value4.allKeys) {
|
|
@@ -60378,7 +60381,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
60378
60381
|
}
|
|
60379
60382
|
if (key3 === "__proto__")
|
|
60380
60383
|
continue;
|
|
60381
|
-
const el2 =
|
|
60384
|
+
const el2 = shape4[key3];
|
|
60382
60385
|
const optin = el2._zod.optin;
|
|
60383
60386
|
const optout = el2._zod.optout;
|
|
60384
60387
|
const r = el2._zod.run({ value: input2[key3], issues: [] }, ctx);
|
|
@@ -60399,10 +60402,10 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
60399
60402
|
const superParse = inst._zod.parse;
|
|
60400
60403
|
const _normalized = cached(() => normalizeDef(def));
|
|
60401
60404
|
const memo3 = globalConfig.memoizer;
|
|
60402
|
-
const generateFastpass = (
|
|
60405
|
+
const generateFastpass = (shape4) => {
|
|
60403
60406
|
const normalized = _normalized.value;
|
|
60404
60407
|
const syms = normalized.symbolKeys;
|
|
60405
|
-
const doc = new Doc(["payload", "ctx"], { shape:
|
|
60408
|
+
const doc = new Doc(["payload", "ctx"], { shape: shape4, inst, memo: memo3, syms });
|
|
60406
60409
|
const parseStr = (k) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
|
|
60407
60410
|
const prefixStr = (id12, k) => `
|
|
60408
60411
|
let ${id12}_ab = false;
|
|
@@ -60429,7 +60432,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
60429
60432
|
const id12 = ids2[key3];
|
|
60430
60433
|
const k = typeof key3 === "symbol" ? `syms[${syms.indexOf(key3)}]` : esc(key3);
|
|
60431
60434
|
const isPresent = `${k} in input`;
|
|
60432
|
-
const schema =
|
|
60435
|
+
const schema = shape4[key3];
|
|
60433
60436
|
const optin = schema?._zod?.optin;
|
|
60434
60437
|
const isOptionalIn = optin !== void 0;
|
|
60435
60438
|
const isOptionalOut = schema?._zod?.optout === "optional";
|
|
@@ -61868,7 +61871,7 @@ function isRecursive(inst, stack, resolve5) {
|
|
|
61868
61871
|
result = answer;
|
|
61869
61872
|
}
|
|
61870
61873
|
};
|
|
61871
|
-
const
|
|
61874
|
+
const shape4 = (sh, spread) => {
|
|
61872
61875
|
let answer = NONE;
|
|
61873
61876
|
for (const key3 of Reflect.ownKeys(sh)) {
|
|
61874
61877
|
const desc = Object.getOwnPropertyDescriptor(sh, key3);
|
|
@@ -61889,7 +61892,7 @@ function isRecursive(inst, stack, resolve5) {
|
|
|
61889
61892
|
switch (kind) {
|
|
61890
61893
|
case "object": {
|
|
61891
61894
|
const raw3 = rawShape(def);
|
|
61892
|
-
merge3(raw3 ?
|
|
61895
|
+
merge3(raw3 ? shape4(raw3, true) : ASSUMED);
|
|
61893
61896
|
check3(def.catchall);
|
|
61894
61897
|
break;
|
|
61895
61898
|
}
|
|
@@ -70100,12 +70103,12 @@ function generatePropertiesChecks(doc, ctx, def, accessor) {
|
|
|
70100
70103
|
throw new ZodCompileUnsupportedError(`check with a custom "when" condition`);
|
|
70101
70104
|
}
|
|
70102
70105
|
doc.write(`if (${accessor} == null) return INVALID;`);
|
|
70103
|
-
const
|
|
70104
|
-
for (const key3 of Reflect.ownKeys(
|
|
70106
|
+
const shape4 = def.shape;
|
|
70107
|
+
for (const key3 of Reflect.ownKeys(shape4)) {
|
|
70105
70108
|
const keyExpr = typeof key3 === "symbol" ? addConstant(ctx, key3) : esc(key3);
|
|
70106
70109
|
const inputVar = newVar(ctx);
|
|
70107
70110
|
doc.write(`const ${inputVar} = ${accessor}[${keyExpr}];`);
|
|
70108
|
-
compileChild(doc, ctx,
|
|
70111
|
+
compileChild(doc, ctx, shape4[key3], inputVar, false);
|
|
70109
70112
|
}
|
|
70110
70113
|
}
|
|
70111
70114
|
function generatePropertyCheck(doc, ctx, def, accessor) {
|
|
@@ -70487,13 +70490,13 @@ function generateDateCheck(doc, accessor) {
|
|
|
70487
70490
|
function generateObjectCheck(doc, ctx, schema, accessor, buildsValue = true) {
|
|
70488
70491
|
const def = schema._zod.def;
|
|
70489
70492
|
doc.write(`if (typeof ${accessor} !== "object" || ${accessor} === null || Array.isArray(${accessor})) return INVALID;`);
|
|
70490
|
-
const
|
|
70491
|
-
const keys5 = Object.keys(
|
|
70492
|
-
const symbolKeys = Object.getOwnPropertySymbols(
|
|
70493
|
+
const shape4 = def.shape;
|
|
70494
|
+
const keys5 = Object.keys(shape4);
|
|
70495
|
+
const symbolKeys = Object.getOwnPropertySymbols(shape4);
|
|
70493
70496
|
const allKeys = symbolKeys.length ? [...keys5, ...symbolKeys] : keys5;
|
|
70494
70497
|
const keyExpr = (k) => typeof k === "symbol" ? addConstant(ctx, k) : esc(k);
|
|
70495
70498
|
const propKey = (k) => typeof k === "symbol" ? `[${keyExpr(k)}]` : esc(k);
|
|
70496
|
-
const propShape =
|
|
70499
|
+
const propShape = shape4;
|
|
70497
70500
|
if (keys5.includes("__proto__")) {
|
|
70498
70501
|
throw new ZodCompileUnsupportedError('object shape key "__proto__"');
|
|
70499
70502
|
}
|
|
@@ -72000,10 +72003,10 @@ function _property(property3, schema, params9) {
|
|
|
72000
72003
|
});
|
|
72001
72004
|
}
|
|
72002
72005
|
// @__NO_SIDE_EFFECTS__
|
|
72003
|
-
function _properties(
|
|
72006
|
+
function _properties(shape4, params9) {
|
|
72004
72007
|
return new $ZodCheckProperties({
|
|
72005
72008
|
check: "properties",
|
|
72006
|
-
shape:
|
|
72009
|
+
shape: shape4,
|
|
72007
72010
|
...normalizeParams(params9)
|
|
72008
72011
|
});
|
|
72009
72012
|
}
|
|
@@ -73265,21 +73268,21 @@ function inputOptin(schema) {
|
|
|
73265
73268
|
var objectProcessor = (schema, ctx, _json, params9) => {
|
|
73266
73269
|
const json30 = _json;
|
|
73267
73270
|
const def = schema._zod.def;
|
|
73268
|
-
const
|
|
73269
|
-
const symbolKeys = Object.getOwnPropertySymbols(
|
|
73271
|
+
const shape4 = def.shape;
|
|
73272
|
+
const symbolKeys = Object.getOwnPropertySymbols(shape4);
|
|
73270
73273
|
if (symbolKeys.length && handleUnrepresentable(schema, ctx, json30, params9, "Symbol keys cannot be represented in JSON Schema")) {
|
|
73271
73274
|
return;
|
|
73272
73275
|
}
|
|
73273
73276
|
json30.type = "object";
|
|
73274
73277
|
json30.properties = {};
|
|
73275
|
-
for (const key3 in
|
|
73276
|
-
assignProp(json30.properties, key3, processSchema(
|
|
73278
|
+
for (const key3 in shape4) {
|
|
73279
|
+
assignProp(json30.properties, key3, processSchema(shape4[key3], ctx, {
|
|
73277
73280
|
...params9,
|
|
73278
73281
|
path: [...params9.path, "properties", key3]
|
|
73279
73282
|
}));
|
|
73280
73283
|
}
|
|
73281
73284
|
const requiredKeys = [];
|
|
73282
|
-
for (const key3 of Object.keys(
|
|
73285
|
+
for (const key3 of Object.keys(shape4)) {
|
|
73283
73286
|
const field3 = def.shape[key3];
|
|
73284
73287
|
if (ctx.io === "input" ? inputOptin(field3) === void 0 : field3._zod.optout === void 0) {
|
|
73285
73288
|
requiredKeys.push(key3);
|
|
@@ -74841,8 +74844,8 @@ function array(element, params9) {
|
|
|
74841
74844
|
return _array(ZodArray, element, params9);
|
|
74842
74845
|
}
|
|
74843
74846
|
function keyof(schema) {
|
|
74844
|
-
const
|
|
74845
|
-
return _enum2(Object.keys(
|
|
74847
|
+
const shape4 = schema._zod.def.shape;
|
|
74848
|
+
return _enum2(Object.keys(shape4));
|
|
74846
74849
|
}
|
|
74847
74850
|
var ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
|
|
74848
74851
|
_ensureDefaultMemoizer();
|
|
@@ -74894,26 +74897,26 @@ var ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
|
|
|
74894
74897
|
return util_exports.required(ZodNonOptional, this, args[0]);
|
|
74895
74898
|
}
|
|
74896
74899
|
});
|
|
74897
|
-
function object(
|
|
74900
|
+
function object(shape4, params9) {
|
|
74898
74901
|
const def = {
|
|
74899
74902
|
type: "object",
|
|
74900
|
-
shape:
|
|
74903
|
+
shape: shape4 ?? {},
|
|
74901
74904
|
...util_exports.normalizeParams(params9)
|
|
74902
74905
|
};
|
|
74903
74906
|
return new ZodObject(def);
|
|
74904
74907
|
}
|
|
74905
|
-
function strictObject(
|
|
74908
|
+
function strictObject(shape4, params9) {
|
|
74906
74909
|
return new ZodObject({
|
|
74907
74910
|
type: "object",
|
|
74908
|
-
shape:
|
|
74911
|
+
shape: shape4,
|
|
74909
74912
|
catchall: never(),
|
|
74910
74913
|
...util_exports.normalizeParams(params9)
|
|
74911
74914
|
});
|
|
74912
74915
|
}
|
|
74913
|
-
function looseObject(
|
|
74916
|
+
function looseObject(shape4, params9) {
|
|
74914
74917
|
return new ZodObject({
|
|
74915
74918
|
type: "object",
|
|
74916
|
-
shape:
|
|
74919
|
+
shape: shape4,
|
|
74917
74920
|
catchall: unknown(),
|
|
74918
74921
|
...util_exports.normalizeParams(params9)
|
|
74919
74922
|
});
|
|
@@ -75452,8 +75455,8 @@ var meta2 = meta;
|
|
|
75452
75455
|
var ZodInstanceOf = /* @__PURE__ */ $constructor("ZodInstanceOf", (inst, def) => {
|
|
75453
75456
|
ZodCustom.init(inst, def);
|
|
75454
75457
|
}, {
|
|
75455
|
-
properties(
|
|
75456
|
-
return this.check(_properties(
|
|
75458
|
+
properties(shape4, params9) {
|
|
75459
|
+
return this.check(_properties(shape4, params9));
|
|
75457
75460
|
}
|
|
75458
75461
|
});
|
|
75459
75462
|
function _instanceof(cls, params9 = {}) {
|
|
@@ -76039,13 +76042,13 @@ function convertBaseSchema(schema, ctx) {
|
|
|
76039
76042
|
break;
|
|
76040
76043
|
}
|
|
76041
76044
|
case "object": {
|
|
76042
|
-
const
|
|
76045
|
+
const shape4 = {};
|
|
76043
76046
|
const properties2 = schema.properties || {};
|
|
76044
76047
|
const requiredSet = new Set(schema.required || []);
|
|
76045
76048
|
const additionalSchema = typeof schema.additionalProperties === "object" ? convertSchema(schema.additionalProperties, ctx) : void 0;
|
|
76046
76049
|
for (const [key3, propSchema] of Object.entries(properties2)) {
|
|
76047
76050
|
const propZodSchema = convertSchema(propSchema, ctx);
|
|
76048
|
-
assignProp(
|
|
76051
|
+
assignProp(shape4, key3, requiredSet.has(key3) ? propZodSchema : propZodSchema.optional());
|
|
76049
76052
|
}
|
|
76050
76053
|
if (schema.patternProperties) {
|
|
76051
76054
|
const patternProps = schema.patternProperties;
|
|
@@ -76057,8 +76060,8 @@ function convertBaseSchema(schema, ctx) {
|
|
|
76057
76060
|
looseRecords.push(z.looseRecord(keySchema, patternValue));
|
|
76058
76061
|
}
|
|
76059
76062
|
const schemasToIntersect = [];
|
|
76060
|
-
if (Object.keys(
|
|
76061
|
-
schemasToIntersect.push(z.object(
|
|
76063
|
+
if (Object.keys(shape4).length > 0) {
|
|
76064
|
+
schemasToIntersect.push(z.object(shape4).passthrough());
|
|
76062
76065
|
}
|
|
76063
76066
|
schemasToIntersect.push(...looseRecords);
|
|
76064
76067
|
if (schemasToIntersect.length === 0) {
|
|
@@ -76073,7 +76076,7 @@ function convertBaseSchema(schema, ctx) {
|
|
|
76073
76076
|
zodSchema = result;
|
|
76074
76077
|
}
|
|
76075
76078
|
if (schema.additionalProperties === false) {
|
|
76076
|
-
const propertyKeys = Object.keys(
|
|
76079
|
+
const propertyKeys = Object.keys(shape4);
|
|
76077
76080
|
const patterns = patternKeys.map((p2) => new RegExp(p2));
|
|
76078
76081
|
const basePatternSchema = zodSchema;
|
|
76079
76082
|
zodSchema = zodSchema.check((payload2) => {
|
|
@@ -76098,7 +76101,7 @@ function convertBaseSchema(schema, ctx) {
|
|
|
76098
76101
|
});
|
|
76099
76102
|
}
|
|
76100
76103
|
} else {
|
|
76101
|
-
const objectSchema = z.object(
|
|
76104
|
+
const objectSchema = z.object(shape4);
|
|
76102
76105
|
if (schema.additionalProperties === false) {
|
|
76103
76106
|
zodSchema = objectSchema.strict();
|
|
76104
76107
|
} else if (additionalSchema) {
|
|
@@ -84950,6 +84953,53 @@ var TraceCheckSchema = external_exports.strictObject({
|
|
|
84950
84953
|
message: "status applies to called; not_called always counts every attempt",
|
|
84951
84954
|
path: ["status"]
|
|
84952
84955
|
});
|
|
84956
|
+
var TOOL_NAME_PATTERN = /^[A-Za-z_][\w.-]{0,127}$/;
|
|
84957
|
+
var ToolObservationSchema = external_exports.strictObject({
|
|
84958
|
+
tool: external_exports.string().regex(TOOL_NAME_PATTERN),
|
|
84959
|
+
at: duration6("Offset from the start of the production trace, e.g. 3s200ms"),
|
|
84960
|
+
/** When the call returned, as an offset like `at`: a test that reaches this answer has reached that time. */
|
|
84961
|
+
end: duration6("Offset from the start of the production trace when the call returned").optional(),
|
|
84962
|
+
args: external_exports.unknown().optional(),
|
|
84963
|
+
/** What the tool function returned. A recorded failure has `error` instead. */
|
|
84964
|
+
result: external_exports.unknown().optional(),
|
|
84965
|
+
error: external_exports.string().optional(),
|
|
84966
|
+
/** The framework's envelope as the trace held it (an MCP CallToolResult, a LangChain ToolMessage), for replay over MCP. */
|
|
84967
|
+
wrap: external_exports.enum(["mcp", "langchain", "output"]).optional(),
|
|
84968
|
+
raw: external_exports.unknown().optional(),
|
|
84969
|
+
call_id: external_exports.string().optional()
|
|
84970
|
+
}).refine((o) => o.error === void 0 || o.result === void 0, { message: "a recorded call has a result or an error, not both" });
|
|
84971
|
+
var ToolExampleSchema = external_exports.strictObject({
|
|
84972
|
+
trace: external_exports.string().optional(),
|
|
84973
|
+
at: duration6("Offset from the start of that trace"),
|
|
84974
|
+
args: external_exports.unknown().optional(),
|
|
84975
|
+
result: external_exports.unknown().optional(),
|
|
84976
|
+
error: external_exports.string().optional()
|
|
84977
|
+
});
|
|
84978
|
+
var SceneToolSchema = external_exports.strictObject({
|
|
84979
|
+
/** A JSON lines file next to the scene, one recorded call per line (`ancha run` reads it into `recorded`). */
|
|
84980
|
+
observations: external_exports.string().regex(/^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[^\0]+$/, "a path relative to the scene file, without ..").optional(),
|
|
84981
|
+
recorded: external_exports.array(ToolObservationSchema).optional(),
|
|
84982
|
+
/** Calls from other traces of this agent, so a simulated answer can follow how the tool behaved there. */
|
|
84983
|
+
examples: external_exports.array(ToolExampleSchema).optional(),
|
|
84984
|
+
/** A call production never made: simulated (the default for a read), a tool error (the default for a write), or the twin. */
|
|
84985
|
+
unrecorded: external_exports.enum(["simulate", "fail", "twin"]).optional(),
|
|
84986
|
+
/** The twin that answers what production never recorded (TRACE_PLAN_V2 §5.3). */
|
|
84987
|
+
twin: external_exports.string().optional(),
|
|
84988
|
+
/** The agent reaches this tool over MCP: in a test its client points at {{tools.mcp_url}}, so there is nothing to wrap. */
|
|
84989
|
+
mcp: external_exports.literal(true).optional(),
|
|
84990
|
+
/** `ancha run --allow-unwrapped`: the agent may call this tool for real (it does not wrap it), so the test does not stop. */
|
|
84991
|
+
allow_unwrapped: external_exports.literal(true).optional(),
|
|
84992
|
+
/** Changes something (a refund, an email): an unrecorded call is never answered by invention unless set to simulate. */
|
|
84993
|
+
write: external_exports.boolean().optional(),
|
|
84994
|
+
/** Only computes from its arguments (a calculator): a call production never made runs the tool itself, for real. */
|
|
84995
|
+
pure: external_exports.literal(true).optional(),
|
|
84996
|
+
description: external_exports.string().optional(),
|
|
84997
|
+
schema: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
84998
|
+
});
|
|
84999
|
+
var TriggerSchema = external_exports.strictObject({
|
|
85000
|
+
task: external_exports.string().optional(),
|
|
85001
|
+
input: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
85002
|
+
});
|
|
84953
85003
|
var CheckSchema = external_exports.union([
|
|
84954
85004
|
external_exports.strictObject({ id: external_exports.string(), state: StateCheckSchema }),
|
|
84955
85005
|
external_exports.strictObject({ id: external_exports.string(), trace: TraceCheckSchema }),
|
|
@@ -84971,6 +85021,8 @@ var SceneSchema = external_exports.strictObject({
|
|
|
84971
85021
|
skip_idle: external_exports.boolean().optional(),
|
|
84972
85022
|
timeout: duration6("Per-trial time budget, e.g. 5m").default("5m"),
|
|
84973
85023
|
task: external_exports.string().optional(),
|
|
85024
|
+
trigger: TriggerSchema.optional(),
|
|
85025
|
+
tools: external_exports.record(external_exports.string().regex(TOOL_NAME_PATTERN, "a tool name as the model saw it"), SceneToolSchema).optional(),
|
|
84974
85026
|
seed: external_exports.strictObject({ slack: SlackSeedSchema.optional(), github: GitHubSeedSchema.optional(), datadog: DatadogSeedSchema.optional(), pagerduty: PagerDutySeedSchema.optional(), "linkedin-ads": LinkedInAdsSeedSchema.optional(), salesforce: SalesforceSeedSchema.optional(), gong: GongSeedSchema.optional(), hubspot: HubSpotSeedSchema.optional(), ga4: GA4SeedSchema.optional(), "google-ads": GoogleAdsSeedSchema.optional(), "chatgpt-ads": ChatGPTAdsSeedSchema.optional(), "open-meteo": OpenMeteoSeedSchema.optional(), "google-drive": GoogleDriveSeedSchema.optional(), gmail: GmailSeedSchema.optional(), "amazon-s3": AmazonS3SeedSchema.optional(), linear: LinearSeedSchema.optional(), "okta": OktaSeedSchema.optional(), stripe: StripeSeedSchema.optional(), "clerk": ClerkSeedSchema.optional(), "better-stack": BetterStackSeedSchema.optional(), notion: NotionSeedSchema.optional(), attio: AttioSeedSchema.optional(), "dropbox": DropboxSeedSchema.optional(), resend: ResendSeedSchema.optional(), "microsoft-word": MicrosoftWordSeedSchema.optional(), shopify: ShopifySeedSchema.optional(), "lob": LobSeedSchema.optional(), paypal: PayPalSeedSchema.optional(), jira: JiraSeedSchema.optional(), "kalshi": KalshiSeedSchema.optional(), intercom: IntercomSeedSchema.optional(), "zendesk": ZendeskSeedSchema.optional(), "google-calendar": GoogleCalendarSeedSchema.optional(), "twilio": TwilioSeedSchema.optional(), "asana": AsanaSeedSchema.optional(), "discord": DiscordSeedSchema.optional(), sentry: SentrySeedSchema.optional(), "airtable": AirtableSeedSchema.optional() }),
|
|
84975
85027
|
world_rules: external_exports.strictObject({ actors: external_exports.array(ActorSchema).optional(), app_calls: external_exports.array(AppCallSchema).optional(), pipelines: external_exports.array(PipelineRuleSchema).optional(), faults: external_exports.array(FaultRuleSchema).optional(), metrics: external_exports.array(MetricRuleSchema).optional(), logs: external_exports.array(LogRuleSchema).optional(), monitors: external_exports.array(MonitorRuleSchema).optional(), integrations: external_exports.array(IntegrationSchema).optional() }).optional(),
|
|
84976
85028
|
people: PeopleSchema.optional(),
|
|
@@ -86103,6 +86155,37 @@ function twinIssues(scene2) {
|
|
|
86103
86155
|
});
|
|
86104
86156
|
return issues;
|
|
86105
86157
|
}
|
|
86158
|
+
function toolIssues(scene2) {
|
|
86159
|
+
const issues = [];
|
|
86160
|
+
for (const [name5, tool] of Object.entries(scene2.tools ?? {})) {
|
|
86161
|
+
const path4 = `tools.${name5}`;
|
|
86162
|
+
if (tool.twin !== void 0) {
|
|
86163
|
+
if (!isTwinName(tool.twin)) issues.push({ path: `${path4}.twin`, message: `unsupported twin ${tool.twin}`, hint: `supported twins: ${SUPPORTED_TWINS.join(", ")}` });
|
|
86164
|
+
else if (!scene2.twins.includes(tool.twin)) issues.push({ path: `${path4}.twin`, message: `twin ${tool.twin} is not listed in twins`, hint: `add ${tool.twin} to twins, e.g. twins: [${tool.twin}]` });
|
|
86165
|
+
}
|
|
86166
|
+
if (tool.unrecorded === "twin" && tool.twin === void 0) issues.push({ path: `${path4}.unrecorded`, message: "unrecorded: twin needs the twin that answers", hint: `set ${path4}.twin, e.g. twin: slack` });
|
|
86167
|
+
if (tool.pure && tool.write) issues.push({ path: `${path4}.pure`, message: "a tool that changes something is not pure", hint: `remove ${path4}.pure, or ${path4}.write if it only computes from its arguments` });
|
|
86168
|
+
if (tool.observations !== void 0 && tool.recorded === void 0) {
|
|
86169
|
+
issues.push({ path: `${path4}.observations`, message: `${tool.observations} was not read`, hint: "load the scene from its file (ancha run, ancha scene validate), which reads the recorded calls next to it" });
|
|
86170
|
+
}
|
|
86171
|
+
tool.recorded?.forEach((o, i) => {
|
|
86172
|
+
if (o.tool !== name5) issues.push({ path: `${path4}.recorded[${i}].tool`, message: `a call to ${o.tool} recorded under ${name5}` });
|
|
86173
|
+
});
|
|
86174
|
+
}
|
|
86175
|
+
if (scene2.tools && Object.keys(scene2.tools).length) {
|
|
86176
|
+
scene2.checks.forEach((check3, i) => {
|
|
86177
|
+
if (!("trace" in check3)) return;
|
|
86178
|
+
for (const key3 of ["called", "not_called"]) {
|
|
86179
|
+
const patterns = check3.trace[key3] === void 0 ? [] : [].concat(check3.trace[key3]);
|
|
86180
|
+
patterns.forEach((pattern) => {
|
|
86181
|
+
const bare = /^([A-Za-z_][\w.-]{0,127})(?:\s+\{.*\})?$/s.exec(pattern.trim());
|
|
86182
|
+
if (bare && !scene2.tools[bare[1]]) issues.push({ path: `checks[${i}].trace.${key3}`, message: `${bare[1]} is not one of this scene's tools`, hint: `the tools are ${Object.keys(scene2.tools).join(", ")}; an API call is "<METHOD> <PATH>"` });
|
|
86183
|
+
});
|
|
86184
|
+
}
|
|
86185
|
+
});
|
|
86186
|
+
}
|
|
86187
|
+
return issues;
|
|
86188
|
+
}
|
|
86106
86189
|
function refName5(ref20) {
|
|
86107
86190
|
try {
|
|
86108
86191
|
return parseRef(ref20).name;
|
|
@@ -86484,7 +86567,7 @@ function parseScene(input2) {
|
|
|
86484
86567
|
throw shapeError(parsed3.error.issues.flatMap((issue5) => fromZodIssue(issue5, [], input2)));
|
|
86485
86568
|
}
|
|
86486
86569
|
const scene2 = parsed3.data;
|
|
86487
|
-
const issues = [...twinIssues(scene2), ...validateRefs(scene2), ...ruleIssues(scene2), ...worldIssues(scene2), ...peopleIssues(scene2)];
|
|
86570
|
+
const issues = [...twinIssues(scene2), ...toolIssues(scene2), ...validateRefs(scene2), ...ruleIssues(scene2), ...worldIssues(scene2), ...peopleIssues(scene2)];
|
|
86488
86571
|
if (issues.length > 0) throw sceneError(issues);
|
|
86489
86572
|
const pd = scene2.seed.pagerduty;
|
|
86490
86573
|
if (pd && pd.default_service === void 0 && pd.services.length === 1) pd.default_service = `$${pd.services[0].ref}`;
|
|
@@ -86494,6 +86577,7 @@ function parseScene(input2) {
|
|
|
86494
86577
|
if (link5.from === "datadog" && link5.handle === void 0 && service) link5.handle = `pagerduty-${service.name}`;
|
|
86495
86578
|
if (link5.from === "pagerduty" && link5.channel === void 0 && service?.slack_channel !== void 0) link5.channel = service.slack_channel;
|
|
86496
86579
|
});
|
|
86580
|
+
if (scene2.task === void 0 && scene2.trigger?.task !== void 0) scene2.task = scene2.trigger.task;
|
|
86497
86581
|
return { ...scene2, twins: scene2.twins.filter(isTwinName), pass: scene2.pass ?? scene2.checks.map((c) => c.id) };
|
|
86498
86582
|
}
|
|
86499
86583
|
var ChecksSchema = external_exports.array(CheckSchema);
|
|
@@ -86513,6 +86597,54 @@ function parseChecks(input2) {
|
|
|
86513
86597
|
{ hint: "run `ancha scene schema` for the check format" }
|
|
86514
86598
|
);
|
|
86515
86599
|
}
|
|
86600
|
+
var PROSE_KEYS = /* @__PURE__ */ new Set(["judge", "task", "text", "value", "about", "message"]);
|
|
86601
|
+
var FIX_SHOWN = 120;
|
|
86602
|
+
function cutProseIssues(doc, text21, lineCounter) {
|
|
86603
|
+
const issues = [];
|
|
86604
|
+
(0, import_yaml.visit)(doc, {
|
|
86605
|
+
Pair(_, pair, ancestors2) {
|
|
86606
|
+
const value4 = pair.value;
|
|
86607
|
+
if (!(0, import_yaml.isScalar)(pair.key) || !PROSE_KEYS.has(String(pair.key.value)) || !(0, import_yaml.isScalar)(value4)) return;
|
|
86608
|
+
if (value4.type !== "PLAIN" || typeof value4.value !== "string" || !value4.range) return;
|
|
86609
|
+
const comment8 = /^[ \t]+#([^\r\n]*)/.exec(text21.slice(value4.range[1]));
|
|
86610
|
+
if (comment8 === null) return;
|
|
86611
|
+
const key3 = String(pair.key.value);
|
|
86612
|
+
const { line: line2 } = lineCounter.linePos(value4.range[0]);
|
|
86613
|
+
const meant = `${value4.value} #${comment8[1].trimEnd()}`;
|
|
86614
|
+
const fix = `${key3}: ${JSON.stringify(meant)}`;
|
|
86615
|
+
issues.push({
|
|
86616
|
+
path: `${pathOf(ancestors2, pair)} (line ${line2})`,
|
|
86617
|
+
message: `the text stops at " #": YAML reads ${JSON.stringify(`#${comment8[1].trimEnd()}`)} as a comment and keeps only ${JSON.stringify(value4.value)}`,
|
|
86618
|
+
hint: fix.length <= FIX_SHOWN ? `quote the text: ${fix}` : `quote the text, e.g. ${key3}: "\u2026", or write it as a block under ${key3}: |`
|
|
86619
|
+
});
|
|
86620
|
+
}
|
|
86621
|
+
});
|
|
86622
|
+
return issues;
|
|
86623
|
+
}
|
|
86624
|
+
function pathOf(ancestors2, pair) {
|
|
86625
|
+
const segments2 = [];
|
|
86626
|
+
ancestors2.forEach((node5, i) => {
|
|
86627
|
+
if ((0, import_yaml.isPair)(node5) && (0, import_yaml.isScalar)(node5.key)) segments2.push(String(node5.key.value));
|
|
86628
|
+
else if ((0, import_yaml.isSeq)(node5)) segments2.push(node5.items.indexOf(ancestors2[i + 1] ?? pair));
|
|
86629
|
+
});
|
|
86630
|
+
return formatPath([...segments2, String(pair.key.value)]);
|
|
86631
|
+
}
|
|
86632
|
+
function parseSceneYaml(text21) {
|
|
86633
|
+
const lineCounter = new import_yaml.LineCounter();
|
|
86634
|
+
const doc = (0, import_yaml.parseDocument)(text21, { lineCounter, prettyErrors: false });
|
|
86635
|
+
if (doc.errors.length > 0) {
|
|
86636
|
+
const issues = doc.errors.map((e) => {
|
|
86637
|
+
const { line: line2, col } = lineCounter.linePos(e.pos[0]);
|
|
86638
|
+
return { path: `line ${line2}, column ${col}`, message: e.message };
|
|
86639
|
+
});
|
|
86640
|
+
const atError = doc.errors.findIndex((e) => text21[e.pos[0]] === "@");
|
|
86641
|
+
if (atError >= 0) issues[atError].hint = "scene refs use $, e.g. $alice \u2014 YAML reserves @";
|
|
86642
|
+
throw sceneError(issues, doc.errors[0]);
|
|
86643
|
+
}
|
|
86644
|
+
const cut = cutProseIssues(doc, text21, lineCounter);
|
|
86645
|
+
if (cut.length > 0) throw sceneError(cut);
|
|
86646
|
+
return doc.toJS();
|
|
86647
|
+
}
|
|
86516
86648
|
|
|
86517
86649
|
// packages/core/src/harness-issues.ts
|
|
86518
86650
|
function collectHarnessIssues(trace, checks) {
|
|
@@ -87160,6 +87292,10 @@ function toolConnectionEnvironment(services2) {
|
|
|
87160
87292
|
for (const [key3, value4] of Object.entries(values2)) if (value4 !== void 0) result[key3] = value4;
|
|
87161
87293
|
};
|
|
87162
87294
|
switch (tool) {
|
|
87295
|
+
case "tools":
|
|
87296
|
+
add({ ANCHA_TOOLS_URL: s.url, ANCHA_TOOLS_TOKEN: s.token });
|
|
87297
|
+
break;
|
|
87298
|
+
// the agent's own tools in a test made from a trace (TRACE_PLAN_V2 §3)
|
|
87163
87299
|
case "slack":
|
|
87164
87300
|
add({ SLACK_API_URL: s.url, SLACK_BOT_TOKEN: s.token, SLACK_SIGNING_SECRET: s.signingSecret, SLACK_APP_TOKEN: s.appToken });
|
|
87165
87301
|
break;
|
|
@@ -87606,6 +87742,7 @@ var TraceRecorder = class {
|
|
|
87606
87742
|
|
|
87607
87743
|
// packages/server/src/twin.ts
|
|
87608
87744
|
var GAP_HEADER = "x-ancha-gap";
|
|
87745
|
+
var SETUP_ISSUE_HEADER = "x-ancha-setup-issue";
|
|
87609
87746
|
var INTERNAL_ERROR_HEADER = "x-ancha-internal-error";
|
|
87610
87747
|
function gapMessage(c) {
|
|
87611
87748
|
return `ancha: not implemented: ${c.req.method} ${new URL(c.req.url).pathname}`;
|
|
@@ -88468,8 +88605,8 @@ function markHandled(env, ids2) {
|
|
|
88468
88605
|
var TABLE = "world_milestones";
|
|
88469
88606
|
var isPredicateMilestone2 = (milestone) => !("called" in milestone) && !("message" in milestone);
|
|
88470
88607
|
function milestoneKey(predicate) {
|
|
88471
|
-
const
|
|
88472
|
-
return JSON.stringify(
|
|
88608
|
+
const canonical5 = (value4) => Array.isArray(value4) ? value4.map(canonical5) : value4 !== null && typeof value4 === "object" ? Object.fromEntries(Object.keys(value4).sort().map((key3) => [key3, canonical5(value4[key3])])) : value4;
|
|
88609
|
+
return JSON.stringify(canonical5(predicate));
|
|
88473
88610
|
}
|
|
88474
88611
|
function tracked(env) {
|
|
88475
88612
|
const out = /* @__PURE__ */ new Map();
|
|
@@ -88966,7 +89103,28 @@ function evaluateWithin(env, within, calls2) {
|
|
|
88966
89103
|
|
|
88967
89104
|
// packages/server/src/checks.ts
|
|
88968
89105
|
var LIST_LIMIT = 10;
|
|
88969
|
-
var PATTERN_HINT =
|
|
89106
|
+
var PATTERN_HINT = `write "<METHOD> <PATH>" using the service-relative path, e.g. "POST /api/chat.postMessage"; * matches any run of characters, and a bare "*" matches every call; one of the agent's own tools is its name, with the arguments it must have if any, e.g. "refund_order {order_id: A-1001}"`;
|
|
89107
|
+
function contains(have, want) {
|
|
89108
|
+
if (want === null || typeof want !== "object") return String(have) === String(want);
|
|
89109
|
+
if (Array.isArray(want)) return Array.isArray(have) && want.every((w, i) => contains(have[i], w));
|
|
89110
|
+
if (have === null || typeof have !== "object" || Array.isArray(have)) return false;
|
|
89111
|
+
return Object.entries(want).every(([k, w]) => contains(have[k], w));
|
|
89112
|
+
}
|
|
89113
|
+
function toolPattern(pattern, tools) {
|
|
89114
|
+
const m = /^([A-Za-z_][\w.-]{0,127})(?:\s+(\{.*\}))?$/s.exec(pattern);
|
|
89115
|
+
if (!m || !tools?.has(m[1])) return void 0;
|
|
89116
|
+
let args;
|
|
89117
|
+
if (m[2] !== void 0) {
|
|
89118
|
+
try {
|
|
89119
|
+
args = parseSceneYaml(m[2]);
|
|
89120
|
+
} catch {
|
|
89121
|
+
args = void 0;
|
|
89122
|
+
}
|
|
89123
|
+
if (args === null || typeof args !== "object" || Array.isArray(args)) throw new AnchaError("USAGE", `invalid trace pattern "${pattern}": the arguments must be a YAML or JSON object, e.g. {order_id: A-1001}`, { hint: PATTERN_HINT });
|
|
89124
|
+
}
|
|
89125
|
+
const path4 = `/tools/${m[1]}`;
|
|
89126
|
+
return (e) => e.source === "agent" && e.service === "tools" && e.method === "POST" && e.path === path4 && (args === void 0 || contains(e.request?.args, args));
|
|
89127
|
+
}
|
|
88970
89128
|
function glob(pattern, caseInsensitive) {
|
|
88971
89129
|
const fold2 = (s) => caseInsensitive ? s.toLowerCase() : s;
|
|
88972
89130
|
const pieces = fold2(pattern).split("*");
|
|
@@ -88987,9 +89145,11 @@ function glob(pattern, caseInsensitive) {
|
|
|
88987
89145
|
return true;
|
|
88988
89146
|
};
|
|
88989
89147
|
}
|
|
88990
|
-
function compileTracePattern(p2) {
|
|
89148
|
+
function compileTracePattern(p2, tools) {
|
|
88991
89149
|
const pattern = p2.trim();
|
|
88992
89150
|
if (pattern === "*") return (e) => e.source === "agent";
|
|
89151
|
+
const tool = toolPattern(pattern, tools);
|
|
89152
|
+
if (tool) return tool;
|
|
88993
89153
|
const parts3 = /^(\S+)\s+(\S+)$/.exec(pattern);
|
|
88994
89154
|
if (!parts3) {
|
|
88995
89155
|
throw new AnchaError("USAGE", `invalid trace pattern "${p2}": expected "<METHOD> <PATH>" or "*"`, { hint: PATTERN_HINT });
|
|
@@ -89017,12 +89177,13 @@ function failure2(e) {
|
|
|
89017
89177
|
if (typeof body6 !== "object" || body6 === null) return void 0;
|
|
89018
89178
|
const r = body6;
|
|
89019
89179
|
if (e.service === "slack" && r.ok === false) return `ok: false${typeof r.error === "string" ? `, ${r.error}` : ""}`;
|
|
89180
|
+
if (e.service === "tools" && typeof r.error === "string") return `the tool's error: ${r.error}`;
|
|
89020
89181
|
if (/\/graphql$/.test(e.path) && Array.isArray(r.errors) && r.errors.length > 0 && (r.data === void 0 || r.data === null)) return "GraphQL errors";
|
|
89021
89182
|
return void 0;
|
|
89022
89183
|
}
|
|
89023
|
-
function calledPart(patterns, calls2, anyStatus) {
|
|
89184
|
+
function calledPart(patterns, calls2, anyStatus, tools) {
|
|
89024
89185
|
const hits = patterns.map((p2) => {
|
|
89025
|
-
const attempts = calls2.filter(compileTracePattern(p2));
|
|
89186
|
+
const attempts = calls2.filter(compileTracePattern(p2, tools));
|
|
89026
89187
|
return { p: p2, attempts, worked: anyStatus ? attempts : attempts.filter((e) => failure2(e) === void 0) };
|
|
89027
89188
|
});
|
|
89028
89189
|
const missing4 = hits.filter((h) => h.worked.length === 0);
|
|
@@ -89048,8 +89209,8 @@ function calledPart(patterns, calls2, anyStatus) {
|
|
|
89048
89209
|
].join(" ");
|
|
89049
89210
|
return { passed: false, expected, actual, explanation, evidence: unique2([...matched, ...failed.flatMap((h) => h.attempts)]) };
|
|
89050
89211
|
}
|
|
89051
|
-
function notCalledPart(patterns, calls2) {
|
|
89052
|
-
const matchers = patterns.map(compileTracePattern);
|
|
89212
|
+
function notCalledPart(patterns, calls2, tools) {
|
|
89213
|
+
const matchers = patterns.map((p2) => compileTracePattern(p2, tools));
|
|
89053
89214
|
const offenders = calls2.filter((c) => matchers.some((m) => m(c)));
|
|
89054
89215
|
const expected = `agent never calls ${patterns.join(" or ")}`;
|
|
89055
89216
|
if (offenders.length === 0) {
|
|
@@ -89070,13 +89231,13 @@ function notCalledPart(patterns, calls2) {
|
|
|
89070
89231
|
evidence: offenders
|
|
89071
89232
|
};
|
|
89072
89233
|
}
|
|
89073
|
-
function evaluateTrace(trace, calls2) {
|
|
89234
|
+
function evaluateTrace(trace, calls2, tools) {
|
|
89074
89235
|
const called = asList(trace.called);
|
|
89075
89236
|
const notCalled = asList(trace.not_called);
|
|
89076
89237
|
if (called.length === 0 && notCalled.length === 0) {
|
|
89077
89238
|
throw new AnchaError("USAGE", "a trace check needs at least one pattern in called or not_called", { hint: 'e.g. { called: "POST /api/chat.postMessage" }' });
|
|
89078
89239
|
}
|
|
89079
|
-
const parts3 = [...called.length > 0 ? [calledPart(called, calls2, trace.status === "any")] : [], ...notCalled.length > 0 ? [notCalledPart(notCalled, calls2)] : []];
|
|
89240
|
+
const parts3 = [...called.length > 0 ? [calledPart(called, calls2, trace.status === "any", tools)] : [], ...notCalled.length > 0 ? [notCalledPart(notCalled, calls2, tools)] : []];
|
|
89080
89241
|
return {
|
|
89081
89242
|
passed: parts3.every((p2) => p2.passed),
|
|
89082
89243
|
expected: parts3.map((p2) => p2.expected).join("; "),
|
|
@@ -89146,10 +89307,11 @@ function evaluateProcess(env, check3, calls2) {
|
|
|
89146
89307
|
if ("decided" in check3) return inspectPeoplePredicate(env, { decided: check3.decided }, atMs);
|
|
89147
89308
|
if ("message" in check3) return evaluateMessageCheck(env, check3.message);
|
|
89148
89309
|
if ("never" in check3) return evaluateNever(env, check3.never);
|
|
89149
|
-
const agent = { first: (pattern) => calls2().find(compileTracePattern(pattern)) };
|
|
89310
|
+
const agent = { first: (pattern) => calls2().find(compileTracePattern(pattern, sceneTools(env))) };
|
|
89150
89311
|
if ("before" in check3) return evaluateBefore(env, check3.before, agent);
|
|
89151
89312
|
return evaluateWithin(env, check3.within, agent);
|
|
89152
89313
|
}
|
|
89314
|
+
var sceneTools = (env) => new Set(Object.keys(env.scene.tools ?? {}));
|
|
89153
89315
|
function errored(label5, e) {
|
|
89154
89316
|
const message6 = e instanceof Error ? e.message : String(e);
|
|
89155
89317
|
const hint = e instanceof AnchaError ? e.hint : void 0;
|
|
@@ -89179,7 +89341,7 @@ function evaluateChecks(env, checks = env.scene.checks) {
|
|
|
89179
89341
|
let outcome3;
|
|
89180
89342
|
let error63;
|
|
89181
89343
|
try {
|
|
89182
|
-
outcome3 = "state" in check3 ? evaluateState(env, check3.state) : "trace" in check3 ? evaluateTrace(check3.trace, agentCalls2()) : evaluateProcess(env, check3, agentCalls2);
|
|
89344
|
+
outcome3 = "state" in check3 ? evaluateState(env, check3.state) : "trace" in check3 ? evaluateTrace(check3.trace, agentCalls2(), sceneTools(env)) : evaluateProcess(env, check3, agentCalls2);
|
|
89183
89345
|
} catch (e) {
|
|
89184
89346
|
error63 = e instanceof Error ? e.message : String(e);
|
|
89185
89347
|
outcome3 = errored("state" in check3 ? Object.keys(check3.state).join(", ") || "state" : checkKind(check3), e);
|
|
@@ -91993,12 +92155,12 @@ function persistMessageLinks(ctx, row, links2 = []) {
|
|
|
91993
92155
|
ctx.store.db.prepare("INSERT INTO slack_message_links VALUES (?, ?, ?, ?, ?)").run(row.channel_id, row.ts, link5.pointer, link5.service, link5.path);
|
|
91994
92156
|
}
|
|
91995
92157
|
}
|
|
91996
|
-
function materializeMessageLinks(ctx, row,
|
|
92158
|
+
function materializeMessageLinks(ctx, row, shape4) {
|
|
91997
92159
|
if (!ctx.serviceUrls) return;
|
|
91998
92160
|
for (const link5 of messageLinks(ctx, row)) {
|
|
91999
92161
|
const root2 = ctx.serviceUrls[link5.service];
|
|
92000
92162
|
if (!root2) throw new AnchaError("INTERNAL", `Missing local ${link5.service} service for Slack message link`);
|
|
92001
|
-
replaceLink(
|
|
92163
|
+
replaceLink(shape4, link5, root2.replace(/\/$/, "") + link5.path);
|
|
92002
92164
|
}
|
|
92003
92165
|
}
|
|
92004
92166
|
|
|
@@ -94809,13 +94971,13 @@ function batch(ctx, type, operation2, raw3, url3) {
|
|
|
94809
94971
|
return { status: 204 };
|
|
94810
94972
|
});
|
|
94811
94973
|
}
|
|
94812
|
-
const traceIds = items.map((item2) => item2.objectWriteTraceId),
|
|
94813
|
-
if (
|
|
94974
|
+
const traceIds = items.map((item2) => item2.objectWriteTraceId), traced3 = operation2 === "create" && traceIds.some((value4) => value4 !== void 0);
|
|
94975
|
+
if (traced3 && (traceIds.some((value4) => typeof value4 !== "string" || !value4 || value4.length > 255) || new Set(traceIds).size !== items.length)) throw new HubError(400, "VALIDATION_ERROR", "Every batch create input requires a unique objectWriteTraceId when enabled.");
|
|
94814
94976
|
const execute3 = (item2) => {
|
|
94815
94977
|
bodyObject2(item2, operation2 === "create" ? ["properties", "associations", "objectWriteTraceId"] : ["id", "properties"]);
|
|
94816
94978
|
return project2(ctx, type, operation2 === "create" ? createRecord(ctx, type, item2) : updateRecord(ctx, type, identifier(item2.id), { properties: item2.properties }));
|
|
94817
94979
|
};
|
|
94818
|
-
if (
|
|
94980
|
+
if (traced3) return withMutation(ctx, () => {
|
|
94819
94981
|
const results = [], errors2 = [];
|
|
94820
94982
|
let gap5 = false;
|
|
94821
94983
|
for (const item2 of items) {
|
|
@@ -98070,7 +98232,7 @@ function explainFailedChecks(env, results, checks = env.scene.checks) {
|
|
|
98070
98232
|
if (!failed.length) return [];
|
|
98071
98233
|
const messages = attemptMessages(env);
|
|
98072
98234
|
const agentCalls2 = env.trace.list().filter((entry2) => entry2.source === "agent");
|
|
98073
|
-
const calls2 = { first: (pattern) => agentCalls2.find(compileTracePattern(pattern)) };
|
|
98235
|
+
const calls2 = { first: (pattern) => agentCalls2.find(compileTracePattern(pattern, sceneTools(env))) };
|
|
98074
98236
|
const start = env.clock.startTime.getTime();
|
|
98075
98237
|
return failed.flatMap((result) => {
|
|
98076
98238
|
const check3 = checks.find((candidate) => candidate.id === result.id);
|
|
@@ -98208,7 +98370,271 @@ function readWorldSnapshot(bytes2) {
|
|
|
98208
98370
|
}
|
|
98209
98371
|
}
|
|
98210
98372
|
|
|
98373
|
+
// packages/server/src/agent-tools/simulate.ts
|
|
98374
|
+
var SYSTEM = `You stand in for one tool of an AI agent's application, in a test made from a production trace. Production recorded some calls to this tool. Answer the new call exactly as the real tool would at this point: consistent with what production recorded, with the calls the agent already made in this test and their answers (calls_in_this_test, writes included), and with the records that mention this call's values (records_that_mention_these_values: what other tools answered about the same thing), in the same shape as production's results (the same top-level fields, with values of the same types). The call happens at time.now: a time the tool reports for this call (when a reading was taken, when something was posted) is time.now. When time has passed since production's last answer, answer as the tool would by then: what changes over time (a status, a measurement) moves on the way the recorded answers, the writes and the tool's calls in other production runs imply; those runs' times are already on this run's timeline. Invent nothing the tool would not know. If the real tool would fail on this call (an unknown id, invalid arguments), answer with its error instead. Reply with JSON: {"result_json": "<the result as a JSON string>"} or {"error": "<the error message>"}.`;
|
|
98375
|
+
var SCHEMA5 = { name: "tool_answer", schema: { type: "object", additionalProperties: false, properties: { result_json: { type: "string" }, error: { type: "string" } } } };
|
|
98376
|
+
function shape(value4) {
|
|
98377
|
+
if (Array.isArray(value4)) return `[${value4.length ? shape(value4[0]) : ""}]`;
|
|
98378
|
+
if (value4 === null || typeof value4 !== "object") return value4 === null ? "null" : typeof value4;
|
|
98379
|
+
return `{${Object.keys(value4).sort().map((k) => `${k}:${value4[k] === null ? "null" : Array.isArray(value4[k]) ? "list" : typeof value4[k]}`).join(",")}}`;
|
|
98380
|
+
}
|
|
98381
|
+
function sameShape(result, recorded2) {
|
|
98382
|
+
if (!recorded2.length) return true;
|
|
98383
|
+
const top = (v) => Array.isArray(v) ? "list" : v === null ? "null" : typeof v;
|
|
98384
|
+
if (!recorded2.some((r) => top(r) === top(result) || top(r) === "null")) return false;
|
|
98385
|
+
const objects = recorded2.filter((r) => r !== null && typeof r === "object" && !Array.isArray(r));
|
|
98386
|
+
if (!objects.length || result === null || typeof result !== "object" || Array.isArray(result)) return true;
|
|
98387
|
+
const got = result;
|
|
98388
|
+
const always = Object.keys(objects[0]).filter((k) => objects.every((o) => k in o));
|
|
98389
|
+
const types = /* @__PURE__ */ new Map();
|
|
98390
|
+
for (const o of objects) for (const [k, v] of Object.entries(o)) types.set(k, (types.get(k) ?? /* @__PURE__ */ new Set()).add(top(v)));
|
|
98391
|
+
return always.every((k) => k in got) && Object.entries(got).every(([k, v]) => types.has(k) && (v === null || types.get(k).has("null") || types.get(k).has(top(v))));
|
|
98392
|
+
}
|
|
98393
|
+
async function simulate(model, request4, signal) {
|
|
98394
|
+
const recorded2 = (request4.tool?.recorded ?? []).map((o) => ({ args: o.args, at: o.at, ...o.error !== void 0 ? { error: o.error } : { result: o.result } }));
|
|
98395
|
+
const results = recorded2.filter((o) => "result" in o).map((o) => o.result);
|
|
98396
|
+
const known2 = results.length ? results : (request4.tool?.examples ?? []).filter((o) => o.error === void 0 && o.result !== void 0).map((o) => o.result);
|
|
98397
|
+
const text21 = known2.length > 0 && known2.every((r) => typeof r === "string");
|
|
98398
|
+
const user8 = JSON.stringify({
|
|
98399
|
+
tool: { name: request4.name, ...request4.tool?.description && { description: request4.tool.description }, ...request4.tool?.schema && { arguments: request4.tool.schema }, ...request4.tool?.write && { changes_something: true } },
|
|
98400
|
+
production_recorded: recorded2.slice(-20),
|
|
98401
|
+
...request4.tool?.examples?.length && { other_production_runs_of_this_agent: request4.tool.examples.slice(-30) },
|
|
98402
|
+
...known2.length && { result_shape: shape(known2[0]) },
|
|
98403
|
+
calls_in_this_test: request4.calls.slice(-30),
|
|
98404
|
+
...request4.records?.length && { records_that_mention_these_values: request4.records },
|
|
98405
|
+
call: { arguments: request4.args, ...request4.repeat && { production_made_this_exact_call: request4.repeat.recorded, this_is_call_number: request4.repeat.call } },
|
|
98406
|
+
// Time moves on as the agent waits: a status read later may say what a real one would say by then.
|
|
98407
|
+
...request4.time && { time: {
|
|
98408
|
+
...request4.time.start && { now: new Date(Date.parse(request4.time.start) + request4.time.now_ms).toISOString() },
|
|
98409
|
+
...request4.time.now_ms > request4.time.last_recorded_ms && { seconds_since_productions_last_answer: Math.round((request4.time.now_ms - request4.time.last_recorded_ms) / 1e3) }
|
|
98410
|
+
} }
|
|
98411
|
+
});
|
|
98412
|
+
let inputTokens = 0, outputTokens = 0, costUsd = 0, model_, feedback = "", last = "";
|
|
98413
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
98414
|
+
const answer = await model.complete({ kind: "simulate", person: request4.name, system: SYSTEM, user: feedback ? `${user8}
|
|
98415
|
+
|
|
98416
|
+
${feedback}` : user8, schema: SCHEMA5, temperature: 0, maxTokens: 1200 }, signal);
|
|
98417
|
+
inputTokens += answer.inputTokens;
|
|
98418
|
+
outputTokens += answer.outputTokens;
|
|
98419
|
+
costUsd += answer.costUsd;
|
|
98420
|
+
model_ = answer.model;
|
|
98421
|
+
const out = answer.output;
|
|
98422
|
+
last = JSON.stringify(out ?? null).slice(0, 200);
|
|
98423
|
+
if (typeof out?.error === "string" && out.error && out.result_json === void 0) return { error: out.error, inputTokens, outputTokens, costUsd, model: model_ };
|
|
98424
|
+
let result;
|
|
98425
|
+
try {
|
|
98426
|
+
result = JSON.parse(String(out?.result_json));
|
|
98427
|
+
} catch {
|
|
98428
|
+
if (!text21 || typeof out?.result_json !== "string") {
|
|
98429
|
+
feedback = "Your result_json was not valid JSON. Answer again.";
|
|
98430
|
+
continue;
|
|
98431
|
+
}
|
|
98432
|
+
result = out.result_json;
|
|
98433
|
+
}
|
|
98434
|
+
if (text21 && typeof result !== "string" && typeof out?.result_json === "string") result = out.result_json;
|
|
98435
|
+
if (sameShape(result, known2)) return { result, inputTokens, outputTokens, costUsd, model: model_ };
|
|
98436
|
+
feedback = `Your result has the shape ${shape(result)}, but production's results have the shape ${shape(known2[0])}. Answer again in that shape.`;
|
|
98437
|
+
}
|
|
98438
|
+
throw new PeopleModelError(`the simulated answer to ${request4.name} did not have the shape of production's results (the model's last answer: ${last})`);
|
|
98439
|
+
}
|
|
98440
|
+
|
|
98441
|
+
// packages/server/src/agent-tools/index.ts
|
|
98442
|
+
var AGENT_TOOLS = "tools";
|
|
98443
|
+
function canonical2(value4) {
|
|
98444
|
+
return JSON.stringify(value4 ?? {}, (_key, v) => v && typeof v === "object" && !Array.isArray(v) ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : v);
|
|
98445
|
+
}
|
|
98446
|
+
var recordedOf = /* @__PURE__ */ new WeakMap();
|
|
98447
|
+
function recorded(ctx, tool) {
|
|
98448
|
+
const tools = ctx.scene.tools ?? {};
|
|
98449
|
+
let byTool = recordedOf.get(tools);
|
|
98450
|
+
if (!byTool) {
|
|
98451
|
+
byTool = new Map(Object.entries(tools).map(([name5, t]) => [name5, (t.recorded ?? []).map((o) => {
|
|
98452
|
+
const atMs = parseDuration(o.at);
|
|
98453
|
+
return { ...o, atMs, endMs: o.end ? parseDuration(o.end) : atMs, key: canonical2(o.args) };
|
|
98454
|
+
}).sort((a, b) => a.atMs - b.atMs)]));
|
|
98455
|
+
recordedOf.set(tools, byTool);
|
|
98456
|
+
}
|
|
98457
|
+
return byTool.get(tool) ?? [];
|
|
98458
|
+
}
|
|
98459
|
+
function migrate6(db2) {
|
|
98460
|
+
db2.exec(`CREATE TABLE agent_tool_calls (key TEXT PRIMARY KEY, n INTEGER NOT NULL);
|
|
98461
|
+
CREATE TABLE agent_tool_state (k TEXT PRIMARY KEY, v TEXT NOT NULL);`);
|
|
98462
|
+
}
|
|
98463
|
+
var getState = (ctx, k) => ctx.store.db.prepare("SELECT v FROM agent_tool_state WHERE k=?").get(k)?.v;
|
|
98464
|
+
var setState = (ctx, k, v) => ctx.store.db.prepare("INSERT INTO agent_tool_state (k, v) VALUES (?, ?) ON CONFLICT(k) DO UPDATE SET v=excluded.v").run(k, v);
|
|
98465
|
+
var SIMULATION_LIMIT = () => Number(process.env.ANCHA_SIMULATE_MAX ?? 30);
|
|
98466
|
+
var simulationOn = (ctx) => process.env.ANCHA_SIMULATE !== "0" && ctx.model !== void 0;
|
|
98467
|
+
var ID_LIKE = /^(?=.*[\d@])[A-Za-z0-9][\w.:@#/+-]{3,63}$/;
|
|
98468
|
+
var DATE = /^\d{4}-\d{2}-\d{2}/;
|
|
98469
|
+
function idValues(value4, out = /* @__PURE__ */ new Set()) {
|
|
98470
|
+
if (Array.isArray(value4)) for (const v of value4) idValues(v, out);
|
|
98471
|
+
else if (value4 && typeof value4 === "object") for (const v of Object.values(value4)) idValues(v, out);
|
|
98472
|
+
else if ((typeof value4 === "string" || typeof value4 === "number" && Number.isInteger(value4)) && ID_LIKE.test(String(value4)) && !DATE.test(String(value4))) out.add(String(value4));
|
|
98473
|
+
return out;
|
|
98474
|
+
}
|
|
98475
|
+
var RECORDS_SHOWN = 20;
|
|
98476
|
+
function recordsMentioning(ctx, name5, args) {
|
|
98477
|
+
const ids2 = [...idValues(args)].map((id12) => new RegExp(`(^|[^A-Za-z0-9])${id12.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&")}([^A-Za-z0-9]|$)`));
|
|
98478
|
+
if (!ids2.length) return [];
|
|
98479
|
+
const records2 = [];
|
|
98480
|
+
const add = (tool, o, here) => {
|
|
98481
|
+
const answer = o.error !== void 0 ? { error: o.error } : { result: o.result };
|
|
98482
|
+
const text21 = JSON.stringify([o.args, answer]);
|
|
98483
|
+
if (ids2.some((id12) => id12.test(text21))) records2.push({ tool, args: o.args ?? {}, ...answer, conversation: here ? "this one" : o.trace ?? "another" });
|
|
98484
|
+
};
|
|
98485
|
+
const others = Object.entries(ctx.scene.tools ?? {}).filter(([tool]) => tool !== name5);
|
|
98486
|
+
for (const [tool] of others) for (const o of recorded(ctx, tool)) add(tool, o, true);
|
|
98487
|
+
for (const [tool, t] of others) for (const o of [...t.examples ?? []].reverse()) add(tool, o, false);
|
|
98488
|
+
return records2.slice(0, RECORDS_SHOWN);
|
|
98489
|
+
}
|
|
98490
|
+
function keepUp(ctx) {
|
|
98491
|
+
const behind = withRead(ctx, () => Number(getState(ctx, "reached") ?? 0)) - ctx.clock.elapsedMs();
|
|
98492
|
+
if (behind > 0) ctx.clock.advance(behind);
|
|
98493
|
+
}
|
|
98494
|
+
function decide(ctx, name5, args) {
|
|
98495
|
+
const tool = ctx.scene.tools?.[name5];
|
|
98496
|
+
const key3 = canonical2(args), callKey = `${name5} ${key3}`;
|
|
98497
|
+
const same2 = recorded(ctx, name5).filter((o) => o.key === key3);
|
|
98498
|
+
const n = ctx.store.db.prepare("SELECT n FROM agent_tool_calls WHERE key=?").get(callKey)?.n ?? 0;
|
|
98499
|
+
ctx.store.db.prepare("INSERT INTO agent_tool_calls (key, n) VALUES (?, 1) ON CONFLICT(key) DO UPDATE SET n=n+1").run(callKey);
|
|
98500
|
+
const policy = tool?.unrecorded ?? (tool?.write ? "fail" : "simulate");
|
|
98501
|
+
const reached = Number(getState(ctx, "reached") ?? 0);
|
|
98502
|
+
const cached2 = getState(ctx, `sim:${callKey}`);
|
|
98503
|
+
if (cached2 !== void 0) {
|
|
98504
|
+
const hit = JSON.parse(cached2);
|
|
98505
|
+
if (tool?.write || hit.reached >= reached) return hit.answer;
|
|
98506
|
+
}
|
|
98507
|
+
if (n < same2.length) {
|
|
98508
|
+
let index = n;
|
|
98509
|
+
for (let i = same2.length - 1; i > index; i--) if (same2[i].atMs <= reached) {
|
|
98510
|
+
index = i;
|
|
98511
|
+
break;
|
|
98512
|
+
}
|
|
98513
|
+
const o = same2[index];
|
|
98514
|
+
setState(ctx, "reached", String(Math.max(reached, o.endMs)));
|
|
98515
|
+
return o.error !== void 0 ? { source: "replayed", error: o.error, ...o.raw !== void 0 && { raw: o.raw, wrap: o.wrap } } : { source: "replayed", result: o.result, ...o.raw !== void 0 && { raw: o.raw, wrap: o.wrap } };
|
|
98516
|
+
}
|
|
98517
|
+
if (!same2.length && !tool?.write) {
|
|
98518
|
+
const elsewhere = [...tool?.examples ?? []].reverse().find((o) => o.error === void 0 && o.result !== void 0 && canonical2(o.args) === key3);
|
|
98519
|
+
if (elsewhere) return { source: "replayed-elsewhere", result: elsewhere.result };
|
|
98520
|
+
}
|
|
98521
|
+
if (tool?.twin !== void 0 || policy === "twin") return { source: "twin", passthrough: true };
|
|
98522
|
+
if (tool?.pure) return { source: "ran", passthrough: true };
|
|
98523
|
+
const repeat = same2.length ? { recorded: same2.length, call: n + 1 } : void 0;
|
|
98524
|
+
const last = same2.at(-1) ?? recorded(ctx, name5).at(-1), took = last ? last.endMs - last.atMs : 0;
|
|
98525
|
+
if (policy === "simulate" && simulationOn(ctx)) {
|
|
98526
|
+
if (Number(getState(ctx, "simulated") ?? 0) >= SIMULATION_LIMIT()) return { source: "failed", error: `Ancha has no recorded answer for this call, and this test reached its limit of ${SIMULATION_LIMIT()} simulated answers` };
|
|
98527
|
+
const lastRecordedMs = Math.max(0, ...recorded(ctx, name5).map((o) => o.endMs));
|
|
98528
|
+
const records2 = recordsMentioning(ctx, name5, args);
|
|
98529
|
+
return { simulate: { name: name5, tool, args, ...repeat && { repeat }, ...records2.length && { records: records2 }, time: { now_ms: Math.max(reached, ctx.clock.elapsedMs()), last_recorded_ms: lastRecordedMs, start: ctx.scene.start_time } }, cacheKey: callKey, reached, took };
|
|
98530
|
+
}
|
|
98531
|
+
if (repeat && !tool?.write) {
|
|
98532
|
+
const o = same2.at(-1);
|
|
98533
|
+
return o.error !== void 0 ? { source: "replayed", error: o.error } : { source: "replayed", result: o.result, ...o.raw !== void 0 && { raw: o.raw, wrap: o.wrap } };
|
|
98534
|
+
}
|
|
98535
|
+
const why = repeat ? `production made this call ${repeat.recorded} ${repeat.recorded === 1 ? "time" : "times"}, and this is call ${repeat.call}` : tool === void 0 || !recorded(ctx, name5).length ? `production never called ${name5}` : `production called ${name5}, but never with these arguments`;
|
|
98536
|
+
const unsimulated = policy === "simulate" && !simulationOn(ctx) ? process.env.ANCHA_SIMULATE === "0" ? "; simulation is off (ANCHA_SIMULATE=0)" : "; there is no model to simulate one with (set OPENROUTER_API_KEY)" : "";
|
|
98537
|
+
return { source: "failed", error: `Ancha has no recorded answer for this call: ${why}${unsimulated}` };
|
|
98538
|
+
}
|
|
98539
|
+
function noteCall(ctx, name5, args, a) {
|
|
98540
|
+
if (a.passthrough) return;
|
|
98541
|
+
const calls2 = JSON.parse(getState(ctx, "calls") ?? "[]");
|
|
98542
|
+
calls2.push({ tool: name5, args, ...ctx.scene.tools?.[name5]?.write && { changes_something: true }, ...a.error !== void 0 ? { error: a.error } : { result: a.result } });
|
|
98543
|
+
setState(ctx, "calls", JSON.stringify(calls2.slice(-50)));
|
|
98544
|
+
}
|
|
98545
|
+
function toolsToWrap(ctx) {
|
|
98546
|
+
return Object.entries(ctx.scene.tools ?? {}).filter(([, t]) => t.twin === void 0 && !t.mcp && !t.pure && !t.allow_unwrapped).map(([name5]) => name5).sort();
|
|
98547
|
+
}
|
|
98548
|
+
function registration(ctx, names3) {
|
|
98549
|
+
const before = JSON.parse(getState(ctx, "wrapped") ?? "[]");
|
|
98550
|
+
const wrapped = [.../* @__PURE__ */ new Set([...before, ...names3])].sort();
|
|
98551
|
+
setState(ctx, "wrapped", JSON.stringify(wrapped));
|
|
98552
|
+
return { wrapped, missing: toolsToWrap(ctx).filter((name5) => !wrapped.includes(name5)) };
|
|
98553
|
+
}
|
|
98554
|
+
function unwrappedMessage(missing4, noneWrapped = false) {
|
|
98555
|
+
const [first] = missing4, it = missing4.length === 1 ? "it" : "them";
|
|
98556
|
+
return `${missing4.join(", ")} ${missing4.length === 1 ? "is" : "are"} in the trace but your agent does not wrap ${it}, so a test would call ${it} for real. Wrap ${it}, or set tools.${first}.unrecorded: fail and allow ${it} with --allow-unwrapped ${missing4.join(",")}.` + (noneWrapped ? " If the agent wraps its tools when it runs, wrap them where they are defined instead, so the test can check them before the agent starts." : "");
|
|
98557
|
+
}
|
|
98558
|
+
function authorized(c) {
|
|
98559
|
+
const token2 = JSON.parse(c.env.ctx.store.meta.get(`credentials:${AGENT_TOOLS}`) ?? "{}").token;
|
|
98560
|
+
return token2 !== void 0 && c.req.header("authorization") === `Bearer ${token2}`;
|
|
98561
|
+
}
|
|
98562
|
+
function agentToolsService() {
|
|
98563
|
+
const app2 = new Hono3();
|
|
98564
|
+
app2.use("*", async (c, next2) => authorized(c) ? next2() : c.json({ error: "send Authorization: Bearer $ANCHA_TOOLS_TOKEN" }, 401));
|
|
98565
|
+
app2.get("/tools", (c) => withRead(c.env.ctx, () => c.json({ tools: Object.entries(c.env.ctx.scene.tools ?? {}).map(([name5, t]) => ({
|
|
98566
|
+
name: name5,
|
|
98567
|
+
...t.description && { description: t.description },
|
|
98568
|
+
...t.schema && { schema: t.schema },
|
|
98569
|
+
recorded: t.recorded?.length ?? 0,
|
|
98570
|
+
...t.twin && { twin: t.twin },
|
|
98571
|
+
...t.write && { write: true }
|
|
98572
|
+
})), wrap: toolsToWrap(c.env.ctx) })));
|
|
98573
|
+
app2.post("/register", async (c) => {
|
|
98574
|
+
const body6 = await c.req.json().catch(() => ({}));
|
|
98575
|
+
const names3 = (Array.isArray(body6.tools) ? body6.tools : []).map((t) => typeof t === "string" ? t : t?.name).filter((n) => typeof n === "string");
|
|
98576
|
+
const { wrapped, missing: missing4 } = withMutation(c.env.ctx, () => registration(c.env.ctx, names3));
|
|
98577
|
+
if (body6.complete) withMutation(c.env.ctx, () => setState(c.env.ctx, "checked", "1"));
|
|
98578
|
+
if (body6.complete && missing4.length) return c.json({ error: unwrappedMessage(missing4, wrapped.length === 0), wrapped, missing: missing4, stop: true }, 409, { [SETUP_ISSUE_HEADER]: "1" });
|
|
98579
|
+
return c.json({ wrapped, missing: missing4 });
|
|
98580
|
+
});
|
|
98581
|
+
app2.post("/tools/:name", async (c) => {
|
|
98582
|
+
const name5 = c.req.param("name");
|
|
98583
|
+
const body6 = await c.req.json().catch(() => ({}));
|
|
98584
|
+
const stop = withMutation(c.env.ctx, () => {
|
|
98585
|
+
if (getState(c.env.ctx, "checked")) return void 0;
|
|
98586
|
+
setState(c.env.ctx, "checked", "1");
|
|
98587
|
+
const { wrapped, missing: missing4 } = registration(c.env.ctx, []);
|
|
98588
|
+
return missing4.length ? { error: unwrappedMessage(missing4, wrapped.length === 0), wrapped, missing: missing4, stop: true } : void 0;
|
|
98589
|
+
});
|
|
98590
|
+
if (stop) return c.json(stop, 409, { [SETUP_ISSUE_HEADER]: "1" });
|
|
98591
|
+
const ctx = c.env.ctx, args = body6.args ?? {};
|
|
98592
|
+
const decision2 = withMutation(ctx, () => decide(ctx, name5, args));
|
|
98593
|
+
if (!("simulate" in decision2)) {
|
|
98594
|
+
withMutation(ctx, () => noteCall(ctx, name5, args, decision2));
|
|
98595
|
+
keepUp(ctx);
|
|
98596
|
+
return c.json(decision2);
|
|
98597
|
+
}
|
|
98598
|
+
let answered;
|
|
98599
|
+
try {
|
|
98600
|
+
const calls2 = withRead(ctx, () => JSON.parse(getState(ctx, "calls") ?? "[]"));
|
|
98601
|
+
const sim = await simulate(ctx.model, { ...decision2.simulate, calls: calls2 }, c.req.raw.signal);
|
|
98602
|
+
answered = { source: "simulated", ...sim.error !== void 0 ? { error: sim.error } : { result: sim.result }, cost_usd: Math.round(sim.costUsd * 1e6) / 1e6 };
|
|
98603
|
+
} catch (error63) {
|
|
98604
|
+
answered = { source: "failed", error: `Ancha has no recorded answer for this call and could not simulate one: ${error63 instanceof Error ? error63.message : String(error63)}` };
|
|
98605
|
+
}
|
|
98606
|
+
const answer = withMutation(ctx, () => {
|
|
98607
|
+
if (answered.source === "simulated") {
|
|
98608
|
+
const now10 = Math.max(Number(getState(ctx, "reached") ?? 0), decision2.reached + decision2.took);
|
|
98609
|
+
setState(ctx, "reached", String(now10));
|
|
98610
|
+
setState(ctx, `sim:${decision2.cacheKey}`, JSON.stringify({ answer: { ...answered, cost_usd: void 0 }, reached: now10 }));
|
|
98611
|
+
setState(ctx, "simulated", String(Number(getState(ctx, "simulated") ?? 0) + 1));
|
|
98612
|
+
}
|
|
98613
|
+
noteCall(ctx, name5, args, answered);
|
|
98614
|
+
return answered;
|
|
98615
|
+
});
|
|
98616
|
+
keepUp(ctx);
|
|
98617
|
+
return answer.source === "failed" ? c.json(answer, 200, { [SETUP_ISSUE_HEADER]: "1" }) : c.json(answer);
|
|
98618
|
+
});
|
|
98619
|
+
app2.all("*", (c) => c.json({ error: `not a route of Ancha's tool service: ${c.req.method} ${new URL(c.req.url).pathname}` }, 404));
|
|
98620
|
+
return {
|
|
98621
|
+
// A built-in service, not a catalog twin: a scene gets it by having tools.
|
|
98622
|
+
name: AGENT_TOOLS,
|
|
98623
|
+
basePath: "",
|
|
98624
|
+
app: app2,
|
|
98625
|
+
migrate: migrate6,
|
|
98626
|
+
seed() {
|
|
98627
|
+
},
|
|
98628
|
+
credentials: (ctx) => ({ token: `ancha-tools-${ctx.secrets.hex(32)}` }),
|
|
98629
|
+
actions: {},
|
|
98630
|
+
checks: {},
|
|
98631
|
+
dumpState: (ctx) => ({ calls: ctx.store.db.prepare("SELECT key, n FROM agent_tool_calls ORDER BY key").all(), wrapped: JSON.parse(getState(ctx, "wrapped") ?? "[]") }),
|
|
98632
|
+
coverage: []
|
|
98633
|
+
};
|
|
98634
|
+
}
|
|
98635
|
+
|
|
98211
98636
|
// packages/server/src/env.ts
|
|
98637
|
+
var agentTools = agentToolsService();
|
|
98212
98638
|
var ENV_ID_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
98213
98639
|
function newEnvId() {
|
|
98214
98640
|
let id12 = "";
|
|
@@ -98302,7 +98728,8 @@ var Environment = class _Environment {
|
|
|
98302
98728
|
}
|
|
98303
98729
|
return twin;
|
|
98304
98730
|
});
|
|
98305
|
-
|
|
98731
|
+
if (Object.keys(scene2.tools ?? {}).length) this.twins.push(agentTools);
|
|
98732
|
+
this.mcpTokens = Object.freeze(Object.fromEntries((opts.mcpTools ?? []).filter((tool) => scene2.twins.some((name5) => name5 === tool) || tool === "tools" && Object.keys(scene2.tools ?? {}).length > 0).map((tool) => [tool, randomBytes(32).toString("hex")])));
|
|
98306
98733
|
const realNow = opts.realNow ?? (() => Date.now());
|
|
98307
98734
|
this.#realNow = realNow;
|
|
98308
98735
|
let frozenRealNow = realNow();
|
|
@@ -98359,7 +98786,8 @@ var Environment = class _Environment {
|
|
|
98359
98786
|
trace: this.trace,
|
|
98360
98787
|
events: this.events,
|
|
98361
98788
|
enqueueJob: (job) => this.scheduler.enqueue(job),
|
|
98362
|
-
world: this.world
|
|
98789
|
+
world: this.world,
|
|
98790
|
+
...this.peopleModel && { model: this.peopleModel }
|
|
98363
98791
|
};
|
|
98364
98792
|
this.#contexts.set(twin, ctx);
|
|
98365
98793
|
}
|
|
@@ -98890,7 +99318,7 @@ var FILE_KEYS2 = ["version", "id", "owner", "sceneId", "createdAt", "expiresAt",
|
|
|
98890
99318
|
|
|
98891
99319
|
// packages/server/src/twins/google-ads/db.ts
|
|
98892
99320
|
var collections = { budgets: "campaignBudgets", campaigns: "campaigns", adGroups: "adGroups", ads: "adGroupAds", criteria: "adGroupCriteria" };
|
|
98893
|
-
function
|
|
99321
|
+
function migrate7(db2) {
|
|
98894
99322
|
db2.exec("CREATE TABLE google_ads_records (kind TEXT NOT NULL, name TEXT NOT NULL, customer_id TEXT NOT NULL, json TEXT NOT NULL, PRIMARY KEY(kind,name)); CREATE INDEX google_ads_customer ON google_ads_records(kind,customer_id)");
|
|
98895
99323
|
}
|
|
98896
99324
|
function config3(ctx) {
|
|
@@ -99857,11 +100285,11 @@ function googleAdsTwin() {
|
|
|
99857
100285
|
throw e;
|
|
99858
100286
|
}
|
|
99859
100287
|
});
|
|
99860
|
-
return { name: "google-ads", basePath: "", unprefixedPaths: /^\/v\d+\/customers[/:]/, app: app2, migrate:
|
|
100288
|
+
return { name: "google-ads", basePath: "", unprefixedPaths: /^\/v\d+\/customers[/:]/, app: app2, migrate: migrate7, seed: seed4, credentials: credentials3, actions: {}, checks: {}, dumpState: dumpState2, coverage: googleAdsCoverage };
|
|
99861
100289
|
}
|
|
99862
100290
|
|
|
99863
100291
|
// packages/server/src/twins/chatgpt-ads/db.ts
|
|
99864
|
-
function
|
|
100292
|
+
function migrate8(db2) {
|
|
99865
100293
|
db2.exec(`CREATE TABLE chatgpt_ads_data(id INTEGER PRIMARY KEY CHECK(id=1),json TEXT NOT NULL);
|
|
99866
100294
|
CREATE TABLE chatgpt_ads_credentials(principal_id TEXT PRIMARY KEY,token TEXT NOT NULL UNIQUE);
|
|
99867
100295
|
CREATE TABLE chatgpt_ads_idempotency(account_id TEXT NOT NULL,kind TEXT NOT NULL,key TEXT NOT NULL,fingerprint TEXT NOT NULL,resource_id TEXT NOT NULL,PRIMARY KEY(account_id,kind,key));
|
|
@@ -100076,9 +100504,9 @@ function pagination(rows7, query10, defaultLimit = 20, max = 500) {
|
|
|
100076
100504
|
const selected2 = rows7.slice(start, Math.min(start + limit, end));
|
|
100077
100505
|
return { object: "list", data: selected2, first_id: selected2[0]?.id ?? null, last_id: selected2.at(-1)?.id ?? null, has_more: before !== void 0 ? start > 0 : start + selected2.length < rows7.length };
|
|
100078
100506
|
}
|
|
100079
|
-
function
|
|
100080
|
-
if (Array.isArray(value4)) return `[${value4.map(
|
|
100081
|
-
if (value4 && typeof value4 === "object") return `{${Object.entries(value4).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${JSON.stringify(k)}:${
|
|
100507
|
+
function canonical3(value4) {
|
|
100508
|
+
if (Array.isArray(value4)) return `[${value4.map(canonical3).join(",")}]`;
|
|
100509
|
+
if (value4 && typeof value4 === "object") return `{${Object.entries(value4).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${JSON.stringify(k)}:${canonical3(v)}`).join(",")}}`;
|
|
100082
100510
|
return JSON.stringify(value4);
|
|
100083
100511
|
}
|
|
100084
100512
|
function idempotency(c, access2, kind, body6) {
|
|
@@ -100086,7 +100514,7 @@ function idempotency(c, access2, kind, body6) {
|
|
|
100086
100514
|
if (key3 === void 0) return { existing: void 0, remember: (_id) => {
|
|
100087
100515
|
} };
|
|
100088
100516
|
if (key3.length > 255 || !key3.trim()) invalid6("Idempotency-Key requires 1\u2013255 characters and non-whitespace");
|
|
100089
|
-
const fingerprint = createHash13("sha256").update(
|
|
100517
|
+
const fingerprint = createHash13("sha256").update(canonical3(body6)).digest("hex");
|
|
100090
100518
|
const prior = c.env.ctx.store.db.prepare("SELECT fingerprint,resource_id FROM chatgpt_ads_idempotency WHERE account_id=? AND kind=? AND key=?").get(access2.account.id, kind, key3);
|
|
100091
100519
|
if (prior && prior.fingerprint !== fingerprint) throw new AdsError2(409, "Idempotency-Key was used with different input", "idempotency_conflict");
|
|
100092
100520
|
return { existing: prior ? find(access2, kind, prior.resource_id) : void 0, remember: (id12) => c.env.ctx.store.db.prepare("INSERT INTO chatgpt_ads_idempotency VALUES (?,?,?,?,?)").run(access2.account.id, kind, key3, fingerprint, id12) };
|
|
@@ -100370,11 +100798,11 @@ function chatGPTAdsTwin() {
|
|
|
100370
100798
|
const app2 = new Hono3();
|
|
100371
100799
|
for (const route11 of chatGPTAdsRoutes) app2.on(route11.method, route11.path, handle2(route11));
|
|
100372
100800
|
app2.all("*", handle2({ method: "GET", path: "*", notes: "", run: (c) => unsupported5(`${c.req.method} ${new URL(c.req.url).pathname}`) }));
|
|
100373
|
-
return { name: "chatgpt-ads", basePath: "", app: app2, migrate:
|
|
100801
|
+
return { name: "chatgpt-ads", basePath: "", app: app2, migrate: migrate8, seed: seed5, credentials: credentials4, dumpState: dumpState3, actions: {}, checks: {}, coverage: chatGPTAdsCoverage };
|
|
100374
100802
|
}
|
|
100375
100803
|
|
|
100376
100804
|
// packages/server/src/twins/ga4/db.ts
|
|
100377
|
-
function
|
|
100805
|
+
function migrate9(db2) {
|
|
100378
100806
|
db2.exec(`CREATE TABLE ga4_data (id INTEGER PRIMARY KEY CHECK(id=1),json TEXT NOT NULL);
|
|
100379
100807
|
CREATE TABLE ga4_credentials (principal_id TEXT PRIMARY KEY,token TEXT NOT NULL UNIQUE);
|
|
100380
100808
|
CREATE TABLE ga4_quota (property_id TEXT NOT NULL,kind TEXT NOT NULL,bucket INTEGER NOT NULL,count INTEGER NOT NULL,PRIMARY KEY(property_id,kind));`);
|
|
@@ -100845,7 +101273,7 @@ function ga4Twin() {
|
|
|
100845
101273
|
property2(c, "0", true);
|
|
100846
101274
|
return unsupported6(`${c.req.method} ${new URL(c.req.url).pathname}`);
|
|
100847
101275
|
} }));
|
|
100848
|
-
return { name: "ga4", basePath: "", unprefixedPaths: /^\/v1(?:alpha|beta)\/properties\//, app: app2, migrate:
|
|
101276
|
+
return { name: "ga4", basePath: "", unprefixedPaths: /^\/v1(?:alpha|beta)\/properties\//, app: app2, migrate: migrate9, seed: seed6, credentials: credentials5, dumpState: dumpState4, actions: {}, checks: {}, coverage: ga4Coverage };
|
|
100849
101277
|
}
|
|
100850
101278
|
|
|
100851
101279
|
// packages/server/src/twins/github/actions.ts
|
|
@@ -100994,7 +101422,7 @@ var actionRoutes = [
|
|
|
100994
101422
|
];
|
|
100995
101423
|
|
|
100996
101424
|
// packages/server/src/twins/github/methods/checks.ts
|
|
100997
|
-
function
|
|
101425
|
+
function shape2(ctx, repo4, row) {
|
|
100998
101426
|
return { ...JSON.parse(row.json), id: row.id, node_id: Buffer.from(`CheckRun:${row.id}`).toString("base64"), head_sha: row.head_sha, name: row.name, status: row.status, conclusion: row.conclusion, started_at: row.status === "queued" ? null : row.created_at, completed_at: row.status === "completed" ? row.created_at : null, url: apiUrl(ctx, `${repoPath(repo4)}/check-runs/${row.id}`), html_url: `https://github.com/${repo4.full_name}/runs/${row.id}`, details_url: null, external_id: "", output: { title: null, summary: null, text: null, annotations_count: 0, annotations_url: apiUrl(ctx, `${repoPath(repo4)}/check-runs/${row.id}/annotations`) }, app: null, check_suite: null, pull_requests: [] };
|
|
100999
101427
|
}
|
|
101000
101428
|
var notes4 = "Read-only seeded check runs, repository-scoped exact SHA/branch/full refs and name/status filters. No check execution, writes, suites or annotations: app and check_suite are null, and the annotations link answers 501 as a recorded gap; partial native resource.";
|
|
@@ -101015,13 +101443,13 @@ var checkRoutes = [
|
|
|
101015
101443
|
});
|
|
101016
101444
|
}
|
|
101017
101445
|
const { page: page15, perPage } = pageInfo(c);
|
|
101018
|
-
return json2({ total_count: rows7.length, check_runs: pageSlice(rows7, page15, perPage).map((row) =>
|
|
101446
|
+
return json2({ total_count: rows7.length, check_runs: pageSlice(rows7, page15, perPage).map((row) => shape2(ctx, repo4, row)) }, 200, pageHeaders(c, rows7.length, page15, perPage));
|
|
101019
101447
|
} },
|
|
101020
101448
|
{ method: "GET", path: "/repos/:owner/:repo/check-runs/:id", coverage: { status: "partial", notes: notes4 }, handler: (c) => {
|
|
101021
101449
|
query(c, []);
|
|
101022
101450
|
const ctx = c.env.ctx, repo4 = repository(c), row = ctx.store.db.prepare("SELECT * FROM github_check_runs WHERE repo_id = ? AND id = ?").get(repo4.id, resourceParam(c, "id"));
|
|
101023
101451
|
if (!row) throw new GitHubError(404, "Not Found");
|
|
101024
|
-
return
|
|
101452
|
+
return shape2(ctx, repo4, row);
|
|
101025
101453
|
} }
|
|
101026
101454
|
];
|
|
101027
101455
|
|
|
@@ -102246,7 +102674,7 @@ function downtime(ctx, args) {
|
|
|
102246
102674
|
}
|
|
102247
102675
|
|
|
102248
102676
|
// packages/server/src/twins/datadog/db.ts
|
|
102249
|
-
function
|
|
102677
|
+
function migrate10(db2) {
|
|
102250
102678
|
db2.exec(`
|
|
102251
102679
|
CREATE TABLE datadog_monitors (
|
|
102252
102680
|
id INTEGER PRIMARY KEY, ref TEXT NOT NULL UNIQUE, name TEXT NOT NULL, query TEXT NOT NULL,
|
|
@@ -102629,7 +103057,7 @@ function datadogTwin() {
|
|
|
102629
103057
|
name: "datadog",
|
|
102630
103058
|
basePath: "",
|
|
102631
103059
|
app: app2,
|
|
102632
|
-
migrate:
|
|
103060
|
+
migrate: migrate10,
|
|
102633
103061
|
seed: seed7,
|
|
102634
103062
|
credentials: credentials6,
|
|
102635
103063
|
dumpState: dumpState6,
|
|
@@ -103685,7 +104113,7 @@ function unsupported8(message6, code2 = "INVALID_FIELD") {
|
|
|
103685
104113
|
}
|
|
103686
104114
|
var versionRoot = "/services/data/v67.0";
|
|
103687
104115
|
var prefixes = { Account: "001", Contact: "003", Lead: "00Q", Opportunity: "006", Campaign: "701", CampaignMember: "00v" };
|
|
103688
|
-
function
|
|
104116
|
+
function migrate11(db2) {
|
|
103689
104117
|
db2.exec(`
|
|
103690
104118
|
CREATE TABLE salesforce_records (type TEXT NOT NULL,id TEXT NOT NULL PRIMARY KEY,data TEXT NOT NULL);
|
|
103691
104119
|
CREATE TABLE salesforce_history (ordinal INTEGER PRIMARY KEY AUTOINCREMENT,type TEXT NOT NULL,id TEXT NOT NULL,operation TEXT NOT NULL,at TEXT NOT NULL,before_json TEXT,after_json TEXT);
|
|
@@ -104208,11 +104636,11 @@ function salesforceTwin() {
|
|
|
104208
104636
|
};
|
|
104209
104637
|
for (const [method2, path4] of routePairs2) app2.on(method2, path4, handler);
|
|
104210
104638
|
app2.all("*", handler);
|
|
104211
|
-
return { name: "salesforce", basePath: "", app: app2, migrate:
|
|
104639
|
+
return { name: "salesforce", basePath: "", app: app2, migrate: migrate11, seed: seed10, credentials: credentials9, actions: {}, checks: {}, dumpState: dumpState9, coverage: salesforceCoverage };
|
|
104212
104640
|
}
|
|
104213
104641
|
|
|
104214
104642
|
// packages/server/src/twins/linkedin-ads/db.ts
|
|
104215
|
-
function
|
|
104643
|
+
function migrate12(db2) {
|
|
104216
104644
|
db2.exec("CREATE TABLE linkedin_ads_records (kind TEXT NOT NULL, id TEXT NOT NULL, account_id TEXT NOT NULL, json TEXT NOT NULL, created_at INTEGER NOT NULL, modified_at INTEGER NOT NULL, PRIMARY KEY(kind,id)); CREATE INDEX linkedin_ads_account ON linkedin_ads_records(kind,account_id)");
|
|
104217
104645
|
}
|
|
104218
104646
|
function get2(ctx, kind, id12) {
|
|
@@ -104724,11 +105152,11 @@ function linkedinAdsTwin() {
|
|
|
104724
105152
|
const app2 = new Hono3();
|
|
104725
105153
|
for (const route11 of linkedinAdsRoutes) app2.on(route11.method, route11.path, handle4(route11));
|
|
104726
105154
|
app2.all("*", unknown2);
|
|
104727
|
-
return { name: "linkedin-ads", basePath: "", app: app2, migrate:
|
|
105155
|
+
return { name: "linkedin-ads", basePath: "", app: app2, migrate: migrate12, seed: seed11, credentials: credentials10, actions: {}, checks: {}, dumpState: dumpState10, coverage: linkedinAdsCoverage };
|
|
104728
105156
|
}
|
|
104729
105157
|
|
|
104730
105158
|
// packages/server/src/twins/gong/db.ts
|
|
104731
|
-
function
|
|
105159
|
+
function migrate13(db2) {
|
|
104732
105160
|
db2.exec(`CREATE TABLE gong_data (id INTEGER PRIMARY KEY CHECK(id=1), json TEXT NOT NULL);
|
|
104733
105161
|
CREATE TABLE gong_credentials (principal_id TEXT PRIMARY KEY, access_key TEXT NOT NULL UNIQUE, access_secret TEXT NOT NULL);
|
|
104734
105162
|
CREATE TABLE gong_quota (account_id TEXT NOT NULL, window TEXT NOT NULL, bucket INTEGER NOT NULL, count INTEGER NOT NULL, PRIMARY KEY(account_id,window));`);
|
|
@@ -104867,13 +105295,13 @@ function handle5(route11) {
|
|
|
104867
105295
|
};
|
|
104868
105296
|
}
|
|
104869
105297
|
var unknown3 = handle5({ method: "GET", path: "*", scope: "", notes: "", run: (c) => unsupported9(`${c.req.method} ${new URL(c.req.url).pathname}`) });
|
|
104870
|
-
function
|
|
104871
|
-
if (Array.isArray(value4)) return `[${value4.map(
|
|
104872
|
-
if (value4 && typeof value4 === "object") return `{${Object.entries(value4).filter(([, v]) => v !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${JSON.stringify(k)}:${
|
|
105298
|
+
function canonical4(value4) {
|
|
105299
|
+
if (Array.isArray(value4)) return `[${value4.map(canonical4).join(",")}]`;
|
|
105300
|
+
if (value4 && typeof value4 === "object") return `{${Object.entries(value4).filter(([, v]) => v !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${JSON.stringify(k)}:${canonical4(v)}`).join(",")}}`;
|
|
104873
105301
|
return JSON.stringify(value4);
|
|
104874
105302
|
}
|
|
104875
105303
|
function pageRequest(ctx, principal, op, criteria, raw3) {
|
|
104876
|
-
const hash4 = createHash15("sha256").update(
|
|
105304
|
+
const hash4 = createHash15("sha256").update(canonical4(criteria)).digest("hex");
|
|
104877
105305
|
const base3 = { v: 1, env: ctx.envId, principal: principal.id, op, hash: hash4, page: 0, asOf: ctx.clock.elapsedMs() };
|
|
104878
105306
|
const sign2 = (payload2) => createHmac2("sha256", ctx.store.meta.get("gong.cursor-secret")).update(payload2).digest("base64url");
|
|
104879
105307
|
let cursor4 = base3;
|
|
@@ -105007,11 +105435,11 @@ function gongTwin() {
|
|
|
105007
105435
|
const app2 = new Hono3();
|
|
105008
105436
|
for (const route11 of gongRoutes) app2.on(route11.method, route11.path, handle5(route11));
|
|
105009
105437
|
app2.all("*", unknown3);
|
|
105010
|
-
return { name: "gong", basePath: "", app: app2, migrate:
|
|
105438
|
+
return { name: "gong", basePath: "", app: app2, migrate: migrate13, seed: seed12, credentials: credentials11, dumpState: dumpState11, actions: {}, checks: {}, coverage: gongCoverage };
|
|
105011
105439
|
}
|
|
105012
105440
|
|
|
105013
105441
|
// packages/server/src/twins/open-meteo/db.ts
|
|
105014
|
-
function
|
|
105442
|
+
function migrate14(db2) {
|
|
105015
105443
|
db2.exec("CREATE TABLE open_meteo_data (id INTEGER PRIMARY KEY CHECK(id=1), json TEXT NOT NULL);");
|
|
105016
105444
|
}
|
|
105017
105445
|
function seed13(ctx) {
|
|
@@ -105259,12 +105687,12 @@ function openMeteoTwin() {
|
|
|
105259
105687
|
app2.get("/v1/forecast", handle6(forecast));
|
|
105260
105688
|
app2.get("/v1/search", handle6(search4));
|
|
105261
105689
|
app2.all("*", handle6(unknownRoute5));
|
|
105262
|
-
return { name: "open-meteo", basePath: "", app: app2, migrate:
|
|
105690
|
+
return { name: "open-meteo", basePath: "", app: app2, migrate: migrate14, seed: seed13, credentials: credentials12, dumpState: dumpState12, actions: {}, checks: {}, coverage: openMeteoCoverage };
|
|
105263
105691
|
}
|
|
105264
105692
|
|
|
105265
105693
|
// packages/server/src/twins/google-drive/db.ts
|
|
105266
105694
|
import { createHash as createHash16 } from "node:crypto";
|
|
105267
|
-
var
|
|
105695
|
+
var SCHEMA6 = `
|
|
105268
105696
|
CREATE TABLE gdrive_users (email TEXT PRIMARY KEY, name TEXT, permission_id TEXT NOT NULL UNIQUE, root_id TEXT NOT NULL UNIQUE);
|
|
105269
105697
|
CREATE TABLE gdrive_files (
|
|
105270
105698
|
id TEXT PRIMARY KEY, name TEXT NOT NULL, mime_type TEXT NOT NULL, owner TEXT NOT NULL, parent TEXT, description TEXT,
|
|
@@ -105290,8 +105718,8 @@ CREATE TABLE gdrive_revisions (file_id TEXT NOT NULL, id TEXT NOT NULL, mime_typ
|
|
|
105290
105718
|
CREATE TABLE gdrive_changes (seq INTEGER PRIMARY KEY, file_id TEXT NOT NULL, owner TEXT NOT NULL, removed INTEGER NOT NULL, time_ms INTEGER NOT NULL);
|
|
105291
105719
|
CREATE TABLE gdrive_notifications (seq INTEGER PRIMARY KEY, file_id TEXT NOT NULL, recipient TEXT NOT NULL, sender TEXT NOT NULL, role TEXT NOT NULL, message TEXT, time_ms INTEGER NOT NULL);
|
|
105292
105720
|
`;
|
|
105293
|
-
function
|
|
105294
|
-
db2.exec(
|
|
105721
|
+
function migrate15(db2) {
|
|
105722
|
+
db2.exec(SCHEMA6);
|
|
105295
105723
|
}
|
|
105296
105724
|
var RANK2 = { reader: 1, commenter: 2, writer: 3, owner: 4 };
|
|
105297
105725
|
var isFolder = (file3) => file3.mime_type === GOOGLE_DRIVE_FOLDER;
|
|
@@ -105917,12 +106345,12 @@ function parseQuery(source, aliases) {
|
|
|
105917
106345
|
return (file3) => file3.sharedWithMe;
|
|
105918
106346
|
}
|
|
105919
106347
|
const operator2 = expect();
|
|
105920
|
-
const
|
|
105921
|
-
if (!
|
|
106348
|
+
const contains3 = operator2.kind === "word" && operator2.value.toLowerCase() === "contains";
|
|
106349
|
+
if (!contains3 && operator2.kind !== "op") {
|
|
105922
106350
|
if (operator2.kind === "word" && operator2.value.toLowerCase() === "has") unsupported11(`${field3} has search`);
|
|
105923
106351
|
throw invalid10("q");
|
|
105924
106352
|
}
|
|
105925
|
-
const op =
|
|
106353
|
+
const op = contains3 ? "contains" : operator2.value;
|
|
105926
106354
|
switch (field3) {
|
|
105927
106355
|
case "name": {
|
|
105928
106356
|
const value4 = literal2();
|
|
@@ -107141,7 +107569,7 @@ async function handle7(c) {
|
|
|
107141
107569
|
function googleDriveTwin() {
|
|
107142
107570
|
const app2 = new Hono3();
|
|
107143
107571
|
app2.all("*", handle7);
|
|
107144
|
-
return { name: "google-drive", basePath: "", unprefixedPaths: /^\/(?:upload\/)?drive\/v3\//, app: app2, migrate:
|
|
107572
|
+
return { name: "google-drive", basePath: "", unprefixedPaths: /^\/(?:upload\/)?drive\/v3\//, app: app2, migrate: migrate15, seed: seed14, credentials: credentials13, dumpState: dumpState13, actions: {}, checks: {}, coverage: googleDriveCoverage };
|
|
107145
107573
|
}
|
|
107146
107574
|
|
|
107147
107575
|
// packages/server/src/twins/gmail/checks.ts
|
|
@@ -108459,9 +108887,9 @@ function stringToSign(method2, path4, query10, headers, signature) {
|
|
|
108459
108887
|
const canonicalQuery = query10.filter(([key3]) => !(signature.presigned && key3 === "X-Amz-Signature")).map(([key3, value4]) => [awsEncode(key3), awsEncode(value4)]).sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0).map(([key3, value4]) => `${key3}=${value4}`).join("&");
|
|
108460
108888
|
const canonicalHeaders = signature.signedHeaders.map((name5) => `${name5}:${(headers.get(name5) ?? "").trim().replace(/\s+/g, " ")}
|
|
108461
108889
|
`).join("");
|
|
108462
|
-
const
|
|
108463
|
-
const toSign = ["AWS4-HMAC-SHA256", signature.amzDate, `${signature.date}/${signature.region}/s3/aws4_request`, sha256Hex(
|
|
108464
|
-
return { canonical:
|
|
108890
|
+
const canonical5 = [method2, path4, canonicalQuery, canonicalHeaders, signature.signedHeaders.join(";"), signature.payloadHash].join("\n");
|
|
108891
|
+
const toSign = ["AWS4-HMAC-SHA256", signature.amzDate, `${signature.date}/${signature.region}/s3/aws4_request`, sha256Hex(canonical5)].join("\n");
|
|
108892
|
+
return { canonical: canonical5, toSign };
|
|
108465
108893
|
}
|
|
108466
108894
|
function verifySignature(secret, signature, toSign) {
|
|
108467
108895
|
const key3 = hmac(hmac(hmac(hmac(`AWS4${secret}`, signature.date), signature.region), "s3"), "aws4_request");
|
|
@@ -108527,7 +108955,7 @@ var md5Hex = (data5) => createHash19("md5").update(data5).digest("hex");
|
|
|
108527
108955
|
var sha2562 = sha256Hex;
|
|
108528
108956
|
|
|
108529
108957
|
// packages/server/src/twins/amazon-s3/db.ts
|
|
108530
|
-
var
|
|
108958
|
+
var SCHEMA7 = `
|
|
108531
108959
|
CREATE TABLE s3_buckets (name TEXT PRIMARY KEY, region TEXT NOT NULL, created_ms INTEGER NOT NULL, access TEXT NOT NULL, tags TEXT);
|
|
108532
108960
|
CREATE TABLE s3_objects (
|
|
108533
108961
|
bucket TEXT NOT NULL, key TEXT NOT NULL, content BLOB NOT NULL, content_type TEXT NOT NULL, etag TEXT NOT NULL,
|
|
@@ -108542,8 +108970,8 @@ CREATE TABLE s3_uploads (
|
|
|
108542
108970
|
CREATE TABLE s3_parts (upload_id TEXT NOT NULL, part_number INTEGER NOT NULL, content BLOB NOT NULL, etag TEXT NOT NULL, modified_ms INTEGER NOT NULL, PRIMARY KEY (upload_id, part_number));
|
|
108543
108971
|
CREATE TABLE s3_taken_names (name TEXT PRIMARY KEY);
|
|
108544
108972
|
`;
|
|
108545
|
-
function
|
|
108546
|
-
db2.exec(
|
|
108973
|
+
function migrate16(db2) {
|
|
108974
|
+
db2.exec(SCHEMA7);
|
|
108547
108975
|
}
|
|
108548
108976
|
function account3(ctx) {
|
|
108549
108977
|
return JSON.parse(ctx.store.meta.get("amazon-s3.account"));
|
|
@@ -109400,11 +109828,11 @@ async function handle8(c) {
|
|
|
109400
109828
|
function amazonS3Twin() {
|
|
109401
109829
|
const app2 = new Hono3();
|
|
109402
109830
|
app2.all("*", handle8);
|
|
109403
|
-
return { name: "amazon-s3", basePath: "", app: app2, migrate:
|
|
109831
|
+
return { name: "amazon-s3", basePath: "", app: app2, migrate: migrate16, seed: seed16, credentials: credentials15, dumpState: dumpState15, actions: {}, checks: {}, coverage: amazonS3Coverage };
|
|
109404
109832
|
}
|
|
109405
109833
|
|
|
109406
109834
|
// packages/server/src/twins/linear/db.ts
|
|
109407
|
-
var
|
|
109835
|
+
var SCHEMA8 = `
|
|
109408
109836
|
CREATE TABLE linear_org (id TEXT PRIMARY KEY, name TEXT NOT NULL, url_key TEXT NOT NULL, created_at TEXT NOT NULL);
|
|
109409
109837
|
CREATE TABLE linear_users (id TEXT PRIMARY KEY, ref TEXT UNIQUE, name TEXT NOT NULL, display_name TEXT NOT NULL, email TEXT NOT NULL COLLATE NOCASE UNIQUE,
|
|
109410
109838
|
admin INTEGER NOT NULL, guest INTEGER NOT NULL, active INTEGER NOT NULL, title TEXT, timezone TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL);
|
|
@@ -109428,8 +109856,8 @@ CREATE TABLE linear_issue_labels (issue_id TEXT NOT NULL, label_id TEXT NOT NULL
|
|
|
109428
109856
|
CREATE TABLE linear_comments (id TEXT PRIMARY KEY, issue_id TEXT NOT NULL, user_id TEXT NOT NULL, body TEXT NOT NULL, parent_id TEXT,
|
|
109429
109857
|
created_at TEXT NOT NULL, updated_at TEXT NOT NULL, edited_at TEXT, archived_at TEXT);
|
|
109430
109858
|
`;
|
|
109431
|
-
function
|
|
109432
|
-
db2.exec(
|
|
109859
|
+
function migrate17(db2) {
|
|
109860
|
+
db2.exec(SCHEMA8);
|
|
109433
109861
|
}
|
|
109434
109862
|
var one = (ctx, sql, ...args) => ctx.store.db.prepare(sql).get(...args);
|
|
109435
109863
|
var all2 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).all(...args);
|
|
@@ -110591,7 +111019,7 @@ function linearTwin() {
|
|
|
110591
111019
|
const app2 = new Hono3();
|
|
110592
111020
|
app2.post("/graphql", handleGraphql);
|
|
110593
111021
|
app2.all("*", unknownRoute7);
|
|
110594
|
-
return { name: "linear", basePath: "/graphql", app: app2, migrate:
|
|
111022
|
+
return { name: "linear", basePath: "/graphql", app: app2, migrate: migrate17, seed: seed17, credentials: credentials16, actions: {}, checks: {}, dumpState: dumpState16, coverage: linearCoverage };
|
|
110595
111023
|
}
|
|
110596
111024
|
|
|
110597
111025
|
// packages/server/src/twins/okta/index.ts
|
|
@@ -110599,7 +111027,7 @@ import { createHash as createHash25 } from "node:crypto";
|
|
|
110599
111027
|
|
|
110600
111028
|
// packages/server/src/twins/okta/db.ts
|
|
110601
111029
|
import { createHash as createHash23 } from "node:crypto";
|
|
110602
|
-
var
|
|
111030
|
+
var SCHEMA9 = `
|
|
110603
111031
|
CREATE TABLE okta_users (
|
|
110604
111032
|
id TEXT PRIMARY KEY, login TEXT NOT NULL UNIQUE COLLATE NOCASE, status TEXT NOT NULL, created_ms INTEGER NOT NULL, activated_ms INTEGER,
|
|
110605
111033
|
status_changed_ms INTEGER, last_login_ms INTEGER, last_updated_ms INTEGER NOT NULL, password_changed_ms INTEGER, has_password INTEGER NOT NULL DEFAULT 0,
|
|
@@ -110615,8 +111043,8 @@ CREATE TABLE okta_logs (
|
|
|
110615
111043
|
outcome TEXT NOT NULL, reason TEXT, actor_id TEXT NOT NULL, targets TEXT NOT NULL
|
|
110616
111044
|
);
|
|
110617
111045
|
`;
|
|
110618
|
-
function
|
|
110619
|
-
db2.exec(
|
|
111046
|
+
function migrate18(db2) {
|
|
111047
|
+
db2.exec(SCHEMA9);
|
|
110620
111048
|
}
|
|
110621
111049
|
var BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
110622
111050
|
var hashed = (value4, length) => [...createHash23("sha256").update(value4).digest()].slice(0, length).map((byte) => BASE62[byte % 62]).join("");
|
|
@@ -111675,18 +112103,18 @@ async function handle9(c) {
|
|
|
111675
112103
|
function oktaTwin() {
|
|
111676
112104
|
const app2 = new Hono3();
|
|
111677
112105
|
app2.all("*", handle9);
|
|
111678
|
-
return { name: "okta", basePath: "", app: app2, migrate:
|
|
112106
|
+
return { name: "okta", basePath: "", app: app2, migrate: migrate18, seed: seed18, credentials: credentials17, dumpState: dumpState17, actions: {}, checks: { user: user5 }, coverage: oktaCoverage };
|
|
111679
112107
|
}
|
|
111680
112108
|
|
|
111681
112109
|
// packages/server/src/twins/stripe/db.ts
|
|
111682
|
-
var
|
|
112110
|
+
var SCHEMA10 = `
|
|
111683
112111
|
CREATE TABLE stripe_objects (id TEXT PRIMARY KEY, type TEXT NOT NULL, seq INTEGER NOT NULL, created INTEGER NOT NULL, customer TEXT, json TEXT NOT NULL);
|
|
111684
112112
|
CREATE INDEX stripe_objects_type ON stripe_objects (type, created, seq);
|
|
111685
112113
|
CREATE TABLE stripe_keys (key TEXT PRIMARY KEY);
|
|
111686
112114
|
CREATE TABLE stripe_idempotency (key TEXT PRIMARY KEY, fingerprint TEXT NOT NULL, status INTEGER NOT NULL, body TEXT NOT NULL);
|
|
111687
112115
|
`;
|
|
111688
|
-
function
|
|
111689
|
-
db2.exec(
|
|
112116
|
+
function migrate19(db2) {
|
|
112117
|
+
db2.exec(SCHEMA10);
|
|
111690
112118
|
}
|
|
111691
112119
|
function load(ctx, id12) {
|
|
111692
112120
|
const row = ctx.store.db.prepare("SELECT json FROM stripe_objects WHERE id = ?").get(id12);
|
|
@@ -113751,7 +114179,7 @@ function stripeTwin() {
|
|
|
113751
114179
|
const app2 = new Hono3();
|
|
113752
114180
|
for (const route11 of [...stripeRoutes].sort((a, b) => Number(a.path.includes(":")) - Number(b.path.includes(":")))) app2.on(route11.method, route11.path, handle10(route11));
|
|
113753
114181
|
app2.all("*", unknownRoute8);
|
|
113754
|
-
return { name: "stripe", basePath: "", app: app2, migrate:
|
|
114182
|
+
return { name: "stripe", basePath: "", app: app2, migrate: migrate19, seed: seed19, credentials: credentials18, actions: {}, checks: {}, dumpState: dumpState18, coverage: stripeCoverage };
|
|
113755
114183
|
}
|
|
113756
114184
|
|
|
113757
114185
|
// packages/server/src/twins/clerk/index.ts
|
|
@@ -113759,7 +114187,7 @@ import { createHash as createHash29 } from "node:crypto";
|
|
|
113759
114187
|
|
|
113760
114188
|
// packages/server/src/twins/clerk/db.ts
|
|
113761
114189
|
import { createHash as createHash27 } from "node:crypto";
|
|
113762
|
-
var
|
|
114190
|
+
var SCHEMA11 = `
|
|
113763
114191
|
CREATE TABLE clerk_users (
|
|
113764
114192
|
id TEXT PRIMARY KEY, email TEXT NOT NULL UNIQUE COLLATE NOCASE, email_id TEXT NOT NULL, email_strategy TEXT NOT NULL DEFAULT 'email_code', first_name TEXT, last_name TEXT, username TEXT UNIQUE,
|
|
113765
114193
|
external_id TEXT, password_enabled INTEGER NOT NULL, banned INTEGER NOT NULL DEFAULT 0, locked INTEGER NOT NULL DEFAULT 0,
|
|
@@ -113777,8 +114205,8 @@ CREATE TABLE clerk_invitations (
|
|
|
113777
114205
|
);
|
|
113778
114206
|
CREATE TABLE clerk_sessions (id TEXT PRIMARY KEY, client_id TEXT NOT NULL, user_id TEXT NOT NULL, status TEXT NOT NULL, last_active_ms INTEGER NOT NULL, org_id TEXT, expire_ms INTEGER NOT NULL, created_ms INTEGER NOT NULL, updated_ms INTEGER NOT NULL);
|
|
113779
114207
|
`;
|
|
113780
|
-
function
|
|
113781
|
-
db2.exec(
|
|
114208
|
+
function migrate20(db2) {
|
|
114209
|
+
db2.exec(SCHEMA11);
|
|
113782
114210
|
}
|
|
113783
114211
|
var BASE623 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
113784
114212
|
var seededId2 = (prefix2, key3) => `${prefix2}_2${[...createHash27("sha256").update(`clerk:${prefix2}:${key3}`).digest()].slice(0, 26).map((byte) => BASE623[byte % 62]).join("")}`;
|
|
@@ -114181,10 +114609,10 @@ function filterUsers(call2, query10) {
|
|
|
114181
114609
|
const found = getOrg(ctx, org5);
|
|
114182
114610
|
return found ? membershipsOf(ctx, found.id).map((member4) => member4.user_id) : [];
|
|
114183
114611
|
})) : void 0;
|
|
114184
|
-
const
|
|
114612
|
+
const contains3 = (value4, needle) => needle === null || (value4 ?? "").toLowerCase().includes(needle.toLowerCase());
|
|
114185
114613
|
const q = query10.get("query"), banned = bool4(query10.get("banned") ?? void 0, "banned");
|
|
114186
114614
|
const before = time7("last_active_at_before"), after = time7("last_active_at_after") ?? time7("last_active_at_since"), createdBefore = time7("created_at_before"), createdAfter = time7("created_at_after");
|
|
114187
|
-
return ctx.store.db.prepare("SELECT * FROM clerk_users").all().filter((user8) => (!emails.length || emails.includes(user8.email.toLowerCase())) && (!ids2.length || ids2.includes(user8.id)) && (!usernames.length || usernames.includes(user8.username ?? "")) && (!externals.length || externals.includes(user8.external_id ?? "")) && (!members4 || members4.has(user8.id)) && (q === null || [user8.email, user8.first_name, user8.last_name, user8.username, user8.id, user8.external_id, `${user8.first_name ?? ""} ${user8.last_name ?? ""}`].some((value4) =>
|
|
114615
|
+
return ctx.store.db.prepare("SELECT * FROM clerk_users").all().filter((user8) => (!emails.length || emails.includes(user8.email.toLowerCase())) && (!ids2.length || ids2.includes(user8.id)) && (!usernames.length || usernames.includes(user8.username ?? "")) && (!externals.length || externals.includes(user8.external_id ?? "")) && (!members4 || members4.has(user8.id)) && (q === null || [user8.email, user8.first_name, user8.last_name, user8.username, user8.id, user8.external_id, `${user8.first_name ?? ""} ${user8.last_name ?? ""}`].some((value4) => contains3(value4, q))) && contains3(user8.email, query10.get("email_address_query")) && contains3(user8.username, query10.get("username_query")) && contains3(`${user8.first_name ?? ""} ${user8.last_name ?? ""}`, query10.get("name_query")) && (banned === void 0 || user8.banned === 1 === banned) && (before === void 0 || user8.last_active_ms !== null && user8.last_active_ms < before) && (after === void 0 || user8.last_active_ms !== null && user8.last_active_ms > after) && (createdBefore === void 0 || user8.created_ms < createdBefore) && (createdAfter === void 0 || user8.created_ms > createdAfter));
|
|
114188
114616
|
}
|
|
114189
114617
|
var USER_ORDER = {
|
|
114190
114618
|
created_at: (user8) => user8.created_ms,
|
|
@@ -114714,12 +115142,12 @@ async function handle11(c) {
|
|
|
114714
115142
|
function clerkTwin() {
|
|
114715
115143
|
const app2 = new Hono3();
|
|
114716
115144
|
app2.all("*", handle11);
|
|
114717
|
-
return { name: "clerk", basePath: "", app: app2, migrate:
|
|
115145
|
+
return { name: "clerk", basePath: "", app: app2, migrate: migrate20, seed: seed20, credentials: credentials19, dumpState: dumpState19, actions: {}, checks: {}, coverage: clerkCoverage };
|
|
114718
115146
|
}
|
|
114719
115147
|
|
|
114720
115148
|
// packages/server/src/twins/better-stack/db.ts
|
|
114721
115149
|
import { createHash as createHash30 } from "node:crypto";
|
|
114722
|
-
var
|
|
115150
|
+
var SCHEMA12 = `
|
|
114723
115151
|
CREATE TABLE bs_users (id TEXT PRIMARY KEY, email TEXT NOT NULL UNIQUE, first_name TEXT NOT NULL, last_name TEXT NOT NULL, phone TEXT);
|
|
114724
115152
|
CREATE TABLE bs_sources (
|
|
114725
115153
|
id TEXT PRIMARY KEY, kind TEXT NOT NULL, name TEXT NOT NULL, url TEXT, monitor_type TEXT, check_frequency INTEGER, required_keyword TEXT, monitor_group TEXT,
|
|
@@ -114735,8 +115163,8 @@ CREATE TABLE bs_resources (id TEXT PRIMARY KEY, page_id TEXT NOT NULL, public_na
|
|
|
114735
115163
|
CREATE TABLE bs_reports (id TEXT PRIMARY KEY, page_id TEXT NOT NULL, title TEXT NOT NULL, report_type TEXT NOT NULL, starts_ms INTEGER NOT NULL, ends_ms INTEGER, created_ms INTEGER NOT NULL);
|
|
114736
115164
|
CREATE TABLE bs_updates (id TEXT PRIMARY KEY, report_id TEXT NOT NULL, message TEXT NOT NULL, published_ms INTEGER NOT NULL, affected TEXT NOT NULL);
|
|
114737
115165
|
`;
|
|
114738
|
-
function
|
|
114739
|
-
db2.exec(
|
|
115166
|
+
function migrate21(db2) {
|
|
115167
|
+
db2.exec(SCHEMA12);
|
|
114740
115168
|
}
|
|
114741
115169
|
var BASES = { user: 145001, monitor: 2245001, heartbeat: 441501, incident: 600001, calendar: 9001, page: 160001, resource: 8800001, report: 3300001, update: 7700001 };
|
|
114742
115170
|
function nextId3(ctx, kind) {
|
|
@@ -115505,18 +115933,18 @@ async function handle12(c) {
|
|
|
115505
115933
|
function betterStackTwin() {
|
|
115506
115934
|
const app2 = new Hono3();
|
|
115507
115935
|
app2.all("*", handle12);
|
|
115508
|
-
return { name: "better-stack", basePath: "", app: app2, migrate:
|
|
115936
|
+
return { name: "better-stack", basePath: "", app: app2, migrate: migrate21, seed: seed21, credentials: credentials20, dumpState: dumpState20, actions: {}, checks: {}, coverage: betterStackCoverage };
|
|
115509
115937
|
}
|
|
115510
115938
|
|
|
115511
115939
|
// packages/server/src/twins/notion/db.ts
|
|
115512
|
-
var
|
|
115940
|
+
var SCHEMA13 = `
|
|
115513
115941
|
CREATE TABLE notion_nodes (id TEXT PRIMARY KEY, kind TEXT NOT NULL CHECK (kind IN ('user','page','block','database','data_source','comment')),
|
|
115514
115942
|
parent_id TEXT, position REAL NOT NULL DEFAULT 0, json TEXT NOT NULL);
|
|
115515
115943
|
CREATE INDEX notion_nodes_parent ON notion_nodes (parent_id, position);
|
|
115516
115944
|
CREATE TABLE notion_tokens (token TEXT PRIMARY KEY, bot_id TEXT NOT NULL);
|
|
115517
115945
|
`;
|
|
115518
|
-
function
|
|
115519
|
-
db2.exec(
|
|
115946
|
+
function migrate22(db2) {
|
|
115947
|
+
db2.exec(SCHEMA13);
|
|
115520
115948
|
}
|
|
115521
115949
|
var node4 = (row) => row && { id: row.id, kind: row.kind, parent_id: row.parent_id, position: row.position, doc: JSON.parse(row.json) };
|
|
115522
115950
|
function get3(ctx, id12) {
|
|
@@ -116723,11 +117151,11 @@ function notionTwin() {
|
|
|
116723
117151
|
const app2 = new Hono3();
|
|
116724
117152
|
for (const route11 of [...notionRoutes].sort((a, b) => Number(a.path.includes(":")) - Number(b.path.includes(":")))) app2.on(route11.method, route11.path, handle13(route11));
|
|
116725
117153
|
app2.all("*", unknownRoute9);
|
|
116726
|
-
return { name: "notion", basePath: "", app: app2, migrate:
|
|
117154
|
+
return { name: "notion", basePath: "", app: app2, migrate: migrate22, seed: seed22, credentials: credentials21, actions: {}, checks: {}, dumpState: dumpState21, coverage: notionCoverage };
|
|
116727
117155
|
}
|
|
116728
117156
|
|
|
116729
117157
|
// packages/server/src/twins/attio/db.ts
|
|
116730
|
-
var
|
|
117158
|
+
var SCHEMA14 = `
|
|
116731
117159
|
CREATE TABLE attio_members (id TEXT PRIMARY KEY, ref TEXT, first_name TEXT NOT NULL, last_name TEXT NOT NULL, email TEXT NOT NULL, access_level TEXT NOT NULL, created_at TEXT NOT NULL);
|
|
116732
117160
|
CREATE TABLE attio_tokens (token TEXT PRIMARY KEY, member_id TEXT NOT NULL);
|
|
116733
117161
|
CREATE TABLE attio_objects (id TEXT PRIMARY KEY, api_slug TEXT NOT NULL UNIQUE, singular_noun TEXT NOT NULL, plural_noun TEXT NOT NULL, created_at TEXT NOT NULL);
|
|
@@ -116744,8 +117172,8 @@ CREATE INDEX attio_values_parent ON attio_values (parent_id, attribute_id, activ
|
|
|
116744
117172
|
CREATE TABLE attio_notes (id TEXT PRIMARY KEY, parent_object TEXT NOT NULL, parent_record_id TEXT NOT NULL, title TEXT NOT NULL, content TEXT NOT NULL, created_by TEXT NOT NULL, created_at TEXT NOT NULL);
|
|
116745
117173
|
CREATE TABLE attio_tasks (id TEXT PRIMARY KEY, content TEXT NOT NULL, deadline_at TEXT, is_completed INTEGER NOT NULL, linked TEXT NOT NULL, assignees TEXT NOT NULL, created_by TEXT NOT NULL, created_at TEXT NOT NULL);
|
|
116746
117174
|
`;
|
|
116747
|
-
function
|
|
116748
|
-
db2.exec(
|
|
117175
|
+
function migrate23(db2) {
|
|
117176
|
+
db2.exec(SCHEMA14);
|
|
116749
117177
|
}
|
|
116750
117178
|
var one2 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).get(...args);
|
|
116751
117179
|
var all5 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).all(...args);
|
|
@@ -117549,7 +117977,7 @@ var attioRoutes = [
|
|
|
117549
117977
|
];
|
|
117550
117978
|
|
|
117551
117979
|
// packages/server/src/twins/attio/seed.ts
|
|
117552
|
-
var
|
|
117980
|
+
var SYSTEM2 = [
|
|
117553
117981
|
{ api_slug: "record_id", title: "Record ID", type: "text", system: true, writable: false }
|
|
117554
117982
|
];
|
|
117555
117983
|
var TAIL = [
|
|
@@ -117559,7 +117987,7 @@ var TAIL = [
|
|
|
117559
117987
|
function standard(dealStages, categories) {
|
|
117560
117988
|
return {
|
|
117561
117989
|
people: { singular: "Person", plural: "People", attributes: [
|
|
117562
|
-
...
|
|
117990
|
+
...SYSTEM2,
|
|
117563
117991
|
{ api_slug: "name", title: "Name", type: "personal-name", system: true },
|
|
117564
117992
|
{ api_slug: "email_addresses", title: "Email addresses", type: "email-address", is_multiselect: true, is_unique: true, system: true },
|
|
117565
117993
|
{ api_slug: "phone_numbers", title: "Phone numbers", type: "phone-number", is_multiselect: true, system: true },
|
|
@@ -117569,7 +117997,7 @@ function standard(dealStages, categories) {
|
|
|
117569
117997
|
...TAIL
|
|
117570
117998
|
] },
|
|
117571
117999
|
companies: { singular: "Company", plural: "Companies", attributes: [
|
|
117572
|
-
...
|
|
118000
|
+
...SYSTEM2,
|
|
117573
118001
|
{ api_slug: "name", title: "Name", type: "text", system: true },
|
|
117574
118002
|
{ api_slug: "domains", title: "Domains", type: "domain", is_multiselect: true, is_unique: true, system: true },
|
|
117575
118003
|
{ api_slug: "description", title: "Description", type: "text", system: true },
|
|
@@ -117578,7 +118006,7 @@ function standard(dealStages, categories) {
|
|
|
117578
118006
|
...TAIL
|
|
117579
118007
|
] },
|
|
117580
118008
|
deals: { singular: "Deal", plural: "Deals", attributes: [
|
|
117581
|
-
...
|
|
118009
|
+
...SYSTEM2,
|
|
117582
118010
|
{ api_slug: "name", title: "Deal name", type: "text", is_required: true, system: true },
|
|
117583
118011
|
{ api_slug: "stage", title: "Deal stage", type: "status", is_required: true, options: dealStages, system: true },
|
|
117584
118012
|
{ api_slug: "owner", title: "Deal owner", type: "actor-reference", is_required: true, system: true },
|
|
@@ -117751,12 +118179,12 @@ function attioTwin() {
|
|
|
117751
118179
|
const rank = (path4) => path4.split("/").filter((s) => s.startsWith(":")).length;
|
|
117752
118180
|
for (const route11 of [...attioRoutes].sort((a, b) => rank(a.path) - rank(b.path))) app2.on(route11.method, route11.path, handle14(route11));
|
|
117753
118181
|
app2.all("*", unknownRoute10);
|
|
117754
|
-
return { name: "attio", basePath: "", app: app2, migrate:
|
|
118182
|
+
return { name: "attio", basePath: "", app: app2, migrate: migrate23, seed: seed23, credentials: credentials22, actions: {}, checks: {}, dumpState: dumpState22, coverage: attioCoverage };
|
|
117755
118183
|
}
|
|
117756
118184
|
|
|
117757
118185
|
// packages/server/src/twins/dropbox/db.ts
|
|
117758
118186
|
import { createHash as createHash33 } from "node:crypto";
|
|
117759
|
-
var
|
|
118187
|
+
var SCHEMA15 = `
|
|
117760
118188
|
CREATE TABLE dbx_entries (
|
|
117761
118189
|
path_lower TEXT PRIMARY KEY, path_display TEXT NOT NULL, id TEXT NOT NULL UNIQUE, kind TEXT NOT NULL, rev TEXT, content BLOB,
|
|
117762
118190
|
client_modified_ms INTEGER, server_modified_ms INTEGER, uploaded_by TEXT, shared_folder_id TEXT
|
|
@@ -117770,8 +118198,8 @@ CREATE TABLE dbx_changes (seq INTEGER PRIMARY KEY, path_lower TEXT NOT NULL);
|
|
|
117770
118198
|
CREATE TABLE dbx_temp_links (token TEXT PRIMARY KEY, path_lower TEXT NOT NULL, rev TEXT NOT NULL, expires_ms INTEGER NOT NULL);
|
|
117771
118199
|
CREATE TABLE dbx_people (email TEXT PRIMARY KEY, name TEXT NOT NULL, same_team INTEGER NOT NULL);
|
|
117772
118200
|
`;
|
|
117773
|
-
function
|
|
117774
|
-
db2.exec(
|
|
118201
|
+
function migrate24(db2) {
|
|
118202
|
+
db2.exec(SCHEMA15);
|
|
117775
118203
|
}
|
|
117776
118204
|
var account5 = (ctx) => JSON.parse(ctx.store.meta.get("dropbox.account"));
|
|
117777
118205
|
var getEntry = (ctx, pathLower) => ctx.store.db.prepare("SELECT * FROM dbx_entries WHERE path_lower = ?").get(pathLower);
|
|
@@ -118551,7 +118979,7 @@ async function handle15(c) {
|
|
|
118551
118979
|
function dropboxTwin() {
|
|
118552
118980
|
const app2 = new Hono3();
|
|
118553
118981
|
app2.all("*", handle15);
|
|
118554
|
-
return { name: "dropbox", basePath: "", app: app2, migrate:
|
|
118982
|
+
return { name: "dropbox", basePath: "", app: app2, migrate: migrate24, seed: seed24, credentials: credentials23, dumpState: dumpState23, actions: {}, checks: {}, coverage: dropboxCoverage };
|
|
118555
118983
|
}
|
|
118556
118984
|
|
|
118557
118985
|
// packages/server/src/twins/resend/request.ts
|
|
@@ -118648,7 +119076,7 @@ function unknownRoute11(c) {
|
|
|
118648
119076
|
}
|
|
118649
119077
|
|
|
118650
119078
|
// packages/server/src/twins/resend/routes.ts
|
|
118651
|
-
function
|
|
119079
|
+
function migrate25(db2) {
|
|
118652
119080
|
db2.exec(`
|
|
118653
119081
|
CREATE TABLE resend_objects (id TEXT PRIMARY KEY, kind TEXT NOT NULL CHECK (kind IN ('email','domain','contact','segment','broadcast')), created_ms INTEGER NOT NULL, json TEXT NOT NULL);
|
|
118654
119082
|
CREATE INDEX resend_objects_kind ON resend_objects (kind, created_ms);
|
|
@@ -119287,7 +119715,7 @@ function resendTwin() {
|
|
|
119287
119715
|
const rank = (path4) => path4.split("/").filter((s) => s.startsWith(":")).length;
|
|
119288
119716
|
for (const route11 of [...resendRoutes].sort((a, b) => rank(a.path) - rank(b.path))) app2.on(route11.method, route11.path, handle16(route11));
|
|
119289
119717
|
app2.all("*", unknownRoute11);
|
|
119290
|
-
return { name: "resend", basePath: "", app: app2, migrate:
|
|
119718
|
+
return { name: "resend", basePath: "", app: app2, migrate: migrate25, seed: seed25, credentials: credentials24, actions: {}, checks: {}, dumpState: dumpState24, coverage: resendCoverage };
|
|
119291
119719
|
}
|
|
119292
119720
|
|
|
119293
119721
|
// packages/server/src/twins/microsoft-word/db.ts
|
|
@@ -119452,7 +119880,7 @@ function quickXorHash(data5) {
|
|
|
119452
119880
|
}
|
|
119453
119881
|
|
|
119454
119882
|
// packages/server/src/twins/microsoft-word/db.ts
|
|
119455
|
-
var
|
|
119883
|
+
var SCHEMA16 = `
|
|
119456
119884
|
CREATE TABLE ms_users (email TEXT PRIMARY KEY, id TEXT NOT NULL UNIQUE, display_name TEXT NOT NULL, job_title TEXT);
|
|
119457
119885
|
CREATE TABLE ms_items (
|
|
119458
119886
|
id TEXT PRIMARY KEY, parent_id TEXT, name TEXT NOT NULL, name_lower TEXT NOT NULL, kind TEXT NOT NULL, mime_type TEXT, content BLOB, description TEXT,
|
|
@@ -119465,8 +119893,8 @@ CREATE TABLE ms_permissions (
|
|
|
119465
119893
|
);
|
|
119466
119894
|
CREATE TABLE ms_invitations (seq INTEGER PRIMARY KEY, item_id TEXT NOT NULL, email TEXT NOT NULL, roles TEXT NOT NULL, message TEXT, time_ms INTEGER NOT NULL);
|
|
119467
119895
|
`;
|
|
119468
|
-
function
|
|
119469
|
-
db2.exec(
|
|
119896
|
+
function migrate26(db2) {
|
|
119897
|
+
db2.exec(SCHEMA16);
|
|
119470
119898
|
}
|
|
119471
119899
|
var hex3 = (value4) => createHash36("sha256").update(value4).digest("hex");
|
|
119472
119900
|
var guid3 = (key3) => {
|
|
@@ -119488,7 +119916,7 @@ var childrenOf2 = (ctx, id12) => ctx.store.db.prepare("SELECT * FROM ms_items WH
|
|
|
119488
119916
|
var userOf = (ctx, email10) => ctx.store.db.prepare("SELECT * FROM ms_users WHERE email = ?").get(email10);
|
|
119489
119917
|
var MIME = { docx: DOCX_TYPE, pdf: "application/pdf", txt: "text/plain", csv: "text/csv", xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation", md: "text/markdown", json: "application/json", png: "image/png" };
|
|
119490
119918
|
var mimeFor = (name5) => MIME[/\.([A-Za-z0-9]+)$/.exec(name5)?.[1]?.toLowerCase() ?? ""] ?? "application/octet-stream";
|
|
119491
|
-
function
|
|
119919
|
+
function pathOf2(ctx, item2) {
|
|
119492
119920
|
const parts3 = [];
|
|
119493
119921
|
for (let node5 = item2; node5 && node5.kind !== "root"; node5 = node5.parent_id ? getItem(ctx, node5.parent_id) : void 0) parts3.unshift(node5.name);
|
|
119494
119922
|
return parts3.length ? `/${parts3.join("/")}` : "";
|
|
@@ -119562,7 +119990,7 @@ function credentials25(ctx) {
|
|
|
119562
119990
|
}
|
|
119563
119991
|
function dumpState25(ctx) {
|
|
119564
119992
|
const db2 = ctx.store.db, iso19 = (ms) => new Date(ms).toISOString();
|
|
119565
|
-
const items = db2.prepare("SELECT * FROM ms_items WHERE kind != 'root'").all().map((item2) => ({ item: item2, path:
|
|
119993
|
+
const items = db2.prepare("SELECT * FROM ms_items WHERE kind != 'root'").all().map((item2) => ({ item: item2, path: pathOf2(ctx, item2) })).sort((a, b) => a.path.toLowerCase() < b.path.toLowerCase() ? -1 : 1);
|
|
119566
119994
|
const paths2 = new Map(items.map((entry2) => [entry2.item.id, entry2.path]));
|
|
119567
119995
|
return {
|
|
119568
119996
|
...config8(ctx),
|
|
@@ -119640,7 +120068,7 @@ function identity3(ctx, email10) {
|
|
|
119640
120068
|
return { user: { email: email10, id: user8?.id ?? guid3(`user:${email10}`), displayName: user8?.display_name ?? email10 } };
|
|
119641
120069
|
}
|
|
119642
120070
|
function itemJson(ctx, item2) {
|
|
119643
|
-
const { driveId, me: me4, tenant } = config8(ctx), path4 =
|
|
120071
|
+
const { driveId, me: me4, tenant } = config8(ctx), path4 = pathOf2(ctx, item2), web = `https://${tenant.domain.split(".")[0]}-my.sharepoint.com/personal/${slug5(me4)}/Documents`;
|
|
119644
120072
|
const tag3 = guid3(`etag:${item2.id}`).toUpperCase(), parent2 = item2.parent_id ? getItem(ctx, item2.parent_id) : void 0;
|
|
119645
120073
|
const size = item2.kind === "file" ? item2.content?.length ?? 0 : childrenSize(ctx, item2);
|
|
119646
120074
|
const shared = sharedScope(ctx, item2);
|
|
@@ -119656,7 +120084,7 @@ function itemJson(ctx, item2) {
|
|
|
119656
120084
|
size,
|
|
119657
120085
|
createdBy: identity3(ctx, item2.created_by),
|
|
119658
120086
|
lastModifiedBy: identity3(ctx, item2.modified_by),
|
|
119659
|
-
parentReference: { driveType: "business", driveId, ...parent2 && { id: parent2.id, name: parent2.kind === "root" ? "Documents" : parent2.name, path: `/drive/root:${
|
|
120087
|
+
parentReference: { driveType: "business", driveId, ...parent2 && { id: parent2.id, name: parent2.kind === "root" ? "Documents" : parent2.name, path: `/drive/root:${pathOf2(ctx, parent2)}` } },
|
|
119660
120088
|
fileSystemInfo: { createdDateTime: iso7(item2.created_ms), lastModifiedDateTime: iso7(item2.modified_ms) },
|
|
119661
120089
|
...item2.description !== null && { description: item2.description },
|
|
119662
120090
|
...item2.kind === "file" ? { file: { mimeType: item2.mime_type, hashes: { quickXorHash: quickXorHash(item2.content ?? Buffer.alloc(0)) } } } : { folder: { childCount: childrenOf2(ctx, item2.id).length } },
|
|
@@ -119685,7 +120113,7 @@ function permissionJson(ctx, row, inheritedFrom) {
|
|
|
119685
120113
|
roles: roles2,
|
|
119686
120114
|
...row.kind === "link" ? { link: { type: row.link_type, scope: row.link_scope, webUrl: `https://${config8(ctx).tenant.domain.split(".")[0]}-my.sharepoint.com/:${kindCode}:/g/personal/${slug5(config8(ctx).me)}/${row.id.slice(-22)}?e=${row.id.slice(-6)}`, preventsDownload: false }, hasPassword: row.has_password === 1 } : { grantedTo: identity3(ctx, row.email), grantedToV2: identity3(ctx, row.email), invitation: { email: row.email, signInRequired: true } },
|
|
119687
120115
|
...row.expires_ms !== null && { expirationDateTime: iso7(row.expires_ms) },
|
|
119688
|
-
...inheritedFrom && { inheritedFrom: { driveId: config8(ctx).driveId, id: inheritedFrom.id, path: `/drive/root:${
|
|
120116
|
+
...inheritedFrom && { inheritedFrom: { driveId: config8(ctx).driveId, id: inheritedFrom.id, path: `/drive/root:${pathOf2(ctx, inheritedFrom)}` } }
|
|
119689
120117
|
};
|
|
119690
120118
|
}
|
|
119691
120119
|
var ITEM_PROPERTIES = /* @__PURE__ */ new Set(["@microsoft.graph.downloadUrl", "createdDateTime", "eTag", "id", "lastModifiedDateTime", "name", "webUrl", "cTag", "size", "createdBy", "lastModifiedBy", "parentReference", "fileSystemInfo", "description", "file", "folder", "root", "shared", "children", "image", "photo", "video", "audio", "package", "remoteItem", "searchResult", "specialFolder", "deleted", "malware", "publication", "sharepointIds", "listItem", "permissions", "thumbnails", "versions", "content", "webDavUrl"]);
|
|
@@ -120262,11 +120690,11 @@ async function handle17(c) {
|
|
|
120262
120690
|
function microsoftWordTwin() {
|
|
120263
120691
|
const app2 = new Hono3();
|
|
120264
120692
|
app2.all("*", handle17);
|
|
120265
|
-
return { name: "microsoft-word", basePath: "", app: app2, migrate:
|
|
120693
|
+
return { name: "microsoft-word", basePath: "", app: app2, migrate: migrate26, seed: seed26, credentials: credentials25, dumpState: dumpState25, actions: {}, checks: {}, coverage: microsoftWordCoverage };
|
|
120266
120694
|
}
|
|
120267
120695
|
|
|
120268
120696
|
// packages/server/src/twins/shopify/db.ts
|
|
120269
|
-
function
|
|
120697
|
+
function migrate27(db2) {
|
|
120270
120698
|
db2.exec(`
|
|
120271
120699
|
CREATE TABLE shopify_objects (gid TEXT PRIMARY KEY, kind TEXT NOT NULL, num INTEGER NOT NULL, parent TEXT, json TEXT NOT NULL);
|
|
120272
120700
|
CREATE INDEX shopify_objects_kind ON shopify_objects (kind, num);
|
|
@@ -120571,7 +120999,7 @@ function compare7(op, a, b) {
|
|
|
120571
120999
|
}
|
|
120572
121000
|
}
|
|
120573
121001
|
var wordsOf = (text21) => text21.toLowerCase().split(/[^\p{L}\p{N}*]+/u).filter(Boolean);
|
|
120574
|
-
function textMatch(values2, wanted,
|
|
121002
|
+
function textMatch(values2, wanted, contains3, words4 = false) {
|
|
120575
121003
|
const options3 = wanted.split(",").map((v) => v.trim().toLowerCase()).filter(Boolean);
|
|
120576
121004
|
return values2.some((raw3) => {
|
|
120577
121005
|
if (raw3 === null) return false;
|
|
@@ -120580,7 +121008,7 @@ function textMatch(values2, wanted, contains2, words4 = false) {
|
|
|
120580
121008
|
const have = wordsOf(v);
|
|
120581
121009
|
return options3.some((o) => wordsOf(o).every((w) => have.some((h) => w.endsWith("*") ? h.startsWith(w.slice(0, -1)) : h === w)));
|
|
120582
121010
|
}
|
|
120583
|
-
return options3.some((o) => o.endsWith("*") ?
|
|
121011
|
+
return options3.some((o) => o.endsWith("*") ? contains3 ? v.split(/[\s,/#@.-]+/).some((w) => w.startsWith(o.slice(0, -1))) || v.startsWith(o.slice(0, -1)) : v.startsWith(o.slice(0, -1)) : contains3 ? v.includes(o) : v === o);
|
|
120584
121012
|
});
|
|
120585
121013
|
}
|
|
120586
121014
|
function search7(items, query10, documented, fields11, nowMs) {
|
|
@@ -120642,7 +121070,7 @@ function decode3(cursor4) {
|
|
|
120642
121070
|
return null;
|
|
120643
121071
|
}
|
|
120644
121072
|
}
|
|
120645
|
-
function connection2(items, args, key3,
|
|
121073
|
+
function connection2(items, args, key3, shape4) {
|
|
120646
121074
|
const { first, last, after, before } = args;
|
|
120647
121075
|
if ((first === void 0 || first === null) && (last === void 0 || last === null)) throw new import_graphql3.GraphQLError("you must provide one of first or last", { extensions: { code: "BAD_REQUEST" } });
|
|
120648
121076
|
for (const [name5, n] of [["first", first], ["last", last]]) {
|
|
@@ -120666,16 +121094,16 @@ function connection2(items, args, key3, shape3) {
|
|
|
120666
121094
|
};
|
|
120667
121095
|
return {
|
|
120668
121096
|
get edges() {
|
|
120669
|
-
return page15.map((item2) => ({ cursor: cursor4(item2), node:
|
|
121097
|
+
return page15.map((item2) => ({ cursor: cursor4(item2), node: shape4(item2) }));
|
|
120670
121098
|
},
|
|
120671
121099
|
get nodes() {
|
|
120672
|
-
return page15.map(
|
|
121100
|
+
return page15.map(shape4);
|
|
120673
121101
|
},
|
|
120674
121102
|
pageInfo: { hasNextPage: end < ordered2.length, hasPreviousPage: start > 0, startCursor: page15.length ? cursor4(page15[0]) : null, endCursor: page15.length ? cursor4(page15[page15.length - 1]) : null }
|
|
120675
121103
|
};
|
|
120676
121104
|
}
|
|
120677
121105
|
var byNum = (d) => ({ id: numOf(d.gid) });
|
|
120678
|
-
var
|
|
121106
|
+
var pathOf3 = (path4) => path4 ? [...pathOf3(path4.prev), path4.key] : [];
|
|
120679
121107
|
var firstOf = (items, n) => typeof n === "number" ? items.slice(0, Math.max(0, n)) : items;
|
|
120680
121108
|
var currencyOf = (ctx) => all6(ctx, "Shop")[0].currency;
|
|
120681
121109
|
var bag = (ctx, c) => {
|
|
@@ -121014,7 +121442,7 @@ function customerShape(req, c) {
|
|
|
121014
121442
|
},
|
|
121015
121443
|
defaultAddress: addressShape(c.address),
|
|
121016
121444
|
addresses: ({ first }) => firstOf(c.address ? [addressShape(c.address)] : [], first),
|
|
121017
|
-
orders: (args, _req, info) => ordersConnection(req, orders(), args,
|
|
121445
|
+
orders: (args, _req, info) => ordersConnection(req, orders(), args, pathOf3(info.path))
|
|
121018
121446
|
};
|
|
121019
121447
|
}
|
|
121020
121448
|
function orderShape(req, o) {
|
|
@@ -121532,21 +121960,21 @@ var now6 = (req) => req.ctx.clock.nowMs();
|
|
|
121532
121960
|
var field2 = (...parts3) => parts3.map(String);
|
|
121533
121961
|
function queryRoot(req) {
|
|
121534
121962
|
const ctx = req.ctx;
|
|
121535
|
-
const one7 = (kind,
|
|
121963
|
+
const one7 = (kind, shape4) => ({ id: id12 }) => {
|
|
121536
121964
|
const d = loadKind(ctx, kind, checkId(id12));
|
|
121537
|
-
return d ?
|
|
121965
|
+
return d ? shape4(req, d) : null;
|
|
121538
121966
|
};
|
|
121539
121967
|
return {
|
|
121540
121968
|
shop: () => shopShape(req),
|
|
121541
|
-
orders: (args, _r, info) => ordersConnection(req, all6(ctx, "Order"), args,
|
|
121969
|
+
orders: (args, _r, info) => ordersConnection(req, all6(ctx, "Order"), args, pathOf3(info.path)),
|
|
121542
121970
|
order: one7("Order", orderShape),
|
|
121543
|
-
products: (args, _r, info) => productsConnection(req, args,
|
|
121971
|
+
products: (args, _r, info) => productsConnection(req, args, pathOf3(info.path)),
|
|
121544
121972
|
product: one7("Product", productShape),
|
|
121545
|
-
productVariants: (args, _r, info) => variantsConnection(req, args,
|
|
121973
|
+
productVariants: (args, _r, info) => variantsConnection(req, args, pathOf3(info.path)),
|
|
121546
121974
|
productVariant: one7("ProductVariant", variantShape),
|
|
121547
|
-
customers: (args, _r, info) => customersConnection(req, args,
|
|
121975
|
+
customers: (args, _r, info) => customersConnection(req, args, pathOf3(info.path)),
|
|
121548
121976
|
customer: one7("Customer", customerShape),
|
|
121549
|
-
locations: (args, _r, info) => locationsConnection(req, args,
|
|
121977
|
+
locations: (args, _r, info) => locationsConnection(req, args, pathOf3(info.path)),
|
|
121550
121978
|
// Without an id, Shopify returns the primary location.
|
|
121551
121979
|
location: ({ id: id12 }) => {
|
|
121552
121980
|
const d = id12 === void 0 || id12 === null ? all6(ctx, "Location")[0] : loadKind(ctx, "Location", checkId(id12));
|
|
@@ -121576,12 +122004,12 @@ function idempotency2(req, info, args) {
|
|
|
121576
122004
|
return { key: key3, fingerprint: `${name5}
|
|
121577
122005
|
${JSON.stringify(args)}` };
|
|
121578
122006
|
}
|
|
121579
|
-
function once(req, info, args, run3,
|
|
122007
|
+
function once(req, info, args, run3, shape4, mismatch) {
|
|
121580
122008
|
const idem = idempotency2(req, info, args);
|
|
121581
122009
|
if (!idem) return run3().payload;
|
|
121582
122010
|
const db2 = req.ctx.store.db;
|
|
121583
122011
|
const seen = db2.prepare("SELECT fingerprint, response FROM shopify_idempotency WHERE key = ?").get(idem.key);
|
|
121584
|
-
if (seen) return seen.fingerprint === idem.fingerprint && seen.response ?
|
|
122012
|
+
if (seen) return seen.fingerprint === idem.fingerprint && seen.response ? shape4(seen.response) : mismatch();
|
|
121585
122013
|
const result = run3();
|
|
121586
122014
|
if (result.made) db2.prepare("INSERT INTO shopify_idempotency (key, fingerprint, response) VALUES (?, ?, ?)").run(idem.key, idem.fingerprint, result.made);
|
|
121587
122015
|
return result.payload;
|
|
@@ -121938,14 +122366,14 @@ function inventoryAdjust(req, input2) {
|
|
|
121938
122366
|
changes.push({ item: item2.gid, location: location.gid, delta: c.delta, before: current, ledger: c.ledgerDocumentUri ?? null, on_hand: quantities(ctx, l).on_hand });
|
|
121939
122367
|
});
|
|
121940
122368
|
if (errors2.length) return fail6(errors2);
|
|
121941
|
-
const at2 = now6(req),
|
|
122369
|
+
const at2 = now6(req), recorded2 = [];
|
|
121942
122370
|
for (const c of changes) {
|
|
121943
122371
|
const column = input2.name;
|
|
121944
122372
|
ctx.store.db.prepare(`UPDATE shopify_inventory SET ${column} = ${column} + ?, updated_ms = ? WHERE item = ? AND location = ?`).run(c.delta, at2, c.item, c.location);
|
|
121945
|
-
|
|
121946
|
-
if (input2.name !== "incoming")
|
|
122373
|
+
recorded2.push({ name: input2.name, delta: c.delta, after: c.before + c.delta, item: c.item, location: c.location, ledger: c.ledger });
|
|
122374
|
+
if (input2.name !== "incoming") recorded2.push({ name: "on_hand", delta: c.delta, after: c.on_hand + c.delta, item: c.item, location: c.location, ledger: null });
|
|
121947
122375
|
}
|
|
121948
|
-
const group5 = save8(ctx, "InventoryAdjustmentGroup", { gid: gid("InventoryAdjustmentGroup", nextNum(ctx, "InventoryAdjustmentGroup")), reason: input2.reason, reference: input2.referenceDocumentUri ?? null, created_ms: at2, changes:
|
|
122376
|
+
const group5 = save8(ctx, "InventoryAdjustmentGroup", { gid: gid("InventoryAdjustmentGroup", nextNum(ctx, "InventoryAdjustmentGroup")), reason: input2.reason, reference: input2.referenceDocumentUri ?? null, created_ms: at2, changes: recorded2 });
|
|
121949
122377
|
return { made: group5.gid, payload: { inventoryAdjustmentGroup: adjustmentGroupShape(req, group5), userErrors: [] } };
|
|
121950
122378
|
}
|
|
121951
122379
|
function inventorySet(req, input2) {
|
|
@@ -121970,13 +122398,13 @@ function inventorySet(req, input2) {
|
|
|
121970
122398
|
sets.push({ item: item2.gid, location: location.gid, delta: q.quantity - current, available: have.available, on_hand: have.on_hand });
|
|
121971
122399
|
});
|
|
121972
122400
|
if (errors2.length) return fail6(errors2);
|
|
121973
|
-
const at2 = now6(req),
|
|
122401
|
+
const at2 = now6(req), recorded2 = [];
|
|
121974
122402
|
for (const s of sets) {
|
|
121975
122403
|
setAvailable(ctx, s.item, s.location, s.available + s.delta, at2);
|
|
121976
|
-
|
|
121977
|
-
|
|
122404
|
+
recorded2.push({ name: input2.name, delta: s.delta, after: (input2.name === "available" ? s.available : s.on_hand) + s.delta, item: s.item, location: s.location, ledger: null });
|
|
122405
|
+
recorded2.push({ name: input2.name === "available" ? "on_hand" : "available", delta: s.delta, after: (input2.name === "available" ? s.on_hand : s.available) + s.delta, item: s.item, location: s.location, ledger: null });
|
|
121978
122406
|
}
|
|
121979
|
-
const group5 = save8(ctx, "InventoryAdjustmentGroup", { gid: gid("InventoryAdjustmentGroup", nextNum(ctx, "InventoryAdjustmentGroup")), reason: input2.reason, reference: input2.referenceDocumentUri ?? null, created_ms: at2, changes:
|
|
122407
|
+
const group5 = save8(ctx, "InventoryAdjustmentGroup", { gid: gid("InventoryAdjustmentGroup", nextNum(ctx, "InventoryAdjustmentGroup")), reason: input2.reason, reference: input2.referenceDocumentUri ?? null, created_ms: at2, changes: recorded2 });
|
|
121980
122408
|
return { made: group5.gid, payload: { inventoryAdjustmentGroup: adjustmentGroupShape(req, group5), userErrors: [] } };
|
|
121981
122409
|
}
|
|
121982
122410
|
function customerWrite(req, input2, create2) {
|
|
@@ -122568,7 +122996,7 @@ function shopifyTwin() {
|
|
|
122568
122996
|
const app2 = new Hono3();
|
|
122569
122997
|
app2.post("/admin/api/:version/graphql.json", handleGraphql2);
|
|
122570
122998
|
app2.all("*", unknownRoute12);
|
|
122571
|
-
return { name: "shopify", basePath: "", app: app2, migrate:
|
|
122999
|
+
return { name: "shopify", basePath: "", app: app2, migrate: migrate27, seed: seed27, credentials: credentials26, actions: {}, checks: {}, dumpState: dumpState26, coverage: shopifyCoverage };
|
|
122572
123000
|
}
|
|
122573
123001
|
|
|
122574
123002
|
// packages/server/src/twins/lob/db.ts
|
|
@@ -122874,7 +123302,7 @@ function assetUrl(ctx, kind, id12) {
|
|
|
122874
123302
|
}
|
|
122875
123303
|
|
|
122876
123304
|
// packages/server/src/twins/lob/db.ts
|
|
122877
|
-
var
|
|
123305
|
+
var SCHEMA17 = `
|
|
122878
123306
|
CREATE TABLE lob_directory (id INTEGER PRIMARY KEY, primary_line TEXT NOT NULL, unit TEXT NOT NULL, city TEXT NOT NULL, state TEXT NOT NULL, zip5 TEXT NOT NULL, zip4 TEXT NOT NULL, vacant INTEGER NOT NULL, type TEXT NOT NULL, county TEXT NOT NULL);
|
|
122879
123307
|
CREATE INDEX lob_directory_street ON lob_directory (primary_line, zip5);
|
|
122880
123308
|
CREATE TABLE lob_addresses (
|
|
@@ -122895,8 +123323,8 @@ CREATE TABLE lob_mail (
|
|
|
122895
123323
|
CREATE TABLE lob_files (id TEXT PRIMARY KEY, name TEXT NOT NULL, type TEXT NOT NULL, bytes BLOB NOT NULL);
|
|
122896
123324
|
CREATE TABLE lob_idempotency (kind TEXT NOT NULL, key TEXT NOT NULL, id TEXT NOT NULL, created_ms INTEGER NOT NULL, PRIMARY KEY (kind, key));
|
|
122897
123325
|
`;
|
|
122898
|
-
function
|
|
122899
|
-
db2.exec(
|
|
123326
|
+
function migrate28(db2) {
|
|
123327
|
+
db2.exec(SCHEMA17);
|
|
122900
123328
|
}
|
|
122901
123329
|
var LENGTH = { adr: 16, ltr: 16, psc: 16, chk: 16, bank: 15, tmpl: 15, vrsn: 15, file: 16 };
|
|
122902
123330
|
var seededId4 = (prefix2, key3) => `${prefix2}_${createHash40("sha256").update(`lob:${prefix2}:${key3}`).digest("hex").slice(0, LENGTH[prefix2])}`;
|
|
@@ -123985,11 +124413,11 @@ async function handle18(c) {
|
|
|
123985
124413
|
function lobTwin() {
|
|
123986
124414
|
const app2 = new Hono3();
|
|
123987
124415
|
app2.all("*", handle18);
|
|
123988
|
-
return { name: "lob", basePath: "/v1", app: app2, migrate:
|
|
124416
|
+
return { name: "lob", basePath: "/v1", app: app2, migrate: migrate28, seed: seed28, credentials: credentials27, dumpState: dumpState27, actions: {}, checks: {}, coverage: lobCoverage };
|
|
123989
124417
|
}
|
|
123990
124418
|
|
|
123991
124419
|
// packages/server/src/twins/paypal/db.ts
|
|
123992
|
-
function
|
|
124420
|
+
function migrate29(db2) {
|
|
123993
124421
|
db2.exec(`
|
|
123994
124422
|
CREATE TABLE paypal_objects (id TEXT PRIMARY KEY, kind TEXT NOT NULL, created_ms INTEGER NOT NULL, json TEXT NOT NULL);
|
|
123995
124423
|
CREATE INDEX paypal_objects_kind ON paypal_objects (kind, created_ms);
|
|
@@ -124534,8 +124962,8 @@ var orderRoutes = [
|
|
|
124534
124962
|
description: u.description
|
|
124535
124963
|
});
|
|
124536
124964
|
save9(r.ctx, "authorization", touch3(r, a));
|
|
124537
|
-
const
|
|
124538
|
-
return [201, r.prefer === "representation" ?
|
|
124965
|
+
const shape4 = captureShape(r, c);
|
|
124966
|
+
return [201, r.prefer === "representation" ? shape4 : { id: shape4.id, status: shape4.status, links: shape4.links }];
|
|
124539
124967
|
}
|
|
124540
124968
|
},
|
|
124541
124969
|
{
|
|
@@ -124570,8 +124998,8 @@ var orderRoutes = [
|
|
|
124570
124998
|
if (want > left) refused("REFUND_AMOUNT_EXCEEDED", "The refund amount must be less than or equal to the capture amount that has not yet been refunded.", "/amount/value");
|
|
124571
124999
|
const x = refund2(r.ctx, c, { cents: want, atMs: r.ctx.clock.nowMs(), note: b.note_to_payer ?? null, invoice_id: b.invoice_id ?? null, custom_id: b.custom_id ?? null });
|
|
124572
125000
|
save9(r.ctx, "capture", { ...c, update_ms: r.ctx.clock.nowMs() });
|
|
124573
|
-
const
|
|
124574
|
-
return [201, r.prefer === "representation" ?
|
|
125001
|
+
const shape4 = refundShape2(r, x);
|
|
125002
|
+
return [201, r.prefer === "representation" ? shape4 : { id: shape4.id, status: shape4.status, links: shape4.links }];
|
|
124575
125003
|
}
|
|
124576
125004
|
},
|
|
124577
125005
|
{ method: "GET", path: "/v2/payments/refunds/:id", coverage: { status: "supported" }, run: (r) => refundShape2(r, load4(r.ctx, "refund", r.param("id")) ?? notFound13(r.param("id"))) }
|
|
@@ -125311,11 +125739,11 @@ function paypalTwin() {
|
|
|
125311
125739
|
const rank = (path4) => path4.split("/").filter((s) => s.startsWith(":")).length;
|
|
125312
125740
|
for (const route11 of [...paypalRoutes].sort((a, b) => rank(a.path) - rank(b.path))) app2.on(route11.method, route11.path, handle19(route11));
|
|
125313
125741
|
app2.all("*", unknownRoute13);
|
|
125314
|
-
return { name: "paypal", basePath: "", app: app2, migrate:
|
|
125742
|
+
return { name: "paypal", basePath: "", app: app2, migrate: migrate29, seed: seed29, credentials: credentials28, actions: {}, checks: {}, dumpState: dumpState28, coverage: paypalCoverage };
|
|
125315
125743
|
}
|
|
125316
125744
|
|
|
125317
125745
|
// packages/server/src/twins/jira/db.ts
|
|
125318
|
-
function
|
|
125746
|
+
function migrate30(db2) {
|
|
125319
125747
|
db2.exec(`
|
|
125320
125748
|
CREATE TABLE jira_site (id INTEGER PRIMARY KEY CHECK (id = 1), json TEXT NOT NULL);
|
|
125321
125749
|
CREATE TABLE jira_users (account_id TEXT PRIMARY KEY, seq INTEGER NOT NULL, json TEXT NOT NULL);
|
|
@@ -127436,7 +127864,7 @@ function jiraTwin() {
|
|
|
127436
127864
|
else for (const api3 of ["3", "2"]) app2.on(route11.method, `/rest/api/${api3}${route11.path}`, handle20(route11, api3));
|
|
127437
127865
|
}
|
|
127438
127866
|
app2.all("*", unknownRoute14);
|
|
127439
|
-
return { name: "jira", basePath: "", app: app2, migrate:
|
|
127867
|
+
return { name: "jira", basePath: "", app: app2, migrate: migrate30, seed: seed30, credentials: credentials29, actions: {}, checks: {}, dumpState: dumpState29, coverage: jiraCoverage };
|
|
127440
127868
|
}
|
|
127441
127869
|
|
|
127442
127870
|
// packages/server/src/twins/kalshi/index.ts
|
|
@@ -127484,7 +127912,7 @@ function rsaPrivateKey(secrets) {
|
|
|
127484
127912
|
}
|
|
127485
127913
|
|
|
127486
127914
|
// packages/server/src/twins/kalshi/db.ts
|
|
127487
|
-
var
|
|
127915
|
+
var SCHEMA18 = `
|
|
127488
127916
|
CREATE TABLE kx_series (ticker TEXT PRIMARY KEY, title TEXT NOT NULL, category TEXT NOT NULL, frequency TEXT NOT NULL, tags TEXT NOT NULL, sources TEXT NOT NULL, fee_type TEXT NOT NULL, fee_multiplier REAL NOT NULL, position INTEGER NOT NULL);
|
|
127489
127917
|
CREATE TABLE kx_events (ticker TEXT PRIMARY KEY, series TEXT NOT NULL, title TEXT NOT NULL, sub_title TEXT NOT NULL, mutually_exclusive INTEGER NOT NULL, strike_ms INTEGER, position INTEGER NOT NULL);
|
|
127490
127918
|
CREATE TABLE kx_markets (
|
|
@@ -127506,8 +127934,8 @@ CREATE TABLE kx_fills (
|
|
|
127506
127934
|
);
|
|
127507
127935
|
CREATE TABLE kx_deposits (id INTEGER PRIMARY KEY, amount INTEGER NOT NULL, at_ms INTEGER NOT NULL);
|
|
127508
127936
|
`;
|
|
127509
|
-
function
|
|
127510
|
-
db2.exec(
|
|
127937
|
+
function migrate31(db2) {
|
|
127938
|
+
db2.exec(SCHEMA18);
|
|
127511
127939
|
}
|
|
127512
127940
|
var ONE = 1e4;
|
|
127513
127941
|
var dollars2 = (price3) => (price3 / ONE).toFixed(4);
|
|
@@ -128534,12 +128962,12 @@ async function handle21(c) {
|
|
|
128534
128962
|
function kalshiTwin() {
|
|
128535
128963
|
const app2 = new Hono3();
|
|
128536
128964
|
app2.all("*", handle21);
|
|
128537
|
-
return { name: "kalshi", basePath: "/trade-api/v2", app: app2, migrate:
|
|
128965
|
+
return { name: "kalshi", basePath: "/trade-api/v2", app: app2, migrate: migrate31, seed: seed31, credentials: credentials30, dumpState: dumpState30, actions: {}, checks: {}, coverage: kalshiCoverage };
|
|
128538
128966
|
}
|
|
128539
128967
|
|
|
128540
128968
|
// packages/server/src/twins/intercom/request.ts
|
|
128541
128969
|
import { createHash as createHash43 } from "node:crypto";
|
|
128542
|
-
function
|
|
128970
|
+
function migrate32(db2) {
|
|
128543
128971
|
db2.exec(`
|
|
128544
128972
|
CREATE TABLE intercom_objects (kind TEXT NOT NULL, id TEXT NOT NULL, seq INTEGER NOT NULL, json TEXT NOT NULL, PRIMARY KEY (kind, id));
|
|
128545
128973
|
CREATE INDEX intercom_objects_seq ON intercom_objects (kind, seq);
|
|
@@ -129754,11 +130182,11 @@ function intercomTwin() {
|
|
|
129754
130182
|
const rank = (path4) => path4.split("/").filter((s) => s.startsWith(":")).length;
|
|
129755
130183
|
for (const route11 of [...intercomRoutes].sort((a, b) => rank(a.path) - rank(b.path))) app2.on(route11.method, route11.path, handle22(route11));
|
|
129756
130184
|
app2.all("*", unknownRoute15);
|
|
129757
|
-
return { name: "intercom", basePath: "", app: app2, migrate:
|
|
130185
|
+
return { name: "intercom", basePath: "", app: app2, migrate: migrate32, seed: seed32, credentials: credentials31, actions: {}, checks: {}, dumpState: dumpState31, coverage: intercomCoverage };
|
|
129758
130186
|
}
|
|
129759
130187
|
|
|
129760
130188
|
// packages/server/src/twins/zendesk/db.ts
|
|
129761
|
-
var
|
|
130189
|
+
var SCHEMA19 = `
|
|
129762
130190
|
CREATE TABLE zd_users (
|
|
129763
130191
|
id INTEGER PRIMARY KEY, email TEXT UNIQUE, name TEXT NOT NULL, role TEXT NOT NULL, organization_id INTEGER, phone TEXT, time_zone TEXT NOT NULL, tags TEXT NOT NULL,
|
|
129764
130192
|
suspended INTEGER NOT NULL, external_id TEXT, default_group_id INTEGER, created_ms INTEGER NOT NULL, updated_ms INTEGER NOT NULL
|
|
@@ -129775,8 +130203,8 @@ CREATE TABLE zd_audits (id INTEGER PRIMARY KEY, ticket_id INTEGER NOT NULL, auth
|
|
|
129775
130203
|
CREATE TABLE zd_macros (id INTEGER PRIMARY KEY, title TEXT NOT NULL, description TEXT, active INTEGER NOT NULL, actions TEXT NOT NULL, position INTEGER NOT NULL, created_ms INTEGER NOT NULL);
|
|
129776
130204
|
CREATE TABLE zd_views (id INTEGER PRIMARY KEY, title TEXT NOT NULL, statuses TEXT NOT NULL, assignee TEXT NOT NULL, group_id INTEGER, sort_by TEXT NOT NULL, sort_order TEXT NOT NULL, active INTEGER NOT NULL, position INTEGER NOT NULL, created_ms INTEGER NOT NULL);
|
|
129777
130205
|
`;
|
|
129778
|
-
function
|
|
129779
|
-
db2.exec(
|
|
130206
|
+
function migrate33(db2) {
|
|
130207
|
+
db2.exec(SCHEMA19);
|
|
129780
130208
|
}
|
|
129781
130209
|
var BASES2 = { user: 21457810001, organization: 360041201001, group: 360000118001, ticket: 4101, comment: 31870100001, audit: 31870200001, macro: 360101000001, view: 360102000001 };
|
|
129782
130210
|
function nextId6(ctx, kind) {
|
|
@@ -129962,20 +130390,20 @@ var ordered = (order4, actual, term) => {
|
|
|
129962
130390
|
if (b < 0 || a < 0) return term.op === ":" && term.value.toLowerCase() === "none" && actual === null;
|
|
129963
130391
|
return term.op === ":" ? a === b : term.op === "<" ? a < b : term.op === ">" ? a > b : term.op === "<=" ? a <= b : a >= b;
|
|
129964
130392
|
};
|
|
129965
|
-
var
|
|
130393
|
+
var contains2 = (haystack, needle) => haystack.toLowerCase().includes(needle.toLowerCase());
|
|
129966
130394
|
var person3 = (world4, id12, value4) => {
|
|
129967
130395
|
if (value4 === "none") return id12 === null;
|
|
129968
130396
|
if (id12 === null) return false;
|
|
129969
130397
|
const user8 = world4.users.get(id12);
|
|
129970
|
-
return value4 === "me" ? id12 === world4.me.id : !!user8 && (String(user8.id) === value4 || user8.email === value4.toLowerCase() ||
|
|
130398
|
+
return value4 === "me" ? id12 === world4.me.id : !!user8 && (String(user8.id) === value4 || user8.email === value4.toLowerCase() || contains2(user8.name, value4));
|
|
129971
130399
|
};
|
|
129972
|
-
var named2 = (map2, id12, value4) => value4 === "none" ? id12 === null : id12 !== null && (String(id12) === value4 ||
|
|
130400
|
+
var named2 = (map2, id12, value4) => value4 === "none" ? id12 === null : id12 !== null && (String(id12) === value4 || contains2(map2.get(id12)?.name ?? "", value4));
|
|
129973
130401
|
function ticketMatches(world4, ticket2, term) {
|
|
129974
130402
|
const tags4 = tagsOf(ticket2.tags);
|
|
129975
130403
|
switch (term.key) {
|
|
129976
130404
|
case null: {
|
|
129977
130405
|
const text21 = [ticket2.subject, ticket2.description, ...commentsOf2(world4.ctx, ticket2.id).map((comment8) => comment8.body), ...tags4].join("\n");
|
|
129978
|
-
return
|
|
130406
|
+
return contains2(text21, term.value);
|
|
129979
130407
|
}
|
|
129980
130408
|
case "status":
|
|
129981
130409
|
return ordered(STATUSES2, ticket2.status, term);
|
|
@@ -129997,11 +130425,11 @@ function ticketMatches(world4, ticket2, term) {
|
|
|
129997
130425
|
case "tag":
|
|
129998
130426
|
return tags4.includes(term.value.toLowerCase());
|
|
129999
130427
|
case "subject":
|
|
130000
|
-
return
|
|
130428
|
+
return contains2(ticket2.subject, term.value);
|
|
130001
130429
|
case "description":
|
|
130002
|
-
return
|
|
130430
|
+
return contains2(ticket2.description, term.value);
|
|
130003
130431
|
case "comment":
|
|
130004
|
-
return commentsOf2(world4.ctx, ticket2.id).some((comment8) =>
|
|
130432
|
+
return commentsOf2(world4.ctx, ticket2.id).some((comment8) => contains2(comment8.body, term.value));
|
|
130005
130433
|
case "via":
|
|
130006
130434
|
return ticket2.via === term.value.toLowerCase();
|
|
130007
130435
|
case "external_id":
|
|
@@ -130020,10 +130448,10 @@ function ticketMatches(world4, ticket2, term) {
|
|
|
130020
130448
|
function userMatches2(world4, user8, term) {
|
|
130021
130449
|
switch (term.key) {
|
|
130022
130450
|
case null:
|
|
130023
|
-
return
|
|
130451
|
+
return contains2(`${user8.name}
|
|
130024
130452
|
${user8.email ?? ""}`, term.value);
|
|
130025
130453
|
case "name":
|
|
130026
|
-
return
|
|
130454
|
+
return contains2(user8.name, term.value);
|
|
130027
130455
|
case "email":
|
|
130028
130456
|
return (user8.email ?? "") === term.value.toLowerCase() || term.value.startsWith("*") && (user8.email ?? "").endsWith(term.value.slice(1).toLowerCase());
|
|
130029
130457
|
case "role":
|
|
@@ -130047,10 +130475,10 @@ ${user8.email ?? ""}`, term.value);
|
|
|
130047
130475
|
function organizationMatches(world4, organization4, term) {
|
|
130048
130476
|
switch (term.key) {
|
|
130049
130477
|
case null:
|
|
130050
|
-
return
|
|
130478
|
+
return contains2(`${organization4.name}
|
|
130051
130479
|
${JSON.parse(organization4.domains).join(" ")}`, term.value);
|
|
130052
130480
|
case "name":
|
|
130053
|
-
return
|
|
130481
|
+
return contains2(organization4.name, term.value);
|
|
130054
130482
|
case "tags":
|
|
130055
130483
|
case "tag":
|
|
130056
130484
|
return tagsOf(organization4.tags).includes(term.value.toLowerCase());
|
|
@@ -130062,7 +130490,7 @@ ${JSON.parse(organization4.domains).join(" ")}`, term.value);
|
|
|
130062
130490
|
}
|
|
130063
130491
|
}
|
|
130064
130492
|
function groupMatches(world4, group5, term) {
|
|
130065
|
-
if (term.key === null || term.key === "name") return
|
|
130493
|
+
if (term.key === null || term.key === "name") return contains2(group5.name, term.value);
|
|
130066
130494
|
return world4.unsupported(`the group search property ${term.key}`);
|
|
130067
130495
|
}
|
|
130068
130496
|
|
|
@@ -130886,11 +131314,11 @@ async function handle23(c) {
|
|
|
130886
131314
|
function zendeskTwin() {
|
|
130887
131315
|
const app2 = new Hono3();
|
|
130888
131316
|
app2.all("*", handle23);
|
|
130889
|
-
return { name: "zendesk", basePath: "/api/v2", app: app2, migrate:
|
|
131317
|
+
return { name: "zendesk", basePath: "/api/v2", app: app2, migrate: migrate33, seed: seed33, credentials: credentials32, dumpState: dumpState32, actions: {}, checks: {}, coverage: zendeskCoverage };
|
|
130890
131318
|
}
|
|
130891
131319
|
|
|
130892
131320
|
// packages/server/src/twins/google-calendar/request.ts
|
|
130893
|
-
function
|
|
131321
|
+
function migrate34(db2) {
|
|
130894
131322
|
db2.exec(`
|
|
130895
131323
|
CREATE TABLE gcal_owner (id INTEGER PRIMARY KEY CHECK (id = 1), json TEXT NOT NULL);
|
|
130896
131324
|
CREATE TABLE gcal_calendars (id TEXT PRIMARY KEY, seq INTEGER NOT NULL, json TEXT NOT NULL);
|
|
@@ -131489,12 +131917,12 @@ function listEvents3(r, cal, only4) {
|
|
|
131489
131917
|
defaultReminders: writable2(cal) ? [{ method: "popup", minutes: 10 }] : [],
|
|
131490
131918
|
...p2.next && { nextPageToken: p2.next },
|
|
131491
131919
|
items: p2.slice.map(({ e, at: at2 }) => {
|
|
131492
|
-
const
|
|
131493
|
-
if (maxAttendees !== null &&
|
|
131494
|
-
|
|
131495
|
-
|
|
131920
|
+
const shape4 = eventShape2(r, e, tz, at2, limited);
|
|
131921
|
+
if (maxAttendees !== null && shape4.attendees?.length > maxAttendees) {
|
|
131922
|
+
shape4.attendees = shape4.attendees.filter((a) => a.self).slice(0, 1);
|
|
131923
|
+
shape4.attendeesOmitted = true;
|
|
131496
131924
|
}
|
|
131497
|
-
return
|
|
131925
|
+
return shape4;
|
|
131498
131926
|
})
|
|
131499
131927
|
};
|
|
131500
131928
|
}
|
|
@@ -131910,12 +132338,12 @@ function googleCalendarTwin() {
|
|
|
131910
132338
|
const rank = (path4) => path4.split("/").filter((s) => s.startsWith(":")).length;
|
|
131911
132339
|
for (const route11 of [...calendarRoutes].sort((a, b) => rank(a.path) - rank(b.path))) app2.on(route11.method, route11.path, handle24(route11));
|
|
131912
132340
|
app2.all("*", unknownRoute16);
|
|
131913
|
-
return { name: "google-calendar", basePath: "", unprefixedPaths: /^\/calendar\/v3\//, app: app2, migrate:
|
|
132341
|
+
return { name: "google-calendar", basePath: "", unprefixedPaths: /^\/calendar\/v3\//, app: app2, migrate: migrate34, seed: seed34, credentials: credentials33, actions: {}, checks: {}, dumpState: dumpState33, coverage: googleCalendarCoverage };
|
|
131914
132342
|
}
|
|
131915
132343
|
|
|
131916
132344
|
// packages/server/src/twins/twilio/db.ts
|
|
131917
132345
|
import { createHash as createHash45 } from "node:crypto";
|
|
131918
|
-
var
|
|
132346
|
+
var SCHEMA20 = `
|
|
131919
132347
|
CREATE TABLE tw_numbers (sid TEXT PRIMARY KEY, phone_number TEXT NOT NULL UNIQUE, friendly_name TEXT NOT NULL, sms INTEGER NOT NULL, voice INTEGER NOT NULL, created_ms INTEGER NOT NULL);
|
|
131920
132348
|
CREATE TABLE tw_directory (phone_number TEXT PRIMARY KEY, type TEXT NOT NULL, carrier TEXT NOT NULL, caller_name TEXT, reachable INTEGER NOT NULL, opted_out INTEGER NOT NULL);
|
|
131921
132349
|
CREATE TABLE tw_messages (
|
|
@@ -131932,8 +132360,8 @@ CREATE TABLE tw_verifications (
|
|
|
131932
132360
|
created_ms INTEGER NOT NULL, updated_ms INTEGER NOT NULL
|
|
131933
132361
|
);
|
|
131934
132362
|
`;
|
|
131935
|
-
function
|
|
131936
|
-
db2.exec(
|
|
132363
|
+
function migrate35(db2) {
|
|
132364
|
+
db2.exec(SCHEMA20);
|
|
131937
132365
|
}
|
|
131938
132366
|
var seededSid = (prefix2, key3) => `${prefix2}${createHash45("sha256").update(`twilio:${prefix2}:${key3}`).digest("hex").slice(0, 32)}`;
|
|
131939
132367
|
var newSid = (ctx, prefix2) => `${prefix2}${ctx.ids.hex(32)}`;
|
|
@@ -132592,11 +133020,11 @@ async function handle25(c) {
|
|
|
132592
133020
|
function twilioTwin() {
|
|
132593
133021
|
const app2 = new Hono3();
|
|
132594
133022
|
app2.all("*", handle25);
|
|
132595
|
-
return { name: "twilio", basePath: "", app: app2, migrate:
|
|
133023
|
+
return { name: "twilio", basePath: "", app: app2, migrate: migrate35, seed: seed35, credentials: credentials34, dumpState: dumpState34, actions: {}, checks: {}, coverage: twilioCoverage };
|
|
132596
133024
|
}
|
|
132597
133025
|
|
|
132598
133026
|
// packages/server/src/twins/asana/db.ts
|
|
132599
|
-
var
|
|
133027
|
+
var SCHEMA21 = `
|
|
132600
133028
|
CREATE TABLE as_users (gid TEXT PRIMARY KEY, email TEXT NOT NULL UNIQUE, name TEXT NOT NULL);
|
|
132601
133029
|
CREATE TABLE as_projects (gid TEXT PRIMARY KEY, name TEXT NOT NULL, owner TEXT, notes TEXT NOT NULL, color TEXT, archived INTEGER NOT NULL, due_on TEXT, created_ms INTEGER NOT NULL, modified_ms INTEGER NOT NULL);
|
|
132602
133030
|
CREATE TABLE as_project_members (project TEXT NOT NULL, user TEXT NOT NULL, PRIMARY KEY (project, user));
|
|
@@ -132609,8 +133037,8 @@ CREATE TABLE as_memberships (task TEXT NOT NULL, project TEXT NOT NULL, section
|
|
|
132609
133037
|
CREATE TABLE as_followers (task TEXT NOT NULL, user TEXT NOT NULL, PRIMARY KEY (task, user));
|
|
132610
133038
|
CREATE TABLE as_stories (gid TEXT PRIMARY KEY, task TEXT NOT NULL, created_by TEXT, created_ms INTEGER NOT NULL, type TEXT NOT NULL, subtype TEXT NOT NULL, text TEXT NOT NULL);
|
|
132611
133039
|
`;
|
|
132612
|
-
function
|
|
132613
|
-
db2.exec(
|
|
133040
|
+
function migrate36(db2) {
|
|
133041
|
+
db2.exec(SCHEMA21);
|
|
132614
133042
|
}
|
|
132615
133043
|
var BASES3 = { workspace: 1200000000000001, user: 1201000000000001, project: 1205000000000001, section: 1206000000000001, task: 1208000000000001, story: 1210000000000001 };
|
|
132616
133044
|
function nextGid(ctx, kind) {
|
|
@@ -132908,22 +133336,22 @@ function treeOf(fields11) {
|
|
|
132908
133336
|
}
|
|
132909
133337
|
return root2;
|
|
132910
133338
|
}
|
|
132911
|
-
function
|
|
132912
|
-
if (Array.isArray(value4)) return value4.map((item2) =>
|
|
133339
|
+
function shape3(ctx, value4, tree) {
|
|
133340
|
+
if (Array.isArray(value4)) return value4.map((item2) => shape3(ctx, item2, tree));
|
|
132913
133341
|
if (value4 === null || typeof value4 !== "object") return value4;
|
|
132914
133342
|
let record8 = value4;
|
|
132915
133343
|
if (record8.resource_type && record8.gid && [...tree.keys()].some((field3) => !(field3 in record8))) record8 = expand2(ctx, record8);
|
|
132916
133344
|
const out = "gid" in record8 ? { gid: record8.gid } : {};
|
|
132917
|
-
for (const [field3, child2] of tree) if (field3 in record8) out[field3] = child2.size ?
|
|
133345
|
+
for (const [field3, child2] of tree) if (field3 in record8) out[field3] = child2.size ? shape3(ctx, record8[field3], child2) : record8[field3];
|
|
132918
133346
|
return out;
|
|
132919
133347
|
}
|
|
132920
133348
|
function one5(call2, full2) {
|
|
132921
133349
|
const tree = treeOf(call2.url.searchParams.get("opt_fields"));
|
|
132922
|
-
return json26({ data: tree ?
|
|
133350
|
+
return json26({ data: tree ? shape3(call2.ctx, full2, tree) : full2 });
|
|
132923
133351
|
}
|
|
132924
133352
|
function list13(call2, items, full2, compact2) {
|
|
132925
133353
|
const params9 = call2.url.searchParams, tree = treeOf(params9.get("opt_fields"));
|
|
132926
|
-
const render = (item2) => tree ?
|
|
133354
|
+
const render = (item2) => tree ? shape3(call2.ctx, full2(item2), tree) : compact2(item2);
|
|
132927
133355
|
if (params9.get("limit") === null) return json26({ data: items.map(render) });
|
|
132928
133356
|
const limit = Number(params9.get("limit")), offset16 = params9.get("offset");
|
|
132929
133357
|
if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw bad("limit: Value must be between 1 and 100");
|
|
@@ -133285,7 +133713,7 @@ function searchTasks(call2) {
|
|
|
133285
133713
|
return (x < y ? -1 : x > y ? 1 : a.gid < b.gid ? -1 : 1) * (ascending ? 1 : -1);
|
|
133286
133714
|
});
|
|
133287
133715
|
const tree = treeOf(params9.get("opt_fields"));
|
|
133288
|
-
return json26({ data: tasks.slice(0, limit).map((task2) => tree ?
|
|
133716
|
+
return json26({ data: tasks.slice(0, limit).map((task2) => tree ? shape3(ctx, taskFull(ctx, task2), tree) : taskCompact(task2)) });
|
|
133289
133717
|
}
|
|
133290
133718
|
var route8 = (method2, path4, write4, handle30, notes6) => ({ method: method2, path: path4, write: write4, handle: handle30, ...notes6 && { notes: notes6 }, pattern: new RegExp(`^${path4.replace(/\{[^}]+\}/g, "([^/]+)")}$`) });
|
|
133291
133719
|
var API = "/api/1.0";
|
|
@@ -133409,11 +133837,11 @@ async function handle26(c) {
|
|
|
133409
133837
|
function asanaTwin() {
|
|
133410
133838
|
const app2 = new Hono3();
|
|
133411
133839
|
app2.all("*", handle26);
|
|
133412
|
-
return { name: "asana", basePath: "/api/1.0", app: app2, migrate:
|
|
133840
|
+
return { name: "asana", basePath: "/api/1.0", app: app2, migrate: migrate36, seed: seed36, credentials: credentials35, dumpState: dumpState35, actions: {}, checks: {}, coverage: asanaCoverage };
|
|
133413
133841
|
}
|
|
133414
133842
|
|
|
133415
133843
|
// packages/server/src/twins/discord/db.ts
|
|
133416
|
-
var
|
|
133844
|
+
var SCHEMA22 = `
|
|
133417
133845
|
CREATE TABLE dc_users (id TEXT PRIMARY KEY, username TEXT NOT NULL UNIQUE, global_name TEXT, bot INTEGER NOT NULL);
|
|
133418
133846
|
CREATE TABLE dc_roles (id TEXT PRIMARY KEY, name TEXT NOT NULL, permissions TEXT NOT NULL, color INTEGER NOT NULL, hoist INTEGER NOT NULL, mentionable INTEGER NOT NULL, managed INTEGER NOT NULL, position INTEGER NOT NULL);
|
|
133419
133847
|
CREATE TABLE dc_members (user_id TEXT PRIMARY KEY, nick TEXT, roles TEXT NOT NULL, joined_ms INTEGER NOT NULL);
|
|
@@ -133427,8 +133855,8 @@ CREATE TABLE dc_messages (
|
|
|
133427
133855
|
);
|
|
133428
133856
|
CREATE TABLE dc_reactions (message_id TEXT NOT NULL, emoji TEXT NOT NULL, user_id TEXT NOT NULL, created_ms INTEGER NOT NULL, PRIMARY KEY (message_id, emoji, user_id));
|
|
133429
133857
|
`;
|
|
133430
|
-
function
|
|
133431
|
-
db2.exec(
|
|
133858
|
+
function migrate37(db2) {
|
|
133859
|
+
db2.exec(SCHEMA22);
|
|
133432
133860
|
}
|
|
133433
133861
|
var TEXT3 = 0;
|
|
133434
133862
|
var DM = 1;
|
|
@@ -134069,11 +134497,11 @@ async function handle27(c) {
|
|
|
134069
134497
|
function discordTwin() {
|
|
134070
134498
|
const app2 = new Hono3();
|
|
134071
134499
|
app2.all("*", handle27);
|
|
134072
|
-
return { name: "discord", basePath: "/api/v10", app: app2, migrate:
|
|
134500
|
+
return { name: "discord", basePath: "/api/v10", app: app2, migrate: migrate37, seed: seed37, credentials: credentials36, dumpState: dumpState36, actions: {}, checks: {}, coverage: discordCoverage };
|
|
134073
134501
|
}
|
|
134074
134502
|
|
|
134075
134503
|
// packages/server/src/twins/sentry/db.ts
|
|
134076
|
-
function
|
|
134504
|
+
function migrate38(db2) {
|
|
134077
134505
|
db2.exec(`
|
|
134078
134506
|
CREATE TABLE sentry_org (id INTEGER PRIMARY KEY CHECK (id = 1), json TEXT NOT NULL);
|
|
134079
134507
|
CREATE TABLE sentry_members (id TEXT PRIMARY KEY, seq INTEGER NOT NULL, json TEXT NOT NULL);
|
|
@@ -135020,8 +135448,8 @@ function apply(ctx, i, by2, c, ms) {
|
|
|
135020
135448
|
const same2 = c.assign?.type === i.assignee?.type && c.assign?.id === i.assignee?.id;
|
|
135021
135449
|
if (!same2) {
|
|
135022
135450
|
i.assignee = c.assign;
|
|
135023
|
-
const
|
|
135024
|
-
if (
|
|
135451
|
+
const shape4 = actorShape(ctx, c.assign);
|
|
135452
|
+
if (shape4) activity(ctx, i, "assigned", by2, { assignee: shape4.id, assigneeEmail: shape4.type === "user" ? shape4.email : void 0, assigneeName: shape4.name, assigneeType: shape4.type }, ms);
|
|
135025
135453
|
else activity(ctx, i, "unassigned", by2, {}, ms);
|
|
135026
135454
|
}
|
|
135027
135455
|
delta.assignedTo = actorShape(ctx, i.assignee);
|
|
@@ -136133,11 +136561,11 @@ function sentryTwin() {
|
|
|
136133
136561
|
if (route11.path.startsWith(ISSUE)) app2.on(route11.method, `/api/0/issues/:issue${route11.path.slice(ISSUE.length)}`, handle28(route11));
|
|
136134
136562
|
}
|
|
136135
136563
|
app2.all("*", unknownRoute17);
|
|
136136
|
-
return { name: "sentry", basePath: "", app: app2, migrate:
|
|
136564
|
+
return { name: "sentry", basePath: "", app: app2, migrate: migrate38, seed: seed38, credentials: credentials37, actions: { capture: capture2 }, checks: {}, dumpState: dumpState37, coverage: sentryCoverage };
|
|
136137
136565
|
}
|
|
136138
136566
|
|
|
136139
136567
|
// packages/server/src/twins/airtable/db.ts
|
|
136140
|
-
var
|
|
136568
|
+
var SCHEMA23 = `
|
|
136141
136569
|
CREATE TABLE at_users (id TEXT PRIMARY KEY, name TEXT NOT NULL, email TEXT NOT NULL UNIQUE, position INTEGER NOT NULL);
|
|
136142
136570
|
CREATE TABLE at_bases (id TEXT PRIMARY KEY, name TEXT NOT NULL, permission TEXT NOT NULL, position INTEGER NOT NULL);
|
|
136143
136571
|
CREATE TABLE at_tables (id TEXT PRIMARY KEY, base_id TEXT NOT NULL, name TEXT NOT NULL, description TEXT, primary_field_id TEXT NOT NULL, position INTEGER NOT NULL, next_number INTEGER NOT NULL);
|
|
@@ -136153,8 +136581,8 @@ CREATE TABLE at_comments (
|
|
|
136153
136581
|
created_ms INTEGER NOT NULL, updated_ms INTEGER, deleted_ms INTEGER
|
|
136154
136582
|
);
|
|
136155
136583
|
`;
|
|
136156
|
-
function
|
|
136157
|
-
db2.exec(
|
|
136584
|
+
function migrate39(db2) {
|
|
136585
|
+
db2.exec(SCHEMA23);
|
|
136158
136586
|
}
|
|
136159
136587
|
var BASE625 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
136160
136588
|
function newId7(ctx, kind) {
|
|
@@ -137487,7 +137915,7 @@ async function handle29(c) {
|
|
|
137487
137915
|
function airtableTwin() {
|
|
137488
137916
|
const app2 = new Hono3();
|
|
137489
137917
|
app2.all("*", handle29);
|
|
137490
|
-
return { name: "airtable", basePath: "/v0", app: app2, migrate:
|
|
137918
|
+
return { name: "airtable", basePath: "/v0", app: app2, migrate: migrate39, seed: seed39, credentials: credentials38, dumpState: dumpState38, actions: {}, checks: {}, coverage: airtableCoverage };
|
|
137491
137919
|
}
|
|
137492
137920
|
|
|
137493
137921
|
// packages/server/src/registry.ts
|
|
@@ -137516,6 +137944,7 @@ function envInfo(env, origin, port) {
|
|
|
137516
137944
|
};
|
|
137517
137945
|
}
|
|
137518
137946
|
const mcp = Object.fromEntries(Object.entries(env.mcpTokens).map(([tool, token2]) => [tool, { url: `${origin}/e/${env.id}/mcp/${tool}`, token: token2 }]));
|
|
137947
|
+
const tools = Object.entries(env.scene.tools ?? {}).map(([name5, t]) => ({ name: name5, ...t.description && { description: t.description }, ...t.schema && { schema: t.schema }, ...t.twin && { twin: t.twin } }));
|
|
137519
137948
|
return {
|
|
137520
137949
|
id: env.id,
|
|
137521
137950
|
sceneId: env.scene.id,
|
|
@@ -137523,6 +137952,7 @@ function envInfo(env, origin, port) {
|
|
|
137523
137952
|
timeScale: env.scene.time_scale,
|
|
137524
137953
|
services: services2,
|
|
137525
137954
|
...Object.keys(mcp).length ? { mcp } : {},
|
|
137955
|
+
...tools.length ? { tools } : {},
|
|
137526
137956
|
...env.sandbox ? { sandbox: { ...structuredClone(env.sandbox), seed: env.seed } } : {}
|
|
137527
137957
|
};
|
|
137528
137958
|
}
|
|
@@ -138370,7 +138800,7 @@ function addressedEvent(env, event3) {
|
|
|
138370
138800
|
// packages/server/src/sessions.ts
|
|
138371
138801
|
function agentCalls(env) {
|
|
138372
138802
|
let calls2;
|
|
138373
|
-
return { first: (pattern) => (calls2 ??= env.trace.list().filter((entry2) => entry2.source === "agent")).find(compileTracePattern(pattern)) };
|
|
138803
|
+
return { first: (pattern) => (calls2 ??= env.trace.list().filter((entry2) => entry2.source === "agent")).find(compileTracePattern(pattern, sceneTools(env))) };
|
|
138374
138804
|
}
|
|
138375
138805
|
function lastTimedActorMs(env) {
|
|
138376
138806
|
return env.store.db.prepare("SELECT max(due_ms) AS due FROM _ancha_jobs WHERE state = 'pending' AND kind IN ('actor', 'world.conditional_actor') AND due_ms <= ?").get(parseDuration(env.scene.timeout)).due;
|
|
@@ -138565,12 +138995,13 @@ var TrialSessions = class {
|
|
|
138565
138995
|
env.touchLease();
|
|
138566
138996
|
return { env, session: { ...record8.session } };
|
|
138567
138997
|
}
|
|
138568
|
-
done(token2) {
|
|
138998
|
+
done(token2, answer) {
|
|
138569
138999
|
const { env, session } = this.authenticate(token2, true);
|
|
138570
139000
|
return env.serialize(() => {
|
|
138571
139001
|
this.authenticate(token2, true);
|
|
138572
139002
|
const record8 = this.#record(env, session.id);
|
|
138573
139003
|
if (record8.session.state === "prepared") throw new AnchaError("SESSION_CONFLICT", "session has not started");
|
|
139004
|
+
if (answer !== void 0 && record8.session.state === "running") env.trace.record({ source: "agent", service: "agent", method: "POST", path: "/done", status: 200, request: { output: answer.output } });
|
|
138574
139005
|
if (record8.session.state === "running") record8.session.state = "done";
|
|
138575
139006
|
});
|
|
138576
139007
|
}
|
|
@@ -138928,7 +139359,8 @@ function sessionRoutes(opts, sessions) {
|
|
|
138928
139359
|
signal: c.req.raw.signal
|
|
138929
139360
|
})));
|
|
138930
139361
|
app2.post("/done", async (c) => {
|
|
138931
|
-
await
|
|
139362
|
+
const body6 = await c.req.json().catch(() => void 0);
|
|
139363
|
+
await sessions.done(token2(c.req.header("authorization")), body6 && typeof body6 === "object" && "output" in body6 ? { output: body6.output } : void 0);
|
|
138932
139364
|
return c.json({ ok: true });
|
|
138933
139365
|
});
|
|
138934
139366
|
app2.get("/events", async (c) => {
|
|
@@ -139221,6 +139653,12 @@ function createApp(opts) {
|
|
|
139221
139653
|
...response5 !== void 0 && { response: response5 },
|
|
139222
139654
|
gap: res.status === 501 || res.headers.has(GAP_HEADER),
|
|
139223
139655
|
// Extract before TraceRecorder caps response bodies; never infer a harness fault from status.
|
|
139656
|
+
...res.headers.has(SETUP_ISSUE_HEADER) && { issue: {
|
|
139657
|
+
kind: "tools",
|
|
139658
|
+
owner: "harness",
|
|
139659
|
+
service,
|
|
139660
|
+
message: typeof response5 === "object" && response5 !== null && typeof response5.error === "string" ? response5.error : "the test stopped before the agent ran"
|
|
139661
|
+
} },
|
|
139224
139662
|
...res.headers.has(INTERNAL_ERROR_HEADER) && { issue: {
|
|
139225
139663
|
kind: "twin",
|
|
139226
139664
|
owner: "harness",
|
|
@@ -142448,11 +142886,11 @@ function build() {
|
|
|
142448
142886
|
const ResultTypeSchema = string2();
|
|
142449
142887
|
const ResultMetaSchema = looseObject({ [SERVER_INFO_META_KEY]: ImplementationSchema$1.optional().catch(void 0) });
|
|
142450
142888
|
const wireMeta = ResultMetaSchema.optional();
|
|
142451
|
-
function wireResult(
|
|
142889
|
+
function wireResult(shape4) {
|
|
142452
142890
|
return looseObject({
|
|
142453
142891
|
_meta: wireMeta,
|
|
142454
142892
|
resultType: ResultTypeSchema.default("complete"),
|
|
142455
|
-
...
|
|
142893
|
+
...shape4
|
|
142456
142894
|
});
|
|
142457
142895
|
}
|
|
142458
142896
|
const ResultSchema$1 = wireResult({});
|
|
@@ -142665,10 +143103,10 @@ function build() {
|
|
|
142665
143103
|
"server/discover": dispatchRequest("server/discover", {}),
|
|
142666
143104
|
"subscriptions/listen": dispatchRequest("subscriptions/listen", subscriptionsListenParamsShape)
|
|
142667
143105
|
};
|
|
142668
|
-
function liftedResult(
|
|
143106
|
+
function liftedResult(shape4) {
|
|
142669
143107
|
return looseObject({
|
|
142670
143108
|
_meta: wireMeta,
|
|
142671
|
-
...
|
|
143109
|
+
...shape4
|
|
142672
143110
|
});
|
|
142673
143111
|
}
|
|
142674
143112
|
const dispatchResultSchemas = {
|
|
@@ -152608,7 +153046,7 @@ var require_formats = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
152608
153046
|
function isLeapYear(year) {
|
|
152609
153047
|
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
152610
153048
|
}
|
|
152611
|
-
const
|
|
153049
|
+
const DATE2 = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
152612
153050
|
const DAYS2 = [
|
|
152613
153051
|
0,
|
|
152614
153052
|
31,
|
|
@@ -152625,7 +153063,7 @@ var require_formats = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
152625
153063
|
31
|
|
152626
153064
|
];
|
|
152627
153065
|
function date10(str3) {
|
|
152628
|
-
const matches7 =
|
|
153066
|
+
const matches7 = DATE2.exec(str3);
|
|
152629
153067
|
if (!matches7) return false;
|
|
152630
153068
|
const year = +matches7[1];
|
|
152631
153069
|
const month = +matches7[2];
|
|
@@ -154456,9 +154894,9 @@ var McpServer = class {
|
|
|
154456
154894
|
};
|
|
154457
154895
|
this._registeredPrompts[name5] = registeredPrompt;
|
|
154458
154896
|
if (argsSchema) {
|
|
154459
|
-
const
|
|
154460
|
-
if (
|
|
154461
|
-
if (Object.values(
|
|
154897
|
+
const shape4 = getSchemaShape(argsSchema);
|
|
154898
|
+
if (shape4) {
|
|
154899
|
+
if (Object.values(shape4).some((field3) => {
|
|
154462
154900
|
return isCompletable(unwrapOptionalSchema(field3));
|
|
154463
154901
|
})) this.setCompletionRequestHandler();
|
|
154464
154902
|
}
|
|
@@ -156059,8 +156497,8 @@ function slackMcpServer(info, request4) {
|
|
|
156059
156497
|
if (!service) throw new AnchaError("USAGE", "this sandbox does not include Slack");
|
|
156060
156498
|
const client = createVendorClient(info, "slack", "/api/", request4);
|
|
156061
156499
|
const server = new McpServer({ name: SLACK_MCP_PROFILE, version: "1.0.0" }, { instructions: "Tools access one local mock Slack workspace. Reads and writes use the same native API as the browser. Follow pagination cursors. There is no user-token search, DM, file upload, or management/reset tool. Reset is controlled by the developer and does not reset your conversation memory." });
|
|
156062
|
-
for (const [method2, description2,
|
|
156063
|
-
server.registerTool("slack_" + method2.replaceAll(".", "_"), { description: description2, inputSchema: external_exports.strictObject(
|
|
156500
|
+
for (const [method2, description2, shape4] of definitions2) {
|
|
156501
|
+
server.registerTool("slack_" + method2.replaceAll(".", "_"), { description: description2, inputSchema: external_exports.strictObject(shape4), annotations: { readOnlyHint: !writes.has(method2), destructiveHint: method2 === "chat.delete", openWorldHint: false } }, async (args, context2) => {
|
|
156064
156502
|
return client.result("POST", method2, args, context2.mcpReq.signal);
|
|
156065
156503
|
});
|
|
156066
156504
|
}
|
|
@@ -156183,9 +156621,9 @@ function safePath(path4, allowRoot = false) {
|
|
|
156183
156621
|
return allowRoot && path4 === "" || path4.length > 0 && !path4.includes("\\") && !path4.includes("\0") && path4.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
156184
156622
|
}
|
|
156185
156623
|
function registerGithubRepositoryTools(server, api3) {
|
|
156186
|
-
const invoke2 = async (method2, path4, body6, signal,
|
|
156624
|
+
const invoke2 = async (method2, path4, body6, signal, shape4) => {
|
|
156187
156625
|
const response5 = await api3.call(method2, path4, body6, signal);
|
|
156188
|
-
return mcpJsonResult(response5.isError ? response5.value :
|
|
156626
|
+
return mcpJsonResult(response5.isError ? response5.value : shape4(response5.value), response5.isError);
|
|
156189
156627
|
};
|
|
156190
156628
|
server.registerTool("list_commits", {
|
|
156191
156629
|
description: "List commits in a branch with native pagination.",
|
|
@@ -156685,8 +157123,34 @@ function datadogMcpServer(info, request4) {
|
|
|
156685
157123
|
return server;
|
|
156686
157124
|
}
|
|
156687
157125
|
|
|
157126
|
+
// backend/src/mcp/agent-tools.ts
|
|
157127
|
+
function traced2(schema) {
|
|
157128
|
+
return { "~standard": { version: 1, vendor: "ancha", validate: (value4) => ({ value: value4 }), jsonSchema: { input: () => schema, output: () => schema } } };
|
|
157129
|
+
}
|
|
157130
|
+
function callToolResult(answer) {
|
|
157131
|
+
if (answer.wrap === "mcp" && answer.raw && typeof answer.raw === "object") return answer.raw;
|
|
157132
|
+
if (answer.error !== void 0) return mcpTextResult(answer.error, true);
|
|
157133
|
+
return typeof answer.result === "string" ? mcpTextResult(answer.result) : mcpJsonResult(answer.result ?? null);
|
|
157134
|
+
}
|
|
157135
|
+
function agentToolsMcpServer(info, request4) {
|
|
157136
|
+
if (!info.services.tools) throw new AnchaError("USAGE", "this world has no tools from a trace");
|
|
157137
|
+
const client = createVendorClient(info, "tools", "", request4);
|
|
157138
|
+
const server = new McpServer({ name: "ancha-tools", version: "1.0.0" }, { instructions: "The agent's own tools, answered as production answered them." });
|
|
157139
|
+
for (const tool of info.tools ?? []) {
|
|
157140
|
+
server.registerTool(
|
|
157141
|
+
tool.name,
|
|
157142
|
+
{ ...tool.description && { description: tool.description }, inputSchema: traced2(tool.schema ?? { type: "object" }) },
|
|
157143
|
+
async (args, context2) => {
|
|
157144
|
+
const { value: value4, isError } = await client.call("POST", `/tools/${encodeURIComponent(tool.name)}`, { args }, context2.mcpReq.signal);
|
|
157145
|
+
return isError && value4?.error && !("source" in value4) ? mcpJsonResult(value4, true) : callToolResult(value4);
|
|
157146
|
+
}
|
|
157147
|
+
);
|
|
157148
|
+
}
|
|
157149
|
+
return server;
|
|
157150
|
+
}
|
|
157151
|
+
|
|
156688
157152
|
// backend/src/mcp/http.ts
|
|
156689
|
-
var factories = { slack: slackMcpServer, github: githubMcpServer, pagerduty: pagerdutyMcpServer, datadog: datadogMcpServer };
|
|
157153
|
+
var factories = { slack: slackMcpServer, github: githubMcpServer, pagerduty: pagerdutyMcpServer, datadog: datadogMcpServer, tools: agentToolsMcpServer };
|
|
156690
157154
|
var names2 = { slack: SLACK_MCP_TOOL_NAMES, github: GITHUB_MCP_TOOL_NAMES, pagerduty: PAGERDUTY_MCP_TOOL_NAMES, datadog: DATADOG_MCP_TOOL_NAMES };
|
|
156691
157155
|
var mcpTwins = Object.fromEntries(Object.entries(factories).map(([tool, factory]) => [
|
|
156692
157156
|
tool,
|
|
@@ -156705,7 +157169,7 @@ var mcpTwins = Object.fromEntries(Object.entries(factories).map(([tool, factory]
|
|
|
156705
157169
|
onerror: () => {
|
|
156706
157170
|
}
|
|
156707
157171
|
});
|
|
156708
|
-
const known2 = new Set(names2[tool]);
|
|
157172
|
+
const known2 = new Set(tool === "tools" ? (info.tools ?? []).map((t) => t.name) : names2[tool]);
|
|
156709
157173
|
return {
|
|
156710
157174
|
close: () => handler.close(),
|
|
156711
157175
|
async fetch(input2) {
|