denchclaw 2.1.3 → 2.1.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 (81) hide show
  1. package/apps/web/.next/standalone/apps/web/.next/BUILD_ID +1 -1
  2. package/apps/web/.next/standalone/apps/web/.next/app-build-manifest.json +95 -95
  3. package/apps/web/.next/standalone/apps/web/.next/app-path-routes-manifest.json +30 -30
  4. package/apps/web/.next/standalone/apps/web/.next/build-manifest.json +2 -2
  5. package/apps/web/.next/standalone/apps/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  6. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/active/route_client-reference-manifest.js +1 -1
  7. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/route_client-reference-manifest.js +1 -1
  8. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/stop/route_client-reference-manifest.js +1 -1
  9. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/stream/route_client-reference-manifest.js +1 -1
  10. package/apps/web/.next/standalone/apps/web/.next/server/app/api/chat/subagents/route_client-reference-manifest.js +1 -1
  11. package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/jobs/[jobId]/runs/route_client-reference-manifest.js +1 -1
  12. package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/jobs/route_client-reference-manifest.js +1 -1
  13. package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/runs/[sessionId]/route_client-reference-manifest.js +1 -1
  14. package/apps/web/.next/standalone/apps/web/.next/server/app/api/cron/runs/search-transcript/route_client-reference-manifest.js +1 -1
  15. package/apps/web/.next/standalone/apps/web/.next/server/app/api/feedback/route_client-reference-manifest.js +1 -1
  16. package/apps/web/.next/standalone/apps/web/.next/server/app/api/memories/route_client-reference-manifest.js +1 -1
  17. package/apps/web/.next/standalone/apps/web/.next/server/app/api/profiles/route_client-reference-manifest.js +1 -1
  18. package/apps/web/.next/standalone/apps/web/.next/server/app/api/profiles/switch/route_client-reference-manifest.js +1 -1
  19. package/apps/web/.next/standalone/apps/web/.next/server/app/api/sessions/[sessionId]/route_client-reference-manifest.js +1 -1
  20. package/apps/web/.next/standalone/apps/web/.next/server/app/api/sessions/route_client-reference-manifest.js +1 -1
  21. package/apps/web/.next/standalone/apps/web/.next/server/app/api/skills/route_client-reference-manifest.js +1 -1
  22. package/apps/web/.next/standalone/apps/web/.next/server/app/api/web-sessions/[id]/messages/route_client-reference-manifest.js +1 -1
  23. package/apps/web/.next/standalone/apps/web/.next/server/app/api/web-sessions/[id]/route_client-reference-manifest.js +1 -1
  24. package/apps/web/.next/standalone/apps/web/.next/server/app/api/web-sessions/route_client-reference-manifest.js +1 -1
  25. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/assets/[...path]/route_client-reference-manifest.js +1 -1
  26. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/browse/route_client-reference-manifest.js +1 -1
  27. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/browse-file/route_client-reference-manifest.js +1 -1
  28. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/context/route_client-reference-manifest.js +1 -1
  29. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/copy/route_client-reference-manifest.js +1 -1
  30. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/db/introspect/route_client-reference-manifest.js +1 -1
  31. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/db/query/route_client-reference-manifest.js +1 -1
  32. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/delete/route_client-reference-manifest.js +1 -1
  33. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/file/route_client-reference-manifest.js +1 -1
  34. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/init/route_client-reference-manifest.js +1 -1
  35. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/list/route_client-reference-manifest.js +1 -1
  36. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/mkdir/route_client-reference-manifest.js +1 -1
  37. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/move/route_client-reference-manifest.js +1 -1
  38. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/display-field/route_client-reference-manifest.js +1 -1
  39. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/[id]/route_client-reference-manifest.js +1 -1
  40. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/bulk-delete/route_client-reference-manifest.js +1 -1
  41. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/options/route_client-reference-manifest.js +1 -1
  42. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/entries/route_client-reference-manifest.js +1 -1
  43. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/fields/[fieldId]/enum-rename/route_client-reference-manifest.js +1 -1
  44. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/fields/[fieldId]/route_client-reference-manifest.js +1 -1
  45. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/fields/reorder/route_client-reference-manifest.js +1 -1
  46. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/route_client-reference-manifest.js +1 -1
  47. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/objects/[name]/views/route_client-reference-manifest.js +1 -1
  48. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/open-file/route_client-reference-manifest.js +1 -1
  49. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/path-info/route_client-reference-manifest.js +1 -1
  50. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/query/route_client-reference-manifest.js +1 -1
  51. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/raw-file/route_client-reference-manifest.js +1 -1
  52. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/rename/route_client-reference-manifest.js +1 -1
  53. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/reports/execute/route_client-reference-manifest.js +1 -1
  54. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/search-index/route_client-reference-manifest.js +1 -1
  55. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/suggest-files/route_client-reference-manifest.js +1 -1
  56. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/switch/route_client-reference-manifest.js +1 -1
  57. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/thumbnail/route_client-reference-manifest.js +1 -1
  58. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/tree/route_client-reference-manifest.js +1 -1
  59. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/upload/route_client-reference-manifest.js +1 -1
  60. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/virtual-file/route_client-reference-manifest.js +1 -1
  61. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/watch/route_client-reference-manifest.js +1 -1
  62. package/apps/web/.next/standalone/apps/web/.next/server/app/api/workspace/write-binary/route_client-reference-manifest.js +1 -1
  63. package/apps/web/.next/standalone/apps/web/.next/server/app/page.js +3 -3
  64. package/apps/web/.next/standalone/apps/web/.next/server/app/page_client-reference-manifest.js +1 -1
  65. package/apps/web/.next/standalone/apps/web/.next/server/app/workspace/page_client-reference-manifest.js +1 -1
  66. package/apps/web/.next/standalone/apps/web/.next/server/app-paths-manifest.json +30 -30
  67. package/apps/web/.next/standalone/apps/web/.next/server/chunks/6426.js +4 -4
  68. package/apps/web/.next/standalone/apps/web/.next/server/functions-config-manifest.json +20 -20
  69. package/apps/web/.next/standalone/apps/web/.next/server/pages/500.html +1 -1
  70. package/apps/web/.next/standalone/apps/web/.next/server/pages-manifest.json +1 -1
  71. package/apps/web/.next/standalone/apps/web/.next/static/chunks/app/{page-a050908a5e555ee8.js → page-69792dc72cd99a61.js} +1 -1
  72. package/apps/web/.next/standalone/package.json +1 -1
  73. package/apps/web/.next/static/chunks/app/{page-a050908a5e555ee8.js → page-69792dc72cd99a61.js} +1 -1
  74. package/dist/entry.js +1 -1
  75. package/dist/{program-Ctezu4M_.js → program-B44Xn_sp.js} +22 -0
  76. package/dist/{run-main-CoqVjynv.js → run-main-CesqAppu.js} +1 -1
  77. package/package.json +1 -1
  78. /package/apps/web/.next/standalone/apps/web/.next/static/{f6BQtAfnkaWmLOerLKNPa → vpW04s7HdH5k8Nb2BR6u3}/_buildManifest.js +0 -0
  79. /package/apps/web/.next/standalone/apps/web/.next/static/{f6BQtAfnkaWmLOerLKNPa → vpW04s7HdH5k8Nb2BR6u3}/_ssgManifest.js +0 -0
  80. /package/apps/web/.next/static/{f6BQtAfnkaWmLOerLKNPa → vpW04s7HdH5k8Nb2BR6u3}/_buildManifest.js +0 -0
  81. /package/apps/web/.next/static/{f6BQtAfnkaWmLOerLKNPa → vpW04s7HdH5k8Nb2BR6u3}/_ssgManifest.js +0 -0
@@ -132,11 +132,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
132
132
  `:`[${e[a]}\r
133
133
  ]`;continue}f+=e[a],"\\"===e[a]?g=!0:h&&"]"===e[a]?h=!1:h||"["!==e[a]||(h=!0)}try{new RegExp(f)}catch(c){return console.warn(`Could not convert regex pattern at ${b.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),a.source}return f}function ki(a,b){var c,d,e,f,g,h;let i={type:"object",additionalProperties:null!=(c=kk(a.valueType._def,{...b,currentPath:[...b.currentPath,"additionalProperties"]}))?c:b.allowedAdditionalProperties};if((null==(d=a.keyType)?void 0:d._def.typeName)===D.ZodString&&(null==(e=a.keyType._def.checks)?void 0:e.length)){let{type:c,...d}=kc(a.keyType._def,b);return{...i,propertyNames:d}}if((null==(f=a.keyType)?void 0:f._def.typeName)===D.ZodEnum)return{...i,propertyNames:{enum:a.keyType._def.values}};if((null==(g=a.keyType)?void 0:g._def.typeName)===D.ZodBranded&&a.keyType._def.type._def.typeName===D.ZodString&&(null==(h=a.keyType._def.type._def.checks)?void 0:h.length)){let{type:c,...d}=j9(a.keyType._def,b);return{...i,propertyNames:d}}return i}var kj={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function kk(a,b,c=!1){var d;let e=b.seen.get(a);if(b.override){let f=null==(d=b.override)?void 0:d.call(b,a,b,e,c);if(f!==j7)return f}if(e&&!c){let a=kl(e,b);if(void 0!==a)return a}let f={def:a,path:b.currentPath,jsonSchema:void 0};b.seen.set(a,f);let g=((a,b,c)=>{switch(b){case D.ZodString:return kc(a,c);case D.ZodNumber:var d,e,f,g,h,i,j=a;let k={type:"number"};if(!j.checks)return k;for(let a of j.checks)switch(a.kind){case"int":k.type="integer";break;case"min":a.inclusive?k.minimum=a.value:k.exclusiveMinimum=a.value;break;case"max":a.inclusive?k.maximum=a.value:k.exclusiveMaximum=a.value;break;case"multipleOf":k.multipleOf=a.value}return k;case D.ZodObject:return function(a,b){let c={type:"object",properties:{}},d=[],e=a.shape();for(let a in e){let f=e[a];if(void 0===f||void 0===f._def)continue;let g=function(a){try{return a.isOptional()}catch(a){return!0}}(f),h=kk(f._def,{...b,currentPath:[...b.currentPath,"properties",a],propertyPath:[...b.currentPath,"properties",a]});void 0!==h&&(c.properties[a]=h,g||d.push(a))}d.length&&(c.required=d);let f=function(a,b){if("ZodNever"!==a.catchall._def.typeName)return kk(a.catchall._def,{...b,currentPath:[...b.currentPath,"additionalProperties"]});switch(a.unknownKeys){case"passthrough":return b.allowedAdditionalProperties;case"strict":return b.rejectedAdditionalProperties;case"strip":return"strict"===b.removeAdditionalStrategy?b.allowedAdditionalProperties:b.rejectedAdditionalProperties}}(a,b);return void 0!==f&&(c.additionalProperties=f),c}(a,c);case D.ZodBigInt:var l=a;let m={type:"integer",format:"int64"};if(!l.checks)return m;for(let a of l.checks)switch(a.kind){case"min":a.inclusive?m.minimum=a.value:m.exclusiveMinimum=a.value;break;case"max":a.inclusive?m.maximum=a.value:m.exclusiveMaximum=a.value;break;case"multipleOf":m.multipleOf=a.value}return m;case D.ZodBoolean:return{type:"boolean"};case D.ZodDate:return function a(b,c,d){let e=null!=d?d:c.dateStrategy;if(Array.isArray(e))return{anyOf:e.map((d,e)=>a(b,c,d))};switch(e){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":var f=b;let g={type:"integer",format:"unix-time"};for(let a of f.checks)switch(a.kind){case"min":g.minimum=a.value;break;case"max":g.maximum=a.value}return g}}(a,c);case D.ZodUndefined:return{not:{}};case D.ZodNull:return{type:"null"};case D.ZodArray:var n,o,p,q=a,r=c;let s={type:"array"};return(null==(n=q.type)?void 0:n._def)&&(null==(p=null==(o=q.type)?void 0:o._def)?void 0:p.typeName)!==D.ZodAny&&(s.items=kk(q.type._def,{...r,currentPath:[...r.currentPath,"items"]})),q.minLength&&(s.minItems=q.minLength.value),q.maxLength&&(s.maxItems=q.maxLength.value),q.exactLength&&(s.minItems=q.exactLength.value,s.maxItems=q.exactLength.value),s;case D.ZodUnion:case D.ZodDiscriminatedUnion:return function(a,b){let c=a.options instanceof Map?Array.from(a.options.values()):a.options;if(c.every(a=>a._def.typeName in kj&&(!a._def.checks||!a._def.checks.length))){let a=c.reduce((a,b)=>{let c=kj[b._def.typeName];return c&&!a.includes(c)?[...a,c]:a},[]);return{type:a.length>1?a:a[0]}}if(c.every(a=>"ZodLiteral"===a._def.typeName&&!a.description)){let a=c.reduce((a,b)=>{let c=typeof b._def.value;switch(c){case"string":case"number":case"boolean":return[...a,c];case"bigint":return[...a,"integer"];case"object":if(null===b._def.value)return[...a,"null"];default:return a}},[]);if(a.length===c.length){let b=a.filter((a,b,c)=>c.indexOf(a)===b);return{type:b.length>1?b:b[0],enum:c.reduce((a,b)=>a.includes(b._def.value)?a:[...a,b._def.value],[])}}}else if(c.every(a=>"ZodEnum"===a._def.typeName))return{type:"string",enum:c.reduce((a,b)=>[...a,...b._def.values.filter(b=>!a.includes(b))],[])};var d=a,e=b;let f=(d.options instanceof Map?Array.from(d.options.values()):d.options).map((a,b)=>kk(a._def,{...e,currentPath:[...e.currentPath,"anyOf",`${b}`]})).filter(a=>!!a&&(!e.strictUnions||"object"==typeof a&&Object.keys(a).length>0));return f.length?{anyOf:f}:void 0}(a,c);case D.ZodIntersection:var t=a,u=c;let v=[kk(t.left._def,{...u,currentPath:[...u.currentPath,"allOf","0"]}),kk(t.right._def,{...u,currentPath:[...u.currentPath,"allOf","1"]})].filter(a=>!!a),w=[];return v.forEach(a=>{if((!("type"in a)||"string"!==a.type)&&"allOf"in a)w.push(...a.allOf);else{let b=a;if("additionalProperties"in a&&!1===a.additionalProperties){let{additionalProperties:c,...d}=a;b=d}w.push(b)}}),w.length?{allOf:w}:void 0;case D.ZodTuple:return H=a,I=c,H.rest?{type:"array",minItems:H.items.length,items:H.items.map((a,b)=>kk(a._def,{...I,currentPath:[...I.currentPath,"items",`${b}`]})).reduce((a,b)=>void 0===b?a:[...a,b],[]),additionalItems:kk(H.rest._def,{...I,currentPath:[...I.currentPath,"additionalItems"]})}:{type:"array",minItems:H.items.length,maxItems:H.items.length,items:H.items.map((a,b)=>kk(a._def,{...I,currentPath:[...I.currentPath,"items",`${b}`]})).reduce((a,b)=>void 0===b?a:[...a,b],[])};case D.ZodRecord:return ki(a,c);case D.ZodLiteral:var x=a;let y=typeof x.value;return"bigint"!==y&&"number"!==y&&"boolean"!==y&&"string"!==y?{type:Array.isArray(x.value)?"array":"object"}:{type:"bigint"===y?"integer":y,const:x.value};case D.ZodEnum:return{type:"string",enum:Array.from(a.values)};case D.ZodNativeEnum:var z=a;let A=z.values,B=Object.keys(z.values).filter(a=>"number"!=typeof A[A[a]]).map(a=>A[a]),C=Array.from(new Set(B.map(a=>typeof a)));return{type:1===C.length?"string"===C[0]?"string":"number":["string","number"],enum:B};case D.ZodNullable:var E=a,F=c;if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(E.innerType._def.typeName)&&(!E.innerType._def.checks||!E.innerType._def.checks.length))return{type:[kj[E.innerType._def.typeName],"null"]};let G=kk(E.innerType._def,{...F,currentPath:[...F.currentPath,"anyOf","0"]});return G&&{anyOf:[G,{type:"null"}]};case D.ZodOptional:var H,I,J,K=a,L=c;if(L.currentPath.toString()===(null==(J=L.propertyPath)?void 0:J.toString()))return kk(K.innerType._def,L);let M=kk(K.innerType._def,{...L,currentPath:[...L.currentPath,"anyOf","1"]});return M?{anyOf:[{not:{}},M]}:{};case D.ZodMap:return d=a,"record"===(e=c).mapStrategy?ki(d,e):{type:"array",maxItems:125,items:{type:"array",items:[kk(d.keyType._def,{...e,currentPath:[...e.currentPath,"items","items","0"]})||{},kk(d.valueType._def,{...e,currentPath:[...e.currentPath,"items","items","1"]})||{}],minItems:2,maxItems:2}};case D.ZodSet:var N=a,O=c;let P={type:"array",uniqueItems:!0,items:kk(N.valueType._def,{...O,currentPath:[...O.currentPath,"items"]})};return N.minSize&&(P.minItems=N.minSize.value),N.maxSize&&(P.maxItems=N.maxSize.value),P;case D.ZodLazy:return()=>a.getter()._def;case D.ZodPromise:return kk(a.type._def,c);case D.ZodNaN:case D.ZodNever:return{not:{}};case D.ZodEffects:return f=a,"input"===(g=c).effectStrategy?kk(f.schema._def,g):{};case D.ZodAny:case D.ZodUnknown:return{};case D.ZodDefault:return h=a,i=c,{...kk(h.innerType._def,i),default:h.defaultValue()};case D.ZodBranded:return j9(a,c);case D.ZodReadonly:case D.ZodCatch:return kk(a.innerType._def,c);case D.ZodPipeline:var Q=a,R=c;if("input"===R.pipeStrategy)return kk(Q.in._def,R);if("output"===R.pipeStrategy)return kk(Q.out._def,R);let S=kk(Q.in._def,{...R,currentPath:[...R.currentPath,"allOf","0"]}),T=kk(Q.out._def,{...R,currentPath:[...R.currentPath,"allOf",S?"1":"0"]});return{allOf:[S,T].filter(a=>void 0!==a)};case D.ZodFunction:case D.ZodVoid:case D.ZodSymbol:default:return}})(a,a.typeName,b),h="function"==typeof g?kk(g(),b):g;if(h&&km(a,b,h),b.postProcess){let c=b.postProcess(h,a,b);return f.jsonSchema=h,c}return f.jsonSchema=h,h}var kl=(a,b)=>{switch(b.$refStrategy){case"root":return{$ref:a.path.join("/")};case"relative":return{$ref:((a,b)=>{let c=0;for(;c<a.length&&c<b.length&&a[c]===b[c];c++);return[(a.length-c).toString(),...b.slice(c)].join("/")})(b.currentPath,a.path)};case"none":case"seen":if(a.path.length<b.currentPath.length&&a.path.every((a,c)=>b.currentPath[c]===a))return console.warn(`Recursive reference detected at ${b.currentPath.join("/")}! Defaulting to any`),{};return"seen"===b.$refStrategy?{}:void 0}},km=(a,b,c)=>(a.description&&(c.description=a.description),c),kn=Symbol.for("vercel.ai.schema");function ko(a){let b;return()=>(null==b&&(b=a()),b)}function kp(a,{validate:b}={}){return{[kn]:!0,_type:void 0,get jsonSchema(){return"function"==typeof a&&(a=a()),a},validate:b}}function kq(a){var b;return null==a?kp({properties:{},additionalProperties:!1}):"object"==typeof a&&null!==a&&kn in a&&!0===a[kn]&&"jsonSchema"in a&&"validate"in a?a:"~standard"in a?"zod"===a["~standard"].vendor?kr(a):(b=a,kp(()=>j5(b["~standard"].jsonSchema.input({target:"draft-07"})),{validate:async a=>{let c=await b["~standard"].validate(a);return"value"in c?{success:!0,value:c.value}:{success:!1,error:new az({value:a,cause:c.issues})}}})):a()}function kr(a,b){var c,d;if("_zod"in a){let d=null!=(c=null==b?void 0:b.useReferences)&&c;return kp(()=>j5(function(a,b){if("_idmap"in a){let c=e2({...b,processors:fL}),d={};for(let b of a._idmap.entries()){let[a,d]=b;e3(d,c)}let e={};for(let f of(c.external={registry:a,uri:b?.uri,defs:d},a._idmap.entries())){let[a,b]=f;e4(c,b),e[a]=e5(c,b)}return Object.keys(d).length>0&&(e.__shared={["draft-2020-12"===c.target?"$defs":"definitions"]:d}),{schemas:e}}let c=e2({...b,processors:fL});return e3(a,c),e4(c,a),e5(c,a)}(a,{target:"draft-7",io:"input",reused:d?"ref":"inline"})),{validate:async b=>{let c=await fZ(a,b);return c.success?{success:!0,value:c.data}:{success:!1,error:c.error}}})}let e=null!=(d=null==b?void 0:b.useReferences)&&d;return kp(()=>((a,b)=>{var c;let d=(a=>{let b,c="string"==typeof(b=a)?{...j8,name:b}:{...j8,...b},d=void 0!==c.name?[...c.basePath,c.definitionPath,c.name]:c.basePath;return{...c,currentPath:d,propertyPath:void 0,seen:new Map(Object.entries(c.definitions).map(([a,b])=>[b._def,{def:b._def,path:[...c.basePath,c.definitionPath,a],jsonSchema:void 0}]))}})(b),e="object"==typeof b&&b.definitions?Object.entries(b.definitions).reduce((a,[b,c])=>{var e;return{...a,[b]:null!=(e=kk(c._def,{...d,currentPath:[...d.basePath,d.definitionPath,b]},!0))?e:{}}},{}):void 0,f="string"==typeof b?b:(null==b?void 0:b.nameStrategy)==="title"||null==b?void 0:b.name,g=null!=(c=kk(a._def,void 0===f?d:{...d,currentPath:[...d.basePath,d.definitionPath,f]},!1))?c:{},h="object"==typeof b&&void 0!==b.name&&"title"===b.nameStrategy?b.name:void 0;void 0!==h&&(g.title=h);let i=void 0===f?e?{...g,[d.definitionPath]:e}:g:{$ref:[..."relative"===d.$refStrategy?[]:d.basePath,d.definitionPath,f].join("/"),[d.definitionPath]:{...e,[f]:g}};return i.$schema="http://json-schema.org/draft-07/schema#",i})(a,{$refStrategy:e?"root":"none"}),{validate:async b=>{let c=await a.safeParseAsync(b);return c.success?{success:!0,value:c.data}:{success:!1,error:c.error}}})}async function ks({value:a,schema:b,context:c}){let d=await kt({value:a,schema:b,context:c});if(!d.success)throw az.wrap({value:a,cause:d.error,context:c});return d.value}async function kt({value:a,schema:b,context:c}){let d=kq(b);try{if(null==d.validate)return{success:!0,value:a,rawValue:a};let b=await d.validate(a);if(b.success)return{success:!0,value:b.value,rawValue:a};return{success:!1,error:az.wrap({value:a,cause:b.error,context:c}),rawValue:a}}catch(b){return{success:!1,error:az.wrap({value:a,cause:b,context:c}),rawValue:a}}}async function ku({text:a,schema:b}){try{let c=j4(a);if(null==b)return{success:!0,value:c,rawValue:c};return await kt({value:c,schema:b})}catch(b){return{success:!1,error:ap.isInstance(b)?b:new ap({text:a,cause:b}),rawValue:void 0}}}async function kv(a){return"function"==typeof a&&(a=a()),Promise.resolve(a)}var kw=Object.defineProperty,kx="AI_InvalidArgumentError",ky=`vercel.ai.error.${kx}`,kz=Symbol.for(ky);G=kz;Symbol.for("vercel.ai.error.AI_InvalidStreamPartError");var kA="AI_InvalidToolApprovalError",kB=`vercel.ai.error.${kA}`,kC=Symbol.for(kB);H=kC;var kD="AI_InvalidToolInputError",kE=`vercel.ai.error.${kD}`,kF=Symbol.for(kE);I=kF;var kG="AI_ToolCallNotFoundForApprovalError",kH=`vercel.ai.error.${kG}`,kI=Symbol.for(kH);J=kI;var kJ="AI_MissingToolResultsError",kK=`vercel.ai.error.${kJ}`,kL=Symbol.for(kK);K=kL;var kM="AI_NoImageGeneratedError",kN=`vercel.ai.error.${kM}`;L=Symbol.for(kN);var kO="AI_NoObjectGeneratedError",kP=`vercel.ai.error.${kO}`,kQ=Symbol.for(kP),kR=class extends ae{constructor({message:a="No object generated.",cause:b,text:c,response:d,usage:e,finishReason:f}){super({name:kO,message:a,cause:b}),this[M]=!0,this.text=c,this.response=d,this.usage=e,this.finishReason=f}static isInstance(a){return ae.hasMarker(a,kP)}};M=kQ;var kS="AI_NoOutputGeneratedError",kT=`vercel.ai.error.${kS}`,kU=Symbol.for(kT);N=kU;var kV="AI_NoSpeechGeneratedError",kW=`vercel.ai.error.${kV}`;O=Symbol.for(kW);var kX="AI_NoTranscriptGeneratedError",kY=`vercel.ai.error.${kX}`;P=Symbol.for(kY);var kZ="AI_NoVideoGeneratedError",k$=`vercel.ai.error.${kZ}`;Q=Symbol.for(k$);var k_="AI_NoSuchToolError",k0=`vercel.ai.error.${k_}`,k1=Symbol.for(k0);R=k1;var k2="AI_ToolCallRepairError",k3=`vercel.ai.error.${k2}`,k4=Symbol.for(k3);S=k4;var k5="AI_UIMessageStreamError",k6=`vercel.ai.error.${k5}`,k7=Symbol.for(k6),k8=class extends ae{constructor({chunkType:a,chunkId:b,message:c}){super({name:k5,message:c}),this[T]=!0,this.chunkType=a,this.chunkId=b}static isInstance(a){return ae.hasMarker(a,k6)}};T=k7;var k9="AI_InvalidDataContentError",la=`vercel.ai.error.${k9}`,lb=Symbol.for(la);U=lb;var lc="AI_InvalidMessageRoleError",ld=`vercel.ai.error.${lc}`,le=Symbol.for(ld);V=le;var lf="AI_MessageConversionError",lg=`vercel.ai.error.${lf}`,lh=Symbol.for(lg);W=lh;var li="AI_RetryError",lj=`vercel.ai.error.${li}`,lk=Symbol.for(lj);X=lk;var ll="6.0.86",lm=async({url:a,maxBytes:b,abortSignal:c})=>{var d;let e=a.toString();try{let a=await fetch(e,{headers:j0({},`ai-sdk/${ll}`,j$()),signal:c});if(!a.ok)throw new jW({url:e,statusCode:a.status,statusText:a.statusText});return{data:await jX({response:a,url:e,maxBytes:null!=b?b:0x80000000}),mediaType:null!=(d=a.headers.get("content-type"))?d:void 0}}catch(a){if(jW.isInstance(a))throw a;throw new jW({url:e,cause:a})}},ln=hz([f9(),iD(Uint8Array),iD(ArrayBuffer),iy(a=>{var b,c;return null!=(c=null==(b=globalThis.Buffer)?void 0:b.isBuffer(a))&&c},{message:"Must be a Buffer"})]),lo=ir(()=>hz([hg(),f9(),gZ(),g5(),hJ(f9(),lo.optional()),hs(lo)])),lp=hJ(f9(),hJ(f9(),lo.optional())),lq=hv({type:hU("text"),text:f9(),providerOptions:lp.optional()}),lr=hv({type:hU("image"),image:hz([ln,iD(URL)]),mediaType:f9().optional(),providerOptions:lp.optional()}),ls=hv({type:hU("file"),data:hz([ln,iD(URL)]),filename:f9().optional(),mediaType:f9(),providerOptions:lp.optional()}),lt=hv({type:hU("reasoning"),text:f9(),providerOptions:lp.optional()}),lu=hv({type:hU("tool-call"),toolCallId:f9(),toolName:f9(),input:hk(),providerOptions:lp.optional(),providerExecuted:g5().optional()}),lv=hD("type",[hv({type:hU("text"),value:f9(),providerOptions:lp.optional()}),hv({type:hU("json"),value:lo,providerOptions:lp.optional()}),hv({type:hU("execution-denied"),reason:f9().optional(),providerOptions:lp.optional()}),hv({type:hU("error-text"),value:f9(),providerOptions:lp.optional()}),hv({type:hU("error-json"),value:lo,providerOptions:lp.optional()}),hv({type:hU("content"),value:hs(hz([hv({type:hU("text"),text:f9(),providerOptions:lp.optional()}),hv({type:hU("media"),data:f9(),mediaType:f9()}),hv({type:hU("file-data"),data:f9(),mediaType:f9(),filename:f9().optional(),providerOptions:lp.optional()}),hv({type:hU("file-url"),url:f9(),providerOptions:lp.optional()}),hv({type:hU("file-id"),fileId:hz([f9(),hJ(f9(),f9())]),providerOptions:lp.optional()}),hv({type:hU("image-data"),data:f9(),mediaType:f9(),providerOptions:lp.optional()}),hv({type:hU("image-url"),url:f9(),providerOptions:lp.optional()}),hv({type:hU("image-file-id"),fileId:hz([f9(),hJ(f9(),f9())]),providerOptions:lp.optional()}),hv({type:hU("custom"),providerOptions:lp.optional()})]))})]),lw=hv({type:hU("tool-result"),toolCallId:f9(),toolName:f9(),output:lv,providerOptions:lp.optional()}),lx=hv({type:hU("tool-approval-request"),approvalId:f9(),toolCallId:f9()}),ly=hv({type:hU("tool-approval-response"),approvalId:f9(),approved:g5(),reason:f9().optional()}),lz=hv({role:hU("system"),content:f9(),providerOptions:lp.optional()}),lA=hv({role:hU("user"),content:hz([f9(),hs(hz([lq,lr,ls]))]),providerOptions:lp.optional()}),lB=hv({role:hU("assistant"),content:hz([f9(),hs(hz([lq,ls,lt,lu,lw,lx]))]),providerOptions:lp.optional()}),lC=hv({role:hU("tool"),content:hs(hz([lw,ly])),providerOptions:lp.optional()}),lD=hz([lz,lA,lB,lC]);function lE(a,b){if(void 0===a&&void 0===b)return;if(void 0===a)return b;if(void 0===b)return a;let c={...a};for(let d in b)if(Object.prototype.hasOwnProperty.call(b,d)){let e=b[d];if(void 0===e)continue;let f=d in a?a[d]:void 0,g=null!==e&&"object"==typeof e&&!Array.isArray(e)&&!(e instanceof Date)&&!(e instanceof RegExp),h=null!=f&&"object"==typeof f&&!Array.isArray(f)&&!(f instanceof Date)&&!(f instanceof RegExp);g&&h?c[d]=lE(f,e):c[d]=e}return c}async function lF(a){if(void 0===a)return{value:void 0,state:"undefined-input"};let b=await ku({text:a});return b.success?{value:b.value,state:"successful-parse"}:(b=await ku({text:function(a){let b=["ROOT"],c=-1,d=null;function e(a,e,f){switch(a){case'"':c=e,b.pop(),b.push(f),b.push("INSIDE_STRING");break;case"f":case"t":case"n":c=e,d=e,b.pop(),b.push(f),b.push("INSIDE_LITERAL");break;case"-":b.pop(),b.push(f),b.push("INSIDE_NUMBER");break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":c=e,b.pop(),b.push(f),b.push("INSIDE_NUMBER");break;case"{":c=e,b.pop(),b.push(f),b.push("INSIDE_OBJECT_START");break;case"[":c=e,b.pop(),b.push(f),b.push("INSIDE_ARRAY_START")}}function f(a,d){switch(a){case",":b.pop(),b.push("INSIDE_OBJECT_AFTER_COMMA");break;case"}":c=d,b.pop()}}function g(a,d){switch(a){case",":b.pop(),b.push("INSIDE_ARRAY_AFTER_COMMA");break;case"]":c=d,b.pop()}}for(let h=0;h<a.length;h++){let i=a[h];switch(b[b.length-1]){case"ROOT":e(i,h,"FINISH");break;case"INSIDE_OBJECT_START":switch(i){case'"':b.pop(),b.push("INSIDE_OBJECT_KEY");break;case"}":c=h,b.pop()}break;case"INSIDE_OBJECT_AFTER_COMMA":'"'===i&&(b.pop(),b.push("INSIDE_OBJECT_KEY"));break;case"INSIDE_OBJECT_KEY":'"'===i&&(b.pop(),b.push("INSIDE_OBJECT_AFTER_KEY"));break;case"INSIDE_OBJECT_AFTER_KEY":":"===i&&(b.pop(),b.push("INSIDE_OBJECT_BEFORE_VALUE"));break;case"INSIDE_OBJECT_BEFORE_VALUE":e(i,h,"INSIDE_OBJECT_AFTER_VALUE");break;case"INSIDE_OBJECT_AFTER_VALUE":f(i,h);break;case"INSIDE_STRING":switch(i){case'"':b.pop(),c=h;break;case"\\":b.push("INSIDE_STRING_ESCAPE");break;default:c=h}break;case"INSIDE_ARRAY_START":"]"===i?(c=h,b.pop()):(c=h,e(i,h,"INSIDE_ARRAY_AFTER_VALUE"));break;case"INSIDE_ARRAY_AFTER_VALUE":switch(i){case",":b.pop(),b.push("INSIDE_ARRAY_AFTER_COMMA");break;case"]":c=h,b.pop();break;default:c=h}break;case"INSIDE_ARRAY_AFTER_COMMA":e(i,h,"INSIDE_ARRAY_AFTER_VALUE");break;case"INSIDE_STRING_ESCAPE":b.pop(),c=h;break;case"INSIDE_NUMBER":switch(i){case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":c=h;break;case"e":case"E":case"-":case".":break;case",":b.pop(),"INSIDE_ARRAY_AFTER_VALUE"===b[b.length-1]&&g(i,h),"INSIDE_OBJECT_AFTER_VALUE"===b[b.length-1]&&f(i,h);break;case"}":b.pop(),"INSIDE_OBJECT_AFTER_VALUE"===b[b.length-1]&&f(i,h);break;case"]":b.pop(),"INSIDE_ARRAY_AFTER_VALUE"===b[b.length-1]&&g(i,h);break;default:b.pop()}break;case"INSIDE_LITERAL":{let e=a.substring(d,h+1);"false".startsWith(e)||"true".startsWith(e)||"null".startsWith(e)?c=h:(b.pop(),"INSIDE_OBJECT_AFTER_VALUE"===b[b.length-1]?f(i,h):"INSIDE_ARRAY_AFTER_VALUE"===b[b.length-1]&&g(i,h))}}}let h=a.slice(0,c+1);for(let c=b.length-1;c>=0;c--)switch(b[c]){case"INSIDE_STRING":h+='"';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":h+="}";break;case"INSIDE_ARRAY_START":case"INSIDE_ARRAY_AFTER_COMMA":case"INSIDE_ARRAY_AFTER_VALUE":h+="]";break;case"INSIDE_LITERAL":{let b=a.substring(d,a.length);"true".startsWith(b)?h+="true".slice(b.length):"false".startsWith(b)?h+="false".slice(b.length):"null".startsWith(b)&&(h+="null".slice(b.length))}}return h}(a)})).success?{value:b.value,state:"repaired-parse"}:{value:void 0,state:"failed-parse"}}((a,b)=>{for(var c in b)kw(a,c,{get:b[c],enumerable:!0})})({},{array:()=>lI,choice:()=>lJ,json:()=>lK,object:()=>lH,text:()=>lG});var lG=()=>({name:"text",responseFormat:Promise.resolve({type:"text"}),parseCompleteOutput:async({text:a})=>a,parsePartialOutput:async({text:a})=>({partial:a}),createElementStreamTransform(){}}),lH=({schema:a,name:b,description:c})=>{let d=kq(a);return{name:"object",responseFormat:kv(d.jsonSchema).then(a=>({type:"json",schema:a,...null!=b&&{name:b},...null!=c&&{description:c}})),async parseCompleteOutput({text:a},b){let c=await ku({text:a});if(!c.success)throw new kR({message:"No object generated: could not parse the response.",cause:c.error,text:a,response:b.response,usage:b.usage,finishReason:b.finishReason});let e=await kt({value:c.value,schema:d});if(!e.success)throw new kR({message:"No object generated: response did not match schema.",cause:e.error,text:a,response:b.response,usage:b.usage,finishReason:b.finishReason});return e.value},async parsePartialOutput({text:a}){let b=await lF(a);switch(b.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return{partial:b.value}}},createElementStreamTransform(){}}},lI=({element:a,name:b,description:c})=>{let d=kq(a);return{name:"array",responseFormat:kv(d.jsonSchema).then(a=>{let{$schema:d,...e}=a;return{type:"json",schema:{$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{elements:{type:"array",items:e}},required:["elements"],additionalProperties:!1},...null!=b&&{name:b},...null!=c&&{description:c}}}),async parseCompleteOutput({text:a},b){let c=await ku({text:a});if(!c.success)throw new kR({message:"No object generated: could not parse the response.",cause:c.error,text:a,response:b.response,usage:b.usage,finishReason:b.finishReason});let e=c.value;if(null==e||"object"!=typeof e||!("elements"in e)||!Array.isArray(e.elements))throw new kR({message:"No object generated: response did not match schema.",cause:new az({value:e,cause:"response must be an object with an elements array"}),text:a,response:b.response,usage:b.usage,finishReason:b.finishReason});for(let c of e.elements){let e=await kt({value:c,schema:d});if(!e.success)throw new kR({message:"No object generated: response did not match schema.",cause:e.error,text:a,response:b.response,usage:b.usage,finishReason:b.finishReason})}return e.elements},async parsePartialOutput({text:a}){let b=await lF(a);switch(b.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":{let a=b.value;if(null==a||"object"!=typeof a||!("elements"in a)||!Array.isArray(a.elements))return;let c="repaired-parse"===b.state&&a.elements.length>0?a.elements.slice(0,-1):a.elements,e=[];for(let a of c){let b=await kt({value:a,schema:d});b.success&&e.push(b.value)}return{partial:e}}}},createElementStreamTransform(){let a=0;return new TransformStream({transform({partialOutput:b},c){if(null!=b)for(;a<b.length;a++)c.enqueue(b[a])}})}}},lJ=({options:a,name:b,description:c})=>({name:"choice",responseFormat:Promise.resolve({type:"json",schema:{$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{result:{type:"string",enum:a}},required:["result"],additionalProperties:!1},...null!=b&&{name:b},...null!=c&&{description:c}}),async parseCompleteOutput({text:b},c){let d=await ku({text:b});if(!d.success)throw new kR({message:"No object generated: could not parse the response.",cause:d.error,text:b,response:c.response,usage:c.usage,finishReason:c.finishReason});let e=d.value;if(null==e||"object"!=typeof e||!("result"in e)||"string"!=typeof e.result||!a.includes(e.result))throw new kR({message:"No object generated: response did not match schema.",cause:new az({value:e,cause:"response must be an object that contains a choice value."}),text:b,response:c.response,usage:c.usage,finishReason:c.finishReason});return e.result},async parsePartialOutput({text:b}){let c=await lF(b);switch(c.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":{let b=c.value;if(null==b||"object"!=typeof b||!("result"in b)||"string"!=typeof b.result)return;let d=a.filter(a=>a.startsWith(b.result));if("successful-parse"===c.state)return d.includes(b.result)?{partial:b.result}:void 0;return 1===d.length?{partial:d[0]}:void 0}}},createElementStreamTransform(){}}),lK=({name:a,description:b}={})=>({name:"json",responseFormat:Promise.resolve({type:"json",...null!=a&&{name:a},...null!=b&&{description:b}}),async parseCompleteOutput({text:a},b){let c=await ku({text:a});if(!c.success)throw new kR({message:"No object generated: could not parse the response.",cause:c.error,text:a,response:b.response,usage:b.usage,finishReason:b.finishReason});return c.value},async parsePartialOutput({text:a}){let b=await lF(a);switch(b.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return void 0===b.value?void 0:{partial:b.value}}},createElementStreamTransform(){}});jY({prefix:"aitxt",size:24});(class extends TransformStream{constructor(){super({transform(a,b){b.enqueue(`data: ${JSON.stringify(a)}
134
134
 
135
- `)},flush(a){a.enqueue("data: [DONE]\n\n")}})}});var lL=ko(()=>kr(hz([hw({type:hU("text-start"),id:f9(),providerMetadata:lp.optional()}),hw({type:hU("text-delta"),id:f9(),delta:f9(),providerMetadata:lp.optional()}),hw({type:hU("text-end"),id:f9(),providerMetadata:lp.optional()}),hw({type:hU("error"),errorText:f9()}),hw({type:hU("tool-input-start"),toolCallId:f9(),toolName:f9(),providerExecuted:g5().optional(),providerMetadata:lp.optional(),dynamic:g5().optional(),title:f9().optional()}),hw({type:hU("tool-input-delta"),toolCallId:f9(),inputTextDelta:f9()}),hw({type:hU("tool-input-available"),toolCallId:f9(),toolName:f9(),input:hk(),providerExecuted:g5().optional(),providerMetadata:lp.optional(),dynamic:g5().optional(),title:f9().optional()}),hw({type:hU("tool-input-error"),toolCallId:f9(),toolName:f9(),input:hk(),providerExecuted:g5().optional(),providerMetadata:lp.optional(),dynamic:g5().optional(),errorText:f9(),title:f9().optional()}),hw({type:hU("tool-approval-request"),approvalId:f9(),toolCallId:f9()}),hw({type:hU("tool-output-available"),toolCallId:f9(),output:hk(),providerExecuted:g5().optional(),dynamic:g5().optional(),preliminary:g5().optional()}),hw({type:hU("tool-output-error"),toolCallId:f9(),errorText:f9(),providerExecuted:g5().optional(),dynamic:g5().optional()}),hw({type:hU("tool-output-denied"),toolCallId:f9()}),hw({type:hU("reasoning-start"),id:f9(),providerMetadata:lp.optional()}),hw({type:hU("reasoning-delta"),id:f9(),delta:f9(),providerMetadata:lp.optional()}),hw({type:hU("reasoning-end"),id:f9(),providerMetadata:lp.optional()}),hw({type:hU("source-url"),sourceId:f9(),url:f9(),title:f9().optional(),providerMetadata:lp.optional()}),hw({type:hU("source-document"),sourceId:f9(),mediaType:f9(),title:f9(),filename:f9().optional(),providerMetadata:lp.optional()}),hw({type:hU("file"),url:f9(),mediaType:f9(),providerMetadata:lp.optional()}),hw({type:iy(a=>"string"==typeof a&&a.startsWith("data-"),{message:'Type must start with "data-"'}),id:f9().optional(),data:hk(),transient:g5().optional()}),hw({type:hU("start-step")}),hw({type:hU("finish-step")}),hw({type:hU("start"),messageId:f9().optional(),messageMetadata:hk().optional()}),hw({type:hU("finish"),finishReason:hR(["stop","length","content-filter","tool-calls","error","other"]).optional(),messageMetadata:hk().optional()}),hw({type:hU("abort"),reason:f9().optional()}),hw({type:hU("message-metadata"),messageMetadata:hk()})])));function lM(a){return a.type.startsWith("tool-")}function lN(a){return"dynamic-tool"===a.type}function lO(a){return lM(a)||lN(a)}function lP(a){return a.type.split("-").slice(1).join("-")}function lQ({lastMessage:a,messageId:b}){return{message:(null==a?void 0:a.role)==="assistant"?a:{id:b,metadata:void 0,role:"assistant",parts:[]},activeTextParts:{},activeReasoningParts:{},partialToolCalls:{}}}function lR({stream:a,messageMetadataSchema:b,dataPartSchemas:c,runUpdateMessageJob:d,onError:e,onToolCall:f,onData:g}){return a.pipeThrough(new TransformStream({async transform(a,h){await d(async({state:d,write:i})=>{var j,k,l,m;function n(a){let b=d.message.parts.filter(lO).find(b=>b.toolCallId===a);if(null==b)throw new k8({chunkType:"tool-invocation",chunkId:a,message:`No tool invocation found for tool call ID "${a}".`});return b}function o(a){var b;let c=d.message.parts.find(b=>lM(b)&&b.toolCallId===a.toolCallId);null!=c?(c.state=a.state,c.input=a.input,c.output=a.output,c.errorText=a.errorText,c.rawInput=a.rawInput,c.preliminary=a.preliminary,void 0!==a.title&&(c.title=a.title),c.providerExecuted=null!=(b=a.providerExecuted)?b:c.providerExecuted,null!=a.providerMetadata&&(c.callProviderMetadata=a.providerMetadata)):d.message.parts.push({type:`tool-${a.toolName}`,toolCallId:a.toolCallId,state:a.state,title:a.title,input:a.input,output:a.output,rawInput:a.rawInput,errorText:a.errorText,providerExecuted:a.providerExecuted,preliminary:a.preliminary,...null!=a.providerMetadata?{callProviderMetadata:a.providerMetadata}:{}})}function p(a){var b,c;let e=d.message.parts.find(b=>"dynamic-tool"===b.type&&b.toolCallId===a.toolCallId);null!=e?(e.state=a.state,e.toolName=a.toolName,e.input=a.input,e.output=a.output,e.errorText=a.errorText,e.rawInput=null!=(b=a.rawInput)?b:e.rawInput,e.preliminary=a.preliminary,void 0!==a.title&&(e.title=a.title),e.providerExecuted=null!=(c=a.providerExecuted)?c:e.providerExecuted,null!=a.providerMetadata&&(e.callProviderMetadata=a.providerMetadata)):d.message.parts.push({type:"dynamic-tool",toolName:a.toolName,toolCallId:a.toolCallId,state:a.state,input:a.input,output:a.output,errorText:a.errorText,preliminary:a.preliminary,providerExecuted:a.providerExecuted,title:a.title,...null!=a.providerMetadata?{callProviderMetadata:a.providerMetadata}:{}})}async function q(a){if(null!=a){let c=null!=d.message.metadata?lE(d.message.metadata,a):a;null!=b&&await ks({value:c,schema:b,context:{field:"message.metadata",entityId:d.message.id}}),d.message.metadata=c}}switch(a.type){case"text-start":{let b={type:"text",text:"",providerMetadata:a.providerMetadata,state:"streaming"};d.activeTextParts[a.id]=b,d.message.parts.push(b),i();break}case"text-delta":{let b=d.activeTextParts[a.id];if(null==b)throw new k8({chunkType:"text-delta",chunkId:a.id,message:`Received text-delta for missing text part with ID "${a.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`});b.text+=a.delta,b.providerMetadata=null!=(j=a.providerMetadata)?j:b.providerMetadata,i();break}case"text-end":{let b=d.activeTextParts[a.id];if(null==b)throw new k8({chunkType:"text-end",chunkId:a.id,message:`Received text-end for missing text part with ID "${a.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`});b.state="done",b.providerMetadata=null!=(k=a.providerMetadata)?k:b.providerMetadata,delete d.activeTextParts[a.id],i();break}case"reasoning-start":{let b={type:"reasoning",text:"",providerMetadata:a.providerMetadata,state:"streaming"};d.activeReasoningParts[a.id]=b,d.message.parts.push(b),i();break}case"reasoning-delta":{let b=d.activeReasoningParts[a.id];if(null==b)throw new k8({chunkType:"reasoning-delta",chunkId:a.id,message:`Received reasoning-delta for missing reasoning part with ID "${a.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`});b.text+=a.delta,b.providerMetadata=null!=(l=a.providerMetadata)?l:b.providerMetadata,i();break}case"reasoning-end":{let b=d.activeReasoningParts[a.id];if(null==b)throw new k8({chunkType:"reasoning-end",chunkId:a.id,message:`Received reasoning-end for missing reasoning part with ID "${a.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`});b.providerMetadata=null!=(m=a.providerMetadata)?m:b.providerMetadata,b.state="done",delete d.activeReasoningParts[a.id],i();break}case"file":d.message.parts.push({type:"file",mediaType:a.mediaType,url:a.url}),i();break;case"source-url":d.message.parts.push({type:"source-url",sourceId:a.sourceId,url:a.url,title:a.title,providerMetadata:a.providerMetadata}),i();break;case"source-document":d.message.parts.push({type:"source-document",sourceId:a.sourceId,mediaType:a.mediaType,title:a.title,filename:a.filename,providerMetadata:a.providerMetadata}),i();break;case"tool-input-start":{let b=d.message.parts.filter(lM);d.partialToolCalls[a.toolCallId]={text:"",toolName:a.toolName,index:b.length,dynamic:a.dynamic,title:a.title},a.dynamic?p({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-streaming",input:void 0,providerExecuted:a.providerExecuted,title:a.title,providerMetadata:a.providerMetadata}):o({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-streaming",input:void 0,providerExecuted:a.providerExecuted,title:a.title,providerMetadata:a.providerMetadata}),i();break}case"tool-input-delta":{let b=d.partialToolCalls[a.toolCallId];if(null==b)throw new k8({chunkType:"tool-input-delta",chunkId:a.toolCallId,message:`Received tool-input-delta for missing tool call with ID "${a.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`});b.text+=a.inputTextDelta;let{value:c}=await lF(b.text);b.dynamic?p({toolCallId:a.toolCallId,toolName:b.toolName,state:"input-streaming",input:c,title:b.title}):o({toolCallId:a.toolCallId,toolName:b.toolName,state:"input-streaming",input:c,title:b.title}),i();break}case"tool-input-available":a.dynamic?p({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-available",input:a.input,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata,title:a.title}):o({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-available",input:a.input,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata,title:a.title}),i(),f&&!a.providerExecuted&&await f({toolCall:a});break;case"tool-input-error":a.dynamic?p({toolCallId:a.toolCallId,toolName:a.toolName,state:"output-error",input:a.input,errorText:a.errorText,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}):o({toolCallId:a.toolCallId,toolName:a.toolName,state:"output-error",input:void 0,rawInput:a.input,errorText:a.errorText,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}),i();break;case"tool-approval-request":{let b=n(a.toolCallId);b.state="approval-requested",b.approval={id:a.approvalId},i();break}case"tool-output-denied":n(a.toolCallId).state="output-denied",i();break;case"tool-output-available":{let b=n(a.toolCallId);"dynamic-tool"===b.type?p({toolCallId:a.toolCallId,toolName:b.toolName,state:"output-available",input:b.input,output:a.output,preliminary:a.preliminary,providerExecuted:a.providerExecuted,title:b.title}):o({toolCallId:a.toolCallId,toolName:lP(b),state:"output-available",input:b.input,output:a.output,providerExecuted:a.providerExecuted,preliminary:a.preliminary,title:b.title}),i();break}case"tool-output-error":{let b=n(a.toolCallId);"dynamic-tool"===b.type?p({toolCallId:a.toolCallId,toolName:b.toolName,state:"output-error",input:b.input,errorText:a.errorText,providerExecuted:a.providerExecuted,title:b.title}):o({toolCallId:a.toolCallId,toolName:lP(b),state:"output-error",input:b.input,rawInput:b.rawInput,errorText:a.errorText,providerExecuted:a.providerExecuted,title:b.title}),i();break}case"start-step":d.message.parts.push({type:"step-start"});break;case"finish-step":d.activeTextParts={},d.activeReasoningParts={};break;case"start":null!=a.messageId&&(d.message.id=a.messageId),await q(a.messageMetadata),(null!=a.messageId||null!=a.messageMetadata)&&i();break;case"finish":null!=a.finishReason&&(d.finishReason=a.finishReason),await q(a.messageMetadata),null!=a.messageMetadata&&i();break;case"message-metadata":await q(a.messageMetadata),null!=a.messageMetadata&&i();break;case"error":null==e||e(Error(a.errorText));break;default:if(a.type.startsWith("data-")){if((null==c?void 0:c[a.type])!=null){let b=d.message.parts.findIndex(b=>"id"in b&&"data"in b&&b.id===a.id&&b.type===a.type),e=b>=0?b:d.message.parts.length;await ks({value:a.data,schema:c[a.type],context:{field:`message.parts[${e}].data`,entityName:a.type,entityId:a.id}})}if(a.transient){null==g||g(a);break}let b=null!=a.id?d.message.parts.find(b=>a.type===b.type&&a.id===b.id):void 0;null!=b?b.data=a.data:d.message.parts.push(a),null==g||g(a),i()}}h.enqueue(a)})}}))}async function lS({stream:a,onError:b}){let c=a.getReader();try{for(;;){let{done:a}=await c.read();if(a)break}}catch(a){null==b||b(a)}finally{c.releaseLock()}}jY({prefix:"aitxt",size:24});ko(()=>kr(hs(hv({id:f9(),role:hR(["system","user","assistant"]),metadata:hk().optional(),parts:hs(hz([hv({type:hU("text"),text:f9(),state:hR(["streaming","done"]).optional(),providerMetadata:lp.optional()}),hv({type:hU("reasoning"),text:f9(),state:hR(["streaming","done"]).optional(),providerMetadata:lp.optional()}),hv({type:hU("source-url"),sourceId:f9(),url:f9(),title:f9().optional(),providerMetadata:lp.optional()}),hv({type:hU("source-document"),sourceId:f9(),mediaType:f9(),title:f9(),filename:f9().optional(),providerMetadata:lp.optional()}),hv({type:hU("file"),mediaType:f9(),filename:f9().optional(),url:f9(),providerMetadata:lp.optional()}),hv({type:hU("step-start")}),hv({type:f9().startsWith("data-"),id:f9().optional(),data:hk()}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("input-streaming"),input:hk().optional(),providerExecuted:g5().optional(),callProviderMetadata:lp.optional(),output:hm().optional(),errorText:hm().optional(),approval:hm().optional()}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("input-available"),input:hk(),providerExecuted:g5().optional(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hm().optional()}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("approval-requested"),input:hk(),providerExecuted:g5().optional(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:hm().optional(),reason:hm().optional()})}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("approval-responded"),input:hk(),providerExecuted:g5().optional(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:g5(),reason:f9().optional()})}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("output-available"),input:hk(),providerExecuted:g5().optional(),output:hk(),errorText:hm().optional(),callProviderMetadata:lp.optional(),preliminary:g5().optional(),approval:hv({id:f9(),approved:hU(!0),reason:f9().optional()}).optional()}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("output-error"),input:hk(),rawInput:hk().optional(),providerExecuted:g5().optional(),output:hm().optional(),errorText:f9(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:hU(!0),reason:f9().optional()}).optional()}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("output-denied"),input:hk(),providerExecuted:g5().optional(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:hU(!1),reason:f9().optional()})}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("input-streaming"),providerExecuted:g5().optional(),callProviderMetadata:lp.optional(),input:hk().optional(),output:hm().optional(),errorText:hm().optional(),approval:hm().optional()}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("input-available"),providerExecuted:g5().optional(),input:hk(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hm().optional()}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("approval-requested"),input:hk(),providerExecuted:g5().optional(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:hm().optional(),reason:hm().optional()})}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("approval-responded"),input:hk(),providerExecuted:g5().optional(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:g5(),reason:f9().optional()})}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("output-available"),providerExecuted:g5().optional(),input:hk(),output:hk(),errorText:hm().optional(),callProviderMetadata:lp.optional(),preliminary:g5().optional(),approval:hv({id:f9(),approved:hU(!0),reason:f9().optional()}).optional()}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("output-error"),providerExecuted:g5().optional(),input:hk(),rawInput:hk().optional(),output:hm().optional(),errorText:f9(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:hU(!0),reason:f9().optional()}).optional()}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("output-denied"),providerExecuted:g5().optional(),input:hk(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:hU(!1),reason:f9().optional()})})])).nonempty("Message must contain at least one part")})).nonempty("Messages array must not be empty")));function lT(a){return({url:b,abortSignal:c})=>lm({url:b,maxBytes:null==a?void 0:a.maxBytes,abortSignal:c})}jY({prefix:"aiobj",size:24});var lU=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(a){return new Promise((b,c)=>{this.queue.push(async()=>{try{await a(),b()}catch(a){c(a)}}),this.processQueue()})}};jY({prefix:"aiobj",size:24}),lT();var lV="AI_NoSuchProviderError",lW=`vercel.ai.error.${lV}`,lX=Symbol.for(lW);Y=lX,lT();async function lY(a){if(null==a)return[];if(!globalThis.FileList||!(a instanceof globalThis.FileList))throw Error("FileList is not supported in the current environment");return Promise.all(Array.from(a).map(async a=>{let{name:b,type:c}=a;return{type:"file",mediaType:c,filename:b,url:await new Promise((b,c)=>{let d=new FileReader;d.onload=a=>{var c;b(null==(c=a.target)?void 0:c.result)},d.onerror=a=>c(a),d.readAsDataURL(a)})}}))}var lZ=class{constructor({api:a="/api/chat",credentials:b,headers:c,body:d,fetch:e,prepareSendMessagesRequest:f,prepareReconnectToStreamRequest:g}){this.api=a,this.credentials=b,this.headers=c,this.body=d,this.fetch=e,this.prepareSendMessagesRequest=f,this.prepareReconnectToStreamRequest=g}async sendMessages({abortSignal:a,...b}){var c,d,e,f,g;let h=await kv(this.body),i=await kv(this.headers),j=await kv(this.credentials),k={...j_(i),...j_(b.headers)},l=await (null==(c=this.prepareSendMessagesRequest)?void 0:c.call(this,{api:this.api,id:b.chatId,messages:b.messages,body:{...h,...b.body},headers:k,credentials:j,requestMetadata:b.metadata,trigger:b.trigger,messageId:b.messageId})),m=null!=(d=null==l?void 0:l.api)?d:this.api,n=(null==l?void 0:l.headers)!==void 0?j_(l.headers):k,o=(null==l?void 0:l.body)!==void 0?l.body:{...h,...b.body,id:b.chatId,messages:b.messages,trigger:b.trigger,messageId:b.messageId},p=null!=(e=null==l?void 0:l.credentials)?e:j,q=null!=(f=this.fetch)?f:globalThis.fetch,r=await q(m,{method:"POST",headers:j0({"Content-Type":"application/json",...n},`ai-sdk/${ll}`,j$()),body:JSON.stringify(o),credentials:p,signal:a});if(!r.ok)throw Error(null!=(g=await r.text())?g:"Failed to fetch the chat response.");if(!r.body)throw Error("The response body is empty.");return this.processResponseStream(r.body)}async reconnectToStream(a){var b,c,d,e,f;let g=await kv(this.body),h=await kv(this.headers),i=await kv(this.credentials),j={...j_(h),...j_(a.headers)},k=await (null==(b=this.prepareReconnectToStreamRequest)?void 0:b.call(this,{api:this.api,id:a.chatId,body:{...g,...a.body},headers:j,credentials:i,requestMetadata:a.metadata})),l=null!=(c=null==k?void 0:k.api)?c:`${this.api}/${a.chatId}/stream`,m=(null==k?void 0:k.headers)!==void 0?j_(k.headers):j,n=null!=(d=null==k?void 0:k.credentials)?d:i,o=null!=(e=this.fetch)?e:globalThis.fetch,p=await o(l,{method:"GET",headers:j0(m,`ai-sdk/${ll}`,j$()),credentials:n});if(204===p.status)return null;if(!p.ok)throw Error(null!=(f=await p.text())?f:"Failed to fetch the chat response.");if(!p.body)throw Error("The response body is empty.");return this.processResponseStream(p.body)}},l$=class extends lZ{constructor(a={}){super(a)}processResponseStream(a){return(function({stream:a,schema:b}){return a.pipeThrough(new TextDecoderStream).pipeThrough(new jQ).pipeThrough(new TransformStream({async transform({data:a},c){"[DONE]"!==a&&c.enqueue(await ku({text:a,schema:b}))}}))})({stream:a,schema:lL}).pipeThrough(new TransformStream({async transform(a,b){if(!a.success)throw a.error;b.enqueue(a.value)}}))}},l_=class{constructor({generateId:a=jZ,id:b=a(),transport:c=new l$,messageMetadataSchema:d,dataPartSchemas:e,state:f,onError:g,onToolCall:h,onFinish:i,onData:j,sendAutomaticallyWhen:k}){this.activeResponse=void 0,this.jobExecutor=new lU,this.sendMessage=async(a,b)=>{var c,d,e,f;let g;if(null==a)return void await this.makeRequest({trigger:"submit-message",messageId:null==(c=this.lastMessage)?void 0:c.id,...b});if(g="text"in a||"files"in a?{parts:[...Array.isArray(a.files)?a.files:await lY(a.files),..."text"in a&&null!=a.text?[{type:"text",text:a.text}]:[]]}:a,null!=a.messageId){let b=this.state.messages.findIndex(b=>b.id===a.messageId);if(-1===b)throw Error(`message with id ${a.messageId} not found`);if("user"!==this.state.messages[b].role)throw Error(`message with id ${a.messageId} is not a user message`);this.state.messages=this.state.messages.slice(0,b+1),this.state.replaceMessage(b,{...g,id:a.messageId,role:null!=(d=g.role)?d:"user",metadata:a.metadata})}else this.state.pushMessage({...g,id:null!=(e=g.id)?e:this.generateId(),role:null!=(f=g.role)?f:"user",metadata:a.metadata});await this.makeRequest({trigger:"submit-message",messageId:a.messageId,...b})},this.regenerate=async({messageId:a,...b}={})=>{let c=null==a?this.state.messages.length-1:this.state.messages.findIndex(b=>b.id===a);if(-1===c)throw Error(`message ${a} not found`);this.state.messages=this.state.messages.slice(0,"assistant"===this.messages[c].role?c:c+1),await this.makeRequest({trigger:"regenerate-message",messageId:a,...b})},this.resumeStream=async(a={})=>{await this.makeRequest({trigger:"resume-stream",...a})},this.clearError=()=>{"error"===this.status&&(this.state.error=void 0,this.setStatus({status:"ready"}))},this.addToolApprovalResponse=async({id:a,approved:b,reason:c})=>this.jobExecutor.run(async()=>{let d=this.state.messages,e=d[d.length-1],f=d=>lO(d)&&"approval-requested"===d.state&&d.approval.id===a?{...d,state:"approval-responded",approval:{id:a,approved:b,reason:c}}:d;this.state.replaceMessage(d.length-1,{...e,parts:e.parts.map(f)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(f)),"streaming"!==this.status&&"submitted"!==this.status&&this.sendAutomaticallyWhen&&this.shouldSendAutomatically().then(a=>{var b;a&&this.makeRequest({trigger:"submit-message",messageId:null==(b=this.lastMessage)?void 0:b.id})})}),this.addToolOutput=async({state:a="output-available",tool:b,toolCallId:c,output:d,errorText:e})=>this.jobExecutor.run(async()=>{let b=this.state.messages,f=b[b.length-1],g=b=>lO(b)&&b.toolCallId===c?{...b,state:a,output:d,errorText:e}:b;this.state.replaceMessage(b.length-1,{...f,parts:f.parts.map(g)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(g)),"streaming"!==this.status&&"submitted"!==this.status&&this.sendAutomaticallyWhen&&this.shouldSendAutomatically().then(a=>{var b;a&&this.makeRequest({trigger:"submit-message",messageId:null==(b=this.lastMessage)?void 0:b.id})})}),this.addToolResult=this.addToolOutput,this.stop=async()=>{var a;("streaming"===this.status||"submitted"===this.status)&&(null==(a=this.activeResponse)?void 0:a.abortController)&&this.activeResponse.abortController.abort()},this.id=b,this.transport=c,this.generateId=a,this.messageMetadataSchema=d,this.dataPartSchemas=e,this.state=f,this.onError=g,this.onToolCall=h,this.onFinish=i,this.onData=j,this.sendAutomaticallyWhen=k}get status(){return this.state.status}setStatus({status:a,error:b}){this.status!==a&&(this.state.status=a,this.state.error=b)}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(a){this.state.messages=a}async shouldSendAutomatically(){if(!this.sendAutomaticallyWhen)return!1;let a=this.sendAutomaticallyWhen({messages:this.state.messages});return a&&"object"==typeof a&&"then"in a?await a:a}async makeRequest({trigger:a,metadata:b,headers:c,body:d,messageId:e}){var f,g,h;this.setStatus({status:"submitted",error:void 0});let i=this.lastMessage,j=!1,k=!1,l=!1;try{let f,g={state:lQ({lastMessage:this.state.snapshot(i),messageId:this.generateId()}),abortController:new AbortController};if(g.abortController.signal.addEventListener("abort",()=>{j=!0}),this.activeResponse=g,"resume-stream"===a){let a=await this.transport.reconnectToStream({chatId:this.id,metadata:b,headers:c,body:d});if(null==a)return void this.setStatus({status:"ready"});f=a}else f=await this.transport.sendMessages({chatId:this.id,messages:this.state.messages,abortSignal:g.abortController.signal,metadata:b,headers:c,body:d,trigger:a,messageId:e});let h=a=>this.jobExecutor.run(()=>a({state:g.state,write:()=>{var a;this.setStatus({status:"streaming"}),g.state.message.id===(null==(a=this.lastMessage)?void 0:a.id)?this.state.replaceMessage(this.state.messages.length-1,g.state.message):this.state.pushMessage(g.state.message)}}));await lS({stream:lR({stream:f,onToolCall:this.onToolCall,onData:this.onData,messageMetadataSchema:this.messageMetadataSchema,dataPartSchemas:this.dataPartSchemas,runUpdateMessageJob:h,onError:a=>{throw a}}),onError:a=>{throw a}}),this.setStatus({status:"ready"})}catch(a){if(j||"AbortError"===a.name)return j=!0,this.setStatus({status:"ready"}),null;l=!0,a instanceof TypeError&&(a.message.toLowerCase().includes("fetch")||a.message.toLowerCase().includes("network"))&&(k=!0),this.onError&&a instanceof Error&&this.onError(a),this.setStatus({status:"error",error:a})}finally{try{null==(g=this.onFinish)||g.call(this,{message:this.activeResponse.state.message,messages:this.state.messages,isAbort:j,isDisconnect:k,isError:l,finishReason:null==(f=this.activeResponse)?void 0:f.state.finishReason})}catch(a){console.error(a)}this.activeResponse=void 0}!l&&await this.shouldSendAutomatically()&&await this.makeRequest({trigger:"submit-message",messageId:null==(h=this.lastMessage)?void 0:h.id,metadata:b,headers:c,body:d})}}},30342:(a,b,c)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"});let d=c(44002),e=c(87011);b.matches=function(a){return a=e.cloneDeep(a),b=>d.isMatch(b,a)}},30858:(a,b,c)=>{"use strict";c.d(b,{i:()=>f});var d=c(86102),e=c(2714);function f(a,b){let{start:c,end:f}=(0,d.P)(b?.in,a),g=+c>+f,h=g?+c:+f,i=g?f:c;i.setHours(0,0,0,0),i.setDate(1);let j=b?.step??1;if(!j)return[];j<0&&(j=-j,g=!g);let k=[];for(;+i<=h;)k.push((0,e.w)(c,i)),i.setMonth(i.getMonth()+j);return g?k.reverse():k}},31038:(a,b,c)=>{"use strict";c.d(b,{A:()=>d});let d=(0,c(15336).A)("zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]])},31480:(a,b,c)=>{"use strict";function d(a){this.content=a}c.d(b,{S4:()=>O,ZF:()=>X,FK:()=>e,CU:()=>i,sX:()=>L,bP:()=>x,u$:()=>v,vI:()=>j,Sj:()=>M,Ji:()=>k}),d.prototype={constructor:d,find:function(a){for(var b=0;b<this.content.length;b+=2)if(this.content[b]===a)return b;return -1},get:function(a){var b=this.find(a);return -1==b?void 0:this.content[b+1]},update:function(a,b,c){var e=c&&c!=a?this.remove(c):this,f=e.find(a),g=e.content.slice();return -1==f?g.push(c||a,b):(g[f+1]=b,c&&(g[f]=c)),new d(g)},remove:function(a){var b=this.find(a);if(-1==b)return this;var c=this.content.slice();return c.splice(b,2),new d(c)},addToStart:function(a,b){return new d([a,b].concat(this.remove(a).content))},addToEnd:function(a,b){var c=this.remove(a).content.slice();return c.push(a,b),new d(c)},addBefore:function(a,b,c){var e=this.remove(b),f=e.content.slice(),g=e.find(a);return f.splice(-1==g?f.length:g,0,b,c),new d(f)},forEach:function(a){for(var b=0;b<this.content.length;b+=2)a(this.content[b],this.content[b+1])},prepend:function(a){return(a=d.from(a)).size?new d(a.content.concat(this.subtract(a).content)):this},append:function(a){return(a=d.from(a)).size?new d(this.subtract(a).content.concat(a.content)):this},subtract:function(a){var b=this;a=d.from(a);for(var c=0;c<a.content.length;c+=2)b=b.remove(a.content[c]);return b},toObject:function(){var a={};return this.forEach(function(b,c){a[b]=c}),a},get size(){return this.content.length>>1}},d.from=function(a){if(a instanceof d)return a;var b=[];if(a)for(var c in a)b.push(c,a[c]);return new d(b)};class e{constructor(a,b){if(this.content=a,this.size=b||0,null==b)for(let b=0;b<a.length;b++)this.size+=a[b].nodeSize}nodesBetween(a,b,c,d=0,e){for(let f=0,g=0;g<b;f++){let h=this.content[f],i=g+h.nodeSize;if(i>a&&!1!==c(h,d+g,e||null,f)&&h.content.size){let e=g+1;h.nodesBetween(Math.max(0,a-e),Math.min(h.content.size,b-e),c,d+e)}g=i}}descendants(a){this.nodesBetween(0,this.size,a)}textBetween(a,b,c,d){let e="",f=!0;return this.nodesBetween(a,b,(g,h)=>{let i=g.isText?g.text.slice(Math.max(a,h)-h,b-h):g.isLeaf?d?"function"==typeof d?d(g):d:g.type.spec.leafText?g.type.spec.leafText(g):"":"";g.isBlock&&(g.isLeaf&&i||g.isTextblock)&&c&&(f?f=!1:e+=c),e+=i},0),e}append(a){if(!a.size)return this;if(!this.size)return a;let b=this.lastChild,c=a.firstChild,d=this.content.slice(),f=0;for(b.isText&&b.sameMarkup(c)&&(d[d.length-1]=b.withText(b.text+c.text),f=1);f<a.content.length;f++)d.push(a.content[f]);return new e(d,this.size+a.size)}cut(a,b=this.size){if(0==a&&b==this.size)return this;let c=[],d=0;if(b>a)for(let e=0,f=0;f<b;e++){let g=this.content[e],h=f+g.nodeSize;h>a&&((f<a||h>b)&&(g=g.isText?g.cut(Math.max(0,a-f),Math.min(g.text.length,b-f)):g.cut(Math.max(0,a-f-1),Math.min(g.content.size,b-f-1))),c.push(g),d+=g.nodeSize),f=h}return new e(c,d)}cutByIndex(a,b){return a==b?e.empty:0==a&&b==this.content.length?this:new e(this.content.slice(a,b))}replaceChild(a,b){let c=this.content[a];if(c==b)return this;let d=this.content.slice(),f=this.size+b.nodeSize-c.nodeSize;return d[a]=b,new e(d,f)}addToStart(a){return new e([a].concat(this.content),this.size+a.nodeSize)}addToEnd(a){return new e(this.content.concat(a),this.size+a.nodeSize)}eq(a){if(this.content.length!=a.content.length)return!1;for(let b=0;b<this.content.length;b++)if(!this.content[b].eq(a.content[b]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(a){let b=this.content[a];if(!b)throw RangeError("Index "+a+" out of range for "+this);return b}maybeChild(a){return this.content[a]||null}forEach(a){for(let b=0,c=0;b<this.content.length;b++){let d=this.content[b];a(d,c,b),c+=d.nodeSize}}findDiffStart(a,b=0){return function a(b,c,d){for(let e=0;;e++){if(e==b.childCount||e==c.childCount)return b.childCount==c.childCount?null:d;let f=b.child(e),g=c.child(e);if(f==g){d+=f.nodeSize;continue}if(!f.sameMarkup(g))return d;if(f.isText&&f.text!=g.text){for(let a=0;f.text[a]==g.text[a];a++)d++;return d}if(f.content.size||g.content.size){let b=a(f.content,g.content,d+1);if(null!=b)return b}d+=f.nodeSize}}(this,a,b)}findDiffEnd(a,b=this.size,c=a.size){return function a(b,c,d,e){for(let f=b.childCount,g=c.childCount;;){if(0==f||0==g)return f==g?null:{a:d,b:e};let h=b.child(--f),i=c.child(--g),j=h.nodeSize;if(h==i){d-=j,e-=j;continue}if(!h.sameMarkup(i))return{a:d,b:e};if(h.isText&&h.text!=i.text){let a=0,b=Math.min(h.text.length,i.text.length);for(;a<b&&h.text[h.text.length-a-1]==i.text[i.text.length-a-1];)a++,d--,e--;return{a:d,b:e}}if(h.content.size||i.content.size){let b=a(h.content,i.content,d-1,e-1);if(b)return b}d-=j,e-=j}}(this,a,b,c)}findIndex(a){if(0==a)return g(0,a);if(a==this.size)return g(this.content.length,a);if(a>this.size||a<0)throw RangeError(`Position ${a} outside of fragment (${this})`);for(let b=0,c=0;;b++){let d=c+this.child(b).nodeSize;if(d>=a){if(d==a)return g(b+1,d);return g(b,c)}c=d}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(a=>a.toJSON()):null}static fromJSON(a,b){if(!b)return e.empty;if(!Array.isArray(b))throw RangeError("Invalid input for Fragment.fromJSON");return new e(b.map(a.nodeFromJSON))}static fromArray(a){if(!a.length)return e.empty;let b,c=0;for(let d=0;d<a.length;d++){let e=a[d];c+=e.nodeSize,d&&e.isText&&a[d-1].sameMarkup(e)?(b||(b=a.slice(0,d)),b[b.length-1]=e.withText(b[b.length-1].text+e.text)):b&&b.push(e)}return new e(b||a,c)}static from(a){if(!a)return e.empty;if(a instanceof e)return a;if(Array.isArray(a))return this.fromArray(a);if(a.attrs)return new e([a],a.nodeSize);throw RangeError("Can not convert "+a+" to a Fragment"+(a.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}e.empty=new e([],0);let f={index:0,offset:0};function g(a,b){return f.index=a,f.offset=b,f}function h(a,b){if(a===b)return!0;if(!(a&&"object"==typeof a)||!(b&&"object"==typeof b))return!1;let c=Array.isArray(a);if(Array.isArray(b)!=c)return!1;if(c){if(a.length!=b.length)return!1;for(let c=0;c<a.length;c++)if(!h(a[c],b[c]))return!1}else{for(let c in a)if(!(c in b)||!h(a[c],b[c]))return!1;for(let c in b)if(!(c in a))return!1}return!0}class i{constructor(a,b){this.type=a,this.attrs=b}addToSet(a){let b,c=!1;for(let d=0;d<a.length;d++){let e=a[d];if(this.eq(e))return a;if(this.type.excludes(e.type))b||(b=a.slice(0,d));else{if(e.type.excludes(this.type))return a;!c&&e.type.rank>this.type.rank&&(b||(b=a.slice(0,d)),b.push(this),c=!0),b&&b.push(e)}}return b||(b=a.slice()),c||b.push(this),b}removeFromSet(a){for(let b=0;b<a.length;b++)if(this.eq(a[b]))return a.slice(0,b).concat(a.slice(b+1));return a}isInSet(a){for(let b=0;b<a.length;b++)if(this.eq(a[b]))return!0;return!1}eq(a){return this==a||this.type==a.type&&h(this.attrs,a.attrs)}toJSON(){let a={type:this.type.name};for(let b in this.attrs){a.attrs=this.attrs;break}return a}static fromJSON(a,b){if(!b)throw RangeError("Invalid input for Mark.fromJSON");let c=a.marks[b.type];if(!c)throw RangeError(`There is no mark type ${b.type} in this schema`);let d=c.create(b.attrs);return c.checkAttrs(d.attrs),d}static sameSet(a,b){if(a==b)return!0;if(a.length!=b.length)return!1;for(let c=0;c<a.length;c++)if(!a[c].eq(b[c]))return!1;return!0}static setFrom(a){if(!a||Array.isArray(a)&&0==a.length)return i.none;if(a instanceof i)return[a];let b=a.slice();return b.sort((a,b)=>a.type.rank-b.type.rank),b}}i.none=[];class j extends Error{}class k{constructor(a,b,c){this.content=a,this.openStart=b,this.openEnd=c}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(a,b){let c=function a(b,c,d,e){let{index:f,offset:g}=b.findIndex(c),h=b.maybeChild(f);if(g==c||h.isText)return e&&!e.canReplace(f,f,d)?null:b.cut(0,c).append(d).append(b.cut(c));let i=a(h.content,c-g-1,d,h);return i&&b.replaceChild(f,h.copy(i))}(this.content,a+this.openStart,b);return c&&new k(c,this.openStart,this.openEnd)}removeBetween(a,b){return new k(function a(b,c,d){let{index:e,offset:f}=b.findIndex(c),g=b.maybeChild(e),{index:h,offset:i}=b.findIndex(d);if(f==c||g.isText){if(i!=d&&!b.child(h).isText)throw RangeError("Removing non-flat range");return b.cut(0,c).append(b.cut(d))}if(e!=h)throw RangeError("Removing non-flat range");return b.replaceChild(e,g.copy(a(g.content,c-f-1,d-f-1)))}(this.content,a+this.openStart,b+this.openStart),this.openStart,this.openEnd)}eq(a){return this.content.eq(a.content)&&this.openStart==a.openStart&&this.openEnd==a.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let a={content:this.content.toJSON()};return this.openStart>0&&(a.openStart=this.openStart),this.openEnd>0&&(a.openEnd=this.openEnd),a}static fromJSON(a,b){if(!b)return k.empty;let c=b.openStart||0,d=b.openEnd||0;if("number"!=typeof c||"number"!=typeof d)throw RangeError("Invalid input for Slice.fromJSON");return new k(e.fromJSON(a,b.content),c,d)}static maxOpen(a,b=!0){let c=0,d=0;for(let d=a.firstChild;d&&!d.isLeaf&&(b||!d.type.spec.isolating);d=d.firstChild)c++;for(let c=a.lastChild;c&&!c.isLeaf&&(b||!c.type.spec.isolating);c=c.lastChild)d++;return new k(a,c,d)}}function l(a,b){if(!b.type.compatibleContent(a.type))throw new j("Cannot join "+b.type.name+" onto "+a.type.name)}function m(a,b,c){let d=a.node(c);return l(d,b.node(c)),d}function n(a,b){let c=b.length-1;c>=0&&a.isText&&a.sameMarkup(b[c])?b[c]=a.withText(b[c].text+a.text):b.push(a)}function o(a,b,c,d){let e=(b||a).node(c),f=0,g=b?b.index(c):e.childCount;a&&(f=a.index(c),a.depth>c?f++:a.textOffset&&(n(a.nodeAfter,d),f++));for(let a=f;a<g;a++)n(e.child(a),d);b&&b.depth==c&&b.textOffset&&n(b.nodeBefore,d)}function p(a,b){return a.type.checkContent(b),a.copy(b)}function q(a,b,c){let d=[];return o(null,a,c,d),a.depth>c&&n(p(m(a,b,c+1),q(a,b,c+1)),d),o(b,null,c,d),new e(d)}k.empty=new k(e.empty,0,0);class r{constructor(a,b,c){this.pos=a,this.path=b,this.parentOffset=c,this.depth=b.length/3-1}resolveDepth(a){return null==a?this.depth:a<0?this.depth+a:a}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(a){return this.path[3*this.resolveDepth(a)]}index(a){return this.path[3*this.resolveDepth(a)+1]}indexAfter(a){return a=this.resolveDepth(a),this.index(a)+(a!=this.depth||this.textOffset?1:0)}start(a){return 0==(a=this.resolveDepth(a))?0:this.path[3*a-1]+1}end(a){return a=this.resolveDepth(a),this.start(a)+this.node(a).content.size}before(a){if(!(a=this.resolveDepth(a)))throw RangeError("There is no position before the top-level node");return a==this.depth+1?this.pos:this.path[3*a-1]}after(a){if(!(a=this.resolveDepth(a)))throw RangeError("There is no position after the top-level node");return a==this.depth+1?this.pos:this.path[3*a-1]+this.path[3*a].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let a=this.parent,b=this.index(this.depth);if(b==a.childCount)return null;let c=this.pos-this.path[this.path.length-1],d=a.child(b);return c?a.child(b).cut(c):d}get nodeBefore(){let a=this.index(this.depth),b=this.pos-this.path[this.path.length-1];return b?this.parent.child(a).cut(0,b):0==a?null:this.parent.child(a-1)}posAtIndex(a,b){b=this.resolveDepth(b);let c=this.path[3*b],d=0==b?0:this.path[3*b-1]+1;for(let b=0;b<a;b++)d+=c.child(b).nodeSize;return d}marks(){let a=this.parent,b=this.index();if(0==a.content.size)return i.none;if(this.textOffset)return a.child(b).marks;let c=a.maybeChild(b-1),d=a.maybeChild(b);if(!c){let a=c;c=d,d=a}let e=c.marks;for(var f=0;f<e.length;f++)!1!==e[f].type.spec.inclusive||d&&e[f].isInSet(d.marks)||(e=e[f--].removeFromSet(e));return e}marksAcross(a){let b=this.parent.maybeChild(this.index());if(!b||!b.isInline)return null;let c=b.marks,d=a.parent.maybeChild(a.index());for(var e=0;e<c.length;e++)!1!==c[e].type.spec.inclusive||d&&c[e].isInSet(d.marks)||(c=c[e--].removeFromSet(c));return c}sharedDepth(a){for(let b=this.depth;b>0;b--)if(this.start(b)<=a&&this.end(b)>=a)return b;return 0}blockRange(a=this,b){if(a.pos<this.pos)return a.blockRange(this);for(let c=this.depth-(this.parent.inlineContent||this.pos==a.pos?1:0);c>=0;c--)if(a.pos<=this.end(c)&&(!b||b(this.node(c))))return new v(this,a,c);return null}sameParent(a){return this.pos-this.parentOffset==a.pos-a.parentOffset}max(a){return a.pos>this.pos?a:this}min(a){return a.pos<this.pos?a:this}toString(){let a="";for(let b=1;b<=this.depth;b++)a+=(a?"/":"")+this.node(b).type.name+"_"+this.index(b-1);return a+":"+this.parentOffset}static resolve(a,b){if(!(b>=0&&b<=a.content.size))throw RangeError("Position "+b+" out of range");let c=[],d=0,e=b;for(let b=a;;){let{index:a,offset:f}=b.content.findIndex(e),g=e-f;if(c.push(b,a,d+f),!g||(b=b.child(a)).isText)break;e=g-1,d+=f+1}return new r(b,c,e)}static resolveCached(a,b){let c=u.get(a);if(c)for(let a=0;a<c.elts.length;a++){let d=c.elts[a];if(d.pos==b)return d}else u.set(a,c=new s);let d=c.elts[c.i]=r.resolve(a,b);return c.i=(c.i+1)%t,d}}class s{constructor(){this.elts=[],this.i=0}}let t=12,u=new WeakMap;class v{constructor(a,b,c){this.$from=a,this.$to=b,this.depth=c}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}let w=Object.create(null);class x{constructor(a,b,c,d=i.none){this.type=a,this.attrs=b,this.marks=d,this.content=c||e.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(a){return this.content.child(a)}maybeChild(a){return this.content.maybeChild(a)}forEach(a){this.content.forEach(a)}nodesBetween(a,b,c,d=0){this.content.nodesBetween(a,b,c,d,this)}descendants(a){this.nodesBetween(0,this.content.size,a)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(a,b,c,d){return this.content.textBetween(a,b,c,d)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(a){return this==a||this.sameMarkup(a)&&this.content.eq(a.content)}sameMarkup(a){return this.hasMarkup(a.type,a.attrs,a.marks)}hasMarkup(a,b,c){return this.type==a&&h(this.attrs,b||a.defaultAttrs||w)&&i.sameSet(this.marks,c||i.none)}copy(a=null){return a==this.content?this:new x(this.type,this.attrs,a,this.marks)}mark(a){return a==this.marks?this:new x(this.type,this.attrs,this.content,a)}cut(a,b=this.content.size){return 0==a&&b==this.content.size?this:this.copy(this.content.cut(a,b))}slice(a,b=this.content.size,c=!1){if(a==b)return k.empty;let d=this.resolve(a),e=this.resolve(b),f=c?0:d.sharedDepth(b),g=d.start(f);return new k(d.node(f).content.cut(d.pos-g,e.pos-g),d.depth-f,e.depth-f)}replace(a,b,c){var d=this.resolve(a),f=this.resolve(b);if(c.openStart>d.depth)throw new j("Inserted content deeper than insertion position");if(d.depth-c.openStart!=f.depth-c.openEnd)throw new j("Inconsistent open depths");return function a(b,c,d,f){let g=b.index(f),h=b.node(f);if(g==c.index(f)&&f<b.depth-d.openStart){let e=a(b,c,d,f+1);return h.copy(h.content.replaceChild(g,e))}if(!d.content.size)return p(h,q(b,c,f));if(d.openStart||d.openEnd||b.depth!=f||c.depth!=f){let{start:a,end:g}=function(a,b){let c=b.depth-a.openStart,d=b.node(c).copy(a.content);for(let a=c-1;a>=0;a--)d=b.node(a).copy(e.from(d));return{start:d.resolveNoCache(a.openStart+c),end:d.resolveNoCache(d.content.size-a.openEnd-c)}}(d,b);return p(h,function a(b,c,d,f,g){let h=b.depth>g&&m(b,c,g+1),i=f.depth>g&&m(d,f,g+1),j=[];return o(null,b,g,j),h&&i&&c.index(g)==d.index(g)?(l(h,i),n(p(h,a(b,c,d,f,g+1)),j)):(h&&n(p(h,q(b,c,g+1)),j),o(c,d,g,j),i&&n(p(i,q(d,f,g+1)),j)),o(f,null,g,j),new e(j)}(b,a,g,c,f))}{let a=b.parent,e=a.content;return p(a,e.cut(0,b.parentOffset).append(d.content).append(e.cut(c.parentOffset)))}}(d,f,c,0)}nodeAt(a){for(let b=this;;){let{index:c,offset:d}=b.content.findIndex(a);if(!(b=b.maybeChild(c)))return null;if(d==a||b.isText)return b;a-=d+1}}childAfter(a){let{index:b,offset:c}=this.content.findIndex(a);return{node:this.content.maybeChild(b),index:b,offset:c}}childBefore(a){if(0==a)return{node:null,index:0,offset:0};let{index:b,offset:c}=this.content.findIndex(a);if(c<a)return{node:this.content.child(b),index:b,offset:c};let d=this.content.child(b-1);return{node:d,index:b-1,offset:c-d.nodeSize}}resolve(a){return r.resolveCached(this,a)}resolveNoCache(a){return r.resolve(this,a)}rangeHasMark(a,b,c){let d=!1;return b>a&&this.nodesBetween(a,b,a=>(c.isInSet(a.marks)&&(d=!0),!d)),d}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let a=this.type.name;return this.content.size&&(a+="("+this.content.toStringInner()+")"),z(this.marks,a)}contentMatchAt(a){let b=this.type.contentMatch.matchFragment(this.content,0,a);if(!b)throw Error("Called contentMatchAt on a node with invalid content");return b}canReplace(a,b,c=e.empty,d=0,f=c.childCount){let g=this.contentMatchAt(a).matchFragment(c,d,f),h=g&&g.matchFragment(this.content,b);if(!h||!h.validEnd)return!1;for(let a=d;a<f;a++)if(!this.type.allowsMarks(c.child(a).marks))return!1;return!0}canReplaceWith(a,b,c,d){if(d&&!this.type.allowsMarks(d))return!1;let e=this.contentMatchAt(a).matchType(c),f=e&&e.matchFragment(this.content,b);return!!f&&f.validEnd}canAppend(a){return a.content.size?this.canReplace(this.childCount,this.childCount,a.content):this.type.compatibleContent(a.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let a=i.none;for(let b=0;b<this.marks.length;b++){let c=this.marks[b];c.type.checkAttrs(c.attrs),a=c.addToSet(a)}if(!i.sameSet(a,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(a=>a.type.name)}`);this.content.forEach(a=>a.check())}toJSON(){let a={type:this.type.name};for(let b in this.attrs){a.attrs=this.attrs;break}return this.content.size&&(a.content=this.content.toJSON()),this.marks.length&&(a.marks=this.marks.map(a=>a.toJSON())),a}static fromJSON(a,b){let c;if(!b)throw RangeError("Invalid input for Node.fromJSON");if(b.marks){if(!Array.isArray(b.marks))throw RangeError("Invalid mark data for Node.fromJSON");c=b.marks.map(a.markFromJSON)}if("text"==b.type){if("string"!=typeof b.text)throw RangeError("Invalid text node in JSON");return a.text(b.text,c)}let d=e.fromJSON(a,b.content),f=a.nodeType(b.type).create(b.attrs,d,c);return f.type.checkAttrs(f.attrs),f}}x.prototype.text=void 0;class y extends x{constructor(a,b,c,d){if(super(a,b,null,d),!c)throw RangeError("Empty text nodes are not allowed");this.text=c}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):z(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(a,b){return this.text.slice(a,b)}get nodeSize(){return this.text.length}mark(a){return a==this.marks?this:new y(this.type,this.attrs,this.text,a)}withText(a){return a==this.text?this:new y(this.type,this.attrs,a,this.marks)}cut(a=0,b=this.text.length){return 0==a&&b==this.text.length?this:this.withText(this.text.slice(a,b))}eq(a){return this.sameMarkup(a)&&this.text==a.text}toJSON(){let a=super.toJSON();return a.text=this.text,a}}function z(a,b){for(let c=a.length-1;c>=0;c--)b=a[c].type.name+"("+b+")";return b}class A{constructor(a){this.validEnd=a,this.next=[],this.wrapCache=[]}static parse(a,b){var c;let d,e=new B(a,b);if(null==e.next)return A.empty;let f=function a(b){let c=[];do c.push(function(b){let c=[];do c.push(function(b){let c=function(b){if(b.eat("(")){let c=a(b);return b.eat(")")||b.err("Missing closing paren"),c}if(/\W/.test(b.next))b.err("Unexpected token '"+b.next+"'");else{let a=(function(a,b){let c=a.nodeTypes,d=c[b];if(d)return[d];let e=[];for(let a in c){let d=c[a];d.isInGroup(b)&&e.push(d)}return 0==e.length&&a.err("No node type or group '"+b+"' found"),e})(b,b.next).map(a=>(null==b.inline?b.inline=a.isInline:b.inline!=a.isInline&&b.err("Mixing inline and block content"),{type:"name",value:a}));return b.pos++,1==a.length?a[0]:{type:"choice",exprs:a}}}(b);for(;;)if(b.eat("+"))c={type:"plus",expr:c};else if(b.eat("*"))c={type:"star",expr:c};else if(b.eat("?"))c={type:"opt",expr:c};else if(b.eat("{"))c=function(a,b){let c=C(a),d=c;return a.eat(",")&&(d="}"!=a.next?C(a):-1),a.eat("}")||a.err("Unclosed braced range"),{type:"range",min:c,max:d,expr:b}}(b,c);else break;return c}(b));while(b.next&&")"!=b.next&&"|"!=b.next);return 1==c.length?c[0]:{type:"seq",exprs:c}}(b));while(b.eat("|"));return 1==c.length?c[0]:{type:"choice",exprs:c}}(e);e.next&&e.err("Unexpected trailing text");let g=(c=function(a){let b=[[]];return e(function a(b,f){if("choice"==b.type)return b.exprs.reduce((b,c)=>b.concat(a(c,f)),[]);if("seq"==b.type)for(let d=0;;d++){let g=a(b.exprs[d],f);if(d==b.exprs.length-1)return g;e(g,f=c())}else if("star"==b.type){let g=c();return d(f,g),e(a(b.expr,g),g),[d(g)]}else if("plus"==b.type){let g=c();return e(a(b.expr,f),g),e(a(b.expr,g),g),[d(g)]}else if("opt"==b.type)return[d(f)].concat(a(b.expr,f));else if("range"==b.type){let g=f;for(let d=0;d<b.min;d++){let d=c();e(a(b.expr,g),d),g=d}if(-1==b.max)e(a(b.expr,g),g);else for(let f=b.min;f<b.max;f++){let f=c();d(g,f),e(a(b.expr,g),f),g=f}return[d(g)]}else if("name"==b.type)return[d(f,void 0,b.value)];else throw Error("Unknown expr type")}(a,0),c()),b;function c(){return b.push([])-1}function d(a,c,d){let e={term:d,to:c};return b[a].push(e),e}function e(a,b){a.forEach(a=>a.to=b)}}(f),d=Object.create(null),function a(b){let e=[];b.forEach(a=>{c[a].forEach(({term:a,to:b})=>{let d;if(a){for(let b=0;b<e.length;b++)e[b][0]==a&&(d=e[b][1]);E(c,b).forEach(b=>{d||e.push([a,d=[]]),-1==d.indexOf(b)&&d.push(b)})}})});let f=d[b.join(",")]=new A(b.indexOf(c.length-1)>-1);for(let b=0;b<e.length;b++){let c=e[b][1].sort(D);f.next.push({type:e[b][0],next:d[c.join(",")]||a(c)})}return f}(E(c,0)));return function(a,b){for(let c=0,d=[a];c<d.length;c++){let a=d[c],e=!a.validEnd,f=[];for(let b=0;b<a.next.length;b++){let{type:c,next:g}=a.next[b];f.push(c.name),e&&!(c.isText||c.hasRequiredAttrs())&&(e=!1),-1==d.indexOf(g)&&d.push(g)}e&&b.err("Only non-generatable nodes ("+f.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(g,e),g}matchType(a){for(let b=0;b<this.next.length;b++)if(this.next[b].type==a)return this.next[b].next;return null}matchFragment(a,b=0,c=a.childCount){let d=this;for(let e=b;d&&e<c;e++)d=d.matchType(a.child(e).type);return d}get inlineContent(){return 0!=this.next.length&&this.next[0].type.isInline}get defaultType(){for(let a=0;a<this.next.length;a++){let{type:b}=this.next[a];if(!(b.isText||b.hasRequiredAttrs()))return b}return null}compatible(a){for(let b=0;b<this.next.length;b++)for(let c=0;c<a.next.length;c++)if(this.next[b].type==a.next[c].type)return!0;return!1}fillBefore(a,b=!1,c=0){let d=[this];return function f(g,h){let i=g.matchFragment(a,c);if(i&&(!b||i.validEnd))return e.from(h.map(a=>a.createAndFill()));for(let a=0;a<g.next.length;a++){let{type:b,next:c}=g.next[a];if(!(b.isText||b.hasRequiredAttrs())&&-1==d.indexOf(c)){d.push(c);let a=f(c,h.concat(b));if(a)return a}}return null}(this,[])}findWrapping(a){for(let b=0;b<this.wrapCache.length;b+=2)if(this.wrapCache[b]==a)return this.wrapCache[b+1];let b=this.computeWrapping(a);return this.wrapCache.push(a,b),b}computeWrapping(a){let b=Object.create(null),c=[{match:this,type:null,via:null}];for(;c.length;){let d=c.shift(),e=d.match;if(e.matchType(a)){let a=[];for(let b=d;b.type;b=b.via)a.push(b.type);return a.reverse()}for(let a=0;a<e.next.length;a++){let{type:f,next:g}=e.next[a];f.isLeaf||f.hasRequiredAttrs()||f.name in b||d.type&&!g.validEnd||(c.push({match:f.contentMatch,type:f,via:d}),b[f.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(a){if(a>=this.next.length)throw RangeError(`There's no ${a}th edge in this content match`);return this.next[a]}toString(){let a=[];return!function b(c){a.push(c);for(let d=0;d<c.next.length;d++)-1==a.indexOf(c.next[d].next)&&b(c.next[d].next)}(this),a.map((b,c)=>{let d=c+(b.validEnd?"*":" ")+" ";for(let c=0;c<b.next.length;c++)d+=(c?", ":"")+b.next[c].type.name+"->"+a.indexOf(b.next[c].next);return d}).join("\n")}}A.empty=new A(!0);class B{constructor(a,b){this.string=a,this.nodeTypes=b,this.inline=null,this.pos=0,this.tokens=a.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(a){return this.next==a&&(this.pos++||!0)}err(a){throw SyntaxError(a+" (in content expression '"+this.string+"')")}}function C(a){/\D/.test(a.next)&&a.err("Expected number, got '"+a.next+"'");let b=Number(a.next);return a.pos++,b}function D(a,b){return b-a}function E(a,b){let c=[];return function b(d){let e=a[d];if(1==e.length&&!e[0].term)return b(e[0].to);c.push(d);for(let a=0;a<e.length;a++){let{term:d,to:f}=e[a];d||-1!=c.indexOf(f)||b(f)}}(b),c.sort(D)}function F(a){let b=Object.create(null);for(let c in a){let d=a[c];if(!d.hasDefault)return null;b[c]=d.default}return b}function G(a,b){let c=Object.create(null);for(let d in a){let e=b&&b[d];if(void 0===e){let b=a[d];if(b.hasDefault)e=b.default;else throw RangeError("No value supplied for attribute "+d)}c[d]=e}return c}function H(a,b,c,d){for(let d in b)if(!(d in a))throw RangeError(`Unsupported attribute ${d} for ${c} of type ${d}`);for(let c in a){let d=a[c];d.validate&&d.validate(b[c])}}function I(a,b){let c=Object.create(null);if(b)for(let d in b)c[d]=new K(a,d,b[d]);return c}class J{constructor(a,b,c){this.name=a,this.schema=b,this.spec=c,this.markSet=null,this.groups=c.group?c.group.split(" "):[],this.attrs=I(a,c.attrs),this.defaultAttrs=F(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(c.inline||"text"==a),this.isText="text"==a}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==A.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(a){return this.groups.indexOf(a)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let a in this.attrs)if(this.attrs[a].isRequired)return!0;return!1}compatibleContent(a){return this==a||this.contentMatch.compatible(a.contentMatch)}computeAttrs(a){return!a&&this.defaultAttrs?this.defaultAttrs:G(this.attrs,a)}create(a=null,b,c){if(this.isText)throw Error("NodeType.create can't construct text nodes");return new x(this,this.computeAttrs(a),e.from(b),i.setFrom(c))}createChecked(a=null,b,c){return b=e.from(b),this.checkContent(b),new x(this,this.computeAttrs(a),b,i.setFrom(c))}createAndFill(a=null,b,c){if(a=this.computeAttrs(a),(b=e.from(b)).size){let a=this.contentMatch.fillBefore(b);if(!a)return null;b=a.append(b)}let d=this.contentMatch.matchFragment(b),f=d&&d.fillBefore(e.empty,!0);return f?new x(this,a,b.append(f),i.setFrom(c)):null}validContent(a){let b=this.contentMatch.matchFragment(a);if(!b||!b.validEnd)return!1;for(let b=0;b<a.childCount;b++)if(!this.allowsMarks(a.child(b).marks))return!1;return!0}checkContent(a){if(!this.validContent(a))throw RangeError(`Invalid content for node ${this.name}: ${a.toString().slice(0,50)}`)}checkAttrs(a){H(this.attrs,a,"node",this.name)}allowsMarkType(a){return null==this.markSet||this.markSet.indexOf(a)>-1}allowsMarks(a){if(null==this.markSet)return!0;for(let b=0;b<a.length;b++)if(!this.allowsMarkType(a[b].type))return!1;return!0}allowedMarks(a){let b;if(null==this.markSet)return a;for(let c=0;c<a.length;c++)this.allowsMarkType(a[c].type)?b&&b.push(a[c]):b||(b=a.slice(0,c));return b?b.length?b:i.none:a}static compile(a,b){let c=Object.create(null);a.forEach((a,d)=>c[a]=new J(a,b,d));let d=b.spec.topNode||"doc";if(!c[d])throw RangeError("Schema is missing its top node type ('"+d+"')");if(!c.text)throw RangeError("Every schema needs a 'text' type");for(let a in c.text.attrs)throw RangeError("The text node type should not have attributes");return c}}class K{constructor(a,b,c){this.hasDefault=Object.prototype.hasOwnProperty.call(c,"default"),this.default=c.default,this.validate="string"==typeof c.validate?function(a,b,c){let d=c.split("|");return c=>{let e=null===c?"null":typeof c;if(0>d.indexOf(e))throw RangeError(`Expected value of type ${d} for attribute ${b} on type ${a}, got ${e}`)}}(a,b,c.validate):c.validate}get isRequired(){return!this.hasDefault}}class L{constructor(a,b,c,d){this.name=a,this.rank=b,this.schema=c,this.spec=d,this.attrs=I(a,d.attrs),this.excluded=null;let e=F(this.attrs);this.instance=e?new i(this,e):null}create(a=null){return!a&&this.instance?this.instance:new i(this,G(this.attrs,a))}static compile(a,b){let c=Object.create(null),d=0;return a.forEach((a,e)=>c[a]=new L(a,d++,b,e)),c}removeFromSet(a){for(var b=0;b<a.length;b++)a[b].type==this&&(a=a.slice(0,b).concat(a.slice(b+1)),b--);return a}isInSet(a){for(let b=0;b<a.length;b++)if(a[b].type==this)return a[b]}checkAttrs(a){H(this.attrs,a,"mark",this.name)}excludes(a){return this.excluded.indexOf(a)>-1}}class M{constructor(a){this.linebreakReplacement=null,this.cached=Object.create(null);let b=this.spec={};for(let c in a)b[c]=a[c];b.nodes=d.from(a.nodes),b.marks=d.from(a.marks||{}),this.nodes=J.compile(this.spec.nodes,this),this.marks=L.compile(this.spec.marks,this);let c=Object.create(null);for(let a in this.nodes){if(a in this.marks)throw RangeError(a+" can not be both a node and a mark");let b=this.nodes[a],d=b.spec.content||"",e=b.spec.marks;if(b.contentMatch=c[d]||(c[d]=A.parse(d,this.nodes)),b.inlineContent=b.contentMatch.inlineContent,b.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError("Multiple linebreak nodes defined");if(!b.isInline||!b.isLeaf)throw RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=b}b.markSet="_"==e?null:e?N(this,e.split(" ")):""!=e&&b.inlineContent?null:[]}for(let a in this.marks){let b=this.marks[a],c=b.spec.excludes;b.excluded=null==c?[b]:""==c?[]:N(this,c.split(" "))}this.nodeFromJSON=a=>x.fromJSON(this,a),this.markFromJSON=a=>i.fromJSON(this,a),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(a,b=null,c,d){if("string"==typeof a)a=this.nodeType(a);else if(a instanceof J){if(a.schema!=this)throw RangeError("Node type from different schema used ("+a.name+")")}else throw RangeError("Invalid node type: "+a);return a.createChecked(b,c,d)}text(a,b){let c=this.nodes.text;return new y(c,c.defaultAttrs,a,i.setFrom(b))}mark(a,b){return"string"==typeof a&&(a=this.marks[a]),a.create(b)}nodeType(a){let b=this.nodes[a];if(!b)throw RangeError("Unknown node type: "+a);return b}}function N(a,b){let c=[];for(let d=0;d<b.length;d++){let e=b[d],f=a.marks[e],g=f;if(f)c.push(f);else for(let b in a.marks){let d=a.marks[b];("_"==e||d.spec.group&&d.spec.group.split(" ").indexOf(e)>-1)&&c.push(g=d)}if(!g)throw SyntaxError("Unknown mark type: '"+b[d]+"'")}return c}class O{constructor(a,b){this.schema=a,this.rules=b,this.tags=[],this.styles=[];let c=this.matchedStyles=[];b.forEach(a=>{if(null!=a.tag)this.tags.push(a);else if(null!=a.style){let b=/[^=]*/.exec(a.style)[0];0>c.indexOf(b)&&c.push(b),this.styles.push(a)}}),this.normalizeLists=!this.tags.some(b=>{if(!/^(ul|ol)\b/.test(b.tag)||!b.node)return!1;let c=a.nodes[b.node];return c.contentMatch.matchType(c)})}parse(a,b={}){let c=new U(this,b,!1);return c.addAll(a,i.none,b.from,b.to),c.finish()}parseSlice(a,b={}){let c=new U(this,b,!0);return c.addAll(a,i.none,b.from,b.to),k.maxOpen(c.finish())}matchTag(a,b,c){for(let f=c?this.tags.indexOf(c)+1:0;f<this.tags.length;f++){var d,e;let c=this.tags[f];if(d=a,e=c.tag,(d.matches||d.msMatchesSelector||d.webkitMatchesSelector||d.mozMatchesSelector).call(d,e)&&(void 0===c.namespace||a.namespaceURI==c.namespace)&&(!c.context||b.matchesContext(c.context))){if(c.getAttrs){let b=c.getAttrs(a);if(!1===b)continue;c.attrs=b||void 0}return c}}}matchStyle(a,b,c,d){for(let e=d?this.styles.indexOf(d)+1:0;e<this.styles.length;e++){let d=this.styles[e],f=d.style;if(0==f.indexOf(a)&&(!d.context||c.matchesContext(d.context))&&(!(f.length>a.length)||61==f.charCodeAt(a.length)&&f.slice(a.length+1)==b)){if(d.getAttrs){let a=d.getAttrs(b);if(!1===a)continue;d.attrs=a||void 0}return d}}}static schemaRules(a){let b=[];function c(a){let c=null==a.priority?50:a.priority,d=0;for(;d<b.length;d++){let a=b[d];if((null==a.priority?50:a.priority)<c)break}b.splice(d,0,a)}for(let b in a.marks){let d=a.marks[b].spec.parseDOM;d&&d.forEach(a=>{c(a=V(a)),a.mark||a.ignore||a.clearMark||(a.mark=b)})}for(let b in a.nodes){let d=a.nodes[b].spec.parseDOM;d&&d.forEach(a=>{c(a=V(a)),a.node||a.ignore||a.mark||(a.node=b)})}return b}static fromSchema(a){return a.cached.domParser||(a.cached.domParser=new O(a,O.schemaRules(a)))}}let P={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Q={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},R={ol:!0,ul:!0};function S(a,b,c){return null!=b?!!b|2*("full"===b):a&&"pre"==a.whitespace?3:-5&c}class T{constructor(a,b,c,d,e,f){this.type=a,this.attrs=b,this.marks=c,this.solid=d,this.options=f,this.content=[],this.activeMarks=i.none,this.match=e||(4&f?null:a.contentMatch)}findWrapping(a){if(!this.match){if(!this.type)return[];let b=this.type.contentMatch.fillBefore(e.from(a));if(b)this.match=this.type.contentMatch.matchFragment(b);else{let b=this.type.contentMatch,c;return(c=b.findWrapping(a.type))?(this.match=b,c):null}}return this.match.findWrapping(a.type)}finish(a){if(!(1&this.options)){let a=this.content[this.content.length-1],b;a&&a.isText&&(b=/[ \t\r\n\u000c]+$/.exec(a.text))&&(a.text.length==b[0].length?this.content.pop():this.content[this.content.length-1]=a.withText(a.text.slice(0,a.text.length-b[0].length)))}let b=e.from(this.content);return!a&&this.match&&(b=b.append(this.match.fillBefore(e.empty,!0))),this.type?this.type.create(this.attrs,b,this.marks):b}inlineContext(a){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:a.parentNode&&!P.hasOwnProperty(a.parentNode.nodeName.toLowerCase())}}class U{constructor(a,b,c){this.parser=a,this.options=b,this.isOpen=c,this.open=0,this.localPreserveWS=!1;let d=b.topNode,e,f=S(null,b.preserveWhitespace,0)|4*!!c;e=d?new T(d.type,d.attrs,i.none,!0,b.topMatch||d.type.contentMatch,f):c?new T(null,null,i.none,!0,null,f):new T(a.schema.topNodeType,null,i.none,!0,null,f),this.nodes=[e],this.find=b.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(a,b){3==a.nodeType?this.addTextNode(a,b):1==a.nodeType&&this.addElement(a,b)}addTextNode(a,b){let c=a.nodeValue,d=this.top,e=2&d.options?"full":this.localPreserveWS||(1&d.options)>0,{schema:f}=this.parser;if("full"===e||d.inlineContext(a)||/[^ \t\r\n\u000c]/.test(c)){if(e)if("full"===e)c=c.replace(/\r\n?/g,"\n");else if(f.linebreakReplacement&&/[\r\n]/.test(c)&&this.top.findWrapping(f.linebreakReplacement.create())){let a=c.split(/\r?\n|\r/);for(let c=0;c<a.length;c++)c&&this.insertNode(f.linebreakReplacement.create(),b,!0),a[c]&&this.insertNode(f.text(a[c]),b,!/\S/.test(a[c]));c=""}else c=c.replace(/\r?\n|\r/g," ");else if(c=c.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(c)&&this.open==this.nodes.length-1){let b=d.content[d.content.length-1],e=a.previousSibling;(!b||e&&"BR"==e.nodeName||b.isText&&/[ \t\r\n\u000c]$/.test(b.text))&&(c=c.slice(1))}c&&this.insertNode(f.text(c),b,!/\S/.test(c)),this.findInText(a)}else this.findInside(a)}addElement(a,b,c){let d=this.localPreserveWS,e=this.top;("PRE"==a.tagName||/pre/.test(a.style&&a.style.whiteSpace))&&(this.localPreserveWS=!0);let f=a.nodeName.toLowerCase(),g;R.hasOwnProperty(f)&&this.parser.normalizeLists&&function(a){for(let b=a.firstChild,c=null;b;b=b.nextSibling){let a=1==b.nodeType?b.nodeName.toLowerCase():null;a&&R.hasOwnProperty(a)&&c?(c.appendChild(b),b=c):"li"==a?c=b:a&&(c=null)}}(a);let h=this.options.ruleFromNode&&this.options.ruleFromNode(a)||(g=this.parser.matchTag(a,this,c));c:if(h?h.ignore:Q.hasOwnProperty(f))this.findInside(a),this.ignoreFallback(a,b);else if(!h||h.skip||h.closeParent){h&&h.closeParent?this.open=Math.max(0,this.open-1):h&&h.skip.nodeType&&(a=h.skip);let c,d=this.needsBlock;if(P.hasOwnProperty(f))e.content.length&&e.content[0].isInline&&this.open&&(this.open--,e=this.top),c=!0,e.type||(this.needsBlock=!0);else if(!a.firstChild){this.leafFallback(a,b);break c}let g=h&&h.skip?b:this.readStyles(a,b);g&&this.addAll(a,g),c&&this.sync(e),this.needsBlock=d}else{let c=this.readStyles(a,b);c&&this.addElementByRule(a,h,c,!1===h.consuming?g:void 0)}this.localPreserveWS=d}leafFallback(a,b){"BR"==a.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(a.ownerDocument.createTextNode("\n"),b)}ignoreFallback(a,b){"BR"!=a.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),b,!0)}readStyles(a,b){let c=a.style;if(c&&c.length)for(let a=0;a<this.parser.matchedStyles.length;a++){let d=this.parser.matchedStyles[a],e=c.getPropertyValue(d);if(e)for(let a;;){let c=this.parser.matchStyle(d,e,this,a);if(!c)break;if(c.ignore)return null;if(b=c.clearMark?b.filter(a=>!c.clearMark(a)):b.concat(this.parser.schema.marks[c.mark].create(c.attrs)),!1===c.consuming)a=c;else break}}return b}addElementByRule(a,b,c,d){let e,f;if(b.node)if((f=this.parser.schema.nodes[b.node]).isLeaf)this.insertNode(f.create(b.attrs),c,"BR"==a.nodeName)||this.leafFallback(a,c);else{let a=this.enter(f,b.attrs||null,c,b.preserveWhitespace);a&&(e=!0,c=a)}else{let a=this.parser.schema.marks[b.mark];c=c.concat(a.create(b.attrs))}let g=this.top;if(f&&f.isLeaf)this.findInside(a);else if(d)this.addElement(a,c,d);else if(b.getContent)this.findInside(a),b.getContent(a,this.parser.schema).forEach(a=>this.insertNode(a,c,!1));else{let d=a;"string"==typeof b.contentElement?d=a.querySelector(b.contentElement):"function"==typeof b.contentElement?d=b.contentElement(a):b.contentElement&&(d=b.contentElement),this.findAround(a,d,!0),this.addAll(d,c),this.findAround(a,d,!1)}e&&this.sync(g)&&this.open--}addAll(a,b,c,d){let e=c||0;for(let f=c?a.childNodes[c]:a.firstChild,g=null==d?null:a.childNodes[d];f!=g;f=f.nextSibling,++e)this.findAtPoint(a,e),this.addDOM(f,b);this.findAtPoint(a,e)}findPlace(a,b,c){let d,e;for(let b=this.open,f=0;b>=0;b--){let g=this.nodes[b],h=g.findWrapping(a);if(h&&(!d||d.length>h.length+f)&&(d=h,e=g,!h.length))break;if(g.solid){if(c)break;f+=2}}if(!d)return null;this.sync(e);for(let a=0;a<d.length;a++)b=this.enterInner(d[a],null,b,!1);return b}insertNode(a,b,c){if(a.isInline&&this.needsBlock&&!this.top.type){let a=this.textblockFromContext();a&&(b=this.enterInner(a,null,b))}let d=this.findPlace(a,b,c);if(d){this.closeExtra();let b=this.top;b.match&&(b.match=b.match.matchType(a.type));let c=i.none;for(let e of d.concat(a.marks))(b.type?b.type.allowsMarkType(e.type):W(e.type,a.type))&&(c=e.addToSet(c));return b.content.push(a.mark(c)),!0}return!1}enter(a,b,c,d){let e=this.findPlace(a.create(b),c,!1);return e&&(e=this.enterInner(a,b,c,!0,d)),e}enterInner(a,b,c,d=!1,e){this.closeExtra();let f=this.top;f.match=f.match&&f.match.matchType(a);let g=S(a,e,f.options);4&f.options&&0==f.content.length&&(g|=4);let h=i.none;return c=c.filter(b=>(f.type?!f.type.allowsMarkType(b.type):!W(b.type,a))||(h=b.addToSet(h),!1)),this.nodes.push(new T(a,b,h,d,null,g)),this.open++,c}closeExtra(a=!1){let b=this.nodes.length-1;if(b>this.open){for(;b>this.open;b--)this.nodes[b-1].content.push(this.nodes[b].finish(a));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(a){for(let b=this.open;b>=0;b--)if(this.nodes[b]==a)return this.open=b,!0;else this.localPreserveWS&&(this.nodes[b].options|=1);return!1}get currentPos(){this.closeExtra();let a=0;for(let b=this.open;b>=0;b--){let c=this.nodes[b].content;for(let b=c.length-1;b>=0;b--)a+=c[b].nodeSize;b&&a++}return a}findAtPoint(a,b){if(this.find)for(let c=0;c<this.find.length;c++)this.find[c].node==a&&this.find[c].offset==b&&(this.find[c].pos=this.currentPos)}findInside(a){if(this.find)for(let b=0;b<this.find.length;b++)null==this.find[b].pos&&1==a.nodeType&&a.contains(this.find[b].node)&&(this.find[b].pos=this.currentPos)}findAround(a,b,c){if(a!=b&&this.find)for(let d=0;d<this.find.length;d++)null==this.find[d].pos&&1==a.nodeType&&a.contains(this.find[d].node)&&b.compareDocumentPosition(this.find[d].node)&(c?2:4)&&(this.find[d].pos=this.currentPos)}findInText(a){if(this.find)for(let b=0;b<this.find.length;b++)this.find[b].node==a&&(this.find[b].pos=this.currentPos-(a.nodeValue.length-this.find[b].offset))}matchesContext(a){if(a.indexOf("|")>-1)return a.split(/\s*\|\s*/).some(this.matchesContext,this);let b=a.split("/"),c=this.options.context,d=!this.isOpen&&(!c||c.parent.type==this.nodes[0].type),e=-(c?c.depth+1:0)+ +!d,f=(a,g)=>{for(;a>=0;a--){let h=b[a];if(""==h){if(a==b.length-1||0==a)continue;for(;g>=e;g--)if(f(a-1,g))return!0;return!1}{let a=g>0||0==g&&d?this.nodes[g].type:c&&g>=e?c.node(g-e).type:null;if(!a||a.name!=h&&!a.isInGroup(h))return!1;g--}}return!0};return f(b.length-1,this.open)}textblockFromContext(){let a=this.options.context;if(a)for(let b=a.depth;b>=0;b--){let c=a.node(b).contentMatchAt(a.indexAfter(b)).defaultType;if(c&&c.isTextblock&&c.defaultAttrs)return c}for(let a in this.parser.schema.nodes){let b=this.parser.schema.nodes[a];if(b.isTextblock&&b.defaultAttrs)return b}}}function V(a){let b={};for(let c in a)b[c]=a[c];return b}function W(a,b){let c=b.schema.nodes;for(let d in c){let e=c[d];if(!e.allowsMarkType(a))continue;let f=[],g=a=>{f.push(a);for(let c=0;c<a.edgeCount;c++){let{type:d,next:e}=a.edge(c);if(d==b||0>f.indexOf(e)&&g(e))return!0}};if(g(e.contentMatch))return!0}}class X{constructor(a,b){this.nodes=a,this.marks=b}serializeFragment(a,b={},c){c||(c=Z(b).createDocumentFragment());let d=c,e=[];return a.forEach(a=>{if(e.length||a.marks.length){let c=0,f=0;for(;c<e.length&&f<a.marks.length;){let b=a.marks[f];if(!this.marks[b.type.name]){f++;continue}if(!b.eq(e[c][0])||!1===b.type.spec.spanning)break;c++,f++}for(;c<e.length;)d=e.pop()[1];for(;f<a.marks.length;){let c=a.marks[f++],g=this.serializeMark(c,a.isInline,b);g&&(e.push([c,d]),d.appendChild(g.dom),d=g.contentDOM||g.dom)}}d.appendChild(this.serializeNodeInner(a,b))}),c}serializeNodeInner(a,b){let{dom:c,contentDOM:d}=aa(Z(b),this.nodes[a.type.name](a),null,a.attrs);if(d){if(a.isLeaf)throw RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(a.content,b,d)}return c}serializeNode(a,b={}){let c=this.serializeNodeInner(a,b);for(let d=a.marks.length-1;d>=0;d--){let e=this.serializeMark(a.marks[d],a.isInline,b);e&&((e.contentDOM||e.dom).appendChild(c),c=e.dom)}return c}serializeMark(a,b,c={}){let d=this.marks[a.type.name];return d&&aa(Z(c),d(a,b),null,a.attrs)}static renderSpec(a,b,c=null,d){return aa(a,b,c,d)}static fromSchema(a){return a.cached.domSerializer||(a.cached.domSerializer=new X(this.nodesFromSchema(a),this.marksFromSchema(a)))}static nodesFromSchema(a){let b=Y(a.nodes);return b.text||(b.text=a=>a.text),b}static marksFromSchema(a){return Y(a.marks)}}function Y(a){let b={};for(let c in a){let d=a[c].spec.toDOM;d&&(b[c]=d)}return b}function Z(a){return a.document||window.document}let _=new WeakMap;function aa(a,b,c,d){let e,f,g;if("string"==typeof b)return{dom:a.createTextNode(b)};if(null!=b.nodeType)return{dom:b};if(b.dom&&null!=b.dom.nodeType)return b;let h=b[0],i;if("string"!=typeof h)throw RangeError("Invalid array passed to renderSpec");if(d&&(void 0===(f=_.get(d))&&_.set(d,(g=null,!function a(b){if(b&&"object"==typeof b)if(Array.isArray(b))if("string"==typeof b[0])g||(g=[]),g.push(b);else for(let c=0;c<b.length;c++)a(b[c]);else for(let c in b)a(b[c])}(d),f=g)),i=f)&&i.indexOf(b)>-1)throw RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let j=h.indexOf(" ");j>0&&(c=h.slice(0,j),h=h.slice(j+1));let k=c?a.createElementNS(c,h):a.createElement(h),l=b[1],m=1;if(l&&"object"==typeof l&&null==l.nodeType&&!Array.isArray(l)){for(let a in m=2,l)if(null!=l[a]){let b=a.indexOf(" ");b>0?k.setAttributeNS(a.slice(0,b),a.slice(b+1),l[a]):"style"==a&&k.style?k.style.cssText=l[a]:k.setAttribute(a,l[a])}}for(let f=m;f<b.length;f++){let g=b[f];if(0===g){if(f<b.length-1||f>m)throw RangeError("Content hole must be the only child of its parent node");return{dom:k,contentDOM:k}}{let{dom:b,contentDOM:f}=aa(a,g,c,d);if(k.appendChild(b),f){if(e)throw RangeError("Multiple content holes");e=f}}}return{dom:k,contentDOM:e}}},31626:(a,b,c)=>{"use strict";c.d(b,{$L:()=>D,Ln:()=>p,N0:()=>B,Um:()=>C,Wg:()=>q,X9:()=>g,Ys:()=>m,dL:()=>O,jP:()=>t,n9:()=>z,oM:()=>u,zy:()=>y});var d=c(31480);class e{constructor(a,b,c){this.pos=a,this.delInfo=b,this.recover=c}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class f{constructor(a,b=!1){if(this.ranges=a,this.inverted=b,!a.length&&f.empty)return f.empty}recover(a){let b=0,c=65535&a;if(!this.inverted)for(let a=0;a<c;a++)b+=this.ranges[3*a+2]-this.ranges[3*a+1];return this.ranges[3*c]+b+(a-(65535&a))/65536}mapResult(a,b=1){return this._map(a,b,!1)}map(a,b=1){return this._map(a,b,!0)}_map(a,b,c){let d=0,f=this.inverted?2:1,g=this.inverted?1:2;for(let h=0;h<this.ranges.length;h+=3){let i=this.ranges[h]-(this.inverted?d:0);if(i>a)break;let j=this.ranges[h+f],k=this.ranges[h+g],l=i+j;if(a<=l){let f=j?a==i?-1:a==l?1:b:b,g=i+d+(f<0?0:k);if(c)return g;let m=a==(b<0?i:l)?null:h/3+(a-i)*65536,n=a==i?2:a==l?1:4;return(b<0?a!=i:a!=l)&&(n|=8),new e(g,n,m)}d+=k-j}return c?a+d:new e(a+d,0,null)}touches(a,b){let c=0,d=65535&b,e=this.inverted?2:1,f=this.inverted?1:2;for(let b=0;b<this.ranges.length;b+=3){let g=this.ranges[b]-(this.inverted?c:0);if(g>a)break;let h=this.ranges[b+e];if(a<=g+h&&b==3*d)return!0;c+=this.ranges[b+f]-h}return!1}forEach(a){let b=this.inverted?2:1,c=this.inverted?1:2;for(let d=0,e=0;d<this.ranges.length;d+=3){let f=this.ranges[d],g=f-(this.inverted?e:0),h=f+(this.inverted?0:e),i=this.ranges[d+b],j=this.ranges[d+c];a(g,g+i,h,h+j),e+=j-i}}invert(){return new f(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(a){return 0==a?f.empty:new f(a<0?[0,-a,0]:[0,0,a])}}f.empty=new f([]);class g{constructor(a,b,c=0,d=a?a.length:0){this.mirror=b,this.from=c,this.to=d,this._maps=a||[],this.ownData=!(a||b)}get maps(){return this._maps}slice(a=0,b=this.maps.length){return new g(this._maps,this.mirror,a,b)}appendMap(a,b){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(a),null!=b&&this.setMirror(this._maps.length-1,b)}appendMapping(a){for(let b=0,c=this._maps.length;b<a._maps.length;b++){let d=a.getMirror(b);this.appendMap(a._maps[b],null!=d&&d<b?c+d:void 0)}}getMirror(a){if(this.mirror){for(let b=0;b<this.mirror.length;b++)if(this.mirror[b]==a)return this.mirror[b+(b%2?-1:1)]}}setMirror(a,b){this.mirror||(this.mirror=[]),this.mirror.push(a,b)}appendMappingInverted(a){for(let b=a.maps.length-1,c=this._maps.length+a._maps.length;b>=0;b--){let d=a.getMirror(b);this.appendMap(a._maps[b].invert(),null!=d&&d>b?c-d-1:void 0)}}invert(){let a=new g;return a.appendMappingInverted(this),a}map(a,b=1){if(this.mirror)return this._map(a,b,!0);for(let c=this.from;c<this.to;c++)a=this._maps[c].map(a,b);return a}mapResult(a,b=1){return this._map(a,b,!1)}_map(a,b,c){let d=0;for(let c=this.from;c<this.to;c++){let e=this._maps[c].mapResult(a,b);if(null!=e.recover){let b=this.getMirror(c);if(null!=b&&b>c&&b<this.to){c=b,a=this._maps[b].recover(e.recover);continue}}d|=e.delInfo,a=e.pos}return c?a:new e(a,d,null)}}let h=Object.create(null);class i{getMap(){return f.empty}merge(a){return null}static fromJSON(a,b){if(!b||!b.stepType)throw RangeError("Invalid input for Step.fromJSON");let c=h[b.stepType];if(!c)throw RangeError(`No step type ${b.stepType} defined`);return c.fromJSON(a,b)}static jsonID(a,b){if(a in h)throw RangeError("Duplicate use of step JSON ID "+a);return h[a]=b,b.prototype.jsonID=a,b}}class j{constructor(a,b){this.doc=a,this.failed=b}static ok(a){return new j(a,null)}static fail(a){return new j(null,a)}static fromReplace(a,b,c,e){try{return j.ok(a.replace(b,c,e))}catch(a){if(a instanceof d.vI)return j.fail(a.message);throw a}}}function k(a,b,c){let e=[];for(let d=0;d<a.childCount;d++){let f=a.child(d);f.content.size&&(f=f.copy(k(f.content,b,f))),f.isInline&&(f=b(f,c,d)),e.push(f)}return d.FK.fromArray(e)}class l extends i{constructor(a,b,c){super(),this.from=a,this.to=b,this.mark=c}apply(a){let b=a.slice(this.from,this.to),c=a.resolve(this.from),e=c.node(c.sharedDepth(this.to)),f=new d.Ji(k(b.content,(a,b)=>a.isAtom&&b.type.allowsMarkType(this.mark.type)?a.mark(this.mark.addToSet(a.marks)):a,e),b.openStart,b.openEnd);return j.fromReplace(a,this.from,this.to,f)}invert(){return new m(this.from,this.to,this.mark)}map(a){let b=a.mapResult(this.from,1),c=a.mapResult(this.to,-1);return b.deleted&&c.deleted||b.pos>=c.pos?null:new l(b.pos,c.pos,this.mark)}merge(a){return a instanceof l&&a.mark.eq(this.mark)&&this.from<=a.to&&this.to>=a.from?new l(Math.min(this.from,a.from),Math.max(this.to,a.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(a,b){if("number"!=typeof b.from||"number"!=typeof b.to)throw RangeError("Invalid input for AddMarkStep.fromJSON");return new l(b.from,b.to,a.markFromJSON(b.mark))}}i.jsonID("addMark",l);class m extends i{constructor(a,b,c){super(),this.from=a,this.to=b,this.mark=c}apply(a){let b=a.slice(this.from,this.to),c=new d.Ji(k(b.content,a=>a.mark(this.mark.removeFromSet(a.marks)),a),b.openStart,b.openEnd);return j.fromReplace(a,this.from,this.to,c)}invert(){return new l(this.from,this.to,this.mark)}map(a){let b=a.mapResult(this.from,1),c=a.mapResult(this.to,-1);return b.deleted&&c.deleted||b.pos>=c.pos?null:new m(b.pos,c.pos,this.mark)}merge(a){return a instanceof m&&a.mark.eq(this.mark)&&this.from<=a.to&&this.to>=a.from?new m(Math.min(this.from,a.from),Math.max(this.to,a.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(a,b){if("number"!=typeof b.from||"number"!=typeof b.to)throw RangeError("Invalid input for RemoveMarkStep.fromJSON");return new m(b.from,b.to,a.markFromJSON(b.mark))}}i.jsonID("removeMark",m);class n extends i{constructor(a,b){super(),this.pos=a,this.mark=b}apply(a){let b=a.nodeAt(this.pos);if(!b)return j.fail("No node at mark step's position");let c=b.type.create(b.attrs,null,this.mark.addToSet(b.marks));return j.fromReplace(a,this.pos,this.pos+1,new d.Ji(d.FK.from(c),0,+!b.isLeaf))}invert(a){let b=a.nodeAt(this.pos);if(b){let a=this.mark.addToSet(b.marks);if(a.length==b.marks.length){for(let c=0;c<b.marks.length;c++)if(!b.marks[c].isInSet(a))return new n(this.pos,b.marks[c]);return new n(this.pos,this.mark)}}return new o(this.pos,this.mark)}map(a){let b=a.mapResult(this.pos,1);return b.deletedAfter?null:new n(b.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(a,b){if("number"!=typeof b.pos)throw RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new n(b.pos,a.markFromJSON(b.mark))}}i.jsonID("addNodeMark",n);class o extends i{constructor(a,b){super(),this.pos=a,this.mark=b}apply(a){let b=a.nodeAt(this.pos);if(!b)return j.fail("No node at mark step's position");let c=b.type.create(b.attrs,null,this.mark.removeFromSet(b.marks));return j.fromReplace(a,this.pos,this.pos+1,new d.Ji(d.FK.from(c),0,+!b.isLeaf))}invert(a){let b=a.nodeAt(this.pos);return b&&this.mark.isInSet(b.marks)?new n(this.pos,this.mark):this}map(a){let b=a.mapResult(this.pos,1);return b.deletedAfter?null:new o(b.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(a,b){if("number"!=typeof b.pos)throw RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new o(b.pos,a.markFromJSON(b.mark))}}i.jsonID("removeNodeMark",o);class p extends i{constructor(a,b,c,d=!1){super(),this.from=a,this.to=b,this.slice=c,this.structure=d}apply(a){return this.structure&&r(a,this.from,this.to)?j.fail("Structure replace would overwrite content"):j.fromReplace(a,this.from,this.to,this.slice)}getMap(){return new f([this.from,this.to-this.from,this.slice.size])}invert(a){return new p(this.from,this.from+this.slice.size,a.slice(this.from,this.to))}map(a){let b=a.mapResult(this.from,1),c=a.mapResult(this.to,-1);return b.deletedAcross&&c.deletedAcross?null:new p(b.pos,Math.max(b.pos,c.pos),this.slice,this.structure)}merge(a){if(!(a instanceof p)||a.structure||this.structure)return null;if(this.from+this.slice.size!=a.from||this.slice.openEnd||a.slice.openStart)if(a.to!=this.from||this.slice.openStart||a.slice.openEnd)return null;else{let b=this.slice.size+a.slice.size==0?d.Ji.empty:new d.Ji(a.slice.content.append(this.slice.content),a.slice.openStart,this.slice.openEnd);return new p(a.from,this.to,b,this.structure)}{let b=this.slice.size+a.slice.size==0?d.Ji.empty:new d.Ji(this.slice.content.append(a.slice.content),this.slice.openStart,a.slice.openEnd);return new p(this.from,this.to+(a.to-a.from),b,this.structure)}}toJSON(){let a={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(a.slice=this.slice.toJSON()),this.structure&&(a.structure=!0),a}static fromJSON(a,b){if("number"!=typeof b.from||"number"!=typeof b.to)throw RangeError("Invalid input for ReplaceStep.fromJSON");return new p(b.from,b.to,d.Ji.fromJSON(a,b.slice),!!b.structure)}}i.jsonID("replace",p);class q extends i{constructor(a,b,c,d,e,f,g=!1){super(),this.from=a,this.to=b,this.gapFrom=c,this.gapTo=d,this.slice=e,this.insert=f,this.structure=g}apply(a){if(this.structure&&(r(a,this.from,this.gapFrom)||r(a,this.gapTo,this.to)))return j.fail("Structure gap-replace would overwrite content");let b=a.slice(this.gapFrom,this.gapTo);if(b.openStart||b.openEnd)return j.fail("Gap is not a flat range");let c=this.slice.insertAt(this.insert,b.content);return c?j.fromReplace(a,this.from,this.to,c):j.fail("Content does not fit in gap")}getMap(){return new f([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(a){let b=this.gapTo-this.gapFrom;return new q(this.from,this.from+this.slice.size+b,this.from+this.insert,this.from+this.insert+b,a.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(a){let b=a.mapResult(this.from,1),c=a.mapResult(this.to,-1),d=this.from==this.gapFrom?b.pos:a.map(this.gapFrom,-1),e=this.to==this.gapTo?c.pos:a.map(this.gapTo,1);return b.deletedAcross&&c.deletedAcross||d<b.pos||e>c.pos?null:new q(b.pos,c.pos,d,e,this.slice,this.insert,this.structure)}toJSON(){let a={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(a.slice=this.slice.toJSON()),this.structure&&(a.structure=!0),a}static fromJSON(a,b){if("number"!=typeof b.from||"number"!=typeof b.to||"number"!=typeof b.gapFrom||"number"!=typeof b.gapTo||"number"!=typeof b.insert)throw RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new q(b.from,b.to,b.gapFrom,b.gapTo,d.Ji.fromJSON(a,b.slice),b.insert,!!b.structure)}}function r(a,b,c){let d=a.resolve(b),e=c-b,f=d.depth;for(;e>0&&f>0&&d.indexAfter(f)==d.node(f).childCount;)f--,e--;if(e>0){let a=d.node(f).maybeChild(d.indexAfter(f));for(;e>0;){if(!a||a.isLeaf)return!0;a=a.firstChild,e--}}return!1}function s(a,b,c,e=c.contentMatch,f=!0){let g=a.doc.nodeAt(b),h=[],i=b+1;for(let b=0;b<g.childCount;b++){let j=g.child(b),k=i+j.nodeSize,l=e.matchType(j.type);if(l){e=l;for(let b=0;b<j.marks.length;b++)c.allowsMarkType(j.marks[b].type)||a.step(new m(i,k,j.marks[b]));if(f&&j.isText&&"pre"!=c.whitespace){let a,b=/\r?\n|\r/g,e;for(;a=b.exec(j.text);)e||(e=new d.Ji(d.FK.from(c.schema.text(" ",c.allowedMarks(j.marks))),0,0)),h.push(new p(i+a.index,i+a.index+a[0].length,e))}}else h.push(new p(i,k,d.Ji.empty));i=k}if(!e.validEnd){let b=e.fillBefore(d.FK.empty,!0);a.replace(i,i,new d.Ji(b,0,0))}for(let b=h.length-1;b>=0;b--)a.step(h[b])}function t(a){let b=a.parent.content.cutByIndex(a.startIndex,a.endIndex);for(let c=a.depth,d=0,e=0;;--c){let f=a.$from.node(c),g=a.$from.index(c)+d,h=a.$to.indexAfter(c)-e;if(c<a.depth&&f.canReplace(g,h,b))return c;if(0==c||f.type.spec.isolating||!((0==g||f.canReplace(g,f.childCount))&&(h==f.childCount||f.canReplace(0,h))))break;g&&(d=1),h<f.childCount&&(e=1)}return null}function u(a,b,c=null,d=a){let e=function(a,b){let{parent:c,startIndex:d,endIndex:e}=a,f=c.contentMatchAt(d).findWrapping(b);if(!f)return null;let g=f.length?f[0]:b;return c.canReplaceWith(d,e,g)?f:null}(a,b),f=e&&function(a,b){let{parent:c,startIndex:d,endIndex:e}=a,f=c.child(d),g=b.contentMatch.findWrapping(f.type);if(!g)return null;let h=(g.length?g[g.length-1]:b).contentMatch;for(let a=d;h&&a<e;a++)h=h.matchType(c.child(a).type);return h&&h.validEnd?g:null}(d,b);return f?e.map(v).concat({type:b,attrs:c}).concat(f.map(v)):null}function v(a){return{type:a,attrs:null}}function w(a,b,c,d){b.forEach((e,f)=>{if(e.isText){let g,h=/\r?\n|\r/g;for(;g=h.exec(e.text);){let e=a.mapping.slice(d).map(c+1+f+g.index);a.replaceWith(e,e+1,b.type.schema.linebreakReplacement.create())}}})}function x(a,b,c,d){b.forEach((e,f)=>{if(e.type==e.type.schema.linebreakReplacement){let e=a.mapping.slice(d).map(c+1+f);a.replaceWith(e,e+1,b.type.schema.text("\n"))}})}function y(a,b,c=1,d){let e=a.resolve(b),f=e.depth-c,g=d&&d[d.length-1]||e.parent;if(f<0||e.parent.type.spec.isolating||!e.parent.canReplace(e.index(),e.parent.childCount)||!g.type.validContent(e.parent.content.cutByIndex(e.index(),e.parent.childCount)))return!1;for(let a=e.depth-1,b=c-2;a>f;a--,b--){let c=e.node(a),f=e.index(a);if(c.type.spec.isolating)return!1;let g=c.content.cutByIndex(f,c.childCount),h=d&&d[b+1];h&&(g=g.replaceChild(0,h.type.create(h.attrs)));let i=d&&d[b]||c;if(!c.canReplace(f+1,c.childCount)||!i.type.validContent(g))return!1}let h=e.indexAfter(f),i=d&&d[0];return e.node(f).canReplaceWith(h,h,i?i.type:e.node(f+1).type)}function z(a,b){let c=a.resolve(b),d=c.index();return A(c.nodeBefore,c.nodeAfter)&&c.parent.canReplace(d,d+1)}function A(a,b){return!!(a&&b&&!a.isLeaf&&function(a,b){b.content.size||a.type.compatibleContent(b.type);let c=a.contentMatchAt(a.childCount),{linebreakReplacement:d}=a.type.schema;for(let e=0;e<b.childCount;e++){let f=b.child(e),g=f.type==d?a.type.schema.nodes.text:f.type;if(!(c=c.matchType(g))||!a.type.allowsMarks(f.marks))return!1}return c.validEnd}(a,b))}function B(a,b,c=-1){let d=a.resolve(b);for(let a=d.depth;;a--){let e,f,g=d.index(a);if(a==d.depth?(e=d.nodeBefore,f=d.nodeAfter):c>0?(e=d.node(a+1),g++,f=d.node(a).maybeChild(g)):(e=d.node(a).maybeChild(g-1),f=d.node(a+1)),e&&!e.isTextblock&&A(e,f)&&d.node(a).canReplace(g,g+1))return b;if(0==a)break;b=c<0?d.before(a):d.after(a)}}function C(a,b,c){let d=a.resolve(b);if(!c.content.size)return b;let e=c.content;for(let a=0;a<c.openStart;a++)e=e.firstChild.content;for(let a=1;a<=(0==c.openStart&&c.size?2:1);a++)for(let b=d.depth;b>=0;b--){let c=b==d.depth?0:d.pos<=(d.start(b+1)+d.end(b+1))/2?-1:1,f=d.index(b)+ +(c>0),g=d.node(b),h=!1;if(1==a)h=g.canReplace(f,f,e);else{let a=g.contentMatchAt(f).findWrapping(e.firstChild.type);h=a&&g.canReplaceWith(f,f,a[0])}if(h)return 0==c?d.pos:c<0?d.before(b+1):d.after(b+1)}return null}function D(a,b,c=b,e=d.Ji.empty){if(b==c&&!e.size)return null;let f=a.resolve(b),g=a.resolve(c);return E(f,g,e)?new p(b,c,e):new F(f,g,e).fit()}function E(a,b,c){return!c.openStart&&!c.openEnd&&a.start()==b.start()&&a.parent.canReplace(a.index(),b.index(),c.content)}i.jsonID("replaceAround",q);class F{constructor(a,b,c){this.$from=a,this.$to=b,this.unplaced=c,this.frontier=[],this.placed=d.FK.empty;for(let b=0;b<=a.depth;b++){let c=a.node(b);this.frontier.push({type:c.type,match:c.contentMatchAt(a.indexAfter(b))})}for(let b=a.depth;b>0;b--)this.placed=d.FK.from(a.node(b).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let a=this.mustMoveInline(),b=this.placed.size-this.depth-this.$from.depth,c=this.$from,e=this.close(a<0?this.$to:c.doc.resolve(a));if(!e)return null;let f=this.placed,g=c.depth,h=e.depth;for(;g&&h&&1==f.childCount;)f=f.firstChild.content,g--,h--;let i=new d.Ji(f,g,h);return a>-1?new q(c.pos,a,this.$to.pos,this.$to.end(),i,b):i.size||c.pos!=this.$to.pos?new p(c.pos,e.pos,i):null}findFittable(){let a=this.unplaced.openStart;for(let b=this.unplaced.content,c=0,d=this.unplaced.openEnd;c<a;c++){let e=b.firstChild;if(b.childCount>1&&(d=0),e.type.spec.isolating&&d<=c){a=c;break}b=e.content}for(let b=1;b<=2;b++)for(let c=1==b?a:this.unplaced.openStart;c>=0;c--){let a=null,e=(c?(a=I(this.unplaced.content,c-1).firstChild).content:this.unplaced.content).firstChild;for(let f=this.depth;f>=0;f--){let{type:g,match:h}=this.frontier[f],i,j=null;if(1==b&&(e?h.matchType(e.type)||(j=h.fillBefore(d.FK.from(e),!1)):a&&g.compatibleContent(a.type)))return{sliceDepth:c,frontierDepth:f,parent:a,inject:j};if(2==b&&e&&(i=h.findWrapping(e.type)))return{sliceDepth:c,frontierDepth:f,parent:a,wrap:i};if(a&&h.matchType(a.type))break}}}openMore(){let{content:a,openStart:b,openEnd:c}=this.unplaced,e=I(a,b);return!!e.childCount&&!e.firstChild.isLeaf&&(this.unplaced=new d.Ji(a,b+1,Math.max(c,e.size+b>=a.size-c?b+1:0)),!0)}dropNode(){let{content:a,openStart:b,openEnd:c}=this.unplaced,e=I(a,b);if(e.childCount<=1&&b>0){let f=a.size-b<=b+e.size;this.unplaced=new d.Ji(G(a,b-1,1),b-1,f?b-1:c)}else this.unplaced=new d.Ji(G(a,b,1),b,c)}placeNodes({sliceDepth:a,frontierDepth:b,parent:c,inject:e,wrap:f}){for(;this.depth>b;)this.closeFrontierNode();if(f)for(let a=0;a<f.length;a++)this.openFrontierNode(f[a]);let g=this.unplaced,h=c?c.content:g.content,i=g.openStart-a,j=0,k=[],{match:l,type:m}=this.frontier[b];if(e){for(let a=0;a<e.childCount;a++)k.push(e.child(a));l=l.matchFragment(e)}let n=h.size+a-(g.content.size-g.openEnd);for(;j<h.childCount;){let a=h.child(j),b=l.matchType(a.type);if(!b)break;(++j>1||0==i||a.content.size)&&(l=b,k.push(function a(b,c,e){if(c<=0)return b;let f=b.content;return c>1&&(f=f.replaceChild(0,a(f.firstChild,c-1,1==f.childCount?e-1:0))),c>0&&(f=b.type.contentMatch.fillBefore(f).append(f),e<=0&&(f=f.append(b.type.contentMatch.matchFragment(f).fillBefore(d.FK.empty,!0)))),b.copy(f)}(a.mark(m.allowedMarks(a.marks)),1==j?i:0,j==h.childCount?n:-1)))}let o=j==h.childCount;o||(n=-1),this.placed=H(this.placed,b,d.FK.from(k)),this.frontier[b].match=l,o&&n<0&&c&&c.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let a=0,b=h;a<n;a++){let a=b.lastChild;this.frontier.push({type:a.type,match:a.contentMatchAt(a.childCount)}),b=a.content}this.unplaced=o?0==a?d.Ji.empty:new d.Ji(G(g.content,a-1,1),a-1,n<0?g.openEnd:a-1):new d.Ji(G(g.content,a,j),g.openStart,g.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return -1;let a=this.frontier[this.depth],b;if(!a.type.isTextblock||!J(this.$to,this.$to.depth,a.type,a.match,!1)||this.$to.depth==this.depth&&(b=this.findCloseLevel(this.$to))&&b.depth==this.depth)return -1;let{depth:c}=this.$to,d=this.$to.after(c);for(;c>1&&d==this.$to.end(--c);)++d;return d}findCloseLevel(a){d:for(let b=Math.min(this.depth,a.depth);b>=0;b--){let{match:c,type:d}=this.frontier[b],e=b<a.depth&&a.end(b+1)==a.pos+(a.depth-(b+1)),f=J(a,b,d,c,e);if(f){for(let c=b-1;c>=0;c--){let{match:b,type:d}=this.frontier[c],e=J(a,c,d,b,!0);if(!e||e.childCount)continue d}return{depth:b,fit:f,move:e?a.doc.resolve(a.after(b+1)):a}}}}close(a){let b=this.findCloseLevel(a);if(!b)return null;for(;this.depth>b.depth;)this.closeFrontierNode();b.fit.childCount&&(this.placed=H(this.placed,b.depth,b.fit)),a=b.move;for(let c=b.depth+1;c<=a.depth;c++){let b=a.node(c),d=b.type.contentMatch.fillBefore(b.content,!0,a.index(c));this.openFrontierNode(b.type,b.attrs,d)}return a}openFrontierNode(a,b=null,c){let e=this.frontier[this.depth];e.match=e.match.matchType(a),this.placed=H(this.placed,this.depth,d.FK.from(a.create(b,c))),this.frontier.push({type:a,match:a.contentMatch})}closeFrontierNode(){let a=this.frontier.pop().match.fillBefore(d.FK.empty,!0);a.childCount&&(this.placed=H(this.placed,this.frontier.length,a))}}function G(a,b,c){return 0==b?a.cutByIndex(c,a.childCount):a.replaceChild(0,a.firstChild.copy(G(a.firstChild.content,b-1,c)))}function H(a,b,c){return 0==b?a.append(c):a.replaceChild(a.childCount-1,a.lastChild.copy(H(a.lastChild.content,b-1,c)))}function I(a,b){for(let c=0;c<b;c++)a=a.firstChild.content;return a}function J(a,b,c,d,e){let f=a.node(b),g=e?a.indexAfter(b):a.index(b);if(g==f.childCount&&!c.compatibleContent(f.type))return null;let h=d.fillBefore(f.content,!0,g);return h&&!function(a,b,c){for(let d=c;d<b.childCount;d++)if(!a.allowsMarks(b.child(d).marks))return!0;return!1}(c,f.content,g)?h:null}function K(a,b){let c=[],d=Math.min(a.depth,b.depth);for(let e=d;e>=0;e--){let d=a.start(e);if(d<a.pos-(a.depth-e)||b.end(e)>b.pos+(b.depth-e)||a.node(e).type.spec.isolating||b.node(e).type.spec.isolating)break;(d==b.start(e)||e==a.depth&&e==b.depth&&a.parent.inlineContent&&b.parent.inlineContent&&e&&b.start(e-1)==d-1)&&c.push(e)}return c}class L extends i{constructor(a,b,c){super(),this.pos=a,this.attr=b,this.value=c}apply(a){let b=a.nodeAt(this.pos);if(!b)return j.fail("No node at attribute step's position");let c=Object.create(null);for(let a in b.attrs)c[a]=b.attrs[a];c[this.attr]=this.value;let e=b.type.create(c,null,b.marks);return j.fromReplace(a,this.pos,this.pos+1,new d.Ji(d.FK.from(e),0,+!b.isLeaf))}getMap(){return f.empty}invert(a){return new L(this.pos,this.attr,a.nodeAt(this.pos).attrs[this.attr])}map(a){let b=a.mapResult(this.pos,1);return b.deletedAfter?null:new L(b.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(a,b){if("number"!=typeof b.pos||"string"!=typeof b.attr)throw RangeError("Invalid input for AttrStep.fromJSON");return new L(b.pos,b.attr,b.value)}}i.jsonID("attr",L);class M extends i{constructor(a,b){super(),this.attr=a,this.value=b}apply(a){let b=Object.create(null);for(let c in a.attrs)b[c]=a.attrs[c];b[this.attr]=this.value;let c=a.type.create(b,a.content,a.marks);return j.ok(c)}getMap(){return f.empty}invert(a){return new M(this.attr,a.attrs[this.attr])}map(a){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(a,b){if("string"!=typeof b.attr)throw RangeError("Invalid input for DocAttrStep.fromJSON");return new M(b.attr,b.value)}}i.jsonID("docAttr",M);let N=class extends Error{};(N=function a(b){let c=Error.call(this,b);return c.__proto__=a.prototype,c}).prototype=Object.create(Error.prototype),N.prototype.constructor=N,N.prototype.name="TransformError";class O{constructor(a){this.doc=a,this.steps=[],this.docs=[],this.mapping=new g}get before(){return this.docs.length?this.docs[0]:this.doc}step(a){let b=this.maybeStep(a);if(b.failed)throw new N(b.failed);return this}maybeStep(a){let b=a.apply(this.doc);return b.failed||this.addStep(a,b.doc),b}get docChanged(){return this.steps.length>0}changedRange(){let a=1e9,b=-1e9;for(let c=0;c<this.mapping.maps.length;c++){let d=this.mapping.maps[c];c&&(a=d.map(a,1),b=d.map(b,-1)),d.forEach((c,d,e,f)=>{a=Math.min(a,e),b=Math.max(b,f)})}return 1e9==a?null:{from:a,to:b}}addStep(a,b){this.docs.push(this.doc),this.steps.push(a),this.mapping.appendMap(a.getMap()),this.doc=b}replace(a,b=a,c=d.Ji.empty){let e=D(this.doc,a,b,c);return e&&this.step(e),this}replaceWith(a,b,c){return this.replace(a,b,new d.Ji(d.FK.from(c),0,0))}delete(a,b){return this.replace(a,b,d.Ji.empty)}insert(a,b){return this.replaceWith(a,a,b)}replaceRange(a,b,c){return!function(a,b,c,e){if(!e.size)return a.deleteRange(b,c);let f=a.doc.resolve(b),g=a.doc.resolve(c);if(E(f,g,e))return a.step(new p(b,c,e));let h=K(f,g);0==h[h.length-1]&&h.pop();let i=-(f.depth+1);h.unshift(i);for(let a=f.depth,b=f.pos-1;a>0;a--,b--){let c=f.node(a).type.spec;if(c.defining||c.definingAsContext||c.isolating)break;h.indexOf(a)>-1?i=a:f.before(a)==b&&h.splice(1,0,-a)}let j=h.indexOf(i),k=[],l=e.openStart;for(let a=e.content,b=0;;b++){let c=a.firstChild;if(k.push(c),b==e.openStart)break;a=c.content}for(let a=l-1;a>=0;a--){var m;let b=k[a],c=(m=b.type).spec.defining||m.spec.definingForContent;if(c&&!b.sameMarkup(f.node(Math.abs(i)-1)))l=a;else if(c||!b.type.isTextblock)break}for(let b=e.openStart;b>=0;b--){let i=(b+l+1)%(e.openStart+1),m=k[i];if(m)for(let b=0;b<h.length;b++){let k=h[(b+j)%h.length],l=!0;k<0&&(l=!1,k=-k);let n=f.node(k-1),o=f.index(k-1);if(n.canReplaceWith(o,o,m.type,m.marks))return a.replace(f.before(k),l?g.after(k):c,new d.Ji(function a(b,c,e,f,g){if(c<e){let d=b.firstChild;b=b.replaceChild(0,d.copy(a(d.content,c+1,e,f,d)))}if(c>f){let a=g.contentMatchAt(0),c=a.fillBefore(b).append(b);b=c.append(a.matchFragment(c).fillBefore(d.FK.empty,!0))}return b}(e.content,0,e.openStart,i),i,e.openEnd))}}let n=a.steps.length;for(let d=h.length-1;d>=0&&(a.replace(b,c,e),!(a.steps.length>n));d--){let a=h[d];a<0||(b=f.before(a),c=g.after(a))}}(this,a,b,c),this}replaceRangeWith(a,b,c){var e=a,f=b;if(!c.isInline&&e==f&&this.doc.resolve(e).parent.content.size){let a=function(a,b,c){let d=a.resolve(b);if(d.parent.canReplaceWith(d.index(),d.index(),c))return b;if(0==d.parentOffset)for(let a=d.depth-1;a>=0;a--){let b=d.index(a);if(d.node(a).canReplaceWith(b,b,c))return d.before(a+1);if(b>0)return null}if(d.parentOffset==d.parent.content.size)for(let a=d.depth-1;a>=0;a--){let b=d.indexAfter(a);if(d.node(a).canReplaceWith(b,b,c))return d.after(a+1);if(b<d.node(a).childCount)break}return null}(this.doc,e,c.type);null!=a&&(e=f=a)}return this.replaceRange(e,f,new d.Ji(d.FK.from(c),0,0)),this}deleteRange(a,b){return!function(a,b,c){let d=a.doc.resolve(b),e=a.doc.resolve(c),f=K(d,e);for(let b=0;b<f.length;b++){let c=f[b],g=b==f.length-1;if(g&&0==c||d.node(c).type.contentMatch.validEnd)return a.delete(d.start(c),e.end(c));if(c>0&&(g||d.node(c-1).canReplace(d.index(c-1),e.indexAfter(c-1))))return a.delete(d.before(c),e.after(c))}for(let f=1;f<=d.depth&&f<=e.depth;f++)if(b-d.start(f)==d.depth-f&&c>d.end(f)&&e.end(f)-c!=e.depth-f&&d.start(f-1)==e.start(f-1)&&d.node(f-1).canReplace(d.index(f-1),e.index(f-1)))return a.delete(d.before(f),c);a.delete(b,c)}(this,a,b),this}lift(a,b){return!function(a,b,c){let{$from:e,$to:f,depth:g}=b,h=e.before(g+1),i=f.after(g+1),j=h,k=i,l=d.FK.empty,m=0;for(let a=g,b=!1;a>c;a--)b||e.index(a)>0?(b=!0,l=d.FK.from(e.node(a).copy(l)),m++):j--;let n=d.FK.empty,o=0;for(let a=g,b=!1;a>c;a--)b||f.after(a+1)<f.end(a)?(b=!0,n=d.FK.from(f.node(a).copy(n)),o++):k++;a.step(new q(j,k,h,i,new d.Ji(l.append(n),m,o),l.size-m,!0))}(this,a,b),this}join(a,b=1){return!function(a,b,c){let e=null,{linebreakReplacement:f}=a.doc.type.schema,g=a.doc.resolve(b-c),h=g.node().type;if(f&&h.inlineContent){let a="pre"==h.whitespace,b=!!h.contentMatch.matchType(f);a&&!b?e=!1:!a&&b&&(e=!0)}let i=a.steps.length;if(!1===e){let d=a.doc.resolve(b+c);x(a,d.node(),d.before(),i)}h.inlineContent&&s(a,b+c-1,h,g.node().contentMatchAt(g.index()),null==e);let j=a.mapping.slice(i),k=j.map(b-c);if(a.step(new p(k,j.map(b+c,-1),d.Ji.empty,!0)),!0===e){let b=a.doc.resolve(k);w(a,b.node(),b.before(),a.steps.length)}}(this,a,b),this}wrap(a,b){return!function(a,b,c){let e=d.FK.empty;for(let a=c.length-1;a>=0;a--){if(e.size){let b=c[a].type.contentMatch.matchFragment(e);if(!b||!b.validEnd)throw RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}e=d.FK.from(c[a].type.create(c[a].attrs,e))}let f=b.start,g=b.end;a.step(new q(f,g,f,g,new d.Ji(e,0,0),c.length,!0))}(this,a,b),this}setBlockType(a,b=a,c,e=null){var f=this;if(!c.isTextblock)throw RangeError("Type given to setBlockType should be a textblock");let g=f.steps.length;return f.doc.nodesBetween(a,b,(a,b)=>{var h,i,j;let k,l,m="function"==typeof e?e(a):e;if(a.isTextblock&&!a.hasMarkup(c,m)&&(h=f.doc,i=f.mapping.slice(g).map(b),j=c,l=(k=h.resolve(i)).index(),k.parent.canReplaceWith(l,l+1,j))){let e=null;if(c.schema.linebreakReplacement){let a="pre"==c.whitespace,b=!!c.contentMatch.matchType(c.schema.linebreakReplacement);a&&!b?e=!1:!a&&b&&(e=!0)}!1===e&&x(f,a,b,g),s(f,f.mapping.slice(g).map(b,1),c,void 0,null===e);let h=f.mapping.slice(g),i=h.map(b,1),j=h.map(b+a.nodeSize,1);return f.step(new q(i,j,i+1,j-1,new d.Ji(d.FK.from(c.create(m,null,a.marks)),0,0),1,!0)),!0===e&&w(f,a,b,g),!1}}),this}setNodeMarkup(a,b,c=null,e){return!function(a,b,c,e,f){let g=a.doc.nodeAt(b);if(!g)throw RangeError("No node at given position");c||(c=g.type);let h=c.create(e,null,f||g.marks);if(g.isLeaf)return a.replaceWith(b,b+g.nodeSize,h);if(!c.validContent(g.content))throw RangeError("Invalid content for node type "+c.name);a.step(new q(b,b+g.nodeSize,b+1,b+g.nodeSize-1,new d.Ji(d.FK.from(h),0,0),1,!0))}(this,a,b,c,e),this}setNodeAttribute(a,b,c){return this.step(new L(a,b,c)),this}setDocAttribute(a,b){return this.step(new M(a,b)),this}addNodeMark(a,b){return this.step(new n(a,b)),this}removeNodeMark(a,b){let c=this.doc.nodeAt(a);if(!c)throw RangeError("No node at position "+a);if(b instanceof d.CU)b.isInSet(c.marks)&&this.step(new o(a,b));else{let d=c.marks,e,f=[];for(;e=b.isInSet(d);)f.push(new o(a,e)),d=e.removeFromSet(d);for(let a=f.length-1;a>=0;a--)this.step(f[a])}return this}split(a,b=1,c){return!function(a,b,c=1,e){let f=a.doc.resolve(b),g=d.FK.empty,h=d.FK.empty;for(let a=f.depth,b=f.depth-c,i=c-1;a>b;a--,i--){g=d.FK.from(f.node(a).copy(g));let b=e&&e[i];h=d.FK.from(b?b.type.create(b.attrs,h):f.node(a).copy(h))}a.step(new p(b,b,new d.Ji(g.append(h),c,c),!0))}(this,a,b,c),this}addMark(a,b,c){var d;let e,f,g,h;return d=this,g=[],h=[],d.doc.nodesBetween(a,b,(d,i,j)=>{if(!d.isInline)return;let k=d.marks;if(!c.isInSet(k)&&j.type.allowsMarkType(c.type)){let j=Math.max(i,a),n=Math.min(i+d.nodeSize,b),o=c.addToSet(k);for(let a=0;a<k.length;a++)k[a].isInSet(o)||(e&&e.to==j&&e.mark.eq(k[a])?e.to=n:g.push(e=new m(j,n,k[a])));f&&f.to==j?f.to=n:h.push(f=new l(j,n,c))}}),g.forEach(a=>d.step(a)),h.forEach(a=>d.step(a)),this}removeMark(a,b,c){var e;let f,g;return e=this,f=[],g=0,e.doc.nodesBetween(a,b,(e,h)=>{if(!e.isInline)return;g++;let i=null;if(c instanceof d.sX){let a=e.marks,b;for(;b=c.isInSet(a);)(i||(i=[])).push(b),a=b.removeFromSet(a)}else c?c.isInSet(e.marks)&&(i=[c]):i=e.marks;if(i&&i.length){let c=Math.min(h+e.nodeSize,b);for(let b=0;b<i.length;b++){let d=i[b],e;for(let a=0;a<f.length;a++){let b=f[a];b.step==g-1&&d.eq(f[a].style)&&(e=b)}e?(e.to=c,e.step=g):f.push({style:d,from:Math.max(h,a),to:c,step:g})}}}),f.forEach(a=>e.step(new m(a.from,a.to,a.style))),this}clearIncompatible(a,b,c){return s(this,a,b,c),this}}},32206:(a,b,c)=>{"use strict";c.d(b,{o:()=>k});var d=c(36927),e=c(15962),f=c(11263);let g=(0,e.createContext)(null);var h=c(35724),i=c(546);let j=a=>!a.isLayoutDirty&&a.willUpdate(!1),k=({children:a,id:b,inherit:c=!0})=>{let k=(0,e.useContext)(f.L),l=(0,e.useContext)(g),[m,n]=function(){let a=function(){let a=(0,e.useRef)(!1);return(0,i.E)(()=>(a.current=!0,()=>{a.current=!1}),[]),a}(),[b,c]=(0,e.useState)(0),d=(0,e.useCallback)(()=>{a.current&&c(b+1)},[b]);return[(0,e.useCallback)(()=>h.Gt.postRender(d),[d]),b]}(),o=(0,e.useRef)(null),p=k.id||l;null===o.current&&((a=>!0==(!0===a)||"id"===a)(c)&&p&&(b=b?p+"-"+b:p),o.current={id:b,group:!0===c&&k.group||function(){let a=new Set,b=new WeakMap,c=()=>a.forEach(j);return{add:d=>{a.add(d),b.set(d,d.addEventListener("willUpdate",c))},remove:d=>{a.delete(d);let e=b.get(d);e&&(e(),b.delete(d)),c()},dirty:c}}()});let q=(0,e.useMemo)(()=>({...o.current,forceRender:m}),[n]);return(0,d.jsx)(f.L.Provider,{value:q,children:a})}},32314:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.d(b,{c:()=>D});var e=c(36927),f=c(58404),g=c(99967),h=c(25607),i=c(15962),j=c(55132),k=c(90106),l=c(43461),m=c(58556),n=c(42837),o=c(73700),p=c(51651),q=c(59448),r=c(29187),s=a([r]);r=(s.then?(await s)():s)[0];let B=(0,f.default)(async()=>{},{loadableGenerated:{modules:["app/components/chat-message.tsx -> ./charts/report-card"]},ssr:!1,loading:()=>(0,e.jsx)("div",{className:"h-48 rounded-2xl animate-pulse",style:{background:"var(--color-surface-hover)"}})}),C="NO_REPLY";function t(a){return"output-available"===a?"done":"error"===a?"error":"running"}function u(a){if(a&&"object"==typeof a&&!Array.isArray(a))return a}function v({paths:a}){return(0,e.jsx)("div",{className:"flex flex-wrap gap-1.5 mb-2 justify-end",children:a.map((a,b)=>{let c=function(a){let b=a.split(".").pop()?.toLowerCase()??"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(b)?"image":["mp4","webm","mov","avi","mkv","flv"].includes(b)?"video":["mp3","wav","ogg","aac","flac","m4a"].includes(b)?"audio":"pdf"===b?"pdf":["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(b)?"code":["doc","docx","xls","xlsx","ppt","pptx","txt","rtf","csv","pages","numbers","key"].includes(b)?"document":"other"}(a),d="image"===c?`/api/workspace/raw-file?path=${encodeURIComponent(a)}`:`/api/workspace/thumbnail?path=${encodeURIComponent(a)}&size=200`,f=a.split(".").pop()?.toUpperCase()??"";return(0,e.jsxs)("div",{className:"relative rounded-xl overflow-hidden shrink-0",children:[(0,e.jsx)("img",{src:d,alt:a.split("/").pop()??"",className:"block rounded-xl object-cover",style:{maxHeight:140,maxWidth:160,background:"rgba(0,0,0,0.04)"},loading:"lazy",onError:a=>{a.currentTarget.style.display="none"}}),"image"!==c&&(0,e.jsx)("span",{className:"absolute bottom-2 left-2 rounded-md px-1.5 py-0.5 text-[10px] font-bold uppercase",style:{background:"rgba(255,255,255,0.85)",color:"rgba(0,0,0,0.5)",backdropFilter:"blur(4px)"},children:f})]},b)})})}function w(a){let b=a.trim();if(!b||b.length<3||b.length>500)return!1;if(b.startsWith("~/")||b.startsWith("/")||b.startsWith("./")||b.startsWith("../")){let a=b.startsWith("~/")?b.slice(2):b.startsWith("../")?b.slice(3):b.startsWith("./")?b.slice(2):b.slice(1);return a.includes("/")||a.includes(".")}return!(!/\.(pdf|docx?|xlsx?|pptx?|csv|txt|rtf|pages|numbers|key|md|json|yaml|yml|toml|xml|html?|css|jsx?|tsx?|py|rb|go|rs|java|cpp|c|h|sh|sql|swift|kt|png|jpe?g|gif|webp|svg|bmp|ico|heic|tiff|mp[34]|webm|mov|avi|mkv|flv|wav|ogg|aac|flac|m4a|zip|tar|gz|dmg)$/i.test(b)||b.includes(" "))}async function x(a,b=!1){try{let c=await fetch("/api/workspace/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a,reveal:b})});if(!c.ok){let a=await c.json().catch(()=>({}));console.error("Failed to open file:",a)}}catch(a){console.error("Failed to open file:",a)}}function y(a){let b=a.trim();if(!b.startsWith("file://"))return b;try{let a=new URL(b);if("file:"!==a.protocol)return b;let c=decodeURIComponent(a.pathname);if(/^\/[A-Za-z]:\//.test(c))return c.slice(1);return c}catch{return b}}function z({path:a,children:b,onFilePathClick:c}){let[d,f]=(0,i.useState)("idle"),g=async b=>{b.preventDefault(),f("opening");try{if(c){let b=await c(a);if(!1===b){f("error"),setTimeout(()=>f("idle"),2e3);return}f("idle")}else(await fetch("/api/workspace/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a})})).ok?f("idle"):(f("error"),setTimeout(()=>f("idle"),2e3))}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},h=async b=>{b.preventDefault(),await x(a,!0)};return(0,e.jsx)("code",{className:`px-[0.3em] no-underline transition-colors duration-150 rounded-[4px] border border-[color:var(--color-border)] bg-white/20 hover:bg-white/40 active:bg-white ${"opening"===d?"cursor-wait opacity-70":"cursor-pointer"}`,style:{color:"var(--color-accent)"},onClick:g,onContextMenu:h,title:"error"===d?"File not found":c?"Click to preview in workspace \xb7 Right-click to reveal in Finder":"Click to open \xb7 Right-click to reveal in Finder",children:b})}function A({messageId:a,sessionId:b}){let c=(0,i.useCallback)((a,b)=>{a&&fetch("/api/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:a,messageId:b,distinctId:g.Ay.get_distinct_id?.()})}).catch(()=>{})},[]),{respond:d,response:f,triggerRef:j}=(0,h.y)({surveyId:"019cc021-a8bf-0000-d41d-b82956ef7e6a",properties:{$ai_trace_id:b,message_id:a},onResponse:()=>c(b,a)}),k="p-1 rounded-md transition-colors";return(0,e.jsxs)("div",{ref:j,className:"flex items-center gap-0.5 mt-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,e.jsx)("button",{type:"button",onClick:()=>d("up"),className:k,style:{color:"up"===f?"var(--color-accent)":"var(--color-text-muted)"},title:"Good response","aria-label":"Thumbs up",children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"up"===f?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M7 10v12"}),(0,e.jsx)("path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z"})]})}),(0,e.jsx)("button",{type:"button",onClick:()=>d("down"),className:k,style:{color:"down"===f?"var(--color-error, #ef4444)":"var(--color-text-muted)"},title:"Bad response","aria-label":"Thumbs down",children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"down"===f?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M17 14V2"}),(0,e.jsx)("path",{d:"M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z"})]})})]})}let D=(0,i.memo)(function({message:a,isStreaming:b,onSubagentClick:c,onFilePathClick:d,sessionId:f,userHtmlMap:g}){let h="user"===a.role,s=function(a){let b=[],c=[],d=a=>{if(c.length>0){if(a)for(let a of c)"tool"===a.kind&&"running"===a.status&&(a.status="done");b.push({type:"chain",parts:[...c]}),c=[]}};for(let e of a)if("text"===e.type){let a=e.text;if(function(a){let b=a.trim();return!!b&&!!(RegExp(`^${C}\\W*$`).test(b)||C.startsWith(b)&&b.length>=2&&b.length<C.length)}(a))continue;if(d(!0),(0,o.x)(a))b.push(...(0,o.R)(a));else if((0,p.k)(a))for(let c of(0,p.g)(a))"diff-artifact"===c.type?b.push({type:"diff-artifact",diff:c.diff}):b.push({type:"text",text:c.text});else b.push({type:"text",text:a})}else if("reasoning"===e.type){let a=e;["Preparing response...","Optimizing session context...","Waiting for subagent results...","Waiting for subagents..."].some(b=>a.text.startsWith(b))||c.push({kind:"reasoning",text:a.text,isStreaming:"streaming"===a.state})}else if("dynamic-tool"===e.type)if("sessions_spawn"===e.toolName){d(!0);let a=u(e.input),c=u(e.output),f="string"==typeof a?.task?a.task:"Subagent task",g="string"==typeof a?.label?a.label:void 0,h="string"==typeof c?.sessionKey?c.sessionKey:void 0;b.push({type:"subagent-card",task:f,label:g,sessionKey:h,status:t(e.state)})}else c.push({kind:"tool",toolName:e.toolName,toolCallId:e.toolCallId,status:t(e.state),args:u(e.input),output:u(e.output)});else if(e.type.startsWith("tool-")){let a=e.title??e.toolName??e.type.replace("tool-","");if("sessions_spawn"===a){d(!0);let a=u(e.input)??u(e.args),c=u(e.output)??u(e.result),f="string"==typeof a?.task?a.task:"Subagent task",g="string"==typeof a?.label?a.label:void 0,h="string"==typeof c?.sessionKey?c.sessionKey:void 0,i=e.state??(e.errorText?"error":"result"in e||"output"in e?"output-available":"input-available");b.push({type:"subagent-card",task:f,label:g,sessionKey:h,status:t(i)})}else{let b=e.state??(e.errorText?"error":"result"in e||"output"in e?"output-available":"input-available");c.push({kind:"tool",toolName:a,toolCallId:e.toolCallId,status:t(b),args:u(e.input)??u(e.args),output:u(e.output)??u(e.result)})}}return d(),b}(a.parts),x=(0,i.useMemo)(()=>({a:({href:a,children:b,...c})=>{let f="string"==typeof a?a:"",g=y(f),h=f&&(f.startsWith("http://")||f.startsWith("https://")||f.startsWith("//")),i=!(f.startsWith("/workspace")||f.startsWith("/?"))&&(!!f.startsWith("file://")||w(g));return(0,e.jsx)("a",{href:a,...h?{target:"_blank",rel:"noopener noreferrer"}:{},...c,onClick:a=>{i&&d&&(a.preventDefault(),d(g))},children:b})},img:({src:a,alt:b,...c})=>{let d="string"!=typeof a||a.startsWith("http://")||a.startsWith("https://")||a.startsWith("data:")?a:`/api/workspace/raw-file?path=${encodeURIComponent(a)}`;return(0,e.jsx)("img",{src:d,alt:b??"",loading:"lazy",...c})},pre:({children:a,...b})=>{let c=Array.isArray(a)?a[0]:a;if(c&&"object"==typeof c&&"type"in c&&"code"===c.type){let a=(c.props?.className??"").match(/language-(\w+)/),b=a?.[1]??"",d="string"==typeof c.props?.children?c.props.children.replace(/\n$/,""):"";if("diff"===b)return(0,e.jsx)(q.a,{diff:d});if(b)return(0,e.jsxs)("div",{className:"chat-code-block",children:[(0,e.jsx)("div",{className:"chat-code-lang",children:b}),(0,e.jsx)(r.F,{code:d,lang:b})]})}return(0,e.jsx)("pre",{...b,children:a})},code:({children:a,className:b,...c})=>{if(b?.startsWith("language-"))return(0,e.jsx)("code",{className:b,...c,children:a});let f=y("string"==typeof a?a:"");return f&&w(f)?(0,e.jsx)(z,{path:f,onFilePathClick:d,children:a}):(0,e.jsx)("code",{...c,children:a})},strong:({children:a,...b})=>{let c="string"==typeof a?a:Array.isArray(a)?a.filter(a=>"string"==typeof a).join(""):"";return c&&function(a){let b=a.trim();return!!b&&!(b.length<3)&&!(b.length>300)&&/\.(pdf|docx?|xlsx?|pptx?|csv|txt|rtf|pages|numbers|key|md|json|yaml|yml|toml|xml|html?|css|jsx?|tsx?|py|rb|go|rs|java|cpp|c|h|sh|sql|swift|kt|png|jpe?g|gif|webp|svg|bmp|ico|heic|tiff|mp[34]|webm|mov|avi|mkv|flv|wav|ogg|aac|flac|m4a|zip|tar|gz|dmg)$/i.test(b)}(c)?(0,e.jsx)("strong",{...b,children:(0,e.jsx)(z,{path:c,onFilePathClick:d,children:a})}):(0,e.jsx)("strong",{...b,children:a})}}),[d]);if(h){let b=s.filter(a=>"text"===a.type).map(a=>a.text).join("\n"),c=function(a){let b=a.match(/\[Attached files: (.+?)\]/);if(!b)return null;let c=(b.index??0)+b[0].length,d=a.slice(c).trim();return{paths:b[1].split(", ").map(a=>a.trim()).filter(Boolean),message:d}}(b),d=g?.get(a.id)??g?.get(b)??g?.get(c?.message??""),f=d?(0,e.jsx)("div",{className:"chat-user-html-content",dangerouslySetInnerHTML:{__html:d}}):(0,e.jsx)("p",{className:"whitespace-pre-wrap break-words",children:c?.message??b});return c?(0,e.jsxs)("div",{className:"flex flex-col items-end gap-1.5 py-2",children:[(0,e.jsx)(v,{paths:c.paths}),(c.message||d)&&(0,e.jsx)("div",{className:"max-w-[80%] w-fit rounded-2xl rounded-br-sm px-3 py-2 text-sm leading-6 break-words chat-message-font",style:{background:"var(--color-user-bubble)",color:"var(--color-user-bubble-text)"},children:f})]}):(0,e.jsx)("div",{className:"flex justify-end py-2",children:(0,e.jsx)("div",{className:"max-w-[80%] min-w-0 rounded-2xl rounded-br-sm px-3 py-2 text-sm leading-6 overflow-hidden break-words chat-message-font",style:{background:"var(--color-user-bubble)",color:"var(--color-user-bubble-text)"},children:f})})}return(0,e.jsxs)("div",{className:"py-3 space-y-2 min-w-0 overflow-hidden group",children:[(0,e.jsx)(j.N,{initial:!1,children:s.map((a,d)=>{if("text"===a.type){let b=a.text.match(/^\[error\]\s*([\s\S]*)$/);return b?(0,e.jsxs)("div",{className:"chat-message-font flex items-start gap-2 rounded-xl px-3 py-2 text-[13px] leading-relaxed overflow-hidden",style:{background:"color-mix(in srgb, var(--color-error) 6%, var(--color-surface))",color:"var(--color-error)",border:"1px solid color-mix(in srgb, var(--color-error) 18%, transparent)"},children:[(0,e.jsx)("span",{className:"flex-shrink-0 mt-0.5","aria-hidden":"true",children:(0,e.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,e.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,e.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}),(0,e.jsx)("span",{className:"whitespace-pre-wrap break-all min-w-0",children:b[1].trim()})]},d):(0,e.jsx)(k.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},className:"chat-prose chat-message-font text-sm",style:{color:"var(--color-text)"},children:(0,e.jsx)(l.oz,{remarkPlugins:[m.A],components:x,children:a.text})},`text-${d}`)}if("report-artifact"===a.type)return(0,e.jsx)(k.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,e.jsx)(B,{config:a.config})},`report-${d}`);if("diff-artifact"===a.type)return(0,e.jsx)(k.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,e.jsx)(q.a,{diff:a.diff})},`diff-${d}`);if("subagent-card"===a.type){let b=a.task.length>80?a.task.slice(0,80)+"...":a.task,f="running"===a.status;return(0,e.jsx)(k.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,e.jsx)("button",{type:"button",onClick:()=>c?.(a.sessionKey??a.task),className:"w-full text-left rounded-xl px-3.5 py-2.5 transition-colors cursor-pointer",style:{background:"var(--color-accent-light)",border:"1px solid color-mix(in srgb, var(--color-accent) 20%, transparent)"},children:(0,e.jsxs)("div",{className:"flex items-center gap-2.5",children:[f?(0,e.jsx)("span",{className:"inline-block w-2 h-2 rounded-full animate-pulse flex-shrink-0",style:{background:"var(--color-accent)"}}):(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{color:"var(--color-accent)"},children:[(0,e.jsx)("path",{d:"M16 3h5v5"}),(0,e.jsx)("path",{d:"m21 3-7 7"}),(0,e.jsx)("path",{d:"M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6"})]}),(0,e.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,e.jsx)("div",{className:"flex items-center gap-2",children:(0,e.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--color-accent)"},children:f?"Running Subagent":"Subagent"})}),(0,e.jsx)("p",{className:"text-xs mt-0.5 leading-relaxed",style:{color:"var(--color-text)"},children:a.label||b})]}),(0,e.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0 opacity-40",style:{color:"var(--color-text)"},children:(0,e.jsx)("path",{d:"m9 18 6-6-6-6"})})]})})},`subagent-${d}`)}return(0,e.jsx)(k.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,e.jsx)(n.I,{parts:a.parts,isStreaming:b})},`chain-${d}`)})}),!b&&(0,e.jsx)(A,{messageId:a.id,sessionId:f})]})});d()}catch(a){d(a)}})},32347:(a,b,c)=>{"use strict";function d(a){return a.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}c.d(b,{B:()=>d})},32468:(a,b)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"}),b.isPrototype=function(a){let b=a?.constructor;return a===("function"==typeof b?b.prototype:Object.prototype)}},32513:(a,b,c)=>{"use strict";c.d(b,{x:()=>n});var d=c(36927),e=c(15962),f=c(81918),g=c(12563),h=c(79924);function i(a){return null==a?"":"object"==typeof a?JSON.stringify(a):"string"==typeof a?a:"number"==typeof a||"boolean"==typeof a||"bigint"==typeof a?String(a):""}function j({entry:a,fields:b,members:c,relationLabels:e,onEntryClick:g}){let h=i(a.entry_id)||"",{attributes:j,listeners:l,setNodeRef:m,isDragging:n}=(0,f.PM)({id:h,data:{entry:a}});return(0,d.jsx)("div",{ref:m,...l,...j,onClick:a=>{!n&&g&&(a.stopPropagation(),g(h))},className:"rounded-lg p-3 mb-2 transition-all duration-100 cursor-grab active:cursor-grabbing select-none",style:{background:"var(--color-surface)",border:`1px solid ${n?"var(--color-accent)":"var(--color-border)"}`,opacity:n?.4:1,transform:n?"scale(1.02)":void 0},children:(0,d.jsx)(k,{entry:a,fields:b,members:c,relationLabels:e})})}function k({entry:a,fields:b,members:c,relationLabels:e}){let f=function(a,b){let c=b.find(a=>a.name.toLowerCase().includes("name")||a.name.toLowerCase().includes("title"));return c?i(a[c.name])||"Untitled":i(a[b[0]?.name])||"Untitled"}(a,b),j=b.filter(b=>"richtext"!==b.type&&null!==a[b.name]&&void 0!==a[b.name]&&""!==a[b.name]).slice(0,4),k=b.find(a=>a.name.toLowerCase().includes("name")||a.name.toLowerCase().includes("title"));return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:"text-sm font-medium mb-1.5 truncate",style:{color:"var(--color-text)"},children:f}),(0,d.jsx)("div",{className:"space-y-1",children:j.filter(a=>a!==k).slice(0,3).map(b=>{let f=a[b.name];if(!f)return null;let j=i(f);if("user"===b.type){let a=c?.find(a=>a.id===j);a&&(j=a.name)}else if("relation"===b.type){let a=e?.[b.name];j=(function(a){if(!a)return[];let b=a.trim();if(!b)return[];if(b.startsWith("["))try{let a=JSON.parse(b);if(Array.isArray(a))return a.map(String).filter(Boolean)}catch{}return[b]})(j).map(b=>a?.[b]??b).join(", ")}let k="tags"===b.type?(0,h.k)(f):[];return(0,d.jsxs)("div",{className:"flex items-center gap-1.5 text-xs",children:[(0,d.jsxs)("span",{style:{color:"var(--color-text-muted)"},children:[b.name,":"]}),"enum"===b.type?(0,d.jsx)(l,{value:i(f),enumValues:b.enum_values,enumColors:b.enum_colors}):"tags"===b.type?(0,d.jsxs)("span",{className:"flex items-center gap-0.5 flex-wrap",children:[k.slice(0,3).map(a=>{let b=(0,g.KJ)(a);return"link"===b.kind&&b.href?(0,d.jsx)("a",{href:b.href,target:"url"===b.linkType||"file"===b.linkType?"_blank":void 0,rel:"url"===b.linkType||"file"===b.linkType?"noopener noreferrer":void 0,onClick:a=>a.stopPropagation(),className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium hover:underline underline-offset-2",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-accent)"},children:b.text},a):(0,d.jsx)("span",{className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-text-muted)"},children:a},a)}),k.length>3&&(0,d.jsxs)("span",{style:{color:"var(--color-text-muted)",opacity:.6},children:["+",k.length-3]})]}):"relation"===b.type?(0,d.jsxs)("span",{className:"truncate inline-flex items-center gap-0.5",style:{color:"#60a5fa"},children:[(0,d.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.5},children:[(0,d.jsx)("path",{d:"M7 7h10v10"}),(0,d.jsx)("path",{d:"M7 17 17 7"})]}),j]}):(0,d.jsx)("span",{className:"whitespace-pre-line line-clamp-2",style:{color:"var(--color-text)"},children:j})]},b.id)})})]})}function l({value:a,enumValues:b,enumColors:c}){let e=b?.indexOf(a)??-1,f=e>=0&&c?c[e]:"#94a3b8";return(0,d.jsx)("span",{className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium",style:{background:`${f}20`,color:f},children:a})}function m({columnName:a,color:b,items:c,cardFields:g,members:h,relationLabels:k,onEntryClick:l,isOver:m,groupFieldId:n,objectName:o,onRefresh:p}){let{setNodeRef:q}=(0,f.zM)({id:`column:${a}`}),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(a),[v,w]=(0,e.useState)(!1),x=(0,e.useRef)(null),y=(0,e.useCallback)(async()=>{let b=t.trim();if(!b||b===a||!n){s(!1),u(a);return}w(!0);try{(await fetch(`/api/workspace/objects/${encodeURIComponent(o)}/fields/${encodeURIComponent(n)}/enum-rename`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldValue:a,newValue:b})})).ok?p?.():u(a)}catch{u(a)}finally{w(!1),s(!1)}},[t,a,n,o,p]);return(0,d.jsxs)("div",{ref:q,className:"flex-shrink-0 flex flex-col rounded-xl transition-colors duration-150",style:{width:"280px",background:m?"var(--color-surface)":"var(--color-bg)",border:`1px solid ${m?"var(--color-accent)":"var(--color-border)"}`},children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b",style:{borderColor:"var(--color-border)"},children:[(0,d.jsx)("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:b}}),r?(0,d.jsx)("input",{ref:x,value:t,onChange:a=>u(a.target.value),onBlur:y,onKeyDown:b=>{"Enter"===b.key&&y(),"Escape"===b.key&&(u(a),s(!1))},disabled:v,className:"text-sm font-medium flex-1 bg-transparent outline-none rounded px-1 -mx-1",style:{color:"var(--color-text)",border:"1px solid var(--color-accent)"}}):(0,d.jsx)("span",{className:"text-sm font-medium flex-1 cursor-text rounded px-1 -mx-1 hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text)"},onDoubleClick:()=>{n&&(u(a),s(!0))},title:n?"Double-click to rename":void 0,children:a}),(0,d.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)"},children:c.length})]}),(0,d.jsx)("div",{className:"flex-1 overflow-y-auto p-2",style:{minHeight:"80px"},children:0===c.length?(0,d.jsx)("div",{className:"flex items-center justify-center py-8 rounded-lg border border-dashed text-xs transition-colors",style:{borderColor:m?"var(--color-accent)":"var(--color-border)",color:m?"var(--color-accent)":"var(--color-text-muted)"},children:m?"Drop here":"No entries"}):c.map((a,b)=>(0,d.jsx)(j,{entry:a,fields:g,members:h,relationLabels:k,onEntryClick:l},i(a.entry_id)||String(b)))})]})}function n({objectName:a,fields:b,entries:c,statuses:g,members:h,relationLabels:l,onEntryClick:n,onRefresh:o}){let[p,q]=(0,e.useState)(null),[r,s]=(0,e.useState)(null),[t,u]=(0,e.useState)(c),v=(0,f.FR)((0,f.MS)(f.AN,{activationConstraint:{distance:5}})),w=(0,e.useMemo)(()=>{let a=b.find(a=>"enum"===a.type&&a.name.toLowerCase().includes("status"));return a||(b.find(a=>"enum"===a.type)??null)},[b]),x=(0,e.useMemo)(()=>{if(g.length>0)return g.map(a=>({name:a.name,color:a.color??"#94a3b8"}));if(w?.enum_values)return w.enum_values.map((a,b)=>({name:a,color:w.enum_colors?.[b]??"#94a3b8"}));let a=new Set;for(let b of t){let c=w?b[w.name]:void 0;c&&a.add(i(c))}return Array.from(a).map(a=>({name:a,color:"#94a3b8"}))},[g,w,t]),y=(0,e.useMemo)(()=>{let a={};for(let b of x)a[b.name]=[];for(let b of(a._ungrouped=[],t)){let c=w?i(b[w.name]):"";a[c]?a[c].push(b):a._ungrouped.push(b)}return a},[x,t,w]),z=b.filter(a=>a!==w),A=(0,e.useMemo)(()=>p?t.find(a=>String(a.entry_id)===p)??null:null,[p,t]),B=(0,e.useCallback)(a=>{q(String(a.active.id))},[]),C=(0,e.useCallback)(a=>{let b=a.over?.id?String(a.over.id):null;b?.startsWith("column:")?s(b.replace("column:","")):s(null)},[]),D=(0,e.useCallback)(async b=>{q(null),s(null);let{active:c,over:d}=b;if(!d||!w)return;let e=String(d.id);if(!e.startsWith("column:"))return;let f=e.replace("column:",""),g=String(c.id),h=t.find(a=>String(a.entry_id)===g);if(!h)return;let j=i(h[w.name]);if(j!==f){u(a=>a.map(a=>String(a.entry_id)===g?{...a,[w.name]:f}:a));try{(await fetch(`/api/workspace/objects/${encodeURIComponent(a)}/entries/${encodeURIComponent(g)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:{[w.name]:f}})})).ok?o?.():u(a=>a.map(a=>String(a.entry_id)===g?{...a,[w.name]:j}:a))}catch{u(a=>a.map(a=>String(a.entry_id)===g?{...a,[w.name]:j}:a))}}},[w,t,a,o]);return w?(0,d.jsxs)(f.Mp,{sensors:v,collisionDetection:f.y$,onDragStart:B,onDragOver:C,onDragEnd:D,children:[(0,d.jsxs)("div",{className:"flex gap-4 overflow-x-auto pb-4 px-1",style:{minHeight:"400px"},children:[x.map(b=>(0,d.jsx)(m,{columnName:b.name,color:b.color,items:y[b.name]??[],cardFields:z,members:h,relationLabels:l,onEntryClick:n,isOver:r===b.name,groupFieldId:w.id,objectName:a,onRefresh:o},b.name)),y._ungrouped?.length>0&&(0,d.jsxs)("div",{className:"flex-shrink-0 flex flex-col rounded-xl",style:{width:"280px",background:"var(--color-bg)",border:"1px dashed var(--color-border)"},children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b",style:{borderColor:"var(--color-border)"},children:[(0,d.jsx)("span",{className:"text-sm font-medium",style:{color:"var(--color-text-muted)"},children:"Ungrouped"}),(0,d.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)"},children:y._ungrouped.length})]}),(0,d.jsx)("div",{className:"flex-1 overflow-y-auto p-2",children:y._ungrouped.map((a,b)=>(0,d.jsx)(j,{entry:a,fields:z,members:h,relationLabels:l,onEntryClick:n},i(a.entry_id)||String(b)))})]})]}),(0,d.jsx)(f.Hd,{dropAnimation:null,children:A?(0,d.jsx)("div",{className:"rounded-lg p-3 shadow-xl",style:{width:"260px",background:"var(--color-surface)",border:"1px solid var(--color-accent)",transform:"rotate(2deg)"},children:(0,d.jsx)(k,{entry:A,fields:z,members:h,relationLabels:l})}):null})]}):(0,d.jsx)("div",{className:"flex flex-col items-center justify-center py-20 gap-3",children:(0,d.jsxs)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:["No enum field found for kanban grouping in"," ",(0,d.jsx)("span",{className:"font-medium",style:{color:"var(--color-text)"},children:a})]})})}},33873:a=>{"use strict";a.exports=require("path")},34487:(a,b,c)=>{"use strict";c.d(b,{f:()=>f});var d=c(2714),e=c(45722);function f(a,b,c){let f=(0,e.a)(a,c?.in);return isNaN(b)?(0,d.w)(c?.in||a,NaN):(b&&f.setDate(f.getDate()+b),f)}},35303:(a,b,c)=>{"use strict";c.d(b,{A:()=>d});let d=(0,c(15336).A)("file-text",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]])},35407:function(a,b){var c,d;"undefined"!=typeof self&&self,void 0===(d="function"==typeof(c=function(){function a(){}a.prototype.saveState=function(){return{idx:this.idx,input:this.input,groupIdx:this.groupIdx}},a.prototype.restoreState=function(a){this.idx=a.idx,this.input=a.input,this.groupIdx=a.groupIdx},a.prototype.pattern=function(a){this.idx=0,this.input=a,this.groupIdx=0,this.consumeChar("/");var b=this.disjunction();this.consumeChar("/");for(var c={type:"Flags",loc:{begin:this.idx,end:a.length},global:!1,ignoreCase:!1,multiLine:!1,unicode:!1,sticky:!1};this.isRegExpFlag();)switch(this.popChar()){case"g":h(c,"global");break;case"i":h(c,"ignoreCase");break;case"m":h(c,"multiLine");break;case"u":h(c,"unicode");break;case"y":h(c,"sticky")}if(this.idx!==this.input.length)throw Error("Redundant input: "+this.input.substring(this.idx));return{type:"Pattern",flags:c,value:b,loc:this.loc(0)}},a.prototype.disjunction=function(){var a=[],b=this.idx;for(a.push(this.alternative());"|"===this.peekChar();)this.consumeChar("|"),a.push(this.alternative());return{type:"Disjunction",value:a,loc:this.loc(b)}},a.prototype.alternative=function(){for(var a=[],b=this.idx;this.isTerm();)a.push(this.term());return{type:"Alternative",value:a,loc:this.loc(b)}},a.prototype.term=function(){return this.isAssertion()?this.assertion():this.atom()},a.prototype.assertion=function(){var a=this.idx;switch(this.popChar()){case"^":return{type:"StartAnchor",loc:this.loc(a)};case"$":return{type:"EndAnchor",loc:this.loc(a)};case"\\":switch(this.popChar()){case"b":return{type:"WordBoundary",loc:this.loc(a)};case"B":return{type:"NonWordBoundary",loc:this.loc(a)}}throw Error("Invalid Assertion Escape");case"(":switch(this.consumeChar("?"),this.popChar()){case"=":b="Lookahead";break;case"!":b="NegativeLookahead"}i(b);var b,c=this.disjunction();return this.consumeChar(")"),{type:b,value:c,loc:this.loc(a)}}throw Error("Internal Error - Should never get here!")},a.prototype.quantifier=function(a){var b=this.idx;switch(this.popChar()){case"*":c={atLeast:0,atMost:1/0};break;case"+":c={atLeast:1,atMost:1/0};break;case"?":c={atLeast:0,atMost:1};break;case"{":var c,d=this.integerIncludingZero();switch(this.popChar()){case"}":c={atLeast:d,atMost:d};break;case",":c=this.isDigit()?{atLeast:d,atMost:this.integerIncludingZero()}:{atLeast:d,atMost:1/0},this.consumeChar("}")}if(!0===a&&void 0===c)return;i(c)}if(!0!==a||void 0!==c)return i(c),"?"===this.peekChar(0)?(this.consumeChar("?"),c.greedy=!1):c.greedy=!0,c.type="Quantifier",c.loc=this.loc(b),c},a.prototype.atom=function(){var a,b=this.idx;switch(this.peekChar()){case".":a=this.dotAll();break;case"\\":a=this.atomEscape();break;case"[":a=this.characterClass();break;case"(":a=this.group()}return void 0===a&&this.isPatternCharacter()&&(a=this.patternCharacter()),i(a),a.loc=this.loc(b),this.isQuantifier()&&(a.quantifier=this.quantifier()),a},a.prototype.dotAll=function(){return this.consumeChar("."),{type:"Set",complement:!0,value:[f("\n"),f("\r"),f("\u2028"),f("\u2029")]}},a.prototype.atomEscape=function(){switch(this.consumeChar("\\"),this.peekChar()){case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":return this.decimalEscapeAtom();case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}},a.prototype.decimalEscapeAtom=function(){return{type:"GroupBackReference",value:this.positiveInteger()}},a.prototype.characterClassEscape=function(){var a,b=!1;switch(this.popChar()){case"d":a=j;break;case"D":a=j,b=!0;break;case"s":a=l;break;case"S":a=l,b=!0;break;case"w":a=k;break;case"W":a=k,b=!0}return i(a),{type:"Set",value:a,complement:b}},a.prototype.controlEscapeAtom=function(){var a;switch(this.popChar()){case"f":a=f("\f");break;case"n":a=f("\n");break;case"r":a=f("\r");break;case"t":a=f(" ");break;case"v":a=f("\v")}return i(a),{type:"Character",value:a}},a.prototype.controlLetterEscapeAtom=function(){this.consumeChar("c");var a=this.popChar();if(!1===/[a-zA-Z]/.test(a))throw Error("Invalid ");return{type:"Character",value:a.toUpperCase().charCodeAt(0)-64}},a.prototype.nulCharacterAtom=function(){return this.consumeChar("0"),{type:"Character",value:f("\0")}},a.prototype.hexEscapeSequenceAtom=function(){return this.consumeChar("x"),this.parseHexDigits(2)},a.prototype.regExpUnicodeEscapeSequenceAtom=function(){return this.consumeChar("u"),this.parseHexDigits(4)},a.prototype.identityEscapeAtom=function(){return{type:"Character",value:f(this.popChar())}},a.prototype.classPatternCharacterAtom=function(){switch(this.peekChar()){case"\n":case"\r":case"\u2028":case"\u2029":case"\\":case"]":throw Error("TBD");default:return{type:"Character",value:f(this.popChar())}}},a.prototype.characterClass=function(){var a=[],b=!1;for(this.consumeChar("["),"^"===this.peekChar(0)&&(this.consumeChar("^"),b=!0);this.isClassAtom();){var c=this.classAtom();if("Character"===c.type&&this.isRangeDash()){this.consumeChar("-");var d=this.classAtom();if("Character"===d.type){if(d.value<c.value)throw Error("Range out of order in character class");a.push({from:c.value,to:d.value})}else g(c.value,a),a.push(f("-")),g(d.value,a)}else g(c.value,a)}return this.consumeChar("]"),{type:"Set",complement:b,value:a}},a.prototype.classAtom=function(){switch(this.peekChar()){case"]":case"\n":case"\r":case"\u2028":case"\u2029":throw Error("TBD");case"\\":return this.classEscape();default:return this.classPatternCharacterAtom()}},a.prototype.classEscape=function(){switch(this.consumeChar("\\"),this.peekChar()){case"b":return this.consumeChar("b"),{type:"Character",value:f("\b")};case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}},a.prototype.group=function(){var a=!0;this.consumeChar("("),"?"===this.peekChar(0)?(this.consumeChar("?"),this.consumeChar(":"),a=!1):this.groupIdx++;var b=this.disjunction();this.consumeChar(")");var c={type:"Group",capturing:a,value:b};return a&&(c.idx=this.groupIdx),c},a.prototype.positiveInteger=function(){var a=this.popChar();if(!1===e.test(a))throw Error("Expecting a positive integer");for(;d.test(this.peekChar(0));)a+=this.popChar();return parseInt(a,10)},a.prototype.integerIncludingZero=function(){var a=this.popChar();if(!1===d.test(a))throw Error("Expecting an integer");for(;d.test(this.peekChar(0));)a+=this.popChar();return parseInt(a,10)},a.prototype.patternCharacter=function(){var a=this.popChar();switch(a){case"\n":case"\r":case"\u2028":case"\u2029":case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":throw Error("TBD");default:return{type:"Character",value:f(a)}}},a.prototype.isRegExpFlag=function(){switch(this.peekChar(0)){case"g":case"i":case"m":case"u":case"y":return!0;default:return!1}},a.prototype.isRangeDash=function(){return"-"===this.peekChar()&&this.isClassAtom(1)},a.prototype.isDigit=function(){return d.test(this.peekChar(0))},a.prototype.isClassAtom=function(a){switch(void 0===a&&(a=0),this.peekChar(a)){case"]":case"\n":case"\r":case"\u2028":case"\u2029":return!1;default:return!0}},a.prototype.isTerm=function(){return this.isAtom()||this.isAssertion()},a.prototype.isAtom=function(){if(this.isPatternCharacter())return!0;switch(this.peekChar(0)){case".":case"\\":case"[":case"(":return!0;default:return!1}},a.prototype.isAssertion=function(){switch(this.peekChar(0)){case"^":case"$":return!0;case"\\":switch(this.peekChar(1)){case"b":case"B":return!0;default:return!1}case"(":return"?"===this.peekChar(1)&&("="===this.peekChar(2)||"!"===this.peekChar(2));default:return!1}},a.prototype.isQuantifier=function(){var a=this.saveState();try{return void 0!==this.quantifier(!0)}catch(a){return!1}finally{this.restoreState(a)}},a.prototype.isPatternCharacter=function(){switch(this.peekChar()){case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":case"/":case"\n":case"\r":case"\u2028":case"\u2029":return!1;default:return!0}},a.prototype.parseHexDigits=function(a){for(var b="",d=0;d<a;d++){var e=this.popChar();if(!1===c.test(e))throw Error("Expecting a HexDecimal digits");b+=e}return{type:"Character",value:parseInt(b,16)}},a.prototype.peekChar=function(a){return void 0===a&&(a=0),this.input[this.idx+a]},a.prototype.popChar=function(){var a=this.peekChar(0);return this.consumeChar(),a},a.prototype.consumeChar=function(a){if(void 0!==a&&this.input[this.idx]!==a)throw Error("Expected: '"+a+"' but found: '"+this.input[this.idx]+"' at offset: "+this.idx);if(this.idx>=this.input.length)throw Error("Unexpected end of input");this.idx++},a.prototype.loc=function(a){return{begin:a,end:this.idx}};var b,c=/[0-9a-fA-F]/,d=/[0-9]/,e=/[1-9]/;function f(a){return a.charCodeAt(0)}function g(a,b){void 0!==a.length?a.forEach(function(a){b.push(a)}):b.push(a)}function h(a,b){if(!0===a[b])throw"duplicate flag "+b;a[b]=!0}function i(a){if(void 0===a)throw Error("Internal Error - Should never get here!")}var j=[];for(b=f("0");b<=f("9");b++)j.push(b);var k=[f("_")].concat(j);for(b=f("a");b<=f("z");b++)k.push(b);for(b=f("A");b<=f("Z");b++)k.push(b);var l=[f(" "),f("\f"),f("\n"),f("\r"),f(" "),f("\v"),f(" "),f("\xa0"),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f("\u2028"),f("\u2029"),f(" "),f(" "),f(" "),f("\uFEFF")];function m(){}return m.prototype.visitChildren=function(a){for(var b in a){var c=a[b];a.hasOwnProperty(b)&&(void 0!==c.type?this.visit(c):Array.isArray(c)&&c.forEach(function(a){this.visit(a)},this))}},m.prototype.visit=function(a){switch(a.type){case"Pattern":this.visitPattern(a);break;case"Flags":this.visitFlags(a);break;case"Disjunction":this.visitDisjunction(a);break;case"Alternative":this.visitAlternative(a);break;case"StartAnchor":this.visitStartAnchor(a);break;case"EndAnchor":this.visitEndAnchor(a);break;case"WordBoundary":this.visitWordBoundary(a);break;case"NonWordBoundary":this.visitNonWordBoundary(a);break;case"Lookahead":this.visitLookahead(a);break;case"NegativeLookahead":this.visitNegativeLookahead(a);break;case"Character":this.visitCharacter(a);break;case"Set":this.visitSet(a);break;case"Group":this.visitGroup(a);break;case"GroupBackReference":this.visitGroupBackReference(a);break;case"Quantifier":this.visitQuantifier(a)}this.visitChildren(a)},m.prototype.visitPattern=function(a){},m.prototype.visitFlags=function(a){},m.prototype.visitDisjunction=function(a){},m.prototype.visitAlternative=function(a){},m.prototype.visitStartAnchor=function(a){},m.prototype.visitEndAnchor=function(a){},m.prototype.visitWordBoundary=function(a){},m.prototype.visitNonWordBoundary=function(a){},m.prototype.visitLookahead=function(a){},m.prototype.visitNegativeLookahead=function(a){},m.prototype.visitCharacter=function(a){},m.prototype.visitSet=function(a){},m.prototype.visitGroup=function(a){},m.prototype.visitGroupBackReference=function(a){},m.prototype.visitQuantifier=function(a){},{RegExpParser:a,BaseRegExpVisitor:m,VERSION:"0.5.0"}})?c.apply(b,[]):c)||(a.exports=d)},35724:(a,b,c)=>{"use strict";c.d(b,{Gt:()=>e,PP:()=>h,WG:()=>f,uv:()=>g});var d=c(53037);let{schedule:e,cancel:f,state:g,steps:h}=(0,c(61081).I)("undefined"!=typeof requestAnimationFrame?requestAnimationFrame:d.l,!0)},36075:(a,b,c)=>{"use strict";function d(a){return"object"==typeof a&&null!==a}c.d(b,{G:()=>d})},36525:(a,b,c)=>{"use strict";c.d(b,{A:()=>l});var d=c(36927),e=c(15962),f=c(41579),g=c(96554);function h(){return(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M5 12h14"}),(0,d.jsx)("path",{d:"M12 5v14"})]})}function i(){return(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M16 3h5v5"}),(0,d.jsx)("path",{d:"m21 3-7 7"}),(0,d.jsx)("path",{d:"M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6"})]})}function j(){return(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function k(){return(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"1"}),(0,d.jsx)("circle",{cx:"5",cy:"12",r:"1"}),(0,d.jsx)("circle",{cx:"19",cy:"12",r:"1"})]})}function l({sessions:a,activeSessionId:b,activeSessionTitle:c,streamingSessionIds:l,subagents:m,activeSubagentKey:n,onSelectSession:o,onNewSession:p,onSelectSubagent:q,onDeleteSession:r,onRenameSession:s,onCollapse:t,mobile:u,onClose:v,width:w,loading:x=!1}){let[y,z]=(0,e.useState)(null),[A,B]=(0,e.useState)(null),[C,D]=(0,e.useState)(""),E=(0,e.useCallback)(a=>{o(a),v?.()},[o,v]),F=(0,e.useCallback)(a=>{q?.(a),v?.()},[q,v]),G=(0,e.useCallback)(a=>{r?.(a)},[r]),H=(0,e.useCallback)((a,b)=>{B(a),D(b||"")},[]),I=(0,e.useCallback)(()=>{A&&C.trim()&&s?.(A,C.trim()),B(null),D("")},[A,C,s]),J=(0,e.useMemo)(()=>{let a=new Map;if(!m)return a;for(let b of m){let c=a.get(b.parentSessionId);c||(c=[],a.set(b.parentSessionId,c)),c.push(b)}return a},[m]),K=function(a){let b=new Date,c=new Date(b.getFullYear(),b.getMonth(),b.getDate()).getTime(),d=c-864e5,e=c-6048e5,f=c-2592e6,g=[],h=[],i=[],j=[],k=[];for(let b of a){let a=b.updatedAt;a>=c?g.push(b):a>=d?h.push(b):a>=e?i.push(b):a>=f?j.push(b):k.push(b)}let l=[];return g.length>0&&l.push({label:"Today",sessions:g}),h.length>0&&l.push({label:"Yesterday",sessions:h}),i.length>0&&l.push({label:"This Week",sessions:i}),j.length>0&&l.push({label:"This Month",sessions:j}),k.length>0&&l.push({label:"Older",sessions:k}),l}((0,e.useMemo)(()=>a.filter(a=>!a.id.includes(":subagent:")),[a])),L=u?"280px":w??260,M=(0,d.jsx)("aside",{className:`flex flex-col h-full shrink-0 ${u?"drawer-right":"border-l"}`,style:{width:"number"==typeof L?`${L}px`:L,minWidth:"number"==typeof L?`${L}px`:L,borderColor:"var(--color-border)",background:"var(--color-sidebar-bg)"},children:(0,d.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[(0,d.jsx)("div",{className:"absolute inset-0 overflow-y-auto",style:{paddingTop:40},children:x&&0===a.length?(0,d.jsxs)("div",{className:"px-4 py-8 flex flex-col items-center justify-center min-h-[120px]",children:[(0,d.jsx)(f.V,{name:"braille",className:"text-xl mb-2",style:{color:"var(--color-text-muted)"}}),(0,d.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading…"})]}):0===a.length?(0,d.jsxs)("div",{className:"px-4 py-8 text-center",children:[(0,d.jsx)("div",{className:"mx-auto w-10 h-10 rounded-xl flex items-center justify-center mb-3",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:(0,d.jsx)(j,{})}),(0,d.jsxs)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["No conversations yet.",(0,d.jsx)("br",{}),"Start a new chat to begin."]})]}):(0,d.jsx)("div",{className:"px-2 py-1",children:K.map(a=>(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{className:"px-2 pt-3 pb-1 text-[10px] font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:a.label}),a.sessions.map(a=>{let c=a.id===b&&!n,e=a.id===y,h=l?.has(a.id)??!1,j=J.get(a.id);return(0,d.jsxs)("div",{className:"group relative",onMouseEnter:()=>z(a.id),onMouseLeave:()=>z(null),children:[(0,d.jsxs)("div",{className:"flex items-stretch w-full rounded-lg",style:{background:c?"var(--color-chat-sidebar-active-bg)":e?"var(--color-surface-hover)":"transparent"},children:[A===a.id?(0,d.jsx)("form",{className:"flex-1 min-w-0 px-2 py-1.5",onSubmit:a=>{a.preventDefault(),I()},children:(0,d.jsx)("input",{type:"text",value:C,onChange:a=>D(a.target.value),onBlur:I,onKeyDown:a=>{"Escape"===a.key&&(B(null),D(""))},autoFocus:!0,className:"w-full text-xs font-medium px-1 py-0.5 rounded outline-none border",style:{color:"var(--color-text)",background:"var(--color-surface)",borderColor:"var(--color-border)"}})}):(0,d.jsxs)("button",{type:"button",onClick:()=>E(a.id),className:"flex-1 min-w-0 text-left px-2 py-2 rounded-l-lg transition-colors cursor-pointer",children:[(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[h&&(0,d.jsx)(f.V,{name:"braille",className:"text-[10px] flex-shrink-0",style:{color:"var(--color-chat-sidebar-muted)"}}),(0,d.jsx)("div",{className:"text-xs font-medium truncate",style:{color:c?"var(--color-chat-sidebar-active-text)":"var(--color-text)"},children:a.title||"Untitled chat"})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",style:{paddingLeft:h?"calc(0.375rem + 6px)":void 0},children:[(0,d.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:function(a){let b=Math.floor((Date.now()-a)/1e3);if(b<60)return"just now";let c=Math.floor(b/60);if(c<60)return`${c}m ago`;let d=Math.floor(c/60);if(d<24)return`${d}h ago`;let e=Math.floor(d/24);if(e<30)return`${e}d ago`;let f=Math.floor(e/30);return f<12?`${f}mo ago`:`${Math.floor(f/12)}y ago`}(a.updatedAt)}),a.messageCount>0&&(0,d.jsxs)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:[a.messageCount," msg",1!==a.messageCount?"s":""]})]})]}),r&&(0,d.jsx)("div",{className:`shrink-0 flex items-center pr-1 transition-opacity ${e?"opacity-100":"opacity-0"}`,children:(0,d.jsxs)(g.rI,{children:[(0,d.jsx)(g.ty,{onClick:a=>a.stopPropagation(),className:"flex items-center justify-center w-6 h-6 rounded-md",style:{color:"var(--color-text-muted)"},title:"More options","aria-label":"More options",children:(0,d.jsx)(k,{})}),(0,d.jsxs)(g.SQ,{align:"end",side:"bottom",children:[(0,d.jsxs)(g._2,{onSelect:()=>H(a.id,a.title),children:[(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"})}),"Rename"]}),(0,d.jsxs)(g._2,{variant:"destructive",onSelect:()=>G(a.id),children:[(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M3 6h18"}),(0,d.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,d.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]}),"Delete"]})]})]})})]}),j&&j.length>0&&(0,d.jsx)("div",{className:"ml-4 border-l",style:{borderColor:"var(--color-border)"},children:j.map(a=>{let b=n===a.childSessionKey,c="running"===a.status,e=a.label||a.task,g=e.length>40?e.slice(0,40)+"...":e;return(0,d.jsx)("button",{type:"button",onClick:()=>F(a.childSessionKey),className:"w-full text-left pl-3 pr-2 py-1.5 rounded-r-lg transition-colors cursor-pointer",style:{background:b?"var(--color-chat-sidebar-active-bg)":"transparent"},children:(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[c&&(0,d.jsx)(f.V,{name:"braille",className:"text-[9px] flex-shrink-0",style:{color:"var(--color-chat-sidebar-muted)"}}),(0,d.jsx)(i,{}),(0,d.jsx)("span",{className:"text-[11px] truncate",style:{color:b?"var(--color-chat-sidebar-active-text)":"var(--color-text-muted)"},children:g})]})},a.childSessionKey)})})]},a.id)})]},a.label))})}),(0,d.jsxs)("div",{className:"absolute top-0 left-0 right-0 z-10 flex items-center justify-between border-b px-4 py-2 backdrop-blur-md",style:{height:40,borderColor:"var(--color-border)",background:"color-mix(in srgb, var(--color-sidebar-bg) 80%, transparent)"},children:[(0,d.jsxs)("div",{className:"min-w-0 flex-1 flex items-center gap-1.5",children:[t&&(0,d.jsx)("button",{type:"button",onClick:t,className:"p-1 rounded-md shrink-0 transition-colors hover:bg-black/5",style:{color:"var(--color-text-muted)"},title:"Hide chat sidebar (⌘⇧B)",children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,d.jsx)("path",{d:"M15 3v18"})]})}),(0,d.jsx)("span",{className:"text-xs font-medium truncate block",style:{color:"var(--color-text)"},children:"Chats"})]}),(0,d.jsxs)("button",{type:"button",onClick:p,className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium transition-colors cursor-pointer shrink-0 ml-1.5",style:{color:"var(--color-chat-sidebar-active-text)",background:"var(--color-chat-sidebar-active-bg)"},title:"New chat",children:[(0,d.jsx)(h,{}),"New"]})]})]})});return u?(0,d.jsx)("div",{className:"drawer-backdrop",onClick:()=>void v?.(),children:(0,d.jsx)("div",{onClick:a=>a.stopPropagation(),className:"fixed inset-y-0 right-0 z-50",children:M})}):M}},36747:(a,b,c)=>{"use strict";c.d(b,{Ch:()=>W});var d=c(36927),e=c(15962);function f(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function g(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function h(a){for(var b=1;b<arguments.length;b++){var c=null!=arguments[b]?arguments[b]:{};b%2?g(Object(c),!0).forEach(function(b){var d;d=c[b],b in a?Object.defineProperty(a,b,{value:d,enumerable:!0,configurable:!0,writable:!0}):a[b]=d}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(c)):g(Object(c)).forEach(function(b){Object.defineProperty(a,b,Object.getOwnPropertyDescriptor(c,b))})}return a}function i(a){return function b(){for(var c=this,d=arguments.length,e=Array(d),f=0;f<d;f++)e[f]=arguments[f];return e.length>=a.length?a.apply(this,e):function(){for(var a=arguments.length,d=Array(a),f=0;f<a;f++)d[f]=arguments[f];return b.apply(c,[].concat(e,d))}}}function j(a){return({}).toString.call(a).includes("Object")}function k(a){return"function"==typeof a}var l=i(function(a,b){throw Error(a[b]||a.default)})({initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"}),m={changes:function(a,b){return j(b)||l("changeType"),Object.keys(b).some(function(b){return!Object.prototype.hasOwnProperty.call(a,b)})&&l("changeField"),b},selector:function(a){k(a)||l("selectorType")},handler:function(a){k(a)||j(a)||l("handlerType"),j(a)&&Object.values(a).some(function(a){return!k(a)})&&l("handlersType")},initial:function(a){a||l("initialIsRequired"),j(a)||l("initialType"),Object.keys(a).length||l("initialContent")}};function n(a,b){return k(b)?b(a.current):b}function o(a,b){return a.current=h(h({},a.current),b),b}function p(a,b,c){return k(b)?b(a.current):Object.keys(c).forEach(function(c){var d;return null==(d=b[c])?void 0:d.call(b,a.current[c])}),c}var q={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:"Deprecation warning!\n You are using deprecated way of configuration.\n\n Instead of using\n monaco.config({ urls: { monacoBase: '...' } })\n use\n monaco.config({ paths: { vs: '...' } })\n\n For more please check the link https://github.com/suren-atoyan/monaco-loader#config\n "},r=(function(a){return function b(){for(var c=this,d=arguments.length,e=Array(d),f=0;f<d;f++)e[f]=arguments[f];return e.length>=a.length?a.apply(this,e):function(){for(var a=arguments.length,d=Array(a),f=0;f<a;f++)d[f]=arguments[f];return b.apply(c,[].concat(e,d))}}})(function(a,b){throw Error(a[b]||a.default)})(q),s=function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return function(a){return b.reduceRight(function(a,b){return b(a)},a)}},t={type:"cancelation",msg:"operation is manually canceled"};function u(a){var b=!1,c=new Promise(function(c,d){a.then(function(a){return b?d(t):c(a)}),a.catch(d)});return c.cancel=function(){return b=!0},c}var v=function(a,b){return function(a){if(Array.isArray(a))return a}(a)||function(a,b){var c=null==a?null:"undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(null!=c){var d,e,f,g,h=[],i=!0,j=!1;try{f=(c=c.call(a)).next,!1;for(;!(i=(d=f.call(c)).done)&&(h.push(d.value),h.length!==b);i=!0);}catch(a){j=!0,e=a}finally{try{if(!i&&null!=c.return&&(g=c.return(),Object(g)!==g))return}finally{if(j)throw e}}return h}}(a,2)||function(a,b){if(a){if("string"==typeof a)return f(a,b);var c=({}).toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?f(a,b):void 0}}(a,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(({create:function(a){var b=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};m.initial(a),m.handler(b);var c={current:a},d=i(p)(c,b),e=i(o)(c),f=i(m.changes)(a),g=i(n)(c);return[function(){var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(a){return a};return m.selector(a),a(c.current)},function(a){(function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return function(a){return b.reduceRight(function(a,b){return b(a)},a)}})(d,e,f,g)(a)}]}}).create({config:{paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}},isInitialized:!1,resolve:null,reject:null,monaco:null}),2),w=v[0],x=v[1];function y(a){return document.body.appendChild(a)}function z(a){var b,c,d=w(function(a){return{config:a.config,reject:a.reject}}),e=(b="".concat(d.config.paths.vs,"/loader.js"),c=document.createElement("script"),b&&(c.src=b),c);return e.onload=function(){return a()},e.onerror=d.reject,e}function A(){var a=w(function(a){return{config:a.config,resolve:a.resolve,reject:a.reject}}),b=window.require;b.config(a.config),b(["vs/editor/editor.main"],function(b){var c=b.m||b;B(c),a.resolve(c)},function(b){a.reject(b)})}function B(a){w().monaco||x({monaco:a})}var C=new Promise(function(a,b){return x({resolve:a,reject:b})}),D={init:function(){var a=w(function(a){return{monaco:a.monaco,isInitialized:a.isInitialized,resolve:a.resolve}});if(!a.isInitialized){if(x({isInitialized:!0}),a.monaco)return a.resolve(a.monaco),u(C);if(window.monaco&&window.monaco.editor)return B(window.monaco),a.resolve(window.monaco),u(C);s(y,z)(A)}return u(C)}},E={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},F={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},G=function({children:a}){return e.createElement("div",{style:F.container},a)},H=(0,e.memo)(function({width:a,height:b,isEditorReady:c,loading:d,_ref:f,className:g,wrapperProps:h}){return e.createElement("section",{style:{...E.wrapper,width:a,height:b},...h},!c&&e.createElement(G,null,d),e.createElement("div",{ref:f,style:{...E.fullWidth,...!c&&E.hide},className:g}))}),I=function(a){(0,e.useEffect)(a,[])},J=function(a,b,c=!0){let d=(0,e.useRef)(!0);(0,e.useEffect)(d.current||!c?()=>{d.current=!1}:a,b)};function K(){}function L(a,b,c,d){var e,f,g,h,i,j;return e=a,f=d,e.editor.getModel(M(e,f))||(g=a,h=b,i=c,j=d,g.editor.createModel(h,i,j?M(g,j):void 0))}function M(a,b){return a.Uri.parse(b)}(0,e.memo)(function({original:a,modified:b,language:c,originalLanguage:d,modifiedLanguage:f,originalModelPath:g,modifiedModelPath:h,keepCurrentOriginalModel:i=!1,keepCurrentModifiedModel:j=!1,theme:k="light",loading:l="Loading...",options:m={},height:n="100%",width:o="100%",className:p,wrapperProps:q={},beforeMount:r=K,onMount:s=K}){let[t,u]=(0,e.useState)(!1),[v,w]=(0,e.useState)(!0),x=(0,e.useRef)(null),y=(0,e.useRef)(null),z=(0,e.useRef)(null),A=(0,e.useRef)(s),B=(0,e.useRef)(r),C=(0,e.useRef)(!1);I(()=>{let a=D.init();return a.then(a=>(y.current=a)&&w(!1)).catch(a=>a?.type!=="cancelation"&&console.error("Monaco initialization: error:",a)),()=>{let b;return x.current?(b=x.current?.getModel(),void(i||b?.original?.dispose(),j||b?.modified?.dispose(),x.current?.dispose())):a.cancel()}}),J(()=>{if(x.current&&y.current){let b=x.current.getOriginalEditor(),e=L(y.current,a||"",d||c||"text",g||"");e!==b.getModel()&&b.setModel(e)}},[g],t),J(()=>{if(x.current&&y.current){let a=x.current.getModifiedEditor(),d=L(y.current,b||"",f||c||"text",h||"");d!==a.getModel()&&a.setModel(d)}},[h],t),J(()=>{let a=x.current.getModifiedEditor();a.getOption(y.current.editor.EditorOption.readOnly)?a.setValue(b||""):b!==a.getValue()&&(a.executeEdits("",[{range:a.getModel().getFullModelRange(),text:b||"",forceMoveMarkers:!0}]),a.pushUndoStop())},[b],t),J(()=>{x.current?.getModel()?.original.setValue(a||"")},[a],t),J(()=>{let{original:a,modified:b}=x.current.getModel();y.current.editor.setModelLanguage(a,d||c||"text"),y.current.editor.setModelLanguage(b,f||c||"text")},[c,d,f],t),J(()=>{y.current?.editor.setTheme(k)},[k],t),J(()=>{x.current?.updateOptions(m)},[m],t);let E=(0,e.useCallback)(()=>{if(!y.current)return;B.current(y.current);let e=L(y.current,a||"",d||c||"text",g||""),i=L(y.current,b||"",f||c||"text",h||"");x.current?.setModel({original:e,modified:i})},[c,b,f,a,d,g,h]),F=(0,e.useCallback)(()=>{!C.current&&z.current&&(x.current=y.current.editor.createDiffEditor(z.current,{automaticLayout:!0,...m}),E(),y.current?.editor.setTheme(k),u(!0),C.current=!0)},[m,k,E]);return(0,e.useEffect)(()=>{t&&A.current(x.current,y.current)},[t]),(0,e.useEffect)(()=>{v||t||F()},[v,t,F]),e.createElement(H,{width:o,height:n,isEditorReady:t,loading:l,_ref:z,className:p,wrapperProps:q})});var N=function(a){let b=(0,e.useRef)();return(0,e.useEffect)(()=>{b.current=a},[a]),b.current},O=new Map,P=(0,e.memo)(function({defaultValue:a,defaultLanguage:b,defaultPath:c,value:d,language:f,path:g,theme:h="light",line:i,loading:j="Loading...",options:k={},overrideServices:l={},saveViewState:m=!0,keepCurrentModel:n=!1,width:o="100%",height:p="100%",className:q,wrapperProps:r={},beforeMount:s=K,onMount:t=K,onChange:u,onValidate:v=K}){let[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(!0),A=(0,e.useRef)(null),B=(0,e.useRef)(null),C=(0,e.useRef)(null),E=(0,e.useRef)(t),F=(0,e.useRef)(s),G=(0,e.useRef)(),M=(0,e.useRef)(d),P=N(g),Q=(0,e.useRef)(!1),R=(0,e.useRef)(!1);I(()=>{let a=D.init();return a.then(a=>(A.current=a)&&z(!1)).catch(a=>a?.type!=="cancelation"&&console.error("Monaco initialization: error:",a)),()=>B.current?void(G.current?.dispose(),n?m&&O.set(g,B.current.saveViewState()):B.current.getModel()?.dispose(),B.current.dispose()):a.cancel()}),J(()=>{let e=L(A.current,a||d||"",b||f||"",g||c||"");e!==B.current?.getModel()&&(m&&O.set(P,B.current?.saveViewState()),B.current?.setModel(e),m&&B.current?.restoreViewState(O.get(g)))},[g],w),J(()=>{B.current?.updateOptions(k)},[k],w),J(()=>{B.current&&void 0!==d&&(B.current.getOption(A.current.editor.EditorOption.readOnly)?B.current.setValue(d):d!==B.current.getValue()&&(R.current=!0,B.current.executeEdits("",[{range:B.current.getModel().getFullModelRange(),text:d,forceMoveMarkers:!0}]),B.current.pushUndoStop(),R.current=!1))},[d],w),J(()=>{let a=B.current?.getModel();a&&f&&A.current?.editor.setModelLanguage(a,f)},[f],w),J(()=>{void 0!==i&&B.current?.revealLine(i)},[i],w),J(()=>{A.current?.editor.setTheme(h)},[h],w);let S=(0,e.useCallback)(()=>{if(!(!C.current||!A.current)&&!Q.current){F.current(A.current);let e=g||c,j=L(A.current,d||a||"",b||f||"",e||"");B.current=A.current?.editor.create(C.current,{model:j,automaticLayout:!0,...k},l),m&&B.current.restoreViewState(O.get(e)),A.current.editor.setTheme(h),void 0!==i&&B.current.revealLine(i),x(!0),Q.current=!0}},[a,b,c,d,f,g,k,l,m,h,i]);return(0,e.useEffect)(()=>{w&&E.current(B.current,A.current)},[w]),(0,e.useEffect)(()=>{y||w||S()},[y,w,S]),M.current=d,(0,e.useEffect)(()=>{w&&u&&(G.current?.dispose(),G.current=B.current?.onDidChangeModelContent(a=>{R.current||u(B.current.getValue(),a)}))},[w,u]),(0,e.useEffect)(()=>{if(w){let a=A.current.editor.onDidChangeMarkers(a=>{let b=B.current.getModel()?.uri;if(b&&a.find(a=>a.path===b.path)){let a=A.current.editor.getModelMarkers({resource:b});v?.(a)}});return()=>{a?.dispose()}}return()=>{}},[w,v]),e.createElement(H,{width:o,height:p,isEditorReady:w,loading:j,_ref:C,className:q,wrapperProps:r})}),Q=c(59448);let R={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",mjs:"javascript",cjs:"javascript",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",kt:"kotlin",swift:"swift",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",css:"css",scss:"scss",less:"less",html:"html",htm:"html",xml:"xml",svg:"xml",json:"json",jsonc:"json",yaml:"yaml",yml:"yaml",toml:"plaintext",md:"markdown",mdx:"markdown",sh:"shell",bash:"shell",zsh:"shell",fish:"shell",ps1:"powershell",sql:"sql",graphql:"graphql",gql:"graphql",dockerfile:"dockerfile",docker:"dockerfile",makefile:"plaintext",cmake:"plaintext",r:"r",lua:"lua",php:"php",vue:"html",svelte:"html",diff:"plaintext",patch:"plaintext",ini:"ini",env:"ini",tf:"plaintext",proto:"protobuf",zig:"plaintext",elixir:"plaintext",ex:"plaintext",erl:"plaintext",hs:"plaintext",scala:"scala",clj:"clojure",dart:"dart"};function S(a){let b=a.toLowerCase();return"dockerfile"===b||b.startsWith("dockerfile.")?"dockerfile":"makefile"===b||"gnumakefile"===b?"makefile":"cmakelists.txt"===b?"cmake":b.split(".").pop()??""}function T(a){return R[S(a)]??"plaintext"}let U=!1;function V(){return"undefined"!=typeof document&&document.documentElement.classList.contains("dark")}function W({content:a,filename:b,filePath:c,className:e}){let f=S(b);return"diff"===f||"patch"===f?(0,d.jsx)("div",{className:"max-w-4xl mx-auto px-6 py-8",children:(0,d.jsx)(Q.a,{diff:a})}):(0,d.jsx)(X,{content:a,filename:b,filePath:c,className:e})}function X({content:a,filename:b,filePath:c,className:f}){let g=(0,e.useRef)(null),h=(0,e.useRef)(null),[i,j]=(0,e.useState)(V()?"denchclaw-dark":"denchclaw-light"),[k,l]=(0,e.useState)("clean"),[m,n]=(0,e.useState)({line:1,col:1}),o=(0,e.useRef)(null),p=(0,e.useRef)(a),q=T(b),r=!!c,s=(0,e.useCallback)(async()=>{if(!c||!g.current)return;let a=g.current.getValue();l("saving");try{if(!(await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:c,content:a})})).ok)throw Error("Save failed");p.current=a,l("saved"),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>l("clean"),2e3)}catch{l("error"),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>l("dirty"),3e3)}},[c]),t=(0,e.useCallback)((a,b)=>{g.current=a,h.current=b,U||(U=!0,b.editor.defineTheme("denchclaw-light",{base:"vs",inherit:!0,rules:[],colors:{"editor.background":"#ffffff","editor.foreground":"#1c1c1a","editor.lineHighlightBackground":"#f5f4f1","editor.selectionBackground":"#2563eb20","editor.inactiveSelectionBackground":"#2563eb10","editorLineNumber.foreground":"#8a8a82","editorLineNumber.activeForeground":"#44443e","editorIndentGuide.background":"#00000010","editorIndentGuide.activeBackground":"#00000020","editor.selectionHighlightBackground":"#2563eb12","editorCursor.foreground":"#2563eb","editorWhitespace.foreground":"#00000010","editorBracketMatch.background":"#2563eb15","editorBracketMatch.border":"#2563eb40","editorGutter.background":"#ffffff","editorWidget.background":"#ffffff","editorWidget.border":"#00000014","editorSuggestWidget.background":"#ffffff","editorSuggestWidget.border":"#00000014","editorSuggestWidget.selectedBackground":"#f5f4f1","editorHoverWidget.background":"#ffffff","editorHoverWidget.border":"#00000014","input.background":"#f5f5f4","input.border":"#00000014","input.foreground":"#1c1c1a","minimap.background":"#ffffff","scrollbarSlider.background":"#00000012","scrollbarSlider.hoverBackground":"#00000020","scrollbarSlider.activeBackground":"#0000002a"}}),b.editor.defineTheme("denchclaw-dark",{base:"vs-dark",inherit:!0,rules:[],colors:{"editor.background":"#0c0c0b","editor.foreground":"#ececea","editor.lineHighlightBackground":"#1e1e1c","editor.selectionBackground":"#3b82f630","editor.inactiveSelectionBackground":"#3b82f618","editorLineNumber.foreground":"#78776f","editorLineNumber.activeForeground":"#b8b8b0","editorIndentGuide.background":"#ffffff08","editorIndentGuide.activeBackground":"#ffffff14","editor.selectionHighlightBackground":"#3b82f618","editorCursor.foreground":"#3b82f6","editorWhitespace.foreground":"#ffffff08","editorBracketMatch.background":"#3b82f620","editorBracketMatch.border":"#3b82f650","editorGutter.background":"#0c0c0b","editorWidget.background":"#161615","editorWidget.border":"#ffffff14","editorSuggestWidget.background":"#161615","editorSuggestWidget.border":"#ffffff14","editorSuggestWidget.selectedBackground":"#1e1e1c","editorHoverWidget.background":"#161615","editorHoverWidget.border":"#ffffff14","input.background":"#1e1e1c","input.border":"#ffffff14","input.foreground":"#ececea","minimap.background":"#0c0c0b","scrollbarSlider.background":"#ffffff12","scrollbarSlider.hoverBackground":"#ffffff20","scrollbarSlider.activeBackground":"#ffffff2a"}})),b.editor.setTheme(V()?"denchclaw-dark":"denchclaw-light"),a.addCommand(b.KeyMod.CtrlCmd|b.KeyCode.KeyS,()=>{s()}),a.onDidChangeCursorPosition(a=>{n({line:a.position.lineNumber,col:a.position.column})}),a.onDidChangeModelContent(()=>{a.getValue()!==p.current?l("dirty"):l("clean")}),a.focus()},[s]),u=function(a){let b=T(a);return"plaintext"===b?S(a)||"TEXT":b}(b),v=a.split("\n").length;return(0,d.jsxs)("div",{className:`flex flex-col h-full ${f??""}`,children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 flex-shrink-0",style:{background:"var(--color-surface)",borderBottom:"1px solid var(--color-border)"},children:[(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-text-muted)",flexShrink:0},children:[(0,d.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,d.jsx)("polyline",{points:"8 6 2 12 8 18"})]}),(0,d.jsx)("span",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:b}),"dirty"===k&&(0,d.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{background:"var(--color-text-muted)"},title:"Unsaved changes"}),(0,d.jsx)("div",{className:"flex-1"}),(0,d.jsx)("span",{className:"text-[11px] px-1.5 py-0.5 rounded font-medium",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:u.toUpperCase()}),(0,d.jsxs)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:[v," lines"]}),(0,d.jsxs)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:["Ln ",m.line,", Col ",m.col]}),r&&(0,d.jsxs)(d.Fragment,{children:["saving"===k&&(0,d.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:"Saving..."}),"saved"===k&&(0,d.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-success)"},children:"Saved"}),"error"===k&&(0,d.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-error)"},children:"Save failed"}),(0,d.jsx)("button",{type:"button",onClick:()=>void s(),disabled:"dirty"!==k,className:"text-[11px] px-2 py-0.5 rounded transition-colors",style:{background:"dirty"===k?"var(--color-accent)":"var(--color-surface-hover)",color:"dirty"===k?"#fff":"var(--color-text-muted)",cursor:"dirty"===k?"pointer":"default",opacity:"dirty"===k?1:.5},children:"Save"})]})]}),(0,d.jsx)("div",{className:"flex-1 min-h-0",children:(0,d.jsx)(P,{defaultValue:a,language:q,theme:i,onMount:t,loading:(0,d.jsx)("div",{className:"flex items-center justify-center h-full",style:{background:"var(--color-bg)"},children:(0,d.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Loading editor..."})}),options:{readOnly:!r,fontSize:13,lineHeight:20,fontFamily:"'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', Menlo, Monaco, 'Courier New', monospace",fontLigatures:!0,minimap:{enabled:!0,scale:1,showSlider:"mouseover"},scrollBeyondLastLine:!0,smoothScrolling:!0,cursorBlinking:"smooth",cursorSmoothCaretAnimation:"on",renderLineHighlight:"all",renderWhitespace:"selection",bracketPairColorization:{enabled:!0},guides:{bracketPairs:!0,indentation:!0,highlightActiveIndentation:!0},stickyScroll:{enabled:!0},folding:!0,foldingHighlight:!0,showFoldingControls:"mouseover",links:!0,wordWrap:"off",padding:{top:8,bottom:8},scrollbar:{verticalScrollbarSize:10,horizontalScrollbarSize:10,verticalSliderSize:10,horizontalSliderSize:10},overviewRulerBorder:!1,hideCursorInOverviewRuler:!0,automaticLayout:!0,tabSize:2,insertSpaces:!1,detectIndentation:!0,formatOnPaste:!1,formatOnType:!1,suggestOnTriggerCharacters:!0,quickSuggestions:!0,contextmenu:!0,mouseWheelZoom:!0,find:{addExtraSpaceOnTop:!1,autoFindInSelection:"multiline",seedSearchStringFromSelection:"selection"}}})})]})}},37519:(a,b,c)=>{let d=c(12089),{FormulaHelpers:e,Types:f}=c(28358);a.exports={ENCODEURL:a=>encodeURIComponent(e.accept(a,f.STRING)),FILTERXML:()=>{},WEBSERVICE:(a,b)=>{throw d.ERROR("WEBSERVICE is not supported in sync mode.")}}},37726:(a,b,c)=>{a.exports=c(543).uniqBy},37889:(a,b,c)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"});let d=c(53913),e=c(70016),f=c(30342),g=c(86975);b.iteratee=function(a){if(null==a)return d.identity;switch(typeof a){case"function":return a;case"object":if(Array.isArray(a)&&2===a.length)return g.matchesProperty(a[0],a[1]);return f.matches(a);case"string":case"symbol":case"number":return e.property(a)}}},38177:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.d(b,{X:()=>Q});var e=c(36927),f=c(42202),g=c(29415),h=c(15962),i=c(32206),j=c(90106),k=c(98790),l=c(62845),m=c(77317),n=c(53823),o=c(31038),p=c(35303),q=c(11916),r=c(64300),s=c(24939),t=c(55087),u=c(1784),v=c(42125),w=c(23932),x=c(25365),y=c(95786),z=c(11838),A=c(79833),B=c(51155),C=c(73432),D=c(42184),E=c(32314),F=c(41),G=c(45555),H=c(96554),I=c(41579),J=a([E]);E=(J.then?(await J)():J)[0];let O=[{id:"email-draft",label:"Draft an Email",icon:k.A,prompt:"Draft a professional follow-up email to a client after our initial meeting, thanking them and summarizing the next steps we discussed"},{id:"enrich-contacts",label:"Enrich Leads",icon:l.A,prompt:"When a new contact is added to my CRM, find their LinkedIn profile and company details and update the record"},{id:"invoice-reminder",label:"Invoice Reminder",icon:m.A,prompt:"Draft a friendly payment reminder email for an invoice that is 7 days overdue, including the invoice number and amount"},{id:"schedule-report",label:"Weekly Report",icon:n.A,prompt:"Set up a cron job that runs every Friday at 4pm to compile a summary of all completed tasks this week and email it to the team"},{id:"auto-tasks",label:"Auto Tasks",icon:o.A,prompt:"Create a workflow that automatically creates a task whenever someone mentions me in an email with a request or action item"},{id:"summarize-docs",label:"Summarize Docs",icon:p.A,prompt:"Read through all the documents in my workspace and create a concise summary of the key information across all files"},{id:"query-data",label:"Query Database",icon:q.A,prompt:"Connect to my database and show me the top 10 customers by revenue this quarter, including their contact details"},{id:"code-review",label:"Review Code",icon:r.A,prompt:"Review the code in my workspace for potential bugs, security issues, and performance improvements. Prioritize critical findings"},{id:"debug-error",label:"Debug Error",icon:s.A,prompt:"Help me debug this error I'm seeing in production. Walk me through the likely causes and how to fix each one"},{id:"daily-digest",label:"Daily Digest",icon:t.A,prompt:"Set up a daily digest that runs every morning at 9am summarizing my unread emails, calendar events, and pending tasks"},{id:"analyze-csv",label:"Analyze Data",icon:u.A,prompt:"Analyze the CSV file in my workspace — find trends, outliers, and generate a visual report with key insights"},{id:"write-content",label:"Write Content",icon:v.A,prompt:"Write a compelling blog post about how AI automation is transforming small business operations in 2026"},{id:"web-research",label:"Web Research",icon:w.A,prompt:"Research the top 5 competitors in my industry and create a comparison table with their pricing, features, and market position"},{id:"search-files",label:"Search Files",icon:x.A,prompt:"Search through all files in my workspace and find every mention of customer feedback, complaints, or feature requests"},{id:"brainstorm",label:"Brainstorm Ideas",icon:y.A,prompt:"Help me brainstorm 10 creative marketing campaign ideas for launching a new product to our existing customer base"},{id:"organize-files",label:"Organize Files",icon:z.A,prompt:"Look at all the files in my workspace and suggest a better folder structure. Then reorganize them for me"},{id:"create-spreadsheet",label:"Build Spreadsheet",icon:A.A,prompt:"Create a project tracking spreadsheet with columns for task name, assignee, status, priority, due date, and notes"},{id:"ai-strategy",label:"AI Strategy",icon:B.A,prompt:"Help me create an AI adoption strategy for my team — which tasks should we automate first for the biggest impact?"},{id:"meeting-prep",label:"Meeting Prep",icon:C.A,prompt:"Prepare a briefing document for my upcoming client meeting. Include their recent activity, open issues, and talking points"},{id:"build-workflow",label:"Build Workflow",icon:D.A,prompt:"Design an automated onboarding workflow for new clients — from welcome email to document collection to account setup"}];function K(a){let b=a.split(".").pop()?.toLowerCase()??"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(b)?"image":["mp4","webm","mov","avi","mkv","flv"].includes(b)?"video":["mp3","wav","ogg","aac","flac","m4a"].includes(b)?"audio":"pdf"===b?"pdf":["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(b)?"code":["doc","docx","xls","xlsx","ppt","pptx","txt","rtf","csv","pages","numbers","key"].includes(b)?"document":"other"}let P={image:{bg:"rgba(16, 185, 129, 0.12)",fg:"#10b981"},video:{bg:"rgba(139, 92, 246, 0.12)",fg:"#8b5cf6"},audio:{bg:"rgba(245, 158, 11, 0.12)",fg:"#f59e0b"},pdf:{bg:"rgba(239, 68, 68, 0.12)",fg:"#ef4444"},code:{bg:"rgba(59, 130, 246, 0.12)",fg:"#3b82f6"},document:{bg:"rgba(107, 114, 128, 0.12)",fg:"#6b7280"},other:{bg:"rgba(107, 114, 128, 0.08)",fg:"#9ca3af"}};function L({category:a}){let b={width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};switch(a){case"image":return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,e.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,e.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});case"video":return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"}),(0,e.jsx)("rect",{x:"2",y:"6",width:"14",height:"12",rx:"2"})]});case"audio":return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,e.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,e.jsx)("circle",{cx:"18",cy:"16",r:"3"})]});case"pdf":return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,e.jsx)("path",{d:"M14 2v6h6"}),(0,e.jsx)("path",{d:"M10 13h4"}),(0,e.jsx)("path",{d:"M10 17h4"})]});case"code":return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,e.jsx)("polyline",{points:"8 6 2 12 8 18"})]});case"document":return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,e.jsx)("path",{d:"M14 2v6h6"}),(0,e.jsx)("path",{d:"M16 13H8"}),(0,e.jsx)("path",{d:"M16 17H8"}),(0,e.jsx)("path",{d:"M10 9H8"})]});default:return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,e.jsx)("path",{d:"M14 2v6h6"})]})}}function M({msg:a,idx:b,onEdit:c,onSendNow:d,onRemove:f}){let[g,i]=(0,h.useState)(!1),[j,k]=(0,h.useState)(a.text),l=(0,h.useRef)(null),m=()=>{let b=j.trim();b&&b!==a.text?c(a.id,b):k(a.text),i(!1)};return(0,e.jsxs)("div",{className:`flex items-start gap-2.5 group py-2 ${b>0?"border-t":""}`,style:b>0?{borderColor:"var(--color-border)"}:void 0,children:[(0,e.jsx)("span",{className:"shrink-0 mt-px text-[11px] font-medium tabular-nums w-4",style:{color:"var(--color-text-muted)"},children:b+1}),g?(0,e.jsx)("textarea",{ref:l,className:"flex-1 text-[13px] leading-[1.45] min-w-0 resize-none rounded-md px-2 py-1 outline-none",style:{color:"var(--color-text-secondary)",background:"var(--color-bg)",border:"1px solid var(--color-border)"},rows:1,value:j,onChange:a=>{k(a.target.value);let b=l.current;b&&(b.style.height="auto",b.style.height=`${b.scrollHeight}px`)},onBlur:m,onKeyDown:b=>{"Enter"!==b.key||b.shiftKey||(b.preventDefault(),m()),"Escape"===b.key&&(k(a.text),i(!1))}}):(0,e.jsxs)("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[a.attachedFiles.length>0&&(0,e.jsx)("div",{className:"flex gap-1 shrink-0",children:a.attachedFiles.map(a=>{let b=K(a.name),c="image"===b?a.localUrl||`/api/workspace/raw-file?path=${encodeURIComponent(a.path)}`:a.path?`/api/workspace/thumbnail?path=${encodeURIComponent(a.path)}&size=100`:void 0;return(0,e.jsx)("img",{src:c,alt:a.name,className:"rounded object-cover",style:{height:28,width:28,background:"var(--color-surface-hover)"},onError:a=>{a.currentTarget.style.display="none"}},a.id)})}),(0,e.jsx)("p",{className:"text-[13px] leading-[1.45] line-clamp-1 min-w-0",style:{color:"var(--color-text-secondary)"},children:a.text||`${a.attachedFiles.length} ${1===a.attachedFiles.length?"file":"files"}`})]}),!g&&(0,e.jsxs)("div",{className:"flex items-center gap-1 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,e.jsx)("button",{type:"button",className:"rounded-md p-1 transition-colors hover:bg-stone-100 dark:hover:bg-stone-800",title:"Edit message",onClick:()=>{k(a.text),i(!0)},children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-stone-400",children:[(0,e.jsx)("path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),(0,e.jsx)("path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"})]})}),(0,e.jsx)("button",{type:"button",className:"rounded-md p-1 transition-colors hover:bg-stone-100 dark:hover:bg-stone-800",title:"Send now",onClick:()=>d(a.id),children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-stone-400",children:[(0,e.jsx)("path",{d:"M12 19V5"}),(0,e.jsx)("path",{d:"m5 12 7-7 7 7"})]})}),(0,e.jsx)("button",{type:"button",className:"rounded-md p-1 transition-colors hover:bg-stone-100 dark:hover:bg-stone-800",title:"Remove from queue",onClick:()=>f(a.id),children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-stone-400",children:[(0,e.jsx)("path",{d:"M3 6h18"}),(0,e.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,e.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]})})]})]})}function N({files:a,compact:b,onRemove:c,onClearAll:d}){return 0===a.length?null:(0,e.jsx)("div",{className:`${b?"px-2":"px-3"} pt-2`,children:(0,e.jsx)("div",{className:"flex gap-2 overflow-x-auto pb-1",style:{scrollbarWidth:"thin"},children:a.map(a=>{let b=K(a.name),d=P[b]??P.other,f=a.path.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Z]:\\Users\\[^\\]+/,"~");return(0,e.jsxs)("div",{className:"relative group flex-shrink-0 rounded-xl overflow-hidden",style:{background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:[(0,e.jsx)("button",{type:"button",onClick:()=>c(a.id),className:"absolute top-1 right-1 z-10 w-[18px] h-[18px] rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",style:{background:"rgba(0,0,0,0.55)",color:"white",backdropFilter:"blur(4px)"},children:(0,e.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:[(0,e.jsx)("path",{d:"M18 6 6 18"}),(0,e.jsx)("path",{d:"m6 6 12 12"})]})}),"image"===b?(0,e.jsx)("img",{src:a.localUrl||`/api/workspace/raw-file?path=${encodeURIComponent(a.path)}`,alt:a.name,className:"block rounded-xl object-cover",style:{height:80,width:"auto",minWidth:60,maxWidth:140,opacity:a.uploading?.6:1,background:"var(--color-bg-secondary)"},onError:a=>{a.currentTarget.style.display="none"}}):"pdf"===b&&a.path?(0,e.jsx)("img",{src:`/api/workspace/thumbnail?path=${encodeURIComponent(a.path)}&size=200`,alt:a.name,className:"block rounded-xl object-cover",style:{height:80,width:"auto",minWidth:60,maxWidth:140,opacity:a.uploading?.6:1,background:"var(--color-bg-secondary)"},onError:a=>{a.currentTarget.style.display="none"}}):(0,e.jsxs)("div",{className:"flex items-center gap-2.5 px-3 py-2.5",style:{opacity:a.uploading?.6:1},children:[(0,e.jsx)("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0",style:{background:d.bg,color:d.fg},children:(0,e.jsx)(L,{category:b})}),(0,e.jsxs)("div",{className:"min-w-0 max-w-[140px]",children:[(0,e.jsx)("p",{className:"text-[11px] font-medium truncate",style:{color:"var(--color-text)"},title:a.path||a.name,children:a.name}),(0,e.jsx)("p",{className:"text-[9px] truncate",style:{color:"var(--color-text-muted)"},title:a.path||a.name,children:a.uploading?"Uploading...":f})]})]})]},a.id)})})})}let Q=(0,h.forwardRef)(function({fileContext:a,compact:b,sessionTitle:c,initialSessionId:d,onFileChanged:k,onActiveSessionChange:l,onSessionsChange:m,onSubagentSpawned:n,onSubagentClick:o,onFilePathClick:p,onDeleteSession:q,onRenameSession:r,sessionKey:s,subagentTask:t,subagentLabel:u,onBack:v},w){let x=!!s,y=(0,h.useRef)(null),[z,A]=(0,h.useState)(!0),[B,C]=(0,h.useState)(null),[D,J]=(0,h.useState)(!1),K=(0,h.useRef)(null),[L,P]=(0,h.useState)([]),[Q,R]=(0,h.useState)(!1),[S,T]=(0,h.useState)(!1),U=(0,h.useRef)(null),V=(0,h.useRef)(new Set),W=(0,h.useRef)(!1),X=(0,h.useRef)(!0),[Y,Z]=(0,h.useState)([]),_=(0,h.useRef)(new Map),aa=(0,h.useRef)(null),[ab,ac]=(0,h.useState)([]),[ad,ae]=(0,h.useState)(!1),[af,ag]=(0,h.useState)(""),[ah,ai]=(0,h.useState)([]);(0,h.useEffect)(()=>{let a=[(()=>{let a=new Date().getHours();return a<12?"Good morning!":a<17?"Good afternoon!":"Good evening!"})(),"Ready to build?","Let's automate something?","What shall we tackle?","Ready to get things done?","Let's get to work?","How can I help?"];ag(a[Math.floor(Math.random()*a.length)])},[]),(0,h.useEffect)(()=>{let a=[...O].sort(()=>.5-Math.random());ai(a.slice(0,7))},[]);let aj=(0,h.useCallback)(a=>{let b=O.find(b=>b.id===a);b&&(y.current?.setText(b.prompt),A(!1))},[]),ak=a?.path??null,al=(0,h.useRef)(null);(0,h.useEffect)(()=>{al.current=B},[B]);let am=(0,h.useRef)(s);(0,h.useEffect)(()=>{am.current=s},[s]);let an=(0,h.useMemo)(()=>new g.rL({api:"/api/chat",body:()=>{let a={},b=am.current;b&&(a.sessionKey=b);let c=al.current;return c&&(a.sessionId=c),aa.current&&(a.userHtml=aa.current,aa.current=null),a}}),[]),{messages:ao,sendMessage:ap,status:aq,stop:ar,error:as,setMessages:at}=(0,f.Y_)({transport:an}),au="streaming"===aq||"submitted"===aq||S,av=(0,h.useRef)(null),aw=(0,h.useRef)(!1),ax=(0,h.useRef)(0);(0,h.useEffect)(()=>{let a=av.current;if(!a)return;let b=()=>{aw.current=a.scrollHeight-a.scrollTop-a.clientHeight>80};return a.addEventListener("scroll",b,{passive:!0}),()=>a.removeEventListener("scroll",b)},[]),(0,h.useEffect)(()=>{!aw.current&&(ax.current||(ax.current=requestAnimationFrame(()=>{ax.current=0,K.current?.scrollIntoView({behavior:"smooth"})})))},[ao]);let ay=(0,h.useCallback)(async a=>{let b={title:a};ak&&(b.filePath=ak);let c=await fetch("/api/web-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)});return(await c.json()).session.id},[ak]),az=(0,h.useCallback)(async(a,b,c)=>{let d=new AbortController;U.current=d;try{let e=c?.sessionKey?`sessionKey=${encodeURIComponent(c.sessionKey)}`:`sessionId=${encodeURIComponent(a)}`,f=await fetch(`/api/chat/stream?${e}`,{signal:d.signal});if(!f.ok||!f.body)return!1;if("false"===f.headers.get("X-Run-Active"))return f.body.cancel(),!1;T(!0);let g=function(){let a=[],b=-1,c=-1;return{processEvent:function(d){switch(d.type){case"user-message":b=-1,c=-1,a.push({type:"user-message",id:d.id,text:d.text??""});break;case"reasoning-start":a.push({type:"reasoning",text:"",state:"streaming"}),c=a.length-1;break;case"reasoning-delta":if(c>=0){let b=a[c];b.text+=d.delta}break;case"reasoning-end":if(c>=0){let b=a[c];delete b.state}c=-1;break;case"text-start":a.push({type:"text",text:""}),b=a.length-1;break;case"text-delta":if(b>=0){let c=a[b];c.text+=d.delta}break;case"text-end":b=-1;break;case"tool-input-start":a.push({type:"dynamic-tool",toolCallId:d.toolCallId,toolName:d.toolName,state:"input-available",input:{}});break;case"tool-input-available":for(let b=a.length-1;b>=0;b--){let c=a[b];if("dynamic-tool"===c.type&&c.toolCallId===d.toolCallId){c.input=d.input??{};break}}break;case"tool-output-partial":for(let b=a.length-1;b>=0;b--){let c=a[b];if("dynamic-tool"===c.type&&c.toolCallId===d.toolCallId){c.output=d.output??{};break}}break;case"tool-output-available":for(let b=a.length-1;b>=0;b--){let c=a[b];if("dynamic-tool"===c.type&&c.toolCallId===d.toolCallId){c.state="output-available",c.output=d.output??{};break}}break;case"tool-output-error":for(let b=a.length-1;b>=0;b--){let c=a[b];if("dynamic-tool"===c.type&&c.toolCallId===d.toolCallId){c.state="error",c.output={error:d.errorText};break}}}},getParts:()=>a.map(a=>({...a}))}}(),h=f.body.getReader(),i=new TextDecoder,j=`reconnect-${a}`,k="",l=!1,m=()=>{if(d.signal.aborted)return;let a={id:j,role:"assistant",parts:g.getParts()};at([...b,a])};for(;;){let a,{done:b,value:c}=await h.read();if(b)break;for(k+=i.decode(c,{stream:!0});-1!==(a=k.indexOf("\n\n"));){let b=k.slice(0,a);if(k=k.slice(a+2),b.startsWith("data: "))try{let a=JSON.parse(b.slice(6));g.processEvent(a)}catch{}}l||(l=!0,requestAnimationFrame(()=>{l=!1,m()}))}if(m(),!d.signal.aborted){for(let a of b)V.current.add(a.id);V.current.add(j)}return T(!1),U.current=null,!0}catch(a){return"AbortError"!==a.name&&console.error("Reconnection error:",a),T(!1),U.current=null,!1}},[at]),aA=(0,h.useRef)(null);aA.current=async()=>{if(!ak)return[];try{let a=await fetch(`/api/web-sessions?filePath=${encodeURIComponent(ak)}`);return(await a.json()).sessions||[]}catch{return[]}},(0,h.useEffect)(()=>{if(!ak||x)return;let a=!1;return al.current=null,C(null),l?.(null),at([]),V.current.clear(),X.current=!0,(async()=>{let b=await aA.current?.()??[];if(!a&&(Z(b),b.length>0)){let c=(d?b.find(a=>a.id===d):void 0)??b[0];C(c.id),al.current=c.id,l?.(c.id),X.current=!1;try{let b=await fetch(`/api/web-sessions/${c.id}`);if(a)return;let d=(await b.json()).messages||[],e=d.some(a=>a._streaming)?d.filter(a=>!a._streaming):d;for(let a of e)"user"===a.role&&a.html&&_.current.set(a.id,a.html);let f=e.map(a=>(V.current.add(a.id),{id:a.id,role:a.role,parts:a.parts??[{type:"text",text:a.content}]}));a||at(f),a||await az(c.id,f)}catch{}}})(),()=>{a=!0}},[ak,az]);let aB=(0,h.useRef)(!1);(0,h.useEffect)(()=>{ak||x||!d||aB.current||(aB.current=!0,aI(d))},[]),(0,h.useEffect)(()=>{if(!s||!t)return;let a=!1;U.current?.abort(),ar(),V.current.clear(),ac([]);let b={id:`task-${s}`,role:"user",parts:[{type:"text",text:t}]};return at([b]),(async()=>{if(a)return;let c=[b];try{let d=await fetch(`/api/web-sessions/${encodeURIComponent(s)}`);if(a)return;if(d.ok){let e=(await d.json()).messages||[],f=e.some(a=>a._streaming)?e.filter(a=>!a._streaming):e;if(f.length>0){for(let a of f)"user"===a.role&&a.html&&_.current.set(a.id,a.html);let d=f.map(a=>(V.current.add(a.id),{id:a.id,role:a.role,parts:a.parts??[{type:"text",text:a.content}]}));c=[b,...d],a||at(c)}}}catch{}a||await az(s,c,{sessionKey:s})})(),()=>{a=!0,U.current?.abort()}},[s,t,az]);let[aC,aD]=(0,h.useState)(!1);(0,h.useEffect)(()=>{if(!B||!n)return;let a=!1,b=async()=>{try{let b=await fetch(`/api/chat/subagents?sessionId=${encodeURIComponent(B)}`);if(a||!b.ok)return;let c=(await b.json()).subagents??[],d=!1;for(let a of c)"running"===a.status&&(d=!0),n({childSessionKey:a.sessionKey,runId:a.runId,task:a.task,label:a.label,parentSessionId:B,status:a.status});a||aD(d)}catch{}};b();let c=setInterval(b,3e3);return()=>{a=!0,clearInterval(c)}},[B,n]);let aE=(0,h.useRef)(aq);(0,h.useEffect)(()=>{let a="streaming"===aE.current||"submitted"===aE.current,b="ready"===aq;if(a&&b&&B){for(let a of ao)V.current.add(a.id);ak&&aA.current?.().then(a=>{Z(a)}),ak&&k&&fetch(`/api/workspace/file?path=${encodeURIComponent(ak)}`).then(a=>a.json()).then(a=>{a.content&&k(a.content)}).catch(()=>{}),m?.()}aE.current=aq},[aq,ao,B,ak,k,m]);let aF=(0,h.useRef)(()=>{}),aG=(0,h.useCallback)(async(b,c,d,e)=>{let f=b.trim().length>0,g=c.length>0,h=e?e.filter(a=>!a.uploading&&a.path):L.filter(a=>!a.uploading&&a.path),i=h.length>0;if(!f&&!g&&!i)return;let j=b.trim(),k=[...h];if("/new"===j.toLowerCase()){for(let a of L)a.localUrl&&URL.revokeObjectURL(a.localUrl);P([]),aF.current();return}if(au){e||P([]),ac(a=>[...a,{id:crypto.randomUUID(),text:j,html:d,mentionedFiles:c,attachedFiles:k,createdAt:Date.now()}]);return}if(!e&&k.length>0){for(let a of L)a.localUrl&&URL.revokeObjectURL(a.localUrl);P([])}let n=B;if(!n&&!x){let a=j||"File attachment",b=a.length>60?a.slice(0,60)+"...":a;n=await ay(b),C(n),al.current=n,l?.(n),m?.(),ak&&aA.current?.().then(a=>{Z(a)})}let o=j,p=[...c.map(a=>a.path),...k.map(a=>a.path)];if(p.length>0){let a=`[Attached files: ${p.join(", ")}]`;o=o?`${a}
135
+ `)},flush(a){a.enqueue("data: [DONE]\n\n")}})}});var lL=ko(()=>kr(hz([hw({type:hU("text-start"),id:f9(),providerMetadata:lp.optional()}),hw({type:hU("text-delta"),id:f9(),delta:f9(),providerMetadata:lp.optional()}),hw({type:hU("text-end"),id:f9(),providerMetadata:lp.optional()}),hw({type:hU("error"),errorText:f9()}),hw({type:hU("tool-input-start"),toolCallId:f9(),toolName:f9(),providerExecuted:g5().optional(),providerMetadata:lp.optional(),dynamic:g5().optional(),title:f9().optional()}),hw({type:hU("tool-input-delta"),toolCallId:f9(),inputTextDelta:f9()}),hw({type:hU("tool-input-available"),toolCallId:f9(),toolName:f9(),input:hk(),providerExecuted:g5().optional(),providerMetadata:lp.optional(),dynamic:g5().optional(),title:f9().optional()}),hw({type:hU("tool-input-error"),toolCallId:f9(),toolName:f9(),input:hk(),providerExecuted:g5().optional(),providerMetadata:lp.optional(),dynamic:g5().optional(),errorText:f9(),title:f9().optional()}),hw({type:hU("tool-approval-request"),approvalId:f9(),toolCallId:f9()}),hw({type:hU("tool-output-available"),toolCallId:f9(),output:hk(),providerExecuted:g5().optional(),dynamic:g5().optional(),preliminary:g5().optional()}),hw({type:hU("tool-output-error"),toolCallId:f9(),errorText:f9(),providerExecuted:g5().optional(),dynamic:g5().optional()}),hw({type:hU("tool-output-denied"),toolCallId:f9()}),hw({type:hU("reasoning-start"),id:f9(),providerMetadata:lp.optional()}),hw({type:hU("reasoning-delta"),id:f9(),delta:f9(),providerMetadata:lp.optional()}),hw({type:hU("reasoning-end"),id:f9(),providerMetadata:lp.optional()}),hw({type:hU("source-url"),sourceId:f9(),url:f9(),title:f9().optional(),providerMetadata:lp.optional()}),hw({type:hU("source-document"),sourceId:f9(),mediaType:f9(),title:f9(),filename:f9().optional(),providerMetadata:lp.optional()}),hw({type:hU("file"),url:f9(),mediaType:f9(),providerMetadata:lp.optional()}),hw({type:iy(a=>"string"==typeof a&&a.startsWith("data-"),{message:'Type must start with "data-"'}),id:f9().optional(),data:hk(),transient:g5().optional()}),hw({type:hU("start-step")}),hw({type:hU("finish-step")}),hw({type:hU("start"),messageId:f9().optional(),messageMetadata:hk().optional()}),hw({type:hU("finish"),finishReason:hR(["stop","length","content-filter","tool-calls","error","other"]).optional(),messageMetadata:hk().optional()}),hw({type:hU("abort"),reason:f9().optional()}),hw({type:hU("message-metadata"),messageMetadata:hk()})])));function lM(a){return a.type.startsWith("tool-")}function lN(a){return"dynamic-tool"===a.type}function lO(a){return lM(a)||lN(a)}function lP(a){return a.type.split("-").slice(1).join("-")}function lQ({lastMessage:a,messageId:b}){return{message:(null==a?void 0:a.role)==="assistant"?a:{id:b,metadata:void 0,role:"assistant",parts:[]},activeTextParts:{},activeReasoningParts:{},partialToolCalls:{}}}function lR({stream:a,messageMetadataSchema:b,dataPartSchemas:c,runUpdateMessageJob:d,onError:e,onToolCall:f,onData:g}){return a.pipeThrough(new TransformStream({async transform(a,h){await d(async({state:d,write:i})=>{var j,k,l,m;function n(a){let b=d.message.parts.filter(lO).find(b=>b.toolCallId===a);if(null==b)throw new k8({chunkType:"tool-invocation",chunkId:a,message:`No tool invocation found for tool call ID "${a}".`});return b}function o(a){var b;let c=d.message.parts.find(b=>lM(b)&&b.toolCallId===a.toolCallId);null!=c?(c.state=a.state,c.input=a.input,c.output=a.output,c.errorText=a.errorText,c.rawInput=a.rawInput,c.preliminary=a.preliminary,void 0!==a.title&&(c.title=a.title),c.providerExecuted=null!=(b=a.providerExecuted)?b:c.providerExecuted,null!=a.providerMetadata&&(c.callProviderMetadata=a.providerMetadata)):d.message.parts.push({type:`tool-${a.toolName}`,toolCallId:a.toolCallId,state:a.state,title:a.title,input:a.input,output:a.output,rawInput:a.rawInput,errorText:a.errorText,providerExecuted:a.providerExecuted,preliminary:a.preliminary,...null!=a.providerMetadata?{callProviderMetadata:a.providerMetadata}:{}})}function p(a){var b,c;let e=d.message.parts.find(b=>"dynamic-tool"===b.type&&b.toolCallId===a.toolCallId);null!=e?(e.state=a.state,e.toolName=a.toolName,e.input=a.input,e.output=a.output,e.errorText=a.errorText,e.rawInput=null!=(b=a.rawInput)?b:e.rawInput,e.preliminary=a.preliminary,void 0!==a.title&&(e.title=a.title),e.providerExecuted=null!=(c=a.providerExecuted)?c:e.providerExecuted,null!=a.providerMetadata&&(e.callProviderMetadata=a.providerMetadata)):d.message.parts.push({type:"dynamic-tool",toolName:a.toolName,toolCallId:a.toolCallId,state:a.state,input:a.input,output:a.output,errorText:a.errorText,preliminary:a.preliminary,providerExecuted:a.providerExecuted,title:a.title,...null!=a.providerMetadata?{callProviderMetadata:a.providerMetadata}:{}})}async function q(a){if(null!=a){let c=null!=d.message.metadata?lE(d.message.metadata,a):a;null!=b&&await ks({value:c,schema:b,context:{field:"message.metadata",entityId:d.message.id}}),d.message.metadata=c}}switch(a.type){case"text-start":{let b={type:"text",text:"",providerMetadata:a.providerMetadata,state:"streaming"};d.activeTextParts[a.id]=b,d.message.parts.push(b),i();break}case"text-delta":{let b=d.activeTextParts[a.id];if(null==b)throw new k8({chunkType:"text-delta",chunkId:a.id,message:`Received text-delta for missing text part with ID "${a.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`});b.text+=a.delta,b.providerMetadata=null!=(j=a.providerMetadata)?j:b.providerMetadata,i();break}case"text-end":{let b=d.activeTextParts[a.id];if(null==b)throw new k8({chunkType:"text-end",chunkId:a.id,message:`Received text-end for missing text part with ID "${a.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`});b.state="done",b.providerMetadata=null!=(k=a.providerMetadata)?k:b.providerMetadata,delete d.activeTextParts[a.id],i();break}case"reasoning-start":{let b={type:"reasoning",text:"",providerMetadata:a.providerMetadata,state:"streaming"};d.activeReasoningParts[a.id]=b,d.message.parts.push(b),i();break}case"reasoning-delta":{let b=d.activeReasoningParts[a.id];if(null==b)throw new k8({chunkType:"reasoning-delta",chunkId:a.id,message:`Received reasoning-delta for missing reasoning part with ID "${a.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`});b.text+=a.delta,b.providerMetadata=null!=(l=a.providerMetadata)?l:b.providerMetadata,i();break}case"reasoning-end":{let b=d.activeReasoningParts[a.id];if(null==b)throw new k8({chunkType:"reasoning-end",chunkId:a.id,message:`Received reasoning-end for missing reasoning part with ID "${a.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`});b.providerMetadata=null!=(m=a.providerMetadata)?m:b.providerMetadata,b.state="done",delete d.activeReasoningParts[a.id],i();break}case"file":d.message.parts.push({type:"file",mediaType:a.mediaType,url:a.url}),i();break;case"source-url":d.message.parts.push({type:"source-url",sourceId:a.sourceId,url:a.url,title:a.title,providerMetadata:a.providerMetadata}),i();break;case"source-document":d.message.parts.push({type:"source-document",sourceId:a.sourceId,mediaType:a.mediaType,title:a.title,filename:a.filename,providerMetadata:a.providerMetadata}),i();break;case"tool-input-start":{let b=d.message.parts.filter(lM);d.partialToolCalls[a.toolCallId]={text:"",toolName:a.toolName,index:b.length,dynamic:a.dynamic,title:a.title},a.dynamic?p({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-streaming",input:void 0,providerExecuted:a.providerExecuted,title:a.title,providerMetadata:a.providerMetadata}):o({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-streaming",input:void 0,providerExecuted:a.providerExecuted,title:a.title,providerMetadata:a.providerMetadata}),i();break}case"tool-input-delta":{let b=d.partialToolCalls[a.toolCallId];if(null==b)throw new k8({chunkType:"tool-input-delta",chunkId:a.toolCallId,message:`Received tool-input-delta for missing tool call with ID "${a.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`});b.text+=a.inputTextDelta;let{value:c}=await lF(b.text);b.dynamic?p({toolCallId:a.toolCallId,toolName:b.toolName,state:"input-streaming",input:c,title:b.title}):o({toolCallId:a.toolCallId,toolName:b.toolName,state:"input-streaming",input:c,title:b.title}),i();break}case"tool-input-available":a.dynamic?p({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-available",input:a.input,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata,title:a.title}):o({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-available",input:a.input,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata,title:a.title}),i(),f&&!a.providerExecuted&&await f({toolCall:a});break;case"tool-input-error":a.dynamic?p({toolCallId:a.toolCallId,toolName:a.toolName,state:"output-error",input:a.input,errorText:a.errorText,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}):o({toolCallId:a.toolCallId,toolName:a.toolName,state:"output-error",input:void 0,rawInput:a.input,errorText:a.errorText,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}),i();break;case"tool-approval-request":{let b=n(a.toolCallId);b.state="approval-requested",b.approval={id:a.approvalId},i();break}case"tool-output-denied":n(a.toolCallId).state="output-denied",i();break;case"tool-output-available":{let b=n(a.toolCallId);"dynamic-tool"===b.type?p({toolCallId:a.toolCallId,toolName:b.toolName,state:"output-available",input:b.input,output:a.output,preliminary:a.preliminary,providerExecuted:a.providerExecuted,title:b.title}):o({toolCallId:a.toolCallId,toolName:lP(b),state:"output-available",input:b.input,output:a.output,providerExecuted:a.providerExecuted,preliminary:a.preliminary,title:b.title}),i();break}case"tool-output-error":{let b=n(a.toolCallId);"dynamic-tool"===b.type?p({toolCallId:a.toolCallId,toolName:b.toolName,state:"output-error",input:b.input,errorText:a.errorText,providerExecuted:a.providerExecuted,title:b.title}):o({toolCallId:a.toolCallId,toolName:lP(b),state:"output-error",input:b.input,rawInput:b.rawInput,errorText:a.errorText,providerExecuted:a.providerExecuted,title:b.title}),i();break}case"start-step":d.message.parts.push({type:"step-start"});break;case"finish-step":d.activeTextParts={},d.activeReasoningParts={};break;case"start":null!=a.messageId&&(d.message.id=a.messageId),await q(a.messageMetadata),(null!=a.messageId||null!=a.messageMetadata)&&i();break;case"finish":null!=a.finishReason&&(d.finishReason=a.finishReason),await q(a.messageMetadata),null!=a.messageMetadata&&i();break;case"message-metadata":await q(a.messageMetadata),null!=a.messageMetadata&&i();break;case"error":null==e||e(Error(a.errorText));break;default:if(a.type.startsWith("data-")){if((null==c?void 0:c[a.type])!=null){let b=d.message.parts.findIndex(b=>"id"in b&&"data"in b&&b.id===a.id&&b.type===a.type),e=b>=0?b:d.message.parts.length;await ks({value:a.data,schema:c[a.type],context:{field:`message.parts[${e}].data`,entityName:a.type,entityId:a.id}})}if(a.transient){null==g||g(a);break}let b=null!=a.id?d.message.parts.find(b=>a.type===b.type&&a.id===b.id):void 0;null!=b?b.data=a.data:d.message.parts.push(a),null==g||g(a),i()}}h.enqueue(a)})}}))}async function lS({stream:a,onError:b}){let c=a.getReader();try{for(;;){let{done:a}=await c.read();if(a)break}}catch(a){null==b||b(a)}finally{c.releaseLock()}}jY({prefix:"aitxt",size:24});ko(()=>kr(hs(hv({id:f9(),role:hR(["system","user","assistant"]),metadata:hk().optional(),parts:hs(hz([hv({type:hU("text"),text:f9(),state:hR(["streaming","done"]).optional(),providerMetadata:lp.optional()}),hv({type:hU("reasoning"),text:f9(),state:hR(["streaming","done"]).optional(),providerMetadata:lp.optional()}),hv({type:hU("source-url"),sourceId:f9(),url:f9(),title:f9().optional(),providerMetadata:lp.optional()}),hv({type:hU("source-document"),sourceId:f9(),mediaType:f9(),title:f9(),filename:f9().optional(),providerMetadata:lp.optional()}),hv({type:hU("file"),mediaType:f9(),filename:f9().optional(),url:f9(),providerMetadata:lp.optional()}),hv({type:hU("step-start")}),hv({type:f9().startsWith("data-"),id:f9().optional(),data:hk()}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("input-streaming"),input:hk().optional(),providerExecuted:g5().optional(),callProviderMetadata:lp.optional(),output:hm().optional(),errorText:hm().optional(),approval:hm().optional()}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("input-available"),input:hk(),providerExecuted:g5().optional(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hm().optional()}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("approval-requested"),input:hk(),providerExecuted:g5().optional(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:hm().optional(),reason:hm().optional()})}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("approval-responded"),input:hk(),providerExecuted:g5().optional(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:g5(),reason:f9().optional()})}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("output-available"),input:hk(),providerExecuted:g5().optional(),output:hk(),errorText:hm().optional(),callProviderMetadata:lp.optional(),preliminary:g5().optional(),approval:hv({id:f9(),approved:hU(!0),reason:f9().optional()}).optional()}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("output-error"),input:hk(),rawInput:hk().optional(),providerExecuted:g5().optional(),output:hm().optional(),errorText:f9(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:hU(!0),reason:f9().optional()}).optional()}),hv({type:hU("dynamic-tool"),toolName:f9(),toolCallId:f9(),state:hU("output-denied"),input:hk(),providerExecuted:g5().optional(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:hU(!1),reason:f9().optional()})}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("input-streaming"),providerExecuted:g5().optional(),callProviderMetadata:lp.optional(),input:hk().optional(),output:hm().optional(),errorText:hm().optional(),approval:hm().optional()}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("input-available"),providerExecuted:g5().optional(),input:hk(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hm().optional()}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("approval-requested"),input:hk(),providerExecuted:g5().optional(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:hm().optional(),reason:hm().optional()})}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("approval-responded"),input:hk(),providerExecuted:g5().optional(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:g5(),reason:f9().optional()})}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("output-available"),providerExecuted:g5().optional(),input:hk(),output:hk(),errorText:hm().optional(),callProviderMetadata:lp.optional(),preliminary:g5().optional(),approval:hv({id:f9(),approved:hU(!0),reason:f9().optional()}).optional()}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("output-error"),providerExecuted:g5().optional(),input:hk(),rawInput:hk().optional(),output:hm().optional(),errorText:f9(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:hU(!0),reason:f9().optional()}).optional()}),hv({type:f9().startsWith("tool-"),toolCallId:f9(),state:hU("output-denied"),providerExecuted:g5().optional(),input:hk(),output:hm().optional(),errorText:hm().optional(),callProviderMetadata:lp.optional(),approval:hv({id:f9(),approved:hU(!1),reason:f9().optional()})})])).nonempty("Message must contain at least one part")})).nonempty("Messages array must not be empty")));function lT(a){return({url:b,abortSignal:c})=>lm({url:b,maxBytes:null==a?void 0:a.maxBytes,abortSignal:c})}jY({prefix:"aiobj",size:24});var lU=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(a){return new Promise((b,c)=>{this.queue.push(async()=>{try{await a(),b()}catch(a){c(a)}}),this.processQueue()})}};jY({prefix:"aiobj",size:24}),lT();var lV="AI_NoSuchProviderError",lW=`vercel.ai.error.${lV}`,lX=Symbol.for(lW);Y=lX,lT();async function lY(a){if(null==a)return[];if(!globalThis.FileList||!(a instanceof globalThis.FileList))throw Error("FileList is not supported in the current environment");return Promise.all(Array.from(a).map(async a=>{let{name:b,type:c}=a;return{type:"file",mediaType:c,filename:b,url:await new Promise((b,c)=>{let d=new FileReader;d.onload=a=>{var c;b(null==(c=a.target)?void 0:c.result)},d.onerror=a=>c(a),d.readAsDataURL(a)})}}))}var lZ=class{constructor({api:a="/api/chat",credentials:b,headers:c,body:d,fetch:e,prepareSendMessagesRequest:f,prepareReconnectToStreamRequest:g}){this.api=a,this.credentials=b,this.headers=c,this.body=d,this.fetch=e,this.prepareSendMessagesRequest=f,this.prepareReconnectToStreamRequest=g}async sendMessages({abortSignal:a,...b}){var c,d,e,f,g;let h=await kv(this.body),i=await kv(this.headers),j=await kv(this.credentials),k={...j_(i),...j_(b.headers)},l=await (null==(c=this.prepareSendMessagesRequest)?void 0:c.call(this,{api:this.api,id:b.chatId,messages:b.messages,body:{...h,...b.body},headers:k,credentials:j,requestMetadata:b.metadata,trigger:b.trigger,messageId:b.messageId})),m=null!=(d=null==l?void 0:l.api)?d:this.api,n=(null==l?void 0:l.headers)!==void 0?j_(l.headers):k,o=(null==l?void 0:l.body)!==void 0?l.body:{...h,...b.body,id:b.chatId,messages:b.messages,trigger:b.trigger,messageId:b.messageId},p=null!=(e=null==l?void 0:l.credentials)?e:j,q=null!=(f=this.fetch)?f:globalThis.fetch,r=await q(m,{method:"POST",headers:j0({"Content-Type":"application/json",...n},`ai-sdk/${ll}`,j$()),body:JSON.stringify(o),credentials:p,signal:a});if(!r.ok)throw Error(null!=(g=await r.text())?g:"Failed to fetch the chat response.");if(!r.body)throw Error("The response body is empty.");return this.processResponseStream(r.body)}async reconnectToStream(a){var b,c,d,e,f;let g=await kv(this.body),h=await kv(this.headers),i=await kv(this.credentials),j={...j_(h),...j_(a.headers)},k=await (null==(b=this.prepareReconnectToStreamRequest)?void 0:b.call(this,{api:this.api,id:a.chatId,body:{...g,...a.body},headers:j,credentials:i,requestMetadata:a.metadata})),l=null!=(c=null==k?void 0:k.api)?c:`${this.api}/${a.chatId}/stream`,m=(null==k?void 0:k.headers)!==void 0?j_(k.headers):j,n=null!=(d=null==k?void 0:k.credentials)?d:i,o=null!=(e=this.fetch)?e:globalThis.fetch,p=await o(l,{method:"GET",headers:j0(m,`ai-sdk/${ll}`,j$()),credentials:n});if(204===p.status)return null;if(!p.ok)throw Error(null!=(f=await p.text())?f:"Failed to fetch the chat response.");if(!p.body)throw Error("The response body is empty.");return this.processResponseStream(p.body)}},l$=class extends lZ{constructor(a={}){super(a)}processResponseStream(a){return(function({stream:a,schema:b}){return a.pipeThrough(new TextDecoderStream).pipeThrough(new jQ).pipeThrough(new TransformStream({async transform({data:a},c){"[DONE]"!==a&&c.enqueue(await ku({text:a,schema:b}))}}))})({stream:a,schema:lL}).pipeThrough(new TransformStream({async transform(a,b){if(!a.success)throw a.error;b.enqueue(a.value)}}))}},l_=class{constructor({generateId:a=jZ,id:b=a(),transport:c=new l$,messageMetadataSchema:d,dataPartSchemas:e,state:f,onError:g,onToolCall:h,onFinish:i,onData:j,sendAutomaticallyWhen:k}){this.activeResponse=void 0,this.jobExecutor=new lU,this.sendMessage=async(a,b)=>{var c,d,e,f;let g;if(null==a)return void await this.makeRequest({trigger:"submit-message",messageId:null==(c=this.lastMessage)?void 0:c.id,...b});if(g="text"in a||"files"in a?{parts:[...Array.isArray(a.files)?a.files:await lY(a.files),..."text"in a&&null!=a.text?[{type:"text",text:a.text}]:[]]}:a,null!=a.messageId){let b=this.state.messages.findIndex(b=>b.id===a.messageId);if(-1===b)throw Error(`message with id ${a.messageId} not found`);if("user"!==this.state.messages[b].role)throw Error(`message with id ${a.messageId} is not a user message`);this.state.messages=this.state.messages.slice(0,b+1),this.state.replaceMessage(b,{...g,id:a.messageId,role:null!=(d=g.role)?d:"user",metadata:a.metadata})}else this.state.pushMessage({...g,id:null!=(e=g.id)?e:this.generateId(),role:null!=(f=g.role)?f:"user",metadata:a.metadata});await this.makeRequest({trigger:"submit-message",messageId:a.messageId,...b})},this.regenerate=async({messageId:a,...b}={})=>{let c=null==a?this.state.messages.length-1:this.state.messages.findIndex(b=>b.id===a);if(-1===c)throw Error(`message ${a} not found`);this.state.messages=this.state.messages.slice(0,"assistant"===this.messages[c].role?c:c+1),await this.makeRequest({trigger:"regenerate-message",messageId:a,...b})},this.resumeStream=async(a={})=>{await this.makeRequest({trigger:"resume-stream",...a})},this.clearError=()=>{"error"===this.status&&(this.state.error=void 0,this.setStatus({status:"ready"}))},this.addToolApprovalResponse=async({id:a,approved:b,reason:c})=>this.jobExecutor.run(async()=>{let d=this.state.messages,e=d[d.length-1],f=d=>lO(d)&&"approval-requested"===d.state&&d.approval.id===a?{...d,state:"approval-responded",approval:{id:a,approved:b,reason:c}}:d;this.state.replaceMessage(d.length-1,{...e,parts:e.parts.map(f)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(f)),"streaming"!==this.status&&"submitted"!==this.status&&this.sendAutomaticallyWhen&&this.shouldSendAutomatically().then(a=>{var b;a&&this.makeRequest({trigger:"submit-message",messageId:null==(b=this.lastMessage)?void 0:b.id})})}),this.addToolOutput=async({state:a="output-available",tool:b,toolCallId:c,output:d,errorText:e})=>this.jobExecutor.run(async()=>{let b=this.state.messages,f=b[b.length-1],g=b=>lO(b)&&b.toolCallId===c?{...b,state:a,output:d,errorText:e}:b;this.state.replaceMessage(b.length-1,{...f,parts:f.parts.map(g)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(g)),"streaming"!==this.status&&"submitted"!==this.status&&this.sendAutomaticallyWhen&&this.shouldSendAutomatically().then(a=>{var b;a&&this.makeRequest({trigger:"submit-message",messageId:null==(b=this.lastMessage)?void 0:b.id})})}),this.addToolResult=this.addToolOutput,this.stop=async()=>{var a;("streaming"===this.status||"submitted"===this.status)&&(null==(a=this.activeResponse)?void 0:a.abortController)&&this.activeResponse.abortController.abort()},this.id=b,this.transport=c,this.generateId=a,this.messageMetadataSchema=d,this.dataPartSchemas=e,this.state=f,this.onError=g,this.onToolCall=h,this.onFinish=i,this.onData=j,this.sendAutomaticallyWhen=k}get status(){return this.state.status}setStatus({status:a,error:b}){this.status!==a&&(this.state.status=a,this.state.error=b)}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(a){this.state.messages=a}async shouldSendAutomatically(){if(!this.sendAutomaticallyWhen)return!1;let a=this.sendAutomaticallyWhen({messages:this.state.messages});return a&&"object"==typeof a&&"then"in a?await a:a}async makeRequest({trigger:a,metadata:b,headers:c,body:d,messageId:e}){var f,g,h;this.setStatus({status:"submitted",error:void 0});let i=this.lastMessage,j=!1,k=!1,l=!1;try{let f,g={state:lQ({lastMessage:this.state.snapshot(i),messageId:this.generateId()}),abortController:new AbortController};if(g.abortController.signal.addEventListener("abort",()=>{j=!0}),this.activeResponse=g,"resume-stream"===a){let a=await this.transport.reconnectToStream({chatId:this.id,metadata:b,headers:c,body:d});if(null==a)return void this.setStatus({status:"ready"});f=a}else f=await this.transport.sendMessages({chatId:this.id,messages:this.state.messages,abortSignal:g.abortController.signal,metadata:b,headers:c,body:d,trigger:a,messageId:e});let h=a=>this.jobExecutor.run(()=>a({state:g.state,write:()=>{var a;this.setStatus({status:"streaming"}),g.state.message.id===(null==(a=this.lastMessage)?void 0:a.id)?this.state.replaceMessage(this.state.messages.length-1,g.state.message):this.state.pushMessage(g.state.message)}}));await lS({stream:lR({stream:f,onToolCall:this.onToolCall,onData:this.onData,messageMetadataSchema:this.messageMetadataSchema,dataPartSchemas:this.dataPartSchemas,runUpdateMessageJob:h,onError:a=>{throw a}}),onError:a=>{throw a}}),this.setStatus({status:"ready"})}catch(a){if(j||"AbortError"===a.name)return j=!0,this.setStatus({status:"ready"}),null;l=!0,a instanceof TypeError&&(a.message.toLowerCase().includes("fetch")||a.message.toLowerCase().includes("network"))&&(k=!0),this.onError&&a instanceof Error&&this.onError(a),this.setStatus({status:"error",error:a})}finally{try{null==(g=this.onFinish)||g.call(this,{message:this.activeResponse.state.message,messages:this.state.messages,isAbort:j,isDisconnect:k,isError:l,finishReason:null==(f=this.activeResponse)?void 0:f.state.finishReason})}catch(a){console.error(a)}this.activeResponse=void 0}!l&&await this.shouldSendAutomatically()&&await this.makeRequest({trigger:"submit-message",messageId:null==(h=this.lastMessage)?void 0:h.id,metadata:b,headers:c,body:d})}}},30342:(a,b,c)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"});let d=c(44002),e=c(87011);b.matches=function(a){return a=e.cloneDeep(a),b=>d.isMatch(b,a)}},30858:(a,b,c)=>{"use strict";c.d(b,{i:()=>f});var d=c(86102),e=c(2714);function f(a,b){let{start:c,end:f}=(0,d.P)(b?.in,a),g=+c>+f,h=g?+c:+f,i=g?f:c;i.setHours(0,0,0,0),i.setDate(1);let j=b?.step??1;if(!j)return[];j<0&&(j=-j,g=!g);let k=[];for(;+i<=h;)k.push((0,e.w)(c,i)),i.setMonth(i.getMonth()+j);return g?k.reverse():k}},31038:(a,b,c)=>{"use strict";c.d(b,{A:()=>d});let d=(0,c(15336).A)("zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]])},31480:(a,b,c)=>{"use strict";function d(a){this.content=a}c.d(b,{S4:()=>O,ZF:()=>X,FK:()=>e,CU:()=>i,sX:()=>L,bP:()=>x,u$:()=>v,vI:()=>j,Sj:()=>M,Ji:()=>k}),d.prototype={constructor:d,find:function(a){for(var b=0;b<this.content.length;b+=2)if(this.content[b]===a)return b;return -1},get:function(a){var b=this.find(a);return -1==b?void 0:this.content[b+1]},update:function(a,b,c){var e=c&&c!=a?this.remove(c):this,f=e.find(a),g=e.content.slice();return -1==f?g.push(c||a,b):(g[f+1]=b,c&&(g[f]=c)),new d(g)},remove:function(a){var b=this.find(a);if(-1==b)return this;var c=this.content.slice();return c.splice(b,2),new d(c)},addToStart:function(a,b){return new d([a,b].concat(this.remove(a).content))},addToEnd:function(a,b){var c=this.remove(a).content.slice();return c.push(a,b),new d(c)},addBefore:function(a,b,c){var e=this.remove(b),f=e.content.slice(),g=e.find(a);return f.splice(-1==g?f.length:g,0,b,c),new d(f)},forEach:function(a){for(var b=0;b<this.content.length;b+=2)a(this.content[b],this.content[b+1])},prepend:function(a){return(a=d.from(a)).size?new d(a.content.concat(this.subtract(a).content)):this},append:function(a){return(a=d.from(a)).size?new d(this.subtract(a).content.concat(a.content)):this},subtract:function(a){var b=this;a=d.from(a);for(var c=0;c<a.content.length;c+=2)b=b.remove(a.content[c]);return b},toObject:function(){var a={};return this.forEach(function(b,c){a[b]=c}),a},get size(){return this.content.length>>1}},d.from=function(a){if(a instanceof d)return a;var b=[];if(a)for(var c in a)b.push(c,a[c]);return new d(b)};class e{constructor(a,b){if(this.content=a,this.size=b||0,null==b)for(let b=0;b<a.length;b++)this.size+=a[b].nodeSize}nodesBetween(a,b,c,d=0,e){for(let f=0,g=0;g<b;f++){let h=this.content[f],i=g+h.nodeSize;if(i>a&&!1!==c(h,d+g,e||null,f)&&h.content.size){let e=g+1;h.nodesBetween(Math.max(0,a-e),Math.min(h.content.size,b-e),c,d+e)}g=i}}descendants(a){this.nodesBetween(0,this.size,a)}textBetween(a,b,c,d){let e="",f=!0;return this.nodesBetween(a,b,(g,h)=>{let i=g.isText?g.text.slice(Math.max(a,h)-h,b-h):g.isLeaf?d?"function"==typeof d?d(g):d:g.type.spec.leafText?g.type.spec.leafText(g):"":"";g.isBlock&&(g.isLeaf&&i||g.isTextblock)&&c&&(f?f=!1:e+=c),e+=i},0),e}append(a){if(!a.size)return this;if(!this.size)return a;let b=this.lastChild,c=a.firstChild,d=this.content.slice(),f=0;for(b.isText&&b.sameMarkup(c)&&(d[d.length-1]=b.withText(b.text+c.text),f=1);f<a.content.length;f++)d.push(a.content[f]);return new e(d,this.size+a.size)}cut(a,b=this.size){if(0==a&&b==this.size)return this;let c=[],d=0;if(b>a)for(let e=0,f=0;f<b;e++){let g=this.content[e],h=f+g.nodeSize;h>a&&((f<a||h>b)&&(g=g.isText?g.cut(Math.max(0,a-f),Math.min(g.text.length,b-f)):g.cut(Math.max(0,a-f-1),Math.min(g.content.size,b-f-1))),c.push(g),d+=g.nodeSize),f=h}return new e(c,d)}cutByIndex(a,b){return a==b?e.empty:0==a&&b==this.content.length?this:new e(this.content.slice(a,b))}replaceChild(a,b){let c=this.content[a];if(c==b)return this;let d=this.content.slice(),f=this.size+b.nodeSize-c.nodeSize;return d[a]=b,new e(d,f)}addToStart(a){return new e([a].concat(this.content),this.size+a.nodeSize)}addToEnd(a){return new e(this.content.concat(a),this.size+a.nodeSize)}eq(a){if(this.content.length!=a.content.length)return!1;for(let b=0;b<this.content.length;b++)if(!this.content[b].eq(a.content[b]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(a){let b=this.content[a];if(!b)throw RangeError("Index "+a+" out of range for "+this);return b}maybeChild(a){return this.content[a]||null}forEach(a){for(let b=0,c=0;b<this.content.length;b++){let d=this.content[b];a(d,c,b),c+=d.nodeSize}}findDiffStart(a,b=0){return function a(b,c,d){for(let e=0;;e++){if(e==b.childCount||e==c.childCount)return b.childCount==c.childCount?null:d;let f=b.child(e),g=c.child(e);if(f==g){d+=f.nodeSize;continue}if(!f.sameMarkup(g))return d;if(f.isText&&f.text!=g.text){for(let a=0;f.text[a]==g.text[a];a++)d++;return d}if(f.content.size||g.content.size){let b=a(f.content,g.content,d+1);if(null!=b)return b}d+=f.nodeSize}}(this,a,b)}findDiffEnd(a,b=this.size,c=a.size){return function a(b,c,d,e){for(let f=b.childCount,g=c.childCount;;){if(0==f||0==g)return f==g?null:{a:d,b:e};let h=b.child(--f),i=c.child(--g),j=h.nodeSize;if(h==i){d-=j,e-=j;continue}if(!h.sameMarkup(i))return{a:d,b:e};if(h.isText&&h.text!=i.text){let a=0,b=Math.min(h.text.length,i.text.length);for(;a<b&&h.text[h.text.length-a-1]==i.text[i.text.length-a-1];)a++,d--,e--;return{a:d,b:e}}if(h.content.size||i.content.size){let b=a(h.content,i.content,d-1,e-1);if(b)return b}d-=j,e-=j}}(this,a,b,c)}findIndex(a){if(0==a)return g(0,a);if(a==this.size)return g(this.content.length,a);if(a>this.size||a<0)throw RangeError(`Position ${a} outside of fragment (${this})`);for(let b=0,c=0;;b++){let d=c+this.child(b).nodeSize;if(d>=a){if(d==a)return g(b+1,d);return g(b,c)}c=d}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(a=>a.toJSON()):null}static fromJSON(a,b){if(!b)return e.empty;if(!Array.isArray(b))throw RangeError("Invalid input for Fragment.fromJSON");return new e(b.map(a.nodeFromJSON))}static fromArray(a){if(!a.length)return e.empty;let b,c=0;for(let d=0;d<a.length;d++){let e=a[d];c+=e.nodeSize,d&&e.isText&&a[d-1].sameMarkup(e)?(b||(b=a.slice(0,d)),b[b.length-1]=e.withText(b[b.length-1].text+e.text)):b&&b.push(e)}return new e(b||a,c)}static from(a){if(!a)return e.empty;if(a instanceof e)return a;if(Array.isArray(a))return this.fromArray(a);if(a.attrs)return new e([a],a.nodeSize);throw RangeError("Can not convert "+a+" to a Fragment"+(a.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}e.empty=new e([],0);let f={index:0,offset:0};function g(a,b){return f.index=a,f.offset=b,f}function h(a,b){if(a===b)return!0;if(!(a&&"object"==typeof a)||!(b&&"object"==typeof b))return!1;let c=Array.isArray(a);if(Array.isArray(b)!=c)return!1;if(c){if(a.length!=b.length)return!1;for(let c=0;c<a.length;c++)if(!h(a[c],b[c]))return!1}else{for(let c in a)if(!(c in b)||!h(a[c],b[c]))return!1;for(let c in b)if(!(c in a))return!1}return!0}class i{constructor(a,b){this.type=a,this.attrs=b}addToSet(a){let b,c=!1;for(let d=0;d<a.length;d++){let e=a[d];if(this.eq(e))return a;if(this.type.excludes(e.type))b||(b=a.slice(0,d));else{if(e.type.excludes(this.type))return a;!c&&e.type.rank>this.type.rank&&(b||(b=a.slice(0,d)),b.push(this),c=!0),b&&b.push(e)}}return b||(b=a.slice()),c||b.push(this),b}removeFromSet(a){for(let b=0;b<a.length;b++)if(this.eq(a[b]))return a.slice(0,b).concat(a.slice(b+1));return a}isInSet(a){for(let b=0;b<a.length;b++)if(this.eq(a[b]))return!0;return!1}eq(a){return this==a||this.type==a.type&&h(this.attrs,a.attrs)}toJSON(){let a={type:this.type.name};for(let b in this.attrs){a.attrs=this.attrs;break}return a}static fromJSON(a,b){if(!b)throw RangeError("Invalid input for Mark.fromJSON");let c=a.marks[b.type];if(!c)throw RangeError(`There is no mark type ${b.type} in this schema`);let d=c.create(b.attrs);return c.checkAttrs(d.attrs),d}static sameSet(a,b){if(a==b)return!0;if(a.length!=b.length)return!1;for(let c=0;c<a.length;c++)if(!a[c].eq(b[c]))return!1;return!0}static setFrom(a){if(!a||Array.isArray(a)&&0==a.length)return i.none;if(a instanceof i)return[a];let b=a.slice();return b.sort((a,b)=>a.type.rank-b.type.rank),b}}i.none=[];class j extends Error{}class k{constructor(a,b,c){this.content=a,this.openStart=b,this.openEnd=c}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(a,b){let c=function a(b,c,d,e){let{index:f,offset:g}=b.findIndex(c),h=b.maybeChild(f);if(g==c||h.isText)return e&&!e.canReplace(f,f,d)?null:b.cut(0,c).append(d).append(b.cut(c));let i=a(h.content,c-g-1,d,h);return i&&b.replaceChild(f,h.copy(i))}(this.content,a+this.openStart,b);return c&&new k(c,this.openStart,this.openEnd)}removeBetween(a,b){return new k(function a(b,c,d){let{index:e,offset:f}=b.findIndex(c),g=b.maybeChild(e),{index:h,offset:i}=b.findIndex(d);if(f==c||g.isText){if(i!=d&&!b.child(h).isText)throw RangeError("Removing non-flat range");return b.cut(0,c).append(b.cut(d))}if(e!=h)throw RangeError("Removing non-flat range");return b.replaceChild(e,g.copy(a(g.content,c-f-1,d-f-1)))}(this.content,a+this.openStart,b+this.openStart),this.openStart,this.openEnd)}eq(a){return this.content.eq(a.content)&&this.openStart==a.openStart&&this.openEnd==a.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let a={content:this.content.toJSON()};return this.openStart>0&&(a.openStart=this.openStart),this.openEnd>0&&(a.openEnd=this.openEnd),a}static fromJSON(a,b){if(!b)return k.empty;let c=b.openStart||0,d=b.openEnd||0;if("number"!=typeof c||"number"!=typeof d)throw RangeError("Invalid input for Slice.fromJSON");return new k(e.fromJSON(a,b.content),c,d)}static maxOpen(a,b=!0){let c=0,d=0;for(let d=a.firstChild;d&&!d.isLeaf&&(b||!d.type.spec.isolating);d=d.firstChild)c++;for(let c=a.lastChild;c&&!c.isLeaf&&(b||!c.type.spec.isolating);c=c.lastChild)d++;return new k(a,c,d)}}function l(a,b){if(!b.type.compatibleContent(a.type))throw new j("Cannot join "+b.type.name+" onto "+a.type.name)}function m(a,b,c){let d=a.node(c);return l(d,b.node(c)),d}function n(a,b){let c=b.length-1;c>=0&&a.isText&&a.sameMarkup(b[c])?b[c]=a.withText(b[c].text+a.text):b.push(a)}function o(a,b,c,d){let e=(b||a).node(c),f=0,g=b?b.index(c):e.childCount;a&&(f=a.index(c),a.depth>c?f++:a.textOffset&&(n(a.nodeAfter,d),f++));for(let a=f;a<g;a++)n(e.child(a),d);b&&b.depth==c&&b.textOffset&&n(b.nodeBefore,d)}function p(a,b){return a.type.checkContent(b),a.copy(b)}function q(a,b,c){let d=[];return o(null,a,c,d),a.depth>c&&n(p(m(a,b,c+1),q(a,b,c+1)),d),o(b,null,c,d),new e(d)}k.empty=new k(e.empty,0,0);class r{constructor(a,b,c){this.pos=a,this.path=b,this.parentOffset=c,this.depth=b.length/3-1}resolveDepth(a){return null==a?this.depth:a<0?this.depth+a:a}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(a){return this.path[3*this.resolveDepth(a)]}index(a){return this.path[3*this.resolveDepth(a)+1]}indexAfter(a){return a=this.resolveDepth(a),this.index(a)+(a!=this.depth||this.textOffset?1:0)}start(a){return 0==(a=this.resolveDepth(a))?0:this.path[3*a-1]+1}end(a){return a=this.resolveDepth(a),this.start(a)+this.node(a).content.size}before(a){if(!(a=this.resolveDepth(a)))throw RangeError("There is no position before the top-level node");return a==this.depth+1?this.pos:this.path[3*a-1]}after(a){if(!(a=this.resolveDepth(a)))throw RangeError("There is no position after the top-level node");return a==this.depth+1?this.pos:this.path[3*a-1]+this.path[3*a].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let a=this.parent,b=this.index(this.depth);if(b==a.childCount)return null;let c=this.pos-this.path[this.path.length-1],d=a.child(b);return c?a.child(b).cut(c):d}get nodeBefore(){let a=this.index(this.depth),b=this.pos-this.path[this.path.length-1];return b?this.parent.child(a).cut(0,b):0==a?null:this.parent.child(a-1)}posAtIndex(a,b){b=this.resolveDepth(b);let c=this.path[3*b],d=0==b?0:this.path[3*b-1]+1;for(let b=0;b<a;b++)d+=c.child(b).nodeSize;return d}marks(){let a=this.parent,b=this.index();if(0==a.content.size)return i.none;if(this.textOffset)return a.child(b).marks;let c=a.maybeChild(b-1),d=a.maybeChild(b);if(!c){let a=c;c=d,d=a}let e=c.marks;for(var f=0;f<e.length;f++)!1!==e[f].type.spec.inclusive||d&&e[f].isInSet(d.marks)||(e=e[f--].removeFromSet(e));return e}marksAcross(a){let b=this.parent.maybeChild(this.index());if(!b||!b.isInline)return null;let c=b.marks,d=a.parent.maybeChild(a.index());for(var e=0;e<c.length;e++)!1!==c[e].type.spec.inclusive||d&&c[e].isInSet(d.marks)||(c=c[e--].removeFromSet(c));return c}sharedDepth(a){for(let b=this.depth;b>0;b--)if(this.start(b)<=a&&this.end(b)>=a)return b;return 0}blockRange(a=this,b){if(a.pos<this.pos)return a.blockRange(this);for(let c=this.depth-(this.parent.inlineContent||this.pos==a.pos?1:0);c>=0;c--)if(a.pos<=this.end(c)&&(!b||b(this.node(c))))return new v(this,a,c);return null}sameParent(a){return this.pos-this.parentOffset==a.pos-a.parentOffset}max(a){return a.pos>this.pos?a:this}min(a){return a.pos<this.pos?a:this}toString(){let a="";for(let b=1;b<=this.depth;b++)a+=(a?"/":"")+this.node(b).type.name+"_"+this.index(b-1);return a+":"+this.parentOffset}static resolve(a,b){if(!(b>=0&&b<=a.content.size))throw RangeError("Position "+b+" out of range");let c=[],d=0,e=b;for(let b=a;;){let{index:a,offset:f}=b.content.findIndex(e),g=e-f;if(c.push(b,a,d+f),!g||(b=b.child(a)).isText)break;e=g-1,d+=f+1}return new r(b,c,e)}static resolveCached(a,b){let c=u.get(a);if(c)for(let a=0;a<c.elts.length;a++){let d=c.elts[a];if(d.pos==b)return d}else u.set(a,c=new s);let d=c.elts[c.i]=r.resolve(a,b);return c.i=(c.i+1)%t,d}}class s{constructor(){this.elts=[],this.i=0}}let t=12,u=new WeakMap;class v{constructor(a,b,c){this.$from=a,this.$to=b,this.depth=c}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}let w=Object.create(null);class x{constructor(a,b,c,d=i.none){this.type=a,this.attrs=b,this.marks=d,this.content=c||e.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(a){return this.content.child(a)}maybeChild(a){return this.content.maybeChild(a)}forEach(a){this.content.forEach(a)}nodesBetween(a,b,c,d=0){this.content.nodesBetween(a,b,c,d,this)}descendants(a){this.nodesBetween(0,this.content.size,a)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(a,b,c,d){return this.content.textBetween(a,b,c,d)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(a){return this==a||this.sameMarkup(a)&&this.content.eq(a.content)}sameMarkup(a){return this.hasMarkup(a.type,a.attrs,a.marks)}hasMarkup(a,b,c){return this.type==a&&h(this.attrs,b||a.defaultAttrs||w)&&i.sameSet(this.marks,c||i.none)}copy(a=null){return a==this.content?this:new x(this.type,this.attrs,a,this.marks)}mark(a){return a==this.marks?this:new x(this.type,this.attrs,this.content,a)}cut(a,b=this.content.size){return 0==a&&b==this.content.size?this:this.copy(this.content.cut(a,b))}slice(a,b=this.content.size,c=!1){if(a==b)return k.empty;let d=this.resolve(a),e=this.resolve(b),f=c?0:d.sharedDepth(b),g=d.start(f);return new k(d.node(f).content.cut(d.pos-g,e.pos-g),d.depth-f,e.depth-f)}replace(a,b,c){var d=this.resolve(a),f=this.resolve(b);if(c.openStart>d.depth)throw new j("Inserted content deeper than insertion position");if(d.depth-c.openStart!=f.depth-c.openEnd)throw new j("Inconsistent open depths");return function a(b,c,d,f){let g=b.index(f),h=b.node(f);if(g==c.index(f)&&f<b.depth-d.openStart){let e=a(b,c,d,f+1);return h.copy(h.content.replaceChild(g,e))}if(!d.content.size)return p(h,q(b,c,f));if(d.openStart||d.openEnd||b.depth!=f||c.depth!=f){let{start:a,end:g}=function(a,b){let c=b.depth-a.openStart,d=b.node(c).copy(a.content);for(let a=c-1;a>=0;a--)d=b.node(a).copy(e.from(d));return{start:d.resolveNoCache(a.openStart+c),end:d.resolveNoCache(d.content.size-a.openEnd-c)}}(d,b);return p(h,function a(b,c,d,f,g){let h=b.depth>g&&m(b,c,g+1),i=f.depth>g&&m(d,f,g+1),j=[];return o(null,b,g,j),h&&i&&c.index(g)==d.index(g)?(l(h,i),n(p(h,a(b,c,d,f,g+1)),j)):(h&&n(p(h,q(b,c,g+1)),j),o(c,d,g,j),i&&n(p(i,q(d,f,g+1)),j)),o(f,null,g,j),new e(j)}(b,a,g,c,f))}{let a=b.parent,e=a.content;return p(a,e.cut(0,b.parentOffset).append(d.content).append(e.cut(c.parentOffset)))}}(d,f,c,0)}nodeAt(a){for(let b=this;;){let{index:c,offset:d}=b.content.findIndex(a);if(!(b=b.maybeChild(c)))return null;if(d==a||b.isText)return b;a-=d+1}}childAfter(a){let{index:b,offset:c}=this.content.findIndex(a);return{node:this.content.maybeChild(b),index:b,offset:c}}childBefore(a){if(0==a)return{node:null,index:0,offset:0};let{index:b,offset:c}=this.content.findIndex(a);if(c<a)return{node:this.content.child(b),index:b,offset:c};let d=this.content.child(b-1);return{node:d,index:b-1,offset:c-d.nodeSize}}resolve(a){return r.resolveCached(this,a)}resolveNoCache(a){return r.resolve(this,a)}rangeHasMark(a,b,c){let d=!1;return b>a&&this.nodesBetween(a,b,a=>(c.isInSet(a.marks)&&(d=!0),!d)),d}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let a=this.type.name;return this.content.size&&(a+="("+this.content.toStringInner()+")"),z(this.marks,a)}contentMatchAt(a){let b=this.type.contentMatch.matchFragment(this.content,0,a);if(!b)throw Error("Called contentMatchAt on a node with invalid content");return b}canReplace(a,b,c=e.empty,d=0,f=c.childCount){let g=this.contentMatchAt(a).matchFragment(c,d,f),h=g&&g.matchFragment(this.content,b);if(!h||!h.validEnd)return!1;for(let a=d;a<f;a++)if(!this.type.allowsMarks(c.child(a).marks))return!1;return!0}canReplaceWith(a,b,c,d){if(d&&!this.type.allowsMarks(d))return!1;let e=this.contentMatchAt(a).matchType(c),f=e&&e.matchFragment(this.content,b);return!!f&&f.validEnd}canAppend(a){return a.content.size?this.canReplace(this.childCount,this.childCount,a.content):this.type.compatibleContent(a.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let a=i.none;for(let b=0;b<this.marks.length;b++){let c=this.marks[b];c.type.checkAttrs(c.attrs),a=c.addToSet(a)}if(!i.sameSet(a,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(a=>a.type.name)}`);this.content.forEach(a=>a.check())}toJSON(){let a={type:this.type.name};for(let b in this.attrs){a.attrs=this.attrs;break}return this.content.size&&(a.content=this.content.toJSON()),this.marks.length&&(a.marks=this.marks.map(a=>a.toJSON())),a}static fromJSON(a,b){let c;if(!b)throw RangeError("Invalid input for Node.fromJSON");if(b.marks){if(!Array.isArray(b.marks))throw RangeError("Invalid mark data for Node.fromJSON");c=b.marks.map(a.markFromJSON)}if("text"==b.type){if("string"!=typeof b.text)throw RangeError("Invalid text node in JSON");return a.text(b.text,c)}let d=e.fromJSON(a,b.content),f=a.nodeType(b.type).create(b.attrs,d,c);return f.type.checkAttrs(f.attrs),f}}x.prototype.text=void 0;class y extends x{constructor(a,b,c,d){if(super(a,b,null,d),!c)throw RangeError("Empty text nodes are not allowed");this.text=c}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):z(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(a,b){return this.text.slice(a,b)}get nodeSize(){return this.text.length}mark(a){return a==this.marks?this:new y(this.type,this.attrs,this.text,a)}withText(a){return a==this.text?this:new y(this.type,this.attrs,a,this.marks)}cut(a=0,b=this.text.length){return 0==a&&b==this.text.length?this:this.withText(this.text.slice(a,b))}eq(a){return this.sameMarkup(a)&&this.text==a.text}toJSON(){let a=super.toJSON();return a.text=this.text,a}}function z(a,b){for(let c=a.length-1;c>=0;c--)b=a[c].type.name+"("+b+")";return b}class A{constructor(a){this.validEnd=a,this.next=[],this.wrapCache=[]}static parse(a,b){var c;let d,e=new B(a,b);if(null==e.next)return A.empty;let f=function a(b){let c=[];do c.push(function(b){let c=[];do c.push(function(b){let c=function(b){if(b.eat("(")){let c=a(b);return b.eat(")")||b.err("Missing closing paren"),c}if(/\W/.test(b.next))b.err("Unexpected token '"+b.next+"'");else{let a=(function(a,b){let c=a.nodeTypes,d=c[b];if(d)return[d];let e=[];for(let a in c){let d=c[a];d.isInGroup(b)&&e.push(d)}return 0==e.length&&a.err("No node type or group '"+b+"' found"),e})(b,b.next).map(a=>(null==b.inline?b.inline=a.isInline:b.inline!=a.isInline&&b.err("Mixing inline and block content"),{type:"name",value:a}));return b.pos++,1==a.length?a[0]:{type:"choice",exprs:a}}}(b);for(;;)if(b.eat("+"))c={type:"plus",expr:c};else if(b.eat("*"))c={type:"star",expr:c};else if(b.eat("?"))c={type:"opt",expr:c};else if(b.eat("{"))c=function(a,b){let c=C(a),d=c;return a.eat(",")&&(d="}"!=a.next?C(a):-1),a.eat("}")||a.err("Unclosed braced range"),{type:"range",min:c,max:d,expr:b}}(b,c);else break;return c}(b));while(b.next&&")"!=b.next&&"|"!=b.next);return 1==c.length?c[0]:{type:"seq",exprs:c}}(b));while(b.eat("|"));return 1==c.length?c[0]:{type:"choice",exprs:c}}(e);e.next&&e.err("Unexpected trailing text");let g=(c=function(a){let b=[[]];return e(function a(b,f){if("choice"==b.type)return b.exprs.reduce((b,c)=>b.concat(a(c,f)),[]);if("seq"==b.type)for(let d=0;;d++){let g=a(b.exprs[d],f);if(d==b.exprs.length-1)return g;e(g,f=c())}else if("star"==b.type){let g=c();return d(f,g),e(a(b.expr,g),g),[d(g)]}else if("plus"==b.type){let g=c();return e(a(b.expr,f),g),e(a(b.expr,g),g),[d(g)]}else if("opt"==b.type)return[d(f)].concat(a(b.expr,f));else if("range"==b.type){let g=f;for(let d=0;d<b.min;d++){let d=c();e(a(b.expr,g),d),g=d}if(-1==b.max)e(a(b.expr,g),g);else for(let f=b.min;f<b.max;f++){let f=c();d(g,f),e(a(b.expr,g),f),g=f}return[d(g)]}else if("name"==b.type)return[d(f,void 0,b.value)];else throw Error("Unknown expr type")}(a,0),c()),b;function c(){return b.push([])-1}function d(a,c,d){let e={term:d,to:c};return b[a].push(e),e}function e(a,b){a.forEach(a=>a.to=b)}}(f),d=Object.create(null),function a(b){let e=[];b.forEach(a=>{c[a].forEach(({term:a,to:b})=>{let d;if(a){for(let b=0;b<e.length;b++)e[b][0]==a&&(d=e[b][1]);E(c,b).forEach(b=>{d||e.push([a,d=[]]),-1==d.indexOf(b)&&d.push(b)})}})});let f=d[b.join(",")]=new A(b.indexOf(c.length-1)>-1);for(let b=0;b<e.length;b++){let c=e[b][1].sort(D);f.next.push({type:e[b][0],next:d[c.join(",")]||a(c)})}return f}(E(c,0)));return function(a,b){for(let c=0,d=[a];c<d.length;c++){let a=d[c],e=!a.validEnd,f=[];for(let b=0;b<a.next.length;b++){let{type:c,next:g}=a.next[b];f.push(c.name),e&&!(c.isText||c.hasRequiredAttrs())&&(e=!1),-1==d.indexOf(g)&&d.push(g)}e&&b.err("Only non-generatable nodes ("+f.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(g,e),g}matchType(a){for(let b=0;b<this.next.length;b++)if(this.next[b].type==a)return this.next[b].next;return null}matchFragment(a,b=0,c=a.childCount){let d=this;for(let e=b;d&&e<c;e++)d=d.matchType(a.child(e).type);return d}get inlineContent(){return 0!=this.next.length&&this.next[0].type.isInline}get defaultType(){for(let a=0;a<this.next.length;a++){let{type:b}=this.next[a];if(!(b.isText||b.hasRequiredAttrs()))return b}return null}compatible(a){for(let b=0;b<this.next.length;b++)for(let c=0;c<a.next.length;c++)if(this.next[b].type==a.next[c].type)return!0;return!1}fillBefore(a,b=!1,c=0){let d=[this];return function f(g,h){let i=g.matchFragment(a,c);if(i&&(!b||i.validEnd))return e.from(h.map(a=>a.createAndFill()));for(let a=0;a<g.next.length;a++){let{type:b,next:c}=g.next[a];if(!(b.isText||b.hasRequiredAttrs())&&-1==d.indexOf(c)){d.push(c);let a=f(c,h.concat(b));if(a)return a}}return null}(this,[])}findWrapping(a){for(let b=0;b<this.wrapCache.length;b+=2)if(this.wrapCache[b]==a)return this.wrapCache[b+1];let b=this.computeWrapping(a);return this.wrapCache.push(a,b),b}computeWrapping(a){let b=Object.create(null),c=[{match:this,type:null,via:null}];for(;c.length;){let d=c.shift(),e=d.match;if(e.matchType(a)){let a=[];for(let b=d;b.type;b=b.via)a.push(b.type);return a.reverse()}for(let a=0;a<e.next.length;a++){let{type:f,next:g}=e.next[a];f.isLeaf||f.hasRequiredAttrs()||f.name in b||d.type&&!g.validEnd||(c.push({match:f.contentMatch,type:f,via:d}),b[f.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(a){if(a>=this.next.length)throw RangeError(`There's no ${a}th edge in this content match`);return this.next[a]}toString(){let a=[];return!function b(c){a.push(c);for(let d=0;d<c.next.length;d++)-1==a.indexOf(c.next[d].next)&&b(c.next[d].next)}(this),a.map((b,c)=>{let d=c+(b.validEnd?"*":" ")+" ";for(let c=0;c<b.next.length;c++)d+=(c?", ":"")+b.next[c].type.name+"->"+a.indexOf(b.next[c].next);return d}).join("\n")}}A.empty=new A(!0);class B{constructor(a,b){this.string=a,this.nodeTypes=b,this.inline=null,this.pos=0,this.tokens=a.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(a){return this.next==a&&(this.pos++||!0)}err(a){throw SyntaxError(a+" (in content expression '"+this.string+"')")}}function C(a){/\D/.test(a.next)&&a.err("Expected number, got '"+a.next+"'");let b=Number(a.next);return a.pos++,b}function D(a,b){return b-a}function E(a,b){let c=[];return function b(d){let e=a[d];if(1==e.length&&!e[0].term)return b(e[0].to);c.push(d);for(let a=0;a<e.length;a++){let{term:d,to:f}=e[a];d||-1!=c.indexOf(f)||b(f)}}(b),c.sort(D)}function F(a){let b=Object.create(null);for(let c in a){let d=a[c];if(!d.hasDefault)return null;b[c]=d.default}return b}function G(a,b){let c=Object.create(null);for(let d in a){let e=b&&b[d];if(void 0===e){let b=a[d];if(b.hasDefault)e=b.default;else throw RangeError("No value supplied for attribute "+d)}c[d]=e}return c}function H(a,b,c,d){for(let d in b)if(!(d in a))throw RangeError(`Unsupported attribute ${d} for ${c} of type ${d}`);for(let c in a){let d=a[c];d.validate&&d.validate(b[c])}}function I(a,b){let c=Object.create(null);if(b)for(let d in b)c[d]=new K(a,d,b[d]);return c}class J{constructor(a,b,c){this.name=a,this.schema=b,this.spec=c,this.markSet=null,this.groups=c.group?c.group.split(" "):[],this.attrs=I(a,c.attrs),this.defaultAttrs=F(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(c.inline||"text"==a),this.isText="text"==a}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==A.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(a){return this.groups.indexOf(a)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let a in this.attrs)if(this.attrs[a].isRequired)return!0;return!1}compatibleContent(a){return this==a||this.contentMatch.compatible(a.contentMatch)}computeAttrs(a){return!a&&this.defaultAttrs?this.defaultAttrs:G(this.attrs,a)}create(a=null,b,c){if(this.isText)throw Error("NodeType.create can't construct text nodes");return new x(this,this.computeAttrs(a),e.from(b),i.setFrom(c))}createChecked(a=null,b,c){return b=e.from(b),this.checkContent(b),new x(this,this.computeAttrs(a),b,i.setFrom(c))}createAndFill(a=null,b,c){if(a=this.computeAttrs(a),(b=e.from(b)).size){let a=this.contentMatch.fillBefore(b);if(!a)return null;b=a.append(b)}let d=this.contentMatch.matchFragment(b),f=d&&d.fillBefore(e.empty,!0);return f?new x(this,a,b.append(f),i.setFrom(c)):null}validContent(a){let b=this.contentMatch.matchFragment(a);if(!b||!b.validEnd)return!1;for(let b=0;b<a.childCount;b++)if(!this.allowsMarks(a.child(b).marks))return!1;return!0}checkContent(a){if(!this.validContent(a))throw RangeError(`Invalid content for node ${this.name}: ${a.toString().slice(0,50)}`)}checkAttrs(a){H(this.attrs,a,"node",this.name)}allowsMarkType(a){return null==this.markSet||this.markSet.indexOf(a)>-1}allowsMarks(a){if(null==this.markSet)return!0;for(let b=0;b<a.length;b++)if(!this.allowsMarkType(a[b].type))return!1;return!0}allowedMarks(a){let b;if(null==this.markSet)return a;for(let c=0;c<a.length;c++)this.allowsMarkType(a[c].type)?b&&b.push(a[c]):b||(b=a.slice(0,c));return b?b.length?b:i.none:a}static compile(a,b){let c=Object.create(null);a.forEach((a,d)=>c[a]=new J(a,b,d));let d=b.spec.topNode||"doc";if(!c[d])throw RangeError("Schema is missing its top node type ('"+d+"')");if(!c.text)throw RangeError("Every schema needs a 'text' type");for(let a in c.text.attrs)throw RangeError("The text node type should not have attributes");return c}}class K{constructor(a,b,c){this.hasDefault=Object.prototype.hasOwnProperty.call(c,"default"),this.default=c.default,this.validate="string"==typeof c.validate?function(a,b,c){let d=c.split("|");return c=>{let e=null===c?"null":typeof c;if(0>d.indexOf(e))throw RangeError(`Expected value of type ${d} for attribute ${b} on type ${a}, got ${e}`)}}(a,b,c.validate):c.validate}get isRequired(){return!this.hasDefault}}class L{constructor(a,b,c,d){this.name=a,this.rank=b,this.schema=c,this.spec=d,this.attrs=I(a,d.attrs),this.excluded=null;let e=F(this.attrs);this.instance=e?new i(this,e):null}create(a=null){return!a&&this.instance?this.instance:new i(this,G(this.attrs,a))}static compile(a,b){let c=Object.create(null),d=0;return a.forEach((a,e)=>c[a]=new L(a,d++,b,e)),c}removeFromSet(a){for(var b=0;b<a.length;b++)a[b].type==this&&(a=a.slice(0,b).concat(a.slice(b+1)),b--);return a}isInSet(a){for(let b=0;b<a.length;b++)if(a[b].type==this)return a[b]}checkAttrs(a){H(this.attrs,a,"mark",this.name)}excludes(a){return this.excluded.indexOf(a)>-1}}class M{constructor(a){this.linebreakReplacement=null,this.cached=Object.create(null);let b=this.spec={};for(let c in a)b[c]=a[c];b.nodes=d.from(a.nodes),b.marks=d.from(a.marks||{}),this.nodes=J.compile(this.spec.nodes,this),this.marks=L.compile(this.spec.marks,this);let c=Object.create(null);for(let a in this.nodes){if(a in this.marks)throw RangeError(a+" can not be both a node and a mark");let b=this.nodes[a],d=b.spec.content||"",e=b.spec.marks;if(b.contentMatch=c[d]||(c[d]=A.parse(d,this.nodes)),b.inlineContent=b.contentMatch.inlineContent,b.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError("Multiple linebreak nodes defined");if(!b.isInline||!b.isLeaf)throw RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=b}b.markSet="_"==e?null:e?N(this,e.split(" ")):""!=e&&b.inlineContent?null:[]}for(let a in this.marks){let b=this.marks[a],c=b.spec.excludes;b.excluded=null==c?[b]:""==c?[]:N(this,c.split(" "))}this.nodeFromJSON=a=>x.fromJSON(this,a),this.markFromJSON=a=>i.fromJSON(this,a),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(a,b=null,c,d){if("string"==typeof a)a=this.nodeType(a);else if(a instanceof J){if(a.schema!=this)throw RangeError("Node type from different schema used ("+a.name+")")}else throw RangeError("Invalid node type: "+a);return a.createChecked(b,c,d)}text(a,b){let c=this.nodes.text;return new y(c,c.defaultAttrs,a,i.setFrom(b))}mark(a,b){return"string"==typeof a&&(a=this.marks[a]),a.create(b)}nodeType(a){let b=this.nodes[a];if(!b)throw RangeError("Unknown node type: "+a);return b}}function N(a,b){let c=[];for(let d=0;d<b.length;d++){let e=b[d],f=a.marks[e],g=f;if(f)c.push(f);else for(let b in a.marks){let d=a.marks[b];("_"==e||d.spec.group&&d.spec.group.split(" ").indexOf(e)>-1)&&c.push(g=d)}if(!g)throw SyntaxError("Unknown mark type: '"+b[d]+"'")}return c}class O{constructor(a,b){this.schema=a,this.rules=b,this.tags=[],this.styles=[];let c=this.matchedStyles=[];b.forEach(a=>{if(null!=a.tag)this.tags.push(a);else if(null!=a.style){let b=/[^=]*/.exec(a.style)[0];0>c.indexOf(b)&&c.push(b),this.styles.push(a)}}),this.normalizeLists=!this.tags.some(b=>{if(!/^(ul|ol)\b/.test(b.tag)||!b.node)return!1;let c=a.nodes[b.node];return c.contentMatch.matchType(c)})}parse(a,b={}){let c=new U(this,b,!1);return c.addAll(a,i.none,b.from,b.to),c.finish()}parseSlice(a,b={}){let c=new U(this,b,!0);return c.addAll(a,i.none,b.from,b.to),k.maxOpen(c.finish())}matchTag(a,b,c){for(let f=c?this.tags.indexOf(c)+1:0;f<this.tags.length;f++){var d,e;let c=this.tags[f];if(d=a,e=c.tag,(d.matches||d.msMatchesSelector||d.webkitMatchesSelector||d.mozMatchesSelector).call(d,e)&&(void 0===c.namespace||a.namespaceURI==c.namespace)&&(!c.context||b.matchesContext(c.context))){if(c.getAttrs){let b=c.getAttrs(a);if(!1===b)continue;c.attrs=b||void 0}return c}}}matchStyle(a,b,c,d){for(let e=d?this.styles.indexOf(d)+1:0;e<this.styles.length;e++){let d=this.styles[e],f=d.style;if(0==f.indexOf(a)&&(!d.context||c.matchesContext(d.context))&&(!(f.length>a.length)||61==f.charCodeAt(a.length)&&f.slice(a.length+1)==b)){if(d.getAttrs){let a=d.getAttrs(b);if(!1===a)continue;d.attrs=a||void 0}return d}}}static schemaRules(a){let b=[];function c(a){let c=null==a.priority?50:a.priority,d=0;for(;d<b.length;d++){let a=b[d];if((null==a.priority?50:a.priority)<c)break}b.splice(d,0,a)}for(let b in a.marks){let d=a.marks[b].spec.parseDOM;d&&d.forEach(a=>{c(a=V(a)),a.mark||a.ignore||a.clearMark||(a.mark=b)})}for(let b in a.nodes){let d=a.nodes[b].spec.parseDOM;d&&d.forEach(a=>{c(a=V(a)),a.node||a.ignore||a.mark||(a.node=b)})}return b}static fromSchema(a){return a.cached.domParser||(a.cached.domParser=new O(a,O.schemaRules(a)))}}let P={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Q={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},R={ol:!0,ul:!0};function S(a,b,c){return null!=b?!!b|2*("full"===b):a&&"pre"==a.whitespace?3:-5&c}class T{constructor(a,b,c,d,e,f){this.type=a,this.attrs=b,this.marks=c,this.solid=d,this.options=f,this.content=[],this.activeMarks=i.none,this.match=e||(4&f?null:a.contentMatch)}findWrapping(a){if(!this.match){if(!this.type)return[];let b=this.type.contentMatch.fillBefore(e.from(a));if(b)this.match=this.type.contentMatch.matchFragment(b);else{let b=this.type.contentMatch,c;return(c=b.findWrapping(a.type))?(this.match=b,c):null}}return this.match.findWrapping(a.type)}finish(a){if(!(1&this.options)){let a=this.content[this.content.length-1],b;a&&a.isText&&(b=/[ \t\r\n\u000c]+$/.exec(a.text))&&(a.text.length==b[0].length?this.content.pop():this.content[this.content.length-1]=a.withText(a.text.slice(0,a.text.length-b[0].length)))}let b=e.from(this.content);return!a&&this.match&&(b=b.append(this.match.fillBefore(e.empty,!0))),this.type?this.type.create(this.attrs,b,this.marks):b}inlineContext(a){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:a.parentNode&&!P.hasOwnProperty(a.parentNode.nodeName.toLowerCase())}}class U{constructor(a,b,c){this.parser=a,this.options=b,this.isOpen=c,this.open=0,this.localPreserveWS=!1;let d=b.topNode,e,f=S(null,b.preserveWhitespace,0)|4*!!c;e=d?new T(d.type,d.attrs,i.none,!0,b.topMatch||d.type.contentMatch,f):c?new T(null,null,i.none,!0,null,f):new T(a.schema.topNodeType,null,i.none,!0,null,f),this.nodes=[e],this.find=b.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(a,b){3==a.nodeType?this.addTextNode(a,b):1==a.nodeType&&this.addElement(a,b)}addTextNode(a,b){let c=a.nodeValue,d=this.top,e=2&d.options?"full":this.localPreserveWS||(1&d.options)>0,{schema:f}=this.parser;if("full"===e||d.inlineContext(a)||/[^ \t\r\n\u000c]/.test(c)){if(e)if("full"===e)c=c.replace(/\r\n?/g,"\n");else if(f.linebreakReplacement&&/[\r\n]/.test(c)&&this.top.findWrapping(f.linebreakReplacement.create())){let a=c.split(/\r?\n|\r/);for(let c=0;c<a.length;c++)c&&this.insertNode(f.linebreakReplacement.create(),b,!0),a[c]&&this.insertNode(f.text(a[c]),b,!/\S/.test(a[c]));c=""}else c=c.replace(/\r?\n|\r/g," ");else if(c=c.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(c)&&this.open==this.nodes.length-1){let b=d.content[d.content.length-1],e=a.previousSibling;(!b||e&&"BR"==e.nodeName||b.isText&&/[ \t\r\n\u000c]$/.test(b.text))&&(c=c.slice(1))}c&&this.insertNode(f.text(c),b,!/\S/.test(c)),this.findInText(a)}else this.findInside(a)}addElement(a,b,c){let d=this.localPreserveWS,e=this.top;("PRE"==a.tagName||/pre/.test(a.style&&a.style.whiteSpace))&&(this.localPreserveWS=!0);let f=a.nodeName.toLowerCase(),g;R.hasOwnProperty(f)&&this.parser.normalizeLists&&function(a){for(let b=a.firstChild,c=null;b;b=b.nextSibling){let a=1==b.nodeType?b.nodeName.toLowerCase():null;a&&R.hasOwnProperty(a)&&c?(c.appendChild(b),b=c):"li"==a?c=b:a&&(c=null)}}(a);let h=this.options.ruleFromNode&&this.options.ruleFromNode(a)||(g=this.parser.matchTag(a,this,c));c:if(h?h.ignore:Q.hasOwnProperty(f))this.findInside(a),this.ignoreFallback(a,b);else if(!h||h.skip||h.closeParent){h&&h.closeParent?this.open=Math.max(0,this.open-1):h&&h.skip.nodeType&&(a=h.skip);let c,d=this.needsBlock;if(P.hasOwnProperty(f))e.content.length&&e.content[0].isInline&&this.open&&(this.open--,e=this.top),c=!0,e.type||(this.needsBlock=!0);else if(!a.firstChild){this.leafFallback(a,b);break c}let g=h&&h.skip?b:this.readStyles(a,b);g&&this.addAll(a,g),c&&this.sync(e),this.needsBlock=d}else{let c=this.readStyles(a,b);c&&this.addElementByRule(a,h,c,!1===h.consuming?g:void 0)}this.localPreserveWS=d}leafFallback(a,b){"BR"==a.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(a.ownerDocument.createTextNode("\n"),b)}ignoreFallback(a,b){"BR"!=a.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),b,!0)}readStyles(a,b){let c=a.style;if(c&&c.length)for(let a=0;a<this.parser.matchedStyles.length;a++){let d=this.parser.matchedStyles[a],e=c.getPropertyValue(d);if(e)for(let a;;){let c=this.parser.matchStyle(d,e,this,a);if(!c)break;if(c.ignore)return null;if(b=c.clearMark?b.filter(a=>!c.clearMark(a)):b.concat(this.parser.schema.marks[c.mark].create(c.attrs)),!1===c.consuming)a=c;else break}}return b}addElementByRule(a,b,c,d){let e,f;if(b.node)if((f=this.parser.schema.nodes[b.node]).isLeaf)this.insertNode(f.create(b.attrs),c,"BR"==a.nodeName)||this.leafFallback(a,c);else{let a=this.enter(f,b.attrs||null,c,b.preserveWhitespace);a&&(e=!0,c=a)}else{let a=this.parser.schema.marks[b.mark];c=c.concat(a.create(b.attrs))}let g=this.top;if(f&&f.isLeaf)this.findInside(a);else if(d)this.addElement(a,c,d);else if(b.getContent)this.findInside(a),b.getContent(a,this.parser.schema).forEach(a=>this.insertNode(a,c,!1));else{let d=a;"string"==typeof b.contentElement?d=a.querySelector(b.contentElement):"function"==typeof b.contentElement?d=b.contentElement(a):b.contentElement&&(d=b.contentElement),this.findAround(a,d,!0),this.addAll(d,c),this.findAround(a,d,!1)}e&&this.sync(g)&&this.open--}addAll(a,b,c,d){let e=c||0;for(let f=c?a.childNodes[c]:a.firstChild,g=null==d?null:a.childNodes[d];f!=g;f=f.nextSibling,++e)this.findAtPoint(a,e),this.addDOM(f,b);this.findAtPoint(a,e)}findPlace(a,b,c){let d,e;for(let b=this.open,f=0;b>=0;b--){let g=this.nodes[b],h=g.findWrapping(a);if(h&&(!d||d.length>h.length+f)&&(d=h,e=g,!h.length))break;if(g.solid){if(c)break;f+=2}}if(!d)return null;this.sync(e);for(let a=0;a<d.length;a++)b=this.enterInner(d[a],null,b,!1);return b}insertNode(a,b,c){if(a.isInline&&this.needsBlock&&!this.top.type){let a=this.textblockFromContext();a&&(b=this.enterInner(a,null,b))}let d=this.findPlace(a,b,c);if(d){this.closeExtra();let b=this.top;b.match&&(b.match=b.match.matchType(a.type));let c=i.none;for(let e of d.concat(a.marks))(b.type?b.type.allowsMarkType(e.type):W(e.type,a.type))&&(c=e.addToSet(c));return b.content.push(a.mark(c)),!0}return!1}enter(a,b,c,d){let e=this.findPlace(a.create(b),c,!1);return e&&(e=this.enterInner(a,b,c,!0,d)),e}enterInner(a,b,c,d=!1,e){this.closeExtra();let f=this.top;f.match=f.match&&f.match.matchType(a);let g=S(a,e,f.options);4&f.options&&0==f.content.length&&(g|=4);let h=i.none;return c=c.filter(b=>(f.type?!f.type.allowsMarkType(b.type):!W(b.type,a))||(h=b.addToSet(h),!1)),this.nodes.push(new T(a,b,h,d,null,g)),this.open++,c}closeExtra(a=!1){let b=this.nodes.length-1;if(b>this.open){for(;b>this.open;b--)this.nodes[b-1].content.push(this.nodes[b].finish(a));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(a){for(let b=this.open;b>=0;b--)if(this.nodes[b]==a)return this.open=b,!0;else this.localPreserveWS&&(this.nodes[b].options|=1);return!1}get currentPos(){this.closeExtra();let a=0;for(let b=this.open;b>=0;b--){let c=this.nodes[b].content;for(let b=c.length-1;b>=0;b--)a+=c[b].nodeSize;b&&a++}return a}findAtPoint(a,b){if(this.find)for(let c=0;c<this.find.length;c++)this.find[c].node==a&&this.find[c].offset==b&&(this.find[c].pos=this.currentPos)}findInside(a){if(this.find)for(let b=0;b<this.find.length;b++)null==this.find[b].pos&&1==a.nodeType&&a.contains(this.find[b].node)&&(this.find[b].pos=this.currentPos)}findAround(a,b,c){if(a!=b&&this.find)for(let d=0;d<this.find.length;d++)null==this.find[d].pos&&1==a.nodeType&&a.contains(this.find[d].node)&&b.compareDocumentPosition(this.find[d].node)&(c?2:4)&&(this.find[d].pos=this.currentPos)}findInText(a){if(this.find)for(let b=0;b<this.find.length;b++)this.find[b].node==a&&(this.find[b].pos=this.currentPos-(a.nodeValue.length-this.find[b].offset))}matchesContext(a){if(a.indexOf("|")>-1)return a.split(/\s*\|\s*/).some(this.matchesContext,this);let b=a.split("/"),c=this.options.context,d=!this.isOpen&&(!c||c.parent.type==this.nodes[0].type),e=-(c?c.depth+1:0)+ +!d,f=(a,g)=>{for(;a>=0;a--){let h=b[a];if(""==h){if(a==b.length-1||0==a)continue;for(;g>=e;g--)if(f(a-1,g))return!0;return!1}{let a=g>0||0==g&&d?this.nodes[g].type:c&&g>=e?c.node(g-e).type:null;if(!a||a.name!=h&&!a.isInGroup(h))return!1;g--}}return!0};return f(b.length-1,this.open)}textblockFromContext(){let a=this.options.context;if(a)for(let b=a.depth;b>=0;b--){let c=a.node(b).contentMatchAt(a.indexAfter(b)).defaultType;if(c&&c.isTextblock&&c.defaultAttrs)return c}for(let a in this.parser.schema.nodes){let b=this.parser.schema.nodes[a];if(b.isTextblock&&b.defaultAttrs)return b}}}function V(a){let b={};for(let c in a)b[c]=a[c];return b}function W(a,b){let c=b.schema.nodes;for(let d in c){let e=c[d];if(!e.allowsMarkType(a))continue;let f=[],g=a=>{f.push(a);for(let c=0;c<a.edgeCount;c++){let{type:d,next:e}=a.edge(c);if(d==b||0>f.indexOf(e)&&g(e))return!0}};if(g(e.contentMatch))return!0}}class X{constructor(a,b){this.nodes=a,this.marks=b}serializeFragment(a,b={},c){c||(c=Z(b).createDocumentFragment());let d=c,e=[];return a.forEach(a=>{if(e.length||a.marks.length){let c=0,f=0;for(;c<e.length&&f<a.marks.length;){let b=a.marks[f];if(!this.marks[b.type.name]){f++;continue}if(!b.eq(e[c][0])||!1===b.type.spec.spanning)break;c++,f++}for(;c<e.length;)d=e.pop()[1];for(;f<a.marks.length;){let c=a.marks[f++],g=this.serializeMark(c,a.isInline,b);g&&(e.push([c,d]),d.appendChild(g.dom),d=g.contentDOM||g.dom)}}d.appendChild(this.serializeNodeInner(a,b))}),c}serializeNodeInner(a,b){let{dom:c,contentDOM:d}=aa(Z(b),this.nodes[a.type.name](a),null,a.attrs);if(d){if(a.isLeaf)throw RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(a.content,b,d)}return c}serializeNode(a,b={}){let c=this.serializeNodeInner(a,b);for(let d=a.marks.length-1;d>=0;d--){let e=this.serializeMark(a.marks[d],a.isInline,b);e&&((e.contentDOM||e.dom).appendChild(c),c=e.dom)}return c}serializeMark(a,b,c={}){let d=this.marks[a.type.name];return d&&aa(Z(c),d(a,b),null,a.attrs)}static renderSpec(a,b,c=null,d){return aa(a,b,c,d)}static fromSchema(a){return a.cached.domSerializer||(a.cached.domSerializer=new X(this.nodesFromSchema(a),this.marksFromSchema(a)))}static nodesFromSchema(a){let b=Y(a.nodes);return b.text||(b.text=a=>a.text),b}static marksFromSchema(a){return Y(a.marks)}}function Y(a){let b={};for(let c in a){let d=a[c].spec.toDOM;d&&(b[c]=d)}return b}function Z(a){return a.document||window.document}let _=new WeakMap;function aa(a,b,c,d){let e,f,g;if("string"==typeof b)return{dom:a.createTextNode(b)};if(null!=b.nodeType)return{dom:b};if(b.dom&&null!=b.dom.nodeType)return b;let h=b[0],i;if("string"!=typeof h)throw RangeError("Invalid array passed to renderSpec");if(d&&(void 0===(f=_.get(d))&&_.set(d,(g=null,!function a(b){if(b&&"object"==typeof b)if(Array.isArray(b))if("string"==typeof b[0])g||(g=[]),g.push(b);else for(let c=0;c<b.length;c++)a(b[c]);else for(let c in b)a(b[c])}(d),f=g)),i=f)&&i.indexOf(b)>-1)throw RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let j=h.indexOf(" ");j>0&&(c=h.slice(0,j),h=h.slice(j+1));let k=c?a.createElementNS(c,h):a.createElement(h),l=b[1],m=1;if(l&&"object"==typeof l&&null==l.nodeType&&!Array.isArray(l)){for(let a in m=2,l)if(null!=l[a]){let b=a.indexOf(" ");b>0?k.setAttributeNS(a.slice(0,b),a.slice(b+1),l[a]):"style"==a&&k.style?k.style.cssText=l[a]:k.setAttribute(a,l[a])}}for(let f=m;f<b.length;f++){let g=b[f];if(0===g){if(f<b.length-1||f>m)throw RangeError("Content hole must be the only child of its parent node");return{dom:k,contentDOM:k}}{let{dom:b,contentDOM:f}=aa(a,g,c,d);if(k.appendChild(b),f){if(e)throw RangeError("Multiple content holes");e=f}}}return{dom:k,contentDOM:e}}},31626:(a,b,c)=>{"use strict";c.d(b,{$L:()=>D,Ln:()=>p,N0:()=>B,Um:()=>C,Wg:()=>q,X9:()=>g,Ys:()=>m,dL:()=>O,jP:()=>t,n9:()=>z,oM:()=>u,zy:()=>y});var d=c(31480);class e{constructor(a,b,c){this.pos=a,this.delInfo=b,this.recover=c}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class f{constructor(a,b=!1){if(this.ranges=a,this.inverted=b,!a.length&&f.empty)return f.empty}recover(a){let b=0,c=65535&a;if(!this.inverted)for(let a=0;a<c;a++)b+=this.ranges[3*a+2]-this.ranges[3*a+1];return this.ranges[3*c]+b+(a-(65535&a))/65536}mapResult(a,b=1){return this._map(a,b,!1)}map(a,b=1){return this._map(a,b,!0)}_map(a,b,c){let d=0,f=this.inverted?2:1,g=this.inverted?1:2;for(let h=0;h<this.ranges.length;h+=3){let i=this.ranges[h]-(this.inverted?d:0);if(i>a)break;let j=this.ranges[h+f],k=this.ranges[h+g],l=i+j;if(a<=l){let f=j?a==i?-1:a==l?1:b:b,g=i+d+(f<0?0:k);if(c)return g;let m=a==(b<0?i:l)?null:h/3+(a-i)*65536,n=a==i?2:a==l?1:4;return(b<0?a!=i:a!=l)&&(n|=8),new e(g,n,m)}d+=k-j}return c?a+d:new e(a+d,0,null)}touches(a,b){let c=0,d=65535&b,e=this.inverted?2:1,f=this.inverted?1:2;for(let b=0;b<this.ranges.length;b+=3){let g=this.ranges[b]-(this.inverted?c:0);if(g>a)break;let h=this.ranges[b+e];if(a<=g+h&&b==3*d)return!0;c+=this.ranges[b+f]-h}return!1}forEach(a){let b=this.inverted?2:1,c=this.inverted?1:2;for(let d=0,e=0;d<this.ranges.length;d+=3){let f=this.ranges[d],g=f-(this.inverted?e:0),h=f+(this.inverted?0:e),i=this.ranges[d+b],j=this.ranges[d+c];a(g,g+i,h,h+j),e+=j-i}}invert(){return new f(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(a){return 0==a?f.empty:new f(a<0?[0,-a,0]:[0,0,a])}}f.empty=new f([]);class g{constructor(a,b,c=0,d=a?a.length:0){this.mirror=b,this.from=c,this.to=d,this._maps=a||[],this.ownData=!(a||b)}get maps(){return this._maps}slice(a=0,b=this.maps.length){return new g(this._maps,this.mirror,a,b)}appendMap(a,b){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(a),null!=b&&this.setMirror(this._maps.length-1,b)}appendMapping(a){for(let b=0,c=this._maps.length;b<a._maps.length;b++){let d=a.getMirror(b);this.appendMap(a._maps[b],null!=d&&d<b?c+d:void 0)}}getMirror(a){if(this.mirror){for(let b=0;b<this.mirror.length;b++)if(this.mirror[b]==a)return this.mirror[b+(b%2?-1:1)]}}setMirror(a,b){this.mirror||(this.mirror=[]),this.mirror.push(a,b)}appendMappingInverted(a){for(let b=a.maps.length-1,c=this._maps.length+a._maps.length;b>=0;b--){let d=a.getMirror(b);this.appendMap(a._maps[b].invert(),null!=d&&d>b?c-d-1:void 0)}}invert(){let a=new g;return a.appendMappingInverted(this),a}map(a,b=1){if(this.mirror)return this._map(a,b,!0);for(let c=this.from;c<this.to;c++)a=this._maps[c].map(a,b);return a}mapResult(a,b=1){return this._map(a,b,!1)}_map(a,b,c){let d=0;for(let c=this.from;c<this.to;c++){let e=this._maps[c].mapResult(a,b);if(null!=e.recover){let b=this.getMirror(c);if(null!=b&&b>c&&b<this.to){c=b,a=this._maps[b].recover(e.recover);continue}}d|=e.delInfo,a=e.pos}return c?a:new e(a,d,null)}}let h=Object.create(null);class i{getMap(){return f.empty}merge(a){return null}static fromJSON(a,b){if(!b||!b.stepType)throw RangeError("Invalid input for Step.fromJSON");let c=h[b.stepType];if(!c)throw RangeError(`No step type ${b.stepType} defined`);return c.fromJSON(a,b)}static jsonID(a,b){if(a in h)throw RangeError("Duplicate use of step JSON ID "+a);return h[a]=b,b.prototype.jsonID=a,b}}class j{constructor(a,b){this.doc=a,this.failed=b}static ok(a){return new j(a,null)}static fail(a){return new j(null,a)}static fromReplace(a,b,c,e){try{return j.ok(a.replace(b,c,e))}catch(a){if(a instanceof d.vI)return j.fail(a.message);throw a}}}function k(a,b,c){let e=[];for(let d=0;d<a.childCount;d++){let f=a.child(d);f.content.size&&(f=f.copy(k(f.content,b,f))),f.isInline&&(f=b(f,c,d)),e.push(f)}return d.FK.fromArray(e)}class l extends i{constructor(a,b,c){super(),this.from=a,this.to=b,this.mark=c}apply(a){let b=a.slice(this.from,this.to),c=a.resolve(this.from),e=c.node(c.sharedDepth(this.to)),f=new d.Ji(k(b.content,(a,b)=>a.isAtom&&b.type.allowsMarkType(this.mark.type)?a.mark(this.mark.addToSet(a.marks)):a,e),b.openStart,b.openEnd);return j.fromReplace(a,this.from,this.to,f)}invert(){return new m(this.from,this.to,this.mark)}map(a){let b=a.mapResult(this.from,1),c=a.mapResult(this.to,-1);return b.deleted&&c.deleted||b.pos>=c.pos?null:new l(b.pos,c.pos,this.mark)}merge(a){return a instanceof l&&a.mark.eq(this.mark)&&this.from<=a.to&&this.to>=a.from?new l(Math.min(this.from,a.from),Math.max(this.to,a.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(a,b){if("number"!=typeof b.from||"number"!=typeof b.to)throw RangeError("Invalid input for AddMarkStep.fromJSON");return new l(b.from,b.to,a.markFromJSON(b.mark))}}i.jsonID("addMark",l);class m extends i{constructor(a,b,c){super(),this.from=a,this.to=b,this.mark=c}apply(a){let b=a.slice(this.from,this.to),c=new d.Ji(k(b.content,a=>a.mark(this.mark.removeFromSet(a.marks)),a),b.openStart,b.openEnd);return j.fromReplace(a,this.from,this.to,c)}invert(){return new l(this.from,this.to,this.mark)}map(a){let b=a.mapResult(this.from,1),c=a.mapResult(this.to,-1);return b.deleted&&c.deleted||b.pos>=c.pos?null:new m(b.pos,c.pos,this.mark)}merge(a){return a instanceof m&&a.mark.eq(this.mark)&&this.from<=a.to&&this.to>=a.from?new m(Math.min(this.from,a.from),Math.max(this.to,a.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(a,b){if("number"!=typeof b.from||"number"!=typeof b.to)throw RangeError("Invalid input for RemoveMarkStep.fromJSON");return new m(b.from,b.to,a.markFromJSON(b.mark))}}i.jsonID("removeMark",m);class n extends i{constructor(a,b){super(),this.pos=a,this.mark=b}apply(a){let b=a.nodeAt(this.pos);if(!b)return j.fail("No node at mark step's position");let c=b.type.create(b.attrs,null,this.mark.addToSet(b.marks));return j.fromReplace(a,this.pos,this.pos+1,new d.Ji(d.FK.from(c),0,+!b.isLeaf))}invert(a){let b=a.nodeAt(this.pos);if(b){let a=this.mark.addToSet(b.marks);if(a.length==b.marks.length){for(let c=0;c<b.marks.length;c++)if(!b.marks[c].isInSet(a))return new n(this.pos,b.marks[c]);return new n(this.pos,this.mark)}}return new o(this.pos,this.mark)}map(a){let b=a.mapResult(this.pos,1);return b.deletedAfter?null:new n(b.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(a,b){if("number"!=typeof b.pos)throw RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new n(b.pos,a.markFromJSON(b.mark))}}i.jsonID("addNodeMark",n);class o extends i{constructor(a,b){super(),this.pos=a,this.mark=b}apply(a){let b=a.nodeAt(this.pos);if(!b)return j.fail("No node at mark step's position");let c=b.type.create(b.attrs,null,this.mark.removeFromSet(b.marks));return j.fromReplace(a,this.pos,this.pos+1,new d.Ji(d.FK.from(c),0,+!b.isLeaf))}invert(a){let b=a.nodeAt(this.pos);return b&&this.mark.isInSet(b.marks)?new n(this.pos,this.mark):this}map(a){let b=a.mapResult(this.pos,1);return b.deletedAfter?null:new o(b.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(a,b){if("number"!=typeof b.pos)throw RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new o(b.pos,a.markFromJSON(b.mark))}}i.jsonID("removeNodeMark",o);class p extends i{constructor(a,b,c,d=!1){super(),this.from=a,this.to=b,this.slice=c,this.structure=d}apply(a){return this.structure&&r(a,this.from,this.to)?j.fail("Structure replace would overwrite content"):j.fromReplace(a,this.from,this.to,this.slice)}getMap(){return new f([this.from,this.to-this.from,this.slice.size])}invert(a){return new p(this.from,this.from+this.slice.size,a.slice(this.from,this.to))}map(a){let b=a.mapResult(this.from,1),c=a.mapResult(this.to,-1);return b.deletedAcross&&c.deletedAcross?null:new p(b.pos,Math.max(b.pos,c.pos),this.slice,this.structure)}merge(a){if(!(a instanceof p)||a.structure||this.structure)return null;if(this.from+this.slice.size!=a.from||this.slice.openEnd||a.slice.openStart)if(a.to!=this.from||this.slice.openStart||a.slice.openEnd)return null;else{let b=this.slice.size+a.slice.size==0?d.Ji.empty:new d.Ji(a.slice.content.append(this.slice.content),a.slice.openStart,this.slice.openEnd);return new p(a.from,this.to,b,this.structure)}{let b=this.slice.size+a.slice.size==0?d.Ji.empty:new d.Ji(this.slice.content.append(a.slice.content),this.slice.openStart,a.slice.openEnd);return new p(this.from,this.to+(a.to-a.from),b,this.structure)}}toJSON(){let a={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(a.slice=this.slice.toJSON()),this.structure&&(a.structure=!0),a}static fromJSON(a,b){if("number"!=typeof b.from||"number"!=typeof b.to)throw RangeError("Invalid input for ReplaceStep.fromJSON");return new p(b.from,b.to,d.Ji.fromJSON(a,b.slice),!!b.structure)}}i.jsonID("replace",p);class q extends i{constructor(a,b,c,d,e,f,g=!1){super(),this.from=a,this.to=b,this.gapFrom=c,this.gapTo=d,this.slice=e,this.insert=f,this.structure=g}apply(a){if(this.structure&&(r(a,this.from,this.gapFrom)||r(a,this.gapTo,this.to)))return j.fail("Structure gap-replace would overwrite content");let b=a.slice(this.gapFrom,this.gapTo);if(b.openStart||b.openEnd)return j.fail("Gap is not a flat range");let c=this.slice.insertAt(this.insert,b.content);return c?j.fromReplace(a,this.from,this.to,c):j.fail("Content does not fit in gap")}getMap(){return new f([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(a){let b=this.gapTo-this.gapFrom;return new q(this.from,this.from+this.slice.size+b,this.from+this.insert,this.from+this.insert+b,a.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(a){let b=a.mapResult(this.from,1),c=a.mapResult(this.to,-1),d=this.from==this.gapFrom?b.pos:a.map(this.gapFrom,-1),e=this.to==this.gapTo?c.pos:a.map(this.gapTo,1);return b.deletedAcross&&c.deletedAcross||d<b.pos||e>c.pos?null:new q(b.pos,c.pos,d,e,this.slice,this.insert,this.structure)}toJSON(){let a={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(a.slice=this.slice.toJSON()),this.structure&&(a.structure=!0),a}static fromJSON(a,b){if("number"!=typeof b.from||"number"!=typeof b.to||"number"!=typeof b.gapFrom||"number"!=typeof b.gapTo||"number"!=typeof b.insert)throw RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new q(b.from,b.to,b.gapFrom,b.gapTo,d.Ji.fromJSON(a,b.slice),b.insert,!!b.structure)}}function r(a,b,c){let d=a.resolve(b),e=c-b,f=d.depth;for(;e>0&&f>0&&d.indexAfter(f)==d.node(f).childCount;)f--,e--;if(e>0){let a=d.node(f).maybeChild(d.indexAfter(f));for(;e>0;){if(!a||a.isLeaf)return!0;a=a.firstChild,e--}}return!1}function s(a,b,c,e=c.contentMatch,f=!0){let g=a.doc.nodeAt(b),h=[],i=b+1;for(let b=0;b<g.childCount;b++){let j=g.child(b),k=i+j.nodeSize,l=e.matchType(j.type);if(l){e=l;for(let b=0;b<j.marks.length;b++)c.allowsMarkType(j.marks[b].type)||a.step(new m(i,k,j.marks[b]));if(f&&j.isText&&"pre"!=c.whitespace){let a,b=/\r?\n|\r/g,e;for(;a=b.exec(j.text);)e||(e=new d.Ji(d.FK.from(c.schema.text(" ",c.allowedMarks(j.marks))),0,0)),h.push(new p(i+a.index,i+a.index+a[0].length,e))}}else h.push(new p(i,k,d.Ji.empty));i=k}if(!e.validEnd){let b=e.fillBefore(d.FK.empty,!0);a.replace(i,i,new d.Ji(b,0,0))}for(let b=h.length-1;b>=0;b--)a.step(h[b])}function t(a){let b=a.parent.content.cutByIndex(a.startIndex,a.endIndex);for(let c=a.depth,d=0,e=0;;--c){let f=a.$from.node(c),g=a.$from.index(c)+d,h=a.$to.indexAfter(c)-e;if(c<a.depth&&f.canReplace(g,h,b))return c;if(0==c||f.type.spec.isolating||!((0==g||f.canReplace(g,f.childCount))&&(h==f.childCount||f.canReplace(0,h))))break;g&&(d=1),h<f.childCount&&(e=1)}return null}function u(a,b,c=null,d=a){let e=function(a,b){let{parent:c,startIndex:d,endIndex:e}=a,f=c.contentMatchAt(d).findWrapping(b);if(!f)return null;let g=f.length?f[0]:b;return c.canReplaceWith(d,e,g)?f:null}(a,b),f=e&&function(a,b){let{parent:c,startIndex:d,endIndex:e}=a,f=c.child(d),g=b.contentMatch.findWrapping(f.type);if(!g)return null;let h=(g.length?g[g.length-1]:b).contentMatch;for(let a=d;h&&a<e;a++)h=h.matchType(c.child(a).type);return h&&h.validEnd?g:null}(d,b);return f?e.map(v).concat({type:b,attrs:c}).concat(f.map(v)):null}function v(a){return{type:a,attrs:null}}function w(a,b,c,d){b.forEach((e,f)=>{if(e.isText){let g,h=/\r?\n|\r/g;for(;g=h.exec(e.text);){let e=a.mapping.slice(d).map(c+1+f+g.index);a.replaceWith(e,e+1,b.type.schema.linebreakReplacement.create())}}})}function x(a,b,c,d){b.forEach((e,f)=>{if(e.type==e.type.schema.linebreakReplacement){let e=a.mapping.slice(d).map(c+1+f);a.replaceWith(e,e+1,b.type.schema.text("\n"))}})}function y(a,b,c=1,d){let e=a.resolve(b),f=e.depth-c,g=d&&d[d.length-1]||e.parent;if(f<0||e.parent.type.spec.isolating||!e.parent.canReplace(e.index(),e.parent.childCount)||!g.type.validContent(e.parent.content.cutByIndex(e.index(),e.parent.childCount)))return!1;for(let a=e.depth-1,b=c-2;a>f;a--,b--){let c=e.node(a),f=e.index(a);if(c.type.spec.isolating)return!1;let g=c.content.cutByIndex(f,c.childCount),h=d&&d[b+1];h&&(g=g.replaceChild(0,h.type.create(h.attrs)));let i=d&&d[b]||c;if(!c.canReplace(f+1,c.childCount)||!i.type.validContent(g))return!1}let h=e.indexAfter(f),i=d&&d[0];return e.node(f).canReplaceWith(h,h,i?i.type:e.node(f+1).type)}function z(a,b){let c=a.resolve(b),d=c.index();return A(c.nodeBefore,c.nodeAfter)&&c.parent.canReplace(d,d+1)}function A(a,b){return!!(a&&b&&!a.isLeaf&&function(a,b){b.content.size||a.type.compatibleContent(b.type);let c=a.contentMatchAt(a.childCount),{linebreakReplacement:d}=a.type.schema;for(let e=0;e<b.childCount;e++){let f=b.child(e),g=f.type==d?a.type.schema.nodes.text:f.type;if(!(c=c.matchType(g))||!a.type.allowsMarks(f.marks))return!1}return c.validEnd}(a,b))}function B(a,b,c=-1){let d=a.resolve(b);for(let a=d.depth;;a--){let e,f,g=d.index(a);if(a==d.depth?(e=d.nodeBefore,f=d.nodeAfter):c>0?(e=d.node(a+1),g++,f=d.node(a).maybeChild(g)):(e=d.node(a).maybeChild(g-1),f=d.node(a+1)),e&&!e.isTextblock&&A(e,f)&&d.node(a).canReplace(g,g+1))return b;if(0==a)break;b=c<0?d.before(a):d.after(a)}}function C(a,b,c){let d=a.resolve(b);if(!c.content.size)return b;let e=c.content;for(let a=0;a<c.openStart;a++)e=e.firstChild.content;for(let a=1;a<=(0==c.openStart&&c.size?2:1);a++)for(let b=d.depth;b>=0;b--){let c=b==d.depth?0:d.pos<=(d.start(b+1)+d.end(b+1))/2?-1:1,f=d.index(b)+ +(c>0),g=d.node(b),h=!1;if(1==a)h=g.canReplace(f,f,e);else{let a=g.contentMatchAt(f).findWrapping(e.firstChild.type);h=a&&g.canReplaceWith(f,f,a[0])}if(h)return 0==c?d.pos:c<0?d.before(b+1):d.after(b+1)}return null}function D(a,b,c=b,e=d.Ji.empty){if(b==c&&!e.size)return null;let f=a.resolve(b),g=a.resolve(c);return E(f,g,e)?new p(b,c,e):new F(f,g,e).fit()}function E(a,b,c){return!c.openStart&&!c.openEnd&&a.start()==b.start()&&a.parent.canReplace(a.index(),b.index(),c.content)}i.jsonID("replaceAround",q);class F{constructor(a,b,c){this.$from=a,this.$to=b,this.unplaced=c,this.frontier=[],this.placed=d.FK.empty;for(let b=0;b<=a.depth;b++){let c=a.node(b);this.frontier.push({type:c.type,match:c.contentMatchAt(a.indexAfter(b))})}for(let b=a.depth;b>0;b--)this.placed=d.FK.from(a.node(b).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let a=this.mustMoveInline(),b=this.placed.size-this.depth-this.$from.depth,c=this.$from,e=this.close(a<0?this.$to:c.doc.resolve(a));if(!e)return null;let f=this.placed,g=c.depth,h=e.depth;for(;g&&h&&1==f.childCount;)f=f.firstChild.content,g--,h--;let i=new d.Ji(f,g,h);return a>-1?new q(c.pos,a,this.$to.pos,this.$to.end(),i,b):i.size||c.pos!=this.$to.pos?new p(c.pos,e.pos,i):null}findFittable(){let a=this.unplaced.openStart;for(let b=this.unplaced.content,c=0,d=this.unplaced.openEnd;c<a;c++){let e=b.firstChild;if(b.childCount>1&&(d=0),e.type.spec.isolating&&d<=c){a=c;break}b=e.content}for(let b=1;b<=2;b++)for(let c=1==b?a:this.unplaced.openStart;c>=0;c--){let a=null,e=(c?(a=I(this.unplaced.content,c-1).firstChild).content:this.unplaced.content).firstChild;for(let f=this.depth;f>=0;f--){let{type:g,match:h}=this.frontier[f],i,j=null;if(1==b&&(e?h.matchType(e.type)||(j=h.fillBefore(d.FK.from(e),!1)):a&&g.compatibleContent(a.type)))return{sliceDepth:c,frontierDepth:f,parent:a,inject:j};if(2==b&&e&&(i=h.findWrapping(e.type)))return{sliceDepth:c,frontierDepth:f,parent:a,wrap:i};if(a&&h.matchType(a.type))break}}}openMore(){let{content:a,openStart:b,openEnd:c}=this.unplaced,e=I(a,b);return!!e.childCount&&!e.firstChild.isLeaf&&(this.unplaced=new d.Ji(a,b+1,Math.max(c,e.size+b>=a.size-c?b+1:0)),!0)}dropNode(){let{content:a,openStart:b,openEnd:c}=this.unplaced,e=I(a,b);if(e.childCount<=1&&b>0){let f=a.size-b<=b+e.size;this.unplaced=new d.Ji(G(a,b-1,1),b-1,f?b-1:c)}else this.unplaced=new d.Ji(G(a,b,1),b,c)}placeNodes({sliceDepth:a,frontierDepth:b,parent:c,inject:e,wrap:f}){for(;this.depth>b;)this.closeFrontierNode();if(f)for(let a=0;a<f.length;a++)this.openFrontierNode(f[a]);let g=this.unplaced,h=c?c.content:g.content,i=g.openStart-a,j=0,k=[],{match:l,type:m}=this.frontier[b];if(e){for(let a=0;a<e.childCount;a++)k.push(e.child(a));l=l.matchFragment(e)}let n=h.size+a-(g.content.size-g.openEnd);for(;j<h.childCount;){let a=h.child(j),b=l.matchType(a.type);if(!b)break;(++j>1||0==i||a.content.size)&&(l=b,k.push(function a(b,c,e){if(c<=0)return b;let f=b.content;return c>1&&(f=f.replaceChild(0,a(f.firstChild,c-1,1==f.childCount?e-1:0))),c>0&&(f=b.type.contentMatch.fillBefore(f).append(f),e<=0&&(f=f.append(b.type.contentMatch.matchFragment(f).fillBefore(d.FK.empty,!0)))),b.copy(f)}(a.mark(m.allowedMarks(a.marks)),1==j?i:0,j==h.childCount?n:-1)))}let o=j==h.childCount;o||(n=-1),this.placed=H(this.placed,b,d.FK.from(k)),this.frontier[b].match=l,o&&n<0&&c&&c.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let a=0,b=h;a<n;a++){let a=b.lastChild;this.frontier.push({type:a.type,match:a.contentMatchAt(a.childCount)}),b=a.content}this.unplaced=o?0==a?d.Ji.empty:new d.Ji(G(g.content,a-1,1),a-1,n<0?g.openEnd:a-1):new d.Ji(G(g.content,a,j),g.openStart,g.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return -1;let a=this.frontier[this.depth],b;if(!a.type.isTextblock||!J(this.$to,this.$to.depth,a.type,a.match,!1)||this.$to.depth==this.depth&&(b=this.findCloseLevel(this.$to))&&b.depth==this.depth)return -1;let{depth:c}=this.$to,d=this.$to.after(c);for(;c>1&&d==this.$to.end(--c);)++d;return d}findCloseLevel(a){d:for(let b=Math.min(this.depth,a.depth);b>=0;b--){let{match:c,type:d}=this.frontier[b],e=b<a.depth&&a.end(b+1)==a.pos+(a.depth-(b+1)),f=J(a,b,d,c,e);if(f){for(let c=b-1;c>=0;c--){let{match:b,type:d}=this.frontier[c],e=J(a,c,d,b,!0);if(!e||e.childCount)continue d}return{depth:b,fit:f,move:e?a.doc.resolve(a.after(b+1)):a}}}}close(a){let b=this.findCloseLevel(a);if(!b)return null;for(;this.depth>b.depth;)this.closeFrontierNode();b.fit.childCount&&(this.placed=H(this.placed,b.depth,b.fit)),a=b.move;for(let c=b.depth+1;c<=a.depth;c++){let b=a.node(c),d=b.type.contentMatch.fillBefore(b.content,!0,a.index(c));this.openFrontierNode(b.type,b.attrs,d)}return a}openFrontierNode(a,b=null,c){let e=this.frontier[this.depth];e.match=e.match.matchType(a),this.placed=H(this.placed,this.depth,d.FK.from(a.create(b,c))),this.frontier.push({type:a,match:a.contentMatch})}closeFrontierNode(){let a=this.frontier.pop().match.fillBefore(d.FK.empty,!0);a.childCount&&(this.placed=H(this.placed,this.frontier.length,a))}}function G(a,b,c){return 0==b?a.cutByIndex(c,a.childCount):a.replaceChild(0,a.firstChild.copy(G(a.firstChild.content,b-1,c)))}function H(a,b,c){return 0==b?a.append(c):a.replaceChild(a.childCount-1,a.lastChild.copy(H(a.lastChild.content,b-1,c)))}function I(a,b){for(let c=0;c<b;c++)a=a.firstChild.content;return a}function J(a,b,c,d,e){let f=a.node(b),g=e?a.indexAfter(b):a.index(b);if(g==f.childCount&&!c.compatibleContent(f.type))return null;let h=d.fillBefore(f.content,!0,g);return h&&!function(a,b,c){for(let d=c;d<b.childCount;d++)if(!a.allowsMarks(b.child(d).marks))return!0;return!1}(c,f.content,g)?h:null}function K(a,b){let c=[],d=Math.min(a.depth,b.depth);for(let e=d;e>=0;e--){let d=a.start(e);if(d<a.pos-(a.depth-e)||b.end(e)>b.pos+(b.depth-e)||a.node(e).type.spec.isolating||b.node(e).type.spec.isolating)break;(d==b.start(e)||e==a.depth&&e==b.depth&&a.parent.inlineContent&&b.parent.inlineContent&&e&&b.start(e-1)==d-1)&&c.push(e)}return c}class L extends i{constructor(a,b,c){super(),this.pos=a,this.attr=b,this.value=c}apply(a){let b=a.nodeAt(this.pos);if(!b)return j.fail("No node at attribute step's position");let c=Object.create(null);for(let a in b.attrs)c[a]=b.attrs[a];c[this.attr]=this.value;let e=b.type.create(c,null,b.marks);return j.fromReplace(a,this.pos,this.pos+1,new d.Ji(d.FK.from(e),0,+!b.isLeaf))}getMap(){return f.empty}invert(a){return new L(this.pos,this.attr,a.nodeAt(this.pos).attrs[this.attr])}map(a){let b=a.mapResult(this.pos,1);return b.deletedAfter?null:new L(b.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(a,b){if("number"!=typeof b.pos||"string"!=typeof b.attr)throw RangeError("Invalid input for AttrStep.fromJSON");return new L(b.pos,b.attr,b.value)}}i.jsonID("attr",L);class M extends i{constructor(a,b){super(),this.attr=a,this.value=b}apply(a){let b=Object.create(null);for(let c in a.attrs)b[c]=a.attrs[c];b[this.attr]=this.value;let c=a.type.create(b,a.content,a.marks);return j.ok(c)}getMap(){return f.empty}invert(a){return new M(this.attr,a.attrs[this.attr])}map(a){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(a,b){if("string"!=typeof b.attr)throw RangeError("Invalid input for DocAttrStep.fromJSON");return new M(b.attr,b.value)}}i.jsonID("docAttr",M);let N=class extends Error{};(N=function a(b){let c=Error.call(this,b);return c.__proto__=a.prototype,c}).prototype=Object.create(Error.prototype),N.prototype.constructor=N,N.prototype.name="TransformError";class O{constructor(a){this.doc=a,this.steps=[],this.docs=[],this.mapping=new g}get before(){return this.docs.length?this.docs[0]:this.doc}step(a){let b=this.maybeStep(a);if(b.failed)throw new N(b.failed);return this}maybeStep(a){let b=a.apply(this.doc);return b.failed||this.addStep(a,b.doc),b}get docChanged(){return this.steps.length>0}changedRange(){let a=1e9,b=-1e9;for(let c=0;c<this.mapping.maps.length;c++){let d=this.mapping.maps[c];c&&(a=d.map(a,1),b=d.map(b,-1)),d.forEach((c,d,e,f)=>{a=Math.min(a,e),b=Math.max(b,f)})}return 1e9==a?null:{from:a,to:b}}addStep(a,b){this.docs.push(this.doc),this.steps.push(a),this.mapping.appendMap(a.getMap()),this.doc=b}replace(a,b=a,c=d.Ji.empty){let e=D(this.doc,a,b,c);return e&&this.step(e),this}replaceWith(a,b,c){return this.replace(a,b,new d.Ji(d.FK.from(c),0,0))}delete(a,b){return this.replace(a,b,d.Ji.empty)}insert(a,b){return this.replaceWith(a,a,b)}replaceRange(a,b,c){return!function(a,b,c,e){if(!e.size)return a.deleteRange(b,c);let f=a.doc.resolve(b),g=a.doc.resolve(c);if(E(f,g,e))return a.step(new p(b,c,e));let h=K(f,g);0==h[h.length-1]&&h.pop();let i=-(f.depth+1);h.unshift(i);for(let a=f.depth,b=f.pos-1;a>0;a--,b--){let c=f.node(a).type.spec;if(c.defining||c.definingAsContext||c.isolating)break;h.indexOf(a)>-1?i=a:f.before(a)==b&&h.splice(1,0,-a)}let j=h.indexOf(i),k=[],l=e.openStart;for(let a=e.content,b=0;;b++){let c=a.firstChild;if(k.push(c),b==e.openStart)break;a=c.content}for(let a=l-1;a>=0;a--){var m;let b=k[a],c=(m=b.type).spec.defining||m.spec.definingForContent;if(c&&!b.sameMarkup(f.node(Math.abs(i)-1)))l=a;else if(c||!b.type.isTextblock)break}for(let b=e.openStart;b>=0;b--){let i=(b+l+1)%(e.openStart+1),m=k[i];if(m)for(let b=0;b<h.length;b++){let k=h[(b+j)%h.length],l=!0;k<0&&(l=!1,k=-k);let n=f.node(k-1),o=f.index(k-1);if(n.canReplaceWith(o,o,m.type,m.marks))return a.replace(f.before(k),l?g.after(k):c,new d.Ji(function a(b,c,e,f,g){if(c<e){let d=b.firstChild;b=b.replaceChild(0,d.copy(a(d.content,c+1,e,f,d)))}if(c>f){let a=g.contentMatchAt(0),c=a.fillBefore(b).append(b);b=c.append(a.matchFragment(c).fillBefore(d.FK.empty,!0))}return b}(e.content,0,e.openStart,i),i,e.openEnd))}}let n=a.steps.length;for(let d=h.length-1;d>=0&&(a.replace(b,c,e),!(a.steps.length>n));d--){let a=h[d];a<0||(b=f.before(a),c=g.after(a))}}(this,a,b,c),this}replaceRangeWith(a,b,c){var e=a,f=b;if(!c.isInline&&e==f&&this.doc.resolve(e).parent.content.size){let a=function(a,b,c){let d=a.resolve(b);if(d.parent.canReplaceWith(d.index(),d.index(),c))return b;if(0==d.parentOffset)for(let a=d.depth-1;a>=0;a--){let b=d.index(a);if(d.node(a).canReplaceWith(b,b,c))return d.before(a+1);if(b>0)return null}if(d.parentOffset==d.parent.content.size)for(let a=d.depth-1;a>=0;a--){let b=d.indexAfter(a);if(d.node(a).canReplaceWith(b,b,c))return d.after(a+1);if(b<d.node(a).childCount)break}return null}(this.doc,e,c.type);null!=a&&(e=f=a)}return this.replaceRange(e,f,new d.Ji(d.FK.from(c),0,0)),this}deleteRange(a,b){return!function(a,b,c){let d=a.doc.resolve(b),e=a.doc.resolve(c),f=K(d,e);for(let b=0;b<f.length;b++){let c=f[b],g=b==f.length-1;if(g&&0==c||d.node(c).type.contentMatch.validEnd)return a.delete(d.start(c),e.end(c));if(c>0&&(g||d.node(c-1).canReplace(d.index(c-1),e.indexAfter(c-1))))return a.delete(d.before(c),e.after(c))}for(let f=1;f<=d.depth&&f<=e.depth;f++)if(b-d.start(f)==d.depth-f&&c>d.end(f)&&e.end(f)-c!=e.depth-f&&d.start(f-1)==e.start(f-1)&&d.node(f-1).canReplace(d.index(f-1),e.index(f-1)))return a.delete(d.before(f),c);a.delete(b,c)}(this,a,b),this}lift(a,b){return!function(a,b,c){let{$from:e,$to:f,depth:g}=b,h=e.before(g+1),i=f.after(g+1),j=h,k=i,l=d.FK.empty,m=0;for(let a=g,b=!1;a>c;a--)b||e.index(a)>0?(b=!0,l=d.FK.from(e.node(a).copy(l)),m++):j--;let n=d.FK.empty,o=0;for(let a=g,b=!1;a>c;a--)b||f.after(a+1)<f.end(a)?(b=!0,n=d.FK.from(f.node(a).copy(n)),o++):k++;a.step(new q(j,k,h,i,new d.Ji(l.append(n),m,o),l.size-m,!0))}(this,a,b),this}join(a,b=1){return!function(a,b,c){let e=null,{linebreakReplacement:f}=a.doc.type.schema,g=a.doc.resolve(b-c),h=g.node().type;if(f&&h.inlineContent){let a="pre"==h.whitespace,b=!!h.contentMatch.matchType(f);a&&!b?e=!1:!a&&b&&(e=!0)}let i=a.steps.length;if(!1===e){let d=a.doc.resolve(b+c);x(a,d.node(),d.before(),i)}h.inlineContent&&s(a,b+c-1,h,g.node().contentMatchAt(g.index()),null==e);let j=a.mapping.slice(i),k=j.map(b-c);if(a.step(new p(k,j.map(b+c,-1),d.Ji.empty,!0)),!0===e){let b=a.doc.resolve(k);w(a,b.node(),b.before(),a.steps.length)}}(this,a,b),this}wrap(a,b){return!function(a,b,c){let e=d.FK.empty;for(let a=c.length-1;a>=0;a--){if(e.size){let b=c[a].type.contentMatch.matchFragment(e);if(!b||!b.validEnd)throw RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}e=d.FK.from(c[a].type.create(c[a].attrs,e))}let f=b.start,g=b.end;a.step(new q(f,g,f,g,new d.Ji(e,0,0),c.length,!0))}(this,a,b),this}setBlockType(a,b=a,c,e=null){var f=this;if(!c.isTextblock)throw RangeError("Type given to setBlockType should be a textblock");let g=f.steps.length;return f.doc.nodesBetween(a,b,(a,b)=>{var h,i,j;let k,l,m="function"==typeof e?e(a):e;if(a.isTextblock&&!a.hasMarkup(c,m)&&(h=f.doc,i=f.mapping.slice(g).map(b),j=c,l=(k=h.resolve(i)).index(),k.parent.canReplaceWith(l,l+1,j))){let e=null;if(c.schema.linebreakReplacement){let a="pre"==c.whitespace,b=!!c.contentMatch.matchType(c.schema.linebreakReplacement);a&&!b?e=!1:!a&&b&&(e=!0)}!1===e&&x(f,a,b,g),s(f,f.mapping.slice(g).map(b,1),c,void 0,null===e);let h=f.mapping.slice(g),i=h.map(b,1),j=h.map(b+a.nodeSize,1);return f.step(new q(i,j,i+1,j-1,new d.Ji(d.FK.from(c.create(m,null,a.marks)),0,0),1,!0)),!0===e&&w(f,a,b,g),!1}}),this}setNodeMarkup(a,b,c=null,e){return!function(a,b,c,e,f){let g=a.doc.nodeAt(b);if(!g)throw RangeError("No node at given position");c||(c=g.type);let h=c.create(e,null,f||g.marks);if(g.isLeaf)return a.replaceWith(b,b+g.nodeSize,h);if(!c.validContent(g.content))throw RangeError("Invalid content for node type "+c.name);a.step(new q(b,b+g.nodeSize,b+1,b+g.nodeSize-1,new d.Ji(d.FK.from(h),0,0),1,!0))}(this,a,b,c,e),this}setNodeAttribute(a,b,c){return this.step(new L(a,b,c)),this}setDocAttribute(a,b){return this.step(new M(a,b)),this}addNodeMark(a,b){return this.step(new n(a,b)),this}removeNodeMark(a,b){let c=this.doc.nodeAt(a);if(!c)throw RangeError("No node at position "+a);if(b instanceof d.CU)b.isInSet(c.marks)&&this.step(new o(a,b));else{let d=c.marks,e,f=[];for(;e=b.isInSet(d);)f.push(new o(a,e)),d=e.removeFromSet(d);for(let a=f.length-1;a>=0;a--)this.step(f[a])}return this}split(a,b=1,c){return!function(a,b,c=1,e){let f=a.doc.resolve(b),g=d.FK.empty,h=d.FK.empty;for(let a=f.depth,b=f.depth-c,i=c-1;a>b;a--,i--){g=d.FK.from(f.node(a).copy(g));let b=e&&e[i];h=d.FK.from(b?b.type.create(b.attrs,h):f.node(a).copy(h))}a.step(new p(b,b,new d.Ji(g.append(h),c,c),!0))}(this,a,b,c),this}addMark(a,b,c){var d;let e,f,g,h;return d=this,g=[],h=[],d.doc.nodesBetween(a,b,(d,i,j)=>{if(!d.isInline)return;let k=d.marks;if(!c.isInSet(k)&&j.type.allowsMarkType(c.type)){let j=Math.max(i,a),n=Math.min(i+d.nodeSize,b),o=c.addToSet(k);for(let a=0;a<k.length;a++)k[a].isInSet(o)||(e&&e.to==j&&e.mark.eq(k[a])?e.to=n:g.push(e=new m(j,n,k[a])));f&&f.to==j?f.to=n:h.push(f=new l(j,n,c))}}),g.forEach(a=>d.step(a)),h.forEach(a=>d.step(a)),this}removeMark(a,b,c){var e;let f,g;return e=this,f=[],g=0,e.doc.nodesBetween(a,b,(e,h)=>{if(!e.isInline)return;g++;let i=null;if(c instanceof d.sX){let a=e.marks,b;for(;b=c.isInSet(a);)(i||(i=[])).push(b),a=b.removeFromSet(a)}else c?c.isInSet(e.marks)&&(i=[c]):i=e.marks;if(i&&i.length){let c=Math.min(h+e.nodeSize,b);for(let b=0;b<i.length;b++){let d=i[b],e;for(let a=0;a<f.length;a++){let b=f[a];b.step==g-1&&d.eq(f[a].style)&&(e=b)}e?(e.to=c,e.step=g):f.push({style:d,from:Math.max(h,a),to:c,step:g})}}}),f.forEach(a=>e.step(new m(a.from,a.to,a.style))),this}clearIncompatible(a,b,c){return s(this,a,b,c),this}}},32206:(a,b,c)=>{"use strict";c.d(b,{o:()=>k});var d=c(36927),e=c(15962),f=c(11263);let g=(0,e.createContext)(null);var h=c(35724),i=c(546);let j=a=>!a.isLayoutDirty&&a.willUpdate(!1),k=({children:a,id:b,inherit:c=!0})=>{let k=(0,e.useContext)(f.L),l=(0,e.useContext)(g),[m,n]=function(){let a=function(){let a=(0,e.useRef)(!1);return(0,i.E)(()=>(a.current=!0,()=>{a.current=!1}),[]),a}(),[b,c]=(0,e.useState)(0),d=(0,e.useCallback)(()=>{a.current&&c(b+1)},[b]);return[(0,e.useCallback)(()=>h.Gt.postRender(d),[d]),b]}(),o=(0,e.useRef)(null),p=k.id||l;null===o.current&&((a=>!0==(!0===a)||"id"===a)(c)&&p&&(b=b?p+"-"+b:p),o.current={id:b,group:!0===c&&k.group||function(){let a=new Set,b=new WeakMap,c=()=>a.forEach(j);return{add:d=>{a.add(d),b.set(d,d.addEventListener("willUpdate",c))},remove:d=>{a.delete(d);let e=b.get(d);e&&(e(),b.delete(d)),c()},dirty:c}}()});let q=(0,e.useMemo)(()=>({...o.current,forceRender:m}),[n]);return(0,d.jsx)(f.L.Provider,{value:q,children:a})}},32314:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.d(b,{c:()=>D});var e=c(36927),f=c(58404),g=c(99967),h=c(25607),i=c(15962),j=c(55132),k=c(90106),l=c(43461),m=c(58556),n=c(42837),o=c(73700),p=c(51651),q=c(59448),r=c(29187),s=a([r]);r=(s.then?(await s)():s)[0];let B=(0,f.default)(async()=>{},{loadableGenerated:{modules:["app/components/chat-message.tsx -> ./charts/report-card"]},ssr:!1,loading:()=>(0,e.jsx)("div",{className:"h-48 rounded-2xl animate-pulse",style:{background:"var(--color-surface-hover)"}})}),C="NO_REPLY";function t(a){return"output-available"===a?"done":"error"===a?"error":"running"}function u(a){if(a&&"object"==typeof a&&!Array.isArray(a))return a}function v({paths:a}){return(0,e.jsx)("div",{className:"flex flex-wrap gap-1.5 mb-2 justify-end",children:a.map((a,b)=>{let c=function(a){let b=a.split(".").pop()?.toLowerCase()??"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(b)?"image":["mp4","webm","mov","avi","mkv","flv"].includes(b)?"video":["mp3","wav","ogg","aac","flac","m4a"].includes(b)?"audio":"pdf"===b?"pdf":["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(b)?"code":["doc","docx","xls","xlsx","ppt","pptx","txt","rtf","csv","pages","numbers","key"].includes(b)?"document":"other"}(a),d="image"===c?`/api/workspace/raw-file?path=${encodeURIComponent(a)}`:`/api/workspace/thumbnail?path=${encodeURIComponent(a)}&size=200`,f=a.split(".").pop()?.toUpperCase()??"";return(0,e.jsxs)("div",{className:"relative rounded-xl overflow-hidden shrink-0",children:[(0,e.jsx)("img",{src:d,alt:a.split("/").pop()??"",className:"block rounded-xl object-cover",style:{maxHeight:140,maxWidth:160,background:"rgba(0,0,0,0.04)"},loading:"lazy",onError:a=>{a.currentTarget.style.display="none"}}),"image"!==c&&(0,e.jsx)("span",{className:"absolute bottom-2 left-2 rounded-md px-1.5 py-0.5 text-[10px] font-bold uppercase",style:{background:"rgba(255,255,255,0.85)",color:"rgba(0,0,0,0.5)",backdropFilter:"blur(4px)"},children:f})]},b)})})}function w(a){let b=a.trim();if(!b||b.length<3||b.length>500)return!1;if(b.startsWith("~/")||b.startsWith("/")||b.startsWith("./")||b.startsWith("../")){let a=b.startsWith("~/")?b.slice(2):b.startsWith("../")?b.slice(3):b.startsWith("./")?b.slice(2):b.slice(1);return a.includes("/")||a.includes(".")}return!(!/\.(pdf|docx?|xlsx?|pptx?|csv|txt|rtf|pages|numbers|key|md|json|yaml|yml|toml|xml|html?|css|jsx?|tsx?|py|rb|go|rs|java|cpp|c|h|sh|sql|swift|kt|png|jpe?g|gif|webp|svg|bmp|ico|heic|tiff|mp[34]|webm|mov|avi|mkv|flv|wav|ogg|aac|flac|m4a|zip|tar|gz|dmg)$/i.test(b)||b.includes(" "))}async function x(a,b=!1){try{let c=await fetch("/api/workspace/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a,reveal:b})});if(!c.ok){let a=await c.json().catch(()=>({}));console.error("Failed to open file:",a)}}catch(a){console.error("Failed to open file:",a)}}function y(a){let b=a.trim();if(!b.startsWith("file://"))return b;try{let a=new URL(b);if("file:"!==a.protocol)return b;let c=decodeURIComponent(a.pathname);if(/^\/[A-Za-z]:\//.test(c))return c.slice(1);return c}catch{return b}}function z({path:a,children:b,onFilePathClick:c}){let[d,f]=(0,i.useState)("idle"),g=async b=>{b.preventDefault(),f("opening");try{if(c){let b=await c(a);if(!1===b){f("error"),setTimeout(()=>f("idle"),2e3);return}f("idle")}else(await fetch("/api/workspace/open-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a})})).ok?f("idle"):(f("error"),setTimeout(()=>f("idle"),2e3))}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},h=async b=>{b.preventDefault(),await x(a,!0)};return(0,e.jsx)("code",{className:`px-[0.3em] no-underline transition-colors duration-150 rounded-[4px] border border-[color:var(--color-border)] bg-white/20 hover:bg-white/40 active:bg-white ${"opening"===d?"cursor-wait opacity-70":"cursor-pointer"}`,style:{color:"var(--color-accent)"},onClick:g,onContextMenu:h,title:"error"===d?"File not found":c?"Click to preview in workspace \xb7 Right-click to reveal in Finder":"Click to open \xb7 Right-click to reveal in Finder",children:b})}function A({messageId:a,sessionId:b}){let c=(0,i.useCallback)((a,b)=>{a&&fetch("/api/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:a,messageId:b,distinctId:g.Ay.get_distinct_id?.()})}).catch(()=>{})},[]),{respond:d,response:f,triggerRef:j}=(0,h.y)({surveyId:"019cc021-a8bf-0000-d41d-b82956ef7e6a",properties:{$ai_trace_id:b,message_id:a},onResponse:()=>c(b,a)}),k="p-1 rounded-md transition-colors";return(0,e.jsxs)("div",{ref:j,className:"flex items-center gap-0.5 mt-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,e.jsx)("button",{type:"button",onClick:()=>d("up"),className:k,style:{color:"up"===f?"var(--color-accent)":"var(--color-text-muted)"},title:"Good response","aria-label":"Thumbs up",children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"up"===f?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M7 10v12"}),(0,e.jsx)("path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z"})]})}),(0,e.jsx)("button",{type:"button",onClick:()=>d("down"),className:k,style:{color:"down"===f?"var(--color-error, #ef4444)":"var(--color-text-muted)"},title:"Bad response","aria-label":"Thumbs down",children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"down"===f?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M17 14V2"}),(0,e.jsx)("path",{d:"M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z"})]})})]})}let D=(0,i.memo)(function({message:a,isStreaming:b,onSubagentClick:c,onFilePathClick:d,sessionId:f,userHtmlMap:g}){let h="user"===a.role,s=function(a){let b=[],c=[],d=a=>{if(c.length>0){if(a)for(let a of c)"tool"===a.kind&&"running"===a.status&&(a.status="done");b.push({type:"chain",parts:[...c]}),c=[]}};for(let e of a)if("text"===e.type){let a=e.text;if(function(a){let b=a.trim();return!!b&&!!(RegExp(`^${C}\\W*$`).test(b)||C.startsWith(b)&&b.length>=2&&b.length<C.length)}(a))continue;if(d(!0),(0,o.x)(a))b.push(...(0,o.R)(a));else if((0,p.k)(a))for(let c of(0,p.g)(a))"diff-artifact"===c.type?b.push({type:"diff-artifact",diff:c.diff}):b.push({type:"text",text:c.text});else b.push({type:"text",text:a})}else if("reasoning"===e.type){let a=e;["Preparing response...","Optimizing session context...","Waiting for subagent results...","Waiting for subagents..."].some(b=>a.text.startsWith(b))||c.push({kind:"reasoning",text:a.text,isStreaming:"streaming"===a.state})}else if("dynamic-tool"===e.type)if("sessions_spawn"===e.toolName){d(!0);let a=u(e.input),c=u(e.output),f="string"==typeof a?.task?a.task:"Subagent task",g="string"==typeof a?.label?a.label:void 0,h="string"==typeof c?.sessionKey?c.sessionKey:void 0;b.push({type:"subagent-card",task:f,label:g,sessionKey:h,status:t(e.state)})}else c.push({kind:"tool",toolName:e.toolName,toolCallId:e.toolCallId,status:t(e.state),args:u(e.input),output:u(e.output)});else if(e.type.startsWith("tool-")){let a=e.title??e.toolName??e.type.replace("tool-","");if("sessions_spawn"===a){d(!0);let a=u(e.input)??u(e.args),c=u(e.output)??u(e.result),f="string"==typeof a?.task?a.task:"Subagent task",g="string"==typeof a?.label?a.label:void 0,h="string"==typeof c?.sessionKey?c.sessionKey:void 0,i=e.state??(e.errorText?"error":"result"in e||"output"in e?"output-available":"input-available");b.push({type:"subagent-card",task:f,label:g,sessionKey:h,status:t(i)})}else{let b=e.state??(e.errorText?"error":"result"in e||"output"in e?"output-available":"input-available");c.push({kind:"tool",toolName:a,toolCallId:e.toolCallId,status:t(b),args:u(e.input)??u(e.args),output:u(e.output)??u(e.result)})}}return d(),b}(a.parts),x=(0,i.useMemo)(()=>({a:({href:a,children:b,...c})=>{let f="string"==typeof a?a:"",g=y(f),h=f&&(f.startsWith("http://")||f.startsWith("https://")||f.startsWith("//")),i=!(f.startsWith("/workspace")||f.startsWith("/?"))&&(!!f.startsWith("file://")||w(g));return(0,e.jsx)("a",{href:a,...h?{target:"_blank",rel:"noopener noreferrer"}:{},...c,onClick:a=>{i&&d&&(a.preventDefault(),d(g))},children:b})},img:({src:a,alt:b,...c})=>{let d="string"!=typeof a||a.startsWith("http://")||a.startsWith("https://")||a.startsWith("data:")?a:`/api/workspace/raw-file?path=${encodeURIComponent(a)}`;return(0,e.jsx)("img",{src:d,alt:b??"",loading:"lazy",...c})},pre:({children:a,...b})=>{let c=Array.isArray(a)?a[0]:a;if(c&&"object"==typeof c&&"type"in c&&"code"===c.type){let a=(c.props?.className??"").match(/language-(\w+)/),b=a?.[1]??"",d="string"==typeof c.props?.children?c.props.children.replace(/\n$/,""):"";if("diff"===b)return(0,e.jsx)(q.a,{diff:d});if(b)return(0,e.jsxs)("div",{className:"chat-code-block",children:[(0,e.jsx)("div",{className:"chat-code-lang",children:b}),(0,e.jsx)(r.F,{code:d,lang:b})]})}return(0,e.jsx)("pre",{...b,children:a})},code:({children:a,className:b,...c})=>{if(b?.startsWith("language-"))return(0,e.jsx)("code",{className:b,...c,children:a});let f=y("string"==typeof a?a:"");return f&&w(f)?(0,e.jsx)(z,{path:f,onFilePathClick:d,children:a}):(0,e.jsx)("code",{...c,children:a})},strong:({children:a,...b})=>{let c="string"==typeof a?a:Array.isArray(a)?a.filter(a=>"string"==typeof a).join(""):"";return c&&function(a){let b=a.trim();return!!b&&!(b.length<3)&&!(b.length>300)&&/\.(pdf|docx?|xlsx?|pptx?|csv|txt|rtf|pages|numbers|key|md|json|yaml|yml|toml|xml|html?|css|jsx?|tsx?|py|rb|go|rs|java|cpp|c|h|sh|sql|swift|kt|png|jpe?g|gif|webp|svg|bmp|ico|heic|tiff|mp[34]|webm|mov|avi|mkv|flv|wav|ogg|aac|flac|m4a|zip|tar|gz|dmg)$/i.test(b)}(c)?(0,e.jsx)("strong",{...b,children:(0,e.jsx)(z,{path:c,onFilePathClick:d,children:a})}):(0,e.jsx)("strong",{...b,children:a})}}),[d]);if(h){let b=s.filter(a=>"text"===a.type).map(a=>a.text).join("\n"),c=function(a){let b=a.match(/\[Attached files: (.+?)\]/);if(!b)return null;let c=(b.index??0)+b[0].length,d=a.slice(c).trim();return{paths:b[1].split(", ").map(a=>a.trim()).filter(Boolean),message:d}}(b),d=g?.get(a.id)??g?.get(b)??g?.get(c?.message??""),f=d?(0,e.jsx)("div",{className:"chat-user-html-content",dangerouslySetInnerHTML:{__html:d}}):(0,e.jsx)("p",{className:"whitespace-pre-wrap break-words",children:c?.message??b});return c?(0,e.jsxs)("div",{className:"flex flex-col items-end gap-1.5 py-2",children:[(0,e.jsx)(v,{paths:c.paths}),(c.message||d)&&(0,e.jsx)("div",{className:"max-w-[80%] w-fit rounded-2xl rounded-br-sm px-3 py-2 text-sm leading-6 break-words chat-message-font",style:{background:"var(--color-user-bubble)",color:"var(--color-user-bubble-text)"},children:f})]}):(0,e.jsx)("div",{className:"flex justify-end py-2",children:(0,e.jsx)("div",{className:"max-w-[80%] min-w-0 rounded-2xl rounded-br-sm px-3 py-2 text-sm leading-6 overflow-hidden break-words chat-message-font",style:{background:"var(--color-user-bubble)",color:"var(--color-user-bubble-text)"},children:f})})}return(0,e.jsxs)("div",{className:"py-3 space-y-2 min-w-0 overflow-hidden group",children:[(0,e.jsx)(j.N,{initial:!1,children:s.map((a,d)=>{if("text"===a.type){let b=a.text.match(/^\[error\]\s*([\s\S]*)$/);return b?(0,e.jsxs)("div",{className:"chat-message-font flex items-start gap-2 rounded-xl px-3 py-2 text-[13px] leading-relaxed overflow-hidden",style:{background:"color-mix(in srgb, var(--color-error) 6%, var(--color-surface))",color:"var(--color-error)",border:"1px solid color-mix(in srgb, var(--color-error) 18%, transparent)"},children:[(0,e.jsx)("span",{className:"flex-shrink-0 mt-0.5","aria-hidden":"true",children:(0,e.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,e.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,e.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}),(0,e.jsx)("span",{className:"whitespace-pre-wrap break-all min-w-0",children:b[1].trim()})]},d):(0,e.jsx)(k.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},className:"chat-prose chat-message-font text-sm",style:{color:"var(--color-text)"},children:(0,e.jsx)(l.oz,{remarkPlugins:[m.A],components:x,children:a.text})},`text-${d}`)}if("report-artifact"===a.type)return(0,e.jsx)(k.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,e.jsx)(B,{config:a.config})},`report-${d}`);if("diff-artifact"===a.type)return(0,e.jsx)(k.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,e.jsx)(q.a,{diff:a.diff})},`diff-${d}`);if("subagent-card"===a.type){let b=a.task.length>80?a.task.slice(0,80)+"...":a.task,f="running"===a.status;return(0,e.jsx)(k.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,e.jsx)("button",{type:"button",onClick:()=>c?.(a.sessionKey??a.task),className:"w-full text-left rounded-xl px-3.5 py-2.5 transition-colors cursor-pointer",style:{background:"var(--color-accent-light)",border:"1px solid color-mix(in srgb, var(--color-accent) 20%, transparent)"},children:(0,e.jsxs)("div",{className:"flex items-center gap-2.5",children:[f?(0,e.jsx)("span",{className:"inline-block w-2 h-2 rounded-full animate-pulse flex-shrink-0",style:{background:"var(--color-accent)"}}):(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{color:"var(--color-accent)"},children:[(0,e.jsx)("path",{d:"M16 3h5v5"}),(0,e.jsx)("path",{d:"m21 3-7 7"}),(0,e.jsx)("path",{d:"M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6"})]}),(0,e.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,e.jsx)("div",{className:"flex items-center gap-2",children:(0,e.jsx)("span",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--color-accent)"},children:f?"Running Subagent":"Subagent"})}),(0,e.jsx)("p",{className:"text-xs mt-0.5 leading-relaxed",style:{color:"var(--color-text)"},children:a.label||b})]}),(0,e.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0 opacity-40",style:{color:"var(--color-text)"},children:(0,e.jsx)("path",{d:"m9 18 6-6-6-6"})})]})})},`subagent-${d}`)}return(0,e.jsx)(k.P.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.2,ease:"easeOut"},children:(0,e.jsx)(n.I,{parts:a.parts,isStreaming:b})},`chain-${d}`)})}),!b&&(0,e.jsx)(A,{messageId:a.id,sessionId:f})]})});d()}catch(a){d(a)}})},32347:(a,b,c)=>{"use strict";function d(a){return a.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}c.d(b,{B:()=>d})},32468:(a,b)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"}),b.isPrototype=function(a){let b=a?.constructor;return a===("function"==typeof b?b.prototype:Object.prototype)}},32513:(a,b,c)=>{"use strict";c.d(b,{x:()=>n});var d=c(36927),e=c(15962),f=c(81918),g=c(12563),h=c(79924);function i(a){return null==a?"":"object"==typeof a?JSON.stringify(a):"string"==typeof a?a:"number"==typeof a||"boolean"==typeof a||"bigint"==typeof a?String(a):""}function j({entry:a,fields:b,members:c,relationLabels:e,onEntryClick:g}){let h=i(a.entry_id)||"",{attributes:j,listeners:l,setNodeRef:m,isDragging:n}=(0,f.PM)({id:h,data:{entry:a}});return(0,d.jsx)("div",{ref:m,...l,...j,onClick:a=>{!n&&g&&(a.stopPropagation(),g(h))},className:"rounded-lg p-3 mb-2 transition-all duration-100 cursor-grab active:cursor-grabbing select-none",style:{background:"var(--color-surface)",border:`1px solid ${n?"var(--color-accent)":"var(--color-border)"}`,opacity:n?.4:1,transform:n?"scale(1.02)":void 0},children:(0,d.jsx)(k,{entry:a,fields:b,members:c,relationLabels:e})})}function k({entry:a,fields:b,members:c,relationLabels:e}){let f=function(a,b){let c=b.find(a=>a.name.toLowerCase().includes("name")||a.name.toLowerCase().includes("title"));return c?i(a[c.name])||"Untitled":i(a[b[0]?.name])||"Untitled"}(a,b),j=b.filter(b=>"richtext"!==b.type&&null!==a[b.name]&&void 0!==a[b.name]&&""!==a[b.name]).slice(0,4),k=b.find(a=>a.name.toLowerCase().includes("name")||a.name.toLowerCase().includes("title"));return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:"text-sm font-medium mb-1.5 truncate",style:{color:"var(--color-text)"},children:f}),(0,d.jsx)("div",{className:"space-y-1",children:j.filter(a=>a!==k).slice(0,3).map(b=>{let f=a[b.name];if(!f)return null;let j=i(f);if("user"===b.type){let a=c?.find(a=>a.id===j);a&&(j=a.name)}else if("relation"===b.type){let a=e?.[b.name];j=(function(a){if(!a)return[];let b=a.trim();if(!b)return[];if(b.startsWith("["))try{let a=JSON.parse(b);if(Array.isArray(a))return a.map(String).filter(Boolean)}catch{}return[b]})(j).map(b=>a?.[b]??b).join(", ")}let k="tags"===b.type?(0,h.k)(f):[];return(0,d.jsxs)("div",{className:"flex items-center gap-1.5 text-xs",children:[(0,d.jsxs)("span",{style:{color:"var(--color-text-muted)"},children:[b.name,":"]}),"enum"===b.type?(0,d.jsx)(l,{value:i(f),enumValues:b.enum_values,enumColors:b.enum_colors}):"tags"===b.type?(0,d.jsxs)("span",{className:"flex items-center gap-0.5 flex-wrap",children:[k.slice(0,3).map(a=>{let b=(0,g.KJ)(a);return"link"===b.kind&&b.href?(0,d.jsx)("a",{href:b.href,target:"url"===b.linkType||"file"===b.linkType?"_blank":void 0,rel:"url"===b.linkType||"file"===b.linkType?"noopener noreferrer":void 0,onClick:a=>a.stopPropagation(),className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium hover:underline underline-offset-2",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-accent)"},children:b.text},a):(0,d.jsx)("span",{className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium",style:{background:"rgba(148, 163, 184, 0.12)",color:"var(--color-text-muted)"},children:a},a)}),k.length>3&&(0,d.jsxs)("span",{style:{color:"var(--color-text-muted)",opacity:.6},children:["+",k.length-3]})]}):"relation"===b.type?(0,d.jsxs)("span",{className:"truncate inline-flex items-center gap-0.5",style:{color:"#60a5fa"},children:[(0,d.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",style:{opacity:.5},children:[(0,d.jsx)("path",{d:"M7 7h10v10"}),(0,d.jsx)("path",{d:"M7 17 17 7"})]}),j]}):(0,d.jsx)("span",{className:"whitespace-pre-line line-clamp-2",style:{color:"var(--color-text)"},children:j})]},b.id)})})]})}function l({value:a,enumValues:b,enumColors:c}){let e=b?.indexOf(a)??-1,f=e>=0&&c?c[e]:"#94a3b8";return(0,d.jsx)("span",{className:"inline-flex items-center px-1.5 py-0 rounded text-[11px] font-medium",style:{background:`${f}20`,color:f},children:a})}function m({columnName:a,color:b,items:c,cardFields:g,members:h,relationLabels:k,onEntryClick:l,isOver:m,groupFieldId:n,objectName:o,onRefresh:p}){let{setNodeRef:q}=(0,f.zM)({id:`column:${a}`}),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(a),[v,w]=(0,e.useState)(!1),x=(0,e.useRef)(null),y=(0,e.useCallback)(async()=>{let b=t.trim();if(!b||b===a||!n){s(!1),u(a);return}w(!0);try{(await fetch(`/api/workspace/objects/${encodeURIComponent(o)}/fields/${encodeURIComponent(n)}/enum-rename`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldValue:a,newValue:b})})).ok?p?.():u(a)}catch{u(a)}finally{w(!1),s(!1)}},[t,a,n,o,p]);return(0,d.jsxs)("div",{ref:q,className:"flex-shrink-0 flex flex-col rounded-xl transition-colors duration-150",style:{width:"280px",background:m?"var(--color-surface)":"var(--color-bg)",border:`1px solid ${m?"var(--color-accent)":"var(--color-border)"}`},children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b",style:{borderColor:"var(--color-border)"},children:[(0,d.jsx)("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:b}}),r?(0,d.jsx)("input",{ref:x,value:t,onChange:a=>u(a.target.value),onBlur:y,onKeyDown:b=>{"Enter"===b.key&&y(),"Escape"===b.key&&(u(a),s(!1))},disabled:v,className:"text-sm font-medium flex-1 bg-transparent outline-none rounded px-1 -mx-1",style:{color:"var(--color-text)",border:"1px solid var(--color-accent)"}}):(0,d.jsx)("span",{className:"text-sm font-medium flex-1 cursor-text rounded px-1 -mx-1 hover:bg-[var(--color-surface-hover)] transition-colors",style:{color:"var(--color-text)"},onDoubleClick:()=>{n&&(u(a),s(!0))},title:n?"Double-click to rename":void 0,children:a}),(0,d.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)"},children:c.length})]}),(0,d.jsx)("div",{className:"flex-1 overflow-y-auto p-2",style:{minHeight:"80px"},children:0===c.length?(0,d.jsx)("div",{className:"flex items-center justify-center py-8 rounded-lg border border-dashed text-xs transition-colors",style:{borderColor:m?"var(--color-accent)":"var(--color-border)",color:m?"var(--color-accent)":"var(--color-text-muted)"},children:m?"Drop here":"No entries"}):c.map((a,b)=>(0,d.jsx)(j,{entry:a,fields:g,members:h,relationLabels:k,onEntryClick:l},i(a.entry_id)||String(b)))})]})}function n({objectName:a,fields:b,entries:c,statuses:g,members:h,relationLabels:l,onEntryClick:n,onRefresh:o}){let[p,q]=(0,e.useState)(null),[r,s]=(0,e.useState)(null),[t,u]=(0,e.useState)(c),v=(0,f.FR)((0,f.MS)(f.AN,{activationConstraint:{distance:5}})),w=(0,e.useMemo)(()=>{let a=b.find(a=>"enum"===a.type&&a.name.toLowerCase().includes("status"));return a||(b.find(a=>"enum"===a.type)??null)},[b]),x=(0,e.useMemo)(()=>{if(g.length>0)return g.map(a=>({name:a.name,color:a.color??"#94a3b8"}));if(w?.enum_values)return w.enum_values.map((a,b)=>({name:a,color:w.enum_colors?.[b]??"#94a3b8"}));let a=new Set;for(let b of t){let c=w?b[w.name]:void 0;c&&a.add(i(c))}return Array.from(a).map(a=>({name:a,color:"#94a3b8"}))},[g,w,t]),y=(0,e.useMemo)(()=>{let a={};for(let b of x)a[b.name]=[];for(let b of(a._ungrouped=[],t)){let c=w?i(b[w.name]):"";a[c]?a[c].push(b):a._ungrouped.push(b)}return a},[x,t,w]),z=b.filter(a=>a!==w),A=(0,e.useMemo)(()=>p?t.find(a=>String(a.entry_id)===p)??null:null,[p,t]),B=(0,e.useCallback)(a=>{q(String(a.active.id))},[]),C=(0,e.useCallback)(a=>{let b=a.over?.id?String(a.over.id):null;b?.startsWith("column:")?s(b.replace("column:","")):s(null)},[]),D=(0,e.useCallback)(async b=>{q(null),s(null);let{active:c,over:d}=b;if(!d||!w)return;let e=String(d.id);if(!e.startsWith("column:"))return;let f=e.replace("column:",""),g=String(c.id),h=t.find(a=>String(a.entry_id)===g);if(!h)return;let j=i(h[w.name]);if(j!==f){u(a=>a.map(a=>String(a.entry_id)===g?{...a,[w.name]:f}:a));try{(await fetch(`/api/workspace/objects/${encodeURIComponent(a)}/entries/${encodeURIComponent(g)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({fields:{[w.name]:f}})})).ok?o?.():u(a=>a.map(a=>String(a.entry_id)===g?{...a,[w.name]:j}:a))}catch{u(a=>a.map(a=>String(a.entry_id)===g?{...a,[w.name]:j}:a))}}},[w,t,a,o]);return w?(0,d.jsxs)(f.Mp,{sensors:v,collisionDetection:f.y$,onDragStart:B,onDragOver:C,onDragEnd:D,children:[(0,d.jsxs)("div",{className:"flex gap-4 overflow-x-auto pb-4 px-1",style:{minHeight:"400px"},children:[x.map(b=>(0,d.jsx)(m,{columnName:b.name,color:b.color,items:y[b.name]??[],cardFields:z,members:h,relationLabels:l,onEntryClick:n,isOver:r===b.name,groupFieldId:w.id,objectName:a,onRefresh:o},b.name)),y._ungrouped?.length>0&&(0,d.jsxs)("div",{className:"flex-shrink-0 flex flex-col rounded-xl",style:{width:"280px",background:"var(--color-bg)",border:"1px dashed var(--color-border)"},children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b",style:{borderColor:"var(--color-border)"},children:[(0,d.jsx)("span",{className:"text-sm font-medium",style:{color:"var(--color-text-muted)"},children:"Ungrouped"}),(0,d.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded-full",style:{background:"var(--color-surface)",color:"var(--color-text-muted)"},children:y._ungrouped.length})]}),(0,d.jsx)("div",{className:"flex-1 overflow-y-auto p-2",children:y._ungrouped.map((a,b)=>(0,d.jsx)(j,{entry:a,fields:z,members:h,relationLabels:l,onEntryClick:n},i(a.entry_id)||String(b)))})]})]}),(0,d.jsx)(f.Hd,{dropAnimation:null,children:A?(0,d.jsx)("div",{className:"rounded-lg p-3 shadow-xl",style:{width:"260px",background:"var(--color-surface)",border:"1px solid var(--color-accent)",transform:"rotate(2deg)"},children:(0,d.jsx)(k,{entry:A,fields:z,members:h,relationLabels:l})}):null})]}):(0,d.jsx)("div",{className:"flex flex-col items-center justify-center py-20 gap-3",children:(0,d.jsxs)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:["No enum field found for kanban grouping in"," ",(0,d.jsx)("span",{className:"font-medium",style:{color:"var(--color-text)"},children:a})]})})}},33873:a=>{"use strict";a.exports=require("path")},34487:(a,b,c)=>{"use strict";c.d(b,{f:()=>f});var d=c(2714),e=c(45722);function f(a,b,c){let f=(0,e.a)(a,c?.in);return isNaN(b)?(0,d.w)(c?.in||a,NaN):(b&&f.setDate(f.getDate()+b),f)}},35303:(a,b,c)=>{"use strict";c.d(b,{A:()=>d});let d=(0,c(15336).A)("file-text",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]])},35407:function(a,b){var c,d;"undefined"!=typeof self&&self,void 0===(d="function"==typeof(c=function(){function a(){}a.prototype.saveState=function(){return{idx:this.idx,input:this.input,groupIdx:this.groupIdx}},a.prototype.restoreState=function(a){this.idx=a.idx,this.input=a.input,this.groupIdx=a.groupIdx},a.prototype.pattern=function(a){this.idx=0,this.input=a,this.groupIdx=0,this.consumeChar("/");var b=this.disjunction();this.consumeChar("/");for(var c={type:"Flags",loc:{begin:this.idx,end:a.length},global:!1,ignoreCase:!1,multiLine:!1,unicode:!1,sticky:!1};this.isRegExpFlag();)switch(this.popChar()){case"g":h(c,"global");break;case"i":h(c,"ignoreCase");break;case"m":h(c,"multiLine");break;case"u":h(c,"unicode");break;case"y":h(c,"sticky")}if(this.idx!==this.input.length)throw Error("Redundant input: "+this.input.substring(this.idx));return{type:"Pattern",flags:c,value:b,loc:this.loc(0)}},a.prototype.disjunction=function(){var a=[],b=this.idx;for(a.push(this.alternative());"|"===this.peekChar();)this.consumeChar("|"),a.push(this.alternative());return{type:"Disjunction",value:a,loc:this.loc(b)}},a.prototype.alternative=function(){for(var a=[],b=this.idx;this.isTerm();)a.push(this.term());return{type:"Alternative",value:a,loc:this.loc(b)}},a.prototype.term=function(){return this.isAssertion()?this.assertion():this.atom()},a.prototype.assertion=function(){var a=this.idx;switch(this.popChar()){case"^":return{type:"StartAnchor",loc:this.loc(a)};case"$":return{type:"EndAnchor",loc:this.loc(a)};case"\\":switch(this.popChar()){case"b":return{type:"WordBoundary",loc:this.loc(a)};case"B":return{type:"NonWordBoundary",loc:this.loc(a)}}throw Error("Invalid Assertion Escape");case"(":switch(this.consumeChar("?"),this.popChar()){case"=":b="Lookahead";break;case"!":b="NegativeLookahead"}i(b);var b,c=this.disjunction();return this.consumeChar(")"),{type:b,value:c,loc:this.loc(a)}}throw Error("Internal Error - Should never get here!")},a.prototype.quantifier=function(a){var b=this.idx;switch(this.popChar()){case"*":c={atLeast:0,atMost:1/0};break;case"+":c={atLeast:1,atMost:1/0};break;case"?":c={atLeast:0,atMost:1};break;case"{":var c,d=this.integerIncludingZero();switch(this.popChar()){case"}":c={atLeast:d,atMost:d};break;case",":c=this.isDigit()?{atLeast:d,atMost:this.integerIncludingZero()}:{atLeast:d,atMost:1/0},this.consumeChar("}")}if(!0===a&&void 0===c)return;i(c)}if(!0!==a||void 0!==c)return i(c),"?"===this.peekChar(0)?(this.consumeChar("?"),c.greedy=!1):c.greedy=!0,c.type="Quantifier",c.loc=this.loc(b),c},a.prototype.atom=function(){var a,b=this.idx;switch(this.peekChar()){case".":a=this.dotAll();break;case"\\":a=this.atomEscape();break;case"[":a=this.characterClass();break;case"(":a=this.group()}return void 0===a&&this.isPatternCharacter()&&(a=this.patternCharacter()),i(a),a.loc=this.loc(b),this.isQuantifier()&&(a.quantifier=this.quantifier()),a},a.prototype.dotAll=function(){return this.consumeChar("."),{type:"Set",complement:!0,value:[f("\n"),f("\r"),f("\u2028"),f("\u2029")]}},a.prototype.atomEscape=function(){switch(this.consumeChar("\\"),this.peekChar()){case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":return this.decimalEscapeAtom();case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}},a.prototype.decimalEscapeAtom=function(){return{type:"GroupBackReference",value:this.positiveInteger()}},a.prototype.characterClassEscape=function(){var a,b=!1;switch(this.popChar()){case"d":a=j;break;case"D":a=j,b=!0;break;case"s":a=l;break;case"S":a=l,b=!0;break;case"w":a=k;break;case"W":a=k,b=!0}return i(a),{type:"Set",value:a,complement:b}},a.prototype.controlEscapeAtom=function(){var a;switch(this.popChar()){case"f":a=f("\f");break;case"n":a=f("\n");break;case"r":a=f("\r");break;case"t":a=f(" ");break;case"v":a=f("\v")}return i(a),{type:"Character",value:a}},a.prototype.controlLetterEscapeAtom=function(){this.consumeChar("c");var a=this.popChar();if(!1===/[a-zA-Z]/.test(a))throw Error("Invalid ");return{type:"Character",value:a.toUpperCase().charCodeAt(0)-64}},a.prototype.nulCharacterAtom=function(){return this.consumeChar("0"),{type:"Character",value:f("\0")}},a.prototype.hexEscapeSequenceAtom=function(){return this.consumeChar("x"),this.parseHexDigits(2)},a.prototype.regExpUnicodeEscapeSequenceAtom=function(){return this.consumeChar("u"),this.parseHexDigits(4)},a.prototype.identityEscapeAtom=function(){return{type:"Character",value:f(this.popChar())}},a.prototype.classPatternCharacterAtom=function(){switch(this.peekChar()){case"\n":case"\r":case"\u2028":case"\u2029":case"\\":case"]":throw Error("TBD");default:return{type:"Character",value:f(this.popChar())}}},a.prototype.characterClass=function(){var a=[],b=!1;for(this.consumeChar("["),"^"===this.peekChar(0)&&(this.consumeChar("^"),b=!0);this.isClassAtom();){var c=this.classAtom();if("Character"===c.type&&this.isRangeDash()){this.consumeChar("-");var d=this.classAtom();if("Character"===d.type){if(d.value<c.value)throw Error("Range out of order in character class");a.push({from:c.value,to:d.value})}else g(c.value,a),a.push(f("-")),g(d.value,a)}else g(c.value,a)}return this.consumeChar("]"),{type:"Set",complement:b,value:a}},a.prototype.classAtom=function(){switch(this.peekChar()){case"]":case"\n":case"\r":case"\u2028":case"\u2029":throw Error("TBD");case"\\":return this.classEscape();default:return this.classPatternCharacterAtom()}},a.prototype.classEscape=function(){switch(this.consumeChar("\\"),this.peekChar()){case"b":return this.consumeChar("b"),{type:"Character",value:f("\b")};case"d":case"D":case"s":case"S":case"w":case"W":return this.characterClassEscape();case"f":case"n":case"r":case"t":case"v":return this.controlEscapeAtom();case"c":return this.controlLetterEscapeAtom();case"0":return this.nulCharacterAtom();case"x":return this.hexEscapeSequenceAtom();case"u":return this.regExpUnicodeEscapeSequenceAtom();default:return this.identityEscapeAtom()}},a.prototype.group=function(){var a=!0;this.consumeChar("("),"?"===this.peekChar(0)?(this.consumeChar("?"),this.consumeChar(":"),a=!1):this.groupIdx++;var b=this.disjunction();this.consumeChar(")");var c={type:"Group",capturing:a,value:b};return a&&(c.idx=this.groupIdx),c},a.prototype.positiveInteger=function(){var a=this.popChar();if(!1===e.test(a))throw Error("Expecting a positive integer");for(;d.test(this.peekChar(0));)a+=this.popChar();return parseInt(a,10)},a.prototype.integerIncludingZero=function(){var a=this.popChar();if(!1===d.test(a))throw Error("Expecting an integer");for(;d.test(this.peekChar(0));)a+=this.popChar();return parseInt(a,10)},a.prototype.patternCharacter=function(){var a=this.popChar();switch(a){case"\n":case"\r":case"\u2028":case"\u2029":case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":throw Error("TBD");default:return{type:"Character",value:f(a)}}},a.prototype.isRegExpFlag=function(){switch(this.peekChar(0)){case"g":case"i":case"m":case"u":case"y":return!0;default:return!1}},a.prototype.isRangeDash=function(){return"-"===this.peekChar()&&this.isClassAtom(1)},a.prototype.isDigit=function(){return d.test(this.peekChar(0))},a.prototype.isClassAtom=function(a){switch(void 0===a&&(a=0),this.peekChar(a)){case"]":case"\n":case"\r":case"\u2028":case"\u2029":return!1;default:return!0}},a.prototype.isTerm=function(){return this.isAtom()||this.isAssertion()},a.prototype.isAtom=function(){if(this.isPatternCharacter())return!0;switch(this.peekChar(0)){case".":case"\\":case"[":case"(":return!0;default:return!1}},a.prototype.isAssertion=function(){switch(this.peekChar(0)){case"^":case"$":return!0;case"\\":switch(this.peekChar(1)){case"b":case"B":return!0;default:return!1}case"(":return"?"===this.peekChar(1)&&("="===this.peekChar(2)||"!"===this.peekChar(2));default:return!1}},a.prototype.isQuantifier=function(){var a=this.saveState();try{return void 0!==this.quantifier(!0)}catch(a){return!1}finally{this.restoreState(a)}},a.prototype.isPatternCharacter=function(){switch(this.peekChar()){case"^":case"$":case"\\":case".":case"*":case"+":case"?":case"(":case")":case"[":case"|":case"/":case"\n":case"\r":case"\u2028":case"\u2029":return!1;default:return!0}},a.prototype.parseHexDigits=function(a){for(var b="",d=0;d<a;d++){var e=this.popChar();if(!1===c.test(e))throw Error("Expecting a HexDecimal digits");b+=e}return{type:"Character",value:parseInt(b,16)}},a.prototype.peekChar=function(a){return void 0===a&&(a=0),this.input[this.idx+a]},a.prototype.popChar=function(){var a=this.peekChar(0);return this.consumeChar(),a},a.prototype.consumeChar=function(a){if(void 0!==a&&this.input[this.idx]!==a)throw Error("Expected: '"+a+"' but found: '"+this.input[this.idx]+"' at offset: "+this.idx);if(this.idx>=this.input.length)throw Error("Unexpected end of input");this.idx++},a.prototype.loc=function(a){return{begin:a,end:this.idx}};var b,c=/[0-9a-fA-F]/,d=/[0-9]/,e=/[1-9]/;function f(a){return a.charCodeAt(0)}function g(a,b){void 0!==a.length?a.forEach(function(a){b.push(a)}):b.push(a)}function h(a,b){if(!0===a[b])throw"duplicate flag "+b;a[b]=!0}function i(a){if(void 0===a)throw Error("Internal Error - Should never get here!")}var j=[];for(b=f("0");b<=f("9");b++)j.push(b);var k=[f("_")].concat(j);for(b=f("a");b<=f("z");b++)k.push(b);for(b=f("A");b<=f("Z");b++)k.push(b);var l=[f(" "),f("\f"),f("\n"),f("\r"),f(" "),f("\v"),f(" "),f("\xa0"),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f(" "),f("\u2028"),f("\u2029"),f(" "),f(" "),f(" "),f("\uFEFF")];function m(){}return m.prototype.visitChildren=function(a){for(var b in a){var c=a[b];a.hasOwnProperty(b)&&(void 0!==c.type?this.visit(c):Array.isArray(c)&&c.forEach(function(a){this.visit(a)},this))}},m.prototype.visit=function(a){switch(a.type){case"Pattern":this.visitPattern(a);break;case"Flags":this.visitFlags(a);break;case"Disjunction":this.visitDisjunction(a);break;case"Alternative":this.visitAlternative(a);break;case"StartAnchor":this.visitStartAnchor(a);break;case"EndAnchor":this.visitEndAnchor(a);break;case"WordBoundary":this.visitWordBoundary(a);break;case"NonWordBoundary":this.visitNonWordBoundary(a);break;case"Lookahead":this.visitLookahead(a);break;case"NegativeLookahead":this.visitNegativeLookahead(a);break;case"Character":this.visitCharacter(a);break;case"Set":this.visitSet(a);break;case"Group":this.visitGroup(a);break;case"GroupBackReference":this.visitGroupBackReference(a);break;case"Quantifier":this.visitQuantifier(a)}this.visitChildren(a)},m.prototype.visitPattern=function(a){},m.prototype.visitFlags=function(a){},m.prototype.visitDisjunction=function(a){},m.prototype.visitAlternative=function(a){},m.prototype.visitStartAnchor=function(a){},m.prototype.visitEndAnchor=function(a){},m.prototype.visitWordBoundary=function(a){},m.prototype.visitNonWordBoundary=function(a){},m.prototype.visitLookahead=function(a){},m.prototype.visitNegativeLookahead=function(a){},m.prototype.visitCharacter=function(a){},m.prototype.visitSet=function(a){},m.prototype.visitGroup=function(a){},m.prototype.visitGroupBackReference=function(a){},m.prototype.visitQuantifier=function(a){},{RegExpParser:a,BaseRegExpVisitor:m,VERSION:"0.5.0"}})?c.apply(b,[]):c)||(a.exports=d)},35724:(a,b,c)=>{"use strict";c.d(b,{Gt:()=>e,PP:()=>h,WG:()=>f,uv:()=>g});var d=c(53037);let{schedule:e,cancel:f,state:g,steps:h}=(0,c(61081).I)("undefined"!=typeof requestAnimationFrame?requestAnimationFrame:d.l,!0)},36075:(a,b,c)=>{"use strict";function d(a){return"object"==typeof a&&null!==a}c.d(b,{G:()=>d})},36525:(a,b,c)=>{"use strict";c.d(b,{A:()=>l});var d=c(36927),e=c(15962),f=c(41579),g=c(96554);function h(){return(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M5 12h14"}),(0,d.jsx)("path",{d:"M12 5v14"})]})}function i(){return(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M16 3h5v5"}),(0,d.jsx)("path",{d:"m21 3-7 7"}),(0,d.jsx)("path",{d:"M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6"})]})}function j(){return(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function k(){return(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"1"}),(0,d.jsx)("circle",{cx:"5",cy:"12",r:"1"}),(0,d.jsx)("circle",{cx:"19",cy:"12",r:"1"})]})}function l({sessions:a,activeSessionId:b,activeSessionTitle:c,streamingSessionIds:l,subagents:m,activeSubagentKey:n,onSelectSession:o,onNewSession:p,onSelectSubagent:q,onDeleteSession:r,onRenameSession:s,onCollapse:t,mobile:u,onClose:v,width:w,loading:x=!1}){let[y,z]=(0,e.useState)(null),[A,B]=(0,e.useState)(null),[C,D]=(0,e.useState)(""),E=(0,e.useCallback)(a=>{o(a),v?.()},[o,v]),F=(0,e.useCallback)(a=>{q?.(a),v?.()},[q,v]),G=(0,e.useCallback)(a=>{r?.(a)},[r]),H=(0,e.useCallback)((a,b)=>{B(a),D(b||"")},[]),I=(0,e.useCallback)(()=>{A&&C.trim()&&s?.(A,C.trim()),B(null),D("")},[A,C,s]),J=(0,e.useMemo)(()=>{let a=new Map;if(!m)return a;for(let b of m){let c=a.get(b.parentSessionId);c||(c=[],a.set(b.parentSessionId,c)),c.push(b)}return a},[m]),K=function(a){let b=new Date,c=new Date(b.getFullYear(),b.getMonth(),b.getDate()).getTime(),d=c-864e5,e=c-6048e5,f=c-2592e6,g=[],h=[],i=[],j=[],k=[];for(let b of a){let a=b.updatedAt;a>=c?g.push(b):a>=d?h.push(b):a>=e?i.push(b):a>=f?j.push(b):k.push(b)}let l=[];return g.length>0&&l.push({label:"Today",sessions:g}),h.length>0&&l.push({label:"Yesterday",sessions:h}),i.length>0&&l.push({label:"This Week",sessions:i}),j.length>0&&l.push({label:"This Month",sessions:j}),k.length>0&&l.push({label:"Older",sessions:k}),l}((0,e.useMemo)(()=>a.filter(a=>!a.id.includes(":subagent:")),[a])),L=u?"280px":w??260,M=(0,d.jsx)("aside",{className:`flex flex-col h-full shrink-0 ${u?"drawer-right":"border-l"}`,style:{width:"number"==typeof L?`${L}px`:L,minWidth:"number"==typeof L?`${L}px`:L,borderColor:"var(--color-border)",background:"var(--color-sidebar-bg)"},children:(0,d.jsxs)("div",{className:"flex-1 min-h-0 relative",children:[(0,d.jsx)("div",{className:"absolute inset-0 overflow-y-auto",style:{paddingTop:40},children:x&&0===a.length?(0,d.jsxs)("div",{className:"px-4 py-8 flex flex-col items-center justify-center min-h-[120px]",children:[(0,d.jsx)(f.V,{name:"braille",className:"text-xl mb-2",style:{color:"var(--color-text-muted)"}}),(0,d.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading…"})]}):0===a.length?(0,d.jsxs)("div",{className:"px-4 py-8 text-center",children:[(0,d.jsx)("div",{className:"mx-auto w-10 h-10 rounded-xl flex items-center justify-center mb-3",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:(0,d.jsx)(j,{})}),(0,d.jsxs)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:["No conversations yet.",(0,d.jsx)("br",{}),"Start a new chat to begin."]})]}):(0,d.jsx)("div",{className:"px-2 py-1",children:K.map(a=>(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{className:"px-2 pt-3 pb-1 text-[10px] font-medium uppercase tracking-wider",style:{color:"var(--color-text-muted)"},children:a.label}),a.sessions.map(a=>{let c=a.id===b&&!n,e=a.id===y,h=l?.has(a.id)??!1,j=J.get(a.id);return(0,d.jsxs)("div",{className:"group relative",onMouseEnter:()=>z(a.id),onMouseLeave:()=>z(null),children:[(0,d.jsxs)("div",{className:"flex items-stretch w-full rounded-lg",style:{background:c?"var(--color-chat-sidebar-active-bg)":e?"var(--color-surface-hover)":"transparent"},children:[A===a.id?(0,d.jsx)("form",{className:"flex-1 min-w-0 px-2 py-1.5",onSubmit:a=>{a.preventDefault(),I()},children:(0,d.jsx)("input",{type:"text",value:C,onChange:a=>D(a.target.value),onBlur:I,onKeyDown:a=>{"Escape"===a.key&&(B(null),D(""))},autoFocus:!0,className:"w-full text-xs font-medium px-1 py-0.5 rounded outline-none border",style:{color:"var(--color-text)",background:"var(--color-surface)",borderColor:"var(--color-border)"}})}):(0,d.jsxs)("button",{type:"button",onClick:()=>E(a.id),className:"flex-1 min-w-0 text-left px-2 py-2 rounded-l-lg transition-colors cursor-pointer",children:[(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[h&&(0,d.jsx)(f.V,{name:"braille",className:"text-[10px] flex-shrink-0",style:{color:"var(--color-chat-sidebar-muted)"}}),(0,d.jsx)("div",{className:"text-xs font-medium truncate",style:{color:c?"var(--color-chat-sidebar-active-text)":"var(--color-text)"},children:a.title||"Untitled chat"})]}),(0,d.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",style:{paddingLeft:h?"calc(0.375rem + 6px)":void 0},children:[(0,d.jsx)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:function(a){let b=Math.floor((Date.now()-a)/1e3);if(b<60)return"just now";let c=Math.floor(b/60);if(c<60)return`${c}m ago`;let d=Math.floor(c/60);if(d<24)return`${d}h ago`;let e=Math.floor(d/24);if(e<30)return`${e}d ago`;let f=Math.floor(e/30);return f<12?`${f}mo ago`:`${Math.floor(f/12)}y ago`}(a.updatedAt)}),a.messageCount>0&&(0,d.jsxs)("span",{className:"text-[10px]",style:{color:"var(--color-text-muted)"},children:[a.messageCount," msg",1!==a.messageCount?"s":""]})]})]}),r&&(0,d.jsx)("div",{className:`shrink-0 flex items-center pr-1 transition-opacity ${e?"opacity-100":"opacity-0"}`,children:(0,d.jsxs)(g.rI,{children:[(0,d.jsx)(g.ty,{onClick:a=>a.stopPropagation(),className:"flex items-center justify-center w-6 h-6 rounded-md",style:{color:"var(--color-text-muted)"},title:"More options","aria-label":"More options",children:(0,d.jsx)(k,{})}),(0,d.jsxs)(g.SQ,{align:"end",side:"bottom",children:[(0,d.jsxs)(g._2,{onSelect:()=>H(a.id,a.title),children:[(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"})}),"Rename"]}),(0,d.jsxs)(g._2,{variant:"destructive",onSelect:()=>G(a.id),children:[(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M3 6h18"}),(0,d.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,d.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]}),"Delete"]})]})]})})]}),j&&j.length>0&&(0,d.jsx)("div",{className:"ml-4 border-l",style:{borderColor:"var(--color-border)"},children:j.map(a=>{let b=n===a.childSessionKey,c="running"===a.status,e=a.label||a.task,g=e.length>40?e.slice(0,40)+"...":e;return(0,d.jsx)("button",{type:"button",onClick:()=>F(a.childSessionKey),className:"w-full text-left pl-3 pr-2 py-1.5 rounded-r-lg transition-colors cursor-pointer",style:{background:b?"var(--color-chat-sidebar-active-bg)":"transparent"},children:(0,d.jsxs)("div",{className:"flex items-center gap-1.5",children:[c&&(0,d.jsx)(f.V,{name:"braille",className:"text-[9px] flex-shrink-0",style:{color:"var(--color-chat-sidebar-muted)"}}),(0,d.jsx)(i,{}),(0,d.jsx)("span",{className:"text-[11px] truncate",style:{color:b?"var(--color-chat-sidebar-active-text)":"var(--color-text-muted)"},children:g})]})},a.childSessionKey)})})]},a.id)})]},a.label))})}),(0,d.jsxs)("div",{className:"absolute top-0 left-0 right-0 z-10 flex items-center justify-between border-b px-4 py-2 backdrop-blur-md",style:{height:40,borderColor:"var(--color-border)",background:"color-mix(in srgb, var(--color-sidebar-bg) 80%, transparent)"},children:[(0,d.jsxs)("div",{className:"min-w-0 flex-1 flex items-center gap-1.5",children:[t&&(0,d.jsx)("button",{type:"button",onClick:t,className:"p-1 rounded-md shrink-0 transition-colors hover:bg-black/5",style:{color:"var(--color-text-muted)"},title:"Hide chat sidebar (⌘⇧B)",children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),(0,d.jsx)("path",{d:"M15 3v18"})]})}),(0,d.jsx)("span",{className:"text-xs font-medium truncate block",style:{color:"var(--color-text)"},children:"Chats"})]}),(0,d.jsxs)("button",{type:"button",onClick:p,className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium transition-colors cursor-pointer shrink-0 ml-1.5",style:{color:"var(--color-chat-sidebar-active-text)",background:"var(--color-chat-sidebar-active-bg)"},title:"New chat",children:[(0,d.jsx)(h,{}),"New"]})]})]})});return u?(0,d.jsx)("div",{className:"drawer-backdrop",onClick:()=>void v?.(),children:(0,d.jsx)("div",{onClick:a=>a.stopPropagation(),className:"fixed inset-y-0 right-0 z-50",children:M})}):M}},36747:(a,b,c)=>{"use strict";c.d(b,{Ch:()=>W});var d=c(36927),e=c(15962);function f(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function g(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function h(a){for(var b=1;b<arguments.length;b++){var c=null!=arguments[b]?arguments[b]:{};b%2?g(Object(c),!0).forEach(function(b){var d;d=c[b],b in a?Object.defineProperty(a,b,{value:d,enumerable:!0,configurable:!0,writable:!0}):a[b]=d}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(c)):g(Object(c)).forEach(function(b){Object.defineProperty(a,b,Object.getOwnPropertyDescriptor(c,b))})}return a}function i(a){return function b(){for(var c=this,d=arguments.length,e=Array(d),f=0;f<d;f++)e[f]=arguments[f];return e.length>=a.length?a.apply(this,e):function(){for(var a=arguments.length,d=Array(a),f=0;f<a;f++)d[f]=arguments[f];return b.apply(c,[].concat(e,d))}}}function j(a){return({}).toString.call(a).includes("Object")}function k(a){return"function"==typeof a}var l=i(function(a,b){throw Error(a[b]||a.default)})({initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"}),m={changes:function(a,b){return j(b)||l("changeType"),Object.keys(b).some(function(b){return!Object.prototype.hasOwnProperty.call(a,b)})&&l("changeField"),b},selector:function(a){k(a)||l("selectorType")},handler:function(a){k(a)||j(a)||l("handlerType"),j(a)&&Object.values(a).some(function(a){return!k(a)})&&l("handlersType")},initial:function(a){a||l("initialIsRequired"),j(a)||l("initialType"),Object.keys(a).length||l("initialContent")}};function n(a,b){return k(b)?b(a.current):b}function o(a,b){return a.current=h(h({},a.current),b),b}function p(a,b,c){return k(b)?b(a.current):Object.keys(c).forEach(function(c){var d;return null==(d=b[c])?void 0:d.call(b,a.current[c])}),c}var q={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:"Deprecation warning!\n You are using deprecated way of configuration.\n\n Instead of using\n monaco.config({ urls: { monacoBase: '...' } })\n use\n monaco.config({ paths: { vs: '...' } })\n\n For more please check the link https://github.com/suren-atoyan/monaco-loader#config\n "},r=(function(a){return function b(){for(var c=this,d=arguments.length,e=Array(d),f=0;f<d;f++)e[f]=arguments[f];return e.length>=a.length?a.apply(this,e):function(){for(var a=arguments.length,d=Array(a),f=0;f<a;f++)d[f]=arguments[f];return b.apply(c,[].concat(e,d))}}})(function(a,b){throw Error(a[b]||a.default)})(q),s=function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return function(a){return b.reduceRight(function(a,b){return b(a)},a)}},t={type:"cancelation",msg:"operation is manually canceled"};function u(a){var b=!1,c=new Promise(function(c,d){a.then(function(a){return b?d(t):c(a)}),a.catch(d)});return c.cancel=function(){return b=!0},c}var v=function(a,b){return function(a){if(Array.isArray(a))return a}(a)||function(a,b){var c=null==a?null:"undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(null!=c){var d,e,f,g,h=[],i=!0,j=!1;try{f=(c=c.call(a)).next,!1;for(;!(i=(d=f.call(c)).done)&&(h.push(d.value),h.length!==b);i=!0);}catch(a){j=!0,e=a}finally{try{if(!i&&null!=c.return&&(g=c.return(),Object(g)!==g))return}finally{if(j)throw e}}return h}}(a,2)||function(a,b){if(a){if("string"==typeof a)return f(a,b);var c=({}).toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?f(a,b):void 0}}(a,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(({create:function(a){var b=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};m.initial(a),m.handler(b);var c={current:a},d=i(p)(c,b),e=i(o)(c),f=i(m.changes)(a),g=i(n)(c);return[function(){var a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(a){return a};return m.selector(a),a(c.current)},function(a){(function(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return function(a){return b.reduceRight(function(a,b){return b(a)},a)}})(d,e,f,g)(a)}]}}).create({config:{paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}},isInitialized:!1,resolve:null,reject:null,monaco:null}),2),w=v[0],x=v[1];function y(a){return document.body.appendChild(a)}function z(a){var b,c,d=w(function(a){return{config:a.config,reject:a.reject}}),e=(b="".concat(d.config.paths.vs,"/loader.js"),c=document.createElement("script"),b&&(c.src=b),c);return e.onload=function(){return a()},e.onerror=d.reject,e}function A(){var a=w(function(a){return{config:a.config,resolve:a.resolve,reject:a.reject}}),b=window.require;b.config(a.config),b(["vs/editor/editor.main"],function(b){var c=b.m||b;B(c),a.resolve(c)},function(b){a.reject(b)})}function B(a){w().monaco||x({monaco:a})}var C=new Promise(function(a,b){return x({resolve:a,reject:b})}),D={init:function(){var a=w(function(a){return{monaco:a.monaco,isInitialized:a.isInitialized,resolve:a.resolve}});if(!a.isInitialized){if(x({isInitialized:!0}),a.monaco)return a.resolve(a.monaco),u(C);if(window.monaco&&window.monaco.editor)return B(window.monaco),a.resolve(window.monaco),u(C);s(y,z)(A)}return u(C)}},E={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},F={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},G=function({children:a}){return e.createElement("div",{style:F.container},a)},H=(0,e.memo)(function({width:a,height:b,isEditorReady:c,loading:d,_ref:f,className:g,wrapperProps:h}){return e.createElement("section",{style:{...E.wrapper,width:a,height:b},...h},!c&&e.createElement(G,null,d),e.createElement("div",{ref:f,style:{...E.fullWidth,...!c&&E.hide},className:g}))}),I=function(a){(0,e.useEffect)(a,[])},J=function(a,b,c=!0){let d=(0,e.useRef)(!0);(0,e.useEffect)(d.current||!c?()=>{d.current=!1}:a,b)};function K(){}function L(a,b,c,d){var e,f,g,h,i,j;return e=a,f=d,e.editor.getModel(M(e,f))||(g=a,h=b,i=c,j=d,g.editor.createModel(h,i,j?M(g,j):void 0))}function M(a,b){return a.Uri.parse(b)}(0,e.memo)(function({original:a,modified:b,language:c,originalLanguage:d,modifiedLanguage:f,originalModelPath:g,modifiedModelPath:h,keepCurrentOriginalModel:i=!1,keepCurrentModifiedModel:j=!1,theme:k="light",loading:l="Loading...",options:m={},height:n="100%",width:o="100%",className:p,wrapperProps:q={},beforeMount:r=K,onMount:s=K}){let[t,u]=(0,e.useState)(!1),[v,w]=(0,e.useState)(!0),x=(0,e.useRef)(null),y=(0,e.useRef)(null),z=(0,e.useRef)(null),A=(0,e.useRef)(s),B=(0,e.useRef)(r),C=(0,e.useRef)(!1);I(()=>{let a=D.init();return a.then(a=>(y.current=a)&&w(!1)).catch(a=>a?.type!=="cancelation"&&console.error("Monaco initialization: error:",a)),()=>{let b;return x.current?(b=x.current?.getModel(),void(i||b?.original?.dispose(),j||b?.modified?.dispose(),x.current?.dispose())):a.cancel()}}),J(()=>{if(x.current&&y.current){let b=x.current.getOriginalEditor(),e=L(y.current,a||"",d||c||"text",g||"");e!==b.getModel()&&b.setModel(e)}},[g],t),J(()=>{if(x.current&&y.current){let a=x.current.getModifiedEditor(),d=L(y.current,b||"",f||c||"text",h||"");d!==a.getModel()&&a.setModel(d)}},[h],t),J(()=>{let a=x.current.getModifiedEditor();a.getOption(y.current.editor.EditorOption.readOnly)?a.setValue(b||""):b!==a.getValue()&&(a.executeEdits("",[{range:a.getModel().getFullModelRange(),text:b||"",forceMoveMarkers:!0}]),a.pushUndoStop())},[b],t),J(()=>{x.current?.getModel()?.original.setValue(a||"")},[a],t),J(()=>{let{original:a,modified:b}=x.current.getModel();y.current.editor.setModelLanguage(a,d||c||"text"),y.current.editor.setModelLanguage(b,f||c||"text")},[c,d,f],t),J(()=>{y.current?.editor.setTheme(k)},[k],t),J(()=>{x.current?.updateOptions(m)},[m],t);let E=(0,e.useCallback)(()=>{if(!y.current)return;B.current(y.current);let e=L(y.current,a||"",d||c||"text",g||""),i=L(y.current,b||"",f||c||"text",h||"");x.current?.setModel({original:e,modified:i})},[c,b,f,a,d,g,h]),F=(0,e.useCallback)(()=>{!C.current&&z.current&&(x.current=y.current.editor.createDiffEditor(z.current,{automaticLayout:!0,...m}),E(),y.current?.editor.setTheme(k),u(!0),C.current=!0)},[m,k,E]);return(0,e.useEffect)(()=>{t&&A.current(x.current,y.current)},[t]),(0,e.useEffect)(()=>{v||t||F()},[v,t,F]),e.createElement(H,{width:o,height:n,isEditorReady:t,loading:l,_ref:z,className:p,wrapperProps:q})});var N=function(a){let b=(0,e.useRef)();return(0,e.useEffect)(()=>{b.current=a},[a]),b.current},O=new Map,P=(0,e.memo)(function({defaultValue:a,defaultLanguage:b,defaultPath:c,value:d,language:f,path:g,theme:h="light",line:i,loading:j="Loading...",options:k={},overrideServices:l={},saveViewState:m=!0,keepCurrentModel:n=!1,width:o="100%",height:p="100%",className:q,wrapperProps:r={},beforeMount:s=K,onMount:t=K,onChange:u,onValidate:v=K}){let[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(!0),A=(0,e.useRef)(null),B=(0,e.useRef)(null),C=(0,e.useRef)(null),E=(0,e.useRef)(t),F=(0,e.useRef)(s),G=(0,e.useRef)(),M=(0,e.useRef)(d),P=N(g),Q=(0,e.useRef)(!1),R=(0,e.useRef)(!1);I(()=>{let a=D.init();return a.then(a=>(A.current=a)&&z(!1)).catch(a=>a?.type!=="cancelation"&&console.error("Monaco initialization: error:",a)),()=>B.current?void(G.current?.dispose(),n?m&&O.set(g,B.current.saveViewState()):B.current.getModel()?.dispose(),B.current.dispose()):a.cancel()}),J(()=>{let e=L(A.current,a||d||"",b||f||"",g||c||"");e!==B.current?.getModel()&&(m&&O.set(P,B.current?.saveViewState()),B.current?.setModel(e),m&&B.current?.restoreViewState(O.get(g)))},[g],w),J(()=>{B.current?.updateOptions(k)},[k],w),J(()=>{B.current&&void 0!==d&&(B.current.getOption(A.current.editor.EditorOption.readOnly)?B.current.setValue(d):d!==B.current.getValue()&&(R.current=!0,B.current.executeEdits("",[{range:B.current.getModel().getFullModelRange(),text:d,forceMoveMarkers:!0}]),B.current.pushUndoStop(),R.current=!1))},[d],w),J(()=>{let a=B.current?.getModel();a&&f&&A.current?.editor.setModelLanguage(a,f)},[f],w),J(()=>{void 0!==i&&B.current?.revealLine(i)},[i],w),J(()=>{A.current?.editor.setTheme(h)},[h],w);let S=(0,e.useCallback)(()=>{if(!(!C.current||!A.current)&&!Q.current){F.current(A.current);let e=g||c,j=L(A.current,d||a||"",b||f||"",e||"");B.current=A.current?.editor.create(C.current,{model:j,automaticLayout:!0,...k},l),m&&B.current.restoreViewState(O.get(e)),A.current.editor.setTheme(h),void 0!==i&&B.current.revealLine(i),x(!0),Q.current=!0}},[a,b,c,d,f,g,k,l,m,h,i]);return(0,e.useEffect)(()=>{w&&E.current(B.current,A.current)},[w]),(0,e.useEffect)(()=>{y||w||S()},[y,w,S]),M.current=d,(0,e.useEffect)(()=>{w&&u&&(G.current?.dispose(),G.current=B.current?.onDidChangeModelContent(a=>{R.current||u(B.current.getValue(),a)}))},[w,u]),(0,e.useEffect)(()=>{if(w){let a=A.current.editor.onDidChangeMarkers(a=>{let b=B.current.getModel()?.uri;if(b&&a.find(a=>a.path===b.path)){let a=A.current.editor.getModelMarkers({resource:b});v?.(a)}});return()=>{a?.dispose()}}return()=>{}},[w,v]),e.createElement(H,{width:o,height:p,isEditorReady:w,loading:j,_ref:C,className:q,wrapperProps:r})}),Q=c(59448);let R={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",mjs:"javascript",cjs:"javascript",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",kt:"kotlin",swift:"swift",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",css:"css",scss:"scss",less:"less",html:"html",htm:"html",xml:"xml",svg:"xml",json:"json",jsonc:"json",yaml:"yaml",yml:"yaml",toml:"plaintext",md:"markdown",mdx:"markdown",sh:"shell",bash:"shell",zsh:"shell",fish:"shell",ps1:"powershell",sql:"sql",graphql:"graphql",gql:"graphql",dockerfile:"dockerfile",docker:"dockerfile",makefile:"plaintext",cmake:"plaintext",r:"r",lua:"lua",php:"php",vue:"html",svelte:"html",diff:"plaintext",patch:"plaintext",ini:"ini",env:"ini",tf:"plaintext",proto:"protobuf",zig:"plaintext",elixir:"plaintext",ex:"plaintext",erl:"plaintext",hs:"plaintext",scala:"scala",clj:"clojure",dart:"dart"};function S(a){let b=a.toLowerCase();return"dockerfile"===b||b.startsWith("dockerfile.")?"dockerfile":"makefile"===b||"gnumakefile"===b?"makefile":"cmakelists.txt"===b?"cmake":b.split(".").pop()??""}function T(a){return R[S(a)]??"plaintext"}let U=!1;function V(){return"undefined"!=typeof document&&document.documentElement.classList.contains("dark")}function W({content:a,filename:b,filePath:c,className:e}){let f=S(b);return"diff"===f||"patch"===f?(0,d.jsx)("div",{className:"max-w-4xl mx-auto px-6 py-8",children:(0,d.jsx)(Q.a,{diff:a})}):(0,d.jsx)(X,{content:a,filename:b,filePath:c,className:e})}function X({content:a,filename:b,filePath:c,className:f}){let g=(0,e.useRef)(null),h=(0,e.useRef)(null),[i,j]=(0,e.useState)(V()?"denchclaw-dark":"denchclaw-light"),[k,l]=(0,e.useState)("clean"),[m,n]=(0,e.useState)({line:1,col:1}),o=(0,e.useRef)(null),p=(0,e.useRef)(a),q=T(b),r=!!c,s=(0,e.useCallback)(async()=>{if(!c||!g.current)return;let a=g.current.getValue();l("saving");try{if(!(await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:c,content:a})})).ok)throw Error("Save failed");p.current=a,l("saved"),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>l("clean"),2e3)}catch{l("error"),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>l("dirty"),3e3)}},[c]),t=(0,e.useCallback)((a,b)=>{g.current=a,h.current=b,U||(U=!0,b.editor.defineTheme("denchclaw-light",{base:"vs",inherit:!0,rules:[],colors:{"editor.background":"#ffffff","editor.foreground":"#1c1c1a","editor.lineHighlightBackground":"#f5f4f1","editor.selectionBackground":"#2563eb20","editor.inactiveSelectionBackground":"#2563eb10","editorLineNumber.foreground":"#8a8a82","editorLineNumber.activeForeground":"#44443e","editorIndentGuide.background":"#00000010","editorIndentGuide.activeBackground":"#00000020","editor.selectionHighlightBackground":"#2563eb12","editorCursor.foreground":"#2563eb","editorWhitespace.foreground":"#00000010","editorBracketMatch.background":"#2563eb15","editorBracketMatch.border":"#2563eb40","editorGutter.background":"#ffffff","editorWidget.background":"#ffffff","editorWidget.border":"#00000014","editorSuggestWidget.background":"#ffffff","editorSuggestWidget.border":"#00000014","editorSuggestWidget.selectedBackground":"#f5f4f1","editorHoverWidget.background":"#ffffff","editorHoverWidget.border":"#00000014","input.background":"#f5f5f4","input.border":"#00000014","input.foreground":"#1c1c1a","minimap.background":"#ffffff","scrollbarSlider.background":"#00000012","scrollbarSlider.hoverBackground":"#00000020","scrollbarSlider.activeBackground":"#0000002a"}}),b.editor.defineTheme("denchclaw-dark",{base:"vs-dark",inherit:!0,rules:[],colors:{"editor.background":"#0c0c0b","editor.foreground":"#ececea","editor.lineHighlightBackground":"#1e1e1c","editor.selectionBackground":"#3b82f630","editor.inactiveSelectionBackground":"#3b82f618","editorLineNumber.foreground":"#78776f","editorLineNumber.activeForeground":"#b8b8b0","editorIndentGuide.background":"#ffffff08","editorIndentGuide.activeBackground":"#ffffff14","editor.selectionHighlightBackground":"#3b82f618","editorCursor.foreground":"#3b82f6","editorWhitespace.foreground":"#ffffff08","editorBracketMatch.background":"#3b82f620","editorBracketMatch.border":"#3b82f650","editorGutter.background":"#0c0c0b","editorWidget.background":"#161615","editorWidget.border":"#ffffff14","editorSuggestWidget.background":"#161615","editorSuggestWidget.border":"#ffffff14","editorSuggestWidget.selectedBackground":"#1e1e1c","editorHoverWidget.background":"#161615","editorHoverWidget.border":"#ffffff14","input.background":"#1e1e1c","input.border":"#ffffff14","input.foreground":"#ececea","minimap.background":"#0c0c0b","scrollbarSlider.background":"#ffffff12","scrollbarSlider.hoverBackground":"#ffffff20","scrollbarSlider.activeBackground":"#ffffff2a"}})),b.editor.setTheme(V()?"denchclaw-dark":"denchclaw-light"),a.addCommand(b.KeyMod.CtrlCmd|b.KeyCode.KeyS,()=>{s()}),a.onDidChangeCursorPosition(a=>{n({line:a.position.lineNumber,col:a.position.column})}),a.onDidChangeModelContent(()=>{a.getValue()!==p.current?l("dirty"):l("clean")}),a.focus()},[s]),u=function(a){let b=T(a);return"plaintext"===b?S(a)||"TEXT":b}(b),v=a.split("\n").length;return(0,d.jsxs)("div",{className:`flex flex-col h-full ${f??""}`,children:[(0,d.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 flex-shrink-0",style:{background:"var(--color-surface)",borderBottom:"1px solid var(--color-border)"},children:[(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--color-text-muted)",flexShrink:0},children:[(0,d.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,d.jsx)("polyline",{points:"8 6 2 12 8 18"})]}),(0,d.jsx)("span",{className:"text-sm font-medium truncate",style:{color:"var(--color-text)"},children:b}),"dirty"===k&&(0,d.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{background:"var(--color-text-muted)"},title:"Unsaved changes"}),(0,d.jsx)("div",{className:"flex-1"}),(0,d.jsx)("span",{className:"text-[11px] px-1.5 py-0.5 rounded font-medium",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)"},children:u.toUpperCase()}),(0,d.jsxs)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:[v," lines"]}),(0,d.jsxs)("span",{className:"text-[11px] tabular-nums",style:{color:"var(--color-text-muted)"},children:["Ln ",m.line,", Col ",m.col]}),r&&(0,d.jsxs)(d.Fragment,{children:["saving"===k&&(0,d.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:"Saving..."}),"saved"===k&&(0,d.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-success)"},children:"Saved"}),"error"===k&&(0,d.jsx)("span",{className:"text-[11px]",style:{color:"var(--color-error)"},children:"Save failed"}),(0,d.jsx)("button",{type:"button",onClick:()=>void s(),disabled:"dirty"!==k,className:"text-[11px] px-2 py-0.5 rounded transition-colors",style:{background:"dirty"===k?"var(--color-accent)":"var(--color-surface-hover)",color:"dirty"===k?"#fff":"var(--color-text-muted)",cursor:"dirty"===k?"pointer":"default",opacity:"dirty"===k?1:.5},children:"Save"})]})]}),(0,d.jsx)("div",{className:"flex-1 min-h-0",children:(0,d.jsx)(P,{defaultValue:a,language:q,theme:i,onMount:t,loading:(0,d.jsx)("div",{className:"flex items-center justify-center h-full",style:{background:"var(--color-bg)"},children:(0,d.jsx)("span",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Loading editor..."})}),options:{readOnly:!r,fontSize:13,lineHeight:20,fontFamily:"'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', Menlo, Monaco, 'Courier New', monospace",fontLigatures:!0,minimap:{enabled:!0,scale:1,showSlider:"mouseover"},scrollBeyondLastLine:!0,smoothScrolling:!0,cursorBlinking:"smooth",cursorSmoothCaretAnimation:"on",renderLineHighlight:"all",renderWhitespace:"selection",bracketPairColorization:{enabled:!0},guides:{bracketPairs:!0,indentation:!0,highlightActiveIndentation:!0},stickyScroll:{enabled:!0},folding:!0,foldingHighlight:!0,showFoldingControls:"mouseover",links:!0,wordWrap:"off",padding:{top:8,bottom:8},scrollbar:{verticalScrollbarSize:10,horizontalScrollbarSize:10,verticalSliderSize:10,horizontalSliderSize:10},overviewRulerBorder:!1,hideCursorInOverviewRuler:!0,automaticLayout:!0,tabSize:2,insertSpaces:!1,detectIndentation:!0,formatOnPaste:!1,formatOnType:!1,suggestOnTriggerCharacters:!0,quickSuggestions:!0,contextmenu:!0,mouseWheelZoom:!0,find:{addExtraSpaceOnTop:!1,autoFindInSelection:"multiline",seedSearchStringFromSelection:"selection"}}})})]})}},37519:(a,b,c)=>{let d=c(12089),{FormulaHelpers:e,Types:f}=c(28358);a.exports={ENCODEURL:a=>encodeURIComponent(e.accept(a,f.STRING)),FILTERXML:()=>{},WEBSERVICE:(a,b)=>{throw d.ERROR("WEBSERVICE is not supported in sync mode.")}}},37726:(a,b,c)=>{a.exports=c(543).uniqBy},37889:(a,b,c)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"});let d=c(53913),e=c(70016),f=c(30342),g=c(86975);b.iteratee=function(a){if(null==a)return d.identity;switch(typeof a){case"function":return a;case"object":if(Array.isArray(a)&&2===a.length)return g.matchesProperty(a[0],a[1]);return f.matches(a);case"string":case"symbol":case"number":return e.property(a)}}},38177:(a,b,c)=>{"use strict";c.a(a,async(a,d)=>{try{c.d(b,{X:()=>Q});var e=c(36927),f=c(42202),g=c(29415),h=c(15962),i=c(32206),j=c(90106),k=c(98790),l=c(62845),m=c(77317),n=c(53823),o=c(31038),p=c(35303),q=c(11916),r=c(64300),s=c(24939),t=c(55087),u=c(1784),v=c(42125),w=c(23932),x=c(25365),y=c(95786),z=c(11838),A=c(79833),B=c(51155),C=c(73432),D=c(42184),E=c(32314),F=c(41),G=c(45555),H=c(96554),I=c(41579),J=a([E]);E=(J.then?(await J)():J)[0];let O=[{id:"email-draft",label:"Draft an Email",icon:k.A,prompt:"Draft a professional follow-up email to a client after our initial meeting, thanking them and summarizing the next steps we discussed"},{id:"enrich-contacts",label:"Enrich Leads",icon:l.A,prompt:"When a new contact is added to my CRM, find their LinkedIn profile and company details and update the record"},{id:"invoice-reminder",label:"Invoice Reminder",icon:m.A,prompt:"Draft a friendly payment reminder email for an invoice that is 7 days overdue, including the invoice number and amount"},{id:"schedule-report",label:"Weekly Report",icon:n.A,prompt:"Set up a cron job that runs every Friday at 4pm to compile a summary of all completed tasks this week and email it to the team"},{id:"auto-tasks",label:"Auto Tasks",icon:o.A,prompt:"Create a workflow that automatically creates a task whenever someone mentions me in an email with a request or action item"},{id:"summarize-docs",label:"Summarize Docs",icon:p.A,prompt:"Read through all the documents in my workspace and create a concise summary of the key information across all files"},{id:"query-data",label:"Query Database",icon:q.A,prompt:"Connect to my database and show me the top 10 customers by revenue this quarter, including their contact details"},{id:"code-review",label:"Review Code",icon:r.A,prompt:"Review the code in my workspace for potential bugs, security issues, and performance improvements. Prioritize critical findings"},{id:"debug-error",label:"Debug Error",icon:s.A,prompt:"Help me debug this error I'm seeing in production. Walk me through the likely causes and how to fix each one"},{id:"daily-digest",label:"Daily Digest",icon:t.A,prompt:"Set up a daily digest that runs every morning at 9am summarizing my unread emails, calendar events, and pending tasks"},{id:"analyze-csv",label:"Analyze Data",icon:u.A,prompt:"Analyze the CSV file in my workspace — find trends, outliers, and generate a visual report with key insights"},{id:"write-content",label:"Write Content",icon:v.A,prompt:"Write a compelling blog post about how AI automation is transforming small business operations in 2026"},{id:"web-research",label:"Web Research",icon:w.A,prompt:"Research the top 5 competitors in my industry and create a comparison table with their pricing, features, and market position"},{id:"search-files",label:"Search Files",icon:x.A,prompt:"Search through all files in my workspace and find every mention of customer feedback, complaints, or feature requests"},{id:"brainstorm",label:"Brainstorm Ideas",icon:y.A,prompt:"Help me brainstorm 10 creative marketing campaign ideas for launching a new product to our existing customer base"},{id:"organize-files",label:"Organize Files",icon:z.A,prompt:"Look at all the files in my workspace and suggest a better folder structure. Then reorganize them for me"},{id:"create-spreadsheet",label:"Build Spreadsheet",icon:A.A,prompt:"Create a project tracking spreadsheet with columns for task name, assignee, status, priority, due date, and notes"},{id:"ai-strategy",label:"AI Strategy",icon:B.A,prompt:"Help me create an AI adoption strategy for my team — which tasks should we automate first for the biggest impact?"},{id:"meeting-prep",label:"Meeting Prep",icon:C.A,prompt:"Prepare a briefing document for my upcoming client meeting. Include their recent activity, open issues, and talking points"},{id:"build-workflow",label:"Build Workflow",icon:D.A,prompt:"Design an automated onboarding workflow for new clients — from welcome email to document collection to account setup"}];function K(a){let b=a.split(".").pop()?.toLowerCase()??"";return["jpg","jpeg","png","gif","webp","svg","bmp","ico","tiff","heic"].includes(b)?"image":["mp4","webm","mov","avi","mkv","flv"].includes(b)?"video":["mp3","wav","ogg","aac","flac","m4a"].includes(b)?"audio":"pdf"===b?"pdf":["js","ts","tsx","jsx","py","rb","go","rs","java","cpp","c","h","css","html","json","yaml","yml","toml","md","sh","bash","sql","swift","kt"].includes(b)?"code":["doc","docx","xls","xlsx","ppt","pptx","txt","rtf","csv","pages","numbers","key"].includes(b)?"document":"other"}let P={image:{bg:"rgba(16, 185, 129, 0.12)",fg:"#10b981"},video:{bg:"rgba(139, 92, 246, 0.12)",fg:"#8b5cf6"},audio:{bg:"rgba(245, 158, 11, 0.12)",fg:"#f59e0b"},pdf:{bg:"rgba(239, 68, 68, 0.12)",fg:"#ef4444"},code:{bg:"rgba(59, 130, 246, 0.12)",fg:"#3b82f6"},document:{bg:"rgba(107, 114, 128, 0.12)",fg:"#6b7280"},other:{bg:"rgba(107, 114, 128, 0.08)",fg:"#9ca3af"}};function L({category:a}){let b={width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};switch(a){case"image":return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,e.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,e.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});case"video":return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"}),(0,e.jsx)("rect",{x:"2",y:"6",width:"14",height:"12",rx:"2"})]});case"audio":return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,e.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,e.jsx)("circle",{cx:"18",cy:"16",r:"3"})]});case"pdf":return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,e.jsx)("path",{d:"M14 2v6h6"}),(0,e.jsx)("path",{d:"M10 13h4"}),(0,e.jsx)("path",{d:"M10 17h4"})]});case"code":return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("polyline",{points:"16 18 22 12 16 6"}),(0,e.jsx)("polyline",{points:"8 6 2 12 8 18"})]});case"document":return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,e.jsx)("path",{d:"M14 2v6h6"}),(0,e.jsx)("path",{d:"M16 13H8"}),(0,e.jsx)("path",{d:"M16 17H8"}),(0,e.jsx)("path",{d:"M10 9H8"})]});default:return(0,e.jsxs)("svg",{...b,children:[(0,e.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,e.jsx)("path",{d:"M14 2v6h6"})]})}}function M({msg:a,idx:b,onEdit:c,onSendNow:d,onRemove:f}){let[g,i]=(0,h.useState)(!1),[j,k]=(0,h.useState)(a.text),l=(0,h.useRef)(null),m=()=>{let b=j.trim();b&&b!==a.text?c(a.id,b):k(a.text),i(!1)};return(0,e.jsxs)("div",{className:`flex items-start gap-2.5 group py-2 ${b>0?"border-t":""}`,style:b>0?{borderColor:"var(--color-border)"}:void 0,children:[(0,e.jsx)("span",{className:"shrink-0 mt-px text-[11px] font-medium tabular-nums w-4",style:{color:"var(--color-text-muted)"},children:b+1}),g?(0,e.jsx)("textarea",{ref:l,className:"flex-1 text-[13px] leading-[1.45] min-w-0 resize-none rounded-md px-2 py-1 outline-none",style:{color:"var(--color-text-secondary)",background:"var(--color-bg)",border:"1px solid var(--color-border)"},rows:1,value:j,onChange:a=>{k(a.target.value);let b=l.current;b&&(b.style.height="auto",b.style.height=`${b.scrollHeight}px`)},onBlur:m,onKeyDown:b=>{"Enter"!==b.key||b.shiftKey||(b.preventDefault(),m()),"Escape"===b.key&&(k(a.text),i(!1))}}):(0,e.jsxs)("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[a.attachedFiles.length>0&&(0,e.jsx)("div",{className:"flex gap-1 shrink-0",children:a.attachedFiles.map(a=>{let b=K(a.name),c="image"===b?a.localUrl||`/api/workspace/raw-file?path=${encodeURIComponent(a.path)}`:a.path?`/api/workspace/thumbnail?path=${encodeURIComponent(a.path)}&size=100`:void 0;return(0,e.jsx)("img",{src:c,alt:a.name,className:"rounded object-cover",style:{height:28,width:28,background:"var(--color-surface-hover)"},onError:a=>{a.currentTarget.style.display="none"}},a.id)})}),(0,e.jsx)("p",{className:"text-[13px] leading-[1.45] line-clamp-1 min-w-0",style:{color:"var(--color-text-secondary)"},children:a.text||`${a.attachedFiles.length} ${1===a.attachedFiles.length?"file":"files"}`})]}),!g&&(0,e.jsxs)("div",{className:"flex items-center gap-1 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,e.jsx)("button",{type:"button",className:"rounded-md p-1 transition-colors hover:bg-stone-100 dark:hover:bg-stone-800",title:"Edit message",onClick:()=>{k(a.text),i(!0)},children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-stone-400",children:[(0,e.jsx)("path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),(0,e.jsx)("path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"})]})}),(0,e.jsx)("button",{type:"button",className:"rounded-md p-1 transition-colors hover:bg-stone-100 dark:hover:bg-stone-800",title:"Send now",onClick:()=>d(a.id),children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-stone-400",children:[(0,e.jsx)("path",{d:"M12 19V5"}),(0,e.jsx)("path",{d:"m5 12 7-7 7 7"})]})}),(0,e.jsx)("button",{type:"button",className:"rounded-md p-1 transition-colors hover:bg-stone-100 dark:hover:bg-stone-800",title:"Remove from queue",onClick:()=>f(a.id),children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-stone-400",children:[(0,e.jsx)("path",{d:"M3 6h18"}),(0,e.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,e.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]})})]})]})}function N({files:a,compact:b,onRemove:c,onClearAll:d}){return 0===a.length?null:(0,e.jsx)("div",{className:`${b?"px-2":"px-3"} pt-2`,children:(0,e.jsx)("div",{className:"flex gap-2 overflow-x-auto pb-1",style:{scrollbarWidth:"thin"},children:a.map(a=>{let b=K(a.name),d=P[b]??P.other,f=a.path.replace(/^\/Users\/[^/]+/,"~").replace(/^\/home\/[^/]+/,"~").replace(/^[A-Z]:\\Users\\[^\\]+/,"~");return(0,e.jsxs)("div",{className:"relative group flex-shrink-0 rounded-xl overflow-hidden",style:{background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:[(0,e.jsx)("button",{type:"button",onClick:()=>c(a.id),className:"absolute top-1 right-1 z-10 w-[18px] h-[18px] rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",style:{background:"rgba(0,0,0,0.55)",color:"white",backdropFilter:"blur(4px)"},children:(0,e.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:[(0,e.jsx)("path",{d:"M18 6 6 18"}),(0,e.jsx)("path",{d:"m6 6 12 12"})]})}),"image"===b?(0,e.jsx)("img",{src:a.localUrl||`/api/workspace/raw-file?path=${encodeURIComponent(a.path)}`,alt:a.name,className:"block rounded-xl object-cover",style:{height:80,width:"auto",minWidth:60,maxWidth:140,opacity:a.uploading?.6:1,background:"var(--color-bg-secondary)"},onError:a=>{a.currentTarget.style.display="none"}}):"pdf"===b&&a.path?(0,e.jsx)("img",{src:`/api/workspace/thumbnail?path=${encodeURIComponent(a.path)}&size=200`,alt:a.name,className:"block rounded-xl object-cover",style:{height:80,width:"auto",minWidth:60,maxWidth:140,opacity:a.uploading?.6:1,background:"var(--color-bg-secondary)"},onError:a=>{a.currentTarget.style.display="none"}}):(0,e.jsxs)("div",{className:"flex items-center gap-2.5 px-3 py-2.5",style:{opacity:a.uploading?.6:1},children:[(0,e.jsx)("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center shrink-0",style:{background:d.bg,color:d.fg},children:(0,e.jsx)(L,{category:b})}),(0,e.jsxs)("div",{className:"min-w-0 max-w-[140px]",children:[(0,e.jsx)("p",{className:"text-[11px] font-medium truncate",style:{color:"var(--color-text)"},title:a.path||a.name,children:a.name}),(0,e.jsx)("p",{className:"text-[9px] truncate",style:{color:"var(--color-text-muted)"},title:a.path||a.name,children:a.uploading?"Uploading...":f})]})]})]},a.id)})})})}let Q=(0,h.forwardRef)(function({fileContext:a,compact:b,sessionTitle:c,initialSessionId:d,onFileChanged:k,onActiveSessionChange:l,onSessionsChange:m,onSubagentSpawned:n,onSubagentClick:o,onFilePathClick:p,onDeleteSession:q,onRenameSession:r,sessionKey:s,subagentTask:t,subagentLabel:u,onBack:v},w){let x=!!s,y=(0,h.useRef)(null),[z,A]=(0,h.useState)(!0),[B,C]=(0,h.useState)(null),[D,J]=(0,h.useState)(!1),K=(0,h.useRef)(null),[L,P]=(0,h.useState)([]),[Q,R]=(0,h.useState)(!1),[S,T]=(0,h.useState)(!1),U=(0,h.useRef)(null),[V,W]=(0,h.useState)(null),X=(0,h.useRef)(new Set),Y=(0,h.useRef)(!1),Z=(0,h.useRef)(!0),[_,aa]=(0,h.useState)([]),ab=(0,h.useRef)(new Map),ac=(0,h.useRef)(null),[ad,ae]=(0,h.useState)([]),[af,ag]=(0,h.useState)(!1),[ah,ai]=(0,h.useState)(""),[aj,ak]=(0,h.useState)([]);(0,h.useEffect)(()=>{let a=[(()=>{let a=new Date().getHours();return a<12?"Good morning!":a<17?"Good afternoon!":"Good evening!"})(),"Ready to build?","Let's automate something?","What shall we tackle?","Ready to get things done?","Let's get to work?","How can I help?"];ai(a[Math.floor(Math.random()*a.length)])},[]),(0,h.useEffect)(()=>{let a=[...O].sort(()=>.5-Math.random());ak(a.slice(0,7))},[]);let al=(0,h.useCallback)(a=>{let b=O.find(b=>b.id===a);b&&(y.current?.setText(b.prompt),A(!1))},[]),am=a?.path??null,an=(0,h.useRef)(null);(0,h.useEffect)(()=>{an.current=B},[B]);let ao=(0,h.useRef)(s);(0,h.useEffect)(()=>{ao.current=s},[s]);let ap=(0,h.useMemo)(()=>new g.rL({api:"/api/chat",body:()=>{let a={},b=ao.current;b&&(a.sessionKey=b);let c=an.current;return c&&(a.sessionId=c),ac.current&&(a.userHtml=ac.current,ac.current=null),a}}),[]),{messages:aq,sendMessage:ar,status:as,stop:at,error:au,setMessages:av}=(0,f.Y_)({transport:ap}),aw="streaming"===as||"submitted"===as||S,ax=(0,h.useRef)(null),ay=(0,h.useRef)(!1),az=(0,h.useRef)(0);(0,h.useEffect)(()=>{let a=ax.current;if(!a)return;let b=()=>{ay.current=a.scrollHeight-a.scrollTop-a.clientHeight>80};return a.addEventListener("scroll",b,{passive:!0}),()=>a.removeEventListener("scroll",b)},[]),(0,h.useEffect)(()=>{!ay.current&&(az.current||(az.current=requestAnimationFrame(()=>{az.current=0,K.current?.scrollIntoView({behavior:"smooth"})})))},[aq]);let aA=(0,h.useCallback)(async a=>{let b={title:a};am&&(b.filePath=am);let c=await fetch("/api/web-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)});return(await c.json()).session.id},[am]),aB=(0,h.useCallback)(async(a,b,c)=>{let d=new AbortController;U.current=d;try{let e=c?.sessionKey?`sessionKey=${encodeURIComponent(c.sessionKey)}`:`sessionId=${encodeURIComponent(a)}`,f=await fetch(`/api/chat/stream?${e}`,{signal:d.signal});if(!f.ok||!f.body)return!1;if("false"===f.headers.get("X-Run-Active"))return f.body.cancel(),!1;T(!0);let g=function(){let a=[],b=-1,c=-1;return{processEvent:function(d){switch(d.type){case"user-message":b=-1,c=-1,a.push({type:"user-message",id:d.id,text:d.text??""});break;case"reasoning-start":a.push({type:"reasoning",text:"",state:"streaming"}),c=a.length-1;break;case"reasoning-delta":if(c>=0){let b=a[c];b.text+=d.delta}break;case"reasoning-end":if(c>=0){let b=a[c];delete b.state}c=-1;break;case"text-start":a.push({type:"text",text:""}),b=a.length-1;break;case"text-delta":if(b>=0){let c=a[b];c.text+=d.delta}break;case"text-end":b=-1;break;case"tool-input-start":a.push({type:"dynamic-tool",toolCallId:d.toolCallId,toolName:d.toolName,state:"input-available",input:{}});break;case"tool-input-available":for(let b=a.length-1;b>=0;b--){let c=a[b];if("dynamic-tool"===c.type&&c.toolCallId===d.toolCallId){c.input=d.input??{};break}}break;case"tool-output-partial":for(let b=a.length-1;b>=0;b--){let c=a[b];if("dynamic-tool"===c.type&&c.toolCallId===d.toolCallId){c.output=d.output??{};break}}break;case"tool-output-available":for(let b=a.length-1;b>=0;b--){let c=a[b];if("dynamic-tool"===c.type&&c.toolCallId===d.toolCallId){c.state="output-available",c.output=d.output??{};break}}break;case"tool-output-error":for(let b=a.length-1;b>=0;b--){let c=a[b];if("dynamic-tool"===c.type&&c.toolCallId===d.toolCallId){c.state="error",c.output={error:d.errorText};break}}}},getParts:()=>a.map(a=>({...a}))}}(),h=f.body.getReader(),i=new TextDecoder,j=`reconnect-${a}`,k="",l=!1,m=()=>{if(d.signal.aborted)return;let a={id:j,role:"assistant",parts:g.getParts()};av([...b,a])};for(;;){let a,{done:b,value:c}=await h.read();if(b)break;for(k+=i.decode(c,{stream:!0});-1!==(a=k.indexOf("\n\n"));){let b=k.slice(0,a);if(k=k.slice(a+2),b.startsWith("data: "))try{let a=JSON.parse(b.slice(6));g.processEvent(a)}catch{}}l||(l=!0,requestAnimationFrame(()=>{l=!1,m()}))}if(m(),!d.signal.aborted){for(let a of b)X.current.add(a.id);X.current.add(j)}return T(!1),U.current=null,!0}catch(a){return"AbortError"!==a.name&&console.error("Reconnection error:",a),T(!1),U.current=null,!1}},[av]),aC=(0,h.useRef)(null);aC.current=async()=>{if(!am)return[];try{let a=await fetch(`/api/web-sessions?filePath=${encodeURIComponent(am)}`);return(await a.json()).sessions||[]}catch{return[]}},(0,h.useEffect)(()=>{if(!am||x)return;let a=!1;return an.current=null,C(null),l?.(null),av([]),X.current.clear(),Z.current=!0,(async()=>{let b=await aC.current?.()??[];if(!a&&(aa(b),b.length>0)){let c=(d?b.find(a=>a.id===d):void 0)??b[0];C(c.id),an.current=c.id,l?.(c.id),Z.current=!1;try{let b=await fetch(`/api/web-sessions/${c.id}`);if(a)return;let d=(await b.json()).messages||[],e=d.some(a=>a._streaming)?d.filter(a=>!a._streaming):d;for(let a of e)"user"===a.role&&a.html&&ab.current.set(a.id,a.html);let f=e.map(a=>(X.current.add(a.id),{id:a.id,role:a.role,parts:a.parts??[{type:"text",text:a.content}]}));a||av(f),a||await aB(c.id,f)}catch{}}})(),()=>{a=!0}},[am,aB]);let aD=(0,h.useRef)(!1);(0,h.useEffect)(()=>{am||x||!d||aD.current||(aD.current=!0,aK(d))},[]),(0,h.useEffect)(()=>{if(!s||!t)return;let a=!1;U.current?.abort(),at(),X.current.clear(),ae([]);let b={id:`task-${s}`,role:"user",parts:[{type:"text",text:t}]};return av([b]),(async()=>{if(a)return;let c=[b];try{let d=await fetch(`/api/web-sessions/${encodeURIComponent(s)}`);if(a)return;if(d.ok){let e=(await d.json()).messages||[],f=e.some(a=>a._streaming)?e.filter(a=>!a._streaming):e;if(f.length>0){for(let a of f)"user"===a.role&&a.html&&ab.current.set(a.id,a.html);let d=f.map(a=>(X.current.add(a.id),{id:a.id,role:a.role,parts:a.parts??[{type:"text",text:a.content}]}));c=[b,...d],a||av(c)}}}catch{}a||await aB(s,c,{sessionKey:s})})(),()=>{a=!0,U.current?.abort()}},[s,t,aB]);let[aE,aF]=(0,h.useState)(!1);(0,h.useEffect)(()=>{if(!B||!n)return;let a=!1,b=async()=>{try{let b=await fetch(`/api/chat/subagents?sessionId=${encodeURIComponent(B)}`);if(a||!b.ok)return;let c=(await b.json()).subagents??[],d=!1;for(let a of c)"running"===a.status&&(d=!0),n({childSessionKey:a.sessionKey,runId:a.runId,task:a.task,label:a.label,parentSessionId:B,status:a.status});a||aF(d)}catch{}};b();let c=setInterval(b,3e3);return()=>{a=!0,clearInterval(c)}},[B,n]);let aG=(0,h.useRef)(as);(0,h.useEffect)(()=>{let a="streaming"===aG.current||"submitted"===aG.current,b="ready"===as;if(a&&b&&B){for(let a of aq)X.current.add(a.id);am&&aC.current?.().then(a=>{aa(a)}),am&&k&&fetch(`/api/workspace/file?path=${encodeURIComponent(am)}`).then(a=>a.json()).then(a=>{a.content&&k(a.content)}).catch(()=>{}),m?.()}aG.current=as},[as,aq,B,am,k,m]),(0,h.useEffect)(()=>{let a="streaming"===aG.current||"submitted"===aG.current,b="ready"===as;if(a&&b){let a=aq[aq.length-1];a?.role==="assistant"&&a.parts.some(a=>"text"===a.type&&a.text.trim().length>0||"tool-invocation"===a.type)||au?W(null):W("No response received from agent.")}"submitted"===as&&W(null)},[as,aq,au]);let aH=(0,h.useRef)(()=>{}),aI=(0,h.useCallback)(async(b,c,d,e)=>{let f=b.trim().length>0,g=c.length>0,h=e?e.filter(a=>!a.uploading&&a.path):L.filter(a=>!a.uploading&&a.path),i=h.length>0;if(!f&&!g&&!i)return;let j=b.trim(),k=[...h];if("/new"===j.toLowerCase()){for(let a of L)a.localUrl&&URL.revokeObjectURL(a.localUrl);P([]),aH.current();return}if(aw){e||P([]),ae(a=>[...a,{id:crypto.randomUUID(),text:j,html:d,mentionedFiles:c,attachedFiles:k,createdAt:Date.now()}]);return}if(!e&&k.length>0){for(let a of L)a.localUrl&&URL.revokeObjectURL(a.localUrl);P([])}let n=B;if(!n&&!x){let a=j||"File attachment",b=a.length>60?a.slice(0,60)+"...":a;n=await aA(b),C(n),an.current=n,l?.(n),m?.(),am&&aC.current?.().then(a=>{aa(a)})}let o=j,p=[...c.map(a=>a.path),...k.map(a=>a.path)];if(p.length>0){let a=`[Attached files: ${p.join(", ")}]`;o=o?`${a}
136
136
 
137
- ${o}`:a}if(a&&X.current){let b=a.isDirectory?"directory":"file";o=`[Context: workspace ${b} '${a.path}']
137
+ ${o}`:a}if(a&&Z.current){let b=a.isDirectory?"directory":"file";o=`[Context: workspace ${b} '${a.path}']
138
138
 
139
- ${o}`,X.current=!1}_.current.set(o,d),aa.current=d,aw.current=!1,ap({text:o})},[L,au,B,ay,l,m,ak,a,ap]),aH=(0,h.useRef)(aq);(0,h.useEffect)(()=>{let a="streaming"===aH.current||"submitted"===aH.current,b="ready"===aq;if(aH.current=aq,a&&b&&ab.length>0){let[a,...b]=ab;for(let c of(ac(b),a.attachedFiles))c.localUrl&&URL.revokeObjectURL(c.localUrl);queueMicrotask(()=>{aG(a.text,a.mentionedFiles,a.html,a.attachedFiles)})}},[aq,ab,aG]);let aI=(0,h.useCallback)(async a=>{if(a!==B){U.current?.abort(),ar(),J(!0),C(a),al.current=a,l?.(a),V.current.clear(),X.current=!1,ac([]);try{let b=await fetch(`/api/web-sessions/${a}`);if(!b.ok)throw Error("Failed to load session");let c=(await b.json()).messages||[],d=c.some(a=>a._streaming)?c.filter(a=>!a._streaming):c;for(let a of(_.current.clear(),d))"user"===a.role&&a.html&&_.current.set(a.id,a.html);let e=d.map(a=>(V.current.add(a.id),{id:a.id,role:a.role,parts:a.parts??[{type:"text",text:a.content}]}));at(e),J(!1),await az(a,e)}catch(a){console.error("Error loading session:",a),J(!1)}}},[B,at,l,ar,az]),aJ=(0,h.useCallback)(()=>{U.current?.abort(),ar(),T(!1),C(null),al.current=null,l?.(null),at([]),V.current.clear(),_.current.clear(),X.current=!0,W.current=!1,ac([]),requestAnimationFrame(()=>{y.current?.focus()})},[at,l,ar]);aF.current=aJ,(0,h.useImperativeHandle)(w,()=>({loadSession:aI,newSession:async()=>{aJ()},sendNewMessage:async a=>{aJ();let b=a.length>60?a.slice(0,60)+"...":a,c=await ay(b);C(c),al.current=c,l?.(c),m?.(),aw.current=!1,ap({text:a})},insertFileMention:(a,b)=>{y.current?.insertFileMention(a,b)}}),[aI,aJ,ay,l,m,ap]);let aK=(0,h.useCallback)(async()=>{if(U.current?.abort(),T(!1),s||B)try{await fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s?{sessionKey:s}:{sessionId:B})})}catch{}ar()},[B,s,ar]),aL=(0,h.useCallback)(a=>{ac(b=>b.filter(b=>b.id!==a))},[]),aM=(0,h.useCallback)((a,b)=>{ac(c=>c.map(c=>c.id===a?{...c,text:b}:c))},[]),aN=(0,h.useCallback)(async a=>{let b=ab.find(b=>b.id===a);b&&(ac(b=>b.filter(b=>b.id!==a)),await aK(),setTimeout(()=>{aG(b.text,b.mentionedFiles,b.html,b.attachedFiles)},100))},[ab,aK,aG]),aO=(0,h.useCallback)(a=>{let b=a.map(a=>({id:`${a.path}-${Date.now()}-${Math.random().toString(36).slice(2)}`,name:a.name,path:a.path}));P(a=>[...a,...b])},[]),aP=(0,h.useCallback)(a=>{P(b=>{let c=b.find(b=>b.id===a);return c?.localUrl&&URL.revokeObjectURL(c.localUrl),b.filter(b=>b.id!==a)})},[]),aQ=(0,h.useCallback)(()=>{P(a=>{for(let b of a)b.localUrl&&URL.revokeObjectURL(b.localUrl);return[]})},[]),aR=(0,h.useCallback)(a=>{let b=Array.from(a),c=b.map(a=>({id:`pending-${Date.now()}-${Math.random().toString(36).slice(2)}`,name:a.name,path:"",uploading:!0,localUrl:URL.createObjectURL(a)}));P(a=>[...a,...c]);for(let a=0;a<b.length;a++){let d=b[a],e=c[a].id,f=c[a].localUrl,g=new FormData;g.append("file",d),fetch("/api/workspace/upload",{method:"POST",body:g}).then(a=>a.ok?a.json():null).then(a=>{a?.ok&&a.path?P(b=>b.map(b=>b.id===e?{...b,path:a.path,uploading:!1}:b)):(P(a=>a.filter(a=>a.id!==e)),f&&URL.revokeObjectURL(f))}).catch(()=>{P(a=>a.filter(a=>a.id!==e)),f&&URL.revokeObjectURL(f)})}},[]),aS=ao.length>0?ao[ao.length-1]:null,aT=aS?.role==="assistant"&&aS.parts.some(a=>"text"===a.type&&a.text.length>0),aU=au&&!aT,aV=0===ao.length&&!b&&!x&&!D,aW=(0,e.jsxs)(e.Fragment,{children:[ab.length>0&&(0,e.jsx)("div",{className:b?"px-2 pt-2":"px-3 pt-3",children:(0,e.jsxs)("div",{className:"rounded-xl border overflow-hidden",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",boxShadow:"var(--shadow-sm)"},children:[(0,e.jsxs)("div",{className:"px-3 py-1.5 text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:["Queue (",ab.length,")"]}),(0,e.jsx)("div",{className:"flex flex-col p-2",children:ab.map((a,b)=>(0,e.jsx)(M,{msg:a,idx:b,onEdit:aM,onSendNow:aN,onRemove:aL},a.id))})]})}),!x&&(0,e.jsx)(N,{files:L,compact:b,onRemove:aP,onClearAll:aQ}),(0,e.jsx)(G.y,{ref:y,onSubmit:aG,onChange:a=>A(a),onNativeFileDrop:x?void 0:aR,placeholder:aV?"Build a workflow to automate your tasks":x?au?"Type to queue a message...":"Type @ to mention files...":b&&a?`Ask about ${a.isDirectory?"this folder":a.filename}...`:au?"Type to queue a message...":L.length>0?"Add a message or send files...":"Type @ to mention files...",disabled:D,compact:b}),(0,e.jsxs)("div",{className:`flex items-center justify-between ${b?"px-2 pb-1.5":"px-3 pb-2.5"}`,children:[(0,e.jsx)("div",{className:"flex items-center gap-0.5",children:!x&&(0,e.jsx)("button",{type:"button",onClick:()=>R(!0),className:"p-1.5 rounded-lg hover:opacity-80 transition-opacity",style:{color:L.length>0?"var(--color-accent)":"var(--color-text-muted)"},title:"Attach files",children:(0,e.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"})})})}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[au&&(0,e.jsx)("button",{type:"button",onClick:()=>aK(),className:`${b?"w-6 h-6":"w-7 h-7"} rounded-full flex items-center justify-center`,style:{background:"var(--color-text)",color:"var(--color-bg)"},title:"Stop generating",children:(0,e.jsx)("svg",{width:"8",height:"8",viewBox:"0 0 10 10",fill:"currentColor",children:(0,e.jsx)("rect",{width:"10",height:"10",rx:"1.5"})})}),au?(0,e.jsxs)("button",{type:"button",onClick:()=>y.current?.submit(),disabled:z&&0===L.length||D,className:"h-7 px-3 rounded-full flex items-center gap-1.5 text-[12px] font-medium disabled:opacity-40 disabled:cursor-not-allowed",style:{background:!z||L.length>0?"var(--color-accent)":"var(--color-surface-hover)",color:!z||L.length>0?"white":"var(--color-text-muted)"},title:"Add to queue",children:[(0,e.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("polyline",{points:"9 10 4 15 9 20"}),(0,e.jsx)("path",{d:"M20 4v7a4 4 0 0 1-4 4H4"})]}),"Queue"]}):(0,e.jsx)("button",{type:"button",onClick:()=>y.current?.submit(),disabled:z&&0===L.length||D,className:`${b?"w-6 h-6":"w-7 h-7"} rounded-full flex items-center justify-center disabled:opacity-50 disabled:cursor-not-allowed`,style:{background:!z||L.length>0?"var(--color-accent)":"var(--color-text-muted)",color:!z||L.length>0?"white":"var(--color-bg)"},title:"Send message",children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M12 19V5"}),(0,e.jsx)("path",{d:"m5 12 7-7 7 7"})]})})]})]})]}),aX=(a,b,c)=>(0,e.jsx)("div",{"data-chat-drop-target":"",className:"rounded-3xl overflow-hidden border shadow-[0_0_32px_rgba(0,0,0,0.07)] transition-[outline,box-shadow] duration-150 ease-out data-drag-hover:outline-2 data-drag-hover:outline-dashed data-drag-hover:outline-(--color-accent) data-drag-hover:-outline-offset-2 data-drag-hover:shadow-[0_0_0_4px_color-mix(in_srgb,var(--color-accent)_15%,transparent),0_0_32px_rgba(0,0,0,0.07)]!",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},onDragOver:a,onDragLeave:b,onDrop:c,children:aW}),aY=a=>{(a.dataTransfer?.types.includes("application/x-file-mention")||a.dataTransfer?.types.includes("Files"))&&(a.preventDefault(),a.dataTransfer.dropEffect="copy",a.currentTarget.setAttribute("data-drag-hover",""))},aZ=a=>{a.currentTarget.contains(a.relatedTarget)||a.currentTarget.removeAttribute("data-drag-hover")},a$=a=>{a.currentTarget.removeAttribute("data-drag-hover");let b=a.dataTransfer?.getData("application/x-file-mention");if(b){a.preventDefault(),a.stopPropagation();try{let{name:a,path:c}=JSON.parse(b);a&&c&&y.current?.insertFileMention(a,c)}catch{}return}let c=a.dataTransfer?.files;c&&c.length>0&&(a.preventDefault(),a.stopPropagation(),aR(c))};return(0,e.jsx)(i.o,{children:(0,e.jsxs)("div",{className:"h-full flex flex-col",style:{background:"var(--color-main-bg)"},children:[(0,e.jsx)("header",{className:`${b?"px-3 py-2":"px-3 py-2 md:px-6 md:py-3"} flex items-center ${x?"gap-3":"justify-between"} z-20`,style:{background:"var(--color-bg-glass)"},children:x?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",onClick:v,className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Back to parent chat",children:(0,e.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,e.jsx)("path",{d:"M19 12H5"})]})}),(0,e.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,e.jsx)("h2",{className:"text-sm font-semibold truncate",style:{color:"var(--color-text)"},children:u||(t&&t.length>60?t.slice(0,60)+"...":t)}),(0,e.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:au?(0,e.jsx)(I.V,{name:"braille"}):"Completed"})]})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"min-w-0 flex-1",children:b&&a?(0,e.jsxs)("h2",{className:"text-xs font-semibold truncate",style:{color:"var(--color-text)"},children:["Chat: ",a.filename]}):(0,e.jsx)("h2",{className:"text-sm font-semibold",style:{color:"var(--color-text)"},children:B?c||"Chat Session":"New Chat"})}),(0,e.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[B&&q&&(0,e.jsxs)(H.rI,{children:[(0,e.jsx)(H.ty,{className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},title:"More options","aria-label":"More options",children:(0,e.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("circle",{cx:"12",cy:"12",r:"1"}),(0,e.jsx)("circle",{cx:"5",cy:"12",r:"1"}),(0,e.jsx)("circle",{cx:"19",cy:"12",r:"1"})]})}),(0,e.jsx)(H.SQ,{align:"end",side:"bottom",children:(0,e.jsxs)(H._2,{variant:"destructive",onSelect:()=>q(B),children:[(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M3 6h18"}),(0,e.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,e.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]}),"Delete"]})})]}),b&&(0,e.jsx)("button",{type:"button",onClick:()=>aJ(),className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},title:"New chat",children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M12 5v14"}),(0,e.jsx)("path",{d:"M5 12h14"})]})})]})]})}),!x&&b&&a&&Y.length>0&&(0,e.jsx)("div",{className:"px-2 py-1.5 border-b flex gap-1 overflow-x-auto z-20",style:{borderColor:"var(--color-border)",background:"var(--color-bg-glass)"},children:Y.slice(0,10).map(a=>(0,e.jsx)("button",{type:"button",onClick:()=>aI(a.id),className:"px-2.5 py-1 text-[10px] rounded-full whitespace-nowrap shrink-0 font-medium",style:{background:a.id===B?"var(--color-accent)":"var(--color-surface-hover)",color:a.id===B?"white":"var(--color-text-muted)",border:a.id===B?"none":"1px solid var(--color-border)"},children:a.title.length>25?a.title.slice(0,25)+"...":a.title},a.id))}),(0,e.jsxs)("div",{ref:av,className:"flex-1 overflow-y-auto min-h-0",children:[(0,e.jsx)("div",{className:b?"px-3":"px-6",children:D?(0,e.jsx)("div",{className:"flex items-center justify-center h-full min-h-[60vh]",children:(0,e.jsxs)("div",{className:"text-center",children:[(0,e.jsx)(I.V,{name:"braille",className:"block text-2xl mx-auto mb-3",style:{color:"var(--color-text-muted)"}}),(0,e.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading session..."})]})}):aV?(0,e.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-[75vh] py-12",children:[af&&(0,e.jsx)(j.P.h1,{className:"text-4xl md:text-5xl font-light tracking-normal font-instrument mb-10 text-center",style:{color:"var(--color-text)"},initial:"hidden",animate:"visible",variants:{hidden:{opacity:0},visible:{opacity:1,transition:{staggerChildren:.12,delayChildren:.2}}},children:af.split(" ").map((a,b)=>(0,e.jsx)(j.P.span,{className:"inline-block mr-2",variants:{hidden:{opacity:0,y:20,filter:"blur(8px)"},visible:{opacity:1,y:0,filter:"blur(0px)",transition:{duration:.8,ease:[.2,.65,.3,.9]}}},children:a},b))}),(0,e.jsx)(j.P.div,{className:"w-full max-w-[720px] mx-auto px-4",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.8,delay:.8,ease:[.22,1,.36,1]},children:(0,e.jsx)(j.P.div,{layout:!0,layoutId:"chat-input-bar",transition:{type:"spring",stiffness:260,damping:30},children:aX(aY,aZ,a$)})}),(0,e.jsxs)(j.P.div,{className:"mt-6 flex flex-col gap-2.5 w-full max-w-[720px] mx-auto px-4",initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5,delay:1,ease:[.22,1,.36,1]},children:[(0,e.jsx)("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:ah.slice(0,3).map(a=>{let b=a.icon;return(0,e.jsxs)("button",{type:"button",onClick:()=>aj(a.id),className:"group flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium whitespace-nowrap rounded-xl transition-all duration-200 border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text-secondary)"},children:[(0,e.jsx)(b,{className:"w-3.5 h-3.5 opacity-50 group-hover:opacity-100 transition-opacity duration-200"}),a.label]},a.id)})}),(0,e.jsx)("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:ah.slice(3,7).map(a=>{let b=a.icon;return(0,e.jsxs)("button",{type:"button",onClick:()=>aj(a.id),className:"group flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium whitespace-nowrap rounded-xl transition-all duration-200 border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text-secondary)"},children:[(0,e.jsx)(b,{className:"w-3.5 h-3.5 opacity-50 group-hover:opacity-100 transition-opacity duration-200"}),a.label]},a.id)})})]})]}):0===ao.length?(0,e.jsx)("div",{className:"flex items-center justify-center h-full min-h-[60vh]",children:(0,e.jsx)("div",{className:"text-center max-w-md px-4",children:(0,e.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Ask about this file"})})}):(0,e.jsxs)("div",{className:`${b?"":"max-w-2xl mx-auto"} py-3`,children:[ad?(0,e.jsx)("pre",{className:"text-xs whitespace-pre-wrap break-all font-mono p-4 rounded-xl",style:{color:"var(--color-text)",background:"var(--color-surface-hover)"},children:JSON.stringify(ao,null,2)}):ao.map((a,b)=>(0,e.jsx)(E.c,{message:a,isStreaming:au&&b===ao.length-1,onSubagentClick:o,onFilePathClick:p,sessionId:B,userHtmlMap:_.current},a.id)),aU&&(0,e.jsx)("div",{className:"py-3 min-w-0",children:(0,e.jsx)(I.V,{name:"pulse",className:"text-base",style:{color:"var(--color-text-muted)"}})}),(0,e.jsx)("div",{ref:K})]})}),as&&(0,e.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 sticky bottom-[72px] z-10",style:{background:"color-mix(in srgb, var(--color-error) 6%, var(--color-surface))",borderColor:"color-mix(in srgb, var(--color-error) 18%, transparent)",color:"var(--color-error)"},children:[(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:[(0,e.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,e.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,e.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),(0,e.jsx)("p",{className:"text-xs",children:as.message})]})]}),!aV&&(0,e.jsx)("div",{className:`${b?"px-3 py-2":"px-3 pb-3 pt-0 md:px-6 md:pb-5"} z-20`,style:{background:"var(--color-bg-glass)"},children:(0,e.jsx)("div",{className:b?"":"max-w-[720px] mx-auto",children:(0,e.jsx)(j.P.div,{layout:!0,layoutId:"chat-input-bar",transition:{type:"spring",stiffness:260,damping:30},children:aX(aY,aZ,a$)})})}),!x&&(0,e.jsx)(F.C,{open:Q,onClose:()=>R(!1),onSelect:aO})]})})});d()}catch(a){d(a)}})},38182:(a,b,c)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"});let d=c(61442),e=c(3182),f=c(5033);b.sortBy=function(a,...b){let c=b.length;return c>1&&f.isIterateeCall(a,b[0],b[1])?b=[]:c>2&&f.isIterateeCall(b[0],b[1],b[2])&&(b=[b[0]]),d.orderBy(a,e.flatten(b),["asc"])}},38899:(a,b)=>{"use strict";function c(a){return a.split("/").map(a=>encodeURIComponent(a)).join("/")}Object.defineProperty(b,"__esModule",{value:!0}),Object.defineProperty(b,"encodeURIPath",{enumerable:!0,get:function(){return c}})},39065:(a,b,c)=>{let d=c(64334),e=c(28123),f=c(26821),g=c(47186),h=c(84878),i=c(68956),j=c(7223),k=c(8366),l=c(11609),m=c(37519),n=c(12089),{FormulaHelpers:o}=c(28358),{Parser:p,allTokens:q}=c(69213),r=c(10490),s=c(5296);class t{constructor(a,b=!1){this.logs=[],this.isTest=b,this.utils=new s(this),a=Object.assign({functions:{},functionsNeedContext:{},onVariable:()=>null,onCell:()=>0,onRange:()=>[[0]]},a),this.onVariable=a.onVariable,this.functions=Object.assign({},l,k,j,i,h,g,d,e,f,m,a.functions,a.functionsNeedContext),this.onRange=a.onRange,this.onCell=a.onCell,this.funsNullAs0=Object.keys(e).concat(Object.keys(f)).concat(Object.keys(g)).concat(Object.keys(h)).concat(Object.keys(i)).concat(Object.keys(k)).concat(Object.keys(l)),this.funsNeedContextAndNoDataRetrieve=["ROW","ROWS","COLUMN","COLUMNS","SUMIF","INDEX","AVERAGEIF","IF"],this.funsNeedContext=[...Object.keys(a.functionsNeedContext),...this.funsNeedContextAndNoDataRetrieve,"INDEX","OFFSET","INDIRECT","IF","CHOOSE","WEBSERVICE"],this.funsPreserveRef=Object.keys(j),this.parser=new p(this,this.utils)}static get allTokens(){return q}getCell(a){return null==a.sheet&&(a.sheet=this.position?this.position.sheet:void 0),this.onCell(a)}getRange(a){return null==a.sheet&&(a.sheet=this.position?this.position.sheet:void 0),this.onRange(a)}getVariable(a){let b={ref:this.onVariable(a,this.position.sheet,this.position)};return null==b.ref?n.NAME:b}retrieveRef(a){return o.isRangeRef(a)?this.getRange(a.ref):o.isCellRef(a)?this.getCell(a.ref):a}_callFunction(a,b){0===a.indexOf("_xlfn.")&&(a=a.slice(6)),a=a.toUpperCase();let c=this.funsNullAs0.includes(a)?0:"";if(this.funsNeedContextAndNoDataRetrieve.includes(a)||(b=b.map(b=>{if(null===b)return{value:c,isArray:!1,omitted:!0};let d=this.utils.extractRefValue(b);return this.funsPreserveRef.includes(a)?{value:d.val,isArray:d.isArray,ref:b.ref}:{value:d.val,isArray:d.isArray,isRangeRef:!!o.isRangeRef(b),isCellRef:!!o.isCellRef(b)}})),this.functions[a]){let c;try{c=this.funsNeedContextAndNoDataRetrieve.includes(a)||this.funsNeedContext.includes(a)?this.functions[a](this,...b):this.functions[a](...b)}catch(a){if(a instanceof n)return a;throw a}if(void 0===c){if(this.isTest)return this.logs.includes(a)||this.logs.push(a),{value:0,ref:{}};throw n.NOT_IMPLEMENTED(a)}return c}if(this.isTest)return this.logs.includes(a)||this.logs.push(a),{value:0,ref:{}};throw n.NOT_IMPLEMENTED(a)}async callFunctionAsync(a,b){let c=[];for(let a of b)c.push(await a);let d=await this._callFunction(a,c);return o.checkFunctionResult(d)}callFunction(a,b){if(this.async)return this.callFunctionAsync(a,b);{let c=this._callFunction(a,b);return o.checkFunctionResult(c)}}supportedFunctions(){let a=[];return Object.keys(this.functions).forEach(b=>{try{let c=this.functions[b](0,0,0,0,0,0,0,0,0,0,0);if(void 0===c)return;a.push(b)}catch(c){c instanceof Error&&a.push(b)}}),a.sort()}checkFormulaResult(a,b=!1){let c=typeof a;if("number"===c){if(isNaN(a))return n.VALUE;if(!isFinite(a))return n.NUM;a+=0}else if("object"===c){if(a instanceof n)return a;if(b){if(a.ref&&(a=this.retrieveRef(a)),"object"==typeof a&&!Array.isArray(a)&&null!=a)return n.VALUE}else if(a.ref&&a.ref.row&&!a.ref.from)a=this.retrieveRef(a);else if(a.ref&&a.ref.from&&a.ref.from.col===a.ref.to.col)a=this.retrieveRef({ref:{row:a.ref.from.row,col:a.ref.from.col}});else{if(!Array.isArray(a))return n.VALUE;a=a[0][0]}}return a}parse(a,b,c=!1){let d;if(0===a.length)throw Error("Input must not be empty.");this.position=b,this.async=!1;let e=r.lex(a);this.parser.input=e.tokens;try{if(d=this.parser.formulaWithBinaryOp(),(d=this.checkFormulaResult(d,c))instanceof n)return d}catch(a){throw n.ERROR(a.message,a)}if(this.parser.errors.length>0){let b=this.parser.errors[0];throw s.formatChevrotainError(b,a)}return d}async parseAsync(a,b,c=!1){let d;if(0===a.length)throw Error("Input must not be empty.");this.position=b,this.async=!0;let e=r.lex(a);this.parser.input=e.tokens;try{if(d=await this.parser.formulaWithBinaryOp(),(d=this.checkFormulaResult(d,c))instanceof n)return d}catch(a){throw n.ERROR(a.message,a)}if(this.parser.errors.length>0){let b=this.parser.errors[0];throw s.formatChevrotainError(b,a)}return d}}a.exports={FormulaParser:t,FormulaHelpers:o}},39384:(a,b)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"}),b.isObject=function(a){return null!==a&&("object"==typeof a||"function"==typeof a)}},39914:(a,b,c)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"});let d=c(80656),e=c(32468),f=c(83037),g=c(95802),h=c(55516);function i(a){let b=[];for(let c in a)b.push(c);return b}b.keysIn=function(a){if(null==a)return[];switch(typeof a){case"object":case"function":if(f.isArrayLike(a)){var b=a;let c=h.times(b.length,a=>`${a}`),e=new Set(c);d.isBuffer(b)&&(e.add("offset"),e.add("parent")),g.isTypedArray(b)&&(e.add("buffer"),e.add("byteLength"),e.add("byteOffset"));let f=i(b).filter(a=>!e.has(a));return Array.isArray(b)?[...c,...f]:[...c.filter(a=>Object.hasOwn(b,a)),...f]}if(e.isPrototype(a))return i(a).filter(a=>"constructor"!==a);return i(a);default:return i(Object(a))}}},39957:(a,b)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"}),b.getSymbols=function(a){return Object.getOwnPropertySymbols(a).filter(b=>Object.prototype.propertyIsEnumerable.call(a,b))}},41025:a=>{"use strict";a.exports=require("next/dist/server/app-render/dynamic-access-async-storage.external.js")},41204:a=>{"use strict";a.exports=require("string_decoder")},41778:(a,b,c)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"});let d=c(58422);b.cloneDeep=function(a){return d.cloneDeepWith(a)}},41790:(a,b,c)=>{let d=c(12089),{FormulaHelpers:e}=c(28358),f={boolean:3,string:2,number:1};a.exports={Prefix:{unaryOp:(a,b,c)=>{let f=1;if(a.forEach(a=>{if("+"===a);else if("-"===a)f=-f;else throw Error(`Unrecognized prefix: ${a}`)}),null==b&&(b=0),1===f)return b;try{b=e.acceptNumber(b,c)}catch(a){if(a instanceof d)Array.isArray(b)&&(b=b[0][0]);else throw a}return"number"==typeof b&&isNaN(b)?d.VALUE:-b}},Postfix:{percentOp:(a,b,c)=>{try{a=e.acceptNumber(a,c)}catch(a){if(a instanceof d)return a;throw a}if("%"===b)return a/100;throw Error(`Unrecognized postfix: ${b}`)}},Infix:{compareOp:(a,b,c,d,e)=>{null==a&&(a=0),null==c&&(c=0),d&&(a=a[0][0]),e&&(c=c[0][0]);let g=typeof a,h=typeof c;if(g===h)switch(b){case"=":return a===c;case">":return a>c;case"<":return a<c;case"<>":return a!==c;case"<=":return a<=c;case">=":return a>=c}else switch(b){case"=":return!1;case">":return f[g]>f[h];case"<":return f[g]<f[h];case"<>":return!0;case"<=":return f[g]<=f[h];case">=":return f[g]>=f[h]}throw Error("Infix.compareOp: Should not reach here.")},concatOp:(a,b,c,d,e)=>(null==a&&(a=""),null==c&&(c=""),d&&(a=a[0][0]),e&&(c=c[0][0]),"boolean"==typeof a&&(a=a?"TRUE":"FALSE"),"boolean"==typeof c&&(c=c?"TRUE":"FALSE"),""+a+c),mathOp:(a,b,c,f,g)=>{null==a&&(a=0),null==c&&(c=0);try{a=e.acceptNumber(a,f),c=e.acceptNumber(c,g)}catch(a){if(a instanceof d)return a;throw a}switch(b){case"+":return a+c;case"-":return a-c;case"*":return a*c;case"/":if(0===c)return d.DIV0;return a/c;case"^":return a**c}throw Error("Infix.mathOp: Should not reach here.")}},Operators:{compareOp:["<",">","=","<>","<=",">="],concatOp:["&"],mathOp:["+","-","*","/","^"]}}},42125:(a,b,c)=>{"use strict";c.d(b,{A:()=>d});let d=(0,c(15336).A)("pen-tool",[["path",{d:"M15.707 21.293a1 1 0 0 1-1.414 0l-1.586-1.586a1 1 0 0 1 0-1.414l5.586-5.586a1 1 0 0 1 1.414 0l1.586 1.586a1 1 0 0 1 0 1.414z",key:"nt11vn"}],["path",{d:"m18 13-1.375-6.874a1 1 0 0 0-.746-.776L3.235 2.028a1 1 0 0 0-1.207 1.207L5.35 15.879a1 1 0 0 0 .776.746L13 18",key:"15qc1e"}],["path",{d:"m2.3 2.3 7.286 7.286",key:"1wuzzi"}],["circle",{cx:"11",cy:"11",r:"2",key:"xmgehs"}]])},42184:(a,b,c)=>{"use strict";c.d(b,{A:()=>d});let d=(0,c(15336).A)("workflow",[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]])},42202:(a,b,c)=>{"use strict";c.d(b,{Y_:()=>w});var d,e,f,g,h,i,j,k,l,m,n=c(15962),o=c(29415),p=c(13799),q=(a,b,c)=>{if(!b.has(a))throw TypeError("Cannot "+c)},r=(a,b,c)=>(q(a,b,"read from private field"),c?c.call(a):b.get(a)),s=(a,b,c)=>{if(b.has(a))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(a):b.set(a,c)},t=(a,b,c,d)=>(q(a,b,"write to private field"),d?d.call(a,c):b.set(a,c),c),u=class{constructor(a=[]){s(this,d,void 0),s(this,e,"ready"),s(this,f,void 0),s(this,g,new Set),s(this,h,new Set),s(this,i,new Set),this.pushMessage=a=>{t(this,d,r(this,d).concat(a)),r(this,j).call(this)},this.popMessage=()=>{t(this,d,r(this,d).slice(0,-1)),r(this,j).call(this)},this.replaceMessage=(a,b)=>{t(this,d,[...r(this,d).slice(0,a),this.snapshot(b),...r(this,d).slice(a+1)]),r(this,j).call(this)},this.snapshot=a=>structuredClone(a),this["~registerMessagesCallback"]=(a,b)=>{let c=b?function(a,b){return null!=b?p(a,b):a}(a,b):a;return r(this,g).add(c),()=>{r(this,g).delete(c)}},this["~registerStatusCallback"]=a=>(r(this,h).add(a),()=>{r(this,h).delete(a)}),this["~registerErrorCallback"]=a=>(r(this,i).add(a),()=>{r(this,i).delete(a)}),s(this,j,()=>{r(this,g).forEach(a=>a())}),s(this,k,()=>{r(this,h).forEach(a=>a())}),s(this,l,()=>{r(this,i).forEach(a=>a())}),t(this,d,a)}get status(){return r(this,e)}set status(a){t(this,e,a),r(this,k).call(this)}get error(){return r(this,f)}set error(a){t(this,f,a),r(this,l).call(this)}get messages(){return r(this,d)}set messages(a){t(this,d,[...a]),r(this,j).call(this)}};d=new WeakMap,e=new WeakMap,f=new WeakMap,g=new WeakMap,h=new WeakMap,i=new WeakMap,j=new WeakMap,k=new WeakMap,l=new WeakMap;var v=class extends o.vl{constructor({messages:a,...b}){let c=new u(a);super({...b,state:c}),s(this,m,void 0),this["~registerMessagesCallback"]=(a,b)=>r(this,m)["~registerMessagesCallback"](a,b),this["~registerStatusCallback"]=a=>r(this,m)["~registerStatusCallback"](a),this["~registerErrorCallback"]=a=>r(this,m)["~registerErrorCallback"](a),t(this,m,c)}};function w({experimental_throttle:a,resume:b=!1,...c}={}){let d=(0,n.useRef)("chat"in c?{}:{onToolCall:c.onToolCall,onData:c.onData,onFinish:c.onFinish,onError:c.onError,sendAutomaticallyWhen:c.sendAutomaticallyWhen});"chat"in c||(d.current={onToolCall:c.onToolCall,onData:c.onData,onFinish:c.onFinish,onError:c.onError,sendAutomaticallyWhen:c.sendAutomaticallyWhen});let e={...c,onToolCall:a=>{var b,c;return null==(c=(b=d.current).onToolCall)?void 0:c.call(b,a)},onData:a=>{var b,c;return null==(c=(b=d.current).onData)?void 0:c.call(b,a)},onFinish:a=>{var b,c;return null==(c=(b=d.current).onFinish)?void 0:c.call(b,a)},onError:a=>{var b,c;return null==(c=(b=d.current).onError)?void 0:c.call(b,a)},sendAutomaticallyWhen:a=>{var b,c,e;return null!=(e=null==(c=(b=d.current).sendAutomaticallyWhen)?void 0:c.call(b,a))&&e}},f=(0,n.useRef)("chat"in c?c.chat:new v(e));("chat"in c&&c.chat!==f.current||"id"in c&&f.current.id!==c.id)&&(f.current="chat"in c?c.chat:new v(e));let g=(0,n.useCallback)(b=>f.current["~registerMessagesCallback"](b,a),[a,f.current.id]),h=(0,n.useSyncExternalStore)(g,()=>f.current.messages,()=>f.current.messages),i=(0,n.useSyncExternalStore)(f.current["~registerStatusCallback"],()=>f.current.status,()=>f.current.status),j=(0,n.useSyncExternalStore)(f.current["~registerErrorCallback"],()=>f.current.error,()=>f.current.error),k=(0,n.useCallback)(a=>{"function"==typeof a&&(a=a(f.current.messages)),f.current.messages=a},[f]);return(0,n.useEffect)(()=>{b&&f.current.resumeStream()},[b,f]),{id:f.current.id,messages:h,setMessages:k,sendMessage:f.current.sendMessage,regenerate:f.current.regenerate,clearError:f.current.clearError,stop:f.current.stop,error:j,resumeStream:f.current.resumeStream,status:i,addToolResult:f.current.addToolOutput,addToolOutput:f.current.addToolOutput,addToolApprovalResponse:f.current.addToolApprovalResponse}}m=new WeakMap},42837:(a,b,c)=>{"use strict";c.d(b,{I:()=>w});var d=c(36927),e=c(15962),f=c(55132),g=c(90106),h=c(59448);let i=new Set(["jpg","jpeg","png","gif","webp","svg","bmp","avif","heic","heif","tiff","tif","ico"]),j=new Set(["mp4","webm","mov","avi","mkv"]),k=new Set(["pdf"]),l=new Set(["mp3","wav","ogg","m4a"]);function m(a){let b=(a.split(".").pop()??"").toLowerCase();return i.has(b)?"image":j.has(b)?"video":k.has(b)?"pdf":l.has(b)?"audio":null}function n(a){return a.startsWith("http://")||a.startsWith("https://")?a:`/api/workspace/raw-file?path=${encodeURIComponent(a)}`}let o=/(?:^|[\s"'(=])(((?:\/|\.\/)?[\w.\-/\\]+)\.(?:jpe?g|png|gif|webp|svg|bmp|avif|heic|heif|tiff?|ico|mp4|webm|mov|avi|mkv|mp3|wav|ogg|m4a|pdf))\b/i,p=["path","file","file_path","filePath","filename","url","src","name","target"];function q(a,b){if(a)for(let b of p){let c=a[b];if("string"==typeof c&&c.length>0)return c}if(b)for(let a of p){let c=b[a];if("string"==typeof c&&c.length>0&&r(c))return c}if(a){let b=s(a);if(b)return b}if(b?.text&&"string"==typeof b.text){let a=b.text.match(o);if(a)return a[1]}if(b){let a=s(b);if(a)return a}return null}function r(a){return a.length>2&&a.length<500&&/\.\w{1,5}$/.test(a)&&!a.includes(" ")}function s(a){for(let b of Object.values(a))if("string"==typeof b&&r(b))return b;return null}let t=/https?:\/\/[^\s"'<>,;)}\]]+/gi;function u(a){return`https://www.google.com/s2/favicons?sz=64&domain_url=${encodeURIComponent(a)}`}function v(a,b){let c=a.toLowerCase().replace(/[_-]/g,"");if(["websearch","search","googlesearch","bingsearch","browsersearch","tavily"].some(a=>c.includes(a)))return"search";if("browser"===c){let a="string"==typeof b?.action?b.action.toLowerCase():"";return"open"===a||"navigate"===a?"fetch":"screenshot"===a?"image":"generic"}return["fetchurl","fetch","browse","browseurl","webfetch"].some(a=>c.includes(a))?"fetch":["read","file","readfile","getfile"].some(a=>c.includes(a))?"read":["bash","shell","execute","exec","terminal","command","run"].some(a=>c.includes(a))?"exec":["write","create","edit","str_replace","save","patch"].some(a=>c.includes(a))?"write":["image","screenshot","photo","picture","dalle","generateimage"].some(a=>c.includes(a))?"image":"generic"}function w({parts:a,isStreaming:b}){let[c,h]=(0,e.useState)(!!b),i=a.some(a=>"reasoning"===a.kind&&a.isStreaming||"tool"===a.kind&&"running"===a.status);(0,e.useRef)(null);let[j,k]=(0,e.useState)(0),l=(0,e.useCallback)(a=>{if(a<60)return`${a}s`;let b=Math.floor(a/60),c=a%60;return c>0?`${b}m ${c}s`:`${b}m`},[]);(0,e.useRef)(!1);let n=a.filter(a=>"reasoning"===a.kind).map(a=>a.text).join(""),o=a.some(a=>"reasoning"===a.kind&&a.isStreaming),p=function(a){let b=[],c=0;for(;c<a.length;){let d=a[c],e=v(d.toolName,d.args),f=q(d.args,d.output),g=f?m(f):null;if("read"===e&&g&&f){let e=[{path:f,tool:d}],h=c+1;for(;h<a.length;){let b=a[h],c=v(b.toolName,b.args),d=q(b.args,b.output),f=d?m(d):null;if("read"===c&&f===g&&d)e.push({path:d,tool:b}),h++;else break}b.push({type:"media-group",mediaKind:g,items:e}),c=h}else if("fetch"===e){let e=[d],f=c+1;for(;f<a.length;){let b=a[f];if("fetch"===v(b.toolName,b.args))e.push(b),f++;else break}e.length>1?b.push({type:"fetch-group",items:e}):b.push({type:"tool",tool:d}),c=f}else b.push({type:"tool",tool:d}),c++}return b}(a.filter(a=>"tool"===a.kind)),r=i?j>0?`Thinking for ${l(j)}`:"Thinking...":j>0?`Thought for ${l(j)}`:"Thought";return(0,d.jsxs)("div",{className:"my-3",children:[(0,d.jsxs)("button",{type:"button",onClick:()=>h(a=>!a),className:"flex items-center gap-2 py-1 text-[13px] cursor-pointer group",style:{color:"var(--color-text-muted)"},children:[(0,d.jsx)(G,{className:"w-4 h-4 flex-shrink-0 opacity-60"}),(0,d.jsx)("span",{className:"font-medium",children:r}),(0,d.jsx)(H,{className:`w-3.5 h-3.5 ml-1 flex-shrink-0 transition-transform duration-200 ${c?"":"-rotate-90"}`})]}),(0,d.jsx)(f.N,{initial:!1,children:c&&(0,d.jsx)(g.P.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.3,ease:[.25,.1,.25,1]},className:"overflow-hidden",children:(0,d.jsxs)("div",{className:"relative pt-2 pb-1",children:[(0,d.jsx)("div",{className:"absolute w-px",style:{left:9,top:16,bottom:8,background:"var(--color-border)"}}),(0,d.jsxs)(f.N,{initial:!1,children:[n&&(0,d.jsxs)(g.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},className:"flex items-start gap-2.5 py-1.5",children:[(0,d.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 2a7 7 0 0 0-7 7c0 2.38 1.19 4.47 3 5.74V17a2 2 0 0 0 2 2h4a2 2 0 0 0 2-2v-2.26c1.81-1.27 3-3.36 3-5.74a7 7 0 0 0-7-7z"}),(0,d.jsx)("path",{d:"M10 21h4"})]})}),(0,d.jsx)("div",{className:"flex-1 min-w-0",children:(0,d.jsx)(x,{text:n,isStreaming:o})})]},"reasoning"),p.map((a,b)=>"media-group"===a.type?(0,d.jsx)(g.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,d.jsx)(z,{mediaKind:a.mediaKind,items:a.items})},`media-${b}`):"fetch-group"===a.type?(0,d.jsx)(g.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,d.jsx)(y,{items:a.items})},`fetch-${b}`):(0,d.jsx)(g.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,d.jsx)(B,{...a.tool})},a.tool.toolCallId))]})]})},"content")})]})}function x({text:a,isStreaming:b}){return(0,d.jsx)("div",{className:"mb-2",children:(0,d.jsx)("div",{className:"text-[13px] whitespace-pre-wrap leading-relaxed",style:{color:"var(--color-text-muted)"},children:a})})}function y({items:a}){let b=a.some(a=>"running"===a.status),c=a.filter(a=>"done"===a.status).length;return(0,d.jsxs)("div",{className:"flex items-start gap-2.5 py-1.5",children:[(0,d.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:(0,d.jsx)("span",{className:b?"animate-pulse":"",children:(0,d.jsx)(D,{kind:"fetch"})})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"text-[13px] leading-snug mb-1.5 flex items-center justify-between",style:{color:b?"var(--color-text)":"var(--color-text-secondary)"},children:[(0,d.jsx)("span",{className:b?"animate-pulse":"",children:b?`Fetching ${a.length} sources...`:`Fetched ${a.length} sources`}),!b&&(0,d.jsxs)("span",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:[c," ",1===c?"result":"results"]})]}),(0,d.jsx)("div",{className:"rounded-2xl overflow-hidden",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:a.map(a=>{let{domain:b,url:c}=function(a,b){for(let b of["url","targetUrl","path","src"]){let c=a?.[b];if("string"==typeof c&&c.startsWith("http"))try{return{domain:new URL(c).hostname,url:c}}catch{}}for(let a of["url","finalUrl","targetUrl"]){let c=b?.[a];if("string"==typeof c&&c.startsWith("http"))try{return{domain:new URL(c).hostname,url:c}}catch{}}return{domain:null,url:null}}(a.args,a.output);return(0,d.jsxs)("a",{href:c??void 0,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2.5 px-3 py-2.5 text-[12px] no-underline",style:{color:"var(--color-text)",cursor:c?"pointer":"default"},onMouseEnter:a=>{a.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent"},onClick:c?void 0:a=>a.preventDefault(),children:[b?(0,d.jsx)("img",{src:u(b),alt:"",width:16,height:16,className:"rounded-sm flex-shrink-0",loading:"lazy"}):(0,d.jsx)("div",{className:"w-4 h-4 rounded-sm flex-shrink-0",style:{background:"var(--color-surface-hover)"}}),(0,d.jsx)("span",{className:"flex-1 min-w-0 truncate",style:{color:"var(--color-text)"},children:b?.replace(/^www\./,"")??c??"Fetching..."}),"running"===a.status?(0,d.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse flex-shrink-0",style:{background:"var(--color-accent)"}}):c?(0,d.jsx)("span",{className:"text-[11px] truncate max-w-[45%] text-right",style:{color:"var(--color-text-muted)"},title:c,children:c}):null]},a.toolCallId)})})]})]})}function z({mediaKind:a,items:b}){let[c,f]=(0,e.useState)(!1),g=b.some(a=>"running"===a.tool.status),h=b.filter(a=>"done"===a.tool.status),i=h.length,j=g?`Reading ${b.length} ${a}${b.length>1?"s":""}...`:"image"===a?1===b.length?"Read 1 image":`Read ${b.length} images`:"video"===a?1===b.length?"Read 1 video":`Read ${b.length} videos`:"pdf"===a?1===b.length?"Read 1 PDF":`Read ${b.length} PDFs`:1===b.length?"Read 1 audio file":`Read ${b.length} audio files`,k=c?h:h.slice(0,6),l=h.length>6&&!c;return(0,d.jsxs)("div",{className:"flex items-start gap-2.5 py-1.5",children:[(0,d.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:(0,d.jsx)("span",{className:g?"animate-pulse":"",children:(0,d.jsx)(D,{kind:"image"===a?"image":"read"})})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("div",{className:`text-[13px] leading-snug mb-1.5${g?" animate-pulse":""}`,style:{color:g?"var(--color-text)":"var(--color-text-secondary)"},children:j}),i>0&&"image"===a&&(0,d.jsxs)("div",{className:"flex flex-wrap gap-1.5",children:[k.map(a=>(0,d.jsx)(A,{path:a.path,single:1===b.length},a.tool.toolCallId)),g&&(0,d.jsx)("div",{className:"flex items-center justify-center rounded-lg",style:{width:80,height:80,background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:(0,d.jsx)("span",{className:"animate-pulse",style:{color:"var(--color-text-muted)"},children:(0,d.jsx)(D,{kind:"image"})})}),l&&(0,d.jsxs)("button",{type:"button",onClick:()=>f(!0),className:"flex items-center justify-center rounded-lg text-xs font-medium cursor-pointer",style:{width:80,height:80,background:"var(--color-surface-hover)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:["+",h.length-6," ","more"]})]}),i>0&&"video"===a&&(0,d.jsx)("div",{className:"flex flex-wrap gap-2",children:k.map(a=>(0,d.jsx)("video",{src:n(a.path),controls:!0,preload:"metadata",className:"rounded-lg max-w-[240px] max-h-[160px]",style:{border:"1px solid var(--color-border)"}},a.tool.toolCallId))}),i>0&&"pdf"===a&&(0,d.jsx)("div",{className:"flex flex-col gap-1.5",children:k.map(a=>{let b=a.path.split("/").pop()??a.path;return(0,d.jsxs)("a",{href:n(a.path),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-3 py-2 rounded-lg text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,d.jsx)(F,{}),(0,d.jsx)("span",{className:"truncate max-w-[200px]",children:b})]},a.tool.toolCallId)})}),i>0&&"audio"===a&&(0,d.jsx)("div",{className:"flex flex-col gap-1.5",children:k.map(a=>(0,d.jsx)("audio",{src:n(a.path),controls:!0,preload:"metadata",className:"max-w-[280px] h-8"},a.tool.toolCallId))})]})]})}function A({path:a,single:b}){let[c,f]=(0,e.useState)(!1),g=a.split("/").pop()??a,h=n(a),i=b?200:80,j=b?150:80;return c?(0,d.jsx)("div",{className:"flex items-center justify-center rounded-lg text-[10px] text-center p-1",style:{width:i,height:j,background:"var(--color-surface-hover)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},title:a,children:(0,d.jsx)("span",{className:"truncate",children:g})}):(0,d.jsx)("a",{href:h,target:"_blank",rel:"noopener noreferrer",className:"block rounded-lg overflow-hidden flex-shrink-0",style:{border:"1px solid var(--color-border)",width:i,height:j},title:g,children:(0,d.jsx)("img",{src:h,alt:g,className:"w-full h-full object-cover",loading:"lazy",onError:()=>f(!0)})})}function B({toolName:a,status:b,args:c,output:f,errorText:g}){let i=v(a,c),[j,k]=(0,e.useState)("exec"===i||"generic"===i),[l,o]=(0,e.useState)(!0),p=function(a,b,c,d){let e=a=>{let b=c?.[a];return"string"==typeof b&&b.length>0?b:null};switch(a){case"search":{let a=e("query")??e("search_query")??e("search")??e("q");return a?`Searching for ${a}`:"Searching..."}case"fetch":{let a=e("url")??e("targetUrl")??e("path")??e("src");if(a)try{return`Fetching ${new URL(a).hostname}`}catch{return`Fetching ${a}`}let b="string"==typeof d?.finalUrl&&d.finalUrl||"string"==typeof d?.url&&d.url;if(b)try{return`Fetched ${new URL(b).hostname}`}catch{return`Fetched ${b}`}return"Fetching page"}case"read":{let a=q(c,d);if(a){let b=a.split("/").pop()??a;return b.startsWith("http")?`Fetching ${b}`:`Reading ${b}`}return"Reading file"}case"exec":{let a=e("command")??e("cmd");if(a)return`Running: ${a}`;return"Running command"}case"write":{let a=e("path")??e("file")??e("file_path");if(a){let b=a.split("/").pop()??a;return`Editing ${b}`}return"Editing file"}case"image":return e("description")?`Generating image: ${e("description")}`:"Generating image";default:{let a=b.replace(/_/g," ").replace(/\b\w/g,a=>a.toUpperCase()).trim();if(c){let b=e("command")??e("cmd")??e("query")??e("path")??e("url")??e("message")??e("description")??e("input")??e("text");if(b)return`${a}: ${b}`}return a||"Tool"}}}(i,a,c,f),r="search"===i?function(a){if(!a)return[];let b="string"==typeof a.text?a.text:"",c=a.results,d=a.citations,e=b;if(Array.isArray(c))for(let a of c)"string"==typeof a?e+=` ${a}`:"object"==typeof a&&null!==a&&("string"==typeof a.url&&(e+=` ${a.url}`),"string"==typeof a.link&&(e+=` ${a.link}`));if(Array.isArray(d))for(let a of d)"string"==typeof a?e+=` ${a}`:"object"==typeof a&&null!==a&&"string"==typeof a.url&&(e+=` ${a.url}`);for(let c of Object.values(a))"string"==typeof c&&c!==b&&c.includes("http")&&(e+=` ${c}`);let f=e.match(t)??[],g=new Set;for(let a of f)try{let b=new URL(a).hostname;b&&!b.includes("localhost")&&g.add(b)}catch{}return[...g].slice(0,8)}(f):"fetch"===i?function(a,b){let c=new Set;for(let b of["url","targetUrl","path","src"]){let d=a?.[b];if("string"==typeof d&&d.startsWith("http"))try{let a=new URL(d).hostname;a&&!a.includes("localhost")&&c.add(a)}catch{}}for(let a of["url","finalUrl","targetUrl"]){let d=b?.[a];if("string"==typeof d&&d.startsWith("http"))try{let a=new URL(d).hostname;a&&!a.includes("localhost")&&c.add(a)}catch{}}return[...c].slice(0,4)}(c,f):[],s="string"==typeof f?.text?f.text:void 0,w=(()=>{if("write"!==i||"done"!==b)return;if("string"==typeof f?.diff)return f.diff;let a="string"==typeof c?.old_string?c.old_string:"string"==typeof c?.oldText?c.oldText:null,d="string"==typeof c?.new_string?c.new_string:"string"==typeof c?.newText?c.newText:null;if(null!==a&&null!==d){var e="string"==typeof c?.path?c.path:"string"==typeof c?.file_path?c.file_path:"file";let b=a.split("\n"),f=d.split("\n"),g=[`--- a/${e}`,`+++ b/${e}`,`@@ -1,${b.length} +1,${f.length} @@`];for(let a of b)g.push(`-${a}`);for(let a of f)g.push(`+${a}`);return g.join("\n")}})(),x=q(c,f),y=x?m(x):null,z="read"===i&&y&&"done"===b;return(0,d.jsxs)("div",{className:"flex items-start gap-2.5 py-1.5",children:[(0,d.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:"error"===b?(0,d.jsx)(E,{}):(0,d.jsx)("span",{className:"running"===b?"animate-pulse":"",children:(0,d.jsx)(D,{kind:i})})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"text-[13px] leading-snug flex items-center gap-2 flex-wrap",style:{color:"running"===b?"var(--color-text)":"var(--color-text-secondary)"},children:[(0,d.jsx)("span",{className:`break-all${"running"===b?" animate-pulse":""}`,children:p}),"exec"===i&&"done"===b&&f?.exitCode!==void 0&&(0,d.jsxs)("span",{className:"text-[11px] font-mono px-1.5 py-0.5 rounded",style:{background:0===f.exitCode?"color-mix(in srgb, var(--color-success, #22c55e) 12%, transparent)":"color-mix(in srgb, var(--color-error) 12%, transparent)",color:0===f.exitCode?"var(--color-success, #22c55e)":"var(--color-error)"},children:["exit ","object"==typeof f.exitCode&&null!=f.exitCode?JSON.stringify(f.exitCode):"number"==typeof f.exitCode?String(f.exitCode):"string"==typeof f.exitCode?f.exitCode:""]})]}),w&&"done"===b&&(0,d.jsxs)("div",{className:"mt-1.5",children:[(0,d.jsx)("button",{type:"button",onClick:()=>o(a=>!a),className:"text-[11px] hover:underline cursor-pointer mb-1",style:{color:"var(--color-accent)"},children:l?"Hide changes":"Show changes"}),l&&(0,d.jsx)(h.a,{diff:w})]}),z&&x&&"image"===y&&(0,d.jsx)("div",{className:"mt-1.5",children:(0,d.jsx)(A,{path:x,single:!0})}),z&&x&&"video"===y&&(0,d.jsx)("video",{src:n(x),controls:!0,preload:"metadata",className:"mt-1.5 rounded-lg max-w-[240px] max-h-[160px]",style:{border:"1px solid var(--color-border)"}}),z&&x&&"pdf"===y&&(0,d.jsxs)("a",{href:n(x),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 mt-1.5 px-3 py-2 rounded-lg text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,d.jsx)(F,{}),(0,d.jsx)("span",{className:"truncate max-w-[200px]",children:x.split("/").pop()??x})]}),z&&x&&"audio"===y&&(0,d.jsx)("audio",{src:n(x),controls:!0,preload:"metadata",className:"mt-1.5 max-w-[280px] h-8"}),r.length>0&&"running"!==b&&(0,d.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-1.5",children:r.map(a=>(0,d.jsx)(C,{domain:a},a))}),("search"===i||"fetch"===i)&&"running"===b&&c&&(0,d.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-1.5",children:r.length>0?r.map(a=>(0,d.jsxs)("span",{className:"inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,d.jsx)("img",{src:u(a),alt:"",width:14,height:14,className:"rounded-sm flex-shrink-0",loading:"lazy"}),a.replace(/^www\./,""),(0,d.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse",style:{background:"var(--color-accent)"}})]},a)):(0,d.jsxs)("span",{className:"inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[(0,d.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse",style:{background:"var(--color-accent)"}}),"fetch"===i?"Fetching...":"Searching..."]})}),"error"===b&&g&&(0,d.jsx)("div",{className:"mt-1.5 text-[12px] font-mono rounded-lg px-2.5 py-1.5",style:{color:"var(--color-error)",background:"color-mix(in srgb, var(--color-error) 6%, var(--color-surface))"},children:g}),!s&&!w&&!z&&"done"===b&&c&&Object.keys(c).length>0&&(0,d.jsx)("pre",{className:"mt-1 text-[11px] font-mono rounded-lg px-2.5 py-1.5 whitespace-pre-wrap break-all max-h-48 overflow-y-auto leading-relaxed",style:{color:"var(--color-text-muted)",background:"var(--color-bg)"},children:function(a){let b=[];for(let[c,d]of Object.entries(a)){if(null==d)continue;let a="string"==typeof d?d:JSON.stringify(d,null,2);b.push(`${c}: ${a}`)}let c=b.join("\n");return c.length>2e3?c.slice(0,2e3)+"\n...":c}(c)}),s&&!z&&!w&&(0,d.jsxs)("div",{className:"mt-1",children:["done"===b&&(0,d.jsx)("button",{type:"button",onClick:()=>k(a=>!a),className:"text-[11px] hover:underline cursor-pointer",style:{color:"var(--color-accent)"},children:j?"Hide output":"Show output"}),(j||"running"===b)&&(0,d.jsx)("pre",{className:"mt-1 text-[11px] font-mono rounded-lg px-2.5 py-2 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto leading-relaxed",style:{color:"var(--color-text-muted)",background:"var(--color-bg)"},children:s.length>1e4?s.slice(0,1e4)+"\n... (truncated)":s})]})]})]})}function C({domain:a}){let b=a.replace(/^www\./,"");return(0,d.jsxs)("span",{className:"inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,d.jsx)("img",{src:u(a),alt:"",width:16,height:16,className:"rounded-sm flex-shrink-0",loading:"lazy"}),b]})}function D({kind:a}){let b="var(--color-text-muted)";switch(a){case"search":return(0,d.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,d.jsx)("path",{d:"m21 21-4.3-4.3"})]});case"fetch":return(0,d.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,d.jsx)("path",{d:"M2 12h20"}),(0,d.jsx)("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]});case"read":return(0,d.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,d.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]});case"exec":return(0,d.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,d.jsx)("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]});case"write":return(0,d.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),(0,d.jsx)("path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"})]});case"image":return(0,d.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,d.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,d.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});default:return(0,d.jsx)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("circle",{cx:"12",cy:"12",r:"1"})})}}function E(){return(0,d.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-error)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,d.jsx)("line",{x1:"15",x2:"9",y1:"9",y2:"15"}),(0,d.jsx)("line",{x1:"9",x2:"15",y1:"9",y2:"15"})]})}function F(){return(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,d.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),(0,d.jsx)("path",{d:"M10 9H8"}),(0,d.jsx)("path",{d:"M16 13H8"}),(0,d.jsx)("path",{d:"M16 17H8"})]})}function G({className:a}){return(0,d.jsxs)("svg",{className:a,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 2a7 7 0 0 0-7 7c0 2.38 1.19 4.47 3 5.74V17a2 2 0 0 0 2 2h4a2 2 0 0 0 2-2v-2.26c1.81-1.27 3-3.36 3-5.74a7 7 0 0 0-7-7z"}),(0,d.jsx)("path",{d:"M10 21h4"}),(0,d.jsx)("path",{d:"M9 9.4a3 3 0 0 1 5.1-2"})]})}function H({className:a}){return(0,d.jsx)("svg",{className:a,viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M3 4.5L6 7.5L9 4.5"})})}},42967:(a,b,c)=>{"use strict";c.d(b,{S:()=>ae});var d=c(36927),e=c(15962),f=c(81918),g=c(49855);function h(){return(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.5},children:[(0,d.jsx)("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),(0,d.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function i({x:a,y:b,target:c,onAction:f,onClose:i}){let j=(0,e.useRef)(null),k=function(a){let b="empty"!==a.kind&&a.isSystem;return"file"===a.kind?[{action:"open",label:"Open"},{separator:!0},{action:"rename",label:"Rename",shortcut:"Enter",disabled:b},{action:"duplicate",label:"Duplicate",shortcut:"⌘D",disabled:b},{action:"copy",label:"Copy Path",shortcut:"⌘C"},{separator:!0},{action:"getInfo",label:"Get Info",shortcut:"⌘I"},{separator:!0},{action:"delete",label:"Move to Trash",shortcut:"⌘⌫",disabled:b,danger:!0}]:"folder"===a.kind?[{action:"open",label:"Open"},{separator:!0},{action:"newFile",label:"New File",shortcut:"⌘N",disabled:b},{action:"newFolder",label:"New Folder",shortcut:"⇧⌘N",disabled:b},{separator:!0},{action:"rename",label:"Rename",shortcut:"Enter",disabled:b},{action:"duplicate",label:"Duplicate",shortcut:"⌘D",disabled:b},{action:"copy",label:"Copy Path",shortcut:"⌘C"},{separator:!0},{action:"getInfo",label:"Get Info",shortcut:"⌘I"},{separator:!0},{action:"delete",label:"Move to Trash",shortcut:"⌘⌫",disabled:b,danger:!0}]:[{action:"newFile",label:"New File",shortcut:"⌘N"},{action:"newFolder",label:"New Folder",shortcut:"⇧⌘N"},{separator:!0},{action:"paste",label:"Paste",shortcut:"⌘V",disabled:!0}]}(c),l="empty"!==c.kind&&c.isSystem;(0,e.useRef)({x:a,y:b});let m=(0,e.useCallback)((a,b)=>{b||(f(a),i())},[f,i]);return(0,g.createPortal)((0,d.jsxs)("div",{ref:j,className:"fixed z-[9999] min-w-[200px] py-1 rounded-lg shadow-xl border",style:{left:a,top:b,background:"var(--color-surface)",borderColor:"var(--color-border)",backdropFilter:"blur(20px)",WebkitBackdropFilter:"blur(20px)",animation:"contextMenuFadeIn 100ms ease-out"},role:"menu",children:[l&&(0,d.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 text-[11px]",style:{color:"var(--color-text-muted)"},children:[(0,d.jsx)(h,{}),(0,d.jsx)("span",{children:"System file (locked)"})]}),k.map((a,b)=>{if("separator"in a&&a.separator)return(0,d.jsx)("div",{className:"my-1 mx-2 border-t",style:{borderColor:"var(--color-border)"}},`sep-${b}`);let c=a.disabled;return(0,d.jsxs)("button",{type:"button",role:"menuitem",disabled:c,className:"w-full flex items-center gap-2 px-3 py-1.5 text-[13px] text-left transition-colors",style:{color:c?"var(--color-text-muted)":a.danger?"#ef4444":"var(--color-text)",opacity:c?.5:1,cursor:c?"default":"pointer"},onMouseEnter:b=>{c||(b.currentTarget.style.background=a.danger?"rgba(239, 68, 68, 0.1)":"var(--color-surface-hover)")},onMouseLeave:a=>{a.currentTarget.style.background="transparent"},onClick:()=>m(a.action,c),children:[a.icon,(0,d.jsx)("span",{className:"flex-1",children:a.label}),c&&l&&(0,d.jsx)(h,{}),a.shortcut&&(0,d.jsx)("span",{className:"text-[11px] ml-4",style:{color:"var(--color-text-muted)"},children:a.shortcut})]},a.action)}),(0,d.jsx)("style",{children:`
139
+ ${o}`,Z.current=!1}ab.current.set(o,d),ac.current=d,ay.current=!1,ar({text:o})},[L,aw,B,aA,l,m,am,a,ar]),aJ=(0,h.useRef)(as);(0,h.useEffect)(()=>{let a="streaming"===aJ.current||"submitted"===aJ.current,b="ready"===as;if(aJ.current=as,a&&b&&ad.length>0){let[a,...b]=ad;for(let c of(ae(b),a.attachedFiles))c.localUrl&&URL.revokeObjectURL(c.localUrl);queueMicrotask(()=>{aI(a.text,a.mentionedFiles,a.html,a.attachedFiles)})}},[as,ad,aI]);let aK=(0,h.useCallback)(async a=>{if(a!==B){U.current?.abort(),at(),J(!0),C(a),an.current=a,l?.(a),X.current.clear(),Z.current=!1,ae([]);try{let b=await fetch(`/api/web-sessions/${a}`);if(!b.ok)throw Error("Failed to load session");let c=(await b.json()).messages||[],d=c.some(a=>a._streaming)?c.filter(a=>!a._streaming):c;for(let a of(ab.current.clear(),d))"user"===a.role&&a.html&&ab.current.set(a.id,a.html);let e=d.map(a=>(X.current.add(a.id),{id:a.id,role:a.role,parts:a.parts??[{type:"text",text:a.content}]}));av(e),J(!1),await aB(a,e)}catch(a){console.error("Error loading session:",a),J(!1)}}},[B,av,l,at,aB]),aL=(0,h.useCallback)(()=>{U.current?.abort(),at(),T(!1),C(null),an.current=null,l?.(null),av([]),X.current.clear(),ab.current.clear(),Z.current=!0,Y.current=!1,ae([]),requestAnimationFrame(()=>{y.current?.focus()})},[av,l,at]);aH.current=aL,(0,h.useImperativeHandle)(w,()=>({loadSession:aK,newSession:async()=>{aL()},sendNewMessage:async a=>{aL();let b=a.length>60?a.slice(0,60)+"...":a,c=await aA(b);C(c),an.current=c,l?.(c),m?.(),ay.current=!1,ar({text:a})},insertFileMention:(a,b)=>{y.current?.insertFileMention(a,b)}}),[aK,aL,aA,l,m,ar]);let aM=(0,h.useCallback)(async()=>{if(U.current?.abort(),T(!1),s||B)try{await fetch("/api/chat/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s?{sessionKey:s}:{sessionId:B})})}catch{}at()},[B,s,at]),aN=(0,h.useCallback)(a=>{ae(b=>b.filter(b=>b.id!==a))},[]),aO=(0,h.useCallback)((a,b)=>{ae(c=>c.map(c=>c.id===a?{...c,text:b}:c))},[]),aP=(0,h.useCallback)(async a=>{let b=ad.find(b=>b.id===a);b&&(ae(b=>b.filter(b=>b.id!==a)),await aM(),setTimeout(()=>{aI(b.text,b.mentionedFiles,b.html,b.attachedFiles)},100))},[ad,aM,aI]),aQ=(0,h.useCallback)(a=>{let b=a.map(a=>({id:`${a.path}-${Date.now()}-${Math.random().toString(36).slice(2)}`,name:a.name,path:a.path}));P(a=>[...a,...b])},[]),aR=(0,h.useCallback)(a=>{P(b=>{let c=b.find(b=>b.id===a);return c?.localUrl&&URL.revokeObjectURL(c.localUrl),b.filter(b=>b.id!==a)})},[]),aS=(0,h.useCallback)(()=>{P(a=>{for(let b of a)b.localUrl&&URL.revokeObjectURL(b.localUrl);return[]})},[]),aT=(0,h.useCallback)(a=>{let b=Array.from(a),c=b.map(a=>({id:`pending-${Date.now()}-${Math.random().toString(36).slice(2)}`,name:a.name,path:"",uploading:!0,localUrl:URL.createObjectURL(a)}));P(a=>[...a,...c]);for(let a=0;a<b.length;a++){let d=b[a],e=c[a].id,f=c[a].localUrl,g=new FormData;g.append("file",d),fetch("/api/workspace/upload",{method:"POST",body:g}).then(a=>a.ok?a.json():null).then(a=>{a?.ok&&a.path?P(b=>b.map(b=>b.id===e?{...b,path:a.path,uploading:!1}:b)):(P(a=>a.filter(a=>a.id!==e)),f&&URL.revokeObjectURL(f))}).catch(()=>{P(a=>a.filter(a=>a.id!==e)),f&&URL.revokeObjectURL(f)})}},[]),aU=aq.length>0?aq[aq.length-1]:null,aV=aU?.role==="assistant"&&aU.parts.some(a=>"text"===a.type&&a.text.length>0),aW=aw&&!aV,aX=0===aq.length&&!b&&!x&&!D,aY=(0,e.jsxs)(e.Fragment,{children:[ad.length>0&&(0,e.jsx)("div",{className:b?"px-2 pt-2":"px-3 pt-3",children:(0,e.jsxs)("div",{className:"rounded-xl border overflow-hidden",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",boxShadow:"var(--shadow-sm)"},children:[(0,e.jsxs)("div",{className:"px-3 py-1.5 text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--color-text-muted)",background:"var(--color-surface-hover)"},children:["Queue (",ad.length,")"]}),(0,e.jsx)("div",{className:"flex flex-col p-2",children:ad.map((a,b)=>(0,e.jsx)(M,{msg:a,idx:b,onEdit:aO,onSendNow:aP,onRemove:aN},a.id))})]})}),!x&&(0,e.jsx)(N,{files:L,compact:b,onRemove:aR,onClearAll:aS}),(0,e.jsx)(G.y,{ref:y,onSubmit:aI,onChange:a=>A(a),onNativeFileDrop:x?void 0:aT,placeholder:aX?"Build a workflow to automate your tasks":x?aw?"Type to queue a message...":"Type @ to mention files...":b&&a?`Ask about ${a.isDirectory?"this folder":a.filename}...`:aw?"Type to queue a message...":L.length>0?"Add a message or send files...":"Type @ to mention files...",disabled:D,compact:b}),(0,e.jsxs)("div",{className:`flex items-center justify-between ${b?"px-2 pb-1.5":"px-3 pb-2.5"}`,children:[(0,e.jsx)("div",{className:"flex items-center gap-0.5",children:!x&&(0,e.jsx)("button",{type:"button",onClick:()=>R(!0),className:"p-1.5 rounded-lg hover:opacity-80 transition-opacity",style:{color:L.length>0?"var(--color-accent)":"var(--color-text-muted)"},title:"Attach files",children:(0,e.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"})})})}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[aw&&(0,e.jsx)("button",{type:"button",onClick:()=>aM(),className:`${b?"w-6 h-6":"w-7 h-7"} rounded-full flex items-center justify-center`,style:{background:"var(--color-text)",color:"var(--color-bg)"},title:"Stop generating",children:(0,e.jsx)("svg",{width:"8",height:"8",viewBox:"0 0 10 10",fill:"currentColor",children:(0,e.jsx)("rect",{width:"10",height:"10",rx:"1.5"})})}),aw?(0,e.jsxs)("button",{type:"button",onClick:()=>y.current?.submit(),disabled:z&&0===L.length||D,className:"h-7 px-3 rounded-full flex items-center gap-1.5 text-[12px] font-medium disabled:opacity-40 disabled:cursor-not-allowed",style:{background:!z||L.length>0?"var(--color-accent)":"var(--color-surface-hover)",color:!z||L.length>0?"white":"var(--color-text-muted)"},title:"Add to queue",children:[(0,e.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("polyline",{points:"9 10 4 15 9 20"}),(0,e.jsx)("path",{d:"M20 4v7a4 4 0 0 1-4 4H4"})]}),"Queue"]}):(0,e.jsx)("button",{type:"button",onClick:()=>y.current?.submit(),disabled:z&&0===L.length||D,className:`${b?"w-6 h-6":"w-7 h-7"} rounded-full flex items-center justify-center disabled:opacity-50 disabled:cursor-not-allowed`,style:{background:!z||L.length>0?"var(--color-accent)":"var(--color-text-muted)",color:!z||L.length>0?"white":"var(--color-bg)"},title:"Send message",children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M12 19V5"}),(0,e.jsx)("path",{d:"m5 12 7-7 7 7"})]})})]})]})]}),aZ=(a,b,c)=>(0,e.jsx)("div",{"data-chat-drop-target":"",className:"rounded-3xl overflow-hidden border shadow-[0_0_32px_rgba(0,0,0,0.07)] transition-[outline,box-shadow] duration-150 ease-out data-drag-hover:outline-2 data-drag-hover:outline-dashed data-drag-hover:outline-(--color-accent) data-drag-hover:-outline-offset-2 data-drag-hover:shadow-[0_0_0_4px_color-mix(in_srgb,var(--color-accent)_15%,transparent),0_0_32px_rgba(0,0,0,0.07)]!",style:{background:"var(--color-surface)",borderColor:"var(--color-border)"},onDragOver:a,onDragLeave:b,onDrop:c,children:aY}),a$=a=>{(a.dataTransfer?.types.includes("application/x-file-mention")||a.dataTransfer?.types.includes("Files"))&&(a.preventDefault(),a.dataTransfer.dropEffect="copy",a.currentTarget.setAttribute("data-drag-hover",""))},a_=a=>{a.currentTarget.contains(a.relatedTarget)||a.currentTarget.removeAttribute("data-drag-hover")},a0=a=>{a.currentTarget.removeAttribute("data-drag-hover");let b=a.dataTransfer?.getData("application/x-file-mention");if(b){a.preventDefault(),a.stopPropagation();try{let{name:a,path:c}=JSON.parse(b);a&&c&&y.current?.insertFileMention(a,c)}catch{}return}let c=a.dataTransfer?.files;c&&c.length>0&&(a.preventDefault(),a.stopPropagation(),aT(c))};return(0,e.jsx)(i.o,{children:(0,e.jsxs)("div",{className:"h-full flex flex-col",style:{background:"var(--color-main-bg)"},children:[(0,e.jsx)("header",{className:`${b?"px-3 py-2":"px-3 py-2 md:px-6 md:py-3"} flex items-center ${x?"gap-3":"justify-between"} z-20`,style:{background:"var(--color-bg-glass)"},children:x?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("button",{type:"button",onClick:v,className:"p-1.5 rounded-lg flex-shrink-0",style:{color:"var(--color-text-muted)"},title:"Back to parent chat",children:(0,e.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"m12 19-7-7 7-7"}),(0,e.jsx)("path",{d:"M19 12H5"})]})}),(0,e.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,e.jsx)("h2",{className:"text-sm font-semibold truncate",style:{color:"var(--color-text)"},children:u||(t&&t.length>60?t.slice(0,60)+"...":t)}),(0,e.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:aw?(0,e.jsx)(I.V,{name:"braille"}):"Completed"})]})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"min-w-0 flex-1",children:b&&a?(0,e.jsxs)("h2",{className:"text-xs font-semibold truncate",style:{color:"var(--color-text)"},children:["Chat: ",a.filename]}):(0,e.jsx)("h2",{className:"text-sm font-semibold",style:{color:"var(--color-text)"},children:B?c||"Chat Session":"New Chat"})}),(0,e.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[B&&q&&(0,e.jsxs)(H.rI,{children:[(0,e.jsx)(H.ty,{className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},title:"More options","aria-label":"More options",children:(0,e.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("circle",{cx:"12",cy:"12",r:"1"}),(0,e.jsx)("circle",{cx:"5",cy:"12",r:"1"}),(0,e.jsx)("circle",{cx:"19",cy:"12",r:"1"})]})}),(0,e.jsx)(H.SQ,{align:"end",side:"bottom",children:(0,e.jsxs)(H._2,{variant:"destructive",onSelect:()=>q(B),children:[(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M3 6h18"}),(0,e.jsx)("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),(0,e.jsx)("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})]}),"Delete"]})})]}),b&&(0,e.jsx)("button",{type:"button",onClick:()=>aL(),className:"p-1.5 rounded-lg",style:{color:"var(--color-text-muted)"},title:"New chat",children:(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M12 5v14"}),(0,e.jsx)("path",{d:"M5 12h14"})]})})]})]})}),!x&&b&&a&&_.length>0&&(0,e.jsx)("div",{className:"px-2 py-1.5 border-b flex gap-1 overflow-x-auto z-20",style:{borderColor:"var(--color-border)",background:"var(--color-bg-glass)"},children:_.slice(0,10).map(a=>(0,e.jsx)("button",{type:"button",onClick:()=>aK(a.id),className:"px-2.5 py-1 text-[10px] rounded-full whitespace-nowrap shrink-0 font-medium",style:{background:a.id===B?"var(--color-accent)":"var(--color-surface-hover)",color:a.id===B?"white":"var(--color-text-muted)",border:a.id===B?"none":"1px solid var(--color-border)"},children:a.title.length>25?a.title.slice(0,25)+"...":a.title},a.id))}),(0,e.jsxs)("div",{ref:ax,className:"flex-1 overflow-y-auto min-h-0",children:[(0,e.jsx)("div",{className:b?"px-3":"px-6",children:D?(0,e.jsx)("div",{className:"flex items-center justify-center h-full min-h-[60vh]",children:(0,e.jsxs)("div",{className:"text-center",children:[(0,e.jsx)(I.V,{name:"braille",className:"block text-2xl mx-auto mb-3",style:{color:"var(--color-text-muted)"}}),(0,e.jsx)("p",{className:"text-xs",style:{color:"var(--color-text-muted)"},children:"Loading session..."})]})}):aX?(0,e.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-[75vh] py-12",children:[ah&&(0,e.jsx)(j.P.h1,{className:"text-4xl md:text-5xl font-light tracking-normal font-instrument mb-10 text-center",style:{color:"var(--color-text)"},initial:"hidden",animate:"visible",variants:{hidden:{opacity:0},visible:{opacity:1,transition:{staggerChildren:.12,delayChildren:.2}}},children:ah.split(" ").map((a,b)=>(0,e.jsx)(j.P.span,{className:"inline-block mr-2",variants:{hidden:{opacity:0,y:20,filter:"blur(8px)"},visible:{opacity:1,y:0,filter:"blur(0px)",transition:{duration:.8,ease:[.2,.65,.3,.9]}}},children:a},b))}),(0,e.jsx)(j.P.div,{className:"w-full max-w-[720px] mx-auto px-4",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.8,delay:.8,ease:[.22,1,.36,1]},children:(0,e.jsx)(j.P.div,{layout:!0,layoutId:"chat-input-bar",transition:{type:"spring",stiffness:260,damping:30},children:aZ(a$,a_,a0)})}),(0,e.jsxs)(j.P.div,{className:"mt-6 flex flex-col gap-2.5 w-full max-w-[720px] mx-auto px-4",initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5,delay:1,ease:[.22,1,.36,1]},children:[(0,e.jsx)("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:aj.slice(0,3).map(a=>{let b=a.icon;return(0,e.jsxs)("button",{type:"button",onClick:()=>al(a.id),className:"group flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium whitespace-nowrap rounded-xl transition-all duration-200 border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text-secondary)"},children:[(0,e.jsx)(b,{className:"w-3.5 h-3.5 opacity-50 group-hover:opacity-100 transition-opacity duration-200"}),a.label]},a.id)})}),(0,e.jsx)("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:aj.slice(3,7).map(a=>{let b=a.icon;return(0,e.jsxs)("button",{type:"button",onClick:()=>al(a.id),className:"group flex items-center gap-1.5 px-3.5 py-2 text-xs font-medium whitespace-nowrap rounded-xl transition-all duration-200 border",style:{background:"var(--color-surface)",borderColor:"var(--color-border)",color:"var(--color-text-secondary)"},children:[(0,e.jsx)(b,{className:"w-3.5 h-3.5 opacity-50 group-hover:opacity-100 transition-opacity duration-200"}),a.label]},a.id)})})]})]}):0===aq.length?(0,e.jsx)("div",{className:"flex items-center justify-center h-full min-h-[60vh]",children:(0,e.jsx)("div",{className:"text-center max-w-md px-4",children:(0,e.jsx)("p",{className:"text-sm",style:{color:"var(--color-text-muted)"},children:"Ask about this file"})})}):(0,e.jsxs)("div",{className:`${b?"":"max-w-2xl mx-auto"} py-3`,children:[af?(0,e.jsx)("pre",{className:"text-xs whitespace-pre-wrap break-all font-mono p-4 rounded-xl",style:{color:"var(--color-text)",background:"var(--color-surface-hover)"},children:JSON.stringify(aq,null,2)}):aq.map((a,b)=>(0,e.jsx)(E.c,{message:a,isStreaming:aw&&b===aq.length-1,onSubagentClick:o,onFilePathClick:p,sessionId:B,userHtmlMap:ab.current},a.id)),aW&&(0,e.jsx)("div",{className:"py-3 min-w-0",children:(0,e.jsx)(I.V,{name:"pulse",className:"text-base",style:{color:"var(--color-text-muted)"}})}),(0,e.jsx)("div",{ref:K})]})}),(au||V)&&(0,e.jsxs)("div",{className:"px-3 py-2 flex items-center gap-2 sticky bottom-[72px] z-10",style:{background:"color-mix(in srgb, var(--color-error) 6%, var(--color-surface))",borderColor:"color-mix(in srgb, var(--color-error) 18%, transparent)",color:"var(--color-error)"},children:[(0,e.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:[(0,e.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,e.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,e.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),(0,e.jsx)("p",{className:"text-xs",children:au?.message??V})]})]}),!aX&&(0,e.jsx)("div",{className:`${b?"px-3 py-2":"px-3 pb-3 pt-0 md:px-6 md:pb-5"} z-20`,style:{background:"var(--color-bg-glass)"},children:(0,e.jsx)("div",{className:b?"":"max-w-[720px] mx-auto",children:(0,e.jsx)(j.P.div,{layout:!0,layoutId:"chat-input-bar",transition:{type:"spring",stiffness:260,damping:30},children:aZ(a$,a_,a0)})})}),!x&&(0,e.jsx)(F.C,{open:Q,onClose:()=>R(!1),onSelect:aQ})]})})});d()}catch(a){d(a)}})},38182:(a,b,c)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"});let d=c(61442),e=c(3182),f=c(5033);b.sortBy=function(a,...b){let c=b.length;return c>1&&f.isIterateeCall(a,b[0],b[1])?b=[]:c>2&&f.isIterateeCall(b[0],b[1],b[2])&&(b=[b[0]]),d.orderBy(a,e.flatten(b),["asc"])}},38899:(a,b)=>{"use strict";function c(a){return a.split("/").map(a=>encodeURIComponent(a)).join("/")}Object.defineProperty(b,"__esModule",{value:!0}),Object.defineProperty(b,"encodeURIPath",{enumerable:!0,get:function(){return c}})},39065:(a,b,c)=>{let d=c(64334),e=c(28123),f=c(26821),g=c(47186),h=c(84878),i=c(68956),j=c(7223),k=c(8366),l=c(11609),m=c(37519),n=c(12089),{FormulaHelpers:o}=c(28358),{Parser:p,allTokens:q}=c(69213),r=c(10490),s=c(5296);class t{constructor(a,b=!1){this.logs=[],this.isTest=b,this.utils=new s(this),a=Object.assign({functions:{},functionsNeedContext:{},onVariable:()=>null,onCell:()=>0,onRange:()=>[[0]]},a),this.onVariable=a.onVariable,this.functions=Object.assign({},l,k,j,i,h,g,d,e,f,m,a.functions,a.functionsNeedContext),this.onRange=a.onRange,this.onCell=a.onCell,this.funsNullAs0=Object.keys(e).concat(Object.keys(f)).concat(Object.keys(g)).concat(Object.keys(h)).concat(Object.keys(i)).concat(Object.keys(k)).concat(Object.keys(l)),this.funsNeedContextAndNoDataRetrieve=["ROW","ROWS","COLUMN","COLUMNS","SUMIF","INDEX","AVERAGEIF","IF"],this.funsNeedContext=[...Object.keys(a.functionsNeedContext),...this.funsNeedContextAndNoDataRetrieve,"INDEX","OFFSET","INDIRECT","IF","CHOOSE","WEBSERVICE"],this.funsPreserveRef=Object.keys(j),this.parser=new p(this,this.utils)}static get allTokens(){return q}getCell(a){return null==a.sheet&&(a.sheet=this.position?this.position.sheet:void 0),this.onCell(a)}getRange(a){return null==a.sheet&&(a.sheet=this.position?this.position.sheet:void 0),this.onRange(a)}getVariable(a){let b={ref:this.onVariable(a,this.position.sheet,this.position)};return null==b.ref?n.NAME:b}retrieveRef(a){return o.isRangeRef(a)?this.getRange(a.ref):o.isCellRef(a)?this.getCell(a.ref):a}_callFunction(a,b){0===a.indexOf("_xlfn.")&&(a=a.slice(6)),a=a.toUpperCase();let c=this.funsNullAs0.includes(a)?0:"";if(this.funsNeedContextAndNoDataRetrieve.includes(a)||(b=b.map(b=>{if(null===b)return{value:c,isArray:!1,omitted:!0};let d=this.utils.extractRefValue(b);return this.funsPreserveRef.includes(a)?{value:d.val,isArray:d.isArray,ref:b.ref}:{value:d.val,isArray:d.isArray,isRangeRef:!!o.isRangeRef(b),isCellRef:!!o.isCellRef(b)}})),this.functions[a]){let c;try{c=this.funsNeedContextAndNoDataRetrieve.includes(a)||this.funsNeedContext.includes(a)?this.functions[a](this,...b):this.functions[a](...b)}catch(a){if(a instanceof n)return a;throw a}if(void 0===c){if(this.isTest)return this.logs.includes(a)||this.logs.push(a),{value:0,ref:{}};throw n.NOT_IMPLEMENTED(a)}return c}if(this.isTest)return this.logs.includes(a)||this.logs.push(a),{value:0,ref:{}};throw n.NOT_IMPLEMENTED(a)}async callFunctionAsync(a,b){let c=[];for(let a of b)c.push(await a);let d=await this._callFunction(a,c);return o.checkFunctionResult(d)}callFunction(a,b){if(this.async)return this.callFunctionAsync(a,b);{let c=this._callFunction(a,b);return o.checkFunctionResult(c)}}supportedFunctions(){let a=[];return Object.keys(this.functions).forEach(b=>{try{let c=this.functions[b](0,0,0,0,0,0,0,0,0,0,0);if(void 0===c)return;a.push(b)}catch(c){c instanceof Error&&a.push(b)}}),a.sort()}checkFormulaResult(a,b=!1){let c=typeof a;if("number"===c){if(isNaN(a))return n.VALUE;if(!isFinite(a))return n.NUM;a+=0}else if("object"===c){if(a instanceof n)return a;if(b){if(a.ref&&(a=this.retrieveRef(a)),"object"==typeof a&&!Array.isArray(a)&&null!=a)return n.VALUE}else if(a.ref&&a.ref.row&&!a.ref.from)a=this.retrieveRef(a);else if(a.ref&&a.ref.from&&a.ref.from.col===a.ref.to.col)a=this.retrieveRef({ref:{row:a.ref.from.row,col:a.ref.from.col}});else{if(!Array.isArray(a))return n.VALUE;a=a[0][0]}}return a}parse(a,b,c=!1){let d;if(0===a.length)throw Error("Input must not be empty.");this.position=b,this.async=!1;let e=r.lex(a);this.parser.input=e.tokens;try{if(d=this.parser.formulaWithBinaryOp(),(d=this.checkFormulaResult(d,c))instanceof n)return d}catch(a){throw n.ERROR(a.message,a)}if(this.parser.errors.length>0){let b=this.parser.errors[0];throw s.formatChevrotainError(b,a)}return d}async parseAsync(a,b,c=!1){let d;if(0===a.length)throw Error("Input must not be empty.");this.position=b,this.async=!0;let e=r.lex(a);this.parser.input=e.tokens;try{if(d=await this.parser.formulaWithBinaryOp(),(d=this.checkFormulaResult(d,c))instanceof n)return d}catch(a){throw n.ERROR(a.message,a)}if(this.parser.errors.length>0){let b=this.parser.errors[0];throw s.formatChevrotainError(b,a)}return d}}a.exports={FormulaParser:t,FormulaHelpers:o}},39384:(a,b)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"}),b.isObject=function(a){return null!==a&&("object"==typeof a||"function"==typeof a)}},39914:(a,b,c)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"});let d=c(80656),e=c(32468),f=c(83037),g=c(95802),h=c(55516);function i(a){let b=[];for(let c in a)b.push(c);return b}b.keysIn=function(a){if(null==a)return[];switch(typeof a){case"object":case"function":if(f.isArrayLike(a)){var b=a;let c=h.times(b.length,a=>`${a}`),e=new Set(c);d.isBuffer(b)&&(e.add("offset"),e.add("parent")),g.isTypedArray(b)&&(e.add("buffer"),e.add("byteLength"),e.add("byteOffset"));let f=i(b).filter(a=>!e.has(a));return Array.isArray(b)?[...c,...f]:[...c.filter(a=>Object.hasOwn(b,a)),...f]}if(e.isPrototype(a))return i(a).filter(a=>"constructor"!==a);return i(a);default:return i(Object(a))}}},39957:(a,b)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"}),b.getSymbols=function(a){return Object.getOwnPropertySymbols(a).filter(b=>Object.prototype.propertyIsEnumerable.call(a,b))}},41025:a=>{"use strict";a.exports=require("next/dist/server/app-render/dynamic-access-async-storage.external.js")},41204:a=>{"use strict";a.exports=require("string_decoder")},41778:(a,b,c)=>{"use strict";Object.defineProperty(b,Symbol.toStringTag,{value:"Module"});let d=c(58422);b.cloneDeep=function(a){return d.cloneDeepWith(a)}},41790:(a,b,c)=>{let d=c(12089),{FormulaHelpers:e}=c(28358),f={boolean:3,string:2,number:1};a.exports={Prefix:{unaryOp:(a,b,c)=>{let f=1;if(a.forEach(a=>{if("+"===a);else if("-"===a)f=-f;else throw Error(`Unrecognized prefix: ${a}`)}),null==b&&(b=0),1===f)return b;try{b=e.acceptNumber(b,c)}catch(a){if(a instanceof d)Array.isArray(b)&&(b=b[0][0]);else throw a}return"number"==typeof b&&isNaN(b)?d.VALUE:-b}},Postfix:{percentOp:(a,b,c)=>{try{a=e.acceptNumber(a,c)}catch(a){if(a instanceof d)return a;throw a}if("%"===b)return a/100;throw Error(`Unrecognized postfix: ${b}`)}},Infix:{compareOp:(a,b,c,d,e)=>{null==a&&(a=0),null==c&&(c=0),d&&(a=a[0][0]),e&&(c=c[0][0]);let g=typeof a,h=typeof c;if(g===h)switch(b){case"=":return a===c;case">":return a>c;case"<":return a<c;case"<>":return a!==c;case"<=":return a<=c;case">=":return a>=c}else switch(b){case"=":return!1;case">":return f[g]>f[h];case"<":return f[g]<f[h];case"<>":return!0;case"<=":return f[g]<=f[h];case">=":return f[g]>=f[h]}throw Error("Infix.compareOp: Should not reach here.")},concatOp:(a,b,c,d,e)=>(null==a&&(a=""),null==c&&(c=""),d&&(a=a[0][0]),e&&(c=c[0][0]),"boolean"==typeof a&&(a=a?"TRUE":"FALSE"),"boolean"==typeof c&&(c=c?"TRUE":"FALSE"),""+a+c),mathOp:(a,b,c,f,g)=>{null==a&&(a=0),null==c&&(c=0);try{a=e.acceptNumber(a,f),c=e.acceptNumber(c,g)}catch(a){if(a instanceof d)return a;throw a}switch(b){case"+":return a+c;case"-":return a-c;case"*":return a*c;case"/":if(0===c)return d.DIV0;return a/c;case"^":return a**c}throw Error("Infix.mathOp: Should not reach here.")}},Operators:{compareOp:["<",">","=","<>","<=",">="],concatOp:["&"],mathOp:["+","-","*","/","^"]}}},42125:(a,b,c)=>{"use strict";c.d(b,{A:()=>d});let d=(0,c(15336).A)("pen-tool",[["path",{d:"M15.707 21.293a1 1 0 0 1-1.414 0l-1.586-1.586a1 1 0 0 1 0-1.414l5.586-5.586a1 1 0 0 1 1.414 0l1.586 1.586a1 1 0 0 1 0 1.414z",key:"nt11vn"}],["path",{d:"m18 13-1.375-6.874a1 1 0 0 0-.746-.776L3.235 2.028a1 1 0 0 0-1.207 1.207L5.35 15.879a1 1 0 0 0 .776.746L13 18",key:"15qc1e"}],["path",{d:"m2.3 2.3 7.286 7.286",key:"1wuzzi"}],["circle",{cx:"11",cy:"11",r:"2",key:"xmgehs"}]])},42184:(a,b,c)=>{"use strict";c.d(b,{A:()=>d});let d=(0,c(15336).A)("workflow",[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]])},42202:(a,b,c)=>{"use strict";c.d(b,{Y_:()=>w});var d,e,f,g,h,i,j,k,l,m,n=c(15962),o=c(29415),p=c(13799),q=(a,b,c)=>{if(!b.has(a))throw TypeError("Cannot "+c)},r=(a,b,c)=>(q(a,b,"read from private field"),c?c.call(a):b.get(a)),s=(a,b,c)=>{if(b.has(a))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(a):b.set(a,c)},t=(a,b,c,d)=>(q(a,b,"write to private field"),d?d.call(a,c):b.set(a,c),c),u=class{constructor(a=[]){s(this,d,void 0),s(this,e,"ready"),s(this,f,void 0),s(this,g,new Set),s(this,h,new Set),s(this,i,new Set),this.pushMessage=a=>{t(this,d,r(this,d).concat(a)),r(this,j).call(this)},this.popMessage=()=>{t(this,d,r(this,d).slice(0,-1)),r(this,j).call(this)},this.replaceMessage=(a,b)=>{t(this,d,[...r(this,d).slice(0,a),this.snapshot(b),...r(this,d).slice(a+1)]),r(this,j).call(this)},this.snapshot=a=>structuredClone(a),this["~registerMessagesCallback"]=(a,b)=>{let c=b?function(a,b){return null!=b?p(a,b):a}(a,b):a;return r(this,g).add(c),()=>{r(this,g).delete(c)}},this["~registerStatusCallback"]=a=>(r(this,h).add(a),()=>{r(this,h).delete(a)}),this["~registerErrorCallback"]=a=>(r(this,i).add(a),()=>{r(this,i).delete(a)}),s(this,j,()=>{r(this,g).forEach(a=>a())}),s(this,k,()=>{r(this,h).forEach(a=>a())}),s(this,l,()=>{r(this,i).forEach(a=>a())}),t(this,d,a)}get status(){return r(this,e)}set status(a){t(this,e,a),r(this,k).call(this)}get error(){return r(this,f)}set error(a){t(this,f,a),r(this,l).call(this)}get messages(){return r(this,d)}set messages(a){t(this,d,[...a]),r(this,j).call(this)}};d=new WeakMap,e=new WeakMap,f=new WeakMap,g=new WeakMap,h=new WeakMap,i=new WeakMap,j=new WeakMap,k=new WeakMap,l=new WeakMap;var v=class extends o.vl{constructor({messages:a,...b}){let c=new u(a);super({...b,state:c}),s(this,m,void 0),this["~registerMessagesCallback"]=(a,b)=>r(this,m)["~registerMessagesCallback"](a,b),this["~registerStatusCallback"]=a=>r(this,m)["~registerStatusCallback"](a),this["~registerErrorCallback"]=a=>r(this,m)["~registerErrorCallback"](a),t(this,m,c)}};function w({experimental_throttle:a,resume:b=!1,...c}={}){let d=(0,n.useRef)("chat"in c?{}:{onToolCall:c.onToolCall,onData:c.onData,onFinish:c.onFinish,onError:c.onError,sendAutomaticallyWhen:c.sendAutomaticallyWhen});"chat"in c||(d.current={onToolCall:c.onToolCall,onData:c.onData,onFinish:c.onFinish,onError:c.onError,sendAutomaticallyWhen:c.sendAutomaticallyWhen});let e={...c,onToolCall:a=>{var b,c;return null==(c=(b=d.current).onToolCall)?void 0:c.call(b,a)},onData:a=>{var b,c;return null==(c=(b=d.current).onData)?void 0:c.call(b,a)},onFinish:a=>{var b,c;return null==(c=(b=d.current).onFinish)?void 0:c.call(b,a)},onError:a=>{var b,c;return null==(c=(b=d.current).onError)?void 0:c.call(b,a)},sendAutomaticallyWhen:a=>{var b,c,e;return null!=(e=null==(c=(b=d.current).sendAutomaticallyWhen)?void 0:c.call(b,a))&&e}},f=(0,n.useRef)("chat"in c?c.chat:new v(e));("chat"in c&&c.chat!==f.current||"id"in c&&f.current.id!==c.id)&&(f.current="chat"in c?c.chat:new v(e));let g=(0,n.useCallback)(b=>f.current["~registerMessagesCallback"](b,a),[a,f.current.id]),h=(0,n.useSyncExternalStore)(g,()=>f.current.messages,()=>f.current.messages),i=(0,n.useSyncExternalStore)(f.current["~registerStatusCallback"],()=>f.current.status,()=>f.current.status),j=(0,n.useSyncExternalStore)(f.current["~registerErrorCallback"],()=>f.current.error,()=>f.current.error),k=(0,n.useCallback)(a=>{"function"==typeof a&&(a=a(f.current.messages)),f.current.messages=a},[f]);return(0,n.useEffect)(()=>{b&&f.current.resumeStream()},[b,f]),{id:f.current.id,messages:h,setMessages:k,sendMessage:f.current.sendMessage,regenerate:f.current.regenerate,clearError:f.current.clearError,stop:f.current.stop,error:j,resumeStream:f.current.resumeStream,status:i,addToolResult:f.current.addToolOutput,addToolOutput:f.current.addToolOutput,addToolApprovalResponse:f.current.addToolApprovalResponse}}m=new WeakMap},42837:(a,b,c)=>{"use strict";c.d(b,{I:()=>w});var d=c(36927),e=c(15962),f=c(55132),g=c(90106),h=c(59448);let i=new Set(["jpg","jpeg","png","gif","webp","svg","bmp","avif","heic","heif","tiff","tif","ico"]),j=new Set(["mp4","webm","mov","avi","mkv"]),k=new Set(["pdf"]),l=new Set(["mp3","wav","ogg","m4a"]);function m(a){let b=(a.split(".").pop()??"").toLowerCase();return i.has(b)?"image":j.has(b)?"video":k.has(b)?"pdf":l.has(b)?"audio":null}function n(a){return a.startsWith("http://")||a.startsWith("https://")?a:`/api/workspace/raw-file?path=${encodeURIComponent(a)}`}let o=/(?:^|[\s"'(=])(((?:\/|\.\/)?[\w.\-/\\]+)\.(?:jpe?g|png|gif|webp|svg|bmp|avif|heic|heif|tiff?|ico|mp4|webm|mov|avi|mkv|mp3|wav|ogg|m4a|pdf))\b/i,p=["path","file","file_path","filePath","filename","url","src","name","target"];function q(a,b){if(a)for(let b of p){let c=a[b];if("string"==typeof c&&c.length>0)return c}if(b)for(let a of p){let c=b[a];if("string"==typeof c&&c.length>0&&r(c))return c}if(a){let b=s(a);if(b)return b}if(b?.text&&"string"==typeof b.text){let a=b.text.match(o);if(a)return a[1]}if(b){let a=s(b);if(a)return a}return null}function r(a){return a.length>2&&a.length<500&&/\.\w{1,5}$/.test(a)&&!a.includes(" ")}function s(a){for(let b of Object.values(a))if("string"==typeof b&&r(b))return b;return null}let t=/https?:\/\/[^\s"'<>,;)}\]]+/gi;function u(a){return`https://www.google.com/s2/favicons?sz=64&domain_url=${encodeURIComponent(a)}`}function v(a,b){let c=a.toLowerCase().replace(/[_-]/g,"");if(["websearch","search","googlesearch","bingsearch","browsersearch","tavily"].some(a=>c.includes(a)))return"search";if("browser"===c){let a="string"==typeof b?.action?b.action.toLowerCase():"";return"open"===a||"navigate"===a?"fetch":"screenshot"===a?"image":"generic"}return["fetchurl","fetch","browse","browseurl","webfetch"].some(a=>c.includes(a))?"fetch":["read","file","readfile","getfile"].some(a=>c.includes(a))?"read":["bash","shell","execute","exec","terminal","command","run"].some(a=>c.includes(a))?"exec":["write","create","edit","str_replace","save","patch"].some(a=>c.includes(a))?"write":["image","screenshot","photo","picture","dalle","generateimage"].some(a=>c.includes(a))?"image":"generic"}function w({parts:a,isStreaming:b}){let[c,h]=(0,e.useState)(!!b),i=a.some(a=>"reasoning"===a.kind&&a.isStreaming||"tool"===a.kind&&"running"===a.status);(0,e.useRef)(null);let[j,k]=(0,e.useState)(0),l=(0,e.useCallback)(a=>{if(a<60)return`${a}s`;let b=Math.floor(a/60),c=a%60;return c>0?`${b}m ${c}s`:`${b}m`},[]);(0,e.useRef)(!1);let n=a.filter(a=>"reasoning"===a.kind).map(a=>a.text).join(""),o=a.some(a=>"reasoning"===a.kind&&a.isStreaming),p=function(a){let b=[],c=0;for(;c<a.length;){let d=a[c],e=v(d.toolName,d.args),f=q(d.args,d.output),g=f?m(f):null;if("read"===e&&g&&f){let e=[{path:f,tool:d}],h=c+1;for(;h<a.length;){let b=a[h],c=v(b.toolName,b.args),d=q(b.args,b.output),f=d?m(d):null;if("read"===c&&f===g&&d)e.push({path:d,tool:b}),h++;else break}b.push({type:"media-group",mediaKind:g,items:e}),c=h}else if("fetch"===e){let e=[d],f=c+1;for(;f<a.length;){let b=a[f];if("fetch"===v(b.toolName,b.args))e.push(b),f++;else break}e.length>1?b.push({type:"fetch-group",items:e}):b.push({type:"tool",tool:d}),c=f}else b.push({type:"tool",tool:d}),c++}return b}(a.filter(a=>"tool"===a.kind)),r=i?j>0?`Thinking for ${l(j)}`:"Thinking...":j>0?`Thought for ${l(j)}`:"Thought";return(0,d.jsxs)("div",{className:"my-3",children:[(0,d.jsxs)("button",{type:"button",onClick:()=>h(a=>!a),className:"flex items-center gap-2 py-1 text-[13px] cursor-pointer group",style:{color:"var(--color-text-muted)"},children:[(0,d.jsx)(G,{className:"w-4 h-4 flex-shrink-0 opacity-60"}),(0,d.jsx)("span",{className:"font-medium",children:r}),(0,d.jsx)(H,{className:`w-3.5 h-3.5 ml-1 flex-shrink-0 transition-transform duration-200 ${c?"":"-rotate-90"}`})]}),(0,d.jsx)(f.N,{initial:!1,children:c&&(0,d.jsx)(g.P.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.3,ease:[.25,.1,.25,1]},className:"overflow-hidden",children:(0,d.jsxs)("div",{className:"relative pt-2 pb-1",children:[(0,d.jsx)("div",{className:"absolute w-px",style:{left:9,top:16,bottom:8,background:"var(--color-border)"}}),(0,d.jsxs)(f.N,{initial:!1,children:[n&&(0,d.jsxs)(g.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},className:"flex items-start gap-2.5 py-1.5",children:[(0,d.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 2a7 7 0 0 0-7 7c0 2.38 1.19 4.47 3 5.74V17a2 2 0 0 0 2 2h4a2 2 0 0 0 2-2v-2.26c1.81-1.27 3-3.36 3-5.74a7 7 0 0 0-7-7z"}),(0,d.jsx)("path",{d:"M10 21h4"})]})}),(0,d.jsx)("div",{className:"flex-1 min-w-0",children:(0,d.jsx)(x,{text:n,isStreaming:o})})]},"reasoning"),p.map((a,b)=>"media-group"===a.type?(0,d.jsx)(g.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,d.jsx)(z,{mediaKind:a.mediaKind,items:a.items})},`media-${b}`):"fetch-group"===a.type?(0,d.jsx)(g.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,d.jsx)(y,{items:a.items})},`fetch-${b}`):(0,d.jsx)(g.P.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.25,ease:"easeOut"},children:(0,d.jsx)(B,{...a.tool})},a.tool.toolCallId))]})]})},"content")})]})}function x({text:a,isStreaming:b}){return(0,d.jsx)("div",{className:"mb-2",children:(0,d.jsx)("div",{className:"text-[13px] whitespace-pre-wrap leading-relaxed",style:{color:"var(--color-text-muted)"},children:a})})}function y({items:a}){let b=a.some(a=>"running"===a.status),c=a.filter(a=>"done"===a.status).length;return(0,d.jsxs)("div",{className:"flex items-start gap-2.5 py-1.5",children:[(0,d.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:(0,d.jsx)("span",{className:b?"animate-pulse":"",children:(0,d.jsx)(D,{kind:"fetch"})})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"text-[13px] leading-snug mb-1.5 flex items-center justify-between",style:{color:b?"var(--color-text)":"var(--color-text-secondary)"},children:[(0,d.jsx)("span",{className:b?"animate-pulse":"",children:b?`Fetching ${a.length} sources...`:`Fetched ${a.length} sources`}),!b&&(0,d.jsxs)("span",{className:"text-[11px]",style:{color:"var(--color-text-muted)"},children:[c," ",1===c?"result":"results"]})]}),(0,d.jsx)("div",{className:"rounded-2xl overflow-hidden",style:{background:"var(--color-surface)",border:"1px solid var(--color-border)"},children:a.map(a=>{let{domain:b,url:c}=function(a,b){for(let b of["url","targetUrl","path","src"]){let c=a?.[b];if("string"==typeof c&&c.startsWith("http"))try{return{domain:new URL(c).hostname,url:c}}catch{}}for(let a of["url","finalUrl","targetUrl"]){let c=b?.[a];if("string"==typeof c&&c.startsWith("http"))try{return{domain:new URL(c).hostname,url:c}}catch{}}return{domain:null,url:null}}(a.args,a.output);return(0,d.jsxs)("a",{href:c??void 0,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2.5 px-3 py-2.5 text-[12px] no-underline",style:{color:"var(--color-text)",cursor:c?"pointer":"default"},onMouseEnter:a=>{a.currentTarget.style.background="var(--color-surface-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent"},onClick:c?void 0:a=>a.preventDefault(),children:[b?(0,d.jsx)("img",{src:u(b),alt:"",width:16,height:16,className:"rounded-sm flex-shrink-0",loading:"lazy"}):(0,d.jsx)("div",{className:"w-4 h-4 rounded-sm flex-shrink-0",style:{background:"var(--color-surface-hover)"}}),(0,d.jsx)("span",{className:"flex-1 min-w-0 truncate",style:{color:"var(--color-text)"},children:b?.replace(/^www\./,"")??c??"Fetching..."}),"running"===a.status?(0,d.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse flex-shrink-0",style:{background:"var(--color-accent)"}}):c?(0,d.jsx)("span",{className:"text-[11px] truncate max-w-[45%] text-right",style:{color:"var(--color-text-muted)"},title:c,children:c}):null]},a.toolCallId)})})]})]})}function z({mediaKind:a,items:b}){let[c,f]=(0,e.useState)(!1),g=b.some(a=>"running"===a.tool.status),h=b.filter(a=>"done"===a.tool.status),i=h.length,j=g?`Reading ${b.length} ${a}${b.length>1?"s":""}...`:"image"===a?1===b.length?"Read 1 image":`Read ${b.length} images`:"video"===a?1===b.length?"Read 1 video":`Read ${b.length} videos`:"pdf"===a?1===b.length?"Read 1 PDF":`Read ${b.length} PDFs`:1===b.length?"Read 1 audio file":`Read ${b.length} audio files`,k=c?h:h.slice(0,6),l=h.length>6&&!c;return(0,d.jsxs)("div",{className:"flex items-start gap-2.5 py-1.5",children:[(0,d.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:(0,d.jsx)("span",{className:g?"animate-pulse":"",children:(0,d.jsx)(D,{kind:"image"===a?"image":"read"})})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsx)("div",{className:`text-[13px] leading-snug mb-1.5${g?" animate-pulse":""}`,style:{color:g?"var(--color-text)":"var(--color-text-secondary)"},children:j}),i>0&&"image"===a&&(0,d.jsxs)("div",{className:"flex flex-wrap gap-1.5",children:[k.map(a=>(0,d.jsx)(A,{path:a.path,single:1===b.length},a.tool.toolCallId)),g&&(0,d.jsx)("div",{className:"flex items-center justify-center rounded-lg",style:{width:80,height:80,background:"var(--color-surface-hover)",border:"1px solid var(--color-border)"},children:(0,d.jsx)("span",{className:"animate-pulse",style:{color:"var(--color-text-muted)"},children:(0,d.jsx)(D,{kind:"image"})})}),l&&(0,d.jsxs)("button",{type:"button",onClick:()=>f(!0),className:"flex items-center justify-center rounded-lg text-xs font-medium cursor-pointer",style:{width:80,height:80,background:"var(--color-surface-hover)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:["+",h.length-6," ","more"]})]}),i>0&&"video"===a&&(0,d.jsx)("div",{className:"flex flex-wrap gap-2",children:k.map(a=>(0,d.jsx)("video",{src:n(a.path),controls:!0,preload:"metadata",className:"rounded-lg max-w-[240px] max-h-[160px]",style:{border:"1px solid var(--color-border)"}},a.tool.toolCallId))}),i>0&&"pdf"===a&&(0,d.jsx)("div",{className:"flex flex-col gap-1.5",children:k.map(a=>{let b=a.path.split("/").pop()??a.path;return(0,d.jsxs)("a",{href:n(a.path),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-3 py-2 rounded-lg text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,d.jsx)(F,{}),(0,d.jsx)("span",{className:"truncate max-w-[200px]",children:b})]},a.tool.toolCallId)})}),i>0&&"audio"===a&&(0,d.jsx)("div",{className:"flex flex-col gap-1.5",children:k.map(a=>(0,d.jsx)("audio",{src:n(a.path),controls:!0,preload:"metadata",className:"max-w-[280px] h-8"},a.tool.toolCallId))})]})]})}function A({path:a,single:b}){let[c,f]=(0,e.useState)(!1),g=a.split("/").pop()??a,h=n(a),i=b?200:80,j=b?150:80;return c?(0,d.jsx)("div",{className:"flex items-center justify-center rounded-lg text-[10px] text-center p-1",style:{width:i,height:j,background:"var(--color-surface-hover)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},title:a,children:(0,d.jsx)("span",{className:"truncate",children:g})}):(0,d.jsx)("a",{href:h,target:"_blank",rel:"noopener noreferrer",className:"block rounded-lg overflow-hidden flex-shrink-0",style:{border:"1px solid var(--color-border)",width:i,height:j},title:g,children:(0,d.jsx)("img",{src:h,alt:g,className:"w-full h-full object-cover",loading:"lazy",onError:()=>f(!0)})})}function B({toolName:a,status:b,args:c,output:f,errorText:g}){let i=v(a,c),[j,k]=(0,e.useState)("exec"===i||"generic"===i),[l,o]=(0,e.useState)(!0),p=function(a,b,c,d){let e=a=>{let b=c?.[a];return"string"==typeof b&&b.length>0?b:null};switch(a){case"search":{let a=e("query")??e("search_query")??e("search")??e("q");return a?`Searching for ${a}`:"Searching..."}case"fetch":{let a=e("url")??e("targetUrl")??e("path")??e("src");if(a)try{return`Fetching ${new URL(a).hostname}`}catch{return`Fetching ${a}`}let b="string"==typeof d?.finalUrl&&d.finalUrl||"string"==typeof d?.url&&d.url;if(b)try{return`Fetched ${new URL(b).hostname}`}catch{return`Fetched ${b}`}return"Fetching page"}case"read":{let a=q(c,d);if(a){let b=a.split("/").pop()??a;return b.startsWith("http")?`Fetching ${b}`:`Reading ${b}`}return"Reading file"}case"exec":{let a=e("command")??e("cmd");if(a)return`Running: ${a}`;return"Running command"}case"write":{let a=e("path")??e("file")??e("file_path");if(a){let b=a.split("/").pop()??a;return`Editing ${b}`}return"Editing file"}case"image":return e("description")?`Generating image: ${e("description")}`:"Generating image";default:{let a=b.replace(/_/g," ").replace(/\b\w/g,a=>a.toUpperCase()).trim();if(c){let b=e("command")??e("cmd")??e("query")??e("path")??e("url")??e("message")??e("description")??e("input")??e("text");if(b)return`${a}: ${b}`}return a||"Tool"}}}(i,a,c,f),r="search"===i?function(a){if(!a)return[];let b="string"==typeof a.text?a.text:"",c=a.results,d=a.citations,e=b;if(Array.isArray(c))for(let a of c)"string"==typeof a?e+=` ${a}`:"object"==typeof a&&null!==a&&("string"==typeof a.url&&(e+=` ${a.url}`),"string"==typeof a.link&&(e+=` ${a.link}`));if(Array.isArray(d))for(let a of d)"string"==typeof a?e+=` ${a}`:"object"==typeof a&&null!==a&&"string"==typeof a.url&&(e+=` ${a.url}`);for(let c of Object.values(a))"string"==typeof c&&c!==b&&c.includes("http")&&(e+=` ${c}`);let f=e.match(t)??[],g=new Set;for(let a of f)try{let b=new URL(a).hostname;b&&!b.includes("localhost")&&g.add(b)}catch{}return[...g].slice(0,8)}(f):"fetch"===i?function(a,b){let c=new Set;for(let b of["url","targetUrl","path","src"]){let d=a?.[b];if("string"==typeof d&&d.startsWith("http"))try{let a=new URL(d).hostname;a&&!a.includes("localhost")&&c.add(a)}catch{}}for(let a of["url","finalUrl","targetUrl"]){let d=b?.[a];if("string"==typeof d&&d.startsWith("http"))try{let a=new URL(d).hostname;a&&!a.includes("localhost")&&c.add(a)}catch{}}return[...c].slice(0,4)}(c,f):[],s="string"==typeof f?.text?f.text:void 0,w=(()=>{if("write"!==i||"done"!==b)return;if("string"==typeof f?.diff)return f.diff;let a="string"==typeof c?.old_string?c.old_string:"string"==typeof c?.oldText?c.oldText:null,d="string"==typeof c?.new_string?c.new_string:"string"==typeof c?.newText?c.newText:null;if(null!==a&&null!==d){var e="string"==typeof c?.path?c.path:"string"==typeof c?.file_path?c.file_path:"file";let b=a.split("\n"),f=d.split("\n"),g=[`--- a/${e}`,`+++ b/${e}`,`@@ -1,${b.length} +1,${f.length} @@`];for(let a of b)g.push(`-${a}`);for(let a of f)g.push(`+${a}`);return g.join("\n")}})(),x=q(c,f),y=x?m(x):null,z="read"===i&&y&&"done"===b;return(0,d.jsxs)("div",{className:"flex items-start gap-2.5 py-1.5",children:[(0,d.jsx)("div",{className:"relative z-10 flex-shrink-0 w-[18px] h-[18px] flex items-center justify-center rounded-full",style:{background:"var(--color-bg)"},children:"error"===b?(0,d.jsx)(E,{}):(0,d.jsx)("span",{className:"running"===b?"animate-pulse":"",children:(0,d.jsx)(D,{kind:i})})}),(0,d.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,d.jsxs)("div",{className:"text-[13px] leading-snug flex items-center gap-2 flex-wrap",style:{color:"running"===b?"var(--color-text)":"var(--color-text-secondary)"},children:[(0,d.jsx)("span",{className:`break-all${"running"===b?" animate-pulse":""}`,children:p}),"exec"===i&&"done"===b&&f?.exitCode!==void 0&&(0,d.jsxs)("span",{className:"text-[11px] font-mono px-1.5 py-0.5 rounded",style:{background:0===f.exitCode?"color-mix(in srgb, var(--color-success, #22c55e) 12%, transparent)":"color-mix(in srgb, var(--color-error) 12%, transparent)",color:0===f.exitCode?"var(--color-success, #22c55e)":"var(--color-error)"},children:["exit ","object"==typeof f.exitCode&&null!=f.exitCode?JSON.stringify(f.exitCode):"number"==typeof f.exitCode?String(f.exitCode):"string"==typeof f.exitCode?f.exitCode:""]})]}),w&&"done"===b&&(0,d.jsxs)("div",{className:"mt-1.5",children:[(0,d.jsx)("button",{type:"button",onClick:()=>o(a=>!a),className:"text-[11px] hover:underline cursor-pointer mb-1",style:{color:"var(--color-accent)"},children:l?"Hide changes":"Show changes"}),l&&(0,d.jsx)(h.a,{diff:w})]}),z&&x&&"image"===y&&(0,d.jsx)("div",{className:"mt-1.5",children:(0,d.jsx)(A,{path:x,single:!0})}),z&&x&&"video"===y&&(0,d.jsx)("video",{src:n(x),controls:!0,preload:"metadata",className:"mt-1.5 rounded-lg max-w-[240px] max-h-[160px]",style:{border:"1px solid var(--color-border)"}}),z&&x&&"pdf"===y&&(0,d.jsxs)("a",{href:n(x),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 mt-1.5 px-3 py-2 rounded-lg text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,d.jsx)(F,{}),(0,d.jsx)("span",{className:"truncate max-w-[200px]",children:x.split("/").pop()??x})]}),z&&x&&"audio"===y&&(0,d.jsx)("audio",{src:n(x),controls:!0,preload:"metadata",className:"mt-1.5 max-w-[280px] h-8"}),r.length>0&&"running"!==b&&(0,d.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-1.5",children:r.map(a=>(0,d.jsx)(C,{domain:a},a))}),("search"===i||"fetch"===i)&&"running"===b&&c&&(0,d.jsx)("div",{className:"flex items-center gap-1.5 flex-wrap mt-1.5",children:r.length>0?r.map(a=>(0,d.jsxs)("span",{className:"inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,d.jsx)("img",{src:u(a),alt:"",width:14,height:14,className:"rounded-sm flex-shrink-0",loading:"lazy"}),a.replace(/^www\./,""),(0,d.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse",style:{background:"var(--color-accent)"}})]},a)):(0,d.jsxs)("span",{className:"inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-muted)",border:"1px solid var(--color-border)"},children:[(0,d.jsx)("span",{className:"w-2 h-2 rounded-full animate-pulse",style:{background:"var(--color-accent)"}}),"fetch"===i?"Fetching...":"Searching..."]})}),"error"===b&&g&&(0,d.jsx)("div",{className:"mt-1.5 text-[12px] font-mono rounded-lg px-2.5 py-1.5",style:{color:"var(--color-error)",background:"color-mix(in srgb, var(--color-error) 6%, var(--color-surface))"},children:g}),!s&&!w&&!z&&"done"===b&&c&&Object.keys(c).length>0&&(0,d.jsx)("pre",{className:"mt-1 text-[11px] font-mono rounded-lg px-2.5 py-1.5 whitespace-pre-wrap break-all max-h-48 overflow-y-auto leading-relaxed",style:{color:"var(--color-text-muted)",background:"var(--color-bg)"},children:function(a){let b=[];for(let[c,d]of Object.entries(a)){if(null==d)continue;let a="string"==typeof d?d:JSON.stringify(d,null,2);b.push(`${c}: ${a}`)}let c=b.join("\n");return c.length>2e3?c.slice(0,2e3)+"\n...":c}(c)}),s&&!z&&!w&&(0,d.jsxs)("div",{className:"mt-1",children:["done"===b&&(0,d.jsx)("button",{type:"button",onClick:()=>k(a=>!a),className:"text-[11px] hover:underline cursor-pointer",style:{color:"var(--color-accent)"},children:j?"Hide output":"Show output"}),(j||"running"===b)&&(0,d.jsx)("pre",{className:"mt-1 text-[11px] font-mono rounded-lg px-2.5 py-2 overflow-x-auto whitespace-pre-wrap break-all max-h-96 overflow-y-auto leading-relaxed",style:{color:"var(--color-text-muted)",background:"var(--color-bg)"},children:s.length>1e4?s.slice(0,1e4)+"\n... (truncated)":s})]})]})]})}function C({domain:a}){let b=a.replace(/^www\./,"");return(0,d.jsxs)("span",{className:"inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full text-[12px]",style:{background:"var(--color-surface-hover)",color:"var(--color-text-secondary)",border:"1px solid var(--color-border)"},children:[(0,d.jsx)("img",{src:u(a),alt:"",width:16,height:16,className:"rounded-sm flex-shrink-0",loading:"lazy"}),b]})}function D({kind:a}){let b="var(--color-text-muted)";switch(a){case"search":return(0,d.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,d.jsx)("path",{d:"m21 21-4.3-4.3"})]});case"fetch":return(0,d.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,d.jsx)("path",{d:"M2 12h20"}),(0,d.jsx)("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]});case"read":return(0,d.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,d.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]});case"exec":return(0,d.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,d.jsx)("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]});case"write":return(0,d.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),(0,d.jsx)("path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"})]});case"image":return(0,d.jsxs)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),(0,d.jsx)("circle",{cx:"9",cy:"9",r:"2"}),(0,d.jsx)("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]});default:return(0,d.jsx)("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:b,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("circle",{cx:"12",cy:"12",r:"1"})})}}function E(){return(0,d.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-error)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,d.jsx)("line",{x1:"15",x2:"9",y1:"9",y2:"15"}),(0,d.jsx)("line",{x1:"9",x2:"15",y1:"9",y2:"15"})]})}function F(){return(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),(0,d.jsx)("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}),(0,d.jsx)("path",{d:"M10 9H8"}),(0,d.jsx)("path",{d:"M16 13H8"}),(0,d.jsx)("path",{d:"M16 17H8"})]})}function G({className:a}){return(0,d.jsxs)("svg",{className:a,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 2a7 7 0 0 0-7 7c0 2.38 1.19 4.47 3 5.74V17a2 2 0 0 0 2 2h4a2 2 0 0 0 2-2v-2.26c1.81-1.27 3-3.36 3-5.74a7 7 0 0 0-7-7z"}),(0,d.jsx)("path",{d:"M10 21h4"}),(0,d.jsx)("path",{d:"M9 9.4a3 3 0 0 1 5.1-2"})]})}function H({className:a}){return(0,d.jsx)("svg",{className:a,viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M3 4.5L6 7.5L9 4.5"})})}},42967:(a,b,c)=>{"use strict";c.d(b,{S:()=>ae});var d=c(36927),e=c(15962),f=c(81918),g=c(49855);function h(){return(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.5},children:[(0,d.jsx)("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),(0,d.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function i({x:a,y:b,target:c,onAction:f,onClose:i}){let j=(0,e.useRef)(null),k=function(a){let b="empty"!==a.kind&&a.isSystem;return"file"===a.kind?[{action:"open",label:"Open"},{separator:!0},{action:"rename",label:"Rename",shortcut:"Enter",disabled:b},{action:"duplicate",label:"Duplicate",shortcut:"⌘D",disabled:b},{action:"copy",label:"Copy Path",shortcut:"⌘C"},{separator:!0},{action:"getInfo",label:"Get Info",shortcut:"⌘I"},{separator:!0},{action:"delete",label:"Move to Trash",shortcut:"⌘⌫",disabled:b,danger:!0}]:"folder"===a.kind?[{action:"open",label:"Open"},{separator:!0},{action:"newFile",label:"New File",shortcut:"⌘N",disabled:b},{action:"newFolder",label:"New Folder",shortcut:"⇧⌘N",disabled:b},{separator:!0},{action:"rename",label:"Rename",shortcut:"Enter",disabled:b},{action:"duplicate",label:"Duplicate",shortcut:"⌘D",disabled:b},{action:"copy",label:"Copy Path",shortcut:"⌘C"},{separator:!0},{action:"getInfo",label:"Get Info",shortcut:"⌘I"},{separator:!0},{action:"delete",label:"Move to Trash",shortcut:"⌘⌫",disabled:b,danger:!0}]:[{action:"newFile",label:"New File",shortcut:"⌘N"},{action:"newFolder",label:"New Folder",shortcut:"⇧⌘N"},{separator:!0},{action:"paste",label:"Paste",shortcut:"⌘V",disabled:!0}]}(c),l="empty"!==c.kind&&c.isSystem;(0,e.useRef)({x:a,y:b});let m=(0,e.useCallback)((a,b)=>{b||(f(a),i())},[f,i]);return(0,g.createPortal)((0,d.jsxs)("div",{ref:j,className:"fixed z-[9999] min-w-[200px] py-1 rounded-lg shadow-xl border",style:{left:a,top:b,background:"var(--color-surface)",borderColor:"var(--color-border)",backdropFilter:"blur(20px)",WebkitBackdropFilter:"blur(20px)",animation:"contextMenuFadeIn 100ms ease-out"},role:"menu",children:[l&&(0,d.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 text-[11px]",style:{color:"var(--color-text-muted)"},children:[(0,d.jsx)(h,{}),(0,d.jsx)("span",{children:"System file (locked)"})]}),k.map((a,b)=>{if("separator"in a&&a.separator)return(0,d.jsx)("div",{className:"my-1 mx-2 border-t",style:{borderColor:"var(--color-border)"}},`sep-${b}`);let c=a.disabled;return(0,d.jsxs)("button",{type:"button",role:"menuitem",disabled:c,className:"w-full flex items-center gap-2 px-3 py-1.5 text-[13px] text-left transition-colors",style:{color:c?"var(--color-text-muted)":a.danger?"#ef4444":"var(--color-text)",opacity:c?.5:1,cursor:c?"default":"pointer"},onMouseEnter:b=>{c||(b.currentTarget.style.background=a.danger?"rgba(239, 68, 68, 0.1)":"var(--color-surface-hover)")},onMouseLeave:a=>{a.currentTarget.style.background="transparent"},onClick:()=>m(a.action,c),children:[a.icon,(0,d.jsx)("span",{className:"flex-1",children:a.label}),c&&l&&(0,d.jsx)(h,{}),a.shortcut&&(0,d.jsx)("span",{className:"text-[11px] ml-4",style:{color:"var(--color-text-muted)"},children:a.shortcut})]},a.action)}),(0,d.jsx)("style",{children:`
140
140
  @keyframes contextMenuFadeIn {
141
141
  from { opacity: 0; transform: scale(0.96); }
142
142
  to { opacity: 1; transform: scale(1); }