@autonome-research/thread-phase 3.0.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 +21 -0
- package/README.md +226 -0
- package/dist/agent/index.d.ts +28 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +28 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/openai-adapter.d.ts +15 -0
- package/dist/agent/openai-adapter.d.ts.map +1 -0
- package/dist/agent/openai-adapter.js +57 -0
- package/dist/agent/openai-adapter.js.map +1 -0
- package/dist/agent/parse-json.d.ts +12 -0
- package/dist/agent/parse-json.d.ts.map +1 -0
- package/dist/agent/parse-json.js +31 -0
- package/dist/agent/parse-json.js.map +1 -0
- package/dist/agent/retry.d.ts +15 -0
- package/dist/agent/retry.d.ts.map +1 -0
- package/dist/agent/retry.js +35 -0
- package/dist/agent/retry.js.map +1 -0
- package/dist/agent/runner.d.ts +25 -0
- package/dist/agent/runner.d.ts.map +1 -0
- package/dist/agent/runner.js +270 -0
- package/dist/agent/runner.js.map +1 -0
- package/dist/agent/stream-consumer.d.ts +57 -0
- package/dist/agent/stream-consumer.d.ts.map +1 -0
- package/dist/agent/stream-consumer.js +126 -0
- package/dist/agent/stream-consumer.js.map +1 -0
- package/dist/agent/types.d.ts +135 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +9 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/agent-runner.d.ts +10 -0
- package/dist/agent-runner.d.ts.map +1 -0
- package/dist/agent-runner.js +10 -0
- package/dist/agent-runner.js.map +1 -0
- package/dist/agents/capability.d.ts +36 -0
- package/dist/agents/capability.d.ts.map +1 -0
- package/dist/agents/capability.js +51 -0
- package/dist/agents/capability.js.map +1 -0
- package/dist/agents/event-bus.d.ts +20 -0
- package/dist/agents/event-bus.d.ts.map +1 -0
- package/dist/agents/event-bus.js +40 -0
- package/dist/agents/event-bus.js.map +1 -0
- package/dist/agents/index.d.ts +23 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +33 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/inference-adapter.d.ts +52 -0
- package/dist/agents/inference-adapter.d.ts.map +1 -0
- package/dist/agents/inference-adapter.js +209 -0
- package/dist/agents/inference-adapter.js.map +1 -0
- package/dist/agents/job-store-bridge.d.ts +44 -0
- package/dist/agents/job-store-bridge.d.ts.map +1 -0
- package/dist/agents/job-store-bridge.js +58 -0
- package/dist/agents/job-store-bridge.js.map +1 -0
- package/dist/agents/memory.d.ts +40 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/memory.js +14 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/protocol.d.ts +302 -0
- package/dist/agents/protocol.d.ts.map +1 -0
- package/dist/agents/protocol.js +36 -0
- package/dist/agents/protocol.js.map +1 -0
- package/dist/agents/run-helpers.d.ts +70 -0
- package/dist/agents/run-helpers.d.ts.map +1 -0
- package/dist/agents/run-helpers.js +131 -0
- package/dist/agents/run-helpers.js.map +1 -0
- package/dist/agents/serialize-error.d.ts +18 -0
- package/dist/agents/serialize-error.d.ts.map +1 -0
- package/dist/agents/serialize-error.js +27 -0
- package/dist/agents/serialize-error.js.map +1 -0
- package/dist/agents/structured-output.d.ts +90 -0
- package/dist/agents/structured-output.d.ts.map +1 -0
- package/dist/agents/structured-output.js +101 -0
- package/dist/agents/structured-output.js.map +1 -0
- package/dist/agents/test-utils/conformance.d.ts +59 -0
- package/dist/agents/test-utils/conformance.d.ts.map +1 -0
- package/dist/agents/test-utils/conformance.js +207 -0
- package/dist/agents/test-utils/conformance.js.map +1 -0
- package/dist/agents/test-utils/index.d.ts +12 -0
- package/dist/agents/test-utils/index.d.ts.map +1 -0
- package/dist/agents/test-utils/index.js +12 -0
- package/dist/agents/test-utils/index.js.map +1 -0
- package/dist/agents/test-utils/mock-agent.d.ts +66 -0
- package/dist/agents/test-utils/mock-agent.d.ts.map +1 -0
- package/dist/agents/test-utils/mock-agent.js +244 -0
- package/dist/agents/test-utils/mock-agent.js.map +1 -0
- package/dist/agents/thread.d.ts +57 -0
- package/dist/agents/thread.d.ts.map +1 -0
- package/dist/agents/thread.js +128 -0
- package/dist/agents/thread.js.map +1 -0
- package/dist/agents/turn-accumulator.d.ts +94 -0
- package/dist/agents/turn-accumulator.d.ts.map +1 -0
- package/dist/agents/turn-accumulator.js +150 -0
- package/dist/agents/turn-accumulator.js.map +1 -0
- package/dist/agents/with-memory.d.ts +55 -0
- package/dist/agents/with-memory.d.ts.map +1 -0
- package/dist/agents/with-memory.js +155 -0
- package/dist/agents/with-memory.js.map +1 -0
- package/dist/agents/with-thread.d.ts +45 -0
- package/dist/agents/with-thread.d.ts.map +1 -0
- package/dist/agents/with-thread.js +70 -0
- package/dist/agents/with-thread.js.map +1 -0
- package/dist/cache.d.ts +47 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +81 -0
- package/dist/cache.js.map +1 -0
- package/dist/context/compressor.d.ts +36 -0
- package/dist/context/compressor.d.ts.map +1 -0
- package/dist/context/compressor.js +158 -0
- package/dist/context/compressor.js.map +1 -0
- package/dist/context/index.d.ts +4 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +4 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/result-capper.d.ts +32 -0
- package/dist/context/result-capper.d.ts.map +1 -0
- package/dist/context/result-capper.js +50 -0
- package/dist/context/result-capper.js.map +1 -0
- package/dist/context/token-budget.d.ts +81 -0
- package/dist/context/token-budget.d.ts.map +1 -0
- package/dist/context/token-budget.js +99 -0
- package/dist/context/token-budget.js.map +1 -0
- package/dist/helpers/caller.d.ts +18 -0
- package/dist/helpers/caller.d.ts.map +1 -0
- package/dist/helpers/caller.js +40 -0
- package/dist/helpers/caller.js.map +1 -0
- package/dist/helpers/hook.d.ts +73 -0
- package/dist/helpers/hook.d.ts.map +1 -0
- package/dist/helpers/hook.js +244 -0
- package/dist/helpers/hook.js.map +1 -0
- package/dist/helpers/index.d.ts +12 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +11 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/one-shot.d.ts +27 -0
- package/dist/helpers/one-shot.d.ts.map +1 -0
- package/dist/helpers/one-shot.js +43 -0
- package/dist/helpers/one-shot.js.map +1 -0
- package/dist/helpers/schedule.d.ts +59 -0
- package/dist/helpers/schedule.d.ts.map +1 -0
- package/dist/helpers/schedule.js +118 -0
- package/dist/helpers/schedule.js.map +1 -0
- package/dist/helpers/types.d.ts +34 -0
- package/dist/helpers/types.d.ts.map +1 -0
- package/dist/helpers/types.js +11 -0
- package/dist/helpers/types.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/inference.d.ts +27 -0
- package/dist/inference.d.ts.map +1 -0
- package/dist/inference.js +34 -0
- package/dist/inference.js.map +1 -0
- package/dist/messages.d.ts +64 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +17 -0
- package/dist/messages.js.map +1 -0
- package/dist/orchestrator.d.ts +56 -0
- package/dist/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator.js +62 -0
- package/dist/orchestrator.js.map +1 -0
- package/dist/patterns/bounded-fanout-of.d.ts +61 -0
- package/dist/patterns/bounded-fanout-of.d.ts.map +1 -0
- package/dist/patterns/bounded-fanout-of.js +142 -0
- package/dist/patterns/bounded-fanout-of.js.map +1 -0
- package/dist/patterns/bounded-fanout.d.ts +111 -0
- package/dist/patterns/bounded-fanout.d.ts.map +1 -0
- package/dist/patterns/bounded-fanout.js +151 -0
- package/dist/patterns/bounded-fanout.js.map +1 -0
- package/dist/patterns/index.d.ts +14 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +13 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/intent-gate.d.ts +27 -0
- package/dist/patterns/intent-gate.d.ts.map +1 -0
- package/dist/patterns/intent-gate.js +32 -0
- package/dist/patterns/intent-gate.js.map +1 -0
- package/dist/patterns/match.d.ts +30 -0
- package/dist/patterns/match.d.ts.map +1 -0
- package/dist/patterns/match.js +58 -0
- package/dist/patterns/match.js.map +1 -0
- package/dist/patterns/parallel-fanout.d.ts +28 -0
- package/dist/patterns/parallel-fanout.d.ts.map +1 -0
- package/dist/patterns/parallel-fanout.js +24 -0
- package/dist/patterns/parallel-fanout.js.map +1 -0
- package/dist/patterns/parallel-phases.d.ts +27 -0
- package/dist/patterns/parallel-phases.d.ts.map +1 -0
- package/dist/patterns/parallel-phases.js +77 -0
- package/dist/patterns/parallel-phases.js.map +1 -0
- package/dist/patterns/preflight-confidence.d.ts +20 -0
- package/dist/patterns/preflight-confidence.d.ts.map +1 -0
- package/dist/patterns/preflight-confidence.js +38 -0
- package/dist/patterns/preflight-confidence.js.map +1 -0
- package/dist/patterns/spot-check.d.ts +19 -0
- package/dist/patterns/spot-check.d.ts.map +1 -0
- package/dist/patterns/spot-check.js +33 -0
- package/dist/patterns/spot-check.js.map +1 -0
- package/dist/patterns/sub-pipeline.d.ts +84 -0
- package/dist/patterns/sub-pipeline.d.ts.map +1 -0
- package/dist/patterns/sub-pipeline.js +90 -0
- package/dist/patterns/sub-pipeline.js.map +1 -0
- package/dist/patterns/synthesize-with-followup.d.ts +35 -0
- package/dist/patterns/synthesize-with-followup.d.ts.map +1 -0
- package/dist/patterns/synthesize-with-followup.js +45 -0
- package/dist/patterns/synthesize-with-followup.js.map +1 -0
- package/dist/patterns/while-condition.d.ts +31 -0
- package/dist/patterns/while-condition.d.ts.map +1 -0
- package/dist/patterns/while-condition.js +59 -0
- package/dist/patterns/while-condition.js.map +1 -0
- package/dist/patterns/with-retry.d.ts +37 -0
- package/dist/patterns/with-retry.d.ts.map +1 -0
- package/dist/patterns/with-retry.js +73 -0
- package/dist/patterns/with-retry.js.map +1 -0
- package/dist/phase.d.ts +78 -0
- package/dist/phase.d.ts.map +1 -0
- package/dist/phase.js +36 -0
- package/dist/phase.js.map +1 -0
- package/dist/session/index.d.ts +5 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +4 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/job-runner.d.ts +67 -0
- package/dist/session/job-runner.d.ts.map +1 -0
- package/dist/session/job-runner.js +131 -0
- package/dist/session/job-runner.js.map +1 -0
- package/dist/session/job-store.d.ts +98 -0
- package/dist/session/job-store.d.ts.map +1 -0
- package/dist/session/job-store.js +37 -0
- package/dist/session/job-store.js.map +1 -0
- package/dist/session/sqlite-job-store.d.ts +40 -0
- package/dist/session/sqlite-job-store.d.ts.map +1 -0
- package/dist/session/sqlite-job-store.js +200 -0
- package/dist/session/sqlite-job-store.js.map +1 -0
- package/dist/session/sse.d.ts +60 -0
- package/dist/session/sse.d.ts.map +1 -0
- package/dist/session/sse.js +97 -0
- package/dist/session/sse.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +44 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +74 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/triggers/index.d.ts +15 -0
- package/dist/triggers/index.d.ts.map +1 -0
- package/dist/triggers/index.js +14 -0
- package/dist/triggers/index.js.map +1 -0
- package/dist/triggers/run-trigger.d.ts +86 -0
- package/dist/triggers/run-trigger.d.ts.map +1 -0
- package/dist/triggers/run-trigger.js +146 -0
- package/dist/triggers/run-trigger.js.map +1 -0
- package/dist/triggers/timer-trigger.d.ts +46 -0
- package/dist/triggers/timer-trigger.d.ts.map +1 -0
- package/dist/triggers/timer-trigger.js +74 -0
- package/dist/triggers/timer-trigger.js.map +1 -0
- package/dist/triggers/types.d.ts +61 -0
- package/dist/triggers/types.d.ts.map +1 -0
- package/dist/triggers/types.js +23 -0
- package/dist/triggers/types.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runTrigger — the canonical Trigger consumer.
|
|
3
|
+
*
|
|
4
|
+
* Reads events from a `Trigger`, calls a user-supplied factory to produce
|
|
5
|
+
* `{ phases, ctx }` per event, and dispatches each pipeline. If a
|
|
6
|
+
* `JobRunner` is supplied, dispatch is persisted (job rows, event log,
|
|
7
|
+
* cancellation); otherwise the pipeline runs inline via
|
|
8
|
+
* `runPipelineToSummary` and events are discarded after dispatch.
|
|
9
|
+
*
|
|
10
|
+
* Resolves when the trigger generator exhausts, the abort signal fires,
|
|
11
|
+
* or `stop()` is called via the returned handle.
|
|
12
|
+
*
|
|
13
|
+
* Concurrency cap is a blocking semaphore. When `maxConcurrency` pipelines
|
|
14
|
+
* are in flight, the loop awaits a slot before pulling the next event
|
|
15
|
+
* from the trigger. The trigger's generator naturally pauses production
|
|
16
|
+
* — no events are dropped, no unbounded queue grows.
|
|
17
|
+
*
|
|
18
|
+
* Pipeline failures are isolated — one failing pipeline does not stop
|
|
19
|
+
* the trigger loop. Errors go through `onError` (or default stderr log)
|
|
20
|
+
* and the next event is still dispatched.
|
|
21
|
+
*
|
|
22
|
+
* Cancellation: each in-flight dispatch owns an `AbortController`. Call
|
|
23
|
+
* `handle.cancel(triggerEventId)` to abort that specific pipeline; the
|
|
24
|
+
* signal flows into `runPipelineToSummary` (inline) or `jobRunner.cancel`
|
|
25
|
+
* (persisted). Returns `true` if the pipeline was found and aborted,
|
|
26
|
+
* `false` if the event id is unknown or already completed.
|
|
27
|
+
*
|
|
28
|
+
* Observability: `onCapacityFull(event)` fires when an event arrives
|
|
29
|
+
* while the concurrency cap is full (the loop blocks on `Promise.race`
|
|
30
|
+
* before pulling the event, so this is the moment backpressure starts).
|
|
31
|
+
* `onDispatchStart(event)` fires immediately when a dispatch begins,
|
|
32
|
+
* before the user-supplied factory runs.
|
|
33
|
+
*/
|
|
34
|
+
import { runPipelineToSummary } from '../orchestrator.js';
|
|
35
|
+
export function runTrigger(trigger, pipelineFactory, options = {}) {
|
|
36
|
+
const maxConcurrency = options.maxConcurrency ?? 1;
|
|
37
|
+
const pipelineName = options.pipelineName ?? trigger.name;
|
|
38
|
+
const onError = options.onError ??
|
|
39
|
+
((event, err) => {
|
|
40
|
+
console.error(`[trigger:${trigger.name}] event ${event.id} failed:`, err.message);
|
|
41
|
+
});
|
|
42
|
+
const inflight = new Map();
|
|
43
|
+
let aborted = false;
|
|
44
|
+
const dispatch = (event) => {
|
|
45
|
+
options.onDispatchStart?.(event);
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
const { phases, ctx } = pipelineFactory(event.input, event);
|
|
48
|
+
// Wire the per-dispatch signal into ctx so phases can observe it for
|
|
49
|
+
// mid-phase cancellation (in addition to runPipeline's between-phase
|
|
50
|
+
// check via the same signal forwarded below).
|
|
51
|
+
ctx.signal = controller.signal;
|
|
52
|
+
let jobId;
|
|
53
|
+
const work = (async () => {
|
|
54
|
+
try {
|
|
55
|
+
if (options.jobRunner) {
|
|
56
|
+
jobId = await options.jobRunner.create(pipelineName, {
|
|
57
|
+
triggerName: trigger.name,
|
|
58
|
+
triggerEventId: event.id,
|
|
59
|
+
occurredAt: event.occurredAt,
|
|
60
|
+
input: event.input,
|
|
61
|
+
metadata: event.metadata,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
options.onStart?.(event, jobId);
|
|
65
|
+
if (options.jobRunner && jobId) {
|
|
66
|
+
// JobRunner has its own controller per job (signalFor / cancel).
|
|
67
|
+
// The dispatch's AbortController is wired so handle.cancel(eventId)
|
|
68
|
+
// delegates to jobRunner.cancel(jobId).
|
|
69
|
+
const jobIdAtRun = jobId;
|
|
70
|
+
controller.signal.addEventListener('abort', () => {
|
|
71
|
+
options.jobRunner.cancel(jobIdAtRun, controller.signal.reason ?? 'cancelled');
|
|
72
|
+
}, { once: true });
|
|
73
|
+
await options.jobRunner.run(jobId, phases, ctx);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Inline path: forward the signal to runPipelineToSummary so
|
|
77
|
+
// phase code that observes it (or the orchestrator's pre-phase
|
|
78
|
+
// check) can unwind cleanly.
|
|
79
|
+
await runPipelineToSummary(phases, ctx, { signal: controller.signal });
|
|
80
|
+
}
|
|
81
|
+
options.onComplete?.(event, jobId);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
85
|
+
onError(event, error, jobId);
|
|
86
|
+
}
|
|
87
|
+
})();
|
|
88
|
+
inflight.set(event.id, { controller, promise: work, jobId });
|
|
89
|
+
work.finally(() => inflight.delete(event.id));
|
|
90
|
+
return work;
|
|
91
|
+
};
|
|
92
|
+
const stop = async () => {
|
|
93
|
+
if (aborted)
|
|
94
|
+
return;
|
|
95
|
+
aborted = true;
|
|
96
|
+
await trigger.stop();
|
|
97
|
+
};
|
|
98
|
+
if (options.signal) {
|
|
99
|
+
if (options.signal.aborted) {
|
|
100
|
+
void stop();
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
options.signal.addEventListener('abort', () => void stop(), { once: true });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const loop = async () => {
|
|
107
|
+
const gen = trigger.start();
|
|
108
|
+
try {
|
|
109
|
+
for await (const event of gen) {
|
|
110
|
+
if (aborted)
|
|
111
|
+
break;
|
|
112
|
+
// Block until a concurrency slot is available — backpressure flows
|
|
113
|
+
// back to the trigger by way of the generator pausing. If we have
|
|
114
|
+
// to wait, fire onCapacityFull so the user knows.
|
|
115
|
+
if (inflight.size >= maxConcurrency) {
|
|
116
|
+
options.onCapacityFull?.(event);
|
|
117
|
+
}
|
|
118
|
+
while (inflight.size >= maxConcurrency && !aborted) {
|
|
119
|
+
await Promise.race(Array.from(inflight.values()).map((d) => d.promise));
|
|
120
|
+
}
|
|
121
|
+
if (aborted)
|
|
122
|
+
break;
|
|
123
|
+
void dispatch(event);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
// Wait for any in-flight pipelines to settle before resolving.
|
|
128
|
+
await Promise.allSettled(Array.from(inflight.values()).map((d) => d.promise));
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const cancel = (triggerEventId) => {
|
|
132
|
+
const dispatchRec = inflight.get(triggerEventId);
|
|
133
|
+
if (!dispatchRec)
|
|
134
|
+
return false;
|
|
135
|
+
if (dispatchRec.controller.signal.aborted)
|
|
136
|
+
return false;
|
|
137
|
+
dispatchRec.controller.abort('cancelled by handle');
|
|
138
|
+
return true;
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
done: loop(),
|
|
142
|
+
stop,
|
|
143
|
+
cancel,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=run-trigger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-trigger.js","sourceRoot":"","sources":["../../src/triggers/run-trigger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AA4D1D,MAAM,UAAU,UAAU,CACxB,OAAwB,EACxB,eAGC,EACD,UAA2C,EAAE;IAE7C,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,CAAC,CAAC;IACnD,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAE1D,MAAM,OAAO,GACX,OAAO,CAAC,OAAO;QACf,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACd,OAAO,CAAC,KAAK,CACX,YAAY,OAAO,CAAC,IAAI,WAAW,KAAK,CAAC,EAAE,UAAU,EACrD,GAAG,CAAC,OAAO,CACZ,CAAC;QACJ,CAAC,CAAC,CAAC;IAEL,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAoB,CA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QACjD,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACjD,IAAI,CAAC,WAAW;YAAE,OAAO,KAAK,CAAC;QAC/B,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO;YAAE,OAAO,KAAK,CAAC;QACxD,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACpD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,IAAI,EAAE;QACZ,IAAI;QACJ,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TimerTrigger — fires at a fixed interval.
|
|
3
|
+
*
|
|
4
|
+
* The canonical scheduled-pipeline source. Replaces `setInterval(() => ..., 60_000)`
|
|
5
|
+
* with the Trigger protocol so the same pipeline-dispatch code works for
|
|
6
|
+
* timer-, webhook-, and queue-driven flows.
|
|
7
|
+
*
|
|
8
|
+
* No cron expression support in core — keep the impl tiny. For cron, wrap
|
|
9
|
+
* a cron parser (e.g. `croner`) and produce events on its schedule;
|
|
10
|
+
* `examples/triggers/timer-with-cron.ts` shows the shape.
|
|
11
|
+
*/
|
|
12
|
+
import type { Trigger, TriggerEvent } from './types.js';
|
|
13
|
+
export interface TimerTriggerOptions<TInput = void> {
|
|
14
|
+
/** Interval between fires, in milliseconds. */
|
|
15
|
+
intervalMs: number;
|
|
16
|
+
/**
|
|
17
|
+
* Payload to attach to each event. Defaults to `undefined`. If a
|
|
18
|
+
* function, called each fire to produce a fresh payload (e.g. the
|
|
19
|
+
* current time, a counter, a snapshot from somewhere).
|
|
20
|
+
*/
|
|
21
|
+
payload?: TInput | (() => TInput) | (() => Promise<TInput>);
|
|
22
|
+
/**
|
|
23
|
+
* If true, fires immediately on `start()` before the first interval
|
|
24
|
+
* elapses. Default: false (first event arrives after one interval).
|
|
25
|
+
*/
|
|
26
|
+
fireImmediately?: boolean;
|
|
27
|
+
/** Stable identifier used for logs. Default: `timer:${intervalMs}ms`. */
|
|
28
|
+
name?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare class TimerTrigger<TInput = void> implements Trigger<TInput> {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
private readonly intervalMs;
|
|
33
|
+
private readonly payload;
|
|
34
|
+
private readonly fireImmediately;
|
|
35
|
+
private seq;
|
|
36
|
+
private stopped;
|
|
37
|
+
private pendingTimer;
|
|
38
|
+
private notifyStop;
|
|
39
|
+
constructor(options: TimerTriggerOptions<TInput>);
|
|
40
|
+
start(): AsyncGenerator<TriggerEvent<TInput>, void>;
|
|
41
|
+
stop(): Promise<void>;
|
|
42
|
+
private makeEvent;
|
|
43
|
+
/** Returns true if the interval elapsed normally, false if stop() fired first. */
|
|
44
|
+
private waitOrStop;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=timer-trigger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer-trigger.d.ts","sourceRoot":"","sources":["../../src/triggers/timer-trigger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,WAAW,mBAAmB,CAAC,MAAM,GAAG,IAAI;IAChD,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5D;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,YAAY,CAAC,MAAM,GAAG,IAAI,CAAE,YAAW,OAAO,CAAC,MAAM,CAAC;IACjE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyC;IACjE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAU;IAE1C,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAA8C;IAClE,OAAO,CAAC,UAAU,CAA6B;gBAEnC,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC;IAOzC,KAAK,IAAI,cAAc,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC;IAepD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAWb,SAAS;IAavB,kFAAkF;IAClF,OAAO,CAAC,UAAU;CAUnB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TimerTrigger — fires at a fixed interval.
|
|
3
|
+
*
|
|
4
|
+
* The canonical scheduled-pipeline source. Replaces `setInterval(() => ..., 60_000)`
|
|
5
|
+
* with the Trigger protocol so the same pipeline-dispatch code works for
|
|
6
|
+
* timer-, webhook-, and queue-driven flows.
|
|
7
|
+
*
|
|
8
|
+
* No cron expression support in core — keep the impl tiny. For cron, wrap
|
|
9
|
+
* a cron parser (e.g. `croner`) and produce events on its schedule;
|
|
10
|
+
* `examples/triggers/timer-with-cron.ts` shows the shape.
|
|
11
|
+
*/
|
|
12
|
+
export class TimerTrigger {
|
|
13
|
+
name;
|
|
14
|
+
intervalMs;
|
|
15
|
+
payload;
|
|
16
|
+
fireImmediately;
|
|
17
|
+
seq = 0;
|
|
18
|
+
stopped = false;
|
|
19
|
+
pendingTimer = null;
|
|
20
|
+
notifyStop = null;
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.intervalMs = options.intervalMs;
|
|
23
|
+
this.payload = options.payload;
|
|
24
|
+
this.fireImmediately = options.fireImmediately ?? false;
|
|
25
|
+
this.name = options.name ?? `timer:${options.intervalMs}ms`;
|
|
26
|
+
}
|
|
27
|
+
async *start() {
|
|
28
|
+
if (this.stopped)
|
|
29
|
+
return;
|
|
30
|
+
if (this.fireImmediately) {
|
|
31
|
+
yield await this.makeEvent();
|
|
32
|
+
if (this.stopped)
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
while (!this.stopped) {
|
|
36
|
+
const waited = await this.waitOrStop();
|
|
37
|
+
if (!waited)
|
|
38
|
+
return;
|
|
39
|
+
yield await this.makeEvent();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async stop() {
|
|
43
|
+
if (this.stopped)
|
|
44
|
+
return;
|
|
45
|
+
this.stopped = true;
|
|
46
|
+
if (this.pendingTimer) {
|
|
47
|
+
clearTimeout(this.pendingTimer);
|
|
48
|
+
this.pendingTimer = null;
|
|
49
|
+
}
|
|
50
|
+
this.notifyStop?.();
|
|
51
|
+
this.notifyStop = null;
|
|
52
|
+
}
|
|
53
|
+
async makeEvent() {
|
|
54
|
+
const input = typeof this.payload === 'function'
|
|
55
|
+
? await this.payload()
|
|
56
|
+
: this.payload;
|
|
57
|
+
return {
|
|
58
|
+
id: ++this.seq,
|
|
59
|
+
occurredAt: new Date().toISOString(),
|
|
60
|
+
input,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** Returns true if the interval elapsed normally, false if stop() fired first. */
|
|
64
|
+
waitOrStop() {
|
|
65
|
+
return new Promise((resolve) => {
|
|
66
|
+
this.pendingTimer = setTimeout(() => {
|
|
67
|
+
this.pendingTimer = null;
|
|
68
|
+
resolve(true);
|
|
69
|
+
}, this.intervalMs);
|
|
70
|
+
this.notifyStop = () => resolve(false);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=timer-trigger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer-trigger.js","sourceRoot":"","sources":["../../src/triggers/timer-trigger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;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UAAU,EAAE,EAAE,CAAC;QACpB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAEO,KAAK,CAAC,SAAS;QACrB,MAAM,KAAK,GACT,OAAO,IAAI,CAAC,OAAO,KAAK,UAAU;YAChC,CAAC,CAAC,MAAO,IAAI,CAAC,OAA0C,EAAE;YAC1D,CAAC,CAAE,IAAI,CAAC,OAAkB,CAAC;QAE/B,OAAO;YACL,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG;YACd,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACpC,KAAK;SACN,CAAC;IACJ,CAAC;IAED,kFAAkF;IAC1E,UAAU;QAChB,OAAO,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,EAAE;YACtC,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,GAAG,EAAE;gBAClC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;gBACzB,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAEpB,IAAI,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trigger protocol — the entry-point abstraction.
|
|
3
|
+
*
|
|
4
|
+
* A `Trigger` is a signal source that yields typed events. A consumer
|
|
5
|
+
* (typically `runTrigger`) reads the generator and dispatches a pipeline
|
|
6
|
+
* for each event. Triggers do not know about pipelines, ctx, or the
|
|
7
|
+
* JobStore — they only know about producing events.
|
|
8
|
+
*
|
|
9
|
+
* Concrete impls in this package: `TimerTrigger`. Anything else
|
|
10
|
+
* (HTTP webhooks, queue consumers, file watchers, message brokers)
|
|
11
|
+
* lives outside core. The `examples/triggers/` tree shows how to
|
|
12
|
+
* adapt arbitrary signal sources into this interface.
|
|
13
|
+
*
|
|
14
|
+
* Design properties:
|
|
15
|
+
* - The generator yields forever until `stop()` resolves or the
|
|
16
|
+
* underlying source exhausts.
|
|
17
|
+
* - `stop()` returns a promise so resource cleanup (closing servers,
|
|
18
|
+
* clearing timers, draining buffers) can be awaited.
|
|
19
|
+
* - Each event carries an `id` monotonic within the trigger instance
|
|
20
|
+
* so consumers can deduplicate or correlate without a separate seq.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* One event produced by a trigger.
|
|
24
|
+
*
|
|
25
|
+
* `input` is the structured payload the pipeline factory will consume.
|
|
26
|
+
* `metadata` is for transport-level info (HTTP headers, source IP,
|
|
27
|
+
* queue message id, file path) that the pipeline may want for logging
|
|
28
|
+
* or auditing but doesn't shape the work.
|
|
29
|
+
*/
|
|
30
|
+
export interface TriggerEvent<TInput = unknown> {
|
|
31
|
+
/** Monotonically increasing id within this trigger instance, starting at 1. */
|
|
32
|
+
readonly id: number;
|
|
33
|
+
/** ISO timestamp at the moment the trigger observed the event. */
|
|
34
|
+
readonly occurredAt: string;
|
|
35
|
+
/** Structured payload. Pipeline factory consumes this. */
|
|
36
|
+
readonly input: TInput;
|
|
37
|
+
/** Transport-level info: headers, source IP, message id, file path, etc. */
|
|
38
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A signal source that fires pipelines.
|
|
42
|
+
*
|
|
43
|
+
* `start()` returns an async generator yielding events. The consumer
|
|
44
|
+
* controls pacing — back-pressure is the consumer's responsibility.
|
|
45
|
+
*
|
|
46
|
+
* `stop()` must idempotently clean up resources. After `stop()` resolves,
|
|
47
|
+
* the generator returned by `start()` must complete (no more yields).
|
|
48
|
+
*
|
|
49
|
+
* Implementations are single-consumer. To fan one trigger's events out
|
|
50
|
+
* to multiple consumers, build the multiplexer in user code — keeping
|
|
51
|
+
* the protocol single-consumer keeps shutdown semantics simple.
|
|
52
|
+
*/
|
|
53
|
+
export interface Trigger<TInput = unknown> {
|
|
54
|
+
/** Stable identifier used for logs and error messages. */
|
|
55
|
+
readonly name: string;
|
|
56
|
+
/** Async iterable of events. Yields until `stop()` resolves. */
|
|
57
|
+
start(): AsyncGenerator<TriggerEvent<TInput>, void>;
|
|
58
|
+
/** Release resources. Idempotent. */
|
|
59
|
+
stop(): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/triggers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY,CAAC,MAAM,GAAG,OAAO;IAC5C,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,0DAA0D;IAC1D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,4EAA4E;IAC5E,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACvD;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,OAAO,CAAC,MAAM,GAAG,OAAO;IACvC,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,KAAK,IAAI,cAAc,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IACpD,qCAAqC;IACrC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trigger protocol — the entry-point abstraction.
|
|
3
|
+
*
|
|
4
|
+
* A `Trigger` is a signal source that yields typed events. A consumer
|
|
5
|
+
* (typically `runTrigger`) reads the generator and dispatches a pipeline
|
|
6
|
+
* for each event. Triggers do not know about pipelines, ctx, or the
|
|
7
|
+
* JobStore — they only know about producing events.
|
|
8
|
+
*
|
|
9
|
+
* Concrete impls in this package: `TimerTrigger`. Anything else
|
|
10
|
+
* (HTTP webhooks, queue consumers, file watchers, message brokers)
|
|
11
|
+
* lives outside core. The `examples/triggers/` tree shows how to
|
|
12
|
+
* adapt arbitrary signal sources into this interface.
|
|
13
|
+
*
|
|
14
|
+
* Design properties:
|
|
15
|
+
* - The generator yields forever until `stop()` resolves or the
|
|
16
|
+
* underlying source exhausts.
|
|
17
|
+
* - `stop()` returns a promise so resource cleanup (closing servers,
|
|
18
|
+
* clearing timers, draining buffers) can be awaited.
|
|
19
|
+
* - Each event carries an `id` monotonic within the trigger instance
|
|
20
|
+
* so consumers can deduplicate or correlate without a separate seq.
|
|
21
|
+
*/
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/triggers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@autonome-research/thread-phase",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "TypeScript substrate for building automation workflows that coordinate AI agents. Phase ordering, typed shared state, persistence, fanout, event flow.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.js",
|
|
11
|
+
"./patterns": "./dist/patterns/index.js",
|
|
12
|
+
"./context": "./dist/context/index.js",
|
|
13
|
+
"./session": "./dist/session/index.js",
|
|
14
|
+
"./tools": "./dist/tools/index.js",
|
|
15
|
+
"./agents": "./dist/agents/index.js",
|
|
16
|
+
"./agents/test-utils": "./dist/agents/test-utils/index.js",
|
|
17
|
+
"./triggers": "./dist/triggers/index.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -p tsconfig.json",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"test:watch": "vitest",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"smoke": "tsx examples/smoke.ts"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"ajv": "^8.17.0",
|
|
33
|
+
"better-sqlite3": "^11.5.0",
|
|
34
|
+
"openai": "^4.77.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@honcho-ai/sdk": "^2.1.1",
|
|
38
|
+
"@types/better-sqlite3": "^7.6.11",
|
|
39
|
+
"@types/node": "^22.0.0",
|
|
40
|
+
"tsx": "^4.19.0",
|
|
41
|
+
"typescript": "^5.6.0",
|
|
42
|
+
"vitest": "^2.1.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"cron-parser": "^4.0.0 || ^5.0.0",
|
|
46
|
+
"vitest": "^2.1.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"cron-parser": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"vitest": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=20"
|
|
58
|
+
},
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "git+https://github.com/Code4me2/thread-phase.git",
|
|
62
|
+
"directory": "packages/thread-phase"
|
|
63
|
+
}
|
|
64
|
+
}
|