@lssm/lib.ai-agent 0.0.0-canary-20251207150805 → 0.0.0-canary-20251207151203
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{agentKey as e}from"../spec/spec.js";import{specToolsToAISDKTools as t}from"../tools/tool-adapter.js";import{createKnowledgeQueryTool as n}from"../tools/knowledge-tool.js";import{injectStaticKnowledge as r}from"../knowledge/injector.js";import{generateSessionId as i}from"../session/store.js";import{trackAgentStep as a}from"../telemetry/adapter.js";import{Experimental_Agent as o,stepCountIs as s}from"ai";import*as c from"zod";const l=c.object({tenantId:c.string().optional(),actorId:c.string().optional(),sessionId:c.string().optional(),metadata:c.record(c.string(),c.unknown()).optional()});var u=class c{version=`agent-v1`;id;spec;tools;inner;config;instructions;constructor(t,n,r){this.config=t,this.spec=t.spec,this.id=e(t.spec.meta),this.tools=r,this.instructions=n,this.inner=new o({model:t.model,instructions:n,tools:r,stopWhen:s(t.spec.maxSteps??10),callOptionsSchema:l,onStepFinish:async e=>{await this.handleStepFinish(e)}})}static async create(i){let a=await r(i.spec.instructions,i.spec.knowledge??[],i.knowledgeRetriever),o=t(i.spec.tools,i.toolHandlers,{agentId:e(i.spec.meta)}),s=i.knowledgeRetriever?n(i.knowledgeRetriever,i.spec.knowledge??[]):null;return new c(i,a,{...o,...s?{query_knowledge:s}:{},...i.additionalTools??{}})}async generate(e){let t=e.options?.sessionId??i();this.config.sessionStore&&(await this.config.sessionStore.get(t)||await this.config.sessionStore.create({sessionId:t,agentId:this.id,tenantId:e.options?.tenantId,actorId:e.options?.actorId,status:`running`,messages:[],steps:[],metadata:e.options?.metadata}));let n=e.systemOverride?`${this.instructions}\n\n${e.systemOverride}\n\n${e.prompt}`:e.prompt,r=await this.inner.generate({prompt:n,abortSignal:e.signal,options:{tenantId:e.options?.tenantId,actorId:e.options?.actorId,sessionId:t,metadata:e.options?.metadata}});return this.config.sessionStore&&await this.config.sessionStore.update(t,{status:`completed`}),{text:r.text,steps:r.steps,toolCalls:r.toolCalls.map(e=>({type:`tool-call`,toolCallId:e.toolCallId,toolName:e.toolName,args:`args`in e?e.args:`input`in e?e.input:void 0})),toolResults:r.toolResults.map(e=>({type:`tool-result`,toolCallId:e.toolCallId,toolName:e.toolName,output:e.output})),finishReason:r.finishReason,usage:r.usage}}async stream(e){let t=e.options?.sessionId??i(),n=e.systemOverride?`${this.instructions}\n\n${e.systemOverride}\n\n${e.prompt}`:e.prompt;return this.inner.stream({prompt:n,abortSignal:e.signal,options:{tenantId:e.options?.tenantId,actorId:e.options?.actorId,sessionId:t,metadata:e.options?.metadata}})}async handleStepFinish(e){let t=e.options?.sessionId;t&&this.config.sessionStore&&await this.config.sessionStore.appendStep(t,e),this.config.telemetryCollector&&await a(this.config.telemetryCollector,this.id,e)}};export{u as ContractSpecAgent};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{agentKey as e,defineAgent as t}from"./spec/spec.js";import{jsonSchemaToZod as n,jsonSchemaToZodSafe as r}from"./schema/json-schema-to-zod.js";import{buildToolHandlers as i,createToolHandler as a,specToolToAISDKTool as o,specToolsToAISDKTools as s}from"./tools/tool-adapter.js";import{createKnowledgeQueryTool as c}from"./tools/knowledge-tool.js";import{createKnowledgeInjector as l,injectStaticKnowledge as u}from"./knowledge/injector.js";import{InMemorySessionStore as d,createInMemorySessionStore as f,generateSessionId as p}from"./session/store.js";import{InMemoryTelemetryCollector as m,createInMemoryTelemetryCollector as h,noopTelemetryCollector as g,trackAgentStep as _}from"./telemetry/adapter.js";import{ContractSpecAgent as v}from"./agent/contract-spec-agent.js";import{AgentFactory as y,createAgentFactory as b}from"./agent/agent-factory.js";import"./agent/index.js";import{AgentRegistry as x,createAgentRegistry as S}from"./spec/registry.js";import{createMcpToolsets as C,mcpServerToTools as w}from"./tools/mcp-client.js";import{agentToMcpServer as T,createAgentMcpServer as E}from"./tools/mcp-server.js";import"./tools/index.js";import{SchemaOutput as D,enumToChoiceOutput as O,jsonSchemaToArrayOutput as k,jsonSchemaToOutput as A,textOutput as j,zodToOutput as M}from"./schema/schema-output.js";import"./schema/index.js";import{ApprovalWorkflow as N,InMemoryApprovalStore as P,createApprovalWorkflow as F}from"./approval/workflow.js";import"./approval/index.js";import{Experimental_Agent as I}from"ai";export{y as AgentFactory,x as AgentRegistry,N as ApprovalWorkflow,v as ContractSpecAgent,P as InMemoryApprovalStore,d as InMemorySessionStore,m as InMemoryTelemetryCollector,D as SchemaOutput,I as ToolLoopAgent,e as agentKey,T as agentToMcpServer,i as buildToolHandlers,b as createAgentFactory,E as createAgentMcpServer,S as createAgentRegistry,F as createApprovalWorkflow,f as createInMemorySessionStore,h as createInMemoryTelemetryCollector,l as createKnowledgeInjector,c as createKnowledgeQueryTool,C as createMcpToolsets,a as createToolHandler,t as defineAgent,O as enumToChoiceOutput,p as generateSessionId,u as injectStaticKnowledge,k as jsonSchemaToArrayOutput,A as jsonSchemaToOutput,n as jsonSchemaToZod,r as jsonSchemaToZodSafe,w as mcpServerToTools,g as noopTelemetryCollector,o as specToolToAISDKTool,s as specToolsToAISDKTools,j as textOutput,_ as trackAgentStep,M as zodToOutput};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{tool as e}from"ai";import
|
|
1
|
+
import{tool as e}from"ai";import*as t from"zod";function n(n,r){let i=r.filter(e=>!e.required).map(e=>e.key).filter(e=>n.supportsSpace(e));return i.length===0?null:e({description:`Query knowledge bases for relevant information. Use this tool when you need to look up specific information that may not be in your context.
|
|
2
2
|
|
|
3
3
|
Available knowledge spaces:
|
|
4
4
|
${r.filter(e=>!e.required&&n.supportsSpace(e.key)).map(e=>`- ${e.key}: ${e.instructions??`Knowledge space`}`).join(`
|
package/dist/tools/mcp-server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsonSchemaToZodSafe as e}from"../schema/json-schema-to-zod.js";import
|
|
1
|
+
import{jsonSchemaToZodSafe as e}from"../schema/json-schema-to-zod.js";import*as t from"zod";import{McpServer as n}from"@modelcontextprotocol/sdk/server/mcp.js";function r(r,i){let a=new n({name:i.meta.name,version:`${i.meta.version}`});a.registerTool(i.meta.name,{description:i.description??`Interact with ${i.meta.name} agent`,inputSchema:t.object({message:t.string().describe(`The message or query to send to the agent`),sessionId:t.string().optional().describe(`Optional session ID to continue a conversation`)})},async e=>{let{message:t,sessionId:n}=e;return{content:[{type:`text`,text:(await r.generate({prompt:t,options:{sessionId:n}})).text}]}});for(let n of i.tools){let o=n.schema?e(n.schema):t.object({});a.registerTool(`${i.meta.name}.${n.name}`,{description:n.description??`Execute ${n.name} tool`,inputSchema:o},async e=>({content:[{type:`text`,text:(await r.generate({prompt:`Execute the ${n.name} tool with the following arguments: ${JSON.stringify(e)}`})).text}]}))}return a}function i(e){return r(e.agent,e.spec)}export{r as agentToMcpServer,i as createAgentMcpServer};
|