@lenserfight/sdk 0.3.0-alpha.9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=100;class C{constructor(t){this.rpcClient=t}async browse(t={},r,e=20){const n=Math.max(1,Math.min(e,k)),i={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:o}=await this.rpcClient.rpc("fn_sdk_browse_agents",i);if(o)throw new Error(`@lenserfight/sdk: fn_sdk_browse_agents failed — ${JSON.stringify(o)}`);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)),i={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",i);if(o)throw new Error(`@lenserfight/sdk: browse failed — ${JSON.stringify(o)}`);return Array.isArray(s)?s:[]}}function w(a){if(!a.url)throw new Error("@lenserfight/sdk: createClient requires `url`");if(!a.anonKey)throw new Error("@lenserfight/sdk: createClient requires `anonKey`");const t=a.fetch??globalThis.fetch;if(typeof t!="function")throw new Error("@lenserfight/sdk: global fetch unavailable — pass `fetch` in options");const r=a.url.replace(/\/+$/,""),e=a.apiKey??a.anonKey;return{async rpc(n,i){const s=await t(`${r}/rest/v1/rpc/${n}`,{method:"POST",headers:{apikey:a.anonKey,authorization:`Bearer ${e}`,"content-type":"application/json"},body:JSON.stringify(i??{})});if(!s.ok){const c=await s.text().catch(()=>"");return{data:null,error:{status:s.status,message:c||s.statusText}}}return{data:await s.json().catch(()=>null),error:null}}}}const S=100;class h{constructor(t){this.rpcClient=t}async browse(t={},r,e=20){const n=Math.max(1,Math.min(e,S)),{data:i,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(i)?i:[]}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:i}=await this.rpcClient.rpc("fn_mcp_lens_resolve_template",{p_lens_id:t,p_version_id:e?.versionId??null});if(i)throw new Error(`@lenserfight/sdk: fn_mcp_lens_resolve_template failed — ${JSON.stringify(i)}`);if(!n)throw new Error(`@lenserfight/sdk: lens ${t} not found`);const s=n;let o=s.template_body;const c=[],d=[];for(const l of s.parameters??[]){const f=`[[:${l.id}]]`,p=r[l.label]??r[l.label.toLowerCase()]??Object.entries(r).find(([m])=>m.toLowerCase()===l.label.toLowerCase())?.[1];p!==void 0?(o=o.split(f).join(p),d.push(l.label)):l.optional?o=o.split(f).join(""):c.push(l.label)}return{resolvedPrompt:o,lensId:s.lens_id,versionId:s.version_id,lensTitle:s.title??t,lensDescription:s.description??null,paramsUsed:d,missing:c}}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 i=n.input_contract;if(!i)return[];const s=i.parameters??i.inputs;return Array.isArray(s)?s:[]}}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??[],i=r.filter(s=>!n.includes(s));return{compatible:i.length===0,missingScopes:i,warnings:[]}}}class g{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,v=12e4;class y{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:i}=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(i)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_start failed — ${JSON.stringify(i)}`);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(i=>{const s=i;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??v,i=await this.startRun(t,r,e),s=Date.now()+n;for(;Date.now()<s;){await new Promise(c=>setTimeout(c,A));const o=await this.getRunStatus(i.id);if($.has(o.status)){if(o.status==="completed")return this.getRunLogs(i.id);throw new Error(`@lenserfight/sdk: workflow run ${i.id} ended with status "${o.status}"`)}}throw new Error(`@lenserfight/sdk: workflow run ${i.id} timed out after ${n}ms`)}}class _{agents;battles;lenses;protocols;templates;workflows;rpc;constructor(t){this.rpc=t,this.agents=new C(t),this.battles=new u(t),this.lenses=new h(t),this.protocols=new E(t),this.templates=new g(t),this.workflows=new y(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 O(a){const t=w(a);return new _(t)}function N(a){return new _(a)}const J="0.3.0-alpha.0";exports.BattleClient=u;exports.LensClient=h;exports.LenserFightClient=_;exports.SDK_VERSION=J;exports.TemplateClient=g;exports.WorkflowClient=y;exports.createClient=O;exports.createClientFromRpc=N;exports.createFetchRpcClient=w;
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="1.0.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
@@ -1,4 +1,5 @@
1
1
  export { createClient, createClientFromRpc, LenserFightClient } from './lib/lenserfight-client';
2
+ export { AgentClient } from './lib/agent-client';
2
3
  export { BattleClient } from './lib/battle-client';
3
4
  export { LensClient } from './lib/lens-client';
4
5
  export { TemplateClient } from './lib/template-client';
@@ -8,4 +9,5 @@ export type { SupabaseLikeRpcClient } from './lib/client';
8
9
  export type { BattleLifecycleStatus, BrowseFilters, BrowseCursor, BrowseBattle, BattleTemplate, CreateClientOptions, } from './lib/types';
9
10
  export type { LensBrowseFilters, SdkLensDetail, SdkLensKind, SdkLensParameter, SdkLensSummary, SdkLensVersion, SdkLensVersionSummary, SdkParameterTool, SdkResolvedTemplate, SdkVisibility, SdkContentStatus, } from './lib/types/lenses';
10
11
  export type { SdkWorkflowDetail, SdkWorkflowRun, SdkWorkflowRunLog, SdkWorkflowRunState, SdkWorkflowRunStatus, SdkWorkflowSummary, } from './lib/types/workflows';
11
- export declare const SDK_VERSION = "0.3.0-alpha.0";
12
+ export type { AgentBrowseFilters, SdkAgentCapabilities, SdkAgentDetail, SdkAgentLensBinding, SdkAgentModelBinding, SdkAgentModelBindingMode, SdkAgentOwner, SdkAgentPage, SdkAgentRuntimePref, SdkAgentStats, SdkAgentSummary, } from './lib/types/agents';
13
+ export declare const SDK_VERSION = "1.0.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
- const n = Math.max(1, Math.min(e, 100)), i = {
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: o } = await this.rpcClient.rpc("fn_sdk_browse_agents", i);
20
+ }, { data: s, error: o } = await this.rpcClient.rpc("fn_sdk_browse_agents", a);
16
21
  if (o)
