@usine/orchestrator 0.2.1 → 0.3.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.
Files changed (173) hide show
  1. package/README.md +151 -52
  2. package/dist/board/items.d.ts +9 -1
  3. package/dist/board/items.d.ts.map +1 -1
  4. package/dist/board/items.js +16 -4
  5. package/dist/board/items.js.map +1 -1
  6. package/dist/board/projection.d.ts +7 -1
  7. package/dist/board/projection.d.ts.map +1 -1
  8. package/dist/board/projection.js +53 -14
  9. package/dist/board/projection.js.map +1 -1
  10. package/dist/board/tasks.d.ts +14 -2
  11. package/dist/board/tasks.d.ts.map +1 -1
  12. package/dist/board/tasks.js +23 -8
  13. package/dist/board/tasks.js.map +1 -1
  14. package/dist/credentials.d.ts +5 -6
  15. package/dist/credentials.d.ts.map +1 -1
  16. package/dist/credentials.js +22 -15
  17. package/dist/credentials.js.map +1 -1
  18. package/dist/current-instance/changes.d.ts +87 -0
  19. package/dist/current-instance/changes.d.ts.map +1 -0
  20. package/dist/current-instance/changes.js +138 -0
  21. package/dist/current-instance/changes.js.map +1 -0
  22. package/dist/current-instance/current-instance.d.ts +89 -0
  23. package/dist/current-instance/current-instance.d.ts.map +1 -0
  24. package/dist/current-instance/current-instance.js +163 -0
  25. package/dist/current-instance/current-instance.js.map +1 -0
  26. package/dist/exe-dev.d.ts +6 -2
  27. package/dist/exe-dev.d.ts.map +1 -1
  28. package/dist/exe-dev.js +7 -8
  29. package/dist/exe-dev.js.map +1 -1
  30. package/dist/idle-triggers.d.ts +1 -1
  31. package/dist/idle-triggers.d.ts.map +1 -1
  32. package/dist/idle-triggers.js +1 -1
  33. package/dist/idle-triggers.js.map +1 -1
  34. package/dist/label-reconciler.d.ts +5 -2
  35. package/dist/label-reconciler.d.ts.map +1 -1
  36. package/dist/label-reconciler.js.map +1 -1
  37. package/dist/local.d.ts +4 -18
  38. package/dist/local.d.ts.map +1 -1
  39. package/dist/local.js +7 -45
  40. package/dist/local.js.map +1 -1
  41. package/dist/loop-matches.d.ts +28 -0
  42. package/dist/loop-matches.d.ts.map +1 -0
  43. package/dist/loop-matches.js +74 -0
  44. package/dist/loop-matches.js.map +1 -0
  45. package/dist/operator/attempt.d.ts +57 -10
  46. package/dist/operator/attempt.d.ts.map +1 -1
  47. package/dist/operator/attempt.js +49 -10
  48. package/dist/operator/attempt.js.map +1 -1
  49. package/dist/operator/board.d.ts +43 -16
  50. package/dist/operator/board.d.ts.map +1 -1
  51. package/dist/operator/board.js +43 -16
  52. package/dist/operator/board.js.map +1 -1
  53. package/dist/operator/configuration.d.ts +258 -0
  54. package/dist/operator/configuration.d.ts.map +1 -0
  55. package/dist/operator/configuration.js +410 -0
  56. package/dist/operator/configuration.js.map +1 -0
  57. package/dist/operator/desk.d.ts +181 -0
  58. package/dist/operator/desk.d.ts.map +1 -0
  59. package/dist/operator/desk.js +463 -0
  60. package/dist/operator/desk.js.map +1 -0
  61. package/dist/operator/github-changes.d.ts +88 -0
  62. package/dist/operator/github-changes.d.ts.map +1 -0
  63. package/dist/operator/github-changes.js +266 -0
  64. package/dist/operator/github-changes.js.map +1 -0
  65. package/dist/operator/http.d.ts +152 -57
  66. package/dist/operator/http.d.ts.map +1 -1
  67. package/dist/operator/http.js +140 -21
  68. package/dist/operator/http.js.map +1 -1
  69. package/dist/operator/need.d.ts +44 -11
  70. package/dist/operator/need.d.ts.map +1 -1
  71. package/dist/operator/need.js +46 -9
  72. package/dist/operator/need.js.map +1 -1
  73. package/dist/operator/operator.d.ts +109 -29
  74. package/dist/operator/operator.d.ts.map +1 -1
  75. package/dist/operator/operator.js +254 -52
  76. package/dist/operator/operator.js.map +1 -1
  77. package/dist/operator/overview.d.ts +7 -7
  78. package/dist/operator/overview.d.ts.map +1 -1
  79. package/dist/operator/overview.js +5 -5
  80. package/dist/operator/overview.js.map +1 -1
  81. package/dist/operator/projection.d.ts +54 -5
  82. package/dist/operator/projection.d.ts.map +1 -1
  83. package/dist/operator/projection.js +100 -9
  84. package/dist/operator/projection.js.map +1 -1
  85. package/dist/operator/run.d.ts +71 -6
  86. package/dist/operator/run.d.ts.map +1 -1
  87. package/dist/operator/run.js +69 -6
  88. package/dist/operator/run.js.map +1 -1
  89. package/dist/operator/task.d.ts +93 -0
  90. package/dist/operator/task.d.ts.map +1 -0
  91. package/dist/operator/task.js +204 -0
  92. package/dist/operator/task.js.map +1 -0
  93. package/dist/operator/transcript.d.ts +12 -12
  94. package/dist/operator/transcript.d.ts.map +1 -1
  95. package/dist/operator/transcript.js +11 -9
  96. package/dist/operator/transcript.js.map +1 -1
  97. package/dist/operator/usage.d.ts +111 -0
  98. package/dist/operator/usage.d.ts.map +1 -0
  99. package/dist/operator/usage.js +219 -0
  100. package/dist/operator/usage.js.map +1 -0
  101. package/dist/orchestrator.d.ts +8 -5
  102. package/dist/orchestrator.d.ts.map +1 -1
  103. package/dist/orchestrator.js +4 -2
  104. package/dist/orchestrator.js.map +1 -1
  105. package/dist/polling/cycle.d.ts +28 -10
  106. package/dist/polling/cycle.d.ts.map +1 -1
  107. package/dist/polling/cycle.js +20 -6
  108. package/dist/polling/cycle.js.map +1 -1
  109. package/dist/polling/evaluation-failures.d.ts +42 -0
  110. package/dist/polling/evaluation-failures.d.ts.map +1 -0
  111. package/dist/polling/evaluation-failures.js +103 -0
  112. package/dist/polling/evaluation-failures.js.map +1 -0
  113. package/dist/polling/hints.d.ts +2 -2
  114. package/dist/polling/hints.d.ts.map +1 -1
  115. package/dist/polling/hints.js +2 -2
  116. package/dist/polling/hints.js.map +1 -1
  117. package/dist/polling/loop-evaluation.d.ts +21 -11
  118. package/dist/polling/loop-evaluation.d.ts.map +1 -1
  119. package/dist/polling/loop-evaluation.js +70 -27
  120. package/dist/polling/loop-evaluation.js.map +1 -1
  121. package/dist/polling/open-issues.d.ts +23 -0
  122. package/dist/polling/open-issues.d.ts.map +1 -0
  123. package/dist/polling/open-issues.js +77 -0
  124. package/dist/polling/open-issues.js.map +1 -0
  125. package/dist/polling/polling.d.ts +20 -11
  126. package/dist/polling/polling.d.ts.map +1 -1
  127. package/dist/polling/polling.js +201 -51
  128. package/dist/polling/polling.js.map +1 -1
  129. package/dist/polling/repository-sync.d.ts +20 -14
  130. package/dist/polling/repository-sync.d.ts.map +1 -1
  131. package/dist/polling/repository-sync.js +34 -27
  132. package/dist/polling/repository-sync.js.map +1 -1
  133. package/dist/polling-triggers.d.ts +1 -1
  134. package/dist/polling-triggers.d.ts.map +1 -1
  135. package/dist/polling-triggers.js +1 -1
  136. package/dist/polling-triggers.js.map +1 -1
  137. package/dist/reloads.d.ts +14 -0
  138. package/dist/reloads.d.ts.map +1 -0
  139. package/dist/reloads.js +7 -0
  140. package/dist/reloads.js.map +1 -0
  141. package/dist/runtime.d.ts +24 -0
  142. package/dist/runtime.d.ts.map +1 -0
  143. package/dist/runtime.js +58 -0
  144. package/dist/runtime.js.map +1 -0
  145. package/dist/schedule-triggers.d.ts +14 -10
  146. package/dist/schedule-triggers.d.ts.map +1 -1
  147. package/dist/schedule-triggers.js +36 -31
  148. package/dist/schedule-triggers.js.map +1 -1
  149. package/dist/scheduler.d.ts +35 -4
  150. package/dist/scheduler.d.ts.map +1 -1
  151. package/dist/scheduler.js +327 -41
  152. package/dist/scheduler.js.map +1 -1
  153. package/dist/ssh.d.ts +39 -0
  154. package/dist/ssh.d.ts.map +1 -0
  155. package/dist/ssh.js +75 -0
  156. package/dist/ssh.js.map +1 -0
  157. package/dist/trigger-condition.d.ts +12 -0
  158. package/dist/trigger-condition.d.ts.map +1 -0
  159. package/dist/trigger-condition.js +88 -0
  160. package/dist/trigger-condition.js.map +1 -0
  161. package/dist/trigger-submission.d.ts +16 -13
  162. package/dist/trigger-submission.d.ts.map +1 -1
  163. package/dist/trigger-submission.js +19 -14
  164. package/dist/trigger-submission.js.map +1 -1
  165. package/dist/worker-engine.d.ts +10 -0
  166. package/dist/worker-engine.d.ts.map +1 -0
  167. package/dist/worker-engine.js +25 -0
  168. package/dist/worker-engine.js.map +1 -0
  169. package/dist/worker-status.d.ts +70 -0
  170. package/dist/worker-status.d.ts.map +1 -0
  171. package/dist/worker-status.js +55 -0
  172. package/dist/worker-status.js.map +1 -0
  173. package/package.json +31 -10
