@jingyi0605/codingns 0.9.0 → 0.9.5
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/dist/public/assets/{AdaptiveButlerPage-B17QiMyT.js → AdaptiveButlerPage-kkJDsnCO.js} +2 -2
- package/dist/public/assets/{App-CFBwDUNA.js → App-DrNI9lWA.js} +6 -6
- package/dist/public/assets/{BootstrapPage-W5wU3BPh.js → BootstrapPage-QgVH5Mps.js} +1 -1
- package/dist/public/assets/{ConversationPage-DQLX1bUh.js → ConversationPage-DVk8VfIj.js} +1 -1
- package/dist/public/assets/{DesktopDetachPreviewPage-DTPeuAW-.js → DesktopDetachPreviewPage-BhfP0TpH.js} +1 -1
- package/dist/public/assets/{DesktopModal-6ii53_Y9.js → DesktopModal-DRmDrv0S.js} +1 -1
- package/dist/public/assets/DesktopWindowPage-DNbJXnSs.js +2 -0
- package/dist/public/assets/FileContextPanel---fLO4ve.js +1 -0
- package/dist/public/assets/GitSidebar-sXUE0TqT.js +6 -0
- package/dist/public/assets/MobileCreateSessionSheet-BftZ5pvb.js +1 -0
- package/dist/public/assets/{MobileSheet-opTWyRe1.js → MobileSheet-nw5SCa3N.js} +1 -1
- package/dist/public/assets/{MobileTopHeaderFrame-BbNON3Y4.js → MobileTopHeaderFrame-DH_D02Wy.js} +1 -1
- package/dist/public/assets/{MobileWorkspaceSwitcherHeader-BZEzPeMj.js → MobileWorkspaceSwitcherHeader-2K406G5p.js} +1 -1
- package/dist/public/assets/{PluginAccessOverview-mQDmAljp.js → PluginAccessOverview-BVJihw3D.js} +1 -1
- package/dist/public/assets/{PluginContainerPage-CcxUJpM4.js → PluginContainerPage-CR4vStvr.js} +1 -1
- package/dist/public/assets/{PluginDetailPage-D5--ACIt.js → PluginDetailPage-CrMX0Mnm.js} +1 -1
- package/dist/public/assets/{PluginsListPage-D_oJxYXT.js → PluginsListPage-FtIL71Yg.js} +1 -1
- package/dist/public/assets/{RelayConnectEntryPage-DROxpnkv.js → RelayConnectEntryPage-Bt1apX53.js} +1 -1
- package/dist/public/assets/{ServerSettingsModal-CUUOPqSe.js → ServerSettingsModal-D-guzPrI.js} +1 -1
- package/dist/public/assets/{SessionIndexPage-C2Jxh6Gp.js → SessionIndexPage-CX2FppcJ.js} +1 -1
- package/dist/public/assets/SettingsPage-BI2Olcvr.js +2 -0
- package/dist/public/assets/TerminalManagerPanel-B5MKGPy-.js +1 -0
- package/dist/public/assets/{TerminalPage-CwWyFDj8.js → TerminalPage-C2dTNGHK.js} +1 -1
- package/dist/public/assets/{TerminalRuntimeFallbackModal-CSVVbO8r.js → TerminalRuntimeFallbackModal-DAqOxFD8.js} +1 -1
- package/dist/public/assets/{ToolFilesPage-QBEY8oCf.js → ToolFilesPage-IsNwyE6T.js} +1 -1
- package/dist/public/assets/{ToolGitPage-BKoZ2l9v.js → ToolGitPage-BK1JBERN.js} +1 -1
- package/dist/public/assets/{ToolProcessesPage-BOH0ib4G.js → ToolProcessesPage-DwTYUQCK.js} +1 -1
- package/dist/public/assets/{ToolsHomePage-BcMZ3BCQ.js → ToolsHomePage-BLOy7lPg.js} +1 -1
- package/dist/public/assets/{WorkbenchLandingPage-B5zoppEl.js → WorkbenchLandingPage-CqZKR6EA.js} +1 -1
- package/dist/public/assets/WorkbenchLayout-CJHQtwuL.js +1022 -0
- package/dist/public/assets/{WorkbenchModal-NGmPgqaE.js → WorkbenchModal-BM-OeW-b.js} +1 -1
- package/dist/public/assets/WorkbenchShellRoute-2bKI6Q9k.js +1 -0
- package/dist/public/assets/WorkbenchShellRoute-BjuZD101.css +1 -0
- package/dist/public/assets/WorkspaceDebugDetailPage-BMsEN5iG.js +1 -0
- package/dist/public/assets/WorkspaceDetailPage-5H9Gosx2.js +1 -0
- package/dist/public/assets/WorkspaceHomePage-DQiXKgiP.js +1 -0
- package/dist/public/assets/{client-runtime-manager-DXbI9K1K.js → client-runtime-manager-CgPJq21V.js} +1 -1
- package/dist/public/assets/index-BARqMVSw.css +1 -0
- package/dist/public/assets/index-BUoNjVrY.js +50 -0
- package/dist/public/assets/{login-direct-candidate-resolver-DkKyFtQJ.js → login-direct-candidate-resolver-CGaxAXV8.js} +1 -1
- package/dist/public/assets/{plugin-permission-copy-CzN269Bk.js → plugin-permission-copy-BR9gWy8b.js} +1 -1
- package/dist/public/assets/{plugins-api-Bv9DHpLF.js → plugins-api-CdCsrG2e.js} +1 -1
- package/dist/public/assets/{preferences-service-D2ISL2Zz.js → preferences-service-lOhnlxzP.js} +1 -1
- package/dist/public/assets/{relay-entry-Bg0OisQy.js → relay-entry-CQpxTS8y.js} +1 -1
- package/dist/public/assets/{terminal-runtime-meta-C8t-CIDF.js → terminal-runtime-meta-oteTx66X.js} +1 -1
- package/dist/public/assets/useRegisteredDebugTemplates-Bu2ykZ6s.js +1 -0
- package/dist/public/assets/workbench-navigation-DlgXuFW2.js +1 -0
- package/dist/public/index.html +2 -2
- package/dist/server/config/env.d.ts +1 -0
- package/dist/server/config/env.js +3 -0
- package/dist/server/config/env.js.map +1 -1
- package/dist/server/modules/affairs-indexer/core/src/parser/parser-skip-repository.js.map +1 -1
- package/dist/server/modules/affairs-indexer/core/src/repositories/catalog-write-repository.js.map +1 -1
- package/dist/server/modules/affairs-indexer/core/src/sqlite/detect-catalog-schema.js +2 -2
- package/dist/server/modules/affairs-indexer/core/src/sqlite/detect-catalog-schema.js.map +1 -1
- package/dist/server/modules/affairs-indexer/core/src/sqlite/open-database.d.ts +20 -3
- package/dist/server/modules/affairs-indexer/core/src/sqlite/open-database.js +3 -3
- package/dist/server/modules/affairs-indexer/core/src/sqlite/open-database.js.map +1 -1
- package/dist/server/modules/butler/assistant-sandbox-cleanup-scheduler.d.ts +32 -0
- package/dist/server/modules/butler/assistant-sandbox-cleanup-scheduler.js +93 -0
- package/dist/server/modules/butler/assistant-sandbox-cleanup-scheduler.js.map +1 -0
- package/dist/server/modules/butler/assistant-sandbox-service.d.ts +69 -0
- package/dist/server/modules/butler/assistant-sandbox-service.js +399 -0
- package/dist/server/modules/butler/assistant-sandbox-service.js.map +1 -0
- package/dist/server/modules/butler/butler-follow-up-service.d.ts +3 -0
- package/dist/server/modules/butler/butler-follow-up-service.js +11 -1
- package/dist/server/modules/butler/butler-follow-up-service.js.map +1 -1
- package/dist/server/modules/butler/butler-inbox-service.d.ts +3 -0
- package/dist/server/modules/butler/butler-inbox-service.js +14 -2
- package/dist/server/modules/butler/butler-inbox-service.js.map +1 -1
- package/dist/server/modules/butler/butler-session-service.d.ts +3 -0
- package/dist/server/modules/butler/butler-session-service.js +18 -0
- package/dist/server/modules/butler/butler-session-service.js.map +1 -1
- package/dist/server/modules/channels/wechat-claw-client.d.ts +51 -0
- package/dist/server/modules/channels/wechat-claw-client.js +245 -0
- package/dist/server/modules/channels/wechat-claw-client.js.map +1 -0
- package/dist/server/modules/file/file-controller.d.ts +11 -2
- package/dist/server/modules/file/file-controller.js +404 -17
- package/dist/server/modules/file/file-controller.js.map +1 -1
- package/dist/server/modules/file/file-search-service.js +200 -12
- package/dist/server/modules/file/file-search-service.js.map +1 -1
- package/dist/server/modules/file/runtime/codingns-workspace-bridge.js +18 -5
- package/dist/server/modules/file/workspace-file-bridge-service.d.ts +9 -0
- package/dist/server/modules/file/workspace-file-bridge-service.js +3 -0
- package/dist/server/modules/file/workspace-file-bridge-service.js.map +1 -1
- package/dist/server/modules/file/workspace-file-bridge-watch-service.d.ts +9 -0
- package/dist/server/modules/file/workspace-file-bridge-watch-service.js +28 -0
- package/dist/server/modules/file/workspace-file-bridge-watch-service.js.map +1 -1
- package/dist/server/modules/tasks/task-types.d.ts +1 -0
- package/dist/server/modules/tasks/task-types.js +1 -0
- package/dist/server/modules/tasks/task-types.js.map +1 -1
- package/dist/server/modules/workbench/affairs-assistant-session-snapshot-service.d.ts +1 -1
- package/dist/server/modules/workbench/affairs-assistant-session-snapshot-service.js +22 -5
- package/dist/server/modules/workbench/affairs-assistant-session-snapshot-service.js.map +1 -1
- package/dist/server/modules/workbench/workbench-controller.d.ts +5 -0
- package/dist/server/modules/workbench/workbench-controller.js +20 -0
- package/dist/server/modules/workbench/workbench-controller.js.map +1 -1
- package/dist/server/modules/workbench/workbench-service.d.ts +6 -6
- package/dist/server/modules/workbench/workbench-service.js +33 -36
- package/dist/server/modules/workbench/workbench-service.js.map +1 -1
- package/dist/server/modules/workspace/affairs-library-controller.d.ts +8 -0
- package/dist/server/modules/workspace/affairs-library-controller.js +11 -0
- package/dist/server/modules/workspace/affairs-library-controller.js.map +1 -1
- package/dist/server/modules/workspace/affairs-library-preview-link-service.d.ts +6 -0
- package/dist/server/modules/workspace/affairs-library-preview-link-service.js +12 -2
- package/dist/server/modules/workspace/affairs-library-preview-link-service.js.map +1 -1
- package/dist/server/modules/workspace/affairs-library-service.d.ts +9 -0
- package/dist/server/modules/workspace/affairs-library-service.js +182 -42
- package/dist/server/modules/workspace/affairs-library-service.js.map +1 -1
- package/dist/server/modules/workspace/affairs-lightweight-session-controller.d.ts +8 -0
- package/dist/server/modules/workspace/affairs-lightweight-session-controller.js +55 -8
- package/dist/server/modules/workspace/affairs-lightweight-session-controller.js.map +1 -1
- package/dist/server/modules/workspace/affairs-lightweight-session-service.d.ts +13 -0
- package/dist/server/modules/workspace/affairs-lightweight-session-service.js +167 -21
- package/dist/server/modules/workspace/affairs-lightweight-session-service.js.map +1 -1
- package/dist/server/modules/workspace/affairs-tag-controller.d.ts +3 -0
- package/dist/server/modules/workspace/affairs-tag-controller.js +5 -0
- package/dist/server/modules/workspace/affairs-tag-controller.js.map +1 -1
- package/dist/server/modules/workspace/affairs-tag-service.d.ts +22 -1
- package/dist/server/modules/workspace/affairs-tag-service.js +41 -2
- package/dist/server/modules/workspace/affairs-tag-service.js.map +1 -1
- package/dist/server/modules/workspace/teable-api-client.d.ts +118 -0
- package/dist/server/modules/workspace/teable-api-client.js +142 -0
- package/dist/server/modules/workspace/teable-api-client.js.map +1 -0
- package/dist/server/modules/workspace/teable-catalog-controller.d.ts +18 -0
- package/dist/server/modules/workspace/teable-catalog-controller.js +17 -0
- package/dist/server/modules/workspace/teable-catalog-controller.js.map +1 -0
- package/dist/server/modules/workspace/teable-catalog-service.d.ts +36 -0
- package/dist/server/modules/workspace/teable-catalog-service.js +124 -0
- package/dist/server/modules/workspace/teable-catalog-service.js.map +1 -0
- package/dist/server/modules/workspace/teable-credential-service.d.ts +8 -0
- package/dist/server/modules/workspace/teable-credential-service.js +37 -0
- package/dist/server/modules/workspace/teable-credential-service.js.map +1 -0
- package/dist/server/modules/workspace/teable-field-mapping-controller.d.ts +25 -0
- package/dist/server/modules/workspace/teable-field-mapping-controller.js +31 -0
- package/dist/server/modules/workspace/teable-field-mapping-controller.js.map +1 -0
- package/dist/server/modules/workspace/teable-field-mapping-service.d.ts +38 -0
- package/dist/server/modules/workspace/teable-field-mapping-service.js +215 -0
- package/dist/server/modules/workspace/teable-field-mapping-service.js.map +1 -0
- package/dist/server/modules/workspace/teable-global-binding-controller.d.ts +22 -0
- package/dist/server/modules/workspace/teable-global-binding-controller.js +25 -0
- package/dist/server/modules/workspace/teable-global-binding-controller.js.map +1 -0
- package/dist/server/modules/workspace/teable-global-binding-service.d.ts +35 -0
- package/dist/server/modules/workspace/teable-global-binding-service.js +151 -0
- package/dist/server/modules/workspace/teable-global-binding-service.js.map +1 -0
- package/dist/server/modules/workspace/teable-mirror-sync-controller.d.ts +29 -0
- package/dist/server/modules/workspace/teable-mirror-sync-controller.js +50 -0
- package/dist/server/modules/workspace/teable-mirror-sync-controller.js.map +1 -0
- package/dist/server/modules/workspace/teable-mirror-sync-service.d.ts +157 -0
- package/dist/server/modules/workspace/teable-mirror-sync-service.js +917 -0
- package/dist/server/modules/workspace/teable-mirror-sync-service.js.map +1 -0
- package/dist/server/modules/workspace/teable-runtime-controller.d.ts +58 -0
- package/dist/server/modules/workspace/teable-runtime-controller.js +60 -0
- package/dist/server/modules/workspace/teable-runtime-controller.js.map +1 -0
- package/dist/server/modules/workspace/teable-runtime-service.d.ts +96 -0
- package/dist/server/modules/workspace/teable-runtime-service.js +362 -0
- package/dist/server/modules/workspace/teable-runtime-service.js.map +1 -0
- package/dist/server/modules/workspace/teable-workbench-sync-config-controller.d.ts +22 -0
- package/dist/server/modules/workspace/teable-workbench-sync-config-controller.js +20 -0
- package/dist/server/modules/workspace/teable-workbench-sync-config-controller.js.map +1 -0
- package/dist/server/modules/workspace/teable-workbench-sync-config-service.d.ts +22 -0
- package/dist/server/modules/workspace/teable-workbench-sync-config-service.js +159 -0
- package/dist/server/modules/workspace/teable-workbench-sync-config-service.js.map +1 -0
- package/dist/server/routes/affairs.d.ts +9 -1
- package/dist/server/routes/affairs.js +120 -1
- package/dist/server/routes/affairs.js.map +1 -1
- package/dist/server/routes/workbench.js +15 -0
- package/dist/server/routes/workbench.js.map +1 -1
- package/dist/server/routes/workspaces.js +51 -41
- package/dist/server/routes/workspaces.js.map +1 -1
- package/dist/server/server/create-server.d.ts +14 -0
- package/dist/server/server/create-server.js +73 -7
- package/dist/server/server/create-server.js.map +1 -1
- package/dist/server/storage/repositories/assistant-sandbox-workspace-repository.d.ts +18 -0
- package/dist/server/storage/repositories/assistant-sandbox-workspace-repository.js +191 -0
- package/dist/server/storage/repositories/assistant-sandbox-workspace-repository.js.map +1 -0
- package/dist/server/storage/repositories/user-affairs-library-setting-repository.js +8 -5
- package/dist/server/storage/repositories/user-affairs-library-setting-repository.js.map +1 -1
- package/dist/server/storage/repositories/user-teable-credential-repository.d.ts +9 -0
- package/dist/server/storage/repositories/user-teable-credential-repository.js +45 -0
- package/dist/server/storage/repositories/user-teable-credential-repository.js.map +1 -0
- package/dist/server/storage/repositories/user-teable-field-mapping-repository.d.ts +10 -0
- package/dist/server/storage/repositories/user-teable-field-mapping-repository.js +69 -0
- package/dist/server/storage/repositories/user-teable-field-mapping-repository.js.map +1 -0
- package/dist/server/storage/repositories/user-teable-global-setting-repository.d.ts +8 -0
- package/dist/server/storage/repositories/user-teable-global-setting-repository.js +52 -0
- package/dist/server/storage/repositories/user-teable-global-setting-repository.js.map +1 -0
- package/dist/server/storage/repositories/user-teable-mirror-record-mapping-repository.d.ts +9 -0
- package/dist/server/storage/repositories/user-teable-mirror-record-mapping-repository.js +66 -0
- package/dist/server/storage/repositories/user-teable-mirror-record-mapping-repository.js.map +1 -0
- package/dist/server/storage/repositories/user-teable-mirror-table-binding-repository.d.ts +9 -0
- package/dist/server/storage/repositories/user-teable-mirror-table-binding-repository.js +67 -0
- package/dist/server/storage/repositories/user-teable-mirror-table-binding-repository.js.map +1 -0
- package/dist/server/storage/repositories/user-teable-sync-log-repository.d.ts +14 -0
- package/dist/server/storage/repositories/user-teable-sync-log-repository.js +97 -0
- package/dist/server/storage/repositories/user-teable-sync-log-repository.js.map +1 -0
- package/dist/server/storage/repositories/user-teable-workbench-sync-config-repository.d.ts +8 -0
- package/dist/server/storage/repositories/user-teable-workbench-sync-config-repository.js +55 -0
- package/dist/server/storage/repositories/user-teable-workbench-sync-config-repository.js.map +1 -0
- package/dist/server/storage/sqlite/client.js +404 -1
- package/dist/server/storage/sqlite/client.js.map +1 -1
- package/dist/server/storage/sqlite/schema.sql +167 -1
- package/dist/server/types/domain.d.ts +106 -0
- package/node_modules/@codingns/session-sync-core/dist/sqlite/node-sqlite.d.ts +22 -3
- package/node_modules/@codingns/session-sync-core/dist/sqlite/node-sqlite.js +29 -2
- package/node_modules/@codingns/session-sync-core/dist/sqlite/node-sqlite.js.map +1 -1
- package/node_modules/@codingns/session-sync-core/package.json +3 -1
- package/package.json +1 -1
- package/dist/public/assets/DesktopWindowPage-D0blSuKd.js +0 -2
- package/dist/public/assets/FileContextPanel-BrKO8Xt6.js +0 -1
- package/dist/public/assets/GitSidebar-BdwiDtOr.js +0 -6
- package/dist/public/assets/MobileCreateSessionSheet-Cx_dBiBb.js +0 -1
- package/dist/public/assets/SettingsPage-BlAZCHsy.js +0 -2
- package/dist/public/assets/TerminalManagerPanel-CjzbiWjl.js +0 -1
- package/dist/public/assets/WorkbenchLayout-CikJBS62.js +0 -1019
- package/dist/public/assets/WorkbenchShellRoute-BbbSOiZw.js +0 -1
- package/dist/public/assets/WorkbenchShellRoute-DT3VMjWD.css +0 -1
- package/dist/public/assets/WorkspaceDebugDetailPage-CVivdPx5.js +0 -1
- package/dist/public/assets/WorkspaceDetailPage-DgOSjscR.js +0 -1
- package/dist/public/assets/WorkspaceHomePage-HPa7M_Vh.js +0 -1
- package/dist/public/assets/index-BxJPQpFM.css +0 -1
- package/dist/public/assets/index-CeXGOT_T.js +0 -50
- package/dist/public/assets/useRegisteredDebugTemplates-Bol3NVfN.js +0 -1
- package/dist/public/assets/workbench-navigation-B7IjRQd8.js +0 -1
|
@@ -6,12 +6,20 @@ interface WorkspaceParams {
|
|
|
6
6
|
interface LightweightSessionParams extends WorkspaceParams {
|
|
7
7
|
sessionId: string;
|
|
8
8
|
}
|
|
9
|
+
interface AffairsLightweightAttachmentBody {
|
|
10
|
+
kind?: "image" | "file";
|
|
11
|
+
fileName?: string | null;
|
|
12
|
+
mimeType?: string | null;
|
|
13
|
+
fileSize?: number | null;
|
|
14
|
+
contentBase64?: string | null;
|
|
15
|
+
}
|
|
9
16
|
interface AffairsLightweightStartBody {
|
|
10
17
|
provider?: string;
|
|
11
18
|
content?: string;
|
|
12
19
|
clientRequestId?: string | null;
|
|
13
20
|
model?: string | null;
|
|
14
21
|
reasoningLevel?: string | null;
|
|
22
|
+
attachments?: AffairsLightweightAttachmentBody[] | null;
|
|
15
23
|
}
|
|
16
24
|
interface AffairsLightweightSendBody extends AffairsLightweightStartBody {
|
|
17
25
|
}
|
|
@@ -12,6 +12,45 @@ function requireText(value, field, detail) {
|
|
|
12
12
|
}
|
|
13
13
|
return normalized;
|
|
14
14
|
}
|
|
15
|
+
function normalizeAttachments(input) {
|
|
16
|
+
if (!Array.isArray(input.attachments)) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
return input.attachments.map((attachment, index) => {
|
|
20
|
+
const kind = attachment?.kind === "image" ? "image" : "file";
|
|
21
|
+
const fileName = attachment?.fileName?.trim() ?? "";
|
|
22
|
+
const mimeType = attachment?.mimeType?.trim() ?? "";
|
|
23
|
+
const contentBase64 = attachment?.contentBase64?.trim() ?? "";
|
|
24
|
+
const fileSize = Number(attachment?.fileSize ?? 0);
|
|
25
|
+
if (!fileName || !mimeType || !contentBase64 || !Number.isFinite(fileSize) || fileSize <= 0) {
|
|
26
|
+
throw new AppError({
|
|
27
|
+
statusCode: 400,
|
|
28
|
+
errorCode: "INVALID_INPUT",
|
|
29
|
+
detail: `attachments[${index}] 缺少有效的附件字段`,
|
|
30
|
+
field: "attachments"
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
kind,
|
|
35
|
+
fileName,
|
|
36
|
+
mimeType,
|
|
37
|
+
fileSize,
|
|
38
|
+
contentBase64
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function requireTextOrAttachments(value, attachments, field, detail) {
|
|
43
|
+
const normalized = value?.trim() ?? "";
|
|
44
|
+
if (!normalized && attachments.length === 0) {
|
|
45
|
+
throw new AppError({
|
|
46
|
+
statusCode: 400,
|
|
47
|
+
errorCode: "INVALID_INPUT",
|
|
48
|
+
detail,
|
|
49
|
+
field
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return normalized;
|
|
53
|
+
}
|
|
15
54
|
export class AffairsLightweightSessionController {
|
|
16
55
|
affairsLightweightSessionService;
|
|
17
56
|
constructor(affairsLightweightSessionService) {
|
|
@@ -47,7 +86,8 @@ export class AffairsLightweightSessionController {
|
|
|
47
86
|
reply.status(204).send();
|
|
48
87
|
};
|
|
49
88
|
startSession = async (request, reply) => {
|
|
50
|
-
const
|
|
89
|
+
const attachments = normalizeAttachments(request.body);
|
|
90
|
+
const content = requireTextOrAttachments(request.body.content, attachments, "content", "事务轻量会话必须提供首条消息或附件");
|
|
51
91
|
const provider = requireText(request.body.provider, "provider", "事务轻量会话必须提供 provider");
|
|
52
92
|
reply.status(201).send(await this.affairsLightweightSessionService.startSession({
|
|
53
93
|
workspaceId: request.params.workspaceId,
|
|
@@ -56,11 +96,13 @@ export class AffairsLightweightSessionController {
|
|
|
56
96
|
content,
|
|
57
97
|
clientRequestId: request.body.clientRequestId ?? null,
|
|
58
98
|
model: request.body.model ?? null,
|
|
59
|
-
reasoningLevel: request.body.reasoningLevel ?? null
|
|
99
|
+
reasoningLevel: request.body.reasoningLevel ?? null,
|
|
100
|
+
attachments
|
|
60
101
|
}));
|
|
61
102
|
};
|
|
62
103
|
startSessionStream = async (request, reply) => {
|
|
63
|
-
const
|
|
104
|
+
const attachments = normalizeAttachments(request.body);
|
|
105
|
+
const content = requireTextOrAttachments(request.body.content, attachments, "content", "事务轻量会话必须提供首条消息或附件");
|
|
64
106
|
const provider = requireText(request.body.provider, "provider", "事务轻量会话必须提供 provider");
|
|
65
107
|
reply.hijack();
|
|
66
108
|
reply.raw.writeHead(200, {
|
|
@@ -77,7 +119,8 @@ export class AffairsLightweightSessionController {
|
|
|
77
119
|
content,
|
|
78
120
|
clientRequestId: request.body.clientRequestId ?? null,
|
|
79
121
|
model: request.body.model ?? null,
|
|
80
|
-
reasoningLevel: request.body.reasoningLevel ?? null
|
|
122
|
+
reasoningLevel: request.body.reasoningLevel ?? null,
|
|
123
|
+
attachments
|
|
81
124
|
}, async (event) => {
|
|
82
125
|
reply.raw.write(`${JSON.stringify(event)}\n`);
|
|
83
126
|
});
|
|
@@ -96,7 +139,8 @@ export class AffairsLightweightSessionController {
|
|
|
96
139
|
}
|
|
97
140
|
};
|
|
98
141
|
sendMessage = async (request, reply) => {
|
|
99
|
-
const
|
|
142
|
+
const attachments = normalizeAttachments(request.body);
|
|
143
|
+
const content = requireTextOrAttachments(request.body.content, attachments, "content", "事务轻量会话发送消息必须提供 content 或附件");
|
|
100
144
|
reply.status(201).send(await this.affairsLightweightSessionService.sendMessage({
|
|
101
145
|
workspaceId: request.params.workspaceId,
|
|
102
146
|
userId: requireUserId(request),
|
|
@@ -104,11 +148,13 @@ export class AffairsLightweightSessionController {
|
|
|
104
148
|
content,
|
|
105
149
|
clientRequestId: request.body.clientRequestId ?? null,
|
|
106
150
|
model: request.body.model ?? null,
|
|
107
|
-
reasoningLevel: request.body.reasoningLevel ?? null
|
|
151
|
+
reasoningLevel: request.body.reasoningLevel ?? null,
|
|
152
|
+
attachments
|
|
108
153
|
}));
|
|
109
154
|
};
|
|
110
155
|
sendMessageStream = async (request, reply) => {
|
|
111
|
-
const
|
|
156
|
+
const attachments = normalizeAttachments(request.body);
|
|
157
|
+
const content = requireTextOrAttachments(request.body.content, attachments, "content", "事务轻量会话发送消息必须提供 content 或附件");
|
|
112
158
|
reply.hijack();
|
|
113
159
|
reply.raw.writeHead(200, {
|
|
114
160
|
"content-type": "application/x-ndjson; charset=utf-8",
|
|
@@ -124,7 +170,8 @@ export class AffairsLightweightSessionController {
|
|
|
124
170
|
content,
|
|
125
171
|
clientRequestId: request.body.clientRequestId ?? null,
|
|
126
172
|
model: request.body.model ?? null,
|
|
127
|
-
reasoningLevel: request.body.reasoningLevel ?? null
|
|
173
|
+
reasoningLevel: request.body.reasoningLevel ?? null,
|
|
174
|
+
attachments
|
|
128
175
|
}, async (event) => {
|
|
129
176
|
reply.raw.write(`${JSON.stringify(event)}\n`);
|
|
130
177
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"affairs-lightweight-session-controller.js","sourceRoot":"","sources":["../../../../src/modules/workspace/affairs-lightweight-session-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"affairs-lightweight-session-controller.js","sourceRoot":"","sources":["../../../../src/modules/workspace/affairs-lightweight-session-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,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I;gBACnD,WAAW;aACZ,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;gBACjB,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAChD,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;gBAC7B,MAAM,MAAM,GAAG,KAAK,YAAY,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC;gBACxE,MAAM,SAAS,GAAG,KAAK,YAAY,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,4BAA4B,CAAC;gBAC7F,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;YAC/E,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;gBAC7B,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC,CAAC;CACH"}
|
|
@@ -37,6 +37,14 @@ export interface AffairsLightweightSessionDocument {
|
|
|
37
37
|
session: AffairsLightweightSessionSummary;
|
|
38
38
|
messages: HistoryPage["messages"];
|
|
39
39
|
}
|
|
40
|
+
export interface AffairsLightweightAttachmentInput {
|
|
41
|
+
id?: string | null;
|
|
42
|
+
kind: "image" | "file";
|
|
43
|
+
fileName: string;
|
|
44
|
+
mimeType: string;
|
|
45
|
+
fileSize: number;
|
|
46
|
+
contentBase64: string;
|
|
47
|
+
}
|
|
40
48
|
export interface StartAffairsLightweightSessionInput {
|
|
41
49
|
workspaceId: string;
|
|
42
50
|
userId: string;
|
|
@@ -45,6 +53,7 @@ export interface StartAffairsLightweightSessionInput {
|
|
|
45
53
|
clientRequestId?: string | null;
|
|
46
54
|
model?: string | null;
|
|
47
55
|
reasoningLevel?: string | null;
|
|
56
|
+
attachments?: AffairsLightweightAttachmentInput[];
|
|
48
57
|
}
|
|
49
58
|
export interface SendAffairsLightweightSessionMessageInput {
|
|
50
59
|
workspaceId: string;
|
|
@@ -54,6 +63,7 @@ export interface SendAffairsLightweightSessionMessageInput {
|
|
|
54
63
|
clientRequestId?: string | null;
|
|
55
64
|
model?: string | null;
|
|
56
65
|
reasoningLevel?: string | null;
|
|
66
|
+
attachments?: AffairsLightweightAttachmentInput[];
|
|
57
67
|
}
|
|
58
68
|
export interface AffairsLightweightSessionTurnResult {
|
|
59
69
|
session: AffairsLightweightSessionSummary;
|
|
@@ -94,7 +104,9 @@ export declare class AffairsLightweightSessionService {
|
|
|
94
104
|
private readonly hostDataRootDir;
|
|
95
105
|
private readonly sessionLocks;
|
|
96
106
|
private readonly sessionDocumentCache;
|
|
107
|
+
private teableMirrorSyncNotifier;
|
|
97
108
|
constructor(hostDataRootDir: string);
|
|
109
|
+
configureTeableMirrorSyncNotifier(notifier: (userId: string, reason: string) => void): void;
|
|
98
110
|
listSessions(workspaceId: string, userId: string): Promise<AffairsLightweightSessionSummary[]>;
|
|
99
111
|
getSession(workspaceId: string, sessionId: string, userId: string): Promise<AffairsLightweightSessionSummary>;
|
|
100
112
|
readMessages(workspaceId: string, sessionId: string, userId: string): Promise<HistoryPage>;
|
|
@@ -122,6 +134,7 @@ export declare class AffairsLightweightSessionService {
|
|
|
122
134
|
private updateSessionSummary;
|
|
123
135
|
private waitForSessionIdle;
|
|
124
136
|
private cacheSessionDocument;
|
|
137
|
+
private notifyTeableSessionChanged;
|
|
125
138
|
private readCachedSessionDocument;
|
|
126
139
|
private readOpenAiRuntimeConfig;
|
|
127
140
|
private readAnthropicRuntimeConfig;
|
|
@@ -22,9 +22,13 @@ export class AffairsLightweightSessionService {
|
|
|
22
22
|
hostDataRootDir;
|
|
23
23
|
sessionLocks = new Map();
|
|
24
24
|
sessionDocumentCache = new Map();
|
|
25
|
+
teableMirrorSyncNotifier = null;
|
|
25
26
|
constructor(hostDataRootDir) {
|
|
26
27
|
this.hostDataRootDir = hostDataRootDir;
|
|
27
28
|
}
|
|
29
|
+
configureTeableMirrorSyncNotifier(notifier) {
|
|
30
|
+
this.teableMirrorSyncNotifier = notifier;
|
|
31
|
+
}
|
|
28
32
|
async listSessions(workspaceId, userId) {
|
|
29
33
|
const workspaceDir = this.resolveWorkspaceDir(workspaceId);
|
|
30
34
|
const entries = await safeReadDir(workspaceDir);
|
|
@@ -85,27 +89,28 @@ export class AffairsLightweightSessionService {
|
|
|
85
89
|
return this.updateSessionSummary(workspaceId, sessionId, userId, (session) => ({
|
|
86
90
|
...session,
|
|
87
91
|
title: normalizedTitle
|
|
88
|
-
}));
|
|
92
|
+
}), "session_title_renamed");
|
|
89
93
|
}
|
|
90
94
|
async updateSessionArchiveState(workspaceId, sessionId, userId, archived) {
|
|
91
95
|
await this.waitForSessionIdle(sessionId);
|
|
92
96
|
return this.updateSessionSummary(workspaceId, sessionId, userId, (session) => ({
|
|
93
97
|
...session,
|
|
94
98
|
isArchived: archived
|
|
95
|
-
}));
|
|
99
|
+
}), "session_archive_changed");
|
|
96
100
|
}
|
|
97
101
|
async updateSessionFavoriteState(workspaceId, sessionId, userId, favorite) {
|
|
98
102
|
await this.waitForSessionIdle(sessionId);
|
|
99
103
|
return this.updateSessionSummary(workspaceId, sessionId, userId, (session) => ({
|
|
100
104
|
...session,
|
|
101
105
|
isFavorite: favorite
|
|
102
|
-
}));
|
|
106
|
+
}), "session_favorite_changed");
|
|
103
107
|
}
|
|
104
108
|
async deleteSession(workspaceId, sessionId, userId) {
|
|
105
109
|
await this.waitForSessionIdle(sessionId);
|
|
106
110
|
await this.requireSessionDocument(workspaceId, sessionId, userId);
|
|
107
111
|
await fs.unlink(this.resolveSessionFilePath(workspaceId, sessionId));
|
|
108
112
|
this.sessionDocumentCache.delete(sessionId);
|
|
113
|
+
this.notifyTeableSessionChanged(userId, `session_deleted:${workspaceId}:${sessionId}`);
|
|
109
114
|
}
|
|
110
115
|
async startSession(input) {
|
|
111
116
|
const sessionId = createId();
|
|
@@ -151,6 +156,7 @@ export class AffairsLightweightSessionService {
|
|
|
151
156
|
messages: []
|
|
152
157
|
};
|
|
153
158
|
await this.writeSessionDocument(document);
|
|
159
|
+
this.notifyTeableSessionChanged(input.userId, `session_started:${input.workspaceId}:${sessionId}`);
|
|
154
160
|
return this.runTurn(document, {
|
|
155
161
|
workspaceId: input.workspaceId,
|
|
156
162
|
userId: input.userId,
|
|
@@ -158,7 +164,8 @@ export class AffairsLightweightSessionService {
|
|
|
158
164
|
content: input.content,
|
|
159
165
|
clientRequestId,
|
|
160
166
|
model: input.model ?? null,
|
|
161
|
-
reasoningLevel: input.reasoningLevel ?? null
|
|
167
|
+
reasoningLevel: input.reasoningLevel ?? null,
|
|
168
|
+
attachments: input.attachments ?? []
|
|
162
169
|
});
|
|
163
170
|
}
|
|
164
171
|
async sendMessage(input) {
|
|
@@ -219,7 +226,8 @@ export class AffairsLightweightSessionService {
|
|
|
219
226
|
content: input.content,
|
|
220
227
|
clientRequestId,
|
|
221
228
|
model: input.model ?? null,
|
|
222
|
-
reasoningLevel: input.reasoningLevel ?? null
|
|
229
|
+
reasoningLevel: input.reasoningLevel ?? null,
|
|
230
|
+
attachments: input.attachments ?? []
|
|
223
231
|
}, onEvent);
|
|
224
232
|
}
|
|
225
233
|
async sendMessageStream(input, onEvent) {
|
|
@@ -258,7 +266,8 @@ export class AffairsLightweightSessionService {
|
|
|
258
266
|
clientRequestId: input.clientRequestId,
|
|
259
267
|
sequence: document.messages.length + 1,
|
|
260
268
|
timestamp: now,
|
|
261
|
-
rawStoreRef: document.session.rawStoreRef
|
|
269
|
+
rawStoreRef: document.session.rawStoreRef,
|
|
270
|
+
attachments: normalizeLightweightMessageAttachments(input.attachments ?? [], input.clientRequestId)
|
|
262
271
|
});
|
|
263
272
|
const runningDocument = {
|
|
264
273
|
...document,
|
|
@@ -336,6 +345,7 @@ export class AffairsLightweightSessionService {
|
|
|
336
345
|
messages: [...workingDocument.messages, assistantMessage]
|
|
337
346
|
};
|
|
338
347
|
await this.writeSessionDocument(completedDocument);
|
|
348
|
+
this.notifyTeableSessionChanged(input.userId, `session_completed:${input.workspaceId}:${baseDocument.session.sessionId}`);
|
|
339
349
|
const result = {
|
|
340
350
|
session: completedDocument.session,
|
|
341
351
|
acceptedAt: now,
|
|
@@ -370,6 +380,7 @@ export class AffairsLightweightSessionService {
|
|
|
370
380
|
}
|
|
371
381
|
};
|
|
372
382
|
await this.writeSessionDocument(failedDocument);
|
|
383
|
+
this.notifyTeableSessionChanged(input.userId, `session_failed:${input.workspaceId}:${baseDocument.session.sessionId}`);
|
|
373
384
|
await onEvent?.({
|
|
374
385
|
type: "error",
|
|
375
386
|
errorCode: error instanceof AppError ? error.errorCode : "LIGHTWEIGHT_RUNTIME_FAILED",
|
|
@@ -401,7 +412,9 @@ export class AffairsLightweightSessionService {
|
|
|
401
412
|
const responsePayload = createOpenAiResponsesPayload({
|
|
402
413
|
model: runtime.model,
|
|
403
414
|
messages: document.messages,
|
|
404
|
-
reasoningLevel: input.reasoningLevel ?? null
|
|
415
|
+
reasoningLevel: input.reasoningLevel ?? null,
|
|
416
|
+
activeClientRequestId: input.clientRequestId,
|
|
417
|
+
attachments: normalizeLightweightRuntimeAttachments(input.attachments ?? [], input.clientRequestId)
|
|
405
418
|
});
|
|
406
419
|
const headers = {
|
|
407
420
|
"content-type": "application/json",
|
|
@@ -432,7 +445,9 @@ export class AffairsLightweightSessionService {
|
|
|
432
445
|
headers,
|
|
433
446
|
body: JSON.stringify(createOpenAiChatPayload({
|
|
434
447
|
model: runtime.model,
|
|
435
|
-
messages: document.messages
|
|
448
|
+
messages: document.messages,
|
|
449
|
+
activeClientRequestId: input.clientRequestId,
|
|
450
|
+
attachments: normalizeLightweightRuntimeAttachments(input.attachments ?? [], input.clientRequestId)
|
|
436
451
|
}))
|
|
437
452
|
}
|
|
438
453
|
});
|
|
@@ -452,10 +467,7 @@ export class AffairsLightweightSessionService {
|
|
|
452
467
|
}
|
|
453
468
|
async generateAnthropicResponseSync(document, input) {
|
|
454
469
|
const runtime = await this.readAnthropicRuntimeConfig(input.model?.trim() || null);
|
|
455
|
-
let messages = document.messages.map((message) => (
|
|
456
|
-
role: message.role,
|
|
457
|
-
content: message.content
|
|
458
|
-
}));
|
|
470
|
+
let messages = document.messages.map((message) => createAnthropicMessagePayload(message, input.clientRequestId, normalizeLightweightRuntimeAttachments(input.attachments ?? [], input.clientRequestId)));
|
|
459
471
|
let finalBody = null;
|
|
460
472
|
for (let index = 0; index < 4; index += 1) {
|
|
461
473
|
const response = await postJsonWithFallbacks({
|
|
@@ -522,7 +534,9 @@ export class AffairsLightweightSessionService {
|
|
|
522
534
|
...createOpenAiResponsesPayload({
|
|
523
535
|
model: runtime.model,
|
|
524
536
|
messages: document.messages,
|
|
525
|
-
reasoningLevel: input.reasoningLevel ?? null
|
|
537
|
+
reasoningLevel: input.reasoningLevel ?? null,
|
|
538
|
+
activeClientRequestId: input.clientRequestId,
|
|
539
|
+
attachments: normalizeLightweightRuntimeAttachments(input.attachments ?? [], input.clientRequestId)
|
|
526
540
|
}),
|
|
527
541
|
stream: true
|
|
528
542
|
};
|
|
@@ -552,7 +566,9 @@ export class AffairsLightweightSessionService {
|
|
|
552
566
|
body: JSON.stringify({
|
|
553
567
|
...createOpenAiChatPayload({
|
|
554
568
|
model: runtime.model,
|
|
555
|
-
messages: document.messages
|
|
569
|
+
messages: document.messages,
|
|
570
|
+
activeClientRequestId: input.clientRequestId,
|
|
571
|
+
attachments: normalizeLightweightRuntimeAttachments(input.attachments ?? [], input.clientRequestId)
|
|
556
572
|
}),
|
|
557
573
|
stream: true
|
|
558
574
|
})
|
|
@@ -580,10 +596,7 @@ export class AffairsLightweightSessionService {
|
|
|
580
596
|
model: runtime.model,
|
|
581
597
|
max_tokens: 2048,
|
|
582
598
|
system: LIGHTWEIGHT_SYSTEM_PROMPT,
|
|
583
|
-
messages: document.messages.map((message) => (
|
|
584
|
-
role: message.role,
|
|
585
|
-
content: message.content
|
|
586
|
-
})),
|
|
599
|
+
messages: document.messages.map((message) => createAnthropicMessagePayload(message, input.clientRequestId, normalizeLightweightRuntimeAttachments(input.attachments ?? [], input.clientRequestId))),
|
|
587
600
|
tools: [
|
|
588
601
|
{
|
|
589
602
|
type: "web_search_20250305",
|
|
@@ -653,13 +666,14 @@ export class AffairsLightweightSessionService {
|
|
|
653
666
|
await fs.rename(tempFilePath, filePath);
|
|
654
667
|
this.cacheSessionDocument(document);
|
|
655
668
|
}
|
|
656
|
-
async updateSessionSummary(workspaceId, sessionId, userId, updater) {
|
|
669
|
+
async updateSessionSummary(workspaceId, sessionId, userId, updater, reason) {
|
|
657
670
|
const document = await this.requireSessionDocument(workspaceId, sessionId, userId);
|
|
658
671
|
const nextSession = updater(document.session);
|
|
659
672
|
await this.writeSessionDocument({
|
|
660
673
|
...document,
|
|
661
674
|
session: nextSession
|
|
662
675
|
});
|
|
676
|
+
this.notifyTeableSessionChanged(userId, `${reason ?? "session_updated"}:${workspaceId}:${sessionId}`);
|
|
663
677
|
return nextSession;
|
|
664
678
|
}
|
|
665
679
|
async waitForSessionIdle(sessionId) {
|
|
@@ -675,6 +689,9 @@ export class AffairsLightweightSessionService {
|
|
|
675
689
|
}
|
|
676
690
|
this.sessionDocumentCache.set(sessionId, cloneSessionDocument(document));
|
|
677
691
|
}
|
|
692
|
+
notifyTeableSessionChanged(userId, reason) {
|
|
693
|
+
this.teableMirrorSyncNotifier?.(userId, reason);
|
|
694
|
+
}
|
|
678
695
|
readCachedSessionDocument(sessionId) {
|
|
679
696
|
const normalizedSessionId = sessionId?.trim() ?? "";
|
|
680
697
|
if (!normalizedSessionId) {
|
|
@@ -800,6 +817,7 @@ function createUserMessage(input) {
|
|
|
800
817
|
content: input.content,
|
|
801
818
|
toolCall: null,
|
|
802
819
|
timestamp: input.timestamp,
|
|
820
|
+
attachments: input.attachments ?? [],
|
|
803
821
|
sequence: input.sequence,
|
|
804
822
|
rawRef: `${input.rawStoreRef}#${input.clientRequestId}`
|
|
805
823
|
};
|
|
@@ -949,7 +967,7 @@ function createOpenAiResponsesPayload(input) {
|
|
|
949
967
|
},
|
|
950
968
|
...input.messages.map((message) => ({
|
|
951
969
|
role: message.role,
|
|
952
|
-
content: message.
|
|
970
|
+
content: createOpenAiResponsesMessageContent(message, input.activeClientRequestId, input.attachments ?? [])
|
|
953
971
|
}))
|
|
954
972
|
]
|
|
955
973
|
};
|
|
@@ -964,12 +982,140 @@ function createOpenAiChatPayload(input) {
|
|
|
964
982
|
},
|
|
965
983
|
...input.messages.map((message) => ({
|
|
966
984
|
role: message.role,
|
|
967
|
-
content: message.
|
|
985
|
+
content: createOpenAiChatMessageContent(message, input.activeClientRequestId, input.attachments ?? [])
|
|
968
986
|
}))
|
|
969
987
|
],
|
|
970
988
|
temperature: 0.2
|
|
971
989
|
};
|
|
972
990
|
}
|
|
991
|
+
function normalizeLightweightRuntimeAttachments(attachments, clientRequestId) {
|
|
992
|
+
return attachments.map((attachment, index) => {
|
|
993
|
+
const kind = attachment.kind === "image" ? "image" : "file";
|
|
994
|
+
return {
|
|
995
|
+
id: attachment.id?.trim() || `lightweight-attachment-${clientRequestId}-${index + 1}`,
|
|
996
|
+
kind,
|
|
997
|
+
fileName: attachment.fileName.trim(),
|
|
998
|
+
mimeType: attachment.mimeType.trim(),
|
|
999
|
+
fileSize: Number(attachment.fileSize),
|
|
1000
|
+
contentBase64: attachment.contentBase64.trim()
|
|
1001
|
+
};
|
|
1002
|
+
}).filter((attachment) => (attachment.fileName.length > 0
|
|
1003
|
+
&& attachment.mimeType.length > 0
|
|
1004
|
+
&& attachment.contentBase64.length > 0
|
|
1005
|
+
&& Number.isFinite(attachment.fileSize)
|
|
1006
|
+
&& attachment.fileSize > 0));
|
|
1007
|
+
}
|
|
1008
|
+
function normalizeLightweightMessageAttachments(attachments, clientRequestId) {
|
|
1009
|
+
return normalizeLightweightRuntimeAttachments(attachments, clientRequestId).map((attachment) => ({
|
|
1010
|
+
id: attachment.id,
|
|
1011
|
+
kind: attachment.kind,
|
|
1012
|
+
fileName: attachment.fileName,
|
|
1013
|
+
mimeType: attachment.mimeType,
|
|
1014
|
+
fileSize: attachment.fileSize
|
|
1015
|
+
}));
|
|
1016
|
+
}
|
|
1017
|
+
function shouldAttachRuntimePayloadToMessage(message, activeClientRequestId, attachments) {
|
|
1018
|
+
return message.role === "user"
|
|
1019
|
+
&& attachments.length > 0
|
|
1020
|
+
&& Boolean(activeClientRequestId?.trim())
|
|
1021
|
+
&& message.rawRef.includes(activeClientRequestId.trim());
|
|
1022
|
+
}
|
|
1023
|
+
function createOpenAiResponsesMessageContent(message, activeClientRequestId, attachments) {
|
|
1024
|
+
if (!shouldAttachRuntimePayloadToMessage(message, activeClientRequestId, attachments)) {
|
|
1025
|
+
return message.content;
|
|
1026
|
+
}
|
|
1027
|
+
return [
|
|
1028
|
+
{ type: "input_text", text: message.content.trim() || "请根据附件回答。" },
|
|
1029
|
+
...attachments.flatMap((attachment) => createOpenAiResponsesAttachmentBlocks(attachment))
|
|
1030
|
+
];
|
|
1031
|
+
}
|
|
1032
|
+
function createOpenAiChatMessageContent(message, activeClientRequestId, attachments) {
|
|
1033
|
+
if (!shouldAttachRuntimePayloadToMessage(message, activeClientRequestId, attachments)) {
|
|
1034
|
+
return message.content;
|
|
1035
|
+
}
|
|
1036
|
+
return [
|
|
1037
|
+
{ type: "text", text: message.content.trim() || "请根据附件回答。" },
|
|
1038
|
+
...attachments.flatMap((attachment) => createOpenAiChatAttachmentBlocks(attachment))
|
|
1039
|
+
];
|
|
1040
|
+
}
|
|
1041
|
+
function createAnthropicMessagePayload(message, activeClientRequestId, attachments) {
|
|
1042
|
+
if (!shouldAttachRuntimePayloadToMessage(message, activeClientRequestId, attachments)) {
|
|
1043
|
+
return {
|
|
1044
|
+
role: message.role,
|
|
1045
|
+
content: message.content
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
return {
|
|
1049
|
+
role: message.role,
|
|
1050
|
+
content: [
|
|
1051
|
+
{ type: "text", text: message.content.trim() || "请根据附件回答。" },
|
|
1052
|
+
...attachments.flatMap((attachment) => createAnthropicAttachmentBlocks(attachment))
|
|
1053
|
+
]
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
function createOpenAiResponsesAttachmentBlocks(attachment) {
|
|
1057
|
+
if (attachment.kind === "image") {
|
|
1058
|
+
return [{
|
|
1059
|
+
type: "input_image",
|
|
1060
|
+
image_url: buildAttachmentDataUrl(attachment)
|
|
1061
|
+
}];
|
|
1062
|
+
}
|
|
1063
|
+
return [{ type: "input_text", text: buildAttachmentTextBlock(attachment) }];
|
|
1064
|
+
}
|
|
1065
|
+
function createOpenAiChatAttachmentBlocks(attachment) {
|
|
1066
|
+
if (attachment.kind === "image") {
|
|
1067
|
+
return [{
|
|
1068
|
+
type: "image_url",
|
|
1069
|
+
image_url: { url: buildAttachmentDataUrl(attachment) }
|
|
1070
|
+
}];
|
|
1071
|
+
}
|
|
1072
|
+
return [{ type: "text", text: buildAttachmentTextBlock(attachment) }];
|
|
1073
|
+
}
|
|
1074
|
+
function createAnthropicAttachmentBlocks(attachment) {
|
|
1075
|
+
if (attachment.kind === "image") {
|
|
1076
|
+
return [{
|
|
1077
|
+
type: "image",
|
|
1078
|
+
source: {
|
|
1079
|
+
type: "base64",
|
|
1080
|
+
media_type: attachment.mimeType,
|
|
1081
|
+
data: attachment.contentBase64
|
|
1082
|
+
}
|
|
1083
|
+
}];
|
|
1084
|
+
}
|
|
1085
|
+
return [{ type: "text", text: buildAttachmentTextBlock(attachment) }];
|
|
1086
|
+
}
|
|
1087
|
+
function buildAttachmentDataUrl(attachment) {
|
|
1088
|
+
return `data:${attachment.mimeType};base64,${attachment.contentBase64}`;
|
|
1089
|
+
}
|
|
1090
|
+
function buildAttachmentTextBlock(attachment) {
|
|
1091
|
+
const decoded = decodeTextAttachment(attachment);
|
|
1092
|
+
const header = [
|
|
1093
|
+
`附件文件:${attachment.fileName}`,
|
|
1094
|
+
`类型:${attachment.mimeType}`,
|
|
1095
|
+
`大小:${attachment.fileSize} bytes`
|
|
1096
|
+
].join("\n");
|
|
1097
|
+
if (!decoded) {
|
|
1098
|
+
return `${header}\n内容:这个文件不是可直接读取的文本格式。请根据文件名、类型和用户问题判断;如果必须读取原始内容,请建议切换到 Agent 会话。`;
|
|
1099
|
+
}
|
|
1100
|
+
const preview = decoded.length > 20_000 ? `${decoded.slice(0, 20_000)}\n...(内容过长,已截断)` : decoded;
|
|
1101
|
+
return `${header}\n内容:\n${preview}`;
|
|
1102
|
+
}
|
|
1103
|
+
function decodeTextAttachment(attachment) {
|
|
1104
|
+
const mimeType = attachment.mimeType.toLowerCase();
|
|
1105
|
+
const fileName = attachment.fileName.toLowerCase();
|
|
1106
|
+
const looksText = mimeType.startsWith("text/")
|
|
1107
|
+
|| ["application/json", "application/xml", "application/javascript", "application/typescript", "application/x-yaml"].includes(mimeType)
|
|
1108
|
+
|| /\.(txt|md|csv|json|xml|yaml|yml|log|ts|tsx|js|jsx|css|html|sql)$/i.test(fileName);
|
|
1109
|
+
if (!looksText) {
|
|
1110
|
+
return null;
|
|
1111
|
+
}
|
|
1112
|
+
try {
|
|
1113
|
+
return Buffer.from(attachment.contentBase64, "base64").toString("utf8");
|
|
1114
|
+
}
|
|
1115
|
+
catch {
|
|
1116
|
+
return null;
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
973
1119
|
function extractOpenAiResponseText(body) {
|
|
974
1120
|
return normalizeText(body?.output_text)
|
|
975
1121
|
?? extractOpenAiOutputText(body?.output)
|