@promptbook/cli 0.113.0-4 → 0.113.0-8

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 (141) hide show
  1. package/apps/agents-server/src/app/admin/update/AdvancedOriginRepositoryPanel.tsx +76 -0
  2. package/apps/agents-server/src/app/admin/update/CurrentDeploymentCard.tsx +160 -0
  3. package/apps/agents-server/src/app/admin/update/PendingCommitsCard.tsx +86 -0
  4. package/apps/agents-server/src/app/admin/update/TargetEnvironmentCard.tsx +331 -0
  5. package/apps/agents-server/src/app/admin/update/UpdateClient.tsx +20 -873
  6. package/apps/agents-server/src/app/admin/update/UpdateJobCard.tsx +329 -0
  7. package/apps/agents-server/src/app/admin/update/UpdateOverview.ts +74 -0
  8. package/apps/agents-server/src/app/admin/update/buildDeploymentTimeBehindLabel.ts +29 -0
  9. package/apps/agents-server/src/app/admin/update/formatHumanReadableTimestamp.ts +18 -0
  10. package/apps/agents-server/src/app/admin/update/getUpdateJobFailureMessage.ts +13 -0
  11. package/apps/agents-server/src/app/admin/update/getUpdateJobSuccessMessage.ts +13 -0
  12. package/apps/agents-server/src/app/admin/update/useUpdateClientState.ts +441 -0
  13. package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +13 -1
  14. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/AgentCodePageClient.tsx +14 -559
  15. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/AgentCodePageHeader.tsx +84 -0
  16. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/AgentCodePageSection.tsx +52 -0
  17. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/GeneratedCodePreview.tsx +138 -0
  18. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/GeneratedHarnessSection.tsx +98 -0
  19. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/SourceBookSection.tsx +66 -0
  20. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/TranspiledCodeErrorBanner.tsx +30 -0
  21. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/TranspiledCodeExportWarningBanner.tsx +62 -0
  22. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/Transpiler.ts +9 -0
  23. package/apps/agents-server/src/app/agents/[agentName]/export-as-transpiled-code/useAgentCodeExportState.ts +478 -0
  24. package/apps/agents-server/src/app/system/utilities/mocked-chats/cloneMockedChatPreset.ts +17 -0
  25. package/apps/agents-server/src/app/system/utilities/mocked-chats/confirmDeleteMockedChat.ts +16 -0
  26. package/apps/agents-server/src/app/system/utilities/mocked-chats/createDraftWithUpdatedMessage.ts +81 -0
  27. package/apps/agents-server/src/app/system/utilities/mocked-chats/createDraftWithUpdatedParticipant.ts +146 -0
  28. package/apps/agents-server/src/app/system/utilities/mocked-chats/createDraftWithUpdatedSettings.ts +19 -0
  29. package/apps/agents-server/src/app/system/utilities/mocked-chats/createDuplicatedDraft.ts +66 -0
  30. package/apps/agents-server/src/app/system/utilities/mocked-chats/findMockedChatById.ts +51 -0
  31. package/apps/agents-server/src/app/system/utilities/mocked-chats/persistMockedChats.ts +51 -0
  32. package/apps/agents-server/src/app/system/utilities/mocked-chats/useMockedChatsEditorState.ts +16 -426
  33. package/apps/agents-server/src/components/Homepage/buildFreeGraphBoxLayout.ts +446 -0
  34. package/apps/agents-server/src/components/Homepage/buildGraphLayoutNodes.ts +415 -157
  35. package/apps/agents-server/src/components/Homepage/useAgentsGraphCanvasState.ts +2 -1
  36. package/apps/agents-server/src/database/sqlite/$provideLocalSqliteSupabase.ts +3 -1541
  37. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/LocalSqliteQueryBuilder.ts +623 -0
  38. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/LocalSqliteSupabaseClient.ts +64 -0
  39. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/ensureTable.ts +93 -0
  40. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteFilters.ts +202 -0
  41. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteMutationPayload.ts +131 -0
  42. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteRowOperations.ts +102 -0
  43. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteSql.ts +59 -0
  44. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteTableSchema.ts +329 -0
  45. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteTypes.ts +84 -0
  46. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/localSqliteValueCodec.ts +63 -0
  47. package/apps/agents-server/src/database/sqlite/localSqliteSupabase/normalizeSqliteError.ts +22 -0
  48. package/apps/agents-server/src/search/createDefaultServerSearchProviders/loadLocalOrganizationSearchDataset.ts +12 -1
  49. package/apps/agents-server/src/tools/send_email.ts +1 -2
  50. package/apps/agents-server/src/utils/agentOrganization/loadAgentOrganizationState.ts +13 -1
  51. package/apps/agents-server/src/utils/backup/createServerBackupZipStream.ts +7 -1382
  52. package/apps/agents-server/src/utils/backup/serverBackup/appendAgentBackupEntriesToZip.ts +27 -0
  53. package/apps/agents-server/src/utils/backup/serverBackup/appendConversationBackupEntriesToZip.ts +140 -0
  54. package/apps/agents-server/src/utils/backup/serverBackup/appendFileBackupEntriesToZip.ts +147 -0
  55. package/apps/agents-server/src/utils/backup/serverBackup/appendMessageBackupEntriesToZip.ts +65 -0
  56. package/apps/agents-server/src/utils/backup/serverBackup/appendMetadataBackupEntriesToZip.ts +39 -0
  57. package/apps/agents-server/src/utils/backup/serverBackup/appendSectionEntriesToZip.ts +92 -0
  58. package/apps/agents-server/src/utils/backup/serverBackup/appendUserBackupEntriesToZip.ts +80 -0
  59. package/apps/agents-server/src/utils/backup/serverBackup/createRedactedWalletBackupRecord.ts +34 -0
  60. package/apps/agents-server/src/utils/backup/serverBackup/createServerBackupManifest.ts +82 -0
  61. package/apps/agents-server/src/utils/backup/serverBackup/downloadBackupBinaryContent.ts +39 -0
  62. package/apps/agents-server/src/utils/backup/serverBackup/resolveFeedbackThreadMessages.ts +53 -0
  63. package/apps/agents-server/src/utils/backup/serverBackup/serverBackupAttachments.ts +151 -0
  64. package/apps/agents-server/src/utils/backup/serverBackup/serverBackupContext.ts +167 -0
  65. package/apps/agents-server/src/utils/backup/serverBackup/serverBackupFilenames.ts +161 -0
  66. package/apps/agents-server/src/utils/backup/serverBackup/serverBackupPreviews.ts +97 -0
  67. package/apps/agents-server/src/utils/backup/serverBackup/serverBackupRowUtilities.ts +158 -0
  68. package/apps/agents-server/src/utils/backup/serverBackup/serverBackupTypes.ts +59 -0
  69. package/apps/agents-server/src/utils/createLocalAgentSourceImporter.ts +159 -0
  70. package/apps/agents-server/src/utils/createMissingImportedAgentFallback.ts +60 -0
  71. package/apps/agents-server/src/utils/customDomainRouting.ts +157 -12
  72. package/apps/agents-server/src/utils/externalChatRunner/processExternalUserChatJob.ts +1 -1
  73. package/apps/agents-server/src/utils/importAgentWithFallback.ts +1 -58
  74. package/apps/agents-server/src/utils/localAgentRouteReferences.ts +167 -0
  75. package/apps/agents-server/src/utils/localChatRunner/processLocalUserChatJob.ts +1 -1
  76. package/apps/agents-server/src/utils/managementApi/managementApiAgents.ts +17 -3
  77. package/apps/agents-server/src/utils/messages/sendMessage.ts +5 -3
  78. package/apps/agents-server/src/utils/resolveAgentStateFromSource.ts +7 -1
  79. package/apps/agents-server/src/utils/resolveInheritedAgentSource.ts +54 -5
  80. package/apps/agents-server/src/utils/resolveServerAgentContext.ts +12 -1
  81. package/apps/agents-server/src/utils/resolveStoredAgentState.ts +2 -1
  82. package/apps/agents-server/src/utils/speech-to-text/SpeechToTextFailoverRecognition/SpeechToTextFailoverRecognitionProviderRuntime.ts +0 -1
  83. package/apps/agents-server/src/utils/speech-to-text/SpeechToTextFailoverRecognition.ts +34 -2
  84. package/apps/agents-server/src/utils/userChat/userChatMessageLifecycle.ts +39 -9
  85. package/apps/agents-server/tests/e2e/support/ChatHistoryNavigationSupport.ts +5 -0
  86. package/esm/index.es.js +875 -60
  87. package/esm/index.es.js.map +1 -1
  88. package/esm/scripts/find-refactor-candidates/find-refactor-candidates.d.ts +7 -0
  89. package/esm/scripts/find-refactor-candidates/selectMostImportantRefactorCandidates.d.ts +12 -0
  90. package/esm/scripts/run-codex-prompts/common/resolveCoderAgent.d.ts +20 -0
  91. package/esm/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +5 -0
  92. package/esm/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +29 -0
  93. package/esm/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +4 -0
  94. package/esm/src/avatars/renderAvatarVisualAsciiArt.d.ts +75 -0
  95. package/esm/src/book-components/Chat/Chat/insertDictationChunk.d.ts +1 -1
  96. package/esm/src/book-components/Chat/Chat/insertDictationChunk.test.d.ts +1 -0
  97. package/esm/src/book-components/Chat/Chat/learnDictationDictionary.test.d.ts +1 -0
  98. package/esm/src/book-components/Chat/Chat/refineFinalDictationChunk.test.d.ts +1 -0
  99. package/esm/src/cli/cli-commands/common/createPositiveIntegerOptionParser.d.ts +10 -0
  100. package/esm/src/utils/ascii-art/$detectTerminalAnsiColorDepth.d.ts +15 -0
  101. package/esm/src/utils/ascii-art/convertImageDataToAsciiArt.d.ts +80 -0
  102. package/esm/src/version.d.ts +1 -1
  103. package/package.json +1 -1
  104. package/src/avatars/avatarAnimationScheduler.ts +2 -1
  105. package/src/avatars/renderAvatarVisualAsciiArt.ts +138 -0
  106. package/src/avatars/visuals/octopus3d3AvatarVisual.ts +6 -2
  107. package/src/avatars/visuals/octopus3d4AvatarVisual.ts +14 -18
  108. package/src/book-components/Chat/Chat/insertDictationChunk.ts +3 -3
  109. package/src/book-components/Chat/Chat/learnDictationDictionary.ts +1 -1
  110. package/src/book-components/Chat/Chat/useChatInputAreaDictation.ts +133 -26
  111. package/src/cli/cli-commands/agents-server/buildAgentsServer.ts +3 -1
  112. package/src/cli/cli-commands/coder/boilerplateTemplates.ts +14 -21
  113. package/src/cli/cli-commands/coder/find-refactor-candidates.ts +9 -2
  114. package/src/cli/cli-commands/coder/initializeCoderProjectConfiguration.ts +1 -4
  115. package/src/cli/cli-commands/coder/run.ts +3 -27
  116. package/src/cli/cli-commands/common/createPositiveIntegerOptionParser.ts +31 -0
  117. package/src/commitments/TEAM/TEAM.ts +5 -5
  118. package/src/other/templates/getTemplatesPipelineCollection.ts +770 -1169
  119. package/src/utils/ascii-art/$detectTerminalAnsiColorDepth.ts +45 -0
  120. package/src/utils/ascii-art/convertImageDataToAsciiArt.ts +396 -0
  121. package/src/version.ts +2 -2
  122. package/src/versions.txt +2 -0
  123. package/umd/index.umd.js +875 -60
  124. package/umd/index.umd.js.map +1 -1
  125. package/umd/scripts/find-refactor-candidates/find-refactor-candidates.d.ts +7 -0
  126. package/umd/scripts/find-refactor-candidates/selectMostImportantRefactorCandidates.d.ts +12 -0
  127. package/umd/scripts/run-codex-prompts/common/resolveCoderAgent.d.ts +20 -0
  128. package/umd/scripts/run-codex-prompts/ui/CoderRunUiState.d.ts +5 -0
  129. package/umd/scripts/run-codex-prompts/ui/buildCoderRunAgentVisual.d.ts +29 -0
  130. package/umd/scripts/run-codex-prompts/ui/buildCoderRunUiFrame.d.ts +4 -0
  131. package/umd/src/avatars/renderAvatarVisualAsciiArt.d.ts +75 -0
  132. package/umd/src/book-components/Chat/Chat/insertDictationChunk.d.ts +1 -1
  133. package/umd/src/book-components/Chat/Chat/insertDictationChunk.test.d.ts +1 -0
  134. package/umd/src/book-components/Chat/Chat/learnDictationDictionary.test.d.ts +1 -0
  135. package/umd/src/book-components/Chat/Chat/refineFinalDictationChunk.test.d.ts +1 -0
  136. package/umd/src/cli/cli-commands/common/createPositiveIntegerOptionParser.d.ts +10 -0
  137. package/umd/src/utils/ascii-art/$detectTerminalAnsiColorDepth.d.ts +15 -0
  138. package/umd/src/utils/ascii-art/convertImageDataToAsciiArt.d.ts +80 -0
  139. package/umd/src/version.d.ts +1 -1
  140. package/esm/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +0 -6
  141. package/umd/scripts/run-codex-prompts/common/resolveAgentSystemMessage.d.ts +0 -6
