@blocklet/pages-kit-agents 0.6.57 → 0.6.59

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.
@@ -1,9 +1,12 @@
1
- import { AnthropicChatModel } from '@aigne/anthropic';
2
- import { DeepSeekChatModel } from '@aigne/deepseek';
1
+ import { AIGNEHubChatModel } from '@aigne/aigne-hub';
3
2
  import { FSMemory, FSMemoryOptions } from '@aigne/fs-memory';
4
- import { OpenAIChatModel } from '@aigne/openai';
5
- import { XAIChatModel } from '@aigne/xai';
6
- export declare function getModel(modelName?: string): OpenAIChatModel | AnthropicChatModel | XAIChatModel | DeepSeekChatModel | undefined;
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;
@@ -1,12 +1,8 @@
1
- import { AnthropicChatModel } from '@aigne/anthropic';
2
- import { DeepSeekChatModel } from '@aigne/deepseek';
1
+ import { AIGNEHubChatModel } from '@aigne/aigne-hub';
3
2
  import { FSMemory } from '@aigne/fs-memory';
4
- import { GeminiChatModel } from '@aigne/gemini';
5
- import { OpenAIChatModel } from '@aigne/openai';
6
- import { XAIChatModel } from '@aigne/xai';
7
- import assert from 'node:assert';
3
+ import axios from 'axios';
8
4
  import path from 'node:path';
9
- const { OPENAI_API_KEY, GEMINI_API_KEY, CLAUDE_API_KEY, XAI_API_KEY, DEEPSEEK_API_KEY } = process.env;
5
+ import { joinURL } from 'ufo';
10
6
  // === 内置 prompt 内容,避免运行时读取文件 ===
11
7
  const recorderInstructions = `你是一个智能的站点生成记忆管理器,负责从多轮对话和用户反馈中提取对后续站点生成有用的知识和偏好,并以结构化方式存储。
12
8
 
@@ -99,54 +95,44 @@ const retrieverInstructions = `你是一个智能的站点生成记忆检索器
99
95
  {{search}}
100
96
  </search-query>
101
97
  `;
102
- export function getModel(modelName = 'openai') {
103
- if (modelName?.includes('gpt')) {
104
- assert(OPENAI_API_KEY, 'Please set the OPENAI_API_KEY environment variable');
105
- const openai = new OpenAIChatModel({
106
- apiKey: OPENAI_API_KEY,
107
- model: modelName,
108
- modelOptions: {
109
- temperature: 0.8,
110
- },
111
- });
112
- return openai;
98
+ const getAigneHubModelApi = async (url) => {
99
+ try {
100
+ const urlObj = new URL(url);
101
+ const appUrl = urlObj.origin;
102
+ const { data: blockletJson } = await axios.get(joinURL(appUrl, '__blocklet__.js?type=json'));
103
+ const { componentMountPoints = [] } = blockletJson || {};
104
+ const aigneHubMountPoint = componentMountPoints.find((item) => item.name === 'ai-kit');
105
+ if (!aigneHubMountPoint) {
106
+ throw new Error("The current application doesn't have the AIGNE Hub component installed");
107
+ }
108
+ return joinURL(appUrl, aigneHubMountPoint.mountPoint);
113
109
  }
114
- if (modelName?.includes('gemini')) {
115
- assert(GEMINI_API_KEY, 'Please set the GEMINI_API_KEY environment variable');
116
- const gemini = new GeminiChatModel({
117
- apiKey: GEMINI_API_KEY,
118
- model: modelName,
119
- });
120
- return gemini;
110
+ catch (error) {
111
+ throw new Error('Invalid url');
121
112
  }
122
- if (modelName?.includes('claude')) {
123
- assert(CLAUDE_API_KEY, 'Please set the CLAUDE_API_KEY environment variable');
124
- const model = new AnthropicChatModel({
125
- apiKey: CLAUDE_API_KEY,
126
- model: modelName,
127
- modelOptions: {
128
- temperature: 0.7,
129
- },
130
- });
131
- return model;
113
+ };
114
+ export const getAigneConfig = async () => {
115
+ let apiKey = {};
116
+ const credential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
117
+ if (credential && typeof credential === 'string') {
118
+ apiKey = JSON.parse(credential);
132
119
  }
133
- if (modelName?.includes('grok')) {
134
- assert(XAI_API_KEY, 'Please set the XAI_API_KEY environment variable');
135
- const grok = new XAIChatModel({
136
- apiKey: XAI_API_KEY,
137
- model: modelName,
138
- });
139
- return grok;
140
- }
141
- if (modelName?.includes('deepseek')) {
142
- assert(DEEPSEEK_API_KEY, 'Please set the DEEPSEEK_API_KEY environment variable');
143
- const deepseek = new DeepSeekChatModel({
144
- apiKey: DEEPSEEK_API_KEY,
145
- model: modelName,
146
- });
147
- return deepseek;
148
- }
149
- return undefined;
120
+ const baseUrl = await getAigneHubModelApi(process.env.BLOCKLET_AIGNE_API_URL || '');
121
+ return {
122
+ apiKey: apiKey.apiKey,
123
+ url: baseUrl,
124
+ provider: process.env.BLOCKLET_AIGNE_API_PROVIDER,
125
+ model: process.env.BLOCKLET_AIGNE_API_MODEL,
126
+ };
127
+ };
128
+ export async function getModel(modelName) {
129
+ const config = await getAigneConfig();
130
+ const model = new AIGNEHubChatModel({
131
+ model: modelName ?? config.model,
132
+ apiKey: config.apiKey,
133
+ url: config.url,
134
+ });
135
+ return model;
150
136
  }
151
137
  export function getMemory({ projectId = 'debug', ...rest }) {
152
138
  // === FSMemory 配置 ===