qtype 0.0.12__py3-none-any.whl → 0.1.7__py3-none-any.whl

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 (137) hide show
  1. qtype/application/commons/tools.py +1 -1
  2. qtype/application/converters/tools_from_api.py +476 -11
  3. qtype/application/converters/tools_from_module.py +38 -14
  4. qtype/application/converters/types.py +15 -30
  5. qtype/application/documentation.py +1 -1
  6. qtype/application/facade.py +102 -85
  7. qtype/base/types.py +227 -7
  8. qtype/cli.py +5 -1
  9. qtype/commands/convert.py +52 -6
  10. qtype/commands/generate.py +44 -4
  11. qtype/commands/run.py +78 -36
  12. qtype/commands/serve.py +74 -44
  13. qtype/commands/validate.py +37 -14
  14. qtype/commands/visualize.py +46 -25
  15. qtype/dsl/__init__.py +6 -5
  16. qtype/dsl/custom_types.py +1 -1
  17. qtype/dsl/domain_types.py +86 -5
  18. qtype/dsl/linker.py +384 -0
  19. qtype/dsl/loader.py +315 -0
  20. qtype/dsl/model.py +753 -264
  21. qtype/dsl/parser.py +200 -0
  22. qtype/dsl/types.py +50 -0
  23. qtype/interpreter/api.py +63 -136
  24. qtype/interpreter/auth/aws.py +19 -9
  25. qtype/interpreter/auth/generic.py +93 -16
  26. qtype/interpreter/base/base_step_executor.py +436 -0
  27. qtype/interpreter/base/batch_step_executor.py +171 -0
  28. qtype/interpreter/base/exceptions.py +50 -0
  29. qtype/interpreter/base/executor_context.py +91 -0
  30. qtype/interpreter/base/factory.py +84 -0
  31. qtype/interpreter/base/progress_tracker.py +110 -0
  32. qtype/interpreter/base/secrets.py +339 -0
  33. qtype/interpreter/base/step_cache.py +74 -0
  34. qtype/interpreter/base/stream_emitter.py +469 -0
  35. qtype/interpreter/conversions.py +495 -24
  36. qtype/interpreter/converters.py +79 -0
  37. qtype/interpreter/endpoints.py +355 -0
  38. qtype/interpreter/executors/agent_executor.py +242 -0
  39. qtype/interpreter/executors/aggregate_executor.py +93 -0
  40. qtype/interpreter/executors/bedrock_reranker_executor.py +195 -0
  41. qtype/interpreter/executors/decoder_executor.py +163 -0
  42. qtype/interpreter/executors/doc_to_text_executor.py +112 -0
  43. qtype/interpreter/executors/document_embedder_executor.py +123 -0
  44. qtype/interpreter/executors/document_search_executor.py +113 -0
  45. qtype/interpreter/executors/document_source_executor.py +118 -0
  46. qtype/interpreter/executors/document_splitter_executor.py +105 -0
  47. qtype/interpreter/executors/echo_executor.py +63 -0
  48. qtype/interpreter/executors/field_extractor_executor.py +165 -0
  49. qtype/interpreter/executors/file_source_executor.py +101 -0
  50. qtype/interpreter/executors/file_writer_executor.py +110 -0
  51. qtype/interpreter/executors/index_upsert_executor.py +232 -0
  52. qtype/interpreter/executors/invoke_embedding_executor.py +104 -0
  53. qtype/interpreter/executors/invoke_flow_executor.py +51 -0
  54. qtype/interpreter/executors/invoke_tool_executor.py +358 -0
  55. qtype/interpreter/executors/llm_inference_executor.py +272 -0
  56. qtype/interpreter/executors/prompt_template_executor.py +78 -0
  57. qtype/interpreter/executors/sql_source_executor.py +106 -0
  58. qtype/interpreter/executors/vector_search_executor.py +91 -0
  59. qtype/interpreter/flow.py +172 -22
  60. qtype/interpreter/logging_progress.py +61 -0
  61. qtype/interpreter/metadata_api.py +115 -0
  62. qtype/interpreter/resource_cache.py +5 -4
  63. qtype/interpreter/rich_progress.py +225 -0
  64. qtype/interpreter/stream/chat/__init__.py +15 -0
  65. qtype/interpreter/stream/chat/converter.py +391 -0
  66. qtype/interpreter/{chat → stream/chat}/file_conversions.py +2 -2
  67. qtype/interpreter/stream/chat/ui_request_to_domain_type.py +140 -0
  68. qtype/interpreter/stream/chat/vercel.py +609 -0
  69. qtype/interpreter/stream/utils/__init__.py +15 -0
  70. qtype/interpreter/stream/utils/build_vercel_ai_formatter.py +74 -0
  71. qtype/interpreter/stream/utils/callback_to_stream.py +66 -0
  72. qtype/interpreter/stream/utils/create_streaming_response.py +18 -0
  73. qtype/interpreter/stream/utils/default_chat_extract_text.py +20 -0
  74. qtype/interpreter/stream/utils/error_streaming_response.py +20 -0
  75. qtype/interpreter/telemetry.py +135 -8
  76. qtype/interpreter/tools/__init__.py +5 -0
  77. qtype/interpreter/tools/function_tool_helper.py +265 -0
  78. qtype/interpreter/types.py +330 -0
  79. qtype/interpreter/typing.py +83 -89
  80. qtype/interpreter/ui/404/index.html +1 -1
  81. qtype/interpreter/ui/404.html +1 -1
  82. qtype/interpreter/ui/_next/static/{OT8QJQW3J70VbDWWfrEMT → 20HoJN6otZ_LyHLHpCPE6}/_buildManifest.js +1 -1
  83. qtype/interpreter/ui/_next/static/chunks/434-b2112d19f25c44ff.js +36 -0
  84. qtype/interpreter/ui/_next/static/chunks/{964-ed4ab073db645007.js → 964-2b041321a01cbf56.js} +1 -1
  85. qtype/interpreter/ui/_next/static/chunks/app/{layout-5ccbc44fd528d089.js → layout-a05273ead5de2c41.js} +1 -1
  86. qtype/interpreter/ui/_next/static/chunks/app/page-8c67d16ac90d23cb.js +1 -0
  87. qtype/interpreter/ui/_next/static/chunks/ba12c10f-546f2714ff8abc66.js +1 -0
  88. qtype/interpreter/ui/_next/static/chunks/{main-6d261b6c5d6fb6c2.js → main-e26b9cb206da2cac.js} +1 -1
  89. qtype/interpreter/ui/_next/static/chunks/webpack-08642e441b39b6c2.js +1 -0
  90. qtype/interpreter/ui/_next/static/css/8a8d1269e362fef7.css +3 -0
  91. qtype/interpreter/ui/_next/static/media/4cf2300e9c8272f7-s.p.woff2 +0 -0
  92. qtype/interpreter/ui/icon.png +0 -0
  93. qtype/interpreter/ui/index.html +1 -1
  94. qtype/interpreter/ui/index.txt +5 -5
  95. qtype/semantic/checker.py +643 -0
  96. qtype/semantic/generate.py +268 -85
  97. qtype/semantic/loader.py +95 -0
  98. qtype/semantic/model.py +535 -163
  99. qtype/semantic/resolver.py +63 -19
  100. qtype/semantic/visualize.py +50 -35
  101. {qtype-0.0.12.dist-info → qtype-0.1.7.dist-info}/METADATA +22 -5
  102. qtype-0.1.7.dist-info/RECORD +137 -0
  103. qtype/dsl/base_types.py +0 -38
  104. qtype/dsl/validator.py +0 -464
  105. qtype/interpreter/batch/__init__.py +0 -0
  106. qtype/interpreter/batch/flow.py +0 -95
  107. qtype/interpreter/batch/sql_source.py +0 -95
  108. qtype/interpreter/batch/step.py +0 -63
  109. qtype/interpreter/batch/types.py +0 -41
  110. qtype/interpreter/batch/utils.py +0 -179
  111. qtype/interpreter/chat/chat_api.py +0 -237
  112. qtype/interpreter/chat/vercel.py +0 -314
  113. qtype/interpreter/exceptions.py +0 -10
  114. qtype/interpreter/step.py +0 -67
  115. qtype/interpreter/steps/__init__.py +0 -0
  116. qtype/interpreter/steps/agent.py +0 -114
  117. qtype/interpreter/steps/condition.py +0 -36
  118. qtype/interpreter/steps/decoder.py +0 -88
  119. qtype/interpreter/steps/llm_inference.py +0 -150
  120. qtype/interpreter/steps/prompt_template.py +0 -54
  121. qtype/interpreter/steps/search.py +0 -24
  122. qtype/interpreter/steps/tool.py +0 -53
  123. qtype/interpreter/streaming_helpers.py +0 -123
  124. qtype/interpreter/ui/_next/static/chunks/736-7fc606e244fedcb1.js +0 -36
  125. qtype/interpreter/ui/_next/static/chunks/app/page-c72e847e888e549d.js +0 -1
  126. qtype/interpreter/ui/_next/static/chunks/ba12c10f-22556063851a6df2.js +0 -1
  127. qtype/interpreter/ui/_next/static/chunks/webpack-8289c17c67827f22.js +0 -1
  128. qtype/interpreter/ui/_next/static/css/a262c53826df929b.css +0 -3
  129. qtype/interpreter/ui/_next/static/media/569ce4b8f30dc480-s.p.woff2 +0 -0
  130. qtype/interpreter/ui/favicon.ico +0 -0
  131. qtype/loader.py +0 -389
  132. qtype-0.0.12.dist-info/RECORD +0 -105
  133. /qtype/interpreter/ui/_next/static/{OT8QJQW3J70VbDWWfrEMT → 20HoJN6otZ_LyHLHpCPE6}/_ssgManifest.js +0 -0
  134. {qtype-0.0.12.dist-info → qtype-0.1.7.dist-info}/WHEEL +0 -0
  135. {qtype-0.0.12.dist-info → qtype-0.1.7.dist-info}/entry_points.txt +0 -0
  136. {qtype-0.0.12.dist-info → qtype-0.1.7.dist-info}/licenses/LICENSE +0 -0
  137. {qtype-0.0.12.dist-info → qtype-0.1.7.dist-info}/top_level.txt +0 -0
