@jini-ai/daemon 0.6.8 → 0.6.9

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 (71) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/agent-executor/antigravity-permissions.d.ts +11 -0
  3. package/dist/agent-executor/antigravity-permissions.js +64 -0
  4. package/dist/agent-executor/contracts.d.ts +31 -6
  5. package/dist/agent-executor/event-translation.d.ts +6 -1
  6. package/dist/agent-executor/event-translation.js +1 -1
  7. package/dist/agent-executor/events.d.ts +1 -0
  8. package/dist/agent-executor/events.js +85 -74
  9. package/dist/agent-executor/launch.d.ts +4 -2
  10. package/dist/agent-executor/launch.js +306 -217
  11. package/dist/agent-executor/mcp-bridge-probe.js +51 -35
  12. package/dist/agent-executor/mcp-bridge.d.ts +18 -8
  13. package/dist/agent-executor/mcp-bridge.js +105 -65
  14. package/dist/agent-executor/run-output.d.ts +20 -0
  15. package/dist/agent-executor/run-output.js +80 -0
  16. package/dist/attachment-content.js +18 -15
  17. package/dist/core/read-only-tools.d.ts +15 -0
  18. package/dist/core/read-only-tools.js +29 -1
  19. package/dist/core/tool-audit.d.ts +3 -1
  20. package/dist/core/tool-audit.js +35 -22
  21. package/dist/core/tool-gaps.d.ts +60 -0
  22. package/dist/core/tool-gaps.js +199 -0
  23. package/dist/delegated-tool-bridge.d.ts +1 -1
  24. package/dist/delegated-tool-bridge.js +161 -122
  25. package/dist/event-log.d.ts +45 -2
  26. package/dist/event-log.js +83 -4
  27. package/dist/http/attachments.d.ts +26 -1
  28. package/dist/http/attachments.js +129 -65
  29. package/dist/http/connectors.d.ts +1 -32
  30. package/dist/http/connectors.js +13 -68
  31. package/dist/http/delegated-tools.d.ts +5 -1
  32. package/dist/http/delegated-tools.js +29 -29
  33. package/dist/http/host-tools.d.ts +1 -0
  34. package/dist/http/host-tools.js +64 -59
  35. package/dist/http/index.d.ts +2 -2
  36. package/dist/http/index.js +1 -1
  37. package/dist/http/media.js +48 -69
  38. package/dist/http/memory.js +45 -36
  39. package/dist/http/model-proxy-fields.d.ts +23 -0
  40. package/dist/http/model-proxy-fields.js +29 -0
  41. package/dist/http/model-proxy.js +193 -395
  42. package/dist/http/research-tavily.adapter.js +72 -49
  43. package/dist/http/research.js +33 -23
  44. package/dist/http/resource-request.d.ts +37 -0
  45. package/dist/http/resource-request.js +59 -0
  46. package/dist/http/routines.js +49 -90
  47. package/dist/http/runs.d.ts +7 -5
  48. package/dist/http/runs.js +21 -7
  49. package/dist/http/terminals.js +23 -48
  50. package/dist/http/tool-catalog.d.ts +5 -0
  51. package/dist/http/xai.d.ts +11 -1
  52. package/dist/http/xai.js +125 -124
  53. package/dist/legacy-data-migration.js +41 -24
  54. package/dist/run/core/retry.js +51 -35
  55. package/dist/run/diagnostics/diagnostics.js +5 -17
  56. package/dist/run-credentials.js +49 -27
  57. package/dist/run-lifecycle.d.ts +12 -2
  58. package/dist/run-lifecycle.js +47 -26
  59. package/dist/store/agent-sessions/sqlite.d.ts +6 -0
  60. package/dist/store/agent-sessions/sqlite.js +6 -4
  61. package/dist/surface-exchanges.js +2 -1
  62. package/dist/terminal-session.d.ts +1 -1
  63. package/dist/terminal-session.js +26 -33
  64. package/dist/tool-audit.d.ts +1 -0
  65. package/dist/tool-audit.js +1 -0
  66. package/dist/tool-executor.d.ts +24 -3
  67. package/dist/tool-executor.js +276 -139
  68. package/dist/tool-recovery/recovery.js +64 -35
  69. package/dist/tool-recovery/stack.d.ts +2 -1
  70. package/dist/tool-recovery/stack.js +1 -1
  71. package/package.json +10 -10
