@cortex-agent/server 2026.9.14 → 2026.9.21
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 +3 -2
- package/defaults/config/hooks/08-agents-md-injector-post-tool.json +10 -0
- package/defaults/config/hooks/{10-cortex-md-injector-session-start.json → 10-agents-md-injector-session-start.json} +3 -3
- package/defaults/config/hooks/{CORTEX.md → AGENTS.md} +2 -2
- package/defaults/hooks/{CORTEX.md → AGENTS.md} +1 -1
- package/defaults/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
- package/defaults/hooks/cortex-hook-api.mjs +2 -2
- package/defaults/hooks/new-session-hook.mjs +2 -2
- package/defaults/hooks/rules-loader.mjs +2 -2
- package/defaults/hooks/status-md-guard.mjs +8 -8
- package/defaults/hooks/task-status-check.mjs +18 -76
- package/defaults/hooks/tasks-yaml-guard.mjs +2 -2
- package/defaults/plugins/cortex-commission/.claude-plugin/plugin.json +2 -2
- package/defaults/plugins/cortex-commission/plugin.json +2 -2
- package/defaults/plugins/cortex-commission/skills/commission/SKILL.md +3 -3
- package/defaults/plugins/cortex-feishu/skills/feishu-doc/SKILL.md +1 -1
- package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +2 -2
- package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +4 -4
- package/defaults/plugins/cortex-system/skills/task/SKILL.md +1 -1
- package/defaults/rules/{cortex-md.md → agents-md.md} +4 -4
- package/defaults/rules/decision-records.md +1 -1
- package/defaults/rules/meta-conventions.md +4 -4
- package/defaults/rules/mission-md.md +1 -1
- package/dist/agent-adapter/claude/adapter.d.ts +0 -6
- package/dist/agent-adapter/claude/adapter.js +0 -8
- package/dist/agent-adapter/claude/defaults.d.ts +10 -7
- package/dist/agent-adapter/claude/defaults.js +18 -16
- package/dist/agent-adapter/claude/hooks-builder.js +2 -2
- package/dist/agent-adapter/claude/spawn-args.d.ts +0 -3
- package/dist/agent-adapter/claude/spawn-args.js +20 -16
- package/dist/agent-adapter/claude/turn-machine.d.ts +11 -0
- package/dist/agent-adapter/claude/turn-machine.js +46 -5
- package/dist/agent-adapter/normalize/prompt-builder.d.ts +16 -1
- package/dist/agent-adapter/normalize/prompt-builder.js +24 -6
- package/dist/agent-adapter/pi/mcp-bridge-logic.d.ts +11 -2
- package/dist/agent-adapter/pi/mcp-bridge-logic.js +32 -1
- package/dist/agent-adapter/pi/mcp-bridge.js +16 -15
- package/dist/agent-adapter/pi/session-options.d.ts +0 -6
- package/dist/agent-adapter/pi/session-options.js +1 -8
- package/dist/agent-adapter/types.d.ts +1 -1
- package/dist/core/mcp-tool-gate.d.ts +3 -17
- package/dist/core/mcp-tool-gate.js +4 -19
- package/dist/core/media-types.d.ts +10 -0
- package/dist/core/media-types.js +34 -0
- package/dist/core/platform-settings-spec.js +1 -1
- package/dist/core/settings-spec.d.ts +22 -1
- package/dist/core/settings-spec.js +33 -2
- package/dist/core/types/agent-types.d.ts +3 -1
- package/dist/core/utils.d.ts +1 -1
- package/dist/core/utils.js +1 -1
- package/dist/domain/agents/config.d.ts +1 -1
- package/dist/domain/agents/config.js +1 -1
- package/dist/domain/agents/profile-switch.d.ts +1 -1
- package/dist/domain/agents/profile-switch.js +3 -5
- package/dist/domain/agents/subagent/runner.js +0 -1
- package/dist/domain/commissions/commission-draft.d.ts +58 -0
- package/dist/domain/commissions/commission-draft.js +87 -4
- package/dist/domain/commissions/commission-finalize.d.ts +8 -3
- package/dist/domain/commissions/commission-finalize.js +14 -0
- package/dist/domain/executions/registry.d.ts +1 -2
- package/dist/domain/executions/registry.js +0 -3
- package/dist/domain/mcp/bundled-server.js +4 -3
- package/dist/domain/mcp/feishu/file.js +37 -18
- package/dist/domain/mcp/feishu/types.d.ts +3 -0
- package/dist/domain/mcp/feishu-server.js +1 -1
- package/dist/domain/mcp/tools/{cortex-md.d.ts → agents-md.d.ts} +6 -6
- package/dist/domain/mcp/tools/{cortex-md.js → agents-md.js} +6 -6
- package/dist/domain/mcp/tools/commission-tools.d.ts +12 -1
- package/dist/domain/mcp/tools/commission-tools.js +68 -14
- package/dist/domain/mcp/tools/remote-file.d.ts +20 -0
- package/dist/domain/mcp/tools/remote-file.js +44 -0
- package/dist/domain/mcp/tools/slack.d.ts +2 -0
- package/dist/domain/mcp/tools/slack.js +22 -7
- package/dist/domain/mcp/tools/task-ops.js +5 -13
- package/dist/domain/mcp/tools/ui-file.js +23 -10
- package/dist/domain/mcp/tools/waitpoint.d.ts +3 -0
- package/dist/domain/mcp/tools/waitpoint.js +122 -0
- package/dist/domain/memory/agents-md-injector.d.ts +24 -0
- package/dist/domain/memory/{cortex-md-injector.js → agents-md-injector.js} +10 -7
- package/dist/domain/projects/project-store.d.ts +1 -1
- package/dist/domain/projects/project-store.js +3 -3
- package/dist/domain/remote/client-hot-reload.js +3 -1
- package/dist/domain/remote/client-manager.js +105 -126
- package/dist/domain/remote/client-ssh-tunnel.d.ts +16 -5
- package/dist/domain/remote/client-ssh-tunnel.js +12 -5
- package/dist/domain/remote/cortex-client-config.d.ts +1 -1
- package/dist/domain/remote/cortex-client-config.js +1 -1
- package/dist/domain/remote/device-file.d.ts +51 -0
- package/dist/domain/remote/device-file.js +193 -0
- package/dist/domain/remote/device-port.js +3 -0
- package/dist/domain/remote/reverse-stream.d.ts +18 -7
- package/dist/domain/remote/reverse-stream.js +19 -6
- package/dist/domain/runs/builders.js +0 -1
- package/dist/domain/runs/compact.js +0 -1
- package/dist/domain/runs/engine-spec.d.ts +11 -4
- package/dist/domain/runs/engine-spec.js +7 -4
- package/dist/domain/runs/prompt.js +16 -10
- package/dist/domain/runs/request.d.ts +0 -1
- package/dist/domain/sessions/session-hooks.d.ts +5 -12
- package/dist/domain/sessions/session-hooks.js +6 -13
- package/dist/domain/sessions/session-lifecycle.d.ts +4 -4
- package/dist/domain/sessions/session-lifecycle.js +5 -6
- package/dist/domain/sessions/session-retention.d.ts +1 -3
- package/dist/domain/sessions/session-retention.js +9 -26
- package/dist/domain/sessions/session-use.d.ts +32 -0
- package/dist/domain/sessions/session-use.js +63 -0
- package/dist/domain/sessions/session.js +6 -5
- package/dist/domain/system/server-update-check.js +29 -1
- package/dist/domain/system/update-ui-state.d.ts +32 -0
- package/dist/domain/system/update-ui-state.js +63 -0
- package/dist/domain/tasks/claim-recovery.js +2 -2
- package/dist/domain/tasks/dispatch-utils.d.ts +10 -1
- package/dist/domain/tasks/dispatch-utils.js +46 -1
- package/dist/domain/tasks/dispatcher.js +4 -5
- package/dist/domain/tasks/mutator.d.ts +2 -2
- package/dist/domain/tasks/mutator.js +2 -2
- package/dist/domain/tasks/system/task-cli.js +2 -2
- package/dist/domain/tasks/system/task-state.js +1 -1
- package/dist/domain/threads/runner.js +3 -2
- package/dist/domain/ui-service/app-router.d.ts +54 -3
- package/dist/domain/ui-service/app-router.js +12 -14
- package/dist/domain/ui-service/input-schemas.d.ts +49 -5
- package/dist/domain/ui-service/input-schemas.js +35 -9
- package/dist/domain/ui-service/mutate/platform-settings.js +1 -1
- package/dist/domain/ui-service/mutate/sessions.d.ts +17 -1
- package/dist/domain/ui-service/mutate/sessions.js +83 -3
- package/dist/domain/ui-service/mutate/system.d.ts +3 -1
- package/dist/domain/ui-service/mutate/system.js +13 -0
- package/dist/domain/ui-service/mutate/waitpoints.d.ts +2 -0
- package/dist/domain/ui-service/mutate/waitpoints.js +20 -0
- package/dist/domain/ui-service/platform-settings.js +1 -1
- package/dist/domain/ui-service/plugins-shared.js +1 -1
- package/dist/domain/ui-service/query/config.js +1 -1
- package/dist/domain/ui-service/query/executions.js +0 -2
- package/dist/domain/ui-service/query/machine-detail.js +3 -8
- package/dist/domain/ui-service/query/memory.js +1 -1
- package/dist/domain/ui-service/query/sessions.js +7 -0
- package/dist/domain/ui-service/query/system.d.ts +2 -1
- package/dist/domain/ui-service/query/system.js +4 -0
- package/dist/domain/ui-service/query/threads.js +1 -54
- package/dist/domain/ui-service/query/waitpoints.d.ts +30 -0
- package/dist/domain/ui-service/query/waitpoints.js +117 -0
- package/dist/domain/ui-service/query-input-schemas.d.ts +3 -0
- package/dist/domain/ui-service/query-input-schemas.js +3 -0
- package/dist/domain/ui-service/trpc.js +1 -1
- package/dist/domain/ui-service/types.d.ts +175 -50
- package/dist/domain/ui-service/types.js +1 -1
- package/dist/domain/ui-service/ui-service.js +13 -33
- package/dist/domain/waitpoints/notices.d.ts +21 -0
- package/dist/domain/waitpoints/notices.js +115 -0
- package/dist/domain/waitpoints/service.d.ts +91 -0
- package/dist/domain/waitpoints/service.js +243 -0
- package/dist/entry/app.js +39 -29
- package/dist/entry/auth-login-cli.js +1 -1
- package/dist/entry/auth-login-terminal.js +1 -1
- package/dist/entry/init-auth.js +1 -1
- package/dist/entry/init.js +6 -6
- package/dist/entry/signal-cli.d.ts +30 -0
- package/dist/entry/signal-cli.js +207 -0
- package/dist/entry/start-ui-http.d.ts +1 -1
- package/dist/entry/start-ui-http.js +5 -3
- package/dist/events/event-types.d.ts +5 -7
- package/dist/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
- package/dist/hooks/cortex-hook-api.mjs +2 -2
- package/dist/hooks/new-session-hook.mjs +2 -2
- package/dist/hooks/rules-loader.mjs +2 -2
- package/dist/hooks/status-md-guard.mjs +8 -8
- package/dist/hooks/task-status-check.mjs +18 -76
- package/dist/hooks/tasks-yaml-guard.mjs +2 -2
- package/dist/orchestration/agent-file-send.d.ts +9 -0
- package/dist/orchestration/agent-file-send.js +21 -2
- package/dist/orchestration/agent-runner.d.ts +4 -3
- package/dist/orchestration/agent-runner.js +25 -23
- package/dist/orchestration/attachments-store.d.ts +31 -0
- package/dist/orchestration/attachments-store.js +184 -0
- package/dist/orchestration/conversation-request.d.ts +30 -8
- package/dist/orchestration/conversation-request.js +62 -26
- package/dist/orchestration/edit-retry.js +2 -1
- package/dist/orchestration/interactions/ask-user-resume.js +2 -1
- package/dist/orchestration/interactions/plan-approvals.js +1 -1
- package/dist/orchestration/interactions/ui-update-prompt.d.ts +8 -0
- package/dist/orchestration/interactions/ui-update-prompt.js +47 -0
- package/dist/orchestration/outputs-store.d.ts +11 -0
- package/dist/orchestration/outputs-store.js +32 -6
- package/dist/orchestration/resume-dispatcher.js +2 -2
- package/dist/orchestration/routing/file-handler.d.ts +23 -2
- package/dist/orchestration/routing/file-handler.js +22 -5
- package/dist/orchestration/routing/webhook.js +240 -39
- package/dist/orchestration/session-compact.d.ts +3 -0
- package/dist/orchestration/session-compact.js +3 -2
- package/dist/orchestration/session-events.d.ts +6 -0
- package/dist/orchestration/session-events.js +5 -0
- package/dist/orchestration/session-gateway.d.ts +1 -1
- package/dist/orchestration/session-gateway.js +1 -0
- package/dist/orchestration/thread-executor.d.ts +2 -0
- package/dist/orchestration/thread-executor.js +11 -1
- package/dist/orchestration/thread-input.d.ts +3 -2
- package/dist/orchestration/thread-input.js +8 -9
- package/dist/orchestration/turn/turn-prep.d.ts +15 -1
- package/dist/orchestration/turn/turn-prep.js +21 -9
- package/dist/orchestration/waitpoint-ingress.d.ts +41 -0
- package/dist/orchestration/waitpoint-ingress.js +172 -0
- package/dist/orchestration/waitpoint-notifier.d.ts +21 -0
- package/dist/orchestration/waitpoint-notifier.js +119 -0
- package/dist/orchestration/waitpoint-remote-drain.d.ts +20 -0
- package/dist/orchestration/waitpoint-remote-drain.js +147 -0
- package/dist/orchestration/waitpoint-sweep.d.ts +42 -0
- package/dist/orchestration/waitpoint-sweep.js +87 -0
- package/dist/platform/adapters/feishu-image.d.ts +19 -0
- package/dist/platform/adapters/feishu-image.js +71 -0
- package/dist/platform/adapters/feishu.d.ts +2 -0
- package/dist/platform/adapters/feishu.js +26 -16
- package/dist/platform/ui-http/app-update.d.ts +11 -0
- package/dist/platform/ui-http/app-update.js +3 -0
- package/dist/platform/ui-http/listening-ports.d.ts +1 -1
- package/dist/platform/ui-http/listening-ports.js +1 -1
- package/dist/platform/ui-http/ui-session.js +1 -1
- package/dist/store/conversation-ledger-repo.d.ts +10 -19
- package/dist/store/conversation-ledger-repo.js +143 -152
- package/dist/store/execution-repo.d.ts +1 -19
- package/dist/store/execution-repo.js +1 -18
- package/dist/store/project-notes-repo.js +11 -2
- package/dist/store/prompt-migration-replacements.js +1 -1
- package/dist/store/session-registry-import.d.ts +34 -0
- package/dist/store/session-registry-import.js +182 -0
- package/dist/store/session-registry-journal.d.ts +107 -0
- package/dist/store/session-registry-journal.js +308 -19
- package/dist/store/session-registry-repo.d.ts +113 -28
- package/dist/store/session-registry-repo.js +288 -105
- package/dist/store/version-migrations.d.ts +29 -3
- package/dist/store/version-migrations.js +288 -24
- package/dist/store/waitpoint-repo.d.ts +108 -0
- package/dist/store/waitpoint-repo.js +94 -0
- package/package.json +2 -2
- package/web/dist/assets/index-CwwQNMpP.css +1 -0
- package/web/dist/assets/index-DLSfgq3o.js +444 -0
- package/web/dist/assets/{index-aHbOZSP6.js → index-DZTuqUO4.js} +1 -1
- package/web/dist/index.html +2 -2
- package/defaults/config/hooks/08-cortex-md-injector-post-tool.json +0 -10
- package/dist/domain/executions/log-tailer.d.ts +0 -71
- package/dist/domain/executions/log-tailer.js +0 -194
- package/dist/domain/memory/cortex-md-injector.d.ts +0 -24
- package/dist/domain/memory/cortex-md-scanner.d.ts +0 -10
- package/dist/domain/memory/cortex-md-scanner.js +0 -66
- package/dist/domain/remote/cortex-client.d.ts +0 -1
- package/dist/domain/remote/cortex-client.js +0 -662
- package/dist/domain/tasks/system/cortex-run.d.ts +0 -25
- package/dist/domain/tasks/system/cortex-run.js +0 -360
- package/dist/store/session-repo.d.ts +0 -65
- package/dist/store/session-repo.js +0 -184
- package/web/dist/assets/index-BuXbCsuz.js +0 -444
- package/web/dist/assets/index-CCPxQ94C.css +0 -1
- /package/defaults/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/config/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/ideas/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/projects/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/scans/{CORTEX.md → AGENTS.md} +0 -0
- /package/defaults/context/user/{CORTEX.md → AGENTS.md} +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// input: a local file a Feishu send is about to carry
|
|
2
|
+
// output: an image_key when Feishu can show it inline in the chat, null when it has to go as a file
|
|
3
|
+
// pos: platform/adapters — shared by the Feishu adapter's `uploadFile` and the `feishu_send_file`
|
|
4
|
+
// MCP tool, the two independent implementations of "send this file to Feishu". Both used to
|
|
5
|
+
// call `im/v1/files` unconditionally, so a screenshot the agent produced arrived as a
|
|
6
|
+
// download card: the user had to tap it to see their own picture, and it never previewed in
|
|
7
|
+
// a notification or on mobile. `im/v1/images` was never called at all.
|
|
8
|
+
import { createReadStream, promises as fs } from 'fs';
|
|
9
|
+
import { sniffImageMime } from '../../core/media-types.js';
|
|
10
|
+
import { createLogger } from '../../core/log.js';
|
|
11
|
+
const log = createLogger('feishu-image');
|
|
12
|
+
/** Feishu rejects an image upload above 10 MB (im/v1/images). Anything larger goes as a file. */
|
|
13
|
+
export const FEISHU_IMAGE_MAX_BYTES = 10 * 1024 * 1024;
|
|
14
|
+
/** Bytes read to identify the file's real type. */
|
|
15
|
+
const SNIFF_BYTES = 16;
|
|
16
|
+
/** The formats Feishu renders inline in a chat. Deliberately a subset of what it accepts: a format
|
|
17
|
+
* we cannot identify from its first bytes is safer as a file than as a rejected upload. */
|
|
18
|
+
const INLINE_IMAGE_MIMES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/bmp']);
|
|
19
|
+
/**
|
|
20
|
+
* The mime Feishu would show inline for this file, or null when it must be sent as a file.
|
|
21
|
+
*
|
|
22
|
+
* Decided from the bytes, not the extension: the agent writes `chart.png` with whatever its plotting
|
|
23
|
+
* library produced, and a mislabelled file that is uploaded as an image is rejected by the API.
|
|
24
|
+
*/
|
|
25
|
+
export async function inlineImageMime(filePath, size) {
|
|
26
|
+
if (!(size > 0) || size > FEISHU_IMAGE_MAX_BYTES)
|
|
27
|
+
return null;
|
|
28
|
+
let handle;
|
|
29
|
+
try {
|
|
30
|
+
handle = await fs.open(filePath, 'r');
|
|
31
|
+
const buf = Buffer.alloc(SNIFF_BYTES);
|
|
32
|
+
const { bytesRead } = await handle.read(buf, 0, SNIFF_BYTES, 0);
|
|
33
|
+
const mime = sniffImageMime(buf.subarray(0, bytesRead));
|
|
34
|
+
return mime && INLINE_IMAGE_MIMES.has(mime) ? mime : null;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
await handle?.close().catch(() => undefined);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Upload `filePath` as a chat image and return its `image_key`, or null when the caller should send
|
|
45
|
+
* it as a file instead.
|
|
46
|
+
*
|
|
47
|
+
* Null is the ordinary outcome for a non-image, an oversized image — and for an upload the app is
|
|
48
|
+
* not allowed to make: `im/v1/images` needs the `im:resource` scope, which an app registered before
|
|
49
|
+
* Cortex ever sent an image will not have. A missing scope must degrade to the previous behaviour,
|
|
50
|
+
* never lose the send.
|
|
51
|
+
*/
|
|
52
|
+
export async function uploadFeishuImage(client, filePath, size) {
|
|
53
|
+
if (!(await inlineImageMime(filePath, size)))
|
|
54
|
+
return null;
|
|
55
|
+
try {
|
|
56
|
+
const res = await client.im.v1.image.create({
|
|
57
|
+
data: { image_type: 'message', image: createReadStream(filePath) },
|
|
58
|
+
});
|
|
59
|
+
if (res && typeof res.code === 'number' && res.code !== 0) {
|
|
60
|
+
throw new Error(`Feishu API error ${res.code}: ${res.msg ?? 'unknown'}`);
|
|
61
|
+
}
|
|
62
|
+
const key = res?.data?.image_key ?? res?.image_key;
|
|
63
|
+
if (key)
|
|
64
|
+
return key;
|
|
65
|
+
log.warn(`image upload returned no image_key for ${filePath}; sending it as a file`);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
log.warn(`image upload failed for ${filePath} (${e.message}); sending it as a file`);
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
@@ -50,6 +50,8 @@ export declare class FeishuAdapter implements PlatformAdapter {
|
|
|
50
50
|
markQueued(ref: MessageRef): Promise<void>;
|
|
51
51
|
unmarkQueued(ref: MessageRef): Promise<void>;
|
|
52
52
|
uploadFile(destination: Destination, filePath: string, opts?: FileUploadOpts): Promise<void>;
|
|
53
|
+
/** Upload as a chat file and return its file_key. */
|
|
54
|
+
private uploadFeishuFile;
|
|
53
55
|
downloadFile(fileRef: PlatformFileRef, destDir: string): Promise<DownloadedFile>;
|
|
54
56
|
getPermalink(_ref: MessageRef): Promise<string | null>;
|
|
55
57
|
openOutputStream(destination: Destination, opts?: OpenOutputStreamOpts): OutputStream;
|
|
@@ -7,6 +7,7 @@ import { updateSettings } from '../../core/settings.js';
|
|
|
7
7
|
import { FeishuOutputStream } from './feishu-output-stream.js';
|
|
8
8
|
import { configureFeishuHttp } from './feishu-http.js';
|
|
9
9
|
import { ProjectConduitsStore } from './project-conduits.js';
|
|
10
|
+
import { uploadFeishuImage } from './feishu-image.js';
|
|
10
11
|
import { reactionFailureReason, shouldWarnReactionFailure } from '../utils/reaction-diagnostics.js';
|
|
11
12
|
const log = createLogger('feishu');
|
|
12
13
|
/**
|
|
@@ -316,26 +317,21 @@ export class FeishuAdapter {
|
|
|
316
317
|
if (!destResolved.channel) {
|
|
317
318
|
return;
|
|
318
319
|
}
|
|
319
|
-
const { resolved: fileResolved } = this.resolveFilePath(filePath);
|
|
320
|
+
const { resolved: fileResolved, size } = this.resolveFilePath(filePath);
|
|
320
321
|
const fileName = opts?.filename || path.basename(fileResolved);
|
|
321
|
-
//
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const fileKey = uploadRes?.data?.file_key;
|
|
330
|
-
if (!fileKey)
|
|
331
|
-
throw new Error('Feishu file upload failed: no file_key returned');
|
|
332
|
-
// Send file message
|
|
333
|
-
const msgContent = JSON.stringify({ file_key: fileKey });
|
|
322
|
+
// A picture the user can see beats a download card. Feishu shows an `image` message inline (and
|
|
323
|
+
// in the notification preview); anything it cannot — a non-image, an image over 10 MB, an app
|
|
324
|
+
// without the `im:resource` scope — falls back to the file card this always used to send.
|
|
325
|
+
const imageKey = await uploadFeishuImage(this.client, fileResolved, size);
|
|
326
|
+
const msgType = imageKey ? 'image' : 'file';
|
|
327
|
+
const msgContent = imageKey
|
|
328
|
+
? JSON.stringify({ image_key: imageKey })
|
|
329
|
+
: JSON.stringify({ file_key: await this.uploadFeishuFile(fileResolved, fileName) });
|
|
334
330
|
const threadId = opts?.threadId;
|
|
335
331
|
if (threadId) {
|
|
336
332
|
await this.client.im.v1.message.reply({
|
|
337
333
|
path: { message_id: threadId },
|
|
338
|
-
data: { msg_type:
|
|
334
|
+
data: { msg_type: msgType, content: msgContent },
|
|
339
335
|
});
|
|
340
336
|
}
|
|
341
337
|
else {
|
|
@@ -343,12 +339,26 @@ export class FeishuAdapter {
|
|
|
343
339
|
params: { receive_id_type: 'chat_id' },
|
|
344
340
|
data: {
|
|
345
341
|
receive_id: destResolved.channel,
|
|
346
|
-
msg_type:
|
|
342
|
+
msg_type: msgType,
|
|
347
343
|
content: msgContent,
|
|
348
344
|
},
|
|
349
345
|
});
|
|
350
346
|
}
|
|
351
347
|
}
|
|
348
|
+
/** Upload as a chat file and return its file_key. */
|
|
349
|
+
async uploadFeishuFile(fileResolved, fileName) {
|
|
350
|
+
const uploadRes = await this.client.im.v1.file.create({
|
|
351
|
+
data: {
|
|
352
|
+
file_type: this.inferFeishuFileType(fileName),
|
|
353
|
+
file_name: fileName,
|
|
354
|
+
file: fs.readFileSync(fileResolved),
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
const fileKey = uploadRes?.data?.file_key;
|
|
358
|
+
if (!fileKey)
|
|
359
|
+
throw new Error('Feishu file upload failed: no file_key returned');
|
|
360
|
+
return fileKey;
|
|
361
|
+
}
|
|
352
362
|
async downloadFile(fileRef, destDir) {
|
|
353
363
|
const raw = fileRef.raw || {};
|
|
354
364
|
const messageId = raw.message_id;
|
|
@@ -45,6 +45,17 @@ export declare function parseAppAssetName(name: string): {
|
|
|
45
45
|
*/
|
|
46
46
|
export declare function buildAppUpdateManifest(releases: GhRelease[], serverVersion: string): AppUpdateManifest | null;
|
|
47
47
|
export interface AppUpdateRouteOptions {
|
|
48
|
+
/**
|
|
49
|
+
* When true the route serves `{}` unconditionally, which the shell reads as "no update".
|
|
50
|
+
*
|
|
51
|
+
* A server running out of a source checkout (`CORTEX_REPO`) is a development install whose
|
|
52
|
+
* version bears no relation to any published release, and the shell caps itself at OUR version —
|
|
53
|
+
* so advertising releases from here would either offer nothing or offer the wrong thing, and with
|
|
54
|
+
* silent updating on it would do so without asking. Same rule the npm self-update path applies
|
|
55
|
+
* (domain/system/server-update-check.ts), decided by the caller because the platform layer may
|
|
56
|
+
* not import from domain.
|
|
57
|
+
*/
|
|
58
|
+
devMode?: boolean;
|
|
48
59
|
serverVersion?: string;
|
|
49
60
|
fetchReleases?: () => Promise<GhRelease[]>;
|
|
50
61
|
ttlMs?: number;
|
|
@@ -112,12 +112,15 @@ async function defaultFetchReleases() {
|
|
|
112
112
|
*/
|
|
113
113
|
export function createAppUpdateRoutes(opts = {}) {
|
|
114
114
|
const serverVersion = opts.serverVersion ?? CORTEX_VERSION;
|
|
115
|
+
const devMode = opts.devMode ?? false;
|
|
115
116
|
const fetchReleases = opts.fetchReleases ?? defaultFetchReleases;
|
|
116
117
|
const ttlMs = opts.ttlMs ?? DEFAULT_TTL_MS;
|
|
117
118
|
const now = opts.now ?? Date.now;
|
|
118
119
|
let lastGood = null;
|
|
119
120
|
let fetchedAt = null;
|
|
120
121
|
const manifest = async () => {
|
|
122
|
+
if (devMode)
|
|
123
|
+
return null;
|
|
121
124
|
if (fetchedAt !== null && now() - fetchedAt < ttlMs)
|
|
122
125
|
return lastGood;
|
|
123
126
|
fetchedAt = now();
|
|
@@ -24,7 +24,7 @@ export declare const MIN_FORWARDABLE_PORT = 1024;
|
|
|
24
24
|
*
|
|
25
25
|
* `MSYS_NO_PATHCONV=1` is required because commands reach a Windows device through git-bash, which
|
|
26
26
|
* rewrites the `/FO` switch into a filesystem path (`C:/Program Files/Git/FO`) and makes tasklist
|
|
27
|
-
* fail. Verified on
|
|
27
|
+
* fail. Verified on a Windows device.
|
|
28
28
|
*/
|
|
29
29
|
export declare const WINDOWS_LISTENER_COMMAND = "netstat -ano; echo '#--tasklist--#'; MSYS_NO_PATHCONV=1 tasklist /FO CSV /NH";
|
|
30
30
|
/**
|
|
@@ -27,7 +27,7 @@ const TASKLIST_MARKER = '#--tasklist--#';
|
|
|
27
27
|
*
|
|
28
28
|
* `MSYS_NO_PATHCONV=1` is required because commands reach a Windows device through git-bash, which
|
|
29
29
|
* rewrites the `/FO` switch into a filesystem path (`C:/Program Files/Git/FO`) and makes tasklist
|
|
30
|
-
* fail. Verified on
|
|
30
|
+
* fail. Verified on a Windows device.
|
|
31
31
|
*/
|
|
32
32
|
export const WINDOWS_LISTENER_COMMAND = `netstat -ano; echo '${TASKLIST_MARKER}'; MSYS_NO_PATHCONV=1 tasklist /FO CSV /NH`;
|
|
33
33
|
/** Foreign address of a listening socket, in both families. Locale-independent — unlike the state
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// HttpOnly cookie; every later request is admitted by that id instead of the token, so the
|
|
6
6
|
// secret itself never enters the page's JavaScript. Ids are 32 random bytes with an
|
|
7
7
|
// ABSOLUTE expiry (verify never renews — that keeps verify write-free), persisted to
|
|
8
|
-
//
|
|
8
|
+
// STORE_DIR/ui-sessions.json at 0600 so a daemon restart does not log every browser out.
|
|
9
9
|
// A session id is bearer-equivalent but strictly weaker than the token: the auth gate never
|
|
10
10
|
// accepts it on the /forward WebSocket upgrade (see ui-http-server.ts).
|
|
11
11
|
import * as crypto from 'crypto';
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
statusMessageTs: string | null;
|
|
7
|
-
responseMessageTimestamps: string[];
|
|
8
|
-
executionId: string | null;
|
|
9
|
-
backupPath: string | null;
|
|
10
|
-
status: TurnStatus;
|
|
11
|
-
createdAt: string;
|
|
12
|
-
updatedAt: string;
|
|
13
|
-
}
|
|
1
|
+
import { type SessionRegistryRepo } from './session-registry-repo.js';
|
|
2
|
+
import type { TurnRecord, TurnStatus } from './session-registry-journal.js';
|
|
3
|
+
export type { TurnStatus };
|
|
4
|
+
/** The ledger's turn IS the registry's turn record — one definition, no drift. */
|
|
5
|
+
export type LedgerTurn = TurnRecord;
|
|
14
6
|
export interface ChannelConversation {
|
|
15
7
|
sessionId: string | null;
|
|
16
8
|
sessionName: string | null;
|
|
@@ -23,8 +15,8 @@ export interface ChannelConversation {
|
|
|
23
15
|
}
|
|
24
16
|
export type LedgerData = Record<string, ChannelConversation>;
|
|
25
17
|
export declare class ConversationLedgerRepo {
|
|
26
|
-
private
|
|
27
|
-
constructor(
|
|
18
|
+
private readonly registry;
|
|
19
|
+
constructor(registry?: SessionRegistryRepo);
|
|
28
20
|
getConversation(channel: string): Promise<ChannelConversation | null>;
|
|
29
21
|
findTurn(channel: string, userMessageTs: string): Promise<{
|
|
30
22
|
conversation: ChannelConversation;
|
|
@@ -58,7 +50,6 @@ export declare class ConversationLedgerRepo {
|
|
|
58
50
|
channel: string;
|
|
59
51
|
}>>;
|
|
60
52
|
clearBySessionIds(sessionIds: Iterable<string>): Promise<number>;
|
|
61
|
-
deleteExceptSessionIds(sessionIds: Iterable<string>): Promise<number>;
|
|
62
53
|
switchSession(channel: string, opts: {
|
|
63
54
|
sessionId: string;
|
|
64
55
|
sessionName: string | null;
|
|
@@ -66,7 +57,7 @@ export declare class ConversationLedgerRepo {
|
|
|
66
57
|
profileName?: string | null;
|
|
67
58
|
}): Promise<void>;
|
|
68
59
|
/**
|
|
69
|
-
* Atomic init-if-missing + beginTurn. Captures the turn index under
|
|
60
|
+
* Atomic init-if-missing + beginTurn. Captures the turn index under one lock
|
|
70
61
|
* so callers can safely pass it to sessionBackup.createBackup.
|
|
71
62
|
* Returns { turn, turnIndex } for the caller.
|
|
72
63
|
*/
|
|
@@ -84,9 +75,9 @@ export declare class ConversationLedgerRepo {
|
|
|
84
75
|
}>;
|
|
85
76
|
/** Set the backup path on the turn identified by userMessageTs. */
|
|
86
77
|
setBackupPath(channel: string, userMessageTs: string, backupPath: string | null): Promise<void>;
|
|
87
|
-
/** Drop the in-memory cache so the next read
|
|
78
|
+
/** Drop the registry's in-memory cache so the next read fetches from disk. For testing. */
|
|
88
79
|
invalidate(): void;
|
|
89
|
-
/** Wait for any in-flight
|
|
80
|
+
/** Wait for any in-flight registry mutation to complete. For graceful SIGTERM drain. */
|
|
90
81
|
flush(): Promise<void>;
|
|
91
82
|
}
|
|
92
83
|
export declare const conversationLedger: ConversationLedgerRepo;
|