@cuylabs/agent-runtime-dapr 0.9.0 → 0.10.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.
@@ -1,8 +1,12 @@
1
- import { AgentWorkflowTurnState, Agent, AgentTaskObserver, AgentTaskPayload, AgentTaskResult, AgentTaskRunner, AgentTaskRunnerOptions } from '@cuylabs/agent-core';
2
- import { h as DaprExecutionStore } from './store-pRLGfYhN.js';
3
- import { DaprAgentTurnWorkflowActivityNames, DaprAgentTurnWorkflowDefinition, StartDaprWorkflowOptions, DaprStartWorkflowResponse, CreateDaprAgentTurnWorkflowKitOptions, DaprWorkflowClient } from './workflow/index.js';
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-B1jvz9DG.js';
6
+ import { D as DaprWorkflowWorker, d as DaprWorkflowWorkerRuntime } from './worker-CXq0IFGX.js';
4
7
  import { RuntimeDriver, RuntimeDriverContext, RuntimeJobRecord, WorkloadRuntime, RuntimeWorkloadRunner, WorkloadRuntimeOptions, RuntimeWorkloadContext } from '@cuylabs/agent-runtime';
5
- import { c as DaprRuntimeDriverOptions, a as DaprExecutionStoreOptions } from './workflow-bridge-C8Z1yr0Y.js';
8
+ import { c as DaprRuntimeDriverOptions, D as DaprExecutionStoreOptions } from './workflow-bridge-BcicHH1Y.js';
9
+ import { D as DaprWorkflowClient } from './client-UsEIzDF6.js';
6
10
  import { Server } from 'node:http';
7
11
 
8
12
  interface DaprJobTriggerHandler {
@@ -32,6 +36,7 @@ declare class DaprRuntimeDriver<TPayload = unknown> implements RuntimeDriver<TPa
32
36
  constructor(options: DaprRuntimeDriverOptions);
33
37
  start(context: RuntimeDriverContext): Promise<void>;
34
38
  stop(): Promise<void>;
39
+ private ensureStarted;
35
40
  listJobs(): Promise<RuntimeJobRecord<TPayload>[]>;
36
41
  getJob(jobId: string): Promise<RuntimeJobRecord<TPayload> | undefined>;
37
42
  upsertJob(job: RuntimeJobRecord<TPayload>): Promise<RuntimeJobRecord<TPayload>>;
@@ -44,79 +49,32 @@ declare class DaprRuntimeDriver<TPayload = unknown> implements RuntimeDriver<TPa
44
49
  private syncScheduledJob;
45
50
  private fromDaprJobName;
46
51
  private stateKeyForJob;
47
- private stateKeyForIndex;
48
52
  private readJob;
49
53
  private writeJob;
50
- private readIndex;
51
- private writeIndex;
52
- private addToIndex;
53
- private removeFromIndex;
54
54
  private listJobsViaStateQuery;
55
- private listJobsFromIndex;
56
55
  private decodeStoredJob;
57
- private updateIndex;
58
56
  private deleteScheduledJob;
59
57
  }
60
58
 
