@geoffai/geoff 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @geoffai/geoff
2
+
3
+ SDK for connecting to GeoffNet.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @geoffai/geoff
9
+ ```
@@ -0,0 +1,4 @@
1
+ 'use strict';var l="http://localhost:3000";var p="https://geoffnet.magma-rpc.com";var c={"Content-Type":"application/json"};var f=class{baseUrl;apiKey;timeout;constructor(e={}){this.baseUrl=(e.baseUrl||l).replace(/\/$/,""),this.apiKey=e.apiKey,this.timeout=e.timeout||6e4;}async*chatCompletions(e){let t=e.messages.filter(n=>n.role==="user"),s=t[t.length-1]?.content||"",o=await this.submitTask({type:"ai-prompt",model:e.model,prompt:s,sessionId:e.sessionId,temperature:e.temperature,maxTokens:e.max_tokens,stream:true});yield*this.streamTaskResults(o,e.model);}async submitTask(e){let t=await fetch(`${this.baseUrl}/tasks`,{method:"POST",headers:{"Content-Type":"application/json",...this.apiKey&&{Authorization:`Bearer ${this.apiKey}`}},body:JSON.stringify(e)});if(!t.ok){let o=await t.text();throw new Error(`Task submission failed: ${o}`)}return (await t.json()).taskId}async getTask(e){let t=await fetch(`${this.baseUrl}/tasks/${e}`,{headers:{...this.apiKey&&{Authorization:`Bearer ${this.apiKey}`}}});if(!t.ok)throw new Error(`Failed to get task: ${t.statusText}`);return t.json()}async*streamTaskResults(e,t){let s=await fetch(`${this.baseUrl}/tasks/${e}/stream`,{headers:{...this.apiKey&&{Authorization:`Bearer ${this.apiKey}`}}});if(!s.ok)throw new Error(`Stream failed: ${s.statusText}`);if(!s.body)throw new Error("Response body is null");let o=s.body.getReader(),n=new TextDecoder,a="",d="",u=Math.floor(Date.now()/1e3);try{for(;;){let{done:h,value:K}=await o.read();if(h){yield {id:e,object:"chat.completion.chunk",created:u,model:t,choices:[{index:0,delta:{},finish_reason:"stop"}]};break}a+=n.decode(K,{stream:!0});let R=a.split(`
2
+ `);a=R.pop()||"";for(let _ of R)if(_.startsWith("data: "))try{let T=JSON.parse(_.slice(6));if(Array.isArray(T)&&T.length>0){let m=T[0].result||"";if(m&&m!==d){let F=m.substring(d.length);d=m,F&&(yield {id:e,object:"chat.completion.chunk",created:u,model:t,choices:[{index:0,delta:{role:"assistant",content:F},finish_reason:null}]});}}}catch{}}}finally{o.releaseLock();}}async*streamTaskRaw(e){let t=await fetch(`${this.baseUrl}/tasks/${e}/stream`,{headers:{...this.apiKey&&{Authorization:`Bearer ${this.apiKey}`}}});if(!t.ok)throw new Error(`Stream failed: ${t.statusText}`);if(!t.body)throw new Error("Response body is null");let s=t.body.getReader(),o=new TextDecoder,n="";try{for(;;){let{done:a,value:d}=await s.read();if(a)break;n+=o.decode(d,{stream:!0});let u=n.split(`
3
+ `);n=u.pop()||"";for(let h of u)if(h.startsWith("data: "))try{yield JSON.parse(h.slice(6));}catch{}}}finally{s.releaseLock();}}async healthCheck(){try{return (await fetch(`${this.baseUrl}/health`)).ok}catch{return false}}async getNode(){let e=await fetch(`${this.baseUrl}/node`);if(!e.ok)throw new Error(`Failed to get node info: ${e.statusText}`);return e.json()}};function E(i){return new f(i)}var B=E();async function A(i){let e=await crypto.subtle.digest("SHA-256",i);return `baf${Array.from(new Uint8Array(e)).map(o=>o.toString(16).padStart(2,"0")).join("").substring(0,52)}`}var g=class{baseUrl;localServerUrl;constructor(e={}){this.baseUrl=e.baseUrl||p,this.localServerUrl=e.localServerUrl||l;}async uploadFile(e){let t=await e.arrayBuffer(),s=await A(t),o=this.arrayBufferToBase64(t);return typeof localStorage<"u"&&localStorage.setItem(`file:${s}`,JSON.stringify({cid:s,name:e.name,type:e.type,size:e.size,data:o})),{cid:s,name:e.name,size:e.size,type:e.type,url:`data:${e.type};base64,${o}`}}async uploadText(e,t){let s=new Blob([e],{type:"text/plain"}),o=new File([s],t,{type:"text/plain"});return this.uploadFile(o)}async storeImagination(e){let t=e.createdBy||"anonymous",o=(await fetch(`${this.localServerUrl}/imaginations/${e.id}`)).ok,n={id:e.id,title:e.title,sources:e.sources,summary:e.summary,character:e.character,workflow:e.workflow,is_public:e.is_public||false,creator_mid:t};if(o){let a=await fetch(`${this.localServerUrl}/imaginations/${e.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!a.ok)throw new Error(`Failed to update imagination: ${a.statusText}`);return typeof localStorage<"u"&&localStorage.setItem(`imagination:${e.id}`,e.id),e.id}else {let a=await fetch(`${this.localServerUrl}/imaginations`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!a.ok)throw new Error(`Failed to store imagination: ${a.statusText}`);let u=(await a.json()).imagination?.id||e.id;return typeof localStorage<"u"&&localStorage.setItem(`imagination:${u}`,u),u}}async getImagination(e){try{let t=await fetch(`${this.localServerUrl}/imaginations/${e}`);if(!t.ok)return null;let s=await t.json();return s.imagination?{id:s.imagination.id,title:s.imagination.title,createdAt:new Date(s.imagination.created_at).toISOString(),createdBy:s.imagination.creator_mid,sources:s.imagination.sources,summary:s.imagination.summary,character:s.imagination.character,workflow:s.imagination.workflow,is_public:s.imagination.is_public}:null}catch(t){return console.error("Failed to retrieve imagination:",t),null}}async getImaginationByCID(e){try{let t=await fetch(`${this.baseUrl}/files/${e}`);if(!t.ok)return null;let s=await t.json();return typeof localStorage<"u"&&localStorage.setItem(`imagination:${s.id}`,e),s}catch(t){return console.error("Failed to retrieve imagination by CID:",t),null}}async listImaginations(e){try{let t=e||"anonymous",s=await fetch(`${this.localServerUrl}/imaginations?creator_mid=${encodeURIComponent(t)}`);if(!s.ok)return console.warn("Failed to fetch imaginations from P2P, falling back to localStorage"),this.listImaginationsFromLocalStorage();let n=(await s.json()).imaginations.map(a=>({id:a.id,title:a.title,createdAt:new Date(a.created_at).toISOString(),createdBy:a.creator_mid,sources:a.sources,summary:a.summary,character:a.character,workflow:a.workflow,is_public:a.is_public}));return typeof localStorage<"u"&&n.forEach(a=>{localStorage.setItem(`imagination:${a.id}`,a.id);}),n}catch(t){return console.error("Failed to list imaginations:",t),this.listImaginationsFromLocalStorage()}}async listImaginationsFromLocalStorage(){if(typeof localStorage>"u")return [];let e=[];for(let t=0;t<localStorage.length;t++){let s=localStorage.key(t);if(s&&s.startsWith("imagination:")){let o=s.replace("imagination:",""),n=await this.getImagination(o);n&&e.push(n);}}return e}async getFile(e){try{let t=await fetch(`${this.baseUrl}/files/${e}`);return t.ok?await t.blob():null}catch(t){return console.error("Failed to retrieve file:",t),null}}arrayBufferToBase64(e){let t=new Uint8Array(e),s="";for(let o=0;o<t.length;o++)s+=String.fromCharCode(t[o]);return btoa(s)}};function j(i){return new g(i)}var G=j();var y=class{baseUrl;timeout;sessions=new Map;constructor(e={}){this.baseUrl=e.baseUrl||"http://localhost:3006",this.timeout=e.timeout||3e4;}async createSession(e="default"){let t=`session_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;try{let s={id:t,agentId:e,status:"active",createdAt:new Date};this.sessions.set(t,s);try{await fetch(`${this.baseUrl}/mcp/sessions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t,agentId:e,clientInfo:{name:"geoffai-sdk",version:"0.1.0"}})});}catch{}return s}catch(s){throw new Error(`Failed to create MCP session: ${s}`)}}getSession(e){return this.sessions.get(e)}async closeSession(e){let t=this.sessions.get(e);if(t){t.status="closed";try{await fetch(`${this.baseUrl}/mcp/sessions/${e}`,{method:"DELETE"});}catch{}this.sessions.delete(e);}}async sendMessage(e,t){let s=this.sessions.get(e);if(!s||s.status!=="active")throw new Error("Invalid or inactive session");try{let o=await fetch(`${this.baseUrl}/mcp/sessions/${e}/messages`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:[{role:"user",content:{type:"text",text:t}}]})});if(!o.ok)throw new Error(`MCP request failed: ${o.statusText}`);return o.json()}catch(o){throw new Error(`Failed to send message: ${o}`)}}async callTool(e,t,s={}){let o=this.sessions.get(e);if(!o||o.status!=="active")throw new Error("Invalid or inactive session");try{let n=await fetch(`${this.baseUrl}/mcp/sessions/${e}/tools/${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!n.ok)throw new Error(`Tool call failed: ${n.statusText}`);return n.json()}catch(n){throw new Error(`Failed to call tool: ${n}`)}}async listTools(e){let t=this.sessions.get(e);if(!t||t.status!=="active")throw new Error("Invalid or inactive session");try{let s=await fetch(`${this.baseUrl}/mcp/sessions/${e}/tools`);return s.ok?(await s.json()).tools||[]:[]}catch{return []}}getActiveSessions(){return Array.from(this.sessions.values()).filter(e=>e.status==="active")}async closeAllSessions(){let e=Array.from(this.sessions.keys());await Promise.all(e.map(t=>this.closeSession(t)));}};function v(i){return new y(i)}var H=v();var Y={database:"log",chat:"response",auth:"response",stream:"response",api:"response",history:"response",vote:"response",document:"response",suggestions:"response",task:"response",agent:"response",imagination:"response"},r=class extends Error{type;surface;statusCode;metadata;constructor(e,t,s){super();let[o,n]=e.split(":");this.type=o,this.cause=t,this.surface=n,this.message=z(e),this.statusCode=V(this.type),this.metadata=s;}toJSON(){return {code:`${this.type}:${this.surface}`,message:this.message,cause:this.cause,statusCode:this.statusCode,...this.metadata&&{metadata:this.metadata}}}toResponse(){let e=`${this.type}:${this.surface}`,t=Y[this.surface],{message:s,cause:o,statusCode:n}=this;return t==="log"?(console.error({code:e,message:s,cause:o}),Response.json({code:"",message:"Something went wrong. Please try again later."},{status:n})):Response.json({code:e,message:s,cause:o},{status:n})}};function z(i){if(i.includes("database"))return "An error occurred while executing a database query.";switch(i){case "bad_request:api":return "The request couldn't be processed. Please check your input and try again.";case "unauthorized:auth":return "You need to sign in before continuing.";case "forbidden:auth":return "Your account does not have access to this feature.";case "rate_limit:chat":return "You have exceeded your maximum number of messages for the day. Please try again later.";case "not_found:chat":return "The requested chat was not found.";case "forbidden:chat":return "This chat belongs to another user.";case "unauthorized:chat":return "You need to sign in to view this chat.";case "offline:chat":return "We're having trouble sending your message. Please check your internet connection.";case "not_found:task":return "The requested task was not found.";case "forbidden:task":return "You do not have access to this task.";case "not_found:agent":return "The requested agent was not found.";case "forbidden:agent":return "You do not have access to this agent.";case "not_found:imagination":return "The requested imagination was not found.";case "forbidden:imagination":return "You do not have access to this imagination.";case "not_found:document":return "The requested document was not found.";case "forbidden:document":return "This document belongs to another user.";case "unauthorized:document":return "You need to sign in to view this document.";case "bad_request:document":return "The request to create or update the document was invalid.";default:return "Something went wrong. Please try again later."}}function V(i){switch(i){case "bad_request":return 400;case "unauthorized":return 401;case "payment_required":return 402;case "forbidden":return 403;case "not_found":return 404;case "rate_limit":return 429;case "offline":return 503;case "internal":return 500;default:return 500}}var w=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||l;}get socialUrl(){return `${this.baseUrl}/social`}async getFeed(e={}){let{page:t=1,limit:s=10,mediaType:o}=e,n=new URLSearchParams({page:String(t),limit:String(s)});o&&n.set("media_type",o);let a=await fetch(`${this.socialUrl}/feed?${n}`);if(!a.ok)throw new r("bad_request:api",`Failed to fetch feed: ${a.statusText}`);return a.json()}async getPost(e){let t=await fetch(`${this.socialUrl}/posts/${e}`);if(!t.ok)throw new r(t.status===404?"not_found:api":"bad_request:api",`Failed to fetch post: ${t.statusText}`);return t.json()}async getComments(e){let t=await fetch(`${this.socialUrl}/posts/${e}/comments`);if(!t.ok)throw new r("bad_request:api",`Failed to fetch comments: ${t.statusText}`);return t.json()}async getRemixes(e){let t=await fetch(`${this.socialUrl}/posts/${e}/remixes`);if(!t.ok)throw new r("bad_request:api",`Failed to fetch remixes: ${t.statusText}`);return t.json()}async checkLike(e,t){let s=await fetch(`${this.socialUrl}/posts/${e}/likes/check?userMid=${encodeURIComponent(t)}`);if(!s.ok)throw new r("bad_request:api",`Failed to check like status: ${s.statusText}`);return s.json()}async likePost(e,t){let s=await fetch(`${this.socialUrl}/like`,{method:"POST",headers:c,body:JSON.stringify({postId:e,userMid:t})});if(!s.ok)throw new r("bad_request:api",`Failed to like post: ${s.statusText}`);return s.json()}async unlikePost(e,t){let s=await fetch(`${this.socialUrl}/unlike`,{method:"POST",headers:c,body:JSON.stringify({postId:e,userMid:t})});if(!s.ok)throw new r("bad_request:api",`Failed to unlike post: ${s.statusText}`);return s.json()}async addComment(e,t,s){let o=await fetch(`${this.socialUrl}/comment`,{method:"POST",headers:c,body:JSON.stringify({postId:e,userMid:t,content:s})});if(!o.ok)throw new r("bad_request:api",`Failed to add comment: ${o.statusText}`);return o.json()}async createPost(e){let t=await fetch(`${this.socialUrl}/post`,{method:"POST",headers:c,body:JSON.stringify({userMid:e.creatorMid,content:e.content,mediaUrl:e.mediaUrl,mediaType:e.mediaType,remixOf:e.remixOf})});if(!t.ok)throw new r("bad_request:api",`Failed to create post: ${t.statusText}`);return t.json()}async trackView(e,t){await fetch(`${this.socialUrl}/posts/${e}/view`,{method:"POST",headers:c,body:JSON.stringify({userMid:t})}).catch(()=>{});}async trackPlay(e,t){await fetch(`${this.socialUrl}/posts/${e}/play`,{method:"POST",headers:c,body:JSON.stringify({userMid:t})}).catch(()=>{});}async getProfile(e){try{let t=await fetch(`${this.socialUrl}/profile/${e}`);if(!t.ok){if(t.status===404)return null;throw new r("bad_request:api",`Failed to fetch profile: ${t.statusText}`)}return t.json()}catch(t){if(t instanceof r)throw t;return null}}};function I(i={}){return new w(i)}var X=I();var C=class{baseUrl;useCpxApi;constructor(e={}){this.baseUrl=e.baseUrl||l,this.useCpxApi=e.useCpxApi!==false;}get agentsUrl(){return this.useCpxApi?`${this.baseUrl}/cpx/agent/agents`:`${this.baseUrl}/agents`}async list(e={}){let t=new URLSearchParams;e.userMid&&t.set("userMid",e.userMid);let s=t.toString(),o=`${this.agentsUrl}${s?`?${s}`:""}`,n=await fetch(o);if(!n.ok)throw new r("bad_request:api",`Failed to list agents: ${n.statusText}`);return n.json()}async get(e){let t=await fetch(`${this.agentsUrl}/${e}`);if(!t.ok)throw new r(t.status===404?"not_found:api":"bad_request:api",`Failed to get agent: ${t.statusText}`);return t.json()}async create(e){let t=await fetch(this.agentsUrl,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create agent: ${t.statusText}`)}return t.json()}async update(e,t){let s=await fetch(`${this.agentsUrl}/${e}`,{method:"PUT",headers:c,body:JSON.stringify(t)});if(!s.ok){let o=await s.json().catch(()=>({}));throw new r("bad_request:api",o.error||`Failed to update agent: ${s.statusText}`)}return s.json()}async delete(e){let t=await fetch(`${this.agentsUrl}/${e}`,{method:"DELETE"});if(!t.ok)throw new r("bad_request:api",`Failed to delete agent: ${t.statusText}`);return t.json()}async enable(e){let t=await fetch(`${this.agentsUrl}/${e}/enable`,{method:"POST"});if(!t.ok)throw new r("bad_request:api",`Failed to enable agent: ${t.statusText}`);return t.json()}async disable(e){let t=await fetch(`${this.agentsUrl}/${e}/disable`,{method:"POST"});if(!t.ok)throw new r("bad_request:api",`Failed to disable agent: ${t.statusText}`);return t.json()}async execute(e,t={}){let s=await fetch(`${this.agentsUrl}/${e}/execute`,{method:"POST",headers:c,body:JSON.stringify(t)});if(!s.ok)throw new r("bad_request:api",`Failed to execute agent: ${s.statusText}`);return s.json()}async createFromPrompt(e){let t=await fetch(`${this.agentsUrl}/from-prompt`,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok)throw new r("bad_request:api",`Failed to generate agent from prompt: ${t.statusText}`);let s=await t.json();return this.create({...s,created_by:e.created_by})}};function O(i={}){return new C(i)}var Q=O();var S=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||l;}get widgetsUrl(){return `${this.baseUrl}/widgets`}async list(e={}){let t=new URLSearchParams;e.creatorMid?t.set("creator_mid",e.creatorMid):e.scope&&t.set("scope",e.scope);let s=t.toString(),o=`${this.widgetsUrl}${s?`?${s}`:""}`,n=await fetch(o);if(!n.ok)throw new r("bad_request:api",`Failed to list widgets: ${n.statusText}`);return n.json()}async get(e){let t=await fetch(`${this.widgetsUrl}/${e}`);if(!t.ok)throw new r(t.status===404?"not_found:api":"bad_request:api",`Failed to get widget: ${t.statusText}`);return t.json()}async create(e){let t=await fetch(this.widgetsUrl,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create widget: ${t.statusText}`)}return t.json()}async update(e,t){let s=await fetch(`${this.widgetsUrl}/${e}`,{method:"PUT",headers:c,body:JSON.stringify(t)});if(!s.ok){let o=await s.json().catch(()=>({}));throw new r("bad_request:api",o.error||`Failed to update widget: ${s.statusText}`)}return s.json()}async delete(e){let t=await fetch(`${this.widgetsUrl}/${e}`,{method:"DELETE"});if(!t.ok)throw new r("bad_request:api",`Failed to delete widget: ${t.statusText}`);return t.json()}async getSystemPrompt(){let e=await fetch(`${this.widgetsUrl}/system-prompt`);if(!e.ok)throw new r("bad_request:api",`Failed to get widget system prompt: ${e.statusText}`);return e.json()}async trackUsage(e){await fetch(`${this.widgetsUrl}/${e}/usage`,{method:"POST"}).catch(()=>{});}};function L(i={}){return new S(i)}var Z=L();var $=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||l;}get userUrl(){return `${this.baseUrl}/user`}async getProfile(e){try{let t=await fetch(`${this.userUrl}/profile/${e}`);if(!t.ok){if(t.status===404)return null;throw new r("bad_request:api",`Failed to get user profile: ${t.statusText}`)}return t.json()}catch(t){if(t instanceof r)throw t;return null}}async updateProfile(e,t){let s=await fetch(`${this.userUrl}/profile/${e}`,{method:"PUT",headers:c,body:JSON.stringify(t)});if(!s.ok){let o=await s.json().catch(()=>({}));throw new r("bad_request:api",o.error||`Failed to update user profile: ${s.statusText}`)}return s.json()}};function D(i={}){return new $(i)}var tt=D();var x=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||l;}get filesUrl(){return `${this.baseUrl}/files`}async upload(e,t){let s=new FormData;s.append("file",e,t);let o=await fetch(`${this.filesUrl}/upload`,{method:"POST",body:s});if(!o.ok)throw new r("bad_request:api",`Failed to upload file: ${o.statusText}`);return o.json()}async uploadFromUrl(e){let t=await fetch(`${this.filesUrl}/upload-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:e})});if(!t.ok)throw new r("bad_request:api",`Failed to upload file from URL: ${t.statusText}`);return t.json()}getFileUrl(e){return `${this.filesUrl}/${e}`}};function N(i={}){return new x(i)}var et=N();var b=class{baseUrl;useCpxApi;constructor(e={}){this.baseUrl=e.baseUrl||p,this.useCpxApi=e.useCpxApi!==false;}get skillsUrl(){return this.useCpxApi?`${this.baseUrl}/cpx/agent/skills`:`${this.baseUrl}/skills`}async list(e){let t=new URLSearchParams;e?.precompiled?(t.set("precompiled","true"),e?.contentType&&t.set("content_type",e.contentType)):e?.contentType?t.set("content_type",e.contentType):e?.creatorMid?t.set("creator_mid",e.creatorMid):e?.scope&&e.scope!=="all"&&t.set("scope",e.scope);let s=t.toString()?`${this.skillsUrl}?${t.toString()}`:this.skillsUrl,o=await fetch(s);if(!o.ok)throw new Error(`Failed to list skills: ${o.statusText}`);return o.json()}async get(e){let t=await fetch(`${this.skillsUrl}/${e}`);if(!t.ok)throw new Error(`Skill not found: ${e}`);return t.json()}async create(e){let t=await fetch(this.skillsUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new Error(s.error||`Failed to create skill: ${t.statusText}`)}return t.json()}async update(e,t){let s=await fetch(`${this.skillsUrl}/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!s.ok){let o=await s.json().catch(()=>({}));throw new Error(o.error||`Failed to update skill: ${s.statusText}`)}return s.json()}async delete(e){let t=await fetch(`${this.skillsUrl}/${e}`,{method:"DELETE"});if(!t.ok){let s=await t.json().catch(()=>({}));throw new Error(s.error||`Failed to delete skill: ${t.statusText}`)}return t.json()}async trackUsage(e){try{await fetch(`${this.skillsUrl}/${e}/usage`,{method:"POST"});}catch{}}async verify(e){let t=await fetch(`${this.skillsUrl}/${e}/verify`);if(!t.ok)throw new Error(`Failed to verify skill: ${t.statusText}`);return t.json()}async rehash(e){let t=await fetch(`${this.skillsUrl}/${e}/rehash`,{method:"POST"});if(!t.ok)throw new Error(`Failed to rehash skill: ${t.statusText}`);return t.json()}async rehashAll(){let e=await fetch(`${this.skillsUrl}/rehash-all`,{method:"POST"});if(!e.ok)throw new Error(`Failed to rehash all skills: ${e.statusText}`);return e.json()}async getMap(e){let t=e?`?content_type=${e}`:"",s=await fetch(`${this.skillsUrl}/map${t}`);if(!s.ok)throw new Error(`Failed to get skill map: ${s.statusText}`);return s.json()}async getMapPrompt(e){let t=e?`?content_type=${e}`:"",s=await fetch(`${this.skillsUrl}/map/prompt${t}`);if(!s.ok)throw new Error(`Failed to get skill map prompt: ${s.statusText}`);return s.json()}async getNonCodeMap(){let e=await fetch(`${this.skillsUrl}/map/noncode`);if(!e.ok)throw new Error(`Failed to get non-code skill map: ${e.statusText}`);return e.json()}async getNonCodeSummary(){let e=await fetch(`${this.skillsUrl}/summary/noncode`);if(!e.ok)throw new Error(`Failed to get non-code skill summary: ${e.statusText}`);return e.json()}};function M(i){return new b(i)}var st=M();var k=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||p;}get pointsUrl(){return `${this.baseUrl}/cpx/points`}async initNetworkDomain(){let e=await fetch(`${this.pointsUrl}/init`,{method:"POST",headers:c});if(!e.ok){let t=await e.json().catch(()=>({}));throw new r("bad_request:api",t.error||`Failed to initialize network domain: ${e.statusText}`)}return e.json()}async listDomains(){let e=await fetch(`${this.pointsUrl}/domains`);if(!e.ok)throw new r("bad_request:api",`Failed to list domains: ${e.statusText}`);return e.json()}async getDomain(e){let t=await fetch(`${this.pointsUrl}/domains/${e}`);if(t.status===404)return null;if(!t.ok)throw new r("bad_request:api",`Failed to get domain: ${t.statusText}`);return t.json()}async createDomain(e){let t=await fetch(`${this.pointsUrl}/domains`,{method:"POST",headers:c,body:JSON.stringify(e)});if(t.status===402){let s=await t.json();throw new r("payment_required:api",s.error,{paymentDetails:s.paymentDetails})}if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create domain: ${t.statusText}`)}return t.json()}async listContexts(e){let t=e?`?domainId=${e}`:"",s=await fetch(`${this.pointsUrl}/contexts${t}`);if(!s.ok)throw new r("bad_request:api",`Failed to list contexts: ${s.statusText}`);return s.json()}async getContext(e){let t=await fetch(`${this.pointsUrl}/contexts/${e}`);if(t.status===404)return null;if(!t.ok)throw new r("bad_request:api",`Failed to get context: ${t.statusText}`);return t.json()}async createContext(e){let t=await fetch(`${this.pointsUrl}/contexts`,{method:"POST",headers:c,body:JSON.stringify(e)});if(t.status===402){let s=await t.json();throw new r("payment_required:api",s.error,{paymentDetails:s.paymentDetails})}if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create context: ${t.statusText}`)}return t.json()}async listDelegations(e={}){let t=new URLSearchParams;e.domainId&&t.set("domainId",e.domainId),e.delegator&&t.set("delegator",e.delegator),e.delegate&&t.set("delegate",e.delegate),e.activeOnly&&t.set("activeOnly","true");let s=t.toString(),o=`${this.pointsUrl}/delegations${s?`?${s}`:""}`,n=await fetch(o);if(!n.ok)throw new r("bad_request:api",`Failed to list delegations: ${n.statusText}`);return n.json()}async createDelegation(e){let t=await fetch(`${this.pointsUrl}/delegations`,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create delegation: ${t.statusText}`)}return t.json()}async revokeDelegation(e){let t=await fetch(`${this.pointsUrl}/delegations/${e}`,{method:"DELETE"});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to revoke delegation: ${t.statusText}`)}return t.json()}async addPoints(e){let t=await fetch(`${this.pointsUrl}/add`,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to add points: ${t.statusText}`)}return t.json()}async spendPoints(e){let t=await fetch(`${this.pointsUrl}/spend`,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to spend points: ${t.statusText}`)}return t.json()}async getBalance(e,t={}){let s=new URLSearchParams;t.domainId&&s.set("domainId",t.domainId),t.contextId&&s.set("contextId",t.contextId);let o=s.toString(),n=`${this.pointsUrl}/balance/${e}${o?`?${o}`:""}`,a=await fetch(n);if(!a.ok)throw new r("bad_request:api",`Failed to get balance: ${a.statusText}`);return a.json()}async getHistory(e={}){let t=new URLSearchParams;e.mid&&t.set("mid",e.mid),e.domainId&&t.set("domainId",e.domainId),e.contextId&&t.set("contextId",e.contextId),e.periodStart&&t.set("periodStart",e.periodStart.toString()),e.periodEnd&&t.set("periodEnd",e.periodEnd.toString()),e.taskId&&t.set("taskId",e.taskId),e.limit&&t.set("limit",e.limit.toString()),e.offset&&t.set("offset",e.offset.toString());let s=t.toString(),o=`${this.pointsUrl}/history${s?`?${s}`:""}`,n=await fetch(o);if(!n.ok)throw new r("bad_request:api",`Failed to get history: ${n.statusText}`);return n.json()}};function q(i={}){return new k(i)}var ot=q();var U=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||p;}get notificationsUrl(){return `${this.baseUrl}/cpx/notifications`}async list(e){let t=new URLSearchParams;t.set("user_mid",e.user_mid),e.unread_only&&t.set("unread_only","true"),e.type&&t.set("type",e.type),e.source&&t.set("source",e.source),e.limit&&t.set("limit",e.limit.toString()),e.offset&&t.set("offset",e.offset.toString());let s=await fetch(`${this.notificationsUrl}?${t.toString()}`);if(!s.ok)throw new r("bad_request:api",`Failed to list notifications: ${s.statusText}`);return s.json()}async get(e){let t=await fetch(`${this.notificationsUrl}/${e}`);if(t.status===404)return null;if(!t.ok)throw new r("bad_request:api",`Failed to get notification: ${t.statusText}`);return t.json()}async getUnreadCount(e){return (await this.list({user_mid:e,unread_only:true,limit:0})).unread_count}async create(e){let t=await fetch(this.notificationsUrl,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create notification: ${t.statusText}`)}return t.json()}async markAsRead(e){let t=await fetch(`${this.notificationsUrl}/${e}/read`,{method:"PUT"});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to mark notification as read: ${t.statusText}`)}return t.json()}async markAllAsRead(e){let t=await fetch(`${this.notificationsUrl}/read-all`,{method:"PUT",headers:c,body:JSON.stringify({user_mid:e})});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to mark all as read: ${t.statusText}`)}return t.json()}async dismiss(e){let t=await fetch(`${this.notificationsUrl}/${e}`,{method:"DELETE"});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to dismiss notification: ${t.statusText}`)}return t.json()}};function J(i={}){return new U(i)}var rt=J();var P=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||p;}get scoutsUrl(){return `${this.baseUrl}/cpx/scouts`}async list(e={}){let t=new URLSearchParams;e.owner_mid&&t.set("owner_mid",e.owner_mid),e.active_only!==void 0&&t.set("active_only",e.active_only.toString());let s=t.toString(),o=`${this.scoutsUrl}${s?`?${s}`:""}`,n=await fetch(o);if(!n.ok)throw new r("bad_request:api",`Failed to list scouts: ${n.statusText}`);return n.json()}async get(e){let t=await fetch(`${this.scoutsUrl}/${e}`);if(t.status===404)return null;if(!t.ok)throw new r("bad_request:api",`Failed to get scout: ${t.statusText}`);return t.json()}async getHistory(e,t={}){let s=new URLSearchParams;t.limit&&s.set("limit",t.limit.toString()),t.offset&&s.set("offset",t.offset.toString());let o=s.toString(),n=`${this.scoutsUrl}/${e}/history${o?`?${o}`:""}`,a=await fetch(n);if(!a.ok)throw new r("bad_request:api",`Failed to get scout history: ${a.statusText}`);return a.json()}async create(e){let t=await fetch(this.scoutsUrl,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create scout: ${t.statusText}`)}return t.json()}async update(e,t){let s=await fetch(`${this.scoutsUrl}/${e}`,{method:"PUT",headers:c,body:JSON.stringify(t)});if(!s.ok){let o=await s.json().catch(()=>({}));throw new r("bad_request:api",o.error||`Failed to update scout: ${s.statusText}`)}return s.json()}async trigger(e){let t=await fetch(`${this.scoutsUrl}/${e}/trigger`,{method:"POST"});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to trigger scout: ${t.statusText}`)}return t.json()}async activate(e){return this.update(e,{is_active:true})}async deactivate(e){return this.update(e,{is_active:false})}async delete(e){let t=await fetch(`${this.scoutsUrl}/${e}`,{method:"DELETE"});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to delete scout: ${t.statusText}`)}return t.json()}};function W(i={}){return new P(i)}var nt=W();
4
+ exports.AgentsClient=C;exports.FilesClient=x;exports.MCPClient=y;exports.MagmaClient=g;exports.NotificationsClient=U;exports.PointsClient=k;exports.ScoutsClient=P;exports.SkillsClient=b;exports.SocialClient=w;exports.TaskNetworkClient=f;exports.UserClient=$;exports.WidgetsClient=S;exports.agentsClient=Q;exports.createAgentsClient=O;exports.createFilesClient=N;exports.createMCPClient=v;exports.createMagmaClient=j;exports.createNotificationsClient=J;exports.createPointsClient=q;exports.createScoutsClient=W;exports.createSkillsClient=M;exports.createSocialClient=I;exports.createTaskNetworkClient=E;exports.createUserClient=D;exports.createWidgetsClient=L;exports.filesClient=et;exports.magmaClient=G;exports.mcpClient=H;exports.notificationsClient=rt;exports.pointsClient=ot;exports.scoutsClient=nt;exports.skillsClient=st;exports.socialClient=X;exports.taskNetworkClient=B;exports.userClient=tt;exports.widgetsClient=Z;
@@ -0,0 +1,114 @@
1
+ export { A as AgentsClient, F as FilesClient, e as MCPClient, M as MagmaClient, d as MagmaClientConfig, P as PointsClient, p as SkillsClient, S as SocialClient, T as TaskNetworkClient, a as TaskNetworkConfig, U as UserClient, W as WidgetsClient, j as agentsClient, i as createAgentsClient, n as createFilesClient, f as createMCPClient, b as createMagmaClient, v as createPointsClient, q as createSkillsClient, h as createSocialClient, c as createTaskNetworkClient, l as createUserClient, k as createWidgetsClient, o as filesClient, m as magmaClient, g as mcpClient, x as pointsClient, r as skillsClient, s as socialClient, t as taskNetworkClient, u as userClient, w as widgetsClient } from '../points-Blo2T9MP.cjs';
2
+ import { f as NotificationsClientConfig, c as NotificationsListFilters, d as NotificationsListResponse, b as Notification, C as CreateNotificationInput, e as NotificationResponse, M as MarkAllReadResponse, q as ScoutsClientConfig, k as ScoutsListFilters, l as ScoutsListResponse, m as ScoutResponse, n as ScoutHistoryResponse, i as CreateScoutInput, j as UpdateScoutInput, o as TriggerScoutResponse, p as DeleteScoutResponse } from '../scouts-CvzLWYpj.cjs';
3
+ export { u as AgentsClientConfig, a6 as FilesClientConfig, aJ as PointsClientConfig, ad as SkillsClientConfig, U as SocialClientConfig, a4 as UserClientConfig, a0 as WidgetsClientConfig } from '../points-CGAg3YZi.cjs';
4
+
5
+ /**
6
+ * Notifications Client
7
+ *
8
+ * Client for interacting with the GeoffNet Notifications API.
9
+ * Provides access to user notifications for alerts, updates, and scout events.
10
+ */
11
+
12
+ declare class NotificationsClient {
13
+ private baseUrl;
14
+ constructor(config?: NotificationsClientConfig);
15
+ private get notificationsUrl();
16
+ /**
17
+ * List notifications with optional filters
18
+ */
19
+ list(filters: NotificationsListFilters): Promise<NotificationsListResponse>;
20
+ /**
21
+ * Get a single notification by ID
22
+ */
23
+ get(notificationId: string): Promise<Notification | null>;
24
+ /**
25
+ * Get unread notification count for a user
26
+ */
27
+ getUnreadCount(userMid: string): Promise<number>;
28
+ /**
29
+ * Create a new notification
30
+ */
31
+ create(input: CreateNotificationInput): Promise<NotificationResponse>;
32
+ /**
33
+ * Mark a notification as read
34
+ */
35
+ markAsRead(notificationId: string): Promise<NotificationResponse>;
36
+ /**
37
+ * Mark all notifications as read for a user
38
+ */
39
+ markAllAsRead(userMid: string): Promise<MarkAllReadResponse>;
40
+ /**
41
+ * Dismiss (soft-delete) a notification
42
+ */
43
+ dismiss(notificationId: string): Promise<NotificationResponse>;
44
+ }
45
+ /**
46
+ * Create a NotificationsClient instance
47
+ */
48
+ declare function createNotificationsClient(config?: NotificationsClientConfig): NotificationsClient;
49
+ /**
50
+ * Default notifications client instance
51
+ */
52
+ declare const notificationsClient: NotificationsClient;
53
+
54
+ /**
55
+ * Scouts Client
56
+ *
57
+ * Client for interacting with the GeoffNet Scouts MCP tool.
58
+ * Provides access to web monitoring agents that track changes to websites.
59
+ */
60
+
61
+ declare class ScoutsClient {
62
+ private baseUrl;
63
+ constructor(config?: ScoutsClientConfig);
64
+ private get scoutsUrl();
65
+ /**
66
+ * List scouts with optional filters
67
+ */
68
+ list(filters?: ScoutsListFilters): Promise<ScoutsListResponse>;
69
+ /**
70
+ * Get a scout by ID with recent snapshots
71
+ */
72
+ get(scoutId: string): Promise<ScoutResponse | null>;
73
+ /**
74
+ * Get snapshot history for a scout
75
+ */
76
+ getHistory(scoutId: string, options?: {
77
+ limit?: number;
78
+ offset?: number;
79
+ }): Promise<ScoutHistoryResponse>;
80
+ /**
81
+ * Create a new scout
82
+ */
83
+ create(input: CreateScoutInput): Promise<ScoutResponse>;
84
+ /**
85
+ * Update a scout's configuration
86
+ */
87
+ update(scoutId: string, updates: UpdateScoutInput): Promise<ScoutResponse>;
88
+ /**
89
+ * Trigger a scout to run immediately
90
+ */
91
+ trigger(scoutId: string): Promise<TriggerScoutResponse>;
92
+ /**
93
+ * Activate a scout
94
+ */
95
+ activate(scoutId: string): Promise<ScoutResponse>;
96
+ /**
97
+ * Deactivate a scout
98
+ */
99
+ deactivate(scoutId: string): Promise<ScoutResponse>;
100
+ /**
101
+ * Delete a scout and its history
102
+ */
103
+ delete(scoutId: string): Promise<DeleteScoutResponse>;
104
+ }
105
+ /**
106
+ * Create a ScoutsClient instance
107
+ */
108
+ declare function createScoutsClient(config?: ScoutsClientConfig): ScoutsClient;
109
+ /**
110
+ * Default scouts client instance
111
+ */
112
+ declare const scoutsClient: ScoutsClient;
113
+
114
+ export { NotificationsClient, NotificationsClientConfig, ScoutsClient, ScoutsClientConfig, createNotificationsClient, createScoutsClient, notificationsClient, scoutsClient };
@@ -0,0 +1,114 @@
1
+ export { A as AgentsClient, F as FilesClient, e as MCPClient, M as MagmaClient, d as MagmaClientConfig, P as PointsClient, p as SkillsClient, S as SocialClient, T as TaskNetworkClient, a as TaskNetworkConfig, U as UserClient, W as WidgetsClient, j as agentsClient, i as createAgentsClient, n as createFilesClient, f as createMCPClient, b as createMagmaClient, v as createPointsClient, q as createSkillsClient, h as createSocialClient, c as createTaskNetworkClient, l as createUserClient, k as createWidgetsClient, o as filesClient, m as magmaClient, g as mcpClient, x as pointsClient, r as skillsClient, s as socialClient, t as taskNetworkClient, u as userClient, w as widgetsClient } from '../points-BXIt899Y.js';
2
+ import { f as NotificationsClientConfig, c as NotificationsListFilters, d as NotificationsListResponse, b as Notification, C as CreateNotificationInput, e as NotificationResponse, M as MarkAllReadResponse, q as ScoutsClientConfig, k as ScoutsListFilters, l as ScoutsListResponse, m as ScoutResponse, n as ScoutHistoryResponse, i as CreateScoutInput, j as UpdateScoutInput, o as TriggerScoutResponse, p as DeleteScoutResponse } from '../scouts-CvzLWYpj.js';
3
+ export { u as AgentsClientConfig, a6 as FilesClientConfig, aJ as PointsClientConfig, ad as SkillsClientConfig, U as SocialClientConfig, a4 as UserClientConfig, a0 as WidgetsClientConfig } from '../points-CGAg3YZi.js';
4
+
5
+ /**
6
+ * Notifications Client
7
+ *
8
+ * Client for interacting with the GeoffNet Notifications API.
9
+ * Provides access to user notifications for alerts, updates, and scout events.
10
+ */
11
+
12
+ declare class NotificationsClient {
13
+ private baseUrl;
14
+ constructor(config?: NotificationsClientConfig);
15
+ private get notificationsUrl();
16
+ /**
17
+ * List notifications with optional filters
18
+ */
19
+ list(filters: NotificationsListFilters): Promise<NotificationsListResponse>;
20
+ /**
21
+ * Get a single notification by ID
22
+ */
23
+ get(notificationId: string): Promise<Notification | null>;
24
+ /**
25
+ * Get unread notification count for a user
26
+ */
27
+ getUnreadCount(userMid: string): Promise<number>;
28
+ /**
29
+ * Create a new notification
30
+ */
31
+ create(input: CreateNotificationInput): Promise<NotificationResponse>;
32
+ /**
33
+ * Mark a notification as read
34
+ */
35
+ markAsRead(notificationId: string): Promise<NotificationResponse>;
36
+ /**
37
+ * Mark all notifications as read for a user
38
+ */
39
+ markAllAsRead(userMid: string): Promise<MarkAllReadResponse>;
40
+ /**
41
+ * Dismiss (soft-delete) a notification
42
+ */
43
+ dismiss(notificationId: string): Promise<NotificationResponse>;
44
+ }
45
+ /**
46
+ * Create a NotificationsClient instance
47
+ */
48
+ declare function createNotificationsClient(config?: NotificationsClientConfig): NotificationsClient;
49
+ /**
50
+ * Default notifications client instance
51
+ */
52
+ declare const notificationsClient: NotificationsClient;
53
+
54
+ /**
55
+ * Scouts Client
56
+ *
57
+ * Client for interacting with the GeoffNet Scouts MCP tool.
58
+ * Provides access to web monitoring agents that track changes to websites.
59
+ */
60
+
61
+ declare class ScoutsClient {
62
+ private baseUrl;
63
+ constructor(config?: ScoutsClientConfig);
64
+ private get scoutsUrl();
65
+ /**
66
+ * List scouts with optional filters
67
+ */
68
+ list(filters?: ScoutsListFilters): Promise<ScoutsListResponse>;
69
+ /**
70
+ * Get a scout by ID with recent snapshots
71
+ */
72
+ get(scoutId: string): Promise<ScoutResponse | null>;
73
+ /**
74
+ * Get snapshot history for a scout
75
+ */
76
+ getHistory(scoutId: string, options?: {
77
+ limit?: number;
78
+ offset?: number;
79
+ }): Promise<ScoutHistoryResponse>;
80
+ /**
81
+ * Create a new scout
82
+ */
83
+ create(input: CreateScoutInput): Promise<ScoutResponse>;
84
+ /**
85
+ * Update a scout's configuration
86
+ */
87
+ update(scoutId: string, updates: UpdateScoutInput): Promise<ScoutResponse>;
88
+ /**
89
+ * Trigger a scout to run immediately
90
+ */
91
+ trigger(scoutId: string): Promise<TriggerScoutResponse>;
92
+ /**
93
+ * Activate a scout
94
+ */
95
+ activate(scoutId: string): Promise<ScoutResponse>;
96
+ /**
97
+ * Deactivate a scout
98
+ */
99
+ deactivate(scoutId: string): Promise<ScoutResponse>;
100
+ /**
101
+ * Delete a scout and its history
102
+ */
103
+ delete(scoutId: string): Promise<DeleteScoutResponse>;
104
+ }
105
+ /**
106
+ * Create a ScoutsClient instance
107
+ */
108
+ declare function createScoutsClient(config?: ScoutsClientConfig): ScoutsClient;
109
+ /**
110
+ * Default scouts client instance
111
+ */
112
+ declare const scoutsClient: ScoutsClient;
113
+
114
+ export { NotificationsClient, NotificationsClientConfig, ScoutsClient, ScoutsClientConfig, createNotificationsClient, createScoutsClient, notificationsClient, scoutsClient };
@@ -0,0 +1,4 @@
1
+ var l="http://localhost:3000";var p="https://geoffnet.magma-rpc.com";var c={"Content-Type":"application/json"};var f=class{baseUrl;apiKey;timeout;constructor(e={}){this.baseUrl=(e.baseUrl||l).replace(/\/$/,""),this.apiKey=e.apiKey,this.timeout=e.timeout||6e4;}async*chatCompletions(e){let t=e.messages.filter(n=>n.role==="user"),s=t[t.length-1]?.content||"",o=await this.submitTask({type:"ai-prompt",model:e.model,prompt:s,sessionId:e.sessionId,temperature:e.temperature,maxTokens:e.max_tokens,stream:true});yield*this.streamTaskResults(o,e.model);}async submitTask(e){let t=await fetch(`${this.baseUrl}/tasks`,{method:"POST",headers:{"Content-Type":"application/json",...this.apiKey&&{Authorization:`Bearer ${this.apiKey}`}},body:JSON.stringify(e)});if(!t.ok){let o=await t.text();throw new Error(`Task submission failed: ${o}`)}return (await t.json()).taskId}async getTask(e){let t=await fetch(`${this.baseUrl}/tasks/${e}`,{headers:{...this.apiKey&&{Authorization:`Bearer ${this.apiKey}`}}});if(!t.ok)throw new Error(`Failed to get task: ${t.statusText}`);return t.json()}async*streamTaskResults(e,t){let s=await fetch(`${this.baseUrl}/tasks/${e}/stream`,{headers:{...this.apiKey&&{Authorization:`Bearer ${this.apiKey}`}}});if(!s.ok)throw new Error(`Stream failed: ${s.statusText}`);if(!s.body)throw new Error("Response body is null");let o=s.body.getReader(),n=new TextDecoder,a="",d="",u=Math.floor(Date.now()/1e3);try{for(;;){let{done:h,value:K}=await o.read();if(h){yield {id:e,object:"chat.completion.chunk",created:u,model:t,choices:[{index:0,delta:{},finish_reason:"stop"}]};break}a+=n.decode(K,{stream:!0});let R=a.split(`
2
+ `);a=R.pop()||"";for(let _ of R)if(_.startsWith("data: "))try{let T=JSON.parse(_.slice(6));if(Array.isArray(T)&&T.length>0){let m=T[0].result||"";if(m&&m!==d){let F=m.substring(d.length);d=m,F&&(yield {id:e,object:"chat.completion.chunk",created:u,model:t,choices:[{index:0,delta:{role:"assistant",content:F},finish_reason:null}]});}}}catch{}}}finally{o.releaseLock();}}async*streamTaskRaw(e){let t=await fetch(`${this.baseUrl}/tasks/${e}/stream`,{headers:{...this.apiKey&&{Authorization:`Bearer ${this.apiKey}`}}});if(!t.ok)throw new Error(`Stream failed: ${t.statusText}`);if(!t.body)throw new Error("Response body is null");let s=t.body.getReader(),o=new TextDecoder,n="";try{for(;;){let{done:a,value:d}=await s.read();if(a)break;n+=o.decode(d,{stream:!0});let u=n.split(`
3
+ `);n=u.pop()||"";for(let h of u)if(h.startsWith("data: "))try{yield JSON.parse(h.slice(6));}catch{}}}finally{s.releaseLock();}}async healthCheck(){try{return (await fetch(`${this.baseUrl}/health`)).ok}catch{return false}}async getNode(){let e=await fetch(`${this.baseUrl}/node`);if(!e.ok)throw new Error(`Failed to get node info: ${e.statusText}`);return e.json()}};function E(i){return new f(i)}var B=E();async function A(i){let e=await crypto.subtle.digest("SHA-256",i);return `baf${Array.from(new Uint8Array(e)).map(o=>o.toString(16).padStart(2,"0")).join("").substring(0,52)}`}var g=class{baseUrl;localServerUrl;constructor(e={}){this.baseUrl=e.baseUrl||p,this.localServerUrl=e.localServerUrl||l;}async uploadFile(e){let t=await e.arrayBuffer(),s=await A(t),o=this.arrayBufferToBase64(t);return typeof localStorage<"u"&&localStorage.setItem(`file:${s}`,JSON.stringify({cid:s,name:e.name,type:e.type,size:e.size,data:o})),{cid:s,name:e.name,size:e.size,type:e.type,url:`data:${e.type};base64,${o}`}}async uploadText(e,t){let s=new Blob([e],{type:"text/plain"}),o=new File([s],t,{type:"text/plain"});return this.uploadFile(o)}async storeImagination(e){let t=e.createdBy||"anonymous",o=(await fetch(`${this.localServerUrl}/imaginations/${e.id}`)).ok,n={id:e.id,title:e.title,sources:e.sources,summary:e.summary,character:e.character,workflow:e.workflow,is_public:e.is_public||false,creator_mid:t};if(o){let a=await fetch(`${this.localServerUrl}/imaginations/${e.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!a.ok)throw new Error(`Failed to update imagination: ${a.statusText}`);return typeof localStorage<"u"&&localStorage.setItem(`imagination:${e.id}`,e.id),e.id}else {let a=await fetch(`${this.localServerUrl}/imaginations`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!a.ok)throw new Error(`Failed to store imagination: ${a.statusText}`);let u=(await a.json()).imagination?.id||e.id;return typeof localStorage<"u"&&localStorage.setItem(`imagination:${u}`,u),u}}async getImagination(e){try{let t=await fetch(`${this.localServerUrl}/imaginations/${e}`);if(!t.ok)return null;let s=await t.json();return s.imagination?{id:s.imagination.id,title:s.imagination.title,createdAt:new Date(s.imagination.created_at).toISOString(),createdBy:s.imagination.creator_mid,sources:s.imagination.sources,summary:s.imagination.summary,character:s.imagination.character,workflow:s.imagination.workflow,is_public:s.imagination.is_public}:null}catch(t){return console.error("Failed to retrieve imagination:",t),null}}async getImaginationByCID(e){try{let t=await fetch(`${this.baseUrl}/files/${e}`);if(!t.ok)return null;let s=await t.json();return typeof localStorage<"u"&&localStorage.setItem(`imagination:${s.id}`,e),s}catch(t){return console.error("Failed to retrieve imagination by CID:",t),null}}async listImaginations(e){try{let t=e||"anonymous",s=await fetch(`${this.localServerUrl}/imaginations?creator_mid=${encodeURIComponent(t)}`);if(!s.ok)return console.warn("Failed to fetch imaginations from P2P, falling back to localStorage"),this.listImaginationsFromLocalStorage();let n=(await s.json()).imaginations.map(a=>({id:a.id,title:a.title,createdAt:new Date(a.created_at).toISOString(),createdBy:a.creator_mid,sources:a.sources,summary:a.summary,character:a.character,workflow:a.workflow,is_public:a.is_public}));return typeof localStorage<"u"&&n.forEach(a=>{localStorage.setItem(`imagination:${a.id}`,a.id);}),n}catch(t){return console.error("Failed to list imaginations:",t),this.listImaginationsFromLocalStorage()}}async listImaginationsFromLocalStorage(){if(typeof localStorage>"u")return [];let e=[];for(let t=0;t<localStorage.length;t++){let s=localStorage.key(t);if(s&&s.startsWith("imagination:")){let o=s.replace("imagination:",""),n=await this.getImagination(o);n&&e.push(n);}}return e}async getFile(e){try{let t=await fetch(`${this.baseUrl}/files/${e}`);return t.ok?await t.blob():null}catch(t){return console.error("Failed to retrieve file:",t),null}}arrayBufferToBase64(e){let t=new Uint8Array(e),s="";for(let o=0;o<t.length;o++)s+=String.fromCharCode(t[o]);return btoa(s)}};function j(i){return new g(i)}var G=j();var y=class{baseUrl;timeout;sessions=new Map;constructor(e={}){this.baseUrl=e.baseUrl||"http://localhost:3006",this.timeout=e.timeout||3e4;}async createSession(e="default"){let t=`session_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;try{let s={id:t,agentId:e,status:"active",createdAt:new Date};this.sessions.set(t,s);try{await fetch(`${this.baseUrl}/mcp/sessions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t,agentId:e,clientInfo:{name:"geoffai-sdk",version:"0.1.0"}})});}catch{}return s}catch(s){throw new Error(`Failed to create MCP session: ${s}`)}}getSession(e){return this.sessions.get(e)}async closeSession(e){let t=this.sessions.get(e);if(t){t.status="closed";try{await fetch(`${this.baseUrl}/mcp/sessions/${e}`,{method:"DELETE"});}catch{}this.sessions.delete(e);}}async sendMessage(e,t){let s=this.sessions.get(e);if(!s||s.status!=="active")throw new Error("Invalid or inactive session");try{let o=await fetch(`${this.baseUrl}/mcp/sessions/${e}/messages`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:[{role:"user",content:{type:"text",text:t}}]})});if(!o.ok)throw new Error(`MCP request failed: ${o.statusText}`);return o.json()}catch(o){throw new Error(`Failed to send message: ${o}`)}}async callTool(e,t,s={}){let o=this.sessions.get(e);if(!o||o.status!=="active")throw new Error("Invalid or inactive session");try{let n=await fetch(`${this.baseUrl}/mcp/sessions/${e}/tools/${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!n.ok)throw new Error(`Tool call failed: ${n.statusText}`);return n.json()}catch(n){throw new Error(`Failed to call tool: ${n}`)}}async listTools(e){let t=this.sessions.get(e);if(!t||t.status!=="active")throw new Error("Invalid or inactive session");try{let s=await fetch(`${this.baseUrl}/mcp/sessions/${e}/tools`);return s.ok?(await s.json()).tools||[]:[]}catch{return []}}getActiveSessions(){return Array.from(this.sessions.values()).filter(e=>e.status==="active")}async closeAllSessions(){let e=Array.from(this.sessions.keys());await Promise.all(e.map(t=>this.closeSession(t)));}};function v(i){return new y(i)}var H=v();var Y={database:"log",chat:"response",auth:"response",stream:"response",api:"response",history:"response",vote:"response",document:"response",suggestions:"response",task:"response",agent:"response",imagination:"response"},r=class extends Error{type;surface;statusCode;metadata;constructor(e,t,s){super();let[o,n]=e.split(":");this.type=o,this.cause=t,this.surface=n,this.message=z(e),this.statusCode=V(this.type),this.metadata=s;}toJSON(){return {code:`${this.type}:${this.surface}`,message:this.message,cause:this.cause,statusCode:this.statusCode,...this.metadata&&{metadata:this.metadata}}}toResponse(){let e=`${this.type}:${this.surface}`,t=Y[this.surface],{message:s,cause:o,statusCode:n}=this;return t==="log"?(console.error({code:e,message:s,cause:o}),Response.json({code:"",message:"Something went wrong. Please try again later."},{status:n})):Response.json({code:e,message:s,cause:o},{status:n})}};function z(i){if(i.includes("database"))return "An error occurred while executing a database query.";switch(i){case "bad_request:api":return "The request couldn't be processed. Please check your input and try again.";case "unauthorized:auth":return "You need to sign in before continuing.";case "forbidden:auth":return "Your account does not have access to this feature.";case "rate_limit:chat":return "You have exceeded your maximum number of messages for the day. Please try again later.";case "not_found:chat":return "The requested chat was not found.";case "forbidden:chat":return "This chat belongs to another user.";case "unauthorized:chat":return "You need to sign in to view this chat.";case "offline:chat":return "We're having trouble sending your message. Please check your internet connection.";case "not_found:task":return "The requested task was not found.";case "forbidden:task":return "You do not have access to this task.";case "not_found:agent":return "The requested agent was not found.";case "forbidden:agent":return "You do not have access to this agent.";case "not_found:imagination":return "The requested imagination was not found.";case "forbidden:imagination":return "You do not have access to this imagination.";case "not_found:document":return "The requested document was not found.";case "forbidden:document":return "This document belongs to another user.";case "unauthorized:document":return "You need to sign in to view this document.";case "bad_request:document":return "The request to create or update the document was invalid.";default:return "Something went wrong. Please try again later."}}function V(i){switch(i){case "bad_request":return 400;case "unauthorized":return 401;case "payment_required":return 402;case "forbidden":return 403;case "not_found":return 404;case "rate_limit":return 429;case "offline":return 503;case "internal":return 500;default:return 500}}var w=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||l;}get socialUrl(){return `${this.baseUrl}/social`}async getFeed(e={}){let{page:t=1,limit:s=10,mediaType:o}=e,n=new URLSearchParams({page:String(t),limit:String(s)});o&&n.set("media_type",o);let a=await fetch(`${this.socialUrl}/feed?${n}`);if(!a.ok)throw new r("bad_request:api",`Failed to fetch feed: ${a.statusText}`);return a.json()}async getPost(e){let t=await fetch(`${this.socialUrl}/posts/${e}`);if(!t.ok)throw new r(t.status===404?"not_found:api":"bad_request:api",`Failed to fetch post: ${t.statusText}`);return t.json()}async getComments(e){let t=await fetch(`${this.socialUrl}/posts/${e}/comments`);if(!t.ok)throw new r("bad_request:api",`Failed to fetch comments: ${t.statusText}`);return t.json()}async getRemixes(e){let t=await fetch(`${this.socialUrl}/posts/${e}/remixes`);if(!t.ok)throw new r("bad_request:api",`Failed to fetch remixes: ${t.statusText}`);return t.json()}async checkLike(e,t){let s=await fetch(`${this.socialUrl}/posts/${e}/likes/check?userMid=${encodeURIComponent(t)}`);if(!s.ok)throw new r("bad_request:api",`Failed to check like status: ${s.statusText}`);return s.json()}async likePost(e,t){let s=await fetch(`${this.socialUrl}/like`,{method:"POST",headers:c,body:JSON.stringify({postId:e,userMid:t})});if(!s.ok)throw new r("bad_request:api",`Failed to like post: ${s.statusText}`);return s.json()}async unlikePost(e,t){let s=await fetch(`${this.socialUrl}/unlike`,{method:"POST",headers:c,body:JSON.stringify({postId:e,userMid:t})});if(!s.ok)throw new r("bad_request:api",`Failed to unlike post: ${s.statusText}`);return s.json()}async addComment(e,t,s){let o=await fetch(`${this.socialUrl}/comment`,{method:"POST",headers:c,body:JSON.stringify({postId:e,userMid:t,content:s})});if(!o.ok)throw new r("bad_request:api",`Failed to add comment: ${o.statusText}`);return o.json()}async createPost(e){let t=await fetch(`${this.socialUrl}/post`,{method:"POST",headers:c,body:JSON.stringify({userMid:e.creatorMid,content:e.content,mediaUrl:e.mediaUrl,mediaType:e.mediaType,remixOf:e.remixOf})});if(!t.ok)throw new r("bad_request:api",`Failed to create post: ${t.statusText}`);return t.json()}async trackView(e,t){await fetch(`${this.socialUrl}/posts/${e}/view`,{method:"POST",headers:c,body:JSON.stringify({userMid:t})}).catch(()=>{});}async trackPlay(e,t){await fetch(`${this.socialUrl}/posts/${e}/play`,{method:"POST",headers:c,body:JSON.stringify({userMid:t})}).catch(()=>{});}async getProfile(e){try{let t=await fetch(`${this.socialUrl}/profile/${e}`);if(!t.ok){if(t.status===404)return null;throw new r("bad_request:api",`Failed to fetch profile: ${t.statusText}`)}return t.json()}catch(t){if(t instanceof r)throw t;return null}}};function I(i={}){return new w(i)}var X=I();var C=class{baseUrl;useCpxApi;constructor(e={}){this.baseUrl=e.baseUrl||l,this.useCpxApi=e.useCpxApi!==false;}get agentsUrl(){return this.useCpxApi?`${this.baseUrl}/cpx/agent/agents`:`${this.baseUrl}/agents`}async list(e={}){let t=new URLSearchParams;e.userMid&&t.set("userMid",e.userMid);let s=t.toString(),o=`${this.agentsUrl}${s?`?${s}`:""}`,n=await fetch(o);if(!n.ok)throw new r("bad_request:api",`Failed to list agents: ${n.statusText}`);return n.json()}async get(e){let t=await fetch(`${this.agentsUrl}/${e}`);if(!t.ok)throw new r(t.status===404?"not_found:api":"bad_request:api",`Failed to get agent: ${t.statusText}`);return t.json()}async create(e){let t=await fetch(this.agentsUrl,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create agent: ${t.statusText}`)}return t.json()}async update(e,t){let s=await fetch(`${this.agentsUrl}/${e}`,{method:"PUT",headers:c,body:JSON.stringify(t)});if(!s.ok){let o=await s.json().catch(()=>({}));throw new r("bad_request:api",o.error||`Failed to update agent: ${s.statusText}`)}return s.json()}async delete(e){let t=await fetch(`${this.agentsUrl}/${e}`,{method:"DELETE"});if(!t.ok)throw new r("bad_request:api",`Failed to delete agent: ${t.statusText}`);return t.json()}async enable(e){let t=await fetch(`${this.agentsUrl}/${e}/enable`,{method:"POST"});if(!t.ok)throw new r("bad_request:api",`Failed to enable agent: ${t.statusText}`);return t.json()}async disable(e){let t=await fetch(`${this.agentsUrl}/${e}/disable`,{method:"POST"});if(!t.ok)throw new r("bad_request:api",`Failed to disable agent: ${t.statusText}`);return t.json()}async execute(e,t={}){let s=await fetch(`${this.agentsUrl}/${e}/execute`,{method:"POST",headers:c,body:JSON.stringify(t)});if(!s.ok)throw new r("bad_request:api",`Failed to execute agent: ${s.statusText}`);return s.json()}async createFromPrompt(e){let t=await fetch(`${this.agentsUrl}/from-prompt`,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok)throw new r("bad_request:api",`Failed to generate agent from prompt: ${t.statusText}`);let s=await t.json();return this.create({...s,created_by:e.created_by})}};function O(i={}){return new C(i)}var Q=O();var S=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||l;}get widgetsUrl(){return `${this.baseUrl}/widgets`}async list(e={}){let t=new URLSearchParams;e.creatorMid?t.set("creator_mid",e.creatorMid):e.scope&&t.set("scope",e.scope);let s=t.toString(),o=`${this.widgetsUrl}${s?`?${s}`:""}`,n=await fetch(o);if(!n.ok)throw new r("bad_request:api",`Failed to list widgets: ${n.statusText}`);return n.json()}async get(e){let t=await fetch(`${this.widgetsUrl}/${e}`);if(!t.ok)throw new r(t.status===404?"not_found:api":"bad_request:api",`Failed to get widget: ${t.statusText}`);return t.json()}async create(e){let t=await fetch(this.widgetsUrl,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create widget: ${t.statusText}`)}return t.json()}async update(e,t){let s=await fetch(`${this.widgetsUrl}/${e}`,{method:"PUT",headers:c,body:JSON.stringify(t)});if(!s.ok){let o=await s.json().catch(()=>({}));throw new r("bad_request:api",o.error||`Failed to update widget: ${s.statusText}`)}return s.json()}async delete(e){let t=await fetch(`${this.widgetsUrl}/${e}`,{method:"DELETE"});if(!t.ok)throw new r("bad_request:api",`Failed to delete widget: ${t.statusText}`);return t.json()}async getSystemPrompt(){let e=await fetch(`${this.widgetsUrl}/system-prompt`);if(!e.ok)throw new r("bad_request:api",`Failed to get widget system prompt: ${e.statusText}`);return e.json()}async trackUsage(e){await fetch(`${this.widgetsUrl}/${e}/usage`,{method:"POST"}).catch(()=>{});}};function L(i={}){return new S(i)}var Z=L();var $=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||l;}get userUrl(){return `${this.baseUrl}/user`}async getProfile(e){try{let t=await fetch(`${this.userUrl}/profile/${e}`);if(!t.ok){if(t.status===404)return null;throw new r("bad_request:api",`Failed to get user profile: ${t.statusText}`)}return t.json()}catch(t){if(t instanceof r)throw t;return null}}async updateProfile(e,t){let s=await fetch(`${this.userUrl}/profile/${e}`,{method:"PUT",headers:c,body:JSON.stringify(t)});if(!s.ok){let o=await s.json().catch(()=>({}));throw new r("bad_request:api",o.error||`Failed to update user profile: ${s.statusText}`)}return s.json()}};function D(i={}){return new $(i)}var tt=D();var x=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||l;}get filesUrl(){return `${this.baseUrl}/files`}async upload(e,t){let s=new FormData;s.append("file",e,t);let o=await fetch(`${this.filesUrl}/upload`,{method:"POST",body:s});if(!o.ok)throw new r("bad_request:api",`Failed to upload file: ${o.statusText}`);return o.json()}async uploadFromUrl(e){let t=await fetch(`${this.filesUrl}/upload-url`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:e})});if(!t.ok)throw new r("bad_request:api",`Failed to upload file from URL: ${t.statusText}`);return t.json()}getFileUrl(e){return `${this.filesUrl}/${e}`}};function N(i={}){return new x(i)}var et=N();var b=class{baseUrl;useCpxApi;constructor(e={}){this.baseUrl=e.baseUrl||p,this.useCpxApi=e.useCpxApi!==false;}get skillsUrl(){return this.useCpxApi?`${this.baseUrl}/cpx/agent/skills`:`${this.baseUrl}/skills`}async list(e){let t=new URLSearchParams;e?.precompiled?(t.set("precompiled","true"),e?.contentType&&t.set("content_type",e.contentType)):e?.contentType?t.set("content_type",e.contentType):e?.creatorMid?t.set("creator_mid",e.creatorMid):e?.scope&&e.scope!=="all"&&t.set("scope",e.scope);let s=t.toString()?`${this.skillsUrl}?${t.toString()}`:this.skillsUrl,o=await fetch(s);if(!o.ok)throw new Error(`Failed to list skills: ${o.statusText}`);return o.json()}async get(e){let t=await fetch(`${this.skillsUrl}/${e}`);if(!t.ok)throw new Error(`Skill not found: ${e}`);return t.json()}async create(e){let t=await fetch(this.skillsUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new Error(s.error||`Failed to create skill: ${t.statusText}`)}return t.json()}async update(e,t){let s=await fetch(`${this.skillsUrl}/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!s.ok){let o=await s.json().catch(()=>({}));throw new Error(o.error||`Failed to update skill: ${s.statusText}`)}return s.json()}async delete(e){let t=await fetch(`${this.skillsUrl}/${e}`,{method:"DELETE"});if(!t.ok){let s=await t.json().catch(()=>({}));throw new Error(s.error||`Failed to delete skill: ${t.statusText}`)}return t.json()}async trackUsage(e){try{await fetch(`${this.skillsUrl}/${e}/usage`,{method:"POST"});}catch{}}async verify(e){let t=await fetch(`${this.skillsUrl}/${e}/verify`);if(!t.ok)throw new Error(`Failed to verify skill: ${t.statusText}`);return t.json()}async rehash(e){let t=await fetch(`${this.skillsUrl}/${e}/rehash`,{method:"POST"});if(!t.ok)throw new Error(`Failed to rehash skill: ${t.statusText}`);return t.json()}async rehashAll(){let e=await fetch(`${this.skillsUrl}/rehash-all`,{method:"POST"});if(!e.ok)throw new Error(`Failed to rehash all skills: ${e.statusText}`);return e.json()}async getMap(e){let t=e?`?content_type=${e}`:"",s=await fetch(`${this.skillsUrl}/map${t}`);if(!s.ok)throw new Error(`Failed to get skill map: ${s.statusText}`);return s.json()}async getMapPrompt(e){let t=e?`?content_type=${e}`:"",s=await fetch(`${this.skillsUrl}/map/prompt${t}`);if(!s.ok)throw new Error(`Failed to get skill map prompt: ${s.statusText}`);return s.json()}async getNonCodeMap(){let e=await fetch(`${this.skillsUrl}/map/noncode`);if(!e.ok)throw new Error(`Failed to get non-code skill map: ${e.statusText}`);return e.json()}async getNonCodeSummary(){let e=await fetch(`${this.skillsUrl}/summary/noncode`);if(!e.ok)throw new Error(`Failed to get non-code skill summary: ${e.statusText}`);return e.json()}};function M(i){return new b(i)}var st=M();var k=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||p;}get pointsUrl(){return `${this.baseUrl}/cpx/points`}async initNetworkDomain(){let e=await fetch(`${this.pointsUrl}/init`,{method:"POST",headers:c});if(!e.ok){let t=await e.json().catch(()=>({}));throw new r("bad_request:api",t.error||`Failed to initialize network domain: ${e.statusText}`)}return e.json()}async listDomains(){let e=await fetch(`${this.pointsUrl}/domains`);if(!e.ok)throw new r("bad_request:api",`Failed to list domains: ${e.statusText}`);return e.json()}async getDomain(e){let t=await fetch(`${this.pointsUrl}/domains/${e}`);if(t.status===404)return null;if(!t.ok)throw new r("bad_request:api",`Failed to get domain: ${t.statusText}`);return t.json()}async createDomain(e){let t=await fetch(`${this.pointsUrl}/domains`,{method:"POST",headers:c,body:JSON.stringify(e)});if(t.status===402){let s=await t.json();throw new r("payment_required:api",s.error,{paymentDetails:s.paymentDetails})}if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create domain: ${t.statusText}`)}return t.json()}async listContexts(e){let t=e?`?domainId=${e}`:"",s=await fetch(`${this.pointsUrl}/contexts${t}`);if(!s.ok)throw new r("bad_request:api",`Failed to list contexts: ${s.statusText}`);return s.json()}async getContext(e){let t=await fetch(`${this.pointsUrl}/contexts/${e}`);if(t.status===404)return null;if(!t.ok)throw new r("bad_request:api",`Failed to get context: ${t.statusText}`);return t.json()}async createContext(e){let t=await fetch(`${this.pointsUrl}/contexts`,{method:"POST",headers:c,body:JSON.stringify(e)});if(t.status===402){let s=await t.json();throw new r("payment_required:api",s.error,{paymentDetails:s.paymentDetails})}if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create context: ${t.statusText}`)}return t.json()}async listDelegations(e={}){let t=new URLSearchParams;e.domainId&&t.set("domainId",e.domainId),e.delegator&&t.set("delegator",e.delegator),e.delegate&&t.set("delegate",e.delegate),e.activeOnly&&t.set("activeOnly","true");let s=t.toString(),o=`${this.pointsUrl}/delegations${s?`?${s}`:""}`,n=await fetch(o);if(!n.ok)throw new r("bad_request:api",`Failed to list delegations: ${n.statusText}`);return n.json()}async createDelegation(e){let t=await fetch(`${this.pointsUrl}/delegations`,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create delegation: ${t.statusText}`)}return t.json()}async revokeDelegation(e){let t=await fetch(`${this.pointsUrl}/delegations/${e}`,{method:"DELETE"});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to revoke delegation: ${t.statusText}`)}return t.json()}async addPoints(e){let t=await fetch(`${this.pointsUrl}/add`,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to add points: ${t.statusText}`)}return t.json()}async spendPoints(e){let t=await fetch(`${this.pointsUrl}/spend`,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to spend points: ${t.statusText}`)}return t.json()}async getBalance(e,t={}){let s=new URLSearchParams;t.domainId&&s.set("domainId",t.domainId),t.contextId&&s.set("contextId",t.contextId);let o=s.toString(),n=`${this.pointsUrl}/balance/${e}${o?`?${o}`:""}`,a=await fetch(n);if(!a.ok)throw new r("bad_request:api",`Failed to get balance: ${a.statusText}`);return a.json()}async getHistory(e={}){let t=new URLSearchParams;e.mid&&t.set("mid",e.mid),e.domainId&&t.set("domainId",e.domainId),e.contextId&&t.set("contextId",e.contextId),e.periodStart&&t.set("periodStart",e.periodStart.toString()),e.periodEnd&&t.set("periodEnd",e.periodEnd.toString()),e.taskId&&t.set("taskId",e.taskId),e.limit&&t.set("limit",e.limit.toString()),e.offset&&t.set("offset",e.offset.toString());let s=t.toString(),o=`${this.pointsUrl}/history${s?`?${s}`:""}`,n=await fetch(o);if(!n.ok)throw new r("bad_request:api",`Failed to get history: ${n.statusText}`);return n.json()}};function q(i={}){return new k(i)}var ot=q();var U=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||p;}get notificationsUrl(){return `${this.baseUrl}/cpx/notifications`}async list(e){let t=new URLSearchParams;t.set("user_mid",e.user_mid),e.unread_only&&t.set("unread_only","true"),e.type&&t.set("type",e.type),e.source&&t.set("source",e.source),e.limit&&t.set("limit",e.limit.toString()),e.offset&&t.set("offset",e.offset.toString());let s=await fetch(`${this.notificationsUrl}?${t.toString()}`);if(!s.ok)throw new r("bad_request:api",`Failed to list notifications: ${s.statusText}`);return s.json()}async get(e){let t=await fetch(`${this.notificationsUrl}/${e}`);if(t.status===404)return null;if(!t.ok)throw new r("bad_request:api",`Failed to get notification: ${t.statusText}`);return t.json()}async getUnreadCount(e){return (await this.list({user_mid:e,unread_only:true,limit:0})).unread_count}async create(e){let t=await fetch(this.notificationsUrl,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create notification: ${t.statusText}`)}return t.json()}async markAsRead(e){let t=await fetch(`${this.notificationsUrl}/${e}/read`,{method:"PUT"});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to mark notification as read: ${t.statusText}`)}return t.json()}async markAllAsRead(e){let t=await fetch(`${this.notificationsUrl}/read-all`,{method:"PUT",headers:c,body:JSON.stringify({user_mid:e})});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to mark all as read: ${t.statusText}`)}return t.json()}async dismiss(e){let t=await fetch(`${this.notificationsUrl}/${e}`,{method:"DELETE"});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to dismiss notification: ${t.statusText}`)}return t.json()}};function J(i={}){return new U(i)}var rt=J();var P=class{baseUrl;constructor(e={}){this.baseUrl=e.baseUrl||p;}get scoutsUrl(){return `${this.baseUrl}/cpx/scouts`}async list(e={}){let t=new URLSearchParams;e.owner_mid&&t.set("owner_mid",e.owner_mid),e.active_only!==void 0&&t.set("active_only",e.active_only.toString());let s=t.toString(),o=`${this.scoutsUrl}${s?`?${s}`:""}`,n=await fetch(o);if(!n.ok)throw new r("bad_request:api",`Failed to list scouts: ${n.statusText}`);return n.json()}async get(e){let t=await fetch(`${this.scoutsUrl}/${e}`);if(t.status===404)return null;if(!t.ok)throw new r("bad_request:api",`Failed to get scout: ${t.statusText}`);return t.json()}async getHistory(e,t={}){let s=new URLSearchParams;t.limit&&s.set("limit",t.limit.toString()),t.offset&&s.set("offset",t.offset.toString());let o=s.toString(),n=`${this.scoutsUrl}/${e}/history${o?`?${o}`:""}`,a=await fetch(n);if(!a.ok)throw new r("bad_request:api",`Failed to get scout history: ${a.statusText}`);return a.json()}async create(e){let t=await fetch(this.scoutsUrl,{method:"POST",headers:c,body:JSON.stringify(e)});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to create scout: ${t.statusText}`)}return t.json()}async update(e,t){let s=await fetch(`${this.scoutsUrl}/${e}`,{method:"PUT",headers:c,body:JSON.stringify(t)});if(!s.ok){let o=await s.json().catch(()=>({}));throw new r("bad_request:api",o.error||`Failed to update scout: ${s.statusText}`)}return s.json()}async trigger(e){let t=await fetch(`${this.scoutsUrl}/${e}/trigger`,{method:"POST"});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to trigger scout: ${t.statusText}`)}return t.json()}async activate(e){return this.update(e,{is_active:true})}async deactivate(e){return this.update(e,{is_active:false})}async delete(e){let t=await fetch(`${this.scoutsUrl}/${e}`,{method:"DELETE"});if(!t.ok){let s=await t.json().catch(()=>({}));throw new r("bad_request:api",s.error||`Failed to delete scout: ${t.statusText}`)}return t.json()}};function W(i={}){return new P(i)}var nt=W();
4
+ export{C as AgentsClient,x as FilesClient,y as MCPClient,g as MagmaClient,U as NotificationsClient,k as PointsClient,P as ScoutsClient,b as SkillsClient,w as SocialClient,f as TaskNetworkClient,$ as UserClient,S as WidgetsClient,Q as agentsClient,O as createAgentsClient,N as createFilesClient,v as createMCPClient,j as createMagmaClient,J as createNotificationsClient,q as createPointsClient,W as createScoutsClient,M as createSkillsClient,I as createSocialClient,E as createTaskNetworkClient,D as createUserClient,L as createWidgetsClient,et as filesClient,G as magmaClient,H as mcpClient,rt as notificationsClient,ot as pointsClient,nt as scoutsClient,st as skillsClient,X as socialClient,B as taskNetworkClient,tt as userClient,Z as widgetsClient};
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Coder type definitions
3
+ * Types for the GeoffCoder AI coding agent
4
+ */
5
+ type CoderSessionStatus = 'active' | 'completed' | 'aborted' | 'error';
6
+ interface CoderSession {
7
+ id: string;
8
+ workingDirectory: string;
9
+ status: CoderSessionStatus;
10
+ createdAt: string;
11
+ updatedAt?: string;
12
+ metrics: CoderMetrics;
13
+ sandboxId?: string;
14
+ }
15
+ interface CoderMetrics {
16
+ tokensUsed: number;
17
+ promptTokens: number;
18
+ completionTokens: number;
19
+ contextSize: number;
20
+ filesCreated: number;
21
+ filesModified: number;
22
+ linesAdded: number;
23
+ linesRemoved: number;
24
+ commandsExecuted: number;
25
+ toolCallsTotal: number;
26
+ apiCalls: number;
27
+ startTime: number;
28
+ endTime?: number;
29
+ modifiedFiles: string[];
30
+ createdFiles: string[];
31
+ }
32
+ interface CoderExecuteRequest {
33
+ /** The prompt/task for the coder agent */
34
+ prompt: string;
35
+ /** Working directory for file operations */
36
+ workingDirectory?: string;
37
+ /** Maximum iterations for the agent loop */
38
+ maxIterations?: number;
39
+ /** Model to use for completions */
40
+ model?: string;
41
+ /** Maximum tokens per response */
42
+ maxTokens?: number;
43
+ /** Temperature for generation */
44
+ temperature?: number;
45
+ /** Whether to stream the response */
46
+ stream?: boolean;
47
+ /** Existing session ID to continue */
48
+ sessionId?: string;
49
+ /** Existing sandbox ID to use (from frontend) */
50
+ sandboxId?: string;
51
+ /** E2B sandbox configuration */
52
+ sandbox?: CoderSandboxConfig;
53
+ }
54
+ interface CoderSandboxConfig {
55
+ /** Enable sandbox execution */
56
+ enabled: boolean;
57
+ /** Sandbox template (e.g., 'node', 'python', 'nextjs') */
58
+ template?: string;
59
+ /** Session timeout in seconds */
60
+ timeout?: number;
61
+ /** Environment variables */
62
+ env?: Record<string, string>;
63
+ /** Packages to pre-install */
64
+ packages?: string[];
65
+ }
66
+ interface CoderExecuteResponse {
67
+ sessionId: string;
68
+ status: CoderSessionStatus;
69
+ result?: string;
70
+ error?: string;
71
+ metrics: CoderMetrics;
72
+ }
73
+ type CoderStreamEventType = 'session_start' | 'thinking' | 'tool_call' | 'tool_result' | 'assistant_message' | 'progress' | 'metrics_update' | 'session_complete' | 'error';
74
+ interface CoderStreamEvent {
75
+ type: CoderStreamEventType;
76
+ data: unknown;
77
+ timestamp: number;
78
+ }
79
+ interface CoderThinkingEvent {
80
+ type: 'thinking';
81
+ data: {
82
+ content: string;
83
+ iteration: number;
84
+ };
85
+ }
86
+ interface CoderToolCallEvent {
87
+ type: 'tool_call';
88
+ data: {
89
+ toolName: string;
90
+ arguments: Record<string, unknown>;
91
+ toolCallId: string;
92
+ };
93
+ }
94
+ interface CoderToolResultEvent {
95
+ type: 'tool_result';
96
+ data: {
97
+ toolCallId: string;
98
+ toolName: string;
99
+ success: boolean;
100
+ output: string;
101
+ error?: string;
102
+ };
103
+ }
104
+ interface CoderProgressEvent {
105
+ type: 'progress';
106
+ data: {
107
+ iteration: number;
108
+ maxIterations: number;
109
+ currentAction: string;
110
+ };
111
+ }
112
+ interface CoderTool {
113
+ name: string;
114
+ description: string;
115
+ parameters: {
116
+ type: 'object';
117
+ properties: Record<string, CoderToolParameter>;
118
+ required?: string[];
119
+ };
120
+ }
121
+ interface CoderToolParameter {
122
+ type: string;
123
+ description: string;
124
+ enum?: string[];
125
+ }
126
+ interface CoderToolResult {
127
+ success: boolean;
128
+ output: string;
129
+ error?: string;
130
+ }
131
+ interface CoderFileInfo {
132
+ name: string;
133
+ path: string;
134
+ size: number;
135
+ isDirectory: boolean;
136
+ modified?: string;
137
+ children?: CoderFileInfo[];
138
+ }
139
+ interface CoderFileContent {
140
+ path: string;
141
+ content: string;
142
+ encoding?: 'utf8' | 'base64';
143
+ size: number;
144
+ }
145
+ interface CoderFileWriteInput {
146
+ path: string;
147
+ content: string;
148
+ encoding?: 'utf8' | 'base64';
149
+ createDirectories?: boolean;
150
+ }
151
+ interface CoderSearchResult {
152
+ file: string;
153
+ line: number;
154
+ content: string;
155
+ contextBefore?: string[];
156
+ contextAfter?: string[];
157
+ }
158
+ interface CoderDiffInput {
159
+ path: string;
160
+ original: string;
161
+ replacement: string;
162
+ replaceAll?: boolean;
163
+ }
164
+ interface CoderCommandResult {
165
+ stdout: string;
166
+ stderr: string;
167
+ exitCode: number;
168
+ executionTimeMs: number;
169
+ }
170
+ interface CoderCommandInput {
171
+ command: string;
172
+ timeout?: number;
173
+ cwd?: string;
174
+ }
175
+ interface CoderSandbox {
176
+ id: string;
177
+ status: 'creating' | 'ready' | 'busy' | 'stopped' | 'error';
178
+ template: string;
179
+ workingDirectory: string;
180
+ createdAt: string;
181
+ expiresAt?: string;
182
+ }
183
+ interface CoderSandboxCreateInput {
184
+ template?: string;
185
+ timeout?: number;
186
+ env?: Record<string, string>;
187
+ packages?: string[];
188
+ }
189
+ interface CoderSandboxExecInput {
190
+ command: string;
191
+ timeout?: number;
192
+ stream?: boolean;
193
+ }
194
+ interface CoderSandboxExecResult {
195
+ stdout: string;
196
+ stderr: string;
197
+ exitCode: number;
198
+ executionTimeMs: number;
199
+ }
200
+ interface CoderSessionResponse {
201
+ session: CoderSession;
202
+ }
203
+ interface CoderSessionsListResponse {
204
+ sessions: CoderSession[];
205
+ }
206
+ interface CoderToolsResponse {
207
+ tools: CoderTool[];
208
+ }
209
+ interface CoderFilesResponse {
210
+ files: CoderFileInfo[];
211
+ path: string;
212
+ }
213
+ interface CoderSandboxResponse {
214
+ sandbox: CoderSandbox;
215
+ }
216
+ interface CoderClientConfig {
217
+ /** Base URL for the task network API */
218
+ baseUrl?: string;
219
+ /** API key for authentication */
220
+ apiKey?: string;
221
+ /** Request timeout in milliseconds */
222
+ timeout?: number;
223
+ /** Default model for coder sessions */
224
+ defaultModel?: string;
225
+ /** Default max iterations */
226
+ defaultMaxIterations?: number;
227
+ }
228
+
229
+ export type { CoderSessionsListResponse as A, CoderToolsResponse as B, CoderSessionStatus as C, CoderFilesResponse as D, CoderSandboxResponse as E, CoderClientConfig as F, CoderSession as a, CoderMetrics as b, CoderExecuteRequest as c, CoderSandboxConfig as d, CoderExecuteResponse as e, CoderStreamEventType as f, CoderStreamEvent as g, CoderThinkingEvent as h, CoderToolCallEvent as i, CoderToolResultEvent as j, CoderProgressEvent as k, CoderTool as l, CoderToolParameter as m, CoderToolResult as n, CoderFileInfo as o, CoderFileContent as p, CoderFileWriteInput as q, CoderSearchResult as r, CoderDiffInput as s, CoderCommandResult as t, CoderCommandInput as u, CoderSandbox as v, CoderSandboxCreateInput as w, CoderSandboxExecInput as x, CoderSandboxExecResult as y, CoderSessionResponse as z };