@fluidframework/tree-agent 2.74.0 → 2.81.0-374083
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 +4 -0
- package/api-report/tree-agent.alpha.api.md +163 -20
- package/dist/alpha.d.ts +26 -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 +17 -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 +222 -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 +345 -0
- package/dist/treeAgentTypes.d.ts.map +1 -0
- package/dist/treeAgentTypes.js +190 -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 +26 -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 +17 -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 +217 -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 +345 -0
- package/lib/treeAgentTypes.d.ts.map +1 -0
- package/lib/treeAgentTypes.js +186 -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 +17 -17
- package/src/index.ts +31 -0
- package/src/methodBinding.ts +94 -15
- package/src/propertyBinding.ts +66 -9
- package/src/renderSchemaTypeScript.ts +25 -9
- package/src/renderTypeFactoryTypeScript.ts +259 -0
- package/src/subtree.ts +6 -5
- package/src/treeAgentTypes.ts +490 -0
- package/src/utils.ts +2 -9
- package/.eslintrc.cjs +0 -48
package/CHANGELOG.md
CHANGED
|
@@ -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
|
+
|
|
115
|
+
// @alpha
|
|
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
|
+
|
|
105
121
|
// @alpha
|
|
106
|
-
export
|
|
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,133 @@ 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
|
+
void(): TypeFactoryVoid;
|
|
208
|
+
undefined(): TypeFactoryUndefined;
|
|
209
|
+
null(): TypeFactoryNull;
|
|
210
|
+
unknown(): TypeFactoryUnknown;
|
|
211
|
+
array(element: TypeFactoryType): TypeFactoryArray;
|
|
212
|
+
object(shape: Record<string, TypeFactoryType>): TypeFactoryObject;
|
|
213
|
+
record(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryRecord;
|
|
214
|
+
map(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryMap;
|
|
215
|
+
tuple(items: readonly TypeFactoryType[], rest?: TypeFactoryType): TypeFactoryTuple;
|
|
216
|
+
union(options: readonly TypeFactoryType[]): TypeFactoryUnion;
|
|
217
|
+
literal(value: string | number | boolean): TypeFactoryLiteral;
|
|
218
|
+
optional(innerType: TypeFactoryType): TypeFactoryOptional;
|
|
219
|
+
readonly(innerType: TypeFactoryType): TypeFactoryReadonly;
|
|
220
|
+
instanceOf<T extends TreeNodeSchemaClass_2>(schema: T): TypeFactoryInstanceOf;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// @alpha
|
|
224
|
+
export interface TypeFactoryArray extends TypeFactoryType {
|
|
225
|
+
readonly element: TypeFactoryType;
|
|
226
|
+
readonly _kind: "array";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// @alpha
|
|
230
|
+
export interface TypeFactoryBoolean extends TypeFactoryType {
|
|
231
|
+
readonly _kind: "boolean";
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// @alpha
|
|
235
|
+
export interface TypeFactoryInstanceOf extends TypeFactoryType {
|
|
236
|
+
readonly _kind: "instanceof";
|
|
237
|
+
readonly schema: ObjectNodeSchema;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// @alpha
|
|
241
|
+
export interface TypeFactoryLiteral extends TypeFactoryType {
|
|
242
|
+
readonly _kind: "literal";
|
|
243
|
+
readonly value: string | number | boolean;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// @alpha
|
|
247
|
+
export interface TypeFactoryMap extends TypeFactoryType {
|
|
248
|
+
readonly keyType: TypeFactoryType;
|
|
249
|
+
readonly _kind: "map";
|
|
250
|
+
readonly valueType: TypeFactoryType;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// @alpha
|
|
254
|
+
export interface TypeFactoryNull extends TypeFactoryType {
|
|
255
|
+
readonly _kind: "null";
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// @alpha
|
|
259
|
+
export interface TypeFactoryNumber extends TypeFactoryType {
|
|
260
|
+
readonly _kind: "number";
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// @alpha
|
|
264
|
+
export interface TypeFactoryObject extends TypeFactoryType {
|
|
265
|
+
readonly _kind: "object";
|
|
266
|
+
readonly shape: Record<string, TypeFactoryType>;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// @alpha
|
|
270
|
+
export interface TypeFactoryOptional extends TypeFactoryType {
|
|
271
|
+
readonly innerType: TypeFactoryType;
|
|
272
|
+
readonly _kind: "optional";
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// @alpha
|
|
276
|
+
export interface TypeFactoryReadonly extends TypeFactoryType {
|
|
277
|
+
readonly innerType: TypeFactoryType;
|
|
278
|
+
readonly _kind: "readonly";
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// @alpha
|
|
282
|
+
export interface TypeFactoryRecord extends TypeFactoryType {
|
|
283
|
+
readonly keyType: TypeFactoryType;
|
|
284
|
+
readonly _kind: "record";
|
|
285
|
+
readonly valueType: TypeFactoryType;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// @alpha
|
|
289
|
+
export interface TypeFactoryString extends TypeFactoryType {
|
|
290
|
+
readonly _kind: "string";
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// @alpha
|
|
294
|
+
export interface TypeFactoryTuple extends TypeFactoryType {
|
|
295
|
+
readonly items: readonly TypeFactoryType[];
|
|
296
|
+
readonly _kind: "tuple";
|
|
297
|
+
readonly rest?: TypeFactoryType;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// @alpha
|
|
301
|
+
export interface TypeFactoryType {
|
|
302
|
+
readonly _kind: TypeFactoryTypeKind;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// @alpha
|
|
306
|
+
export type TypeFactoryTypeKind = "string" | "number" | "boolean" | "void" | "undefined" | "null" | "unknown" | "array" | "object" | "record" | "map" | "tuple" | "union" | "literal" | "optional" | "readonly" | "instanceof";
|
|
307
|
+
|
|
308
|
+
// @alpha
|
|
309
|
+
export interface TypeFactoryUndefined extends TypeFactoryType {
|
|
310
|
+
readonly _kind: "undefined";
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// @alpha
|
|
314
|
+
export interface TypeFactoryUnion extends TypeFactoryType {
|
|
315
|
+
readonly _kind: "union";
|
|
316
|
+
readonly options: readonly TypeFactoryType[];
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// @alpha
|
|
320
|
+
export interface TypeFactoryUnknown extends TypeFactoryType {
|
|
321
|
+
readonly _kind: "unknown";
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// @alpha
|
|
325
|
+
export interface TypeFactoryVoid extends TypeFactoryType {
|
|
326
|
+
readonly _kind: "void";
|
|
327
|
+
}
|
|
328
|
+
|
|
186
329
|
// @alpha
|
|
187
330
|
export type TypeMatchOrError<Expected, Received> = [Received] extends [Expected] ? unknown : {
|
|
188
331
|
__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,34 @@ export {
|
|
|
42
45
|
SharedTreeSemanticAgent,
|
|
43
46
|
SynchronousEditor,
|
|
44
47
|
TreeView,
|
|
48
|
+
TypeFactoryArray,
|
|
49
|
+
TypeFactoryBoolean,
|
|
50
|
+
TypeFactoryInstanceOf,
|
|
51
|
+
TypeFactoryLiteral,
|
|
52
|
+
TypeFactoryMap,
|
|
53
|
+
TypeFactoryNull,
|
|
54
|
+
TypeFactoryNumber,
|
|
55
|
+
TypeFactoryObject,
|
|
56
|
+
TypeFactoryOptional,
|
|
57
|
+
TypeFactoryReadonly,
|
|
58
|
+
TypeFactoryRecord,
|
|
59
|
+
TypeFactoryString,
|
|
60
|
+
TypeFactoryTuple,
|
|
61
|
+
TypeFactoryType,
|
|
62
|
+
TypeFactoryTypeKind,
|
|
63
|
+
TypeFactoryUndefined,
|
|
64
|
+
TypeFactoryUnion,
|
|
65
|
+
TypeFactoryUnknown,
|
|
66
|
+
TypeFactoryVoid,
|
|
45
67
|
TypeMatchOrError,
|
|
46
68
|
ViewOrTree,
|
|
47
69
|
buildFunc,
|
|
48
70
|
createContext,
|
|
49
71
|
exposeMethodsSymbol,
|
|
50
72
|
exposePropertiesSymbol,
|
|
51
|
-
|
|
73
|
+
instanceOfsTypeFactory,
|
|
74
|
+
isTypeFactoryType,
|
|
75
|
+
llmDefault,
|
|
76
|
+
typeFactory
|
|
52
77
|
// #endregion
|
|
53
78
|
} 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, TypeFactoryVoid, TypeFactoryUndefined, TypeFactoryNull, TypeFactoryUnknown, TypeFactoryArray, TypeFactoryObject, TypeFactoryRecord, TypeFactoryMap, TypeFactoryTuple, TypeFactoryUnion, TypeFactoryLiteral, TypeFactoryOptional, TypeFactoryReadonly, 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,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,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\tTypeFactoryVoid,\n\tTypeFactoryUndefined,\n\tTypeFactoryNull,\n\tTypeFactoryUnknown,\n\tTypeFactoryArray,\n\tTypeFactoryObject,\n\tTypeFactoryRecord,\n\tTypeFactoryMap,\n\tTypeFactoryTuple,\n\tTypeFactoryUnion,\n\tTypeFactoryLiteral,\n\tTypeFactoryOptional,\n\tTypeFactoryReadonly,\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
|
//# s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ACxB,WAAW,CAAC,OAAO,CACnB,CAAC;IACH,CAAC;IAEM,UAAU,CAChB,MAAS;QAET,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,IAAA,mCAAU,EAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAEM,MAAM,CAAC,iBAAiB,CAAC,WAA2B;QAI1D,MAAM,cAAc,GAAG,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC;QACxD,MAAM,WAAW,GAAG,WAAyC,CAAC;QAC9D,IAAI,WAAW,CAAC,2BAAmB,CAAC,KAAK,SAAS,EAAE,CAAC;YACpD,WAAW,CAAC,2BAAmB,CAAC,CAAC,cAAc,CAAC,CAAC;QAClD,CAAC;QACD,OAAO;YACN,OAAO,EAAE,cAAc,CAAC,OAAO;YAC/B,eAAe,EAAE,cAAc,CAAC,eAAe;SAC/C,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { TreeNodeSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport { NodeKind } from \"@fluidframework/tree\";\nimport type { z } from \"zod\";\nimport { instanceOf } from \"./renderZodTypeScript.js\";\n\n/**\n * A utility type that extracts the method keys from a given type.\n * @alpha\n */\nexport type MethodKeys<T> = {\n\t[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;\n};\n\n/**\n * A type that represents a constructor function.\n * @alpha\n */\nexport type Ctor<T = any> = new (...args: any[]) => T;\n\n/**\n * A type that represents an object schema class.\n * @alpha\n */\nexport type BindableSchema =\n\t| TreeNodeSchema<string, NodeKind.Object>\n\t| TreeNodeSchema<string, NodeKind.Record>\n\t| TreeNodeSchema<string, NodeKind.Array>\n\t| TreeNodeSchema<string, NodeKind.Map>;\n\n/**\n * A type guard to check if a schema is {@link BindableSchema | bindable}.\n */\nexport function isBindableSchema(schema: TreeNodeSchema): schema is BindableSchema {\n\treturn (\n\t\tschema.kind === NodeKind.Object ||\n\t\tschema.kind === NodeKind.Record ||\n\t\tschema.kind === NodeKind.Array ||\n\t\tschema.kind === NodeKind.Map\n\t);\n}\n\n/**\n * Get the exposed methods of a schema class.\n * @param schemaClass - The schema class to extract methods from.\n * @returns A record of method names and their corresponding Zod types.\n */\nexport function getExposedMethods(schemaClass: BindableSchema): {\n\tmethods: Record<string, FunctionWrapper>;\n\treferencedTypes: Set<TreeNodeSchema>;\n} {\n\treturn ExposedMethodsI.getExposedMethods(schemaClass);\n}\n\n/**\n * A type that represents a function argument.\n * @alpha\n */\nexport type Arg<T extends z.ZodTypeAny = z.ZodTypeAny> = readonly [name: string, type: T];\n\n/**\n * A function definition interface that describes the structure of a function.\n * @alpha\n */\nexport interface FunctionDef<\n\tArgs extends readonly Arg[],\n\tReturn extends z.ZodTypeAny,\n\tRest extends z.ZodTypeAny | null = null,\n> {\n\tdescription?: string;\n\targs: Args;\n\trest?: Rest;\n\treturns: Return;\n}\n\n/**\n * A class that implements the FunctionDef interface.\n */\nexport class FunctionWrapper\n\timplements FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>\n{\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly description: string | undefined,\n\t\tpublic readonly args: readonly Arg[],\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic readonly rest: z.ZodTypeAny | null,\n\t\tpublic readonly returns: z.ZodTypeAny,\n\t) {}\n}\n\n/**\n * A utility type that extracts the argument types from a function definition.\n * @alpha\n */\nexport type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Single extends Arg]\n\t? [Single[1]]\n\t: T extends readonly [infer Head extends Arg, ...infer Tail extends readonly Arg[]]\n\t\t? [Head[1], ...ArgsTuple<Tail>]\n\t\t: never;\n\n/**\n * A utility function to build a function definition.\n * @alpha\n */\nexport function buildFunc<\n\tconst Return extends z.ZodTypeAny,\n\tconst Args extends readonly Arg[],\n\tconst Rest extends z.ZodTypeAny | null = null,\n>(\n\tdef: { description?: string; returns: Return; rest?: Rest },\n\t...args: Args\n): FunctionDef<Args, Return, Rest> {\n\treturn {\n\t\tdescription: def.description,\n\t\treturns: def.returns,\n\t\targs,\n\t\trest: def.rest,\n\t};\n}\n\n/**\n * A utility type that infers the return type of a function definition.\n * @alpha\n */\nexport type Infer<T> = T extends FunctionDef<infer Args, infer Return, infer Rest>\n\t? z.infer<z.ZodFunction<z.ZodTuple<ArgsTuple<Args>, Rest>, Return>>\n\t: never;\n\n/**\n * An interface for exposing methods of schema classes to an agent.\n * @alpha\n */\nexport interface ExposedMethods {\n\texpose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods,\n\t\tZ extends FunctionDef<any, any, any>,\n\t>(schema: S, methodName: K, zodFunction: Z): void;\n\n\t/**\n\t * Create a Zod schema for a SharedTree schema class.\n\t * @remarks\n\t * Use it to \"wrap\" schema types that are referenced as arguments or return types when exposing methods (with {@link ExposedMethods.expose}).\n\t */\n\tinstanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>>;\n}\n\n/**\n * A symbol used to expose methods to the LLM.\n * @alpha\n */\nexport const exposeMethodsSymbol: unique symbol = Symbol(\"run\");\n\n/**\n * An interface that SharedTree schema classes should implement to expose their methods to the LLM.\n *\n * @remarks\n * The `getExposedMethods` free function will cause the method here to be called on the class passed to it.\n *\n * @privateremarks\n * Implementing this interface correctly seems tricky?\n * To actually implement it in a way that satisfies TypeScript,\n * classes need to declare both a static version and an instance version of the method\n * (the instance one can just delegate to the static one).\n *\n * @alpha\n */\nexport interface IExposedMethods {\n\t[exposeMethodsSymbol](methods: ExposedMethods): void;\n}\n\nclass ExposedMethodsI implements ExposedMethods {\n\tprivate readonly methods: Record<string, FunctionWrapper> = {};\n\tprivate readonly referencedTypes = new Set<TreeNodeSchema>();\n\n\tpublic constructor(private readonly schemaClass: BindableSchema) {}\n\n\tpublic expose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods,\n\t\tZ extends FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>,\n\t>(schema: S, methodName: K, functionDef: Z): void {\n\t\tif (schema !== this.schemaClass) {\n\t\t\tthrow new Error('Must expose methods on the \"this\" object');\n\t\t}\n\t\tthis.methods[methodName] = new FunctionWrapper(\n\t\t\tmethodName,\n\t\t\tfunctionDef.description,\n\t\t\tfunctionDef.args,\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tfunctionDef.rest ?? null,\n\t\t\tfunctionDef.returns,\n\t\t);\n\t}\n\n\tpublic instanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>> {\n\t\tthis.referencedTypes.add(schema);\n\t\treturn instanceOf(schema);\n\t}\n\n\tpublic static getExposedMethods(schemaClass: BindableSchema): {\n\t\tmethods: Record<string, FunctionWrapper>;\n\t\treferencedTypes: Set<TreeNodeSchema>;\n\t} {\n\t\tconst exposedMethods = new ExposedMethodsI(schemaClass);\n\t\tconst extractable = schemaClass as unknown as IExposedMethods;\n\t\tif (extractable[exposeMethodsSymbol] !== undefined) {\n\t\t\textractable[exposeMethodsSymbol](exposedMethods);\n\t\t}\n\t\treturn {\n\t\t\tmethods: exposedMethods.methods,\n\t\t\treferencedTypes: exposedMethods.referencedTypes,\n\t\t};\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"methodBinding.js","sourceRoot":"","sources":["../src/methodBinding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,+CAAgD;AAGhD,qEAAsD;AA2BtD;;GAEG;AACH,SAAgB,gBAAgB,CAAC,MAAsB;IACtD,OAAO,CACN,MAA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AC,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,eAAe,CAC7C,UAAU,EACV,WAAW,CAAC,WAAW,EACvB,WAAW,CAAC,IAAI;QAChB,2CAA2C;QAC3C,WAAW,CAAC,IAAI,IAAI,IAAI,EACxB,WAAW,CAAC,OAAO,CACnB,CAAC;IACH,CAAC;IAEM,UAAU,CAChB,MAAS;QAET,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,IAAA,mCAAU,EAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAEM,MAAM,CAAC,iBAAiB,CAAC,WAA2B;QAI1D,MAAM,cAAc,GAAG,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC;QACxD,MAAM,WAAW,GAAG,WAAyC,CAAC;QAC9D,IAAI,WAAW,CAAC,2BAAmB,CAAC,KAAK,SAAS,EAAE,CAAC;YACpD,WAAW,CAAC,2BAAmB,CAAC,CAAC,cAAc,CAAC,CAAC;QAClD,CAAC;QACD,OAAO;YACN,OAAO,EAAE,cAAc,CAAC,OAAO;YAC/B,eAAe,EAAE,cAAc,CAAC,eAAe;SAC/C,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { TreeNodeSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport { NodeKind } from \"@fluidframework/tree\";\nimport type { z } from \"zod\";\n\nimport { instanceOf } from \"./renderZodTypeScript.js\";\nimport type { TypeFactoryType } from \"./treeAgentTypes.js\";\n\n/**\n * A utility type that extracts the method keys from a given type.\n * @alpha\n */\nexport type MethodKeys<T> = {\n\t[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;\n};\n\n/**\n * A type that represents a constructor function.\n * @alpha\n */\nexport type Ctor<T = any> = new (...args: any[]) => T;\n\n/**\n * A type that represents an object schema class.\n * @alpha\n */\nexport type BindableSchema =\n\t| TreeNodeSchema<string, NodeKind.Object>\n\t| TreeNodeSchema<string, NodeKind.Record>\n\t| TreeNodeSchema<string, NodeKind.Array>\n\t| TreeNodeSchema<string, NodeKind.Map>;\n\n/**\n * A type guard to check if a schema is {@link BindableSchema | bindable}.\n */\nexport function isBindableSchema(schema: TreeNodeSchema): schema is BindableSchema {\n\treturn (\n\t\tschema.kind === NodeKind.Object ||\n\t\tschema.kind === NodeKind.Record ||\n\t\tschema.kind === NodeKind.Array ||\n\t\tschema.kind === NodeKind.Map\n\t);\n}\n\n/**\n * Get the exposed methods of a schema class.\n * @param schemaClass - The schema class to extract methods from.\n * @returns A record of method names and their corresponding Zod types.\n */\nexport function getExposedMethods(schemaClass: BindableSchema): {\n\tmethods: Record<string, FunctionWrapper>;\n\treferencedTypes: Set<TreeNodeSchema>;\n} {\n\treturn ExposedMethodsI.getExposedMethods(schemaClass);\n}\n\n/**\n * A type that represents a function argument.\n * @alpha\n */\nexport type Arg<T extends z.ZodTypeAny | TypeFactoryType = z.ZodTypeAny | TypeFactoryType> =\n\treadonly [name: string, type: T];\n\n/**\n * A function definition interface that describes the structure of a function.\n * @alpha\n */\nexport interface FunctionDef<\n\tArgs extends readonly Arg[],\n\tReturn extends z.ZodTypeAny | TypeFactoryType,\n\tRest extends z.ZodTypeAny | TypeFactoryType | null = null,\n> {\n\t/**\n\t * Optional description of the function.\n\t */\n\tdescription?: string;\n\t/**\n\t * The function's parameters.\n\t */\n\targs: Args;\n\t/**\n\t * Optional rest parameter type.\n\t */\n\trest?: Rest;\n\t/**\n\t * The function's return type.\n\t */\n\treturns: Return;\n}\n\n/**\n * A class that implements the FunctionDef interface.\n */\nexport class FunctionWrapper\n\timplements\n\t\tFunctionDef<\n\t\t\treadonly Arg[],\n\t\t\tz.ZodTypeAny | TypeFactoryType,\n\t\t\tz.ZodTypeAny | TypeFactoryType | null\n\t\t>\n{\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly description: string | undefined,\n\t\tpublic readonly args: readonly Arg[],\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic readonly rest: z.ZodTypeAny | TypeFactoryType | null,\n\t\tpublic readonly returns: z.ZodTypeAny | TypeFactoryType,\n\t) {}\n}\n\n/**\n * A utility type that extracts the argument types from a function definition.\n * @alpha\n */\nexport type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Single extends Arg]\n\t? [Single[1]]\n\t: T extends readonly [infer Head extends Arg, ...infer Tail extends readonly Arg[]]\n\t\t? [Head[1], ...ArgsTuple<Tail>]\n\t\t: never;\n\n/**\n * A utility function to build a function definition.\n * @alpha\n */\nexport function buildFunc<\n\tconst Return extends z.ZodTypeAny | TypeFactoryType,\n\tconst Args extends readonly Arg[],\n\tconst Rest extends z.ZodTypeAny | TypeFactoryType | null = null,\n>(\n\tdef: { description?: string; returns: Return; rest?: Rest },\n\t...args: Args\n): FunctionDef<Args, Return, Rest> {\n\treturn {\n\t\tdescription: def.description,\n\t\treturns: def.returns,\n\t\targs,\n\t\trest: def.rest,\n\t};\n}\n\n/**\n * A utility type that extracts inferred parameter types from Zod args.\n * @alpha\n */\nexport type InferArgsZod<Args extends readonly Arg<z.ZodTypeAny>[]> = Args extends readonly [\n\tinfer Head extends Arg<z.ZodTypeAny>,\n\t...infer Tail extends readonly Arg<z.ZodTypeAny>[],\n]\n\t? [z.infer<Head[1]>, ...InferArgsZod<Tail>]\n\t: [];\n\n/**\n * A utility type that infers the function signature from a Zod function definition with strict type checking.\n * @alpha\n */\nexport type InferZod<T> = T extends FunctionDef<\n\tinfer Args extends readonly Arg<z.ZodTypeAny>[],\n\tinfer Return extends z.ZodTypeAny,\n\tany\n>\n\t? (...args: InferArgsZod<Args>) => z.infer<Return>\n\t: never;\n\n/**\n * A utility type that infers the function signature from a type factory function definition with relaxed type checking.\n * @alpha\n */\nexport type InferTypeFactory<T> = T extends FunctionDef<readonly Arg[], infer Return, any>\n\t? (...args: any[]) => any\n\t: never;\n\n/**\n * A utility type that infers the return type of a function definition.\n * @alpha\n * @remarks\n * For Zod types, provides strict compile-time type checking. For type factory types, returns `any`.\n * @deprecated Use InferZod or InferTypeFactory directly for better type safety.\n */\nexport type Infer<T> = T extends FunctionDef<readonly Arg[], infer Return, any>\n\t? Return extends z.ZodTypeAny\n\t\t? InferZod<T>\n\t\t: InferTypeFactory<T>\n\t: never;\n\n/**\n * An interface for exposing methods of schema classes to an agent.\n * @alpha\n */\nexport interface ExposedMethods {\n\t/**\n\t * Expose a method with Zod types (strict compile-time type checking).\n\t */\n\texpose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor<Record<K, InferZod<Z>>> & IExposedMethods,\n\t\tZ extends FunctionDef<readonly Arg<z.ZodTypeAny>[], z.ZodTypeAny, z.ZodTypeAny | null>,\n\t>(schema: S, methodName: K, zodFunction: Z): void;\n\n\t/**\n\t * Expose a method with type factory types (relaxed compile-time type checking).\n\t */\n\texpose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor & IExposedMethods,\n\t\tZ extends FunctionDef<\n\t\t\treadonly Arg<TypeFactoryType>[],\n\t\t\tTypeFactoryType,\n\t\t\tTypeFactoryType | null\n\t\t>,\n\t>(schema: S, methodName: K, tfFunction: Z): void;\n\n\t/**\n\t * Create a Zod schema for a SharedTree schema class.\n\t * @remarks\n\t * Use it to \"wrap\" schema types that are referenced as arguments or return types when exposing methods with {@link ExposedMethods}.\n\t */\n\tinstanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>>;\n}\n\n/**\n * A symbol used to expose methods to the LLM.\n * @alpha\n */\nexport const exposeMethodsSymbol: unique symbol = Symbol(\"run\");\n\n/**\n * An interface that SharedTree schema classes should implement to expose their methods to the LLM.\n *\n * @remarks\n * The `getExposedMethods` free function will cause the method here to be called on the class passed to it.\n *\n * @privateremarks\n * Implementing this interface correctly seems tricky?\n * To actually implement it in a way that satisfies TypeScript,\n * classes need to declare both a static version and an instance version of the method\n * (the instance one can just delegate to the static one).\n *\n * @alpha\n */\nexport interface IExposedMethods {\n\t/**\n\t * Static method that exposes methods of this schema class to an agent.\n\t */\n\t[exposeMethodsSymbol](methods: ExposedMethods): void;\n}\n\nclass ExposedMethodsI implements ExposedMethods {\n\tprivate readonly methods: Record<string, FunctionWrapper> = {};\n\tprivate readonly referencedTypes = new Set<TreeNodeSchema>();\n\n\tpublic constructor(private readonly schemaClass: BindableSchema) {}\n\n\tpublic expose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor & IExposedMethods,\n\t\tZ extends FunctionDef<\n\t\t\treadonly Arg[],\n\t\t\tz.ZodTypeAny | TypeFactoryType,\n\t\t\tz.ZodTypeAny | TypeFactoryType | null\n\t\t>,\n\t>(schema: S, methodName: K, functionDef: Z): void {\n\t\tif (schema !== this.schemaClass) {\n\t\t\tthrow new Error('Must expose methods on the \"this\" object');\n\t\t}\n\t\tthis.methods[methodName] = new FunctionWrapper(\n\t\t\tmethodName,\n\t\t\tfunctionDef.description,\n\t\t\tfunctionDef.args,\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tfunctionDef.rest ?? null,\n\t\t\tfunctionDef.returns,\n\t\t);\n\t}\n\n\tpublic instanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>> {\n\t\tthis.referencedTypes.add(schema);\n\t\treturn instanceOf(schema);\n\t}\n\n\tpublic static getExposedMethods(schemaClass: BindableSchema): {\n\t\tmethods: Record<string, FunctionWrapper>;\n\t\treferencedTypes: Set<TreeNodeSchema>;\n\t} {\n\t\tconst exposedMethods = new ExposedMethodsI(schemaClass);\n\t\tconst extractable = schemaClass as unknown as IExposedMethods;\n\t\tif (extractable[exposeMethodsSymbol] !== undefined) {\n\t\t\textractable[exposeMethodsSymbol](exposedMethods);\n\t\t}\n\t\treturn {\n\t\t\tmethods: exposedMethods.methods,\n\t\t\treferencedTypes: exposedMethods.referencedTypes,\n\t\t};\n\t}\n}\n"]}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { TreeNodeSchema, TreeNodeSchemaClass } from "@fluidframework/tree";
|
|
6
6
|
import type { ZodType, ZodTypeAny, ZodTypeDef, infer as ZodInfer } from "zod";
|
|
7
7
|
import type { BindableSchema, Ctor } from "./methodBinding.js";
|
|
8
|
+
import type { TypeFactoryType } from "./treeAgentTypes.js";
|
|
8
9
|
/**
|
|
9
10
|
* A symbol used to expose properties to the LLM.
|
|
10
11
|
* @alpha
|
|
@@ -60,21 +61,67 @@ export type TypeMatchOrError<Expected, Received> = [Received] extends [Expected]
|
|
|
60
61
|
* @alpha
|
|
61
62
|
*/
|
|
62
63
|
export declare class PropertyDef {
|
|
64
|
+
/**
|
|
65
|
+
* The name of the property.
|
|
66
|
+
*/
|
|
63
67
|
readonly name: string;
|
|
68
|
+
/**
|
|
69
|
+
* Optional description of the property.
|
|
70
|
+
*/
|
|
64
71
|
readonly description: string | undefined;
|
|
65
|
-
|
|
72
|
+
/**
|
|
73
|
+
* The schema defining the property's type (either Zod or TypeFactory).
|
|
74
|
+
*/
|
|
75
|
+
readonly schema: ZodTypeAny | TypeFactoryType;
|
|
76
|
+
/**
|
|
77
|
+
* Whether the property is readonly.
|
|
78
|
+
*/
|
|
66
79
|
readonly readOnly: boolean;
|
|
67
|
-
constructor(
|
|
80
|
+
constructor(
|
|
81
|
+
/**
|
|
82
|
+
* The name of the property.
|
|
83
|
+
*/
|
|
84
|
+
name: string,
|
|
85
|
+
/**
|
|
86
|
+
* Optional description of the property.
|
|
87
|
+
*/
|
|
88
|
+
description: string | undefined,
|
|
89
|
+
/**
|
|
90
|
+
* The schema defining the property's type (either Zod or TypeFactory).
|
|
91
|
+
*/
|
|
92
|
+
schema: ZodTypeAny | TypeFactoryType,
|
|
93
|
+
/**
|
|
94
|
+
* Whether the property is readonly.
|
|
95
|
+
*/
|
|
96
|
+
readOnly: boolean);
|
|
68
97
|
}
|
|
69
98
|
/**
|
|
70
99
|
* An interface for exposing properties of schema classes to an agent.
|
|
71
100
|
* @alpha
|
|
72
101
|
*/
|
|
73
102
|
export interface ExposedProperties {
|
|
103
|
+
/**
|
|
104
|
+
* Expose a property with Zod type checking.
|
|
105
|
+
*/
|
|
74
106
|
exposeProperty<S extends BindableSchema & Ctor, K extends string & ExposableKeys<InstanceType<S>>, TZ extends ZodTypeAny>(schema: S, name: K, def: {
|
|
75
107
|
schema: TZ;
|
|
76
108
|
description?: string;
|
|
77
109
|
} & ReadOnlyRequirement<InstanceType<S>, K> & TypeMatchOrError<InstanceType<S>[K], ZodInfer<TZ>>): void;
|
|
110
|
+
/**
|
|
111
|
+
* Expose a property with type factory type and metadata.
|
|
112
|
+
*/
|
|
113
|
+
exposeProperty<S extends BindableSchema & Ctor, K extends string & ExposableKeys<InstanceType<S>>>(schema: S, name: K, def: {
|
|
114
|
+
schema: TypeFactoryType;
|
|
115
|
+
description?: string;
|
|
116
|
+
readOnly?: boolean;
|
|
117
|
+
}): void;
|
|
118
|
+
/**
|
|
119
|
+
* Expose a property with type factory type (simple form).
|
|
120
|
+
*/
|
|
121
|
+
exposeProperty<S extends BindableSchema & Ctor, K extends string & ExposableKeys<InstanceType<S>>>(schema: S, name: K, tfType: TypeFactoryType): void;
|
|
122
|
+
/**
|
|
123
|
+
* Create a Zod type that references a SharedTree schema class.
|
|
124
|
+
*/
|
|
78
125
|
instanceOf<T extends TreeNodeSchemaClass>(schema: T): ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>;
|
|
79
126
|
}
|
|
80
127
|
/**
|
|
@@ -92,6 +139,9 @@ export interface ExposedProperties {
|
|
|
92
139
|
* @alpha
|
|
93
140
|
*/
|
|
94
141
|
export interface IExposedProperties {
|
|
142
|
+
/**
|
|
143
|
+
* Static method that exposes properties of this schema class to an agent.
|
|
144
|
+
*/
|
|
95
145
|
[exposePropertiesSymbol]?(properties: ExposedProperties): void;
|
|
96
146
|
}
|
|
97
147
|
/**
|