exoagent 0.0.11 → 0.0.13
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/README.md +8 -11
- package/dist/code-mode.d.ts +2 -24
- package/dist/exoeval/builtins.d.ts +173 -0
- package/dist/exoeval/evaluator.d.ts +59 -0
- package/dist/exoeval/expr.d.ts +50 -0
- package/dist/exoeval/index.d.ts +6 -0
- package/dist/exoeval/scope.d.ts +13 -0
- package/dist/exoeval/tool.d.ts +44 -0
- package/dist/exoeval/utils.d.ts +9 -0
- package/dist/index.d.ts +3 -5
- package/dist/index.mjs +8128 -197
- package/dist/rpc-toolset-test-helpers.d.ts +2 -5
- package/dist/sql/builder.d.ts +6 -7
- package/dist/sql/expression.d.ts +1 -2
- package/dist/sql.mjs +61 -77
- package/dist/tool-DGs9ZxVn.js +175 -0
- package/dist/tool-wrapper.d.ts +6 -13
- package/package.json +6 -10
- package/dist/capnweb/LICENSE.txt +0 -21
- package/dist/capnweb/README.md +0 -734
- package/dist/capnweb/dist/index-workers.cjs +0 -2791
- package/dist/capnweb/dist/index-workers.cjs.map +0 -1
- package/dist/capnweb/dist/index-workers.d.cts +0 -2
- package/dist/capnweb/dist/index-workers.d.ts +0 -2
- package/dist/capnweb/dist/index-workers.js +0 -2754
- package/dist/capnweb/dist/index-workers.js.map +0 -1
- package/dist/capnweb/dist/index.cjs +0 -2768
- package/dist/capnweb/dist/index.cjs.map +0 -1
- package/dist/capnweb/dist/index.d.cts +0 -383
- package/dist/capnweb/dist/index.d.ts +0 -383
- package/dist/capnweb/dist/index.js +0 -2751
- package/dist/capnweb/dist/index.js.map +0 -1
- package/dist/capnweb/package.json +0 -59
- package/dist/capnweb-test-helpers.d.ts +0 -25
- package/dist/chunk-VBDAOXYI-BhoIkhUn.mjs +0 -831
- package/dist/code-mode-deno.d.ts +0 -13
- package/dist/code-mode-runtime.d.ts +0 -1
- package/dist/nodefs-C8H-6XZ_.mjs +0 -26
- package/dist/opfs-ahp-Dy9HQOrY.mjs +0 -367
- package/dist/rpc-toolset-BnC2BXPq.js +0 -146
- package/dist/rpc-toolset-test-helpers.d.mts +0 -254
- package/dist/rpc-toolset-test-helpers.mjs +0 -10364
- package/dist/rpc-toolset.d.ts +0 -34
- package/dist/stream-transport.d.ts +0 -11
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare class TestToolset extends RpcToolset {
|
|
1
|
+
export declare class TestToolset {
|
|
3
2
|
add(input: {
|
|
4
3
|
a: number;
|
|
5
4
|
b: number;
|
|
@@ -9,7 +8,7 @@ export declare class TestToolset extends RpcToolset {
|
|
|
9
8
|
id: string;
|
|
10
9
|
}): Promise<typeof User>;
|
|
11
10
|
}
|
|
12
|
-
export declare class TestToolset2
|
|
11
|
+
export declare class TestToolset2 {
|
|
13
12
|
subtract(input: {
|
|
14
13
|
a: number;
|
|
15
14
|
b: number;
|
|
@@ -20,7 +19,6 @@ declare const User_base: Omit<import('./sql').TableClass<"users">, keyof import(
|
|
|
20
19
|
remapColumns?: boolean;
|
|
21
20
|
};
|
|
22
21
|
column: (this: InstanceType<import('./sql').TableClass<string>>, columnName: string) => import('./sql/expression').ColumnReferenceExpression;
|
|
23
|
-
__RPC_TARGET_BRAND: never;
|
|
24
22
|
});
|
|
25
23
|
export declare class User extends User_base {
|
|
26
24
|
id: import('./sql/expression').ColumnReferenceExpression;
|
|
@@ -34,7 +32,6 @@ declare const Post_base: Omit<import('./sql').TableClass<"posts">, keyof import(
|
|
|
34
32
|
remapColumns?: boolean;
|
|
35
33
|
};
|
|
36
34
|
column: (this: InstanceType<import('./sql').TableClass<string>>, columnName: string) => import('./sql/expression').ColumnReferenceExpression;
|
|
37
|
-
__RPC_TARGET_BRAND: never;
|
|
38
35
|
});
|
|
39
36
|
export declare class Post extends Post_base {
|
|
40
37
|
id: import('./sql/expression').ColumnReferenceExpression;
|
package/dist/sql/builder.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CompiledQuery, Dialect } from 'kysely';
|
|
2
|
-
import { ToolCallback, RpcToolset } from '../rpc-toolset';
|
|
3
2
|
import { SqlExpressionIn, ColumnReferenceExpression, OrderByValue, SqlExpression } from './expression';
|
|
4
3
|
import { RawSql } from './sql';
|
|
5
4
|
type RowLikeRaw = {
|
|
@@ -26,7 +25,7 @@ export declare const isFromItem: (value: unknown) => value is FromItem<string, R
|
|
|
26
25
|
type TableNamespace = {
|
|
27
26
|
[key: string]: RowLike;
|
|
28
27
|
};
|
|
29
|
-
type OrderByItem
|
|
28
|
+
type OrderByItem = SqlExpression | SqlExpression[] | OrderByValue | OrderByValue[] | (SqlExpression | OrderByValue)[];
|
|
30
29
|
type Tables<TN extends TableNamespace> = {
|
|
31
30
|
[k in keyof TN & string]: {
|
|
32
31
|
fromItem: FromItem<k, TN[k]>;
|
|
@@ -46,7 +45,7 @@ type QueryBuilderParams<N extends string, TN extends TableNamespace, S extends R
|
|
|
46
45
|
offset?: number;
|
|
47
46
|
rawTable: TableClass<N> | undefined;
|
|
48
47
|
};
|
|
49
|
-
declare class QueryBuilder<N extends string, TN extends TableNamespace, S extends RowLike>
|
|
48
|
+
declare class QueryBuilder<N extends string, TN extends TableNamespace, S extends RowLike> implements FromItem<N, S> {
|
|
50
49
|
#private;
|
|
51
50
|
readonly alias: N;
|
|
52
51
|
private selectRowLike;
|
|
@@ -56,9 +55,9 @@ declare class QueryBuilder<N extends string, TN extends TableNamespace, S extend
|
|
|
56
55
|
private arg;
|
|
57
56
|
private rawTable;
|
|
58
57
|
constructor(params: QueryBuilderParams<N, TN, S>);
|
|
59
|
-
select<S2 extends RowLikeIn>(select:
|
|
60
|
-
where(where:
|
|
61
|
-
orderBy(orderBy:
|
|
58
|
+
select<S2 extends RowLikeIn>(select: (arg: TN) => S2): QueryBuilder<N, TN, AsRowLike<S2>>;
|
|
59
|
+
where(where: (arg: TN) => SqlExpressionIn): QueryBuilder<N, TN, S>;
|
|
60
|
+
orderBy(orderBy: (arg: TN) => OrderByItem): QueryBuilder<N, TN, S>;
|
|
62
61
|
limit(limit: number): QueryBuilder<N, TN, S>;
|
|
63
62
|
offset(offset: number): QueryBuilder<N, TN, S>;
|
|
64
63
|
join<N2 extends string, F2 extends TableClass<N2>>(fromItem: F2 | NamespacedExpression<TN, F2>, on?: NamespacedExpression<TN & {
|
|
@@ -84,7 +83,7 @@ declare class QueryBuilder<N extends string, TN extends TableNamespace, S extend
|
|
|
84
83
|
isSubquery?: boolean;
|
|
85
84
|
}) => import('kysely').RawBuilder<unknown>;
|
|
86
85
|
}
|
|
87
|
-
declare class TableBase
|
|
86
|
+
declare class TableBase {
|
|
88
87
|
opts?: {
|
|
89
88
|
remapColumns?: boolean;
|
|
90
89
|
};
|
package/dist/sql/expression.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { RawSql } from './sql';
|
|
2
|
-
import { RpcToolset } from '../rpc-toolset';
|
|
3
2
|
type LiteralValue = number | string | boolean | null;
|
|
4
3
|
export type SqlExpressionIn = LiteralValue | SqlExpression;
|
|
5
4
|
export declare const asSqlExpression: (value: LiteralValue | SqlExpression) => SqlExpression;
|
|
6
5
|
export declare const isSqlExpressionIn: (value: unknown) => value is SqlExpressionIn;
|
|
7
|
-
export declare class SqlExpression
|
|
6
|
+
export declare class SqlExpression {
|
|
8
7
|
precedence: number;
|
|
9
8
|
constructor(precedence?: number);
|
|
10
9
|
compile: () => RawSql;
|
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 = (
|
|
13
|
-
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (
|
|
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
|
|
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(
|
|
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,
|
|
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 {
|
|
54
|
+
import { a as tool, r as registerToolField, f as fn } from "./tool-DGs9ZxVn.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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
|
374
|
-
|
|
375
|
-
|
|
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
|
|
380
|
-
return
|
|
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
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return
|
|
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
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
-
|
|
420
|
-
|
|
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(
|
|
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
|
|
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
|
-
|
|
502
|
-
|
|
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,175 @@
|
|
|
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
|
+
if (typeof value !== "function") {
|
|
76
|
+
return { issues: [{ message: "Expected a function" }] };
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
value: (...args) => {
|
|
80
|
+
const res = Reflect.apply(value, void 0, args);
|
|
81
|
+
if (res != null && typeof res === "object" && "then" in res && typeof res.then === "function") {
|
|
82
|
+
throw new TypeError(`${value.name}: Promise not allowed`);
|
|
83
|
+
}
|
|
84
|
+
return validate(retSchema, res);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
return Object.assign(schema, {
|
|
91
|
+
optional() {
|
|
92
|
+
return makeFnSchema(retSchema, true);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
const fn = {
|
|
97
|
+
returns(retSchema) {
|
|
98
|
+
return makeFnSchema(retSchema);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const expr = () => (target, _context) => {
|
|
102
|
+
target[toolSymbol] = "expr";
|
|
103
|
+
return target;
|
|
104
|
+
};
|
|
105
|
+
function asToolFn(fn2, schemas) {
|
|
106
|
+
const name = fn2.name || "anonymous";
|
|
107
|
+
const { [name]: wrapped } = {
|
|
108
|
+
[name](...args) {
|
|
109
|
+
const validatedArgs = validateArgs(name, schemas, args);
|
|
110
|
+
return Reflect.apply(fn2, this, validatedArgs);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
wrapped[toolSymbol] = "raw";
|
|
114
|
+
return wrapped;
|
|
115
|
+
}
|
|
116
|
+
function asToolConstructor(Original, argSchemas) {
|
|
117
|
+
const { [Original.name]: Wrapped } = { [Original.name]: class extends Original {
|
|
118
|
+
constructor(...args) {
|
|
119
|
+
const validated = argSchemas.length > 0 ? validateArgs(`new ${Original.name}`, argSchemas, args) : args;
|
|
120
|
+
super(...validated);
|
|
121
|
+
}
|
|
122
|
+
} };
|
|
123
|
+
Wrapped[toolSymbol] = "constructor";
|
|
124
|
+
return Wrapped;
|
|
125
|
+
}
|
|
126
|
+
const isToolableFunction = (value) => {
|
|
127
|
+
return typeof value === "function" && value[toolSymbol] === "raw";
|
|
128
|
+
};
|
|
129
|
+
const isExprFunction = (value) => {
|
|
130
|
+
return typeof value === "function" && value[toolSymbol] === "expr";
|
|
131
|
+
};
|
|
132
|
+
const isToolableConstructor = (value) => {
|
|
133
|
+
return typeof value === "function" && value[toolSymbol] === "constructor";
|
|
134
|
+
};
|
|
135
|
+
const getToolUnbound = (thisArg, obj, key) => {
|
|
136
|
+
let current = obj;
|
|
137
|
+
while (current != null) {
|
|
138
|
+
const desc = Object.getOwnPropertyDescriptor(current, key);
|
|
139
|
+
if (desc) {
|
|
140
|
+
if (desc.get && isToolableFunction(desc.get)) {
|
|
141
|
+
return desc.get.call(thisArg);
|
|
142
|
+
}
|
|
143
|
+
if (isToolableFunction(desc.value) || isExprFunction(desc.value)) {
|
|
144
|
+
return desc.value;
|
|
145
|
+
}
|
|
146
|
+
if (current[toolFieldsSymbol]?.has(String(key))) {
|
|
147
|
+
return "value" in desc ? desc.value : desc.get?.call(thisArg);
|
|
148
|
+
}
|
|
149
|
+
return void 0;
|
|
150
|
+
}
|
|
151
|
+
current = Object.getPrototypeOf(current);
|
|
152
|
+
}
|
|
153
|
+
return void 0;
|
|
154
|
+
};
|
|
155
|
+
const getTool = (thisArg, obj, key) => {
|
|
156
|
+
const unbound = getToolUnbound(thisArg, obj, key);
|
|
157
|
+
if (typeof unbound === "function" && toolSymbol in unbound) {
|
|
158
|
+
const bound = unbound.bind(thisArg);
|
|
159
|
+
bound[toolSymbol] = unbound[toolSymbol];
|
|
160
|
+
return bound;
|
|
161
|
+
}
|
|
162
|
+
return unbound;
|
|
163
|
+
};
|
|
164
|
+
export {
|
|
165
|
+
tool as a,
|
|
166
|
+
isToolableFunction as b,
|
|
167
|
+
isToolableConstructor as c,
|
|
168
|
+
asToolFn as d,
|
|
169
|
+
expr as e,
|
|
170
|
+
fn as f,
|
|
171
|
+
getTool as g,
|
|
172
|
+
isExprFunction as i,
|
|
173
|
+
registerToolField as r,
|
|
174
|
+
toolFieldsSymbol as t
|
|
175
|
+
};
|
package/dist/tool-wrapper.d.ts
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { Tool, ToolExecutionOptions } from 'ai';
|
|
2
|
-
import {
|
|
2
|
+
import { ToolFunction } from './exoeval';
|
|
3
3
|
export type WrappableTools = {
|
|
4
|
-
[key: string]: Tool
|
|
5
|
-
} | Tool[]
|
|
6
|
-
|
|
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
|
|
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.
|
|
4
|
+
"version": "0.0.13",
|
|
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,27 @@
|
|
|
40
40
|
],
|
|
41
41
|
"scripts": {
|
|
42
42
|
"clean": "rm -rf dist",
|
|
43
|
-
"build": "npm run clean && npm run build:
|
|
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",
|
|
55
51
|
"typecheck": "tsc",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"ci": "npm run ci:capnweb && npm ci && npm run lint && npm run typecheck && npm run build && npm run test && npm run ci:examples"
|
|
52
|
+
"check:examples": "npm --prefix ./examples run check",
|
|
53
|
+
"check": "npm ci && npm run lint && npm run typecheck && npm run build && npm run test && npm run check:examples"
|
|
59
54
|
},
|
|
60
55
|
"peerDependencies": {
|
|
61
56
|
"ai": "^6.0.0"
|
|
62
57
|
},
|
|
63
58
|
"dependencies": {
|
|
64
59
|
"camelcase": "^9.0.0",
|
|
65
|
-
"capnweb": "file:dist/capnweb",
|
|
66
60
|
"json-schema": "^0.4.0",
|
|
67
61
|
"json-schema-to-typescript": "^15.0.0",
|
|
68
62
|
"kysely": "^0.28.9",
|
|
63
|
+
"secure-json-parse": "^4.1.0",
|
|
69
64
|
"tiny-invariant": "^1.3.3",
|
|
70
65
|
"zod": "^4.2.1",
|
|
71
66
|
"zod-to-json-schema": "^3.25.0"
|
|
@@ -77,6 +72,7 @@
|
|
|
77
72
|
"@electric-sql/pglite": "^0.3.15",
|
|
78
73
|
"@standard-schema/spec": "^1.1.0",
|
|
79
74
|
"@types/node": "25.0.1",
|
|
75
|
+
"acorn": "^8.16.0",
|
|
80
76
|
"bumpp": "10.3.2",
|
|
81
77
|
"eslint": "9.39.2",
|
|
82
78
|
"kysely-pglite-dialect": "^1.2.0",
|
package/dist/capnweb/LICENSE.txt
DELETED
|
@@ -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.
|