@rivus/gateway 0.21.2 → 0.22.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.
Files changed (31) hide show
  1. package/README.md +4 -1
  2. package/assets/audio-transcriber/fetch-model.mjs +63 -70
  3. package/assets/audio-transcriber/transcribe.mjs +38 -47
  4. package/assets/installation-policy.json +4 -3
  5. package/dist/bootstrap/feishu.d.ts +4 -2
  6. package/dist/bootstrap/feishu.js +19389 -17389
  7. package/dist/bootstrap/herdr-feishu.d.ts +1 -7
  8. package/dist/bootstrap/herdr-feishu.js +23 -12
  9. package/dist/chunks/automation-presentation.js +58 -60
  10. package/dist/chunks/feishu-receive-message.js +113 -0
  11. package/dist/chunks/herdr-feishu-runtime.js +1011 -626
  12. package/dist/chunks/public.d.ts +278 -0
  13. package/dist/chunks/public2.d.ts +10 -0
  14. package/dist/chunks/rivus-deployment-cli-process.d.ts +127 -455
  15. package/dist/chunks/rivus-home-deployment-env.js +1342 -1781
  16. package/dist/chunks/rivus-node-entrypoint.js +4574 -4199
  17. package/dist/index.d.ts +23 -11
  18. package/dist/mcp.d.ts +10 -9
  19. package/dist/mcp.js +43 -43
  20. package/package.json +18 -11
  21. package/templates/a-share-briefing-analysis.mjs +32 -34
  22. package/templates/a-share-briefing-renderer.mjs +175 -186
  23. package/templates/a-share-index-evidence.mjs +50 -54
  24. package/templates/a-share-market-briefing.mjs +37 -39
  25. package/templates/a-share-overseas-evidence.mjs +35 -39
  26. package/templates/a-share-policy-evidence.mjs +90 -96
  27. package/templates/a-share-sector-evidence.mjs +32 -35
  28. package/templates/acp-stdio-proxy.mjs +21 -22
  29. package/templates/current-weather.mjs +56 -58
  30. package/templates/html-drive-tools.mjs +130 -141
  31. package/templates/rivus-agents.plugin.mjs +55 -57
@@ -1,10 +1,4 @@
1
- import { Effect } from "effect";
2
- //#region src/adapters/herdr/session/herdr-socket-client.d.ts
3
- interface HerdrSessionConfig {
4
- readonly name: string;
5
- readonly socketPath: string;
6
- }
7
- //#endregion
1
+ import { t as HerdrSessionConfig } from "../chunks/public2.js";
8
2
  //#region src/bootstrap/herdr-feishu.d.ts
