@blocklet/pages-kit-agents 0.6.58 → 0.6.60
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/.env.local.example +4 -5
- package/README.md +4 -1
- package/cli.ts +1 -1
- package/lib/cjs/agents/multi-agent-page-writer.js +2 -2
- package/lib/cjs/agents/template-designer.js +0 -7
- package/lib/cjs/agents/template-generator.js +0 -7
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/agent-utils.d.ts +8 -5
- package/lib/cjs/utils/agent-utils.js +40 -52
- package/lib/esm/agents/multi-agent-page-writer.js +2 -2
- package/lib/esm/agents/template-designer.js +0 -7
- package/lib/esm/agents/template-generator.js +0 -7
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/agent-utils.d.ts +8 -5
- package/lib/esm/utils/agent-utils.js +38 -52
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/agent-utils.d.ts +8 -5
- package/package.json +11 -8
- package/workflow-cli.ts +9 -20
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DeepSeekChatModel } from '@aigne/deepseek';
|
|
1
|
+
import { AIGNEHubChatModel } from '@aigne/aigne-hub';
|
|
3
2
|
import { FSMemory, FSMemoryOptions } from '@aigne/fs-memory';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export declare const getAigneConfig: () => Promise<{
|
|
4
|
+
apiKey: any;
|
|
5
|
+
url: string;
|
|
6
|
+
provider: string | undefined;
|
|
7
|
+
model: string | undefined;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function getModel(modelName?: string): Promise<AIGNEHubChatModel>;
|
|
7
10
|
export declare function getMemory({ projectId, ...rest }: Pick<FSMemoryOptions, 'autoUpdate'> & {
|
|
8
11
|
projectId?: string;
|
|
9
12
|
}): FSMemory;
|
|
@@ -3,17 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getAigneConfig = void 0;
|
|
6
7
|
exports.getModel = getModel;
|
|
7
8
|
exports.getMemory = getMemory;
|
|
8
|
-
const
|
|
9
|
-
const deepseek_1 = require("@aigne/deepseek");
|
|
9
|
+
const aigne_hub_1 = require("@aigne/aigne-hub");
|
|
10
10
|
const fs_memory_1 = require("@aigne/fs-memory");
|
|
11
|
-
const
|
|
12
|
-
const openai_1 = require("@aigne/openai");
|
|
13
|
-
const xai_1 = require("@aigne/xai");
|
|
14
|
-
const node_assert_1 = __importDefault(require("node:assert"));
|
|
11
|
+
const axios_1 = __importDefault(require("axios"));
|
|
15
12
|
const node_path_1 = __importDefault(require("node:path"));
|
|
16
|
-
const
|
|
13
|
+
const ufo_1 = require("ufo");
|
|
17
14
|
// === 内置 prompt 内容,避免运行时读取文件 ===
|
|
18
15
|
const recorderInstructions = `你是一个智能的站点生成记忆管理器,负责从多轮对话和用户反馈中提取对后续站点生成有用的知识和偏好,并以结构化方式存储。
|
|
19
16
|
|
|
@@ -106,54 +103,45 @@ const retrieverInstructions = `你是一个智能的站点生成记忆检索器
|
|
|
106
103
|
{{search}}
|
|
107
104
|
</search-query>
|
|
108
105
|
`;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
return
|
|
106
|
+
const getAigneHubModelApi = async (url) => {
|
|
107
|
+
try {
|
|
108
|
+
const urlObj = new URL(url);
|
|
109
|
+
const appUrl = urlObj.origin;
|
|
110
|
+
const { data: blockletJson } = await axios_1.default.get((0, ufo_1.joinURL)(appUrl, '__blocklet__.js?type=json'));
|
|
111
|
+
const { componentMountPoints = [] } = blockletJson || {};
|
|
112
|
+
const aigneHubMountPoint = componentMountPoints.find((item) => item.name === 'ai-kit');
|
|
113
|
+
if (!aigneHubMountPoint) {
|
|
114
|
+
throw new Error("The current application doesn't have the AIGNE Hub component installed");
|
|
115
|
+
}
|
|
116
|
+
return (0, ufo_1.joinURL)(appUrl, aigneHubMountPoint.mountPoint);
|
|
120
117
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const gemini = new gemini_1.GeminiChatModel({
|
|
124
|
-
apiKey: GEMINI_API_KEY,
|
|
125
|
-
model: modelName,
|
|
126
|
-
});
|
|
127
|
-
return gemini;
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new Error('Invalid url');
|
|
128
120
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
temperature: 0.7,
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
return model;
|
|
139
|
-
}
|
|
140
|
-
if (modelName?.includes('grok')) {
|
|
141
|
-
(0, node_assert_1.default)(XAI_API_KEY, 'Please set the XAI_API_KEY environment variable');
|
|
142
|
-
const grok = new xai_1.XAIChatModel({
|
|
143
|
-
apiKey: XAI_API_KEY,
|
|
144
|
-
model: modelName,
|
|
145
|
-
});
|
|
146
|
-
return grok;
|
|
147
|
-
}
|
|
148
|
-
if (modelName?.includes('deepseek')) {
|
|
149
|
-
(0, node_assert_1.default)(DEEPSEEK_API_KEY, 'Please set the DEEPSEEK_API_KEY environment variable');
|
|
150
|
-
const deepseek = new deepseek_1.DeepSeekChatModel({
|
|
151
|
-
apiKey: DEEPSEEK_API_KEY,
|
|
152
|
-
model: modelName,
|
|
153
|
-
});
|
|
154
|
-
return deepseek;
|
|
121
|
+
};
|
|
122
|
+
const getAigneConfig = async () => {
|
|
123
|
+
let apiKey = {};
|
|
124
|
+
const credential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
|
|
125
|
+
if (credential && typeof credential === 'string') {
|
|
126
|
+
apiKey = JSON.parse(credential);
|
|
155
127
|
}
|
|
156
|
-
|
|
128
|
+
const baseUrl = await getAigneHubModelApi(process.env.BLOCKLET_AIGNE_API_URL || '');
|
|
129
|
+
return {
|
|
130
|
+
apiKey: apiKey.apiKey,
|
|
131
|
+
url: baseUrl,
|
|
132
|
+
provider: process.env.BLOCKLET_AIGNE_API_PROVIDER,
|
|
133
|
+
model: process.env.BLOCKLET_AIGNE_API_MODEL,
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
exports.getAigneConfig = getAigneConfig;
|
|
137
|
+
async function getModel(modelName) {
|
|
138
|
+
const config = await (0, exports.getAigneConfig)();
|
|
139
|
+
const model = new aigne_hub_1.AIGNEHubChatModel({
|
|
140
|
+
model: modelName ?? config.model,
|
|
141
|
+
apiKey: config.apiKey,
|
|
142
|
+
url: config.url,
|
|
143
|
+
});
|
|
144
|
+
return model;
|
|
157
145
|
}
|
|
158
146
|
function getMemory({ projectId = 'debug', ...rest }) {
|
|
159
147
|
// === FSMemory 配置 ===
|
|
@@ -47,7 +47,7 @@ export default async function generatePageContentMultiAgent(input) {
|
|
|
47
47
|
throw new Error('Client disconnected');
|
|
48
48
|
}
|
|
49
49
|
let structurePlanMap = {};
|
|
50
|
-
const model = getModel(modelName);
|
|
50
|
+
const model = await getModel(modelName);
|
|
51
51
|
// 3-4 使用反思工作流生成页面结构
|
|
52
52
|
const planningEngine = new AIGNE({
|
|
53
53
|
model,
|
|
@@ -175,7 +175,7 @@ export async function generateSingleSectionContent({ context, question, locale,
|
|
|
175
175
|
generatedSections: JSON.stringify(existingSections),
|
|
176
176
|
};
|
|
177
177
|
const sectionContentAgent = await createSectionContentAgent(sectionContentInput);
|
|
178
|
-
const model = getModel(modelName);
|
|
178
|
+
const model = await getModel(modelName);
|
|
179
179
|
const engine = new AIGNE({
|
|
180
180
|
model,
|
|
181
181
|
});
|
|
@@ -3,13 +3,6 @@ import { AIAgent } from '@aigne/core';
|
|
|
3
3
|
// import assert from 'node:assert';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { getMemory } from '../utils';
|
|
6
|
-
// const { OPENAI_API_KEY } = process.env;
|
|
7
|
-
// assert(OPENAI_API_KEY, 'Please set the OPENAI_API_KEY environment variable');
|
|
8
|
-
// const memory = new DefaultMemory({
|
|
9
|
-
// storage: {
|
|
10
|
-
// url: 'file:./dbs/memory.db', // Path to store memory data, such as 'file:./memory.db'
|
|
11
|
-
// },
|
|
12
|
-
// });
|
|
13
6
|
const agentInstructions = `
|
|
14
7
|
你是一个专业的页面设计师,名叫小设。你的任务是根据整理好的用户需求,设计一个页面结构。
|
|
15
8
|
|
|
@@ -6,13 +6,6 @@ import path from 'node:path';
|
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import { getMemory } from '../utils/agent-utils.js';
|
|
8
8
|
import { ReflectionAgent } from '../workflow-agents/reflection-agent.js';
|
|
9
|
-
// const { OPENAI_API_KEY } = process.env;
|
|
10
|
-
// assert(OPENAI_API_KEY, 'Please set the OPENAI_API_KEY environment variable');
|
|
11
|
-
// const memory = new DefaultMemory({
|
|
12
|
-
// storage: {
|
|
13
|
-
// url: 'file:./dbs/memory.db', // Path to store memory data, such as 'file:./memory.db'
|
|
14
|
-
// },
|
|
15
|
-
// });
|
|
16
9
|
const pagesKitTemplateRule = fs.readFileSync(path.join(__dirname, '../prompts/pages-kit-template-rule.md'), 'utf-8');
|
|
17
10
|
const contextRule = `
|
|
18
11
|
## 技术规范参考
|