agl 43.14.0 → 44.0.1

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 (89) hide show
  1. package/changelog.md +33 -0
  2. package/dist_serve/bundle.js +4473 -4235
  3. package/dist_serve/bundle.js.map +2 -2
  4. package/dist_serve/bundle.js.third-party-notices.json +29 -29
  5. package/dist_serve/bundle.js.third-party-notices.txt +29 -29
  6. package/dist_ts/00_commitinfo_data.js +2 -2
  7. package/dist_ts/aglapi/aglapisurface.document.js +37 -4
  8. package/dist_ts/classes.authstore.d.ts +60 -3
  9. package/dist_ts/classes.authstore.js +161 -13
  10. package/dist_ts/classes.controller.d.ts +63 -0
  11. package/dist_ts/classes.controller.js +502 -43
  12. package/dist_ts/classes.embeddeddb.js +7 -2
  13. package/dist_ts/classes.flexmodels.private.d.ts +39 -0
  14. package/dist_ts/classes.flexmodels.private.js +127 -1
  15. package/dist_ts/classes.flexprojectpreparation.d.ts +21 -0
  16. package/dist_ts/classes.flexprojectpreparation.js +69 -0
  17. package/dist_ts/classes.flexpromptqueue.d.ts +21 -1
  18. package/dist_ts/classes.flexpromptqueue.js +67 -7
  19. package/dist_ts/classes.flexrequestqueue.d.ts +11 -0
  20. package/dist_ts/classes.flexrequestqueue.js +40 -0
  21. package/dist_ts/classes.flexservice.d.ts +46 -14
  22. package/dist_ts/classes.flexservice.js +179 -55
  23. package/dist_ts/classes.flexstore.d.ts +68 -3
  24. package/dist_ts/classes.flexstore.js +277 -11
  25. package/dist_ts/classes.flexsubmissionmodels.d.ts +58 -0
  26. package/dist_ts/classes.flexsubmissionmodels.js +162 -0
  27. package/dist_ts/classes.flexsubmissionstore.d.ts +70 -0
  28. package/dist_ts/classes.flexsubmissionstore.js +323 -0
  29. package/dist_ts/classes.flexsupervisor.d.ts +10 -0
  30. package/dist_ts/classes.flexsupervisor.js +27 -1
  31. package/dist_ts/classes.harnessoperationmanager.d.ts +31 -0
  32. package/dist_ts/classes.harnessoperationmanager.js +69 -7
  33. package/dist_ts/classes.pendingpromptstore.d.ts +11 -3
  34. package/dist_ts/classes.pendingpromptstore.js +66 -10
  35. package/dist_ts/classes.sessionidentityservice.d.ts +18 -1
  36. package/dist_ts/classes.sessionidentityservice.js +34 -4
  37. package/dist_ts/classes.validation.d.ts +3 -0
  38. package/dist_ts/classes.validation.js +50 -1
  39. package/dist_ts/functions.deviceapi.js +3 -1
  40. package/dist_ts/interfaces.auth.d.ts +3 -1
  41. package/dist_ts/interfaces.auth.js +1 -1
  42. package/dist_ts/interfaces.flexipc.d.ts +29 -5
  43. package/dist_ts/interfaces.flexipc.js +13 -4
  44. package/dist_ts_authswitch/classes.authoritydatabase.d.ts +1 -0
  45. package/dist_ts_authswitch/classes.authoritydatabase.js +17 -5
  46. package/dist_ts_interfaces/flexadmission.d.ts +69 -0
  47. package/dist_ts_interfaces/flexadmission.js +2 -0
  48. package/dist_ts_interfaces/index.d.ts +1 -0
  49. package/dist_ts_interfaces/index.js +2 -1
  50. package/dist_ts_interfaces/interfaces.d.ts +10 -1
  51. package/dist_ts_interfaces/interfaces.js +2 -2
  52. package/dist_ts_interfaces/requests.d.ts +2 -1
  53. package/dist_ts_interfaces/requests.js +1 -1
  54. package/dist_ts_migration/v10_flexharnessv3migration.js +4 -1
  55. package/docs/nosqldb11-migration.md +59 -0
  56. package/package.json +10 -9
  57. package/readme.md +5 -1
  58. package/ts/00_commitinfo_data.ts +1 -1
  59. package/ts/aglapi/aglapisurface.document.ts +36 -3
  60. package/ts/classes.authstore.ts +179 -11
  61. package/ts/classes.controller.ts +498 -40
  62. package/ts/classes.embeddeddb.ts +6 -1
  63. package/ts/classes.flexmodels.private.ts +109 -0
  64. package/ts/classes.flexprojectpreparation.ts +69 -0
  65. package/ts/classes.flexpromptqueue.ts +69 -6
  66. package/ts/classes.flexrequestqueue.ts +47 -0
  67. package/ts/classes.flexservice.ts +187 -51
  68. package/ts/classes.flexstore.ts +352 -10
  69. package/ts/classes.flexsubmissionmodels.ts +89 -0
  70. package/ts/classes.flexsubmissionstore.ts +312 -0
  71. package/ts/classes.flexsupervisor.ts +26 -0
  72. package/ts/classes.harnessoperationmanager.ts +79 -6
  73. package/ts/classes.pendingpromptstore.ts +55 -6
  74. package/ts/classes.sessionidentityservice.ts +33 -2
  75. package/ts/classes.validation.ts +42 -0
  76. package/ts/functions.deviceapi.ts +2 -0
  77. package/ts/interfaces.auth.ts +3 -1
  78. package/ts/interfaces.flexipc.ts +38 -4
  79. package/ts_authswitch/classes.authoritydatabase.ts +19 -5
  80. package/ts_interfaces/flexadmission.ts +52 -0
  81. package/ts_interfaces/index.ts +2 -0
  82. package/ts_interfaces/interfaces.ts +10 -1
  83. package/ts_interfaces/requests.ts +3 -0
  84. package/ts_migration/v10_flexharnessv3migration.ts +3 -0
  85. package/ts_web/00_commitinfo_data.ts +1 -1
  86. package/ts_web/classes.browsersubmissions.ts +279 -0
  87. package/ts_web/classes.sessiondraftsync.ts +64 -1
  88. package/ts_web/elements.harnesscontrollerapp.ts +340 -5
  89. package/ts_web/functions.flexsubmissions.ts +88 -0
