@genesislcap/ai-assistant 15.61.0 → 15.63.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 (137) hide show
  1. package/dist/ai-assistant.api.json +18231 -11171
  2. package/dist/ai-assistant.d.ts +1235 -9
  3. package/dist/chat-driver.cjs +658 -50
  4. package/dist/chat-driver.cjs.map +4 -4
  5. package/dist/chat-driver.mjs +657 -50
  6. package/dist/chat-driver.mjs.map +4 -4
  7. package/dist/custom-elements.json +4759 -717
  8. package/dist/dts/autopilot/autopilot-driver.d.ts +278 -0
  9. package/dist/dts/autopilot/autopilot-driver.d.ts.map +1 -0
  10. package/dist/dts/autopilot/autopilot-session.d.ts +163 -0
  11. package/dist/dts/autopilot/autopilot-session.d.ts.map +1 -0
  12. package/dist/dts/autopilot/autopilot-tools.d.ts +15 -0
  13. package/dist/dts/autopilot/autopilot-tools.d.ts.map +1 -0
  14. package/dist/dts/autopilot/decision-message.d.ts +62 -0
  15. package/dist/dts/autopilot/decision-message.d.ts.map +1 -0
  16. package/dist/dts/autopilot/hand-back/hand-back.controller.d.ts +69 -0
  17. package/dist/dts/autopilot/hand-back/hand-back.controller.d.ts.map +1 -0
  18. package/dist/dts/autopilot/hand-back/hand-back.d.ts +22 -0
  19. package/dist/dts/autopilot/hand-back/hand-back.d.ts.map +1 -0
  20. package/dist/dts/autopilot/index.d.ts +4 -0
  21. package/dist/dts/autopilot/index.d.ts.map +1 -0
  22. package/dist/dts/channel/ai-activity-bus.d.ts.map +1 -1
  23. package/dist/dts/channel/ai-activity-channel.d.ts +17 -0
  24. package/dist/dts/channel/ai-activity-channel.d.ts.map +1 -1
  25. package/dist/dts/channel/autopilot-needs-user.d.ts +8 -0
  26. package/dist/dts/channel/autopilot-needs-user.d.ts.map +1 -0
  27. package/dist/dts/components/agent-picker/agent-picker.constants.d.ts +10 -0
  28. package/dist/dts/components/agent-picker/agent-picker.constants.d.ts.map +1 -1
  29. package/dist/dts/components/agent-picker/agent-picker.d.ts +4 -0
  30. package/dist/dts/components/agent-picker/agent-picker.d.ts.map +1 -1
  31. package/dist/dts/components/agent-picker/agent-picker.template.d.ts.map +1 -1
  32. package/dist/dts/components/ai-driver/ai-driver.d.ts +34 -1
  33. package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
  34. package/dist/dts/components/ai-driver/base-driver-decorator.d.ts +3 -1
  35. package/dist/dts/components/ai-driver/base-driver-decorator.d.ts.map +1 -1
  36. package/dist/dts/components/chat-bubble/chat-bubble.d.ts +21 -0
  37. package/dist/dts/components/chat-bubble/chat-bubble.d.ts.map +1 -1
  38. package/dist/dts/components/chat-bubble/chat-bubble.styles.d.ts.map +1 -1
  39. package/dist/dts/components/chat-bubble/chat-bubble.template.d.ts.map +1 -1
  40. package/dist/dts/components/chat-driver/chat-driver.d.ts +5 -1
  41. package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
  42. package/dist/dts/components/chat-driver/interaction-controller.d.ts +27 -3
  43. package/dist/dts/components/chat-driver/interaction-controller.d.ts.map +1 -1
  44. package/dist/dts/components/chat-interaction-wrapper/chat-interaction-wrapper.d.ts +10 -2
  45. package/dist/dts/components/chat-interaction-wrapper/chat-interaction-wrapper.d.ts.map +1 -1
  46. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +9 -1
  47. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
  48. package/dist/dts/config/config.d.ts +183 -0
  49. package/dist/dts/config/config.d.ts.map +1 -1
  50. package/dist/dts/config/define-stateful-agent.d.ts +31 -1
  51. package/dist/dts/config/define-stateful-agent.d.ts.map +1 -1
  52. package/dist/dts/genesis/write-commit.d.ts +17 -7
  53. package/dist/dts/genesis/write-commit.d.ts.map +1 -1
  54. package/dist/dts/index.d.ts +7 -3
  55. package/dist/dts/index.d.ts.map +1 -1
  56. package/dist/dts/main/main.d.ts +128 -5
  57. package/dist/dts/main/main.d.ts.map +1 -1
  58. package/dist/dts/main/main.styles.d.ts.map +1 -1
  59. package/dist/dts/main/main.template.d.ts +2 -2
  60. package/dist/dts/main/main.template.d.ts.map +1 -1
  61. package/dist/dts/react.d.ts +10 -0
  62. package/dist/dts/state/debug-event-log.d.ts +1 -1
  63. package/dist/dts/state/debug-event-log.d.ts.map +1 -1
  64. package/dist/dts/state/decision-surface.d.ts +46 -0
  65. package/dist/dts/state/decision-surface.d.ts.map +1 -0
  66. package/dist/dts/state/interaction-context.d.ts +21 -1
  67. package/dist/dts/state/interaction-context.d.ts.map +1 -1
  68. package/dist/dts/state/interaction-registry.d.ts +63 -0
  69. package/dist/dts/state/interaction-registry.d.ts.map +1 -0
  70. package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
  71. package/dist/dts/state/persistence/session-snapshot.d.ts +21 -0
  72. package/dist/dts/state/persistence/session-snapshot.d.ts.map +1 -1
  73. package/dist/dts/state/run-steps.d.ts +66 -0
  74. package/dist/dts/state/run-steps.d.ts.map +1 -0
  75. package/dist/dts/types/ai-chat-widget.d.ts +7 -1
  76. package/dist/dts/types/ai-chat-widget.d.ts.map +1 -1
  77. package/dist/dts/types/interaction-context.d.ts +66 -1
  78. package/dist/dts/types/interaction-context.d.ts.map +1 -1
  79. package/dist/dts/types/interaction-interceptor.d.ts +60 -2
  80. package/dist/dts/types/interaction-interceptor.d.ts.map +1 -1
  81. package/dist/dts/types/interaction-surface.d.ts +195 -0
  82. package/dist/dts/types/interaction-surface.d.ts.map +1 -0
  83. package/dist/dts/utils/context-tokens.d.ts +6 -0
  84. package/dist/dts/utils/context-tokens.d.ts.map +1 -1
  85. package/dist/dts/utils/delegated-message.d.ts +13 -0
  86. package/dist/dts/utils/delegated-message.d.ts.map +1 -1
  87. package/dist/dts/utils/history-transform.d.ts.map +1 -1
  88. package/dist/dts/utils/preserved-user-messages.d.ts +21 -0
  89. package/dist/dts/utils/preserved-user-messages.d.ts.map +1 -0
  90. package/dist/esm/autopilot/autopilot-driver.js +906 -0
  91. package/dist/esm/autopilot/autopilot-session.js +449 -0
  92. package/dist/esm/autopilot/autopilot-tools.js +68 -0
  93. package/dist/esm/autopilot/decision-message.js +206 -0
  94. package/dist/esm/autopilot/hand-back/hand-back.controller.js +47 -0
  95. package/dist/esm/autopilot/hand-back/hand-back.js +129 -0
  96. package/dist/esm/autopilot/index.js +4 -0
  97. package/dist/esm/channel/ai-activity-bus.js +7 -0
  98. package/dist/esm/channel/autopilot-needs-user.js +26 -0
  99. package/dist/esm/components/agent-picker/agent-picker.constants.js +10 -0
  100. package/dist/esm/components/agent-picker/agent-picker.js +11 -1
  101. package/dist/esm/components/agent-picker/agent-picker.template.js +2 -4
  102. package/dist/esm/components/ai-driver/ai-driver.js +2 -0
  103. package/dist/esm/components/ai-driver/base-driver-decorator.js +8 -0
  104. package/dist/esm/components/chat-bubble/chat-bubble.js +45 -0
  105. package/dist/esm/components/chat-bubble/chat-bubble.styles.js +26 -0
  106. package/dist/esm/components/chat-bubble/chat-bubble.template.js +13 -0
  107. package/dist/esm/components/chat-driver/chat-driver.js +53 -18
  108. package/dist/esm/components/chat-driver/interaction-controller.js +297 -12
  109. package/dist/esm/components/chat-interaction-wrapper/chat-interaction-wrapper.js +16 -2
  110. package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +28 -11
  111. package/dist/esm/config/define-stateful-agent.js +34 -29
  112. package/dist/esm/genesis/write-outcome.js +2 -2
  113. package/dist/esm/index.js +3 -0
  114. package/dist/esm/main/main.js +334 -15
  115. package/dist/esm/main/main.styles.js +126 -0
  116. package/dist/esm/main/main.template.js +116 -11
  117. package/dist/esm/state/debug-event-log.js +28 -1
  118. package/dist/esm/state/decision-surface.js +209 -0
  119. package/dist/esm/state/interaction-context.js +89 -1
  120. package/dist/esm/state/interaction-registry.js +33 -0
  121. package/dist/esm/state/persistence/session-persister.js +23 -11
  122. package/dist/esm/state/persistence/session-snapshot.js +1 -1
  123. package/dist/esm/state/run-steps.js +77 -0
  124. package/dist/esm/types/interaction-surface.js +1 -0
  125. package/dist/esm/utils/context-tokens.js +23 -9
  126. package/dist/esm/utils/delegated-message.js +15 -0
  127. package/dist/esm/utils/history-transform.js +18 -7
  128. package/dist/esm/utils/preserved-user-messages.js +31 -0
  129. package/dist/react.cjs +7 -0
  130. package/dist/react.mjs +6 -0
  131. package/docs/styling.md +1 -1
  132. package/package.json +17 -17
  133. package/sandbox/README.md +38 -2
  134. package/sandbox/autopilot.ts +358 -0
  135. package/sandbox/controls.ts +24 -1
  136. package/sandbox/fixtures.ts +2 -0
  137. package/sandbox/sandbox.ts +188 -1
