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
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ ExoAgent uses **Object Capabilities (OCap)** to enforce security at the runtime
|
|
|
21
21
|
|
|
22
22
|
It doesn't matter if the LLM gets jailbroken. It runs inside a sandbox where invalid actions are mathematically impossible. Security as a system invariant, not a polite suggestion.
|
|
23
23
|
|
|
24
|
-

|
|
25
25
|
|
|
26
26
|
## Quick Start
|
|
27
27
|
|
|
@@ -73,15 +73,14 @@ class User extends db.Table('users').as('user') {
|
|
|
73
73
|
```typescript
|
|
74
74
|
import { google } from '@ai-sdk/google'
|
|
75
75
|
import { generateText, stepCountIs } from 'ai'
|
|
76
|
-
import {
|
|
76
|
+
import { codemode } from 'exoagent'
|
|
77
77
|
|
|
78
78
|
// Create a capability scoped to user_id=1
|
|
79
79
|
const userCap = User.on(u => u.id['='](1)).from()
|
|
80
80
|
|
|
81
|
-
// Wrap with
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
currentUser: () => userCap,
|
|
81
|
+
// Wrap with codemode for sandboxed execution
|
|
82
|
+
const codeTool = await codemode({
|
|
83
|
+
currentUser: userCap,
|
|
85
84
|
}, schemaString) // schemaString = the class definitions above as a string
|
|
86
85
|
|
|
87
86
|
const result = await generateText({
|
|
@@ -115,17 +114,15 @@ npx tsx saas-bot.ts
|
|
|
115
114
|
|
|
116
115
|
Note the examples require:
|
|
117
116
|
1. NodeJS (runtime)
|
|
118
|
-
2.
|
|
119
|
-
3. An LLM API key set via one of the env vars:
|
|
117
|
+
2. An LLM API key set via one of the env vars:
|
|
120
118
|
- `OPENAI_API_KEY`
|
|
121
119
|
- `ANTHROPIC_API_KEY`
|
|
122
120
|
- `GOOGLE_GENERATIVE_AI_API_KEY`
|
|
123
121
|
|
|
124
122
|
## Architecture
|
|
125
123
|
ExoAgent sits between your LLM and your infrastructure as a regular tool.
|
|
126
|
-
1. **
|
|
127
|
-
2. **
|
|
128
|
-
3. **Query Builder**: Uses a custom capability SQL builder that compiles to safe SQL.
|
|
124
|
+
1. **Evaluator**: A custom sandboxed JavaScript evaluator (`exoeval`) that only allows safe operations.
|
|
125
|
+
2. **Query Builder**: A capability-based SQL builder that compiles to safe SQL with scoped access.
|
|
129
126
|
|
|
130
127
|
## ⚠️ Project Status: Experimental (v0.0.x)
|
|
131
128
|
ExoAgent is an exploration of capability-based security for LLMs. While the architecture (OCaps + Sandboxing) is theoretically robust, this specific implementation is new and may contain bugs.
|
package/dist/code-mode.d.ts
CHANGED
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
import { Tool, ToolExecutionOptions } from 'ai';
|
|
2
|
-
import { RpcTarget } from '../packages/capnweb/dist';
|
|
3
|
-
import { RpcToolset } from './rpc-toolset';
|
|
4
2
|
import { z } from 'zod';
|
|
5
|
-
export type SafeEvalResult = {
|
|
6
|
-
wait: () => Promise<void>;
|
|
7
|
-
input: ReadableStream<Uint8Array>;
|
|
8
|
-
output: WritableStream<Uint8Array>;
|
|
9
|
-
};
|
|
10
|
-
export type SafeEvalContext<R> = {
|
|
11
|
-
kind: 'direct';
|
|
12
|
-
safeEval: (code: string) => Promise<SafeEvalResult>;
|
|
13
|
-
sandboxContext: string;
|
|
14
|
-
} | {
|
|
15
|
-
kind: 'rpc';
|
|
16
|
-
safeEval: (code: string, api: RpcTarget) => Promise<R>;
|
|
17
|
-
};
|
|
18
3
|
type FlatTools = {
|
|
19
4
|
[key: string]: Tool;
|
|
20
5
|
} | Tool[];
|
|
21
|
-
type RpcTools = {
|
|
22
|
-
[key: string]: () => RpcToolset;
|
|
23
|
-
};
|
|
24
6
|
type ExecutableTool<R> = {
|
|
25
7
|
description: string;
|
|
26
8
|
inputSchema: z.ZodSchema<{
|
|
@@ -30,10 +12,6 @@ type ExecutableTool<R> = {
|
|
|
30
12
|
code: string;
|
|
31
13
|
}, opts: ToolExecutionOptions) => Promise<R>;
|
|
32
14
|
};
|
|
33
|
-
export declare
|
|
34
|
-
|
|
35
|
-
constructor(context: SafeEvalContext<R>);
|
|
36
|
-
wrap(tools: FlatTools): Promise<ExecutableTool<R>>;
|
|
37
|
-
wrap(tools: RpcTools | FlatTools, dts: string): Promise<ExecutableTool<R>>;
|
|
38
|
-
}
|
|
15
|
+
export declare function codemode<R>(tools: FlatTools): Promise<ExecutableTool<R>>;
|
|
16
|
+
export declare function codemode<R>(tools: object, dts: string): Promise<ExecutableTool<R>>;
|
|
39
17
|
export {};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { ExpressionContext } from './expr';
|
|
2
|
+
export declare class ExoArray<T = unknown> {
|
|
3
|
+
constructor(...args: Parameters<typeof Array>);
|
|
4
|
+
get length(): number;
|
|
5
|
+
get map(): <U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[];
|
|
6
|
+
get filter(): {
|
|
7
|
+
<S extends any>(predicate: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S[];
|
|
8
|
+
(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): any[];
|
|
9
|
+
};
|
|
10
|
+
get reduce(): {
|
|
11
|
+
(callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any;
|
|
12
|
+
(callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any;
|
|
13
|
+
<U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U;
|
|
14
|
+
};
|
|
15
|
+
get reduceRight(): {
|
|
16
|
+
(callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any): any;
|
|
17
|
+
(callbackfn: (previousValue: any, currentValue: any, currentIndex: number, array: any[]) => any, initialValue: any): any;
|
|
18
|
+
<U>(callbackfn: (previousValue: U, currentValue: any, currentIndex: number, array: any[]) => U, initialValue: U): U;
|
|
19
|
+
};
|
|
20
|
+
get find(): {
|
|
21
|
+
<S extends any>(predicate: (value: any, index: number, obj: any[]) => value is S, thisArg?: any): S | undefined;
|
|
22
|
+
(predicate: (value: any, index: number, obj: any[]) => unknown, thisArg?: any): any;
|
|
23
|
+
};
|
|
24
|
+
get findIndex(): (predicate: (value: any, index: number, obj: any[]) => unknown, thisArg?: any) => number;
|
|
25
|
+
get findLast(): {
|
|
26
|
+
<S extends any>(predicate: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S | undefined;
|
|
27
|
+
(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): any;
|
|
28
|
+
};
|
|
29
|
+
get findLastIndex(): (predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any) => number;
|
|
30
|
+
get some(): (predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any) => boolean;
|
|
31
|
+
get every(): {
|
|
32
|
+
<S extends any>(predicate: (value: any, index: number, array: any[]) => value is S, thisArg?: any): this is S[];
|
|
33
|
+
(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): boolean;
|
|
34
|
+
};
|
|
35
|
+
get flatMap(): <U, This = undefined>(callback: (this: This, value: any, index: number, array: any[]) => U | readonly U[], thisArg?: This | undefined) => U[];
|
|
36
|
+
get toSorted(): (compareFn?: ((a: any, b: any) => number) | undefined) => any[];
|
|
37
|
+
get at(): (index: number) => any;
|
|
38
|
+
get slice(): (start?: number, end?: number) => any[];
|
|
39
|
+
get join(): (separator?: string) => string;
|
|
40
|
+
get concat(): {
|
|
41
|
+
(...items: ConcatArray<any>[]): any[];
|
|
42
|
+
(...items: any[]): any[];
|
|
43
|
+
};
|
|
44
|
+
get indexOf(): (searchElement: any, fromIndex?: number) => number;
|
|
45
|
+
get lastIndexOf(): (searchElement: any, fromIndex?: number) => number;
|
|
46
|
+
get includes(): (searchElement: any, fromIndex?: number) => boolean;
|
|
47
|
+
get flat(): <A, D extends number = 1>(this: A, depth?: D | undefined) => FlatArray<A, D>[];
|
|
48
|
+
get entries(): () => ArrayIterator<[number, any]>;
|
|
49
|
+
get keys(): () => ArrayIterator<number>;
|
|
50
|
+
get values(): () => ArrayIterator<any>;
|
|
51
|
+
get toReversed(): () => any[];
|
|
52
|
+
get toSpliced(): {
|
|
53
|
+
(start: number, deleteCount: number, ...items: any[]): any[];
|
|
54
|
+
(start: number, deleteCount?: number): any[];
|
|
55
|
+
};
|
|
56
|
+
get with(): (index: number, value: any) => any[];
|
|
57
|
+
static from(arrayLike: ArrayLike<unknown>): unknown[];
|
|
58
|
+
static isArray(value: unknown): value is any[];
|
|
59
|
+
}
|
|
60
|
+
export declare class ExoString {
|
|
61
|
+
constructor(...args: Parameters<typeof String>);
|
|
62
|
+
get length(): number;
|
|
63
|
+
get at(): (index: number) => string | undefined;
|
|
64
|
+
get charAt(): (pos: number) => string;
|
|
65
|
+
get charCodeAt(): (index: number) => number;
|
|
66
|
+
get codePointAt(): (pos: number) => number | undefined;
|
|
67
|
+
get concat(): (...strings: string[]) => string;
|
|
68
|
+
get endsWith(): (searchString: string, endPosition?: number) => boolean;
|
|
69
|
+
get includes(): (searchString: string, position?: number) => boolean;
|
|
70
|
+
get indexOf(): (searchString: string, position?: number) => number;
|
|
71
|
+
get lastIndexOf(): (searchString: string, position?: number) => number;
|
|
72
|
+
get padEnd(): (maxLength: number, fillString?: string) => string;
|
|
73
|
+
get padStart(): (maxLength: number, fillString?: string) => string;
|
|
74
|
+
get repeat(): (count: number) => string;
|
|
75
|
+
get replace(): {
|
|
76
|
+
(searchValue: string | RegExp, replaceValue: string): string;
|
|
77
|
+
(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;
|
|
78
|
+
(searchValue: {
|
|
79
|
+
[Symbol.replace](string: string, replaceValue: string): string;
|
|
80
|
+
}, replaceValue: string): string;
|
|
81
|
+
(searchValue: {
|
|
82
|
+
[Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string;
|
|
83
|
+
}, replacer: (substring: string, ...args: any[]) => string): string;
|
|
84
|
+
};
|
|
85
|
+
get replaceAll(): {
|
|
86
|
+
(searchValue: string | RegExp, replaceValue: string): string;
|
|
87
|
+
(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;
|
|
88
|
+
};
|
|
89
|
+
get slice(): (start?: number, end?: number) => string;
|
|
90
|
+
get split(): {
|
|
91
|
+
(separator: string | RegExp, limit?: number): string[];
|
|
92
|
+
(splitter: {
|
|
93
|
+
[Symbol.split](string: string, limit?: number): string[];
|
|
94
|
+
}, limit?: number): string[];
|
|
95
|
+
};
|
|
96
|
+
get startsWith(): (searchString: string, position?: number) => boolean;
|
|
97
|
+
get substring(): (start: number, end?: number) => string;
|
|
98
|
+
get toLowerCase(): () => string;
|
|
99
|
+
get toUpperCase(): () => string;
|
|
100
|
+
get trim(): () => string;
|
|
101
|
+
get trimEnd(): () => string;
|
|
102
|
+
get trimStart(): () => string;
|
|
103
|
+
}
|
|
104
|
+
export declare class ExoDate {
|
|
105
|
+
constructor();
|
|
106
|
+
constructor(value: string | number | Date);
|
|
107
|
+
constructor(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number);
|
|
108
|
+
get getTime(): () => number;
|
|
109
|
+
get getFullYear(): () => number;
|
|
110
|
+
get getMonth(): () => number;
|
|
111
|
+
get getDate(): () => number;
|
|
112
|
+
get getHours(): () => number;
|
|
113
|
+
get getMinutes(): () => number;
|
|
114
|
+
get getSeconds(): () => number;
|
|
115
|
+
get getMilliseconds(): () => number;
|
|
116
|
+
get toISOString(): () => string;
|
|
117
|
+
get toLocaleDateString(): {
|
|
118
|
+
(): string;
|
|
119
|
+
(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
120
|
+
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
121
|
+
};
|
|
122
|
+
get toLocaleTimeString(): {
|
|
123
|
+
(): string;
|
|
124
|
+
(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
125
|
+
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
126
|
+
};
|
|
127
|
+
get toLocaleString(): {
|
|
128
|
+
(): string;
|
|
129
|
+
(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
130
|
+
(locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
|
|
131
|
+
};
|
|
132
|
+
get valueOf(): () => number;
|
|
133
|
+
static now(): number;
|
|
134
|
+
static parse(dateString: string): number;
|
|
135
|
+
}
|
|
136
|
+
export declare class ExoObject {
|
|
137
|
+
static keys(ctx: ExpressionContext, obj: unknown): unknown;
|
|
138
|
+
static values(ctx: ExpressionContext, obj: unknown): unknown;
|
|
139
|
+
static entries(ctx: ExpressionContext, obj: unknown): unknown;
|
|
140
|
+
static fromEntries(entries: [string, unknown][]): {
|
|
141
|
+
[k: string]: unknown;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export declare class ExoBoolean {
|
|
145
|
+
constructor(...args: Parameters<typeof Boolean>);
|
|
146
|
+
get valueOf(): () => boolean;
|
|
147
|
+
}
|
|
148
|
+
export declare class ExoJSON {
|
|
149
|
+
static parse(text: string): any;
|
|
150
|
+
static stringify(value: unknown, replacer?: null, space?: number): string;
|
|
151
|
+
}
|
|
152
|
+
export declare class ExoMath {
|
|
153
|
+
static min(a: number, b: number): number;
|
|
154
|
+
static max(a: number, b: number): number;
|
|
155
|
+
static round(x: number): number;
|
|
156
|
+
static floor(x: number): number;
|
|
157
|
+
static ceil(x: number): number;
|
|
158
|
+
static abs(x: number): number;
|
|
159
|
+
static sqrt(x: number): number;
|
|
160
|
+
static pow(base: number, exp: number): number;
|
|
161
|
+
static log(x: number): number;
|
|
162
|
+
static random(): number;
|
|
163
|
+
static sign(x: number): number;
|
|
164
|
+
static trunc(x: number): number;
|
|
165
|
+
}
|
|
166
|
+
export declare class ExoNumber {
|
|
167
|
+
constructor(...args: Parameters<typeof Number>);
|
|
168
|
+
static parseInt(s: string, radix?: number): number;
|
|
169
|
+
static parseFloat(s: string): number;
|
|
170
|
+
static isNaN(value: unknown): boolean;
|
|
171
|
+
static isFinite(value: unknown): boolean;
|
|
172
|
+
static isInteger(value: unknown): boolean;
|
|
173
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Control, ExpressionContext } from './expr';
|
|
2
|
+
import { Scope } from './scope';
|
|
3
|
+
import { Invariant } from './utils';
|
|
4
|
+
import type * as acorn from 'acorn';
|
|
5
|
+
export type EvalResult<Expr, Ret = Expr> = Generator<Control<InternalControl<Expr>> | Expr, Ret, unknown>;
|
|
6
|
+
type InternalControl<Expr> = {
|
|
7
|
+
control: 'await';
|
|
8
|
+
value: Expr;
|
|
9
|
+
} | {
|
|
10
|
+
control: 'return';
|
|
11
|
+
value: Expr;
|
|
12
|
+
};
|
|
13
|
+
type BuiltinPrototypes = {
|
|
14
|
+
Array?: object;
|
|
15
|
+
String?: object;
|
|
16
|
+
Number?: object;
|
|
17
|
+
Boolean?: object;
|
|
18
|
+
Date?: object;
|
|
19
|
+
};
|
|
20
|
+
export declare class Evaluator<Expr> {
|
|
21
|
+
private readonly ast;
|
|
22
|
+
readonly code: string;
|
|
23
|
+
readonly ctx: ExpressionContext<Expr>;
|
|
24
|
+
readonly scope: Scope<Expr>;
|
|
25
|
+
readonly builtinPrototypes: BuiltinPrototypes;
|
|
26
|
+
readonly inv: Invariant;
|
|
27
|
+
constructor(ast: acorn.Node, code: string, ctx: ExpressionContext<Expr>, scope: Scope<Expr>, builtinPrototypes: BuiltinPrototypes);
|
|
28
|
+
with({ newScope }: {
|
|
29
|
+
newScope?: boolean;
|
|
30
|
+
}): Evaluator<Expr>;
|
|
31
|
+
Identifier(node: acorn.Identifier): EvalResult<Expr>;
|
|
32
|
+
Literal(node: acorn.Literal): EvalResult<Expr>;
|
|
33
|
+
ChainExpression(node: acorn.ChainExpression): EvalResult<Expr>;
|
|
34
|
+
MemberExpression(node: acorn.MemberExpression): EvalResult<Expr>;
|
|
35
|
+
evalArray(elements: (acorn.Expression | acorn.SpreadElement | null)[]): EvalResult<Expr, Expr[]>;
|
|
36
|
+
CallExpression(node: acorn.CallExpression): EvalResult<Expr>;
|
|
37
|
+
ArrayExpression(node: acorn.ArrayExpression): EvalResult<Expr>;
|
|
38
|
+
assertAllowedProperty(key: string | number, node: acorn.Node): void;
|
|
39
|
+
defineProperty(obj: object, key: string | number, value: unknown, node: acorn.Node): void;
|
|
40
|
+
getExoProperty(obj: Expr, key: string | number, node: acorn.Node, optional: boolean): EvalResult<Expr>;
|
|
41
|
+
getBuiltinPrototype(value: unknown): unknown;
|
|
42
|
+
ObjectExpression(node: acorn.ObjectExpression): EvalResult<Expr>;
|
|
43
|
+
AwaitExpression(node: acorn.AwaitExpression): EvalResult<Expr>;
|
|
44
|
+
evalStatements(statements: (acorn.Statement | acorn.ModuleDeclaration)[]): EvalResult<Expr>;
|
|
45
|
+
evalFunctionCall(node: acorn.Function, args: Expr[]): EvalResult<Expr>;
|
|
46
|
+
ArrowFunctionExpression(node: acorn.ArrowFunctionExpression): EvalResult<Expr>;
|
|
47
|
+
UnaryExpression(node: acorn.UnaryExpression): EvalResult<Expr>;
|
|
48
|
+
ConditionalExpression(node: acorn.ConditionalExpression): EvalResult<Expr>;
|
|
49
|
+
BinaryExpression(node: acorn.BinaryExpression): EvalResult<Expr>;
|
|
50
|
+
LogicalExpression(node: acorn.LogicalExpression): EvalResult<Expr>;
|
|
51
|
+
TemplateLiteral(node: acorn.TemplateLiteral): EvalResult<Expr>;
|
|
52
|
+
NewExpression(node: acorn.NewExpression): EvalResult<Expr>;
|
|
53
|
+
Expression(node: acorn.Expression): EvalResult<Expr>;
|
|
54
|
+
$(node: acorn.Expression): EvalResult<Expr, unknown>;
|
|
55
|
+
makeReturn(value: Expr, node: acorn.Node): EvalResult<Expr>;
|
|
56
|
+
Statement(node: acorn.Statement): EvalResult<Expr>;
|
|
57
|
+
Program(node: acorn.Program): Expr | Promise<Expr>;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
declare const control: unique symbol;
|
|
2
|
+
export type Control<V extends {
|
|
3
|
+
value: unknown;
|
|
4
|
+
} = {
|
|
5
|
+
value: unknown;
|
|
6
|
+
}> = {
|
|
7
|
+
[control]: V;
|
|
8
|
+
};
|
|
9
|
+
export declare function getControl<C extends Control>(cntrl: C): C[typeof control];
|
|
10
|
+
export declare function getControl(value: object): {
|
|
11
|
+
value: unknown;
|
|
12
|
+
} | undefined;
|
|
13
|
+
export declare const isControl: (value: unknown) => value is Control;
|
|
14
|
+
export declare const makeControl: <T, V extends {
|
|
15
|
+
value: T;
|
|
16
|
+
}>(obj: V) => Control<V>;
|
|
17
|
+
export declare const isPlainObject: (value: unknown) => value is {
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
export declare abstract class ExpressionContext<Expr = unknown> {
|
|
21
|
+
abstract of(value: unknown): Expr;
|
|
22
|
+
abstract doGen<C extends Control<{
|
|
23
|
+
value: Expr;
|
|
24
|
+
}>>(gen: Generator<C | Expr, Expr, unknown>): Generator<C, Expr, unknown>;
|
|
25
|
+
abstract sequence(expr: Expr): {
|
|
26
|
+
[key in string | number]: Expr;
|
|
27
|
+
} | Expr[] | null | undefined;
|
|
28
|
+
abstract sequencePromiseLike(expr: Expr): PromiseLike<Expr> | Expr;
|
|
29
|
+
abstract distribute(entries: {
|
|
30
|
+
[key in string | number]: Expr;
|
|
31
|
+
} | Expr[]): Expr;
|
|
32
|
+
abstract isExpr(value: unknown): value is Expr;
|
|
33
|
+
abstract call(callee: Expr, args: Expr[]): Expr;
|
|
34
|
+
do(gen: Generator<Expr, Expr, unknown>): Expr;
|
|
35
|
+
chain(expr: Expr, then: (value: unknown) => Expr): Expr;
|
|
36
|
+
}
|
|
37
|
+
export declare class IdentityContext extends ExpressionContext<unknown> {
|
|
38
|
+
doGen<C extends Control<{
|
|
39
|
+
value: unknown;
|
|
40
|
+
}>>(gen: Generator<C | unknown, unknown, unknown>): Generator<C, unknown, unknown>;
|
|
41
|
+
of(value: unknown): unknown;
|
|
42
|
+
call(callee: unknown, args: unknown[]): unknown;
|
|
43
|
+
sequence(obj: unknown): {
|
|
44
|
+
[key in string | number]: unknown;
|
|
45
|
+
} | unknown[] | null | undefined;
|
|
46
|
+
sequencePromiseLike(expr: unknown): unknown;
|
|
47
|
+
distribute(entries: unknown): unknown;
|
|
48
|
+
isExpr(value: unknown): value is unknown;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ExpressionContext } from './expr';
|
|
2
|
+
export { asToolFn } from './tool';
|
|
3
|
+
export type { ToolFunction } from './tool';
|
|
4
|
+
export declare function exoEval(code: string): unknown;
|
|
5
|
+
export declare function exoEval<T>(code: string, ctx: ExpressionContext<T>): T;
|
|
6
|
+
export declare function exoFn<T extends (...args: any[]) => unknown>(fn: T): T;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EvalResult, Evaluator } from './evaluator';
|
|
2
|
+
import type * as acorn from 'acorn';
|
|
3
|
+
export declare class Scope<T> {
|
|
4
|
+
private readonly parent;
|
|
5
|
+
private readonly bindings;
|
|
6
|
+
constructor(parent: Scope<T> | undefined);
|
|
7
|
+
get(node: acorn.Identifier, evaluator: Evaluator<T>): T;
|
|
8
|
+
set(node: acorn.Identifier, value: T, evaluator: Evaluator<T>): void;
|
|
9
|
+
bind(param: acorn.Pattern, value: T, evaluator: Evaluator<T>): EvalResult<T>;
|
|
10
|
+
AssignmentPattern(param: acorn.AssignmentPattern, value: T, evaluator: Evaluator<T>): EvalResult<T, void>;
|
|
11
|
+
ArrayPattern(param: acorn.ArrayPattern, value: T, evaluator: Evaluator<T>): EvalResult<T, void>;
|
|
12
|
+
ObjectPattern(param: acorn.ObjectPattern, value: T, evaluator: Evaluator<T>): EvalResult<T, void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
export declare const toolSymbol: unique symbol;
|
|
3
|
+
export declare const toolFieldsSymbol: unique symbol;
|
|
4
|
+
export type ToolKind = 'raw' | 'expr' | 'constructor';
|
|
5
|
+
export type ToolFunction<T extends (...args: unknown[]) => unknown = (...args: unknown[]) => unknown> = T & ((...args: unknown[]) => unknown) & {
|
|
6
|
+
[toolSymbol]?: ToolKind;
|
|
7
|
+
};
|
|
8
|
+
export type ToolConstructor<T extends new (...args: unknown[]) => unknown = new (...args: unknown[]) => unknown> = T & {
|
|
9
|
+
[toolSymbol]?: ToolKind;
|
|
10
|
+
};
|
|
11
|
+
type SchemaToParam<Schema extends StandardSchemaV1> = Schema extends StandardSchemaV1<infer Params> ? Params : never;
|
|
12
|
+
type SchemasToParams<Schemas extends StandardSchemaV1[]> = {
|
|
13
|
+
[K in keyof Schemas]: SchemaToParam<Schemas[K]>;
|
|
14
|
+
};
|
|
15
|
+
export declare const validateArgs: <Schemas extends StandardSchemaV1[]>(methodName: string, inputSchemas: Schemas, args: SchemasToParams<Schemas>) => SchemasToParams<Schemas>;
|
|
16
|
+
export declare const registerToolField: (obj: unknown, key: string) => void;
|
|
17
|
+
/**
|
|
18
|
+
* @tool decorator - marks a method, getter, field, or class as a tool
|
|
19
|
+
*
|
|
20
|
+
* Methods: returns a replacement function on the prototype with validation + toolSymbol.
|
|
21
|
+
* Getters: returns a replacement getter with toolSymbol on the function.
|
|
22
|
+
* If the getter returns a function, it's wrapped with asTool(fn, undefined, schemas).
|
|
23
|
+
* Fields: adds field name to toolFieldsSymbol Set on instance.
|
|
24
|
+
* If value is a function with schemas, wraps with asTool.
|
|
25
|
+
* Classes: returns replacement class with constructor validation + toolSymbol.
|
|
26
|
+
*/
|
|
27
|
+
export declare function tool<Schemas extends StandardSchemaV1[]>(...argSchemas: Schemas): {
|
|
28
|
+
<This, Value extends (this: This, ...args: SchemasToParams<Schemas>) => any>(target: Value, context: ClassMethodDecoratorContext<This, Value>): Value;
|
|
29
|
+
<This, Value>(target: (this: This) => Value, context: ClassGetterDecoratorContext<This, Value>): (this: This) => Value;
|
|
30
|
+
<This, Value>(target: undefined, context: ClassFieldDecoratorContext<This, Value>): (value: Value) => Value;
|
|
31
|
+
<Value extends abstract new (...args: any) => any>(target: Value, context: ClassDecoratorContext<Value>): void;
|
|
32
|
+
};
|
|
33
|
+
export declare const fn: {
|
|
34
|
+
returns(retSchema: StandardSchemaV1): StandardSchemaV1<unknown, unknown> & {
|
|
35
|
+
optional: () => StandardSchemaV1;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export declare const expr: () => (target: any, _context: ClassMethodDecoratorContext) => any;
|
|
39
|
+
export declare function asToolFn<Schemas extends StandardSchemaV1[], T extends (...args: SchemasToParams<Schemas>) => unknown>(fn: T, schemas: Schemas): T & ToolFunction;
|
|
40
|
+
export declare const isToolableFunction: (value: unknown) => value is ToolFunction;
|
|
41
|
+
export declare const isExprFunction: (value: unknown) => boolean;
|
|
42
|
+
export declare const isToolableConstructor: (value: unknown) => value is ToolConstructor;
|
|
43
|
+
export declare const getTool: (thisArg: unknown, obj: unknown, key: string | number) => unknown;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type * as acorn from 'acorn';
|
|
2
|
+
export declare const disallowedProperties: Set<string>;
|
|
3
|
+
export declare const formatCodeMessage: (code: string, position: number, message: string) => string;
|
|
4
|
+
export declare class Invariant {
|
|
5
|
+
private readonly code;
|
|
6
|
+
constructor(code: string);
|
|
7
|
+
parse(condition: boolean, message: string, node: acorn.Node): asserts condition;
|
|
8
|
+
eval(condition: boolean, message: string, node: acorn.Node, value: unknown): asserts condition;
|
|
9
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export { RpcToolset, tool } from './rpc-toolset.js';
|
|
5
|
-
export type { ToolCallback } from './rpc-toolset.js';
|
|
1
|
+
export { codemode } from './code-mode';
|
|
2
|
+
export { exoEval } from './exoeval';
|
|
3
|
+
export { tool } from './exoeval/tool';
|