@@ -1,13 +1,13 @@
1
1
  import * as AttemptChannel from "@usine/core/attempt/channel";
2
2
  import { Schema } from "effect";
3
3
  declare const FailedTranscriptView_base: Schema.Class<FailedTranscriptView, Schema.TaggedStruct<"Failed", {
4
- readonly failure: Schema.Union<readonly [typeof import("./attempt.ts").InfraFailureView, typeof import("./attempt.ts").DefectFailureView, typeof import("./attempt.ts").AgentFailureView, typeof import("./attempt.ts").RunawayFailureView, typeof import("./attempt.ts").ChildSessionBudgetFailureView]>;
4
+ readonly failure: Schema.Union<readonly [typeof import("./attempt.ts").InfraFailureView, typeof import("./attempt.ts").DefectFailureView, typeof import("./attempt.ts").AgentFailureView, typeof import("./attempt.ts").BlockedFailureView, typeof import("./attempt.ts").QuestionFailureView, typeof import("./attempt.ts").RunawayFailureView, typeof import("./attempt.ts").ChildSessionBudgetFailureView]>;
5
5
  }>, {}>;
6
- /** An Attempt failure recorded in the transcript with displayable details only. */
6
+ /** An Attempt failure in the transcript with only displayable details. */
7
7
  export declare class FailedTranscriptView extends FailedTranscriptView_base {
8
8
  }