@@ -3,12 +3,12 @@ import { AIServiceError, BudgetExhaustedError } from '@genesislcap/foundation-ai
3
3
  import { validateStaticAgentProviders } from '../../config/validate-providers';
4
4
  import { recordMetaEvent } from '../../state/debug-event-log';
5
5
  import { reachesProvider } from '../../utils/context-tokens';
6
- import { DEFAULT_DELEGATE_FRAMING, frameDelegatedContent, } from '../../utils/delegated-message';
6
+ import { delegatedFields, frameDelegatedContent, } from '../../utils/delegated-message';
7
7
  import { transformHistoryForAgent } from '../../utils/history-transform';
8
8
  import { logger } from '../../utils/logger';
9
9
  import { messageUsage } from '../../utils/sum-usage';
10
10
  import { BaseDriverDecorator } from '../ai-driver/base-driver-decorator';
11
- import { ChatDriver, REQUEST_CONTINUATION_TOOL } from '../chat-driver/chat-driver';
11
+ import { ChatDriver, REQUEST_CONTINUATION_TOOL, } from '../chat-driver/chat-driver';
12
12
  const DEFAULT_MAX_HANDOFFS = 3;
13
13
  const DEFAULT_CLASSIFIER_HISTORY_LENGTH = 4;
14
14
  const DEFAULT_CLASSIFIER_RETRIES = 2;
