@fluidframework/ai-collab 2.22.1 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +70 -4
- package/api-report/ai-collab.alpha.api.md +170 -2
- package/dist/aiCollab.d.ts +0 -1
- package/dist/aiCollab.d.ts.map +1 -1
- package/dist/aiCollab.js +1 -2
- package/dist/aiCollab.js.map +1 -1
- package/dist/aiCollabApi.d.ts +50 -3
- package/dist/aiCollabApi.d.ts.map +1 -1
- package/dist/aiCollabApi.js.map +1 -1
- package/dist/alpha.d.ts +17 -0
- package/dist/explicit-strategy/debugEvents.d.ts +248 -0
- package/dist/explicit-strategy/debugEvents.d.ts.map +1 -0
- package/dist/explicit-strategy/debugEvents.js +36 -0
- package/dist/explicit-strategy/debugEvents.js.map +1 -0
- package/dist/explicit-strategy/index.d.ts +4 -4
- package/dist/explicit-strategy/index.d.ts.map +1 -1
- package/dist/explicit-strategy/index.js +176 -54
- package/dist/explicit-strategy/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/lib/aiCollab.d.ts +0 -1
- package/lib/aiCollab.d.ts.map +1 -1
- package/lib/aiCollab.js +1 -2
- package/lib/aiCollab.js.map +1 -1
- package/lib/aiCollabApi.d.ts +50 -3
- package/lib/aiCollabApi.d.ts.map +1 -1
- package/lib/aiCollabApi.js.map +1 -1
- package/lib/alpha.d.ts +17 -0
- package/lib/explicit-strategy/debugEvents.d.ts +248 -0
- package/lib/explicit-strategy/debugEvents.d.ts.map +1 -0
- package/lib/explicit-strategy/debugEvents.js +32 -0
- package/lib/explicit-strategy/debugEvents.js.map +1 -0
- package/lib/explicit-strategy/index.d.ts +4 -4
- package/lib/explicit-strategy/index.d.ts.map +1 -1
- package/lib/explicit-strategy/index.js +174 -52
- package/lib/explicit-strategy/index.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +13 -11
- package/src/aiCollab.ts +1 -2
- package/src/aiCollabApi.ts +54 -3
- package/src/explicit-strategy/debugEvents.ts +297 -0
- package/src/explicit-strategy/index.ts +269 -59
- package/src/index.ts +20 -0
package/lib/aiCollabApi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiCollabApi.d.ts","sourceRoot":"","sources":["../src/aiCollabApi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IACnC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC/B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACrC;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE;QAChB;;;WAGG;QACH,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;QACnC;;WAEG;QACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;KACzB,CAAC;IACF;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACnB;;WAEG;QACH,QAAQ,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC;QAC3C;;;;WAIG;QACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;QACtC;;;;WAIG;QACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;QAChC;;;;;WAKG;QACH,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;KACnC,CAAC;IACF;;;;O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,CAAC,UAAU,EAAE,UAAU,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IAC1B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B;;OAEG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;OAEG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAC/B"}
|
package/lib/aiCollabApi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiCollabApi.js","sourceRoot":"","sources":["../src/aiCollabApi.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { TreeNode } from \"@fluidframework/tree\";\n// eslint-disable-next-line import/no-named-as-default\nimport type OpenAI from \"openai\";\n\n/**\n * OpenAI client options for the {@link AiCollabOptions} interface.\n *\n * @alpha\n */\nexport interface OpenAiClientOptions {\n\t/**\n\t * The OpenAI client to use for the AI collaboration.\n\t */\n\tclient: OpenAI;\n\t/**\n\t * The name of the target OpenAI model to use for the AI collaboration.\n\t */\n\tmodelName?: string;\n}\n\n/**\n * Options for the AI collaboration.\n *\n * @alpha\n */\nexport interface AiCollabOptions {\n\t/**\n\t * The OpenAI client options to use for the LLM based AI collaboration.\n\t */\n\treadonly openAI: OpenAiClientOptions;\n\t/**\n\t * The specific tree node you want the AI to collaborate on. Pass the root node of your tree if you intend\n\t * for the AI to work on the entire tree.\n\t * @remarks\n\t * - Optional root nodes are not supported\n\t * - Primitive root nodes are not supported\n\t */\n\treadonly treeNode: TreeNode;\n\t/**\n\t * The prompt context to give the LLM in order to collaborate with your applications data.\n\t */\n\treadonly prompt: {\n\t\t/**\n\t\t * The context to give the LLM about its role in the collaboration.\n\t\t * @remarks It's highly recommended to give context about your applications data model and the LLM's role in the collaboration.\n\t\t */\n\t\treadonly systemRoleContext: string;\n\t\t/**\n\t\t * The request from the users to the LLM.\n\t\t */\n\t\treadonly userAsk: string;\n\t};\n\t/**\n\t * Limiters are various optional ways to limit this library's usage of the LLM.\n\t */\n\treadonly limiters?: {\n\t\t/**\n\t\t * An optional AbortController that can be used to abort the AI collaboration while it is still in progress.\n\t\t */\n\t\treadonly abortController?: AbortController;\n\t\t/**\n\t\t * The maximum number of sequential errors the LLM can make before aborting the collaboration.\n\t\t * If the maximum number of sequential errors is reached, the AI collaboration will be aborted and return with the errorMessage 'tooManyErrors'.\n\t\t * Leaving this undefined will disable this limiter.\n\t\t */\n\t\treadonly maxSequentialErrors?: number;\n\t\t/**\n\t\t * The maximum number of model calls the LLM can make before aborting the collaboration.\n\t\t * If the maximum number of model calls is reached, the AI collaboration will be aborted and return with the errorMessage 'tooManyModelCalls'.\n\t\t * Leaving this undefined will disable this limiter.\n\t\t */\n\t\treadonly maxModelCalls?: number;\n\t\t/**\n\t\t * The maximum token usage limits for the LLM.\n\t\t * If the LLM exceeds the token limits, the AI collaboration will be aborted and return with the errorMessage 'tokenLimitExceeded'.\n\t\t * This happens after the first model call's token usage is calculated, meaning that the limits set may be exceeded by a certain amount.\n\t\t * Leaving this undefined will disable this limiter.\n\t\t */\n\t\treadonly tokenLimits?: TokenLimits;\n\t};\n\t/**\n\t * 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.\n\t * This can help the LLM produce better results.\n\t * When set to false, the LLM will not be asked to produce a plan.\n\t */\n\treadonly planningStep?: boolean;\n\t/**\n\t * 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.\n\t * When set to false, the LLM will not be asked to complete a final review.\n\t */\n\treadonly finalReviewStep?: boolean;\n\t/**\n\t * An optional validator function that can be used to validate the new content produced by the LLM.\n\t */\n\treadonly validator?: (newContent: TreeNode) => void;\n\t/**\n\t *
|
|
1
|
+
{"version":3,"file":"aiCollabApi.js","sourceRoot":"","sources":["../src/aiCollabApi.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { TreeNode } from \"@fluidframework/tree\";\n// eslint-disable-next-line import/no-named-as-default\nimport type OpenAI from \"openai\";\n\n/**\n * Core Debug event type for the ai-collab\n * @alpha\n */\nexport interface DebugEvent {\n\t/**\n\t * The unique id of the debug event.\n\t */\n\tid: string;\n\t/**\n\t * An id that will be shared across all debug events that originate from the same single execution of ai-collab.\n\t * @remarks This is intended to be used to correlate all debug events that originate from the same execution\n\t */\n\ttraceId: string;\n\t/**\n\t * The name of the debug event.\n\t */\n\teventName: string;\n\t/**\n\t * The date and time at which the debug event was created.\n\t */\n\ttimestamp: string;\n}\n\n/**\n * A Debug event that marks the start or end of a single core logic flow, such as generated tree edits, planning prompt, etc.\n * @alpha\n */\nexport interface EventFlowDebugEvent extends DebugEvent {\n\t/**\n\t * The name of the particular event flow.\n\t */\n\teventFlowName: string;\n\t/**\n\t * The status of the particular event flow.\n\t */\n\teventFlowStatus: \"STARTED\" | \"COMPLETED\" | \"IN_PROGRESS\";\n\t/**\n\t * A unique id that will be shared across all debug events that are part of the same event flow.\n\t */\n\teventFlowTraceId: string;\n}\n\n/**\n * A callback function that can be used to handle debug events that occur during the AI collaboration process.\n * @alpha\n */\nexport type DebugEventLogHandler = <T extends DebugEvent>(event: T) => unknown;\n\n/**\n * OpenAI client options for the {@link AiCollabOptions} interface.\n *\n * @alpha\n */\nexport interface OpenAiClientOptions {\n\t/**\n\t * The OpenAI client to use for the AI collaboration.\n\t */\n\tclient: OpenAI;\n\t/**\n\t * The name of the target OpenAI model to use for the AI collaboration.\n\t */\n\tmodelName?: string;\n}\n\n/**\n * Options for the AI collaboration.\n *\n * @alpha\n */\nexport interface AiCollabOptions {\n\t/**\n\t * The OpenAI client options to use for the LLM based AI collaboration.\n\t */\n\treadonly openAI: OpenAiClientOptions;\n\t/**\n\t * The specific tree node you want the AI to collaborate on. Pass the root node of your tree if you intend\n\t * for the AI to work on the entire tree.\n\t * @remarks\n\t * - Optional root nodes are not supported\n\t * - Primitive root nodes are not supported\n\t */\n\treadonly treeNode: TreeNode;\n\t/**\n\t * The prompt context to give the LLM in order to collaborate with your applications data.\n\t */\n\treadonly prompt: {\n\t\t/**\n\t\t * The context to give the LLM about its role in the collaboration.\n\t\t * @remarks It's highly recommended to give context about your applications data model and the LLM's role in the collaboration.\n\t\t */\n\t\treadonly systemRoleContext: string;\n\t\t/**\n\t\t * The request from the users to the LLM.\n\t\t */\n\t\treadonly userAsk: string;\n\t};\n\t/**\n\t * Limiters are various optional ways to limit this library's usage of the LLM.\n\t */\n\treadonly limiters?: {\n\t\t/**\n\t\t * An optional AbortController that can be used to abort the AI collaboration while it is still in progress.\n\t\t */\n\t\treadonly abortController?: AbortController;\n\t\t/**\n\t\t * The maximum number of sequential errors the LLM can make before aborting the collaboration.\n\t\t * If the maximum number of sequential errors is reached, the AI collaboration will be aborted and return with the errorMessage 'tooManyErrors'.\n\t\t * Leaving this undefined will disable this limiter.\n\t\t */\n\t\treadonly maxSequentialErrors?: number;\n\t\t/**\n\t\t * The maximum number of model calls the LLM can make before aborting the collaboration.\n\t\t * If the maximum number of model calls is reached, the AI collaboration will be aborted and return with the errorMessage 'tooManyModelCalls'.\n\t\t * Leaving this undefined will disable this limiter.\n\t\t */\n\t\treadonly maxModelCalls?: number;\n\t\t/**\n\t\t * The maximum token usage limits for the LLM.\n\t\t * If the LLM exceeds the token limits, the AI collaboration will be aborted and return with the errorMessage 'tokenLimitExceeded'.\n\t\t * This happens after the first model call's token usage is calculated, meaning that the limits set may be exceeded by a certain amount.\n\t\t * Leaving this undefined will disable this limiter.\n\t\t */\n\t\treadonly tokenLimits?: TokenLimits;\n\t};\n\t/**\n\t * 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.\n\t * This can help the LLM produce better results.\n\t * When set to false, the LLM will not be asked to produce a plan.\n\t */\n\treadonly planningStep?: boolean;\n\t/**\n\t * 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.\n\t * When set to false, the LLM will not be asked to complete a final review.\n\t */\n\treadonly finalReviewStep?: boolean;\n\t/**\n\t * An optional validator function that can be used to validate the new content produced by the LLM.\n\t */\n\treadonly validator?: (newContent: TreeNode) => void;\n\t/**\n\t * An optional handler for debug events that occur during the AI collaboration.\n\t */\n\treadonly debugEventLogHandler?: DebugEventLogHandler;\n}\n\n/**\n * A successful response from the AI collaboration.\n *\n * @alpha\n */\nexport interface AiCollabSuccessResponse {\n\t/**\n\t * The status of the Ai Collaboration.\n\t * A 'success' status indicates that the AI collaboration was successful at creating changes.\n\t */\n\treadonly status: \"success\";\n\t/**\n\t * {@inheritDoc TokenUsage}\n\t */\n\treadonly tokensUsed: TokenUsage;\n}\n\n/**\n * An error response from the AI collaboration.\n *\n * @alpha\n */\nexport interface AiCollabErrorResponse {\n\t/**\n\t * The status of the Ai Collaboration.\n\t * - A 'partial-failure' status indicates that the AI collaboration was partially successful, but was aborted due to a limiter or other error\n\t * - A \"failure\" status indicates that the AI collaboration was not successful at creating any changes.\n\t */\n\treadonly status: \"failure\" | \"partial-failure\";\n\t/**\n\t * The type of known error that occured\n\t * - 'tokenLimitExceeded' indicates that the LLM exceeded the token limits set by the user\n\t * - 'tooManyErrors' indicates that the LLM made too many errors in a row\n\t * - 'tooManyModelCalls' indicates that the LLM made too many model calls\n\t * - 'aborted' indicates that the AI collaboration was aborted by the user or a limiter\n\t * - 'unexpectedError' indicates that an unexpected error occured\n\t */\n\treadonly errorMessage:\n\t\t| \"tokenLimitExceeded\"\n\t\t| \"tooManyErrors\"\n\t\t| \"tooManyModelCalls\"\n\t\t| \"aborted\"\n\t\t| \"unexpectedError\";\n\t/**\n\t * {@inheritDoc TokenUsage}\n\t */\n\treadonly tokensUsed: TokenUsage;\n}\n\n/**\n * Total usage of tokens by an LLM.\n *\n * @alpha\n */\nexport interface TokenUsage {\n\t/**\n\t * The total number of tokens used by the LLM for input.\n\t */\n\tinputTokens: number;\n\t/**\n\t * The total number of tokens used by the LLM for output.\n\t */\n\toutputTokens: number;\n}\n\n/**\n * Maximum limits for the total tokens that can be used by an llm\n *\n * @alpha\n */\nexport interface TokenLimits {\n\t/**\n\t * The maximum number of tokens that can be used by the LLM for input.\n\t */\n\treadonly inputTokens?: number;\n\t/**\n\t * The maximum number of tokens that can be used by the LLM for output.\n\t */\n\treadonly outputTokens?: number;\n}\n"]}
|
package/lib/alpha.d.ts
CHANGED
|
@@ -22,14 +22,31 @@ export {
|
|
|
22
22
|
AiCollabErrorResponse,
|
|
23
23
|
AiCollabOptions,
|
|
24
24
|
AiCollabSuccessResponse,
|
|
25
|
+
ApplyEditFailure,
|
|
26
|
+
ApplyEditSuccess,
|
|
27
|
+
CoreEventLoopCompleted,
|
|
28
|
+
CoreEventLoopStarted,
|
|
29
|
+
DebugEvent,
|
|
30
|
+
DebugEventLogHandler,
|
|
25
31
|
Difference,
|
|
26
32
|
DifferenceChange,
|
|
27
33
|
DifferenceCreate,
|
|
28
34
|
DifferenceMove,
|
|
29
35
|
DifferenceRemove,
|
|
36
|
+
EventFlowDebugEvent,
|
|
37
|
+
EventFlowDebugName,
|
|
38
|
+
EventFlowDebugNames,
|
|
39
|
+
FinalReviewCompleted,
|
|
40
|
+
FinalReviewStarted,
|
|
41
|
+
GenerateTreeEditCompleted,
|
|
42
|
+
GenerateTreeEditStarted,
|
|
43
|
+
LlmApiCallDebugEvent,
|
|
44
|
+
LlmTreeEdit,
|
|
30
45
|
ObjectPath,
|
|
31
46
|
OpenAiClientOptions,
|
|
32
47
|
Options,
|
|
48
|
+
PlanningPromptCompleted,
|
|
49
|
+
PlanningPromptStarted,
|
|
33
50
|
SharedTreeBranchManager,
|
|
34
51
|
TokenLimits,
|
|
35
52
|
TokenUsage,
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { DebugEvent, EventFlowDebugEvent } from "../aiCollabApi.js";
|
|
6
|
+
/**
|
|
7
|
+
* This file contains the types for the debug events that are emitted by the explicit strategy
|
|
8
|
+
* as well as a helper functions to help create a consistent method for producing a base {@link DebugEvent}.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The possible values for the `eventFlowName` field in an {@link EventFlowDebugEvent}.
|
|
12
|
+
* @alpha
|
|
13
|
+
*/
|
|
14
|
+
export declare const EventFlowDebugNames: {
|
|
15
|
+
readonly CORE_EVENT_LOOP: "CORE_EVENT_LOOP";
|
|
16
|
+
readonly GENERATE_PLANNING_PROMPT: "GENERATE_PLANNING_PROMPT";
|
|
17
|
+
readonly GENERATE_AND_APPLY_TREE_EDIT: "GENERATE_AND_APPLY_TREE_EDIT";
|
|
18
|
+
readonly FINAL_REVIEW: "FINAL_REVIEW";
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The type for possible values for the `eventFlowName` field in an {@link EventFlowDebugEvent}.
|
|
22
|
+
* @alpha
|
|
23
|
+
*/
|
|
24
|
+
export type EventFlowDebugName = (typeof EventFlowDebugNames)[keyof typeof EventFlowDebugNames];
|
|
25
|
+
/**
|
|
26
|
+
* An edit generated by an LLM that can be applied to a given SharedTree.
|
|
27
|
+
* @privateremarks TODO: We need a better solution here because don't want to expose the internal TreeEdit type here, but we need to be able to type it.
|
|
28
|
+
* @alpha
|
|
29
|
+
*/
|
|
30
|
+
export type LlmTreeEdit = Record<string, unknown>;
|
|
31
|
+
/**
|
|
32
|
+
* An {@link EventFlowDebugEvent} for signaling the start of the ai-collab's core event loop.
|
|
33
|
+
* Which makes various calls to the LLM to eventually apply edits to the users SharedTree which
|
|
34
|
+
* accomplish the user's provided goal. There will be exactly 1 of these events per ai-collab function execution.
|
|
35
|
+
* @alpha
|
|
36
|
+
*/
|
|
37
|
+
export interface CoreEventLoopStarted extends EventFlowDebugEvent {
|
|
38
|
+
eventName: "CORE_EVENT_LOOP_STARTED";
|
|
39
|
+
eventFlowName: typeof EventFlowDebugNames.CORE_EVENT_LOOP;
|
|
40
|
+
eventFlowStatus: "STARTED";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* An {@link EventFlowDebugEvent} for signaling the end of the ai-collab's core event loop.
|
|
44
|
+
* There could be various reasons for the event loop to end, early exits and failures
|
|
45
|
+
* which should be captured in the status and failureReason fields. There will be exactly 1
|
|
46
|
+
* of these events per ai-collab function execution.
|
|
47
|
+
* @alpha
|
|
48
|
+
*/
|
|
49
|
+
export interface CoreEventLoopCompleted extends EventFlowDebugEvent {
|
|
50
|
+
eventName: "CORE_EVENT_LOOP_COMPLETED";
|
|
51
|
+
eventFlowName: typeof EventFlowDebugNames.CORE_EVENT_LOOP;
|
|
52
|
+
eventFlowStatus: "COMPLETED";
|
|
53
|
+
status: "success" | "failure";
|
|
54
|
+
failureReason?: string;
|
|
55
|
+
errorMessage?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* An {@link EventFlowDebugEvent} marking the initiation of the flow for prompting an LLM to generate a plan for accomplishing the user's goal.
|
|
59
|
+
* There will be exactly 1 of these events per ai-collab function execution.
|
|
60
|
+
* @alpha
|
|
61
|
+
*/
|
|
62
|
+
export interface PlanningPromptStarted extends EventFlowDebugEvent {
|
|
63
|
+
eventName: "GENERATE_PLANNING_PROMPT_STARTED";
|
|
64
|
+
eventFlowName: typeof EventFlowDebugNames.GENERATE_PLANNING_PROMPT;
|
|
65
|
+
eventFlowStatus: "STARTED";
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* An {@link EventFlowDebugEvent} marking the completion of the flow for prompting an LLM to generate a plan for accomplishing the user's goal.
|
|
69
|
+
* There will be exactly 1 of these events per ai-collab function execution.
|
|
70
|
+
* @alpha
|
|
71
|
+
*/
|
|
72
|
+
export interface PlanningPromptCompleted<TIsLlmResponseValid = boolean, TPlan = TIsLlmResponseValid extends true ? string : undefined> extends EventFlowDebugEvent {
|
|
73
|
+
eventName: "GENERATE_PLANNING_PROMPT_COMPLETED";
|
|
74
|
+
eventFlowName: typeof EventFlowDebugNames.GENERATE_PLANNING_PROMPT;
|
|
75
|
+
eventFlowStatus: "COMPLETED";
|
|
76
|
+
/**
|
|
77
|
+
* Whether the response produced by the LLM is an expected response.
|
|
78
|
+
* In the event that the LLM fails to respond in an expected way, despite the API call to the LLM itself being successful, then this fields value will be `false`.
|
|
79
|
+
*
|
|
80
|
+
* For now, this case is limited to the LLM returning undefined as a response when it should have returned something. But in the future this could expand
|
|
81
|
+
* to things such as invalid json.
|
|
82
|
+
*/
|
|
83
|
+
isLlmResponseValid: TIsLlmResponseValid;
|
|
84
|
+
/**
|
|
85
|
+
* The plan generated by the LLM. If the `wasLlmResponseValid` field is `false` then this will be undefined, otherwise it will be a string.
|
|
86
|
+
*/
|
|
87
|
+
llmGeneratedPlan: TPlan;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* An {@link EventFlowDebugEvent} marking the initiation of the flow for prompting an LLM to
|
|
91
|
+
* generate an {@link LlmTreeEdit} to the users Shared Tree based on the users initial ask.
|
|
92
|
+
* It is expected that the LLM will generate multiple of these events when it must generate multiple tree edits to satisfy the user request
|
|
93
|
+
* @alpha
|
|
94
|
+
*/
|
|
95
|
+
export interface GenerateTreeEditStarted extends EventFlowDebugEvent {
|
|
96
|
+
eventName: "GENERATE_TREE_EDIT_STARTED";
|
|
97
|
+
eventFlowName: typeof EventFlowDebugNames.GENERATE_AND_APPLY_TREE_EDIT;
|
|
98
|
+
eventFlowStatus: "STARTED";
|
|
99
|
+
llmPrompt: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* An {@link EventFlowDebugEvent} marking the completion of the flow for prompting an LLM to
|
|
103
|
+
* generate an {@link LlmTreeEdit} to the users Shared Tree based on the users initial ask.
|
|
104
|
+
* It is expected that the LLM will generate multiple of these events when it must generate multiple tree edits to satisfy the user request
|
|
105
|
+
* @alpha
|
|
106
|
+
*/
|
|
107
|
+
export interface GenerateTreeEditCompleted<TIsLlmResponseValid = boolean, TEdit = TIsLlmResponseValid extends true ? LlmTreeEdit | null : undefined> extends EventFlowDebugEvent {
|
|
108
|
+
eventName: "GENERATE_TREE_EDIT_COMPLETED";
|
|
109
|
+
eventFlowName: typeof EventFlowDebugNames.GENERATE_AND_APPLY_TREE_EDIT;
|
|
110
|
+
eventFlowStatus: "COMPLETED";
|
|
111
|
+
/**
|
|
112
|
+
* Whether the response produced by the LLM is an expected response.
|
|
113
|
+
* In the event that the LLM fails to respond in an expected way, despite the API call to the LLM itself being successful, then this fields value will be `false`.
|
|
114
|
+
*
|
|
115
|
+
* For now, this case is limited to the LLM returning undefined as a response when it should have returned something. But in the future this could expand
|
|
116
|
+
* to things such as invalid json.
|
|
117
|
+
*/
|
|
118
|
+
isLlmResponseValid: TIsLlmResponseValid;
|
|
119
|
+
/**
|
|
120
|
+
* If the `isLlmResponseValid` field value is `true` then this be one of two following values returned by the LLM:
|
|
121
|
+
* 1. An edit that can be applied to a SharedTree to further accomplish the user's goal.
|
|
122
|
+
* 2. `null` if the LLM decides no more edits are necessary.
|
|
123
|
+
*
|
|
124
|
+
* If the `isLlmResponseValid` field is `false` then this field will be `undefined`.
|
|
125
|
+
*/
|
|
126
|
+
llmGeneratedEdit: TEdit;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* An {@link EventFlowDebugEvent} marking the successful application of an edit generated by the LLM to a SharedTree.
|
|
130
|
+
* @alpha
|
|
131
|
+
*/
|
|
132
|
+
export interface ApplyEditSuccess extends EventFlowDebugEvent {
|
|
133
|
+
eventName: "APPLIED_EDIT_SUCCESS";
|
|
134
|
+
eventFlowName: typeof EventFlowDebugNames.GENERATE_AND_APPLY_TREE_EDIT;
|
|
135
|
+
eventFlowStatus: "IN_PROGRESS";
|
|
136
|
+
/**
|
|
137
|
+
* A unique id that will be shared across all debug events that are part of the same event flow.
|
|
138
|
+
*/
|
|
139
|
+
eventFlowTraceId: string;
|
|
140
|
+
/**
|
|
141
|
+
* The {@link LlmTreeEdit} generated by the LLM.
|
|
142
|
+
*/
|
|
143
|
+
edit: LlmTreeEdit;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* An {@link EventFlowDebugEvent} marking the failure of applying an edit generated by the LLM to a SharedTree.
|
|
147
|
+
* @alpha
|
|
148
|
+
*/
|
|
149
|
+
export interface ApplyEditFailure extends EventFlowDebugEvent {
|
|
150
|
+
eventName: "APPLIED_EDIT_FAILURE";
|
|
151
|
+
eventFlowName: typeof EventFlowDebugNames.GENERATE_AND_APPLY_TREE_EDIT;
|
|
152
|
+
eventFlowStatus: "IN_PROGRESS";
|
|
153
|
+
/**
|
|
154
|
+
* A unique id that will be shared across all debug events that are part of the same event flow.
|
|
155
|
+
*/
|
|
156
|
+
eventFlowTraceId: string;
|
|
157
|
+
/**
|
|
158
|
+
* The {@link LlmTreeEdit} generated by the LLM.
|
|
159
|
+
*/
|
|
160
|
+
edit: LlmTreeEdit;
|
|
161
|
+
/**
|
|
162
|
+
* The error message that was thrown when attempting to apply the edit.
|
|
163
|
+
*/
|
|
164
|
+
errorMessage: string;
|
|
165
|
+
/**
|
|
166
|
+
* The total number of errors that have occurred up until this point, not including this error.
|
|
167
|
+
*/
|
|
168
|
+
sequentialErrorCount: number;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* An {@link EventFlowDebugEvent} marking the initiation of the flow for prompting an LLM to complete a final review of its edits
|
|
172
|
+
* and determine whether the user's goal was accomplished.
|
|
173
|
+
* @alpha
|
|
174
|
+
*/
|
|
175
|
+
export interface FinalReviewStarted extends EventFlowDebugEvent {
|
|
176
|
+
eventName: "FINAL_REVIEW_STARTED";
|
|
177
|
+
eventFlowName: typeof EventFlowDebugNames.FINAL_REVIEW;
|
|
178
|
+
eventFlowStatus: "STARTED";
|
|
179
|
+
/**
|
|
180
|
+
* The prompt sent to the LLM to complete its final review of the edits its made.
|
|
181
|
+
*/
|
|
182
|
+
llmPrompt: string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* An {@link EventFlowDebugEvent} marking the end of the flow for prompting an LLM to complete a final review of its edits
|
|
186
|
+
* and determine whether the user's goal was accomplished.
|
|
187
|
+
* @alpha
|
|
188
|
+
*/
|
|
189
|
+
export interface FinalReviewCompleted<TIsLlmResponseValid = boolean, TReviewResponse = TIsLlmResponseValid extends true ? "yes" | "no" : undefined> extends EventFlowDebugEvent {
|
|
190
|
+
eventName: "FINAL_REVIEW_COMPLETED";
|
|
191
|
+
eventFlowName: typeof EventFlowDebugNames.FINAL_REVIEW;
|
|
192
|
+
eventFlowStatus: "COMPLETED";
|
|
193
|
+
/**
|
|
194
|
+
* Whether the response produced by the LLM is an expected response.
|
|
195
|
+
* In the event that the LLM fails to respond in an expected way, despite the API call to the LLM itself being successful, then this fields value will be `false`.
|
|
196
|
+
*
|
|
197
|
+
* For now, this case is limited to the LLM returning undefined as a response when it should have returned something. But in the future this could expand
|
|
198
|
+
* to things such as invalid json.
|
|
199
|
+
*/
|
|
200
|
+
isLlmResponseValid: TIsLlmResponseValid;
|
|
201
|
+
/**
|
|
202
|
+
* Whether the Llm believes the user's ask was accomplished, based on the Edits is has already generated and applied.
|
|
203
|
+
* If the `status` field is `false` then this field value will be `undefined`, otherwise it will be either "yes" or "no"
|
|
204
|
+
*/
|
|
205
|
+
didLlmAccomplishGoal: TReviewResponse;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* An {@link DebugEvent} for an API call directly to a LLM.
|
|
209
|
+
* @alpha
|
|
210
|
+
*/
|
|
211
|
+
export interface LlmApiCallDebugEvent extends DebugEvent {
|
|
212
|
+
eventName: "LLM_API_CALL";
|
|
213
|
+
/**
|
|
214
|
+
* The event flow name that made this LLM API call.
|
|
215
|
+
*/
|
|
216
|
+
triggeringEventFlowName: EventFlowDebugName;
|
|
217
|
+
/**
|
|
218
|
+
* The unique id that will be shared across all debug events that are part of the same event flow.
|
|
219
|
+
* @remarks This can be used to correlate all debug events that are part of the same event flow.
|
|
220
|
+
*/
|
|
221
|
+
eventFlowTraceId: string;
|
|
222
|
+
/**
|
|
223
|
+
* The LLM model name that was used for the API call.
|
|
224
|
+
*/
|
|
225
|
+
modelName: string;
|
|
226
|
+
/**
|
|
227
|
+
* The request parameters sent in the API call to the LLM. (Not the HTTP request parameters such as headers, etc.)
|
|
228
|
+
*/
|
|
229
|
+
requestParams: unknown;
|
|
230
|
+
/**
|
|
231
|
+
* The raw response from the LLM.
|
|
232
|
+
*/
|
|
233
|
+
response: unknown;
|
|
234
|
+
/**
|
|
235
|
+
* The total number of tokens used in the API call to the LLM.
|
|
236
|
+
*/
|
|
237
|
+
tokenUsage?: {
|
|
238
|
+
promptTokens: number;
|
|
239
|
+
completionTokens: number;
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Creates a base {@link DebugEvent}.
|
|
244
|
+
*/
|
|
245
|
+
export declare function generateDebugEvent<Tevent extends string>(eventName: Tevent, traceId: string): DebugEvent & {
|
|
246
|
+
eventName: Tevent;
|
|
247
|
+
};
|
|
248
|
+
//# sourceMappingURL=debugEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debugEvents.d.ts","sourceRoot":"","sources":["../../src/explicit-strategy/debugEvents.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAEzE;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;;CAKtB,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAC7B,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAC;AAEhE;;;;GA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D,eAAe,EAAE,SAAS,CAAC;IAC3B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB,CACpC,mBAAmB,GAAG,OAAO,EAC7B,eAAe,GAAG,mBAAmB,SAAS,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,CAC5E,SAAQ,mBAAmB;IAC5B,SAAS,EAAE,wBAAwB,CAAC;IACpC,aAAa,EAAE,OAAO,mBAAmB,CAAC,YAAY,CAAC;IACvD,eAAe,EAAE,WAAW,CAAC;IAC7B;;;;;;OAMG;IACH,kBAAkB,EAAE,mBAAmB,CAAC;IACxC;;;OAGG;IACH,oBAAoB,EAAE,eAAe,CAAC;CACtC;AAID;;;GAGG;AACH,MAAM,WAAW,oBAAqB,SAAQ,UAAU;IACvD,SAAS,EAAE,cAAc,CAAC;IAC1B;;OAEG;IACH,uBAAuB,EAAE,kBAAkB,CAAC;IAC5C;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE;QACZ,YAAY,EAAE,MAAM,CAAC;QACrB,gBAAgB,EAAE,MAAM,CAAC;KACzB,CAAC;CACF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,MAAM,EACvD,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACb,UAAU,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAQpC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { v4 as uuidv4 } from "uuid";
|
|
6
|
+
/**
|
|
7
|
+
* This file contains the types for the debug events that are emitted by the explicit strategy
|
|
8
|
+
* as well as a helper functions to help create a consistent method for producing a base {@link DebugEvent}.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The possible values for the `eventFlowName` field in an {@link EventFlowDebugEvent}.
|
|
12
|
+
* @alpha
|
|
13
|
+
*/
|
|
14
|
+
export const EventFlowDebugNames = {
|
|
15
|
+
CORE_EVENT_LOOP: "CORE_EVENT_LOOP",
|
|
16
|
+
GENERATE_PLANNING_PROMPT: "GENERATE_PLANNING_PROMPT",
|
|
17
|
+
GENERATE_AND_APPLY_TREE_EDIT: "GENERATE_AND_APPLY_TREE_EDIT",
|
|
18
|
+
FINAL_REVIEW: "FINAL_REVIEW",
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Creates a base {@link DebugEvent}.
|
|
22
|
+
*/
|
|
23
|
+
export function generateDebugEvent(eventName, traceId) {
|
|
24
|
+
const event = {
|
|
25
|
+
eventName,
|
|
26
|
+
id: uuidv4(),
|
|
27
|
+
traceId,
|
|
28
|
+
timestamp: new Date().toISOString(),
|
|
29
|
+
};
|
|
30
|
+
return event;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=debugEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debugEvents.js","sourceRoot":"","sources":["../../src/explicit-strategy/debugEvents.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAIpC;;;GAGG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAClC,eAAe,EAAE,iBAAiB;IAClC,wBAAwB,EAAE,0BAA0B;IACpD,4BAA4B,EAAE,8BAA8B;IAC5D,YAAY,EAAE,cAAc;CACnB,CAAC;AAmQX;;GAEG;AACH,MAAM,UAAU,kBAAkB,CACjC,SAAiB,EACjB,OAAe;IAEf,MAAM,KAAK,GAAG;QACb,SAAS;QACT,EAAE,EAAE,MAAM,EAAE;QACZ,OAAO;QACP,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACnC,CAAC;IACF,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuidv4 } from \"uuid\";\n\nimport type { DebugEvent, EventFlowDebugEvent } from \"../aiCollabApi.js\";\n\n/**\n * This file contains the types for the debug events that are emitted by the explicit strategy\n * as well as a helper functions to help create a consistent method for producing a base {@link DebugEvent}.\n */\n\n/**\n * The possible values for the `eventFlowName` field in an {@link EventFlowDebugEvent}.\n * @alpha\n */\nexport const EventFlowDebugNames = {\n\tCORE_EVENT_LOOP: \"CORE_EVENT_LOOP\",\n\tGENERATE_PLANNING_PROMPT: \"GENERATE_PLANNING_PROMPT\",\n\tGENERATE_AND_APPLY_TREE_EDIT: \"GENERATE_AND_APPLY_TREE_EDIT\",\n\tFINAL_REVIEW: \"FINAL_REVIEW\",\n} as const;\n\n/**\n * The type for possible values for the `eventFlowName` field in an {@link EventFlowDebugEvent}.\n * @alpha\n */\nexport type EventFlowDebugName =\n\t(typeof EventFlowDebugNames)[keyof typeof EventFlowDebugNames];\n\n/**\n * An edit generated by an LLM that can be applied to a given SharedTree.\n * @privateremarks TODO: We need a better solution here because don't want to expose the internal TreeEdit type here, but we need to be able to type it.\n * @alpha\n */\nexport type LlmTreeEdit = Record<string, unknown>;\n\n/**\n * An {@link EventFlowDebugEvent} for signaling the start of the ai-collab's core event loop.\n * Which makes various calls to the LLM to eventually apply edits to the users SharedTree which\n * accomplish the user's provided goal. There will be exactly 1 of these events per ai-collab function execution.\n * @alpha\n */\nexport interface CoreEventLoopStarted extends EventFlowDebugEvent {\n\teventName: \"CORE_EVENT_LOOP_STARTED\";\n\teventFlowName: typeof EventFlowDebugNames.CORE_EVENT_LOOP;\n\teventFlowStatus: \"STARTED\";\n}\n\n/**\n * An {@link EventFlowDebugEvent} for signaling the end of the ai-collab's core event loop.\n * There could be various reasons for the event loop to end, early exits and failures\n * which should be captured in the status and failureReason fields. There will be exactly 1\n * of these events per ai-collab function execution.\n * @alpha\n */\nexport interface CoreEventLoopCompleted extends EventFlowDebugEvent {\n\teventName: \"CORE_EVENT_LOOP_COMPLETED\";\n\teventFlowName: typeof EventFlowDebugNames.CORE_EVENT_LOOP;\n\teventFlowStatus: \"COMPLETED\";\n\tstatus: \"success\" | \"failure\";\n\tfailureReason?: string;\n\terrorMessage?: string;\n}\n\n// #region Planning Prompt Debug events -------------------------------\n\n/**\n * An {@link EventFlowDebugEvent} marking the initiation of the flow for prompting an LLM to generate a plan for accomplishing the user's goal.\n * There will be exactly 1 of these events per ai-collab function execution.\n * @alpha\n */\nexport interface PlanningPromptStarted extends EventFlowDebugEvent {\n\teventName: \"GENERATE_PLANNING_PROMPT_STARTED\";\n\teventFlowName: typeof EventFlowDebugNames.GENERATE_PLANNING_PROMPT;\n\teventFlowStatus: \"STARTED\";\n}\n\n/**\n * An {@link EventFlowDebugEvent} marking the completion of the flow for prompting an LLM to generate a plan for accomplishing the user's goal.\n * There will be exactly 1 of these events per ai-collab function execution.\n * @alpha\n */\nexport interface PlanningPromptCompleted<\n\tTIsLlmResponseValid = boolean,\n\tTPlan = TIsLlmResponseValid extends true ? string : undefined,\n> extends EventFlowDebugEvent {\n\teventName: \"GENERATE_PLANNING_PROMPT_COMPLETED\";\n\teventFlowName: typeof EventFlowDebugNames.GENERATE_PLANNING_PROMPT;\n\teventFlowStatus: \"COMPLETED\";\n\t/**\n\t * Whether the response produced by the LLM is an expected response.\n\t * In the event that the LLM fails to respond in an expected way, despite the API call to the LLM itself being successful, then this fields value will be `false`.\n\t *\n\t * For now, this case is limited to the LLM returning undefined as a response when it should have returned something. But in the future this could expand\n\t * to things such as invalid json.\n\t */\n\tisLlmResponseValid: TIsLlmResponseValid;\n\t/**\n\t * The plan generated by the LLM. If the `wasLlmResponseValid` field is `false` then this will be undefined, otherwise it will be a string.\n\t */\n\tllmGeneratedPlan: TPlan;\n}\n\n// #endregion Planning Prompt Debug events ----------------------------------------------------------\n\n// #region Generate And Apply Tree Edit Debug events ------------------\n\n/**\n * An {@link EventFlowDebugEvent} marking the initiation of the flow for prompting an LLM to\n * generate an {@link LlmTreeEdit} to the users Shared Tree based on the users initial ask.\n * It is expected that the LLM will generate multiple of these events when it must generate multiple tree edits to satisfy the user request\n * @alpha\n */\nexport interface GenerateTreeEditStarted extends EventFlowDebugEvent {\n\teventName: \"GENERATE_TREE_EDIT_STARTED\";\n\teventFlowName: typeof EventFlowDebugNames.GENERATE_AND_APPLY_TREE_EDIT;\n\teventFlowStatus: \"STARTED\";\n\tllmPrompt: string;\n}\n\n/**\n * An {@link EventFlowDebugEvent} marking the completion of the flow for prompting an LLM to\n * generate an {@link LlmTreeEdit} to the users Shared Tree based on the users initial ask.\n * It is expected that the LLM will generate multiple of these events when it must generate multiple tree edits to satisfy the user request\n * @alpha\n */\nexport interface GenerateTreeEditCompleted<\n\tTIsLlmResponseValid = boolean,\n\tTEdit = TIsLlmResponseValid extends true ? LlmTreeEdit | null : undefined,\n> extends EventFlowDebugEvent {\n\teventName: \"GENERATE_TREE_EDIT_COMPLETED\";\n\teventFlowName: typeof EventFlowDebugNames.GENERATE_AND_APPLY_TREE_EDIT;\n\teventFlowStatus: \"COMPLETED\";\n\t/**\n\t * Whether the response produced by the LLM is an expected response.\n\t * In the event that the LLM fails to respond in an expected way, despite the API call to the LLM itself being successful, then this fields value will be `false`.\n\t *\n\t * For now, this case is limited to the LLM returning undefined as a response when it should have returned something. But in the future this could expand\n\t * to things such as invalid json.\n\t */\n\tisLlmResponseValid: TIsLlmResponseValid;\n\t/**\n\t * If the `isLlmResponseValid` field value is `true` then this be one of two following values returned by the LLM:\n\t * 1. An edit that can be applied to a SharedTree to further accomplish the user's goal.\n\t * 2. `null` if the LLM decides no more edits are necessary.\n\t *\n\t * If the `isLlmResponseValid` field is `false` then this field will be `undefined`.\n\t */\n\tllmGeneratedEdit: TEdit;\n}\n\n/**\n * An {@link EventFlowDebugEvent} marking the successful application of an edit generated by the LLM to a SharedTree.\n * @alpha\n */\nexport interface ApplyEditSuccess extends EventFlowDebugEvent {\n\teventName: \"APPLIED_EDIT_SUCCESS\";\n\teventFlowName: typeof EventFlowDebugNames.GENERATE_AND_APPLY_TREE_EDIT;\n\teventFlowStatus: \"IN_PROGRESS\";\n\t/**\n\t * A unique id that will be shared across all debug events that are part of the same event flow.\n\t */\n\teventFlowTraceId: string;\n\t/**\n\t * The {@link LlmTreeEdit} generated by the LLM.\n\t */\n\tedit: LlmTreeEdit;\n}\n\n/**\n * An {@link EventFlowDebugEvent} marking the failure of applying an edit generated by the LLM to a SharedTree.\n * @alpha\n */\nexport interface ApplyEditFailure extends EventFlowDebugEvent {\n\teventName: \"APPLIED_EDIT_FAILURE\";\n\teventFlowName: typeof EventFlowDebugNames.GENERATE_AND_APPLY_TREE_EDIT;\n\teventFlowStatus: \"IN_PROGRESS\";\n\t/**\n\t * A unique id that will be shared across all debug events that are part of the same event flow.\n\t */\n\teventFlowTraceId: string;\n\t/**\n\t * The {@link LlmTreeEdit} generated by the LLM.\n\t */\n\tedit: LlmTreeEdit;\n\t/**\n\t * The error message that was thrown when attempting to apply the edit.\n\t */\n\terrorMessage: string;\n\t/**\n\t * The total number of errors that have occurred up until this point, not including this error.\n\t */\n\tsequentialErrorCount: number;\n}\n\n// #endregion Generate And Apply Tree Edit Debug events ----------------------\n\n// #region Generate Final Review Debug events -------------------------\n\n/**\n * An {@link EventFlowDebugEvent} marking the initiation of the flow for prompting an LLM to complete a final review of its edits\n * and determine whether the user's goal was accomplished.\n * @alpha\n */\nexport interface FinalReviewStarted extends EventFlowDebugEvent {\n\teventName: \"FINAL_REVIEW_STARTED\";\n\teventFlowName: typeof EventFlowDebugNames.FINAL_REVIEW;\n\teventFlowStatus: \"STARTED\";\n\t/**\n\t * The prompt sent to the LLM to complete its final review of the edits its made.\n\t */\n\tllmPrompt: string;\n}\n\n/**\n * An {@link EventFlowDebugEvent} marking the end of the flow for prompting an LLM to complete a final review of its edits\n * and determine whether the user's goal was accomplished.\n * @alpha\n */\nexport interface FinalReviewCompleted<\n\tTIsLlmResponseValid = boolean,\n\tTReviewResponse = TIsLlmResponseValid extends true ? \"yes\" | \"no\" : undefined,\n> extends EventFlowDebugEvent {\n\teventName: \"FINAL_REVIEW_COMPLETED\";\n\teventFlowName: typeof EventFlowDebugNames.FINAL_REVIEW;\n\teventFlowStatus: \"COMPLETED\";\n\t/**\n\t * Whether the response produced by the LLM is an expected response.\n\t * In the event that the LLM fails to respond in an expected way, despite the API call to the LLM itself being successful, then this fields value will be `false`.\n\t *\n\t * For now, this case is limited to the LLM returning undefined as a response when it should have returned something. But in the future this could expand\n\t * to things such as invalid json.\n\t */\n\tisLlmResponseValid: TIsLlmResponseValid;\n\t/**\n\t * Whether the Llm believes the user's ask was accomplished, based on the Edits is has already generated and applied.\n\t * If the `status` field is `false` then this field value will be `undefined`, otherwise it will be either \"yes\" or \"no\"\n\t */\n\tdidLlmAccomplishGoal: TReviewResponse;\n}\n\n// #endregion Generate Final Review Debug events ----------------------\n\n/**\n * An {@link DebugEvent} for an API call directly to a LLM.\n * @alpha\n */\nexport interface LlmApiCallDebugEvent extends DebugEvent {\n\teventName: \"LLM_API_CALL\";\n\t/**\n\t * The event flow name that made this LLM API call.\n\t */\n\ttriggeringEventFlowName: EventFlowDebugName;\n\t/**\n\t * The unique id that will be shared across all debug events that are part of the same event flow.\n\t * @remarks This can be used to correlate all debug events that are part of the same event flow.\n\t */\n\teventFlowTraceId: string;\n\t/**\n\t * The LLM model name that was used for the API call.\n\t */\n\tmodelName: string;\n\t/**\n\t * The request parameters sent in the API call to the LLM. (Not the HTTP request parameters such as headers, etc.)\n\t */\n\trequestParams: unknown;\n\t/**\n\t * The raw response from the LLM.\n\t */\n\tresponse: unknown;\n\t/**\n\t * The total number of tokens used in the API call to the LLM.\n\t */\n\ttokenUsage?: {\n\t\tpromptTokens: number;\n\t\tcompletionTokens: number;\n\t};\n}\n\n/**\n * Creates a base {@link DebugEvent}.\n */\nexport function generateDebugEvent<Tevent extends string>(\n\teventName: Tevent,\n\ttraceId: string,\n): DebugEvent & { eventName: Tevent } {\n\tconst event = {\n\t\teventName,\n\t\tid: uuidv4(),\n\t\ttraceId,\n\t\ttimestamp: new Date().toISOString(),\n\t};\n\treturn event;\n}\n"]}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { type TreeNode } from "@fluidframework/tree/internal";
|
|
6
|
-
import type { OpenAiClientOptions, TokenLimits, TokenUsage } from "../aiCollabApi.js";
|
|
6
|
+
import type { DebugEventLogHandler, OpenAiClientOptions, TokenLimits, TokenUsage } from "../aiCollabApi.js";
|
|
7
|
+
export type { ApplyEditFailure, ApplyEditSuccess, CoreEventLoopCompleted, CoreEventLoopStarted, FinalReviewCompleted, FinalReviewStarted, GenerateTreeEditCompleted, GenerateTreeEditStarted, LlmApiCallDebugEvent, PlanningPromptCompleted, PlanningPromptStarted, LlmTreeEdit, EventFlowDebugName, EventFlowDebugNames, } from "./debugEvents.js";
|
|
7
8
|
/**
|
|
8
9
|
* {@link generateTreeEdits} options.
|
|
9
10
|
*
|
|
@@ -24,7 +25,7 @@ export interface GenerateTreeEditsOptions {
|
|
|
24
25
|
};
|
|
25
26
|
finalReviewStep?: boolean;
|
|
26
27
|
validator?: (newContent: TreeNode) => void;
|
|
27
|
-
|
|
28
|
+
debugEventLogHandler?: DebugEventLogHandler;
|
|
28
29
|
planningStep?: boolean;
|
|
29
30
|
}
|
|
30
31
|
interface GenerateTreeEditsSuccessResponse {
|
|
@@ -33,7 +34,7 @@ interface GenerateTreeEditsSuccessResponse {
|
|
|
33
34
|
}
|
|
34
35
|
interface GenerateTreeEditsErrorResponse {
|
|
35
36
|
status: "failure" | "partial-failure";
|
|
36
|
-
errorMessage: "tokenLimitExceeded" | "tooManyErrors" | "tooManyModelCalls" | "aborted";
|
|
37
|
+
errorMessage: "tokenLimitExceeded" | "tooManyErrors" | "tooManyModelCalls" | "aborted" | "unexpectedError";
|
|
37
38
|
tokensUsed: TokenUsage;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
@@ -47,5 +48,4 @@ interface GenerateTreeEditsErrorResponse {
|
|
|
47
48
|
* @internal
|
|
48
49
|
*/
|
|
49
50
|
export declare function generateTreeEdits(options: GenerateTreeEditsOptions): Promise<GenerateTreeEditsSuccessResponse | GenerateTreeEditsErrorResponse>;
|
|
50
|
-
export {};
|
|
51
51
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/explicit-strategy/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/explicit-strategy/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAIN,KAAK,QAAQ,EACb,MAAM,+BAA+B,CAAC;AAUvC,OAAO,KAAK,EACX,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,MAAM,mBAAmB,CAAC;AAgC3B,YAAY,EACX,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,EACrB,WAAW,EACX,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,kBAAkB,CAAC;AAE1B;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACxC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE;QACP,iBAAiB,EAAE,MAAM,CAAC;QAC1B,OAAO,EAAE,MAAM,CAAC;KACh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