@lensmcp/protocol-types 1.25.48 → 1.25.49
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/lib/ai-call.js +5 -5
- package/lib/dashboard.d.ts +84 -0
- package/lib/team.d.ts +55 -0
- package/package.json +1 -1
package/lib/ai-call.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var se=Object.defineProperty;var v=(t,s)=>se(t,"name",{value:s,configurable:!0});var oe=Object.defineProperty,_=v((t,s)=>oe(t,"name",{value:s,configurable:!0}),"d");const b=_(t=>!!t&&typeof t=="object"&&!Array.isArray(t),"isObj"),e=_(t=>typeof t=="string"?t:void 0,"str"),h=_(t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,"num"),k=_(t=>Array.isArray(t)?t:[],"arr"),c=_(t=>b(t)?t:{},"obj"),A=_(t=>typeof t=="string"?t:t===void 0?"":JSON.stringify(t),"json"),
|
|
1
|
+
"use strict";var se=Object.defineProperty;var v=(t,s)=>se(t,"name",{value:s,configurable:!0});var oe=Object.defineProperty,_=v((t,s)=>oe(t,"name",{value:s,configurable:!0}),"d");const b=_(t=>!!t&&typeof t=="object"&&!Array.isArray(t),"isObj"),e=_(t=>typeof t=="string"?t:void 0,"str"),h=_(t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,"num"),k=_(t=>Array.isArray(t)?t:[],"arr"),c=_(t=>b(t)?t:{},"obj"),A=_(t=>typeof t=="string"?t:t===void 0?"":JSON.stringify(t),"json"),F=_(t=>t>=1024*1024?`${(t/1024/1024).toFixed(1)} MB`:`${Math.round(t/1024)} KB`,"kb");export const CUT_MARK="\u2026";export function parseJsonPrefix(t){try{return{value:JSON.parse(t),cut:!1}}catch{}const s=[];let n=0,l=!1,a=!1,r=!1;const o=t.length,i=_(m=>{const d=s[s.length-1];d&&(d.state="after"),n=m},"ended");for(let m=0;m<o;m++){const d=t[m];if(l){r?r=!1:d==="\\"?r=!0:d==='"'&&(l=!1,a?s[s.length-1].state="colon":i(m+1));continue}if(d===" "||d===`
|
|
2
2
|
`||d==="\r"||d===" ")continue;const f=s[s.length-1];if(d==='"'){l=!0,a=!!f&&f.c==="{"&&f.state==="key";continue}if(d==="{"||d==="["){s.push({c:d,state:d==="{"?"key":"value"}),n=m+1;continue}if(d==="}"||d==="]"){s.pop(),i(m+1);continue}if(d===":"){f&&(f.state="value");continue}if(d===","){f&&(f.state=f.c==="{"?"key":"value");continue}let g=m;for(;g<o&&!`,}]
|
|
3
|
-
\r `.includes(t[g]);)g++;if(g>=o)break;i(g),m=g-1}const u=s.map(m=>m.c==="{"?"}":"]").reverse().join("");if(l&&!a)for(let m=0;m<=6;m++)try{return{value:JSON.parse(`${t.slice(0,o-m)}${CUT_MARK}"${u}`),cut:!0}}catch{}if(n)try{return{value:JSON.parse(`${t.slice(0,n)}${u}`),cut:!0}}catch{return}}v(parseJsonPrefix,"parseJsonPrefix"),_(parseJsonPrefix,"parseJsonPrefix");export function aiApiOf(t){const s=t.split("?")[0].replace(/\/+$/,"");if(/\/responses$/.test(s))return"responses";if(/\/chat\/completions$/.test(s))return"chat";if(/\/embeddings$/.test(s))return"embeddings";if(/\/messages$/.test(s))return"messages"}v(aiApiOf,"aiApiOf"),_(aiApiOf,"aiApiOf");export function splitToolName(t,s){if(s)return{server:s,tool:t};const n=/^(?:mcp__)?([A-Za-z0-9-]+(?:_[A-Za-z0-9-]+)*)__(.+)$/.exec(t);return n?{server:n[1],tool:n[2]}:{tool:t}}v(splitToolName,"splitToolName"),_(splitToolName,"splitToolName");const $=_((t,s,n={})=>({...n.callId?{callId:n.callId}:{},name:t,...splitToolName(t,n.server),arguments:s,...n.output!==void 0?{output:n.output}:{},...n.error?{error:n.error}:{}}),"toolCall");function M(t,s,n){if(!t)return;if(t.omitted==="ai"){n.push(`The ${s==="request"?"prompt":"answer"} was not kept \u2014 an AI provider\u2019s bodies are kept only when asked for: Settings \u203A
|
|
3
|
+
\r `.includes(t[g]);)g++;if(g>=o)break;i(g),m=g-1}const u=s.map(m=>m.c==="{"?"}":"]").reverse().join("");if(l&&!a)for(let m=0;m<=6;m++)try{return{value:JSON.parse(`${t.slice(0,o-m)}${CUT_MARK}"${u}`),cut:!0}}catch{}if(n)try{return{value:JSON.parse(`${t.slice(0,n)}${u}`),cut:!0}}catch{return}}v(parseJsonPrefix,"parseJsonPrefix"),_(parseJsonPrefix,"parseJsonPrefix");export function aiApiOf(t){const s=t.split("?")[0].replace(/\/+$/,"");if(/\/responses$/.test(s))return"responses";if(/\/chat\/completions$/.test(s))return"chat";if(/\/embeddings$/.test(s))return"embeddings";if(/\/messages$/.test(s))return"messages"}v(aiApiOf,"aiApiOf"),_(aiApiOf,"aiApiOf");export function splitToolName(t,s){if(s)return{server:s,tool:t};const n=/^(?:mcp__)?([A-Za-z0-9-]+(?:_[A-Za-z0-9-]+)*)__(.+)$/.exec(t);return n?{server:n[1],tool:n[2]}:{tool:t}}v(splitToolName,"splitToolName"),_(splitToolName,"splitToolName");const $=_((t,s,n={})=>({...n.callId?{callId:n.callId}:{},name:t,...splitToolName(t,n.server),arguments:s,...n.output!==void 0?{output:n.output}:{},...n.error?{error:n.error}:{}}),"toolCall");function M(t,s,n){if(!t)return;if(t.omitted==="ai"){n.push(`The ${s==="request"?"prompt":"answer"} was not kept \u2014 an AI provider\u2019s bodies are kept only when asked for: Settings \u203A Capture \u203A AI calls, for the calls made after.`);return}if(t.omitted||t.text===void 0)return;const l=parseJsonPrefix(t.text);if(l)return(l.cut||t.truncated)&&n.push(`The ${s} was kept to its first ${F(t.kept)} of ${F(t.size)} \u2014 read as far as it goes; what follows is not shown (the ${s==="request"?"end of the conversation":"rest of the answer"}, marked ${CUT_MARK}).`),l.value}v(M,"E"),_(M,"readBody");function J(t){if(t.data===void 0||t.data==="[DONE]")return;const s=parseJsonPrefix(t.data);return s&&b(s.value)?{v:s.value,cut:s.cut}:void 0}v(J,"M"),_(J,"eventJson");function I(t){if(typeof t=="string")return{text:t,attachments:[]};const s=[],n=[];for(const l of k(t)){if(typeof l=="string"){s.push(l);continue}const a=c(l),r=e(a.type)??"",o=e(a.text)??e(a.refusal);o!==void 0?s.push(o):/image/.test(r)?n.push(e(a.detail)?`image (${e(a.detail)})`:"image"):/file|document/.test(r)?n.push(`file ${e(a.filename)??e(c(a.source).media_type)??e(a.file_id)??""}`.trim()):/audio/.test(r)?n.push("audio"):r&&n.push(r)}return{text:s.join(`
|
|
4
4
|
|
|
5
5
|
`),attachments:n}}v(I,"I"),_(I,"contentOf");const N=_(t=>typeof t=="string"?t:Array.isArray(t)&&I(t).text||A(t),"outputOf");function C(t,s){const n=[];for(const[a,r]of s){let o=t;for(const u of a.split("."))o=c(o)[u];if(o==null)continue;const i=typeof o=="string"?o:typeof o=="number"||typeof o=="boolean"?String(o):b(o)&&e(o.name)?`${e(o.type)??"tool"} ${e(o.name)}`:b(o)&&e(o.type)?e(o.type):JSON.stringify(o);n.push({name:r,value:i})}const l=c(t.metadata);for(const[a,r]of Object.entries(l))n.push({name:`metadata.${a}`,value:typeof r=="string"?r:JSON.stringify(r)});return n}v(C,"O"),_(C,"settingsOf");function O(t,s,n,l){const a=s?t.byCallId.get(s):void 0;if(a){a.output=n,l&&(a.error=l);return}t.call.turns.push({kind:"tool",...$("(an earlier call)","",{callId:s,output:n,error:l})})}v(O,"T"),_(O,"addOutput");function j(t,s){const n={kind:"tool",...s};t.call.turns.push(n),s.callId&&t.byCallId.set(s.callId,n)}v(j,"S"),_(j,"addCall");const ne=[["reasoning.effort","reasoning effort"],["reasoning.summary","reasoning summary"],["max_output_tokens","max output tokens"],["temperature","temperature"],["top_p","top_p"],["tool_choice","tool choice"],["parallel_tool_calls","parallel tool calls"],["text.verbosity","verbosity"],["truncation","truncation"],["previous_response_id","continues response"],["store","store"],["service_tier","service tier"],["stream","stream"],["prompt_cache_key","prompt cache key"],["user","user"],["safety_identifier","safety identifier"]],W=_(t=>A(Object.fromEntries(Object.entries(t).filter(([s])=>s!=="type"&&s!=="id"&&s!=="status"))),"builtInCall");function Z(t,s){const n=e(s.type)??(s.role?"message":"");if(n==="message"){const l=e(s.role)??"user",{text:a,attachments:r}=I(s.content);l==="system"?t.call.system.push({source:"system message",text:a}):t.call.turns.push({kind:"message",role:l,text:a,...r.length?{attachments:r}:{}})}else if(n==="function_call"||n==="custom_tool_call")j(t,$(e(s.name)??"?",e(s.arguments)??A(s.input),{callId:e(s.call_id)}));else if(n==="function_call_output"||n==="custom_tool_call_output"||n==="computer_call_output"||n==="local_shell_call_output")O(t,e(s.call_id),N(s.output));else if(n==="mcp_call")j(t,$(e(s.name)??"?",e(s.arguments)??"",{callId:e(s.id),server:e(s.server_label),...s.output!==void 0&&s.output!==null?{output:N(s.output)}:{},error:e(s.error)}));else if(n==="mcp_list_tools"){const l=k(s.tools).map(a=>e(c(a).name)).filter(Boolean);j(t,$("list_tools","",{server:e(s.server_label),output:l.join(", ")}))}else if(n==="reasoning"){const l=k(s.summary).map(a=>e(c(a).text)).filter(Boolean).join(`
|
|
6
6
|
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
`)),a.length&&(n.reasoning=a.join(`
|
|
12
12
|
|
|
13
|
-
`))}v(E,"
|
|
13
|
+
`))}v(E,"G"),_(E,"responsesOutput");function H(t,s,n){let l,a=0;const r=new Map,o=new Set,i=new Map,u=new Map,m=new Map;for(const f of s){const g=J(f);if(!g)continue;g.cut&&a++;const p=g.v,y=e(p.type)??f.event,w=h(p.output_index)??0;if(y==="response.completed"||y==="response.incomplete"||y==="response.failed"){if(!g.cut&&b(p.response))l=p.response;else if(b(p.response)){const x=p.response;e(x.status)&&(t.call.answer.status=e(x.status))}}else if(y==="response.created"||y==="response.in_progress"){const x=c(p.response);e(x.model)&&(t.call.model??=e(x.model)),e(x.id)&&(t.call.responseId??=e(x.id))}else y==="response.output_item.added"||y==="response.output_item.done"?b(p.item)&&(!o.has(w)||!g.cut)&&(r.set(w,{...r.get(w)??{},...p.item}),y.endsWith(".done")&&!g.cut&&o.add(w)):y==="response.output_text.delta"||y==="response.refusal.delta"?i.set(w,(i.get(w)??"")+(e(p.delta)??"")):y==="response.output_text.done"&&!g.cut&&e(p.text)!==void 0?i.set(w,e(p.text)):y==="response.function_call_arguments.delta"||y==="response.custom_tool_call_input.delta"||y==="response.mcp_call_arguments.delta"?u.set(w,(u.get(w)??"")+(e(p.delta)??"")):(y==="response.function_call_arguments.done"||y==="response.mcp_call_arguments.done")&&!g.cut&&e(p.arguments)!==void 0?u.set(w,e(p.arguments)):y==="response.reasoning_summary_text.delta"?m.set(w,(m.get(w)??"")+(e(p.delta)??"")):(y==="error"||y==="response.error")&&(t.call.answer.error=e(p.message)??e(c(p.error).message)??"the stream reported an error")}if(l){q(t,l);return}const d=[...r.entries()].sort(([f],[g])=>f-g).map(([f,g])=>{if(o.has(f))return g;const p=e(g.type);return p==="message"&&i.has(f)?{...g,content:[{type:"output_text",text:i.get(f)}]}:(p==="function_call"||p==="mcp_call")&&u.has(f)?{...g,arguments:u.get(f)}:p==="custom_tool_call"&&u.has(f)?{...g,input:u.get(f)}:p==="reasoning"&&m.has(f)?{...g,summary:[{type:"summary_text",text:m.get(f)}]}:g});for(const[f,g]of i)r.has(f)||d.push({type:"message",content:[{type:"output_text",text:g}]});E(t,d),t.call.answer.status||(t.call.answer.status=d.length?"completed":"unknown"),a&&n.push(`${a} of the stream\u2019s events were kept to their first 4 KB, so the answer was rebuilt from its pieces${t.call.usage?"":" \u2014 its token counts came in the last event, which was cut"}.`)}v(H,"Z"),_(H,"responsesStream");function R(t,s,n,l){const a=t.call;e(s.model)&&(a.model=e(s.model)),e(s.instructions)&&a.system.push({source:"instructions",text:e(s.instructions)});const r=s.input;if(typeof r=="string")a.turns.push({kind:"message",role:"user",text:r});else for(const i of k(r))b(i)&&Z(t,i);a.tools=D(s),a.settings=C(s,ne);const o=c(c(s.text).format);e(o.type)&&o.type!=="text"&&(a.answer.format={type:e(o.type),...e(o.name)?{name:e(o.name)}:{},...o.schema!==void 0?{schema:o.schema}:{},...typeof o.strict=="boolean"?{strict:o.strict}:{}}),T(t,n,l,i=>q(t,i),i=>H(t,i,l))}v(R,"D"),_(R,"responsesCall");const re=[["reasoning_effort","reasoning effort"],["max_completion_tokens","max completion tokens"],["max_tokens","max tokens"],["temperature","temperature"],["top_p","top_p"],["tool_choice","tool choice"],["parallel_tool_calls","parallel tool calls"],["n","n"],["seed","seed"],["stop","stop"],["presence_penalty","presence penalty"],["frequency_penalty","frequency penalty"],["verbosity","verbosity"],["store","store"],["service_tier","service tier"],["stream","stream"],["user","user"]];function K(t){const s=k(t.tool_calls).map(c).map(l=>{const a=c(l.function);return $(e(a.name)??e(c(l.custom).name)??"?",e(a.arguments)??e(c(l.custom).input)??"",{callId:e(l.id)})}),n=c(t.function_call);return e(n.name)&&s.push($(e(n.name),e(n.arguments)??"",{})),s}v(K,"L"),_(K,"chatCalls");function z(t,s){const n=t.call.answer;e(s.model)&&(t.call.model??=e(s.model)),e(s.id)&&(t.call.responseId??=e(s.id));const l=c(k(s.choices)[0]),a=c(l.message),r=I(a.content).text;r&&(n.text=r),e(a.refusal)&&(n.refusal=e(a.refusal));const o=e(a.reasoning_content)??e(a.reasoning);o&&(n.reasoning=o),n.toolCalls.push(...K(a)),e(l.finish_reason)&&(n.finish=e(l.finish_reason)),n.status=n.finish?"completed":n.status??"unknown";const i=c(s.error);e(i.message)&&(n.error=e(i.message));const u=c(s.usage);Object.keys(u).length&&(t.call.usage={...h(u.prompt_tokens)!==void 0?{input:h(u.prompt_tokens)}:{},...h(c(u.prompt_tokens_details).cached_tokens)!==void 0?{cached:h(c(u.prompt_tokens_details).cached_tokens)}:{},...h(c(u.prompt_tokens_details).cache_write_tokens)?{written:h(c(u.prompt_tokens_details).cache_write_tokens)}:{},...h(u.completion_tokens)!==void 0?{output:h(u.completion_tokens)}:{},...h(c(u.completion_tokens_details).reasoning_tokens)!==void 0?{reasoning:h(c(u.completion_tokens_details).reasoning_tokens)}:{},...h(u.total_tokens)!==void 0?{total:h(u.total_tokens)}:{}})}v(z,"P"),_(z,"chatAnswer");function G(t,s,n){let l="",a="",r="",o,i,u,m,d=0;const f=new Map;for(const p of s){const y=J(p);if(!y)continue;y.cut&&d++,u??=e(y.v.model),m??=e(y.v.id),b(y.v.usage)&&(i=y.v.usage),b(y.v.error)&&(t.call.answer.error=e(y.v.error.message)??"the stream reported an error");const w=c(k(y.v.choices)[0]),x=c(w.delta);l+=e(x.content)??"",a+=e(x.reasoning_content)??e(x.reasoning)??"",r+=e(x.refusal)??"";for(const S of k(x.tool_calls).map(c)){const P=h(S.index)??0,B=f.get(P)??{name:"",args:""},U=c(S.function);e(S.id)&&(B.id=e(S.id)),B.name+=e(U.name)??"",B.args+=e(U.arguments)??"",f.set(P,B)}e(w.finish_reason)&&(o=e(w.finish_reason))}const g={content:l,...a?{reasoning_content:a}:{},...r?{refusal:r}:{},tool_calls:[...f.entries()].sort(([p],[y])=>p-y).map(([,p])=>({id:p.id,function:{name:p.name,arguments:p.args}}))};z(t,{...u?{model:u}:{},...m?{id:m}:{},choices:[{message:g,...o?{finish_reason:o}:{}}],...i?{usage:i}:{}}),d&&n.push(`${d} of the stream\u2019s chunks were kept to their first 4 KB \u2014 the answer was joined from what was kept of them.`)}v(G,"V"),_(G,"chatStream");function Q(t,s,n,l){const a=t.call;e(s.model)&&(a.model=e(s.model));for(const o of k(s.messages).map(c)){const i=e(o.role)??"user",{text:u,attachments:m}=I(o.content);if(i==="system")a.system.push({source:"system message",text:u});else if(i==="tool")O(t,e(o.tool_call_id),u);else if(i==="function")O(t,void 0,u);else{(u||m.length||i!=="assistant")&&a.turns.push({kind:"message",role:i,text:u,...m.length?{attachments:m}:{}});for(const d of K(o))j(t,d)}}a.tools=[...k(s.tools).map(c),...k(s.functions).map(o=>({type:"function",function:o}))].map(o=>{const i=c(o.function),u=e(o.type)??"function",m=e(i.name)??e(c(o.custom).name)??u;return{name:m,...splitToolName(m),type:u,...e(i.description)??e(c(o.custom).description)?{description:e(i.description)??e(c(o.custom).description)}:{},...i.parameters!==void 0?{parameters:i.parameters}:{},...typeof i.strict=="boolean"?{strict:i.strict}:{},called:0}}),a.settings=C(s,re);const r=c(s.response_format);if(e(r.type)&&r.type!=="text"){const o=c(r.json_schema);a.answer.format={type:e(r.type),...e(o.name)?{name:e(o.name)}:{},...o.schema!==void 0?{schema:o.schema}:{},...typeof o.strict=="boolean"?{strict:o.strict}:{}}}T(t,n,l,o=>z(t,o),o=>G(t,o,l))}v(Q,"X"),_(Q,"chatCall");const ae=[["max_tokens","max tokens"],["thinking.budget_tokens","thinking budget"],["temperature","temperature"],["top_p","top_p"],["top_k","top_k"],["tool_choice","tool choice"],["stop_sequences","stop sequences"],["stream","stream"],["metadata.user_id","user"]];function V(t,s,n){if(typeof n=="string"){t.call.turns.push({kind:"message",role:s,text:n});return}const l=[],a=[],r=_(()=>{(l.length||a.length)&&t.call.turns.push({kind:"message",role:s,text:l.join(`
|
|
14
14
|
|
|
15
|
-
`),...a.length?{attachments:[...a]}:{}}),l.length=0,a.length=0},"flush");for(const o of k(n).map(c)){const i=e(o.type)??"";i==="text"?l.push(e(o.text)??""):i==="tool_use"||i==="server_tool_use"||i==="mcp_tool_use"?(r(),j(t,$(e(o.name)??"?",A(o.input),{callId:e(o.id),server:e(o.server_name)}))):i==="tool_result"||i==="mcp_tool_result"||/_tool_result$/.test(i)?(r(),O(t,e(o.tool_use_id),N(o.content),o.is_error===!0?"the tool reported an error":void 0)):i==="thinking"||i==="redacted_thinking"?(r(),t.call.turns.push({kind:"reasoning",...e(o.thinking)?{text:e(o.thinking)}:{}})):a.push(i==="image"?"image":i==="document"?`document ${e(o.title)??""}`.trim():i)}r()}v(V,"ee"),_(V,"anthropicBlocks");function
|
|
15
|
+
`),...a.length?{attachments:[...a]}:{}}),l.length=0,a.length=0},"flush");for(const o of k(n).map(c)){const i=e(o.type)??"";i==="text"?l.push(e(o.text)??""):i==="tool_use"||i==="server_tool_use"||i==="mcp_tool_use"?(r(),j(t,$(e(o.name)??"?",A(o.input),{callId:e(o.id),server:e(o.server_name)}))):i==="tool_result"||i==="mcp_tool_result"||/_tool_result$/.test(i)?(r(),O(t,e(o.tool_use_id),N(o.content),o.is_error===!0?"the tool reported an error":void 0)):i==="thinking"||i==="redacted_thinking"?(r(),t.call.turns.push({kind:"reasoning",...e(o.thinking)?{text:e(o.thinking)}:{}})):a.push(i==="image"?"image":i==="document"?`document ${e(o.title)??""}`.trim():i)}r()}v(V,"ee"),_(V,"anthropicBlocks");function L(t,s){const n=t.call.answer;e(s.model)&&(t.call.model??=e(s.model)),e(s.id)&&(t.call.responseId??=e(s.id));const l=[],a=[];for(const i of k(s.content).map(c)){const u=e(i.type);u==="text"?l.push(e(i.text)??""):u==="tool_use"||u==="server_tool_use"||u==="mcp_tool_use"?n.toolCalls.push($(e(i.name)??"?",A(i.input),{callId:e(i.id),server:e(i.server_name)})):u==="thinking"&&a.push(e(i.thinking)??"")}l.length&&(n.text=l.join(`
|
|
16
16
|
|
|
17
17
|
`)),a.length&&(n.reasoning=a.join(`
|
|
18
18
|
|
|
19
|
-
`)),e(s.stop_reason)&&(n.finish=e(s.stop_reason)),n.status=s.type==="error"?"failed":n.finish?"completed":n.status??"unknown";const r=c(s.error);e(r.message)&&(n.error=e(r.message));const o=c(s.usage);if(Object.keys(o).length){const i=h(o.input_tokens),u=h(o.cache_read_input_tokens),m=h(o.output_tokens);t.call.usage={...i!==void 0?{input:i+(u??0)+(h(o.cache_creation_input_tokens)??0)}:{},...u!==void 0?{cached:u}:{},...h(o.cache_creation_input_tokens)?{written:h(o.cache_creation_input_tokens)}:{},...m!==void 0?{output:m}:{}}}}v(
|
|
19
|
+
`)),e(s.stop_reason)&&(n.finish=e(s.stop_reason)),n.status=s.type==="error"?"failed":n.finish?"completed":n.status??"unknown";const r=c(s.error);e(r.message)&&(n.error=e(r.message));const o=c(s.usage);if(Object.keys(o).length){const i=h(o.input_tokens),u=h(o.cache_read_input_tokens),m=h(o.output_tokens);t.call.usage={...i!==void 0?{input:i+(u??0)+(h(o.cache_creation_input_tokens)??0)}:{},...u!==void 0?{cached:u}:{},...h(o.cache_creation_input_tokens)?{written:h(o.cache_creation_input_tokens)}:{},...m!==void 0?{output:m}:{}}}}v(L,"U"),_(L,"anthropicAnswer");function X(t,s,n){let l={};const a=new Map,r=new Map;let o={},i=0;for(const u of s){const m=J(u);if(!m)continue;m.cut&&i++;const d=m.v,f=e(d.type)??u.event,g=h(d.index)??0;if(f==="message_start")l=c(d.message),o={...c(l.usage)};else if(f==="content_block_start")a.set(g,{...c(d.content_block)});else if(f==="content_block_delta"){const p=c(d.delta),y=a.get(g)??{};e(p.text)!==void 0&&(y.text=(e(y.text)??"")+e(p.text)),e(p.thinking)!==void 0&&(y.thinking=(e(y.thinking)??"")+e(p.thinking)),e(p.partial_json)!==void 0&&r.set(g,(r.get(g)??"")+e(p.partial_json)),a.set(g,y)}else f==="message_delta"?(l={...l,...c(d.delta)},o={...o,...c(d.usage)}):f==="error"&&(t.call.answer.error=e(c(d.error).message)??"the stream reported an error")}for(const[u,m]of r){const d=a.get(u);d&&(d.input=parseJsonPrefix(m)?.value??m)}L(t,{...l,content:[...a.entries()].sort(([u],[m])=>u-m).map(([,u])=>u),usage:o}),i&&n.push(`${i} of the stream\u2019s events were kept to their first 4 KB \u2014 the answer was joined from what was kept of them.`)}v(X,"te"),_(X,"anthropicStream");function Y(t,s,n,l){const a=t.call;e(s.model)&&(a.model=e(s.model));const r=s.system;if(typeof r=="string"&&r)a.system.push({source:"system",text:r});else for(const o of k(r).map(c))e(o.text)&&a.system.push({source:"system",text:e(o.text)});for(const o of k(s.messages).map(c))V(t,e(o.role)??"user",o.content);a.tools=[...k(s.tools).map(c).map(o=>{const i=e(o.name)??e(o.type)??"tool";return{name:i,...splitToolName(i),type:e(o.type)??"custom",...e(o.description)?{description:e(o.description)}:{},...o.input_schema!==void 0?{parameters:o.input_schema}:{},called:0}}),...k(s.mcp_servers).map(c).map(o=>({name:e(o.name)??"mcp",server:e(o.name)??"mcp",tool:"every tool",type:"mcp",...e(o.url)?{description:e(o.url)}:{},called:0}))],a.settings=C(s,ae),T(t,n,l,o=>L(t,o),o=>X(t,o,l))}v(Y,"ne"),_(Y,"anthropicCall");function ee(t,s,n,l){const a=t.call;e(s.model)&&(a.model=e(s.model));const r=s.input,o=typeof r=="string"?[r]:k(r),i=o.slice(0,200).map(p=>typeof p=="string"?p:typeof p=="number"?`token ${p}`:Array.isArray(p)?`${p.length} tokens`:A(p)),u=o.length>0&&o.every(p=>typeof p=="number");a.embedding={inputs:u?[`${o.length} tokens`]:i,count:u?1:o.length,...h(s.dimensions)!==void 0?{dimensions:h(s.dimensions)}:{}},a.settings=C(s,[["dimensions","dimensions"],["encoding_format","encoding"],["user","user"]]);const m=c(M(n.response.body,"answer",[])),d=k(m.data);if(d.length){a.embedding.vectors=d.length;const p=c(d[0]).embedding;Array.isArray(p)&&a.embedding.dimensions===void 0&&(a.embedding.dimensions=p.length)}const f=c(m.usage);h(f.prompt_tokens)!==void 0&&(a.usage={input:h(f.prompt_tokens),...h(f.total_tokens)!==void 0?{total:h(f.total_tokens)}:{}}),a.answer.status=n.status!==void 0&&n.status<400?"completed":"failed";const g=c(m.error);e(g.message)&&(a.answer.error=e(g.message))}v(ee,"se"),_(ee,"embeddingsCall");function T(t,s,n,l,a){const r=s.response.stream;if(r){if(r.events.length&&r.events.every(i=>i.data===void 0)){n.push("The answer streamed, and only each event\u2019s name, time and size were kept \u2014 an AI provider\u2019s bodies are kept only when asked for: Settings \u203A Capture \u203A AI calls.");return}a(r.events),r.cut&&n.push(`The stream was cut after ${r.events.length.toLocaleString("en-US")} of its ${r.total.toLocaleString("en-US")} events \u2014 what came after is not shown.`);return}const o=M(s.response.body,"answer",n);b(o)?l(o):s.error&&(t.call.answer.error=s.error),t.call.answer.status||(t.call.answer.status=s.error||(s.status??0)>=400?"failed":"unknown")}v(T,"N"),_(T,"answerOf");function te(t){return t.api==="embeddings"?"embedding":t.answer.format&&/json/.test(t.answer.format.type)?"decision":t.tools.length||t.answer.toolCalls.length||t.turns.some(s=>s.kind==="tool")?"tools":t.turns.filter(s=>s.kind==="message"&&(s.role==="user"||s.role==="assistant")).length>1?"chat":"prompt"}v(te,"oe"),_(te,"shapeOf");export function aiCallOf(t){if(!t.ai)return;const s=aiApiOf(t.path);if(!s)return;const n=[],l={call:{provider:t.ai.provider,api:s,shape:"prompt",settings:[],system:[],turns:[],tools:[],answer:{toolCalls:[]},gaps:n},byCallId:new Map},a=c(M(t.request.body,"request",n));s==="responses"?R(l,a,t,n):s==="chat"?Q(l,a,t,n):s==="messages"?Y(l,a,t,n):ee(l,a,t,n);const r=l.call;if(r.answer.text!==void 0&&(r.answer.format?/json/.test(r.answer.format.type):/^\s*[{[]/.test(r.answer.text))){const i=parseJsonPrefix(r.answer.text);i&&(b(i.value)||Array.isArray(i.value))&&(r.answer.json=i.value)}!r.answer.finish&&r.answer.toolCalls.length&&(r.answer.finish="tool calls");const o=new Map;for(const i of r.turns)i.kind==="tool"&&o.set(i.name,(o.get(i.name)??0)+1);for(const i of r.answer.toolCalls)o.set(i.name,(o.get(i.name)??0)+1);for(const i of r.tools)i.called=o.get(i.name)??0;r.shape=te(r);for(const i of r.system)i.text.endsWith(CUT_MARK)&&(i.cut=!0);return r}v(aiCallOf,"aiCallOf"),_(aiCallOf,"aiCallOf");export const SHAPE_LABEL={prompt:"Single prompt",chat:"Conversation",tools:"Tool calling",decision:"Structured decision",embedding:"Embedding"};export function prettyJson(t){const s=t.trim()?parseJsonPrefix(t):void 0;return s&&(b(s.value)||Array.isArray(s.value))?{value:s.value,text:t}:{text:t}}v(prettyJson,"prettyJson"),_(prettyJson,"prettyJson");
|
package/lib/dashboard.d.ts
CHANGED
|
@@ -3702,3 +3702,87 @@ export interface DashVersions {
|
|
|
3702
3702
|
};
|
|
3703
3703
|
processes: DashRunningVersion[];
|
|
3704
3704
|
}
|
|
3705
|
+
/** Where a setting's value comes from: its default, this machine, this repository's `lensmcp.json`, or the environment. */
|
|
3706
|
+
export type DashSettingSource = 'default' | 'machine' | 'repository' | 'env';
|
|
3707
|
+
/** When a change reaches what reads it: at once, when a service starts again, when the lens starts again, when the gateway starts again. */
|
|
3708
|
+
export type DashSettingApplies = 'now' | 'service' | 'lens' | 'gateway';
|
|
3709
|
+
/** One row of a Settings page: a card's switch (`switch`) or a variable kept as a setting (`variable`). */
|
|
3710
|
+
export interface DashSettingRow {
|
|
3711
|
+
/** A switch's key (`sqlValues`) or a variable's name (`LENSMCP_TYPECHECK`): what `POST /api/settings` takes. */
|
|
3712
|
+
key: string;
|
|
3713
|
+
kind: 'switch' | 'variable';
|
|
3714
|
+
title: string;
|
|
3715
|
+
/** One or two sentences: what it does, and what the other value does. */
|
|
3716
|
+
desc: string;
|
|
3717
|
+
value: string | number;
|
|
3718
|
+
default: string | number;
|
|
3719
|
+
/** The values it takes, each with its word. `on`/`off` alone: the screen draws a switch. */
|
|
3720
|
+
options?: Array<{
|
|
3721
|
+
value: string | number;
|
|
3722
|
+
label: string;
|
|
3723
|
+
}>;
|
|
3724
|
+
/** A number: the unit it is edited in, what one of that unit is in the stored value, its bounds, and what 0 means. */
|
|
3725
|
+
number?: {
|
|
3726
|
+
unit: string;
|
|
3727
|
+
scale?: number;
|
|
3728
|
+
min?: number;
|
|
3729
|
+
max?: number;
|
|
3730
|
+
zero?: string;
|
|
3731
|
+
};
|
|
3732
|
+
/** `usd`: dollars a day, the usual amounts with a click or any amount typed. */
|
|
3733
|
+
unit?: 'usd';
|
|
3734
|
+
kept: 'repository' | 'machine';
|
|
3735
|
+
source: DashSettingSource;
|
|
3736
|
+
/** The variable that sets it in a process's environment. Set there, it wins and the row is locked. */
|
|
3737
|
+
env?: string;
|
|
3738
|
+
/** Where the environment's value comes from when it is set: `shell`, or the dotenv file that declares it. */
|
|
3739
|
+
envFrom?: string;
|
|
3740
|
+
applies: DashSettingApplies;
|
|
3741
|
+
/** Turning it up spends from the person's API keys. */
|
|
3742
|
+
costs?: boolean;
|
|
3743
|
+
/** Its feature is off: the value reads off until the feature is on again. */
|
|
3744
|
+
featureOff?: {
|
|
3745
|
+
id: string;
|
|
3746
|
+
title: string;
|
|
3747
|
+
};
|
|
3748
|
+
/** Today's spend, for a daily allowance. */
|
|
3749
|
+
spentToday?: number;
|
|
3750
|
+
}
|
|
3751
|
+
export interface DashSettingSection {
|
|
3752
|
+
title: string;
|
|
3753
|
+
desc?: string;
|
|
3754
|
+
rows: DashSettingRow[];
|
|
3755
|
+
}
|
|
3756
|
+
/** A documented variable on «All variables»: its value in the lens's environment and where that comes from. */
|
|
3757
|
+
export interface DashSettingVariable {
|
|
3758
|
+
name: string;
|
|
3759
|
+
/** The section of the variables reference it is in (`Pod lifecycle`, `Event history`…). */
|
|
3760
|
+
group: string;
|
|
3761
|
+
default: string;
|
|
3762
|
+
desc: string;
|
|
3763
|
+
value?: string;
|
|
3764
|
+
source: DashSettingSource | 'unset';
|
|
3765
|
+
envFrom?: string;
|
|
3766
|
+
/** It is a setting too: the page that edits it. */
|
|
3767
|
+
page?: string;
|
|
3768
|
+
}
|
|
3769
|
+
export interface DashSettings {
|
|
3770
|
+
workspace: string;
|
|
3771
|
+
at: number;
|
|
3772
|
+
/** Each page's sections, by page id (`capture`, `typecheck`…). Pages drawn by the screen alone are absent. */
|
|
3773
|
+
pages: Record<string, DashSettingSection[]>;
|
|
3774
|
+
variables: DashSettingVariable[];
|
|
3775
|
+
files: {
|
|
3776
|
+
repository: string;
|
|
3777
|
+
repositoryExists: boolean;
|
|
3778
|
+
machine: string;
|
|
3779
|
+
};
|
|
3780
|
+
/** Machine switches are kept in the workspace history: false when there is none, and those rows cannot change. */
|
|
3781
|
+
kept: boolean;
|
|
3782
|
+
}
|
|
3783
|
+
/** What `POST /api/settings` answers: the row as it is now, and the value it had — what Undo sends back. */
|
|
3784
|
+
export interface DashSettingSaved {
|
|
3785
|
+
row: DashSettingRow;
|
|
3786
|
+
/** The value before; null: it was not set (the default, or the environment's). */
|
|
3787
|
+
previous: string | number | null;
|
|
3788
|
+
}
|
package/lib/team.d.ts
CHANGED
|
@@ -98,6 +98,55 @@ export interface DashTeamTask {
|
|
|
98
98
|
wrapUp?: DashTeamWrapUp;
|
|
99
99
|
/** A task moved to its goal's next list: the item it became (cancelled, never counted against the plan). */
|
|
100
100
|
movedToNext?: string;
|
|
101
|
+
/** A goal's own capacity, the person's (issues/closed/foodguard-179): its numbers over the repository's flow.json `goal.capacity`. */
|
|
102
|
+
capacity?: Record<string, number>;
|
|
103
|
+
/** A goal's launches refused for want of a slot, in line for the next one that frees (foodguard-179 GC-D4). */
|
|
104
|
+
waits?: DashTeamGoalWait[];
|
|
105
|
+
}
|
|
106
|
+
/** A launch in line for a slot (issues/closed/foodguard-179 GC-D4). */
|
|
107
|
+
export interface DashTeamGoalWait {
|
|
108
|
+
role: string;
|
|
109
|
+
taskId?: string;
|
|
110
|
+
/** Its place in line: when it began to wait. */
|
|
111
|
+
since: number;
|
|
112
|
+
/** The manager that asked. */
|
|
113
|
+
by: string;
|
|
114
|
+
/** A free slot held for it: its manager told at `at`, no other goal takes it until `until`. */
|
|
115
|
+
offered?: {
|
|
116
|
+
at: number;
|
|
117
|
+
until: number;
|
|
118
|
+
};
|
|
119
|
+
/** The agent another goal borrowed past its capacity that gives its slot back for it. */
|
|
120
|
+
freeing?: string;
|
|
121
|
+
}
|
|
122
|
+
/** One of a goal's capacity numbers and what it uses of it — `used` past `max`: borrowed (foodguard-179). */
|
|
123
|
+
export interface DashTeamCapacityUse {
|
|
124
|
+
/** A role's id, a kind of role (`kind`: writers, checkers) or `research` — its claimed research tasks. */
|
|
125
|
+
key: string;
|
|
126
|
+
kind?: boolean;
|
|
127
|
+
max: number;
|
|
128
|
+
used: number;
|
|
129
|
+
/** flow.json's (`team`), the person's for this goal, or its manager's lower one. */
|
|
130
|
+
from: 'team' | 'person' | 'manager';
|
|
131
|
+
}
|
|
132
|
+
/** The running goals (`GET /api/team/board` `goals`, issues/closed/foodguard-179). */
|
|
133
|
+
export interface DashTeamGoals {
|
|
134
|
+
/** flow.json `goals.running`: the most goals that run at once. */
|
|
135
|
+
max: number;
|
|
136
|
+
running: Array<{
|
|
137
|
+
id: string;
|
|
138
|
+
title: string;
|
|
139
|
+
capacity: DashTeamCapacityUse[];
|
|
140
|
+
waits?: DashTeamGoalWait[];
|
|
141
|
+
}>;
|
|
142
|
+
/** Open goals no goal is above, first to start first — while the running goals fill `max`. */
|
|
143
|
+
next?: string[];
|
|
144
|
+
/** The kinds the running goals' capacities add up past the team's caps: a goal may wait for its own. */
|
|
145
|
+
over?: Array<{
|
|
146
|
+
kind: 'writers' | 'checkers';
|
|
147
|
+
guaranteed: number;
|
|
148
|
+
cap: number;
|
|
149
|
+
}>;
|
|
101
150
|
}
|
|
102
151
|
/** A goal's plan as it stands (planning/team/16 GS-D1). */
|
|
103
152
|
export interface DashTeamGoalPlan {
|
|
@@ -138,6 +187,8 @@ export interface DashTeamGoalRole {
|
|
|
138
187
|
effort?: string;
|
|
139
188
|
client?: 'codex' | 'claude';
|
|
140
189
|
reviews?: string[];
|
|
190
|
+
/** The most agents of the role the goal runs — its manager's word, never above the goal's capacity. */
|
|
191
|
+
max?: number;
|
|
141
192
|
}
|
|
142
193
|
/** One claim's work, from its holder's hooks: the files edited, commits, the checks and the whole suites run, workspace actions. */
|
|
143
194
|
export interface DashTeamTaskWork {
|
|
@@ -305,6 +356,8 @@ export interface DashTeamBoard {
|
|
|
305
356
|
roles: DashTeamRole[];
|
|
306
357
|
/** What the board's tasks raise about the agents that hold or held them. */
|
|
307
358
|
flags?: DashTeamFlag[];
|
|
359
|
+
/** The running goals, each one's capacity and waits, and the goals next to start (issues/closed/foodguard-179). */
|
|
360
|
+
goals?: DashTeamGoals;
|
|
308
361
|
/** More sessions or tasks than the board carries. */
|
|
309
362
|
truncated: boolean;
|
|
310
363
|
/**
|
|
@@ -361,6 +414,8 @@ export interface DashTeamOperate {
|
|
|
361
414
|
/** Cancel it, with why. */
|
|
362
415
|
cancel?: string;
|
|
363
416
|
note?: string;
|
|
417
|
+
/** A goal's capacity, by role, kind or research — null gives a key back to flow.json's (foodguard-179). */
|
|
418
|
+
capacity?: Record<string, number | null>;
|
|
364
419
|
}
|
|
365
420
|
/** `POST /api/team/message` — to one agent, or to everyone (no `to`). */
|
|
366
421
|
export interface DashTeamMessage {
|