@rivus/gateway 0.19.0 → 0.20.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 +12 -7
- package/dist/bootstrap/feishu.d.ts +13 -0
- package/dist/bootstrap/{pi-feishu.js → feishu.js} +16038 -15746
- package/dist/chunks/automation-presentation.js +265 -0
- package/dist/chunks/herdr-feishu-runtime.js +1 -1
- package/dist/chunks/{rivus-daemon-cli.d.ts → rivus-deployment-cli-process.d.ts} +136 -355
- package/dist/chunks/rivus-home-deployment-env.js +958 -91
- package/dist/chunks/rivus-node-entrypoint.js +377 -1148
- package/dist/index.d.ts +27 -3
- package/dist/index.js +2 -1
- package/dist/mcp.d.ts +11 -15
- package/dist/mcp.js +64 -86
- package/package.json +9 -8
- package/templates/{pi-feishu-deployment.bootstrap.ts → feishu-deployment.bootstrap.ts} +1 -1
- package/dist/bootstrap/pi-feishu.d.ts +0 -285
- package/dist/chunks/background-session-authority.js +0 -194
- package/templates/pi-feishu.bootstrap.ts +0 -1
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { Result, Schema, SchemaIssue } from "effect";
|
|
2
|
+
//#region src/core/application/agent-catalog/contracts/rivus-automation-template.ts
|
|
3
|
+
var RivusAutomationFailure = class extends Error {
|
|
4
|
+
name = "RivusAutomationFailure";
|
|
5
|
+
code;
|
|
6
|
+
constructor(code, message = code, options) {
|
|
7
|
+
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}$");
|
|
8
|
+
super(message, options);
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/core/application/automation/presentation/automation-presentation-validation.ts
|
|
14
|
+
var InvalidAutomationPresentation = class extends Error {
|
|
15
|
+
name = "InvalidAutomationPresentation";
|
|
16
|
+
};
|
|
17
|
+
function decodePresentationValue(schema, value, path) {
|
|
18
|
+
const result = Schema.decodeUnknownResult(schema, { onExcessProperty: "error" })(value);
|
|
19
|
+
if (Result.isSuccess(result)) return result.success;
|
|
20
|
+
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}`);
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/core/application/automation/presentation/automation-line-chart.ts
|
|
28
|
+
const lineChartSchema = Schema.Struct({
|
|
29
|
+
title: Schema.String,
|
|
30
|
+
labels: Schema.Array(Schema.String),
|
|
31
|
+
unit: Schema.String,
|
|
32
|
+
seriesLayout: Schema.optional(Schema.Literals(["overlay", "separate"])),
|
|
33
|
+
series: Schema.Array(Schema.Struct({
|
|
34
|
+
name: Schema.String,
|
|
35
|
+
values: Schema.Array(Schema.Number)
|
|
36
|
+
}))
|
|
37
|
+
});
|
|
38
|
+
function readAutomationLineChart(value, path = "lineChart") {
|
|
39
|
+
const chart = decodePresentationValue(lineChartSchema, value, path);
|
|
40
|
+
const text = (value, path, limit) => {
|
|
41
|
+
const normalized = value.trim();
|
|
42
|
+
if (!normalized || normalized.length > limit) throw new InvalidAutomationPresentation(`Automation presentation ${path} must contain 1 to ${limit} characters`);
|
|
43
|
+
return normalized;
|
|
44
|
+
};
|
|
45
|
+
if (chart.labels.length < 2 || chart.labels.length > 60) throw new InvalidAutomationPresentation(`Automation presentation ${path}.labels requires 2 to 60 labels`);
|
|
46
|
+
const labels = Array.from(chart.labels, (label, index) => text(label, `${path}.labels[${index}]`, 64));
|
|
47
|
+
if (new Set(labels).size !== labels.length) throw new InvalidAutomationPresentation(`Automation presentation ${path}.labels must be unique`);
|
|
48
|
+
if (chart.series.length < 1 || chart.series.length > 6) throw new InvalidAutomationPresentation(`Automation presentation ${path}.series requires 1 to 6 series`);
|
|
49
|
+
const series = Array.from(chart.series, (row, seriesIndex) => {
|
|
50
|
+
const rowPath = `${path}.series[${seriesIndex}]`;
|
|
51
|
+
if (row.values.length !== labels.length) throw new InvalidAutomationPresentation(`Automation presentation ${rowPath}.values must align with every label`);
|
|
52
|
+
const values = Array.from(row.values, (value, valueIndex) => {
|
|
53
|
+
if (!Number.isFinite(value)) throw new InvalidAutomationPresentation(`Automation presentation ${rowPath}.values[${valueIndex}] must be a finite number`);
|
|
54
|
+
return value;
|
|
55
|
+
});
|
|
56
|
+
return Object.freeze({
|
|
57
|
+
name: text(row.name, `${rowPath}.name`, 80),
|
|
58
|
+
values: Object.freeze(values)
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
if (new Set(series.map(({ name }) => name)).size !== series.length) throw new InvalidAutomationPresentation(`Automation presentation ${path}.series names must be unique`);
|
|
62
|
+
return Object.freeze({
|
|
63
|
+
title: text(chart.title, `${path}.title`, 120),
|
|
64
|
+
labels: Object.freeze(labels),
|
|
65
|
+
unit: text(chart.unit, `${path}.unit`, 80),
|
|
66
|
+
...chart.seriesLayout === void 0 ? {} : { seriesLayout: chart.seriesLayout },
|
|
67
|
+
series: Object.freeze(series)
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const sourceSchema = Schema.Struct({
|
|
71
|
+
label: Schema.String,
|
|
72
|
+
url: Schema.String
|
|
73
|
+
});
|
|
74
|
+
const itemFields = {
|
|
75
|
+
emphasis: Schema.optional(Schema.Literal("accent")),
|
|
76
|
+
headline: Schema.String,
|
|
77
|
+
note: Schema.optional(Schema.String)
|
|
78
|
+
};
|
|
79
|
+
const sectionFields = {
|
|
80
|
+
collapsed: Schema.optional(Schema.Boolean),
|
|
81
|
+
id: Schema.String,
|
|
82
|
+
lineChart: Schema.optional(Schema.Unknown),
|
|
83
|
+
listStyle: Schema.optional(Schema.Literals([
|
|
84
|
+
"bullet",
|
|
85
|
+
"numbered",
|
|
86
|
+
"plain"
|
|
87
|
+
])),
|
|
88
|
+
style: Schema.optional(Schema.Literals(["plain", "highlight"])),
|
|
89
|
+
table: Schema.optional(Schema.Struct({
|
|
90
|
+
columns: Schema.Array(Schema.Struct({
|
|
91
|
+
label: Schema.String,
|
|
92
|
+
align: Schema.optional(Schema.Literals([
|
|
93
|
+
"left",
|
|
94
|
+
"center",
|
|
95
|
+
"right"
|
|
96
|
+
])),
|
|
97
|
+
width: Schema.optional(Schema.Number)
|
|
98
|
+
})),
|
|
99
|
+
rows: Schema.Array(Schema.Array(Schema.Struct({
|
|
100
|
+
text: Schema.String,
|
|
101
|
+
trend: Schema.optional(Schema.Literals([
|
|
102
|
+
"up",
|
|
103
|
+
"down",
|
|
104
|
+
"flat"
|
|
105
|
+
]))
|
|
106
|
+
})))
|
|
107
|
+
})),
|
|
108
|
+
title: Schema.String
|
|
109
|
+
};
|
|
110
|
+
const presentationFields = {
|
|
111
|
+
footer: Schema.optional(Schema.String),
|
|
112
|
+
footnote: Schema.optional(Schema.String),
|
|
113
|
+
kind: Schema.optional(Schema.Literals([
|
|
114
|
+
"daily-ai",
|
|
115
|
+
"generic",
|
|
116
|
+
"industry",
|
|
117
|
+
"news",
|
|
118
|
+
"subscriptions"
|
|
119
|
+
])),
|
|
120
|
+
lineChart: Schema.optional(Schema.Unknown),
|
|
121
|
+
sectionDividers: Schema.optional(Schema.Boolean),
|
|
122
|
+
subtitle: Schema.optional(Schema.String),
|
|
123
|
+
summary: Schema.optional(Schema.String),
|
|
124
|
+
summaryStyle: Schema.optional(Schema.Literals(["plain", "highlight"])),
|
|
125
|
+
title: Schema.String,
|
|
126
|
+
trendColors: Schema.optional(Schema.Literals(["red-up", "green-up"]))
|
|
127
|
+
};
|
|
128
|
+
Schema.Struct({
|
|
129
|
+
...presentationFields,
|
|
130
|
+
meta: Schema.optional(Schema.Array(Schema.String)),
|
|
131
|
+
sections: Schema.Array(Schema.Struct({
|
|
132
|
+
...sectionFields,
|
|
133
|
+
items: Schema.Array(Schema.Struct({
|
|
134
|
+
...itemFields,
|
|
135
|
+
sources: Schema.optional(Schema.Array(sourceSchema))
|
|
136
|
+
}))
|
|
137
|
+
}))
|
|
138
|
+
});
|
|
139
|
+
const presentationSchema = Schema.Struct({
|
|
140
|
+
...presentationFields,
|
|
141
|
+
meta: Schema.Array(Schema.String),
|
|
142
|
+
schemaVersion: Schema.Literal(2),
|
|
143
|
+
sections: Schema.Array(Schema.Struct({
|
|
144
|
+
...sectionFields,
|
|
145
|
+
items: Schema.Array(Schema.Struct({
|
|
146
|
+
...itemFields,
|
|
147
|
+
sources: Schema.Array(sourceSchema)
|
|
148
|
+
}))
|
|
149
|
+
}))
|
|
150
|
+
});
|
|
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, ""));
|
|
155
|
+
}
|
|
156
|
+
function normalizePresentation(input) {
|
|
157
|
+
const title = requiredText(input.title, "title", 120);
|
|
158
|
+
const meta = (input.meta ?? []).map((value, index) => requiredText(value, `meta[${index}]`, 80));
|
|
159
|
+
if (meta.length > 6) throw new InvalidAutomationPresentation("Automation presentation meta exceeds 6 items");
|
|
160
|
+
if (input.sections.length > 12) throw new InvalidAutomationPresentation("Automation presentation sections exceeds 12 sections");
|
|
161
|
+
if (input.summaryStyle === "highlight" && !input.summary?.trim()) throw new InvalidAutomationPresentation("Automation presentation summaryStyle highlight requires summary");
|
|
162
|
+
let chartCount = input.lineChart === void 0 ? 0 : 1;
|
|
163
|
+
let tableCount = 0;
|
|
164
|
+
const sections = input.sections.map((section, sectionIndex) => {
|
|
165
|
+
const path = `sections[${sectionIndex}]`;
|
|
166
|
+
const id = requiredIdentifier(section.id, `${path}.id`);
|
|
167
|
+
const sectionTitle = requiredText(section.title, `${path}.title`, 80);
|
|
168
|
+
if (section.items.length > 40) throw new InvalidAutomationPresentation(`Automation presentation ${path}.items exceeds 40 items`);
|
|
169
|
+
if (section.collapsed && section.style === "highlight") throw new InvalidAutomationPresentation(`Automation presentation ${path}.collapsed cannot use style highlight`);
|
|
170
|
+
if (section.lineChart !== void 0 && ++chartCount > 1) throw new InvalidAutomationPresentation(`Automation presentation ${path}.lineChart exceeds one lineChart`);
|
|
171
|
+
if (section.table !== void 0) {
|
|
172
|
+
if (section.collapsed || section.style === "highlight") throw new InvalidAutomationPresentation(`Automation presentation ${path}.table requires a plain, expanded section`);
|
|
173
|
+
if (++tableCount > 5) throw new InvalidAutomationPresentation(`Automation presentation ${path}.table exceeds 5 tables`);
|
|
174
|
+
}
|
|
175
|
+
return Object.freeze({
|
|
176
|
+
...section.collapsed === void 0 ? {} : { collapsed: section.collapsed },
|
|
177
|
+
id,
|
|
178
|
+
items: Object.freeze(section.items.map((item, itemIndex) => {
|
|
179
|
+
const itemPath = `${path}.items[${itemIndex}]`;
|
|
180
|
+
return Object.freeze({
|
|
181
|
+
...item.emphasis === void 0 ? {} : { emphasis: item.emphasis },
|
|
182
|
+
headline: requiredText(item.headline, `${itemPath}.headline`, 240),
|
|
183
|
+
...item.note ? { note: requiredText(item.note, `${itemPath}.note`, 400) } : {},
|
|
184
|
+
sources: Object.freeze((item.sources ?? []).map((source, sourceIndex) => Object.freeze({
|
|
185
|
+
label: requiredText(source.label, `${itemPath}.sources[${sourceIndex}].label`, 60),
|
|
186
|
+
url: safeHttpUrl(source.url, `${itemPath}.sources[${sourceIndex}].url`)
|
|
187
|
+
})))
|
|
188
|
+
});
|
|
189
|
+
})),
|
|
190
|
+
...section.lineChart === void 0 ? {} : { lineChart: readAutomationLineChart(section.lineChart, `${path}.lineChart`) },
|
|
191
|
+
...section.listStyle === void 0 ? {} : { listStyle: section.listStyle },
|
|
192
|
+
...section.style === void 0 ? {} : { style: section.style },
|
|
193
|
+
...section.table === void 0 ? {} : { table: normalizeTable(section.table, `${path}.table`, input.trendColors) },
|
|
194
|
+
title: sectionTitle
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
return Object.freeze({
|
|
198
|
+
...input.footer === void 0 ? {} : { footer: requiredText(input.footer, "footer", 120) },
|
|
199
|
+
...input.lineChart === void 0 ? {} : { lineChart: readAutomationLineChart(input.lineChart) },
|
|
200
|
+
...input.footnote ? { footnote: requiredText(input.footnote, "footnote", 240) } : {},
|
|
201
|
+
...input.kind === void 0 ? {} : { kind: input.kind },
|
|
202
|
+
meta: Object.freeze(meta),
|
|
203
|
+
schemaVersion: 2,
|
|
204
|
+
...input.sectionDividers === void 0 ? {} : { sectionDividers: input.sectionDividers },
|
|
205
|
+
sections: Object.freeze(sections),
|
|
206
|
+
...input.subtitle === void 0 ? {} : { subtitle: requiredText(input.subtitle, "subtitle", 120) },
|
|
207
|
+
...input.summary ? { summary: requiredText(input.summary, "summary", 800) } : {},
|
|
208
|
+
...input.summaryStyle === void 0 ? {} : { summaryStyle: input.summaryStyle },
|
|
209
|
+
title,
|
|
210
|
+
...input.trendColors === void 0 ? {} : { trendColors: input.trendColors }
|
|
211
|
+
});
|
|
212
|
+
}
|
|
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
|
+
}
|
|
262
|
+
}
|
|
263
|
+
//#endregion
|
|
264
|
+
export { RivusAutomationFailure as n, readAutomationPresentation as t };
|
|
265
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isAbsolute, join, resolve } from "node:path";
|
|
2
1
|
import { Array as Array$1, Effect, Fiber, Result, Schema, Semaphore } from "effect";
|
|
2
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
3
3
|
import { chmod, lstat, mkdir, open, readFile, readdir, unlink } from "node:fs/promises";
|
|
4
4
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
5
5
|
import { writeAtomicTextFile } from "@rivus/platform/persistence";
|