@downcity/agent 1.1.5 → 1.1.7
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/bin/host/sdk/Agent.d.ts +10 -2
- package/bin/host/sdk/Agent.d.ts.map +1 -1
- package/bin/host/sdk/Agent.js +93 -26
- package/bin/host/sdk/Agent.js.map +1 -1
- package/bin/host/sdk/AgentSdkTypes.d.ts +12 -2
- package/bin/host/sdk/AgentSdkTypes.d.ts.map +1 -1
- package/bin/host/sdk/AgentSdkTypes.js +2 -2
- package/bin/host/sdk/SdkSessionSystemComposer.d.ts +11 -2
- package/bin/host/sdk/SdkSessionSystemComposer.d.ts.map +1 -1
- package/bin/host/sdk/SdkSessionSystemComposer.js +19 -2
- package/bin/host/sdk/SdkSessionSystemComposer.js.map +1 -1
- package/bin/host/sdk/Session.d.ts +10 -0
- package/bin/host/sdk/Session.d.ts.map +1 -1
- package/bin/host/sdk/Session.js +8 -0
- package/bin/host/sdk/Session.js.map +1 -1
- package/bin/index.d.ts +7 -0
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +7 -0
- package/bin/index.js.map +1 -1
- package/package.json +1 -1
- package/src/host/sdk/Agent.ts +105 -26
- package/src/host/sdk/AgentSdkTypes.ts +13 -2
- package/src/host/sdk/SdkSessionSystemComposer.ts +39 -2
- package/src/host/sdk/Session.ts +18 -0
- package/src/index.ts +7 -0
- package/tsconfig.tsbuildinfo +1 -1
package/bin/index.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// SDK 入口
|
|
9
9
|
export { Agent } from "./host/sdk/Agent.js";
|
|
10
10
|
export { RemoteAgent } from "./host/sdk/RemoteAgent.js";
|
|
11
|
+
export { BaseService } from "./service/builtins/BaseService.js";
|
|
11
12
|
export { ChatService } from "./service/builtins/chat/ChatService.js";
|
|
12
13
|
export { ChatChannelAccountService } from "./service/builtins/chat/accounts/ChannelAccountService.js";
|
|
13
14
|
// Agent 运行时
|
|
@@ -88,6 +89,12 @@ export { normalizeDefaultAgentName, listPlatformModelChoices, isAgentProjectInit
|
|
|
88
89
|
export { readProjectExecutionBinding, readProjectPrimaryModelId, hasProjectExecutionTarget, assertProjectExecutionTarget, } from "./agent/project/ProjectExecutionBinding.js";
|
|
89
90
|
export { listChatAuthorizationRoles, readChatAuthorizationConfigSync, setChatAuthorizationUserRole, } from "./plugins/auth/runtime/AuthorizationConfig.js";
|
|
90
91
|
export { resolveAuthorizedUserRole } from "./plugins/auth/runtime/AuthorizationPolicy.js";
|
|
92
|
+
export { authPlugin } from "./plugins/auth/Plugin.js";
|
|
93
|
+
export { skillPlugin } from "./plugins/skill/Plugin.js";
|
|
94
|
+
export { webPlugin } from "./plugins/web/Plugin.js";
|
|
95
|
+
export { asrPlugin } from "./plugins/asr/Plugin.js";
|
|
96
|
+
export { ttsPlugin } from "./plugins/tts/Plugin.js";
|
|
97
|
+
export { workboardPlugin } from "./plugins/workboard/Plugin.js";
|
|
91
98
|
// Agent 项目准备
|
|
92
99
|
export { ensureRuntimeProjectReady, ensureRuntimeExecutionBindingReady, } from "./host/daemon/ProjectSetup.js";
|
|
93
100
|
export { buildStaticPluginAvailability, findBuiltinPlugin, findStaticPluginView, listBuiltinPlugins, listStaticPluginViews, toStaticPluginView, } from "./plugin/Catalog.js";
|
package/bin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,SAAS;AACT,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAYxD,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2DAA2D,CAAC;AAUtG,YAAY;AACZ,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,eAAe,EAC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@ -2,9 +2,9 @@
|
|
|
2
2
|
* Agent SDK 本地入口。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - `new Agent({ id, path, tools, services })` 只做同步装配,不在构造阶段启动任何 I/O。
|
|
5
|
+
* - `new Agent({ id, path, tools, services, plugins })` 只做同步装配,不在构造阶段启动任何 I/O。
|
|
6
6
|
* - session、HTTP、RPC、service lifecycle 都按需异步初始化。
|
|
7
|
-
* - SDK Agent 通过最小 `AgentContext` 适配层复用现有 service/chat
|
|
7
|
+
* - SDK Agent 通过最小 `AgentContext` 适配层复用现有 service/plugin/chat 运行协议,而不是重复实现一套执行链。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import fs from "fs-extra";
|
|
@@ -16,6 +16,12 @@ import type { AgentContext } from "@/agent/AgentContextTypes.js";
|
|
|
16
16
|
import type { AgentRuntime } from "@/agent/AgentRuntimeTypes.js";
|
|
17
17
|
import type { DowncityConfig } from "@/shared/types/DowncityConfig.js";
|
|
18
18
|
import type { JsonValue } from "@/shared/types/Json.js";
|
|
19
|
+
import type {
|
|
20
|
+
Plugin,
|
|
21
|
+
PluginAvailability,
|
|
22
|
+
PluginPort,
|
|
23
|
+
PluginView,
|
|
24
|
+
} from "@/shared/types/Plugin.js";
|
|
19
25
|
import type {
|
|
20
26
|
AgentOptions,
|
|
21
27
|
AgentSessionMetadata,
|
|
@@ -25,11 +31,17 @@ import { loadStaticSystemPrompts } from "@session/composer/system/default/Static
|
|
|
25
31
|
import { getSdkAgentSessionsRootDirPath } from "@/host/sdk/Paths.js";
|
|
26
32
|
import { SdkAgentHttpServer } from "@/host/sdk/HttpServer.js";
|
|
27
33
|
import { SdkAgentRpcServer } from "@/host/sdk/RpcServer.js";
|
|
28
|
-
import {
|
|
34
|
+
import {
|
|
35
|
+
createAgentPathRuntime,
|
|
36
|
+
createAgentPluginConfigRuntime,
|
|
37
|
+
} from "@/host/runtime/AgentHostRuntime.js";
|
|
29
38
|
import { loadDowncityConfig } from "@/config/Config.js";
|
|
30
39
|
import { appendExecSessionMessage } from "@/service/builtins/chat/runtime/ChatIngressStore.js";
|
|
31
40
|
import { readChatMetaBySessionId } from "@/service/builtins/chat/runtime/ChatMetaStore.js";
|
|
32
41
|
import { resolveChatQueueStore } from "@/service/builtins/chat/runtime/ChatQueueStore.js";
|
|
42
|
+
import { HookRegistry } from "@/plugin/HookRegistry.js";
|
|
43
|
+
import { PluginRegistry } from "@/plugin/PluginRegistry.js";
|
|
44
|
+
import { isPluginEnabled } from "@/plugin/Activation.js";
|
|
33
45
|
|
|
34
46
|
function createFallbackSdkConfig(agentId: string): DowncityConfig {
|
|
35
47
|
return {
|
|
@@ -48,11 +60,14 @@ export class Agent {
|
|
|
48
60
|
readonly http: SdkAgentHttpServer;
|
|
49
61
|
readonly rpc: SdkAgentRpcServer;
|
|
50
62
|
readonly services: Map<string, BaseService>;
|
|
63
|
+
readonly plugins: PluginPort;
|
|
51
64
|
|
|
52
65
|
private readonly logger: Logger;
|
|
53
66
|
private readonly sessionsById = new Map<string, SdkSession>();
|
|
54
67
|
private readonly runtime: AgentRuntime;
|
|
55
68
|
private readonly serviceContext: AgentContext;
|
|
69
|
+
private readonly pluginRegistry: PluginRegistry;
|
|
70
|
+
private readonly pluginSystemProviders: Plugin[];
|
|
56
71
|
private readonly config: DowncityConfig;
|
|
57
72
|
private systems: string[];
|
|
58
73
|
private servicesStartPromise: Promise<void> | null = null;
|
|
@@ -79,6 +94,11 @@ export class Agent {
|
|
|
79
94
|
for (const service of this.services.values()) {
|
|
80
95
|
service.bindAgent(this.runtime);
|
|
81
96
|
}
|
|
97
|
+
this.pluginSystemProviders = Array.isArray(options.plugins)
|
|
98
|
+
? [...options.plugins]
|
|
99
|
+
: [];
|
|
100
|
+
this.pluginRegistry = this.createPluginRegistry(this.pluginSystemProviders);
|
|
101
|
+
this.plugins = this.createPluginPort();
|
|
82
102
|
this.serviceContext = this.createServiceContext();
|
|
83
103
|
this.http = new SdkAgentHttpServer(this);
|
|
84
104
|
this.rpc = new SdkAgentRpcServer(this);
|
|
@@ -167,6 +187,84 @@ export class Agent {
|
|
|
167
187
|
return services;
|
|
168
188
|
}
|
|
169
189
|
|
|
190
|
+
private createPluginRegistry(input: Plugin[]): PluginRegistry {
|
|
191
|
+
let pluginRegistryRef: PluginRegistry | null = null;
|
|
192
|
+
const hookRegistry = new HookRegistry({
|
|
193
|
+
contextResolver: () => this.serviceContext,
|
|
194
|
+
pluginEnabledChecker: (pluginName) => {
|
|
195
|
+
const plugin = pluginRegistryRef?.get(pluginName);
|
|
196
|
+
return plugin ? isPluginEnabled({ plugin }) : false;
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
const registry = new PluginRegistry({
|
|
200
|
+
contextResolver: () => this.serviceContext,
|
|
201
|
+
hookRegistry,
|
|
202
|
+
});
|
|
203
|
+
pluginRegistryRef = registry;
|
|
204
|
+
|
|
205
|
+
for (const plugin of input) {
|
|
206
|
+
registry.register(plugin);
|
|
207
|
+
}
|
|
208
|
+
return registry;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private createPluginPort(): PluginPort {
|
|
212
|
+
return {
|
|
213
|
+
list: (): PluginView[] => this.pluginRegistry.list(),
|
|
214
|
+
availability: async (pluginName: string): Promise<PluginAvailability> =>
|
|
215
|
+
await this.pluginRegistry.availability(pluginName),
|
|
216
|
+
runAction: async (params) => await this.pluginRegistry.runAction(params),
|
|
217
|
+
pipeline: async <T>(pointName: string, value: T): Promise<T> =>
|
|
218
|
+
await this.pluginRegistry.pipeline(pointName, value),
|
|
219
|
+
guard: async <T>(pointName: string, value: T): Promise<void> => {
|
|
220
|
+
await this.pluginRegistry.guard(pointName, value);
|
|
221
|
+
},
|
|
222
|
+
effect: async <T>(pointName: string, value: T): Promise<void> => {
|
|
223
|
+
await this.pluginRegistry.effect(pointName, value);
|
|
224
|
+
},
|
|
225
|
+
resolve: async <TInput, TOutput>(
|
|
226
|
+
pointName: string,
|
|
227
|
+
value: TInput,
|
|
228
|
+
): Promise<TOutput> =>
|
|
229
|
+
await this.pluginRegistry.resolve<TInput, TOutput>(pointName, value),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private async loadPluginSystemPrompts(): Promise<string[]> {
|
|
234
|
+
const out: string[] = [];
|
|
235
|
+
for (const plugin of this.pluginSystemProviders) {
|
|
236
|
+
if (typeof plugin.system !== "function") continue;
|
|
237
|
+
try {
|
|
238
|
+
if (!isPluginEnabled({ plugin })) continue;
|
|
239
|
+
if (typeof plugin.availability === "function") {
|
|
240
|
+
const availability = await plugin.availability(this.serviceContext);
|
|
241
|
+
if (!availability.available) continue;
|
|
242
|
+
}
|
|
243
|
+
const text = String(await plugin.system(this.serviceContext)).trim();
|
|
244
|
+
if (!text) continue;
|
|
245
|
+
out.push(text);
|
|
246
|
+
} catch {
|
|
247
|
+
// 单个 plugin system 失败不应阻断 SDK session 主链路。
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
private async loadServiceSystemPrompts(): Promise<string[]> {
|
|
254
|
+
const out: string[] = [];
|
|
255
|
+
for (const service of this.services.values()) {
|
|
256
|
+
if (typeof service.system !== "function") continue;
|
|
257
|
+
try {
|
|
258
|
+
const text = String(await service.system(this.serviceContext)).trim();
|
|
259
|
+
if (!text) continue;
|
|
260
|
+
out.push(text);
|
|
261
|
+
} catch {
|
|
262
|
+
// 单个 service system 失败不应阻断 SDK session 主链路。
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return out;
|
|
266
|
+
}
|
|
267
|
+
|
|
170
268
|
private createRuntime(): AgentRuntime {
|
|
171
269
|
const runtime = {
|
|
172
270
|
cwd: this.path,
|
|
@@ -177,11 +275,7 @@ export class Agent {
|
|
|
177
275
|
globalEnv: {},
|
|
178
276
|
systems: this.systems,
|
|
179
277
|
paths: createAgentPathRuntime(this.path),
|
|
180
|
-
pluginConfig:
|
|
181
|
-
async persistProjectPlugins(): Promise<string> {
|
|
182
|
-
return "";
|
|
183
|
-
},
|
|
184
|
-
},
|
|
278
|
+
pluginConfig: createAgentPluginConfigRuntime(this.path),
|
|
185
279
|
model: undefined,
|
|
186
280
|
getSession: (sessionId: string) => {
|
|
187
281
|
return this.getOrCreateSession(sessionId).getServicePort() as never;
|
|
@@ -274,24 +368,7 @@ export class Agent {
|
|
|
274
368
|
},
|
|
275
369
|
enqueue: (params) => resolveChatQueueStore(context).enqueue(params),
|
|
276
370
|
},
|
|
277
|
-
plugins:
|
|
278
|
-
list: () => [],
|
|
279
|
-
availability: async () => ({
|
|
280
|
-
enabled: false,
|
|
281
|
-
available: false,
|
|
282
|
-
reasons: ["SDK Agent plugin runtime is not configured"],
|
|
283
|
-
}),
|
|
284
|
-
runAction: async () => ({
|
|
285
|
-
success: false,
|
|
286
|
-
error: "SDK Agent plugin runtime is not configured",
|
|
287
|
-
}),
|
|
288
|
-
pipeline: async <T>(_: string, value: T): Promise<T> => value,
|
|
289
|
-
guard: async (): Promise<void> => {},
|
|
290
|
-
effect: async (): Promise<void> => {},
|
|
291
|
-
resolve: async () => {
|
|
292
|
-
throw new Error("SDK Agent plugin resolve is not configured");
|
|
293
|
-
},
|
|
294
|
-
},
|
|
371
|
+
plugins: this.plugins,
|
|
295
372
|
};
|
|
296
373
|
return context;
|
|
297
374
|
}
|
|
@@ -309,6 +386,8 @@ export class Agent {
|
|
|
309
386
|
tools: this.tools,
|
|
310
387
|
logger: this.logger,
|
|
311
388
|
getStaticSystemPrompts: () => this.systems,
|
|
389
|
+
getServiceSystemPrompts: () => this.loadServiceSystemPrompts(),
|
|
390
|
+
getPluginSystemPrompts: () => this.loadPluginSystemPrompts(),
|
|
312
391
|
});
|
|
313
392
|
this.sessionsById.set(resolvedSessionId, created);
|
|
314
393
|
return created;
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 这里集中声明 `Agent` / `RemoteAgent` / `Session` 面向外部调用方的稳定接口。
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
6
|
+
* - SDK 用户通过显式 `tools` / `services` / `plugins` 装配能力,不直接依赖内部 runtime 单例。
|
|
7
|
+
* - 本地/远程 session 运行与基础落盘能力仍是 SDK 主路径。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { LanguageModel, Tool } from "ai";
|
|
11
11
|
import type { BaseService } from "@/service/builtins/BaseService.js";
|
|
12
12
|
import type { JsonValue } from "@/shared/types/Json.js";
|
|
13
|
+
import type { Plugin } from "@/shared/types/Plugin.js";
|
|
13
14
|
import type { SessionMessageV1 } from "@/types/session/SessionMessages.js";
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -48,6 +49,16 @@ export interface AgentOptions {
|
|
|
48
49
|
* - v1 推荐显式传入 `new ChatService(...)` 这类实例,而不是依赖包内隐式注册表。
|
|
49
50
|
*/
|
|
50
51
|
services?: BaseService[];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 当前 agent 显式注册的 plugin 定义集合。
|
|
55
|
+
*
|
|
56
|
+
* 关键点(中文)
|
|
57
|
+
* - 这里接收完整 plugin 定义对象,而不是 plugin 名称。
|
|
58
|
+
* - `Agent` 会为当前 SDK 实例创建独立 plugin registry,避免污染全局 runtime。
|
|
59
|
+
* - 同名 plugin 会直接报错,避免 action / hook / resolve 行为被静默覆盖。
|
|
60
|
+
*/
|
|
61
|
+
plugins?: Plugin[];
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
/**
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 面向 `Agent` SDK 的本地会话执行场景。
|
|
6
|
-
* -
|
|
7
|
-
* - 暂不把 service/plugin system 注入暴露到 SDK 主路径。
|
|
6
|
+
* - 注入静态 PROFILE / SOUL / core prompt、显式注入 service system、显式注册 plugin system 与运行时时钟上下文。
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
9
|
import { SessionSystemComposer } from "@session/composer/system/SessionSystemComposer.js";
|
|
@@ -22,6 +21,16 @@ type SdkSessionSystemComposerOptions = {
|
|
|
22
21
|
* 读取当前生效的静态 system 文本集合。
|
|
23
22
|
*/
|
|
24
23
|
getStaticSystemPrompts: () => string[];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 读取当前显式注册 plugin 的 system 文本集合。
|
|
27
|
+
*/
|
|
28
|
+
getPluginSystemPrompts: () => Promise<string[]>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 读取当前显式注入 service 的 system 文本集合。
|
|
32
|
+
*/
|
|
33
|
+
getServiceSystemPrompts: () => Promise<string[]>;
|
|
25
34
|
};
|
|
26
35
|
|
|
27
36
|
/**
|
|
@@ -32,11 +41,15 @@ export class SdkSessionSystemComposer extends SessionSystemComposer {
|
|
|
32
41
|
|
|
33
42
|
private readonly projectRoot: string;
|
|
34
43
|
private readonly getStaticSystemPrompts: SdkSessionSystemComposerOptions["getStaticSystemPrompts"];
|
|
44
|
+
private readonly getServiceSystemPrompts: SdkSessionSystemComposerOptions["getServiceSystemPrompts"];
|
|
45
|
+
private readonly getPluginSystemPrompts: SdkSessionSystemComposerOptions["getPluginSystemPrompts"];
|
|
35
46
|
|
|
36
47
|
constructor(options: SdkSessionSystemComposerOptions) {
|
|
37
48
|
super();
|
|
38
49
|
this.projectRoot = String(options.projectRoot || "").trim();
|
|
39
50
|
this.getStaticSystemPrompts = options.getStaticSystemPrompts;
|
|
51
|
+
this.getServiceSystemPrompts = options.getServiceSystemPrompts;
|
|
52
|
+
this.getPluginSystemPrompts = options.getPluginSystemPrompts;
|
|
40
53
|
if (!this.projectRoot) {
|
|
41
54
|
throw new Error("SdkSessionSystemComposer requires a non-empty projectRoot");
|
|
42
55
|
}
|
|
@@ -61,9 +74,33 @@ export class SdkSessionSystemComposer extends SessionSystemComposer {
|
|
|
61
74
|
variableMode: "stable",
|
|
62
75
|
},
|
|
63
76
|
);
|
|
77
|
+
const servicePrompts = (await this.getServiceSystemPrompts()).filter((item) =>
|
|
78
|
+
String(item || "").trim(),
|
|
79
|
+
);
|
|
80
|
+
const serviceMessages = await transformPromptsIntoSystemMessages(
|
|
81
|
+
servicePrompts,
|
|
82
|
+
{
|
|
83
|
+
projectPath: this.projectRoot,
|
|
84
|
+
sessionId,
|
|
85
|
+
variableMode: "stable",
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
const pluginPrompts = (await this.getPluginSystemPrompts()).filter((item) =>
|
|
89
|
+
String(item || "").trim(),
|
|
90
|
+
);
|
|
91
|
+
const pluginMessages = await transformPromptsIntoSystemMessages(
|
|
92
|
+
pluginPrompts,
|
|
93
|
+
{
|
|
94
|
+
projectPath: this.projectRoot,
|
|
95
|
+
sessionId,
|
|
96
|
+
variableMode: "stable",
|
|
97
|
+
},
|
|
98
|
+
);
|
|
64
99
|
|
|
65
100
|
return [
|
|
66
101
|
...staticMessages,
|
|
102
|
+
...serviceMessages,
|
|
103
|
+
...pluginMessages,
|
|
67
104
|
{
|
|
68
105
|
role: "system" as const,
|
|
69
106
|
content: buildRuntimeClockSystemPrompt({
|
package/src/host/sdk/Session.ts
CHANGED
|
@@ -73,6 +73,16 @@ type SdkSessionOptions = {
|
|
|
73
73
|
* 读取静态 system 文本集合。
|
|
74
74
|
*/
|
|
75
75
|
getStaticSystemPrompts: () => string[];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 读取当前 agent 显式注入 service 的 system 文本集合。
|
|
79
|
+
*/
|
|
80
|
+
getServiceSystemPrompts: () => Promise<string[]>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 读取当前 agent 显式注册 plugin 的 system 文本集合。
|
|
84
|
+
*/
|
|
85
|
+
getPluginSystemPrompts: () => Promise<string[]>;
|
|
76
86
|
};
|
|
77
87
|
|
|
78
88
|
/**
|
|
@@ -86,6 +96,8 @@ export class SdkSession {
|
|
|
86
96
|
private readonly tools: Record<string, Tool>;
|
|
87
97
|
private readonly logger: SdkSessionOptions["logger"];
|
|
88
98
|
private readonly getStaticSystemPrompts: SdkSessionOptions["getStaticSystemPrompts"];
|
|
99
|
+
private readonly getServiceSystemPrompts: SdkSessionOptions["getServiceSystemPrompts"];
|
|
100
|
+
private readonly getPluginSystemPrompts: SdkSessionOptions["getPluginSystemPrompts"];
|
|
89
101
|
private readonly historyComposer: JsonlSessionHistoryComposer;
|
|
90
102
|
private readonly coreSession: CoreSession;
|
|
91
103
|
private sessionConfig: AgentSessionConfigSnapshot = {};
|
|
@@ -99,6 +111,8 @@ export class SdkSession {
|
|
|
99
111
|
this.tools = options.tools;
|
|
100
112
|
this.logger = options.logger;
|
|
101
113
|
this.getStaticSystemPrompts = options.getStaticSystemPrompts;
|
|
114
|
+
this.getServiceSystemPrompts = options.getServiceSystemPrompts;
|
|
115
|
+
this.getPluginSystemPrompts = options.getPluginSystemPrompts;
|
|
102
116
|
if (!this.id) {
|
|
103
117
|
throw new Error("SdkSession requires a non-empty sessionId");
|
|
104
118
|
}
|
|
@@ -149,6 +163,8 @@ export class SdkSession {
|
|
|
149
163
|
systemComposer: new SdkSessionSystemComposer({
|
|
150
164
|
projectRoot: this.projectRoot,
|
|
151
165
|
getStaticSystemPrompts: this.getStaticSystemPrompts,
|
|
166
|
+
getServiceSystemPrompts: this.getServiceSystemPrompts,
|
|
167
|
+
getPluginSystemPrompts: this.getPluginSystemPrompts,
|
|
152
168
|
}),
|
|
153
169
|
getTools: () => this.tools,
|
|
154
170
|
});
|
|
@@ -356,6 +372,8 @@ export class SdkSession {
|
|
|
356
372
|
tools: this.tools,
|
|
357
373
|
logger: this.logger,
|
|
358
374
|
getStaticSystemPrompts: this.getStaticSystemPrompts,
|
|
375
|
+
getServiceSystemPrompts: this.getServiceSystemPrompts,
|
|
376
|
+
getPluginSystemPrompts: this.getPluginSystemPrompts,
|
|
359
377
|
});
|
|
360
378
|
await forked.initialize();
|
|
361
379
|
if (this.sessionConfig.model) {
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export type {
|
|
|
20
20
|
AgentSessionMetadata,
|
|
21
21
|
AgentSessionForkInput,
|
|
22
22
|
} from "./host/sdk/AgentSdkTypes.js";
|
|
23
|
+
export { BaseService } from "./service/builtins/BaseService.js";
|
|
23
24
|
export { ChatService } from "./service/builtins/chat/ChatService.js";
|
|
24
25
|
export { ChatChannelAccountService } from "./service/builtins/chat/accounts/ChannelAccountService.js";
|
|
25
26
|
export type { ChatChannelAccountListItem } from "./service/builtins/chat/types/ChannelAccount.js";
|
|
@@ -188,6 +189,12 @@ export {
|
|
|
188
189
|
setChatAuthorizationUserRole,
|
|
189
190
|
} from "./plugins/auth/runtime/AuthorizationConfig.js";
|
|
190
191
|
export { resolveAuthorizedUserRole } from "./plugins/auth/runtime/AuthorizationPolicy.js";
|
|
192
|
+
export { authPlugin } from "./plugins/auth/Plugin.js";
|
|
193
|
+
export { skillPlugin } from "./plugins/skill/Plugin.js";
|
|
194
|
+
export { webPlugin } from "./plugins/web/Plugin.js";
|
|
195
|
+
export { asrPlugin } from "./plugins/asr/Plugin.js";
|
|
196
|
+
export { ttsPlugin } from "./plugins/tts/Plugin.js";
|
|
197
|
+
export { workboardPlugin } from "./plugins/workboard/Plugin.js";
|
|
191
198
|
|
|
192
199
|
// Agent 项目准备
|
|
193
200
|
export {
|