@genesislcap/ai-assistant 15.43.0 → 15.45.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 (56) hide show
  1. package/dist/ai-assistant.api.json +34 -19
  2. package/dist/ai-assistant.d.ts +36 -2
  3. package/dist/chat-driver.cjs +89 -10
  4. package/dist/chat-driver.cjs.map +2 -2
  5. package/dist/chat-driver.mjs +89 -10
  6. package/dist/chat-driver.mjs.map +2 -2
  7. package/dist/custom-elements.json +466 -285
  8. package/dist/dts/components/chat-driver/chat-driver.d.ts +15 -2
  9. package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
  10. package/dist/dts/components/chat-driver/interaction-controller.d.ts +26 -3
  11. package/dist/dts/components/chat-driver/interaction-controller.d.ts.map +1 -1
  12. package/dist/dts/components/chat-interaction-wrapper/chat-interaction-wrapper.d.ts +6 -0
  13. package/dist/dts/components/chat-interaction-wrapper/chat-interaction-wrapper.d.ts.map +1 -1
  14. package/dist/dts/genesis/config.d.ts +28 -1
  15. package/dist/dts/genesis/config.d.ts.map +1 -1
  16. package/dist/dts/genesis/consumes.d.ts.map +1 -1
  17. package/dist/dts/genesis/index.d.ts +2 -1
  18. package/dist/dts/genesis/index.d.ts.map +1 -1
  19. package/dist/dts/genesis/register-genesis-assistant.d.ts.map +1 -1
  20. package/dist/dts/genesis/review-model.d.ts +72 -1
  21. package/dist/dts/genesis/review-model.d.ts.map +1 -1
  22. package/dist/dts/genesis/types.d.ts +32 -0
  23. package/dist/dts/genesis/types.d.ts.map +1 -1
  24. package/dist/dts/genesis/write-review/write-review.d.ts +22 -1
  25. package/dist/dts/genesis/write-review/write-review.d.ts.map +1 -1
  26. package/dist/dts/genesis/write-review/write-review.styles.d.ts.map +1 -1
  27. package/dist/dts/genesis/write-review/write-review.template.d.ts.map +1 -1
  28. package/dist/dts/genesis/write-tools.d.ts +6 -1
  29. package/dist/dts/genesis/write-tools.d.ts.map +1 -1
  30. package/dist/dts/main/main.template.d.ts +8 -0
  31. package/dist/dts/main/main.template.d.ts.map +1 -1
  32. package/dist/dts/state/debug-event-log.d.ts +1 -1
  33. package/dist/dts/state/debug-event-log.d.ts.map +1 -1
  34. package/dist/dts/types/ai-chat-widget.d.ts +7 -0
  35. package/dist/dts/types/ai-chat-widget.d.ts.map +1 -1
  36. package/dist/esm/components/chat-driver/chat-driver.js +39 -6
  37. package/dist/esm/components/chat-driver/interaction-controller.js +50 -4
  38. package/dist/esm/components/chat-interaction-wrapper/chat-interaction-wrapper.js +17 -6
  39. package/dist/esm/genesis/config.js +108 -7
  40. package/dist/esm/genesis/consumes.js +8 -1
  41. package/dist/esm/genesis/index.js +1 -0
  42. package/dist/esm/genesis/register-genesis-assistant.js +7 -0
  43. package/dist/esm/genesis/review-model.js +115 -7
  44. package/dist/esm/genesis/write-review/write-review.js +80 -19
  45. package/dist/esm/genesis/write-review/write-review.styles.js +5 -2
  46. package/dist/esm/genesis/write-review/write-review.template.js +19 -2
  47. package/dist/esm/genesis/write-tools.js +49 -13
  48. package/dist/esm/main/main.template.js +19 -10
  49. package/dist/esm/state/debug-event-log.js +4 -0
  50. package/dist/genesis-consumes.cjs +8 -1
  51. package/dist/genesis-consumes.cjs.map +2 -2
  52. package/dist/genesis-consumes.mjs +8 -1
  53. package/dist/genesis-consumes.mjs.map +2 -2
  54. package/docs/genesis.md +60 -2
  55. package/package.json +18 -18
  56. package/scripts/smoke-genesis-consumes-node.mjs +1 -1
@@ -2728,7 +2728,7 @@
2728
2728
  },
