@rivus/agent 0.5.2 → 0.6.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.
@@ -1,177 +1,5 @@
1
- import { c as MemoryScope, t as AgentMemoryAuthority } from "./agent-memory.js";
1
+ import { h as RivusPlugin, l as RivusAgentDeployment } from "./rivus-plugin.js";
2
2
 
3
- //#region src/domain/rivus-plugin.d.ts
4
- declare const RIVUS_PLUGIN_API_VERSION = "1";
5
- type RivusToolRisk = "observe" | "mutate" | "irreversible" | "host-control";
6
- type RivusToolIdempotency = "none" | "supported" | "required";
7
- declare function requiresToolApproval(risk: RivusToolRisk): boolean;
8
- declare class RivusToolInputRejected extends Error {
9
- readonly name: string;
10
- }
11
- interface RivusPluginManifest {
12
- readonly apiVersion: string;
13
- readonly id: string;
14
- readonly version: string;
15
- }
16
- interface RivusToolExecutor {
17
- execute(input: unknown, context: RivusToolExecutionContext): unknown;
18
- }
19
- interface RivusToolExecutionContext {
20
- readonly agentId: string;
21
- readonly instanceId: string;
22
- readonly memory?: AgentMemoryAuthority;
23
- readonly runId: string;
24
- readonly callId: string;
25
- readonly operationId?: string;
26
- readonly policyEpoch: number;
27
- readonly toolId: string;
28
- readonly toolVersion: string;
29
- readonly sessionKey: string;
30
- }
31
- interface RivusToolFactoryContext {
32
- readonly toolId: string;
33
- readonly toolVersion: string;
34
- }
35
- interface RivusToolDescriptor {
36
- readonly id: string;
37
- readonly version: string;
38
- readonly digest: string;
39
- readonly description: string;
40
- readonly inputSchema: unknown;
41
- readonly risk: RivusToolRisk;
42
- readonly idempotency: RivusToolIdempotency;
43
- readonly createExecutor: (context: RivusToolFactoryContext) => RivusToolExecutor;
44
- }
45
- interface RivusHostToolDescriptor extends RivusToolDescriptor {
46
- readonly replayCompleted?: (input: unknown, completedResult: unknown, context: RivusToolExecutionContext) => unknown;
47
- }
48
- interface RivusSkillDescriptor {
49
- readonly id: string;
50
- readonly version: string;
51
- readonly digest: string;
52
- readonly title: string;
53
- readonly content: string;
54
- }
55
- interface RivusAutomationTemplate {
56
- readonly id: string;
57
- readonly profileId: string;
58
- readonly requestedSkillIds: ReadonlyArray<string>;
59
- readonly requestedToolIds: ReadonlyArray<string>;
60
- readonly createInput: (tick: RivusAutomationTickContext) => RivusAutomationInput;
61
- }
62
- interface RivusAutomationTickContext {
63
- readonly occurrence: string;
64
- }
65
- interface RivusAutomationInput {
66
- readonly text: string;
67
- }
68
- interface RivusAgentProfile {
69
- readonly id: string;
70
- readonly displayName: string;
71
- readonly systemPrompt: string;
72
- readonly model: Readonly<Record<string, unknown>>;
73
- readonly tools: {
74
- readonly allow: ReadonlyArray<string>;
75
- };
76
- readonly skills: {
77
- readonly allow: ReadonlyArray<string>;
78
- };
79
- readonly memory: {
80
- readonly scopes: ReadonlyArray<MemoryScope>;
81
- };
82
- }
83
- interface RivusPluginRegistry {
84
- registerAgentProfile(profile: RivusAgentProfile): void;
85
- registerTool(tool: RivusToolDescriptor): void;
86
- registerSkill(skill: RivusSkillDescriptor): void;
87
- registerAutomation(template: RivusAutomationTemplate): void;
88
- }
89
- interface RivusPlugin {
90
- readonly manifest: RivusPluginManifest;
91
- register(registry: RivusPluginRegistry): void;
92
- }
93
- interface RegisteredRivusPlugin extends RivusPluginManifest {}
94
- interface RegisteredRivusTool extends RivusToolDescriptor {
95
- readonly pluginId: string;
96
- }
97
- interface RegisteredRivusSkill extends RivusSkillDescriptor {
98
- readonly pluginId: string;
99
- }
100
- interface RegisteredRivusAutomation extends RivusAutomationTemplate {
101
- readonly pluginId: string;
102
- }
103
- interface RegisteredRivusAgentProfile extends RivusAgentProfile {
104
- readonly pluginId: string;
105
- }
106
- interface RivusPluginCatalogSnapshot {
107
- readonly plugins: ReadonlyArray<RegisteredRivusPlugin>;
108
- readonly profiles: ReadonlyArray<RegisteredRivusAgentProfile>;
109
- readonly tools: ReadonlyArray<RegisteredRivusTool>;
110
- readonly skills: ReadonlyArray<RegisteredRivusSkill>;
111
- readonly automations: ReadonlyArray<RegisteredRivusAutomation>;
112
- }
113
- interface RivusPluginCatalog {
114
- registerPlugin(plugin: RivusPlugin): void;
115
- snapshot(): RivusPluginCatalogSnapshot;
116
- }
117
- interface RivusAgentDeployment {
118
- readonly agentId: string;
119
- readonly pluginId: string;
120
- readonly profileId: string;
121
- readonly projectSpaceId?: string;
122
- readonly endpointIds: ReadonlyArray<string>;
123
- readonly memory?: {
124
- readonly scopes: ReadonlyArray<MemoryScope>;
125
- readonly tool: boolean;
126
- };
127
- readonly skills: {
128
- readonly allow: ReadonlyArray<string>;
129
- };
130
- readonly tools: {
131
- readonly allow: ReadonlyArray<string>;
132
- };
133
- }
134
- interface RivusResolvedToolDescriptor {
135
- readonly id: string;
136
- readonly version: string;
137
- readonly digest: string;
138
- readonly description: string;
139
- readonly inputSchema: unknown;
140
- readonly risk: RivusToolRisk;
141
- readonly idempotency: RivusToolIdempotency;
142
- readonly pluginId: string;
143
- }
144
- interface RivusToolGrantSet {
145
- readonly toolIds: ReadonlyArray<string>;
146
- readonly revision: string;
147
- }
148
- interface RivusSkillGrantSet {
149
- readonly skillIds: ReadonlyArray<string>;
150
- readonly revision: string;
151
- }
152
- interface ResolvedRivusAgentDefinition {
153
- readonly agentId: string;
154
- readonly pluginId: string;
155
- readonly profileId: string;
156
- readonly projectSpaceId?: string;
157
- readonly projectSpaceRevision?: string;
158
- readonly endpointIds: ReadonlyArray<string>;
159
- readonly profileRevision: string;
160
- readonly systemPrompt: string;
161
- readonly model: Readonly<Record<string, unknown>>;
162
- readonly memory: {
163
- readonly scopes: ReadonlyArray<MemoryScope>;
164
- readonly tool: boolean;
165
- };
166
- readonly skillGrantSet: RivusSkillGrantSet;
167
- readonly skills: ReadonlyArray<RegisteredRivusSkill>;
168
- readonly tools: ReadonlyArray<RivusResolvedToolDescriptor>;
169
- readonly toolGrantSet: RivusToolGrantSet;
170
- }
171
- declare class InvalidRivusPlugin extends Error {
172
- readonly name = "InvalidRivusPlugin";
173
- }
174
- //#endregion
175
3
  //#region src/testing/rivus-plugin-testkit.d.ts
