@rivus/agent 0.5.0 → 0.5.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.
- package/dist/index.d.ts +7 -0
- package/dist/index.js +27 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ interface AgentHarnessOptions {
|
|
|
18
18
|
readonly initialEvents?: ReadonlyArray<AgentDomainEvent>;
|
|
19
19
|
readonly initialRunStates?: ReadonlyArray<AgentRunState>;
|
|
20
20
|
readonly loop: AgentLoop;
|
|
21
|
+
readonly runTimeoutMs?: number;
|
|
21
22
|
readonly runIds: RunIdGenerator;
|
|
22
23
|
}
|
|
23
24
|
interface PromptCommand {
|
|
@@ -1902,14 +1903,17 @@ declare function createFeishuEventHandlers(options: FeishuEventHandlersOptions):
|
|
|
1902
1903
|
//#region src/composition/feishu-agent-runtime.d.ts
|
|
1903
1904
|
interface FeishuAgentRuntimeOptions {
|
|
1904
1905
|
readonly agentId: string;
|
|
1906
|
+
readonly botOpenId?: string;
|
|
1905
1907
|
readonly clock: AgentClock;
|
|
1906
1908
|
readonly eventSinks?: ReadonlyArray<AgentDomainEventSink>;
|
|
1909
|
+
readonly inboxRepository?: FeishuInboxRepository;
|
|
1907
1910
|
readonly initialEvents?: ReadonlyArray<AgentDomainEvent>;
|
|
1908
1911
|
readonly initialRunStates?: ReadonlyArray<AgentRunState>;
|
|
1909
1912
|
readonly loop: AgentLoop;
|
|
1910
1913
|
readonly prepareRun?: (run: FeishuAgentRunPreparation) => Effect.Effect<void, unknown>;
|
|
1911
1914
|
readonly periodicFlush?: FeishuPeriodicFlushSupervisor;
|
|
1912
1915
|
readonly publish: (action: FeishuStreamAction) => Effect.Effect<void, unknown>;
|
|
1916
|
+
readonly runTimeoutMs?: number;
|
|
1913
1917
|
readonly runIds: RunIdGenerator;
|
|
1914
1918
|
}
|
|
1915
1919
|
interface FeishuPeriodicFlushSupervisor {
|
|
@@ -2155,6 +2159,7 @@ declare function createJsonlAgentEventLog(options: JsonlAgentEventLogOptions): A
|
|
|
2155
2159
|
type ConfiguredRivusDaemonBootstrapRequest = ConfiguredFeishuOpenApiRequest;
|
|
2156
2160
|
type ConfiguredRivusDaemonBootstrapResponse = ConfiguredFeishuOpenApiResponse;
|
|
2157
2161
|
interface ConfiguredRivusDaemonBootstrapOptions {
|
|
2162
|
+
readonly botOpenId?: string;
|
|
2158
2163
|
readonly cardTargets: FeishuCardTargetRegistry;
|
|
2159
2164
|
readonly clock: AgentClock;
|
|
2160
2165
|
readonly config: RivusDaemonConfig;
|
|
@@ -2164,10 +2169,12 @@ interface ConfiguredRivusDaemonBootstrapOptions {
|
|
|
2164
2169
|
readonly flushIntervalMs?: number;
|
|
2165
2170
|
readonly initialEvents?: ReadonlyArray<AgentDomainEvent>;
|
|
2166
2171
|
readonly initialRunStates?: ReadonlyArray<AgentRunState>;
|
|
2172
|
+
readonly inboxRepository?: FeishuInboxRepository;
|
|
2167
2173
|
readonly loop: AgentLoop;
|
|
2168
2174
|
readonly onWorkerError?: (error: unknown) => void | Promise<void>;
|
|
2169
2175
|
readonly request: (request: ConfiguredRivusDaemonBootstrapRequest) => Effect.Effect<ConfiguredRivusDaemonBootstrapResponse, unknown>;
|
|
2170
2176
|
readonly runIds: RunIdGenerator;
|
|
2177
|
+
readonly runTimeoutMs?: number;
|
|
2171
2178
|
readonly sleep: (ms: number) => Effect.Effect<void, unknown>;
|
|
2172
2179
|
readonly websocketClient: FeishuWebSocketClient;
|
|
2173
2180
|
readonly workerIntervalMs?: number;
|
package/dist/index.js
CHANGED
|
@@ -1083,6 +1083,7 @@ function createAgentRunUpdateHandler(handle) {
|
|
|
1083
1083
|
});
|
|
1084
1084
|
}
|
|
1085
1085
|
function createAgentHarness(options) {
|
|
1086
|
+
if (options.runTimeoutMs !== void 0 && (!Number.isSafeInteger(options.runTimeoutMs) || options.runTimeoutMs < 1)) throw new Error("Agent run timeout must be a positive integer");
|
|
1086
1087
|
let activeRun;
|
|
1087
1088
|
let activeCancellation;
|
|
1088
1089
|
let activeRunState;
|
|
@@ -1223,7 +1224,7 @@ function createAgentHarness(options) {
|
|
|
1223
1224
|
sessionKey: command.sessionKey,
|
|
1224
1225
|
text: command.text
|
|
1225
1226
|
};
|
|
1226
|
-
|
|
1227
|
+
const loop = Effect.try({
|
|
1227
1228
|
try: () => options.loop.run(loopInput),
|
|
1228
1229
|
catch: (error) => error
|
|
1229
1230
|
}).pipe(Effect.flatMap((loopStream) => Stream.runForEach(loopStream.pipe(Stream.interruptWhenDeferred(cancellation.deferred)), (event) => Effect.gen(function* () {
|
|
@@ -1244,6 +1245,16 @@ function createAgentHarness(options) {
|
|
|
1244
1245
|
return yield* Effect.fail(new AgentLoopFailed(runId, errorMessage, error, state));
|
|
1245
1246
|
});
|
|
1246
1247
|
}));
|
|
1248
|
+
yield* options.runTimeoutMs === void 0 ? loop : Effect.raceFirst(loop, Effect.sleep(options.runTimeoutMs).pipe(Effect.flatMap(() => {
|
|
1249
|
+
const request = {
|
|
1250
|
+
reason: `run timed out after ${options.runTimeoutMs}ms`,
|
|
1251
|
+
runId,
|
|
1252
|
+
sessionKey: command.sessionKey
|
|
1253
|
+
};
|
|
1254
|
+
cancellation.requested = request;
|
|
1255
|
+
cancellation.abortController.abort(request);
|
|
1256
|
+
return Deferred.succeed(cancellation.deferred, request);
|
|
1257
|
+
}), Effect.asVoid));
|
|
1247
1258
|
if (cancellation.requested) {
|
|
1248
1259
|
const cancelledAt = yield* options.clock.now;
|
|
1249
1260
|
yield* record({
|
|
@@ -2626,10 +2637,12 @@ function createFeishuAgentRuntime(options) {
|
|
|
2626
2637
|
...options.initialEvents ? { initialEvents: options.initialEvents } : {},
|
|
2627
2638
|
...options.initialRunStates ? { initialRunStates: options.initialRunStates } : {},
|
|
2628
2639
|
loop: options.loop,
|
|
2640
|
+
...options.runTimeoutMs === void 0 ? {} : { runTimeoutMs: options.runTimeoutMs },
|
|
2629
2641
|
runIds: options.runIds
|
|
2630
2642
|
});
|
|
2631
2643
|
const daemon = createFeishuAgentDaemon({
|
|
2632
2644
|
agentId: options.agentId,
|
|
2645
|
+
...options.botOpenId ? { botOpenId: options.botOpenId } : {},
|
|
2633
2646
|
harness,
|
|
2634
2647
|
...options.prepareRun ? { prepareRun: options.prepareRun } : {},
|
|
2635
2648
|
publish: options.publish
|
|
@@ -2638,7 +2651,10 @@ function createFeishuAgentRuntime(options) {
|
|
|
2638
2651
|
let lastHandled;
|
|
2639
2652
|
const queue = createFeishuMessageQueue({
|
|
2640
2653
|
handleMessage: (payload, handleOptions) => {
|
|
2641
|
-
const effect = daemon.handleMessage(payload, handleOptions).pipe(Effect.tap((result) => describeFeishuMessageIntake(payload, {
|
|
2654
|
+
const effect = daemon.handleMessage(payload, handleOptions).pipe(Effect.tap((result) => describeFeishuMessageIntake(payload, {
|
|
2655
|
+
agentId: options.agentId,
|
|
2656
|
+
...options.botOpenId ? { botOpenId: options.botOpenId } : {}
|
|
2657
|
+
}).pipe(Effect.tap((intake) => Effect.gen(function* () {
|
|
2642
2658
|
const observedAt = yield* options.clock.now;
|
|
2643
2659
|
lastHandled = {
|
|
2644
2660
|
intake,
|
|
@@ -2649,6 +2665,7 @@ function createFeishuAgentRuntime(options) {
|
|
|
2649
2665
|
})))));
|
|
2650
2666
|
return options.periodicFlush ? options.periodicFlush.withPeriodicFlush(effect) : effect;
|
|
2651
2667
|
},
|
|
2668
|
+
...options.inboxRepository ? { repository: options.inboxRepository } : {},
|
|
2652
2669
|
shouldRetryError: isRetryableFeishuMessageError
|
|
2653
2670
|
});
|
|
2654
2671
|
const worker = createFeishuMessageWorker({ queue });
|
|
@@ -2675,7 +2692,10 @@ function createFeishuAgentRuntime(options) {
|
|
|
2675
2692
|
...lastHandled ? { lastHandled } : {}
|
|
2676
2693
|
}),
|
|
2677
2694
|
replayReceiveMessage: (payload, replayOptions) => Effect.gen(function* () {
|
|
2678
|
-
const intake = yield* describeFeishuMessageIntake(payload, {
|
|
2695
|
+
const intake = yield* describeFeishuMessageIntake(payload, {
|
|
2696
|
+
agentId: options.agentId,
|
|
2697
|
+
...options.botOpenId ? { botOpenId: options.botOpenId } : {}
|
|
2698
|
+
});
|
|
2679
2699
|
return {
|
|
2680
2700
|
accepted: yield* observedQueue.accept(payload, replayOptions),
|
|
2681
2701
|
drained: yield* worker.drainAvailable(),
|
|
@@ -3114,6 +3134,7 @@ function isRecord$2(value) {
|
|
|
3114
3134
|
//#endregion
|
|
3115
3135
|
//#region src/composition/rivus-daemon-bootstrap.ts
|
|
3116
3136
|
const DEFAULT_WORKER_INTERVAL_MS$1 = 250;
|
|
3137
|
+
const DEFAULT_RUN_TIMEOUT_MS = 900 * 1e3;
|
|
3117
3138
|
function restoreConfiguredRivusDaemonBootstrap(options) {
|
|
3118
3139
|
return options.eventLog.readAll().pipe(Effect.map((events) => createConfiguredRivusDaemonBootstrap({
|
|
3119
3140
|
...options,
|
|
@@ -3139,14 +3160,17 @@ function createConfiguredRivusDaemonBootstrap(options) {
|
|
|
3139
3160
|
const periodicFlush = createPeriodicFlush(options, publisher);
|
|
3140
3161
|
const runtime = createFeishuAgentRuntime({
|
|
3141
3162
|
agentId: options.config.agentId,
|
|
3163
|
+
...options.botOpenId ? { botOpenId: options.botOpenId } : {},
|
|
3142
3164
|
clock: options.clock,
|
|
3143
3165
|
eventSinks: [options.eventLog],
|
|
3166
|
+
...options.inboxRepository ? { inboxRepository: options.inboxRepository } : {},
|
|
3144
3167
|
...options.initialEvents ? { initialEvents: options.initialEvents } : {},
|
|
3145
3168
|
...options.initialRunStates ? { initialRunStates: options.initialRunStates } : {},
|
|
3146
3169
|
loop: options.loop,
|
|
3147
3170
|
periodicFlush,
|
|
3148
3171
|
prepareRun,
|
|
3149
3172
|
publish: (action) => publisher.publish(action),
|
|
3173
|
+
runTimeoutMs: options.runTimeoutMs ?? DEFAULT_RUN_TIMEOUT_MS,
|
|
3150
3174
|
runIds: options.runIds
|
|
3151
3175
|
});
|
|
3152
3176
|
const websocketTransport = createFeishuWebSocketDaemon({
|