@midscene/core 0.28.12-beta-20250923124052.0 → 0.28.12-beta-20250923124135.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/dist/es/agent/agent.mjs +1 -1
- package/dist/es/agent/agent.mjs.map +1 -1
- package/dist/es/agent/tasks.mjs +160 -45
- package/dist/es/agent/tasks.mjs.map +1 -1
- package/dist/es/agent/utils.mjs +1 -1
- package/dist/es/ai-model/index.mjs +2 -3
- package/dist/es/ai-model/llm-planning.mjs +12 -44
- package/dist/es/ai-model/llm-planning.mjs.map +1 -1
- package/dist/es/ai-model/prompt/llm-planning.mjs +61 -7
- package/dist/es/ai-model/prompt/llm-planning.mjs.map +1 -1
- package/dist/es/ai-model/service-caller/index.mjs.map +1 -1
- package/dist/es/ai-model/ui-tars-planning.mjs +18 -40
- package/dist/es/ai-model/ui-tars-planning.mjs.map +1 -1
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/types.mjs.map +1 -1
- package/dist/es/utils.mjs +2 -2
- package/dist/lib/agent/agent.js +1 -1
- package/dist/lib/agent/agent.js.map +1 -1
- package/dist/lib/agent/tasks.js +159 -44
- package/dist/lib/agent/tasks.js.map +1 -1
- package/dist/lib/agent/utils.js +1 -1
- package/dist/lib/ai-model/index.js +4 -8
- package/dist/lib/ai-model/llm-planning.js +11 -43
- package/dist/lib/ai-model/llm-planning.js.map +1 -1
- package/dist/lib/ai-model/prompt/llm-planning.js +67 -7
- package/dist/lib/ai-model/prompt/llm-planning.js.map +1 -1
- package/dist/lib/ai-model/service-caller/index.js.map +1 -1
- package/dist/lib/ai-model/ui-tars-planning.js +20 -42
- package/dist/lib/ai-model/ui-tars-planning.js.map +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/utils.js +2 -2
- package/dist/types/agent/tasks.d.ts +17 -4
- package/dist/types/ai-model/index.d.ts +1 -2
- package/dist/types/ai-model/llm-planning.d.ts +1 -2
- package/dist/types/ai-model/prompt/llm-planning.d.ts +6 -0
- package/dist/types/ai-model/service-caller/index.d.ts +1 -1
- package/dist/types/ai-model/ui-tars-planning.d.ts +18 -6
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types.d.ts +1 -0
- package/dist/types/yaml.d.ts +11 -1
- package/package.json +3 -3
- package/dist/es/ai-model/conversation-history.mjs +0 -58
- package/dist/es/ai-model/conversation-history.mjs.map +0 -1
- package/dist/lib/ai-model/conversation-history.js +0 -92
- package/dist/lib/ai-model/conversation-history.js.map +0 -1
- package/dist/types/ai-model/conversation-history.d.ts +0 -18
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ChatCompletionMessageParam } from '../ai-model';
|
|
1
2
|
import type { AbstractInterface } from '../device';
|
|
2
3
|
import { type DetailedLocateParam, type ExecutionTaskApply, type ExecutionTaskProgressOptions, Executor, type Insight, type InsightExtractOption, type InsightExtractParam, type MidsceneYamlFlowItem, type PlanningAction, type PlanningActionParamWaitFor, type PlanningLocateParam, type TMultimodalPrompt, type TUserPrompt } from '../index';
|
|
3
4
|
import { type IModelConfig } from '@midscene/shared/env';
|
|
@@ -12,7 +13,7 @@ export declare class TaskExecutor {
|
|
|
12
13
|
interface: AbstractInterface;
|
|
13
14
|
insight: Insight;
|
|
14
15
|
taskCache?: TaskCache;
|
|
15
|
-
|
|
16
|
+
conversationHistory: ChatCompletionMessageParam[];
|
|
16
17
|
onTaskStartCallback?: ExecutionTaskProgressOptions['onTaskStart'];
|
|
17
18
|
replanningCycleLimit?: number;
|
|
18
19
|
get page(): AbstractInterface;
|
|
@@ -31,17 +32,29 @@ export declare class TaskExecutor {
|
|
|
31
32
|
loadYamlFlowAsPlanning(userInstruction: string, yamlString: string): Promise<{
|
|
32
33
|
executor: Executor;
|
|
33
34
|
}>;
|
|
34
|
-
private
|
|
35
|
+
private planningTaskFromPrompt;
|
|
36
|
+
private planningTaskToGoal;
|
|
35
37
|
runPlans(title: string, plans: PlanningAction[], modelConfig: IModelConfig): Promise<ExecutionResult>;
|
|
36
|
-
private getReplanningCycleLimit;
|
|
37
38
|
action(userPrompt: string, modelConfig: IModelConfig, actionContext?: string): Promise<ExecutionResult<{
|
|
38
39
|
yamlFlow?: MidsceneYamlFlowItem[];
|
|
39
40
|
} | undefined>>;
|
|
41
|
+
actionToGoal(userPrompt: string, modelConfig: IModelConfig): Promise<ExecutionResult<{
|
|
42
|
+
yamlFlow?: MidsceneYamlFlowItem[];
|
|
43
|
+
} | undefined>>;
|
|
40
44
|
private createTypeQueryTask;
|
|
41
45
|
createTypeQueryExecution<T>(type: 'Query' | 'Boolean' | 'Number' | 'String' | 'Assert', demand: InsightExtractParam, modelConfig: IModelConfig, opt?: InsightExtractOption, multimodalPrompt?: TMultimodalPrompt): Promise<ExecutionResult<T>>;
|
|
42
46
|
assert(assertion: TUserPrompt, modelConfig: IModelConfig, opt?: InsightExtractOption): Promise<ExecutionResult<boolean>>;
|
|
47
|
+
/**
|
|
48
|
+
* Append a message to the conversation history
|
|
49
|
+
* For user messages with images:
|
|
50
|
+
* - Keep max 4 user image messages in history
|
|
51
|
+
* - Remove oldest user image message when limit reached
|
|
52
|
+
* For assistant messages:
|
|
53
|
+
* - Simply append to history
|
|
54
|
+
* @param conversationHistory Message to append
|
|
55
|
+
*/
|
|
56
|
+
private appendConversationHistory;
|
|
43
57
|
private appendErrorPlan;
|
|
44
|
-
taskForSleep(timeMs: number, modelConfig: IModelConfig): Promise<ExecutionTaskApply<any, any, any, any>>;
|
|
45
58
|
waitFor(assertion: TUserPrompt, opt: PlanningActionParamWaitFor, modelConfig: IModelConfig): Promise<ExecutionResult<void>>;
|
|
46
59
|
}
|
|
47
60
|
export {};
|
|
@@ -7,7 +7,6 @@ export type { ChatCompletionMessageParam } from 'openai/resources/index';
|
|
|
7
7
|
export { AiLocateElement, AiExtractElementInfo, AiLocateSection, } from './inspect';
|
|
8
8
|
export { plan } from './llm-planning';
|
|
9
9
|
export { adaptBboxToRect } from './common';
|
|
10
|
-
export {
|
|
11
|
-
export { ConversationHistory, type ConversationHistoryOptions, } from './conversation-history';
|
|
10
|
+
export { vlmPlanning, resizeImageForUiTars } from './ui-tars-planning';
|
|
12
11
|
export { AIActionType, type AIArgs } from './common';
|
|
13
12
|
export { getMidsceneLocationSchema, type MidsceneLocationResultType, PointSchema, SizeSchema, RectSchema, TMultimodalPromptSchema, TUserPromptSchema, type TMultimodalPrompt, type TUserPrompt, findAllMidsceneLocatorField, dumpActionParam, loadActionParam, } from './common';
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { DeviceAction, InterfaceType, PlanningAIResponse, UIContext } from '../types';
|
|
2
2
|
import type { IModelConfig } from '@midscene/shared/env';
|
|
3
|
-
import type { ConversationHistory } from './conversation-history';
|
|
4
3
|
export declare function plan(userInstruction: string, opts: {
|
|
5
4
|
context: UIContext;
|
|
6
5
|
interfaceType: InterfaceType;
|
|
7
6
|
actionSpace: DeviceAction<any>[];
|
|
7
|
+
log?: string;
|
|
8
8
|
actionContext?: string;
|
|
9
9
|
modelConfig: IModelConfig;
|
|
10
|
-
conversationHistory?: ConversationHistory;
|
|
11
10
|
}): Promise<PlanningAIResponse>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DeviceAction } from '../../types';
|
|
2
|
+
import { PromptTemplate } from '@langchain/core/prompts';
|
|
2
3
|
import type { TVlModeTypes } from '@midscene/shared/env';
|
|
3
4
|
import type { ResponseFormatJSONSchema } from 'openai/resources/index';
|
|
4
5
|
export declare const descriptionForAction: (action: DeviceAction<any>, locatorSchemaTypeDescription: string) => string;
|
|
@@ -7,3 +8,8 @@ export declare function systemPromptToTaskPlanning({ actionSpace, vlMode, }: {
|
|
|
7
8
|
vlMode: TVlModeTypes | undefined;
|
|
8
9
|
}): Promise<string>;
|
|
9
10
|
export declare const planSchema: ResponseFormatJSONSchema;
|
|
11
|
+
export declare const generateTaskBackgroundContext: (userInstruction: string, log?: string, userActionContext?: string) => string;
|
|
12
|
+
export declare const automationUserPrompt: (vlMode: TVlModeTypes | undefined) => PromptTemplate<{
|
|
13
|
+
pageDescription: any;
|
|
14
|
+
taskBackgroundContext: any;
|
|
15
|
+
}, any>;
|
|
@@ -13,7 +13,7 @@ export declare function callAI(messages: ChatCompletionMessageParam[], AIActionT
|
|
|
13
13
|
isStreamed: boolean;
|
|
14
14
|
}>;
|
|
15
15
|
export declare const getResponseFormat: (modelName: string, AIActionTypeValue: AIActionType) => OpenAI.ChatCompletionCreateParams["response_format"] | OpenAI.ResponseFormatJSONObject;
|
|
16
|
-
export declare function callAIWithObjectResponse<T>(messages:
|
|
16
|
+
export declare function callAIWithObjectResponse<T>(messages: AIArgs, AIActionTypeValue: AIActionType, modelConfig: IModelConfig): Promise<{
|
|
17
17
|
content: T;
|
|
18
18
|
usage?: AIUsageInfo;
|
|
19
19
|
}>;
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AIUsageInfo, MidsceneYamlFlowItem, PlanningAction, Size } from '../types';
|
|
2
2
|
import { type IModelConfig, UITarsModelVersion } from '@midscene/shared/env';
|
|
3
|
-
import
|
|
3
|
+
import { actionParser } from '@ui-tars/action-parser';
|
|
4
|
+
import type { ChatCompletionMessageParam } from 'openai/resources/index';
|
|
4
5
|
type ActionType = 'click' | 'drag' | 'type' | 'hotkey' | 'finished' | 'scroll' | 'wait';
|
|
5
|
-
export declare function
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export declare function vlmPlanning(options: {
|
|
7
|
+
userInstruction: string;
|
|
8
|
+
conversationHistory: ChatCompletionMessageParam[];
|
|
9
|
+
size: {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
8
13
|
modelConfig: IModelConfig;
|
|
9
|
-
}): Promise<
|
|
14
|
+
}): Promise<{
|
|
15
|
+
actions: PlanningAction<any>[];
|
|
16
|
+
actionsFromModel: ReturnType<typeof actionParser>['parsed'];
|
|
17
|
+
action_summary: string;
|
|
18
|
+
yamlFlow?: MidsceneYamlFlowItem[];
|
|
19
|
+
usage?: AIUsageInfo;
|
|
20
|
+
rawResponse?: string;
|
|
21
|
+
}>;
|
|
10
22
|
interface BaseAction {
|
|
11
23
|
action_type: ActionType;
|
|
12
24
|
action_inputs: Record<string, any>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ export type * from './types';
|
|
|
8
8
|
export { z };
|
|
9
9
|
export default Insight;
|
|
10
10
|
export { Executor, Insight, getVersion };
|
|
11
|
-
export type { MidsceneYamlScript, MidsceneYamlTask, MidsceneYamlFlowItem, MidsceneYamlConfigResult, LocateOption, DetailedLocateParam, } from './yaml';
|
|
11
|
+
export type { MidsceneYamlScript, MidsceneYamlTask, MidsceneYamlFlowItem, MidsceneYamlConfigResult, MidsceneYamlConfig, MidsceneYamlScriptWebEnv, MidsceneYamlScriptAndroidEnv, MidsceneYamlScriptIOSEnv, MidsceneYamlScriptEnv, LocateOption, DetailedLocateParam, } from './yaml';
|
|
12
12
|
export { Agent, type AgentOpt, createAgent } from './agent';
|
package/dist/types/types.d.ts
CHANGED
|
@@ -318,6 +318,7 @@ export type ExecutionTaskLogApply<LogParam = {
|
|
|
318
318
|
export type ExecutionTaskLog = ExecutionTask<ExecutionTaskLogApply>;
|
|
319
319
|
export type ExecutionTaskPlanningApply = ExecutionTaskApply<'Planning', {
|
|
320
320
|
userInstruction: string;
|
|
321
|
+
log?: string;
|
|
321
322
|
}, PlanningAIResponse>;
|
|
322
323
|
export type ExecutionTaskPlanning = ExecutionTask<ExecutionTaskPlanningApply>;
|
|
323
324
|
export interface GroupedActionDump {
|
package/dist/types/yaml.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface MidsceneYamlScript {
|
|
|
32
32
|
target?: MidsceneYamlScriptWebEnv;
|
|
33
33
|
web?: MidsceneYamlScriptWebEnv;
|
|
34
34
|
android?: MidsceneYamlScriptAndroidEnv;
|
|
35
|
+
ios?: MidsceneYamlScriptIOSEnv;
|
|
35
36
|
interface?: MidsceneYamlScriptEnvGeneralInterface;
|
|
36
37
|
config?: MidsceneYamlScriptConfig;
|
|
37
38
|
agent?: MidsceneYamlScriptAgentOpt;
|
|
@@ -73,7 +74,15 @@ export interface MidsceneYamlScriptAndroidEnv extends MidsceneYamlScriptConfig {
|
|
|
73
74
|
deviceId?: string;
|
|
74
75
|
launch?: string;
|
|
75
76
|
}
|
|
76
|
-
export
|
|
77
|
+
export interface MidsceneYamlScriptIOSEnv extends MidsceneYamlScriptConfig {
|
|
78
|
+
deviceId?: string;
|
|
79
|
+
wdaPort?: number;
|
|
80
|
+
wdaHost?: string;
|
|
81
|
+
autoDismissKeyboard?: boolean;
|
|
82
|
+
keyboardDismissStrategy?: 'done-first' | 'escape-first';
|
|
83
|
+
launch?: string;
|
|
84
|
+
}
|
|
85
|
+
export type MidsceneYamlScriptEnv = MidsceneYamlScriptWebEnv | MidsceneYamlScriptAndroidEnv | MidsceneYamlScriptIOSEnv;
|
|
77
86
|
export interface MidsceneYamlFlowItemAIAction {
|
|
78
87
|
ai?: string;
|
|
79
88
|
aiAction?: string;
|
|
@@ -143,6 +152,7 @@ export interface MidsceneYamlConfig {
|
|
|
143
152
|
shareBrowserContext?: boolean;
|
|
144
153
|
web?: MidsceneYamlScriptWebEnv;
|
|
145
154
|
android?: MidsceneYamlScriptAndroidEnv;
|
|
155
|
+
ios?: MidsceneYamlScriptIOSEnv;
|
|
146
156
|
files: string[];
|
|
147
157
|
headed?: boolean;
|
|
148
158
|
keepWindow?: boolean;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/core",
|
|
3
3
|
"description": "Automate browser actions, extract data, and perform assertions using AI. It offers JavaScript SDK, Chrome extension, and support for scripting in YAML. See https://midscenejs.com/ for details.",
|
|
4
|
-
"version": "0.28.12-beta-
|
|
4
|
+
"version": "0.28.12-beta-20250923124135.0",
|
|
5
5
|
"repository": "https://github.com/web-infra-dev/midscene",
|
|
6
6
|
"homepage": "https://midscenejs.com/",
|
|
7
7
|
"main": "./dist/lib/index.js",
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"zod": "3.24.3",
|
|
88
88
|
"semver": "7.5.2",
|
|
89
89
|
"js-yaml": "4.1.0",
|
|
90
|
-
"@midscene/recorder": "0.28.12-beta-
|
|
91
|
-
"@midscene/shared": "0.28.12-beta-
|
|
90
|
+
"@midscene/recorder": "0.28.12-beta-20250923124135.0",
|
|
91
|
+
"@midscene/shared": "0.28.12-beta-20250923124135.0"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
94
|
"@microsoft/api-extractor": "^7.52.10",
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
3
|
-
value: value,
|
|
4
|
-
enumerable: true,
|
|
5
|
-
configurable: true,
|
|
6
|
-
writable: true
|
|
7
|
-
});
|
|
8
|
-
else obj[key] = value;
|
|
9
|
-
return obj;
|
|
10
|
-
}
|
|
11
|
-
var _computedKey;
|
|
12
|
-
_computedKey = Symbol.iterator;
|
|
13
|
-
let _computedKey1 = _computedKey;
|
|
14
|
-
class ConversationHistory {
|
|
15
|
-
append(message) {
|
|
16
|
-
if ('user' === message.role) this.pruneOldestUserMessageIfNecessary();
|
|
17
|
-
this.messages.push(message);
|
|
18
|
-
}
|
|
19
|
-
seed(messages) {
|
|
20
|
-
this.reset();
|
|
21
|
-
messages.forEach((message)=>{
|
|
22
|
-
this.append(message);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
reset() {
|
|
26
|
-
this.messages.length = 0;
|
|
27
|
-
}
|
|
28
|
-
snapshot() {
|
|
29
|
-
return [
|
|
30
|
-
...this.messages
|
|
31
|
-
];
|
|
32
|
-
}
|
|
33
|
-
get length() {
|
|
34
|
-
return this.messages.length;
|
|
35
|
-
}
|
|
36
|
-
[_computedKey1]() {
|
|
37
|
-
return this.messages[Symbol.iterator]();
|
|
38
|
-
}
|
|
39
|
-
toJSON() {
|
|
40
|
-
return this.snapshot();
|
|
41
|
-
}
|
|
42
|
-
pruneOldestUserMessageIfNecessary() {
|
|
43
|
-
const userMessages = this.messages.filter((item)=>'user' === item.role);
|
|
44
|
-
if (userMessages.length < this.maxUserImageMessages) return;
|
|
45
|
-
const firstUserMessageIndex = this.messages.findIndex((item)=>'user' === item.role);
|
|
46
|
-
if (firstUserMessageIndex >= 0) this.messages.splice(firstUserMessageIndex, 1);
|
|
47
|
-
}
|
|
48
|
-
constructor(options){
|
|
49
|
-
var _options_initialMessages;
|
|
50
|
-
_define_property(this, "maxUserImageMessages", void 0);
|
|
51
|
-
_define_property(this, "messages", []);
|
|
52
|
-
this.maxUserImageMessages = (null == options ? void 0 : options.maxUserImageMessages) ?? 4;
|
|
53
|
-
if (null == options ? void 0 : null == (_options_initialMessages = options.initialMessages) ? void 0 : _options_initialMessages.length) this.seed(options.initialMessages);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export { ConversationHistory };
|
|
57
|
-
|
|
58
|
-
//# sourceMappingURL=conversation-history.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ai-model/conversation-history.mjs","sources":["webpack://@midscene/core/./src/ai-model/conversation-history.ts"],"sourcesContent":["import type { ChatCompletionMessageParam } from 'openai/resources/index';\n\nexport interface ConversationHistoryOptions {\n maxUserImageMessages?: number;\n initialMessages?: ChatCompletionMessageParam[];\n}\n\nexport class ConversationHistory {\n private readonly maxUserImageMessages: number;\n private readonly messages: ChatCompletionMessageParam[] = [];\n\n constructor(options?: ConversationHistoryOptions) {\n this.maxUserImageMessages = options?.maxUserImageMessages ?? 4;\n if (options?.initialMessages?.length) {\n this.seed(options.initialMessages);\n }\n }\n\n append(message: ChatCompletionMessageParam) {\n if (message.role === 'user') {\n this.pruneOldestUserMessageIfNecessary();\n }\n\n this.messages.push(message);\n }\n\n seed(messages: ChatCompletionMessageParam[]) {\n this.reset();\n messages.forEach((message) => {\n this.append(message);\n });\n }\n\n reset() {\n this.messages.length = 0;\n }\n\n snapshot(): ChatCompletionMessageParam[] {\n return [...this.messages];\n }\n\n get length(): number {\n return this.messages.length;\n }\n\n [Symbol.iterator](): IterableIterator<ChatCompletionMessageParam> {\n return this.messages[Symbol.iterator]();\n }\n\n toJSON(): ChatCompletionMessageParam[] {\n return this.snapshot();\n }\n\n private pruneOldestUserMessageIfNecessary() {\n const userMessages = this.messages.filter((item) => item.role === 'user');\n if (userMessages.length < this.maxUserImageMessages) {\n return;\n }\n\n const firstUserMessageIndex = this.messages.findIndex(\n (item) => item.role === 'user',\n );\n\n if (firstUserMessageIndex >= 0) {\n this.messages.splice(firstUserMessageIndex, 1);\n }\n }\n}\n"],"names":["Symbol","ConversationHistory","message","messages","userMessages","item","firstUserMessageIndex","options","_options_initialMessages"],"mappings":";;;;;;;;;;;eA6CGA,OAAO,QAAQ;;AAtCX,MAAMC;IAWX,OAAOC,OAAmC,EAAE;QAC1C,IAAIA,AAAiB,WAAjBA,QAAQ,IAAI,EACd,IAAI,CAAC,iCAAiC;QAGxC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAACA;IACrB;IAEA,KAAKC,QAAsC,EAAE;QAC3C,IAAI,CAAC,KAAK;QACVA,SAAS,OAAO,CAAC,CAACD;YAChB,IAAI,CAAC,MAAM,CAACA;QACd;IACF;IAEA,QAAQ;QACN,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG;IACzB;IAEA,WAAyC;QACvC,OAAO;eAAI,IAAI,CAAC,QAAQ;SAAC;IAC3B;IAEA,IAAI,SAAiB;QACnB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM;IAC7B;IAEA,CAAC,cAAD,GAAkE;QAChE,OAAO,IAAI,CAAC,QAAQ,CAACF,OAAO,QAAQ,CAAC;IACvC;IAEA,SAAuC;QACrC,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEQ,oCAAoC;QAC1C,MAAMI,eAAe,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAACC,OAASA,AAAc,WAAdA,KAAK,IAAI;QAC7D,IAAID,aAAa,MAAM,GAAG,IAAI,CAAC,oBAAoB,EACjD;QAGF,MAAME,wBAAwB,IAAI,CAAC,QAAQ,CAAC,SAAS,CACnD,CAACD,OAASA,AAAc,WAAdA,KAAK,IAAI;QAGrB,IAAIC,yBAAyB,GAC3B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAACA,uBAAuB;IAEhD;IAvDA,YAAYC,OAAoC,CAAE;YAE5CC;QALN,uBAAiB,wBAAjB;QACA,uBAAiB,YAAyC,EAAE;QAG1D,IAAI,CAAC,oBAAoB,GAAGD,AAAAA,CAAAA,QAAAA,UAAAA,KAAAA,IAAAA,QAAS,oBAAoB,AAAD,KAAK;QAC7D,IAAIC,QAAAA,UAAAA,KAAAA,IAAAA,QAAAA,CAAAA,2BAAAA,QAAS,eAAe,AAAD,IAAvBA,KAAAA,IAAAA,yBAA0B,MAAM,EAClC,IAAI,CAAC,IAAI,CAACD,QAAQ,eAAe;IAErC;AAmDF"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: definition[key]
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
})();
|
|
11
|
-
(()=>{
|
|
12
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
-
})();
|
|
14
|
-
(()=>{
|
|
15
|
-
__webpack_require__.r = (exports1)=>{
|
|
16
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
-
value: 'Module'
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
-
value: true
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
var __webpack_exports__ = {};
|
|
25
|
-
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
ConversationHistory: ()=>ConversationHistory
|
|
28
|
-
});
|
|
29
|
-
function _define_property(obj, key, value) {
|
|
30
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
31
|
-
value: value,
|
|
32
|
-
enumerable: true,
|
|
33
|
-
configurable: true,
|
|
34
|
-
writable: true
|
|
35
|
-
});
|
|
36
|
-
else obj[key] = value;
|
|
37
|
-
return obj;
|
|
38
|
-
}
|
|
39
|
-
var _computedKey;
|
|
40
|
-
_computedKey = Symbol.iterator;
|
|
41
|
-
let _computedKey1 = _computedKey;
|
|
42
|
-
class ConversationHistory {
|
|
43
|
-
append(message) {
|
|
44
|
-
if ('user' === message.role) this.pruneOldestUserMessageIfNecessary();
|
|
45
|
-
this.messages.push(message);
|
|
46
|
-
}
|
|
47
|
-
seed(messages) {
|
|
48
|
-
this.reset();
|
|
49
|
-
messages.forEach((message)=>{
|
|
50
|
-
this.append(message);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
reset() {
|
|
54
|
-
this.messages.length = 0;
|
|
55
|
-
}
|
|
56
|
-
snapshot() {
|
|
57
|
-
return [
|
|
58
|
-
...this.messages
|
|
59
|
-
];
|
|
60
|
-
}
|
|
61
|
-
get length() {
|
|
62
|
-
return this.messages.length;
|
|
63
|
-
}
|
|
64
|
-
[_computedKey1]() {
|
|
65
|
-
return this.messages[Symbol.iterator]();
|
|
66
|
-
}
|
|
67
|
-
toJSON() {
|
|
68
|
-
return this.snapshot();
|
|
69
|
-
}
|
|
70
|
-
pruneOldestUserMessageIfNecessary() {
|
|
71
|
-
const userMessages = this.messages.filter((item)=>'user' === item.role);
|
|
72
|
-
if (userMessages.length < this.maxUserImageMessages) return;
|
|
73
|
-
const firstUserMessageIndex = this.messages.findIndex((item)=>'user' === item.role);
|
|
74
|
-
if (firstUserMessageIndex >= 0) this.messages.splice(firstUserMessageIndex, 1);
|
|
75
|
-
}
|
|
76
|
-
constructor(options){
|
|
77
|
-
var _options_initialMessages;
|
|
78
|
-
_define_property(this, "maxUserImageMessages", void 0);
|
|
79
|
-
_define_property(this, "messages", []);
|
|
80
|
-
this.maxUserImageMessages = (null == options ? void 0 : options.maxUserImageMessages) ?? 4;
|
|
81
|
-
if (null == options ? void 0 : null == (_options_initialMessages = options.initialMessages) ? void 0 : _options_initialMessages.length) this.seed(options.initialMessages);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.ConversationHistory = __webpack_exports__.ConversationHistory;
|
|
85
|
-
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
86
|
-
"ConversationHistory"
|
|
87
|
-
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
88
|
-
Object.defineProperty(exports, '__esModule', {
|
|
89
|
-
value: true
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
//# sourceMappingURL=conversation-history.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ai-model/conversation-history.js","sources":["webpack://@midscene/core/webpack/runtime/define_property_getters","webpack://@midscene/core/webpack/runtime/has_own_property","webpack://@midscene/core/webpack/runtime/make_namespace_object","webpack://@midscene/core/./src/ai-model/conversation-history.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { ChatCompletionMessageParam } from 'openai/resources/index';\n\nexport interface ConversationHistoryOptions {\n maxUserImageMessages?: number;\n initialMessages?: ChatCompletionMessageParam[];\n}\n\nexport class ConversationHistory {\n private readonly maxUserImageMessages: number;\n private readonly messages: ChatCompletionMessageParam[] = [];\n\n constructor(options?: ConversationHistoryOptions) {\n this.maxUserImageMessages = options?.maxUserImageMessages ?? 4;\n if (options?.initialMessages?.length) {\n this.seed(options.initialMessages);\n }\n }\n\n append(message: ChatCompletionMessageParam) {\n if (message.role === 'user') {\n this.pruneOldestUserMessageIfNecessary();\n }\n\n this.messages.push(message);\n }\n\n seed(messages: ChatCompletionMessageParam[]) {\n this.reset();\n messages.forEach((message) => {\n this.append(message);\n });\n }\n\n reset() {\n this.messages.length = 0;\n }\n\n snapshot(): ChatCompletionMessageParam[] {\n return [...this.messages];\n }\n\n get length(): number {\n return this.messages.length;\n }\n\n [Symbol.iterator](): IterableIterator<ChatCompletionMessageParam> {\n return this.messages[Symbol.iterator]();\n }\n\n toJSON(): ChatCompletionMessageParam[] {\n return this.snapshot();\n }\n\n private pruneOldestUserMessageIfNecessary() {\n const userMessages = this.messages.filter((item) => item.role === 'user');\n if (userMessages.length < this.maxUserImageMessages) {\n return;\n }\n\n const firstUserMessageIndex = this.messages.findIndex(\n (item) => item.role === 'user',\n );\n\n if (firstUserMessageIndex >= 0) {\n this.messages.splice(firstUserMessageIndex, 1);\n }\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","ConversationHistory","message","messages","userMessages","item","firstUserMessageIndex","options","_options_initialMessages"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;;;;;;eCuCGG,OAAO,QAAQ;;AAtCX,MAAMC;IAWX,OAAOC,OAAmC,EAAE;QAC1C,IAAIA,AAAiB,WAAjBA,QAAQ,IAAI,EACd,IAAI,CAAC,iCAAiC;QAGxC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAACA;IACrB;IAEA,KAAKC,QAAsC,EAAE;QAC3C,IAAI,CAAC,KAAK;QACVA,SAAS,OAAO,CAAC,CAACD;YAChB,IAAI,CAAC,MAAM,CAACA;QACd;IACF;IAEA,QAAQ;QACN,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG;IACzB;IAEA,WAAyC;QACvC,OAAO;eAAI,IAAI,CAAC,QAAQ;SAAC;IAC3B;IAEA,IAAI,SAAiB;QACnB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM;IAC7B;IAEA,CAAC,cAAD,GAAkE;QAChE,OAAO,IAAI,CAAC,QAAQ,CAACF,OAAO,QAAQ,CAAC;IACvC;IAEA,SAAuC;QACrC,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEQ,oCAAoC;QAC1C,MAAMI,eAAe,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAACC,OAASA,AAAc,WAAdA,KAAK,IAAI;QAC7D,IAAID,aAAa,MAAM,GAAG,IAAI,CAAC,oBAAoB,EACjD;QAGF,MAAME,wBAAwB,IAAI,CAAC,QAAQ,CAAC,SAAS,CACnD,CAACD,OAASA,AAAc,WAAdA,KAAK,IAAI;QAGrB,IAAIC,yBAAyB,GAC3B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAACA,uBAAuB;IAEhD;IAvDA,YAAYC,OAAoC,CAAE;YAE5CC;QALN,uBAAiB,wBAAjB;QACA,uBAAiB,YAAyC,EAAE;QAG1D,IAAI,CAAC,oBAAoB,GAAGD,AAAAA,CAAAA,QAAAA,UAAAA,KAAAA,IAAAA,QAAS,oBAAoB,AAAD,KAAK;QAC7D,IAAIC,QAAAA,UAAAA,KAAAA,IAAAA,QAAAA,CAAAA,2BAAAA,QAAS,eAAe,AAAD,IAAvBA,KAAAA,IAAAA,yBAA0B,MAAM,EAClC,IAAI,CAAC,IAAI,CAACD,QAAQ,eAAe;IAErC;AAmDF"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ChatCompletionMessageParam } from 'openai/resources/index';
|
|
2
|
-
export interface ConversationHistoryOptions {
|
|
3
|
-
maxUserImageMessages?: number;
|
|
4
|
-
initialMessages?: ChatCompletionMessageParam[];
|
|
5
|
-
}
|
|
6
|
-
export declare class ConversationHistory {
|
|
7
|
-
private readonly maxUserImageMessages;
|
|
8
|
-
private readonly messages;
|
|
9
|
-
constructor(options?: ConversationHistoryOptions);
|
|
10
|
-
append(message: ChatCompletionMessageParam): void;
|
|
11
|
-
seed(messages: ChatCompletionMessageParam[]): void;
|
|
12
|
-
reset(): void;
|
|
13
|
-
snapshot(): ChatCompletionMessageParam[];
|
|
14
|
-
get length(): number;
|
|
15
|
-
[Symbol.iterator](): IterableIterator<ChatCompletionMessageParam>;
|
|
16
|
-
toJSON(): ChatCompletionMessageParam[];
|
|
17
|
-
private pruneOldestUserMessageIfNecessary;
|
|
18
|
-
}
|