@lenserfight/sdk 0.3.0-alpha.14 → 0.3.0-alpha.16

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/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=100;class w{constructor(t){this.rpcClient=t}async browse(t={},r,e=20){const n=Math.max(1,Math.min(e,C)),a={p_search:t.search??null,p_cursor_created_at:r?.created_at??null,p_cursor_id:r?.id??null,p_limit:n},{data:s,error:i}=await this.rpcClient.rpc("fn_sdk_browse_agents",a);if(i)throw new Error(`@lenserfight/sdk: fn_sdk_browse_agents failed — ${JSON.stringify(i)}`);return Array.isArray(s)?s:[]}async getById(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_agent_detail",{p_agent_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_agent_detail failed — ${JSON.stringify(e)}`);return r??null}async getLensBindings(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_agent_lens_bindings",{p_agent_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_agent_lens_bindings failed — ${JSON.stringify(e)}`);return Array.isArray(r)?r:[]}async getModelBindings(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_agent_model_bindings",{p_agent_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_agent_model_bindings failed — ${JSON.stringify(e)}`);return Array.isArray(r)?r:[]}}const b=100;class u{constructor(t){this.rpcClient=t}async browse(t={},r,e=20){const n=Math.max(1,Math.min(e,b)),a={p_search:t.search??null,p_category:t.category??null,p_status:t.status??null,p_cursor_created_at:r?.created_at??null,p_cursor_id:r?.id??null,p_limit:n},{data:s,error:i}=await this.rpcClient.rpc("fn_browse_battles",a);if(i)throw new Error(`@lenserfight/sdk: browse failed — ${JSON.stringify(i)}`);return Array.isArray(s)?s:[]}}function h(o){if(!o.url)throw new Error("@lenserfight/sdk: createClient requires `url`");if(!o.anonKey)throw new Error("@lenserfight/sdk: createClient requires `anonKey`");const t=o.fetch??globalThis.fetch;if(typeof t!="function")throw new Error("@lenserfight/sdk: global fetch unavailable — pass `fetch` in options");const r=o.url.replace(/\/+$/,""),e=o.apiKey??o.anonKey;return{async rpc(n,a){const s=await t(`${r}/rest/v1/rpc/${n}`,{method:"POST",headers:{apikey:o.anonKey,authorization:`Bearer ${e}`,"content-type":"application/json"},body:JSON.stringify(a??{})});if(!s.ok){const l=await s.text().catch(()=>"");return{data:null,error:{status:s.status,message:l||s.statusText}}}return{data:await s.json().catch(()=>null),error:null}}}}const S=100;class g{constructor(t){this.rpcClient=t}async browse(t={},r,e=20){const n=Math.max(1,Math.min(e,S)),{data:a,error:s}=await this.rpcClient.rpc("fn_sdk_browse_lenses",{p_search:t.search??null,p_tag:t.tag??null,p_kind:t.kind??null,p_cursor_created_at:r?.created_at??null,p_cursor_id:r?.id??null,p_limit:n});if(s)throw new Error(`@lenserfight/sdk: fn_sdk_browse_lenses failed — ${JSON.stringify(s)}`);return Array.isArray(a)?a:[]}async search(t,r={},e,n=20){return this.browse({...r,search:t},e,n)}async getById(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_get_lens_detail_bootstrap",{p_lens_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_get_lens_detail_bootstrap failed — ${JSON.stringify(e)}`);return!r||r.error?null:r}async getVersion(t){const[r,e]=await Promise.all([this.rpcClient.rpc("fn_get_lens_version_detail",{p_version_id:t}),this.rpcClient.rpc("fn_get_lens_version_parameters",{p_version_id:t})]);if(r.error)throw new Error(`@lenserfight/sdk: fn_get_lens_version_detail failed — ${JSON.stringify(r.error)}`);if(!r.data)return null;const n=Array.isArray(r.data)?r.data[0]:r.data;return n?{...n,parameters:Array.isArray(e.data)?e.data:e.data??[]}:null}async resolveTemplate(t,r,e){const{data:n,error:a}=await this.rpcClient.rpc("fn_mcp_lens_resolve_template",{p_lens_id:t,p_version_id:e?.versionId??null});if(a)throw new Error(`@lenserfight/sdk: fn_mcp_lens_resolve_template failed — ${JSON.stringify(a)}`);if(!n)throw new Error(`@lenserfight/sdk: lens ${t} not found`);const s=n;let i=s.template_body;const l=[],d=[];for(const c of s.parameters??[]){const f=`[[:${c.id}]]`,p=r[c.label]??r[c.label.toLowerCase()]??Object.entries(r).find(([k])=>k.toLowerCase()===c.label.toLowerCase())?.[1];p!==void 0?(i=i.split(f).join(p),d.push(c.label)):c.optional?i=i.split(f).join(""):l.push(c.label)}return{resolvedPrompt:i,lensId:s.lens_id,versionId:s.version_id,lensTitle:s.title??t,lensDescription:s.description??null,paramsUsed:d,missing:l}}async getParameterContracts(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_get_version_contracts",{p_version_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_get_version_contracts failed — ${JSON.stringify(e)}`);if(!r)return[];const n=Array.isArray(r)?r[0]:r;if(!n)return[];const a=n.input_contract;if(!a)return[];const s=a.parameters??a.inputs;return Array.isArray(s)?s:[]}async extractParams(t){const r=await this.getParameterContracts(t);return{params:r,labels:r.map(e=>e.label)}}async validateParams(t,r){const e=await this.getParameterContracts(t),n=new Set(Object.keys(r).map(l=>l.toLowerCase())),a=new Set(e.map(l=>l.label.toLowerCase())),s=e.filter(l=>l.required&&!n.has(l.label.toLowerCase())).map(l=>l.label),i=Object.keys(r).filter(l=>!a.has(l.toLowerCase()));return{valid:s.length===0&&i.length===0,missing:s,unknown:i,total:e.length,provided:Object.keys(r).length}}}class E{constructor(t){this.rpcClient=t}async getContractByVersion(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_contract",{p_version_id:t,p_content_hash:null});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_contract failed — ${JSON.stringify(e)}`);return r??null}async getContractByHash(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_contract",{p_version_id:null,p_content_hash:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_contract failed — ${JSON.stringify(e)}`);return r??null}async getManifest(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_manifest",{p_version_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_manifest failed — ${JSON.stringify(e)}`);return r??null}async getDependencies(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_dependencies",{p_content_hash:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_dependencies failed — ${JSON.stringify(e)}`);return Array.isArray(r)?r:[]}async checkCompatibility(t,r){const e=await this.getContractByHash(t);if(!e)return{compatible:!1,missingScopes:[],warnings:["Contract not found"]};const n=e.body.requiredScopes??[],a=r.filter(s=>!n.includes(s));return{compatible:a.length===0,missingScopes:a,warnings:[]}}}class y{constructor(t){this.rpcClient=t}async renderPrompt(t,r={}){const{data:e,error:n}=await this.rpcClient.rpc("fn_battles_render_prompt",{p_template_id:t,p_variables:r});if(n)throw new Error(`@lenserfight/sdk: renderPrompt failed — ${JSON.stringify(n)}`);return typeof e=="string"?e:""}}const $=new Set(["completed","failed","cancelled"]),A=3e3,O=12e4;class m{constructor(t){this.rpcClient=t}async browse(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_mcp_workflow_list",{p_limit:t?.limit??20,p_offset:t?.offset??0,p_visibility:t?.visibility??null,p_lenser_id:null});if(e)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_list failed — ${JSON.stringify(e)}`);const n=r?.data;return Array.isArray(n)?n:[]}async getById(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_mcp_workflow_get",{p_workflow_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_get failed — ${JSON.stringify(e)}`);return r??null}async startRun(t,r,e){const{data:n,error:a}=await this.rpcClient.rpc("fn_mcp_workflow_run_start",{p_workflow_id:t,p_inputs:r??{},p_global_model_id:e?.modelId??null,p_idempotency_key:e?.idempotencyKey??null,p_metadata:{}});if(a)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_start failed — ${JSON.stringify(a)}`);if(!n)throw new Error(`@lenserfight/sdk: workflow ${t} not found or inaccessible`);return n}async getRunStatus(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_mcp_workflow_run_status",{p_run_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_status failed — ${JSON.stringify(e)}`);if(!r)throw new Error(`@lenserfight/sdk: run ${t} not found`);const n=r;return{id:n.id,status:n.status,activeNodeId:n.active_node_id??null,creditsSpent:n.credits_spent??0}}async getRunLogs(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_mcp_workflow_run_logs",{p_run_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_logs failed — ${JSON.stringify(e)}`);const n=r?.node_results;return Array.isArray(n)?n.map(a=>{const s=a;return{nodeId:s.node_id,status:s.status,result:s.result??null,error:s.error??null,durationMs:s.duration_ms??0,tokenCount:s.token_count??0}}):[]}async awaitRun(t,r,e){const n=e?.timeoutMs??O,a=await this.startRun(t,r,e),s=Date.now()+n;for(;Date.now()<s;){await new Promise(l=>setTimeout(l,A));const i=await this.getRunStatus(a.id);if($.has(i.status)){if(i.status==="completed")return this.getRunLogs(a.id);throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${i.status}"`)}}throw new Error(`@lenserfight/sdk: workflow run ${a.id} timed out after ${n}ms`)}}class _{agents;battles;lenses;protocols;templates;workflows;rpc;constructor(t){this.rpc=t,this.agents=new w(t),this.battles=new u(t),this.lenses=new g(t),this.protocols=new E(t),this.templates=new y(t),this.workflows=new m(t)}async rpcCall(t,r){const{data:e,error:n}=await this.rpc.rpc(t,r);if(n)throw new Error(`@lenserfight/sdk: ${t} failed — ${JSON.stringify(n)}`);return e}}function v(o){const t=h(o);return new _(t)}function N(o){return new _(o)}const L="0.4.0-alpha.0";exports.AgentClient=w;exports.BattleClient=u;exports.LensClient=g;exports.LenserFightClient=_;exports.SDK_VERSION=L;exports.TemplateClient=y;exports.WorkflowClient=m;exports.createClient=v;exports.createClientFromRpc=N;exports.createFetchRpcClient=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=100;class u{constructor(t){this.rpcClient=t}async browse(t={},r,e=20){const n=Math.max(1,Math.min(e,C)),a={p_search:t.search??null,p_runtime_pref:t.runtimePref??null,p_can_join_battles:t.canJoinBattles??null,p_cursor_created_at:r?.created_at??null,p_cursor_id:r?.id??null,p_limit:n},{data:s,error:o}=await this.rpcClient.rpc("fn_sdk_browse_agents",a);if(o)throw new Error(`@lenserfight/sdk: fn_sdk_browse_agents failed — ${JSON.stringify(o)}`);const i=Array.isArray(s)?s:[],_=i[i.length-1],c=i.length===n&&_?{created_at:_.createdAt,id:_.id}:null;return{items:i,nextCursor:c}}async getById(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_agent_detail",{p_agent_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_agent_detail failed — ${JSON.stringify(e)}`);return r??null}async getLensBindings(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_agent_lens_bindings",{p_agent_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_agent_lens_bindings failed — ${JSON.stringify(e)}`);return Array.isArray(r)?r:[]}async getModelBindings(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_agent_model_bindings",{p_agent_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_agent_model_bindings failed — ${JSON.stringify(e)}`);return Array.isArray(r)?r:[]}}const b=100;class w{constructor(t){this.rpcClient=t}async browse(t={},r,e=20){const n=Math.max(1,Math.min(e,b)),a={p_search:t.search??null,p_category:t.category??null,p_status:t.status??null,p_cursor_created_at:r?.created_at??null,p_cursor_id:r?.id??null,p_limit:n},{data:s,error:o}=await this.rpcClient.rpc("fn_browse_battles",a);if(o)throw new Error(`@lenserfight/sdk: browse failed — ${JSON.stringify(o)}`);return Array.isArray(s)?s:[]}}function h(l){if(!l.url)throw new Error("@lenserfight/sdk: createClient requires `url`");if(!l.anonKey)throw new Error("@lenserfight/sdk: createClient requires `anonKey`");const t=l.fetch??globalThis.fetch;if(typeof t!="function")throw new Error("@lenserfight/sdk: global fetch unavailable — pass `fetch` in options");const r=l.url.replace(/\/+$/,""),e=l.apiKey??l.anonKey;return{async rpc(n,a){const s=await t(`${r}/rest/v1/rpc/${n}`,{method:"POST",headers:{apikey:l.anonKey,authorization:`Bearer ${e}`,"content-type":"application/json"},body:JSON.stringify(a??{})});if(!s.ok){const i=await s.text().catch(()=>"");return{data:null,error:{status:s.status,message:i||s.statusText}}}return{data:await s.json().catch(()=>null),error:null}}}}const S=100;class g{constructor(t){this.rpcClient=t}async browse(t={},r,e=20){const n=Math.max(1,Math.min(e,S)),{data:a,error:s}=await this.rpcClient.rpc("fn_sdk_browse_lenses",{p_search:t.search??null,p_tag:t.tag??null,p_kind:t.kind??null,p_cursor_created_at:r?.created_at??null,p_cursor_id:r?.id??null,p_limit:n});if(s)throw new Error(`@lenserfight/sdk: fn_sdk_browse_lenses failed — ${JSON.stringify(s)}`);return Array.isArray(a)?a:[]}async search(t,r={},e,n=20){return this.browse({...r,search:t},e,n)}async getById(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_get_lens_detail_bootstrap",{p_lens_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_get_lens_detail_bootstrap failed — ${JSON.stringify(e)}`);return!r||r.error?null:r}async getVersion(t){const[r,e]=await Promise.all([this.rpcClient.rpc("fn_get_lens_version_detail",{p_version_id:t}),this.rpcClient.rpc("fn_get_lens_version_parameters",{p_version_id:t})]);if(r.error)throw new Error(`@lenserfight/sdk: fn_get_lens_version_detail failed — ${JSON.stringify(r.error)}`);if(!r.data)return null;const n=Array.isArray(r.data)?r.data[0]:r.data;return n?{...n,parameters:Array.isArray(e.data)?e.data:e.data??[]}:null}async resolveTemplate(t,r,e){const{data:n,error:a}=await this.rpcClient.rpc("fn_mcp_lens_resolve_template",{p_lens_id:t,p_version_id:e?.versionId??null});if(a)throw new Error(`@lenserfight/sdk: fn_mcp_lens_resolve_template failed — ${JSON.stringify(a)}`);if(!n)throw new Error(`@lenserfight/sdk: lens ${t} not found`);const s=n;let o=s.template_body;const i=[],_=[];for(const c of s.parameters??[]){const f=`[[:${c.id}]]`,p=r[c.label]??r[c.label.toLowerCase()]??Object.entries(r).find(([k])=>k.toLowerCase()===c.label.toLowerCase())?.[1];p!==void 0?(o=o.split(f).join(p),_.push(c.label)):c.optional?o=o.split(f).join(""):i.push(c.label)}return{resolvedPrompt:o,lensId:s.lens_id,versionId:s.version_id,lensTitle:s.title??t,lensDescription:s.description??null,paramsUsed:_,missing:i}}async getParameterContracts(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_get_version_contracts",{p_version_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_get_version_contracts failed — ${JSON.stringify(e)}`);if(!r)return[];const n=Array.isArray(r)?r[0]:r;if(!n)return[];const a=n.input_contract;if(!a)return[];const s=a.parameters??a.inputs;return Array.isArray(s)?s:[]}async extractParams(t){const r=await this.getParameterContracts(t);return{params:r,labels:r.map(e=>e.label)}}async validateParams(t,r){const e=await this.getParameterContracts(t),n=new Set(Object.keys(r).map(i=>i.toLowerCase())),a=new Set(e.map(i=>i.label.toLowerCase())),s=e.filter(i=>i.required&&!n.has(i.label.toLowerCase())).map(i=>i.label),o=Object.keys(r).filter(i=>!a.has(i.toLowerCase()));return{valid:s.length===0&&o.length===0,missing:s,unknown:o,total:e.length,provided:Object.keys(r).length}}}class E{constructor(t){this.rpcClient=t}async getContractByVersion(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_contract",{p_version_id:t,p_content_hash:null});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_contract failed — ${JSON.stringify(e)}`);return r??null}async getContractByHash(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_contract",{p_version_id:null,p_content_hash:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_contract failed — ${JSON.stringify(e)}`);return r??null}async getManifest(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_manifest",{p_version_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_manifest failed — ${JSON.stringify(e)}`);return r??null}async getDependencies(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_dependencies",{p_content_hash:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_dependencies failed — ${JSON.stringify(e)}`);return Array.isArray(r)?r:[]}async checkCompatibility(t,r){const e=await this.getContractByHash(t);if(!e)return{compatible:!1,missingScopes:[],warnings:["Contract not found"]};const n=e.body.requiredScopes??[],a=r.filter(s=>!n.includes(s));return{compatible:a.length===0,missingScopes:a,warnings:[]}}}class y{constructor(t){this.rpcClient=t}async renderPrompt(t,r={}){const{data:e,error:n}=await this.rpcClient.rpc("fn_battles_render_prompt",{p_template_id:t,p_variables:r});if(n)throw new Error(`@lenserfight/sdk: renderPrompt failed — ${JSON.stringify(n)}`);return typeof e=="string"?e:""}}const $=new Set(["completed","failed","cancelled"]),A=3e3,O=12e4;class m{constructor(t){this.rpcClient=t}async browse(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_mcp_workflow_list",{p_limit:t?.limit??20,p_offset:t?.offset??0,p_visibility:t?.visibility??null,p_lenser_id:null});if(e)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_list failed — ${JSON.stringify(e)}`);const n=r?.data;return Array.isArray(n)?n:[]}async getById(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_mcp_workflow_get",{p_workflow_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_get failed — ${JSON.stringify(e)}`);return r??null}async startRun(t,r,e){const{data:n,error:a}=await this.rpcClient.rpc("fn_mcp_workflow_run_start",{p_workflow_id:t,p_inputs:r??{},p_global_model_id:e?.modelId??null,p_idempotency_key:e?.idempotencyKey??null,p_metadata:{}});if(a)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_start failed — ${JSON.stringify(a)}`);if(!n)throw new Error(`@lenserfight/sdk: workflow ${t} not found or inaccessible`);return n}async getRunStatus(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_mcp_workflow_run_status",{p_run_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_status failed — ${JSON.stringify(e)}`);if(!r)throw new Error(`@lenserfight/sdk: run ${t} not found`);const n=r;return{id:n.id,status:n.status,activeNodeId:n.active_node_id??null,creditsSpent:n.credits_spent??0}}async getRunLogs(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_mcp_workflow_run_logs",{p_run_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_logs failed — ${JSON.stringify(e)}`);const n=r?.node_results;return Array.isArray(n)?n.map(a=>{const s=a;return{nodeId:s.node_id,status:s.status,result:s.result??null,error:s.error??null,durationMs:s.duration_ms??0,tokenCount:s.token_count??0}}):[]}async awaitRun(t,r,e){const n=e?.timeoutMs??O,a=await this.startRun(t,r,e),s=Date.now()+n;for(;Date.now()<s;){await new Promise(i=>setTimeout(i,A));const o=await this.getRunStatus(a.id);if($.has(o.status)){if(o.status==="completed")return this.getRunLogs(a.id);throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${o.status}"`)}}throw new Error(`@lenserfight/sdk: workflow run ${a.id} timed out after ${n}ms`)}}class d{agents;battles;lenses;protocols;templates;workflows;rpc;constructor(t){this.rpc=t,this.agents=new u(t),this.battles=new w(t),this.lenses=new g(t),this.protocols=new E(t),this.templates=new y(t),this.workflows=new m(t)}async rpcCall(t,r){const{data:e,error:n}=await this.rpc.rpc(t,r);if(n)throw new Error(`@lenserfight/sdk: ${t} failed — ${JSON.stringify(n)}`);return e}}function v(l){const t=h(l);return new d(t)}function N(l){return new d(l)}const L="0.4.0-alpha.0";exports.AgentClient=u;exports.BattleClient=w;exports.LensClient=g;exports.LenserFightClient=d;exports.SDK_VERSION=L;exports.TemplateClient=y;exports.WorkflowClient=m;exports.createClient=v;exports.createClientFromRpc=N;exports.createFetchRpcClient=h;
package/index.d.ts CHANGED
@@ -9,5 +9,5 @@ export type { SupabaseLikeRpcClient } from './lib/client';
9
9
  export type { BattleLifecycleStatus, BrowseFilters, BrowseCursor, BrowseBattle, BattleTemplate, CreateClientOptions, } from './lib/types';
