@rivus/agent 0.16.2 → 0.17.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.
Files changed (55) hide show
  1. package/LICENSE +669 -17
  2. package/README.md +25 -1080
  3. package/dist/cli.d.ts +1 -1
  4. package/dist/cli.js +12 -1234
  5. package/dist/index.d.ts +3 -7
  6. package/dist/index.js +3 -8
  7. package/dist/testing/index.d.ts +21 -50
  8. package/dist/testing/index.js +58 -89
  9. package/package.json +40 -104
  10. package/dist/acp.d.ts +0 -144
  11. package/dist/acp.js +0 -768
  12. package/dist/bootstrap/pi-feishu.d.ts +0 -20
  13. package/dist/bootstrap/pi-feishu.js +0 -4341
  14. package/dist/chunks/agent-loop.d.ts +0 -446
  15. package/dist/chunks/agent-loop.js +0 -158
  16. package/dist/chunks/background-session-authority.js +0 -230
  17. package/dist/chunks/background-session-control-input.js +0 -51
  18. package/dist/chunks/background-session-service.d.ts +0 -382
  19. package/dist/chunks/index.d.ts +0 -4448
  20. package/dist/chunks/pi-tool-proxy.d.ts +0 -120
  21. package/dist/chunks/pi.js +0 -406
  22. package/dist/chunks/rivus-agent-definition-resolver.js +0 -508
  23. package/dist/chunks/rivus-daemon-cli.js +0 -3839
  24. package/dist/chunks/rivus-model-management-wire.js +0 -344
  25. package/dist/chunks/rivus-plugin-testkit.d.ts +0 -214
  26. package/dist/chunks/rivus-plugin-testkit.js +0 -78
  27. package/dist/chunks/rivus-skill.d.ts +0 -95
  28. package/dist/chunks/rivus-tool.js +0 -158
  29. package/dist/chunks/sha256-digest.js +0 -7
  30. package/dist/chunks/src.js +0 -15313
  31. package/dist/mcp.d.ts +0 -92
  32. package/dist/mcp.js +0 -454
  33. package/dist/pi.d.ts +0 -129
  34. package/dist/pi.js +0 -3
  35. package/examples/a-share-briefing-analysis.mjs +0 -93
  36. package/examples/a-share-briefing-renderer.mjs +0 -257
  37. package/examples/a-share-index-evidence.mjs +0 -99
  38. package/examples/a-share-market-briefing.mjs +0 -83
  39. package/examples/a-share-market-date.mjs +0 -10
  40. package/examples/a-share-overseas-evidence.mjs +0 -86
  41. package/examples/a-share-policy-evidence.mjs +0 -145
  42. package/examples/a-share-provider-response.mjs +0 -21
  43. package/examples/a-share-sector-evidence.mjs +0 -70
  44. package/examples/acp-stdio-proxy.mjs +0 -58
  45. package/examples/current-weather.mjs +0 -117
  46. package/examples/html-drive-tools.mjs +0 -262
  47. package/examples/https-response-reader.mjs +0 -36
  48. package/examples/langfuse-drive-e2e.mjs +0 -175
  49. package/examples/pi-feishu-deployment.bootstrap.ts +0 -894
  50. package/examples/pi-feishu.bootstrap.ts +0 -242
  51. package/examples/rivus-agents.plugin.mjs +0 -290
  52. package/examples/rivus-langfuse-demo.config.json +0 -37
  53. package/examples/rivus-starter.plugin.mjs +0 -47
  54. package/examples/rivus.config.json +0 -114
  55. package/skills/runtime-management/SKILL.md +0 -65
