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
@@ -1,3 +1,5 @@
1
+ import { ControllerFlexSubmissionStore, FlexSubmissionError } from './classes.flexsubmissionstore.js';
2
+ import { ControllerFlexSubmissionModel, ControllerFlexAdmissionConversationModel } from './classes.flexsubmissionmodels.js';
1
3
  import { FleetWorkerModel } from './fleet/classes.workerstore.js';
2
4
  import { DriverModel } from './driver/classes.driverstore.js';
3
5
  import { DirectReportModel } from './driver/classes.directreportstore.js';
@@ -646,6 +648,14 @@ const trimSessionStateExchanges = (
646
648
  const projectManagementStoreKey = (projectIdArg: string, sessionIdArg: string): string =>
647
649
  JSON.stringify([projectIdArg, sessionIdArg]);
648
650
 
651
+ /** Whether a session state holds any field `clearControllerSessionFields` clears. */
652
+ const holdsControllerSessionFields = (documentArg: IControllerSessionStateDocument): boolean => (
653
+ documentArg.intelligenceExchanges.length > 0
654
+ || documentArg.modelChoice !== undefined
655
+ || documentArg.providerConnectionId !== undefined
656
+ || documentArg.flexLimitResume !== undefined
657
+ );
658
+
649
659
  const cloneProjectManagementRecord = <TRecord extends TFlexProjectManagementRecord>(
650
660
  recordArg: TRecord,
651
661
  ): TRecord => structuredClone(recordArg);
@@ -808,6 +818,8 @@ const setAuthStoreModelManager = (
808
818
  plugins.nosqldb.setDefaultManagerForDoc(managerArg, ControllerSessionGroupsModel);
809
819
  plugins.nosqldb.setDefaultManagerForDoc(managerArg, ControllerSessionStateModel);
810
820
  plugins.nosqldb.setDefaultManagerForDoc(managerArg, ControllerPendingPromptModel);
821
+ plugins.nosqldb.setDefaultManagerForDoc(managerArg, ControllerFlexSubmissionModel);
822
+ plugins.nosqldb.setDefaultManagerForDoc(managerArg, ControllerFlexAdmissionConversationModel);
811
823
  plugins.nosqldb.setDefaultManagerForDoc(managerArg, ControllerCodexTurnModel);
812
824
  plugins.nosqldb.setDefaultManagerForDoc(managerArg, FlexTranscriptGrantModel);
813
825
  plugins.nosqldb.setDefaultManagerForDoc(managerArg, ControllerTrackedConversationModel);
@@ -877,6 +889,7 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
877
889
  private codexConnectionStore?: ControllerCodexConnectionStore;
878
890
  private claudeSessionStore?: ControllerClaudeSessionStore;
879
891
  private pendingPromptStore?: ControllerPendingPromptStore;
892
+ private flexSubmissionStore?: ControllerFlexSubmissionStore;
880
893
  private codexTurnStore?: ControllerCodexTurnStore;
881
894
  private readonly modelOwner = {};
882
895
  private releaseModelOwnership?: () => void;
@@ -1104,6 +1117,21 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
1104
1117
  await ControllerSessionGroupsModel.init();
1105
1118
  await ControllerSessionStateModel.init();
1106
1119
  await ControllerPendingPromptModel.init();
1120
+ await ControllerFlexSubmissionModel.init();
1121
+ await ControllerFlexAdmissionConversationModel.init();
1122
+ // A Flex admission commits these in one transaction, which takes only prepared collections.
1123
+ if (this.issuerIdentity) {
1124
+ for (const model of [
1125
+ ControllerProjectModel,
1126
+ ControllerSessionLocatorModel,
1127
+ ControllerManagedSessionModel,
1128
+ ControllerSessionCreationObligationModel,
1129
+ ControllerSessionStateModel,
1130
+ ControllerPendingPromptModel,
1131
+ ControllerFlexSubmissionModel,
1132
+ ControllerFlexAdmissionConversationModel,
1133
+ ] as const) await model.exact.prepare();
1134
+ }
1107
1135
  await ControllerCodexTurnModel.init();
1108
1136
  await FlexTranscriptGrantModel.init();
1109
1137
  await ControllerTrackedConversationModel.init();
@@ -1325,6 +1353,7 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
1325
1353
  this.issuerIdentity = undefined;
1326
1354
  this.initializedDataRoot = undefined;
1327
1355
  this.sessionIdentityService = undefined;
1356
+ this.flexSubmissionStore = undefined;
1328
1357
  this.releaseModelOwnership = undefined;
1329
1358
  } finally {
1330
1359
  if (this.closePromise === closePromise) this.closePromise = undefined;
@@ -2098,6 +2127,27 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
2098
2127
  }
2099
2128
 
2100
2129
  /** The messages this controller's conversations have not taken in; needs the resolved controller. */
2130
+ public requireFlexSubmissions(): ControllerFlexSubmissionStore {
2131
+ this.assertInitialized();
2132
+ if (!this.sessionIdentityService || !this.issuerIdentity) throw new Error('The session identity authority is not open.');
2133
+ this.flexSubmissionStore ??= new ControllerFlexSubmissionStore(this.requireControllerId(), this.issuerIdentity.issuerId, this.db, this.sessionIdentityService, this.requirePendingPrompts());
2134
+ return this.flexSubmissionStore;
2135
+ }
2136
+
2137
+ /**
2138
+ * Same lifecycle writer as managed identity: retirement cannot overtake a durable admission. A
2139
+ * project that is not registered, or whose removal started, is `project_not_found`.
2140
+ */
2141
+ public withFlexSubmissionAdmission<TResult>(projectIdArg: string, operationArg: (storeArg: ControllerFlexSubmissionStore) => Promise<TResult>): Promise<TResult> {
2142
+ this.assertInitialized();
2143
+ return this.withProjectMutation(async () => {
2144
+ if (!await this.getProject(projectIdArg)) {
2145
+ throw new FlexSubmissionError('project_not_found', 'The requested project is not registered.');
2146
+ }
2147
+ return operationArg(this.requireFlexSubmissions());
2148
+ });
2149
+ }
2150
+
2101
2151
  public requirePendingPrompts(): ControllerPendingPromptStore {
2102
2152
  if (!this.initialized || this.closeStarted) throw new Error('Pending message persistence is unavailable.');
2103
2153
  this.pendingPromptStore ??= new ControllerPendingPromptStore(this.requireControllerId(), this.db);
@@ -3014,7 +3064,20 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
3014
3064
  ));