10
10
  export type { LensBrowseFilters, SdkLensDetail, SdkLensKind, SdkLensParameter, SdkLensSummary, SdkLensVersion, SdkLensVersionSummary, SdkParameterTool, SdkResolvedTemplate, SdkVisibility, SdkContentStatus, } from './lib/types/lenses';
11
11
  export type { SdkWorkflowDetail, SdkWorkflowRun, SdkWorkflowRunLog, SdkWorkflowRunState, SdkWorkflowRunStatus, SdkWorkflowSummary, } from './lib/types/workflows';
12
- export type { AgentBrowseFilters, SdkAgentCapabilities, SdkAgentDetail, SdkAgentLensBinding, SdkAgentModelBinding, SdkAgentModelBindingMode, SdkAgentOwner, SdkAgentRuntimePref, SdkAgentStats, SdkAgentSummary, } from './lib/types/agents';
12
+ export type { AgentBrowseFilters, SdkAgentCapabilities, SdkAgentDetail, SdkAgentLensBinding, SdkAgentModelBinding, SdkAgentModelBindingMode, SdkAgentOwner, SdkAgentPage, SdkAgentRuntimePref, SdkAgentStats, SdkAgentSummary, } from './lib/types/agents';
13
13
  export declare const SDK_VERSION = "0.4.0-alpha.0";