@@ -1,36 +0,0 @@
1
- import { get } from "node:https";
2
-
3
- export function readBoundedHttpsResponse(url, options) {
4
- return new Promise((resolve, reject) => {
5
- const request = get(
6
- url,
7
- {
8
- family: 4,
9
- headers: options.headers,
10
- signal: AbortSignal.timeout(options.timeoutMs ?? 10_000)
11
- },
12
- (response) => {
13
- const status = response.statusCode ?? 0;
14
- response.once("error", reject);
15
- if (status < 200 || status >= 300) {
16
- response.resume();
17
- resolve({ body: Buffer.alloc(0), status });
18
- return;
19
- }
20
- const chunks = [];
21
- let length = 0;
22
- response.on("data", (chunk) => {
23
- const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
24
- length += buffer.length;
25
- if (length > options.maxBytes) {
26
- request.destroy(new Error(`HTTPS response exceeds ${options.maxBytes} bytes`));
27
- return;
28
- }
29
- chunks.push(buffer);
30
- });
31
- response.once("end", () => resolve({ body: Buffer.concat(chunks), status }));
32
- }
33
- );
34
- request.once("error", reject);
35
- });
36
- }
@@ -1,175 +0,0 @@
1
- import { execFile } from "node:child_process";
2
- import { randomUUID } from "node:crypto";
3
- import { mkdtemp, readFile, rm } from "node:fs/promises";
4
- import { tmpdir } from "node:os";
5
- import { join } from "node:path";
6
- import { promisify } from "node:util";
7
-
8
- import { runLangfuseDriveE2E } from "../dist/testing/index.js";
9
-
10
- const execFileAsync = promisify(execFile);
11
- const baseUrl = requiredEnv("LANGFUSE_BASE_URL");
12
- const publicKey = requiredEnv("LANGFUSE_PUBLIC_KEY");
13
- const secretKey = requiredEnv("LANGFUSE_SECRET_KEY");
14
- const marker = `${new Date()
15
- .toISOString()
16
- .replace(/[^0-9]/g, "")
17
- .slice(0, 14)}-${randomUUID().slice(0, 8)}`;
18
- const sessionKey = `e2e:langfuse-drive:${marker}`;
19
- const expectedDriveTitle = `langfuse-e2e-${marker}.html`;
20
- const discoveredTraceIds = new Set();
21
- const deploymentStateDirectory = await mkdtemp(join(tmpdir(), "rivus-langfuse-e2e-state-"));
22
- const prompt = [
23
- "Read the granted Langfuse HTML publishing Skill.",
24
- "Create a polished, accessible, self-contained Chinese Langfuse introduction page.",
25
- `Include the visible E2E marker ${marker}, then upload it as ${expectedDriveTitle}.`,
26
- "Return the verified Feishu Drive URL."
27
- ].join(" ");
28
-
29
- const result = await runLangfuseDriveE2E({
30
- dependencies: {
31
- inspectDrive: async (url) => {
32
- const output = await command(process.env.RIVUS_LARK_CLI_PATH?.trim() || "lark-cli", [
33
- "drive",
34
- "+inspect",
35
- "--as",
36
- "user",
37
- "--url",
38
- url,
39
- "--format",
40
- "json"
41
- ]);
42
- const parsed = JSON.parse(output);
43
- return isRecord(parsed.data) ? parsed.data : parsed;
44
- },
45
- listObservations: async ({ deadlineAt, fromStartTime, sessionKey: expectedSessionKey, toStartTime }) => {
46
- if (discoveredTraceIds.size === 0) {
47
- let cursor;
48
- do {
49
- const endpoint = new URL("/api/public/v2/observations", baseUrl);
50
- endpoint.searchParams.set("fields", "core,basic");
51
- endpoint.searchParams.set("fromStartTime", fromStartTime);
52
- endpoint.searchParams.set("limit", "1000");
53
- endpoint.searchParams.set("toStartTime", toStartTime);
54
- if (cursor) endpoint.searchParams.set("cursor", cursor);
55
- const body = await fetchLangfuseJson(endpoint, deadlineAt);
56
- if (!isRecord(body) || !Array.isArray(body.data))
57
- throw new Error("Langfuse returned an invalid observation page");
58
- for (const observation of body.data.filter(isObservation)) {
59
- if (observation.sessionId === expectedSessionKey) discoveredTraceIds.add(observation.traceId);
60
- }
61
- cursor = isRecord(body.meta) && typeof body.meta.cursor === "string" ? body.meta.cursor : undefined;
62
- } while (cursor && discoveredTraceIds.size === 0);
63
- }
64
- const traces = [];
65
- for (const traceId of [...discoveredTraceIds].slice(0, 4)) {
66
- traces.push(await fetchLangfuseJson(new URL(`/api/public/traces/${traceId}`, baseUrl), deadlineAt));
67
- }
68
- return traces.flatMap((trace) => {
69
- if (
70
- !isRecord(trace) ||
71
- typeof trace.id !== "string" ||
72
- typeof trace.sessionId !== "string" ||
73
- !Array.isArray(trace.observations)
74
- )
75
- return [];
76
- return trace.observations.filter(isTraceObservation).map((observation) => ({
77
- ...observation,
78
- sessionId: trace.sessionId,
79
- traceId: trace.id
80
- }));
81
- });
82
- },
83
- now: () => new Date(),
84
- readDriveFile: async (fileToken) => {
85
- const directory = await mkdtemp(join(tmpdir(), "rivus-langfuse-drive-e2e-"));
86
- const outputName = `./${expectedDriveTitle}`;
87
- try {
88
- await command(
89
- process.env.RIVUS_LARK_CLI_PATH?.trim() || "lark-cli",
90
- ["drive", "+download", "--as", "user", "--file-token", fileToken, "--output", outputName],
91
- directory
92
- );
93
- return await readFile(join(directory, expectedDriveTitle), "utf8");
94
- } finally {
95
- await rm(directory, { force: true, recursive: true });
96
- }
97
- },
98
- runAgent: ({ prompt: agentPrompt, sessionKey: agentSessionKey }) =>
99
- command(
100
- process.execPath,
101
- [
102
- "dist/cli.js",
103
- "--bootstrap",
104
- "./examples/pi-feishu-deployment.bootstrap.ts",
105
- "--manifest",
106
- "./examples/rivus-langfuse-demo.config.json",
107
- "--prompt",
108
- agentPrompt,
109
- "--session-key",
110
- agentSessionKey
111
- ],
112
- process.cwd(),
113
- { RIVUS_DEPLOYMENT_STATE_DIR: deploymentStateDirectory }
114
- ),
115
- sleep: (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds))
116
- },
117
- expectedDriveContentMarker: marker,
118
- expectedDriveTitle,
119
- prompt,
120
- sessionKey
121
- }).finally(() => rm(deploymentStateDirectory, { force: true, recursive: true }));
122
-
123
- process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
124
-
125
- async function fetchLangfuseJson(endpoint, deadlineAt) {
126
- const remainingMs = new Date(deadlineAt).getTime() - Date.now();
127
- if (!Number.isFinite(remainingMs) || remainingMs <= 0) throw new Error("Langfuse request deadline expired");
128
- const response = await fetch(endpoint, {
129
- headers: {
130
- authorization: `Basic ${Buffer.from(`${publicKey}:${secretKey}`).toString("base64")}`
131
- },
132
- signal: AbortSignal.timeout(Math.min(remainingMs, 10_000))
133
- });
134
- if (!response.ok) throw new Error(`Langfuse request failed with HTTP ${response.status}`);
135
- return response.json();
136
- }
137
-
138
- async function command(executable, args, cwd = process.cwd(), extraEnv = {}) {
139
- const { stdout } = await execFileAsync(executable, args, {
140
- cwd,
141
- env: {
142
- ...process.env,
143
- ...extraEnv,
144
- LARKSUITE_CLI_NO_SKILLS_NOTIFIER: "1",
145
- LARKSUITE_CLI_NO_UPDATE_NOTIFIER: "1"
146
- },
147
- maxBuffer: 2 * 1024 * 1024,
148
- timeout: 300_000
149
- });
150
- return stdout;
151
- }
152
-
153
- function requiredEnv(name) {
154
- const value = process.env[name]?.trim();
155
- if (!value) throw new Error(`${name} is required`);
156
- return value;
157
- }
158
-
159
- function isObservation(value) {
160
- return isTraceObservation(value) && typeof value.traceId === "string" && typeof value.sessionId === "string";
161
- }
162
-
163
- function isTraceObservation(value) {
164
- return (
165
- isRecord(value) &&
166
- typeof value.id === "string" &&
167
- typeof value.name === "string" &&
168
- typeof value.startTime === "string" &&
169
- typeof value.type === "string"
170
- );
171
- }
172
-
173
- function isRecord(value) {
174
- return value !== null && typeof value === "object" && !Array.isArray(value);
175
- }