stitchkit 0.130.0 → 0.131.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 (148) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/agent-executor/acp/v1-connect.d.ts +40 -26
  3. package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
  4. package/dist/agent-executor/acp/v1-driver.d.ts +10 -4
  5. package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -1
  6. package/dist/agent-executor/acp/v1-handlers.d.ts +6 -2
  7. package/dist/agent-executor/acp/v1-handlers.d.ts.map +1 -1
  8. package/dist/agent-executor/acp/v1-probe.d.ts +38 -0
  9. package/dist/agent-executor/acp/v1-probe.d.ts.map +1 -0
  10. package/dist/agent-executor/acp/v1-protocol.d.ts +15 -0
  11. package/dist/agent-executor/acp/v1-protocol.d.ts.map +1 -1
  12. package/dist/agent-executor/acp/v1-session.d.ts +9 -7
  13. package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
  14. package/dist/agent-executor/claude/cli-driver.d.ts +7 -7
  15. package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
  16. package/dist/agent-executor/claude/limits.d.ts +6 -4
  17. package/dist/agent-executor/claude/limits.d.ts.map +1 -1
  18. package/dist/agent-executor/claude/session.d.ts +3 -3
  19. package/dist/agent-executor/claude/session.d.ts.map +1 -1
  20. package/dist/agent-executor/claude-sdk/controls.d.ts +1 -0
  21. package/dist/agent-executor/claude-sdk/controls.d.ts.map +1 -1
  22. package/dist/agent-executor/claude-sdk/driver.d.ts +51 -50
  23. package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
  24. package/dist/agent-executor/claude-sdk/probe.d.ts +3 -3
  25. package/dist/agent-executor/claude-sdk/probe.d.ts.map +1 -1
  26. package/dist/agent-executor/claude-sdk/query-loop.d.ts +2 -1
  27. package/dist/agent-executor/claude-sdk/query-loop.d.ts.map +1 -1
  28. package/dist/agent-executor/codex/classify.d.ts.map +1 -1
  29. package/dist/agent-executor/codex/connect.d.ts +9 -7
  30. package/dist/agent-executor/codex/connect.d.ts.map +1 -1
  31. package/dist/agent-executor/codex/control-client.d.ts +112 -87
  32. package/dist/agent-executor/codex/control-client.d.ts.map +1 -1
  33. package/dist/agent-executor/codex/control-read-methods.d.ts +7 -0
  34. package/dist/agent-executor/codex/control-read-methods.d.ts.map +1 -0
  35. package/dist/agent-executor/codex/driver.d.ts +42 -31
  36. package/dist/agent-executor/codex/driver.d.ts.map +1 -1
  37. package/dist/agent-executor/codex/event-routing.d.ts +14 -0
  38. package/dist/agent-executor/codex/event-routing.d.ts.map +1 -0
  39. package/dist/agent-executor/codex/handlers.d.ts +9 -4
  40. package/dist/agent-executor/codex/handlers.d.ts.map +1 -1
  41. package/dist/agent-executor/codex/limits.d.ts +9 -3
  42. package/dist/agent-executor/codex/limits.d.ts.map +1 -1
  43. package/dist/agent-executor/codex/notifications.d.ts +183 -0
  44. package/dist/agent-executor/codex/notifications.d.ts.map +1 -0
  45. package/dist/agent-executor/codex/pagination.d.ts +54 -0
  46. package/dist/agent-executor/codex/pagination.d.ts.map +1 -0
  47. package/dist/agent-executor/codex/protocol.d.ts +586 -144
  48. package/dist/agent-executor/codex/protocol.d.ts.map +1 -1
  49. package/dist/agent-executor/codex/request-answers.d.ts +4 -2
  50. package/dist/agent-executor/codex/request-answers.d.ts.map +1 -1
  51. package/dist/agent-executor/codex/responses.d.ts +855 -0
  52. package/dist/agent-executor/codex/responses.d.ts.map +1 -0
  53. package/dist/agent-executor/codex/session-bind.d.ts +410 -0
  54. package/dist/agent-executor/codex/session-bind.d.ts.map +1 -0
  55. package/dist/agent-executor/codex/session-controls.d.ts +21 -169
  56. package/dist/agent-executor/codex/session-controls.d.ts.map +1 -1
  57. package/dist/agent-executor/codex/session-types.d.ts +190 -0
  58. package/dist/agent-executor/codex/session-types.d.ts.map +1 -0
  59. package/dist/agent-executor/codex/session.d.ts +5 -53
  60. package/dist/agent-executor/codex/session.d.ts.map +1 -1
  61. package/dist/agent-executor/codex/shared-server.d.ts +7 -5
  62. package/dist/agent-executor/codex/shared-server.d.ts.map +1 -1
  63. package/dist/agent-executor/codex/shared-thread.d.ts +8 -8
  64. package/dist/agent-executor/codex/shared-thread.d.ts.map +1 -1
  65. package/dist/agent-executor/codex/thread-controls.d.ts +61 -36
  66. package/dist/agent-executor/codex/thread-controls.d.ts.map +1 -1
  67. package/dist/agent-executor/codex/thread-list-query.d.ts +5 -0
  68. package/dist/agent-executor/codex/thread-list-query.d.ts.map +1 -0
  69. package/dist/agent-executor/codex/thread-open.d.ts +66 -0
  70. package/dist/agent-executor/codex/thread-open.d.ts.map +1 -0
  71. package/dist/agent-executor/codex/turn-input.d.ts +25 -7
  72. package/dist/agent-executor/codex/turn-input.d.ts.map +1 -1
  73. package/dist/agent-executor/codex/unix-socket-target.d.ts +12 -3
  74. package/dist/agent-executor/codex/unix-socket-target.d.ts.map +1 -1
  75. package/dist/agent-executor/codex/ws-frame.d.ts +4 -1
  76. package/dist/agent-executor/codex/ws-frame.d.ts.map +1 -1
  77. package/dist/agent-executor/contract.d.ts +3 -1
  78. package/dist/agent-executor/contract.d.ts.map +1 -1
  79. package/dist/agent-executor/engine-process.d.ts +4 -4
  80. package/dist/agent-executor/engine-process.d.ts.map +1 -1
  81. package/dist/agent-executor/engine.d.ts +3 -3
  82. package/dist/agent-executor/engine.d.ts.map +1 -1
  83. package/dist/agent-executor/handoff.d.ts.map +1 -1
  84. package/dist/agent-executor/hello.d.ts +7 -0
  85. package/dist/agent-executor/hello.d.ts.map +1 -1
  86. package/dist/agent-executor/json-rpc-peer.d.ts +9 -4
  87. package/dist/agent-executor/json-rpc-peer.d.ts.map +1 -1
  88. package/dist/agent-executor/leases.d.ts +1 -1
  89. package/dist/agent-executor/leases.d.ts.map +1 -1
  90. package/dist/agent-executor/plan-limits.d.ts +12 -1
  91. package/dist/agent-executor/plan-limits.d.ts.map +1 -1
  92. package/dist/agent-executor/profile.d.ts +7 -0
  93. package/dist/agent-executor/profile.d.ts.map +1 -1
  94. package/dist/agent-executor/session-primitives.d.ts +8 -0
  95. package/dist/agent-executor/session-primitives.d.ts.map +1 -1
  96. package/dist/agent-executor/testing/consumer-stubs.d.ts +45 -0
  97. package/dist/agent-executor/testing/consumer-stubs.d.ts.map +1 -0
  98. package/dist/agent-executor/testing/fake-claude-sdk-query.d.ts +88 -0
  99. package/dist/agent-executor/testing/fake-claude-sdk-query.d.ts.map +1 -0
  100. package/dist/agent-executor/testing/fake-codex-app-server.d.ts +56 -0
  101. package/dist/agent-executor/testing/fake-codex-app-server.d.ts.map +1 -0
  102. package/dist/agent-executor/testing/fixtures.d.ts +26 -0
  103. package/dist/agent-executor/testing/fixtures.d.ts.map +1 -0
  104. package/dist/agent-executor/testing/replay-driver.d.ts +8 -8
  105. package/dist/agent-executor/testing/replay-driver.d.ts.map +1 -1
  106. package/dist/agent-executor/testing/replay-runner.d.ts +3 -2
  107. package/dist/agent-executor/testing/replay-runner.d.ts.map +1 -1
  108. package/dist/agent-executor/testing/replay-transcript.d.ts +5 -3
  109. package/dist/agent-executor/testing/replay-transcript.d.ts.map +1 -1
  110. package/dist/agent-runtime/branch-observations.d.ts +5 -5
  111. package/dist/entrypoints/agent-executor/acp.d.ts +2 -1
  112. package/dist/entrypoints/agent-executor/acp.d.ts.map +1 -1
  113. package/dist/entrypoints/agent-executor/acp.js +284 -82
  114. package/dist/entrypoints/agent-executor/claude-sdk.d.ts +4 -0
  115. package/dist/entrypoints/agent-executor/claude-sdk.d.ts.map +1 -1
  116. package/dist/entrypoints/agent-executor/claude-sdk.js +58 -32
  117. package/dist/entrypoints/agent-executor/claude.d.ts +2 -2
  118. package/dist/entrypoints/agent-executor/claude.d.ts.map +1 -1
  119. package/dist/entrypoints/agent-executor/claude.js +25 -20
  120. package/dist/entrypoints/agent-executor/codex.d.ts +11 -6
  121. package/dist/entrypoints/agent-executor/codex.d.ts.map +1 -1
  122. package/dist/entrypoints/agent-executor/codex.js +2223 -1803
  123. package/dist/entrypoints/agent-executor/testing.d.ts +4 -0
  124. package/dist/entrypoints/agent-executor/testing.d.ts.map +1 -1
  125. package/dist/entrypoints/agent-executor/testing.js +880 -18
  126. package/dist/entrypoints/agent-executor.d.ts +3 -3
  127. package/dist/entrypoints/agent-executor.d.ts.map +1 -1
  128. package/dist/entrypoints/agent-executor.js +42 -8
  129. package/dist/entrypoints/process.js +3 -3
  130. package/dist/{index-jrn3prgm.js → index-32vaajec.js} +29 -4
  131. package/dist/{index-p1qmpq0p.js → index-64e9p079.js} +92 -56
  132. package/dist/{index-dbp6xemn.js → index-g2d9kws8.js} +199 -3
  133. package/dist/index-gm9yz82v.js +56 -0
  134. package/dist/index-j15dhkda.js +749 -0
  135. package/dist/{index-1q0n6zek.js → index-kwsr7j5k.js} +84 -44
  136. package/llms/agent-executor-acp.txt +5 -5
  137. package/llms/agent-executor-claude-sdk.txt +3 -1
  138. package/llms/agent-executor-claude.txt +2 -2
  139. package/llms/agent-executor-codex.txt +13 -10
  140. package/llms/agent-executor-testing.txt +5 -1
  141. package/llms/agent-executor.txt +4 -4
  142. package/llms/stitchkit.txt +75 -74
  143. package/llms/{upgrading-0.128.0-0.130.0.txt → upgrading-0.128.0-0.131.0.txt} +56 -3
  144. package/llms/upgrading.txt +1 -1
  145. package/llms-full.txt +160 -97
  146. package/llms.txt +8 -8
  147. package/package.json +3 -3
  148. package/dist/index-2s8sy57y.js +0 -229