package/index.mjs CHANGED
@@ -5,17 +5,23 @@ class u {
5
5
  /**
6
6
  * Browse public AI agents. Only agents with `is_public_policy = true` are visible.
7
7
  * Keyset pagination on (created_at DESC, id DESC).
8
+ *
9
+ * `nextCursor` in the result is `null` when no further pages exist — pass it
10
+ * back as `cursor` on the next call to advance the page.
8
11
  */
9
12
  async browse(t = {}, r, e = 20) {
10
13
  const n = Math.max(1, Math.min(e, 100)), a = {
11
14
  p_search: t.search ?? null,
15
+ p_runtime_pref: t.runtimePref ?? null,
16
+ p_can_join_battles: t.canJoinBattles ?? null,
12
17
  p_cursor_created_at: r?.created_at ?? null,
13
18
  p_cursor_id: r?.id ?? null,
14
19
  p_limit: n
15
- }, { data: s, error: i } = await this.rpcClient.rpc("fn_sdk_browse_agents", a);
16
- if (i)
17
- throw new Error(`@lenserfight/sdk: fn_sdk_browse_agents failed — ${JSON.stringify(i)}`);
18
- return Array.isArray(s) ? s : [];
20
+ }, { data: s, error: o } = await this.rpcClient.rpc("fn_sdk_browse_agents", a);
21
+ if (o)
22
+ throw new Error(`@lenserfight/sdk: fn_sdk_browse_agents failed — ${JSON.stringify(o)}`);
23
+ const i = Array.isArray(s) ? s : [], _ = i[i.length - 1], c = i.length === n && _ ? { created_at: _.createdAt, id: _.id } : null;
24
+ return { items: i, nextCursor: c };
19
25
  }
