@cuylabs/agent-runtime 0.5.0 → 0.7.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/README.md CHANGED
@@ -1,16 +1,40 @@
1
1
  # @cuylabs/agent-runtime
2
2
 
3
- Runtime orchestration layer for agent workloads.
3
+ Workload orchestration layer for agent and background workloads.
4
4
 
5
5
  `@cuylabs/agent-core` focuses on single-turn agent execution.
6
6
  `@cuylabs/agent-runtime` manages scheduling and execution of recurring/background work.
7
7
 
8
+ The package now makes one architectural seam explicit:
9
+
10
+ - `agent-core` defines turn/task execution semantics
11
+ - `agent-runtime` consumes a generic workload contract
12
+ - infrastructure packages such as `agent-runtime-dapr` implement that contract
13
+
14
+ ## Package Boundary
15
+
16
+ Use `@cuylabs/agent-runtime` when you need outer orchestration:
17
+
18
+ - job definitions and schedules
19
+ - dispatch, retries, and concurrency limits
20
+ - pluggable runtime drivers
21
+ - runtime observers and metrics
22
+ - orchestration APIs for invoking and guiding long-running work
23
+
24
+ This package does not own in-process model or tool interception.
25
+
26
+ - `agent-core` owns middleware, tool execution, model execution, and turn semantics
27
+ - `agent-runtime` owns workload scheduling and dispatch around that execution
28
+
29
+ So most users start with `agent-core`, then add `agent-runtime` when they need workers, jobs, or orchestrated execution.
30
+
8
31
  ## What This Package Owns
9
32
 
10
33
  - Job definitions and lifecycle (`schedule`, `update`, `pause`, `resume`, `runNow`, `dispatch`)
11
34
  - Schedule evaluation (`at`, `every`, `cron`)
12
35
  - Execution loop with concurrency limits
13
36
  - Pluggable runtime drivers (in-memory now, Dapr/others later)
37
+ - Neutral workload adapter for plugging application work into the runtime
14
38
  - Optional app-level orchestration API (`invoke`, `listInvocations`, `waitForInvocation`, `close`, `guide`)
15
39
 
16
40
  ## Layered Architecture
@@ -24,7 +48,7 @@ host app / worker process
24
48
  ```
25
49
 
26
50
  - `agent-core`: tool loop + model calls + business logic
27
- - `agent-runtime`: scheduling/execution orchestration
51
+ - `agent-runtime`: scheduling/execution orchestration + workload contract
28
52
  - driver package (for example `agent-runtime-dapr`): infrastructure adapter
29
53
 
30
54
  The runtime does not require Dapr. Dapr is one driver/store implementation.
@@ -33,17 +57,46 @@ See `docs/architecture.md` for a concrete package/folder layout across `agent-co
33
57
  See `docs/capability-matrix.md` for the difference between shared runtime contract and backend-specific guarantees.
34
58
  See `docs/production-hardening.md` for the current path from local/in-memory runtime to durable/distributed deployments.
35
59
 
60
+ ## How It Connects To `agent-core`
61
+
62
+ `agent-runtime` does not depend on the `Agent` class directly. It runs generic
63
+ workloads.
64
+
65
+ When you want to schedule agent work, the usual handoff is:
66
+
67
+ ```text
68
+ agent-core
69
+ -> createAgentTaskRunner(agent)
70
+ -> agent-runtime workload adapter
71
+ -> WorkloadRuntime
72
+ ```
73
+
74
+ That means:
75
+
76
+ - `agent-core` turns a live `Agent` into a task-shaped function
77
+ - `agent-runtime` schedules and dispatches that task like any other workload
78
+ - backend packages such as `agent-runtime-dapr` can then add durability,
79
+ persistence, and host integration on top
80
+
81
+ This separation is intentional:
82
+
83
+ - `agent-core` owns agent semantics
84
+ - `agent-runtime` owns outer orchestration semantics
85
+ - the bridge between them is the workload contract
86
+
36
87
  ## Package Structure
37
88
 
38
89
  ```text
39
90
  src/
40
91
  index.ts # Public exports
41
92
  types.ts # Runtime/job contracts
93
+ workload/
94
+ index.ts # Generic workload contract + adapter helper
42
95
  observer.ts # Runtime lifecycle/queue/run observer contracts
43
96
  logger.ts # Logger interface + defaults
44
97
  schedule.ts # Schedule normalization + next-run calculation
45
98
  driver.ts # Driver interface
46
- runtime.ts # AgentRuntime orchestration class
99
+ runtime.ts # WorkloadRuntime orchestration class
47
100
  drivers/
48
101
  in-memory.ts # Default local runtime driver
49
102
  orchestration/
@@ -70,13 +123,14 @@ Focused imports are also available when you want the package surface to match th
70
123
  ```ts
71
124
  import { createAgentOrchestrator } from "@cuylabs/agent-runtime/orchestration";
72
125
  import { InMemoryRuntimeDriver } from "@cuylabs/agent-runtime/drivers/in-memory";
