taskmeld 0.1.1 → 0.1.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +176 -172
- package/README.zh-CN.md +176 -172
- package/dist/src/app/app-context-env.js +1 -1
- package/dist/src/app/create-app-context.js +3 -3
- package/dist/src/app/data-dir.js +13 -3
- package/dist/src/app/pipeline-config.js +4 -4
- package/dist/src/app/pipeline-registry.js +11 -11
- package/dist/src/app/pipeline-runtime.js +6 -9
- package/dist/src/app/runtime-store.js +3 -3
- package/dist/src/artifacts/artifact-cleanup.js +17 -17
- package/dist/src/artifacts/artifact-index.js +14 -14
- package/dist/src/artifacts/artifact-rebuilder.js +3 -3
- package/dist/src/artifacts/storage-service.js +18 -18
- package/dist/src/cli/bootstrap.js +7 -7
- package/dist/src/cli/commands/agent.js +12 -11
- package/dist/src/cli/commands/artifact.js +31 -30
- package/dist/src/cli/commands/init.js +49 -47
- package/dist/src/cli/commands/pipeline/result.js +9 -8
- package/dist/src/cli/commands/pipeline/selector.js +1 -1
- package/dist/src/cli/commands/pipeline/watch.js +2 -2
- package/dist/src/cli/commands/pipeline.js +54 -53
- package/dist/src/cli/commands/scheduler.js +9 -8
- package/dist/src/cli/commands/server.js +12 -11
- package/dist/src/cli/commands/system.js +4 -3
- package/dist/src/cli/errors.js +2 -2
- package/dist/src/cli/help.js +18 -17
- package/dist/src/cli/i18n.js +46 -0
- package/dist/src/cli/locales/en.json +244 -0
- package/dist/src/cli/locales/zh.json +244 -0
- package/dist/src/cli/output.js +3 -3
- package/dist/src/cli/renderers/engine/markdown.js +1 -1
- package/dist/src/cli/renderers/specs/index.js +1 -1
- package/dist/src/cli/router.js +1 -1
- package/dist/src/cli/server-runtime-client.js +54 -95
- package/dist/src/cli/ui-prompts.js +96 -0
- package/dist/src/cli/ws-runtime-client.js +51 -0
- package/dist/src/gateway/gateway-client.js +4 -4
- package/dist/src/index.js +28 -2
- package/dist/src/logs/run-log-reader.js +1 -1
- package/dist/src/pipeline/agent-activity.js +2 -2
- package/dist/src/pipeline/artifact-storage.js +11 -11
- package/dist/src/pipeline/diagnostics/dependency-diagnostic.js +11 -11
- package/dist/src/pipeline/dispatch/pipeline-inbound-queue.js +2 -2
- package/dist/src/pipeline/execution/group-item-executor.js +1 -1
- package/dist/src/pipeline/execution/node-item-executor.js +3 -3
- package/dist/src/pipeline/execution/node-runner.js +7 -7
- package/dist/src/pipeline/execution/readiness-state.js +1 -1
- package/dist/src/pipeline/execution/reject-handler.js +5 -5
- package/dist/src/pipeline/execution/rejected-artifact-archiver.js +1 -1
- package/dist/src/pipeline/execution/route-item-manager.js +4 -4
- package/dist/src/pipeline/execution/run-abort-controller.js +5 -5
- package/dist/src/pipeline/execution/run-state-helpers.js +2 -2
- package/dist/src/pipeline/execution/service.js +4 -4
- package/dist/src/pipeline/execution/structured-node-runner.js +24 -24
- package/dist/src/pipeline/execution-timeout.js +3 -3
- package/dist/src/pipeline/identity/index.js +3 -3
- package/dist/src/pipeline/item-batch-controller.js +6 -6
- package/dist/src/pipeline/scheduler/dependency-state.js +5 -5
- package/dist/src/pipeline/scheduler-service.js +24 -24
- package/dist/src/pipeline/state-machine.js +2 -2
- package/dist/src/pipeline/structured-output/contract.js +4 -4
- package/dist/src/pipeline/structured-output/index.js +2 -2
- package/dist/src/pipeline/structured-output/parser.js +5 -5
- package/dist/src/pipeline/structured-output/prompt.js +38 -38
- package/dist/src/pipeline/structured-output/waiter.js +6 -6
- package/dist/src/pipeline/template.js +5 -5
- package/dist/src/pipeline/timeline-log-store.js +5 -5
- package/dist/src/pipeline/tool-activity.js +3 -3
- package/dist/src/pipeline/types/pipeline-output.js +1 -1
- package/dist/src/pipeline/workflow/branch-rules.js +19 -19
- package/dist/src/pipeline/workflow/io.js +1 -1
- package/dist/src/pipeline/workflow/normalize.js +18 -18
- package/dist/src/pipeline/workflow/template-mapper.js +3 -3
- package/dist/src/pipeline/workflow/validate.js +39 -39
- package/dist/src/pipeline/workflow-graph.js +10 -10
- package/dist/src/server/http-handler.js +74 -0
- package/dist/src/services/agent-service.js +2 -2
- package/dist/src/services/gateway-read-helpers.js +1 -1
- package/dist/src/services/pipeline-service.js +19 -19
- package/dist/src/services/pipeline-status.js +4 -4
- package/dist/src/services/read-services.js +1 -1
- package/dist/src/services/session-service.js +6 -6
- package/dist/src/services/system-service.js +1 -1
- package/dist/src/transport/ws-broker.js +12 -1
- package/dist/src/transport/ws-handler.js +60 -0
- package/dist/src/transport/ws-methods/agents.js +144 -0
- package/dist/src/transport/ws-methods/artifacts.js +171 -0
- package/dist/src/transport/ws-methods/gateway.js +16 -0
- package/dist/src/transport/ws-methods/logs.js +43 -0
- package/dist/src/transport/ws-methods/pipeline-batch.js +68 -0
- package/dist/src/transport/ws-methods/pipeline-links.js +100 -0
- package/dist/src/transport/ws-methods/pipeline-queue.js +51 -0
- package/dist/src/transport/ws-methods/pipeline-runtime.js +151 -0
- package/dist/src/transport/ws-methods/pipeline-scheduler.js +48 -0
- package/dist/src/transport/ws-methods/pipeline-workflow.js +127 -0
- package/dist/src/transport/ws-methods/pipelines.js +56 -0
- package/dist/src/transport/ws-methods/register-all.js +32 -0
- package/dist/src/transport/ws-methods/sessions.js +154 -0
- package/dist/src/transport/ws-methods/timeline.js +10 -0
- package/dist/src/{server/routes/pipeline-identity.js → transport/ws-methods/utils.js} +14 -9
- package/dist/src/version.js +1 -1
- package/package.json +16 -7
- package/web/dist/assets/agent-DP6TMcLj.js +1 -0
- package/web/dist/assets/agent-DmJHzLyj.js +1 -0
- package/web/dist/assets/artifact-BqnoZy2M.js +1 -0
- package/web/dist/assets/artifact-DfDkgkno.js +1 -0
- package/web/dist/assets/common-DRMTVwE9.js +1 -0
- package/web/dist/assets/common-DeXccbr2.js +1 -0
- package/web/dist/assets/dispatch-CBskGCQI.js +1 -0
- package/web/dist/assets/dispatch-sk4Wp30e.js +1 -0
- package/web/dist/assets/index-C8wTjZvH.css +1 -0
- package/web/dist/assets/index-DYDQZRLk.js +58 -0
- package/web/dist/assets/log-DN8cjb0w.js +1 -0
- package/web/dist/assets/log-HSeA_dYy.js +1 -0
- package/web/dist/assets/modal-BdNai9jf.js +1 -0
- package/web/dist/assets/modal-D9_KDpFD.js +1 -0
- package/web/dist/assets/nav-BmF7oAKg.js +1 -0
- package/web/dist/assets/nav-IjC2xqXQ.js +1 -0
- package/web/dist/assets/node-detail-CENRXcrh.js +1 -0
- package/web/dist/assets/node-detail-bndPr0IM.js +1 -0
- package/web/dist/assets/overview-B87zWAxq.js +1 -0
- package/web/dist/assets/overview-gQvk-NOK.js +1 -0
- package/web/dist/assets/pipeline-D4dSJRDz.js +1 -0
- package/web/dist/assets/pipeline-DZzyOqQa.js +1 -0
- package/web/dist/assets/session-CUWvU14v.js +5 -0
- package/web/dist/assets/session-DQ6UuCaJ.js +5 -0
- package/web/dist/assets/timeline-8y_2_0Em.js +1 -0
- package/web/dist/assets/timeline-CAPsXUTC.js +1 -0
- package/web/dist/index.html +3 -3
- package/dist/src/app/pipeline-plugin-config.js +0 -2
- package/dist/src/server/api-handler.js +0 -163
- package/dist/src/server/http-utils.js +0 -34
- package/dist/src/server/middleware.js +0 -61
- package/dist/src/server/router.js +0 -105
- package/dist/src/server/routes/agents.js +0 -189
- package/dist/src/server/routes/artifacts.js +0 -163
- package/dist/src/server/routes/gateway.js +0 -18
- package/dist/src/server/routes/health.js +0 -16
- package/dist/src/server/routes/logs.js +0 -73
- package/dist/src/server/routes/pipeline-batch.js +0 -163
- package/dist/src/server/routes/pipeline-diagnostics.js +0 -33
- package/dist/src/server/routes/pipeline-links.js +0 -117
- package/dist/src/server/routes/pipeline-outputs.js +0 -27
- package/dist/src/server/routes/pipeline-queue.js +0 -62
- package/dist/src/server/routes/pipeline-runtime.js +0 -162
- package/dist/src/server/routes/pipeline-scheduler.js +0 -69
- package/dist/src/server/routes/pipeline-workflow.js +0 -180
- package/dist/src/server/routes/pipelines.js +0 -96
- package/dist/src/server/routes/sessions.js +0 -244
- package/dist/src/server/routes/timeline.js +0 -14
- package/dist/src/server/serve-static.js +0 -42
- package/web/dist/assets/index-CWnfhkn-.js +0 -65
- package/web/dist/assets/index-gZ0xOfSO.css +0 -1
- /package/dist/src/{server → transport/ws-methods}/types.js +0 -0
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerPipelinesRoutes = void 0;
|
|
4
|
-
const PIPELINE_ID_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
5
|
-
// 从请求体读取流水线标题,若未提供则生成默认标题
|
|
6
|
-
const readPipelineTitle = (value, pipelineId) => typeof value === "string" && value.trim() ? value.trim() : `流水线 DAG-${pipelineId}`;
|
|
7
|
-
/**
|
|
8
|
-
* 注册 Pipeline CRUD 路由:
|
|
9
|
-
* GET /api/pipelines — 列出所有流水线
|
|
10
|
-
* POST /api/pipelines — 创建流水线
|
|
11
|
-
* PATCH /api/pipelines/:pipelineId — 重命名流水线
|
|
12
|
-
* DELETE /api/pipelines/:pipelineId — 删除流水线
|
|
13
|
-
*/
|
|
14
|
-
const registerPipelinesRoutes = (router) => {
|
|
15
|
-
router.register("GET", "/api/pipelines", (ctx) => {
|
|
16
|
-
ctx.sendJson(200, {
|
|
17
|
-
items: ctx.options.app.listPipelines().map((definition) => ({
|
|
18
|
-
id: definition.id,
|
|
19
|
-
title: definition.title,
|
|
20
|
-
})),
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
router.register("POST", "/api/pipelines", async (ctx) => {
|
|
24
|
-
const body = await ctx.readBody();
|
|
25
|
-
const pipelineId = typeof body.id === "string" ? body.id.trim() : "";
|
|
26
|
-
const cloneFrom = typeof body.cloneFrom === "string" && body.cloneFrom.trim() ? body.cloneFrom.trim() : undefined;
|
|
27
|
-
if (!PIPELINE_ID_PATTERN.test(pipelineId)) {
|
|
28
|
-
ctx.sendJson(400, { ok: false, error: "pipeline_id_invalid" });
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
const item = await ctx.options.app.createPipeline({
|
|
33
|
-
id: pipelineId,
|
|
34
|
-
title: readPipelineTitle(body.title, pipelineId),
|
|
35
|
-
cloneFrom,
|
|
36
|
-
});
|
|
37
|
-
ctx.sendJson(200, {
|
|
38
|
-
ok: true,
|
|
39
|
-
item: {
|
|
40
|
-
id: item.id,
|
|
41
|
-
title: item.title,
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
const detail = error instanceof Error ? error.message : "pipeline_create_failed";
|
|
47
|
-
const status = detail === "pipeline_already_exists"
|
|
48
|
-
? 409
|
|
49
|
-
: detail === "pipeline_id_invalid" || detail === "pipeline_clone_source_not_found"
|
|
50
|
-
? 400
|
|
51
|
-
: 500;
|
|
52
|
-
ctx.sendJson(status, { ok: false, error: detail });
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
router.register("PATCH", "/api/pipelines/:pipelineId", async (ctx) => {
|
|
56
|
-
const { pipelineId } = ctx.params;
|
|
57
|
-
const body = await ctx.readBody();
|
|
58
|
-
const title = typeof body.title === "string" ? body.title.trim() : "";
|
|
59
|
-
if (!title) {
|
|
60
|
-
ctx.sendJson(400, { ok: false, error: "pipeline_title_invalid", pipelineId: pipelineId || null });
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
const item = ctx.options.app.renamePipeline(pipelineId, title);
|
|
65
|
-
ctx.sendJson(200, {
|
|
66
|
-
ok: true,
|
|
67
|
-
item: {
|
|
68
|
-
id: item.id,
|
|
69
|
-
title: item.title,
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
const detail = error instanceof Error ? error.message : "pipeline_rename_failed";
|
|
75
|
-
const status = detail === "pipeline_not_found" ? 404 : detail === "pipeline_title_invalid" ? 400 : 500;
|
|
76
|
-
ctx.sendJson(status, { ok: false, error: detail, pipelineId: pipelineId || null });
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
router.register("DELETE", "/api/pipelines/:pipelineId", async (ctx) => {
|
|
80
|
-
const { pipelineId } = ctx.params;
|
|
81
|
-
try {
|
|
82
|
-
const deleted = ctx.options.app.deletePipeline(pipelineId);
|
|
83
|
-
ctx.sendJson(200, { ok: true, pipelineId: deleted.pipelineId });
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
const detail = error instanceof Error ? error.message : "pipeline_delete_failed";
|
|
87
|
-
const status = detail === "pipeline_not_found"
|
|
88
|
-
? 404
|
|
89
|
-
: detail === "pipeline_delete_last_forbidden" || detail === "pipeline_delete_running_forbidden"
|
|
90
|
-
? 409
|
|
91
|
-
: 500;
|
|
92
|
-
ctx.sendJson(status, { ok: false, error: detail, pipelineId: pipelineId || null });
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
exports.registerPipelinesRoutes = registerPipelinesRoutes;
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerSessionsRoutes = void 0;
|
|
4
|
-
const http_utils_js_1 = require("../http-utils.js");
|
|
5
|
-
const asRecord = (value) => value && typeof value === "object" && !Array.isArray(value)
|
|
6
|
-
? value
|
|
7
|
-
: null;
|
|
8
|
-
const pickString = (record, keys) => {
|
|
9
|
-
for (const key of keys) {
|
|
10
|
-
const raw = record[key];
|
|
11
|
-
if (typeof raw === "string" && raw.trim())
|
|
12
|
-
return raw.trim();
|
|
13
|
-
}
|
|
14
|
-
return null;
|
|
15
|
-
};
|
|
16
|
-
const readModelInfo = (value) => {
|
|
17
|
-
const direct = asRecord(value);
|
|
18
|
-
if (!direct)
|
|
19
|
-
return { model: null, modelProvider: null, api: null };
|
|
20
|
-
const nestedSession = asRecord(direct.session);
|
|
21
|
-
const nestedMeta = asRecord(direct.meta);
|
|
22
|
-
const model = pickString(direct, ["model", "modelName"]) ??
|
|
23
|
-
(nestedSession
|
|
24
|
-
? pickString(nestedSession, ["model", "modelName"])
|
|
25
|
-
: null) ??
|
|
26
|
-
(nestedMeta
|
|
27
|
-
? pickString(nestedMeta, ["model", "modelName"])
|
|
28
|
-
: null);
|
|
29
|
-
const modelProvider = pickString(direct, ["modelProvider", "provider", "model_provider"]) ??
|
|
30
|
-
(nestedSession
|
|
31
|
-
? pickString(nestedSession, [
|
|
32
|
-
"modelProvider",
|
|
33
|
-
"provider",
|
|
34
|
-
"model_provider",
|
|
35
|
-
])
|
|
36
|
-
: null) ??
|
|
37
|
-
(nestedMeta
|
|
38
|
-
? pickString(nestedMeta, ["modelProvider", "provider", "model_provider"])
|
|
39
|
-
: null);
|
|
40
|
-
const api = pickString(direct, ["api", "apiType"]) ??
|
|
41
|
-
(nestedSession
|
|
42
|
-
? pickString(nestedSession, ["api", "apiType"])
|
|
43
|
-
: null) ??
|
|
44
|
-
(nestedMeta ? pickString(nestedMeta, ["api", "apiType"]) : null);
|
|
45
|
-
return { model, modelProvider, api };
|
|
46
|
-
};
|
|
47
|
-
const mergeModelInfo = (preferred, fallback) => ({
|
|
48
|
-
model: preferred.model ?? fallback.model,
|
|
49
|
-
modelProvider: preferred.modelProvider ?? fallback.modelProvider,
|
|
50
|
-
api: preferred.api ?? fallback.api,
|
|
51
|
-
});
|
|
52
|
-
const registerSessionsRoutes = (router) => {
|
|
53
|
-
router.register("GET", "/api/sessions", async (ctx) => {
|
|
54
|
-
const services = ctx.services;
|
|
55
|
-
try {
|
|
56
|
-
const { payload, items } = await services.refreshSessionsFromGateway();
|
|
57
|
-
ctx.sendJson(200, { items, raw: payload });
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
ctx.sendJson(503, { error: String(error) });
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
router.register("GET", "/api/sessions/:sessionId/history", async (ctx) => {
|
|
64
|
-
const services = ctx.services;
|
|
65
|
-
try {
|
|
66
|
-
const sessionId = ctx.params.sessionId;
|
|
67
|
-
if (!sessionId) {
|
|
68
|
-
ctx.sendJson(400, { error: "invalid_session_id" });
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const limitRaw = Number(ctx.url.searchParams.get("limit") ?? 200);
|
|
72
|
-
const limit = Number.isFinite(limitRaw) && limitRaw > 0
|
|
73
|
-
? Math.min(500, Math.floor(limitRaw))
|
|
74
|
-
: 200;
|
|
75
|
-
const payload = await services.client.sendReq("chat.history", {
|
|
76
|
-
sessionKey: sessionId,
|
|
77
|
-
limit,
|
|
78
|
-
});
|
|
79
|
-
const raw = (payload ?? {});
|
|
80
|
-
const rawItems = Array.isArray(raw.items)
|
|
81
|
-
? raw.items
|
|
82
|
-
: Array.isArray(raw.messages)
|
|
83
|
-
? raw.messages
|
|
84
|
-
: Array.isArray(raw.history)
|
|
85
|
-
? raw.history
|
|
86
|
-
: Array.isArray(payload)
|
|
87
|
-
? payload
|
|
88
|
-
: [];
|
|
89
|
-
const latestAssistant = [...rawItems]
|
|
90
|
-
.reverse()
|
|
91
|
-
.find((item) => String((asRecord(item) ?? {}).role ?? "").toLowerCase() === "assistant");
|
|
92
|
-
const latestModelInfo = readModelInfo(latestAssistant);
|
|
93
|
-
let sessionModelInfo = {
|
|
94
|
-
model: null,
|
|
95
|
-
modelProvider: null,
|
|
96
|
-
api: null,
|
|
97
|
-
};
|
|
98
|
-
try {
|
|
99
|
-
const { items } = await services.refreshSessionsFromGateway();
|
|
100
|
-
const matched = items.find((session) => session.id === sessionId);
|
|
101
|
-
sessionModelInfo = readModelInfo(matched?.raw);
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
// 即使 sessions.list 暂时不可用,仍保持 history 端点可用
|
|
105
|
-
}
|
|
106
|
-
const mergedInfo = mergeModelInfo(latestModelInfo, sessionModelInfo);
|
|
107
|
-
const items = rawItems.map((item) => {
|
|
108
|
-
const rec = asRecord(item);
|
|
109
|
-
if (!rec)
|
|
110
|
-
return item;
|
|
111
|
-
const role = String(rec.role ?? "").toLowerCase();
|
|
112
|
-
if (role !== "assistant")
|
|
113
|
-
return item;
|
|
114
|
-
const itemModelInfo = mergeModelInfo(readModelInfo(rec), mergedInfo);
|
|
115
|
-
return {
|
|
116
|
-
...rec,
|
|
117
|
-
model: rec.model ?? itemModelInfo.model,
|
|
118
|
-
modelProvider: rec.modelProvider ??
|
|
119
|
-
rec.provider ??
|
|
120
|
-
itemModelInfo.modelProvider,
|
|
121
|
-
provider: rec.provider ??
|
|
122
|
-
rec.modelProvider ??
|
|
123
|
-
itemModelInfo.modelProvider,
|
|
124
|
-
api: rec.api ?? itemModelInfo.api,
|
|
125
|
-
};
|
|
126
|
-
});
|
|
127
|
-
ctx.sendJson(200, {
|
|
128
|
-
items,
|
|
129
|
-
raw: payload,
|
|
130
|
-
limit,
|
|
131
|
-
model: mergedInfo.model,
|
|
132
|
-
modelProvider: mergedInfo.modelProvider,
|
|
133
|
-
api: mergedInfo.api,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
ctx.sendJson(503, { error: String(error) });
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
router.register("POST", "/api/sessions", async (ctx) => {
|
|
141
|
-
const services = ctx.services;
|
|
142
|
-
try {
|
|
143
|
-
const body = await ctx.readBody();
|
|
144
|
-
const payload = await services.client.sendReq("sessions.create", body, { sideEffect: true });
|
|
145
|
-
ctx.sendJson(200, { item: payload ?? null });
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
ctx.sendJson(500, { error: String(error) });
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
router.register("POST", "/api/sessions/:sessionId/send", async (ctx) => {
|
|
152
|
-
const services = ctx.services;
|
|
153
|
-
try {
|
|
154
|
-
const sessionId = ctx.params.sessionId;
|
|
155
|
-
if (!sessionId) {
|
|
156
|
-
ctx.sendJson(400, { error: "invalid_session_id" });
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const body = await ctx.readBody();
|
|
160
|
-
const text = (0, http_utils_js_1.firstText)(body);
|
|
161
|
-
const mode = String(body.mode ?? "auto");
|
|
162
|
-
if (!text) {
|
|
163
|
-
ctx.sendJson(400, { error: "message_required" });
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const attempts = [];
|
|
167
|
-
const chatAttempts = [
|
|
168
|
-
{
|
|
169
|
-
method: "chat.send",
|
|
170
|
-
params: { sessionKey: sessionId, message: text },
|
|
171
|
-
},
|
|
172
|
-
];
|
|
173
|
-
const sessionsAttempts = [
|
|
174
|
-
{
|
|
175
|
-
method: "sessions.send",
|
|
176
|
-
params: { key: sessionId, message: text },
|
|
177
|
-
},
|
|
178
|
-
];
|
|
179
|
-
if (mode === "chat") {
|
|
180
|
-
attempts.push(...chatAttempts);
|
|
181
|
-
}
|
|
182
|
-
else if (mode === "sessions") {
|
|
183
|
-
attempts.push(...sessionsAttempts);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
attempts.push(...chatAttempts, ...sessionsAttempts);
|
|
187
|
-
}
|
|
188
|
-
let payload = null;
|
|
189
|
-
let lastError = null;
|
|
190
|
-
const attemptErrors = [];
|
|
191
|
-
let usedMethod = null;
|
|
192
|
-
let usedParams = null;
|
|
193
|
-
for (const attempt of attempts) {
|
|
194
|
-
try {
|
|
195
|
-
payload = await services.client.sendReq(attempt.method, attempt.params, { sideEffect: true });
|
|
196
|
-
usedMethod = attempt.method;
|
|
197
|
-
usedParams = attempt.params;
|
|
198
|
-
services.pushTimeline(`会话消息发送成功: ${sessionId} (${attempt.method})`);
|
|
199
|
-
break;
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
lastError = error;
|
|
203
|
-
attemptErrors.push(`${attempt.method}: ${String(error)}`);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
if (payload === null) {
|
|
207
|
-
ctx.sendJson(500, {
|
|
208
|
-
error: String(lastError ?? "sessions_send_failed"),
|
|
209
|
-
attempts: attemptErrors,
|
|
210
|
-
mode,
|
|
211
|
-
});
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
let sessionModelInfo = {
|
|
215
|
-
model: null,
|
|
216
|
-
modelProvider: null,
|
|
217
|
-
api: null,
|
|
218
|
-
};
|
|
219
|
-
try {
|
|
220
|
-
const { items } = await services.refreshSessionsFromGateway();
|
|
221
|
-
const matched = items.find((session) => session.id === sessionId);
|
|
222
|
-
sessionModelInfo = readModelInfo(matched?.raw);
|
|
223
|
-
}
|
|
224
|
-
catch {
|
|
225
|
-
// 即使 sessions.list 刷新失败,仍保持 send 路径可用
|
|
226
|
-
}
|
|
227
|
-
const usedModelInfo = mergeModelInfo(readModelInfo(payload), sessionModelInfo);
|
|
228
|
-
ctx.sendJson(200, {
|
|
229
|
-
item: payload ?? null,
|
|
230
|
-
mode,
|
|
231
|
-
usedMethod,
|
|
232
|
-
usedParams,
|
|
233
|
-
model: usedModelInfo.model,
|
|
234
|
-
modelProvider: usedModelInfo.modelProvider,
|
|
235
|
-
api: usedModelInfo.api,
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
catch (error) {
|
|
239
|
-
services.pushTimeline(`会话消息发送失败: ${String(error)}`, "error");
|
|
240
|
-
ctx.sendJson(500, { error: String(error) });
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
};
|
|
244
|
-
exports.registerSessionsRoutes = registerSessionsRoutes;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerTimelineRoutes = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* 注册 GET /api/timeline 路由。
|
|
6
|
-
* 返回合并后的全流水线时间线记录。
|
|
7
|
-
*/
|
|
8
|
-
const registerTimelineRoutes = (router) => {
|
|
9
|
-
router.register("GET", "/api/timeline", (ctx) => {
|
|
10
|
-
const services = ctx.services;
|
|
11
|
-
ctx.sendJson(200, { items: services.getTimeline() });
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
exports.registerTimelineRoutes = registerTimelineRoutes;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serveStatic = void 0;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
const MIME = {
|
|
7
|
-
".html": "text/html; charset=utf-8",
|
|
8
|
-
".css": "text/css; charset=utf-8",
|
|
9
|
-
".js": "application/javascript; charset=utf-8",
|
|
10
|
-
".json": "application/json; charset=utf-8",
|
|
11
|
-
".svg": "image/svg+xml",
|
|
12
|
-
".png": "image/png",
|
|
13
|
-
".ico": "image/x-icon",
|
|
14
|
-
".woff": "font/woff",
|
|
15
|
-
".woff2": "font/woff2",
|
|
16
|
-
};
|
|
17
|
-
const resolveWebDist = () => {
|
|
18
|
-
// dist/src/server/serve-static.js → ../../../web/dist
|
|
19
|
-
return (0, node_path_1.join)(__dirname, "..", "..", "..", "web", "dist");
|
|
20
|
-
};
|
|
21
|
-
const webDistRoot = resolveWebDist();
|
|
22
|
-
const serveStatic = (req, res) => {
|
|
23
|
-
if (!(0, node_fs_1.existsSync)(webDistRoot))
|
|
24
|
-
return false;
|
|
25
|
-
const url = new URL(req.url ?? "/", "http://localhost");
|
|
26
|
-
let filePath = (0, node_path_1.join)(webDistRoot, url.pathname === "/" ? "index.html" : url.pathname);
|
|
27
|
-
// If the path doesn't map to a real file, serve index.html (SPA fallback)
|
|
28
|
-
if (!(0, node_fs_1.existsSync)(filePath) || !filePath.startsWith(webDistRoot)) {
|
|
29
|
-
filePath = (0, node_path_1.join)(webDistRoot, "index.html");
|
|
30
|
-
}
|
|
31
|
-
if (!(0, node_fs_1.existsSync)(filePath))
|
|
32
|
-
return false;
|
|
33
|
-
const ext = (0, node_path_1.extname)(filePath);
|
|
34
|
-
const contentType = MIME[ext] ?? "application/octet-stream";
|
|
35
|
-
res.writeHead(200, {
|
|
36
|
-
"Content-Type": contentType,
|
|
37
|
-
"Cache-Control": ext === ".html" ? "no-cache" : "public, max-age=3600",
|
|
38
|
-
});
|
|
39
|
-
(0, node_fs_1.createReadStream)(filePath).pipe(res);
|
|
40
|
-
return true;
|
|
41
|
-
};
|
|
42
|
-
exports.serveStatic = serveStatic;
|