@jini-ai/daemon 0.1.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 (142) hide show
  1. package/LICENSE +201 -0
  2. package/dist/agent-executor.d.ts +458 -0
  3. package/dist/agent-executor.d.ts.map +1 -0
  4. package/dist/agent-executor.js +1277 -0
  5. package/dist/agent-executor.js.map +1 -0
  6. package/dist/artifacts/index.d.ts +14 -0
  7. package/dist/artifacts/index.d.ts.map +1 -0
  8. package/dist/artifacts/index.js +14 -0
  9. package/dist/artifacts/index.js.map +1 -0
  10. package/dist/artifacts/manifest.d.ts +90 -0
  11. package/dist/artifacts/manifest.d.ts.map +1 -0
  12. package/dist/artifacts/manifest.js +229 -0
  13. package/dist/artifacts/manifest.js.map +1 -0
  14. package/dist/artifacts/publication-guard.d.ts +28 -0
  15. package/dist/artifacts/publication-guard.d.ts.map +1 -0
  16. package/dist/artifacts/publication-guard.js +77 -0
  17. package/dist/artifacts/publication-guard.js.map +1 -0
  18. package/dist/artifacts/runtime-compat.d.ts +37 -0
  19. package/dist/artifacts/runtime-compat.d.ts.map +1 -0
  20. package/dist/artifacts/runtime-compat.js +33 -0
  21. package/dist/artifacts/runtime-compat.js.map +1 -0
  22. package/dist/artifacts/store.d.ts +85 -0
  23. package/dist/artifacts/store.d.ts.map +1 -0
  24. package/dist/artifacts/store.js +92 -0
  25. package/dist/artifacts/store.js.map +1 -0
  26. package/dist/artifacts/stub-guard.d.ts +73 -0
  27. package/dist/artifacts/stub-guard.d.ts.map +1 -0
  28. package/dist/artifacts/stub-guard.js +198 -0
  29. package/dist/artifacts/stub-guard.js.map +1 -0
  30. package/dist/artifacts/text-suppression.d.ts +68 -0
  31. package/dist/artifacts/text-suppression.d.ts.map +1 -0
  32. package/dist/artifacts/text-suppression.js +184 -0
  33. package/dist/artifacts/text-suppression.js.map +1 -0
  34. package/dist/close-status.d.ts +86 -0
  35. package/dist/close-status.d.ts.map +1 -0
  36. package/dist/close-status.js +91 -0
  37. package/dist/close-status.js.map +1 -0
  38. package/dist/continuation/continuation-transport.d.ts +41 -0
  39. package/dist/continuation/continuation-transport.d.ts.map +1 -0
  40. package/dist/continuation/continuation-transport.js +18 -0
  41. package/dist/continuation/continuation-transport.js.map +1 -0
  42. package/dist/continuation/index.d.ts +4 -0
  43. package/dist/continuation/index.d.ts.map +1 -0
  44. package/dist/continuation/index.js +4 -0
  45. package/dist/continuation/index.js.map +1 -0
  46. package/dist/continuation/journal.d.ts +37 -0
  47. package/dist/continuation/journal.d.ts.map +1 -0
  48. package/dist/continuation/journal.js +23 -0
  49. package/dist/continuation/journal.js.map +1 -0
  50. package/dist/continuation/run-start-handler.d.ts +75 -0
  51. package/dist/continuation/run-start-handler.d.ts.map +1 -0
  52. package/dist/continuation/run-start-handler.js +32 -0
  53. package/dist/continuation/run-start-handler.js.map +1 -0
  54. package/dist/delegated-tool-bridge.d.ts +53 -0
  55. package/dist/delegated-tool-bridge.d.ts.map +1 -0
  56. package/dist/delegated-tool-bridge.js +92 -0
  57. package/dist/delegated-tool-bridge.js.map +1 -0
  58. package/dist/event-log.d.ts +134 -0
  59. package/dist/event-log.d.ts.map +1 -0
  60. package/dist/event-log.js +108 -0
  61. package/dist/event-log.js.map +1 -0
  62. package/dist/frontend-capability-tools.d.ts +102 -0
  63. package/dist/frontend-capability-tools.d.ts.map +1 -0
  64. package/dist/frontend-capability-tools.js +68 -0
  65. package/dist/frontend-capability-tools.js.map +1 -0
  66. package/dist/frontend-session-registry.d.ts +127 -0
  67. package/dist/frontend-session-registry.d.ts.map +1 -0
  68. package/dist/frontend-session-registry.js +180 -0
  69. package/dist/frontend-session-registry.js.map +1 -0
  70. package/dist/index.d.ts +38 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +38 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/legacy-data-migration.d.ts +104 -0
  75. package/dist/legacy-data-migration.d.ts.map +1 -0
  76. package/dist/legacy-data-migration.js +239 -0
  77. package/dist/legacy-data-migration.js.map +1 -0
  78. package/dist/routines/index.d.ts +12 -0
  79. package/dist/routines/index.d.ts.map +1 -0
  80. package/dist/routines/index.js +12 -0
  81. package/dist/routines/index.js.map +1 -0
  82. package/dist/routines/routine-store.d.ts +77 -0
  83. package/dist/routines/routine-store.d.ts.map +1 -0
  84. package/dist/routines/routine-store.js +162 -0
  85. package/dist/routines/routine-store.js.map +1 -0
  86. package/dist/routines/schedule.d.ts +72 -0
  87. package/dist/routines/schedule.d.ts.map +1 -0
  88. package/dist/routines/schedule.js +263 -0
  89. package/dist/routines/schedule.js.map +1 -0
  90. package/dist/routines/scheduler.d.ts +34 -0
  91. package/dist/routines/scheduler.d.ts.map +1 -0
  92. package/dist/routines/scheduler.js +330 -0
  93. package/dist/routines/scheduler.js.map +1 -0
  94. package/dist/routines/types.d.ts +131 -0
  95. package/dist/routines/types.d.ts.map +1 -0
  96. package/dist/routines/types.js +9 -0
  97. package/dist/routines/types.js.map +1 -0
  98. package/dist/run/core/failure-taxonomy.d.ts +27 -0
  99. package/dist/run/core/failure-taxonomy.d.ts.map +1 -0
  100. package/dist/run/core/failure-taxonomy.js +16 -0
  101. package/dist/run/core/failure-taxonomy.js.map +1 -0
  102. package/dist/run/core/index.d.ts +5 -0
  103. package/dist/run/core/index.d.ts.map +1 -0
  104. package/dist/run/core/index.js +5 -0
  105. package/dist/run/core/index.js.map +1 -0
  106. package/dist/run/core/result.d.ts +25 -0
  107. package/dist/run/core/result.d.ts.map +1 -0
  108. package/dist/run/core/result.js +52 -0
  109. package/dist/run/core/result.js.map +1 -0
  110. package/dist/run/core/retry.d.ts +106 -0
  111. package/dist/run/core/retry.d.ts.map +1 -0
  112. package/dist/run/core/retry.js +210 -0
  113. package/dist/run/core/retry.js.map +1 -0
  114. package/dist/run/diagnostics/diagnostics.d.ts +86 -0
  115. package/dist/run/diagnostics/diagnostics.d.ts.map +1 -0
  116. package/dist/run/diagnostics/diagnostics.js +211 -0
  117. package/dist/run/diagnostics/diagnostics.js.map +1 -0
  118. package/dist/run/diagnostics/index.d.ts +3 -0
  119. package/dist/run/diagnostics/index.d.ts.map +1 -0
  120. package/dist/run/diagnostics/index.js +3 -0
  121. package/dist/run/diagnostics/index.js.map +1 -0
  122. package/dist/run/index.d.ts +16 -0
  123. package/dist/run/index.d.ts.map +1 -0
  124. package/dist/run/index.js +16 -0
  125. package/dist/run/index.js.map +1 -0
  126. package/dist/run-lifecycle.d.ts +118 -0
  127. package/dist/run-lifecycle.d.ts.map +1 -0
  128. package/dist/run-lifecycle.js +451 -0
  129. package/dist/run-lifecycle.js.map +1 -0
  130. package/dist/terminal-session.d.ts +139 -0
  131. package/dist/terminal-session.d.ts.map +1 -0
  132. package/dist/terminal-session.js +316 -0
  133. package/dist/terminal-session.js.map +1 -0
  134. package/dist/tokens.d.ts +9 -0
  135. package/dist/tokens.d.ts.map +1 -0
  136. package/dist/tokens.js +19 -0
  137. package/dist/tokens.js.map +1 -0
  138. package/dist/tool-executor.d.ts +97 -0
  139. package/dist/tool-executor.d.ts.map +1 -0
  140. package/dist/tool-executor.js +198 -0
  141. package/dist/tool-executor.js.map +1 -0
  142. package/package.json +51 -0
