@gt-fe/eap-runtime 0.0.8 → 0.0.11
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/README.md +15 -20
- package/dist/api/handlers/invoke.handler.js +7 -3
- package/dist/api/handlers/messages.handler.js +0 -1
- package/dist/api/handlers/stream.handler.js +8 -4
- package/dist/api/routes/agent.routes.d.ts +2 -2
- package/dist/api/routes/agent.routes.js +2 -2
- package/dist/checkpoint/checkpoint-ref-notify.d.ts +10 -0
- package/dist/checkpoint/checkpoint-ref-notify.js +59 -0
- package/dist/checkpoint/index.d.ts +1 -0
- package/dist/checkpoint/index.js +1 -0
- package/dist/checkpoint/pg-checkpoint-saver.js +25 -2
- package/dist/common/agent-code.d.ts +2 -4
- package/dist/common/agent-code.js +4 -5
- package/dist/common/types.d.ts +5 -5
- package/dist/common/types.js +2 -2
- package/dist/contracts/permission-checker.d.ts +1 -1
- package/dist/contracts/trace-collector.d.ts +16 -2
- package/dist/debug/llm-turn-log.d.ts +100 -0
- package/dist/debug/llm-turn-log.js +130 -0
- package/dist/debug/pg-llm-turn-log.d.ts +22 -0
- package/dist/debug/pg-llm-turn-log.js +57 -0
- package/dist/governance/governance-client.d.ts +1 -1
- package/dist/governance/governance-client.js +40 -16
- package/dist/governance/index.d.ts +2 -2
- package/dist/governance/index.js +1 -1
- package/dist/governance/permission-guard.d.ts +2 -1
- package/dist/governance/permission-guard.js +13 -4
- package/dist/graph/adapters/langgraph-checkpointer.js +3 -1
- package/dist/graph/adapters/langgraph.adapter.d.ts +1 -0
- package/dist/graph/adapters/langgraph.adapter.js +153 -92
- package/dist/graph/adapters/skill-read.d.ts +12 -0
- package/dist/graph/adapters/skill-read.js +63 -0
- package/dist/graph/adapters/subgraph-compiler.js +5 -0
- package/dist/graph/contracts/executable-graph.d.ts +11 -9
- package/dist/graph/contracts/executable-graph.js +1 -1
- package/dist/graph/hitl/hitl-handler.d.ts +10 -0
- package/dist/graph/hitl/hitl-handler.js +50 -6
- package/dist/graph/nodes/llm-node.d.ts +14 -0
- package/dist/graph/nodes/skill-bind-node.js +1 -2
- package/dist/graph/nodes/tool-node.d.ts +2 -0
- package/dist/graph/nodes/tool-node.js +50 -10
- package/dist/graph/trace-span.d.ts +22 -0
- package/dist/graph/trace-span.js +69 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +3 -1
- package/dist/memory/compression/compression.repository.d.ts +1 -15
- package/dist/providers/echo-llm-provider.d.ts +1 -1
- package/dist/providers/echo-llm-provider.js +4 -3
- package/dist/providers/http-llm-provider.d.ts +4 -0
- package/dist/providers/http-llm-provider.js +129 -4
- package/dist/providers/local-llm-provider.d.ts +5 -1
- package/dist/providers/local-llm-provider.js +14 -6
- package/dist/providers/routing-llm-provider.d.ts +4 -0
- package/dist/providers/routing-llm-provider.js +12 -2
- package/dist/registry/agent-models.d.ts +1 -1
- package/dist/registry/agent-models.js +1 -1
- package/dist/registry/agent-registry-client.d.ts +3 -3
- package/dist/registry/deployment-snapshot.d.ts +17 -5
- package/dist/registry/deployment-snapshot.js +97 -49
- package/dist/registry/graph-loader.d.ts +2 -2
- package/dist/registry/graph-loader.js +43 -80
- package/dist/registry/index.d.ts +2 -2
- package/dist/registry/index.js +2 -2
- package/dist/registry/preload-errors.d.ts +1 -1
- package/dist/registry/preload-errors.js +1 -1
- package/dist/registry/skill-io-guard.js +1 -1
- package/dist/registry/skill-tree.d.ts +3 -0
- package/dist/registry/skill-tree.js +41 -3
- package/dist/runtime/agent-runtime.d.ts +42 -3
- package/dist/runtime/agent-runtime.js +129 -39
- package/dist/runtime/dev-runtime.d.ts +7 -4
- package/dist/runtime/dev-runtime.js +24 -21
- package/dist/runtime/index.d.ts +3 -3
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/storage-profile.d.ts +19 -10
- package/dist/runtime/storage-profile.js +42 -29
- package/dist/runtime/types.d.ts +17 -19
- package/dist/server.js +2 -2
- package/dist/session/session.service.d.ts +5 -0
- package/dist/session/session.service.js +12 -0
- package/dist/sse/events/index.d.ts +5 -3
- package/dist/sse/events/index.js +2 -0
- package/dist/sse/events/skill-events.d.ts +12 -1
- package/dist/sse/events/skill-events.js +1 -1
- package/dist/sse/trace-collector.d.ts +10 -0
- package/dist/sse/trace-collector.js +1 -0
- package/dist/token/token-budget.service.d.ts +2 -2
- package/dist/token/token-budget.service.js +1 -1
- package/dist/tool/create-tool-executor.d.ts +1 -1
- package/dist/tool/create-tool-executor.js +3 -2
- package/dist/tool/dev-http-executor.d.ts +1 -1
- package/dist/tool/dev-http-executor.js +10 -7
- package/dist/tool/dev-mcp-executor.js +5 -3
- package/dist/tool/dev-tool-executor.d.ts +1 -1
- package/dist/tool/dev-tool-executor.js +2 -2
- package/dist/tool/harness-command.d.ts +32 -0
- package/dist/tool/harness-command.js +276 -0
- package/dist/tool/harness-primitives.d.ts +54 -0
- package/dist/tool/harness-primitives.js +492 -0
- package/dist/tool/http-tool-executor.js +16 -21
- package/dist/tool/index.d.ts +4 -2
- package/dist/tool/index.js +4 -2
- package/dist/tool/local-mcp-client.d.ts +1 -1
- package/dist/tool/local-mcp-client.js +54 -23
- package/dist/tool/local-tool-executor.d.ts +4 -4
- package/dist/tool/local-tool-executor.js +18 -16
- package/dist/tool/mcp-tool-executor.js +23 -7
- package/dist/tool/skill-script-refs.d.ts +20 -0
- package/dist/tool/skill-script-refs.js +62 -0
- package/dist/tool/system-prompt-builder.d.ts +61 -25
- package/dist/tool/system-prompt-builder.js +198 -92
- package/dist/tool/timeout.d.ts +14 -0
- package/dist/tool/timeout.js +36 -0
- package/dist/tool/tool-confirmation.js +2 -1
- package/dist/tool/tool-execution-router.d.ts +1 -1
- package/dist/tool/tool-execution-router.js +2 -2
- package/dist/tool/tool-executor.interface.d.ts +23 -7
- package/dist/tool/tool-orchestrator.d.ts +1 -1
- package/dist/tool/tool-orchestrator.js +6 -3
- package/dist/utils/format-error.d.ts +2 -2
- package/dist/utils/format-error.js +2 -2
- package/dist/utils/http-error.d.ts +2 -2
- package/dist/utils/http-error.js +2 -2
- package/package.json +3 -3
- package/dist/common/concurrency.d.ts +0 -79
- package/dist/common/concurrency.js +0 -121
- package/dist/common/queue-consumer.d.ts +0 -125
- package/dist/common/queue-consumer.js +0 -159
- package/dist/tool/mock-tool-executor.d.ts +0 -28
- package/dist/tool/mock-tool-executor.js +0 -65
|
@@ -7,16 +7,63 @@
|
|
|
7
7
|
* - tool_calls 解析(同步 & 流式)
|
|
8
8
|
*/
|
|
9
9
|
import { resolveLlmModelName } from './resolve-llm-model.js';
|
|
10
|
+
import { createFileLlmTurnLogFromEnv, maskApiKey } from '../debug/llm-turn-log.js';
|
|
10
11
|
export class HttpLLMProvider {
|
|
11
12
|
apiKey;
|
|
12
13
|
baseUrl;
|
|
13
14
|
defaultModel;
|
|
14
15
|
timeoutMs;
|
|
16
|
+
turnLog;
|
|
15
17
|
constructor(config) {
|
|
16
18
|
this.apiKey = config.apiKey;
|
|
17
19
|
this.baseUrl = (config.baseUrl ?? 'https://api.openai.com/v1').replace(/\/$/, '');
|
|
18
20
|
this.defaultModel = config.defaultModel ?? 'DeepSeek-V4-Pro';
|
|
19
21
|
this.timeoutMs = config.timeoutMs ?? 60000;
|
|
22
|
+
this.turnLog = 'turnLog' in config ? config.turnLog : createFileLlmTurnLogFromEnv();
|
|
23
|
+
}
|
|
24
|
+
async writeTurn(args) {
|
|
25
|
+
if (!this.turnLog)
|
|
26
|
+
return;
|
|
27
|
+
const model = resolveLlmModelName(args.config.model, this.defaultModel);
|
|
28
|
+
try {
|
|
29
|
+
await this.turnLog.record({
|
|
30
|
+
...args.config.turn,
|
|
31
|
+
url: args.url,
|
|
32
|
+
model,
|
|
33
|
+
temperature: args.config.temperature,
|
|
34
|
+
maxTokens: args.config.maxTokens,
|
|
35
|
+
apiKey: maskApiKey(this.apiKey),
|
|
36
|
+
systemPrompt: args.config.systemPrompt,
|
|
37
|
+
systemSections: args.config.systemSections?.map((section) => ({
|
|
38
|
+
id: section.id,
|
|
39
|
+
title: section.title,
|
|
40
|
+
chars: section.body.length,
|
|
41
|
+
body: section.body,
|
|
42
|
+
})),
|
|
43
|
+
tools: args.config.tools?.map((tool) => tool.function.name),
|
|
44
|
+
messages: args.messages.map((message) => ({
|
|
45
|
+
role: message.role,
|
|
46
|
+
content: message.content,
|
|
47
|
+
toolCallId: message.toolCallId,
|
|
48
|
+
toolCalls: message.toolCalls,
|
|
49
|
+
})),
|
|
50
|
+
response: {
|
|
51
|
+
content: args.response.content,
|
|
52
|
+
toolCalls: args.response.toolCalls,
|
|
53
|
+
reasoningContent: args.response.reasoningContent,
|
|
54
|
+
inputTokens: args.response.inputTokens,
|
|
55
|
+
outputTokens: args.response.outputTokens,
|
|
56
|
+
finishReason: args.response.finishReason,
|
|
57
|
+
error: args.response.error,
|
|
58
|
+
},
|
|
59
|
+
latencyMs: Date.now() - args.startedAt,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
if (process.env.EAP_LLM_DEBUG === '1') {
|
|
64
|
+
console.warn('[LLM-TURN] write failed', err);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
20
67
|
}
|
|
21
68
|
async invoke(messages, config) {
|
|
22
69
|
const body = this.buildRequestBody(messages, config, false);
|
|
@@ -52,6 +99,7 @@ export class HttpLLMProvider {
|
|
|
52
99
|
const controller = new AbortController();
|
|
53
100
|
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
54
101
|
const url = `${this.baseUrl}/chat/completions`;
|
|
102
|
+
const startedAt = Date.now();
|
|
55
103
|
try {
|
|
56
104
|
let response;
|
|
57
105
|
try {
|
|
@@ -90,7 +138,7 @@ export class HttpLLMProvider {
|
|
|
90
138
|
usage: data.usage,
|
|
91
139
|
}, null, 2));
|
|
92
140
|
}
|
|
93
|
-
|
|
141
|
+
const result = {
|
|
94
142
|
content,
|
|
95
143
|
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
96
144
|
...(reasoningContent ? { reasoningContent } : {}),
|
|
@@ -99,6 +147,37 @@ export class HttpLLMProvider {
|
|
|
99
147
|
// model 字段优先级:config(用户显式配置) > data.model(网关返回,可能是路由别名如 "/mnt/fast") > defaultModel
|
|
100
148
|
model: config.model ?? (typeof data.model === 'string' && !data.model.includes('/') ? data.model : undefined) ?? this.defaultModel,
|
|
101
149
|
};
|
|
150
|
+
await this.writeTurn({
|
|
151
|
+
url,
|
|
152
|
+
messages,
|
|
153
|
+
config,
|
|
154
|
+
startedAt,
|
|
155
|
+
response: {
|
|
156
|
+
content: result.content,
|
|
157
|
+
toolCalls: result.toolCalls,
|
|
158
|
+
reasoningContent: result.reasoningContent,
|
|
159
|
+
inputTokens: result.inputTokens,
|
|
160
|
+
outputTokens: result.outputTokens,
|
|
161
|
+
finishReason: choice?.finish_reason,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
await this.writeTurn({
|
|
168
|
+
url,
|
|
169
|
+
messages,
|
|
170
|
+
config,
|
|
171
|
+
startedAt,
|
|
172
|
+
response: {
|
|
173
|
+
content: '',
|
|
174
|
+
inputTokens: 0,
|
|
175
|
+
outputTokens: 0,
|
|
176
|
+
finishReason: 'error',
|
|
177
|
+
error: err instanceof Error ? err.message : String(err),
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
throw err;
|
|
102
181
|
}
|
|
103
182
|
finally {
|
|
104
183
|
clearTimeout(timeout);
|
|
@@ -136,6 +215,13 @@ export class HttpLLMProvider {
|
|
|
136
215
|
const controller = new AbortController();
|
|
137
216
|
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
138
217
|
const url = `${this.baseUrl}/chat/completions`;
|
|
218
|
+
const startedAt = Date.now();
|
|
219
|
+
const contentChunks = [];
|
|
220
|
+
const reasoningChunks = [];
|
|
221
|
+
const toolCallAccumulators = new Map();
|
|
222
|
+
let inputTokens = 0;
|
|
223
|
+
let outputTokens = 0;
|
|
224
|
+
let lastFinishReason;
|
|
139
225
|
try {
|
|
140
226
|
let response;
|
|
141
227
|
try {
|
|
@@ -163,9 +249,6 @@ export class HttpLLMProvider {
|
|
|
163
249
|
const reader = response.body.getReader();
|
|
164
250
|
const decoder = new TextDecoder();
|
|
165
251
|
let buffer = '';
|
|
166
|
-
const toolCallAccumulators = new Map();
|
|
167
|
-
let inputTokens = 0;
|
|
168
|
-
let outputTokens = 0;
|
|
169
252
|
let usageEmitted = false;
|
|
170
253
|
let model = config.model ?? this.defaultModel;
|
|
171
254
|
while (true) {
|
|
@@ -200,6 +283,8 @@ export class HttpLLMProvider {
|
|
|
200
283
|
}
|
|
201
284
|
const delta = chunk.choices?.[0]?.delta;
|
|
202
285
|
const finishReason = chunk.choices?.[0]?.finish_reason;
|
|
286
|
+
if (finishReason)
|
|
287
|
+
lastFinishReason = finishReason;
|
|
203
288
|
// 累积 tool_calls delta
|
|
204
289
|
if (delta?.tool_calls) {
|
|
205
290
|
for (const tc of delta.tool_calls) {
|
|
@@ -223,6 +308,10 @@ export class HttpLLMProvider {
|
|
|
223
308
|
// 产出内容 / reasoning chunk
|
|
224
309
|
const content = delta?.content ?? '';
|
|
225
310
|
const reasoningContent = typeof delta?.reasoning_content === 'string' ? delta.reasoning_content : '';
|
|
311
|
+
if (content)
|
|
312
|
+
contentChunks.push(content);
|
|
313
|
+
if (reasoningContent)
|
|
314
|
+
reasoningChunks.push(reasoningContent);
|
|
226
315
|
const isEnd = finishReason === 'stop' || finishReason === 'tool_calls';
|
|
227
316
|
const hasUsage = Boolean(chunk.usage);
|
|
228
317
|
if (content || reasoningContent || isEnd) {
|
|
@@ -281,6 +370,42 @@ export class HttpLLMProvider {
|
|
|
281
370
|
outputTokens,
|
|
282
371
|
}, null, 2));
|
|
283
372
|
}
|
|
373
|
+
await this.writeTurn({
|
|
374
|
+
url,
|
|
375
|
+
messages,
|
|
376
|
+
config,
|
|
377
|
+
startedAt,
|
|
378
|
+
response: {
|
|
379
|
+
content: contentChunks.join(''),
|
|
380
|
+
toolCalls: toolCallAccumulators.size > 0
|
|
381
|
+
? this.finalizeToolCalls(toolCallAccumulators)
|
|
382
|
+
: undefined,
|
|
383
|
+
reasoningContent: reasoningChunks.length > 0 ? reasoningChunks.join('') : undefined,
|
|
384
|
+
inputTokens,
|
|
385
|
+
outputTokens,
|
|
386
|
+
finishReason: lastFinishReason,
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
catch (err) {
|
|
391
|
+
await this.writeTurn({
|
|
392
|
+
url,
|
|
393
|
+
messages,
|
|
394
|
+
config,
|
|
395
|
+
startedAt,
|
|
396
|
+
response: {
|
|
397
|
+
content: contentChunks.join(''),
|
|
398
|
+
toolCalls: toolCallAccumulators.size > 0
|
|
399
|
+
? this.finalizeToolCalls(toolCallAccumulators)
|
|
400
|
+
: undefined,
|
|
401
|
+
reasoningContent: reasoningChunks.length > 0 ? reasoningChunks.join('') : undefined,
|
|
402
|
+
inputTokens,
|
|
403
|
+
outputTokens,
|
|
404
|
+
finishReason: 'error',
|
|
405
|
+
error: err instanceof Error ? err.message : String(err),
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
throw err;
|
|
284
409
|
}
|
|
285
410
|
finally {
|
|
286
411
|
clearTimeout(timeout);
|
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
* 连接表里只带 apiKeyEnv,密钥从 process.env 读取,不进 JSON。
|
|
4
4
|
*/
|
|
5
5
|
import type { ILLMProvider } from '../graph/nodes/llm-node.js';
|
|
6
|
+
import type { ILlmTurnLog } from '../debug/llm-turn-log.js';
|
|
7
|
+
import { type ModelCallDefaults } from '@eap/contracts';
|
|
6
8
|
export interface LocalLlmConnection {
|
|
7
9
|
baseUrl: string;
|
|
8
10
|
apiKey: string;
|
|
11
|
+
defaults?: ModelCallDefaults;
|
|
9
12
|
}
|
|
10
13
|
export interface LocalLlmConnectionRef {
|
|
11
14
|
baseUrl: string;
|
|
12
15
|
apiKeyEnv: string;
|
|
16
|
+
defaults?: ModelCallDefaults;
|
|
13
17
|
}
|
|
14
18
|
export interface LocalLlmConnectionRefs {
|
|
15
19
|
default?: LocalLlmConnectionRef;
|
|
@@ -24,4 +28,4 @@ export declare function parseLocalLlmConnectionRefs(env?: NodeJS.ProcessEnv): Lo
|
|
|
24
28
|
export declare function hydrateLocalLlmConnections(refs: LocalLlmConnectionRefs, env?: NodeJS.ProcessEnv): LocalLlmConnections;
|
|
25
29
|
export declare function requireLocalLlmConnections(env?: NodeJS.ProcessEnv): LocalLlmConnections;
|
|
26
30
|
export declare function resolveLocalLlmConnection(connections: LocalLlmConnections, model?: string): LocalLlmConnection;
|
|
27
|
-
export declare function createLocalLlmProvider(connections?: LocalLlmConnections): ILLMProvider;
|
|
31
|
+
export declare function createLocalLlmProvider(connections?: LocalLlmConnections, turnLog?: ILlmTurnLog): ILLMProvider;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* 本地多模型 LLM:按节点 model 选网关。仅 dev。
|
|
3
3
|
* 连接表里只带 apiKeyEnv,密钥从 process.env 读取,不进 JSON。
|
|
4
4
|
*/
|
|
5
|
+
import { mergeModelCallParams } from '@eap/contracts';
|
|
5
6
|
import { HttpLLMProvider } from './http-llm-provider.js';
|
|
6
7
|
export const LLM_CONNECTIONS_ENV = 'EAP_LLM_CONNECTIONS';
|
|
7
8
|
export function parseLocalLlmConnectionRefs(env = process.env) {
|
|
@@ -41,7 +42,7 @@ export function hydrateLocalLlmConnections(refs, env = process.env) {
|
|
|
41
42
|
const apiKey = env[ref.apiKeyEnv]?.trim();
|
|
42
43
|
if (!apiKey)
|
|
43
44
|
return undefined;
|
|
44
|
-
return { baseUrl: ref.baseUrl, apiKey };
|
|
45
|
+
return { baseUrl: ref.baseUrl, apiKey, defaults: ref.defaults };
|
|
45
46
|
};
|
|
46
47
|
const byModel = {};
|
|
47
48
|
for (const [name, ref] of Object.entries(refs.byModel ?? {})) {
|
|
@@ -73,20 +74,26 @@ export function resolveLocalLlmConnection(connections, model) {
|
|
|
73
74
|
}
|
|
74
75
|
return connection;
|
|
75
76
|
}
|
|
76
|
-
export function createLocalLlmProvider(connections = requireLocalLlmConnections()) {
|
|
77
|
-
return new LocalLlmProvider(connections);
|
|
77
|
+
export function createLocalLlmProvider(connections = requireLocalLlmConnections(), turnLog) {
|
|
78
|
+
return new LocalLlmProvider(connections, turnLog);
|
|
78
79
|
}
|
|
79
80
|
class LocalLlmProvider {
|
|
80
81
|
connections;
|
|
82
|
+
turnLog;
|
|
81
83
|
cache = new Map();
|
|
82
|
-
constructor(connections) {
|
|
84
|
+
constructor(connections, turnLog) {
|
|
83
85
|
this.connections = connections;
|
|
86
|
+
this.turnLog = turnLog;
|
|
84
87
|
}
|
|
85
88
|
invoke(messages, config) {
|
|
86
|
-
|
|
89
|
+
const connection = resolveLocalLlmConnection(this.connections, config.model);
|
|
90
|
+
const merged = mergeModelCallParams(config, connection.defaults);
|
|
91
|
+
return this.providerFor(config.model).invoke(messages, { ...config, ...merged });
|
|
87
92
|
}
|
|
88
93
|
stream(messages, config) {
|
|
89
|
-
|
|
94
|
+
const connection = resolveLocalLlmConnection(this.connections, config.model);
|
|
95
|
+
const merged = mergeModelCallParams(config, connection.defaults);
|
|
96
|
+
return this.providerFor(config.model).stream(messages, { ...config, ...merged });
|
|
90
97
|
}
|
|
91
98
|
providerFor(model) {
|
|
92
99
|
const connection = resolveLocalLlmConnection(this.connections, model);
|
|
@@ -98,6 +105,7 @@ class LocalLlmProvider {
|
|
|
98
105
|
apiKey: connection.apiKey,
|
|
99
106
|
baseUrl: connection.baseUrl,
|
|
100
107
|
defaultModel: model,
|
|
108
|
+
turnLog: this.turnLog,
|
|
101
109
|
});
|
|
102
110
|
this.cache.set(cacheKey, provider);
|
|
103
111
|
return provider;
|
|
@@ -13,16 +13,20 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { GraphMessage } from '../graph/contracts/executable-graph.js';
|
|
15
15
|
import type { ILLMProvider, LLMNodeConfig, LLMResponse, LLMChunk } from '../graph/nodes/llm-node.js';
|
|
16
|
+
import type { ILlmTurnLog } from '../debug/llm-turn-log.js';
|
|
16
17
|
export interface RoutingLLMProviderConfig {
|
|
17
18
|
foundationUrl: string;
|
|
18
19
|
fallbackProvider?: ILLMProvider;
|
|
20
|
+
turnLog?: ILlmTurnLog;
|
|
19
21
|
}
|
|
20
22
|
export declare class RoutingLLMProvider implements ILLMProvider {
|
|
21
23
|
private readonly foundationUrl;
|
|
22
24
|
private readonly fallback;
|
|
25
|
+
private readonly turnLog?;
|
|
23
26
|
constructor(config: RoutingLLMProviderConfig);
|
|
24
27
|
invoke(messages: GraphMessage[], config: LLMNodeConfig): Promise<LLMResponse>;
|
|
25
28
|
stream(messages: GraphMessage[], config: LLMNodeConfig): AsyncIterableIterator<LLMChunk>;
|
|
29
|
+
private withCallDefaults;
|
|
26
30
|
private selectModel;
|
|
27
31
|
private createProviderForModel;
|
|
28
32
|
}
|
|
@@ -11,24 +11,31 @@
|
|
|
11
11
|
* - 支持任意 OpenAI 兼容 API(OpenAI / DeepSeek / 本地 Ollama 等)
|
|
12
12
|
* - 连接配置由 Foundation 统一管理,Runtime 无感知
|
|
13
13
|
*/
|
|
14
|
+
import { mergeModelCallParams } from '@eap/contracts';
|
|
14
15
|
import { EchoLLMProvider } from './echo-llm-provider.js';
|
|
15
16
|
import { HttpLLMProvider } from './http-llm-provider.js';
|
|
16
17
|
export class RoutingLLMProvider {
|
|
17
18
|
foundationUrl;
|
|
18
19
|
fallback;
|
|
20
|
+
turnLog;
|
|
19
21
|
constructor(config) {
|
|
20
22
|
this.foundationUrl = config.foundationUrl.replace(/\/$/, '');
|
|
21
23
|
this.fallback = config.fallbackProvider ?? new EchoLLMProvider();
|
|
24
|
+
this.turnLog = config.turnLog;
|
|
22
25
|
}
|
|
23
26
|
async invoke(messages, config) {
|
|
24
27
|
const selected = await this.selectModel(config);
|
|
25
28
|
const provider = this.createProviderForModel(selected);
|
|
26
|
-
return provider.invoke(messages,
|
|
29
|
+
return provider.invoke(messages, this.withCallDefaults(config, selected));
|
|
27
30
|
}
|
|
28
31
|
async *stream(messages, config) {
|
|
29
32
|
const selected = await this.selectModel(config);
|
|
30
33
|
const provider = this.createProviderForModel(selected);
|
|
31
|
-
yield* provider.stream(messages,
|
|
34
|
+
yield* provider.stream(messages, this.withCallDefaults(config, selected));
|
|
35
|
+
}
|
|
36
|
+
withCallDefaults(config, selected) {
|
|
37
|
+
const merged = mergeModelCallParams(config, selected.defaults);
|
|
38
|
+
return { ...config, ...merged, model: selected.name };
|
|
32
39
|
}
|
|
33
40
|
async selectModel(config) {
|
|
34
41
|
try {
|
|
@@ -47,6 +54,7 @@ export class RoutingLLMProvider {
|
|
|
47
54
|
name: body.data.name,
|
|
48
55
|
provider: body.data.provider,
|
|
49
56
|
connection: body.data.connection ?? null,
|
|
57
|
+
defaults: body.data.defaults ?? null,
|
|
50
58
|
};
|
|
51
59
|
}
|
|
52
60
|
}
|
|
@@ -64,6 +72,7 @@ export class RoutingLLMProvider {
|
|
|
64
72
|
baseUrl: selected.connection.baseUrl,
|
|
65
73
|
defaultModel: selected.name,
|
|
66
74
|
timeoutMs: selected.connection.timeoutMs,
|
|
75
|
+
turnLog: this.turnLog,
|
|
67
76
|
});
|
|
68
77
|
}
|
|
69
78
|
// Fallback: 兼容旧逻辑(直接读 env)—— 开发环境快速启动用
|
|
@@ -72,6 +81,7 @@ export class RoutingLLMProvider {
|
|
|
72
81
|
apiKey: process.env.OPENAI_API_KEY,
|
|
73
82
|
baseUrl: process.env.OPENAI_BASE_URL,
|
|
74
83
|
defaultModel: selected.name,
|
|
84
|
+
turnLog: this.turnLog,
|
|
75
85
|
});
|
|
76
86
|
}
|
|
77
87
|
return this.fallback;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { resolveDeclaredModels,
|
|
1
|
+
export { resolveDeclaredModels, resolveAgentDefaultModel, resolveAgentModelAllowlist, } from '@eap/contracts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { resolveDeclaredModels,
|
|
1
|
+
export { resolveDeclaredModels, resolveAgentDefaultModel, resolveAgentModelAllowlist, } from '@eap/contracts';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Agent Registry 客户端 — 从 foundation-service 拉取 Agent 定义
|
|
3
3
|
*/
|
|
4
|
-
/** Agent 清单(与 @
|
|
4
|
+
/** Agent 清单(与 @eap/contracts AgentManifest 对齐) */
|
|
5
5
|
export interface AgentManifest {
|
|
6
6
|
id: string;
|
|
7
7
|
name: string;
|
|
@@ -12,8 +12,8 @@ export interface AgentManifest {
|
|
|
12
12
|
skills: string[];
|
|
13
13
|
prompts: Record<string, string>;
|
|
14
14
|
models?: {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
default: string;
|
|
16
|
+
allowed?: string[];
|
|
17
17
|
};
|
|
18
18
|
config?: {
|
|
19
19
|
timeout?: number;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* {root}/agents/<agentCode>/<version>/users/<userId>/skills/<skillCode>/
|
|
8
8
|
*
|
|
9
9
|
* 命名:agentCode / toolsetCode / skillCode / toolName 均为语义化小写标识;
|
|
10
|
-
* Skill
|
|
10
|
+
* Skill 目录无版本层:包内必含 SKILL.md(Agent Skills)。
|
|
11
11
|
*/
|
|
12
12
|
export interface SnapshotToolRef {
|
|
13
13
|
toolId?: string;
|
|
@@ -17,7 +17,7 @@ export interface SnapshotToolRef {
|
|
|
17
17
|
sha256?: string;
|
|
18
18
|
/**
|
|
19
19
|
* 可选白名单:列出则仅启用所列子工具;省略 = 启用该 toolset 下全部子工具。
|
|
20
|
-
* @see agent.manifest
|
|
20
|
+
* @see agent.manifest toolsets[].enabled
|
|
21
21
|
*/
|
|
22
22
|
enabledTools?: string[];
|
|
23
23
|
/** 免 HITL 确认的子工具名(覆盖子工具 requireConfirmation) */
|
|
@@ -74,12 +74,24 @@ export interface IDeploymentSnapshot {
|
|
|
74
74
|
/** 规范化摘要:去 sha256: 前缀、空白,转小写 hex */
|
|
75
75
|
export declare function normalizeDigest(value: unknown): string | null;
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
77
|
+
* Agent 清单装配读取:现行 `skills`,兼容 CLI `skillRefs`。
|
|
78
|
+
* 项身份:`code` / `skill` / `skillId`。两边都有时现行字段先写入;同名只补 version/name 等空位。
|
|
79
|
+
*/
|
|
80
|
+
export declare function skillRefsFromManifest(manifest: Record<string, unknown>): SnapshotSkillRef[];
|
|
81
|
+
/**
|
|
82
|
+
* 装配引用 vs 内联完整 ToolManifest。
|
|
83
|
+
* 含 type/execution 的视为内联定义;仅 code/toolset/version/enabled 等视为引用。
|
|
79
84
|
*/
|
|
80
85
|
export declare function isInlineToolDeclaration(item: unknown): boolean;
|
|
81
86
|
/**
|
|
82
|
-
*
|
|
87
|
+
* 从 Agent 清单收集工具集装配引用。
|
|
88
|
+
* 现行 `toolsets`;兼容 CLI `toolRefs` 与更旧的 `tools`(内联完整 manifest 会跳过)。
|
|
89
|
+
* 项身份:`code` / `toolset`(字符串项即 code)。不用展示名 `name`。白名单:`enabled` / `enabledTools`。
|
|
90
|
+
* 两边都有时现行字段先写入;同名条目的 enabled/autoApprove 以先写入为准。
|
|
91
|
+
*/
|
|
92
|
+
export declare function toolsetsFromManifest(manifest: Record<string, unknown>): SnapshotToolRef[];
|
|
93
|
+
/**
|
|
94
|
+
* 将 agent.manifest 装配项上的 enabled/autoApprove 叠到 snapshot.tools[](snapshot 未带时)。
|
|
83
95
|
*/
|
|
84
96
|
export declare function overlayToolRefPolicies(snapTools: SnapshotToolRef[], manifest?: Record<string, unknown>): SnapshotToolRef[];
|
|
85
97
|
export declare class FileSystemDeploymentSnapshot implements IDeploymentSnapshot {
|