@autoai-ui/autoui 0.2.2 → 0.2.4

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 (61) hide show
  1. package/dist/autoui.css +1 -0
  2. package/dist/index.cjs +286 -40
  3. package/dist/index.mjs +3947 -2628
  4. package/dist/lib/index.d.ts +1 -0
  5. package/dist/lib/plugin.d.ts +2 -0
  6. package/dist/plugin.cjs +4 -0
  7. package/dist/plugin.d.ts +2 -0
  8. package/dist/plugin.mjs +428 -0
  9. package/package.json +14 -3
  10. package/dist/lib/bin/index.d.ts +0 -1
  11. package/dist/lib/components/chat/context/chatContext.d.ts +0 -3
  12. package/dist/lib/components/chat/context/modalChatContext.d.ts +0 -9
  13. package/dist/lib/components/chat/hooks/useAutoUiChat.d.ts +0 -4
  14. package/dist/lib/components/chat/hooks/useChat.d.ts +0 -3
  15. package/dist/lib/components/chat/hooks/useChatState.d.ts +0 -7
  16. package/dist/lib/components/chat/hooks/useRendering.d.ts +0 -7
  17. package/dist/lib/components/chat/hooks/useSpeechToText.d.ts +0 -9
  18. package/dist/lib/components/chat/hooks/useTheme.d.ts +0 -6
  19. package/dist/lib/components/chat/index.d.ts +0 -2
  20. package/dist/lib/components/chat/types/index.d.ts +0 -114
  21. package/dist/lib/components/chat/ui/Chat.d.ts +0 -3
  22. package/dist/lib/components/chat/ui/ChatHeader.d.ts +0 -1
  23. package/dist/lib/components/chat/ui/ChatInput.d.ts +0 -4
  24. package/dist/lib/components/chat/ui/ChatMenu.d.ts +0 -1
  25. package/dist/lib/components/chat/ui/ChatMessageList.d.ts +0 -3
  26. package/dist/lib/components/chat/ui/ChatMessageListItem.d.ts +0 -6
  27. package/dist/lib/components/chat/ui/ChatTextBox.d.ts +0 -5
  28. package/dist/lib/components/chat/ui/MicButton.d.ts +0 -4
  29. package/dist/lib/components/chat/ui/ModalChat.d.ts +0 -2
  30. package/dist/lib/components/chat/ui/ScrollToBottomButton.d.ts +0 -7
  31. package/dist/lib/components/chat/ui/SendButton.d.ts +0 -1
  32. package/dist/lib/components/chat/ui/btnOpenChat/index.d.ts +0 -3
  33. package/dist/lib/components/index.d.ts +0 -2
  34. package/dist/lib/components/menu/index.d.ts +0 -1
  35. package/dist/lib/components/menu/ui/Menu.d.ts +0 -6
  36. package/dist/lib/components/menu/ui/MenuItem.d.ts +0 -16
  37. package/dist/lib/components/menu/ui/MenuSelectedIcon.d.ts +0 -4
  38. package/dist/lib/components/popover/index.d.ts +0 -2
  39. package/dist/lib/components/popover/ui/Popover.d.ts +0 -10
  40. package/dist/lib/components/popover/ui/PopoverMenu.d.ts +0 -10
  41. package/dist/lib/components/spinner/index.d.ts +0 -1
  42. package/dist/lib/components/spinner/ui/Spinner.d.ts +0 -16
  43. package/dist/lib/components/switch/index.d.ts +0 -1
  44. package/dist/lib/components/switch/ui/Switch.d.ts +0 -30
  45. package/dist/lib/core/buildDataAnalyzingPrompt.d.ts +0 -3
  46. package/dist/lib/core/buildIntentPrompt.d.ts +0 -2
  47. package/dist/lib/core/extraDataAnalyzingWithLLM.d.ts +0 -3
  48. package/dist/lib/core/index.d.ts +0 -1
  49. package/dist/lib/core/llmClient.d.ts +0 -3
  50. package/dist/lib/core/sseParser.d.ts +0 -1
  51. package/dist/lib/runtime/index.d.ts +0 -1
  52. package/dist/lib/runtime/rerenderChatFromHistory.d.ts +0 -3
  53. package/dist/lib/runtime/runtimeEngine.d.ts +0 -9
  54. package/dist/lib/runtime/stepExecutor.d.ts +0 -7
  55. package/dist/lib/types/index.d.ts +0 -79
  56. package/dist/lib/types/llmTypes.d.ts +0 -21
  57. package/dist/lib/utils/clsx.d.ts +0 -1
  58. package/dist/lib/utils/debounce.d.ts +0 -11
  59. package/dist/lib/utils/index.d.ts +0 -1
  60. package/dist/lib/utils/resolveProps.d.ts +0 -2
  61. package/dist/stats.html +0 -4949