126
+ import { createRuntimeWorkloadExecutor } from "@cuylabs/agent-runtime/workload";
73
127
  ```
74
128
 
75
129
  ## Quick Start
76
130
 
77
131
  ```ts
78
132
  import {
79
- createAgentRuntime,
133
+ createWorkloadRuntime,
80
134
  createPrometheusRuntimeMetrics,
81
135
  InMemoryRuntimeDriver,
82
136
  type RuntimeJobRecord,
@@ -88,7 +142,7 @@ const metrics = createPrometheusRuntimeMetrics<Payload>({
88
142
  defaultLabels: { service: "digest-worker" },
89
143
  });
90
144
 
91
- const runtime = createAgentRuntime<Payload>({
145
+ const runtime = createWorkloadRuntime<Payload>({
92
146
  driver: new InMemoryRuntimeDriver(),
93
147
  execute: async (job: RuntimeJobRecord<Payload>) => {
94
148
  console.log(`[job:${job.id}]`, job.payload.message);
@@ -118,6 +172,37 @@ const job = await runtime.schedule({
118
172
  console.log("scheduled", job.id);
119
173
  ```
120
174
 
175
+ ## Workload Contract
176
+
177
+ Use the workload adapter when you want your app logic to stay independent from
178
+ the runtime internals:
179
+
180
+ ```ts
181
+ import {
182
+ createWorkloadRuntime,
183
+ createRuntimeWorkloadExecutor,
184
+ InMemoryRuntimeDriver,
185
+ } from "@cuylabs/agent-runtime";
186
+
187
+ const runDigest = async (
188
+ payload: { message: string },
189
+ context: { jobId: string; signal: AbortSignal },
190
+ ) => {
191
+ console.log(context.jobId, payload.message);
192
+ return { delivered: true };
193
+ };
194
+
195
+ const runtime = createWorkloadRuntime({
196
+ driver: new InMemoryRuntimeDriver(),
197
+ execute: createRuntimeWorkloadExecutor({
198
+ run: runDigest,
199
+ }),
200
+ });
201
+ ```
202
+
203
+ For agent workloads, `@cuylabs/agent-core` already provides
204
+ `createAgentTaskRunner(...)`, which fits naturally into this workload boundary.
205
+
121
206
  ## Dispatch API
122
207
 
123
208
  `dispatch` lets host apps route explicit triggers into the runtime:
@@ -131,7 +216,7 @@ Use this from transport callbacks (HTTP/gRPC/event handlers) after you map exter
131
216
 
132
217
  ## Production Guardrails
133
218
 
134
- `createAgentRuntime(...)` includes baseline guardrails:
219
+ `createWorkloadRuntime(...)` includes baseline guardrails:
135
220
 
136
221
  - `maxConcurrentRuns` (default `4`)
137
222
  - `maxQueuedDispatches` (optional cap for pending dispatches)
@@ -146,7 +231,7 @@ Use this from transport callbacks (HTTP/gRPC/event handlers) after you map exter
146
231
 
147
232
  ## Runtime Observers
148
233
 
149
- `AgentRuntime` exposes a small observer surface for production hooks, and the package now ships a concrete Prometheus-style collector for the common case.
234
+ `WorkloadRuntime` exposes a small observer surface for production hooks, and the package now ships a concrete Prometheus-style collector for the common case.
150
235
 
151
236
  ```ts
152
237
  import {
@@ -0,0 +1,53 @@
1
+ // src/workload/index.ts
2
+ function toErrorMessage(error) {
3
+ if (error instanceof Error && error.message) {
4
+ return error.message;
5
+ }
6
+ return String(error);
7
+ }
8
+ function createRuntimeWorkloadContext(job, context) {
9
+ return {
10
+ ...context,
11
+ jobId: job.id,
12
+ jobName: job.name,
13
+ ...job.metadata ? { metadata: job.metadata } : {}
14
+ };
15
+ }
16
+ function createRuntimeWorkloadExecutor(options) {
17
+ return async (job, runtimeContext) => {
18
+ const workloadContext = createRuntimeWorkloadContext(job, runtimeContext);
19
+ try {
20
+ const result = await options.run(job.payload, workloadContext);
21
+ if (options.onResult) {
22
+ await options.onResult({
23
+ job,
24
+ context: workloadContext,
25
+ result
26
+ });
27
+ }
28
+ return { status: "ok" };
29
+ } catch (error) {
30
+ const message = toErrorMessage(error);
31
+ if (options.onError) {
32
+ try {
33
+ await options.onError({
34
+ job,
35
+ context: workloadContext,
36
+ error,
37
+ message
38
+ });
39
+ } catch {
40
+ }
41
+ }
42
+ return {
43
+ status: "error",
44
+ error: message
45
+ };
46
+ }
47
+ };
48
+ }
49
+
50
+ export {
51
+ createRuntimeWorkloadContext,
52
+ createRuntimeWorkloadExecutor
53
+ };
@@ -216,7 +216,7 @@ function waitForSignalOrTimeout(ms, signal) {
216
216
  signal.addEventListener("abort", onAbort, { once: true });
217
217
  });
218
218
  }
219
- var AgentRuntime = class {
219
+ var WorkloadRuntime = class {
220
220
  driver;
221
221
  executeJob;
222
222
  logger;
@@ -812,8 +812,8 @@ var AgentRuntime = class {
812
812
  }
813
813
  }
814
814
  };
815
- function createAgentRuntime(options) {
816
- return new AgentRuntime(options);
815
+ function createWorkloadRuntime(options) {
816
+ return new WorkloadRuntime(options);
817
817
  }
818
818
 
819
819
  // src/orchestration/service.ts
@@ -911,7 +911,7 @@ var AgentOrchestrator = class {
911
911
  currentInput: params.run.input,
912
912
  guideMessage: params.guideMessage
913
913
  }));
914
- this.runtime = createAgentRuntime({
914
+ this.runtime = createWorkloadRuntime({
915
915
  ...options.runtime,
916
916
  logger: options.runtime?.logger ?? this.logger,
917
917
  driver: options.driver,
@@ -1457,8 +1457,8 @@ function createAgentOrchestrator(options) {
1457
1457
  export {
1458
1458
  silentRuntimeLogger,
1459
1459
  createConsoleRuntimeLogger,
1460
- AgentRuntime,
1461
- createAgentRuntime,
1460
+ WorkloadRuntime,
1461
+ createWorkloadRuntime,
1462
1462
  isTerminalRunStatus,
1463
1463
  InMemoryOrchestratorRunStore,
1464
1464
  AgentOrchestrator,
@@ -0,0 +1,28 @@
1
+ import { o as RuntimeRunResult, R as RuntimeJobRecord } from './types-DllX9NP8.js';
2
+
3
+ type RuntimeLogMeta = Record<string, unknown>;
4
+ interface RuntimeLogger {
5
+ debug(message: string, meta?: RuntimeLogMeta): void;
6
+ info(message: string, meta?: RuntimeLogMeta): void;
7
+ warn(message: string, meta?: RuntimeLogMeta): void;
8
+ error(message: string, meta?: RuntimeLogMeta): void;
9
+ }
10
+ declare const silentRuntimeLogger: RuntimeLogger;
11
+ declare function createConsoleRuntimeLogger(prefix?: string): RuntimeLogger;
12
+
13
+ interface RuntimeDriverContext<TPayload = unknown> {
14
+ now: () => number;
15
+ onDue: (jobId: string) => Promise<void | RuntimeRunResult>;
16
+ logger: RuntimeLogger;
17
+ }
18
+ interface RuntimeDriver<TPayload = unknown> {
19
+ readonly name: string;
20
+ start(context: RuntimeDriverContext<TPayload>): Promise<void>;
21
+ stop(): Promise<void>;
22
+ listJobs(): Promise<RuntimeJobRecord<TPayload>[]>;
23
+ getJob?(jobId: string): Promise<RuntimeJobRecord<TPayload> | undefined>;
24
+ upsertJob(job: RuntimeJobRecord<TPayload>): Promise<RuntimeJobRecord<TPayload>>;
25
+ removeJob(jobId: string): Promise<boolean>;
26
+ }
27
+
28
+ export { type RuntimeDriver as R, type RuntimeDriverContext as a, type RuntimeLogMeta as b, type RuntimeLogger as c, createConsoleRuntimeLogger as d, silentRuntimeLogger as s };
@@ -1,4 +1,5 @@
1
- import { R as RuntimeDriver, a as RuntimeDriverContext, b as RuntimeJobRecord } from '../driver-KdyMlXQq.js';
1
+ import { R as RuntimeDriver, a as RuntimeDriverContext } from '../driver-CKBCu2Gb.js';
2
+ import { R as RuntimeJobRecord } from '../types-DllX9NP8.js';
2
3
 
3
4
  interface InMemoryRuntimeDriverOptions {
4
5
  maxTimerDelayMs?: number;
@@ -1,4 +1,5 @@
1
- import { w as RuntimeTrigger, b as RuntimeJobRecord, t as RuntimeRunStatus, h as RuntimeDeadLetterEvent, R as RuntimeDriver, m as RuntimeExecutor, p as RuntimeLogger, u as RuntimeScheduleInput, v as RuntimeSchedulePatch, s as RuntimeRunResult, i as RuntimeDispatchInput } from './driver-KdyMlXQq.js';
1
+ import { s as RuntimeTrigger, R as RuntimeJobRecord, p as RuntimeRunStatus, h as RuntimeDeadLetterEvent, b as RuntimeExecutor, q as RuntimeScheduleInput, r as RuntimeSchedulePatch, o as RuntimeRunResult, i as RuntimeDispatchInput } from './types-DllX9NP8.js';
2
+ import { R as RuntimeDriver, c as RuntimeLogger } from './driver-CKBCu2Gb.js';
2
3
 
3
4
  interface RuntimeLifecycleEvent {
4
5
  driver: string;
@@ -51,7 +52,7 @@ interface RuntimeObserver<TPayload = unknown> {
51
52
  notifyDeadLetter?(event: RuntimeDeadLetterEvent<TPayload>): void | Promise<void>;
52
53
  }
53
54
 
54
- interface AgentRuntimeOptions<TPayload = unknown> {
55
+ interface WorkloadRuntimeOptions<TPayload = unknown> {
55
56
  driver: RuntimeDriver<TPayload>;
56
57
  execute: RuntimeExecutor<TPayload>;
57
58
  logger?: RuntimeLogger;
@@ -63,7 +64,7 @@ interface AgentRuntimeOptions<TPayload = unknown> {
63
64
  onDeadLetter?: (event: RuntimeDeadLetterEvent<TPayload>) => void | Promise<void>;
64
65
  observers?: RuntimeObserver<TPayload>[];
65
66
  }
66
- declare class AgentRuntime<TPayload = unknown> {
67
+ declare class WorkloadRuntime<TPayload = unknown> {
67
68
  private readonly driver;
68
69
  private readonly executeJob;
69
70
  private readonly logger;
@@ -80,7 +81,7 @@ declare class AgentRuntime<TPayload = unknown> {
80
81
  private readonly runControllers;
81
82
  private readonly pendingDispatches;
82
83
  private readonly pendingDispatchByJobId;
83
- constructor(options: AgentRuntimeOptions<TPayload>);
84
+ constructor(options: WorkloadRuntimeOptions<TPayload>);
84
85
  private forEachObserver;
85
86
  start(): Promise<void>;
86
87
  stop(): Promise<void>;
@@ -112,7 +113,7 @@ declare class AgentRuntime<TPayload = unknown> {
112
113
  private releaseRunReservation;
113
114
  private drainPendingDispatches;
114
115
  }
115
- declare function createAgentRuntime<TPayload = unknown>(options: AgentRuntimeOptions<TPayload>): AgentRuntime<TPayload>;
116
+ declare function createWorkloadRuntime<TPayload = unknown>(options: WorkloadRuntimeOptions<TPayload>): WorkloadRuntime<TPayload>;
116
117
 
117
118
  type OrchestratorRunStatus = "queued" | "running" | "completed" | "failed" | "cancelled";
118
119
  type OrchestratorRunMode = "invoke" | "guide";
@@ -207,7 +208,7 @@ declare class InMemoryOrchestratorRunStore<TInput = unknown, TResult = unknown>
207
208
  interface AgentOrchestratorOptions<TInput = unknown, TResult = unknown> {
208
209
  driver: RuntimeDriver<OrchestratorJobPayload<TInput>>;
209
210
  execute: OrchestratorExecutor<TInput, TResult>;
210
- runtime?: Omit<AgentRuntimeOptions<OrchestratorJobPayload<TInput>>, "driver" | "execute">;
211
+ runtime?: Omit<WorkloadRuntimeOptions<OrchestratorJobPayload<TInput>>, "driver" | "execute">;
211
212
  store?: OrchestratorRunStore<TInput, TResult>;
212
213
  logger?: RuntimeLogger;
213
214
  createId?: () => string;
@@ -217,7 +218,7 @@ interface AgentOrchestratorOptions<TInput = unknown, TResult = unknown> {
217
218
  resolveGuidedInput?: OrchestratorGuidedInputResolver<TInput, TResult>;
218
219
  }
219
220
  declare class AgentOrchestrator<TInput = unknown, TResult = unknown> {
220
- readonly runtime: AgentRuntime<OrchestratorJobPayload<TInput>>;
221
+ readonly runtime: WorkloadRuntime<OrchestratorJobPayload<TInput>>;
221
222
  private readonly store;
222
223
  private readonly executeRun;
223
224
  private readonly logger;
@@ -234,7 +235,7 @@ declare class AgentOrchestrator<TInput = unknown, TResult = unknown> {
234
235
  start(): Promise<void>;
235
236
  stop(): Promise<void>;
236
237
  status(): Promise<{
237
- runtime: ReturnType<AgentRuntime<OrchestratorJobPayload<TInput>>["status"]>;
238
+ runtime: ReturnType<WorkloadRuntime<OrchestratorJobPayload<TInput>>["status"]>;
238
239
  runs: {
239
240
  total: number;
240
241
  queued: number;
@@ -263,4 +264,4 @@ declare class AgentOrchestrator<TInput = unknown, TResult = unknown> {
263
264
  }
264
265
  declare function createAgentOrchestrator<TInput = unknown, TResult = unknown>(options: AgentOrchestratorOptions<TInput, TResult>): AgentOrchestrator<TInput, TResult>;
265
266
 
266
- export { AgentOrchestrator as A, InMemoryOrchestratorRunStore as I, type OrchestratorCloseOptions as O, type RuntimeObserver as R, type AgentOrchestratorOptions as a, AgentRuntime as b, type AgentRuntimeOptions as c, type OrchestratorExecutionContext as d, type OrchestratorExecutor as e, type OrchestratorGuideInput as f, type OrchestratorGuidedInputResolver as g, type OrchestratorInvokeInput as h, type OrchestratorInvokeResult as i, type OrchestratorJobPayload as j, type OrchestratorListOptions as k, type OrchestratorRunMode as l, type OrchestratorRunRecord as m, type OrchestratorRunState as n, type OrchestratorRunStatus as o, type OrchestratorRunStore as p, type OrchestratorWaitOptions as q, type RuntimeDispatchDroppedEvent as r, type RuntimeDispatchQueuedEvent as s, type RuntimeLifecycleEvent as t, type RuntimeRunCompleteEvent as u, type RuntimeRunRetryEvent as v, type RuntimeRunStartEvent as w, createAgentOrchestrator as x, createAgentRuntime as y, isTerminalRunStatus as z };
267
+ export { AgentOrchestrator as A, InMemoryOrchestratorRunStore as I, type OrchestratorCloseOptions as O, type RuntimeObserver as R, WorkloadRuntime as W, type AgentOrchestratorOptions as a, type OrchestratorExecutionContext as b, type OrchestratorExecutor as c, type OrchestratorGuideInput as d, type OrchestratorGuidedInputResolver as e, type OrchestratorInvokeInput as f, type OrchestratorInvokeResult as g, type OrchestratorJobPayload as h, type OrchestratorListOptions as i, type OrchestratorRunMode as j, type OrchestratorRunRecord as k, type OrchestratorRunState as l, type OrchestratorRunStatus as m, type OrchestratorRunStore as n, type OrchestratorWaitOptions as o, type RuntimeDispatchDroppedEvent as p, type RuntimeDispatchQueuedEvent as q, type RuntimeLifecycleEvent as r, type RuntimeRunCompleteEvent as s, type RuntimeRunRetryEvent as t, type RuntimeRunStartEvent as u, type WorkloadRuntimeOptions as v, createAgentOrchestrator as w, createWorkloadRuntime as x, isTerminalRunStatus as y };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { c as RuntimeJobSchedule, d as RuntimeJobScheduleInput } from './driver-KdyMlXQq.js';
2
- export { e as RuntimeAtSchedule, f as RuntimeAtScheduleInput, g as RuntimeCronSchedule, h as RuntimeDeadLetterEvent, i as RuntimeDispatchInput, R as RuntimeDriver, a as RuntimeDriverContext, j as RuntimeEverySchedule, k as RuntimeExecutionContext, l as RuntimeExecutionResult, m as RuntimeExecutor, b as RuntimeJobRecord, n as RuntimeJobState, o as RuntimeLogMeta, p as RuntimeLogger, q as RuntimeRetryPolicy, r as RuntimeRetryStrategy, s as RuntimeRunResult, t as RuntimeRunStatus, u as RuntimeScheduleInput, v as RuntimeSchedulePatch, w as RuntimeTrigger, x as createConsoleRuntimeLogger, y as silentRuntimeLogger } from './driver-KdyMlXQq.js';
3
- import { R as RuntimeObserver } from './index-CbLKNFMq.js';
4
- export { A as AgentOrchestrator, a as AgentOrchestratorOptions, b as AgentRuntime, c as AgentRuntimeOptions, I as InMemoryOrchestratorRunStore, O as OrchestratorCloseOptions, d as OrchestratorExecutionContext, e as OrchestratorExecutor, f as OrchestratorGuideInput, g as OrchestratorGuidedInputResolver, h as OrchestratorInvokeInput, i as OrchestratorInvokeResult, j as OrchestratorJobPayload, k as OrchestratorListOptions, l as OrchestratorRunMode, m as OrchestratorRunRecord, n as OrchestratorRunState, o as OrchestratorRunStatus, p as OrchestratorRunStore, q as OrchestratorWaitOptions, r as RuntimeDispatchDroppedEvent, s as RuntimeDispatchQueuedEvent, t as RuntimeLifecycleEvent, u as RuntimeRunCompleteEvent, v as RuntimeRunRetryEvent, w as RuntimeRunStartEvent, x as createAgentOrchestrator, y as createAgentRuntime, z as isTerminalRunStatus } from './index-CbLKNFMq.js';
1
+ import { c as RuntimeJobSchedule, d as RuntimeJobScheduleInput } from './types-DllX9NP8.js';
2
+ export { e as RuntimeAtSchedule, f as RuntimeAtScheduleInput, g as RuntimeCronSchedule, h as RuntimeDeadLetterEvent, i as RuntimeDispatchInput, j as RuntimeEverySchedule, a as RuntimeExecutionContext, k as RuntimeExecutionResult, b as RuntimeExecutor, R as RuntimeJobRecord, l as RuntimeJobState, m as RuntimeRetryPolicy, n as RuntimeRetryStrategy, o as RuntimeRunResult, p as RuntimeRunStatus, q as RuntimeScheduleInput, r as RuntimeSchedulePatch, s as RuntimeTrigger } from './types-DllX9NP8.js';
3
+ export { RuntimeWorkloadContext, RuntimeWorkloadErrorContext, RuntimeWorkloadExecutorOptions, RuntimeWorkloadResultContext, RuntimeWorkloadRunner, createRuntimeWorkloadContext, createRuntimeWorkloadExecutor } from './workload/index.js';
4
+ export { R as RuntimeDriver, a as RuntimeDriverContext, b as RuntimeLogMeta, c as RuntimeLogger, d as createConsoleRuntimeLogger, s as silentRuntimeLogger } from './driver-CKBCu2Gb.js';
5
+ import { R as RuntimeObserver } from './index-Cp7CPYy7.js';
6
+ export { A as AgentOrchestrator, a as AgentOrchestratorOptions, I as InMemoryOrchestratorRunStore, O as OrchestratorCloseOptions, b as OrchestratorExecutionContext, c as OrchestratorExecutor, d as OrchestratorGuideInput, e as OrchestratorGuidedInputResolver, f as OrchestratorInvokeInput, g as OrchestratorInvokeResult, h as OrchestratorJobPayload, i as OrchestratorListOptions, j as OrchestratorRunMode, k as OrchestratorRunRecord, l as OrchestratorRunState, m as OrchestratorRunStatus, n as OrchestratorRunStore, o as OrchestratorWaitOptions, p as RuntimeDispatchDroppedEvent, q as RuntimeDispatchQueuedEvent, r as RuntimeLifecycleEvent, s as RuntimeRunCompleteEvent, t as RuntimeRunRetryEvent, u as RuntimeRunStartEvent, W as WorkloadRuntime, v as WorkloadRuntimeOptions, w as createAgentOrchestrator, x as createWorkloadRuntime, y as isTerminalRunStatus } from './index-Cp7CPYy7.js';
5
7
  export { InMemoryRuntimeDriver } from './drivers/in-memory.js';
6
8
 
7
9
  declare const PROMETHEUS_TEXT_CONTENT_TYPE = "text/plain; version=0.0.4; charset=utf-8";
package/dist/index.js CHANGED
@@ -3,18 +3,22 @@ import {
3
3
  } from "./chunk-DBQSJ476.js";
4
4
  import {
5
5
  AgentOrchestrator,
6
- AgentRuntime,
7
6
  InMemoryOrchestratorRunStore,
7
+ WorkloadRuntime,
8
8
  createAgentOrchestrator,
9
- createAgentRuntime,
10
9
  createConsoleRuntimeLogger,
10
+ createWorkloadRuntime,
11
11
  isTerminalRunStatus,
12
12
  silentRuntimeLogger
13
- } from "./chunk-H6BHDIUX.js";
13
+ } from "./chunk-MAVHVV2U.js";
14
14
  import {
15
15
  computeNextRunAtMs,
16
16
  normalizeSchedule
17
17
  } from "./chunk-ZVISWF7S.js";
18
+ import {
19
+ createRuntimeWorkloadContext,
20
+ createRuntimeWorkloadExecutor
21
+ } from "./chunk-INCALI7Z.js";
18
22
 
19
23
  // src/metrics.ts
20
24
  var DEFAULT_METRIC_PREFIX = "agent_runtime";
@@ -393,15 +397,17 @@ function createPrometheusRuntimeMetrics(options = {}) {
393
397
  }
394
398
  export {
395
399
  AgentOrchestrator,
396
- AgentRuntime,
397
400
  InMemoryOrchestratorRunStore,
398
401
  InMemoryRuntimeDriver,
399
402
  PROMETHEUS_TEXT_CONTENT_TYPE,
403
+ WorkloadRuntime,
400
404
  computeNextRunAtMs,
401
405
  createAgentOrchestrator,
402
- createAgentRuntime,
403
406
  createConsoleRuntimeLogger,
404
407
  createPrometheusRuntimeMetrics,
408
+ createRuntimeWorkloadContext,
409
+ createRuntimeWorkloadExecutor,
410
+ createWorkloadRuntime,
405
411
  isTerminalRunStatus,
406
412
  normalizeSchedule,
407
413
  silentRuntimeLogger
@@ -1,2 +1,3 @@
1
- export { A as AgentOrchestrator, a as AgentOrchestratorOptions, I as InMemoryOrchestratorRunStore, O as OrchestratorCloseOptions, d as OrchestratorExecutionContext, e as OrchestratorExecutor, f as OrchestratorGuideInput, g as OrchestratorGuidedInputResolver, h as OrchestratorInvokeInput, i as OrchestratorInvokeResult, j as OrchestratorJobPayload, k as OrchestratorListOptions, l as OrchestratorRunMode, m as OrchestratorRunRecord, n as OrchestratorRunState, o as OrchestratorRunStatus, p as OrchestratorRunStore, q as OrchestratorWaitOptions, x as createAgentOrchestrator, z as isTerminalRunStatus } from '../index-CbLKNFMq.js';
2
- import '../driver-KdyMlXQq.js';
1
+ export { A as AgentOrchestrator, a as AgentOrchestratorOptions, I as InMemoryOrchestratorRunStore, O as OrchestratorCloseOptions, b as OrchestratorExecutionContext, c as OrchestratorExecutor, d as OrchestratorGuideInput, e as OrchestratorGuidedInputResolver, f as OrchestratorInvokeInput, g as OrchestratorInvokeResult, h as OrchestratorJobPayload, i as OrchestratorListOptions, j as OrchestratorRunMode, k as OrchestratorRunRecord, l as OrchestratorRunState, m as OrchestratorRunStatus, n as OrchestratorRunStore, o as OrchestratorWaitOptions, w as createAgentOrchestrator, y as isTerminalRunStatus } from '../index-Cp7CPYy7.js';
2
+ import '../types-DllX9NP8.js';
3
+ import '../driver-CKBCu2Gb.js';
@@ -3,7 +3,7 @@ import {
3
3
  InMemoryOrchestratorRunStore,
4
4
  createAgentOrchestrator,
5
5
  isTerminalRunStatus
6
- } from "../chunk-H6BHDIUX.js";
6
+ } from "../chunk-MAVHVV2U.js";
7
7
  import "../chunk-ZVISWF7S.js";
8
8
  export {
9
9
  AgentOrchestrator,
@@ -99,29 +99,4 @@ interface RuntimeDeadLetterEvent<TPayload = unknown> {
99
99
  error: string;
100
100
  }
101
101
 
102
- type RuntimeLogMeta = Record<string, unknown>;
103
- interface RuntimeLogger {
104
- debug(message: string, meta?: RuntimeLogMeta): void;
105
- info(message: string, meta?: RuntimeLogMeta): void;
106
- warn(message: string, meta?: RuntimeLogMeta): void;
107
- error(message: string, meta?: RuntimeLogMeta): void;
108
- }
109
- declare const silentRuntimeLogger: RuntimeLogger;
110
- declare function createConsoleRuntimeLogger(prefix?: string): RuntimeLogger;
111
-
112
- interface RuntimeDriverContext<TPayload = unknown> {
113
- now: () => number;
114
- onDue: (jobId: string) => Promise<void | RuntimeRunResult>;
115
- logger: RuntimeLogger;
116
- }
117
- interface RuntimeDriver<TPayload = unknown> {
118
- readonly name: string;
119
- start(context: RuntimeDriverContext<TPayload>): Promise<void>;
120
- stop(): Promise<void>;
121
- listJobs(): Promise<RuntimeJobRecord<TPayload>[]>;
122
- getJob?(jobId: string): Promise<RuntimeJobRecord<TPayload> | undefined>;
123
- upsertJob(job: RuntimeJobRecord<TPayload>): Promise<RuntimeJobRecord<TPayload>>;
124
- removeJob(jobId: string): Promise<boolean>;
125
- }
126
-
127
- export { type RuntimeDriver as R, type RuntimeDriverContext as a, type RuntimeJobRecord as b, type RuntimeJobSchedule as c, type RuntimeJobScheduleInput as d, type RuntimeAtSchedule as e, type RuntimeAtScheduleInput as f, type RuntimeCronSchedule as g, type RuntimeDeadLetterEvent as h, type RuntimeDispatchInput as i, type RuntimeEverySchedule as j, type RuntimeExecutionContext as k, type RuntimeExecutionResult as l, type RuntimeExecutor as m, type RuntimeJobState as n, type RuntimeLogMeta as o, type RuntimeLogger as p, type RuntimeRetryPolicy as q, type RuntimeRetryStrategy as r, type RuntimeRunResult as s, type RuntimeRunStatus as t, type RuntimeScheduleInput as u, type RuntimeSchedulePatch as v, type RuntimeTrigger as w, createConsoleRuntimeLogger as x, silentRuntimeLogger as y };
102
+ export type { RuntimeJobRecord as R, RuntimeExecutionContext as a, RuntimeExecutor as b, RuntimeJobSchedule as c, RuntimeJobScheduleInput as d, RuntimeAtSchedule as e, RuntimeAtScheduleInput as f, RuntimeCronSchedule as g, RuntimeDeadLetterEvent as h, RuntimeDispatchInput as i, RuntimeEverySchedule as j, RuntimeExecutionResult as k, RuntimeJobState as l, RuntimeRetryPolicy as m, RuntimeRetryStrategy as n, RuntimeRunResult as o, RuntimeRunStatus as p, RuntimeScheduleInput as q, RuntimeSchedulePatch as r, RuntimeTrigger as s };
@@ -0,0 +1,47 @@
1
+ import { a as RuntimeExecutionContext, R as RuntimeJobRecord, b as RuntimeExecutor } from '../types-DllX9NP8.js';
2
+
3
+ /**
4
+ * Context exposed to domain workloads that run inside `WorkloadRuntime`.
5
+ *
6
+ * This extends the low-level runtime execution context with stable job
7
+ * identity so application code does not need to understand runtime internals.
8
+ */
9
+ interface RuntimeWorkloadContext extends RuntimeExecutionContext {
10
+ jobId: string;
11
+ jobName: string;
12
+ metadata?: Record<string, string>;
13
+ }
14
+ /**
15
+ * Domain workload function executed by the runtime.
16
+ *
17
+ * `agent-core` task runners, queue workers, and other app-level executors can
18
+ * all implement this shape and stay independent from any particular backend.
19
+ */
20
+ type RuntimeWorkloadRunner<TPayload = unknown, TResult = unknown> = (payload: TPayload, context: RuntimeWorkloadContext) => Promise<TResult> | TResult;
21
+ interface RuntimeWorkloadResultContext<TPayload = unknown, TResult = unknown> {
22
+ job: RuntimeJobRecord<TPayload>;
23
+ context: RuntimeWorkloadContext;
24
+ result: TResult;
25
+ }
26
+ interface RuntimeWorkloadErrorContext<TPayload = unknown> {
27
+ job: RuntimeJobRecord<TPayload>;
28
+ context: RuntimeWorkloadContext;
29
+ error: unknown;
30
+ message: string;
31
+ }
32
+ interface RuntimeWorkloadExecutorOptions<TPayload = unknown, TResult = unknown> {
33
+ run: RuntimeWorkloadRunner<TPayload, TResult>;
34
+ onResult?(context: RuntimeWorkloadResultContext<TPayload, TResult>): void | Promise<void>;
35
+ onError?(context: RuntimeWorkloadErrorContext<TPayload>): void | Promise<void>;
36
+ }
37
+ declare function createRuntimeWorkloadContext<TPayload>(job: RuntimeJobRecord<TPayload>, context: RuntimeExecutionContext): RuntimeWorkloadContext;
38
+ /**
39
+ * Adapt a domain workload into the lower-level `RuntimeExecutor` contract.
40
+ *
41
+ * This is the seam between the orchestration layer and application-specific
42
+ * work. Most packages should plug into the runtime through this helper rather
43
+ * than constructing `execute(job, context)` inline.
44
+ */
45
+ declare function createRuntimeWorkloadExecutor<TPayload = unknown, TResult = unknown>(options: RuntimeWorkloadExecutorOptions<TPayload, TResult>): RuntimeExecutor<TPayload>;
46
+
47
+ export { type RuntimeWorkloadContext, type RuntimeWorkloadErrorContext, type RuntimeWorkloadExecutorOptions, type RuntimeWorkloadResultContext, type RuntimeWorkloadRunner, createRuntimeWorkloadContext, createRuntimeWorkloadExecutor };
@@ -0,0 +1,8 @@
1
+ import {
2
+ createRuntimeWorkloadContext,
3
+ createRuntimeWorkloadExecutor
4
+ } from "../chunk-INCALI7Z.js";
5
+ export {
6
+ createRuntimeWorkloadContext,
7
+ createRuntimeWorkloadExecutor
8
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cuylabs/agent-runtime",
3
- "version": "0.5.0",
4
- "description": "Agent runtime orchestration layer - scheduling, execution, and pluggable runtime drivers",
3
+ "version": "0.7.0",
4
+ "description": "Workload runtime orchestration layer - scheduling, execution, and pluggable runtime drivers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -16,6 +16,11 @@
16
16
  "import": "./dist/orchestration/index.js",
17
17
  "default": "./dist/orchestration/index.js"
18
18
  },
19
+ "./workload": {
20
+ "types": "./dist/workload/index.d.ts",
21
+ "import": "./dist/workload/index.js",
22
+ "default": "./dist/workload/index.js"
23
+ },
19
24
  "./drivers/in-memory": {
20
25
  "types": "./dist/drivers/in-memory.d.ts",
21
26
  "import": "./dist/drivers/in-memory.js",
@@ -56,8 +61,8 @@
56
61
  "access": "public"
57
62
  },
58
63
  "scripts": {
59
- "build": "tsup src/index.ts src/orchestration/index.ts src/drivers/in-memory.ts --format esm --dts --clean",
60
- "dev": "tsup src/index.ts src/orchestration/index.ts src/drivers/in-memory.ts --format esm --dts --watch",
64
+ "build": "tsup src/index.ts src/orchestration/index.ts src/workload/index.ts src/drivers/in-memory.ts --format esm --dts --clean",
65
+ "dev": "tsup src/index.ts src/orchestration/index.ts src/workload/index.ts src/drivers/in-memory.ts --format esm --dts --watch",
61
66
  "typecheck": "tsc --noEmit",
62
67
  "test": "vitest run",
63
68
  "test:watch": "vitest",