exoagent 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +7 -10
  2. package/dist/code-mode.d.ts +2 -24
  3. package/dist/exoeval/allowed.d.ts +9 -0
  4. package/dist/exoeval/builtins.d.ts +188 -0
  5. package/dist/exoeval/evaluator.d.ts +68 -0
  6. package/dist/exoeval/expr.d.ts +50 -0
  7. package/dist/exoeval/index.d.ts +16 -0
  8. package/dist/exoeval/lib/index.d.ts +1 -0
  9. package/dist/exoeval/scope.d.ts +13 -0
  10. package/dist/exoeval/tool.d.ts +49 -0
  11. package/dist/exoeval/utils.d.ts +9 -0
  12. package/dist/index.d.ts +3 -5
  13. package/dist/index.mjs +8255 -205
  14. package/dist/rpc-toolset-test-helpers.d.ts +2 -5
  15. package/dist/runtime/daemon.d.ts +37 -0
  16. package/dist/runtime/dts.d.ts +21 -0
  17. package/dist/runtime/eslint-exo-rule.d.ts +3 -0
  18. package/dist/runtime/exo.d.ts +33 -0
  19. package/dist/runtime/providers/args.d.ts +13 -0
  20. package/dist/runtime/providers/pi.d.ts +68 -0
  21. package/dist/runtime/providers/review.d.ts +82 -0
  22. package/dist/runtime/providers/sandbox.d.ts +54 -0
  23. package/dist/runtime/providers/secrets.d.ts +18 -0
  24. package/dist/runtime/providers/storage.d.ts +16 -0
  25. package/dist/runtime/secrets-ui.d.ts +19 -0
  26. package/dist/runtime/start-agent.d.ts +2 -0
  27. package/dist/runtime/start.d.ts +2 -0
  28. package/dist/sql/builder.d.ts +6 -7
  29. package/dist/sql/expression.d.ts +1 -2
  30. package/dist/sql.mjs +61 -77
  31. package/dist/tool-5wSlXWJ2.js +176 -0
  32. package/dist/tool-wrapper.d.ts +6 -13
  33. package/package.json +11 -10
  34. package/dist/capnweb/LICENSE.txt +0 -21
  35. package/dist/capnweb/README.md +0 -734
  36. package/dist/capnweb/dist/index-workers.cjs +0 -2791
  37. package/dist/capnweb/dist/index-workers.cjs.map +0 -1
  38. package/dist/capnweb/dist/index-workers.d.cts +0 -2
  39. package/dist/capnweb/dist/index-workers.d.ts +0 -2
  40. package/dist/capnweb/dist/index-workers.js +0 -2754
  41. package/dist/capnweb/dist/index-workers.js.map +0 -1
  42. package/dist/capnweb/dist/index.cjs +0 -2768
  43. package/dist/capnweb/dist/index.cjs.map +0 -1
  44. package/dist/capnweb/dist/index.d.cts +0 -383
  45. package/dist/capnweb/dist/index.d.ts +0 -383
  46. package/dist/capnweb/dist/index.js +0 -2751
  47. package/dist/capnweb/dist/index.js.map +0 -1
  48. package/dist/capnweb/package.json +0 -59
  49. package/dist/capnweb-test-helpers.d.ts +0 -25
  50. package/dist/chunk-VBDAOXYI-BhoIkhUn.mjs +0 -831
  51. package/dist/code-mode-deno.d.ts +0 -13
  52. package/dist/code-mode-runtime.d.ts +0 -1
  53. package/dist/nodefs-C8H-6XZ_.mjs +0 -26
  54. package/dist/opfs-ahp-Dy9HQOrY.mjs +0 -367
  55. package/dist/rpc-toolset-BnC2BXPq.js +0 -146
  56. package/dist/rpc-toolset-test-helpers.d.mts +0 -254
  57. package/dist/rpc-toolset-test-helpers.mjs +0 -10364
  58. package/dist/rpc-toolset.d.ts +0 -34
  59. package/dist/stream-transport.d.ts +0 -11
package/dist/sql.mjs CHANGED
@@ -9,15 +9,15 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
9
9
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
10
  var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
