@adecore/agents 0.37.2 → 0.37.3
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/chat/chat-session.d.ts +10 -2
- package/dist/chat/chat-session.js +22 -11
- package/dist/host/handlers.js +8 -1
- package/package.json +3 -3
- package/src/chat/chat-core.ts +1 -1
- package/src/chat/chat-session.ts +34 -12
- package/src/host/handlers.ts +8 -1
|
@@ -24,8 +24,14 @@ export interface PromptNotes {
|
|
|
24
24
|
};
|
|
25
25
|
reset(): void;
|
|
26
26
|
}
|
|
27
|
-
export
|
|
28
|
-
|
|
27
|
+
export interface ChatAttached {
|
|
28
|
+
chats: string[];
|
|
29
|
+
references: string[];
|
|
30
|
+
}
|
|
31
|
+
export type ChatReferences = (attached: {
|
|
32
|
+
readonly chats?: readonly string[];
|
|
33
|
+
readonly references?: readonly string[];
|
|
34
|
+
}) => ChatAttached & {
|
|
29
35
|
note: string | null;
|
|
30
36
|
};
|
|
31
37
|
export interface ChatSessionOptions {
|
|
@@ -74,6 +80,7 @@ export interface ChatSendExtras {
|
|
|
74
80
|
chats?: string[];
|
|
75
81
|
quoteSource?: ChatQuoteSource;
|
|
76
82
|
attachments?: ChatAttachment[];
|
|
83
|
+
references?: string[];
|
|
77
84
|
}
|
|
78
85
|
export interface ResumeWords {
|
|
79
86
|
prompt: string;
|
|
@@ -152,6 +159,7 @@ export declare class ChatSession {
|
|
|
152
159
|
};
|
|
153
160
|
private recordUiAnswer;
|
|
154
161
|
private vetted;
|
|
162
|
+
private attached;
|
|
155
163
|
sendInput(text: string, extras?: ChatSendExtras): Promise<{
|
|
156
164
|
queued: boolean;
|
|
157
165
|
turnId: string;
|
|
@@ -260,7 +260,8 @@ export class ChatSession {
|
|
|
260
260
|
...(extras.skills?.length ? { skills: extras.skills } : {}),
|
|
261
261
|
...(extras.chats?.length ? { chats: extras.chats } : {}),
|
|
262
262
|
...(extras.quoteSource ? { quoteSource: extras.quoteSource } : {}),
|
|
263
|
-
...(extras.attachments?.length ? { attachments: extras.attachments } : {})
|
|
263
|
+
...(extras.attachments?.length ? { attachments: extras.attachments } : {}),
|
|
264
|
+
...(extras.references?.length ? { references: extras.references } : {})
|
|
264
265
|
};
|
|
265
266
|
this.setQueue([...this.queue, message]);
|
|
266
267
|
this.lapseResume();
|
|
@@ -364,6 +365,14 @@ export class ChatSession {
|
|
|
364
365
|
delete plain.quoteSource;
|
|
365
366
|
return plain;
|
|
366
367
|
}
|
|
368
|
+
/* The chats and views a message pointed at as the host names them; without a host's `references` they are dropped. */
|
|
369
|
+
attached(text, extras) {
|
|
370
|
+
// A slash command must stay the first thing the CLI reads, as `contextNote` keeps it.
|
|
371
|
+
if (text.startsWith('/') || !this.options.references) {
|
|
372
|
+
return { chats: [], references: [], note: null };
|
|
373
|
+
}
|
|
374
|
+
return this.options.references({ chats: extras.chats, references: extras.references });
|
|
375
|
+
}
|
|
367
376
|
sendInput(text, extras = {}) {
|
|
368
377
|
return this.submitInput(text, extras);
|
|
369
378
|
}
|
|
@@ -411,11 +420,11 @@ export class ChatSession {
|
|
|
411
420
|
}
|
|
412
421
|
async steer(message, text, extras, steerTurn, turnId, queued) {
|
|
413
422
|
try {
|
|
414
|
-
const
|
|
423
|
+
const attached = this.attached(text, extras);
|
|
415
424
|
const accepted = await steerTurn({
|
|
416
425
|
promptId: message.id,
|
|
417
426
|
text,
|
|
418
|
-
preamble:
|
|
427
|
+
preamble: attached.note,
|
|
419
428
|
attachments: extras.attachments ?? [],
|
|
420
429
|
mentions: extras.mentions ?? [],
|
|
421
430
|
skills: extras.skills ?? []
|
|
@@ -432,9 +441,10 @@ export class ChatSession {
|
|
|
432
441
|
text,
|
|
433
442
|
mentions: extras.mentions,
|
|
434
443
|
skills: extras.skills,
|
|
435
|
-
chats:
|
|
444
|
+
chats: attached.chats,
|
|
436
445
|
attachments: extras.attachments,
|
|
437
|
-
...(extras.quoteSource ? { quoteSource: extras.quoteSource } : {})
|
|
446
|
+
...(extras.quoteSource ? { quoteSource: extras.quoteSource } : {}),
|
|
447
|
+
...(attached.references.length > 0 ? { references: attached.references } : {})
|
|
438
448
|
}),
|
|
439
449
|
this.thread.patchInfo({ queue: this.queue.filter((entry) => entry.id !== message.id) })
|
|
440
450
|
]);
|
|
@@ -524,7 +534,8 @@ export class ChatSession {
|
|
|
524
534
|
chats: next.chats,
|
|
525
535
|
attachments: next.attachments,
|
|
526
536
|
uiChoice: next.uiChoice,
|
|
527
|
-
quoteSource: next.quoteSource
|
|
537
|
+
quoteSource: next.quoteSource,
|
|
538
|
+
references: next.references
|
|
528
539
|
}, next.turnId);
|
|
529
540
|
}
|
|
530
541
|
dispatch(text, extras, requestedTurnId) {
|
|
@@ -535,13 +546,12 @@ export class ChatSession {
|
|
|
535
546
|
this.emit([this.thread.patchInfo({ goal: undefined })]);
|
|
536
547
|
}
|
|
537
548
|
const { preamble, note } = this.contextNote(text);
|
|
538
|
-
|
|
539
|
-
const
|
|
540
|
-
const turnId = this.openTurn(text, note, { ...extras, chats: references.ids }, requestedTurnId);
|
|
549
|
+
const attached = this.attached(text, extras);
|
|
550
|
+
const turnId = this.openTurn(text, note, { ...extras, chats: attached.chats, references: attached.references }, requestedTurnId);
|
|
541
551
|
const choiceNote = extras.uiChoice
|
|
542
552
|
? `The person chose ${JSON.stringify(extras.uiChoice.label)} from your UI reply. Their message is the visible context of that choice.`
|
|
543
553
|
: null;
|
|
544
|
-
const said = [preamble,
|
|
554
|
+
const said = [preamble, attached.note, choiceNote].filter((part) => part !== null);
|
|
545
555
|
const input = {
|
|
546
556
|
text,
|
|
547
557
|
preamble: said.length === 0 ? null : said.join('\n\n'),
|
|
@@ -1382,7 +1392,8 @@ export class ChatSession {
|
|
|
1382
1392
|
chats,
|
|
1383
1393
|
attachments,
|
|
1384
1394
|
...(extras.uiChoice ? { uiChoice: extras.uiChoice } : {}),
|
|
1385
|
-
...(extras.quoteSource ? { quoteSource: extras.quoteSource } : {})
|
|
1395
|
+
...(extras.quoteSource ? { quoteSource: extras.quoteSource } : {}),
|
|
1396
|
+
...(extras.references?.length ? { references: extras.references } : {})
|
|
1386
1397
|
}));
|
|
1387
1398
|
}
|
|
1388
1399
|
events.push(this.thread.patchInfo({ status: this.thread.statusFor(turnId), activeTurnId: turnId }));
|
package/dist/host/handlers.js
CHANGED
|
@@ -35,7 +35,14 @@ export function chatHandlers(chats, providers) {
|
|
|
35
35
|
chats.detach(payload.chatId, clientId);
|
|
36
36
|
return {};
|
|
37
37
|
},
|
|
38
|
-
'chat.send': (payload) => chats.send(payload.chatId, payload.text, {
|
|
38
|
+
'chat.send': (payload) => chats.send(payload.chatId, payload.text, {
|
|
39
|
+
delivery: payload.delivery,
|
|
40
|
+
mentions: payload.mentions,
|
|
41
|
+
skills: payload.skills,
|
|
42
|
+
chats: payload.chats,
|
|
43
|
+
quoteSource: payload.quoteSource,
|
|
44
|
+
references: payload.references
|
|
45
|
+
}, payload.attachments),
|
|
39
46
|
'chat.uiChoice': (payload, clientId) => chats.choose(payload, clientId),
|
|
40
47
|
'ui.link': (payload, clientId) => chats.linkUi(payload, clientId),
|
|
41
48
|
'ui.query': (payload, clientId) => chats.queryUi(payload, clientId),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adecore/agents",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.3",
|
|
4
4
|
"description": "Node-compatible agent chat hosts, providers, accounts, usage and durable task coordination.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -81,8 +81,8 @@
|
|
|
81
81
|
"test": "bun --conditions=source test"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@adecore/agent-contracts": "0.37.
|
|
85
|
-
"@adecore/intelligent-ui": "0.37.
|
|
84
|
+
"@adecore/agent-contracts": "0.37.3",
|
|
85
|
+
"@adecore/intelligent-ui": "0.37.3",
|
|
86
86
|
"zod": "^4.6.5"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
package/src/chat/chat-core.ts
CHANGED
|
@@ -137,7 +137,7 @@ export interface ChatCoreHooks {
|
|
|
137
137
|
hiddenFor?(chatId: string): boolean;
|
|
138
138
|
/* What the host says in front of a chat's next real prompt, beside what the chat keeps itself. */
|
|
139
139
|
promptNotesFor?(chatId: string): PromptNotes | undefined;
|
|
140
|
-
/* How the chats a person attached to a message are named to the agent; without it they are dropped. */
|
|
140
|
+
/* How the chats, views and nodes a person attached to a message are named to the agent; without it they are dropped. */
|
|
141
141
|
referencesFor?(chatId: string): ChatReferences | undefined;
|
|
142
142
|
/* The environment of this chat's CLI before its account adds its own. */
|
|
143
143
|
envFor?(chatId: string, base: Record<string, string>): Record<string, string | undefined>;
|
package/src/chat/chat-session.ts
CHANGED
|
@@ -57,7 +57,16 @@ export interface PromptNotes {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/* Chats a person attached to a message: the ones the host knows, and what the agent is told about them. */
|
|
60
|
-
|
|
60
|
+
/* What a message pointed at: other chats with `@`, and views and nodes with `#`, by id. */
|
|
61
|
+
export interface ChatAttached {
|
|
62
|
+
chats: string[];
|
|
63
|
+
references: string[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type ChatReferences = (attached: {
|
|
67
|
+
readonly chats?: readonly string[];
|
|
68
|
+
readonly references?: readonly string[];
|
|
69
|
+
}) => ChatAttached & { note: string | null };
|
|
61
70
|
|
|
62
71
|
export interface ChatSessionOptions {
|
|
63
72
|
info: ChatInfo;
|
|
@@ -129,6 +138,7 @@ export interface ChatSendExtras {
|
|
|
129
138
|
chats?: string[];
|
|
130
139
|
quoteSource?: ChatQuoteSource;
|
|
131
140
|
attachments?: ChatAttachment[];
|
|
141
|
+
references?: string[];
|
|
132
142
|
}
|
|
133
143
|
|
|
134
144
|
/* How a turn the host went down in is taken up: what the CLI is told, the note a person reads, and what goes in front. */
|
|
@@ -407,7 +417,8 @@ export class ChatSession {
|
|
|
407
417
|
...(extras.skills?.length ? { skills: extras.skills } : {}),
|
|
408
418
|
...(extras.chats?.length ? { chats: extras.chats } : {}),
|
|
409
419
|
...(extras.quoteSource ? { quoteSource: extras.quoteSource } : {}),
|
|
410
|
-
...(extras.attachments?.length ? { attachments: extras.attachments } : {})
|
|
420
|
+
...(extras.attachments?.length ? { attachments: extras.attachments } : {}),
|
|
421
|
+
...(extras.references?.length ? { references: extras.references } : {})
|
|
411
422
|
};
|
|
412
423
|
this.setQueue([...this.queue, message]);
|
|
413
424
|
this.lapseResume();
|
|
@@ -523,6 +534,15 @@ export class ChatSession {
|
|
|
523
534
|
return plain;
|
|
524
535
|
}
|
|
525
536
|
|
|
537
|
+
/* The chats and views a message pointed at as the host names them; without a host's `references` they are dropped. */
|
|
538
|
+
private attached(text: string, extras: ChatSendExtras): ChatAttached & { note: string | null } {
|
|
539
|
+
// A slash command must stay the first thing the CLI reads, as `contextNote` keeps it.
|
|
540
|
+
if (text.startsWith('/') || !this.options.references) {
|
|
541
|
+
return { chats: [], references: [], note: null };
|
|
542
|
+
}
|
|
543
|
+
return this.options.references({ chats: extras.chats, references: extras.references });
|
|
544
|
+
}
|
|
545
|
+
|
|
526
546
|
sendInput(text: string, extras: ChatSendExtras = {}): Promise<{ queued: boolean; turnId: string }> {
|
|
527
547
|
return this.submitInput(text, extras);
|
|
528
548
|
}
|
|
@@ -580,11 +600,11 @@ export class ChatSession {
|
|
|
580
600
|
queued: { queued: boolean; turnId: string }
|
|
581
601
|
): Promise<{ queued: boolean; turnId: string }> {
|
|
582
602
|
try {
|
|
583
|
-
const
|
|
603
|
+
const attached = this.attached(text, extras);
|
|
584
604
|
const accepted = await steerTurn({
|
|
585
605
|
promptId: message.id,
|
|
586
606
|
text,
|
|
587
|
-
preamble:
|
|
607
|
+
preamble: attached.note,
|
|
588
608
|
attachments: extras.attachments ?? [],
|
|
589
609
|
mentions: extras.mentions ?? [],
|
|
590
610
|
skills: extras.skills ?? []
|
|
@@ -601,9 +621,10 @@ export class ChatSession {
|
|
|
601
621
|
text,
|
|
602
622
|
mentions: extras.mentions,
|
|
603
623
|
skills: extras.skills,
|
|
604
|
-
chats:
|
|
624
|
+
chats: attached.chats,
|
|
605
625
|
attachments: extras.attachments,
|
|
606
|
-
...(extras.quoteSource ? { quoteSource: extras.quoteSource } : {})
|
|
626
|
+
...(extras.quoteSource ? { quoteSource: extras.quoteSource } : {}),
|
|
627
|
+
...(attached.references.length > 0 ? { references: attached.references } : {})
|
|
607
628
|
}),
|
|
608
629
|
this.thread.patchInfo({ queue: this.queue.filter((entry) => entry.id !== message.id) })
|
|
609
630
|
]);
|
|
@@ -700,7 +721,8 @@ export class ChatSession {
|
|
|
700
721
|
chats: next.chats,
|
|
701
722
|
attachments: next.attachments,
|
|
702
723
|
uiChoice: next.uiChoice,
|
|
703
|
-
quoteSource: next.quoteSource
|
|
724
|
+
quoteSource: next.quoteSource,
|
|
725
|
+
references: next.references
|
|
704
726
|
},
|
|
705
727
|
next.turnId
|
|
706
728
|
);
|
|
@@ -714,13 +736,12 @@ export class ChatSession {
|
|
|
714
736
|
this.emit([this.thread.patchInfo({ goal: undefined })]);
|
|
715
737
|
}
|
|
716
738
|
const { preamble, note } = this.contextNote(text);
|
|
717
|
-
|
|
718
|
-
const
|
|
719
|
-
const turnId = this.openTurn(text, note, { ...extras, chats: references.ids }, requestedTurnId);
|
|
739
|
+
const attached = this.attached(text, extras);
|
|
740
|
+
const turnId = this.openTurn(text, note, { ...extras, chats: attached.chats, references: attached.references }, requestedTurnId);
|
|
720
741
|
const choiceNote = extras.uiChoice
|
|
721
742
|
? `The person chose ${JSON.stringify(extras.uiChoice.label)} from your UI reply. Their message is the visible context of that choice.`
|
|
722
743
|
: null;
|
|
723
|
-
const said = [preamble,
|
|
744
|
+
const said = [preamble, attached.note, choiceNote].filter((part): part is string => part !== null);
|
|
724
745
|
const input = {
|
|
725
746
|
text,
|
|
726
747
|
preamble: said.length === 0 ? null : said.join('\n\n'),
|
|
@@ -1612,7 +1633,8 @@ export class ChatSession {
|
|
|
1612
1633
|
chats,
|
|
1613
1634
|
attachments,
|
|
1614
1635
|
...(extras.uiChoice ? { uiChoice: extras.uiChoice } : {}),
|
|
1615
|
-
...(extras.quoteSource ? { quoteSource: extras.quoteSource } : {})
|
|
1636
|
+
...(extras.quoteSource ? { quoteSource: extras.quoteSource } : {}),
|
|
1637
|
+
...(extras.references?.length ? { references: extras.references } : {})
|
|
1616
1638
|
})
|
|
1617
1639
|
);
|
|
1618
1640
|
}
|
package/src/host/handlers.ts
CHANGED
|
@@ -67,7 +67,14 @@ export function chatHandlers(chats: ChatCore, providers: ProviderRegistry): { [T
|
|
|
67
67
|
chats.send(
|
|
68
68
|
payload.chatId,
|
|
69
69
|
payload.text,
|
|
70
|
-
{
|
|
70
|
+
{
|
|
71
|
+
delivery: payload.delivery,
|
|
72
|
+
mentions: payload.mentions,
|
|
73
|
+
skills: payload.skills,
|
|
74
|
+
chats: payload.chats,
|
|
75
|
+
quoteSource: payload.quoteSource,
|
|
76
|
+
references: payload.references
|
|
77
|
+
},
|
|
71
78
|
payload.attachments
|
|
72
79
|
),
|
|
73
80
|
'chat.uiChoice': (payload, clientId) => chats.choose(payload, clientId),
|