@xandreed/plugin-tasks 0.13.0 → 0.14.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,5 +1,5 @@
1
1
  # @xandreed/plugin-tasks
2
2
 
3
- Efferent composable agent framework, 0.13.0. Node 24 or Bun.
3
+ Efferent composable agent framework, 0.14.0. Node 24 or Bun.
4
4
 
5
5
  Documentation: https://github.com/xandreeddev/efferent
@@ -5,7 +5,7 @@ import { TasksConfig, tasksDefaults } from "./task-records.entity.js";
5
5
  import { TasksLive } from "./tasks.adapter.js";
6
6
  export const tasksPlugin = definePlugin({
7
7
  id: "@xandreed/plugin-tasks",
8
- version: "0.13.0",
8
+ version: "0.14.0",
9
9
  scope: "runtime",
10
10
  config: TasksConfig,
11
11
  defaults: tasksDefaults,
@@ -1,11 +1,19 @@
1
1
  import { Layer } from "effect";
2
- import { TaskRunner } from "@xandreed/core";
2
+ import { TaskActivity, TaskRunner } from "@xandreed/core";
3
3
  /**
4
4
  * Background work on fibers of this process, each on its own fiber (it
5
5
  * keeps none of the starting turn's services), all interrupted when the
6
6
  * layer's scope closes: an interrupted task's turn ends as interrupted.
7
7
  * With `maxMs`, each piece of work must be done that long after it starts.
8
+ * The work runs with the services the layer was built with, its trace state
9
+ * included (no `replayableContext`: a new fiber has no other): its spans nest
10
+ * under the span current where the layer was built, and it reads the
11
+ * `CurrentTraceContent` set there.
12
+ * It also provides `TaskActivity`: the work running now, counted from the
13
+ * moment `run` hands it over until it ends. The fiber is forked and joins
14
+ * the set in one step, so a caller interrupted as it hands work over leaves
15
+ * none running outside the set (uncounted, and not interrupted with it).
8
16
  */
9
17
  export declare const InProcessTaskRunnerLive: (options?: {
10
18
  readonly maxMs?: number;
11
- }) => Layer.Layer<TaskRunner>;
19
+ }) => Layer.Layer<TaskRunner | TaskActivity>;
@@ -1,11 +1,11 @@
1
- import { Clock, Effect, FiberSet, Layer, Option } from "effect";
2
- import { TaskRunner } from "@xandreed/core";
3
- export const InProcessTaskRunnerLive = (options) => Layer.effect(TaskRunner, Effect.gen(function* () {
4
- const fibers = yield* FiberSet.make(), context = yield* Effect.context();
5
- return TaskRunner.of({
1
+ import { Clock, Context, Effect, FiberSet, Layer, Option } from "effect";
2
+ import { TaskActivity, TaskRunner } from "@xandreed/core";
3
+ export const InProcessTaskRunnerLive = (options) => Layer.effectContext(Effect.gen(function* () {
4
+ const fibers = yield* FiberSet.make(), context = yield* Effect.context(), runner = TaskRunner.of({
6
5
  run: (work) => Effect.gen(function* () {
7
- const now = yield* Clock.currentTimeMillis, deadline = Option.map(Option.fromNullishOr(options?.maxMs), (ms) => now + ms), fiber = yield* Effect.sync(() => Effect.runForkWith(context)(work(deadline)));
8
- yield* FiberSet.add(fibers, fiber);
6
+ const now = yield* Clock.currentTimeMillis, deadline = Option.map(Option.fromNullishOr(options?.maxMs), (ms) => now + ms);
7
+ yield* Effect.sync(() => FiberSet.addUnsafe(fibers, Effect.runForkWith(context)(work(deadline))));
9
8
  })
10
- });
9
+ }), activity = TaskActivity.of({ running: FiberSet.size(fibers), idle: FiberSet.awaitEmpty(fibers) });
10
+ return Context.make(TaskRunner, runner).pipe(Context.add(TaskActivity, activity));
11
11
  }));
@@ -0,0 +1 @@
1
+ export {};
@@ -58,6 +58,7 @@ export const TasksLive = (config) => Layer.effect(Tasks, Effect.gen(function* ()
58
58
  TurnDuplicate: () => Effect.void,
59
59
  KeyConflict: () => Effect.void,
60
60
  NothingPending: () => Effect.void,
61
+ NotResumable: () => Effect.void,
61
62
  TurnRefused: (refused) => recordEnd(child, {
62
63
  taskId: task.taskId,
63
64
  outcome: "failed",
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xandreed/plugin-tasks",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "engines": {
5
5
  "node": ">=24",
6
6
  "bun": ">=1.3.0"
@@ -14,7 +14,7 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@xandreed/core": "0.13.0",
17
+ "@xandreed/core": "0.14.0",
18
18
  "effect": "4.0.7"
19
19
  },
20
20
  "private": false,