@noodleseed/assistant 1.28.0 → 1.29.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 (41) hide show
  1. package/dist/{app-view-element-mXHvcAXc.d.ts → app-view-element-kR8eqhyD.d.cts} +1 -1
  2. package/dist/{app-view-element-BjRkwNN1.d.cts → app-view-element-nY1svwHT.d.ts} +1 -1
  3. package/dist/app-view.d.cts +3 -3
  4. package/dist/app-view.d.ts +3 -3
  5. package/dist/{chunk-WJV4MJUR.js → chunk-3VZ3M5BE.js} +92 -9
  6. package/dist/{chunk-WJV4MJUR.js.map → chunk-3VZ3M5BE.js.map} +1 -1
  7. package/dist/{chunk-QH7PL3GU.js → chunk-DOWFW3KA.js} +259 -54
  8. package/dist/chunk-DOWFW3KA.js.map +1 -0
  9. package/dist/{client-CPFw8tfo.d.ts → client-contract-Bw9dtrhw.d.cts} +26 -35
  10. package/dist/{client-_xivfs4q.d.cts → client-contract-DjU9qsoP.d.ts} +26 -35
  11. package/dist/client.cjs +91 -8
  12. package/dist/client.cjs.map +1 -1
  13. package/dist/client.d.cts +12 -2
  14. package/dist/client.d.ts +12 -2
  15. package/dist/client.js +1 -1
  16. package/dist/embed.global.js +46 -46
  17. package/dist/index.cjs +348 -60
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +3 -3
  20. package/dist/index.d.ts +3 -3
  21. package/dist/index.js +2 -2
  22. package/dist/react/client.cjs +91 -8
  23. package/dist/react/client.cjs.map +1 -1
  24. package/dist/react/client.d.cts +2 -2
  25. package/dist/react/client.d.ts +2 -2
  26. package/dist/react/client.js +1 -1
  27. package/dist/react.cjs +348 -60
  28. package/dist/react.cjs.map +1 -1
  29. package/dist/react.d.cts +3 -3
  30. package/dist/react.d.ts +3 -3
  31. package/dist/react.js +2 -2
  32. package/dist/server-CMqlAnxs.d.cts +270 -0
  33. package/dist/server-CMqlAnxs.d.ts +270 -0
  34. package/dist/server.cjs.map +1 -1
  35. package/dist/server.d.cts +1 -121
  36. package/dist/server.d.ts +1 -121
  37. package/dist/server.js.map +1 -1
  38. package/package.json +1 -1
  39. package/dist/appearance-BpVu3lpk.d.cts +0 -146
  40. package/dist/appearance-BpVu3lpk.d.ts +0 -146
  41. package/dist/chunk-QH7PL3GU.js.map +0 -1
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { f as AssistantAppearance, c as AssistantContext, g as AssistantModelContextUpdate, b as AssistantPageContext, j as AssistantInteractionResponse } from './client-_xivfs4q.cjs';
2
- export { k as AssistantAppearanceTheme, i as AssistantAppearanceWarning, e as AssistantErrorDetail, l as AssistantEvent, m as AssistantSurfaceAppearance, a as AssistantViewAvailableDetail, n as AssistantViewAvailableEvent } from './client-_xivfs4q.cjs';
3
- import './appearance-BpVu3lpk.cjs';
1
+ import { Q as AssistantAppearance, c as AssistantContext, y as AssistantModelContextUpdate, b as AssistantPageContext, v as AssistantInteractionResponse } from './client-contract-Bw9dtrhw.cjs';
2
+ export { S as AssistantAppearanceTheme, R as AssistantAppearanceWarning, e as AssistantErrorDetail, T as AssistantEvent, U as AssistantSurfaceAppearance, a as AssistantViewAvailableDetail, O as AssistantViewAvailableEvent } from './client-contract-Bw9dtrhw.cjs';
4
3
  import 'ai';
4
+ import './server-CMqlAnxs.cjs';
5
5
 
6
6
  declare const ASSISTANT_TAG_NAME = "noodle-assistant";
7
7
  declare const HTMLElementBase: typeof HTMLElement;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { f as AssistantAppearance, c as AssistantContext, g as AssistantModelContextUpdate, b as AssistantPageContext, j as AssistantInteractionResponse } from './client-CPFw8tfo.js';