9
3
  export interface HerdrFeishuBridgeOptions {
10
4
  readonly appId: string;
@@ -1,5 +1,7 @@
1
- import { a as openTerminalBindingsStore, d as parseFeishuTerminalMessage, i as openTerminalMessageClaims, l as createFeishuTerminalDelivery, r as standaloneHerdrOptionsSchema, s as createHerdrSocketClient, t as createHerdrFeishuBridgeRuntime, u as parseFeishuTerminalAction } from "../chunks/herdr-feishu-runtime.js";
1
+ import { t as decodeFeishuReceiveMessage } from "../chunks/feishu-receive-message.js";
2
+ import { c as parseFeishuTerminalMessage, d as decodeFeishuTerminalEvent, h as createHerdrSocketClient, i as standaloneHerdrOptionsSchema, n as openHerdrBridgeStores, o as createFeishuTerminalDelivery, p as fileTerminalSessionStores, s as parseFeishuTerminalAction, t as createHerdrFeishuBridgeRuntime, u as decodeFeishuCardCallback, v as decodeFeishuTerminalText } from "../chunks/herdr-feishu-runtime.js";
2
3
  import { Effect, Schema } from "effect";
4
+ import { createNodePlatform } from "@rivus/agent-kit/node";
3
5
  import { Client, EventDispatcher, LoggerLevel, WSClient } from "@larksuiteoapi/node-sdk";
4
6
  //#region src/bootstrap/herdr-feishu.ts
5
7
  const configSchema = standaloneHerdrOptionsSchema;
@@ -20,11 +22,12 @@ async function checkHerdrFeishuBridge(options) {
20
22
  }
21
23
  async function startHerdrFeishuBridge(options) {
22
24
  const sessions = configuredSessions(options);
23
- const claims = await openTerminalMessageClaims(options.stateDirectory, options.appId);
24
- const bindings = await openTerminalBindingsStore(options.stateDirectory, options.appId).catch(async (error) => {
25
- await claims.close();
26
- throw error;
27
- });
25
+ const platform = createNodePlatform();
26
+ const stores = await openHerdrBridgeStores(fileTerminalSessionStores({
27
+ appId: options.appId,
28
+ directory: options.stateDirectory,
29
+ platform
30
+ }));
28
31
  const client = new Client({
29
32
  appId: options.appId,
30
33
  appSecret: options.appSecret,
@@ -41,13 +44,12 @@ async function startHerdrFeishuBridge(options) {
41
44
  actors: options.allowedActors,
42
45
  chats: options.allowedChats,
43
46
  writable: options.writable === true,
44
- claim: claims.claim,
45
- bindings,
47
+ stores: stores.context,
46
48
  delivery: createFeishuTerminalDelivery(client, { isStopped: () => stopState.stopped }),
47
49
  stopState,
48
50
  ...options.fontFiles === void 0 ? {} : { fontFiles: options.fontFiles },
49
51
  ...options.onObservation === void 0 ? {} : { onObservation: options.onObservation },
50
- closeStores: () => claims.close()
52
+ closeStores: stores.close
51
53
  });
52
54
  const receive = async (message) => {
53
55
  if (!message) return;
@@ -58,10 +60,19 @@ async function startHerdrFeishuBridge(options) {
58
60
  if (!await runtime.submit(message)) throw new Error("Herdr bridge queue is full or stopped");
59
61
  };
60
62
  const dispatcher = new EventDispatcher({}).register({
61
- "im.message.receive_v1": (event) => receive(parseFeishuTerminalMessage(event)),
62
- "application.bot.menu_v6": (event) => receive(parseFeishuTerminalAction(event, options.menuChats ?? {})),
63
+ "im.message.receive_v1": (event) => {
64
+ let message;
65
+ try {
66
+ message = decodeFeishuReceiveMessage(event);
67
+ } catch {
68
+ return;
69
+ }
70
+ if (message.event.message.message_type !== "text") return;
71
+ return receive(parseFeishuTerminalMessage(message.event, decodeFeishuTerminalText(message.event.message.content)));
72
+ },
73
+ "application.bot.menu_v6": (event) => receive(parseFeishuTerminalAction(decodeFeishuTerminalEvent(event), options.menuChats ?? {})),
63
74
  "card.action.trigger": async (event) => {
64
- await receive(parseFeishuTerminalAction(event, options.menuChats ?? {}));
75
+ await receive(parseFeishuTerminalAction(decodeFeishuCardCallback(event).terminal, options.menuChats ?? {}));
65
76
  return {};
66
77
  }
67
78
  });
@@ -1,5 +1,6 @@
1
+ import { i as formatSchemaIssuePath } from "./feishu-receive-message.js";
1
2
  import { Result, Schema, SchemaIssue } from "effect";
2
- //#region src/core/application/agent-catalog/contracts/rivus-automation-template.ts
3
+ //#region src/automation/domain/automation-occurrence/errors/rivus-automation-failure.ts
3
4
  var RivusAutomationFailure = class extends Error {
4
5
  name = "RivusAutomationFailure";
5
6
  code;
@@ -10,7 +11,7 @@ var RivusAutomationFailure = class extends Error {
10
11
  }
11
12
  };
12
13
  //#endregion
13
- //#region src/core/application/automation/presentation/automation-presentation-validation.ts
14
+ //#region src/automation/domain/presentation/adapters/automation-presentation-validation.ts
14
15
  var InvalidAutomationPresentation = class extends Error {
15
16
  name = "InvalidAutomationPresentation";
16
17
  };
@@ -18,13 +19,10 @@ function decodePresentationValue(schema, value, path) {
18
19
  const result = Schema.decodeUnknownResult(schema, { onExcessProperty: "error" })(value);
19
20
  if (Result.isSuccess(result)) return result.success;
20
21
  const issue = SchemaIssue.makeFormatterStandardSchemaV1()(result.failure.issue).issues[0];
21
- throw new InvalidAutomationPresentation(`Automation presentation ${(path + (issue.path ?? []).map((segment) => {
22
- const key = typeof segment === "object" ? segment.key : segment;
23
- return typeof key === "number" ? `[${key}]` : `.${String(key)}`;
24
- }).join("")).replace(/^\./, "") || "value"}: ${issue.message}`);
22
+ throw new InvalidAutomationPresentation(`Automation presentation ${(path + formatSchemaIssuePath(issue)).replace(/^\./, "") || "value"}: ${issue.message}`);
25
23
  }
26
24
  //#endregion
27
- //#region src/core/application/automation/presentation/automation-line-chart.ts
25
+ //#region src/automation/domain/presentation/adapters/automation-line-chart.ts
28
26
  const lineChartSchema = Schema.Struct({
29
27
  title: Schema.String,
30
28
  labels: Schema.Array(Schema.String),
@@ -148,10 +146,56 @@ const presentationSchema = Schema.Struct({
148
146
  }))
149
147
  }))
150
148
  });