@@ -0,0 +1,184 @@
1
+ /**
2
+ * @module artifacts/text-suppression
3
+ *
4
+ * A streaming-text state machine that suppresses a tagged block (matched by
5
+ * caller-supplied open/close patterns) from user-visible output while it's
6
+ * still arriving — used to hide an artifact's raw markup from chat prose
7
+ * while it streams in, without buffering the whole response first. Ported
8
+ * from OD's `apps/daemon/src/artifacts/text-suppression.ts`.
9
+ *
10
+ * The core (`createTaggedTextSuppressor`) was already fully generic in the
11
+ * origin — it takes its open/close regexes and open/close prefix-match
12
+ * predicates as parameters, no product coupling. What needed de-branding
13
+ * were the origin's two pre-built instances: `createDsmlArtifactTextSuppressor`
14
+ * hardcoded OD's own "DSML" markup-language tag name family
15
+ * (`<|DSML artifact>`/`<artifact>`) as its open/close patterns.
16
+ * `createXmlTagTextSuppressor` below replaces it — a generic factory taking
17
+ * the caller's own tag-name list instead of a hardcoded vocabulary. The
18
+ * `tool_call`/`edit` pairing the origin's other instance
19
+ * (`createToolCallTextSuppressor`) suppressed is a generic agent-protocol
20
+ * convention, not OD-branded, and is kept as a named default instance.
21
+ */
22
+ const MAX_CANDIDATE_LENGTH = 512;
23
+ /**
24
+ * Builds a suppressor for a tagged block delimited by `openRe`/`closeRe`.
25
+ * `isPossibleOpen`/`isPossibleClose` decide whether a trailing `<...`
26
+ * fragment (with no closing `>` yet) *could* still become a match once more
27
+ * text arrives — this is what lets the suppressor hold back a
28
+ * not-yet-decidable tail across streaming chunk boundaries instead of
29
+ * either emitting a tag fragment early or hanging indefinitely on a `<` that
30
+ * turns out to be unrelated text.
31
+ */
32
+ export function createTaggedTextSuppressor(args) {
33
+ let suppressing = false;
34
+ let candidate = '';
35
+ let suppressedChars = 0;
36
+ let suppressedChunks = 0;
37
+ let openedBlocks = 0;
38
+ let closedBlocks = 0;
39
+ function noteSuppressed(text) {
40
+ if (text.length <= 0)
41
+ return;
42
+ suppressedChars += text.length;
43
+ suppressedChunks += 1;
44
+ }
45
+ function strip(text) {
46
+ const current = `${candidate}${text}`;
47
+ candidate = '';
48
+ if (suppressing) {
49
+ const close = args.closeRe.exec(current);
50
+ if (!close || close.index === undefined) {
51
+ const closeCandidateStart = possibleTagStart(current, args.isPossibleClose);
52
+ if (closeCandidateStart !== -1) {
53
+ candidate = current.slice(closeCandidateStart);
54
+ noteSuppressed(current.slice(0, closeCandidateStart));
55
+ }
56
+ else {
57
+ noteSuppressed(current);
58
+ }
59
+ return '';
60
+ }
61
+ suppressing = false;
62
+ const end = close.index + close[0].length;
63
+ closedBlocks += 1;
64
+ noteSuppressed(current.slice(0, end));
65
+ return strip(current.slice(end));
66
+ }
67
+ const open = args.openRe.exec(current);
68
+ if (open && open.index !== undefined) {
69
+ suppressing = true;
70
+ openedBlocks += 1;
71
+ const prefix = current.slice(0, open.index);
72
+ const tail = current.slice(open.index + open[0].length);
73
+ noteSuppressed(open[0]);
74
+ return `${prefix}${strip(tail)}`;
75
+ }
76
+ const candidateStart = possibleTagStart(current, args.isPossibleOpen);
77
+ if (candidateStart === -1)
78
+ return current;
79
+ candidate = current.slice(candidateStart);
80
+ return current.slice(0, candidateStart);
81
+ }
82
+ function flush() {
83
+ const text = candidate;
84
+ candidate = '';
85
+ return suppressing ? '' : text;
86
+ }
87
+ function isSuppressing() {
88
+ return suppressing;
89
+ }
90
+ function hasPendingCandidate() {
91
+ return candidate.length > 0;
92
+ }
93
+ function stats() {
94
+ return {
95
+ suppressedChars,
96
+ suppressedChunks,
97
+ openedBlocks,
98
+ closedBlocks,
99
+ pendingCandidateChars: candidate.length,
100
+ suppressing,
101
+ };
102
+ }
103
+ return { strip, flush, isSuppressing, hasPendingCandidate, stats };
104
+ }
105
+ /** Feeds `text` through `suppressor` and emits a `text_delta` on `onEvent` only when something survives. Returns whether an event was emitted. */
106
+ export function emitWithTextSuppressor(suppressor, onEvent, text) {
107
+ const delta = suppressor.strip(text);
108
+ if (!delta)
109
+ return false;
110
+ onEvent({ type: 'text_delta', delta });
111
+ return true;
112
+ }
113
+ function possibleTagStart(text, predicate) {
114
+ const min = Math.max(0, text.length - MAX_CANDIDATE_LENGTH);
115
+ let index = text.lastIndexOf('<');
116
+ while (index >= min) {
117
+ const tail = text.slice(index);
118
+ if (predicate(tail))
119
+ return index;
120
+ if (index === 0)
121
+ break;
122
+ index = text.lastIndexOf('<', index - 1);
123
+ }
124
+ return -1;
125
+ }
126
+ // `text` is always a `possibleTagStart` tail slice starting at a `<`
127
+ // position (its only caller) — no `!text.startsWith('<')` re-check needed.
128
+ function compactTagCandidate(text, stripChars) {
129
+ if (text.includes('>'))
130
+ return null;
131
+ return text.toLowerCase().replace(stripChars, '');
132
+ }
133
+ /**
134
+ * Builds a suppressor for an XML-like `<tagName ...>...</tagName>` block (or
135
+ * a bracket-pipe variant `<|tagName ...>...<|/tagName|>`), matched
136
+ * case-insensitively against any of `tagNames`. Replaces the origin's
137
+ * hardcoded "DSML" tag-name family with a caller-supplied vocabulary.
138
+ */
139
+ export function createXmlTagTextSuppressor(tagNames) {
140
+ const canonicals = tagNames.map((t) => t.toLowerCase());
141
+ const namesPattern = canonicals.map((t) => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
142
+ const openRe = new RegExp(`(?:<\\s*\\|?\\s*(?:${namesPattern})\\b[^>]*>)`, 'i');
143
+ const closeRe = new RegExp(`(?:<\\/(?:${namesPattern})>|<\\s*\\|?\\s*\\/\\s*(?:${namesPattern})\\s*\\|?\\s*>)`, 'i');
144
+ function isPossibleOpen(text) {
145
+ const compact = compactTagCandidate(text, /[<|,\s]/g);
146
+ if (compact === null)
147
+ return false;
148
+ return compact.length === 0 || canonicals.some((c) => c.startsWith(compact) || compact.startsWith(c));
149
+ }
150
+ function isPossibleClose(text) {
151
+ const compact = compactTagCandidate(text, /[<|/\s]/g);
152
+ if (compact === null)
153
+ return false;
154
+ return compact.length === 0 || canonicals.some((c) => c.startsWith(compact) || compact.startsWith(c));
155
+ }
156
+ return createTaggedTextSuppressor({ openRe, closeRe, isPossibleOpen, isPossibleClose });
157
+ }
158
+ const TOOL_CALL_OPEN_RE = /(?:<\s*tool_call\b[^>]*>|<\s*edit\s*>)/i;
159
+ const TOOL_CALL_CLOSE_RE = /(?:<\/\s*tool_call\s*>|<\/\s*edit\s*>)/i;
160
+ const TOOL_CALL_CANONICALS = ['toolcall', 'edit'];
161
+ // Same reasoning as compactTagCandidate above: `text` always starts with
162
+ // `<` here (a `possibleTagStart` tail slice) — no re-check needed.
163
+ function isPossibleToolCallOpen(text) {
164
+ if (text.includes('>'))
165
+ return false;
166
+ const compact = text.toLowerCase().replace(/[<|,\s_-]/g, '');
167
+ return compact.length === 0 || TOOL_CALL_CANONICALS.some((c) => c.startsWith(compact) || compact.startsWith(c));
168
+ }
169
+ function isPossibleToolCallClose(text) {
170
+ if (text.includes('>'))
171
+ return false;
172
+ const compact = text.toLowerCase().replace(/[<|/\s_-]/g, '');
173
+ return compact.length === 0 || TOOL_CALL_CANONICALS.some((c) => c.startsWith(compact) || compact.startsWith(c));
174
+ }
175
+ /** Suppresses a `<tool_call>...</tool_call>` or `<edit>...</edit>` block — a generic agent-protocol convention, not product-branded. */
176
+ export function createToolCallTextSuppressor() {
177
+ return createTaggedTextSuppressor({
178
+ openRe: TOOL_CALL_OPEN_RE,
179
+ closeRe: TOOL_CALL_CLOSE_RE,
180
+ isPossibleOpen: isPossibleToolCallOpen,
181
+ isPossibleClose: isPossibleToolCallClose,
182
+ });
183
+ }
184
+ //# sourceMappingURL=text-suppression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-suppression.js","sourceRoot":"","sources":["../../src/artifacts/text-suppression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAsBH,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAK1C;IACC,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,SAAS,GAAG,EAAE,CAAC;IACnB,IAAI,eAAe,GAAG,CAAC,CAAC;IACxB,IAAI,gBAAgB,GAAG,CAAC,CAAC;IACzB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,SAAS,cAAc,CAAC,IAAY;QAClC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC;YAAE,OAAO;QAC7B,eAAe,IAAI,IAAI,CAAC,MAAM,CAAC;QAC/B,gBAAgB,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,SAAS,KAAK,CAAC,IAAY;QACzB,MAAM,OAAO,GAAG,GAAG,SAAS,GAAG,IAAI,EAAE,CAAC;QACtC,SAAS,GAAG,EAAE,CAAC;QAEf,IAAI,WAAW,EAAE,CAAC;YAChB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CA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AAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAC7D,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAClH,CAAC;AAED,SAAS,uBAAuB,CAAC,IAAY;IAC3C,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACrC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAC7D,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAClH,CAAC;AAED,wIAAwI;AACxI,MAAM,UAAU,4BAA4B;IAC1C,OAAO,0BAA0B,CAAC;QAChC,MAAM,EAAE,iBAAiB;QACzB,OAAO,EAAE,kBAAkB;QAC3B,cAAc,EAAE,sBAAsB;QACtC,eAAe,EAAE,uBAAuB;KACzC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Pure run-close classification and inactivity-timeout helpers, generalized
3
+ * from OD's `apps/daemon/src/runtimes/chat-run-lifecycle.ts`
4
+ * (`arch/server-startserver-endgame` branch — see `source-map.md`). The
5
+ * origin file mixes a generic close-status decision tree with several
6
+ * OD/ACP-vendor-specific escape hatches (forced-shutdown-but-actually-clean
7
+ * heuristics for a specific agent-CLI protocol, artifact-quiet-period
8
+ * nuance). Only the generic skeleton is kept here — see `source-map.md` for
9
+ * the itemized list of what was dropped and why.
10
+ */
11
+ export type TerminalRunOutcome = 'succeeded' | 'failed' | 'cancelled';
12
+ export interface CloseStatusInput {
13
+ /** Whether `RunLifecycle.cancel` had already been called for this run. */
14
+ readonly cancelRequested: boolean;
15
+ readonly code: number | null;
16
+ readonly signal?: string | null;
17
+ }
18
+ /**
19
+ * Classifies a terminated run's exit into `RunLifecycle`'s terminal state.
20
+ *
21
+ * @param input - Cancellation flag plus the driver-observed exit code/signal.
22
+ * @returns `'cancelled'` if cancellation was requested (this takes priority
23
+ * over the exit code, since a cancelled process often exits non-zero as a
24
+ * direct result of the signal delivery — the cancellation intent, not the
25
+ * process's raw exit shape, is the ground truth); otherwise `'succeeded'`
26
+ * for exit code `0`; otherwise `'failed'`.
27
+ * @complexity O(1).
28
+ * @overallScore 100/100
29
+ */
30
+ export declare function classifyRunCloseStatus(input: CloseStatusInput): TerminalRunOutcome;
31
+ export interface ResolveTimeoutMsInput {
32
+ /** Env var name checked first (highest precedence), e.g. `'JINI_RUN_INACTIVITY_TIMEOUT_MS'`. */
33
+ readonly envVar?: string;
34
+ /** Per-agent/per-runtime default, used when no env override is set. */
35
+ readonly agentDefaultMs?: number;
36
+ /** Kernel default, used when neither an env override nor an agent default is set. */
37
+ readonly defaultMs: number;
38
+ /** Upper clamp applied after resolution, regardless of source. */
39
+ readonly maxMs: number;
40
+ /** Injectable env source (defaults to `process.env`) — kept explicit so this stays a pure, testable function rather than reading a process-global implicitly. */
41
+ readonly env?: Readonly<Record<string, string | undefined>>;
42
+ }
43
+ /**
44
+ * Resolves a timeout in milliseconds from an env-var override, an
45
+ * agent-supplied default, and a kernel default, in that precedence order,
46
+ * clamped to a maximum. Generalized from OD's
47
+ * `resolveChatRunInactivityTimeoutMs`/`resolveChatRunArtifactQuietPeriodMs`
48
+ * cascade (env > agentDefault > default, clamped) — the same shape reused
49
+ * for any timeout a `RunLifecycle` driver needs to resolve.
50
+ *
51
+ * @throws Never — a non-numeric or non-positive env value is treated as
52
+ * absent rather than raised, since a malformed env var should degrade to the
53
+ * next precedence tier, not crash startup.
54
+ * @complexity O(1).
55
+ * @overallScore 100/100
56
+ */
57
+ export declare function resolveTimeoutMs(input: ResolveTimeoutMsInput): number;
58
+ export interface InactivityWatchdog {
59
+ /** Resets the timeout window — call on every observed unit of run activity (an emitted event, a stdout chunk). */
60
+ noteActivity(): void;
61
+ /** Disarms the watchdog permanently (e.g. once the run reaches a terminal state). Safe to call more than once. */
62
+ cancel(): void;
63
+ }
64
+ export interface CreateInactivityWatchdogInput {
65
+ readonly timeoutMs: number;
66
+ /** Invoked once if `timeoutMs` elapses with no `noteActivity()` call in between. Never invoked after `cancel()`. */
67
+ readonly onTimeout: () => void;
68
+ }
69
+ /**
70
+ * Generic reset-on-activity timeout, generalized from OD's inactivity
71
+ * watchdog pattern in `start-chat-run.ts` (reset timer on every stdout/agent
72
+ * event; the origin's SIGTERM-then-SIGKILL escalation on fire is
73
+ * subprocess-signaling detail out of this task's scope — a driver's
74
+ * `onTimeout` callback is where that would plug in).
75
+ *
76
+ * @param input.timeoutMs - Milliseconds of inactivity before `onTimeout` fires.
77
+ * @param input.onTimeout - Fired at most once per watchdog instance.
78
+ * @returns A handle to reset (`noteActivity`) or permanently disarm (`cancel`) the timer.
79
+ * @remarks Side effect: starts a `setTimeout` immediately and calls
80
+ * `.unref()` on it (when available) so a bare watchdog never keeps a Node
81
+ * process alive on its own.
82
+ * @complexity O(1) per call.
83
+ * @overallScore 100/100
84
+ */
85
+ export declare function createInactivityWatchdog(input: CreateInactivityWatchdogInput): InactivityWatchdog;
86
+ //# sourceMappingURL=close-status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"close-status.d.ts","sourceRoot":"","sources":["../src/close-status.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEtE,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,gBAAgB,GAAG,kBAAkB,CAQlF;AAED,MAAM,WAAW,qBAAqB;IACpC,gGAAgG;IAChG,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,uEAAuE;IACvE,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,qFAAqF;IACrF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iKAAiK;IACjK,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;CAC7D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,MAAM,CAOrE;AAED,MAAM,WAAW,kBAAkB;IACjC,kHAAkH;IAClH,YAAY,IAAI,IAAI,CAAC;IACrB,kHAAkH;IAClH,MAAM,IAAI,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,oHAAoH;IACpH,QAAQ,CAAC,SAAS,EAAE,MAAM,IAAI,CAAC;CAChC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,GAAG,kBAAkB,CAwBjG"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Pure run-close classification and inactivity-timeout helpers, generalized
3
+ * from OD's `apps/daemon/src/runtimes/chat-run-lifecycle.ts`
4
+ * (`arch/server-startserver-endgame` branch — see `source-map.md`). The
5
+ * origin file mixes a generic close-status decision tree with several
6
+ * OD/ACP-vendor-specific escape hatches (forced-shutdown-but-actually-clean
7
+ * heuristics for a specific agent-CLI protocol, artifact-quiet-period
8
+ * nuance). Only the generic skeleton is kept here — see `source-map.md` for
9
+ * the itemized list of what was dropped and why.
10
+ */
11
+ /**
12
+ * Classifies a terminated run's exit into `RunLifecycle`'s terminal state.
13
+ *
14
+ * @param input - Cancellation flag plus the driver-observed exit code/signal.
15
+ * @returns `'cancelled'` if cancellation was requested (this takes priority
16
+ * over the exit code, since a cancelled process often exits non-zero as a
17
+ * direct result of the signal delivery — the cancellation intent, not the
18
+ * process's raw exit shape, is the ground truth); otherwise `'succeeded'`
19
+ * for exit code `0`; otherwise `'failed'`.
20
+ * @complexity O(1).
21
+ * @overallScore 100/100
22
+ */
23
+ export function classifyRunCloseStatus(input) {
24
+ if (input.cancelRequested) {
25
+ return 'cancelled';
26
+ }
27
+ if (input.code === 0) {
28
+ return 'succeeded';
29
+ }
30
+ return 'failed';
31
+ }
32
+ /**
33
+ * Resolves a timeout in milliseconds from an env-var override, an
34
+ * agent-supplied default, and a kernel default, in that precedence order,
35
+ * clamped to a maximum. Generalized from OD's
36
+ * `resolveChatRunInactivityTimeoutMs`/`resolveChatRunArtifactQuietPeriodMs`
37
+ * cascade (env > agentDefault > default, clamped) — the same shape reused
38
+ * for any timeout a `RunLifecycle` driver needs to resolve.
39
+ *
40
+ * @throws Never — a non-numeric or non-positive env value is treated as
41
+ * absent rather than raised, since a malformed env var should degrade to the
42
+ * next precedence tier, not crash startup.
43
+ * @complexity O(1).
44
+ * @overallScore 100/100
45
+ */
46
+ export function resolveTimeoutMs(input) {
47
+ const env = input.env ?? (typeof process !== 'undefined' ? process.env : {});
48
+ const rawFromEnv = input.envVar ? env[input.envVar] : undefined;
49
+ const fromEnv = rawFromEnv !== undefined ? Number(rawFromEnv) : undefined;
50
+ const candidate = fromEnv !== undefined && Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : (input.agentDefaultMs ?? input.defaultMs);
51
+ return Math.min(candidate, input.maxMs);
52
+ }
53
+ /**
54
+ * Generic reset-on-activity timeout, generalized from OD's inactivity
55
+ * watchdog pattern in `start-chat-run.ts` (reset timer on every stdout/agent
56
+ * event; the origin's SIGTERM-then-SIGKILL escalation on fire is
57
+ * subprocess-signaling detail out of this task's scope — a driver's
58
+ * `onTimeout` callback is where that would plug in).
59
+ *
60
+ * @param input.timeoutMs - Milliseconds of inactivity before `onTimeout` fires.
61
+ * @param input.onTimeout - Fired at most once per watchdog instance.
62
+ * @returns A handle to reset (`noteActivity`) or permanently disarm (`cancel`) the timer.
63
+ * @remarks Side effect: starts a `setTimeout` immediately and calls
64
+ * `.unref()` on it (when available) so a bare watchdog never keeps a Node
65
+ * process alive on its own.
66
+ * @complexity O(1) per call.
67
+ * @overallScore 100/100
68
+ */
69
+ export function createInactivityWatchdog(input) {
70
+ let timer;
71
+ const arm = () => {
72
+ if (timer) {
73
+ clearTimeout(timer);
74
+ }
75
+ timer = setTimeout(input.onTimeout, input.timeoutMs);
76
+ if (typeof timer.unref === 'function') {
77
+ timer.unref();
78
+ }
79
+ };
80
+ arm();
81
+ return {
82
+ noteActivity: arm,
83
+ cancel: () => {
84
+ if (timer) {
85
+ clearTimeout(timer);
86
+ timer = undefined;
87
+ }
88
+ },
89
+ };
90
+ }
91
+ //# sourceMappingURL=close-status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"close-status.js","sourceRoot":"","sources":["../src/close-status.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAWH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAuB;IAC5D,IAAI,KAAK,CAAC,eAAe,EAAE,CAAC;QAC1B,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,OAAO,QAAQ,CA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,YAAY,EAAE,GAAG;QACjB,MAAM,EAAE,GAAS,EAAE;YACjB,IAAI,KAAK,EAAE,CAAC;gBACV,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,KAAK,GAAG,SAAS,CAAC;YACpB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * `resolveContinuationTransport` — gap 3 of the run/chat orchestration
3
+ * swarm-consensus Final Recommendation: "per-definition `continuationTransport:
4
+ * 'mcp-callback' | 'stdin-injection' | 'none'`, resolved from each def's
5
+ * declared input format (defaulting `'none'` for unverified entries)."
6
+ * Evidence-backed as a factual constraint, not a preference: stdin closes
7
+ * after the first write for ~22/24 registered defs (see the consensus
8
+ * report's DP3).
9
+ *
10
+ * Resolution order (2026-07-22 research, `@jini-ai/agent-runtime`'s 24 defs
11
+ * enumerated directly): `externalMcpInjection` set → `'mcp-callback'`;
12
+ * else `promptInputFormat === 'stream-json' && promptViaStdin` →
13
+ * `'stdin-injection'`; else `'none'`. `externalMcpInjection` is checked
14
+ * first because it is the more capable transport (a real bidirectional tool
15
+ * protocol vs. a single-shot JSONL injection) and because `claude`/
16
+ * `codebuddy` are the only defs where both conditions are simultaneously
17
+ * true — they resolve to `'mcp-callback'` as primary, with
18
+ * `'stdin-injection'` available as a documented secondary path (see
19
+ * `agent-executor.ts`'s stdin-tool-result injection, which is independently
20
+ * gated and does not consult this function).
21
+ *
22
+ * Keyed deliberately off `promptInputFormat`/`externalMcpInjection`, never
23
+ * `streamFormat`: `amp.ts` reuses `streamFormat: 'claude-stream-json'` (the
24
+ * *output* parser) but declares neither input-continuation field — its own
25
+ * comment states it deliberately stays plain-text stdin. Keying off
26
+ * `streamFormat` would misroute it into `'stdin-injection'`.
27
+ */
28
+ import type { RuntimeAgentDef } from '@jini-ai/agent-runtime';
29
+ export type ContinuationTransport = 'mcp-callback' | 'stdin-injection' | 'none';
30
+ /**
31
+ * Resolves the continuation transport a def supports, from its own declared
32
+ * capability fields — never guessed, never defaulted to something more
33
+ * capable than what the def actually declares.
34
+ * @param def - The resolved agent def.
35
+ * @returns The transport this def supports for injecting a tool result (or
36
+ * other mid-run input) back into an already-running child process.
37
+ * @complexity O(1).
38
+ * @overallScore 100/100
39
+ */
40
+ export declare function resolveContinuationTransport(def: RuntimeAgentDef): ContinuationTransport;
41
+ //# sourceMappingURL=continuation-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"continuation-transport.d.ts","sourceRoot":"","sources":["../../src/continuation/continuation-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,MAAM,MAAM,qBAAqB,GAAG,cAAc,GAAG,iBAAiB,GAAG,MAAM,CAAC;AAEhF;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,eAAe,GAAG,qBAAqB,CAIxF"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Resolves the continuation transport a def supports, from its own declared
3
+ * capability fields — never guessed, never defaulted to something more
4
+ * capable than what the def actually declares.
5
+ * @param def - The resolved agent def.
6
+ * @returns The transport this def supports for injecting a tool result (or
7
+ * other mid-run input) back into an already-running child process.
8
+ * @complexity O(1).
9
+ * @overallScore 100/100
10
+ */
11
+ export function resolveContinuationTransport(def) {
12
+ if (def.externalMcpInjection !== undefined)
13
+ return 'mcp-callback';
14
+ if (def.promptInputFormat === 'stream-json' && def.promptViaStdin === true)
15
+ return 'stdin-injection';
16
+ return 'none';
17
+ }
18
+ //# sourceMappingURL=continuation-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"continuation-transport.js","sourceRoot":"","sources":["../../src/continuation/continuation-transport.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;GASG;AACH,MAAM,UAAU,4BAA4B,CAAC,GAAoB;IAC/D,IAAI,GAAG,CAAC,oBAAoB,KAAK,SAAS;QAAE,OAAO,cAAc,CAAC;IAClE,IAAI,GAAG,CAAC,iBAAiB,KAAK,aAAa,IAAI,GAAG,CAAC,cAAc,KAAK,IAAI;QAAE,OAAO,iBAAiB,CAAC;IACrG,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './journal.js';
2
+ export * from './run-start-handler.js';
3
+ export * from './continuation-transport.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/continuation/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './journal.js';
2
+ export * from './run-start-handler.js';
3
+ export * from './continuation-transport.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/continuation/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * `RunByteJournal` — gap 1 of the run/chat orchestration swarm-consensus
3
+ * Final Recommendation ("a durable, typed byte-journal... recording every
4
+ * byte sent to/received from a child agent process. This is the
5
+ * observability floor every later increment depends on." — see
6
+ * `ADS-memory/reports/swarm-consensus/runs/20260722T023000Z-consensus-report.md`).
7
+ *
8
+ * Deliberately backed by the existing `EventLog` port rather than a new
9
+ * storage mechanism ("no new package" — same debate), but deliberately NOT
10
+ * the same `EventLog` *instance* `RunLifecycle` appends its own
11
+ * `RunProtocolEvent`s to: that log's `stream()` replays every entry it holds
12
+ * to SSE subscribers, typed as `RunProtocolEvent`, and a `'journal'` entry
13
+ * has no corresponding `RunProtocolEvent` kind. Reusing the same instance
14
+ * would either leak raw, potentially untrusted agent bytes into the public
15
+ * run-event stream or force widening `RunProtocolEvent` itself. A caller
16
+ * supplies its own `EventLog` instance here — reusing the exact same port
17
+ * type and, for a durable deployment, the exact same `@jini-ai/sqlite` adapter
18
+ * — so the journal gets the identical durability/replay guarantees without
19
+ * touching the run-protocol vocabulary at all.
20
+ */
21
+ import type { JournalEntry } from '@jini-ai/protocol';
22
+ import type { EventLog } from '../event-log.js';
23
+ export interface RunByteJournal {
24
+ /** Durably appends one journal entry for `runId`. Never rejects into caller code — see {@link createRunByteJournal}. */
25
+ record(runId: string, entry: JournalEntry): Promise<void>;
26
+ /** Replays every journal entry recorded for `runId`, oldest first. */
27
+ read(runId: string): Promise<readonly JournalEntry[]>;
28
+ }
29
+ /**
30
+ * Creates a `RunByteJournal` over the given `EventLog` instance.
31
+ * @param eventLog - A dedicated `EventLog` instance for journal storage — see this module's doc for why it must not be the same instance `RunLifecycle` uses.
32
+ * @returns A `RunByteJournal` whose `record`/`read` are thin, structurally-typed projections of `eventLog.append`/`eventLog.replay`.
33
+ * @complexity Both methods are exactly as expensive as the underlying `EventLog`'s `append`/`replay`.
34
+ * @overallScore 100/100
35
+ */
36
+ export declare function createRunByteJournal(eventLog: EventLog): RunByteJournal;
37
+ //# sourceMappingURL=journal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal.d.ts","sourceRoot":"","sources":["../../src/continuation/journal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAKhD,MAAM,WAAW,cAAc;IAC7B,wHAAwH;IACxH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,sEAAsE;IACtE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,YAAY,EAAE,CAAC,CAAC;CACvD;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAWvE"}
@@ -0,0 +1,23 @@
1
+ /** The one event name every journal entry is appended under — never a `RunProtocolEvent` kind, so a shared-instance mistake would be immediately obvious in a replay. */
2
+ const JOURNAL_EVENT_NAME = 'journal';
3
+ /**
4
+ * Creates a `RunByteJournal` over the given `EventLog` instance.
5
+ * @param eventLog - A dedicated `EventLog` instance for journal storage — see this module's doc for why it must not be the same instance `RunLifecycle` uses.
6
+ * @returns A `RunByteJournal` whose `record`/`read` are thin, structurally-typed projections of `eventLog.append`/`eventLog.replay`.
7
+ * @complexity Both methods are exactly as expensive as the underlying `EventLog`'s `append`/`replay`.
8
+ * @overallScore 100/100
9
+ */
10
+ export function createRunByteJournal(eventLog) {
11
+ return {
12
+ async record(runId, entry) {
13
+ await eventLog.append({ runId, event: JOURNAL_EVENT_NAME, data: entry });
14
+ },
15
+ async read(runId) {
16
+ const replay = await eventLog.replay(runId, null);
17
+ if (replay.kind !== 'ok')
18
+ return [];
19
+ return replay.entries.map((entry) => entry.data);
20
+ },
21
+ };
22
+ }
23
+ //# sourceMappingURL=journal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal.js","sourceRoot":"","sources":["../../src/continuation/journal.ts"],"names":[],"mappings":"AAuBA,yKAAyK;AACzK,MAAM,kBAAkB,GAAG,SAAS,CAAC;AASrC;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAkB;IACrD,OAAO;QACL,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,KAAmB;YAC7C,MAAM,QAAQ,CAAC,MAAM,CAAe,EAAE,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACzF,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,KAAa;YACtB,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAClD,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI;gBAAE,OAAO,EAAE,CAAC;YACpC,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAoB,CAAC,CAAC;QACnE,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * `resolveRunInput` + `createDefaultRunStartHandler` — gap 1's other half:
3
+ * "a default `RunStartHandler`-style wiring (host-supplied `resolveRunInput`
4
+ * seam, matching the existing `resolveDaemonUrl` precedent)" (Final
5
+ * Recommendation, `ADS-memory/reports/swarm-consensus/runs/20260722T023000Z-consensus-report.md`).
6
+ *
7
+ * Today, `@jini-ai/http`'s `POST /api/runs` durably starts a run via
8
+ * `RunLifecycle.start()` and then — only if a host supplied one — invokes an
9
+ * `onStarted`/`RunStartHandler` callback. Nothing in the kernel ever turns
10
+ * that durable start into an actual `AgentExecutor.run()` call: a host with
11
+ * no `onStarted` gets a run that is durably `'running'` forever, with no
12
+ * driver ever attached. This module is the missing default, built the same
13
+ * way `@jini-ai/cli`'s `resolveDaemonUrl` composes a required resolution step
14
+ * (there: a daemon URL; here: an agent's prompt/cwd/env) out of an
15
+ * injectable async seam — `resolveRunInput` has no generic default, unlike
16
+ * `resolveDaemonUrl`'s optional `discover`, because prompt/skill/memory
17
+ * composition is gap 2, and gap 2 stays host-owned *permanently* (Final
18
+ * Recommendation item 5) — there is no sensible kernel-supplied fallback to
19
+ * fall through to.
20
+ *
21
+ * This does not itself touch `@jini-ai/http`'s `RunStartHandler` type (a
22
+ * `@jini-ai/daemon` → `@jini-ai/http` import would invert the package graph —
23
+ * `@jini-ai/http` already imports `@jini-ai/daemon`, never the reverse).
24
+ * {@link DefaultRunStartHandler}'s parameter type is a structural subset of
25
+ * `@jini-ai/http`'s `RunStartContext`, so a real `RunStartContext` value —
26
+ * passed by a host wiring this handler in as `RunHttpDeps.onStarted` —
27
+ * satisfies it without either package needing to import the other's types.
28
+ */
29
+ import type { AgentExecutor } from '../agent-executor.js';
30
+ export interface ResolveRunInputContext {
31
+ readonly runId: string;
32
+ readonly contextRef: string;
33
+ readonly agentId?: string;
34
+ }
35
+ export interface ResolvedRunInput {
36
+ readonly agentId: string;
37
+ readonly prompt: string;
38
+ readonly cwd: string;
39
+ readonly env?: NodeJS.ProcessEnv;
40
+ }
41
+ /** Host-owned composition seam: turns a durably-started run's identity into what `AgentExecutor.run()` actually needs. No generic default exists — see module doc. */
42
+ export type ResolveRunInput = (context: ResolveRunInputContext) => Promise<ResolvedRunInput> | ResolvedRunInput;
43
+ /** Structural subset of `@jini-ai/http`'s `RunStartContext` — see module doc for why this package cannot import that type directly. */
44
+ export interface RunStartDriverContext {
45
+ readonly request: {
46
+ readonly contextRef: string;
47
+ readonly agentId?: string;
48
+ };
49
+ readonly run: {
50
+ readonly id: string;
51
+ };
52
+ }
53
+ /** Structurally assignable to `@jini-ai/http`'s `RunStartHandler` — see module doc. */
54
+ export type DefaultRunStartHandler = (context: RunStartDriverContext) => Promise<void>;
55
+ export interface CreateDefaultRunStartHandlerOptions {
56
+ readonly agentExecutor: AgentExecutor;
57
+ readonly resolveRunInput: ResolveRunInput;
58
+ }
59
+ /**
60
+ * Builds the default `RunStartHandler`-shaped driver: resolves the real
61
+ * agent input via `options.resolveRunInput`, then hands it straight to
62
+ * `options.agentExecutor.run()`. A host wires this in as
63
+ * `RunHttpDeps.onStarted` (or `CreateLocalNodeDaemonConfig.onRunStarted`)
64
+ * instead of writing its own driver from scratch — it still owns
65
+ * `resolveRunInput` itself (gap 2 stays host-owned), but no longer needs to
66
+ * know `AgentExecutor`'s call shape or wire cancellation/journaling by hand.
67
+ * @param options.agentExecutor - The executor this handler drives. Any byte-journaling is the executor's own concern (see `CreateAgentExecutorOptions.journal`) — this handler does not journal directly.
68
+ * @param options.resolveRunInput - Host-owned composition seam — see module doc.
69
+ * @returns A handler structurally assignable to `@jini-ai/http`'s `RunStartHandler`.
70
+ * @throws Whatever `resolveRunInput` or `agentExecutor.run()` throw — `@jini-ai/http`'s `runStartRoute` already treats a rejecting `onStarted` as a failed run (finishes it, reports the internal error), so this handler deliberately does not swallow either failure itself.
71
+ * @complexity O(1) plus `resolveRunInput`'s and `agentExecutor.run()`'s own costs.
72
+ * @overallScore 100/100
73
+ */
74
+ export declare function createDefaultRunStartHandler(options: CreateDefaultRunStartHandlerOptions): DefaultRunStartHandler;
75
+ //# sourceMappingURL=run-start-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-start-handler.d.ts","sourceRoot":"","sources":["../../src/continuation/run-start-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CAClC;AAED,sKAAsK;AACtK,MAAM,MAAM,eAAe,GAAG,CAC5B,OAAO,EAAE,sBAAsB,KAC5B,OAAO,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,CAAC;AAElD,uIAAuI;AACvI,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;I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