pi-tsgw 1.5.0 → 1.5.1
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.
|
@@ -2,8 +2,12 @@ import type { Api, ClassifierContext, Model, Usage } from "@earendil-works/pi-ai
|
|
|
2
2
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { isPlainObject, PayloadWriter } from "#tsgw/models/_tools";
|
|
4
4
|
import { openaiThinking } from "#tsgw/models/vendors/openai";
|
|
5
|
+
import { minimaxThinking } from "#tsgw/models/vendors/minimax";
|
|
5
6
|
import { DELEGATION_KINDS, resolveDelegationKeys, type DelegationCandidate } from "./policy.ts";
|
|
7
|
+
import { chatFailure, type SelectionFailure } from "./failure.ts";
|
|
6
8
|
|
|
9
|
+
export const CHAT_SELECTION_IDS = ["gpt-6-luna", "deepseek-flash", "MiniMax-M3.1-Flash"] as const;
|
|
10
|
+
type ChatSelectionId = (typeof CHAT_SELECTION_IDS)[number];
|
|
7
11
|
interface ChatSelectionOptions {
|
|
8
12
|
models: readonly Model<Api>[];
|
|
9
13
|
signal: AbortSignal;
|
|
@@ -13,20 +17,21 @@ interface ChatSelectionOptions {
|
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
|
-
* 创建前选型的单次聊天通道,不改变原生 classify
|
|
17
|
-
*
|
|
20
|
+
* 创建前选型的单次聊天通道,不改变原生 classify,也不将聊天执行器注册为分类模型。
|
|
21
|
+
* 复用宿主认证与各模型原有协议;只发送原分类材料,不携带会话历史、本地工具或搜索。
|
|
18
22
|
*/
|
|
19
|
-
export async function
|
|
23
|
+
export async function selectWithChat(
|
|
20
24
|
registry: ExtensionContext["modelRegistry"],
|
|
21
25
|
context: ClassifierContext,
|
|
22
26
|
candidates: readonly DelegationCandidate[],
|
|
27
|
+
modelId: ChatSelectionId,
|
|
23
28
|
options: ChatSelectionOptions,
|
|
24
|
-
): Promise<{ selected: DelegationCandidate; kind: string; model: string } | undefined> {
|
|
29
|
+
): Promise<{ selected: DelegationCandidate; kind: string; model: string } | { failure: SelectionFailure } | undefined> {
|
|
25
30
|
const { signal } = options;
|
|
26
31
|
signal.throwIfAborted();
|
|
27
32
|
if (typeof registry.streamSimple !== "function") return undefined;
|
|
28
33
|
// 分类执行器不受子代理输出候选的 scope 限制,但必须尊重宿主可用目录和用户过滤。
|
|
29
|
-
const model = options.models.find(entry => entry.provider === "tsgw" && entry.id ===
|
|
34
|
+
const model = options.models.find(entry => entry.provider === "tsgw" && entry.id === modelId &&
|
|
30
35
|
(entry.type === undefined || entry.type === "chat") && entry.input.includes("text"));
|
|
31
36
|
if (!model) return undefined;
|
|
32
37
|
// 即使计时器尚未获得执行机会,目录查询耗尽总预算后也不能再发出付费请求。
|
|
@@ -46,39 +51,49 @@ export async function selectWithLuna(
|
|
|
46
51
|
if (!isPlainObject(payload)) return payload;
|
|
47
52
|
// 只复用厂商文本策略,不经过会注入 web_search 的公共调度。
|
|
48
53
|
const writer = new PayloadWriter(payload);
|
|
49
|
-
|
|
54
|
+
const operation = {
|
|
50
55
|
provider: model.provider, modelId: model.id, api: model.api,
|
|
51
|
-
thinkingLevel: "low", tsSearchMode: "cached",
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
thinkingLevel: "low" as const, tsSearchMode: "cached" as const,
|
|
57
|
+
};
|
|
58
|
+
if (modelId === "MiniMax-M3.1-Flash") {
|
|
59
|
+
minimaxThinking[modelId](writer, operation);
|
|
60
|
+
// 沿用 Anthropic Messages;不假定其支持 Responses 的 text.format。
|
|
61
|
+
// JSON 由提示约束并在响应入口严格校验,与其他通道使用相同硬规则。
|
|
62
|
+
} else {
|
|
63
|
+
if (modelId === "gpt-6-luna") openaiThinking[modelId](writer, operation);
|
|
64
|
+
const text = writer.get("text");
|
|
65
|
+
writer.set("text", {
|
|
66
|
+
...(isPlainObject(text) ? text : {}),
|
|
67
|
+
format: {
|
|
68
|
+
type: "json_schema", name: "delegation_selection", strict: true,
|
|
69
|
+
schema: {
|
|
70
|
+
type: "object",
|
|
71
|
+
properties: {
|
|
72
|
+
kind: { type: "string", enum: [...DELEGATION_KINDS] },
|
|
73
|
+
selection: { type: "string", enum: [...candidates.map(candidate => candidate.key), "unresolved"] },
|
|
74
|
+
},
|
|
75
|
+
required: ["kind", "selection"], additionalProperties: false,
|
|
64
76
|
},
|
|
65
|
-
required: ["kind", "selection"], additionalProperties: false,
|
|
66
77
|
},
|
|
67
|
-
}
|
|
68
|
-
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
69
80
|
return writer.result();
|
|
70
81
|
},
|
|
71
82
|
}).result();
|
|
72
83
|
options.onUsage(result.usage);
|
|
73
84
|
signal.throwIfAborted();
|
|
74
|
-
if (result.stopReason
|
|
85
|
+
if (result.stopReason === "error" || result.stopReason === "aborted") return { failure: chatFailure(result.errorMessage) };
|
|
86
|
+
const invalid: { failure: SelectionFailure } = {
|
|
87
|
+
failure: { failureKind: "invalid_result", reason: "聊天选型结果无效、未决或不符合固定审阅规则。" },
|
|
88
|
+
};
|
|
89
|
+
if (result.stopReason !== "stop" || result.content.some(part => part.type === "toolCall")) return invalid;
|
|
75
90
|
const text = result.content.flatMap(part => part.type === "text" ? [part.text] : []).join("");
|
|
76
91
|
try {
|
|
77
92
|
const answer: unknown = JSON.parse(text);
|
|
78
|
-
if (!isPlainObject(answer) || Object.keys(answer).length !== 2 || typeof answer.kind !== "string") return
|
|
93
|
+
if (!isPlainObject(answer) || Object.keys(answer).length !== 2 || typeof answer.kind !== "string") return invalid;
|
|
79
94
|
const selected = resolveDelegationKeys(answer.kind, answer.selection, candidates);
|
|
80
|
-
return selected ? { selected, kind: answer.kind, model: modelName } :
|
|
95
|
+
return selected ? { selected, kind: answer.kind, model: modelName } : invalid;
|
|
81
96
|
} catch {
|
|
82
|
-
return
|
|
97
|
+
return invalid;
|
|
83
98
|
}
|
|
84
99
|
}
|
|
@@ -4,21 +4,22 @@ export type DelegationFailureKind =
|
|
|
4
4
|
| "invalid_response" | "unsupported" | "unknown" | "invalid_input" | "unavailable"
|
|
5
5
|
| "invalid_result" | "model_unavailable";
|
|
6
6
|
|
|
7
|
-
interface
|
|
7
|
+
export interface SelectionFailure {
|
|
8
8
|
failureKind: DelegationFailureKind;
|
|
9
9
|
reason: string;
|
|
10
|
+
statusCode?: number;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
/** 只识别 adapter 的安全类别,不把任意 errorMessage 当作可信展示文本。 */
|
|
13
|
-
export function classifierFailure(message: string | undefined, aborted = false):
|
|
14
|
+
export function classifierFailure(message: string | undefined, aborted = false): SelectionFailure {
|
|
14
15
|
if (aborted) return { failureKind: "cancelled", reason: "分类请求已取消。" };
|
|
15
16
|
if (message === "分类请求超时。") return { failureKind: "timeout", reason: message };
|
|
16
17
|
const status = /^分类请求(?:认证失败|被上游限流|失败)(HTTP ([45]\d{2}))。$/.exec(message ?? "")?.[1];
|
|
17
18
|
if (status) {
|
|
18
19
|
if (status === "401" || status === "403")
|
|
19
|
-
return { failureKind: "authentication", reason: `分类请求认证失败(HTTP ${status}
|
|
20
|
-
if (status === "429") return { failureKind: "rate_limit", reason: "分类请求被上游限流(HTTP 429)。" };
|
|
21
|
-
return { failureKind: "http", reason: `分类请求失败(HTTP ${status}
|
|
20
|
+
return { failureKind: "authentication", reason: `分类请求认证失败(HTTP ${status})。`, statusCode: Number(status) };
|
|
21
|
+
if (status === "429") return { failureKind: "rate_limit", reason: "分类请求被上游限流(HTTP 429)。", statusCode: 429 };
|
|
22
|
+
return { failureKind: "http", reason: `分类请求失败(HTTP ${status})。`, statusCode: Number(status) };
|
|
22
23
|
}
|
|
23
24
|
switch (message) {
|
|
24
25
|
case "分类请求缺少有效认证信息。":
|
|
@@ -36,6 +37,23 @@ export function classifierFailure(message: string | undefined, aborted = false):
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
/** SDK 错误仅提取 HTTP 状态码;不回显可能含凭据、请求或上游正文的 message。 */
|
|
41
|
+
export function chatFailure(message: string | undefined): SelectionFailure {
|
|
42
|
+
// Responses 使用宿主格式“tsgw API error (状态码):”,Anthropic 保留 SDK 数字前缀。
|
|
43
|
+
const match = /^(?:(?:HTTP\s+)?([45]\d{2})\b|tsgw API error \(([45]\d{2})\):)/i.exec(message ?? "");
|
|
44
|
+
const status = match?.[1] ?? match?.[2];
|
|
45
|
+
if (status) {
|
|
46
|
+
const statusCode = Number(status);
|
|
47
|
+
const failureKind = statusCode === 401 || statusCode === 403 ? "authentication" : statusCode === 429 ? "rate_limit" : "http";
|
|
48
|
+
return { failureKind, reason: `聊天选型请求失败(HTTP ${statusCode})。`, statusCode };
|
|
49
|
+
}
|
|
50
|
+
if (/^(?:request timed out\.?|request timeout\.?)$/i.test(message ?? ""))
|
|
51
|
+
return { failureKind: "timeout", reason: "聊天选型请求超时。" };
|
|
52
|
+
if (/^connection error\.?$/i.test(message ?? ""))
|
|
53
|
+
return { failureKind: "network", reason: "聊天选型连接失败。" };
|
|
54
|
+
return { failureKind: "unknown", reason: "聊天选型请求失败(原因未明)。" };
|
|
55
|
+
}
|
|
56
|
+
|
|
39
57
|
export function failureGuidance(kind: DelegationFailureKind | undefined): string {
|
|
40
58
|
if (kind === "cancelled") return "本次未创建子代理。";
|
|
41
59
|
return "本次未创建子代理。请按以下选型指导处理,不重试自动选型。";
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type DelegationCandidate,
|
|
10
10
|
} from "./policy.ts";
|
|
11
11
|
import { failureGuidance, type DelegationFailureKind } from "./failure.ts";
|
|
12
|
-
import { raceSelection } from "./selection-race.ts";
|
|
12
|
+
import { raceSelection, type SelectionError } from "./selection-race.ts";
|
|
13
13
|
|
|
14
14
|
const TIMEOUT_MS = 15_000;
|
|
15
15
|
const MAX_CONTEXT_BYTES = 28 * 1024;
|
|
@@ -21,6 +21,8 @@ type Decision = {
|
|
|
21
21
|
status: "selected" | "blocked";
|
|
22
22
|
classifier?: string;
|
|
23
23
|
chatModel?: string;
|
|
24
|
+
chatModels?: string[];
|
|
25
|
+
selectionErrors?: SelectionError[];
|
|
24
26
|
selectionSource?: { type: "classifier" | "chat"; model: string };
|
|
25
27
|
model?: string;
|
|
26
28
|
kind?: string;
|
|
@@ -37,10 +39,16 @@ interface Attempt {
|
|
|
37
39
|
candidates?: DelegationCandidate[];
|
|
38
40
|
}
|
|
39
41
|
|
|
42
|
+
function selectionErrorsText(decision: Decision): string {
|
|
43
|
+
return decision.selectionErrors?.length ? "\n选型通道报错(返回前已收到):\n" +
|
|
44
|
+
decision.selectionErrors.map(error => `- ${error.source.model}:${error.reason}`).join("\n") : "";
|
|
45
|
+
}
|
|
46
|
+
|
|
40
47
|
function failureText(decision: Decision): string {
|
|
41
48
|
return `TSGW ${decision.reason ?? "分类选型未完成。"}${failureGuidance(decision.failureKind)}` +
|
|
42
49
|
`\n选型来源:无(未完成有效选型${decision.classifier ? `;已尝试分类模型 ${decision.classifier}` : ""}` +
|
|
43
|
-
`${decision.
|
|
50
|
+
`${decision.chatModels?.length ? `;已尝试聊天模型 ${decision.chatModels.join("、")}` : ""})。` +
|
|
51
|
+
selectionErrorsText(decision) +
|
|
44
52
|
(decision.selectionGuide ? `\n\n${decision.selectionGuide}` : "");
|
|
45
53
|
}
|
|
46
54
|
|
|
@@ -135,10 +143,12 @@ export function registerDelegation(pi: ExtensionAPI): void {
|
|
|
135
143
|
...(typeof input.run_in_background === "boolean" ? { run_in_background: input.run_in_background } : {}),
|
|
136
144
|
};
|
|
137
145
|
let classifierId: string | undefined;
|
|
138
|
-
|
|
146
|
+
const chatModelIds: string[] = [];
|
|
147
|
+
const selectionErrors: SelectionError[] = [];
|
|
139
148
|
const failure = (reason: string, kind: DelegationFailureKind): Decision => {
|
|
140
149
|
return { ...blocked(reason, kind), ...(classifierId ? { classifier: classifierId } : {}),
|
|
141
|
-
...(
|
|
150
|
+
...(chatModelIds.length ? { chatModel: chatModelIds[0], chatModels: [...chatModelIds] } : {}),
|
|
151
|
+
...(selectionErrors.length ? { selectionErrors: [...selectionErrors] } : {}),
|
|
142
152
|
...(kind === "cancelled" ? {} : { selectionGuide: buildDelegationGuide(attempt.candidates) }) };
|
|
143
153
|
};
|
|
144
154
|
try {
|
|
@@ -163,9 +173,10 @@ export function registerDelegation(pi: ExtensionAPI): void {
|
|
|
163
173
|
models, signal, deadlineMs: started + TIMEOUT_MS,
|
|
164
174
|
onStart: source => {
|
|
165
175
|
if (source.type === "classifier") classifierId = source.model;
|
|
166
|
-
else
|
|
176
|
+
else chatModelIds.push(source.model);
|
|
167
177
|
},
|
|
168
178
|
onUsage: usage => { attempt.usage = addUsage(attempt.usage, usage); },
|
|
179
|
+
onError: error => { selectionErrors.push(error); },
|
|
169
180
|
}), signal);
|
|
170
181
|
if ("failure" in result) return failure(result.failure.reason, result.failure.failureKind);
|
|
171
182
|
const { selected, kind, source } = result.winner;
|
|
@@ -175,7 +186,9 @@ export function registerDelegation(pi: ExtensionAPI): void {
|
|
|
175
186
|
if (!current.some(candidate => candidate.model === selected.model))
|
|
176
187
|
return failure("选定模型或思考档位已不在当前可用候选中。", "model_unavailable");
|
|
177
188
|
return { status: "selected", classifier: classifierId, model: selected.model,
|
|
178
|
-
selectionSource: source,
|
|
189
|
+
selectionSource: source,
|
|
190
|
+
...(chatModelIds.length ? { chatModel: chatModelIds[0], chatModels: [...chatModelIds] } : {}),
|
|
191
|
+
...(selectionErrors.length ? { selectionErrors: [...selectionErrors] } : {}),
|
|
179
192
|
...(kind ? { kind } : {}), durationMs: Date.now() - started };
|
|
180
193
|
} catch {
|
|
181
194
|
if (cancellation.aborted) return failure("分类选型已取消(调用或会话已结束)。", "cancelled");
|
|
@@ -219,8 +232,9 @@ export function registerDelegation(pi: ExtensionAPI): void {
|
|
|
219
232
|
summary = `TSGW 创建前选型:${decision.model};选型来源:${sourceType} ${decision.selectionSource?.model}`;
|
|
220
233
|
summary += "(并行竞速,采用首个有效结果)";
|
|
221
234
|
summary += `;${event.isError ? "原 Agent 调用未成功。" : "已交由原 Agent 执行。"}`;
|
|
222
|
-
if (decision.classifier
|
|
235
|
+
if ((decision.classifier ? 1 : 0) + (decision.chatModels?.length ?? 0) > 1)
|
|
223
236
|
summary += " 并行用量仅累计汇总前已报告部分;取消不保证远端停止处理或计费。";
|
|
237
|
+
summary += selectionErrorsText(decision);
|
|
224
238
|
} else {
|
|
225
239
|
summary = failureText(decision);
|
|
226
240
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import type { Api, ClassifierContext, Model, Usage } from "@earendil-works/pi-ai";
|
|
2
2
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import {
|
|
4
|
-
import { classifierFailure, type
|
|
3
|
+
import { CHAT_SELECTION_IDS, selectWithChat } from "./chat-selection.ts";
|
|
4
|
+
import { chatFailure, classifierFailure, type SelectionFailure } from "./failure.ts";
|
|
5
5
|
import { chooseClassifier, resolveDelegationChoice, type DelegationCandidate } from "./policy.ts";
|
|
6
6
|
|
|
7
7
|
export interface SelectionSource {
|
|
8
8
|
type: "classifier" | "chat";
|
|
9
9
|
model: string;
|
|
10
10
|
}
|
|
11
|
-
interface SelectionFailure {
|
|
12
|
-
|
|
13
|
-
failureKind: DelegationFailureKind;
|
|
11
|
+
export interface SelectionError extends SelectionFailure {
|
|
12
|
+
source: SelectionSource;
|
|
14
13
|
}
|
|
15
14
|
interface RaceOptions {
|
|
16
15
|
models: readonly Model<Api>[];
|
|
@@ -18,6 +17,7 @@ interface RaceOptions {
|
|
|
18
17
|
deadlineMs: number;
|
|
19
18
|
onStart: (source: SelectionSource) => void;
|
|
20
19
|
onUsage: (usage: Usage) => void;
|
|
20
|
+
onError: (error: SelectionError) => void;
|
|
21
21
|
}
|
|
22
22
|
interface SelectionWinner {
|
|
23
23
|
selected: DelegationCandidate;
|
|
@@ -25,7 +25,7 @@ interface SelectionWinner {
|
|
|
25
25
|
source: SelectionSource;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
/**
|
|
28
|
+
/** 四路各发一次;失败或非法结果不是胜者,不为等待取消确认延长选型。 */
|
|
29
29
|
export async function raceSelection(
|
|
30
30
|
registry: ExtensionContext["modelRegistry"],
|
|
31
31
|
context: ClassifierContext,
|
|
@@ -39,6 +39,7 @@ export async function raceSelection(
|
|
|
39
39
|
reason: "选型结果无效、未决或不符合固定审阅规则。", failureKind: "invalid_result",
|
|
40
40
|
};
|
|
41
41
|
const native = async (): Promise<SelectionWinner> => {
|
|
42
|
+
let source: SelectionSource | undefined;
|
|
42
43
|
try {
|
|
43
44
|
signal.throwIfAborted();
|
|
44
45
|
if (typeof registry.classify !== "function") {
|
|
@@ -57,7 +58,7 @@ export async function raceSelection(
|
|
|
57
58
|
nativeFailure = { reason: "选型预算已耗尽。", failureKind: "timeout" };
|
|
58
59
|
throw new Error("选型预算已耗尽。");
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
source = { type: "classifier", model: `${classifier.provider}/${classifier.id}` };
|
|
61
62
|
options.onStart(source);
|
|
62
63
|
const result = await registry.classify(classifier, context, { signal, timeoutMs: remaining, maxRetries: 0 });
|
|
63
64
|
if (result.usage) options.onUsage(result.usage);
|
|
@@ -76,25 +77,39 @@ export async function raceSelection(
|
|
|
76
77
|
return { selected, kind: answer?.type === "choice" ? answer.choice : undefined, source };
|
|
77
78
|
} catch {
|
|
78
79
|
nativeFailure ??= { reason: "分类请求失败(原因未明)。", failureKind: "unknown" };
|
|
80
|
+
if (source && !signal.aborted) options.onError({ source, ...nativeFailure });
|
|
79
81
|
throw new Error("原生选型通道未提供有效结果。");
|
|
80
82
|
}
|
|
81
83
|
};
|
|
82
|
-
const chat = async (): Promise<SelectionWinner> => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
const chat = async (modelId: (typeof CHAT_SELECTION_IDS)[number]): Promise<SelectionWinner> => {
|
|
85
|
+
let source: SelectionSource | undefined;
|
|
86
|
+
let failure: SelectionFailure | undefined;
|
|
87
|
+
try {
|
|
88
|
+
const result = await selectWithChat(registry, context, candidates, modelId, {
|
|
89
|
+
...options, signal, onStart: model => {
|
|
90
|
+
source = { type: "chat", model };
|
|
91
|
+
options.onStart(source);
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
if (result && !("failure" in result))
|
|
95
|
+
return { selected: result.selected, kind: result.kind, source: { type: "chat", model: result.model } };
|
|
96
|
+
if (result) failure = result.failure;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
failure = chatFailure(error instanceof Error ? error.message : undefined);
|
|
99
|
+
}
|
|
100
|
+
// 未发起的通道和获胜/整体取消导致的中止不作为通道报错。
|
|
101
|
+
if (source && !signal.aborted) options.onError({ source, ...(failure ?? invalid) });
|
|
102
|
+
throw new Error("聊天选型通道未提供有效结果。");
|
|
88
103
|
};
|
|
89
104
|
try {
|
|
90
|
-
const winner = await Promise.any([native(), chat
|
|
105
|
+
const winner = await Promise.any([native(), ...CHAT_SELECTION_IDS.map(chat)]);
|
|
91
106
|
options.signal.throwIfAborted();
|
|
92
107
|
return { winner };
|
|
93
108
|
} catch {
|
|
94
109
|
options.signal.throwIfAborted();
|
|
95
110
|
return { failure: nativeFailure ?? invalid };
|
|
96
111
|
} finally {
|
|
97
|
-
//
|
|
112
|
+
// 只取消选型请求,不中断获胜后的目录复核;不保证远端停止处理或计费。
|
|
98
113
|
finished.abort();
|
|
99
114
|
}
|
|
100
115
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: tsgw-synology-dav
|
|
3
|
+
description: 查询或管理群晖日历、日程及联系人时使用,通过 tsn__* MCP 工具读取真实数据,并在明确授权后创建、修改或删除。
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: 需要宿主已连接并获准使用提供 tsn__* 工具的 MCP 服务及已有 DAV 账号配置。
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# 群晖日历与联系人
|
|
9
|
+
|
|
10
|
+
涉及用户日程、联系人或空闲时间时,优先查询真实数据,不凭记忆猜测。本技能只指导宿主现有 MCP 调用,不新增 DAV 客户端、认证存储或连接配置。
|
|
11
|
+
|
|
12
|
+
## 工具发现与连接
|
|
13
|
+
|
|
14
|
+
- 先通过当前宿主的工具发现入口查找 `tsn__calendar_list`、`tsn__calendar_event_list`、`tsn__contacts_search` 等实际工具,再读取其参数 schema。工具可能带服务前缀;以发现的完整名称调用,不猜测名称或参数,不把描述中提及的其他工具视为已经可用。
|
|
15
|
+
- 在 Pi codemode 中可用 `searchTools('tsn__calendar_list', { limit: 3 })` 发现工具,必要时用 `describeTool()` 查看参数,再调用实际返回的 `tools.<完整工具名>(...)`。不得搜索或输出凭据。
|
|
16
|
+
- 提示账号未连接时,可调用 `dav_reconnect` 使用已有配置重连;已知目标账号时显式指定,避免无故重连全部账号。重连后重新查询目标目录或数据;连接成功、发现目录成功和读取真实数据是不同证据。
|
|
17
|
+
- 认证失败立即停止,不反复尝试,不索取或读取保存的密码,也不改用 `dav_connect` 绕过失败。配置缺失、权限不足或工具不可用时明确报告阻塞,不自行安装、登录或修改 MCP 配置。
|
|
18
|
+
- 同时检查工具错误标记及文本结果;不能仅因调用正常返回就断言成功,未连接或业务错误也可能出现在文本中。
|
|
19
|
+
|
|
20
|
+
## 日历查询
|
|
21
|
+
|
|
22
|
+
1. 先调用 `calendar_list`,确认实际账号、日历名称和路径。不要硬编码个人目录,也不要将 calendar home 当作具体日历路径。
|
|
23
|
+
2. 未指定时区时使用 `Asia/Shanghai`;根据当前真实日期将“今天、明天、下周”等转换为具体起止日期。“下周”默认目标周周一 `00:00` 至再下一周周一 `00:00`,即目标周周一至周日;若上下文有其他含义,先澄清。调用时用带时区偏移的 ISO 8601 时间,并在结果中说明具体范围及所用时区。
|
|
24
|
+
3. 调用 `calendar_event_list`,必传明确的 `start`、`end`。整天查询从当天 `00:00:00+08:00` 到次日 `00:00:00+08:00`,避免用 `23:59:59` 漏掉小数秒;不臆测服务端边界是否包含,必要时核对返回的边界事件。指定日历时使用发现的账号和路径。当前实现中,传 `account` 却省略 `calendar` 只查询该账号的第一个日历,与工具描述的范围不一致;需要覆盖多个日历时,按发现结果逐个显式传 `account` 和 `calendar`,分别检查结果,不依赖省略参数的聚合查询(它可能跳过部分失败)。不把默认主日历当作全部日历。
|
|
25
|
+
4. 先读取列表摘要,仅在完成任务确有必要且存在相应工具时再取单项详情。注意全天、跨天、重复事件及其例外;不要未经核验把重复规则当作已展开的每次发生记录,也不要把局部列表当作完整空闲证明。
|
|
26
|
+
5. 查询为空时说明查了哪些日历及哪个时间范围。寻找近期安排或做只读实测时,可合理扩大到前后数周,明确区分各次结果;用户只问某一天时不为证明服务器有数据而无故扩查。不得把“当天无事件”说成“服务器没有数据”。
|
|
27
|
+
|
|
28
|
+
## 联系人查询
|
|
29
|
+
|
|
30
|
+
- 已有姓名、邮箱或电话线索时优先 `contacts_search`;确实需要浏览列表或做一次只读能力验证时用 `contacts_list`。需要单项详情时,先确认实际存在的工具及目标 UID。
|
|
31
|
+
- 当前搜索会读取地址簿后在本地按姓名、邮箱、电话、组织或备注做不区分大小写的子串筛选,不是廉价的服务端索引查询。避免连续试探大量关键词或反复拉取整本地址簿;先利用已返回的结果,只有线索实质变化才再查询。
|
|
32
|
+
- 账号与地址簿参数按实际 schema 选择;默认主地址簿不代表所有地址簿。查不到时说明查询线索和范围,不断言联系人不存在于整个服务器。
|
|
33
|
+
- 同名或多个匹配结果时,只展示区分目标所需的少量字段;涉及写入则先请用户确认,不能自行挑选。
|
|
34
|
+
|
|
35
|
+
## 写入授权与核验
|
|
36
|
+
|
|
37
|
+
- 查询可直接执行;创建、修改和删除日程或联系人,必须有用户针对该动作的明确授权。“实测工具”“检查连接”或本技能本身都不是业务写入授权,不为验收创建再删除测试数据。
|
|
38
|
+
- 操作前查询现状,确认账号、具体日历或地址簿、目标 UID、时间与时区,以及用户要求变更的字段。存在重名、重复事件、重复联系人、时间歧义或周期事件单次/整组范围不明时,先询问,不误改其他数据。
|
|
39
|
+
- 新建前在相关时间范围或联系人线索内核对是否已有目标。修改只传明确要求改变的字段;省略字段与空字符串可能含义不同,不用猜测值填满参数。删除前精确定位目标,不仅凭名称执行,也不依赖跨目录模糊搜索。
|
|
40
|
+
- 周期事件、待办或日志类能力,仅在用户确有需求、实际工具支持且获得对应授权时使用;不把日程工具的能力推定为其他类型也支持。
|
|
41
|
+
- 写入返回后,在授权范围内按实际可用查询工具回读核对。请求失败或结果不明时先查询,避免重复创建或重复执行;未确认结果就报告“未确认”,不得声称成功或自动补偿删除。
|
|
42
|
+
|
|
43
|
+
## 隐私与结果汇报
|
|
44
|
+
|
|
45
|
+
- 只展示完成任务所需的信息,不倾倒整本通讯录或日程。只读实测优先输出查询范围、数量或成功/失败摘要,不展示无关正文;使用 codemode 时在当前调用内处理并精简输出,不把原始工具结果整段 `text()` 回显。
|
|
46
|
+
- 不把凭据、联系人正文或日程正文写入 `store`、日志、额外文件、代码仓库或记忆条目;也不在示例中固化真实姓名、电话、邮箱、UID 或个人目录。
|
|
47
|
+
- 分开汇报连接、目录发现、真实数据读取和写入结果;列出失败及未验证项。空结果不等于故障,也不证明有数据;只读成功不代表创建、修改、删除或周期处理已经通过验收。
|