@ancha-labs/cli 0.2.0 → 0.3.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 +4947 -3534
- package/lib/assets/SKILL.md +1 -1
- package/lib/assets/docs/apps.md +7 -5
- package/lib/assets/docs/integrations.md +1 -1
- package/lib/assets/docs/run.md +2 -0
- package/lib/assets/harbor/companion.mjs +722 -277
- package/lib/assets/ui/app.js +1 -1
- package/lib/mcp-entry.mjs +51 -1
- package/lib/worker.mjs +87968 -85498
- package/lib/world-server.mjs +719 -278
- package/package.json +1 -1
package/lib/world-server.mjs
CHANGED
|
@@ -56907,9 +56907,9 @@ function stringifyPrimitive(value4) {
|
|
|
56907
56907
|
return `"${value4}"`;
|
|
56908
56908
|
return `${value4}`;
|
|
56909
56909
|
}
|
|
56910
|
-
function optionalKeys(
|
|
56911
|
-
return Object.keys(
|
|
56912
|
-
return
|
|
56910
|
+
function optionalKeys(shape4) {
|
|
56911
|
+
return Object.keys(shape4).filter((k) => {
|
|
56912
|
+
return shape4[k]._zod.optin !== void 0 && shape4[k]._zod.optout === "optional";
|
|
56913
56913
|
});
|
|
56914
56914
|
}
|
|
56915
56915
|
var NUMBER_FORMAT_RANGES = /* @__PURE__ */ (() => ({
|
|
@@ -56958,33 +56958,33 @@ function omit(schema, mask2) {
|
|
|
56958
56958
|
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)).filter((key3) => !omitted.has(key3)));
|
|
56959
56959
|
return clone(schema, mergeDefs(currDef, { shape: newShape, checks: [] }));
|
|
56960
56960
|
}
|
|
56961
|
-
function extend(schema,
|
|
56962
|
-
if (!isPlainObject(
|
|
56961
|
+
function extend(schema, shape4) {
|
|
56962
|
+
if (!isPlainObject(shape4)) {
|
|
56963
56963
|
throw new Error("Invalid input to extend: expected a plain object");
|
|
56964
56964
|
}
|
|
56965
56965
|
const checks = schema._zod.def.checks;
|
|
56966
56966
|
const hasChecks = checks && checks.length > 0;
|
|
56967
56967
|
if (hasChecks) {
|
|
56968
56968
|
const existingShape = sourceShape(schema);
|
|
56969
|
-
for (const key3 of Reflect.ownKeys(
|
|
56969
|
+
for (const key3 of Reflect.ownKeys(shape4)) {
|
|
56970
56970
|
if (Object.getOwnPropertyDescriptor(existingShape, key3) !== void 0) {
|
|
56971
56971
|
throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
|
|
56972
56972
|
}
|
|
56973
56973
|
}
|
|
56974
56974
|
}
|
|
56975
|
-
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema,
|
|
56975
|
+
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema, shape4) }));
|
|
56976
56976
|
}
|
|
56977
|
-
function extended(schema,
|
|
56977
|
+
function extended(schema, shape4) {
|
|
56978
56978
|
const newShape = {};
|
|
56979
56979
|
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)));
|
|
56980
|
-
mirrorProps(newShape,
|
|
56980
|
+
mirrorProps(newShape, shape4);
|
|
56981
56981
|
return newShape;
|
|
56982
56982
|
}
|
|
56983
|
-
function safeExtend(schema,
|
|
56984
|
-
if (!isPlainObject(
|
|
56983
|
+
function safeExtend(schema, shape4) {
|
|
56984
|
+
if (!isPlainObject(shape4)) {
|
|
56985
56985
|
throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
56986
56986
|
}
|
|
56987
|
-
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema,
|
|
56987
|
+
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema, shape4) }));
|
|
56988
56988
|
}
|
|
56989
56989
|
function merge(a, b) {
|
|
56990
56990
|
if (!b?._zod?.def) {
|
|
@@ -59432,10 +59432,10 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
59432
59432
|
}
|
|
59433
59433
|
const _normalized = cached(() => normalizeDef(def));
|
|
59434
59434
|
defineLazyInternal(inst, "propValues", (zod) => {
|
|
59435
|
-
const
|
|
59435
|
+
const shape4 = zod.def.shape;
|
|
59436
59436
|
const propValues = {};
|
|
59437
|
-
for (const key3 in
|
|
59438
|
-
const field3 =
|
|
59437
|
+
for (const key3 in shape4) {
|
|
59438
|
+
const field3 = shape4[key3]._zod;
|
|
59439
59439
|
if (field3.values) {
|
|
59440
59440
|
if (!Object.prototype.hasOwnProperty.call(propValues, key3)) {
|
|
59441
59441
|
assignProp(propValues, key3, /* @__PURE__ */ new Set());
|
|
@@ -59467,7 +59467,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
59467
59467
|
}
|
|
59468
59468
|
payload2.value = memo3 ? memo3.alloc(inst, payload2, {}, ctx) : {};
|
|
59469
59469
|
const proms = [];
|
|
59470
|
-
const
|
|
59470
|
+
const shape4 = value4.shape;
|
|
59471
59471
|
const abortEarly = ctx?.abortEarly;
|
|
59472
59472
|
let seen = payload2.issues.length;
|
|
59473
59473
|
for (const key3 of value4.allKeys) {
|
|
@@ -59478,7 +59478,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
59478
59478
|
}
|
|
59479
59479
|
if (key3 === "__proto__")
|
|
59480
59480
|
continue;
|
|
59481
|
-
const el2 =
|
|
59481
|
+
const el2 = shape4[key3];
|
|
59482
59482
|
const optin = el2._zod.optin;
|
|
59483
59483
|
const optout = el2._zod.optout;
|
|
59484
59484
|
const r = el2._zod.run({ value: input2[key3], issues: [] }, ctx);
|
|
@@ -59499,10 +59499,10 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
59499
59499
|
const superParse = inst._zod.parse;
|
|
59500
59500
|
const _normalized = cached(() => normalizeDef(def));
|
|
59501
59501
|
const memo3 = globalConfig.memoizer;
|
|
59502
|
-
const generateFastpass = (
|
|
59502
|
+
const generateFastpass = (shape4) => {
|
|
59503
59503
|
const normalized = _normalized.value;
|
|
59504
59504
|
const syms = normalized.symbolKeys;
|
|
59505
|
-
const doc = new Doc(["payload", "ctx"], { shape:
|
|
59505
|
+
const doc = new Doc(["payload", "ctx"], { shape: shape4, inst, memo: memo3, syms });
|
|
59506
59506
|
const parseStr = (k) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
|
|
59507
59507
|
const prefixStr = (id12, k) => `
|
|
59508
59508
|
let ${id12}_ab = false;
|
|
@@ -59529,7 +59529,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
59529
59529
|
const id12 = ids2[key3];
|
|
59530
59530
|
const k = typeof key3 === "symbol" ? `syms[${syms.indexOf(key3)}]` : esc(key3);
|
|
59531
59531
|
const isPresent = `${k} in input`;
|
|
59532
|
-
const schema =
|
|
59532
|
+
const schema = shape4[key3];
|
|
59533
59533
|
const optin = schema?._zod?.optin;
|
|
59534
59534
|
const isOptionalIn = optin !== void 0;
|
|
59535
59535
|
const isOptionalOut = schema?._zod?.optout === "optional";
|
|
@@ -60968,7 +60968,7 @@ function isRecursive(inst, stack, resolve5) {
|
|
|
60968
60968
|
result = answer;
|
|
60969
60969
|
}
|
|
60970
60970
|
};
|
|
60971
|
-
const
|
|
60971
|
+
const shape4 = (sh, spread) => {
|
|
60972
60972
|
let answer = NONE;
|
|
60973
60973
|
for (const key3 of Reflect.ownKeys(sh)) {
|
|
60974
60974
|
const desc = Object.getOwnPropertyDescriptor(sh, key3);
|
|
@@ -60989,7 +60989,7 @@ function isRecursive(inst, stack, resolve5) {
|
|
|
60989
60989
|
switch (kind) {
|
|
60990
60990
|
case "object": {
|
|
60991
60991
|
const raw3 = rawShape(def);
|
|
60992
|
-
merge3(raw3 ?
|
|
60992
|
+
merge3(raw3 ? shape4(raw3, true) : ASSUMED);
|
|
60993
60993
|
check3(def.catchall);
|
|
60994
60994
|
break;
|
|
60995
60995
|
}
|
|
@@ -69200,12 +69200,12 @@ function generatePropertiesChecks(doc, ctx, def, accessor) {
|
|
|
69200
69200
|
throw new ZodCompileUnsupportedError(`check with a custom "when" condition`);
|
|
69201
69201
|
}
|
|
69202
69202
|
doc.write(`if (${accessor} == null) return INVALID;`);
|
|
69203
|
-
const
|
|
69204
|
-
for (const key3 of Reflect.ownKeys(
|
|
69203
|
+
const shape4 = def.shape;
|
|
69204
|
+
for (const key3 of Reflect.ownKeys(shape4)) {
|
|
69205
69205
|
const keyExpr = typeof key3 === "symbol" ? addConstant(ctx, key3) : esc(key3);
|
|
69206
69206
|
const inputVar = newVar(ctx);
|
|
69207
69207
|
doc.write(`const ${inputVar} = ${accessor}[${keyExpr}];`);
|
|
69208
|
-
compileChild(doc, ctx,
|
|
69208
|
+
compileChild(doc, ctx, shape4[key3], inputVar, false);
|
|
69209
69209
|
}
|
|
69210
69210
|
}
|
|
69211
69211
|
function generatePropertyCheck(doc, ctx, def, accessor) {
|
|
@@ -69587,13 +69587,13 @@ function generateDateCheck(doc, accessor) {
|
|
|
69587
69587
|
function generateObjectCheck(doc, ctx, schema, accessor, buildsValue = true) {
|
|
69588
69588
|
const def = schema._zod.def;
|
|
69589
69589
|
doc.write(`if (typeof ${accessor} !== "object" || ${accessor} === null || Array.isArray(${accessor})) return INVALID;`);
|
|
69590
|
-
const
|
|
69591
|
-
const keys5 = Object.keys(
|
|
69592
|
-
const symbolKeys = Object.getOwnPropertySymbols(
|
|
69590
|
+
const shape4 = def.shape;
|
|
69591
|
+
const keys5 = Object.keys(shape4);
|
|
69592
|
+
const symbolKeys = Object.getOwnPropertySymbols(shape4);
|
|
69593
69593
|
const allKeys = symbolKeys.length ? [...keys5, ...symbolKeys] : keys5;
|
|
69594
69594
|
const keyExpr = (k) => typeof k === "symbol" ? addConstant(ctx, k) : esc(k);
|
|
69595
69595
|
const propKey = (k) => typeof k === "symbol" ? `[${keyExpr(k)}]` : esc(k);
|
|
69596
|
-
const propShape =
|
|
69596
|
+
const propShape = shape4;
|
|
69597
69597
|
if (keys5.includes("__proto__")) {
|
|
69598
69598
|
throw new ZodCompileUnsupportedError('object shape key "__proto__"');
|
|
69599
69599
|
}
|
|
@@ -71100,10 +71100,10 @@ function _property(property3, schema, params9) {
|
|
|
71100
71100
|
});
|
|
71101
71101
|
}
|
|
71102
71102
|
// @__NO_SIDE_EFFECTS__
|
|
71103
|
-
function _properties(
|
|
71103
|
+
function _properties(shape4, params9) {
|
|
71104
71104
|
return new $ZodCheckProperties({
|
|
71105
71105
|
check: "properties",
|
|
71106
|
-
shape:
|
|
71106
|
+
shape: shape4,
|
|
71107
71107
|
...normalizeParams(params9)
|
|
71108
71108
|
});
|
|
71109
71109
|
}
|
|
@@ -72365,21 +72365,21 @@ function inputOptin(schema) {
|
|
|
72365
72365
|
var objectProcessor = (schema, ctx, _json, params9) => {
|
|
72366
72366
|
const json30 = _json;
|
|
72367
72367
|
const def = schema._zod.def;
|
|
72368
|
-
const
|
|
72369
|
-
const symbolKeys = Object.getOwnPropertySymbols(
|
|
72368
|
+
const shape4 = def.shape;
|
|
72369
|
+
const symbolKeys = Object.getOwnPropertySymbols(shape4);
|
|
72370
72370
|
if (symbolKeys.length && handleUnrepresentable(schema, ctx, json30, params9, "Symbol keys cannot be represented in JSON Schema")) {
|
|
72371
72371
|
return;
|
|
72372
72372
|
}
|
|
72373
72373
|
json30.type = "object";
|
|
72374
72374
|
json30.properties = {};
|
|
72375
|
-
for (const key3 in
|
|
72376
|
-
assignProp(json30.properties, key3, processSchema(
|
|
72375
|
+
for (const key3 in shape4) {
|
|
72376
|
+
assignProp(json30.properties, key3, processSchema(shape4[key3], ctx, {
|
|
72377
72377
|
...params9,
|
|
72378
72378
|
path: [...params9.path, "properties", key3]
|
|
72379
72379
|
}));
|
|
72380
72380
|
}
|
|
72381
72381
|
const requiredKeys = [];
|
|
72382
|
-
for (const key3 of Object.keys(
|
|
72382
|
+
for (const key3 of Object.keys(shape4)) {
|
|
72383
72383
|
const field3 = def.shape[key3];
|
|
72384
72384
|
if (ctx.io === "input" ? inputOptin(field3) === void 0 : field3._zod.optout === void 0) {
|
|
72385
72385
|
requiredKeys.push(key3);
|
|
@@ -73941,8 +73941,8 @@ function array(element, params9) {
|
|
|
73941
73941
|
return _array(ZodArray, element, params9);
|
|
73942
73942
|
}
|
|
73943
73943
|
function keyof(schema) {
|
|
73944
|
-
const
|
|
73945
|
-
return _enum2(Object.keys(
|
|
73944
|
+
const shape4 = schema._zod.def.shape;
|
|
73945
|
+
return _enum2(Object.keys(shape4));
|
|
73946
73946
|
}
|
|
73947
73947
|
var ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
|
|
73948
73948
|
_ensureDefaultMemoizer();
|
|
@@ -73994,26 +73994,26 @@ var ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
|
|
|
73994
73994
|
return util_exports.required(ZodNonOptional, this, args[0]);
|
|
73995
73995
|
}
|
|
73996
73996
|
});
|
|
73997
|
-
function object(
|
|
73997
|
+
function object(shape4, params9) {
|
|
73998
73998
|
const def = {
|
|
73999
73999
|
type: "object",
|
|
74000
|
-
shape:
|
|
74000
|
+
shape: shape4 ?? {},
|
|
74001
74001
|
...util_exports.normalizeParams(params9)
|
|
74002
74002
|
};
|
|
74003
74003
|
return new ZodObject(def);
|
|
74004
74004
|
}
|
|
74005
|
-
function strictObject(
|
|
74005
|
+
function strictObject(shape4, params9) {
|
|
74006
74006
|
return new ZodObject({
|
|
74007
74007
|
type: "object",
|
|
74008
|
-
shape:
|
|
74008
|
+
shape: shape4,
|
|
74009
74009
|
catchall: never(),
|
|
74010
74010
|
...util_exports.normalizeParams(params9)
|
|
74011
74011
|
});
|
|
74012
74012
|
}
|
|
74013
|
-
function looseObject(
|
|
74013
|
+
function looseObject(shape4, params9) {
|
|
74014
74014
|
return new ZodObject({
|
|
74015
74015
|
type: "object",
|
|
74016
|
-
shape:
|
|
74016
|
+
shape: shape4,
|
|
74017
74017
|
catchall: unknown(),
|
|
74018
74018
|
...util_exports.normalizeParams(params9)
|
|
74019
74019
|
});
|
|
@@ -74552,8 +74552,8 @@ var meta2 = meta;
|
|
|
74552
74552
|
var ZodInstanceOf = /* @__PURE__ */ $constructor("ZodInstanceOf", (inst, def) => {
|
|
74553
74553
|
ZodCustom.init(inst, def);
|
|
74554
74554
|
}, {
|
|
74555
|
-
properties(
|
|
74556
|
-
return this.check(_properties(
|
|
74555
|
+
properties(shape4, params9) {
|
|
74556
|
+
return this.check(_properties(shape4, params9));
|
|
74557
74557
|
}
|
|
74558
74558
|
});
|
|
74559
74559
|
function _instanceof(cls, params9 = {}) {
|
|
@@ -75139,13 +75139,13 @@ function convertBaseSchema(schema, ctx) {
|
|
|
75139
75139
|
break;
|
|
75140
75140
|
}
|
|
75141
75141
|
case "object": {
|
|
75142
|
-
const
|
|
75142
|
+
const shape4 = {};
|
|
75143
75143
|
const properties2 = schema.properties || {};
|
|
75144
75144
|
const requiredSet = new Set(schema.required || []);
|
|
75145
75145
|
const additionalSchema = typeof schema.additionalProperties === "object" ? convertSchema(schema.additionalProperties, ctx) : void 0;
|
|
75146
75146
|
for (const [key3, propSchema] of Object.entries(properties2)) {
|
|
75147
75147
|
const propZodSchema = convertSchema(propSchema, ctx);
|
|
75148
|
-
assignProp(
|
|
75148
|
+
assignProp(shape4, key3, requiredSet.has(key3) ? propZodSchema : propZodSchema.optional());
|
|
75149
75149
|
}
|
|
75150
75150
|
if (schema.patternProperties) {
|
|
75151
75151
|
const patternProps = schema.patternProperties;
|
|
@@ -75157,8 +75157,8 @@ function convertBaseSchema(schema, ctx) {
|
|
|
75157
75157
|
looseRecords.push(z.looseRecord(keySchema, patternValue));
|
|
75158
75158
|
}
|
|
75159
75159
|
const schemasToIntersect = [];
|
|
75160
|
-
if (Object.keys(
|
|
75161
|
-
schemasToIntersect.push(z.object(
|
|
75160
|
+
if (Object.keys(shape4).length > 0) {
|
|
75161
|
+
schemasToIntersect.push(z.object(shape4).passthrough());
|
|
75162
75162
|
}
|
|
75163
75163
|
schemasToIntersect.push(...looseRecords);
|
|
75164
75164
|
if (schemasToIntersect.length === 0) {
|
|
@@ -75173,7 +75173,7 @@ function convertBaseSchema(schema, ctx) {
|
|
|
75173
75173
|
zodSchema = result;
|
|
75174
75174
|
}
|
|
75175
75175
|
if (schema.additionalProperties === false) {
|
|
75176
|
-
const propertyKeys = Object.keys(
|
|
75176
|
+
const propertyKeys = Object.keys(shape4);
|
|
75177
75177
|
const patterns = patternKeys.map((p2) => new RegExp(p2));
|
|
75178
75178
|
const basePatternSchema = zodSchema;
|
|
75179
75179
|
zodSchema = zodSchema.check((payload2) => {
|
|
@@ -75198,7 +75198,7 @@ function convertBaseSchema(schema, ctx) {
|
|
|
75198
75198
|
});
|
|
75199
75199
|
}
|
|
75200
75200
|
} else {
|
|
75201
|
-
const objectSchema = z.object(
|
|
75201
|
+
const objectSchema = z.object(shape4);
|
|
75202
75202
|
if (schema.additionalProperties === false) {
|
|
75203
75203
|
zodSchema = objectSchema.strict();
|
|
75204
75204
|
} else if (additionalSchema) {
|
|
@@ -78375,11 +78375,11 @@ function build() {
|
|
|
78375
78375
|
const ResultTypeSchema = string2();
|
|
78376
78376
|
const ResultMetaSchema = looseObject({ [SERVER_INFO_META_KEY]: ImplementationSchema$1.optional().catch(void 0) });
|
|
78377
78377
|
const wireMeta = ResultMetaSchema.optional();
|
|
78378
|
-
function wireResult(
|
|
78378
|
+
function wireResult(shape4) {
|
|
78379
78379
|
return looseObject({
|
|
78380
78380
|
_meta: wireMeta,
|
|
78381
78381
|
resultType: ResultTypeSchema.default("complete"),
|
|
78382
|
-
...
|
|
78382
|
+
...shape4
|
|
78383
78383
|
});
|
|
78384
78384
|
}
|
|
78385
78385
|
const ResultSchema$1 = wireResult({});
|
|
@@ -78592,10 +78592,10 @@ function build() {
|
|
|
78592
78592
|
"server/discover": dispatchRequest("server/discover", {}),
|
|
78593
78593
|
"subscriptions/listen": dispatchRequest("subscriptions/listen", subscriptionsListenParamsShape)
|
|
78594
78594
|
};
|
|
78595
|
-
function liftedResult(
|
|
78595
|
+
function liftedResult(shape4) {
|
|
78596
78596
|
return looseObject({
|
|
78597
78597
|
_meta: wireMeta,
|
|
78598
|
-
...
|
|
78598
|
+
...shape4
|
|
78599
78599
|
});
|
|
78600
78600
|
}
|
|
78601
78601
|
const dispatchResultSchemas = {
|
|
@@ -90383,9 +90383,9 @@ var McpServer = class {
|
|
|
90383
90383
|
};
|
|
90384
90384
|
this._registeredPrompts[name5] = registeredPrompt;
|
|
90385
90385
|
if (argsSchema) {
|
|
90386
|
-
const
|
|
90387
|
-
if (
|
|
90388
|
-
if (Object.values(
|
|
90386
|
+
const shape4 = getSchemaShape(argsSchema);
|
|
90387
|
+
if (shape4) {
|
|
90388
|
+
if (Object.values(shape4).some((field3) => {
|
|
90389
90389
|
return isCompletable(unwrapOptionalSchema(field3));
|
|
90390
90390
|
})) this.setCompletionRequestHandler();
|
|
90391
90391
|
}
|
|
@@ -91921,6 +91921,8 @@ var EXECUTION_SUPPORT = {
|
|
|
91921
91921
|
"world_rules": sceneOnly,
|
|
91922
91922
|
"people": sceneOnly,
|
|
91923
91923
|
"until": sceneOnly,
|
|
91924
|
+
"trigger": sceneOnly,
|
|
91925
|
+
"tools": sceneOnly,
|
|
91924
91926
|
"deadline": sceneOnly,
|
|
91925
91927
|
"start.message": sceneOnly,
|
|
91926
91928
|
"pass": sceneOnly,
|
|
@@ -91959,7 +91961,8 @@ var EXECUTION_SUPPORT = {
|
|
|
91959
91961
|
"--pass-env": sceneOnly,
|
|
91960
91962
|
"--inherit-env": sceneOnly,
|
|
91961
91963
|
"--upload": sceneOnly,
|
|
91962
|
-
"--upload-required": sceneOnly
|
|
91964
|
+
"--upload-required": sceneOnly,
|
|
91965
|
+
"--allow-unwrapped": sceneOnly
|
|
91963
91966
|
};
|
|
91964
91967
|
|
|
91965
91968
|
// packages/core/src/relay.ts
|
|
@@ -100635,6 +100638,51 @@ var TraceCheckSchema = external_exports.strictObject({
|
|
|
100635
100638
|
message: "status applies to called; not_called always counts every attempt",
|
|
100636
100639
|
path: ["status"]
|
|
100637
100640
|
});
|
|
100641
|
+
var TOOL_NAME_PATTERN = /^[A-Za-z_][\w.-]{0,127}$/;
|
|
100642
|
+
var ToolObservationSchema = external_exports.strictObject({
|
|
100643
|
+
tool: external_exports.string().regex(TOOL_NAME_PATTERN),
|
|
100644
|
+
at: duration6("Offset from the start of the production trace, e.g. 3s200ms"),
|
|
100645
|
+
/** When the call returned, as an offset like `at`: a test that reaches this answer has reached that time. */
|
|
100646
|
+
end: duration6("Offset from the start of the production trace when the call returned").optional(),
|
|
100647
|
+
args: external_exports.unknown().optional(),
|
|
100648
|
+
/** What the tool function returned. A recorded failure has `error` instead. */
|
|
100649
|
+
result: external_exports.unknown().optional(),
|
|
100650
|
+
error: external_exports.string().optional(),
|
|
100651
|
+
/** The framework's envelope as the trace held it (an MCP CallToolResult, a LangChain ToolMessage), for replay over MCP. */
|
|
100652
|
+
wrap: external_exports.enum(["mcp", "langchain", "output"]).optional(),
|
|
100653
|
+
raw: external_exports.unknown().optional(),
|
|
100654
|
+
call_id: external_exports.string().optional()
|
|
100655
|
+
}).refine((o) => o.error === void 0 || o.result === void 0, { message: "a recorded call has a result or an error, not both" });
|
|
100656
|
+
var ToolExampleSchema = external_exports.strictObject({
|
|
100657
|
+
trace: external_exports.string().optional(),
|
|
100658
|
+
at: duration6("Offset from the start of that trace"),
|
|
100659
|
+
args: external_exports.unknown().optional(),
|
|
100660
|
+
result: external_exports.unknown().optional(),
|
|
100661
|
+
error: external_exports.string().optional()
|
|
100662
|
+
});
|
|
100663
|
+
var SceneToolSchema = external_exports.strictObject({
|
|
100664
|
+
/** A JSON lines file next to the scene, one recorded call per line (`ancha run` reads it into `recorded`). */
|
|
100665
|
+
observations: external_exports.string().regex(/^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[^\0]+$/, "a path relative to the scene file, without ..").optional(),
|
|
100666
|
+
recorded: external_exports.array(ToolObservationSchema).optional(),
|
|
100667
|
+
/** Calls from other traces of this agent, so a simulated answer can follow how the tool behaved there. */
|
|
100668
|
+
examples: external_exports.array(ToolExampleSchema).optional(),
|
|
100669
|
+
/** A call production never made: simulated (the default for a read), a tool error (the default for a write), or the twin. */
|
|
100670
|
+
unrecorded: external_exports.enum(["simulate", "fail", "twin"]).optional(),
|
|
100671
|
+
/** The twin that answers what production never recorded (TRACE_PLAN_V2 §5.3). */
|
|
100672
|
+
twin: external_exports.string().optional(),
|
|
100673
|
+
/** The agent reaches this tool over MCP: in a test its client points at {{tools.mcp_url}}, so there is nothing to wrap. */
|
|
100674
|
+
mcp: external_exports.literal(true).optional(),
|
|
100675
|
+
/** `ancha run --allow-unwrapped`: the agent may call this tool for real (it does not wrap it), so the test does not stop. */
|
|
100676
|
+
allow_unwrapped: external_exports.literal(true).optional(),
|
|
100677
|
+
/** Changes something (a refund, an email): an unrecorded call is never answered by invention unless set to simulate. */
|
|
100678
|
+
write: external_exports.boolean().optional(),
|
|
100679
|
+
description: external_exports.string().optional(),
|
|
100680
|
+
schema: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
100681
|
+
});
|
|
100682
|
+
var TriggerSchema = external_exports.strictObject({
|
|
100683
|
+
task: external_exports.string().optional(),
|
|
100684
|
+
input: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
100685
|
+
});
|
|
100638
100686
|
var CheckSchema = external_exports.union([
|
|
100639
100687
|
external_exports.strictObject({ id: external_exports.string(), state: StateCheckSchema }),
|
|
100640
100688
|
external_exports.strictObject({ id: external_exports.string(), trace: TraceCheckSchema }),
|
|
@@ -100656,6 +100704,8 @@ var SceneSchema = external_exports.strictObject({
|
|
|
100656
100704
|
skip_idle: external_exports.boolean().optional(),
|
|
100657
100705
|
timeout: duration6("Per-trial time budget, e.g. 5m").default("5m"),
|
|
100658
100706
|
task: external_exports.string().optional(),
|
|
100707
|
+
trigger: TriggerSchema.optional(),
|
|
100708
|
+
tools: external_exports.record(external_exports.string().regex(TOOL_NAME_PATTERN, "a tool name as the model saw it"), SceneToolSchema).optional(),
|
|
100659
100709
|
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() }),
|
|
100660
100710
|
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(),
|
|
100661
100711
|
people: PeopleSchema.optional(),
|
|
@@ -101788,6 +101838,36 @@ function twinIssues(scene2) {
|
|
|
101788
101838
|
});
|
|
101789
101839
|
return issues;
|
|
101790
101840
|
}
|
|
101841
|
+
function toolIssues(scene2) {
|
|
101842
|
+
const issues = [];
|
|
101843
|
+
for (const [name5, tool] of Object.entries(scene2.tools ?? {})) {
|
|
101844
|
+
const path4 = `tools.${name5}`;
|
|
101845
|
+
if (tool.twin !== void 0) {
|
|
101846
|
+
if (!isTwinName(tool.twin)) issues.push({ path: `${path4}.twin`, message: `unsupported twin ${tool.twin}`, hint: `supported twins: ${SUPPORTED_TWINS.join(", ")}` });
|
|
101847
|
+
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}]` });
|
|
101848
|
+
}
|
|
101849
|
+
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` });
|
|
101850
|
+
if (tool.observations !== void 0 && tool.recorded === void 0) {
|
|
101851
|
+
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" });
|
|
101852
|
+
}
|
|
101853
|
+
tool.recorded?.forEach((o, i) => {
|
|
101854
|
+
if (o.tool !== name5) issues.push({ path: `${path4}.recorded[${i}].tool`, message: `a call to ${o.tool} recorded under ${name5}` });
|
|
101855
|
+
});
|
|
101856
|
+
}
|
|
101857
|
+
if (scene2.tools && Object.keys(scene2.tools).length) {
|
|
101858
|
+
scene2.checks.forEach((check3, i) => {
|
|
101859
|
+
if (!("trace" in check3)) return;
|
|
101860
|
+
for (const key3 of ["called", "not_called"]) {
|
|
101861
|
+
const patterns = check3.trace[key3] === void 0 ? [] : [].concat(check3.trace[key3]);
|
|
101862
|
+
patterns.forEach((pattern) => {
|
|
101863
|
+
const bare = /^([A-Za-z_][\w.-]{0,127})(?:\s+\{.*\})?$/s.exec(pattern.trim());
|
|
101864
|
+
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>"` });
|
|
101865
|
+
});
|
|
101866
|
+
}
|
|
101867
|
+
});
|
|
101868
|
+
}
|
|
101869
|
+
return issues;
|
|
101870
|
+
}
|
|
101791
101871
|
function refName5(ref20) {
|
|
101792
101872
|
try {
|
|
101793
101873
|
return parseRef(ref20).name;
|
|
@@ -102169,7 +102249,7 @@ function parseScene(input2) {
|
|
|
102169
102249
|
throw shapeError(parsed3.error.issues.flatMap((issue5) => fromZodIssue(issue5, [], input2)));
|
|
102170
102250
|
}
|
|
102171
102251
|
const scene2 = parsed3.data;
|
|
102172
|
-
const issues = [...twinIssues(scene2), ...validateRefs(scene2), ...ruleIssues(scene2), ...worldIssues(scene2), ...peopleIssues(scene2)];
|
|
102252
|
+
const issues = [...twinIssues(scene2), ...toolIssues(scene2), ...validateRefs(scene2), ...ruleIssues(scene2), ...worldIssues(scene2), ...peopleIssues(scene2)];
|
|
102173
102253
|
if (issues.length > 0) throw sceneError(issues);
|
|
102174
102254
|
const pd = scene2.seed.pagerduty;
|
|
102175
102255
|
if (pd && pd.default_service === void 0 && pd.services.length === 1) pd.default_service = `$${pd.services[0].ref}`;
|
|
@@ -102179,6 +102259,7 @@ function parseScene(input2) {
|
|
|
102179
102259
|
if (link5.from === "datadog" && link5.handle === void 0 && service) link5.handle = `pagerduty-${service.name}`;
|
|
102180
102260
|
if (link5.from === "pagerduty" && link5.channel === void 0 && service?.slack_channel !== void 0) link5.channel = service.slack_channel;
|
|
102181
102261
|
});
|
|
102262
|
+
if (scene2.task === void 0 && scene2.trigger?.task !== void 0) scene2.task = scene2.trigger.task;
|
|
102182
102263
|
return { ...scene2, twins: scene2.twins.filter(isTwinName), pass: scene2.pass ?? scene2.checks.map((c) => c.id) };
|
|
102183
102264
|
}
|
|
102184
102265
|
var ChecksSchema = external_exports.array(CheckSchema);
|
|
@@ -102198,6 +102279,54 @@ function parseChecks(input2) {
|
|
|
102198
102279
|
{ hint: "run `ancha scene schema` for the check format" }
|
|
102199
102280
|
);
|
|
102200
102281
|
}
|
|
102282
|
+
var PROSE_KEYS = /* @__PURE__ */ new Set(["judge", "task", "text", "value", "about", "message"]);
|
|
102283
|
+
var FIX_SHOWN = 120;
|
|
102284
|
+
function cutProseIssues(doc, text21, lineCounter) {
|
|
102285
|
+
const issues = [];
|
|
102286
|
+
(0, import_yaml.visit)(doc, {
|
|
102287
|
+
Pair(_, pair, ancestors2) {
|
|
102288
|
+
const value4 = pair.value;
|
|
102289
|
+
if (!(0, import_yaml.isScalar)(pair.key) || !PROSE_KEYS.has(String(pair.key.value)) || !(0, import_yaml.isScalar)(value4)) return;
|
|
102290
|
+
if (value4.type !== "PLAIN" || typeof value4.value !== "string" || !value4.range) return;
|
|
102291
|
+
const comment8 = /^[ \t]+#([^\r\n]*)/.exec(text21.slice(value4.range[1]));
|
|
102292
|
+
if (comment8 === null) return;
|
|
102293
|
+
const key3 = String(pair.key.value);
|
|
102294
|
+
const { line: line2 } = lineCounter.linePos(value4.range[0]);
|
|
102295
|
+
const meant = `${value4.value} #${comment8[1].trimEnd()}`;
|
|
102296
|
+
const fix = `${key3}: ${JSON.stringify(meant)}`;
|
|
102297
|
+
issues.push({
|
|
102298
|
+
path: `${pathOf(ancestors2, pair)} (line ${line2})`,
|
|
102299
|
+
message: `the text stops at " #": YAML reads ${JSON.stringify(`#${comment8[1].trimEnd()}`)} as a comment and keeps only ${JSON.stringify(value4.value)}`,
|
|
102300
|
+
hint: fix.length <= FIX_SHOWN ? `quote the text: ${fix}` : `quote the text, e.g. ${key3}: "\u2026", or write it as a block under ${key3}: |`
|
|
102301
|
+
});
|
|
102302
|
+
}
|
|
102303
|
+
});
|
|
102304
|
+
return issues;
|
|
102305
|
+
}
|
|
102306
|
+
function pathOf(ancestors2, pair) {
|
|
102307
|
+
const segments2 = [];
|
|
102308
|
+
ancestors2.forEach((node5, i) => {
|
|
102309
|
+
if ((0, import_yaml.isPair)(node5) && (0, import_yaml.isScalar)(node5.key)) segments2.push(String(node5.key.value));
|
|
102310
|
+
else if ((0, import_yaml.isSeq)(node5)) segments2.push(node5.items.indexOf(ancestors2[i + 1] ?? pair));
|
|
102311
|
+
});
|
|
102312
|
+
return formatPath([...segments2, String(pair.key.value)]);
|
|
102313
|
+
}
|
|
102314
|
+
function parseSceneYaml(text21) {
|
|
102315
|
+
const lineCounter = new import_yaml.LineCounter();
|
|
102316
|
+
const doc = (0, import_yaml.parseDocument)(text21, { lineCounter, prettyErrors: false });
|
|
102317
|
+
if (doc.errors.length > 0) {
|
|
102318
|
+
const issues = doc.errors.map((e) => {
|
|
102319
|
+
const { line: line2, col } = lineCounter.linePos(e.pos[0]);
|
|
102320
|
+
return { path: `line ${line2}, column ${col}`, message: e.message };
|
|
102321
|
+
});
|
|
102322
|
+
const atError = doc.errors.findIndex((e) => text21[e.pos[0]] === "@");
|
|
102323
|
+
if (atError >= 0) issues[atError].hint = "scene refs use $, e.g. $alice \u2014 YAML reserves @";
|
|
102324
|
+
throw sceneError(issues, doc.errors[0]);
|
|
102325
|
+
}
|
|
102326
|
+
const cut = cutProseIssues(doc, text21, lineCounter);
|
|
102327
|
+
if (cut.length > 0) throw sceneError(cut);
|
|
102328
|
+
return doc.toJS();
|
|
102329
|
+
}
|
|
102201
102330
|
|
|
102202
102331
|
// packages/core/src/harness-issues.ts
|
|
102203
102332
|
function collectHarnessIssues(trace, checks) {
|
|
@@ -102988,8 +103117,8 @@ function slackMcpServer(info, request) {
|
|
|
102988
103117
|
if (!service) throw new AnchaError("USAGE", "this sandbox does not include Slack");
|
|
102989
103118
|
const client = createVendorClient(info, "slack", "/api/", request);
|
|
102990
103119
|
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." });
|
|
102991
|
-
for (const [method2, description2,
|
|
102992
|
-
server.registerTool("slack_" + method2.replaceAll(".", "_"), { description: description2, inputSchema: external_exports.strictObject(
|
|
103120
|
+
for (const [method2, description2, shape4] of definitions) {
|
|
103121
|
+
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) => {
|
|
102993
103122
|
return client.result("POST", method2, args, context2.mcpReq.signal);
|
|
102994
103123
|
});
|
|
102995
103124
|
}
|
|
@@ -103112,9 +103241,9 @@ function safePath(path4, allowRoot = false) {
|
|
|
103112
103241
|
return allowRoot && path4 === "" || path4.length > 0 && !path4.includes("\\") && !path4.includes("\0") && path4.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
103113
103242
|
}
|
|
103114
103243
|
function registerGithubRepositoryTools(server, api3) {
|
|
103115
|
-
const invoke2 = async (method2, path4, body6, signal,
|
|
103244
|
+
const invoke2 = async (method2, path4, body6, signal, shape4) => {
|
|
103116
103245
|
const response5 = await api3.call(method2, path4, body6, signal);
|
|
103117
|
-
return mcpJsonResult(response5.isError ? response5.value :
|
|
103246
|
+
return mcpJsonResult(response5.isError ? response5.value : shape4(response5.value), response5.isError);
|
|
103118
103247
|
};
|
|
103119
103248
|
server.registerTool("list_commits", {
|
|
103120
103249
|
description: "List commits in a branch with native pagination.",
|
|
@@ -103613,8 +103742,34 @@ function datadogMcpServer(info, request) {
|
|
|
103613
103742
|
return server;
|
|
103614
103743
|
}
|
|
103615
103744
|
|
|
103745
|
+
// backend/src/mcp/agent-tools.ts
|
|
103746
|
+
function traced(schema) {
|
|
103747
|
+
return { "~standard": { version: 1, vendor: "ancha", validate: (value4) => ({ value: value4 }), jsonSchema: { input: () => schema, output: () => schema } } };
|
|
103748
|
+
}
|
|
103749
|
+
function callToolResult(answer) {
|
|
103750
|
+
if (answer.wrap === "mcp" && answer.raw && typeof answer.raw === "object") return answer.raw;
|
|
103751
|
+
if (answer.error !== void 0) return mcpTextResult(answer.error, true);
|
|
103752
|
+
return typeof answer.result === "string" ? mcpTextResult(answer.result) : mcpJsonResult(answer.result ?? null);
|
|
103753
|
+
}
|
|
103754
|
+
function agentToolsMcpServer(info, request) {
|
|
103755
|
+
if (!info.services.tools) throw new AnchaError("USAGE", "this world has no tools from a trace");
|
|
103756
|
+
const client = createVendorClient(info, "tools", "", request);
|
|
103757
|
+
const server = new McpServer({ name: "ancha-tools", version: "1.0.0" }, { instructions: "The agent's own tools, answered as production answered them." });
|
|
103758
|
+
for (const tool of info.tools ?? []) {
|
|
103759
|
+
server.registerTool(
|
|
103760
|
+
tool.name,
|
|
103761
|
+
{ ...tool.description && { description: tool.description }, inputSchema: traced(tool.schema ?? { type: "object" }) },
|
|
103762
|
+
async (args, context2) => {
|
|
103763
|
+
const { value: value4, isError } = await client.call("POST", `/tools/${encodeURIComponent(tool.name)}`, { args }, context2.mcpReq.signal);
|
|
103764
|
+
return isError && value4?.error && !("source" in value4) ? mcpJsonResult(value4, true) : callToolResult(value4);
|
|
103765
|
+
}
|
|
103766
|
+
);
|
|
103767
|
+
}
|
|
103768
|
+
return server;
|
|
103769
|
+
}
|
|
103770
|
+
|
|
103616
103771
|
// backend/src/mcp/http.ts
|
|
103617
|
-
var factories = { slack: slackMcpServer, github: githubMcpServer, pagerduty: pagerdutyMcpServer, datadog: datadogMcpServer };
|
|
103772
|
+
var factories = { slack: slackMcpServer, github: githubMcpServer, pagerduty: pagerdutyMcpServer, datadog: datadogMcpServer, tools: agentToolsMcpServer };
|
|
103618
103773
|
var names = { slack: SLACK_MCP_TOOL_NAMES, github: GITHUB_MCP_TOOL_NAMES, pagerduty: PAGERDUTY_MCP_TOOL_NAMES, datadog: DATADOG_MCP_TOOL_NAMES };
|
|
103619
103774
|
var mcpTwins = Object.fromEntries(Object.entries(factories).map(([tool, factory]) => [
|
|
103620
103775
|
tool,
|
|
@@ -103633,7 +103788,7 @@ var mcpTwins = Object.fromEntries(Object.entries(factories).map(([tool, factory]
|
|
|
103633
103788
|
onerror: () => {
|
|
103634
103789
|
}
|
|
103635
103790
|
});
|
|
103636
|
-
const known2 = new Set(names[tool]);
|
|
103791
|
+
const known2 = new Set(tool === "tools" ? (info.tools ?? []).map((t) => t.name) : names[tool]);
|
|
103637
103792
|
return {
|
|
103638
103793
|
close: () => handler.close(),
|
|
103639
103794
|
async fetch(input2) {
|
|
@@ -103968,6 +104123,7 @@ var TraceRecorder = class {
|
|
|
103968
104123
|
|
|
103969
104124
|
// packages/server/src/twin.ts
|
|
103970
104125
|
var GAP_HEADER = "x-ancha-gap";
|
|
104126
|
+
var SETUP_ISSUE_HEADER = "x-ancha-setup-issue";
|
|
103971
104127
|
var INTERNAL_ERROR_HEADER = "x-ancha-internal-error";
|
|
103972
104128
|
function gapMessage(c) {
|
|
103973
104129
|
return `ancha: not implemented: ${c.req.method} ${new URL(c.req.url).pathname}`;
|
|
@@ -104830,8 +104986,8 @@ function markHandled(env, ids2) {
|
|
|
104830
104986
|
var TABLE = "world_milestones";
|
|
104831
104987
|
var isPredicateMilestone2 = (milestone) => !("called" in milestone) && !("message" in milestone);
|
|
104832
104988
|
function milestoneKey(predicate) {
|
|
104833
|
-
const
|
|
104834
|
-
return JSON.stringify(
|
|
104989
|
+
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;
|
|
104990
|
+
return JSON.stringify(canonical5(predicate));
|
|
104835
104991
|
}
|
|
104836
104992
|
function tracked(env) {
|
|
104837
104993
|
const out = /* @__PURE__ */ new Map();
|
|
@@ -105328,7 +105484,28 @@ function evaluateWithin(env, within, calls2) {
|
|
|
105328
105484
|
|
|
105329
105485
|
// packages/server/src/checks.ts
|
|
105330
105486
|
var LIST_LIMIT = 10;
|
|
105331
|
-
var PATTERN_HINT =
|
|
105487
|
+
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}"`;
|
|
105488
|
+
function contains(have, want) {
|
|
105489
|
+
if (want === null || typeof want !== "object") return String(have) === String(want);
|
|
105490
|
+
if (Array.isArray(want)) return Array.isArray(have) && want.every((w, i) => contains(have[i], w));
|
|
105491
|
+
if (have === null || typeof have !== "object" || Array.isArray(have)) return false;
|
|
105492
|
+
return Object.entries(want).every(([k, w]) => contains(have[k], w));
|
|
105493
|
+
}
|
|
105494
|
+
function toolPattern(pattern, tools) {
|
|
105495
|
+
const m = /^([A-Za-z_][\w.-]{0,127})(?:\s+(\{.*\}))?$/s.exec(pattern);
|
|
105496
|
+
if (!m || !tools?.has(m[1])) return void 0;
|
|
105497
|
+
let args;
|
|
105498
|
+
if (m[2] !== void 0) {
|
|
105499
|
+
try {
|
|
105500
|
+
args = parseSceneYaml(m[2]);
|
|
105501
|
+
} catch {
|
|
105502
|
+
args = void 0;
|
|
105503
|
+
}
|
|
105504
|
+
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 });
|
|
105505
|
+
}
|
|
105506
|
+
const path4 = `/tools/${m[1]}`;
|
|
105507
|
+
return (e) => e.source === "agent" && e.service === "tools" && e.method === "POST" && e.path === path4 && (args === void 0 || contains(e.request?.args, args));
|
|
105508
|
+
}
|
|
105332
105509
|
function glob(pattern, caseInsensitive) {
|
|
105333
105510
|
const fold2 = (s) => caseInsensitive ? s.toLowerCase() : s;
|
|
105334
105511
|
const pieces = fold2(pattern).split("*");
|
|
@@ -105349,9 +105526,11 @@ function glob(pattern, caseInsensitive) {
|
|
|
105349
105526
|
return true;
|
|
105350
105527
|
};
|
|
105351
105528
|
}
|
|
105352
|
-
function compileTracePattern(p2) {
|
|
105529
|
+
function compileTracePattern(p2, tools) {
|
|
105353
105530
|
const pattern = p2.trim();
|
|
105354
105531
|
if (pattern === "*") return (e) => e.source === "agent";
|
|
105532
|
+
const tool = toolPattern(pattern, tools);
|
|
105533
|
+
if (tool) return tool;
|
|
105355
105534
|
const parts3 = /^(\S+)\s+(\S+)$/.exec(pattern);
|
|
105356
105535
|
if (!parts3) {
|
|
105357
105536
|
throw new AnchaError("USAGE", `invalid trace pattern "${p2}": expected "<METHOD> <PATH>" or "*"`, { hint: PATTERN_HINT });
|
|
@@ -105379,12 +105558,13 @@ function failure2(e) {
|
|
|
105379
105558
|
if (typeof body6 !== "object" || body6 === null) return void 0;
|
|
105380
105559
|
const r = body6;
|
|
105381
105560
|
if (e.service === "slack" && r.ok === false) return `ok: false${typeof r.error === "string" ? `, ${r.error}` : ""}`;
|
|
105561
|
+
if (e.service === "tools" && typeof r.error === "string") return `the tool's error: ${r.error}`;
|
|
105382
105562
|
if (/\/graphql$/.test(e.path) && Array.isArray(r.errors) && r.errors.length > 0 && (r.data === void 0 || r.data === null)) return "GraphQL errors";
|
|
105383
105563
|
return void 0;
|
|
105384
105564
|
}
|
|
105385
|
-
function calledPart(patterns, calls2, anyStatus) {
|
|
105565
|
+
function calledPart(patterns, calls2, anyStatus, tools) {
|
|
105386
105566
|
const hits = patterns.map((p2) => {
|
|
105387
|
-
const attempts = calls2.filter(compileTracePattern(p2));
|
|
105567
|
+
const attempts = calls2.filter(compileTracePattern(p2, tools));
|
|
105388
105568
|
return { p: p2, attempts, worked: anyStatus ? attempts : attempts.filter((e) => failure2(e) === void 0) };
|
|
105389
105569
|
});
|
|
105390
105570
|
const missing4 = hits.filter((h) => h.worked.length === 0);
|
|
@@ -105410,8 +105590,8 @@ function calledPart(patterns, calls2, anyStatus) {
|
|
|
105410
105590
|
].join(" ");
|
|
105411
105591
|
return { passed: false, expected, actual, explanation, evidence: unique2([...matched, ...failed.flatMap((h) => h.attempts)]) };
|
|
105412
105592
|
}
|
|
105413
|
-
function notCalledPart(patterns, calls2) {
|
|
105414
|
-
const matchers = patterns.map(compileTracePattern);
|
|
105593
|
+
function notCalledPart(patterns, calls2, tools) {
|
|
105594
|
+
const matchers = patterns.map((p2) => compileTracePattern(p2, tools));
|
|
105415
105595
|
const offenders = calls2.filter((c) => matchers.some((m) => m(c)));
|
|
105416
105596
|
const expected = `agent never calls ${patterns.join(" or ")}`;
|
|
105417
105597
|
if (offenders.length === 0) {
|
|
@@ -105432,13 +105612,13 @@ function notCalledPart(patterns, calls2) {
|
|
|
105432
105612
|
evidence: offenders
|
|
105433
105613
|
};
|
|
105434
105614
|
}
|
|
105435
|
-
function evaluateTrace(trace, calls2) {
|
|
105615
|
+
function evaluateTrace(trace, calls2, tools) {
|
|
105436
105616
|
const called = asList(trace.called);
|
|
105437
105617
|
const notCalled = asList(trace.not_called);
|
|
105438
105618
|
if (called.length === 0 && notCalled.length === 0) {
|
|
105439
105619
|
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" }' });
|
|
105440
105620
|
}
|
|
105441
|
-
const parts3 = [...called.length > 0 ? [calledPart(called, calls2, trace.status === "any")] : [], ...notCalled.length > 0 ? [notCalledPart(notCalled, calls2)] : []];
|
|
105621
|
+
const parts3 = [...called.length > 0 ? [calledPart(called, calls2, trace.status === "any", tools)] : [], ...notCalled.length > 0 ? [notCalledPart(notCalled, calls2, tools)] : []];
|
|
105442
105622
|
return {
|
|
105443
105623
|
passed: parts3.every((p2) => p2.passed),
|
|
105444
105624
|
expected: parts3.map((p2) => p2.expected).join("; "),
|
|
@@ -105508,10 +105688,11 @@ function evaluateProcess(env, check3, calls2) {
|
|
|
105508
105688
|
if ("decided" in check3) return inspectPeoplePredicate(env, { decided: check3.decided }, atMs);
|
|
105509
105689
|
if ("message" in check3) return evaluateMessageCheck(env, check3.message);
|
|
105510
105690
|
if ("never" in check3) return evaluateNever(env, check3.never);
|
|
105511
|
-
const agent = { first: (pattern) => calls2().find(compileTracePattern(pattern)) };
|
|
105691
|
+
const agent = { first: (pattern) => calls2().find(compileTracePattern(pattern, sceneTools(env))) };
|
|
105512
105692
|
if ("before" in check3) return evaluateBefore(env, check3.before, agent);
|
|
105513
105693
|
return evaluateWithin(env, check3.within, agent);
|
|
105514
105694
|
}
|
|
105695
|
+
var sceneTools = (env) => new Set(Object.keys(env.scene.tools ?? {}));
|
|
105515
105696
|
function errored(label5, e) {
|
|
105516
105697
|
const message5 = e instanceof Error ? e.message : String(e);
|
|
105517
105698
|
const hint = e instanceof AnchaError ? e.hint : void 0;
|
|
@@ -105541,7 +105722,7 @@ function evaluateChecks(env, checks = env.scene.checks) {
|
|
|
105541
105722
|
let outcome3;
|
|
105542
105723
|
let error63;
|
|
105543
105724
|
try {
|
|
105544
|
-
outcome3 = "state" in check3 ? evaluateState(env, check3.state) : "trace" in check3 ? evaluateTrace(check3.trace, agentCalls2()) : evaluateProcess(env, check3, agentCalls2);
|
|
105725
|
+
outcome3 = "state" in check3 ? evaluateState(env, check3.state) : "trace" in check3 ? evaluateTrace(check3.trace, agentCalls2(), sceneTools(env)) : evaluateProcess(env, check3, agentCalls2);
|
|
105545
105726
|
} catch (e) {
|
|
105546
105727
|
error63 = e instanceof Error ? e.message : String(e);
|
|
105547
105728
|
outcome3 = errored("state" in check3 ? Object.keys(check3.state).join(", ") || "state" : checkKind(check3), e);
|
|
@@ -108355,12 +108536,12 @@ function persistMessageLinks(ctx, row, links2 = []) {
|
|
|
108355
108536
|
ctx.store.db.prepare("INSERT INTO slack_message_links VALUES (?, ?, ?, ?, ?)").run(row.channel_id, row.ts, link5.pointer, link5.service, link5.path);
|
|
108356
108537
|
}
|
|
108357
108538
|
}
|
|
108358
|
-
function materializeMessageLinks(ctx, row,
|
|
108539
|
+
function materializeMessageLinks(ctx, row, shape4) {
|
|
108359
108540
|
if (!ctx.serviceUrls) return;
|
|
108360
108541
|
for (const link5 of messageLinks(ctx, row)) {
|
|
108361
108542
|
const root2 = ctx.serviceUrls[link5.service];
|
|
108362
108543
|
if (!root2) throw new AnchaError("INTERNAL", `Missing local ${link5.service} service for Slack message link`);
|
|
108363
|
-
replaceLink(
|
|
108544
|
+
replaceLink(shape4, link5, root2.replace(/\/$/, "") + link5.path);
|
|
108364
108545
|
}
|
|
108365
108546
|
}
|
|
108366
108547
|
|
|
@@ -111171,13 +111352,13 @@ function batch(ctx, type, operation, raw3, url3) {
|
|
|
111171
111352
|
return { status: 204 };
|
|
111172
111353
|
});
|
|
111173
111354
|
}
|
|
111174
|
-
const traceIds = items.map((item2) => item2.objectWriteTraceId),
|
|
111175
|
-
if (
|
|
111355
|
+
const traceIds = items.map((item2) => item2.objectWriteTraceId), traced3 = operation === "create" && traceIds.some((value4) => value4 !== void 0);
|
|
111356
|
+
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.");
|
|
111176
111357
|
const execute3 = (item2) => {
|
|
111177
111358
|
bodyObject2(item2, operation === "create" ? ["properties", "associations", "objectWriteTraceId"] : ["id", "properties"]);
|
|
111178
111359
|
return project3(ctx, type, operation === "create" ? createRecord(ctx, type, item2) : updateRecord(ctx, type, identifier(item2.id), { properties: item2.properties }));
|
|
111179
111360
|
};
|
|
111180
|
-
if (
|
|
111361
|
+
if (traced3) return withMutation(ctx, () => {
|
|
111181
111362
|
const results = [], errors2 = [];
|
|
111182
111363
|
let gap5 = false;
|
|
111183
111364
|
for (const item2 of items) {
|
|
@@ -114432,7 +114613,7 @@ function explainFailedChecks(env, results, checks = env.scene.checks) {
|
|
|
114432
114613
|
if (!failed.length) return [];
|
|
114433
114614
|
const messages = attemptMessages(env);
|
|
114434
114615
|
const agentCalls2 = env.trace.list().filter((entry2) => entry2.source === "agent");
|
|
114435
|
-
const calls2 = { first: (pattern) => agentCalls2.find(compileTracePattern(pattern)) };
|
|
114616
|
+
const calls2 = { first: (pattern) => agentCalls2.find(compileTracePattern(pattern, sceneTools(env))) };
|
|
114436
114617
|
const start = env.clock.startTime.getTime();
|
|
114437
114618
|
return failed.flatMap((result) => {
|
|
114438
114619
|
const check3 = checks.find((candidate) => candidate.id === result.id);
|
|
@@ -114570,7 +114751,234 @@ function readWorldSnapshot(bytes2) {
|
|
|
114570
114751
|
}
|
|
114571
114752
|
}
|
|
114572
114753
|
|
|
114754
|
+
// packages/server/src/agent-tools/simulate.ts
|
|
114755
|
+
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 and with the writes the agent already made in this test, 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>"}.`;
|
|
114756
|
+
var SCHEMA5 = { name: "tool_answer", schema: { type: "object", additionalProperties: false, properties: { result_json: { type: "string" }, error: { type: "string" } } } };
|
|
114757
|
+
function shape(value4) {
|
|
114758
|
+
if (Array.isArray(value4)) return `[${value4.length ? shape(value4[0]) : ""}]`;
|
|
114759
|
+
if (value4 === null || typeof value4 !== "object") return value4 === null ? "null" : typeof value4;
|
|
114760
|
+
return `{${Object.keys(value4).sort().map((k) => `${k}:${value4[k] === null ? "null" : Array.isArray(value4[k]) ? "list" : typeof value4[k]}`).join(",")}}`;
|
|
114761
|
+
}
|
|
114762
|
+
function sameShape(result, recorded2) {
|
|
114763
|
+
if (!recorded2.length) return true;
|
|
114764
|
+
const top = (v) => Array.isArray(v) ? "list" : v === null ? "null" : typeof v;
|
|
114765
|
+
if (!recorded2.some((r) => top(r) === top(result) || top(r) === "null")) return false;
|
|
114766
|
+
const objects = recorded2.filter((r) => r !== null && typeof r === "object" && !Array.isArray(r));
|
|
114767
|
+
if (!objects.length || result === null || typeof result !== "object" || Array.isArray(result)) return true;
|
|
114768
|
+
const got = result;
|
|
114769
|
+
const always = Object.keys(objects[0]).filter((k) => objects.every((o) => k in o));
|
|
114770
|
+
const types = /* @__PURE__ */ new Map();
|
|
114771
|
+
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)));
|
|
114772
|
+
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))));
|
|
114773
|
+
}
|
|
114774
|
+
async function simulate(model, request, signal) {
|
|
114775
|
+
const recorded2 = (request.tool?.recorded ?? []).map((o) => ({ args: o.args, at: o.at, ...o.error !== void 0 ? { error: o.error } : { result: o.result } }));
|
|
114776
|
+
const results = recorded2.filter((o) => "result" in o).map((o) => o.result);
|
|
114777
|
+
const user8 = JSON.stringify({
|
|
114778
|
+
tool: { name: request.name, ...request.tool?.description && { description: request.tool.description }, ...request.tool?.schema && { arguments: request.tool.schema }, ...request.tool?.write && { changes_something: true } },
|
|
114779
|
+
production_recorded: recorded2.slice(-20),
|
|
114780
|
+
...request.tool?.examples?.length && { other_production_runs_of_this_agent: request.tool.examples.slice(-30) },
|
|
114781
|
+
...results.length && { result_shape: shape(results[0]) },
|
|
114782
|
+
writes_in_this_test: request.writes.slice(-20),
|
|
114783
|
+
call: { arguments: request.args, ...request.repeat && { production_made_this_exact_call: request.repeat.recorded, this_is_call_number: request.repeat.call } },
|
|
114784
|
+
// Time moves on as the agent waits: a status read later may say what a real one would say by then.
|
|
114785
|
+
...request.time && { time: {
|
|
114786
|
+
...request.time.start && { now: new Date(Date.parse(request.time.start) + request.time.now_ms).toISOString() },
|
|
114787
|
+
...request.time.now_ms > request.time.last_recorded_ms && { seconds_since_productions_last_answer: Math.round((request.time.now_ms - request.time.last_recorded_ms) / 1e3) }
|
|
114788
|
+
} }
|
|
114789
|
+
});
|
|
114790
|
+
let inputTokens = 0, outputTokens = 0, costUsd = 0, model_, feedback = "";
|
|
114791
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
114792
|
+
const answer = await model.complete({ kind: "simulate", person: request.name, system: SYSTEM, user: feedback ? `${user8}
|
|
114793
|
+
|
|
114794
|
+
${feedback}` : user8, schema: SCHEMA5, temperature: 0, maxTokens: 1200 }, signal);
|
|
114795
|
+
inputTokens += answer.inputTokens;
|
|
114796
|
+
outputTokens += answer.outputTokens;
|
|
114797
|
+
costUsd += answer.costUsd;
|
|
114798
|
+
model_ = answer.model;
|
|
114799
|
+
const out = answer.output;
|
|
114800
|
+
if (typeof out?.error === "string" && out.error && out.result_json === void 0) return { error: out.error, inputTokens, outputTokens, costUsd, model: model_ };
|
|
114801
|
+
let result;
|
|
114802
|
+
try {
|
|
114803
|
+
result = JSON.parse(String(out?.result_json));
|
|
114804
|
+
} catch {
|
|
114805
|
+
feedback = "Your result_json was not valid JSON. Answer again.";
|
|
114806
|
+
continue;
|
|
114807
|
+
}
|
|
114808
|
+
if (sameShape(result, results)) return { result, inputTokens, outputTokens, costUsd, model: model_ };
|
|
114809
|
+
feedback = `Your result has the shape ${shape(result)}, but production's results have the shape ${shape(results[0])}. Answer again in that shape.`;
|
|
114810
|
+
}
|
|
114811
|
+
throw new PeopleModelError(`the simulated answer to ${request.name} did not have the shape of production's results`);
|
|
114812
|
+
}
|
|
114813
|
+
|
|
114814
|
+
// packages/server/src/agent-tools/index.ts
|
|
114815
|
+
var AGENT_TOOLS = "tools";
|
|
114816
|
+
function canonical2(value4) {
|
|
114817
|
+
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);
|
|
114818
|
+
}
|
|
114819
|
+
var recordedOf = /* @__PURE__ */ new WeakMap();
|
|
114820
|
+
function recorded(ctx, tool) {
|
|
114821
|
+
const tools = ctx.scene.tools ?? {};
|
|
114822
|
+
let byTool = recordedOf.get(tools);
|
|
114823
|
+
if (!byTool) {
|
|
114824
|
+
byTool = new Map(Object.entries(tools).map(([name5, t]) => [name5, (t.recorded ?? []).map((o) => {
|
|
114825
|
+
const atMs = parseDuration(o.at);
|
|
114826
|
+
return { ...o, atMs, endMs: o.end ? parseDuration(o.end) : atMs, key: canonical2(o.args) };
|
|
114827
|
+
}).sort((a, b) => a.atMs - b.atMs)]));
|
|
114828
|
+
recordedOf.set(tools, byTool);
|
|
114829
|
+
}
|
|
114830
|
+
return byTool.get(tool) ?? [];
|
|
114831
|
+
}
|
|
114832
|
+
function migrate6(db2) {
|
|
114833
|
+
db2.exec(`CREATE TABLE agent_tool_calls (key TEXT PRIMARY KEY, n INTEGER NOT NULL);
|
|
114834
|
+
CREATE TABLE agent_tool_state (k TEXT PRIMARY KEY, v TEXT NOT NULL);`);
|
|
114835
|
+
}
|
|
114836
|
+
var getState = (ctx, k) => ctx.store.db.prepare("SELECT v FROM agent_tool_state WHERE k=?").get(k)?.v;
|
|
114837
|
+
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);
|
|
114838
|
+
var SIMULATION_LIMIT = () => Number(process.env.ANCHA_SIMULATE_MAX ?? 30);
|
|
114839
|
+
var simulationOn = (ctx) => process.env.ANCHA_SIMULATE !== "0" && ctx.model !== void 0;
|
|
114840
|
+
function keepUp(ctx) {
|
|
114841
|
+
const behind = withRead(ctx, () => Number(getState(ctx, "reached") ?? 0)) - ctx.clock.elapsedMs();
|
|
114842
|
+
if (behind > 0) ctx.clock.advance(behind);
|
|
114843
|
+
}
|
|
114844
|
+
function decide(ctx, name5, args) {
|
|
114845
|
+
const tool = ctx.scene.tools?.[name5];
|
|
114846
|
+
const key3 = canonical2(args), callKey = `${name5} ${key3}`;
|
|
114847
|
+
const same2 = recorded(ctx, name5).filter((o) => o.key === key3);
|
|
114848
|
+
const n = ctx.store.db.prepare("SELECT n FROM agent_tool_calls WHERE key=?").get(callKey)?.n ?? 0;
|
|
114849
|
+
ctx.store.db.prepare("INSERT INTO agent_tool_calls (key, n) VALUES (?, 1) ON CONFLICT(key) DO UPDATE SET n=n+1").run(callKey);
|
|
114850
|
+
const policy = tool?.unrecorded ?? (tool?.write ? "fail" : "simulate");
|
|
114851
|
+
const reached = Number(getState(ctx, "reached") ?? 0);
|
|
114852
|
+
const cached2 = getState(ctx, `sim:${callKey}`);
|
|
114853
|
+
if (cached2 !== void 0) {
|
|
114854
|
+
const hit = JSON.parse(cached2);
|
|
114855
|
+
if (tool?.write || hit.reached >= reached) return hit.answer;
|
|
114856
|
+
}
|
|
114857
|
+
if (n < same2.length) {
|
|
114858
|
+
let index = n;
|
|
114859
|
+
for (let i = same2.length - 1; i > index; i--) if (same2[i].atMs <= reached) {
|
|
114860
|
+
index = i;
|
|
114861
|
+
break;
|
|
114862
|
+
}
|
|
114863
|
+
const o = same2[index];
|
|
114864
|
+
setState(ctx, "reached", String(Math.max(reached, o.endMs)));
|
|
114865
|
+
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 } };
|
|
114866
|
+
}
|
|
114867
|
+
if (tool?.twin !== void 0 || policy === "twin") return { source: "twin", passthrough: true };
|
|
114868
|
+
const repeat = same2.length ? { recorded: same2.length, call: n + 1 } : void 0;
|
|
114869
|
+
const last = same2.at(-1) ?? recorded(ctx, name5).at(-1), took = last ? last.endMs - last.atMs : 0;
|
|
114870
|
+
if (policy === "simulate" && simulationOn(ctx)) {
|
|
114871
|
+
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` };
|
|
114872
|
+
const lastRecordedMs = Math.max(0, ...recorded(ctx, name5).map((o) => o.endMs));
|
|
114873
|
+
return { simulate: { name: name5, tool, args, ...repeat && { repeat }, time: { now_ms: Math.max(reached, ctx.clock.elapsedMs()), last_recorded_ms: lastRecordedMs, start: ctx.scene.start_time } }, cacheKey: callKey, reached, took };
|
|
114874
|
+
}
|
|
114875
|
+
if (repeat && !tool?.write) {
|
|
114876
|
+
const o = same2.at(-1);
|
|
114877
|
+
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 } };
|
|
114878
|
+
}
|
|
114879
|
+
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`;
|
|
114880
|
+
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)" : "";
|
|
114881
|
+
return { source: "failed", error: `Ancha has no recorded answer for this call: ${why}${unsimulated}` };
|
|
114882
|
+
}
|
|
114883
|
+
function noteWrite(ctx, name5, args, a) {
|
|
114884
|
+
if (!ctx.scene.tools?.[name5]?.write || a.passthrough) return;
|
|
114885
|
+
const writes2 = JSON.parse(getState(ctx, "writes") ?? "[]");
|
|
114886
|
+
writes2.push({ tool: name5, args, ...a.error !== void 0 ? { error: a.error } : { result: a.result } });
|
|
114887
|
+
setState(ctx, "writes", JSON.stringify(writes2.slice(-50)));
|
|
114888
|
+
}
|
|
114889
|
+
function toolsToWrap(ctx) {
|
|
114890
|
+
return Object.entries(ctx.scene.tools ?? {}).filter(([, t]) => t.twin === void 0 && !t.mcp && !t.allow_unwrapped).map(([name5]) => name5).sort();
|
|
114891
|
+
}
|
|
114892
|
+
function registration(ctx, names3) {
|
|
114893
|
+
const before = JSON.parse(getState(ctx, "wrapped") ?? "[]");
|
|
114894
|
+
const wrapped = [.../* @__PURE__ */ new Set([...before, ...names3])].sort();
|
|
114895
|
+
setState(ctx, "wrapped", JSON.stringify(wrapped));
|
|
114896
|
+
return { wrapped, missing: toolsToWrap(ctx).filter((name5) => !wrapped.includes(name5)) };
|
|
114897
|
+
}
|
|
114898
|
+
function unwrappedMessage(missing4, noneWrapped = false) {
|
|
114899
|
+
const [first] = missing4, it = missing4.length === 1 ? "it" : "them";
|
|
114900
|
+
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." : "");
|
|
114901
|
+
}
|
|
114902
|
+
function authorized(c) {
|
|
114903
|
+
const token2 = JSON.parse(c.env.ctx.store.meta.get(`credentials:${AGENT_TOOLS}`) ?? "{}").token;
|
|
114904
|
+
return token2 !== void 0 && c.req.header("authorization") === `Bearer ${token2}`;
|
|
114905
|
+
}
|
|
114906
|
+
function agentToolsService() {
|
|
114907
|
+
const app2 = new Hono3();
|
|
114908
|
+
app2.use("*", async (c, next2) => authorized(c) ? next2() : c.json({ error: "send Authorization: Bearer $ANCHA_TOOLS_TOKEN" }, 401));
|
|
114909
|
+
app2.get("/tools", (c) => withRead(c.env.ctx, () => c.json({ tools: Object.entries(c.env.ctx.scene.tools ?? {}).map(([name5, t]) => ({
|
|
114910
|
+
name: name5,
|
|
114911
|
+
...t.description && { description: t.description },
|
|
114912
|
+
...t.schema && { schema: t.schema },
|
|
114913
|
+
recorded: t.recorded?.length ?? 0,
|
|
114914
|
+
...t.twin && { twin: t.twin },
|
|
114915
|
+
...t.write && { write: true }
|
|
114916
|
+
})), wrap: toolsToWrap(c.env.ctx) })));
|
|
114917
|
+
app2.post("/register", async (c) => {
|
|
114918
|
+
const body6 = await c.req.json().catch(() => ({}));
|
|
114919
|
+
const names3 = (Array.isArray(body6.tools) ? body6.tools : []).map((t) => typeof t === "string" ? t : t?.name).filter((n) => typeof n === "string");
|
|
114920
|
+
const { wrapped, missing: missing4 } = withMutation(c.env.ctx, () => registration(c.env.ctx, names3));
|
|
114921
|
+
if (body6.complete) withMutation(c.env.ctx, () => setState(c.env.ctx, "checked", "1"));
|
|
114922
|
+
if (body6.complete && missing4.length) return c.json({ error: unwrappedMessage(missing4, wrapped.length === 0), wrapped, missing: missing4, stop: true }, 409, { [SETUP_ISSUE_HEADER]: "1" });
|
|
114923
|
+
return c.json({ wrapped, missing: missing4 });
|
|
114924
|
+
});
|
|
114925
|
+
app2.post("/tools/:name", async (c) => {
|
|
114926
|
+
const name5 = c.req.param("name");
|
|
114927
|
+
const body6 = await c.req.json().catch(() => ({}));
|
|
114928
|
+
const stop = withMutation(c.env.ctx, () => {
|
|
114929
|
+
if (getState(c.env.ctx, "checked")) return void 0;
|
|
114930
|
+
setState(c.env.ctx, "checked", "1");
|
|
114931
|
+
const { wrapped, missing: missing4 } = registration(c.env.ctx, []);
|
|
114932
|
+
return missing4.length ? { error: unwrappedMessage(missing4, wrapped.length === 0), wrapped, missing: missing4, stop: true } : void 0;
|
|
114933
|
+
});
|
|
114934
|
+
if (stop) return c.json(stop, 409, { [SETUP_ISSUE_HEADER]: "1" });
|
|
114935
|
+
const ctx = c.env.ctx, args = body6.args ?? {};
|
|
114936
|
+
const decision2 = withMutation(ctx, () => decide(ctx, name5, args));
|
|
114937
|
+
if (!("simulate" in decision2)) {
|
|
114938
|
+
withMutation(ctx, () => noteWrite(ctx, name5, args, decision2));
|
|
114939
|
+
keepUp(ctx);
|
|
114940
|
+
return c.json(decision2);
|
|
114941
|
+
}
|
|
114942
|
+
let answered;
|
|
114943
|
+
try {
|
|
114944
|
+
const writes2 = withRead(ctx, () => JSON.parse(getState(ctx, "writes") ?? "[]"));
|
|
114945
|
+
const sim = await simulate(ctx.model, { ...decision2.simulate, writes: writes2 }, c.req.raw.signal);
|
|
114946
|
+
answered = { source: "simulated", ...sim.error !== void 0 ? { error: sim.error } : { result: sim.result }, cost_usd: Math.round(sim.costUsd * 1e6) / 1e6 };
|
|
114947
|
+
} catch (error63) {
|
|
114948
|
+
answered = { source: "failed", error: `Ancha has no recorded answer for this call and could not simulate one: ${error63 instanceof Error ? error63.message : String(error63)}` };
|
|
114949
|
+
}
|
|
114950
|
+
const answer = withMutation(ctx, () => {
|
|
114951
|
+
if (answered.source === "simulated") {
|
|
114952
|
+
const now10 = Math.max(Number(getState(ctx, "reached") ?? 0), decision2.reached + decision2.took);
|
|
114953
|
+
setState(ctx, "reached", String(now10));
|
|
114954
|
+
setState(ctx, `sim:${decision2.cacheKey}`, JSON.stringify({ answer: { ...answered, cost_usd: void 0 }, reached: now10 }));
|
|
114955
|
+
setState(ctx, "simulated", String(Number(getState(ctx, "simulated") ?? 0) + 1));
|
|
114956
|
+
}
|
|
114957
|
+
noteWrite(ctx, name5, args, answered);
|
|
114958
|
+
return answered;
|
|
114959
|
+
});
|
|
114960
|
+
keepUp(ctx);
|
|
114961
|
+
return c.json(answer);
|
|
114962
|
+
});
|
|
114963
|
+
app2.all("*", (c) => c.json({ error: `not a route of Ancha's tool service: ${c.req.method} ${new URL(c.req.url).pathname}` }, 404));
|
|
114964
|
+
return {
|
|
114965
|
+
// A built-in service, not a catalog twin: a scene gets it by having tools.
|
|
114966
|
+
name: AGENT_TOOLS,
|
|
114967
|
+
basePath: "",
|
|
114968
|
+
app: app2,
|
|
114969
|
+
migrate: migrate6,
|
|
114970
|
+
seed() {
|
|
114971
|
+
},
|
|
114972
|
+
credentials: (ctx) => ({ token: `ancha-tools-${ctx.secrets.hex(32)}` }),
|
|
114973
|
+
actions: {},
|
|
114974
|
+
checks: {},
|
|
114975
|
+
dumpState: (ctx) => ({ calls: ctx.store.db.prepare("SELECT key, n FROM agent_tool_calls ORDER BY key").all(), wrapped: JSON.parse(getState(ctx, "wrapped") ?? "[]") }),
|
|
114976
|
+
coverage: []
|
|
114977
|
+
};
|
|
114978
|
+
}
|
|
114979
|
+
|
|
114573
114980
|
// packages/server/src/env.ts
|
|
114981
|
+
var agentTools = agentToolsService();
|
|
114574
114982
|
var ENV_ID_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
114575
114983
|
function newEnvId() {
|
|
114576
114984
|
let id12 = "";
|
|
@@ -114664,7 +115072,8 @@ var Environment = class _Environment {
|
|
|
114664
115072
|
}
|
|
114665
115073
|
return twin;
|
|
114666
115074
|
});
|
|
114667
|
-
|
|
115075
|
+
if (Object.keys(scene2.tools ?? {}).length) this.twins.push(agentTools);
|
|
115076
|
+
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")])));
|
|
114668
115077
|
const realNow = opts.realNow ?? (() => Date.now());
|
|
114669
115078
|
this.#realNow = realNow;
|
|
114670
115079
|
let frozenRealNow = realNow();
|
|
@@ -114721,7 +115130,8 @@ var Environment = class _Environment {
|
|
|
114721
115130
|
trace: this.trace,
|
|
114722
115131
|
events: this.events,
|
|
114723
115132
|
enqueueJob: (job) => this.scheduler.enqueue(job),
|
|
114724
|
-
world: this.world
|
|
115133
|
+
world: this.world,
|
|
115134
|
+
...this.peopleModel && { model: this.peopleModel }
|
|
114725
115135
|
};
|
|
114726
115136
|
this.#contexts.set(twin, ctx);
|
|
114727
115137
|
}
|
|
@@ -115252,7 +115662,7 @@ var FILE_KEYS2 = ["version", "id", "owner", "sceneId", "createdAt", "expiresAt",
|
|
|
115252
115662
|
|
|
115253
115663
|
// packages/server/src/twins/google-ads/db.ts
|
|
115254
115664
|
var collections = { budgets: "campaignBudgets", campaigns: "campaigns", adGroups: "adGroups", ads: "adGroupAds", criteria: "adGroupCriteria" };
|
|
115255
|
-
function
|
|
115665
|
+
function migrate7(db2) {
|
|
115256
115666
|
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)");
|
|
115257
115667
|
}
|
|
115258
115668
|
function config3(ctx) {
|
|
@@ -116219,11 +116629,11 @@ function googleAdsTwin() {
|
|
|
116219
116629
|
throw e;
|
|
116220
116630
|
}
|
|
116221
116631
|
});
|
|
116222
|
-
return { name: "google-ads", basePath: "", unprefixedPaths: /^\/v\d+\/customers[/:]/, app: app2, migrate:
|
|
116632
|
+
return { name: "google-ads", basePath: "", unprefixedPaths: /^\/v\d+\/customers[/:]/, app: app2, migrate: migrate7, seed: seed4, credentials: credentials3, actions: {}, checks: {}, dumpState: dumpState2, coverage: googleAdsCoverage };
|
|
116223
116633
|
}
|
|
116224
116634
|
|
|
116225
116635
|
// packages/server/src/twins/chatgpt-ads/db.ts
|
|
116226
|
-
function
|
|
116636
|
+
function migrate8(db2) {
|
|
116227
116637
|
db2.exec(`CREATE TABLE chatgpt_ads_data(id INTEGER PRIMARY KEY CHECK(id=1),json TEXT NOT NULL);
|
|
116228
116638
|
CREATE TABLE chatgpt_ads_credentials(principal_id TEXT PRIMARY KEY,token TEXT NOT NULL UNIQUE);
|
|
116229
116639
|
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));
|
|
@@ -116438,9 +116848,9 @@ function pagination(rows7, query10, defaultLimit = 20, max = 500) {
|
|
|
116438
116848
|
const selected2 = rows7.slice(start, Math.min(start + limit, end));
|
|
116439
116849
|
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 };
|
|
116440
116850
|
}
|
|
116441
|
-
function
|
|
116442
|
-
if (Array.isArray(value4)) return `[${value4.map(
|
|
116443
|
-
if (value4 && typeof value4 === "object") return `{${Object.entries(value4).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${JSON.stringify(k)}:${
|
|
116851
|
+
function canonical3(value4) {
|
|
116852
|
+
if (Array.isArray(value4)) return `[${value4.map(canonical3).join(",")}]`;
|
|
116853
|
+
if (value4 && typeof value4 === "object") return `{${Object.entries(value4).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${JSON.stringify(k)}:${canonical3(v)}`).join(",")}}`;
|
|
116444
116854
|
return JSON.stringify(value4);
|
|
116445
116855
|
}
|
|
116446
116856
|
function idempotency(c, access2, kind, body6) {
|
|
@@ -116448,7 +116858,7 @@ function idempotency(c, access2, kind, body6) {
|
|
|
116448
116858
|
if (key3 === void 0) return { existing: void 0, remember: (_id) => {
|
|
116449
116859
|
} };
|
|
116450
116860
|
if (key3.length > 255 || !key3.trim()) invalid6("Idempotency-Key requires 1\u2013255 characters and non-whitespace");
|
|
116451
|
-
const fingerprint = createHash13("sha256").update(
|
|
116861
|
+
const fingerprint = createHash13("sha256").update(canonical3(body6)).digest("hex");
|
|
116452
116862
|
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);
|
|
116453
116863
|
if (prior && prior.fingerprint !== fingerprint) throw new AdsError2(409, "Idempotency-Key was used with different input", "idempotency_conflict");
|
|
116454
116864
|
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) };
|
|
@@ -116732,11 +117142,11 @@ function chatGPTAdsTwin() {
|
|
|
116732
117142
|
const app2 = new Hono3();
|
|
116733
117143
|
for (const route11 of chatGPTAdsRoutes) app2.on(route11.method, route11.path, handle2(route11));
|
|
116734
117144
|
app2.all("*", handle2({ method: "GET", path: "*", notes: "", run: (c) => unsupported5(`${c.req.method} ${new URL(c.req.url).pathname}`) }));
|
|
116735
|
-
return { name: "chatgpt-ads", basePath: "", app: app2, migrate:
|
|
117145
|
+
return { name: "chatgpt-ads", basePath: "", app: app2, migrate: migrate8, seed: seed5, credentials: credentials4, dumpState: dumpState3, actions: {}, checks: {}, coverage: chatGPTAdsCoverage };
|
|
116736
117146
|
}
|
|
116737
117147
|
|
|
116738
117148
|
// packages/server/src/twins/ga4/db.ts
|
|
116739
|
-
function
|
|
117149
|
+
function migrate9(db2) {
|
|
116740
117150
|
db2.exec(`CREATE TABLE ga4_data (id INTEGER PRIMARY KEY CHECK(id=1),json TEXT NOT NULL);
|
|
116741
117151
|
CREATE TABLE ga4_credentials (principal_id TEXT PRIMARY KEY,token TEXT NOT NULL UNIQUE);
|
|
116742
117152
|
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));`);
|
|
@@ -117207,7 +117617,7 @@ function ga4Twin() {
|
|
|
117207
117617
|
property2(c, "0", true);
|
|
117208
117618
|
return unsupported6(`${c.req.method} ${new URL(c.req.url).pathname}`);
|
|
117209
117619
|
} }));
|
|
117210
|
-
return { name: "ga4", basePath: "", unprefixedPaths: /^\/v1(?:alpha|beta)\/properties\//, app: app2, migrate:
|
|
117620
|
+
return { name: "ga4", basePath: "", unprefixedPaths: /^\/v1(?:alpha|beta)\/properties\//, app: app2, migrate: migrate9, seed: seed6, credentials: credentials5, dumpState: dumpState4, actions: {}, checks: {}, coverage: ga4Coverage };
|
|
117211
117621
|
}
|
|
117212
117622
|
|
|
117213
117623
|
// packages/server/src/twins/github/actions.ts
|
|
@@ -117356,7 +117766,7 @@ var actionRoutes = [
|
|
|
117356
117766
|
];
|
|
117357
117767
|
|
|
117358
117768
|
// packages/server/src/twins/github/methods/checks.ts
|
|
117359
|
-
function
|
|
117769
|
+
function shape2(ctx, repo4, row) {
|
|
117360
117770
|
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: [] };
|
|
117361
117771
|
}
|
|
117362
117772
|
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.";
|
|
@@ -117377,13 +117787,13 @@ var checkRoutes = [
|
|
|
117377
117787
|
});
|
|
117378
117788
|
}
|
|
117379
117789
|
const { page: page15, perPage } = pageInfo(c);
|
|
117380
|
-
return json2({ total_count: rows7.length, check_runs: pageSlice(rows7, page15, perPage).map((row) =>
|
|
117790
|
+
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));
|
|
117381
117791
|
} },
|
|
117382
117792
|
{ method: "GET", path: "/repos/:owner/:repo/check-runs/:id", coverage: { status: "partial", notes: notes4 }, handler: (c) => {
|
|
117383
117793
|
query2(c, []);
|
|
117384
117794
|
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"));
|
|
117385
117795
|
if (!row) throw new GitHubError(404, "Not Found");
|
|
117386
|
-
return
|
|
117796
|
+
return shape2(ctx, repo4, row);
|
|
117387
117797
|
} }
|
|
117388
117798
|
];
|
|
117389
117799
|
|
|
@@ -118608,7 +119018,7 @@ function downtime(ctx, args) {
|
|
|
118608
119018
|
}
|
|
118609
119019
|
|
|
118610
119020
|
// packages/server/src/twins/datadog/db.ts
|
|
118611
|
-
function
|
|
119021
|
+
function migrate10(db2) {
|
|
118612
119022
|
db2.exec(`
|
|
118613
119023
|
CREATE TABLE datadog_monitors (
|
|
118614
119024
|
id INTEGER PRIMARY KEY, ref TEXT NOT NULL UNIQUE, name TEXT NOT NULL, query TEXT NOT NULL,
|
|
@@ -118991,7 +119401,7 @@ function datadogTwin() {
|
|
|
118991
119401
|
name: "datadog",
|
|
118992
119402
|
basePath: "",
|
|
118993
119403
|
app: app2,
|
|
118994
|
-
migrate:
|
|
119404
|
+
migrate: migrate10,
|
|
118995
119405
|
seed: seed7,
|
|
118996
119406
|
credentials: credentials6,
|
|
118997
119407
|
dumpState: dumpState6,
|
|
@@ -120047,7 +120457,7 @@ function unsupported8(message5, code2 = "INVALID_FIELD") {
|
|
|
120047
120457
|
}
|
|
120048
120458
|
var versionRoot = "/services/data/v67.0";
|
|
120049
120459
|
var prefixes = { Account: "001", Contact: "003", Lead: "00Q", Opportunity: "006", Campaign: "701", CampaignMember: "00v" };
|
|
120050
|
-
function
|
|
120460
|
+
function migrate11(db2) {
|
|
120051
120461
|
db2.exec(`
|
|
120052
120462
|
CREATE TABLE salesforce_records (type TEXT NOT NULL,id TEXT NOT NULL PRIMARY KEY,data TEXT NOT NULL);
|
|
120053
120463
|
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);
|
|
@@ -120570,11 +120980,11 @@ function salesforceTwin() {
|
|
|
120570
120980
|
};
|
|
120571
120981
|
for (const [method2, path4] of routePairs2) app2.on(method2, path4, handler);
|
|
120572
120982
|
app2.all("*", handler);
|
|
120573
|
-
return { name: "salesforce", basePath: "", app: app2, migrate:
|
|
120983
|
+
return { name: "salesforce", basePath: "", app: app2, migrate: migrate11, seed: seed10, credentials: credentials9, actions: {}, checks: {}, dumpState: dumpState9, coverage: salesforceCoverage };
|
|
120574
120984
|
}
|
|
120575
120985
|
|
|
120576
120986
|
// packages/server/src/twins/linkedin-ads/db.ts
|
|
120577
|
-
function
|
|
120987
|
+
function migrate12(db2) {
|
|
120578
120988
|
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)");
|
|
120579
120989
|
}
|
|
120580
120990
|
function get2(ctx, kind, id12) {
|
|
@@ -121086,11 +121496,11 @@ function linkedinAdsTwin() {
|
|
|
121086
121496
|
const app2 = new Hono3();
|
|
121087
121497
|
for (const route11 of linkedinAdsRoutes) app2.on(route11.method, route11.path, handle4(route11));
|
|
121088
121498
|
app2.all("*", unknown2);
|
|
121089
|
-
return { name: "linkedin-ads", basePath: "", app: app2, migrate:
|
|
121499
|
+
return { name: "linkedin-ads", basePath: "", app: app2, migrate: migrate12, seed: seed11, credentials: credentials10, actions: {}, checks: {}, dumpState: dumpState10, coverage: linkedinAdsCoverage };
|
|
121090
121500
|
}
|
|
121091
121501
|
|
|
121092
121502
|
// packages/server/src/twins/gong/db.ts
|
|
121093
|
-
function
|
|
121503
|
+
function migrate13(db2) {
|
|
121094
121504
|
db2.exec(`CREATE TABLE gong_data (id INTEGER PRIMARY KEY CHECK(id=1), json TEXT NOT NULL);
|
|
121095
121505
|
CREATE TABLE gong_credentials (principal_id TEXT PRIMARY KEY, access_key TEXT NOT NULL UNIQUE, access_secret TEXT NOT NULL);
|
|
121096
121506
|
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));`);
|
|
@@ -121229,13 +121639,13 @@ function handle5(route11) {
|
|
|
121229
121639
|
};
|
|
121230
121640
|
}
|
|
121231
121641
|
var unknown3 = handle5({ method: "GET", path: "*", scope: "", notes: "", run: (c) => unsupported9(`${c.req.method} ${new URL(c.req.url).pathname}`) });
|
|
121232
|
-
function
|
|
121233
|
-
if (Array.isArray(value4)) return `[${value4.map(
|
|
121234
|
-
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)}:${
|
|
121642
|
+
function canonical4(value4) {
|
|
121643
|
+
if (Array.isArray(value4)) return `[${value4.map(canonical4).join(",")}]`;
|
|
121644
|
+
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(",")}}`;
|
|
121235
121645
|
return JSON.stringify(value4);
|
|
121236
121646
|
}
|
|
121237
121647
|
function pageRequest(ctx, principal, op, criteria, raw3) {
|
|
121238
|
-
const hash4 = createHash15("sha256").update(
|
|
121648
|
+
const hash4 = createHash15("sha256").update(canonical4(criteria)).digest("hex");
|
|
121239
121649
|
const base3 = { v: 1, env: ctx.envId, principal: principal.id, op, hash: hash4, page: 0, asOf: ctx.clock.elapsedMs() };
|
|
121240
121650
|
const sign2 = (payload2) => createHmac2("sha256", ctx.store.meta.get("gong.cursor-secret")).update(payload2).digest("base64url");
|
|
121241
121651
|
let cursor4 = base3;
|
|
@@ -121369,11 +121779,11 @@ function gongTwin() {
|
|
|
121369
121779
|
const app2 = new Hono3();
|
|
121370
121780
|
for (const route11 of gongRoutes) app2.on(route11.method, route11.path, handle5(route11));
|
|
121371
121781
|
app2.all("*", unknown3);
|
|
121372
|
-
return { name: "gong", basePath: "", app: app2, migrate:
|
|
121782
|
+
return { name: "gong", basePath: "", app: app2, migrate: migrate13, seed: seed12, credentials: credentials11, dumpState: dumpState11, actions: {}, checks: {}, coverage: gongCoverage };
|
|
121373
121783
|
}
|
|
121374
121784
|
|
|
121375
121785
|
// packages/server/src/twins/open-meteo/db.ts
|
|
121376
|
-
function
|
|
121786
|
+
function migrate14(db2) {
|
|
121377
121787
|
db2.exec("CREATE TABLE open_meteo_data (id INTEGER PRIMARY KEY CHECK(id=1), json TEXT NOT NULL);");
|
|
121378
121788
|
}
|
|
121379
121789
|
function seed13(ctx) {
|
|
@@ -121621,12 +122031,12 @@ function openMeteoTwin() {
|
|
|
121621
122031
|
app2.get("/v1/forecast", handle6(forecast));
|
|
121622
122032
|
app2.get("/v1/search", handle6(search4));
|
|
121623
122033
|
app2.all("*", handle6(unknownRoute5));
|
|
121624
|
-
return { name: "open-meteo", basePath: "", app: app2, migrate:
|
|
122034
|
+
return { name: "open-meteo", basePath: "", app: app2, migrate: migrate14, seed: seed13, credentials: credentials12, dumpState: dumpState12, actions: {}, checks: {}, coverage: openMeteoCoverage };
|
|
121625
122035
|
}
|
|
121626
122036
|
|
|
121627
122037
|
// packages/server/src/twins/google-drive/db.ts
|
|
121628
122038
|
import { createHash as createHash16 } from "node:crypto";
|
|
121629
|
-
var
|
|
122039
|
+
var SCHEMA6 = `
|
|
121630
122040
|
CREATE TABLE gdrive_users (email TEXT PRIMARY KEY, name TEXT, permission_id TEXT NOT NULL UNIQUE, root_id TEXT NOT NULL UNIQUE);
|
|
121631
122041
|
CREATE TABLE gdrive_files (
|
|
121632
122042
|
id TEXT PRIMARY KEY, name TEXT NOT NULL, mime_type TEXT NOT NULL, owner TEXT NOT NULL, parent TEXT, description TEXT,
|
|
@@ -121652,8 +122062,8 @@ CREATE TABLE gdrive_revisions (file_id TEXT NOT NULL, id TEXT NOT NULL, mime_typ
|
|
|
121652
122062
|
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);
|
|
121653
122063
|
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);
|
|
121654
122064
|
`;
|
|
121655
|
-
function
|
|
121656
|
-
db2.exec(
|
|
122065
|
+
function migrate15(db2) {
|
|
122066
|
+
db2.exec(SCHEMA6);
|
|
121657
122067
|
}
|
|
121658
122068
|
var RANK2 = { reader: 1, commenter: 2, writer: 3, owner: 4 };
|
|
121659
122069
|
var isFolder = (file3) => file3.mime_type === GOOGLE_DRIVE_FOLDER;
|
|
@@ -122279,12 +122689,12 @@ function parseQuery(source, aliases) {
|
|
|
122279
122689
|
return (file3) => file3.sharedWithMe;
|
|
122280
122690
|
}
|
|
122281
122691
|
const operator2 = expect();
|
|
122282
|
-
const
|
|
122283
|
-
if (!
|
|
122692
|
+
const contains3 = operator2.kind === "word" && operator2.value.toLowerCase() === "contains";
|
|
122693
|
+
if (!contains3 && operator2.kind !== "op") {
|
|
122284
122694
|
if (operator2.kind === "word" && operator2.value.toLowerCase() === "has") unsupported11(`${field3} has search`);
|
|
122285
122695
|
throw invalid10("q");
|
|
122286
122696
|
}
|
|
122287
|
-
const op =
|
|
122697
|
+
const op = contains3 ? "contains" : operator2.value;
|
|
122288
122698
|
switch (field3) {
|
|
122289
122699
|
case "name": {
|
|
122290
122700
|
const value4 = literal2();
|
|
@@ -123503,7 +123913,7 @@ async function handle7(c) {
|
|
|
123503
123913
|
function googleDriveTwin() {
|
|
123504
123914
|
const app2 = new Hono3();
|
|
123505
123915
|
app2.all("*", handle7);
|
|
123506
|
-
return { name: "google-drive", basePath: "", unprefixedPaths: /^\/(?:upload\/)?drive\/v3\//, app: app2, migrate:
|
|
123916
|
+
return { name: "google-drive", basePath: "", unprefixedPaths: /^\/(?:upload\/)?drive\/v3\//, app: app2, migrate: migrate15, seed: seed14, credentials: credentials13, dumpState: dumpState13, actions: {}, checks: {}, coverage: googleDriveCoverage };
|
|
123507
123917
|
}
|
|
123508
123918
|
|
|
123509
123919
|
// packages/server/src/twins/gmail/checks.ts
|
|
@@ -123536,7 +123946,7 @@ import { randomUUID as randomUUID2 } from "node:crypto";
|
|
|
123536
123946
|
import { STATUS_CODES } from "node:http";
|
|
123537
123947
|
var MAX_PARTS2 = 100;
|
|
123538
123948
|
var BODYLESS = /* @__PURE__ */ new Set(["GET", "HEAD", "DELETE"]);
|
|
123539
|
-
function
|
|
123949
|
+
function traced2(text21) {
|
|
123540
123950
|
if (text21 === "") return void 0;
|
|
123541
123951
|
try {
|
|
123542
123952
|
return JSON.parse(text21);
|
|
@@ -123576,8 +123986,8 @@ function batchHandler(app2) {
|
|
|
123576
123986
|
path: url3.pathname,
|
|
123577
123987
|
...url3.search.length > 1 && { query: url3.search.slice(1) },
|
|
123578
123988
|
status: response5.status,
|
|
123579
|
-
...content2 !== "" && { request:
|
|
123580
|
-
...text21 !== "" && { response:
|
|
123989
|
+
...content2 !== "" && { request: traced2(content2) },
|
|
123990
|
+
...text21 !== "" && { response: traced2(text21) },
|
|
123581
123991
|
gap: response5.status === 501,
|
|
123582
123992
|
note: "batch part"
|
|
123583
123993
|
});
|
|
@@ -124584,7 +124994,7 @@ function seed15(ctx) {
|
|
|
124584
124994
|
function credentials14(ctx) {
|
|
124585
124995
|
const agent = ctx.scene.seed.gmail?.agent ?? ctx.store.db.prepare("SELECT address FROM gmail_mailboxes ORDER BY ordinal LIMIT 1").get().address;
|
|
124586
124996
|
const row = ctx.store.db.prepare("SELECT token FROM gmail_tokens WHERE mailbox = ?").get(agent);
|
|
124587
|
-
return { token: row.token };
|
|
124997
|
+
return { token: row.token, address: agent };
|
|
124588
124998
|
}
|
|
124589
124999
|
|
|
124590
125000
|
// packages/server/src/twins/gmail/state.ts
|
|
@@ -124636,11 +125046,32 @@ ${m.thread_id}`;
|
|
|
124636
125046
|
}
|
|
124637
125047
|
|
|
124638
125048
|
// packages/server/src/twins/gmail/index.ts
|
|
124639
|
-
var
|
|
125049
|
+
var GOOGLE_OPENID_CONFIGURATION = {
|
|
125050
|
+
issuer: "https://accounts.google.com",
|
|
125051
|
+
authorization_endpoint: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
125052
|
+
device_authorization_endpoint: "https://oauth2.googleapis.com/device/code",
|
|
125053
|
+
token_endpoint: "https://oauth2.googleapis.com/token",
|
|
125054
|
+
userinfo_endpoint: "https://openidconnect.googleapis.com/v1/userinfo",
|
|
125055
|
+
revocation_endpoint: "https://oauth2.googleapis.com/revoke",
|
|
125056
|
+
jwks_uri: "https://www.googleapis.com/oauth2/v3/certs",
|
|
125057
|
+
response_types_supported: ["code", "token", "id_token", "code token", "code id_token", "token id_token", "code token id_token", "none"],
|
|
125058
|
+
subject_types_supported: ["public"],
|
|
125059
|
+
id_token_signing_alg_values_supported: ["RS256"],
|
|
125060
|
+
scopes_supported: ["openid", "email", "profile"],
|
|
125061
|
+
token_endpoint_auth_methods_supported: ["client_secret_post", "client_secret_basic"],
|
|
125062
|
+
claims_supported: ["aud", "email", "email_verified", "exp", "family_name", "given_name", "iat", "iss", "name", "picture", "sub"],
|
|
125063
|
+
code_challenge_methods_supported: ["plain", "S256"],
|
|
125064
|
+
grant_types_supported: ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code", "urn:ietf:params:oauth:grant-type:jwt-bearer"]
|
|
125065
|
+
};
|
|
125066
|
+
var gmailCoverage = [
|
|
125067
|
+
...gmailRoutes.map(({ method: method2, path: path4, coverage: coverage4 }) => ({ method: method2, path: path4, ...coverage4 })),
|
|
125068
|
+
{ method: "GET", path: "/.well-known/openid-configuration", status: "supported", notes: "Google's discovery document; the endpoints it names are Google's" }
|
|
125069
|
+
];
|
|
124640
125070
|
function gmailTwin() {
|
|
124641
125071
|
const app2 = new Hono3();
|
|
124642
125072
|
for (const route11 of gmailRoutes) app2.on(route11.method, route11.path, handle(route11));
|
|
124643
125073
|
app2.post("/batch/gmail/v1", batchHandler(app2));
|
|
125074
|
+
app2.get("/.well-known/openid-configuration", (c) => c.json(GOOGLE_OPENID_CONFIGURATION));
|
|
124644
125075
|
app2.all("*", unknownRoute3);
|
|
124645
125076
|
return { name: "gmail", basePath: "", unprefixedPaths: /^\/(?:(?:(?:upload|batch)\/)?gmail\/v1(?:\/|$)|oauth2\/v2\/userinfo$)/, app: app2, migrate: migrate5, seed: seed15, credentials: credentials14, actions: gmailActions, checks: { thread }, dumpState: dumpState14, coverage: gmailCoverage };
|
|
124646
125077
|
}
|
|
@@ -124800,9 +125231,9 @@ function stringToSign(method2, path4, query10, headers, signature) {
|
|
|
124800
125231
|
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("&");
|
|
124801
125232
|
const canonicalHeaders = signature.signedHeaders.map((name5) => `${name5}:${(headers.get(name5) ?? "").trim().replace(/\s+/g, " ")}
|
|
124802
125233
|
`).join("");
|
|
124803
|
-
const
|
|
124804
|
-
const toSign = ["AWS4-HMAC-SHA256", signature.amzDate, `${signature.date}/${signature.region}/s3/aws4_request`, sha256Hex(
|
|
124805
|
-
return { canonical:
|
|
125234
|
+
const canonical5 = [method2, path4, canonicalQuery, canonicalHeaders, signature.signedHeaders.join(";"), signature.payloadHash].join("\n");
|
|
125235
|
+
const toSign = ["AWS4-HMAC-SHA256", signature.amzDate, `${signature.date}/${signature.region}/s3/aws4_request`, sha256Hex(canonical5)].join("\n");
|
|
125236
|
+
return { canonical: canonical5, toSign };
|
|
124806
125237
|
}
|
|
124807
125238
|
function verifySignature(secret, signature, toSign) {
|
|
124808
125239
|
const key3 = hmac(hmac(hmac(hmac(`AWS4${secret}`, signature.date), signature.region), "s3"), "aws4_request");
|
|
@@ -124868,7 +125299,7 @@ var md5Hex = (data5) => createHash19("md5").update(data5).digest("hex");
|
|
|
124868
125299
|
var sha2562 = sha256Hex;
|
|
124869
125300
|
|
|
124870
125301
|
// packages/server/src/twins/amazon-s3/db.ts
|
|
124871
|
-
var
|
|
125302
|
+
var SCHEMA7 = `
|
|
124872
125303
|
CREATE TABLE s3_buckets (name TEXT PRIMARY KEY, region TEXT NOT NULL, created_ms INTEGER NOT NULL, access TEXT NOT NULL, tags TEXT);
|
|
124873
125304
|
CREATE TABLE s3_objects (
|
|
124874
125305
|
bucket TEXT NOT NULL, key TEXT NOT NULL, content BLOB NOT NULL, content_type TEXT NOT NULL, etag TEXT NOT NULL,
|
|
@@ -124883,8 +125314,8 @@ CREATE TABLE s3_uploads (
|
|
|
124883
125314
|
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));
|
|
124884
125315
|
CREATE TABLE s3_taken_names (name TEXT PRIMARY KEY);
|
|
124885
125316
|
`;
|
|
124886
|
-
function
|
|
124887
|
-
db2.exec(
|
|
125317
|
+
function migrate16(db2) {
|
|
125318
|
+
db2.exec(SCHEMA7);
|
|
124888
125319
|
}
|
|
124889
125320
|
function account3(ctx) {
|
|
124890
125321
|
return JSON.parse(ctx.store.meta.get("amazon-s3.account"));
|
|
@@ -125741,11 +126172,11 @@ async function handle8(c) {
|
|
|
125741
126172
|
function amazonS3Twin() {
|
|
125742
126173
|
const app2 = new Hono3();
|
|
125743
126174
|
app2.all("*", handle8);
|
|
125744
|
-
return { name: "amazon-s3", basePath: "", app: app2, migrate:
|
|
126175
|
+
return { name: "amazon-s3", basePath: "", app: app2, migrate: migrate16, seed: seed16, credentials: credentials15, dumpState: dumpState15, actions: {}, checks: {}, coverage: amazonS3Coverage };
|
|
125745
126176
|
}
|
|
125746
126177
|
|
|
125747
126178
|
// packages/server/src/twins/linear/db.ts
|
|
125748
|
-
var
|
|
126179
|
+
var SCHEMA8 = `
|
|
125749
126180
|
CREATE TABLE linear_org (id TEXT PRIMARY KEY, name TEXT NOT NULL, url_key TEXT NOT NULL, created_at TEXT NOT NULL);
|
|
125750
126181
|
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,
|
|
125751
126182
|
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);
|
|
@@ -125769,8 +126200,8 @@ CREATE TABLE linear_issue_labels (issue_id TEXT NOT NULL, label_id TEXT NOT NULL
|
|
|
125769
126200
|
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,
|
|
125770
126201
|
created_at TEXT NOT NULL, updated_at TEXT NOT NULL, edited_at TEXT, archived_at TEXT);
|
|
125771
126202
|
`;
|
|
125772
|
-
function
|
|
125773
|
-
db2.exec(
|
|
126203
|
+
function migrate17(db2) {
|
|
126204
|
+
db2.exec(SCHEMA8);
|
|
125774
126205
|
}
|
|
125775
126206
|
var one = (ctx, sql, ...args) => ctx.store.db.prepare(sql).get(...args);
|
|
125776
126207
|
var all2 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).all(...args);
|
|
@@ -126932,7 +127363,7 @@ function linearTwin() {
|
|
|
126932
127363
|
const app2 = new Hono3();
|
|
126933
127364
|
app2.post("/graphql", handleGraphql);
|
|
126934
127365
|
app2.all("*", unknownRoute7);
|
|
126935
|
-
return { name: "linear", basePath: "/graphql", app: app2, migrate:
|
|
127366
|
+
return { name: "linear", basePath: "/graphql", app: app2, migrate: migrate17, seed: seed17, credentials: credentials16, actions: {}, checks: {}, dumpState: dumpState16, coverage: linearCoverage };
|
|
126936
127367
|
}
|
|
126937
127368
|
|
|
126938
127369
|
// packages/server/src/twins/okta/index.ts
|
|
@@ -126940,7 +127371,7 @@ import { createHash as createHash25 } from "node:crypto";
|
|
|
126940
127371
|
|
|
126941
127372
|
// packages/server/src/twins/okta/db.ts
|
|
126942
127373
|
import { createHash as createHash23 } from "node:crypto";
|
|
126943
|
-
var
|
|
127374
|
+
var SCHEMA9 = `
|
|
126944
127375
|
CREATE TABLE okta_users (
|
|
126945
127376
|
id TEXT PRIMARY KEY, login TEXT NOT NULL UNIQUE COLLATE NOCASE, status TEXT NOT NULL, created_ms INTEGER NOT NULL, activated_ms INTEGER,
|
|
126946
127377
|
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,
|
|
@@ -126956,8 +127387,8 @@ CREATE TABLE okta_logs (
|
|
|
126956
127387
|
outcome TEXT NOT NULL, reason TEXT, actor_id TEXT NOT NULL, targets TEXT NOT NULL
|
|
126957
127388
|
);
|
|
126958
127389
|
`;
|
|
126959
|
-
function
|
|
126960
|
-
db2.exec(
|
|
127390
|
+
function migrate18(db2) {
|
|
127391
|
+
db2.exec(SCHEMA9);
|
|
126961
127392
|
}
|
|
126962
127393
|
var BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
126963
127394
|
var hashed = (value4, length) => [...createHash23("sha256").update(value4).digest()].slice(0, length).map((byte) => BASE62[byte % 62]).join("");
|
|
@@ -128016,18 +128447,18 @@ async function handle9(c) {
|
|
|
128016
128447
|
function oktaTwin() {
|
|
128017
128448
|
const app2 = new Hono3();
|
|
128018
128449
|
app2.all("*", handle9);
|
|
128019
|
-
return { name: "okta", basePath: "", app: app2, migrate:
|
|
128450
|
+
return { name: "okta", basePath: "", app: app2, migrate: migrate18, seed: seed18, credentials: credentials17, dumpState: dumpState17, actions: {}, checks: { user: user6 }, coverage: oktaCoverage };
|
|
128020
128451
|
}
|
|
128021
128452
|
|
|
128022
128453
|
// packages/server/src/twins/stripe/db.ts
|
|
128023
|
-
var
|
|
128454
|
+
var SCHEMA10 = `
|
|
128024
128455
|
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);
|
|
128025
128456
|
CREATE INDEX stripe_objects_type ON stripe_objects (type, created, seq);
|
|
128026
128457
|
CREATE TABLE stripe_keys (key TEXT PRIMARY KEY);
|
|
128027
128458
|
CREATE TABLE stripe_idempotency (key TEXT PRIMARY KEY, fingerprint TEXT NOT NULL, status INTEGER NOT NULL, body TEXT NOT NULL);
|
|
128028
128459
|
`;
|
|
128029
|
-
function
|
|
128030
|
-
db2.exec(
|
|
128460
|
+
function migrate19(db2) {
|
|
128461
|
+
db2.exec(SCHEMA10);
|
|
128031
128462
|
}
|
|
128032
128463
|
function load(ctx, id12) {
|
|
128033
128464
|
const row = ctx.store.db.prepare("SELECT json FROM stripe_objects WHERE id = ?").get(id12);
|
|
@@ -130092,7 +130523,7 @@ function stripeTwin() {
|
|
|
130092
130523
|
const app2 = new Hono3();
|
|
130093
130524
|
for (const route11 of [...stripeRoutes].sort((a, b) => Number(a.path.includes(":")) - Number(b.path.includes(":")))) app2.on(route11.method, route11.path, handle10(route11));
|
|
130094
130525
|
app2.all("*", unknownRoute8);
|
|
130095
|
-
return { name: "stripe", basePath: "", app: app2, migrate:
|
|
130526
|
+
return { name: "stripe", basePath: "", app: app2, migrate: migrate19, seed: seed19, credentials: credentials18, actions: {}, checks: {}, dumpState: dumpState18, coverage: stripeCoverage };
|
|
130096
130527
|
}
|
|
130097
130528
|
|
|
130098
130529
|
// packages/server/src/twins/clerk/index.ts
|
|
@@ -130100,7 +130531,7 @@ import { createHash as createHash29 } from "node:crypto";
|
|
|
130100
130531
|
|
|
130101
130532
|
// packages/server/src/twins/clerk/db.ts
|
|
130102
130533
|
import { createHash as createHash27 } from "node:crypto";
|
|
130103
|
-
var
|
|
130534
|
+
var SCHEMA11 = `
|
|
130104
130535
|
CREATE TABLE clerk_users (
|
|
130105
130536
|
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,
|
|
130106
130537
|
external_id TEXT, password_enabled INTEGER NOT NULL, banned INTEGER NOT NULL DEFAULT 0, locked INTEGER NOT NULL DEFAULT 0,
|
|
@@ -130118,8 +130549,8 @@ CREATE TABLE clerk_invitations (
|
|
|
130118
130549
|
);
|
|
130119
130550
|
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);
|
|
130120
130551
|
`;
|
|
130121
|
-
function
|
|
130122
|
-
db2.exec(
|
|
130552
|
+
function migrate20(db2) {
|
|
130553
|
+
db2.exec(SCHEMA11);
|
|
130123
130554
|
}
|
|
130124
130555
|
var BASE623 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
130125
130556
|
var seededId2 = (prefix2, key3) => `${prefix2}_2${[...createHash27("sha256").update(`clerk:${prefix2}:${key3}`).digest()].slice(0, 26).map((byte) => BASE623[byte % 62]).join("")}`;
|
|
@@ -130522,10 +130953,10 @@ function filterUsers(call2, query10) {
|
|
|
130522
130953
|
const found = getOrg(ctx, org5);
|
|
130523
130954
|
return found ? membershipsOf(ctx, found.id).map((member4) => member4.user_id) : [];
|
|
130524
130955
|
})) : void 0;
|
|
130525
|
-
const
|
|
130956
|
+
const contains3 = (value4, needle) => needle === null || (value4 ?? "").toLowerCase().includes(needle.toLowerCase());
|
|
130526
130957
|
const q = query10.get("query"), banned = bool4(query10.get("banned") ?? void 0, "banned");
|
|
130527
130958
|
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");
|
|
130528
|
-
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) =>
|
|
130959
|
+
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));
|
|
130529
130960
|
}
|
|
130530
130961
|
var USER_ORDER = {
|
|
130531
130962
|
created_at: (user8) => user8.created_ms,
|
|
@@ -131055,12 +131486,12 @@ async function handle11(c) {
|
|
|
131055
131486
|
function clerkTwin() {
|
|
131056
131487
|
const app2 = new Hono3();
|
|
131057
131488
|
app2.all("*", handle11);
|
|
131058
|
-
return { name: "clerk", basePath: "", app: app2, migrate:
|
|
131489
|
+
return { name: "clerk", basePath: "", app: app2, migrate: migrate20, seed: seed20, credentials: credentials19, dumpState: dumpState19, actions: {}, checks: {}, coverage: clerkCoverage };
|
|
131059
131490
|
}
|
|
131060
131491
|
|
|
131061
131492
|
// packages/server/src/twins/better-stack/db.ts
|
|
131062
131493
|
import { createHash as createHash30 } from "node:crypto";
|
|
131063
|
-
var
|
|
131494
|
+
var SCHEMA12 = `
|
|
131064
131495
|
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);
|
|
131065
131496
|
CREATE TABLE bs_sources (
|
|
131066
131497
|
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,
|
|
@@ -131076,8 +131507,8 @@ CREATE TABLE bs_resources (id TEXT PRIMARY KEY, page_id TEXT NOT NULL, public_na
|
|
|
131076
131507
|
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);
|
|
131077
131508
|
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);
|
|
131078
131509
|
`;
|
|
131079
|
-
function
|
|
131080
|
-
db2.exec(
|
|
131510
|
+
function migrate21(db2) {
|
|
131511
|
+
db2.exec(SCHEMA12);
|
|
131081
131512
|
}
|
|
131082
131513
|
var BASES = { user: 145001, monitor: 2245001, heartbeat: 441501, incident: 600001, calendar: 9001, page: 160001, resource: 8800001, report: 3300001, update: 7700001 };
|
|
131083
131514
|
function nextId3(ctx, kind) {
|
|
@@ -131846,18 +132277,18 @@ async function handle12(c) {
|
|
|
131846
132277
|
function betterStackTwin() {
|
|
131847
132278
|
const app2 = new Hono3();
|
|
131848
132279
|
app2.all("*", handle12);
|
|
131849
|
-
return { name: "better-stack", basePath: "", app: app2, migrate:
|
|
132280
|
+
return { name: "better-stack", basePath: "", app: app2, migrate: migrate21, seed: seed21, credentials: credentials20, dumpState: dumpState20, actions: {}, checks: {}, coverage: betterStackCoverage };
|
|
131850
132281
|
}
|
|
131851
132282
|
|
|
131852
132283
|
// packages/server/src/twins/notion/db.ts
|
|
131853
|
-
var
|
|
132284
|
+
var SCHEMA13 = `
|
|
131854
132285
|
CREATE TABLE notion_nodes (id TEXT PRIMARY KEY, kind TEXT NOT NULL CHECK (kind IN ('user','page','block','database','data_source','comment')),
|
|
131855
132286
|
parent_id TEXT, position REAL NOT NULL DEFAULT 0, json TEXT NOT NULL);
|
|
131856
132287
|
CREATE INDEX notion_nodes_parent ON notion_nodes (parent_id, position);
|
|
131857
132288
|
CREATE TABLE notion_tokens (token TEXT PRIMARY KEY, bot_id TEXT NOT NULL);
|
|
131858
132289
|
`;
|
|
131859
|
-
function
|
|
131860
|
-
db2.exec(
|
|
132290
|
+
function migrate22(db2) {
|
|
132291
|
+
db2.exec(SCHEMA13);
|
|
131861
132292
|
}
|
|
131862
132293
|
var node4 = (row) => row && { id: row.id, kind: row.kind, parent_id: row.parent_id, position: row.position, doc: JSON.parse(row.json) };
|
|
131863
132294
|
function get3(ctx, id12) {
|
|
@@ -133064,11 +133495,11 @@ function notionTwin() {
|
|
|
133064
133495
|
const app2 = new Hono3();
|
|
133065
133496
|
for (const route11 of [...notionRoutes].sort((a, b) => Number(a.path.includes(":")) - Number(b.path.includes(":")))) app2.on(route11.method, route11.path, handle13(route11));
|
|
133066
133497
|
app2.all("*", unknownRoute9);
|
|
133067
|
-
return { name: "notion", basePath: "", app: app2, migrate:
|
|
133498
|
+
return { name: "notion", basePath: "", app: app2, migrate: migrate22, seed: seed22, credentials: credentials21, actions: {}, checks: {}, dumpState: dumpState21, coverage: notionCoverage };
|
|
133068
133499
|
}
|
|
133069
133500
|
|
|
133070
133501
|
// packages/server/src/twins/attio/db.ts
|
|
133071
|
-
var
|
|
133502
|
+
var SCHEMA14 = `
|
|
133072
133503
|
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);
|
|
133073
133504
|
CREATE TABLE attio_tokens (token TEXT PRIMARY KEY, member_id TEXT NOT NULL);
|
|
133074
133505
|
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);
|
|
@@ -133085,8 +133516,8 @@ CREATE INDEX attio_values_parent ON attio_values (parent_id, attribute_id, activ
|
|
|
133085
133516
|
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);
|
|
133086
133517
|
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);
|
|
133087
133518
|
`;
|
|
133088
|
-
function
|
|
133089
|
-
db2.exec(
|
|
133519
|
+
function migrate23(db2) {
|
|
133520
|
+
db2.exec(SCHEMA14);
|
|
133090
133521
|
}
|
|
133091
133522
|
var one2 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).get(...args);
|
|
133092
133523
|
var all5 = (ctx, sql, ...args) => ctx.store.db.prepare(sql).all(...args);
|
|
@@ -133890,7 +134321,7 @@ var attioRoutes = [
|
|
|
133890
134321
|
];
|
|
133891
134322
|
|
|
133892
134323
|
// packages/server/src/twins/attio/seed.ts
|
|
133893
|
-
var
|
|
134324
|
+
var SYSTEM2 = [
|
|
133894
134325
|
{ api_slug: "record_id", title: "Record ID", type: "text", system: true, writable: false }
|
|
133895
134326
|
];
|
|
133896
134327
|
var TAIL = [
|
|
@@ -133900,7 +134331,7 @@ var TAIL = [
|
|
|
133900
134331
|
function standard(dealStages, categories) {
|
|
133901
134332
|
return {
|
|
133902
134333
|
people: { singular: "Person", plural: "People", attributes: [
|
|
133903
|
-
...
|
|
134334
|
+
...SYSTEM2,
|
|
133904
134335
|
{ api_slug: "name", title: "Name", type: "personal-name", system: true },
|
|
133905
134336
|
{ api_slug: "email_addresses", title: "Email addresses", type: "email-address", is_multiselect: true, is_unique: true, system: true },
|
|
133906
134337
|
{ api_slug: "phone_numbers", title: "Phone numbers", type: "phone-number", is_multiselect: true, system: true },
|
|
@@ -133910,7 +134341,7 @@ function standard(dealStages, categories) {
|
|
|
133910
134341
|
...TAIL
|
|
133911
134342
|
] },
|
|
133912
134343
|
companies: { singular: "Company", plural: "Companies", attributes: [
|
|
133913
|
-
...
|
|
134344
|
+
...SYSTEM2,
|
|
133914
134345
|
{ api_slug: "name", title: "Name", type: "text", system: true },
|
|
133915
134346
|
{ api_slug: "domains", title: "Domains", type: "domain", is_multiselect: true, is_unique: true, system: true },
|
|
133916
134347
|
{ api_slug: "description", title: "Description", type: "text", system: true },
|
|
@@ -133919,7 +134350,7 @@ function standard(dealStages, categories) {
|
|
|
133919
134350
|
...TAIL
|
|
133920
134351
|
] },
|
|
133921
134352
|
deals: { singular: "Deal", plural: "Deals", attributes: [
|
|
133922
|
-
...
|
|
134353
|
+
...SYSTEM2,
|
|
133923
134354
|
{ api_slug: "name", title: "Deal name", type: "text", is_required: true, system: true },
|
|
133924
134355
|
{ api_slug: "stage", title: "Deal stage", type: "status", is_required: true, options: dealStages, system: true },
|
|
133925
134356
|
{ api_slug: "owner", title: "Deal owner", type: "actor-reference", is_required: true, system: true },
|
|
@@ -134092,12 +134523,12 @@ function attioTwin() {
|
|
|
134092
134523
|
const rank = (path4) => path4.split("/").filter((s) => s.startsWith(":")).length;
|
|
134093
134524
|
for (const route11 of [...attioRoutes].sort((a, b) => rank(a.path) - rank(b.path))) app2.on(route11.method, route11.path, handle14(route11));
|
|
134094
134525
|
app2.all("*", unknownRoute10);
|
|
134095
|
-
return { name: "attio", basePath: "", app: app2, migrate:
|
|
134526
|
+
return { name: "attio", basePath: "", app: app2, migrate: migrate23, seed: seed23, credentials: credentials22, actions: {}, checks: {}, dumpState: dumpState22, coverage: attioCoverage };
|
|
134096
134527
|
}
|
|
134097
134528
|
|
|
134098
134529
|
// packages/server/src/twins/dropbox/db.ts
|
|
134099
134530
|
import { createHash as createHash33 } from "node:crypto";
|
|
134100
|
-
var
|
|
134531
|
+
var SCHEMA15 = `
|
|
134101
134532
|
CREATE TABLE dbx_entries (
|
|
134102
134533
|
path_lower TEXT PRIMARY KEY, path_display TEXT NOT NULL, id TEXT NOT NULL UNIQUE, kind TEXT NOT NULL, rev TEXT, content BLOB,
|
|
134103
134534
|
client_modified_ms INTEGER, server_modified_ms INTEGER, uploaded_by TEXT, shared_folder_id TEXT
|
|
@@ -134111,8 +134542,8 @@ CREATE TABLE dbx_changes (seq INTEGER PRIMARY KEY, path_lower TEXT NOT NULL);
|
|
|
134111
134542
|
CREATE TABLE dbx_temp_links (token TEXT PRIMARY KEY, path_lower TEXT NOT NULL, rev TEXT NOT NULL, expires_ms INTEGER NOT NULL);
|
|
134112
134543
|
CREATE TABLE dbx_people (email TEXT PRIMARY KEY, name TEXT NOT NULL, same_team INTEGER NOT NULL);
|
|
134113
134544
|
`;
|
|
134114
|
-
function
|
|
134115
|
-
db2.exec(
|
|
134545
|
+
function migrate24(db2) {
|
|
134546
|
+
db2.exec(SCHEMA15);
|
|
134116
134547
|
}
|
|
134117
134548
|
var account5 = (ctx) => JSON.parse(ctx.store.meta.get("dropbox.account"));
|
|
134118
134549
|
var getEntry = (ctx, pathLower) => ctx.store.db.prepare("SELECT * FROM dbx_entries WHERE path_lower = ?").get(pathLower);
|
|
@@ -134892,7 +135323,7 @@ async function handle15(c) {
|
|
|
134892
135323
|
function dropboxTwin() {
|
|
134893
135324
|
const app2 = new Hono3();
|
|
134894
135325
|
app2.all("*", handle15);
|
|
134895
|
-
return { name: "dropbox", basePath: "", app: app2, migrate:
|
|
135326
|
+
return { name: "dropbox", basePath: "", app: app2, migrate: migrate24, seed: seed24, credentials: credentials23, dumpState: dumpState23, actions: {}, checks: {}, coverage: dropboxCoverage };
|
|
134896
135327
|
}
|
|
134897
135328
|
|
|
134898
135329
|
// packages/server/src/twins/resend/request.ts
|
|
@@ -134989,7 +135420,7 @@ function unknownRoute11(c) {
|
|
|
134989
135420
|
}
|
|
134990
135421
|
|
|
134991
135422
|
// packages/server/src/twins/resend/routes.ts
|
|
134992
|
-
function
|
|
135423
|
+
function migrate25(db2) {
|
|
134993
135424
|
db2.exec(`
|
|
134994
135425
|
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);
|
|
134995
135426
|
CREATE INDEX resend_objects_kind ON resend_objects (kind, created_ms);
|
|
@@ -135628,7 +136059,7 @@ function resendTwin() {
|
|
|
135628
136059
|
const rank = (path4) => path4.split("/").filter((s) => s.startsWith(":")).length;
|
|
135629
136060
|
for (const route11 of [...resendRoutes].sort((a, b) => rank(a.path) - rank(b.path))) app2.on(route11.method, route11.path, handle16(route11));
|
|
135630
136061
|
app2.all("*", unknownRoute11);
|
|
135631
|
-
return { name: "resend", basePath: "", app: app2, migrate:
|
|
136062
|
+
return { name: "resend", basePath: "", app: app2, migrate: migrate25, seed: seed25, credentials: credentials24, actions: {}, checks: {}, dumpState: dumpState24, coverage: resendCoverage };
|
|
135632
136063
|
}
|
|
135633
136064
|
|
|
135634
136065
|
// packages/server/src/twins/microsoft-word/db.ts
|
|
@@ -135793,7 +136224,7 @@ function quickXorHash(data5) {
|
|
|
135793
136224
|
}
|
|
135794
136225
|
|
|
135795
136226
|
// packages/server/src/twins/microsoft-word/db.ts
|
|
135796
|
-
var
|
|
136227
|
+
var SCHEMA16 = `
|
|
135797
136228
|
CREATE TABLE ms_users (email TEXT PRIMARY KEY, id TEXT NOT NULL UNIQUE, display_name TEXT NOT NULL, job_title TEXT);
|
|
135798
136229
|
CREATE TABLE ms_items (
|
|
135799
136230
|
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,
|
|
@@ -135806,8 +136237,8 @@ CREATE TABLE ms_permissions (
|
|
|
135806
136237
|
);
|
|
135807
136238
|
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);
|
|
135808
136239
|
`;
|
|
135809
|
-
function
|
|
135810
|
-
db2.exec(
|
|
136240
|
+
function migrate26(db2) {
|
|
136241
|
+
db2.exec(SCHEMA16);
|
|
135811
136242
|
}
|
|
135812
136243
|
var hex3 = (value4) => createHash36("sha256").update(value4).digest("hex");
|
|
135813
136244
|
var guid3 = (key3) => {
|
|
@@ -135829,7 +136260,7 @@ var childrenOf2 = (ctx, id12) => ctx.store.db.prepare("SELECT * FROM ms_items WH
|
|
|
135829
136260
|
var userOf = (ctx, email10) => ctx.store.db.prepare("SELECT * FROM ms_users WHERE email = ?").get(email10);
|
|
135830
136261
|
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" };
|
|
135831
136262
|
var mimeFor = (name5) => MIME[/\.([A-Za-z0-9]+)$/.exec(name5)?.[1]?.toLowerCase() ?? ""] ?? "application/octet-stream";
|
|
135832
|
-
function
|
|
136263
|
+
function pathOf2(ctx, item2) {
|
|
135833
136264
|
const parts3 = [];
|
|
135834
136265
|
for (let node5 = item2; node5 && node5.kind !== "root"; node5 = node5.parent_id ? getItem(ctx, node5.parent_id) : void 0) parts3.unshift(node5.name);
|
|
135835
136266
|
return parts3.length ? `/${parts3.join("/")}` : "";
|
|
@@ -135903,7 +136334,7 @@ function credentials25(ctx) {
|
|
|
135903
136334
|
}
|
|
135904
136335
|
function dumpState25(ctx) {
|
|
135905
136336
|
const db2 = ctx.store.db, iso19 = (ms) => new Date(ms).toISOString();
|
|
135906
|
-
const items = db2.prepare("SELECT * FROM ms_items WHERE kind != 'root'").all().map((item2) => ({ item: item2, path:
|
|
136337
|
+
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);
|
|
135907
136338
|
const paths2 = new Map(items.map((entry2) => [entry2.item.id, entry2.path]));
|
|
135908
136339
|
return {
|
|
135909
136340
|
...config8(ctx),
|
|
@@ -135981,7 +136412,7 @@ function identity3(ctx, email10) {
|
|
|
135981
136412
|
return { user: { email: email10, id: user8?.id ?? guid3(`user:${email10}`), displayName: user8?.display_name ?? email10 } };
|
|
135982
136413
|
}
|
|
135983
136414
|
function itemJson(ctx, item2) {
|
|
135984
|
-
const { driveId, me: me4, tenant } = config8(ctx), path4 =
|
|
136415
|
+
const { driveId, me: me4, tenant } = config8(ctx), path4 = pathOf2(ctx, item2), web = `https://${tenant.domain.split(".")[0]}-my.sharepoint.com/personal/${slug7(me4)}/Documents`;
|
|
135985
136416
|
const tag3 = guid3(`etag:${item2.id}`).toUpperCase(), parent2 = item2.parent_id ? getItem(ctx, item2.parent_id) : void 0;
|
|
135986
136417
|
const size = item2.kind === "file" ? item2.content?.length ?? 0 : childrenSize(ctx, item2);
|
|
135987
136418
|
const shared = sharedScope(ctx, item2);
|
|
@@ -135997,7 +136428,7 @@ function itemJson(ctx, item2) {
|
|
|
135997
136428
|
size,
|
|
135998
136429
|
createdBy: identity3(ctx, item2.created_by),
|
|
135999
136430
|
lastModifiedBy: identity3(ctx, item2.modified_by),
|
|
136000
|
-
parentReference: { driveType: "business", driveId, ...parent2 && { id: parent2.id, name: parent2.kind === "root" ? "Documents" : parent2.name, path: `/drive/root:${
|
|
136431
|
+
parentReference: { driveType: "business", driveId, ...parent2 && { id: parent2.id, name: parent2.kind === "root" ? "Documents" : parent2.name, path: `/drive/root:${pathOf2(ctx, parent2)}` } },
|
|
136001
136432
|
fileSystemInfo: { createdDateTime: iso7(item2.created_ms), lastModifiedDateTime: iso7(item2.modified_ms) },
|
|
136002
136433
|
...item2.description !== null && { description: item2.description },
|
|
136003
136434
|
...item2.kind === "file" ? { file: { mimeType: item2.mime_type, hashes: { quickXorHash: quickXorHash(item2.content ?? Buffer.alloc(0)) } } } : { folder: { childCount: childrenOf2(ctx, item2.id).length } },
|
|
@@ -136026,7 +136457,7 @@ function permissionJson(ctx, row, inheritedFrom) {
|
|
|
136026
136457
|
roles: roles2,
|
|
136027
136458
|
...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/${slug7(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 } },
|
|
136028
136459
|
...row.expires_ms !== null && { expirationDateTime: iso7(row.expires_ms) },
|
|
136029
|
-
...inheritedFrom && { inheritedFrom: { driveId: config8(ctx).driveId, id: inheritedFrom.id, path: `/drive/root:${
|
|
136460
|
+
...inheritedFrom && { inheritedFrom: { driveId: config8(ctx).driveId, id: inheritedFrom.id, path: `/drive/root:${pathOf2(ctx, inheritedFrom)}` } }
|
|
136030
136461
|
};
|
|
136031
136462
|
}
|
|
136032
136463
|
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"]);
|
|
@@ -136603,11 +137034,11 @@ async function handle17(c) {
|
|
|
136603
137034
|
function microsoftWordTwin() {
|
|
136604
137035
|
const app2 = new Hono3();
|
|
136605
137036
|
app2.all("*", handle17);
|
|
136606
|
-
return { name: "microsoft-word", basePath: "", app: app2, migrate:
|
|
137037
|
+
return { name: "microsoft-word", basePath: "", app: app2, migrate: migrate26, seed: seed26, credentials: credentials25, dumpState: dumpState25, actions: {}, checks: {}, coverage: microsoftWordCoverage };
|
|
136607
137038
|
}
|
|
136608
137039
|
|
|
136609
137040
|
// packages/server/src/twins/shopify/db.ts
|
|
136610
|
-
function
|
|
137041
|
+
function migrate27(db2) {
|
|
136611
137042
|
db2.exec(`
|
|
136612
137043
|
CREATE TABLE shopify_objects (gid TEXT PRIMARY KEY, kind TEXT NOT NULL, num INTEGER NOT NULL, parent TEXT, json TEXT NOT NULL);
|
|
136613
137044
|
CREATE INDEX shopify_objects_kind ON shopify_objects (kind, num);
|
|
@@ -136912,7 +137343,7 @@ function compare7(op, a, b) {
|
|
|
136912
137343
|
}
|
|
136913
137344
|
}
|
|
136914
137345
|
var wordsOf = (text21) => text21.toLowerCase().split(/[^\p{L}\p{N}*]+/u).filter(Boolean);
|
|
136915
|
-
function textMatch(values2, wanted,
|
|
137346
|
+
function textMatch(values2, wanted, contains3, words4 = false) {
|
|
136916
137347
|
const options3 = wanted.split(",").map((v) => v.trim().toLowerCase()).filter(Boolean);
|
|
136917
137348
|
return values2.some((raw3) => {
|
|
136918
137349
|
if (raw3 === null) return false;
|
|
@@ -136921,7 +137352,7 @@ function textMatch(values2, wanted, contains2, words4 = false) {
|
|
|
136921
137352
|
const have = wordsOf(v);
|
|
136922
137353
|
return options3.some((o) => wordsOf(o).every((w) => have.some((h) => w.endsWith("*") ? h.startsWith(w.slice(0, -1)) : h === w)));
|
|
136923
137354
|
}
|
|
136924
|
-
return options3.some((o) => o.endsWith("*") ?
|
|
137355
|
+
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);
|
|
136925
137356
|
});
|
|
136926
137357
|
}
|
|
136927
137358
|
function search7(items, query10, documented, fields11, nowMs) {
|
|
@@ -136983,7 +137414,7 @@ function decode3(cursor4) {
|
|
|
136983
137414
|
return null;
|
|
136984
137415
|
}
|
|
136985
137416
|
}
|
|
136986
|
-
function connection2(items, args, key3,
|
|
137417
|
+
function connection2(items, args, key3, shape4) {
|
|
136987
137418
|
const { first, last, after, before } = args;
|
|
136988
137419
|
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" } });
|
|
136989
137420
|
for (const [name5, n] of [["first", first], ["last", last]]) {
|
|
@@ -137007,16 +137438,16 @@ function connection2(items, args, key3, shape3) {
|
|
|
137007
137438
|
};
|
|
137008
137439
|
return {
|
|
137009
137440
|
get edges() {
|
|
137010
|
-
return page15.map((item2) => ({ cursor: cursor4(item2), node:
|
|
137441
|
+
return page15.map((item2) => ({ cursor: cursor4(item2), node: shape4(item2) }));
|
|
137011
137442
|
},
|
|
137012
137443
|
get nodes() {
|
|
137013
|
-
return page15.map(
|
|
137444
|
+
return page15.map(shape4);
|
|
137014
137445
|
},
|
|
137015
137446
|
pageInfo: { hasNextPage: end < ordered2.length, hasPreviousPage: start > 0, startCursor: page15.length ? cursor4(page15[0]) : null, endCursor: page15.length ? cursor4(page15[page15.length - 1]) : null }
|
|
137016
137447
|
};
|
|
137017
137448
|
}
|
|
137018
137449
|
var byNum = (d) => ({ id: numOf(d.gid) });
|
|
137019
|
-
var
|
|
137450
|
+
var pathOf3 = (path4) => path4 ? [...pathOf3(path4.prev), path4.key] : [];
|
|
137020
137451
|
var firstOf = (items, n) => typeof n === "number" ? items.slice(0, Math.max(0, n)) : items;
|
|
137021
137452
|
var currencyOf = (ctx) => all6(ctx, "Shop")[0].currency;
|
|
137022
137453
|
var bag = (ctx, c) => {
|
|
@@ -137355,7 +137786,7 @@ function customerShape(req, c) {
|
|
|
137355
137786
|
},
|
|
137356
137787
|
defaultAddress: addressShape(c.address),
|
|
137357
137788
|
addresses: ({ first }) => firstOf(c.address ? [addressShape(c.address)] : [], first),
|
|
137358
|
-
orders: (args, _req, info) => ordersConnection(req, orders(), args,
|
|
137789
|
+
orders: (args, _req, info) => ordersConnection(req, orders(), args, pathOf3(info.path))
|
|
137359
137790
|
};
|
|
137360
137791
|
}
|
|
137361
137792
|
function orderShape(req, o) {
|
|
@@ -137873,21 +138304,21 @@ var now6 = (req) => req.ctx.clock.nowMs();
|
|
|
137873
138304
|
var field2 = (...parts3) => parts3.map(String);
|
|
137874
138305
|
function queryRoot(req) {
|
|
137875
138306
|
const ctx = req.ctx;
|
|
137876
|
-
const one7 = (kind,
|
|
138307
|
+
const one7 = (kind, shape4) => ({ id: id12 }) => {
|
|
137877
138308
|
const d = loadKind(ctx, kind, checkId(id12));
|
|
137878
|
-
return d ?
|
|
138309
|
+
return d ? shape4(req, d) : null;
|
|
137879
138310
|
};
|
|
137880
138311
|
return {
|
|
137881
138312
|
shop: () => shopShape(req),
|
|
137882
|
-
orders: (args, _r, info) => ordersConnection(req, all6(ctx, "Order"), args,
|
|
138313
|
+
orders: (args, _r, info) => ordersConnection(req, all6(ctx, "Order"), args, pathOf3(info.path)),
|
|
137883
138314
|
order: one7("Order", orderShape),
|
|
137884
|
-
products: (args, _r, info) => productsConnection(req, args,
|
|
138315
|
+
products: (args, _r, info) => productsConnection(req, args, pathOf3(info.path)),
|
|
137885
138316
|
product: one7("Product", productShape),
|
|
137886
|
-
productVariants: (args, _r, info) => variantsConnection(req, args,
|
|
138317
|
+
productVariants: (args, _r, info) => variantsConnection(req, args, pathOf3(info.path)),
|
|
137887
138318
|
productVariant: one7("ProductVariant", variantShape),
|
|
137888
|
-
customers: (args, _r, info) => customersConnection(req, args,
|
|
138319
|
+
customers: (args, _r, info) => customersConnection(req, args, pathOf3(info.path)),
|
|
137889
138320
|
customer: one7("Customer", customerShape),
|
|
137890
|
-
locations: (args, _r, info) => locationsConnection(req, args,
|
|
138321
|
+
locations: (args, _r, info) => locationsConnection(req, args, pathOf3(info.path)),
|
|
137891
138322
|
// Without an id, Shopify returns the primary location.
|
|
137892
138323
|
location: ({ id: id12 }) => {
|
|
137893
138324
|
const d = id12 === void 0 || id12 === null ? all6(ctx, "Location")[0] : loadKind(ctx, "Location", checkId(id12));
|
|
@@ -137917,12 +138348,12 @@ function idempotency2(req, info, args) {
|
|
|
137917
138348
|
return { key: key3, fingerprint: `${name5}
|
|
137918
138349
|
${JSON.stringify(args)}` };
|
|
137919
138350
|
}
|
|
137920
|
-
function once(req, info, args, run3,
|
|
138351
|
+
function once(req, info, args, run3, shape4, mismatch) {
|
|
137921
138352
|
const idem = idempotency2(req, info, args);
|
|
137922
138353
|
if (!idem) return run3().payload;
|
|
137923
138354
|
const db2 = req.ctx.store.db;
|
|
137924
138355
|
const seen = db2.prepare("SELECT fingerprint, response FROM shopify_idempotency WHERE key = ?").get(idem.key);
|
|
137925
|
-
if (seen) return seen.fingerprint === idem.fingerprint && seen.response ?
|
|
138356
|
+
if (seen) return seen.fingerprint === idem.fingerprint && seen.response ? shape4(seen.response) : mismatch();
|
|
137926
138357
|
const result = run3();
|
|
137927
138358
|
if (result.made) db2.prepare("INSERT INTO shopify_idempotency (key, fingerprint, response) VALUES (?, ?, ?)").run(idem.key, idem.fingerprint, result.made);
|
|
137928
138359
|
return result.payload;
|
|
@@ -138279,14 +138710,14 @@ function inventoryAdjust(req, input2) {
|
|
|
138279
138710
|
changes.push({ item: item2.gid, location: location.gid, delta: c.delta, before: current, ledger: c.ledgerDocumentUri ?? null, on_hand: quantities(ctx, l).on_hand });
|
|
138280
138711
|
});
|
|
138281
138712
|
if (errors2.length) return fail6(errors2);
|
|
138282
|
-
const at2 = now6(req),
|
|
138713
|
+
const at2 = now6(req), recorded2 = [];
|
|
138283
138714
|
for (const c of changes) {
|
|
138284
138715
|
const column = input2.name;
|
|
138285
138716
|
ctx.store.db.prepare(`UPDATE shopify_inventory SET ${column} = ${column} + ?, updated_ms = ? WHERE item = ? AND location = ?`).run(c.delta, at2, c.item, c.location);
|
|
138286
|
-
|
|
138287
|
-
if (input2.name !== "incoming")
|
|
138717
|
+
recorded2.push({ name: input2.name, delta: c.delta, after: c.before + c.delta, item: c.item, location: c.location, ledger: c.ledger });
|
|
138718
|
+
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 });
|
|
138288
138719
|
}
|
|
138289
|
-
const group5 = save8(ctx, "InventoryAdjustmentGroup", { gid: gid("InventoryAdjustmentGroup", nextNum(ctx, "InventoryAdjustmentGroup")), reason: input2.reason, reference: input2.referenceDocumentUri ?? null, created_ms: at2, changes:
|
|
138720
|
+
const group5 = save8(ctx, "InventoryAdjustmentGroup", { gid: gid("InventoryAdjustmentGroup", nextNum(ctx, "InventoryAdjustmentGroup")), reason: input2.reason, reference: input2.referenceDocumentUri ?? null, created_ms: at2, changes: recorded2 });
|
|
138290
138721
|
return { made: group5.gid, payload: { inventoryAdjustmentGroup: adjustmentGroupShape(req, group5), userErrors: [] } };
|
|
138291
138722
|
}
|
|
138292
138723
|
function inventorySet(req, input2) {
|
|
@@ -138311,13 +138742,13 @@ function inventorySet(req, input2) {
|
|
|
138311
138742
|
sets.push({ item: item2.gid, location: location.gid, delta: q.quantity - current, available: have.available, on_hand: have.on_hand });
|
|
138312
138743
|
});
|
|
138313
138744
|
if (errors2.length) return fail6(errors2);
|
|
138314
|
-
const at2 = now6(req),
|
|
138745
|
+
const at2 = now6(req), recorded2 = [];
|
|
138315
138746
|
for (const s of sets) {
|
|
138316
138747
|
setAvailable(ctx, s.item, s.location, s.available + s.delta, at2);
|
|
138317
|
-
|
|
138318
|
-
|
|
138748
|
+
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 });
|
|
138749
|
+
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 });
|
|
138319
138750
|
}
|
|
138320
|
-
const group5 = save8(ctx, "InventoryAdjustmentGroup", { gid: gid("InventoryAdjustmentGroup", nextNum(ctx, "InventoryAdjustmentGroup")), reason: input2.reason, reference: input2.referenceDocumentUri ?? null, created_ms: at2, changes:
|
|
138751
|
+
const group5 = save8(ctx, "InventoryAdjustmentGroup", { gid: gid("InventoryAdjustmentGroup", nextNum(ctx, "InventoryAdjustmentGroup")), reason: input2.reason, reference: input2.referenceDocumentUri ?? null, created_ms: at2, changes: recorded2 });
|
|
138321
138752
|
return { made: group5.gid, payload: { inventoryAdjustmentGroup: adjustmentGroupShape(req, group5), userErrors: [] } };
|
|
138322
138753
|
}
|
|
138323
138754
|
function customerWrite(req, input2, create2) {
|
|
@@ -138909,7 +139340,7 @@ function shopifyTwin() {
|
|
|
138909
139340
|
const app2 = new Hono3();
|
|
138910
139341
|
app2.post("/admin/api/:version/graphql.json", handleGraphql2);
|
|
138911
139342
|
app2.all("*", unknownRoute12);
|
|
138912
|
-
return { name: "shopify", basePath: "", app: app2, migrate:
|
|
139343
|
+
return { name: "shopify", basePath: "", app: app2, migrate: migrate27, seed: seed27, credentials: credentials26, actions: {}, checks: {}, dumpState: dumpState26, coverage: shopifyCoverage };
|
|
138913
139344
|
}
|
|
138914
139345
|
|
|
138915
139346
|
// packages/server/src/twins/lob/db.ts
|
|
@@ -139215,7 +139646,7 @@ function assetUrl(ctx, kind, id12) {
|
|
|
139215
139646
|
}
|
|
139216
139647
|
|
|
139217
139648
|
// packages/server/src/twins/lob/db.ts
|
|
139218
|
-
var
|
|
139649
|
+
var SCHEMA17 = `
|
|
139219
139650
|
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);
|
|
139220
139651
|
CREATE INDEX lob_directory_street ON lob_directory (primary_line, zip5);
|
|
139221
139652
|
CREATE TABLE lob_addresses (
|
|
@@ -139236,8 +139667,8 @@ CREATE TABLE lob_mail (
|
|
|
139236
139667
|
CREATE TABLE lob_files (id TEXT PRIMARY KEY, name TEXT NOT NULL, type TEXT NOT NULL, bytes BLOB NOT NULL);
|
|
139237
139668
|
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));
|
|
139238
139669
|
`;
|
|
139239
|
-
function
|
|
139240
|
-
db2.exec(
|
|
139670
|
+
function migrate28(db2) {
|
|
139671
|
+
db2.exec(SCHEMA17);
|
|
139241
139672
|
}
|
|
139242
139673
|
var LENGTH = { adr: 16, ltr: 16, psc: 16, chk: 16, bank: 15, tmpl: 15, vrsn: 15, file: 16 };
|
|
139243
139674
|
var seededId4 = (prefix2, key3) => `${prefix2}_${createHash40("sha256").update(`lob:${prefix2}:${key3}`).digest("hex").slice(0, LENGTH[prefix2])}`;
|
|
@@ -140326,11 +140757,11 @@ async function handle18(c) {
|
|
|
140326
140757
|
function lobTwin() {
|
|
140327
140758
|
const app2 = new Hono3();
|
|
140328
140759
|
app2.all("*", handle18);
|
|
140329
|
-
return { name: "lob", basePath: "/v1", app: app2, migrate:
|
|
140760
|
+
return { name: "lob", basePath: "/v1", app: app2, migrate: migrate28, seed: seed28, credentials: credentials27, dumpState: dumpState27, actions: {}, checks: {}, coverage: lobCoverage };
|
|
140330
140761
|
}
|
|
140331
140762
|
|
|
140332
140763
|
// packages/server/src/twins/paypal/db.ts
|
|
140333
|
-
function
|
|
140764
|
+
function migrate29(db2) {
|
|
140334
140765
|
db2.exec(`
|
|
140335
140766
|
CREATE TABLE paypal_objects (id TEXT PRIMARY KEY, kind TEXT NOT NULL, created_ms INTEGER NOT NULL, json TEXT NOT NULL);
|
|
140336
140767
|
CREATE INDEX paypal_objects_kind ON paypal_objects (kind, created_ms);
|
|
@@ -140875,8 +141306,8 @@ var orderRoutes = [
|
|
|
140875
141306
|
description: u.description
|
|
140876
141307
|
});
|
|
140877
141308
|
save9(r.ctx, "authorization", touch3(r, a));
|
|
140878
|
-
const
|
|
140879
|
-
return [201, r.prefer === "representation" ?
|
|
141309
|
+
const shape4 = captureShape(r, c);
|
|
141310
|
+
return [201, r.prefer === "representation" ? shape4 : { id: shape4.id, status: shape4.status, links: shape4.links }];
|
|
140880
141311
|
}
|
|
140881
141312
|
},
|
|
140882
141313
|
{
|
|
@@ -140911,8 +141342,8 @@ var orderRoutes = [
|
|
|
140911
141342
|
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");
|
|
140912
141343
|
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 });
|
|
140913
141344
|
save9(r.ctx, "capture", { ...c, update_ms: r.ctx.clock.nowMs() });
|
|
140914
|
-
const
|
|
140915
|
-
return [201, r.prefer === "representation" ?
|
|
141345
|
+
const shape4 = refundShape2(r, x);
|
|
141346
|
+
return [201, r.prefer === "representation" ? shape4 : { id: shape4.id, status: shape4.status, links: shape4.links }];
|
|
140916
141347
|
}
|
|
140917
141348
|
},
|
|
140918
141349
|
{ 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"))) }
|
|
@@ -141652,11 +142083,11 @@ function paypalTwin() {
|
|
|
141652
142083
|
const rank = (path4) => path4.split("/").filter((s) => s.startsWith(":")).length;
|
|
141653
142084
|
for (const route11 of [...paypalRoutes].sort((a, b) => rank(a.path) - rank(b.path))) app2.on(route11.method, route11.path, handle19(route11));
|
|
141654
142085
|
app2.all("*", unknownRoute13);
|
|
141655
|
-
return { name: "paypal", basePath: "", app: app2, migrate:
|
|
142086
|
+
return { name: "paypal", basePath: "", app: app2, migrate: migrate29, seed: seed29, credentials: credentials28, actions: {}, checks: {}, dumpState: dumpState28, coverage: paypalCoverage };
|
|
141656
142087
|
}
|
|
141657
142088
|
|
|
141658
142089
|
// packages/server/src/twins/jira/db.ts
|
|
141659
|
-
function
|
|
142090
|
+
function migrate30(db2) {
|
|
141660
142091
|
db2.exec(`
|
|
141661
142092
|
CREATE TABLE jira_site (id INTEGER PRIMARY KEY CHECK (id = 1), json TEXT NOT NULL);
|
|
141662
142093
|
CREATE TABLE jira_users (account_id TEXT PRIMARY KEY, seq INTEGER NOT NULL, json TEXT NOT NULL);
|
|
@@ -143777,7 +144208,7 @@ function jiraTwin() {
|
|
|
143777
144208
|
else for (const api3 of ["3", "2"]) app2.on(route11.method, `/rest/api/${api3}${route11.path}`, handle20(route11, api3));
|
|
143778
144209
|
}
|
|
143779
144210
|
app2.all("*", unknownRoute14);
|
|
143780
|
-
return { name: "jira", basePath: "", app: app2, migrate:
|
|
144211
|
+
return { name: "jira", basePath: "", app: app2, migrate: migrate30, seed: seed30, credentials: credentials29, actions: {}, checks: {}, dumpState: dumpState29, coverage: jiraCoverage };
|
|
143781
144212
|
}
|
|
143782
144213
|
|
|
143783
144214
|
// packages/server/src/twins/kalshi/index.ts
|
|
@@ -143825,7 +144256,7 @@ function rsaPrivateKey(secrets) {
|
|
|
143825
144256
|
}
|
|
143826
144257
|
|
|
143827
144258
|
// packages/server/src/twins/kalshi/db.ts
|
|
143828
|
-
var
|
|
144259
|
+
var SCHEMA18 = `
|
|
143829
144260
|
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);
|
|
143830
144261
|
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);
|
|
143831
144262
|
CREATE TABLE kx_markets (
|
|
@@ -143847,8 +144278,8 @@ CREATE TABLE kx_fills (
|
|
|
143847
144278
|
);
|
|
143848
144279
|
CREATE TABLE kx_deposits (id INTEGER PRIMARY KEY, amount INTEGER NOT NULL, at_ms INTEGER NOT NULL);
|
|
143849
144280
|
`;
|
|
143850
|
-
function
|
|
143851
|
-
db2.exec(
|
|
144281
|
+
function migrate31(db2) {
|
|
144282
|
+
db2.exec(SCHEMA18);
|
|
143852
144283
|
}
|
|
143853
144284
|
var ONE = 1e4;
|
|
143854
144285
|
var dollars2 = (price3) => (price3 / ONE).toFixed(4);
|
|
@@ -144875,12 +145306,12 @@ async function handle21(c) {
|
|
|
144875
145306
|
function kalshiTwin() {
|
|
144876
145307
|
const app2 = new Hono3();
|
|
144877
145308
|
app2.all("*", handle21);
|
|
144878
|
-
return { name: "kalshi", basePath: "/trade-api/v2", app: app2, migrate:
|
|
145309
|
+
return { name: "kalshi", basePath: "/trade-api/v2", app: app2, migrate: migrate31, seed: seed31, credentials: credentials30, dumpState: dumpState30, actions: {}, checks: {}, coverage: kalshiCoverage };
|
|
144879
145310
|
}
|
|
144880
145311
|
|
|
144881
145312
|
// packages/server/src/twins/intercom/request.ts
|
|
144882
145313
|
import { createHash as createHash43 } from "node:crypto";
|
|
144883
|
-
function
|
|
145314
|
+
function migrate32(db2) {
|
|
144884
145315
|
db2.exec(`
|
|
144885
145316
|
CREATE TABLE intercom_objects (kind TEXT NOT NULL, id TEXT NOT NULL, seq INTEGER NOT NULL, json TEXT NOT NULL, PRIMARY KEY (kind, id));
|
|
144886
145317
|
CREATE INDEX intercom_objects_seq ON intercom_objects (kind, seq);
|
|
@@ -146095,11 +146526,11 @@ function intercomTwin() {
|
|
|
146095
146526
|
const rank = (path4) => path4.split("/").filter((s) => s.startsWith(":")).length;
|
|
146096
146527
|
for (const route11 of [...intercomRoutes].sort((a, b) => rank(a.path) - rank(b.path))) app2.on(route11.method, route11.path, handle22(route11));
|
|
146097
146528
|
app2.all("*", unknownRoute15);
|
|
146098
|
-
return { name: "intercom", basePath: "", app: app2, migrate:
|
|
146529
|
+
return { name: "intercom", basePath: "", app: app2, migrate: migrate32, seed: seed32, credentials: credentials31, actions: {}, checks: {}, dumpState: dumpState31, coverage: intercomCoverage };
|
|
146099
146530
|
}
|
|
146100
146531
|
|
|
146101
146532
|
// packages/server/src/twins/zendesk/db.ts
|
|
146102
|
-
var
|
|
146533
|
+
var SCHEMA19 = `
|
|
146103
146534
|
CREATE TABLE zd_users (
|
|
146104
146535
|
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,
|
|
146105
146536
|
suspended INTEGER NOT NULL, external_id TEXT, default_group_id INTEGER, created_ms INTEGER NOT NULL, updated_ms INTEGER NOT NULL
|
|
@@ -146116,8 +146547,8 @@ CREATE TABLE zd_audits (id INTEGER PRIMARY KEY, ticket_id INTEGER NOT NULL, auth
|
|
|
146116
146547
|
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);
|
|
146117
146548
|
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);
|
|
146118
146549
|
`;
|
|
146119
|
-
function
|
|
146120
|
-
db2.exec(
|
|
146550
|
+
function migrate33(db2) {
|
|
146551
|
+
db2.exec(SCHEMA19);
|
|
146121
146552
|
}
|
|
146122
146553
|
var BASES2 = { user: 21457810001, organization: 360041201001, group: 360000118001, ticket: 4101, comment: 31870100001, audit: 31870200001, macro: 360101000001, view: 360102000001 };
|
|
146123
146554
|
function nextId6(ctx, kind) {
|
|
@@ -146303,20 +146734,20 @@ var ordered = (order4, actual, term) => {
|
|
|
146303
146734
|
if (b < 0 || a < 0) return term.op === ":" && term.value.toLowerCase() === "none" && actual === null;
|
|
146304
146735
|
return term.op === ":" ? a === b : term.op === "<" ? a < b : term.op === ">" ? a > b : term.op === "<=" ? a <= b : a >= b;
|
|
146305
146736
|
};
|
|
146306
|
-
var
|
|
146737
|
+
var contains2 = (haystack, needle) => haystack.toLowerCase().includes(needle.toLowerCase());
|
|
146307
146738
|
var person3 = (world4, id12, value4) => {
|
|
146308
146739
|
if (value4 === "none") return id12 === null;
|
|
146309
146740
|
if (id12 === null) return false;
|
|
146310
146741
|
const user8 = world4.users.get(id12);
|
|
146311
|
-
return value4 === "me" ? id12 === world4.me.id : !!user8 && (String(user8.id) === value4 || user8.email === value4.toLowerCase() ||
|
|
146742
|
+
return value4 === "me" ? id12 === world4.me.id : !!user8 && (String(user8.id) === value4 || user8.email === value4.toLowerCase() || contains2(user8.name, value4));
|
|
146312
146743
|
};
|
|
146313
|
-
var named2 = (map2, id12, value4) => value4 === "none" ? id12 === null : id12 !== null && (String(id12) === value4 ||
|
|
146744
|
+
var named2 = (map2, id12, value4) => value4 === "none" ? id12 === null : id12 !== null && (String(id12) === value4 || contains2(map2.get(id12)?.name ?? "", value4));
|
|
146314
146745
|
function ticketMatches(world4, ticket2, term) {
|
|
146315
146746
|
const tags4 = tagsOf(ticket2.tags);
|
|
146316
146747
|
switch (term.key) {
|
|
146317
146748
|
case null: {
|
|
146318
146749
|
const text21 = [ticket2.subject, ticket2.description, ...commentsOf2(world4.ctx, ticket2.id).map((comment8) => comment8.body), ...tags4].join("\n");
|
|
146319
|
-
return
|
|
146750
|
+
return contains2(text21, term.value);
|
|
146320
146751
|
}
|
|
146321
146752
|
case "status":
|
|
146322
146753
|
return ordered(STATUSES2, ticket2.status, term);
|
|
@@ -146338,11 +146769,11 @@ function ticketMatches(world4, ticket2, term) {
|
|
|
146338
146769
|
case "tag":
|
|
146339
146770
|
return tags4.includes(term.value.toLowerCase());
|
|
146340
146771
|
case "subject":
|
|
146341
|
-
return
|
|
146772
|
+
return contains2(ticket2.subject, term.value);
|
|
146342
146773
|
case "description":
|
|
146343
|
-
return
|
|
146774
|
+
return contains2(ticket2.description, term.value);
|
|
146344
146775
|
case "comment":
|
|
146345
|
-
return commentsOf2(world4.ctx, ticket2.id).some((comment8) =>
|
|
146776
|
+
return commentsOf2(world4.ctx, ticket2.id).some((comment8) => contains2(comment8.body, term.value));
|
|
146346
146777
|
case "via":
|
|
146347
146778
|
return ticket2.via === term.value.toLowerCase();
|
|
146348
146779
|
case "external_id":
|
|
@@ -146361,10 +146792,10 @@ function ticketMatches(world4, ticket2, term) {
|
|
|
146361
146792
|
function userMatches2(world4, user8, term) {
|
|
146362
146793
|
switch (term.key) {
|
|
146363
146794
|
case null:
|
|
146364
|
-
return
|
|
146795
|
+
return contains2(`${user8.name}
|
|
146365
146796
|
${user8.email ?? ""}`, term.value);
|
|
146366
146797
|
case "name":
|
|
146367
|
-
return
|
|
146798
|
+
return contains2(user8.name, term.value);
|
|
146368
146799
|
case "email":
|
|
146369
146800
|
return (user8.email ?? "") === term.value.toLowerCase() || term.value.startsWith("*") && (user8.email ?? "").endsWith(term.value.slice(1).toLowerCase());
|
|
146370
146801
|
case "role":
|
|
@@ -146388,10 +146819,10 @@ ${user8.email ?? ""}`, term.value);
|
|
|
146388
146819
|
function organizationMatches(world4, organization4, term) {
|
|
146389
146820
|
switch (term.key) {
|
|
146390
146821
|
case null:
|
|
146391
|
-
return
|
|
146822
|
+
return contains2(`${organization4.name}
|
|
146392
146823
|
${JSON.parse(organization4.domains).join(" ")}`, term.value);
|
|
146393
146824
|
case "name":
|
|
146394
|
-
return
|
|
146825
|
+
return contains2(organization4.name, term.value);
|
|
146395
146826
|
case "tags":
|
|
146396
146827
|
case "tag":
|
|
146397
146828
|
return tagsOf(organization4.tags).includes(term.value.toLowerCase());
|
|
@@ -146403,7 +146834,7 @@ ${JSON.parse(organization4.domains).join(" ")}`, term.value);
|
|
|
146403
146834
|
}
|
|
146404
146835
|
}
|
|
146405
146836
|
function groupMatches(world4, group5, term) {
|
|
146406
|
-
if (term.key === null || term.key === "name") return
|
|
146837
|
+
if (term.key === null || term.key === "name") return contains2(group5.name, term.value);
|
|
146407
146838
|
return world4.unsupported(`the group search property ${term.key}`);
|
|
146408
146839
|
}
|
|
146409
146840
|
|
|
@@ -147227,11 +147658,11 @@ async function handle23(c) {
|
|
|
147227
147658
|
function zendeskTwin() {
|
|
147228
147659
|
const app2 = new Hono3();
|
|
147229
147660
|
app2.all("*", handle23);
|
|
147230
|
-
return { name: "zendesk", basePath: "/api/v2", app: app2, migrate:
|
|
147661
|
+
return { name: "zendesk", basePath: "/api/v2", app: app2, migrate: migrate33, seed: seed33, credentials: credentials32, dumpState: dumpState32, actions: {}, checks: {}, coverage: zendeskCoverage };
|
|
147231
147662
|
}
|
|
147232
147663
|
|
|
147233
147664
|
// packages/server/src/twins/google-calendar/request.ts
|
|
147234
|
-
function
|
|
147665
|
+
function migrate34(db2) {
|
|
147235
147666
|
db2.exec(`
|
|
147236
147667
|
CREATE TABLE gcal_owner (id INTEGER PRIMARY KEY CHECK (id = 1), json TEXT NOT NULL);
|
|
147237
147668
|
CREATE TABLE gcal_calendars (id TEXT PRIMARY KEY, seq INTEGER NOT NULL, json TEXT NOT NULL);
|
|
@@ -147830,12 +148261,12 @@ function listEvents3(r, cal, only4) {
|
|
|
147830
148261
|
defaultReminders: writable2(cal) ? [{ method: "popup", minutes: 10 }] : [],
|
|
147831
148262
|
...p2.next && { nextPageToken: p2.next },
|
|
147832
148263
|
items: p2.slice.map(({ e, at: at2 }) => {
|
|
147833
|
-
const
|
|
147834
|
-
if (maxAttendees !== null &&
|
|
147835
|
-
|
|
147836
|
-
|
|
148264
|
+
const shape4 = eventShape2(r, e, tz, at2, limited);
|
|
148265
|
+
if (maxAttendees !== null && shape4.attendees?.length > maxAttendees) {
|
|
148266
|
+
shape4.attendees = shape4.attendees.filter((a) => a.self).slice(0, 1);
|
|
148267
|
+
shape4.attendeesOmitted = true;
|
|
147837
148268
|
}
|
|
147838
|
-
return
|
|
148269
|
+
return shape4;
|
|
147839
148270
|
})
|
|
147840
148271
|
};
|
|
147841
148272
|
}
|
|
@@ -148251,12 +148682,12 @@ function googleCalendarTwin() {
|
|
|
148251
148682
|
const rank = (path4) => path4.split("/").filter((s) => s.startsWith(":")).length;
|
|
148252
148683
|
for (const route11 of [...calendarRoutes].sort((a, b) => rank(a.path) - rank(b.path))) app2.on(route11.method, route11.path, handle24(route11));
|
|
148253
148684
|
app2.all("*", unknownRoute16);
|
|
148254
|
-
return { name: "google-calendar", basePath: "", unprefixedPaths: /^\/calendar\/v3\//, app: app2, migrate:
|
|
148685
|
+
return { name: "google-calendar", basePath: "", unprefixedPaths: /^\/calendar\/v3\//, app: app2, migrate: migrate34, seed: seed34, credentials: credentials33, actions: {}, checks: {}, dumpState: dumpState33, coverage: googleCalendarCoverage };
|
|
148255
148686
|
}
|
|
148256
148687
|
|
|
148257
148688
|
// packages/server/src/twins/twilio/db.ts
|
|
148258
148689
|
import { createHash as createHash45 } from "node:crypto";
|
|
148259
|
-
var
|
|
148690
|
+
var SCHEMA20 = `
|
|
148260
148691
|
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);
|
|
148261
148692
|
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);
|
|
148262
148693
|
CREATE TABLE tw_messages (
|
|
@@ -148273,8 +148704,8 @@ CREATE TABLE tw_verifications (
|
|
|
148273
148704
|
created_ms INTEGER NOT NULL, updated_ms INTEGER NOT NULL
|
|
148274
148705
|
);
|
|
148275
148706
|
`;
|
|
148276
|
-
function
|
|
148277
|
-
db2.exec(
|
|
148707
|
+
function migrate35(db2) {
|
|
148708
|
+
db2.exec(SCHEMA20);
|
|
148278
148709
|
}
|
|
148279
148710
|
var seededSid = (prefix2, key3) => `${prefix2}${createHash45("sha256").update(`twilio:${prefix2}:${key3}`).digest("hex").slice(0, 32)}`;
|
|
148280
148711
|
var newSid = (ctx, prefix2) => `${prefix2}${ctx.ids.hex(32)}`;
|
|
@@ -148933,11 +149364,11 @@ async function handle25(c) {
|
|
|
148933
149364
|
function twilioTwin() {
|
|
148934
149365
|
const app2 = new Hono3();
|
|
148935
149366
|
app2.all("*", handle25);
|
|
148936
|
-
return { name: "twilio", basePath: "", app: app2, migrate:
|
|
149367
|
+
return { name: "twilio", basePath: "", app: app2, migrate: migrate35, seed: seed35, credentials: credentials34, dumpState: dumpState34, actions: {}, checks: {}, coverage: twilioCoverage };
|
|
148937
149368
|
}
|
|
148938
149369
|
|
|
148939
149370
|
// packages/server/src/twins/asana/db.ts
|
|
148940
|
-
var
|
|
149371
|
+
var SCHEMA21 = `
|
|
148941
149372
|
CREATE TABLE as_users (gid TEXT PRIMARY KEY, email TEXT NOT NULL UNIQUE, name TEXT NOT NULL);
|
|
148942
149373
|
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);
|
|
148943
149374
|
CREATE TABLE as_project_members (project TEXT NOT NULL, user TEXT NOT NULL, PRIMARY KEY (project, user));
|
|
@@ -148950,8 +149381,8 @@ CREATE TABLE as_memberships (task TEXT NOT NULL, project TEXT NOT NULL, section
|
|
|
148950
149381
|
CREATE TABLE as_followers (task TEXT NOT NULL, user TEXT NOT NULL, PRIMARY KEY (task, user));
|
|
148951
149382
|
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);
|
|
148952
149383
|
`;
|
|
148953
|
-
function
|
|
148954
|
-
db2.exec(
|
|
149384
|
+
function migrate36(db2) {
|
|
149385
|
+
db2.exec(SCHEMA21);
|
|
148955
149386
|
}
|
|
148956
149387
|
var BASES3 = { workspace: 1200000000000001, user: 1201000000000001, project: 1205000000000001, section: 1206000000000001, task: 1208000000000001, story: 1210000000000001 };
|
|
148957
149388
|
function nextGid(ctx, kind) {
|
|
@@ -149249,22 +149680,22 @@ function treeOf(fields11) {
|
|
|
149249
149680
|
}
|
|
149250
149681
|
return root2;
|
|
149251
149682
|
}
|
|
149252
|
-
function
|
|
149253
|
-
if (Array.isArray(value4)) return value4.map((item2) =>
|
|
149683
|
+
function shape3(ctx, value4, tree) {
|
|
149684
|
+
if (Array.isArray(value4)) return value4.map((item2) => shape3(ctx, item2, tree));
|
|
149254
149685
|
if (value4 === null || typeof value4 !== "object") return value4;
|
|
149255
149686
|
let record8 = value4;
|
|
149256
149687
|
if (record8.resource_type && record8.gid && [...tree.keys()].some((field3) => !(field3 in record8))) record8 = expand2(ctx, record8);
|
|
149257
149688
|
const out = "gid" in record8 ? { gid: record8.gid } : {};
|
|
149258
|
-
for (const [field3, child2] of tree) if (field3 in record8) out[field3] = child2.size ?
|
|
149689
|
+
for (const [field3, child2] of tree) if (field3 in record8) out[field3] = child2.size ? shape3(ctx, record8[field3], child2) : record8[field3];
|
|
149259
149690
|
return out;
|
|
149260
149691
|
}
|
|
149261
149692
|
function one5(call2, full2) {
|
|
149262
149693
|
const tree = treeOf(call2.url.searchParams.get("opt_fields"));
|
|
149263
|
-
return json26({ data: tree ?
|
|
149694
|
+
return json26({ data: tree ? shape3(call2.ctx, full2, tree) : full2 });
|
|
149264
149695
|
}
|
|
149265
149696
|
function list14(call2, items, full2, compact2) {
|
|
149266
149697
|
const params9 = call2.url.searchParams, tree = treeOf(params9.get("opt_fields"));
|
|
149267
|
-
const render = (item2) => tree ?
|
|
149698
|
+
const render = (item2) => tree ? shape3(call2.ctx, full2(item2), tree) : compact2(item2);
|
|
149268
149699
|
if (params9.get("limit") === null) return json26({ data: items.map(render) });
|
|
149269
149700
|
const limit = Number(params9.get("limit")), offset16 = params9.get("offset");
|
|
149270
149701
|
if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw bad("limit: Value must be between 1 and 100");
|
|
@@ -149626,7 +150057,7 @@ function searchTasks(call2) {
|
|
|
149626
150057
|
return (x < y ? -1 : x > y ? 1 : a.gid < b.gid ? -1 : 1) * (ascending ? 1 : -1);
|
|
149627
150058
|
});
|
|
149628
150059
|
const tree = treeOf(params9.get("opt_fields"));
|
|
149629
|
-
return json26({ data: tasks.slice(0, limit).map((task2) => tree ?
|
|
150060
|
+
return json26({ data: tasks.slice(0, limit).map((task2) => tree ? shape3(ctx, taskFull(ctx, task2), tree) : taskCompact(task2)) });
|
|
149630
150061
|
}
|
|
149631
150062
|
var route8 = (method2, path4, write4, handle30, notes6) => ({ method: method2, path: path4, write: write4, handle: handle30, ...notes6 && { notes: notes6 }, pattern: new RegExp(`^${path4.replace(/\{[^}]+\}/g, "([^/]+)")}$`) });
|
|
149632
150063
|
var API = "/api/1.0";
|
|
@@ -149750,11 +150181,11 @@ async function handle26(c) {
|
|
|
149750
150181
|
function asanaTwin() {
|
|
149751
150182
|
const app2 = new Hono3();
|
|
149752
150183
|
app2.all("*", handle26);
|
|
149753
|
-
return { name: "asana", basePath: "/api/1.0", app: app2, migrate:
|
|
150184
|
+
return { name: "asana", basePath: "/api/1.0", app: app2, migrate: migrate36, seed: seed36, credentials: credentials35, dumpState: dumpState35, actions: {}, checks: {}, coverage: asanaCoverage };
|
|
149754
150185
|
}
|
|
149755
150186
|
|
|
149756
150187
|
// packages/server/src/twins/discord/db.ts
|
|
149757
|
-
var
|
|
150188
|
+
var SCHEMA22 = `
|
|
149758
150189
|
CREATE TABLE dc_users (id TEXT PRIMARY KEY, username TEXT NOT NULL UNIQUE, global_name TEXT, bot INTEGER NOT NULL);
|
|
149759
150190
|
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);
|
|
149760
150191
|
CREATE TABLE dc_members (user_id TEXT PRIMARY KEY, nick TEXT, roles TEXT NOT NULL, joined_ms INTEGER NOT NULL);
|
|
@@ -149768,8 +150199,8 @@ CREATE TABLE dc_messages (
|
|
|
149768
150199
|
);
|
|
149769
150200
|
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));
|
|
149770
150201
|
`;
|
|
149771
|
-
function
|
|
149772
|
-
db2.exec(
|
|
150202
|
+
function migrate37(db2) {
|
|
150203
|
+
db2.exec(SCHEMA22);
|
|
149773
150204
|
}
|
|
149774
150205
|
var TEXT3 = 0;
|
|
149775
150206
|
var DM = 1;
|
|
@@ -150410,11 +150841,11 @@ async function handle27(c) {
|
|
|
150410
150841
|
function discordTwin() {
|
|
150411
150842
|
const app2 = new Hono3();
|
|
150412
150843
|
app2.all("*", handle27);
|
|
150413
|
-
return { name: "discord", basePath: "/api/v10", app: app2, migrate:
|
|
150844
|
+
return { name: "discord", basePath: "/api/v10", app: app2, migrate: migrate37, seed: seed37, credentials: credentials36, dumpState: dumpState36, actions: {}, checks: {}, coverage: discordCoverage };
|
|
150414
150845
|
}
|
|
150415
150846
|
|
|
150416
150847
|
// packages/server/src/twins/sentry/db.ts
|
|
150417
|
-
function
|
|
150848
|
+
function migrate38(db2) {
|
|
150418
150849
|
db2.exec(`
|
|
150419
150850
|
CREATE TABLE sentry_org (id INTEGER PRIMARY KEY CHECK (id = 1), json TEXT NOT NULL);
|
|
150420
150851
|
CREATE TABLE sentry_members (id TEXT PRIMARY KEY, seq INTEGER NOT NULL, json TEXT NOT NULL);
|
|
@@ -151361,8 +151792,8 @@ function apply(ctx, i, by2, c, ms) {
|
|
|
151361
151792
|
const same2 = c.assign?.type === i.assignee?.type && c.assign?.id === i.assignee?.id;
|
|
151362
151793
|
if (!same2) {
|
|
151363
151794
|
i.assignee = c.assign;
|
|
151364
|
-
const
|
|
151365
|
-
if (
|
|
151795
|
+
const shape4 = actorShape(ctx, c.assign);
|
|
151796
|
+
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);
|
|
151366
151797
|
else activity(ctx, i, "unassigned", by2, {}, ms);
|
|
151367
151798
|
}
|
|
151368
151799
|
delta.assignedTo = actorShape(ctx, i.assignee);
|
|
@@ -152474,11 +152905,11 @@ function sentryTwin() {
|
|
|
152474
152905
|
if (route11.path.startsWith(ISSUE)) app2.on(route11.method, `/api/0/issues/:issue${route11.path.slice(ISSUE.length)}`, handle28(route11));
|
|
152475
152906
|
}
|
|
152476
152907
|
app2.all("*", unknownRoute17);
|
|
152477
|
-
return { name: "sentry", basePath: "", app: app2, migrate:
|
|
152908
|
+
return { name: "sentry", basePath: "", app: app2, migrate: migrate38, seed: seed38, credentials: credentials37, actions: { capture: capture2 }, checks: {}, dumpState: dumpState37, coverage: sentryCoverage };
|
|
152478
152909
|
}
|
|
152479
152910
|
|
|
152480
152911
|
// packages/server/src/twins/airtable/db.ts
|
|
152481
|
-
var
|
|
152912
|
+
var SCHEMA23 = `
|
|
152482
152913
|
CREATE TABLE at_users (id TEXT PRIMARY KEY, name TEXT NOT NULL, email TEXT NOT NULL UNIQUE, position INTEGER NOT NULL);
|
|
152483
152914
|
CREATE TABLE at_bases (id TEXT PRIMARY KEY, name TEXT NOT NULL, permission TEXT NOT NULL, position INTEGER NOT NULL);
|
|
152484
152915
|
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);
|
|
@@ -152494,8 +152925,8 @@ CREATE TABLE at_comments (
|
|
|
152494
152925
|
created_ms INTEGER NOT NULL, updated_ms INTEGER, deleted_ms INTEGER
|
|
152495
152926
|
);
|
|
152496
152927
|
`;
|
|
152497
|
-
function
|
|
152498
|
-
db2.exec(
|
|
152928
|
+
function migrate39(db2) {
|
|
152929
|
+
db2.exec(SCHEMA23);
|
|
152499
152930
|
}
|
|
152500
152931
|
var BASE625 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
152501
152932
|
function newId7(ctx, kind) {
|
|
@@ -153828,7 +154259,7 @@ async function handle29(c) {
|
|
|
153828
154259
|
function airtableTwin() {
|
|
153829
154260
|
const app2 = new Hono3();
|
|
153830
154261
|
app2.all("*", handle29);
|
|
153831
|
-
return { name: "airtable", basePath: "/v0", app: app2, migrate:
|
|
154262
|
+
return { name: "airtable", basePath: "/v0", app: app2, migrate: migrate39, seed: seed39, credentials: credentials38, dumpState: dumpState38, actions: {}, checks: {}, coverage: airtableCoverage };
|
|
153832
154263
|
}
|
|
153833
154264
|
|
|
153834
154265
|
// packages/server/src/registry.ts
|
|
@@ -153857,6 +154288,7 @@ function envInfo(env, origin, port) {
|
|
|
153857
154288
|
};
|
|
153858
154289
|
}
|
|
153859
154290
|
const mcp = Object.fromEntries(Object.entries(env.mcpTokens).map(([tool, token2]) => [tool, { url: `${origin}/e/${env.id}/mcp/${tool}`, token: token2 }]));
|
|
154291
|
+
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 } }));
|
|
153860
154292
|
return {
|
|
153861
154293
|
id: env.id,
|
|
153862
154294
|
sceneId: env.scene.id,
|
|
@@ -153864,6 +154296,7 @@ function envInfo(env, origin, port) {
|
|
|
153864
154296
|
timeScale: env.scene.time_scale,
|
|
153865
154297
|
services: services2,
|
|
153866
154298
|
...Object.keys(mcp).length ? { mcp } : {},
|
|
154299
|
+
...tools.length ? { tools } : {},
|
|
153867
154300
|
...env.sandbox ? { sandbox: { ...structuredClone(env.sandbox), seed: env.seed } } : {}
|
|
153868
154301
|
};
|
|
153869
154302
|
}
|
|
@@ -154711,7 +155144,7 @@ function addressedEvent(env, event3) {
|
|
|
154711
155144
|
// packages/server/src/sessions.ts
|
|
154712
155145
|
function agentCalls(env) {
|
|
154713
155146
|
let calls2;
|
|
154714
|
-
return { first: (pattern) => (calls2 ??= env.trace.list().filter((entry2) => entry2.source === "agent")).find(compileTracePattern(pattern)) };
|
|
155147
|
+
return { first: (pattern) => (calls2 ??= env.trace.list().filter((entry2) => entry2.source === "agent")).find(compileTracePattern(pattern, sceneTools(env))) };
|
|
154715
155148
|
}
|
|
154716
155149
|
function lastTimedActorMs(env) {
|
|
154717
155150
|
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;
|
|
@@ -154906,12 +155339,13 @@ var TrialSessions = class {
|
|
|
154906
155339
|
env.touchLease();
|
|
154907
155340
|
return { env, session: { ...record8.session } };
|
|
154908
155341
|
}
|
|
154909
|
-
done(token2) {
|
|
155342
|
+
done(token2, answer) {
|
|
154910
155343
|
const { env, session } = this.authenticate(token2, true);
|
|
154911
155344
|
return env.serialize(() => {
|
|
154912
155345
|
this.authenticate(token2, true);
|
|
154913
155346
|
const record8 = this.#record(env, session.id);
|
|
154914
155347
|
if (record8.session.state === "prepared") throw new AnchaError("SESSION_CONFLICT", "session has not started");
|
|
155348
|
+
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 } });
|
|
154915
155349
|
if (record8.session.state === "running") record8.session.state = "done";
|
|
154916
155350
|
});
|
|
154917
155351
|
}
|
|
@@ -155269,7 +155703,8 @@ function sessionRoutes(opts, sessions) {
|
|
|
155269
155703
|
signal: c.req.raw.signal
|
|
155270
155704
|
})));
|
|
155271
155705
|
app2.post("/done", async (c) => {
|
|
155272
|
-
await
|
|
155706
|
+
const body6 = await c.req.json().catch(() => void 0);
|
|
155707
|
+
await sessions.done(token2(c.req.header("authorization")), body6 && typeof body6 === "object" && "output" in body6 ? { output: body6.output } : void 0);
|
|
155273
155708
|
return c.json({ ok: true });
|
|
155274
155709
|
});
|
|
155275
155710
|
app2.get("/events", async (c) => {
|
|
@@ -155562,6 +155997,12 @@ function createApp(opts) {
|
|
|
155562
155997
|
...response5 !== void 0 && { response: response5 },
|
|
155563
155998
|
gap: res.status === 501 || res.headers.has(GAP_HEADER),
|
|
155564
155999
|
// Extract before TraceRecorder caps response bodies; never infer a harness fault from status.
|
|
156000
|
+
...res.headers.has(SETUP_ISSUE_HEADER) && { issue: {
|
|
156001
|
+
kind: "tools",
|
|
156002
|
+
owner: "harness",
|
|
156003
|
+
service,
|
|
156004
|
+
message: typeof response5 === "object" && response5 !== null && typeof response5.error === "string" ? response5.error : "the test stopped before the agent ran"
|
|
156005
|
+
} },
|
|
155565
156006
|
...res.headers.has(INTERNAL_ERROR_HEADER) && { issue: {
|
|
155566
156007
|
kind: "twin",
|
|
155567
156008
|
owner: "harness",
|