9
- /** Attempt channel messages exposed to the operator, with defect causes removed from failures. */
10
- export declare const TranscriptPayload: Schema.Union<readonly [typeof AttemptChannel.Started, typeof AttemptChannel.SessionEvent, typeof AttemptChannel.Final, typeof FailedTranscriptView, typeof AttemptChannel.Interrupted, typeof AttemptChannel.Steer, typeof AttemptChannel.Interrupt, typeof AttemptChannel.OperatorMessage, typeof AttemptChannel.Release, typeof AttemptChannel.Cancel, typeof AttemptChannel.InterventionApplied, typeof AttemptChannel.InterventionRejected]>;
9
+ /** The Attempt channel messages shown to the operator, with defect causes removed from failures. */
10
+ export declare const TranscriptPayload: Schema.Union<readonly [typeof AttemptChannel.Started, typeof AttemptChannel.SessionEvent, typeof AttemptChannel.Final, typeof FailedTranscriptView, typeof AttemptChannel.Interrupted, typeof AttemptChannel.Steer, typeof AttemptChannel.Interrupt, typeof AttemptChannel.OperatorMessage, typeof AttemptChannel.Release, typeof AttemptChannel.Cancel, typeof AttemptChannel.InterventionApplied, typeof AttemptChannel.InterventionRejected, typeof AttemptChannel.WorkerUnresponsive, typeof AttemptChannel.WorkerResponsive]>;
11
11
  export type TranscriptPayload = typeof TranscriptPayload.Type;
12
12
  declare const TranscriptEventView_base: Schema.Class<TranscriptEventView, Schema.Struct<{
13
13
  readonly sequence: Schema.brand<Schema.Int, "TranscriptSequence">;
@@ -16,43 +16,43 @@ declare const TranscriptEventView_base: Schema.Class<TranscriptEventView, Schema
16
16
  readonly direction: Schema.Literals<readonly ["inbound", "outbound"]>;
17
17
  readonly target: Schema.optionalKey<Schema.Union<readonly [typeof AttemptChannel.ParentTarget, typeof AttemptChannel.ChildTarget]>>;
18
18
  readonly operator: Schema.optionalKey<Schema.NonEmptyString>;
19
- readonly payload: Schema.Union<readonly [typeof AttemptChannel.Started, typeof AttemptChannel.SessionEvent, typeof AttemptChannel.Final, typeof FailedTranscriptView, typeof AttemptChannel.Interrupted, typeof AttemptChannel.Steer, typeof AttemptChannel.Interrupt, typeof AttemptChannel.OperatorMessage, typeof AttemptChannel.Release, typeof AttemptChannel.Cancel, typeof AttemptChannel.InterventionApplied, typeof AttemptChannel.InterventionRejected]>;
19
+ readonly payload: Schema.Union<readonly [typeof AttemptChannel.Started, typeof AttemptChannel.SessionEvent, typeof AttemptChannel.Final, typeof FailedTranscriptView, typeof AttemptChannel.Interrupted, typeof AttemptChannel.Steer, typeof AttemptChannel.Interrupt, typeof AttemptChannel.OperatorMessage, typeof AttemptChannel.Release, typeof AttemptChannel.Cancel, typeof AttemptChannel.InterventionApplied, typeof AttemptChannel.InterventionRejected, typeof AttemptChannel.WorkerUnresponsive, typeof AttemptChannel.WorkerResponsive]>;
20
20
  }>, {}>;
21
- /** A persisted Attempt channel message with its sequence, direction, and receipt time. */
21
+ /** A stored Attempt channel message with its sequence, direction, and receipt time. */
22
22
  export declare class TranscriptEventView extends TranscriptEventView_base {
23
23
  }
24
24
  declare const TranscriptPageCursor_base: Schema.Class<TranscriptPageCursor, Schema.Struct<{
25
25
  readonly attemptId: Schema.brand<Schema.NonEmptyString, "AttemptId">;
26
26
  readonly before: Schema.brand<Schema.Int, "TranscriptSequence">;
27
27
  }>, {}>;
28
- /** Where the next earlier transcript page starts, scoped to one Attempt. */
28
+ /** The start of the next earlier transcript page within one Attempt. */
29
29
  export declare class TranscriptPageCursor extends TranscriptPageCursor_base {
30
30
  }
31
31
  declare const ColdTranscriptRequest_base: Schema.Class<ColdTranscriptRequest, Schema.TaggedStruct<"ColdTranscriptRequest", {}>, {}>;
32
- /** Requests the newest bounded transcript window when opening a Run. */
32
+ /** A request for the newest bounded transcript window when a Run opens. */
33
33
  export declare class ColdTranscriptRequest extends ColdTranscriptRequest_base {
34
34
  }
35
35
  declare const TailTranscriptRequest_base: Schema.Class<TailTranscriptRequest, Schema.TaggedStruct<"TailTranscriptRequest", {
36
36
  readonly after: Schema.brand<Schema.Int, "TranscriptSequence">;
37
37
  }>, {}>;
38
- /** Requests transcript events after the last observed sequence. */
38
+ /** A request for transcript events after the last seen sequence. */
39
39
  export declare class TailTranscriptRequest extends TailTranscriptRequest_base {
40
40
  }
41
41
  declare const EarlierTranscriptRequest_base: Schema.Class<EarlierTranscriptRequest, Schema.TaggedStruct<"EarlierTranscriptRequest", {
42
42
  readonly attemptId: Schema.brand<Schema.NonEmptyString, "AttemptId">;
43
43
  readonly before: Schema.brand<Schema.Int, "TranscriptSequence">;
44
44
  }>, {}>;
45
- /** Requests an earlier page before a sequence within one Attempt. */
45
+ /** A request for an earlier page before a sequence within one Attempt. */
46
46
  export declare class EarlierTranscriptRequest extends EarlierTranscriptRequest_base {
47
47
  }
48
- /** Selects the initial window, live tail, or earlier page of a Run transcript. */
48
+ /** A request for the initial window, live tail, or an earlier page of a Run transcript. */
49
49
  export declare const TranscriptRequest: Schema.Union<readonly [typeof ColdTranscriptRequest, typeof TailTranscriptRequest, typeof EarlierTranscriptRequest]>;
50
50
  export type TranscriptRequest = typeof TranscriptRequest.Type;
51
51
  declare const TranscriptAttemptNotFoundError_base: Schema.Class<TranscriptAttemptNotFoundError, Schema.TaggedStruct<"TranscriptAttemptNotFoundError", {
52
52
  readonly runId: Schema.brand<Schema.NonEmptyString, "RunId">;
53
53
  readonly attemptId: Schema.brand<Schema.NonEmptyString, "AttemptId">;
54
54
  }>, import("effect/Cause").YieldableError>;
