@hyperwindmill/caretaker-cli 0.31.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/web/mcp_bridge.d.ts +1 -0
- package/dist/cli/web/mcp_bridge.d.ts.map +1 -1
- package/dist/cli/web/mcp_bridge.js +11 -2
- package/dist/cli/web/scheduler/cycle_events.d.ts +8 -3
- package/dist/cli/web/scheduler/cycle_events.d.ts.map +1 -1
- package/dist/cli/web/scheduler/cycle_events.js +2 -0
- package/dist/cli/web/scheduler/email_triage.d.ts +70 -0
- package/dist/cli/web/scheduler/email_triage.d.ts.map +1 -0
- package/dist/cli/web/scheduler/email_triage.js +262 -0
- package/dist/cli/web/scheduler/email_triage_agent.d.ts +16 -0
- package/dist/cli/web/scheduler/email_triage_agent.d.ts.map +1 -0
- package/dist/cli/web/scheduler/email_triage_agent.js +94 -0
- package/dist/cli/web/scheduler/heartbeat.d.ts +1 -1
- package/dist/cli/web/scheduler/heartbeat.d.ts.map +1 -1
- package/dist/cli/web/scheduler/heartbeat.js +9 -5
- package/dist/cli/web/scheduler/service_runs.d.ts +12 -0
- package/dist/cli/web/scheduler/service_runs.d.ts.map +1 -0
- package/dist/cli/web/scheduler/service_runs.js +39 -0
- package/dist/cli/web/scheduler.d.ts +9 -0
- package/dist/cli/web/scheduler.d.ts.map +1 -1
- package/dist/cli/web/scheduler.js +25 -1
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +34 -1
- package/dist/harness/tools/builtin/email_tools.d.ts +1 -0
- package/dist/harness/tools/builtin/email_tools.d.ts.map +1 -1
- package/dist/harness/tools/builtin/email_tools.js +41 -1
- package/dist/harness/tools/builtin/index.d.ts +2 -2
- package/dist/harness/tools/builtin/index.d.ts.map +1 -1
- package/dist/harness/tools/builtin/index.js +3 -2
- package/dist/lib/email.d.ts +20 -0
- package/dist/lib/email.d.ts.map +1 -1
- package/dist/lib/email.js +107 -33
- package/dist/webview/standalone.js +644 -333
- package/dist/webview/standalone.js.map +4 -4
- package/package.json +3 -3
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Live channel for service runs (heartbeat, email triage): the run in flight per
|
|
2
|
+
// service, streamed through the task-cycle buffer keyed by run id, so the log
|
|
3
|
+
// viewer can follow a run whether it was started by its cron or by hand.
|
|
4
|
+
//
|
|
5
|
+
// Harness-free on purpose: email_triage.ts imports it and must stay testable
|
|
6
|
+
// with plain fakes.
|
|
7
|
+
import { randomUUID } from 'node:crypto';
|
|
8
|
+
import { beginCycleStream, emitCycleEvent } from './cycle_events.js';
|
|
9
|
+
/** serviceId → runId of the run in flight. */
|
|
10
|
+
const active = new Map();
|
|
11
|
+
export function newRunId() {
|
|
12
|
+
return `run_${randomUUID().slice(0, 8)}`;
|
|
13
|
+
}
|
|
14
|
+
/** Must be called in the same synchronous block that takes the service's
|
|
15
|
+
* `runningTasks` lock, so the two can never disagree. */
|
|
16
|
+
export function beginServiceRun(serviceId, runId, prompt) {
|
|
17
|
+
active.set(serviceId, runId);
|
|
18
|
+
beginCycleStream(runId, prompt);
|
|
19
|
+
}
|
|
20
|
+
/** Call only after the run's log is persisted: a watcher reloads the run list on `done`. */
|
|
21
|
+
export function endServiceRun(serviceId, runId) {
|
|
22
|
+
if (active.get(serviceId) === runId)
|
|
23
|
+
active.delete(serviceId);
|
|
24
|
+
emitCycleEvent(runId, { type: 'done' });
|
|
25
|
+
}
|
|
26
|
+
export function activeServiceRun(serviceId) {
|
|
27
|
+
return active.get(serviceId);
|
|
28
|
+
}
|
|
29
|
+
export function emitServiceRunEvent(runId, text, type) {
|
|
30
|
+
emitCycleEvent(runId, { type, text });
|
|
31
|
+
}
|
|
32
|
+
export function serviceRunCallbacks(runId) {
|
|
33
|
+
return {
|
|
34
|
+
onChunk: (text) => emitCycleEvent(runId, { type: 'chunk', text }),
|
|
35
|
+
onThinking: (text) => emitCycleEvent(runId, { type: 'thinking', text }),
|
|
36
|
+
onToolCall: (id, name, args) => emitCycleEvent(runId, { type: 'tool_call', id, name, args }),
|
|
37
|
+
onToolResult: (id, content) => emitCycleEvent(runId, { type: 'tool_result', id, content }),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import type { ServiceConfig } from '../../types.js';
|
|
1
2
|
export { schedulerLogsDir, schedulerLogPath, ensureSchedulerLogsDir, loadTaskRuns, saveTaskRun, } from './scheduler/logs.js';
|
|
2
3
|
export { runningTasks } from './scheduler/locks.js';
|
|
3
4
|
/**
|
|
4
5
|
* Evaluates all scheduled tasks and triggers execution loops for matching ones.
|
|
5
6
|
*/
|
|
6
7
|
export declare function runSchedulerTick(): Promise<void>;
|
|
8
|
+
/** Service types a user can run by hand: the cron-driven ones. */
|
|
9
|
+
export declare function isRunnableService(service: ServiceConfig): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Starts a run of a cron-driven service now, regardless of its schedule or
|
|
12
|
+
* enabled flag, and returns its run id. A run already in flight is not
|
|
13
|
+
* duplicated: its id is returned instead, so the caller can follow it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function runServiceNow(service: ServiceConfig): string;
|
|
7
16
|
/**
|
|
8
17
|
* Starts the in-process background scheduler loop.
|
|
9
18
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../src/cli/web/scheduler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../src/cli/web/scheduler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAUpD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAQpD;;GAEG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CA4BtD;AAGD,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAU5D;AAID;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAQ/C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAM9C"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { loadConfig } from '../../store/json.js';
|
|
2
|
-
import { HeartbeatStrategy } from './scheduler/heartbeat.js';
|
|
2
|
+
import { HeartbeatStrategy, executeTaskRun } from './scheduler/heartbeat.js';
|
|
3
3
|
import { TelegramStrategy } from './scheduler/telegram.js';
|
|
4
|
+
import { EmailTriageStrategy, realTriageDeps } from './scheduler/email_triage_agent.js';
|
|
5
|
+
import { executeTriageRun } from './scheduler/email_triage.js';
|
|
6
|
+
import { activeServiceRun, newRunId } from './scheduler/service_runs.js';
|
|
4
7
|
import { runTaskHeartbeatTick } from './scheduler/task_strategy.js';
|
|
5
8
|
import { runMemorySweepTick } from './scheduler/memory_sweep.js';
|
|
6
9
|
// Re-exported for backwards compatibility with existing consumers (server.ts, tests).
|
|
@@ -9,6 +12,7 @@ export { runningTasks } from './scheduler/locks.js';
|
|
|
9
12
|
const strategies = new Map([
|
|
10
13
|
[HeartbeatStrategy.type, HeartbeatStrategy],
|
|
11
14
|
[TelegramStrategy.type, TelegramStrategy],
|
|
15
|
+
[EmailTriageStrategy.type, EmailTriageStrategy],
|
|
12
16
|
]);
|
|
13
17
|
/**
|
|
14
18
|
* Evaluates all scheduled tasks and triggers execution loops for matching ones.
|
|
@@ -40,6 +44,26 @@ export async function runSchedulerTick() {
|
|
|
40
44
|
console.error('[scheduler] Error evaluating scheduler tasks tick:', err);
|
|
41
45
|
}
|
|
42
46
|
}
|
|
47
|
+
/** Service types a user can run by hand: the cron-driven ones. */
|
|
48
|
+
export function isRunnableService(service) {
|
|
49
|
+
return service.type === 'heartbeat' || service.type === 'email_triage';
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Starts a run of a cron-driven service now, regardless of its schedule or
|
|
53
|
+
* enabled flag, and returns its run id. A run already in flight is not
|
|
54
|
+
* duplicated: its id is returned instead, so the caller can follow it.
|
|
55
|
+
*/
|
|
56
|
+
export function runServiceNow(service) {
|
|
57
|
+
const inFlight = activeServiceRun(service.id);
|
|
58
|
+
if (inFlight)
|
|
59
|
+
return inFlight;
|
|
60
|
+
const runId = newRunId();
|
|
61
|
+
const run = service.type === 'email_triage'
|
|
62
|
+
? executeTriageRun(service, realTriageDeps, runId)
|
|
63
|
+
: executeTaskRun(service, runId);
|
|
64
|
+
void run.catch((err) => console.error(`[scheduler] Manual run of "${service.name}" failed:`, err));
|
|
65
|
+
return runId;
|
|
66
|
+
}
|
|
43
67
|
let schedulerIntervalRef = null;
|
|
44
68
|
/**
|
|
45
69
|
* Starts the in-process background scheduler loop.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AA8ClD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAgC,MAAM,gBAAgB,CAAC;AAChG,OAAO,KAAK,EAAe,eAAe,EAA0B,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/cli/web/server.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AA8ClD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAgC,MAAM,gBAAgB,CAAC;AAChG,OAAO,KAAK,EAAe,eAAe,EAA0B,MAAM,mBAAmB,CAAC;AAuC9F,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,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QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,EACtE,iBAAiB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,IAAI,CAAC;IAsFhB,KAAK,IAAI,IAAI;CAGd;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqvC3E"}
|
package/dist/cli/web/server.js
CHANGED
|
@@ -23,7 +23,8 @@ import { listForAgent, readSession, deleteSession, computeContextUsage, createSe
|
|
|
23
23
|
import { sessionRunScope } from './session_scope.js';
|
|
24
24
|
import { guardTurnCallbacks } from './turn_guard.js';
|
|
25
25
|
import { watchCycleStream } from './scheduler/cycle_events.js';
|
|
26
|
-
import { startBackgroundScheduler, loadTaskRuns } from './scheduler.js';
|
|
26
|
+
import { startBackgroundScheduler, loadTaskRuns, isRunnableService, runServiceNow } from './scheduler.js';
|
|
27
|
+
import { activeServiceRun } from './scheduler/service_runs.js';
|
|
27
28
|
import { fsRouter } from './fs.js';
|
|
28
29
|
import { activationStatus, resolvePlanningEnabled } from './scheduler/task_roles.js';
|
|
29
30
|
import { registerVoiceProxy, voiceClientConfig, fetchVoiceCatalog, formKeyFor, KEY_WITHHELD_HINT, } from './voice_proxy.js';
|
|
@@ -1336,10 +1337,42 @@ export async function startServer(port, host) {
|
|
|
1336
1337
|
if (/^[A-Za-z0-9_-]+$/.test(msg.sessionId))
|
|
1337
1338
|
unwatchCycle(msg.sessionId);
|
|
1338
1339
|
return;
|
|
1340
|
+
case 'runService': {
|
|
1341
|
+
const service = (await loadConfig()).scheduler?.tasks?.find((t) => t.id === msg.serviceId);
|
|
1342
|
+
if (!service || !isRunnableService(service)) {
|
|
1343
|
+
post({ type: 'error', message: `Service "${msg.serviceId}" cannot be run manually` });
|
|
1344
|
+
return;
|
|
1345
|
+
}
|
|
1346
|
+
post({ type: 'serviceRunActive', serviceId: service.id, runId: runServiceNow(service) });
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
case 'watchServiceRun': {
|
|
1350
|
+
// A service run lives only in memory while running; its log is on disk after.
|
|
1351
|
+
const { runId } = msg;
|
|
1352
|
+
unwatchCycle(runId);
|
|
1353
|
+
const live = watchCycleStream(runId, (event) => post({ type: 'cycleEvent', sessionId: runId, event }));
|
|
1354
|
+
if (!live) {
|
|
1355
|
+
post({ type: 'cycleEvent', sessionId: runId, event: { type: 'done' } });
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1358
|
+
cycleWatchers.set(runId, live.unwatch);
|
|
1359
|
+
post({
|
|
1360
|
+
type: 'cycleLoaded',
|
|
1361
|
+
sessionId: runId,
|
|
1362
|
+
messages: live.prompt ? [toChatMessage(live.prompt)] : [],
|
|
1363
|
+
running: true,
|
|
1364
|
+
});
|
|
1365
|
+
for (const event of live.events)
|
|
1366
|
+
post({ type: 'cycleEvent', sessionId: runId, event });
|
|
1367
|
+
return;
|
|
1368
|
+
}
|
|
1339
1369
|
case 'getTaskRuns':
|
|
1340
1370
|
try {
|
|
1341
1371
|
const runs = await loadTaskRuns(msg.taskId);
|
|
1342
1372
|
post({ type: 'taskRunsLoaded', taskId: msg.taskId, runs });
|
|
1373
|
+
const runId = activeServiceRun(msg.taskId);
|
|
1374
|
+
if (runId)
|
|
1375
|
+
post({ type: 'serviceRunActive', serviceId: msg.taskId, runId });
|
|
1343
1376
|
}
|
|
1344
1377
|
catch (err) {
|
|
1345
1378
|
console.error('[web] failed to load task runs:', err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/email_tools.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"email_tools.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/email_tools.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,aAAa,CAAC;AAoCpD,eAAO,MAAM,qBAAqB,EAAE,IAqBnC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,IAiE5B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IAyC3B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,IAwG3B,CAAC"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// ctx.callerAgent — a scoped account is invisible, not refused);
|
|
10
10
|
// - who an account may send to (`allowedRecipients`, checked before connecting);
|
|
11
11
|
// - whose mail it may read (`allowedSenders`, checked on the envelope pass).
|
|
12
|
-
import { listEmailAccounts, findAccount, matchesAllowlist, bareAddress, sendEmail, fetchInbox, canSend, canRead, clampLimit, markdownToHtml, MAX_FETCH, } from '../../../lib/email.js';
|
|
12
|
+
import { listEmailAccounts, findAccount, matchesAllowlist, bareAddress, sendEmail, fetchInbox, readMessage, canSend, canRead, clampLimit, markdownToHtml, MAX_FETCH, } from '../../../lib/email.js';
|
|
13
13
|
function err(msg) {
|
|
14
14
|
return { content: JSON.stringify({ error: msg }) };
|
|
15
15
|
}
|
|
@@ -112,6 +112,46 @@ export const emailFetchTool = {
|
|
|
112
112
|
}
|
|
113
113
|
},
|
|
114
114
|
};
|
|
115
|
+
export const emailReadTool = {
|
|
116
|
+
name: 'mcp__email__email_read',
|
|
117
|
+
description: 'Read one message from an account inbox by its UID, without marking it read. Returns the plain-text body (possibly truncated) and attachment names. A message from a sender outside the account allowlist, or an unknown UID, is reported as "No message".',
|
|
118
|
+
parameters: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
properties: {
|
|
121
|
+
account: { type: 'string', description: 'Account name from email_list_accounts.' },
|
|
122
|
+
uid: { type: 'number', description: 'IMAP UID of the message, as returned by email_fetch.' },
|
|
123
|
+
},
|
|
124
|
+
required: ['account', 'uid'],
|
|
125
|
+
},
|
|
126
|
+
execute: async (args, ctx) => {
|
|
127
|
+
const name = typeof args?.account === 'string' ? args.account : '';
|
|
128
|
+
if (!name.trim())
|
|
129
|
+
return err('account must be a non-empty string');
|
|
130
|
+
const uid = args?.uid;
|
|
131
|
+
if (typeof uid !== 'number' || !Number.isInteger(uid) || uid < 1)
|
|
132
|
+
return err('uid must be a positive integer');
|
|
133
|
+
const accounts = await listEmailAccounts(ctx.callerAgent?.id);
|
|
134
|
+
const account = findAccount(accounts, name);
|
|
135
|
+
if (!account) {
|
|
136
|
+
const available = accounts.filter(canRead).map((a) => a.name);
|
|
137
|
+
return err(available.length
|
|
138
|
+
? `Unknown email account "${name}". Readable accounts: ${available.join(', ')}`
|
|
139
|
+
: `Unknown email account "${name}". No account is configured for reading — an email service needs an IMAP host and must be enabled.`);
|
|
140
|
+
}
|
|
141
|
+
if (!canRead(account)) {
|
|
142
|
+
return err(`Account "${account.name}" has no IMAP host, so it cannot be read.`);
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const message = await readMessage(account, uid, ctx.signal);
|
|
146
|
+
if (!message)
|
|
147
|
+
return err(`No message with uid ${uid} in "${account.name}".`);
|
|
148
|
+
return { content: JSON.stringify({ account: account.name, message }) };
|
|
149
|
+
}
|
|
150
|
+
catch (e) {
|
|
151
|
+
return err(`IMAP read failed: ${e?.message ?? String(e)}`);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
};
|
|
115
155
|
export const emailSendTool = {
|
|
116
156
|
name: 'mcp__email__email_send',
|
|
117
157
|
description: 'Send an email through one of the configured accounts. Pick the account by its name from email_list_accounts. `body` is the plain-text version and is always required; for a formatted message write `body` in markdown and set `markdown: true` (converted for you, so you write the content once), or pass your own `html`. No attachments. Recipients outside the account allowlist are refused and nothing is sent.',
|
|
@@ -17,9 +17,9 @@ import { invokeAgentTool } from './invoke_agent.js';
|
|
|
17
17
|
import { listCommandsTool } from './list_commands.js';
|
|
18
18
|
import { invokeCommandTool } from './invoke_command.js';
|
|
19
19
|
import { getAgentContextTool } from './get_agent_context.js';
|
|
20
|
-
import { emailListAccountsTool, emailSendTool, emailFetchTool } from './email_tools.js';
|
|
20
|
+
import { emailListAccountsTool, emailSendTool, emailFetchTool, emailReadTool } from './email_tools.js';
|
|
21
21
|
import { memoryReadTool } from './memory_tools.js';
|
|
22
22
|
import { getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool } from './task_tools.js';
|
|
23
23
|
export declare function registerBuiltins(registry: ToolRegistry): void;
|
|
24
|
-
export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, emailListAccountsTool, emailSendTool, emailFetchTool, memoryReadTool, };
|
|
24
|
+
export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, emailListAccountsTool, emailSendTool, emailFetchTool, emailReadTool, memoryReadTool, };
|
|
25
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/harness/tools/builtin/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG/C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,cAA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AACnD,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AAEzB,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAmE7D;AAED,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,aAAa,EACb,cAAc,GACf,CAAC"}
|
|
@@ -22,7 +22,7 @@ import { setWorkspaceTool } from './set_workspace.js';
|
|
|
22
22
|
import { listCommandsTool } from './list_commands.js';
|
|
23
23
|
import { invokeCommandTool } from './invoke_command.js';
|
|
24
24
|
import { getAgentContextTool } from './get_agent_context.js';
|
|
25
|
-
import { emailListAccountsTool, emailSendTool, emailFetchTool } from './email_tools.js';
|
|
25
|
+
import { emailListAccountsTool, emailSendTool, emailFetchTool, emailReadTool } from './email_tools.js';
|
|
26
26
|
import { memoryReadTool } from './memory_tools.js';
|
|
27
27
|
import { getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, } from './task_tools.js';
|
|
28
28
|
export function registerBuiltins(registry) {
|
|
@@ -86,7 +86,8 @@ export function registerBuiltins(registry) {
|
|
|
86
86
|
registry.register(emailListAccountsTool);
|
|
87
87
|
registry.register(emailSendTool);
|
|
88
88
|
registry.register(emailFetchTool);
|
|
89
|
+
registry.register(emailReadTool);
|
|
89
90
|
// Memory subsystem read path (recall accounting lives in the tool).
|
|
90
91
|
registry.register(memoryReadTool);
|
|
91
92
|
}
|
|
92
|
-
export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, emailListAccountsTool, emailSendTool, emailFetchTool, memoryReadTool, };
|
|
93
|
+
export { readFileTool, readDocumentTool, readImageTool, readAttachmentTool, writeTool, editTool, multieditTool, globTool, grepTool, fetchTool, bashTool, listSkillsTool, readSkillTool, listAgentsTool, invokeAgentTool, listCommandsTool, invokeCommandTool, getAgentContextTool, getTaskStateTool, updateChecklistItemTool, updateChecklistTool, addMessageTool, completeTaskTool, blockTaskTool, yieldTaskTool, projectListTool, taskCreateTool, taskSearchTool, taskUnblockTool, taskActivateTool, taskUnpauseTool, taskDiscardWorktreeTool, taskArchiveTool, taskUnarchiveTool, taskDeleteTool, taskSetAgentTool, submitPlanTool, taskUpdateDetailsTool, emailListAccountsTool, emailSendTool, emailFetchTool, emailReadTool, memoryReadTool, };
|
package/dist/lib/email.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ import type { ServiceConfig } from '../types.js';
|
|
|
10
10
|
export declare const NET_TIMEOUT_MS = 60000;
|
|
11
11
|
/** An email account with its secrets decrypted and its defaults applied. */
|
|
12
12
|
export type EmailAccount = {
|
|
13
|
+
/** The service record id. */
|
|
14
|
+
id: string;
|
|
13
15
|
name: string;
|
|
14
16
|
from: string;
|
|
15
17
|
smtpHost: string;
|
|
@@ -145,4 +147,22 @@ export declare function fetchInbox(account: EmailAccount, opts?: FetchOptions):
|
|
|
145
147
|
refused: number;
|
|
146
148
|
scanTruncated?: boolean;
|
|
147
149
|
}>;
|
|
150
|
+
export type TriageEnvelope = {
|
|
151
|
+
uid: number;
|
|
152
|
+
from: string;
|
|
153
|
+
subject: string;
|
|
154
|
+
date: string;
|
|
155
|
+
};
|
|
156
|
+
/** Oldest unseen envelopes the account may read; no bodies, no flag changes. */
|
|
157
|
+
export declare function listUnseenEnvelopes(account: EmailAccount, max: number, signal?: AbortSignal): Promise<{
|
|
158
|
+
envelopes: TriageEnvelope[];
|
|
159
|
+
refused: number;
|
|
160
|
+
scanTruncated: boolean;
|
|
161
|
+
uidValidity: string;
|
|
162
|
+
}>;
|
|
163
|
+
/** One message by UID, or null when it does not exist or its sender is not
|
|
164
|
+
* allowed. `source` is fetched as BODY.PEEK[], so `\Seen` stays untouched. */
|
|
165
|
+
export declare function readMessage(account: EmailAccount, uid: number, signal?: AbortSignal): Promise<InboundMessage | null>;
|
|
166
|
+
/** Mark `uids` seen, unless the mailbox was reset since they were listed. */
|
|
167
|
+
export declare function markSeen(account: EmailAccount, uids: number[], expectedUidValidity: string, signal?: AbortSignal): Promise<'marked' | 'uidvalidity-changed'>;
|
|
148
168
|
//# sourceMappingURL=email.d.ts.map
|
package/dist/lib/email.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/lib/email.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,QAAS,CAAC;AAarC,4EAA4E;AAC5E,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,qFAAqF;IACrF,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,oEAAoE;IACpE,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,oEAAoE;AACpE,wBAAgB,OAAO,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAEhD;AAED,yDAAyD;AACzD,wBAAgB,OAAO,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAEhD;AAOD,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAK/D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAc7E;AAED;;;;GAIG;AACH,wBA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AAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAwDnF;AAOD,MAAM,MAAM,cAAc,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1F,gFAAgF;AAChF,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,YAAY,EACrB,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC;IAAE,SAAS,EAAE,cAAc,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,CA8BxG;AAED;+EAC+E;AAC/E,wBAAsB,WAAW,CAC/B,OAAO,EAAE,YAAY,EACrB,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAahC;AAED,6EAA6E;AAC7E,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,MAAM,EAAE,EACd,mBAAmB,EAAE,MAAM,EAC3B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,QAAQ,GAAG,qBAAqB,CAAC,CAO3C"}
|
package/dist/lib/email.js
CHANGED
|
@@ -94,6 +94,7 @@ export function emailAccounts(services) {
|
|
|
94
94
|
return services
|
|
95
95
|
.filter((s) => s.type === 'email' && s.enabled)
|
|
96
96
|
.map((s) => ({
|
|
97
|
+
id: s.id,
|
|
97
98
|
name: s.name,
|
|
98
99
|
from: (s.smtpFrom || s.imapUser || '').trim(),
|
|
99
100
|
smtpHost: (s.smtpHost ?? '').trim(),
|
|
@@ -154,9 +155,14 @@ export function findAccount(accounts, name) {
|
|
|
154
155
|
*/
|
|
155
156
|
export function markdownToHtml(markdown) {
|
|
156
157
|
const body = marked.parse(markdown, { async: false, gfm: true });
|
|
158
|
+
// Tables: clients strip <style>, so borders go inline; border="1" is for old Outlook.
|
|
159
|
+
const cell = 'border:1px solid #999;padding:6px 10px;text-align:left;vertical-align:top';
|
|
160
|
+
const html = body
|
|
161
|
+
.replace(/<table(?=[\s>])/g, '<table border="1" style="border-collapse:collapse"')
|
|
162
|
+
.replace(/<(th|td)(?=[\s>])/g, `<$1 style="${cell}"`);
|
|
157
163
|
return ('<div style="font-family:-apple-system,Segoe UI,Helvetica,Arial,sans-serif;' +
|
|
158
164
|
'font-size:14px;line-height:1.5;color:#1a1a1a;max-width:40em">' +
|
|
159
|
-
|
|
165
|
+
html +
|
|
160
166
|
'</div>');
|
|
161
167
|
}
|
|
162
168
|
/** Send one message (plain text, plus an HTML alternative when given).
|
|
@@ -193,11 +199,14 @@ export async function sendEmail(account, mail, signal) {
|
|
|
193
199
|
}
|
|
194
200
|
// ─── Inbound ──────────────────────────────────────────────────────────────
|
|
195
201
|
//
|
|
196
|
-
// There is no `email` scheduler strategy and no stored UID cursor:
|
|
197
|
-
// workflow is a `heartbeat` service whose prompt tells the agent
|
|
198
|
-
// email_fetch, and "already handled" is the IMAP `\Seen` flag — server
|
|
199
|
-
// shared with the user's own mail client. Two behaviours on one account
|
|
200
|
-
//
|
|
202
|
+
// There is no generic `email` scheduler strategy and no stored UID cursor: a
|
|
203
|
+
// generic inbound workflow is a `heartbeat` service whose prompt tells the agent
|
|
204
|
+
// to call email_fetch, and "already handled" is the IMAP `\Seen` flag — server
|
|
205
|
+
// state, shared with the user's own mail client. Two behaviours on one account
|
|
206
|
+
// are two heartbeats. The dedicated `email_triage` service (cli/web/scheduler/)
|
|
207
|
+
// references an account by id and uses the peek-style helpers below
|
|
208
|
+
// (listUnseenEnvelopes / readMessage / markSeen) so it marks mail read only
|
|
209
|
+
// after its report is delivered.
|
|
201
210
|
/** Hard ceiling on messages per call, whatever the caller asks for. */
|
|
202
211
|
export const MAX_FETCH = 50;
|
|
203
212
|
/** How many unread messages we are willing to look at to fill one window.
|
|
@@ -235,11 +244,9 @@ export function messageText(parsed) {
|
|
|
235
244
|
return turndown.turndown(parsed.html);
|
|
236
245
|
return '';
|
|
237
246
|
}
|
|
238
|
-
/**
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const markSeen = opts.markSeen !== false;
|
|
242
|
-
if (opts.signal?.aborted)
|
|
247
|
+
/** Connect, lock INBOX, run `fn`, and always release and log out. */
|
|
248
|
+
async function withInbox(account, signal, fn) {
|
|
249
|
+
if (signal?.aborted)
|
|
243
250
|
throw new Error('aborted before connecting');
|
|
244
251
|
const client = new ImapFlow({
|
|
245
252
|
host: account.imapHost,
|
|
@@ -248,7 +255,7 @@ export async function fetchInbox(account, opts = {}) {
|
|
|
248
255
|
auth: { user: account.imapUser, pass: account.imapPassword },
|
|
249
256
|
logger: false,
|
|
250
257
|
});
|
|
251
|
-
const disarm = armAbort(() => client.close(),
|
|
258
|
+
const disarm = armAbort(() => client.close(), signal);
|
|
252
259
|
try {
|
|
253
260
|
await client.connect();
|
|
254
261
|
}
|
|
@@ -258,6 +265,36 @@ export async function fetchInbox(account, opts = {}) {
|
|
|
258
265
|
}
|
|
259
266
|
const lock = await client.getMailboxLock('INBOX');
|
|
260
267
|
try {
|
|
268
|
+
return await fn(client);
|
|
269
|
+
}
|
|
270
|
+
finally {
|
|
271
|
+
disarm();
|
|
272
|
+
lock.release();
|
|
273
|
+
await client.logout().catch(() => client.close());
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/** Build the model-facing message from a parsed source. */
|
|
277
|
+
function toInbound(uid, parsed, internalDate) {
|
|
278
|
+
const { body, truncated } = truncateBody(messageText(parsed));
|
|
279
|
+
return {
|
|
280
|
+
uid,
|
|
281
|
+
from: parsed.from?.text ?? '',
|
|
282
|
+
to: parsed.to?.text ?? '',
|
|
283
|
+
subject: parsed.subject ?? '',
|
|
284
|
+
// The server's INTERNALDATE always exists; a Date header may be absent
|
|
285
|
+
// or malformed, and mailparser then leaves the field undefined. (imapflow
|
|
286
|
+
// types internalDate as string | Date depending on the fetch shape.)
|
|
287
|
+
date: isoDate(parsed.date ?? internalDate),
|
|
288
|
+
body,
|
|
289
|
+
...(truncated ? { truncated } : {}),
|
|
290
|
+
attachments: (parsed.attachments ?? []).map((a) => a.filename ?? '(unnamed)'),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/** Read the oldest matching messages from INBOX. */
|
|
294
|
+
export async function fetchInbox(account, opts = {}) {
|
|
295
|
+
const limit = clampLimit(opts.limit);
|
|
296
|
+
const markSeen = opts.markSeen !== false;
|
|
297
|
+
return withInbox(account, opts.signal, async (client) => {
|
|
261
298
|
// Only the two criteria every server implements the same way. The sender
|
|
262
299
|
// allowlist is applied below, host-side: IMAP `SEARCH FROM` is substring by
|
|
263
300
|
// spec but not in practice (GreenMail matches whole addresses only and
|
|
@@ -297,21 +334,7 @@ export async function fetchInbox(account, opts = {}) {
|
|
|
297
334
|
const msg = await client.fetchOne(String(uid), { source: true, internalDate: true }, { uid: true });
|
|
298
335
|
if (!msg || !msg.source)
|
|
299
336
|
continue;
|
|
300
|
-
|
|
301
|
-
const { body, truncated } = truncateBody(messageText(parsed));
|
|
302
|
-
messages.push({
|
|
303
|
-
uid,
|
|
304
|
-
from: parsed.from?.text ?? '',
|
|
305
|
-
to: parsed.to?.text ?? '',
|
|
306
|
-
subject: parsed.subject ?? '',
|
|
307
|
-
// The server's INTERNALDATE always exists; a Date header may be absent
|
|
308
|
-
// or malformed, and mailparser then leaves the field undefined. (imapflow
|
|
309
|
-
// types internalDate as string | Date depending on the fetch shape.)
|
|
310
|
-
date: isoDate(parsed.date ?? msg.internalDate),
|
|
311
|
-
body,
|
|
312
|
-
...(truncated ? { truncated } : {}),
|
|
313
|
-
attachments: (parsed.attachments ?? []).map((a) => a.filename ?? '(unnamed)'),
|
|
314
|
-
});
|
|
337
|
+
messages.push(toInbound(uid, await simpleParser(msg.source), msg.internalDate));
|
|
315
338
|
}
|
|
316
339
|
// Only what the agent actually received is marked read — a refused message
|
|
317
340
|
// is left untouched for the human.
|
|
@@ -319,10 +342,61 @@ export async function fetchInbox(account, opts = {}) {
|
|
|
319
342
|
await client.messageFlagsAdd(messages.map((m) => m.uid).join(','), ['\\Seen'], { uid: true });
|
|
320
343
|
}
|
|
321
344
|
return { messages, refused, ...(scanTruncated ? { scanTruncated } : {}) };
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
/** Oldest unseen envelopes the account may read; no bodies, no flag changes. */
|
|
348
|
+
export async function listUnseenEnvelopes(account, max, signal) {
|
|
349
|
+
// ponytail: no clamp beyond >= 1, the MAX_SCAN window already bounds it.
|
|
350
|
+
const limit = Math.max(1, Math.trunc(max) || 1);
|
|
351
|
+
return withInbox(account, signal, async (client) => {
|
|
352
|
+
const uidValidity = String(client.mailbox.uidValidity ?? '');
|
|
353
|
+
const uids = (await client.search({ seen: false }, { uid: true }));
|
|
354
|
+
const envelopes = [];
|
|
355
|
+
let refused = 0;
|
|
356
|
+
if (!uids || uids.length === 0)
|
|
357
|
+
return { envelopes, refused, scanTruncated: false, uidValidity };
|
|
358
|
+
const scanTruncated = uids.length > MAX_SCAN;
|
|
359
|
+
for await (const msg of client.fetch(uids.slice(0, MAX_SCAN).join(','), { envelope: true, uid: true, internalDate: true }, { uid: true })) {
|
|
360
|
+
const from = msg.envelope?.from?.[0]?.address ?? '';
|
|
361
|
+
if (!matchesAllowlist(from, account.allowedSenders)) {
|
|
362
|
+
refused++;
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
envelopes.push({
|
|
366
|
+
uid: msg.uid,
|
|
367
|
+
from,
|
|
368
|
+
subject: msg.envelope?.subject ?? '',
|
|
369
|
+
date: isoDate(msg.envelope?.date ?? msg.internalDate),
|
|
370
|
+
});
|
|
371
|
+
if (envelopes.length >= limit)
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
return { envelopes, refused, scanTruncated, uidValidity };
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
/** One message by UID, or null when it does not exist or its sender is not
|
|
378
|
+
* allowed. `source` is fetched as BODY.PEEK[], so `\Seen` stays untouched. */
|
|
379
|
+
export async function readMessage(account, uid, signal) {
|
|
380
|
+
return withInbox(account, signal, async (client) => {
|
|
381
|
+
const env = await client.fetchOne(String(uid), { envelope: true }, { uid: true });
|
|
382
|
+
if (!env)
|
|
383
|
+
return null;
|
|
384
|
+
if (!matchesAllowlist(env.envelope?.from?.[0]?.address ?? '', account.allowedSenders))
|
|
385
|
+
return null;
|
|
386
|
+
const msg = await client.fetchOne(String(uid), { source: true, internalDate: true }, { uid: true });
|
|
387
|
+
if (!msg || !msg.source)
|
|
388
|
+
return null;
|
|
389
|
+
return toInbound(uid, await simpleParser(msg.source), msg.internalDate);
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
/** Mark `uids` seen, unless the mailbox was reset since they were listed. */
|
|
393
|
+
export async function markSeen(account, uids, expectedUidValidity, signal) {
|
|
394
|
+
return withInbox(account, signal, async (client) => {
|
|
395
|
+
const current = String(client.mailbox.uidValidity ?? '');
|
|
396
|
+
if (current !== expectedUidValidity)
|
|
397
|
+
return 'uidvalidity-changed';
|
|
398
|
+
if (uids.length)
|
|
399
|
+
await client.messageFlagsAdd(uids.join(','), ['\\Seen'], { uid: true });
|
|
400
|
+
return 'marked';
|
|
401
|
+
});
|
|
328
402
|
}
|