@@ -231,8 +231,42 @@ type ResolveInheritedAgentSourceOptions = ImportAgentOptions & {
231
231
  * Retry configuration used for federated imported-agent loading.
232
232
  */
233
233
  readonly federatedAgentImportConfiguration?: FederatedAgentImportConfiguration;
234
+ /**
235
+ * Optional same-instance source importer used before falling back to HTTP import.
236
+ */
237
+ readonly agentSourceImporter?: AgentSourceImporter;
234
238
  };
235
239
 
240
+ /**
241
+ * Context passed to a custom agent source importer.
242
+ */
243
+ export type AgentSourceImporterContext = {
244
+ /**
245
+ * Commitment that requested the imported source.
246
+ */
247
+ readonly commitmentType: 'FROM' | 'IMPORT';
248
+
249
+ /**
250
+ * Import options propagated from the current resolution pass.
251
+ */
252
+ readonly importAgentOptions: ImportAgentOptions;
253
+
254
+ /**
255
+ * Retry configuration used by the default HTTP importer.
256
+ */
257
+ readonly federatedAgentImportConfiguration: FederatedAgentImportConfiguration;
258
+ };
259
+
260
+ /**
261
+ * Imports one agent source before the resolver falls back to the default HTTP importer.
262
+ *
263
+ * Return `null` when the importer does not own the given URL.
264
+ */
265
+ export type AgentSourceImporter = (
266
+ agentUrl: string_agent_url,
267
+ context: AgentSourceImporterContext,
268
+ ) => Promise<string_book | null>;
269
+
236
270
  /**
237
271
  * Parent inheritance state derived before rewriting the source body.
238
272
  */