55
- /** The requested Attempt is absent from the Run whose transcript is being read. */
55
+ /** The requested Attempt isn't in the Run whose transcript is being read. */
56
56
  export declare class TranscriptAttemptNotFoundError extends TranscriptAttemptNotFoundError_base {
57
57
  }
58
58
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../../src/operator/transcript.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,cAAc,MAAM,6BAA6B,CAAC;AAG9D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;AAGhC,mFAAmF;AACnF,qBAAa,oBAAqB,SAAQ,yBAEL;CAAG;AAExC,kGAAkG;AAClG,eAAO,MAAM,iBAAiB,kbAa5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAC;;;;;;;;;;AAE9D,0FAA0F;AAC1F,qBAAa,mBAAoB,SAAQ,wBAUvC;CAAG;;;;;AAEL,4EAA4E;AAC5E,qBAAa,oBAAqB,SAAQ,yBAKxC;CAAG;;AAEL,wEAAwE;AACxE,qBAAa,qBAAsB,SAAQ,0BAEb;CAAG;;;;AAEjC,mEAAmE;AACnE,qBAAa,qBAAsB,SAAQ,0BAEc;CAAG;;;;;AAE5D,qEAAqE;AACrE,qBAAa,wBAAyB,SAAQ,6BAK5C;CAAG;AAEL,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,sHAI5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAC;;;;;AAE9D,mFAAmF;AACnF,qBAAa,8BAA+B,SAAQ,mCAKlD;CAAG"}
1
+ {"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../../src/operator/transcript.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,cAAc,MAAM,6BAA6B,CAAC;AAG9D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;AAGhC,0EAA0E;AAC1E,qBAAa,oBAAqB,SAAQ,yBAEL;CAAG;AAExC,oGAAoG;AACpG,eAAO,MAAM,iBAAiB,ogBAe5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAC;;;;;;;;;;AAE9D,uFAAuF;AACvF,qBAAa,mBAAoB,SAAQ,wBAUvC;CAAG;;;;;AAEL,wEAAwE;AACxE,qBAAa,oBAAqB,SAAQ,yBAKxC;CAAG;;AAEL,2EAA2E;AAC3E,qBAAa,qBAAsB,SAAQ,0BAEb;CAAG;;;;AAEjC,oEAAoE;AACpE,qBAAa,qBAAsB,SAAQ,0BAEc;CAAG;;;;;AAE5D,0EAA0E;AAC1E,qBAAa,wBAAyB,SAAQ,6BAK5C;CAAG;AAEL,2FAA2F;AAC3F,eAAO,MAAM,iBAAiB,sHAI5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAC;;;;;AAE9D,6EAA6E;AAC7E,qBAAa,8BAA+B,SAAQ,mCAKlD;CAAG"}
@@ -4,10 +4,10 @@ import { RunId } from "@usine/core/run";
4
4
  import { TranscriptSequence } from "@usine/engine/transcript";
5
5
  import { Schema } from "effect";
6
6
  import { FailureView } from "./attempt.js";
7
- /** An Attempt failure recorded in the transcript with displayable details only. */
7
+ /** An Attempt failure in the transcript with only displayable details. */
8
8
  export class FailedTranscriptView extends Schema.TaggedClass("@usine/orchestrator/FailedTranscriptView")("Failed", { failure: FailureView }) {
9
9
  }