2729
2729
  {
2730
2730
  "kind": "Content",
2731
- "text": "<TResult>;\n}"
2731
+ "text": "<TResult>;\n outcome?: unknown;\n}"
2732
2732
  },
2733
2733
  {
2734
2734
  "kind": "Content",
@@ -6939,6 +6939,14 @@
6939
6939
  "text": "InteractionRequestOptions",
6940
6940
  "canonicalReference": "@genesislcap/foundation-ai!InteractionRequestOptions:interface"
6941
6941
  },
6942
+ {
6943
+ "kind": "Content",
6944
+ "text": ", onOpened?: "
6945
+ },
6946
+ {
6947
+ "kind": "Content",
6948
+ "text": "(interactionId: string) => void"
6949
+ },
6942
6950
  {
6943
6951
  "kind": "Content",
6944
6952
  "text": "): "
@@ -6972,8 +6980,8 @@
6972
6980
  ],
6973
6981
  "isStatic": false,
6974
6982
  "returnTypeTokenRange": {
6975
- "startIndex": 7,
6976
- "endIndex": 9
6983
+ "startIndex": 9,
6984
+ "endIndex": 11
6977
6985
  },
6978
6986
  "releaseTag": "Public",
6979
6987
  "isProtected": false,
@@ -7002,6 +7010,14 @@
7002
7010
  "endIndex": 6
7003
7011
  },
7004
7012
  "isOptional": true
7013
+ },
7014
+ {
7015
+ "parameterName": "onOpened",
7016
+ "parameterTypeTokenRange": {
7017
+ "startIndex": 7,
7018
+ "endIndex": 8
7019
+ },
7020
+ "isOptional": true
7005
7021
  }
7006
7022
  ],
7007
7023
  "isOptional": false,
@@ -7309,27 +7325,18 @@
7309
7325
  "kind": "Content",
7310
7326
  "text": "setHostInteractionRequester(fn: "
7311
7327
  },
7312
- {
7313
- "kind": "Content",
7314
- "text": "<T>(componentName: string, data: any, options?: "
7315
- },
7316
7328
  {
7317
7329
  "kind": "Reference",
7318
- "text": "InteractionRequestOptions",
7319
- "canonicalReference": "@genesislcap/foundation-ai!InteractionRequestOptions:interface"
7330
+ "text": "InteractionRequester",
7331
+ "canonicalReference": "@genesislcap/ai-assistant!~InteractionRequester:type"
7320
7332
  },
7321
7333
  {
7322
7334
  "kind": "Content",
7323
- "text": ") => "
7324
- },
7325
- {
7326
- "kind": "Reference",
7327
- "text": "Promise",
7328
- "canonicalReference": "!Promise:interface"
7335
+ "text": ", recordOutcome?: "
7329
7336
  },
7330
7337
  {
7331
7338
  "kind": "Content",
7332
- "text": "<T>"
7339
+ "text": "(interactionId: string, outcome: unknown) => boolean"
7333
7340
  },
7334
7341
  {
7335
7342
  "kind": "Content",
@@ -7346,8 +7353,8 @@
7346
7353
  ],
7347
7354
  "isStatic": false,
7348
7355
  "returnTypeTokenRange": {
7349
- "startIndex": 7,
7350
- "endIndex": 8
7356
+ "startIndex": 5,
7357
+ "endIndex": 6
7351
7358
  },
7352
7359
  "releaseTag": "Public",
7353
7360
  "isProtected": false,
@@ -7357,9 +7364,17 @@
7357
7364
  "parameterName": "fn",
7358
7365
  "parameterTypeTokenRange": {
7359
7366
  "startIndex": 1,
7360
- "endIndex": 6
7367
+ "endIndex": 2
7361
7368
  },
7362
7369
  "isOptional": false
7370
+ },
7371
+ {
7372
+ "parameterName": "recordOutcome",
7373
+ "parameterTypeTokenRange": {
7374
+ "startIndex": 3,
7375
+ "endIndex": 4
7376
+ },
7377
+ "isOptional": true
7363
7378
  }
7364
7379
  ],
7365
7380
  "isOptional": false,
