aamp-sdk 0.1.14 → 0.1.15
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 +29 -1
- package/dist/client.d.ts +26 -1
- package/dist/client.js +201 -0
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/jmap-push.d.ts +2 -1
- package/dist/jmap-push.js +3 -0
- package/dist/jmap-push.js.map +1 -1
- package/dist/parser.d.ts +4 -0
- package/dist/parser.js +23 -0
- package/dist/parser.js.map +1 -1
- package/dist/smtp-sender.d.ts +15 -0
- package/dist/smtp-sender.js +329 -11
- package/dist/smtp-sender.js.map +1 -1
- package/dist/thread.d.ts +5 -0
- package/dist/thread.js +53 -0
- package/dist/thread.js.map +1 -0
- package/dist/types.d.ts +90 -3
- package/dist/types.js +2 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/thread.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
function singleLine(value, maxLength = 220) {
|
|
2
|
+
const normalized = (value ?? '').replace(/\s+/g, ' ').trim();
|
|
3
|
+
if (!normalized)
|
|
4
|
+
return '';
|
|
5
|
+
if (normalized.length <= maxLength)
|
|
6
|
+
return normalized;
|
|
7
|
+
return `${normalized.slice(0, maxLength - 1)}…`;
|
|
8
|
+
}
|
|
9
|
+
function formatTimestamp(value) {
|
|
10
|
+
const date = new Date(value);
|
|
11
|
+
if (Number.isNaN(date.getTime()))
|
|
12
|
+
return value;
|
|
13
|
+
return date.toISOString().slice(0, 16).replace('T', ' ');
|
|
14
|
+
}
|
|
15
|
+
function renderEventLine(event) {
|
|
16
|
+
const from = event.from.split('@')[0] || event.from;
|
|
17
|
+
const timestamp = formatTimestamp(event.createdAt);
|
|
18
|
+
if (event.intent === 'task.dispatch') {
|
|
19
|
+
const summary = singleLine(event.bodyText) || singleLine(event.title) || 'Task dispatched';
|
|
20
|
+
return `[${timestamp}] ${from} dispatched: ${summary}`;
|
|
21
|
+
}
|
|
22
|
+
if (event.intent === 'task.help_needed') {
|
|
23
|
+
const question = singleLine(event.question) || 'Asked for help';
|
|
24
|
+
const reason = singleLine(event.blockedReason);
|
|
25
|
+
return `[${timestamp}] ${from} asked for help: ${question}${reason ? ` (reason: ${reason})` : ''}`;
|
|
26
|
+
}
|
|
27
|
+
if (event.intent === 'task.result') {
|
|
28
|
+
const output = singleLine(event.output) || singleLine(event.bodyText) || 'Sent a result';
|
|
29
|
+
return `[${timestamp}] ${from} replied: ${output}`;
|
|
30
|
+
}
|
|
31
|
+
if (event.intent === 'task.cancel') {
|
|
32
|
+
const body = singleLine(event.bodyText) || 'Cancelled the task';
|
|
33
|
+
return `[${timestamp}] ${from} cancelled the task: ${body}`;
|
|
34
|
+
}
|
|
35
|
+
if (event.intent === 'task.ack') {
|
|
36
|
+
return `[${timestamp}] ${from} acknowledged the task`;
|
|
37
|
+
}
|
|
38
|
+
return `[${timestamp}] ${from}: ${singleLine(event.bodyText) || event.intent}`;
|
|
39
|
+
}
|
|
40
|
+
export function renderThreadHistoryForAgent(events, options = {}) {
|
|
41
|
+
const filtered = events.filter((event) => event.intent !== 'task.stream.opened');
|
|
42
|
+
if (filtered.length === 0)
|
|
43
|
+
return '';
|
|
44
|
+
const maxEvents = Math.max(1, options.maxEvents ?? 8);
|
|
45
|
+
const visible = filtered.slice(-maxEvents);
|
|
46
|
+
const omitted = filtered.length - visible.length;
|
|
47
|
+
return [
|
|
48
|
+
'Prior thread context:',
|
|
49
|
+
...(omitted > 0 ? [`(${omitted} earlier event(s) omitted)`] : []),
|
|
50
|
+
...visible.map((event) => `- ${renderEventLine(event)}`),
|
|
51
|
+
].join('\n');
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=thread.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thread.js","sourceRoot":"","sources":["../src/thread.ts"],"names":[],"mappings":"AAMA,SAAS,U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O,EAAE,CAAA;IAEpC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC,CAAA;IACrD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAA;IAC1C,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;IAEhD,OAAO;QACL,uBAAuB;QACvB,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,4BAA4B,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;KACzD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AAMP SDK Type Definitions
|
|
3
3
|
*/
|
|
4
|
-
export declare const AAMP_PROTOCOL_VERSION = "1.
|
|
5
|
-
export type AampIntent = 'task.dispatch' | 'task.cancel' | 'task.result' | 'task.help_needed' | 'task.ack' | 'card.query' | 'card.response';
|
|
4
|
+
export declare const AAMP_PROTOCOL_VERSION = "1.1";
|
|
5
|
+
export type AampIntent = 'task.dispatch' | 'task.cancel' | 'task.result' | 'task.help_needed' | 'task.ack' | 'task.stream.opened' | 'card.query' | 'card.response';
|
|
6
6
|
export type TaskPriority = 'urgent' | 'high' | 'normal';
|
|
7
7
|
export type TaskStatus = 'pending' | 'running' | 'completed' | 'rejected' | 'failed' | 'help_needed' | 'cancelled' | 'expired';
|
|
8
8
|
export declare const AAMP_HEADER: {
|
|
@@ -20,6 +20,7 @@ export declare const AAMP_HEADER: {
|
|
|
20
20
|
readonly QUESTION: "X-AAMP-Question";
|
|
21
21
|
readonly BLOCKED_REASON: "X-AAMP-BlockedReason";
|
|
22
22
|
readonly SUGGESTED_OPTIONS: "X-AAMP-SuggestedOptions";
|
|
23
|
+
readonly STREAM_ID: "X-AAMP-Stream-Id";
|
|
23
24
|
readonly PARENT_TASK_ID: "X-AAMP-ParentTaskId";
|
|
24
25
|
readonly CARD_SUMMARY: "X-AAMP-Card-Summary";
|
|
25
26
|
};
|
|
@@ -107,6 +108,15 @@ export interface TaskAck {
|
|
|
107
108
|
to: string;
|
|
108
109
|
messageId?: string;
|
|
109
110
|
}
|
|
111
|
+
export interface TaskStreamOpened {
|
|
112
|
+
protocolVersion: string;
|
|
113
|
+
intent: 'task.stream.opened';
|
|
114
|
+
taskId: string;
|
|
115
|
+
streamId: string;
|
|
116
|
+
from: string;
|
|
117
|
+
to: string;
|
|
118
|
+
messageId?: string;
|
|
119
|
+
}
|
|
110
120
|
export interface CardQuery {
|
|
111
121
|
protocolVersion: string;
|
|
112
122
|
intent: 'card.query';
|
|
@@ -142,7 +152,7 @@ export interface ReceivedAttachment {
|
|
|
142
152
|
size: number;
|
|
143
153
|
blobId: string;
|
|
144
154
|
}
|
|
145
|
-
export type AampMessage = TaskDispatch | TaskCancel | TaskResult | TaskHelp | TaskAck | CardQuery | CardResponse | HumanReply;
|
|
155
|
+
export type AampMessage = TaskDispatch | TaskCancel | TaskResult | TaskHelp | TaskAck | TaskStreamOpened | CardQuery | CardResponse | HumanReply;
|
|
146
156
|
export interface AampClientConfig {
|
|
147
157
|
/** Node email address, e.g. codereviewer-abc123@aamp.yourdomain.com */
|
|
148
158
|
email: string;
|
|
@@ -188,6 +198,16 @@ export interface AampDiscoveryDocument {
|
|
|
188
198
|
actions?: string[];
|
|
189
199
|
};
|
|
190
200
|
endpoints?: Record<string, string>;
|
|
201
|
+
capabilities?: {
|
|
202
|
+
stream?: {
|
|
203
|
+
transport: 'sse';
|
|
204
|
+
createAction?: string;
|
|
205
|
+
appendAction?: string;
|
|
206
|
+
closeAction?: string;
|
|
207
|
+
getAction?: string;
|
|
208
|
+
subscribeUrlTemplate?: string;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
191
211
|
}
|
|
192
212
|
export interface RegisterMailboxOptions {
|
|
193
213
|
/** AAMP service root, e.g. https://meshmail.ai */
|
|
@@ -211,6 +231,29 @@ export interface AgentDirectorySearchEntry extends AgentDirectoryEntry {
|
|
|
211
231
|
export interface AgentDirectoryProfile extends AgentDirectoryEntry {
|
|
212
232
|
cardText: string | null;
|
|
213
233
|
}
|
|
234
|
+
export interface AampThreadEvent {
|
|
235
|
+
intent: AampIntent;
|
|
236
|
+
from: string;
|
|
237
|
+
to: string;
|
|
238
|
+
title?: string | null;
|
|
239
|
+
bodyText?: string | null;
|
|
240
|
+
output?: string | null;
|
|
241
|
+
question?: string | null;
|
|
242
|
+
blockedReason?: string | null;
|
|
243
|
+
messageId?: string | null;
|
|
244
|
+
createdAt: string;
|
|
245
|
+
}
|
|
246
|
+
export interface GetThreadHistoryOptions {
|
|
247
|
+
includeStreamOpened?: boolean;
|
|
248
|
+
}
|
|
249
|
+
export interface TaskThreadHistory {
|
|
250
|
+
taskId: string;
|
|
251
|
+
events: AampThreadEvent[];
|
|
252
|
+
}
|
|
253
|
+
export interface HydratedTaskDispatch extends TaskDispatch {
|
|
254
|
+
threadHistory: AampThreadEvent[];
|
|
255
|
+
threadContextText: string;
|
|
256
|
+
}
|
|
214
257
|
export interface SendTaskOptions {
|
|
215
258
|
/** Target node email */
|
|
216
259
|
to: string;
|
|
@@ -270,6 +313,49 @@ export interface SendCardResponseOptions {
|
|
|
270
313
|
bodyText: string;
|
|
271
314
|
inReplyTo?: string;
|
|
272
315
|
}
|
|
316
|
+
export interface CreateStreamOptions {
|
|
317
|
+
taskId: string;
|
|
318
|
+
peerEmail: string;
|
|
319
|
+
}
|
|
320
|
+
export interface CreateStreamResult {
|
|
321
|
+
streamId: string;
|
|
322
|
+
taskId: string;
|
|
323
|
+
status: 'created' | 'opened' | 'closed';
|
|
324
|
+
ownerEmail: string;
|
|
325
|
+
peerEmail: string;
|
|
326
|
+
createdAt: string;
|
|
327
|
+
openedAt?: string;
|
|
328
|
+
closedAt?: string;
|
|
329
|
+
}
|
|
330
|
+
export type AampStreamEventType = 'text.delta' | 'progress' | 'status' | 'artifact' | 'error' | 'done';
|
|
331
|
+
export interface AampStreamEvent {
|
|
332
|
+
id?: string;
|
|
333
|
+
streamId: string;
|
|
334
|
+
taskId: string;
|
|
335
|
+
seq: number;
|
|
336
|
+
timestamp: string;
|
|
337
|
+
type: AampStreamEventType;
|
|
338
|
+
payload: Record<string, unknown>;
|
|
339
|
+
}
|
|
340
|
+
export interface AppendStreamEventOptions {
|
|
341
|
+
streamId: string;
|
|
342
|
+
type: AampStreamEventType;
|
|
343
|
+
payload: Record<string, unknown>;
|
|
344
|
+
}
|
|
345
|
+
export interface CloseStreamOptions {
|
|
346
|
+
streamId: string;
|
|
347
|
+
payload?: Record<string, unknown>;
|
|
348
|
+
}
|
|
349
|
+
export interface GetTaskStreamOptions {
|
|
350
|
+
taskId?: string;
|
|
351
|
+
streamId?: string;
|
|
352
|
+
}
|
|
353
|
+
export interface TaskStreamState extends CreateStreamResult {
|
|
354
|
+
latestEvent?: AampStreamEvent;
|
|
355
|
+
}
|
|
356
|
+
export interface StreamSubscription {
|
|
357
|
+
close(): void;
|
|
358
|
+
}
|
|
273
359
|
export interface DirectoryListOptions {
|
|
274
360
|
scope?: string;
|
|
275
361
|
includeSelf?: boolean;
|
|
@@ -288,6 +374,7 @@ export interface AampClientEvents {
|
|
|
288
374
|
'task.result': (result: TaskResult) => void;
|
|
289
375
|
'task.help_needed': (help: TaskHelp) => void;
|
|
290
376
|
'task.ack': (ack: TaskAck) => void;
|
|
377
|
+
'task.stream.opened': (stream: TaskStreamOpened) => void;
|
|
291
378
|
'card.query': (query: CardQuery) => void;
|
|
292
379
|
'card.response': (response: CardResponse) => void;
|
|
293
380
|
/** Emitted when a standard email reply (no X-AAMP headers) is received for a known thread.
|
package/dist/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AAMP SDK Type Definitions
|
|
3
3
|
*/
|
|
4
|
-
export const AAMP_PROTOCOL_VERSION = '1.
|
|
4
|
+
export const AAMP_PROTOCOL_VERSION = '1.1';
|
|
5
5
|
// =====================================================
|
|
6
6
|
// AAMP Header constants
|
|
7
7
|
// =====================================================
|
|
@@ -20,6 +20,7 @@ export const AAMP_HEADER = {
|
|
|
20
20
|
QUESTION: 'X-AAMP-Question',
|
|
21
21
|
BLOCKED_REASON: 'X-AAMP-BlockedReason',
|
|
22
22
|
SUGGESTED_OPTIONS: 'X-AAMP-SuggestedOptions',
|
|
23
|
+
STREAM_ID: 'X-AAMP-Stream-Id',
|
|
23
24
|
PARENT_TASK_ID: 'X-AAMP-ParentTaskId',
|
|
24
25
|
CARD_SUMMARY: 'X-AAMP-Card-Summary',
|
|
25
26
|
};
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAA;AAwB1C,wDAAwD;AACxD,wBAAwB;AACxB,wDAAwD;AACxD,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,gBAAgB;IACzB,MAAM,EAAE,eAAe;IACvB,OAAO,EAAE,eAAe;IACxB,aAAa,EAAE,qBAAqB;IACpC,gBAAgB,EAAE,yBAAyB;IAC3C,QAAQ,EAAE,iBAAiB;IAC3B,UAAU,EAAE,mBAAmB;IAC/B,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,eAAe;IACvB,SAAS,EAAE,iBAAiB;IAC5B,iBAAiB,EAAE,yBAAyB;IAC5C,QAAQ,EAAE,iBAAiB;IAC3B,cAAc,EAAE,sBAAsB;IACtC,iBAAiB,EAAE,yBAAyB;IAC5C,SAAS,EAAE,kBAAkB;IAC7B,cAAc,EAAE,qBAAqB;IACrC,YAAY,EAAE,qBAAqB;CAC3B,CAAA"}
|