openmates 0.12.0-alpha.14 → 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.
@@ -41485,7 +41485,12 @@ function isInteractiveQuestionPayload(value) {
41485
41485
  if (!isQuestionType(payload.type)) return false;
41486
41486
  if (typeof payload.id !== "string" || payload.id.trim().length === 0) return false;
41487
41487
  if (payload.type === "choice") {
41488
- return typeof payload.question === "string" && payload.question.trim().length > 0 && Array.isArray(payload.options) && payload.options.length > 0;
41488
+ if (typeof payload.question !== "string" || payload.question.trim().length === 0) return false;
41489
+ if (!Array.isArray(payload.options) || payload.options.length === 0) return false;
41490
+ if (payload.custom_option_id !== void 0) {
41491
+ return typeof payload.custom_option_id === "string" && payload.options.some((option) => option.id === payload.custom_option_id);
41492
+ }
41493
+ return true;
41489
41494
  }
41490
41495
  if (payload.type === "input") return Array.isArray(payload.fields) && payload.fields.length > 0;
41491
41496
  if (payload.type === "slider") {
@@ -41493,13 +41498,27 @@ function isInteractiveQuestionPayload(value) {
41493
41498
  }
41494
41499
  if (payload.type === "swipe") return Array.isArray(payload.cards) && payload.cards.length > 0;
41495
41500
  if (payload.type === "rating") {
41496
- 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");
41497
41502
  }
41498
41503
  return false;
41499
41504
  }
41500
41505
  function isQuestionType(value) {
41501
41506
  return value === "choice" || value === "input" || value === "slider" || value === "swipe" || value === "rating";
41502
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
+ }
41503
41522
  function toWaitingForUserResult(params) {
41504
41523
  return {
41505
41524
  status: "waiting_for_user",
@@ -41509,6 +41528,50 @@ function toWaitingForUserResult(params) {
41509
41528
  question: params.question
41510
41529
  };
41511
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
+ }
41512
41575
 
41513
41576
  // src/feedback.ts
41514
41577
  var ASSISTANT_FEEDBACK_THANKS = "Thanks for the feedback!";
@@ -42699,7 +42762,15 @@ async function main() {
42699
42762
  throw new Error(`Unknown command '${command}'. Run 'openmates help'.`);
42700
42763
  }
42701
42764
  function shouldInitializeRedactor(command, subcommand) {
42702
- 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
+ }
42703
42774
  }
42704
42775
  async function handleChats(client, subcommand, rest, flags, redactor) {
42705
42776
  if (!subcommand || subcommand === "help" || flags.help === true) {
@@ -42833,6 +42904,34 @@ Run 'openmates chats show ` + chatId + "' to check if suggestions have been save
42833
42904
  if (flags.json === true) printJson2(result);
42834
42905
  return;
42835
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
+ }
42836
42935
  if (subcommand === "incognito") {
42837
42936
  const message = rest.join(" ").trim();
42838
42937
  if (!message)
@@ -47022,6 +47121,7 @@ function printChatsHelp() {
47022
47121
  openmates chats new <message> [--json] [--auto-approve] [--auto-approve-memories] [--no-pii-detection]
47023
47122
  openmates chats send [--chat <id>] [--incognito] <message> [--json] [--auto-approve] [--auto-approve-memories] [--no-pii-detection]
47024
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]
47025
47125
  openmates chats download <chat-id> [--output <path>] [--zip] [--json]
47026
47126
  openmates chats delete <id1> [id2] [id3] ... [--yes]
47027
47127
  openmates chats share [<chat-id>] [--expires <seconds>] [--password <pwd>] [--json]
@@ -47050,6 +47150,11 @@ Options for 'send':
47050
47150
  typing the full message (requires --chat)
47051
47151
  --incognito Send without saving to chat history
47052
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
+
47053
47158
  Options for 'new', 'send', and 'incognito':
47054
47159
  --auto-approve Automatically approve server-requested sub-chat batches.
47055
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-YHOUQRWZ.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-YHOUQRWZ.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.14",
3
+ "version": "0.12.0-alpha.16",
4
4
  "description": "OpenMates CLI and SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",