10
- /** Attempt channel messages exposed to the operator, with defect causes removed from failures. */
10
+ /** The Attempt channel messages shown to the operator, with defect causes removed from failures. */
11
11
  export const TranscriptPayload = Schema.Union([
12
12
  AttemptChannel.Started,
13
13
  AttemptChannel.SessionEvent,
@@ -21,8 +21,10 @@ export const TranscriptPayload = Schema.Union([
21
21
  AttemptChannel.Cancel,
22
22
  AttemptChannel.InterventionApplied,
23
23
  AttemptChannel.InterventionRejected,
24
+ AttemptChannel.WorkerUnresponsive,
25
+ AttemptChannel.WorkerResponsive,
24
26
  ]);
25
- /** A persisted Attempt channel message with its sequence, direction, and receipt time. */
27
+ /** A stored Attempt channel message with its sequence, direction, and receipt time. */
26
28
  export class TranscriptEventView extends Schema.Class("@usine/orchestrator/TranscriptEventView")({
27
29
  sequence: TranscriptSequence,
28
30
  attemptId: AttemptId,
@@ -33,31 +35,31 @@ export class TranscriptEventView extends Schema.Class("@usine/orchestrator/Trans
33
35
  payload: TranscriptPayload,
34
36
  }) {
35
37
  }
36
- /** Where the next earlier transcript page starts, scoped to one Attempt. */
38
+ /** The start of the next earlier transcript page within one Attempt. */
37
39
  export class TranscriptPageCursor extends Schema.Class("@usine/orchestrator/TranscriptPageCursor")({
38
40
  attemptId: AttemptId,
39
41
  before: TranscriptSequence,
40
42
  }) {
41
43
  }
42
- /** Requests the newest bounded transcript window when opening a Run. */
44
+ /** A request for the newest bounded transcript window when a Run opens. */
43
45
  export class ColdTranscriptRequest extends Schema.TaggedClass("@usine/orchestrator/ColdTranscriptRequest")("ColdTranscriptRequest", {}) {
44
46
  }
45
- /** Requests transcript events after the last observed sequence. */
47
+ /** A request for transcript events after the last seen sequence. */
46
48
  export class TailTranscriptRequest extends Schema.TaggedClass("@usine/orchestrator/TailTranscriptRequest")("TailTranscriptRequest", { after: TranscriptSequence }) {
47
49
  }
48
- /** Requests an earlier page before a sequence within one Attempt. */
50
+ /** A request for an earlier page before a sequence within one Attempt. */
49
51
  export class EarlierTranscriptRequest extends Schema.TaggedClass("@usine/orchestrator/EarlierTranscriptRequest")("EarlierTranscriptRequest", {
50
52
  attemptId: AttemptId,
51
53
  before: TranscriptSequence,
52
54
  }) {
53
55
  }
54
- /** Selects the initial window, live tail, or earlier page of a Run transcript. */
56
+ /** A request for the initial window, live tail, or an earlier page of a Run transcript. */
55
57
  export const TranscriptRequest = Schema.Union([
56
58
  ColdTranscriptRequest,
57
59
  TailTranscriptRequest,
58
60
  EarlierTranscriptRequest,
59
61
  ]);
60
- /** The requested Attempt is absent from the Run whose transcript is being read. */
62
+ /** The requested Attempt isn't in the Run whose transcript is being read. */
61
63
  export class TranscriptAttemptNotFoundError extends Schema.TaggedError("@usine/orchestrator/TranscriptAttemptNotFoundError")("TranscriptAttemptNotFoundError", {
62
64
  runId: RunId,
63
65
  attemptId: AttemptId,
@@ -1 +1 @@
1
- {"version":3,"file":"transcript.js","sourceRoot":"","sources":["../../src/operator/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,cAAc,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,mFAAmF;AACnF,MAAM,OAAO,oBAAqB,SAAQ,MAAM,CAAC,WAAW,CAC1D,0CAA0C,CAC3C,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;CAAG;AAExC,kGAAkG;AAClG,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,KAAK,CAAC;IAC5C,cAAc,CAAC,OAAO;IACtB,cAAc,CAAC,YAAY;IAC3B,cAAc,CAAC,KAAK;IACpB,oBAAoB;IACpB,cAAc,CAAC,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AAO,8BAA+B,SAAQ,MAAM,CAAC,WAAW,CACpE,oDAAoD,CACrD,CAAC,gCAAgC,EAAE;IAClC,KAAK,EAAE,KAAK;IACZ,SAAS,EAAE,SAAS;CACrB,CAAC;CAAG"}
@@ -0,0 +1,111 @@
1
+ import type { RunStoreError } from "@usine/engine/engine";
2
+ import type { RunId } from "@usine/core/run";
3
+ import { RunReader, type RunSnapshot } from "@usine/engine/run-reader";
4
+ import { Context, Effect, Layer, Schema } from "effect";
5
+ import type { AttemptView } from "./attempt.ts";
6
+ declare const UsageCostView_base: Schema.Class<UsageCostView, Schema.Struct<{
7
+ readonly usd: Schema.brand<Schema.Finite, "UsdAmount">;
8
+ readonly estimate: Schema.Boolean;
9
+ }>, {}>;
10
+ /**
11
+ * A dollar cost reported by a harness. `estimate` is true for Claude plan figures, which the Agent
12
+ * SDK computes from bundled prices (ADR 0013).
13
+ */
14
+ export declare class UsageCostView extends UsageCostView_base {
15
+ }
16
+ declare const SessionUsageView_base: Schema.Class<SessionUsageView, Schema.Struct<{
17
+ readonly attemptId: Schema.brand<Schema.NonEmptyString, "AttemptId">;
18
+ readonly session: Schema.Union<readonly [typeof import("@usine/core/agent/session").ParentSession, typeof import("@usine/core/agent/session").ChildSession]>;
19
+ readonly pool: Schema.Literals<readonly ["apiKeys", "claudePlan", "chatgptPlan"]>;
20
+ readonly tokens: Schema.brand<Schema.Int, "TokenCount">;
21
+ /** Null in the ChatGPT plan, which has no dollar rate, or if the harness priced nothing. */
22
+ readonly cost: Schema.NullOr<typeof UsageCostView>;
23
+ }>, {}>;
24
+ /** One Attempt session's usage from its highest token report, and its billing pool. */
25
+ export declare class SessionUsageView extends SessionUsageView_base {
26
+ }
27
+ declare const PoolUsageView_base: Schema.Class<PoolUsageView, Schema.Struct<{
28
+ readonly pool: Schema.Literals<readonly ["apiKeys", "claudePlan", "chatgptPlan"]>;
29
+ readonly tokens: Schema.brand<Schema.Int, "TokenCount">;
30
+ /** Null in the ChatGPT plan, or if any session in the pool has no price. */
31
+ readonly cost: Schema.NullOr<typeof UsageCostView>;
32
+ }>, {}>;
33
+ /** A Run's usage in one billing pool. */
34
+ export declare class PoolUsageView extends PoolUsageView_base {
35
+ }
36
+ declare const RunUsageView_base: Schema.Class<RunUsageView, Schema.Struct<{
37
+ readonly tokens: Schema.brand<Schema.Int, "TokenCount">;
38
+ /** In the order API keys, Claude plan, ChatGPT plan; unused pools are absent. */
39
+ readonly pools: Schema.$Array<typeof PoolUsageView>;
40
+ /** In order of Attempt start, then first report. */
41
+ readonly sessions: Schema.$Array<typeof SessionUsageView>;
42
+ }>, {}>;
43
+ /**
44
+ * The tokens a Run's Attempts used, per pool and session, with prices where a pool has a dollar
45
+ * rate.
46
+ */
47
+ export declare class RunUsageView extends RunUsageView_base {
48
+ }
49
+ declare const TaskPoolUsageView_base: Schema.Class<TaskPoolUsageView, Schema.Struct<{
50
+ readonly pool: Schema.Literals<readonly ["apiKeys", "claudePlan", "chatgptPlan"]>;
51
+ readonly tokens: Schema.brand<Schema.Int, "TokenCount">;
52
+ /**
53
+ * The cost of the priced sessions, or null in the ChatGPT plan or if no session in the pool has a
54
+ * price yet.
55
+ */
56
+ readonly cost: Schema.NullOr<typeof UsageCostView>;
57
+ /**
58
+ * Whether a session in a priced pool has no price yet, so `cost` is a lower bound. Always false
59
+ * in the ChatGPT plan.
60
+ */
61
+ readonly unpriced: Schema.Boolean;
62
+ }>, {}>;
63
+ /** A Task's usage in one billing pool, summed over every session of every Run. */
64
+ export declare class TaskPoolUsageView extends TaskPoolUsageView_base {
65
+ }
66
+ declare const TaskUsageView_base: Schema.Class<TaskUsageView, Schema.Struct<{
67
+ /** The summed wall time of ended Attempts, each from start to recorded end. */
68
+ readonly durationMillis: Schema.Int;
69
+ /** The start times of running Attempts; add the time since each to `durationMillis`. */
70
+ readonly runningSince: Schema.$Array<Schema.String>;
71
+ /** The number of ended Attempts with no recorded end, excluded from `durationMillis`. */
72
+ readonly unmeasured: Schema.Int;
73
+ readonly tokens: Schema.brand<Schema.Int, "TokenCount">;
74
+ /**
75
+ * Each pool summed over the Runs, in the order API keys, Claude plan, ChatGPT plan; unused
76
+ * pools are absent.
77
+ */
78
+ readonly pools: Schema.$Array<typeof TaskPoolUsageView>;
79
+ /**
80
+ * The summed cost of the priced pools, or null if no pool has a price. It's an estimate if it
81
+ * includes the Claude plan, and a lower bound if a pool is `unpriced`.
82
+ */
83
+ readonly cost: Schema.NullOr<typeof UsageCostView>;
84
+ }>, {}>;
85
+ /**
86
+ * A Task's usage over every Run on its Items: Attempt wall time, and tokens and cost per billing
87
+ * pool.
88
+ */
89
+ export declare class TaskUsageView extends TaskUsageView_base {
90
+ }
91
+ /**
92
+ * Sums the Attempt time, tokens, and cost of a Task's `runs`. Pools sum sessions rather than Run
93
+ * pools, so priced sessions count even when another session is unpriced, which sets `unpriced`.
94
+ */
95
+ export declare const taskUsage: (runs: ReadonlyArray<{
96
+ readonly id: RunId;
97
+ readonly attempts: ReadonlyArray<Pick<AttemptView, "startedAt" | "endedAt" | "outcome">>;
98
+ }>, usage: ReadonlyMap<RunId, RunUsageView>) => TaskUsageView;
99
+ type RunUsageSource = Pick<RunSnapshot, "run" | "attempts">;
100
+ declare const RunUsageReader_base: Context.ServiceClass<RunUsageReader, "@usine/orchestrator/RunUsageReader", {
101
+ readonly read: (run: RunUsageSource) => Effect.Effect<RunUsageView, RunStoreError>;
102
+ }>;
103
+ /**
104
+ * Reads a Run's usage from each session's highest token report. Caches the reports of Attempts with
105
+ * an outcome and rereads running Attempts on every call.
106
+ */
107
+ export declare class RunUsageReader extends RunUsageReader_base {
108
+ static readonly layer: Layer.Layer<RunUsageReader, never, RunReader>;
109
+ }
110
+ export {};
111
+ //# sourceMappingURL=usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/operator/usage.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OA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AY,EAAE,aAAa,CAAC;;AANtF;;;GAGG;AACH,qBAAa,cAAe,SAAQ,mBAGK;IACvC,MAAM,CAAC,QAAQ,CAAC,KAAK,gDAAoD;CAC1E"}
@@ -0,0 +1,219 @@
1
+ import { AgentSession, BillingPool, sessionPool, TokenCount, UsdAmount, } from "@usine/core/agent/session";
2
+ import { AttemptId } from "@usine/core/attempt";
3
+ import { RunReader } from "@usine/engine/run-reader";
4
+ import { TranscriptUsageQuery } from "@usine/engine/transcript";
5
+ import { Context, Effect, Layer, Option, Schema } from "effect";
6
+ /**
7
+ * A dollar cost reported by a harness. `estimate` is true for Claude plan figures, which the Agent
8
+ * SDK computes from bundled prices (ADR 0013).
9
+ */
10
+ export class UsageCostView extends Schema.Class("@usine/orchestrator/UsageCostView")({ usd: UsdAmount, estimate: Schema.Boolean }) {
11
+ }
12
+ /** One Attempt session's usage from its highest token report, and its billing pool. */
13
+ export class SessionUsageView extends Schema.Class("@usine/orchestrator/SessionUsageView")({
14
+ attemptId: AttemptId,
15
+ session: AgentSession,
16
+ pool: BillingPool,
17
+ tokens: TokenCount,
18
+ /** Null in the ChatGPT plan, which has no dollar rate, or if the harness priced nothing. */
19
+ cost: Schema.NullOr(UsageCostView),
20
+ }) {
21
+ }
22
+ /** A Run's usage in one billing pool. */
23
+ export class PoolUsageView extends Schema.Class("@usine/orchestrator/PoolUsageView")({
24
+ pool: BillingPool,
25
+ tokens: TokenCount,
26
+ /** Null in the ChatGPT plan, or if any session in the pool has no price. */
27
+ cost: Schema.NullOr(UsageCostView),
28
+ }) {
29
+ }
30
+ /**
31
+ * The tokens a Run's Attempts used, per pool and session, with prices where a pool has a dollar
32
+ * rate.
33
+ */
34
+ export class RunUsageView extends Schema.Class("@usine/orchestrator/RunUsageView")({
35
+ tokens: TokenCount,
36
+ /** In the order API keys, Claude plan, ChatGPT plan; unused pools are absent. */
37
+ pools: Schema.Array(PoolUsageView),
38
+ /** In order of Attempt start, then first report. */
39
+ sessions: Schema.Array(SessionUsageView),
40
+ }) {
41
+ }
42
+ /** A Task's usage in one billing pool, summed over every session of every Run. */
43
+ export class TaskPoolUsageView extends Schema.Class("@usine/orchestrator/TaskPoolUsageView")({
44
+ pool: BillingPool,
45
+ tokens: TokenCount,
46
+ /**
47
+ * The cost of the priced sessions, or null in the ChatGPT plan or if no session in the pool has a
48
+ * price yet.
49
+ */
50
+ cost: Schema.NullOr(UsageCostView),
51
+ /**
52
+ * Whether a session in a priced pool has no price yet, so `cost` is a lower bound. Always false
53
+ * in the ChatGPT plan.
54
+ */
55
+ unpriced: Schema.Boolean,
56
+ }) {
57
+ }
58
+ /**
59
+ * A Task's usage over every Run on its Items: Attempt wall time, and tokens and cost per billing
60
+ * pool.
61
+ */
62
+ export class TaskUsageView extends Schema.Class("@usine/orchestrator/TaskUsageView")({
63
+ /** The summed wall time of ended Attempts, each from start to recorded end. */
64
+ durationMillis: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
65
+ /** The start times of running Attempts; add the time since each to `durationMillis`. */
66
+ runningSince: Schema.Array(Schema.String),
67
+ /** The number of ended Attempts with no recorded end, excluded from `durationMillis`. */
68
+ unmeasured: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
69
+ tokens: TokenCount,
70
+ /**
71
+ * Each pool summed over the Runs, in the order API keys, Claude plan, ChatGPT plan; unused
72
+ * pools are absent.
73
+ */
74
+ pools: Schema.Array(TaskPoolUsageView),
75
+ /**
76
+ * The summed cost of the priced pools, or null if no pool has a price. It's an estimate if it
77
+ * includes the Claude plan, and a lower bound if a pool is `unpriced`.
78
+ */
79
+ cost: Schema.NullOr(UsageCostView),
80
+ }) {
81
+ }
82
+ const POOLS = ["apiKeys", "claudePlan", "chatgptPlan"];
83
+ const priced = (pool, usd) => pool === "chatgptPlan"
84
+ ? null
85
+ : Option.match(usd, {
86
+ onNone: () => null,
87
+ onSome: (value) => new UsageCostView({ usd: value, estimate: pool === "claudePlan" }),
88
+ });
89
+ /**
90
+ * Sums a Run's token reports per pool and for the Run, using each session's highest report because
91
+ * reports are cumulative.
92
+ */
93
+ const runUsage = (reports) => {
94
+ const highest = new Map();
95
+ for (const { attemptId, envelope } of reports) {
96
+ const payload = envelope.payload;
97
+ if (payload._tag !== "SessionEvent" || payload.event._tag !== "SessionTokensUpdated")
98
+ continue;
99
+ const { session, totalTokens, costUsd } = payload.event;
100
+ const key = `${attemptId} ${session.id}`;
101
+ const previous = highest.get(key);
102
+ if (previous !== undefined && previous.tokens >= totalTokens)
103
+ continue;
104
+ const pool = sessionPool(session);
105
+ highest.set(key, new SessionUsageView({
106
+ attemptId,
107
+ session,
108
+ pool,
109
+ tokens: totalTokens,
110
+ cost: priced(pool, costUsd),
111
+ }));
112
+ }
113
+ const sessions = [...highest.values()];
114
+ const pools = POOLS.flatMap((pool) => {
115
+ const members = sessions.filter((session) => session.pool === pool);
116
+ if (members.length === 0)
117
+ return [];
118
+ const costs = members.flatMap(({ cost }) => (cost === null ? [] : [cost.usd]));
119
+ return [
120
+ new PoolUsageView({
121
+ pool,
122
+ tokens: TokenCount.make(members.reduce((sum, { tokens }) => sum + tokens, 0)),
123
+ cost: priced(pool, costs.length === members.length
124
+ ? Option.some(UsdAmount.make(costs.reduce((sum, usd) => sum + usd, 0)))
125
+ : Option.none()),
126
+ }),
127
+ ];
128
+ });
129
+ return new RunUsageView({
130
+ tokens: TokenCount.make(sessions.reduce((sum, { tokens }) => sum + tokens, 0)),
131
+ pools,
132
+ sessions,
133
+ });
134
+ };
135
+ /**
136
+ * Sums the Attempt time, tokens, and cost of a Task's `runs`. Pools sum sessions rather than Run
137
+ * pools, so priced sessions count even when another session is unpriced, which sets `unpriced`.
138
+ */
139
+ export const taskUsage = (runs, usage) => {
140
+ let durationMillis = 0;
141
+ let unmeasured = 0;
142
+ const runningSince = [];
143
+ for (const { attempts } of runs) {
144
+ for (const { startedAt, endedAt, outcome } of attempts) {
145
+ if (outcome === null)
146
+ runningSince.push(startedAt);
147
+ else if (endedAt === null)
148
+ unmeasured += 1;
149
+ else
150
+ durationMillis += Math.max(0, Date.parse(endedAt) - Date.parse(startedAt));
151
+ }
152
+ }
153
+ const sessions = runs.flatMap(({ id }) => usage.get(id)?.sessions ?? []);
154
+ const pools = POOLS.flatMap((pool) => {
155
+ const members = sessions.filter((session) => session.pool === pool);
156
+ if (members.length === 0)
157
+ return [];
158
+ const costs = members.flatMap(({ cost }) => (cost === null ? [] : [cost.usd]));
159
+ return [
160
+ new TaskPoolUsageView({
161
+ pool,
162
+ tokens: TokenCount.make(members.reduce((sum, { tokens }) => sum + tokens, 0)),
163
+ cost: priced(pool, costs.length === 0
164
+ ? Option.none()
165
+ : Option.some(UsdAmount.make(costs.reduce((sum, usd) => sum + usd, 0)))),
166
+ unpriced: pool !== "chatgptPlan" && costs.length < members.length,
167
+ }),
168
+ ];
169
+ });
170
+ const costs = pools.flatMap(({ cost }) => (cost === null ? [] : [cost]));
171
+ return new TaskUsageView({
172
+ durationMillis: Math.round(durationMillis),
173
+ runningSince,
174
+ unmeasured,
175
+ tokens: TokenCount.make(sessions.reduce((sum, { tokens }) => sum + tokens, 0)),
176
+ pools,
177
+ cost: costs.length === 0
178
+ ? null
179
+ : new UsageCostView({
180
+ usd: UsdAmount.make(costs.reduce((sum, { usd }) => sum + usd, 0)),
181
+ estimate: costs.some(({ estimate }) => estimate),
182
+ }),
183
+ });
184
+ };
185
+ const makeRunUsageReader = Effect.gen(function* () {
186
+ const runs = yield* RunReader;
187
+ const ended = yield* Effect.sync(() => new Map());
188
+ const attemptReports = Effect.fn("RunUsageReader.attemptReports")(function* (attempt) {
189
+ const cached = ended.get(attempt.id);
190
+ if (cached !== undefined)
191
+ return { reports: cached, read: false };
192
+ const reports = yield* runs.transcript(new TranscriptUsageQuery({ attemptId: attempt.id }));
193
+ if (Option.isSome(attempt.outcome))
194
+ ended.set(attempt.id, reports);
195
+ return { reports, read: true };
196
+ });
197
+ const read = Effect.fn("RunUsageReader.read")(function* (snapshot) {
198
+ yield* Effect.annotateCurrentSpan({ runId: snapshot.run.id });
199
+ const attempts = yield* Effect.forEach(snapshot.attempts, attemptReports, { concurrency: 4 });
200
+ const usage = runUsage(attempts.flatMap(({ reports }) => reports));
201
+ yield* Effect.logDebug("Read Run usage", {
202
+ runId: snapshot.run.id,
203
+ sessions: usage.sessions.length,
204
+ tokens: usage.tokens,
205
+ attemptsRead: attempts.filter(({ read: queried }) => queried).length,
206
+ attemptsCached: attempts.filter(({ read: queried }) => !queried).length,
207
+ });
208
+ return usage;
209
+ });
210
+ return { read };
211
+ });
212
+ /**
213
+ * Reads a Run's usage from each session's highest token report. Caches the reports of Attempts with
214
+ * an outcome and rereads running Attempts on every call.
215
+ */
216
+ export class RunUsageReader extends Context.Service()("@usine/orchestrator/RunUsageReader") {
217
+ static layer = Layer.effect(RunUsageReader, makeRunUsageReader);
218
+ }
219
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/operator/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,WAAW,EACX,WAAW,EACX,UAAU,EACV,SAAS,GACV,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAgB,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAG9D,OAAO,EAAE,SAAS,EAAoB,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAwB,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACtF,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhE;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,MAAM,CAAC,KAAK,CAAgB,mCAAmC,CAAC,CACjG,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,OAAO,EAAE,CAC7C;CAAG;AAEJ,uFAAuF;AACvF,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,KAAK,CAChD,sCAAsC,CAC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B,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,MAAM;YACpE,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM;SACxE,CAAC,CAAC;QACH,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,IAAI,EAAE,CAAC;AAClB,CAAC,CAAC,CAAC;AAIH;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,OAAO,CAAC,OAAO,EAGhD,CAAC,oCAAoC,CAAC;IACvC,MAAM,CAAU,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;CAC1E"}
@@ -1,14 +1,17 @@
1
- import type { LoadedInstance } from "@usine/config/instance";
2
1
  import { Context, Effect, Layer } from "effect";
2
+ import { CurrentInstance } from "./current-instance/current-instance.ts";
3
3
  import { PollingTriggers } from "./polling-triggers.ts";
4
4
  import { ScheduleTriggers } from "./schedule-triggers.ts";
5
5
  declare const Orchestrator_base: Context.ServiceClass<Orchestrator, "@usine/orchestrator/Orchestrator", {
6
- /** Evaluates the supplied instance's triggers until interrupted, using that snapshot of its Loops and roster. */
7
- readonly run: (instance: LoadedInstance) => Effect.Effect<never>;
6
+ /**
7
+ * Evaluates the triggers until interrupted. Each cycle reads the current instance, and an
8
+ * accepted reload starts the next poll and schedule evaluation immediately.
9
+ */
10
+ readonly run: Effect.Effect<never>;
8
11
  }>;
9
- /** Coordinates polling and schedule triggers for one loaded factory instance. */
12
+ /** Coordinates polling and schedule triggers for the factory's current instance. */
10
13
  export declare class Orchestrator extends Orchestrator_base {
11
- static readonly layer: Layer.Layer<Orchestrator, never, PollingTriggers | ScheduleTriggers>;
14
+ static readonly layer: Layer.Layer<Orchestrator, never, CurrentInstance | PollingTriggers | ScheduleTriggers>;
12
15
  }
13
16
  export {};
14
17
  //# sourceMappingURL=orchestrator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;;IAgBtD,iHAAiH;kBACnG,CAAC,QAAQ,EAAE,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;;AALpE,iFAAiF;AACjF,qBAAa,YAAa,SAAQ,iBAMK;IACrC,MAAM,CAAC,QAAQ,CAAC,KAAK,uEAAgD;CACtE"}
1
+ {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;;IAmBtD;;;OAGG;kBACW,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;;AARtC,oFAAoF;AACpF,qBAAa,YAAa,SAAQ,iBASK;IACrC,MAAM,CAAC,QAAQ,CAAC,KAAK,yFAAgD;CACtE"}
@@ -1,13 +1,15 @@
1
1
  import { Context, Effect, Layer } from "effect";
2
+ import { CurrentInstance } from "./current-instance/current-instance.js";
2
3
  import { PollingTriggers } from "./polling-triggers.js";
3
4
  import { ScheduleTriggers } from "./schedule-triggers.js";
4
5
  const makeOrchestrator = Effect.gen(function* () {
5
6
  const polling = yield* PollingTriggers;
6
7
  const schedules = yield* ScheduleTriggers;
7
- const run = (instance) => Effect.raceFirst(polling.run(instance), schedules.run(instance));
8
+ const instances = yield* CurrentInstance;
9
+ const run = Effect.raceFirst(polling.run(instances), schedules.run(instances));
8
10
  return { run };
9
11
  });
10
- /** Coordinates polling and schedule triggers for one loaded factory instance. */
12
+ /** Coordinates polling and schedule triggers for the factory's current instance. */
11
13
  export class Orchestrator extends Context.Service()("@usine/orchestrator/Orchestrator") {
12
14
  static layer = Layer.effect(Orchestrator, makeOrchestrator);
13
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC3C,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,eAAe,CAAC;IACvC,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,gBAAgB,CAAC;IAE1C,MAAM,GAAG,GAAG,CAAC,QAAwB,EAAwB,EAAE,CAC7D,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEnE,OAAO,EAAE,GAAG,EAAW,CAAC;AAC1B,CAAC,CAAC,CAAC;AAEH,iFAAiF;AACjF,MAAM,OAAO,YAAa,SAAQ,OAAO,CAAC,OAAO,EAM9C,CAAC,kCAAkC,CAAC;IACrC,MAAM,CAAU,KAAK,GAAG,KAAK,CAAC,MAAM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