@fluidframework/tree-agent 2.80.0 → 2.81.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +95 -0
- package/api-report/tree-agent.alpha.api.md +195 -20
- package/dist/alpha.d.ts +31 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/methodBinding.d.ts +54 -10
- package/dist/methodBinding.d.ts.map +1 -1
- package/dist/methodBinding.js.map +1 -1
- package/dist/propertyBinding.d.ts +52 -2
- package/dist/propertyBinding.d.ts.map +1 -1
- package/dist/propertyBinding.js +28 -3
- package/dist/propertyBinding.js.map +1 -1
- package/dist/renderSchemaTypeScript.d.ts.map +1 -1
- package/dist/renderSchemaTypeScript.js +23 -8
- package/dist/renderSchemaTypeScript.js.map +1 -1
- package/dist/renderTypeFactoryTypeScript.d.ts +13 -0
- package/dist/renderTypeFactoryTypeScript.d.ts.map +1 -0
- package/dist/renderTypeFactoryTypeScript.js +290 -0
- package/dist/renderTypeFactoryTypeScript.js.map +1 -0
- package/dist/subtree.d.ts.map +1 -1
- package/dist/subtree.js +4 -4
- package/dist/subtree.js.map +1 -1
- package/dist/treeAgentTypes.d.ts +430 -0
- package/dist/treeAgentTypes.d.ts.map +1 -0
- package/dist/treeAgentTypes.js +227 -0
- package/dist/treeAgentTypes.js.map +1 -0
- package/dist/utils.d.ts +0 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -9
- package/dist/utils.js.map +1 -1
- package/eslint.config.mts +4 -4
- package/lib/alpha.d.ts +31 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/methodBinding.d.ts +54 -10
- package/lib/methodBinding.d.ts.map +1 -1
- package/lib/methodBinding.js.map +1 -1
- package/lib/propertyBinding.d.ts +52 -2
- package/lib/propertyBinding.d.ts.map +1 -1
- package/lib/propertyBinding.js +28 -3
- package/lib/propertyBinding.js.map +1 -1
- package/lib/renderSchemaTypeScript.d.ts.map +1 -1
- package/lib/renderSchemaTypeScript.js +23 -8
- package/lib/renderSchemaTypeScript.js.map +1 -1
- package/lib/renderTypeFactoryTypeScript.d.ts +13 -0
- package/lib/renderTypeFactoryTypeScript.d.ts.map +1 -0
- package/lib/renderTypeFactoryTypeScript.js +285 -0
- package/lib/renderTypeFactoryTypeScript.js.map +1 -0
- package/lib/subtree.d.ts.map +1 -1
- package/lib/subtree.js +4 -4
- package/lib/subtree.js.map +1 -1
- package/lib/treeAgentTypes.d.ts +430 -0
- package/lib/treeAgentTypes.d.ts.map +1 -0
- package/lib/treeAgentTypes.js +223 -0
- package/lib/treeAgentTypes.js.map +1 -0
- package/lib/utils.d.ts +0 -4
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +2 -8
- package/lib/utils.js.map +1 -1
- package/package.json +12 -12
- package/src/index.ts +36 -0
- package/src/methodBinding.ts +93 -15
- package/src/propertyBinding.ts +66 -9
- package/src/renderSchemaTypeScript.ts +31 -9
- package/src/renderTypeFactoryTypeScript.ts +339 -0
- package/src/subtree.ts +5 -4
- package/src/treeAgentTypes.ts +611 -0
- package/src/utils.ts +2 -9
- package/.eslintrc.cjs +0 -48
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,100 @@
|
|
|
1
1
|
# @fluidframework/tree-agent
|
|
2
2
|
|
|
3
|
+
## 2.81.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- tree-agent: New type factory system for method and property bindings ([#26167](https://github.com/microsoft/FluidFramework/pull/26167)) [f09aa24009](https://github.com/microsoft/FluidFramework/commit/f09aa24009635284852e07f126eadb7a7a8c0fdf)
|
|
8
|
+
|
|
9
|
+
The `@fluidframework/tree-agent` package now includes a custom type system (Type Factory) as an alternative to Zod for
|
|
10
|
+
defining method and property types. This new system is available in the `/alpha` entry point and provides a familiar
|
|
11
|
+
API for type definitions.
|
|
12
|
+
|
|
13
|
+
#### Key features
|
|
14
|
+
- **Familiar API**: Use `tf.string()`, `tf.object()`, etc. - similar to Zod's syntax (where `tf` is aliased from
|
|
15
|
+
`typeFactory`)
|
|
16
|
+
- **Same API surface**: The existing `expose`, `exposeProperty`, and `buildFunc` methods work with both Zod and Type
|
|
17
|
+
Factory types
|
|
18
|
+
|
|
19
|
+
#### Usage
|
|
20
|
+
|
|
21
|
+
Import from the alpha entry point to use Type Factory types:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import {
|
|
25
|
+
typeFactory as tf,
|
|
26
|
+
buildFunc,
|
|
27
|
+
exposeMethodsSymbol,
|
|
28
|
+
} from "@fluidframework/tree-agent/alpha";
|
|
29
|
+
import { SchemaFactory } from "@fluidframework/tree";
|
|
30
|
+
|
|
31
|
+
const sf = new SchemaFactory("myApp");
|
|
32
|
+
|
|
33
|
+
class TodoList extends sf.object("TodoList", {
|
|
34
|
+
items: sf.array(sf.string),
|
|
35
|
+
}) {
|
|
36
|
+
public addItem(item: string): void {
|
|
37
|
+
this.items.insertAtEnd(item);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static [exposeMethodsSymbol](methods) {
|
|
41
|
+
methods.expose(
|
|
42
|
+
TodoList,
|
|
43
|
+
"addItem",
|
|
44
|
+
buildFunc({ returns: tf.void() }, ["item", tf.string()]),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Available types
|
|
51
|
+
|
|
52
|
+
All common types are supported:
|
|
53
|
+
- **Primitives**: `tf.string()`, `tf.number()`, `tf.boolean()`, `tf.void()`, `tf.undefined()`, `tf.null()`,
|
|
54
|
+
`tf.unknown()`
|
|
55
|
+
- **Collections**: `tf.array(elementType)`, `tf.object({ shape })`, `tf.map(keyType, valueType)`,
|
|
56
|
+
`tf.record(keyType, valueType)`, `tf.tuple([types])`
|
|
57
|
+
- **Utilities**: `tf.union([types])`, `tf.literal(value)`, `tf.optional(type)`, `tf.readonly(type)`
|
|
58
|
+
- **Schema references**: `tf.instanceOf(SchemaClass)`
|
|
59
|
+
|
|
60
|
+
#### Migration from Zod
|
|
61
|
+
|
|
62
|
+
You can migrate gradually - both Zod and Type Factory types work in the same codebase:
|
|
63
|
+
|
|
64
|
+
**Before (Zod):**
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { z } from "zod";
|
|
68
|
+
import { buildFunc, exposeMethodsSymbol } from "@fluidframework/tree-agent";
|
|
69
|
+
|
|
70
|
+
methods.expose(
|
|
71
|
+
MyClass,
|
|
72
|
+
"myMethod",
|
|
73
|
+
buildFunc({ returns: z.string() }, ["param", z.number()]),
|
|
74
|
+
);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**After (Type Factory):**
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import {
|
|
81
|
+
typeFactory as tf,
|
|
82
|
+
buildFunc,
|
|
83
|
+
exposeMethodsSymbol,
|
|
84
|
+
} from "@fluidframework/tree-agent/alpha";
|
|
85
|
+
|
|
86
|
+
methods.expose(
|
|
87
|
+
MyClass,
|
|
88
|
+
"myMethod",
|
|
89
|
+
buildFunc({ returns: tf.string() }, ["param", tf.number()]),
|
|
90
|
+
);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Note on type safety
|
|
94
|
+
|
|
95
|
+
The Type Factory type system does not currently provide compile-time type checking, though this may be added in the
|
|
96
|
+
future. For applications requiring strict compile-time validation, Zod types remain fully supported.
|
|
97
|
+
|
|
3
98
|
## 2.80.0
|
|
4
99
|
|
|
5
100
|
Dependency updates only.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
```ts
|
|
6
6
|
|
|
7
7
|
// @alpha
|
|
8
|
-
export type Arg<T extends z.ZodTypeAny = z.ZodTypeAny> = readonly [name: string, type: T];
|
|
8
|
+
export type Arg<T extends z.ZodTypeAny | TypeFactoryType = z.ZodTypeAny | TypeFactoryType> = readonly [name: string, type: T];
|
|
9
9
|
|
|
10
10
|
// @alpha
|
|
11
11
|
export type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Single extends Arg] ? [Single[1]] : T extends readonly [infer Head extends Arg, ...infer Tail extends readonly Arg[]] ? [Head[1], ...ArgsTuple<Tail>] : never;
|
|
@@ -17,7 +17,7 @@ export type AsynchronousEditor<TSchema extends ImplicitFieldSchema> = (tree: Vie
|
|
|
17
17
|
export type BindableSchema = TreeNodeSchema<string, NodeKind.Object> | TreeNodeSchema<string, NodeKind.Record> | TreeNodeSchema<string, NodeKind.Array> | TreeNodeSchema<string, NodeKind.Map>;
|
|
18
18
|
|
|
19
19
|
// @alpha
|
|
20
|
-
export function buildFunc<const Return extends z.ZodTypeAny, const Args extends readonly Arg[], const Rest extends z.ZodTypeAny | null = null>(def: {
|
|
20
|
+
export function buildFunc<const Return extends z.ZodTypeAny | TypeFactoryType, const Args extends readonly Arg[], const Rest extends z.ZodTypeAny | TypeFactoryType | null = null>(def: {
|
|
21
21
|
description?: string;
|
|
22
22
|
returns: Return;
|
|
23
23
|
rest?: Rest;
|
|
@@ -53,19 +53,23 @@ export type ExposableKeys<T> = {
|
|
|
53
53
|
|
|
54
54
|
// @alpha
|
|
55
55
|
export interface ExposedMethods {
|
|
56
|
-
|
|
57
|
-
expose<const K extends string & keyof MethodKeys<InstanceType<S>>, S extends BindableSchema & Ctor
|
|
56
|
+
expose<const K extends string & keyof MethodKeys<InstanceType<S>>, S extends BindableSchema & Ctor<Record<K, InferZod<Z>>> & IExposedMethods, Z extends FunctionDef<readonly Arg<z.ZodTypeAny>[], z.ZodTypeAny, z.ZodTypeAny | null>>(schema: S, methodName: K, zodFunction: Z): void;
|
|
57
|
+
expose<const K extends string & keyof MethodKeys<InstanceType<S>>, S extends BindableSchema & Ctor & IExposedMethods, Z extends FunctionDef<readonly Arg<TypeFactoryType>[], TypeFactoryType, TypeFactoryType | null>>(schema: S, methodName: K, tfFunction: Z): void;
|
|
58
58
|
instanceOf<T extends TreeNodeSchemaClass>(schema: T): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>>;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// @alpha
|
|
62
62
|
export interface ExposedProperties {
|
|
63
|
-
// (undocumented)
|
|
64
63
|
exposeProperty<S extends BindableSchema & Ctor, K extends string & ExposableKeys<InstanceType<S>>, TZ extends ZodTypeAny>(schema: S, name: K, def: {
|
|
65
64
|
schema: TZ;
|
|
66
65
|
description?: string;
|
|
67
66
|
} & ReadOnlyRequirement<InstanceType<S>, K> & TypeMatchOrError<InstanceType<S>[K], infer<TZ>>): void;
|
|
68
|
-
|
|
67
|
+
exposeProperty<S extends BindableSchema & Ctor, K extends string & ExposableKeys<InstanceType<S>>>(schema: S, name: K, def: {
|
|
68
|
+
schema: TypeFactoryType;
|
|
69
|
+
description?: string;
|
|
70
|
+
readOnly?: boolean;
|
|
71
|
+
}): void;
|
|
72
|
+
exposeProperty<S extends BindableSchema & Ctor, K extends string & ExposableKeys<InstanceType<S>>>(schema: S, name: K, tfType: TypeFactoryType): void;
|
|
69
73
|
instanceOf<T extends TreeNodeSchemaClass>(schema: T): ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>;
|
|
70
74
|
}
|
|
71
75
|
|
|
@@ -76,34 +80,46 @@ export const exposeMethodsSymbol: unique symbol;
|
|
|
76
80
|
export const exposePropertiesSymbol: unique symbol;
|
|
77
81
|
|
|
78
82
|
// @alpha
|
|
79
|
-
export interface FunctionDef<Args extends readonly Arg[], Return extends z.ZodTypeAny, Rest extends z.ZodTypeAny | null = null> {
|
|
80
|
-
// (undocumented)
|
|
83
|
+
export interface FunctionDef<Args extends readonly Arg[], Return extends z.ZodTypeAny | TypeFactoryType, Rest extends z.ZodTypeAny | TypeFactoryType | null = null> {
|
|
81
84
|
args: Args;
|
|
82
|
-
// (undocumented)
|
|
83
85
|
description?: string;
|
|
84
|
-
// (undocumented)
|
|
85
86
|
rest?: Rest;
|
|
86
|
-
// (undocumented)
|
|
87
87
|
returns: Return;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
// @alpha
|
|
91
91
|
export interface IExposedMethods {
|
|
92
|
-
// (undocumented)
|
|
93
92
|
[exposeMethodsSymbol](methods: ExposedMethods): void;
|
|
94
93
|
}
|
|
95
94
|
|
|
96
95
|
// @alpha
|
|
97
96
|
export interface IExposedProperties {
|
|
98
|
-
// (undocumented)
|
|
99
97
|
[exposePropertiesSymbol]?(properties: ExposedProperties): void;
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
// @alpha
|
|
103
101
|
export type IfEquals<X, Y, A = true, B = false> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B;
|
|
104
102
|
|
|
103
|
+
// @alpha @deprecated
|
|
104
|
+
export type Infer<T> = T extends FunctionDef<readonly Arg[], infer Return, any> ? Return extends z.ZodTypeAny ? InferZod<T> : InferTypeFactory<T> : never;
|
|
105
|
+
|
|
106
|
+
// @alpha
|
|
107
|
+
export type InferArgsZod<Args extends readonly Arg<z.ZodTypeAny>[]> = Args extends readonly [
|
|
108
|
+
infer Head extends Arg<z.ZodTypeAny>,
|
|
109
|
+
...infer Tail extends readonly Arg<z.ZodTypeAny>[]
|
|
110
|
+
] ? [z.infer<Head[1]>, ...InferArgsZod<Tail>] : [];
|
|
111
|
+
|
|
112
|
+
// @alpha
|
|
113
|
+
export type InferTypeFactory<T> = T extends FunctionDef<readonly Arg[], infer Return, any> ? (...args: any[]) => any : never;
|
|
114
|
+
|
|
105
115
|
// @alpha
|
|
106
|
-
export type
|
|
116
|
+
export type InferZod<T> = T extends FunctionDef<infer Args extends readonly Arg<z.ZodTypeAny>[], infer Return extends z.ZodTypeAny, any> ? (...args: InferArgsZod<Args>) => z.infer<Return> : never;
|
|
117
|
+
|
|
118
|
+
// @alpha
|
|
119
|
+
export const instanceOfsTypeFactory: WeakMap<TypeFactoryInstanceOf, ObjectNodeSchema<string, RestrictiveStringRecord<ImplicitFieldSchema_2>, boolean, unknown>>;
|
|
120
|
+
|
|
121
|
+
// @alpha
|
|
122
|
+
export function isTypeFactoryType(value: unknown): value is TypeFactoryType;
|
|
107
123
|
|
|
108
124
|
// @alpha
|
|
109
125
|
export const llmDefault: unique symbol;
|
|
@@ -120,15 +136,15 @@ export type MethodKeys<T> = {
|
|
|
120
136
|
|
|
121
137
|
// @alpha
|
|
122
138
|
export class PropertyDef {
|
|
123
|
-
constructor(
|
|
124
|
-
|
|
139
|
+
constructor(
|
|
140
|
+
name: string,
|
|
141
|
+
description: string | undefined,
|
|
142
|
+
schema: ZodTypeAny | TypeFactoryType,
|
|
143
|
+
readOnly: boolean);
|
|
125
144
|
readonly description: string | undefined;
|
|
126
|
-
// (undocumented)
|
|
127
145
|
readonly name: string;
|
|
128
|
-
// (undocumented)
|
|
129
146
|
readonly readOnly: boolean;
|
|
130
|
-
|
|
131
|
-
readonly schema: ZodTypeAny;
|
|
147
|
+
readonly schema: ZodTypeAny | TypeFactoryType;
|
|
132
148
|
}
|
|
133
149
|
|
|
134
150
|
// @alpha
|
|
@@ -183,6 +199,165 @@ export type SynchronousEditor<TSchema extends ImplicitFieldSchema> = (tree: View
|
|
|
183
199
|
// @alpha
|
|
184
200
|
export type TreeView<TRoot extends ImplicitFieldSchema> = Pick<TreeViewAlpha<TRoot>, "root" | "fork" | "merge" | "rebaseOnto" | "schema" | "events"> & TreeBranchAlpha;
|
|
185
201
|
|
|
202
|
+
// @alpha
|
|
203
|
+
export const typeFactory: {
|
|
204
|
+
string(): TypeFactoryString;
|
|
205
|
+
number(): TypeFactoryNumber;
|
|
206
|
+
boolean(): TypeFactoryBoolean;
|
|
207
|
+
date(): TypeFactoryDate;
|
|
208
|
+
void(): TypeFactoryVoid;
|
|
209
|
+
undefined(): TypeFactoryUndefined;
|
|
210
|
+
null(): TypeFactoryNull;
|
|
211
|
+
unknown(): TypeFactoryUnknown;
|
|
212
|
+
array(element: TypeFactoryType): TypeFactoryArray;
|
|
213
|
+
promise(innerType: TypeFactoryType): TypeFactoryPromise;
|
|
214
|
+
object(shape: Record<string, TypeFactoryType>): TypeFactoryObject;
|
|
215
|
+
record(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryRecord;
|
|
216
|
+
map(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryMap;
|
|
217
|
+
tuple(items: readonly TypeFactoryType[], rest?: TypeFactoryType): TypeFactoryTuple;
|
|
218
|
+
union(options: readonly TypeFactoryType[]): TypeFactoryUnion;
|
|
219
|
+
intersection(types: readonly TypeFactoryType[]): TypeFactoryIntersection;
|
|
220
|
+
literal(value: string | number | boolean): TypeFactoryLiteral;
|
|
221
|
+
optional(innerType: TypeFactoryType): TypeFactoryOptional;
|
|
222
|
+
readonly(innerType: TypeFactoryType): TypeFactoryReadonly;
|
|
223
|
+
function(parameters: readonly TypeFactoryFunctionParameter[], returnType: TypeFactoryType, restParameter?: TypeFactoryFunctionParameter): TypeFactoryFunction;
|
|
224
|
+
instanceOf<T extends TreeNodeSchemaClass_2>(schema: T): TypeFactoryInstanceOf;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// @alpha
|
|
228
|
+
export interface TypeFactoryArray extends TypeFactoryType {
|
|
229
|
+
readonly element: TypeFactoryType;
|
|
230
|
+
readonly _kind: "array";
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// @alpha
|
|
234
|
+
export interface TypeFactoryBoolean extends TypeFactoryType {
|
|
235
|
+
readonly _kind: "boolean";
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// @alpha
|
|
239
|
+
export interface TypeFactoryDate extends TypeFactoryType {
|
|
240
|
+
readonly _kind: "date";
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// @alpha
|
|
244
|
+
export interface TypeFactoryFunction extends TypeFactoryType {
|
|
245
|
+
readonly _kind: "function";
|
|
246
|
+
readonly parameters: readonly TypeFactoryFunctionParameter[];
|
|
247
|
+
readonly restParameter?: TypeFactoryFunctionParameter;
|
|
248
|
+
readonly returnType: TypeFactoryType;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// @alpha
|
|
252
|
+
export type TypeFactoryFunctionParameter = readonly [name: string, type: TypeFactoryType];
|
|
253
|
+
|
|
254
|
+
// @alpha
|
|
255
|
+
export interface TypeFactoryInstanceOf extends TypeFactoryType {
|
|
256
|
+
readonly _kind: "instanceof";
|
|
257
|
+
readonly schema: ObjectNodeSchema;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// @alpha
|
|
261
|
+
export interface TypeFactoryIntersection extends TypeFactoryType {
|
|
262
|
+
readonly _kind: "intersection";
|
|
263
|
+
readonly types: readonly TypeFactoryType[];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// @alpha
|
|
267
|
+
export interface TypeFactoryLiteral extends TypeFactoryType {
|
|
268
|
+
readonly _kind: "literal";
|
|
269
|
+
readonly value: string | number | boolean;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// @alpha
|
|
273
|
+
export interface TypeFactoryMap extends TypeFactoryType {
|
|
274
|
+
readonly keyType: TypeFactoryType;
|
|
275
|
+
readonly _kind: "map";
|
|
276
|
+
readonly valueType: TypeFactoryType;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// @alpha
|
|
280
|
+
export interface TypeFactoryNull extends TypeFactoryType {
|
|
281
|
+
readonly _kind: "null";
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// @alpha
|
|
285
|
+
export interface TypeFactoryNumber extends TypeFactoryType {
|
|
286
|
+
readonly _kind: "number";
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// @alpha
|
|
290
|
+
export interface TypeFactoryObject extends TypeFactoryType {
|
|
291
|
+
readonly _kind: "object";
|
|
292
|
+
readonly shape: Record<string, TypeFactoryType>;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// @alpha
|
|
296
|
+
export interface TypeFactoryOptional extends TypeFactoryType {
|
|
297
|
+
readonly innerType: TypeFactoryType;
|
|
298
|
+
readonly _kind: "optional";
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// @alpha
|
|
302
|
+
export interface TypeFactoryPromise extends TypeFactoryType {
|
|
303
|
+
readonly innerType: TypeFactoryType;
|
|
304
|
+
readonly _kind: "promise";
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// @alpha
|
|
308
|
+
export interface TypeFactoryReadonly extends TypeFactoryType {
|
|
309
|
+
readonly innerType: TypeFactoryType;
|
|
310
|
+
readonly _kind: "readonly";
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// @alpha
|
|
314
|
+
export interface TypeFactoryRecord extends TypeFactoryType {
|
|
315
|
+
readonly keyType: TypeFactoryType;
|
|
316
|
+
readonly _kind: "record";
|
|
317
|
+
readonly valueType: TypeFactoryType;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// @alpha
|
|
321
|
+
export interface TypeFactoryString extends TypeFactoryType {
|
|
322
|
+
readonly _kind: "string";
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// @alpha
|
|
326
|
+
export interface TypeFactoryTuple extends TypeFactoryType {
|
|
327
|
+
readonly items: readonly TypeFactoryType[];
|
|
328
|
+
readonly _kind: "tuple";
|
|
329
|
+
readonly rest?: TypeFactoryType;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// @alpha
|
|
333
|
+
export interface TypeFactoryType {
|
|
334
|
+
readonly _kind: TypeFactoryTypeKind;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// @alpha
|
|
338
|
+
export type TypeFactoryTypeKind = "string" | "number" | "boolean" | "void" | "undefined" | "null" | "unknown" | "date" | "promise" | "array" | "object" | "record" | "map" | "tuple" | "union" | "intersection" | "literal" | "optional" | "readonly" | "function" | "instanceof";
|
|
339
|
+
|
|
340
|
+
// @alpha
|
|
341
|
+
export interface TypeFactoryUndefined extends TypeFactoryType {
|
|
342
|
+
readonly _kind: "undefined";
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// @alpha
|
|
346
|
+
export interface TypeFactoryUnion extends TypeFactoryType {
|
|
347
|
+
readonly _kind: "union";
|
|
348
|
+
readonly options: readonly TypeFactoryType[];
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// @alpha
|
|
352
|
+
export interface TypeFactoryUnknown extends TypeFactoryType {
|
|
353
|
+
readonly _kind: "unknown";
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// @alpha
|
|
357
|
+
export interface TypeFactoryVoid extends TypeFactoryType {
|
|
358
|
+
readonly _kind: "void";
|
|
359
|
+
}
|
|
360
|
+
|
|
186
361
|
// @alpha
|
|
187
362
|
export type TypeMatchOrError<Expected, Received> = [Received] extends [Expected] ? unknown : {
|
|
188
363
|
__error__: "Zod schema value type does not match the property's declared type";
|
package/dist/alpha.d.ts
CHANGED
|
@@ -31,6 +31,9 @@ export {
|
|
|
31
31
|
IExposedProperties,
|
|
32
32
|
IfEquals,
|
|
33
33
|
Infer,
|
|
34
|
+
InferArgsZod,
|
|
35
|
+
InferTypeFactory,
|
|
36
|
+
InferZod,
|
|
34
37
|
Logger,
|
|
35
38
|
MethodKeys,
|
|
36
39
|
PropertyDef,
|
|
@@ -42,12 +45,39 @@ export {
|
|
|
42
45
|
SharedTreeSemanticAgent,
|
|
43
46
|
SynchronousEditor,
|
|
44
47
|
TreeView,
|
|
48
|
+
TypeFactoryArray,
|
|
49
|
+
TypeFactoryBoolean,
|
|
50
|
+
TypeFactoryDate,
|
|
51
|
+
TypeFactoryFunction,
|
|
52
|
+
TypeFactoryFunctionParameter,
|
|
53
|
+
TypeFactoryInstanceOf,
|
|
54
|
+
TypeFactoryIntersection,
|
|
55
|
+
TypeFactoryLiteral,
|
|
56
|
+
TypeFactoryMap,
|
|
57
|
+
TypeFactoryNull,
|
|
58
|
+
TypeFactoryNumber,
|
|
59
|
+
TypeFactoryObject,
|
|
60
|
+
TypeFactoryOptional,
|
|
61
|
+
TypeFactoryPromise,
|
|
62
|
+
TypeFactoryReadonly,
|
|
63
|
+
TypeFactoryRecord,
|
|
64
|
+
TypeFactoryString,
|
|
65
|
+
TypeFactoryTuple,
|
|
66
|
+
TypeFactoryType,
|
|
67
|
+
TypeFactoryTypeKind,
|
|
68
|
+
TypeFactoryUndefined,
|
|
69
|
+
TypeFactoryUnion,
|
|
70
|
+
TypeFactoryUnknown,
|
|
71
|
+
TypeFactoryVoid,
|
|
45
72
|
TypeMatchOrError,
|
|
46
73
|
ViewOrTree,
|
|
47
74
|
buildFunc,
|
|
48
75
|
createContext,
|
|
49
76
|
exposeMethodsSymbol,
|
|
50
77
|
exposePropertiesSymbol,
|
|
51
|
-
|
|
78
|
+
instanceOfsTypeFactory,
|
|
79
|
+
isTypeFactoryType,
|
|
80
|
+
llmDefault,
|
|
81
|
+
typeFactory
|
|
52
82
|
// #endregion
|
|
53
83
|
} from "./index.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
export { SharedTreeSemanticAgent, createContext, } from "./agent.js";
|
|
11
11
|
export type { EditResult, SharedTreeChatModel, SharedTreeChatQuery, Logger, SemanticAgentOptions, SynchronousEditor, AsynchronousEditor, TreeView, ViewOrTree, Context, } from "./api.js";
|
|
12
12
|
export { llmDefault } from "./utils.js";
|
|
13
|
-
export { buildFunc, exposeMethodsSymbol, type ArgsTuple, type ExposedMethods, type Arg, type FunctionDef, type MethodKeys, type BindableSchema, type Ctor, type Infer, type IExposedMethods, } from "./methodBinding.js";
|
|
13
|
+
export { buildFunc, exposeMethodsSymbol, type ArgsTuple, type ExposedMethods, type Arg, type FunctionDef, type MethodKeys, type BindableSchema, type Ctor, type Infer, type InferZod, type InferArgsZod, type InferTypeFactory, type IExposedMethods, } from "./methodBinding.js";
|
|
14
14
|
export type { exposePropertiesSymbol, PropertyDef, ExposedProperties, IExposedProperties, ExposableKeys, ReadOnlyRequirement, ReadonlyKeys, TypeMatchOrError, IfEquals, } from "./propertyBinding.js";
|
|
15
|
+
export { typeFactory, isTypeFactoryType, instanceOfsTypeFactory, } from "./treeAgentTypes.js";
|
|
16
|
+
export type { TypeFactoryType, TypeFactoryTypeKind, TypeFactoryString, TypeFactoryNumber, TypeFactoryBoolean, TypeFactoryDate, TypeFactoryVoid, TypeFactoryUndefined, TypeFactoryNull, TypeFactoryUnknown, TypeFactoryArray, TypeFactoryPromise, TypeFactoryObject, TypeFactoryRecord, TypeFactoryMap, TypeFactoryTuple, TypeFactoryUnion, TypeFactoryIntersection, TypeFactoryLiteral, TypeFactoryOptional, TypeFactoryReadonly, TypeFactoryFunction, TypeFactoryFunctionParameter, TypeFactoryInstanceOf, } from "./treeAgentTypes.js";
|
|
15
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EACN,uBAAuB,EACvB,aAAa,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EACX,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EACnB,MAAM,EACN,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,OAAO,GACP,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EACN,SAAS,EACT,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,GAAG,EACR,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,IAAI,EACT,KAAK,KAAK,EACV,KAAK,eAAe,GACpB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACX,sBAAsB,EACtB,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,QAAQ,GACR,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH,OAAO,EACN,uBAAuB,EACvB,aAAa,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EACX,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EACnB,MAAM,EACN,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,OAAO,GACP,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EACN,SAAS,EACT,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,GAAG,EACR,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,IAAI,EACT,KAAK,KAAK,EACV,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACpB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACX,sBAAsB,EACtB,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,QAAQ,GACR,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,sBAAsB,GACtB,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EACX,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,4BAA4B,EAC5B,qBAAqB,GACrB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.exposeMethodsSymbol = exports.buildFunc = exports.llmDefault = exports.createContext = exports.SharedTreeSemanticAgent = void 0;
|
|
7
|
+
exports.instanceOfsTypeFactory = exports.isTypeFactoryType = exports.typeFactory = exports.exposeMethodsSymbol = exports.buildFunc = exports.llmDefault = exports.createContext = exports.SharedTreeSemanticAgent = void 0;
|
|
8
8
|
/**
|
|
9
9
|
* A library for creating AI agents to interact with a {@link SharedTree | https://fluidframework.com/docs/data-structures/tree/}.
|
|
10
10
|
*
|
|
@@ -18,4 +18,8 @@ Object.defineProperty(exports, "llmDefault", { enumerable: true, get: function (
|
|
|
18
18
|
var methodBinding_js_1 = require("./methodBinding.js");
|
|
19
19
|
Object.defineProperty(exports, "buildFunc", { enumerable: true, get: function () { return methodBinding_js_1.buildFunc; } });
|
|
20
20
|
Object.defineProperty(exports, "exposeMethodsSymbol", { enumerable: true, get: function () { return methodBinding_js_1.exposeMethodsSymbol; } });
|
|
21
|
+
var treeAgentTypes_js_1 = require("./treeAgentTypes.js");
|
|
22
|
+
Object.defineProperty(exports, "typeFactory", { enumerable: true, get: function () { return treeAgentTypes_js_1.typeFactory; } });
|
|
23
|
+
Object.defineProperty(exports, "isTypeFactoryType", { enumerable: true, get: function () { return treeAgentTypes_js_1.isTypeFactoryType; } });
|
|
24
|
+
Object.defineProperty(exports, "instanceOfsTypeFactory", { enumerable: true, get: function () { return treeAgentTypes_js_1.instanceOfsTypeFactory; } });
|
|
21
25
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;AAEH,uCAGoB;AAFnB,mHAAA,uBAAuB,OAAA;AACvB,yGAAA,aAAa,OAAA;AAcd,uCAAwC;AAA/B,sGAAA,UAAU,OAAA;AACnB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;AAEH,uCAGoB;AAFnB,mHAAA,uBAAuB,OAAA;AACvB,yGAAA,aAAa,OAAA;AAcd,uCAAwC;AAA/B,sGAAA,UAAU,OAAA;AACnB,uDAe4B;AAd3B,6GAAA,SAAS,OAAA;AACT,uHAAA,mBAAmB,OAAA;AA0BpB,yDAI6B;AAH5B,gHAAA,WAAW,OAAA;AACX,sHAAA,iBAAiB,OAAA;AACjB,2HAAA,sBAAsB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A library for creating AI agents to interact with a {@link SharedTree | https://fluidframework.com/docs/data-structures/tree/}.\n *\n * @packageDocumentation\n */\n\nexport {\n\tSharedTreeSemanticAgent,\n\tcreateContext,\n} from \"./agent.js\";\nexport type {\n\tEditResult,\n\tSharedTreeChatModel,\n\tSharedTreeChatQuery,\n\tLogger,\n\tSemanticAgentOptions,\n\tSynchronousEditor,\n\tAsynchronousEditor,\n\tTreeView,\n\tViewOrTree,\n\tContext,\n} from \"./api.js\";\nexport { llmDefault } from \"./utils.js\";\nexport {\n\tbuildFunc,\n\texposeMethodsSymbol,\n\ttype ArgsTuple,\n\ttype ExposedMethods,\n\ttype Arg,\n\ttype FunctionDef,\n\ttype MethodKeys,\n\ttype BindableSchema,\n\ttype Ctor,\n\ttype Infer,\n\ttype InferZod,\n\ttype InferArgsZod,\n\ttype InferTypeFactory,\n\ttype IExposedMethods,\n} from \"./methodBinding.js\";\nexport type {\n\texposePropertiesSymbol,\n\tPropertyDef,\n\tExposedProperties,\n\tIExposedProperties,\n\tExposableKeys,\n\tReadOnlyRequirement,\n\tReadonlyKeys,\n\tTypeMatchOrError,\n\tIfEquals,\n} from \"./propertyBinding.js\";\n\nexport {\n\ttypeFactory,\n\tisTypeFactoryType,\n\tinstanceOfsTypeFactory,\n} from \"./treeAgentTypes.js\";\n\nexport type {\n\tTypeFactoryType,\n\tTypeFactoryTypeKind,\n\tTypeFactoryString,\n\tTypeFactoryNumber,\n\tTypeFactoryBoolean,\n\tTypeFactoryDate,\n\tTypeFactoryVoid,\n\tTypeFactoryUndefined,\n\tTypeFactoryNull,\n\tTypeFactoryUnknown,\n\tTypeFactoryArray,\n\tTypeFactoryPromise,\n\tTypeFactoryObject,\n\tTypeFactoryRecord,\n\tTypeFactoryMap,\n\tTypeFactoryTuple,\n\tTypeFactoryUnion,\n\tTypeFactoryIntersection,\n\tTypeFactoryLiteral,\n\tTypeFactoryOptional,\n\tTypeFactoryReadonly,\n\tTypeFactoryFunction,\n\tTypeFactoryFunctionParameter,\n\tTypeFactoryInstanceOf,\n} from \"./treeAgentTypes.js\";\n"]}
|
package/dist/methodBinding.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { TreeNodeSchema, TreeNodeSchemaClass } from "@fluidframework/tree";
|
|
6
6
|
import { NodeKind } from "@fluidframework/tree";
|
|
7
7
|
import type { z } from "zod";
|
|
8
|
+
import type { TypeFactoryType } from "./treeAgentTypes.js";
|
|
8
9
|
/**
|
|
9
10
|
* A utility type that extracts the method keys from a given type.
|
|
10
11
|
* @alpha
|
|
@@ -39,27 +40,39 @@ export declare function getExposedMethods(schemaClass: BindableSchema): {
|
|
|
39
40
|
* A type that represents a function argument.
|
|
40
41
|
* @alpha
|
|
41
42
|
*/
|
|
42
|
-
export type Arg<T extends z.ZodTypeAny = z.ZodTypeAny> = readonly [name: string, type: T];
|
|
43
|
+
export type Arg<T extends z.ZodTypeAny | TypeFactoryType = z.ZodTypeAny | TypeFactoryType> = readonly [name: string, type: T];
|
|
43
44
|
/**
|
|
44
45
|
* A function definition interface that describes the structure of a function.
|
|
45
46
|
* @alpha
|
|
46
47
|
*/
|
|
47
|
-
export interface FunctionDef<Args extends readonly Arg[], Return extends z.ZodTypeAny, Rest extends z.ZodTypeAny | null = null> {
|
|
48
|
+
export interface FunctionDef<Args extends readonly Arg[], Return extends z.ZodTypeAny | TypeFactoryType, Rest extends z.ZodTypeAny | TypeFactoryType | null = null> {
|
|
49
|
+
/**
|
|
50
|
+
* Optional description of the function.
|
|
51
|
+
*/
|
|
48
52
|
description?: string;
|
|
53
|
+
/**
|
|
54
|
+
* The function's parameters.
|
|
55
|
+
*/
|
|
49
56
|
args: Args;
|
|
57
|
+
/**
|
|
58
|
+
* Optional rest parameter type.
|
|
59
|
+
*/
|
|
50
60
|
rest?: Rest;
|
|
61
|
+
/**
|
|
62
|
+
* The function's return type.
|
|
63
|
+
*/
|
|
51
64
|
returns: Return;
|
|
52
65
|
}
|
|
53
66
|
/**
|
|
54
67
|
* A class that implements the FunctionDef interface.
|
|
55
68
|
*/
|
|
56
|
-
export declare class FunctionWrapper implements FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null> {
|
|
69
|
+
export declare class FunctionWrapper implements FunctionDef<readonly Arg[], z.ZodTypeAny | TypeFactoryType, z.ZodTypeAny | TypeFactoryType | null> {
|
|
57
70
|
readonly name: string;
|
|
58
71
|
readonly description: string | undefined;
|
|
59
72
|
readonly args: readonly Arg[];
|
|
60
|
-
readonly rest: z.ZodTypeAny | null;
|
|
61
|
-
readonly returns: z.ZodTypeAny;
|
|
62
|
-
constructor(name: string, description: string | undefined, args: readonly Arg[], rest: z.ZodTypeAny | null, returns: z.ZodTypeAny);
|
|
73
|
+
readonly rest: z.ZodTypeAny | TypeFactoryType | null;
|
|
74
|
+
readonly returns: z.ZodTypeAny | TypeFactoryType;
|
|
75
|
+
constructor(name: string, description: string | undefined, args: readonly Arg[], rest: z.ZodTypeAny | TypeFactoryType | null, returns: z.ZodTypeAny | TypeFactoryType);
|
|
63
76
|
}
|
|
64
77
|
/**
|
|
65
78
|
* A utility type that extracts the argument types from a function definition.
|
|
@@ -70,26 +83,54 @@ export type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Sing
|
|
|
70
83
|
* A utility function to build a function definition.
|
|
71
84
|
* @alpha
|
|
72
85
|
*/
|
|
73
|
-
export declare function buildFunc<const Return extends z.ZodTypeAny, const Args extends readonly Arg[], const Rest extends z.ZodTypeAny | null = null>(def: {
|
|
86
|
+
export declare function buildFunc<const Return extends z.ZodTypeAny | TypeFactoryType, const Args extends readonly Arg[], const Rest extends z.ZodTypeAny | TypeFactoryType | null = null>(def: {
|
|
74
87
|
description?: string;
|
|
75
88
|
returns: Return;
|
|
76
89
|
rest?: Rest;
|
|
77
90
|
}, ...args: Args): FunctionDef<Args, Return, Rest>;
|
|
91
|
+
/**
|
|
92
|
+
* A utility type that extracts inferred parameter types from Zod args.
|
|
93
|
+
* @alpha
|
|
94
|
+
*/
|
|
95
|
+
export type InferArgsZod<Args extends readonly Arg<z.ZodTypeAny>[]> = Args extends readonly [
|
|
96
|
+
infer Head extends Arg<z.ZodTypeAny>,
|
|
97
|
+
...infer Tail extends readonly Arg<z.ZodTypeAny>[]
|
|
98
|
+
] ? [z.infer<Head[1]>, ...InferArgsZod<Tail>] : [];
|
|
99
|
+
/**
|
|
100
|
+
* A utility type that infers the function signature from a Zod function definition with strict type checking.
|
|
101
|
+
* @alpha
|
|
102
|
+
*/
|
|
103
|
+
export type InferZod<T> = T extends FunctionDef<infer Args extends readonly Arg<z.ZodTypeAny>[], infer Return extends z.ZodTypeAny, any> ? (...args: InferArgsZod<Args>) => z.infer<Return> : never;
|
|
104
|
+
/**
|
|
105
|
+
* A utility type that infers the function signature from a type factory function definition with relaxed type checking.
|
|
106
|
+
* @alpha
|
|
107
|
+
*/
|
|
108
|
+
export type InferTypeFactory<T> = T extends FunctionDef<readonly Arg[], infer Return, any> ? (...args: any[]) => any : never;
|
|
78
109
|
/**
|
|
79
110
|
* A utility type that infers the return type of a function definition.
|
|
80
111
|
* @alpha
|
|
112
|
+
* @remarks
|
|
113
|
+
* For Zod types, provides strict compile-time type checking. For type factory types, returns `any`.
|
|
114
|
+
* @deprecated Use InferZod or InferTypeFactory directly for better type safety.
|
|
81
115
|
*/
|
|
82
|
-
export type Infer<T> = T extends FunctionDef<
|
|
116
|
+
export type Infer<T> = T extends FunctionDef<readonly Arg[], infer Return, any> ? Return extends z.ZodTypeAny ? InferZod<T> : InferTypeFactory<T> : never;
|
|
83
117
|
/**
|
|
84
118
|
* An interface for exposing methods of schema classes to an agent.
|
|
85
119
|
* @alpha
|
|
86
120
|
*/
|
|
87
121
|
export interface ExposedMethods {
|
|
88
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Expose a method with Zod types (strict compile-time type checking).
|
|
124
|
+
*/
|
|
125
|
+
expose<const K extends string & keyof MethodKeys<InstanceType<S>>, S extends BindableSchema & Ctor<Record<K, InferZod<Z>>> & IExposedMethods, Z extends FunctionDef<readonly Arg<z.ZodTypeAny>[], z.ZodTypeAny, z.ZodTypeAny | null>>(schema: S, methodName: K, zodFunction: Z): void;
|
|
126
|
+
/**
|
|
127
|
+
* Expose a method with type factory types (relaxed compile-time type checking).
|
|
128
|
+
*/
|
|
129
|
+
expose<const K extends string & keyof MethodKeys<InstanceType<S>>, S extends BindableSchema & Ctor & IExposedMethods, Z extends FunctionDef<readonly Arg<TypeFactoryType>[], TypeFactoryType, TypeFactoryType | null>>(schema: S, methodName: K, tfFunction: Z): void;
|
|
89
130
|
/**
|
|
90
131
|
* Create a Zod schema for a SharedTree schema class.
|
|
91
132
|
* @remarks
|
|
92
|
-
* Use it to "wrap" schema types that are referenced as arguments or return types when exposing methods
|
|
133
|
+
* Use it to "wrap" schema types that are referenced as arguments or return types when exposing methods with {@link ExposedMethods}.
|
|
93
134
|
*/
|
|
94
135
|
instanceOf<T extends TreeNodeSchemaClass>(schema: T): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>>;
|
|
95
136
|
}
|
|
@@ -113,6 +154,9 @@ export declare const exposeMethodsSymbol: unique symbol;
|
|
|
113
154
|
* @alpha
|
|
114
155
|
*/
|
|
115
156
|
export interface IExposedMethods {
|
|
157
|
+
/**
|
|
158
|
+
* Static method that exposes methods of this schema class to an agent.
|
|
159
|
+
*/
|
|
116
160
|
[exposeMethodsSymbol](methods: ExposedMethods): void;
|
|
117
161
|
}
|
|
118
162
|
//# sourceMappingURL=methodBinding.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"methodBinding.d.ts","sourceRoot":"","sources":["../src/methodBinding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"methodBinding.d.ts","sourceRoot":"","sources":["../src/methodBinding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK;CAChE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,IAAI,CAAC,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