151
- const hasCurrentSchemaVersion = Schema.is(Schema.Struct({ schemaVersion: Schema.Literal(2) }));
152
- function readAutomationPresentation(value) {
153
- if (!hasCurrentSchemaVersion(value)) throw new InvalidAutomationPresentation(`Automation presentation schemaVersion must be 2`);
154
- return normalizePresentation(decodePresentationValue(presentationSchema, value, ""));
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
+ }
155
199
  }
156
200
  function normalizePresentation(input) {
157
201
  const title = requiredText(input.title, "title", 120);
@@ -210,55 +254,9 @@ function normalizePresentation(input) {
210
254
  ...input.trendColors === void 0 ? {} : { trendColors: input.trendColors }
211
255
  });
212
256
  }
213
- function normalizeTable(table, path, trendColors) {
214
- if (table.columns.length < 1 || table.columns.length > 6) throw new InvalidAutomationPresentation(`Automation presentation ${path}.columns requires 1 to 6 columns`);
215
- const columns = table.columns.map((column, index) => {
216
- 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`);
217
- return Object.freeze({
218
- label: requiredText(column.label, `${path}.columns[${index}].label`, 40),
219
- ...column.align === void 0 ? {} : { align: column.align },
220
- ...column.width === void 0 ? {} : { width: column.width }
221
- });
222
- });
223
- const widths = columns.filter((column) => column.width !== void 0);
224
- if (widths.length !== 0 && widths.length !== columns.length) throw new InvalidAutomationPresentation(`Automation presentation ${path}.columns must all specify width or all omit it`);
225
- if (widths.reduce((sum, column) => sum + column.width, 0) > 100) throw new InvalidAutomationPresentation(`Automation presentation ${path}.columns width total exceeds 100`);
226
- if (table.rows.length < 1 || table.rows.length > 20) throw new InvalidAutomationPresentation(`Automation presentation ${path}.rows requires 1 to 20 rows`);
227
- const rows = table.rows.map((row, rowIndex) => {
228
- const rowPath = `${path}.rows[${rowIndex}]`;
229
- if (row.length !== columns.length) throw new InvalidAutomationPresentation(`Automation presentation ${rowPath} must contain ${columns.length} cells`);
230
- return Object.freeze(row.map((cell, cellIndex) => {
231
- if (cell.trend !== void 0 && trendColors === void 0) throw new InvalidAutomationPresentation(`Automation presentation ${rowPath}[${cellIndex}].trend requires trendColors`);
232
- return Object.freeze({
233
- text: requiredText(cell.text, `${rowPath}[${cellIndex}].text`, 80),
234
- ...cell.trend === void 0 ? {} : { trend: cell.trend }
235
- });
236
- }));
237
- });
238
- return Object.freeze({
239
- columns: Object.freeze(columns),
240
- rows: Object.freeze(rows)
241
- });
242
- }
243
- function requiredText(value, path, maxLength) {
244
- const normalized = value.trim();
245
- if (!normalized) throw new InvalidAutomationPresentation(`Automation presentation ${path} is empty`);
246
- if (normalized.length > maxLength) throw new InvalidAutomationPresentation(`Automation presentation ${path} exceeds ${maxLength} characters`);
247
- return normalized;
248
- }
249
- function requiredIdentifier(value, path) {
250
- const normalized = requiredText(value, path, 80);
251
- if (!/^[a-z0-9][a-z0-9._-]*$/i.test(normalized)) throw new InvalidAutomationPresentation(`Automation presentation ${path} is not a stable identifier`);
252
- return normalized;
253
- }
254
- function safeHttpUrl(value, path) {
255
- try {
256
- const parsed = new URL(value);
257
- if (parsed.protocol !== "https:" && parsed.protocol !== "http:") throw new Error("unsupported protocol");
258
- return parsed.toString();
259
- } catch {
260
- throw new InvalidAutomationPresentation(`Automation presentation ${path} must be an HTTP(S) URL`);
261
- }
257
+ function readAutomationPresentation(value) {
258
+ if (!hasCurrentSchemaVersion(value)) throw new InvalidAutomationPresentation(`Automation presentation schemaVersion must be 2`);
259
+ return normalizePresentation(decodePresentationValue(presentationSchema, value, ""));
262
260
  }
263
261
  //#endregion
264
262
  export { RivusAutomationFailure as n, readAutomationPresentation as t };
@@ -0,0 +1,113 @@
1
+ import { Result, Schema, SchemaIssue } from "effect";
2
+ //#region src/lib/schema-issue-path.ts
3
+ /**
4
+ * Format an issue path with the repository's existing semantics: a dotted key, or an indexed bracket for a numeric
5
+ * segment. This is the path formatter shared by Feishu entry diagnostics and Automation presentation validation; it
6
+ * intentionally does not use Effect's internal `Formatter.formatPath`, which wraps every segment in brackets and would
7
+ * change the original error texts.
8
+ */
9
+ function formatSchemaIssuePath(issue) {
10
+ return (issue.path ?? []).map((segment) => {
11
+ const key = typeof segment === "object" ? segment.key : segment;
12
+ return typeof key === "number" ? `[${key}]` : `.${String(key)}`;
13
+ }).join("");
14
+ }
15
+ //#endregion
16
+ //#region src/feishu/domain/message/adapters/feishu-receive-message.ts
17
+ /** Match the durable codec's non-blank check without changing the stored identifier text. */
18
+ const filledText = Schema.String.check(Schema.makeFilter((value) => value.trim().length > 0));
19
+ const storedMessageFields = {
20
+ chat_id: filledText,
21
+ content: Schema.String,
22
+ message_id: filledText,
23
+ message_type: filledText
24
+ };
25
+ /** The four fields a stored inbound-delivery payload must have; the storage accept set is fixed and shares this. */
26
+ const storedFeishuReceiveMessageSchema = Schema.Struct({ event: Schema.Struct({ message: Schema.Struct(storedMessageFields) }) });
27
+ /**
28
+ * Tolerance: a declared field that is present but has the wrong type (including `null`) rejects the whole payload;
29
+ * undeclared wire fields stay on the returned object and are never read. The required message fields are non-blank
30
+ * because the durable inbound-delivery codec accepts only non-blank ids.
31
+ */
32
+ const messageFields = {
33
+ ...storedMessageFields,
34
+ chat_type: Schema.optional(Schema.String),
35
+ create_time: Schema.optional(Schema.String),
36
+ mentions: Schema.optional(Schema.Array(Schema.Struct({
37
+ id: Schema.optional(Schema.Record(Schema.String, Schema.String)),
38
+ key: Schema.optional(Schema.String),
39
+ name: Schema.optional(Schema.String)
40
+ }))),
41
+ parent_id: Schema.optional(Schema.String),
42
+ root_id: Schema.optional(Schema.String),
43
+ thread_id: Schema.optional(Schema.String)
44
+ };
45
+ const wireMessageSchema = Schema.Struct(messageFields);
46
+ const senderSchema = Schema.Struct({
47
+ sender_id: Schema.optional(Schema.Struct({ open_id: Schema.optional(Schema.String) })),
48
+ sender_type: Schema.optional(Schema.String),
49
+ tenant_key: Schema.optional(Schema.String)
50
+ });
51
+ /** The Lark event envelope: `header`/`event` wrapping the message. */
52
+ const envelopeWireSchema = Schema.Struct({
53
+ header: Schema.optional(Schema.Struct({ tenant_key: Schema.optional(Schema.String) })),
54
+ event: Schema.Struct({
55
+ message: wireMessageSchema,
56
+ sender: Schema.optional(senderSchema)
57
+ })
58
+ });
59
+ /** The SDK dispatcher's flat shape: `tenant_key`, `message` and `sender` at the payload root. A payload that
60
+ * carries an `event` key is never a flat shape, even when that value is `undefined`; it is decoded as an envelope
61
+ * or refused by the shared union. */
62
+ const sdkFlatWireSchema = Schema.Struct({
63
+ message: wireMessageSchema,
64
+ sender: Schema.optional(senderSchema),
65
+ tenant_key: Schema.optional(Schema.String),
66
+ event: Schema.optionalKey(Schema.Never)
67
+ });
68
+ const wireSchema = Schema.Union([envelopeWireSchema, sdkFlatWireSchema]);
69
+ var UndecodableFeishuReceiveMessage = class extends Error {
70
+ reason;
71
+ name = "UndecodableFeishuReceiveMessage";
72
+ _tag = "UndecodableFeishuReceiveMessage";
73
+ constructor(reason) {
74
+ super(reason);
75
+ this.reason = reason;
76
+ }
77
+ };
78
+ function describeIssue(issue) {
79
+ const formatted = SchemaIssue.makeFormatterStandardSchemaV1()(issue).issues[0];
80
+ if (formatted === void 0) return "Feishu receive-message payload does not match the envelope or SDK-flat wire shape";
81
+ return `Feishu receive-message payload${formatSchemaIssuePath(formatted) || " value"}: ${formatted.message}`;
82
+ }
83
+ /**
84
+ * Decode the inbound message event once. The Lark dispatcher hands over the envelope or its flat SDK shape; one
85
+ * union Schema validates both, and the decoded branch decides how the value is returned:
86
+ *
87
+ * - envelope: the original payload object, so unknown wire fields survive the durable store round-trip;
88
+ * - flat: `{ header?, event: { message, sender? } }` built from the original nested objects, with the tenant key
89
+ * moved to `header` and the remaining root wire fields dropped as the previous normalizer did.
90
+ *
91
+ * The failure reason names the field path and expected type only; it never echoes a field value.
92
+ */
93
+ function decodeFeishuReceiveMessage(raw) {
94
+ const decoded = Schema.decodeUnknownResult(wireSchema)(raw);
95
+ if (Result.isFailure(decoded)) throw new UndecodableFeishuReceiveMessage(describeIssue(decoded.failure.issue));
96
+ if (!("message" in decoded.success)) return raw;
97
+ const flat = raw;
98
+ return {
99
+ ...flat.tenant_key ? { header: { tenant_key: flat.tenant_key } } : {},
100
+ event: {
101
+ message: flat.message,
102
+ ...flat.sender ? { sender: flat.sender } : {}
103
+ }
104
+ };
105
+ }
106
+ /** The tenant key is resolved at read time, sender first. Decoding only moves a flat shape's root `tenant_key`
107
+ * into `header`; it does not resolve or merge the two carriers. */
108
+ function readTenantKey(payload) {
109
+ return payload.event.sender?.tenant_key ?? payload.header?.tenant_key ?? "";
110
+ }
111
+ //#endregion
112
+ export { formatSchemaIssuePath as i, readTenantKey as n, storedFeishuReceiveMessageSchema as r, decodeFeishuReceiveMessage as t };
113
+