@zibby/skills 0.2.1 → 0.2.2
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/dist/datasetStore.js +2 -2
- package/dist/index.js +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/datasetStore.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{existsSync as f,readFileSync as b}from"node:fs";import{homedir as T}from"node:os";import{join as S,dirname as O,resolve as w}from"node:path";import{fileURLToPath as _}from"node:url";function
|
|
1
|
+
import{existsSync as f,readFileSync as b}from"node:fs";import{homedir as T}from"node:os";import{join as S,dirname as O,resolve as w}from"node:path";import{fileURLToPath as _}from"node:url";function I(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let n=O(_(import.meta.url)),t=w(n,"..","bin","mcp-skill.mjs");return f(t)?t:null}function m(){if(process.env.PROJECT_API_TOKEN)return process.env.PROJECT_API_TOKEN;if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let n=S(T(),".zibby","config.json");return f(n)&&JSON.parse(b(n,"utf-8")).sessionToken||null}catch{return null}}function h(){return process.env.ZIBBY_ACCOUNT_API_URL?process.env.ZIBBY_ACCOUNT_API_URL.replace(/\/$/,""):(process.env.ZIBBY_ENV||"prod")==="local"?"http://localhost:3001":process.env.ZIBBY_PROD_ACCOUNT_API_URL||"https://api-prod.zibby.app"}function y(){return(typeof process.env.WORKFLOW_TYPE=="string"?process.env.WORKFLOW_TYPE.trim():"")||"agent"}function A(){let n={};for(let[t,e]of Object.entries(process.env)){let r=/^ZIBBY_STORE__(.+)$/.exec(t);if(!r)continue;let o=typeof e=="string"?e.trim():"";o&&(n[r[1]]=o)}return n}var u={};function C(){for(let n of Object.keys(u))delete u[n]}function p(n){let t={...A(),...u},e=Object.keys(t),r=typeof n=="string"?n.trim():"";return r?Object.prototype.hasOwnProperty.call(t,r)?{storeId:t[r],name:r}:{error:`unknown store '${r}'; available: ${e.join(", ")}`}:e.length===1?{storeId:t[e[0]],name:e[0]}:e.length===0?{error:"no stores bound to this agent"}:{error:`multiple stores are bound; pass \`store\` (one of: ${e.join(", ")})`}}async function N(n){let t=m();if(!t)throw new Error("No backend credential (PROJECT_API_TOKEN). Stores are only available inside a Zibby run.");let e=await fetch(`${h()}/datasets/stores/ensure`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify(n)});if(!e.ok){let r=await e.text().catch(()=>"");throw new Error(`ensure_store failed (${e.status}): ${r.slice(0,300)}`)}return e.json()}async function a(n,t,e){let r=m();if(!r)throw new Error("No backend credential (PROJECT_API_TOKEN). Dataset store is only available inside a Zibby run.");let o=`${h()}/datasets/stores/${encodeURIComponent(n)}/${t}`,s=await fetch(o,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify(e)});if(!s.ok){let i=await s.text().catch(()=>"");throw new Error(`Store ${t} failed (${s.status}): ${i.slice(0,300)}`)}return s.json()}var L=Math.floor(3.5*1024*1024);async function B(n,t,e,r){let o=await a(n,"put-url",{path:t,contentType:r});if(!o?.url)throw new Error("put-url did not return an upload URL");let s=await fetch(o.url,{method:o.method||"PUT",headers:o.headers||{"Content-Type":r},body:e});if(!s.ok){let i=await s.text().catch(()=>"");throw new Error(`direct upload failed (${s.status}): ${i.slice(0,200)}`)}return{ok:!0,path:o.path||t,size:e.length,contentType:o.contentType||r,via:"presign"}}async function R(n,t){let e=await a(n,"get-url",{path:t});if(!e?.url)throw new Error("get-url did not return a download URL");let r=await fetch(e.url,{method:e.method||"GET"});if(!r.ok){let s=await r.text().catch(()=>"");throw new Error(`direct download failed (${r.status}): ${s.slice(0,200)}`)}let o=await r.arrayBuffer();return{buf:Buffer.from(o),contentType:r.headers.get("content-type")||"application/octet-stream"}}var P={id:"dataset-store",serverName:"dataset_store",allowedTools:["mcp__dataset_store__*"],description:"Dataset store \u2014 a durable, queryable store for structured JSON records; append rows now, run SQL-style aggregations/reports later",promptFragment:`## Dataset Store (durable, queryable structured-record store)
|
|
2
2
|
You have one or more durable stores for STRUCTURED records that survive across
|
|
3
3
|
your stateless runs. Unlike key-value memory (for picking up where you left
|
|
4
4
|
off), this is for accumulating DATA you want to QUERY and AGGREGATE later \u2014 e.g.
|
|
@@ -45,4 +45,4 @@ Tools:
|
|
|
45
45
|
- file_list: (file stores) List stored files (optionally by path prefix).
|
|
46
46
|
- file_delete: (file stores) Delete ONE file by path.
|
|
47
47
|
Pick the tool that matches the store's TYPE; using a dataset tool on a sqlite
|
|
48
|
-
store (or a file tool on either, etc.) is rejected.`,resolve(){let n=A();if(!n)return{command:null,args:[],env:{},description:this.description};let t={};for(let e of["PROJECT_API_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV","ZIBBY_PROD_ACCOUNT_API_URL","ZIBBY_USER_TOKEN","WORKFLOW_TYPE"])process.env[e]&&(t[e]=process.env[e]);for(let e of Object.keys(process.env))/^ZIBBY_STORE__.+$/.test(e)&&process.env[e]&&(t[e]=process.env[e]);return{type:"stdio",command:"node",args:[n,"../dist/datasetStore.js","datasetStoreSkill"],env:t,description:this.description,alwaysLoad:!1}},async handleToolCall(n,t){try{switch(n){case"dataset_append":{if(t?.record==null||typeof t.record!="object"||Array.isArray(t.record))return JSON.stringify({error:"record is required (a JSON object)"});let e=d(t?.store);if(e.error)return JSON.stringify({error:e.error});let r=typeof t?.agent=="string"&&t.agent.trim()?t.agent.trim():y(),o={record:t.record,agent:r};typeof t?.description=="string"&&t.description.trim()&&(o.description=t.description.trim());let s=await a(e.storeId,"append",o);return JSON.stringify({...s,store:e.name,storeId:e.storeId})}case"dataset_query":{let e=d(t?.store);if(e.error)return JSON.stringify({error:e.error});let r={};for(let s of["select","where","groupBy","orderBy","limit","since","until","agent"])t?.[s]!=null&&(r[s]=t[s]);let o=await a(e.storeId,"query",r);return JSON.stringify({...o,store:e.name,storeId:e.storeId})}case"ensure_store":{let e=typeof t?.name=="string"?t.name.trim():"";if(!e)return JSON.stringify({error:"name is required"});let r=typeof t?.type=="string"&&t.type.trim()?t.type.trim().toLowerCase():"sqlite",o=typeof t?.description=="string"?t.description.trim():"",s=await N({name:e,type:r,description:o,namespace:y()});return s?.storeId&&(u[e]=s.storeId),JSON.stringify({...s,store:e})}case"file_put":{let e=d(t?.store);if(e.error)return JSON.stringify({error:e.error});if(typeof t?.path!="string"||!t.path.trim())return JSON.stringify({error:'path is required (a relative file path like "reports/2026-07.json")'});let r=typeof t?.content=="string",o=typeof t?.contentBase64=="string"&&t.contentBase64.length>0;if(!r&&!o)return JSON.stringify({error:"content (text) or contentBase64 (base64 bytes) is required"});let s=t.path.trim(),i=typeof t?.contentType=="string"&&t.contentType.trim()?t.contentType.trim():"",p=r?Buffer.from(t.content,"utf8"):Buffer.from(String(t.contentBase64).replace(/\s+/g,""),"base64");if(p.length>L){let g=i||(r?"text/plain; charset=utf-8":"application/octet-stream"),E=await B(e.storeId,s,p,g);return JSON.stringify({...E,store:e.name,storeId:e.storeId})}let c={path:s};r?c.content=t.content:c.contentBase64=t.contentBase64,i&&(c.contentType=i);let l=await a(e.storeId,"put",c);return JSON.stringify({...l,store:e.name,storeId:e.storeId})}case"file_get":{let e=d(t?.store);if(e.error)return JSON.stringify({error:e.error});if(typeof t?.path!="string"||!t.path.trim())return JSON.stringify({error:"path is required"});let r=t.path.trim(),o;try{o=await a(e.storeId,"get",{path:r})}catch(c){if(!/failed \(413\)/.test(c?.message||""))throw c;let l=await R(e.storeId,r);o={path:r,size:l.buf.length,contentType:l.contentType,lastModified:null,contentBase64:l.buf.toString("base64")}}let s={ok:!0,store:e.name,storeId:e.storeId,path:o.path,size:o.size,contentType:o.contentType,lastModified:o.lastModified},i=Buffer.from(o.contentBase64||"","base64"),p=i.toString("utf8");return Buffer.compare(Buffer.from(p,"utf8"),i)===0&&!p.includes("\0")?(s.content=p,s.encoding="utf8"):(s.contentBase64=o.contentBase64,s.encoding="base64"),JSON.stringify(s)}case"file_list":{let e=d(t?.store);if(e.error)return JSON.stringify({error:e.error});let r={};typeof t?.prefix=="string"&&t.prefix.trim()&&(r.prefix=t.prefix.trim()),t?.limit!=null&&(r.limit=t.limit),typeof t?.cursor=="string"&&t.cursor&&(r.cursor=t.cursor);let o=await a(e.storeId,"list",r);return JSON.stringify({...o,store:e.name,storeId:e.storeId})}case"file_delete":{let e=d(t?.store);if(e.error)return JSON.stringify({error:e.error});if(typeof t?.path!="string"||!t.path.trim())return JSON.stringify({error:"path is required"});let r=await a(e.storeId,"delete",{path:t.path.trim()});return JSON.stringify({...r,store:e.name,storeId:e.storeId})}case"sqlite_exec":case"sqlite_query":{let e=d(t?.store);if(e.error)return JSON.stringify({error:e.error});if(typeof t?.sql!="string"||!t.sql.trim())return JSON.stringify({error:"sql is required (a non-empty SQL string)"});let r={sql:t.sql};Array.isArray(t?.params)&&(r.params=t.params);let o=await a(e.storeId,"sql",r);return JSON.stringify({...o,store:e.name,storeId:e.storeId})}default:return JSON.stringify({error:`Unknown tool: ${n}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"dataset_append",description:"Append ONE structured JSON record to a bound store, durably. Records persist across your stateless runs and are auto-tagged with your agent type so you can filter to your own writes later. Use to accumulate data you will query/aggregate (e.g. per-run metrics, processed items). Append ONE record per call.",input_schema:{type:"object",properties:{store:{type:"string",description:'The logical store NAME to write to (e.g. "scorecards"), taken from the AVAILABLE STORES list \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this and it defaults to that store; you can ONLY write to a bound store name.'},record:{type:"object",description:'An arbitrary JSON object \u2014 one row of data. Its keys become queryable fields (e.g. {"repo":"owner/x","stars":1200}). One record per call.'},description:{type:"string",description:"Optional, informational note about this write. The store already exists from deploy, so this is not required and does not create anything."},agent:{type:"string",description:"Optional writing-agent tag. Defaults to your own agent type \u2014 leave unset to auto-tag."}},required:["record"]}},{name:"dataset_query",description:"Run a SQL-style query over a bound store to build reports: select/aggregate (count|sum|avg|min|max), filter, group, order, limit, and bound by month. Returns { columns, rows }. Use this to compute summaries/aggregations from records you appended earlier.",input_schema:{type:"object",properties:{store:{type:"string",description:'The logical store NAME to query (e.g. "scorecards"), taken from the AVAILABLE STORES list \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this and it defaults to that store.'},select:{type:"array",description:"Columns to return. Each item is { field?, agg?, as? }. agg \u2208 count|sum|avg|min|max; omit field for count(*). Omit `select` entirely to return raw rows."},where:{type:"array",description:"Filters, ANDed. Each item is { field, op, value }; op \u2208 eq|ne|gt|gte|lt|lte|like. `field` is a JSON key of the stored record."},groupBy:{type:"array",description:"Field names to group by (array of strings) for aggregation."},orderBy:{type:"array",description:"Sort spec. Each item is { field|as, dir }; dir \u2208 asc|desc."},limit:{type:"number",description:"Maximum number of rows to return."},since:{type:"string",description:"Inclusive lower bound month, 'yyyy-MM' (e.g. '2026-01')."},until:{type:"string",description:"Inclusive upper bound month, 'yyyy-MM' (e.g. '2026-06')."},agent:{type:"string",description:"Filter to records written by one agent namespace. Omit to query across all writers."}},required:[]}},{name:"ensure_store",description:'Create (or reuse) a store ON DEMAND for THIS agent \u2014 use when you need a store that was NOT declared/bound at deploy. Idempotent by name and private to this agent: calling again with the same name returns the SAME store (safe to call at the start of every run). Returns { storeId }. For type "sqlite" you then define schema with sqlite_exec (CREATE TABLE IF NOT EXISTS) and read/write via sqlite_exec/sqlite_query using this name.',input_schema:{type:"object",properties:{name:{type:"string",description:'A short logical name for the store (e.g. "linkedin_posts"). Letters, digits, _ and - only.'},type:{type:"string",enum:["sqlite","dataset","file"],description:'Store type. "sqlite" (default) = a mutable relational DB whose schema YOU define with SQL. "dataset" = append-only JSON records for later aggregation/analytics. "file" = arbitrary file/blob storage by relative path (file_put/file_get/file_list/file_delete).'},description:{type:"string",description:"What this store is for (shown in the Storage UI)."}},required:["name"]}},{name:"sqlite_exec",description:"For SQLITE-type stores: run SQL that CHANGES data \u2014 CREATE TABLE (use IF NOT EXISTS), INSERT, UPDATE, DELETE (one or more statements in one call). The store is a real, mutable SQLite database that persists across your stateless runs. Returns { rowsModified, wrote }. Use this to build schema on the fly and to update rows / track changing state (e.g. a queue with a status column).",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a sqlite-type store from AVAILABLE STORES) \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this."},sql:{type:"string",description:'The SQL to run. May contain multiple statements separated by ";". Prefer CREATE TABLE IF NOT EXISTS for idempotent schema.'},params:{type:"array",description:'Optional positional bind params for a SINGLE parameterized statement (safe binding of values), e.g. sql "UPDATE t SET s=? WHERE id=?" with params ["done", 1].'}},required:["sql"]}},{name:"sqlite_query",description:"For SQLITE-type stores: run a read-only SELECT (optionally with `params` for safe binding) against the store's SQLite database. Returns { columns, rows }. Never changes data. Use to read back rows/state you stored earlier.",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a sqlite-type store from AVAILABLE STORES) \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this."},sql:{type:"string",description:"A single SELECT statement. Use ? placeholders + `params` for any values."},params:{type:"array",description:'Optional positional bind params for the SELECT, e.g. ["linkedin_personal"].'}},required:["sql"]}},{name:"file_put",description:"For FILE-type stores: write (or overwrite) ONE file at a relative path \u2014 raw JSON dumps, CSVs, images, snapshots, any blob you want to keep across your stateless runs. Text goes in `content`; binary goes base64-encoded in `contentBase64` (pass exactly one). Max 4 MiB per file. Overwriting the same path UPDATES the file. Returns { ok, path, size }.",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES) \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this."},path:{type:"string",description:'Relative file path, e.g. "dumps/run-42.json" or "img/chart.png". Letters, digits, ".", "_", "-" and "/" only; no "..", no leading "/".'},content:{type:"string",description:"Text content (UTF-8). Use for JSON/CSV/text files."},contentBase64:{type:"string",description:"Base64-encoded binary content (images etc.). Alternative to `content`."},contentType:{type:"string",description:'Optional MIME type (e.g. "application/json", "image/png"). Defaults sensibly.'}},required:["path"]}},{name:"file_get",description:'For FILE-type stores: read ONE stored file back by its relative path. Text files come back as `content` (encoding "utf8"); binary files come back as `contentBase64` (encoding "base64"). Returns { path, size, contentType, lastModified, content|contentBase64, encoding }.',input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES). If exactly one store is bound you may omit this."},path:{type:"string",description:"The relative file path to fetch (as listed by file_list / used in file_put)."}},required:["path"]}},{name:"file_list",description:'For FILE-type stores: list the stored files \u2014 each entry has { path, size, lastModified }. Optionally filter by a path `prefix` (e.g. "dumps/"). Paginated via `cursor` when there are more results.',input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES). If exactly one store is bound you may omit this."},prefix:{type:"string",description:'Optional path prefix filter, e.g. "dumps/" or "reports/2026".'},limit:{type:"number",description:"Max entries to return (default/max 1000)."},cursor:{type:"string",description:"Pagination cursor from a previous file_list response (nextCursor)."}},required:[]}},{name:"file_delete",description:"For FILE-type stores: delete ONE stored file by its relative path. Returns { ok, path, deleted }. Errors if the path does not exist.",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES). If exactly one store is bound you may omit this."},path:{type:"string",description:"The relative file path to delete."}},required:["path"]}}]};export{P as __clearEnsuredStores,C as datasetStoreSkill};
|
|
48
|
+
store (or a file tool on either, etc.) is rejected.`,resolve(){let n=I();if(!n)return{command:null,args:[],env:{},description:this.description};let t={};for(let e of["PROJECT_API_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV","ZIBBY_PROD_ACCOUNT_API_URL","ZIBBY_USER_TOKEN","WORKFLOW_TYPE"])process.env[e]&&(t[e]=process.env[e]);for(let e of Object.keys(process.env))/^ZIBBY_STORE__.+$/.test(e)&&process.env[e]&&(t[e]=process.env[e]);return{type:"stdio",command:"node",args:[n,"../dist/datasetStore.js","datasetStoreSkill"],env:t,description:this.description,alwaysLoad:!1}},async handleToolCall(n,t){try{switch(n){case"dataset_append":{if(t?.record==null||typeof t.record!="object"||Array.isArray(t.record))return JSON.stringify({error:"record is required (a JSON object)"});let e=p(t?.store);if(e.error)return JSON.stringify({error:e.error});let r=typeof t?.agent=="string"&&t.agent.trim()?t.agent.trim():y(),o={record:t.record,agent:r};typeof t?.description=="string"&&t.description.trim()&&(o.description=t.description.trim());let s=await a(e.storeId,"append",o);return JSON.stringify({...s,store:e.name,storeId:e.storeId})}case"dataset_query":{let e=p(t?.store);if(e.error)return JSON.stringify({error:e.error});let r={};for(let s of["select","where","groupBy","orderBy","limit","since","until","agent"])t?.[s]!=null&&(r[s]=t[s]);let o=await a(e.storeId,"query",r);return JSON.stringify({...o,store:e.name,storeId:e.storeId})}case"ensure_store":{let e=typeof t?.name=="string"?t.name.trim():"";if(!e)return JSON.stringify({error:"name is required"});let r=typeof t?.type=="string"&&t.type.trim()?t.type.trim().toLowerCase():"sqlite",o=typeof t?.description=="string"?t.description.trim():"",s=await N({name:e,type:r,description:o,namespace:y()});return s?.storeId&&(u[e]=s.storeId),JSON.stringify({...s,store:e})}case"file_put":{let e=p(t?.store);if(e.error)return JSON.stringify({error:e.error});if(typeof t?.path!="string"||!t.path.trim())return JSON.stringify({error:'path is required (a relative file path like "reports/2026-07.json")'});let r=typeof t?.content=="string",o=typeof t?.contentBase64=="string"&&t.contentBase64.length>0;if(!r&&!o)return JSON.stringify({error:"content (text) or contentBase64 (base64 bytes) is required"});let s=t.path.trim(),i=typeof t?.contentType=="string"&&t.contentType.trim()?t.contentType.trim():"",d=r?Buffer.from(t.content,"utf8"):Buffer.from(String(t.contentBase64).replace(/\s+/g,""),"base64");if(d.length>L){let g=i||(r?"text/plain; charset=utf-8":"application/octet-stream"),E=await B(e.storeId,s,d,g);return JSON.stringify({...E,store:e.name,storeId:e.storeId})}let c={path:s};r?c.content=t.content:c.contentBase64=t.contentBase64,i&&(c.contentType=i);let l=await a(e.storeId,"put",c);return JSON.stringify({...l,store:e.name,storeId:e.storeId})}case"file_get":{let e=p(t?.store);if(e.error)return JSON.stringify({error:e.error});if(typeof t?.path!="string"||!t.path.trim())return JSON.stringify({error:"path is required"});let r=t.path.trim(),o;try{o=await a(e.storeId,"get",{path:r})}catch(c){if(!/failed \(413\)/.test(c?.message||""))throw c;let l=await R(e.storeId,r);o={path:r,size:l.buf.length,contentType:l.contentType,lastModified:null,contentBase64:l.buf.toString("base64")}}let s={ok:!0,store:e.name,storeId:e.storeId,path:o.path,size:o.size,contentType:o.contentType,lastModified:o.lastModified},i=Buffer.from(o.contentBase64||"","base64"),d=i.toString("utf8");return Buffer.compare(Buffer.from(d,"utf8"),i)===0&&!d.includes("\0")?(s.content=d,s.encoding="utf8"):(s.contentBase64=o.contentBase64,s.encoding="base64"),JSON.stringify(s)}case"file_list":{let e=p(t?.store);if(e.error)return JSON.stringify({error:e.error});let r={};typeof t?.prefix=="string"&&t.prefix.trim()&&(r.prefix=t.prefix.trim()),t?.limit!=null&&(r.limit=t.limit),typeof t?.cursor=="string"&&t.cursor&&(r.cursor=t.cursor);let o=await a(e.storeId,"list",r);return JSON.stringify({...o,store:e.name,storeId:e.storeId})}case"file_delete":{let e=p(t?.store);if(e.error)return JSON.stringify({error:e.error});if(typeof t?.path!="string"||!t.path.trim())return JSON.stringify({error:"path is required"});let r=await a(e.storeId,"delete",{path:t.path.trim()});return JSON.stringify({...r,store:e.name,storeId:e.storeId})}case"sqlite_exec":case"sqlite_query":{let e=p(t?.store);if(e.error)return JSON.stringify({error:e.error});if(typeof t?.sql!="string"||!t.sql.trim())return JSON.stringify({error:"sql is required (a non-empty SQL string)"});let r={sql:t.sql};Array.isArray(t?.params)&&(r.params=t.params);let o=await a(e.storeId,"sql",r);return JSON.stringify({...o,store:e.name,storeId:e.storeId})}default:return JSON.stringify({error:`Unknown tool: ${n}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"dataset_append",description:"Append ONE structured JSON record to a bound store, durably. Records persist across your stateless runs and are auto-tagged with your agent type so you can filter to your own writes later. Use to accumulate data you will query/aggregate (e.g. per-run metrics, processed items). Append ONE record per call.",input_schema:{type:"object",properties:{store:{type:"string",description:'The logical store NAME to write to (e.g. "scorecards"), taken from the AVAILABLE STORES list \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this and it defaults to that store; you can ONLY write to a bound store name.'},record:{type:"object",description:'An arbitrary JSON object \u2014 one row of data. Its keys become queryable fields (e.g. {"repo":"owner/x","stars":1200}). One record per call.'},description:{type:"string",description:"Optional, informational note about this write. The store already exists from deploy, so this is not required and does not create anything."},agent:{type:"string",description:"Optional writing-agent tag. Defaults to your own agent type \u2014 leave unset to auto-tag."}},required:["record"]}},{name:"dataset_query",description:"Run a SQL-style query over a bound store to build reports: select/aggregate (count|sum|avg|min|max), filter, group, order, limit, and bound by month. Returns { columns, rows }. Use this to compute summaries/aggregations from records you appended earlier.",input_schema:{type:"object",properties:{store:{type:"string",description:'The logical store NAME to query (e.g. "scorecards"), taken from the AVAILABLE STORES list \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this and it defaults to that store.'},select:{type:"array",description:"Columns to return. Each item is { field?, agg?, as? }. agg \u2208 count|sum|avg|min|max; omit field for count(*). Omit `select` entirely to return raw rows."},where:{type:"array",description:"Filters, ANDed. Each item is { field, op, value }; op \u2208 eq|ne|gt|gte|lt|lte|like. `field` is a JSON key of the stored record."},groupBy:{type:"array",description:"Field names to group by (array of strings) for aggregation."},orderBy:{type:"array",description:"Sort spec. Each item is { field|as, dir }; dir \u2208 asc|desc."},limit:{type:"number",description:"Maximum number of rows to return."},since:{type:"string",description:"Inclusive lower bound month, 'yyyy-MM' (e.g. '2026-01')."},until:{type:"string",description:"Inclusive upper bound month, 'yyyy-MM' (e.g. '2026-06')."},agent:{type:"string",description:"Filter to records written by one agent namespace. Omit to query across all writers."}},required:[]}},{name:"ensure_store",description:'Create (or reuse) a store ON DEMAND for THIS agent \u2014 use when you need a store that was NOT declared/bound at deploy. Idempotent by name and private to this agent: calling again with the same name returns the SAME store (safe to call at the start of every run). Returns { storeId }. For type "sqlite" you then define schema with sqlite_exec (CREATE TABLE IF NOT EXISTS) and read/write via sqlite_exec/sqlite_query using this name.',input_schema:{type:"object",properties:{name:{type:"string",description:'A short logical name for the store (e.g. "linkedin_posts"). Letters, digits, _ and - only.'},type:{type:"string",enum:["sqlite","dataset","file"],description:'Store type. "sqlite" (default) = a mutable relational DB whose schema YOU define with SQL. "dataset" = append-only JSON records for later aggregation/analytics. "file" = arbitrary file/blob storage by relative path (file_put/file_get/file_list/file_delete).'},description:{type:"string",description:"What this store is for (shown in the Storage UI)."}},required:["name"]}},{name:"sqlite_exec",description:"For SQLITE-type stores: run SQL that CHANGES data \u2014 CREATE TABLE (use IF NOT EXISTS), INSERT, UPDATE, DELETE (one or more statements in one call). The store is a real, mutable SQLite database that persists across your stateless runs. Returns { rowsModified, wrote }. Use this to build schema on the fly and to update rows / track changing state (e.g. a queue with a status column).",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a sqlite-type store from AVAILABLE STORES) \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this."},sql:{type:"string",description:'The SQL to run. May contain multiple statements separated by ";". Prefer CREATE TABLE IF NOT EXISTS for idempotent schema.'},params:{type:"array",description:'Optional positional bind params for a SINGLE parameterized statement (safe binding of values), e.g. sql "UPDATE t SET s=? WHERE id=?" with params ["done", 1].'}},required:["sql"]}},{name:"sqlite_query",description:"For SQLITE-type stores: run a read-only SELECT (optionally with `params` for safe binding) against the store's SQLite database. Returns { columns, rows }. Never changes data. Use to read back rows/state you stored earlier.",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a sqlite-type store from AVAILABLE STORES) \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this."},sql:{type:"string",description:"A single SELECT statement. Use ? placeholders + `params` for any values."},params:{type:"array",description:'Optional positional bind params for the SELECT, e.g. ["linkedin_personal"].'}},required:["sql"]}},{name:"file_put",description:"For FILE-type stores: write (or overwrite) ONE file at a relative path \u2014 raw JSON dumps, CSVs, images, snapshots, any blob you want to keep across your stateless runs. Text goes in `content`; binary goes base64-encoded in `contentBase64` (pass exactly one). SIZE: there is no practical limit \u2014 anything over ~3.5 MiB is streamed straight to object storage via a presigned URL automatically, so do NOT gzip, base64-wrap, chunk or split a file just to make it fit. Non-ASCII paths (e.g. \u4E2A\u4EBA\u62A5\u544A.html) are fine \u2014 do not transliterate. Overwriting the same path UPDATES the file. Returns { ok, path, size }.",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES) \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this."},path:{type:"string",description:'Relative file path, e.g. "dumps/run-42.json" or "img/chart.png". Letters, digits, ".", "_", "-" and "/" only; no "..", no leading "/".'},content:{type:"string",description:"Text content (UTF-8). Use for JSON/CSV/text files."},contentBase64:{type:"string",description:"Base64-encoded binary content (images etc.). Alternative to `content`."},contentType:{type:"string",description:'Optional MIME type (e.g. "application/json", "image/png"). Defaults sensibly.'}},required:["path"]}},{name:"file_get",description:'For FILE-type stores: read ONE stored file back by its relative path. Text files come back as `content` (encoding "utf8"); binary files come back as `contentBase64` (encoding "base64"). Returns { path, size, contentType, lastModified, content|contentBase64, encoding }.',input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES). If exactly one store is bound you may omit this."},path:{type:"string",description:"The relative file path to fetch (as listed by file_list / used in file_put)."}},required:["path"]}},{name:"file_list",description:'For FILE-type stores: list the stored files \u2014 each entry has { path, size, lastModified }. Optionally filter by a path `prefix` (e.g. "dumps/"). Paginated via `cursor` when there are more results.',input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES). If exactly one store is bound you may omit this."},prefix:{type:"string",description:'Optional path prefix filter, e.g. "dumps/" or "reports/2026".'},limit:{type:"number",description:"Max entries to return (default/max 1000)."},cursor:{type:"string",description:"Pagination cursor from a previous file_list response (nextCursor)."}},required:[]}},{name:"file_delete",description:"For FILE-type stores: delete ONE stored file by its relative path. Returns { ok, path, deleted }. Errors if the path does not exist.",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES). If exactly one store is bound you may omit this."},path:{type:"string",description:"The relative file path to delete."}},required:["path"]}}]};export{C as __clearEnsuredStores,P as datasetStoreSkill};
|
package/dist/index.js
CHANGED
|
@@ -774,7 +774,7 @@ Tools:
|
|
|
774
774
|
- file_list: (file stores) List stored files (optionally by path prefix).
|
|
775
775
|
- file_delete: (file stores) Delete ONE file by path.
|
|
776
776
|
Pick the tool that matches the store's TYPE; using a dataset tool on a sqlite
|
|
777
|
-
store (or a file tool on either, etc.) is rejected.`,resolve(){let r=Zd();if(!r)return{command:null,args:[],env:{},description:this.description};let e={};for(let t of["PROJECT_API_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV","ZIBBY_PROD_ACCOUNT_API_URL","ZIBBY_USER_TOKEN","WORKFLOW_TYPE"])process.env[t]&&(e[t]=process.env[t]);for(let t of Object.keys(process.env))/^ZIBBY_STORE__.+$/.test(t)&&process.env[t]&&(e[t]=process.env[t]);return{type:"stdio",command:"node",args:[r,"../dist/datasetStore.js","datasetStoreSkill"],env:e,description:this.description,alwaysLoad:!1}},async handleToolCall(r,e){try{switch(r){case"dataset_append":{if(e?.record==null||typeof e.record!="object"||Array.isArray(e.record))return JSON.stringify({error:"record is required (a JSON object)"});let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});let n=typeof e?.agent=="string"&&e.agent.trim()?e.agent.trim():Ci(),i={record:e.record,agent:n};typeof e?.description=="string"&&e.description.trim()&&(i.description=e.description.trim());let s=await le(t.storeId,"append",i);return JSON.stringify({...s,store:t.name,storeId:t.storeId})}case"dataset_query":{let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});let n={};for(let s of["select","where","groupBy","orderBy","limit","since","until","agent"])e?.[s]!=null&&(n[s]=e[s]);let i=await le(t.storeId,"query",n);return JSON.stringify({...i,store:t.name,storeId:t.storeId})}case"ensure_store":{let t=typeof e?.name=="string"?e.name.trim():"";if(!t)return JSON.stringify({error:"name is required"});let n=typeof e?.type=="string"&&e.type.trim()?e.type.trim().toLowerCase():"sqlite",i=typeof e?.description=="string"?e.description.trim():"",s=await Qd({name:t,type:n,description:i,namespace:Ci()});return s?.storeId&&(Bi[t]=s.storeId),JSON.stringify({...s,store:t})}case"file_put":{let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});if(typeof e?.path!="string"||!e.path.trim())return JSON.stringify({error:'path is required (a relative file path like "reports/2026-07.json")'});let n=typeof e?.content=="string",i=typeof e?.contentBase64=="string"&&e.contentBase64.length>0;if(!n&&!i)return JSON.stringify({error:"content (text) or contentBase64 (base64 bytes) is required"});let s=e.path.trim(),o=typeof e?.contentType=="string"&&e.contentType.trim()?e.contentType.trim():"",a=n?Buffer.from(e.content,"utf8"):Buffer.from(String(e.contentBase64).replace(/\s+/g,""),"base64");if(a.length>Xd){let l=o||(n?"text/plain; charset=utf-8":"application/octet-stream"),p=await ep(t.storeId,s,a,l);return JSON.stringify({...p,store:t.name,storeId:t.storeId})}let c={path:s};n?c.content=e.content:c.contentBase64=e.contentBase64,o&&(c.contentType=o);let d=await le(t.storeId,"put",c);return JSON.stringify({...d,store:t.name,storeId:t.storeId})}case"file_get":{let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});if(typeof e?.path!="string"||!e.path.trim())return JSON.stringify({error:"path is required"});let n=e.path.trim(),i;try{i=await le(t.storeId,"get",{path:n})}catch(c){if(!/failed \(413\)/.test(c?.message||""))throw c;let d=await tp(t.storeId,n);i={path:n,size:d.buf.length,contentType:d.contentType,lastModified:null,contentBase64:d.buf.toString("base64")}}let s={ok:!0,store:t.name,storeId:t.storeId,path:i.path,size:i.size,contentType:i.contentType,lastModified:i.lastModified},o=Buffer.from(i.contentBase64||"","base64"),a=o.toString("utf8");return Buffer.compare(Buffer.from(a,"utf8"),o)===0&&!a.includes("\0")?(s.content=a,s.encoding="utf8"):(s.contentBase64=i.contentBase64,s.encoding="base64"),JSON.stringify(s)}case"file_list":{let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});let n={};typeof e?.prefix=="string"&&e.prefix.trim()&&(n.prefix=e.prefix.trim()),e?.limit!=null&&(n.limit=e.limit),typeof e?.cursor=="string"&&e.cursor&&(n.cursor=e.cursor);let i=await le(t.storeId,"list",n);return JSON.stringify({...i,store:t.name,storeId:t.storeId})}case"file_delete":{let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});if(typeof e?.path!="string"||!e.path.trim())return JSON.stringify({error:"path is required"});let n=await le(t.storeId,"delete",{path:e.path.trim()});return JSON.stringify({...n,store:t.name,storeId:t.storeId})}case"sqlite_exec":case"sqlite_query":{let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});if(typeof e?.sql!="string"||!e.sql.trim())return JSON.stringify({error:"sql is required (a non-empty SQL string)"});let n={sql:e.sql};Array.isArray(e?.params)&&(n.params=e.params);let i=await le(t.storeId,"sql",n);return JSON.stringify({...i,store:t.name,storeId:t.storeId})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(t){return JSON.stringify({error:t.message})}},tools:[{name:"dataset_append",description:"Append ONE structured JSON record to a bound store, durably. Records persist across your stateless runs and are auto-tagged with your agent type so you can filter to your own writes later. Use to accumulate data you will query/aggregate (e.g. per-run metrics, processed items). Append ONE record per call.",input_schema:{type:"object",properties:{store:{type:"string",description:'The logical store NAME to write to (e.g. "scorecards"), taken from the AVAILABLE STORES list \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this and it defaults to that store; you can ONLY write to a bound store name.'},record:{type:"object",description:'An arbitrary JSON object \u2014 one row of data. Its keys become queryable fields (e.g. {"repo":"owner/x","stars":1200}). One record per call.'},description:{type:"string",description:"Optional, informational note about this write. The store already exists from deploy, so this is not required and does not create anything."},agent:{type:"string",description:"Optional writing-agent tag. Defaults to your own agent type \u2014 leave unset to auto-tag."}},required:["record"]}},{name:"dataset_query",description:"Run a SQL-style query over a bound store to build reports: select/aggregate (count|sum|avg|min|max), filter, group, order, limit, and bound by month. Returns { columns, rows }. Use this to compute summaries/aggregations from records you appended earlier.",input_schema:{type:"object",properties:{store:{type:"string",description:'The logical store NAME to query (e.g. "scorecards"), taken from the AVAILABLE STORES list \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this and it defaults to that store.'},select:{type:"array",description:"Columns to return. Each item is { field?, agg?, as? }. agg \u2208 count|sum|avg|min|max; omit field for count(*). Omit `select` entirely to return raw rows."},where:{type:"array",description:"Filters, ANDed. Each item is { field, op, value }; op \u2208 eq|ne|gt|gte|lt|lte|like. `field` is a JSON key of the stored record."},groupBy:{type:"array",description:"Field names to group by (array of strings) for aggregation."},orderBy:{type:"array",description:"Sort spec. Each item is { field|as, dir }; dir \u2208 asc|desc."},limit:{type:"number",description:"Maximum number of rows to return."},since:{type:"string",description:"Inclusive lower bound month, 'yyyy-MM' (e.g. '2026-01')."},until:{type:"string",description:"Inclusive upper bound month, 'yyyy-MM' (e.g. '2026-06')."},agent:{type:"string",description:"Filter to records written by one agent namespace. Omit to query across all writers."}},required:[]}},{name:"ensure_store",description:'Create (or reuse) a store ON DEMAND for THIS agent \u2014 use when you need a store that was NOT declared/bound at deploy. Idempotent by name and private to this agent: calling again with the same name returns the SAME store (safe to call at the start of every run). Returns { storeId }. For type "sqlite" you then define schema with sqlite_exec (CREATE TABLE IF NOT EXISTS) and read/write via sqlite_exec/sqlite_query using this name.',input_schema:{type:"object",properties:{name:{type:"string",description:'A short logical name for the store (e.g. "linkedin_posts"). Letters, digits, _ and - only.'},type:{type:"string",enum:["sqlite","dataset","file"],description:'Store type. "sqlite" (default) = a mutable relational DB whose schema YOU define with SQL. "dataset" = append-only JSON records for later aggregation/analytics. "file" = arbitrary file/blob storage by relative path (file_put/file_get/file_list/file_delete).'},description:{type:"string",description:"What this store is for (shown in the Storage UI)."}},required:["name"]}},{name:"sqlite_exec",description:"For SQLITE-type stores: run SQL that CHANGES data \u2014 CREATE TABLE (use IF NOT EXISTS), INSERT, UPDATE, DELETE (one or more statements in one call). The store is a real, mutable SQLite database that persists across your stateless runs. Returns { rowsModified, wrote }. Use this to build schema on the fly and to update rows / track changing state (e.g. a queue with a status column).",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a sqlite-type store from AVAILABLE STORES) \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this."},sql:{type:"string",description:'The SQL to run. May contain multiple statements separated by ";". Prefer CREATE TABLE IF NOT EXISTS for idempotent schema.'},params:{type:"array",description:'Optional positional bind params for a SINGLE parameterized statement (safe binding of values), e.g. sql "UPDATE t SET s=? WHERE id=?" with params ["done", 1].'}},required:["sql"]}},{name:"sqlite_query",description:"For SQLITE-type stores: run a read-only SELECT (optionally with `params` for safe binding) against the store's SQLite database. Returns { columns, rows }. Never changes data. Use to read back rows/state you stored earlier.",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a sqlite-type store from AVAILABLE STORES) \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this."},sql:{type:"string",description:"A single SELECT statement. Use ? placeholders + `params` for any values."},params:{type:"array",description:'Optional positional bind params for the SELECT, e.g. ["linkedin_personal"].'}},required:["sql"]}},{name:"file_put",description:"For FILE-type stores: write (or overwrite) ONE file at a relative path \u2014 raw JSON dumps, CSVs, images, snapshots, any blob you want to keep across your stateless runs. Text goes in `content`; binary goes base64-encoded in `contentBase64` (pass exactly one). Max 4 MiB per file. Overwriting the same path UPDATES the file. Returns { ok, path, size }.",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES) \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this."},path:{type:"string",description:'Relative file path, e.g. "dumps/run-42.json" or "img/chart.png". Letters, digits, ".", "_", "-" and "/" only; no "..", no leading "/".'},content:{type:"string",description:"Text content (UTF-8). Use for JSON/CSV/text files."},contentBase64:{type:"string",description:"Base64-encoded binary content (images etc.). Alternative to `content`."},contentType:{type:"string",description:'Optional MIME type (e.g. "application/json", "image/png"). Defaults sensibly.'}},required:["path"]}},{name:"file_get",description:'For FILE-type stores: read ONE stored file back by its relative path. Text files come back as `content` (encoding "utf8"); binary files come back as `contentBase64` (encoding "base64"). Returns { path, size, contentType, lastModified, content|contentBase64, encoding }.',input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES). If exactly one store is bound you may omit this."},path:{type:"string",description:"The relative file path to fetch (as listed by file_list / used in file_put)."}},required:["path"]}},{name:"file_list",description:'For FILE-type stores: list the stored files \u2014 each entry has { path, size, lastModified }. Optionally filter by a path `prefix` (e.g. "dumps/"). Paginated via `cursor` when there are more results.',input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES). If exactly one store is bound you may omit this."},prefix:{type:"string",description:'Optional path prefix filter, e.g. "dumps/" or "reports/2026".'},limit:{type:"number",description:"Max entries to return (default/max 1000)."},cursor:{type:"string",description:"Pagination cursor from a previous file_list response (nextCursor)."}},required:[]}},{name:"file_delete",description:"For FILE-type stores: delete ONE stored file by its relative path. Returns { ok, path, deleted }. Errors if the path does not exist.",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES). If exactly one store is bound you may omit this."},path:{type:"string",description:"The relative file path to delete."}},required:["path"]}}]};import{SKILL_META as rp}from"@zibby/skill-ids";import{existsSync as Gi,readFileSync as np}from"node:fs";import{homedir as ip}from"node:os";import{join as sp,dirname as op,resolve as ap}from"node:path";import{fileURLToPath as cp}from"node:url";function lp(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let r=op(cp(import.meta.url)),e=ap(r,"..","bin","mcp-skill.mjs");return Gi(e)?e:null}function jt(){if(process.env.PROJECT_API_TOKEN)return process.env.PROJECT_API_TOKEN;if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let r=sp(ip(),".zibby","config.json");return Gi(r)&&JSON.parse(np(r,"utf-8")).sessionToken||null}catch{return null}}function $t(){return process.env.ZIBBY_ACCOUNT_API_URL?process.env.ZIBBY_ACCOUNT_API_URL.replace(/\/$/,""):(process.env.ZIBBY_ENV||"prod")==="local"?"http://localhost:3001":process.env.ZIBBY_PROD_ACCOUNT_API_URL||"https://api-prod.zibby.app"}function dp(){return(typeof process.env.WORKFLOW_TYPE=="string"?process.env.WORKFLOW_TYPE.trim():"")||"agent"}function Hi(r){return`${dp()}:artifact:${r}`}async function Mi(r){let e=jt();if(!e)throw new Error("No backend credential (PROJECT_API_TOKEN). Artifacts are only available inside a Zibby run.");let t=await fetch(`${$t()}/credits/artifacts`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!t.ok){let n=await t.text().catch(()=>"");throw new Error(`artifact write failed (${t.status}): ${n.slice(0,300)}`)}return t.json()}async function pp(r){let e=jt();if(!e)throw new Error("No backend credential (PROJECT_API_TOKEN). Artifacts are only available inside a Zibby run.");let t=await fetch(`${$t()}/credits/artifacts/${encodeURIComponent(r)}`,{method:"GET",headers:{Authorization:`Bearer ${e}`}});if(!t.ok){let n=await t.text().catch(()=>"");throw new Error(`artifact get failed (${t.status}): ${n.slice(0,300)}`)}return t.json()}async function Fi(r,e){let t=jt();if(!t)return;let n=await fetch(`${$t()}/credits/review-memory`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({op:"store",scope:Hi(r),content:JSON.stringify(e)})});if(!n.ok){let i=await n.text().catch(()=>"");throw new Error(`artifact index write failed (${n.status}): ${i.slice(0,200)}`)}}async function up(r){let e=jt();if(!e)return null;let t=await fetch(`${$t()}/credits/review-memory`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify({op:"recall",scope:Hi(r)})});if(!t.ok)return null;let n=await t.json().catch(()=>null);if(!n?.found||!n?.memory?.content)return null;try{return JSON.parse(n.memory.content)}catch{return null}}function Ki(r){return typeof r?.html=="string"&&r.html.length>0?{format:"html",content:r.html}:typeof r?.markdown=="string"&&r.markdown.length>0?{format:"markdown",content:r.markdown}:null}var zi={id:"artifact",meta:rp.artifact,serverName:"artifact",allowedTools:["mcp__artifact__*"],description:"Artifacts \u2014 publish a self-contained, shareable HTML/Markdown page to Zibby and get back a URL; the index of what you published is your memory.",promptFragment:`## Artifacts (publish a shareable page, remember what you made)
|
|
777
|
+
store (or a file tool on either, etc.) is rejected.`,resolve(){let r=Zd();if(!r)return{command:null,args:[],env:{},description:this.description};let e={};for(let t of["PROJECT_API_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV","ZIBBY_PROD_ACCOUNT_API_URL","ZIBBY_USER_TOKEN","WORKFLOW_TYPE"])process.env[t]&&(e[t]=process.env[t]);for(let t of Object.keys(process.env))/^ZIBBY_STORE__.+$/.test(t)&&process.env[t]&&(e[t]=process.env[t]);return{type:"stdio",command:"node",args:[r,"../dist/datasetStore.js","datasetStoreSkill"],env:e,description:this.description,alwaysLoad:!1}},async handleToolCall(r,e){try{switch(r){case"dataset_append":{if(e?.record==null||typeof e.record!="object"||Array.isArray(e.record))return JSON.stringify({error:"record is required (a JSON object)"});let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});let n=typeof e?.agent=="string"&&e.agent.trim()?e.agent.trim():Ci(),i={record:e.record,agent:n};typeof e?.description=="string"&&e.description.trim()&&(i.description=e.description.trim());let s=await le(t.storeId,"append",i);return JSON.stringify({...s,store:t.name,storeId:t.storeId})}case"dataset_query":{let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});let n={};for(let s of["select","where","groupBy","orderBy","limit","since","until","agent"])e?.[s]!=null&&(n[s]=e[s]);let i=await le(t.storeId,"query",n);return JSON.stringify({...i,store:t.name,storeId:t.storeId})}case"ensure_store":{let t=typeof e?.name=="string"?e.name.trim():"";if(!t)return JSON.stringify({error:"name is required"});let n=typeof e?.type=="string"&&e.type.trim()?e.type.trim().toLowerCase():"sqlite",i=typeof e?.description=="string"?e.description.trim():"",s=await Qd({name:t,type:n,description:i,namespace:Ci()});return s?.storeId&&(Bi[t]=s.storeId),JSON.stringify({...s,store:t})}case"file_put":{let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});if(typeof e?.path!="string"||!e.path.trim())return JSON.stringify({error:'path is required (a relative file path like "reports/2026-07.json")'});let n=typeof e?.content=="string",i=typeof e?.contentBase64=="string"&&e.contentBase64.length>0;if(!n&&!i)return JSON.stringify({error:"content (text) or contentBase64 (base64 bytes) is required"});let s=e.path.trim(),o=typeof e?.contentType=="string"&&e.contentType.trim()?e.contentType.trim():"",a=n?Buffer.from(e.content,"utf8"):Buffer.from(String(e.contentBase64).replace(/\s+/g,""),"base64");if(a.length>Xd){let l=o||(n?"text/plain; charset=utf-8":"application/octet-stream"),p=await ep(t.storeId,s,a,l);return JSON.stringify({...p,store:t.name,storeId:t.storeId})}let c={path:s};n?c.content=e.content:c.contentBase64=e.contentBase64,o&&(c.contentType=o);let d=await le(t.storeId,"put",c);return JSON.stringify({...d,store:t.name,storeId:t.storeId})}case"file_get":{let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});if(typeof e?.path!="string"||!e.path.trim())return JSON.stringify({error:"path is required"});let n=e.path.trim(),i;try{i=await le(t.storeId,"get",{path:n})}catch(c){if(!/failed \(413\)/.test(c?.message||""))throw c;let d=await tp(t.storeId,n);i={path:n,size:d.buf.length,contentType:d.contentType,lastModified:null,contentBase64:d.buf.toString("base64")}}let s={ok:!0,store:t.name,storeId:t.storeId,path:i.path,size:i.size,contentType:i.contentType,lastModified:i.lastModified},o=Buffer.from(i.contentBase64||"","base64"),a=o.toString("utf8");return Buffer.compare(Buffer.from(a,"utf8"),o)===0&&!a.includes("\0")?(s.content=a,s.encoding="utf8"):(s.contentBase64=i.contentBase64,s.encoding="base64"),JSON.stringify(s)}case"file_list":{let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});let n={};typeof e?.prefix=="string"&&e.prefix.trim()&&(n.prefix=e.prefix.trim()),e?.limit!=null&&(n.limit=e.limit),typeof e?.cursor=="string"&&e.cursor&&(n.cursor=e.cursor);let i=await le(t.storeId,"list",n);return JSON.stringify({...i,store:t.name,storeId:t.storeId})}case"file_delete":{let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});if(typeof e?.path!="string"||!e.path.trim())return JSON.stringify({error:"path is required"});let n=await le(t.storeId,"delete",{path:e.path.trim()});return JSON.stringify({...n,store:t.name,storeId:t.storeId})}case"sqlite_exec":case"sqlite_query":{let t=Oe(e?.store);if(t.error)return JSON.stringify({error:t.error});if(typeof e?.sql!="string"||!e.sql.trim())return JSON.stringify({error:"sql is required (a non-empty SQL string)"});let n={sql:e.sql};Array.isArray(e?.params)&&(n.params=e.params);let i=await le(t.storeId,"sql",n);return JSON.stringify({...i,store:t.name,storeId:t.storeId})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(t){return JSON.stringify({error:t.message})}},tools:[{name:"dataset_append",description:"Append ONE structured JSON record to a bound store, durably. Records persist across your stateless runs and are auto-tagged with your agent type so you can filter to your own writes later. Use to accumulate data you will query/aggregate (e.g. per-run metrics, processed items). Append ONE record per call.",input_schema:{type:"object",properties:{store:{type:"string",description:'The logical store NAME to write to (e.g. "scorecards"), taken from the AVAILABLE STORES list \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this and it defaults to that store; you can ONLY write to a bound store name.'},record:{type:"object",description:'An arbitrary JSON object \u2014 one row of data. Its keys become queryable fields (e.g. {"repo":"owner/x","stars":1200}). One record per call.'},description:{type:"string",description:"Optional, informational note about this write. The store already exists from deploy, so this is not required and does not create anything."},agent:{type:"string",description:"Optional writing-agent tag. Defaults to your own agent type \u2014 leave unset to auto-tag."}},required:["record"]}},{name:"dataset_query",description:"Run a SQL-style query over a bound store to build reports: select/aggregate (count|sum|avg|min|max), filter, group, order, limit, and bound by month. Returns { columns, rows }. Use this to compute summaries/aggregations from records you appended earlier.",input_schema:{type:"object",properties:{store:{type:"string",description:'The logical store NAME to query (e.g. "scorecards"), taken from the AVAILABLE STORES list \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this and it defaults to that store.'},select:{type:"array",description:"Columns to return. Each item is { field?, agg?, as? }. agg \u2208 count|sum|avg|min|max; omit field for count(*). Omit `select` entirely to return raw rows."},where:{type:"array",description:"Filters, ANDed. Each item is { field, op, value }; op \u2208 eq|ne|gt|gte|lt|lte|like. `field` is a JSON key of the stored record."},groupBy:{type:"array",description:"Field names to group by (array of strings) for aggregation."},orderBy:{type:"array",description:"Sort spec. Each item is { field|as, dir }; dir \u2208 asc|desc."},limit:{type:"number",description:"Maximum number of rows to return."},since:{type:"string",description:"Inclusive lower bound month, 'yyyy-MM' (e.g. '2026-01')."},until:{type:"string",description:"Inclusive upper bound month, 'yyyy-MM' (e.g. '2026-06')."},agent:{type:"string",description:"Filter to records written by one agent namespace. Omit to query across all writers."}},required:[]}},{name:"ensure_store",description:'Create (or reuse) a store ON DEMAND for THIS agent \u2014 use when you need a store that was NOT declared/bound at deploy. Idempotent by name and private to this agent: calling again with the same name returns the SAME store (safe to call at the start of every run). Returns { storeId }. For type "sqlite" you then define schema with sqlite_exec (CREATE TABLE IF NOT EXISTS) and read/write via sqlite_exec/sqlite_query using this name.',input_schema:{type:"object",properties:{name:{type:"string",description:'A short logical name for the store (e.g. "linkedin_posts"). Letters, digits, _ and - only.'},type:{type:"string",enum:["sqlite","dataset","file"],description:'Store type. "sqlite" (default) = a mutable relational DB whose schema YOU define with SQL. "dataset" = append-only JSON records for later aggregation/analytics. "file" = arbitrary file/blob storage by relative path (file_put/file_get/file_list/file_delete).'},description:{type:"string",description:"What this store is for (shown in the Storage UI)."}},required:["name"]}},{name:"sqlite_exec",description:"For SQLITE-type stores: run SQL that CHANGES data \u2014 CREATE TABLE (use IF NOT EXISTS), INSERT, UPDATE, DELETE (one or more statements in one call). The store is a real, mutable SQLite database that persists across your stateless runs. Returns { rowsModified, wrote }. Use this to build schema on the fly and to update rows / track changing state (e.g. a queue with a status column).",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a sqlite-type store from AVAILABLE STORES) \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this."},sql:{type:"string",description:'The SQL to run. May contain multiple statements separated by ";". Prefer CREATE TABLE IF NOT EXISTS for idempotent schema.'},params:{type:"array",description:'Optional positional bind params for a SINGLE parameterized statement (safe binding of values), e.g. sql "UPDATE t SET s=? WHERE id=?" with params ["done", 1].'}},required:["sql"]}},{name:"sqlite_query",description:"For SQLITE-type stores: run a read-only SELECT (optionally with `params` for safe binding) against the store's SQLite database. Returns { columns, rows }. Never changes data. Use to read back rows/state you stored earlier.",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a sqlite-type store from AVAILABLE STORES) \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this."},sql:{type:"string",description:"A single SELECT statement. Use ? placeholders + `params` for any values."},params:{type:"array",description:'Optional positional bind params for the SELECT, e.g. ["linkedin_personal"].'}},required:["sql"]}},{name:"file_put",description:"For FILE-type stores: write (or overwrite) ONE file at a relative path \u2014 raw JSON dumps, CSVs, images, snapshots, any blob you want to keep across your stateless runs. Text goes in `content`; binary goes base64-encoded in `contentBase64` (pass exactly one). SIZE: there is no practical limit \u2014 anything over ~3.5 MiB is streamed straight to object storage via a presigned URL automatically, so do NOT gzip, base64-wrap, chunk or split a file just to make it fit. Non-ASCII paths (e.g. \u4E2A\u4EBA\u62A5\u544A.html) are fine \u2014 do not transliterate. Overwriting the same path UPDATES the file. Returns { ok, path, size }.",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES) \u2014 pick by description. NOT an id. If exactly one store is bound you may omit this."},path:{type:"string",description:'Relative file path, e.g. "dumps/run-42.json" or "img/chart.png". Letters, digits, ".", "_", "-" and "/" only; no "..", no leading "/".'},content:{type:"string",description:"Text content (UTF-8). Use for JSON/CSV/text files."},contentBase64:{type:"string",description:"Base64-encoded binary content (images etc.). Alternative to `content`."},contentType:{type:"string",description:'Optional MIME type (e.g. "application/json", "image/png"). Defaults sensibly.'}},required:["path"]}},{name:"file_get",description:'For FILE-type stores: read ONE stored file back by its relative path. Text files come back as `content` (encoding "utf8"); binary files come back as `contentBase64` (encoding "base64"). Returns { path, size, contentType, lastModified, content|contentBase64, encoding }.',input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES). If exactly one store is bound you may omit this."},path:{type:"string",description:"The relative file path to fetch (as listed by file_list / used in file_put)."}},required:["path"]}},{name:"file_list",description:'For FILE-type stores: list the stored files \u2014 each entry has { path, size, lastModified }. Optionally filter by a path `prefix` (e.g. "dumps/"). Paginated via `cursor` when there are more results.',input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES). If exactly one store is bound you may omit this."},prefix:{type:"string",description:'Optional path prefix filter, e.g. "dumps/" or "reports/2026".'},limit:{type:"number",description:"Max entries to return (default/max 1000)."},cursor:{type:"string",description:"Pagination cursor from a previous file_list response (nextCursor)."}},required:[]}},{name:"file_delete",description:"For FILE-type stores: delete ONE stored file by its relative path. Returns { ok, path, deleted }. Errors if the path does not exist.",input_schema:{type:"object",properties:{store:{type:"string",description:"The logical store NAME (a file-type store from AVAILABLE STORES). If exactly one store is bound you may omit this."},path:{type:"string",description:"The relative file path to delete."}},required:["path"]}}]};import{SKILL_META as rp}from"@zibby/skill-ids";import{existsSync as Gi,readFileSync as np}from"node:fs";import{homedir as ip}from"node:os";import{join as sp,dirname as op,resolve as ap}from"node:path";import{fileURLToPath as cp}from"node:url";function lp(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let r=op(cp(import.meta.url)),e=ap(r,"..","bin","mcp-skill.mjs");return Gi(e)?e:null}function jt(){if(process.env.PROJECT_API_TOKEN)return process.env.PROJECT_API_TOKEN;if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let r=sp(ip(),".zibby","config.json");return Gi(r)&&JSON.parse(np(r,"utf-8")).sessionToken||null}catch{return null}}function $t(){return process.env.ZIBBY_ACCOUNT_API_URL?process.env.ZIBBY_ACCOUNT_API_URL.replace(/\/$/,""):(process.env.ZIBBY_ENV||"prod")==="local"?"http://localhost:3001":process.env.ZIBBY_PROD_ACCOUNT_API_URL||"https://api-prod.zibby.app"}function dp(){return(typeof process.env.WORKFLOW_TYPE=="string"?process.env.WORKFLOW_TYPE.trim():"")||"agent"}function Hi(r){return`${dp()}:artifact:${r}`}async function Mi(r){let e=jt();if(!e)throw new Error("No backend credential (PROJECT_API_TOKEN). Artifacts are only available inside a Zibby run.");let t=await fetch(`${$t()}/credits/artifacts`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(r)});if(!t.ok){let n=await t.text().catch(()=>"");throw new Error(`artifact write failed (${t.status}): ${n.slice(0,300)}`)}return t.json()}async function pp(r){let e=jt();if(!e)throw new Error("No backend credential (PROJECT_API_TOKEN). Artifacts are only available inside a Zibby run.");let t=await fetch(`${$t()}/credits/artifacts/${encodeURIComponent(r)}`,{method:"GET",headers:{Authorization:`Bearer ${e}`}});if(!t.ok){let n=await t.text().catch(()=>"");throw new Error(`artifact get failed (${t.status}): ${n.slice(0,300)}`)}return t.json()}async function Fi(r,e){let t=jt();if(!t)return;let n=await fetch(`${$t()}/credits/review-memory`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({op:"store",scope:Hi(r),content:JSON.stringify(e)})});if(!n.ok){let i=await n.text().catch(()=>"");throw new Error(`artifact index write failed (${n.status}): ${i.slice(0,200)}`)}}async function up(r){let e=jt();if(!e)return null;let t=await fetch(`${$t()}/credits/review-memory`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify({op:"recall",scope:Hi(r)})});if(!t.ok)return null;let n=await t.json().catch(()=>null);if(!n?.found||!n?.memory?.content)return null;try{return JSON.parse(n.memory.content)}catch{return null}}function Ki(r){return typeof r?.html=="string"&&r.html.length>0?{format:"html",content:r.html}:typeof r?.markdown=="string"&&r.markdown.length>0?{format:"markdown",content:r.markdown}:null}var zi={id:"artifact",meta:rp.artifact,serverName:"artifact",allowedTools:["mcp__artifact__*"],description:"Artifacts \u2014 publish a self-contained, shareable HTML/Markdown page to Zibby and get back a URL; the index of what you published is your memory.",promptFragment:`## Artifacts (publish a shareable page, remember what you made)
|
|
778
778
|
You can PUBLISH a standalone page \u2014 a status report, a plan, a comparison table,
|
|
779
779
|
a dashboard-y summary, a diagram, a "here's what I found" write-up \u2014 and get back
|
|
780
780
|
a shareable URL. The page is a self-contained HTML (or Markdown) document; it is
|
package/dist/package.json
CHANGED