@cuylabs/agent-runtime-dapr 0.9.0 → 0.11.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.
@@ -0,0 +1,770 @@
1
+ import { AgentTaskPayload, SteeringResponse, FollowUpResponse, Tool, AgentTaskResult, AgentTaskRunner, Agent, AgentTaskRunnerOptions, AgentTaskObserver, FollowUpPolicy, AgentEvent, ApprovalRememberScope, HumanInputResponse, FollowUpStatus, QueuedFollowUpRecord, FollowUpDecisionAction } from '@cuylabs/agent-core';
2
+ import { h as DaprExecutionStore } from './store-BXBIDz40.js';
3
+ import { q as DaprPubSubEventBridge, v as DaprWorkflowApprovalRuntime, C as DaprWorkflowHumanInputRuntime, y as DaprWorkflowFollowUpRuntime, F as DaprWorkflowStarterLike, d as DaprAgentWorkflowRunRequest, e as DaprAgentWorkflowRunResult, x as DaprWorkflowEventRaiserLike, f as DaprAgentWorkflowSteerRequest, b as DaprAgentWorkflowFollowUpRequest, a as DaprAgentWorkflowHost, c as DaprAgentWorkflowHostOptions } from './workflow-host-D6W6fXoL.js';
4
+ import { EventBus } from '@cuylabs/agent-core/events';
5
+ import { b as DaprServiceInvoker, c as DaprServiceInvokerOptions } from './invoker-B6ikdYaz.js';
6
+ import { D as DaprWorkflowWorker, d as DaprWorkflowWorkerRuntime } from './worker-CXq0IFGX.js';
7
+ import { RuntimeDriver, RuntimeDriverContext, RuntimeJobRecord, WorkloadRuntime, RuntimeWorkloadRunner, WorkloadRuntimeOptions, RuntimeWorkloadContext } from '@cuylabs/agent-runtime';
8
+ import { c as DaprRuntimeDriverOptions, D as DaprExecutionStoreOptions } from './workflow-bridge-BcicHH1Y.js';
9
+ import { D as DaprWorkflowClient } from './client-UsEIzDF6.js';
10
+ import { Server } from 'node:http';
11
+
12
+ interface DaprJobTriggerHandler {
13
+ handleJobTriggerByName(jobName: string): Promise<boolean>;
14
+ }
15
+ interface DaprHttpJobHandlerOptions {
16
+ driver: DaprJobTriggerHandler;
17
+ handledStatus?: number;
18
+ unhandledStatus?: number;
19
+ errorStatus?: number;
20
+ onError?: (error: unknown, jobName: string) => void | Promise<void>;
21
+ }
22
+ interface DaprHttpJobHandlerResult {
23
+ status: number;
24
+ handled: boolean;
25
+ error?: unknown;
26
+ }
27
+ declare function createDaprHttpJobHandler(options: DaprHttpJobHandlerOptions): (jobName: string) => Promise<DaprHttpJobHandlerResult>;
28
+
29
+ declare class DaprRuntimeDriver<TPayload = unknown> implements RuntimeDriver<TPayload> {
30
+ readonly name = "dapr";
31
+ private readonly client;
32
+ private readonly jobsApi;
33
+ private readonly keyPrefix;
34
+ private context;
35
+ private started;
36
+ constructor(options: DaprRuntimeDriverOptions);
37
+ start(context: RuntimeDriverContext): Promise<void>;
38
+ stop(): Promise<void>;
39
+ private ensureStarted;
40
+ listJobs(): Promise<RuntimeJobRecord<TPayload>[]>;
41
+ getJob(jobId: string): Promise<RuntimeJobRecord<TPayload> | undefined>;
42
+ upsertJob(job: RuntimeJobRecord<TPayload>): Promise<RuntimeJobRecord<TPayload>>;
43
+ removeJob(jobId: string): Promise<boolean>;
44
+ /**
45
+ * Handle a Dapr scheduler callback routed to `/job/:name`.
46
+ * Returns false when the job name is not managed by this driver.
47
+ */
48
+ handleJobTriggerByName(jobName: string): Promise<boolean>;
49
+ private syncScheduledJob;
50
+ private fromDaprJobName;
51
+ private stateKeyForJob;
52
+ private readJob;
53
+ private writeJob;
54
+ private listJobsViaStateQuery;
55
+ private decodeStoredJob;
56
+ private deleteScheduledJob;
57
+ }
58
+
59
+ interface DaprHostedAgentInfo<TPayload extends AgentTaskPayload = AgentTaskPayload> {
60
+ readonly id: string;
61
+ readonly aliases: string[];
62
+ readonly description?: string;
63
+ readonly workflowHost: {
64
+ readonly workflowName: string;
65
+ /** Event bus for real-time streaming. `undefined` if not configured. */
66
+ readonly eventBus?: EventBus;
67
+ /** Dapr pub/sub bridge for multi-instance fan-out. `undefined` if not configured. */
68
+ readonly pubsubBridge?: DaprPubSubEventBridge;
69
+ /** Durable approval runtime for workflow-backed approvals, when configured. */
70
+ readonly approvalRuntime?: DaprWorkflowApprovalRuntime;
71
+ /** Durable human-input runtime for workflow-backed question tools, when configured. */
72
+ readonly humanInputRuntime?: DaprWorkflowHumanInputRuntime;
73
+ /** Durable follow-up runtime for workflow-backed next-turn control, when configured. */
74
+ readonly followUpRuntime?: DaprWorkflowFollowUpRuntime;
75
+ startTurn(client: DaprWorkflowStarterLike, request: DaprAgentWorkflowRunRequest): Promise<DaprAgentWorkflowRunResult>;
76
+ steerTurn?(client: DaprWorkflowEventRaiserLike, request: DaprAgentWorkflowSteerRequest): Promise<SteeringResponse>;
77
+ followUpTurn?(client: DaprWorkflowEventRaiserLike, request: DaprAgentWorkflowFollowUpRequest): Promise<FollowUpResponse>;
78
+ };
79
+ readonly runtimeBundle: {
80
+ readonly executionStore?: DaprExecutionStore<TPayload>;
81
+ };
82
+ }
83
+ interface DaprHostReadinessCheck {
84
+ readonly name: string;
85
+ readonly ok: boolean;
86
+ readonly detail?: string;
87
+ }
88
+ interface DaprHostReadinessStatus {
89
+ readonly ok: boolean;
90
+ readonly checks: readonly DaprHostReadinessCheck[];
91
+ }
92
+ interface DaprHostApp<TPayload extends AgentTaskPayload = AgentTaskPayload> {
93
+ isRunning(): boolean;
94
+ checkReadiness?(): DaprHostReadinessStatus | Promise<DaprHostReadinessStatus>;
95
+ listAgents(): readonly DaprHostedAgentInfo<TPayload>[];
96
+ getAgent(idOrAlias: string): DaprHostedAgentInfo<TPayload> | undefined;
97
+ runAgent(idOrAlias: string, payload: TPayload): Promise<unknown>;
98
+ handleScheduledJob(jobName: string): Promise<DaprHttpJobHandlerResult>;
99
+ }
100
+
101
+ /**
102
+ * Remote agent tool — wraps Dapr service invocation into an agent Tool.
103
+ *
104
+ * Creates a tool that a coordinator agent can use to invoke a remote
105
+ * agent running as its own Dapr app. Each remote agent has its own
106
+ * sidecar, workflow runtime, and state — making them independently
107
+ * durable and scalable.
108
+ *
109
+ * ## Modes
110
+ *
111
+ * ### Durable (default, `mode: "durable"`)
112
+ *
113
+ * 1. `POST /agents/run-durable` on the remote app → 202 `{ instanceId, sessionId }`
114
+ * 2. Poll `GET /agents/{id}/workflows/{instanceId}` until terminal status
115
+ * 3. Fetch result from `GET /agents/{id}/executions/{sessionId}`
116
+ *
117
+ * Both sides are fully durable workflows. If the remote agent crashes
118
+ * mid-turn, its Dapr workflow resumes from the last checkpoint — the
119
+ * coordinator just keeps polling.
120
+ *
121
+ * ### Direct (`mode: "direct"`)
122
+ *
123
+ * `POST /agents/run` — synchronous. Simple but not durable on the
124
+ * remote side. If the remote crashes, the call fails and the
125
+ * coordinator's workflow retries the whole tool call.
126
+ *
127
+ * ## Example
128
+ *
129
+ * ```typescript
130
+ * const researcherTool = createRemoteAgentTool({
131
+ * appId: "researcher",
132
+ * name: "researcher",
133
+ * description: "Research topics and gather information.",
134
+ * // mode: "durable" is the default — fully durable
135
+ * });
136
+ * ```
137
+ */
138
+
139
+ interface CreateRemoteAgentToolOptions {
140
+ /**
141
+ * The Dapr service invoker to use for HTTP requests.
142
+ * If omitted, a new invoker is created with default settings
143
+ * (or you can pass `invokerOptions` instead).
144
+ */
145
+ invoker?: DaprServiceInvoker;
146
+ /**
147
+ * Options for creating a `DaprServiceInvoker` when `invoker` is not
148
+ * provided. Ignored if `invoker` is set.
149
+ */
150
+ invokerOptions?: DaprServiceInvokerOptions;
151
+ /**
152
+ * The Dapr app ID of the remote agent.
153
+ * This must match the `--app-id` used when launching the remote agent
154
+ * with `dapr run`.
155
+ */
156
+ appId: string;
157
+ /**
158
+ * Tool name exposed to the LLM. The tool will be registered as
159
+ * `ask_{name}` (e.g., `ask_researcher`).
160
+ */
161
+ name: string;
162
+ /**
163
+ * Tool description exposed to the LLM. Explain what the remote agent
164
+ * is good at so the coordinator knows when to delegate.
165
+ */
166
+ description: string;
167
+ /**
168
+ * Execution mode for the remote agent.
169
+ *
170
+ * - `"durable"` (default) — Starts a durable workflow on the remote
171
+ * agent and polls for completion. Both coordinator and remote agent
172
+ * are independently durable. If the remote crashes, its workflow
173
+ * resumes from the last activity checkpoint.
174
+ *
175
+ * - `"direct"` — Synchronous `POST /agents/run`. Simpler but if the
176
+ * remote crashes, the whole call fails and the coordinator retries
177
+ * from scratch.
178
+ */
179
+ mode?: "durable" | "direct";
180
+ /**
181
+ * Polling interval for checking workflow completion (workflow mode only).
182
+ * Defaults to 2000ms.
183
+ */
184
+ pollIntervalMs?: number;
185
+ /**
186
+ * Maximum time to wait for the remote workflow to complete.
187
+ * Defaults to 5 minutes (300_000ms).
188
+ */
189
+ timeoutMs?: number;
190
+ }
191
+ /**
192
+ * Create a tool that invokes a remote Dapr agent via service invocation.
193
+ *
194
+ * In the default `"durable"` mode, both the coordinator and the remote
195
+ * agent run as independent durable workflows:
196
+ *
197
+ * ```
198
+ * Coordinator Workflow
199
+ * │
200
+ * ├─ activity: start remote workflow
201
+ * │ POST /agents/run-durable → 202 { instanceId, sessionId }
202
+ * │ checkpoint instanceId ✓
203
+ * │
204
+ * ├─ activity: poll remote workflow
205
+ * │ GET /agents/{id}/workflows/{instanceId}
206
+ * │ ...RUNNING → RUNNING → COMPLETED
207
+ * │ checkpoint completion ✓
208
+ * │
209
+ * ├─ activity: fetch remote result
210
+ * │ GET /agents/{id}/executions/{sessionId}
211
+ * │ checkpoint result ✓
212
+ * ```
213
+ *
214
+ * If the coordinator crashes after starting the remote workflow, it
215
+ * resumes polling (doesn't re-start the remote). If the remote crashes
216
+ * mid-turn, its own Dapr workflow resumes from the last activity
217
+ * checkpoint.
218
+ *
219
+ * @returns A `Tool.AnyInfo` that can be passed to `createAgent({ tools: [...] })`.
220
+ */
221
+ declare function createRemoteAgentTool(options: CreateRemoteAgentToolOptions): Tool.AnyInfo;
222
+
223
+ interface DaprWorkloadResultContext<TPayload = unknown, TResult = unknown> {
224
+ jobId: string;
225
+ payload: TPayload;
226
+ runtimeContext: RuntimeWorkloadContext;
227
+ result: TResult;
228
+ }
229
+ interface DaprWorkloadErrorContext<TPayload = unknown> {
230
+ jobId: string;
231
+ payload: TPayload;
232
+ runtimeContext: RuntimeWorkloadContext;
233
+ error: unknown;
234
+ message: string;
235
+ }
236
+ interface DaprWorkloadRuntimeOptions<TPayload = unknown, TResult = unknown> {
237
+ /** Dapr driver configuration (sidecar + state store + retries). */
238
+ driver: DaprRuntimeDriverOptions;
239
+ /**
240
+ * Optional runtime options excluding driver and execute.
241
+ * Use this to set concurrency/timeouts/logging behavior.
242
+ */
243
+ runtime?: Omit<WorkloadRuntimeOptions<TPayload>, "driver" | "execute">;
244
+ /**
245
+ * Domain workload executed for each scheduled or manually triggered job.
246
+ *
247
+ * This is the neutral seam between `agent-runtime` orchestration and
248
+ * application-specific work. `agent-core` task runners can plug in here,
249
+ * but so can any other job/workload adapter.
250
+ */
251
+ runWorkload: RuntimeWorkloadRunner<TPayload, TResult>;
252
+ /** Optional hook invoked after successful workload execution. */
253
+ onWorkloadResult?: (context: DaprWorkloadResultContext<TPayload, TResult>) => void | Promise<void>;
254
+ /** Optional hook invoked when workload execution fails. */
255
+ onWorkloadError?: (context: DaprWorkloadErrorContext<TPayload>) => void | Promise<void>;
256
+ }
257
+ interface DaprWorkloadRuntimeBundle<TPayload = unknown, TResult = unknown> {
258
+ runtime: WorkloadRuntime<TPayload>;
259
+ driver: DaprRuntimeDriver<TPayload>;
260
+ runWorkload: RuntimeWorkloadRunner<TPayload, TResult>;
261
+ handleDaprJob: (jobName: string) => Promise<DaprHttpJobHandlerResult>;
262
+ }
263
+ type DaprAgentTaskResultContext<TPayload extends AgentTaskPayload = AgentTaskPayload> = DaprWorkloadResultContext<TPayload, AgentTaskResult>;
264
+ type DaprAgentTaskErrorContext<TPayload extends AgentTaskPayload = AgentTaskPayload> = DaprWorkloadErrorContext<TPayload>;
265
+ interface DaprAgentRuntimeOptions<TPayload extends AgentTaskPayload = AgentTaskPayload> extends Omit<DaprWorkloadRuntimeOptions<TPayload, AgentTaskResult>, "runWorkload" | "onWorkloadResult" | "onWorkloadError"> {
266
+ /** Agent instance used for job execution. */
267
+ agent: Agent;
268
+ /**
269
+ * Optional explicit task runner. If omitted, one is created with
270
+ * createAgentTaskRunner(agent, taskRunnerOptions).
271
+ */
272
+ taskRunner?: AgentTaskRunner<TPayload>;
273
+ /** Options used when creating the default task runner. */
274
+ taskRunnerOptions?: AgentTaskRunnerOptions<TPayload>;
275
+ /**
276
+ * Persist neutral execution snapshots/checkpoints into Dapr state.
277
+ *
278
+ * Enabled by default when this helper creates the task runner. Disable it if
279
+ * you only want outer scheduling/orchestration durability.
280
+ */
281
+ persistExecutionState?: boolean;
282
+ /**
283
+ * Optional pre-created execution store. When omitted and
284
+ * `persistExecutionState !== false`, a store is created from the driver
285
+ * configuration.
286
+ */
287
+ executionStore?: DaprExecutionStore<TPayload>;
288
+ /**
289
+ * Optional execution store configuration override. This is only used when
290
+ * `executionStore` is not provided.
291
+ */
292
+ executionStoreOptions?: DaprExecutionStoreOptions;
293
+ /** Optional hook invoked after successful task execution. */
294
+ onTaskResult?: (context: DaprAgentTaskResultContext<TPayload>) => void | Promise<void>;
295
+ /** Optional hook invoked when task execution fails. */
296
+ onTaskError?: (context: DaprAgentTaskErrorContext<TPayload>) => void | Promise<void>;
297
+ }
298
+ interface DaprAgentRuntimeBundle<TPayload extends AgentTaskPayload = AgentTaskPayload> extends DaprWorkloadRuntimeBundle<TPayload, AgentTaskResult> {
299
+ runTask: AgentTaskRunner<TPayload>;
300
+ executionStore?: DaprExecutionStore<TPayload>;
301
+ }
302
+ /**
303
+ * Create a Dapr-backed runtime bundle for generic application workloads.
304
+ *
305
+ * This is the neutral Dapr implementation of the `agent-runtime` workload
306
+ * contract. Agent-specific helpers in this package are built on top of this.
307
+ */
308
+ declare function createDaprWorkloadRuntime<TPayload = unknown, TResult = unknown>(options: DaprWorkloadRuntimeOptions<TPayload, TResult>): DaprWorkloadRuntimeBundle<TPayload, TResult>;
309
+ /**
310
+ * Create a Dapr-backed runtime bundle for executing `agent-core` task
311
+ * workloads. This is a thin agent-specific wrapper over
312
+ * `createDaprWorkloadRuntime(...)`.
313
+ *
314
+ * This is the outer integration seam:
315
+ * - `createAgentTaskRunner(...)` adapts an `Agent` into a workload-shaped task
316
+ * - `createDaprWorkloadRuntime(...)` lets `agent-runtime` schedule and dispatch it
317
+ *
318
+ * Durable workflow decomposition is handled separately by the workflow host
319
+ * and `workflow/runtime.ts`.
320
+ */
321
+ declare function createDaprAgentRuntime<TPayload extends AgentTaskPayload = AgentTaskPayload>(options: DaprAgentRuntimeOptions<TPayload>): DaprAgentRuntimeBundle<TPayload>;
322
+
323
+ interface DaprHostRemoteRunRequest extends AgentTaskPayload {
324
+ agentId?: string;
325
+ }
326
+
327
+ /**
328
+ * Main HTTP router for a Dapr host app.
329
+ *
330
+ * This is a thin dispatcher that delegates to domain-specific routers
331
+ * under `routers/`. Each router returns `Response | undefined` — `undefined`
332
+ * means "not my route", so the chain continues.
333
+ */
334
+
335
+ type DaprHostHttpHandler = (request: Request) => Promise<Response>;
336
+ interface DaprHostHttpHandlerOptions<TPayload extends AgentTaskPayload = DaprHostRemoteRunRequest> {
337
+ app: DaprHostApp<TPayload>;
338
+ workflowClient?: DaprWorkflowClient;
339
+ }
340
+ /**
341
+ * Create a lightweight HTTP handler for a Dapr host app.
342
+ *
343
+ * Routes:
344
+ * - `GET /health` / `GET /healthz`
345
+ * - `GET /ready` / `GET /readyz`
346
+ * - `GET /agents`
347
+ * - `POST /job/:name`
348
+ * - `GET /dapr/subscribe`
349
+ * - `POST /dapr/:topic`
350
+ * - `POST /agents/run`
351
+ * - `POST /agents/run-durable`
352
+ * - `POST /agents/:id/run`
353
+ * - `POST /agents/:id/run-durable`
354
+ * - `GET /agents/:id/events/:sessionId` — SSE stream
355
+ * - `GET /agents/:id/executions/:sessionId`
356
+ * - `GET /agents/:id/executions/:sessionId/checkpoints`
357
+ * - `GET /agents/:id/workflows/:instanceId`
358
+ * - `POST /agents/:id/workflows/:instanceId/terminate`
359
+ * - `POST /agents/:id/workflows/:instanceId/pause`
360
+ * - `POST /agents/:id/workflows/:instanceId/resume`
361
+ * - `POST /agents/:id/workflows/:instanceId/purge`
362
+ * - `GET /agents/:id/inputs` / `:requestId` / `:requestId/respond`
363
+ * - `GET /agents/:id/approvals` / `:requestId` / `:requestId/respond`
364
+ * - `GET /agents/:id/follow-ups` / `:requestId` / `:requestId/respond`
365
+ * - `POST /agents/:id/steer`
366
+ * - `POST /agents/:id/follow-up`
367
+ * - Shorthand variants (`/agents/inputs`, `/agents/approvals`, etc.) for single-agent hosts
368
+ */
369
+ declare function createDaprHostHttpHandler<TPayload extends AgentTaskPayload = DaprHostRemoteRunRequest>(options: DaprHostHttpHandlerOptions<TPayload>): DaprHostHttpHandler;
370
+
371
+ interface DaprHttpServerOptions {
372
+ handler: DaprHostHttpHandler;
373
+ port: number;
374
+ host?: string;
375
+ }
376
+ interface DaprHostHttpServerOptions<TPayload extends AgentTaskPayload = DaprHostRemoteRunRequest> extends DaprHostHttpHandlerOptions<TPayload> {
377
+ port: number;
378
+ host?: string;
379
+ }
380
+ interface DaprHostHttpServer {
381
+ server: Server;
382
+ origin: string;
383
+ close(): Promise<void>;
384
+ }
385
+ declare function startDaprHttpServer(options: DaprHttpServerOptions): Promise<DaprHostHttpServer>;
386
+ declare function startDaprHostHttpServer<TPayload extends AgentTaskPayload = DaprHostRemoteRunRequest>(options: DaprHostHttpServerOptions<TPayload>): Promise<DaprHostHttpServer>;
387
+
388
+ interface DaprAgentRunnerOptions {
389
+ /** The agent to run. */
390
+ agent: Agent;
391
+ /**
392
+ * Unique identifier for this agent in the Dapr ecosystem.
393
+ * Defaults to `agent.name` if omitted.
394
+ */
395
+ name?: string;
396
+ /**
397
+ * Dapr sidecar HTTP endpoint.
398
+ * Defaults to `http://${DAPR_HOST ?? "127.0.0.1"}:${DAPR_HTTP_PORT ?? "3500"}`.
399
+ */
400
+ daprHttpEndpoint?: string;
401
+ /**
402
+ * Dapr gRPC host for the workflow runtime.
403
+ * Configure this directly on the provided `workflowRuntime`.
404
+ */
405
+ /**
406
+ * Dapr state store component name.
407
+ * Defaults to `"statestore"`.
408
+ */
409
+ stateStoreName?: string;
410
+ /**
411
+ * Dapr workflow component name.
412
+ * Defaults to `"dapr"`.
413
+ */
414
+ workflowComponent?: string;
415
+ /**
416
+ * Advanced Dapr driver options shared by the runtime bundle and readiness
417
+ * checks. Use this for API tokens, retry/timeouts, or custom fetch impls.
418
+ */
419
+ driverOptions?: Omit<DaprRuntimeDriverOptions, "stateStoreName" | "daprHttpEndpoint">;
420
+ /**
421
+ * The Dapr workflow runtime for registering workflows and activities.
422
+ * Must implement `start()`, `stop()`, `registerWorkflowWithName()`,
423
+ * and `registerActivityWithName()`.
424
+ *
425
+ * Pass `new WorkflowRuntime(...)` from `@dapr/dapr`.
426
+ */
427
+ workflowRuntime: DaprWorkflowWorkerRuntime;
428
+ /**
429
+ * Optional aliases for multi-agent lookups.
430
+ */
431
+ aliases?: string[];
432
+ /**
433
+ * Optional description for this agent.
434
+ */
435
+ description?: string;
436
+ /**
437
+ * Additional observers for execution lifecycle events.
438
+ * A logging observer is always included by default — pass extras here
439
+ * for persistence (e.g. `createDaprExecutionObserver()`), telemetry, etc.
440
+ */
441
+ observers?: AgentTaskObserver[];
442
+ /**
443
+ * Enable/disable the built-in console logging observer.
444
+ * Defaults to `true`.
445
+ */
446
+ logging?: boolean;
447
+ /**
448
+ * Prefix for log lines from the built-in logging observer.
449
+ * Defaults to `[${name}]`.
450
+ */
451
+ logPrefix?: string;
452
+ /**
453
+ * Override for workflow host options (advanced).
454
+ * Properties set here override the defaults derived from the runner config.
455
+ */
456
+ workflowHost?: Omit<DaprAgentWorkflowHostOptions, "agent" | "observers">;
457
+ /**
458
+ * Policy for deferred follow-up requests in durable mode.
459
+ */
460
+ followUpPolicy?: FollowUpPolicy;
461
+ /**
462
+ * Override for runtime bundle options (advanced).
463
+ * The `agent` and `driver` fields are always derived from the runner config.
464
+ */
465
+ runtimeOptions?: Omit<DaprAgentRuntimeOptions, "agent" | "driver" | "taskRunnerOptions"> & {
466
+ taskRunnerOptions?: Omit<NonNullable<DaprAgentRuntimeOptions["taskRunnerOptions"]>, "observers">;
467
+ };
468
+ }
469
+ interface DaprAgentServeOptions {
470
+ /** HTTP port. Defaults to `3000`. */
471
+ port?: number;
472
+ /** HTTP host. Defaults to all interfaces. */
473
+ host?: string;
474
+ /** Serve static assets from this directory before the built-in agent routes. */
475
+ staticDir?: string;
476
+ /** File served for `/` when `staticDir` is configured. Defaults to `index.html`. */
477
+ indexFile?: string;
478
+ /** Additional exact-match routes evaluated before static assets and built-in routes. */
479
+ extraRoutes?: readonly DaprAgentHttpRoute[];
480
+ }
481
+ interface DaprAgentHttpRoute {
482
+ /** Exact URL pathname match, e.g. `/` or `/ui/config.json`. */
483
+ path: string;
484
+ /** Allowed HTTP methods. Defaults to all methods. */
485
+ method?: string | readonly string[];
486
+ handler(request: Request): Response | Promise<Response>;
487
+ }
488
+ interface DaprAgentHttpHandlerOptions {
489
+ staticDir?: string;
490
+ indexFile?: string;
491
+ extraRoutes?: readonly DaprAgentHttpRoute[];
492
+ }
493
+ interface DaprAgentDurableRunOptions {
494
+ sessionId?: string;
495
+ system?: string;
496
+ workflowInstanceId?: string;
497
+ maxSteps?: number;
498
+ }
499
+ interface DaprAgentDurableRunResult {
500
+ agentId: string;
501
+ workflowName: string;
502
+ sessionId: string;
503
+ instanceId: string;
504
+ }
505
+ interface DaprAgentRunner {
506
+ /** Agent name / ID. */
507
+ readonly name: string;
508
+ /** The underlying agent instance. */
509
+ readonly agent: Agent;
510
+ /** The underlying workflow host. */
511
+ readonly workflowHost: DaprAgentWorkflowHost;
512
+ /** The underlying runtime bundle (scheduling, workload adapter, execution store). */
513
+ readonly runtimeBundle: DaprAgentRuntimeBundle;
514
+ /** The underlying workflow worker. */
515
+ readonly worker: DaprWorkflowWorker;
516
+ /** The workflow client for managing workflow instances. */
517
+ readonly workflowClient: DaprWorkflowClient;
518
+ /**
519
+ * Return a capabilities patch describing the Dapr runtime backing.
520
+ *
521
+ * Structurally compatible with `AgentServerCapabilitiesPatch` from
522
+ * `@cuylabs/agent-server`. Used internally by
523
+ * `createDaprAgentServerAdapter(...)` and available for custom
524
+ * composition if you need to layer additional transport metadata.
525
+ *
526
+ * @example
527
+ * ```ts
528
+ * import { createDaprAgentServerAdapter } from "@cuylabs/agent-runtime-dapr";
529
+ * const adapter = createDaprAgentServerAdapter(runner);
530
+ * ```
531
+ */
532
+ agentServerCapabilities(): {
533
+ runtime: {
534
+ execution: "local";
535
+ orchestration: "agent-runtime-dapr";
536
+ durability: "workflow";
537
+ dapr: {
538
+ available: true;
539
+ delegatedTurns: false;
540
+ workflowBacked: true;
541
+ };
542
+ };
543
+ };
544
+ /**
545
+ * Start the runtime and workflow worker.
546
+ * Must be called before `serve()` or manual invocation.
547
+ */
548
+ start(): Promise<void>;
549
+ /**
550
+ * Start the HTTP server and block until SIGINT/SIGTERM.
551
+ * Calls `start()` internally if not already started.
552
+ */
553
+ serve(options?: DaprAgentServeOptions): Promise<void>;
554
+ /**
555
+ * Build the HTTP handler for this runner.
556
+ * Useful when embedding the Dapr host routes inside a custom server.
557
+ */
558
+ createHttpHandler(options?: DaprAgentHttpHandlerOptions): DaprHostHttpHandler;
559
+ /**
560
+ * Run a task directly (synchronous execution, no workflow).
561
+ * The agent must be started first.
562
+ */
563
+ run(message: string, options?: {
564
+ sessionId?: string;
565
+ }): Promise<AgentTaskResult>;
566
+ /**
567
+ * Start a durable workflow-backed task and return its identifiers.
568
+ * The agent must be started first.
569
+ */
570
+ runDurable(message: string, options?: DaprAgentDurableRunOptions): Promise<DaprAgentDurableRunResult>;
571
+ /**
572
+ * Gracefully shut down the runner.
573
+ */
574
+ stop(): Promise<void>;
575
+ }
576
+ interface DaprMultiAgentRunnerAgentConfig {
577
+ /** The agent instance. */
578
+ agent: Agent;
579
+ /** Unique identifier for this agent in the Dapr ecosystem. */
580
+ name: string;
581
+ /** Optional aliases for multi-agent lookups. */
582
+ aliases?: string[];
583
+ /** Optional description for this agent. */
584
+ description?: string;
585
+ /** Policy for deferred follow-up requests for this hosted agent. */
586
+ followUpPolicy?: FollowUpPolicy;
587
+ }
588
+ interface DaprMultiAgentRunnerOptions {
589
+ /** Agent configurations. */
590
+ agents: DaprMultiAgentRunnerAgentConfig[];
591
+ /** Shared Dapr workflow runtime. */
592
+ workflowRuntime: DaprWorkflowWorkerRuntime;
593
+ /** Dapr sidecar HTTP endpoint. */
594
+ daprHttpEndpoint?: string;
595
+ /** Dapr state store component name. Defaults to `"statestore"`. */
596
+ stateStoreName?: string;
597
+ /** Advanced Dapr driver options shared by all hosted runtimes. */
598
+ driverOptions?: Omit<DaprRuntimeDriverOptions, "stateStoreName" | "daprHttpEndpoint">;
599
+ /** Dapr workflow component name. Defaults to `"dapr"`. */
600
+ workflowComponent?: string;
601
+ /** Additional observers applied to all agents. */
602
+ observers?: AgentTaskObserver[];
603
+ /** Enable/disable built-in console logging. Defaults to `true`. */
604
+ logging?: boolean;
605
+ }
606
+ interface DaprMultiAgentRunner {
607
+ /** Start all runtimes and the shared workflow worker. */
608
+ start(): Promise<void>;
609
+ /** Start HTTP server and block until SIGINT/SIGTERM. Calls `start()` internally. */
610
+ serve(options?: DaprAgentServeOptions): Promise<void>;
611
+ /** Build the HTTP handler for this multi-agent runner. */
612
+ createHttpHandler(options?: DaprAgentHttpHandlerOptions): DaprHostHttpHandler;
613
+ /** Gracefully shut down. */
614
+ stop(): Promise<void>;
615
+ }
616
+
617
+ type AgentServerCapabilitiesPatch = Record<string, unknown>;
618
+ interface AppToolInfo {
619
+ id: string;
620
+ }
621
+ interface AppSkillInfo {
622
+ name: string;
623
+ description?: string;
624
+ path?: string;
625
+ }
626
+ interface AppSubAgentProfileInfo {
627
+ name: string;
628
+ description?: string;
629
+ }
630
+ interface AppPluginCommandInfo {
631
+ pluginId?: string;
632
+ name: string;
633
+ alias: string[];
634
+ summary: string;
635
+ metadata?: unknown;
636
+ }
637
+ interface AppModelState {
638
+ label: string;
639
+ switchable: boolean;
640
+ }
641
+ type AppModelSwitchResult = {
642
+ ok: true;
643
+ label: string;
644
+ } | {
645
+ ok: false;
646
+ error: string;
647
+ };
648
+ type AppRuntimeStatusSnapshot = {
649
+ session: Record<string, unknown>;
650
+ model: Record<string, unknown>;
651
+ context: unknown;
652
+ };
653
+ type AppContextCompactionResult = unknown;
654
+ type AppUndoResult = unknown;
655
+ interface AppFollowUpListOptions {
656
+ sessionId?: string;
657
+ sourceTurnId?: string;
658
+ status?: FollowUpStatus | FollowUpStatus[];
659
+ }
660
+ type ResolveInputRequestPayload = {
661
+ kind: "approval";
662
+ action: "allow" | "deny" | "remember";
663
+ feedback?: string;
664
+ rememberScope?: ApprovalRememberScope;
665
+ } | {
666
+ kind: "human";
667
+ response: HumanInputResponse;
668
+ };
669
+ interface AgentServerPluginCommand {
670
+ pluginId?: string;
671
+ name: string;
672
+ alias: string[];
673
+ summary: string;
674
+ metadata?: unknown;
675
+ execute(args: string): Promise<string | null> | string | null;
676
+ }
677
+ interface AgentServerAdapter {
678
+ readonly cwd: string;
679
+ getCapabilities?(): AgentServerCapabilitiesPatch;
680
+ getModelState?(): Promise<AppModelState> | AppModelState;
681
+ switchModel?(spec: string): Promise<AppModelSwitchResult> | AppModelSwitchResult;
682
+ getSessionRuntimeStatus?(sessionId: string): Promise<AppRuntimeStatusSnapshot> | AppRuntimeStatusSnapshot;
683
+ listTools?(): Promise<AppToolInfo[]> | AppToolInfo[];
684
+ listSkills?(): Promise<AppSkillInfo[]> | AppSkillInfo[];
685
+ listSubAgents?(): Promise<AppSubAgentProfileInfo[]> | AppSubAgentProfileInfo[];
686
+ compactSessionContext?(sessionId: string): Promise<AppContextCompactionResult> | AppContextCompactionResult;
687
+ undoSessionTurn?(sessionId: string): Promise<AppUndoResult> | AppUndoResult;
688
+ getSessionTurnDiff?(sessionId: string): Promise<string | null> | string | null;
689
+ chat(sessionId: string, message: string, options?: {
690
+ system?: string;
691
+ abort?: AbortSignal;
692
+ }): AsyncGenerator<AgentEvent>;
693
+ steer?(request: {
694
+ sessionId: string;
695
+ turnId: string;
696
+ message: string;
697
+ }): SteeringResponse;
698
+ followUp?(request: {
699
+ sessionId: string;
700
+ turnId: string;
701
+ message: string;
702
+ }): FollowUpResponse;
703
+ interruptTurn?(request: {
704
+ sessionId: string;
705
+ turnId: string;
706
+ }): void | Promise<void>;
707
+ respondToInputRequest?(requestId: string, payload: ResolveInputRequestPayload): void | Promise<void>;
708
+ listFollowUps?(options?: AppFollowUpListOptions): Promise<QueuedFollowUpRecord[]> | QueuedFollowUpRecord[];
709
+ getFollowUp?(followUpId: string): Promise<QueuedFollowUpRecord | null> | QueuedFollowUpRecord | null;
710
+ resolveFollowUp?(followUpId: string, action: FollowUpDecisionAction): Promise<QueuedFollowUpRecord | null> | QueuedFollowUpRecord | null;
711
+ listSessions(): ReturnType<Agent["listSessions"]>;
712
+ deleteSession(sessionId: string): Promise<boolean>;
713
+ getSessionStorage(): ReturnType<ReturnType<Agent["getSessionManager"]>["getStorage"]>;
714
+ listPluginCommands?(): Promise<AppPluginCommandInfo[]> | AppPluginCommandInfo[];
715
+ executePluginCommand?(name: string, args: string): Promise<string | null> | string | null;
716
+ }
717
+ interface CreateDaprAgentServerAdapterOptions {
718
+ pluginCommands?: AgentServerPluginCommand[];
719
+ currentModelLabel?: string;
720
+ switchModel?: (spec: string) => Promise<AppModelSwitchResult> | AppModelSwitchResult;
721
+ listSkills?: () => Promise<AppSkillInfo[]> | AppSkillInfo[];
722
+ listSubAgents?: () => Promise<AppSubAgentProfileInfo[]> | AppSubAgentProfileInfo[];
723
+ capabilities?: AgentServerCapabilitiesPatch;
724
+ }
725
+ declare function createDaprAgentServerAdapter(runner: DaprAgentRunner, options?: CreateDaprAgentServerAdapterOptions): AgentServerAdapter;
726
+
727
+ /**
728
+ * Create a Dapr agent runner — the single-call composition of all pieces
729
+ * needed to run an agent with Dapr durability.
730
+ *
731
+ * Equivalent to Diagrid's `DaprWorkflowAgentRunner`. Internally creates:
732
+ * - Workflow host (Dapr workflow registration + turn state management)
733
+ * - Runtime bundle (scheduling + workload adapter + execution store)
734
+ * - Workflow worker (gRPC worker for Dapr workflow engine)
735
+ * - Workflow client (HTTP client for managing workflow instances)
736
+ * - HTTP server (on `serve()`)
737
+ *
738
+ * @example
739
+ * ```ts
740
+ * const runner = createDaprAgentRunner({
741
+ * agent,
742
+ * name: "my-agent",
743
+ * workflowRuntime: new WorkflowRuntime({ daprHost: "127.0.0.1", daprPort: "50001" }),
744
+ * });
745
+ *
746
+ * await runner.serve({ port: 3000 });
747
+ * ```
748
+ */
749
+ declare function createDaprAgentRunner(options: DaprAgentRunnerOptions): DaprAgentRunner;
750
+
751
+ /**
752
+ * Create a multi-agent Dapr runner — multiple agents sharing a single
753
+ * workflow worker, HTTP server, and Dapr sidecar.
754
+ *
755
+ * @example
756
+ * ```ts
757
+ * const runner = createDaprMultiAgentRunner({
758
+ * agents: [
759
+ * { agent: greeter, name: "greeter" },
760
+ * { agent: calculator, name: "calculator" },
761
+ * ],
762
+ * workflowRuntime: new WorkflowRuntime(),
763
+ * });
764
+ *
765
+ * await runner.serve({ port: 3000 });
766
+ * ```
767
+ */
768
+ declare function createDaprMultiAgentRunner(options: DaprMultiAgentRunnerOptions): DaprMultiAgentRunner;
769
+
770
+ export { type DaprWorkloadRuntimeBundle as A, type DaprWorkloadRuntimeOptions as B, type CreateDaprAgentServerAdapterOptions as C, type DaprAgentDurableRunOptions as D, createDaprAgentRunner as E, createDaprAgentRuntime as F, createDaprAgentServerAdapter as G, createDaprHostHttpHandler as H, createDaprHttpJobHandler as I, createDaprMultiAgentRunner as J, createDaprWorkloadRuntime as K, createRemoteAgentTool as L, startDaprHostHttpServer as M, type DaprAgentHttpHandlerOptions as N, type DaprAgentHttpRoute as O, type DaprHostHttpHandler as P, type DaprHttpServerOptions as Q, startDaprHttpServer as R, type CreateRemoteAgentToolOptions as a, type DaprAgentDurableRunResult as b, type DaprAgentRunner as c, type DaprAgentRunnerOptions as d, type DaprAgentRuntimeBundle as e, type DaprAgentRuntimeOptions as f, type DaprAgentServeOptions as g, type DaprAgentTaskErrorContext as h, type DaprAgentTaskResultContext as i, type DaprHostApp as j, type DaprHostHttpHandlerOptions as k, type DaprHostHttpServer as l, type DaprHostHttpServerOptions as m, type DaprHostReadinessCheck as n, type DaprHostReadinessStatus as o, type DaprHostRemoteRunRequest as p, type DaprHostedAgentInfo as q, type DaprHttpJobHandlerOptions as r, type DaprHttpJobHandlerResult as s, type DaprJobTriggerHandler as t, type DaprMultiAgentRunner as u, type DaprMultiAgentRunnerAgentConfig as v, type DaprMultiAgentRunnerOptions as w, DaprRuntimeDriver as x, type DaprWorkloadErrorContext as y, type DaprWorkloadResultContext as z };