17
22
  throw new Error(`@lenserfight/sdk: fn_sdk_browse_agents failed — ${JSON.stringify(o)}`);
18
- return Array.isArray(s) ? s : [];
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.
@@ -70,14 +76,14 @@ class g {
70
76
  * For deeper paging, pass the last row's `{created_at, id}` as `cursor`.
71
77
  */
72
78
  async browse(t = {}, r, e = 20) {
73
- const n = Math.max(1, Math.min(e, h)), i = {
79
+ const n = Math.max(1, Math.min(e, h)), a = {
74
80
  p_search: t.search ?? null,
75
81
  p_category: t.category ?? null,
76
82
  p_status: t.status ?? null,
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: o } = await this.rpcClient.rpc("fn_browse_battles", i);
86
+ }, { data: s, error: o } = await this.rpcClient.rpc("fn_browse_battles", a);
81
87
  if (o)
82
88
  throw new Error(
83
89
  `@lenserfight/sdk: browse failed — ${JSON.stringify(o)}`
@@ -85,31 +91,31 @@ class g {
85
91
  return Array.isArray(s) ? s : [];
86
92
  }
87
93
  }
88
- function y(a) {
89
- if (!a.url)
94
+ function y(l) {
95
+ if (!l.url)
90
96
  throw new Error("@lenserfight/sdk: createClient requires `url`");
91
- if (!a.anonKey)
97
+ if (!l.anonKey)
92
98
  throw new Error("@lenserfight/sdk: createClient requires `anonKey`");
93
- const t = a.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 = a.url.replace(/\/+$/, ""), e = a.apiKey ?? a.anonKey;
102
+ const r = l.url.replace(/\/+$/, ""), e = l.apiKey ?? l.anonKey;
97
103
  return {
98
- async rpc(n, i) {
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: a.anonKey,
108
+ apikey: l.anonKey,
103
109
  authorization: `Bearer ${e}`,
104
110
  "content-type": "application/json"
105
111
  },
106
- body: JSON.stringify(i ?? {})
112
+ body: JSON.stringify(a ?? {})
107
113
  });
108
114
  if (!s.ok) {
109
- const c = await s.text().catch(() => "");
115
+ const i = await s.text().catch(() => "");
110
116
  return {
111
117
  data: null,
112
- error: { status: s.status, message: c || 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 };
@@ -125,7 +131,7 @@ class k {
125
131
  * Browse public lenses. Keyset pagination on (created_at DESC, id DESC).
126
132
  */
127
133
  async browse(t = {}, r, e = 20) {
128
- const n = Math.max(1, Math.min(e, m)), { data: i, error: s } = await this.rpcClient.rpc("fn_sdk_browse_lenses", {
134
+ const n = Math.max(1, Math.min(e, m)), { data: a, error: s } = await this.rpcClient.rpc("fn_sdk_browse_lenses", {
129
135
  p_search: t.search ?? null,
130
136
  p_tag: t.tag ?? null,
131
137
  p_kind: t.kind ?? null,
@@ -135,7 +141,7 @@ class k {
135
141
  });
136
142
  if (s)
137
143
  throw new Error(`@lenserfight/sdk: fn_sdk_browse_lenses failed — ${JSON.stringify(s)}`);
138
- return Array.isArray(i) ? i : [];
144
+ return Array.isArray(a) ? a : [];
139
145
  }
140
146
  /**
141
147
  * Full-text search across public lenses.
@@ -186,20 +192,20 @@ class k {
186
192
  * }
187
193
  */
188
194
  async resolveTemplate(t, r, e) {
189
- const { data: n, error: i } = await this.rpcClient.rpc("fn_mcp_lens_resolve_template", {
195
+ const { data: n, error: a } = await this.rpcClient.rpc("fn_mcp_lens_resolve_template", {
190
196
  p_lens_id: t,
191
197
  p_version_id: e?.versionId ?? null
192
198
  });
193
- if (i)
194
- throw new Error(`@lenserfight/sdk: fn_mcp_lens_resolve_template failed — ${JSON.stringify(i)}`);
199
+ if (a)
200
+ throw new Error(`@lenserfight/sdk: fn_mcp_lens_resolve_template failed — ${JSON.stringify(a)}`);
195
201
  if (!n)
196
202
  throw new Error(`@lenserfight/sdk: lens ${t} not found`);
197
203
  const s = n;
198
204
  let o = s.template_body;
199
- const c = [], _ = [];
200
- for (const l of s.parameters ?? []) {
201
- const d = `[[:${l.id}]]`, f = r[l.label] ?? r[l.label.toLowerCase()] ?? Object.entries(r).find(([w]) => w.toLowerCase() === l.label.toLowerCase())?.[1];
202
- f !== void 0 ? (o = o.split(d).join(f), _.push(l.label)) : l.optional ? o = o.split(d).join("") : c.push(l.label);
205
+ const i = [], _ = [];
206
+ for (const c of s.parameters ?? []) {
207
+ const d = `[[:${c.id}]]`, f = r[c.label] ?? r[c.label.toLowerCase()] ?? Object.entries(r).find(([w]) => w.toLowerCase() === c.label.toLowerCase())?.[1];
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
211
  resolvedPrompt: o,
@@ -208,7 +214,7 @@ class k {
208
214
  lensTitle: s.title ?? t,
209
215
  lensDescription: s.description ?? null,
210
216
  paramsUsed: _,
211
- missing: c
217
+ missing: i
212
218
  };
213
219
  }
214
220
  /**
@@ -224,13 +230,38 @@ class k {
224
230
  if (!r) return [];
225
231
  const n = Array.isArray(r) ? r[0] : r;
226
232
  if (!n) return [];
227
- const i = n.input_contract;
228
- if (!i) return [];
229
- const s = i.parameters ?? i.inputs;
233
+ const a = n.input_contract;
234
+ if (!a) return [];
235
+ const s = a.parameters ?? a.inputs;
230
236
  return Array.isArray(s) ? s : [];
231
237
  }
238
+ /**
239
+ * Extract the parameters declared by a lens version — the contracts plus their
240
+ * labels. Use this to know which values a lens needs before resolving it.
241
+ */
242
+ async extractParams(t) {
243
+ const r = await this.getParameterContracts(t);
244
+ return { params: r, labels: r.map((e) => e.label) };
245
+ }
246
+ /**
247
+ * Validate supplied values against a lens version's parameter contracts.
248
+ * - `missing`: required parameter labels with no value
249
+ * - `unknown`: provided keys that match no contract label (case-insensitive)
250
+ */
251
+ async validateParams(t, r) {
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())
254
+ );
255
+ return {
256
+ valid: s.length === 0 && o.length === 0,
257
+ missing: s,
258
+ unknown: o,
259
+ total: e.length,
260
+ provided: Object.keys(r).length
261
+ };
262
+ }
232
263
  }
233
- class C {
264
+ class b {
234
265
  constructor(t) {
235
266
  this.rpcClient = t;
236
267
  }
@@ -290,11 +321,11 @@ class C {
290
321
  const e = await this.getContractByHash(t);
291
322
  if (!e)
292
323
  return { compatible: !1, missingScopes: [], warnings: ["Contract not found"] };
293
- const n = e.body.requiredScopes ?? [], i = r.filter((s) => !n.includes(s));
294
- return { compatible: i.length === 0, missingScopes: i, warnings: [] };
324
+ const n = e.body.requiredScopes ?? [], a = r.filter((s) => !n.includes(s));
325
+ return { compatible: a.length === 0, missingScopes: a, warnings: [] };
295
326
  }
296
327
  }
297
- class b {
328
+ class C {
298
329
  constructor(t) {
299
330
  this.rpcClient = t;
300
331
  }
@@ -355,15 +386,15 @@ class A {
355
386
  * Requires an authenticated client (`apiKey` in `createClient`).
356
387
  */
357
388
  async startRun(t, r, e) {
358
- const { data: n, error: i } = await this.rpcClient.rpc("fn_mcp_workflow_run_start", {
389
+ const { data: n, error: a } = await this.rpcClient.rpc("fn_mcp_workflow_run_start", {
359
390
  p_workflow_id: t,
360
391
  p_inputs: r ?? {},
361
392
  p_global_model_id: e?.modelId ?? null,
362
393
  p_idempotency_key: e?.idempotencyKey ?? null,
363
394
  p_metadata: {}
364
395
  });
365
- if (i)
366
- throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_start failed — ${JSON.stringify(i)}`);
396
+ if (a)
397
+ throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_start failed — ${JSON.stringify(a)}`);
367
398
  if (!n)
368
399
  throw new Error(`@lenserfight/sdk: workflow ${t} not found or inaccessible`);
369
400
  return n;
@@ -397,8 +428,8 @@ class A {
397
428
  if (e)
398
429
  throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_logs failed — ${JSON.stringify(e)}`);
399
430
  const n = r?.node_results;
400
- return Array.isArray(n) ? n.map((i) => {
401
- const s = i;
431
+ return Array.isArray(n) ? n.map((a) => {
432
+ const s = a;
402
433
  return {
403
434
  nodeId: s.node_id,
404
435
  status: s.status,
@@ -417,17 +448,17 @@ class A {
417
448
  * @param timeoutMs Maximum wait time in milliseconds (default 120 s).
418
449
  */
419
450
  async awaitRun(t, r, e) {
420
- const n = e?.timeoutMs ?? E, i = await this.startRun(t, r, e), s = Date.now() + n;
451
+ const n = e?.timeoutMs ?? E, a = await this.startRun(t, r, e), s = Date.now() + n;
421
452
  for (; Date.now() < s; ) {
422
- await new Promise((c) => setTimeout(c, $));
423
- const o = await this.getRunStatus(i.id);
453
+ await new Promise((i) => setTimeout(i, $));
454
+ const o = await this.getRunStatus(a.id);
424
455
  if (S.has(o.status)) {
425
456
  if (o.status === "completed")
426
- return this.getRunLogs(i.id);
427
- throw new Error(`@lenserfight/sdk: workflow run ${i.id} ended with status "${o.status}"`);
457
+ return this.getRunLogs(a.id);
458
+ throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${o.status}"`);
428
459
  }
429
460
  }
430
- throw new Error(`@lenserfight/sdk: workflow run ${i.id} timed out after ${n}ms`);
461
+ throw new Error(`@lenserfight/sdk: workflow run ${a.id} timed out after ${n}ms`);
431
462
  }
432
463
  }
433
464
  class p {
@@ -439,7 +470,7 @@ class p {
439
470
  workflows;
440
471
  rpc;
441
472
  constructor(t) {
442
- this.rpc = t, this.agents = new u(t), this.battles = new g(t), this.lenses = new k(t), this.protocols = new C(t), this.templates = new b(t), this.workflows = new A(t);
473
+ this.rpc = t, this.agents = new u(t), this.battles = new g(t), this.lenses = new k(t), this.protocols = new b(t), this.templates = new C(t), this.workflows = new A(t);
443
474
  }
444
475
  /**
445
476
  * Direct RPC escape hatch. Use sparingly — anything that's part of the
@@ -453,20 +484,21 @@ class p {
453
484
  return e;
454
485
  }
455
486
  }
456
- function v(a) {
457
- const t = y(a);
487
+ function v(l) {
488
+ const t = y(l);
458
489
  return new p(t);
459
490
  }
460
- function O(a) {
461
- return new p(a);
491
+ function O(l) {
492
+ return new p(l);
462
493
  }
463
- const N = "0.3.0-alpha.0";
494
+ const N = "1.0.0";
464
495
  export {
496
+ u as AgentClient,
465
497
  g as BattleClient,
466
498
  k as LensClient,
467
499
  p as LenserFightClient,
468
500
  N as SDK_VERSION,
469
- b as TemplateClient,
501
+ C as TemplateClient,
470
502
  A as WorkflowClient,
471
503
  v as createClient,
472
504
  O as createClientFromRpc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenserfight/sdk",
3
- "version": "0.3.0-alpha.9",
3
+ "version": "2.0.0",
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",