3015
3065
  }
3016
3066
 
3017
- /** A caller whose `signalArg` aborts while it waits for its turn withdraws its operation. */
3067
+ /**
3068
+ * Whether this store reached an embedded engine another process owns (a CLI command or the
3069
+ * upgrade worker beside a running controller). Such a store never takes the project mutation lane.
3070
+ */
3071
+ public get attachedToForeignEngine(): boolean {
3072
+ return this.embeddedDatabase !== undefined && !this.embeddedDatabase.ownsEngine;
3073
+ }
3074
+
3075
+ /**
3076
+ * The single writer lane: projects, session locators and managed sessions are written only here,
3077
+ * and only by the controller process that owns the embedded engine. A store attached to another
3078
+ * process's engine is refused before anything is read or written. A caller whose `signalArg`
3079
+ * aborts while it waits for its turn withdraws its operation.
3080
+ */
3018
3081
  private withProjectMutation<T>(
3019
3082
  operationArg: () => Promise<T>,
3020
3083
  signalArg?: AbortSignal,
@@ -3025,6 +3088,12 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
3025
3088
  'Project mutations are unavailable while the authentication store is closing.',
3026
3089
  ));
3027
3090
  }
3091
+ if (this.attachedToForeignEngine) {
3092
+ return Promise.reject(new AuthError(
3093
+ 'not_database_owner',
3094
+ 'Projects, session locators and managed sessions are written only by the controller process that owns the database engine.',
3095
+ ));
3096
+ }
3028
3097
  const { result, settled } = queueAbortableOperation(this.projectMutationTail, async () => {
3029
3098
  if (!this.projectMutationAdmissionOpen) {
3030
3099
  throw new AuthError(
@@ -4565,7 +4634,7 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
4565
4634
  randomAuthorityValue(),
4566
4635
  );
4567
4636
  candidate.flexProjectManagement = tombstone;
4568
- this.applySessionStateTombstone(candidate, deletedAt);
4637
+ this.endSessionStateLifecycle(candidate, deletedAt);
4569
4638
  try {
4570
4639
  await this.insertSessionState(candidate);
4571
4640
  return;
@@ -4613,7 +4682,7 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
4613
4682
  }
4614
4683
  await this.transitionSessionState(stored, (document) => {
4615
4684
  document.flexProjectManagement = tombstone;
4616
- this.applySessionStateTombstone(document, deletedAt);
4685
+ this.endSessionStateLifecycle(document, deletedAt);
4617
4686
  });
4618
4687
  });
4619
4688
  }