@@ -646,6 +646,13 @@ export declare type AiChatInteraction<TData = unknown, TResult = unknown> = {
646
646
  data: TData;
647
647
  /** The interaction outcome. */
648
648
  result: InteractionResult<TResult>;
649
+ /**
650
+ * What came of the answer, when the tool that opened the widget recorded it afterwards (see
651
+ * `recordInteractionOutcome` on the tool handler context): which rows a write review's
652
+ * approval actually wrote, say. Absent until then, and for a tool that records none.
653
+ * Display-only: the widget shows it, and it is never sent to a model.
654
+ */
655
+ outcome?: unknown;
649
656
  };
650
657
 
651
658
  export declare class AiChatMarkdown extends GenesisElement {
@@ -2458,7 +2465,7 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
2458
2465
  * resolves through) the parent's history and pending map. Calls chain
2459
2466
  * naturally: a grandchild → child → root.
2460
2467
  */
2461
- setHostInteractionRequester(fn: <T>(componentName: string, data: any, options?: InteractionRequestOptions) => Promise<T>): void;
2468
+ setHostInteractionRequester(fn: InteractionRequester, recordOutcome?: (interactionId: string, outcome: unknown) => boolean): void;
2462
2469
  /**
2463
2470
  * Request a custom UI interaction. Emits a new message with the interaction.
2464
2471
  * Tool handlers can call this to pause execution until the user completes the UI interaction.
@@ -2478,7 +2485,19 @@ export declare class ChatDriver extends EventTarget implements AiDriver {
2478
2485
  * and `presentation` to control whether the host wraps the widget in a chat
2479
2486
  * bubble and/or shows the "Assistant" label.
2480
2487
  */
2481
- requestInteraction<T>(componentName: string, data: any, options?: InteractionRequestOptions): Promise<T>;
2488
+ requestInteraction<T>(componentName: string, data: any, options?: InteractionRequestOptions, onOpened?: (interactionId: string) => void): Promise<T>;
2489
+ /**
2490
+ * Record what came of an interaction, after it resolved, on its history message
2491
+ * (`interaction.outcome`): handed to its widget and persisted with the session, never sent to a
2492
+ * model. Routed to the host driver when the interaction lives there (a sub-agent's). `false`,
2493
+ * changing nothing, when it is unknown, still pending, or the value cannot be stored as JSON.
2494
+ *
2495
+ * Tool handlers reach this through `recordInteractionOutcome` on their context, which binds it
2496
+ * to the interaction that call opened: see `buildHandlerContext`.
2497
+ *
2498
+ * @internal
2499
+ */
2500
+ recordInteractionOutcome(interactionId: string, outcome: unknown): boolean;
2482
2501
  /**
2483
2502
  * Add external (non-LLM) spend to an interaction's message AFTER it has resolved — for a widget
2484
2503
  * that resolves early so the assistant stops waiting, then keeps doing paid work on the user's
@@ -5239,6 +5258,21 @@ export declare interface InteractionContext<TState extends object = Record<strin
5239
5258
  */
5240
5259
  export declare type InteractionCostEventDetail = ChatInteractionEventsMap['interaction-cost'];
5241
5260
 
5261
+ /**
5262
+ * Opens an interaction somewhere else — the parent driver, for a sub-agent's — and tells
5263
+ * `onOpened` its id.
5264
+ */
5265
+ declare type InteractionRequester = <T>(componentName: string, data: any, options?: InteractionRequestOptions, onOpened?: (interactionId: string) => void) => Promise<T>;
5266
+
5267
+ /**
5268
+ * A message's interaction widget, in the wrapper that mounts it. Everything the widget is shown
5269
+ * comes from the history message through here, the outcome a tool recorded after the answer
5270
+ * included, so a remount, a pop-out and a reload all show the same thing.
5271
+ *
5272
+ * @internal
5273
+ */
5274
+ export declare const interactionWrapperTemplate: ViewTemplate<ChatMessage, FoundationAiAssistant>;
5275
+
5242
5276
  /** True when the assistant is active in the layout panel (docked) rather than the bubble. */
5243
5277
  export declare function isAiAssistantDocked(): boolean;
5244
5278
 