11
11
  var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
12
- var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
13
- var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
12
+ var __expectFn = (fn2) => fn2 !== void 0 && typeof fn2 !== "function" ? __typeError("Function expected") : fn2;
13
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn2) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn2 || null)) });
14
14
  var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
15
15
  var __runInitializers = (array, flags, self, value) => {
16
16
  for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
17
17
  return value;
18
18
  };
19
19
  var __decorateElement = (array, flags, name, decorators, target, extra) => {
20
- var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
20
+ var fn2, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
21
21
  var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
22
22
  var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
23
23
  var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
@@ -36,7 +36,7 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
36
36
  it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
37
37
  if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
38
38
  else if (typeof it !== "object" || it === null) __typeError("Object expected");
39
- else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
39
+ else __expectFn(fn2 = it.get) && (desc.get = fn2), __expectFn(fn2 = it.set) && (desc.set = fn2), __expectFn(fn2 = it.init) && initializers.unshift(fn2);
40
40
  }
41
41
  return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
42
42
  };
@@ -47,11 +47,11 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
47
47
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
48
48
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
49
49
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
50
- var _desc_dec, _asc_dec, ___dec, ___dec2, ___dec3, ___dec4, ___dec5, _NOT_LIKE_dec, _LIKE_dec, ____dec, ____dec2, ___dec6, ____dec3, ___dec7, ____dec4, ___dec8, _isNotNull_dec, _isNull_dec, _not_dec, _and_dec, _or_dec, _a, _init, _execute_dec, _join_dec, _offset_dec, _limit_dec, _orderBy_dec, _where_dec, _select_dec, _b, _db, _limit, _offset, _init2;
50
+ var _desc_dec, _asc_dec, ___dec, ___dec2, ___dec3, ___dec4, ___dec5, _NOT_LIKE_dec, _LIKE_dec, ____dec, ____dec2, ___dec6, ____dec3, ___dec7, ____dec4, ___dec8, _isNotNull_dec, _isNull_dec, _not_dec, _and_dec, _or_dec, _init, _execute_dec, _join_dec, _offset_dec, _limit_dec, _orderBy_dec, _where_dec, _select_dec, _db, _limit, _offset, _init2;
51
51
  import { sql as sql$1, Kysely } from "kysely";
52
52
  import invariant from "tiny-invariant";
53
53
  import z from "zod";
54
- import { R as RpcToolset, t as tool, s as setToolMetadata } from "./rpc-toolset-BnC2BXPq.js";
54
+ import { a as tool, r as registerToolField, f as fn } from "./tool-5wSlXWJ2.js";
55
55
  const sql = sql$1;
