@rivus/agent 0.16.2 → 0.16.6

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,158 +0,0 @@
1
- import { Effect, Stream } from "effect";
2
- //#region src/core/application/agent-execution/loop/agent-loop.ts
3
- function createAgentLoopTextDelta(delta) {
4
- return {
5
- delta,
6
- type: "assistant_text_delta"
7
- };
8
- }
9
- function createAgentLoopTurnStart() {
10
- return { type: "turn_start" };
11
- }
12
- function normalizeAgentLoopEvent(event) {
13
- return typeof event === "string" ? createAgentLoopTextDelta(event) : event;
14
- }
15
- function createAgentLoopThinkingDelta(delta) {
16
- return {
17
- delta,
18
- type: "assistant_thinking_delta"
19
- };
20
- }
21
- function createAgentLoopModelExecutionStart(options) {
22
- return {
23
- ...options,
24
- type: "model_execution_start"
25
- };
26
- }
27
- function createAgentLoopModelExecutionEnd(options) {
28
- return {
29
- ...options,
30
- type: "model_execution_end"
31
- };
32
- }
33
- function createAgentLoopSkillExecutionStart(options) {
34
- return {
35
- ...options,
36
- type: "skill_execution_start"
37
- };
38
- }
39
- function createAgentLoopSkillExecutionEnd(options) {
40
- return {
41
- ...options,
42
- type: "skill_execution_end"
43
- };
44
- }
45
- function createAgentLoopToolExecutionStart(options) {
46
- return {
47
- input: options.input,
48
- toolCallId: options.toolCallId,
49
- toolName: options.toolName,
50
- type: "tool_execution_start"
51
- };
52
- }
53
- function createAgentLoopToolExecutionUpdate(options) {
54
- return {
55
- input: options.input,
56
- partialResult: options.partialResult,
57
- toolCallId: options.toolCallId,
58
- toolName: options.toolName,
59
- type: "tool_execution_update"
60
- };
61
- }
62
- function createAgentLoopToolExecutionEnd(options) {
63
- return {
64
- isError: options.isError,
65
- result: options.result,
66
- toolCallId: options.toolCallId,
67
- toolName: options.toolName,
68
- type: "tool_execution_end"
69
- };
70
- }
71
- function createTextAgentLoop$1(options) {
72
- return { run: (input) => Stream.fromEffect(options.generate(input)).pipe(Stream.map((delta) => createAgentLoopTextDelta(delta))) };
73
- }
74
- //#endregion
75
- //#region src/adapters/compatibility/agent-execution/loop/agent-loop.ts
76
- function createEventAgentLoop(options) {
77
- return { run: (input) => {
78
- const events = typeof options.events === "function" ? options.events(input) : options.events;
79
- if (isPromiseLike(events)) return Stream.fromEffect(Effect.tryPromise({
80
- try: () => events,
81
- catch: (cause) => cause
82
- })).pipe(Stream.flatMap((resolvedEvents) => Stream.fromIterable(resolvedEvents)), Stream.map(normalizeAgentLoopEvent));
83
- return Stream.fromIterable(events).pipe(Stream.map(normalizeAgentLoopEvent));
84
- } };
85
- }
86
- function createAsyncIterableAgentLoop(options) {
87
- return { run: (input) => Stream.fromAsyncIterable(options.run(input), (error) => error).pipe(Stream.map(normalizeAgentLoopEvent)) };
88
- }
89
- function createAgentLoopFromCallback(run) {
90
- return { run: (input) => Stream.fromEffect(Effect.try({
91
- try: () => run(input),
92
- catch: (cause) => cause
93
- })).pipe(Stream.flatMap(streamFromAgentLoopCallbackResult)) };
94
- }
95
- function createTextAgentLoop(options) {
96
- return fromEffectAgentLoop(createTextAgentLoop$1({ generate: (input) => options.generate(toCompatibilityAgentLoopInput(input)) }));
97
- }
98
- function createTextAgentLoopFromCallback(generate) {
99
- return createTextAgentLoop({ generate: (input) => Effect.tryPromise({
100
- try: async () => generate(input),
101
- catch: (cause) => cause
102
- }) });
103
- }
104
- function toEffectAgentLoop(loop) {
105
- return {
106
- run: (input) => loop.run(toCompatibilityAgentLoopInput(input)),
107
- ...loop.supportsSteering ? { supportsSteering: true } : {}
108
- };
109
- }
110
- function fromEffectAgentLoop(loop) {
111
- return {
112
- run: (input) => loop.run(toEffectAgentLoopInput(input)),
113
- ...loop.supportsSteering ? { supportsSteering: true } : {}
114
- };
115
- }
116
- function toEffectAgentLoopInput(input) {
117
- const { steering, ...rest } = input;
118
- return {
119
- ...rest,
120
- ...steering ? { steering: {
121
- ...steering.close ? { close: () => Effect.promise(() => steering.close()) } : {},
122
- next: () => Effect.promise((signal) => steering.next(signal))
123
- } } : {}
124
- };
125
- }
126
- function toCompatibilityAgentLoopInput(input) {
127
- const { steering, ...rest } = input;
128
- return {
129
- ...rest,
130
- ...steering ? { steering: {
131
- ...steering.close ? { close: () => Effect.runPromise(steering.close()) } : {},
132
- next: (signal) => Effect.runPromise(steering.next(), { signal })
133
- } } : {}
134
- };
135
- }
136
- function isPromiseLike(value) {
137
- return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
138
- }
139
- function streamFromAgentLoopCallbackResult(result) {
140
- if (Effect.isEffect(result)) return Stream.fromEffect(result).pipe(Stream.flatMap(streamFromAgentLoopCallbackOutput));
141
- if (isPromiseLike(result)) return Stream.fromEffect(Effect.tryPromise({
142
- try: () => Promise.resolve(result),
143
- catch: (cause) => cause
144
- })).pipe(Stream.flatMap(streamFromAgentLoopCallbackOutput));
145
- return streamFromAgentLoopCallbackOutput(result);
146
- }
147
- function streamFromAgentLoopCallbackOutput(output) {
148
- if (isEffectStream(output)) return output.pipe(Stream.map(normalizeAgentLoopEvent));
149
- return (isAsyncIterable(output) ? Stream.fromAsyncIterable(output, (error) => error) : Stream.fromIterable(output)).pipe(Stream.map(normalizeAgentLoopEvent));
150
- }
151
- function isAsyncIterable(value) {
152
- return Symbol.asyncIterator in value && typeof value[Symbol.asyncIterator] === "function";
153
- }
154
- function isEffectStream(value) {
155
- return typeof value === "object" && value !== null && Stream.StreamTypeId in value;
156
- }
157
- //#endregion
158
- export { createAgentLoopToolExecutionStart as _, createTextAgentLoopFromCallback as a, toEffectAgentLoop as c, createAgentLoopModelExecutionStart as d, createAgentLoopSkillExecutionEnd as f, createAgentLoopToolExecutionEnd as g, createAgentLoopThinkingDelta as h, createTextAgentLoop as i, toEffectAgentLoopInput as l, createAgentLoopTextDelta as m, createAsyncIterableAgentLoop as n, fromEffectAgentLoop as o, createAgentLoopSkillExecutionStart as p, createEventAgentLoop as r, toCompatibilityAgentLoopInput as s, createAgentLoopFromCallback as t, createAgentLoopModelExecutionEnd as u, createAgentLoopToolExecutionUpdate as v, createAgentLoopTurnStart as y };
@@ -1,230 +0,0 @@
1
- //#region src/core/application/background-session/authority/background-session-identity.ts
2
- const BACKGROUND_SESSION_SESSION_KEY_PREFIX = "background";
3
- function createBackgroundSessionKey(sessionId) {
4
- return `${BACKGROUND_SESSION_SESSION_KEY_PREFIX}:${sessionId}`;
5
- }
6
- function createBackgroundSessionStepSourceMessageId(sessionId, stepCount) {
7
- return `bg:${sessionId}:step:${stepCount}`;
8
- }
9
- //#endregion
10
- //#region src/core/application/background-session/authority/background-session-authority.ts
11
- const BACKGROUND_SESSION_TOOL_IDS = [
12
- "background.start",
13
- "background.wait",
14
- "background.list",
15
- "background.status",
16
- "background.send",
17
- "background.stop"
18
- ];
19
- const BACKGROUND_SESSION_START_TOOL_ID = "background.start";
20
- const BACKGROUND_SESSION_TOOL_PLUGIN_ID = "rivus-core";
21
- const BACKGROUND_SESSION_TOOL_VERSION = "1.0.0";
22
- const BACKGROUND_SESSION_TOOL_DIGESTS = {
23
- "background.list": "sha256:c935847595e406d55ca889875b38db66bb1d4d7a34d7b0fb2b85aecf9478c149",
24
- "background.send": "sha256:b7ed492e45c794dc286f7f66aca8d046082d11dfdc8787eaf5604765b68a7735",
25
- "background.start": "sha256:773690e47f6eef1f1b289216e94cf98e548382d6cffb7b2f034c3ed0635dfcbb",
26
- "background.status": "sha256:6aaa328d6cd97d8755a63abbe97286f1061fd2f238f68b1e576ed9a1d2b7e6b1",
27
- "background.stop": "sha256:aa0bfdf0c9394058bfcbd8662e7bedd59055f9ddad51c2a1bb61666bd67ebfcb",
28
- "background.wait": "sha256:4a0dc80e933ad3c99b6d58421ac9ef733157e39e0ac9b6ad87ac6e65ceaedaab"
29
- };
30
- function createBackgroundSessionToolContracts() {
31
- return [
32
- Object.freeze({
33
- description: "Start a background agent session. Use when the request must wait for external changes, observe over time, or continue working after the foreground run ends. Returns a stable session id immediately; the foreground response can finish here. The detached session continues with the granted Skills, CLI, Tools, Project Space, and Memory of this agent.",
34
- digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.start"],
35
- id: "background.start",
36
- idempotency: "supported",
37
- inputSchema: Object.freeze({
38
- additionalProperties: false,
39
- properties: Object.freeze({
40
- displayName: {
41
- type: "string",
42
- maxLength: 200
43
- },
44
- prompt: {
45
- type: "string",
46
- minLength: 1,
47
- maxLength: 2e4
48
- }
49
- }),
50
- required: ["prompt"],
51
- type: "object"
52
- }),
53
- pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
54
- risk: "mutate",
55
- version: BACKGROUND_SESSION_TOOL_VERSION
56
- }),
57
- Object.freeze({
58
- description: "Pause the current background session durably and end the current step. Call with delayMs to resume after a delay, with until to resume at an absolute ISO time, or with neither to wait for user input. After this call no further tool calls are accepted in this step.",
59
- digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.wait"],
60
- id: "background.wait",
61
- idempotency: "supported",
62
- inputSchema: Object.freeze({
63
- additionalProperties: false,
64
- properties: Object.freeze({
65
- delayMs: {
66
- type: "integer",
67
- minimum: 1e3,
68
- maximum: 864e5
69
- },
70
- reason: {
71
- type: "string",
72
- maxLength: 500
73
- },
74
- until: {
75
- type: "string",
76
- maxLength: 64
77
- }
78
- }),
79
- type: "object"
80
- }),
81
- pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
82
- risk: "mutate",
83
- version: BACKGROUND_SESSION_TOOL_VERSION
84
- }),
85
- Object.freeze({
86
- description: "List background sessions owned by this conversation, newest first. Optionally filter by phase and limit the number of results.",
87
- digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.list"],
88
- id: "background.list",
89
- idempotency: "supported",
90
- inputSchema: Object.freeze({
91
- additionalProperties: false,
92
- properties: Object.freeze({
93
- limit: {
94
- type: "integer",
95
- minimum: 1,
96
- maximum: 50
97
- },
98
- phase: {
99
- enum: [
100
- "queued",
101
- "running",
102
- "waiting",
103
- "input-required",
104
- "stopping",
105
- "stopped",
106
- "completed",
107
- "failed",
108
- "reconciliation-required"
109
- ],
110
- type: "string"
111
- }
112
- }),
113
- type: "object"
114
- }),
115
- pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
116
- risk: "observe",
117
- version: BACKGROUND_SESSION_TOOL_VERSION
118
- }),
119
- Object.freeze({
120
- description: "Return the current phase, step counts, wake time, and result of one background session owned by this conversation.",
121
- digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.status"],
122
- id: "background.status",
123
- idempotency: "supported",
124
- inputSchema: Object.freeze({
125
- additionalProperties: false,
126
- properties: Object.freeze({ sessionId: {
127
- type: "string",
128
- minLength: 1,
129
- maxLength: 200
130
- } }),
131
- required: ["sessionId"],
132
- type: "object"
133
- }),
134
- pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
135
- risk: "observe",
136
- version: BACKGROUND_SESSION_TOOL_VERSION
137
- }),
138
- Object.freeze({
139
- description: "Send new user instruction text to a background session owned by this conversation and wake it. The input is delivered exactly once in the next step.",
140
- digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.send"],
141
- id: "background.send",
142
- idempotency: "supported",
143
- inputSchema: Object.freeze({
144
- additionalProperties: false,
145
- properties: Object.freeze({
146
- message: {
147
- type: "string",
148
- minLength: 1,
149
- maxLength: 2e4
150
- },
151
- sessionId: {
152
- type: "string",
153
- minLength: 1,
154
- maxLength: 200
155
- }
156
- }),
157
- required: ["message", "sessionId"],
158
- type: "object"
159
- }),
160
- pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
161
- risk: "mutate",
162
- version: BACKGROUND_SESSION_TOOL_VERSION
163
- }),
164
- Object.freeze({
165
- description: "Stop a background session owned by this conversation. Persists the cancellation, aborts the active step and its owned process, and delivers a terminal notice.",
166
- digest: BACKGROUND_SESSION_TOOL_DIGESTS["background.stop"],
167
- id: "background.stop",
168
- idempotency: "supported",
169
- inputSchema: Object.freeze({
170
- additionalProperties: false,
171
- properties: Object.freeze({
172
- reason: {
173
- type: "string",
174
- maxLength: 500
175
- },
176
- sessionId: {
177
- type: "string",
178
- minLength: 1,
179
- maxLength: 200
180
- }
181
- }),
182
- required: ["sessionId"],
183
- type: "object"
184
- }),
185
- pluginId: BACKGROUND_SESSION_TOOL_PLUGIN_ID,
186
- risk: "mutate",
187
- version: BACKGROUND_SESSION_TOOL_VERSION
188
- })
189
- ];
190
- }
191
- function backgroundSessionToolIds() {
192
- return [...BACKGROUND_SESSION_TOOL_IDS];
193
- }
194
- function isBackgroundSessionToolId(toolId) {
195
- return BACKGROUND_SESSION_TOOL_IDS.includes(toolId);
196
- }
197
- function extendBackgroundSessionDefinition(definition, digest) {
198
- const contracts = createBackgroundSessionToolContracts();
199
- const existingIds = new Set(definition.tools.map(({ id }) => id));
200
- const additions = contracts.filter((contract) => !existingIds.has(contract.id));
201
- const toolGrantSet = Object.freeze({
202
- revision: grantRevision(digest, definition.toolGrantSet.revision, additions.map(({ id }) => id)),
203
- toolIds: Object.freeze([...definition.toolGrantSet.toolIds, ...additions.map(({ id }) => id)].sort())
204
- });
205
- return Object.freeze({
206
- ...definition,
207
- tools: Object.freeze([...definition.tools, ...additions]),
208
- toolGrantSet
209
- });
210
- }
211
- function narrowBackgroundSessionDefinition(definition, digest) {
212
- const childToolIds = definition.toolGrantSet.toolIds.filter((id) => id !== BACKGROUND_SESSION_START_TOOL_ID);
213
- const toolGrantSet = Object.freeze({
214
- revision: grantRevision(digest, definition.toolGrantSet.revision, childToolIds),
215
- toolIds: Object.freeze(childToolIds)
216
- });
217
- return Object.freeze({
218
- ...definition,
219
- tools: Object.freeze(definition.tools.filter(({ id }) => id !== BACKGROUND_SESSION_START_TOOL_ID)),
220
- toolGrantSet
221
- });
222
- }
223
- function grantRevision(digest, parentRevision, toolIds) {
224
- return digest(JSON.stringify({
225
- parentRevision,
226
- toolIds: [...toolIds].sort()
227
- }));
228
- }
229
- //#endregion
230
- export { backgroundSessionToolIds as a, isBackgroundSessionToolId as c, createBackgroundSessionKey as d, createBackgroundSessionStepSourceMessageId as f, BACKGROUND_SESSION_TOOL_VERSION as i, narrowBackgroundSessionDefinition as l, BACKGROUND_SESSION_TOOL_IDS as n, createBackgroundSessionToolContracts as o, BACKGROUND_SESSION_TOOL_PLUGIN_ID as r, extendBackgroundSessionDefinition as s, BACKGROUND_SESSION_START_TOOL_ID as t, BACKGROUND_SESSION_SESSION_KEY_PREFIX as u };
@@ -1,51 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- //#region src/platform/identity/random-id.ts
3
- function createRandomId() {
4
- return randomUUID();
5
- }
6
- //#endregion
7
- //#region src/core/application/background-session/control/background-session-control-input.ts
8
- function readBackgroundSessionObject(input, allowed, error) {
9
- if (input === null || typeof input !== "object" || Array.isArray(input)) throw error("background tool input must be an object");
10
- const record = input;
11
- const unknown = Object.keys(record).find((key) => !allowed.includes(key));
12
- if (unknown) throw error(`field is not allowed: ${unknown}`);
13
- return record;
14
- }
15
- function readBackgroundSessionString(value, name, error) {
16
- if (typeof value !== "string" || value.trim() === "") throw error(`${name} must be a non-empty string`);
17
- return value;
18
- }
19
- function readBackgroundSessionInteger(value, name, error) {
20
- if (!Number.isSafeInteger(value) || value < 1) throw error(`${name} must be a positive integer`);
21
- return value;
22
- }
23
- function readBackgroundSessionPhase(value, error) {
24
- const phases = [
25
- "queued",
26
- "running",
27
- "waiting",
28
- "input-required",
29
- "stopping",
30
- "stopped",
31
- "completed",
32
- "failed",
33
- "reconciliation-required"
34
- ];
35
- if (typeof value !== "string" || !phases.includes(value)) throw error(`phase must be one of ${phases.join(", ")}`);
36
- return value;
37
- }
38
- function readBackgroundSessionWaitInput(input, error) {
39
- const { delayMs, reason, until } = readBackgroundSessionObject(input, [
40
- "delayMs",
41
- "reason",
42
- "until"
43
- ], error);
44
- const args = {};
45
- if (delayMs !== void 0) args.delayMs = readBackgroundSessionInteger(delayMs, "delayMs", error);
46
- if (reason !== void 0) args.reason = readBackgroundSessionString(reason, "reason", error);
47
- if (until !== void 0) args.until = readBackgroundSessionString(until, "until", error);
48
- return args;
49
- }
50
- //#endregion
51
- export { readBackgroundSessionWaitInput as a, readBackgroundSessionString as i, readBackgroundSessionObject as n, createRandomId as o, readBackgroundSessionPhase as r, readBackgroundSessionInteger as t };