@@ -277,6 +311,11 @@ type AgentImportContext = {
277
311
  */
278
312
  readonly importAgentOptions: ImportAgentOptions;
279
313
 
314
+ /**
315
+ * Optional importer for same-instance agent sources.
316
+ */
317
+ readonly agentSourceImporter?: AgentSourceImporter;
318
+
280
319
  /**
281
320
  * Original resolution options used for cycle detection.
282
321
  */
@@ -364,6 +403,7 @@ function createAgentImportContext(options?: ResolveInheritedAgentSourceOptions):
364
403
  recursionLevel: options?.recursionLevel || 0,
365
404
  inheritancePath: createResolutionLineage(options),
366
405
  },
406
+ agentSourceImporter: options?.agentSourceImporter,
367
407
  resolutionOptions: options,
368
408
  };
369
409
  }
@@ -427,11 +467,20 @@ async function importAgentCorpus(
427
467
  ): Promise<string> {
428
468
  assertNoResolutionCycle(agentUrl, commitmentType, context.resolutionOptions);
429
469
 
430
- const importedAgentSource = await importAgentWithFallback(
431
- agentUrl,
432
- context.importAgentOptions,
433
- context.federatedAgentImportConfiguration,
434
- );
470
+ const locallyImportedAgentSource = context.agentSourceImporter
471
+ ? await context.agentSourceImporter(agentUrl, {
472
+ commitmentType,
473
+ importAgentOptions: context.importAgentOptions,
474
+ federatedAgentImportConfiguration: context.federatedAgentImportConfiguration,
475
+ })
476
+ : null;
477
+ const importedAgentSource =
478
+ locallyImportedAgentSource ??
479
+ (await importAgentWithFallback(
480
+ agentUrl,
481
+ context.importAgentOptions,
482
+ context.federatedAgentImportConfiguration,
483
+ ));
435
484
 
436
485
  return getAgentSourceCorpus(importedAgentSource as string_book);
437
486
  }