@@ -75,6 +75,8 @@ interface IActiveDraft {
75
75
  writeTask?: Promise<IControllerSessionDraft>;
76
76
  submissionToken?: symbol;
77
77
  pendingAppend?: IPendingDraftAppend;
78
+ detachedText?: boolean;
79
+ detachedAttachments?: boolean;
78
80
  }
79
81
 
80
82
  interface IPreparedSubmission {
@@ -193,6 +195,7 @@ export class SessionDraftSync {
193
195
  if (active.pendingAppend !== undefined && active.pendingAppend.textAtAppend !== textArg) {
194
196
  active.pendingAppend = undefined;
195
197
  }
198
+ active.detachedText = false;
196
199
  active.desiredText = textArg;
197
200
  active.dirtyText = active.desiredText !== active.authoritative.text;
198
201
  active.error = '';
@@ -253,6 +256,7 @@ export class SessionDraftSync {
253
256
  public setAttachments(attachmentsArg: readonly IControllerDraftAttachment[]): void {
254
257
  const active = this.active;
255
258
  if (!active || active.loading) return;
259
+ active.detachedAttachments = false;
256
260
  active.desiredAttachments = cloneAttachments(attachmentsArg);
257
261
  active.dirtyAttachments = !attachmentsEqual(
258
262
  active.desiredAttachments,
@@ -263,6 +267,41 @@ export class SessionDraftSync {
263
267
  this.schedule(active);
264
268
  }
265
269
 
270
+ /** Names a shared revision only when it actually contains the immutable body being captured. */
271
+ public submittedSnapshotRevision(textArg: string, attachmentsArg: readonly IControllerDraftAttachment[]): number | undefined {
272
+ const active = this.active;
273
+ return active && !active.loading && active.authoritative.text === textArg
274
+ && attachmentsEqual(active.authoritative.attachments, attachmentsArg)
275
+ ? active.authoritative.revision : undefined;
276
+ }
277
+
278
+ /**
279
+ * An immutable admission owns its body, not this mutable draft. Detach only the fields that
280
+ * still equal its click-time snapshot, synchronously; later typing/files are the next message.
281
+ * The normal writer keeps its revision-CAS ordering (including a write already in flight).
282
+ * No network result ever restores this body over newer input: a refusal belongs to its row.
283
+ */
284
+ public clearSubmittedSnapshot(
285
+ textArg: string,
286
+ attachmentsArg: readonly IControllerDraftAttachment[],
287
+ ): void {
288
+ const active = this.active;
289
+ if (!active || active.loading || active.submissionToken) return;
290
+ if (active.desiredText === textArg) {
291
+ active.desiredText = '';
292
+ active.detachedText = true;
293
+ active.pendingAppend = undefined;
294
+ }
295
+ if (attachmentsEqual(active.desiredAttachments, attachmentsArg)) {
296
+ active.desiredAttachments = [];
297
+ active.detachedAttachments = true;
298
+ }
299
+ active.dirtyText = active.desiredText !== active.authoritative.text;
300
+ active.dirtyAttachments = !attachmentsEqual(active.desiredAttachments, active.authoritative.attachments);
301
+ this.emit(active);
302
+ this.schedule(active);
303
+ }
304
+
266
305
  public async flush(): Promise<IControllerSessionDraft> {
267
306
  const active = this.active;
268
307
  if (!active) throw new Error('No session draft is active.');
@@ -445,6 +484,7 @@ export class SessionDraftSync {
445
484
  active.desiredAttachments,
446
485
  active.authoritative.attachments,
447
486
  );
487
+ if (!active.writeTask) this.releaseDetachedClear(active);
448
488
  this.emit(active);
449
489
  if (active.dirtyText || active.dirtyAttachments) this.schedule(active);
450
490
  return true;
@@ -465,7 +505,9 @@ export class SessionDraftSync {
465
505
  try {
466
506
  const draft = await this.options.transport.getDraft(activeArg.projectId, activeArg.sessionId);
467
507
  if (!this.canSynchronize(activeArg)) return;
508
+ const revisionAdvanced = draft.revision !== activeArg.authoritative.revision;
468
509
  activeArg.authoritative = cloneDraft(draft);
510
+ if (revisionAdvanced && !activeArg.writeTask) this.releaseDetachedClear(activeArg);
469
511
  const pendingAppend = activeArg.pendingAppend;
470
512
  if (pendingAppend !== undefined) {
471
513
  // The appends are re-applied to the text that is authoritative now, each one only when it
@@ -538,6 +580,9 @@ export class SessionDraftSync {
538
580
  ) {
539
581
  conflictAttempts += 1;
540
582
  await this.hydrate(activeArg);
583
+ // A detached clear never replays against another writer’s newer revision. Only
584
+ // actual next-message edits retain the ordinary whole-draft retry semantics.
585
+ this.releaseDetachedClear(activeArg);
541
586
  continue;
542
587
  }
543
588
  throw errorArg;
@@ -548,6 +593,7 @@ export class SessionDraftSync {
548
593
  activeArg.authoritative = cloneDraft(response);
549
594
  if (sentTextField && activeArg.desiredText === sentText) {
550
595
  activeArg.dirtyText = false;
596
+ activeArg.detachedText = false;
551
597
  // The text the controller now holds is the one that carried the appended blocks, so
552
598
  // nothing is left to re-apply after a later conflict.
553
599
  activeArg.pendingAppend = undefined;
@@ -555,7 +601,10 @@ export class SessionDraftSync {
555
601
  if (
556
602
  sentAttachmentField
557
603
  && attachmentsEqual(activeArg.desiredAttachments, sentAttachments)
558
- ) activeArg.dirtyAttachments = false;
604
+ ) {
605
+ activeArg.dirtyAttachments = false;
606
+ activeArg.detachedAttachments = false;
607
+ }
559
608
  }
560
609
  activeArg.dirtyText = activeArg.desiredText !== activeArg.authoritative.text;
561
610
  activeArg.dirtyAttachments = !attachmentsEqual(
@@ -583,6 +632,20 @@ export class SessionDraftSync {
583
632
  }
584
633
  }
585
634
 
635
+ /** A concurrent revision owns untouched fields; never retry a snapshot-clear over it. */
636
+ private releaseDetachedClear(activeArg: IActiveDraft): void {
637
+ if (activeArg.detachedText) {
638
+ activeArg.desiredText = activeArg.authoritative.text;
639
+ activeArg.dirtyText = false;
640
+ activeArg.detachedText = false;
641
+ }
642
+ if (activeArg.detachedAttachments) {
643
+ activeArg.desiredAttachments = cloneAttachments(activeArg.authoritative.attachments);
644
+ activeArg.dirtyAttachments = false;
645
+ activeArg.detachedAttachments = false;
646
+ }
647
+ }
648
+
586
649
  private schedule(activeArg: IActiveDraft): void {
587
650
  if (!this.isCurrent(activeArg) || activeArg.loading || activeArg.submissionToken) return;
588
651
  if (activeArg.debounceTimer) clearTimeout(activeArg.debounceTimer);
@@ -1,3 +1,5 @@
1
+ import { BrowserSubmissions } from './classes.browsersubmissions.js';
2
+ import { checkedFlexSubmissionReceipt, flexSubmissionFailure, flexSubmissionMessage, type TFlexBrowserSubmission } from './functions.flexsubmissions.js';
1
3
  import { AglFlexCompaction, harnessSessionMetrics } from './elements.flexcompaction.js';
2
4
  import { BrowserDialogPresenter } from './classes.browserdialogpresenter.js';
3
5
  import { BrowserDevToolsClient } from './classes.browserdevtools.js';
@@ -165,6 +167,26 @@ interface IFormDataEventDetail {
165
167
  data?: Record<string, unknown>;
166
168
  }
167
169
 
170
+ interface IFlexBrowserConversationIntent {
171
+ projectId: string;
172
+ draftGeneration: number;
173
+ clientConversationId: string;
174
+ scratchpad: string;
175
+ sessionId?: interfaces.IControllerRuntimeId & { harnessId: 'flex' };
176
+ attaching?: boolean;
177
+ }
178
+
179
+ interface IFlexBrowserComposerResume {
180
+ projectId: string;
181
+ sessionId?: TBrowserSessionId;
182
+ clientConversationId?: string;
183
+ text: string;
184
+ attachments: interfaces.IControllerDraftAttachment[];
185
+ model: string;
186
+ account: string;
187
+ effort: string;
188
+ }
189
+
168
190
  interface ILocalSessionTurnMarker {
169
191
  projectId: string;
170
192
  sessionId: TBrowserSessionId;
@@ -2044,6 +2066,34 @@ export class HarnessControllerApp extends plugins.deesElement.DeesElement {
2044
2066
  ),
2045
2067
  };
2046
2068
  private readonly sessionDraftSync: SessionDraftSync;
2069
+ private readonly flexConversationIntents = new Map<string, IFlexBrowserConversationIntent>();
2070
+ private readonly flexBrowserSubmissions = new BrowserSubmissions<
2071
+ interfaces.IControllerFlexSubmissionInput, interfaces.IControllerFlexSubmissionReceipt
2072
+ >({
2073
+ admit: async (entry) => checkedFlexSubmissionReceipt(await this.socketClient.fire<interfaces.IReq_ControllerFlexSubmissionAdmit>(
2074
+ 'controller.flex.submission.admit', entry.snapshot, { maxRetries: 0 },
2075
+ ), entry.snapshot),
2076
+ lookup: async (entry) => {
2077
+ const answer = await this.socketClient.fire<interfaces.IReq_ControllerFlexSubmissionGet>(
2078
+ 'controller.flex.submission.get',
2079
+ { version: 1, projectId: entry.snapshot.projectId, clientMessageId: entry.id },
2080
+ { maxRetries: 0, timeoutMs: 10_000 },
2081
+ );
2082
+ if (!answer || answer.version !== 1) throw new Error('The controller returned an invalid submission lookup.');
2083
+ return answer.receipt === null ? undefined : checkedFlexSubmissionReceipt(answer.receipt, entry.snapshot);
2084
+ },
2085
+ failure: flexSubmissionFailure,
2086
+ canContinue: (receipt) => receipt.creation === 'pending' || receipt.creation === 'ready',
2087
+ changed: () => {
2088
+ this.canonicalChatProjectionDirty = true;
2089
+ this.requestUpdate();
2090
+ if (this.flexBrowserMessagesModal?.isConnected) this.flexBrowserMessagesModal.content = this.renderFlexBrowserMessages();
2091
+ },
2092
+ admitted: (entry) => this.acceptFlexBrowserSubmission(entry),
2093
+ });
2094
+ private flexBrowserComposerResume?: IFlexBrowserComposerResume;
2095
+ private flexBrowserMessagesModal?: InstanceType<typeof plugins.deesCatalog.DeesModal>;
2096
+ private flexBrowserMessagesOpening = false;
2047
2097
  private componentConnected = false;
2048
2098
  private lifecycleGeneration = 0;
2049
2099
  private connectionGeneration = 0;
@@ -4469,6 +4519,23 @@ export class HarnessControllerApp extends plugins.deesElement.DeesElement {
4469
4519
  }
4470
4520
 
4471
4521
  private invalidateAuthenticatedWorkspace(): void {
4522
+ if (this.authenticated && this.flexBrowserSubmissions.current.length > 0
4523
+ && (this.selectedSessionId?.harnessId ?? this.draftHarnessId) === 'flex') {
4524
+ const sessionId = this.selectedSessionId;
4525
+ const intent = [...this.flexConversationIntents.values()].find((candidate) => candidate.projectId === this.selectedProjectId
4526
+ && candidate.draftGeneration === this.draftSessionGeneration && this.draftSessionActive);
4527
+ const state = sessionId ? this.selectedDraftState(sessionId) : undefined;
4528
+ this.flexBrowserComposerResume = {
4529
+ projectId: this.selectedProjectId, sessionId, clientConversationId: intent?.clientConversationId,
4530
+ text: state?.text ?? this.localDraftText,
4531
+ attachments: structuredClone(state?.attachments ?? this.localDraftAttachments),
4532
+ model: this.resolveSessionModelString(sessionId), account: this.resolveSessionAccount(sessionId),
4533
+ effort: this.resolveSessionEffortString(sessionId),
4534
+ };
4535
+ }
4536
+ this.flexBrowserSubmissions.disconnect();
4537
+ void this.flexBrowserMessagesModal?.destroy();
4538
+ this.flexBrowserMessagesModal = undefined;
4472
4539
  this.cancelComposerFocus();
4473
4540
  this.sessionDraftSync.deactivate();
4474
4541
  void this.closeBrowserView();
@@ -5192,9 +5259,11 @@ export class HarnessControllerApp extends plugins.deesElement.DeesElement {
5192
5259
  * nothing back. It resolves once every read has settled.
5193
5260
  */
5194
5261
  private async loadWorkspaceData(): Promise<void> {
5262
+ void this.flexBrowserSubmissions.reconnect();
5195
5263
  this.scheduleSystemMetricsRefresh(0);
5196
5264
  await Promise.all([
5197
5265
  this.refreshProjects().then(async () => {
5266
+ this.restoreFlexBrowserComposer();
5198
5267
  void this.retryStaleDraftSessionCleanup();
5199
5268
  void this.refreshModelCatalog();
5200
5269
  await this.refreshSessions();
@@ -6194,8 +6263,12 @@ export class HarnessControllerApp extends plugins.deesElement.DeesElement {
6194
6263
  if (
6195
6264
  changedPropertiesArg.has('selectedProjectId')
6196
6265
  || changedPropertiesArg.has('selectedSessionId')
6197
- ) this.forgetAcceptedFirstMessagesOffScreen();
6266
+ ) {
6267
+ this.forgetAcceptedFirstMessagesOffScreen();
6268
+ this.readFlexSubmissionReceiptsOnSelection(changedPropertiesArg);
6269
+ }
6198
6270
  if (changedPropertiesArg.has('sessionDetail')) {
6271
+ this.reconcileFlexBrowserSubmissions();
6199
6272
  this.reloadSlashCatalogOnRunStateChange(
6200
6273
  changedPropertiesArg.get('sessionDetail') as IControllerSessionRenderDetail | undefined,
6201
6274
  );
@@ -6896,6 +6969,7 @@ export class HarnessControllerApp extends plugins.deesElement.DeesElement {
6896
6969
  if (firstMessage && !this.transcriptCarriesFirstMessage(messages, firstMessage)) {
6897
6970
  messages.push(firstMessageHarnessMessage(firstMessage));
6898
6971
  }
6972
+ messages.push(...this.flexSubmissionMessages(projectIdArg, sessionIdArg, detailArg));
6899
6973
  this.mergeLiveReasoningMessages(messages, projectIdArg, sessionIdArg);
6900
6974
  this.mergeLiveTextMessages(messages, projectIdArg, sessionIdArg);
6901
6975
  this.mergeLiveToolMessages(messages, projectIdArg, sessionIdArg);
@@ -8682,6 +8756,7 @@ export class HarnessControllerApp extends plugins.deesElement.DeesElement {
8682
8756
  for (const attention of reconciledDetail.childAttention ?? []) {
8683
8757
  this.applyPendingChildEvent(attention.scopeGeneration, attention.sequence);
8684
8758
  }
8759
+ this.reconcileFlexBrowserSubmissions();
8685
8760
  this.ensureCanonicalChatProjection(reconciledDetail, projectId, sessionIdArg);
8686
8761
  this.reconcileSubtaskStatuses(projectId, sessionIdArg);
8687
8762
  // A draft that materialized keeps its placeholder view until this first
@@ -12185,6 +12260,10 @@ export class HarnessControllerApp extends plugins.deesElement.DeesElement {
12185
12260
  this.requestCurrentComposerFocus();
12186
12261
  return;
12187
12262
  }
12263
+ if (targetHarnessId === 'flex' && slashInput.type === 'ordinary') {
12264
+ this.submitFlexBrowserMessage({ text, attachments: draftAttachments }, delivery ?? 'steer');
12265
+ return;
12266
+ }
12188
12267
  if (this.draftSessionActive && this.selectedSessionId === undefined) {
12189
12268
  if (slashInput.type === 'ordinary') {
12190
12269
  void this.sendFirstMessage({ text, attachments: draftAttachments });
@@ -12217,6 +12296,256 @@ export class HarnessControllerApp extends plugins.deesElement.DeesElement {
12217
12296
  });
12218
12297
  }
12219
12298
 
12299
+ /** Captures before the first await. A message owns its body, files, account and model forever. */
12300
+ private submitFlexBrowserMessage(contentArg: IComposerContent, deliveryArg: interfaces.TControllerPromptDelivery): void {
12301
+ const projectId = this.selectedProjectId;
12302
+ const sessionId = this.selectedSessionId;
12303
+ const model = this.resolveComposerModelChoice(sessionId);
12304
+ const providerConnectionId = this.resolveSessionAccount(sessionId);
12305
+ if (!projectId || model?.harnessId !== 'flex' || !providerConnectionId
12306
+ || !this.authenticated || !this.socketClient.isConnected) return;
12307
+ let conversation: interfaces.TControllerFlexAdmissionConversation;
12308
+ let scope: string;
12309
+ // A provisional new intent remains the address even if its receipt already names a native ID.
12310
+ const intent = [...this.flexConversationIntents.values()].find((candidate) => (
12311
+ candidate.projectId === projectId && candidate.draftGeneration === this.draftSessionGeneration
12312
+ && this.draftSessionActive && (!sessionId || controllerRuntimeIdsEqual(candidate.sessionId, sessionId))
12313
+ ));
12314
+ if (intent || (!sessionId && this.draftSessionActive)) {
12315
+ const current = intent ?? {
12316
+ projectId, draftGeneration: this.draftSessionGeneration, clientConversationId: crypto.randomUUID(),
12317
+ scratchpad: this.currentDraftScratchpad()?.text ?? '',
12318
+ };
12319
+ this.flexConversationIntents.set(current.clientConversationId, current);
12320
+ conversation = { kind: 'new', clientConversationId: current.clientConversationId,
12321
+ scratchpad: current.scratchpad };
12322
+ scope = `${projectId}\u0000intent:${current.clientConversationId}`;
12323
+ } else {
12324
+ if (sessionId?.harnessId !== 'flex') return;
12325
+ const identity = controllerRuntimeIdsEqual(this.sessionDetail?.session.id, sessionId)
12326
+ ? this.sessionDetail?.session.sessionIdentityId : undefined;
12327
+ if (!identity) {
12328
+ this.noteComposer('The exact Flex conversation identity is not loaded. Reload its detail before sending.');
12329
+ return;
12330
+ }
12331
+ conversation = { kind: 'existing', sessionId: { ...sessionId, harnessId: 'flex' }, sessionIdentityId: identity };
12332
+ const nativeIntent = [...this.flexConversationIntents.values()].find((candidate) => candidate.projectId === projectId
12333
+ && controllerRuntimeIdsEqual(candidate.sessionId, sessionId));
12334
+ scope = nativeIntent ? `${projectId}\u0000intent:${nativeIntent.clientConversationId}` : `${projectId}\u0000session:${identity}`;
12335
+ }
12336
+ const clientMessageId = crypto.randomUUID();
12337
+ const capturedRevision = sessionId ? this.sessionDraftSync.submittedSnapshotRevision(contentArg.text, contentArg.attachments) : undefined;
12338
+ this.flexBrowserSubmissions.capture(clientMessageId, scope, {
12339
+ version: 1, projectId, clientMessageId, conversation, text: contentArg.text,
12340
+ attachments: contentArg.attachments, model, providerConnectionId, delivery: deliveryArg,
12341
+ ...(capturedRevision === undefined ? {} : { capturedDraft: { revision: capturedRevision } }),
12342
+ });
12343
+ if (this.draftSessionActive && !sessionId) {
12344
+ if (this.localDraftText === contentArg.text) this.localDraftText = '';
12345
+ // The send event carries the live composer's files; each payload is cloned by capture.
12346
+ if (controllerJsonValuesEqual(this.localDraftAttachments, contentArg.attachments)) this.localDraftAttachments = [];
12347
+ } else {
12348
+ this.sessionDraftSync.clearSubmittedSnapshot(contentArg.text, contentArg.attachments);
12349
+ }
12350
+ this.requestCurrentComposerFocus();
12351
+ }
12352
+
12353
+ private acceptFlexBrowserSubmission(entryArg: TFlexBrowserSubmission): void {
12354
+ const receipt = entryArg.receipt;
12355
+ if (!receipt) return;
12356
+ if (receipt.clientConversationId) {
12357
+ const intent = this.flexConversationIntents.get(receipt.clientConversationId);
12358
+ if (intent) {
12359
+ intent.sessionId = receipt.sessionId;
12360
+ if (receipt.creation === 'ready') void this.attachFlexBrowserConversation(intent);
12361
+ }
12362
+ }
12363
+ this.reconcileFlexBrowserSubmissions();
12364
+ this.scheduleRefresh();
12365
+ }
12366
+
12367
+ /** Keep the mounted draft editable through native creation and its draft/detail reads. */
12368
+ private async attachFlexBrowserConversation(intentArg: IFlexBrowserConversationIntent): Promise<void> {
12369
+ if (intentArg.attaching || !intentArg.sessionId
12370
+ || !this.draftIsCurrent(intentArg.projectId, intentArg.draftGeneration)) return;
12371
+ intentArg.attaching = true;
12372
+ const sessionId = intentArg.sessionId;
12373
+ const generation = this.connectionGeneration;
12374
+ try {
12375
+ // Hydrate off screen first; onState cannot overwrite the still-local next-message draft.
12376
+ await this.sessionDraftSync.activate(intentArg.projectId, sessionId);
12377
+ if (!this.isCurrentConnection(generation) || !this.draftIsCurrent(intentArg.projectId, intentArg.draftGeneration)) return;
12378
+ this.sessionDraftSync.setText(this.localDraftText);
12379
+ this.sessionDraftSync.setAttachments(this.localDraftAttachments);
12380
+ this.adoptDraftComposerChoices(intentArg.projectId, 'flex', sessionId);
12381
+ this.attachDraftConversation(sessionId);
12382
+ void this.refreshSelectedSessionDetail();
12383
+ this.requestCurrentComposerFocus();
12384
+ } catch (errorArg) {
12385
+ this.reportWorkspaceError('Open the admitted Flex conversation', errorArg);
12386
+ } finally {
12387
+ intentArg.attaching = false;
12388
+ }
12389
+ }
12390
+
12391
+ /**
12392
+ * Selecting a project reads its admitted rows, selecting a conversation reads that conversation's;
12393
+ * a selection that names the same project and conversation again reads nothing.
12394
+ */
12395
+ private readFlexSubmissionReceiptsOnSelection(changedPropertiesArg: Map<PropertyKey, unknown>): void {
12396
+ const previousProjectId = changedPropertiesArg.has('selectedProjectId')
12397
+ ? changedPropertiesArg.get('selectedProjectId') as string | undefined
12398
+ : this.selectedProjectId;
12399
+ const previousSessionId = changedPropertiesArg.has('selectedSessionId')
12400
+ ? changedPropertiesArg.get('selectedSessionId') as TBrowserSessionId | undefined
12401
+ : this.selectedSessionId;
12402
+ if (!isNonEmptyString(this.selectedProjectId)) return;
12403
+ if (previousProjectId !== this.selectedProjectId) {
12404
+ this.readFlexSubmissionReceipts(this.selectedProjectId);
12405
+ } else if (!controllerRuntimeIdsEqual(previousSessionId, this.selectedSessionId)) {
12406
+ this.readFlexSubmissionReceipts(this.selectedProjectId, this.selectedSessionId);
12407
+ }
12408
+ }
12409
+
12410
+ private flexSubmissionBelongsTo(entryArg: TFlexBrowserSubmission, projectIdArg: string, sessionIdArg?: TBrowserSessionId): boolean {
12411
+ if (entryArg.snapshot.projectId !== projectIdArg) return false;
12412
+ const target = entryArg.snapshot.conversation;
12413
+ if (sessionIdArg) return controllerRuntimeIdsEqual(entryArg.receipt?.sessionId, sessionIdArg)
12414
+ || (target.kind === 'existing' && controllerRuntimeIdsEqual(target.sessionId, sessionIdArg))
12415
+ || (target.kind === 'new' && controllerRuntimeIdsEqual(this.flexConversationIntents.get(target.clientConversationId)?.sessionId, sessionIdArg));
12416
+ return target.kind === 'new'
12417
+ && this.flexConversationIntents.get(target.clientConversationId)?.draftGeneration === this.draftSessionGeneration;
12418
+ }
12419
+
12420
+ private flexSubmissionCarried(entryArg: TFlexBrowserSubmission, detailArg: IControllerSessionRenderDetail): boolean {
12421
+ const receipt = entryArg.receipt;
12422
+ if (!receipt || !controllerRuntimeIdsEqual(receipt.sessionId, detailArg.session.id)) return false;
12423
+ const exact = (idArg: interfaces.IControllerRuntimeId | undefined): boolean => (
12424
+ idArg?.harnessId === 'flex' && idArg.nativeId === receipt.operationId
12425
+ );
12426
+ return detailArg.pendingPrompts.some((prompt) => exact(prompt.id))
12427
+ || detailArg.messages.some((message) => message.role === 'user' && exact(message.promptId));
12428
+ }
12429
+
12430
+ private reconcileFlexBrowserSubmissions(): void {
12431
+ const detail = this.sessionDetail;
12432
+ if (!detail || detail.session.id.harnessId !== 'flex') return;
12433
+ this.flexBrowserSubmissions.reconcile((entry) => entry.snapshot.projectId === this.selectedProjectId
12434
+ && this.flexSubmissionCarried(entry, detail));
12435
+ }
12436
+
12437
+ private flexSubmissionMessages(projectIdArg: string, sessionIdArg?: TBrowserSessionId, detailArg?: IControllerSessionRenderDetail): plugins.deesCatalog.IHarnessMessage[] {
12438
+ return this.flexBrowserSubmissions.current
12439
+ .filter((entry) => this.flexSubmissionBelongsTo(entry, projectIdArg, sessionIdArg)
12440
+ && (!detailArg || !this.flexSubmissionCarried(entry, detailArg)))
12441
+ .map(flexSubmissionMessage);
12442
+ }
12443
+
12444
+ private renderFlexSubmissionChecks(): plugins.deesElement.TemplateResult | '' {
12445
+ const entries = this.flexBrowserSubmissions.current.filter((entry) => entry.snapshot.projectId === this.selectedProjectId
12446
+ && (entry.state === 'unknown' || entry.receipt?.creation === 'uncertain' || entry.receipt?.state === 'settled'));
12447
+ if (entries.length === 0) return '';
12448
+ return plugins.deesElement.html`<div class="composerNotice notice" role="status">
12449
+ <span>Admission or creation is unconfirmed. Checking never resends a message.</span>
12450
+ <dees-button @clicked=${() => { void Promise.all(entries.map((entry) => this.flexBrowserSubmissions.check(entry.id))).then(() => this.refreshSelectedSessionDetail()); }}>Check receipts</dees-button>
12451
+ </div>`;
12452
+ }
12453
+
12454
+ /** Local failures and orphaned provisional intents stay inspectable after navigation/reconnect. */
12455
+ private renderFlexBrowserMessages(): plugins.deesElement.TemplateResult {
12456
+ return plugins.deesElement.html`<div>
12457
+ <p>Captured in this page only. Unconfirmed messages are never resent automatically. Keep this page open until their outcomes are known.</p>
12458
+ ${this.flexBrowserSubmissions.current.map((entry) => plugins.deesElement.html`<section>
12459
+ <p>${this.projects.find((project) => project.id === entry.snapshot.projectId)?.name ?? entry.snapshot.projectId}
12460
+ · ${entry.id}</p>
12461
+ <dees-harness-message .message=${flexSubmissionMessage(entry)}></dees-harness-message>
12462
+ ${entry.state === 'unknown' || entry.state === 'admitted' ? plugins.deesElement.html`
12463
+ <dees-button type="ghost" size="sm" .text=${'Check receipt'}
12464
+ @clicked=${() => void this.flexBrowserSubmissions.check(entry.id)}></dees-button>` : ''}
12465
+ </section>`)}
12466
+ </div>`;
12467
+ }
12468
+
12469
+ private async openFlexBrowserMessages(): Promise<void> {
12470
+ if (this.flexBrowserMessagesOpening || this.flexBrowserMessagesModal?.isConnected) return;
12471
+ this.flexBrowserMessagesOpening = true;
12472
+ const generation = this.connectionGeneration;
12473
+ try {
12474
+ const modal = await plugins.deesCatalog.DeesModal.createAndShow({
12475
+ heading: 'Browser messages', subheading: 'Immutable messages awaiting an exact durable or native owner.',
12476
+ width: 'large', content: this.renderFlexBrowserMessages(),
12477
+ menuOptions: [{ name: 'Close', action: async (modalArg) => { await modalArg?.destroy(); } }],
12478
+ });
12479
+ if (!modal) return;
12480
+ if (!this.componentConnected || !this.isCurrentConnection(generation)) { await modal.destroy(); return; }
12481
+ this.flexBrowserMessagesModal = modal;
12482
+ modal.content = this.renderFlexBrowserMessages();
12483
+ } catch (errorArg) {
12484
+ this.reportWorkspaceError('Review browser messages', errorArg);
12485
+ } finally {
12486
+ this.flexBrowserMessagesOpening = false;
12487
+ }
12488
+ }
12489
+
12490
+ /** Reconnection restores this page's next draft and the same intent, never an attempted send. */
12491
+ private restoreFlexBrowserComposer(): void {
12492
+ const resume = this.flexBrowserComposerResume;
12493
+ if (!resume || !this.projects.some((project) => project.id === resume.projectId)) return;
12494
+ this.flexBrowserComposerResume = undefined;
12495
+ this.selectedProjectId = resume.projectId;
12496
+ const intent = resume.clientConversationId ? this.flexConversationIntents.get(resume.clientConversationId) : undefined;
12497
+ if (intent) {
12498
+ intent.draftGeneration = this.draftSessionGeneration;
12499
+ this.draftSessionActive = true;
12500
+ this.draftHarnessId = 'flex';
12501
+ this.selectedSessionId = undefined;
12502
+ this.localDraftText = resume.text;
12503
+ this.localDraftAttachments = resume.attachments;
12504
+ } else if (resume.sessionId) {
12505
+ this.selectedSessionId = resume.sessionId;
12506
+ const generation = this.connectionGeneration;
12507
+ void this.sessionDraftSync.activate(resume.projectId, resume.sessionId).then(() => {
12508
+ if (!this.isCurrentConnection(generation) || !this.isSelectedConversation(resume.projectId, resume.sessionId!)) return;
12509
+ this.sessionDraftSync.setText(resume.text);
12510
+ this.sessionDraftSync.setAttachments(resume.attachments);
12511
+ }).catch((errorArg) => this.reportWorkspaceError('Restore the next Flex draft', errorArg));
12512
+ }
12513
+ const key = intent ? draftSessionKey('flex') : resume.sessionId ? this.sessionOperationKey(resume.projectId, resume.sessionId) : undefined;
12514
+ if (key) {
12515
+ if (resume.model) this.sessionModelOverrides.set(key, resume.model);
12516
+ if (resume.account) this.sessionAccountOverrides.set(key, resume.account);
12517
+ this.sessionEffortOverrides.set(key, resume.effort);
12518
+ }
12519
+ void this.flexBrowserSubmissions.reconnect();
12520
+ }
12521
+
12522
+ /**
12523
+ * Reads the receipts of the admitted rows of a project, or of one of its conversations. It runs
12524
+ * on events only, never on a timer: a push of the controller for that conversation (it follows
12525
+ * every change of what a receipt reports: hand-over, hold, release, creation), a selection of the
12526
+ * project or conversation, a reconnection (`BrowserSubmissions.reconnect`) and Check receipts.
12527
+ * Reads only: neither a missing receipt nor a read failure authorizes another admission.
12528
+ */
12529
+ private readFlexSubmissionReceipts(projectIdArg: string, sessionIdArg?: IControllerBrowserRuntimeId): void {
12530
+ if (!this.componentConnected || !this.authenticated || !this.socketClient.isConnected) return;
12531
+ for (const entry of this.flexBrowserSubmissions.current) {
12532
+ if (entry.state !== 'admitted' || entry.snapshot.projectId !== projectIdArg
12533
+ || (sessionIdArg !== undefined && !controllerRuntimeIdsEqual(entry.receipt?.sessionId, sessionIdArg))) continue;
12534
+ void this.flexBrowserSubmissions.check(entry.id);
12535
+ }
12536
+ }
12537
+
12538
+ /** A Flex conversation or conversation-list push of the controller reads that conversation's rows. */
12539
+ private readFlexSubmissionReceiptsAfterPush(eventArg: interfaces.IControllerEvent): void {
12540
+ if (eventArg.type !== 'session.changed' && eventArg.type !== 'sessions.changed'
12541
+ && eventArg.type !== 'session.history.changed') return;
12542
+ const sessionId = isSessionRuntimeId(eventArg.sessionId) ? eventArg.sessionId : undefined;
12543
+ const harnessId = sessionId?.harnessId ?? eventArg.harnessId;
12544
+ if (harnessId !== undefined && harnessId !== 'flex') return;
12545
+ const projectId = eventArg.projectId ?? this.selectedProjectId;
12546
+ if (isNonEmptyString(projectId)) this.readFlexSubmissionReceipts(projectId, sessionId);
12547
+ }
12548
+
12220
12549
  private async submitCodexSteer(
12221
12550
  chatArg: plugins.deesCatalog.DeesHarnessChat,
12222
12551
  textArg: string,
@@ -17011,6 +17340,7 @@ ${entry.detail.stack}`}</pre>`}
17011
17340
  if (!this.authenticated) {
17012
17341
  return;
17013
17342
  }
17343
+ this.readFlexSubmissionReceiptsAfterPush(eventArg);
17014
17344
  if (eventArg.type === 'driver.changed' && eventArg.driverStatus) {
17015
17345
  this.applyDriverStatus(eventArg.driverStatus);
17016
17346
  return;
@@ -20129,6 +20459,10 @@ ${entry.detail.stack}`}</pre>`}
20129
20459
  </dees-button>
20130
20460
  </div>
20131
20461
  ${this.renderSidebarNotice()}
20462
+ ${this.flexBrowserSubmissions.current.length > 0 ? plugins.deesElement.html`
20463
+ <dees-button class="flexBrowserMessagesButton" type="ghost" size="sm"
20464
+ .text=${`Browser messages (${this.flexBrowserSubmissions.current.length})`}
20465
+ @clicked=${() => void this.openFlexBrowserMessages()}></dees-button>` : ''}
20132
20466
  ${this.renderBlockedRemovals()}
20133
20467
  <dees-harness-session-list
20134
20468
  class="conversationList"
@@ -21863,7 +22197,7 @@ ${entry.detail.stack}`}</pre>`}
21863
22197
  historyNotice: '',
21864
22198
  messages: this.stableRenderValue(
21865
22199
  'draft.messages',
21866
- firstMessage ? [firstMessageHarnessMessage(firstMessage)] : [],
22200
+ firstMessage ? [firstMessageHarnessMessage(firstMessage)] : this.flexSubmissionMessages(this.selectedProjectId),
21867
22201
  ),
21868
22202
  history: emptyHarnessHistory,
21869
22203
  hasEarlierHistory: false,
@@ -21919,7 +22253,7 @@ ${entry.detail.stack}`}</pre>`}
21919
22253
  subheading: directory
21920
22254
  ? `${harnessLabel} creates this session on first send · starts in ${directory}`
21921
22255
  : `${harnessLabel} creates this session on first send`,
21922
- strips: [this.draftHarnessId === 'codex' ? this.renderCodexConnectionStrip() : ''],
22256
+ strips: [this.draftHarnessId === 'codex' ? this.renderCodexConnectionStrip() : '', this.renderFlexSubmissionChecks()],
21923
22257
  });
21924
22258
  }
21925
22259
 
@@ -22264,9 +22598,9 @@ ${entry.detail.stack}`}</pre>`}
22264
22598
  : codexExternalWriter
22265
22599
  ? 'This Codex turn cannot be stopped from AGL.'
22266
22600
  : 'This Codex turn is no longer interruptible.',
22267
- disabled: this.detailLoading
22601
+ disabled: (this.detailLoading && sessionId.harnessId !== 'flex')
22268
22602
  || (this.composerMutationPending() && !this.codexSteerPending)
22269
- || this.sessionModelPending
22603
+ || (this.sessionModelPending && sessionId.harnessId !== 'flex')
22270
22604
  || draftState?.loading === true
22271
22605
  || readOnly,
22272
22606
  composerValue: this.selectedComposerText(),
@@ -22299,6 +22633,7 @@ ${entry.detail.stack}`}</pre>`}
22299
22633
  sessionId.harnessId === 'codex' ? this.renderCodexActivity(detailArg) : '',
22300
22634
  sessionId.harnessId === 'codex' ? this.renderCodexUsageLimitNotice(detailArg) : '',
22301
22635
  sessionId.harnessId === 'flex' ? this.renderFlexLimitStrip(detailArg, sessionId) : '',
22636
+ this.renderFlexSubmissionChecks(),
22302
22637
  ],
22303
22638
  });
22304
22639
  }