2
- export { k as AssistantAppearanceTheme, i as AssistantAppearanceWarning, e as AssistantErrorDetail, l as AssistantEvent, m as AssistantSurfaceAppearance, a as AssistantViewAvailableDetail, n as AssistantViewAvailableEvent } from './client-CPFw8tfo.js';
3
- import './appearance-BpVu3lpk.js';
1
+ import { Q as AssistantAppearance, c as AssistantContext, y as AssistantModelContextUpdate, b as AssistantPageContext, v as AssistantInteractionResponse } from './client-contract-DjU9qsoP.js';
2
+ export { S as AssistantAppearanceTheme, R as AssistantAppearanceWarning, e as AssistantErrorDetail, T as AssistantEvent, U as AssistantSurfaceAppearance, a as AssistantViewAvailableDetail, O as AssistantViewAvailableEvent } from './client-contract-DjU9qsoP.js';
4
3
  import 'ai';
4
+ import './server-CMqlAnxs.js';
5
5
 
6
6
  declare const ASSISTANT_TAG_NAME = "noodle-assistant";
7
7
  declare const HTMLElementBase: typeof HTMLElement;
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@ import {
2
2
  ASSISTANT_TAG_NAME,
3
3
  NoodleAssistantElement,
4
4
  registerNoodleAssistant
5
- } from "./chunk-QH7PL3GU.js";
5
+ } from "./chunk-DOWFW3KA.js";
6
6
  import "./chunk-XKTUXFGX.js";
7
- import "./chunk-WJV4MJUR.js";
7
+ import "./chunk-3VZ3M5BE.js";
8
8
  import "./chunk-P223CYPO.js";
9
9
  import "./chunk-3YYTUJPJ.js";
10
10
  import "./chunk-5FUTL2UF.js";
