larkup 0.1.30 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -1
- package/.next/build-manifest.json +3 -3
- package/.next/diagnostics/route-bundle-stats.json +2 -2
- package/.next/fallback-build-manifest.json +3 -3
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/analytics.html +1 -1
- package/.next/server/app/analytics.rsc +1 -1
- package/.next/server/app/analytics.segments/_full.segment.rsc +1 -1
- package/.next/server/app/analytics.segments/_head.segment.rsc +1 -1
- package/.next/server/app/analytics.segments/_index.segment.rsc +1 -1
- package/.next/server/app/analytics.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/analytics.segments/analytics/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/analytics.segments/analytics.segment.rsc +1 -1
- package/.next/server/app/chat.html +1 -1
- package/.next/server/app/chat.rsc +1 -1
- package/.next/server/app/chat.segments/_full.segment.rsc +1 -1
- package/.next/server/app/chat.segments/_head.segment.rsc +1 -1
- package/.next/server/app/chat.segments/_index.segment.rsc +1 -1
- package/.next/server/app/chat.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/chat.segments/chat/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/chat.segments/chat.segment.rsc +1 -1
- package/.next/server/app/data/page_client-reference-manifest.js +1 -1
- package/.next/server/app/data.html +1 -1
- package/.next/server/app/data.rsc +2 -2
- package/.next/server/app/data.segments/_full.segment.rsc +2 -2
- package/.next/server/app/data.segments/_head.segment.rsc +1 -1
- package/.next/server/app/data.segments/_index.segment.rsc +1 -1
- package/.next/server/app/data.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/data.segments/data/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/data.segments/data.segment.rsc +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +1 -1
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/settings.html +1 -1
- package/.next/server/app/settings.rsc +1 -1
- package/.next/server/app/settings.segments/_full.segment.rsc +1 -1
- package/.next/server/app/settings.segments/_head.segment.rsc +1 -1
- package/.next/server/app/settings.segments/_index.segment.rsc +1 -1
- package/.next/server/app/settings.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/settings.segments/settings/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/settings.segments/settings.segment.rsc +1 -1
- package/.next/server/chunks/0598_next_dist_esm_build_templates_app-route_0kbcuk-.js +16 -3
- package/.next/server/chunks/[root-of-the-server]__01al2n0._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__1ahdfq9._.js +3 -3
- package/.next/server/chunks/packages_core_src_generator_generate-server_ts_11-w3m3._.js +2 -2
- package/.next/server/chunks/packages_marketplace_src_125_g2p._.js +1 -1
- package/.next/server/chunks/ssr/_169pdlf._.js +1 -1
- package/.next/server/chunks/ssr/packages_core_src_generator_generate-server_ts_15zzrn2._.js +2 -2
- package/.next/server/middleware-build-manifest.js +3 -3
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/static/chunks/{1uzf7x2okeuab.js → 0ff5osu771ajz.js} +1 -1
- package/CHANGELOG.md +21 -0
- package/app/api/chat/route.ts +13 -1
- package/app/api/chat/tools.ts +2 -2
- package/app/api/firecrawl/local/route.ts +6 -3
- package/components/data/firecrawl-notice.tsx +1 -9
- package/next-env.d.ts +1 -1
- package/package.json +8 -8
- /package/.next/static/{Laf7YhpONHOZXSCw6POiL → kaW1RhJBmrNB5F_JAJ6QO}/_buildManifest.js +0 -0
- /package/.next/static/{Laf7YhpONHOZXSCw6POiL → kaW1RhJBmrNB5F_JAJ6QO}/_clientMiddlewareManifest.js +0 -0
- /package/.next/static/{Laf7YhpONHOZXSCw6POiL → kaW1RhJBmrNB5F_JAJ6QO}/_ssgManifest.js +0 -0
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
module.exports=[400660,e=>{"use strict";var t=e.i(239441),a=e.i(449055),r=e.i(391328),s=e.i(6352),i=e.i(746789),n=e.i(423437),o=e.i(178820),l=e.i(569191),c=e.i(576251),d=e.i(199962),u=e.i(547545),m=e.i(664046),p=e.i(235691),h=e.i(298907),f=e.i(110763),g=e.i(193695);e.i(673243);var y=e.i(236167),b=e.i(214312),w=e.i(367165),x=e.i(844915),v=e.i(336321),S=e.i(608778),T=e.i(416487),A=e.i(733164),C=e.i(731699),z=e.i(235072),I=e.i(528909),R=e.i(89087),N=e.i(344963),k=e.i(256485),E=e.i(638725),M=e.i(313893),D=e.i(868776),O=e.i(489694),q=e.i(432970),P=e.i(585071),j=e.i(523554),$=e.i(192441),U=e.i(705252);function _(e,t){return t?e.filter(e=>{if(t.source&&e.source!==t.source||t.status&&e.status!==t.status)return!1;if(t.titleContains){let a=t.titleContains.toLowerCase();if(!e.title.toLowerCase().includes(a))return!1}return(!t.createdAfter||!(e.createdAt<t.createdAfter))&&(!t.createdBefore||!(e.createdAt>t.createdBefore))&&(!t.metadataKey||!!e.metadata&&t.metadataKey in e.metadata&&(void 0===t.metadataValue||String(e.metadata[t.metadataKey])===t.metadataValue))&&!0}):e}async function F(e,t=200,a=0,r=!1){let s=_(await (0,U.readDocuments)(),e),i=s.length;return{documents:s.slice(a,a+t).map(e=>{let t={id:e.id,title:e.title,source:e.source,url:e.url,charCount:e.charCount,status:e.status,metadata:e.metadata,createdAt:e.createdAt};return r&&(t.content=e.content.slice(0,2e3)),t}),total:i,summary:function(e){let t={},a={},r={},s=0,i="",n="";for(let o of e){t[o.source]=(t[o.source]??0)+1;let e=o.status??"unindexed";if(a[e]=(a[e]??0)+1,s+=o.charCount,(!i||o.createdAt<i)&&(i=o.createdAt),(!n||o.createdAt>n)&&(n=o.createdAt),o.metadata)for(let e of Object.keys(o.metadata))e.startsWith("_")||(r[e]=(r[e]??0)+1)}let o=Object.entries(r).sort((e,t)=>t[1]-e[1]).slice(0,20).map(([e,t])=>({key:e,count:t}));return{totalDocuments:e.length,bySource:t,byStatus:a,topMetadataKeys:o,totalCharacters:s,dateRange:i?{earliest:i,latest:n}:null}}(s)}}async function L(e,t=1e3){let a=_(await (0,U.readDocuments)(),e);if(0===a.length)return"";let r=new Set;for(let e of a)if(e.metadata)for(let t of Object.keys(e.metadata))t.startsWith("_")||r.add(t);let s=[...r].sort(),i=["id","title","source","url","charCount","status","createdAt","content",...s.map(e=>`metadata_${e}`)],n=e=>e.includes(",")||e.includes('"')||e.includes("\n")?`"${e.replace(/"/g,'""')}"`:e,o=[i.join(",")];for(let e of a){let a=[e.id,e.title,e.source,e.url??"",String(e.charCount),e.status??"unindexed",e.createdAt,e.content.slice(0,t).replace(/\n/g," ")],r=s.map(t=>{let a=e.metadata?.[t];return null==a?"":"object"==typeof a?JSON.stringify(a):String(a)});o.push([...a,...r].map(n).join(","))}return o.join("\n")}async function K(e,t=1e3){return _(await (0,U.readDocuments)(),e).map(e=>{let a={id:e.id,title:e.title,source:e.source,url:e.url??"",charCount:e.charCount,status:e.status??"unindexed",createdAt:e.createdAt,content:e.content.slice(0,t)};if(e.metadata)for(let[t,r]of Object.entries(e.metadata))t.startsWith("_")||(a[`metadata_${t}`]=r);return JSON.stringify(a)}).join("\n")}e.i(983131);var B=e.i(778923);e.i(907667);var W=e.i(490517),H=e.i(504740),V=e.i(463857),Y=e.i(839554),G=e.i(534404);function J({output:e}){return{type:"json",value:e?.success?{success:!0,action:e.action,sessionId:e.sessionId,updatedFields:e.updatedFields??[],fileName:e.fileName,totalPages:e.totalPages,message:"The document was updated successfully. Do not repeat the edit unless requested."}:{success:!1,error:e?.error??"Document update failed"}}}async function Q(t,a,r){let s=async()=>{let s=await (0,w.readConfig)(),i=Math.max(4*a,20),n=await (0,q.refreshServerStatus)();if(n.running)try{let s=Date.now(),o=await fetch(`${n.endpoint}/query`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,topK:i}),signal:AbortSignal.timeout(15e3)}),l=await o.json(),{trackUsageEvent:c}=await e.A(313282);if(c({type:"server_request",endpoint:"/query",method:"POST",statusCode:o.status,latencyMs:Date.now()-s,serverId:r??void 0,timestamp:new Date().toISOString()}),o.ok&&Array.isArray(l.hits)&&l.hits.length>0)return X(t,l.hits,a)}catch{}let o=await (0,O.readRun)();if(!o||"completed"!==o.status||(o.totalChunks??0)===0)return{query:t,hits:[]};let l=await (0,j.embedQuery)(s,t),c=await (0,P.createAdapter)(s),d=await c.query(l,i,t);return X(t,d,a)};return r?(0,$.runWithServer)(r,s):s()}async function X(e,t,a){var r;let[s,i]=await Promise.all([(0,U.readDocuments)(),(0,Y.readMediaAssets)()]),n=new Map(s.map(e=>[e.id,e])),o=new Set(i.flatMap(e=>e.documentIds)),l=t.map(e=>{let t=n.get(e.documentId);return{...e,title:e.title||t?.title||"Untitled",url:e.url||t?.url||"",text:e.text||t?.content||"",metadata:{...t?.metadata,...e.metadata}}}),c=[],d=new Map;for(let e of l){if(e.metadata?.mediaAssetId&&(!n.has(e.documentId)||!o.has(e.documentId)))continue;let t=d.get(e.documentId)??0;if(!(t>=(e.metadata?.isMediaSummary===!0||e.metadata?.contentKind==="multimodal-segment"||e.metadata?.contentKind==="audio-transcript-segment"?1:3))&&(c.push(e),d.set(e.documentId,t+1),c.length>=a))break}let u=c.find(e=>e.metadata?.mediaAssetId)?.metadata.mediaAssetId,m=u?s.filter(e=>"indexed"===e.status&&e.metadata?.mediaAssetId===u&&o.has(e.id)):[],p=m.filter(e=>Number.isFinite(Number(e.metadata?.endSecs))).sort((e,t)=>Number(e.metadata?.endSecs??0)-Number(t.metadata?.endSecs??0)),h=Math.max(0,...p.map(e=>Number(e.metadata?.durationSecs??e.metadata?.endSecs??0))),f=Math.max(600,Math.min(1800,.2*h)),g=p.filter(e=>Number(e.metadata?.endSecs??0)>=h-f),y=[...new Map([...(r=e,/\b(who won|winner|won|final score|scoreline|result|beat|defeated|victor|champion|took (?:the )?(?:game|match|round))\b|من فاز|مين فاز|الفائز|النتيجة|نتيجة|فاز|كسب|البطل|حسم|انتصر/i.test(r))?g.filter(e=>{var t;return t=e.content,/\b(winner|won|final score|total score|scoreline|champion|victor|defeated|beat)\b|الفائز|النتيجة|فاز|كسب|البطل|حسم|انتصر/i.test(t)}).slice(-2):[],...g.slice(-4)].map(e=>[e.id,e])).values()].sort((e,t)=>Number(e.metadata?.endSecs??0)-Number(t.metadata?.endSecs??0)),b=m.find(e=>e.metadata?.isMediaSummary===!0),w=0===y.length?m.find(e=>e.metadata?.contentKind==="multimodal-timeline"):void 0,x=u?[...b?[{role:"summary",title:b.title,url:b.url,text:(0,G.queryAwareExcerpt)(b.content,e,6e3),startSecs:void 0,endSecs:void 0}]:[],...y.map(t=>({role:"ending",title:t.title,url:t.url,text:(0,G.queryAwareExcerpt)(t.content,e,3200,!0),startSecs:t.metadata?.startSecs,endSecs:t.metadata?.endSecs})),...w?[{role:"ending",title:w.title,url:w.url,text:(0,G.queryAwareExcerpt)(w.content,e,4e3,!0),startSecs:void 0,endSecs:w.metadata?.durationSecs}]:[]]:void 0;return{query:e,hits:c.map((t,a)=>{let r=Number(t.metadata?.sequence),i=Number(t.metadata?.startSecs),n=t.metadata?.mediaAssetId?s.filter(e=>{let a=Number(e.metadata?.sequence),s=Number(e.metadata?.startSecs);return"indexed"===e.status&&o.has(e.id)&&e.metadata?.mediaAssetId===t.metadata.mediaAssetId&&Number.isFinite(r)&&Number.isFinite(a)&&1>=Math.abs(a-r)&&(!Number.isFinite(i)||!Number.isFinite(s)||Math.abs(s-i)<=Math.max(90,Number(t.metadata?.endSecs??i)-i,Number(e.metadata?.endSecs??s)-s))}).sort((e,t)=>Number(e.metadata?.startSecs??0)-Number(t.metadata?.startSecs??0)).map(t=>({role:Number(t.metadata?.sequence)<r?"before":Number(t.metadata?.sequence)>r?"after":"matched",title:t.title,url:t.url,text:(0,G.queryAwareExcerpt)(t.content,e,3200),startSecs:t.metadata?.startSecs,endSecs:t.metadata?.endSecs})):void 0;return{documentId:t.documentId,title:t.title??"Untitled",url:t.url??"",score:Number((t.score??0).toFixed(3)),text:(0,G.queryAwareExcerpt)(t.text??"",e,4e3),metadata:t.metadata,timelineContext:n,endingContext:0===a?x:void 0}})}}async function Z(t){let{serverId:a,docSessionId:r,config:s}=t,i={searchKnowledgeBase:(0,M.tool)({description:"Search the user's private RAG knowledge base when their question depends on indexed documents or media and the needed evidence is not already in the conversation. Do not use for general knowledge, casual conversation, writing tasks, or a follow-up that can be answered from an earlier search result. Search once with a focused query. For media, inspect the returned timeline and endingContext when relevant, and reuse exact mediaAssetId/startSecs/endSecs values with presentMedia when a preview is useful. Never guess timestamps.",inputSchema:D.z.object({query:D.z.string().describe("The search query for the knowledge base.")}),execute:async({query:e})=>Q(e,5,a??null)}),presentMedia:(0,M.tool)({description:"Embed one indexed image, video segment, or audio segment as a compact citation in the chat. Use the exact mediaAssetId and timestamps from a current or earlier search result. Call this when the user asks to see, watch, play, or hear the media, or when one preview materially supports the answer. Prefer one best citation and do not call this for every search hit. Do not search again if the needed asset ID is already in the conversation.",inputSchema:D.z.object({assetId:D.z.string().describe("Exact mediaAssetId returned by searchKnowledgeBase."),startSecs:D.z.number().nonnegative().optional().describe("Exact segment start time returned by searchKnowledgeBase."),endSecs:D.z.number().nonnegative().optional().describe("Exact segment end time returned by searchKnowledgeBase.")}),execute:async({assetId:e,startSecs:t,endSecs:r})=>{let s=async()=>{let s=(await (0,Y.readMediaAssets)()).find(t=>t.id===e);if(!s||"completed"!==s.processingStatus)return{success:!1,error:"That indexed media asset is no longer available."};let i=(0,G.normalizeMediaCitationRange)(s.type,s.durationSecs,t,r),n=a?`?serverId=${encodeURIComponent(a)}`:"",o=`/api/media/${s.id}${n}`,l=void 0!==i.startSecs?(0,G.timestampMediaUrl)(s.originalUrl||o,i.startSecs):s.originalUrl||o;return{success:!0,assetId:s.id,mediaType:s.type,fileName:s.fileName,mediaUrl:o,sourceUrl:l,startSecs:i.startSecs,endSecs:i.endSecs}};return a?(0,$.runWithServer)(a,s):s()}}),queryTabularData:(0,M.tool)({description:"Query a tabular dataset (CSV/Excel/JSON) for exact values, filtering, grouping, and aggregations. Use this when the user asks about specific data values, comparisons, averages, sums, counts, highest/lowest, or any numerical question about uploaded data.",inputSchema:D.z.object({datasetId:D.z.string().describe("The ID of the dataset to query. Get this from the available datasets list in the system prompt."),filters:D.z.array(D.z.object({column:D.z.string(),op:D.z.enum(["eq","neq","gt","gte","lt","lte","contains","in"]),value:D.z.any()})).optional().describe("Filters to apply to the data."),groupBy:D.z.array(D.z.string()).optional().describe("Columns to group by for aggregations."),aggregations:D.z.array(D.z.object({column:D.z.string(),op:D.z.enum(["sum","avg","count","min","max","median"])})).optional().describe("Aggregation operations to perform."),sortBy:D.z.string().optional().describe("Column to sort results by."),sortOrder:D.z.enum(["asc","desc"]).optional().describe("Sort direction."),limit:D.z.number().optional().describe("Max number of rows to return."),columns:D.z.array(D.z.string()).optional().describe("Specific columns to include in results.")}),execute:async e=>{try{return await (0,S.queryTabular)(e)}catch(e){return{columns:[],rows:[],totalRows:0,error:e.message??"Query failed"}}}}),generateVisualization:(0,M.tool)({description:"Generate an interactive chart visualization. Use this when the user asks to see trends, comparisons, distributions, or any visual representation of data. The UI will render this as an interactive Recharts chart.",inputSchema:D.z.object({chartType:D.z.enum(["bar","area","line","pie","scatter","radar"]).describe("The type of chart to create."),title:D.z.string().describe("Chart title."),subtitle:D.z.string().optional().describe("Chart subtitle for additional context."),data:D.z.array(D.z.record(D.z.string(),D.z.any())).describe("Array of data points to plot. You MUST provide the data here. Example: [{'name': 'North', 'value': 3206}, {'name': 'East', 'value': 2492}]"),xAxisKey:D.z.string().describe("The key in data objects to use for the X axis (usually 'name')."),series:D.z.array(D.z.object({dataKey:D.z.string().describe("The key in data objects for this series values."),label:D.z.string().optional().describe("Display label for this series in the legend."),color:D.z.string().optional().describe("Color for this series (hex). If omitted, theme colors are used.")})).describe("Data series to plot."),stacked:D.z.boolean().optional().describe("Whether to stack bar/area charts."),showLegend:D.z.boolean().optional().default(!0).describe("Whether to show the legend."),xAxisLabel:D.z.string().optional().describe("Label for the X axis."),yAxisLabel:D.z.string().optional().describe("Label for the Y axis.")}),execute:async e=>e}),executeAnalysis:(0,M.tool)({description:"Execute Python code in a secure sandbox for deep data analysis. Use this for complex statistical computations (correlations, regressions, clustering), data transformations, or when creating custom matplotlib visualizations. The code has access to pandas, numpy, matplotlib, scipy, scikit-learn, and seaborn. Always print results to stdout and use plt.show() for charts.",inputSchema:D.z.object({code:D.z.string().describe('Python code to execute. Has pandas (2.0+), numpy, matplotlib, scipy, sklearn, seaborn available. ALWAYS use "ME" instead of "M" for resample frequency. Print results and use plt.show() for charts.'),datasetId:D.z.string().optional().describe("If provided, the dataset CSV will be available as 'data.csv' in the working directory.")}),execute:async({code:e,datasetId:t})=>{try{let a=new B.SandboxManager({backend:"docker"}),r=[];if(t){let e=await (0,S.getTabularDataset)(t);if(e&&e.rows.length>0){let t=e.columns.map(e=>e.name),a=[t.join(",")];for(let r of e.rows)a.push(t.map(e=>{let t=r[e],a=String(t??"");return a.includes(",")||a.includes('"')?`"${a.replace(/"/g,'""')}"`:a}).join(","));r.push({name:"data.csv",content:a.join("\n")})}}let s=e,i=await a.execute({code:s,language:"python",files:r,timeout:3e4});return 0!==i.exitCode&&(s=(s=(s=(s=s.replace(/resample\((['"])M(['"])\)/g,"resample($1ME$2)")).replace(/resample\((['"])Q(['"])\)/g,"resample($1QE$2)")).replace(/resample\((['"])Y(['"])\)/g,"resample($1YE$2)")).replace(/freq=(['"])M(['"])/g,"freq=$1ME$2"),i=await a.execute({code:s,language:"python",files:r,timeout:3e4})),{stdout:i.stdout.slice(0,5e3),stderr:i.stderr.slice(0,2e3),exitCode:i.exitCode,artifacts:i.artifacts.map(e=>({name:e.name,mimeType:e.mimeType,data:e.data.slice(0,5e5)})),executionTimeMs:i.executionTimeMs}}catch(e){return{stdout:"",stderr:e.message??"Sandbox execution failed",exitCode:1,artifacts:[],executionTimeMs:0}}}}),analyzeImageDeeply:(0,M.tool)({description:"Use this tool when you need to answer a detailed question about an image (like a diagram, chart, or schema) found in the knowledge base. Pass the exact imageUrl found in the document metadata, along with specific instructions on what you need to extract from it.",inputSchema:D.z.object({imageUrl:D.z.string().describe("The URL of the image to analyze (from metadata.images.imageUrl)"),prompt:D.z.string().describe("Specific instructions on what to extract or analyze from this image. Be as detailed as possible to get the best result.")}),execute:async({imageUrl:e,prompt:t})=>{try{let a=e.startsWith("/")?`http://127.0.0.1:${process.env.PORT||3e3}${e}`:e,r=await fetch(a);if(!r.ok)throw Error(`Failed to fetch image: ${r.statusText}`);let s=await r.arrayBuffer(),i=Buffer.from(s).toString("base64");r.headers.get("content-type");let n=await fetch(`http://127.0.0.1:${process.env.PORT||3e3}/api/describe-image`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({base64:i,prompt:t})});if(!n.ok)throw Error(`Vision API error: ${n.statusText}`);return{analysis:(await n.json()).description}}catch(e){return{error:`Failed to analyze image: ${e.message}`}}}}),getIndexedData:(0,M.tool)({description:'Get structured access to ALL indexed source documents. Use this for counting, listing, filtering, and overview questions about the knowledge base. Returns document metadata (title, source type, status, custom metadata fields, dates). Use this when the user asks "how many documents?", "list all X", "show progress", "what sources?", or any structural question about the corpus.',inputSchema:D.z.object({filter:D.z.object({source:D.z.enum(["paste","upload","scrape","tabular","media"]).optional().describe("Filter by document source type."),status:D.z.enum(["indexed","unindexed"]).optional().describe("Filter by indexing status."),metadataKey:D.z.string().optional().describe("Filter by metadata key existence."),metadataValue:D.z.string().optional().describe("Filter by metadata key=value (requires metadataKey)."),titleContains:D.z.string().optional().describe("Case-insensitive text search in title."),createdAfter:D.z.string().optional().describe("Only docs created on or after this ISO date."),createdBefore:D.z.string().optional().describe("Only docs created on or before this ISO date.")}).optional().describe("Optional filters to narrow down documents."),limit:D.z.number().optional().default(200).describe("Max number of document summaries to return (default 200)."),offset:D.z.number().optional().default(0).describe("Pagination offset."),includeContent:D.z.boolean().optional().default(!1).describe("Whether to include truncated document content. Default false for performance. Set true only when you need the actual text.")}),execute:async({filter:e,limit:t,offset:a,includeContent:r})=>{try{let s=Math.min(t??(r?20:100),r?20:100);return await F(e,s,a??0,r??!1)}catch(e){return{documents:[],total:0,summary:{totalDocuments:0,bySource:{},byStatus:{},topMetadataKeys:[],totalCharacters:0,dateRange:null},error:e.message??"Failed to retrieve corpus data"}}}}),analyzeCorpusWithCode:(0,M.tool)({description:'Run Python code in a sandbox with the FULL indexed corpus available as a file. Use this for complex analysis of documents: parsing fields from content, computing progress percentages, grouping by patterns, detecting duplicates, generating charts from corpus data, or any question that requires programmatic processing of hundreds/thousands of documents. The corpus is available as "corpus.csv" (or "corpus.jsonl" if format is jsonl). CSV columns: id, title, source, url, charCount, status, createdAt, content, plus any metadata_* columns.',inputSchema:D.z.object({code:D.z.string().describe('Python code to execute. The corpus file is in the working directory. Use pandas to load it: df = pd.read_csv("corpus.csv") or for JSONL: df = pd.read_json("corpus.jsonl", lines=True). Has pandas (2.0+), numpy, matplotlib, scipy, sklearn, seaborn available. ALWAYS use "ME" instead of "M" for resample frequency. Print results and use plt.show() for charts.'),format:D.z.enum(["csv","jsonl"]).optional().default("csv").describe("Format of the corpus file. Default is CSV.")}),execute:async({code:e,format:t})=>{try{let a=new B.SandboxManager({backend:"docker"}),r="jsonl"===t?await K():await L();if(!r)return{stdout:"No documents found in the corpus.",stderr:"",exitCode:0,artifacts:[],executionTimeMs:0};let s=[{name:"jsonl"===t?"corpus.jsonl":"corpus.csv",content:r}],i=e,n=await a.execute({code:i,language:"python",files:s,timeout:3e4});return 0!==n.exitCode&&(i=(i=(i=(i=i.replace(/resample\((['"])M(['"])\)/g,"resample($1ME$2)")).replace(/resample\((['"])Q(['"])\)/g,"resample($1QE$2)")).replace(/resample\((['"])Y(['"])\)/g,"resample($1YE$2)")).replace(/freq=(['"])M(['"])/g,"freq=$1ME$2"),n=await a.execute({code:i,language:"python",files:s,timeout:3e4})),{stdout:n.stdout.slice(0,5e3),stderr:n.stderr.slice(0,2e3),exitCode:n.exitCode,artifacts:n.artifacts.map(e=>({name:e.name,mimeType:e.mimeType,data:e.data.slice(0,5e5)})),executionTimeMs:n.executionTimeMs}}catch(e){return{stdout:"",stderr:e.message??"Corpus analysis failed",exitCode:1,artifacts:[],executionTimeMs:0}}}}),fillDocumentForm:(0,M.tool)({description:'Fill form fields, text inputs, or checkboxes in the currently active document. Use this when the user asks to "fill the form", "add data to fields", or "fill with dummy data". You should use the searchKnowledgeBase tool to find answers to form questions if you do not know them. The available fields are provided in your system prompt.',inputSchema:D.z.object({edits:D.z.array(D.z.object({fieldId:D.z.string().describe("The ID of the field to fill (from the active document context)"),value:D.z.string().describe("The value to set for the field")})).describe("List of fields to fill and their new values")}),execute:async({edits:e})=>{if(!r)return{success:!1,error:"Document not loaded yet. Please wait a moment or ask the user to click the document to open it in the canvas before filling it."};try{let t=e.map(e=>({...e,type:"fill"})),a=await (0,W.applyFieldEdits)(r,t);if(!a.success)return{success:!1,error:a.error};return{success:!0,action:"fill_document",sessionId:r,edits:e,updatedFields:a.updatedFields,fileName:a.parsed.fileName,mimeType:a.parsed.mimeType,fields:a.parsed.fields,pages:a.parsed.pages.map(e=>({index:e.index,text:e.text.slice(0,2e3),html:e.html,fields:e.fields,dimensions:e.dimensions})),totalPages:a.parsed.totalPages,fileBase64:a.fileBase64}}catch(e){return{success:!1,error:e.message}}},toModelOutput:J}),editDocument:(0,M.tool)({description:"Edit the content (text) of the currently active document. Use this when the user asks to modify paragraphs, rewrite text, or change slides (not form fields).",inputSchema:D.z.object({edits:D.z.array(D.z.object({pageIndex:D.z.number().default(0).describe("Page or slide index (0-based)"),type:D.z.enum(["replace_text","insert_text"]).describe("Type of edit"),search:D.z.string().optional().describe("Text to search for (if replacing)"),text:D.z.string().describe("Replacement text or text to insert")})).describe("List of content edits to apply")}),execute:async({edits:e})=>{if(!r)return{success:!1,error:"Document not loaded yet. Please wait a moment or ask the user to click the document to open it in the canvas before editing it."};try{let t=await (0,W.applyContentEdits)(r,e);if(!t.success)return{success:!1,error:t.error};return{success:!0,action:"edit_document",sessionId:r,edits:e,updatedFields:t.updatedFields,fileName:t.parsed.fileName,mimeType:t.parsed.mimeType,pages:t.parsed.pages.map(e=>({index:e.index,text:e.text.slice(0,2e3),html:e.html,fields:e.fields,dimensions:e.dimensions})),totalPages:t.parsed.totalPages,fileBase64:t.fileBase64}}catch(e){return{success:!1,error:e.message}}},toModelOutput:J}),requestDocumentSignature:(0,M.tool)({description:'STRICTLY ONLY use this when the user explicitly asks to "sign" the currently active document or asks for a "signature". CRITICAL: Do NOT use this tool for filling forms, answering questions, or adding dummy data. CRITICAL: NEVER call this tool more than once per user request. Yields a UI widget for the user to confirm the placement and provide their signature.',inputSchema:D.z.object({detectedLocations:D.z.array(D.z.object({pageIndex:D.z.number(),context:D.z.string()})).optional().describe("Optional. The detected signature locations in the document.")})}),webSearch:(0,M.tool)({description:"Search the public internet for current information, news, or facts that are not available in the local knowledge base.",inputSchema:D.z.object({query:D.z.string().describe("The search query.")}),execute:async({query:t})=>{let a,r=s?.webSearchProvider||"tavily",i=new Request("http://localhost/api/search",{method:"POST",body:JSON.stringify({query:t})});try{switch(r){case"google":case"serper":let{POST:t}=await e.A(311108);a=await t(i);break;case"tavily":let{POST:s}=await e.A(118890);a=await s(i);break;case"brave":let{POST:n}=await e.A(3366);a=await n(i);break;case"bing":let{POST:o}=await e.A(654210);a=await o(i);break;case"exa":let{POST:l}=await e.A(187616);a=await l(i);break;default:let{POST:c}=await e.A(465615);a=await c(i)}if(a.status>=400)return{error:(await a.json()).error||"Search failed",results:[]};let d=await a.json();return{results:(d.items||d.results||[]).slice(0,10).map(e=>({title:e.title,url:e.url,snippet:e.description||e.snippet||""}))}}catch(e){return{error:e.message||"Search failed",results:[]}}}})},n=s?.enabledTools||[],o={},l=e=>0===n.length||n.includes(e);for(let[e,t]of Object.entries(i))"webSearch"!==e&&(l(e)||["presentMedia","fillDocumentForm","editDocument","requestDocumentSignature"].includes(e))&&(o[e]=t);s?.webSearchEnabled===!0&&(o.webSearch=i.webSearch);try{for(let e of(await (0,V.getInstalledTools)()))if(l(e.id)){let a=await (0,H.loadTool)(e.id);a&&a.default?o[e.id]=a.default(t):a&&a.tool&&(o[e.id]=a.tool(t))}}catch(e){console.error("[marketplace] Failed to load marketplace tools for chat:",e)}return o}let ee=`
|
|
1
|
+
module.exports=[400660,e=>{"use strict";var t=e.i(239441),a=e.i(449055),r=e.i(391328),s=e.i(6352),i=e.i(746789),n=e.i(423437),o=e.i(178820),l=e.i(569191),d=e.i(576251),c=e.i(199962),u=e.i(547545),m=e.i(664046),p=e.i(235691),h=e.i(298907),f=e.i(110763),g=e.i(193695);e.i(673243);var y=e.i(236167),b=e.i(214312),w=e.i(367165),x=e.i(844915),v=e.i(336321),S=e.i(608778),T=e.i(416487),A=e.i(733164),C=e.i(731699),I=e.i(235072),R=e.i(528909),z=e.i(89087),N=e.i(344963),E=e.i(256485),k=e.i(638725),M=e.i(313893),O=e.i(868776),q=e.i(489694),D=e.i(432970),P=e.i(585071),j=e.i(523554),$=e.i(192441),U=e.i(705252);function L(e,t){return t?e.filter(e=>{if(t.source&&e.source!==t.source||t.status&&e.status!==t.status)return!1;if(t.titleContains){let a=t.titleContains.toLowerCase();if(!e.title.toLowerCase().includes(a))return!1}return(!t.createdAfter||!(e.createdAt<t.createdAfter))&&(!t.createdBefore||!(e.createdAt>t.createdBefore))&&(!t.metadataKey||!!e.metadata&&t.metadataKey in e.metadata&&(void 0===t.metadataValue||String(e.metadata[t.metadataKey])===t.metadataValue))&&!0}):e}async function F(e,t=200,a=0,r=!1){let s=L(await (0,U.readDocuments)(),e),i=s.length;return{documents:s.slice(a,a+t).map(e=>{let t={id:e.id,title:e.title,source:e.source,url:e.url,charCount:e.charCount,status:e.status,metadata:e.metadata,createdAt:e.createdAt};return r&&(t.content=e.content.slice(0,2e3)),t}),total:i,summary:function(e){let t={},a={},r={},s=0,i="",n="";for(let o of e){t[o.source]=(t[o.source]??0)+1;let e=o.status??"unindexed";if(a[e]=(a[e]??0)+1,s+=o.charCount,(!i||o.createdAt<i)&&(i=o.createdAt),(!n||o.createdAt>n)&&(n=o.createdAt),o.metadata)for(let e of Object.keys(o.metadata))e.startsWith("_")||(r[e]=(r[e]??0)+1)}let o=Object.entries(r).sort((e,t)=>t[1]-e[1]).slice(0,20).map(([e,t])=>({key:e,count:t}));return{totalDocuments:e.length,bySource:t,byStatus:a,topMetadataKeys:o,totalCharacters:s,dateRange:i?{earliest:i,latest:n}:null}}(s)}}async function _(e,t=1e3){let a=L(await (0,U.readDocuments)(),e);if(0===a.length)return"";let r=new Set;for(let e of a)if(e.metadata)for(let t of Object.keys(e.metadata))t.startsWith("_")||r.add(t);let s=[...r].sort(),i=["id","title","source","url","charCount","status","createdAt","content",...s.map(e=>`metadata_${e}`)],n=e=>e.includes(",")||e.includes('"')||e.includes("\n")?`"${e.replace(/"/g,'""')}"`:e,o=[i.join(",")];for(let e of a){let a=[e.id,e.title,e.source,e.url??"",String(e.charCount),e.status??"unindexed",e.createdAt,e.content.slice(0,t).replace(/\n/g," ")],r=s.map(t=>{let a=e.metadata?.[t];return null==a?"":"object"==typeof a?JSON.stringify(a):String(a)});o.push([...a,...r].map(n).join(","))}return o.join("\n")}async function K(e,t=1e3){return L(await (0,U.readDocuments)(),e).map(e=>{let a={id:e.id,title:e.title,source:e.source,url:e.url??"",charCount:e.charCount,status:e.status??"unindexed",createdAt:e.createdAt,content:e.content.slice(0,t)};if(e.metadata)for(let[t,r]of Object.entries(e.metadata))t.startsWith("_")||(a[`metadata_${t}`]=r);return JSON.stringify(a)}).join("\n")}e.i(983131);var B=e.i(778923);e.i(907667);var W=e.i(490517),Y=e.i(504740),H=e.i(463857),V=e.i(839554),G=e.i(534404);function J({output:e}){return{type:"json",value:e?.success?{success:!0,action:e.action,sessionId:e.sessionId,updatedFields:e.updatedFields??[],fileName:e.fileName,totalPages:e.totalPages,message:"The document was updated successfully. Do not repeat the edit unless requested."}:{success:!1,error:e?.error??"Document update failed"}}}async function Q(t,a,r){let s=async()=>{let s=await (0,w.readConfig)(),i=Math.max(4*a,20),n=await (0,D.refreshServerStatus)();if(n.running)try{let s=Date.now(),o=await fetch(`${n.endpoint}/query`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,topK:i}),signal:AbortSignal.timeout(15e3)}),l=await o.json(),{trackUsageEvent:d}=await e.A(313282);if(d({type:"server_request",endpoint:"/query",method:"POST",statusCode:o.status,latencyMs:Date.now()-s,serverId:r??void 0,timestamp:new Date().toISOString()}),o.ok&&Array.isArray(l.hits)&&l.hits.length>0)return X(t,l.hits,a)}catch{}let o=await (0,q.readRun)();if(!o||"completed"!==o.status||(o.totalChunks??0)===0)return{query:t,hits:[]};let l=await (0,j.embedQuery)(s,t),d=await (0,P.createAdapter)(s),c=await d.query(l,i,t);return X(t,c,a)};return r?(0,$.runWithServer)(r,s):s()}async function X(e,t,a){var r;let[s,i]=await Promise.all([(0,U.readDocuments)(),(0,V.readMediaAssets)()]),n=new Map(s.map(e=>[e.id,e])),o=new Set(i.flatMap(e=>e.documentIds)),l=t.map(e=>{let t=n.get(e.documentId);return{...e,title:e.title||t?.title||"Untitled",url:e.url||t?.url||"",text:e.text||t?.content||"",metadata:{...t?.metadata,...e.metadata}}}),d=[],c=new Map;for(let e of l){if(e.metadata?.mediaAssetId&&(!n.has(e.documentId)||!o.has(e.documentId)))continue;let t=c.get(e.documentId)??0;if(!(t>=(e.metadata?.isMediaSummary===!0||e.metadata?.contentKind==="multimodal-segment"||e.metadata?.contentKind==="audio-transcript-segment"?1:3))&&(d.push(e),c.set(e.documentId,t+1),d.length>=a))break}let u=d.find(e=>e.metadata?.mediaAssetId)?.metadata.mediaAssetId,m=u?s.filter(e=>"indexed"===e.status&&e.metadata?.mediaAssetId===u&&o.has(e.id)):[],p=m.filter(e=>Number.isFinite(Number(e.metadata?.endSecs))).sort((e,t)=>Number(e.metadata?.endSecs??0)-Number(t.metadata?.endSecs??0)),h=Math.max(0,...p.map(e=>Number(e.metadata?.durationSecs??e.metadata?.endSecs??0))),f=Math.max(600,Math.min(1800,.2*h)),g=p.filter(e=>Number(e.metadata?.endSecs??0)>=h-f),y=[...new Map([...(r=e,/\b(who won|winner|won|final score|scoreline|result|beat|defeated|victor|champion|took (?:the )?(?:game|match|round))\b|من فاز|مين فاز|الفائز|النتيجة|نتيجة|فاز|كسب|البطل|حسم|انتصر/i.test(r))?g.filter(e=>{var t;return t=e.content,/\b(winner|won|final score|total score|scoreline|champion|victor|defeated|beat)\b|الفائز|النتيجة|فاز|كسب|البطل|حسم|انتصر/i.test(t)}).slice(-2):[],...g.slice(-4)].map(e=>[e.id,e])).values()].sort((e,t)=>Number(e.metadata?.endSecs??0)-Number(t.metadata?.endSecs??0)),b=m.find(e=>e.metadata?.isMediaSummary===!0),w=0===y.length?m.find(e=>e.metadata?.contentKind==="multimodal-timeline"):void 0,x=u?[...b?[{role:"summary",title:b.title,url:b.url,text:(0,G.queryAwareExcerpt)(b.content,e,6e3),startSecs:void 0,endSecs:void 0}]:[],...y.map(t=>({role:"ending",title:t.title,url:t.url,text:(0,G.queryAwareExcerpt)(t.content,e,3200,!0),startSecs:t.metadata?.startSecs,endSecs:t.metadata?.endSecs})),...w?[{role:"ending",title:w.title,url:w.url,text:(0,G.queryAwareExcerpt)(w.content,e,4e3,!0),startSecs:void 0,endSecs:w.metadata?.durationSecs}]:[]]:void 0;return{query:e,hits:d.map((t,a)=>{let r=Number(t.metadata?.sequence),i=Number(t.metadata?.startSecs),n=t.metadata?.mediaAssetId?s.filter(e=>{let a=Number(e.metadata?.sequence),s=Number(e.metadata?.startSecs);return"indexed"===e.status&&o.has(e.id)&&e.metadata?.mediaAssetId===t.metadata.mediaAssetId&&Number.isFinite(r)&&Number.isFinite(a)&&1>=Math.abs(a-r)&&(!Number.isFinite(i)||!Number.isFinite(s)||Math.abs(s-i)<=Math.max(90,Number(t.metadata?.endSecs??i)-i,Number(e.metadata?.endSecs??s)-s))}).sort((e,t)=>Number(e.metadata?.startSecs??0)-Number(t.metadata?.startSecs??0)).map(t=>({role:Number(t.metadata?.sequence)<r?"before":Number(t.metadata?.sequence)>r?"after":"matched",title:t.title,url:t.url,text:(0,G.queryAwareExcerpt)(t.content,e,3200),startSecs:t.metadata?.startSecs,endSecs:t.metadata?.endSecs})):void 0;return{documentId:t.documentId,title:t.title??"Untitled",url:t.url??"",score:Number((t.score??0).toFixed(3)),text:(0,G.queryAwareExcerpt)(t.text??"",e,4e3),metadata:t.metadata,timelineContext:n,endingContext:0===a?x:void 0}})}}async function Z(t){let{serverId:a,docSessionId:r,config:s}=t,i={searchKnowledgeBase:(0,M.tool)({description:"HIGHEST PRIORITY TOOL — Search the user's private RAG knowledge base. ALWAYS use this FIRST before webSearch or any other tool when the question may relate to the user's indexed data. This includes questions about documents, files, images, diagrams, videos, or anything the user may have uploaded. Do not use for general knowledge, casual conversation, or writing tasks. Search once with a focused query. For media, inspect the returned timeline and endingContext, and reuse exact mediaAssetId/startSecs/endSecs values with presentMedia when a preview is useful. Never guess timestamps.",inputSchema:O.z.object({query:O.z.string().describe("The search query for the knowledge base.")}),execute:async({query:e})=>Q(e,5,a??null)}),presentMedia:(0,M.tool)({description:"Embed one indexed image, video segment, or audio segment as a compact citation in the chat. Use the exact mediaAssetId and timestamps from a current or earlier search result. Call this when the user asks to see, watch, play, or hear the media, or when one preview materially supports the answer. Prefer one best citation and do not call this for every search hit. Do not search again if the needed asset ID is already in the conversation.",inputSchema:O.z.object({assetId:O.z.string().describe("Exact mediaAssetId returned by searchKnowledgeBase."),startSecs:O.z.number().nonnegative().optional().describe("Exact segment start time returned by searchKnowledgeBase."),endSecs:O.z.number().nonnegative().optional().describe("Exact segment end time returned by searchKnowledgeBase.")}),execute:async({assetId:e,startSecs:t,endSecs:r})=>{let s=async()=>{let s=(await (0,V.readMediaAssets)()).find(t=>t.id===e);if(!s||"completed"!==s.processingStatus)return{success:!1,error:"That indexed media asset is no longer available."};let i=(0,G.normalizeMediaCitationRange)(s.type,s.durationSecs,t,r),n=a?`?serverId=${encodeURIComponent(a)}`:"",o=`/api/media/${s.id}${n}`,l=void 0!==i.startSecs?(0,G.timestampMediaUrl)(s.originalUrl||o,i.startSecs):s.originalUrl||o;return{success:!0,assetId:s.id,mediaType:s.type,fileName:s.fileName,mediaUrl:o,sourceUrl:l,startSecs:i.startSecs,endSecs:i.endSecs}};return a?(0,$.runWithServer)(a,s):s()}}),queryTabularData:(0,M.tool)({description:"Query a tabular dataset (CSV/Excel/JSON) for exact values, filtering, grouping, and aggregations. Use this when the user asks about specific data values, comparisons, averages, sums, counts, highest/lowest, or any numerical question about uploaded data.",inputSchema:O.z.object({datasetId:O.z.string().describe("The ID of the dataset to query. Get this from the available datasets list in the system prompt."),filters:O.z.array(O.z.object({column:O.z.string(),op:O.z.enum(["eq","neq","gt","gte","lt","lte","contains","in"]),value:O.z.any()})).optional().describe("Filters to apply to the data."),groupBy:O.z.array(O.z.string()).optional().describe("Columns to group by for aggregations."),aggregations:O.z.array(O.z.object({column:O.z.string(),op:O.z.enum(["sum","avg","count","min","max","median"])})).optional().describe("Aggregation operations to perform."),sortBy:O.z.string().optional().describe("Column to sort results by."),sortOrder:O.z.enum(["asc","desc"]).optional().describe("Sort direction."),limit:O.z.number().optional().describe("Max number of rows to return."),columns:O.z.array(O.z.string()).optional().describe("Specific columns to include in results.")}),execute:async e=>{try{return await (0,S.queryTabular)(e)}catch(e){return{columns:[],rows:[],totalRows:0,error:e.message??"Query failed"}}}}),generateVisualization:(0,M.tool)({description:"Generate an interactive chart visualization. Use this when the user asks to see trends, comparisons, distributions, or any visual representation of data. The UI will render this as an interactive Recharts chart.",inputSchema:O.z.object({chartType:O.z.enum(["bar","area","line","pie","scatter","radar"]).describe("The type of chart to create."),title:O.z.string().describe("Chart title."),subtitle:O.z.string().optional().describe("Chart subtitle for additional context."),data:O.z.array(O.z.record(O.z.string(),O.z.any())).describe("Array of data points to plot. You MUST provide the data here. Example: [{'name': 'North', 'value': 3206}, {'name': 'East', 'value': 2492}]"),xAxisKey:O.z.string().describe("The key in data objects to use for the X axis (usually 'name')."),series:O.z.array(O.z.object({dataKey:O.z.string().describe("The key in data objects for this series values."),label:O.z.string().optional().describe("Display label for this series in the legend."),color:O.z.string().optional().describe("Color for this series (hex). If omitted, theme colors are used.")})).describe("Data series to plot."),stacked:O.z.boolean().optional().describe("Whether to stack bar/area charts."),showLegend:O.z.boolean().optional().default(!0).describe("Whether to show the legend."),xAxisLabel:O.z.string().optional().describe("Label for the X axis."),yAxisLabel:O.z.string().optional().describe("Label for the Y axis.")}),execute:async e=>e}),executeAnalysis:(0,M.tool)({description:"Execute Python code in a secure sandbox for deep data analysis. Use this for complex statistical computations (correlations, regressions, clustering), data transformations, or when creating custom matplotlib visualizations. The code has access to pandas, numpy, matplotlib, scipy, scikit-learn, and seaborn. Always print results to stdout and use plt.show() for charts.",inputSchema:O.z.object({code:O.z.string().describe('Python code to execute. Has pandas (2.0+), numpy, matplotlib, scipy, sklearn, seaborn available. ALWAYS use "ME" instead of "M" for resample frequency. Print results and use plt.show() for charts.'),datasetId:O.z.string().optional().describe("If provided, the dataset CSV will be available as 'data.csv' in the working directory.")}),execute:async({code:e,datasetId:t})=>{try{let a=new B.SandboxManager({backend:"docker"}),r=[];if(t){let e=await (0,S.getTabularDataset)(t);if(e&&e.rows.length>0){let t=e.columns.map(e=>e.name),a=[t.join(",")];for(let r of e.rows)a.push(t.map(e=>{let t=r[e],a=String(t??"");return a.includes(",")||a.includes('"')?`"${a.replace(/"/g,'""')}"`:a}).join(","));r.push({name:"data.csv",content:a.join("\n")})}}let s=e,i=await a.execute({code:s,language:"python",files:r,timeout:3e4});return 0!==i.exitCode&&(s=(s=(s=(s=s.replace(/resample\((['"])M(['"])\)/g,"resample($1ME$2)")).replace(/resample\((['"])Q(['"])\)/g,"resample($1QE$2)")).replace(/resample\((['"])Y(['"])\)/g,"resample($1YE$2)")).replace(/freq=(['"])M(['"])/g,"freq=$1ME$2"),i=await a.execute({code:s,language:"python",files:r,timeout:3e4})),{stdout:i.stdout.slice(0,5e3),stderr:i.stderr.slice(0,2e3),exitCode:i.exitCode,artifacts:i.artifacts.map(e=>({name:e.name,mimeType:e.mimeType,data:e.data.slice(0,5e5)})),executionTimeMs:i.executionTimeMs}}catch(e){return{stdout:"",stderr:e.message??"Sandbox execution failed",exitCode:1,artifacts:[],executionTimeMs:0}}}}),analyzeImageDeeply:(0,M.tool)({description:"Use this tool when you need to answer a detailed question about an image (like a diagram, chart, or schema) found in the knowledge base. Pass the exact imageUrl found in the document metadata, along with specific instructions on what you need to extract from it.",inputSchema:O.z.object({imageUrl:O.z.string().describe("The URL of the image to analyze (from metadata.images.imageUrl)"),prompt:O.z.string().describe("Specific instructions on what to extract or analyze from this image. Be as detailed as possible to get the best result.")}),execute:async({imageUrl:e,prompt:t})=>{try{let a=e.startsWith("/")?`http://127.0.0.1:${process.env.PORT||3e3}${e}`:e,r=await fetch(a);if(!r.ok)throw Error(`Failed to fetch image: ${r.statusText}`);let s=await r.arrayBuffer(),i=Buffer.from(s).toString("base64");r.headers.get("content-type");let n=await fetch(`http://127.0.0.1:${process.env.PORT||3e3}/api/describe-image`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({base64:i,prompt:t})});if(!n.ok)throw Error(`Vision API error: ${n.statusText}`);return{analysis:(await n.json()).description}}catch(e){return{error:`Failed to analyze image: ${e.message}`}}}}),getIndexedData:(0,M.tool)({description:'Get structured access to ALL indexed source documents. Use this for counting, listing, filtering, and overview questions about the knowledge base. Returns document metadata (title, source type, status, custom metadata fields, dates). Use this when the user asks "how many documents?", "list all X", "show progress", "what sources?", or any structural question about the corpus.',inputSchema:O.z.object({filter:O.z.object({source:O.z.enum(["paste","upload","scrape","tabular","media"]).optional().describe("Filter by document source type."),status:O.z.enum(["indexed","unindexed"]).optional().describe("Filter by indexing status."),metadataKey:O.z.string().optional().describe("Filter by metadata key existence."),metadataValue:O.z.string().optional().describe("Filter by metadata key=value (requires metadataKey)."),titleContains:O.z.string().optional().describe("Case-insensitive text search in title."),createdAfter:O.z.string().optional().describe("Only docs created on or after this ISO date."),createdBefore:O.z.string().optional().describe("Only docs created on or before this ISO date.")}).optional().describe("Optional filters to narrow down documents."),limit:O.z.number().optional().default(200).describe("Max number of document summaries to return (default 200)."),offset:O.z.number().optional().default(0).describe("Pagination offset."),includeContent:O.z.boolean().optional().default(!1).describe("Whether to include truncated document content. Default false for performance. Set true only when you need the actual text.")}),execute:async({filter:e,limit:t,offset:a,includeContent:r})=>{try{let s=Math.min(t??(r?20:100),r?20:100);return await F(e,s,a??0,r??!1)}catch(e){return{documents:[],total:0,summary:{totalDocuments:0,bySource:{},byStatus:{},topMetadataKeys:[],totalCharacters:0,dateRange:null},error:e.message??"Failed to retrieve corpus data"}}}}),analyzeCorpusWithCode:(0,M.tool)({description:'Run Python code in a sandbox with the FULL indexed corpus available as a file. Use this for complex analysis of documents: parsing fields from content, computing progress percentages, grouping by patterns, detecting duplicates, generating charts from corpus data, or any question that requires programmatic processing of hundreds/thousands of documents. The corpus is available as "corpus.csv" (or "corpus.jsonl" if format is jsonl). CSV columns: id, title, source, url, charCount, status, createdAt, content, plus any metadata_* columns.',inputSchema:O.z.object({code:O.z.string().describe('Python code to execute. The corpus file is in the working directory. Use pandas to load it: df = pd.read_csv("corpus.csv") or for JSONL: df = pd.read_json("corpus.jsonl", lines=True). Has pandas (2.0+), numpy, matplotlib, scipy, sklearn, seaborn available. ALWAYS use "ME" instead of "M" for resample frequency. Print results and use plt.show() for charts.'),format:O.z.enum(["csv","jsonl"]).optional().default("csv").describe("Format of the corpus file. Default is CSV.")}),execute:async({code:e,format:t})=>{try{let a=new B.SandboxManager({backend:"docker"}),r="jsonl"===t?await K():await _();if(!r)return{stdout:"No documents found in the corpus.",stderr:"",exitCode:0,artifacts:[],executionTimeMs:0};let s=[{name:"jsonl"===t?"corpus.jsonl":"corpus.csv",content:r}],i=e,n=await a.execute({code:i,language:"python",files:s,timeout:3e4});return 0!==n.exitCode&&(i=(i=(i=(i=i.replace(/resample\((['"])M(['"])\)/g,"resample($1ME$2)")).replace(/resample\((['"])Q(['"])\)/g,"resample($1QE$2)")).replace(/resample\((['"])Y(['"])\)/g,"resample($1YE$2)")).replace(/freq=(['"])M(['"])/g,"freq=$1ME$2"),n=await a.execute({code:i,language:"python",files:s,timeout:3e4})),{stdout:n.stdout.slice(0,5e3),stderr:n.stderr.slice(0,2e3),exitCode:n.exitCode,artifacts:n.artifacts.map(e=>({name:e.name,mimeType:e.mimeType,data:e.data.slice(0,5e5)})),executionTimeMs:n.executionTimeMs}}catch(e){return{stdout:"",stderr:e.message??"Corpus analysis failed",exitCode:1,artifacts:[],executionTimeMs:0}}}}),fillDocumentForm:(0,M.tool)({description:'Fill form fields, text inputs, or checkboxes in the currently active document. Use this when the user asks to "fill the form", "add data to fields", or "fill with dummy data". You should use the searchKnowledgeBase tool to find answers to form questions if you do not know them. The available fields are provided in your system prompt.',inputSchema:O.z.object({edits:O.z.array(O.z.object({fieldId:O.z.string().describe("The ID of the field to fill (from the active document context)"),value:O.z.string().describe("The value to set for the field")})).describe("List of fields to fill and their new values")}),execute:async({edits:e})=>{if(!r)return{success:!1,error:"Document not loaded yet. Please wait a moment or ask the user to click the document to open it in the canvas before filling it."};try{let t=e.map(e=>({...e,type:"fill"})),a=await (0,W.applyFieldEdits)(r,t);if(!a.success)return{success:!1,error:a.error};return{success:!0,action:"fill_document",sessionId:r,edits:e,updatedFields:a.updatedFields,fileName:a.parsed.fileName,mimeType:a.parsed.mimeType,fields:a.parsed.fields,pages:a.parsed.pages.map(e=>({index:e.index,text:e.text.slice(0,2e3),html:e.html,fields:e.fields,dimensions:e.dimensions})),totalPages:a.parsed.totalPages,fileBase64:a.fileBase64}}catch(e){return{success:!1,error:e.message}}},toModelOutput:J}),editDocument:(0,M.tool)({description:"Edit the content (text) of the currently active document. Use this when the user asks to modify paragraphs, rewrite text, or change slides (not form fields).",inputSchema:O.z.object({edits:O.z.array(O.z.object({pageIndex:O.z.number().default(0).describe("Page or slide index (0-based)"),type:O.z.enum(["replace_text","insert_text"]).describe("Type of edit"),search:O.z.string().optional().describe("Text to search for (if replacing)"),text:O.z.string().describe("Replacement text or text to insert")})).describe("List of content edits to apply")}),execute:async({edits:e})=>{if(!r)return{success:!1,error:"Document not loaded yet. Please wait a moment or ask the user to click the document to open it in the canvas before editing it."};try{let t=await (0,W.applyContentEdits)(r,e);if(!t.success)return{success:!1,error:t.error};return{success:!0,action:"edit_document",sessionId:r,edits:e,updatedFields:t.updatedFields,fileName:t.parsed.fileName,mimeType:t.parsed.mimeType,pages:t.parsed.pages.map(e=>({index:e.index,text:e.text.slice(0,2e3),html:e.html,fields:e.fields,dimensions:e.dimensions})),totalPages:t.parsed.totalPages,fileBase64:t.fileBase64}}catch(e){return{success:!1,error:e.message}}},toModelOutput:J}),requestDocumentSignature:(0,M.tool)({description:'STRICTLY ONLY use this when the user explicitly asks to "sign" the currently active document or asks for a "signature". CRITICAL: Do NOT use this tool for filling forms, answering questions, or adding dummy data. CRITICAL: NEVER call this tool more than once per user request. Yields a UI widget for the user to confirm the placement and provide their signature.',inputSchema:O.z.object({detectedLocations:O.z.array(O.z.object({pageIndex:O.z.number(),context:O.z.string()})).optional().describe("Optional. The detected signature locations in the document.")})}),webSearch:(0,M.tool)({description:"Search the public internet for current information, news, or facts. IMPORTANT: Only use this AFTER searchKnowledgeBase has been tried first and returned no relevant results. Never use webSearch as a first resort — the user's indexed knowledge base always takes priority. Use webSearch for questions about current events, public facts, or topics clearly outside the user's indexed data.",inputSchema:O.z.object({query:O.z.string().describe("The search query.")}),execute:async({query:t})=>{let a,r=s?.webSearchProvider||"tavily",i=new Request("http://localhost/api/search",{method:"POST",body:JSON.stringify({query:t})});try{switch(r){case"google":case"serper":let{POST:t}=await e.A(311108);a=await t(i);break;case"tavily":let{POST:s}=await e.A(118890);a=await s(i);break;case"brave":let{POST:n}=await e.A(3366);a=await n(i);break;case"bing":let{POST:o}=await e.A(654210);a=await o(i);break;case"exa":let{POST:l}=await e.A(187616);a=await l(i);break;default:let{POST:d}=await e.A(465615);a=await d(i)}if(a.status>=400)return{error:(await a.json()).error||"Search failed",results:[]};let c=await a.json();return{results:(c.items||c.results||[]).slice(0,10).map(e=>({title:e.title,url:e.url,snippet:e.description||e.snippet||""}))}}catch(e){return{error:e.message||"Search failed",results:[]}}}})},n=s?.enabledTools||[],o={},l=e=>0===n.length||n.includes(e);for(let[e,t]of Object.entries(i))"webSearch"!==e&&(l(e)||["presentMedia","fillDocumentForm","editDocument","requestDocumentSignature"].includes(e))&&(o[e]=t);s?.webSearchEnabled===!0&&(o.webSearch=i.webSearch);try{for(let e of(await (0,H.getInstalledTools)()))if(l(e.id)){let a=await (0,Y.loadTool)(e.id);a&&a.default?o[e.id]=a.default(t):a&&a.tool&&(o[e.id]=a.tool(t))}}catch(e){console.error("[marketplace] Failed to load marketplace tools for chat:",e)}return o}let ee=`
|
|
2
2
|
|
|
3
3
|
CONVERSATION, RETRIEVAL, AND MEDIA POLICY:
|
|
4
|
+
|
|
5
|
+
TOOL PRIORITY (strict order):
|
|
6
|
+
1. searchKnowledgeBase — ALWAYS try this FIRST when the question may relate to the user's indexed data. This includes any question mentioning "I", "my", "our", "the document", "the file", "the diagram", "the image", "show me", or referencing specific topics the user has likely indexed.
|
|
7
|
+
2. Web search (if enabled) — Use ONLY if searchKnowledgeBase returned zero relevant hits AND the question is factual and benefits from web results.
|
|
8
|
+
3. Other tools (tabular queries, analysis, etc.) — Use when the question specifically requires them.
|
|
9
|
+
4. General knowledge — Answer from your training data ONLY for general knowledge questions clearly unrelated to the user's data.
|
|
10
|
+
5. If no tool yields relevant results AND you cannot answer reliably from general knowledge, respond honestly: "I could not find relevant information in your knowledge base or available sources."
|
|
11
|
+
|
|
12
|
+
RETRIEVAL RULES:
|
|
4
13
|
- Default to a short, direct answer. One to three sentences is usually enough; use structure only when the task is genuinely complex.
|
|
5
14
|
- Do not search for greetings, casual conversation, writing help, brainstorming, explanations you can answer reliably from general knowledge, or questions unrelated to the user's indexed data.
|
|
6
15
|
- Use searchKnowledgeBase only when the answer depends on the user's indexed/private content, an exact source-specific fact, or a topic that plausibly refers to something the user indexed.
|
|
7
16
|
- Treat questions about the user or their materials as knowledge-base questions: phrases such as "I", "my", "our", "you have", "the database", "the document", "the file", or "the diagram" require searchKnowledgeBase before answering whenever indexed content may contain the answer.
|
|
8
17
|
- Search at most once per user request unless the first search is clearly irrelevant. Never repeat a search when a prior tool result in this conversation already contains enough evidence.
|
|
18
|
+
|
|
19
|
+
IMAGE AND MEDIA RULES:
|
|
20
|
+
- NEVER output raw markdown image syntax like . The chat UI blocks these and shows "[Image unavailable]". Instead, always use the presentMedia tool to display images, videos, or audio from indexed content.
|
|
21
|
+
- When search results contain metadata.images or a mediaAssetId referencing an image, use presentMedia with the exact assetId to embed the image in the chat. This is the ONLY way images can appear in the conversation.
|
|
9
22
|
- For a follow-up such as "show me that part", "play the clip", "show the image", or "let me hear it", reuse the mediaAssetId and timestamps already present in the earlier search result and call presentMedia directly. Do not search again just to rediscover the same media.
|
|
10
23
|
- Use presentMedia to embed exactly one best video, image, or audio citation when the user asks to see/hear it or when one compact preview materially supports the answer. Do not present every search result.
|
|
11
24
|
- Keep the written answer minimal around a media citation. Do not print internal media reference markers.
|
|
12
|
-
`;async function et(t){let{messages:a,serverId:r,chatModelId:s,docSessionId:i,docFields:n}=await t.json(),o=await (0,w.readConfig)(),l=o.chatProvider||o.embeddingProvider,
|
|
25
|
+
`;async function et(t){let{messages:a,serverId:r,chatModelId:s,docSessionId:i,docFields:n}=await t.json(),o=await (0,w.readConfig)(),l=o.chatProvider||o.embeddingProvider,d=(await (0,x.getModelsByType)("language")).map(v.toChatDescriptor),c=s||o.chatModelId||(0,v.getDefaultChatModel)(d,l)?.id||"openai/gpt-4o-mini",u=c.split("/")[0],m="vercel_ai_gateway"===l?"vercel_ai_gateway":u||l,p=function(e,t,a,r){if(t.startsWith("custom:")){let e=t.slice(7),s=(r??[]).find(t=>t.modelName===e);if(s)return(0,E.createOpenAICompatible)({name:"custom_chat_provider",baseURL:s.baseUrl,apiKey:s.apiKey||a||void 0})(s.modelName)}let s=t.includes("/")?t.split("/").slice(1).join("/"):t;switch(e){case"google":return(0,A.createGoogleGenerativeAI)({apiKey:a})(s);case"cohere":return(0,C.createCohere)({apiKey:a})(s);case"mistral":return(0,I.createMistral)({apiKey:a})(s);case"deepseek":return(0,R.createDeepSeek)({apiKey:a})(s);case"anthropic":return(0,z.createAnthropic)({apiKey:a})(s);case"openai":return(0,T.createOpenAI)({apiKey:a})(s);default:return(0,N.createGateway)({apiKey:a})(t)}}(m,c,o.chatApiKey||o.embeddingApiKey||void 0,o.customChatModels),h=(a.length>20?a.slice(a.length-20):a).map(e=>{let t={...e},a=(e,t)=>{let a=e,r=!1;if("string"==typeof e)try{a=JSON.parse(e),r=!0}catch{return e}if("object"!=typeof a||null===a)return e;let s=t&&["fillDocumentForm","editDocument","requestDocumentSignature"].includes(t);if(s||a.fileBase64||a.pages){let e={...a};return delete e.fileBase64,delete e.pages,s&&(delete e.fields,e.rawText&&(e.rawText=e.rawText.slice(0,500))),r?JSON.stringify(e):e}return e};return"assistant"===t.role&&t.toolInvocations&&(t.toolInvocations=t.toolInvocations.filter(e=>"result"===e.state||"output"===e.state||"output-available"===e.state).map(e=>e.result?{...e,result:a(e.result,e.toolName)}:e)),Array.isArray(t.parts)&&(t.parts=t.parts.map(e=>{if("tool-invocation"===e.type&&e.toolInvocation){let t=e.toolInvocation;if(void 0!==t.result)return{...e,toolInvocation:{...t,result:a(t.result,t.toolName)}}}if("tool-result"===e.type&&void 0!==e.result)return{...e,result:a(e.result,e.toolName)};if("file"===e.type){let t=e.data||e.url||"";if("string"==typeof t&&t.length>5e3){let t=(e.mimeType||e.mediaType||"").toLowerCase();if(!t.startsWith("image/"))return{type:"text",text:`[File attachment: ${t||"document"} — removed from context for size]`}}}return e})),t.experimental_attachments&&(t.experimental_attachments=t.experimental_attachments.filter(e=>!(e.url&&e.url.length>5e3&&(e.contentType&&e.contentType.toLowerCase().includes("pdf")||e.name&&e.name.toLowerCase().endsWith(".pdf")||e.url.substring(0,50).toLowerCase().includes("pdf")||!(e.contentType&&e.contentType.toLowerCase().startsWith("image/"))))&&!0)),Array.isArray(t.content)&&(t.content=t.content.filter(e=>{let t=e.data||e.url||e.text;return!("string"==typeof t&&t.length>5e3&&(e.mimeType&&e.mimeType.toLowerCase().includes("pdf")||e.contentType&&e.contentType.toLowerCase().includes("pdf")||t.substring(0,50).toLowerCase().includes("pdf")||!(e.mimeType?.startsWith("image/")||e.contentType?.startsWith("image/"))))&&!0})),t}),f="";try{let e=await (0,S.listTabularDatasets)();e.length>0&&(f=`
|
|
13
26
|
|
|
14
27
|
Available tabular datasets:
|
|
15
28
|
${e.map(e=>{let t=e.columns.map(e=>{let t=`${e.name} (${e.type})`;return"date"===e.type&&e.dateRange&&(t+=` [format: ${e.dateRange.format}, range: ${e.dateRange.min} to ${e.dateRange.max}]`),e.sampleValues&&e.sampleValues.length>0&&(t+=` [samples: ${e.sampleValues.slice(0,3).join(", ")}]`),t}).join(", "),a=e.rowCount>1e4?" ⚠️ LARGE DATASET — prefer executeAnalysis with pandas for complex queries":"";return`- Dataset "${e.fileName}" (ID: ${e.id}): ${e.rowCount} rows, ${e.summary.totalColumns} columns.${a}
|
|
@@ -20,6 +33,6 @@ You are currently editing a document in the Canvas.
|
|
|
20
33
|
The user may ask you to fill out form fields or edit content.
|
|
21
34
|
IMPORTANT: Use the exact field IDs listed below when calling "fillDocumentForm". Do NOT invent field IDs.
|
|
22
35
|
Available Form Fields (${n?.length??0} total):
|
|
23
|
-
${e}`}let y=(o.systemPrompt||
|
|
36
|
+
${e}`}let y=(o.systemPrompt||k.DEFAULT_SYSTEM_PROMPT)+ee+f+g,M=await Z({serverId:r,docSessionId:i,config:o});return(0,b.streamText)({model:p,system:y,messages:await (0,b.convertToModelMessages)(h,{tools:M}),maxOutputTokens:8192,stopWhen:(0,b.stepCountIs)(8),onFinish:async({usage:t,response:a})=>{let{trackUsageEvent:r,estimateCost:s}=await e.A(313282);r({type:"chat",modelId:c,provider:m,promptTokens:t?.promptTokens??0,completionTokens:t?.completionTokens??0,totalTokens:t?.totalTokens??0,estimatedCost:s(c,t?.promptTokens??0,t?.completionTokens??0),timestamp:new Date().toISOString()})},tools:M}).toUIMessageStreamResponse({onError:e=>{if(console.error("[chat] stream error:",e),e&&"object"==typeof e){if(e.message)return e.message;if(e.error&&e.error.message)return e.error.message;try{return JSON.stringify(e)}catch{return"Something went wrong while generating a response."}}return(e instanceof Error?e.message:String(e))||"Something went wrong while generating a response."}})}e.s(["POST",0,et,"maxDuration",0,60],246037);var ea=e.i(246037);let er=new t.AppRouteRouteModule({definition:{kind:a.RouteKind.APP_ROUTE,page:"/api/chat/route",pathname:"/api/chat",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/apps/web/app/api/chat/route.ts",nextConfigOutput:"standalone",userland:ea,...{}}),{workAsyncStorage:es,workUnitAsyncStorage:ei,serverHooks:en}=er;async function eo(e,t,r){r.requestMeta&&(0,s.setRequestMeta)(e,r.requestMeta),er.isDev&&(0,s.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let b="/api/chat/route";b=b.replace(/\/index$/,"")||"/";let w=await er.prepare(e,t,{srcPage:b,multiZoneDraftMode:!1});if(!w)return t.statusCode=400,t.end("Bad Request"),null==r.waitUntil||r.waitUntil.call(r,Promise.resolve()),null;let{buildId:x,deploymentId:v,params:S,nextConfig:T,parsedUrl:A,isDraftMode:C,prerenderManifest:I,routerServerContext:R,isOnDemandRevalidate:z,revalidateOnlyGenerated:N,resolvedPathname:E,clientReferenceManifest:k,serverActionsManifest:M}=w,O=(0,o.normalizeAppPath)(b),q=!!(I.dynamicRoutes[O]||I.routes[E]),D=async()=>((null==R?void 0:R.render404)?await R.render404(e,t,A,!1):t.end("This page could not be found"),null);if(q&&!C){let e=!!I.routes[E],t=I.dynamicRoutes[O];if(t&&!1===t.fallback&&!e){if(T.adapterPath)return await D();throw new g.NoFallbackError}}let P=null;!q||er.isDev||C||(P="/index"===(P=E)?"/":P);let j=!0===er.isDev||!q,$=q&&!j;M&&k&&(0,n.setManifestsSingleton)({page:b,clientReferenceManifest:k,serverActionsManifest:M});let U=e.method||"GET",L=(0,i.getTracer)(),F=L.getActiveScopeSpan(),_=!!(null==R?void 0:R.isWrappedByNextServer),K=!!(0,s.getRequestMeta)(e,"minimalMode"),B=(0,s.getRequestMeta)(e,"incrementalCache")||await er.getIncrementalCache(e,T,I,K);null==B||B.resetRequestCache(),globalThis.__incrementalCache=B;let W={params:S,previewProps:I.preview,renderOpts:{experimental:{authInterrupts:!!T.experimental.authInterrupts},cacheComponents:!!T.cacheComponents,supportsDynamicResponse:j,incrementalCache:B,cacheLifeProfiles:T.cacheLife,waitUntil:r.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,a,r,s)=>er.onRequestError(e,t,r,s,R)},sharedContext:{buildId:x,deploymentId:v}},Y=new l.NodeNextRequest(e),H=new l.NodeNextResponse(t),V=d.NextRequestAdapter.fromNodeNextRequest(Y,(0,d.signalFromNodeResponse)(t));try{let s,n=async e=>er.handle(V,W).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let a=L.getRootSpanAttributes();if(!a)return;if(a.get("next.span_type")!==c.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${a.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let r=a.get("next.route");if(r){let t=`${U} ${r}`;e.setAttributes({"next.route":r,"http.route":r,"next.span_name":t}),e.updateName(t),s&&s!==e&&(s.setAttribute("http.route",r),s.updateName(t))}else e.updateName(`${U} ${b}`)}),o=async s=>{var i,o;let l=async({previousCacheEntry:a})=>{try{if(!K&&z&&N&&!a)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let i=await n(s);e.fetchMetrics=W.renderOpts.fetchMetrics;let o=W.renderOpts.pendingWaitUntil;o&&r.waitUntil&&(r.waitUntil(o),o=void 0);let l=W.renderOpts.collectedTags;if(!q)return await (0,m.sendResponse)(Y,H,i,W.renderOpts.pendingWaitUntil),null;{let e=await i.blob(),t=(0,p.toNodeOutgoingHttpHeaders)(i.headers);l&&(t[f.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let a=void 0!==W.renderOpts.collectedRevalidate&&!(W.renderOpts.collectedRevalidate>=f.INFINITE_CACHE)&&W.renderOpts.collectedRevalidate,r=void 0===W.renderOpts.collectedExpire||W.renderOpts.collectedExpire>=f.INFINITE_CACHE?void 0:W.renderOpts.collectedExpire;return{value:{kind:y.CachedRouteKind.APP_ROUTE,status:i.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:a,expire:r}}}}catch(t){throw(null==a?void 0:a.isStale)&&await er.onRequestError(e,t,{routerKind:"App Router",routePath:b,routeType:"route",revalidateReason:(0,u.getRevalidateReason)({isStaticGeneration:$,isOnDemandRevalidate:z})},!1,R),t}},d=await er.handleResponse({req:e,nextConfig:T,cacheKey:P,routeKind:a.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:I,isRoutePPREnabled:!1,isOnDemandRevalidate:z,revalidateOnlyGenerated:N,responseGenerator:l,waitUntil:r.waitUntil,isMinimalMode:K});if(!q)return null;if((null==d||null==(i=d.value)?void 0:i.kind)!==y.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==d||null==(o=d.value)?void 0:o.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});K||t.setHeader("x-nextjs-cache",z?"REVALIDATED":d.isMiss?"MISS":d.isStale?"STALE":"HIT"),C&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let c=(0,p.fromNodeOutgoingHttpHeaders)(d.value.headers);return K&&q||c.delete(f.NEXT_CACHE_TAGS_HEADER),!d.cacheControl||t.getHeader("Cache-Control")||c.get("Cache-Control")||c.set("Cache-Control",(0,h.getCacheControlHeader)(d.cacheControl)),await (0,m.sendResponse)(Y,H,new Response(d.value.body,{headers:c,status:d.value.status||200})),null};_&&F?await o(F):(s=L.getActiveScopeSpan(),await L.withPropagatedContext(e.headers,()=>L.trace(c.BaseServerSpan.handleRequest,{spanName:`${U} ${b}`,kind:i.SpanKind.SERVER,attributes:{"http.method":U,"http.target":e.url}},o),void 0,!_))}catch(t){if(t instanceof g.NoFallbackError||await er.onRequestError(e,t,{routerKind:"App Router",routePath:O,routeType:"route",revalidateReason:(0,u.getRevalidateReason)({isStaticGeneration:$,isOnDemandRevalidate:z})},!1,R),q)throw t;return await (0,m.sendResponse)(Y,H,new Response(null,{status:500})),null}}e.s(["handler",0,eo,"patchFetch",0,function(){return(0,r.patchFetch)({workAsyncStorage:es,workUnitAsyncStorage:ei})},"routeModule",0,er,"serverHooks",0,en,"workAsyncStorage",0,es,"workUnitAsyncStorage",0,ei],400660)}];
|
|
24
37
|
|
|
25
38
|
//# sourceMappingURL=0598_next_dist_esm_build_templates_app-route_0kbcuk-.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module.exports=[912714,(t,e,a)=>{e.exports=t.x("node:fs/promises",()=>require("node:fs/promises"))},46465,t=>{"use strict";var e=t.i(750227),a=t.i(912714);let i=null;async function s(){return i||(i=await import("@lancedb/lancedb")),i}t.s(["LanceDBAdapter",0,class{config;conn;table;tableName;constructor(t){this.config=t,this.conn=null,this.table=null,this.tableName=t.tableName?.trim()||"documents"}async connect(){if(this.conn)return this.conn;let t=await s();if("cloud"===this.config.mode){if(!this.config.uri||!this.config.apiKey)throw Error("LanceDB Cloud requires both a URI and an API key.");if(!this.config.uri.startsWith("db://"))throw Error("LanceDB Cloud URI must start with 'db://' (e.g. db://my-database).");this.conn=await t.connect(this.config.uri,{apiKey:this.config.apiKey})}else if("s3"===this.config.mode){if(!this.config.s3Uri||!this.config.s3AccessKeyId||!this.config.s3SecretAccessKey)throw Error("S3-compatible LanceDB requires a URI, access key ID, and secret access key.");if(!this.config.s3Uri.startsWith("s3://"))throw Error("S3-compatible LanceDB URI must start with 's3://' (e.g. s3://my-bucket/lancedb).");this.conn=await t.connect(this.config.s3Uri,{storageOptions:{aws_access_key_id:this.config.s3AccessKeyId,aws_secret_access_key:this.config.s3SecretAccessKey,...this.config.s3Endpoint?{aws_endpoint:this.config.s3Endpoint}:{},...this.config.s3Region?{aws_region:this.config.s3Region}:{}}})}else{let i=this.config.dbPath?.trim()||"./.larkup/lancedb",s=e.default.isAbsolute(i)?i:e.default.join(process.cwd(),i);try{await a.default.mkdir(s,{recursive:!0})}catch(t){if(e.default.isAbsolute(i)){let t="."+i;s=e.default.join(process.cwd(),t);try{await a.default.mkdir(s,{recursive:!0})}catch(t){throw Error(`Could not create directory for LanceDB at "${s}": ${t.message}`)}}else throw Error(`Could not create directory for LanceDB at "${s}": ${t.message}`)}this.conn=await t.connect(s)}return this.conn}async init(){let t=await this.connect();(await t.tableNames()).includes(this.tableName)&&(this.table=await t.openTable(this.tableName))}async reset(){let t=await this.connect();(await t.tableNames()).includes(this.tableName)&&await t.dropTable(this.tableName),this.table=null}async deleteByDocumentIds(t){if(0===t.length||!this.table&&(await this.init(),!this.table))return;let e=t.map(t=>`'${t}'`).join(", ");await this.table.delete(`documentId IN (${e})`)}toRow(t){return{id:t.id,vector:t.vector,text:t.text,title:t.title,url:t.url??"",source:t.source,documentId:t.documentId,chunkIndex:t.chunkIndex,metadata:
|
|
1
|
+
module.exports=[912714,(t,e,a)=>{e.exports=t.x("node:fs/promises",()=>require("node:fs/promises"))},46465,t=>{"use strict";var e=t.i(750227),a=t.i(912714);let i=null;async function s(){return i||(i=await import("@lancedb/lancedb")),i}t.s(["LanceDBAdapter",0,class{config;conn;table;tableName;constructor(t){this.config=t,this.conn=null,this.table=null,this.tableName=t.tableName?.trim()||"documents"}async connect(){if(this.conn)return this.conn;let t=await s();if("cloud"===this.config.mode){if(!this.config.uri||!this.config.apiKey)throw Error("LanceDB Cloud requires both a URI and an API key.");if(!this.config.uri.startsWith("db://"))throw Error("LanceDB Cloud URI must start with 'db://' (e.g. db://my-database).");this.conn=await t.connect(this.config.uri,{apiKey:this.config.apiKey})}else if("s3"===this.config.mode){if(!this.config.s3Uri||!this.config.s3AccessKeyId||!this.config.s3SecretAccessKey)throw Error("S3-compatible LanceDB requires a URI, access key ID, and secret access key.");if(!this.config.s3Uri.startsWith("s3://"))throw Error("S3-compatible LanceDB URI must start with 's3://' (e.g. s3://my-bucket/lancedb).");this.conn=await t.connect(this.config.s3Uri,{storageOptions:{aws_access_key_id:this.config.s3AccessKeyId,aws_secret_access_key:this.config.s3SecretAccessKey,...this.config.s3Endpoint?{aws_endpoint:this.config.s3Endpoint}:{},...this.config.s3Region?{aws_region:this.config.s3Region}:{}}})}else{let i=this.config.dbPath?.trim()||"./.larkup/lancedb",s=e.default.isAbsolute(i)?i:e.default.join(process.cwd(),i);try{await a.default.mkdir(s,{recursive:!0})}catch(t){if(e.default.isAbsolute(i)){let t="."+i;s=e.default.join(process.cwd(),t);try{await a.default.mkdir(s,{recursive:!0})}catch(t){throw Error(`Could not create directory for LanceDB at "${s}": ${t.message}`)}}else throw Error(`Could not create directory for LanceDB at "${s}": ${t.message}`)}this.conn=await t.connect(s)}return this.conn}async init(){let t=await this.connect();(await t.tableNames()).includes(this.tableName)&&(this.table=await t.openTable(this.tableName))}async reset(){let t=await this.connect();(await t.tableNames()).includes(this.tableName)&&await t.dropTable(this.tableName),this.table=null}async deleteByDocumentIds(t){if(0===t.length||!this.table&&(await this.init(),!this.table))return;let e=t.map(t=>`'${t}'`).join(", ");await this.table.delete(`documentId IN (${e})`)}toRow(t){return{id:t.id,vector:t.vector,text:t.text,title:t.title,url:t.url??"",source:t.source,documentId:t.documentId,chunkIndex:t.chunkIndex,metadata:JSON.stringify(t.metadata??{})}}async upsert(t){if(0===t.length)return;let e=await this.connect(),a=t.map(t=>this.toRow(t));this.table?await this.table.add(a):(await e.tableNames()).includes(this.tableName)?(this.table=await e.openTable(this.tableName),await this.table.add(a)):this.table=await e.createTable(this.tableName,a)}async count(){if(!this.table&&(await this.init(),!this.table))return 0;try{return await this.table.countRows()}catch{return null}}async query(t,e){return this.table||(await this.init(),this.table)?(await this.table.search(t).limit(e).toArray()).map(t=>({id:t.id,score:"number"==typeof t._distance?1/(1+t._distance):0,text:t.text,title:t.title,url:t.url||void 0,documentId:t.documentId,metadata:"string"==typeof t.metadata?JSON.parse(t.metadata):void 0})):[]}async testConnection(t){let e;if("cloud"!==this.config.mode)try{await this.connect();return}catch(e){let t="s3"===this.config.mode?"S3-compatible LanceDB":"local LanceDB";throw Error(`Failed to connect to ${t}: ${e.message}`)}try{e=await this.connect()}catch(t){throw Error(`Failed to connect to LanceDB Cloud: ${t.message}`)}try{await e.tableNames()}catch(e){let t=e.message??"";if(t.includes("401")||t.includes("Unauthorized")||t.includes("403")||t.includes("Forbidden"))throw Error("Invalid LanceDB Cloud API key. Please check your credentials in the LanceDB Cloud dashboard.");if(t.includes("404")||t.includes("Not Found"))throw Error('LanceDB Cloud database not found. Please verify your URI (e.g. "db://my-database").');throw Error(`Failed to reach LanceDB Cloud: ${t}`)}}}])}];
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=%5Broot-of-the-server%5D__01al2n0._.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module.exports=[367165,e=>{"use strict";var t=e.i(902157),r=e.i(750227),a=e.i(638725),n=e.i(192441);async function
|
|
1
|
+
module.exports=[367165,e=>{"use strict";var t=e.i(902157),r=e.i(750227),a=e.i(638725),n=e.i(192441);async function s(){let e=await (0,n.getDataDir)();if(!e)return a.DEFAULT_CONFIG;try{let n=await t.promises.readFile(r.default.join(e,"config.json"),"utf8"),s=JSON.parse(n),i=s.customEmbeddings,o=s.embeddingModelId;if(s.customEmbedding&&!i?.length){let e=s.customEmbedding;i=[e],"custom"===o&&(o=`custom:${e.modelName}`)}let l={...a.DEFAULT_CONFIG,...s,embeddingModelId:o??a.DEFAULT_CONFIG.embeddingModelId,customEmbeddings:i,chunking:{...a.DEFAULT_CONFIG.chunking,...s.chunking},storeConfig:{...a.DEFAULT_CONFIG.storeConfig,...s.storeConfig}};return delete l.customEmbedding,l}catch{return a.DEFAULT_CONFIG}}async function i(e){let a=await (0,n.requireDataDir)(),s={...e,updatedAt:new Date().toISOString()};return await t.promises.writeFile(r.default.join(a,"config.json"),JSON.stringify(s,null,2),"utf8"),s}e.s(["readConfig",0,s,"writeConfig",0,i])},874533,(e,t,r)=>{t.exports=e.x("node:child_process",()=>require("node:child_process"))},812057,(e,t,r)=>{t.exports=e.x("node:util",()=>require("node:util"))},700259,e=>{"use strict";var t=e.i(902157),r=e.i(750227),a=e.i(761095),n=e.i(666680),s=e.i(874533),i=e.i(812057),o=e.i(367165);let l=(0,i.promisify)(s.exec);async function c(e,t){return l(e,{timeout:t,env:{...process.env,PATH:`${process.env.PATH||""}:/usr/local/bin:/opt/homebrew/bin:/bin:/usr/bin`}})}let u=r.default.join(process.cwd(),".larkup"),d=r.default.join(u,"firecrawl-local.json"),p=r.default.join(u,"firecrawl","docker-compose.yml"),h="ragtoolkit-firecrawl";async function m(e){return new Promise((t,r)=>{let n=a.default.createServer();n.listen(e,()=>{let e=n.address().port;n.close(()=>t(e))}),n.on("error",a=>{"EADDRINUSE"===a.code?m(0===e?0:e+1).then(t,r):r(a)})})}async function f(){try{let e=r.default.join(process.cwd(),"proxies.txt"),a=(await t.promises.readFile(e,"utf8")).split("\n").map(e=>e.trim()).filter(e=>e.length>0);if(a.length>0){let e=a[Math.floor(Math.random()*a.length)].split(":");if(e.length>=4)return{server:`http://${e[0]}:${e[1]}`,username:e[2],password:e[3]}}}catch(e){}let e=await (0,o.readConfig)();return e.useScraperProxy&&e.scraperProxyServer?{server:e.scraperProxyServer,username:e.scraperProxyUsername,password:e.scraperProxyPassword}:null}let w={running:!1,endpoint:"http://localhost:3002",apiKey:"",port:3002,project:h};async function g(){try{let e=await t.promises.readFile(d,"utf8");return{...w,...JSON.parse(e)}}catch{return w}}async function R(e){return await t.promises.mkdir(u,{recursive:!0}),await t.promises.writeFile(d,JSON.stringify(e,null,2),"utf8"),e}async function v(){try{await c("docker --version")}catch(e){return console.error("DOCKER ERR:",e),{docker:!1,compose:null}}try{return await c("docker compose version"),{docker:!0,compose:"docker compose"}}catch(e){console.error("DOCKER COMPOSE ERR:",e)}try{return await c("docker-compose version"),{docker:!0,compose:"docker-compose"}}catch{return{docker:!0,compose:null}}}async function E(){let{docker:e,compose:t}=await v();return e?t?{docker:!0,compose:!0,message:"Docker is ready."}:{docker:!0,compose:!1,message:"Docker is installed but the Compose plugin was not found. Install `docker compose` to launch Firecrawl locally."}:{docker:!1,compose:!1,message:"Docker isn't available on this machine. Install Docker Desktop (or the Docker engine) and make sure it's running."}}function y(e,t,r){let a=r?[`PROXY_SERVER: "${r.server}"`,...r.username&&r.password?[`PROXY_USERNAME: "${r.username}"`,`PROXY_PASSWORD: "${r.password}"`]:[]]:[],n=['PORT: "3000"',...a].map(e=>` ${e}`).join("\n"),s=['PORT: "3002"',...a,'HOST: "0.0.0.0"','REDIS_URL: "redis://redis:6379"','REDIS_RATE_LIMIT_URL: "redis://redis:6379"','PLAYWRIGHT_MICROSERVICE_URL: "http://playwright-service:3000/scrape"','USE_DB_AUTHENTICATION: "false"',`TEST_API_KEY: "${e}"`,`BULL_AUTH_KEY: "${e}"`,'DATABASE_URL: "postgresql://user:password@db:5432/postgres"','NUQ_DATABASE_URL: "postgresql://user:password@db:5432/postgres"','NUQ_RABBITMQ_URL: "amqp://user:password@rabbitmq:5672"'].map(e=>` ${e}`).join("\n");return`# Auto-generated by RAG Toolkit. Do not edit by hand.
|
|
2
2
|
services:
|
|
3
3
|
db:
|
|
4
4
|
image: ghcr.io/firecrawl/nuq-postgres:latest
|
|
@@ -54,8 +54,8 @@ ${n}
|
|
|
54
54
|
ports:
|
|
55
55
|
- "${t}:3002"
|
|
56
56
|
environment:
|
|
57
|
-
${
|
|
57
|
+
${s}
|
|
58
58
|
restart: unless-stopped
|
|
59
|
-
`}async function b(){let e=await E();if(!e.compose)return R({...await g(),running:!1,lastError:e.message});let{compose:a}=await v(),i=await g(),s=i.apiKey||`fc-local-${(0,n.randomUUID)()}`,o=i.port||3002,l=await f();await t.promises.mkdir(r.default.dirname(p),{recursive:!0}),await t.promises.writeFile(p,y(s,o,l),"utf8");try{await c(`${a} -p ${h} -f "${p}" up -d`,18e4)}catch(r){let e=r instanceof Error?r.message:"docker compose failed";if(!(e.includes("address already in use")||e.includes("Ports are not available")))return R({...i,apiKey:s,port:o,running:!1,lastError:e});try{o=await m(o+1),await t.promises.writeFile(p,y(s,o,l),"utf8"),await c(`${a} -p ${h} -f "${p}" up -d`,18e4)}catch(e){return R({...i,apiKey:s,port:o,running:!1,lastError:e instanceof Error?e.message:"docker compose retry failed"})}}let u=(0,t.existsSync)("/.dockerenv"),d=`http://${u?"host.docker.internal":"localhost"}:${o}`,w=await _(d,9e4);return R({running:w,endpoint:d,apiKey:s,port:o,project:h,startedAt:new Date().toISOString(),lastError:w?void 0:"Containers started but the API did not become healthy in time. It may still be warming up — try refreshing in a moment."})}async function S(){let{compose:e}=await v(),t=await g();if(e)try{await c(`${e} -p ${h} -f "${p}" down`,6e4)}catch{}return R({...t,running:!1,startedAt:void 0})}async function A(){let e=await g();if(!e.startedAt)return e;let t=await k(e.endpoint);return t!==e.running?R({...e,running:t}):e}async function k(e){try{return(await fetch(e,{method:"GET",signal:AbortSignal.timeout(4e3)})).status>0}catch{return!1}}async function _(e,t){let r=Date.now()+t;for(;Date.now()<r;){if(await k(e))return!0;await new Promise(e=>setTimeout(e,3e3))}return!1}let D="http://firecrawl-api:3002";async function C(){return"true"===process.env.DOCKER_ENV||"1"===process.env.DOCKER_BUILD||(0,t.existsSync)("/.dockerenv")?{available:await k(D),endpoint:D}:{available:!1,endpoint:""}}async function T(){let{available:e}=await C();return e?R({running:!0,endpoint:D,apiKey:`fc-docker-${(0,n.randomUUID)()}`,port:3002,project:"docker-sibling",startedAt:new Date().toISOString()}):R({...w,running:!1,lastError:"The web crawler service is not available in this Docker deployment."})}e.s(["checkDocker",0,E,"checkDockerSibling",0,C,"connectDockerSibling",0,T,"readLocalState",0,g,"refreshLocalStatus",0,A,"startLocal",0,b,"stopLocal",0,S])},231344,e=>{"use strict";var t=e.i(239441),r=e.i(449055),a=e.i(391328),n=e.i(6352),i=e.i(746789),s=e.i(423437),o=e.i(178820),l=e.i(569191),c=e.i(576251),u=e.i(199962),d=e.i(547545),p=e.i(664046),h=e.i(235691),m=e.i(298907),f=e.i(110763),w=e.i(193695);e.i(673243);var g=e.i(236167),R=e.i(766576),v=e.i(700259),E=e.i(902157);function y(){return process.env.TAURI_ENV_PLATFORM||process.env.TAURI_ENV_ARCH?"desktop":"true"===process.env.DOCKER_ENV||"1"===process.env.DOCKER_BUILD||(0,E.existsSync)("/.dockerenv")?"docker":"web"}async function b(){let e=y();if("docker"===e){let[t,r]=await Promise.all([(0,v.refreshLocalStatus)(),(0,v.checkDockerSibling)()]),{apiKey:a,...n}=t;return R.NextResponse.json({state:{...n,hasKey:!!a,running:t.running||r.available,endpoint:r.available?r.endpoint:n.endpoint},docker:{docker:!0,compose:r.available,message:r.available?"Crawler service is running.":"Crawler service is not available for this Docker installation."},runtimeEnv:e})}let[t,r]=await Promise.all([(0,v.refreshLocalStatus)(),(0,v.checkDocker)()]),{apiKey:a,...n}=t;return R.NextResponse.json({state:{...n,hasKey:!!a},docker:r,runtimeEnv:e})}async function S(e){let t,r=y();try{({action:t}=await e.json())}catch{return R.NextResponse.json({error:"Invalid request body."},{status:400})}if("start"!==t&&"stop"!==t)return R.NextResponse.json({error:'action must be "start" or "stop".'},{status:400});if("docker"===r)if("start"===t){let{apiKey:e,...t}=await (0,v.connectDockerSibling)();return R.NextResponse.json({state:{...t,hasKey:!!e}})}else{let{apiKey:e,...t}=await (0,v.readLocalState)();return R.NextResponse.json({state:{...t,running:!1,hasKey:!!e}})}let{apiKey:a,...n}="start"===t?await (0,v.startLocal)():await (0,v.stopLocal)();return R.NextResponse.json({state:{...n,hasKey:!!a}})}e.s(["GET",0,b,"POST",0,S,"dynamic",0,"force-dynamic","runtime",0,"nodejs"],705563);var A=e.i(705563);let k=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/firecrawl/local/route",pathname:"/api/firecrawl/local",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/apps/web/app/api/firecrawl/local/route.ts",nextConfigOutput:"standalone",userland:A,...{}}),{workAsyncStorage:_,workUnitAsyncStorage:D,serverHooks:C}=k;async function T(e,t,a){a.requestMeta&&(0,n.setRequestMeta)(e,a.requestMeta),k.isDev&&(0,n.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let R="/api/firecrawl/local/route";R=R.replace(/\/index$/,"")||"/";let v=await k.prepare(e,t,{srcPage:R,multiZoneDraftMode:!1});if(!v)return t.statusCode=400,t.end("Bad Request"),null==a.waitUntil||a.waitUntil.call(a,Promise.resolve()),null;let{buildId:E,deploymentId:y,params:b,nextConfig:S,parsedUrl:A,isDraftMode:_,prerenderManifest:D,routerServerContext:C,isOnDemandRevalidate:T,revalidateOnlyGenerated:O,resolvedPathname:P,clientReferenceManifest:x,serverActionsManifest:I}=v,N=(0,o.normalizeAppPath)(R),U=!!(D.dynamicRoutes[N]||D.routes[P]),L=async()=>((null==C?void 0:C.render404)?await C.render404(e,t,A,!1):t.end("This page could not be found"),null);if(U&&!_){let e=!!D.routes[P],t=D.dynamicRoutes[N];if(t&&!1===t.fallback&&!e){if(S.adapterPath)return await L();throw new w.NoFallbackError}}let $=null;!U||k.isDev||_||($="/index"===($=P)?"/":$);let q=!0===k.isDev||!U,F=U&&!q;I&&x&&(0,s.setManifestsSingleton)({page:R,clientReferenceManifest:x,serverActionsManifest:I});let M=e.method||"GET",j=(0,i.getTracer)(),H=j.getActiveScopeSpan(),K=!!(null==C?void 0:C.isWrappedByNextServer),B=!!(0,n.getRequestMeta)(e,"minimalMode"),G=(0,n.getRequestMeta)(e,"incrementalCache")||await k.getIncrementalCache(e,S,D,B);null==G||G.resetRequestCache(),globalThis.__incrementalCache=G;let V={params:b,previewProps:D.preview,renderOpts:{experimental:{authInterrupts:!!S.experimental.authInterrupts},cacheComponents:!!S.cacheComponents,supportsDynamicResponse:q,incrementalCache:G,cacheLifeProfiles:S.cacheLife,waitUntil:a.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,a,n)=>k.onRequestError(e,t,a,n,C)},sharedContext:{buildId:E,deploymentId:y}},W=new l.NodeNextRequest(e),X=new l.NodeNextResponse(t),Y=c.NextRequestAdapter.fromNodeNextRequest(W,(0,c.signalFromNodeResponse)(t));try{let n,s=async e=>k.handle(Y,V).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=j.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==u.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${r.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let a=r.get("next.route");if(a){let t=`${M} ${a}`;e.setAttributes({"next.route":a,"http.route":a,"next.span_name":t}),e.updateName(t),n&&n!==e&&(n.setAttribute("http.route",a),n.updateName(t))}else e.updateName(`${M} ${R}`)}),o=async n=>{var i,o;let l=async({previousCacheEntry:r})=>{try{if(!B&&T&&O&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let i=await s(n);e.fetchMetrics=V.renderOpts.fetchMetrics;let o=V.renderOpts.pendingWaitUntil;o&&a.waitUntil&&(a.waitUntil(o),o=void 0);let l=V.renderOpts.collectedTags;if(!U)return await (0,p.sendResponse)(W,X,i,V.renderOpts.pendingWaitUntil),null;{let e=await i.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(i.headers);l&&(t[f.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==V.renderOpts.collectedRevalidate&&!(V.renderOpts.collectedRevalidate>=f.INFINITE_CACHE)&&V.renderOpts.collectedRevalidate,a=void 0===V.renderOpts.collectedExpire||V.renderOpts.collectedExpire>=f.INFINITE_CACHE?void 0:V.renderOpts.collectedExpire;return{value:{kind:g.CachedRouteKind.APP_ROUTE,status:i.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:a}}}}catch(t){throw(null==r?void 0:r.isStale)&&await k.onRequestError(e,t,{routerKind:"App Router",routePath:R,routeType:"route",revalidateReason:(0,d.getRevalidateReason)({isStaticGeneration:F,isOnDemandRevalidate:T})},!1,C),t}},c=await k.handleResponse({req:e,nextConfig:S,cacheKey:$,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:D,isRoutePPREnabled:!1,isOnDemandRevalidate:T,revalidateOnlyGenerated:O,responseGenerator:l,waitUntil:a.waitUntil,isMinimalMode:B});if(!U)return null;if((null==c||null==(i=c.value)?void 0:i.kind)!==g.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==c||null==(o=c.value)?void 0:o.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});B||t.setHeader("x-nextjs-cache",T?"REVALIDATED":c.isMiss?"MISS":c.isStale?"STALE":"HIT"),_&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let u=(0,h.fromNodeOutgoingHttpHeaders)(c.value.headers);return B&&U||u.delete(f.NEXT_CACHE_TAGS_HEADER),!c.cacheControl||t.getHeader("Cache-Control")||u.get("Cache-Control")||u.set("Cache-Control",(0,m.getCacheControlHeader)(c.cacheControl)),await (0,p.sendResponse)(W,X,new Response(c.value.body,{headers:u,status:c.value.status||200})),null};K&&H?await o(H):(n=j.getActiveScopeSpan(),await j.withPropagatedContext(e.headers,()=>j.trace(u.BaseServerSpan.handleRequest,{spanName:`${M} ${R}`,kind:i.SpanKind.SERVER,attributes:{"http.method":M,"http.target":e.url}},o),void 0,!K))}catch(t){if(t instanceof w.NoFallbackError||await k.onRequestError(e,t,{routerKind:"App Router",routePath:N,routeType:"route",revalidateReason:(0,d.getRevalidateReason)({isStaticGeneration:F,isOnDemandRevalidate:T})},!1,C),U)throw t;return await (0,p.sendResponse)(W,X,new Response(null,{status:500})),null}}e.s(["handler",0,T,"patchFetch",0,function(){return(0,a.patchFetch)({workAsyncStorage:_,workUnitAsyncStorage:D})},"routeModule",0,k,"serverHooks",0,C,"workAsyncStorage",0,_,"workUnitAsyncStorage",0,D],231344)}];
|
|
59
|
+
`}async function b(){let e=await E();if(!e.compose)return R({...await g(),running:!1,lastError:e.message});let{compose:a}=await v(),s=await g(),i=s.apiKey||`fc-local-${(0,n.randomUUID)()}`,o=s.port||3002,l=await f();await t.promises.mkdir(r.default.dirname(p),{recursive:!0}),await t.promises.writeFile(p,y(i,o,l),"utf8");try{await c(`${a} -p ${h} -f "${p}" up -d`,18e4)}catch(r){let e=r instanceof Error?r.message:"docker compose failed";if(!(e.includes("address already in use")||e.includes("Ports are not available")))return R({...s,apiKey:i,port:o,running:!1,lastError:e});try{o=await m(o+1),await t.promises.writeFile(p,y(i,o,l),"utf8"),await c(`${a} -p ${h} -f "${p}" up -d`,18e4)}catch(e){return R({...s,apiKey:i,port:o,running:!1,lastError:e instanceof Error?e.message:"docker compose retry failed"})}}let u=(0,t.existsSync)("/.dockerenv"),d=`http://${u?"host.docker.internal":"localhost"}:${o}`,w=await _(d,9e4);return R({running:w,endpoint:d,apiKey:i,port:o,project:h,startedAt:new Date().toISOString(),lastError:w?void 0:"Containers started but the API did not become healthy in time. It may still be warming up — try refreshing in a moment."})}async function S(){let{compose:e}=await v(),t=await g();if(e)try{await c(`${e} -p ${h} -f "${p}" down`,6e4)}catch{}return R({...t,running:!1,startedAt:void 0})}async function A(){let e=await g();if(!e.startedAt)return e;let t=await k(e.endpoint);return t!==e.running?R({...e,running:t}):e}async function k(e){try{return(await fetch(e,{method:"GET",signal:AbortSignal.timeout(4e3)})).status>0}catch{return!1}}async function _(e,t){let r=Date.now()+t;for(;Date.now()<r;){if(await k(e))return!0;await new Promise(e=>setTimeout(e,3e3))}return!1}let D="http://firecrawl-api:3002";async function C(){return"true"===process.env.DOCKER_ENV||"1"===process.env.DOCKER_BUILD||(0,t.existsSync)("/.dockerenv")?{available:await k(D),endpoint:D}:{available:!1,endpoint:""}}async function T(){let{available:e}=await C();return e?R({running:!0,endpoint:D,apiKey:`fc-docker-${(0,n.randomUUID)()}`,port:3002,project:"docker-sibling",startedAt:new Date().toISOString()}):R({...w,running:!1,lastError:"The web crawler service is not available in this Docker deployment."})}e.s(["checkDocker",0,E,"checkDockerSibling",0,C,"connectDockerSibling",0,T,"readLocalState",0,g,"refreshLocalStatus",0,A,"startLocal",0,b,"stopLocal",0,S])},231344,e=>{"use strict";var t=e.i(239441),r=e.i(449055),a=e.i(391328),n=e.i(6352),s=e.i(746789),i=e.i(423437),o=e.i(178820),l=e.i(569191),c=e.i(576251),u=e.i(199962),d=e.i(547545),p=e.i(664046),h=e.i(235691),m=e.i(298907),f=e.i(110763),w=e.i(193695);e.i(673243);var g=e.i(236167),R=e.i(766576),v=e.i(700259),E=e.i(902157);function y(){return process.env.TAURI_ENV_PLATFORM||process.env.TAURI_ENV_ARCH?"desktop":"true"===process.env.DOCKER_ENV||"1"===process.env.DOCKER_BUILD||(0,E.existsSync)("/.dockerenv")?"docker":"web"}async function b(){let e=y();if("docker"===e){let[t,r]=await Promise.all([(0,v.refreshLocalStatus)(),(0,v.checkDockerSibling)()]),{apiKey:a,...n}=t;return R.NextResponse.json({state:{...n,hasKey:!!a,running:t.running||r.available,endpoint:r.available?r.endpoint:n.endpoint},docker:{docker:!0,compose:r.available,message:r.available?"Crawler service is running.":"Crawler service is not available for this Docker installation."},runtimeEnv:e})}let[t,r]=await Promise.all([(0,v.refreshLocalStatus)(),(0,v.checkDocker)()]),{apiKey:a,...n}=t;return R.NextResponse.json({state:{...n,hasKey:!!a},docker:r,runtimeEnv:e})}async function S(e){let t,r=y();try{({action:t}=await e.json())}catch{return R.NextResponse.json({error:"Invalid request body."},{status:400})}if("start"!==t&&"stop"!==t)return R.NextResponse.json({error:'action must be "start" or "stop".'},{status:400});if("docker"===r)if("start"===t){let e=await (0,v.connectDockerSibling)();e.running||(e=await (0,v.startLocal)());let{apiKey:t,...r}=e;return R.NextResponse.json({state:{...r,hasKey:!!t}})}else{let{apiKey:e,...t}=await (0,v.stopLocal)();return R.NextResponse.json({state:{...t,hasKey:!!e}})}let{apiKey:a,...n}="start"===t?await (0,v.startLocal)():await (0,v.stopLocal)();return R.NextResponse.json({state:{...n,hasKey:!!a}})}e.s(["GET",0,b,"POST",0,S,"dynamic",0,"force-dynamic","runtime",0,"nodejs"],705563);var A=e.i(705563);let k=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/firecrawl/local/route",pathname:"/api/firecrawl/local",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/apps/web/app/api/firecrawl/local/route.ts",nextConfigOutput:"standalone",userland:A,...{}}),{workAsyncStorage:_,workUnitAsyncStorage:D,serverHooks:C}=k;async function T(e,t,a){a.requestMeta&&(0,n.setRequestMeta)(e,a.requestMeta),k.isDev&&(0,n.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let R="/api/firecrawl/local/route";R=R.replace(/\/index$/,"")||"/";let v=await k.prepare(e,t,{srcPage:R,multiZoneDraftMode:!1});if(!v)return t.statusCode=400,t.end("Bad Request"),null==a.waitUntil||a.waitUntil.call(a,Promise.resolve()),null;let{buildId:E,deploymentId:y,params:b,nextConfig:S,parsedUrl:A,isDraftMode:_,prerenderManifest:D,routerServerContext:C,isOnDemandRevalidate:T,revalidateOnlyGenerated:O,resolvedPathname:P,clientReferenceManifest:x,serverActionsManifest:I}=v,N=(0,o.normalizeAppPath)(R),U=!!(D.dynamicRoutes[N]||D.routes[P]),L=async()=>((null==C?void 0:C.render404)?await C.render404(e,t,A,!1):t.end("This page could not be found"),null);if(U&&!_){let e=!!D.routes[P],t=D.dynamicRoutes[N];if(t&&!1===t.fallback&&!e){if(S.adapterPath)return await L();throw new w.NoFallbackError}}let $=null;!U||k.isDev||_||($="/index"===($=P)?"/":$);let q=!0===k.isDev||!U,F=U&&!q;I&&x&&(0,i.setManifestsSingleton)({page:R,clientReferenceManifest:x,serverActionsManifest:I});let M=e.method||"GET",j=(0,s.getTracer)(),H=j.getActiveScopeSpan(),K=!!(null==C?void 0:C.isWrappedByNextServer),B=!!(0,n.getRequestMeta)(e,"minimalMode"),G=(0,n.getRequestMeta)(e,"incrementalCache")||await k.getIncrementalCache(e,S,D,B);null==G||G.resetRequestCache(),globalThis.__incrementalCache=G;let V={params:b,previewProps:D.preview,renderOpts:{experimental:{authInterrupts:!!S.experimental.authInterrupts},cacheComponents:!!S.cacheComponents,supportsDynamicResponse:q,incrementalCache:G,cacheLifeProfiles:S.cacheLife,waitUntil:a.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,a,n)=>k.onRequestError(e,t,a,n,C)},sharedContext:{buildId:E,deploymentId:y}},W=new l.NodeNextRequest(e),X=new l.NodeNextResponse(t),Y=c.NextRequestAdapter.fromNodeNextRequest(W,(0,c.signalFromNodeResponse)(t));try{let n,i=async e=>k.handle(Y,V).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=j.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==u.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${r.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let a=r.get("next.route");if(a){let t=`${M} ${a}`;e.setAttributes({"next.route":a,"http.route":a,"next.span_name":t}),e.updateName(t),n&&n!==e&&(n.setAttribute("http.route",a),n.updateName(t))}else e.updateName(`${M} ${R}`)}),o=async n=>{var s,o;let l=async({previousCacheEntry:r})=>{try{if(!B&&T&&O&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let s=await i(n);e.fetchMetrics=V.renderOpts.fetchMetrics;let o=V.renderOpts.pendingWaitUntil;o&&a.waitUntil&&(a.waitUntil(o),o=void 0);let l=V.renderOpts.collectedTags;if(!U)return await (0,p.sendResponse)(W,X,s,V.renderOpts.pendingWaitUntil),null;{let e=await s.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(s.headers);l&&(t[f.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==V.renderOpts.collectedRevalidate&&!(V.renderOpts.collectedRevalidate>=f.INFINITE_CACHE)&&V.renderOpts.collectedRevalidate,a=void 0===V.renderOpts.collectedExpire||V.renderOpts.collectedExpire>=f.INFINITE_CACHE?void 0:V.renderOpts.collectedExpire;return{value:{kind:g.CachedRouteKind.APP_ROUTE,status:s.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:a}}}}catch(t){throw(null==r?void 0:r.isStale)&&await k.onRequestError(e,t,{routerKind:"App Router",routePath:R,routeType:"route",revalidateReason:(0,d.getRevalidateReason)({isStaticGeneration:F,isOnDemandRevalidate:T})},!1,C),t}},c=await k.handleResponse({req:e,nextConfig:S,cacheKey:$,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:D,isRoutePPREnabled:!1,isOnDemandRevalidate:T,revalidateOnlyGenerated:O,responseGenerator:l,waitUntil:a.waitUntil,isMinimalMode:B});if(!U)return null;if((null==c||null==(s=c.value)?void 0:s.kind)!==g.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==c||null==(o=c.value)?void 0:o.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});B||t.setHeader("x-nextjs-cache",T?"REVALIDATED":c.isMiss?"MISS":c.isStale?"STALE":"HIT"),_&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let u=(0,h.fromNodeOutgoingHttpHeaders)(c.value.headers);return B&&U||u.delete(f.NEXT_CACHE_TAGS_HEADER),!c.cacheControl||t.getHeader("Cache-Control")||u.get("Cache-Control")||u.set("Cache-Control",(0,m.getCacheControlHeader)(c.cacheControl)),await (0,p.sendResponse)(W,X,new Response(c.value.body,{headers:u,status:c.value.status||200})),null};K&&H?await o(H):(n=j.getActiveScopeSpan(),await j.withPropagatedContext(e.headers,()=>j.trace(u.BaseServerSpan.handleRequest,{spanName:`${M} ${R}`,kind:s.SpanKind.SERVER,attributes:{"http.method":M,"http.target":e.url}},o),void 0,!K))}catch(t){if(t instanceof w.NoFallbackError||await k.onRequestError(e,t,{routerKind:"App Router",routePath:N,routeType:"route",revalidateReason:(0,d.getRevalidateReason)({isStaticGeneration:F,isOnDemandRevalidate:T})},!1,C),U)throw t;return await (0,p.sendResponse)(W,X,new Response(null,{status:500})),null}}e.s(["handler",0,T,"patchFetch",0,function(){return(0,a.patchFetch)({workAsyncStorage:_,workUnitAsyncStorage:D})},"routeModule",0,k,"serverHooks",0,C,"workAsyncStorage",0,_,"workUnitAsyncStorage",0,D],231344)}];
|
|
60
60
|
|
|
61
61
|
//# sourceMappingURL=%5Broot-of-the-server%5D__1ahdfq9._.js.map
|
|
@@ -241,7 +241,7 @@ const server = createServer(async (req, res) => {
|
|
|
241
241
|
<svg class="icon" viewBox="0 0 24 24"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>
|
|
242
242
|
API Reference
|
|
243
243
|
</a>
|
|
244
|
-
<a href="https://github.com/Larkup-AI/larkup
|
|
244
|
+
<a href="https://github.com/Larkup-AI/larkup" target="_blank" rel="noopener" class="btn btn-outline">
|
|
245
245
|
<svg class="icon" viewBox="0 0 24 24"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
|
|
246
246
|
Larkup Team
|
|
247
247
|
</a>
|
|
@@ -250,7 +250,7 @@ const server = createServer(async (req, res) => {
|
|
|
250
250
|
Contact
|
|
251
251
|
</a>
|
|
252
252
|
</div>
|
|
253
|
-
<div class="footer">Built with <a href="https://github.com/Larkup-AI/larkup
|
|
253
|
+
<div class="footer">Built with <a href="https://github.com/Larkup-AI/larkup/buddy-rag" target="_blank" rel="noopener">larkup</a> \xb7 v1.0</div>
|
|
254
254
|
</div>
|
|
255
255
|
</body>
|
|
256
256
|
</html>\`)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module.exports=[612069,e=>{"use strict";var a=e.i(902157),t=e.i(750227);let o=process.env.LARKUP_HUB_URL??"https://hub.larkup.de",i=null;async function n(){let e={};for(let o of[t.default.resolve(process.cwd(),"packages","tools"),t.default.resolve(process.cwd(),"..","..","packages","tools"),t.default.resolve(process.cwd(),".larkup","tools","node_modules","@larkup"),t.default.resolve(process.cwd(),"..","..",".larkup","tools","node_modules","@larkup")])try{for(let i of(await a.promises.readdir(o,{withFileTypes:!0}))){if(!i.isDirectory())continue;let n=t.default.join(o,i.name,"tool.manifest.json");try{let t=await a.promises.readFile(n,"utf8"),o=JSON.parse(t);o.id&&(e[o.id]=o)}catch{}}}catch{}return e}async function r(e){try{let a=new AbortController,t=setTimeout(()=>a.abort(),5e3),i=await fetch(`${e??o}/v1/tools`,{signal:a.signal,headers:{Accept:"application/json"}});if(clearTimeout(t),!i.ok)return{};let n=await i.json(),r={};for(let e of n.tools??[])e.id&&(r[e.id]=e);return r}catch{return{}}}let s={"video-audio":{id:"video-audio",name:"Video & Audio",description:"Index video and audio files with transcription and frame analysis.",category:"media",version:"0.2.1",pricing:"free",emoji:"🎬",icon:"Film",packageName:"@larkup/tool-video-audio",installSize:"~15 MB",systemDeps:["ffmpeg"],author:"Larkup",capabilities:["video-indexing","audio-indexing","transcription","frame-extraction","youtube-import"],tags:["transcription","ffmpeg","video","audio","whisper"],downloads:0,repositoryUrl:"https://github.com/Larkup-AI/larkup-rag",license:"Apache-2.0",updatedAt:"2026-07-20",configSchema:[{key:"frameInterval",label:"Frame extraction interval (seconds)",type:"text",defaultValue:"10",help:"Baseline cadence for duration-aware coverage frames; scene changes and a reserved ending pass are added separately."},{key:"audioProvider",label:"Audio Provider",type:"select",help:"Choose the provider used only for audio and video transcription.",options:[{label:"OpenAI",value:"openai"},{label:"Groq",value:"groq"},{label:"Deepgram",value:"deepgram"},{label:"ElevenLabs",value:"elevenlabs"},{label:"Local Whisper",value:"local"}]},{key:"audioLanguage",label:"Transcription language",type:"text",defaultValue:"auto",help:"Use auto to infer Arabic from the media title and use provider detection otherwise. Enter a language code such as ar, ar-EG, en, or de to override it."},{key:"audioApiKey",label:"Audio API Key",type:"password",help:"Required for the selected audio provider and kept separate from the chat model key."}]},"clip-embeddings":{id:"clip-embeddings",name:"CLIP Image Search",description:"Direct image-to-image similarity search using CLIP/SigLIP embeddings.",category:"embedding",version:"0.1.0",pricing:"free",emoji:"🔍",icon:"ScanEye",packageName:"@larkup/tool-clip-embeddings",installSize:"~200 MB",author:"Larkup",capabilities:["clip-embeddings","image-similarity"],tags:["clip","siglip","image-search","visual-similarity"],downloads:0,repositoryUrl:"https://github.com/Larkup-AI/larkup-rag",license:"Apache-2.0",updatedAt:"2026-07-20",comingSoon:!0},"doc-editor":{id:"doc-editor",name:"Document Editor",description:"AI-powered form filling and document editing with Canvas-style live preview.",category:"utility",version:"0.2.3",pricing:"free",emoji:"📝",icon:"FileEdit",packageName:"@larkup/tool-doc-editor",installSize:"~5 MB",systemDeps:["docker"],author:"Larkup",capabilities:["document-editing","form-filling","document-preview"],tags:["pdf","docx","pptx","form","canvas","editor","fill"],downloads:0,repositoryUrl:"https://github.com/Larkup-AI/larkup-rag",license:"Apache-2.0",updatedAt:"2026-07-20"}};async function l(e){if(i)return i;let a={...s};return Object.assign(a,await n()),e?.skipHub||Object.assign(a,await r(e?.hubUrl)),i=a,a}async function c(){return Object.values(await l()).sort((e,a)=>e.name.localeCompare(a.name))}async function d(e){return(await l())[e]}async function u(e){return(await c()).filter(a=>a.capabilities.includes(e))}e.s(["getAllTools",0,c,"getToolById",0,d,"getToolsWithCapability",0,u,"invalidateRegistryCache",0,function(){i=null}],612069)},463857,e=>{"use strict";var a=e.i(902157),t=e.i(750227),o=e.i(874533),i=e.i(812057),n=e.i(612069);let r=(0,i.promisify)(o.exec);function s(){return t.default.join(process.cwd(),".larkup","tools")}function l(){return t.default.join(s(),"installed.json")}async function c(){await a.promises.mkdir(s(),{recursive:!0})}async function d(){try{let e=await a.promises.readFile(l(),"utf8"),t=JSON.parse(e);for(let e of(t.downloadCounts||(t.downloadCounts={}),t.tools??[]))e.packagePath&&!e.packageName&&(e.packageName=e.packagePath,delete e.packagePath),e.source||(e.source="local"),e.resolvedPath||(e.resolvedPath=e.packageName);return t}catch{return{tools:[],downloadCounts:{},updatedAt:new Date().toISOString()}}}async function u(e){await c(),e.updatedAt=new Date().toISOString(),await a.promises.writeFile(l(),JSON.stringify(e,null,2),"utf8")}async function p(){let e=[...(await d()).tools];for(let a of(process.env.LARKUP_BUNDLED_TOOLS??"").split(",").map(e=>e.trim()).filter(Boolean)){if(e.some(e=>e.id===a))continue;let t=await (0,n.getToolById)(a);t&&e.push({id:a,version:t.version,installedAt:"bundled",packageName:t.packageName,resolvedPath:t.packageName,source:"local",config:I(t)})}return e}async function f(e){return(await p()).some(a=>a.id===e)}async function m(e){return(await p()).find(a=>a.id===e)}async function g(){return(await d()).downloadCounts}async function w(e){let a=await (0,n.getToolById)(e);if(!a?.systemDeps?.length)return[];let t=h(),o=[];for(let e of a.systemDeps)if("docker"!==t||"docker"!==e)try{await r(`which ${e}`)}catch{o.push(e)}return o}function h(){let a=process.env.LARKUP_DEPLOYMENT_TARGET;return a&&["local","docker","serverless","sandbox"].includes(a)?a:process.env.VERCEL||process.env.AWS_LAMBDA_FUNCTION_NAME?"serverless":process.env.DOCKER_CONTAINER||function(){try{return e.r(902157).existsSync("/.dockerenv")}catch{return!1}}()?"docker":process.env.E2B_SANDBOX_ID||process.env.MODAL_TASK_ID?"sandbox":"local"}async function y(){let e=s(),o=t.default.join(e,"package.json");try{await a.promises.access(o)}catch{await c(),await a.promises.writeFile(o,JSON.stringify({name:"larkup-tools",version:"1.0.0",private:!0,description:"Isolated directory for installed Larkup marketplace tools."},null,2),"utf8")}}async function v(e,o,i,n){let l=s();switch(i){case"local":case"docker":{await y();let s=async e=>{let a=`npm install ${e} --prefix "${l}" --save --no-audit --no-fund`;n?.(`Running: npm install ${e}`);let{stderr:o}=await r(a,{cwd:l,timeout:"docker"===i?3e5:12e4,env:{...process.env,NODE_ENV:"production",HOME:process.env.HOME&&"/nonexistent"!==process.env.HOME?process.env.HOME:l,npm_config_cache:t.default.join(l,".npm-cache"),npm_config_update_notifier:"false"}});o&&!o.includes("npm warn")&&console.warn(`[marketplace] Install stderr: ${o}`)};try{await s(`${e}@${o}`)}catch(t){let a=t instanceof Error?t.message:"Install command failed";if(!a.includes("ETARGET")&&!a.includes("No matching version found"))throw Error(`Failed to install ${e}: ${a}`);n?.(`Catalog version ${o} is unavailable; installing the latest published version…`);try{await s(`${e}@latest`)}catch(t){let a=t instanceof Error?t.message:"Install command failed";throw Error(`Failed to install ${e}: ${a}`)}}let c=t.default.join(l,"node_modules",e);try{await a.promises.access(c)}catch{throw Error(`Package ${e} was installed but could not be found at ${c}`)}let d=JSON.parse(await a.promises.readFile(t.default.join(c,"package.json"),"utf8"));return{resolvedPath:c,version:d.version??o}}case"serverless":{n?.("Serverless environment detected — queuing for next deploy");let i=t.default.join(l,"pending-tools.json"),r={tools:[]};try{let e=await a.promises.readFile(i,"utf8");r=JSON.parse(e)}catch{}return r.tools.push({packageName:e,version:o}),await c(),await a.promises.writeFile(i,JSON.stringify(r,null,2),"utf8"),{resolvedPath:t.default.join(l,"node_modules",e),version:o}}case"sandbox":{n?.("Installing in sandbox environment"),await y();let a=`npm install ${e}@${o} --prefix "${l}" --save --no-audit --no-fund`;return await r(a,{cwd:l,timeout:12e4}),{resolvedPath:t.default.join(l,"node_modules",e),version:o}}default:throw Error(`Unsupported deployment target: ${i}`)}}async function k(e){let a=await (0,n.getToolById)(e);if(a)return a;throw Error(`Unknown tool: ${e}. Not found in local registry or Hub.`)}async function b(e){try{let{stdout:a}=await r("pnpm ls -r --depth -1 --json 2>/dev/null || true",{cwd:process.cwd(),timeout:1e4}),t=JSON.parse(a||"[]");return Array.isArray(t)&&t.some(a=>a.name===e)}catch{return!1}}async function A(e,a){let o=(t,o,i)=>{a?.({toolId:e,stage:t,percent:o,message:i})};try{let a,i;o("checking-deps",5,"Resolving tool manifest…");let r=await k(e);if(r.comingSoon)throw Error(`${r.name} is coming soon.`);o("checking-deps",15,"Checking system dependencies…");let s=await w(e);if(s.length>0){let e=`Missing system dependencies: ${s.join(", ")}. Please install them first.`;throw o("failed",0,e),Error(e)}let l=await b(r.packageName),p=h(),f=r.version;if(l){o("downloading",30,"Resolving workspace package…");try{let e=(()=>{let e=Error("Cannot find module as expression is too dynamic");throw e.code="MODULE_NOT_FOUND",e})();a=t.default.dirname(e)}catch{a=t.default.join(process.cwd(),"node_modules",r.packageName)}i="local",o("installing",60,"Workspace package resolved.")}else{o("downloading",30,`Downloading ${r.packageName}@${r.version}…`);let e=await v(r.packageName,r.version,p,e=>o("downloading",50,e));a=e.resolvedPath,f=e.version,i="sandbox"===p?"sandbox":"registry",o("installing",70,"Package installed.")}o("installing",80,"Registering tool…"),await c();let m=await d(),g=m.tools.findIndex(a=>a.id===e),y={id:e,version:f,installedAt:new Date().toISOString(),packageName:r.packageName,resolvedPath:a,source:i,config:I(r)};g>=0?m.tools[g]=y:m.tools.push(y),m.downloadCounts[e]=(m.downloadCounts[e]??0)+1,await u(m),E(e).catch(()=>{}),(0,n.invalidateRegistryCache)(),o("completed",100,"Installed successfully.")}catch(e){throw o("failed",0,e instanceof Error?e.message:"Installation failed."),e}}async function N(a){let t=await d(),o=t.tools.find(e=>e.id===a);if(t.tools=t.tools.filter(e=>e.id!==a),await u(t),o?.source==="registry"&&o.packageName)try{let e=s();await r(`npm uninstall ${o.packageName} --prefix "${e}"`,{cwd:e,timeout:3e4})}catch{}(0,n.invalidateRegistryCache)();let{unloadTool:i}=await e.A(484620);i(a)}async function E(e){let a=process.env.LARKUP_HUB_URL??"https://hub.larkup.de";try{let t=new AbortController,o=setTimeout(()=>t.abort(),3e3);await fetch(`${a}/v1/tools/${e}/installed`,{method:"POST",signal:t.signal,headers:{"Content-Type":"application/json"}}),clearTimeout(o)}catch{}}function I(e){let a={};for(let t of e.configSchema??[])void 0!==t.defaultValue&&(a[t.key]=t.defaultValue);return a}e.s(["getDownloadCounts",0,g,"getInstalledTool",0,m,"getInstalledTools",0,p,"installTool",0,A,"isToolInstalled",0,f,"uninstallTool",0,N])}];
|
|
1
|
+
module.exports=[612069,e=>{"use strict";var a=e.i(902157),t=e.i(750227);let o=process.env.LARKUP_HUB_URL??"https://hub.larkup.de",i=null;async function n(){let e={};for(let o of[t.default.resolve(process.cwd(),"packages","tools"),t.default.resolve(process.cwd(),"..","..","packages","tools"),t.default.resolve(process.cwd(),".larkup","tools","node_modules","@larkup"),t.default.resolve(process.cwd(),"..","..",".larkup","tools","node_modules","@larkup")])try{for(let i of(await a.promises.readdir(o,{withFileTypes:!0}))){if(!i.isDirectory())continue;let n=t.default.join(o,i.name,"tool.manifest.json");try{let t=await a.promises.readFile(n,"utf8"),o=JSON.parse(t);o.id&&(e[o.id]=o)}catch{}}}catch{}return e}async function r(e){try{let a=new AbortController,t=setTimeout(()=>a.abort(),5e3),i=await fetch(`${e??o}/v1/tools`,{signal:a.signal,headers:{Accept:"application/json"}});if(clearTimeout(t),!i.ok)return{};let n=await i.json(),r={};for(let e of n.tools??[])e.id&&(r[e.id]=e);return r}catch{return{}}}let s={"video-audio":{id:"video-audio",name:"Video & Audio",description:"Index video and audio files with transcription and frame analysis.",category:"media",version:"0.2.1",pricing:"free",emoji:"🎬",icon:"Film",packageName:"@larkup/tool-video-audio",installSize:"~15 MB",systemDeps:["ffmpeg"],author:"Larkup",capabilities:["video-indexing","audio-indexing","transcription","frame-extraction","youtube-import"],tags:["transcription","ffmpeg","video","audio","whisper"],downloads:0,repositoryUrl:"https://github.com/Larkup-AI/larkup",license:"Apache-2.0",updatedAt:"2026-07-20",configSchema:[{key:"frameInterval",label:"Frame extraction interval (seconds)",type:"text",defaultValue:"10",help:"Baseline cadence for duration-aware coverage frames; scene changes and a reserved ending pass are added separately."},{key:"audioProvider",label:"Audio Provider",type:"select",help:"Choose the provider used only for audio and video transcription.",options:[{label:"OpenAI",value:"openai"},{label:"Groq",value:"groq"},{label:"Deepgram",value:"deepgram"},{label:"ElevenLabs",value:"elevenlabs"},{label:"Local Whisper",value:"local"}]},{key:"audioLanguage",label:"Transcription language",type:"text",defaultValue:"auto",help:"Use auto to infer Arabic from the media title and use provider detection otherwise. Enter a language code such as ar, ar-EG, en, or de to override it."},{key:"audioApiKey",label:"Audio API Key",type:"password",help:"Required for the selected audio provider and kept separate from the chat model key."}]},"clip-embeddings":{id:"clip-embeddings",name:"CLIP Image Search",description:"Direct image-to-image similarity search using CLIP/SigLIP embeddings.",category:"embedding",version:"0.1.0",pricing:"free",emoji:"🔍",icon:"ScanEye",packageName:"@larkup/tool-clip-embeddings",installSize:"~200 MB",author:"Larkup",capabilities:["clip-embeddings","image-similarity"],tags:["clip","siglip","image-search","visual-similarity"],downloads:0,repositoryUrl:"https://github.com/Larkup-AI/larkup",license:"Apache-2.0",updatedAt:"2026-07-20",comingSoon:!0},"doc-editor":{id:"doc-editor",name:"Document Editor",description:"AI-powered form filling and document editing with Canvas-style live preview.",category:"utility",version:"0.2.3",pricing:"free",emoji:"📝",icon:"FileEdit",packageName:"@larkup/tool-doc-editor",installSize:"~5 MB",systemDeps:["docker"],author:"Larkup",capabilities:["document-editing","form-filling","document-preview"],tags:["pdf","docx","pptx","form","canvas","editor","fill"],downloads:0,repositoryUrl:"https://github.com/Larkup-AI/larkup",license:"Apache-2.0",updatedAt:"2026-07-20"}};async function l(e){if(i)return i;let a={...s};return Object.assign(a,await n()),e?.skipHub||Object.assign(a,await r(e?.hubUrl)),i=a,a}async function c(){return Object.values(await l()).sort((e,a)=>e.name.localeCompare(a.name))}async function d(e){return(await l())[e]}async function u(e){return(await c()).filter(a=>a.capabilities.includes(e))}e.s(["getAllTools",0,c,"getToolById",0,d,"getToolsWithCapability",0,u,"invalidateRegistryCache",0,function(){i=null}],612069)},463857,e=>{"use strict";var a=e.i(902157),t=e.i(750227),o=e.i(874533),i=e.i(812057),n=e.i(612069);let r=(0,i.promisify)(o.exec);function s(){return t.default.join(process.cwd(),".larkup","tools")}function l(){return t.default.join(s(),"installed.json")}async function c(){await a.promises.mkdir(s(),{recursive:!0})}async function d(){try{let e=await a.promises.readFile(l(),"utf8"),t=JSON.parse(e);for(let e of(t.downloadCounts||(t.downloadCounts={}),t.tools??[]))e.packagePath&&!e.packageName&&(e.packageName=e.packagePath,delete e.packagePath),e.source||(e.source="local"),e.resolvedPath||(e.resolvedPath=e.packageName);return t}catch{return{tools:[],downloadCounts:{},updatedAt:new Date().toISOString()}}}async function u(e){await c(),e.updatedAt=new Date().toISOString(),await a.promises.writeFile(l(),JSON.stringify(e,null,2),"utf8")}async function p(){let e=[...(await d()).tools];for(let a of(process.env.LARKUP_BUNDLED_TOOLS??"").split(",").map(e=>e.trim()).filter(Boolean)){if(e.some(e=>e.id===a))continue;let t=await (0,n.getToolById)(a);t&&e.push({id:a,version:t.version,installedAt:"bundled",packageName:t.packageName,resolvedPath:t.packageName,source:"local",config:I(t)})}return e}async function f(e){return(await p()).some(a=>a.id===e)}async function m(e){return(await p()).find(a=>a.id===e)}async function g(){return(await d()).downloadCounts}async function w(e){let a=await (0,n.getToolById)(e);if(!a?.systemDeps?.length)return[];let t=h(),o=[];for(let e of a.systemDeps)if("docker"!==t||"docker"!==e)try{await r(`which ${e}`)}catch{o.push(e)}return o}function h(){let a=process.env.LARKUP_DEPLOYMENT_TARGET;return a&&["local","docker","serverless","sandbox"].includes(a)?a:process.env.VERCEL||process.env.AWS_LAMBDA_FUNCTION_NAME?"serverless":process.env.DOCKER_CONTAINER||function(){try{return e.r(902157).existsSync("/.dockerenv")}catch{return!1}}()?"docker":process.env.E2B_SANDBOX_ID||process.env.MODAL_TASK_ID?"sandbox":"local"}async function y(){let e=s(),o=t.default.join(e,"package.json");try{await a.promises.access(o)}catch{await c(),await a.promises.writeFile(o,JSON.stringify({name:"larkup-tools",version:"1.0.0",private:!0,description:"Isolated directory for installed Larkup marketplace tools."},null,2),"utf8")}}async function v(e,o,i,n){let l=s();switch(i){case"local":case"docker":{await y();let s=async e=>{let a=`npm install ${e} --prefix "${l}" --save --no-audit --no-fund --prefer-offline`;n?.(`Running: npm install ${e}`);let{stderr:o}=await r(a,{cwd:l,timeout:"docker"===i?3e5:12e4,env:{...process.env,NODE_ENV:"production",HOME:process.env.HOME&&"/nonexistent"!==process.env.HOME?process.env.HOME:l,npm_config_cache:t.default.join(l,".npm-cache"),npm_config_update_notifier:"false"}});o&&!o.includes("npm warn")&&console.warn(`[marketplace] Install stderr: ${o}`)};try{await s(`${e}@${o}`)}catch(t){let a=t instanceof Error?t.message:"Install command failed";if(!a.includes("ETARGET")&&!a.includes("No matching version found"))throw Error(`Failed to install ${e}: ${a}`);n?.(`Catalog version ${o} is unavailable; installing the latest published version…`);try{await s(`${e}@latest`)}catch(t){let a=t instanceof Error?t.message:"Install command failed";throw Error(`Failed to install ${e}: ${a}`)}}let c=t.default.join(l,"node_modules",e);try{await a.promises.access(c)}catch{throw Error(`Package ${e} was installed but could not be found at ${c}`)}let d=JSON.parse(await a.promises.readFile(t.default.join(c,"package.json"),"utf8"));return{resolvedPath:c,version:d.version??o}}case"serverless":{n?.("Serverless environment detected — queuing for next deploy");let i=t.default.join(l,"pending-tools.json"),r={tools:[]};try{let e=await a.promises.readFile(i,"utf8");r=JSON.parse(e)}catch{}return r.tools.push({packageName:e,version:o}),await c(),await a.promises.writeFile(i,JSON.stringify(r,null,2),"utf8"),{resolvedPath:t.default.join(l,"node_modules",e),version:o}}case"sandbox":{n?.("Installing in sandbox environment"),await y();let a=`npm install ${e}@${o} --prefix "${l}" --save --no-audit --no-fund`;return await r(a,{cwd:l,timeout:12e4}),{resolvedPath:t.default.join(l,"node_modules",e),version:o}}default:throw Error(`Unsupported deployment target: ${i}`)}}async function k(e){let a=await (0,n.getToolById)(e);if(a)return a;throw Error(`Unknown tool: ${e}. Not found in local registry or Hub.`)}async function b(e){try{let{stdout:a}=await r("pnpm ls -r --depth -1 --json 2>/dev/null || true",{cwd:process.cwd(),timeout:1e4}),t=JSON.parse(a||"[]");return Array.isArray(t)&&t.some(a=>a.name===e)}catch{return!1}}async function A(e,a){let o=(t,o,i)=>{a?.({toolId:e,stage:t,percent:o,message:i})};try{let a,i;o("checking-deps",5,"Resolving tool manifest…");let r=await k(e);if(r.comingSoon)throw Error(`${r.name} is coming soon.`);o("checking-deps",15,"Checking system dependencies…");let s=await w(e);if(s.length>0){let e=`Missing system dependencies: ${s.join(", ")}. Please install them first.`;throw o("failed",0,e),Error(e)}let l=await b(r.packageName),p=h(),f=r.version;if(l){o("downloading",30,"Resolving workspace package…");try{let e=(()=>{let e=Error("Cannot find module as expression is too dynamic");throw e.code="MODULE_NOT_FOUND",e})();a=t.default.dirname(e)}catch{a=t.default.join(process.cwd(),"node_modules",r.packageName)}i="local",o("installing",60,"Workspace package resolved.")}else{o("downloading",30,`Downloading ${r.packageName}@${r.version}…`);let e=await v(r.packageName,r.version,p,e=>o("downloading",50,e));a=e.resolvedPath,f=e.version,i="sandbox"===p?"sandbox":"registry",o("installing",70,"Package installed.")}o("installing",80,"Registering tool…"),await c();let m=await d(),g=m.tools.findIndex(a=>a.id===e),y={id:e,version:f,installedAt:new Date().toISOString(),packageName:r.packageName,resolvedPath:a,source:i,config:I(r)};g>=0?m.tools[g]=y:m.tools.push(y),m.downloadCounts[e]=(m.downloadCounts[e]??0)+1,await u(m),E(e).catch(()=>{}),(0,n.invalidateRegistryCache)(),o("completed",100,"Installed successfully.")}catch(e){throw o("failed",0,e instanceof Error?e.message:"Installation failed."),e}}async function N(a){let t=await d(),o=t.tools.find(e=>e.id===a);if(t.tools=t.tools.filter(e=>e.id!==a),await u(t),o?.source==="registry"&&o.packageName)try{let e=s();await r(`npm uninstall ${o.packageName} --prefix "${e}"`,{cwd:e,timeout:3e4})}catch{}(0,n.invalidateRegistryCache)();let{unloadTool:i}=await e.A(484620);i(a)}async function E(e){let a=process.env.LARKUP_HUB_URL??"https://hub.larkup.de";try{let t=new AbortController,o=setTimeout(()=>t.abort(),3e3);await fetch(`${a}/v1/tools/${e}/installed`,{method:"POST",signal:t.signal,headers:{"Content-Type":"application/json"}}),clearTimeout(o)}catch{}}function I(e){let a={};for(let t of e.configSchema??[])void 0!==t.defaultValue&&(a[t.key]=t.defaultValue);return a}e.s(["getDownloadCounts",0,g,"getInstalledTool",0,m,"getInstalledTools",0,p,"installTool",0,A,"isToolInstalled",0,f,"uninstallTool",0,N])}];
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=packages_marketplace_src_125_g2p._.js.map
|