@lenserfight/sdk 2.0.0 → 2.2.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 +1 -1
- package/index.d.ts +2 -0
- package/index.mjs +247 -169
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=100;class w{constructor(t){this.rpcClient=t}async browse(t,e=20){const r=Math.max(1,Math.min(e,v)),{data:n,error:a}=await this.rpcClient.rpc("fn_list_agents_by_owner",{p_owner_lenser_id:t.ownerId});if(a)throw new Error(`@lenserfight/sdk: fn_list_agents_by_owner failed — ${JSON.stringify(a)}`);return{items:(Array.isArray(n)?n:[]).slice(0,r),nextCursor:null}}async getById(t){const{data:e,error:r}=await this.rpcClient.rpc("fn_get_agent_profile",{p_ai_lenser_id:t});if(r)throw new Error(`@lenserfight/sdk: fn_get_agent_profile failed — ${JSON.stringify(r)}`);return e??null}async getLensBindings(t){const{data:e,error:r}=await this.rpcClient.rpc("fn_list_agent_lens_bindings",{p_ai_lenser_id:t,p_limit:50,p_offset:0});if(r)throw new Error(`@lenserfight/sdk: fn_list_agent_lens_bindings failed — ${JSON.stringify(r)}`);return Array.isArray(e)?e:[]}async getModelBindings(t){const{data:e,error:r}=await this.rpcClient.rpc("fn_list_agent_model_bindings",{p_ai_lenser_id:t,p_limit:50,p_offset:0});if(r)throw new Error(`@lenserfight/sdk: fn_list_agent_model_bindings failed — ${JSON.stringify(r)}`);return Array.isArray(e)?e:[]}}const A=100;class g{constructor(t){this.rpcClient=t}async browse(t={},e,r=20){const n=Math.max(1,Math.min(r,A)),a={p_search:t.search??null,p_category:t.category??null,p_status:t.status??null,p_cursor_created_at:e?.created_at??null,p_cursor_id:e?.id??null,p_limit:n},{data:i,error:l}=await this.rpcClient.rpc("fn_browse_battles",a);if(l)throw new Error(`@lenserfight/sdk: browse failed — ${JSON.stringify(l)}`);return Array.isArray(i)?i:[]}}function y(s){if(!s.url)throw new Error("@lenserfight/sdk: createClient requires `url`");if(!s.anonKey)throw new Error("@lenserfight/sdk: createClient requires `anonKey`");const t=s.fetch??globalThis.fetch;if(typeof t!="function")throw new Error("@lenserfight/sdk: global fetch unavailable — pass `fetch` in options");const e=s.url.replace(/\/+$/,""),r=s.apiKey??s.anonKey;return{async rpc(n,a){const i=await t(`${e}/rest/v1/rpc/${n}`,{method:"POST",headers:{apikey:s.anonKey,authorization:`Bearer ${r}`,"content-type":"application/json"},body:JSON.stringify(a??{})});if(!i.ok){const o=await i.text().catch(()=>"");return{data:null,error:{status:i.status,message:o||i.statusText}}}return{data:await i.json().catch(()=>null),error:null}}}}const E=100;function f(s){if(!s)return[];const t=s;return Array.isArray(t.data)?t.data:Array.isArray(s)?s:[]}function $(s){return{id:s.id,key:s.key,label:s.label??null,description:s.description??null,category:s.category,type:s.type,required:s.required??!0,placeholder:s.placeholder??null,helpText:s.help_text??null,options:s.options??null,validationSchema:s.validation_schema??null,icon:s.icon??null,color:s.color??null,isSystem:s.is_system??!1,maxLength:s.max_length??null,minLength:s.min_length??null,sortOrder:s.sort_order??0}}function O(s){const t=s.tool;return{id:s.id,label:s.label,toolId:s.tool_id??"",optional:s.optional??!1,tool:t?$(t):null}}function h(s){return{id:s.id,title:s.title??"",description:s.description??null,author:{id:s.lenser_id??"",handle:s.author_handle??"",displayName:s.author_handle??"",avatarUrl:null},tags:Array.isArray(s.tags)?s.tags:[],visibility:s.visibility??"public",status:s.status??"published",outputKind:null,latestVersionNumber:null,createdAt:s.created_at??""}}class m{constructor(t){this.rpcClient=t}async browse(t={},e=0,r=20){const n=Math.max(1,Math.min(r,E));if(t.search){const{data:l,error:o}=await this.rpcClient.rpc("fn_mcp_lens_search",{p_query:t.search,p_visibility:"public",p_limit:n,p_offset:Math.max(0,e)});if(o)throw new Error(`@lenserfight/sdk: fn_mcp_lens_search failed — ${JSON.stringify(o)}`);return f(l).map(h)}const{data:a,error:i}=await this.rpcClient.rpc("fn_mcp_lens_list",{p_limit:n,p_offset:Math.max(0,e),p_visibility:"public",p_status:t.status??null,p_lenser_id:null,p_include_archived:!1});if(i)throw new Error(`@lenserfight/sdk: fn_mcp_lens_list failed — ${JSON.stringify(i)}`);return f(a).map(h)}async search(t,e={},r=0,n=20){return this.browse({...e,search:t},r,n)}async getById(t){const{data:e,error:r}=await this.rpcClient.rpc("fn_get_lens_detail_bootstrap",{p_lens_id:t});if(r)throw new Error(`@lenserfight/sdk: fn_get_lens_detail_bootstrap failed — ${JSON.stringify(r)}`);return!e||e.error?null:e}async getVersion(t){const[e,r]=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(e.error)throw new Error(`@lenserfight/sdk: fn_get_lens_version_detail failed — ${JSON.stringify(e.error)}`);if(r.error)throw new Error(`@lenserfight/sdk: fn_get_lens_version_parameters failed — ${JSON.stringify(r.error)}`);if(!e.data)return null;const n=Array.isArray(e.data)?e.data[0]:e.data;if(!n)return null;const i=(Array.isArray(r.data)?r.data:[]).map(O);return{id:n.id,lensId:n.lens_id,versionNumber:n.version_number,status:n.status,changelog:n.changelog??null,parameterCount:i.length,createdAt:n.created_at,templateBody:n.template_body,publishedAt:n.published_at??null,parameters:i}}async getLatestVersion(t){const{data:e,error:r}=await this.rpcClient.rpc("fn_get_lens_detail_bootstrap",{p_lens_id:t});if(r)throw new Error(`@lenserfight/sdk: fn_get_lens_detail_bootstrap failed — ${JSON.stringify(r)}`);if(!e||e.error)return null;const n=e.head_version_id;return n?this.getVersion(n):null}async resolveTemplate(t,e,r){const{data:n,error:a}=await this.rpcClient.rpc("fn_mcp_lens_resolve_template",{p_lens_id:t,p_version_id:r?.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 i=n;let l=i.template_body;const o=[],d=[];for(const c of i.parameters??[]){const u=`[[:${c.id}]]`,p=e[c.label]??e[c.label.toLowerCase()]??Object.entries(e).find(([S])=>S.toLowerCase()===c.label.toLowerCase())?.[1];p!==void 0?(l=l.split(u).join(p),d.push(c.label)):c.optional?l=l.split(u).join(""):o.push(c.label)}return{resolvedPrompt:l,lensId:i.lens_id,versionId:i.version_id,lensTitle:i.title??t,lensDescription:i.description??null,paramsUsed:d,missing:o}}async getParameterContracts(t){const{data:e,error:r}=await this.rpcClient.rpc("fn_get_version_contracts",{p_version_id:t});if(r)throw new Error(`@lenserfight/sdk: fn_get_version_contracts failed — ${JSON.stringify(r)}`);if(!e)return[];const n=Array.isArray(e)?e[0]:e;if(!n)return[];const a=n.input_contract;if(!a)return[];const i=a.parameters??a.inputs;return Array.isArray(i)?i:[]}async extractParams(t){const e=await this.getParameterContracts(t);return{params:e,labels:e.map(r=>r.label)}}async validateParams(t,e){const r=await this.getParameterContracts(t),n=new Set(Object.keys(e).map(o=>o.toLowerCase())),a=new Set(r.map(o=>o.label.toLowerCase())),i=r.filter(o=>o.required&&!n.has(o.label.toLowerCase())).map(o=>o.label),l=Object.keys(e).filter(o=>!a.has(o.toLowerCase()));return{valid:i.length===0&&l.length===0,missing:i,unknown:l,total:r.length,provided:Object.keys(e).length}}}class b{constructor(t){this.rpcClient=t}async getContractByVersion(t){const{data:e,error:r}=await this.rpcClient.rpc("fn_get_version_contracts",{p_version_id:t});if(r)throw new Error(`@lenserfight/sdk: fn_get_version_contracts failed — ${JSON.stringify(r)}`);if(!e)return null;const n=Array.isArray(e)?e[0]:e;if(!n)return null;const a=n.input_contract;return a?{contentHash:"",body:a,publishedBy:"",publishedAt:"",supersedesHash:null}:null}async getContractByHash(t){return null}async getManifest(t){const e=await this.getContractByVersion(t);return e?{specVersion:e.body?.specVersion??"1.0.0",contentHash:e.contentHash,body:e.body,channel:null,signatures:[]}:null}async getDependencies(t){return[]}async checkCompatibility(t,e){const r=await this.getContractByVersion(t);if(!r)return{compatible:!1,missingScopes:[],warnings:["Contract not found"]};const n=r.body?.requiredScopes??[],a=e.filter(i=>!n.includes(i));return{compatible:a.length===0,missingScopes:a,warnings:[]}}}class C{constructor(t){this.rpcClient=t}async renderPrompt(t,e={}){const{data:r,error:n}=await this.rpcClient.rpc("fn_battles_render_prompt",{p_template_id:t,p_variables:e});if(n)throw new Error(`@lenserfight/sdk: renderPrompt failed — ${JSON.stringify(n)}`);return typeof r=="string"?r:""}}const N=new Set(["completed","failed","cancelled"]),L=3e3,M=12e4;class k{constructor(t){this.rpcClient=t}async browse(t){const{data:e,error:r}=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(r)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_list failed — ${JSON.stringify(r)}`);const n=e?.data;return Array.isArray(n)?n:[]}async getById(t){const{data:e,error:r}=await this.rpcClient.rpc("fn_mcp_workflow_get",{p_workflow_id:t});if(r)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_get failed — ${JSON.stringify(r)}`);return e??null}async startRun(t,e,r){const{data:n,error:a}=await this.rpcClient.rpc("fn_mcp_workflow_run_start",{p_workflow_id:t,p_inputs:e??{},p_global_model_id:r?.modelId??null,p_idempotency_key:r?.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:e,error:r}=await this.rpcClient.rpc("fn_mcp_workflow_run_status",{p_run_id:t});if(r)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_status failed — ${JSON.stringify(r)}`);if(!e)throw new Error(`@lenserfight/sdk: run ${t} not found`);const n=e;return{id:n.id,status:n.status,activeNodeId:n.active_node_id??null,creditsSpent:n.credits_spent??0}}async getRunLogs(t){const{data:e,error:r}=await this.rpcClient.rpc("fn_mcp_workflow_run_logs",{p_run_id:t});if(r)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_logs failed — ${JSON.stringify(r)}`);const n=e?.node_results;return Array.isArray(n)?n.map(a=>{const i=a;return{nodeId:i.node_id,status:i.status,result:i.result??null,error:i.error??null,durationMs:i.duration_ms??0,tokenCount:i.token_count??0}}):[]}async awaitRun(t,e,r){const n=r?.timeoutMs??M,a=await this.startRun(t,e,r),i=Date.now()+n;for(;Date.now()<i;){await new Promise(o=>setTimeout(o,L));const l=await this.getRunStatus(a.id);if(N.has(l.status)){if(l.status==="completed")return this.getRunLogs(a.id);throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${l.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 g(t),this.lenses=new m(t),this.protocols=new b(t),this.templates=new C(t),this.workflows=new k(t)}async rpcCall(t,e){const{data:r,error:n}=await this.rpc.rpc(t,e);if(n)throw new Error(`@lenserfight/sdk: ${t} failed — ${JSON.stringify(n)}`);return r}}function T(s){const t=y(s);return new _(t)}function J(s){return new _(s)}const R="1.0.0";exports.AgentClient=w;exports.BattleClient=g;exports.LensClient=m;exports.LenserFightClient=_;exports.ProtocolClient=b;exports.SDK_VERSION=R;exports.TemplateClient=C;exports.WorkflowClient=k;exports.createClient=T;exports.createClientFromRpc=J;exports.createFetchRpcClient=y;
|
package/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { createClient, createClientFromRpc, LenserFightClient } from './lib/lens
|
|
|
2
2
|
export { AgentClient } from './lib/agent-client';
|
|
3
3
|
export { BattleClient } from './lib/battle-client';
|
|
4
4
|
export { LensClient } from './lib/lens-client';
|
|
5
|
+
export { ProtocolClient } from './lib/protocol-client';
|
|
5
6
|
export { TemplateClient } from './lib/template-client';
|
|
6
7
|
export { WorkflowClient } from './lib/workflow-client';
|
|
7
8
|
export { createFetchRpcClient } from './lib/client';
|
|
@@ -10,4 +11,5 @@ export type { BattleLifecycleStatus, BrowseFilters, BrowseCursor, BrowseBattle,
|
|
|
10
11
|
export type { LensBrowseFilters, SdkLensDetail, SdkLensKind, SdkLensParameter, SdkLensSummary, SdkLensVersion, SdkLensVersionSummary, SdkParameterTool, SdkResolvedTemplate, SdkVisibility, SdkContentStatus, } from './lib/types/lenses';
|
|
11
12
|
export type { SdkWorkflowDetail, SdkWorkflowRun, SdkWorkflowRunLog, SdkWorkflowRunState, SdkWorkflowRunStatus, SdkWorkflowSummary, } from './lib/types/workflows';
|
|
12
13
|
export type { AgentBrowseFilters, SdkAgentCapabilities, SdkAgentDetail, SdkAgentLensBinding, SdkAgentModelBinding, SdkAgentModelBindingMode, SdkAgentOwner, SdkAgentPage, SdkAgentRuntimePref, SdkAgentStats, SdkAgentSummary, } from './lib/types/agents';
|
|
14
|
+
export type { SdkCompatibilityResult, SdkDependencyEdge, SdkLensContract, SdkLensContractBody, SdkLensManifest, SdkParameterContract, } from './lib/types/protocols';
|
|
13
15
|
export declare const SDK_VERSION = "1.0.0";
|
package/index.mjs
CHANGED
|
@@ -1,70 +1,65 @@
|
|
|
1
|
-
class
|
|
1
|
+
class g {
|
|
2
2
|
constructor(t) {
|
|
3
3
|
this.rpcClient = t;
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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.
|
|
6
|
+
* List AI agents owned by `filters.ownerId`. Uses `fn_list_agents_by_owner`.
|
|
7
|
+
* Requires an authenticated client.
|
|
11
8
|
*/
|
|
12
|
-
async browse(t
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
p_limit: n
|
|
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 };
|
|
9
|
+
async browse(t, r = 20) {
|
|
10
|
+
const e = Math.max(1, Math.min(r, 100)), { data: n, error: a } = await this.rpcClient.rpc("fn_list_agents_by_owner", {
|
|
11
|
+
p_owner_lenser_id: t.ownerId
|
|
12
|
+
});
|
|
13
|
+
if (a)
|
|
14
|
+
throw new Error(`@lenserfight/sdk: fn_list_agents_by_owner failed — ${JSON.stringify(a)}`);
|
|
15
|
+
return { items: (Array.isArray(n) ? n : []).slice(0, e), nextCursor: null };
|
|
25
16
|
}
|
|
26
17
|
/**
|
|
27
|
-
* Get
|
|
18
|
+
* Get agent profile detail by agent ID. Uses `fn_get_agent_profile`.
|
|
28
19
|
*/
|
|
29
20
|
async getById(t) {
|
|
30
|
-
const { data: r, error: e } = await this.rpcClient.rpc("
|
|
31
|
-
|
|
21
|
+
const { data: r, error: e } = await this.rpcClient.rpc("fn_get_agent_profile", {
|
|
22
|
+
p_ai_lenser_id: t
|
|
32
23
|
});
|
|
33
24
|
if (e)
|
|
34
25
|
throw new Error(
|
|
35
|
-
`@lenserfight/sdk:
|
|
26
|
+
`@lenserfight/sdk: fn_get_agent_profile failed — ${JSON.stringify(e)}`
|
|
36
27
|
);
|
|
37
28
|
return r ?? null;
|
|
38
29
|
}
|
|
39
30
|
/**
|
|
40
|
-
* Get lens bindings for
|
|
31
|
+
* Get lens bindings for an agent. Uses `fn_list_agent_lens_bindings`.
|
|
41
32
|
*/
|
|
42
33
|
async getLensBindings(t) {
|
|
43
|
-
const { data: r, error: e } = await this.rpcClient.rpc("
|
|
44
|
-
|
|
34
|
+
const { data: r, error: e } = await this.rpcClient.rpc("fn_list_agent_lens_bindings", {
|
|
35
|
+
p_ai_lenser_id: t,
|
|
36
|
+
p_limit: 50,
|
|
37
|
+
p_offset: 0
|
|
45
38
|
});
|
|
46
39
|
if (e)
|
|
47
40
|
throw new Error(
|
|
48
|
-
`@lenserfight/sdk:
|
|
41
|
+
`@lenserfight/sdk: fn_list_agent_lens_bindings failed — ${JSON.stringify(e)}`
|
|
49
42
|
);
|
|
50
43
|
return Array.isArray(r) ? r : [];
|
|
51
44
|
}
|
|
52
45
|
/**
|
|
53
|
-
* Get model bindings for
|
|
46
|
+
* Get model bindings for an agent. Uses `fn_list_agent_model_bindings`.
|
|
54
47
|
*/
|
|
55
48
|
async getModelBindings(t) {
|
|
56
|
-
const { data: r, error: e } = await this.rpcClient.rpc("
|
|
57
|
-
|
|
49
|
+
const { data: r, error: e } = await this.rpcClient.rpc("fn_list_agent_model_bindings", {
|
|
50
|
+
p_ai_lenser_id: t,
|
|
51
|
+
p_limit: 50,
|
|
52
|
+
p_offset: 0
|
|
58
53
|
});
|
|
59
54
|
if (e)
|
|
60
55
|
throw new Error(
|
|
61
|
-
`@lenserfight/sdk:
|
|
56
|
+
`@lenserfight/sdk: fn_list_agent_model_bindings failed — ${JSON.stringify(e)}`
|
|
62
57
|
);
|
|
63
58
|
return Array.isArray(r) ? r : [];
|
|
64
59
|
}
|
|
65
60
|
}
|
|
66
|
-
const
|
|
67
|
-
class
|
|
61
|
+
const y = 100;
|
|
62
|
+
class m {
|
|
68
63
|
constructor(t) {
|
|
69
64
|
this.rpcClient = t;
|
|
70
65
|
}
|
|
@@ -76,77 +71,146 @@ class g {
|
|
|
76
71
|
* For deeper paging, pass the last row's `{created_at, id}` as `cursor`.
|
|
77
72
|
*/
|
|
78
73
|
async browse(t = {}, r, e = 20) {
|
|
79
|
-
const n = Math.max(1, Math.min(e,
|
|
74
|
+
const n = Math.max(1, Math.min(e, y)), a = {
|
|
80
75
|
p_search: t.search ?? null,
|
|
81
76
|
p_category: t.category ?? null,
|
|
82
77
|
p_status: t.status ?? null,
|
|
83
78
|
p_cursor_created_at: r?.created_at ?? null,
|
|
84
79
|
p_cursor_id: r?.id ?? null,
|
|
85
80
|
p_limit: n
|
|
86
|
-
}, { data:
|
|
87
|
-
if (
|
|
81
|
+
}, { data: i, error: l } = await this.rpcClient.rpc("fn_browse_battles", a);
|
|
82
|
+
if (l)
|
|
88
83
|
throw new Error(
|
|
89
|
-
`@lenserfight/sdk: browse failed — ${JSON.stringify(
|
|
84
|
+
`@lenserfight/sdk: browse failed — ${JSON.stringify(l)}`
|
|
90
85
|
);
|
|
91
|
-
return Array.isArray(
|
|
86
|
+
return Array.isArray(i) ? i : [];
|
|
92
87
|
}
|
|
93
88
|
}
|
|
94
|
-
function
|
|
95
|
-
if (!
|
|
89
|
+
function b(s) {
|
|
90
|
+
if (!s.url)
|
|
96
91
|
throw new Error("@lenserfight/sdk: createClient requires `url`");
|
|
97
|
-
if (!
|
|
92
|
+
if (!s.anonKey)
|
|
98
93
|
throw new Error("@lenserfight/sdk: createClient requires `anonKey`");
|
|
99
|
-
const t =
|
|
94
|
+
const t = s.fetch ?? globalThis.fetch;
|
|
100
95
|
if (typeof t != "function")
|
|
101
96
|
throw new Error("@lenserfight/sdk: global fetch unavailable — pass `fetch` in options");
|
|
102
|
-
const r =
|
|
97
|
+
const r = s.url.replace(/\/+$/, ""), e = s.apiKey ?? s.anonKey;
|
|
103
98
|
return {
|
|
104
99
|
async rpc(n, a) {
|
|
105
|
-
const
|
|
100
|
+
const i = await t(`${r}/rest/v1/rpc/${n}`, {
|
|
106
101
|
method: "POST",
|
|
107
102
|
headers: {
|
|
108
|
-
apikey:
|
|
103
|
+
apikey: s.anonKey,
|
|
109
104
|
authorization: `Bearer ${e}`,
|
|
110
105
|
"content-type": "application/json"
|
|
111
106
|
},
|
|
112
107
|
body: JSON.stringify(a ?? {})
|
|
113
108
|
});
|
|
114
|
-
if (!
|
|
115
|
-
const
|
|
109
|
+
if (!i.ok) {
|
|
110
|
+
const o = await i.text().catch(() => "");
|
|
116
111
|
return {
|
|
117
112
|
data: null,
|
|
118
|
-
error: { status:
|
|
113
|
+
error: { status: i.status, message: o || i.statusText }
|
|
119
114
|
};
|
|
120
115
|
}
|
|
121
|
-
return { data: await
|
|
116
|
+
return { data: await i.json().catch(() => null), error: null };
|
|
122
117
|
}
|
|
123
118
|
};
|
|
124
119
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
120
|
+
const k = 100;
|
|
121
|
+
function p(s) {
|
|
122
|
+
if (!s) return [];
|
|
123
|
+
const t = s;
|
|
124
|
+
return Array.isArray(t.data) ? t.data : Array.isArray(s) ? s : [];
|
|
125
|
+
}
|
|
126
|
+
function C(s) {
|
|
127
|
+
return {
|
|
128
|
+
id: s.id,
|
|
129
|
+
key: s.key,
|
|
130
|
+
label: s.label ?? null,
|
|
131
|
+
description: s.description ?? null,
|
|
132
|
+
category: s.category,
|
|
133
|
+
type: s.type,
|
|
134
|
+
required: s.required ?? !0,
|
|
135
|
+
placeholder: s.placeholder ?? null,
|
|
136
|
+
helpText: s.help_text ?? null,
|
|
137
|
+
options: s.options ?? null,
|
|
138
|
+
validationSchema: s.validation_schema ?? null,
|
|
139
|
+
icon: s.icon ?? null,
|
|
140
|
+
color: s.color ?? null,
|
|
141
|
+
isSystem: s.is_system ?? !1,
|
|
142
|
+
maxLength: s.max_length ?? null,
|
|
143
|
+
minLength: s.min_length ?? null,
|
|
144
|
+
sortOrder: s.sort_order ?? 0
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function v(s) {
|
|
148
|
+
const t = s.tool;
|
|
149
|
+
return {
|
|
150
|
+
id: s.id,
|
|
151
|
+
label: s.label,
|
|
152
|
+
toolId: s.tool_id ?? "",
|
|
153
|
+
optional: s.optional ?? !1,
|
|
154
|
+
tool: t ? C(t) : null
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function f(s) {
|
|
158
|
+
return {
|
|
159
|
+
id: s.id,
|
|
160
|
+
title: s.title ?? "",
|
|
161
|
+
description: s.description ?? null,
|
|
162
|
+
author: {
|
|
163
|
+
id: s.lenser_id ?? "",
|
|
164
|
+
handle: s.author_handle ?? "",
|
|
165
|
+
displayName: s.author_handle ?? "",
|
|
166
|
+
avatarUrl: null
|
|
167
|
+
},
|
|
168
|
+
tags: Array.isArray(s.tags) ? s.tags : [],
|
|
169
|
+
visibility: s.visibility ?? "public",
|
|
170
|
+
status: s.status ?? "published",
|
|
171
|
+
outputKind: null,
|
|
172
|
+
latestVersionNumber: null,
|
|
173
|
+
createdAt: s.created_at ?? ""
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
class A {
|
|
127
177
|
constructor(t) {
|
|
128
178
|
this.rpcClient = t;
|
|
129
179
|
}
|
|
130
180
|
/**
|
|
131
|
-
* Browse public lenses.
|
|
181
|
+
* Browse public lenses. Uses fn_mcp_lens_list (offset pagination).
|
|
182
|
+
* For text search, uses fn_mcp_lens_search instead.
|
|
183
|
+
* Requires an authenticated client.
|
|
132
184
|
*/
|
|
133
|
-
async browse(t = {}, r, e = 20) {
|
|
134
|
-
const n = Math.max(1, Math.min(e,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
185
|
+
async browse(t = {}, r = 0, e = 20) {
|
|
186
|
+
const n = Math.max(1, Math.min(e, k));
|
|
187
|
+
if (t.search) {
|
|
188
|
+
const { data: l, error: o } = await this.rpcClient.rpc("fn_mcp_lens_search", {
|
|
189
|
+
p_query: t.search,
|
|
190
|
+
p_visibility: "public",
|
|
191
|
+
p_limit: n,
|
|
192
|
+
p_offset: Math.max(0, r)
|
|
193
|
+
});
|
|
194
|
+
if (o)
|
|
195
|
+
throw new Error(`@lenserfight/sdk: fn_mcp_lens_search failed — ${JSON.stringify(o)}`);
|
|
196
|
+
return p(l).map(f);
|
|
197
|
+
}
|
|
198
|
+
const { data: a, error: i } = await this.rpcClient.rpc("fn_mcp_lens_list", {
|
|
199
|
+
p_limit: n,
|
|
200
|
+
p_offset: Math.max(0, r),
|
|
201
|
+
p_visibility: "public",
|
|
202
|
+
p_status: t.status ?? null,
|
|
203
|
+
p_lenser_id: null,
|
|
204
|
+
p_include_archived: !1
|
|
141
205
|
});
|
|
142
|
-
if (
|
|
143
|
-
throw new Error(`@lenserfight/sdk:
|
|
144
|
-
return
|
|
206
|
+
if (i)
|
|
207
|
+
throw new Error(`@lenserfight/sdk: fn_mcp_lens_list failed — ${JSON.stringify(i)}`);
|
|
208
|
+
return p(a).map(f);
|
|
145
209
|
}
|
|
146
210
|
/**
|
|
147
211
|
* Full-text search across public lenses.
|
|
148
212
|
*/
|
|
149
|
-
async search(t, r = {}, e, n = 20) {
|
|
213
|
+
async search(t, r = {}, e = 0, n = 20) {
|
|
150
214
|
return this.browse({ ...r, search: t }, e, n);
|
|
151
215
|
}
|
|
152
216
|
/**
|
|
@@ -171,12 +235,39 @@ class k {
|
|
|
171
235
|
]);
|
|
172
236
|
if (r.error)
|
|
173
237
|
throw new Error(`@lenserfight/sdk: fn_get_lens_version_detail failed — ${JSON.stringify(r.error)}`);
|
|
238
|
+
if (e.error)
|
|
239
|
+
throw new Error(`@lenserfight/sdk: fn_get_lens_version_parameters failed — ${JSON.stringify(e.error)}`);
|
|
174
240
|
if (!r.data) return null;
|
|
175
241
|
const n = Array.isArray(r.data) ? r.data[0] : r.data;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
242
|
+
if (!n) return null;
|
|
243
|
+
const i = (Array.isArray(e.data) ? e.data : []).map(v);
|
|
244
|
+
return {
|
|
245
|
+
id: n.id,
|
|
246
|
+
lensId: n.lens_id,
|
|
247
|
+
versionNumber: n.version_number,
|
|
248
|
+
status: n.status,
|
|
249
|
+
changelog: n.changelog ?? null,
|
|
250
|
+
parameterCount: i.length,
|
|
251
|
+
createdAt: n.created_at,
|
|
252
|
+
templateBody: n.template_body,
|
|
253
|
+
publishedAt: n.published_at ?? null,
|
|
254
|
+
parameters: i
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Get the latest (HEAD) version of a lens with its parameters.
|
|
259
|
+
* Convenience wrapper: resolves `head_version_id` via `fn_get_lens_detail_bootstrap`,
|
|
260
|
+
* then delegates to `getVersion()`.
|
|
261
|
+
*/
|
|
262
|
+
async getLatestVersion(t) {
|
|
263
|
+
const { data: r, error: e } = await this.rpcClient.rpc("fn_get_lens_detail_bootstrap", {
|
|
264
|
+
p_lens_id: t
|
|
265
|
+
});
|
|
266
|
+
if (e)
|
|
267
|
+
throw new Error(`@lenserfight/sdk: fn_get_lens_detail_bootstrap failed — ${JSON.stringify(e)}`);
|
|
268
|
+
if (!r || r.error) return null;
|
|
269
|
+
const n = r.head_version_id;
|
|
270
|
+
return n ? this.getVersion(n) : null;
|
|
180
271
|
}
|
|
181
272
|
/**
|
|
182
273
|
* Resolve a lens template by substituting `[[:paramId]]` tokens with the
|
|
@@ -184,12 +275,6 @@ class k {
|
|
|
184
275
|
* filled prompt and lists which parameters were used or missing.
|
|
185
276
|
*
|
|
186
277
|
* Requires an authenticated client (`apiKey` in `createClient`).
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* const result = await lf.lenses.resolveTemplate(lensId, { Topic: 'TypeScript' });
|
|
190
|
-
* if (result.missing.length === 0) {
|
|
191
|
-
* // pass result.resolvedPrompt to your AI model
|
|
192
|
-
* }
|
|
193
278
|
*/
|
|
194
279
|
async resolveTemplate(t, r, e) {
|
|
195
280
|
const { data: n, error: a } = await this.rpcClient.rpc("fn_mcp_lens_resolve_template", {
|
|
@@ -200,21 +285,21 @@ class k {
|
|
|
200
285
|
throw new Error(`@lenserfight/sdk: fn_mcp_lens_resolve_template failed — ${JSON.stringify(a)}`);
|
|
201
286
|
if (!n)
|
|
202
287
|
throw new Error(`@lenserfight/sdk: lens ${t} not found`);
|
|
203
|
-
const
|
|
204
|
-
let
|
|
205
|
-
const
|
|
206
|
-
for (const c of
|
|
207
|
-
const d = `[[:${c.id}]]`,
|
|
208
|
-
|
|
288
|
+
const i = n;
|
|
289
|
+
let l = i.template_body;
|
|
290
|
+
const o = [], _ = [];
|
|
291
|
+
for (const c of i.parameters ?? []) {
|
|
292
|
+
const d = `[[:${c.id}]]`, u = r[c.label] ?? r[c.label.toLowerCase()] ?? Object.entries(r).find(([w]) => w.toLowerCase() === c.label.toLowerCase())?.[1];
|
|
293
|
+
u !== void 0 ? (l = l.split(d).join(u), _.push(c.label)) : c.optional ? l = l.split(d).join("") : o.push(c.label);
|
|
209
294
|
}
|
|
210
295
|
return {
|
|
211
|
-
resolvedPrompt:
|
|
212
|
-
lensId:
|
|
213
|
-
versionId:
|
|
214
|
-
lensTitle:
|
|
215
|
-
lensDescription:
|
|
296
|
+
resolvedPrompt: l,
|
|
297
|
+
lensId: i.lens_id,
|
|
298
|
+
versionId: i.version_id,
|
|
299
|
+
lensTitle: i.title ?? t,
|
|
300
|
+
lensDescription: i.description ?? null,
|
|
216
301
|
paramsUsed: _,
|
|
217
|
-
missing:
|
|
302
|
+
missing: o
|
|
218
303
|
};
|
|
219
304
|
}
|
|
220
305
|
/**
|
|
@@ -232,12 +317,11 @@ class k {
|
|
|
232
317
|
if (!n) return [];
|
|
233
318
|
const a = n.input_contract;
|
|
234
319
|
if (!a) return [];
|
|
235
|
-
const
|
|
236
|
-
return Array.isArray(
|
|
320
|
+
const i = a.parameters ?? a.inputs;
|
|
321
|
+
return Array.isArray(i) ? i : [];
|
|
237
322
|
}
|
|
238
323
|
/**
|
|
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.
|
|
324
|
+
* Extract the parameters declared by a lens version — the contracts plus their labels.
|
|
241
325
|
*/
|
|
242
326
|
async extractParams(t) {
|
|
243
327
|
const r = await this.getParameterContracts(t);
|
|
@@ -245,87 +329,81 @@ class k {
|
|
|
245
329
|
}
|
|
246
330
|
/**
|
|
247
331
|
* 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
332
|
*/
|
|
251
333
|
async validateParams(t, r) {
|
|
252
|
-
const e = await this.getParameterContracts(t), n = new Set(Object.keys(r).map((
|
|
253
|
-
(
|
|
334
|
+
const e = await this.getParameterContracts(t), n = new Set(Object.keys(r).map((o) => o.toLowerCase())), a = new Set(e.map((o) => o.label.toLowerCase())), i = e.filter((o) => o.required && !n.has(o.label.toLowerCase())).map((o) => o.label), l = Object.keys(r).filter(
|
|
335
|
+
(o) => !a.has(o.toLowerCase())
|
|
254
336
|
);
|
|
255
337
|
return {
|
|
256
|
-
valid:
|
|
257
|
-
missing:
|
|
258
|
-
unknown:
|
|
338
|
+
valid: i.length === 0 && l.length === 0,
|
|
339
|
+
missing: i,
|
|
340
|
+
unknown: l,
|
|
259
341
|
total: e.length,
|
|
260
342
|
provided: Object.keys(r).length
|
|
261
343
|
};
|
|
262
344
|
}
|
|
263
345
|
}
|
|
264
|
-
class
|
|
346
|
+
class S {
|
|
265
347
|
constructor(t) {
|
|
266
348
|
this.rpcClient = t;
|
|
267
349
|
}
|
|
268
350
|
/**
|
|
269
|
-
* Get the contract for a lens version
|
|
270
|
-
*
|
|
351
|
+
* Get the input contract for a lens version. Uses `fn_get_version_contracts`.
|
|
352
|
+
* Note: contentHash, publishedBy, publishedAt are not available from this function.
|
|
271
353
|
*/
|
|
272
354
|
async getContractByVersion(t) {
|
|
273
|
-
const { data: r, error: e } = await this.rpcClient.rpc("
|
|
274
|
-
p_version_id: t
|
|
275
|
-
p_content_hash: null
|
|
355
|
+
const { data: r, error: e } = await this.rpcClient.rpc("fn_get_version_contracts", {
|
|
356
|
+
p_version_id: t
|
|
276
357
|
});
|
|
277
358
|
if (e)
|
|
278
|
-
throw new Error(`@lenserfight/sdk:
|
|
279
|
-
|
|
359
|
+
throw new Error(`@lenserfight/sdk: fn_get_version_contracts failed — ${JSON.stringify(e)}`);
|
|
360
|
+
if (!r) return null;
|
|
361
|
+
const n = Array.isArray(r) ? r[0] : r;
|
|
362
|
+
if (!n) return null;
|
|
363
|
+
const a = n.input_contract;
|
|
364
|
+
return a ? { contentHash: "", body: a, publishedBy: "", publishedAt: "", supersedesHash: null } : null;
|
|
280
365
|
}
|
|
281
366
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
367
|
+
* Hash-based contract lookup is not supported by the current DB schema.
|
|
368
|
+
* Always returns null.
|
|
284
369
|
*/
|
|
285
370
|
async getContractByHash(t) {
|
|
286
|
-
|
|
287
|
-
p_version_id: null,
|
|
288
|
-
p_content_hash: t
|
|
289
|
-
});
|
|
290
|
-
if (e)
|
|
291
|
-
throw new Error(`@lenserfight/sdk: fn_sdk_get_contract failed — ${JSON.stringify(e)}`);
|
|
292
|
-
return r ?? null;
|
|
371
|
+
return null;
|
|
293
372
|
}
|
|
294
373
|
/**
|
|
295
|
-
* Get the
|
|
374
|
+
* Get the manifest for a lens version. Built from `fn_get_version_contracts`.
|
|
375
|
+
* Channel and signatures are not available.
|
|
296
376
|
*/
|
|
297
377
|
async getManifest(t) {
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
378
|
+
const r = await this.getContractByVersion(t);
|
|
379
|
+
return r ? {
|
|
380
|
+
specVersion: r.body?.specVersion ?? "1.0.0",
|
|
381
|
+
contentHash: r.contentHash,
|
|
382
|
+
body: r.body,
|
|
383
|
+
channel: null,
|
|
384
|
+
signatures: []
|
|
385
|
+
} : null;
|
|
304
386
|
}
|
|
305
387
|
/**
|
|
306
|
-
*
|
|
388
|
+
* Dependency graph lookup is not supported by the current DB schema.
|
|
389
|
+
* Always returns an empty array.
|
|
307
390
|
*/
|
|
308
391
|
async getDependencies(t) {
|
|
309
|
-
|
|
310
|
-
p_content_hash: t
|
|
311
|
-
});
|
|
312
|
-
if (e)
|
|
313
|
-
throw new Error(`@lenserfight/sdk: fn_sdk_get_dependencies failed — ${JSON.stringify(e)}`);
|
|
314
|
-
return Array.isArray(r) ? r : [];
|
|
392
|
+
return [];
|
|
315
393
|
}
|
|
316
394
|
/**
|
|
317
|
-
* Check if a
|
|
318
|
-
*
|
|
395
|
+
* Check if a lens version satisfies required scopes. Fetches the contract
|
|
396
|
+
* via `getContractByVersion` and compares scopes locally.
|
|
319
397
|
*/
|
|
320
398
|
async checkCompatibility(t, r) {
|
|
321
|
-
const e = await this.
|
|
399
|
+
const e = await this.getContractByVersion(t);
|
|
322
400
|
if (!e)
|
|
323
401
|
return { compatible: !1, missingScopes: [], warnings: ["Contract not found"] };
|
|
324
|
-
const n = e.body
|
|
402
|
+
const n = e.body?.requiredScopes ?? [], a = r.filter((i) => !n.includes(i));
|
|
325
403
|
return { compatible: a.length === 0, missingScopes: a, warnings: [] };
|
|
326
404
|
}
|
|
327
405
|
}
|
|
328
|
-
class
|
|
406
|
+
class $ {
|
|
329
407
|
constructor(t) {
|
|
330
408
|
this.rpcClient = t;
|
|
331
409
|
}
|
|
@@ -347,8 +425,8 @@ class C {
|
|
|
347
425
|
return typeof e == "string" ? e : "";
|
|
348
426
|
}
|
|
349
427
|
}
|
|
350
|
-
const
|
|
351
|
-
class
|
|
428
|
+
const E = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]), O = 3e3, N = 12e4;
|
|
429
|
+
class L {
|
|
352
430
|
constructor(t) {
|
|
353
431
|
this.rpcClient = t;
|
|
354
432
|
}
|
|
@@ -429,14 +507,14 @@ class A {
|
|
|
429
507
|
throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_logs failed — ${JSON.stringify(e)}`);
|
|
430
508
|
const n = r?.node_results;
|
|
431
509
|
return Array.isArray(n) ? n.map((a) => {
|
|
432
|
-
const
|
|
510
|
+
const i = a;
|
|
433
511
|
return {
|
|
434
|
-
nodeId:
|
|
435
|
-
status:
|
|
436
|
-
result:
|
|
437
|
-
error:
|
|
438
|
-
durationMs:
|
|
439
|
-
tokenCount:
|
|
512
|
+
nodeId: i.node_id,
|
|
513
|
+
status: i.status,
|
|
514
|
+
result: i.result ?? null,
|
|
515
|
+
error: i.error ?? null,
|
|
516
|
+
durationMs: i.duration_ms ?? 0,
|
|
517
|
+
tokenCount: i.token_count ?? 0
|
|
440
518
|
};
|
|
441
519
|
}) : [];
|
|
442
520
|
}
|
|
@@ -448,20 +526,20 @@ class A {
|
|
|
448
526
|
* @param timeoutMs Maximum wait time in milliseconds (default 120 s).
|
|
449
527
|
*/
|
|
450
528
|
async awaitRun(t, r, e) {
|
|
451
|
-
const n = e?.timeoutMs ??
|
|
452
|
-
for (; Date.now() <
|
|
453
|
-
await new Promise((
|
|
454
|
-
const
|
|
455
|
-
if (
|
|
456
|
-
if (
|
|
529
|
+
const n = e?.timeoutMs ?? N, a = await this.startRun(t, r, e), i = Date.now() + n;
|
|
530
|
+
for (; Date.now() < i; ) {
|
|
531
|
+
await new Promise((o) => setTimeout(o, O));
|
|
532
|
+
const l = await this.getRunStatus(a.id);
|
|
533
|
+
if (E.has(l.status)) {
|
|
534
|
+
if (l.status === "completed")
|
|
457
535
|
return this.getRunLogs(a.id);
|
|
458
|
-
throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${
|
|
536
|
+
throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${l.status}"`);
|
|
459
537
|
}
|
|
460
538
|
}
|
|
461
539
|
throw new Error(`@lenserfight/sdk: workflow run ${a.id} timed out after ${n}ms`);
|
|
462
540
|
}
|
|
463
541
|
}
|
|
464
|
-
class
|
|
542
|
+
class h {
|
|
465
543
|
agents;
|
|
466
544
|
battles;
|
|
467
545
|
lenses;
|
|
@@ -470,12 +548,11 @@ class p {
|
|
|
470
548
|
workflows;
|
|
471
549
|
rpc;
|
|
472
550
|
constructor(t) {
|
|
473
|
-
this.rpc = t, this.agents = new
|
|
551
|
+
this.rpc = t, this.agents = new g(t), this.battles = new m(t), this.lenses = new A(t), this.protocols = new S(t), this.templates = new $(t), this.workflows = new L(t);
|
|
474
552
|
}
|
|
475
553
|
/**
|
|
476
554
|
* Direct RPC escape hatch. Use sparingly — anything that's part of the
|
|
477
|
-
* stable surface should live on
|
|
478
|
-
* in a follow-up PR).
|
|
555
|
+
* stable surface should live on a named sub-client.
|
|
479
556
|
*/
|
|
480
557
|
async rpcCall(t, r) {
|
|
481
558
|
const { data: e, error: n } = await this.rpc.rpc(t, r);
|
|
@@ -484,23 +561,24 @@ class p {
|
|
|
484
561
|
return e;
|
|
485
562
|
}
|
|
486
563
|
}
|
|
487
|
-
function
|
|
488
|
-
const t =
|
|
489
|
-
return new
|
|
564
|
+
function M(s) {
|
|
565
|
+
const t = b(s);
|
|
566
|
+
return new h(t);
|
|
490
567
|
}
|
|
491
|
-
function
|
|
492
|
-
return new
|
|
568
|
+
function J(s) {
|
|
569
|
+
return new h(s);
|
|
493
570
|
}
|
|
494
|
-
const
|
|
571
|
+
const T = "1.0.0";
|
|
495
572
|
export {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
573
|
+
g as AgentClient,
|
|
574
|
+
m as BattleClient,
|
|
575
|
+
A as LensClient,
|
|
576
|
+
h as LenserFightClient,
|
|
577
|
+
S as ProtocolClient,
|
|
578
|
+
T as SDK_VERSION,
|
|
579
|
+
$ as TemplateClient,
|
|
580
|
+
L as WorkflowClient,
|
|
581
|
+
M as createClient,
|
|
582
|
+
J as createClientFromRpc,
|
|
583
|
+
b as createFetchRpcClient
|
|
506
584
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenserfight/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.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",
|