@@ -5260,6 +5329,65 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
5260
5329
  )));
5261
5330
  }
5262
5331
 
5332
+ /**
5333
+ * The generation of the session's live Flex project-management record, or undefined when the
5334
+ * state holds none or only a tombstone.
5335
+ */
5336
+ public async liveFlexProjectManagementGeneration(
5337
+ projectIdArg: string,
5338
+ sessionIdArg: IControllerRuntimeId,
5339
+ ): Promise<TFlexSessionGeneration | undefined> {
5340
+ const stored = await this.findStoredSessionState(projectIdArg, sessionIdArg);
5341
+ const record = stored
5342
+ ? ControllerSessionStateModel.exact.toPersisted(stored).flexProjectManagement
5343
+ : undefined;
5344
+ if (!record || Object.hasOwn(record, 'deletedAt')) return undefined;
5345
+ return {
5346
+ sessionGenerationId: record.sessionGenerationId,
5347
+ sessionGenerationSequence: record.sessionGenerationSequence,
5348
+ };
5349
+ }
5350
+
5351
+ /**
5352
+ * Ends a Flex session's state after FlexHarness answered its generation-fenced deletion `absent`
5353
+ * (no live session and no retained cleanup tombstone of any generation holds the id), in one
5354
+ * session-state mutation that reads the latest document: a missing document is written deleted,
5355
+ * a deleted one stays as it is, a live one without a project-management record or with a live
5356
+ * record of `generationArg` (an orphan FlexHarness no longer knows, logged as a warning) ends.
5357
+ * A live record of any other generation means a newer session took the id meanwhile: nothing is
5358
+ * written and its generation is returned.
5359
+ */
5360
+ public settleAbsentFlexSessionState(
5361
+ projectIdArg: string,
5362
+ sessionIdArg: IControllerRuntimeId,
5363
+ generationArg: Readonly<TFlexSessionGeneration>,
5364
+ ): Promise<{ outcome: 'ended' } | { outcome: 'other-generation'; generation: TFlexSessionGeneration }> {
5365
+ return this.runSessionStateMutation(async () => {
5366
+ const stored = await this.findStoredSessionState(projectIdArg, sessionIdArg);
5367
+ const record = stored
5368
+ ? ControllerSessionStateModel.exact.toPersisted(stored).flexProjectManagement
5369
+ : undefined;
5370
+ if (record && !Object.hasOwn(record, 'deletedAt')) {
5371
+ if (
5372
+ record.sessionGenerationId !== generationArg.sessionGenerationId
5373
+ || record.sessionGenerationSequence !== generationArg.sessionGenerationSequence
5374
+ ) {
5375
+ return {
5376
+ outcome: 'other-generation' as const,
5377
+ generation: {
5378
+ sessionGenerationId: record.sessionGenerationId,
5379
+ sessionGenerationSequence: record.sessionGenerationSequence,
5380
+ },
5381
+ };
5382
+ }
5383
+ console.warn(`FlexHarness no longer knows session ${JSON.stringify(sessionIdArg.nativeId)} of project ${
5384
+ JSON.stringify(projectIdArg)}, whose live project-management record of the deleted generation remained; it is ended with that generation.`);
5385
+ }
5386
+ await this.tombstoneSessionStateUnqueued(projectIdArg, sessionIdArg);
5387
+ return { outcome: 'ended' as const };
5388
+ });
5389
+ }
5390
+
5263
5391
  public async isSessionStateTombstoned(
5264
5392
  projectIdArg: string,
5265
5393
  sessionIdArg: IControllerRuntimeId,
@@ -5269,10 +5397,19 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
5269
5397
  return ControllerSessionStateModel.exact.toPersisted(stored).deletedAt !== undefined;
5270
5398
  }
5271
5399
 
