@mulmochat-plugin/form 0.1.0 → 0.1.1

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.
package/README.md CHANGED
@@ -1,96 +1,49 @@
1
- # MulmoChat Plugin Form
1
+ # MulmoChat Plugin
2
2
 
3
- A form plugin for MulmoChat. Creates structured forms to collect user information.
3
+ A plugin for [MulmoChat](https://github.com/receptron/MulmoChat) - a multi-modal voice chat application with OpenAI's GPT-4 Realtime API.
4
4
 
5
- ## Overview
5
+ ## What this plugin does
6
6
 
7
- This plugin provides dynamic form generation with various field types including text, textarea, radio, dropdown, checkbox, date, time, and number fields.
8
-
9
- - **Tailwind CSS 4** for styling
10
- - **TypeScript** for type-safe implementation
11
- - **ESLint** for static analysis
7
+ Creates structured forms to collect user information with various field types.
12
8
 
13
9
  ## Installation
14
10
 
15
- ### Adding to MulmoChat
16
-
17
- 1. Install the plugin:
18
11
  ```bash
19
- cd MulmoChat
20
12
  yarn add @mulmochat-plugin/form
21
13
  ```
22
14
 
23
- 2. Import in MulmoChat's `src/tools/index.ts`:
15
+ ## Usage
16
+
24
17
  ```typescript
25
- import FormPlugin from "@mulmochat-plugin/form";
18
+ import Plugin from "@mulmochat-plugin/form";
26
19
  import "@mulmochat-plugin/form/style.css";
27
20
 
28
21
  // Add to pluginList
29
22
  const pluginList = [
30
23
  // ... other plugins
31
- FormPlugin,
24
+ Plugin,
32
25
  ];
33
26
  ```
34
27
 
35
28
  ## Development
36
29
 
37
- ### Setup
38
-
39
30
  ```bash
31
+ # Install dependencies
40
32
  yarn install
41
- ```
42
-
43
- ### Development Server
44
33
 
45
- ```bash
34
+ # Start dev server (http://localhost:5173/)
46
35
  yarn dev
47
- ```
48
-
49
- Demo page will be available at http://localhost:5173/
50
36
 
51
- ### Build
52
-
53
- ```bash
37
+ # Build
54
38
  yarn build
55
- ```
56
-
57
- ### Type Check
58
39
 
59
- ```bash
40
+ # Type check
60
41
  yarn typecheck
61
- ```
62
-
63
- ### Lint
64
42
 
65
- ```bash
43
+ # Lint
66
44
  yarn lint
67
45
  ```
68
46
 
69
- ## Plugin Structure
70
-
71
- ```
72
- MulmoChatPluginForm/
73
- ├── src/
74
- │ ├── index.ts # Export definitions
75
- │ ├── plugin.ts # Form-specific plugin implementation
76
- │ ├── types.ts # Re-exports common types (backward compat)
77
- │ ├── style.css # Tailwind CSS entry
78
- │ ├── common/ # Plugin-agnostic shared code
79
- │ │ ├── index.ts # Common exports
80
- │ │ └── types.ts # ToolPlugin, ToolResult, etc.
81
- │ ├── views/
82
- │ │ └── FormView.vue # Form-specific view component
83
- │ └── previews/
84
- │ └── FormPreview.vue # Form-specific preview
85
- ├── demo/ # Generic plugin demo
86
- │ ├── App.vue
87
- │ └── main.ts
88
- ├── package.json
89
- ├── vite.config.ts
90
- ├── tsconfig.json
91
- └── eslint.config.js
92
- ```
93
-
94
47
  ## License
95
48
 
96
49
  MIT
@@ -12,6 +12,8 @@ export interface ToolContext {
12
12
  currentResult?: ToolResult<unknown> | null;
13
13
  userPreferences?: Record<string, unknown>;
14
14
  getPluginConfig?: <T = unknown>(key: string) => T | undefined;
15
+ /** Backend API functions provided by the host app */
16
+ app?: Record<string, (...args: any[]) => any>;
15
17
  }
16
18
  /**
17
19
  * Result returned from plugin execution
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),M={class:"w-full h-full overflow-y-auto p-8"},q={key:0,class:"max-w-3xl w-full mx-auto"},A={key:0,class:"text-gray-900 text-3xl font-bold mb-4 text-center"},R={key:1,class:"text-gray-600 text-center mb-8 text-lg"},T={key:2,class:"bg-red-50 border-2 border-red-500 rounded-lg p-4 mb-6",role:"alert"},U={class:"text-red-700 space-y-1"},z=["href","onClick"],O=["id"],j=["for"],I={key:0,class:"text-red-500 ml-1","aria-label":"required"},P={key:0,class:"text-gray-600 text-sm mb-2"},Y=["id","onUpdate:modelValue","placeholder","aria-invalid","aria-describedby","onBlur","onInput"],H=["id","onUpdate:modelValue","placeholder","rows","aria-invalid","aria-describedby","onBlur","onInput"],J=["id","onUpdate:modelValue","min","max","step","aria-invalid","aria-describedby","onBlur","onInput"],W=["id","onUpdate:modelValue","min","max","aria-invalid","aria-describedby","onBlur","onChange"],G=["id","onUpdate:modelValue","aria-invalid","aria-describedby","onBlur","onChange"],K=["aria-invalid","aria-describedby"],Q=["name","value","onUpdate:modelValue","onChange","onBlur"],X={class:"text-gray-800"},Z=["id","onUpdate:modelValue","aria-invalid","aria-describedby","onBlur","onChange"],ee=["value"],te=["aria-invalid","aria-describedby"],re=["value","onUpdate:modelValue","onChange","onBlur"],ae={class:"text-gray-800"},oe=["id"],ne={key:0},ie={class:"mt-8 flex justify-center"},se=["disabled"],le={class:"mt-4 text-center text-gray-600 text-sm"},de=t.defineComponent({__name:"FormView",props:{selectedResult:{},sendTextMessage:{type:Function}},emits:["updateResult"],setup(x,{emit:v}){const c=x,b=v,d=t.ref(null),s=t.ref({}),i=t.ref(new Set),p=t.ref(new Map),m=t.ref(!1),k=t.ref(!1),h=t.ref(!1);t.watch(()=>c.selectedResult,(a,n)=>{if(a?.toolName==="presentForm"&&a.jsonData&&(!n||!n.jsonData||n.uuid!==a.uuid||n.jsonData!==a.jsonData)){if(h.value=!0,d.value=a.jsonData,s.value={},d.value.fields.forEach(o=>{s.value[o.id]=r(o)}),a.viewState){const o=a.viewState;o.userResponses&&Object.assign(s.value,o.userResponses),o.touched&&(i.value=new Set(o.touched),o.touched.forEach(u=>{V(u)})),o.submitted!==void 0&&(m.value=o.submitted)}h.value=!1}},{immediate:!0}),t.watch([s,i,m],()=>{if(h.value||!c.selectedResult)return;const a={...c.selectedResult,viewState:{userResponses:{...s.value},touched:Array.from(i.value),submitted:m.value}};b("updateResult",a)},{deep:!0});function r(a){const n=a;if(n.defaultValue!==void 0)switch(a.type){case"radio":case"dropdown":{const e=a.choices.indexOf(n.defaultValue);return e!==-1?e:null}case"checkbox":return Array.isArray(n.defaultValue)?n.defaultValue.map(e=>a.choices.indexOf(e)).filter(e=>e!==-1):[];default:return n.defaultValue}switch(a.type){case"text":case"textarea":return"";case"number":return a.min!==void 0?a.min:0;case"date":case"time":return"";case"radio":case"dropdown":return null;case"checkbox":return[];default:return null}}function g(a){return a==null?!0:typeof a=="string"?a.trim()==="":Array.isArray(a)?a.length===0:!1}function S(a){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a)}function _(a){try{return new URL(a),!0}catch{return!1}}function B(a){return/^[\d\s\-+()]+$/.test(a)&&a.replace(/\D/g,"").length>=10}function D(a,n){if(a.required&&g(n))return`${a.label} is required`;if(g(n))return null;switch(a.type){case"text":{const e=a;if(e.validation==="email"&&!S(n))return"Please enter a valid email address";if(e.validation==="url"&&!_(n))return"Please enter a valid URL";if(e.validation==="phone"&&!B(n))return"Please enter a valid phone number";if(typeof e.validation=="string"&&e.validation!=="email"&&e.validation!=="url"&&e.validation!=="phone")try{if(!new RegExp(e.validation).test(n))return`${a.label} format is invalid`}catch{console.warn(`Invalid regex pattern: ${e.validation}`)}break}case"textarea":{const e=a;if(e.minLength&&n.length<e.minLength)return`Must be at least ${e.minLength} characters (currently ${n.length})`;if(e.maxLength&&n.length>e.maxLength)return`Must be no more than ${e.maxLength} characters (currently ${n.length})`;break}case"number":{const e=a;if(e.min!==void 0&&n<e.min)return`Must be at least ${e.min}`;if(e.max!==void 0&&n>e.max)return`Must be no more than ${e.max}`;break}case"date":{const e=a;if(e.minDate&&n<e.minDate)return`Date must be on or after ${e.minDate}`;if(e.maxDate&&n>e.maxDate)return`Date must be on or before ${e.maxDate}`;break}case"checkbox":{const e=a,o=n?.length||0;if(e.minSelections&&o<e.minSelections)return`Please select at least ${e.minSelections} option${e.minSelections>1?"s":""}`;if(e.maxSelections&&o>e.maxSelections)return`Please select no more than ${e.maxSelections} option${e.maxSelections>1?"s":""}`;break}}return null}function V(a){const n=d.value?.fields.find(u=>u.id===a);if(!n)return!0;const e=s.value[a],o=D(n,e);return o?(p.value.set(a,{fieldId:a,message:o,type:"custom"}),!1):(p.value.delete(a),!0)}function y(a){i.value.add(a),V(a)}function f(a){i.value.has(a)&&V(a)}function l(a){return p.value.has(a)}function E(a){const n=document.getElementById(`input-${a}`);n&&(n.focus(),n.scrollIntoView({behavior:"smooth",block:"center"}))}function F(a){return(a.type==="text"||a.type==="textarea")&&a.maxLength!==void 0}function $(a){if(a.type!=="text"&&a.type!=="textarea")return!1;const n=a.maxLength;return n?(s.value[a.id]||"").length/n>.9:!1}const N=t.computed(()=>d.value?.fields.filter(a=>a.required).length||0),C=t.computed(()=>d.value?d.value.fields.filter(a=>a.required&&!g(s.value[a.id])).length:0);function L(){if(m.value)return;if(d.value?.fields.forEach(e=>{i.value.add(e.id),V(e.id)}),p.value.size>0){k.value=!0;const e=Array.from(p.value.keys())[0];E(e);return}const a={};d.value?.fields.forEach(e=>{const o=s.value[e.id];e.type==="radio"||e.type==="dropdown"?o!=null?a[e.id]=e.choices[o]:a[e.id]=null:e.type==="checkbox"?a[e.id]=(o||[]).map(u=>e.choices[u]):a[e.id]=o});const n=JSON.stringify({formSubmission:{formTitle:d.value?.title||"Form",responses:a}},null,2);m.value=!0,c.sendTextMessage(n)}return(a,n)=>(t.openBlock(),t.createElementBlock("div",M,[d.value?(t.openBlock(),t.createElementBlock("div",q,[d.value.title?(t.openBlock(),t.createElementBlock("h2",A,t.toDisplayString(d.value.title),1)):t.createCommentVNode("",!0),d.value.description?(t.openBlock(),t.createElementBlock("p",R,t.toDisplayString(d.value.description),1)):t.createCommentVNode("",!0),k.value&&p.value.size>0?(t.openBlock(),t.createElementBlock("div",T,[n[0]||(n[0]=t.createElementVNode("h3",{class:"text-red-800 font-semibold mb-2 flex items-center gap-2"},[t.createElementVNode("svg",{class:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20","aria-hidden":"true"},[t.createElementVNode("path",{"fill-rule":"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z","clip-rule":"evenodd"})]),t.createTextVNode(" Please fix the following errors: ")],-1)),t.createElementVNode("ul",U,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(p.value,([e,o])=>(t.openBlock(),t.createElementBlock("li",{key:e},[t.createElementVNode("a",{href:`#${e}`,onClick:t.withModifiers(u=>E(e),["prevent"]),class:"hover:underline cursor-pointer"},t.toDisplayString(o.message),9,z)]))),128))])])):t.createCommentVNode("",!0),t.createElementVNode("form",{onSubmit:t.withModifiers(L,["prevent"]),class:"space-y-6"},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(d.value.fields,e=>(t.openBlock(),t.createElementBlock("div",{key:e.id,id:e.id,class:t.normalizeClass(["form-field",{"has-error":l(e.id)&&i.value.has(e.id)}])},[t.createElementVNode("label",{for:`input-${e.id}`,class:t.normalizeClass(["block text-gray-800 font-semibold mb-2",{"text-red-600":l(e.id)&&i.value.has(e.id)}])},[t.createTextVNode(t.toDisplayString(e.label)+" ",1),e.required?(t.openBlock(),t.createElementBlock("span",I,"*")):t.createCommentVNode("",!0)],10,j),e.description?(t.openBlock(),t.createElementBlock("p",P,t.toDisplayString(e.description),1)):t.createCommentVNode("",!0),e.type==="text"?t.withDirectives((t.openBlock(),t.createElementBlock("input",{key:1,id:`input-${e.id}`,"onUpdate:modelValue":o=>s.value[e.id]=o,type:"text",placeholder:e.placeholder,"aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0,onBlur:o=>y(e.id),onInput:o=>f(e.id),class:t.normalizeClass(["w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors",{"border-red-500 focus:ring-red-500":l(e.id)&&i.value.has(e.id),"border-gray-300":!l(e.id)||!i.value.has(e.id)}])},null,42,Y)),[[t.vModelText,s.value[e.id]]]):e.type==="textarea"?t.withDirectives((t.openBlock(),t.createElementBlock("textarea",{key:2,id:`input-${e.id}`,"onUpdate:modelValue":o=>s.value[e.id]=o,placeholder:e.placeholder,rows:e.rows||4,"aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0,onBlur:o=>y(e.id),onInput:o=>f(e.id),class:t.normalizeClass(["w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors resize-y",{"border-red-500 focus:ring-red-500":l(e.id)&&i.value.has(e.id),"border-gray-300":!l(e.id)||!i.value.has(e.id)}])},null,42,H)),[[t.vModelText,s.value[e.id]]]):e.type==="number"?t.withDirectives((t.openBlock(),t.createElementBlock("input",{key:3,id:`input-${e.id}`,"onUpdate:modelValue":o=>s.value[e.id]=o,type:"number",min:e.min,max:e.max,step:e.step,"aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0,onBlur:o=>y(e.id),onInput:o=>f(e.id),class:t.normalizeClass(["w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors",{"border-red-500 focus:ring-red-500":l(e.id)&&i.value.has(e.id),"border-gray-300":!l(e.id)||!i.value.has(e.id)}])},null,42,J)),[[t.vModelText,s.value[e.id],void 0,{number:!0}]]):e.type==="date"?t.withDirectives((t.openBlock(),t.createElementBlock("input",{key:4,id:`input-${e.id}`,"onUpdate:modelValue":o=>s.value[e.id]=o,type:"date",min:e.minDate,max:e.maxDate,"aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0,onBlur:o=>y(e.id),onChange:o=>f(e.id),class:t.normalizeClass(["w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors",{"border-red-500 focus:ring-red-500":l(e.id)&&i.value.has(e.id),"border-gray-300":!l(e.id)||!i.value.has(e.id)}])},null,42,W)),[[t.vModelText,s.value[e.id]]]):e.type==="time"?t.withDirectives((t.openBlock(),t.createElementBlock("input",{key:5,id:`input-${e.id}`,"onUpdate:modelValue":o=>s.value[e.id]=o,type:"time","aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0,onBlur:o=>y(e.id),onChange:o=>f(e.id),class:t.normalizeClass(["w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors",{"border-red-500 focus:ring-red-500":l(e.id)&&i.value.has(e.id),"border-gray-300":!l(e.id)||!i.value.has(e.id)}])},null,42,G)),[[t.vModelText,s.value[e.id]]]):e.type==="radio"?(t.openBlock(),t.createElementBlock("div",{key:6,class:"space-y-2",role:"radiogroup","aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.choices,(o,u)=>(t.openBlock(),t.createElementBlock("label",{key:u,class:t.normalizeClass(["flex items-center p-3 border-2 border-gray-300 rounded-lg cursor-pointer transition-all hover:bg-gray-50",{"border-blue-500 bg-blue-50":s.value[e.id]===u,"border-gray-300":s.value[e.id]!==u}])},[t.withDirectives(t.createElementVNode("input",{type:"radio",name:e.id,value:u,"onUpdate:modelValue":w=>s.value[e.id]=w,onChange:w=>f(e.id),onBlur:w=>y(e.id),class:"mr-3 h-4 w-4 flex-shrink-0"},null,40,Q),[[t.vModelRadio,s.value[e.id]]]),t.createElementVNode("span",X,t.toDisplayString(o),1)],2))),128))],8,K)):e.type==="dropdown"?t.withDirectives((t.openBlock(),t.createElementBlock("select",{key:7,id:`input-${e.id}`,"onUpdate:modelValue":o=>s.value[e.id]=o,"aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0,onBlur:o=>y(e.id),onChange:o=>f(e.id),class:t.normalizeClass(["w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors bg-white",{"border-red-500 focus:ring-red-500":l(e.id)&&i.value.has(e.id),"border-gray-300":!l(e.id)||!i.value.has(e.id)}])},[n[1]||(n[1]=t.createElementVNode("option",{value:null,disabled:""},"Select an option...",-1)),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.choices,(o,u)=>(t.openBlock(),t.createElementBlock("option",{key:u,value:u},t.toDisplayString(o),9,ee))),128))],42,Z)),[[t.vModelSelect,s.value[e.id]]]):e.type==="checkbox"?(t.openBlock(),t.createElementBlock("div",{key:8,class:"space-y-2",role:"group","aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.choices,(o,u)=>(t.openBlock(),t.createElementBlock("label",{key:u,class:t.normalizeClass(["flex items-center p-3 border-2 border-gray-300 rounded-lg cursor-pointer transition-all hover:bg-gray-50",{"border-blue-500 bg-blue-50":(s.value[e.id]||[]).includes(u),"border-gray-300":!(s.value[e.id]||[]).includes(u)}])},[t.withDirectives(t.createElementVNode("input",{type:"checkbox",value:u,"onUpdate:modelValue":w=>s.value[e.id]=w,onChange:w=>f(e.id),onBlur:w=>y(e.id),class:"mr-3 h-4 w-4 flex-shrink-0"},null,40,re),[[t.vModelCheckbox,s.value[e.id]]]),t.createElementVNode("span",ae,t.toDisplayString(o),1)],2))),128))],8,te)):t.createCommentVNode("",!0),l(e.id)&&i.value.has(e.id)?(t.openBlock(),t.createElementBlock("div",{key:9,id:`${e.id}-error`,class:"flex items-center gap-2 mt-2 text-red-600 text-sm",role:"alert"},[n[2]||(n[2]=t.createElementVNode("svg",{class:"w-4 h-4 flex-shrink-0",fill:"currentColor",viewBox:"0 0 20 20","aria-hidden":"true"},[t.createElementVNode("path",{"fill-rule":"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z","clip-rule":"evenodd"})],-1)),t.createTextVNode(" "+t.toDisplayString(p.value.get(e.id)?.message),1)],8,oe)):t.createCommentVNode("",!0),F(e)?(t.openBlock(),t.createElementBlock("div",{key:10,class:t.normalizeClass(["text-sm mt-2",{"text-amber-600 font-semibold":$(e),"text-gray-500":!$(e)}])},[t.createTextVNode(t.toDisplayString((s.value[e.id]||"").length)+" ",1),e.maxLength?(t.openBlock(),t.createElementBlock("span",ne," / "+t.toDisplayString(e.maxLength),1)):t.createCommentVNode("",!0),n[3]||(n[3]=t.createTextVNode(" characters ",-1))],2)):t.createCommentVNode("",!0)],10,O))),128)),t.createElementVNode("div",ie,[t.createElementVNode("button",{type:"submit",disabled:m.value,class:t.normalizeClass([m.value?"bg-green-600 cursor-default":"bg-blue-600 hover:bg-blue-700","px-8 py-3 rounded-lg text-white font-semibold text-lg transition-colors"])},t.toDisplayString(m.value?"Submitted":"Submit Form"),11,se)]),t.createElementVNode("div",le,t.toDisplayString(C.value)+" / "+t.toDisplayString(N.value)+" required fields completed ",1)],32)])):t.createCommentVNode("",!0)]))}}),ce=(x,v)=>{const c=x.__vccOpts||x;for(const[b,d]of v)c[b]=d;return c},ue=ce(de,[["__scopeId","data-v-2615e49a"]]),me={class:"w-full h-full flex flex-col items-center justify-center p-4 bg-gradient-to-br from-blue-50 to-indigo-50 rounded-lg border-2 border-gray-200"},pe={class:"text-center"},he={class:"text-gray-900 font-bold text-lg mb-1 line-clamp-2"},ve={class:"text-gray-600 text-sm mb-2"},ge={key:0,class:"flex items-center justify-center gap-2"},be={class:"w-32 h-2 bg-gray-200 rounded-full overflow-hidden"},ye={class:"text-xs text-gray-500"},fe={key:1,class:"inline-flex items-center gap-1 px-3 py-1 bg-green-100 text-green-700 rounded-full text-xs font-semibold"},xe=t.defineComponent({__name:"FormPreview",props:{result:{}},setup(x){const v=x,c=t.computed(()=>v.result?.toolName==="presentForm"?v.result.jsonData:null),b=t.computed(()=>v.result?.viewState||null),d=t.computed(()=>c.value?.fields.length||0),s=t.computed(()=>b.value?.submitted||!1),i=t.computed(()=>{if(!c.value||s.value)return 100;const p=c.value.fields.filter(h=>h.required);if(p.length===0)return 0;const m=b.value?.userResponses||{},k=p.filter(h=>{const r=m[h.id];return r==null?!1:typeof r=="string"?r.trim()!=="":Array.isArray(r)?r.length>0:!0}).length;return Math.round(k/p.length*100)});return(p,m)=>(t.openBlock(),t.createElementBlock("div",me,[t.createElementVNode("div",pe,[m[1]||(m[1]=t.createElementVNode("svg",{class:"w-12 h-12 mx-auto mb-3 text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1)),t.createElementVNode("h3",he,t.toDisplayString(c.value?.title||"Form"),1),t.createElementVNode("p",ve,t.toDisplayString(d.value)+" field"+t.toDisplayString(d.value!==1?"s":""),1),s.value?(t.openBlock(),t.createElementBlock("div",fe,[...m[0]||(m[0]=[t.createElementVNode("svg",{class:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20"},[t.createElementVNode("path",{"fill-rule":"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z","clip-rule":"evenodd"})],-1),t.createTextVNode(" Submitted ",-1)])])):(t.openBlock(),t.createElementBlock("div",ge,[t.createElementVNode("div",be,[t.createElementVNode("div",{class:"h-full bg-blue-600 transition-all duration-300",style:t.normalizeStyle({width:`${i.value}%`})},null,4)]),t.createElementVNode("span",ye,t.toDisplayString(i.value)+"%",1)]))])]))}}),we="presentForm",ke=[{name:"Contact Form",args:{title:"Contact Us",description:"Please fill out the form below to get in touch.",fields:[{id:"name",type:"text",label:"Full Name",required:!0,placeholder:"John Doe"},{id:"email",type:"text",label:"Email Address",required:!0,placeholder:"john@example.com",validation:"email"},{id:"subject",type:"dropdown",label:"Subject",choices:["General Inquiry","Technical Support","Sales","Feedback"],required:!0},{id:"message",type:"textarea",label:"Message",required:!0,minLength:10,maxLength:500,rows:5}]}},{name:"Survey Form",args:{title:"Customer Satisfaction Survey",fields:[{id:"satisfaction",type:"radio",label:"How satisfied are you with our service?",choices:["Very Satisfied","Satisfied","Neutral","Dissatisfied","Very Dissatisfied"],required:!0},{id:"features",type:"checkbox",label:"Which features do you use most?",choices:["Dashboard","Reports","Analytics","API","Integrations"],minSelections:1,maxSelections:3},{id:"recommendation",type:"number",label:"How likely are you to recommend us? (0-10)",min:0,max:10,step:1}]}},{name:"Event Registration",args:{title:"Event Registration",description:"Register for our upcoming conference.",fields:[{id:"attendeeName",type:"text",label:"Attendee Name",required:!0},{id:"eventDate",type:"date",label:"Preferred Date",required:!0,minDate:"2025-01-01",maxDate:"2025-12-31"},{id:"sessionTime",type:"time",label:"Session Time",format:"12hr"},{id:"dietaryRestrictions",type:"checkbox",label:"Dietary Restrictions",choices:["Vegetarian","Vegan","Gluten-Free","Halal","Kosher"]}]}}],Ve={type:"function",name:we,description:"Create a structured form to collect information from the user. Supports various field types including text input, textarea, multiple choice (radio), dropdown menus, checkboxes, date/time pickers, and number inputs. Each field can have validation rules and help text.",parameters:{type:"object",properties:{title:{type:"string",description:"Optional title for the form (e.g., 'User Registration')"},description:{type:"string",description:"Optional description explaining the purpose of the form"},fields:{type:"array",description:"Array of form fields with various types and configurations",items:{type:"object",properties:{id:{type:"string",description:"Unique identifier for the field (e.g., 'email', 'birthdate'). This will be the key in the JSON response. Use descriptive camelCase or snake_case names."},type:{type:"string",enum:["text","textarea","radio","dropdown","checkbox","date","time","number"],description:"Field type: 'text' for short text, 'textarea' for long text, 'radio' for 2-6 choices, 'dropdown' for many choices, 'checkbox' for multiple selections, 'date' for date picker, 'time' for time picker, 'number' for numeric input"},label:{type:"string",description:"Field label shown to the user"},description:{type:"string",description:"Optional help text explaining the field"},required:{type:"boolean",description:"Whether the field is required (default: false)"},placeholder:{type:"string",description:"Placeholder text for text/textarea fields"},validation:{type:"string",description:"For text fields: 'email', 'url', 'phone', or a regex pattern"},minLength:{type:"number",description:"Minimum character length for textarea fields"},maxLength:{type:"number",description:"Maximum character length for textarea fields"},rows:{type:"number",description:"Number of visible rows for textarea (default: 4)"},choices:{type:"array",items:{type:"string"},description:"Array of choices for radio/dropdown/checkbox fields. Radio should have 2-6 choices, dropdown for 7+ choices."},searchable:{type:"boolean",description:"Make dropdown searchable (for large lists)"},minSelections:{type:"number",description:"Minimum number of selections for checkbox fields"},maxSelections:{type:"number",description:"Maximum number of selections for checkbox fields"},minDate:{type:"string",description:"Minimum date (ISO format: YYYY-MM-DD)"},maxDate:{type:"string",description:"Maximum date (ISO format: YYYY-MM-DD)"},format:{type:"string",description:"Format for time fields: '12hr' or '24hr'"},min:{type:"number",description:"Minimum value for number fields"},max:{type:"number",description:"Maximum value for number fields"},step:{type:"number",description:"Step increment for number fields"},defaultValue:{description:"Optional default/pre-filled value for the field. Type varies by field: string for text/textarea/radio/dropdown/date/time, number for number fields, array of strings for checkbox fields. For radio/dropdown, must be one of the choices. For checkbox, must be a subset of choices."}},required:["id","type","label"]},minItems:1}},required:["fields"]}},Ee=async(x,v)=>{try{const{title:c,description:b,fields:d}=v;if(!d||!Array.isArray(d)||d.length===0)throw new Error("At least one field is required");const s=new Set;for(let h=0;h<d.length;h++){const r=d[h];if(!r.id||typeof r.id!="string")throw new Error(`Field ${h+1} must have a valid 'id' property`);if(!r.type||typeof r.type!="string")throw new Error(`Field ${h+1} must have a valid 'type' property`);if(!r.label||typeof r.label!="string")throw new Error(`Field ${h+1} must have a valid 'label' property`);if(s.has(r.id))throw new Error(`Duplicate field ID: '${r.id}'`);switch(s.add(r.id),r.type){case"text":case"textarea":if(r.minLength!==void 0&&r.maxLength!==void 0&&r.minLength>r.maxLength)throw new Error(`Field '${r.id}': minLength cannot be greater than maxLength`);break;case"radio":if(!Array.isArray(r.choices)||r.choices.length<2)throw new Error(`Field '${r.id}': radio fields must have at least 2 choices`);r.choices.length>6&&console.warn(`Field '${r.id}': radio fields with more than 6 choices should use 'dropdown' type instead`);break;case"dropdown":case"checkbox":if(!Array.isArray(r.choices)||r.choices.length<1)throw new Error(`Field '${r.id}': ${r.type} fields must have at least 1 choice`);break;case"number":if(r.min!==void 0&&r.max!==void 0&&r.min>r.max)throw new Error(`Field '${r.id}': min cannot be greater than max`);break;case"date":if(r.minDate&&r.maxDate&&r.minDate>r.maxDate)throw new Error(`Field '${r.id}': minDate cannot be after maxDate`);break;case"time":break;default:{const g=r;throw new Error(`Field '${g.id}': unknown field type '${g.type}'`)}}if(r.type==="checkbox"){if(r.minSelections!==void 0&&r.maxSelections!==void 0&&r.minSelections>r.maxSelections)throw new Error(`Field '${r.id}': minSelections cannot be greater than maxSelections`);if(r.maxSelections!==void 0&&r.maxSelections>r.choices.length)throw new Error(`Field '${r.id}': maxSelections cannot exceed number of choices`)}if(r.defaultValue!==void 0)switch(r.type){case"text":case"textarea":if(typeof r.defaultValue!="string")throw new Error(`Field '${r.id}': defaultValue must be a string`);if(r.minLength!==void 0&&r.defaultValue.length<r.minLength)throw new Error(`Field '${r.id}': defaultValue length is less than minLength`);if(r.maxLength!==void 0&&r.defaultValue.length>r.maxLength)throw new Error(`Field '${r.id}': defaultValue length exceeds maxLength`);break;case"radio":case"dropdown":if(typeof r.defaultValue!="string")throw new Error(`Field '${r.id}': defaultValue must be a string`);if(!r.choices.includes(r.defaultValue))throw new Error(`Field '${r.id}': defaultValue '${r.defaultValue}' is not in choices`);break;case"checkbox":if(!Array.isArray(r.defaultValue))throw new Error(`Field '${r.id}': defaultValue must be an array`);for(const g of r.defaultValue)if(!r.choices.includes(g))throw new Error(`Field '${r.id}': defaultValue contains '${g}' which is not in choices`);if(r.minSelections!==void 0&&r.defaultValue.length<r.minSelections)throw new Error(`Field '${r.id}': defaultValue has fewer selections than minSelections`);if(r.maxSelections!==void 0&&r.defaultValue.length>r.maxSelections)throw new Error(`Field '${r.id}': defaultValue has more selections than maxSelections`);break;case"number":if(typeof r.defaultValue!="number")throw new Error(`Field '${r.id}': defaultValue must be a number`);if(r.min!==void 0&&r.defaultValue<r.min)throw new Error(`Field '${r.id}': defaultValue is less than min`);if(r.max!==void 0&&r.defaultValue>r.max)throw new Error(`Field '${r.id}': defaultValue is greater than max`);break;case"date":if(typeof r.defaultValue!="string")throw new Error(`Field '${r.id}': defaultValue must be a string (ISO date format)`);if(r.minDate!==void 0&&r.defaultValue<r.minDate)throw new Error(`Field '${r.id}': defaultValue is before minDate`);if(r.maxDate!==void 0&&r.defaultValue>r.maxDate)throw new Error(`Field '${r.id}': defaultValue is after maxDate`);break;case"time":if(typeof r.defaultValue!="string")throw new Error(`Field '${r.id}': defaultValue must be a string`);break}}const i={title:c,description:b,fields:d},p=`${d.length} field${d.length>1?"s":""}`,m=c?`: ${c}`:"";return{message:`Form created with ${p}${m}`,jsonData:i,instructions:"The form has been presented to the user. Wait for the user to fill out and submit the form. They will send their responses as a JSON message."}}catch(c){return console.error(`ERR: exception
2
- Form creation error`,c),{message:`Form error: ${c instanceof Error?c.message:"Unknown error"}`,instructions:"Acknowledge that there was an error creating the form and suggest trying again with corrected field definitions."}}},$e={toolDefinition:Ve,execute:Ee,generatingMessage:"Preparing form...",isEnabled:()=>!0,viewComponent:ue,previewComponent:xe,samples:ke},Se={plugin:$e};exports.default=Se;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),M="presentForm",q={type:"function",name:M,description:"Create a structured form to collect information from the user. Supports various field types including text input, textarea, multiple choice (radio), dropdown menus, checkboxes, date/time pickers, and number inputs. Each field can have validation rules and help text.",parameters:{type:"object",properties:{title:{type:"string",description:"Optional title for the form (e.g., 'User Registration')"},description:{type:"string",description:"Optional description explaining the purpose of the form"},fields:{type:"array",description:"Array of form fields with various types and configurations",items:{type:"object",properties:{id:{type:"string",description:"Unique identifier for the field (e.g., 'email', 'birthdate'). This will be the key in the JSON response. Use descriptive camelCase or snake_case names."},type:{type:"string",enum:["text","textarea","radio","dropdown","checkbox","date","time","number"],description:"Field type: 'text' for short text, 'textarea' for long text, 'radio' for 2-6 choices, 'dropdown' for many choices, 'checkbox' for multiple selections, 'date' for date picker, 'time' for time picker, 'number' for numeric input"},label:{type:"string",description:"Field label shown to the user"},description:{type:"string",description:"Optional help text explaining the field"},required:{type:"boolean",description:"Whether the field is required (default: false)"},placeholder:{type:"string",description:"Placeholder text for text/textarea fields"},validation:{type:"string",description:"For text fields: 'email', 'url', 'phone', or a regex pattern"},minLength:{type:"number",description:"Minimum character length for textarea fields"},maxLength:{type:"number",description:"Maximum character length for textarea fields"},rows:{type:"number",description:"Number of visible rows for textarea (default: 4)"},choices:{type:"array",items:{type:"string"},description:"Array of choices for radio/dropdown/checkbox fields. Radio should have 2-6 choices, dropdown for 7+ choices."},searchable:{type:"boolean",description:"Make dropdown searchable (for large lists)"},minSelections:{type:"number",description:"Minimum number of selections for checkbox fields"},maxSelections:{type:"number",description:"Maximum number of selections for checkbox fields"},minDate:{type:"string",description:"Minimum date (ISO format: YYYY-MM-DD)"},maxDate:{type:"string",description:"Maximum date (ISO format: YYYY-MM-DD)"},format:{type:"string",description:"Format for time fields: '12hr' or '24hr'"},min:{type:"number",description:"Minimum value for number fields"},max:{type:"number",description:"Maximum value for number fields"},step:{type:"number",description:"Step increment for number fields"},defaultValue:{description:"Optional default/pre-filled value for the field. Type varies by field: string for text/textarea/radio/dropdown/date/time, number for number fields, array of strings for checkbox fields. For radio/dropdown, must be one of the choices. For checkbox, must be a subset of choices."}},required:["id","type","label"]},minItems:1}},required:["fields"]}},A=[{name:"Contact Form",args:{title:"Contact Us",description:"Please fill out the form below to get in touch.",fields:[{id:"name",type:"text",label:"Full Name",required:!0,placeholder:"John Doe"},{id:"email",type:"text",label:"Email Address",required:!0,placeholder:"john@example.com",validation:"email"},{id:"subject",type:"dropdown",label:"Subject",choices:["General Inquiry","Technical Support","Sales","Feedback"],required:!0},{id:"message",type:"textarea",label:"Message",required:!0,minLength:10,maxLength:500,rows:5}]}},{name:"Survey Form",args:{title:"Customer Satisfaction Survey",fields:[{id:"satisfaction",type:"radio",label:"How satisfied are you with our service?",choices:["Very Satisfied","Satisfied","Neutral","Dissatisfied","Very Dissatisfied"],required:!0},{id:"features",type:"checkbox",label:"Which features do you use most?",choices:["Dashboard","Reports","Analytics","API","Integrations"],minSelections:1,maxSelections:3},{id:"recommendation",type:"number",label:"How likely are you to recommend us? (0-10)",min:0,max:10,step:1}]}},{name:"Event Registration",args:{title:"Event Registration",description:"Register for our upcoming conference.",fields:[{id:"attendeeName",type:"text",label:"Attendee Name",required:!0},{id:"eventDate",type:"date",label:"Preferred Date",required:!0,minDate:"2025-01-01",maxDate:"2025-12-31"},{id:"sessionTime",type:"time",label:"Session Time",format:"12hr"},{id:"dietaryRestrictions",type:"checkbox",label:"Dietary Restrictions",choices:["Vegetarian","Vegan","Gluten-Free","Halal","Kosher"]}]}}],R={class:"w-full h-full overflow-y-auto p-8"},T={key:0,class:"max-w-3xl w-full mx-auto"},U={key:0,class:"text-gray-900 text-3xl font-bold mb-4 text-center"},z={key:1,class:"text-gray-600 text-center mb-8 text-lg"},O={key:2,class:"bg-red-50 border-2 border-red-500 rounded-lg p-4 mb-6",role:"alert"},j={class:"text-red-700 space-y-1"},I=["href","onClick"],P=["id"],Y=["for"],H={key:0,class:"text-red-500 ml-1","aria-label":"required"},J={key:0,class:"text-gray-600 text-sm mb-2"},W=["id","onUpdate:modelValue","placeholder","aria-invalid","aria-describedby","onBlur","onInput"],G=["id","onUpdate:modelValue","placeholder","rows","aria-invalid","aria-describedby","onBlur","onInput"],K=["id","onUpdate:modelValue","min","max","step","aria-invalid","aria-describedby","onBlur","onInput"],Q=["id","onUpdate:modelValue","min","max","aria-invalid","aria-describedby","onBlur","onChange"],X=["id","onUpdate:modelValue","aria-invalid","aria-describedby","onBlur","onChange"],Z=["aria-invalid","aria-describedby"],ee=["name","value","onUpdate:modelValue","onChange","onBlur"],te={class:"text-gray-800"},re=["id","onUpdate:modelValue","aria-invalid","aria-describedby","onBlur","onChange"],ae=["value"],oe=["aria-invalid","aria-describedby"],ne=["value","onUpdate:modelValue","onChange","onBlur"],ie={class:"text-gray-800"},se=["id"],le={key:0},de={class:"mt-8 flex justify-center"},ce=["disabled"],ue={class:"mt-4 text-center text-gray-600 text-sm"},me=t.defineComponent({__name:"View",props:{selectedResult:{},sendTextMessage:{type:Function}},emits:["updateResult"],setup(x,{emit:v}){const c=x,b=v,d=t.ref(null),s=t.ref({}),i=t.ref(new Set),p=t.ref(new Map),m=t.ref(!1),k=t.ref(!1),h=t.ref(!1);t.watch(()=>c.selectedResult,(a,n)=>{if(a?.toolName==="presentForm"&&a.jsonData&&(!n||!n.jsonData||n.uuid!==a.uuid||n.jsonData!==a.jsonData)){if(h.value=!0,d.value=a.jsonData,s.value={},d.value.fields.forEach(o=>{s.value[o.id]=r(o)}),a.viewState){const o=a.viewState;o.userResponses&&Object.assign(s.value,o.userResponses),o.touched&&(i.value=new Set(o.touched),o.touched.forEach(u=>{V(u)})),o.submitted!==void 0&&(m.value=o.submitted)}h.value=!1}},{immediate:!0}),t.watch([s,i,m],()=>{if(h.value||!c.selectedResult)return;const a={...c.selectedResult,viewState:{userResponses:{...s.value},touched:Array.from(i.value),submitted:m.value}};b("updateResult",a)},{deep:!0});function r(a){const n=a;if(n.defaultValue!==void 0)switch(a.type){case"radio":case"dropdown":{const e=a.choices.indexOf(n.defaultValue);return e!==-1?e:null}case"checkbox":return Array.isArray(n.defaultValue)?n.defaultValue.map(e=>a.choices.indexOf(e)).filter(e=>e!==-1):[];default:return n.defaultValue}switch(a.type){case"text":case"textarea":return"";case"number":return a.min!==void 0?a.min:0;case"date":case"time":return"";case"radio":case"dropdown":return null;case"checkbox":return[];default:return null}}function g(a){return a==null?!0:typeof a=="string"?a.trim()==="":Array.isArray(a)?a.length===0:!1}function S(a){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a)}function _(a){try{return new URL(a),!0}catch{return!1}}function B(a){return/^[\d\s\-+()]+$/.test(a)&&a.replace(/\D/g,"").length>=10}function D(a,n){if(a.required&&g(n))return`${a.label} is required`;if(g(n))return null;switch(a.type){case"text":{const e=a;if(e.validation==="email"&&!S(n))return"Please enter a valid email address";if(e.validation==="url"&&!_(n))return"Please enter a valid URL";if(e.validation==="phone"&&!B(n))return"Please enter a valid phone number";if(typeof e.validation=="string"&&e.validation!=="email"&&e.validation!=="url"&&e.validation!=="phone")try{if(!new RegExp(e.validation).test(n))return`${a.label} format is invalid`}catch{console.warn(`Invalid regex pattern: ${e.validation}`)}break}case"textarea":{const e=a;if(e.minLength&&n.length<e.minLength)return`Must be at least ${e.minLength} characters (currently ${n.length})`;if(e.maxLength&&n.length>e.maxLength)return`Must be no more than ${e.maxLength} characters (currently ${n.length})`;break}case"number":{const e=a;if(e.min!==void 0&&n<e.min)return`Must be at least ${e.min}`;if(e.max!==void 0&&n>e.max)return`Must be no more than ${e.max}`;break}case"date":{const e=a;if(e.minDate&&n<e.minDate)return`Date must be on or after ${e.minDate}`;if(e.maxDate&&n>e.maxDate)return`Date must be on or before ${e.maxDate}`;break}case"checkbox":{const e=a,o=n?.length||0;if(e.minSelections&&o<e.minSelections)return`Please select at least ${e.minSelections} option${e.minSelections>1?"s":""}`;if(e.maxSelections&&o>e.maxSelections)return`Please select no more than ${e.maxSelections} option${e.maxSelections>1?"s":""}`;break}}return null}function V(a){const n=d.value?.fields.find(u=>u.id===a);if(!n)return!0;const e=s.value[a],o=D(n,e);return o?(p.value.set(a,{fieldId:a,message:o,type:"custom"}),!1):(p.value.delete(a),!0)}function y(a){i.value.add(a),V(a)}function f(a){i.value.has(a)&&V(a)}function l(a){return p.value.has(a)}function E(a){const n=document.getElementById(`input-${a}`);n&&(n.focus(),n.scrollIntoView({behavior:"smooth",block:"center"}))}function F(a){return(a.type==="text"||a.type==="textarea")&&a.maxLength!==void 0}function $(a){if(a.type!=="text"&&a.type!=="textarea")return!1;const n=a.maxLength;return n?(s.value[a.id]||"").length/n>.9:!1}const N=t.computed(()=>d.value?.fields.filter(a=>a.required).length||0),C=t.computed(()=>d.value?d.value.fields.filter(a=>a.required&&!g(s.value[a.id])).length:0);function L(){if(m.value)return;if(d.value?.fields.forEach(e=>{i.value.add(e.id),V(e.id)}),p.value.size>0){k.value=!0;const e=Array.from(p.value.keys())[0];E(e);return}const a={};d.value?.fields.forEach(e=>{const o=s.value[e.id];e.type==="radio"||e.type==="dropdown"?o!=null?a[e.id]=e.choices[o]:a[e.id]=null:e.type==="checkbox"?a[e.id]=(o||[]).map(u=>e.choices[u]):a[e.id]=o});const n=JSON.stringify({formSubmission:{formTitle:d.value?.title||"Form",responses:a}},null,2);m.value=!0,c.sendTextMessage(n)}return(a,n)=>(t.openBlock(),t.createElementBlock("div",R,[d.value?(t.openBlock(),t.createElementBlock("div",T,[d.value.title?(t.openBlock(),t.createElementBlock("h2",U,t.toDisplayString(d.value.title),1)):t.createCommentVNode("",!0),d.value.description?(t.openBlock(),t.createElementBlock("p",z,t.toDisplayString(d.value.description),1)):t.createCommentVNode("",!0),k.value&&p.value.size>0?(t.openBlock(),t.createElementBlock("div",O,[n[0]||(n[0]=t.createElementVNode("h3",{class:"text-red-800 font-semibold mb-2 flex items-center gap-2"},[t.createElementVNode("svg",{class:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20","aria-hidden":"true"},[t.createElementVNode("path",{"fill-rule":"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z","clip-rule":"evenodd"})]),t.createTextVNode(" Please fix the following errors: ")],-1)),t.createElementVNode("ul",j,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(p.value,([e,o])=>(t.openBlock(),t.createElementBlock("li",{key:e},[t.createElementVNode("a",{href:`#${e}`,onClick:t.withModifiers(u=>E(e),["prevent"]),class:"hover:underline cursor-pointer"},t.toDisplayString(o.message),9,I)]))),128))])])):t.createCommentVNode("",!0),t.createElementVNode("form",{onSubmit:t.withModifiers(L,["prevent"]),class:"space-y-6"},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(d.value.fields,e=>(t.openBlock(),t.createElementBlock("div",{key:e.id,id:e.id,class:t.normalizeClass(["form-field",{"has-error":l(e.id)&&i.value.has(e.id)}])},[t.createElementVNode("label",{for:`input-${e.id}`,class:t.normalizeClass(["block text-gray-800 font-semibold mb-2",{"text-red-600":l(e.id)&&i.value.has(e.id)}])},[t.createTextVNode(t.toDisplayString(e.label)+" ",1),e.required?(t.openBlock(),t.createElementBlock("span",H,"*")):t.createCommentVNode("",!0)],10,Y),e.description?(t.openBlock(),t.createElementBlock("p",J,t.toDisplayString(e.description),1)):t.createCommentVNode("",!0),e.type==="text"?t.withDirectives((t.openBlock(),t.createElementBlock("input",{key:1,id:`input-${e.id}`,"onUpdate:modelValue":o=>s.value[e.id]=o,type:"text",placeholder:e.placeholder,"aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0,onBlur:o=>y(e.id),onInput:o=>f(e.id),class:t.normalizeClass(["w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors",{"border-red-500 focus:ring-red-500":l(e.id)&&i.value.has(e.id),"border-gray-300":!l(e.id)||!i.value.has(e.id)}])},null,42,W)),[[t.vModelText,s.value[e.id]]]):e.type==="textarea"?t.withDirectives((t.openBlock(),t.createElementBlock("textarea",{key:2,id:`input-${e.id}`,"onUpdate:modelValue":o=>s.value[e.id]=o,placeholder:e.placeholder,rows:e.rows||4,"aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0,onBlur:o=>y(e.id),onInput:o=>f(e.id),class:t.normalizeClass(["w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors resize-y",{"border-red-500 focus:ring-red-500":l(e.id)&&i.value.has(e.id),"border-gray-300":!l(e.id)||!i.value.has(e.id)}])},null,42,G)),[[t.vModelText,s.value[e.id]]]):e.type==="number"?t.withDirectives((t.openBlock(),t.createElementBlock("input",{key:3,id:`input-${e.id}`,"onUpdate:modelValue":o=>s.value[e.id]=o,type:"number",min:e.min,max:e.max,step:e.step,"aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0,onBlur:o=>y(e.id),onInput:o=>f(e.id),class:t.normalizeClass(["w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors",{"border-red-500 focus:ring-red-500":l(e.id)&&i.value.has(e.id),"border-gray-300":!l(e.id)||!i.value.has(e.id)}])},null,42,K)),[[t.vModelText,s.value[e.id],void 0,{number:!0}]]):e.type==="date"?t.withDirectives((t.openBlock(),t.createElementBlock("input",{key:4,id:`input-${e.id}`,"onUpdate:modelValue":o=>s.value[e.id]=o,type:"date",min:e.minDate,max:e.maxDate,"aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0,onBlur:o=>y(e.id),onChange:o=>f(e.id),class:t.normalizeClass(["w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors",{"border-red-500 focus:ring-red-500":l(e.id)&&i.value.has(e.id),"border-gray-300":!l(e.id)||!i.value.has(e.id)}])},null,42,Q)),[[t.vModelText,s.value[e.id]]]):e.type==="time"?t.withDirectives((t.openBlock(),t.createElementBlock("input",{key:5,id:`input-${e.id}`,"onUpdate:modelValue":o=>s.value[e.id]=o,type:"time","aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0,onBlur:o=>y(e.id),onChange:o=>f(e.id),class:t.normalizeClass(["w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors",{"border-red-500 focus:ring-red-500":l(e.id)&&i.value.has(e.id),"border-gray-300":!l(e.id)||!i.value.has(e.id)}])},null,42,X)),[[t.vModelText,s.value[e.id]]]):e.type==="radio"?(t.openBlock(),t.createElementBlock("div",{key:6,class:"space-y-2",role:"radiogroup","aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.choices,(o,u)=>(t.openBlock(),t.createElementBlock("label",{key:u,class:t.normalizeClass(["flex items-center p-3 border-2 border-gray-300 rounded-lg cursor-pointer transition-all hover:bg-gray-50",{"border-blue-500 bg-blue-50":s.value[e.id]===u,"border-gray-300":s.value[e.id]!==u}])},[t.withDirectives(t.createElementVNode("input",{type:"radio",name:e.id,value:u,"onUpdate:modelValue":w=>s.value[e.id]=w,onChange:w=>f(e.id),onBlur:w=>y(e.id),class:"mr-3 h-4 w-4 flex-shrink-0"},null,40,ee),[[t.vModelRadio,s.value[e.id]]]),t.createElementVNode("span",te,t.toDisplayString(o),1)],2))),128))],8,Z)):e.type==="dropdown"?t.withDirectives((t.openBlock(),t.createElementBlock("select",{key:7,id:`input-${e.id}`,"onUpdate:modelValue":o=>s.value[e.id]=o,"aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0,onBlur:o=>y(e.id),onChange:o=>f(e.id),class:t.normalizeClass(["w-full px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors bg-white",{"border-red-500 focus:ring-red-500":l(e.id)&&i.value.has(e.id),"border-gray-300":!l(e.id)||!i.value.has(e.id)}])},[n[1]||(n[1]=t.createElementVNode("option",{value:null,disabled:""},"Select an option...",-1)),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.choices,(o,u)=>(t.openBlock(),t.createElementBlock("option",{key:u,value:u},t.toDisplayString(o),9,ae))),128))],42,re)),[[t.vModelSelect,s.value[e.id]]]):e.type==="checkbox"?(t.openBlock(),t.createElementBlock("div",{key:8,class:"space-y-2",role:"group","aria-invalid":l(e.id)&&i.value.has(e.id),"aria-describedby":l(e.id)&&i.value.has(e.id)?`${e.id}-error`:void 0},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.choices,(o,u)=>(t.openBlock(),t.createElementBlock("label",{key:u,class:t.normalizeClass(["flex items-center p-3 border-2 border-gray-300 rounded-lg cursor-pointer transition-all hover:bg-gray-50",{"border-blue-500 bg-blue-50":(s.value[e.id]||[]).includes(u),"border-gray-300":!(s.value[e.id]||[]).includes(u)}])},[t.withDirectives(t.createElementVNode("input",{type:"checkbox",value:u,"onUpdate:modelValue":w=>s.value[e.id]=w,onChange:w=>f(e.id),onBlur:w=>y(e.id),class:"mr-3 h-4 w-4 flex-shrink-0"},null,40,ne),[[t.vModelCheckbox,s.value[e.id]]]),t.createElementVNode("span",ie,t.toDisplayString(o),1)],2))),128))],8,oe)):t.createCommentVNode("",!0),l(e.id)&&i.value.has(e.id)?(t.openBlock(),t.createElementBlock("div",{key:9,id:`${e.id}-error`,class:"flex items-center gap-2 mt-2 text-red-600 text-sm",role:"alert"},[n[2]||(n[2]=t.createElementVNode("svg",{class:"w-4 h-4 flex-shrink-0",fill:"currentColor",viewBox:"0 0 20 20","aria-hidden":"true"},[t.createElementVNode("path",{"fill-rule":"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z","clip-rule":"evenodd"})],-1)),t.createTextVNode(" "+t.toDisplayString(p.value.get(e.id)?.message),1)],8,se)):t.createCommentVNode("",!0),F(e)?(t.openBlock(),t.createElementBlock("div",{key:10,class:t.normalizeClass(["text-sm mt-2",{"text-amber-600 font-semibold":$(e),"text-gray-500":!$(e)}])},[t.createTextVNode(t.toDisplayString((s.value[e.id]||"").length)+" ",1),e.maxLength?(t.openBlock(),t.createElementBlock("span",le," / "+t.toDisplayString(e.maxLength),1)):t.createCommentVNode("",!0),n[3]||(n[3]=t.createTextVNode(" characters ",-1))],2)):t.createCommentVNode("",!0)],10,P))),128)),t.createElementVNode("div",de,[t.createElementVNode("button",{type:"submit",disabled:m.value,class:t.normalizeClass([m.value?"bg-green-600 cursor-default":"bg-blue-600 hover:bg-blue-700","px-8 py-3 rounded-lg text-white font-semibold text-lg transition-colors"])},t.toDisplayString(m.value?"Submitted":"Submit Form"),11,ce)]),t.createElementVNode("div",ue,t.toDisplayString(C.value)+" / "+t.toDisplayString(N.value)+" required fields completed ",1)],32)])):t.createCommentVNode("",!0)]))}}),pe=(x,v)=>{const c=x.__vccOpts||x;for(const[b,d]of v)c[b]=d;return c},he=pe(me,[["__scopeId","data-v-b79fe71c"]]),ve={class:"w-full h-full flex flex-col items-center justify-center p-4 bg-gradient-to-br from-blue-50 to-indigo-50 rounded-lg border-2 border-gray-200"},ge={class:"text-center"},be={class:"text-gray-900 font-bold text-lg mb-1 line-clamp-2"},ye={class:"text-gray-600 text-sm mb-2"},fe={key:0,class:"flex items-center justify-center gap-2"},xe={class:"w-32 h-2 bg-gray-200 rounded-full overflow-hidden"},we={class:"text-xs text-gray-500"},ke={key:1,class:"inline-flex items-center gap-1 px-3 py-1 bg-green-100 text-green-700 rounded-full text-xs font-semibold"},Ve=t.defineComponent({__name:"Preview",props:{result:{}},setup(x){const v=x,c=t.computed(()=>v.result?.toolName==="presentForm"?v.result.jsonData:null),b=t.computed(()=>v.result?.viewState||null),d=t.computed(()=>c.value?.fields.length||0),s=t.computed(()=>b.value?.submitted||!1),i=t.computed(()=>{if(!c.value||s.value)return 100;const p=c.value.fields.filter(h=>h.required);if(p.length===0)return 0;const m=b.value?.userResponses||{},k=p.filter(h=>{const r=m[h.id];return r==null?!1:typeof r=="string"?r.trim()!=="":Array.isArray(r)?r.length>0:!0}).length;return Math.round(k/p.length*100)});return(p,m)=>(t.openBlock(),t.createElementBlock("div",ve,[t.createElementVNode("div",ge,[m[1]||(m[1]=t.createElementVNode("svg",{class:"w-12 h-12 mx-auto mb-3 text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1)),t.createElementVNode("h3",be,t.toDisplayString(c.value?.title||"Form"),1),t.createElementVNode("p",ye,t.toDisplayString(d.value)+" field"+t.toDisplayString(d.value!==1?"s":""),1),s.value?(t.openBlock(),t.createElementBlock("div",ke,[...m[0]||(m[0]=[t.createElementVNode("svg",{class:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20"},[t.createElementVNode("path",{"fill-rule":"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z","clip-rule":"evenodd"})],-1),t.createTextVNode(" Submitted ",-1)])])):(t.openBlock(),t.createElementBlock("div",fe,[t.createElementVNode("div",xe,[t.createElementVNode("div",{class:"h-full bg-blue-600 transition-all duration-300",style:t.normalizeStyle({width:`${i.value}%`})},null,4)]),t.createElementVNode("span",we,t.toDisplayString(i.value)+"%",1)]))])]))}}),Ee=async(x,v)=>{try{const{title:c,description:b,fields:d}=v;if(!d||!Array.isArray(d)||d.length===0)throw new Error("At least one field is required");const s=new Set;for(let h=0;h<d.length;h++){const r=d[h];if(!r.id||typeof r.id!="string")throw new Error(`Field ${h+1} must have a valid 'id' property`);if(!r.type||typeof r.type!="string")throw new Error(`Field ${h+1} must have a valid 'type' property`);if(!r.label||typeof r.label!="string")throw new Error(`Field ${h+1} must have a valid 'label' property`);if(s.has(r.id))throw new Error(`Duplicate field ID: '${r.id}'`);switch(s.add(r.id),r.type){case"text":case"textarea":if(r.minLength!==void 0&&r.maxLength!==void 0&&r.minLength>r.maxLength)throw new Error(`Field '${r.id}': minLength cannot be greater than maxLength`);break;case"radio":if(!Array.isArray(r.choices)||r.choices.length<2)throw new Error(`Field '${r.id}': radio fields must have at least 2 choices`);r.choices.length>6&&console.warn(`Field '${r.id}': radio fields with more than 6 choices should use 'dropdown' type instead`);break;case"dropdown":case"checkbox":if(!Array.isArray(r.choices)||r.choices.length<1)throw new Error(`Field '${r.id}': ${r.type} fields must have at least 1 choice`);break;case"number":if(r.min!==void 0&&r.max!==void 0&&r.min>r.max)throw new Error(`Field '${r.id}': min cannot be greater than max`);break;case"date":if(r.minDate&&r.maxDate&&r.minDate>r.maxDate)throw new Error(`Field '${r.id}': minDate cannot be after maxDate`);break;case"time":break;default:{const g=r;throw new Error(`Field '${g.id}': unknown field type '${g.type}'`)}}if(r.type==="checkbox"){if(r.minSelections!==void 0&&r.maxSelections!==void 0&&r.minSelections>r.maxSelections)throw new Error(`Field '${r.id}': minSelections cannot be greater than maxSelections`);if(r.maxSelections!==void 0&&r.maxSelections>r.choices.length)throw new Error(`Field '${r.id}': maxSelections cannot exceed number of choices`)}if(r.defaultValue!==void 0)switch(r.type){case"text":case"textarea":if(typeof r.defaultValue!="string")throw new Error(`Field '${r.id}': defaultValue must be a string`);if(r.minLength!==void 0&&r.defaultValue.length<r.minLength)throw new Error(`Field '${r.id}': defaultValue length is less than minLength`);if(r.maxLength!==void 0&&r.defaultValue.length>r.maxLength)throw new Error(`Field '${r.id}': defaultValue length exceeds maxLength`);break;case"radio":case"dropdown":if(typeof r.defaultValue!="string")throw new Error(`Field '${r.id}': defaultValue must be a string`);if(!r.choices.includes(r.defaultValue))throw new Error(`Field '${r.id}': defaultValue '${r.defaultValue}' is not in choices`);break;case"checkbox":if(!Array.isArray(r.defaultValue))throw new Error(`Field '${r.id}': defaultValue must be an array`);for(const g of r.defaultValue)if(!r.choices.includes(g))throw new Error(`Field '${r.id}': defaultValue contains '${g}' which is not in choices`);if(r.minSelections!==void 0&&r.defaultValue.length<r.minSelections)throw new Error(`Field '${r.id}': defaultValue has fewer selections than minSelections`);if(r.maxSelections!==void 0&&r.defaultValue.length>r.maxSelections)throw new Error(`Field '${r.id}': defaultValue has more selections than maxSelections`);break;case"number":if(typeof r.defaultValue!="number")throw new Error(`Field '${r.id}': defaultValue must be a number`);if(r.min!==void 0&&r.defaultValue<r.min)throw new Error(`Field '${r.id}': defaultValue is less than min`);if(r.max!==void 0&&r.defaultValue>r.max)throw new Error(`Field '${r.id}': defaultValue is greater than max`);break;case"date":if(typeof r.defaultValue!="string")throw new Error(`Field '${r.id}': defaultValue must be a string (ISO date format)`);if(r.minDate!==void 0&&r.defaultValue<r.minDate)throw new Error(`Field '${r.id}': defaultValue is before minDate`);if(r.maxDate!==void 0&&r.defaultValue>r.maxDate)throw new Error(`Field '${r.id}': defaultValue is after maxDate`);break;case"time":if(typeof r.defaultValue!="string")throw new Error(`Field '${r.id}': defaultValue must be a string`);break}}const i={title:c,description:b,fields:d},p=`${d.length} field${d.length>1?"s":""}`,m=c?`: ${c}`:"";return{message:`Form created with ${p}${m}`,jsonData:i,instructions:"The form has been presented to the user. Wait for the user to fill out and submit the form. They will send their responses as a JSON message."}}catch(c){return console.error(`ERR: exception
2
+ Form creation error`,c),{message:`Form error: ${c instanceof Error?c.message:"Unknown error"}`,instructions:"Acknowledge that there was an error creating the form and suggest trying again with corrected field definitions."}}},$e={toolDefinition:q,execute:Ee,generatingMessage:"Preparing form...",isEnabled:()=>!0,viewComponent:he,previewComponent:Ve,samples:A},Se={plugin:$e};exports.default=Se;
package/dist/index.d.ts CHANGED
@@ -1,11 +1,7 @@
1
1
  /**
2
- * MulmoChat Form Plugin
2
+ * MulmoChat Plugin
3
3
  *
4
- * @example
5
- * ```typescript
6
- * import FormPlugin from "@mulmochat-plugin/form";
7
- * import "@mulmochat-plugin/form/style.css";
8
- * ```
4
+ * See package.json for plugin details.
9
5
  */
10
6
  import "./style.css";
11
7
  import type { ToolPlugin } from "./common";