@lenserfight/sdk 0.3.0-alpha.9 → 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 +5 -1
- package/index.mjs +197 -145
- package/package.json +1 -1
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 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
|
@@ -1,6 +1,8 @@
|
|
|
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';
|
|
5
|
+
export { ProtocolClient } from './lib/protocol-client';
|
|
4
6
|
export { TemplateClient } from './lib/template-client';
|
|
5
7
|
export { WorkflowClient } from './lib/workflow-client';
|
|
6
8
|
export { createFetchRpcClient } from './lib/client';
|
|
@@ -8,4 +10,6 @@ export type { SupabaseLikeRpcClient } from './lib/client';
|
|
|
8
10
|
export type { BattleLifecycleStatus, BrowseFilters, BrowseCursor, BrowseBattle, BattleTemplate, CreateClientOptions, } from './lib/types';
|
|
9
11
|
export type { LensBrowseFilters, SdkLensDetail, SdkLensKind, SdkLensParameter, SdkLensSummary, SdkLensVersion, SdkLensVersionSummary, SdkParameterTool, SdkResolvedTemplate, SdkVisibility, SdkContentStatus, } from './lib/types/lenses';
|
|
10
12
|
export type { SdkWorkflowDetail, SdkWorkflowRun, SdkWorkflowRunLog, SdkWorkflowRunState, SdkWorkflowRunStatus, SdkWorkflowSummary, } from './lib/types/workflows';
|
|
11
|
-
export
|
|
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';
|
|
15
|
+
export declare const SDK_VERSION = "1.0.0";
|
package/index.mjs
CHANGED
|
@@ -1,64 +1,65 @@
|
|
|
1
|
-
class
|
|
1
|
+
class g {
|
|
2
2
|
constructor(t) {
|
|
3
3
|
this.rpcClient = t;
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* List AI agents owned by `filters.ownerId`. Uses `fn_list_agents_by_owner`.
|
|
7
|
+
* Requires an authenticated client.
|
|
8
8
|
*/
|
|
9
|
-
async browse(t
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (o)
|
|
17
|
-
throw new Error(`@lenserfight/sdk: fn_sdk_browse_agents failed — ${JSON.stringify(o)}`);
|
|
18
|
-
return Array.isArray(s) ? s : [];
|
|
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 };
|
|
19
16
|
}
|
|
20
17
|
/**
|
|
21
|
-
* Get
|
|
18
|
+
* Get agent profile detail by agent ID. Uses `fn_get_agent_profile`.
|
|
22
19
|
*/
|
|
23
20
|
async getById(t) {
|
|
24
|
-
const { data: r, error: e } = await this.rpcClient.rpc("
|
|
25
|
-
|
|
21
|
+
const { data: r, error: e } = await this.rpcClient.rpc("fn_get_agent_profile", {
|
|
22
|
+
p_ai_lenser_id: t
|
|
26
23
|
});
|
|
27
24
|
if (e)
|
|
28
25
|
throw new Error(
|
|
29
|
-
`@lenserfight/sdk:
|
|
26
|
+
`@lenserfight/sdk: fn_get_agent_profile failed — ${JSON.stringify(e)}`
|
|
30
27
|
);
|
|
31
28
|
return r ?? null;
|
|
32
29
|
}
|
|
33
30
|
/**
|
|
34
|
-
* Get lens bindings for
|
|
31
|
+
* Get lens bindings for an agent. Uses `fn_list_agent_lens_bindings`.
|
|
35
32
|
*/
|
|
36
33
|
async getLensBindings(t) {
|
|
37
|
-
const { data: r, error: e } = await this.rpcClient.rpc("
|
|
38
|
-
|
|
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
|
|
39
38
|
});
|
|
40
39
|
if (e)
|
|
41
40
|
throw new Error(
|
|
42
|
-
`@lenserfight/sdk:
|
|
41
|
+
`@lenserfight/sdk: fn_list_agent_lens_bindings failed — ${JSON.stringify(e)}`
|
|
43
42
|
);
|
|
44
43
|
return Array.isArray(r) ? r : [];
|
|
45
44
|
}
|
|
46
45
|
/**
|
|
47
|
-
* Get model bindings for
|
|
46
|
+
* Get model bindings for an agent. Uses `fn_list_agent_model_bindings`.
|
|
48
47
|
*/
|
|
49
48
|
async getModelBindings(t) {
|
|
50
|
-
const { data: r, error: e } = await this.rpcClient.rpc("
|
|
51
|
-
|
|
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
|
|
52
53
|
});
|
|
53
54
|
if (e)
|
|
54
55
|
throw new Error(
|
|
55
|
-
`@lenserfight/sdk:
|
|
56
|
+
`@lenserfight/sdk: fn_list_agent_model_bindings failed — ${JSON.stringify(e)}`
|
|
56
57
|
);
|
|
57
58
|
return Array.isArray(r) ? r : [];
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
const
|
|
61
|
-
class
|
|
61
|
+
const y = 100;
|
|
62
|
+
class m {
|
|
62
63
|
constructor(t) {
|
|
63
64
|
this.rpcClient = t;
|
|
64
65
|
}
|
|
@@ -70,77 +71,115 @@ class g {
|
|
|
70
71
|
* For deeper paging, pass the last row's `{created_at, id}` as `cursor`.
|
|
71
72
|
*/
|
|
72
73
|
async browse(t = {}, r, e = 20) {
|
|
73
|
-
const n = Math.max(1, Math.min(e,
|
|
74
|
+
const n = Math.max(1, Math.min(e, y)), a = {
|
|
74
75
|
p_search: t.search ?? null,
|
|
75
76
|
p_category: t.category ?? null,
|
|
76
77
|
p_status: t.status ?? null,
|
|
77
78
|
p_cursor_created_at: r?.created_at ?? null,
|
|
78
79
|
p_cursor_id: r?.id ?? null,
|
|
79
80
|
p_limit: n
|
|
80
|
-
}, { data: s, error:
|
|
81
|
-
if (
|
|
81
|
+
}, { data: s, error: l } = await this.rpcClient.rpc("fn_browse_battles", a);
|
|
82
|
+
if (l)
|
|
82
83
|
throw new Error(
|
|
83
|
-
`@lenserfight/sdk: browse failed — ${JSON.stringify(
|
|
84
|
+
`@lenserfight/sdk: browse failed — ${JSON.stringify(l)}`
|
|
84
85
|
);
|
|
85
86
|
return Array.isArray(s) ? s : [];
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
|
-
function
|
|
89
|
-
if (!
|
|
89
|
+
function b(i) {
|
|
90
|
+
if (!i.url)
|
|
90
91
|
throw new Error("@lenserfight/sdk: createClient requires `url`");
|
|
91
|
-
if (!
|
|
92
|
+
if (!i.anonKey)
|
|
92
93
|
throw new Error("@lenserfight/sdk: createClient requires `anonKey`");
|
|
93
|
-
const t =
|
|
94
|
+
const t = i.fetch ?? globalThis.fetch;
|
|
94
95
|
if (typeof t != "function")
|
|
95
96
|
throw new Error("@lenserfight/sdk: global fetch unavailable — pass `fetch` in options");
|
|
96
|
-
const r =
|
|
97
|
+
const r = i.url.replace(/\/+$/, ""), e = i.apiKey ?? i.anonKey;
|
|
97
98
|
return {
|
|
98
|
-
async rpc(n,
|
|
99
|
+
async rpc(n, a) {
|
|
99
100
|
const s = await t(`${r}/rest/v1/rpc/${n}`, {
|
|
100
101
|
method: "POST",
|
|
101
102
|
headers: {
|
|
102
|
-
apikey:
|
|
103
|
+
apikey: i.anonKey,
|
|
103
104
|
authorization: `Bearer ${e}`,
|
|
104
105
|
"content-type": "application/json"
|
|
105
106
|
},
|
|
106
|
-
body: JSON.stringify(
|
|
107
|
+
body: JSON.stringify(a ?? {})
|
|
107
108
|
});
|
|
108
109
|
if (!s.ok) {
|
|
109
|
-
const
|
|
110
|
+
const o = await s.text().catch(() => "");
|
|
110
111
|
return {
|
|
111
112
|
data: null,
|
|
112
|
-
error: { status: s.status, message:
|
|
113
|
+
error: { status: s.status, message: o || s.statusText }
|
|
113
114
|
};
|
|
114
115
|
}
|
|
115
116
|
return { data: await s.json().catch(() => null), error: null };
|
|
116
117
|
}
|
|
117
118
|
};
|
|
118
119
|
}
|
|
119
|
-
const
|
|
120
|
-
|
|
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 {
|
|
121
146
|
constructor(t) {
|
|
122
147
|
this.rpcClient = t;
|
|
123
148
|
}
|
|
124
149
|
/**
|
|
125
|
-
* 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.
|
|
126
153
|
*/
|
|
127
|
-
async browse(t = {}, r, e = 20) {
|
|
128
|
-
const n = Math.max(1, Math.min(e,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
|
135
174
|
});
|
|
136
175
|
if (s)
|
|
137
|
-
throw new Error(`@lenserfight/sdk:
|
|
138
|
-
return
|
|
176
|
+
throw new Error(`@lenserfight/sdk: fn_mcp_lens_list failed — ${JSON.stringify(s)}`);
|
|
177
|
+
return u(a).map(p);
|
|
139
178
|
}
|
|
140
179
|
/**
|
|
141
180
|
* Full-text search across public lenses.
|
|
142
181
|
*/
|
|
143
|
-
async search(t, r = {}, e, n = 20) {
|
|
182
|
+
async search(t, r = {}, e = 0, n = 20) {
|
|
144
183
|
return this.browse({ ...r, search: t }, e, n);
|
|
145
184
|
}
|
|
146
185
|
/**
|
|
@@ -178,37 +217,31 @@ class k {
|
|
|
178
217
|
* filled prompt and lists which parameters were used or missing.
|
|
179
218
|
*
|
|
180
219
|
* Requires an authenticated client (`apiKey` in `createClient`).
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* const result = await lf.lenses.resolveTemplate(lensId, { Topic: 'TypeScript' });
|
|
184
|
-
* if (result.missing.length === 0) {
|
|
185
|
-
* // pass result.resolvedPrompt to your AI model
|
|
186
|
-
* }
|
|
187
220
|
*/
|
|
188
221
|
async resolveTemplate(t, r, e) {
|
|
189
|
-
const { data: n, error:
|
|
222
|
+
const { data: n, error: a } = await this.rpcClient.rpc("fn_mcp_lens_resolve_template", {
|
|
190
223
|
p_lens_id: t,
|
|
191
224
|
p_version_id: e?.versionId ?? null
|
|
192
225
|
});
|
|
193
|
-
if (
|
|
194
|
-
throw new Error(`@lenserfight/sdk: fn_mcp_lens_resolve_template failed — ${JSON.stringify(
|
|
226
|
+
if (a)
|
|
227
|
+
throw new Error(`@lenserfight/sdk: fn_mcp_lens_resolve_template failed — ${JSON.stringify(a)}`);
|
|
195
228
|
if (!n)
|
|
196
229
|
throw new Error(`@lenserfight/sdk: lens ${t} not found`);
|
|
197
230
|
const s = n;
|
|
198
|
-
let
|
|
199
|
-
const
|
|
200
|
-
for (const
|
|
201
|
-
const d = `[[:${
|
|
202
|
-
f !== void 0 ? (
|
|
231
|
+
let l = s.template_body;
|
|
232
|
+
const o = [], _ = [];
|
|
233
|
+
for (const c of s.parameters ?? []) {
|
|
234
|
+
const d = `[[:${c.id}]]`, f = r[c.label] ?? r[c.label.toLowerCase()] ?? Object.entries(r).find(([w]) => w.toLowerCase() === c.label.toLowerCase())?.[1];
|
|
235
|
+
f !== void 0 ? (l = l.split(d).join(f), _.push(c.label)) : c.optional ? l = l.split(d).join("") : o.push(c.label);
|
|
203
236
|
}
|
|
204
237
|
return {
|
|
205
|
-
resolvedPrompt:
|
|
238
|
+
resolvedPrompt: l,
|
|
206
239
|
lensId: s.lens_id,
|
|
207
240
|
versionId: s.version_id,
|
|
208
241
|
lensTitle: s.title ?? t,
|
|
209
242
|
lensDescription: s.description ?? null,
|
|
210
243
|
paramsUsed: _,
|
|
211
|
-
missing:
|
|
244
|
+
missing: o
|
|
212
245
|
};
|
|
213
246
|
}
|
|
214
247
|
/**
|
|
@@ -224,77 +257,95 @@ class k {
|
|
|
224
257
|
if (!r) return [];
|
|
225
258
|
const n = Array.isArray(r) ? r[0] : r;
|
|
226
259
|
if (!n) return [];
|
|
227
|
-
const
|
|
228
|
-
if (!
|
|
229
|
-
const s =
|
|
260
|
+
const a = n.input_contract;
|
|
261
|
+
if (!a) return [];
|
|
262
|
+
const s = a.parameters ?? a.inputs;
|
|
230
263
|
return Array.isArray(s) ? s : [];
|
|
231
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Extract the parameters declared by a lens version — the contracts plus their labels.
|
|
267
|
+
*/
|
|
268
|
+
async extractParams(t) {
|
|
269
|
+
const r = await this.getParameterContracts(t);
|
|
270
|
+
return { params: r, labels: r.map((e) => e.label) };
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Validate supplied values against a lens version's parameter contracts.
|
|
274
|
+
*/
|
|
275
|
+
async validateParams(t, r) {
|
|
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())
|
|
278
|
+
);
|
|
279
|
+
return {
|
|
280
|
+
valid: s.length === 0 && l.length === 0,
|
|
281
|
+
missing: s,
|
|
282
|
+
unknown: l,
|
|
283
|
+
total: e.length,
|
|
284
|
+
provided: Object.keys(r).length
|
|
285
|
+
};
|
|
286
|
+
}
|
|
232
287
|
}
|
|
233
|
-
class
|
|
288
|
+
class A {
|
|
234
289
|
constructor(t) {
|
|
235
290
|
this.rpcClient = t;
|
|
236
291
|
}
|
|
237
292
|
/**
|
|
238
|
-
* Get the contract for a lens version
|
|
239
|
-
*
|
|
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.
|
|
240
295
|
*/
|
|
241
296
|
async getContractByVersion(t) {
|
|
242
|
-
const { data: r, error: e } = await this.rpcClient.rpc("
|
|
243
|
-
p_version_id: t
|
|
244
|
-
p_content_hash: null
|
|
297
|
+
const { data: r, error: e } = await this.rpcClient.rpc("fn_get_version_contracts", {
|
|
298
|
+
p_version_id: t
|
|
245
299
|
});
|
|
246
300
|
if (e)
|
|
247
|
-
throw new Error(`@lenserfight/sdk:
|
|
248
|
-
|
|
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;
|
|
249
307
|
}
|
|
250
308
|
/**
|
|
251
|
-
*
|
|
252
|
-
*
|
|
309
|
+
* Hash-based contract lookup is not supported by the current DB schema.
|
|
310
|
+
* Always returns null.
|
|
253
311
|
*/
|
|
254
312
|
async getContractByHash(t) {
|
|
255
|
-
|
|
256
|
-
p_version_id: null,
|
|
257
|
-
p_content_hash: t
|
|
258
|
-
});
|
|
259
|
-
if (e)
|
|
260
|
-
throw new Error(`@lenserfight/sdk: fn_sdk_get_contract failed — ${JSON.stringify(e)}`);
|
|
261
|
-
return r ?? null;
|
|
313
|
+
return null;
|
|
262
314
|
}
|
|
263
315
|
/**
|
|
264
|
-
* Get the
|
|
316
|
+
* Get the manifest for a lens version. Built from `fn_get_version_contracts`.
|
|
317
|
+
* Channel and signatures are not available.
|
|
265
318
|
*/
|
|
266
319
|
async getManifest(t) {
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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;
|
|
273
328
|
}
|
|
274
329
|
/**
|
|
275
|
-
*
|
|
330
|
+
* Dependency graph lookup is not supported by the current DB schema.
|
|
331
|
+
* Always returns an empty array.
|
|
276
332
|
*/
|
|
277
333
|
async getDependencies(t) {
|
|
278
|
-
|
|
279
|
-
p_content_hash: t
|
|
280
|
-
});
|
|
281
|
-
if (e)
|
|
282
|
-
throw new Error(`@lenserfight/sdk: fn_sdk_get_dependencies failed — ${JSON.stringify(e)}`);
|
|
283
|
-
return Array.isArray(r) ? r : [];
|
|
334
|
+
return [];
|
|
284
335
|
}
|
|
285
336
|
/**
|
|
286
|
-
* Check if a
|
|
287
|
-
*
|
|
337
|
+
* Check if a lens version satisfies required scopes. Fetches the contract
|
|
338
|
+
* via `getContractByVersion` and compares scopes locally.
|
|
288
339
|
*/
|
|
289
340
|
async checkCompatibility(t, r) {
|
|
290
|
-
const e = await this.
|
|
341
|
+
const e = await this.getContractByVersion(t);
|
|
291
342
|
if (!e)
|
|
292
343
|
return { compatible: !1, missingScopes: [], warnings: ["Contract not found"] };
|
|
293
|
-
const n = e.body
|
|
294
|
-
return { compatible:
|
|
344
|
+
const n = e.body?.requiredScopes ?? [], a = r.filter((s) => !n.includes(s));
|
|
345
|
+
return { compatible: a.length === 0, missingScopes: a, warnings: [] };
|
|
295
346
|
}
|
|
296
347
|
}
|
|
297
|
-
class
|
|
348
|
+
class S {
|
|
298
349
|
constructor(t) {
|
|
299
350
|
this.rpcClient = t;
|
|
300
351
|
}
|
|
@@ -316,8 +367,8 @@ class b {
|
|
|
316
367
|
return typeof e == "string" ? e : "";
|
|
317
368
|
}
|
|
318
369
|
}
|
|
319
|
-
const
|
|
320
|
-
class
|
|
370
|
+
const v = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]), $ = 3e3, E = 12e4;
|
|
371
|
+
class O {
|
|
321
372
|
constructor(t) {
|
|
322
373
|
this.rpcClient = t;
|
|
323
374
|
}
|
|
@@ -355,15 +406,15 @@ class A {
|
|
|
355
406
|
* Requires an authenticated client (`apiKey` in `createClient`).
|
|
356
407
|
*/
|
|
357
408
|
async startRun(t, r, e) {
|
|
358
|
-
const { data: n, error:
|
|
409
|
+
const { data: n, error: a } = await this.rpcClient.rpc("fn_mcp_workflow_run_start", {
|
|
359
410
|
p_workflow_id: t,
|
|
360
411
|
p_inputs: r ?? {},
|
|
361
412
|
p_global_model_id: e?.modelId ?? null,
|
|
362
413
|
p_idempotency_key: e?.idempotencyKey ?? null,
|
|
363
414
|
p_metadata: {}
|
|
364
415
|
});
|
|
365
|
-
if (
|
|
366
|
-
throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_start failed — ${JSON.stringify(
|
|
416
|
+
if (a)
|
|
417
|
+
throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_start failed — ${JSON.stringify(a)}`);
|
|
367
418
|
if (!n)
|
|
368
419
|
throw new Error(`@lenserfight/sdk: workflow ${t} not found or inaccessible`);
|
|
369
420
|
return n;
|
|
@@ -397,8 +448,8 @@ class A {
|
|
|
397
448
|
if (e)
|
|
398
449
|
throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_logs failed — ${JSON.stringify(e)}`);
|
|
399
450
|
const n = r?.node_results;
|
|
400
|
-
return Array.isArray(n) ? n.map((
|
|
401
|
-
const s =
|
|
451
|
+
return Array.isArray(n) ? n.map((a) => {
|
|
452
|
+
const s = a;
|
|
402
453
|
return {
|
|
403
454
|
nodeId: s.node_id,
|
|
404
455
|
status: s.status,
|
|
@@ -417,20 +468,20 @@ class A {
|
|
|
417
468
|
* @param timeoutMs Maximum wait time in milliseconds (default 120 s).
|
|
418
469
|
*/
|
|
419
470
|
async awaitRun(t, r, e) {
|
|
420
|
-
const n = e?.timeoutMs ?? E,
|
|
471
|
+
const n = e?.timeoutMs ?? E, a = await this.startRun(t, r, e), s = Date.now() + n;
|
|
421
472
|
for (; Date.now() < s; ) {
|
|
422
|
-
await new Promise((
|
|
423
|
-
const
|
|
424
|
-
if (
|
|
425
|
-
if (
|
|
426
|
-
return this.getRunLogs(
|
|
427
|
-
throw new Error(`@lenserfight/sdk: workflow run ${
|
|
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")
|
|
477
|
+
return this.getRunLogs(a.id);
|
|
478
|
+
throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${l.status}"`);
|
|
428
479
|
}
|
|
429
480
|
}
|
|
430
|
-
throw new Error(`@lenserfight/sdk: workflow run ${
|
|
481
|
+
throw new Error(`@lenserfight/sdk: workflow run ${a.id} timed out after ${n}ms`);
|
|
431
482
|
}
|
|
432
483
|
}
|
|
433
|
-
class
|
|
484
|
+
class h {
|
|
434
485
|
agents;
|
|
435
486
|
battles;
|
|
436
487
|
lenses;
|
|
@@ -439,12 +490,11 @@ class p {
|
|
|
439
490
|
workflows;
|
|
440
491
|
rpc;
|
|
441
492
|
constructor(t) {
|
|
442
|
-
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);
|
|
443
494
|
}
|
|
444
495
|
/**
|
|
445
496
|
* Direct RPC escape hatch. Use sparingly — anything that's part of the
|
|
446
|
-
* stable surface should live on
|
|
447
|
-
* in a follow-up PR).
|
|
497
|
+
* stable surface should live on a named sub-client.
|
|
448
498
|
*/
|
|
449
499
|
async rpcCall(t, r) {
|
|
450
500
|
const { data: e, error: n } = await this.rpc.rpc(t, r);
|
|
@@ -453,22 +503,24 @@ class p {
|
|
|
453
503
|
return e;
|
|
454
504
|
}
|
|
455
505
|
}
|
|
456
|
-
function
|
|
457
|
-
const t =
|
|
458
|
-
return new
|
|
506
|
+
function N(i) {
|
|
507
|
+
const t = b(i);
|
|
508
|
+
return new h(t);
|
|
459
509
|
}
|
|
460
|
-
function
|
|
461
|
-
return new
|
|
510
|
+
function M(i) {
|
|
511
|
+
return new h(i);
|
|
462
512
|
}
|
|
463
|
-
const
|
|
513
|
+
const L = "1.0.0";
|
|
464
514
|
export {
|
|
465
|
-
g as
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
O as
|
|
473
|
-
|
|
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
|
|
474
526
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenserfight/sdk",
|
|
3
|
-
"version": "
|
|
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",
|