@chenkai114/dsh-superagent-dingtalk 0.0.0-stage → 0.0.1

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,221 @@
1
+ import { S as ChannelRef, U as Trigger } from "./intake-Ba9xBNyb.js";
2
+ import { n as Health, r as SourceContext, t as SourceKind } from "./kind-BlPO15JX.js";
3
+ import { Context } from "@deepseek-ai/cordis";
4
+ import { z } from "zod";
5
+ //#region src/sources/dingtalk-config.d.ts
6
+ /** One conversation the Source listens to; `all` also reads messages that do not address the robot. */
7
+ declare const DingtalkGroupSchema: z.ZodObject<{
8
+ conversationId: z.ZodString;
9
+ name: z.ZodOptional<z.ZodString>;
10
+ listen: z.ZodDefault<z.ZodEnum<{
11
+ mentions: "mentions";
12
+ all: "all";
13
+ }>>;
14
+ }, z.core.$strict>;
15
+ type DingtalkGroup = z.infer<typeof DingtalkGroupSchema>;
16
+ /**
17
+ * The Source configuration. Fields are flat because the Settings form edits top-level keys only; the accessors below
18
+ * group them for the code that uses them.
19
+ */
20
+ declare const DingtalkConfigSchema: z.ZodObject<{
21
+ groups: z.ZodDefault<z.ZodArray<z.ZodObject<{
22
+ conversationId: z.ZodString;
23
+ name: z.ZodOptional<z.ZodString>;
24
+ listen: z.ZodDefault<z.ZodEnum<{
25
+ mentions: "mentions";
26
+ all: "all";
27
+ }>>;
28
+ }, z.core.$strict>>>;
29
+ bots: z.ZodDefault<z.ZodArray<z.ZodObject<{
30
+ name: z.ZodString;
31
+ conversationId: z.ZodString;
32
+ token: z.ZodString;
33
+ secret: z.ZodOptional<z.ZodString>;
34
+ }, z.core.$strict>>>;
35
+ streamClientId: z.ZodDefault<z.ZodString>;
36
+ streamClientSecret: z.ZodDefault<z.ZodString>;
37
+ streamRobotCode: z.ZodDefault<z.ZodString>;
38
+ dwsEnabled: z.ZodDefault<z.ZodBoolean>;
39
+ dwsCli: z.ZodDefault<z.ZodString>;
40
+ dwsPollSeconds: z.ZodDefault<z.ZodNumber>;
41
+ dwsPageSize: z.ZodDefault<z.ZodNumber>;
42
+ mentionNames: z.ZodDefault<z.ZodArray<z.ZodObject<{
43
+ name: z.ZodString;
44
+ }, z.core.$strict>>>;
45
+ otherChats: z.ZodDefault<z.ZodBoolean>;
46
+ directMessages: z.ZodDefault<z.ZodBoolean>;
47
+ readPageSize: z.ZodDefault<z.ZodNumber>;
48
+ failuresBeforeError: z.ZodDefault<z.ZodNumber>;
49
+ }, z.core.$strict>;
50
+ type DingtalkConfig = z.infer<typeof DingtalkConfigSchema>;
51
+ /** The Stream robot credentials, or `undefined` when either half is unset. */
52
+ declare const streamOf: (config: DingtalkConfig) => {
53
+ clientId: string;
54
+ clientSecret: string;
55
+ robotCode?: string;
56
+ } | undefined;
57
+ /** The `dws` settings the readers, the poll loop and the channel share. */
58
+ declare const dwsOf: (config: DingtalkConfig) => {
59
+ enabled: boolean;
60
+ cli: string;
61
+ pollSeconds: number;
62
+ pageSize: number;
63
+ };
64
+ //#endregion
65
+ //#region src/sources/dingtalk-trigger.d.ts
66
+ declare const SOURCE = "dingtalk";
67
+ /** Constructs a DingTalk reply channel address; `messageId` is the message a reply quotes, when one is known. */
68
+ declare const dingtalkChannel: (conversationId: string, messageId?: string, extra?: Record<string, string>) => ChannelRef;
69
+ /** One conversation is one Thread: a group's messages and a direct conversation's messages each reply in place. */
70
+ declare const dingtalkThreadId: (conversationId: string) => string;
71
+ /** Deterministic Trigger ID for a DingTalk message, so every read path for it produces the same ID and the Engine deduplicates. */
72
+ declare const dingtalkTriggerId: (messageId: string) => string;
73
+ /**
74
+ * Parses a DingTalk timestamp into ISO-8601. The Stream callback sends epoch milliseconds, while `dws chat message list`
75
+ * prints Shanghai wall-clock time without an offset; an unqualified value is read as UTC+08:00.
76
+ * @param value Epoch milliseconds, or `YYYY-MM-DD HH:mm:ss`.
77
+ * @returns The instant as an ISO-8601 string.
78
+ * @throws when the value is neither form.
79
+ */
80
+ declare function dingtalkTime(value: string | number): string;
81
+ /**
82
+ * A message as the Stream callback delivers it. A message that addresses the robot arrives as `richText`, whose text is a
83
+ * JSON `content` string, not as `text`; a plain text message carries `text.content` instead.
84
+ */
85
+ declare const StreamMessageSchema: z.ZodObject<{
86
+ msgId: z.ZodString;
87
+ conversationId: z.ZodString;
88
+ conversationType: z.ZodDefault<z.ZodString>;
89
+ conversationTitle: z.ZodOptional<z.ZodString>;
90
+ chatbotUserId: z.ZodOptional<z.ZodString>;
91
+ robotCode: z.ZodOptional<z.ZodString>;
92
+ senderId: z.ZodDefault<z.ZodString>;
93
+ senderNick: z.ZodDefault<z.ZodString>;
94
+ senderStaffId: z.ZodOptional<z.ZodString>;
95
+ createAt: z.ZodNumber;
96
+ msgtype: z.ZodDefault<z.ZodString>;
97
+ text: z.ZodOptional<z.ZodObject<{
98
+ content: z.ZodDefault<z.ZodString>;
99
+ }, z.core.$loose>>;
100
+ content: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
101
+ richText: z.ZodOptional<z.ZodArray<z.ZodObject<{
102
+ text: z.ZodOptional<z.ZodString>;
103
+ }, z.core.$loose>>>;
104
+ }, z.core.$loose>]>>;
105
+ isInAtList: z.ZodOptional<z.ZodBoolean>;
106
+ sessionWebhook: z.ZodOptional<z.ZodString>;
107
+ sessionWebhookExpiredTime: z.ZodOptional<z.ZodNumber>;
108
+ atUsers: z.ZodDefault<z.ZodArray<z.ZodObject<{
109
+ dingtalkId: z.ZodOptional<z.ZodString>;
110
+ staffId: z.ZodOptional<z.ZodString>;
111
+ }, z.core.$loose>>>;
112
+ }, z.core.$loose>;
113
+ type StreamMessage = z.infer<typeof StreamMessageSchema>;
114
+ /**
115
+ * Flattens a Stream message body to plain text. A rich-text body is a JSON `content` whose `richText` array carries text
116
+ * runs in order, so a mention and the request that follows it read as one sentence.
117
+ * @param message The message as the Stream callback delivered it.
118
+ * @returns The text, or an empty string when the body carries none this Source can read.
119
+ */
120
+ declare function streamText(message: StreamMessage): string;
121
+ /** What a normalized message carries into a Trigger, independent of which transport read it. */
122
+ interface DingtalkMessageInput {
123
+ messageId: string;
124
+ conversationId: string;
125
+ /** Milliseconds since the epoch, or a Shanghai wall-clock string. */
126
+ at: string | number;
127
+ text: string;
128
+ senderId: string;
129
+ /** Other IDs the same person has on the platform, such as a staff ID the other transport reports. */
130
+ senderAliases?: string[];
131
+ senderName?: string;
132
+ /** `true` for a person; the history read reports robots as `robot`. */
133
+ human: boolean;
134
+ direct: boolean;
135
+ /** Whether the message addresses the agent: always true for a group message the Stream callback delivered. */
136
+ mentioned: boolean;
137
+ /** Present on a message the Stream callback delivered; a reply can go there without any sending permission. */
138
+ sessionWebhook?: string | undefined;
139
+ sessionWebhookExpiredTime?: number | undefined;
140
+ robotCode?: string | undefined;
141
+ /** The conversation's display name, when the transport reports one. */
142
+ conversationTitle?: string | undefined;
143
+ /** Set when a Thread's message is quoted, so a reply can quote it too. */
144
+ quoteMessageId?: string | undefined;
145
+ }
146
+ /**
147
+ * Builds a Trigger for a normalized DingTalk message.
148
+ * @param input The message as either transport normalized it.
149
+ * @returns The Trigger, or `undefined` when the text is empty and the message can carry no request.
150
+ */
151
+ declare function dingtalkTrigger(input: DingtalkMessageInput): Trigger | undefined;
152
+ //#endregion
153
+ //#region src/sources/dingtalk-loops.d.ts
154
+ /**
155
+ * Whether `text` addresses one of the configured robot names. A history read has no structural mention field, so this is
156
+ * the only addressing signal it has; the admission table still decides whether an unaddressed message may become work.
157
+ * @param text The message body.
158
+ * @param names The robot display names to look for.
159
+ * @returns True when the text names one of them with an `@`.
160
+ */
161
+ declare function addressedTo(text: string, names: readonly string[]): boolean;
162
+ /**
163
+ * Runs every configured transport until `signal` aborts: the Stream connection, and the `dws` poll loop.
164
+ * @param host The Source context.
165
+ * @param signal Aborts the run, closing the connection.
166
+ */
167
+ declare function runDingtalk(host: SourceContext, signal: AbortSignal): Promise<void>;
168
+ //#endregion
169
+ //#region src/sources/dingtalk-stream.d.ts
170
+ /** The credentials and identity of the application robot that receives messages. */
171
+ interface StreamConfig {
172
+ clientId: string;
173
+ clientSecret: string;
174
+ /** The robot that posts; defaults to `clientId`, which is what an application robot uses. */
175
+ robotCode?: string;
176
+ }
177
+ /** What the Stream client reports upward: one normalized message per callback, and its own health. */
178
+ interface StreamHandlers {
179
+ /** Receives a message the robot was addressed in; in a group the platform delivers only addressed messages. */
180
+ message(input: DingtalkMessageInput, robotCode: string): Promise<void>;
181
+ /** Reports the connection state, so a refused connection shows on the overview instead of failing silently. */
182
+ report(state: Health['state'], detail: string): void;
183
+ }
184
+ /**
185
+ * Holds one Stream connection and turns its callbacks into domain messages.
186
+ * A connection the platform refuses means the application robot is not published or its receiving mode is not Stream;
187
+ * the failure is reported once, because a person must change it in the DingTalk developer console.
188
+ */
189
+ declare class DingtalkStream {
190
+ private readonly config;
191
+ private readonly handlers;
192
+ private client;
193
+ private stopped;
194
+ constructor(config: StreamConfig, handlers: StreamHandlers);
195
+ /** The robot code this connection receives for. */
196
+ get robotCode(): string;
197
+ /**
198
+ * Opens the connection and registers the robot message topic.
199
+ * @throws when the credentials are rejected, so the Source reports the failure instead of waiting silently.
200
+ */
201
+ start(): Promise<void>;
202
+ /** Closes the connection; a later `start` opens a new one. */
203
+ stop(): void;
204
+ private handleRobot;
205
+ }
206
+ //#endregion
207
+ //#region src/sources/dingtalk.d.ts
208
+ /**
209
+ * DingTalk Source: reads a conversation through the operator's `dws` CLI, receives messages addressed to an application
210
+ * robot over the Stream long connection, and replies as a bot so its words are never attributed to the operator.
211
+ */
212
+ declare const dingtalkKind: SourceKind<DingtalkConfig>;
213
+ declare const name = "dsh-superagent-dingtalk";
214
+ declare const inject: string[];
215
+ /**
216
+ * Registers the DingTalk Source kind and runs its transports.
217
+ * @param ctx The Cordis context the bundle mounts in.
218
+ */
219
+ declare function apply(ctx: Context): void;
220
+ //#endregion
221
+ export { type DingtalkConfig, DingtalkConfigSchema, type DingtalkGroup, type DingtalkMessageInput, DingtalkStream, SOURCE, type StreamMessage, StreamMessageSchema, addressedTo, apply, dingtalkChannel, dingtalkKind, dingtalkThreadId, dingtalkTime, dingtalkTrigger, dingtalkTriggerId, dwsOf, inject, name, runDingtalk, streamOf, streamText };