@@ -5,9 +5,22 @@ import {
5
5
  AgentToolResultPartSchema2,
6
6
  AgentMessagePartSchema2
7
7
  } from "./index-2rf33y2h.js";
8
+ import {
9
+ createBoundedChannel2
10
+ } from "./index-09f7w2qq.js";
11
+ import {
12
+ runNativeCommand2
13
+ } from "./index-pzhqydxb.js";
14
+ import {
15
+ jsonDataRefusal
16
+ } from "./index-m6w6jtda.js";
8
17
  import {
9
18
  MAX_TIMER_MS
10
19
  } from "./index-mxt0wfjy.js";
20
+ import {
21
+ abortReason,
22
+ linkAbortSignals
23
+ } from "./index-rptj3qnc.js";
11
24
 
12
25
  // src/agent-executor/executor-contract.ts
13
26
  import { z as z2 } from "zod";
@@ -265,12 +278,14 @@ var PlanWindowSchema2 = z3.strictObject({
265
278
  usedPercent: z3.number().min(0).max(100),
266
279
  resetsAt: z3.iso.datetime({ offset: true }).optional(),
267
280
  windowDurationMins: z3.int().positive().optional(),
268
- label: Name.optional()
281
+ label: Name.optional(),
282
+ scope: Name.optional()
269
283
  });
