@alfe.ai/openclaw-chat 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.cts +1 -94
- package/dist/index.d.ts +1 -94
- package/dist/plugin.d.cts +168 -2
- package/dist/plugin.d.ts +168 -2
- package/dist/plugin2.cjs +678 -17
- package/dist/plugin2.js +679 -18
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,95 +1,2 @@
|
|
|
1
|
-
import { _ as AlfeResolvedAccount, g as AlfePluginConfig, h as AlfeChannelConfig, m as createAlfeChannelPlugin, u as plugin } from "./plugin.cjs";
|
|
2
|
-
|
|
3
|
-
//#region src/session-store.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Session Store — persists chat sessions to the local filesystem.
|
|
7
|
-
*
|
|
8
|
-
* Storage layout:
|
|
9
|
-
* ~/.alfe/sessions/chat/{sessionId}.json
|
|
10
|
-
*
|
|
11
|
-
* Each session file contains metadata and the full message history.
|
|
12
|
-
* Sessions are written on every message to ensure durability.
|
|
13
|
-
* Old sessions are cleaned up automatically (30-day TTL, 1000 max).
|
|
14
|
-
*
|
|
15
|
-
* NOTE: the storage path and SessionData shape are a read contract —
|
|
16
|
-
* packages/openclaw-memory-cloud/src/session-backfill.ts reads these files
|
|
17
|
-
* directly (the memory plugin can't depend on this package). Keep in sync.
|
|
18
|
-
*/
|
|
19
|
-
interface ChatMessage {
|
|
20
|
-
role: 'user' | 'assistant';
|
|
21
|
-
content: string;
|
|
22
|
-
timestamp: number;
|
|
23
|
-
senderId?: string;
|
|
24
|
-
senderName?: string;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Persisted form of a turn's agent activity (tool cards + thinking), so a
|
|
28
|
-
* refresh can replay what the live `chat-activity` stream showed. Terminal
|
|
29
|
-
* by construction: no `progressText` (transient streaming window) and no
|
|
30
|
-
* `running` status — a tool still running at flush time is persisted as
|
|
31
|
-
* `interrupted`. Tool text fields arrive pre-capped (activity-serialize.ts);
|
|
32
|
-
* thinking text is capped at append time (MAX_ACTIVITY_THINKING_CHARS).
|
|
33
|
-
*/
|
|
34
|
-
type ChatActivityRecord = {
|
|
35
|
-
kind: 'thinking';
|
|
36
|
-
text: string;
|
|
37
|
-
ts: number;
|
|
38
|
-
} | {
|
|
39
|
-
kind: 'tool';
|
|
40
|
-
toolCallId: string;
|
|
41
|
-
name: string;
|
|
42
|
-
status: 'done' | 'failed' | 'interrupted';
|
|
43
|
-
summary?: string;
|
|
44
|
-
argsText?: string;
|
|
45
|
-
resultText?: string;
|
|
46
|
-
isError?: boolean;
|
|
47
|
-
durationMs?: number;
|
|
48
|
-
truncated?: {
|
|
49
|
-
args?: boolean;
|
|
50
|
-
progress?: boolean;
|
|
51
|
-
result?: boolean;
|
|
52
|
-
};
|
|
53
|
-
ts: number;
|
|
54
|
-
};
|
|
55
|
-
interface SessionData {
|
|
56
|
-
sessionId: string;
|
|
57
|
-
agentId: string;
|
|
58
|
-
channel: string;
|
|
59
|
-
tenantId?: string;
|
|
60
|
-
userId?: string;
|
|
61
|
-
createdAt: string;
|
|
62
|
-
updatedAt: string;
|
|
63
|
-
messages: ChatMessage[];
|
|
64
|
-
/**
|
|
65
|
-
* Fallback activity records (see appendActivity). The PRIMARY history
|
|
66
|
-
* source is OpenClaw's own session transcript (transcript-activity.ts) —
|
|
67
|
-
* these records serve conversations whose transcript is missing
|
|
68
|
-
* (deleted / rotated / compacted). Absent on pre-persistence files.
|
|
69
|
-
*/
|
|
70
|
-
activity?: ChatActivityRecord[];
|
|
71
|
-
/**
|
|
72
|
-
* OpenClaw route(s) this conversation dispatched through, captured per
|
|
73
|
-
* turn — the exact transcript lookup keys for transcript-backed history.
|
|
74
|
-
* Multiple entries occur for group conversations (per-peer dm scope
|
|
75
|
-
* yields one OpenClaw session per sender). Absent on old files (the
|
|
76
|
-
* transcript index `:conv:` scan covers those retroactively).
|
|
77
|
-
*/
|
|
78
|
-
routes?: {
|
|
79
|
-
sessionKey: string;
|
|
80
|
-
storePath: string;
|
|
81
|
-
}[];
|
|
82
|
-
}
|
|
83
|
-
interface SessionSummary {
|
|
84
|
-
sessionId: string;
|
|
85
|
-
agentId: string;
|
|
86
|
-
channel: string;
|
|
87
|
-
tenantId?: string;
|
|
88
|
-
userId?: string;
|
|
89
|
-
createdAt: string;
|
|
90
|
-
lastMessageAt?: string;
|
|
91
|
-
preview?: string;
|
|
92
|
-
messageCount: number;
|
|
93
|
-
}
|
|
94
|
-
//#endregion
|
|
1
|
+
import { _ as AlfeResolvedAccount, b as SessionSummary, g as AlfePluginConfig, h as AlfeChannelConfig, m as createAlfeChannelPlugin, u as plugin, v as ChatMessage, y as SessionData } from "./plugin.cjs";
|
|
95
2
|
export { type AlfeChannelConfig, type AlfePluginConfig, type AlfeResolvedAccount, type ChatMessage, type SessionData, type SessionSummary, createAlfeChannelPlugin, plugin as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,95 +1,2 @@
|
|
|
1
|
-
import { _ as AlfeResolvedAccount, g as AlfePluginConfig, h as AlfeChannelConfig, m as createAlfeChannelPlugin, u as plugin } from "./plugin.js";
|
|
2
|
-
|
|
3
|
-
//#region src/session-store.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Session Store — persists chat sessions to the local filesystem.
|
|
7
|
-
*
|
|
8
|
-
* Storage layout:
|
|
9
|
-
* ~/.alfe/sessions/chat/{sessionId}.json
|
|
10
|
-
*
|
|
11
|
-
* Each session file contains metadata and the full message history.
|
|
12
|
-
* Sessions are written on every message to ensure durability.
|
|
13
|
-
* Old sessions are cleaned up automatically (30-day TTL, 1000 max).
|
|
14
|
-
*
|
|
15
|
-
* NOTE: the storage path and SessionData shape are a read contract —
|
|
16
|
-
* packages/openclaw-memory-cloud/src/session-backfill.ts reads these files
|
|
17
|
-
* directly (the memory plugin can't depend on this package). Keep in sync.
|
|
18
|
-
*/
|
|
19
|
-
interface ChatMessage {
|
|
20
|
-
role: 'user' | 'assistant';
|
|
21
|
-
content: string;
|
|
22
|
-
timestamp: number;
|
|
23
|
-
senderId?: string;
|
|
24
|
-
senderName?: string;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Persisted form of a turn's agent activity (tool cards + thinking), so a
|
|
28
|
-
* refresh can replay what the live `chat-activity` stream showed. Terminal
|
|
29
|
-
* by construction: no `progressText` (transient streaming window) and no
|
|
30
|
-
* `running` status — a tool still running at flush time is persisted as
|
|
31
|
-
* `interrupted`. Tool text fields arrive pre-capped (activity-serialize.ts);
|
|
32
|
-
* thinking text is capped at append time (MAX_ACTIVITY_THINKING_CHARS).
|
|
33
|
-
*/
|
|
34
|
-
type ChatActivityRecord = {
|
|
35
|
-
kind: 'thinking';
|
|
36
|
-
text: string;
|
|
37
|
-
ts: number;
|
|
38
|
-
} | {
|
|
39
|
-
kind: 'tool';
|
|
40
|
-
toolCallId: string;
|
|
41
|
-
name: string;
|
|
42
|
-
status: 'done' | 'failed' | 'interrupted';
|
|
43
|
-
summary?: string;
|
|
44
|
-
argsText?: string;
|
|
45
|
-
resultText?: string;
|
|
46
|
-
isError?: boolean;
|
|
47
|
-
durationMs?: number;
|
|
48
|
-
truncated?: {
|
|
49
|
-
args?: boolean;
|
|
50
|
-
progress?: boolean;
|
|
51
|
-
result?: boolean;
|
|
52
|
-
};
|
|
53
|
-
ts: number;
|
|
54
|
-
};
|
|
55
|
-
interface SessionData {
|
|
56
|
-
sessionId: string;
|
|
57
|
-
agentId: string;
|
|
58
|
-
channel: string;
|
|
59
|
-
tenantId?: string;
|
|
60
|
-
userId?: string;
|
|
61
|
-
createdAt: string;
|
|
62
|
-
updatedAt: string;
|
|
63
|
-
messages: ChatMessage[];
|
|
64
|
-
/**
|
|
65
|
-
* Fallback activity records (see appendActivity). The PRIMARY history
|
|
66
|
-
* source is OpenClaw's own session transcript (transcript-activity.ts) —
|
|
67
|
-
* these records serve conversations whose transcript is missing
|
|
68
|
-
* (deleted / rotated / compacted). Absent on pre-persistence files.
|
|
69
|
-
*/
|
|
70
|
-
activity?: ChatActivityRecord[];
|
|
71
|
-
/**
|
|
72
|
-
* OpenClaw route(s) this conversation dispatched through, captured per
|
|
73
|
-
* turn — the exact transcript lookup keys for transcript-backed history.
|
|
74
|
-
* Multiple entries occur for group conversations (per-peer dm scope
|
|
75
|
-
* yields one OpenClaw session per sender). Absent on old files (the
|
|
76
|
-
* transcript index `:conv:` scan covers those retroactively).
|
|
77
|
-
*/
|
|
78
|
-
routes?: {
|
|
79
|
-
sessionKey: string;
|
|
80
|
-
storePath: string;
|
|
81
|
-
}[];
|
|
82
|
-
}
|
|
83
|
-
interface SessionSummary {
|
|
84
|
-
sessionId: string;
|
|
85
|
-
agentId: string;
|
|
86
|
-
channel: string;
|
|
87
|
-
tenantId?: string;
|
|
88
|
-
userId?: string;
|
|
89
|
-
createdAt: string;
|
|
90
|
-
lastMessageAt?: string;
|
|
91
|
-
preview?: string;
|
|
92
|
-
messageCount: number;
|
|
93
|
-
}
|
|
94
|
-
//#endregion
|
|
1
|
+
import { _ as AlfeResolvedAccount, b as SessionSummary, g as AlfePluginConfig, h as AlfeChannelConfig, m as createAlfeChannelPlugin, u as plugin, v as ChatMessage, y as SessionData } from "./plugin.js";
|
|
95
2
|
export { type AlfeChannelConfig, type AlfePluginConfig, type AlfeResolvedAccount, type ChatMessage, type SessionData, type SessionSummary, createAlfeChannelPlugin, plugin as default };
|
package/dist/plugin.d.cts
CHANGED
|
@@ -1,3 +1,152 @@
|
|
|
1
|
+
//#region src/session-store.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Session Store — persists chat sessions to the local filesystem.
|
|
4
|
+
*
|
|
5
|
+
* Storage layout:
|
|
6
|
+
* ~/.alfe/sessions/chat/{sessionId}.json
|
|
7
|
+
*
|
|
8
|
+
* Each session file contains metadata and the full message history.
|
|
9
|
+
* Sessions are written on every message to ensure durability.
|
|
10
|
+
* Old sessions are cleaned up automatically (30-day TTL, 1000 max).
|
|
11
|
+
*
|
|
12
|
+
* NOTE: the storage path and SessionData shape are a read contract —
|
|
13
|
+
* packages/openclaw-memory-cloud/src/session-backfill.ts reads these files
|
|
14
|
+
* directly (the memory plugin can't depend on this package). Keep in sync.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Persisted form of an interactive message component. Structural mirror of
|
|
18
|
+
* `MessageComponent` in `@alfe/chat-transport` — duplicated here rather than
|
|
19
|
+
* imported because openclaw-chat is a PUBLISHED (`@alfe.ai/*`) package and must
|
|
20
|
+
* not carry a runtime dependency on an internal (`@alfe/*`) package (see root
|
|
21
|
+
* DEVELOPING.md → "Publishing public @alfe.ai/* packages"). Keep in sync with
|
|
22
|
+
* the transport union.
|
|
23
|
+
*/
|
|
24
|
+
interface StoredSelectOption {
|
|
25
|
+
label: string;
|
|
26
|
+
value: string;
|
|
27
|
+
}
|
|
28
|
+
type StoredMessageComponent = {
|
|
29
|
+
type: 'link_button';
|
|
30
|
+
id: string;
|
|
31
|
+
label: string;
|
|
32
|
+
url: string;
|
|
33
|
+
target?: 'same-tab' | 'new-tab' | 'popup';
|
|
34
|
+
style?: 'primary' | 'secondary' | 'danger';
|
|
35
|
+
} | {
|
|
36
|
+
type: 'quick_reply';
|
|
37
|
+
id: string;
|
|
38
|
+
label: string;
|
|
39
|
+
value: string;
|
|
40
|
+
style?: 'primary' | 'secondary' | 'danger';
|
|
41
|
+
} | {
|
|
42
|
+
type: 'select';
|
|
43
|
+
id: string;
|
|
44
|
+
label?: string;
|
|
45
|
+
placeholder?: string;
|
|
46
|
+
options: StoredSelectOption[];
|
|
47
|
+
} | {
|
|
48
|
+
type: 'multi_select';
|
|
49
|
+
id: string;
|
|
50
|
+
label?: string;
|
|
51
|
+
options: StoredSelectOption[];
|
|
52
|
+
submitLabel?: string;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'confirm';
|
|
55
|
+
id: string;
|
|
56
|
+
label?: string;
|
|
57
|
+
confirmLabel: string;
|
|
58
|
+
confirmValue: string;
|
|
59
|
+
cancelLabel?: string;
|
|
60
|
+
cancelValue?: string;
|
|
61
|
+
} | {
|
|
62
|
+
type: 'copy_button';
|
|
63
|
+
id: string;
|
|
64
|
+
label: string;
|
|
65
|
+
value: string;
|
|
66
|
+
};
|
|
67
|
+
interface ChatMessage {
|
|
68
|
+
role: 'user' | 'assistant';
|
|
69
|
+
content: string;
|
|
70
|
+
timestamp: number;
|
|
71
|
+
senderId?: string;
|
|
72
|
+
senderName?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Interactive components attached to the message (link buttons, quick
|
|
75
|
+
* replies). Additive field — absent on pre-component files, and ignored by
|
|
76
|
+
* the memory backfill read contract (session-backfill.ts reads only role +
|
|
77
|
+
* content). Persisted so a refresh / reconnect replays the button.
|
|
78
|
+
*/
|
|
79
|
+
components?: StoredMessageComponent[];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Persisted form of a turn's agent activity (tool cards + thinking), so a
|
|
83
|
+
* refresh can replay what the live `chat-activity` stream showed. Terminal
|
|
84
|
+
* by construction: no `progressText` (transient streaming window) and no
|
|
85
|
+
* `running` status — a tool still running at flush time is persisted as
|
|
86
|
+
* `interrupted`. Tool text fields arrive pre-capped (activity-serialize.ts);
|
|
87
|
+
* thinking text is capped at append time (MAX_ACTIVITY_THINKING_CHARS).
|
|
88
|
+
*/
|
|
89
|
+
type ChatActivityRecord = {
|
|
90
|
+
kind: 'thinking';
|
|
91
|
+
text: string;
|
|
92
|
+
ts: number;
|
|
93
|
+
} | {
|
|
94
|
+
kind: 'tool';
|
|
95
|
+
toolCallId: string;
|
|
96
|
+
name: string;
|
|
97
|
+
status: 'done' | 'failed' | 'interrupted';
|
|
98
|
+
summary?: string;
|
|
99
|
+
argsText?: string;
|
|
100
|
+
resultText?: string;
|
|
101
|
+
isError?: boolean;
|
|
102
|
+
durationMs?: number;
|
|
103
|
+
truncated?: {
|
|
104
|
+
args?: boolean;
|
|
105
|
+
progress?: boolean;
|
|
106
|
+
result?: boolean;
|
|
107
|
+
};
|
|
108
|
+
ts: number;
|
|
109
|
+
};
|
|
110
|
+
interface SessionData {
|
|
111
|
+
sessionId: string;
|
|
112
|
+
agentId: string;
|
|
113
|
+
channel: string;
|
|
114
|
+
tenantId?: string;
|
|
115
|
+
userId?: string;
|
|
116
|
+
createdAt: string;
|
|
117
|
+
updatedAt: string;
|
|
118
|
+
messages: ChatMessage[];
|
|
119
|
+
/**
|
|
120
|
+
* Fallback activity records (see appendActivity). The PRIMARY history
|
|
121
|
+
* source is OpenClaw's own session transcript (transcript-activity.ts) —
|
|
122
|
+
* these records serve conversations whose transcript is missing
|
|
123
|
+
* (deleted / rotated / compacted). Absent on pre-persistence files.
|
|
124
|
+
*/
|
|
125
|
+
activity?: ChatActivityRecord[];
|
|
126
|
+
/**
|
|
127
|
+
* OpenClaw route(s) this conversation dispatched through, captured per
|
|
128
|
+
* turn — the exact transcript lookup keys for transcript-backed history.
|
|
129
|
+
* Multiple entries occur for group conversations (per-peer dm scope
|
|
130
|
+
* yields one OpenClaw session per sender). Absent on old files (the
|
|
131
|
+
* transcript index `:conv:` scan covers those retroactively).
|
|
132
|
+
*/
|
|
133
|
+
routes?: {
|
|
134
|
+
sessionKey: string;
|
|
135
|
+
storePath: string;
|
|
136
|
+
}[];
|
|
137
|
+
}
|
|
138
|
+
interface SessionSummary {
|
|
139
|
+
sessionId: string;
|
|
140
|
+
agentId: string;
|
|
141
|
+
channel: string;
|
|
142
|
+
tenantId?: string;
|
|
143
|
+
userId?: string;
|
|
144
|
+
createdAt: string;
|
|
145
|
+
lastMessageAt?: string;
|
|
146
|
+
preview?: string;
|
|
147
|
+
messageCount: number;
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
1
150
|
//#region src/types.d.ts
|
|
2
151
|
/**
|
|
3
152
|
* Types for the Alfe chat channel plugin.
|
|
@@ -48,12 +197,19 @@ interface AlfeOutboundSession {
|
|
|
48
197
|
}
|
|
49
198
|
interface AlfeChannelOutboundDeps {
|
|
50
199
|
getChatClient: () => AlfeOutboundChatClient | null;
|
|
200
|
+
/** Plugin logger — used by the outbound media upload path. Optional so
|
|
201
|
+
* CLI metadata registration (no deps at all) stays unaffected. */
|
|
202
|
+
log?: {
|
|
203
|
+
info(msg: string): void;
|
|
204
|
+
warn(msg: string): void;
|
|
205
|
+
error(msg: string): void;
|
|
206
|
+
};
|
|
51
207
|
listSessions: (filters?: {
|
|
52
208
|
userId?: string;
|
|
53
209
|
}) => Promise<AlfeOutboundSessionSummary[]>;
|
|
54
210
|
getSession: (sessionId: string) => Promise<AlfeOutboundSession | null>;
|
|
55
211
|
createSession: (sessionId: string, agentId: string, channel: string, tenantId?: string, userId?: string) => Promise<unknown>;
|
|
56
|
-
addMessage: (sessionId: string, role: 'user' | 'assistant', content: string, senderId?: string, senderName?: string) => Promise<void>;
|
|
212
|
+
addMessage: (sessionId: string, role: 'user' | 'assistant', content: string, senderId?: string, senderName?: string, components?: StoredMessageComponent[]) => Promise<void>;
|
|
57
213
|
}
|
|
58
214
|
//#endregion
|
|
59
215
|
//#region src/alfe-channel.d.ts
|
|
@@ -71,6 +227,16 @@ interface OutboundDeliveryResult {
|
|
|
71
227
|
conversationId: string;
|
|
72
228
|
timestamp: number;
|
|
73
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Present interactive components (link buttons, quick replies) into a
|
|
232
|
+
* conversation — the outbound path for the `chat_present_components` tool.
|
|
233
|
+
* `to` is a `conv:{id}` or `user:{id}` target (same vocabulary as the channel's
|
|
234
|
+
* `resolveTarget`). Persists + broadcasts through the same `sendViaChat` path
|
|
235
|
+
* as a normal reply, so the components ride the standard `message` frame and
|
|
236
|
+
* are replayed on backfill. Components are sanitized (unsafe URLs dropped)
|
|
237
|
+
* before delivery.
|
|
238
|
+
*/
|
|
239
|
+
|
|
74
240
|
/**
|
|
75
241
|
* Creates the Alfe ChannelPlugin object for registration with OpenClaw.
|
|
76
242
|
*
|
|
@@ -440,4 +606,4 @@ declare const plugin: {
|
|
|
440
606
|
deactivate(api: PluginApi): Promise<void>;
|
|
441
607
|
};
|
|
442
608
|
//#endregion
|
|
443
|
-
export { AlfeResolvedAccount as _, __setActiveRunForTest as a, buildToolActivity as c, resolveAbortTargetKeys as d, rewriteAssistantText as f, AlfePluginConfig as g, AlfeChannelConfig as h, __resetAgentTurnQueueForTest as i, joinAssistantText as l, createAlfeChannelPlugin as m, RunEventGate as n, admitAgentEvent as o, stripLeakedToolSummary as p, __agentTurnQueueForTest as r, buildA2ACompletePayload as s, ActiveRunRef as t, plugin as u };
|
|
609
|
+
export { AlfeResolvedAccount as _, __setActiveRunForTest as a, SessionSummary as b, buildToolActivity as c, resolveAbortTargetKeys as d, rewriteAssistantText as f, AlfePluginConfig as g, AlfeChannelConfig as h, __resetAgentTurnQueueForTest as i, joinAssistantText as l, createAlfeChannelPlugin as m, RunEventGate as n, admitAgentEvent as o, stripLeakedToolSummary as p, __agentTurnQueueForTest as r, buildA2ACompletePayload as s, ActiveRunRef as t, plugin as u, ChatMessage as v, SessionData as y };
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,3 +1,152 @@
|
|
|
1
|
+
//#region src/session-store.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Session Store — persists chat sessions to the local filesystem.
|
|
4
|
+
*
|
|
5
|
+
* Storage layout:
|
|
6
|
+
* ~/.alfe/sessions/chat/{sessionId}.json
|
|
7
|
+
*
|
|
8
|
+
* Each session file contains metadata and the full message history.
|
|
9
|
+
* Sessions are written on every message to ensure durability.
|
|
10
|
+
* Old sessions are cleaned up automatically (30-day TTL, 1000 max).
|
|
11
|
+
*
|
|
12
|
+
* NOTE: the storage path and SessionData shape are a read contract —
|
|
13
|
+
* packages/openclaw-memory-cloud/src/session-backfill.ts reads these files
|
|
14
|
+
* directly (the memory plugin can't depend on this package). Keep in sync.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Persisted form of an interactive message component. Structural mirror of
|
|
18
|
+
* `MessageComponent` in `@alfe/chat-transport` — duplicated here rather than
|
|
19
|
+
* imported because openclaw-chat is a PUBLISHED (`@alfe.ai/*`) package and must
|
|
20
|
+
* not carry a runtime dependency on an internal (`@alfe/*`) package (see root
|
|
21
|
+
* DEVELOPING.md → "Publishing public @alfe.ai/* packages"). Keep in sync with
|
|
22
|
+
* the transport union.
|
|
23
|
+
*/
|
|
24
|
+
interface StoredSelectOption {
|
|
25
|
+
label: string;
|
|
26
|
+
value: string;
|
|
27
|
+
}
|
|
28
|
+
type StoredMessageComponent = {
|
|
29
|
+
type: 'link_button';
|
|
30
|
+
id: string;
|
|
31
|
+
label: string;
|
|
32
|
+
url: string;
|
|
33
|
+
target?: 'same-tab' | 'new-tab' | 'popup';
|
|
34
|
+
style?: 'primary' | 'secondary' | 'danger';
|
|
35
|
+
} | {
|
|
36
|
+
type: 'quick_reply';
|
|
37
|
+
id: string;
|
|
38
|
+
label: string;
|
|
39
|
+
value: string;
|
|
40
|
+
style?: 'primary' | 'secondary' | 'danger';
|
|
41
|
+
} | {
|
|
42
|
+
type: 'select';
|
|
43
|
+
id: string;
|
|
44
|
+
label?: string;
|
|
45
|
+
placeholder?: string;
|
|
46
|
+
options: StoredSelectOption[];
|
|
47
|
+
} | {
|
|
48
|
+
type: 'multi_select';
|
|
49
|
+
id: string;
|
|
50
|
+
label?: string;
|
|
51
|
+
options: StoredSelectOption[];
|
|
52
|
+
submitLabel?: string;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'confirm';
|
|
55
|
+
id: string;
|
|
56
|
+
label?: string;
|
|
57
|
+
confirmLabel: string;
|
|
58
|
+
confirmValue: string;
|
|
59
|
+
cancelLabel?: string;
|
|
60
|
+
cancelValue?: string;
|
|
61
|
+
} | {
|
|
62
|
+
type: 'copy_button';
|
|
63
|
+
id: string;
|
|
64
|
+
label: string;
|
|
65
|
+
value: string;
|
|
66
|
+
};
|
|
67
|
+
interface ChatMessage {
|
|
68
|
+
role: 'user' | 'assistant';
|
|
69
|
+
content: string;
|
|
70
|
+
timestamp: number;
|
|
71
|
+
senderId?: string;
|
|
72
|
+
senderName?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Interactive components attached to the message (link buttons, quick
|
|
75
|
+
* replies). Additive field — absent on pre-component files, and ignored by
|
|
76
|
+
* the memory backfill read contract (session-backfill.ts reads only role +
|
|
77
|
+
* content). Persisted so a refresh / reconnect replays the button.
|
|
78
|
+
*/
|
|
79
|
+
components?: StoredMessageComponent[];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Persisted form of a turn's agent activity (tool cards + thinking), so a
|
|
83
|
+
* refresh can replay what the live `chat-activity` stream showed. Terminal
|
|
84
|
+
* by construction: no `progressText` (transient streaming window) and no
|
|
85
|
+
* `running` status — a tool still running at flush time is persisted as
|
|
86
|
+
* `interrupted`. Tool text fields arrive pre-capped (activity-serialize.ts);
|
|
87
|
+
* thinking text is capped at append time (MAX_ACTIVITY_THINKING_CHARS).
|
|
88
|
+
*/
|
|
89
|
+
type ChatActivityRecord = {
|
|
90
|
+
kind: 'thinking';
|
|
91
|
+
text: string;
|
|
92
|
+
ts: number;
|
|
93
|
+
} | {
|
|
94
|
+
kind: 'tool';
|
|
95
|
+
toolCallId: string;
|
|
96
|
+
name: string;
|
|
97
|
+
status: 'done' | 'failed' | 'interrupted';
|
|
98
|
+
summary?: string;
|
|
99
|
+
argsText?: string;
|
|
100
|
+
resultText?: string;
|
|
101
|
+
isError?: boolean;
|
|
102
|
+
durationMs?: number;
|
|
103
|
+
truncated?: {
|
|
104
|
+
args?: boolean;
|
|
105
|
+
progress?: boolean;
|
|
106
|
+
result?: boolean;
|
|
107
|
+
};
|
|
108
|
+
ts: number;
|
|
109
|
+
};
|
|
110
|
+
interface SessionData {
|
|
111
|
+
sessionId: string;
|
|
112
|
+
agentId: string;
|
|
113
|
+
channel: string;
|
|
114
|
+
tenantId?: string;
|
|
115
|
+
userId?: string;
|
|
116
|
+
createdAt: string;
|
|
117
|
+
updatedAt: string;
|
|
118
|
+
messages: ChatMessage[];
|
|
119
|
+
/**
|
|
120
|
+
* Fallback activity records (see appendActivity). The PRIMARY history
|
|
121
|
+
* source is OpenClaw's own session transcript (transcript-activity.ts) —
|
|
122
|
+
* these records serve conversations whose transcript is missing
|
|
123
|
+
* (deleted / rotated / compacted). Absent on pre-persistence files.
|
|
124
|
+
*/
|
|
125
|
+
activity?: ChatActivityRecord[];
|
|
126
|
+
/**
|
|
127
|
+
* OpenClaw route(s) this conversation dispatched through, captured per
|
|
128
|
+
* turn — the exact transcript lookup keys for transcript-backed history.
|
|
129
|
+
* Multiple entries occur for group conversations (per-peer dm scope
|
|
130
|
+
* yields one OpenClaw session per sender). Absent on old files (the
|
|
131
|
+
* transcript index `:conv:` scan covers those retroactively).
|
|
132
|
+
*/
|
|
133
|
+
routes?: {
|
|
134
|
+
sessionKey: string;
|
|
135
|
+
storePath: string;
|
|
136
|
+
}[];
|
|
137
|
+
}
|
|
138
|
+
interface SessionSummary {
|
|
139
|
+
sessionId: string;
|
|
140
|
+
agentId: string;
|
|
141
|
+
channel: string;
|
|
142
|
+
tenantId?: string;
|
|
143
|
+
userId?: string;
|
|
144
|
+
createdAt: string;
|
|
145
|
+
lastMessageAt?: string;
|
|
146
|
+
preview?: string;
|
|
147
|
+
messageCount: number;
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
1
150
|
//#region src/types.d.ts
|
|
2
151
|
/**
|
|
3
152
|
* Types for the Alfe chat channel plugin.
|
|
@@ -48,12 +197,19 @@ interface AlfeOutboundSession {
|
|
|
48
197
|
}
|
|
49
198
|
interface AlfeChannelOutboundDeps {
|
|
50
199
|
getChatClient: () => AlfeOutboundChatClient | null;
|
|
200
|
+
/** Plugin logger — used by the outbound media upload path. Optional so
|
|
201
|
+
* CLI metadata registration (no deps at all) stays unaffected. */
|
|
202
|
+
log?: {
|
|
203
|
+
info(msg: string): void;
|
|
204
|
+
warn(msg: string): void;
|
|
205
|
+
error(msg: string): void;
|
|
206
|
+
};
|
|
51
207
|
listSessions: (filters?: {
|
|
52
208
|
userId?: string;
|
|
53
209
|
}) => Promise<AlfeOutboundSessionSummary[]>;
|
|
54
210
|
getSession: (sessionId: string) => Promise<AlfeOutboundSession | null>;
|
|
55
211
|
createSession: (sessionId: string, agentId: string, channel: string, tenantId?: string, userId?: string) => Promise<unknown>;
|
|
56
|
-
addMessage: (sessionId: string, role: 'user' | 'assistant', content: string, senderId?: string, senderName?: string) => Promise<void>;
|
|
212
|
+
addMessage: (sessionId: string, role: 'user' | 'assistant', content: string, senderId?: string, senderName?: string, components?: StoredMessageComponent[]) => Promise<void>;
|
|
57
213
|
}
|
|
58
214
|
//#endregion
|
|
59
215
|
//#region src/alfe-channel.d.ts
|
|
@@ -71,6 +227,16 @@ interface OutboundDeliveryResult {
|
|
|
71
227
|
conversationId: string;
|
|
72
228
|
timestamp: number;
|
|
73
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Present interactive components (link buttons, quick replies) into a
|
|
232
|
+
* conversation — the outbound path for the `chat_present_components` tool.
|
|
233
|
+
* `to` is a `conv:{id}` or `user:{id}` target (same vocabulary as the channel's
|
|
234
|
+
* `resolveTarget`). Persists + broadcasts through the same `sendViaChat` path
|
|
235
|
+
* as a normal reply, so the components ride the standard `message` frame and
|
|
236
|
+
* are replayed on backfill. Components are sanitized (unsafe URLs dropped)
|
|
237
|
+
* before delivery.
|
|
238
|
+
*/
|
|
239
|
+
|
|
74
240
|
/**
|
|
75
241
|
* Creates the Alfe ChannelPlugin object for registration with OpenClaw.
|
|
76
242
|
*
|
|
@@ -440,4 +606,4 @@ declare const plugin: {
|
|
|
440
606
|
deactivate(api: PluginApi): Promise<void>;
|
|
441
607
|
};
|
|
442
608
|
//#endregion
|
|
443
|
-
export { AlfeResolvedAccount as _, __setActiveRunForTest as a, buildToolActivity as c, resolveAbortTargetKeys as d, rewriteAssistantText as f, AlfePluginConfig as g, AlfeChannelConfig as h, __resetAgentTurnQueueForTest as i, joinAssistantText as l, createAlfeChannelPlugin as m, RunEventGate as n, admitAgentEvent as o, stripLeakedToolSummary as p, __agentTurnQueueForTest as r, buildA2ACompletePayload as s, ActiveRunRef as t, plugin as u };
|
|
609
|
+
export { AlfeResolvedAccount as _, __setActiveRunForTest as a, SessionSummary as b, buildToolActivity as c, resolveAbortTargetKeys as d, rewriteAssistantText as f, AlfePluginConfig as g, AlfeChannelConfig as h, __resetAgentTurnQueueForTest as i, joinAssistantText as l, createAlfeChannelPlugin as m, RunEventGate as n, admitAgentEvent as o, stripLeakedToolSummary as p, __agentTurnQueueForTest as r, buildA2ACompletePayload as s, ActiveRunRef as t, plugin as u, ChatMessage as v, SessionData as y };
|