exoagent 0.0.1 → 0.0.3
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 +115 -30
- package/dist/capnweb/index-workers.cjs +2811 -0
- package/dist/capnweb/index-workers.cjs.map +1 -0
- package/dist/capnweb/index-workers.d.cts +2 -0
- package/dist/capnweb/index-workers.d.ts +2 -0
- package/dist/capnweb/index-workers.js +2774 -0
- package/dist/capnweb/index-workers.js.map +1 -0
- package/dist/capnweb/index.cjs +2788 -0
- package/dist/capnweb/index.cjs.map +1 -0
- package/dist/capnweb/index.d.cts +383 -0
- package/dist/capnweb/index.d.ts +383 -0
- package/dist/{code-mode-runtime.mjs → capnweb/index.js} +342 -90
- package/dist/capnweb/index.js.map +1 -0
- package/dist/capnweb-test-helpers.d.ts +25 -0
- package/dist/code-mode-deno.d.ts +13 -0
- package/dist/code-mode-runtime.d.ts +1 -0
- package/dist/code-mode.d.ts +39 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +97 -3391
- package/dist/rpc-toolset-BnC2BXPq.js +146 -0
- package/dist/rpc-toolset-test-helpers.d.mts +11 -2
- package/dist/rpc-toolset-test-helpers.d.ts +45 -0
- package/dist/rpc-toolset-test-helpers.mjs +12 -1371
- package/dist/rpc-toolset.d.ts +34 -0
- package/dist/sql/builder.d.ts +127 -0
- package/dist/sql/expression.d.ts +69 -0
- package/dist/sql/sql.d.ts +4 -0
- package/dist/sql/test-helpers.d.ts +9 -0
- package/dist/sql.d.ts +2 -0
- package/dist/sql.mjs +553 -0
- package/dist/stream-transport.d.ts +11 -0
- package/dist/tool-wrapper.d.ts +16 -0
- package/package.json +26 -12
- package/dist/index.d.mts +0 -426
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { inspect } from "node:util";
|
|
2
|
+
import { RpcTarget } from "capnweb";
|
|
3
|
+
const validate = (schema, value) => {
|
|
4
|
+
if ("~standard" in schema) {
|
|
5
|
+
const validation = schema["~standard"].validate(value);
|
|
6
|
+
if (validation instanceof Promise) {
|
|
7
|
+
throw new TypeError(`Validation must be synchronous`);
|
|
8
|
+
}
|
|
9
|
+
if (validation.issues) {
|
|
10
|
+
throw new Error(`Invalid value: ${validation.issues.map((e) => e.message).join(", ")}`);
|
|
11
|
+
}
|
|
12
|
+
} else {
|
|
13
|
+
if (!schema(value)) {
|
|
14
|
+
throw new Error(`Invalid value: ${inspect(value)} (expected ${schema.name || schema.toString()})`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const toolMetadataKey = Symbol("toolMetadata");
|
|
19
|
+
const setToolMetadata = (target, metadata) => {
|
|
20
|
+
const meta = target;
|
|
21
|
+
meta[toolMetadataKey] = {
|
|
22
|
+
...meta[toolMetadataKey],
|
|
23
|
+
...metadata
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
function toolDef(inputSchema) {
|
|
27
|
+
return (target, context) => {
|
|
28
|
+
if (context.kind !== "method") {
|
|
29
|
+
throw new Error(`Tool decorator can only be used on methods`);
|
|
30
|
+
}
|
|
31
|
+
const methodName = String(context.name);
|
|
32
|
+
const replacementMethod = function(...args) {
|
|
33
|
+
const expectedArgs = inputSchema ? 1 : 0;
|
|
34
|
+
if (args.length > expectedArgs) {
|
|
35
|
+
throw new Error(`Tool ${methodName} got too many arguments: ${args.length} provided (expected ${expectedArgs})`);
|
|
36
|
+
}
|
|
37
|
+
if (inputSchema) {
|
|
38
|
+
const arg = args[0];
|
|
39
|
+
validate(inputSchema, arg);
|
|
40
|
+
return target.call(this, arg);
|
|
41
|
+
} else {
|
|
42
|
+
return target.call(this);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
setToolMetadata(replacementMethod, { runtimeValidationEnabled: true });
|
|
46
|
+
return replacementMethod;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function toolUnsafeNoValidation() {
|
|
50
|
+
return (target, context) => {
|
|
51
|
+
if (context.kind !== "method") {
|
|
52
|
+
throw new Error(`Tool decorator can only be used on methods`);
|
|
53
|
+
}
|
|
54
|
+
setToolMetadata(target, { runtimeValidationEnabled: true });
|
|
55
|
+
return target;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const callbackMetadataKey = Symbol("callbackMetadata");
|
|
59
|
+
function callbackTool() {
|
|
60
|
+
return (target, context) => {
|
|
61
|
+
if (context.kind !== "method") {
|
|
62
|
+
throw new Error(`Tool decorator can only be used on methods`);
|
|
63
|
+
}
|
|
64
|
+
const methodName = String(context.name);
|
|
65
|
+
const replacementMethod = function(...args) {
|
|
66
|
+
if (args.length !== 1) {
|
|
67
|
+
throw new Error(`Tool ${methodName} got too many arguments: ${args.length} provided (expected 1)`);
|
|
68
|
+
}
|
|
69
|
+
const callback = args[0];
|
|
70
|
+
if (typeof callback !== "function") {
|
|
71
|
+
throw new TypeError(`Callback for tool ${methodName} must be a function`);
|
|
72
|
+
}
|
|
73
|
+
const callbackWrapped = (() => {
|
|
74
|
+
throw new Error(`Callback for tool ${methodName} must be wrapped with \`tool.unwrapCallback\``);
|
|
75
|
+
});
|
|
76
|
+
callbackWrapped[callbackMetadataKey] = {
|
|
77
|
+
callback
|
|
78
|
+
};
|
|
79
|
+
return target.call(this, callbackWrapped);
|
|
80
|
+
};
|
|
81
|
+
setToolMetadata(replacementMethod, { runtimeValidationEnabled: true });
|
|
82
|
+
return replacementMethod;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const unwrapCallback = (toolCallback, returnSchema) => (arg, then, opts) => {
|
|
86
|
+
const callback = callbackMetadataKey in toolCallback ? toolCallback[callbackMetadataKey].callback : toolCallback;
|
|
87
|
+
let isPromise = false;
|
|
88
|
+
try {
|
|
89
|
+
const result = callback(arg);
|
|
90
|
+
if (result instanceof Promise) {
|
|
91
|
+
isPromise = true;
|
|
92
|
+
let ret;
|
|
93
|
+
ret = result.then(async (r) => {
|
|
94
|
+
validate(returnSchema, r);
|
|
95
|
+
return then(r);
|
|
96
|
+
}, opts?.catch);
|
|
97
|
+
if (opts?.finally) {
|
|
98
|
+
ret = ret.finally(opts.finally);
|
|
99
|
+
}
|
|
100
|
+
return ret;
|
|
101
|
+
}
|
|
102
|
+
validate(returnSchema, result);
|
|
103
|
+
return then(result);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (opts?.catch) {
|
|
106
|
+
return opts.catch(error);
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
} finally {
|
|
110
|
+
if (!isPromise) {
|
|
111
|
+
opts?.finally?.();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const tool = toolDef;
|
|
116
|
+
tool.callback = callbackTool;
|
|
117
|
+
tool.unwrap = unwrapCallback;
|
|
118
|
+
tool.unsafeNoValidation = toolUnsafeNoValidation;
|
|
119
|
+
class RpcToolset extends RpcTarget {
|
|
120
|
+
constructor() {
|
|
121
|
+
super();
|
|
122
|
+
let prototype = Object.getPrototypeOf(this);
|
|
123
|
+
while (prototype !== null && prototype !== RpcToolset.prototype) {
|
|
124
|
+
for (const key of Object.getOwnPropertyNames(prototype)) {
|
|
125
|
+
if (key === "constructor") {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, key);
|
|
129
|
+
const fn = descriptor?.value ?? descriptor?.get;
|
|
130
|
+
if (!fn || typeof fn !== "function") {
|
|
131
|
+
throw new Error(`RpcToolset prototype must be methods or getters: ${key} is not`);
|
|
132
|
+
}
|
|
133
|
+
const meta = fn;
|
|
134
|
+
if (!meta[toolMetadataKey]?.runtimeValidationEnabled) {
|
|
135
|
+
throw new Error(`Prototype method \`${key}\` is not a tool. Did you forget to use the @tool decorator?`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export {
|
|
143
|
+
RpcToolset as R,
|
|
144
|
+
setToolMetadata as s,
|
|
145
|
+
tool as t
|
|
146
|
+
};
|
|
@@ -154,7 +154,11 @@ declare class QueryBuilder<N extends string, TN extends TableNamespace, S extend
|
|
|
154
154
|
offset(offset: number): QueryBuilder<N, TN, S>;
|
|
155
155
|
join<N2 extends string, F2 extends TableClass<N2>>(fromItem: F2 | NamespacedExpression<TN, F2>, on?: NamespacedExpression<TN & { [k in N2]: InstanceType<F2> }, SqlExpressionIn>): QueryBuilder<N, TN & { [k in N2]: InstanceType<F2> }, S>;
|
|
156
156
|
join<N2 extends string, F2 extends RowLike>(fromItem: FromItem<N2, F2> | NamespacedExpression<TN, FromItem<N2, F2>>, on?: NamespacedExpression<TN & { [k in N2]: F2 }, SqlExpressionIn>): QueryBuilder<N, TN & { [k in N2]: F2 }, S>;
|
|
157
|
-
execute(): Promise<{
|
|
157
|
+
execute(): Promise<{
|
|
158
|
+
results: { [key in keyof S]: unknown }[];
|
|
159
|
+
sql?: string;
|
|
160
|
+
parameters?: readonly unknown[];
|
|
161
|
+
}>;
|
|
158
162
|
private paramsForCopy;
|
|
159
163
|
toRowLike: () => S;
|
|
160
164
|
compile: (opts?: {
|
|
@@ -190,8 +194,13 @@ declare class Database {
|
|
|
190
194
|
private kysely?;
|
|
191
195
|
constructor(dialect: Dialect, opts?: {
|
|
192
196
|
logQuery?: (raw: CompiledQuery) => void;
|
|
197
|
+
returnExecutedQuery?: boolean;
|
|
193
198
|
} | undefined);
|
|
194
|
-
execute(query: RawSql): Promise<
|
|
199
|
+
execute(query: RawSql): Promise<{
|
|
200
|
+
results: unknown[];
|
|
201
|
+
sql?: string;
|
|
202
|
+
parameters?: readonly unknown[];
|
|
203
|
+
}>;
|
|
195
204
|
Table<N extends string>(name: N): TableClass<N>;
|
|
196
205
|
}
|
|
197
206
|
//#endregion
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { RpcToolset } from './rpc-toolset';
|
|
2
|
+
export declare class TestToolset extends RpcToolset {
|
|
3
|
+
add(input: {
|
|
4
|
+
a: number;
|
|
5
|
+
b: number;
|
|
6
|
+
}): Promise<number>;
|
|
7
|
+
toolset2(): Promise<TestToolset2>;
|
|
8
|
+
userForId({ id }: {
|
|
9
|
+
id: string;
|
|
10
|
+
}): Promise<typeof User>;
|
|
11
|
+
}
|
|
12
|
+
export declare class TestToolset2 extends RpcToolset {
|
|
13
|
+
subtract(input: {
|
|
14
|
+
a: number;
|
|
15
|
+
b: number;
|
|
16
|
+
}): Promise<number>;
|
|
17
|
+
}
|
|
18
|
+
declare const User_base: Omit<import('./sql').TableClass<"users">, keyof import('./sql').TableClass<string>> & import('./sql').TableClass<"user"> & (new () => {
|
|
19
|
+
opts?: {
|
|
20
|
+
remapColumns?: boolean;
|
|
21
|
+
};
|
|
22
|
+
column: (this: InstanceType<import('./sql').TableClass<string>>, columnName: string) => import('./sql/expression').ColumnReferenceExpression;
|
|
23
|
+
__RPC_TARGET_BRAND: never;
|
|
24
|
+
});
|
|
25
|
+
export declare class User extends User_base {
|
|
26
|
+
id: import('./sql/expression').ColumnReferenceExpression;
|
|
27
|
+
name: import('./sql/expression').ColumnReferenceExpression;
|
|
28
|
+
email: import('./sql/expression').ColumnReferenceExpression;
|
|
29
|
+
age: import('./sql/expression').ColumnReferenceExpression;
|
|
30
|
+
posts(): typeof Post;
|
|
31
|
+
}
|
|
32
|
+
declare const Post_base: Omit<import('./sql').TableClass<"posts">, keyof import('./sql').TableClass<string>> & import('./sql').TableClass<"post"> & (new () => {
|
|
33
|
+
opts?: {
|
|
34
|
+
remapColumns?: boolean;
|
|
35
|
+
};
|
|
36
|
+
column: (this: InstanceType<import('./sql').TableClass<string>>, columnName: string) => import('./sql/expression').ColumnReferenceExpression;
|
|
37
|
+
__RPC_TARGET_BRAND: never;
|
|
38
|
+
});
|
|
39
|
+
export declare class Post extends Post_base {
|
|
40
|
+
id: import('./sql/expression').ColumnReferenceExpression;
|
|
41
|
+
userId: import('./sql/expression').ColumnReferenceExpression;
|
|
42
|
+
title: import('./sql/expression').ColumnReferenceExpression;
|
|
43
|
+
content: import('./sql/expression').ColumnReferenceExpression;
|
|
44
|
+
}
|
|
45
|
+
export {};
|