20
26
  /**
21
27
  * Get public agent profile detail. Returns null for non-public or non-existent agents.
@@ -77,39 +83,39 @@ class g {
77
83
  p_cursor_created_at: r?.created_at ?? null,
78
84
  p_cursor_id: r?.id ?? null,
79
85
  p_limit: n
80
- }, { data: s, error: i } = await this.rpcClient.rpc("fn_browse_battles", a);
81
- if (i)
86
+ }, { data: s, error: o } = await this.rpcClient.rpc("fn_browse_battles", a);
87
+ if (o)
82
88
  throw new Error(
83
- `@lenserfight/sdk: browse failed — ${JSON.stringify(i)}`
89
+ `@lenserfight/sdk: browse failed — ${JSON.stringify(o)}`
84
90
  );
85
91
  return Array.isArray(s) ? s : [];
86
92
  }
87
93
  }
88
- function y(o) {
89
- if (!o.url)
94
+ function y(l) {
95
+ if (!l.url)
90
96
  throw new Error("@lenserfight/sdk: createClient requires `url`");
91
- if (!o.anonKey)
97
+ if (!l.anonKey)
92
98
  throw new Error("@lenserfight/sdk: createClient requires `anonKey`");
93
- const t = o.fetch ?? globalThis.fetch;
99
+ const t = l.fetch ?? globalThis.fetch;
94
100
  if (typeof t != "function")
95
101
  throw new Error("@lenserfight/sdk: global fetch unavailable — pass `fetch` in options");
96
- const r = o.url.replace(/\/+$/, ""), e = o.apiKey ?? o.anonKey;
102
+ const r = l.url.replace(/\/+$/, ""), e = l.apiKey ?? l.anonKey;
97
103
  return {
98
104
  async rpc(n, a) {
99
105
  const s = await t(`${r}/rest/v1/rpc/${n}`, {
100
106
  method: "POST",
101
107
  headers: {
102
- apikey: o.anonKey,
108
+ apikey: l.anonKey,
103
109
  authorization: `Bearer ${e}`,
104
110
  "content-type": "application/json"
105
111
  },
106
112
  body: JSON.stringify(a ?? {})
107
113
  });
108
114
  if (!s.ok) {
109
- const l = await s.text().catch(() => "");
115
+ const i = await s.text().catch(() => "");
110
116
  return {
111
117
  data: null,
112
- error: { status: s.status, message: l || s.statusText }
118
+ error: { status: s.status, message: i || s.statusText }
113
119
  };
114
120
  }
115
121
  return { data: await s.json().catch(() => null), error: null };
@@ -195,20 +201,20 @@ class k {
195
201
  if (!n)
196
202
  throw new Error(`@lenserfight/sdk: lens ${t} not found`);
197
203
  const s = n;
198
- let i = s.template_body;
199
- const l = [], _ = [];
204
+ let o = s.template_body;
205
+ const i = [], _ = [];
200
206
  for (const c of s.parameters ?? []) {
201
207
  const d = `[[:${c.id}]]`, f = r[c.label] ?? r[c.label.toLowerCase()] ?? Object.entries(r).find(([w]) => w.toLowerCase() === c.label.toLowerCase())?.[1];
202
- f !== void 0 ? (i = i.split(d).join(f), _.push(c.label)) : c.optional ? i = i.split(d).join("") : l.push(c.label);
208
+ f !== void 0 ? (o = o.split(d).join(f), _.push(c.label)) : c.optional ? o = o.split(d).join("") : i.push(c.label);
203
209
  }
204
210
  return {
205
- resolvedPrompt: i,
211
+ resolvedPrompt: o,
206
212
  lensId: s.lens_id,
207
213
  versionId: s.version_id,
208
214
  lensTitle: s.title ?? t,
209
215
  lensDescription: s.description ?? null,
210
216
  paramsUsed: _,
211
- missing: l
217
+ missing: i
212
218
  };
213
219
  }
214
220
  /**
@@ -243,13 +249,13 @@ class k {
243
249
  * - `unknown`: provided keys that match no contract label (case-insensitive)
244
250
  */