270
284
  var PlanLimitsSchema2 = z3.strictObject({
271
285
  answer: z3.enum(["known", "no-plan-limit", "unpublished"]),
272
286
  windows: z3.array(PlanWindowSchema2).max(HELLO_LIMITS.windows),
273
287
  observedAt: z3.iso.datetime({ offset: true }),
288
+ plan: Name.optional(),
274
289
  error: Text.optional()
275
290
  });
276
291
  var ExecutorProfileSchema2 = z3.strictObject({
@@ -324,14 +339,30 @@ var ExecutorHelloAckSchema2 = z3.strictObject({
324
339
  resumable: z3.array(ExecutorResumeAckSchema).max(HELLO_LIMITS.resumableTurns)
325
340
  });
326
341
 
342
+ // src/agent-executor/session-primitives.ts
343
+ import { createHash } from "node:crypto";
344
+ import { z as z5 } from "zod";
345
+
327
346
  // src/agent-executor/profile.ts
328
347
  import { z as z4 } from "zod";
348
+ var EXECUTOR_ENV_KEY_PATTERN2 = /^[A-Z_][A-Z0-9_]*$/;
349
+ function sanitizeProfileEnv2(env) {
350
+ const sanitized = {};
351
+ if (env === undefined)
352
+ return sanitized;
353
+ for (const [key, value] of Object.entries(env)) {
354
+ if (typeof value === "string" && EXECUTOR_ENV_KEY_PATTERN2.test(key)) {
355
+ sanitized[key] = value;
356
+ }
357
+ }
358
+ return sanitized;
359
+ }
329
360
  var ExecutorProfileConfigSchema2 = z4.strictObject({
330
361
  profileId: z4.string().min(1).max(128),
331
362
  engine: ExecutorEngineSchema2,
332
363
  home: z4.string().min(1),
333
364
  accountLabel: z4.string().min(1).max(200).optional(),
334
- env: z4.record(z4.string().regex(/^[A-Z_][A-Z0-9_]*$/), z4.string()).default({})
365
+ env: z4.record(z4.string().regex(EXECUTOR_ENV_KEY_PATTERN2), z4.string()).default({})
335
366
  });
336
367
  function engineProfile(engine, raw) {
337
368
  const profile = ExecutorProfileConfigSchema2.parse(raw);
@@ -384,4 +415,169 @@ function helloProfile2(input) {
384
415
  };
385
416
  }
386
417
 
387
- export { ExecutorRawSchema2, ExecutorTokenUsageSchema2, ExecutorModelUsageSchema2, ExecutorThreadDispositionSchema2, ExecutorStartupPhaseSchema2, ExecutorStatusDeltaSchema2, ExecutorErrorKindSchema2, ExecutorDeltaSchema2, ThreadClaimSchema2, ThreadLeaseSchema2, ThreadRenewSchema2, ThreadReleaseSchema2, TurnOfferSchema2, TurnPhaseSchema2, TurnFailureKindSchema2, TurnReportSchema2, TurnReportAckSchema2, TurnInterruptSchema2, InteractionReplySchema2, EXECUTOR_ERRORS2, ExecutorEngineSchema2, ExecutorReconcileSchema2, ExecutorDriverCapabilitiesSchema2, PlanWindowSchema2, PlanLimitsSchema2, ExecutorProfileSchema2, ExecutorEngineInfoSchema2, ExecutorResumableTurnSchema2, ExecutorHelloSchema2, ExecutorHelloAckSchema2, ExecutorProfileConfigSchema2, engineProfile, CREDENTIAL_VARIABLES2, engineEnvironment2, ownCredentials2, helloProfile2 };
418
+ // src/agent-executor/session-primitives.ts
419
+ var TURN_QUEUE = { maxItems: 65536, maxBytes: 64 * 1024 * 1024 };
420
+ var MAX_DATE_MS = 8640000000000000;
421
+ var SAFE_JSON_LIMITS = {
422
+ maxDepth: 100,
423
+ maxNodes: 1e5,
424
+ omitObjectUndefined: true,
425
+ zodJson: true
426
+ };
427
+ function nonEmptyString(value) {
428
+ return typeof value === "string" && value.trim().length > 0 ? value : undefined;
429
+ }
430
+ function clampPlanName(value, maxChars = 256) {
431
+ const trimmed = nonEmptyString(value)?.trim();
432
+ return trimmed !== undefined ? trimmed.slice(0, maxChars) : undefined;
433
+ }
434
+ function epochMsToIso(ms) {
435
+ if (ms === null || ms === undefined)
436
+ return;
437
+ if (!Number.isFinite(ms) || Math.abs(ms) > MAX_DATE_MS)
438
+ return;
439
+ return new Date(ms).toISOString();
440
+ }
441
+ function epochSecondsToIso(seconds) {
442
+ if (seconds === null || seconds === undefined)
443
+ return;
444
+ return epochMsToIso(seconds * 1000);
445
+ }
446
+ function createTurnDeltaChannel() {
447
+ return createBoundedChannel2({
448
+ policy: "ordered",
449
+ ...TURN_QUEUE,
450
+ sizeOf: (delta) => JSON.stringify(delta).length
451
+ });
452
+ }
453
+ function normalizeDeltaIdentifiers(delta) {
454
+ if (delta.type === "tool-call" || delta.type === "tool-result") {
455
+ const callId = nonEmptyString(delta.callId) ?? delta.itemId;
456
+ const toolName = nonEmptyString(delta.toolName) ?? "unknown";
457
+ if (callId === delta.callId && toolName === delta.toolName)
458
+ return delta;
459
+ return { ...delta, callId, toolName };
460
+ }
461
+ if (delta.type === "request") {
462
+ const callId = nonEmptyString(delta.callId);
463
+ const toolName = delta.toolName === undefined ? undefined : nonEmptyString(delta.toolName) ?? "tool";
464
+ if (callId === delta.callId && toolName === delta.toolName)
465
+ return delta;
466
+ const { callId: _callId, toolName: _toolName, ...rest } = delta;
467
+ return {
468
+ ...rest,
469
+ ...callId !== undefined && { callId },
470
+ ...toolName !== undefined && { toolName }
471
+ };
472
+ }
473
+ return delta;
474
+ }
475
+ function offerTurnDelta(channel, delta) {
476
+ if (channel === undefined)
477
+ return;
478
+ const result = channel.offer(normalizeDeltaIdentifiers(delta));
479
+ if (result.outcome === "refused" && result.reason !== "not-open") {
480
+ channel.fail(new Error(`The turn's delta queue refused a delta (${result.reason})`));
481
+ }
482
+ }
483
+ function sessionAbort(caller) {
484
+ if (caller?.aborted)
485
+ throw abortReason(caller);
486
+ const own = new AbortController;
487
+ const link = caller ? linkAbortSignals(caller, own.signal) : { signal: own.signal, release: () => {
488
+ return;
489
+ } };
490
+ return { signal: link.signal, abort: () => own.abort(), release: link.release };
491
+ }
492
+ function runEngineCli(input) {
493
+ return runNativeCommand2({
494
+ executable: input.executable,
495
+ args: [...input.prefix, ...input.args],
496
+ env: engineEnvironment2(input.profile, input.ambient),
497
+ envPolicy: "declared-only",
498
+ capture: true,
499
+ maxOutputBytes: 1024 * 1024,
500
+ timeoutMs: 30000
501
+ });
502
+ }
503
+ function errorText(error) {
504
+ return error instanceof Error ? error.message : String(error);
505
+ }
506
+ async function stopConnection(connection, primary) {
507
+ let stopFailure;
508
+ try {
509
+ await connection.engine.stop();
510
+ } catch (error) {
511
+ stopFailure = { error };
512
+ }
513
+ await connection.reading;
514
+ if (stopFailure === undefined)
515
+ return;
516
+ if (primary === undefined)
517
+ throw stopFailure.error;
518
+ throw new AggregateError([primary.error, stopFailure.error], `${errorText(primary.error)}; stopping the engine also failed: ${errorText(stopFailure.error)}`, { cause: primary.error });
519
+ }
520
+ async function withEphemeralConnection(connect, use) {
521
+ const stop = new AbortController;
522
+ const connection = await connect(stop.signal);
523
+ let answer;
524
+ try {
525
+ answer = await use(connection);
526
+ } catch (error) {
527
+ stop.abort();
528
+ await stopConnection(connection, { error });
529
+ throw error;
530
+ }
531
+ stop.abort();
532
+ try {
533
+ await stopConnection(connection);
534
+ } catch {}
535
+ return answer;
536
+ }
537
+ function safeJsonValue(value) {
538
+ const snapshot = {};
539
+ const refusal = jsonDataRefusal(value, SAFE_JSON_LIMITS, snapshot);
540
+ if (refusal !== undefined) {
541
+ throw new TypeError(`Expected bounded JSON data (refused: ${refusal})`);
542
+ }
543
+ return z5.json().parse(snapshot.value);
544
+ }
545
+ function invokeSafely(invoke) {
546
+ try {
547
+ const result = invoke();
548
+ if (typeof result === "object" && result !== null && "then" in result && typeof result.then === "function") {
549
+ Promise.resolve(result).catch(() => {
550
+ return;
551
+ });
552
+ }
553
+ } catch {}
554
+ }
555
+ function emitStartupPhase(callback, phase) {
556
+ if (callback === undefined)
557
+ return;
558
+ const parsed = ExecutorStartupPhaseSchema2.parse(phase);
559
+ invokeSafely(() => callback(parsed));
560
+ }
561
+ function clampUniqueWindowName(prefix, suffix, seenNames, disambiguatorSeed, maxChars = 256) {
562
+ const maxPrefix = Math.max(1, maxChars - suffix.length);
563
+ let candidate = prefix.length > maxPrefix ? `${prefix.slice(0, maxPrefix)}${suffix}`.slice(0, maxChars) : `${prefix}${suffix}`;
564
+ if (!seenNames.has(candidate)) {
565
+ seenNames.add(candidate);
566
+ return candidate;
567
+ }
568
+ const digest = createHash("sha256").update(disambiguatorSeed).digest("hex").slice(0, 8);
569
+ const tag = `#${digest}${suffix}`;
570
+ const room = Math.max(1, maxChars - tag.length);
571
+ candidate = `${prefix.slice(0, room)}${tag}`.slice(0, maxChars);
572
+ let index = 2;
573
+ while (seenNames.has(candidate)) {
574
+ const indexedTag = `#${digest}_${index}${suffix}`;
575
+ const indexedRoom = Math.max(1, maxChars - indexedTag.length);
576
+ candidate = `${prefix.slice(0, indexedRoom)}${indexedTag}`.slice(0, maxChars);
577
+ index += 1;
578
+ }
579
+ seenNames.add(candidate);
580
+ return candidate;
581
+ }
582
+
583
+ export { ExecutorRawSchema2, ExecutorTokenUsageSchema2, ExecutorModelUsageSchema2, ExecutorThreadDispositionSchema2, ExecutorStartupPhaseSchema2, ExecutorStatusDeltaSchema2, ExecutorErrorKindSchema2, ExecutorDeltaSchema2, ThreadClaimSchema2, ThreadLeaseSchema2, ThreadRenewSchema2, ThreadReleaseSchema2, TurnOfferSchema2, TurnPhaseSchema2, TurnFailureKindSchema2, TurnReportSchema2, TurnReportAckSchema2, TurnInterruptSchema2, InteractionReplySchema2, EXECUTOR_ERRORS2, ExecutorEngineSchema2, ExecutorReconcileSchema2, ExecutorDriverCapabilitiesSchema2, PlanWindowSchema2, PlanLimitsSchema2, ExecutorProfileSchema2, ExecutorEngineInfoSchema2, ExecutorResumableTurnSchema2, ExecutorHelloSchema2, ExecutorHelloAckSchema2, EXECUTOR_ENV_KEY_PATTERN2, sanitizeProfileEnv2, ExecutorProfileConfigSchema2, engineProfile, CREDENTIAL_VARIABLES2, engineEnvironment2, ownCredentials2, helloProfile2, TURN_QUEUE, nonEmptyString, clampPlanName, epochMsToIso, epochSecondsToIso, createTurnDeltaChannel, offerTurnDelta, sessionAbort, runEngineCli, stopConnection, withEphemeralConnection, safeJsonValue, invokeSafely, emitStartupPhase, clampUniqueWindowName };
@@ -0,0 +1,56 @@
1
+ import {
2
+ offerTurnDelta
3
+ } from "./index-g2d9kws8.js";
4
+
5
+ // src/agent-executor/engine-requests.ts
6
+ function holdEngineRequest(turn, request) {
7
+ if (turn.state.interruptRequested) {
8
+ request.resolve(request.refusal);
9
+ return;
10
+ }
11
+ const offered = request.delta();
12
+ turn.pending.set(request.interactionId, {
13
+ detail: request.detail,
14
+ answeredBy: request.answeredBy,
15
+ resolve: request.resolve
16
+ });
17
+ offerTurnDelta(turn.channel, offered);
18
+ }
19
+ function answerEngineRequest(turn, interactionId, answer) {
20
+ const waiting = turn.pending.get(interactionId);
21
+ if (waiting === undefined)
22
+ return false;
23
+ waiting.resolve(answer);
24
+ turn.pending.delete(interactionId);
25
+ offerTurnDelta(turn.channel, {
26
+ type: "request-resolved",
27
+ turnId: turn.state.turnId,
28
+ itemId: `resolved:${interactionId}`,
29
+ raw: waiting.answeredBy,
30
+ interactionId
31
+ });
32
+ return true;
33
+ }
34
+ function drainEngineRequests(turn, answer) {
35
+ if (turn === undefined)
36
+ return;
37
+ for (const [interactionId, waiting] of [...turn.pending]) {
38
+ answerEngineRequest(turn, interactionId, answer(waiting));
39
+ }
40
+ }
41
+ function endEngineTurn(turn, answer, deltas) {
42
+ if (turn === undefined)
43
+ return;
44
+ drainEngineRequests(turn, answer);
45
+ for (const delta of deltas)
46
+ offerTurnDelta(turn.channel, delta);
47
+ turn.channel.close();
48
+ }
49
+ function loseEngineTurn(turn, answer, error) {
50
+ if (turn === undefined)
51
+ return;
52
+ drainEngineRequests(turn, answer);
53
+ turn.channel.fail(error);
54
+ }
55
+
56
+ export { holdEngineRequest, answerEngineRequest, drainEngineRequests, endEngineTurn, loseEngineTurn };