5400
+ /**
5401
+ * Retires every live session state of a project being removed. `full` follows FlexHarness's
5402
+ * project removal, which ended every Flex session's project-management record it knew: a record
5403
+ * still live then is ended here with its own generation and reported. `metadata-only` removes a
5404
+ * project whose directory is not trusted, without FlexHarness: a document whose Flex
5405
+ * project-management record is live stays FlexHarness's to end, so only AGL's own fields are
5406
+ * cleared (and nothing is written when none is held); every other document ends as in `full`.
5407
+ */
5272
5408
  public async retireProjectSessionStates(
5273
5409
  projectIdArg: string,
5274
5410
  cleanupTemporarySessionArg: (temporarySessionIdArg: string) => Promise<void>,
5275
5411
  signalArg?: AbortSignal,
5412
+ modeArg: 'full' | 'metadata-only' = 'full',
5276
5413
  ): Promise<{
5277
5414
  retiredCount: number;
5278
5415
  temporarySessionIds: string[];
@@ -5315,9 +5452,26 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
5315
5452
  signalArg?.throwIfAborted();
5316
5453
  const retired = await this.runSessionStateMutation(async () => {
5317
5454
  const latest = await this.findStoredSessionState(projectIdArg, current.sessionId);
5318
- if (!latest || ControllerSessionStateModel.exact.toPersisted(latest).deletedAt) return false;
5455
+ if (!latest) return false;
5456
+ const persisted = ControllerSessionStateModel.exact.toPersisted(latest);
5457
+ if (persisted.deletedAt) return false;
5458
+ const projectManagement = persisted.flexProjectManagement;
5459
+ const liveProjectManagement = projectManagement !== undefined
5460
+ && !Object.hasOwn(projectManagement, 'deletedAt');
5461
+ if (liveProjectManagement && modeArg === 'metadata-only') {
5462
+ if (!holdsControllerSessionFields(persisted)) return false;
5463
+ await this.transitionSessionState(latest, (document) => {
5464
+ this.clearControllerSessionFields(document);
5465
+ });
5466
+ return false;
5467
+ }
5468
+ if (liveProjectManagement) {
5469
+ console.warn(`Project removal left the live Flex project-management record of session ${JSON.stringify(
5470
+ persisted.sessionId.nativeId,
5471
+ )} in project ${JSON.stringify(projectIdArg)}; it is ended with its own generation.`);
5472
+ }
5319
5473
  await this.transitionSessionState(latest, (document) => {
5320
- this.applySessionStateTombstone(document, new Date());
5474
+ this.endSessionStateLifecycle(document, new Date());
5321
5475
  });
5322
5476
  return true;
5323
5477
  });
@@ -5396,7 +5550,7 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
5396
5550
  const current = ControllerSessionStateModel.exact.toPersisted(stored);
5397
5551
  if (current.deletedAt) return;
5398
5552
  await this.transitionSessionState(stored, (document) => {
5399
- this.applySessionStateTombstone(document, deletedAt);
5553
+ this.endSessionStateLifecycle(document, deletedAt);
5400
5554
  });
5401
5555
  }
5402
5556
 
@@ -5415,7 +5569,24 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
5415
5569
  documentArg.flexProjectManagement = snapshot;
5416
5570
  }
5417
5571
 
5418
- private applySessionStateTombstone(
5572
+ /**
5573
+ * Clears the fields of a session's state that AGL owns: its Session Intelligence exchanges, its
5574
+ * model and account choice and its limit-resume plan. The Flex project-management record, its
5575
+ * scratchpad mirror and the document's end are not among them.
5576
+ */
5577
+ private clearControllerSessionFields(documentArg: IControllerSessionStateDocument): void {
5578
+ documentArg.intelligenceExchanges = [];
5579
+ delete documentArg.modelChoice;
5580
+ delete documentArg.providerConnectionId;
5581
+ delete documentArg.flexLimitResume;
5582
+ }
5583
+
5584
+ /**
5585
+ * Ends a session state's life: a live Flex project-management record becomes a tombstone of its
5586
+ * own generation at its next revision with the document's deletion time (the invariant 41.1.0
5587
+ * asserts), the scratchpad is emptied and AGL's own fields are cleared.
5588
+ */
5589
+ private endSessionStateLifecycle(
5419
5590
  documentArg: IControllerSessionStateDocument,
5420
5591
  deletedAtArg: Date,
5421
5592
  ): void {
@@ -5441,10 +5612,7 @@ export class SmartDataAuthStore implements IAuthStore, IAuthStoreSessionIdentity
5441
5612
  ? {}
5442
5613
  : { updatedBy: documentArg.scratchpad.updatedBy }),
5443
5614
  };
5444
- documentArg.intelligenceExchanges = [];
5445
- delete documentArg.modelChoice;
5446
- delete documentArg.providerConnectionId;
5447
- delete documentArg.flexLimitResume;
5615
+ this.clearControllerSessionFields(documentArg);
5448
5616
  documentArg.deletedAt = deletedAtArg;
5449
5617
  }
5450
5618