ework3-task-mcp 0.1.0 → 0.3.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/README.md +169 -152
- package/dist/index.js +1729 -91
- package/package.json +41 -41
package/dist/index.js
CHANGED
|
@@ -22820,6 +22820,326 @@ function toNumericId(value) {
|
|
|
22820
22820
|
return Number.isFinite(numeric) ? numeric : value;
|
|
22821
22821
|
}
|
|
22822
22822
|
|
|
22823
|
+
// src/domain/groups.ts
|
|
22824
|
+
var MAX_GROUPS_FOR_COUNTS = 30;
|
|
22825
|
+
var MAX_GROUPS_FOR_LOOKUP = 30;
|
|
22826
|
+
var GROUP_NAME_MAX_LENGTH = 30;
|
|
22827
|
+
function isNoGroupTarget(value) {
|
|
22828
|
+
const text = value.trim().toLowerCase();
|
|
22829
|
+
return text === "" || text === "\u672A\u5206\u7EC4" || text === "none" || text === "no_group";
|
|
22830
|
+
}
|
|
22831
|
+
function validateGroupName(value, label = "\u5206\u7EC4\u540D\u79F0") {
|
|
22832
|
+
const name = value.trim();
|
|
22833
|
+
if (!name) {
|
|
22834
|
+
throw new EworkError(`${label}\u4E0D\u80FD\u4E3A\u7A7A`);
|
|
22835
|
+
}
|
|
22836
|
+
if (name.length > GROUP_NAME_MAX_LENGTH) {
|
|
22837
|
+
throw new EworkError(
|
|
22838
|
+
`${label}\u8FC7\u957F\uFF08${name.length} \u5B57\u7B26\uFF09\uFF0C\u6700\u591A ${GROUP_NAME_MAX_LENGTH} \u5B57\u7B26`
|
|
22839
|
+
);
|
|
22840
|
+
}
|
|
22841
|
+
return name;
|
|
22842
|
+
}
|
|
22843
|
+
function findDuplicateGroup(groups, name, excludeId) {
|
|
22844
|
+
const target = name.trim();
|
|
22845
|
+
return groups.find(
|
|
22846
|
+
(group) => String(group.id ?? "") !== excludeId && String(group.groupName ?? "").trim() === target
|
|
22847
|
+
);
|
|
22848
|
+
}
|
|
22849
|
+
function matchGroup(input, groups) {
|
|
22850
|
+
const value = input.trim();
|
|
22851
|
+
if (!value) {
|
|
22852
|
+
return {
|
|
22853
|
+
ok: false,
|
|
22854
|
+
message: "\u8BF7\u63D0\u4F9B\u5206\u7EC4\u540D\u79F0\u6216\u5206\u7EC4 id",
|
|
22855
|
+
candidates: [],
|
|
22856
|
+
available: groups.map(toCandidate)
|
|
22857
|
+
};
|
|
22858
|
+
}
|
|
22859
|
+
const byId = groups.filter((group) => String(group.id ?? "") === value);
|
|
22860
|
+
if (byId.length === 1) {
|
|
22861
|
+
return { ok: true, group: byId[0] };
|
|
22862
|
+
}
|
|
22863
|
+
const byName = groups.filter(
|
|
22864
|
+
(group) => String(group.groupName ?? "").trim() === value
|
|
22865
|
+
);
|
|
22866
|
+
if (byName.length === 1) {
|
|
22867
|
+
return { ok: true, group: byName[0] };
|
|
22868
|
+
}
|
|
22869
|
+
if (byName.length > 1) {
|
|
22870
|
+
return {
|
|
22871
|
+
ok: false,
|
|
22872
|
+
message: `\u5206\u7EC4\u540D\u79F0\u300C${value}\u300D\u6709 ${byName.length} \u4E2A\u540C\u540D\u5206\u7EC4\uFF0C\u8BF7\u6539\u7528\u5206\u7EC4 id \u6307\u5B9A`,
|
|
22873
|
+
candidates: byName.map(toCandidate)
|
|
22874
|
+
};
|
|
22875
|
+
}
|
|
22876
|
+
if (!groups.length) {
|
|
22877
|
+
return {
|
|
22878
|
+
ok: false,
|
|
22879
|
+
message: `\u6CA1\u6709\u627E\u5230\u5206\u7EC4\u300C${value}\u300D\uFF1B\u5F53\u524D\u5458\u5DE5\u8FD8\u6CA1\u6709\u5206\u7EC4\uFF0C\u53EF\u7528 manage_task_group \u521B\u5EFA`,
|
|
22880
|
+
candidates: [],
|
|
22881
|
+
available: []
|
|
22882
|
+
};
|
|
22883
|
+
}
|
|
22884
|
+
return {
|
|
22885
|
+
ok: false,
|
|
22886
|
+
message: `\u6CA1\u6709\u627E\u5230\u5206\u7EC4\u300C${value}\u300D`,
|
|
22887
|
+
candidates: [],
|
|
22888
|
+
available: groups.map(toCandidate)
|
|
22889
|
+
};
|
|
22890
|
+
}
|
|
22891
|
+
async function resolveTaskGroup(ctx, input) {
|
|
22892
|
+
const groups = await loadPersonalGroups(ctx);
|
|
22893
|
+
return matchGroup(input, groups);
|
|
22894
|
+
}
|
|
22895
|
+
async function loadPersonalGroups(ctx) {
|
|
22896
|
+
const raw = await ctx.client.requestRaw(
|
|
22897
|
+
"POST",
|
|
22898
|
+
"/external/home/task/setting/loadEmpGroups",
|
|
22899
|
+
{ json: { type: "T" }, write: false }
|
|
22900
|
+
);
|
|
22901
|
+
return raw.result ?? [];
|
|
22902
|
+
}
|
|
22903
|
+
async function groupTaskCount(ctx, groupId) {
|
|
22904
|
+
const raw = await ctx.client.requestRaw(
|
|
22905
|
+
"POST",
|
|
22906
|
+
"/external/home/task/v2/query/loadByParamsInPage",
|
|
22907
|
+
{
|
|
22908
|
+
json: {
|
|
22909
|
+
groupId,
|
|
22910
|
+
isTopTask: "N",
|
|
22911
|
+
current: 1,
|
|
22912
|
+
size: 1
|
|
22913
|
+
},
|
|
22914
|
+
write: false
|
|
22915
|
+
}
|
|
22916
|
+
);
|
|
22917
|
+
return Number(raw.total ?? 0);
|
|
22918
|
+
}
|
|
22919
|
+
async function isTaskInGroup(ctx, taskId, groupId) {
|
|
22920
|
+
const raw = await ctx.client.requestRaw(
|
|
22921
|
+
"POST",
|
|
22922
|
+
"/external/home/task/v2/query/loadByParamsInPage",
|
|
22923
|
+
{
|
|
22924
|
+
json: {
|
|
22925
|
+
groupId,
|
|
22926
|
+
taskIds: [taskId],
|
|
22927
|
+
isTopTask: "N",
|
|
22928
|
+
current: 1,
|
|
22929
|
+
size: 1
|
|
22930
|
+
},
|
|
22931
|
+
write: false
|
|
22932
|
+
}
|
|
22933
|
+
);
|
|
22934
|
+
return (raw.result ?? []).some((item) => String(item.id ?? "") === taskId);
|
|
22935
|
+
}
|
|
22936
|
+
async function taskGroupIdsContaining(ctx, taskId, groups) {
|
|
22937
|
+
if (groups.length > MAX_GROUPS_FOR_LOOKUP) {
|
|
22938
|
+
throw new EworkError(
|
|
22939
|
+
`\u5206\u7EC4\u6570\u91CF\u8D85\u8FC7 ${MAX_GROUPS_FOR_LOOKUP} \u4E2A\uFF0C\u65E0\u6CD5\u81EA\u52A8\u786E\u8BA4\u4EFB\u52A1\u6240\u5C5E\u5206\u7EC4\uFF1B\u8BF7\u5148\u5728\u7F51\u9875\u6574\u7406\u5206\u7EC4\uFF0C\u6216\u5206\u6B21\u5904\u7406`
|
|
22940
|
+
);
|
|
22941
|
+
}
|
|
22942
|
+
const groupIds = [];
|
|
22943
|
+
for (const group of groups) {
|
|
22944
|
+
const id = String(group.id ?? "");
|
|
22945
|
+
if (id && await isTaskInGroup(ctx, taskId, id)) {
|
|
22946
|
+
groupIds.push(id);
|
|
22947
|
+
}
|
|
22948
|
+
}
|
|
22949
|
+
return groupIds;
|
|
22950
|
+
}
|
|
22951
|
+
function formatGroupCandidate(group) {
|
|
22952
|
+
const count = group.taskCount === void 0 ? "" : ` \u4EFB\u52A1 ${group.taskCount} \u6761`;
|
|
22953
|
+
return `- ${group.name || "\uFF08\u65E0\u540D\u79F0\uFF09"}\uFF08${group.id}\uFF09${count}`;
|
|
22954
|
+
}
|
|
22955
|
+
function formatGroupFailure(resolution) {
|
|
22956
|
+
const lines = [resolution.message];
|
|
22957
|
+
if (resolution.candidates.length) {
|
|
22958
|
+
lines.push("\u5019\u9009\u5206\u7EC4\uFF1A");
|
|
22959
|
+
lines.push(...resolution.candidates.map(formatGroupCandidate));
|
|
22960
|
+
}
|
|
22961
|
+
if (resolution.available?.length) {
|
|
22962
|
+
lines.push("\u53EF\u7528\u5206\u7EC4\uFF1A");
|
|
22963
|
+
lines.push(...resolution.available.map(formatGroupCandidate));
|
|
22964
|
+
}
|
|
22965
|
+
return lines.join("\n");
|
|
22966
|
+
}
|
|
22967
|
+
function groupToCandidate(group, taskCount) {
|
|
22968
|
+
return {
|
|
22969
|
+
id: String(group.id ?? ""),
|
|
22970
|
+
name: String(group.groupName ?? ""),
|
|
22971
|
+
seq: group.seq,
|
|
22972
|
+
taskCount
|
|
22973
|
+
};
|
|
22974
|
+
}
|
|
22975
|
+
function toCandidate(group) {
|
|
22976
|
+
return groupToCandidate(group);
|
|
22977
|
+
}
|
|
22978
|
+
|
|
22979
|
+
// src/tools/assignTaskGroup.ts
|
|
22980
|
+
function registerAssignTaskToGroup(server, ctx) {
|
|
22981
|
+
server.registerTool(
|
|
22982
|
+
"assign_task_to_group",
|
|
22983
|
+
{
|
|
22984
|
+
title: "\u628A\u4EFB\u52A1\u79FB\u5165\u6216\u79FB\u51FA\u5206\u7EC4",
|
|
22985
|
+
description: "\u628A\u4EFB\u52A1\u79FB\u5165\u5F53\u524D API Key \u5458\u5DE5\u7684\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u3001\u5728\u5206\u7EC4\u95F4\u79FB\u52A8\uFF0C\u6216\u79FB\u51FA\u5206\u7EC4\u3002group \u4F20\u5206\u7EC4\u540D\u79F0\u6216 id\uFF1B\u4F20\u300C\u672A\u5206\u7EC4\u300D\u300Cnone\u300D\u6216\u7A7A\u4E32\u8868\u793A\u79FB\u51FA\u6240\u6709\u5206\u7EC4\u3002\u53EA\u8981\u6C42\u4EFB\u52A1\u5BF9\u5F53\u524D\u5458\u5DE5\u53EF\u89C1\uFF1B\u5206\u7EC4\u53EA\u6539\u4E2A\u4EBA\u770B\u677F\uFF0C\u4E0D\u6539\u4EFB\u52A1\u672C\u8EAB\u3002\u5FC5\u987B\u5148\u4E0D\u5E26 confirm \u8C03\u7528\u62FF previewToken\uFF0C\u628A\u9884\u6F14\u5C55\u793A\u7ED9\u7528\u6237\u5E76\u53D6\u5F97\u660E\u786E\u540C\u610F\u540E\uFF0C\u518D\u5E26 previewToken \u548C confirm=true \u6267\u884C\u3002",
|
|
22986
|
+
inputSchema: {
|
|
22987
|
+
taskId: external_exports.string().optional().describe("\u4EFB\u52A1\u7F16\u53F7\uFF1B\u4E0E url \u4E8C\u9009\u4E00"),
|
|
22988
|
+
url: external_exports.string().optional().describe("\u4EFB\u52A1\u94FE\u63A5\uFF1B\u4E0E taskId \u4E8C\u9009\u4E00"),
|
|
22989
|
+
group: external_exports.string().describe("\u76EE\u6807\u5206\u7EC4\u540D\u79F0\u6216 id\uFF1B\u4F20\u300C\u672A\u5206\u7EC4\u300D\u300Cnone\u300D\u6216\u7A7A\u4E32\u8868\u793A\u79FB\u51FA\u5206\u7EC4"),
|
|
22990
|
+
confirm: external_exports.boolean().optional().describe("true \u624D\u771F\u6B63\u5199\u5165\uFF1B\u7F3A\u7701\u53EA\u9884\u6F14"),
|
|
22991
|
+
previewToken: external_exports.string().optional().describe("\u9884\u6F14\u8FD4\u56DE\u7684\u4EE4\u724C\uFF1Bconfirm=true \u65F6\u5FC5\u586B")
|
|
22992
|
+
},
|
|
22993
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
|
|
22994
|
+
},
|
|
22995
|
+
async (args) => {
|
|
22996
|
+
try {
|
|
22997
|
+
return await handleAssign(ctx, args);
|
|
22998
|
+
} catch (error2) {
|
|
22999
|
+
return fail(error2);
|
|
23000
|
+
}
|
|
23001
|
+
}
|
|
23002
|
+
);
|
|
23003
|
+
}
|
|
23004
|
+
async function handleAssign(ctx, args) {
|
|
23005
|
+
const taskId = resolveTaskInput(ctx, args.taskId, args.url);
|
|
23006
|
+
const detail = await loadDetail(ctx, taskId);
|
|
23007
|
+
const groups = await loadPersonalGroups(ctx);
|
|
23008
|
+
if (groups.length > MAX_GROUPS_FOR_LOOKUP) {
|
|
23009
|
+
throw new EworkError(
|
|
23010
|
+
`\u5206\u7EC4\u6570\u91CF\u8D85\u8FC7 ${MAX_GROUPS_FOR_LOOKUP} \u4E2A\uFF0C\u65E0\u6CD5\u81EA\u52A8\u786E\u8BA4\u4EFB\u52A1\u6240\u5C5E\u5206\u7EC4\uFF1B\u8BF7\u5148\u5728\u7F51\u9875\u6574\u7406\u5206\u7EC4\uFF0C\u6216\u5206\u6B21\u5904\u7406`
|
|
23011
|
+
);
|
|
23012
|
+
}
|
|
23013
|
+
const target = resolveTargetGroup(args.group, groups);
|
|
23014
|
+
const sourceGroupIds = await taskGroupIdsContaining(ctx, taskId, groups);
|
|
23015
|
+
const sourceGroups = describeGroups(groups, sourceGroupIds);
|
|
23016
|
+
if (target && sourceGroupIds.length === 1 && sourceGroupIds[0] === target.id) {
|
|
23017
|
+
return ok(
|
|
23018
|
+
`\u4EFB\u52A1 ${taskId} \u5DF2\u7ECF\u5728\u5206\u7EC4\u300C${target.name}\u300D\u4E2D\uFF0C\u65E0\u9700\u4FEE\u6539\u3002`,
|
|
23019
|
+
{
|
|
23020
|
+
taskId,
|
|
23021
|
+
sourceGroups,
|
|
23022
|
+
targetGroup: target,
|
|
23023
|
+
changed: false,
|
|
23024
|
+
verified: true
|
|
23025
|
+
}
|
|
23026
|
+
);
|
|
23027
|
+
}
|
|
23028
|
+
if (!target && sourceGroupIds.length === 0) {
|
|
23029
|
+
return ok(`\u4EFB\u52A1 ${taskId} \u672C\u6765\u5C31\u4E0D\u5728\u4EFB\u4F55\u4E2A\u4EBA\u5206\u7EC4\u4E2D\uFF0C\u65E0\u9700\u4FEE\u6539\u3002`, {
|
|
23030
|
+
taskId,
|
|
23031
|
+
sourceGroups: [],
|
|
23032
|
+
targetGroup: null,
|
|
23033
|
+
changed: false,
|
|
23034
|
+
verified: true
|
|
23035
|
+
});
|
|
23036
|
+
}
|
|
23037
|
+
const payload = {
|
|
23038
|
+
taskId,
|
|
23039
|
+
targetGroupId: target?.id ?? null,
|
|
23040
|
+
sourceGroupIds: [...sourceGroupIds].sort()
|
|
23041
|
+
};
|
|
23042
|
+
const preview = formatAssignPreview(detail, taskId, sourceGroups, target);
|
|
23043
|
+
if (!args.confirm) {
|
|
23044
|
+
const previewToken = createPreviewToken("assign_task_to_group", taskId, payload);
|
|
23045
|
+
return ok(`${preview}
|
|
23046
|
+
previewToken\uFF1A${previewToken}
|
|
23047
|
+
\u8BF7\u786E\u8BA4\u540E\u5E26 previewToken \u4E0E confirm=true \u6267\u884C\u3002`, {
|
|
23048
|
+
taskId,
|
|
23049
|
+
sourceGroups,
|
|
23050
|
+
targetGroup: target,
|
|
23051
|
+
previewToken,
|
|
23052
|
+
expiresInSeconds: previewTtlSeconds()
|
|
23053
|
+
});
|
|
23054
|
+
}
|
|
23055
|
+
consumePreviewToken(args.previewToken, "assign_task_to_group", taskId, payload);
|
|
23056
|
+
if (target) {
|
|
23057
|
+
await addTaskToGroup(ctx, target.id, taskId);
|
|
23058
|
+
for (const sourceId of sourceGroupIds) {
|
|
23059
|
+
if (sourceId !== target.id) {
|
|
23060
|
+
await removeTaskFromGroup(ctx, sourceId, taskId);
|
|
23061
|
+
}
|
|
23062
|
+
}
|
|
23063
|
+
} else {
|
|
23064
|
+
for (const sourceId of sourceGroupIds) {
|
|
23065
|
+
await removeTaskFromGroup(ctx, sourceId, taskId);
|
|
23066
|
+
}
|
|
23067
|
+
}
|
|
23068
|
+
const afterGroups = await loadPersonalGroups(ctx);
|
|
23069
|
+
const afterSourceIds = await taskGroupIdsContaining(ctx, taskId, afterGroups);
|
|
23070
|
+
const expectedIds = target ? [target.id] : [];
|
|
23071
|
+
const verified = sameIds(afterSourceIds, expectedIds);
|
|
23072
|
+
const afterNames = describeGroups(afterGroups, afterSourceIds);
|
|
23073
|
+
return ok(
|
|
23074
|
+
[
|
|
23075
|
+
verified ? target ? `\u5DF2\u628A\u4EFB\u52A1 ${taskId} \u79FB\u5230\u5206\u7EC4\u300C${target.name}\u300D\u3002` : `\u5DF2\u628A\u4EFB\u52A1 ${taskId} \u79FB\u51FA\u6240\u6709\u4E2A\u4EBA\u5206\u7EC4\u3002` : `\u5206\u7EC4\u64CD\u4F5C\u5DF2\u63D0\u4EA4\uFF0C\u4F46\u56DE\u8BFB\u672A\u786E\u8BA4\uFF1B\u5F53\u524D\u4EFB\u52A1\u5728\uFF1A${formatGroupNames(afterNames) || "\u672A\u5206\u7EC4"}\u3002`,
|
|
23076
|
+
`\u4EFB\u52A1\uFF1A${taskTitle(detail)}`
|
|
23077
|
+
].join("\n"),
|
|
23078
|
+
{
|
|
23079
|
+
taskId,
|
|
23080
|
+
sourceGroups,
|
|
23081
|
+
targetGroup: target,
|
|
23082
|
+
afterGroups: afterNames,
|
|
23083
|
+
changed: true,
|
|
23084
|
+
verified
|
|
23085
|
+
}
|
|
23086
|
+
);
|
|
23087
|
+
}
|
|
23088
|
+
function resolveTargetGroup(input, groups) {
|
|
23089
|
+
if (isNoGroupTarget(input)) {
|
|
23090
|
+
return void 0;
|
|
23091
|
+
}
|
|
23092
|
+
const resolution = matchGroup(input, groups);
|
|
23093
|
+
if (!resolution.ok) {
|
|
23094
|
+
throw new EworkError(formatGroupFailure(resolution));
|
|
23095
|
+
}
|
|
23096
|
+
const id = String(resolution.group.id ?? "").trim();
|
|
23097
|
+
if (!id) {
|
|
23098
|
+
throw new EworkError(`\u5206\u7EC4\u300C${resolution.group.groupName ?? input}\u300D\u7F3A\u5C11\u5206\u7EC4 id\uFF0C\u65E0\u6CD5\u5199\u5165`);
|
|
23099
|
+
}
|
|
23100
|
+
return {
|
|
23101
|
+
id,
|
|
23102
|
+
name: String(resolution.group.groupName ?? "")
|
|
23103
|
+
};
|
|
23104
|
+
}
|
|
23105
|
+
function describeGroups(groups, groupIds) {
|
|
23106
|
+
return groupIds.map((id) => {
|
|
23107
|
+
const group = groups.find((item) => String(item.id ?? "") === id);
|
|
23108
|
+
return { id, name: String(group?.groupName ?? "").trim() || id };
|
|
23109
|
+
});
|
|
23110
|
+
}
|
|
23111
|
+
function formatAssignPreview(detail, taskId, sources, target) {
|
|
23112
|
+
return [
|
|
23113
|
+
`\u4EFB\u52A1\u5206\u7EC4\u9884\u6F14\uFF08\u672A\u5199\u5165\uFF09\uFF1A`,
|
|
23114
|
+
`\u4EFB\u52A1\uFF1A${taskTitle(detail)}\uFF08${taskId}\uFF09`,
|
|
23115
|
+
`\u5F53\u524D\u5206\u7EC4\uFF1A${formatGroupNames(sources) || "\u672A\u5206\u7EC4"}`,
|
|
23116
|
+
`\u76EE\u6807\u5206\u7EC4\uFF1A${target ? `${target.name}\uFF08${target.id}\uFF09` : "\u672A\u5206\u7EC4\uFF08\u79FB\u51FA\u6240\u6709\u5206\u7EC4\uFF09"}`,
|
|
23117
|
+
"\u4EFB\u52A1\u53EA\u80FD\u4FDD\u7559\u4E00\u4E2A\u4E2A\u4EBA\u5206\u7EC4\uFF1B\u786E\u8BA4\u540E\u4F1A\u4ECE\u5176\u4ED6\u5206\u7EC4\u79FB\u9664\u3002"
|
|
23118
|
+
].join("\n");
|
|
23119
|
+
}
|
|
23120
|
+
function formatGroupNames(groups) {
|
|
23121
|
+
return groups.map((group) => `${group.name}\uFF08${group.id}\uFF09`).join("\u3001");
|
|
23122
|
+
}
|
|
23123
|
+
async function addTaskToGroup(ctx, groupId, taskId) {
|
|
23124
|
+
await ctx.client.post("/external/home/task/setting/addTaskInGroup", {
|
|
23125
|
+
groupId,
|
|
23126
|
+
relId: taskId
|
|
23127
|
+
});
|
|
23128
|
+
}
|
|
23129
|
+
async function removeTaskFromGroup(ctx, groupId, taskId) {
|
|
23130
|
+
await ctx.client.post("/external/home/task/setting/removeTaskInGroup", {
|
|
23131
|
+
groupId,
|
|
23132
|
+
relId: taskId
|
|
23133
|
+
});
|
|
23134
|
+
}
|
|
23135
|
+
function sameIds(actual, expected) {
|
|
23136
|
+
if (actual.length !== expected.length) {
|
|
23137
|
+
return false;
|
|
23138
|
+
}
|
|
23139
|
+
const set = new Set(actual);
|
|
23140
|
+
return expected.every((id) => set.has(id));
|
|
23141
|
+
}
|
|
23142
|
+
|
|
22823
23143
|
// src/domain/members.ts
|
|
22824
23144
|
function collectMembers(detail) {
|
|
22825
23145
|
const members = [];
|
|
@@ -22855,6 +23175,62 @@ function dedupe(members) {
|
|
|
22855
23175
|
return result;
|
|
22856
23176
|
}
|
|
22857
23177
|
|
|
23178
|
+
// src/domain/employees.ts
|
|
23179
|
+
async function resolveEmployee(ctx, input) {
|
|
23180
|
+
const keyword = input.trim();
|
|
23181
|
+
if (!keyword) {
|
|
23182
|
+
return { ok: false, message: "\u8BF7\u63D0\u4F9B\u5458\u5DE5\u59D3\u540D\u6216 empId", candidates: [] };
|
|
23183
|
+
}
|
|
23184
|
+
const list = await ctx.client.get("/external/base/sel2/emp", { queryKey: keyword }) ?? [];
|
|
23185
|
+
const byId = list.find((emp) => emp.id === keyword);
|
|
23186
|
+
if (byId) {
|
|
23187
|
+
return { ok: true, emp: byId };
|
|
23188
|
+
}
|
|
23189
|
+
const sameName = list.filter((emp) => emp.name === keyword);
|
|
23190
|
+
if (sameName.length === 1) {
|
|
23191
|
+
return { ok: true, emp: sameName[0] };
|
|
23192
|
+
}
|
|
23193
|
+
if (sameName.length > 1) {
|
|
23194
|
+
return {
|
|
23195
|
+
ok: false,
|
|
23196
|
+
message: `\u300C${keyword}\u300D\u6709 ${sameName.length} \u4E2A\u540C\u540D\u5458\u5DE5\uFF0C\u8BF7\u6539\u7528 empId \u6307\u5B9A`,
|
|
23197
|
+
candidates: sameName
|
|
23198
|
+
};
|
|
23199
|
+
}
|
|
23200
|
+
if (list.length === 1) {
|
|
23201
|
+
return {
|
|
23202
|
+
ok: false,
|
|
23203
|
+
message: `\u6CA1\u6709\u7CBE\u786E\u5339\u914D\u5230\u5458\u5DE5\u300C${keyword}\u300D\uFF1B\u53EA\u627E\u5230\u4E00\u4E2A\u76F8\u8FD1\u7ED3\u679C\uFF0C\u8BF7\u786E\u8BA4\u59D3\u540D\u6216\u6539\u7528 empId`,
|
|
23204
|
+
candidates: list
|
|
23205
|
+
};
|
|
23206
|
+
}
|
|
23207
|
+
return {
|
|
23208
|
+
ok: false,
|
|
23209
|
+
message: list.length ? `\u300C${keyword}\u300D\u5339\u914D\u5230\u591A\u4E2A\u5458\u5DE5\uFF0C\u8BF7\u6539\u7528 empId \u6307\u5B9A` : `\u6CA1\u6709\u627E\u5230\u5458\u5DE5\u300C${keyword}\u300D\uFF1B\u8BF7\u63D0\u4F9B\u66F4\u5B8C\u6574\u7684\u59D3\u540D\uFF0C\u6216\u5148\u7528 search_employee \u67E5\u8BE2`,
|
|
23210
|
+
candidates: list
|
|
23211
|
+
};
|
|
23212
|
+
}
|
|
23213
|
+
async function resolveEmployeeOrThrow(ctx, input) {
|
|
23214
|
+
const resolution = await resolveEmployee(ctx, input);
|
|
23215
|
+
if (!resolution.ok) {
|
|
23216
|
+
throw new EworkError(
|
|
23217
|
+
resolution.candidates.length ? `${resolution.message}
|
|
23218
|
+
\u5019\u9009\uFF1A
|
|
23219
|
+
${formatCandidates(resolution.candidates)}` : resolution.message
|
|
23220
|
+
);
|
|
23221
|
+
}
|
|
23222
|
+
return resolution.emp;
|
|
23223
|
+
}
|
|
23224
|
+
function formatCandidates(list) {
|
|
23225
|
+
return list.map((emp) => `- ${emp.name || "-"}\uFF08${emp.id || "-"}\uFF09${emp.departmentFullName || ""}`).join("\n");
|
|
23226
|
+
}
|
|
23227
|
+
function describeEmployee(emp) {
|
|
23228
|
+
const name = emp.name || emp.id || "";
|
|
23229
|
+
const id = emp.id ? `\uFF08${emp.id}\uFF09` : "";
|
|
23230
|
+
const department = emp.departmentFullName ? ` ${emp.departmentFullName}` : "";
|
|
23231
|
+
return `${name}${id}${department}`.trim();
|
|
23232
|
+
}
|
|
23233
|
+
|
|
22858
23234
|
// src/tools/changeOwner.ts
|
|
22859
23235
|
function registerChangeOwner(server, ctx) {
|
|
22860
23236
|
server.registerTool(
|
|
@@ -22951,40 +23327,6 @@ ${formatCandidates(resolution.candidates)}` : resolution.message
|
|
|
22951
23327
|
}
|
|
22952
23328
|
);
|
|
22953
23329
|
}
|
|
22954
|
-
async function resolveEmployee(ctx, input) {
|
|
22955
|
-
const keyword = input.trim();
|
|
22956
|
-
if (!keyword) {
|
|
22957
|
-
return { ok: false, message: "\u8BF7\u63D0\u4F9B\u5458\u5DE5\u59D3\u540D\u6216 empId", candidates: [] };
|
|
22958
|
-
}
|
|
22959
|
-
const list = await ctx.client.get("/external/base/sel2/emp", { queryKey: keyword }) ?? [];
|
|
22960
|
-
const byId = list.find((emp) => emp.id === keyword);
|
|
22961
|
-
if (byId) {
|
|
22962
|
-
return { ok: true, emp: byId };
|
|
22963
|
-
}
|
|
22964
|
-
const sameName = list.filter((emp) => emp.name === keyword);
|
|
22965
|
-
if (sameName.length === 1) {
|
|
22966
|
-
return { ok: true, emp: sameName[0] };
|
|
22967
|
-
}
|
|
22968
|
-
if (sameName.length > 1) {
|
|
22969
|
-
return {
|
|
22970
|
-
ok: false,
|
|
22971
|
-
message: `\u300C${keyword}\u300D\u6709 ${sameName.length} \u4E2A\u540C\u540D\u5458\u5DE5\uFF0C\u8BF7\u6539\u7528 empId \u6307\u5B9A`,
|
|
22972
|
-
candidates: sameName
|
|
22973
|
-
};
|
|
22974
|
-
}
|
|
22975
|
-
if (list.length === 1) {
|
|
22976
|
-
return {
|
|
22977
|
-
ok: false,
|
|
22978
|
-
message: `\u6CA1\u6709\u7CBE\u786E\u5339\u914D\u5230\u5458\u5DE5\u300C${keyword}\u300D\uFF1B\u53EA\u627E\u5230\u4E00\u4E2A\u76F8\u8FD1\u7ED3\u679C\uFF0C\u8BF7\u786E\u8BA4\u59D3\u540D\u6216\u6539\u7528 empId`,
|
|
22979
|
-
candidates: list
|
|
22980
|
-
};
|
|
22981
|
-
}
|
|
22982
|
-
return {
|
|
22983
|
-
ok: false,
|
|
22984
|
-
message: list.length ? `\u300C${keyword}\u300D\u5339\u914D\u5230\u591A\u4E2A\u5458\u5DE5\uFF0C\u8BF7\u6539\u7528 empId \u6307\u5B9A` : `\u6CA1\u6709\u627E\u5230\u5458\u5DE5\u300C${keyword}\u300D\uFF1B\u8BF7\u63D0\u4F9B\u66F4\u5B8C\u6574\u7684\u59D3\u540D\uFF0C\u6216\u5148\u7528 search_employee \u67E5\u8BE2`,
|
|
22985
|
-
candidates: list
|
|
22986
|
-
};
|
|
22987
|
-
}
|
|
22988
23330
|
function buildNameMap(detail, target) {
|
|
22989
23331
|
const map = /* @__PURE__ */ new Map();
|
|
22990
23332
|
for (const emp of [...detail.ownEmps ?? [], ...detail.patEmps ?? [], ...detail.cpyEmps ?? []]) {
|
|
@@ -23014,15 +23356,6 @@ function roleLabel(role) {
|
|
|
23014
23356
|
if (role === "C") return "\u6284\u9001\u4EBA";
|
|
23015
23357
|
return role;
|
|
23016
23358
|
}
|
|
23017
|
-
function describeEmployee(emp) {
|
|
23018
|
-
const name = emp.name || emp.id || "";
|
|
23019
|
-
const id = emp.id ? `\uFF08${emp.id}\uFF09` : "";
|
|
23020
|
-
const department = emp.departmentFullName ? ` ${emp.departmentFullName}` : "";
|
|
23021
|
-
return `${name}${id}${department}`.trim();
|
|
23022
|
-
}
|
|
23023
|
-
function formatCandidates(list) {
|
|
23024
|
-
return list.map((emp) => `- ${emp.name || "-"}\uFF08${emp.id || "-"}\uFF09${emp.departmentFullName || ""}`).join("\n");
|
|
23025
|
-
}
|
|
23026
23359
|
|
|
23027
23360
|
// src/tools/changeStatus.ts
|
|
23028
23361
|
function registerChangeStatus(server, ctx) {
|
|
@@ -23119,14 +23452,868 @@ function registerChangeStatus(server, ctx) {
|
|
|
23119
23452
|
}
|
|
23120
23453
|
);
|
|
23121
23454
|
}
|
|
23122
|
-
function formatPreview3(preview, previewToken) {
|
|
23123
|
-
return [
|
|
23124
|
-
`\u4EFB\u52A1 ${preview.taskId}\uFF08${preview.title}\uFF09\u72B6\u6001\u4FEE\u6539\u9884\u6F14\uFF08\u672A\u5199\u5165\uFF09\uFF1A`,
|
|
23125
|
-
`\u72B6\u6001\uFF1A${preview.status.before.name || preview.status.before.id || "-"} \u2192 ${preview.status.after.name}\uFF08${preview.status.after.type}\uFF09`,
|
|
23126
|
-
`\u5907\u6CE8\uFF1A${preview.remark || "-"}`,
|
|
23127
|
-
`previewToken\uFF1A${previewToken}`,
|
|
23455
|
+
function formatPreview3(preview, previewToken) {
|
|
23456
|
+
return [
|
|
23457
|
+
`\u4EFB\u52A1 ${preview.taskId}\uFF08${preview.title}\uFF09\u72B6\u6001\u4FEE\u6539\u9884\u6F14\uFF08\u672A\u5199\u5165\uFF09\uFF1A`,
|
|
23458
|
+
`\u72B6\u6001\uFF1A${preview.status.before.name || preview.status.before.id || "-"} \u2192 ${preview.status.after.name}\uFF08${preview.status.after.type}\uFF09`,
|
|
23459
|
+
`\u5907\u6CE8\uFF1A${preview.remark || "-"}`,
|
|
23460
|
+
`previewToken\uFF1A${previewToken}`,
|
|
23461
|
+
"\u8BF7\u5148\u628A\u4EE5\u4E0A\u6539\u52A8\u5C55\u793A\u7ED9\u7528\u6237\uFF0C\u5F97\u5230\u660E\u786E\u540C\u610F\u540E\uFF0C\u518D\u5E26 previewToken \u4E0E confirm=true \u8C03\u7528\u3002"
|
|
23462
|
+
].join("\n");
|
|
23463
|
+
}
|
|
23464
|
+
|
|
23465
|
+
// src/domain/createTask.ts
|
|
23466
|
+
var DATE_INPUT_PATTERN = /^(\d{4})[/-](\d{1,2})[/-](\d{1,2})$/;
|
|
23467
|
+
var MEMBER_RANK = { O: 0, P: 1, C: 2 };
|
|
23468
|
+
var TEMPLATE_TITLES = {
|
|
23469
|
+
BIS: ["\u4E1A\u52A1\u7C7B\u4EFB\u52A1", "\u6807\u51C6\u884C\u52A8\u8BA1\u5212-\u4E1A\u52A1-\u4EFB\u52A1"],
|
|
23470
|
+
MGR: ["\u7BA1\u7406\u7C7B\u4EFB\u52A1", "\u6807\u51C6\u884C\u52A8\u8BA1\u5212-\u7BA1\u7406-\u4EFB\u52A1"]
|
|
23471
|
+
};
|
|
23472
|
+
var PRIORITY_CODES = {
|
|
23473
|
+
"\u975E\u5E38\u7D27\u6025": "3-VH",
|
|
23474
|
+
"3-VH": "3-VH",
|
|
23475
|
+
"3VH": "3-VH",
|
|
23476
|
+
"\u7D27\u6025": "2-H",
|
|
23477
|
+
"2-H": "2-H",
|
|
23478
|
+
H: "2-H",
|
|
23479
|
+
"\u666E\u901A": "1-M",
|
|
23480
|
+
"1-M": "1-M",
|
|
23481
|
+
M: "1-M",
|
|
23482
|
+
"\u8F83\u4F4E": "0-L",
|
|
23483
|
+
"0-L": "0-L",
|
|
23484
|
+
L: "0-L"
|
|
23485
|
+
};
|
|
23486
|
+
function todayDateString(now = /* @__PURE__ */ new Date()) {
|
|
23487
|
+
return `${now.getFullYear()}/${pad2(now.getMonth() + 1)}/${pad2(now.getDate())}`;
|
|
23488
|
+
}
|
|
23489
|
+
function normalizeDateInput(value, label = "\u65E5\u671F") {
|
|
23490
|
+
const text = value.trim();
|
|
23491
|
+
const match = DATE_INPUT_PATTERN.exec(text);
|
|
23492
|
+
if (!match) {
|
|
23493
|
+
throw new EworkError(`${label}\u683C\u5F0F\u4E0D\u6B63\u786E\uFF08${text}\uFF09\uFF1A\u8BF7\u7528 yyyy/MM/dd \u6216 yyyy-MM-dd`);
|
|
23494
|
+
}
|
|
23495
|
+
const year = Number(match[1]);
|
|
23496
|
+
const month = Number(match[2]);
|
|
23497
|
+
const day = Number(match[3]);
|
|
23498
|
+
const date3 = new Date(year, month - 1, day);
|
|
23499
|
+
if (date3.getFullYear() !== year || date3.getMonth() !== month - 1 || date3.getDate() !== day) {
|
|
23500
|
+
throw new EworkError(`${label}\u4E0D\u662F\u6709\u6548\u65E5\u671F\uFF1A${text}`);
|
|
23501
|
+
}
|
|
23502
|
+
return `${year}/${pad2(month)}/${pad2(day)}`;
|
|
23503
|
+
}
|
|
23504
|
+
function normalizePriority(value) {
|
|
23505
|
+
const text = value?.trim();
|
|
23506
|
+
if (!text) {
|
|
23507
|
+
return "1-M";
|
|
23508
|
+
}
|
|
23509
|
+
const code = PRIORITY_CODES[text] ?? PRIORITY_CODES[text.toUpperCase()];
|
|
23510
|
+
if (!code) {
|
|
23511
|
+
throw new EworkError(
|
|
23512
|
+
`\u4F18\u5148\u7EA7\u300C${text}\u300D\u4E0D\u8BA4\u8BC6\uFF1A\u8BF7\u7528 \u975E\u5E38\u7D27\u6025/\u7D27\u6025/\u666E\u901A/\u8F83\u4F4E\uFF0C\u6216 3-VH/2-H/1-M/0-L`
|
|
23513
|
+
);
|
|
23514
|
+
}
|
|
23515
|
+
return code;
|
|
23516
|
+
}
|
|
23517
|
+
function dedupeMembers(members) {
|
|
23518
|
+
const byEmpId = /* @__PURE__ */ new Map();
|
|
23519
|
+
for (const member of members) {
|
|
23520
|
+
const empId = member.empId.trim();
|
|
23521
|
+
if (!empId) {
|
|
23522
|
+
continue;
|
|
23523
|
+
}
|
|
23524
|
+
const existing = byEmpId.get(empId);
|
|
23525
|
+
if (!existing || MEMBER_RANK[member.role] < MEMBER_RANK[existing.role]) {
|
|
23526
|
+
byEmpId.set(empId, { empId, role: member.role });
|
|
23527
|
+
}
|
|
23528
|
+
}
|
|
23529
|
+
return Array.from(byEmpId.values()).sort(
|
|
23530
|
+
(a, b) => MEMBER_RANK[a.role] - MEMBER_RANK[b.role]
|
|
23531
|
+
);
|
|
23532
|
+
}
|
|
23533
|
+
function selectTemplate(templates, businessCode, explicitId) {
|
|
23534
|
+
const available = templates.filter(
|
|
23535
|
+
(template) => String(template.category ?? "") === "T" && template.id
|
|
23536
|
+
);
|
|
23537
|
+
const sameBusiness = available.filter(
|
|
23538
|
+
(template) => String(template.business ?? "") === businessCode
|
|
23539
|
+
);
|
|
23540
|
+
const specified = explicitId?.trim();
|
|
23541
|
+
if (specified) {
|
|
23542
|
+
const matched = available.filter((template) => String(template.id) === specified);
|
|
23543
|
+
if (matched.length === 1) {
|
|
23544
|
+
const templateBusiness = String(matched[0].business ?? "");
|
|
23545
|
+
if (businessCode && templateBusiness && templateBusiness !== businessCode) {
|
|
23546
|
+
return {
|
|
23547
|
+
ok: false,
|
|
23548
|
+
message: `\u6307\u5B9A\u7684\u6807\u51C6\u884C\u52A8\u8BA1\u5212\u5C5E\u4E8E\u300C${templateBusiness}\u300D\uFF0C\u4E0E\u8BA1\u5212\u4E1A\u52A1\u300C${businessCode}\u300D\u4E0D\u4E00\u81F4`,
|
|
23549
|
+
candidates: sameBusiness.length ? sameBusiness : available
|
|
23550
|
+
};
|
|
23551
|
+
}
|
|
23552
|
+
return { ok: true, template: matched[0], automatic: false };
|
|
23553
|
+
}
|
|
23554
|
+
return {
|
|
23555
|
+
ok: false,
|
|
23556
|
+
message: `\u6307\u5B9A\u7684\u6807\u51C6\u884C\u52A8\u8BA1\u5212\u4E0D\u5B58\u5728\u6216\u5F53\u524D\u5458\u5DE5\u4E0D\u53EF\u89C1\uFF1A${specified}`,
|
|
23557
|
+
candidates: available
|
|
23558
|
+
};
|
|
23559
|
+
}
|
|
23560
|
+
for (const title of TEMPLATE_TITLES[businessCode] ?? []) {
|
|
23561
|
+
const matched = sameBusiness.filter(
|
|
23562
|
+
(template) => String(template.title ?? "").trim() === title
|
|
23563
|
+
);
|
|
23564
|
+
if (matched.length === 1) {
|
|
23565
|
+
return { ok: true, template: matched[0], automatic: true };
|
|
23566
|
+
}
|
|
23567
|
+
if (matched.length > 1) {
|
|
23568
|
+
return {
|
|
23569
|
+
ok: false,
|
|
23570
|
+
message: `\u6807\u51C6\u884C\u52A8\u8BA1\u5212\u300C${title}\u300D\u6709 ${matched.length} \u4E2A\u540C\u540D\u6A21\u677F\uFF0C\u8BF7\u7528 template \u6307\u5B9A id`,
|
|
23571
|
+
candidates: matched
|
|
23572
|
+
};
|
|
23573
|
+
}
|
|
23574
|
+
}
|
|
23575
|
+
if (sameBusiness.length === 1) {
|
|
23576
|
+
return { ok: true, template: sameBusiness[0], automatic: true };
|
|
23577
|
+
}
|
|
23578
|
+
if (sameBusiness.length > 1) {
|
|
23579
|
+
return {
|
|
23580
|
+
ok: false,
|
|
23581
|
+
message: `\u8BA1\u5212\u4E1A\u52A1\u300C${businessCode}\u300D\u4E0B\u5339\u914D\u5230 ${sameBusiness.length} \u4E2A\u6807\u51C6\u884C\u52A8\u8BA1\u5212\uFF0C\u8BF7\u7528 template \u6307\u5B9A id`,
|
|
23582
|
+
candidates: sameBusiness
|
|
23583
|
+
};
|
|
23584
|
+
}
|
|
23585
|
+
return {
|
|
23586
|
+
ok: false,
|
|
23587
|
+
message: `\u6CA1\u6709\u627E\u5230\u8BA1\u5212\u4E1A\u52A1\u300C${businessCode}\u300D\u53EF\u7528\u7684\u6807\u51C6\u884C\u52A8\u8BA1\u5212\uFF0C\u8BF7\u7528 template \u6307\u5B9A id`,
|
|
23588
|
+
candidates: available
|
|
23589
|
+
};
|
|
23590
|
+
}
|
|
23591
|
+
function buildAddTaskPayload(input) {
|
|
23592
|
+
const payload = {
|
|
23593
|
+
template: input.template,
|
|
23594
|
+
planId: input.planId,
|
|
23595
|
+
planTaskCategoryId: input.planTaskCategoryId,
|
|
23596
|
+
title: input.title,
|
|
23597
|
+
status: input.status,
|
|
23598
|
+
priority: input.priority,
|
|
23599
|
+
startTime: input.startTime,
|
|
23600
|
+
endTime: input.endTime,
|
|
23601
|
+
isFullDay: "Y",
|
|
23602
|
+
emps: input.members.map((member) => ({
|
|
23603
|
+
empId: member.empId,
|
|
23604
|
+
role: member.role
|
|
23605
|
+
}))
|
|
23606
|
+
};
|
|
23607
|
+
if (input.detailsHtml) {
|
|
23608
|
+
payload.details = input.detailsHtml;
|
|
23609
|
+
}
|
|
23610
|
+
if (input.father) {
|
|
23611
|
+
payload.father = input.father;
|
|
23612
|
+
}
|
|
23613
|
+
if (input.projectId) {
|
|
23614
|
+
payload.projectId = input.projectId;
|
|
23615
|
+
}
|
|
23616
|
+
if (input.subProjectId) {
|
|
23617
|
+
payload.subProjectId = input.subProjectId;
|
|
23618
|
+
}
|
|
23619
|
+
if (input.groupId) {
|
|
23620
|
+
payload.groupId = input.groupId;
|
|
23621
|
+
}
|
|
23622
|
+
if (input.tagIds.length) {
|
|
23623
|
+
payload.taskTags = input.tagIds.map((tagId) => ({ tagId }));
|
|
23624
|
+
}
|
|
23625
|
+
return payload;
|
|
23626
|
+
}
|
|
23627
|
+
function templateLabel(template) {
|
|
23628
|
+
const title = template.title || "\uFF08\u672A\u547D\u540D\u6A21\u677F\uFF09";
|
|
23629
|
+
const id = template.id ? `\uFF08${template.id}\uFF09` : "";
|
|
23630
|
+
return `${title}${id}`;
|
|
23631
|
+
}
|
|
23632
|
+
function memberRoleLabel(role) {
|
|
23633
|
+
if (role === "O") return "\u8D1F\u8D23\u4EBA";
|
|
23634
|
+
if (role === "P") return "\u53C2\u4E0E\u4EBA";
|
|
23635
|
+
return "\u6284\u9001\u4EBA";
|
|
23636
|
+
}
|
|
23637
|
+
function pad2(value) {
|
|
23638
|
+
return String(value).padStart(2, "0");
|
|
23639
|
+
}
|
|
23640
|
+
|
|
23641
|
+
// src/domain/plans.ts
|
|
23642
|
+
var PLAN_ID_PATTERN = /^[0-9a-fA-F]{32}$/;
|
|
23643
|
+
var UNSAFE_PLAN_NAME = /['"\\;%_]|--/;
|
|
23644
|
+
var MAX_PLAN_NAME_LENGTH = 100;
|
|
23645
|
+
var PLAN_LOOKUP_SIZE = 100;
|
|
23646
|
+
var PLAN_AVAILABLE_SIZE = 20;
|
|
23647
|
+
function isPlanId(value) {
|
|
23648
|
+
return PLAN_ID_PATTERN.test(value.trim());
|
|
23649
|
+
}
|
|
23650
|
+
function normalizePlanName(value) {
|
|
23651
|
+
const name = value.trim();
|
|
23652
|
+
if (!name) {
|
|
23653
|
+
throw new EworkError("\u8BA1\u5212\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");
|
|
23654
|
+
}
|
|
23655
|
+
if (name.length > MAX_PLAN_NAME_LENGTH) {
|
|
23656
|
+
throw new EworkError(`\u8BA1\u5212\u540D\u79F0\u8FC7\u957F\uFF08${name.length} \u5B57\u7B26\uFF09\uFF0C\u6700\u591A ${MAX_PLAN_NAME_LENGTH} \u5B57\u7B26`);
|
|
23657
|
+
}
|
|
23658
|
+
if (UNSAFE_PLAN_NAME.test(name)) {
|
|
23659
|
+
throw new EworkError(
|
|
23660
|
+
`\u8BA1\u5212\u540D\u79F0\u5305\u542B\u4E0D\u652F\u6301\u7684\u5B57\u7B26\uFF08' " \\ ; % _ \u6216 --\uFF09\uFF0C\u8BF7\u6539\u7528 32 \u4F4D\u8BA1\u5212 id\uFF0C\u6216\u7B80\u5316\u8BA1\u5212\u540D\u79F0`
|
|
23661
|
+
);
|
|
23662
|
+
}
|
|
23663
|
+
return name;
|
|
23664
|
+
}
|
|
23665
|
+
async function resolvePlan(ctx, input) {
|
|
23666
|
+
const value = input.trim();
|
|
23667
|
+
if (!value) {
|
|
23668
|
+
throw new EworkError("\u8BF7\u63D0\u4F9B\u8BA1\u5212\u540D\u79F0\u6216 32 \u4F4D\u8BA1\u5212 id");
|
|
23669
|
+
}
|
|
23670
|
+
if (isPlanId(value)) {
|
|
23671
|
+
const plan = await loadPlanBase(ctx, value);
|
|
23672
|
+
if (!plan) {
|
|
23673
|
+
throw new EworkError(`\u8BA1\u5212\u4E0D\u5B58\u5728\u6216\u5DF2\u5220\u9664\uFF1A${value}`);
|
|
23674
|
+
}
|
|
23675
|
+
return { ok: true, plan, matchedBy: "id" };
|
|
23676
|
+
}
|
|
23677
|
+
const name = normalizePlanName(value);
|
|
23678
|
+
const page = await loadPlanPage(ctx, name, PLAN_LOOKUP_SIZE);
|
|
23679
|
+
const exact = page.items.filter((item) => String(item.title ?? "") === name);
|
|
23680
|
+
if (exact.length === 1) {
|
|
23681
|
+
const plan = await loadPlanBase(ctx, exact[0].id ?? "");
|
|
23682
|
+
if (!plan) {
|
|
23683
|
+
throw new EworkError(`\u8BA1\u5212\u4E0D\u5B58\u5728\u6216\u5DF2\u5220\u9664\uFF1A${exact[0].id ?? name}`);
|
|
23684
|
+
}
|
|
23685
|
+
return { ok: true, plan, matchedBy: "exact" };
|
|
23686
|
+
}
|
|
23687
|
+
if (exact.length > 1) {
|
|
23688
|
+
return {
|
|
23689
|
+
ok: false,
|
|
23690
|
+
message: `\u8BA1\u5212\u540D\u79F0\u300C${name}\u300D\u6709 ${exact.length} \u4E2A\u540C\u540D\u8BA1\u5212\uFF0C\u8BF7\u6539\u7528\u8BA1\u5212 id \u6307\u5B9A${pageNote(page)}`,
|
|
23691
|
+
candidates: exact.map(toCandidate2)
|
|
23692
|
+
};
|
|
23693
|
+
}
|
|
23694
|
+
if (page.items.length === 1) {
|
|
23695
|
+
const plan = await loadPlanBase(ctx, page.items[0].id ?? "");
|
|
23696
|
+
if (!plan) {
|
|
23697
|
+
throw new EworkError(`\u8BA1\u5212\u4E0D\u5B58\u5728\u6216\u5DF2\u5220\u9664\uFF1A${page.items[0].id ?? name}`);
|
|
23698
|
+
}
|
|
23699
|
+
return { ok: true, plan, matchedBy: "fuzzy" };
|
|
23700
|
+
}
|
|
23701
|
+
if (page.items.length > 1) {
|
|
23702
|
+
return {
|
|
23703
|
+
ok: false,
|
|
23704
|
+
message: `\u8BA1\u5212\u540D\u79F0\u300C${name}\u300D\u6A21\u7CCA\u5339\u914D\u5230 ${page.items.length} \u4E2A\u8BA1\u5212\uFF0C\u8BF7\u6539\u7528\u8BA1\u5212 id \u6307\u5B9A${pageNote(page)}`,
|
|
23705
|
+
candidates: page.items.map(toCandidate2)
|
|
23706
|
+
};
|
|
23707
|
+
}
|
|
23708
|
+
const available = await loadPlanPage(ctx, "", PLAN_AVAILABLE_SIZE);
|
|
23709
|
+
return {
|
|
23710
|
+
ok: false,
|
|
23711
|
+
message: `\u6CA1\u6709\u627E\u5230\u8BA1\u5212\u300C${name}\u300D${pageNote(page)}${available.items.length ? "\u3002\u5F53\u524D\u53EF\u7528\u7684\u8BA1\u5212\u89C1 availablePlans" : "\uFF0C\u5F53\u524D\u5458\u5DE5\u4E5F\u6CA1\u6709\u53EF\u89C1\u8BA1\u5212"}`,
|
|
23712
|
+
candidates: [],
|
|
23713
|
+
available: available.items.map(toCandidate2)
|
|
23714
|
+
};
|
|
23715
|
+
}
|
|
23716
|
+
function pageNote(page) {
|
|
23717
|
+
return page.total > page.items.length ? `\uFF08\u5339\u914D\u7ED3\u679C\u5171 ${page.total} \u6761\uFF0C\u4EC5\u5C55\u793A\u524D ${page.items.length} \u6761\uFF0C\u5EFA\u8BAE\u7528\u66F4\u5B8C\u6574\u7684\u540D\u79F0\u6216\u8BA1\u5212 id\uFF09` : "";
|
|
23718
|
+
}
|
|
23719
|
+
function formatPlanFailure(resolution) {
|
|
23720
|
+
const lines = [resolution.message];
|
|
23721
|
+
if (resolution.candidates.length) {
|
|
23722
|
+
lines.push("\u5019\u9009\u8BA1\u5212\uFF1A");
|
|
23723
|
+
lines.push(...resolution.candidates.map(formatPlanCandidate));
|
|
23724
|
+
}
|
|
23725
|
+
if (resolution.available?.length) {
|
|
23726
|
+
lines.push("\u5F53\u524D\u53EF\u7528\u7684\u8BA1\u5212\uFF1A");
|
|
23727
|
+
lines.push(...resolution.available.map(formatPlanCandidate));
|
|
23728
|
+
}
|
|
23729
|
+
return lines.join("\n");
|
|
23730
|
+
}
|
|
23731
|
+
function formatPlanCandidate(plan) {
|
|
23732
|
+
const archive = plan.isArchive ? "\uFF08\u5DF2\u5F52\u6863\uFF09" : "";
|
|
23733
|
+
const creator = plan.creatorName ? ` \u521B\u5EFA\u4EBA ${plan.creatorName}` : "";
|
|
23734
|
+
return `- ${plan.title || "\uFF08\u65E0\u6807\u9898\uFF09"}\uFF08${plan.id}\uFF09${archive}${creator}`;
|
|
23735
|
+
}
|
|
23736
|
+
async function loadPlanPage(ctx, title, size) {
|
|
23737
|
+
const taskPlan = { isDel: "N" };
|
|
23738
|
+
if (title) {
|
|
23739
|
+
taskPlan.title = title;
|
|
23740
|
+
}
|
|
23741
|
+
const raw = await ctx.client.requestRaw(
|
|
23742
|
+
"POST",
|
|
23743
|
+
"/external/home/task/plan/query/loadByParamsInPage",
|
|
23744
|
+
{
|
|
23745
|
+
json: {
|
|
23746
|
+
taskPlan,
|
|
23747
|
+
queryFollowers: "Y",
|
|
23748
|
+
current: 1,
|
|
23749
|
+
size
|
|
23750
|
+
},
|
|
23751
|
+
write: false
|
|
23752
|
+
}
|
|
23753
|
+
);
|
|
23754
|
+
return { items: raw.result ?? [], total: Number(raw.total ?? 0) };
|
|
23755
|
+
}
|
|
23756
|
+
async function loadPlanBase(ctx, planId) {
|
|
23757
|
+
if (!planId) {
|
|
23758
|
+
return null;
|
|
23759
|
+
}
|
|
23760
|
+
const raw = await ctx.client.get(
|
|
23761
|
+
"/external/home/task/plan/query/loadBaseById",
|
|
23762
|
+
{ id: planId }
|
|
23763
|
+
);
|
|
23764
|
+
if (!raw || raw.isDel === "Y") {
|
|
23765
|
+
return null;
|
|
23766
|
+
}
|
|
23767
|
+
return toPlanInfo(raw);
|
|
23768
|
+
}
|
|
23769
|
+
function toPlanInfo(raw) {
|
|
23770
|
+
const business = String(raw.business ?? "");
|
|
23771
|
+
const parsed = parseBusiness(business);
|
|
23772
|
+
return {
|
|
23773
|
+
id: String(raw.id ?? ""),
|
|
23774
|
+
title: String(raw.title ?? ""),
|
|
23775
|
+
business,
|
|
23776
|
+
businessCode: parsed.businessCode,
|
|
23777
|
+
isArchive: raw.isArchive === "Y",
|
|
23778
|
+
isMember: raw.isMember === "Y",
|
|
23779
|
+
isAdmin: raw.isAdmin === "Y",
|
|
23780
|
+
projectId: parsed.projectId ?? idOf(raw.projectBase?.id),
|
|
23781
|
+
subProjectId: parsed.subProjectId ?? idOf(raw.subProjectBase?.id),
|
|
23782
|
+
creatorName: raw.creatorName
|
|
23783
|
+
};
|
|
23784
|
+
}
|
|
23785
|
+
function parseBusiness(business) {
|
|
23786
|
+
const parts = business.split("/");
|
|
23787
|
+
const businessCode = parts[0] ?? "";
|
|
23788
|
+
if (parts.length === 3 && parts[1] === "PROJECT") {
|
|
23789
|
+
return { businessCode, projectId: parts[2] };
|
|
23790
|
+
}
|
|
23791
|
+
if (parts.length === 3 && parts[1] === "SUBPROJECT") {
|
|
23792
|
+
return { businessCode, subProjectId: parts[2] };
|
|
23793
|
+
}
|
|
23794
|
+
return { businessCode };
|
|
23795
|
+
}
|
|
23796
|
+
function toCandidate2(item) {
|
|
23797
|
+
return {
|
|
23798
|
+
id: String(item.id ?? ""),
|
|
23799
|
+
title: String(item.title ?? ""),
|
|
23800
|
+
business: String(item.business ?? ""),
|
|
23801
|
+
isArchive: item.isArchive === "Y"
|
|
23802
|
+
};
|
|
23803
|
+
}
|
|
23804
|
+
function idOf(value) {
|
|
23805
|
+
if (value === void 0 || value === null || value === "") {
|
|
23806
|
+
return void 0;
|
|
23807
|
+
}
|
|
23808
|
+
return String(value);
|
|
23809
|
+
}
|
|
23810
|
+
|
|
23811
|
+
// src/tools/createTask.ts
|
|
23812
|
+
var PRIORITY_LABELS = {
|
|
23813
|
+
"3-VH": "\u975E\u5E38\u7D27\u6025",
|
|
23814
|
+
"2-H": "\u7D27\u6025",
|
|
23815
|
+
"1-M": "\u666E\u901A",
|
|
23816
|
+
"0-L": "\u8F83\u4F4E"
|
|
23817
|
+
};
|
|
23818
|
+
var MAX_DUPLICATE_HITS = 10;
|
|
23819
|
+
function registerCreateTask(server, ctx) {
|
|
23820
|
+
server.registerTool(
|
|
23821
|
+
"create_task",
|
|
23822
|
+
{
|
|
23823
|
+
title: "\u5728\u8BA1\u5212\u4E0B\u521B\u5EFA\u4EFB\u52A1",
|
|
23824
|
+
description: "\u5728\u6307\u5B9A\u8BA1\u5212\u4E0B\u521B\u5EFA\u4EFB\u52A1\u3002\u5FC5\u586B plan\uFF08\u8BA1\u5212\u540D\u79F0\u6216 32 \u4F4D id\uFF09\u3001taskType\uFF08\u4EFB\u52A1\u7C7B\u578B\u540D\u79F0\u6216 id\uFF0C\u5982 \u4EFB\u52A1/\u9700\u6C42/\u7F3A\u9677\uFF09\u3001title\u3001dueDate\uFF08yyyy/MM/dd \u6216 yyyy-MM-dd\uFF09\u3002\u9ED8\u8BA4\u8D1F\u8D23\u4EBA\u4E3A\u5F53\u524D API Key \u5458\u5DE5\u3001\u5F00\u59CB\u65E5\u671F\u4E3A\u4ECA\u5929\u3001\u4F18\u5148\u7EA7\u666E\u901A\u3001\u72B6\u6001\u4E3A\u5DE5\u4F5C\u6D41\u8D77\u59CB\u8282\u70B9\u3001\u5168\u5929\u4EFB\u52A1\u3002\u53EF\u9009\u6B63\u6587\u3001\u53C2\u4E0E\u4EBA\u3001\u6284\u9001\u4EBA\u3001\u4F18\u5148\u7EA7\u3001\u8BA1\u5212\u5185\u6807\u7B7E\u3001\u7236\u4EFB\u52A1\u3001\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u548C template\u3002\u5FC5\u987B\u5148\u4E0D\u5E26 confirm \u8C03\u7528\u62FF previewToken\uFF0C\u628A\u9884\u6F14\u5C55\u793A\u7ED9\u7528\u6237\u5E76\u53D6\u5F97\u660E\u786E\u540C\u610F\u540E\uFF0C\u518D\u5E26 previewToken \u548C confirm=true \u6267\u884C\u3002\u53EA\u652F\u6301\u8BA1\u5212\u4EFB\u52A1\u3002",
|
|
23825
|
+
inputSchema: {
|
|
23826
|
+
plan: external_exports.string().describe("\u8BA1\u5212\u540D\u79F0\u6216 32 \u4F4D\u8BA1\u5212 id"),
|
|
23827
|
+
taskType: external_exports.string().describe("\u4EFB\u52A1\u7C7B\u578B\u540D\u79F0\u6216 id\uFF0C\u5982 \u4EFB\u52A1\u3001\u9700\u6C42\u3001\u7F3A\u9677"),
|
|
23828
|
+
title: external_exports.string().describe("\u4EFB\u52A1\u6807\u9898"),
|
|
23829
|
+
dueDate: external_exports.string().describe("\u622A\u6B62\u65E5\u671F\uFF0Cyyyy/MM/dd \u6216 yyyy-MM-dd"),
|
|
23830
|
+
content: external_exports.string().optional().describe("\u6B63\u6587\uFF08\u7EAF\u6587\u672C/Markdown\uFF0C\u4F1A\u8F6C\u6210\u7B80\u5355 HTML\uFF09"),
|
|
23831
|
+
participants: external_exports.array(external_exports.string()).optional().describe("\u53C2\u4E0E\u4EBA\u59D3\u540D\u6216 empId \u6570\u7EC4"),
|
|
23832
|
+
cc: external_exports.array(external_exports.string()).optional().describe("\u6284\u9001\u4EBA\u59D3\u540D\u6216 empId \u6570\u7EC4"),
|
|
23833
|
+
priority: external_exports.string().optional().describe("\u4F18\u5148\u7EA7\uFF1A\u975E\u5E38\u7D27\u6025/\u7D27\u6025/\u666E\u901A/\u8F83\u4F4E\uFF0C\u6216 3-VH/2-H/1-M/0-L\uFF1B\u9ED8\u8BA4\u666E\u901A"),
|
|
23834
|
+
tags: external_exports.array(external_exports.string()).optional().describe("\u8BA1\u5212\u5185\u6807\u7B7E\u540D\u6216 id \u6570\u7EC4"),
|
|
23835
|
+
group: external_exports.string().optional().describe("\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u540D\u79F0\u6216 id\uFF1B\u521B\u5EFA\u540E\u76F4\u63A5\u52A0\u5165\u8BE5\u5206\u7EC4"),
|
|
23836
|
+
parentTaskId: external_exports.string().optional().describe("\u7236\u4EFB\u52A1 taskId\uFF1B\u4E0E parentUrl \u4E8C\u9009\u4E00"),
|
|
23837
|
+
parentUrl: external_exports.string().optional().describe("\u7236\u4EFB\u52A1\u94FE\u63A5\uFF1B\u4E0E parentTaskId \u4E8C\u9009\u4E00"),
|
|
23838
|
+
template: external_exports.string().optional().describe("\u6807\u51C6\u884C\u52A8\u8BA1\u5212 id\uFF1B\u901A\u5E38\u81EA\u52A8\u9009\u62E9\uFF0C\u89E3\u6790\u5931\u8D25\u65F6\u518D\u7528\u5B83\u6307\u5B9A"),
|
|
23839
|
+
confirm: external_exports.boolean().optional().describe("true \u624D\u771F\u6B63\u521B\u5EFA\uFF1B\u7F3A\u7701\u53EA\u9884\u6F14"),
|
|
23840
|
+
previewToken: external_exports.string().optional().describe("\u9884\u6F14\u8FD4\u56DE\u7684\u4EE4\u724C\uFF1Bconfirm=true \u65F6\u5FC5\u586B")
|
|
23841
|
+
},
|
|
23842
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
|
|
23843
|
+
},
|
|
23844
|
+
async (args) => {
|
|
23845
|
+
try {
|
|
23846
|
+
return await handleCreate(ctx, args);
|
|
23847
|
+
} catch (error2) {
|
|
23848
|
+
return fail(error2);
|
|
23849
|
+
}
|
|
23850
|
+
}
|
|
23851
|
+
);
|
|
23852
|
+
}
|
|
23853
|
+
async function handleCreate(ctx, args) {
|
|
23854
|
+
const title = args.title.trim();
|
|
23855
|
+
if (!title) {
|
|
23856
|
+
throw new EworkError("\u4EFB\u52A1\u6807\u9898\u4E0D\u80FD\u4E3A\u7A7A");
|
|
23857
|
+
}
|
|
23858
|
+
const planResolution = await resolvePlan(ctx, args.plan);
|
|
23859
|
+
if (!planResolution.ok) {
|
|
23860
|
+
throw new EworkError(formatPlanFailure(planResolution));
|
|
23861
|
+
}
|
|
23862
|
+
const plan = planResolution.plan;
|
|
23863
|
+
if (plan.isArchive) {
|
|
23864
|
+
throw new EworkError(`\u8BA1\u5212\u300C${plan.title}\u300D\u5DF2\u5F52\u6863\uFF0C\u4E0D\u80FD\u5728\u5F52\u6863\u8BA1\u5212\u4E0B\u521B\u5EFA\u4EFB\u52A1`);
|
|
23865
|
+
}
|
|
23866
|
+
if (!plan.isMember) {
|
|
23867
|
+
throw new EworkError(
|
|
23868
|
+
`\u5F53\u524D\u5458\u5DE5\u4E0D\u662F\u8BA1\u5212\u300C${plan.title}\u300D\u7684\u6210\u5458\uFF0C\u4E0D\u80FD\u5728\u8BE5\u8BA1\u5212\u4E0B\u521B\u5EFA\u4EFB\u52A1\uFF1B\u8BF7\u8BA9\u8BA1\u5212\u7BA1\u7406\u5458\u6DFB\u52A0\u6210\u5458`
|
|
23869
|
+
);
|
|
23870
|
+
}
|
|
23871
|
+
const employee = await loadCurrentEmployee(ctx);
|
|
23872
|
+
const categories = await loadCategories(ctx, plan.id);
|
|
23873
|
+
const category = resolveCategory(categories, args.taskType);
|
|
23874
|
+
if (!category.id) {
|
|
23875
|
+
throw new EworkError(`\u4EFB\u52A1\u7C7B\u578B\u300C${category.name}\u300D\u7F3A\u5C11 id\uFF0C\u65E0\u6CD5\u521B\u5EFA`);
|
|
23876
|
+
}
|
|
23877
|
+
const requiredFields = (category.configFieldList ?? []).filter((field) => field.required === "Y" && field.isDel !== "Y").map((field) => String(field.name ?? "").trim()).filter(Boolean);
|
|
23878
|
+
if (requiredFields.length) {
|
|
23879
|
+
throw new EworkError(
|
|
23880
|
+
`\u4EFB\u52A1\u7C7B\u578B\u300C${category.name}\u300D\u6709\u5FC5\u586B\u81EA\u5B9A\u4E49\u5B57\u6BB5\uFF1A${requiredFields.join("\u3001")}\u3002MCP \u6682\u4E0D\u652F\u6301\u586B\u5199\u81EA\u5B9A\u4E49\u5B57\u6BB5\uFF0C\u8BF7\u5728\u7F51\u9875\u521B\u5EFA`
|
|
23881
|
+
);
|
|
23882
|
+
}
|
|
23883
|
+
const startStatus = (category.flowItemList ?? []).find(
|
|
23884
|
+
(item) => item.type === "S" && item.id
|
|
23885
|
+
);
|
|
23886
|
+
if (!startStatus?.id) {
|
|
23887
|
+
throw new EworkError(`\u4EFB\u52A1\u7C7B\u578B\u300C${category.name}\u300D\u6CA1\u6709\u8D77\u59CB\u72B6\u6001\u8282\u70B9\uFF0C\u65E0\u6CD5\u521B\u5EFA`);
|
|
23888
|
+
}
|
|
23889
|
+
const templates = await loadTemplates(ctx, employee.id);
|
|
23890
|
+
const templateResolution = selectTemplate(
|
|
23891
|
+
templates,
|
|
23892
|
+
plan.businessCode,
|
|
23893
|
+
args.template
|
|
23894
|
+
);
|
|
23895
|
+
if (!templateResolution.ok) {
|
|
23896
|
+
throw new EworkError(
|
|
23897
|
+
`${templateResolution.message}
|
|
23898
|
+
\u53EF\u7528\u6A21\u677F\uFF1A
|
|
23899
|
+
${formatTemplates(templateResolution.candidates)}`
|
|
23900
|
+
);
|
|
23901
|
+
}
|
|
23902
|
+
const template = templateResolution.template;
|
|
23903
|
+
if (!template.id) {
|
|
23904
|
+
throw new EworkError("\u6807\u51C6\u884C\u52A8\u8BA1\u5212 id \u4E3A\u7A7A\uFF0C\u65E0\u6CD5\u521B\u5EFA");
|
|
23905
|
+
}
|
|
23906
|
+
const priority = normalizePriority(args.priority);
|
|
23907
|
+
const startDate = todayDateString();
|
|
23908
|
+
const dueDate = normalizeDateInput(args.dueDate, "\u622A\u6B62\u65E5\u671F");
|
|
23909
|
+
if (dueDate < startDate) {
|
|
23910
|
+
throw new EworkError(`\u622A\u6B62\u65E5\u671F ${dueDate} \u65E9\u4E8E\u5F00\u59CB\u65E5\u671F ${startDate}\uFF0C\u8BF7\u8C03\u6574`);
|
|
23911
|
+
}
|
|
23912
|
+
const ownerMember = { emp: employee, role: "O" };
|
|
23913
|
+
const participantMembers = await resolveMembers(
|
|
23914
|
+
ctx,
|
|
23915
|
+
args.participants ?? [],
|
|
23916
|
+
"P"
|
|
23917
|
+
);
|
|
23918
|
+
const ccMembers = await resolveMembers(ctx, args.cc ?? [], "C");
|
|
23919
|
+
const members = dedupeMembers(
|
|
23920
|
+
toMemberInputs([ownerMember, ...participantMembers, ...ccMembers])
|
|
23921
|
+
);
|
|
23922
|
+
const nameByEmpId = buildNameMap2([ownerMember, ...participantMembers, ...ccMembers]);
|
|
23923
|
+
const memberViews = members.map((member) => ({
|
|
23924
|
+
empId: member.empId,
|
|
23925
|
+
name: nameByEmpId.get(member.empId) || member.empId,
|
|
23926
|
+
role: member.role,
|
|
23927
|
+
roleLabel: memberRoleLabel(member.role)
|
|
23928
|
+
}));
|
|
23929
|
+
const planTags = await loadPlanTags(ctx, plan.id);
|
|
23930
|
+
const selectedTags = resolveTags(args.tags ?? [], planTags);
|
|
23931
|
+
let group;
|
|
23932
|
+
if (args.group?.trim() && !isNoGroupTarget(args.group)) {
|
|
23933
|
+
const groupResolution = await resolveTaskGroup(ctx, args.group);
|
|
23934
|
+
if (!groupResolution.ok) {
|
|
23935
|
+
throw new EworkError(formatGroupFailure(groupResolution));
|
|
23936
|
+
}
|
|
23937
|
+
if (!String(groupResolution.group.id ?? "").trim()) {
|
|
23938
|
+
throw new EworkError(
|
|
23939
|
+
`\u5206\u7EC4\u300C${String(groupResolution.group.groupName ?? args.group)}\u300D\u7F3A\u5C11\u5206\u7EC4 id\uFF0C\u65E0\u6CD5\u5165\u7EC4`
|
|
23940
|
+
);
|
|
23941
|
+
}
|
|
23942
|
+
group = groupResolution.group;
|
|
23943
|
+
}
|
|
23944
|
+
let parent;
|
|
23945
|
+
if (args.parentTaskId || args.parentUrl) {
|
|
23946
|
+
parent = await resolveParent(ctx, args.parentTaskId, args.parentUrl, plan);
|
|
23947
|
+
}
|
|
23948
|
+
const duplicate = await findDuplicateTitles(ctx, plan.id, title);
|
|
23949
|
+
const detailsHtml = args.content !== void 0 ? textToHtml(args.content) : void 0;
|
|
23950
|
+
const payload = buildAddTaskPayload({
|
|
23951
|
+
template: template.id,
|
|
23952
|
+
planId: plan.id,
|
|
23953
|
+
planTaskCategoryId: String(category.id ?? ""),
|
|
23954
|
+
title,
|
|
23955
|
+
detailsHtml,
|
|
23956
|
+
status: String(startStatus.id),
|
|
23957
|
+
priority,
|
|
23958
|
+
startTime: startDate,
|
|
23959
|
+
endTime: dueDate,
|
|
23960
|
+
father: parent?.taskId,
|
|
23961
|
+
projectId: plan.projectId,
|
|
23962
|
+
subProjectId: plan.subProjectId,
|
|
23963
|
+
groupId: group ? String(group.id ?? "") : void 0,
|
|
23964
|
+
members,
|
|
23965
|
+
tagIds: selectedTags.map((tag) => String(tag.id))
|
|
23966
|
+
});
|
|
23967
|
+
const preview = {
|
|
23968
|
+
plan: { id: plan.id, title: plan.title, business: plan.business },
|
|
23969
|
+
category: { id: String(category.id ?? ""), name: String(category.name ?? "") },
|
|
23970
|
+
template: {
|
|
23971
|
+
id: String(template.id),
|
|
23972
|
+
title: String(template.title ?? ""),
|
|
23973
|
+
automatic: templateResolution.automatic
|
|
23974
|
+
},
|
|
23975
|
+
title,
|
|
23976
|
+
contentText: detailsHtml ? htmlToText(detailsHtml).slice(0, 500) : "",
|
|
23977
|
+
dates: { start: startDate, end: dueDate, fullDay: true },
|
|
23978
|
+
priority: { code: priority, label: PRIORITY_LABELS[priority] ?? priority },
|
|
23979
|
+
members: memberViews,
|
|
23980
|
+
tags: selectedTags.map((tag) => ({
|
|
23981
|
+
id: String(tag.id),
|
|
23982
|
+
name: String(tag.name ?? "")
|
|
23983
|
+
})),
|
|
23984
|
+
parent,
|
|
23985
|
+
group: group ? {
|
|
23986
|
+
id: String(group.id ?? ""),
|
|
23987
|
+
name: String(group.groupName ?? "")
|
|
23988
|
+
} : void 0,
|
|
23989
|
+
project: plan.projectId || plan.subProjectId ? { projectId: plan.projectId, subProjectId: plan.subProjectId } : void 0,
|
|
23990
|
+
duplicateTaskIds: duplicate.taskIds,
|
|
23991
|
+
duplicateNote: duplicate.note
|
|
23992
|
+
};
|
|
23993
|
+
if (!args.confirm) {
|
|
23994
|
+
const previewToken = createPreviewToken("create_task", plan.id, payload);
|
|
23995
|
+
return ok(formatPreview4(preview, previewToken), {
|
|
23996
|
+
...preview,
|
|
23997
|
+
planMatchedBy: planResolution.matchedBy,
|
|
23998
|
+
previewToken,
|
|
23999
|
+
expiresInSeconds: previewTtlSeconds(),
|
|
24000
|
+
payload
|
|
24001
|
+
});
|
|
24002
|
+
}
|
|
24003
|
+
consumePreviewToken(args.previewToken, "create_task", plan.id, payload);
|
|
24004
|
+
const taskId = String(
|
|
24005
|
+
await ctx.client.post("/external/home/task/addTask", payload) ?? ""
|
|
24006
|
+
).trim();
|
|
24007
|
+
if (!taskId) {
|
|
24008
|
+
throw new EworkError("\u521B\u5EFA\u63A5\u53E3\u6CA1\u6709\u8FD4\u56DE taskId\uFF0C\u8BF7\u5230\u7F51\u9875\u786E\u8BA4\u4EFB\u52A1\u662F\u5426\u5DF2\u521B\u5EFA");
|
|
24009
|
+
}
|
|
24010
|
+
const url = `${ctx.baseUrl.replace(/\/$/, "")}/workPlan/plan?taskId=${taskId}`;
|
|
24011
|
+
const expected = {
|
|
24012
|
+
title,
|
|
24013
|
+
planId: plan.id,
|
|
24014
|
+
categoryId: String(category.id ?? ""),
|
|
24015
|
+
statusId: String(startStatus.id),
|
|
24016
|
+
startTime: startDate,
|
|
24017
|
+
endTime: dueDate,
|
|
24018
|
+
ownerId: employee.id,
|
|
24019
|
+
participantIds: members.filter((member) => member.role === "P").map((m) => m.empId),
|
|
24020
|
+
ccIds: members.filter((member) => member.role === "C").map((m) => m.empId),
|
|
24021
|
+
tagIds: selectedTags.map((tag) => String(tag.id)),
|
|
24022
|
+
father: parent?.taskId,
|
|
24023
|
+
projectId: plan.projectId,
|
|
24024
|
+
subProjectId: plan.subProjectId
|
|
24025
|
+
};
|
|
24026
|
+
try {
|
|
24027
|
+
const after = await loadDetail(ctx, taskId);
|
|
24028
|
+
const verification = verifyCreatedTask(after, expected);
|
|
24029
|
+
if (group) {
|
|
24030
|
+
const groupId = String(group.id ?? "");
|
|
24031
|
+
const inGroup = groupId ? await isTaskInGroup(ctx, taskId, groupId) : false;
|
|
24032
|
+
if (!inGroup) {
|
|
24033
|
+
verification.mismatches.push("\u5206\u7EC4");
|
|
24034
|
+
verification.verified = false;
|
|
24035
|
+
}
|
|
24036
|
+
}
|
|
24037
|
+
return ok(
|
|
24038
|
+
[
|
|
24039
|
+
`\u5DF2\u521B\u5EFA\u4EFB\u52A1 ${taskId}\uFF08${title}\uFF09\u3002`,
|
|
24040
|
+
`\u8BA1\u5212\uFF1A${plan.title}\uFF1B\u4EFB\u52A1\u7C7B\u578B\uFF1A${category.name}\uFF1B\u72B6\u6001\uFF1A${startStatus.name || startStatus.id}\uFF1B\u8D1F\u8D23\u4EBA\uFF1A${describeEmployee(employee)}\u3002`,
|
|
24041
|
+
group ? `\u5206\u7EC4\uFF1A${String(group.groupName ?? "")}\uFF08${String(group.id ?? "")}\uFF09\u3002` : "\u5206\u7EC4\uFF1A\u672A\u5206\u7EC4\u3002",
|
|
24042
|
+
verification.verified ? "\u56DE\u8BFB\u786E\u8BA4\u6210\u529F\u3002" : `\u5199\u5165\u5DF2\u63D0\u4EA4\uFF0C\u4F46\u56DE\u8BFB\u672A\u786E\u8BA4\uFF08${verification.mismatches.join("\u3001")}\uFF09\uFF0C\u8BF7\u624B\u52A8\u68C0\u67E5\u3002`,
|
|
24043
|
+
`\u94FE\u63A5\uFF1A${url}`
|
|
24044
|
+
].join("\n"),
|
|
24045
|
+
{
|
|
24046
|
+
...preview,
|
|
24047
|
+
created: true,
|
|
24048
|
+
taskId,
|
|
24049
|
+
url,
|
|
24050
|
+
verified: verification.verified,
|
|
24051
|
+
mismatches: verification.mismatches
|
|
24052
|
+
}
|
|
24053
|
+
);
|
|
24054
|
+
} catch (error2) {
|
|
24055
|
+
return ok(
|
|
24056
|
+
[
|
|
24057
|
+
`\u4EFB\u52A1\u5DF2\u63D0\u4EA4\u521B\u5EFA\uFF0C\u4F46\u56DE\u8BFB\u5931\u8D25\uFF1A${error2 instanceof Error ? error2.message : String(error2)}`,
|
|
24058
|
+
`taskId\uFF1A${taskId}`,
|
|
24059
|
+
`\u94FE\u63A5\uFF1A${url}`,
|
|
24060
|
+
"\u8BF7\u5230\u7F51\u9875\u786E\u8BA4\u4EFB\u52A1\u662F\u5426\u5DF2\u521B\u5EFA\u3002"
|
|
24061
|
+
].join("\n"),
|
|
24062
|
+
{ ...preview, created: true, taskId, url, verified: false }
|
|
24063
|
+
);
|
|
24064
|
+
}
|
|
24065
|
+
}
|
|
24066
|
+
async function loadCurrentEmployee(ctx) {
|
|
24067
|
+
const info = await ctx.client.get("/external/base/plt/userInfo");
|
|
24068
|
+
const id = String(info?.base?.id ?? "").trim();
|
|
24069
|
+
if (!id) {
|
|
24070
|
+
throw new EworkError("\u65E0\u6CD5\u83B7\u53D6\u5F53\u524D\u5458\u5DE5\u4FE1\u606F\uFF1B\u8BF7\u786E\u8BA4 API Key \u7ED1\u5B9A\u5458\u5DE5\u6709\u6548");
|
|
24071
|
+
}
|
|
24072
|
+
return { id, name: String(info?.base?.name ?? "") };
|
|
24073
|
+
}
|
|
24074
|
+
async function loadCategories(ctx, planId) {
|
|
24075
|
+
const list = await ctx.client.get(
|
|
24076
|
+
"/external/home/task/plan/query/loadTaskCategoryListByPlanId",
|
|
24077
|
+
{ planId }
|
|
24078
|
+
) ?? [];
|
|
24079
|
+
return list;
|
|
24080
|
+
}
|
|
24081
|
+
async function loadPlanTags(ctx, planId) {
|
|
24082
|
+
const list = await ctx.client.get(
|
|
24083
|
+
"/external/home/task/plan/query/loadTaskTagListByPlanId",
|
|
24084
|
+
{ planId }
|
|
24085
|
+
) ?? [];
|
|
24086
|
+
return list;
|
|
24087
|
+
}
|
|
24088
|
+
async function loadTemplates(ctx, empId) {
|
|
24089
|
+
const list = await ctx.client.get(
|
|
24090
|
+
"/external/home/task/query/loadTplsByEmpId",
|
|
24091
|
+
{ empId }
|
|
24092
|
+
) ?? [];
|
|
24093
|
+
return list;
|
|
24094
|
+
}
|
|
24095
|
+
function resolveCategory(categories, input) {
|
|
24096
|
+
const value = input.trim();
|
|
24097
|
+
if (!value) {
|
|
24098
|
+
throw new EworkError("\u8BF7\u63D0\u4F9B\u4EFB\u52A1\u7C7B\u578B\u540D\u79F0\u6216 id");
|
|
24099
|
+
}
|
|
24100
|
+
const byId = categories.filter((category) => String(category.id ?? "") === value);
|
|
24101
|
+
const byName = categories.filter(
|
|
24102
|
+
(category) => String(category.name ?? "").trim() === value
|
|
24103
|
+
);
|
|
24104
|
+
const matched = byId.length ? byId : byName;
|
|
24105
|
+
if (matched.length === 1) {
|
|
24106
|
+
return matched[0];
|
|
24107
|
+
}
|
|
24108
|
+
if (matched.length > 1) {
|
|
24109
|
+
throw new EworkError(
|
|
24110
|
+
`\u4EFB\u52A1\u7C7B\u578B\u300C${value}\u300D\u6709 ${matched.length} \u4E2A\u540C\u540D\u9879\uFF0C\u8BF7\u7528\u4EFB\u52A1\u7C7B\u578B id \u6307\u5B9A\u3002
|
|
24111
|
+
${formatCategories(matched)}`
|
|
24112
|
+
);
|
|
24113
|
+
}
|
|
24114
|
+
throw new EworkError(
|
|
24115
|
+
`\u6CA1\u6709\u627E\u5230\u4EFB\u52A1\u7C7B\u578B\u300C${value}\u300D\u3002\u8BE5\u8BA1\u5212\u7684\u53EF\u7528\u7C7B\u578B\uFF1A
|
|
24116
|
+
${categories.length ? formatCategories(categories) : "\u65E0"}`
|
|
24117
|
+
);
|
|
24118
|
+
}
|
|
24119
|
+
async function resolveMembers(ctx, inputs, role) {
|
|
24120
|
+
const members = [];
|
|
24121
|
+
for (const input of inputs) {
|
|
24122
|
+
const value = input.trim();
|
|
24123
|
+
if (!value) {
|
|
24124
|
+
continue;
|
|
24125
|
+
}
|
|
24126
|
+
members.push({ emp: await resolveEmployeeOrThrow(ctx, value), role });
|
|
24127
|
+
}
|
|
24128
|
+
return members;
|
|
24129
|
+
}
|
|
24130
|
+
function toMemberInputs(members) {
|
|
24131
|
+
return members.map((member) => ({
|
|
24132
|
+
empId: String(member.emp.id ?? "").trim(),
|
|
24133
|
+
role: member.role
|
|
24134
|
+
})).filter((member) => member.empId);
|
|
24135
|
+
}
|
|
24136
|
+
function buildNameMap2(members) {
|
|
24137
|
+
const map = /* @__PURE__ */ new Map();
|
|
24138
|
+
for (const member of members) {
|
|
24139
|
+
const empId = String(member.emp.id ?? "").trim();
|
|
24140
|
+
if (empId) {
|
|
24141
|
+
map.set(empId, member.emp.name || empId);
|
|
24142
|
+
}
|
|
24143
|
+
}
|
|
24144
|
+
return map;
|
|
24145
|
+
}
|
|
24146
|
+
function resolveTags(inputs, available) {
|
|
24147
|
+
const selected = [];
|
|
24148
|
+
const problems = [];
|
|
24149
|
+
for (const input of inputs) {
|
|
24150
|
+
const value = input.trim();
|
|
24151
|
+
if (!value) {
|
|
24152
|
+
continue;
|
|
24153
|
+
}
|
|
24154
|
+
const byId = available.filter((tag) => String(tag.id ?? "") === value);
|
|
24155
|
+
const matched = byId.length ? byId : available.filter((tag) => String(tag.name ?? "") === value);
|
|
24156
|
+
if (matched.length === 1) {
|
|
24157
|
+
const tagId = String(matched[0].id ?? "");
|
|
24158
|
+
if (!selected.some((tag) => String(tag.id ?? "") === tagId)) {
|
|
24159
|
+
selected.push(matched[0]);
|
|
24160
|
+
}
|
|
24161
|
+
} else if (matched.length === 0) {
|
|
24162
|
+
problems.push(`\u6807\u7B7E\u300C${value}\u300D\u4E0D\u5728\u8BE5\u8BA1\u5212\u4E0B`);
|
|
24163
|
+
} else {
|
|
24164
|
+
problems.push(`\u6807\u7B7E\u300C${value}\u300D\u6709 ${matched.length} \u4E2A\u540C\u540D\u9879\uFF0C\u8BF7\u7528\u6807\u7B7E id \u6307\u5B9A`);
|
|
24165
|
+
}
|
|
24166
|
+
}
|
|
24167
|
+
if (problems.length) {
|
|
24168
|
+
throw new EworkError(
|
|
24169
|
+
`${problems.join("\uFF1B")}\u3002\u8BE5\u8BA1\u5212\u53EF\u7528\u6807\u7B7E\uFF1A
|
|
24170
|
+
${available.length ? formatTags(available) : "\u65E0"}`
|
|
24171
|
+
);
|
|
24172
|
+
}
|
|
24173
|
+
return selected;
|
|
24174
|
+
}
|
|
24175
|
+
async function resolveParent(ctx, parentTaskId, parentUrl, plan) {
|
|
24176
|
+
const taskId = resolveTaskInput(ctx, parentTaskId, parentUrl);
|
|
24177
|
+
const detail = await loadDetail(ctx, taskId);
|
|
24178
|
+
const parentPlanId = String(detail.task?.planId ?? "");
|
|
24179
|
+
if (parentPlanId !== plan.id) {
|
|
24180
|
+
throw new EworkError(
|
|
24181
|
+
`\u7236\u4EFB\u52A1 ${taskId} \u5C5E\u4E8E\u5176\u4ED6\u8BA1\u5212\uFF08${parentPlanId || "\u65E0\u8BA1\u5212"}\uFF09\uFF0C\u5FC5\u987B\u4E0E\u65B0\u5EFA\u4EFB\u52A1\u540C\u8BA1\u5212`
|
|
24182
|
+
);
|
|
24183
|
+
}
|
|
24184
|
+
if (String(detail.task?.isCycle ?? "N").toUpperCase() === "Y") {
|
|
24185
|
+
throw new EworkError(`\u7236\u4EFB\u52A1 ${taskId} \u662F\u5468\u671F\u4EFB\u52A1\uFF0C\u4E0D\u80FD\u4F5C\u4E3A\u7236\u4EFB\u52A1`);
|
|
24186
|
+
}
|
|
24187
|
+
return { taskId, title: String(detail.task?.title ?? "") };
|
|
24188
|
+
}
|
|
24189
|
+
async function findDuplicateTitles(ctx, planId, title) {
|
|
24190
|
+
try {
|
|
24191
|
+
const raw = await ctx.client.requestRaw(
|
|
24192
|
+
"POST",
|
|
24193
|
+
"/external/home/task/v2/query/loadByParamsInPage",
|
|
24194
|
+
{
|
|
24195
|
+
json: {
|
|
24196
|
+
empRoles: [],
|
|
24197
|
+
isTopTask: "N",
|
|
24198
|
+
containsTaskEmps: "N",
|
|
24199
|
+
containsTaskTags: "N",
|
|
24200
|
+
task: { planId, title },
|
|
24201
|
+
current: 1,
|
|
24202
|
+
size: MAX_DUPLICATE_HITS
|
|
24203
|
+
},
|
|
24204
|
+
write: false
|
|
24205
|
+
}
|
|
24206
|
+
);
|
|
24207
|
+
const taskIds = (raw.result ?? []).filter((item) => String(item.title ?? "") === title).map((item) => String(item.id ?? "")).filter(Boolean);
|
|
24208
|
+
return { taskIds };
|
|
24209
|
+
} catch {
|
|
24210
|
+
return { taskIds: [], note: "\u540C\u540D\u4EFB\u52A1\u68C0\u67E5\u5931\u8D25\uFF08\u4E0D\u5F71\u54CD\u521B\u5EFA\uFF09" };
|
|
24211
|
+
}
|
|
24212
|
+
}
|
|
24213
|
+
function verifyCreatedTask(detail, expected) {
|
|
24214
|
+
const task = detail.task ?? {};
|
|
24215
|
+
const mismatches = [];
|
|
24216
|
+
if (String(task.title ?? "") !== expected.title) mismatches.push("\u6807\u9898");
|
|
24217
|
+
if (String(task.planId ?? "") !== expected.planId) mismatches.push("\u8BA1\u5212");
|
|
24218
|
+
if (String(task.planTaskCategoryId ?? "") !== expected.categoryId) {
|
|
24219
|
+
mismatches.push("\u4EFB\u52A1\u7C7B\u578B");
|
|
24220
|
+
}
|
|
24221
|
+
if (String(task.status ?? "") !== expected.statusId) mismatches.push("\u72B6\u6001");
|
|
24222
|
+
if (!sameDate(task.startTime, expected.startTime)) mismatches.push("\u5F00\u59CB\u65E5\u671F");
|
|
24223
|
+
if (!sameDate(task.endTime, expected.endTime)) mismatches.push("\u622A\u6B62\u65E5\u671F");
|
|
24224
|
+
const owners = (detail.ownEmps ?? []).map((emp) => String(emp.empId ?? ""));
|
|
24225
|
+
if (!owners.includes(expected.ownerId)) mismatches.push("\u8D1F\u8D23\u4EBA");
|
|
24226
|
+
if (!sameIdSet(
|
|
24227
|
+
(detail.patEmps ?? []).map((emp) => String(emp.empId ?? "")),
|
|
24228
|
+
expected.participantIds
|
|
24229
|
+
)) {
|
|
24230
|
+
mismatches.push("\u53C2\u4E0E\u4EBA");
|
|
24231
|
+
}
|
|
24232
|
+
if (!sameIdSet(
|
|
24233
|
+
(detail.cpyEmps ?? []).map((emp) => String(emp.empId ?? "")),
|
|
24234
|
+
expected.ccIds
|
|
24235
|
+
)) {
|
|
24236
|
+
mismatches.push("\u6284\u9001\u4EBA");
|
|
24237
|
+
}
|
|
24238
|
+
if (expected.tagIds.length) {
|
|
24239
|
+
const actualTagIds = (detail.tagClassifyList ?? []).map(
|
|
24240
|
+
(tag) => String(tag.id ?? "")
|
|
24241
|
+
);
|
|
24242
|
+
if (!expected.tagIds.every((id) => actualTagIds.includes(id))) {
|
|
24243
|
+
mismatches.push("\u6807\u7B7E");
|
|
24244
|
+
}
|
|
24245
|
+
}
|
|
24246
|
+
if (expected.father && String(task.father ?? "") !== expected.father) {
|
|
24247
|
+
mismatches.push("\u7236\u4EFB\u52A1");
|
|
24248
|
+
}
|
|
24249
|
+
if (expected.projectId && String(detail.projectId ?? "") !== expected.projectId) {
|
|
24250
|
+
mismatches.push("\u9879\u76EE");
|
|
24251
|
+
}
|
|
24252
|
+
if (expected.subProjectId && String(detail.subProjectId ?? "") !== expected.subProjectId) {
|
|
24253
|
+
mismatches.push("\u5B50\u9879\u76EE");
|
|
24254
|
+
}
|
|
24255
|
+
return { verified: mismatches.length === 0, mismatches };
|
|
24256
|
+
}
|
|
24257
|
+
function sameDate(actual, expected) {
|
|
24258
|
+
const text = String(actual ?? "").slice(0, 10).replace(/-/g, "/");
|
|
24259
|
+
return text === expected;
|
|
24260
|
+
}
|
|
24261
|
+
function sameIdSet(actual, expected) {
|
|
24262
|
+
if (actual.length !== expected.length) {
|
|
24263
|
+
return false;
|
|
24264
|
+
}
|
|
24265
|
+
const set = new Set(actual);
|
|
24266
|
+
return expected.every((id) => set.has(id));
|
|
24267
|
+
}
|
|
24268
|
+
function formatPreview4(preview, previewToken) {
|
|
24269
|
+
const lines = [
|
|
24270
|
+
`\u5728\u8BA1\u5212\u300C${preview.plan.title}\u300D\uFF08${preview.plan.id}\uFF09\u521B\u5EFA\u4EFB\u52A1\u9884\u6F14\uFF08\u672A\u5199\u5165\uFF09\uFF1A`,
|
|
24271
|
+
`\u6807\u9898\uFF1A${preview.title}`,
|
|
24272
|
+
`\u4EFB\u52A1\u7C7B\u578B\uFF1A${preview.category.name}\uFF08${preview.category.id}\uFF09`,
|
|
24273
|
+
`\u6807\u51C6\u884C\u52A8\u8BA1\u5212\uFF1A${preview.template.title}\uFF08${preview.template.id}\uFF0C${preview.template.automatic ? "\u81EA\u52A8\u9009\u62E9" : "\u7528\u6237\u6307\u5B9A"}\uFF09`,
|
|
24274
|
+
`\u65E5\u671F\uFF1A${preview.dates.start} ~ ${preview.dates.end}\uFF08\u5168\u5929\uFF09`,
|
|
24275
|
+
`\u4F18\u5148\u7EA7\uFF1A${preview.priority.label}\uFF08${preview.priority.code}\uFF09`,
|
|
24276
|
+
`\u6210\u5458\uFF1A${formatMembers(preview.members)}`
|
|
24277
|
+
];
|
|
24278
|
+
if (preview.contentText) {
|
|
24279
|
+
lines.push(`\u6B63\u6587\u9884\u89C8\uFF1A${preview.contentText}`);
|
|
24280
|
+
}
|
|
24281
|
+
lines.push(`\u6807\u7B7E\uFF1A${preview.tags.map((tag) => tag.name).join("\u3001") || "\u65E0"}`);
|
|
24282
|
+
lines.push(
|
|
24283
|
+
`\u5206\u7EC4\uFF1A${preview.group ? `${preview.group.name}\uFF08${preview.group.id}\uFF09` : "\u672A\u5206\u7EC4"}`
|
|
24284
|
+
);
|
|
24285
|
+
lines.push(`\u7236\u4EFB\u52A1\uFF1A${preview.parent ? `${preview.parent.title}\uFF08${preview.parent.taskId}\uFF09` : "\u65E0"}`);
|
|
24286
|
+
if (preview.project) {
|
|
24287
|
+
const project = preview.project.projectId ? `\u9879\u76EE ${preview.project.projectId}` : `\u5B50\u9879\u76EE ${preview.project.subProjectId}`;
|
|
24288
|
+
lines.push(`\u5F52\u5C5E\uFF1A${project}`);
|
|
24289
|
+
}
|
|
24290
|
+
if (preview.duplicateTaskIds.length) {
|
|
24291
|
+
lines.push(
|
|
24292
|
+
`\u540C\u540D\u4EFB\u52A1\u63D0\u793A\uFF1A\u540C\u8BA1\u5212\u4E0B\u5DF2\u6709 ${preview.duplicateTaskIds.length} \u6761\u540C\u540D\u4EFB\u52A1\uFF08${preview.duplicateTaskIds.join("\u3001")}\uFF09\uFF0C\u4EC5\u63D0\u793A\uFF0C\u4E0D\u963B\u65AD`
|
|
24293
|
+
);
|
|
24294
|
+
} else if (preview.duplicateNote) {
|
|
24295
|
+
lines.push(preview.duplicateNote);
|
|
24296
|
+
}
|
|
24297
|
+
lines.push(`previewToken\uFF1A${previewToken}`);
|
|
24298
|
+
lines.push(
|
|
23128
24299
|
"\u8BF7\u5148\u628A\u4EE5\u4E0A\u6539\u52A8\u5C55\u793A\u7ED9\u7528\u6237\uFF0C\u5F97\u5230\u660E\u786E\u540C\u610F\u540E\uFF0C\u518D\u5E26 previewToken \u4E0E confirm=true \u8C03\u7528\u3002"
|
|
23129
|
-
|
|
24300
|
+
);
|
|
24301
|
+
return lines.join("\n");
|
|
24302
|
+
}
|
|
24303
|
+
function formatMembers(members) {
|
|
24304
|
+
if (!members.length) {
|
|
24305
|
+
return "\u65E0";
|
|
24306
|
+
}
|
|
24307
|
+
return members.map((member) => `${member.roleLabel} ${member.name}\uFF08${member.empId}\uFF09`).join("\uFF1B");
|
|
24308
|
+
}
|
|
24309
|
+
function formatCategories(categories) {
|
|
24310
|
+
return categories.map((category) => `- ${category.name || "-"}\uFF08${category.id || "-"}\uFF09`).join("\n");
|
|
24311
|
+
}
|
|
24312
|
+
function formatTags(tags) {
|
|
24313
|
+
return tags.map((tag) => `- ${tag.name || "-"}\uFF08${tag.id || "-"}\uFF09`).join("\n");
|
|
24314
|
+
}
|
|
24315
|
+
function formatTemplates(templates) {
|
|
24316
|
+
return templates.map((template) => `- ${templateLabel(template)}`).join("\n");
|
|
23130
24317
|
}
|
|
23131
24318
|
|
|
23132
24319
|
// src/tools/getTask.ts
|
|
@@ -23166,9 +24353,9 @@ function registerGetTask(server, ctx) {
|
|
|
23166
24353
|
// src/tools/query.ts
|
|
23167
24354
|
var SCAN_PAGE_SIZE = 100;
|
|
23168
24355
|
var MAX_SCAN_ITEMS = 2e3;
|
|
23169
|
-
function
|
|
24356
|
+
function buildTaskQuery(options) {
|
|
23170
24357
|
const query = {
|
|
23171
|
-
empRoles: [
|
|
24358
|
+
empRoles: [...options.empRoles],
|
|
23172
24359
|
isTopTask: "N",
|
|
23173
24360
|
containsTaskEmps: "Y",
|
|
23174
24361
|
containsTaskTags: "Y",
|
|
@@ -23178,12 +24365,25 @@ function buildOwnerQuery(options) {
|
|
|
23178
24365
|
if (options.statusType) {
|
|
23179
24366
|
query.statusTypeList = [options.statusType];
|
|
23180
24367
|
}
|
|
24368
|
+
if (options.groupId) {
|
|
24369
|
+
query.groupId = options.groupId;
|
|
24370
|
+
}
|
|
24371
|
+
if (options.isNotInGroup) {
|
|
24372
|
+
query.isNotInGroup = "Y";
|
|
24373
|
+
}
|
|
24374
|
+
const task = {};
|
|
24375
|
+
if (options.planId) {
|
|
24376
|
+
task.planId = options.planId;
|
|
24377
|
+
}
|
|
23181
24378
|
if (options.keyword?.trim()) {
|
|
23182
|
-
|
|
24379
|
+
task.title = options.keyword.trim();
|
|
24380
|
+
}
|
|
24381
|
+
if (Object.keys(task).length) {
|
|
24382
|
+
query.task = task;
|
|
23183
24383
|
}
|
|
23184
24384
|
return query;
|
|
23185
24385
|
}
|
|
23186
|
-
async function
|
|
24386
|
+
async function fetchTaskPage(ctx, base, page, size) {
|
|
23187
24387
|
const raw = await ctx.client.requestRaw(
|
|
23188
24388
|
"POST",
|
|
23189
24389
|
"/external/home/task/v2/query/loadByParamsInPage",
|
|
@@ -23191,14 +24391,14 @@ async function fetchOwnerPage(ctx, base, page, size) {
|
|
|
23191
24391
|
);
|
|
23192
24392
|
return { items: raw.result ?? [], total: Number(raw.total ?? 0) };
|
|
23193
24393
|
}
|
|
23194
|
-
async function
|
|
24394
|
+
async function scanTasks(ctx, base, predicate) {
|
|
23195
24395
|
const matched = [];
|
|
23196
24396
|
const statusNames = /* @__PURE__ */ new Set();
|
|
23197
24397
|
const tagNames = /* @__PURE__ */ new Set();
|
|
23198
24398
|
let scanned = 0;
|
|
23199
24399
|
let total = 0;
|
|
23200
24400
|
for (let page = 1; page <= MAX_SCAN_ITEMS / SCAN_PAGE_SIZE; page += 1) {
|
|
23201
|
-
const result = await
|
|
24401
|
+
const result = await fetchTaskPage(ctx, base, page, SCAN_PAGE_SIZE);
|
|
23202
24402
|
total = result.total;
|
|
23203
24403
|
scanned += result.items.length;
|
|
23204
24404
|
for (const item of result.items) {
|
|
@@ -23260,18 +24460,20 @@ function assertScanComplete(result, hint) {
|
|
|
23260
24460
|
}
|
|
23261
24461
|
}
|
|
23262
24462
|
|
|
23263
|
-
// src/tools/
|
|
23264
|
-
function
|
|
24463
|
+
// src/tools/taskList.ts
|
|
24464
|
+
function registerTaskList(server, ctx, definition) {
|
|
23265
24465
|
server.registerTool(
|
|
23266
|
-
|
|
24466
|
+
definition.name,
|
|
23267
24467
|
{
|
|
23268
|
-
title:
|
|
23269
|
-
description:
|
|
24468
|
+
title: definition.title,
|
|
24469
|
+
description: definition.description,
|
|
23270
24470
|
inputSchema: {
|
|
23271
24471
|
statusName: external_exports.string().optional().describe("\u72B6\u6001\u4E2D\u6587\u540D\uFF0C\u5982 \u672A\u5F00\u59CB\u3001\u5F85\u5904\u7406\u3001\u5F85\u53D1\u5E03\u3001\u5DF2\u89E3\u51B3\uFF1B\u4E0D\u8981\u4F20 S/P/F/E"),
|
|
23272
24472
|
statusType: external_exports.enum(["S", "P", "F", "E"]).optional().describe("\u72B6\u6001\u7C7B\u578B"),
|
|
23273
24473
|
keyword: external_exports.string().optional().describe("\u6807\u9898\u5173\u952E\u8BCD"),
|
|
23274
24474
|
tag: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional().describe("\u6807\u7B7E\u540D\u6216\u6807\u7B7E id\uFF1B\u6570\u7EC4\u8868\u793A\u540C\u65F6\u5177\u5907"),
|
|
24475
|
+
plan: external_exports.string().optional().describe("\u8BA1\u5212\u540D\u79F0\u6216 32 \u4F4D\u8BA1\u5212 id\uFF1B\u540D\u79F0\u91CD\u540D\u65F6\u8FD4\u56DE\u5019\u9009"),
|
|
24476
|
+
group: external_exports.string().optional().describe("\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u540D\u79F0\u6216 id\uFF1B\u4F20\u300C\u672A\u5206\u7EC4\u300D\u8868\u793A\u53EA\u770B\u672A\u5206\u7EC4\u4EFB\u52A1"),
|
|
23275
24477
|
page: external_exports.number().int().optional().describe("\u9875\u7801\uFF0C\u9ED8\u8BA4 1\uFF1B\u5C0F\u4E8E 1 \u6309 1 \u5904\u7406"),
|
|
23276
24478
|
size: external_exports.number().int().optional().describe("\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 20\uFF1B\u5927\u4E8E 100 \u6309 100 \u5904\u7406")
|
|
23277
24479
|
},
|
|
@@ -23279,14 +24481,14 @@ function registerListMyTasks(server, ctx) {
|
|
|
23279
24481
|
},
|
|
23280
24482
|
async (args) => {
|
|
23281
24483
|
try {
|
|
23282
|
-
return await handleList(ctx, args);
|
|
24484
|
+
return await handleList(ctx, args, definition);
|
|
23283
24485
|
} catch (error2) {
|
|
23284
24486
|
return fail(error2);
|
|
23285
24487
|
}
|
|
23286
24488
|
}
|
|
23287
24489
|
);
|
|
23288
24490
|
}
|
|
23289
|
-
async function handleList(ctx, args) {
|
|
24491
|
+
async function handleList(ctx, args, definition) {
|
|
23290
24492
|
const notes = [];
|
|
23291
24493
|
const page = normalizePage(args.page);
|
|
23292
24494
|
const size = normalizeSize(args.size);
|
|
@@ -23301,26 +24503,90 @@ async function handleList(ctx, args) {
|
|
|
23301
24503
|
`\u300C${args.statusName}\u300D\u662F\u72B6\u6001\u7C7B\u578B\uFF0C\u4E0D\u662F\u72B6\u6001\u540D\u3002\u6309\u7C7B\u578B\u7B5B\u9009\u8BF7\u7528 statusType\uFF0C\u6309\u540D\u79F0\u8BF7\u7528\u4E2D\u6587\u72B6\u6001\u540D\uFF08\u5982 \u672A\u5F00\u59CB\u3001\u5F85\u5904\u7406\u3001\u5DF2\u53D1\u5E03\u3001\u5DF2\u5B8C\u6210\uFF09`
|
|
23302
24504
|
);
|
|
23303
24505
|
}
|
|
24506
|
+
let plan;
|
|
24507
|
+
let matchedBy;
|
|
24508
|
+
if (args.plan?.trim()) {
|
|
24509
|
+
const resolution = await resolvePlan(ctx, args.plan);
|
|
24510
|
+
if (!resolution.ok) {
|
|
24511
|
+
return ok(formatPlanFailure(resolution), {
|
|
24512
|
+
items: [],
|
|
24513
|
+
total: 0,
|
|
24514
|
+
page,
|
|
24515
|
+
size,
|
|
24516
|
+
filtered: true,
|
|
24517
|
+
empRole: definition.empRoles[0],
|
|
24518
|
+
planResolutionFailed: true,
|
|
24519
|
+
planCandidates: resolution.candidates,
|
|
24520
|
+
availablePlans: resolution.available ?? [],
|
|
24521
|
+
...notes.length ? { notes } : {}
|
|
24522
|
+
});
|
|
24523
|
+
}
|
|
24524
|
+
plan = resolution.plan;
|
|
24525
|
+
matchedBy = resolution.matchedBy;
|
|
24526
|
+
}
|
|
24527
|
+
let group;
|
|
24528
|
+
let ungrouped = false;
|
|
24529
|
+
let groupMatchedBy;
|
|
24530
|
+
if (args.group?.trim()) {
|
|
24531
|
+
if (isNoGroupTarget(args.group)) {
|
|
24532
|
+
ungrouped = true;
|
|
24533
|
+
groupMatchedBy = "none";
|
|
24534
|
+
} else {
|
|
24535
|
+
const resolution = await resolveTaskGroup(ctx, args.group);
|
|
24536
|
+
if (!resolution.ok) {
|
|
24537
|
+
return ok(formatGroupFailure(resolution), {
|
|
24538
|
+
items: [],
|
|
24539
|
+
total: 0,
|
|
24540
|
+
page,
|
|
24541
|
+
size,
|
|
24542
|
+
filtered: true,
|
|
24543
|
+
empRole: definition.empRoles[0],
|
|
24544
|
+
groupResolutionFailed: true,
|
|
24545
|
+
groupCandidates: resolution.candidates,
|
|
24546
|
+
availableGroups: resolution.available ?? [],
|
|
24547
|
+
...notes.length ? { notes } : {}
|
|
24548
|
+
});
|
|
24549
|
+
}
|
|
24550
|
+
group = resolution.group;
|
|
24551
|
+
groupMatchedBy = String(group.id ?? "") === args.group.trim() ? "id" : "name";
|
|
24552
|
+
}
|
|
24553
|
+
}
|
|
23304
24554
|
const tags = normalizeTags(args.tag);
|
|
23305
24555
|
const needsClientFilter = Boolean(args.statusName) || tags.length > 0;
|
|
23306
|
-
const base =
|
|
24556
|
+
const base = buildTaskQuery({
|
|
24557
|
+
empRoles: definition.empRoles,
|
|
24558
|
+
planId: plan?.id,
|
|
24559
|
+
groupId: group?.id,
|
|
24560
|
+
isNotInGroup: ungrouped,
|
|
24561
|
+
statusType: args.statusType,
|
|
24562
|
+
keyword: args.keyword
|
|
24563
|
+
});
|
|
23307
24564
|
const start = (page - 1) * size;
|
|
23308
24565
|
if (!needsClientFilter) {
|
|
23309
|
-
const result = await
|
|
24566
|
+
const result = await fetchTaskPage(ctx, base, page, size);
|
|
23310
24567
|
if (result.total > 0 && start >= result.total) {
|
|
23311
24568
|
return pageOutOfRange(result.total, page, size, notes);
|
|
23312
24569
|
}
|
|
23313
24570
|
const items2 = result.items.map(summarizeListItem);
|
|
23314
|
-
return ok(
|
|
23315
|
-
|
|
23316
|
-
|
|
23317
|
-
|
|
23318
|
-
|
|
23319
|
-
|
|
23320
|
-
|
|
23321
|
-
|
|
24571
|
+
return ok(
|
|
24572
|
+
formatListText(items2, result.total, page, size, notes, definition.roleLabel, {
|
|
24573
|
+
planTitle: plan?.title,
|
|
24574
|
+
groupTitle: groupTitleValue(group, ungrouped)
|
|
24575
|
+
}),
|
|
24576
|
+
{
|
|
24577
|
+
items: items2,
|
|
24578
|
+
total: result.total,
|
|
24579
|
+
page,
|
|
24580
|
+
size,
|
|
24581
|
+
filtered: false,
|
|
24582
|
+
empRole: definition.empRoles[0],
|
|
24583
|
+
...planOutput(plan, matchedBy),
|
|
24584
|
+
...groupOutput(group, ungrouped, groupMatchedBy),
|
|
24585
|
+
...notes.length ? { notes } : {}
|
|
24586
|
+
}
|
|
24587
|
+
);
|
|
23322
24588
|
}
|
|
23323
|
-
const scanned = await
|
|
24589
|
+
const scanned = await scanTasks(ctx, base, (item) => {
|
|
23324
24590
|
if (args.statusName && item.statusValue !== args.statusName) {
|
|
23325
24591
|
return false;
|
|
23326
24592
|
}
|
|
@@ -23336,6 +24602,14 @@ async function handleList(ctx, args) {
|
|
|
23336
24602
|
}
|
|
23337
24603
|
if (total === 0) {
|
|
23338
24604
|
const hints = [];
|
|
24605
|
+
if (plan) {
|
|
24606
|
+
hints.push(`\u8BA1\u5212\u300C${plan.title}\u300D\u4E0B\u6CA1\u6709\u5339\u914D\u7684\u4EFB\u52A1\u3002`);
|
|
24607
|
+
}
|
|
24608
|
+
if (group || ungrouped) {
|
|
24609
|
+
hints.push(
|
|
24610
|
+
`\u5206\u7EC4\u300C${groupTitleValue(group, ungrouped)}\u300D\u4E0B\u6CA1\u6709\u5339\u914D\u7684\u4EFB\u52A1\u3002`
|
|
24611
|
+
);
|
|
24612
|
+
}
|
|
23339
24613
|
if (args.statusName) {
|
|
23340
24614
|
hints.push(
|
|
23341
24615
|
`\u6CA1\u6709\u72B6\u6001\u4E3A\u300C${args.statusName}\u300D\u7684\u4EFB\u52A1\u3002\u4F60\u7684\u4EFB\u52A1\u5B9E\u9645\u72B6\u6001\u6709\uFF1A${scanned.statusNames.join("\u3001") || "\u65E0"}`
|
|
@@ -23353,16 +24627,21 @@ async function handleList(ctx, args) {
|
|
|
23353
24627
|
page,
|
|
23354
24628
|
size,
|
|
23355
24629
|
filtered: true,
|
|
24630
|
+
empRole: definition.empRoles[0],
|
|
23356
24631
|
scanned: scanned.scanned,
|
|
23357
24632
|
availableStatusNames: scanned.statusNames,
|
|
23358
|
-
availableTagNames: scanned.tagNames
|
|
24633
|
+
availableTagNames: scanned.tagNames,
|
|
24634
|
+
...planOutput(plan, matchedBy),
|
|
24635
|
+
...groupOutput(group, ungrouped, groupMatchedBy)
|
|
23359
24636
|
});
|
|
23360
24637
|
}
|
|
23361
24638
|
const items = scanned.matched.slice(start, start + size).map(summarizeListItem);
|
|
23362
24639
|
return ok(
|
|
23363
|
-
formatListText(items, total, page, size, notes, {
|
|
24640
|
+
formatListText(items, total, page, size, notes, definition.roleLabel, {
|
|
23364
24641
|
statusName: args.statusName,
|
|
23365
|
-
tags
|
|
24642
|
+
tags,
|
|
24643
|
+
planTitle: plan?.title,
|
|
24644
|
+
groupTitle: groupTitleValue(group, ungrouped)
|
|
23366
24645
|
}),
|
|
23367
24646
|
{
|
|
23368
24647
|
items,
|
|
@@ -23370,11 +24649,47 @@ async function handleList(ctx, args) {
|
|
|
23370
24649
|
page,
|
|
23371
24650
|
size,
|
|
23372
24651
|
filtered: true,
|
|
24652
|
+
empRole: definition.empRoles[0],
|
|
23373
24653
|
scanned: scanned.scanned,
|
|
24654
|
+
...planOutput(plan, matchedBy),
|
|
24655
|
+
...groupOutput(group, ungrouped, groupMatchedBy),
|
|
23374
24656
|
...notes.length ? { notes } : {}
|
|
23375
24657
|
}
|
|
23376
24658
|
);
|
|
23377
24659
|
}
|
|
24660
|
+
function groupOutput(group, ungrouped, matchedBy) {
|
|
24661
|
+
if (ungrouped) {
|
|
24662
|
+
return {
|
|
24663
|
+
groupName: "\u672A\u5206\u7EC4",
|
|
24664
|
+
ungrouped: true,
|
|
24665
|
+
groupMatchedBy: matchedBy
|
|
24666
|
+
};
|
|
24667
|
+
}
|
|
24668
|
+
if (!group) {
|
|
24669
|
+
return {};
|
|
24670
|
+
}
|
|
24671
|
+
return {
|
|
24672
|
+
groupId: String(group.id ?? ""),
|
|
24673
|
+
groupName: String(group.groupName ?? ""),
|
|
24674
|
+
groupMatchedBy: matchedBy
|
|
24675
|
+
};
|
|
24676
|
+
}
|
|
24677
|
+
function groupTitleValue(group, ungrouped) {
|
|
24678
|
+
if (ungrouped) {
|
|
24679
|
+
return "\u672A\u5206\u7EC4";
|
|
24680
|
+
}
|
|
24681
|
+
return group ? String(group.groupName ?? "").trim() || void 0 : void 0;
|
|
24682
|
+
}
|
|
24683
|
+
function planOutput(plan, matchedBy) {
|
|
24684
|
+
if (!plan) {
|
|
24685
|
+
return {};
|
|
24686
|
+
}
|
|
24687
|
+
return {
|
|
24688
|
+
planId: plan.id,
|
|
24689
|
+
planTitle: plan.title,
|
|
24690
|
+
planMatchedBy: matchedBy
|
|
24691
|
+
};
|
|
24692
|
+
}
|
|
23378
24693
|
function normalizePage(value) {
|
|
23379
24694
|
return value !== void 0 && Number.isInteger(value) && value >= 1 ? value : 1;
|
|
23380
24695
|
}
|
|
@@ -23396,14 +24711,25 @@ function pageOutOfRange(total, page, size, notes) {
|
|
|
23396
24711
|
}
|
|
23397
24712
|
);
|
|
23398
24713
|
}
|
|
23399
|
-
function formatListText(items, total, page, size, notes, filter) {
|
|
23400
|
-
const headerParts = [
|
|
24714
|
+
function formatListText(items, total, page, size, notes, roleLabel2, filter) {
|
|
24715
|
+
const headerParts = [
|
|
24716
|
+
`\u5171 ${total} \u6761`,
|
|
24717
|
+
`\u7B2C ${page} \u9875`,
|
|
24718
|
+
`\u6BCF\u9875 ${size} \u6761`,
|
|
24719
|
+
`\u89C6\u89D2=${roleLabel2}`
|
|
24720
|
+
];
|
|
23401
24721
|
if (filter?.statusName) {
|
|
23402
24722
|
headerParts.push(`\u72B6\u6001=${filter.statusName}`);
|
|
23403
24723
|
}
|
|
23404
24724
|
if (filter?.tags?.length) {
|
|
23405
24725
|
headerParts.push(`\u6807\u7B7E=${filter.tags.join("+")}`);
|
|
23406
24726
|
}
|
|
24727
|
+
if (filter?.planTitle) {
|
|
24728
|
+
headerParts.push(`\u8BA1\u5212=${filter.planTitle}`);
|
|
24729
|
+
}
|
|
24730
|
+
if (filter?.groupTitle) {
|
|
24731
|
+
headerParts.push(`\u5206\u7EC4=${filter.groupTitle}`);
|
|
24732
|
+
}
|
|
23407
24733
|
const lines = [...notes];
|
|
23408
24734
|
if (!items.length) {
|
|
23409
24735
|
lines.push(`${headerParts.join("\uFF0C")}`, "\u6CA1\u6709\u5339\u914D\u7684\u4EFB\u52A1\u3002");
|
|
@@ -23418,23 +24744,60 @@ function formatListText(items, total, page, size, notes, filter) {
|
|
|
23418
24744
|
return lines.join("\n");
|
|
23419
24745
|
}
|
|
23420
24746
|
|
|
24747
|
+
// src/tools/listCreatedTasks.ts
|
|
24748
|
+
function registerListCreatedTasks(server, ctx) {
|
|
24749
|
+
registerTaskList(server, ctx, {
|
|
24750
|
+
name: "list_created_tasks",
|
|
24751
|
+
title: "\u67E5\u8BE2\u6211\u521B\u5EFA\u7684\u4EFB\u52A1",
|
|
24752
|
+
description: "\u67E5\u8BE2\u521B\u5EFA\u4EBA\uFF08\u4EFB\u52A1\u6210\u5458\u89D2\u8272 R\uFF09\u662F\u5F53\u524D API Key \u7ED1\u5B9A\u5458\u5DE5\u7684\u4EFB\u52A1\uFF0C\u4E0D\u662F\u8D1F\u8D23\u4EBA\u89C6\u89D2\u3002\u652F\u6301\u6309\u72B6\u6001\u540D\u79F0\u3001\u72B6\u6001\u7C7B\u578B\u3001\u5173\u952E\u8BCD\u3001\u6807\u7B7E\u3001\u8BA1\u5212\u3001\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u548C\u5206\u9875\u7B5B\u9009\u3002\u72B6\u6001\u540D\u79F0\u6309\u4EFB\u52A1\u5B9E\u9645\u72B6\u6001\u7CBE\u786E\u5339\u914D\uFF1BS/P/F/E \u662F\u72B6\u6001\u7C7B\u578B\uFF0C\u4E0D\u662F\u72B6\u6001\u540D\u3002\u6807\u7B7E\u6309\u540D\u79F0\u6216 id \u7CBE\u786E\u5339\u914D\uFF0C\u6570\u7EC4\u8868\u793A\u540C\u65F6\u5177\u5907\u3002\u8BA1\u5212\u53EF\u4F20\u540D\u79F0\u6216 32 \u4F4D id\uFF1B\u5206\u7EC4\u53EF\u4F20\u540D\u79F0\u6216 id\uFF0C\u4F20\u300C\u672A\u5206\u7EC4\u300D\u8868\u793A\u53EA\u770B\u672A\u5206\u7EC4\u4EFB\u52A1\uFF1B\u540D\u79F0\u91CD\u540D\u65F6\u8FD4\u56DE\u5019\u9009\uFF0C\u4E0D\u8FD4\u56DE\u4EFB\u52A1\u3002",
|
|
24753
|
+
empRoles: ["R"],
|
|
24754
|
+
roleLabel: "\u521B\u5EFA\u4EBA"
|
|
24755
|
+
});
|
|
24756
|
+
}
|
|
24757
|
+
|
|
24758
|
+
// src/tools/listMyTasks.ts
|
|
24759
|
+
function registerListMyTasks(server, ctx) {
|
|
24760
|
+
registerTaskList(server, ctx, {
|
|
24761
|
+
name: "list_my_tasks",
|
|
24762
|
+
title: "\u67E5\u8BE2\u6211\u8D1F\u8D23\u7684\u4EFB\u52A1",
|
|
24763
|
+
description: "\u67E5\u8BE2\u8D1F\u8D23\u4EBA\uFF08\u89D2\u8272 O\uFF09\u662F\u5F53\u524D API Key \u7ED1\u5B9A\u5458\u5DE5\u7684\u4EFB\u52A1\uFF0C\u4E0D\u542B\u53C2\u4E0E\u4EBA/\u6284\u9001\u4EBA\u89C6\u89D2\u3002\u652F\u6301\u6309\u72B6\u6001\u540D\u79F0\u3001\u72B6\u6001\u7C7B\u578B\u3001\u5173\u952E\u8BCD\u3001\u6807\u7B7E\u3001\u8BA1\u5212\u3001\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u548C\u5206\u9875\u7B5B\u9009\u3002\u72B6\u6001\u540D\u79F0\u6309\u4EFB\u52A1\u5B9E\u9645\u72B6\u6001\u7CBE\u786E\u5339\u914D\uFF1BS/P/F/E \u662F\u72B6\u6001\u7C7B\u578B\uFF0C\u4E0D\u662F\u72B6\u6001\u540D\u3002\u6807\u7B7E\u6309\u540D\u79F0\u6216 id \u7CBE\u786E\u5339\u914D\uFF0C\u6570\u7EC4\u8868\u793A\u540C\u65F6\u5177\u5907\u3002\u8BA1\u5212\u53EF\u4F20\u540D\u79F0\u6216 32 \u4F4D id\uFF1B\u5206\u7EC4\u53EF\u4F20\u540D\u79F0\u6216 id\uFF0C\u4F20\u300C\u672A\u5206\u7EC4\u300D\u8868\u793A\u53EA\u770B\u672A\u5206\u7EC4\u4EFB\u52A1\uFF1B\u540D\u79F0\u91CD\u540D\u65F6\u8FD4\u56DE\u5019\u9009\uFF0C\u4E0D\u8FD4\u56DE\u4EFB\u52A1\u3002",
|
|
24764
|
+
empRoles: ["O"],
|
|
24765
|
+
roleLabel: "\u8D1F\u8D23\u4EBA"
|
|
24766
|
+
});
|
|
24767
|
+
}
|
|
24768
|
+
|
|
23421
24769
|
// src/tools/myTaskStats.ts
|
|
23422
24770
|
function registerMyTaskStats(server, ctx) {
|
|
23423
24771
|
server.registerTool(
|
|
23424
24772
|
"my_task_stats",
|
|
23425
24773
|
{
|
|
23426
24774
|
title: "\u7EDF\u8BA1\u6211\u8D1F\u8D23\u7684\u4EFB\u52A1",
|
|
23427
|
-
description: "\u7EDF\u8BA1\u8D1F\u8D23\u4EBA\uFF08\u89D2\u8272 O\uFF09\u662F\u5F53\u524D API Key \u7ED1\u5B9A\u5458\u5DE5\u7684\u4EFB\u52A1\u6570\u91CF\uFF0C\u4E0D\u542B\u53C2\u4E0E\u4EBA/\u6284\u9001\u4EBA\u89C6\u89D2\u3002\u8FD4\u56DE\u6309\u72B6\u6001\u540D\u79F0\u548C\u6309\u72B6\u6001\u7C7B\u578B\uFF08S/P/F/E\uFF09\u4E24\u5C42\u6C47\u603B\uFF0C\u53EF\u9009\u6309\u6807\u7B7E\u8FC7\u6EE4\uFF1B\u6807\u7B7E\u6309\u540D\u79F0\u6216 id \u7CBE\u786E\u5339\u914D\u3002",
|
|
24775
|
+
description: "\u7EDF\u8BA1\u8D1F\u8D23\u4EBA\uFF08\u89D2\u8272 O\uFF09\u662F\u5F53\u524D API Key \u7ED1\u5B9A\u5458\u5DE5\u7684\u4EFB\u52A1\u6570\u91CF\uFF0C\u4E0D\u542B\u53C2\u4E0E\u4EBA/\u6284\u9001\u4EBA\u89C6\u89D2\u3002\u8FD4\u56DE\u6309\u72B6\u6001\u540D\u79F0\u548C\u6309\u72B6\u6001\u7C7B\u578B\uFF08S/P/F/E\uFF09\u4E24\u5C42\u6C47\u603B\uFF0C\u53EF\u9009\u6309\u6807\u7B7E\u3001\u8BA1\u5212\u8FC7\u6EE4\uFF1B\u6807\u7B7E\u6309\u540D\u79F0\u6216 id \u7CBE\u786E\u5339\u914D\uFF0C\u8BA1\u5212\u53EF\u4F20\u540D\u79F0\u6216 32 \u4F4D id\u3002\u8BA1\u5212\u540D\u91CD\u540D\u65F6\u8FD4\u56DE\u5019\u9009\uFF0C\u4E0D\u8FD4\u56DE\u7EDF\u8BA1\u6570\u5B57\u3002",
|
|
23428
24776
|
inputSchema: {
|
|
23429
|
-
tag: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional().describe("\u6807\u7B7E\u540D\u6216\u6807\u7B7E id\uFF1B\u6570\u7EC4\u8868\u793A\u540C\u65F6\u5177\u5907")
|
|
24777
|
+
tag: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional().describe("\u6807\u7B7E\u540D\u6216\u6807\u7B7E id\uFF1B\u6570\u7EC4\u8868\u793A\u540C\u65F6\u5177\u5907"),
|
|
24778
|
+
plan: external_exports.string().optional().describe("\u8BA1\u5212\u540D\u79F0\u6216 32 \u4F4D\u8BA1\u5212 id\uFF1B\u540D\u79F0\u91CD\u540D\u65F6\u8FD4\u56DE\u5019\u9009")
|
|
23430
24779
|
},
|
|
23431
24780
|
annotations: { readOnlyHint: true }
|
|
23432
24781
|
},
|
|
23433
24782
|
async (args) => {
|
|
23434
24783
|
try {
|
|
24784
|
+
let plan;
|
|
24785
|
+
let matchedBy;
|
|
24786
|
+
if (args.plan?.trim()) {
|
|
24787
|
+
const resolution = await resolvePlan(ctx, args.plan);
|
|
24788
|
+
if (!resolution.ok) {
|
|
24789
|
+
return ok(formatPlanFailure(resolution), {
|
|
24790
|
+
planResolutionFailed: true,
|
|
24791
|
+
planCandidates: resolution.candidates,
|
|
24792
|
+
availablePlans: resolution.available ?? []
|
|
24793
|
+
});
|
|
24794
|
+
}
|
|
24795
|
+
plan = resolution.plan;
|
|
24796
|
+
matchedBy = resolution.matchedBy;
|
|
24797
|
+
}
|
|
23435
24798
|
const tags = normalizeTags(args.tag);
|
|
23436
|
-
const base =
|
|
23437
|
-
const scanned = await
|
|
24799
|
+
const base = buildTaskQuery({ empRoles: ["O"], planId: plan?.id });
|
|
24800
|
+
const scanned = await scanTasks(ctx, base, (item) => matchesTags(item, tags));
|
|
23438
24801
|
const byNameMap = /* @__PURE__ */ new Map();
|
|
23439
24802
|
const byType = { S: 0, P: 0, F: 0, E: 0 };
|
|
23440
24803
|
for (const item of scanned.matched) {
|
|
@@ -23465,20 +24828,22 @@ function registerMyTaskStats(server, ctx) {
|
|
|
23465
24828
|
scanned: scanned.scanned,
|
|
23466
24829
|
partial: scanned.partial,
|
|
23467
24830
|
tag: tags,
|
|
23468
|
-
availableTagNames: scanned.tagNames
|
|
24831
|
+
availableTagNames: scanned.tagNames,
|
|
24832
|
+
empRole: "O",
|
|
24833
|
+
...plan ? { planId: plan.id, planTitle: plan.title, planMatchedBy: matchedBy } : {}
|
|
23469
24834
|
};
|
|
23470
24835
|
const hint = total === 0 && tags.length ? `
|
|
23471
24836
|
\u6CA1\u6709\u6807\u7B7E\u4E3A\u300C${tags.join("+")}\u300D\u7684\u4EFB\u52A1\u3002\u626B\u63CF\u5230\u7684\u6807\u7B7E\u6709\uFF1A${scanned.tagNames.join("\u3001") || "\u65E0"}` : "";
|
|
23472
|
-
return ok(`${formatStatsText(structured)}${hint}`, structured);
|
|
24837
|
+
return ok(`${formatStatsText(structured, plan?.title)}${hint}`, structured);
|
|
23473
24838
|
} catch (error2) {
|
|
23474
24839
|
return fail(error2);
|
|
23475
24840
|
}
|
|
23476
24841
|
}
|
|
23477
24842
|
);
|
|
23478
24843
|
}
|
|
23479
|
-
function formatStatsText(stats) {
|
|
24844
|
+
function formatStatsText(stats, planTitle) {
|
|
23480
24845
|
const lines = [
|
|
23481
|
-
`\u6211\u7684\u4EFB\u52A1\u5171 ${stats.total} \u6761${stats.tag.length ? `\uFF08\u6807\u7B7E ${stats.tag.join("+")}\uFF09` : ""}\uFF0C\u626B\u63CF ${stats.scanned} \u6761`
|
|
24846
|
+
`${planTitle ? `\u8BA1\u5212\u300C${planTitle}\u300D\u5185` : ""}\u6211\u8D1F\u8D23\u7684\u4EFB\u52A1\u5171 ${stats.total} \u6761${stats.tag.length ? `\uFF08\u6807\u7B7E ${stats.tag.join("+")}\uFF09` : ""}\uFF0C\u626B\u63CF ${stats.scanned} \u6761`
|
|
23482
24847
|
];
|
|
23483
24848
|
lines.push(
|
|
23484
24849
|
`\u6309\u72B6\u6001\uFF1A${stats.byName.length ? stats.byName.map((item) => `${item.name}(${item.type || "-"}) ${item.count}`).join("\uFF1B") : "\u65E0"}`
|
|
@@ -23537,6 +24902,275 @@ function registerSearchEmployee(server, ctx) {
|
|
|
23537
24902
|
);
|
|
23538
24903
|
}
|
|
23539
24904
|
|
|
24905
|
+
// src/tools/taskGroups.ts
|
|
24906
|
+
function registerTaskGroups(server, ctx) {
|
|
24907
|
+
registerListTaskGroups(server, ctx);
|
|
24908
|
+
registerManageTaskGroup(server, ctx);
|
|
24909
|
+
}
|
|
24910
|
+
function registerListTaskGroups(server, ctx) {
|
|
24911
|
+
server.registerTool(
|
|
24912
|
+
"list_task_groups",
|
|
24913
|
+
{
|
|
24914
|
+
title: "\u67E5\u8BE2\u6211\u7684\u4EFB\u52A1\u5206\u7EC4",
|
|
24915
|
+
description: "\u5217\u51FA\u5F53\u524D API Key \u5458\u5DE5\u7684\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\uFF08\u300C\u6211\u7684\u4EFB\u52A1\u300D\u9875\u7684\u81EA\u5B9A\u4E49\u5206\u7EC4\uFF09\uFF0C\u8FD4\u56DE\u540D\u79F0\u3001id\u3001\u6392\u5E8F\u548C\u521B\u5EFA\u65F6\u95F4\u3002withCounts=true \u65F6\u9010\u7EC4\u8FD4\u56DE\u5F53\u524D\u5458\u5DE5\u53EF\u89C1\u7684\u4EFB\u52A1\u6570\uFF08\u4E0D\u9650\u89D2\u8272\uFF09\uFF1B\u5206\u7EC4\u8D85\u8FC7 30 \u4E2A\u65F6\u4E0D\u7EDF\u8BA1\u4EFB\u52A1\u6570\u3002\u4E0D\u542B\u8BA1\u5212\u5171\u4EAB\u5206\u7EC4\u3002",
|
|
24916
|
+
inputSchema: {
|
|
24917
|
+
withCounts: external_exports.boolean().optional().describe("true \u65F6\u8FD4\u56DE\u6BCF\u4E2A\u5206\u7EC4\u7684\u4EFB\u52A1\u6570\uFF1B\u9ED8\u8BA4 false\uFF0C\u53EA\u5217\u5206\u7EC4")
|
|
24918
|
+
},
|
|
24919
|
+
annotations: { readOnlyHint: true }
|
|
24920
|
+
},
|
|
24921
|
+
async (args) => {
|
|
24922
|
+
try {
|
|
24923
|
+
const groups = await loadPersonalGroups(ctx);
|
|
24924
|
+
if (!groups.length) {
|
|
24925
|
+
return ok("\u5F53\u524D\u5458\u5DE5\u8FD8\u6CA1\u6709\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\uFF1B\u53EF\u7528 manage_task_group \u521B\u5EFA\u3002", {
|
|
24926
|
+
total: 0,
|
|
24927
|
+
groups: [],
|
|
24928
|
+
countsOmitted: false
|
|
24929
|
+
});
|
|
24930
|
+
}
|
|
24931
|
+
const countsOmitted = Boolean(
|
|
24932
|
+
args.withCounts && groups.length > MAX_GROUPS_FOR_COUNTS
|
|
24933
|
+
);
|
|
24934
|
+
const items = [];
|
|
24935
|
+
for (const group of groups) {
|
|
24936
|
+
const id = String(group.id ?? "");
|
|
24937
|
+
const name = String(group.groupName ?? "");
|
|
24938
|
+
const taskCount = args.withCounts && !countsOmitted && id ? await groupTaskCount(ctx, id) : void 0;
|
|
24939
|
+
items.push({
|
|
24940
|
+
groupId: id,
|
|
24941
|
+
name,
|
|
24942
|
+
seq: group.seq,
|
|
24943
|
+
createTime: group.createTime,
|
|
24944
|
+
...taskCount === void 0 ? {} : { taskCount }
|
|
24945
|
+
});
|
|
24946
|
+
}
|
|
24947
|
+
const lines = [`\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u5171 ${items.length} \u4E2A`];
|
|
24948
|
+
if (countsOmitted) {
|
|
24949
|
+
lines.push(
|
|
24950
|
+
`\u5206\u7EC4\u8D85\u8FC7 ${MAX_GROUPS_FOR_COUNTS} \u4E2A\uFF0C\u672C\u6B21\u4E0D\u7EDF\u8BA1\u4EFB\u52A1\u6570\uFF1B\u53EF\u4F20 withCounts=false \u5148\u770B\u5206\u7EC4\u3002`
|
|
24951
|
+
);
|
|
24952
|
+
}
|
|
24953
|
+
for (const item of items) {
|
|
24954
|
+
const count = item.taskCount === void 0 ? "" : ` \u4EFB\u52A1 ${item.taskCount} \u6761`;
|
|
24955
|
+
lines.push(
|
|
24956
|
+
`- ${item.name || "\uFF08\u65E0\u540D\u79F0\uFF09"}\uFF08${item.groupId}\uFF09 \u6392\u5E8F=${item.seq ?? "-"}${count}`
|
|
24957
|
+
);
|
|
24958
|
+
}
|
|
24959
|
+
return ok(lines.join("\n"), {
|
|
24960
|
+
total: items.length,
|
|
24961
|
+
groups: items,
|
|
24962
|
+
countsOmitted
|
|
24963
|
+
});
|
|
24964
|
+
} catch (error2) {
|
|
24965
|
+
return fail(error2);
|
|
24966
|
+
}
|
|
24967
|
+
}
|
|
24968
|
+
);
|
|
24969
|
+
}
|
|
24970
|
+
function registerManageTaskGroup(server, ctx) {
|
|
24971
|
+
server.registerTool(
|
|
24972
|
+
"manage_task_group",
|
|
24973
|
+
{
|
|
24974
|
+
title: "\u7BA1\u7406\u6211\u7684\u4EFB\u52A1\u5206\u7EC4",
|
|
24975
|
+
description: "\u7BA1\u7406\u5F53\u524D API Key \u5458\u5DE5\u7684\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\uFF1Aaction=create \u521B\u5EFA\uFF08name \u5FC5\u586B\uFF09\uFF1Baction=rename \u91CD\u547D\u540D\uFF08group + newName\uFF09\uFF1Baction=delete \u5220\u9664\uFF08group\uFF09\u3002\u5220\u9664\u524D\u4F1A\u68C0\u67E5\u5206\u7EC4\u662F\u5426\u4E3A\u7A7A\uFF0C\u975E\u7A7A\u62D2\u7EDD\u3002\u6240\u6709\u5199\u64CD\u4F5C\u5FC5\u987B\u5148\u4E0D\u5E26 confirm \u8C03\u7528\u62FF previewToken\uFF0C\u628A\u9884\u6F14\u5C55\u793A\u7ED9\u7528\u6237\u5E76\u53D6\u5F97\u660E\u786E\u540C\u610F\u540E\uFF0C\u518D\u5E26 previewToken \u548C confirm=true \u6267\u884C\u3002",
|
|
24976
|
+
inputSchema: {
|
|
24977
|
+
action: external_exports.enum(["create", "rename", "delete"]).describe("\u64CD\u4F5C\u7C7B\u578B"),
|
|
24978
|
+
name: external_exports.string().optional().describe("create\uFF1A\u65B0\u5206\u7EC4\u540D\u79F0\uFF0C1\u201330 \u5B57\u7B26"),
|
|
24979
|
+
group: external_exports.string().optional().describe("rename/delete\uFF1A\u5206\u7EC4\u540D\u79F0\u6216\u5206\u7EC4 id"),
|
|
24980
|
+
newName: external_exports.string().optional().describe("rename\uFF1A\u65B0\u5206\u7EC4\u540D\u79F0\uFF0C1\u201330 \u5B57\u7B26"),
|
|
24981
|
+
confirm: external_exports.boolean().optional().describe("true \u624D\u771F\u6B63\u5199\u5165\uFF1B\u7F3A\u7701\u53EA\u9884\u6F14"),
|
|
24982
|
+
previewToken: external_exports.string().optional().describe("\u9884\u6F14\u8FD4\u56DE\u7684\u4EE4\u724C\uFF1Bconfirm=true \u65F6\u5FC5\u586B")
|
|
24983
|
+
},
|
|
24984
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
|
|
24985
|
+
},
|
|
24986
|
+
async (args) => {
|
|
24987
|
+
try {
|
|
24988
|
+
return await handleManageGroup(ctx, args);
|
|
24989
|
+
} catch (error2) {
|
|
24990
|
+
return fail(error2);
|
|
24991
|
+
}
|
|
24992
|
+
}
|
|
24993
|
+
);
|
|
24994
|
+
}
|
|
24995
|
+
async function handleManageGroup(ctx, args) {
|
|
24996
|
+
if (args.action === "create") {
|
|
24997
|
+
return handleCreateGroup(ctx, args);
|
|
24998
|
+
}
|
|
24999
|
+
if (args.action === "rename") {
|
|
25000
|
+
return handleRenameGroup(ctx, args);
|
|
25001
|
+
}
|
|
25002
|
+
return handleDeleteGroup(ctx, args);
|
|
25003
|
+
}
|
|
25004
|
+
async function handleCreateGroup(ctx, args) {
|
|
25005
|
+
const name = validateGroupName(args.name ?? "", "\u65B0\u5206\u7EC4\u540D\u79F0");
|
|
25006
|
+
const groups = await loadPersonalGroups(ctx);
|
|
25007
|
+
const duplicate = findDuplicateGroup(groups, name);
|
|
25008
|
+
if (duplicate) {
|
|
25009
|
+
throw new EworkError(
|
|
25010
|
+
`\u5206\u7EC4\u300C${name}\u300D\u5DF2\u5B58\u5728\uFF08${duplicate.id ?? "-"}\uFF09\uFF1B\u8BF7\u6362\u4E00\u4E2A\u540D\u79F0\uFF0C\u6216\u76F4\u63A5\u7528\u5DF2\u6709\u5206\u7EC4`
|
|
25011
|
+
);
|
|
25012
|
+
}
|
|
25013
|
+
const payload = { action: "create", name };
|
|
25014
|
+
const preview = formatManagePreview(`\u521B\u5EFA\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u300C${name}\u300D`);
|
|
25015
|
+
if (!args.confirm) {
|
|
25016
|
+
const previewToken = createPreviewToken("manage_task_group", "new", payload);
|
|
25017
|
+
return ok(`${preview}
|
|
25018
|
+
previewToken\uFF1A${previewToken}
|
|
25019
|
+
\u8BF7\u786E\u8BA4\u540E\u5E26 previewToken \u4E0E confirm=true \u6267\u884C\u3002`, {
|
|
25020
|
+
action: "create",
|
|
25021
|
+
name,
|
|
25022
|
+
previewToken,
|
|
25023
|
+
expiresInSeconds: previewTtlSeconds()
|
|
25024
|
+
});
|
|
25025
|
+
}
|
|
25026
|
+
consumePreviewToken(args.previewToken, "manage_task_group", "new", payload);
|
|
25027
|
+
const groupId = String(
|
|
25028
|
+
await ctx.client.post("/external/home/task/setting/createGroup", {
|
|
25029
|
+
groupName: name
|
|
25030
|
+
}) ?? ""
|
|
25031
|
+
).trim();
|
|
25032
|
+
const after = await loadPersonalGroups(ctx);
|
|
25033
|
+
const created = after.find(
|
|
25034
|
+
(group) => groupId && String(group.id ?? "") === groupId || String(group.groupName ?? "").trim() === name
|
|
25035
|
+
);
|
|
25036
|
+
const verified = Boolean(created) && String(created?.groupName ?? "").trim() === name;
|
|
25037
|
+
const resultId = groupId || String(created?.id ?? "");
|
|
25038
|
+
return ok(
|
|
25039
|
+
[
|
|
25040
|
+
verified ? `\u5DF2\u521B\u5EFA\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u300C${name}\u300D\uFF08${resultId || "-"}\uFF09\u3002` : `\u521B\u5EFA\u5DF2\u63D0\u4EA4\uFF0C\u4F46\u56DE\u8BFB\u672A\u786E\u8BA4\u5206\u7EC4\u300C${name}\u300D\uFF1B\u8BF7\u624B\u52A8\u68C0\u67E5\u3002`
|
|
25041
|
+
].join("\n"),
|
|
25042
|
+
{
|
|
25043
|
+
action: "create",
|
|
25044
|
+
name,
|
|
25045
|
+
groupId: resultId,
|
|
25046
|
+
verified
|
|
25047
|
+
}
|
|
25048
|
+
);
|
|
25049
|
+
}
|
|
25050
|
+
async function handleRenameGroup(ctx, args) {
|
|
25051
|
+
const groupInput = String(args.group ?? "").trim();
|
|
25052
|
+
if (!groupInput) {
|
|
25053
|
+
throw new EworkError("\u8BF7\u63D0\u4F9B\u8981\u91CD\u547D\u540D\u7684\u5206\u7EC4\u540D\u79F0\u6216\u5206\u7EC4 id");
|
|
25054
|
+
}
|
|
25055
|
+
const newName = validateGroupName(args.newName ?? "", "\u65B0\u5206\u7EC4\u540D\u79F0");
|
|
25056
|
+
const groups = await loadPersonalGroups(ctx);
|
|
25057
|
+
const resolution = matchGroup(groupInput, groups);
|
|
25058
|
+
if (!resolution.ok) {
|
|
25059
|
+
throw new EworkError(formatGroupFailure(resolution));
|
|
25060
|
+
}
|
|
25061
|
+
const group = resolution.group;
|
|
25062
|
+
const groupId = String(group.id ?? "");
|
|
25063
|
+
const oldName = String(group.groupName ?? "");
|
|
25064
|
+
const duplicate = findDuplicateGroup(groups, newName, groupId);
|
|
25065
|
+
if (duplicate) {
|
|
25066
|
+
throw new EworkError(
|
|
25067
|
+
`\u5206\u7EC4\u300C${newName}\u300D\u5DF2\u5B58\u5728\uFF08${duplicate.id ?? "-"}\uFF09\uFF1B\u8BF7\u6362\u4E00\u4E2A\u540D\u79F0`
|
|
25068
|
+
);
|
|
25069
|
+
}
|
|
25070
|
+
if (oldName === newName) {
|
|
25071
|
+
return ok(`\u5206\u7EC4\u300C${oldName}\u300D\u540D\u79F0\u6CA1\u6709\u53D8\u5316\uFF0C\u672A\u6267\u884C\u5199\u5165\u3002`, {
|
|
25072
|
+
action: "rename",
|
|
25073
|
+
groupId,
|
|
25074
|
+
name: oldName,
|
|
25075
|
+
verified: true,
|
|
25076
|
+
changed: false
|
|
25077
|
+
});
|
|
25078
|
+
}
|
|
25079
|
+
const payload = { action: "rename", groupId, newName };
|
|
25080
|
+
const preview = formatManagePreview(
|
|
25081
|
+
`\u91CD\u547D\u540D\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\uFF1A${oldName}\uFF08${groupId}\uFF09 \u2192 ${newName}`
|
|
25082
|
+
);
|
|
25083
|
+
if (!args.confirm) {
|
|
25084
|
+
const previewToken = createPreviewToken("manage_task_group", groupId, payload);
|
|
25085
|
+
return ok(`${preview}
|
|
25086
|
+
previewToken\uFF1A${previewToken}
|
|
25087
|
+
\u8BF7\u786E\u8BA4\u540E\u5E26 previewToken \u4E0E confirm=true \u6267\u884C\u3002`, {
|
|
25088
|
+
action: "rename",
|
|
25089
|
+
groupId,
|
|
25090
|
+
before: oldName,
|
|
25091
|
+
after: newName,
|
|
25092
|
+
previewToken,
|
|
25093
|
+
expiresInSeconds: previewTtlSeconds()
|
|
25094
|
+
});
|
|
25095
|
+
}
|
|
25096
|
+
consumePreviewToken(args.previewToken, "manage_task_group", groupId, payload);
|
|
25097
|
+
await ctx.client.post("/external/home/task/setting/updateGroup", {
|
|
25098
|
+
id: groupId,
|
|
25099
|
+
groupName: newName
|
|
25100
|
+
});
|
|
25101
|
+
const after = await loadPersonalGroups(ctx);
|
|
25102
|
+
const updated = after.find((item) => String(item.id ?? "") === groupId);
|
|
25103
|
+
const verified = String(updated?.groupName ?? "").trim() === newName;
|
|
25104
|
+
return ok(
|
|
25105
|
+
verified ? `\u5DF2\u628A\u5206\u7EC4\u300C${oldName}\u300D\u91CD\u547D\u540D\u4E3A\u300C${newName}\u300D\u3002` : `\u91CD\u547D\u540D\u5DF2\u63D0\u4EA4\uFF0C\u4F46\u56DE\u8BFB\u672A\u786E\u8BA4\uFF1B\u5F53\u524D\u540D\u79F0\u4E3A\u300C${updated?.groupName ?? "-"}\u300D\uFF0C\u8BF7\u624B\u52A8\u68C0\u67E5\u3002`,
|
|
25106
|
+
{
|
|
25107
|
+
action: "rename",
|
|
25108
|
+
groupId,
|
|
25109
|
+
before: oldName,
|
|
25110
|
+
after: newName,
|
|
25111
|
+
verified
|
|
25112
|
+
}
|
|
25113
|
+
);
|
|
25114
|
+
}
|
|
25115
|
+
async function handleDeleteGroup(ctx, args) {
|
|
25116
|
+
const groupInput = String(args.group ?? "").trim();
|
|
25117
|
+
if (!groupInput) {
|
|
25118
|
+
throw new EworkError("\u8BF7\u63D0\u4F9B\u8981\u5220\u9664\u7684\u5206\u7EC4\u540D\u79F0\u6216\u5206\u7EC4 id");
|
|
25119
|
+
}
|
|
25120
|
+
const groups = await loadPersonalGroups(ctx);
|
|
25121
|
+
const resolution = matchGroup(groupInput, groups);
|
|
25122
|
+
if (!resolution.ok) {
|
|
25123
|
+
throw new EworkError(formatGroupFailure(resolution));
|
|
25124
|
+
}
|
|
25125
|
+
const group = resolution.group;
|
|
25126
|
+
const groupId = String(group.id ?? "");
|
|
25127
|
+
const groupName = String(group.groupName ?? "");
|
|
25128
|
+
const taskCount = await groupTaskCount(ctx, groupId);
|
|
25129
|
+
if (taskCount > 0) {
|
|
25130
|
+
throw new EworkError(
|
|
25131
|
+
`\u5206\u7EC4\u300C${groupName}\u300D\u4E0B\u8FD8\u6709 ${taskCount} \u6761\u4EFB\u52A1\uFF0C\u4E0D\u80FD\u5220\u9664\uFF1B\u8BF7\u5148\u628A\u4EFB\u52A1\u79FB\u51FA\u5206\u7EC4\uFF0C\u6216\u5728\u7F51\u9875\u5904\u7406`
|
|
25132
|
+
);
|
|
25133
|
+
}
|
|
25134
|
+
const payload = { action: "delete", groupId };
|
|
25135
|
+
const preview = formatManagePreview(
|
|
25136
|
+
`\u5220\u9664\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u300C${groupName}\u300D\uFF08${groupId}\uFF0C0 \u6761\u4EFB\u52A1\uFF09`
|
|
25137
|
+
);
|
|
25138
|
+
if (!args.confirm) {
|
|
25139
|
+
const previewToken = createPreviewToken("manage_task_group", groupId, payload);
|
|
25140
|
+
return ok(`${preview}
|
|
25141
|
+
previewToken\uFF1A${previewToken}
|
|
25142
|
+
\u8BF7\u786E\u8BA4\u540E\u5E26 previewToken \u4E0E confirm=true \u6267\u884C\u3002`, {
|
|
25143
|
+
action: "delete",
|
|
25144
|
+
groupId,
|
|
25145
|
+
name: groupName,
|
|
25146
|
+
taskCount,
|
|
25147
|
+
previewToken,
|
|
25148
|
+
expiresInSeconds: previewTtlSeconds()
|
|
25149
|
+
});
|
|
25150
|
+
}
|
|
25151
|
+
consumePreviewToken(args.previewToken, "manage_task_group", groupId, payload);
|
|
25152
|
+
await ctx.client.post("/external/home/task/setting/removeGroup", {
|
|
25153
|
+
id: groupId
|
|
25154
|
+
});
|
|
25155
|
+
const after = await loadPersonalGroups(ctx);
|
|
25156
|
+
const stillExists = after.some((item) => String(item.id ?? "") === groupId);
|
|
25157
|
+
return ok(
|
|
25158
|
+
stillExists ? `\u5220\u9664\u5DF2\u63D0\u4EA4\uFF0C\u4F46\u56DE\u8BFB\u4ECD\u80FD\u67E5\u5230\u5206\u7EC4\u300C${groupName}\u300D\uFF08${groupId}\uFF09\uFF0C\u8BF7\u624B\u52A8\u68C0\u67E5\u3002` : `\u5DF2\u5220\u9664\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u300C${groupName}\u300D\uFF08${groupId}\uFF09\u3002`,
|
|
25159
|
+
{
|
|
25160
|
+
action: "delete",
|
|
25161
|
+
groupId,
|
|
25162
|
+
name: groupName,
|
|
25163
|
+
verified: !stillExists
|
|
25164
|
+
}
|
|
25165
|
+
);
|
|
25166
|
+
}
|
|
25167
|
+
function formatManagePreview(action) {
|
|
25168
|
+
return [
|
|
25169
|
+
`\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u64CD\u4F5C\u9884\u6F14\uFF08\u672A\u5199\u5165\uFF09\uFF1A${action}`,
|
|
25170
|
+
"\u5206\u7EC4\u53EA\u5F71\u54CD\u5F53\u524D\u5458\u5DE5\u81EA\u5DF1\u7684\u300C\u6211\u7684\u4EFB\u52A1\u300D\u770B\u677F\uFF0C\u4E0D\u4F1A\u4FEE\u6539\u4EFB\u52A1\u672C\u8EAB\uFF0C\u4E5F\u4E0D\u4F1A\u540C\u6B65\u7ED9\u4ED6\u4EBA\u3002"
|
|
25171
|
+
].join("\n");
|
|
25172
|
+
}
|
|
25173
|
+
|
|
23540
25174
|
// src/tools/updateTask.ts
|
|
23541
25175
|
function registerUpdateTask(server, ctx) {
|
|
23542
25176
|
server.registerTool(
|
|
@@ -23600,7 +25234,7 @@ function registerUpdateTask(server, ctx) {
|
|
|
23600
25234
|
};
|
|
23601
25235
|
if (!args.confirm) {
|
|
23602
25236
|
const previewToken = createPreviewToken("update_task", taskId, tokenPayload);
|
|
23603
|
-
return ok(
|
|
25237
|
+
return ok(formatPreview5(preview, previewToken), {
|
|
23604
25238
|
...preview,
|
|
23605
25239
|
previewToken,
|
|
23606
25240
|
expiresInSeconds: previewTtlSeconds()
|
|
@@ -23634,7 +25268,7 @@ function registerUpdateTask(server, ctx) {
|
|
|
23634
25268
|
}
|
|
23635
25269
|
);
|
|
23636
25270
|
}
|
|
23637
|
-
function
|
|
25271
|
+
function formatPreview5(preview, previewToken) {
|
|
23638
25272
|
const lines = [`\u4EFB\u52A1 ${preview.taskId} \u4FEE\u6539\u9884\u6F14\uFF08\u672A\u5199\u5165\uFF09\uFF1A`];
|
|
23639
25273
|
if (preview.changed.title) {
|
|
23640
25274
|
lines.push(`\u6807\u9898\uFF1A${preview.title.before || "-"} \u2192 ${preview.title.after || "-"}`);
|
|
@@ -23678,20 +25312,24 @@ async function main() {
|
|
|
23678
25312
|
const server = new McpServer(
|
|
23679
25313
|
{
|
|
23680
25314
|
name: "task-mcp",
|
|
23681
|
-
version: "0.
|
|
25315
|
+
version: "0.3.0"
|
|
23682
25316
|
},
|
|
23683
25317
|
{
|
|
23684
|
-
instructions: "\u8FD9\u662F\u6613\u5DE5\u4F5C\u300C\u5DE5\u4F5C\u8BA1\u5212\u300D\u4EFB\u52A1\u5DE5\u5177\u3002'\u6211\u7684\u4EFB\u52A1/\u6211\u8D1F\u8D23\u7684\u4EFB\u52A1'\u53EA\u6307\u8D1F\u8D23\u4EBA\uFF08\u4EFB\u52A1\u6210\u5458\u89D2\u8272 O\uFF09\u662F\u5F53\u524D API Key \u5458\u5DE5\u7684\u4EFB\u52A1\uFF0C\u4E0D\u542B\u53C2\u4E0E\u4EBA/\u6284\u9001\u4EBA\u89C6\u89D2\u3002\u72B6\u6001\u540D\u6309\u4EFB\u52A1\u6240\u5C5E\u5DE5\u4F5C\u6D41\u7CBE\u786E\u5339\u914D\uFF1BS/P/F/E \u662F\u72B6\u6001\u7C7B\u578B\uFF0C\u4E0D\u662F\u72B6\u6001\u540D\uFF1B\u7CFB\u7EDF\u6CA1\u6709'\u672A\u5904\u7406/\u5904\u7406\u4E2D'\uFF0C\u5E38\u89C1\u72B6\u6001\u4E3A\u672A\u5F00\u59CB/\u8FDB\u884C\u4E2D/\u5DF2\u5B8C\u6210/\u5DF2\u53D6\u6D88\u6216\u5F85\u5904\u7406/\u4FEE\u590D\u4E2D/\u5F85\u53D1\u5E03/\u5DF2\u89E3\u51B3/\u5DF2\u5173\u95ED\u3002\u6240\u6709\u5199\u5DE5\u5177\u5FC5\u987B\u5148\u5728\u7528\u6237\u660E\u786E\u540C\u610F\u540E\uFF0C\u7528\u9884\u6F14\u8FD4\u56DE\u7684 previewToken \u548C confirm=true \u6267\u884C\uFF0C\u4E0D\u80FD\u8DF3\u8FC7\u9884\u6F14\u3002taskId \u5FC5\u987B\u6309\u5B57\u7B26\u4E32\u4F20\u9012\uFF1B\u4EFB\u52A1\u94FE\u63A5\u5FC5\u987B\u4E0E EWORK_BASE_URL \u540C\u4E00\u73AF\u5883\u3002"
|
|
25318
|
+
instructions: "\u8FD9\u662F\u6613\u5DE5\u4F5C\u300C\u5DE5\u4F5C\u8BA1\u5212\u300D\u4EFB\u52A1\u5DE5\u5177\u3002'\u6211\u7684\u4EFB\u52A1/\u6211\u8D1F\u8D23\u7684\u4EFB\u52A1'\u53EA\u6307\u8D1F\u8D23\u4EBA\uFF08\u4EFB\u52A1\u6210\u5458\u89D2\u8272 O\uFF09\u662F\u5F53\u524D API Key \u5458\u5DE5\u7684\u4EFB\u52A1\uFF0C\u4E0D\u542B\u53C2\u4E0E\u4EBA/\u6284\u9001\u4EBA\u89C6\u89D2\uFF1B'\u6211\u521B\u5EFA\u7684\u4EFB\u52A1'\u6307\u521B\u5EFA\u4EBA\uFF08\u89D2\u8272 R\uFF09\uFF0C\u7528 list_created_tasks\u3002list_my_tasks \u4E0E my_task_stats \u652F\u6301\u7528 plan \u53C2\u6570\u6309\u8BA1\u5212\u540D\u79F0\u6216 32 \u4F4D\u8BA1\u5212 id \u7B5B\u9009\uFF0C\u8BA1\u5212\u540D\u91CD\u540D\u65F6\u8FD4\u56DE\u5019\u9009\u3002\u4E2A\u4EBA\u4EFB\u52A1\u5206\u7EC4\u7528 list_task_groups / manage_task_group / assign_task_to_group\uFF1B\u5206\u7EC4\u53EA\u5F71\u54CD\u5F53\u524D\u5458\u5DE5\u81EA\u5DF1\u7684\u770B\u677F\uFF0C\u4E0D\u662F\u8BA1\u5212\u5171\u4EAB\u5206\u7EC4\uFF1Blist_my_tasks / list_created_tasks \u53EF\u7528 group \u53C2\u6570\u7B5B\u9009\uFF0Ccreate_task \u53EF\u7528 group \u76F4\u63A5\u5165\u7EC4\u3002\u72B6\u6001\u540D\u6309\u4EFB\u52A1\u6240\u5C5E\u5DE5\u4F5C\u6D41\u7CBE\u786E\u5339\u914D\uFF1BS/P/F/E \u662F\u72B6\u6001\u7C7B\u578B\uFF0C\u4E0D\u662F\u72B6\u6001\u540D\uFF1B\u7CFB\u7EDF\u6CA1\u6709'\u672A\u5904\u7406/\u5904\u7406\u4E2D'\uFF0C\u5E38\u89C1\u72B6\u6001\u4E3A\u672A\u5F00\u59CB/\u8FDB\u884C\u4E2D/\u5DF2\u5B8C\u6210/\u5DF2\u53D6\u6D88\u6216\u5F85\u5904\u7406/\u4FEE\u590D\u4E2D/\u5F85\u53D1\u5E03/\u5DF2\u89E3\u51B3/\u5DF2\u5173\u95ED\u3002create_task \u53EA\u521B\u5EFA\u8BA1\u5212\u4EFB\u52A1\uFF0C\u5FC5\u586B\u8BA1\u5212\u3001\u4EFB\u52A1\u7C7B\u578B\u3001\u6807\u9898\u548C\u622A\u6B62\u65E5\u671F\uFF0C\u9ED8\u8BA4\u8D1F\u8D23\u4EBA\u4E3A\u5F53\u524D\u5458\u5DE5\u3001\u5F00\u59CB\u65E5\u671F\u4E3A\u4ECA\u5929\u3001\u5168\u5929\u4EFB\u52A1\u3002\u6240\u6709\u5199\u5DE5\u5177\u5FC5\u987B\u5148\u5728\u7528\u6237\u660E\u786E\u540C\u610F\u540E\uFF0C\u7528\u9884\u6F14\u8FD4\u56DE\u7684 previewToken \u548C confirm=true \u6267\u884C\uFF0C\u4E0D\u80FD\u8DF3\u8FC7\u9884\u6F14\u3002taskId \u5FC5\u987B\u6309\u5B57\u7B26\u4E32\u4F20\u9012\uFF1B\u4EFB\u52A1\u94FE\u63A5\u5FC5\u987B\u4E0E EWORK_BASE_URL \u540C\u4E00\u73AF\u5883\u3002"
|
|
23685
25319
|
}
|
|
23686
25320
|
);
|
|
23687
25321
|
registerGetTask(server, ctx);
|
|
23688
25322
|
registerListMyTasks(server, ctx);
|
|
25323
|
+
registerListCreatedTasks(server, ctx);
|
|
23689
25324
|
registerMyTaskStats(server, ctx);
|
|
23690
25325
|
registerUpdateTask(server, ctx);
|
|
23691
25326
|
registerChangeOwner(server, ctx);
|
|
23692
25327
|
registerChangeStatus(server, ctx);
|
|
23693
25328
|
registerAddComment(server, ctx);
|
|
23694
25329
|
registerSearchEmployee(server, ctx);
|
|
25330
|
+
registerCreateTask(server, ctx);
|
|
25331
|
+
registerTaskGroups(server, ctx);
|
|
25332
|
+
registerAssignTaskToGroup(server, ctx);
|
|
23695
25333
|
const transport = new StdioServerTransport();
|
|
23696
25334
|
await server.connect(transport);
|
|
23697
25335
|
process.stderr.write(`[task-mcp] \u5DF2\u542F\u52A8\uFF0C\u7F51\u5173\u5730\u5740 ${config2.baseUrl}
|