eve-lark 0.1.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,258 @@
1
+ import { Channel } from 'eve/channels';
2
+
3
+ /**
4
+ * Public types for eve-lark.
5
+ */
6
+ /**
7
+ * Discriminated union of normalized inbound message parts (text vs file).
8
+ * Useful for consumers that want to inspect what eve-lark handed to `send()`.
9
+ */
10
+ type LarkInboundMessage = LarkInboundResult;
11
+ type LarkReplyMode = "streaming" | "static";
12
+ /**
13
+ * Branded string for a continuation token in the wire format `${chatId}:${rootMessageId ?? "_"}`.
14
+ * Use {@link larkContinuationToken} to mint one.
15
+ */
16
+ type LarkContinuationToken = string & {
17
+ readonly __larkContinuationTokenBrand: unique symbol;
18
+ };
19
+ interface LarkChannelOptions {
20
+ appId?: string | undefined;
21
+ appSecret?: string | undefined;
22
+ verificationToken?: string | undefined;
23
+ encryptKey?: string | undefined;
24
+ baseUrl?: string | undefined;
25
+ botOpenId?: string | undefined;
26
+ webhookPath?: string | undefined;
27
+ replyMode?: LarkReplyMode | undefined;
28
+ streamPatchIntervalMs?: number | undefined;
29
+ streamCreateThresholdMs?: number | undefined;
30
+ dedupTtlMs?: number | undefined;
31
+ dedupMaxEntries?: number | undefined;
32
+ requestTimeoutMs?: number | undefined;
33
+ maxRetries?: number | undefined;
34
+ tokenRefreshBufferMs?: number | undefined;
35
+ signatureSkewMs?: number | undefined;
36
+ fetch?: typeof fetch | undefined;
37
+ /**
38
+ * Emoji type to react to the inbound user message with as soon as it arrives
39
+ * (acknowledgement feedback). Set to a Feishu emoji type string like
40
+ * "TYPING", an array of candidates (one is picked at random per message),
41
+ * or `false` to disable. Default: "TYPING".
42
+ */
43
+ ackReaction?: string | readonly string[] | false | undefined;
44
+ }
45
+ interface ResolvedLarkOptions {
46
+ appId: string;
47
+ appSecret: string;
48
+ verificationToken: string;
49
+ encryptKey: string | undefined;
50
+ baseUrl: string;
51
+ botOpenId: string | undefined;
52
+ webhookPath: string;
53
+ replyMode: LarkReplyMode;
54
+ streamPatchIntervalMs: number;
55
+ streamCreateThresholdMs: number;
56
+ dedupTtlMs: number;
57
+ dedupMaxEntries: number;
58
+ requestTimeoutMs: number;
59
+ maxRetries: number;
60
+ tokenRefreshBufferMs: number;
61
+ signatureSkewMs: number;
62
+ fetch: typeof fetch;
63
+ ackReaction: string | readonly string[] | false;
64
+ }
65
+ type LarkSenderType = "user" | "app";
66
+ type LarkChatType = "p2p" | "group";
67
+ interface LarkMention {
68
+ key: string;
69
+ id: LarkMentionId;
70
+ name: string;
71
+ idType: LarkMentionIdType;
72
+ isOpenIdOfBot: boolean;
73
+ isAll: boolean;
74
+ }
75
+ interface LarkMentionId {
76
+ openId?: string | undefined;
77
+ userId?: string | undefined;
78
+ unionId?: string | undefined;
79
+ }
80
+ type LarkMentionIdType = "open_id" | "user_id" | "union_id";
81
+ interface LarkInboundFile {
82
+ fileKey: string;
83
+ mediaType: string;
84
+ kind: "image" | "file";
85
+ }
86
+ interface LarkInboundResult {
87
+ text: string;
88
+ files: LarkInboundFile[];
89
+ chatId: string;
90
+ rootId: string | null;
91
+ parentId: string | null;
92
+ messageId: string;
93
+ senderOpenId: string;
94
+ senderType: LarkSenderType;
95
+ chatType: LarkChatType;
96
+ mentions: LarkMention[];
97
+ }
98
+ /** Subset of the official v2 `im.message.receive_v1` event payload we depend on. */
99
+ interface LarkInboundEvent {
100
+ message: {
101
+ message_id: string;
102
+ root_id?: string | undefined;
103
+ parent_id?: string | undefined;
104
+ chat_id: string;
105
+ message_type: string;
106
+ content: string;
107
+ create_time?: string | undefined;
108
+ mentions?: LarkRawMention[] | undefined;
109
+ };
110
+ sender: {
111
+ sender_id: {
112
+ open_id?: string | undefined;
113
+ user_id?: string | undefined;
114
+ union_id?: string | undefined;
115
+ };
116
+ sender_type?: string | undefined;
117
+ };
118
+ chat_type?: string | undefined;
119
+ }
120
+ interface LarkRawMention {
121
+ key: string;
122
+ id: {
123
+ open_id?: string | undefined;
124
+ user_id?: string | undefined;
125
+ union_id?: string | undefined;
126
+ };
127
+ name: string;
128
+ id_type?: LarkMentionIdType | undefined;
129
+ }
130
+ interface LarkContext {
131
+ client: unknown;
132
+ options: ResolvedLarkOptions;
133
+ anchorThread(rootMessageId: string): void;
134
+ }
135
+ interface LarkAdapterState {
136
+ client: unknown;
137
+ dedup: unknown;
138
+ options: ResolvedLarkOptions;
139
+ }
140
+ /**
141
+ * Minimal interactive card payload (template_blue).
142
+ */
143
+ interface LarkCard {
144
+ config: {
145
+ wide_screen_mode?: boolean | undefined;
146
+ update_multi?: boolean | undefined;
147
+ };
148
+ elements: LarkCardElement[];
149
+ }
150
+ type LarkCardElement = {
151
+ tag: "markdown";
152
+ content: string;
153
+ } | {
154
+ tag: "hr";
155
+ } | {
156
+ tag: "note";
157
+ elements: Array<{
158
+ tag: "plain_text";
159
+ content: string;
160
+ }>;
161
+ };
162
+
163
+ /**
164
+ * Continuation token format: `${chatId}:${rootMessageId ?? "_"}`.
165
+ * The framework prepends the channel file stem before handing the token to
166
+ * the runtime; consumers should call this helper rather than concatenate.
167
+ */
168
+ declare function larkContinuationToken(chatId: string, rootMessageId: string | null): LarkContinuationToken;
169
+ /**
170
+ * Create a Lark/Feishu channel for the eve agent framework.
171
+ *
172
+ * The channel mounts a single POST webhook that verifies the request,
173
+ * decrypts the body when an encrypt key is configured, deduplicates events
174
+ * by id, parses the inbound message, and starts or resumes an eve session.
175
+ *
176
+ * Streaming happens via eve's native channel events: `message.appended`
177
+ * drives live card patches, `message.completed` finalizes the card, and
178
+ * `turn.failed` aborts it. In `replyMode: "static"` the controller is
179
+ * skipped and `message.completed` delivers a single card.
180
+ */
181
+ declare function createLarkChannel(optionsInput: LarkChannelOptions): Channel<undefined, Record<string, unknown>, Record<string, unknown>>;
182
+
183
+ declare class LarkClient {
184
+ #private;
185
+ private readonly options;
186
+ private token;
187
+ private refreshPromise;
188
+ constructor(options: ResolvedLarkOptions);
189
+ getTenantAccessToken(): Promise<string>;
190
+ sendText(args: {
191
+ chatId: string;
192
+ content: string;
193
+ rootId?: string;
194
+ parentId?: string;
195
+ }): Promise<{
196
+ messageId: string;
197
+ }>;
198
+ sendCard(args: {
199
+ chatId: string;
200
+ card: LarkCard;
201
+ rootId?: string;
202
+ parentId?: string;
203
+ }): Promise<{
204
+ messageId: string;
205
+ }>;
206
+ patchCard(args: {
207
+ messageId: string;
208
+ card: LarkCard;
209
+ }): Promise<void>;
210
+ downloadResource(args: {
211
+ messageId: string;
212
+ fileKey: string;
213
+ type: "image" | "file";
214
+ }): Promise<Buffer>;
215
+ addReaction(args: {
216
+ messageId: string;
217
+ emojiType: string;
218
+ }): Promise<{
219
+ reactionId: string;
220
+ }>;
221
+ removeReaction(args: {
222
+ messageId: string;
223
+ reactionId: string;
224
+ }): Promise<void>;
225
+ }
226
+
227
+ /**
228
+ * Typed error hierarchy for eve-lark.
229
+ *
230
+ * All errors extend a common base so consumers can `instanceof LarkChannelError`
231
+ * to catch anything thrown by the channel.
232
+ */
233
+ declare class LarkChannelError extends Error {
234
+ constructor(message: string, options?: ErrorOptions);
235
+ }
236
+ declare class LarkConfigError extends LarkChannelError {
237
+ }
238
+ declare class LarkSignatureError extends LarkChannelError {
239
+ }
240
+ declare class LarkDecryptError extends LarkChannelError {
241
+ }
242
+ interface LarkApiErrorBody {
243
+ code?: number | undefined;
244
+ msg?: string | undefined;
245
+ }
246
+ declare class LarkApiError extends LarkChannelError {
247
+ readonly code: number | undefined;
248
+ readonly body: LarkApiErrorBody | undefined;
249
+ readonly status: number | undefined;
250
+ constructor(message: string, opts?: {
251
+ code?: number | undefined;
252
+ body?: LarkApiErrorBody | undefined;
253
+ status?: number | undefined;
254
+ cause?: unknown;
255
+ });
256
+ }
257
+
258
+ export { type LarkAdapterState, LarkApiError, type LarkApiErrorBody, type LarkCard, type LarkCardElement, LarkChannelError, type LarkChannelOptions, LarkClient, LarkConfigError, type LarkContext, type LarkContinuationToken, LarkDecryptError, type LarkInboundEvent, type LarkInboundFile, type LarkInboundMessage, type LarkInboundResult, type LarkMention, type LarkReplyMode, LarkSignatureError, type ResolvedLarkOptions, createLarkChannel, larkContinuationToken };