@lenserfight/sdk 0.3.0-alpha.12 → 0.3.0-alpha.14
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 +3 -1
- package/index.mjs +83 -57
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=100;class w{constructor(t){this.rpcClient=t}async browse(t={},r,e=20){const n=Math.max(1,Math.min(e,C)),a={p_search:t.search??null,p_cursor_created_at:r?.created_at??null,p_cursor_id:r?.id??null,p_limit:n},{data:s,error:i}=await this.rpcClient.rpc("fn_sdk_browse_agents",a);if(i)throw new Error(`@lenserfight/sdk: fn_sdk_browse_agents failed — ${JSON.stringify(i)}`);return Array.isArray(s)?s:[]}async getById(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_agent_detail",{p_agent_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_agent_detail failed — ${JSON.stringify(e)}`);return r??null}async getLensBindings(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_agent_lens_bindings",{p_agent_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_agent_lens_bindings failed — ${JSON.stringify(e)}`);return Array.isArray(r)?r:[]}async getModelBindings(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_agent_model_bindings",{p_agent_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_agent_model_bindings failed — ${JSON.stringify(e)}`);return Array.isArray(r)?r:[]}}const b=100;class u{constructor(t){this.rpcClient=t}async browse(t={},r,e=20){const n=Math.max(1,Math.min(e,b)),a={p_search:t.search??null,p_category:t.category??null,p_status:t.status??null,p_cursor_created_at:r?.created_at??null,p_cursor_id:r?.id??null,p_limit:n},{data:s,error:i}=await this.rpcClient.rpc("fn_browse_battles",a);if(i)throw new Error(`@lenserfight/sdk: browse failed — ${JSON.stringify(i)}`);return Array.isArray(s)?s:[]}}function h(o){if(!o.url)throw new Error("@lenserfight/sdk: createClient requires `url`");if(!o.anonKey)throw new Error("@lenserfight/sdk: createClient requires `anonKey`");const t=o.fetch??globalThis.fetch;if(typeof t!="function")throw new Error("@lenserfight/sdk: global fetch unavailable — pass `fetch` in options");const r=o.url.replace(/\/+$/,""),e=o.apiKey??o.anonKey;return{async rpc(n,a){const s=await t(`${r}/rest/v1/rpc/${n}`,{method:"POST",headers:{apikey:o.anonKey,authorization:`Bearer ${e}`,"content-type":"application/json"},body:JSON.stringify(a??{})});if(!s.ok){const l=await s.text().catch(()=>"");return{data:null,error:{status:s.status,message:l||s.statusText}}}return{data:await s.json().catch(()=>null),error:null}}}}const S=100;class g{constructor(t){this.rpcClient=t}async browse(t={},r,e=20){const n=Math.max(1,Math.min(e,S)),{data:a,error:s}=await this.rpcClient.rpc("fn_sdk_browse_lenses",{p_search:t.search??null,p_tag:t.tag??null,p_kind:t.kind??null,p_cursor_created_at:r?.created_at??null,p_cursor_id:r?.id??null,p_limit:n});if(s)throw new Error(`@lenserfight/sdk: fn_sdk_browse_lenses failed — ${JSON.stringify(s)}`);return Array.isArray(a)?a:[]}async search(t,r={},e,n=20){return this.browse({...r,search:t},e,n)}async getById(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_get_lens_detail_bootstrap",{p_lens_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_get_lens_detail_bootstrap failed — ${JSON.stringify(e)}`);return!r||r.error?null:r}async getVersion(t){const[r,e]=await Promise.all([this.rpcClient.rpc("fn_get_lens_version_detail",{p_version_id:t}),this.rpcClient.rpc("fn_get_lens_version_parameters",{p_version_id:t})]);if(r.error)throw new Error(`@lenserfight/sdk: fn_get_lens_version_detail failed — ${JSON.stringify(r.error)}`);if(!r.data)return null;const n=Array.isArray(r.data)?r.data[0]:r.data;return n?{...n,parameters:Array.isArray(e.data)?e.data:e.data??[]}:null}async resolveTemplate(t,r,e){const{data:n,error:a}=await this.rpcClient.rpc("fn_mcp_lens_resolve_template",{p_lens_id:t,p_version_id:e?.versionId??null});if(a)throw new Error(`@lenserfight/sdk: fn_mcp_lens_resolve_template failed — ${JSON.stringify(a)}`);if(!n)throw new Error(`@lenserfight/sdk: lens ${t} not found`);const s=n;let i=s.template_body;const l=[],d=[];for(const c of s.parameters??[]){const f=`[[:${c.id}]]`,p=r[c.label]??r[c.label.toLowerCase()]??Object.entries(r).find(([k])=>k.toLowerCase()===c.label.toLowerCase())?.[1];p!==void 0?(i=i.split(f).join(p),d.push(c.label)):c.optional?i=i.split(f).join(""):l.push(c.label)}return{resolvedPrompt:i,lensId:s.lens_id,versionId:s.version_id,lensTitle:s.title??t,lensDescription:s.description??null,paramsUsed:d,missing:l}}async getParameterContracts(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_get_version_contracts",{p_version_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_get_version_contracts failed — ${JSON.stringify(e)}`);if(!r)return[];const n=Array.isArray(r)?r[0]:r;if(!n)return[];const a=n.input_contract;if(!a)return[];const s=a.parameters??a.inputs;return Array.isArray(s)?s:[]}async extractParams(t){const r=await this.getParameterContracts(t);return{params:r,labels:r.map(e=>e.label)}}async validateParams(t,r){const e=await this.getParameterContracts(t),n=new Set(Object.keys(r).map(l=>l.toLowerCase())),a=new Set(e.map(l=>l.label.toLowerCase())),s=e.filter(l=>l.required&&!n.has(l.label.toLowerCase())).map(l=>l.label),i=Object.keys(r).filter(l=>!a.has(l.toLowerCase()));return{valid:s.length===0&&i.length===0,missing:s,unknown:i,total:e.length,provided:Object.keys(r).length}}}class E{constructor(t){this.rpcClient=t}async getContractByVersion(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_contract",{p_version_id:t,p_content_hash:null});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_contract failed — ${JSON.stringify(e)}`);return r??null}async getContractByHash(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_contract",{p_version_id:null,p_content_hash:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_contract failed — ${JSON.stringify(e)}`);return r??null}async getManifest(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_manifest",{p_version_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_manifest failed — ${JSON.stringify(e)}`);return r??null}async getDependencies(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_sdk_get_dependencies",{p_content_hash:t});if(e)throw new Error(`@lenserfight/sdk: fn_sdk_get_dependencies failed — ${JSON.stringify(e)}`);return Array.isArray(r)?r:[]}async checkCompatibility(t,r){const e=await this.getContractByHash(t);if(!e)return{compatible:!1,missingScopes:[],warnings:["Contract not found"]};const n=e.body.requiredScopes??[],a=r.filter(s=>!n.includes(s));return{compatible:a.length===0,missingScopes:a,warnings:[]}}}class y{constructor(t){this.rpcClient=t}async renderPrompt(t,r={}){const{data:e,error:n}=await this.rpcClient.rpc("fn_battles_render_prompt",{p_template_id:t,p_variables:r});if(n)throw new Error(`@lenserfight/sdk: renderPrompt failed — ${JSON.stringify(n)}`);return typeof e=="string"?e:""}}const $=new Set(["completed","failed","cancelled"]),A=3e3,O=12e4;class m{constructor(t){this.rpcClient=t}async browse(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_mcp_workflow_list",{p_limit:t?.limit??20,p_offset:t?.offset??0,p_visibility:t?.visibility??null,p_lenser_id:null});if(e)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_list failed — ${JSON.stringify(e)}`);const n=r?.data;return Array.isArray(n)?n:[]}async getById(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_mcp_workflow_get",{p_workflow_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_get failed — ${JSON.stringify(e)}`);return r??null}async startRun(t,r,e){const{data:n,error:a}=await this.rpcClient.rpc("fn_mcp_workflow_run_start",{p_workflow_id:t,p_inputs:r??{},p_global_model_id:e?.modelId??null,p_idempotency_key:e?.idempotencyKey??null,p_metadata:{}});if(a)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_start failed — ${JSON.stringify(a)}`);if(!n)throw new Error(`@lenserfight/sdk: workflow ${t} not found or inaccessible`);return n}async getRunStatus(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_mcp_workflow_run_status",{p_run_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_status failed — ${JSON.stringify(e)}`);if(!r)throw new Error(`@lenserfight/sdk: run ${t} not found`);const n=r;return{id:n.id,status:n.status,activeNodeId:n.active_node_id??null,creditsSpent:n.credits_spent??0}}async getRunLogs(t){const{data:r,error:e}=await this.rpcClient.rpc("fn_mcp_workflow_run_logs",{p_run_id:t});if(e)throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_logs failed — ${JSON.stringify(e)}`);const n=r?.node_results;return Array.isArray(n)?n.map(a=>{const s=a;return{nodeId:s.node_id,status:s.status,result:s.result??null,error:s.error??null,durationMs:s.duration_ms??0,tokenCount:s.token_count??0}}):[]}async awaitRun(t,r,e){const n=e?.timeoutMs??O,a=await this.startRun(t,r,e),s=Date.now()+n;for(;Date.now()<s;){await new Promise(l=>setTimeout(l,A));const i=await this.getRunStatus(a.id);if($.has(i.status)){if(i.status==="completed")return this.getRunLogs(a.id);throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${i.status}"`)}}throw new Error(`@lenserfight/sdk: workflow run ${a.id} timed out after ${n}ms`)}}class _{agents;battles;lenses;protocols;templates;workflows;rpc;constructor(t){this.rpc=t,this.agents=new w(t),this.battles=new u(t),this.lenses=new g(t),this.protocols=new E(t),this.templates=new y(t),this.workflows=new m(t)}async rpcCall(t,r){const{data:e,error:n}=await this.rpc.rpc(t,r);if(n)throw new Error(`@lenserfight/sdk: ${t} failed — ${JSON.stringify(n)}`);return e}}function v(o){const t=h(o);return new _(t)}function N(o){return new _(o)}const L="0.4.0-alpha.0";exports.AgentClient=w;exports.BattleClient=u;exports.LensClient=g;exports.LenserFightClient=_;exports.SDK_VERSION=L;exports.TemplateClient=y;exports.WorkflowClient=m;exports.createClient=v;exports.createClientFromRpc=N;exports.createFetchRpcClient=h;
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createClient, createClientFromRpc, LenserFightClient } from './lib/lenserfight-client';
|
|
2
|
+
export { AgentClient } from './lib/agent-client';
|
|
2
3
|
export { BattleClient } from './lib/battle-client';
|
|
3
4
|
export { LensClient } from './lib/lens-client';
|
|
4
5
|
export { TemplateClient } from './lib/template-client';
|
|
@@ -8,4 +9,5 @@ export type { SupabaseLikeRpcClient } from './lib/client';
|
|
|
8
9
|
export type { BattleLifecycleStatus, BrowseFilters, BrowseCursor, BrowseBattle, BattleTemplate, CreateClientOptions, } from './lib/types';
|
|
9
10
|
export type { LensBrowseFilters, SdkLensDetail, SdkLensKind, SdkLensParameter, SdkLensSummary, SdkLensVersion, SdkLensVersionSummary, SdkParameterTool, SdkResolvedTemplate, SdkVisibility, SdkContentStatus, } from './lib/types/lenses';
|
|
10
11
|
export type { SdkWorkflowDetail, SdkWorkflowRun, SdkWorkflowRunLog, SdkWorkflowRunState, SdkWorkflowRunStatus, SdkWorkflowSummary, } from './lib/types/workflows';
|
|
11
|
-
export
|
|
12
|
+
export type { AgentBrowseFilters, SdkAgentCapabilities, SdkAgentDetail, SdkAgentLensBinding, SdkAgentModelBinding, SdkAgentModelBindingMode, SdkAgentOwner, SdkAgentRuntimePref, SdkAgentStats, SdkAgentSummary, } from './lib/types/agents';
|
|
13
|
+
export declare const SDK_VERSION = "0.4.0-alpha.0";
|
package/index.mjs
CHANGED
|
@@ -7,14 +7,14 @@ class u {
|
|
|
7
7
|
* Keyset pagination on (created_at DESC, id DESC).
|
|
8
8
|
*/
|
|
9
9
|
async browse(t = {}, r, e = 20) {
|
|
10
|
-
const n = Math.max(1, Math.min(e, 100)),
|
|
10
|
+
const n = Math.max(1, Math.min(e, 100)), a = {
|
|
11
11
|
p_search: t.search ?? null,
|
|
12
12
|
p_cursor_created_at: r?.created_at ?? null,
|
|
13
13
|
p_cursor_id: r?.id ?? null,
|
|
14
14
|
p_limit: n
|
|
15
|
-
}, { data: s, error:
|
|
16
|
-
if (
|
|
17
|
-
throw new Error(`@lenserfight/sdk: fn_sdk_browse_agents failed — ${JSON.stringify(
|
|
15
|
+
}, { data: s, error: i } = await this.rpcClient.rpc("fn_sdk_browse_agents", a);
|
|
16
|
+
if (i)
|
|
17
|
+
throw new Error(`@lenserfight/sdk: fn_sdk_browse_agents failed — ${JSON.stringify(i)}`);
|
|
18
18
|
return Array.isArray(s) ? s : [];
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
@@ -70,46 +70,46 @@ class g {
|
|
|
70
70
|
* For deeper paging, pass the last row's `{created_at, id}` as `cursor`.
|
|
71
71
|
*/
|
|
72
72
|
async browse(t = {}, r, e = 20) {
|
|
73
|
-
const n = Math.max(1, Math.min(e, h)),
|
|
73
|
+
const n = Math.max(1, Math.min(e, h)), a = {
|
|
74
74
|
p_search: t.search ?? null,
|
|
75
75
|
p_category: t.category ?? null,
|
|
76
76
|
p_status: t.status ?? null,
|
|
77
77
|
p_cursor_created_at: r?.created_at ?? null,
|
|
78
78
|
p_cursor_id: r?.id ?? null,
|
|
79
79
|
p_limit: n
|
|
80
|
-
}, { data: s, error:
|
|
81
|
-
if (
|
|
80
|
+
}, { data: s, error: i } = await this.rpcClient.rpc("fn_browse_battles", a);
|
|
81
|
+
if (i)
|
|
82
82
|
throw new Error(
|
|
83
|
-
`@lenserfight/sdk: browse failed — ${JSON.stringify(
|
|
83
|
+
`@lenserfight/sdk: browse failed — ${JSON.stringify(i)}`
|
|
84
84
|
);
|
|
85
85
|
return Array.isArray(s) ? s : [];
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
function y(
|
|
89
|
-
if (!
|
|
88
|
+
function y(o) {
|
|
89
|
+
if (!o.url)
|
|
90
90
|
throw new Error("@lenserfight/sdk: createClient requires `url`");
|
|
91
|
-
if (!
|
|
91
|
+
if (!o.anonKey)
|
|
92
92
|
throw new Error("@lenserfight/sdk: createClient requires `anonKey`");
|
|
93
|
-
const t =
|
|
93
|
+
const t = o.fetch ?? globalThis.fetch;
|
|
94
94
|
if (typeof t != "function")
|
|
95
95
|
throw new Error("@lenserfight/sdk: global fetch unavailable — pass `fetch` in options");
|
|
96
|
-
const r =
|
|
96
|
+
const r = o.url.replace(/\/+$/, ""), e = o.apiKey ?? o.anonKey;
|
|
97
97
|
return {
|
|
98
|
-
async rpc(n,
|
|
98
|
+
async rpc(n, a) {
|
|
99
99
|
const s = await t(`${r}/rest/v1/rpc/${n}`, {
|
|
100
100
|
method: "POST",
|
|
101
101
|
headers: {
|
|
102
|
-
apikey:
|
|
102
|
+
apikey: o.anonKey,
|
|
103
103
|
authorization: `Bearer ${e}`,
|
|
104
104
|
"content-type": "application/json"
|
|
105
105
|
},
|
|
106
|
-
body: JSON.stringify(
|
|
106
|
+
body: JSON.stringify(a ?? {})
|
|
107
107
|
});
|
|
108
108
|
if (!s.ok) {
|
|
109
|
-
const
|
|
109
|
+
const l = await s.text().catch(() => "");
|
|
110
110
|
return {
|
|
111
111
|
data: null,
|
|
112
|
-
error: { status: s.status, message:
|
|
112
|
+
error: { status: s.status, message: l || s.statusText }
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
return { data: await s.json().catch(() => null), error: null };
|
|
@@ -125,7 +125,7 @@ class k {
|
|
|
125
125
|
* Browse public lenses. Keyset pagination on (created_at DESC, id DESC).
|
|
126
126
|
*/
|
|
127
127
|
async browse(t = {}, r, e = 20) {
|
|
128
|
-
const n = Math.max(1, Math.min(e, m)), { data:
|
|
128
|
+
const n = Math.max(1, Math.min(e, m)), { data: a, error: s } = await this.rpcClient.rpc("fn_sdk_browse_lenses", {
|
|
129
129
|
p_search: t.search ?? null,
|
|
130
130
|
p_tag: t.tag ?? null,
|
|
131
131
|
p_kind: t.kind ?? null,
|
|
@@ -135,7 +135,7 @@ class k {
|
|
|
135
135
|
});
|
|
136
136
|
if (s)
|
|
137
137
|
throw new Error(`@lenserfight/sdk: fn_sdk_browse_lenses failed — ${JSON.stringify(s)}`);
|
|
138
|
-
return Array.isArray(
|
|
138
|
+
return Array.isArray(a) ? a : [];
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
141
|
* Full-text search across public lenses.
|
|
@@ -186,29 +186,29 @@ class k {
|
|
|
186
186
|
* }
|
|
187
187
|
*/
|
|
188
188
|
async resolveTemplate(t, r, e) {
|
|
189
|
-
const { data: n, error:
|
|
189
|
+
const { data: n, error: a } = await this.rpcClient.rpc("fn_mcp_lens_resolve_template", {
|
|
190
190
|
p_lens_id: t,
|
|
191
191
|
p_version_id: e?.versionId ?? null
|
|
192
192
|
});
|
|
193
|
-
if (
|
|
194
|
-
throw new Error(`@lenserfight/sdk: fn_mcp_lens_resolve_template failed — ${JSON.stringify(
|
|
193
|
+
if (a)
|
|
194
|
+
throw new Error(`@lenserfight/sdk: fn_mcp_lens_resolve_template failed — ${JSON.stringify(a)}`);
|
|
195
195
|
if (!n)
|
|
196
196
|
throw new Error(`@lenserfight/sdk: lens ${t} not found`);
|
|
197
197
|
const s = n;
|
|
198
|
-
let
|
|
199
|
-
const
|
|
200
|
-
for (const
|
|
201
|
-
const d = `[[:${
|
|
202
|
-
f !== void 0 ? (
|
|
198
|
+
let i = s.template_body;
|
|
199
|
+
const l = [], _ = [];
|
|
200
|
+
for (const c of s.parameters ?? []) {
|
|
201
|
+
const d = `[[:${c.id}]]`, f = r[c.label] ?? r[c.label.toLowerCase()] ?? Object.entries(r).find(([w]) => w.toLowerCase() === c.label.toLowerCase())?.[1];
|
|
202
|
+
f !== void 0 ? (i = i.split(d).join(f), _.push(c.label)) : c.optional ? i = i.split(d).join("") : l.push(c.label);
|
|
203
203
|
}
|
|
204
204
|
return {
|
|
205
|
-
resolvedPrompt:
|
|
205
|
+
resolvedPrompt: i,
|
|
206
206
|
lensId: s.lens_id,
|
|
207
207
|
versionId: s.version_id,
|
|
208
208
|
lensTitle: s.title ?? t,
|
|
209
209
|
lensDescription: s.description ?? null,
|
|
210
210
|
paramsUsed: _,
|
|
211
|
-
missing:
|
|
211
|
+
missing: l
|
|
212
212
|
};
|
|
213
213
|
}
|
|
214
214
|
/**
|
|
@@ -224,13 +224,38 @@ class k {
|
|
|
224
224
|
if (!r) return [];
|
|
225
225
|
const n = Array.isArray(r) ? r[0] : r;
|
|
226
226
|
if (!n) return [];
|
|
227
|
-
const
|
|
228
|
-
if (!
|
|
229
|
-
const s =
|
|
227
|
+
const a = n.input_contract;
|
|
228
|
+
if (!a) return [];
|
|
229
|
+
const s = a.parameters ?? a.inputs;
|
|
230
230
|
return Array.isArray(s) ? s : [];
|
|
231
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Extract the parameters declared by a lens version — the contracts plus their
|
|
234
|
+
* labels. Use this to know which values a lens needs before resolving it.
|
|
235
|
+
*/
|
|
236
|
+
async extractParams(t) {
|
|
237
|
+
const r = await this.getParameterContracts(t);
|
|
238
|
+
return { params: r, labels: r.map((e) => e.label) };
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Validate supplied values against a lens version's parameter contracts.
|
|
242
|
+
* - `missing`: required parameter labels with no value
|
|
243
|
+
* - `unknown`: provided keys that match no contract label (case-insensitive)
|
|
244
|
+
*/
|
|
245
|
+
async validateParams(t, r) {
|
|
246
|
+
const e = await this.getParameterContracts(t), n = new Set(Object.keys(r).map((l) => l.toLowerCase())), a = new Set(e.map((l) => l.label.toLowerCase())), s = e.filter((l) => l.required && !n.has(l.label.toLowerCase())).map((l) => l.label), i = Object.keys(r).filter(
|
|
247
|
+
(l) => !a.has(l.toLowerCase())
|
|
248
|
+
);
|
|
249
|
+
return {
|
|
250
|
+
valid: s.length === 0 && i.length === 0,
|
|
251
|
+
missing: s,
|
|
252
|
+
unknown: i,
|
|
253
|
+
total: e.length,
|
|
254
|
+
provided: Object.keys(r).length
|
|
255
|
+
};
|
|
256
|
+
}
|
|
232
257
|
}
|
|
233
|
-
class
|
|
258
|
+
class b {
|
|
234
259
|
constructor(t) {
|
|
235
260
|
this.rpcClient = t;
|
|
236
261
|
}
|
|
@@ -290,11 +315,11 @@ class C {
|
|
|
290
315
|
const e = await this.getContractByHash(t);
|
|
291
316
|
if (!e)
|
|
292
317
|
return { compatible: !1, missingScopes: [], warnings: ["Contract not found"] };
|
|
293
|
-
const n = e.body.requiredScopes ?? [],
|
|
294
|
-
return { compatible:
|
|
318
|
+
const n = e.body.requiredScopes ?? [], a = r.filter((s) => !n.includes(s));
|
|
319
|
+
return { compatible: a.length === 0, missingScopes: a, warnings: [] };
|
|
295
320
|
}
|
|
296
321
|
}
|
|
297
|
-
class
|
|
322
|
+
class C {
|
|
298
323
|
constructor(t) {
|
|
299
324
|
this.rpcClient = t;
|
|
300
325
|
}
|
|
@@ -355,15 +380,15 @@ class A {
|
|
|
355
380
|
* Requires an authenticated client (`apiKey` in `createClient`).
|
|
356
381
|
*/
|
|
357
382
|
async startRun(t, r, e) {
|
|
358
|
-
const { data: n, error:
|
|
383
|
+
const { data: n, error: a } = await this.rpcClient.rpc("fn_mcp_workflow_run_start", {
|
|
359
384
|
p_workflow_id: t,
|
|
360
385
|
p_inputs: r ?? {},
|
|
361
386
|
p_global_model_id: e?.modelId ?? null,
|
|
362
387
|
p_idempotency_key: e?.idempotencyKey ?? null,
|
|
363
388
|
p_metadata: {}
|
|
364
389
|
});
|
|
365
|
-
if (
|
|
366
|
-
throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_start failed — ${JSON.stringify(
|
|
390
|
+
if (a)
|
|
391
|
+
throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_start failed — ${JSON.stringify(a)}`);
|
|
367
392
|
if (!n)
|
|
368
393
|
throw new Error(`@lenserfight/sdk: workflow ${t} not found or inaccessible`);
|
|
369
394
|
return n;
|
|
@@ -397,8 +422,8 @@ class A {
|
|
|
397
422
|
if (e)
|
|
398
423
|
throw new Error(`@lenserfight/sdk: fn_mcp_workflow_run_logs failed — ${JSON.stringify(e)}`);
|
|
399
424
|
const n = r?.node_results;
|
|
400
|
-
return Array.isArray(n) ? n.map((
|
|
401
|
-
const s =
|
|
425
|
+
return Array.isArray(n) ? n.map((a) => {
|
|
426
|
+
const s = a;
|
|
402
427
|
return {
|
|
403
428
|
nodeId: s.node_id,
|
|
404
429
|
status: s.status,
|
|
@@ -417,17 +442,17 @@ class A {
|
|
|
417
442
|
* @param timeoutMs Maximum wait time in milliseconds (default 120 s).
|
|
418
443
|
*/
|
|
419
444
|
async awaitRun(t, r, e) {
|
|
420
|
-
const n = e?.timeoutMs ?? E,
|
|
445
|
+
const n = e?.timeoutMs ?? E, a = await this.startRun(t, r, e), s = Date.now() + n;
|
|
421
446
|
for (; Date.now() < s; ) {
|
|
422
|
-
await new Promise((
|
|
423
|
-
const
|
|
424
|
-
if (S.has(
|
|
425
|
-
if (
|
|
426
|
-
return this.getRunLogs(
|
|
427
|
-
throw new Error(`@lenserfight/sdk: workflow run ${
|
|
447
|
+
await new Promise((l) => setTimeout(l, $));
|
|
448
|
+
const i = await this.getRunStatus(a.id);
|
|
449
|
+
if (S.has(i.status)) {
|
|
450
|
+
if (i.status === "completed")
|
|
451
|
+
return this.getRunLogs(a.id);
|
|
452
|
+
throw new Error(`@lenserfight/sdk: workflow run ${a.id} ended with status "${i.status}"`);
|
|
428
453
|
}
|
|
429
454
|
}
|
|
430
|
-
throw new Error(`@lenserfight/sdk: workflow run ${
|
|
455
|
+
throw new Error(`@lenserfight/sdk: workflow run ${a.id} timed out after ${n}ms`);
|
|
431
456
|
}
|
|
432
457
|
}
|
|
433
458
|
class p {
|
|
@@ -439,7 +464,7 @@ class p {
|
|
|
439
464
|
workflows;
|
|
440
465
|
rpc;
|
|
441
466
|
constructor(t) {
|
|
442
|
-
this.rpc = t, this.agents = new u(t), this.battles = new g(t), this.lenses = new k(t), this.protocols = new
|
|
467
|
+
this.rpc = t, this.agents = new u(t), this.battles = new g(t), this.lenses = new k(t), this.protocols = new b(t), this.templates = new C(t), this.workflows = new A(t);
|
|
443
468
|
}
|
|
444
469
|
/**
|
|
445
470
|
* Direct RPC escape hatch. Use sparingly — anything that's part of the
|
|
@@ -453,20 +478,21 @@ class p {
|
|
|
453
478
|
return e;
|
|
454
479
|
}
|
|
455
480
|
}
|
|
456
|
-
function v(
|
|
457
|
-
const t = y(
|
|
481
|
+
function v(o) {
|
|
482
|
+
const t = y(o);
|
|
458
483
|
return new p(t);
|
|
459
484
|
}
|
|
460
|
-
function O(
|
|
461
|
-
return new p(
|
|
485
|
+
function O(o) {
|
|
486
|
+
return new p(o);
|
|
462
487
|
}
|
|
463
|
-
const N = "0.
|
|
488
|
+
const N = "0.4.0-alpha.0";
|
|
464
489
|
export {
|
|
490
|
+
u as AgentClient,
|
|
465
491
|
g as BattleClient,
|
|
466
492
|
k as LensClient,
|
|
467
493
|
p as LenserFightClient,
|
|
468
494
|
N as SDK_VERSION,
|
|
469
|
-
|
|
495
|
+
C as TemplateClient,
|
|
470
496
|
A as WorkflowClient,
|
|
471
497
|
v as createClient,
|
|
472
498
|
O as createClientFromRpc,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenserfight/sdk",
|
|
3
|
-
"version": "0.3.0-alpha.
|
|
3
|
+
"version": "0.3.0-alpha.14",
|
|
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",
|