@fluidframework/ai-collab 2.10.0-306579
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/.eslintrc.cjs +26 -0
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +280 -0
- package/alpha.d.ts +11 -0
- package/api-extractor/api-extractor-lint-alpha.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-alpha.esm.json +5 -0
- package/api-extractor/api-extractor-lint-bundle.json +5 -0
- package/api-extractor/api-extractor-lint-index.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-index.esm.json +5 -0
- package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-public.esm.json +5 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +4 -0
- package/api-report/ai-collab.alpha.api.md +164 -0
- package/api-report/ai-collab.beta.api.md +7 -0
- package/api-report/ai-collab.public.api.md +7 -0
- package/biome.jsonc +4 -0
- package/dist/aiCollab.d.ts +65 -0
- package/dist/aiCollab.d.ts.map +1 -0
- package/dist/aiCollab.js +81 -0
- package/dist/aiCollab.js.map +1 -0
- package/dist/aiCollabApi.d.ts +173 -0
- package/dist/aiCollabApi.d.ts.map +1 -0
- package/dist/aiCollabApi.js +7 -0
- package/dist/aiCollabApi.js.map +1 -0
- package/dist/alpha.d.ts +41 -0
- package/dist/explicit-strategy/agentEditReducer.d.ts +12 -0
- package/dist/explicit-strategy/agentEditReducer.d.ts.map +1 -0
- package/dist/explicit-strategy/agentEditReducer.js +394 -0
- package/dist/explicit-strategy/agentEditReducer.js.map +1 -0
- package/dist/explicit-strategy/agentEditTypes.d.ts +158 -0
- package/dist/explicit-strategy/agentEditTypes.d.ts.map +1 -0
- package/dist/explicit-strategy/agentEditTypes.js +50 -0
- package/dist/explicit-strategy/agentEditTypes.js.map +1 -0
- package/dist/explicit-strategy/idGenerator.d.ts +22 -0
- package/dist/explicit-strategy/idGenerator.d.ts.map +1 -0
- package/dist/explicit-strategy/idGenerator.js +74 -0
- package/dist/explicit-strategy/idGenerator.js.map +1 -0
- package/dist/explicit-strategy/index.d.ts +51 -0
- package/dist/explicit-strategy/index.d.ts.map +1 -0
- package/dist/explicit-strategy/index.js +223 -0
- package/dist/explicit-strategy/index.js.map +1 -0
- package/dist/explicit-strategy/jsonTypes.d.ts +23 -0
- package/dist/explicit-strategy/jsonTypes.d.ts.map +1 -0
- package/dist/explicit-strategy/jsonTypes.js +7 -0
- package/dist/explicit-strategy/jsonTypes.js.map +1 -0
- package/dist/explicit-strategy/promptGeneration.d.ts +51 -0
- package/dist/explicit-strategy/promptGeneration.d.ts.map +1 -0
- package/dist/explicit-strategy/promptGeneration.js +218 -0
- package/dist/explicit-strategy/promptGeneration.js.map +1 -0
- package/dist/explicit-strategy/typeGeneration.d.ts +15 -0
- package/dist/explicit-strategy/typeGeneration.d.ts.map +1 -0
- package/dist/explicit-strategy/typeGeneration.js +264 -0
- package/dist/explicit-strategy/typeGeneration.js.map +1 -0
- package/dist/explicit-strategy/utils.d.ts +37 -0
- package/dist/explicit-strategy/utils.d.ts.map +1 -0
- package/dist/explicit-strategy/utils.js +47 -0
- package/dist/explicit-strategy/utils.js.map +1 -0
- package/dist/implicit-strategy/index.d.ts +8 -0
- package/dist/implicit-strategy/index.d.ts.map +1 -0
- package/dist/implicit-strategy/index.js +18 -0
- package/dist/implicit-strategy/index.js.map +1 -0
- package/dist/implicit-strategy/sharedTreeBranchManager.d.ts +63 -0
- package/dist/implicit-strategy/sharedTreeBranchManager.d.ts.map +1 -0
- package/dist/implicit-strategy/sharedTreeBranchManager.js +212 -0
- package/dist/implicit-strategy/sharedTreeBranchManager.js.map +1 -0
- package/dist/implicit-strategy/sharedTreeDiff.d.ts +102 -0
- package/dist/implicit-strategy/sharedTreeDiff.d.ts.map +1 -0
- package/dist/implicit-strategy/sharedTreeDiff.js +522 -0
- package/dist/implicit-strategy/sharedTreeDiff.js.map +1 -0
- package/dist/implicit-strategy/utils.d.ts +21 -0
- package/dist/implicit-strategy/utils.d.ts.map +1 -0
- package/dist/implicit-strategy/utils.js +49 -0
- package/dist/implicit-strategy/utils.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +3 -0
- package/dist/public.d.ts +19 -0
- package/eslintrc.cjs +11 -0
- package/internal.d.ts +11 -0
- package/lib/aiCollab.d.ts +65 -0
- package/lib/aiCollab.d.ts.map +1 -0
- package/lib/aiCollab.js +77 -0
- package/lib/aiCollab.js.map +1 -0
- package/lib/aiCollabApi.d.ts +173 -0
- package/lib/aiCollabApi.d.ts.map +1 -0
- package/lib/aiCollabApi.js +6 -0
- package/lib/aiCollabApi.js.map +1 -0
- package/lib/alpha.d.ts +41 -0
- package/lib/explicit-strategy/agentEditReducer.d.ts +12 -0
- package/lib/explicit-strategy/agentEditReducer.d.ts.map +1 -0
- package/lib/explicit-strategy/agentEditReducer.js +390 -0
- package/lib/explicit-strategy/agentEditReducer.js.map +1 -0
- package/lib/explicit-strategy/agentEditTypes.d.ts +158 -0
- package/lib/explicit-strategy/agentEditTypes.d.ts.map +1 -0
- package/lib/explicit-strategy/agentEditTypes.js +47 -0
- package/lib/explicit-strategy/agentEditTypes.js.map +1 -0
- package/lib/explicit-strategy/idGenerator.d.ts +22 -0
- package/lib/explicit-strategy/idGenerator.d.ts.map +1 -0
- package/lib/explicit-strategy/idGenerator.js +70 -0
- package/lib/explicit-strategy/idGenerator.js.map +1 -0
- package/lib/explicit-strategy/index.d.ts +51 -0
- package/lib/explicit-strategy/index.d.ts.map +1 -0
- package/lib/explicit-strategy/index.js +219 -0
- package/lib/explicit-strategy/index.js.map +1 -0
- package/lib/explicit-strategy/jsonTypes.d.ts +23 -0
- package/lib/explicit-strategy/jsonTypes.d.ts.map +1 -0
- package/lib/explicit-strategy/jsonTypes.js +6 -0
- package/lib/explicit-strategy/jsonTypes.js.map +1 -0
- package/lib/explicit-strategy/promptGeneration.d.ts +51 -0
- package/lib/explicit-strategy/promptGeneration.d.ts.map +1 -0
- package/lib/explicit-strategy/promptGeneration.js +208 -0
- package/lib/explicit-strategy/promptGeneration.js.map +1 -0
- package/lib/explicit-strategy/typeGeneration.d.ts +15 -0
- package/lib/explicit-strategy/typeGeneration.d.ts.map +1 -0
- package/lib/explicit-strategy/typeGeneration.js +260 -0
- package/lib/explicit-strategy/typeGeneration.js.map +1 -0
- package/lib/explicit-strategy/utils.d.ts +37 -0
- package/lib/explicit-strategy/utils.d.ts.map +1 -0
- package/lib/explicit-strategy/utils.js +41 -0
- package/lib/explicit-strategy/utils.js.map +1 -0
- package/lib/implicit-strategy/index.d.ts +8 -0
- package/lib/implicit-strategy/index.d.ts.map +1 -0
- package/lib/implicit-strategy/index.js +8 -0
- package/lib/implicit-strategy/index.js.map +1 -0
- package/lib/implicit-strategy/sharedTreeBranchManager.d.ts +63 -0
- package/lib/implicit-strategy/sharedTreeBranchManager.d.ts.map +1 -0
- package/lib/implicit-strategy/sharedTreeBranchManager.js +213 -0
- package/lib/implicit-strategy/sharedTreeBranchManager.js.map +1 -0
- package/lib/implicit-strategy/sharedTreeDiff.d.ts +102 -0
- package/lib/implicit-strategy/sharedTreeDiff.d.ts.map +1 -0
- package/lib/implicit-strategy/sharedTreeDiff.js +515 -0
- package/lib/implicit-strategy/sharedTreeDiff.js.map +1 -0
- package/lib/implicit-strategy/utils.d.ts +21 -0
- package/lib/implicit-strategy/utils.d.ts.map +1 -0
- package/lib/implicit-strategy/utils.js +43 -0
- package/lib/implicit-strategy/utils.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +15 -0
- package/lib/index.js.map +1 -0
- package/lib/public.d.ts +19 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/mocharc.cjs +14 -0
- package/package.json +165 -0
- package/prettier.config.cjs +8 -0
- package/src/aiCollab.ts +86 -0
- package/src/aiCollabApi.ts +184 -0
- package/src/explicit-strategy/agentEditReducer.ts +498 -0
- package/src/explicit-strategy/agentEditTypes.ts +177 -0
- package/src/explicit-strategy/idGenerator.ts +90 -0
- package/src/explicit-strategy/index.ts +364 -0
- package/src/explicit-strategy/jsonTypes.ts +27 -0
- package/src/explicit-strategy/promptGeneration.ts +294 -0
- package/src/explicit-strategy/typeGeneration.ts +374 -0
- package/src/explicit-strategy/utils.ts +60 -0
- package/src/implicit-strategy/README.md +4 -0
- package/src/implicit-strategy/index.ts +21 -0
- package/src/implicit-strategy/sharedTreeBranchManager.ts +294 -0
- package/src/implicit-strategy/sharedTreeDiff.ts +735 -0
- package/src/implicit-strategy/utils.ts +54 -0
- package/src/index.ts +39 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +12 -0
- package/tsdoc.json +4 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { NodeKind } from "@fluidframework/tree";
|
|
6
|
+
/**
|
|
7
|
+
* Checks if the given object is an {@link TreeMapNode}.
|
|
8
|
+
*/
|
|
9
|
+
export function isTreeMapNode(obj) {
|
|
10
|
+
if (typeof obj === "object" && obj !== null) {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
12
|
+
const maybeNodeKind = Object.getPrototypeOf(obj)?.constructor?.kind;
|
|
13
|
+
return maybeNodeKind === NodeKind.Map;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Checks if the given object is an {@link TreeArrayNode}.
|
|
19
|
+
*/
|
|
20
|
+
export function isTreeArrayNode(obj) {
|
|
21
|
+
if (typeof obj === "object" && obj !== null) {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
23
|
+
const maybeNodeKind = Object.getPrototypeOf(obj)?.constructor?.kind;
|
|
24
|
+
return maybeNodeKind === NodeKind.Array;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Traverses the provided {@link ObjectPath} on the provided Shared Tree or JSON object and returns the value at the end of the path.
|
|
30
|
+
*
|
|
31
|
+
* @alpha
|
|
32
|
+
*/
|
|
33
|
+
export function sharedTreeTraverse(jsonObject, path) {
|
|
34
|
+
let current = jsonObject;
|
|
35
|
+
for (const key of path) {
|
|
36
|
+
if (current === undefined || current === null) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
current = isTreeMapNode(current) ? current.get(key) : current[key];
|
|
40
|
+
}
|
|
41
|
+
return current;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/implicit-strategy/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAwC,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAItF;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,GAAY;IACzC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC7C,sEAAsE;QACtE,MAAM,aAAa,GAAY,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC;QAC7E,OAAO,aAAa,KAAK,QAAQ,CAAC,GAAG,CAAC;IACvC,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,GAAY;IAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC7C,sEAAsE;QACtE,MAAM,aAAa,GAAY,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC;QAC7E,OAAO,aAAa,KAAK,QAAQ,CAAC,KAAK,CAAC;IACzC,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CACjC,UAAiE,EACjE,IAAgB;IAEhB,IAAI,OAAO,GAAY,UAAU,CAAC;IAElC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YAC/C,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,GAAa,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,OAAY,CAAC;AACrB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type TreeMapNode, type TreeArrayNode, NodeKind } from \"@fluidframework/tree\";\n\nimport type { ObjectPath } from \"./sharedTreeDiff.js\";\n\n/**\n * Checks if the given object is an {@link TreeMapNode}.\n */\nexport function isTreeMapNode(obj: unknown): obj is TreeMapNode {\n\tif (typeof obj === \"object\" && obj !== null) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\tconst maybeNodeKind: unknown = Object.getPrototypeOf(obj)?.constructor?.kind;\n\t\treturn maybeNodeKind === NodeKind.Map;\n\t}\n\treturn false;\n}\n\n/**\n * Checks if the given object is an {@link TreeArrayNode}.\n */\nexport function isTreeArrayNode(obj: unknown): obj is TreeArrayNode {\n\tif (typeof obj === \"object\" && obj !== null) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\tconst maybeNodeKind: unknown = Object.getPrototypeOf(obj)?.constructor?.kind;\n\t\treturn maybeNodeKind === NodeKind.Array;\n\t}\n\treturn false;\n}\n\n/**\n * Traverses the provided {@link ObjectPath} on the provided Shared Tree or JSON object and returns the value at the end of the path.\n *\n * @alpha\n */\nexport function sharedTreeTraverse<T = unknown>(\n\tjsonObject: TreeMapNode | TreeArrayNode | Record<string, unknown>,\n\tpath: ObjectPath,\n): T | undefined {\n\tlet current: unknown = jsonObject;\n\n\tfor (const key of path) {\n\t\tif (current === undefined || current === null) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tcurrent = isTreeMapNode(current) ? current.get(key as string) : current[key];\n\t}\n\n\treturn current as T;\n}\n"]}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Experimental package for utilities that enable/simplify interaction with LLMs for apps based on SharedTree.
|
|
7
|
+
*
|
|
8
|
+
* See {@link https://github.com/microsoft/FluidFramework/tree/main/packages/framework/ai-collab#readme | README.md }
|
|
9
|
+
* for an overview of the package.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
export { type DifferenceCreate, type DifferenceChange, type DifferenceMove, type DifferenceRemove, type Difference, type ObjectPath, type Options, sharedTreeDiff, createMergableIdDiffSeries, createMergableDiffSeries, SharedTreeBranchManager, sharedTreeTraverse, } from "./implicit-strategy/index.js";
|
|
14
|
+
export { type AiCollabOptions, type AiCollabSuccessResponse, type AiCollabErrorResponse, type TokenUsage, type TokenLimits, type OpenAiClientOptions, } from "./aiCollabApi.js";
|
|
15
|
+
export { aiCollab } from "./aiCollab.js";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,cAAc,EACd,0BAA0B,EAC1B,wBAAwB,EACxB,uBAAuB,EACvB,kBAAkB,GAClB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,mBAAmB,GACxB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Experimental package for utilities that enable/simplify interaction with LLMs for apps based on SharedTree.
|
|
7
|
+
*
|
|
8
|
+
* See {@link https://github.com/microsoft/FluidFramework/tree/main/packages/framework/ai-collab#readme | README.md }
|
|
9
|
+
* for an overview of the package.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
export { sharedTreeDiff, createMergableIdDiffSeries, createMergableDiffSeries, SharedTreeBranchManager, sharedTreeTraverse, } from "./implicit-strategy/index.js";
|
|
14
|
+
export { aiCollab } from "./aiCollab.js";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAQN,cAAc,EACd,0BAA0B,EAC1B,wBAAwB,EACxB,uBAAuB,EACvB,kBAAkB,GAClB,MAAM,8BAA8B,CAAC;AAWtC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Experimental package for utilities that enable/simplify interaction with LLMs for apps based on SharedTree.\n *\n * See {@link https://github.com/microsoft/FluidFramework/tree/main/packages/framework/ai-collab#readme | README.md }\n * for an overview of the package.\n *\n * @packageDocumentation\n */\n\nexport {\n\ttype DifferenceCreate,\n\ttype DifferenceChange,\n\ttype DifferenceMove,\n\ttype DifferenceRemove,\n\ttype Difference,\n\ttype ObjectPath,\n\ttype Options,\n\tsharedTreeDiff,\n\tcreateMergableIdDiffSeries,\n\tcreateMergableDiffSeries,\n\tSharedTreeBranchManager,\n\tsharedTreeTraverse,\n} from \"./implicit-strategy/index.js\";\n\nexport {\n\ttype AiCollabOptions,\n\ttype AiCollabSuccessResponse,\n\ttype AiCollabErrorResponse,\n\ttype TokenUsage,\n\ttype TokenLimits,\n\ttype OpenAiClientOptions,\n} from \"./aiCollabApi.js\";\n\nexport { aiCollab } from \"./aiCollab.js\";\n"]}
|
package/lib/public.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
8
|
+
* Generated by "flub generate entrypoints" in @fluid-tools/build-cli.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Experimental package for utilities that enable/simplify interaction with LLMs for apps based on SharedTree.
|
|
13
|
+
*
|
|
14
|
+
* See {@link https://github.com/microsoft/FluidFramework/tree/main/packages/framework/ai-collab#readme | README.md }
|
|
15
|
+
* for an overview of the package.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/export {}
|
|
19
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.47.8"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/mocharc.cjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const getFluidTestMochaConfig = require("@fluid-internal/mocha-test-setup/mocharc-common");
|
|
9
|
+
|
|
10
|
+
const packageDir = __dirname;
|
|
11
|
+
const config = getFluidTestMochaConfig(packageDir);
|
|
12
|
+
config.spec = process.env.MOCHA_SPEC ?? "lib/test/**/*.spec.js";
|
|
13
|
+
|
|
14
|
+
module.exports = config;
|
package/package.json
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluidframework/ai-collab",
|
|
3
|
+
"version": "2.10.0-306579",
|
|
4
|
+
"description": "Experimental package to simplify integrating AI into Fluid-based applications",
|
|
5
|
+
"homepage": "https://fluidframework.com",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/microsoft/FluidFramework.git",
|
|
9
|
+
"directory": "packages/framework/ai-collab"
|
|
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/core-utils": "2.10.0-306579",
|
|
73
|
+
"@fluidframework/runtime-utils": "2.10.0-306579",
|
|
74
|
+
"@fluidframework/telemetry-utils": "2.10.0-306579",
|
|
75
|
+
"@fluidframework/tree": "2.10.0-306579",
|
|
76
|
+
"openai": "^4.67.3",
|
|
77
|
+
"typechat": "^0.1.1",
|
|
78
|
+
"zod": "^3.23.8"
|
|
79
|
+
},
|
|
80
|
+
"devDependencies": {
|
|
81
|
+
"@arethetypeswrong/cli": "^0.16.4",
|
|
82
|
+
"@biomejs/biome": "~1.9.3",
|
|
83
|
+
"@fluid-internal/mocha-test-setup": "2.10.0-306579",
|
|
84
|
+
"@fluid-tools/build-cli": "^0.50.0",
|
|
85
|
+
"@fluidframework/build-common": "^2.0.3",
|
|
86
|
+
"@fluidframework/build-tools": "^0.50.0",
|
|
87
|
+
"@fluidframework/eslint-config-fluid": "^5.4.0",
|
|
88
|
+
"@fluidframework/id-compressor": "2.10.0-306579",
|
|
89
|
+
"@fluidframework/runtime-utils": "2.10.0-306579",
|
|
90
|
+
"@fluidframework/test-runtime-utils": "2.10.0-306579",
|
|
91
|
+
"@microsoft/api-extractor": "7.47.8",
|
|
92
|
+
"@types/mocha": "^9.1.1",
|
|
93
|
+
"@types/node": "^18.19.0",
|
|
94
|
+
"c8": "^8.0.1",
|
|
95
|
+
"concurrently": "^8.2.1",
|
|
96
|
+
"copyfiles": "^2.4.1",
|
|
97
|
+
"cross-env": "^7.0.3",
|
|
98
|
+
"eslint": "~8.55.0",
|
|
99
|
+
"eslint-config-prettier": "~9.0.0",
|
|
100
|
+
"mocha": "^10.2.0",
|
|
101
|
+
"mocha-json-output-reporter": "^2.0.1",
|
|
102
|
+
"mocha-multi-reporters": "^1.5.1",
|
|
103
|
+
"prettier": "~3.0.3",
|
|
104
|
+
"rimraf": "^4.4.0",
|
|
105
|
+
"typescript": "~5.4.5"
|
|
106
|
+
},
|
|
107
|
+
"fluidBuild": {
|
|
108
|
+
"tasks": {
|
|
109
|
+
"build:esnext": [
|
|
110
|
+
"...",
|
|
111
|
+
"typetests:gen"
|
|
112
|
+
],
|
|
113
|
+
"tsc": [
|
|
114
|
+
"...",
|
|
115
|
+
"typetests:gen"
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"typeValidation": {
|
|
120
|
+
"disabled": true,
|
|
121
|
+
"broken": {},
|
|
122
|
+
"entrypoint": "internal"
|
|
123
|
+
},
|
|
124
|
+
"scripts": {
|
|
125
|
+
"api": "fluid-build . --task api",
|
|
126
|
+
"api-extractor:commonjs": "flub generate entrypoints --outDir ./dist",
|
|
127
|
+
"api-extractor:esnext": "flub generate entrypoints --outDir ./lib --node10TypeCompat",
|
|
128
|
+
"build": "fluid-build . --task build",
|
|
129
|
+
"build:commonjs": "fluid-build . --task commonjs",
|
|
130
|
+
"build:compile": "fluid-build . --task compile",
|
|
131
|
+
"build:docs": "api-extractor run --local",
|
|
132
|
+
"build:esnext": "tsc --project ./tsconfig.json",
|
|
133
|
+
"build:test": "npm run build:test:esm && npm run build:test:cjs",
|
|
134
|
+
"build:test:cjs": "fluid-tsc commonjs --project ./src/test/tsconfig.cjs.json",
|
|
135
|
+
"build:test:esm": "tsc --project ./src/test/tsconfig.json",
|
|
136
|
+
"check:are-the-types-wrong": "echo skip per issue #112 - node10 requirement: attw --pack .",
|
|
137
|
+
"check:biome": "biome check .",
|
|
138
|
+
"check:exports": "concurrently \"npm:check:exports:*\"",
|
|
139
|
+
"check:exports:bundle-release-tags": "api-extractor run --config api-extractor/api-extractor-lint-bundle.json",
|
|
140
|
+
"check:exports:cjs:alpha": "api-extractor run --config api-extractor/api-extractor-lint-alpha.cjs.json",
|
|
141
|
+
"check:exports:cjs:index": "api-extractor run --config api-extractor/api-extractor-lint-index.cjs.json",
|
|
142
|
+
"check:exports:cjs:public": "api-extractor run --config api-extractor/api-extractor-lint-public.cjs.json",
|
|
143
|
+
"check:exports:esm:alpha": "api-extractor run --config api-extractor/api-extractor-lint-alpha.esm.json",
|
|
144
|
+
"check:exports:esm:index": "api-extractor run --config api-extractor/api-extractor-lint-index.esm.json",
|
|
145
|
+
"check:exports:esm:public": "api-extractor run --config api-extractor/api-extractor-lint-public.esm.json",
|
|
146
|
+
"check:format": "npm run check:biome",
|
|
147
|
+
"ci:build:docs": "api-extractor run",
|
|
148
|
+
"clean": "rimraf --glob dist lib \"*.d.ts\" \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
|
|
149
|
+
"eslint": "eslint --format stylish src",
|
|
150
|
+
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
151
|
+
"format": "npm run format:biome",
|
|
152
|
+
"format:biome": "biome check . --write",
|
|
153
|
+
"lint": "fluid-build . --task lint",
|
|
154
|
+
"lint:fix": "fluid-build . --task eslint:fix --task format",
|
|
155
|
+
"test": "npm run test:mocha",
|
|
156
|
+
"test:coverage": "c8 npm test",
|
|
157
|
+
"test:mocha": "npm run test:mocha:esm && echo skipping cjs to avoid overhead - npm run test:mocha:cjs",
|
|
158
|
+
"test:mocha:cjs": "mocha --recursive \"dist/test/**/*.spec.js\"",
|
|
159
|
+
"test:mocha:esm": "mocha --recursive \"lib/test/**/*.spec.js\"",
|
|
160
|
+
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
|
|
161
|
+
"tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist",
|
|
162
|
+
"typetests:gen": "flub generate typetests --dir . -v",
|
|
163
|
+
"typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
|
|
164
|
+
}
|
|
165
|
+
}
|
package/src/aiCollab.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
AiCollabErrorResponse,
|
|
8
|
+
AiCollabOptions,
|
|
9
|
+
AiCollabSuccessResponse,
|
|
10
|
+
} from "./aiCollabApi.js";
|
|
11
|
+
import { generateTreeEdits } from "./explicit-strategy/index.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Calls an LLM to modify the provided SharedTree in a series of real time edits based on the provided users prompt input.
|
|
15
|
+
* @remarks This function is designed to be a controlled "all-in-one" function that handles the entire process of calling an LLM to collaborative edit a SharedTree.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import {
|
|
20
|
+
* SchemaFactory,
|
|
21
|
+
* TreeViewConfiguration,
|
|
22
|
+
* type TreeView
|
|
23
|
+
* } from "@fluidframework/tree";
|
|
24
|
+
*
|
|
25
|
+
* const sf = new SchemaFactory("todo-app");
|
|
26
|
+
*
|
|
27
|
+
* class TodoTask extends sf.object("TodoTask", {
|
|
28
|
+
* title: sf.string,
|
|
29
|
+
* description: sf.string,
|
|
30
|
+
* }) {}
|
|
31
|
+
*
|
|
32
|
+
* class TodoAppState extends sf.object("TodoAppState", {
|
|
33
|
+
* tasks: sf.array(TodoTask),
|
|
34
|
+
* }) {}
|
|
35
|
+
*
|
|
36
|
+
* // Initialize your SharedTree
|
|
37
|
+
* const treeView: TreeView = tree.viewWith(new TreeViewConfiguration({ schema: TodoAppState }));
|
|
38
|
+
* treeView.initialize({ tasks: [] });
|
|
39
|
+
*
|
|
40
|
+
* // Collaborate with AI in realtime in just one function call.
|
|
41
|
+
* const response = await aiCollab({
|
|
42
|
+
* openAI: {
|
|
43
|
+
* client: new OpenAI({
|
|
44
|
+
* apiKey: OPENAI_API_KEY,
|
|
45
|
+
* }),
|
|
46
|
+
* modelName: "gpt-4o",
|
|
47
|
+
* },
|
|
48
|
+
* treeNode: view.root,
|
|
49
|
+
* prompt: {
|
|
50
|
+
* systemRoleContext:
|
|
51
|
+
* "You are an helpful assistant managing a todo list for a user.",
|
|
52
|
+
* userAsk: "Create a set of new todos to plan a vacation to Cancun.",
|
|
53
|
+
* },
|
|
54
|
+
* planningStep: true,
|
|
55
|
+
* finalReviewStep: true,
|
|
56
|
+
* dumpDebugLog: true,
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @remarks Known Limitiations:
|
|
61
|
+
* - Root level array nodes are not supported
|
|
62
|
+
* - Nested arrays are not supported
|
|
63
|
+
* - Primitive nodes are not supported, e.g. 'string', 'number', 'boolean'
|
|
64
|
+
* - Your application's Shared Tree schema must have no more than 4 levels of nesting
|
|
65
|
+
* - Optional nodes are not supported in the Shared Tree schema
|
|
66
|
+
* - Union types are not supported in the Shared Tree schema
|
|
67
|
+
* - See README for more details.
|
|
68
|
+
*
|
|
69
|
+
* @alpha
|
|
70
|
+
*/
|
|
71
|
+
export async function aiCollab(
|
|
72
|
+
options: AiCollabOptions,
|
|
73
|
+
): Promise<AiCollabSuccessResponse | AiCollabErrorResponse> {
|
|
74
|
+
const response = await generateTreeEdits({
|
|
75
|
+
treeNode: options.treeNode,
|
|
76
|
+
validator: options.validator,
|
|
77
|
+
openAI: options.openAI,
|
|
78
|
+
prompt: options.prompt,
|
|
79
|
+
limiters: options.limiters,
|
|
80
|
+
dumpDebugLog: options.dumpDebugLog,
|
|
81
|
+
planningStep: options.planningStep,
|
|
82
|
+
finalReviewStep: options.finalReviewStep,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return response;
|
|
86
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { TreeNode } from "@fluidframework/tree";
|
|
7
|
+
// eslint-disable-next-line import/no-named-as-default
|
|
8
|
+
import type OpenAI from "openai";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* OpenAI client options for the {@link AiCollabOptions} interface.
|
|
12
|
+
*
|
|
13
|
+
* @alpha
|
|
14
|
+
*/
|
|
15
|
+
export interface OpenAiClientOptions {
|
|
16
|
+
/**
|
|
17
|
+
* The OpenAI client to use for the AI collaboration.
|
|
18
|
+
*/
|
|
19
|
+
client: OpenAI;
|
|
20
|
+
/**
|
|
21
|
+
* The name of the target OpenAI model to use for the AI collaboration.
|
|
22
|
+
*/
|
|
23
|
+
modelName?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Options for the AI collaboration.
|
|
28
|
+
*
|
|
29
|
+
* @alpha
|
|
30
|
+
*/
|
|
31
|
+
export interface AiCollabOptions {
|
|
32
|
+
/**
|
|
33
|
+
* The OpenAI client options to use for the LLM based AI collaboration.
|
|
34
|
+
*/
|
|
35
|
+
readonly openAI: OpenAiClientOptions;
|
|
36
|
+
/**
|
|
37
|
+
* The specific tree node you want the AI to collaborate on. Pass the root node of your tree if you intend
|
|
38
|
+
* for the AI to work on the entire tree.
|
|
39
|
+
* @remarks
|
|
40
|
+
* - Optional root nodes are not supported
|
|
41
|
+
* - Primitive root nodes are not supported
|
|
42
|
+
*/
|
|
43
|
+
readonly treeNode: TreeNode;
|
|
44
|
+
/**
|
|
45
|
+
* The prompt context to give the LLM in order to collaborate with your applications data.
|
|
46
|
+
*/
|
|
47
|
+
readonly prompt: {
|
|
48
|
+
/**
|
|
49
|
+
* The context to give the LLM about its role in the collaboration.
|
|
50
|
+
* @remarks It's highly recommended to give context about your applications data model and the LLM's role in the collaboration.
|
|
51
|
+
*/
|
|
52
|
+
readonly systemRoleContext: string;
|
|
53
|
+
/**
|
|
54
|
+
* The request from the users to the LLM.
|
|
55
|
+
*/
|
|
56
|
+
readonly userAsk: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Limiters are various optional ways to limit this library's usage of the LLM.
|
|
60
|
+
*/
|
|
61
|
+
readonly limiters?: {
|
|
62
|
+
/**
|
|
63
|
+
* An optional AbortController that can be used to abort the AI collaboration while it is still in progress.
|
|
64
|
+
*/
|
|
65
|
+
readonly abortController?: AbortController;
|
|
66
|
+
/**
|
|
67
|
+
* The maximum number of sequential errors the LLM can make before aborting the collaboration.
|
|
68
|
+
* If the maximum number of sequential errors is reached, the AI collaboration will be aborted and return with the errorMessage 'tooManyErrors'.
|
|
69
|
+
* Leaving this undefined will disable this limiter.
|
|
70
|
+
*/
|
|
71
|
+
readonly maxSequentialErrors?: number;
|
|
72
|
+
/**
|
|
73
|
+
* The maximum number of model calls the LLM can make before aborting the collaboration.
|
|
74
|
+
* If the maximum number of model calls is reached, the AI collaboration will be aborted and return with the errorMessage 'tooManyModelCalls'.
|
|
75
|
+
* Leaving this undefined will disable this limiter.
|
|
76
|
+
*/
|
|
77
|
+
readonly maxModelCalls?: number;
|
|
78
|
+
/**
|
|
79
|
+
* The maximum token usage limits for the LLM.
|
|
80
|
+
* If the LLM exceeds the token limits, the AI collaboration will be aborted and return with the errorMessage 'tokenLimitExceeded'.
|
|
81
|
+
* This happens after the first model call's token usage is calculated, meaning that the limits set may be exceeded by a certain amount.
|
|
82
|
+
* Leaving this undefined will disable this limiter.
|
|
83
|
+
*/
|
|
84
|
+
readonly tokenLimits?: TokenLimits;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* When set to true, the LLM will be asked to first produce a plan, based on the user's ask, before generating any changes to your applications data.
|
|
88
|
+
* This can help the LLM produce better results.
|
|
89
|
+
* When set to false, the LLM will not be asked to produce a plan.
|
|
90
|
+
*/
|
|
91
|
+
readonly planningStep?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* When set to true, the LLM will be asked to complete a final review of the changes and determine if any additional changes need to be made.
|
|
94
|
+
* When set to false, the LLM will not be asked to complete a final review.
|
|
95
|
+
*/
|
|
96
|
+
readonly finalReviewStep?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* An optional validator function that can be used to validate the new content produced by the LLM.
|
|
99
|
+
*/
|
|
100
|
+
readonly validator?: (newContent: TreeNode) => void;
|
|
101
|
+
/**
|
|
102
|
+
* When enabled, the library will console.log information useful for debugging the AI collaboration.
|
|
103
|
+
*/
|
|
104
|
+
readonly dumpDebugLog?: boolean;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A successful response from the AI collaboration.
|
|
109
|
+
*
|
|
110
|
+
* @alpha
|
|
111
|
+
*/
|
|
112
|
+
export interface AiCollabSuccessResponse {
|
|
113
|
+
/**
|
|
114
|
+
* The status of the Ai Collaboration.
|
|
115
|
+
* A 'success' status indicates that the AI collaboration was successful at creating changes.
|
|
116
|
+
*/
|
|
117
|
+
readonly status: "success";
|
|
118
|
+
/**
|
|
119
|
+
* {@inheritDoc TokenUsage}
|
|
120
|
+
*/
|
|
121
|
+
readonly tokensUsed: TokenUsage;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* An error response from the AI collaboration.
|
|
126
|
+
*
|
|
127
|
+
* @alpha
|
|
128
|
+
*/
|
|
129
|
+
export interface AiCollabErrorResponse {
|
|
130
|
+
/**
|
|
131
|
+
* The status of the Ai Collaboration.
|
|
132
|
+
* - A 'partial-failure' status indicates that the AI collaboration was partially successful, but was aborted due to a limiter or other error
|
|
133
|
+
* - A "failure" status indicates that the AI collaboration was not successful at creating any changes.
|
|
134
|
+
*/
|
|
135
|
+
readonly status: "failure" | "partial-failure";
|
|
136
|
+
/**
|
|
137
|
+
* The type of known error that occured
|
|
138
|
+
* - 'tokenLimitExceeded' indicates that the LLM exceeded the token limits set by the user
|
|
139
|
+
* - 'tooManyErrors' indicates that the LLM made too many errors in a row
|
|
140
|
+
* - 'tooManyModelCalls' indicates that the LLM made too many model calls
|
|
141
|
+
* - 'aborted' indicates that the AI collaboration was aborted by the user or a limiter
|
|
142
|
+
*/
|
|
143
|
+
readonly errorMessage:
|
|
144
|
+
| "tokenLimitExceeded"
|
|
145
|
+
| "tooManyErrors"
|
|
146
|
+
| "tooManyModelCalls"
|
|
147
|
+
| "aborted";
|
|
148
|
+
/**
|
|
149
|
+
* {@inheritDoc TokenUsage}
|
|
150
|
+
*/
|
|
151
|
+
readonly tokensUsed: TokenUsage;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Total usage of tokens by an LLM.
|
|
156
|
+
*
|
|
157
|
+
* @alpha
|
|
158
|
+
*/
|
|
159
|
+
export interface TokenUsage {
|
|
160
|
+
/**
|
|
161
|
+
* The total number of tokens used by the LLM for input.
|
|
162
|
+
*/
|
|
163
|
+
inputTokens: number;
|
|
164
|
+
/**
|
|
165
|
+
* The total number of tokens used by the LLM for output.
|
|
166
|
+
*/
|
|
167
|
+
outputTokens: number;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Maximum limits for the total tokens that can be used by an llm
|
|
172
|
+
*
|
|
173
|
+
* @alpha
|
|
174
|
+
*/
|
|
175
|
+
export interface TokenLimits {
|
|
176
|
+
/**
|
|
177
|
+
* The maximum number of tokens that can be used by the LLM for input.
|
|
178
|
+
*/
|
|
179
|
+
readonly inputTokens?: number;
|
|
180
|
+
/**
|
|
181
|
+
* The maximum number of tokens that can be used by the LLM for output.
|
|
182
|
+
*/
|
|
183
|
+
readonly outputTokens?: number;
|
|
184
|
+
}
|