56
56
  const buildSql = (parts, separator = sql$1` `) => {
57
57
  return sql$1.join(parts.filter((x) => x != null), separator);
@@ -65,9 +65,9 @@ const isSqlExpressionIn = (value) => {
65
65
  const zSqlExpression = z.custom((val) => val instanceof SqlExpression);
66
66
  const zNumericSqlExpression = z.union([zSqlExpression, z.number(), z.string()]);
67
67
  const zSqlExpressionIn = z.union([zSqlExpression, z.number(), z.string(), z.boolean(), z.null()]);
68
- class SqlExpression extends (_a = RpcToolset, _or_dec = [tool(zSqlExpression)], _and_dec = [tool(zSqlExpression)], _not_dec = [tool()], _isNull_dec = [tool()], _isNotNull_dec = [tool()], ___dec8 = [tool(zNumericSqlExpression)], ____dec4 = [tool(zNumericSqlExpression)], ___dec7 = [tool(zNumericSqlExpression)], ____dec3 = [tool(zNumericSqlExpression)], ___dec6 = [tool(zSqlExpressionIn)], ____dec2 = [tool(zSqlExpressionIn)], ____dec = [tool(zSqlExpressionIn)], _LIKE_dec = [tool(z.union([zSqlExpression, z.string()]))], _NOT_LIKE_dec = [tool(z.union([zSqlExpression, z.string()]))], ___dec5 = [tool(zNumericSqlExpression)], ___dec4 = [tool(zNumericSqlExpression)], ___dec3 = [tool(zNumericSqlExpression)], ___dec2 = [tool(zNumericSqlExpression)], ___dec = [tool(zNumericSqlExpression)], _asc_dec = [tool()], _desc_dec = [tool()], _a) {
68
+ _or_dec = [tool(zSqlExpression)], _and_dec = [tool(zSqlExpression)], _not_dec = [tool()], _isNull_dec = [tool()], _isNotNull_dec = [tool()], ___dec8 = [tool(zNumericSqlExpression)], ____dec4 = [tool(zNumericSqlExpression)], ___dec7 = [tool(zNumericSqlExpression)], ____dec3 = [tool(zNumericSqlExpression)], ___dec6 = [tool(zSqlExpressionIn)], ____dec2 = [tool(zSqlExpressionIn)], ____dec = [tool(zSqlExpressionIn)], _LIKE_dec = [tool(z.union([zSqlExpression, z.string()]))], _NOT_LIKE_dec = [tool(z.union([zSqlExpression, z.string()]))], ___dec5 = [tool(zNumericSqlExpression)], ___dec4 = [tool(zNumericSqlExpression)], ___dec3 = [tool(zNumericSqlExpression)], ___dec2 = [tool(zNumericSqlExpression)], ___dec = [tool(zNumericSqlExpression)], _asc_dec = [tool()], _desc_dec = [tool()];
69
+ class SqlExpression {
69
70
  constructor(precedence = 100) {
70
- super();
71
71
  __runInitializers(_init, 5, this);
72
72
  // `= () => ` to ensure the method is a direct property of the class instance,
73
73
  // not a method of the class prototype
@@ -140,7 +140,7 @@ class SqlExpression extends (_a = RpcToolset, _or_dec = [tool(zSqlExpression)],
140
140
  return new OrderByValue(this, sql`DESC`);
141
141
  }
142
142
  }
143
- _init = __decoratorStart(_a);
143
+ _init = __decoratorStart(null);
144
144
  __decorateElement(_init, 1, "or", _or_dec, SqlExpression);
145
145
  __decorateElement(_init, 1, "and", _and_dec, SqlExpression);
146
146
  __decorateElement(_init, 1, "not", _not_dec, SqlExpression);
@@ -294,13 +294,19 @@ const combinePredicates = (...predicates) => {
294
294
  }
295
295
  return filtered.reduce((acc, predicate) => acc.and(predicate));
296
296
  };
297
+ const isOrderByItem = (value) => {
298
+ if (Array.isArray(value)) {
299
+ return value.every((e) => e instanceof SqlExpression || e instanceof OrderByValue);
300
+ }
301
+ return value instanceof SqlExpression || value instanceof OrderByValue;
302
+ };
297
303
  const namespacedArg = (tables) => {
298
304
  return Object.fromEntries(Object.entries(tables).map(([k, v]) => [k, v.fromItem.toRowLike()]));
299
305
  };
300
- const _QueryBuilder = class _QueryBuilder extends (_b = RpcToolset, _select_dec = [tool.callback()], _where_dec = [tool.callback()], _orderBy_dec = [tool.callback()], _limit_dec = [tool(z.number().int().nonnegative())], _offset_dec = [tool(z.number().int().nonnegative())], _join_dec = [tool.unsafeNoValidation()], _execute_dec = [tool()], _b) {
306
+ _select_dec = [tool(fn.returns(z.any()))], _where_dec = [tool(fn.returns(z.custom(isSqlExpressionIn)))], _orderBy_dec = [tool(fn.returns(z.custom(isOrderByItem)))], _limit_dec = [tool(z.number().int().nonnegative())], _offset_dec = [tool(z.number().int().nonnegative())], _join_dec = [tool(z.any(), z.any())], _execute_dec = [tool()];
307
+ const _QueryBuilder = class _QueryBuilder {
301
308
  // set only when created directly from a TableClass
302
309
  constructor(params) {
303
- super();
304
310
  __runInitializers(_init2, 5, this);
305
311
  __privateAdd(this, _db);
306
312
  __publicField(this, "alias");
@@ -370,32 +376,22 @@ const _QueryBuilder = class _QueryBuilder extends (_b = RpcToolset, _select_dec
370
376
  this.rawTable = params.rawTable;
371
377
  }
372
378
  select(select) {
373
- const selectUnwrapped = tool.unwrap(select, isRowLikeIn);
374
- return selectUnwrapped(this.arg, (result) => {
375
- return new _QueryBuilder({ ...this.paramsForCopy(), selectRowLike: asRowLike(result) });
376
- });
379
+ const result = select(this.arg);
380
+ invariant(isRowLikeIn(result), "select must return a RowLikeIn");
381
+ return new _QueryBuilder({ ...this.paramsForCopy(), selectRowLike: asRowLike(result) });
377
382
  }
378
383
  where(where) {
379
- const whereUnwrapped = tool.unwrap(where, isSqlExpressionIn);
380
- return whereUnwrapped(this.arg, (result) => {
381
- return new _QueryBuilder({ ...this.paramsForCopy(), whereExpression: combinePredicates(this.whereExpression, asSqlExpression(result)) });
382
- });
384
+ const result = where(this.arg);
385
+ return new _QueryBuilder({ ...this.paramsForCopy(), whereExpression: combinePredicates(this.whereExpression, asSqlExpression(result)) });
383
386
  }
384
387
  orderBy(orderBy) {
385
- const orderByUnwrapped = tool.unwrap(orderBy, (arg) => {
386
- if (Array.isArray(arg)) {
387
- return arg.every((e) => e instanceof SqlExpression || e instanceof OrderByValue);
388
- }
389
- return arg instanceof SqlExpression || arg instanceof OrderByValue;
390
- });
391
- return orderByUnwrapped(this.arg, (raw) => {
392
- const rawArray = Array.isArray(raw) ? raw : [raw];
393
- const exprs = rawArray.map((e) => {
394
- invariant(e instanceof SqlExpression || e instanceof OrderByValue, "orderBy must return a SqlExpression/OrderByValue or an array of SqlExpressions/OrderByValues");
395
- return e instanceof SqlExpression ? new OrderByValue(e) : e;
396
- });
397
- return new _QueryBuilder({ ...this.paramsForCopy(), orderByExpressions: (this.orderByExpressions ?? []).concat(exprs) });
388
+ const raw = orderBy(this.arg);
389
+ const rawArray = Array.isArray(raw) ? raw : [raw];
390
+ const exprs = rawArray.map((e) => {
391
+ invariant(e instanceof SqlExpression || e instanceof OrderByValue, "orderBy must return a SqlExpression/OrderByValue or an array of SqlExpressions/OrderByValues");
392
+ return e instanceof SqlExpression ? new OrderByValue(e) : e;
398
393
  });
394
+ return new _QueryBuilder({ ...this.paramsForCopy(), orderByExpressions: (this.orderByExpressions ?? []).concat(exprs) });
399
395
  }
400
396
  limit(limit) {
401
397
  invariant(typeof limit === "number" && limit >= 0, "limit must be greater than or equal to 0");
@@ -407,44 +403,42 @@ const _QueryBuilder = class _QueryBuilder extends (_b = RpcToolset, _select_dec
407
403
  }
408
404
  join(fromItem, on) {
409
405
  const fromItemCallbackRaw = isFromItem(fromItem) ? () => fromItem : fromItem;
410
- const fromItemCallback = tool.unwrap(fromItemCallbackRaw, isFromItem);
411
- const res = fromItemCallback(this.arg, (fromItemResolved) => {
412
- if (fromItemResolved instanceof _QueryBuilder && fromItemResolved.rawTable) {
413
- fromItemResolved = fromItemResolved.rawTable;
414
- }
415
- const alias = fromItemResolved.alias;
416
- if (this.tables[alias]) {
417
- throw new Error(`Join already exists: ${alias} in ${Object.keys(this.tables)}`);
406
+ let fromItemResolved = fromItemCallbackRaw(this.arg);
407
+ invariant(isFromItem(fromItemResolved), "fromItem must return a FromItem");
408
+ if (fromItemResolved instanceof _QueryBuilder && fromItemResolved.rawTable) {
409
+ fromItemResolved = fromItemResolved.rawTable;
410
+ }
411
+ const alias = fromItemResolved.alias;
412
+ invariant(typeof alias === "string" && isSafeAlias(alias), "alias must be a safe alias");
413
+ if (this.tables[alias]) {
414
+ throw new Error(`Join already exists: ${alias} in ${Object.keys(this.tables)}`);
415
+ }
416
+ const arg = {
417
+ ...this.arg,
418
+ [alias]: fromItemResolved.toRowLike()
419
+ };
420
+ const onRaw = on?.(arg);
421
+ invariant(onRaw === void 0 || isSqlExpressionIn(onRaw), "on must return a SqlExpressionIn");
422
+ const onResolved = combinePredicates(onRaw !== void 0 ? asSqlExpression(onRaw) : void 0, fromItemResolved.onExpression);
423
+ invariant(onResolved != null, "Must specify an `on` expression or use `Table.on` to set the on expression");
424
+ invariant(onResolved instanceof SqlExpression, "on must return a SqlExpression");
425
+ const tablesWithAlias = {
426
+ ...this.tables,
427
+ [alias]: {
428
+ fromItem: fromItemResolved,
429
+ on: onResolved,
430
+ joinType: "inner",
431
+ // If `fromItem` is a function that returns a QueryBuilder, it is implicitly a lateral join (depends on the other tables)
432
+ isLateral: !isFromItem(fromItem) && fromItemResolved instanceof _QueryBuilder
418
433
  }
419
- const arg = {
420
- ...this.arg,
421
- [alias]: fromItemResolved.toRowLike()
422
- };
423
- const onCallback = tool.unwrap(on ?? (() => void 0), (raw) => raw === void 0 || isSqlExpressionIn(raw));
424
- return onCallback(arg, (onRaw) => {
425
- const onResolved = combinePredicates(onRaw !== void 0 ? asSqlExpression(onRaw) : void 0, fromItemResolved.onExpression);
426
- invariant(onResolved != null, "Must specify an `on` expression or use `Table.on` to set the on expression");
427
- invariant(onResolved instanceof SqlExpression, "on must return a SqlExpression");
428
- const tablesWithAlias = {
429
- ...this.tables,
430
- [alias]: {
431
- fromItem: fromItemResolved,
432
- on: onResolved,
433
- joinType: "inner",
434
- // If `fromItem` is a function that returns a QueryBuilder, it is implicitly a lateral join (depends on the other tables)
435
- isLateral: !isFromItem(fromItem) && fromItemResolved instanceof _QueryBuilder
436
- }
437
- };
438
- return new _QueryBuilder({ ...this.paramsForCopy(), tables: tablesWithAlias });
439
- });
440
- });
441
- return res;
434
+ };
435
+ return new _QueryBuilder({ ...this.paramsForCopy(), tables: tablesWithAlias });
442
436
  }
443
437
  async execute() {
444
438
  return await __privateGet(this, _db).execute(this.compile());
445
439
  }
446
440
  };
447
- _init2 = __decoratorStart(_b);
441
+ _init2 = __decoratorStart(null);
448
442
  _db = new WeakMap();
449
443
  _limit = new WeakMap();
450
444
  _offset = new WeakMap();
@@ -457,7 +451,7 @@ __decorateElement(_init2, 1, "join", _join_dec, _QueryBuilder);
457
451
  __decorateElement(_init2, 1, "execute", _execute_dec, _QueryBuilder);
458
452
  __decoratorMetadata(_init2, _QueryBuilder);
459
453
  let QueryBuilder = _QueryBuilder;
460
- class TableBase extends RpcToolset {
454
+ class TableBase {
461
455
  opts;
462
456
  // `= () => ` to ensure the method is a direct property of the class instance,
463
457
  // not a method of the class prototype
@@ -498,18 +492,8 @@ const table = (db, name) => {
498
492
  for (const key of Object.keys(rowLike)) {
499
493
  const value = rowLike[key];
500
494
  if (value instanceof UnboundColumnReferenceExpression) {
501
- const proto = Object.getPrototypeOf(rowLike);
502
- const getter = function() {
503
- const cls = this.constructor;
504
- return new ColumnReferenceExpression(cls.alias ?? cls.tableName, this.opts?.remapColumns ? key : value.column);
505
- };
506
- setToolMetadata(getter, { runtimeValidationEnabled: true });
507
- Object.defineProperty(proto, key, {
508
- get: getter,
509
- enumerable: true,
510
- configurable: true
511
- });
512
- delete rowLike[key];
495
+ rowLike[key] = new ColumnReferenceExpression(this.alias ?? this.tableName, opts?.remapColumns ? key : value.column);
496
+ registerToolField(rowLike, key);
513
497
  }
514
498
  }
515
499
  return rowLike;
@@ -0,0 +1,176 @@
1
+ const toolSymbol = Symbol("tool");
2
+ const toolFieldsSymbol = Symbol("toolFields");
3
+ const validate = (schema, value, index) => {
4
+ const validation = schema["~standard"].validate(value);
5
+ if (validation instanceof Promise) {
6
+ throw new TypeError(`Validation must be synchronous: ${validation} ${value}`);
7
+ }
8
+ if (validation.issues) {
9
+ const msg = validation.issues.map((e) => e.message).join(", ");
10
+ throw new TypeError(`Invalid value: ${msg}${index != null ? ` for argument ${index}` : ""}`);
11
+ }
12
+ return validation.value;
13
+ };
14
+ const validateArgs = (methodName, inputSchemas, args) => {
15
+ const ret = [];
16
+ if (args.length > inputSchemas.length) {
17
+ throw new TypeError(`${methodName}: Too many arguments: ${args.length} > ${inputSchemas.length}`);
18
+ }
19
+ for (const [index, schema] of inputSchemas.entries()) {
20
+ ret.push(validate(schema, args[index], index));
21
+ }
22
+ return ret;
23
+ };
24
+ const registerToolField = (obj, key) => {
25
+ if (!Object.getOwnPropertyDescriptor(obj, toolFieldsSymbol)) {
26
+ Object.defineProperty(obj, toolFieldsSymbol, {
27
+ value: /* @__PURE__ */ new Set(),
28
+ writable: false,
29
+ enumerable: false,
30
+ configurable: false
31
+ });
32
+ }
33
+ obj[toolFieldsSymbol].add(key);
34
+ };
35
+ function tool(...argSchemas) {
36
+ return function(target, context) {
37
+ const key = String(context.name);
38
+ if (context.kind === "method") {
39
+ return asToolFn(target, argSchemas);
40
+ }
41
+ if (context.kind === "getter") {
42
+ const newGetter = function() {
43
+ const result = Reflect.apply(target, this, []);
44
+ if (typeof result === "function") {
45
+ return asToolFn(result, argSchemas);
46
+ }
47
+ return result;
48
+ };
49
+ return asToolFn(newGetter, []);
50
+ }
51
+ if (context.kind === "field") {
52
+ context.addInitializer(function() {
53
+ registerToolField(this, key);
54
+ });
55
+ return function(initialValue) {
56
+ if (typeof initialValue === "function") {
57
+ return asToolFn(initialValue, argSchemas);
58
+ }
59
+ return initialValue;
60
+ };
61
+ }
62
+ if (context.kind === "class") {
63
+ return asToolConstructor(target, argSchemas);
64
+ }
65
+ };
66
+ }
67
+ const makeFnSchema = (retSchema, allowOptional = false) => {
68
+ const schema = {
69
+ "~standard": {
70
+ version: 1,
71
+ vendor: "exoeval",
72
+ validate: (value) => {
73
+ if (value === void 0 && allowOptional) {
74
+ return { value: void 0 };
75
+ }
76
+ if (typeof value !== "function") {
77
+ return { issues: [{ message: "Expected a function" }] };
78
+ }
79
+ return {
80
+ value: (...args) => {
81
+ const res = Reflect.apply(value, void 0, args);
82
+ if (res != null && typeof res === "object" && "then" in res && typeof res.then === "function") {
83
+ throw new TypeError(`${value.name}: Promise not allowed`);
84
+ }
85
+ return validate(retSchema, res);
86
+ }
87
+ };
88
+ }
89
+ }
90
+ };
91
+ return Object.assign(schema, {
92
+ optional() {
93
+ return makeFnSchema(retSchema, true);
94
+ }
95
+ });
96
+ };
97
+ const fn = {
98
+ returns(retSchema) {
99
+ return makeFnSchema(retSchema);
100
+ }
101
+ };
102
+ const expr = () => (target, _context) => {
103
+ target[toolSymbol] = "expr";
104
+ return target;
105
+ };
106
+ function asToolFn(fn2, schemas) {
107
+ const name = fn2.name || "anonymous";
108
+ const { [name]: wrapped } = {
109
+ [name](...args) {
110
+ const validatedArgs = validateArgs(name, schemas, args);
111
+ return Reflect.apply(fn2, this, validatedArgs);
112
+ }
113
+ };
114
+ wrapped[toolSymbol] = "raw";
115
+ return wrapped;
116
+ }
117
+ function asToolConstructor(Original, argSchemas) {
118
+ const { [Original.name]: Wrapped } = { [Original.name]: class extends Original {
119
+ constructor(...args) {
120
+ const validated = argSchemas.length > 0 ? validateArgs(`new ${Original.name}`, argSchemas, args) : args;
121
+ super(...validated);
122
+ }
123
+ } };
124
+ Wrapped[toolSymbol] = "constructor";
125
+ return Wrapped;
126
+ }
127
+ const isToolableFunction = (value) => {
128
+ return typeof value === "function" && value[toolSymbol] === "raw";
129
+ };
130
+ const isExprFunction = (value) => {
131
+ return typeof value === "function" && value[toolSymbol] === "expr";
132
+ };
133
+ const isToolableConstructor = (value) => {
134
+ return typeof value === "function" && value[toolSymbol] === "constructor";
135
+ };
136
+ const getToolUnbound = (thisArg, obj, key) => {
137
+ let current = obj;
138
+ while (current != null) {
139
+ const desc = Object.getOwnPropertyDescriptor(current, key);
140
+ if (desc) {
141
+ if (desc.get && isToolableFunction(desc.get)) {
142
+ return desc.get.call(thisArg);
143
+ }
144
+ if (isToolableFunction(desc.value) || isExprFunction(desc.value)) {
145
+ return desc.value;
146
+ }
147
+ if (current[toolFieldsSymbol]?.has(String(key))) {
148
+ return "value" in desc ? desc.value : desc.get?.call(thisArg);
149
+ }
150
+ return void 0;
151
+ }
152
+ current = Object.getPrototypeOf(current);
153
+ }
154
+ return void 0;
155
+ };
156
+ const getTool = (thisArg, obj, key) => {
157
+ const unbound = getToolUnbound(thisArg, obj, key);
158
+ if (typeof unbound === "function" && toolSymbol in unbound) {
159
+ const bound = unbound.bind(thisArg);
160
+ bound[toolSymbol] = unbound[toolSymbol];
161
+ return bound;
162
+ }
163
+ return unbound;
164
+ };
165
+ export {
166
+ tool as a,
167
+ isToolableFunction as b,
168
+ isToolableConstructor as c,
169
+ asToolFn as d,
170
+ expr as e,
171
+ fn as f,
172
+ getTool as g,
173
+ isExprFunction as i,
174
+ registerToolField as r,
175
+ toolFieldsSymbol as t
176
+ };
@@ -1,16 +1,9 @@
1
1
  import { Tool, ToolExecutionOptions } from 'ai';
2
- import { RpcToolset } from './rpc-toolset';
2
+ import { ToolFunction } from './exoeval';
3
3
  export type WrappableTools = {
4
- [key: string]: Tool | (() => RpcToolset);
5
- } | Tool[];
6
- export declare function generateToolTypes(tools: WrappableTools, name: string): AsyncGenerator<string, void, unknown>;
7
- export declare const generateToolApi: (tools: WrappableTools, opts: ToolExecutionOptions) => {
8
- new (code: string): {
9
- __return_value__: unknown;
10
- __raw_code__: string;
11
- __code__(): Promise<string>;
12
- __return__(result: unknown): void;
13
- __RPC_TARGET_BRAND: never;
14
- };
4
+ [key: string]: Tool;
5
+ } | Tool[] | {
6
+ [k in string]: ToolFunction;
15
7
  };
16
- export type ToolApi = InstanceType<ReturnType<typeof generateToolApi>>;
8
+ export declare function generateToolTypes(tools: WrappableTools, name: string): AsyncGenerator<string, void, unknown>;
9
+ export declare const wrapTools: (tools: WrappableTools, opts: ToolExecutionOptions) => { [k in string]: ToolFunction; };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "exoagent",
3
3
  "type": "module",
4
- "version": "0.0.12",
4
+ "version": "0.0.14",
5
5
  "description": "The OS kernel to safely unleash your agents",
6
6
  "author": "Ryan Rasti <https://github.com/ryanrasti>",
7
7
  "license": "MIT",
@@ -40,32 +40,31 @@
40
40
  ],
41
41
  "scripts": {
42
42
  "clean": "rm -rf dist",
43
- "build": "npm run clean && npm run build:runtime && npm run build:main && npm run build:capnweb && npm run build:test-deps",
43
+ "build": "npm run clean && npm run build:main",
44
44
  "build:main": "vite build",
45
- "build:runtime": "esbuild src/code-mode-runtime.ts --bundle --format=esm --target=es2022 --outfile=dist/code-mode-runtime.mjs --packages=external",
46
- "build:capnweb": "npm pack ./packages/capnweb --pack-destination dist && mkdir -p dist/capnweb && tar -xzf dist/capnweb-*.tgz --strip-components=1 -C dist/capnweb && rm dist/capnweb-*.tgz",
47
- "build:test-deps": "tsdown --config tsdown.test-deps.config.ts",
48
45
  "dev": "tsdown --watch",
49
46
  "lint": "eslint",
50
47
  "prepublishOnly": "npm run build",
51
48
  "release": "bumpp",
52
49
  "start": "tsx src/index.ts",
53
- "pretest": "npm run build:runtime",
54
50
  "test": "vitest --run",
51
+ "test:ci": "vitest --run --exclude '**/*.local.test.ts'",
55
52
  "typecheck": "tsc",
56
- "ci:capnweb": "cd packages/capnweb && npm ci && npm run build",
57
- "ci:examples": "npm --prefix ./examples run ci",
58
- "ci": "npm run ci:capnweb && npm ci && npm run lint && npm run typecheck && npm run build && npm run test && npm run ci:examples"
53
+ "check:examples": "npm --prefix ./examples run check",
54
+ "check": "npm ci && npm run lint && npm run typecheck && npm run build && npm run test && npm run check:examples"
59
55
  },
60
56
  "peerDependencies": {
61
57
  "ai": "^6.0.0"
62
58
  },
63
59
  "dependencies": {
60
+ "@mariozechner/pi-coding-agent": "^0.58.4",
61
+ "@sinclair/typebox": "^0.34.48",
62
+ "better-sqlite3": "^12.8.0",
64
63
  "camelcase": "^9.0.0",
65
- "capnweb": "file:dist/capnweb",
66
64
  "json-schema": "^0.4.0",
67
65
  "json-schema-to-typescript": "^15.0.0",
68
66
  "kysely": "^0.28.9",
67
+ "secure-json-parse": "^4.1.0",
69
68
  "tiny-invariant": "^1.3.3",
70
69
  "zod": "^4.2.1",
71
70
  "zod-to-json-schema": "^3.25.0"
@@ -76,7 +75,9 @@
76
75
  "@antfu/utils": "9.3.0",
77
76
  "@electric-sql/pglite": "^0.3.15",
78
77
  "@standard-schema/spec": "^1.1.0",
78
+ "@types/better-sqlite3": "^7.6.13",
79
79
  "@types/node": "25.0.1",
80
+ "acorn": "^8.16.0",
80
81
  "bumpp": "10.3.2",
81
82
  "eslint": "9.39.2",
82
83
  "kysely-pglite-dialect": "^1.2.0",
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Cloudflare, Inc.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.