@@ -115,6 +115,10 @@ function toSessionInfo(session, resourceRef) {
115
115
  signal: session.signal,
116
116
  };
117
117
  }
118
+ /** Drop undefined-valued keys so an omitted option never overrides the engine's own default. */
119
+ function definedOnly(value) {
120
+ return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined));
121
+ }
118
122
  /**
119
123
  * Serializes calls made for the same `id` through a per-id promise chain
120
124
  * (matching this codebase's `oauth-tokens.ts` `withLock` precedent), so a
@@ -141,18 +145,19 @@ async function runExclusive(locks, id, fn) {
141
145
  * the kill/write/resize lock, and (via {@link createTerminalToolRegistrations})
142
146
  * `ToolExecutor` gating for creation. See module doc for the full design.
143
147
  */
144
- export function createTerminalSessionManager(requiredArgs, optionalArgs = {}) {
145
- const options = { ...requiredArgs, ...optionalArgs };
148
+ export function createTerminalSessionManager(_requiredArgs, options = {}) {
146
149
  const terminalService = options.terminalService ??
147
150
  createTerminalService({
148
151
  loadSpawnPty: options.loadSpawnPty ?? (() => loadRealSpawnPty({})),
149
- ...(options.maxEvents !== undefined ? { maxEvents: options.maxEvents } : {}),
150
- ...(options.maxBufferBytes !== undefined ? { maxBufferBytes: options.maxBufferBytes } : {}),
151
- ...(options.exitTailBytes !== undefined ? { exitTailBytes: options.exitTailBytes } : {}),
152
- ...(options.flushIntervalMs !== undefined ? { flushIntervalMs: options.flushIntervalMs } : {}),
153
- ...(options.flushThresholdBytes !== undefined ? { flushThresholdBytes: options.flushThresholdBytes } : {}),
154
- ...(options.ttlMs !== undefined ? { ttlMs: options.ttlMs } : {}),
155
- ...(options.shutdownGraceMs !== undefined ? { shutdownGraceMs: options.shutdownGraceMs } : {}),
152
+ ...definedOnly({
153
+ maxEvents: options.maxEvents,
154
+ maxBufferBytes: options.maxBufferBytes,
155
+ exitTailBytes: options.exitTailBytes,
156
+ flushIntervalMs: options.flushIntervalMs,
157
+ flushThresholdBytes: options.flushThresholdBytes,
158
+ ttlMs: options.ttlMs,
159
+ shutdownGraceMs: options.shutdownGraceMs,
160
+ }),
156
161
  });
157
162
  const metadata = new Map();
158
163
  const locks = new Map();
@@ -181,9 +186,7 @@ export function createTerminalSessionManager(requiredArgs, optionalArgs = {}) {
181
186
  async function create({ principal, options: createOptions }) {
182
187
  const session = await terminalService.create({
183
188
  cwd: createOptions.cwd,
184
- ...(createOptions.cols !== undefined ? { cols: createOptions.cols } : {}),
185
- ...(createOptions.rows !== undefined ? { rows: createOptions.rows } : {}),
186
- ...(createOptions.shell !== undefined ? { shell: createOptions.shell } : {}),
189
+ ...definedOnly({ cols: createOptions.cols, rows: createOptions.rows, shell: createOptions.shell }),
187
190
  });
188
191
  const resourceRef = createOptions.resourceRef ?? null;
189
192
  metadata.set(session.id, { principalId: principal.id, resourceRef, killed: false });
@@ -210,7 +213,8 @@ export function createTerminalSessionManager(requiredArgs, optionalArgs = {}) {
210
213
  const session = terminalService.get(id);
211
214
  return session ? toSessionInfo(session, resourceRef) : null;
212
215
  }
213
- async function write({ principal, id, input }) {
216
+ /** Shared write/resize path: ownership check, then the per-session lock, then the killed flag. */
217
+ async function unlessKilled(principal, id, act) {
214
218
  const found = checkOwnership(principal, id);
215
219
  if (!found)
216
220
  return { status: 'not-found' };
@@ -221,22 +225,15 @@ export function createTerminalSessionManager(requiredArgs, optionalArgs = {}) {
221
225
  if (!meta || meta.killed) {
222
226
  return { status: 'ok', ok: false, session: currentSnapshot(id, meta?.resourceRef ?? null) };
223
227
  }
224
- const ok = terminalService.write(id, input);
228
+ const ok = act();
225
229
  return { status: 'ok', ok, session: currentSnapshot(id, meta.resourceRef) };
226
230
  });
227
231
  }
232
+ async function write({ principal, id, input }) {
233
+ return unlessKilled(principal, id, () => terminalService.write(id, input));
234
+ }
228
235
  async function resize({ principal, id, cols, rows }) {
229
- const found = checkOwnership(principal, id);
230
- if (!found)
231
- return { status: 'not-found' };
232
- return runExclusive(locks, id, () => {
233
- const meta = metadata.get(id);
234
- if (!meta || meta.killed) {
235
- return { status: 'ok', ok: false, session: currentSnapshot(id, meta?.resourceRef ?? null) };
236
- }
237
- const ok = terminalService.resize(id, cols, rows);
238
- return { status: 'ok', ok, session: currentSnapshot(id, meta.resourceRef) };
239
- });
236
+ return unlessKilled(principal, id, () => terminalService.resize(id, cols, rows));
240
237
  }
241
238
  async function kill({ principal, id }, { signal } = {}) {
242
239
  const found = checkOwnership(principal, id);
@@ -280,12 +277,9 @@ function isRecord(value) {
280
277
  * precedent).
281
278
  */
282
279
  export function createTerminalToolRegistrations(requiredArgs, optionalArgs = {}) {
283
- const options = { ...requiredArgs, ...optionalArgs };
284
- const { manager, policy = denyAllTerminalCreatePolicy, requiresConfirmation, timeoutMs } = options;
285
- const descriptorExtras = {
286
- ...(requiresConfirmation !== undefined ? { requiresConfirmation } : {}),
287
- ...(timeoutMs !== undefined ? { timeoutMs } : {}),
288
- };
280
+ const { manager } = requiredArgs;
281
+ const { policy = denyAllTerminalCreatePolicy, requiresConfirmation, timeoutMs } = optionalArgs;
282
+ const descriptorExtras = definedOnly({ requiresConfirmation, timeoutMs });
289
283
  return {
290
284
  create: {
291
285
  descriptor: {
@@ -307,8 +301,7 @@ export function createTerminalToolRegistrations(requiredArgs, optionalArgs = {})
307
301
  return manager.create({ principal: ctx.principal, options: {
308
302
  resourceRef,
309
303
  cwd,
310
- ...(cols !== undefined ? { cols } : {}),
311
- ...(rows !== undefined ? { rows } : {}),
304
+ ...definedOnly({ cols, rows }),
312
305
  shell,
313
306
  } });
314
307
  },
@@ -1,2 +1,3 @@
1
1
  export * from './core/tool-audit.js';
2
+ export * from './core/tool-gaps.js';
2
3
  //# sourceMappingURL=tool-audit.d.ts.map
@@ -1,3 +1,4 @@
1
1
  // Shared audit owner; used by standalone auditing and the recovery stack.
2
2
  export * from './core/tool-audit.js';
3
+ export * from './core/tool-gaps.js';
3
4
  //# sourceMappingURL=tool-audit.js.map
@@ -70,6 +70,8 @@ export type ToolExecutionStatus = 'completed' | 'denied' | 'confirmation-denied'
70
70
  */
71
71
  export type ToolExecutionErrorKind = 'validation' | 'internal';
72
72
  export interface ToolExecutionResult {
73
+ /** Value-free rewrites, retained even when output text is truncated. */
74
+ readonly normalizationNotes?: readonly string[];
73
75
  readonly executionId: string;
74
76
  readonly status: ToolExecutionStatus;
75
77
  readonly output?: unknown;
@@ -99,7 +101,7 @@ export interface ToolExecutor {
99
101
  readonly executionId: string;
100
102
  readonly decision: ConfirmationDecision;
101
103
  }): void;
102
- /** Aborts an in-flight handler, or resolves a still-pending confirmation as denied. No-op if `executionId` is already terminal or unknown. */
104
+ /** Cancels an in-flight execution, unblocking a still-pending confirmation. No-op if `executionId` is already terminal or unknown. */
103
105
  cancel(args: {
104
106
  readonly executionId: string;
105
107
  }): void;
@@ -107,12 +109,30 @@ export interface ToolExecutor {
107
109
  readonly executionId: string;
108
110
  }): ToolExecutionAuditRecord | null;
109
111
  }
112
+ /** Advisory preparation after authorization/confirmation, before the handler. A failure is fail-open. */
113
+ export type PrepareToolGuidance = (required: {
114
+ principal: Principal;
115
+ run: RunRef;
116
+ tool: ToolDescriptor;
117
+ signal: AbortSignal;
118
+ emitSurface?: SurfaceEmitter;
119
+ }, optional?: Record<string, never>) => Promise<string>;
110
120
  export interface CreateToolExecutorOptions {
121
+ readonly prepareGuidance?: PrepareToolGuidance;
111
122
  readonly registry: ToolRegistry;
112
123
  readonly delegate?: ExecutionDelegate;
113
124
  /** Injectable clock for audit timestamps — defaults to `Date.now`. Test-only hook. */
114
125
  readonly now?: () => number;
126
+ /** Cap on retained finished audit records, oldest evicted first. See {@link DEFAULT_MAX_AUDIT_RECORDS}. */
127
+ readonly maxAuditRecords?: number;
115
128
  }
129
+ /**
130
+ * Default cap on finished audit records kept for `getAuditRecord`. One record is added per tool
131
+ * execution and nothing else ever removed one, so a long-lived daemon grew the map for its whole
132
+ * uptime (memory investigation 2026-10-21). An in-flight execution's record is never evicted: its
133
+ * later transitions still have to land on it.
134
+ */
135
+ export declare const DEFAULT_MAX_AUDIT_RECORDS = 1000;
116
136
  /**
117
137
  * Creates the `ToolExecutor` reference implementation: an in-process,
118
138
  * in-memory gate over a `ToolRegistry`. No persistence — a real host that
@@ -125,8 +145,9 @@ export interface CreateToolExecutorOptions {
125
145
  * — the one and only caller of that internal export.
126
146
  * @param options.delegate - Transport-supplied authorize/confirm UI seam;
127
147
  * omit for a headless caller whose tools never need interactive gating.
128
- * @complexity Known-id `execute` is O(1) plus the handler's own cost; unknown ids scan O(n) descriptors for hints. `resumeConfirmation`/`cancel`/`getAuditRecord` are O(1) map lookups.
148
+ * @param options.maxAuditRecords - Finished audit records kept, see {@link DEFAULT_MAX_AUDIT_RECORDS}.
149
+ * @complexity Known-id `execute` adds schema-guided normalization to the handler's cost; unknown ids scan O(n) descriptors for hints. `resumeConfirmation`/`cancel`/`getAuditRecord` are O(1) map lookups.
129
150
  * @overallScore 100/100
130
151
  */
131
- export declare function createToolExecutor(requiredArgs: Pick<CreateToolExecutorOptions, "registry">, optionalArgs?: Pick<CreateToolExecutorOptions, "delegate" | "now">): ToolExecutor;
152
+ export declare function createToolExecutor(requiredArgs: Pick<CreateToolExecutorOptions, "registry">, optionalArgs?: Pick<CreateToolExecutorOptions, "delegate" | "now" | "prepareGuidance" | "maxAuditRecords">): ToolExecutor;
132
153
  //# sourceMappingURL=tool-executor.d.ts.map