@ghostpaw/email 0.2.3 → 0.4.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.
@@ -0,0 +1,20 @@
1
+ interface EmailRunResult {
2
+ lastInsertRowid: number | bigint;
3
+ changes?: number | bigint | undefined;
4
+ }
5
+ interface EmailStatement {
6
+ run(...params: unknown[]): EmailRunResult;
7
+ get<TRecord>(...params: unknown[]): TRecord | undefined;
8
+ all<TRecord>(...params: unknown[]): TRecord[];
9
+ }
10
+ /**
11
+ * SQLite dependency injected into every email operation.
12
+ * Node.js `DatabaseSync` satisfies this interface directly.
13
+ */
14
+ type EmailDb = {
15
+ exec(sql: string): void;
16
+ prepare(sql: string): EmailStatement;
17
+ close(): void;
18
+ };
19
+
20
+ export type { EmailDb as E };
@@ -0,0 +1,20 @@
1
+ interface EmailRunResult {
2
+ lastInsertRowid: number | bigint;
3
+ changes?: number | bigint | undefined;
4
+ }
5
+ interface EmailStatement {
6
+ run(...params: unknown[]): EmailRunResult;
7
+ get<TRecord>(...params: unknown[]): TRecord | undefined;
8
+ all<TRecord>(...params: unknown[]): TRecord[];
9
+ }
10
+ /**
11
+ * SQLite dependency injected into every email operation.
12
+ * Node.js `DatabaseSync` satisfies this interface directly.
13
+ */
14
+ type EmailDb = {
15
+ exec(sql: string): void;
16
+ prepare(sql: string): EmailStatement;
17
+ close(): void;
18
+ };
19
+
20
+ export type { EmailDb as E };
package/dist/index.cjs CHANGED
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var events = require('events');
4
- var net = require('net');
5
- var tls = require('tls');
6
- var zlib = require('zlib');
7
- var sqlite = require('node:sqlite');
8
- var crypto = require('crypto');
3
+ var node_events = require('node:events');
4
+ var net = require('node:net');
5
+ var tls = require('node:tls');
6
+ var zlib = require('node:zlib');
7
+ var node_crypto = require('node:crypto');
9
8
 
