@rivus/gateway 0.22.3 → 0.24.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/README.md +3 -3
- package/assets/audio-transcriber/THIRD_PARTY_NOTICES.md +1 -3
- package/assets/audio-transcriber/fetch-model.mjs +29 -21
- package/assets/audio-transcriber/npm-shrinkwrap.json +5 -63
- package/assets/audio-transcriber/package.json +1 -1
- package/assets/installation-policy.json +9 -4
- package/dist/bootstrap/feishu.d.ts +42 -3
- package/dist/bootstrap/feishu.js +11964 -12401
- package/dist/bootstrap/herdr-feishu.d.ts +8 -1
- package/dist/bootstrap/herdr-feishu.js +2 -2
- package/dist/chunks/dist.js +10371 -0
- package/dist/chunks/errors.js +13 -0
- package/dist/chunks/herdr-feishu-runtime.js +128 -395
- package/dist/chunks/herdr-socket-client.js +496 -0
- package/dist/chunks/public.d.ts +93 -63
- package/dist/chunks/public2.d.ts +0 -7
- package/dist/chunks/rivus-deployment-cli-process.d.ts +136 -353
- package/dist/chunks/rivus-node-entrypoint.js +1543 -1579
- package/dist/chunks/superagent-worker-programs.js +7240 -0
- package/dist/chunks/superagent-worker-wire.js +233 -0
- package/dist/index.d.ts +12 -25
- package/dist/index.js +2 -1
- package/dist/mcp.js +109 -24
- package/dist/superagent.d.ts +301 -0
- package/dist/superagent.js +2 -0
- package/package.json +25 -11
- package/dist/chunks/automation-presentation.js +0 -263
- package/dist/chunks/feishu-receive-message.js +0 -113
- package/dist/chunks/rivus-home-deployment-env.js +0 -1916
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
//#region ../superagent/dist/chunks/scenario.d.ts
|
|
3
|
+
//#region src/work/domain/audience/audience.d.ts
|
|
4
|
+
type Audience = "public" | "internal" | `private:${string}:${string}` | `group:${string}:${string}`;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/work/domain/trigger/adapters/input.d.ts
|
|
7
|
+
declare const triggerInput: Schema.Struct<{
|
|
8
|
+
readonly sourceEventId: Schema.NonEmptyString;
|
|
9
|
+
readonly inReplyTo: Schema.optionalKey<Schema.NonEmptyString>;
|
|
10
|
+
readonly kind: Schema.Literals<readonly ["message", "comment", "review", "ci", "thread_closed", "thread_open", "timer", "edit", "delete"]>;
|
|
11
|
+
readonly threads: Schema.NonEmptyArray<Schema.NonEmptyString>;
|
|
12
|
+
readonly actor: Schema.Struct<{
|
|
13
|
+
readonly id: Schema.NonEmptyString;
|
|
14
|
+
readonly kind: Schema.Literals<readonly ["person", "bot", "self", "system"]>;
|
|
15
|
+
}>;
|
|
16
|
+
readonly addressed: Schema.optionalKey<Schema.Literals<readonly ["mention", "direct", "watch", "observed"]>>;
|
|
17
|
+
readonly audience: Schema.Union<readonly [Schema.Literals<readonly ["public", "internal", "private"]>, Schema.TemplateLiteral<readonly ["group:", Schema.NonEmptyString]>]>;
|
|
18
|
+
readonly occurredAt: Schema.DateFromString;
|
|
19
|
+
readonly text: Schema.String;
|
|
20
|
+
readonly replyTarget: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
21
|
+
readonly closeOutcome: Schema.optionalKey<Schema.Literals<readonly ["closed", "merged"]>>;
|
|
22
|
+
}>;
|
|
23
|
+
type TriggerInput = typeof triggerInput.Encoded;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/work/domain/trigger/adapters/message-change-input.d.ts
|
|
26
|
+
declare const messageChange: Schema.Struct<{
|
|
27
|
+
readonly originalSourceEventId: Schema.NonEmptyString;
|
|
28
|
+
readonly kind: Schema.Literals<readonly ["edit", "delete"]>;
|
|
29
|
+
readonly occurredAt: Schema.DateFromString;
|
|
30
|
+
readonly text: Schema.String;
|
|
31
|
+
readonly thread: Schema.optionalKey<Schema.NonEmptyString>;
|
|
32
|
+
}>;
|
|
33
|
+
type MessageChangeInput = typeof messageChange.Encoded;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/work/domain/reply/notice-text.d.ts
|
|
36
|
+
/** The language of the fixed texts the host writes to a source; a source declares it, English by default. */
|
|
37
|
+
type ReplyLocale = "en" | "zh";
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/work/domain/reply/delivery.d.ts
|
|
40
|
+
/** What a source reports after one send attempt. */
|
|
41
|
+
type SendResult = {
|
|
42
|
+
readonly status: "sent";
|
|
43
|
+
readonly remoteId: string;
|
|
44
|
+
} | {
|
|
45
|
+
readonly status: "gone" | "retry" | "unknown";
|
|
46
|
+
readonly reason: string;
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/work/application/spi/source.d.ts
|
|
50
|
+
interface ReplyRequest {
|
|
51
|
+
readonly id: string;
|
|
52
|
+
readonly generation: number;
|
|
53
|
+
readonly firstAttemptAt: number;
|
|
54
|
+
readonly thread: string;
|
|
55
|
+
readonly audience: Audience;
|
|
56
|
+
readonly target: Readonly<Record<string, string>>;
|
|
57
|
+
readonly text: string;
|
|
58
|
+
/** The key returned by this source's upload for a native file message. */
|
|
59
|
+
readonly fileKey?: string;
|
|
60
|
+
}
|
|
61
|
+
interface SourceHealth {
|
|
62
|
+
readonly state: "ready" | "degraded" | "failed";
|
|
63
|
+
readonly reason: string | undefined;
|
|
64
|
+
}
|
|
65
|
+
interface ThreadPage {
|
|
66
|
+
readonly events: readonly TriggerInput[];
|
|
67
|
+
readonly changes?: readonly MessageChangeInput[];
|
|
68
|
+
readonly cursor: string | undefined;
|
|
69
|
+
}
|
|
70
|
+
/** Host services a source kind may use. */
|
|
71
|
+
interface SourceHost {
|
|
72
|
+
/** The secret a configuration reference names, or `undefined` when it is not set; throws on a malformed reference. */
|
|
73
|
+
secret(this: void, ref: string): string | undefined;
|
|
74
|
+
}
|
|
75
|
+
interface SuperagentSource {
|
|
76
|
+
prepare?(signal: AbortSignal): Promise<void>;
|
|
77
|
+
start(signal: AbortSignal): Promise<void>;
|
|
78
|
+
send(reply: ReplyRequest): Promise<SendResult>;
|
|
79
|
+
/** Upload immutable file content for a subsequent native file reply through this same source. */
|
|
80
|
+
readonly files?: {
|
|
81
|
+
readonly maxBytes: number;
|
|
82
|
+
upload(name: string, content: Uint8Array): Promise<string>;
|
|
83
|
+
};
|
|
84
|
+
readThread?(thread: string, cursor?: string, signal?: AbortSignal): Promise<ThreadPage>;
|
|
85
|
+
/**
|
|
86
|
+
* How replies to this source are written. A `conversational` source is where people chat with the bot, so it receives dispatch
|
|
87
|
+
* acknowledgements and the notice when all of a Task's deliverables close; `maxWords`, `maxCharacters` (UTF-16 code units,
|
|
88
|
+
* prefix included) and `prefix` apply to every reply.
|
|
89
|
+
* `locale` is the language of the host's fixed notices there, English by default.
|
|
90
|
+
*/
|
|
91
|
+
readonly reply?: {
|
|
92
|
+
readonly conversational?: boolean;
|
|
93
|
+
readonly maxWords?: number;
|
|
94
|
+
readonly maxCharacters?: number;
|
|
95
|
+
readonly prefix?: string;
|
|
96
|
+
readonly locale?: ReplyLocale;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Where to start a direct chat with an allowlisted actor, for the host's notices about watched threads: a native
|
|
100
|
+
* thread key and the address `send` receives. `undefined` when this source cannot reach the actor.
|
|
101
|
+
*/
|
|
102
|
+
directTarget?(this: void, actor: string): {
|
|
103
|
+
readonly thread: string;
|
|
104
|
+
readonly address: Readonly<Record<string, string>>;
|
|
105
|
+
} | undefined;
|
|
106
|
+
/** A readable label for a native thread on Router cards, and its web address when it has one. */
|
|
107
|
+
describeThread?(this: void, thread: string): {
|
|
108
|
+
readonly label?: string;
|
|
109
|
+
readonly url?: string;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
interface SourceState {
|
|
113
|
+
get<T, Encoded>(key: string, schema: Schema.Codec<T, Encoded>): Promise<T | undefined>;
|
|
114
|
+
set<T, Encoded>(key: string, schema: Schema.Codec<T, Encoded>, value: T): Promise<void>;
|
|
115
|
+
}
|
|
116
|
+
interface SuperagentSourceContext<Config> {
|
|
117
|
+
/** The kind's own configuration, decoded by its `config` Schema. */
|
|
118
|
+
readonly config: Config;
|
|
119
|
+
readonly host: SourceHost;
|
|
120
|
+
receive(trigger: TriggerInput, options?: {
|
|
121
|
+
readonly filtered?: string;
|
|
122
|
+
}): Promise<"stored" | "duplicate" | "filtered">;
|
|
123
|
+
receiveMessageChange?(this: void, change: MessageChangeInput): Promise<"stored" | "duplicate" | "unknown" | "pending">;
|
|
124
|
+
/** Whether this source already admitted the message in the given native thread, if supplied. */
|
|
125
|
+
receivedMessage?(sourceEventId: string, thread?: string, actorId?: string): boolean;
|
|
126
|
+
isSubscribed(thread: string): boolean;
|
|
127
|
+
polledThreads(): Promise<readonly string[]>;
|
|
128
|
+
/** Durable source state. A missing key reads as `undefined`; a value of another shape fails naming its key. */
|
|
129
|
+
readonly state: SourceState;
|
|
130
|
+
report(health: SourceHealth): void;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* A kind of trigger source, such as GitHub or Feishu. A configured source is `{ id, kind, allowedActors, ...fields }`:
|
|
134
|
+
* Superagent decodes the shared fields, and `config` decodes the remaining fields, rejecting unknown ones.
|
|
135
|
+
*/
|
|
136
|
+
interface SuperagentSourceKind<Config = unknown> {
|
|
137
|
+
/** An identifier matching `^[a-z0-9][a-z0-9_-]*$`; `timer` is reserved for internal follow-ups. */
|
|
138
|
+
readonly kind: string;
|
|
139
|
+
readonly config: Schema.Codec<Config, unknown>;
|
|
140
|
+
/**
|
|
141
|
+
* Maps a configured `allowedActors` entry to the form this kind's triggers carry, such as a lowercase login. Sources
|
|
142
|
+
* already emit actor IDs in that form.
|
|
143
|
+
*/
|
|
144
|
+
normalizeActor?(this: void, id: string): string;
|
|
145
|
+
/** Checks what the source needs from the host before startup, such as its credential; throws when unmet. */
|
|
146
|
+
preflight?(this: void, config: Config, host: SourceHost): void;
|
|
147
|
+
/**
|
|
148
|
+
* The kind emits watch candidates (`addressed: "watch"`): events from people outside the allowlist that the Router
|
|
149
|
+
* judges against the owner's instructions. A Superagent with such a source must configure an `owner`.
|
|
150
|
+
*/
|
|
151
|
+
readonly watches?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* The kind emits observed candidates (`addressed: "observed"`): messages, comments and reviews that do not address
|
|
154
|
+
* the bot, offered because the source observes where they happened. Intake keeps the mark only for an actor on the
|
|
155
|
+
* source's `allowedActors`; anyone else's event arrives as the unaddressed event it is.
|
|
156
|
+
*/
|
|
157
|
+
readonly observes?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* What the Router must know about this kind's watch or observed candidates beyond Superagent's own description of
|
|
160
|
+
* those bases, such as what its threads are and how a watch task's worker fetches one. Superagent appends the notes
|
|
161
|
+
* of every configured kind to the Router instructions, so a changed note starts a new policy.
|
|
162
|
+
*/
|
|
163
|
+
readonly routerNotes?: string;
|
|
164
|
+
/** The owner's instructions on this kind's watch candidate cards when the configuration sets none. */
|
|
165
|
+
readonly defaultWatchInstructions?: string;
|
|
166
|
+
/** The owner's instructions on this kind's observed candidate cards when the configuration sets none. */
|
|
167
|
+
readonly defaultObservedInstructions?: string;
|
|
168
|
+
create(this: void, context: SuperagentSourceContext<Config>): SuperagentSource;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* A named set of source and scenario kinds that a deployment loads. Source kind names, and scenario kind names, must be
|
|
172
|
+
* unique across the presets a deployment names; the trigger kinds a source emits stay Superagent's fixed set.
|
|
173
|
+
*/
|
|
174
|
+
interface SuperagentSourcePreset {
|
|
175
|
+
/** A readable name for error messages, such as `builtin` or the package name. */
|
|
176
|
+
readonly id: string;
|
|
177
|
+
readonly sourceKinds: readonly SuperagentSourceKind[];
|
|
178
|
+
readonly scenarioKinds?: readonly SuperagentScenarioKind[];
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/work/application/spi/scenario.d.ts
|
|
182
|
+
/** The Task a scenario is asked about. */
|
|
183
|
+
interface ScenarioTask {
|
|
184
|
+
readonly id: string;
|
|
185
|
+
/** Names the Task's workspace directory and its branch `agent/<shortName>`. */
|
|
186
|
+
readonly shortName: string;
|
|
187
|
+
/** The configured repository the Task works in; `undefined` for work without one. */
|
|
188
|
+
readonly repository: string | undefined;
|
|
189
|
+
}
|
|
190
|
+
/** A report a worker or the host recorded for an open Task. */
|
|
191
|
+
interface ScenarioReport {
|
|
192
|
+
readonly id: string;
|
|
193
|
+
readonly state: "progress" | "waiting" | "ready" | "blocked" | "failed" | "dropped";
|
|
194
|
+
/** Addresses of what the worker published; the scenario recognizes the ones it can claim. */
|
|
195
|
+
readonly links?: readonly string[];
|
|
196
|
+
}
|
|
197
|
+
/** Variables and Git configuration a scenario adds to a Task's worker environment. */
|
|
198
|
+
interface WorkerEnvironment {
|
|
199
|
+
readonly variables: Readonly<Record<string, string>>;
|
|
200
|
+
readonly gitConfig?: ReadonlyArray<readonly [key: string, value: string]>;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* What one kind of work adds to "a worker ran a Task", such as coding with its pull requests. Superagent runs at most
|
|
204
|
+
* one scenario, which its kind creates over the configured source the scenario names as its code host. Work keeps execution
|
|
205
|
+
* authority: it authenticates a worker, requires an open Task and applies its own credential rule before it asks the
|
|
206
|
+
* scenario for a credential.
|
|
207
|
+
*/
|
|
208
|
+
interface Scenario {
|
|
209
|
+
/** The repositories the scenario serves; each must be a configured Superagent repository. */
|
|
210
|
+
readonly repositories: readonly string[];
|
|
211
|
+
/** The repository a native thread of the code host source belongs to, such as `owner/name`. */
|
|
212
|
+
repositoryOf(this: void, thread: string): string | undefined;
|
|
213
|
+
/**
|
|
214
|
+
* `task.reported`: runs on an open Task's report that names a link or is ready, before the Router sees it, for
|
|
215
|
+
* example to bind the deliverables the report names. Work calls it outside any transaction and retries it with
|
|
216
|
+
* backoff when it fails, and again after a restart that interrupted it, so it must be idempotent. When it returns,
|
|
217
|
+
* Work relays the report even if the Task ended meanwhile, for example because it bound deliverables that had
|
|
218
|
+
* already closed.
|
|
219
|
+
*/
|
|
220
|
+
onTaskReported(this: void, event: {
|
|
221
|
+
readonly task: ScenarioTask;
|
|
222
|
+
readonly report: ScenarioReport;
|
|
223
|
+
}): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* The scenario's additions to the Task's worker environment. `waiting` holds the Task's deliveries until the
|
|
226
|
+
* scenario is ready, such as before it verified its account; `undefined` adds nothing.
|
|
227
|
+
*/
|
|
228
|
+
workerEnvironment(this: void, task: ScenarioTask): WorkerEnvironment | "waiting" | undefined;
|
|
229
|
+
/** The credential a worker's Git or CLI request for `repository` receives, or `undefined` to refuse it. */
|
|
230
|
+
credential(this: void, task: ScenarioTask, request: {
|
|
231
|
+
readonly repository: string | undefined;
|
|
232
|
+
}): {
|
|
233
|
+
readonly username: string;
|
|
234
|
+
readonly token: string;
|
|
235
|
+
} | undefined;
|
|
236
|
+
/** Standing instructions every worker delivery carries after the host's own. */
|
|
237
|
+
readonly workerInstructions?: string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* What a scenario kind creates its scenario with. Work's operations act on native threads of the code host source,
|
|
241
|
+
* which Work keys as `<codeHost>:<thread>` exactly as that source's own context does.
|
|
242
|
+
*/
|
|
243
|
+
interface ScenarioContext<Config> {
|
|
244
|
+
/** The kind's own configuration, decoded by its `config` Schema. */
|
|
245
|
+
readonly config: Config;
|
|
246
|
+
/**
|
|
247
|
+
* The configured source `codeHost` names, as its kind created it, before it is prepared or started. The scenario kind
|
|
248
|
+
* takes from it the host it works through, so the scenario and the source act as the one account the source verifies.
|
|
249
|
+
*/
|
|
250
|
+
readonly codeHost: SuperagentSource;
|
|
251
|
+
/**
|
|
252
|
+
* The Git credential helper, as a `credential.helper` value, through which a worker's Git asks the scenario for a
|
|
253
|
+
* credential; `undefined` when the host runs no worker credential service.
|
|
254
|
+
*/
|
|
255
|
+
readonly gitCredentialHelper: string | undefined;
|
|
256
|
+
/** Whether an open Task follows the code host's native thread. */
|
|
257
|
+
isSubscribed(this: void, thread: string): boolean;
|
|
258
|
+
/** The open Task with this short name. */
|
|
259
|
+
openTaskByShortName(this: void, shortName: string): string | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* Binds native threads as the Task's deliverables in one transaction: the Task follows them and ends once all of
|
|
262
|
+
* its deliverables have closed.
|
|
263
|
+
*/
|
|
264
|
+
bindDeliverables(this: void, taskId: string, threads: readonly string[]): Promise<void>;
|
|
265
|
+
/** Makes the Task follow a native thread whose closure does not end it. */
|
|
266
|
+
bindThread(this: void, taskId: string, thread: string): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Marks `key` failed in Superagent's health until restart, such as a link the scenario could not verify for a Task.
|
|
269
|
+
* The caller chooses a key that names the problem.
|
|
270
|
+
*/
|
|
271
|
+
reportFailure(this: void, key: string): void;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* A kind of scenario, such as coding. The configured scenario is `{ kind, codeHost, ...fields }`: Superagent decodes
|
|
275
|
+
* `kind` and `codeHost`, the ID of a configured source, and `config` decodes the remaining fields, rejecting unknown
|
|
276
|
+
* ones.
|
|
277
|
+
*/
|
|
278
|
+
interface SuperagentScenarioKind<Config = unknown> {
|
|
279
|
+
/** An identifier matching `^[a-z0-9][a-z0-9_-]*$`. */
|
|
280
|
+
readonly kind: string;
|
|
281
|
+
readonly config: Schema.Codec<Config, unknown>;
|
|
282
|
+
/**
|
|
283
|
+
* What the configured source `codeHost` names would serve as this scenario's host, read from its kind and decoded
|
|
284
|
+
* settings alone, so the configuration check needs no network and creates no source: the repositories it serves,
|
|
285
|
+
* each of which must be a configured repository, or `undefined` when no source of that kind can host this scenario.
|
|
286
|
+
*/
|
|
287
|
+
codeHost(this: void, source: {
|
|
288
|
+
readonly kind: SuperagentSourceKind;
|
|
289
|
+
readonly settings: unknown;
|
|
290
|
+
}): {
|
|
291
|
+
readonly repositories: readonly string[];
|
|
292
|
+
} | undefined;
|
|
293
|
+
/**
|
|
294
|
+
* Creates the scenario once every configured source exists and before any is prepared or started, so the scenario
|
|
295
|
+
* can register what its code host calls while it polls.
|
|
296
|
+
*/
|
|
297
|
+
create(this: void, context: ScenarioContext<Config>): Scenario;
|
|
298
|
+
}
|
|
299
|
+
//#endregion
|
|
300
|
+
export type { MessageChangeInput, ReplyRequest, Scenario, ScenarioContext, ScenarioReport, ScenarioTask, SendResult, SourceHost, SuperagentScenarioKind, SuperagentSource, SuperagentSourceContext, SuperagentSourceKind, SuperagentSourcePreset, TriggerInput, WorkerEnvironment };
|
|
301
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivus/gateway",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Message gateway, channels, host binding, automation, and daemon assembly for Rivus.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -31,6 +31,11 @@
|
|
|
31
31
|
"import": "./dist/mcp.js",
|
|
32
32
|
"default": "./dist/mcp.js"
|
|
33
33
|
},
|
|
34
|
+
"./superagent": {
|
|
35
|
+
"types": "./dist/superagent.d.ts",
|
|
36
|
+
"import": "./dist/superagent.js",
|
|
37
|
+
"default": "./dist/superagent.js"
|
|
38
|
+
},
|
|
34
39
|
"./cli": "./dist/cli.js",
|
|
35
40
|
"./plugin/starter": "./templates/rivus-starter.plugin.mjs",
|
|
36
41
|
"./skills/runtime-management/SKILL.md": "./skills/runtime-management/SKILL.md",
|
|
@@ -58,30 +63,39 @@
|
|
|
58
63
|
"LICENSE"
|
|
59
64
|
],
|
|
60
65
|
"dependencies": {
|
|
61
|
-
"@agentclientprotocol/sdk": "1.
|
|
62
|
-
"@
|
|
66
|
+
"@agentclientprotocol/sdk": "1.9.0",
|
|
67
|
+
"@earendil-works/chord": "1.5.2",
|
|
68
|
+
"@earendil-works/pi-ai": "1.5.2",
|
|
69
|
+
"@earendil-works/pi-coding-agent": "1.5.2",
|
|
70
|
+
"@earendil-works/pi-durable": "1.5.2",
|
|
71
|
+
"@earendil-works/pi-schema": "1.5.2",
|
|
72
|
+
"@larksuiteoapi/node-sdk": "1.76.0",
|
|
63
73
|
"@resvg/resvg-js": "2.6.2",
|
|
64
|
-
"@rivus/agent-kit": "0.
|
|
65
|
-
"@rivus/agent-kit-collab": "0.
|
|
66
|
-
"@rivus/platform": "0.
|
|
67
|
-
"@rivus/runtime": "0.
|
|
68
|
-
"axios": "1.
|
|
74
|
+
"@rivus/agent-kit": "0.25.0",
|
|
75
|
+
"@rivus/agent-kit-collab": "0.25.0",
|
|
76
|
+
"@rivus/platform": "0.24.0",
|
|
77
|
+
"@rivus/runtime": "0.24.0",
|
|
78
|
+
"axios": "1.21.1",
|
|
69
79
|
"effect": "4.1.1",
|
|
70
80
|
"get-east-asian-width": "1.7.0",
|
|
71
|
-
"marked": "18.
|
|
72
|
-
"semver": "7.8.
|
|
81
|
+
"marked": "18.2.0",
|
|
82
|
+
"semver": "7.8.6",
|
|
73
83
|
"yaml": "2.9.1"
|
|
74
84
|
},
|
|
75
85
|
"publishConfig": {
|
|
76
86
|
"access": "public"
|
|
77
87
|
},
|
|
78
88
|
"devDependencies": {
|
|
89
|
+
"@rivus/scenario-coding": "0.21.2",
|
|
90
|
+
"@rivus/superagent": "0.21.2",
|
|
91
|
+
"@rivus/trigger-github": "0.21.2",
|
|
92
|
+
"@rivus/trigger-wechat": "0.21.2",
|
|
79
93
|
"@rivus/utils": "0.21.2",
|
|
80
94
|
"@types/node": "24.19.2",
|
|
81
95
|
"@types/semver": "7.8.0",
|
|
82
96
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
83
97
|
"@vitest/coverage-v8": "5.0.5",
|
|
84
|
-
"tar": "
|
|
98
|
+
"tar": "8.0.5",
|
|
85
99
|
"typescript": "6.0.3",
|
|
86
100
|
"unbzip2-stream": "1.4.3",
|
|
87
101
|
"vite": "npm:@voidzero-dev/vite-plus-core@1.3.0",
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import { i as formatSchemaIssuePath } from "./feishu-receive-message.js";
|
|
2
|
-
import { Result, Schema, SchemaIssue } from "effect";
|
|
3
|
-
//#region src/automation/domain/automation-occurrence/errors/rivus-automation-failure.ts
|
|
4
|
-
var RivusAutomationFailure = class extends Error {
|
|
5
|
-
name = "RivusAutomationFailure";
|
|
6
|
-
code;
|
|
7
|
-
constructor(code, message = code, options) {
|
|
8
|
-
if (typeof code !== "string" || !/^[A-Z][A-Z0-9_]{0,63}$/.test(code)) throw new TypeError("Automation failure code must match ^[A-Z][A-Z0-9_]{0,63}$");
|
|
9
|
-
super(message, options);
|
|
10
|
-
this.code = code;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/automation/domain/presentation/adapters/automation-presentation-validation.ts
|
|
15
|
-
var InvalidAutomationPresentation = class extends Error {
|
|
16
|
-
name = "InvalidAutomationPresentation";
|
|
17
|
-
};
|
|
18
|
-
function decodePresentationValue(schema, value, path) {
|
|
19
|
-
const result = Schema.decodeUnknownResult(schema, { onExcessProperty: "error" })(value);
|
|
20
|
-
if (Result.isSuccess(result)) return result.success;
|
|
21
|
-
const issue = SchemaIssue.makeFormatterStandardSchemaV1()(result.failure.issue).issues[0];
|
|
22
|
-
throw new InvalidAutomationPresentation(`Automation presentation ${(path + formatSchemaIssuePath(issue)).replace(/^\./, "") || "value"}: ${issue.message}`);
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/automation/domain/presentation/adapters/automation-line-chart.ts
|
|
26
|
-
const lineChartSchema = Schema.Struct({
|
|
27
|
-
title: Schema.String,
|
|
28
|
-
labels: Schema.Array(Schema.String),
|
|
29
|
-
unit: Schema.String,
|
|
30
|
-
seriesLayout: Schema.optional(Schema.Literals(["overlay", "separate"])),
|
|
31
|
-
series: Schema.Array(Schema.Struct({
|
|
32
|
-
name: Schema.String,
|
|
33
|
-
values: Schema.Array(Schema.Number)
|
|
34
|
-
}))
|
|
35
|
-
});
|
|
36
|
-
function readAutomationLineChart(value, path = "lineChart") {
|
|
37
|
-
const chart = decodePresentationValue(lineChartSchema, value, path);
|
|
38
|
-
const text = (value, path, limit) => {
|
|
39
|
-
const normalized = value.trim();
|
|
40
|
-
if (!normalized || normalized.length > limit) throw new InvalidAutomationPresentation(`Automation presentation ${path} must contain 1 to ${limit} characters`);
|
|
41
|
-
return normalized;
|
|
42
|
-
};
|
|
43
|
-
if (chart.labels.length < 2 || chart.labels.length > 60) throw new InvalidAutomationPresentation(`Automation presentation ${path}.labels requires 2 to 60 labels`);
|
|
44
|
-
const labels = Array.from(chart.labels, (label, index) => text(label, `${path}.labels[${index}]`, 64));
|
|
45
|
-
if (new Set(labels).size !== labels.length) throw new InvalidAutomationPresentation(`Automation presentation ${path}.labels must be unique`);
|
|
46
|
-
if (chart.series.length < 1 || chart.series.length > 6) throw new InvalidAutomationPresentation(`Automation presentation ${path}.series requires 1 to 6 series`);
|
|
47
|
-
const series = Array.from(chart.series, (row, seriesIndex) => {
|
|
48
|
-
const rowPath = `${path}.series[${seriesIndex}]`;
|
|
49
|
-
if (row.values.length !== labels.length) throw new InvalidAutomationPresentation(`Automation presentation ${rowPath}.values must align with every label`);
|
|
50
|
-
const values = Array.from(row.values, (value, valueIndex) => {
|
|
51
|
-
if (!Number.isFinite(value)) throw new InvalidAutomationPresentation(`Automation presentation ${rowPath}.values[${valueIndex}] must be a finite number`);
|
|
52
|
-
return value;
|
|
53
|
-
});
|
|
54
|
-
return Object.freeze({
|
|
55
|
-
name: text(row.name, `${rowPath}.name`, 80),
|
|
56
|
-
values: Object.freeze(values)
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
if (new Set(series.map(({ name }) => name)).size !== series.length) throw new InvalidAutomationPresentation(`Automation presentation ${path}.series names must be unique`);
|
|
60
|
-
return Object.freeze({
|
|
61
|
-
title: text(chart.title, `${path}.title`, 120),
|
|
62
|
-
labels: Object.freeze(labels),
|
|
63
|
-
unit: text(chart.unit, `${path}.unit`, 80),
|
|
64
|
-
...chart.seriesLayout === void 0 ? {} : { seriesLayout: chart.seriesLayout },
|
|
65
|
-
series: Object.freeze(series)
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
const sourceSchema = Schema.Struct({
|
|
69
|
-
label: Schema.String,
|
|
70
|
-
url: Schema.String
|
|
71
|
-
});
|
|
72
|
-
const itemFields = {
|
|
73
|
-
emphasis: Schema.optional(Schema.Literal("accent")),
|
|
74
|
-
headline: Schema.String,
|
|
75
|
-
note: Schema.optional(Schema.String)
|
|
76
|
-
};
|
|
77
|
-
const sectionFields = {
|
|
78
|
-
collapsed: Schema.optional(Schema.Boolean),
|
|
79
|
-
id: Schema.String,
|
|
80
|
-
lineChart: Schema.optional(Schema.Unknown),
|
|
81
|
-
listStyle: Schema.optional(Schema.Literals([
|
|
82
|
-
"bullet",
|
|
83
|
-
"numbered",
|
|
84
|
-
"plain"
|
|
85
|
-
])),
|
|
86
|
-
style: Schema.optional(Schema.Literals(["plain", "highlight"])),
|
|
87
|
-
table: Schema.optional(Schema.Struct({
|
|
88
|
-
columns: Schema.Array(Schema.Struct({
|
|
89
|
-
label: Schema.String,
|
|
90
|
-
align: Schema.optional(Schema.Literals([
|
|
91
|
-
"left",
|
|
92
|
-
"center",
|
|
93
|
-
"right"
|
|
94
|
-
])),
|
|
95
|
-
width: Schema.optional(Schema.Number)
|
|
96
|
-
})),
|
|
97
|
-
rows: Schema.Array(Schema.Array(Schema.Struct({
|
|
98
|
-
text: Schema.String,
|
|
99
|
-
trend: Schema.optional(Schema.Literals([
|
|
100
|
-
"up",
|
|
101
|
-
"down",
|
|
102
|
-
"flat"
|
|
103
|
-
]))
|
|
104
|
-
})))
|
|
105
|
-
})),
|
|
106
|
-
title: Schema.String
|
|
107
|
-
};
|
|
108
|
-
const presentationFields = {
|
|
109
|
-
footer: Schema.optional(Schema.String),
|
|
110
|
-
footnote: Schema.optional(Schema.String),
|
|
111
|
-
kind: Schema.optional(Schema.Literals([
|
|
112
|
-
"daily-ai",
|
|
113
|
-
"generic",
|
|
114
|
-
"industry",
|
|
115
|
-
"news",
|
|
116
|
-
"subscriptions"
|
|
117
|
-
])),
|
|
118
|
-
lineChart: Schema.optional(Schema.Unknown),
|
|
119
|
-
sectionDividers: Schema.optional(Schema.Boolean),
|
|
120
|
-
subtitle: Schema.optional(Schema.String),
|
|
121
|
-
summary: Schema.optional(Schema.String),
|
|
122
|
-
summaryStyle: Schema.optional(Schema.Literals(["plain", "highlight"])),
|
|
123
|
-
title: Schema.String,
|
|
124
|
-
trendColors: Schema.optional(Schema.Literals(["red-up", "green-up"]))
|
|
125
|
-
};
|
|
126
|
-
Schema.Struct({
|
|
127
|
-
...presentationFields,
|
|
128
|
-
meta: Schema.optional(Schema.Array(Schema.String)),
|
|
129
|
-
sections: Schema.Array(Schema.Struct({
|
|
130
|
-
...sectionFields,
|
|
131
|
-
items: Schema.Array(Schema.Struct({
|
|
132
|
-
...itemFields,
|
|
133
|
-
sources: Schema.optional(Schema.Array(sourceSchema))
|
|
134
|
-
}))
|
|
135
|
-
}))
|
|
136
|
-
});
|
|
137
|
-
const presentationSchema = Schema.Struct({
|
|
138
|
-
...presentationFields,
|
|
139
|
-
meta: Schema.Array(Schema.String),
|
|
140
|
-
schemaVersion: Schema.Literal(2),
|
|
141
|
-
sections: Schema.Array(Schema.Struct({
|
|
142
|
-
...sectionFields,
|
|
143
|
-
items: Schema.Array(Schema.Struct({
|
|
144
|
-
...itemFields,
|
|
145
|
-
sources: Schema.Array(sourceSchema)
|
|
146
|
-
}))
|
|
147
|
-
}))
|
|
148
|
-
});
|
|
149
|
-
const hasCurrentSchemaVersion = (value) => value?.schemaVersion === 2;
|
|
150
|
-
function requiredText(value, path, maxLength) {
|
|
151
|
-
const normalized = value.trim();
|
|
152
|
-
if (!normalized) throw new InvalidAutomationPresentation(`Automation presentation ${path} is empty`);
|
|
153
|
-
if (normalized.length > maxLength) throw new InvalidAutomationPresentation(`Automation presentation ${path} exceeds ${maxLength} characters`);
|
|
154
|
-
return normalized;
|
|
155
|
-
}
|
|
156
|
-
function normalizeTable(table, path, trendColors) {
|
|
157
|
-
if (table.columns.length < 1 || table.columns.length > 6) throw new InvalidAutomationPresentation(`Automation presentation ${path}.columns requires 1 to 6 columns`);
|
|
158
|
-
const columns = table.columns.map((column, index) => {
|
|
159
|
-
if (column.width !== void 0 && (!Number.isInteger(column.width) || column.width < 1 || column.width > 100)) throw new InvalidAutomationPresentation(`Automation presentation ${path}.columns[${index}].width must be an integer from 1 to 100`);
|
|
160
|
-
return Object.freeze({
|
|
161
|
-
label: requiredText(column.label, `${path}.columns[${index}].label`, 40),
|
|
162
|
-
...column.align === void 0 ? {} : { align: column.align },
|
|
163
|
-
...column.width === void 0 ? {} : { width: column.width }
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
const widths = columns.filter((column) => column.width !== void 0);
|
|
167
|
-
if (widths.length !== 0 && widths.length !== columns.length) throw new InvalidAutomationPresentation(`Automation presentation ${path}.columns must all specify width or all omit it`);
|
|
168
|
-
if (widths.reduce((sum, column) => sum + column.width, 0) > 100) throw new InvalidAutomationPresentation(`Automation presentation ${path}.columns width total exceeds 100`);
|
|
169
|
-
if (table.rows.length < 1 || table.rows.length > 20) throw new InvalidAutomationPresentation(`Automation presentation ${path}.rows requires 1 to 20 rows`);
|
|
170
|
-
const rows = table.rows.map((row, rowIndex) => {
|
|
171
|
-
const rowPath = `${path}.rows[${rowIndex}]`;
|
|
172
|
-
if (row.length !== columns.length) throw new InvalidAutomationPresentation(`Automation presentation ${rowPath} must contain ${columns.length} cells`);
|
|
173
|
-
return Object.freeze(row.map((cell, cellIndex) => {
|
|
174
|
-
if (cell.trend !== void 0 && trendColors === void 0) throw new InvalidAutomationPresentation(`Automation presentation ${rowPath}[${cellIndex}].trend requires trendColors`);
|
|
175
|
-
return Object.freeze({
|
|
176
|
-
text: requiredText(cell.text, `${rowPath}[${cellIndex}].text`, 80),
|
|
177
|
-
...cell.trend === void 0 ? {} : { trend: cell.trend }
|
|
178
|
-
});
|
|
179
|
-
}));
|
|
180
|
-
});
|
|
181
|
-
return Object.freeze({
|
|
182
|
-
columns: Object.freeze(columns),
|
|
183
|
-
rows: Object.freeze(rows)
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
function requiredIdentifier(value, path) {
|
|
187
|
-
const normalized = requiredText(value, path, 80);
|
|
188
|
-
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(normalized)) throw new InvalidAutomationPresentation(`Automation presentation ${path} is not a stable identifier`);
|
|
189
|
-
return normalized;
|
|
190
|
-
}
|
|
191
|
-
function safeHttpUrl(value, path) {
|
|
192
|
-
try {
|
|
193
|
-
const parsed = new URL(value);
|
|
194
|
-
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") throw new Error("unsupported protocol");
|
|
195
|
-
return parsed.toString();
|
|
196
|
-
} catch {
|
|
197
|
-
throw new InvalidAutomationPresentation(`Automation presentation ${path} must be an HTTP(S) URL`);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
function normalizePresentation(input) {
|
|
201
|
-
const title = requiredText(input.title, "title", 120);
|
|
202
|
-
const meta = (input.meta ?? []).map((value, index) => requiredText(value, `meta[${index}]`, 80));
|
|
203
|
-
if (meta.length > 6) throw new InvalidAutomationPresentation("Automation presentation meta exceeds 6 items");
|
|
204
|
-
if (input.sections.length > 12) throw new InvalidAutomationPresentation("Automation presentation sections exceeds 12 sections");
|
|
205
|
-
if (input.summaryStyle === "highlight" && !input.summary?.trim()) throw new InvalidAutomationPresentation("Automation presentation summaryStyle highlight requires summary");
|
|
206
|
-
let chartCount = input.lineChart === void 0 ? 0 : 1;
|
|
207
|
-
let tableCount = 0;
|
|
208
|
-
const sections = input.sections.map((section, sectionIndex) => {
|
|
209
|
-
const path = `sections[${sectionIndex}]`;
|
|
210
|
-
const id = requiredIdentifier(section.id, `${path}.id`);
|
|
211
|
-
const sectionTitle = requiredText(section.title, `${path}.title`, 80);
|
|
212
|
-
if (section.items.length > 40) throw new InvalidAutomationPresentation(`Automation presentation ${path}.items exceeds 40 items`);
|
|
213
|
-
if (section.collapsed && section.style === "highlight") throw new InvalidAutomationPresentation(`Automation presentation ${path}.collapsed cannot use style highlight`);
|
|
214
|
-
if (section.lineChart !== void 0 && ++chartCount > 1) throw new InvalidAutomationPresentation(`Automation presentation ${path}.lineChart exceeds one lineChart`);
|
|
215
|
-
if (section.table !== void 0) {
|
|
216
|
-
if (section.collapsed || section.style === "highlight") throw new InvalidAutomationPresentation(`Automation presentation ${path}.table requires a plain, expanded section`);
|
|
217
|
-
if (++tableCount > 5) throw new InvalidAutomationPresentation(`Automation presentation ${path}.table exceeds 5 tables`);
|
|
218
|
-
}
|
|
219
|
-
return Object.freeze({
|
|
220
|
-
...section.collapsed === void 0 ? {} : { collapsed: section.collapsed },
|
|
221
|
-
id,
|
|
222
|
-
items: Object.freeze(section.items.map((item, itemIndex) => {
|
|
223
|
-
const itemPath = `${path}.items[${itemIndex}]`;
|
|
224
|
-
return Object.freeze({
|
|
225
|
-
...item.emphasis === void 0 ? {} : { emphasis: item.emphasis },
|
|
226
|
-
headline: requiredText(item.headline, `${itemPath}.headline`, 240),
|
|
227
|
-
...item.note ? { note: requiredText(item.note, `${itemPath}.note`, 400) } : {},
|
|
228
|
-
sources: Object.freeze((item.sources ?? []).map((source, sourceIndex) => Object.freeze({
|
|
229
|
-
label: requiredText(source.label, `${itemPath}.sources[${sourceIndex}].label`, 60),
|
|
230
|
-
url: safeHttpUrl(source.url, `${itemPath}.sources[${sourceIndex}].url`)
|
|
231
|
-
})))
|
|
232
|
-
});
|
|
233
|
-
})),
|
|
234
|
-
...section.lineChart === void 0 ? {} : { lineChart: readAutomationLineChart(section.lineChart, `${path}.lineChart`) },
|
|
235
|
-
...section.listStyle === void 0 ? {} : { listStyle: section.listStyle },
|
|
236
|
-
...section.style === void 0 ? {} : { style: section.style },
|
|
237
|
-
...section.table === void 0 ? {} : { table: normalizeTable(section.table, `${path}.table`, input.trendColors) },
|
|
238
|
-
title: sectionTitle
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
return Object.freeze({
|
|
242
|
-
...input.footer === void 0 ? {} : { footer: requiredText(input.footer, "footer", 120) },
|
|
243
|
-
...input.lineChart === void 0 ? {} : { lineChart: readAutomationLineChart(input.lineChart) },
|
|
244
|
-
...input.footnote ? { footnote: requiredText(input.footnote, "footnote", 240) } : {},
|
|
245
|
-
...input.kind === void 0 ? {} : { kind: input.kind },
|
|
246
|
-
meta: Object.freeze(meta),
|
|
247
|
-
schemaVersion: 2,
|
|
248
|
-
...input.sectionDividers === void 0 ? {} : { sectionDividers: input.sectionDividers },
|
|
249
|
-
sections: Object.freeze(sections),
|
|
250
|
-
...input.subtitle === void 0 ? {} : { subtitle: requiredText(input.subtitle, "subtitle", 120) },
|
|
251
|
-
...input.summary ? { summary: requiredText(input.summary, "summary", 800) } : {},
|
|
252
|
-
...input.summaryStyle === void 0 ? {} : { summaryStyle: input.summaryStyle },
|
|
253
|
-
title,
|
|
254
|
-
...input.trendColors === void 0 ? {} : { trendColors: input.trendColors }
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
function readAutomationPresentation(value) {
|
|
258
|
-
if (!hasCurrentSchemaVersion(value)) throw new InvalidAutomationPresentation(`Automation presentation schemaVersion must be 2`);
|
|
259
|
-
return normalizePresentation(decodePresentationValue(presentationSchema, value, ""));
|
|
260
|
-
}
|
|
261
|
-
//#endregion
|
|
262
|
-
export { RivusAutomationFailure as n, readAutomationPresentation as t };
|
|
263
|
-
|