@xtalpi/agentic-lab-agent-sdk 0.0.17
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/LICENSE.md +20 -0
- package/README.md +172 -0
- package/dist/agent/index.d.ts +21 -0
- package/dist/agent/index.js +30 -0
- package/dist/agent/tracer.d.ts +37 -0
- package/dist/agent/tracer.js +217 -0
- package/dist/context/context.d.ts +6 -0
- package/dist/context/context.js +9 -0
- package/dist/file/file.d.ts +25 -0
- package/dist/file/file.js +95 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +53 -0
- package/dist/message/message.d.ts +12 -0
- package/dist/message/message.js +35 -0
- package/dist/message/normalize.d.ts +4 -0
- package/dist/message/normalize.js +11 -0
- package/dist/middleware/createToolErrorCatchMiddleware.d.ts +7 -0
- package/dist/middleware/createToolErrorCatchMiddleware.js +45 -0
- package/dist/middleware/createToolMiddleware.d.ts +8 -0
- package/dist/middleware/createToolMiddleware.js +32 -0
- package/dist/middleware/index.d.ts +11 -0
- package/dist/middleware/index.js +11 -0
- package/dist/prompt/prompt.d.ts +11 -0
- package/dist/prompt/prompt.js +19 -0
- package/dist/protocal/protocal.d.ts +22 -0
- package/dist/protocal/protocal.js +118 -0
- package/dist/skill/skill.d.ts +14 -0
- package/dist/skill/skill.js +18 -0
- package/dist/stream/stream.d.ts +15 -0
- package/dist/stream/stream.js +38 -0
- package/dist/types/message/enum.d.ts +7 -0
- package/dist/types/message/enum.js +9 -0
- package/dist/types/message/index.d.ts +20 -0
- package/dist/types/message/index.js +1 -0
- package/dist/types/protocal/content/echarts.d.ts +7 -0
- package/dist/types/protocal/content/echarts.js +1 -0
- package/dist/types/protocal/content/fileLink.d.ts +14 -0
- package/dist/types/protocal/content/fileLink.js +9 -0
- package/dist/types/protocal/content/form.d.ts +49 -0
- package/dist/types/protocal/content/form.js +10 -0
- package/dist/types/protocal/content/progress.d.ts +16 -0
- package/dist/types/protocal/content/progress.js +9 -0
- package/dist/types/protocal/content/smiles.d.ts +21 -0
- package/dist/types/protocal/content/smiles.js +15 -0
- package/dist/types/protocal/content/toolCall.d.ts +16 -0
- package/dist/types/protocal/content/toolCall.js +11 -0
- package/dist/types/protocal/enum.d.ts +12 -0
- package/dist/types/protocal/enum.js +14 -0
- package/dist/types/protocal/index.d.ts +21 -0
- package/dist/types/protocal/index.js +1 -0
- package/dist/types/stream/index.d.ts +7 -0
- package/dist/types/stream/index.js +1 -0
- package/dist/types/tracer/index.d.ts +33 -0
- package/dist/types/tracer/index.js +14 -0
- package/dist/utils/error.d.ts +4 -0
- package/dist/utils/error.js +15 -0
- package/dist/utils/utils.d.ts +15 -0
- package/dist/utils/utils.js +42 -0
- package/package.json +72 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { StreamModule } from "./stream/stream.js";
|
|
2
|
+
import { ProtocolModule } from "./protocal/protocal.js";
|
|
3
|
+
import { ContextModule } from "./context/context.js";
|
|
4
|
+
import { MessageModule } from "./message/message.js";
|
|
5
|
+
import { PromptModule } from "./prompt/prompt.js";
|
|
6
|
+
import { SkillModule } from "./skill/skill.js";
|
|
7
|
+
import { FileModule } from "./file/file.js";
|
|
8
|
+
import { UtilsModule } from "./utils/utils.js";
|
|
9
|
+
import { TraceEventType } from "./types/tracer/index.js";
|
|
10
|
+
import { AgentModule } from "./agent/index.js";
|
|
11
|
+
import { MiddlewareModule } from "./middleware/index.js";
|
|
12
|
+
|
|
13
|
+
//#region src/index.ts
|
|
14
|
+
let UIEnv = /* @__PURE__ */ function(UIEnv$1) {
|
|
15
|
+
UIEnv$1["Curve"] = "Curve";
|
|
16
|
+
UIEnv$1["Common"] = "Common";
|
|
17
|
+
return UIEnv$1;
|
|
18
|
+
}({});
|
|
19
|
+
var Curve = class {
|
|
20
|
+
stream;
|
|
21
|
+
protocol;
|
|
22
|
+
context;
|
|
23
|
+
message;
|
|
24
|
+
prompt;
|
|
25
|
+
skill;
|
|
26
|
+
file;
|
|
27
|
+
utils;
|
|
28
|
+
agent;
|
|
29
|
+
middleware;
|
|
30
|
+
_uiEnv = UIEnv.Curve;
|
|
31
|
+
constructor() {
|
|
32
|
+
this.stream = new StreamModule(this);
|
|
33
|
+
this.protocol = new ProtocolModule(this);
|
|
34
|
+
this.context = new ContextModule();
|
|
35
|
+
this.message = new MessageModule(this);
|
|
36
|
+
this.file = new FileModule();
|
|
37
|
+
this.prompt = new PromptModule(this);
|
|
38
|
+
this.skill = new SkillModule(this);
|
|
39
|
+
this.utils = new UtilsModule();
|
|
40
|
+
this.agent = new AgentModule();
|
|
41
|
+
this.middleware = new MiddlewareModule();
|
|
42
|
+
}
|
|
43
|
+
setUIEnv(env) {
|
|
44
|
+
this._uiEnv = env;
|
|
45
|
+
}
|
|
46
|
+
getUIEnv() {
|
|
47
|
+
return this._uiEnv;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const curve = new Curve();
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { Curve, TraceEventType, UIEnv, curve };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChatMessageItem, ChatParams, LoadMessagesOptions } from "../types/message/index.js";
|
|
2
|
+
import { Curve } from "../index.js";
|
|
3
|
+
|
|
4
|
+
//#region src/message/message.d.ts
|
|
5
|
+
declare class MessageModule {
|
|
6
|
+
private readonly curve;
|
|
7
|
+
constructor(curve: Curve);
|
|
8
|
+
parseChatParams(params?: ChatParams): ChatParams;
|
|
9
|
+
loadMessages(messages: ChatMessageItem[], options?: LoadMessagesOptions): ChatMessageItem[];
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { MessageModule };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { normalizeContent } from "./normalize.js";
|
|
2
|
+
import { ResponseMode } from "../types/message/enum.js";
|
|
3
|
+
|
|
4
|
+
//#region src/message/message.ts
|
|
5
|
+
var MessageModule = class {
|
|
6
|
+
constructor(curve) {
|
|
7
|
+
this.curve = curve;
|
|
8
|
+
this.curve = curve;
|
|
9
|
+
}
|
|
10
|
+
parseChatParams(params) {
|
|
11
|
+
if (!params?.context_link) this.curve.utils.paramsException("context_link");
|
|
12
|
+
if (!params?.message_id) this.curve.utils.paramsException("message_id");
|
|
13
|
+
if (!Array.isArray(params?.messages) || params.messages.length === 0) this.curve.utils.paramsException("messages");
|
|
14
|
+
const query = params?.messages?.filter?.((msg) => msg.role === "user")?.pop?.()?.content ?? "";
|
|
15
|
+
if (!query) this.curve.utils.commonException("Not found user input content");
|
|
16
|
+
return {
|
|
17
|
+
...params,
|
|
18
|
+
response_mode: params?.response_mode ?? ResponseMode.Streaming,
|
|
19
|
+
agent_params_global: params?.agent_params_global ?? {},
|
|
20
|
+
query
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
loadMessages(messages, options) {
|
|
24
|
+
const { maxHistoryMessages = 20, isNormalize = true } = options ?? {};
|
|
25
|
+
const normalizedMessages = messages.filter((message) => typeof message?.content === "string" && message.content).map((message) => ({
|
|
26
|
+
role: message.role === "agent" ? "assistant" : message.role,
|
|
27
|
+
content: isNormalize && ["assistant", "agent"].includes(message.role) ? normalizeContent(message.content) : message.content
|
|
28
|
+
})).filter((message) => message.content.trim().length > 0);
|
|
29
|
+
if ([...normalizedMessages].reverse()[0]?.role !== "user") throw new Error("Not found user query content");
|
|
30
|
+
return normalizedMessages.slice(Math.max(0, normalizedMessages.length - 1 - maxHistoryMessages * 2));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { MessageModule };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/message/normalize.ts
|
|
2
|
+
const TOOL_CALL_BLOCK_RE = /```data\s+?\{[\s\S]*?"data_type"\s*:\s*"tool_call"[\s\S]*?```/g;
|
|
3
|
+
const TOOL_USE_JSON_RE = /\{\s*"type"\s*:\s*"tool_use"[^}]*\}/g;
|
|
4
|
+
const COLLAPSE_BLANK_RE = /\n{3,}/g;
|
|
5
|
+
const normalizeContent = (content) => {
|
|
6
|
+
if (!(content && typeof content === "string")) return content;
|
|
7
|
+
return content.replaceAll(TOOL_CALL_BLOCK_RE, "").replaceAll(TOOL_USE_JSON_RE, "").replaceAll(COLLAPSE_BLANK_RE, "\n\n").trim();
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { normalizeContent };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as langchain2 from "langchain";
|
|
2
|
+
import * as _langchain_core_tools5 from "@langchain/core/tools";
|
|
3
|
+
|
|
4
|
+
//#region src/middleware/createToolErrorCatchMiddleware.d.ts
|
|
5
|
+
declare const createToolErrorCatchMiddleware: () => langchain2.AgentMiddleware<undefined, undefined, unknown, readonly (_langchain_core_tools5.ClientTool | _langchain_core_tools5.ServerTool)[]>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createToolErrorCatchMiddleware };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ToolMessage, createMiddleware } from "langchain";
|
|
2
|
+
|
|
3
|
+
//#region src/middleware/createToolErrorCatchMiddleware.ts
|
|
4
|
+
const stringifyDetails = (details) => {
|
|
5
|
+
if (details === void 0 || details === null) return "";
|
|
6
|
+
if (typeof details === "string") return details;
|
|
7
|
+
try {
|
|
8
|
+
return JSON.stringify(details, null, 2);
|
|
9
|
+
} catch {
|
|
10
|
+
return String(details);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const isToolAbortError = (error) => error instanceof Error && error.name === "ToolAbortError";
|
|
14
|
+
const buildAbortSummary = (toolName, error) => {
|
|
15
|
+
const resolvedToolName = toolName || "unknown_tool";
|
|
16
|
+
const detailsText = stringifyDetails(error.details);
|
|
17
|
+
return [
|
|
18
|
+
`Tool ${resolvedToolName} validation or business check failed: ${error.message}`,
|
|
19
|
+
detailsText ? `Details: ${detailsText}` : "",
|
|
20
|
+
"This is a terminal failure for the current task. Please inform the user directly and stop calling tools."
|
|
21
|
+
].filter(Boolean).join("\n");
|
|
22
|
+
};
|
|
23
|
+
const buildToolMessageContent = (toolName, error) => {
|
|
24
|
+
if (isToolAbortError(error)) return buildAbortSummary(toolName, error);
|
|
25
|
+
return `Tool ${toolName || "unknown_tool"} error: ${error instanceof Error ? error.message : String(error)}`;
|
|
26
|
+
};
|
|
27
|
+
const createToolErrorCatchMiddleware = () => createMiddleware({
|
|
28
|
+
name: "ToolErrorCatchMiddleware",
|
|
29
|
+
wrapToolCall: async (request, handler) => {
|
|
30
|
+
try {
|
|
31
|
+
return await handler(request);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
const toolName = request.toolCall?.name ?? "";
|
|
34
|
+
return new ToolMessage({
|
|
35
|
+
content: buildToolMessageContent(toolName, error),
|
|
36
|
+
tool_call_id: request.toolCall?.id ?? "",
|
|
37
|
+
name: toolName,
|
|
38
|
+
status: "error"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { createToolErrorCatchMiddleware };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as langchain0 from "langchain";
|
|
2
|
+
import * as _langchain_core_tools0 from "@langchain/core/tools";
|
|
3
|
+
import { StructuredTool } from "@langchain/core/tools";
|
|
4
|
+
|
|
5
|
+
//#region src/middleware/createToolMiddleware.d.ts
|
|
6
|
+
declare const createToolMiddleware: (tools: StructuredTool[]) => langchain0.AgentMiddleware<undefined, undefined, unknown, readonly (_langchain_core_tools0.ClientTool | _langchain_core_tools0.ServerTool)[]>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { createToolMiddleware };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { curve } from "../index.js";
|
|
2
|
+
import { createMiddleware } from "langchain";
|
|
3
|
+
|
|
4
|
+
//#region src/middleware/createToolMiddleware.ts
|
|
5
|
+
const toToolId = (name) => `tool_${name}`;
|
|
6
|
+
const toGroupId = (name) => `group_${name}`;
|
|
7
|
+
const createToolMiddleware = (tools) => {
|
|
8
|
+
const toolNames = new Set(tools.map((t) => t.name));
|
|
9
|
+
return createMiddleware({
|
|
10
|
+
name: "ToolCallNotifyMiddleware",
|
|
11
|
+
wrapToolCall: async (request, handler) => {
|
|
12
|
+
const toolName = request.toolCall?.name ?? "";
|
|
13
|
+
if (!toolNames.has(toolName)) return handler(request);
|
|
14
|
+
const writer = request.runtime?.writer;
|
|
15
|
+
if (!writer) return handler(request);
|
|
16
|
+
const toolId = toToolId(toolName);
|
|
17
|
+
const groupId = toGroupId(toolName);
|
|
18
|
+
writer(curve.protocol.output({ content: [curve.protocol.toToolCallChunk(toolId, toolName, "running", groupId)] }));
|
|
19
|
+
try {
|
|
20
|
+
const result = await handler(request);
|
|
21
|
+
writer(curve.protocol.output({ content: [curve.protocol.toToolCallChunk(toolId, toolName, "finished", groupId)] }));
|
|
22
|
+
return result;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
writer(curve.protocol.output({ content: [curve.protocol.toToolCallChunk(toolId, toolName, "failed", groupId)] }));
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createToolMiddleware };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as langchain0 from "langchain";
|
|
2
|
+
import * as _langchain_core_tools1 from "@langchain/core/tools";
|
|
3
|
+
import { StructuredTool } from "@langchain/core/tools";
|
|
4
|
+
|
|
5
|
+
//#region src/middleware/index.d.ts
|
|
6
|
+
declare class MiddlewareModule {
|
|
7
|
+
createToolMiddleware: (tools: StructuredTool[]) => langchain0.AgentMiddleware<undefined, undefined, unknown, readonly (_langchain_core_tools1.ClientTool | _langchain_core_tools1.ServerTool)[]>;
|
|
8
|
+
createToolErrorCatchMiddleware: () => langchain0.AgentMiddleware<undefined, undefined, unknown, readonly (_langchain_core_tools1.ClientTool | _langchain_core_tools1.ServerTool)[]>;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { MiddlewareModule };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createToolMiddleware } from "./createToolMiddleware.js";
|
|
2
|
+
import { createToolErrorCatchMiddleware } from "./createToolErrorCatchMiddleware.js";
|
|
3
|
+
|
|
4
|
+
//#region src/middleware/index.ts
|
|
5
|
+
var MiddlewareModule = class {
|
|
6
|
+
createToolMiddleware = (tools) => createToolMiddleware(tools);
|
|
7
|
+
createToolErrorCatchMiddleware = () => createToolErrorCatchMiddleware();
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { MiddlewareModule };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Curve } from "../index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/prompt/prompt.d.ts
|
|
4
|
+
declare class PromptModule {
|
|
5
|
+
private readonly curve;
|
|
6
|
+
constructor(curve: Curve);
|
|
7
|
+
loadPrompt(filePath: string): Promise<string>;
|
|
8
|
+
systemPrompt(): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { PromptModule };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/prompt/prompt.ts
|
|
2
|
+
var PromptModule = class {
|
|
3
|
+
constructor(curve) {
|
|
4
|
+
this.curve = curve;
|
|
5
|
+
this.curve = curve;
|
|
6
|
+
}
|
|
7
|
+
async loadPrompt(filePath) {
|
|
8
|
+
if (!this.curve.file.isExist(filePath)) throw new Error(`Not found ${filePath}`);
|
|
9
|
+
return await this.curve.file.readFileString(this.curve.file.resolvePath(filePath));
|
|
10
|
+
}
|
|
11
|
+
async systemPrompt() {
|
|
12
|
+
const storageDir = this.curve.file.resolvePath(process.cwd(), "storage");
|
|
13
|
+
const filePath = this.curve.file.resolvePath(storageDir, "prompts/system.md");
|
|
14
|
+
return this.loadPrompt(filePath);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { PromptModule };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Action, Schema } from "../types/protocal/content/form.js";
|
|
2
|
+
import { ViewType } from "../types/protocal/content/fileLink.js";
|
|
3
|
+
import { CurveChunk, CurveInnerChunk } from "../types/protocal/index.js";
|
|
4
|
+
import { StreamChunk } from "../types/stream/index.js";
|
|
5
|
+
import { Curve } from "../index.js";
|
|
6
|
+
|
|
7
|
+
//#region src/protocal/protocal.d.ts
|
|
8
|
+
declare class ProtocolModule {
|
|
9
|
+
private readonly curve;
|
|
10
|
+
constructor(curve: Curve);
|
|
11
|
+
output(chunk: StreamChunk): CurveChunk | string;
|
|
12
|
+
formatInnerChunk(chunk: CurveInnerChunk): string;
|
|
13
|
+
private innerChunkToMarkdown;
|
|
14
|
+
toFileLinkChunk(filePath: string, view?: ViewType, label?: string, table?: string): string;
|
|
15
|
+
toToolCallChunk(toolId: string, title?: string, status?: string, groupId?: string): string;
|
|
16
|
+
toProgressChunk(id: string, value: number, text?: string, type?: string, position?: string): string;
|
|
17
|
+
toSmilesChunk(smiles: string, uiType?: string, uiSize?: string): string;
|
|
18
|
+
toEChartsChunk(options?: Record<string, any>): string;
|
|
19
|
+
toFormChunk(schema?: Schema, action?: Action, title?: string): string;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ProtocolModule };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { DataType } from "../types/protocal/enum.js";
|
|
2
|
+
import { ToolCallStatus } from "../types/protocal/content/toolCall.js";
|
|
3
|
+
import { ProgressType } from "../types/protocal/content/progress.js";
|
|
4
|
+
import { ViewType } from "../types/protocal/content/fileLink.js";
|
|
5
|
+
import { SmilesContentSize, SmilesContentType } from "../types/protocal/content/smiles.js";
|
|
6
|
+
import { ActionType } from "../types/protocal/content/form.js";
|
|
7
|
+
import { UIEnv } from "../index.js";
|
|
8
|
+
|
|
9
|
+
//#region src/protocal/protocal.ts
|
|
10
|
+
var ProtocolModule = class {
|
|
11
|
+
constructor(curve) {
|
|
12
|
+
this.curve = curve;
|
|
13
|
+
this.curve = curve;
|
|
14
|
+
}
|
|
15
|
+
output(chunk) {
|
|
16
|
+
let content = "";
|
|
17
|
+
if (chunk.content && typeof chunk.content === "string") content = chunk.content;
|
|
18
|
+
else if (Array.isArray(chunk.content)) content = chunk.content.join("");
|
|
19
|
+
if (this.curve.getUIEnv() === UIEnv.Common) return content;
|
|
20
|
+
return {
|
|
21
|
+
data_type: chunk.data_type ?? DataType.Markdown,
|
|
22
|
+
metadata: chunk.metadata ?? {},
|
|
23
|
+
content
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
formatInnerChunk(chunk) {
|
|
27
|
+
if (this.curve.getUIEnv() === UIEnv.Common) return this.innerChunkToMarkdown(chunk);
|
|
28
|
+
return `\n\`\`\`data ${JSON.stringify(chunk)}\`\`\`\n`;
|
|
29
|
+
}
|
|
30
|
+
innerChunkToMarkdown(chunk) {
|
|
31
|
+
const c = chunk.content;
|
|
32
|
+
switch (chunk.data_type) {
|
|
33
|
+
case DataType.FileLink: return `Generated file **${c.label || "file"}**, link: **${c.link}**`;
|
|
34
|
+
case DataType.ToolCall: return `Calling tool **${c.title || c.tool_id}**, status: **${c.status}**`;
|
|
35
|
+
case DataType.Progress: return `Current progress: **${c.value}%**${c.text ? ` (${c.text})` : ""}`;
|
|
36
|
+
case DataType.Smiles: return `Molecular structure (SMILES): \`${c.value}\``;
|
|
37
|
+
case DataType.ECharts: return `Chart data:\n${JSON.stringify(c, null, 2)}`;
|
|
38
|
+
case DataType.Form: return `Form: **${c.title || "Untitled"}**\n${JSON.stringify(c.schema, null, 2)}`;
|
|
39
|
+
default: return typeof c === "string" ? c : JSON.stringify(c, null, 2);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
toFileLinkChunk(filePath, view, label, table) {
|
|
43
|
+
if (!filePath) throw new Error("[File link] file path is required");
|
|
44
|
+
const chunk = {
|
|
45
|
+
data_type: DataType.FileLink,
|
|
46
|
+
content: {
|
|
47
|
+
label: label ?? this.curve.file.getFilename(filePath),
|
|
48
|
+
link: filePath,
|
|
49
|
+
view: view ?? ViewType.Link
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
if (table) chunk.content.table = table;
|
|
53
|
+
return this.formatInnerChunk(chunk);
|
|
54
|
+
}
|
|
55
|
+
toToolCallChunk(toolId, title, status, groupId) {
|
|
56
|
+
if (!toolId) throw new Error("[Tool call] toolId is required");
|
|
57
|
+
const chunk = {
|
|
58
|
+
data_type: DataType.ToolCall,
|
|
59
|
+
content: {
|
|
60
|
+
tool_id: toolId,
|
|
61
|
+
title: title ?? toolId,
|
|
62
|
+
group_id: groupId ?? toolId,
|
|
63
|
+
status: status ?? ToolCallStatus.Created
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
return this.formatInnerChunk(chunk);
|
|
67
|
+
}
|
|
68
|
+
toProgressChunk(id, value, text, type, position) {
|
|
69
|
+
if (!(value >= 0 && value <= 100)) throw new Error("[Progress] value must be between 0 and 100");
|
|
70
|
+
if (!id) throw new Error("[Progress] id is required");
|
|
71
|
+
const chunk = {
|
|
72
|
+
data_type: DataType.Progress,
|
|
73
|
+
content: {
|
|
74
|
+
id,
|
|
75
|
+
value,
|
|
76
|
+
type: type ?? ProgressType.Linear
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
if (text) chunk.content.text = text;
|
|
80
|
+
if (position) chunk.content.position = position;
|
|
81
|
+
return this.formatInnerChunk(chunk);
|
|
82
|
+
}
|
|
83
|
+
toSmilesChunk(smiles, uiType, uiSize) {
|
|
84
|
+
if (!smiles) throw new Error("[Smiles] smiles is required");
|
|
85
|
+
const chunk = {
|
|
86
|
+
data_type: DataType.Smiles,
|
|
87
|
+
content: {
|
|
88
|
+
value: smiles,
|
|
89
|
+
ui_type: uiType ?? SmilesContentType.Image,
|
|
90
|
+
ui_size: uiSize ?? SmilesContentSize.Normal
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return this.formatInnerChunk(chunk);
|
|
94
|
+
}
|
|
95
|
+
toEChartsChunk(options) {
|
|
96
|
+
if (!options) throw new Error("[ECharts] options is required");
|
|
97
|
+
const chunk = {
|
|
98
|
+
data_type: DataType.ECharts,
|
|
99
|
+
content: options
|
|
100
|
+
};
|
|
101
|
+
return this.formatInnerChunk(chunk);
|
|
102
|
+
}
|
|
103
|
+
toFormChunk(schema, action, title) {
|
|
104
|
+
if (!(schema && typeof schema === "object")) throw new Error("[Form] schema is required");
|
|
105
|
+
const chunk = {
|
|
106
|
+
data_type: DataType.Form,
|
|
107
|
+
content: {
|
|
108
|
+
action: action ?? ActionType.Chat,
|
|
109
|
+
title: title ?? "",
|
|
110
|
+
schema
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return this.formatInnerChunk(chunk);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
export { ProtocolModule };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Curve } from "../index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/skill/skill.d.ts
|
|
4
|
+
declare class SkillModule {
|
|
5
|
+
private readonly curve;
|
|
6
|
+
constructor(curve: Curve);
|
|
7
|
+
/**
|
|
8
|
+
* 获取 skills 目录路径列表(相对于 FilesystemBackend 的 rootDir)
|
|
9
|
+
* deepagents SkillsMiddleware 要求使用相对路径
|
|
10
|
+
*/
|
|
11
|
+
getSkillDirs(): string[];
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { SkillModule };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/skill/skill.ts
|
|
2
|
+
var SkillModule = class {
|
|
3
|
+
constructor(curve) {
|
|
4
|
+
this.curve = curve;
|
|
5
|
+
this.curve = curve;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 获取 skills 目录路径列表(相对于 FilesystemBackend 的 rootDir)
|
|
9
|
+
* deepagents SkillsMiddleware 要求使用相对路径
|
|
10
|
+
*/
|
|
11
|
+
getSkillDirs() {
|
|
12
|
+
const skillsDir = this.curve.file.resolvePath(process.cwd(), "storage", "skills");
|
|
13
|
+
return this.curve.file.isExist(skillsDir) ? ["storage/skills"] : [];
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { SkillModule };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Curve } from "../index.js";
|
|
2
|
+
import { Response } from "express";
|
|
3
|
+
|
|
4
|
+
//#region src/stream/stream.d.ts
|
|
5
|
+
declare class StreamModule {
|
|
6
|
+
private readonly curve;
|
|
7
|
+
constructor(curve: Curve);
|
|
8
|
+
private flush;
|
|
9
|
+
setupSSEHeaders(res: Response): void;
|
|
10
|
+
writeChunk(res: Response, chunk: Record<string, any> | string): void;
|
|
11
|
+
writeDone(res: Response): void;
|
|
12
|
+
writeError(res: Response, error: any): void;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { StreamModule };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getMessageFromError } from "../utils/error.js";
|
|
2
|
+
|
|
3
|
+
//#region src/stream/stream.ts
|
|
4
|
+
var StreamModule = class {
|
|
5
|
+
constructor(curve) {
|
|
6
|
+
this.curve = curve;
|
|
7
|
+
this.curve = curve;
|
|
8
|
+
}
|
|
9
|
+
flush(res) {
|
|
10
|
+
if (typeof res.flush === "function") res.flush();
|
|
11
|
+
}
|
|
12
|
+
setupSSEHeaders(res) {
|
|
13
|
+
res.setHeader("Content-Type", "text/event-stream");
|
|
14
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
15
|
+
res.setHeader("Connection", "keep-alive");
|
|
16
|
+
res.setHeader("X-Accel-Buffering", "no");
|
|
17
|
+
res.flushHeaders();
|
|
18
|
+
}
|
|
19
|
+
writeChunk(res, chunk) {
|
|
20
|
+
let content = "";
|
|
21
|
+
if (typeof chunk === "string") content = chunk;
|
|
22
|
+
else content = JSON.stringify(chunk);
|
|
23
|
+
res.write(`data: ${content}\n\n`);
|
|
24
|
+
this.flush(res);
|
|
25
|
+
}
|
|
26
|
+
writeDone(res) {
|
|
27
|
+
res.write(`data: [DONE]\n\n`);
|
|
28
|
+
res.end();
|
|
29
|
+
}
|
|
30
|
+
writeError(res, error) {
|
|
31
|
+
const errorMessage = getMessageFromError(error);
|
|
32
|
+
res.write(`data: [ERROR] ${errorMessage}\n\n`);
|
|
33
|
+
this.flush(res);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { StreamModule };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/types/message/index.d.ts
|
|
2
|
+
interface ChatMessageItem {
|
|
3
|
+
role: string;
|
|
4
|
+
content: string;
|
|
5
|
+
}
|
|
6
|
+
interface ChatParams {
|
|
7
|
+
message_id?: string;
|
|
8
|
+
context_link?: string;
|
|
9
|
+
messages?: ChatMessageItem[];
|
|
10
|
+
agent_params_global?: Record<string, any>;
|
|
11
|
+
response_mode?: string;
|
|
12
|
+
query?: string;
|
|
13
|
+
[propName: string]: any;
|
|
14
|
+
}
|
|
15
|
+
interface LoadMessagesOptions {
|
|
16
|
+
maxHistoryMessages?: number;
|
|
17
|
+
isNormalize?: boolean;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { ChatMessageItem, ChatParams, LoadMessagesOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/types/protocal/content/fileLink.d.ts
|
|
2
|
+
declare enum ViewType {
|
|
3
|
+
Inner = "inner",
|
|
4
|
+
// 内嵌在视图中
|
|
5
|
+
Link = "link",
|
|
6
|
+
}
|
|
7
|
+
interface FileLinkContent {
|
|
8
|
+
label: string;
|
|
9
|
+
link: string;
|
|
10
|
+
view: ViewType;
|
|
11
|
+
table?: string;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { FileLinkContent, ViewType };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/types/protocal/content/form.d.ts
|
|
2
|
+
type FieldType = 'String' | 'Number' | 'Boolean' | 'JSON' | 'Select' | 'Checkbox' | 'Time' | 'Text' | 'HTML' | 'Structure' | 'Attachment';
|
|
3
|
+
type ConditionOperator = 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'in' | 'notIn' | 'regexp' | 'nregexp';
|
|
4
|
+
interface CommonOption {
|
|
5
|
+
label: string;
|
|
6
|
+
value: string | number | boolean;
|
|
7
|
+
}
|
|
8
|
+
interface FieldCondition {
|
|
9
|
+
field: string;
|
|
10
|
+
operator?: ConditionOperator;
|
|
11
|
+
value: any;
|
|
12
|
+
}
|
|
13
|
+
interface SchemaFiled {
|
|
14
|
+
field: string;
|
|
15
|
+
type: FieldType;
|
|
16
|
+
label?: string;
|
|
17
|
+
value?: any;
|
|
18
|
+
filePath?: string;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
options?: CommonOption[];
|
|
22
|
+
booleanOptions?: [string, string];
|
|
23
|
+
regex?: string;
|
|
24
|
+
regexErrorMessage?: string;
|
|
25
|
+
condition?: FieldCondition;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
hint?: string;
|
|
28
|
+
order?: number;
|
|
29
|
+
multiple?: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface Schema {
|
|
32
|
+
fields: SchemaFiled[];
|
|
33
|
+
}
|
|
34
|
+
declare enum ActionType {
|
|
35
|
+
Chat = "chat",
|
|
36
|
+
Request = "request",
|
|
37
|
+
OpenForm = "open-form",
|
|
38
|
+
}
|
|
39
|
+
interface Action {
|
|
40
|
+
type: ActionType;
|
|
41
|
+
value: string | FormContent;
|
|
42
|
+
}
|
|
43
|
+
interface FormContent {
|
|
44
|
+
schema: Schema;
|
|
45
|
+
action?: Action;
|
|
46
|
+
[propName: string]: any;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { Action, ActionType, CommonOption, ConditionOperator, FieldCondition, FieldType, FormContent, Schema, SchemaFiled };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/types/protocal/content/form.ts
|
|
2
|
+
let ActionType = /* @__PURE__ */ function(ActionType$1) {
|
|
3
|
+
ActionType$1["Chat"] = "chat";
|
|
4
|
+
ActionType$1["Request"] = "request";
|
|
5
|
+
ActionType$1["OpenForm"] = "open-form";
|
|
6
|
+
return ActionType$1;
|
|
7
|
+
}({});
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ActionType };
|