openmates 0.12.0-alpha.15 → 0.12.0-alpha.16

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.
@@ -41498,13 +41498,27 @@ function isInteractiveQuestionPayload(value) {
41498
41498
  }
41499
41499
  if (payload.type === "swipe") return Array.isArray(payload.cards) && payload.cards.length > 0;
41500
41500
  if (payload.type === "rating") {
41501
- return typeof payload.question === "string" && payload.question.trim().length > 0 && (typeof payload.max === "number" || typeof payload.scale === "number");
41501
+ return typeof payload.question === "string" && payload.question.trim().length > 0 && (typeof payload.max_stars === "number" || typeof payload.max === "number" || typeof payload.scale === "number");
41502
41502
  }
41503
41503
  return false;
41504
41504
  }
41505
41505
  function isQuestionType(value) {
41506
41506
  return value === "choice" || value === "input" || value === "slider" || value === "swipe" || value === "rating";
41507
41507
  }
41508
+ function formatInteractiveQuestionAnswer(question, answer) {
41509
+ const responsePayload = buildResponsePayload(question, answer);
41510
+ const displayText = buildDisplayText(question, answer);
41511
+ const protocol = JSON.stringify(responsePayload, null, 2);
41512
+ return {
41513
+ displayText,
41514
+ messageContent: `${displayText}
41515
+
41516
+ \`\`\`interactive_response
41517
+ ${protocol}
41518
+ \`\`\``,
41519
+ responsePayload
41520
+ };
41521
+ }
41508
41522
  function toWaitingForUserResult(params) {
41509
41523
  return {
41510
41524
  status: "waiting_for_user",
@@ -41514,6 +41528,50 @@ function toWaitingForUserResult(params) {
41514
41528
  question: params.question
41515
41529
  };
41516
41530
  }
41531
+ function buildResponsePayload(question, answer) {
41532
+ return {
41533
+ id: question.id,
41534
+ ...answer
41535
+ };
41536
+ }
41537
+ function buildDisplayText(question, answer) {
41538
+ if (question.type === "choice") {
41539
+ const selection = Array.isArray(answer.selection) ? answer.selection.map(String) : [];
41540
+ const optionsById = new Map((question.options ?? []).map((option) => [option.id, option.text]));
41541
+ const customAnswer = answer.custom_answer == null ? "" : String(answer.custom_answer).trim();
41542
+ return selection.map((id) => customAnswer && isCustomChoiceOption(question, id) ? customAnswer : optionsById.get(id) ?? id).join(", ");
41543
+ }
41544
+ if (question.type === "input") {
41545
+ const values = answer.inputs && typeof answer.inputs === "object" ? answer.inputs : answer.values && typeof answer.values === "object" ? answer.values : answer;
41546
+ return Object.entries(values).filter(([key]) => key !== "id").map(([, value]) => String(value)).filter(Boolean).join("\n");
41547
+ }
41548
+ if (question.type === "slider") {
41549
+ return answer.value == null ? "" : String(answer.value);
41550
+ }
41551
+ if (question.type === "swipe") {
41552
+ const liked = Array.isArray(answer.liked) ? answer.liked.map(String) : [];
41553
+ const cardsById = new Map((question.cards ?? []).map((card) => [card.id, card.text]));
41554
+ return liked.map((id) => cardsById.get(id) ?? id).join(", ");
41555
+ }
41556
+ if (question.type === "rating") {
41557
+ const rating = answer.rating == null ? "" : String(answer.rating);
41558
+ const comment = answer.comment == null ? "" : String(answer.comment).trim();
41559
+ return [rating, comment].filter(Boolean).join("\n");
41560
+ }
41561
+ return "";
41562
+ }
41563
+ function isCustomChoiceOption(question, optionId) {
41564
+ if (question.custom_option_id) return optionId === question.custom_option_id;
41565
+ const optionText = (question.options ?? []).find((option) => option.id === optionId)?.text.trim().toLowerCase() ?? "";
41566
+ return [
41567
+ "i give you my own answer",
41568
+ "my own answer",
41569
+ "own answer",
41570
+ "custom answer",
41571
+ "something else",
41572
+ "other"
41573
+ ].some((pattern) => optionText === pattern || optionText.includes(pattern));
41574
+ }
41517
41575
 
41518
41576
  // src/feedback.ts
41519
41577
  var ASSISTANT_FEEDBACK_THANKS = "Thanks for the feedback!";
@@ -42704,7 +42762,15 @@ async function main() {
42704
42762
  throw new Error(`Unknown command '${command}'. Run 'openmates help'.`);
42705
42763
  }
42706
42764
  function shouldInitializeRedactor(command, subcommand) {
42707
- return command === "chats" && ["new", "send", "incognito"].includes(subcommand ?? "");
42765
+ return command === "chats" && ["new", "send", "answer-interactive", "incognito"].includes(subcommand ?? "");
42766
+ }
42767
+ function parseJsonFlag(value, flagName) {
42768
+ try {
42769
+ return JSON.parse(value);
42770
+ } catch (error) {
42771
+ const message = error instanceof Error ? error.message : String(error);
42772
+ throw new Error(`Invalid JSON for ${flagName}: ${message}`);
42773
+ }
42708
42774
  }
42709
42775
  async function handleChats(client, subcommand, rest, flags, redactor) {
42710
42776
  if (!subcommand || subcommand === "help" || flags.help === true) {
@@ -42838,6 +42904,34 @@ Run 'openmates chats show ` + chatId + "' to check if suggestions have been save
42838
42904
  if (flags.json === true) printJson2(result);
42839
42905
  return;
42840
42906
  }
42907
+ if (subcommand === "answer-interactive") {
42908
+ const chatId = typeof flags.chat === "string" ? flags.chat : void 0;
42909
+ const questionJson = typeof flags["question-json"] === "string" ? flags["question-json"] : void 0;
42910
+ const answerJson = typeof flags["answer-json"] === "string" ? flags["answer-json"] : void 0;
42911
+ if (!chatId || !questionJson || !answerJson) {
42912
+ throw new Error(
42913
+ "Missing interactive answer data. Usage: openmates chats answer-interactive --chat <id> --question-json '<json>' --answer-json '<json>'"
42914
+ );
42915
+ }
42916
+ const question = parseJsonFlag(questionJson, "--question-json");
42917
+ const answer = parseJsonFlag(answerJson, "--answer-json");
42918
+ const formatted = formatInteractiveQuestionAnswer(question, answer);
42919
+ const result = await sendMessageStreaming(
42920
+ client,
42921
+ {
42922
+ message: formatted.messageContent,
42923
+ chatId,
42924
+ incognito: false,
42925
+ json: flags.json === true,
42926
+ autoApproveSubChats: flags["auto-approve"] === true,
42927
+ autoApproveMemories: flags["auto-approve-memories"] === true,
42928
+ piiDetection: flags["no-pii-detection"] !== true
42929
+ },
42930
+ redactor
42931
+ );
42932
+ if (flags.json === true) printJson2(result);
42933
+ return;
42934
+ }
42841
42935
  if (subcommand === "incognito") {
42842
42936
  const message = rest.join(" ").trim();
42843
42937
  if (!message)
@@ -47027,6 +47121,7 @@ function printChatsHelp() {
47027
47121
  openmates chats new <message> [--json] [--auto-approve] [--auto-approve-memories] [--no-pii-detection]
47028
47122
  openmates chats send [--chat <id>] [--incognito] <message> [--json] [--auto-approve] [--auto-approve-memories] [--no-pii-detection]
47029
47123
  openmates chats send --chat <id> --followup <n> [--json] [--auto-approve] [--auto-approve-memories]
47124
+ openmates chats answer-interactive --chat <id> --question-json '<json>' --answer-json '<json>' [--json]
47030
47125
  openmates chats download <chat-id> [--output <path>] [--zip] [--json]
47031
47126
  openmates chats delete <id1> [id2] [id3] ... [--yes]
47032
47127
  openmates chats share [<chat-id>] [--expires <seconds>] [--password <pwd>] [--json]
@@ -47055,6 +47150,11 @@ Options for 'send':
47055
47150
  typing the full message (requires --chat)
47056
47151
  --incognito Send without saving to chat history
47057
47152
 
47153
+ Options for 'answer-interactive':
47154
+ --chat <id> Chat containing the interactive question
47155
+ --question-json The question payload returned by 'chats send --json'
47156
+ --answer-json Structured answer JSON, for example '{"selection":["opt_a"]}'
47157
+
47058
47158
  Options for 'new', 'send', and 'incognito':
47059
47159
  --auto-approve Automatically approve server-requested sub-chat batches.
47060
47160
  Without this, the CLI prompts in the terminal like the web app.
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  getExtForLang,
4
4
  serializeToYaml
5
- } from "./chunk-LVAKDI4C.js";
5
+ } from "./chunk-2L7XCIUT.js";
6
6
  import "./chunk-AXNRPVLE.js";
7
7
  export {
8
8
  getExtForLang,
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  deriveAppUrl,
10
10
  getExtForLang,
11
11
  serializeToYaml
12
- } from "./chunk-LVAKDI4C.js";
12
+ } from "./chunk-2L7XCIUT.js";
13
13
  import "./chunk-AXNRPVLE.js";
14
14
  export {
15
15
  ASSISTANT_FEEDBACK_REPORT_TITLE,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmates",
3
- "version": "0.12.0-alpha.15",
3
+ "version": "0.12.0-alpha.16",
4
4
  "description": "OpenMates CLI and SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",