@@ -4032,6 +4032,10 @@ var META_EVENT_IMPORTANCE = {
4032
4032
  // the value was not real spend). 'high': it is the one way the session total goes quietly
4033
4033
  // wrong, so it must stand out when reconciling.
4034
4034
  "interaction.external-cost-dropped": "high",
4035
+ // What came of an answer, recorded by the tool that asked (see recordInteractionOutcome).
4036
+ "interaction.outcome": "normal",
4037
+ // An outcome that could not be recorded: the widget goes on showing only the answer.
4038
+ "interaction.outcome-dropped": "high",
4035
4039
  "external-diagnostics.folded": "normal",
4036
4040
  "session.cleared": "normal",
4037
4041
  "session.switched": "low",
@@ -5238,13 +5242,17 @@ var InteractionController = class {
5238
5242
  this.contexts = /* @__PURE__ */ new Map();
5239
5243
  }
5240
5244
  /** See `ChatDriver.setHostInteractionRequester`. */
5241
- setHostRequester(fn) {
5245
+ setHostRequester(fn, recordOutcome) {
5242
5246
  this.hostRequester = fn;
5247
+ this.hostOutcome = recordOutcome;
5243
5248
  }
5244
- /** See `ChatDriver.requestInteraction`. */
5245
- request(componentName, data, options) {
5249
+ /**
5250
+ * See `ChatDriver.requestInteraction`. `onOpened` is told the id of the interaction this call
5251
+ * opens, wherever it opens it, so the caller can later record its outcome and no other's.
5252
+ */
5253
+ request(componentName, data, options, onOpened) {
5246
5254
  if (this.hostRequester) {
5247
- return this.hostRequester(componentName, data, options);
5255
+ return this.hostRequester(componentName, data, options, onOpened);
5248
5256
  }
5249
5257
  if (this.pending.size > 0) {
5250
5258
  throw new Error(
@@ -5252,6 +5260,7 @@ var InteractionController = class {
5252
5260
  );
5253
5261
  }
5254
5262
  const interactionId = crypto.randomUUID();
5263
+ onOpened?.(interactionId);
5255
5264
  const chatInputDuringExecution = options?.chatInputDuringExecution;
5256
5265
  const timeoutMs = options?.timeoutMs;
5257
5266
  const presentation = options?.presentation;
@@ -5388,6 +5397,45 @@ var InteractionController = class {
5388
5397
  );
5389
5398
  return true;
5390
5399
  }
5400
+ /**
5401
+ * See `ChatDriver.recordInteractionOutcome`.
5402
+ *
5403
+ * @remarks
5404
+ * Only once the interaction has resolved: an outcome is what came of an answer. The message is
5405
+ * REPLACED, as `resolve` replaces it, never changed in place — the host's store freezes what it
5406
+ * holds. The value is copied as JSON, the form it is persisted in, so what the widget shows now
5407
+ * is what a reload shows, and nothing the caller keeps can change it afterwards.
5408
+ *
5409
+ * Announced on `history-updated`, unlike `recordExternalCost`: the outcome changes what the
5410
+ * widget shows, so the resolved widget has to be rebuilt with it.
5411
+ */
5412
+ recordOutcome(interactionId, outcome) {
5413
+ if (this.hostOutcome) return this.hostOutcome(interactionId, outcome);
5414
+ const drop = (reason) => {
5415
+ recordMetaEvent(this.deps.sessionKey, "interaction.outcome-dropped", {
5416
+ interactionId,
5417
+ reason
5418
+ });
5419
+ return false;
5420
+ };
5421
+ if (this.pending.has(interactionId)) return drop("interaction not resolved");
5422
+ let copy;
5423
+ try {
5424
+ const json = JSON.stringify(outcome);
5425
+ if (json === void 0) return drop("no value to store");
5426
+ copy = JSON.parse(json);
5427
+ } catch {
5428
+ return drop("not storable as JSON");
5429
+ }
5430
+ const patched = this.deps.patchInteractionMessage(interactionId, (message) => ({
5431
+ ...message,
5432
+ interaction: { ...message.interaction, outcome: copy }
5433
+ }));
5434
+ if (!patched) return drop("interaction message no longer in history");
5435
+ recordMetaEvent(this.deps.sessionKey, "interaction.outcome", { interactionId });
5436
+ this.deps.notifyHistoryUpdated();
5437
+ return true;
5438
+ }
5391
5439
  /** See `ChatDriver.getInteractionContext`. */
5392
5440
  context(interactionId) {
5393
5441
  return this.contexts.get(interactionId)?.context;
@@ -6985,8 +7033,8 @@ var ChatDriver = class _ChatDriver extends EventTarget {
6985
7033
  * resolves through) the parent's history and pending map. Calls chain
6986
7034
  * naturally: a grandchild → child → root.
6987
7035
  */
6988
- setHostInteractionRequester(fn) {
6989
- this.interactions.setHostRequester(fn);
7036
+ setHostInteractionRequester(fn, recordOutcome) {
7037
+ this.interactions.setHostRequester(fn, recordOutcome);
6990
7038
  }
6991
7039
  /**
6992
7040
  * Request a custom UI interaction. Emits a new message with the interaction.
@@ -7007,8 +7055,22 @@ var ChatDriver = class _ChatDriver extends EventTarget {
7007
7055
  * and `presentation` to control whether the host wraps the widget in a chat
7008
7056
  * bubble and/or shows the "Assistant" label.
7009
7057
  */
7010
- async requestInteraction(componentName, data, options) {
7011
- return this.interactions.request(componentName, data, options);
7058
+ async requestInteraction(componentName, data, options, onOpened) {
7059
+ return this.interactions.request(componentName, data, options, onOpened);
7060
+ }
7061
+ /**
7062
+ * Record what came of an interaction, after it resolved, on its history message
7063
+ * (`interaction.outcome`): handed to its widget and persisted with the session, never sent to a
7064
+ * model. Routed to the host driver when the interaction lives there (a sub-agent's). `false`,
7065
+ * changing nothing, when it is unknown, still pending, or the value cannot be stored as JSON.
7066
+ *
7067
+ * Tool handlers reach this through `recordInteractionOutcome` on their context, which binds it
7068
+ * to the interaction that call opened: see `buildHandlerContext`.
7069
+ *
7070
+ * @internal
7071
+ */
7072
+ recordInteractionOutcome(interactionId, outcome) {
7073
+ return this.interactions.recordOutcome(interactionId, outcome);
7012
7074
  }
7013
7075
  /**
7014
7076
  * Add external (non-LLM) spend to an interaction's message AFTER it has resolved — for a widget
@@ -7147,8 +7209,23 @@ var ChatDriver = class _ChatDriver extends EventTarget {
7147
7209
  * error growing as the fan-out widens.
7148
7210
  */
7149
7211
  buildHandlerContext(activeToolCallId, traceCapture) {
7212
+ let opened;
7213
+ let recorded = false;
7150
7214
  return {
7151
- requestInteraction: (componentName, data, options) => this.requestInteraction(componentName, data, options),
7215
+ requestInteraction: (componentName, data, options) => this.requestInteraction(componentName, data, options, (interactionId) => {
7216
+ opened = interactionId;
7217
+ }),
7218
+ recordInteractionOutcome: (outcome) => {
7219
+ if (!opened) return false;
7220
+ if (recorded) {
7221
+ logger2.warn(
7222
+ `ChatDriver(${this.activeAgentName ?? "unknown"}): recordInteractionOutcome called more than once in one tool call \u2014 ignoring`
7223
+ );
7224
+ return false;
7225
+ }
7226
+ recorded = true;
7227
+ return this.recordInteractionOutcome(opened, outcome);
7228
+ },
7152
7229
  // The MESSAGE's scope: one object per `sendMessage`, kept across a handoff's continuation
7153
7230
  // and handed to a sub-agent, and aborted by `cancel()` as well as a dispose. Not the
7154
7231
  // per-request `turnController`, which every continuation replaces.
@@ -7256,7 +7333,9 @@ var ChatDriver = class _ChatDriver extends EventTarget {
7256
7333
  }
7257
7334
  child.installAgent({ ...subConfig, primerHistory: effectivePrimer });
7258
7335
  child.setHostInteractionRequester(
7259
- (componentName, data, opts) => this.requestInteraction(componentName, data, opts)
7336
+ (componentName, data, opts, onOpened) => this.requestInteraction(componentName, data, opts, onOpened),
7337
+ // An outcome goes where its interaction went.
7338
+ (interactionId, outcome) => this.recordInteractionOutcome(interactionId, outcome)
7260
7339
  );
7261
7340
  child.hostAIServiceNotice = (code) => this.noticeAIServiceRefusal(code);
7262
7341
  const forwardTrace = (e) => {