@rivus/gateway 0.23.0 → 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.
@@ -119,7 +119,7 @@ const superagentWorkerTools = [
119
119
  },
120
120
  {
121
121
  name: "task_report",
122
- description: "Report progress, a question, or completion for this assignment",
122
+ description: "Report progress, a question, or completion for this assignment. List the URLs of what you published, such as a pull request you opened, in links.",
123
123
  properties: {
124
124
  id: { type: "string" },
125
125
  state: { enum: [
@@ -143,7 +143,14 @@ const superagentWorkerTools = [
143
143
  },
144
144
  question: { type: "string" },
145
145
  replyTo: { type: "string" },
146
- pullRequest: { type: "string" }
146
+ file: {
147
+ type: "string",
148
+ description: "Requested file relative to the task workspace; use with state ready and replyTo."
149
+ },
150
+ links: {
151
+ type: "array",
152
+ items: { type: "string" }
153
+ }
147
154
  },
148
155
  required: [
149
156
  "id",
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as readAutomationPresentation } from "./chunks/rivus-audio-process.js";
1
+ import { X as readAutomationPresentation } from "./chunks/superagent-worker-programs.js";
2
2
  import { i as RIVUS_PLUGIN_API_VERSION, n as createRivusPluginCatalog, r as resolveRivusAgentDefinition, t as runRivusNodeEntrypoint } from "./chunks/rivus-node-entrypoint.js";
3
3
  import { t as RivusAutomationFailure } from "./chunks/errors.js";
4
4
  export { RIVUS_PLUGIN_API_VERSION, RivusAutomationFailure, createRivusPluginCatalog, readAutomationPresentation, resolveRivusAgentDefinition, runRivusNodeEntrypoint };
@@ -1,16 +1,12 @@
1
1
  import { Schema } from "effect";
2
- //#region ../superagent/dist/chunks/spi.d.ts
2
+ //#region ../superagent/dist/chunks/scenario.d.ts
3
3
  //#region src/work/domain/audience/audience.d.ts
4
4
  type Audience = "public" | "internal" | `private:${string}:${string}` | `group:${string}:${string}`;
5
- /** The code host's variables and Git configuration for one Task's worker. */
6
- interface WorkerEnvironment {
7
- readonly variables: Readonly<Record<string, string>>;
8
- readonly gitConfig?: ReadonlyArray<readonly [key: string, value: string]>;
9
- }
10
5
  //#endregion
11
6
  //#region src/work/domain/trigger/adapters/input.d.ts
12
7
  declare const triggerInput: Schema.Struct<{
13
8
  readonly sourceEventId: Schema.NonEmptyString;
9
+ readonly inReplyTo: Schema.optionalKey<Schema.NonEmptyString>;
14
10
  readonly kind: Schema.Literals<readonly ["message", "comment", "review", "ci", "thread_closed", "thread_open", "timer", "edit", "delete"]>;
15
11
  readonly threads: Schema.NonEmptyArray<Schema.NonEmptyString>;
16
12
  readonly actor: Schema.Struct<{
@@ -40,7 +36,7 @@ type MessageChangeInput = typeof messageChange.Encoded;
40
36
  /** The language of the fixed texts the host writes to a source; a source declares it, English by default. */
41
37
  type ReplyLocale = "en" | "zh";
42
38
  //#endregion
43
- //#region src/source/domain/reply/delivery.d.ts
39
+ //#region src/work/domain/reply/delivery.d.ts
44
40
  /** What a source reports after one send attempt. */
45
41
  type SendResult = {
46
42
  readonly status: "sent";
@@ -50,7 +46,7 @@ type SendResult = {
50
46
  readonly reason: string;
51
47
  };
52
48
  //#endregion
53
- //#region src/source/application/spi.d.ts
49
+ //#region src/work/application/spi/source.d.ts
54
50
  interface ReplyRequest {
55
51
  readonly id: string;
56
52
  readonly generation: number;
@@ -59,6 +55,8 @@ interface ReplyRequest {
59
55
  readonly audience: Audience;
60
56
  readonly target: Readonly<Record<string, string>>;
61
57
  readonly text: string;
58
+ /** The key returned by this source's upload for a native file message. */
59
+ readonly fileKey?: string;
62
60
  }
63
61
  interface SourceHealth {
64
62
  readonly state: "ready" | "degraded" | "failed";
@@ -74,43 +72,24 @@ interface SourceHost {
74
72
  /** The secret a configuration reference names, or `undefined` when it is not set; throws on a malformed reference. */
75
73
  secret(this: void, ref: string): string | undefined;
76
74
  }
77
- /**
78
- * The repository host behind a source: the account that opens the pull requests of Tasks. Superagent accepts at most
79
- * one. Pull requests themselves are a Superagent concept; the code host verifies and binds them.
80
- */
81
- interface CodeHost {
82
- /** The repositories this host serves; each must also be a configured Superagent repository. */
83
- readonly repositories: readonly string[];
84
- /** The repository a native thread of this source belongs to, such as `owner/name`. */
85
- repository(this: void, thread: string): string | undefined;
86
- /** Binds the pull request a worker reported; `false` when it cannot be verified now. */
87
- claimPullRequest(this: void, taskId: string, branch: string, url: string): Promise<boolean>;
88
- /** Finds and binds the Task's own pull requests for its branch in the Task's repository. */
89
- discoverPullRequest(this: void, taskId: string, branch: string, repository: string): Promise<boolean>;
90
- /** The credential a worker's Git or CLI request receives for `repo`, or `undefined` to refuse it. */
91
- credential(this: void, repo: string | undefined): {
92
- readonly username: string;
93
- readonly token: string;
94
- } | undefined;
95
- /** Variables and Git settings for a Task's worker; `undefined` until the source has verified its account. */
96
- environment(this: void, task: {
97
- readonly id: string;
98
- readonly branch: string;
99
- }): WorkerEnvironment | undefined;
100
- }
101
75
  interface SuperagentSource {
102
76
  prepare?(signal: AbortSignal): Promise<void>;
103
77
  start(signal: AbortSignal): Promise<void>;
104
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
+ };
105
84
  readThread?(thread: string, cursor?: string, signal?: AbortSignal): Promise<ThreadPage>;
106
85
  /**
107
- * How replies to this source are written. A `messaging` source is where people chat with the bot, so it also
108
- * receives the notice when all of a Task's pull requests close; `maxWords`, `maxCharacters` (UTF-16 code units,
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,
109
88
  * prefix included) and `prefix` apply to every reply.
110
89
  * `locale` is the language of the host's fixed notices there, English by default.
111
90
  */
112
91
  readonly reply?: {
113
- readonly messaging?: boolean;
92
+ readonly conversational?: boolean;
114
93
  readonly maxWords?: number;
115
94
  readonly maxCharacters?: number;
116
95
  readonly prefix?: string;
@@ -129,7 +108,6 @@ interface SuperagentSource {
129
108
  readonly label?: string;
130
109
  readonly url?: string;
131
110
  };
132
- readonly codeHost?: CodeHost;
133
111
  }
134
112
  interface SourceState {
135
113
  get<T, Encoded>(key: string, schema: Schema.Codec<T, Encoded>): Promise<T | undefined>;
@@ -143,13 +121,12 @@ interface SuperagentSourceContext<Config> {
143
121
  readonly filtered?: string;
144
122
  }): Promise<"stored" | "duplicate" | "filtered">;
145
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;
146
126
  isSubscribed(thread: string): boolean;
147
127
  polledThreads(): Promise<readonly string[]>;
148
128
  /** Durable source state. A missing key reads as `undefined`; a value of another shape fails naming its key. */
149
129
  readonly state: SourceState;
150
- openTaskForBranch?(branch: string): string | undefined;
151
- bindOwnedThreads?(taskId: string, threads: readonly string[]): Promise<void>;
152
- bindThread(taskId: string, thread: string, own: boolean): Promise<void>;
153
130
  report(health: SourceHealth): void;
154
131
  }
155
132
  /**
@@ -178,17 +155,147 @@ interface SuperagentSourceKind<Config = unknown> {
178
155
  * source's `allowedActors`; anyone else's event arrives as the unaddressed event it is.
179
156
  */
180
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;
181
168
  create(this: void, context: SuperagentSourceContext<Config>): SuperagentSource;
182
169
  }
183
170
  /**
184
- * A named set of source kinds that a deployment loads. Kind names must be unique across the presets a deployment
185
- * names; the trigger kinds a source emits stay Superagent's fixed set.
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.
186
173
  */
187
174
  interface SuperagentSourcePreset {
188
175
  /** A readable name for error messages, such as `builtin` or the package name. */
189
176
  readonly id: string;
190
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;
191
298
  }
192
299
  //#endregion
193
- export type { CodeHost, MessageChangeInput, ReplyRequest, SendResult, SourceHost, SuperagentSource, SuperagentSourceContext, SuperagentSourceKind, SuperagentSourcePreset, TriggerInput, WorkerEnvironment };
300
+ export type { MessageChangeInput, ReplyRequest, Scenario, ScenarioContext, ScenarioReport, ScenarioTask, SendResult, SourceHost, SuperagentScenarioKind, SuperagentSource, SuperagentSourceContext, SuperagentSourceKind, SuperagentSourcePreset, TriggerInput, WorkerEnvironment };
194
301
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivus/gateway",
3
- "version": "0.23.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": [
@@ -63,37 +63,39 @@
63
63
  "LICENSE"
64
64
  ],
65
65
  "dependencies": {
66
- "@agentclientprotocol/sdk": "1.5.1",
66
+ "@agentclientprotocol/sdk": "1.9.0",
67
67
  "@earendil-works/chord": "1.5.2",
68
68
  "@earendil-works/pi-ai": "1.5.2",
69
69
  "@earendil-works/pi-coding-agent": "1.5.2",
70
70
  "@earendil-works/pi-durable": "1.5.2",
71
71
  "@earendil-works/pi-schema": "1.5.2",
72
- "@larksuiteoapi/node-sdk": "1.74.0",
72
+ "@larksuiteoapi/node-sdk": "1.76.0",
73
73
  "@resvg/resvg-js": "2.6.2",
74
74
  "@rivus/agent-kit": "0.25.0",
75
75
  "@rivus/agent-kit-collab": "0.25.0",
76
- "@rivus/platform": "0.23.0",
77
- "@rivus/runtime": "0.23.0",
78
- "axios": "1.20.0",
76
+ "@rivus/platform": "0.24.0",
77
+ "@rivus/runtime": "0.24.0",
78
+ "axios": "1.21.1",
79
79
  "effect": "4.1.1",
80
80
  "get-east-asian-width": "1.7.0",
81
- "marked": "18.1.3",
82
- "semver": "7.8.5",
81
+ "marked": "18.2.0",
82
+ "semver": "7.8.6",
83
83
  "yaml": "2.9.1"
84
84
  },
85
85
  "publishConfig": {
86
86
  "access": "public"
87
87
  },
88
88
  "devDependencies": {
89
- "@rivus/source-github": "0.21.2",
89
+ "@rivus/scenario-coding": "0.21.2",
90
90
  "@rivus/superagent": "0.21.2",
91
+ "@rivus/trigger-github": "0.21.2",
92
+ "@rivus/trigger-wechat": "0.21.2",
91
93
  "@rivus/utils": "0.21.2",
92
94
  "@types/node": "24.19.2",
93
95
  "@types/semver": "7.8.0",
94
96
  "@typescript/native": "npm:typescript@7.0.2",
95
97
  "@vitest/coverage-v8": "5.0.5",
96
- "tar": "7.5.22",
98
+ "tar": "8.0.5",
97
99
  "typescript": "6.0.3",
98
100
  "unbzip2-stream": "1.4.3",
99
101
  "vite": "npm:@voidzero-dev/vite-plus-core@1.3.0",
@@ -1,113 +0,0 @@
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/lib/message/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.Struct({ open_id: Schema.optional(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
-