@@ -1 +1 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[177],{5688:e=>{e.exports={style:{fontFamily:"'Geist', 'Geist Fallback'",fontStyle:"normal"},className:"__className_6de60c",variable:"__variable_6de60c"}},8866:(e,a,s)=>{Promise.resolve().then(s.t.bind(s,5688,23)),Promise.resolve().then(s.t.bind(s,9432,23)),Promise.resolve().then(s.t.bind(s,9324,23))},9324:()=>{},9432:e=>{e.exports={style:{fontFamily:"'Geist Mono', 'Geist Mono Fallback'",fontStyle:"normal"},className:"__className_152ec0",variable:"__variable_152ec0"}}},e=>{e.O(0,[261,441,964,358],()=>e(e.s=8866)),_N_E=e.O()}]);
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[177],{5688:e=>{e.exports={style:{fontFamily:"'Geist', 'Geist Fallback'",fontStyle:"normal"},className:"__className_c57559",variable:"__variable_c57559"}},8866:(e,a,s)=>{Promise.resolve().then(s.t.bind(s,5688,23)),Promise.resolve().then(s.t.bind(s,9432,23)),Promise.resolve().then(s.t.bind(s,9324,23))},9324:()=>{},9432:e=>{e.exports={style:{fontFamily:"'Geist Mono', 'Geist Mono Fallback'",fontStyle:"normal"},className:"__className_152ec0",variable:"__variable_152ec0"}}},e=>{e.O(0,[261,441,964,358],()=>e(e.s=8866)),_N_E=e.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{2941:(e,t,r)=>{Promise.resolve().then(r.bind(r,6148))},6148:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>eU});var a=r(5155),s=r(2115),n=r(5339),l=r(2085),i=r(2596),d=r(9688);function o(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return(0,d.QP)((0,i.$)(t))}let c=(0,l.F)("relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",{variants:{variant:{default:"bg-card text-card-foreground",destructive:"text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90"}},defaultVariants:{variant:"default"}});function u(e){let{className:t,variant:r,...s}=e;return(0,a.jsx)("div",{"data-slot":"alert",role:"alert",className:o(c({variant:r}),t),...s})}function x(e){let{className:t,...r}=e;return(0,a.jsx)("div",{"data-slot":"alert-title",className:o("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",t),...r})}function m(e){let{className:t,...r}=e;return(0,a.jsx)("div",{"data-slot":"alert-description",className:o("text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed",t),...r})}var p=r(4056);function g(e){let{className:t,...r}=e;return(0,a.jsx)(p.bL,{"data-slot":"tabs",className:o("flex flex-col gap-2",t),...r})}function h(e){let{className:t,...r}=e;return(0,a.jsx)(p.B8,{"data-slot":"tabs-list",className:o("bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",t),...r})}function f(e){let{className:t,...r}=e;return(0,a.jsx)(p.l9,{"data-slot":"tabs-trigger",className:o("data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",t),...r})}function b(e){let{className:t,...r}=e;return(0,a.jsx)(p.UC,{"data-slot":"tabs-content",className:o("flex-1 outline-none",t),...r})}var y=r(838),v=r(9509);class j extends Error{constructor(e,t,r){super(e),this.name="ApiClientError",this.status=t,this.detail=r}}class N{async fetchWithTimeout(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=new AbortController,a=setTimeout(()=>r.abort(),this.config.timeout);try{let s=await fetch(e,{...t,signal:r.signal,headers:{"Content-Type":"application/json",...t.headers}});if(clearTimeout(a),!s.ok){let e;try{e=await s.json()}catch(t){e={message:s.statusText}}let t="API request failed: ".concat(s.status," ").concat(s.statusText);if(null==e?void 0:e.detail){let r="string"==typeof e.detail?e.detail:JSON.stringify(e.detail,null,2);t+="\n".concat(r)}throw new j(t,s.status,e)}return s}catch(e){if(clearTimeout(a),e instanceof j)throw e;if(e instanceof Error&&"AbortError"===e.name)throw new j("Request timeout",408);throw new j("Network error: ".concat(e instanceof Error?e.message:"Unknown error"),0)}}getUrl(e){let t=this.config.baseUrl.endsWith("/")?this.config.baseUrl.slice(0,-1):this.config.baseUrl,r=e.startsWith("/")?e:"/".concat(e);return"".concat(t).concat(r)}async get(e){return(await this.fetchWithTimeout(this.getUrl(e),{method:"GET"})).json()}async post(e,t){return(await this.fetchWithTimeout(this.getUrl(e),{method:"POST",body:t?JSON.stringify(t):void 0})).json()}async executeFlow(e,t){return this.post(e,t)}async getOpenApiSpec(){return this.get("/openapi.json")}async getFlows(){return this.get("/flows")}async healthCheck(){try{return await this.getFlows(),{status:"healthy",timestamp:new Date().toISOString()}}catch(e){throw new j("Health check failed: ".concat(e instanceof Error?e.message:"Unknown error"),500,e)}}getBaseUrl(){return this.config.baseUrl}setBaseUrl(e){this.config.baseUrl=e}constructor(e){this.config={baseUrl:v.env.NEXT_PUBLIC_QTYPE_HOST||"../",timeout:5e5,...e}}}let w=new N,k=()=>w.getOpenApiSpec();var _=r(8827),S=r(9051),C=r(9708);let z=(0,l.F)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",{variants:{variant:{default:"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",destructive:"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",sm:"h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9"}},defaultVariants:{variant:"default",size:"default"}});function A(e){let{className:t,variant:r,size:s,asChild:n=!1,...l}=e,i=n?C.DX:"button";return(0,a.jsx)(i,{"data-slot":"button",className:o(z({variant:r,size:s,className:t})),...l})}var E=r(239);function T(e){let{className:t,...r}=e;return(0,a.jsx)(E.bL,{"data-slot":"switch",className:o("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",t),...r,children:(0,a.jsx)(E.zi,{"data-slot":"switch-thumb",className:o("bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}function q(e){let{name:t,property:r,required:s,value:n=!1,onChange:l}=e;return(0,a.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,a.jsx)(T,{checked:!!n,onCheckedChange:e=>{null==l||l(t,e)},required:s}),(0,a.jsx)("div",{className:"flex-1",children:(0,a.jsx)("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:n?"Enabled":"Disabled"})})]})}var F=r(3008),O=r(9074),P=r(5933),U=r(2355),M=r(3052),D=r(6474),R=r(713),L=r(8934);function I(){let e=(0,P._)(["rtl:**:[.rdp-button_next>svg]:rotate-180"],["rtl:**:[.rdp-button\\_next>svg]:rotate-180"]);return I=function(){return e},e}function B(){let e=(0,P._)(["rtl:**:[.rdp-button_previous>svg]:rotate-180"],["rtl:**:[.rdp-button\\_previous>svg]:rotate-180"]);return B=function(){return e},e}function H(e){let{className:t,classNames:r,showOutsideDays:s=!0,captionLayout:n="label",buttonVariant:l="ghost",formatters:i,components:d,...c}=e,u=(0,R.a)();return(0,a.jsx)(L.h,{showOutsideDays:s,className:o("bg-background group/calendar p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",String.raw(I()),String.raw(B()),t),captionLayout:n,formatters:{formatMonthDropdown:e=>e.toLocaleString("default",{month:"short"}),...i},classNames:{root:o("w-fit",u.root),months:o("flex gap-4 flex-col md:flex-row relative",u.months),month:o("flex flex-col w-full gap-4",u.month),nav:o("flex items-center gap-1 w-full absolute top-0 inset-x-0 justify-between",u.nav),button_previous:o(z({variant:l}),"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",u.button_previous),button_next:o(z({variant:l}),"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",u.button_next),month_caption:o("flex items-center justify-center h-(--cell-size) w-full px-(--cell-size)",u.month_caption),dropdowns:o("w-full flex items-center text-sm font-medium justify-center h-(--cell-size) gap-1.5",u.dropdowns),dropdown_root:o("relative has-focus:border-ring border border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] rounded-md",u.dropdown_root),dropdown:o("absolute bg-popover inset-0 opacity-0",u.dropdown),caption_label:o("select-none font-medium","label"===n?"text-sm":"rounded-md pl-2 pr-1 flex items-center gap-1 text-sm h-8 [&>svg]:text-muted-foreground [&>svg]:size-3.5",u.caption_label),table:"w-full border-collapse",weekdays:o("flex",u.weekdays),weekday:o("text-muted-foreground rounded-md flex-1 font-normal text-[0.8rem] select-none",u.weekday),week:o("flex w-full mt-2",u.week),week_number_header:o("select-none w-(--cell-size)",u.week_number_header),week_number:o("text-[0.8rem] select-none text-muted-foreground",u.week_number),day:o("relative w-full h-full p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md group/day aspect-square select-none",u.day),range_start:o("rounded-l-md bg-accent",u.range_start),range_middle:o("rounded-none",u.range_middle),range_end:o("rounded-r-md bg-accent",u.range_end),today:o("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",u.today),outside:o("text-muted-foreground aria-selected:text-muted-foreground",u.outside),disabled:o("text-muted-foreground opacity-50",u.disabled),hidden:o("invisible",u.hidden),...r},components:{Root:e=>{let{className:t,rootRef:r,...s}=e;return(0,a.jsx)("div",{"data-slot":"calendar",ref:r,className:o(t),...s})},Chevron:e=>{let{className:t,orientation:r,...s}=e;return"left"===r?(0,a.jsx)(U.A,{className:o("size-4",t),...s}):"right"===r?(0,a.jsx)(M.A,{className:o("size-4",t),...s}):(0,a.jsx)(D.A,{className:o("size-4",t),...s})},DayButton:W,WeekNumber:e=>{let{children:t,...r}=e;return(0,a.jsx)("td",{...r,children:(0,a.jsx)("div",{className:"flex size-(--cell-size) items-center justify-center text-center",children:t})})},...d},...c})}function W(e){let{className:t,day:r,modifiers:n,...l}=e,i=(0,R.a)(),d=s.useRef(null);return s.useEffect(()=>{var e;n.focused&&(null==(e=d.current)||e.focus())},[n.focused]),(0,a.jsx)(A,{ref:d,variant:"ghost",size:"icon","data-day":r.date.toLocaleDateString(),"data-selected-single":n.selected&&!n.range_start&&!n.range_end&&!n.range_middle,"data-range-start":n.range_start,"data-range-end":n.range_end,"data-range-middle":n.range_middle,className:o("data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 dark:hover:text-accent-foreground flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md [&>span]:text-xs [&>span]:opacity-70",i.day,t),...l})}var G=r(6059);function Q(e){let{...t}=e;return(0,a.jsx)(G.bL,{"data-slot":"popover",...t})}function V(e){let{...t}=e;return(0,a.jsx)(G.l9,{"data-slot":"popover-trigger",...t})}function J(e){let{className:t,align:r="center",sideOffset:s=4,...n}=e;return(0,a.jsx)(G.ZL,{children:(0,a.jsx)(G.UC,{"data-slot":"popover-content",align:r,sideOffset:s,className:o("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",t),...n})})}function K(e){let{name:t,property:r,value:n,onChange:l,required:i}=e,[d,c]=s.useState(n&&"string"==typeof n?new Date(n):void 0);return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("label",{className:"text-sm font-medium",children:[r.title||"Date"," ",i&&(0,a.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,a.jsxs)(Q,{children:[(0,a.jsx)(V,{asChild:!0,children:(0,a.jsxs)(A,{variant:"outline",className:o("w-full justify-start text-left font-normal",!d&&"text-muted-foreground"),children:[(0,a.jsx)(O.A,{className:"mr-2 h-4 w-4"}),d?(0,F.GP)(d,"PPP"):"Select a date"]})}),(0,a.jsx)(J,{className:"w-auto p-0",children:(0,a.jsx)(H,{mode:"single",selected:d,onSelect:e=>{if(c(e),e){let r=(0,F.GP)(e,"yyyy-MM-dd");null==l||l(t,r)}},initialFocus:!0})})]}),r.description&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:r.description})]})}function $(e){let{className:t,type:r,...s}=e;return(0,a.jsx)("input",{type:r,"data-slot":"input",className:o("file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]","aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",t),...s})}function X(e){let{name:t,property:r,value:n,onChange:l,required:i}=e,{date:d,time:c}=(e=>{var t;if(!e)return{date:void 0,time:""};let r=new Date(e);return isNaN(r.getTime())?{date:void 0,time:""}:{date:r,time:e.includes("T")&&(null==(t=e.split("T")[1])?void 0:t.split(".")[0])||""}})("string"==typeof n?n:void 0),[u,x]=s.useState(d),[m,p]=s.useState(c),g=(e,r)=>{if(!e)return;let a=(0,F.GP)(e,"yyyy-MM-dd"),s="".concat(a,"T").concat(r||"00:00:00");null==l||l(t,s)};return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("label",{className:"text-sm font-medium",children:[r.title||"Date & Time"," ",i&&(0,a.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,a.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,a.jsxs)(Q,{children:[(0,a.jsx)(V,{asChild:!0,children:(0,a.jsxs)(A,{variant:"outline",className:o("w-full justify-start text-left font-normal",!u&&"text-muted-foreground"),children:[(0,a.jsx)(O.A,{className:"mr-2 h-4 w-4"}),u?(0,a.jsxs)("span",{children:[(0,F.GP)(u,"PPP"),m&&(0,a.jsxs)("span",{className:"text-muted-foreground ml-2",children:["at ",m]})]}):"Select date and time"]})}),(0,a.jsx)(J,{className:"w-auto p-0",children:(0,a.jsx)(H,{mode:"single",selected:u,onSelect:e=>{x(e),g(e,m)},initialFocus:!0})})]}),(0,a.jsx)($,{type:"time",value:m,onChange:e=>{var t;p(t=e.target.value),g(u,t)},step:"1",placeholder:"HH:MM:SS",className:"w-full"})]}),r.description&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:r.description})]})}function Y(e){let{name:t,property:r,required:s,value:n,onChange:l}=e,i="integer"===r.type||"int32"===r.format||"int64"===r.format?1:"any";return(0,a.jsx)($,{type:"number",placeholder:r.description||"Enter ".concat(r.title||t),value:String(n||""),onChange:e=>{let a,s=e.target.value;if(""===s){null==l||l(t,0);return}isNaN(a="integer"===r.type||"int32"===r.format||"int64"===r.format?parseInt(s,10):parseFloat(s))||null==l||l(t,a)},required:s,step:i,min:r.minimum,max:r.maximum,className:"w-full"})}function Z(e){let{name:t,property:r,required:s,value:n="",onChange:l}=e;return(0,a.jsx)($,{type:"text",placeholder:r.description||"Enter ".concat(r.title||t),value:String(n||""),onChange:e=>{null==l||l(t,e.target.value)},required:s,className:"w-full"})}function ee(e){let{name:t,property:r,value:n,onChange:l,required:i}=e,[d,o]=s.useState(String(n||""));return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("label",{className:"text-sm font-medium",children:[r.title||"Time"," ",i&&(0,a.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,a.jsx)($,{type:"time",value:d,onChange:e=>{var r;o(r=e.target.value),null==l||l(t,r)},step:"1",className:"w-full",placeholder:"HH:MM:SS"}),r.description&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:r.description})]})}function et(e){let{name:t,property:r,required:s,value:n,onChange:l}=e;return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:[r.title||t,s&&(0,a.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),r.description&&(0,a.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:r.description}),(()=>{switch(r.qtype_type){case"text":return(0,a.jsx)(Z,{name:t,property:r,required:s,value:n,onChange:l});case"date":return(0,a.jsx)(K,{name:t,property:r,required:s,value:n,onChange:l});case"time":return(0,a.jsx)(ee,{name:t,property:r,required:s,value:n,onChange:l});case"datetime":return(0,a.jsx)(X,{name:t,property:r,required:s,value:n,onChange:l});case"boolean":return(0,a.jsx)(q,{name:t,property:r,required:s,value:n,onChange:l});case"number":case"int":case"float":return(0,a.jsx)(Y,{name:t,property:r,required:s,value:n,onChange:l});case"bytes":case"file":case"image":case"audio":case"video":return(0,a.jsx)("div",{className:"bg-gray-50 dark:bg-gray-900 p-3 rounded border",children:(0,a.jsx)("p",{className:"text-xs text-gray-600 dark:text-gray-400",children:"File upload input coming soon..."})});default:return(0,a.jsx)(u,{variant:"destructive",children:(0,a.jsxs)(m,{children:["Unknown input type:"," ",(0,a.jsx)("code",{className:"font-mono text-sm",children:r.type})]})})}})()]})}function er(e){let{requestSchema:t,onInputChange:r}=e,[n,l]=(0,s.useState)({});if(!t)return(0,a.jsx)("div",{className:"text-gray-500 dark:text-gray-400 text-sm",children:"No input parameters required for this flow."});let i=t.properties||{},d=t.required||[],o=(e,t)=>{let a={...n,[e]:t};l(a),null==r||r(a)};return 0===Object.keys(i).length?(0,a.jsx)("div",{className:"text-gray-500 dark:text-gray-400 text-sm",children:"No input parameters defined for this flow."}):(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)("h5",{className:"font-medium text-gray-900 dark:text-white",children:"Inputs"}),(0,a.jsx)("div",{className:"space-y-4",children:Object.entries(i).map(e=>{let[t,r]=e;return(0,a.jsx)(et,{name:t,property:r,required:d.includes(t),value:n[t],onChange:o},t)})})]})}var ea=r(8240),es=r(4823);function en(e){let{children:t}=e;return(0,a.jsx)("div",{className:"bg-gray-50 dark:bg-gray-900 p-3 rounded",children:(0,a.jsx)(ea.oz,{remarkPlugins:[es.A],components:{code:e=>{let{children:t,...r}=e;return r.className?(0,a.jsx)("pre",{className:"bg-gray-100 dark:bg-gray-800 p-2 rounded text-xs overflow-x-auto",children:(0,a.jsx)("code",{...r,children:t})}):(0,a.jsx)("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 py-0.5 rounded text-xs",...r,children:t})},table:e=>{let{children:t}=e;return(0,a.jsx)("div",{className:"overflow-x-auto mb-4",children:(0,a.jsx)("table",{className:"min-w-full border-collapse border border-gray-300 dark:border-gray-600",children:t})})},thead:e=>{let{children:t}=e;return(0,a.jsx)("thead",{className:"bg-gray-100 dark:bg-gray-800",children:t})},tbody:e=>{let{children:t}=e;return(0,a.jsx)("tbody",{children:t})},tr:e=>{let{children:t}=e;return(0,a.jsx)("tr",{className:"border-b border-gray-200 dark:border-gray-700",children:t})},th:e=>{let{children:t}=e;return(0,a.jsx)("th",{className:"px-3 py-2 text-left text-xs font-medium text-gray-700 dark:text-gray-300 border-r border-gray-300 dark:border-gray-600 last:border-r-0",children:t})},td:e=>{let{children:t}=e;return(0,a.jsx)("td",{className:"px-3 py-2 text-xs text-gray-600 dark:text-gray-400 border-r border-gray-300 dark:border-gray-600 last:border-r-0",children:t})},h1:e=>{let{children:t}=e;return(0,a.jsx)("h1",{className:"text-xl font-bold mb-4 mt-6 text-gray-900 dark:text-gray-100 border-b border-gray-200 dark:border-gray-700 pb-2",children:t})},h2:e=>{let{children:t}=e;return(0,a.jsx)("h2",{className:"text-lg font-semibold mb-3 mt-5 text-gray-900 dark:text-gray-100",children:t})},h3:e=>{let{children:t}=e;return(0,a.jsx)("h3",{className:"text-base font-semibold mb-2 mt-4 text-gray-800 dark:text-gray-200",children:t})},h4:e=>{let{children:t}=e;return(0,a.jsx)("h4",{className:"text-sm font-medium mb-2 mt-3 text-gray-700 dark:text-gray-300",children:t})},ul:e=>{let{children:t}=e;return(0,a.jsx)("ul",{className:"mb-3 pl-0 space-y-1 text-gray-800 dark:text-gray-200",children:t})},ol:e=>{let{children:t}=e;return(0,a.jsx)("ol",{className:"mb-3 pl-0 space-y-1 text-gray-800 dark:text-gray-200",children:t})},li:e=>{let{children:t}=e;return(0,a.jsxs)("li",{className:"flex items-start ml-4",children:[(0,a.jsx)("span",{className:"mr-2 text-gray-500 dark:text-gray-400 select-none",children:"•"}),(0,a.jsx)("span",{className:"flex-1",children:t})]})},p:e=>{let{children:t}=e;return(0,a.jsx)("p",{className:"mb-3 text-gray-800 dark:text-gray-200 leading-relaxed",children:t})},strong:e=>{let{children:t}=e;return(0,a.jsx)("strong",{className:"font-semibold text-gray-900 dark:text-gray-100",children:t})},blockquote:e=>{let{children:t}=e;return(0,a.jsx)("blockquote",{className:"border-l-4 border-gray-300 dark:border-gray-600 pl-4 italic mb-3 text-gray-700 dark:text-gray-300",children:t})}},children:t})})}function el(e){var t;let{flow:r}=e,n=r.endpoints.stream,l=eO(r.id),i=r.description,d=r.input_schema,[o,c]=(0,s.useState)({}),[x,p]=(0,s.useState)(null),g="".concat(w.getBaseUrl().replace(/\/$/,"")).concat(n),{completion:h,complete:f,isLoading:b,error:y}=(0,_.sQ)({api:g}),v=(0,s.useCallback)(()=>{var e,t;if("question"in o)return String(null!=(e=o.question)?e:"");let r=Object.keys(o);return 1===r.length?String(null!=(t=o[r[0]])?t:""):""},[o]),N=async()=>{p(null);let e=v().trim();if(!e)return void p("Provide a 'question' input (or a single input field).");try{await f(e)}catch(e){p(e instanceof j||e instanceof Error?e.message:"Streaming failed")}};return(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"border-b pb-4",children:[(0,a.jsx)("h3",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:l}),(0,a.jsxs)("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:[g," • POST (stream)"]}),i&&(0,a.jsx)("p",{className:"text-gray-600 dark:text-gray-300 mt-2",children:i})]}),(0,a.jsx)(er,{requestSchema:d||null,onInputChange:e=>{c(e)}}),(0,a.jsxs)("div",{children:[(x||y)&&(0,a.jsx)(u,{variant:"destructive",className:"mb-4",children:(0,a.jsx)(m,{className:"whitespace-pre-line",children:null!=(t=x||(null==y?void 0:y.message))?t:"Error"})}),h&&(0,a.jsx)(S.FK,{className:"flex-1 min-h-0",children:(0,a.jsx)(en,{children:h})})]}),(0,a.jsx)("div",{className:"mt-6 pt-4 border-t flex gap-2",children:(0,a.jsx)(A,{disabled:b,onClick:N,children:b?"Streaming...":"Execute Flow"})})]})}var ei=r(3736),ed=r(5657),eo=r(5736),ec=r(492),eu=r(1154),ex=r(2486),em=r(4416);function ep(e){let{files:t,onRemoveFile:r,onClearAll:s}=e;return(0,a.jsxs)("div",{className:"mb-3 p-2 bg-muted rounded",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsxs)("span",{className:"text-sm font-medium",children:["Attachments (",t.length,")"]}),(0,a.jsx)(A,{type:"button",variant:"ghost",size:"sm",onClick:s,className:"h-6 px-2",children:"Clear all"})]}),(0,a.jsx)("div",{className:"space-y-1",children:t.map((e,t)=>{let s;return(0,a.jsxs)("div",{className:"flex items-center justify-between bg-background rounded p-2",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,a.jsx)(ec.A,{className:"h-4 w-4 flex-shrink-0"}),(0,a.jsx)("span",{className:"text-sm truncate",children:e.filename}),(0,a.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",(s=e.size||0,"".concat((s/1048576).toFixed(1)," MB")),")"]})]}),(0,a.jsx)(A,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(t),className:"h-6 w-6 p-0 flex-shrink-0","aria-label":"Remove ".concat(e.filename),children:(0,a.jsx)(em.A,{className:"h-3 w-3"})})]},"".concat(e.filename,"-").concat(t))})})]})}var eg=r(1007),eh=r(4011);function ef(e){let{className:t,...r}=e;return(0,a.jsx)(eh.bL,{"data-slot":"avatar",className:o("relative flex size-8 shrink-0 overflow-hidden rounded-full",t),...r})}function eb(e){let{className:t,...r}=e;return(0,a.jsx)(eh.H4,{"data-slot":"avatar-fallback",className:o("bg-muted flex size-full items-center justify-center rounded-full",t),...r})}function ey(e){let{mediaType:t,filename:r,url:s,size:n}=e;if(!s)return null;let l=null==t?void 0:t.startsWith("image/");return(0,a.jsx)("div",{className:"border rounded p-2 bg-background",children:l?(0,a.jsx)("img",{src:s,alt:r||"Attached image",className:"max-w-full h-auto rounded",style:{maxHeight:"200px"}}):(0,a.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,a.jsx)(ec.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{children:r||"Attachment"}),t&&(0,a.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",t,")"]}),n&&(0,a.jsxs)("span",{className:"text-xs text-muted-foreground",children:["- ","".concat((n/1048576).toFixed(1)," MB")]})]})})}function ev(e){let{message:t}=e,r="user"===t.role,n=(0,s.useMemo)(()=>{var e;return t.content||(null==(e=t.parts)?void 0:e.filter(e=>"text"===e.type).map(e=>"text"in e?e.text:"").join(""))||""},[t]),l=(0,s.useMemo)(()=>{var e;return t.files||t.experimental_attachments||(null==(e=t.parts)?void 0:e.filter(e=>"file"===e.type))||[]},[t]);return(0,a.jsxs)("div",{className:"flex gap-3 w-full ".concat(r?"justify-end":"justify-start"),children:[!r&&(0,a.jsx)(ef,{className:"h-8 w-8 flex-shrink-0",children:(0,a.jsx)(eb,{children:(0,a.jsx)(ed.A,{className:"h-4 w-4"})})}),(0,a.jsxs)("div",{className:"flex-1 max-w-[75%] space-y-2",children:[n&&(0,a.jsx)("div",{className:"rounded-lg px-3 py-2 text-sm whitespace-pre-wrap break-words ".concat(r?"bg-primary text-primary-foreground":"bg-muted"),children:n}),l.map((e,t)=>(0,a.jsx)(ey,{mediaType:e.mediaType,filename:e.filename,url:e.url,size:e.size},"".concat(e.filename,"-").concat(t)))]}),r&&(0,a.jsx)(ef,{className:"h-8 w-8 flex-shrink-0",children:(0,a.jsx)(eb,{children:(0,a.jsx)(eg.A,{className:"h-4 w-4"})})})]})}function ej(e){let{className:t,...r}=e;return(0,a.jsx)("div",{"data-slot":"card",className:o("bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",t),...r})}function eN(e){let{className:t,...r}=e;return(0,a.jsx)("div",{"data-slot":"card-header",className:o("@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",t),...r})}function ew(e){let{className:t,...r}=e;return(0,a.jsx)("div",{"data-slot":"card-title",className:o("leading-none font-semibold",t),...r})}function ek(e){let{className:t,...r}=e;return(0,a.jsx)("div",{"data-slot":"card-description",className:o("text-muted-foreground text-sm",t),...r})}function e_(e){let{className:t,...r}=e;return(0,a.jsx)("div",{"data-slot":"card-content",className:o("px-6",t),...r})}function eS(e){let{className:t,children:r,...s}=e;return(0,a.jsxs)(S.bL,{"data-slot":"scroll-area",className:o("relative",t),...s,children:[(0,a.jsx)(S.LM,{"data-slot":"scroll-area-viewport",className:"focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1",children:r}),(0,a.jsx)(eC,{}),(0,a.jsx)(S.OK,{})]})}function eC(e){let{className:t,orientation:r="vertical",...s}=e;return(0,a.jsx)(S.VM,{"data-slot":"scroll-area-scrollbar",orientation:r,className:o("flex touch-none p-px transition-colors select-none","vertical"===r&&"h-full w-2.5 border-l border-l-transparent","horizontal"===r&&"h-2.5 flex-col border-t border-t-transparent",t),...s,children:(0,a.jsx)(S.lr,{"data-slot":"scroll-area-thumb",className:"bg-border relative flex-1 rounded-full"})})}let ez=()=>"".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,12));function eA(e){let{flow:t}=e,r=t.endpoints.stream,n=eO(t.id),l=t.description,[i,d]=(0,s.useState)(()=>ez()),[o,c]=(0,s.useState)(""),[u,x]=(0,s.useState)([]),[m,p]=(0,s.useState)(null),[g,h]=(0,s.useState)(null),f=(0,s.useRef)(null),b=(0,s.useRef)(null),y=(0,s.useRef)(null),v=(0,s.useMemo)(()=>new ei.rL({api:"".concat(w.getBaseUrl().replace(/\/$/,"")).concat(r)}),[r]),{messages:j,sendMessage:N,status:k,error:S,setMessages:C}=(0,_.Y_)({id:i,transport:v,onFinish:()=>{h(null)}}),z="streaming"===k||"submitted"===k,E=("ready"===k||"error"===k)&&(o.trim()||u.length>0),T=(0,s.useCallback)(()=>{var e;null==(e=y.current)||e.scrollIntoView({behavior:"smooth"})},[]);(0,s.useEffect)(()=>{T()},[j,T]),(0,s.useEffect)(()=>{S&&g&&(c(g.input),x(g.files),h(null),C(e=>((e=e.filter(e=>e.parts.length>0)).length>0&&e.pop(),e)))},[S,g]),(0,s.useEffect)(()=>{var e;"ready"===k&&(null==(e=f.current)||e.focus())},[k]);let q=(0,s.useCallback)(()=>{c(""),x([]),p(null),b.current&&(b.current.value="")},[]),F=(0,s.useCallback)(()=>{d(ez()),C([]),h(null),q()},[C,q]),O=(0,s.useCallback)(e=>new Promise((t,r)=>{let a=new FileReader;a.onload=()=>t(a.result),a.onerror=r,a.readAsDataURL(e)}),[]),P=(0,s.useCallback)(async e=>{let t=e.target.files;if(t){p(null);try{let e=await Promise.all(Array.from(t).map(async e=>{let t=await O(e);return{type:"file",mediaType:e.type||"application/octet-stream",filename:e.name,url:t,size:e.size}}));x(t=>[...t,...e])}catch(t){let e=t instanceof Error?t.message:"Unknown error occurred";p("Failed to process files: ".concat(e))}}},[O]),U=(0,s.useCallback)(e=>{x(t=>t.filter((t,r)=>r!==e))},[]),M=(0,s.useCallback)(()=>{x([]),b.current&&(b.current.value="")},[]),D=(0,s.useCallback)(async e=>{if(e.preventDefault(),!E)return;let t=o.trim(),r=[...u];h({input:t,files:r}),q(),r.length>0?await N({role:"user",parts:[{type:"text",text:t||"[Files attached]"},...r.map(e=>({type:"file",mediaType:e.mediaType,filename:e.filename,url:e.url,size:e.size}))]}):await N({text:t})},[E,o,u,N,q]);return(0,a.jsxs)(ej,{className:"w-full max-w-4xl mx-auto h-[calc(100vh-12rem)] flex flex-col",children:[(0,a.jsx)(eN,{className:"flex-shrink-0",children:(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsxs)("div",{children:[(0,a.jsxs)(ew,{className:"flex items-center gap-2",children:[(0,a.jsx)(ed.A,{className:"h-5 w-5"}),n]}),l&&(0,a.jsx)(ek,{children:l})]}),(0,a.jsxs)(A,{variant:"outline",size:"sm",onClick:F,disabled:z,className:"flex items-center gap-2",children:[(0,a.jsx)(eo.A,{className:"h-4 w-4"}),"New Conversation"]})]})}),(0,a.jsxs)(e_,{className:"flex-1 flex flex-col p-0 min-h-0",children:[(0,a.jsx)(eS,{className:"flex-1 min-h-0",children:(0,a.jsxs)("div",{className:"space-y-4 p-4",children:[0===j.length?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-[400px] text-center text-muted-foreground",children:[(0,a.jsx)(ed.A,{className:"h-12 w-12 mb-4 opacity-50"}),(0,a.jsx)("p",{children:"Start a conversation!"})]}):j.map(e=>(0,a.jsx)(ev,{message:e},e.id)),(0,a.jsx)("div",{ref:y})]})}),(0,a.jsxs)("div",{className:"border-t p-4",children:[S&&(0,a.jsxs)("div",{className:"mb-3 p-2 bg-destructive/10 text-destructive text-sm rounded",children:["Error: ",S.message]}),m&&(0,a.jsx)("div",{className:"mb-3 p-2 bg-destructive/10 text-destructive text-sm rounded",children:m}),u.length>0&&(0,a.jsx)(ep,{files:u,onRemoveFile:U,onClearAll:M}),(0,a.jsxs)("form",{onSubmit:D,className:"flex gap-2",children:[(0,a.jsx)("input",{ref:b,type:"file",multiple:!0,onChange:P,className:"hidden",accept:"*"}),(0,a.jsx)(A,{type:"button",variant:"outline",size:"icon",onClick:()=>{var e;return null==(e=b.current)?void 0:e.click()},disabled:z,"aria-label":"Attach file",children:(0,a.jsx)(ec.A,{className:"h-4 w-4"})}),(0,a.jsx)($,{ref:f,value:o,onChange:e=>c(e.target.value),onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&E&&(e.preventDefault(),D(e))},disabled:z,placeholder:"Type your message... (Enter to send, Shift+Enter for new line)",className:"flex-1",autoFocus:!0}),(0,a.jsx)(A,{type:"submit",disabled:!E,size:"icon","aria-label":"Send message",children:z?(0,a.jsx)(eu.A,{className:"h-4 w-4 animate-spin"}):(0,a.jsx)(ex.A,{className:"h-4 w-4"})})]})]})]})]})}function eE(e){let{name:t,property:r,value:s}=e;return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:r.title||t}),r.description&&(0,a.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:r.description}),(()=>{switch(r.qtype_type){case"text":return(0,a.jsx)(en,{children:String(s)});case"boolean":return(0,a.jsx)("div",{className:"bg-gray-50 dark:bg-gray-900 p-3 rounded",children:(0,a.jsx)("p",{className:"text-gray-800 dark:text-gray-200",children:String(s)})});case"number":case"int":case"float":return(0,a.jsx)("div",{className:"bg-gray-50 dark:bg-gray-900 p-3 rounded",children:(0,a.jsx)("p",{className:"text-gray-800 dark:text-gray-200 font-mono",children:String(s)})});default:return(0,a.jsx)(u,{variant:"destructive",children:(0,a.jsxs)(m,{children:["Unsupported response type:"," ",(0,a.jsx)("code",{className:"font-mono text-sm",children:r.qtype_type||r.type})]})})}})()]})}function eT(e){let{responseSchema:t,responseData:r}=e;if(!r)return(0,a.jsx)("div",{className:"text-gray-500 dark:text-gray-400 text-sm",children:"No response data to display"});if(!(null==t?void 0:t.properties))return(0,a.jsx)("div",{className:"bg-gray-50 dark:bg-gray-900 p-4 rounded",children:(0,a.jsx)("pre",{className:"text-xs text-gray-800 dark:text-gray-200 overflow-x-auto whitespace-pre-wrap",children:JSON.stringify(r,null,2)})});let s=r&&"object"==typeof r?r.outputs||r:r||{};return(0,a.jsx)("div",{className:"space-y-4",children:t.properties&&Object.entries(t.properties).map(e=>{let[t,r]=e,n=s[t];return null==n?null:(0,a.jsx)(eE,{name:t,property:r,value:n},t)})})}function eq(e){let{flow:t}=e,r=t.endpoints.rest,n=eO(t.id),l=t.description,i=t.input_schema,[d,o]=(0,s.useState)({}),[c,x]=(0,s.useState)(!1),[p,g]=(0,s.useState)(null),[h,f]=(0,s.useState)(null),b=async()=>{x(!0),f(null),g(null);try{let e=await w.executeFlow(r,d);g(e)}catch(e){e instanceof j?f(e.message):f(e instanceof Error?e.message:"An unknown error occurred")}finally{x(!1)}};return(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"border-b pb-4",children:[(0,a.jsx)("h3",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:n}),(0,a.jsxs)("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:[r," • POST"]}),l&&(0,a.jsx)("p",{className:"text-gray-600 dark:text-gray-300 mt-2",children:l})]}),(0,a.jsx)(er,{requestSchema:i||null,onInputChange:e=>{o(e)}}),(0,a.jsxs)("div",{children:[h&&(0,a.jsx)(u,{variant:"destructive",className:"mb-4",children:(0,a.jsx)(m,{children:(0,a.jsxs)("div",{className:"whitespace-pre-line",children:[(0,a.jsx)("span",{className:"font-medium",children:"Error:"}),(0,a.jsx)("br",{}),h]})})}),p&&(0,a.jsxs)("div",{className:"space-y-4",children:[p.errors&&p.errors.length>0&&(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("h4",{className:"text-sm font-semibold text-red-600 dark:text-red-400",children:["Errors (",p.errors.length,")"]}),p.errors.map((e,t)=>(0,a.jsx)(u,{variant:"destructive",children:(0,a.jsx)(m,{children:(0,a.jsx)("pre",{className:"text-xs whitespace-pre-wrap",children:JSON.stringify(e,null,2)})})},t))]}),p.outputs&&p.outputs.length>0&&(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("h4",{className:"text-sm font-semibold text-gray-700 dark:text-gray-300",children:["Outputs (",p.outputs.length,")"]}),p.outputs.map((e,r)=>(0,a.jsxs)("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4",children:[p.outputs.length>1&&(0,a.jsxs)("div",{className:"text-xs text-gray-500 dark:text-gray-400 mb-2",children:["Result ",r+1]}),(0,a.jsx)(eT,{responseSchema:t.output_schema,responseData:e})]},r))]}),(!p.outputs||0===p.outputs.length)&&(!p.errors||0===p.errors.length)&&(0,a.jsx)("div",{className:"text-gray-500 dark:text-gray-400 text-sm",children:"No results returned"})]})]}),(0,a.jsx)("div",{className:"mt-6 pt-4 border-t",children:(0,a.jsx)(A,{disabled:c,onClick:b,children:c?"Executing...":"Execute Flow"})})]})}function eF(e){let{flows:t}=e;return(0,a.jsx)(h,{className:"grid w-full",style:{gridTemplateColumns:"repeat(".concat(t.length,", minmax(0, 1fr))")},children:t.map(e=>{let{id:t}=e;return(0,a.jsx)(f,{value:t,className:"text-sm",children:eO(t)},t)})})}function eO(e){return e.split("_").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}function eP(){var e;let{flows:t,isLoading:r,error:s}=function(){let{data:e,error:t,isLoading:r,mutate:a}=(0,y.Ay)("/flows",()=>w.getFlows(),{refreshInterval:3e5,revalidateOnFocus:!1,errorRetryCount:3,errorRetryInterval:5e3});return{flows:e,isLoading:r,error:t,refresh:a}}();return r?(0,a.jsx)("p",{className:"text-muted-foreground text-sm",children:"Loading flows..."}):s?(0,a.jsxs)(u,{variant:"destructive",children:[(0,a.jsx)(n.A,{className:"h-4 w-4"}),(0,a.jsx)(x,{children:"Failed to load flows"}),(0,a.jsx)(m,{children:s.message})]}):t&&t.length?(0,a.jsxs)(g,{defaultValue:null==(e=t[0])?void 0:e.id,className:"w-full",children:[t.length>1&&(0,a.jsx)(eF,{flows:t}),t.map(e=>(0,a.jsxs)(b,{value:e.id,className:"mt-6",children:["Conversational"===e.interface_type&&(0,a.jsx)(eA,{flow:e}),"Complete"===e.interface_type&&(0,a.jsx)(el,{flow:e}),!e.interface_type&&(0,a.jsx)(eq,{flow:e})]},e.id))]}):(0,a.jsxs)(u,{children:[(0,a.jsx)(n.A,{className:"h-4 w-4"}),(0,a.jsx)(x,{children:"No flows found"}),(0,a.jsx)(m,{children:"No flows were found in the API. Make sure your QType application has flows defined."})]})}function eU(){var e,t;let{spec:r,isLoading:n}=function(){let{data:e,error:t,isLoading:r,mutate:a}=(0,y.Ay)("/openapi.json",k,{refreshInterval:3e5,revalidateOnFocus:!1,errorRetryCount:3,errorRetryInterval:5e3});return{spec:e,isLoading:r,error:t,refresh:a}}(),l=(null==r||null==(e=r.info)?void 0:e.title)||"QType Frontend";return(0,s.useEffect)(()=>{n||(document.title=l)},[l,n]),(0,a.jsx)("div",{className:"font-sans min-h-screen p-6 sm:p-8",children:(0,a.jsxs)("main",{className:"max-w-6xl mx-auto space-y-6",children:[(0,a.jsxs)("div",{className:"text-center border-b pb-4",children:[(0,a.jsx)("h1",{className:"text-4xl font-bold text-gray-900 dark:text-white mb-2",children:l}),(null==r||null==(t=r.info)?void 0:t.description)&&(0,a.jsx)("p",{className:"text-gray-600 dark:text-gray-400 text-lg",children:r.info.description})]}),(0,a.jsx)(eP,{})]})})}}},e=>{e.O(0,[803,434,441,964,358],()=>e(e.s=2941)),_N_E=e.O()}]);
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[803],{3736:(e,t,a)=>{a.d(t,{$L:()=>X,rL:()=>ea,vl:()=>es});var s,r=a(7013),o=a(9143),i=a(3201),l=Object.defineProperty,n=Symbol.for("vercel.ai.error.AI_NoOutputSpecifiedError");o.bD;Symbol.for("vercel.ai.error.AI_InvalidArgumentError");o.bD;Symbol.for("vercel.ai.error.AI_InvalidStreamPartError");o.bD;Symbol.for("vercel.ai.error.AI_InvalidToolInputError");o.bD;Symbol.for("vercel.ai.error.AI_MCPClientError");o.bD;Symbol.for("vercel.ai.error.AI_NoImageGeneratedError");o.bD;var u="AI_NoObjectGeneratedError",d=`vercel.ai.error.${u}`,p=Symbol.for(d),c=class extends o.bD{constructor({message:e="No object generated.",cause:t,text:a,response:r,usage:o,finishReason:i}){super({name:u,message:e,cause:t}),this[s]=!0,this.text=a,this.response=r,this.usage=o,this.finishReason=i}static isInstance(e){return o.bD.hasMarker(e,d)}};s=p;Symbol.for("vercel.ai.error.AI_NoSuchToolError");o.bD;Symbol.for("vercel.ai.error.AI_ToolCallRepairError");o.bD,o.bD;Symbol.for("vercel.ai.error.AI_InvalidDataContentError");o.bD;Symbol.for("vercel.ai.error.AI_InvalidMessageRoleError");o.bD;Symbol.for("vercel.ai.error.AI_MessageConversionError");o.bD;Symbol.for("vercel.ai.error.AI_DownloadError");o.bD;Symbol.for("vercel.ai.error.AI_RetryError");o.bD;var h=i.KC([i.Yj(),i.Nl(Uint8Array),i.Nl(ArrayBuffer),i.Ie(e=>{var t,a;return null!=(a=null==(t=globalThis.Buffer)?void 0:t.isBuffer(e))&&a},{message:"Must be a Buffer"})]),m=i.RZ(()=>i.KC([i.ch(),i.Yj(),i.ai(),i.zM(),i.g1(i.Yj(),m),i.YO(m)])),I=i.g1(i.Yj(),i.g1(i.Yj(),m)),g=i.Ik({type:i.eu("text"),text:i.Yj(),providerOptions:I.optional()}),v=i.Ik({type:i.eu("image"),image:i.KC([h,i.Nl(URL)]),mediaType:i.Yj().optional(),providerOptions:I.optional()}),E=i.Ik({type:i.eu("file"),data:i.KC([h,i.Nl(URL)]),filename:i.Yj().optional(),mediaType:i.Yj(),providerOptions:I.optional()}),y=i.Ik({type:i.eu("reasoning"),text:i.Yj(),providerOptions:I.optional()}),f=i.Ik({type:i.eu("tool-call"),toolCallId:i.Yj(),toolName:i.Yj(),input:i.L5(),providerOptions:I.optional(),providerExecuted:i.zM().optional()}),b=i.gM("type",[i.Ik({type:i.eu("text"),value:i.Yj()}),i.Ik({type:i.eu("json"),value:m}),i.Ik({type:i.eu("error-text"),value:i.Yj()}),i.Ik({type:i.eu("error-json"),value:m}),i.Ik({type:i.eu("content"),value:i.YO(i.KC([i.Ik({type:i.eu("text"),text:i.Yj()}),i.Ik({type:i.eu("media"),data:i.Yj(),mediaType:i.Yj()})]))})]),T=i.Ik({type:i.eu("tool-result"),toolCallId:i.Yj(),toolName:i.Yj(),output:b,providerOptions:I.optional()}),_=i.Ik({role:i.eu("system"),content:i.Yj(),providerOptions:I.optional()}),x=i.Ik({role:i.eu("user"),content:i.KC([i.Yj(),i.YO(i.KC([g,v,E]))]),providerOptions:I.optional()}),C=i.Ik({role:i.eu("assistant"),content:i.KC([i.Yj(),i.YO(i.KC([g,E,y,f,T]))]),providerOptions:I.optional()}),M=i.Ik({role:i.eu("tool"),content:i.YO(T),providerOptions:I.optional()});i.KC([_,x,C,M]),(0,r.hK)({prefix:"aitxt",size:24}),TransformStream;var R=i.KC([i.re({type:i.eu("text-start"),id:i.Yj(),providerMetadata:I.optional()}),i.re({type:i.eu("text-delta"),id:i.Yj(),delta:i.Yj(),providerMetadata:I.optional()}),i.re({type:i.eu("text-end"),id:i.Yj(),providerMetadata:I.optional()}),i.re({type:i.eu("error"),errorText:i.Yj()}),i.re({type:i.eu("tool-input-start"),toolCallId:i.Yj(),toolName:i.Yj(),providerExecuted:i.zM().optional(),dynamic:i.zM().optional()}),i.re({type:i.eu("tool-input-delta"),toolCallId:i.Yj(),inputTextDelta:i.Yj()}),i.re({type:i.eu("tool-input-available"),toolCallId:i.Yj(),toolName:i.Yj(),input:i.L5(),providerExecuted:i.zM().optional(),providerMetadata:I.optional(),dynamic:i.zM().optional()}),i.re({type:i.eu("tool-input-error"),toolCallId:i.Yj(),toolName:i.Yj(),input:i.L5(),providerExecuted:i.zM().optional(),providerMetadata:I.optional(),dynamic:i.zM().optional(),errorText:i.Yj()}),i.re({type:i.eu("tool-output-available"),toolCallId:i.Yj(),output:i.L5(),providerExecuted:i.zM().optional(),dynamic:i.zM().optional()}),i.re({type:i.eu("tool-output-error"),toolCallId:i.Yj(),errorText:i.Yj(),providerExecuted:i.zM().optional(),dynamic:i.zM().optional()}),i.re({type:i.eu("reasoning"),text:i.Yj(),providerMetadata:I.optional()}),i.re({type:i.eu("reasoning-start"),id:i.Yj(),providerMetadata:I.optional()}),i.re({type:i.eu("reasoning-delta"),id:i.Yj(),delta:i.Yj(),providerMetadata:I.optional()}),i.re({type:i.eu("reasoning-end"),id:i.Yj(),providerMetadata:I.optional()}),i.re({type:i.eu("reasoning-part-finish")}),i.re({type:i.eu("source-url"),sourceId:i.Yj(),url:i.Yj(),title:i.Yj().optional(),providerMetadata:I.optional()}),i.re({type:i.eu("source-document"),sourceId:i.Yj(),mediaType:i.Yj(),title:i.Yj(),filename:i.Yj().optional(),providerMetadata:I.optional()}),i.re({type:i.eu("file"),url:i.Yj(),mediaType:i.Yj(),providerMetadata:I.optional()}),i.re({type:i.Yj().startsWith("data-"),id:i.Yj().optional(),data:i.L5(),transient:i.zM().optional()}),i.re({type:i.eu("start-step")}),i.re({type:i.eu("finish-step")}),i.re({type:i.eu("start"),messageId:i.Yj().optional(),messageMetadata:i.L5().optional()}),i.re({type:i.eu("finish"),messageMetadata:i.L5().optional()}),i.re({type:i.eu("abort")}),i.re({type:i.eu("message-metadata"),messageMetadata:i.L5()})]);async function A(e){if(void 0===e)return{value:void 0,state:"undefined-input"};let t=await (0,r.N8)({text:e});return t.success?{value:t.value,state:"successful-parse"}:(t=await (0,r.N8)({text:function(e){let t=["ROOT"],a=-1,s=null;function r(e,r,o){switch(e){case'"':a=r,t.pop(),t.push(o),t.push("INSIDE_STRING");break;case"f":case"t":case"n":a=r,s=r,t.pop(),t.push(o),t.push("INSIDE_LITERAL");break;case"-":t.pop(),t.push(o),t.push("INSIDE_NUMBER");break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":a=r,t.pop(),t.push(o),t.push("INSIDE_NUMBER");break;case"{":a=r,t.pop(),t.push(o),t.push("INSIDE_OBJECT_START");break;case"[":a=r,t.pop(),t.push(o),t.push("INSIDE_ARRAY_START")}}function o(e,s){switch(e){case",":t.pop(),t.push("INSIDE_OBJECT_AFTER_COMMA");break;case"}":a=s,t.pop()}}function i(e,s){switch(e){case",":t.pop(),t.push("INSIDE_ARRAY_AFTER_COMMA");break;case"]":a=s,t.pop()}}for(let l=0;l<e.length;l++){let n=e[l];switch(t[t.length-1]){case"ROOT":r(n,l,"FINISH");break;case"INSIDE_OBJECT_START":switch(n){case'"':t.pop(),t.push("INSIDE_OBJECT_KEY");break;case"}":a=l,t.pop()}break;case"INSIDE_OBJECT_AFTER_COMMA":'"'===n&&(t.pop(),t.push("INSIDE_OBJECT_KEY"));break;case"INSIDE_OBJECT_KEY":'"'===n&&(t.pop(),t.push("INSIDE_OBJECT_AFTER_KEY"));break;case"INSIDE_OBJECT_AFTER_KEY":":"===n&&(t.pop(),t.push("INSIDE_OBJECT_BEFORE_VALUE"));break;case"INSIDE_OBJECT_BEFORE_VALUE":r(n,l,"INSIDE_OBJECT_AFTER_VALUE");break;case"INSIDE_OBJECT_AFTER_VALUE":o(n,l);break;case"INSIDE_STRING":switch(n){case'"':t.pop(),a=l;break;case"\\":t.push("INSIDE_STRING_ESCAPE");break;default:a=l}break;case"INSIDE_ARRAY_START":"]"===n?(a=l,t.pop()):(a=l,r(n,l,"INSIDE_ARRAY_AFTER_VALUE"));break;case"INSIDE_ARRAY_AFTER_VALUE":switch(n){case",":t.pop(),t.push("INSIDE_ARRAY_AFTER_COMMA");break;case"]":a=l,t.pop();break;default:a=l}break;case"INSIDE_ARRAY_AFTER_COMMA":r(n,l,"INSIDE_ARRAY_AFTER_VALUE");break;case"INSIDE_STRING_ESCAPE":t.pop(),a=l;break;case"INSIDE_NUMBER":switch(n){case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":a=l;break;case"e":case"E":case"-":case".":break;case",":t.pop(),"INSIDE_ARRAY_AFTER_VALUE"===t[t.length-1]&&i(n,l),"INSIDE_OBJECT_AFTER_VALUE"===t[t.length-1]&&o(n,l);break;case"}":t.pop(),"INSIDE_OBJECT_AFTER_VALUE"===t[t.length-1]&&o(n,l);break;case"]":t.pop(),"INSIDE_ARRAY_AFTER_VALUE"===t[t.length-1]&&i(n,l);break;default:t.pop()}break;case"INSIDE_LITERAL":{let r=e.substring(s,l+1);"false".startsWith(r)||"true".startsWith(r)||"null".startsWith(r)?a=l:(t.pop(),"INSIDE_OBJECT_AFTER_VALUE"===t[t.length-1]?o(n,l):"INSIDE_ARRAY_AFTER_VALUE"===t[t.length-1]&&i(n,l))}}}let l=e.slice(0,a+1);for(let a=t.length-1;a>=0;a--)switch(t[a]){case"INSIDE_STRING":l+='"';break;case"INSIDE_OBJECT_KEY":case"INSIDE_OBJECT_AFTER_KEY":case"INSIDE_OBJECT_AFTER_COMMA":case"INSIDE_OBJECT_START":case"INSIDE_OBJECT_BEFORE_VALUE":case"INSIDE_OBJECT_AFTER_VALUE":l+="}";break;case"INSIDE_ARRAY_START":case"INSIDE_ARRAY_AFTER_COMMA":case"INSIDE_ARRAY_AFTER_VALUE":l+="]";break;case"INSIDE_LITERAL":{let t=e.substring(s,e.length);"true".startsWith(t)?l+="true".slice(t.length):"false".startsWith(t)?l+="false".slice(t.length):"null".startsWith(t)&&(l+="null".slice(t.length))}}return l}(e)})).success?{value:t.value,state:"repaired-parse"}:{value:void 0,state:"failed-parse"}}function S(e){return e.type.startsWith("tool-")}function k(e){return e.type.split("-").slice(1).join("-")}async function w({stream:e,onError:t}){let a=e.getReader();try{for(;;){let{done:e}=await a.read();if(e)break}}catch(e){null==t||t(e)}finally{a.releaseLock()}}(0,r.hK)({prefix:"aitxt",size:24}),(0,r.hK)({prefix:"aiobj",size:24});var N=class{constructor(){this.queue=[],this.isProcessing=!1}async processQueue(){if(!this.isProcessing){for(this.isProcessing=!0;this.queue.length>0;)await this.queue[0](),this.queue.shift();this.isProcessing=!1}}async run(e){return new Promise((t,a)=>{this.queue.push(async()=>{try{await e(),t()}catch(e){a(e)}}),this.processQueue()})}};(0,r.hK)({prefix:"aiobj",size:24}),o.bD,((e,t)=>{for(var a in t)l(e,a,{get:t[a],enumerable:!0})})({},{object:()=>j,text:()=>Y});var Y=()=>({type:"text",responseFormat:{type:"text"},parsePartial:async({text:e})=>({partial:e}),parseOutput:async({text:e})=>e}),j=({schema:e})=>{let t=(0,r.mD)(e);return{type:"object",responseFormat:{type:"json",schema:t.jsonSchema},async parsePartial({text:e}){let t=await A(e);switch(t.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return{partial:t.value};default:{let e=t.state;throw Error(`Unsupported parse state: ${e}`)}}},async parseOutput({text:e},a){let s=await (0,r.N8)({text:e});if(!s.success)throw new c({message:"No object generated: could not parse the response.",cause:s.error,text:e,response:a.response,usage:a.usage,finishReason:a.finishReason});let o=await (0,r.ZZ)({value:s.value,schema:t});if(!o.success)throw new c({message:"No object generated: response did not match schema.",cause:o.error,text:e,response:a.response,usage:a.usage,finishReason:a.finishReason});return o.value}}},D=Symbol.for("vercel.ai.error.AI_NoSuchProviderError");o.eM;var O=i._H({name:i.Yj(),version:i.Yj()}),L=i._H({_meta:i.lq(i.Ik({}).loose())}),q=i.Ik({method:i.Yj(),params:i.lq(L)}),F=i._H({experimental:i.lq(i.Ik({}).loose()),logging:i.lq(i.Ik({}).loose()),prompts:i.lq(i._H({listChanged:i.lq(i.zM())})),resources:i.lq(i._H({subscribe:i.lq(i.zM()),listChanged:i.lq(i.zM())})),tools:i.lq(i._H({listChanged:i.lq(i.zM())}))});L.extend({protocolVersion:i.Yj(),capabilities:F,serverInfo:O,instructions:i.lq(i.Yj())});var P=L.extend({nextCursor:i.lq(i.Yj())}),B=i.Ik({name:i.Yj(),description:i.lq(i.Yj()),inputSchema:i.Ik({type:i.eu("object"),properties:i.lq(i.Ik({}).loose())}).loose()}).loose();P.extend({tools:i.YO(B)});var K=i.Ik({type:i.eu("text"),text:i.Yj()}).loose(),U=i.Ik({type:i.eu("image"),data:i.K3(),mimeType:i.Yj()}).loose(),J=i.Ik({uri:i.Yj(),mimeType:i.lq(i.Yj())}).loose(),z=J.extend({text:i.Yj()}),V=J.extend({blob:i.K3()}),W=i.Ik({type:i.eu("resource"),resource:i.KC([z,V])}).loose();L.extend({content:i.YO(i.KC([K,U,W])),isError:i.zM().default(!1).optional()}).or(L.extend({toolResult:i.L5()}));var $=i.Ik({jsonrpc:i.eu("2.0"),id:i.KC([i.Yj(),i.ai().int()])}).merge(q).strict(),G=i.Ik({jsonrpc:i.eu("2.0"),id:i.KC([i.Yj(),i.ai().int()]),result:L}).strict(),H=i.Ik({jsonrpc:i.eu("2.0"),id:i.KC([i.Yj(),i.ai().int()]),error:i.Ik({code:i.ai().int(),message:i.Yj(),data:i.lq(i.L5())})}).strict(),Z=i.Ik({jsonrpc:i.eu("2.0")}).merge(i.Ik({method:i.Yj(),params:i.lq(L)})).strict();async function Q({stream:e,onTextPart:t}){let a=e.pipeThrough(new TextDecoderStream).getReader();for(;;){let{done:e,value:s}=await a.read();if(e)break;await t(s)}}async function X({api:e,prompt:t,credentials:a,headers:s,body:o,streamProtocol:i="data",setCompletion:l,setLoading:n,setError:u,setAbortController:d,onFinish:p,onError:c,fetch:h=fetch}){var m;try{n(!0),u(void 0);let c=new AbortController;d(c),l("");let I=await h(e,{method:"POST",body:JSON.stringify({prompt:t,...o}),credentials:a,headers:{"Content-Type":"application/json",...s},signal:c.signal}).catch(e=>{throw e});if(!I.ok)throw Error(null!=(m=await I.text())?m:"Failed to fetch the chat response.");if(!I.body)throw Error("The response body is empty.");let g="";switch(i){case"text":await Q({stream:I.body,onTextPart:e=>{g+=e,l(g)}});break;case"data":await w({stream:(0,r._Z)({stream:I.body,schema:R}).pipeThrough(new TransformStream({async transform(e){if(!e.success)throw e.error;let t=e.value;if("text-delta"===t.type)g+=t.delta,l(g);else if("error"===t.type)throw Error(t.errorText)}})),onError:e=>{throw e}});break;default:throw Error(`Unknown stream protocol: ${i}`)}return p&&p(t,g),d(null),g}catch(e){if("AbortError"===e.name)return d(null),null;e instanceof Error&&c&&c(e),u(e)}finally{n(!1)}}async function ee(e){if(null==e)return[];if(!globalThis.FileList||!(e instanceof globalThis.FileList))throw Error("FileList is not supported in the current environment");return Promise.all(Array.from(e).map(async e=>{let{name:t,type:a}=e;return{type:"file",mediaType:a,filename:t,url:await new Promise((t,a)=>{let s=new FileReader;s.onload=e=>{var a;t(null==(a=e.target)?void 0:a.result)},s.onerror=e=>a(e),s.readAsDataURL(e)})}}))}i.KC([$,Z,G,H]),o.bD;var et=class{constructor({api:e="/api/chat",credentials:t,headers:a,body:s,fetch:r,prepareSendMessagesRequest:o,prepareReconnectToStreamRequest:i}){this.api=e,this.credentials=t,this.headers=a,this.body=s,this.fetch=r,this.prepareSendMessagesRequest=o,this.prepareReconnectToStreamRequest=i}async sendMessages({abortSignal:e,...t}){var a,s,o,i,l;let n=await (0,r.hd)(this.body),u=await (0,r.hd)(this.headers),d=await (0,r.hd)(this.credentials),p=await (null==(a=this.prepareSendMessagesRequest)?void 0:a.call(this,{api:this.api,id:t.chatId,messages:t.messages,body:{...n,...t.body},headers:{...u,...t.headers},credentials:d,requestMetadata:t.metadata,trigger:t.trigger,messageId:t.messageId})),c=null!=(s=null==p?void 0:p.api)?s:this.api,h=(null==p?void 0:p.headers)!==void 0?p.headers:{...u,...t.headers},m=(null==p?void 0:p.body)!==void 0?p.body:{...n,...t.body,id:t.chatId,messages:t.messages,trigger:t.trigger,messageId:t.messageId},I=null!=(o=null==p?void 0:p.credentials)?o:d,g=null!=(i=this.fetch)?i:globalThis.fetch,v=await g(c,{method:"POST",headers:{"Content-Type":"application/json",...h},body:JSON.stringify(m),credentials:I,signal:e});if(!v.ok)throw Error(null!=(l=await v.text())?l:"Failed to fetch the chat response.");if(!v.body)throw Error("The response body is empty.");return this.processResponseStream(v.body)}async reconnectToStream(e){var t,a,s,o,i;let l=await (0,r.hd)(this.body),n=await (0,r.hd)(this.headers),u=await (0,r.hd)(this.credentials),d=await (null==(t=this.prepareReconnectToStreamRequest)?void 0:t.call(this,{api:this.api,id:e.chatId,body:{...l,...e.body},headers:{...n,...e.headers},credentials:u,requestMetadata:e.metadata})),p=null!=(a=null==d?void 0:d.api)?a:`${this.api}/${e.chatId}/stream`,c=(null==d?void 0:d.headers)!==void 0?d.headers:{...n,...e.headers},h=null!=(s=null==d?void 0:d.credentials)?s:u,m=null!=(o=this.fetch)?o:globalThis.fetch,I=await m(p,{method:"GET",headers:c,credentials:h});if(204===I.status)return null;if(!I.ok)throw Error(null!=(i=await I.text())?i:"Failed to fetch the chat response.");if(!I.body)throw Error("The response body is empty.");return this.processResponseStream(I.body)}},ea=class extends et{constructor(e={}){super(e)}processResponseStream(e){return(0,r._Z)({stream:e,schema:R}).pipeThrough(new TransformStream({async transform(e,t){if(!e.success)throw e.error;t.enqueue(e.value)}}))}},es=class{constructor({generateId:e=r.$C,id:t=e(),transport:a=new ea,messageMetadataSchema:s,dataPartSchemas:o,state:i,onError:l,onToolCall:n,onFinish:u,onData:d,sendAutomaticallyWhen:p}){this.activeResponse=void 0,this.jobExecutor=new N,this.sendMessage=async(e,t)=>{var a,s,r,o;let i;if(null==e)return void await this.makeRequest({trigger:"submit-message",messageId:null==(a=this.lastMessage)?void 0:a.id,...t});if(i="text"in e||"files"in e?{parts:[...Array.isArray(e.files)?e.files:await ee(e.files),..."text"in e&&null!=e.text?[{type:"text",text:e.text}]:[]]}:e,null!=e.messageId){let t=this.state.messages.findIndex(t=>t.id===e.messageId);if(-1===t)throw Error(`message with id ${e.messageId} not found`);if("user"!==this.state.messages[t].role)throw Error(`message with id ${e.messageId} is not a user message`);this.state.messages=this.state.messages.slice(0,t+1),this.state.replaceMessage(t,{...i,id:e.messageId,role:null!=(s=i.role)?s:"user",metadata:e.metadata})}else this.state.pushMessage({...i,id:null!=(r=i.id)?r:this.generateId(),role:null!=(o=i.role)?o:"user",metadata:e.metadata});await this.makeRequest({trigger:"submit-message",messageId:e.messageId,...t})},this.regenerate=async({messageId:e,...t}={})=>{let a=null==e?this.state.messages.length-1:this.state.messages.findIndex(t=>t.id===e);if(-1===a)throw Error(`message ${e} not found`);this.state.messages=this.state.messages.slice(0,"assistant"===this.messages[a].role?a:a+1),await this.makeRequest({trigger:"regenerate-message",messageId:e,...t})},this.resumeStream=async(e={})=>{await this.makeRequest({trigger:"resume-stream",...e})},this.clearError=()=>{"error"===this.status&&(this.state.error=void 0,this.setStatus({status:"ready"}))},this.addToolResult=async({tool:e,toolCallId:t,output:a})=>this.jobExecutor.run(async()=>{var e,s;let r=this.state.messages,o=r[r.length-1];this.state.replaceMessage(r.length-1,{...o,parts:o.parts.map(e=>S(e)&&e.toolCallId===t?{...e,state:"output-available",output:a}:e)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(e=>S(e)&&e.toolCallId===t?{...e,state:"output-available",output:a,errorText:void 0}:e)),"streaming"!==this.status&&"submitted"!==this.status&&(null==(e=this.sendAutomaticallyWhen)?void 0:e.call(this,{messages:this.state.messages}))&&this.makeRequest({trigger:"submit-message",messageId:null==(s=this.lastMessage)?void 0:s.id})}),this.stop=async()=>{var e;("streaming"===this.status||"submitted"===this.status)&&(null==(e=this.activeResponse)?void 0:e.abortController)&&this.activeResponse.abortController.abort()},this.id=t,this.transport=a,this.generateId=e,this.messageMetadataSchema=s,this.dataPartSchemas=o,this.state=i,this.onError=l,this.onToolCall=n,this.onFinish=u,this.onData=d,this.sendAutomaticallyWhen=p}get status(){return this.state.status}setStatus({status:e,error:t}){this.status!==e&&(this.state.status=e,this.state.error=t)}get error(){return this.state.error}get messages(){return this.state.messages}get lastMessage(){return this.state.messages[this.state.messages.length-1]}set messages(e){this.state.messages=e}async makeRequest({trigger:e,metadata:t,headers:a,body:s,messageId:o}){var i,l,n;this.setStatus({status:"submitted",error:void 0});let u=this.lastMessage;try{let l,n={state:function({lastMessage:e,messageId:t}){return{message:(null==e?void 0:e.role)==="assistant"?e:{id:t,metadata:void 0,role:"assistant",parts:[]},activeTextParts:{},activeReasoningParts:{},partialToolCalls:{}}}({lastMessage:this.state.snapshot(u),messageId:this.generateId()}),abortController:new AbortController};if(this.activeResponse=n,"resume-stream"===e){let e=await this.transport.reconnectToStream({chatId:this.id,metadata:t,headers:a,body:s});if(null==e)return void this.setStatus({status:"ready"});l=e}else l=await this.transport.sendMessages({chatId:this.id,messages:this.state.messages,abortSignal:n.abortController.signal,metadata:t,headers:a,body:s,trigger:e,messageId:o});let d=e=>this.jobExecutor.run(()=>e({state:n.state,write:()=>{var e;this.setStatus({status:"streaming"}),n.state.message.id===(null==(e=this.lastMessage)?void 0:e.id)?this.state.replaceMessage(this.state.messages.length-1,n.state.message):this.state.pushMessage(n.state.message)}}));await w({stream:function({stream:e,messageMetadataSchema:t,dataPartSchemas:a,runUpdateMessageJob:s,onError:o,onToolCall:i,onData:l}){return e.pipeThrough(new TransformStream({async transform(e,n){await s(async({state:s,write:u})=>{var d,p,c,h;function m(e){let t=s.message.parts.filter(S).find(t=>t.toolCallId===e);if(null==t)throw Error("tool-output-error must be preceded by a tool-input-available");return t}function I(e){let t=s.message.parts.filter(e=>"dynamic-tool"===e.type).find(t=>t.toolCallId===e);if(null==t)throw Error("tool-output-error must be preceded by a tool-input-available");return t}function g(e){var t;let a=s.message.parts.find(t=>S(t)&&t.toolCallId===e.toolCallId);null!=a?(a.state=e.state,a.input=e.input,a.output=e.output,a.errorText=e.errorText,a.rawInput=e.rawInput,a.providerExecuted=null!=(t=e.providerExecuted)?t:a.providerExecuted,null!=e.providerMetadata&&"input-available"===a.state&&(a.callProviderMetadata=e.providerMetadata)):s.message.parts.push({type:`tool-${e.toolName}`,toolCallId:e.toolCallId,state:e.state,input:e.input,output:e.output,rawInput:e.rawInput,errorText:e.errorText,providerExecuted:e.providerExecuted,...null!=e.providerMetadata?{callProviderMetadata:e.providerMetadata}:{}})}function v(e){var t;let a=s.message.parts.find(t=>"dynamic-tool"===t.type&&t.toolCallId===e.toolCallId);null!=a?(a.state=e.state,a.toolName=e.toolName,a.input=e.input,a.output=e.output,a.errorText=e.errorText,a.rawInput=null!=(t=e.rawInput)?t:a.rawInput,null!=e.providerMetadata&&"input-available"===a.state&&(a.callProviderMetadata=e.providerMetadata)):s.message.parts.push({type:"dynamic-tool",toolName:e.toolName,toolCallId:e.toolCallId,state:e.state,input:e.input,output:e.output,errorText:e.errorText,...null!=e.providerMetadata?{callProviderMetadata:e.providerMetadata}:{}})}async function E(e){if(null!=e){let a=null!=s.message.metadata?function e(t,a){if(void 0===t&&void 0===a)return;if(void 0===t)return a;if(void 0===a)return t;let s={...t};for(let r in a)if(Object.prototype.hasOwnProperty.call(a,r)){let o=a[r];if(void 0===o)continue;let i=r in t?t[r]:void 0,l=null!==o&&"object"==typeof o&&!Array.isArray(o)&&!(o instanceof Date)&&!(o instanceof RegExp),n=null!=i&&"object"==typeof i&&!Array.isArray(i)&&!(i instanceof Date)&&!(i instanceof RegExp);l&&n?s[r]=e(i,o):s[r]=o}return s}(s.message.metadata,e):e;null!=t&&await (0,r.k5)({value:a,schema:t}),s.message.metadata=a}}switch(e.type){case"text-start":{let t={type:"text",text:"",providerMetadata:e.providerMetadata,state:"streaming"};s.activeTextParts[e.id]=t,s.message.parts.push(t),u();break}case"text-delta":{let t=s.activeTextParts[e.id];t.text+=e.delta,t.providerMetadata=null!=(d=e.providerMetadata)?d:t.providerMetadata,u();break}case"text-end":{let t=s.activeTextParts[e.id];t.state="done",t.providerMetadata=null!=(p=e.providerMetadata)?p:t.providerMetadata,delete s.activeTextParts[e.id],u();break}case"reasoning-start":{let t={type:"reasoning",text:"",providerMetadata:e.providerMetadata,state:"streaming"};s.activeReasoningParts[e.id]=t,s.message.parts.push(t),u();break}case"reasoning-delta":{let t=s.activeReasoningParts[e.id];t.text+=e.delta,t.providerMetadata=null!=(c=e.providerMetadata)?c:t.providerMetadata,u();break}case"reasoning-end":{let t=s.activeReasoningParts[e.id];t.providerMetadata=null!=(h=e.providerMetadata)?h:t.providerMetadata,t.state="done",delete s.activeReasoningParts[e.id],u();break}case"file":s.message.parts.push({type:"file",mediaType:e.mediaType,url:e.url}),u();break;case"source-url":s.message.parts.push({type:"source-url",sourceId:e.sourceId,url:e.url,title:e.title,providerMetadata:e.providerMetadata}),u();break;case"source-document":s.message.parts.push({type:"source-document",sourceId:e.sourceId,mediaType:e.mediaType,title:e.title,filename:e.filename,providerMetadata:e.providerMetadata}),u();break;case"tool-input-start":{let t=s.message.parts.filter(S);s.partialToolCalls[e.toolCallId]={text:"",toolName:e.toolName,index:t.length,dynamic:e.dynamic},e.dynamic?v({toolCallId:e.toolCallId,toolName:e.toolName,state:"input-streaming",input:void 0}):g({toolCallId:e.toolCallId,toolName:e.toolName,state:"input-streaming",input:void 0,providerExecuted:e.providerExecuted}),u();break}case"tool-input-delta":{let t=s.partialToolCalls[e.toolCallId];t.text+=e.inputTextDelta;let{value:a}=await A(t.text);t.dynamic?v({toolCallId:e.toolCallId,toolName:t.toolName,state:"input-streaming",input:a}):g({toolCallId:e.toolCallId,toolName:t.toolName,state:"input-streaming",input:a}),u();break}case"tool-input-available":e.dynamic?v({toolCallId:e.toolCallId,toolName:e.toolName,state:"input-available",input:e.input,providerMetadata:e.providerMetadata}):g({toolCallId:e.toolCallId,toolName:e.toolName,state:"input-available",input:e.input,providerExecuted:e.providerExecuted,providerMetadata:e.providerMetadata}),u(),i&&!e.providerExecuted&&await i({toolCall:e});break;case"tool-input-error":e.dynamic?v({toolCallId:e.toolCallId,toolName:e.toolName,state:"output-error",input:e.input,errorText:e.errorText,providerMetadata:e.providerMetadata}):g({toolCallId:e.toolCallId,toolName:e.toolName,state:"output-error",input:void 0,rawInput:e.input,errorText:e.errorText,providerExecuted:e.providerExecuted,providerMetadata:e.providerMetadata}),u();break;case"tool-output-available":if(e.dynamic){let t=I(e.toolCallId);v({toolCallId:e.toolCallId,toolName:t.toolName,state:"output-available",input:t.input,output:e.output})}else{let t=m(e.toolCallId);g({toolCallId:e.toolCallId,toolName:k(t),state:"output-available",input:t.input,output:e.output,providerExecuted:e.providerExecuted})}u();break;case"tool-output-error":if(e.dynamic){let t=I(e.toolCallId);v({toolCallId:e.toolCallId,toolName:t.toolName,state:"output-error",input:t.input,errorText:e.errorText})}else{let t=m(e.toolCallId);g({toolCallId:e.toolCallId,toolName:k(t),state:"output-error",input:t.input,rawInput:t.rawInput,errorText:e.errorText})}u();break;case"start-step":s.message.parts.push({type:"step-start"});break;case"finish-step":s.activeTextParts={},s.activeReasoningParts={};break;case"start":null!=e.messageId&&(s.message.id=e.messageId),await E(e.messageMetadata),(null!=e.messageId||null!=e.messageMetadata)&&u();break;case"finish":case"message-metadata":await E(e.messageMetadata),null!=e.messageMetadata&&u();break;case"error":null==o||o(Error(e.errorText));break;default:if(e.type.startsWith("data-")){if((null==a?void 0:a[e.type])!=null&&await (0,r.k5)({value:e.data,schema:a[e.type]}),e.transient){null==l||l(e);break}let t=null!=e.id?s.message.parts.find(t=>e.type===t.type&&e.id===t.id):void 0;null!=t?t.data=e.data:s.message.parts.push(e),null==l||l(e),u()}}n.enqueue(e)})}}))}({stream:l,onToolCall:this.onToolCall,onData:this.onData,messageMetadataSchema:this.messageMetadataSchema,dataPartSchemas:this.dataPartSchemas,runUpdateMessageJob:d,onError:e=>{throw e}}),onError:e=>{throw e}}),null==(i=this.onFinish)||i.call(this,{message:n.state.message}),this.setStatus({status:"ready"})}catch(e){if("AbortError"===e.name)return this.setStatus({status:"ready"}),null;this.onError&&e instanceof Error&&this.onError(e),this.setStatus({status:"error",error:e})}finally{this.activeResponse=void 0}(null==(l=this.sendAutomaticallyWhen)?void 0:l.call(this,{messages:this.state.messages}))&&await this.makeRequest({trigger:"submit-message",messageId:null==(n=this.lastMessage)?void 0:n.id,metadata:t,headers:a,body:s})}}}}]);