@@ -3,3 +3,4 @@ export type { ChatContextType, ChatMessage, ChatMessageListProps, ChatProps, Cha
3
3
  export type { AutoUIComponent, AutoUIConfig, AutoUIFunction, AutoUIMetadata, LLMConfig, RuntimeConfig, } from './types/index';
4
4
  export type { InstructionPlan, InstructionStep, ComponentStep, FunctionStep, TextStep } from './types/llmTypes';
5
5
  export type { SpinnerProps } from './components/spinner/ui/Spinner';
6
+ export { autouiRegisterComponentPropsSchema, autouiRegisterFunctionParamsSchema } from './registration';
@@ -0,0 +1,2 @@
1
+ export { autouiTypeSchemaPlugin } from './build-time/typeSchemaPlugin';
2
+ export type * from './build-time/typeSchemaPlugin/types';
@@ -0,0 +1,4 @@
1
+ "use strict";var x=Object.create;var I=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var _=(t,e,n,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of F(e))!O.call(t,o)&&o!==n&&I(t,o,{get:()=>e[o],enumerable:!(l=w(e,o))||l.enumerable});return t};var q=(t,e,n)=>(n=t!=null?x(k(t)):{},_(e||!t||!t.__esModule?I(n,"default",{value:t,enumerable:!0}):n,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("node:fs"),h=require("node:path"),y=require("ts-morph"),j=require("node:crypto");function L(t){const e=[],n=[],l=t.getSourceFiles(),o=t.getTypeChecker();for(const g of l)g.isDeclarationFile()||g.getFilePath().includes("node_modules")||g.forEachDescendant(u=>{if(y.Node.isCallExpression(u)){const i=u.getExpression();if(y.Node.isIdentifier(i)){const s=i.getText();if(s==="autouiRegisterComponentPropsSchema"){const m=u.getArguments();if(m.length>0){const p=m[0],c=o.getTypeAtLocation(p),r=o.getSymbolAtLocation(p);let a="Unknown";if(r)a=r.getName();else{const f=c.getSymbol();f&&(a=f.getName())}console.log(`[AutoUI Type Schema] Found component registration: "${a}"`),e.push({name:a,type:c})}}if(s==="autouiRegisterFunctionParamsSchema"){const m=u.getArguments();if(m.length>0){const p=m[0],c=o.getTypeAtLocation(p),r=o.getSymbolAtLocation(p);let a="Unknown";if(r)a=r.getName();else{const f=c.getSymbol();f&&(a=f.getName())}console.log(`[AutoUI Type Schema] Found function registration: "${a}"`),n.push({name:a,type:c})}}}}});return{components:e,functions:n}}function v(t,e){const n=t.getDeclarations();for(const o of n)if(y.Node.isPropertySignature(o)&&o.hasQuestionToken()||y.Node.isParameterDeclaration(o)&&(o.hasQuestionToken()||o.hasInitializer())||y.Node.isBindingElement(o)&&o.hasInitializer())return!0;if(e.isUnion()){const o=e.getUnionTypes(),g=o.some(i=>{if(i.isUndefined())return!0;const s=i.getText();if(s==="undefined"||s==="void")return!0;try{if((i.getFlags()&256)!==0)return!0}catch{}return!1}),u=o.some(i=>!!(i.isNull()||i.getText()==="null"));if(g||u)return!0}if(e.isUndefined())return!0;const l=e.getText();return l==="undefined"||l==="void"}function A(t){if(t.isUnion()){const n=t.getUnionTypes().find(l=>{if(l.isUndefined()||l.isNull())return!1;const o=l.getText();if(o==="undefined"||o==="null"||o==="void")return!1;try{if((l.getFlags()&256)!==0)return!1}catch{}return!0});if(n)return n}return t}function P(t,e){if(e.typeNames.has(t))return e.typeNames.get(t);const n=t.getSymbol();if(n){const o=n.getName();if(o&&o!=="__type"&&o!=="__function"){const g=n.getDeclarations();if(g&&g.length>0){const u=g[0],i=u.getSourceFile();if(!i.isDeclarationFile()&&!i.getFilePath().includes("node_modules")&&(y.Node.isTypeAliasDeclaration(u)||y.Node.isInterfaceDeclaration(u)||y.Node.isEnumDeclaration(u)))return e.typeNames.set(t,o),o}}}if(t.isArray()){const o=t.getArrayElementType();if(o)return`${P(o,e)}[]`}const l=t.getText();return l==="string"||l==="number"||l==="boolean"?l:C(t,e)}function C(t,e){const n=t.getText(),l=j.createHash("md5").update(n).digest("hex").substring(0,8);let o="Anonymous";n.includes("{")?o="Object":n.includes("[")?o="Array":n.includes("|")&&(o="Union");const g=e.anonymousTypeCounter.get(o)||0;e.anonymousTypeCounter.set(o,g+1);const u=`${o}_${l}`;return e.typeNames.set(t,u),u}function T(t,e){const n=P(t,e);if(e.types.has(n)||e.visitedTypes.has(t))return n;if(e.visitedTypes.add(t),t.isString()||t.isStringLiteral())return console.log(`[AutoUI Type Schema] Extracting primitive type "${n}": string`),e.types.set(n,{type:"primitive"}),n;if(t.isNumber()||t.isNumberLiteral())return console.log(`[AutoUI Type Schema] Extracting primitive type "${n}": number`),e.types.set(n,{type:"primitive"}),n;if(t.isBoolean()||t.isBooleanLiteral())return console.log(`[AutoUI Type Schema] Extracting primitive type "${n}": boolean`),e.types.set(n,{type:"primitive"}),n;if(t.isArray()){const i=t.getArrayElementType();if(i){console.log(`[AutoUI Type Schema] Extracting array type "${n}"`);const s=T(i,e);return e.types.set(n,{type:"array",items:{type:s},refs:[s]}),console.log(` → Array element type: "${s}"`),n}}if(t.isEnum()){const i=t.getSymbol();if(i){const s=i.getValueDeclaration();if(s&&y.Node.isEnumDeclaration(s)){const m=s.getMembers().map(p=>p.getName());return console.log(`[AutoUI Type Schema] Extracting enum type "${n}" with values: [${m.join(", ")}]`),e.types.set(n,{type:"enum",values:m}),n}}}if(t.isUnion()){const i=t.getUnionTypes();console.log(`[AutoUI Type Schema] Extracting union type "${n}" with ${i.length} union members`);const s=[];let m=!0,p=!1;for(const r of i){if(r.isUndefined()||r.isNull()){p=!0;continue}if(r.isStringLiteral()){const a=r.getLiteralValue();typeof a=="string"?s.push(a):m=!1}else m=!1}if(m&&s.length>0&&!p){const r=t.getSymbol();if(r){const a=r.getDeclarations();if(a&&a.length>0){const f=a[0];if(y.Node.isTypeAliasDeclaration(f)){const d=r.getName();return console.log(` → Converting string literal union to enum "${d}" with values: [${s.join(", ")}]`),e.types.set(d,{type:"enum",values:s}),e.typeNames.set(t,d),d}}}}const c=[];for(const r of i)if(!r.isUndefined()&&!r.isNull()){const a=T(r,e);c.includes(a)||c.push(a)}if(console.log(` → Union members: [${c.join(", ")}]`),c.length>1)return e.types.set(n,{type:"union",refs:c}),n;if(c.length===1)return console.log(` → Single type union (with undefined) - returning "${c[0]}"`),c[0]}const l={},o=[],g=t.getProperties(),u=t.getText();console.log(`[AutoUI Type Schema] Extracting object type "${n}":`),console.log(` Type text: ${u.substring(0,100)}${u.length>100?"...":""}`),console.log(` Properties count: ${g.length}`);for(const i of g){const s=i.getName();if(s.startsWith("__")||s==="toString"||s==="valueOf")continue;const m=i.getValueDeclaration()||i.getDeclarations()[0];if(!m)continue;const p=e.checker.getTypeAtLocation(m);console.log(` [Object Property] ${s}:`),console.log(` Raw type: ${p.getText()}`);const c=v(i,p),r=!c;c&&console.log(" Detected as optional (question token, union with undefined/null, or default value)");const a=A(p);a!==p&&console.log(` Extracting non-optional type: ${a.getText()}`);const f=T(a,e);l[s]={type:f,required:r},console.log(` → Evaluated type: "${f}" (required: ${r})`),o.includes(f)||o.push(f)}return e.types.set(n,{type:"object",properties:l,refs:o}),n}function R(t,e){const n={};let l=null;const o=t.getTypeArguments();if(o.length>0)l=o[0],console.log(`[AutoUI Type Schema] Extracting component props from generic type argument: ${l.getText()}`);else{const u=t.getCallSignatures();if(u.length>0){const s=u[0].getParameters();if(s.length>0){const p=s[0].getValueDeclaration();p&&(l=e.checker.getTypeAtLocation(p),console.log(`[AutoUI Type Schema] Extracting component props from call signature parameter: ${l.getText()}`))}}}if(!l)return console.log("[AutoUI Type Schema] Could not extract props type from component"),n;const g=l.getProperties();console.log(`[AutoUI Type Schema] Extracting component props from type: ${l.getText()}`),console.log(`[AutoUI Type Schema] Properties count: ${g.length}`);for(const u of g){const i=u.getName();if(i.startsWith("__")||i==="toString"||i==="valueOf")continue;const s=u.getValueDeclaration()||u.getDeclarations()[0];if(!s)continue;const m=e.checker.getTypeAtLocation(s);console.log(` [Component Prop] ${i}:`),console.log(` Raw type: ${m.getText()}`);const p=v(u,m),c=!p;p&&console.log(" Detected as optional (question token, union with undefined/null, or default value)");const r=A(m);r!==m&&console.log(` Extracting non-optional type: ${r.getText()}`);const a=T(r,e);n[i]={type:a,required:c},console.log(` → Evaluated type: "${a}" (required: ${c})`)}return n}function V(t,e){const n={},l=t.getCallSignatures();if(l.length>0){const o=l[0],g=o.getParameters();console.log(`[AutoUI Type Schema] Extracting function parameters (count: ${g.length})`);for(const s of g){const m=s.getName();if(m&&!m.startsWith("__")){const p=s.getValueDeclaration();if(!p)continue;const c=e.checker.getTypeAtLocation(p);console.log(` [Function Param] ${m}:`),console.log(` Raw type: ${c.getText()}`);const r=v(s,c),a=!r;r&&console.log(" Detected as optional (question token, union with undefined/null, or default value)");const f=A(c);f!==c&&console.log(` Extracting non-optional type: ${f.getText()}`);const d=T(f,e);n[m]={type:d,required:a},console.log(` → Evaluated type: "${d}" (required: ${a})`)}else{const p=s.getValueDeclaration();if(!p)continue;const c=e.checker.getTypeAtLocation(p);if(console.log(" [Function Param] (destructured):"),console.log(` Raw type: ${c.getText()}`),c.isObject()){const r=c.getProperties();console.log(` Extracting destructured object properties (count: ${r.length})`);for(const a of r){const f=a.getName();if(f.startsWith("__"))continue;console.log(` [Destructured Prop] ${f}:`);const d=a.getValueDeclaration()||a.getDeclarations()[0];if(!d)continue;const N=e.checker.getTypeAtLocation(d);console.log(` Raw type: ${N.getText()}`);const E=v(a,N),b=!E;E&&console.log(" Detected as optional (question token, union with undefined/null, or default value)");const U=A(N);U!==N&&console.log(` Extracting non-optional type: ${U.getText()}`);const D=T(U,e);n[f]={type:D,required:b},console.log(` → Evaluated type: "${D}" (required: ${b})`)}}else{const r=T(c,e);n.param={type:r,required:!0},console.log(` → Evaluated type: "${r}" (required: true)`)}}}const u=o.getReturnType(),i=T(u,e);return console.log(` [Function Return] → Evaluated type: "${i}"`),{params:n,returns:{type:i}}}return{params:n,returns:{type:"void"}}}function W(t,e,n){const o={checker:t.getTypeChecker(),types:new Map,typeNames:new Map,visitedTypes:new Set,anonymousTypeCounter:new Map};console.log(`[AutoUI Type Schema] Starting schema generation for appId: ${e}, version: ${n}`);const{components:g,functions:u}=L(t);console.log(`[AutoUI Type Schema] Found ${g.length} component(s) and ${u.length} function(s)`);const i=[];for(const{name:p,type:c}of g){console.log(`
2
+ [AutoUI Type Schema] ========================================`),console.log(`[AutoUI Type Schema] Processing Component: "${p}"`),console.log("[AutoUI Type Schema] ========================================");const r=R(c,o);i.push({name:p,props:r}),console.log(`[AutoUI Type Schema] ✓ Component "${p}" processed with ${Object.keys(r).length} prop(s)`)}const s=[];for(const{name:p,type:c}of u){console.log(`
3
+ [AutoUI Type Schema] ========================================`),console.log(`[AutoUI Type Schema] Processing Function: "${p}"`),console.log("[AutoUI Type Schema] ========================================");const{params:r,returns:a}=V(c,o);s.push({name:p,params:r,returns:a}),console.log(`[AutoUI Type Schema] ✓ Function "${p}" processed with ${Object.keys(r).length} param(s), return type: "${a.type}"`)}const m={};for(const[p,c]of o.types.entries())m[p]=c;return{appId:e,version:n,generatedAt:new Date().toISOString(),types:m,components:i,functions:s}}function $(t){const e={};if(!S.existsSync(t))return e;try{const l=S.readFileSync(t,"utf-8").split(`
4
+ `);for(const o of l){const g=o.trim();if(!g||g.startsWith("#"))continue;const u=g.match(/^([^=:#]+)=(.*)$/);if(u){const i=u[1].trim();let s=u[2].trim();(s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'"))&&(s=s.slice(1,-1)),e[i]=s}}}catch{}return e}function M(t="development"){const e=process.cwd(),n={},l=$(h.resolve(e,".env"));Object.assign(n,l);const o=$(h.resolve(e,`.env.${t}`));Object.assign(n,o);const g=$(h.resolve(e,".env.local"));Object.assign(n,g);const u=process.env.NODE_ENV||t;if(u!==t){const i=$(h.resolve(e,`.env.${u}`));Object.assign(n,i)}return n}function B(t={}){const e=t.runtimeSchemaFile||".autoui-runtime-schema.json";return{name:"autoui-type-schema",enforce:"pre",async buildStart(){if(process.env.NODE_ENV==="production"||process.env.MODE==="production"){console.log("[AutoUI Type Schema Plugin] Skipping schema generation in production build. Using existing schema file.");return}const g={...M("development"),...process.env},u=t.appId||g.AUTOUI_APP_ID||"unknown",i=t.version||g.AUTOUI_VERSION||"1.0.0";try{let s=h.resolve(process.cwd(),"tsconfig.app.json");if(S.existsSync(s)||(s=h.resolve(process.cwd(),"tsconfig.json")),!S.existsSync(s)){console.warn("[AutoUI Type Schema Plugin] No tsconfig.json or tsconfig.app.json found, skipping schema extraction");return}const m=new y.Project({tsConfigFilePath:s});if(m.getSourceFiles().filter(f=>!f.isDeclarationFile()&&!f.getFilePath().includes("node_modules")).length===0){console.warn("[AutoUI Type Schema Plugin] No source files found after filtering!");return}const c=W(m,u,i);if(c.components.length===0&&c.functions.length===0)return;const r=h.resolve(process.cwd(),e),a=h.resolve(r,"..");if(!S.existsSync(a)){const{mkdirSync:f}=await import("node:fs");f(a,{recursive:!0})}S.writeFileSync(r,JSON.stringify(c,null,2),"utf-8"),console.log(`[AutoUI Type Schema Plugin] Schema written to ${e}`)}catch(s){console.error("❌ [AutoUI Type Schema Plugin] Error in plugin:",s),s instanceof Error&&(console.error(` Error message: ${s.message}`),s.stack&&console.error(` Stack trace: ${s.stack}`))}}}}exports.autouiTypeSchemaPlugin=B;
@@ -0,0 +1,2 @@
1
+ export * from './lib/plugin'
2
+ export {}
@@ -0,0 +1,428 @@
1
+ import { existsSync as N, readFileSync as P, writeFileSync as w } from "node:fs";
2
+ import { resolve as h } from "node:path";
3
+ import { Node as d, Project as x } from "ts-morph";
4
+ import { createHash as F } from "node:crypto";
5
+ function k(n) {
6
+ const e = [], t = [], p = n.getSourceFiles(), o = n.getTypeChecker();
7
+ for (const g of p)
8
+ g.isDeclarationFile() || g.getFilePath().includes("node_modules") || g.forEachDescendant((l) => {
9
+ if (d.isCallExpression(l)) {
10
+ const i = l.getExpression();
11
+ if (d.isIdentifier(i)) {
12
+ const s = i.getText();
13
+ if (s === "autouiRegisterComponentPropsSchema") {
14
+ const m = l.getArguments();
15
+ if (m.length > 0) {
16
+ const u = m[0], c = o.getTypeAtLocation(u), r = o.getSymbolAtLocation(u);
17
+ let a = "Unknown";
18
+ if (r)
19
+ a = r.getName();
20
+ else {
21
+ const f = c.getSymbol();
22
+ f && (a = f.getName());
23
+ }
24
+ console.log(`[AutoUI Type Schema] Found component registration: "${a}"`), e.push({ name: a, type: c });
25
+ }
26
+ }
27
+ if (s === "autouiRegisterFunctionParamsSchema") {
28
+ const m = l.getArguments();
29
+ if (m.length > 0) {
30
+ const u = m[0], c = o.getTypeAtLocation(u), r = o.getSymbolAtLocation(u);
31
+ let a = "Unknown";
32
+ if (r)
33
+ a = r.getName();
34
+ else {
35
+ const f = c.getSymbol();
36
+ f && (a = f.getName());
37
+ }
38
+ console.log(`[AutoUI Type Schema] Found function registration: "${a}"`), t.push({ name: a, type: c });
39
+ }
40
+ }
41
+ }
42
+ }
43
+ });
44
+ return { components: e, functions: t };
45
+ }
46
+ function v(n, e) {
47
+ const t = n.getDeclarations();
48
+ for (const o of t)
49
+ if (d.isPropertySignature(o) && o.hasQuestionToken() || d.isParameterDeclaration(o) && (o.hasQuestionToken() || o.hasInitializer()) || d.isBindingElement(o) && o.hasInitializer())
50
+ return !0;
51
+ if (e.isUnion()) {
52
+ const o = e.getUnionTypes(), g = o.some((i) => {
53
+ if (i.isUndefined()) return !0;
54
+ const s = i.getText();
55
+ if (s === "undefined" || s === "void") return !0;
56
+ try {
57
+ if ((i.getFlags() & 256) !== 0) return !0;
58
+ } catch {
59
+ }
60
+ return !1;
61
+ }), l = o.some((i) => !!(i.isNull() || i.getText() === "null"));
62
+ if (g || l)
63
+ return !0;
64
+ }
65
+ if (e.isUndefined())
66
+ return !0;
67
+ const p = e.getText();
68
+ return p === "undefined" || p === "void";
69
+ }
70
+ function A(n) {
71
+ if (n.isUnion()) {
72
+ const t = n.getUnionTypes().find((p) => {
73
+ if (p.isUndefined() || p.isNull()) return !1;
74
+ const o = p.getText();
75
+ if (o === "undefined" || o === "null" || o === "void")
76
+ return !1;
77
+ try {
78
+ if ((p.getFlags() & 256) !== 0) return !1;
79
+ } catch {
80
+ }
81
+ return !0;
82
+ });
83
+ if (t)
84
+ return t;
85
+ }
86
+ return n;
87
+ }
88
+ function I(n, e) {
89
+ if (e.typeNames.has(n))
90
+ return e.typeNames.get(n);
91
+ const t = n.getSymbol();
92
+ if (t) {
93
+ const o = t.getName();
94
+ if (o && o !== "__type" && o !== "__function") {
95
+ const g = t.getDeclarations();
96
+ if (g && g.length > 0) {
97
+ const l = g[0], i = l.getSourceFile();
98
+ if (!i.isDeclarationFile() && !i.getFilePath().includes("node_modules") && (d.isTypeAliasDeclaration(l) || d.isInterfaceDeclaration(l) || d.isEnumDeclaration(l)))
99
+ return e.typeNames.set(n, o), o;
100
+ }
101
+ }
102
+ }
103
+ if (n.isArray()) {
104
+ const o = n.getArrayElementType();
105
+ if (o)
106
+ return `${I(o, e)}[]`;
107
+ }
108
+ const p = n.getText();
109
+ return p === "string" || p === "number" || p === "boolean" ? p : O(n, e);
110
+ }
111
+ function O(n, e) {
112
+ const t = n.getText(), p = F("md5").update(t).digest("hex").substring(0, 8);
113
+ let o = "Anonymous";
114
+ t.includes("{") ? o = "Object" : t.includes("[") ? o = "Array" : t.includes("|") && (o = "Union");
115
+ const g = e.anonymousTypeCounter.get(o) || 0;
116
+ e.anonymousTypeCounter.set(o, g + 1);
117
+ const l = `${o}_${p}`;
118
+ return e.typeNames.set(n, l), l;
119
+ }
120
+ function T(n, e) {
121
+ const t = I(n, e);
122
+ if (e.types.has(t) || e.visitedTypes.has(n))
123
+ return t;
124
+ if (e.visitedTypes.add(n), n.isString() || n.isStringLiteral())
125
+ return console.log(`[AutoUI Type Schema] Extracting primitive type "${t}": string`), e.types.set(t, { type: "primitive" }), t;
126
+ if (n.isNumber() || n.isNumberLiteral())
127
+ return console.log(`[AutoUI Type Schema] Extracting primitive type "${t}": number`), e.types.set(t, { type: "primitive" }), t;
128
+ if (n.isBoolean() || n.isBooleanLiteral())
129
+ return console.log(`[AutoUI Type Schema] Extracting primitive type "${t}": boolean`), e.types.set(t, { type: "primitive" }), t;
130
+ if (n.isArray()) {
131
+ const i = n.getArrayElementType();
132
+ if (i) {
133
+ console.log(`[AutoUI Type Schema] Extracting array type "${t}"`);
134
+ const s = T(i, e);
135
+ return e.types.set(t, {
136
+ type: "array",
137
+ items: { type: s },
138
+ refs: [s]
139
+ }), console.log(` → Array element type: "${s}"`), t;
140
+ }
141
+ }
142
+ if (n.isEnum()) {
143
+ const i = n.getSymbol();
144
+ if (i) {
145
+ const s = i.getValueDeclaration();
146
+ if (s && d.isEnumDeclaration(s)) {
147
+ const m = s.getMembers().map((u) => u.getName());
148
+ return console.log(`[AutoUI Type Schema] Extracting enum type "${t}" with values: [${m.join(", ")}]`), e.types.set(t, {
149
+ type: "enum",
150
+ values: m
151
+ }), t;
152
+ }
153
+ }
154
+ }
155
+ if (n.isUnion()) {
156
+ const i = n.getUnionTypes();
157
+ console.log(`[AutoUI Type Schema] Extracting union type "${t}" with ${i.length} union members`);
158
+ const s = [];
159
+ let m = !0, u = !1;
160
+ for (const r of i) {
161
+ if (r.isUndefined() || r.isNull()) {
162
+ u = !0;
163
+ continue;
164
+ }
165
+ if (r.isStringLiteral()) {
166
+ const a = r.getLiteralValue();
167
+ typeof a == "string" ? s.push(a) : m = !1;
168
+ } else
169
+ m = !1;
170
+ }
171
+ if (m && s.length > 0 && !u) {
172
+ const r = n.getSymbol();
173
+ if (r) {
174
+ const a = r.getDeclarations();
175
+ if (a && a.length > 0) {
176
+ const f = a[0];
177
+ if (d.isTypeAliasDeclaration(f)) {
178
+ const y = r.getName();
179
+ return console.log(` → Converting string literal union to enum "${y}" with values: [${s.join(", ")}]`), e.types.set(y, {
180
+ type: "enum",
181
+ values: s
182
+ }), e.typeNames.set(n, y), y;
183
+ }
184
+ }
185
+ }
186
+ }
187
+ const c = [];
188
+ for (const r of i)
189
+ if (!r.isUndefined() && !r.isNull()) {
190
+ const a = T(r, e);
191
+ c.includes(a) || c.push(a);
192
+ }
193
+ if (console.log(` → Union members: [${c.join(", ")}]`), c.length > 1)
194
+ return e.types.set(t, {
195
+ type: "union",
196
+ refs: c
197
+ }), t;
198
+ if (c.length === 1)
199
+ return console.log(` → Single type union (with undefined) - returning "${c[0]}"`), c[0];
200
+ }
201
+ const p = {}, o = [], g = n.getProperties(), l = n.getText();
202
+ console.log(`[AutoUI Type Schema] Extracting object type "${t}":`), console.log(` Type text: ${l.substring(0, 100)}${l.length > 100 ? "..." : ""}`), console.log(` Properties count: ${g.length}`);
203
+ for (const i of g) {
204
+ const s = i.getName();
205
+ if (s.startsWith("__") || s === "toString" || s === "valueOf")
206
+ continue;
207
+ const m = i.getValueDeclaration() || i.getDeclarations()[0];
208
+ if (!m) continue;
209
+ const u = e.checker.getTypeAtLocation(m);
210
+ console.log(` [Object Property] ${s}:`), console.log(` Raw type: ${u.getText()}`);
211
+ const c = v(i, u), r = !c;
212
+ c && console.log(" Detected as optional (question token, union with undefined/null, or default value)");
213
+ const a = A(u);
214
+ a !== u && console.log(` Extracting non-optional type: ${a.getText()}`);
215
+ const f = T(a, e);
216
+ p[s] = { type: f, required: r }, console.log(` → Evaluated type: "${f}" (required: ${r})`), o.includes(f) || o.push(f);
217
+ }
218
+ return e.types.set(t, {
219
+ type: "object",
220
+ properties: p,
221
+ refs: o
222
+ }), t;
223
+ }
224
+ function _(n, e) {
225
+ const t = {};
226
+ let p = null;
227
+ const o = n.getTypeArguments();
228
+ if (o.length > 0)
229
+ p = o[0], console.log(`[AutoUI Type Schema] Extracting component props from generic type argument: ${p.getText()}`);
230
+ else {
231
+ const l = n.getCallSignatures();
232
+ if (l.length > 0) {
233
+ const s = l[0].getParameters();
234
+ if (s.length > 0) {
235
+ const u = s[0].getValueDeclaration();
236
+ u && (p = e.checker.getTypeAtLocation(u), console.log(`[AutoUI Type Schema] Extracting component props from call signature parameter: ${p.getText()}`));
237
+ }
238
+ }
239
+ }
240
+ if (!p)
241
+ return console.log("[AutoUI Type Schema] Could not extract props type from component"), t;
242
+ const g = p.getProperties();
243
+ console.log(`[AutoUI Type Schema] Extracting component props from type: ${p.getText()}`), console.log(`[AutoUI Type Schema] Properties count: ${g.length}`);
244
+ for (const l of g) {
245
+ const i = l.getName();
246
+ if (i.startsWith("__") || i === "toString" || i === "valueOf")
247
+ continue;
248
+ const s = l.getValueDeclaration() || l.getDeclarations()[0];
249
+ if (!s) continue;
250
+ const m = e.checker.getTypeAtLocation(s);
251
+ console.log(` [Component Prop] ${i}:`), console.log(` Raw type: ${m.getText()}`);
252
+ const u = v(l, m), c = !u;
253
+ u && console.log(" Detected as optional (question token, union with undefined/null, or default value)");
254
+ const r = A(m);
255
+ r !== m && console.log(` Extracting non-optional type: ${r.getText()}`);
256
+ const a = T(r, e);
257
+ t[i] = { type: a, required: c }, console.log(` → Evaluated type: "${a}" (required: ${c})`);
258
+ }
259
+ return t;
260
+ }
261
+ function j(n, e) {
262
+ const t = {}, p = n.getCallSignatures();
263
+ if (p.length > 0) {
264
+ const o = p[0], g = o.getParameters();
265
+ console.log(`[AutoUI Type Schema] Extracting function parameters (count: ${g.length})`);
266
+ for (const s of g) {
267
+ const m = s.getName();
268
+ if (m && !m.startsWith("__")) {
269
+ const u = s.getValueDeclaration();
270
+ if (!u) continue;
271
+ const c = e.checker.getTypeAtLocation(u);
272
+ console.log(` [Function Param] ${m}:`), console.log(` Raw type: ${c.getText()}`);
273
+ const r = v(s, c), a = !r;
274
+ r && console.log(" Detected as optional (question token, union with undefined/null, or default value)");
275
+ const f = A(c);
276
+ f !== c && console.log(` Extracting non-optional type: ${f.getText()}`);
277
+ const y = T(f, e);
278
+ t[m] = { type: y, required: a }, console.log(` → Evaluated type: "${y}" (required: ${a})`);
279
+ } else {
280
+ const u = s.getValueDeclaration();
281
+ if (!u) continue;
282
+ const c = e.checker.getTypeAtLocation(u);
283
+ if (console.log(" [Function Param] (destructured):"), console.log(` Raw type: ${c.getText()}`), c.isObject()) {
284
+ const r = c.getProperties();
285
+ console.log(` Extracting destructured object properties (count: ${r.length})`);
286
+ for (const a of r) {
287
+ const f = a.getName();
288
+ if (f.startsWith("__")) continue;
289
+ console.log(` [Destructured Prop] ${f}:`);
290
+ const y = a.getValueDeclaration() || a.getDeclarations()[0];
291
+ if (!y) continue;
292
+ const S = e.checker.getTypeAtLocation(y);
293
+ console.log(` Raw type: ${S.getText()}`);
294
+ const E = v(a, S), b = !E;
295
+ E && console.log(" Detected as optional (question token, union with undefined/null, or default value)");
296
+ const U = A(S);
297
+ U !== S && console.log(` Extracting non-optional type: ${U.getText()}`);
298
+ const D = T(U, e);
299
+ t[f] = { type: D, required: b }, console.log(` → Evaluated type: "${D}" (required: ${b})`);
300
+ }
301
+ } else {
302
+ const r = T(c, e);
303
+ t.param = { type: r, required: !0 }, console.log(` → Evaluated type: "${r}" (required: true)`);
304
+ }
305
+ }
306
+ }
307
+ const l = o.getReturnType(), i = T(l, e);
308
+ return console.log(` [Function Return] → Evaluated type: "${i}"`), { params: t, returns: { type: i } };
309
+ }
310
+ return { params: t, returns: { type: "void" } };
311
+ }
312
+ function q(n, e, t) {
313
+ const o = {
314
+ checker: n.getTypeChecker(),
315
+ types: /* @__PURE__ */ new Map(),
316
+ typeNames: /* @__PURE__ */ new Map(),
317
+ visitedTypes: /* @__PURE__ */ new Set(),
318
+ anonymousTypeCounter: /* @__PURE__ */ new Map()
319
+ };
320
+ console.log(`[AutoUI Type Schema] Starting schema generation for appId: ${e}, version: ${t}`);
321
+ const { components: g, functions: l } = k(n);
322
+ console.log(`[AutoUI Type Schema] Found ${g.length} component(s) and ${l.length} function(s)`);
323
+ const i = [];
324
+ for (const { name: u, type: c } of g) {
325
+ console.log(`
326
+ [AutoUI Type Schema] ========================================`), console.log(`[AutoUI Type Schema] Processing Component: "${u}"`), console.log("[AutoUI Type Schema] ========================================");
327
+ const r = _(c, o);
328
+ i.push({ name: u, props: r }), console.log(`[AutoUI Type Schema] ✓ Component "${u}" processed with ${Object.keys(r).length} prop(s)`);
329
+ }
330
+ const s = [];
331
+ for (const { name: u, type: c } of l) {
332
+ console.log(`
333
+ [AutoUI Type Schema] ========================================`), console.log(`[AutoUI Type Schema] Processing Function: "${u}"`), console.log("[AutoUI Type Schema] ========================================");
334
+ const { params: r, returns: a } = j(c, o);
335
+ s.push({ name: u, params: r, returns: a }), console.log(`[AutoUI Type Schema] ✓ Function "${u}" processed with ${Object.keys(r).length} param(s), return type: "${a.type}"`);
336
+ }
337
+ const m = {};
338
+ for (const [u, c] of o.types.entries())
339
+ m[u] = c;
340
+ return {
341
+ appId: e,
342
+ version: t,
343
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
344
+ types: m,
345
+ components: i,
346
+ functions: s
347
+ };
348
+ }
349
+ function $(n) {
350
+ const e = {};
351
+ if (!N(n))
352
+ return e;
353
+ try {
354
+ const p = P(n, "utf-8").split(`
355
+ `);
356
+ for (const o of p) {
357
+ const g = o.trim();
358
+ if (!g || g.startsWith("#"))
359
+ continue;
360
+ const l = g.match(/^([^=:#]+)=(.*)$/);
361
+ if (l) {
362
+ const i = l[1].trim();
363
+ let s = l[2].trim();
364
+ (s.startsWith('"') && s.endsWith('"') || s.startsWith("'") && s.endsWith("'")) && (s = s.slice(1, -1)), e[i] = s;
365
+ }
366
+ }
367
+ } catch {
368
+ }
369
+ return e;
370
+ }
371
+ function L(n = "development") {
372
+ const e = process.cwd(), t = {}, p = $(h(e, ".env"));
373
+ Object.assign(t, p);
374
+ const o = $(h(e, `.env.${n}`));
375
+ Object.assign(t, o);
376
+ const g = $(h(e, ".env.local"));
377
+ Object.assign(t, g);
378
+ const l = process.env.NODE_ENV || n;
379
+ if (l !== n) {
380
+ const i = $(h(e, `.env.${l}`));
381
+ Object.assign(t, i);
382
+ }
383
+ return t;
384
+ }
385
+ function M(n = {}) {
386
+ const e = n.runtimeSchemaFile || ".autoui-runtime-schema.json";
387
+ return {
388
+ name: "autoui-type-schema",
389
+ enforce: "pre",
390
+ async buildStart() {
391
+ if (process.env.NODE_ENV === "production" || process.env.MODE === "production") {
392
+ console.log("[AutoUI Type Schema Plugin] Skipping schema generation in production build. Using existing schema file.");
393
+ return;
394
+ }
395
+ const g = { ...L("development"), ...process.env }, l = n.appId || g.AUTOUI_APP_ID || "unknown", i = n.version || g.AUTOUI_VERSION || "1.0.0";
396
+ try {
397
+ let s = h(process.cwd(), "tsconfig.app.json");
398
+ if (N(s) || (s = h(process.cwd(), "tsconfig.json")), !N(s)) {
399
+ console.warn("[AutoUI Type Schema Plugin] No tsconfig.json or tsconfig.app.json found, skipping schema extraction");
400
+ return;
401
+ }
402
+ const m = new x({
403
+ tsConfigFilePath: s
404
+ });
405
+ if (m.getSourceFiles().filter(
406
+ (f) => !f.isDeclarationFile() && !f.getFilePath().includes("node_modules")
407
+ ).length === 0) {
408
+ console.warn("[AutoUI Type Schema Plugin] No source files found after filtering!");
409
+ return;
410
+ }
411
+ const c = q(m, l, i);
412
+ if (c.components.length === 0 && c.functions.length === 0)
413
+ return;
414
+ const r = h(process.cwd(), e), a = h(r, "..");
415
+ if (!N(a)) {
416
+ const { mkdirSync: f } = await import("node:fs");
417
+ f(a, { recursive: !0 });
418
+ }
419
+ w(r, JSON.stringify(c, null, 2), "utf-8"), console.log(`[AutoUI Type Schema Plugin] Schema written to ${e}`);
420
+ } catch (s) {
421
+ console.error("❌ [AutoUI Type Schema Plugin] Error in plugin:", s), s instanceof Error && (console.error(` Error message: ${s.message}`), s.stack && console.error(` Stack trace: ${s.stack}`));
422
+ }
423
+ }
424
+ };
425
+ }
426
+ export {
427
+ M as autouiTypeSchemaPlugin
428
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autoai-ui/autoui",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "scripts": {
@@ -9,7 +9,10 @@
9
9
  "build:lib": "vite build --config vite.config.lib.ts",
10
10
  "pack": "npm run build:lib && npm pack",
11
11
  "lint": "eslint .",
12
- "test": "",
12
+ "test": "vitest",
13
+ "test:watch": "vitest --watch",
14
+ "test:run": "vitest run",
15
+ "test:coverage": "vitest run --coverage",
13
16
  "lint:fix": "eslint . --fix",
14
17
  "format": "prettier --write .",
15
18
  "format:check": "prettier --check .",
@@ -29,10 +32,11 @@
29
32
  },
30
33
  "dependencies": {
31
34
  "react-virtuoso": "^4.14.1",
35
+ "ts-morph": "^27.0.2",
32
36
  "vite-plugin-css-injected-by-js": "^3.5.2"
33
37
  },
34
38
  "devDependencies": {
35
- "vite-plugin-css-injected-by-js": "^3.5.2",
39
+ "@autoai-ui/autoui": "^0.2.3",
36
40
  "@changesets/cli": "^2.29.7",
37
41
  "@dnd-kit/core": "^6.3.1",
38
42
  "@dnd-kit/modifiers": "^9.0.0",
@@ -53,6 +57,7 @@
53
57
  "@types/react": "^19.1.16",
54
58
  "@types/react-dom": "^19.1.9",
55
59
  "@vitejs/plugin-react": "^5.0.4",
60
+ "@vitest/coverage-v8": "^4.0.16",
56
61
  "autoprefixer": "^10.4.21",
57
62
  "class-variance-authority": "^0.7.1",
58
63
  "clsx": "^2.1.1",
@@ -83,6 +88,7 @@
83
88
  "typescript-eslint": "^8.45.0",
84
89
  "vite": "^7.1.7",
85
90
  "vite-plugin-dts": "^4.5.4",
91
+ "vitest": "^4.0.16",
86
92
  "zod": "^4.1.12",
87
93
  "zustand": "^5.0.8"
88
94
  },
@@ -95,6 +101,11 @@
95
101
  "types": "./dist/index.d.ts",
96
102
  "import": "./dist/index.mjs",
97
103
  "require": "./dist/index.cjs"
104
+ },
105
+ "./plugin": {
106
+ "types": "./dist/plugin.d.ts",
107
+ "import": "./dist/plugin.mjs",
108
+ "require": "./dist/plugin.cjs"
98
109
  }
99
110
  },
100
111
  "types": "dist/index.d.ts",
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { ChatContextType, ChatProviderPropsType } from '../types';
2
- export declare const ChatProvider: ({ children, value, config }: ChatProviderPropsType) => import("react/jsx-runtime").JSX.Element;
3
- export declare const useChatContext: () => ChatContextType;
@@ -1,9 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { ModalChatContext } from '../types';
3
- import { AutoUIConfig } from '../../../types';
4
- export interface ModalChatProviderProps {
5
- config: AutoUIConfig;
6
- children: ReactNode;
7
- }
8
- export declare const ModalChatProvider: ({ config, children }: ModalChatProviderProps) => import("react/jsx-runtime").JSX.Element;
9
- export declare const useModalChatContext: () => ModalChatContext;
@@ -1,4 +0,0 @@
1
- import { AutoUIConfig } from '../../../types';
2
- export declare function useAutoUiChat(config: AutoUIConfig): {
3
- processMessage: (text: string) => Promise<import('../../..').InstructionPlan>;
4
- };
@@ -1,3 +0,0 @@
1
- import { ChatContextType, ChatProps } from '../types';
2
- export declare function useChat({ config, theme, mode, setTheme, onError, onClose, storageKey, title, classNames, isOpen, }: ChatProps): ChatContextType;
3
- export type UseChatReturn = ReturnType<typeof useChat>;
@@ -1,7 +0,0 @@
1
- import { SerializedMessage, ChatMessage } from '../types';
2
- import { AutoUIConfig } from '../../../types';
3
- export declare function useChatState(storageKey: string, config: AutoUIConfig): {
4
- messages: ChatMessage[];
5
- serializedMessages: SerializedMessage[];
6
- setSerializedMessages: import('react').Dispatch<import('react').SetStateAction<SerializedMessage[]>>;
7
- };
@@ -1,7 +0,0 @@
1
- import { default as React, ComponentType, ReactNode } from 'react';
2
- import { AutoUIConfig } from '../../../types';
3
- export declare function useRendering(config: AutoUIConfig): {
4
- setUIRenderer: (fn: (node: ReactNode | string | ComponentType<any>) => void) => void;
5
- resolveComponent: (name: string, props: any) => ReactNode;
6
- setUI: (ui: React.ReactNode | string) => void;
7
- };
@@ -1,9 +0,0 @@
1
- export declare const useSpeechToText: ({ lang }?: {
2
- lang?: string | undefined;
3
- }) => {
4
- start: () => void;
5
- stop: () => void;
6
- text: string;
7
- listening: boolean;
8
- isSupported: boolean;
9
- };
@@ -1,6 +0,0 @@
1
- export type ThemeMode = 'light' | 'dark' | 'auto';
2
- export declare const useTheme: () => {
3
- mode: ThemeMode;
4
- theme: "light" | "dark";
5
- setTheme: (newMode: ThemeMode) => void;
6
- };
@@ -1,2 +0,0 @@
1
- export { Chat } from './ui/Chat';
2
- export { ModalChat } from './ui/ModalChat';