10
9
  function _interopNamespace(e) {
11
10
  if (e && e.__esModule) return e;
@@ -399,7 +398,7 @@ var DEFAULT_MAX_MESSAGE_SIZE = 26214400;
399
398
  var DEFAULT_CHARSET = "utf-8";
400
399
 
401
400
  // src/imap/connection.ts
402
- var ImapConnection = class extends events.EventEmitter {
401
+ var ImapConnection = class extends node_events.EventEmitter {
403
402
  #config;
404
403
  #socket = null;
405
404
  #connected = false;
@@ -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 arr = u.data;
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 db = new sqlite.DatabaseSync(dbPath);
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
  }
@@ -3877,11 +3880,11 @@ __export(write_exports, {
3877
3880
  createWriteSurface: () => createWriteSurface
3878
3881
  });
3879
3882
  function generateMessageId(domain) {
3880
- const id = crypto.randomUUID().replace(/-/g, "");
3883
+ const id = node_crypto.randomUUID().replace(/-/g, "");
3881
3884
  return `<${Date.now()}.${id}@${domain}>`;
3882
3885
  }
3883
3886
  function generateBoundary() {
3884
- return `----=_Part_${crypto.randomUUID()}`;
3887
+ return `----=_Part_${node_crypto.randomUUID()}`;
3885
3888
  }
3886
3889
 
3887
3890
  // src/lib/normalize_subject.ts
@@ -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: () => 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/get_email_tool_by_name.ts
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
@@ -1,26 +1,8 @@
1
+ import { E as EmailDb } from './database-Rfe-wn1C.cjs';
1
2
  import { Writable, Duplex } from 'node:stream';
2
3
  import { EventEmitter } from 'node:events';
3
4
  import { DatabaseSync } from 'node:sqlite';
4
5
 
5
- interface EmailRunResult {
6
- lastInsertRowid: number | bigint;
7
- changes?: number | bigint | undefined;
8
- }
9
- interface EmailStatement {
10
- run(...params: unknown[]): EmailRunResult;
11
- get<TRecord>(...params: unknown[]): TRecord | undefined;
12
- all<TRecord>(...params: unknown[]): TRecord[];
13
- }
14
- /**
15
- * SQLite dependency injected into every email operation.
16
- * Node.js `DatabaseSync` satisfies this interface directly.
17
- */
18
- type EmailDb = {
19
- exec(sql: string): void;
20
- prepare(sql: string): EmailStatement;
21
- close(): void;
22
- };
23
-
24
6
  type EmailErrorCode = 'invariant' | 'not_found' | 'state' | 'validation' | 'auth' | 'connection' | 'protocol' | 'timeout' | 'unsupported' | 'envelope_rejected' | 'quota';
25
7
  declare class EmailError extends Error {
26
8
  readonly code: EmailErrorCode;
@@ -1348,6 +1330,40 @@ interface EmailToolDefinition<TInput = unknown> {
1348
1330
  handler(ctx: EmailToolContext, input: TInput): Promise<EmailToolResult>;
1349
1331
  }
1350
1332
 
1333
+ interface SharedEmailToolResult {
1334
+ ok: boolean;
1335
+ outcome: ToolOutcomeKind;
1336
+ summary: string;
1337
+ next: {
1338
+ kind: 'use_tool';
1339
+ message: string;
1340
+ }[];
1341
+ data: {
1342
+ entities: EmailToolResult['entities'];
1343
+ };
1344
+ }
1345
+ interface SharedEmailToolDefinition {
1346
+ name: string;
1347
+ description: string;
1348
+ whenToUse: string;
1349
+ whenNotToUse: string;
1350
+ inputSchema: JsonSchema;
1351
+ readOnly: boolean;
1352
+ sideEffects: 'none' | 'writes_state';
1353
+ handler(ctx: EmailToolContext, input: unknown): Promise<SharedEmailToolResult>;
1354
+ }
1355
+ /** Shared metadata and result adapters; legacy handlers remain available unchanged. */
1356
+ declare const emailTools$1: readonly SharedEmailToolDefinition[];
1357
+ declare function listEmailToolDefinitions(): SharedEmailToolDefinition[];
1358
+ declare function getEmailToolByName$1(name: string): SharedEmailToolDefinition | null;
1359
+
1360
+ type aligned_SharedEmailToolDefinition = SharedEmailToolDefinition;
1361
+ type aligned_SharedEmailToolResult = SharedEmailToolResult;
1362
+ declare const aligned_listEmailToolDefinitions: typeof listEmailToolDefinitions;
1363
+ declare namespace aligned {
1364
+ export { type aligned_SharedEmailToolDefinition as SharedEmailToolDefinition, type aligned_SharedEmailToolResult as SharedEmailToolResult, emailTools$1 as emailTools, getEmailToolByName$1 as getEmailToolByName, aligned_listEmailToolDefinitions as listEmailToolDefinitions };
1365
+ }
1366
+
1351
1367
  type MailReadInput = {
1352
1368
  view: 'folders';
1353
1369
  refresh?: boolean;
@@ -1454,6 +1470,7 @@ type MailSyncInput = {
1454
1470
  action: 'watch';
1455
1471
  folders?: string[];
1456
1472
  };
1473
+ /** @deprecated Use tools.aligned.emailTools for the shared result shape. */
1457
1474
  declare const emailTools: ({
1458
1475
  name: string;
1459
1476
  description: string;
@@ -1837,6 +1854,7 @@ declare const emailTools: ({
1837
1854
  }>;
1838
1855
  })[];
1839
1856
 
1857
+ /** @deprecated Use tools.aligned.getEmailToolByName for the shared result shape. */
1840
1858
  declare function getEmailToolByName(name: string): EmailToolDefinition<unknown> | undefined;
1841
1859
 
1842
1860
  type index$1_EmailToolContext = EmailToolContext;
@@ -1848,10 +1866,11 @@ type index$1_ToolEntityKind = ToolEntityKind;
1848
1866
  type index$1_ToolEntityRef = ToolEntityRef;
1849
1867
  type index$1_ToolOutcomeKind = ToolOutcomeKind;
1850
1868
  type index$1_ToolSideEffects = ToolSideEffects;
1869
+ declare const index$1_aligned: typeof aligned;
1851
1870
  declare const index$1_emailTools: typeof emailTools;
1852
1871
  declare const index$1_getEmailToolByName: typeof getEmailToolByName;
1853
1872
  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 };
1873
+ 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
1874
  }
1856
1875
 
1857
1876
  declare const DEFAULT_CONNECTION_TIMEOUT = 30000;
@@ -1957,4 +1976,4 @@ declare namespace write {
1957
1976
  export { type write_CreateWriteSurfaceOptions as CreateWriteSurfaceOptions, write_createWriteSurface as createWriteSurface };
1958
1977
  }
1959
1978
 
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 };
1979
+ 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, 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
@@ -1,26 +1,8 @@
1
+ import { E as EmailDb } from './database-Rfe-wn1C.js';
1
2
  import { Writable, Duplex } from 'node:stream';
2
3
  import { EventEmitter } from 'node:events';
3
4
  import { DatabaseSync } from 'node:sqlite';
4
5
 
5
- interface EmailRunResult {
6
- lastInsertRowid: number | bigint;
7
- changes?: number | bigint | undefined;
8
- }
9
- interface EmailStatement {
10
- run(...params: unknown[]): EmailRunResult;
11
- get<TRecord>(...params: unknown[]): TRecord | undefined;
12
- all<TRecord>(...params: unknown[]): TRecord[];
13
- }
14
- /**
15
- * SQLite dependency injected into every email operation.
16
- * Node.js `DatabaseSync` satisfies this interface directly.
17
- */
18
- type EmailDb = {
19
- exec(sql: string): void;
20
- prepare(sql: string): EmailStatement;
21
- close(): void;
22
- };
23
-
24
6
  type EmailErrorCode = 'invariant' | 'not_found' | 'state' | 'validation' | 'auth' | 'connection' | 'protocol' | 'timeout' | 'unsupported' | 'envelope_rejected' | 'quota';
25
7
  declare class EmailError extends Error {
26
8
  readonly code: EmailErrorCode;
@@ -1348,6 +1330,40 @@ interface EmailToolDefinition<TInput = unknown> {
1348
1330
  handler(ctx: EmailToolContext, input: TInput): Promise<EmailToolResult>;
1349
1331
  }
1350
1332
 
1333
+ interface SharedEmailToolResult {
1334
+ ok: boolean;
1335
+ outcome: ToolOutcomeKind;
1336
+ summary: string;
1337
+ next: {
1338
+ kind: 'use_tool';
1339
+ message: string;
1340
+ }[];
1341
+ data: {
1342
+ entities: EmailToolResult['entities'];
1343
+ };
1344
+ }
1345
+ interface SharedEmailToolDefinition {
1346
+ name: string;
1347
+ description: string;
1348
+ whenToUse: string;
1349
+ whenNotToUse: string;
1350
+ inputSchema: JsonSchema;
1351
+ readOnly: boolean;
1352
+ sideEffects: 'none' | 'writes_state';
1353
+ handler(ctx: EmailToolContext, input: unknown): Promise<SharedEmailToolResult>;
1354
+ }
1355
+ /** Shared metadata and result adapters; legacy handlers remain available unchanged. */
1356
+ declare const emailTools$1: readonly SharedEmailToolDefinition[];
1357
+ declare function listEmailToolDefinitions(): SharedEmailToolDefinition[];
1358
+ declare function getEmailToolByName$1(name: string): SharedEmailToolDefinition | null;
1359
+
1360
+ type aligned_SharedEmailToolDefinition = SharedEmailToolDefinition;
1361
+ type aligned_SharedEmailToolResult = SharedEmailToolResult;
1362
+ declare const aligned_listEmailToolDefinitions: typeof listEmailToolDefinitions;
1363
+ declare namespace aligned {
1364
+ export { type aligned_SharedEmailToolDefinition as SharedEmailToolDefinition, type aligned_SharedEmailToolResult as SharedEmailToolResult, emailTools$1 as emailTools, getEmailToolByName$1 as getEmailToolByName, aligned_listEmailToolDefinitions as listEmailToolDefinitions };
1365
+ }
1366
+
1351
1367
  type MailReadInput = {
1352
1368
  view: 'folders';
1353
1369
  refresh?: boolean;
@@ -1454,6 +1470,7 @@ type MailSyncInput = {
1454
1470
  action: 'watch';
1455
1471
  folders?: string[];
1456
1472
  };
1473
+ /** @deprecated Use tools.aligned.emailTools for the shared result shape. */
1457
1474
  declare const emailTools: ({
1458
1475
  name: string;
1459
1476
  description: string;
@@ -1837,6 +1854,7 @@ declare const emailTools: ({
1837
1854
  }>;
1838
1855
  })[];
1839
1856
 
1857
+ /** @deprecated Use tools.aligned.getEmailToolByName for the shared result shape. */
1840
1858
  declare function getEmailToolByName(name: string): EmailToolDefinition<unknown> | undefined;
1841
1859
 
1842
1860
  type index$1_EmailToolContext = EmailToolContext;
@@ -1848,10 +1866,11 @@ type index$1_ToolEntityKind = ToolEntityKind;
1848
1866
  type index$1_ToolEntityRef = ToolEntityRef;
1849
1867
  type index$1_ToolOutcomeKind = ToolOutcomeKind;
1850
1868
  type index$1_ToolSideEffects = ToolSideEffects;
1869
+ declare const index$1_aligned: typeof aligned;
1851
1870
  declare const index$1_emailTools: typeof emailTools;
1852
1871
  declare const index$1_getEmailToolByName: typeof getEmailToolByName;
1853
1872
  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 };
1873
+ 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
1874
  }
1856
1875
 
1857
1876
  declare const DEFAULT_CONNECTION_TIMEOUT = 30000;
@@ -1957,4 +1976,4 @@ declare namespace write {
1957
1976
  export { type write_CreateWriteSurfaceOptions as CreateWriteSurfaceOptions, write_createWriteSurface as createWriteSurface };
1958
1977
  }
1959
1978
 
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 };
1979
+ 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, 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
@@ -1,9 +1,8 @@
1
- import { EventEmitter } from 'events';
2
- import * as net from 'net';
3
- import * as tls from 'tls';
4
- import * as zlib from 'zlib';
5
- import { DatabaseSync } from 'node:sqlite';
6
- import { randomUUID } from 'crypto';
1
+ import { EventEmitter } from 'node:events';
2
+ import * as net from 'node:net';
3
+ import * as tls from 'node:tls';
4
+ import * as zlib from 'node:zlib';
5
+ import { randomUUID } from 'node:crypto';
7
6
 
8
7
  var __defProp = Object.defineProperty;
9
8
  var __export = (target, all) => {
@@ -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 arr = u.data;
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: () => 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/get_email_tool_by_name.ts
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