176
4
  interface RivusPluginLifecycleProbe {
177
5
  activate(): Promise<{
@@ -196,4 +24,4 @@ declare class RivusPluginConformanceError extends Error {
196
24
  declare function assertRivusPluginConforms(input: RivusPluginConformanceInput): Promise<RivusPluginConformanceReport>;
197
25
  declare function createFakeRivusPlugin(): RivusPlugin;
198
26
  //#endregion
199
- export { RivusToolExecutionContext as A, RivusPluginCatalogSnapshot as C, RivusSkillDescriptor as D, RivusResolvedToolDescriptor as E, RivusToolInputRejected as F, RivusToolRisk as I, requiresToolApproval as L, RivusToolFactoryContext as M, RivusToolGrantSet as N, RivusSkillGrantSet as O, RivusToolIdempotency as P, RivusPluginCatalog as S, RivusPluginRegistry as T, RivusAutomationInput as _, assertRivusPluginConforms as a, RivusHostToolDescriptor as b, RIVUS_PLUGIN_API_VERSION as c, RegisteredRivusPlugin as d, RegisteredRivusSkill as f, RivusAgentProfile as g, RivusAgentDeployment as h, RivusPluginLifecycleProbe as i, RivusToolExecutor as j, RivusToolDescriptor as k, RegisteredRivusAgentProfile as l, ResolvedRivusAgentDefinition as m, RivusPluginConformanceInput as n, createFakeRivusPlugin as o, RegisteredRivusTool as p, RivusPluginConformanceReport as r, InvalidRivusPlugin as s, RivusPluginConformanceError as t, RegisteredRivusAutomation as u, RivusAutomationTemplate as v, RivusPluginManifest as w, RivusPlugin as x, RivusAutomationTickContext as y };
27
+ export { assertRivusPluginConforms as a, RivusPluginLifecycleProbe as i, RivusPluginConformanceInput as n, createFakeRivusPlugin as o, RivusPluginConformanceReport as r, RivusPluginConformanceError as t };
@@ -1,4 +1,5 @@
1
- import { a as RIVUS_MEMORY_TOOL_ID, n as resolveRivusAgentDefinition, t as createRivusPluginCatalog } from "./rivus-plugin-registry.js";
1
+ import { n as RIVUS_MEMORY_TOOL_ID } from "./agent-memory.js";
2
+ import { n as resolveRivusAgentDefinition, t as createRivusPluginCatalog } from "./rivus-plugin-registry.js";
2
3
  //#region src/testing/rivus-plugin-testkit.ts
3
4
  var RivusPluginConformanceError = class extends Error {
4
5
  name = "RivusPluginConformanceError";
@@ -0,0 +1,175 @@
1
+ import { c as MemoryScope, t as AgentMemoryAuthority } from "./agent-memory.js";
2
+
3
+ //#region src/domain/rivus-plugin.d.ts
4
+ declare const RIVUS_PLUGIN_API_VERSION = "1";
5
+ type RivusToolRisk = "observe" | "mutate" | "irreversible" | "host-control";
6
+ type RivusToolIdempotency = "none" | "supported" | "required";
7
+ declare function requiresToolApproval(risk: RivusToolRisk): boolean;
8
+ declare class RivusToolInputRejected extends Error {
9
+ readonly name: string;
10
+ }
11
+ interface RivusPluginManifest {
12
+ readonly apiVersion: string;
13
+ readonly id: string;
14
+ readonly version: string;
15
+ }
16
+ interface RivusToolExecutor {
17
+ execute(input: unknown, context: RivusToolExecutionContext): unknown;
18
+ }
19
+ interface RivusToolExecutionContext {
20
+ readonly agentId: string;
21
+ readonly instanceId: string;
22
+ readonly memory?: AgentMemoryAuthority;
23
+ readonly runId: string;
24
+ readonly callId: string;
25
+ readonly operationId?: string;
26
+ readonly policyEpoch: number;
27
+ readonly toolId: string;
28
+ readonly toolVersion: string;
29
+ readonly sessionKey: string;
30
+ }
31
+ interface RivusToolFactoryContext {
32
+ readonly toolId: string;
33
+ readonly toolVersion: string;
34
+ }
35
+ interface RivusToolDescriptor {
36
+ readonly id: string;
37
+ readonly version: string;
38
+ readonly digest: string;
39
+ readonly description: string;
40
+ readonly inputSchema: unknown;
41
+ readonly risk: RivusToolRisk;
42
+ readonly idempotency: RivusToolIdempotency;
43
+ readonly createExecutor: (context: RivusToolFactoryContext) => RivusToolExecutor;
44
+ }
45
+ interface RivusHostToolDescriptor extends RivusToolDescriptor {
46
+ readonly replayCompleted?: (input: unknown, completedResult: unknown, context: RivusToolExecutionContext) => unknown;
47
+ }
48
+ interface RivusSkillDescriptor {
49
+ readonly id: string;
50
+ readonly version: string;
51
+ readonly digest: string;
52
+ readonly title: string;
53
+ readonly content: string;
54
+ }
55
+ interface RivusAutomationTemplate {
56
+ readonly id: string;
57
+ readonly profileId: string;
58
+ readonly requestedSkillIds: ReadonlyArray<string>;
59
+ readonly requestedToolIds: ReadonlyArray<string>;
60
+ readonly createInput: (tick: RivusAutomationTickContext) => RivusAutomationInput;
61
+ }
62
+ interface RivusAutomationTickContext {
63
+ readonly occurrence: string;
64
+ }
65
+ interface RivusAutomationInput {
66
+ readonly text: string;
67
+ }
68
+ interface RivusAgentProfile {
69
+ readonly id: string;
70
+ readonly displayName: string;
71
+ readonly systemPrompt: string;
72
+ readonly model: Readonly<Record<string, unknown>>;
73
+ readonly tools: {
74
+ readonly allow: ReadonlyArray<string>;
75
+ };
76
+ readonly skills: {
77
+ readonly allow: ReadonlyArray<string>;
78
+ };
79
+ readonly memory: {
80
+ readonly scopes: ReadonlyArray<MemoryScope>;
81
+ };
82
+ }
83
+ interface RivusPluginRegistry {
84
+ registerAgentProfile(profile: RivusAgentProfile): void;
85
+ registerTool(tool: RivusToolDescriptor): void;
86
+ registerSkill(skill: RivusSkillDescriptor): void;
87
+ registerAutomation(template: RivusAutomationTemplate): void;
88
+ }
89
+ interface RivusPlugin {
90
+ readonly manifest: RivusPluginManifest;
91
+ register(registry: RivusPluginRegistry): void;
92
+ }
93
+ interface RegisteredRivusPlugin extends RivusPluginManifest {}
94
+ interface RegisteredRivusTool extends RivusToolDescriptor {
95
+ readonly pluginId: string;
96
+ }
97
+ interface RegisteredRivusSkill extends RivusSkillDescriptor {
98
+ readonly pluginId: string;
99
+ }
100
+ interface RegisteredRivusAutomation extends RivusAutomationTemplate {
101
+ readonly pluginId: string;
102
+ }
103
+ interface RegisteredRivusAgentProfile extends RivusAgentProfile {
104
+ readonly pluginId: string;
105
+ }
106
+ interface RivusPluginCatalogSnapshot {
107
+ readonly plugins: ReadonlyArray<RegisteredRivusPlugin>;
108
+ readonly profiles: ReadonlyArray<RegisteredRivusAgentProfile>;
109
+ readonly tools: ReadonlyArray<RegisteredRivusTool>;
110
+ readonly skills: ReadonlyArray<RegisteredRivusSkill>;
111
+ readonly automations: ReadonlyArray<RegisteredRivusAutomation>;
112
+ }
113
+ interface RivusPluginCatalog {
114
+ registerPlugin(plugin: RivusPlugin): void;
115
+ snapshot(): RivusPluginCatalogSnapshot;
116
+ }
117
+ interface RivusAgentDeployment {
118
+ readonly agentId: string;
119
+ readonly pluginId: string;
120
+ readonly profileId: string;
121
+ readonly projectSpaceId?: string;
122
+ readonly endpointIds: ReadonlyArray<string>;
123
+ readonly memory?: {
124
+ readonly scopes: ReadonlyArray<MemoryScope>;
125
+ readonly tool: boolean;
126
+ };
127
+ readonly skills: {
128
+ readonly allow: ReadonlyArray<string>;
129
+ };
130
+ readonly tools: {
131
+ readonly allow: ReadonlyArray<string>;
132
+ };
133
+ }
134
+ interface RivusResolvedToolDescriptor {
135
+ readonly id: string;
136
+ readonly version: string;
137
+ readonly digest: string;
138
+ readonly description: string;
139
+ readonly inputSchema: unknown;
140
+ readonly risk: RivusToolRisk;
141
+ readonly idempotency: RivusToolIdempotency;
142
+ readonly pluginId: string;
143
+ }
144
+ interface RivusToolGrantSet {
145
+ readonly toolIds: ReadonlyArray<string>;
146
+ readonly revision: string;
147
+ }
148
+ interface RivusSkillGrantSet {
149
+ readonly skillIds: ReadonlyArray<string>;
150
+ readonly revision: string;
151
+ }
152
+ interface ResolvedRivusAgentDefinition {
153
+ readonly agentId: string;
154
+ readonly pluginId: string;
155
+ readonly profileId: string;
156
+ readonly projectSpaceId?: string;
157
+ readonly projectSpaceRevision?: string;
158
+ readonly endpointIds: ReadonlyArray<string>;
159
+ readonly profileRevision: string;
160
+ readonly systemPrompt: string;
161
+ readonly model: Readonly<Record<string, unknown>>;
162
+ readonly memory: {
163
+ readonly scopes: ReadonlyArray<MemoryScope>;
164
+ readonly tool: boolean;
165
+ };
166
+ readonly skillGrantSet: RivusSkillGrantSet;
167
+ readonly skills: ReadonlyArray<RegisteredRivusSkill>;
168
+ readonly tools: ReadonlyArray<RivusResolvedToolDescriptor>;
169
+ readonly toolGrantSet: RivusToolGrantSet;
170
+ }
171
+ declare class InvalidRivusPlugin extends Error {
172
+ readonly name = "InvalidRivusPlugin";
173
+ }
174
+ //#endregion
175
+ export { RivusToolRisk as A, RivusToolDescriptor as C, RivusToolGrantSet as D, RivusToolFactoryContext as E, RivusToolIdempotency as O, RivusSkillGrantSet as S, RivusToolExecutor as T, RivusPluginCatalogSnapshot as _, RegisteredRivusPlugin as a, RivusResolvedToolDescriptor as b, ResolvedRivusAgentDefinition as c, RivusAutomationInput as d, RivusAutomationTemplate as f, RivusPluginCatalog as g, RivusPlugin as h, RegisteredRivusAutomation as i, requiresToolApproval as j, RivusToolInputRejected as k, RivusAgentDeployment as l, RivusHostToolDescriptor as m, RIVUS_PLUGIN_API_VERSION as n, RegisteredRivusSkill as o, RivusAutomationTickContext as p, RegisteredRivusAgentProfile as r, RegisteredRivusTool as s, InvalidRivusPlugin as t, RivusAgentProfile as u, RivusPluginManifest as v, RivusToolExecutionContext as w, RivusSkillDescriptor as x, RivusPluginRegistry as y };
@@ -0,0 +1,126 @@
1
+ import { s as restrictMemoryScopesForAudience } from "./agent-memory.js";
2
+ import { createHash, randomUUID } from "node:crypto";
3
+ import { Unsafe } from "typebox";
4
+ //#region src/infrastructure/pi/pi-skill-tool.ts
5
+ const PI_SKILL_READER_TOOL_NAME = "rivus_read_skill";
6
+ function createPiSkillRuntime(skills) {
7
+ if (skills.length === 0) return Object.freeze({ prompt: "" });
8
+ const skillsById = new Map(skills.map((skill) => [skill.id, skill]));
9
+ const prompt = [
10
+ "Granted Skills are versioned instructions loaded on demand.",
11
+ `Before following a Skill, call ${PI_SKILL_READER_TOOL_NAME} with its exact ID and follow the returned content.`,
12
+ "Granted Skill catalog:",
13
+ ...skills.map((skill) => `- ${skill.id} | ${skill.title} | v${skill.version} | ${skill.digest}`)
14
+ ].join("\n");
15
+ const tool = {
16
+ description: "Read the full versioned instructions for one Skill granted to this Agent Runtime.",
17
+ execute: async (_callId, input) => {
18
+ const skillId = readSkillId(input);
19
+ const skill = skillsById.get(skillId);
20
+ if (!skill) throw new Error(`Skill is not granted: ${skillId}`);
21
+ const details = {
22
+ contentLength: skill.content.length,
23
+ digest: skill.digest,
24
+ skillId: skill.id,
25
+ title: skill.title,
26
+ version: skill.version
27
+ };
28
+ return {
29
+ content: [{
30
+ text: skill.content,
31
+ type: "text"
32
+ }],
33
+ details
34
+ };
35
+ },
36
+ executionMode: "sequential",
37
+ label: "Read granted Skill",
38
+ name: PI_SKILL_READER_TOOL_NAME,
39
+ parameters: Unsafe({
40
+ additionalProperties: false,
41
+ properties: { skillId: {
42
+ description: "Exact Skill ID from the granted Skill catalog.",
43
+ type: "string"
44
+ } },
45
+ required: ["skillId"],
46
+ type: "object"
47
+ }),
48
+ promptSnippet: `${PI_SKILL_READER_TOOL_NAME}: read one granted Skill by exact ID`
49
+ };
50
+ return Object.freeze({
51
+ prompt,
52
+ tool
53
+ });
54
+ }
55
+ function readSkillId(input) {
56
+ if (input === null || typeof input !== "object" || Array.isArray(input) || typeof input.skillId !== "string") throw new Error("Skill reader input requires a string skillId");
57
+ return input.skillId;
58
+ }
59
+ //#endregion
60
+ //#region src/application/delegation/tool-authority.ts
61
+ const authorities = /* @__PURE__ */ new WeakMap();
62
+ var InvalidInvocationAuthority = class extends Error {
63
+ name = "InvalidInvocationAuthority";
64
+ };
65
+ function createInvocationAuthority(authority) {
66
+ if (!authority.sourceMessageId.trim()) throw new InvalidInvocationAuthority("invocation authority requires a trusted source message id");
67
+ const reference = Object.freeze({ id: `authority:${randomUUID()}` });
68
+ const memory = authority.memory ? Object.freeze({
69
+ ...authority.memory,
70
+ scopes: Object.freeze(restrictMemoryScopesForAudience(authority.memory.scopes, authority.memory.audience))
71
+ }) : void 0;
72
+ authorities.set(reference, Object.freeze({
73
+ ...authority,
74
+ ...memory ? { memory } : {}
75
+ }));
76
+ return reference;
77
+ }
78
+ function resolveInvocationAuthority(reference) {
79
+ const authority = authorities.get(reference);
80
+ if (!authority) throw new InvalidInvocationAuthority("invocation authority was not issued by this host");
81
+ return authority;
82
+ }
83
+ //#endregion
84
+ //#region src/application/delegation/tool-input-digest.ts
85
+ var InvalidStableJson = class extends Error {
86
+ name = "InvalidStableJson";
87
+ };
88
+ var InvalidToolInput = class extends InvalidStableJson {
89
+ name = "InvalidToolInput";
90
+ };
91
+ function createToolInputDigest(input) {
92
+ let canonical;
93
+ try {
94
+ canonical = normalizeStableJson(input);
95
+ } catch (error) {
96
+ if (error instanceof InvalidStableJson) throw new InvalidToolInput(error.message);
97
+ throw error;
98
+ }
99
+ return `sha256:${createHash("sha256").update(JSON.stringify(canonical)).digest("hex")}`;
100
+ }
101
+ function normalizeStableJson(value) {
102
+ return canonicalize(value, /* @__PURE__ */ new Set());
103
+ }
104
+ function canonicalize(value, ancestors) {
105
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
106
+ if (typeof value === "number") {
107
+ if (!Number.isFinite(value)) throw new InvalidStableJson("stable JSON numbers must be finite");
108
+ return Object.is(value, -0) ? 0 : value;
109
+ }
110
+ if (typeof value !== "object") throw new InvalidStableJson("value must contain only stable JSON values");
111
+ if (ancestors.has(value)) throw new InvalidStableJson("stable JSON must not contain cycles");
112
+ ancestors.add(value);
113
+ try {
114
+ if (Array.isArray(value)) return Array.from({ length: value.length }, (_, index) => {
115
+ if (!Object.hasOwn(value, index)) throw new InvalidStableJson("stable JSON arrays must not contain holes");
116
+ return canonicalize(value[index], ancestors);
117
+ });
118
+ const prototype = Object.getPrototypeOf(value);
119
+ if (prototype !== Object.prototype && prototype !== null) throw new InvalidStableJson("stable JSON objects must be plain objects");
120
+ return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, entry]) => [key, canonicalize(entry, ancestors)]));
121
+ } finally {
122
+ ancestors.delete(value);
123
+ }
124
+ }
125
+ //#endregion
126
+ export { InvalidInvocationAuthority as a, PI_SKILL_READER_TOOL_NAME as c, normalizeStableJson as i, createPiSkillRuntime as l, InvalidToolInput as n, createInvocationAuthority as o, createToolInputDigest as r, resolveInvocationAuthority as s, InvalidStableJson as t };
@@ -16,14 +16,14 @@ import {
16
16
  createAgentHarnessPooledRuntime,
17
17
  createRivusMemoryToolDescriptor,
18
18
  createConfiguredFeishuAutomationCardSender,
19
- createConfiguredFeishuCardKitPublisher,
20
- createConfiguredFeishuCardKitTargetPreparation,
19
+ createConfiguredFeishuCardRolloverRuntime,
21
20
  createConfiguredFeishuHumanInteractionPresenter,
22
21
  createConfiguredFeishuOpenApiClient,
23
22
  createConfiguredFeishuTextReplySender,
24
23
  createFeishuCotPublisher,
25
24
  createFeishuDeploymentEndpoint,
26
25
  createFeishuPresentationPreparation,
26
+ createSystemClock,
27
27
  createFeishuCardDeliveryReconciler,
28
28
  createHumanInteractionEndpointRegistry,
29
29
  createHumanInteractionService,
@@ -36,14 +36,10 @@ import {
36
36
  createLazyFeishuWebSocketEventDispatcher,
37
37
  createPiAgentLoop,
38
38
  createProjectMemoryPromptPreparer,
39
- createPiSkillRuntime,
40
- createPiToolNameResolver,
41
- createPiToolProxyDefinitions,
42
39
  createPiSessionRegistry,
43
40
  createRoutedHumanInteractionToolApprovalService,
44
41
  createSessionScheduler,
45
42
  createScheduledAutomation,
46
- createSystemClock,
47
43
  createToolBroker,
48
44
  createUuidRunIds,
49
45
  createWorkspaceRootHandle,
@@ -61,12 +57,18 @@ import {
61
57
  type CreateRivusDeploymentAutomationInput,
62
58
  type CreateRivusDeploymentRuntimeInput,
63
59
  type ConfiguredFeishuOpenApiResponse,
60
+ type FeishuAgentRunPreparation,
64
61
  type FeishuWebSocketClient,
65
62
  type RivusDaemonConfig,
66
63
  type RivusDeploymentBootstrapContext,
67
64
  type RivusThinkingLevel
68
65
  } from "@rivus/agent";
69
- import { createPiProjectSkillReadTool } from "@rivus/agent/pi";
66
+ import {
67
+ createPiProjectSkillReadTool,
68
+ createPiSkillRuntime,
69
+ createPiToolNameResolver,
70
+ createPiToolProxyDefinitions
71
+ } from "@rivus/agent/pi";
70
72
 
71
73
  type PiSessionOptions = NonNullable<Parameters<typeof createAgentSession>[0]>;
72
74
 
@@ -106,6 +108,7 @@ export async function createRivusDeploymentAdapters(context: RivusDeploymentBoot
106
108
  feishu: {
107
109
  ...credentials,
108
110
  baseUrl: input.deliveryEndpoint.baseUrl,
111
+ cardStreamLeaseMs: input.deliveryEndpoint.cardStreamLeaseMs,
109
112
  streamMinIntervalMs: input.deliveryEndpoint.streamMinIntervalMs
110
113
  },
111
114
  pi: {}
@@ -176,6 +179,7 @@ export async function createRivusDeploymentAdapters(context: RivusDeploymentBoot
176
179
  feishu: {
177
180
  ...credentials,
178
181
  baseUrl: input.definition.baseUrl,
182
+ cardStreamLeaseMs: input.definition.cardStreamLeaseMs,
179
183
  streamMinIntervalMs: input.definition.streamMinIntervalMs
180
184
  },
181
185
  pi: {}
@@ -198,14 +202,20 @@ export async function createRivusDeploymentAdapters(context: RivusDeploymentBoot
198
202
  filePath: join(endpointState, "human-interactions.jsonl")
199
203
  })
200
204
  });
201
- const publisher = createConfiguredFeishuCardKitPublisher({
205
+ const cardRollover = createConfiguredFeishuCardRolloverRuntime({
202
206
  agentName: input.agentId,
207
+ cardTargets,
203
208
  client: openApiClient,
209
+ clock: createSystemClock(),
204
210
  config,
205
211
  ledger: cardLedger,
206
- resolveTarget: (runId) => cardTargets.resolveTarget(runId),
207
- sleep
212
+ onError: (error) => {
213
+ console.error(`Feishu card rollover failed for endpoint ${input.endpointId}`, error);
214
+ },
215
+ sleep,
216
+ title: input.agentId
208
217
  });
218
+ const publisher = cardRollover.rollover;
209
219
  const endpointEvents = createJsonlAgentEventLog({
210
220
  filePath: join(STATE_DIR, "instances", input.instanceId, "agent-events.jsonl")
211
221
  });
@@ -220,15 +230,12 @@ export async function createRivusDeploymentAdapters(context: RivusDeploymentBoot
220
230
  client: openApiClient,
221
231
  config
222
232
  });
223
- const prepareCardTarget = createConfiguredFeishuCardKitTargetPreparation({
224
- client: openApiClient,
225
- config,
226
- registry: cardTargets,
227
- title: input.agentId
228
- });
233
+ const prepareCardTarget = (run: FeishuAgentRunPreparation) => cardRollover.prepareRun(run);
229
234
  const endpoint = createFeishuDeploymentEndpoint({
230
235
  agentId: input.agentId,
231
236
  botOpenId,
237
+ cardRollover: cardRollover.transport,
238
+ finalizeRun: (runId) => cardRollover.rollover.releaseRun(runId),
232
239
  cancel: input.cancel,
233
240
  endpointId: input.endpointId,
234
241
  eventDispatcher: createLazyFeishuWebSocketEventDispatcher(() => new Lark.EventDispatcher({})),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivus/agent",
3
- "version": "0.5.2",
3
+ "version": "0.6.1",
4
4
  "description": "A local agent daemon core built around a usable agent harness and domain events.",
5
5
  "type": "module",
6
6
  "license": "MIT",