@@ -1,6 +1,7 @@
1
1
  import type { AgentReferenceResolver } from '../../../../src/book-2.0/agent-source/AgentReferenceResolver';
2
2
  import type { AgentCollection } from '../../../../src/collection/agent-collection/AgentCollection';
3
3
  import { resolveBookScopedAgentContext, type ResolvedBookScopedAgentContext } from './agentReferenceResolver/bookScopedAgentReferences';
4
+ import { createLocalAgentSourceImporter } from './createLocalAgentSourceImporter';
4
5
  import { loadFederatedAgentImportConfiguration } from './federatedAgentImportConfiguration';
5
6
  import { getWellKnownAgentUrl } from './getWellKnownAgentUrl';
6
7
  import { resolveAgentStateFromSource, type ResolvedAgentState } from './resolveAgentStateFromSource';
@@ -46,12 +47,22 @@ export async function resolveServerAgentContext(
46
47
  ): Promise<ResolvedServerAgentContext> {
47
48
  const bookScopedAgentContext = await resolveBookScopedAgentContext(options);
48
49
  const federatedAgentImportConfiguration = await loadFederatedAgentImportConfiguration();
50
+ const adamAgentUrl = await getWellKnownAgentUrl('ADAM');
51
+ const agentSourceImporter = createLocalAgentSourceImporter({
52
+ collection: options.collection,
53
+ localServerUrls: [options.localServerUrl],
54
+ localAgentUrls: [adamAgentUrl],
55
+ adamAgentUrl,
56
+ fallbackResolver: options.fallbackResolver,
57
+ federatedAgentImportConfiguration,
58
+ });
49
59
  const resolvedAgentState = await resolveAgentStateFromSource(bookScopedAgentContext.unresolvedAgentSource, {
50
- adamAgentUrl: await getWellKnownAgentUrl('ADAM'),
60
+ adamAgentUrl,
51
61
  canonicalAgentUrl: bookScopedAgentContext.canonicalAgentUrl,
52
62
  currentAgentAliases: bookScopedAgentContext.currentAgentAliases,
53
63
  agentReferenceResolver: bookScopedAgentContext.scopedAgentReferenceResolver,
54
64
  federatedAgentImportConfiguration,
65
+ agentSourceImporter,
55
66
  });
56
67
 
57
68
  return {
@@ -30,7 +30,7 @@ export type ResolvedStoredAgentState<TAgent extends StoredAgentSourceRecord> = T
30
30
  */
31
31
  export type ResolveStoredAgentStateOptions = Pick<
32
32
  ResolveAgentStateFromSourceOptions,
33
- 'adamAgentUrl' | 'agentReferenceResolver' | 'federatedAgentImportConfiguration'
33
+ 'adamAgentUrl' | 'agentReferenceResolver' | 'federatedAgentImportConfiguration' | 'agentSourceImporter'
34
34
  > & {
35
35
  /**
36
36
  * Public/current server origin used to build canonical local agent URLs.
@@ -91,6 +91,7 @@ export async function resolveStoredAgentState<TAgent extends StoredAgentSourceRe
91
91
  currentAgentAliases: createCanonicalLocalAgentAliases(agent, options.localServerUrl),
92
92
  agentReferenceResolver: options.agentReferenceResolver,
93
93
  federatedAgentImportConfiguration,
94
+ agentSourceImporter: options.agentSourceImporter,
94
95
  });
95
96
 
96
97
  return {
@@ -172,7 +172,6 @@ export class SpeechToTextFailoverRecognitionProviderRuntime {
172
172
  }
173
173
  }
174
174
 
175
- this.options.onForceIdleStop();
176
175
  return false;
177
176
  }
178
177
 
@@ -302,13 +302,45 @@ export class SpeechToTextFailoverRecognition implements SpeechRecognition {
302
302
  * Handles stall watchdog restart/failover escalation.
303
303
  */
304
304
  private handleStallDetected(): void {
305
+ void this.handleStallDetectedAsync();
306
+ }
307
+
308
+ /**
309
+ * Handles stall watchdog restart/failover escalation.
310
+ */
311
+ private async handleStallDetectedAsync(): Promise<void> {
312
+ const providerId = this.providerRuntime.currentProviderId;
313
+
305
314
  if (!this.providerRuntime.hasRestartedCurrentProvider) {
306
315
  this.providerRuntime.markCurrentProviderRestarted();
307
- void this.providerRuntime.restartCurrentProvider('stall-detected');
316
+ this.telemetryReporter.emit({
317
+ type: 'provider-restart',
318
+ providerId,
319
+ elapsedMs: Date.now() - this.sessionStartedAtMs,
320
+ detail: 'stall-detected',
321
+ });
322
+
323
+ const restartSucceeded = await this.providerRuntime.restartCurrentProvider('stall-detected');
324
+ if (restartSucceeded) {
325
+ return;
326
+ }
327
+ }
328
+
329
+ const failoverSucceeded = await this.providerRuntime.failoverToNextProvider('stall-after-restart');
330
+ if (failoverSucceeded) {
308
331
  return;
309
332
  }
310
333
 
311
- void this.providerRuntime.failoverToNextProvider('stall-after-restart');
334
+ this._state = 'ERROR';
335
+ this.emit({
336
+ type: 'ERROR',
337
+ message: 'Speech recognition stalled while audio was detected. No fallback speech-to-text provider was available.',
338
+ code: 'unknown',
339
+ providerId,
340
+ canRetry: true,
341
+ canOpenBrowserSettings: false,
342
+ });
343
+ this.forceIdleStop();
312
344
  }
313
345
 
314
346
  /**
@@ -1,4 +1,6 @@
1
1
  import type { ChatMessage } from '../../../../../src/_packages/types.index';
2
+ import { appendChatAttachmentContextWithContent } from '../../../../../src/utils/chat/chatAttachments/appendChatAttachmentContextWithContent';
3
+
2
4
  /**
3
5
  * Lifecycle states rendered on canonical server-owned chat messages.
4
6
  */
@@ -99,11 +101,11 @@ export function resolvePromptThreadBeforeUserMessage(
99
101
  /**
100
102
  * Creates the complete chat thread mirrored to a runner before it writes the next answer.
101
103
  */
102
- export function createUserChatRunnerThreadMessages(options: {
104
+ export async function createUserChatRunnerThreadMessages(options: {
103
105
  messages: ReadonlyArray<ChatMessage>;
104
106
  userMessageId: string;
105
107
  resolveInitialAgentMessage: () => string | null | undefined;
106
- }): Array<UserChatRunnerThreadMessage> {
108
+ }): Promise<Array<UserChatRunnerThreadMessage>> {
107
109
  const userMessage = options.messages.find((message) => message.id === options.userMessageId);
108
110
  if (!userMessage) {
109
111
  return [];
@@ -111,19 +113,16 @@ export function createUserChatRunnerThreadMessages(options: {
111
113
 
112
114
  const previousThreadMessages = resolvePromptThreadBeforeUserMessage(options.messages, options.userMessageId);
113
115
 
114
- return [
116
+ const threadMessages = [
115
117
  ...createInitialUserChatRunnerThreadMessages({
116
118
  isFirstUserTurn: previousThreadMessages.length === 0,
117
119
  resolveInitialAgentMessage: options.resolveInitialAgentMessage,
118
120
  }),
119
121
  ...previousThreadMessages,
120
122
  userMessage,
121
- ]
122
- .filter(isUserChatRunnerThreadMessage)
123
- .map((message) => ({
124
- sender: message.sender,
125
- content: message.content,
126
- }));
123
+ ].filter(isUserChatRunnerThreadMessage);
124
+
125
+ return await Promise.all(threadMessages.map(createUserChatRunnerThreadMessage));
127
126
  }
128
127
 
129
128
  /**
@@ -176,3 +175,34 @@ function isUserChatRunnerThreadMessage(message: ChatMessage): message is ChatMes
176
175
  const isRunnerSender = message.sender === 'USER' || message.sender === 'AGENT';
177
176
  return message.isComplete !== false && isRunnerSender;
178
177
  }
178
+
179
+ /**
180
+ * Creates one runner-visible message with attachment context inlined into user-authored content.
181
+ *
182
+ * @private helper of `createUserChatRunnerThreadMessages`
183
+ */
184
+ async function createUserChatRunnerThreadMessage(
185
+ message: ChatMessage & UserChatRunnerThreadMessage,
186
+ ): Promise<UserChatRunnerThreadMessage> {
187
+ return {
188
+ sender: message.sender,
189
+ content: await createUserChatRunnerThreadMessageContent(message),
190
+ };
191
+ }
192
+
193
+ /**
194
+ * Adds attachment URLs and best-effort text previews to user messages mirrored into runner `.book` files.
195
+ *
196
+ * @private helper of `createUserChatRunnerThreadMessage`
197
+ */
198
+ async function createUserChatRunnerThreadMessageContent(
199
+ message: ChatMessage & UserChatRunnerThreadMessage,
200
+ ): Promise<string> {
201
+ if (message.sender !== 'USER' || !message.attachments || message.attachments.length === 0) {
202
+ return message.content;
203
+ }
204
+
205
+ return await appendChatAttachmentContextWithContent(message.content, message.attachments, {
206
+ allowLocalhost: true,
207
+ });
208
+ }
@@ -212,6 +212,7 @@ async function delayNextMatchingRequest(
212
212
  options: DelayNextMatchingRequestOptions,
213
213
  ): Promise<DelayedRequestControl> {
214
214
  let hasInterceptedTargetRequest = false;
215
+ let isReleased = false;
215
216
  let releaseRequest: (() => void) | null = null;
216
217
  let markStarted: (() => void) | null = null;
217
218
  let markFinished: (() => void) | null = null;
@@ -239,6 +240,9 @@ async function delayNextMatchingRequest(
239
240
 
240
241
  await new Promise<void>((resolve) => {
241
242
  releaseRequest = resolve;
243
+ if (isReleased) {
244
+ resolve();
245
+ }
242
246
  });
243
247
 
244
248
  try {
@@ -255,6 +259,7 @@ async function delayNextMatchingRequest(
255
259
  waitUntilStarted,
256
260
  waitUntilFinished,
257
261
  release() {
262
+ isReleased = true;
258
263
  releaseRequest?.();
259
264
  },
260
265
  async dispose() {