245
251
  async validateParams(t, r) {
246
- const e = await this.getParameterContracts(t), n = new Set(Object.keys(r).map((l) => l.toLowerCase())), a = new Set(e.map((l) => l.label.toLowerCase())), s = e.filter((l) => l.required && !n.has(l.label.toLowerCase())).map((l) => l.label), i = Object.keys(r).filter(
247
- (l) => !a.has(l.toLowerCase())
252
+ const e = await this.getParameterContracts(t), n = new Set(Object.keys(r).map((i) => i.toLowerCase())), a = new Set(e.map((i) => i.label.toLowerCase())), s = e.filter((i) => i.required && !n.has(i.label.toLowerCase())).map((i) => i.label), o = Object.keys(r).filter(
253
+ (i) => !a.has(i.toLowerCase())
248
254
  );
249
255
  return {
250
- valid: s.length === 0 && i.length === 0,
256
+ valid: s.length === 0 && o.length === 0,
251
257
  missing: s,
252
- unknown: i,
258
+ unknown: o,
253
259
  total: e.length,
254
260
  provided: Object.keys(r).length
255
261
  };
@@ -444,12 +450,12 @@ class A {
444
450
  async awaitRun(t, r, e) {
445
451
  const n = e?.timeoutMs ?? E, a = await this.startRun(t, r, e), s = Date.now() + n;
446
452
  for (; Date.now() < s; ) {
447
- await new Promise((l) => setTimeout(l, $));
448
- const i = await this.getRunStatus(a.id);
449
- if (S.has(i.status)) {
450
- if (i.status === "completed")
453
+ await new Promise((i) => setTimeout(i, $));
454
+ const o = await this.getRunStatus(a.id);
455
+ if (S.has(o.status)) {
456
+ if (o.status === "completed")
451
457
  return this.getRunLogs(a.id);
452
- throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${i.status}"`);
458
+ throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${o.status}"`);
453
459
  }
454
460
  }
455
461
  throw new Error(`@lenserfight/sdk: workflow run ${a.id} timed out after ${n}ms`);
@@ -478,12 +484,12 @@ class p {
478
484
  return e;
479
485
  }
480
486
  }
481
- function v(o) {
482
- const t = y(o);
487
+ function v(l) {
488
+ const t = y(l);
483
489
  return new p(t);
484
490
  }
485
- function O(o) {
486
- return new p(o);
491
+ function O(l) {
492
+ return new p(l);
487
493
  }
488
494
  const N = "0.4.0-alpha.0";
489
495
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenserfight/sdk",
3
- "version": "0.3.0-alpha.14",
3
+ "version": "0.3.0-alpha.16",
4
4
  "description": "LenserFight public client SDK — browse and execute lenses, workflows, battles, agents, and protocols from any Supabase-backed deployment",
5
5
  "license": "MIT",
6
6
  "main": "./index.cjs",