@fluidframework/type-factory 2.93.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.
Files changed (64) hide show
  1. package/.mocharc.cjs +11 -0
  2. package/CHANGELOG.md +3 -0
  3. package/LICENSE +21 -0
  4. package/README.md +133 -0
  5. package/alpha.d.ts +11 -0
  6. package/api-extractor/api-extractor-lint-alpha.cjs.json +5 -0
  7. package/api-extractor/api-extractor-lint-alpha.esm.json +5 -0
  8. package/api-extractor/api-extractor-lint-bundle.json +5 -0
  9. package/api-extractor/api-extractor-lint-index.cjs.json +5 -0
  10. package/api-extractor/api-extractor-lint-index.esm.json +5 -0
  11. package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
  12. package/api-extractor/api-extractor-lint-public.esm.json +5 -0
  13. package/api-extractor.json +14 -0
  14. package/api-report/type-factory.alpha.api.md +208 -0
  15. package/api-report/type-factory.beta.api.md +7 -0
  16. package/api-report/type-factory.public.api.md +7 -0
  17. package/dist/alpha.d.ts +57 -0
  18. package/dist/index.d.ts +14 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +21 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/methodBinding.d.ts +101 -0
  23. package/dist/methodBinding.d.ts.map +1 -0
  24. package/dist/methodBinding.js +26 -0
  25. package/dist/methodBinding.js.map +1 -0
  26. package/dist/package.json +4 -0
  27. package/dist/propertyBinding.d.ts +50 -0
  28. package/dist/propertyBinding.d.ts.map +1 -0
  29. package/dist/propertyBinding.js +13 -0
  30. package/dist/propertyBinding.js.map +1 -0
  31. package/dist/public.d.ts +16 -0
  32. package/dist/treeAgentTypes.d.ts +428 -0
  33. package/dist/treeAgentTypes.d.ts.map +1 -0
  34. package/dist/treeAgentTypes.js +218 -0
  35. package/dist/treeAgentTypes.js.map +1 -0
  36. package/eslint.config.mts +43 -0
  37. package/internal.d.ts +11 -0
  38. package/lib/alpha.d.ts +57 -0
  39. package/lib/index.d.ts +14 -0
  40. package/lib/index.d.ts.map +1 -0
  41. package/lib/index.js +13 -0
  42. package/lib/index.js.map +1 -0
  43. package/lib/methodBinding.d.ts +101 -0
  44. package/lib/methodBinding.d.ts.map +1 -0
  45. package/lib/methodBinding.js +22 -0
  46. package/lib/methodBinding.js.map +1 -0
  47. package/lib/propertyBinding.d.ts +50 -0
  48. package/lib/propertyBinding.d.ts.map +1 -0
  49. package/lib/propertyBinding.js +10 -0
  50. package/lib/propertyBinding.js.map +1 -0
  51. package/lib/public.d.ts +16 -0
  52. package/lib/treeAgentTypes.d.ts +428 -0
  53. package/lib/treeAgentTypes.d.ts.map +1 -0
  54. package/lib/treeAgentTypes.js +214 -0
  55. package/lib/treeAgentTypes.js.map +1 -0
  56. package/lib/tsdoc-metadata.json +11 -0
  57. package/package.json +142 -0
  58. package/src/index.ts +57 -0
  59. package/src/methodBinding.ts +139 -0
  60. package/src/propertyBinding.ts +62 -0
  61. package/src/treeAgentTypes.ts +601 -0
  62. package/tsconfig.cjs.json +7 -0
  63. package/tsconfig.json +14 -0
  64. package/tsdoc.json +4 -0
