@ghostpaw/email 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -4
- package/dist/cli.js +5 -2
- package/dist/index.cjs +67 -5
- package/dist/index.d.cts +39 -2
- package/dist/index.d.ts +39 -2
- package/dist/index.js +66 -4
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -117,8 +117,8 @@ surface designed to minimise LLM cognitive load:
|
|
|
117
117
|
import { skills, soul, tools } from '@ghostpaw/email';
|
|
118
118
|
|
|
119
119
|
// 5 intent-shaped tools covering the full mailbox lifecycle
|
|
120
|
-
const allTools = tools.emailTools;
|
|
121
|
-
const readTool = tools.getEmailToolByName('mail_read');
|
|
120
|
+
const allTools = tools.aligned.emailTools;
|
|
121
|
+
const readTool = tools.aligned.getEmailToolByName('mail_read');
|
|
122
122
|
|
|
123
123
|
// 8 reusable workflow skills for multi-step scenarios
|
|
124
124
|
const triageSkill = skills.getEmailSkillByName('triage-inbox');
|
|
@@ -127,8 +127,28 @@ const triageSkill = skills.getEmailSkillByName('triage-inbox');
|
|
|
127
127
|
const systemPrompt = soul.renderEmailSoulPromptFoundation();
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
The shared facade exposes `name`, `description`, `whenToUse`, `whenNotToUse`,
|
|
131
|
+
`inputSchema`, `readOnly`, and `sideEffects`. Handlers take a context containing
|
|
132
|
+
`read`, `write`, and `network` surfaces and the existing tool input. They return
|
|
133
|
+
`{ ok, outcome, summary, next, data }`; `data.entities` contains the message or
|
|
134
|
+
mailbox references, and `next` contains follow-up hints. Errors map to `ok: false`.
|
|
135
|
+
Read operations may refresh the local cache, so metadata conservatively marks
|
|
136
|
+
all tools as writing state.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
const definitions = tools.aligned.listEmailToolDefinitions();
|
|
140
|
+
const tool = tools.aligned.getEmailToolByName('mail_read');
|
|
141
|
+
if (!tool) throw new Error('mail_read is unavailable');
|
|
142
|
+
const result = await tool.handler(
|
|
143
|
+
{ read: mailbox.read, write: mailbox.write, network: mailbox.network },
|
|
144
|
+
{ view: 'folders' },
|
|
145
|
+
);
|
|
146
|
+
console.log(result.ok, result.summary);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The deprecated `tools.emailTools` and `tools.getEmailToolByName()` remain
|
|
150
|
+
available with the original `{ outcome, summary, entities, nextSteps }` result
|
|
151
|
+
and unchanged inputs. Migrate to `tools.aligned` to use the shared shape.
|
|
132
152
|
|
|
133
153
|
See [LLM.md](docs/LLM.md) for the full AI-facing guide covering soul, tools,
|
|
134
154
|
and skills.
|
package/dist/cli.js
CHANGED
|
@@ -11,7 +11,6 @@ import { EventEmitter } from 'events';
|
|
|
11
11
|
import * as net from 'net';
|
|
12
12
|
import * as tls from 'tls';
|
|
13
13
|
import * as zlib from 'zlib';
|
|
14
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
15
14
|
import { randomUUID } from 'crypto';
|
|
16
15
|
|
|
17
16
|
var __defProp = Object.defineProperty;
|
|
@@ -4521,7 +4520,8 @@ async function statusFolder(dispatcher, path) {
|
|
|
4521
4520
|
let highestModSeq = null;
|
|
4522
4521
|
for (const u3 of res.untagged) {
|
|
4523
4522
|
if (u3.type === "STATUS" && Array.isArray(u3.data)) {
|
|
4524
|
-
const
|
|
4523
|
+
const data = u3.data;
|
|
4524
|
+
const arr = Array.isArray(data[1]) ? data[1] : data;
|
|
4525
4525
|
for (let i2 = 0; i2 + 1 < arr.length; i2 += 2) {
|
|
4526
4526
|
const k2 = tokStr2(arr[i2]).toUpperCase();
|
|
4527
4527
|
const v2 = tokNum2(arr[i2 + 1]);
|
|
@@ -7188,7 +7188,10 @@ function initSchema(db) {
|
|
|
7188
7188
|
// src/runtime.ts
|
|
7189
7189
|
function init2(config) {
|
|
7190
7190
|
const dbPath = config.storage ?? ":memory:";
|
|
7191
|
+
const { DatabaseSync } = process.getBuiltinModule("node:sqlite");
|
|
7191
7192
|
const db = new DatabaseSync(dbPath);
|
|
7193
|
+
if (dbPath !== ":memory:") db.exec("PRAGMA journal_mode=WAL");
|
|
7194
|
+
db.exec("PRAGMA busy_timeout=5000");
|
|
7192
7195
|
initSchema(db);
|
|
7193
7196
|
return { db };
|
|
7194
7197
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,6 @@ var events = require('events');
|
|
|
4
4
|
var net = require('net');
|
|
5
5
|
var tls = require('tls');
|
|
6
6
|
var zlib = require('zlib');
|
|
7
|
-
var sqlite = require('node:sqlite');
|
|
8
7
|
var crypto = require('crypto');
|
|
9
8
|
|
|
10
9
|
function _interopNamespace(e) {
|
|
@@ -975,7 +974,8 @@ async function statusFolder(dispatcher, path) {
|
|
|
975
974
|
let highestModSeq = null;
|
|
976
975
|
for (const u of res.untagged) {
|
|
977
976
|
if (u.type === "STATUS" && Array.isArray(u.data)) {
|
|
978
|
-
const
|
|
977
|
+
const data = u.data;
|
|
978
|
+
const arr = Array.isArray(data[1]) ? data[1] : data;
|
|
979
979
|
for (let i = 0; i + 1 < arr.length; i += 2) {
|
|
980
980
|
const k = tokStr2(arr[i]).toUpperCase();
|
|
981
981
|
const v = tokNum2(arr[i + 1]);
|
|
@@ -3866,7 +3866,10 @@ function initSchema(db) {
|
|
|
3866
3866
|
// src/runtime.ts
|
|
3867
3867
|
function init(config) {
|
|
3868
3868
|
const dbPath = config.storage ?? ":memory:";
|
|
3869
|
-
const
|
|
3869
|
+
const { DatabaseSync } = process.getBuiltinModule("node:sqlite");
|
|
3870
|
+
const db = new DatabaseSync(dbPath);
|
|
3871
|
+
if (dbPath !== ":memory:") db.exec("PRAGMA journal_mode=WAL");
|
|
3872
|
+
db.exec("PRAGMA busy_timeout=5000");
|
|
3870
3873
|
initSchema(db);
|
|
3871
3874
|
return { db };
|
|
3872
3875
|
}
|
|
@@ -5146,8 +5149,17 @@ __export(sync_exports, {
|
|
|
5146
5149
|
// src/tools/index.ts
|
|
5147
5150
|
var tools_exports = {};
|
|
5148
5151
|
__export(tools_exports, {
|
|
5152
|
+
aligned: () => aligned_exports,
|
|
5149
5153
|
emailTools: () => emailTools,
|
|
5150
|
-
getEmailToolByName: () =>
|
|
5154
|
+
getEmailToolByName: () => getEmailToolByName2
|
|
5155
|
+
});
|
|
5156
|
+
|
|
5157
|
+
// src/tools/aligned.ts
|
|
5158
|
+
var aligned_exports = {};
|
|
5159
|
+
__export(aligned_exports, {
|
|
5160
|
+
emailTools: () => emailTools2,
|
|
5161
|
+
getEmailToolByName: () => getEmailToolByName,
|
|
5162
|
+
listEmailToolDefinitions: () => listEmailToolDefinitions
|
|
5151
5163
|
});
|
|
5152
5164
|
|
|
5153
5165
|
// src/tools/email_tools.ts
|
|
@@ -5871,8 +5883,58 @@ var emailTools = [
|
|
|
5871
5883
|
}
|
|
5872
5884
|
];
|
|
5873
5885
|
|
|
5874
|
-
// src/tools/
|
|
5886
|
+
// src/tools/aligned.ts
|
|
5887
|
+
var usage = {
|
|
5888
|
+
mail_read: {
|
|
5889
|
+
whenToUse: "Inspect folders, cached messages, threads, attachments or raw message content.",
|
|
5890
|
+
whenNotToUse: "Use mail_search to find messages by query or mail_organize to change them."
|
|
5891
|
+
},
|
|
5892
|
+
mail_search: {
|
|
5893
|
+
whenToUse: "Find messages by a local full-text query or a remote IMAP search.",
|
|
5894
|
+
whenNotToUse: "Use mail_read when the folder and message UID are already known."
|
|
5895
|
+
},
|
|
5896
|
+
mail_compose: {
|
|
5897
|
+
whenToUse: "Send, reply, forward, or save and manage a draft after its content is agreed.",
|
|
5898
|
+
whenNotToUse: "Use mail_read to inspect an existing message without sending or saving content."
|
|
5899
|
+
},
|
|
5900
|
+
mail_organize: {
|
|
5901
|
+
whenToUse: "Change message flags, labels, destinations or folder organization.",
|
|
5902
|
+
whenNotToUse: "Use mail_read or mail_search when only inspection is requested."
|
|
5903
|
+
},
|
|
5904
|
+
mail_sync: {
|
|
5905
|
+
whenToUse: "Connect, disconnect, reconnect, refresh folders or synchronize the cache.",
|
|
5906
|
+
whenNotToUse: "Use mail_read for cached content or the network watch stream for continuous monitoring."
|
|
5907
|
+
}
|
|
5908
|
+
};
|
|
5909
|
+
var emailTools2 = emailTools.map((tool) => ({
|
|
5910
|
+
name: tool.name,
|
|
5911
|
+
description: tool.description,
|
|
5912
|
+
whenToUse: usage[tool.name]?.whenToUse ?? tool.description,
|
|
5913
|
+
whenNotToUse: usage[tool.name]?.whenNotToUse ?? "Use a tool matching the requested operation.",
|
|
5914
|
+
inputSchema: tool.inputSchema,
|
|
5915
|
+
// Read tools can fetch remote data and update the local cache.
|
|
5916
|
+
readOnly: false,
|
|
5917
|
+
sideEffects: "writes_state",
|
|
5918
|
+
async handler(ctx, input) {
|
|
5919
|
+
const result = await tool.handler(ctx, input);
|
|
5920
|
+
return {
|
|
5921
|
+
ok: result.outcome === "success" || result.outcome === "no_op",
|
|
5922
|
+
outcome: result.outcome,
|
|
5923
|
+
summary: result.summary,
|
|
5924
|
+
next: result.nextSteps.map((message) => ({ kind: "use_tool", message })),
|
|
5925
|
+
data: { entities: result.entities }
|
|
5926
|
+
};
|
|
5927
|
+
}
|
|
5928
|
+
}));
|
|
5929
|
+
function listEmailToolDefinitions() {
|
|
5930
|
+
return [...emailTools2];
|
|
5931
|
+
}
|
|
5875
5932
|
function getEmailToolByName(name) {
|
|
5933
|
+
return emailTools2.find((tool) => tool.name === name) ?? null;
|
|
5934
|
+
}
|
|
5935
|
+
|
|
5936
|
+
// src/tools/get_email_tool_by_name.ts
|
|
5937
|
+
function getEmailToolByName2(name) {
|
|
5876
5938
|
return emailTools.find((tool) => tool.name === name);
|
|
5877
5939
|
}
|
|
5878
5940
|
|
package/dist/index.d.cts
CHANGED
|
@@ -1348,6 +1348,40 @@ interface EmailToolDefinition<TInput = unknown> {
|
|
|
1348
1348
|
handler(ctx: EmailToolContext, input: TInput): Promise<EmailToolResult>;
|
|
1349
1349
|
}
|
|
1350
1350
|
|
|
1351
|
+
interface SharedEmailToolResult {
|
|
1352
|
+
ok: boolean;
|
|
1353
|
+
outcome: ToolOutcomeKind;
|
|
1354
|
+
summary: string;
|
|
1355
|
+
next: {
|
|
1356
|
+
kind: 'use_tool';
|
|
1357
|
+
message: string;
|
|
1358
|
+
}[];
|
|
1359
|
+
data: {
|
|
1360
|
+
entities: EmailToolResult['entities'];
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
interface SharedEmailToolDefinition {
|
|
1364
|
+
name: string;
|
|
1365
|
+
description: string;
|
|
1366
|
+
whenToUse: string;
|
|
1367
|
+
whenNotToUse: string;
|
|
1368
|
+
inputSchema: JsonSchema;
|
|
1369
|
+
readOnly: boolean;
|
|
1370
|
+
sideEffects: 'none' | 'writes_state';
|
|
1371
|
+
handler(ctx: EmailToolContext, input: unknown): Promise<SharedEmailToolResult>;
|
|
1372
|
+
}
|
|
1373
|
+
/** Shared metadata and result adapters; legacy handlers remain available unchanged. */
|
|
1374
|
+
declare const emailTools$1: readonly SharedEmailToolDefinition[];
|
|
1375
|
+
declare function listEmailToolDefinitions(): SharedEmailToolDefinition[];
|
|
1376
|
+
declare function getEmailToolByName$1(name: string): SharedEmailToolDefinition | null;
|
|
1377
|
+
|
|
1378
|
+
type aligned_SharedEmailToolDefinition = SharedEmailToolDefinition;
|
|
1379
|
+
type aligned_SharedEmailToolResult = SharedEmailToolResult;
|
|
1380
|
+
declare const aligned_listEmailToolDefinitions: typeof listEmailToolDefinitions;
|
|
1381
|
+
declare namespace aligned {
|
|
1382
|
+
export { type aligned_SharedEmailToolDefinition as SharedEmailToolDefinition, type aligned_SharedEmailToolResult as SharedEmailToolResult, emailTools$1 as emailTools, getEmailToolByName$1 as getEmailToolByName, aligned_listEmailToolDefinitions as listEmailToolDefinitions };
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1351
1385
|
type MailReadInput = {
|
|
1352
1386
|
view: 'folders';
|
|
1353
1387
|
refresh?: boolean;
|
|
@@ -1454,6 +1488,7 @@ type MailSyncInput = {
|
|
|
1454
1488
|
action: 'watch';
|
|
1455
1489
|
folders?: string[];
|
|
1456
1490
|
};
|
|
1491
|
+
/** @deprecated Use tools.aligned.emailTools for the shared result shape. */
|
|
1457
1492
|
declare const emailTools: ({
|
|
1458
1493
|
name: string;
|
|
1459
1494
|
description: string;
|
|
@@ -1837,6 +1872,7 @@ declare const emailTools: ({
|
|
|
1837
1872
|
}>;
|
|
1838
1873
|
})[];
|
|
1839
1874
|
|
|
1875
|
+
/** @deprecated Use tools.aligned.getEmailToolByName for the shared result shape. */
|
|
1840
1876
|
declare function getEmailToolByName(name: string): EmailToolDefinition<unknown> | undefined;
|
|
1841
1877
|
|
|
1842
1878
|
type index$1_EmailToolContext = EmailToolContext;
|
|
@@ -1848,10 +1884,11 @@ type index$1_ToolEntityKind = ToolEntityKind;
|
|
|
1848
1884
|
type index$1_ToolEntityRef = ToolEntityRef;
|
|
1849
1885
|
type index$1_ToolOutcomeKind = ToolOutcomeKind;
|
|
1850
1886
|
type index$1_ToolSideEffects = ToolSideEffects;
|
|
1887
|
+
declare const index$1_aligned: typeof aligned;
|
|
1851
1888
|
declare const index$1_emailTools: typeof emailTools;
|
|
1852
1889
|
declare const index$1_getEmailToolByName: typeof getEmailToolByName;
|
|
1853
1890
|
declare namespace index$1 {
|
|
1854
|
-
export { type index$1_EmailToolContext as EmailToolContext, type index$1_EmailToolDefinition as EmailToolDefinition, type index$1_EmailToolResult as EmailToolResult, type index$1_JsonSchema as JsonSchema, type index$1_JsonSchemaType as JsonSchemaType, type index$1_ToolEntityKind as ToolEntityKind, type index$1_ToolEntityRef as ToolEntityRef, type index$1_ToolOutcomeKind as ToolOutcomeKind, type index$1_ToolSideEffects as ToolSideEffects, index$1_emailTools as emailTools, index$1_getEmailToolByName as getEmailToolByName };
|
|
1891
|
+
export { type index$1_EmailToolContext as EmailToolContext, type index$1_EmailToolDefinition as EmailToolDefinition, type index$1_EmailToolResult as EmailToolResult, type index$1_JsonSchema as JsonSchema, type index$1_JsonSchemaType as JsonSchemaType, type index$1_ToolEntityKind as ToolEntityKind, type index$1_ToolEntityRef as ToolEntityRef, type index$1_ToolOutcomeKind as ToolOutcomeKind, type index$1_ToolSideEffects as ToolSideEffects, index$1_aligned as aligned, index$1_emailTools as emailTools, index$1_getEmailToolByName as getEmailToolByName };
|
|
1855
1892
|
}
|
|
1856
1893
|
|
|
1857
1894
|
declare const DEFAULT_CONNECTION_TIMEOUT = 30000;
|
|
@@ -1957,4 +1994,4 @@ declare namespace write {
|
|
|
1957
1994
|
export { type write_CreateWriteSurfaceOptions as CreateWriteSurfaceOptions, write_createWriteSurface as createWriteSurface };
|
|
1958
1995
|
}
|
|
1959
1996
|
|
|
1960
|
-
export { type Account, type AccountStats, type Address, type Attachment, type AttachmentMeta, type AuthConfig, type BodyPart, type ComposeAttachment, type ComposeInput, type ContinuationResponse, DEFAULT_AUTO_EXPUNGE, DEFAULT_BATCH_SIZE, DEFAULT_CHARSET, DEFAULT_COMPRESS, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_IDLE_TIMEOUT, DEFAULT_KEEPALIVE_INTERVAL, DEFAULT_MAX_ATTACHMENT_CACHE, DEFAULT_MAX_BODY_CACHE, DEFAULT_MAX_CONNECTIONS, DEFAULT_MAX_MESSAGE_SIZE, DEFAULT_MAX_NESTING_DEPTH, DEFAULT_MAX_RECONNECT_ATTEMPTS, DEFAULT_MAX_RECONNECT_DELAY, DEFAULT_PIPELINING, DEFAULT_SOCKET_TIMEOUT, DEFAULT_SYNC_DELETED_FOLDERS, DEFAULT_TAG_PREFIX, DEFAULT_WATCH_FOLDERS, EmailAuthError, type EmailConfig, EmailConnectionError, type EmailDb, EmailEnvelopeRejectedError, EmailError, type EmailErrorCode, EmailInvariantError, type EmailNetworkSurface, EmailNotFoundError, EmailProtocolError, EmailQuotaError, type EmailReadSurface, type EmailRuntimeSurface, type EmailSkill, type EmailSkillRegistry, type EmailSoul, type EmailSoulTrait, EmailStateError, EmailTimeoutError, type EmailToolContext, type EmailToolDefinition, type EmailToolResult, EmailUnsupportedError, EmailValidationError, type EmailWriteSurface, type FetchResult, type Folder, type FolderRole, type FolderStatus, type ForwardInput, type ImapResponse, type ImapToken, type InsertMessageInput, type JsonSchema, type JsonSchemaType, type LocalSearchOptions, Mailbox, type Message, type MessageBody, type MessageDetail, type MessageListOptions, type NegotiatedExtensions, type ParsedEnvelope, type ReplyInput, type ResponseCode, type SearchQuery, type SelectedFolder, type SmtpErrorCategory, type SmtpResponse, type SyncFolderResult, type SyncOptions, type SyncResult, type TaggedResponse, type Thread, type ThreadListOptions, type ThreadMessage, type TokenType, type ToolEntityKind, type ToolEntityRef, type ToolOutcomeKind, type ToolSideEffects, type UntaggedResponse, type WatchEvent, type WatchOptions, attachmentWorkflowSkill, composeAndSendSkill, connectAndSyncSkill, defineEmailSkill, emailSkills, emailSoul, emailSoulEssence, emailSoulTraits, emailTools, errors, getEmailSkillByName, getEmailToolByName, index$8 as imap, initSchema, isEmailError, isRetriable, index$7 as mime, network, organizeBulkSkill, read, readAndReplySkill, recoverFromDisruptionSkill, renderEmailSoulPromptFoundation, runtime, index$6 as schema, searchAndActSkill, index$5 as skills, index$4 as smtp, soul, index$3 as store, index$2 as sync, index$1 as tools, triageInboxSkill, index as types, write };
|
|
1997
|
+
export { type Account, type AccountStats, type Address, type Attachment, type AttachmentMeta, type AuthConfig, type BodyPart, type ComposeAttachment, type ComposeInput, type ContinuationResponse, DEFAULT_AUTO_EXPUNGE, DEFAULT_BATCH_SIZE, DEFAULT_CHARSET, DEFAULT_COMPRESS, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_IDLE_TIMEOUT, DEFAULT_KEEPALIVE_INTERVAL, DEFAULT_MAX_ATTACHMENT_CACHE, DEFAULT_MAX_BODY_CACHE, DEFAULT_MAX_CONNECTIONS, DEFAULT_MAX_MESSAGE_SIZE, DEFAULT_MAX_NESTING_DEPTH, DEFAULT_MAX_RECONNECT_ATTEMPTS, DEFAULT_MAX_RECONNECT_DELAY, DEFAULT_PIPELINING, DEFAULT_SOCKET_TIMEOUT, DEFAULT_SYNC_DELETED_FOLDERS, DEFAULT_TAG_PREFIX, DEFAULT_WATCH_FOLDERS, EmailAuthError, type EmailConfig, EmailConnectionError, type EmailDb, EmailEnvelopeRejectedError, EmailError, type EmailErrorCode, EmailInvariantError, type EmailNetworkSurface, EmailNotFoundError, EmailProtocolError, EmailQuotaError, type EmailReadSurface, type EmailRuntimeSurface, type EmailSkill, type EmailSkillRegistry, type EmailSoul, type EmailSoulTrait, EmailStateError, EmailTimeoutError, type EmailToolContext, type EmailToolDefinition, type EmailToolResult, EmailUnsupportedError, EmailValidationError, type EmailWriteSurface, type FetchResult, type Folder, type FolderRole, type FolderStatus, type ForwardInput, type ImapResponse, type ImapToken, type InsertMessageInput, type JsonSchema, type JsonSchemaType, type LocalSearchOptions, Mailbox, type Message, type MessageBody, type MessageDetail, type MessageListOptions, type NegotiatedExtensions, type ParsedEnvelope, type ReplyInput, type ResponseCode, type SearchQuery, type SelectedFolder, type SmtpErrorCategory, type SmtpResponse, type SyncFolderResult, type SyncOptions, type SyncResult, type TaggedResponse, type Thread, type ThreadListOptions, type ThreadMessage, type TokenType, type ToolEntityKind, type ToolEntityRef, type ToolOutcomeKind, type ToolSideEffects, type UntaggedResponse, type WatchEvent, type WatchOptions, aligned, attachmentWorkflowSkill, composeAndSendSkill, connectAndSyncSkill, defineEmailSkill, emailSkills, emailSoul, emailSoulEssence, emailSoulTraits, emailTools, errors, getEmailSkillByName, getEmailToolByName, index$8 as imap, initSchema, isEmailError, isRetriable, index$7 as mime, network, organizeBulkSkill, read, readAndReplySkill, recoverFromDisruptionSkill, renderEmailSoulPromptFoundation, runtime, index$6 as schema, searchAndActSkill, index$5 as skills, index$4 as smtp, soul, index$3 as store, index$2 as sync, index$1 as tools, triageInboxSkill, index as types, write };
|
package/dist/index.d.ts
CHANGED
|
@@ -1348,6 +1348,40 @@ interface EmailToolDefinition<TInput = unknown> {
|
|
|
1348
1348
|
handler(ctx: EmailToolContext, input: TInput): Promise<EmailToolResult>;
|
|
1349
1349
|
}
|
|
1350
1350
|
|
|
1351
|
+
interface SharedEmailToolResult {
|
|
1352
|
+
ok: boolean;
|
|
1353
|
+
outcome: ToolOutcomeKind;
|
|
1354
|
+
summary: string;
|
|
1355
|
+
next: {
|
|
1356
|
+
kind: 'use_tool';
|
|
1357
|
+
message: string;
|
|
1358
|
+
}[];
|
|
1359
|
+
data: {
|
|
1360
|
+
entities: EmailToolResult['entities'];
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
interface SharedEmailToolDefinition {
|
|
1364
|
+
name: string;
|
|
1365
|
+
description: string;
|
|
1366
|
+
whenToUse: string;
|
|
1367
|
+
whenNotToUse: string;
|
|
1368
|
+
inputSchema: JsonSchema;
|
|
1369
|
+
readOnly: boolean;
|
|
1370
|
+
sideEffects: 'none' | 'writes_state';
|
|
1371
|
+
handler(ctx: EmailToolContext, input: unknown): Promise<SharedEmailToolResult>;
|
|
1372
|
+
}
|
|
1373
|
+
/** Shared metadata and result adapters; legacy handlers remain available unchanged. */
|
|
1374
|
+
declare const emailTools$1: readonly SharedEmailToolDefinition[];
|
|
1375
|
+
declare function listEmailToolDefinitions(): SharedEmailToolDefinition[];
|
|
1376
|
+
declare function getEmailToolByName$1(name: string): SharedEmailToolDefinition | null;
|
|
1377
|
+
|
|
1378
|
+
type aligned_SharedEmailToolDefinition = SharedEmailToolDefinition;
|
|
1379
|
+
type aligned_SharedEmailToolResult = SharedEmailToolResult;
|
|
1380
|
+
declare const aligned_listEmailToolDefinitions: typeof listEmailToolDefinitions;
|
|
1381
|
+
declare namespace aligned {
|
|
1382
|
+
export { type aligned_SharedEmailToolDefinition as SharedEmailToolDefinition, type aligned_SharedEmailToolResult as SharedEmailToolResult, emailTools$1 as emailTools, getEmailToolByName$1 as getEmailToolByName, aligned_listEmailToolDefinitions as listEmailToolDefinitions };
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1351
1385
|
type MailReadInput = {
|
|
1352
1386
|
view: 'folders';
|
|
1353
1387
|
refresh?: boolean;
|
|
@@ -1454,6 +1488,7 @@ type MailSyncInput = {
|
|
|
1454
1488
|
action: 'watch';
|
|
1455
1489
|
folders?: string[];
|
|
1456
1490
|
};
|
|
1491
|
+
/** @deprecated Use tools.aligned.emailTools for the shared result shape. */
|
|
1457
1492
|
declare const emailTools: ({
|
|
1458
1493
|
name: string;
|
|
1459
1494
|
description: string;
|
|
@@ -1837,6 +1872,7 @@ declare const emailTools: ({
|
|
|
1837
1872
|
}>;
|
|
1838
1873
|
})[];
|
|
1839
1874
|
|
|
1875
|
+
/** @deprecated Use tools.aligned.getEmailToolByName for the shared result shape. */
|
|
1840
1876
|
declare function getEmailToolByName(name: string): EmailToolDefinition<unknown> | undefined;
|
|
1841
1877
|
|
|
1842
1878
|
type index$1_EmailToolContext = EmailToolContext;
|
|
@@ -1848,10 +1884,11 @@ type index$1_ToolEntityKind = ToolEntityKind;
|
|
|
1848
1884
|
type index$1_ToolEntityRef = ToolEntityRef;
|
|
1849
1885
|
type index$1_ToolOutcomeKind = ToolOutcomeKind;
|
|
1850
1886
|
type index$1_ToolSideEffects = ToolSideEffects;
|
|
1887
|
+
declare const index$1_aligned: typeof aligned;
|
|
1851
1888
|
declare const index$1_emailTools: typeof emailTools;
|
|
1852
1889
|
declare const index$1_getEmailToolByName: typeof getEmailToolByName;
|
|
1853
1890
|
declare namespace index$1 {
|
|
1854
|
-
export { type index$1_EmailToolContext as EmailToolContext, type index$1_EmailToolDefinition as EmailToolDefinition, type index$1_EmailToolResult as EmailToolResult, type index$1_JsonSchema as JsonSchema, type index$1_JsonSchemaType as JsonSchemaType, type index$1_ToolEntityKind as ToolEntityKind, type index$1_ToolEntityRef as ToolEntityRef, type index$1_ToolOutcomeKind as ToolOutcomeKind, type index$1_ToolSideEffects as ToolSideEffects, index$1_emailTools as emailTools, index$1_getEmailToolByName as getEmailToolByName };
|
|
1891
|
+
export { type index$1_EmailToolContext as EmailToolContext, type index$1_EmailToolDefinition as EmailToolDefinition, type index$1_EmailToolResult as EmailToolResult, type index$1_JsonSchema as JsonSchema, type index$1_JsonSchemaType as JsonSchemaType, type index$1_ToolEntityKind as ToolEntityKind, type index$1_ToolEntityRef as ToolEntityRef, type index$1_ToolOutcomeKind as ToolOutcomeKind, type index$1_ToolSideEffects as ToolSideEffects, index$1_aligned as aligned, index$1_emailTools as emailTools, index$1_getEmailToolByName as getEmailToolByName };
|
|
1855
1892
|
}
|
|
1856
1893
|
|
|
1857
1894
|
declare const DEFAULT_CONNECTION_TIMEOUT = 30000;
|
|
@@ -1957,4 +1994,4 @@ declare namespace write {
|
|
|
1957
1994
|
export { type write_CreateWriteSurfaceOptions as CreateWriteSurfaceOptions, write_createWriteSurface as createWriteSurface };
|
|
1958
1995
|
}
|
|
1959
1996
|
|
|
1960
|
-
export { type Account, type AccountStats, type Address, type Attachment, type AttachmentMeta, type AuthConfig, type BodyPart, type ComposeAttachment, type ComposeInput, type ContinuationResponse, DEFAULT_AUTO_EXPUNGE, DEFAULT_BATCH_SIZE, DEFAULT_CHARSET, DEFAULT_COMPRESS, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_IDLE_TIMEOUT, DEFAULT_KEEPALIVE_INTERVAL, DEFAULT_MAX_ATTACHMENT_CACHE, DEFAULT_MAX_BODY_CACHE, DEFAULT_MAX_CONNECTIONS, DEFAULT_MAX_MESSAGE_SIZE, DEFAULT_MAX_NESTING_DEPTH, DEFAULT_MAX_RECONNECT_ATTEMPTS, DEFAULT_MAX_RECONNECT_DELAY, DEFAULT_PIPELINING, DEFAULT_SOCKET_TIMEOUT, DEFAULT_SYNC_DELETED_FOLDERS, DEFAULT_TAG_PREFIX, DEFAULT_WATCH_FOLDERS, EmailAuthError, type EmailConfig, EmailConnectionError, type EmailDb, EmailEnvelopeRejectedError, EmailError, type EmailErrorCode, EmailInvariantError, type EmailNetworkSurface, EmailNotFoundError, EmailProtocolError, EmailQuotaError, type EmailReadSurface, type EmailRuntimeSurface, type EmailSkill, type EmailSkillRegistry, type EmailSoul, type EmailSoulTrait, EmailStateError, EmailTimeoutError, type EmailToolContext, type EmailToolDefinition, type EmailToolResult, EmailUnsupportedError, EmailValidationError, type EmailWriteSurface, type FetchResult, type Folder, type FolderRole, type FolderStatus, type ForwardInput, type ImapResponse, type ImapToken, type InsertMessageInput, type JsonSchema, type JsonSchemaType, type LocalSearchOptions, Mailbox, type Message, type MessageBody, type MessageDetail, type MessageListOptions, type NegotiatedExtensions, type ParsedEnvelope, type ReplyInput, type ResponseCode, type SearchQuery, type SelectedFolder, type SmtpErrorCategory, type SmtpResponse, type SyncFolderResult, type SyncOptions, type SyncResult, type TaggedResponse, type Thread, type ThreadListOptions, type ThreadMessage, type TokenType, type ToolEntityKind, type ToolEntityRef, type ToolOutcomeKind, type ToolSideEffects, type UntaggedResponse, type WatchEvent, type WatchOptions, attachmentWorkflowSkill, composeAndSendSkill, connectAndSyncSkill, defineEmailSkill, emailSkills, emailSoul, emailSoulEssence, emailSoulTraits, emailTools, errors, getEmailSkillByName, getEmailToolByName, index$8 as imap, initSchema, isEmailError, isRetriable, index$7 as mime, network, organizeBulkSkill, read, readAndReplySkill, recoverFromDisruptionSkill, renderEmailSoulPromptFoundation, runtime, index$6 as schema, searchAndActSkill, index$5 as skills, index$4 as smtp, soul, index$3 as store, index$2 as sync, index$1 as tools, triageInboxSkill, index as types, write };
|
|
1997
|
+
export { type Account, type AccountStats, type Address, type Attachment, type AttachmentMeta, type AuthConfig, type BodyPart, type ComposeAttachment, type ComposeInput, type ContinuationResponse, DEFAULT_AUTO_EXPUNGE, DEFAULT_BATCH_SIZE, DEFAULT_CHARSET, DEFAULT_COMPRESS, DEFAULT_CONNECTION_TIMEOUT, DEFAULT_IDLE_TIMEOUT, DEFAULT_KEEPALIVE_INTERVAL, DEFAULT_MAX_ATTACHMENT_CACHE, DEFAULT_MAX_BODY_CACHE, DEFAULT_MAX_CONNECTIONS, DEFAULT_MAX_MESSAGE_SIZE, DEFAULT_MAX_NESTING_DEPTH, DEFAULT_MAX_RECONNECT_ATTEMPTS, DEFAULT_MAX_RECONNECT_DELAY, DEFAULT_PIPELINING, DEFAULT_SOCKET_TIMEOUT, DEFAULT_SYNC_DELETED_FOLDERS, DEFAULT_TAG_PREFIX, DEFAULT_WATCH_FOLDERS, EmailAuthError, type EmailConfig, EmailConnectionError, type EmailDb, EmailEnvelopeRejectedError, EmailError, type EmailErrorCode, EmailInvariantError, type EmailNetworkSurface, EmailNotFoundError, EmailProtocolError, EmailQuotaError, type EmailReadSurface, type EmailRuntimeSurface, type EmailSkill, type EmailSkillRegistry, type EmailSoul, type EmailSoulTrait, EmailStateError, EmailTimeoutError, type EmailToolContext, type EmailToolDefinition, type EmailToolResult, EmailUnsupportedError, EmailValidationError, type EmailWriteSurface, type FetchResult, type Folder, type FolderRole, type FolderStatus, type ForwardInput, type ImapResponse, type ImapToken, type InsertMessageInput, type JsonSchema, type JsonSchemaType, type LocalSearchOptions, Mailbox, type Message, type MessageBody, type MessageDetail, type MessageListOptions, type NegotiatedExtensions, type ParsedEnvelope, type ReplyInput, type ResponseCode, type SearchQuery, type SelectedFolder, type SmtpErrorCategory, type SmtpResponse, type SyncFolderResult, type SyncOptions, type SyncResult, type TaggedResponse, type Thread, type ThreadListOptions, type ThreadMessage, type TokenType, type ToolEntityKind, type ToolEntityRef, type ToolOutcomeKind, type ToolSideEffects, type UntaggedResponse, type WatchEvent, type WatchOptions, aligned, attachmentWorkflowSkill, composeAndSendSkill, connectAndSyncSkill, defineEmailSkill, emailSkills, emailSoul, emailSoulEssence, emailSoulTraits, emailTools, errors, getEmailSkillByName, getEmailToolByName, index$8 as imap, initSchema, isEmailError, isRetriable, index$7 as mime, network, organizeBulkSkill, read, readAndReplySkill, recoverFromDisruptionSkill, renderEmailSoulPromptFoundation, runtime, index$6 as schema, searchAndActSkill, index$5 as skills, index$4 as smtp, soul, index$3 as store, index$2 as sync, index$1 as tools, triageInboxSkill, index as types, write };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { EventEmitter } from 'events';
|
|
|
2
2
|
import * as net from 'net';
|
|
3
3
|
import * as tls from 'tls';
|
|
4
4
|
import * as zlib from 'zlib';
|
|
5
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
6
5
|
import { randomUUID } from 'crypto';
|
|
7
6
|
|
|
8
7
|
var __defProp = Object.defineProperty;
|
|
@@ -951,7 +950,8 @@ async function statusFolder(dispatcher, path) {
|
|
|
951
950
|
let highestModSeq = null;
|
|
952
951
|
for (const u of res.untagged) {
|
|
953
952
|
if (u.type === "STATUS" && Array.isArray(u.data)) {
|
|
954
|
-
const
|
|
953
|
+
const data = u.data;
|
|
954
|
+
const arr = Array.isArray(data[1]) ? data[1] : data;
|
|
955
955
|
for (let i = 0; i + 1 < arr.length; i += 2) {
|
|
956
956
|
const k = tokStr2(arr[i]).toUpperCase();
|
|
957
957
|
const v = tokNum2(arr[i + 1]);
|
|
@@ -3842,7 +3842,10 @@ function initSchema(db) {
|
|
|
3842
3842
|
// src/runtime.ts
|
|
3843
3843
|
function init(config) {
|
|
3844
3844
|
const dbPath = config.storage ?? ":memory:";
|
|
3845
|
+
const { DatabaseSync } = process.getBuiltinModule("node:sqlite");
|
|
3845
3846
|
const db = new DatabaseSync(dbPath);
|
|
3847
|
+
if (dbPath !== ":memory:") db.exec("PRAGMA journal_mode=WAL");
|
|
3848
|
+
db.exec("PRAGMA busy_timeout=5000");
|
|
3846
3849
|
initSchema(db);
|
|
3847
3850
|
return { db };
|
|
3848
3851
|
}
|
|
@@ -5122,8 +5125,17 @@ __export(sync_exports, {
|
|
|
5122
5125
|
// src/tools/index.ts
|
|
5123
5126
|
var tools_exports = {};
|
|
5124
5127
|
__export(tools_exports, {
|
|
5128
|
+
aligned: () => aligned_exports,
|
|
5125
5129
|
emailTools: () => emailTools,
|
|
5126
|
-
getEmailToolByName: () =>
|
|
5130
|
+
getEmailToolByName: () => getEmailToolByName2
|
|
5131
|
+
});
|
|
5132
|
+
|
|
5133
|
+
// src/tools/aligned.ts
|
|
5134
|
+
var aligned_exports = {};
|
|
5135
|
+
__export(aligned_exports, {
|
|
5136
|
+
emailTools: () => emailTools2,
|
|
5137
|
+
getEmailToolByName: () => getEmailToolByName,
|
|
5138
|
+
listEmailToolDefinitions: () => listEmailToolDefinitions
|
|
5127
5139
|
});
|
|
5128
5140
|
|
|
5129
5141
|
// src/tools/email_tools.ts
|
|
@@ -5847,8 +5859,58 @@ var emailTools = [
|
|
|
5847
5859
|
}
|
|
5848
5860
|
];
|
|
5849
5861
|
|
|
5850
|
-
// src/tools/
|
|
5862
|
+
// src/tools/aligned.ts
|
|
5863
|
+
var usage = {
|
|
5864
|
+
mail_read: {
|
|
5865
|
+
whenToUse: "Inspect folders, cached messages, threads, attachments or raw message content.",
|
|
5866
|
+
whenNotToUse: "Use mail_search to find messages by query or mail_organize to change them."
|
|
5867
|
+
},
|
|
5868
|
+
mail_search: {
|
|
5869
|
+
whenToUse: "Find messages by a local full-text query or a remote IMAP search.",
|
|
5870
|
+
whenNotToUse: "Use mail_read when the folder and message UID are already known."
|
|
5871
|
+
},
|
|
5872
|
+
mail_compose: {
|
|
5873
|
+
whenToUse: "Send, reply, forward, or save and manage a draft after its content is agreed.",
|
|
5874
|
+
whenNotToUse: "Use mail_read to inspect an existing message without sending or saving content."
|
|
5875
|
+
},
|
|
5876
|
+
mail_organize: {
|
|
5877
|
+
whenToUse: "Change message flags, labels, destinations or folder organization.",
|
|
5878
|
+
whenNotToUse: "Use mail_read or mail_search when only inspection is requested."
|
|
5879
|
+
},
|
|
5880
|
+
mail_sync: {
|
|
5881
|
+
whenToUse: "Connect, disconnect, reconnect, refresh folders or synchronize the cache.",
|
|
5882
|
+
whenNotToUse: "Use mail_read for cached content or the network watch stream for continuous monitoring."
|
|
5883
|
+
}
|
|
5884
|
+
};
|
|
5885
|
+
var emailTools2 = emailTools.map((tool) => ({
|
|
5886
|
+
name: tool.name,
|
|
5887
|
+
description: tool.description,
|
|
5888
|
+
whenToUse: usage[tool.name]?.whenToUse ?? tool.description,
|
|
5889
|
+
whenNotToUse: usage[tool.name]?.whenNotToUse ?? "Use a tool matching the requested operation.",
|
|
5890
|
+
inputSchema: tool.inputSchema,
|
|
5891
|
+
// Read tools can fetch remote data and update the local cache.
|
|
5892
|
+
readOnly: false,
|
|
5893
|
+
sideEffects: "writes_state",
|
|
5894
|
+
async handler(ctx, input) {
|
|
5895
|
+
const result = await tool.handler(ctx, input);
|
|
5896
|
+
return {
|
|
5897
|
+
ok: result.outcome === "success" || result.outcome === "no_op",
|
|
5898
|
+
outcome: result.outcome,
|
|
5899
|
+
summary: result.summary,
|
|
5900
|
+
next: result.nextSteps.map((message) => ({ kind: "use_tool", message })),
|
|
5901
|
+
data: { entities: result.entities }
|
|
5902
|
+
};
|
|
5903
|
+
}
|
|
5904
|
+
}));
|
|
5905
|
+
function listEmailToolDefinitions() {
|
|
5906
|
+
return [...emailTools2];
|
|
5907
|
+
}
|
|
5851
5908
|
function getEmailToolByName(name) {
|
|
5909
|
+
return emailTools2.find((tool) => tool.name === name) ?? null;
|
|
5910
|
+
}
|
|
5911
|
+
|
|
5912
|
+
// src/tools/get_email_tool_by_name.ts
|
|
5913
|
+
function getEmailToolByName2(name) {
|
|
5852
5914
|
return emailTools.find((tool) => tool.name === name);
|
|
5853
5915
|
}
|
|
5854
5916
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ghostpaw/email",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Standalone IMAP/SMTP email engine for Node.js — SQLite local cache, threading, sync, zero dependencies, with a built-in LLM tool facade",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"format": "biome format --write",
|
|
36
36
|
"typecheck": "tsc --noEmit",
|
|
37
37
|
"check": "biome check && tsc --noEmit",
|
|
38
|
+
"check:deps": "node scripts/check-zero-deps.mjs",
|
|
38
39
|
"clean": "rm -rf dist",
|
|
39
40
|
"version": "biome format --write package.json package-lock.json && git add package.json package-lock.json",
|
|
40
41
|
"prepublishOnly": "npm run check && npm run build",
|