@cuylabs/agent-runtime-dapr 0.5.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.
- package/LICENSE +201 -0
- package/README.md +260 -0
- package/dist/chunk-2CEICSJH.js +809 -0
- package/dist/chunk-2FMHOZLU.js +1997 -0
- package/dist/chunk-A34CHK2E.js +283 -0
- package/dist/chunk-DILON56B.js +668 -0
- package/dist/execution/index.d.ts +126 -0
- package/dist/execution/index.js +17 -0
- package/dist/host/index.d.ts +7 -0
- package/dist/host/index.js +27 -0
- package/dist/index-CKTP36vE.d.ts +533 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +65 -0
- package/dist/store-pRLGfYhN.d.ts +97 -0
- package/dist/workflow/index.d.ts +216 -0
- package/dist/workflow/index.js +23 -0
- package/dist/workflow-bridge-C8Z1yr0Y.d.ts +83 -0
- package/package.json +99 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { AgentTaskPayload, AgentTaskCheckpointReason, AgentTaskExecutionSnapshot, AgentTurnState, AgentTaskResult, AgentTaskExecutionRun, AgentTaskExecutionCheckpoint } from '@cuylabs/agent-core';
|
|
2
|
+
import { a as DaprExecutionStoreOptions } from './workflow-bridge-C8Z1yr0Y.js';
|
|
3
|
+
|
|
4
|
+
interface DaprExecutionCleanupOptions {
|
|
5
|
+
maxAgeMs?: number;
|
|
6
|
+
maxExecutions?: number;
|
|
7
|
+
maxCheckpointsPerExecution?: number;
|
|
8
|
+
includeRunning?: boolean;
|
|
9
|
+
now?: () => number;
|
|
10
|
+
}
|
|
11
|
+
interface DaprExecutionCleanupResult {
|
|
12
|
+
deletedExecutions: number;
|
|
13
|
+
deletedExecutionIds: string[];
|
|
14
|
+
deletedCheckpoints: number;
|
|
15
|
+
trimmedSessions: number;
|
|
16
|
+
}
|
|
17
|
+
type DaprExecutionStatus = "running" | "completed" | "failed";
|
|
18
|
+
interface DaprExecutionContextMetadata {
|
|
19
|
+
trigger?: string;
|
|
20
|
+
fallbackSessionKey?: string;
|
|
21
|
+
}
|
|
22
|
+
interface DaprExecutionSnapshot {
|
|
23
|
+
sessionId: string;
|
|
24
|
+
response: string;
|
|
25
|
+
usage: AgentTaskExecutionSnapshot["usage"];
|
|
26
|
+
toolCalls: Array<{
|
|
27
|
+
name: string;
|
|
28
|
+
result: unknown;
|
|
29
|
+
}>;
|
|
30
|
+
eventCount: number;
|
|
31
|
+
activeStep?: number;
|
|
32
|
+
lastEvent?: unknown;
|
|
33
|
+
error?: string;
|
|
34
|
+
startedAt: string;
|
|
35
|
+
updatedAt: string;
|
|
36
|
+
turnState: AgentTurnState;
|
|
37
|
+
}
|
|
38
|
+
interface DaprExecutionErrorRecord {
|
|
39
|
+
name: string;
|
|
40
|
+
message: string;
|
|
41
|
+
stack?: string;
|
|
42
|
+
}
|
|
43
|
+
interface DaprExecutionRunRecord<TPayload extends AgentTaskPayload = AgentTaskPayload> {
|
|
44
|
+
sessionId: string;
|
|
45
|
+
payload: TPayload;
|
|
46
|
+
context: DaprExecutionContextMetadata;
|
|
47
|
+
status: DaprExecutionStatus;
|
|
48
|
+
startedAt: string;
|
|
49
|
+
updatedAt: string;
|
|
50
|
+
completedAt?: string;
|
|
51
|
+
checkpointCount: number;
|
|
52
|
+
lastCheckpointReason?: AgentTaskCheckpointReason;
|
|
53
|
+
snapshot: DaprExecutionSnapshot;
|
|
54
|
+
result?: AgentTaskResult;
|
|
55
|
+
error?: DaprExecutionErrorRecord;
|
|
56
|
+
}
|
|
57
|
+
interface DaprExecutionCheckpointRecord<TPayload extends AgentTaskPayload = AgentTaskPayload> {
|
|
58
|
+
id: string;
|
|
59
|
+
sessionId: string;
|
|
60
|
+
payload: TPayload;
|
|
61
|
+
context: DaprExecutionContextMetadata;
|
|
62
|
+
startedAt: string;
|
|
63
|
+
reason: AgentTaskCheckpointReason;
|
|
64
|
+
snapshot: DaprExecutionSnapshot;
|
|
65
|
+
event?: unknown;
|
|
66
|
+
createdAt: string;
|
|
67
|
+
}
|
|
68
|
+
declare class DaprExecutionStore<TPayload extends AgentTaskPayload = AgentTaskPayload> {
|
|
69
|
+
private readonly client;
|
|
70
|
+
private readonly keyPrefix;
|
|
71
|
+
constructor(options: DaprExecutionStoreOptions);
|
|
72
|
+
getExecution(sessionId: string): Promise<DaprExecutionRunRecord<TPayload> | undefined>;
|
|
73
|
+
listExecutions(): Promise<DaprExecutionRunRecord<TPayload>[]>;
|
|
74
|
+
listCheckpoints(sessionId: string): Promise<DaprExecutionCheckpointRecord<TPayload>[]>;
|
|
75
|
+
recordStart(run: AgentTaskExecutionRun<TPayload>, snapshot: AgentTaskExecutionSnapshot): Promise<void>;
|
|
76
|
+
recordCheckpoint(checkpoint: AgentTaskExecutionCheckpoint<TPayload>): Promise<void>;
|
|
77
|
+
recordCompletion(run: AgentTaskExecutionRun<TPayload>, result: AgentTaskResult, snapshot: AgentTaskExecutionSnapshot): Promise<void>;
|
|
78
|
+
recordError(run: AgentTaskExecutionRun<TPayload>, error: Error, snapshot: AgentTaskExecutionSnapshot): Promise<void>;
|
|
79
|
+
cleanup(options?: DaprExecutionCleanupOptions): Promise<DaprExecutionCleanupResult>;
|
|
80
|
+
private stateKeyForExecution;
|
|
81
|
+
private stateKeyForCheckpoint;
|
|
82
|
+
private stateKeyForCheckpointIndex;
|
|
83
|
+
private deleteExecutionRecord;
|
|
84
|
+
private deleteCheckpoint;
|
|
85
|
+
private readCheckpoint;
|
|
86
|
+
private readCheckpointIndex;
|
|
87
|
+
private writeCheckpointIndex;
|
|
88
|
+
private updateCheckpointIndex;
|
|
89
|
+
private addCheckpointToIndex;
|
|
90
|
+
private listCheckpointsFromIndex;
|
|
91
|
+
private writeExecution;
|
|
92
|
+
private writeCheckpoint;
|
|
93
|
+
private decodeExecution;
|
|
94
|
+
private decodeCheckpoint;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { type DaprExecutionCheckpointRecord as D, type DaprExecutionCleanupOptions as a, type DaprExecutionCleanupResult as b, type DaprExecutionContextMetadata as c, type DaprExecutionErrorRecord as d, type DaprExecutionRunRecord as e, type DaprExecutionSnapshot as f, type DaprExecutionStatus as g, DaprExecutionStore as h };
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { d as DaprSidecarClientOptions, f as DaprWorkflowObserverBridge } from '../workflow-bridge-C8Z1yr0Y.js';
|
|
2
|
+
import { AgentWorkflowModelStepPlan, AgentWorkflowModelStepResult, AgentWorkflowToolCallPlan, AgentWorkflowToolCallResult, AgentWorkflowStepCommitPlan, AgentWorkflowCommitResult, AgentWorkflowOutputCommitPlan, AgentTurnStepRuntimeConfig, Tool, convertAgentMessagesToModelMessages, PrepareModelStepOptions, ToolHost, TurnTrackerContext, MiddlewareRunner, ReasoningLevel, AgentEvent, Message, AgentWorkflowTurnState } from '@cuylabs/agent-core';
|
|
3
|
+
|
|
4
|
+
type DaprWorkflowApiVersion = "v1.0" | "v1.0-beta1" | "v1.0-alpha1";
|
|
5
|
+
type DaprWorkflowRuntimeStatus = "RUNNING" | "COMPLETED" | "FAILED" | "TERMINATED" | "CONTINUED_AS_NEW" | "PENDING" | "SUSPENDED" | (string & {});
|
|
6
|
+
interface DaprWorkflowClientOptions extends DaprSidecarClientOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Dapr workflow component name configured in the sidecar resources.
|
|
9
|
+
*
|
|
10
|
+
* Dapr requires the component name as part of the workflow HTTP route, so the
|
|
11
|
+
* client keeps it explicit rather than guessing a default.
|
|
12
|
+
*/
|
|
13
|
+
workflowComponent: string;
|
|
14
|
+
/**
|
|
15
|
+
* HTTP API version for workflow endpoints. Defaults to `v1.0`.
|
|
16
|
+
*/
|
|
17
|
+
workflowApiVersion?: DaprWorkflowApiVersion;
|
|
18
|
+
/**
|
|
19
|
+
* Default polling interval for wait helpers. Defaults to 1000ms.
|
|
20
|
+
*/
|
|
21
|
+
workflowPollIntervalMs?: number;
|
|
22
|
+
}
|
|
23
|
+
interface StartDaprWorkflowOptions<TInput = unknown> {
|
|
24
|
+
/**
|
|
25
|
+
* Optional workflow instance identifier. When omitted, Dapr generates one.
|
|
26
|
+
*/
|
|
27
|
+
instanceId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Optional workflow input payload. Objects are JSON serialized; strings are
|
|
30
|
+
* sent as-is to preserve exact text payloads.
|
|
31
|
+
*/
|
|
32
|
+
input?: TInput;
|
|
33
|
+
}
|
|
34
|
+
interface RaiseDaprWorkflowEventOptions<TEventData = unknown> {
|
|
35
|
+
eventData?: TEventData;
|
|
36
|
+
}
|
|
37
|
+
interface WaitForDaprWorkflowOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Max time to wait before returning `undefined`. Defaults to 60000ms.
|
|
40
|
+
*/
|
|
41
|
+
timeoutMs?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Polling interval for repeated `getWorkflow` checks. Defaults to the client
|
|
44
|
+
* default and never below 50ms.
|
|
45
|
+
*/
|
|
46
|
+
pollIntervalMs?: number;
|
|
47
|
+
}
|
|
48
|
+
interface DaprWorkflowState {
|
|
49
|
+
instanceId: string;
|
|
50
|
+
workflowName: string;
|
|
51
|
+
createdAt?: string;
|
|
52
|
+
lastUpdatedAt?: string;
|
|
53
|
+
runtimeStatus: DaprWorkflowRuntimeStatus;
|
|
54
|
+
/**
|
|
55
|
+
* Raw string properties returned by Dapr for the orchestration instance.
|
|
56
|
+
*/
|
|
57
|
+
properties: Record<string, string>;
|
|
58
|
+
}
|
|
59
|
+
interface DaprStartWorkflowResponse {
|
|
60
|
+
instanceId: string;
|
|
61
|
+
}
|
|
62
|
+
declare function isTerminalDaprWorkflowStatus(status: DaprWorkflowRuntimeStatus): boolean;
|
|
63
|
+
declare function hasStartedDaprWorkflow(status: DaprWorkflowRuntimeStatus): boolean;
|
|
64
|
+
|
|
65
|
+
interface DaprAgentTurnWorkflowActivityNames {
|
|
66
|
+
modelStep: string;
|
|
67
|
+
toolCall: string;
|
|
68
|
+
stepCommit: string;
|
|
69
|
+
outputCommit: string;
|
|
70
|
+
}
|
|
71
|
+
interface DaprAgentTurnWorkflowContextLike {
|
|
72
|
+
callActivity(name: string, input: unknown): unknown;
|
|
73
|
+
setCustomStatus?(status: string): void;
|
|
74
|
+
isReplaying?(): boolean;
|
|
75
|
+
}
|
|
76
|
+
type DaprAgentTurnWorkflowDefinition = (context: DaprAgentTurnWorkflowContextLike, input: AgentWorkflowTurnState) => AsyncGenerator<unknown, AgentWorkflowTurnState, unknown>;
|
|
77
|
+
interface DaprAgentTurnActivityRegistration<TInput, TOutput> {
|
|
78
|
+
name: string;
|
|
79
|
+
handler: (context: unknown, input: TInput) => Promise<TOutput> | TOutput;
|
|
80
|
+
}
|
|
81
|
+
interface DaprAgentTurnWorkflowRegistration {
|
|
82
|
+
workflowName: string;
|
|
83
|
+
activityNames: DaprAgentTurnWorkflowActivityNames;
|
|
84
|
+
workflow: DaprAgentTurnWorkflowDefinition;
|
|
85
|
+
}
|
|
86
|
+
interface CreateDaprAgentTurnWorkflowOptions {
|
|
87
|
+
workflowName?: string;
|
|
88
|
+
activityNames?: Partial<DaprAgentTurnWorkflowActivityNames>;
|
|
89
|
+
now?: () => string;
|
|
90
|
+
}
|
|
91
|
+
type CreateDaprAgentTurnWorkflowRegistrationOptions = CreateDaprAgentTurnWorkflowOptions;
|
|
92
|
+
interface DaprAgentTurnModelStepActivityOptions {
|
|
93
|
+
runtime: AgentTurnStepRuntimeConfig;
|
|
94
|
+
tools: Record<string, Tool.Info>;
|
|
95
|
+
toModelMessages?: typeof convertAgentMessagesToModelMessages;
|
|
96
|
+
mcpTools?: PrepareModelStepOptions["mcpTools"] | (() => Promise<PrepareModelStepOptions["mcpTools"]>);
|
|
97
|
+
host?: ToolHost;
|
|
98
|
+
turnTracker?: TurnTrackerContext;
|
|
99
|
+
middleware?: MiddlewareRunner;
|
|
100
|
+
reasoningLevel?: ReasoningLevel;
|
|
101
|
+
createAbortSignal?: () => AbortSignal;
|
|
102
|
+
onEvent?: (event: AgentEvent) => void | Promise<void>;
|
|
103
|
+
now?: () => string;
|
|
104
|
+
/** Observer bridge for OTel trace context propagation. */
|
|
105
|
+
observerBridge?: DaprWorkflowObserverBridge;
|
|
106
|
+
}
|
|
107
|
+
interface DaprAgentTurnToolCallActivityOptions {
|
|
108
|
+
tools: Record<string, Tool.Info>;
|
|
109
|
+
cwd: string;
|
|
110
|
+
host?: ToolHost;
|
|
111
|
+
turnTracker?: TurnTrackerContext;
|
|
112
|
+
middleware?: MiddlewareRunner;
|
|
113
|
+
createAbortSignal?: () => AbortSignal;
|
|
114
|
+
now?: () => string;
|
|
115
|
+
/** Observer bridge for OTel trace context propagation. */
|
|
116
|
+
observerBridge?: DaprWorkflowObserverBridge;
|
|
117
|
+
}
|
|
118
|
+
interface DaprAgentTurnCommitActivityOptions {
|
|
119
|
+
persistMessages: (sessionId: string, messages: Message[]) => Promise<void>;
|
|
120
|
+
now?: () => string;
|
|
121
|
+
}
|
|
122
|
+
interface CreateDaprAgentTurnWorkflowDefinitionOptions extends CreateDaprAgentTurnWorkflowRegistrationOptions {
|
|
123
|
+
modelStep: (input: AgentWorkflowModelStepPlan) => Promise<AgentWorkflowModelStepResult> | AgentWorkflowModelStepResult;
|
|
124
|
+
toolCall: (input: AgentWorkflowToolCallPlan) => Promise<AgentWorkflowToolCallResult> | AgentWorkflowToolCallResult;
|
|
125
|
+
stepCommit: (input: AgentWorkflowStepCommitPlan) => Promise<AgentWorkflowCommitResult> | AgentWorkflowCommitResult;
|
|
126
|
+
outputCommit: (input: AgentWorkflowOutputCommitPlan) => Promise<AgentWorkflowCommitResult> | AgentWorkflowCommitResult;
|
|
127
|
+
/**
|
|
128
|
+
* Optional observer bridge. When provided, the workflow generator emits
|
|
129
|
+
* lifecycle notifications (task-start, checkpoint, complete, error) so
|
|
130
|
+
* that `AgentTaskObserver`s work on the workflow path too.
|
|
131
|
+
*/
|
|
132
|
+
observerBridge?: DaprWorkflowObserverBridge;
|
|
133
|
+
}
|
|
134
|
+
interface CreateDaprAgentTurnWorkflowKitOptions extends CreateDaprAgentTurnWorkflowRegistrationOptions {
|
|
135
|
+
modelStepActivity: DaprAgentTurnModelStepActivityOptions;
|
|
136
|
+
toolCallActivity: DaprAgentTurnToolCallActivityOptions;
|
|
137
|
+
commitActivity: DaprAgentTurnCommitActivityOptions;
|
|
138
|
+
/** Optional observer bridge passed through to the workflow definition. */
|
|
139
|
+
observerBridge?: DaprWorkflowObserverBridge;
|
|
140
|
+
}
|
|
141
|
+
interface DaprAgentTurnWorkflowKit extends DaprAgentTurnWorkflowRegistration {
|
|
142
|
+
activities: {
|
|
143
|
+
modelStep: DaprAgentTurnActivityRegistration<AgentWorkflowModelStepPlan, AgentWorkflowModelStepResult>;
|
|
144
|
+
toolCall: DaprAgentTurnActivityRegistration<AgentWorkflowToolCallPlan, AgentWorkflowToolCallResult>;
|
|
145
|
+
stepCommit: DaprAgentTurnActivityRegistration<AgentWorkflowStepCommitPlan, AgentWorkflowCommitResult>;
|
|
146
|
+
outputCommit: DaprAgentTurnActivityRegistration<AgentWorkflowOutputCommitPlan, AgentWorkflowCommitResult>;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Create the deterministic workflow definition that a host app can register
|
|
151
|
+
* with the Dapr JS SDK runtime.
|
|
152
|
+
*
|
|
153
|
+
* The returned workflow stays SDK-agnostic at the package boundary: it only
|
|
154
|
+
* assumes a context with `callActivity()` and optional `setCustomStatus()`.
|
|
155
|
+
*/
|
|
156
|
+
declare function createDaprAgentTurnWorkflowDefinition(options: CreateDaprAgentTurnWorkflowDefinitionOptions): DaprAgentTurnWorkflowRegistration;
|
|
157
|
+
/**
|
|
158
|
+
* Build the default model-step activity over the extracted `agent-core`
|
|
159
|
+
* phase helpers.
|
|
160
|
+
*/
|
|
161
|
+
declare function createDaprAgentTurnModelStepActivity(options: DaprAgentTurnModelStepActivityOptions): DaprAgentTurnActivityRegistration<AgentWorkflowModelStepPlan, AgentWorkflowModelStepResult>;
|
|
162
|
+
/**
|
|
163
|
+
* Build the default single-tool-call activity.
|
|
164
|
+
*
|
|
165
|
+
* One tool call per activity is the durable boundary used by the workflow
|
|
166
|
+
* adapter. That is intentionally finer-grained than the in-process
|
|
167
|
+
* `runToolBatch(...)` helper.
|
|
168
|
+
*/
|
|
169
|
+
declare function createDaprAgentTurnToolCallActivity(options: DaprAgentTurnToolCallActivityOptions): DaprAgentTurnActivityRegistration<AgentWorkflowToolCallPlan, AgentWorkflowToolCallResult>;
|
|
170
|
+
/**
|
|
171
|
+
* Build the default step-commit activity that appends assistant/tool messages
|
|
172
|
+
* to the durable session store owned by the host app.
|
|
173
|
+
*/
|
|
174
|
+
declare function createDaprAgentTurnStepCommitActivity(options: DaprAgentTurnCommitActivityOptions): DaprAgentTurnActivityRegistration<AgentWorkflowStepCommitPlan, AgentWorkflowCommitResult>;
|
|
175
|
+
/**
|
|
176
|
+
* Build the default output-commit activity that appends the final assistant
|
|
177
|
+
* message to the durable session store owned by the host app.
|
|
178
|
+
*/
|
|
179
|
+
declare function createDaprAgentTurnOutputCommitActivity(options: DaprAgentTurnCommitActivityOptions): DaprAgentTurnActivityRegistration<AgentWorkflowOutputCommitPlan, AgentWorkflowCommitResult>;
|
|
180
|
+
/**
|
|
181
|
+
* Create a full workflow registration kit with default activity handlers.
|
|
182
|
+
*
|
|
183
|
+
* Host apps can register the returned workflow and activities directly with the
|
|
184
|
+
* Dapr JS SDK runtime while keeping execution semantics in `agent-core`.
|
|
185
|
+
*/
|
|
186
|
+
declare function createDaprAgentTurnWorkflowKit(options: CreateDaprAgentTurnWorkflowKitOptions): DaprAgentTurnWorkflowKit;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Thin HTTP client for Dapr workflow management APIs.
|
|
190
|
+
*
|
|
191
|
+
* This intentionally mirrors the rest of `agent-runtime-dapr`: direct sidecar
|
|
192
|
+
* HTTP calls with retry/timeout behavior owned by `DaprSidecarClient`. The
|
|
193
|
+
* higher-level runtime/workflow adapter can build on this without pulling gRPC
|
|
194
|
+
* or DurableTask types into the package boundary.
|
|
195
|
+
*/
|
|
196
|
+
declare class DaprWorkflowClient {
|
|
197
|
+
private readonly client;
|
|
198
|
+
private readonly workflowComponent;
|
|
199
|
+
private readonly workflowApiVersion;
|
|
200
|
+
private readonly workflowPollIntervalMs;
|
|
201
|
+
constructor(options: DaprWorkflowClientOptions);
|
|
202
|
+
verifySidecar(): Promise<void>;
|
|
203
|
+
startWorkflow<TInput = unknown>(workflowName: string, options?: StartDaprWorkflowOptions<TInput>): Promise<DaprStartWorkflowResponse>;
|
|
204
|
+
getWorkflow(instanceId: string): Promise<DaprWorkflowState | undefined>;
|
|
205
|
+
waitForWorkflowStart(instanceId: string, options?: WaitForDaprWorkflowOptions): Promise<DaprWorkflowState | undefined>;
|
|
206
|
+
waitForWorkflowCompletion(instanceId: string, options?: WaitForDaprWorkflowOptions): Promise<DaprWorkflowState | undefined>;
|
|
207
|
+
pauseWorkflow(instanceId: string): Promise<void>;
|
|
208
|
+
resumeWorkflow(instanceId: string): Promise<void>;
|
|
209
|
+
terminateWorkflow(instanceId: string): Promise<void>;
|
|
210
|
+
purgeWorkflow(instanceId: string): Promise<void>;
|
|
211
|
+
raiseWorkflowEvent<TEventData = unknown>(instanceId: string, eventName: string, options?: RaiseDaprWorkflowEventOptions<TEventData>): Promise<void>;
|
|
212
|
+
private controlWorkflow;
|
|
213
|
+
private waitForWorkflowState;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export { type CreateDaprAgentTurnWorkflowDefinitionOptions, type CreateDaprAgentTurnWorkflowKitOptions, type CreateDaprAgentTurnWorkflowOptions, type DaprAgentTurnActivityRegistration, type DaprAgentTurnCommitActivityOptions, type DaprAgentTurnModelStepActivityOptions, type DaprAgentTurnToolCallActivityOptions, type DaprAgentTurnWorkflowActivityNames, type DaprAgentTurnWorkflowContextLike, type DaprAgentTurnWorkflowDefinition, type DaprAgentTurnWorkflowKit, type DaprAgentTurnWorkflowRegistration, type DaprStartWorkflowResponse, type DaprWorkflowApiVersion, DaprWorkflowClient, type DaprWorkflowClientOptions, type DaprWorkflowRuntimeStatus, type DaprWorkflowState, type RaiseDaprWorkflowEventOptions, type StartDaprWorkflowOptions, type WaitForDaprWorkflowOptions, createDaprAgentTurnModelStepActivity, createDaprAgentTurnOutputCommitActivity, createDaprAgentTurnStepCommitActivity, createDaprAgentTurnToolCallActivity, createDaprAgentTurnWorkflowDefinition, createDaprAgentTurnWorkflowKit, hasStartedDaprWorkflow, isTerminalDaprWorkflowStatus };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DaprWorkflowClient,
|
|
3
|
+
createDaprAgentTurnModelStepActivity,
|
|
4
|
+
createDaprAgentTurnOutputCommitActivity,
|
|
5
|
+
createDaprAgentTurnStepCommitActivity,
|
|
6
|
+
createDaprAgentTurnToolCallActivity,
|
|
7
|
+
createDaprAgentTurnWorkflowDefinition,
|
|
8
|
+
createDaprAgentTurnWorkflowKit,
|
|
9
|
+
hasStartedDaprWorkflow,
|
|
10
|
+
isTerminalDaprWorkflowStatus
|
|
11
|
+
} from "../chunk-DILON56B.js";
|
|
12
|
+
import "../chunk-A34CHK2E.js";
|
|
13
|
+
export {
|
|
14
|
+
DaprWorkflowClient,
|
|
15
|
+
createDaprAgentTurnModelStepActivity,
|
|
16
|
+
createDaprAgentTurnOutputCommitActivity,
|
|
17
|
+
createDaprAgentTurnStepCommitActivity,
|
|
18
|
+
createDaprAgentTurnToolCallActivity,
|
|
19
|
+
createDaprAgentTurnWorkflowDefinition,
|
|
20
|
+
createDaprAgentTurnWorkflowKit,
|
|
21
|
+
hasStartedDaprWorkflow,
|
|
22
|
+
isTerminalDaprWorkflowStatus
|
|
23
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { AgentWorkflowTurnState, AgentTaskCheckpointReason, AgentTaskPayload, AgentTaskObserver } from '@cuylabs/agent-core';
|
|
2
|
+
|
|
3
|
+
type DaprFetch = typeof fetch;
|
|
4
|
+
interface DaprSidecarClientOptions {
|
|
5
|
+
/** Dapr sidecar HTTP endpoint. Defaults to http://127.0.0.1:3500 */
|
|
6
|
+
daprHttpEndpoint?: string;
|
|
7
|
+
/** Optional API token sent as the dapr-api-token header. */
|
|
8
|
+
apiToken?: string;
|
|
9
|
+
/** Request timeout (ms) for sidecar HTTP calls. Defaults to 15000. */
|
|
10
|
+
requestTimeoutMs?: number;
|
|
11
|
+
/** Max retries for transient sidecar/network failures. Defaults to 2. */
|
|
12
|
+
maxRequestRetries?: number;
|
|
13
|
+
/** Verify sidecar availability on start() via /v1.0/metadata. Defaults to true. */
|
|
14
|
+
verifySidecarOnStart?: boolean;
|
|
15
|
+
/** Override fetch implementation for tests and custom runtimes. */
|
|
16
|
+
fetch?: DaprFetch;
|
|
17
|
+
}
|
|
18
|
+
interface DaprStateStoreClientOptions extends DaprSidecarClientOptions {
|
|
19
|
+
/** Dapr state store component name used to persist runtime records. */
|
|
20
|
+
stateStoreName: string;
|
|
21
|
+
}
|
|
22
|
+
interface DaprRuntimeDriverOptions extends DaprStateStoreClientOptions {
|
|
23
|
+
/** Prefix for state keys in the configured store. */
|
|
24
|
+
keyPrefix?: string;
|
|
25
|
+
/** Prefix for Dapr scheduler job names. */
|
|
26
|
+
jobNamePrefix?: string;
|
|
27
|
+
}
|
|
28
|
+
interface DaprOrchestratorRunStoreOptions extends DaprStateStoreClientOptions {
|
|
29
|
+
/** Prefix for state keys used by durable orchestrator run records. */
|
|
30
|
+
keyPrefix?: string;
|
|
31
|
+
}
|
|
32
|
+
interface DaprExecutionStoreOptions extends DaprStateStoreClientOptions {
|
|
33
|
+
/** Prefix for state keys used by durable execution snapshots and checkpoints. */
|
|
34
|
+
keyPrefix?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Options for the workflow observer adapter.
|
|
39
|
+
*/
|
|
40
|
+
interface DaprWorkflowObserverOptions<TPayload extends AgentTaskPayload = AgentTaskPayload> {
|
|
41
|
+
observers: AgentTaskObserver<TPayload>[];
|
|
42
|
+
/** Original payload that triggered the workflow. */
|
|
43
|
+
payload: Readonly<TPayload>;
|
|
44
|
+
/** Execution trigger label (e.g. "workflow", "http"). */
|
|
45
|
+
trigger?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A bridge that lets existing `AgentTaskObserver`s (DaprExecutionObserver,
|
|
49
|
+
* DaprLoggingObserver, etc.) receive lifecycle notifications from the
|
|
50
|
+
* workflow execution path.
|
|
51
|
+
*
|
|
52
|
+
* The workflow path doesn't run through `createAgentTaskRunner`, so
|
|
53
|
+
* observers are never notified — unless the workflow host explicitly calls
|
|
54
|
+
* this adapter at each activity boundary.
|
|
55
|
+
*
|
|
56
|
+
* Usage in workflow-host.ts:
|
|
57
|
+
* ```ts
|
|
58
|
+
* const bridge = createWorkflowObserverBridge({ observers, payload });
|
|
59
|
+
* bridge.notifyTaskStart(initialState);
|
|
60
|
+
* // ... after each activity ...
|
|
61
|
+
* bridge.notifyCheckpoint("step-finish", state);
|
|
62
|
+
* // ... on completion ...
|
|
63
|
+
* bridge.notifyTaskComplete(state);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
interface DaprWorkflowObserverBridge {
|
|
67
|
+
notifyTaskStart(state: AgentWorkflowTurnState): Promise<void>;
|
|
68
|
+
notifyCheckpoint(reason: AgentTaskCheckpointReason, state: AgentWorkflowTurnState): Promise<void>;
|
|
69
|
+
notifyTaskComplete(state: AgentWorkflowTurnState): Promise<void>;
|
|
70
|
+
notifyTaskError(state: AgentWorkflowTurnState, error: Error): Promise<void>;
|
|
71
|
+
/** Update the payload for future observer notifications. */
|
|
72
|
+
updatePayload(payload: AgentTaskPayload): void;
|
|
73
|
+
/**
|
|
74
|
+
* Get the active OTel context for a session from the observers.
|
|
75
|
+
*
|
|
76
|
+
* Used by workflow activities to wrap their execution so child spans
|
|
77
|
+
* (AI SDK, tool calls) are correlated under the observer's root span.
|
|
78
|
+
*/
|
|
79
|
+
getOtelContext(sessionId: string): unknown;
|
|
80
|
+
}
|
|
81
|
+
declare function createWorkflowObserverBridge<TPayload extends AgentTaskPayload = AgentTaskPayload>(options: DaprWorkflowObserverOptions<TPayload>): DaprWorkflowObserverBridge;
|
|
82
|
+
|
|
83
|
+
export { type DaprOrchestratorRunStoreOptions as D, type DaprExecutionStoreOptions as a, type DaprFetch as b, type DaprRuntimeDriverOptions as c, type DaprSidecarClientOptions as d, type DaprStateStoreClientOptions as e, type DaprWorkflowObserverBridge as f, type DaprWorkflowObserverOptions as g, createWorkflowObserverBridge as h };
|
package/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cuylabs/agent-runtime-dapr",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Dapr-backed runtime driver for @cuylabs/agent-runtime",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./execution": {
|
|
15
|
+
"types": "./dist/execution/index.d.ts",
|
|
16
|
+
"import": "./dist/execution/index.js",
|
|
17
|
+
"default": "./dist/execution/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./host": {
|
|
20
|
+
"types": "./dist/host/index.d.ts",
|
|
21
|
+
"import": "./dist/host/index.js",
|
|
22
|
+
"default": "./dist/host/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./workflow": {
|
|
25
|
+
"types": "./dist/workflow/index.d.ts",
|
|
26
|
+
"import": "./dist/workflow/index.js",
|
|
27
|
+
"default": "./dist/workflow/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@cuylabs/agent-core": "^0.5.0",
|
|
36
|
+
"@cuylabs/agent-runtime": "^0.5.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@dapr/dapr": "^3.6.1",
|
|
40
|
+
"@opentelemetry/api": "^1.9.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"@dapr/dapr": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"@opentelemetry/api": {
|
|
47
|
+
"optional": true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@ai-sdk/openai": "^3.0.0",
|
|
52
|
+
"@arizeai/openinference-vercel": "^2.7.1",
|
|
53
|
+
"@dapr/dapr": "^3.6.1",
|
|
54
|
+
"@opentelemetry/api": "^1.9.0",
|
|
55
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.213.0",
|
|
56
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.213.0",
|
|
57
|
+
"@opentelemetry/exporter-zipkin": "^2.6.0",
|
|
58
|
+
"@opentelemetry/resources": "^2.6.0",
|
|
59
|
+
"@opentelemetry/sdk-node": "^0.213.0",
|
|
60
|
+
"@opentelemetry/sdk-trace-node": "^2.6.0",
|
|
61
|
+
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
62
|
+
"@types/node": "^22.0.0",
|
|
63
|
+
"dotenv": "^17.2.3",
|
|
64
|
+
"tsup": "^8.0.0",
|
|
65
|
+
"typescript": "^5.7.0",
|
|
66
|
+
"vitest": "^4.0.18",
|
|
67
|
+
"zod": "^3.24.0",
|
|
68
|
+
"@cuylabs/agent-code": "^0.5.0"
|
|
69
|
+
},
|
|
70
|
+
"keywords": [
|
|
71
|
+
"agent",
|
|
72
|
+
"runtime",
|
|
73
|
+
"dapr",
|
|
74
|
+
"scheduler",
|
|
75
|
+
"orchestration"
|
|
76
|
+
],
|
|
77
|
+
"author": "cuylabs",
|
|
78
|
+
"license": "Apache-2.0",
|
|
79
|
+
"repository": {
|
|
80
|
+
"type": "git",
|
|
81
|
+
"url": "https://github.com/cuylabs-ai/agents-ts.git",
|
|
82
|
+
"directory": "packages/agent-runtime-dapr"
|
|
83
|
+
},
|
|
84
|
+
"engines": {
|
|
85
|
+
"node": ">=20"
|
|
86
|
+
},
|
|
87
|
+
"publishConfig": {
|
|
88
|
+
"access": "public"
|
|
89
|
+
},
|
|
90
|
+
"scripts": {
|
|
91
|
+
"build": "tsup src/index.ts src/execution/index.ts src/host/index.ts src/workflow/index.ts --format esm --dts --clean",
|
|
92
|
+
"dev": "tsup src/index.ts src/execution/index.ts src/host/index.ts src/workflow/index.ts --format esm --dts --watch",
|
|
93
|
+
"typecheck": "tsc --noEmit",
|
|
94
|
+
"test": "vitest run",
|
|
95
|
+
"test:watch": "vitest",
|
|
96
|
+
"test:integration:dapr": "RUN_DAPR_WORKFLOW_LIVE=1 vitest run tests/integration/",
|
|
97
|
+
"clean": "rm -rf dist"
|
|
98
|
+
}
|
|
99
|
+
}
|