@@ -22618,6 +22618,7 @@ var AssistantChatStateStore = class {
22618
22618
  #messages = [];
22619
22619
  #status = "ready";
22620
22620
  #error;
22621
+ #suggestions;
22621
22622
  #operation;
22622
22623
  #nextId = 0;
22623
22624
  subscribe(listener) {
@@ -22629,20 +22630,24 @@ var AssistantChatStateStore = class {
22629
22630
  return structuredClone({
22630
22631
  status: this.#status,
22631
22632
  messages: this.#messages,
22633
+ ...this.#suggestions ? { suggestions: this.#suggestions } : {},
22632
22634
  ...this.#error ? { error: this.#error } : {}
22633
22635
  });
22634
22636
  }
22635
22637
  handle(event) {
22636
22638
  switch (event.event) {
22637
22639
  case "message_started":
22640
+ this.#suggestions = void 0;
22638
22641
  this.#beginMessage(event.data.message);
22639
22642
  return;
22640
22643
  case "interaction_started":
22644
+ this.#suggestions = void 0;
22641
22645
  this.#beginInteraction(event.data.id);
22642
22646
  return;
22643
22647
  case "resume_started":
22644
22648
  this.#status = "submitted";
22645
22649
  this.#error = void 0;
22650
+ this.#suggestions = void 0;
22646
22651
  this.#startOperation();
22647
22652
  this.#notify();
22648
22653
  return;
@@ -22675,6 +22680,13 @@ var AssistantChatStateStore = class {
22675
22680
  case "view_available":
22676
22681
  this.#writeData("view", event.data.id, event.data);
22677
22682
  return;
22683
+ case "suggested_prompts":
22684
+ this.#suggestions = {
22685
+ phase: event.data.phase,
22686
+ prompts: [...event.data.prompts]
22687
+ };
22688
+ this.#notify();
22689
+ return;
22678
22690
  case "message_completed":
22679
22691
  this.#closeOperation("ready");
22680
22692
  return;
@@ -22715,6 +22727,7 @@ var AssistantChatStateStore = class {
22715
22727
  this.#messages = [...this.#messages, userMessage];
22716
22728
  this.#status = "submitted";
22717
22729
  this.#error = void 0;
22730
+ this.#suggestions = void 0;
22718
22731
  this.#startOperation();
22719
22732
  this.#notify();
22720
22733
  }
@@ -23044,7 +23057,8 @@ var assistantUiSchema = external_exports.object({
23044
23057
  privacyUrl: httpsUrlSchema.optional(),
23045
23058
  termsUrl: httpsUrlSchema.optional(),
23046
23059
  locale: external_exports.string().trim().min(2).max(35).optional(),
23047
- direction: external_exports.enum(["ltr", "rtl", "auto"]).optional()
23060
+ direction: external_exports.enum(["ltr", "rtl", "auto"]).optional(),
23061
+ webmcp: external_exports.object({ enabled: external_exports.boolean().optional() }).strict().optional()
23048
23062
  }).strict();
23049
23063
  var assistantConfigurationSchema = external_exports.object({ branding: brandingSchema.optional(), assistant: assistantUiSchema.optional() }).strict();
23050
23064
  function parseAssistantConfiguration(value) {
@@ -23106,7 +23120,8 @@ function parseSession(value) {
23106
23120
  const apps = value.endpoints.apps;
23107
23121
  const sandbox = value.endpoints.sandbox;
23108
23122
  const transcript = value.endpoints.transcript;
23109
- if (typeof value.token !== "string" || typeof value.expiresAt !== "string" || typeof value.endpoints.turns !== "string" || typeof value.endpoints.toolConfirmations !== "string" || interactions !== void 0 && typeof interactions !== "string" || apps !== void 0 && typeof apps !== "string" || sandbox !== void 0 && typeof sandbox !== "string" || transcript !== void 0 && typeof transcript !== "string") {
23123
+ const suggestions = value.endpoints.suggestions;
23124
+ if (typeof value.token !== "string" || typeof value.expiresAt !== "string" || typeof value.endpoints.turns !== "string" || typeof value.endpoints.toolConfirmations !== "string" || interactions !== void 0 && typeof interactions !== "string" || apps !== void 0 && typeof apps !== "string" || sandbox !== void 0 && typeof sandbox !== "string" || transcript !== void 0 && typeof transcript !== "string" || suggestions !== void 0 && typeof suggestions !== "string") {
23110
23125
  throw clientError("session_failed", "Assistant session response is invalid", true);
23111
23126
  }
23112
23127
  const configuration = parseAssistantConfiguration(value.configuration);
@@ -23119,7 +23134,8 @@ function parseSession(value) {
23119
23134
  ...typeof interactions === "string" ? { interactions } : {},
23120
23135
  ...typeof apps === "string" ? { apps } : {},
23121
23136
  ...typeof sandbox === "string" ? { sandbox } : {},
23122
- ...typeof transcript === "string" ? { transcript } : {}
23137
+ ...typeof transcript === "string" ? { transcript } : {},
23138
+ ...typeof suggestions === "string" ? { suggestions } : {}
23123
23139
  },
23124
23140
  ...configuration === void 0 ? {} : { configuration },
23125
23141
  ...isRecord2(value.resume) && typeof value.resume.tool === "string" ? { resume: { tool: value.resume.tool } } : {}
@@ -23203,6 +23219,10 @@ function toAssistantClientEvent(event) {
23203
23219
  return event;
23204
23220
  }
23205
23221
  break;
23222
+ case "suggested_prompts":
23223
+ if (isSuggestedPromptsDetail(value))
23224
+ return event;
23225
+ break;
23206
23226
  case "done":
23207
23227
  if (hasOptionalTurnId(value)) return event;
23208
23228
  break;
@@ -23214,6 +23234,12 @@ function toAssistantClientEvent(event) {
23214
23234
  }
23215
23235
  return { event: "unrecognized", data: { name: event.event, payload: value } };
23216
23236
  }
23237
+ function isSuggestedPromptsDetail(value) {
23238
+ if (!isRecord3(value)) return false;
23239
+ return (value.phase === "initial" || value.phase === "follow_up") && Array.isArray(value.prompts) && value.prompts.length <= 3 && value.prompts.every(
23240
+ (prompt) => typeof prompt === "string" && prompt.trim().length > 0 && prompt.length <= 240
23241
+ ) && hasOptionalTurnId(value);
23242
+ }
23217
23243
  function isViewAvailableDetail(value) {
23218
23244
  return hasString(value, "id") && hasString(value, "tool") && typeof value.resourceUri === "string" && value.resourceUri.startsWith("ui://") && hasOptionalString(value.title) && (value.replayed === void 0 || value.replayed === true) && isJsonValue(value.result, 0) && hasOptionalJson(value.arguments) && hasOptionalString(value.html) && (value.resourceMeta === void 0 || isRecord3(value.resourceMeta)) && (value.allowedOpenDomains === void 0 || Array.isArray(value.allowedOpenDomains) && value.allowedOpenDomains.every(isHttpsUrl2)) && hasOptionalTurnId(value);
23219
23245
  }
@@ -23397,6 +23423,11 @@ function parseTranscriptEntries(value) {
23397
23423
  }
23398
23424
  return parsed;
23399
23425
  }
23426
+ function parseTranscriptSuggestions(value) {
23427
+ if (typeof value !== "object" || value === null) return void 0;
23428
+ const suggestions = value.suggestions;
23429
+ return isSuggestedPromptsDetail(suggestions) && suggestions.phase === "follow_up" ? { phase: suggestions.phase, prompts: suggestions.prompts } : void 0;
23430
+ }
23400
23431
  function transcriptReplayEvents(entries) {
23401
23432
  const events = [];
23402
23433
  let open = false;
@@ -23559,6 +23590,7 @@ var DefaultAssistantClient = class {
23559
23590
  #context;
23560
23591
  #modelContext;
23561
23592
  #active;
23593
+ #initialSuggestions;
23562
23594
  #pendingAppInteractions = /* @__PURE__ */ new Map();
23563
23595
  constructor(options) {
23564
23596
  this.#source = resolveSessionSource(options);
@@ -23620,10 +23652,13 @@ var DefaultAssistantClient = class {
23620
23652
  "turn_failed"
23621
23653
  );
23622
23654
  if (!response.ok) return;
23623
- for (const event of transcriptReplayEvents(parseTranscriptEntries(await response.json()))) {
23655
+ const value = await response.json();
23656
+ for (const event of transcriptReplayEvents(parseTranscriptEntries(value))) {
23624
23657
  this.#emit(event);
23625
23658
  if (event.event === "message_completed") await this.#chat.flush();
23626
23659
  }
23660
+ const suggestions = parseTranscriptSuggestions(value);
23661
+ if (suggestions) this.#emit({ event: "suggested_prompts", data: suggestions });
23627
23662
  }
23628
23663
  /** POST the one-shot resume trigger; a 409 means nothing was pending, which renders as silence. */
23629
23664
  async #resumeTurn(session, signal) {
@@ -23632,7 +23667,10 @@ var DefaultAssistantClient = class {
23632
23667
  {
23633
23668
  method: "POST",
23634
23669
  headers: authorizedHeaders(session.token, "text/event-stream"),
23635
- body: JSON.stringify({ resume: true }),
23670
+ body: JSON.stringify({
23671
+ resume: true,
23672
+ ...session.endpoints.suggestions ? { suggestions: true } : {}
23673
+ }),
23636
23674
  signal
23637
23675
  },
23638
23676
  "turn_failed"
@@ -23655,6 +23693,7 @@ var DefaultAssistantClient = class {
23655
23693
  async sendMessage(text2) {
23656
23694
  const message = text2.trim();
23657
23695
  if (!message) return;
23696
+ this.#cancelInitialSuggestions();
23658
23697
  await this.#singleFlight(async (signal) => {
23659
23698
  await this.#runChatOperation(
23660
23699
  signal,
@@ -23662,10 +23701,42 @@ var DefaultAssistantClient = class {
23662
23701
  );
23663
23702
  });
23664
23703
  }
23704
+ async loadInitialSuggestions() {
23705
+ if (!this.#session) await this.connect();
23706
+ const session = this.#session;
23707
+ if (!session?.endpoints.suggestions) return;
23708
+ if (this.#initialSuggestions) return this.#initialSuggestions.promise;
23709
+ const controller = new AbortController();
23710
+ const clientContext = this.#resolveClientContext();
23711
+ const pageContext = this.#resolvePageContext();
23712
+ const promise2 = this.#request(
23713
+ session.endpoints.suggestions,
23714
+ {
23715
+ method: "POST",
23716
+ headers: authorizedHeaders(session.token, "text/event-stream"),
23717
+ body: JSON.stringify({
23718
+ ...clientContext ? { clientContext } : {},
23719
+ ...pageContext === void 0 ? {} : { pageContext },
23720
+ ...this.#modelContext ? { modelContext: this.#modelContext } : {}
23721
+ }),
23722
+ signal: controller.signal
23723
+ },
23724
+ "turn_failed"
23725
+ ).then(async (response) => {
23726
+ if (response.ok) await this.#consume(response);
23727
+ }).finally(() => {
23728
+ if (this.#initialSuggestions?.controller === controller) {
23729
+ this.#initialSuggestions = void 0;
23730
+ }
23731
+ });
23732
+ this.#initialSuggestions = { controller, promise: promise2 };
23733
+ return promise2;
23734
+ }
23665
23735
  async respond(id, resolution) {
23666
23736
  if (!id) {
23667
23737
  throw clientError("invalid_request", "interaction id is required", false);
23668
23738
  }
23739
+ this.#cancelInitialSuggestions();
23669
23740
  await this.#singleFlight(async (signal) => {
23670
23741
  await this.#runChatOperation(signal, async () => {
23671
23742
  const pendingApp = this.#pendingAppInteractions.get(id);
@@ -23685,6 +23756,7 @@ var DefaultAssistantClient = class {
23685
23756
  const body = modernEndpoint ? {
23686
23757
  id,
23687
23758
  action: resolution.action,
23759
+ ...session.endpoints.suggestions ? { suggestions: true } : {},
23688
23760
  ...resolution.action === "accept" && resolution.content !== void 0 ? { content: resolution.content } : {}
23689
23761
  } : { id };
23690
23762
  this.#emit({ event: "interaction_started", data: { id, action: resolution.action } });
@@ -23763,7 +23835,7 @@ var DefaultAssistantClient = class {
23763
23835
  this.#modelContext = copyAssistantModelContext(update);
23764
23836
  this.#emit({ event: "model_context_changed", data: { modelContext: this.#modelContext } });
23765
23837
  }
23766
- async requestApp(method, params) {
23838
+ async requestApp(method, params, options) {
23767
23839
  const session = this.#session;
23768
23840
  if (!session?.endpoints.apps) {
23769
23841
  throw clientError(
@@ -23777,7 +23849,11 @@ var DefaultAssistantClient = class {
23777
23849
  {
23778
23850
  method: "POST",
23779
23851
  headers: authorizedHeaders(session.token, "application/json"),
23780
- body: JSON.stringify({ method, params })
23852
+ body: JSON.stringify({
23853
+ ...options?.bridge ? { bridge: options.bridge } : {},
23854
+ method,
23855
+ params
23856
+ })
23781
23857
  },
23782
23858
  "app_request_failed"
23783
23859
  );
@@ -23792,6 +23868,7 @@ var DefaultAssistantClient = class {
23792
23868
  const value = await response.json();
23793
23869
  const interaction = parseAppInteraction(value);
23794
23870
  if (!interaction) return value;
23871
+ options?.onSuspended?.();
23795
23872
  return new Promise((resolve2, reject) => {
23796
23873
  const id = interaction.data.id;
23797
23874
  const replaced = this.#pendingAppInteractions.get(id);
@@ -23809,6 +23886,7 @@ var DefaultAssistantClient = class {
23809
23886
  return this.#session?.endpoints.sandbox;
23810
23887
  }
23811
23888
  resetSession() {
23889
+ this.#cancelInitialSuggestions();
23812
23890
  this.#rejectPendingAppInteractions(
23813
23891
  clientError("confirmation_expired", "assistant session is not active", false)
23814
23892
  );
@@ -23817,6 +23895,7 @@ var DefaultAssistantClient = class {
23817
23895
  }
23818
23896
  abort() {
23819
23897
  this.#active?.abort();
23898
+ this.#cancelInitialSuggestions();
23820
23899
  }
23821
23900
  async #sendTurn(message, mayRetry, signal, modelContext) {
23822
23901
  const session = this.#session ?? await this.#createSession(signal);
@@ -23832,7 +23911,8 @@ var DefaultAssistantClient = class {
23832
23911
  message,
23833
23912
  ...clientContext ? { clientContext } : {},
23834
23913
  ...pageContext === void 0 ? {} : { pageContext },
23835
- ...modelContext ? { modelContext } : {}
23914
+ ...modelContext ? { modelContext } : {},
23915
+ ...session.endpoints.suggestions ? { suggestions: true } : {}
23836
23916
  }),
23837
23917
  signal
23838
23918
  },
@@ -24021,6 +24101,9 @@ var DefaultAssistantClient = class {
24021
24101
  this.#active = void 0;
24022
24102
  }
24023
24103
  }
24104
+ #cancelInitialSuggestions() {
24105
+ this.#initialSuggestions?.controller.abort();
24106
+ }
24024
24107
  async #runChatOperation(signal, operation) {
24025
24108
  try {
24026
24109
  await operation();