@dsh-plugin/dsh-synapse 0.1.0-dev.41044228975 → 0.1.0
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 +661 -661
- package/README.md +0 -14
- package/package.json +1 -1
- package/vendor/gugle-chat-bot/LICENSE +661 -661
- package/vendor/gugle-chat-bot/package.json +57 -57
- package/vendor/gugle-chat-bot/src/allow-rule.yml +9345 -9345
- package/vendor/gugle-chat-bot/src/api.json +4284 -4284
- package/vendor/gugle-chat-bot/src/command/index.ts +141 -141
- package/vendor/gugle-chat-bot/src/config/features.ts +547 -547
- package/vendor/gugle-chat-bot/src/config/index.ts +184 -184
- package/vendor/gugle-chat-bot/src/config/manager.ts +356 -356
- package/vendor/gugle-chat-bot/src/constants/index.ts +13 -13
- package/vendor/gugle-chat-bot/src/custom.ts +548 -548
- package/vendor/gugle-chat-bot/src/event/index.ts +118 -118
- package/vendor/gugle-chat-bot/src/features/admin/index.ts +414 -414
- package/vendor/gugle-chat-bot/src/features/bili/image/impl/video.ts +39 -39
- package/vendor/gugle-chat-bot/src/features/bili/image/index.ts +37 -37
- package/vendor/gugle-chat-bot/src/features/bili/index.ts +65 -65
- package/vendor/gugle-chat-bot/src/features/bili/template/style/video.css +97 -97
- package/vendor/gugle-chat-bot/src/features/bili/template/video.html +56 -56
- package/vendor/gugle-chat-bot/src/features/discord-bridge/index.ts +1128 -1128
- package/vendor/gugle-chat-bot/src/features/discord-bridge/markdown.ts +105 -105
- package/vendor/gugle-chat-bot/src/features/discord-bridge/slash.ts +355 -355
- package/vendor/gugle-chat-bot/src/features/discord-bridge/source.ts +96 -96
- package/vendor/gugle-chat-bot/src/features/discord-bridge/template/message.html +14 -14
- package/vendor/gugle-chat-bot/src/features/discord-bridge/template/style/message.css +144 -144
- package/vendor/gugle-chat-bot/src/features/github/api.ts +93 -93
- package/vendor/gugle-chat-bot/src/features/github/binding.ts +161 -161
- package/vendor/gugle-chat-bot/src/features/github/image/impl/issue.ts +132 -132
- package/vendor/gugle-chat-bot/src/features/github/image/impl/pr.ts +144 -144
- package/vendor/gugle-chat-bot/src/features/github/image/impl/release.ts +160 -160
- package/vendor/gugle-chat-bot/src/features/github/image/index.ts +310 -310
- package/vendor/gugle-chat-bot/src/features/github/index.ts +302 -302
- package/vendor/gugle-chat-bot/src/features/github/template/issue.html +118 -118
- package/vendor/gugle-chat-bot/src/features/github/template/pull_request.html +125 -125
- package/vendor/gugle-chat-bot/src/features/github/template/release.html +53 -53
- package/vendor/gugle-chat-bot/src/features/github/template/style/issue.css +468 -468
- package/vendor/gugle-chat-bot/src/features/github/template/style/pull_request.css +468 -468
- package/vendor/gugle-chat-bot/src/features/github/template/style/release.css +412 -412
- package/vendor/gugle-chat-bot/src/features/hermes/client.ts +184 -184
- package/vendor/gugle-chat-bot/src/features/hermes/config.ts +210 -210
- package/vendor/gugle-chat-bot/src/features/hermes/context.ts +67 -67
- package/vendor/gugle-chat-bot/src/features/hermes/history.ts +86 -86
- package/vendor/gugle-chat-bot/src/features/hermes/index.ts +1533 -1533
- package/vendor/gugle-chat-bot/src/features/hermes/message.ts +319 -319
- package/vendor/gugle-chat-bot/src/features/hermes/reaction.ts +181 -181
- package/vendor/gugle-chat-bot/src/features/hermes/render.ts +118 -118
- package/vendor/gugle-chat-bot/src/features/hermes/reply-units.ts +331 -331
- package/vendor/gugle-chat-bot/src/features/hermes/skills.ts +406 -406
- package/vendor/gugle-chat-bot/src/features/hermes/template/approval.html +30 -30
- package/vendor/gugle-chat-bot/src/features/hermes/template/progress.html +21 -21
- package/vendor/gugle-chat-bot/src/features/hermes/template/style/approval.css +81 -81
- package/vendor/gugle-chat-bot/src/features/hermes/template/style/progress.css +120 -120
- package/vendor/gugle-chat-bot/src/features/hermes/trigger.ts +86 -86
- package/vendor/gugle-chat-bot/src/features/hermes/types.ts +327 -327
- package/vendor/gugle-chat-bot/src/features/management/index.ts +156 -156
- package/vendor/gugle-chat-bot/src/features/minecraft/index.ts +127 -127
- package/vendor/gugle-chat-bot/src/features/modrinth/index.ts +71 -71
- package/vendor/gugle-chat-bot/src/features/parentheses/index.ts +117 -117
- package/vendor/gugle-chat-bot/src/features/peak-valley-timer/index.ts +451 -451
- package/vendor/gugle-chat-bot/src/features/poke/index.ts +24 -24
- package/vendor/gugle-chat-bot/src/features/version-tracker/index.ts +77 -77
- package/vendor/gugle-chat-bot/src/features/welcome/index.ts +57 -57
- package/vendor/gugle-chat-bot/src/github-ip.json +5814 -5814
- package/vendor/gugle-chat-bot/src/image/index.ts +278 -278
- package/vendor/gugle-chat-bot/src/index.ts +695 -695
- package/vendor/gugle-chat-bot/src/logger/index.ts +54 -54
- package/vendor/gugle-chat-bot/src/result.json +359 -359
- package/vendor/gugle-chat-bot/src/type/bili.d.ts +825 -825
- package/vendor/gugle-chat-bot/src/type/event.d.ts +146 -146
- package/vendor/gugle-chat-bot/src/type/github.d.ts +446 -446
- package/vendor/gugle-chat-bot/src/type/index.d.ts +254 -254
- package/vendor/gugle-chat-bot/tsconfig.json +46 -46
- package/scripts/dump-npm-latest.mjs +0 -30
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
import { getHermesConfig } from '@/features/hermes/config';
|
|
2
|
-
import { ApprovalChoice, HermesEventCallbacks, MessageContentPart } from '@/features/hermes/types';
|
|
3
|
-
|
|
4
|
-
/** 提交运行参数 */
|
|
5
|
-
interface SubmitRunParams {
|
|
6
|
-
userMessage: string | MessageContentPart[];
|
|
7
|
-
sessionId?: string;
|
|
8
|
-
systemPrompt?: string;
|
|
9
|
-
conversationHistory?: Array<{ role: string; content: string }>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Hermes API 客户端(移植自 qq-hermes-bridge src/hermes.ts,MIT 协议,原作者 Amorter)。
|
|
14
|
-
* 负责异步提交任务、监听 SSE 事件流、审批管理和任务停止。
|
|
15
|
-
* 配置每次调用时读取(ConfigStore 热重载生效)。
|
|
16
|
-
*/
|
|
17
|
-
export class HermesClient {
|
|
18
|
-
private get baseUrl(): string {
|
|
19
|
-
return getHermesConfig().apiUrl;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 提交异步运行任务。
|
|
24
|
-
* @returns 包含 runId 和 status 的结果
|
|
25
|
-
*/
|
|
26
|
-
public async submitRun({ userMessage, sessionId, systemPrompt, conversationHistory }: SubmitRunParams): Promise<{
|
|
27
|
-
runId: string;
|
|
28
|
-
status: string;
|
|
29
|
-
}> {
|
|
30
|
-
// 多模态消息:input 需传消息数组,最后一条携带图片内容段;纯文本保持原样
|
|
31
|
-
const body: Record<string, unknown> = {
|
|
32
|
-
input: Array.isArray(userMessage) ? [{ role: 'user', content: userMessage }] : userMessage
|
|
33
|
-
};
|
|
34
|
-
if (systemPrompt) body.instructions = systemPrompt;
|
|
35
|
-
if (sessionId) body.session_id = sessionId;
|
|
36
|
-
if (conversationHistory?.length) body.conversation_history = conversationHistory;
|
|
37
|
-
|
|
38
|
-
const resp = await fetch(`${this.baseUrl}/v1/runs`, {
|
|
39
|
-
method: 'POST',
|
|
40
|
-
headers: this.headers(),
|
|
41
|
-
body: JSON.stringify(body)
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
if (!resp.ok) {
|
|
45
|
-
const text = await resp.text().catch(() => '');
|
|
46
|
-
throw new Error(`submitRun 失败 ${resp.status}: ${text.slice(0, 200)}`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const data = (await resp.json()) as Record<string, string>;
|
|
50
|
-
return {
|
|
51
|
-
runId: data.run_id || data.id || '',
|
|
52
|
-
status: data.status || ''
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 连接 SSE 事件流,监听运行过程中的各类事件。
|
|
58
|
-
* @param runId 运行 ID
|
|
59
|
-
* @param callbacks 事件回调映射
|
|
60
|
-
* @returns 包含 abort 方法的控制器
|
|
61
|
-
*/
|
|
62
|
-
public streamEvents(runId: string, callbacks: HermesEventCallbacks): { abort(): void } {
|
|
63
|
-
const url = `${this.baseUrl}/v1/runs/${runId}/events`;
|
|
64
|
-
const headers = this.headers({ Accept: 'text/event-stream' });
|
|
65
|
-
|
|
66
|
-
let aborted = false;
|
|
67
|
-
const controller = new AbortController();
|
|
68
|
-
|
|
69
|
-
const doConnect = async () => {
|
|
70
|
-
try {
|
|
71
|
-
const resp = await fetch(url, { headers, signal: controller.signal });
|
|
72
|
-
if (!resp.ok) {
|
|
73
|
-
const text = await resp.text().catch(() => '');
|
|
74
|
-
callbacks._error?.(new Error(`SSE ${resp.status}: ${text.slice(0, 200)}`));
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const reader = resp.body!.getReader();
|
|
79
|
-
const decoder = new TextDecoder();
|
|
80
|
-
let buffer = '';
|
|
81
|
-
let currentEvent = '';
|
|
82
|
-
|
|
83
|
-
while (!aborted) {
|
|
84
|
-
const { done, value } = await reader.read();
|
|
85
|
-
if (done) break;
|
|
86
|
-
|
|
87
|
-
buffer += decoder.decode(value, { stream: true });
|
|
88
|
-
const lines = buffer.split('\n');
|
|
89
|
-
buffer = lines.pop() || '';
|
|
90
|
-
|
|
91
|
-
for (const line of lines) {
|
|
92
|
-
// SSE event 行:记录当前事件类型
|
|
93
|
-
if (line.startsWith('event: ')) {
|
|
94
|
-
currentEvent = line.slice(7).trim();
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
if (line.startsWith('data: ')) {
|
|
98
|
-
const jsonStr = line.slice(6).trim();
|
|
99
|
-
if (!jsonStr) continue;
|
|
100
|
-
try {
|
|
101
|
-
const data = JSON.parse(jsonStr) as { event?: string } & Record<string, unknown>;
|
|
102
|
-
// 优先用 SSE event 行的类型,其次用 data.event
|
|
103
|
-
const eventType =
|
|
104
|
-
currentEvent || (data.event as string) || (data as Record<string, unknown>).type as string || 'unknown';
|
|
105
|
-
|
|
106
|
-
if (eventType) {
|
|
107
|
-
const handler = (callbacks as Record<string, ((ev: unknown) => void) | undefined>)[eventType];
|
|
108
|
-
if (handler) {
|
|
109
|
-
handler(data);
|
|
110
|
-
} else {
|
|
111
|
-
callbacks._any?.(data as never);
|
|
112
|
-
}
|
|
113
|
-
// run.completed / run.failed 也触发 _end
|
|
114
|
-
if (eventType === 'run.completed' || eventType === 'run.failed') {
|
|
115
|
-
callbacks._end?.();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
currentEvent = ''; // 重置,等待下一个事件
|
|
120
|
-
} catch {
|
|
121
|
-
// 非 JSON 的 SSE 数据(心跳注释)
|
|
122
|
-
}
|
|
123
|
-
} else if (line.startsWith(': stream closed')) {
|
|
124
|
-
callbacks._end?.();
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
callbacks._end?.();
|
|
130
|
-
} catch (err) {
|
|
131
|
-
if (!aborted) callbacks._error?.(err as Error);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
void doConnect();
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
/** 中止 SSE 连接 */
|
|
139
|
-
abort() {
|
|
140
|
-
aborted = true;
|
|
141
|
-
controller.abort();
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* 批准或拒绝待审批命令。
|
|
148
|
-
* @param runId 运行 ID
|
|
149
|
-
* @param choice 审批选择:once | deny | always | session
|
|
150
|
-
*/
|
|
151
|
-
public async resolveApproval(runId: string, choice: ApprovalChoice): Promise<unknown> {
|
|
152
|
-
const resp = await fetch(`${this.baseUrl}/v1/runs/${runId}/approval`, {
|
|
153
|
-
method: 'POST',
|
|
154
|
-
headers: this.headers(),
|
|
155
|
-
body: JSON.stringify({ choice })
|
|
156
|
-
});
|
|
157
|
-
if (!resp.ok) {
|
|
158
|
-
const text = await resp.text().catch(() => '');
|
|
159
|
-
throw new Error(`审批处理失败 ${resp.status}: ${text.slice(0, 200)}`);
|
|
160
|
-
}
|
|
161
|
-
return resp.json();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* 停止正在运行的 Agent 任务。
|
|
166
|
-
* @param runId 运行 ID
|
|
167
|
-
* @returns 是否成功停止
|
|
168
|
-
*/
|
|
169
|
-
public async stopRun(runId: string): Promise<boolean> {
|
|
170
|
-
const resp = await fetch(`${this.baseUrl}/v1/runs/${runId}/stop`, {
|
|
171
|
-
method: 'POST',
|
|
172
|
-
headers: this.headers()
|
|
173
|
-
});
|
|
174
|
-
return resp.ok;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/** 构建请求头 */
|
|
178
|
-
private headers(extra: Record<string, string> = {}): Record<string, string> {
|
|
179
|
-
const headers: Record<string, string> = { 'Content-Type': 'application/json', ...extra };
|
|
180
|
-
const apiKey = getHermesConfig().apiKey;
|
|
181
|
-
if (apiKey) headers['Authorization'] = `Bearer ${apiKey}`;
|
|
182
|
-
return headers;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
1
|
+
import { getHermesConfig } from '@/features/hermes/config';
|
|
2
|
+
import { ApprovalChoice, HermesEventCallbacks, MessageContentPart } from '@/features/hermes/types';
|
|
3
|
+
|
|
4
|
+
/** 提交运行参数 */
|
|
5
|
+
interface SubmitRunParams {
|
|
6
|
+
userMessage: string | MessageContentPart[];
|
|
7
|
+
sessionId?: string;
|
|
8
|
+
systemPrompt?: string;
|
|
9
|
+
conversationHistory?: Array<{ role: string; content: string }>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Hermes API 客户端(移植自 qq-hermes-bridge src/hermes.ts,MIT 协议,原作者 Amorter)。
|
|
14
|
+
* 负责异步提交任务、监听 SSE 事件流、审批管理和任务停止。
|
|
15
|
+
* 配置每次调用时读取(ConfigStore 热重载生效)。
|
|
16
|
+
*/
|
|
17
|
+
export class HermesClient {
|
|
18
|
+
private get baseUrl(): string {
|
|
19
|
+
return getHermesConfig().apiUrl;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 提交异步运行任务。
|
|
24
|
+
* @returns 包含 runId 和 status 的结果
|
|
25
|
+
*/
|
|
26
|
+
public async submitRun({ userMessage, sessionId, systemPrompt, conversationHistory }: SubmitRunParams): Promise<{
|
|
27
|
+
runId: string;
|
|
28
|
+
status: string;
|
|
29
|
+
}> {
|
|
30
|
+
// 多模态消息:input 需传消息数组,最后一条携带图片内容段;纯文本保持原样
|
|
31
|
+
const body: Record<string, unknown> = {
|
|
32
|
+
input: Array.isArray(userMessage) ? [{ role: 'user', content: userMessage }] : userMessage
|
|
33
|
+
};
|
|
34
|
+
if (systemPrompt) body.instructions = systemPrompt;
|
|
35
|
+
if (sessionId) body.session_id = sessionId;
|
|
36
|
+
if (conversationHistory?.length) body.conversation_history = conversationHistory;
|
|
37
|
+
|
|
38
|
+
const resp = await fetch(`${this.baseUrl}/v1/runs`, {
|
|
39
|
+
method: 'POST',
|
|
40
|
+
headers: this.headers(),
|
|
41
|
+
body: JSON.stringify(body)
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (!resp.ok) {
|
|
45
|
+
const text = await resp.text().catch(() => '');
|
|
46
|
+
throw new Error(`submitRun 失败 ${resp.status}: ${text.slice(0, 200)}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const data = (await resp.json()) as Record<string, string>;
|
|
50
|
+
return {
|
|
51
|
+
runId: data.run_id || data.id || '',
|
|
52
|
+
status: data.status || ''
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 连接 SSE 事件流,监听运行过程中的各类事件。
|
|
58
|
+
* @param runId 运行 ID
|
|
59
|
+
* @param callbacks 事件回调映射
|
|
60
|
+
* @returns 包含 abort 方法的控制器
|
|
61
|
+
*/
|
|
62
|
+
public streamEvents(runId: string, callbacks: HermesEventCallbacks): { abort(): void } {
|
|
63
|
+
const url = `${this.baseUrl}/v1/runs/${runId}/events`;
|
|
64
|
+
const headers = this.headers({ Accept: 'text/event-stream' });
|
|
65
|
+
|
|
66
|
+
let aborted = false;
|
|
67
|
+
const controller = new AbortController();
|
|
68
|
+
|
|
69
|
+
const doConnect = async () => {
|
|
70
|
+
try {
|
|
71
|
+
const resp = await fetch(url, { headers, signal: controller.signal });
|
|
72
|
+
if (!resp.ok) {
|
|
73
|
+
const text = await resp.text().catch(() => '');
|
|
74
|
+
callbacks._error?.(new Error(`SSE ${resp.status}: ${text.slice(0, 200)}`));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const reader = resp.body!.getReader();
|
|
79
|
+
const decoder = new TextDecoder();
|
|
80
|
+
let buffer = '';
|
|
81
|
+
let currentEvent = '';
|
|
82
|
+
|
|
83
|
+
while (!aborted) {
|
|
84
|
+
const { done, value } = await reader.read();
|
|
85
|
+
if (done) break;
|
|
86
|
+
|
|
87
|
+
buffer += decoder.decode(value, { stream: true });
|
|
88
|
+
const lines = buffer.split('\n');
|
|
89
|
+
buffer = lines.pop() || '';
|
|
90
|
+
|
|
91
|
+
for (const line of lines) {
|
|
92
|
+
// SSE event 行:记录当前事件类型
|
|
93
|
+
if (line.startsWith('event: ')) {
|
|
94
|
+
currentEvent = line.slice(7).trim();
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (line.startsWith('data: ')) {
|
|
98
|
+
const jsonStr = line.slice(6).trim();
|
|
99
|
+
if (!jsonStr) continue;
|
|
100
|
+
try {
|
|
101
|
+
const data = JSON.parse(jsonStr) as { event?: string } & Record<string, unknown>;
|
|
102
|
+
// 优先用 SSE event 行的类型,其次用 data.event
|
|
103
|
+
const eventType =
|
|
104
|
+
currentEvent || (data.event as string) || (data as Record<string, unknown>).type as string || 'unknown';
|
|
105
|
+
|
|
106
|
+
if (eventType) {
|
|
107
|
+
const handler = (callbacks as Record<string, ((ev: unknown) => void) | undefined>)[eventType];
|
|
108
|
+
if (handler) {
|
|
109
|
+
handler(data);
|
|
110
|
+
} else {
|
|
111
|
+
callbacks._any?.(data as never);
|
|
112
|
+
}
|
|
113
|
+
// run.completed / run.failed 也触发 _end
|
|
114
|
+
if (eventType === 'run.completed' || eventType === 'run.failed') {
|
|
115
|
+
callbacks._end?.();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
currentEvent = ''; // 重置,等待下一个事件
|
|
120
|
+
} catch {
|
|
121
|
+
// 非 JSON 的 SSE 数据(心跳注释)
|
|
122
|
+
}
|
|
123
|
+
} else if (line.startsWith(': stream closed')) {
|
|
124
|
+
callbacks._end?.();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
callbacks._end?.();
|
|
130
|
+
} catch (err) {
|
|
131
|
+
if (!aborted) callbacks._error?.(err as Error);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
void doConnect();
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
/** 中止 SSE 连接 */
|
|
139
|
+
abort() {
|
|
140
|
+
aborted = true;
|
|
141
|
+
controller.abort();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 批准或拒绝待审批命令。
|
|
148
|
+
* @param runId 运行 ID
|
|
149
|
+
* @param choice 审批选择:once | deny | always | session
|
|
150
|
+
*/
|
|
151
|
+
public async resolveApproval(runId: string, choice: ApprovalChoice): Promise<unknown> {
|
|
152
|
+
const resp = await fetch(`${this.baseUrl}/v1/runs/${runId}/approval`, {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
headers: this.headers(),
|
|
155
|
+
body: JSON.stringify({ choice })
|
|
156
|
+
});
|
|
157
|
+
if (!resp.ok) {
|
|
158
|
+
const text = await resp.text().catch(() => '');
|
|
159
|
+
throw new Error(`审批处理失败 ${resp.status}: ${text.slice(0, 200)}`);
|
|
160
|
+
}
|
|
161
|
+
return resp.json();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 停止正在运行的 Agent 任务。
|
|
166
|
+
* @param runId 运行 ID
|
|
167
|
+
* @returns 是否成功停止
|
|
168
|
+
*/
|
|
169
|
+
public async stopRun(runId: string): Promise<boolean> {
|
|
170
|
+
const resp = await fetch(`${this.baseUrl}/v1/runs/${runId}/stop`, {
|
|
171
|
+
method: 'POST',
|
|
172
|
+
headers: this.headers()
|
|
173
|
+
});
|
|
174
|
+
return resp.ok;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** 构建请求头 */
|
|
178
|
+
private headers(extra: Record<string, string> = {}): Record<string, string> {
|
|
179
|
+
const headers: Record<string, string> = { 'Content-Type': 'application/json', ...extra };
|
|
180
|
+
const apiKey = getHermesConfig().apiKey;
|
|
181
|
+
if (apiKey) headers['Authorization'] = `Bearer ${apiKey}`;
|
|
182
|
+
return headers;
|
|
183
|
+
}
|
|
184
|
+
}
|