package/package.json ADDED
@@ -0,0 +1,142 @@
1
+ {
2
+ "name": "@fluidframework/type-factory",
3
+ "version": "2.93.0",
4
+ "description": "Shared types for exposing schema methods and properties to an LLM agent",
5
+ "homepage": "https://fluidframework.com",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/microsoft/FluidFramework.git",
9
+ "directory": "packages/framework/type-factory"
10
+ },
11
+ "license": "MIT",
12
+ "author": "Microsoft and contributors",
13
+ "sideEffects": false,
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "import": {
18
+ "types": "./lib/public.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "require": {
22
+ "types": "./dist/public.d.ts",
23
+ "default": "./dist/index.js"
24
+ }
25
+ },
26
+ "./alpha": {
27
+ "import": {
28
+ "types": "./lib/alpha.d.ts",
29
+ "default": "./lib/index.js"
30
+ },
31
+ "require": {
32
+ "types": "./dist/alpha.d.ts",
33
+ "default": "./dist/index.js"
34
+ }
35
+ },
36
+ "./internal": {
37
+ "import": {
38
+ "types": "./lib/index.d.ts",
39
+ "default": "./lib/index.js"
40
+ },
41
+ "require": {
42
+ "types": "./dist/index.d.ts",
43
+ "default": "./dist/index.js"
44
+ }
45
+ }
46
+ },
47
+ "main": "lib/index.js",
48
+ "types": "lib/public.d.ts",
49
+ "c8": {
50
+ "all": true,
51
+ "cache-dir": "nyc/.cache",
52
+ "exclude": [
53
+ "src/test/**/*.*ts",
54
+ "dist/test/**/*.*js",
55
+ "lib/test/**/*.*js"
56
+ ],
57
+ "exclude-after-remap": false,
58
+ "include": [
59
+ "src/**/*.*ts",
60
+ "dist/**/*.*js",
61
+ "lib/**/*.*js"
62
+ ],
63
+ "report-dir": "nyc/report",
64
+ "reporter": [
65
+ "cobertura",
66
+ "html",
67
+ "text"
68
+ ],
69
+ "temp-directory": "nyc/.nyc_output"
70
+ },
71
+ "dependencies": {
72
+ "@fluidframework/telemetry-utils": "~2.93.0"
73
+ },
74
+ "devDependencies": {
75
+ "@arethetypeswrong/cli": "^0.18.2",
76
+ "@biomejs/biome": "~2.4.5",
77
+ "@fluid-internal/mocha-test-setup": "~2.93.0",
78
+ "@fluid-tools/build-cli": "^0.64.0",
79
+ "@fluidframework/build-common": "^2.0.3",
80
+ "@fluidframework/build-tools": "^0.64.0",
81
+ "@fluidframework/eslint-config-fluid": "^9.0.0",
82
+ "@microsoft/api-extractor": "7.58.1",
83
+ "@types/mocha": "^10.0.10",
84
+ "@types/node": "~22.19.17",
85
+ "c8": "^10.1.3",
86
+ "concurrently": "^9.2.1",
87
+ "copyfiles": "^2.4.1",
88
+ "cross-env": "^10.1.0",
89
+ "eslint": "~9.39.1",
90
+ "eslint-config-prettier": "~10.1.8",
91
+ "jiti": "^2.6.1",
92
+ "mocha": "^11.7.5",
93
+ "mocha-multi-reporters": "^1.5.1",
94
+ "prettier": "~3.6.2",
95
+ "rimraf": "^6.1.3",
96
+ "typescript": "~5.4.5"
97
+ },
98
+ "typeValidation": {
99
+ "disabled": true
100
+ },
101
+ "scripts": {
102
+ "api": "fluid-build . --task api",
103
+ "api-extractor:commonjs": "flub generate entrypoints --resolutionConditions require --outFileLegacyBeta legacy --outDir ./dist",
104
+ "api-extractor:esnext": "flub generate entrypoints --outFileLegacyBeta legacy --outDir ./lib --node10TypeCompat",
105
+ "build": "fluid-build . --task build",
106
+ "build:commonjs": "fluid-build . --task commonjs",
107
+ "build:compile": "fluid-build . --task compile",
108
+ "build:docs": "api-extractor run --local",
109
+ "build:esnext": "tsc --project ./tsconfig.json",
110
+ "build:test": "npm run build:test:esm && npm run build:test:cjs",
111
+ "build:test:cjs": "fluid-tsc commonjs --project ./src/test/tsconfig.cjs.json",
112
+ "build:test:esm": "tsc --project ./src/test/tsconfig.json",
113
+ "check:are-the-types-wrong": "attw --pack . --profile node16",
114
+ "check:biome": "biome check .",
115
+ "check:exports": "concurrently \"npm:check:exports:*\"",
116
+ "check:exports:bundle-release-tags": "api-extractor run --config api-extractor/api-extractor-lint-bundle.json",
117
+ "check:exports:cjs:alpha": "api-extractor run --config api-extractor/api-extractor-lint-alpha.cjs.json",
118
+ "check:exports:cjs:index": "api-extractor run --config api-extractor/api-extractor-lint-index.cjs.json",
119
+ "check:exports:cjs:public": "api-extractor run --config api-extractor/api-extractor-lint-public.cjs.json",
120
+ "check:exports:esm:alpha": "api-extractor run --config api-extractor/api-extractor-lint-alpha.esm.json",
121
+ "check:exports:esm:index": "api-extractor run --config api-extractor/api-extractor-lint-index.esm.json",
122
+ "check:exports:esm:public": "api-extractor run --config api-extractor/api-extractor-lint-public.esm.json",
123
+ "check:format": "npm run check:biome",
124
+ "ci:build:docs": "api-extractor run",
125
+ "clean": "rimraf --glob dist lib {alpha,beta,internal,legacy}.d.ts \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
126
+ "eslint": "eslint --quiet --format stylish src",
127
+ "eslint:fix": "eslint --quiet --format stylish src --fix --fix-type problem,suggestion,layout",
128
+ "format": "npm run format:biome",
129
+ "format:biome": "biome check . --write",
130
+ "lint": "fluid-build . --task lint",
131
+ "lint:fix": "fluid-build . --task eslint:fix --task format",
132
+ "test": "npm run test:mocha",
133
+ "test:coverage": "c8 npm test",
134
+ "test:mocha": "npm run test:mocha:esm && echo skipping cjs to avoid overhead - npm run test:mocha:cjs",
135
+ "test:mocha:cjs": "cross-env FLUID_TEST_MODULE_SYSTEM=CJS mocha",
136
+ "test:mocha:esm": "mocha",
137
+ "test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
138
+ "tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist",
139
+ "typetests:gen": "flub generate typetests --dir . -v",
140
+ "typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
141
+ }
142
+ }
package/src/index.ts ADDED
@@ -0,0 +1,57 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * Shared types for exposing schema methods and properties to an LLM agent.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+
12
+ export {
13
+ buildFunc,
14
+ exposeMethodsSymbol,
15
+ type ExposedMethods,
16
+ type Arg,
17
+ type ArgsTuple,
18
+ type FunctionDef,
19
+ type MethodKeys,
20
+ type Ctor,
21
+ type IExposedMethods,
22
+ } from "./methodBinding.js";
23
+
24
+ export {
25
+ exposePropertiesSymbol,
26
+ type ExposedProperties,
27
+ type IExposedProperties,
28
+ } from "./propertyBinding.js";
29
+
30
+ export { typeFactory, isTypeFactoryType } from "./treeAgentTypes.js";
31
+
32
+ export type {
33
+ TypeFactoryType,
34
+ TypeFactoryTypeKind,
35
+ TypeFactoryString,
36
+ TypeFactoryNumber,
37
+ TypeFactoryBoolean,
38
+ TypeFactoryDate,
39
+ TypeFactoryVoid,
40
+ TypeFactoryUndefined,
41
+ TypeFactoryNull,
42
+ TypeFactoryUnknown,
43
+ TypeFactoryArray,
44
+ TypeFactoryPromise,
45
+ TypeFactoryObject,
46
+ TypeFactoryRecord,
47
+ TypeFactoryMap,
48
+ TypeFactoryTuple,
49
+ TypeFactoryUnion,
50
+ TypeFactoryIntersection,
51
+ TypeFactoryLiteral,
52
+ TypeFactoryOptional,
53
+ TypeFactoryReadonly,
54
+ TypeFactoryFunction,
55
+ TypeFactoryFunctionParameter,
56
+ TypeFactoryInstanceOf,
57
+ } from "./treeAgentTypes.js";
@@ -0,0 +1,139 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /* eslint-disable @typescript-eslint/no-explicit-any */
7
+
8
+ import type { TypeFactoryType } from "./treeAgentTypes.js";
9
+
10
+ /**
11
+ * A utility type that extracts the method keys from a given type.
12
+ * @alpha
13
+ */
14
+ export type MethodKeys<T> = {
15
+ [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
16
+ };
17
+
18
+ /**
19
+ * A type that represents a constructor function.
20
+ * @alpha
21
+ */
22
+ export type Ctor<T = any> = new (...args: any[]) => T;
23
+
24
+ /**
25
+ * A type that represents a function argument.
26
+ * @alpha
27
+ */
28
+ export type Arg<T extends TypeFactoryType = TypeFactoryType> = readonly [
29
+ name: string,
30
+ type: T,
31
+ ];
32
+
33
+ /**
34
+ * A utility type that extracts the argument types from a function definition.
35
+ * @alpha
36
+ */
37
+ export type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Single extends Arg]
38
+ ? [Single[1]]
39
+ : T extends readonly [infer Head extends Arg, ...infer Tail extends readonly Arg[]]
40
+ ? [Head[1], ...ArgsTuple<Tail>]
41
+ : never;
42
+
43
+ /**
44
+ * A function definition interface that describes the structure of a function.
45
+ * @alpha
46
+ */
47
+ export interface FunctionDef<
48
+ Args extends readonly Arg[],
49
+ Return extends TypeFactoryType,
50
+ Rest extends TypeFactoryType | null = null,
51
+ > {
52
+ /**
53
+ * Optional description of the function.
54
+ */
55
+ description?: string;
56
+ /**
57
+ * The function's parameters.
58
+ */
59
+ args: Args;
60
+ /**
61
+ * Optional rest parameter type.
62
+ */
63
+ rest?: Rest;
64
+ /**
65
+ * The function's return type.
66
+ */
67
+ returns: Return;
68
+ }
69
+
70
+ /**
71
+ * A utility function to build a function definition.
72
+ * @alpha
73
+ */
74
+ export function buildFunc<
75
+ const Return extends TypeFactoryType,
76
+ const Args extends readonly Arg[],
77
+ const Rest extends TypeFactoryType | null = null,
78
+ >(
79
+ def: { description?: string; returns: Return; rest?: Rest },
80
+ ...args: Args
81
+ ): FunctionDef<Args, Return, Rest> {
82
+ return {
83
+ description: def.description,
84
+ returns: def.returns,
85
+ args,
86
+ rest: def.rest,
87
+ };
88
+ }
89
+
90
+ /**
91
+ * An interface for exposing methods of classes to an agent.
92
+ * @alpha
93
+ */
94
+ export interface ExposedMethods {
95
+ /**
96
+ * Expose a method with type factory types.
97
+ */
98
+ exposeMethod<
99
+ const K extends string & keyof MethodKeys<InstanceType<S>>,
100
+ S extends Ctor & IExposedMethods,
101
+ Z extends FunctionDef<readonly Arg[], TypeFactoryType, TypeFactoryType | null>,
102
+ >(constructor: S, methodName: K, tfFunction: Z): void;
103
+
104
+ /**
105
+ * Expose a method with type factory types.
106
+ */
107
+ expose<
108
+ const K extends string & keyof MethodKeys<InstanceType<S>>,
109
+ S extends Ctor & IExposedMethods,
110
+ Z extends FunctionDef<readonly Arg[], TypeFactoryType, TypeFactoryType | null>,
111
+ >(constructor: S, methodName: K, tfFunction: Z): void;
112
+ }
113
+
114
+ /**
115
+ * A symbol used to expose methods to the LLM.
116
+ * @alpha
117
+ */
118
+ export const exposeMethodsSymbol: unique symbol = Symbol("Type factory expose method/symbol");
119
+
120
+ /**
121
+ * An interface that classes should implement to expose their methods to the LLM.
122
+ *
123
+ * @remarks
124
+ * The `getExposedMethods` free function will cause the method here to be called on the class passed to it.
125
+ *
126
+ * @privateremarks
127
+ * Implementing this interface correctly seems tricky?
128
+ * To actually implement it in a way that satisfies TypeScript,
129
+ * classes need to declare both a static version and an instance version of the method
130
+ * (the instance one can just delegate to the static one).
131
+ *
132
+ * @alpha
133
+ */
134
+ export interface IExposedMethods {
135
+ /**
136
+ * Static method that exposes methods of this class to an agent.
137
+ */
138
+ [exposeMethodsSymbol](methods: ExposedMethods): void;
139
+ }
@@ -0,0 +1,62 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /* eslint-disable @typescript-eslint/no-explicit-any */
7
+
8
+ import type { Ctor } from "./methodBinding.js";
9
+ import type { TypeFactoryType } from "./treeAgentTypes.js";
10
+
11
+ /**
12
+ * A symbol used to expose properties to the LLM.
13
+ * @alpha
14
+ */
15
+ export const exposePropertiesSymbol: unique symbol = Symbol(
16
+ "Type factory expose property/symbol",
17
+ );
18
+
19
+ /**
20
+ * An interface for exposing properties of classes to an agent.
21
+ * @alpha
22
+ */
23
+ export interface ExposedProperties {
24
+ /**
25
+ * Expose a property with type factory type and metadata.
26
+ */
27
+ exposeProperty<S extends Ctor, K extends string>(
28
+ constructor: S,
29
+ name: K,
30
+ def: { schema: TypeFactoryType; description?: string; readOnly?: boolean },
31
+ ): void;
32
+
33
+ /**
34
+ * Expose a property with type factory type (simple form).
35
+ */
36
+ exposeProperty<S extends Ctor, K extends string>(
37
+ constructor: S,
38
+ name: K,
39
+ tfType: TypeFactoryType,
40
+ ): void;
41
+ }
42
+
43
+ /**
44
+ * An interface that classes should implement to expose their properties to the LLM.
45
+ *
46
+ * @remarks
47
+ * The `getExposedProperties` free function will cause the method here to be called on the class passed to it.
48
+ *
49
+ * @privateremarks
50
+ * Implementing this interface correctly seems tricky?
51
+ * To actually implement it in a way that satisfies TypeScript,
52
+ * classes need to declare both a static version and an instance version of the method
53
+ * (the instance one can just delegate to the static one).
54
+ *
55
+ * @alpha
56
+ */
57
+ export interface IExposedProperties {
58
+ /**
59
+ * Static method that exposes properties of this class to an agent.
60
+ */
61
+ [exposePropertiesSymbol]?(properties: ExposedProperties): void;
62
+ }