61
- interface DaprWorkflowRuntimeRegistrar {
62
- registerWorkflowWithName(name: string, workflow: DaprAgentTurnWorkflowDefinition): this;
63
- registerActivityWithName<TInput, TOutput>(name: string, handler: (context: unknown, input: TInput) => Promise<TOutput> | TOutput): this;
64
- }
65
- interface DaprWorkflowStarterLike {
66
- startWorkflow<TInput = unknown>(workflowName: string, options?: StartDaprWorkflowOptions<TInput>): Promise<DaprStartWorkflowResponse>;
67
- }
68
- interface DaprAgentWorkflowRunRequest {
69
- message: string;
70
- sessionId?: string;
71
- system?: string;
72
- workflowInstanceId?: string;
73
- maxSteps?: number;
74
- }
75
- interface DaprAgentWorkflowRunResult {
76
- sessionId: string;
77
- workflowInstanceId: string;
78
- initialState: AgentWorkflowTurnState;
79
- }
80
- interface DaprAgentWorkflowHostOptions {
81
- agent: Agent;
82
- workflowName?: string;
83
- activityNames?: Partial<DaprAgentTurnWorkflowActivityNames>;
84
- mcpTools?: CreateDaprAgentTurnWorkflowKitOptions["modelStepActivity"]["mcpTools"];
85
- /**
86
- * Optional observers that receive lifecycle notifications during
87
- * workflow execution. The same observers used on the direct (`/agents/run`)
88
- * path — `DaprExecutionObserver`, `createDaprLoggingObserver`, etc. —
89
- * work here too via an internal bridge.
90
- */
91
- observers?: AgentTaskObserver[];
92
- createAbortSignal?: () => AbortSignal;
93
- now?: () => string;
94
- }
95
- interface DaprAgentWorkflowHost {
96
- workflowName: string;
97
- activityNames: DaprAgentTurnWorkflowActivityNames;
98
- register<TRuntime extends DaprWorkflowRuntimeRegistrar>(runtime: TRuntime): TRuntime;
99
- createInitialState(request: DaprAgentWorkflowRunRequest): Promise<DaprAgentWorkflowRunResult>;
100
- startTurn(client: DaprWorkflowStarterLike, request: DaprAgentWorkflowRunRequest): Promise<DaprAgentWorkflowRunResult>;
101
- }
102
- /**
103
- * Create the host-side Dapr workflow helper for an `Agent`.
104
- *
105
- * This wires the extracted workflow kit to a `WorkflowRuntime`-compatible
106
- * object and provides a safe `startTurn()` helper that creates/loads the
107
- * session, appends the initial user message, snapshots the durable turn
108
- * state, and starts the workflow instance.
109
- */
110
- declare function createDaprAgentWorkflowHost(options: DaprAgentWorkflowHostOptions): DaprAgentWorkflowHost;
111
- declare function startDaprAgentWorkflowTurn(client: DaprWorkflowClient, host: DaprAgentWorkflowHost, request: DaprAgentWorkflowRunRequest): Promise<DaprAgentWorkflowRunResult>;
112
-
113
59
  interface DaprHostedAgentInfo<TPayload extends AgentTaskPayload = AgentTaskPayload> {
114
60
  readonly id: string;
115
61
  readonly aliases: string[];
116
62
  readonly description?: string;
117
63
  readonly workflowHost: {
118
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;
119
75
  startTurn(client: DaprWorkflowStarterLike, request: DaprAgentWorkflowRunRequest): Promise<DaprAgentWorkflowRunResult>;
76
+ steerTurn?(client: DaprWorkflowEventRaiserLike, request: DaprAgentWorkflowSteerRequest): Promise<SteeringResponse>;
77
+ followUpTurn?(client: DaprWorkflowEventRaiserLike, request: DaprAgentWorkflowFollowUpRequest): Promise<FollowUpResponse>;
120
78
  };
121
79
  readonly runtimeBundle: {
122
80
  readonly executionStore?: DaprExecutionStore<TPayload>;
@@ -140,93 +98,127 @@ interface DaprHostApp<TPayload extends AgentTaskPayload = AgentTaskPayload> {
140
98
  handleScheduledJob(jobName: string): Promise<DaprHttpJobHandlerResult>;
141
99
  }
142
100
 
143
- interface DaprServiceInvokerOptions {
144
- /** Dapr sidecar HTTP endpoint. Defaults to http://127.0.0.1:3500. */
145
- daprHttpEndpoint?: string;
146
- /** Optional Dapr API token sent as the dapr-api-token header. */
147
- apiToken?: string;
148
- /** Default request timeout in milliseconds. Defaults to 15000. */
149
- requestTimeoutMs?: number;
150
- /** Override fetch implementation for tests/custom runtimes. */
151
- fetch?: typeof fetch;
152
- }
153
- interface DaprInvokeMethodOptions<TBody = unknown> {
154
- /** HTTP method for invocation. Defaults to POST when body exists, otherwise GET. */
155
- method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
156
- /** Request body. Objects are serialized as JSON. */
157
- body?: TBody;
158
- /** Additional HTTP headers. */
159
- headers?: Record<string, string>;
160
- /** Query-string parameters appended to method URL. */
161
- query?: Record<string, string | number | boolean | undefined>;
162
- /** Per-request timeout override in milliseconds. */
163
- timeoutMs?: number;
164
- }
165
- interface DaprInvokeMethodResult<TResponse = unknown> {
166
- status: number;
167
- data: TResponse | undefined;
168
- headers: Headers;
169
- }
170
- /** Default request contract for invoking a remote agent over service invocation. */
171
- interface RemoteAgentRunRequest extends AgentTaskPayload {
172
- }
173
- /** Default response contract for remote agent execution. */
174
- interface RemoteAgentRunResponse extends AgentTaskResult {
175
- }
176
-
177
- declare class DaprServiceInvoker {
178
- private readonly daprHttpEndpoint;
179
- private readonly apiToken?;
180
- private readonly requestTimeoutMs;
181
- private readonly fetchImpl;
182
- constructor(options?: DaprServiceInvokerOptions);
183
- invokeMethod<TResponse = unknown, TBody = unknown>(appId: string, methodPath: string, options?: DaprInvokeMethodOptions<TBody>): Promise<DaprInvokeMethodResult<TResponse>>;
184
- }
185
101
  /**
186
- * Invoke a remote agent endpoint using the default run contract.
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.
187
120
  *
188
- * Default route: `POST /agents/run`.
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
+ * ```
189
137
  */
190
- declare function invokeRemoteAgentRun(invoker: DaprServiceInvoker, appId: string, request: RemoteAgentRunRequest, methodPath?: string): Promise<RemoteAgentRunResponse>;
191
138
 
192
- interface DaprWorkflowWorkerRuntime extends DaprWorkflowRuntimeRegistrar {
193
- start(): Promise<void>;
194
- stop(): Promise<void>;
195
- }
196
- interface DaprWorkflowWorkerLogger {
197
- info?(message: string): void;
198
- warn?(message: string): void;
199
- error?(message: string): void;
200
- }
201
- interface DaprWorkflowWorkerAgentDefinition {
202
- id: string;
203
- host: DaprAgentWorkflowHost;
204
- aliases?: string[];
205
- description?: string;
206
- }
207
- interface DaprWorkflowWorkerOptions {
208
- runtime: DaprWorkflowWorkerRuntime;
209
- agents: readonly DaprWorkflowWorkerAgentDefinition[];
210
- logger?: DaprWorkflowWorkerLogger;
211
- }
212
- interface DaprWorkflowWorker {
213
- readonly runtime: DaprWorkflowWorkerRuntime;
214
- readonly agents: readonly DaprWorkflowWorkerAgentDefinition[];
215
- start(): Promise<void>;
216
- stop(): Promise<void>;
217
- isRunning(): boolean;
218
- listAgents(): readonly DaprWorkflowWorkerAgentDefinition[];
219
- getAgent(idOrAlias: string): DaprWorkflowWorkerAgentDefinition | undefined;
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;
220
190
  }
221
191
  /**
222
- * Create a Dapr workflow worker controller around one or more agent hosts.
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.
223
218
  *
224
- * This is the host-process analogue of Diagrid's `runner.start()` path:
225
- * the worker owns Dapr SDK lifecycle and workflow/activity registration,
226
- * while each registered host owns the workflow definition for a concrete
227
- * agent profile.
219
+ * @returns A `Tool.AnyInfo` that can be passed to `createAgent({ tools: [...] })`.
228
220
  */
229
- declare function createDaprWorkflowWorker(options: DaprWorkflowWorkerOptions): DaprWorkflowWorker;
221
+ declare function createRemoteAgentTool(options: CreateRemoteAgentToolOptions): Tool.AnyInfo;
230
222
 
231
223
  interface DaprWorkloadResultContext<TPayload = unknown, TResult = unknown> {
232
224
  jobId: string;
@@ -333,38 +325,66 @@ declare function createDaprAgentRuntime<TPayload extends AgentTaskPayload = Agen
333
325
  interface DaprHostRemoteRunRequest extends AgentTaskPayload {
334
326
  agentId?: string;
335
327
  }
328
+
329
+ /**
330
+ * Main HTTP router for a Dapr host app.
331
+ *
332
+ * This is a thin dispatcher that delegates to domain-specific routers
333
+ * under `routers/`. Each router returns `Response | undefined` — `undefined`
334
+ * means "not my route", so the chain continues.
335
+ */
336
+
337
+ type DaprHostHttpHandler = (request: Request) => Promise<Response>;
336
338
  interface DaprHostHttpHandlerOptions<TPayload extends AgentTaskPayload = DaprHostRemoteRunRequest> {
337
339
  app: DaprHostApp<TPayload>;
338
340
  workflowClient?: DaprWorkflowClient;
339
341
  }
340
- interface DaprHostHttpServerOptions<TPayload extends AgentTaskPayload = DaprHostRemoteRunRequest> extends DaprHostHttpHandlerOptions<TPayload> {
341
- port: number;
342
- host?: string;
343
- }
344
- interface DaprHostHttpServer {
345
- server: Server;
346
- origin: string;
347
- close(): Promise<void>;
348
- }
349
342
  /**
350
343
  * Create a lightweight HTTP handler for a Dapr host app.
351
344
  *
352
345
  * Routes:
353
- * - `GET /health`
354
- * - `GET /healthz`
355
- * - `GET /ready`
356
- * - `GET /readyz`
346
+ * - `GET /health` / `GET /healthz`
347
+ * - `GET /ready` / `GET /readyz`
357
348
  * - `GET /agents`
358
349
  * - `POST /job/:name`
350
+ * - `GET /dapr/subscribe`
351
+ * - `POST /dapr/:topic`
359
352
  * - `POST /agents/run`
360
- * - `POST /agents/workflow`
353
+ * - `POST /agents/run-durable`
361
354
  * - `POST /agents/:id/run`
362
- * - `POST /agents/:id/workflow`
355
+ * - `POST /agents/:id/run-durable`
356
+ * - `GET /agents/:id/events/:sessionId` — SSE stream
363
357
  * - `GET /agents/:id/executions/:sessionId`
364
358
  * - `GET /agents/:id/executions/:sessionId/checkpoints`
365
359
  * - `GET /agents/:id/workflows/:instanceId`
360
+ * - `POST /agents/:id/workflows/:instanceId/terminate`
361
+ * - `POST /agents/:id/workflows/:instanceId/pause`
362
+ * - `POST /agents/:id/workflows/:instanceId/resume`
363
+ * - `POST /agents/:id/workflows/:instanceId/purge`
364
+ * - `GET /agents/:id/inputs` / `:requestId` / `:requestId/respond`
365
+ * - `GET /agents/:id/approvals` / `:requestId` / `:requestId/respond`
366
+ * - `GET /agents/:id/follow-ups` / `:requestId` / `:requestId/respond`
367
+ * - `POST /agents/:id/steer`
368
+ * - `POST /agents/:id/follow-up`
369
+ * - Shorthand variants (`/agents/inputs`, `/agents/approvals`, etc.) for single-agent hosts
366
370
  */
367
- declare function createDaprHostHttpHandler<TPayload extends AgentTaskPayload = DaprHostRemoteRunRequest>(options: DaprHostHttpHandlerOptions<TPayload>): (request: Request) => Promise<Response>;
371
+ declare function createDaprHostHttpHandler<TPayload extends AgentTaskPayload = DaprHostRemoteRunRequest>(options: DaprHostHttpHandlerOptions<TPayload>): DaprHostHttpHandler;
372
+
373
+ interface DaprHttpServerOptions {
374
+ handler: DaprHostHttpHandler;
375
+ port: number;
376
+ host?: string;
377
+ }
378
+ interface DaprHostHttpServerOptions<TPayload extends AgentTaskPayload = DaprHostRemoteRunRequest> extends DaprHostHttpHandlerOptions<TPayload> {
379
+ port: number;
380
+ host?: string;
381
+ }
382
+ interface DaprHostHttpServer {
383
+ server: Server;
384
+ origin: string;
385
+ close(): Promise<void>;
386
+ }
387
+ declare function startDaprHttpServer(options: DaprHttpServerOptions): Promise<DaprHostHttpServer>;
368
388
  declare function startDaprHostHttpServer<TPayload extends AgentTaskPayload = DaprHostRemoteRunRequest>(options: DaprHostHttpServerOptions<TPayload>): Promise<DaprHostHttpServer>;
369
389
 
370
390
  interface DaprAgentRunnerOptions {
@@ -436,6 +456,10 @@ interface DaprAgentRunnerOptions {
436
456
  * Properties set here override the defaults derived from the runner config.
437
457
  */
438
458
  workflowHost?: Omit<DaprAgentWorkflowHostOptions, "agent" | "observers">;
459
+ /**
460
+ * Policy for deferred follow-up requests in durable mode.
461
+ */
462
+ followUpPolicy?: FollowUpPolicy;
439
463
  /**
440
464
  * Override for runtime bundle options (advanced).
441
465
  * The `agent` and `driver` fields are always derived from the runner config.
@@ -449,10 +473,42 @@ interface DaprAgentServeOptions {
449
473
  port?: number;
450
474
  /** HTTP host. Defaults to all interfaces. */
451
475
  host?: string;
476
+ /** Serve static assets from this directory before the built-in agent routes. */
477
+ staticDir?: string;
478
+ /** File served for `/` when `staticDir` is configured. Defaults to `index.html`. */
479
+ indexFile?: string;
480
+ /** Additional exact-match routes evaluated before static assets and built-in routes. */
481
+ extraRoutes?: readonly DaprAgentHttpRoute[];
482
+ }
483
+ interface DaprAgentHttpRoute {
484
+ /** Exact URL pathname match, e.g. `/` or `/ui/config.json`. */
485
+ path: string;
486
+ /** Allowed HTTP methods. Defaults to all methods. */
487
+ method?: string | readonly string[];
488
+ handler(request: Request): Response | Promise<Response>;
489
+ }
490
+ interface DaprAgentHttpHandlerOptions {
491
+ staticDir?: string;
492
+ indexFile?: string;
493
+ extraRoutes?: readonly DaprAgentHttpRoute[];
494
+ }
495
+ interface DaprAgentDurableRunOptions {
496
+ sessionId?: string;
497
+ system?: string;
498
+ workflowInstanceId?: string;
499
+ maxSteps?: number;
500
+ }
501
+ interface DaprAgentDurableRunResult {
502
+ agentId: string;
503
+ workflowName: string;
504
+ sessionId: string;
505
+ instanceId: string;
452
506
  }
453
507
  interface DaprAgentRunner {
454
508
  /** Agent name / ID. */
455
509
  readonly name: string;
510
+ /** The underlying agent instance. */
511
+ readonly agent: Agent;
456
512
  /** The underlying workflow host. */
457
513
  readonly workflowHost: DaprAgentWorkflowHost;
458
514
  /** The underlying runtime bundle (scheduling, workload adapter, execution store). */
@@ -461,6 +517,32 @@ interface DaprAgentRunner {
461
517
  readonly worker: DaprWorkflowWorker;
462
518
  /** The workflow client for managing workflow instances. */
463
519
  readonly workflowClient: DaprWorkflowClient;
520
+ /**
521
+ * Return a capabilities patch describing the Dapr runtime backing.
522
+ *
523
+ * Structurally compatible with `AgentServerCapabilitiesPatch` from
524
+ * `@cuylabs/agent-server`. Used internally by
525
+ * `createDaprAgentServerAdapter(...)` and available for custom
526
+ * composition if you need to layer additional transport metadata.
527
+ *
528
+ * @example
529
+ * ```ts
530
+ * import { createDaprAgentServerAdapter } from "@cuylabs/agent-runtime-dapr";
531
+ * const adapter = createDaprAgentServerAdapter(runner);
532
+ * ```
533
+ */
534
+ agentServerCapabilities(): {
535
+ runtime: {
536
+ execution: "local";
537
+ orchestration: "agent-runtime-dapr";
538
+ durability: "workflow";
539
+ dapr: {
540
+ available: true;
541
+ delegatedTurns: false;
542
+ workflowBacked: true;
543
+ };
544
+ };
545
+ };
464
546
  /**
465
547
  * Start the runtime and workflow worker.
466
548
  * Must be called before `serve()` or manual invocation.
@@ -471,6 +553,11 @@ interface DaprAgentRunner {
471
553
  * Calls `start()` internally if not already started.
472
554
  */
473
555
  serve(options?: DaprAgentServeOptions): Promise<void>;
556
+ /**
557
+ * Build the HTTP handler for this runner.
558
+ * Useful when embedding the Dapr host routes inside a custom server.
559
+ */
560
+ createHttpHandler(options?: DaprAgentHttpHandlerOptions): DaprHostHttpHandler;
474
561
  /**
475
562
  * Run a task directly (synchronous execution, no workflow).
476
563
  * The agent must be started first.
@@ -478,34 +565,16 @@ interface DaprAgentRunner {
478
565
  run(message: string, options?: {
479
566
  sessionId?: string;
480
567
  }): Promise<AgentTaskResult>;
568
+ /**
569
+ * Start a durable workflow-backed task and return its identifiers.
570
+ * The agent must be started first.
571
+ */
572
+ runDurable(message: string, options?: DaprAgentDurableRunOptions): Promise<DaprAgentDurableRunResult>;
481
573
  /**
482
574
  * Gracefully shut down the runner.
483
575
  */
484
576
  stop(): Promise<void>;
485
577
  }
486
- /**
487
- * Create a Dapr agent runner — the single-call composition of all pieces
488
- * needed to run an agent with Dapr durability.
489
- *
490
- * Equivalent to Diagrid's `DaprWorkflowAgentRunner`. Internally creates:
491
- * - Workflow host (Dapr workflow registration + turn state management)
492
- * - Runtime bundle (scheduling + workload adapter + execution store)
493
- * - Workflow worker (gRPC worker for Dapr workflow engine)
494
- * - Workflow client (HTTP client for managing workflow instances)
495
- * - HTTP server (on `serve()`)
496
- *
497
- * @example
498
- * ```ts
499
- * const runner = createDaprAgentRunner({
500
- * agent,
501
- * name: "my-agent",
502
- * workflowRuntime: new WorkflowRuntime({ daprHost: "127.0.0.1", daprPort: "50001" }),
503
- * });
504
- *
505
- * await runner.serve({ port: 3000 });
506
- * ```
507
- */
508
- declare function createDaprAgentRunner(options: DaprAgentRunnerOptions): DaprAgentRunner;
509
578
  interface DaprMultiAgentRunnerAgentConfig {
510
579
  /** The agent instance. */
511
580
  agent: Agent;
@@ -515,6 +584,8 @@ interface DaprMultiAgentRunnerAgentConfig {
515
584
  aliases?: string[];
516
585
  /** Optional description for this agent. */
517
586
  description?: string;
587
+ /** Policy for deferred follow-up requests for this hosted agent. */
588
+ followUpPolicy?: FollowUpPolicy;
518
589
  }
519
590
  interface DaprMultiAgentRunnerOptions {
520
591
  /** Agent configurations. */
@@ -539,9 +610,146 @@ interface DaprMultiAgentRunner {
539
610
  start(): Promise<void>;
540
611
  /** Start HTTP server and block until SIGINT/SIGTERM. Calls `start()` internally. */
541
612
  serve(options?: DaprAgentServeOptions): Promise<void>;
613
+ /** Build the HTTP handler for this multi-agent runner. */
614
+ createHttpHandler(options?: DaprAgentHttpHandlerOptions): DaprHostHttpHandler;
542
615
  /** Gracefully shut down. */
543
616
  stop(): Promise<void>;
544
617
  }
618
+
619
+ type AgentServerCapabilitiesPatch = Record<string, unknown>;
620
+ interface AppToolInfo {
621
+ id: string;
622
+ }
623
+ interface AppSkillInfo {
624
+ name: string;
625
+ description?: string;
626
+ path?: string;
627
+ }
628
+ interface AppSubAgentProfileInfo {
629
+ name: string;
630
+ description?: string;
631
+ }
632
+ interface AppPluginCommandInfo {
633
+ pluginId?: string;
634
+ name: string;
635
+ alias: string[];
636
+ summary: string;
637
+ metadata?: unknown;
638
+ }
639
+ interface AppModelState {
640
+ label: string;
641
+ switchable: boolean;
642
+ }
643
+ type AppModelSwitchResult = {
644
+ ok: true;
645
+ label: string;
646
+ } | {
647
+ ok: false;
648
+ error: string;
649
+ };
650
+ type AppRuntimeStatusSnapshot = {
651
+ session: Record<string, unknown>;
652
+ model: Record<string, unknown>;
653
+ context: unknown;
654
+ };
655
+ type AppContextCompactionResult = unknown;
656
+ type AppUndoResult = unknown;
657
+ interface AppFollowUpListOptions {
658
+ sessionId?: string;
659
+ sourceTurnId?: string;
660
+ status?: FollowUpStatus | FollowUpStatus[];
661
+ }
662
+ type ResolveInputRequestPayload = {
663
+ kind: "approval";
664
+ action: "allow" | "deny" | "remember";
665
+ feedback?: string;
666
+ rememberScope?: ApprovalRememberScope;
667
+ } | {
668
+ kind: "human";
669
+ response: HumanInputResponse;
670
+ };
671
+ interface AgentServerPluginCommand {
672
+ pluginId?: string;
673
+ name: string;
674
+ alias: string[];
675
+ summary: string;
676
+ metadata?: unknown;
677
+ execute(args: string): Promise<string | null> | string | null;
678
+ }
679
+ interface AgentServerAdapter {
680
+ readonly cwd: string;
681
+ getCapabilities?(): AgentServerCapabilitiesPatch;
682
+ getModelState?(): Promise<AppModelState> | AppModelState;
683
+ switchModel?(spec: string): Promise<AppModelSwitchResult> | AppModelSwitchResult;
684
+ getSessionRuntimeStatus?(sessionId: string): Promise<AppRuntimeStatusSnapshot> | AppRuntimeStatusSnapshot;
685
+ listTools?(): Promise<AppToolInfo[]> | AppToolInfo[];
686
+ listSkills?(): Promise<AppSkillInfo[]> | AppSkillInfo[];
687
+ listSubAgents?(): Promise<AppSubAgentProfileInfo[]> | AppSubAgentProfileInfo[];
688
+ compactSessionContext?(sessionId: string): Promise<AppContextCompactionResult> | AppContextCompactionResult;
689
+ undoSessionTurn?(sessionId: string): Promise<AppUndoResult> | AppUndoResult;
690
+ getSessionTurnDiff?(sessionId: string): Promise<string | null> | string | null;
691
+ chat(sessionId: string, message: string, options?: {
692
+ system?: string;
693
+ abort?: AbortSignal;
694
+ }): AsyncGenerator<AgentEvent>;
695
+ steer?(request: {
696
+ sessionId: string;
697
+ turnId: string;
698
+ message: string;
699
+ }): SteeringResponse;
700
+ followUp?(request: {
701
+ sessionId: string;
702
+ turnId: string;
703
+ message: string;
704
+ }): FollowUpResponse;
705
+ interruptTurn?(request: {
706
+ sessionId: string;
707
+ turnId: string;
708
+ }): void | Promise<void>;
709
+ respondToInputRequest?(requestId: string, payload: ResolveInputRequestPayload): void | Promise<void>;
710
+ listFollowUps?(options?: AppFollowUpListOptions): Promise<QueuedFollowUpRecord[]> | QueuedFollowUpRecord[];
711
+ getFollowUp?(followUpId: string): Promise<QueuedFollowUpRecord | null> | QueuedFollowUpRecord | null;
712
+ resolveFollowUp?(followUpId: string, action: FollowUpDecisionAction): Promise<QueuedFollowUpRecord | null> | QueuedFollowUpRecord | null;
713
+ listSessions(): ReturnType<Agent["listSessions"]>;
714
+ deleteSession(sessionId: string): Promise<boolean>;
715
+ getSessionStorage(): ReturnType<ReturnType<Agent["getSessionManager"]>["getStorage"]>;
716
+ listPluginCommands?(): Promise<AppPluginCommandInfo[]> | AppPluginCommandInfo[];
717
+ executePluginCommand?(name: string, args: string): Promise<string | null> | string | null;
718
+ }
719
+ interface CreateDaprAgentServerAdapterOptions {
720
+ pluginCommands?: AgentServerPluginCommand[];
721
+ currentModelLabel?: string;
722
+ switchModel?: (spec: string) => Promise<AppModelSwitchResult> | AppModelSwitchResult;
723
+ listSkills?: () => Promise<AppSkillInfo[]> | AppSkillInfo[];
724
+ listSubAgents?: () => Promise<AppSubAgentProfileInfo[]> | AppSubAgentProfileInfo[];
725
+ capabilities?: AgentServerCapabilitiesPatch;
726
+ }
727
+ declare function createDaprAgentServerAdapter(runner: DaprAgentRunner, options?: CreateDaprAgentServerAdapterOptions): AgentServerAdapter;
728
+
729
+ /**
730
+ * Create a Dapr agent runner — the single-call composition of all pieces
731
+ * needed to run an agent with Dapr durability.
732
+ *
733
+ * Equivalent to Diagrid's `DaprWorkflowAgentRunner`. Internally creates:
734
+ * - Workflow host (Dapr workflow registration + turn state management)
735
+ * - Runtime bundle (scheduling + workload adapter + execution store)
736
+ * - Workflow worker (gRPC worker for Dapr workflow engine)
737
+ * - Workflow client (HTTP client for managing workflow instances)
738
+ * - HTTP server (on `serve()`)
739
+ *
740
+ * @example
741
+ * ```ts
742
+ * const runner = createDaprAgentRunner({
743
+ * agent,
744
+ * name: "my-agent",
745
+ * workflowRuntime: new WorkflowRuntime({ daprHost: "127.0.0.1", daprPort: "50001" }),
746
+ * });
747
+ *
748
+ * await runner.serve({ port: 3000 });
749
+ * ```
750
+ */
751
+ declare function createDaprAgentRunner(options: DaprAgentRunnerOptions): DaprAgentRunner;
752
+
545
753
  /**
546
754
  * Create a multi-agent Dapr runner — multiple agents sharing a single
547
755
  * workflow worker, HTTP server, and Dapr sidecar.
@@ -561,4 +769,4 @@ interface DaprMultiAgentRunner {
561
769
  */
562
770
  declare function createDaprMultiAgentRunner(options: DaprMultiAgentRunnerOptions): DaprMultiAgentRunner;
563
771
 
564
- export { startDaprHostHttpServer as $, DaprRuntimeDriver as A, DaprServiceInvoker as B, type DaprServiceInvokerOptions as C, type DaprAgentRunner as D, type DaprWorkflowRuntimeRegistrar as E, type DaprWorkflowStarterLike as F, type DaprWorkflowWorker as G, type DaprWorkflowWorkerAgentDefinition as H, type DaprWorkflowWorkerLogger as I, type DaprWorkflowWorkerOptions as J, type DaprWorkflowWorkerRuntime as K, type DaprWorkloadErrorContext as L, type DaprWorkloadResultContext as M, type DaprWorkloadRuntimeBundle as N, type DaprWorkloadRuntimeOptions as O, type RemoteAgentRunResponse as P, createDaprAgentRunner as Q, type RemoteAgentRunRequest as R, createDaprAgentRuntime as S, createDaprAgentWorkflowHost as T, createDaprHostHttpHandler as U, createDaprHttpJobHandler as V, createDaprMultiAgentRunner as W, createDaprWorkflowWorker as X, createDaprWorkloadRuntime as Y, invokeRemoteAgentRun as Z, startDaprAgentWorkflowTurn as _, type DaprAgentRunnerOptions as a, type DaprAgentRuntimeBundle as b, type DaprAgentRuntimeOptions as c, type DaprAgentServeOptions as d, type DaprAgentTaskErrorContext as e, type DaprAgentTaskResultContext as f, type DaprAgentWorkflowHost as g, type DaprAgentWorkflowHostOptions as h, type DaprAgentWorkflowRunRequest as i, type DaprAgentWorkflowRunResult as j, type DaprHostApp as k, type DaprHostHttpHandlerOptions as l, type DaprHostHttpServer as m, type DaprHostHttpServerOptions as n, type DaprHostReadinessCheck as o, type DaprHostReadinessStatus as p, type DaprHostRemoteRunRequest as q, type DaprHostedAgentInfo as r, type DaprHttpJobHandlerOptions as s, type DaprHttpJobHandlerResult as t, type DaprInvokeMethodOptions as u, type DaprInvokeMethodResult as v, type DaprJobTriggerHandler as w, type DaprMultiAgentRunner as x, type DaprMultiAgentRunnerAgentConfig as y, type DaprMultiAgentRunnerOptions as z };
772
+ 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 };