@lenserfight/sdk 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +1 -1
- package/index.d.ts +2 -0
- package/index.mjs +161 -141
- 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 A=100;class w{constructor(t){this.rpcClient=t}async browse(t,r=20){const e=Math.max(1,Math.min(r,A)),{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,e),nextCursor:null}}async getById(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_get_agent_profile",{p_ai_lenser_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_get_agent_profile failed — ${JSON.stringify(e)}`);return r??null}async getLensBindings(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_list_agent_lens_bindings",{p_ai_lenser_id:t,p_limit:50,p_offset:0});if(e)throw new Error(`@lenserfight/sdk: fn_list_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_list_agent_model_bindings",{p_ai_lenser_id:t,p_limit:50,p_offset:0});if(e)throw new Error(`@lenserfight/sdk: fn_list_agent_model_bindings failed — ${JSON.stringify(e)}`);return Array.isArray(r)?r:[]}}const v=100;class g{constructor(t){this.rpcClient=t}async browse(t={},r,e=20){const n=Math.max(1,Math.min(e,v)),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:l}=await this.rpcClient.rpc("fn_browse_battles",a);if(l)throw new Error(`@lenserfight/sdk: browse failed — ${JSON.stringify(l)}`);return Array.isArray(s)?s:[]}}function y(i){if(!i.url)throw new Error("@lenserfight/sdk: createClient requires `url`");if(!i.anonKey)throw new Error("@lenserfight/sdk: createClient requires `anonKey`");const t=i.fetch??globalThis.fetch;if(typeof t!="function")throw new Error("@lenserfight/sdk: global fetch unavailable — pass `fetch` in options");const r=i.url.replace(/\/+$/,""),e=i.apiKey??i.anonKey;return{async rpc(n,a){const s=await t(`${r}/rest/v1/rpc/${n}`,{method:"POST",headers:{apikey:i.anonKey,authorization:`Bearer ${e}`,"content-type":"application/json"},body:JSON.stringify(a??{})});if(!s.ok){const o=await s.text().catch(()=>"");return{data:null,error:{status:s.status,message:o||s.statusText}}}return{data:await s.json().catch(()=>null),error:null}}}}const E=100;function p(i){if(!i)return[];const t=i;return Array.isArray(t.data)?t.data:Array.isArray(i)?i:[]}function h(i){return{id:i.id,title:i.title??"",description:i.description??null,author:{id:i.lenser_id??"",handle:i.author_handle??"",displayName:i.author_handle??"",avatarUrl:null},tags:Array.isArray(i.tags)?i.tags:[],visibility:i.visibility??"public",status:i.status??"published",outputKind:null,latestVersionNumber:null,createdAt:i.created_at??""}}class m{constructor(t){this.rpcClient=t}async browse(t={},r=0,e=20){const n=Math.max(1,Math.min(e,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,r)});if(o)throw new Error(`@lenserfight/sdk: fn_mcp_lens_search failed — ${JSON.stringify(o)}`);return p(l).map(h)}const{data:a,error:s}=await this.rpcClient.rpc("fn_mcp_lens_list",{p_limit:n,p_offset:Math.max(0,r),p_visibility:"public",p_status:t.status??null,p_lenser_id:null,p_include_archived:!1});if(s)throw new Error(`@lenserfight/sdk: fn_mcp_lens_list failed — ${JSON.stringify(s)}`);return p(a).map(h)}async search(t,r={},e=0,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 l=s.template_body;const o=[],d=[];for(const c of s.parameters??[]){const f=`[[:${c.id}]]`,u=r[c.label]??r[c.label.toLowerCase()]??Object.entries(r).find(([S])=>S.toLowerCase()===c.label.toLowerCase())?.[1];u!==void 0?(l=l.split(f).join(u),d.push(c.label)):c.optional?l=l.split(f).join(""):o.push(c.label)}return{resolvedPrompt:l,lensId:s.lens_id,versionId:s.version_id,lensTitle:s.title??t,lensDescription:s.description??null,paramsUsed:d,missing:o}}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(o=>o.toLowerCase())),a=new Set(e.map(o=>o.label.toLowerCase())),s=e.filter(o=>o.required&&!n.has(o.label.toLowerCase())).map(o=>o.label),l=Object.keys(r).filter(o=>!a.has(o.toLowerCase()));return{valid:s.length===0&&l.length===0,missing:s,unknown:l,total:e.length,provided:Object.keys(r).length}}}class b{constructor(t){this.rpcClient=t}async getContractByVersion(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 null;const n=Array.isArray(r)?r[0]:r;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 r=await this.getContractByVersion(t);return r?{specVersion:r.body?.specVersion??"1.0.0",contentHash:r.contentHash,body:r.body,channel:null,signatures:[]}:null}async getDependencies(t){return[]}async checkCompatibility(t,r){const e=await this.getContractByVersion(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 C{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"]),O=3e3,N=12e4;class k{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??N,a=await this.startRun(t,r,e),s=Date.now()+n;for(;Date.now()<s;){await new Promise(o=>setTimeout(o,O));const l=await this.getRunStatus(a.id);if($.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,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 L(i){const t=y(i);return new _(t)}function M(i){return new _(i)}const T="1.0.0";exports.AgentClient=w;exports.BattleClient=g;exports.LensClient=m;exports.LenserFightClient=_;exports.ProtocolClient=b;exports.SDK_VERSION=T;exports.TemplateClient=C;exports.WorkflowClient=k;exports.createClient=L;exports.createClientFromRpc=M;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,115 @@ 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: s, error:
|
|
87
|
-
if (
|
|
81
|
+
}, { data: s, 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
86
|
return Array.isArray(s) ? s : [];
|
|
92
87
|
}
|
|
93
88
|
}
|
|
94
|
-
function
|
|
95
|
-
if (!
|
|
89
|
+
function b(i) {
|
|
90
|
+
if (!i.url)
|
|
96
91
|
throw new Error("@lenserfight/sdk: createClient requires `url`");
|
|
97
|
-
if (!
|
|
92
|
+
if (!i.anonKey)
|
|
98
93
|
throw new Error("@lenserfight/sdk: createClient requires `anonKey`");
|
|
99
|
-
const t =
|
|
94
|
+
const t = i.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 = i.url.replace(/\/+$/, ""), e = i.apiKey ?? i.anonKey;
|
|
103
98
|
return {
|
|
104
99
|
async rpc(n, a) {
|
|
105
100
|
const s = await t(`${r}/rest/v1/rpc/${n}`, {
|
|
106
101
|
method: "POST",
|
|
107
102
|
headers: {
|
|
108
|
-
apikey:
|
|
103
|
+
apikey: i.anonKey,
|
|
109
104
|
authorization: `Bearer ${e}`,
|
|
110
105
|
"content-type": "application/json"
|
|
111
106
|
},
|
|
112
107
|
body: JSON.stringify(a ?? {})
|
|
113
108
|
});
|
|
114
109
|
if (!s.ok) {
|
|
115
|
-
const
|
|
110
|
+
const o = await s.text().catch(() => "");
|
|
116
111
|
return {
|
|
117
112
|
data: null,
|
|
118
|
-
error: { status: s.status, message:
|
|
113
|
+
error: { status: s.status, message: o || s.statusText }
|
|
119
114
|
};
|
|
120
115
|
}
|
|
121
116
|
return { data: await s.json().catch(() => null), error: null };
|
|
122
117
|
}
|
|
123
118
|
};
|
|
124
119
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
120
|
+
const k = 100;
|
|
121
|
+
function u(i) {
|
|
122
|
+
if (!i) return [];
|
|
123
|
+
const t = i;
|
|
124
|
+
return Array.isArray(t.data) ? t.data : Array.isArray(i) ? i : [];
|
|
125
|
+
}
|
|
126
|
+
function p(i) {
|
|
127
|
+
return {
|
|
128
|
+
id: i.id,
|
|
129
|
+
title: i.title ?? "",
|
|
130
|
+
description: i.description ?? null,
|
|
131
|
+
author: {
|
|
132
|
+
id: i.lenser_id ?? "",
|
|
133
|
+
handle: i.author_handle ?? "",
|
|
134
|
+
displayName: i.author_handle ?? "",
|
|
135
|
+
avatarUrl: null
|
|
136
|
+
},
|
|
137
|
+
tags: Array.isArray(i.tags) ? i.tags : [],
|
|
138
|
+
visibility: i.visibility ?? "public",
|
|
139
|
+
status: i.status ?? "published",
|
|
140
|
+
outputKind: null,
|
|
141
|
+
latestVersionNumber: null,
|
|
142
|
+
createdAt: i.created_at ?? ""
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
class C {
|
|
127
146
|
constructor(t) {
|
|
128
147
|
this.rpcClient = t;
|
|
129
148
|
}
|
|
130
149
|
/**
|
|
131
|
-
* Browse public lenses.
|
|
150
|
+
* Browse public lenses. Uses fn_mcp_lens_list (offset pagination).
|
|
151
|
+
* For text search, uses fn_mcp_lens_search instead.
|
|
152
|
+
* Requires an authenticated client.
|
|
132
153
|
*/
|
|
133
|
-
async browse(t = {}, r, e = 20) {
|
|
134
|
-
const n = Math.max(1, Math.min(e,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
154
|
+
async browse(t = {}, r = 0, e = 20) {
|
|
155
|
+
const n = Math.max(1, Math.min(e, k));
|
|
156
|
+
if (t.search) {
|
|
157
|
+
const { data: l, error: o } = await this.rpcClient.rpc("fn_mcp_lens_search", {
|
|
158
|
+
p_query: t.search,
|
|
159
|
+
p_visibility: "public",
|
|
160
|
+
p_limit: n,
|
|
161
|
+
p_offset: Math.max(0, r)
|
|
162
|
+
});
|
|
163
|
+
if (o)
|
|
164
|
+
throw new Error(`@lenserfight/sdk: fn_mcp_lens_search failed — ${JSON.stringify(o)}`);
|
|
165
|
+
return u(l).map(p);
|
|
166
|
+
}
|
|
167
|
+
const { data: a, error: s } = await this.rpcClient.rpc("fn_mcp_lens_list", {
|
|
168
|
+
p_limit: n,
|
|
169
|
+
p_offset: Math.max(0, r),
|
|
170
|
+
p_visibility: "public",
|
|
171
|
+
p_status: t.status ?? null,
|
|
172
|
+
p_lenser_id: null,
|
|
173
|
+
p_include_archived: !1
|
|
141
174
|
});
|
|
142
175
|
if (s)
|
|
143
|
-
throw new Error(`@lenserfight/sdk:
|
|
144
|
-
return
|
|
176
|
+
throw new Error(`@lenserfight/sdk: fn_mcp_lens_list failed — ${JSON.stringify(s)}`);
|
|
177
|
+
return u(a).map(p);
|
|
145
178
|
}
|
|
146
179
|
/**
|
|
147
180
|
* Full-text search across public lenses.
|
|
148
181
|
*/
|
|
149
|
-
async search(t, r = {}, e, n = 20) {
|
|
182
|
+
async search(t, r = {}, e = 0, n = 20) {
|
|
150
183
|
return this.browse({ ...r, search: t }, e, n);
|
|
151
184
|
}
|
|
152
185
|
/**
|
|
@@ -184,12 +217,6 @@ class k {
|
|
|
184
217
|
* filled prompt and lists which parameters were used or missing.
|
|
185
218
|
*
|
|
186
219
|
* 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
220
|
*/
|
|
194
221
|
async resolveTemplate(t, r, e) {
|
|
195
222
|
const { data: n, error: a } = await this.rpcClient.rpc("fn_mcp_lens_resolve_template", {
|
|
@@ -201,20 +228,20 @@ class k {
|
|
|
201
228
|
if (!n)
|
|
202
229
|
throw new Error(`@lenserfight/sdk: lens ${t} not found`);
|
|
203
230
|
const s = n;
|
|
204
|
-
let
|
|
205
|
-
const
|
|
231
|
+
let l = s.template_body;
|
|
232
|
+
const o = [], _ = [];
|
|
206
233
|
for (const c of s.parameters ?? []) {
|
|
207
234
|
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 ? (
|
|
235
|
+
f !== void 0 ? (l = l.split(d).join(f), _.push(c.label)) : c.optional ? l = l.split(d).join("") : o.push(c.label);
|
|
209
236
|
}
|
|
210
237
|
return {
|
|
211
|
-
resolvedPrompt:
|
|
238
|
+
resolvedPrompt: l,
|
|
212
239
|
lensId: s.lens_id,
|
|
213
240
|
versionId: s.version_id,
|
|
214
241
|
lensTitle: s.title ?? t,
|
|
215
242
|
lensDescription: s.description ?? null,
|
|
216
243
|
paramsUsed: _,
|
|
217
|
-
missing:
|
|
244
|
+
missing: o
|
|
218
245
|
};
|
|
219
246
|
}
|
|
220
247
|
/**
|
|
@@ -236,8 +263,7 @@ class k {
|
|
|
236
263
|
return Array.isArray(s) ? s : [];
|
|
237
264
|
}
|
|
238
265
|
/**
|
|
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.
|
|
266
|
+
* Extract the parameters declared by a lens version — the contracts plus their labels.
|
|
241
267
|
*/
|
|
242
268
|
async extractParams(t) {
|
|
243
269
|
const r = await this.getParameterContracts(t);
|
|
@@ -245,87 +271,81 @@ class k {
|
|
|
245
271
|
}
|
|
246
272
|
/**
|
|
247
273
|
* 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
274
|
*/
|
|
251
275
|
async validateParams(t, r) {
|
|
252
|
-
const e = await this.getParameterContracts(t), n = new Set(Object.keys(r).map((
|
|
253
|
-
(
|
|
276
|
+
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())), s = e.filter((o) => o.required && !n.has(o.label.toLowerCase())).map((o) => o.label), l = Object.keys(r).filter(
|
|
277
|
+
(o) => !a.has(o.toLowerCase())
|
|
254
278
|
);
|
|
255
279
|
return {
|
|
256
|
-
valid: s.length === 0 &&
|
|
280
|
+
valid: s.length === 0 && l.length === 0,
|
|
257
281
|
missing: s,
|
|
258
|
-
unknown:
|
|
282
|
+
unknown: l,
|
|
259
283
|
total: e.length,
|
|
260
284
|
provided: Object.keys(r).length
|
|
261
285
|
};
|
|
262
286
|
}
|
|
263
287
|
}
|
|
264
|
-
class
|
|
288
|
+
class A {
|
|
265
289
|
constructor(t) {
|
|
266
290
|
this.rpcClient = t;
|
|
267
291
|
}
|
|
268
292
|
/**
|
|
269
|
-
* Get the contract for a lens version
|
|
270
|
-
*
|
|
293
|
+
* Get the input contract for a lens version. Uses `fn_get_version_contracts`.
|
|
294
|
+
* Note: contentHash, publishedBy, publishedAt are not available from this function.
|
|
271
295
|
*/
|
|
272
296
|
async getContractByVersion(t) {
|
|
273
|
-
const { data: r, error: e } = await this.rpcClient.rpc("
|
|
274
|
-
p_version_id: t
|
|
275
|
-
p_content_hash: null
|
|
297
|
+
const { data: r, error: e } = await this.rpcClient.rpc("fn_get_version_contracts", {
|
|
298
|
+
p_version_id: t
|
|
276
299
|
});
|
|
277
300
|
if (e)
|
|
278
|
-
throw new Error(`@lenserfight/sdk:
|
|
279
|
-
|
|
301
|
+
throw new Error(`@lenserfight/sdk: fn_get_version_contracts failed — ${JSON.stringify(e)}`);
|
|
302
|
+
if (!r) return null;
|
|
303
|
+
const n = Array.isArray(r) ? r[0] : r;
|
|
304
|
+
if (!n) return null;
|
|
305
|
+
const a = n.input_contract;
|
|
306
|
+
return a ? { contentHash: "", body: a, publishedBy: "", publishedAt: "", supersedesHash: null } : null;
|
|
280
307
|
}
|
|
281
308
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
309
|
+
* Hash-based contract lookup is not supported by the current DB schema.
|
|
310
|
+
* Always returns null.
|
|
284
311
|
*/
|
|
285
312
|
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;
|
|
313
|
+
return null;
|
|
293
314
|
}
|
|
294
315
|
/**
|
|
295
|
-
* Get the
|
|
316
|
+
* Get the manifest for a lens version. Built from `fn_get_version_contracts`.
|
|
317
|
+
* Channel and signatures are not available.
|
|
296
318
|
*/
|
|
297
319
|
async getManifest(t) {
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
320
|
+
const r = await this.getContractByVersion(t);
|
|
321
|
+
return r ? {
|
|
322
|
+
specVersion: r.body?.specVersion ?? "1.0.0",
|
|
323
|
+
contentHash: r.contentHash,
|
|
324
|
+
body: r.body,
|
|
325
|
+
channel: null,
|
|
326
|
+
signatures: []
|
|
327
|
+
} : null;
|
|
304
328
|
}
|
|
305
329
|
/**
|
|
306
|
-
*
|
|
330
|
+
* Dependency graph lookup is not supported by the current DB schema.
|
|
331
|
+
* Always returns an empty array.
|
|
307
332
|
*/
|
|
308
333
|
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 : [];
|
|
334
|
+
return [];
|
|
315
335
|
}
|
|
316
336
|
/**
|
|
317
|
-
* Check if a
|
|
318
|
-
*
|
|
337
|
+
* Check if a lens version satisfies required scopes. Fetches the contract
|
|
338
|
+
* via `getContractByVersion` and compares scopes locally.
|
|
319
339
|
*/
|
|
320
340
|
async checkCompatibility(t, r) {
|
|
321
|
-
const e = await this.
|
|
341
|
+
const e = await this.getContractByVersion(t);
|
|
322
342
|
if (!e)
|
|
323
343
|
return { compatible: !1, missingScopes: [], warnings: ["Contract not found"] };
|
|
324
|
-
const n = e.body
|
|
344
|
+
const n = e.body?.requiredScopes ?? [], a = r.filter((s) => !n.includes(s));
|
|
325
345
|
return { compatible: a.length === 0, missingScopes: a, warnings: [] };
|
|
326
346
|
}
|
|
327
347
|
}
|
|
328
|
-
class
|
|
348
|
+
class S {
|
|
329
349
|
constructor(t) {
|
|
330
350
|
this.rpcClient = t;
|
|
331
351
|
}
|
|
@@ -347,8 +367,8 @@ class C {
|
|
|
347
367
|
return typeof e == "string" ? e : "";
|
|
348
368
|
}
|
|
349
369
|
}
|
|
350
|
-
const
|
|
351
|
-
class
|
|
370
|
+
const v = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]), $ = 3e3, E = 12e4;
|
|
371
|
+
class O {
|
|
352
372
|
constructor(t) {
|
|
353
373
|
this.rpcClient = t;
|
|
354
374
|
}
|
|
@@ -450,18 +470,18 @@ class A {
|
|
|
450
470
|
async awaitRun(t, r, e) {
|
|
451
471
|
const n = e?.timeoutMs ?? E, a = await this.startRun(t, r, e), s = Date.now() + n;
|
|
452
472
|
for (; Date.now() < s; ) {
|
|
453
|
-
await new Promise((
|
|
454
|
-
const
|
|
455
|
-
if (
|
|
456
|
-
if (
|
|
473
|
+
await new Promise((o) => setTimeout(o, $));
|
|
474
|
+
const l = await this.getRunStatus(a.id);
|
|
475
|
+
if (v.has(l.status)) {
|
|
476
|
+
if (l.status === "completed")
|
|
457
477
|
return this.getRunLogs(a.id);
|
|
458
|
-
throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${
|
|
478
|
+
throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${l.status}"`);
|
|
459
479
|
}
|
|
460
480
|
}
|
|
461
481
|
throw new Error(`@lenserfight/sdk: workflow run ${a.id} timed out after ${n}ms`);
|
|
462
482
|
}
|
|
463
483
|
}
|
|
464
|
-
class
|
|
484
|
+
class h {
|
|
465
485
|
agents;
|
|
466
486
|
battles;
|
|
467
487
|
lenses;
|
|
@@ -470,12 +490,11 @@ class p {
|
|
|
470
490
|
workflows;
|
|
471
491
|
rpc;
|
|
472
492
|
constructor(t) {
|
|
473
|
-
this.rpc = t, this.agents = new
|
|
493
|
+
this.rpc = t, this.agents = new g(t), this.battles = new m(t), this.lenses = new C(t), this.protocols = new A(t), this.templates = new S(t), this.workflows = new O(t);
|
|
474
494
|
}
|
|
475
495
|
/**
|
|
476
496
|
* Direct RPC escape hatch. Use sparingly — anything that's part of the
|
|
477
|
-
* stable surface should live on
|
|
478
|
-
* in a follow-up PR).
|
|
497
|
+
* stable surface should live on a named sub-client.
|
|
479
498
|
*/
|
|
480
499
|
async rpcCall(t, r) {
|
|
481
500
|
const { data: e, error: n } = await this.rpc.rpc(t, r);
|
|
@@ -484,23 +503,24 @@ class p {
|
|
|
484
503
|
return e;
|
|
485
504
|
}
|
|
486
505
|
}
|
|
487
|
-
function
|
|
488
|
-
const t =
|
|
489
|
-
return new
|
|
506
|
+
function N(i) {
|
|
507
|
+
const t = b(i);
|
|
508
|
+
return new h(t);
|
|
490
509
|
}
|
|
491
|
-
function
|
|
492
|
-
return new
|
|
510
|
+
function M(i) {
|
|
511
|
+
return new h(i);
|
|
493
512
|
}
|
|
494
|
-
const
|
|
513
|
+
const L = "1.0.0";
|
|
495
514
|
export {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
515
|
+
g as AgentClient,
|
|
516
|
+
m as BattleClient,
|
|
517
|
+
C as LensClient,
|
|
518
|
+
h as LenserFightClient,
|
|
519
|
+
A as ProtocolClient,
|
|
520
|
+
L as SDK_VERSION,
|
|
521
|
+
S as TemplateClient,
|
|
522
|
+
O as WorkflowClient,
|
|
523
|
+
N as createClient,
|
|
524
|
+
M as createClientFromRpc,
|
|
525
|
+
b as createFetchRpcClient
|
|
506
526
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenserfight/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.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",
|