@@ -262,14 +262,9 @@ export class OrchestratingDriver extends BaseDriverDecorator {
262
262
  }
263
263
  sendMessage(input, attachments, options) {
264
264
  return __awaiter(this, void 0, void 0, function* () {
265
- var _a;
266
- // Who it is from travels with every copy of the message this method makes (GENC-1660).
267
- const delegated = (options === null || options === void 0 ? void 0 : options.delegate)
268
- ? {
269
- delegate: options.delegate,
270
- delegateFraming: (_a = options.delegateFraming) !== null && _a !== void 0 ? _a : DEFAULT_DELEGATE_FRAMING,
271
- }
272
- : {};
265
+ // Who it is from, and what writing it cost, travel with every copy of the message this method
266
+ // makes (GENC-1660).
267
+ const delegated = delegatedFields(options);
273
268
  try {
274
269
  return yield this.runOrchestratedTurn(input, attachments, options, delegated);
275
270
  }
@@ -490,7 +485,29 @@ export class OrchestratingDriver extends BaseDriverDecorator {
490
485
  yield this.installAgent(agent);
491
486
  if (!resumeNote || agent.resumeOnRestore === false || this.cancelled)
492
487
  return undefined;
493
- return this.chatDriver.continueFromHistory(undefined, { tailNote: resumeNote });
488
+ const result = yield this.chatDriver.continueFromHistory(undefined, { tailNote: resumeNote });
489
+ yield this.releaseIfRequested();
490
+ return result;
491
+ });
492
+ }
493
+ /**
494
+ * A continuation outside a routed turn — a decorator carrying the agent on, say — can finish the
495
+ * flow as surely as a turn can, so a release it requests is acted on here too. Before
496
+ * (GENC-1660), only `sendMessage` checked, and a flow finished by a continuation stayed locked.
497
+ */
498
+ continueFromHistory(transientPrimer, options) {
499
+ return __awaiter(this, void 0, void 0, function* () {
500
+ const result = yield this.chatDriver.continueFromHistory(transientPrimer, options);
501
+ yield this.releaseIfRequested();
502
+ return result;
503
+ });
504
+ }
505
+ /** Release the flow if the turn that just ended asked to, and an agent is still active to release. */
506
+ releaseIfRequested() {
507
+ return __awaiter(this, void 0, void 0, function* () {
508
+ if (this.chatDriver.getAgentReleaseRequested() && this.agentSession.getActive()) {
509
+ yield this.releaseActiveAgent();
510
+ }
494
511
  });
495
512
  }
496
513
  /**
@@ -246,27 +246,12 @@ export function defineStatefulAgent(opts) {
246
246
  });
247
247
  })
248
248
  : undefined;
249
- const base = {
250
- name: opts.name,
251
- displayName: wrappedDisplayName,
252
- primerHistory: opts.primerHistory,
253
- subAgents: opts.subAgents,
254
- manualSelection: opts.manualSelection,
255
- chatInputDuringExecution: opts.chatInputDuringExecution,
256
- toolDefinitions: wrappedTools,
257
- toolHandlers: wrappedHandlers,
258
- provider: wrappedProvider,
259
- temperature: wrappedTemperature,
260
- toolChoice: wrappedToolChoice,
261
- cachePolicy: wrappedCachePolicy,
262
- thinkingPolicy: wrappedThinkingPolicy,
263
- tailContext: wrappedTailContext,
264
- onUnresolvedTool: wrappedOnUnresolvedTool,
265
- resumable: wrappedResumable,
266
- notResumableMessage: opts.notResumableMessage,
267
- resumeOnRestore: opts.resumeOnRestore,
268
- contextReserve: opts.contextReserve,
269
- onActivate: (ctx) => __awaiter(this, void 0, void 0, function* () {
249
+ const base = Object.assign(Object.assign({ name: opts.name, displayName: wrappedDisplayName, primerHistory: opts.primerHistory, subAgents: opts.subAgents, manualSelection: opts.manualSelection, chatInputDuringExecution: opts.chatInputDuringExecution, toolDefinitions: wrappedTools, toolHandlers: wrappedHandlers, provider: wrappedProvider, temperature: wrappedTemperature, toolChoice: wrappedToolChoice, cachePolicy: wrappedCachePolicy, thinkingPolicy: wrappedThinkingPolicy, tailContext: wrappedTailContext, onUnresolvedTool: wrappedOnUnresolvedTool, resumable: wrappedResumable, notResumableMessage: opts.notResumableMessage, resumeOnRestore: opts.resumeOnRestore, contextReserve: opts.contextReserve }, (opts.autopilot && {
250
+ autopilot: {
251
+ config: opts.autopilot,
252
+ state: () => state,
253
+ },
254
+ })), { onActivate: (ctx) => __awaiter(this, void 0, void 0, function* () {
270
255
  state = yield opts.init(ctx);
271
256
  // Sample once with the init state to fail loud on fold misuse at the
272
257
  // agent-switch boundary instead of waiting for the first tool call.
@@ -277,8 +262,7 @@ export function defineStatefulAgent(opts) {
277
262
  const sampled = yield opts.toolHandlers(state);
278
263
  assertNoFolds(sampled);
279
264
  }
280
- }),
281
- onDeactivate: (ctx) => __awaiter(this, void 0, void 0, function* () {
265
+ }), onDeactivate: (ctx) => __awaiter(this, void 0, void 0, function* () {
282
266
  if (state !== undefined && opts.dispose) {
283
267
  yield opts.dispose(Object.assign(Object.assign({}, ctx), { state }));
284
268
  }
@@ -286,15 +270,14 @@ export function defineStatefulAgent(opts) {
286
270
  // cannot interleave the read-then-write of `state`.
287
271
  // eslint-disable-next-line require-atomic-updates
288
272
  state = undefined;
289
- }),
290
- systemPrompt: opts.systemPrompt
273
+ }), systemPrompt: opts.systemPrompt
291
274
  ? (ctx) => __awaiter(this, void 0, void 0, function* () {
292
275
  if (!state) {
293
276
  throw new Error(`Stateful agent "${opts.name}" systemPrompt called before init`);
294
277
  }
295
278
  return opts.systemPrompt(Object.assign(Object.assign({}, ctx), { state }));
296
279
  })
297
- : undefined,
280
+ : undefined,
298
281
  // Called per LLM call by ChatDriver, and once at debug-log export time.
299
282
  // Returns `undefined` before activation (state hasn't been built yet) and
300
283
  // after deactivation (state was disposed) — the snapshotter is best-effort
@@ -305,14 +288,36 @@ export function defineStatefulAgent(opts) {
305
288
  return opts.getDebugSnapshot
306
289
  ? opts.getDebugSnapshot(state)
307
290
  : defaultStatefulDebugSnapshot(state);
308
- },
291
+ },
309
292
  // Lossless restore image for session persistence (see `serialize` on the
310
293
  // config). Returns undefined before activation / after disposal.
311
294
  serialize: () => {
312
295
  if (state === undefined)
313
296
  return undefined;
314
297
  return opts.serialize ? opts.serialize(state) : defaultStatefulSerialize(state);
315
- },
316
- };
298
+ } });
317
299
  return Object.assign(Object.assign({}, base), { description: opts.description, excludeFromClassifier: opts.excludeFromClassifier });
318
300
  }
301
+ /**
302
+ * Define an autopilot for a stateful agent whose state is `S` (GENC-1660). An identity function
303
+ * that exists for its type: the resolvers get `S`, and the result goes on `defineStatefulAgent`'s
304
+ * `autopilot` option.
305
+ *
306
+ * @example
307
+ * ```ts
308
+ * defineStatefulAgent<BootstrapState>({
309
+ * name: 'bootstrap',
310
+ * …,
311
+ * autopilot: defineAutopilot<BootstrapState>({
312
+ * availableWhen: ({ state }) => briefApproved(state.machine),
313
+ * widgetPolicy: { 'planning-question': 'allowed' },
314
+ * systemPrompt: ({ state }) => `${AUTOPILOT_BASE}\n<brief>${frozenBrief(state)}</brief>`,
315
+ * }),
316
+ * });
317
+ * ```
318
+ *
319
+ * @beta
320
+ */
321
+ export function defineAutopilot(config) {
322
+ return config;
323
+ }
@@ -145,8 +145,8 @@ export function mapWriteReply(reply, { mode, op }) {
145
145
  const warnings = warningsOf(message);
146
146
  if (type === 'EVENT_ACK') {
147
147
  // The mode is the whole difference. A dry run ACKs without writing anything, and on a
148
- // generated app it ACKs whatever it is given, so calling that "written" would be the lie
149
- // the review table is built to avoid.
148
+ // generated app it ACKs any payload that passes the schema, so calling that "written" would
149
+ // be the lie the review table is built to avoid.
150
150
  if (mode === 'validate') {
151
151
  return Object.assign({ status: 'checked', committed: false, message: 'Checked.' }, (warnings ? { warnings } : {}));
152
152
  }
package/dist/esm/index.js CHANGED
@@ -3,6 +3,7 @@ export * from './main/main.types';
3
3
  export * from './main/main.template';
4
4
  export * from './components/agent-picker';
5
5
  export * from './components/agent-session';
6
+ export * from './autopilot';
6
7
  export * from './components/ai-driver';
7
8
  export * from './components/chat-driver';
8
9
  export * from './components/orchestrating-driver';
@@ -19,6 +20,8 @@ export * from './provider/assistant-app-settings';
19
20
  export * from './utils/tool-fold';
20
21
  export { DEFAULT_DELEGATE_FRAMING, isDelegated, } from './utils/delegated-message';
21
22
  export { assistantSettingsSectionTitleStyles } from './styles/settings-section';
23
+ export { runSteps } from './state/run-steps';
24
+ export { getInteractionRegistration, registerInteraction, } from './state/interaction-registry';
22
25
  // MARKDOWN_EXPORTPARTS travels with the component: a host rendering `<ai-chat-markdown>` in its
23
26
  // own shadow root has to forward its parts, and hand-copying the list is how it drifts.
24
27
  export { AiChatMarkdown, MARKDOWN_EXPORTPARTS } from './components/chat-markdown/chat-markdown';