@roll-agent/sdk 0.1.4 → 0.1.5
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/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/context.js +0 -1
- package/dist/define-agent.js +0 -1
- package/dist/define-tool.js +0 -1
- package/dist/types/index.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{createServer as e}from"node:http";import{randomUUID as n}from"node:crypto";import{McpServer as t}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as o}from"@modelcontextprotocol/sdk/server/stdio.js";import{StreamableHTTPServerTransport as r}from"@modelcontextprotocol/sdk/server/streamableHttp.js";import"zod";var s={debug:0,info:1,warn:2,error:3};function i(e,n="info"){const t=s[n],o=(n,o)=>{if(s[n]<t)return;const r=(new Date).toISOString(),i=n.toUpperCase().padEnd(5);console.error(`${r} [${i}] [${e}] ${o}`)};return{debug:e=>o("debug",e),info:e=>o("info",e),warn:e=>o("warn",e),error:e=>o("error",e)}}function a(e,n,t){return{llm:{generateText:async e=>{try{const n=c((await t.server.createMessage({messages:[{role:"user",content:{type:"text",text:e}}],maxTokens:1024})).content);if(void 0===n)throw new Error("Sampling response did not include text content");return n}catch(e){throw new Error("LLM sampling unavailable. Ensure roll-core client enables sampling capability.",{cause:e})}}},logger:i(e,n)}}function c(e){if("object"==typeof e&&null!==e&&"type"in e&&"text"===e.type&&"text"in e){const n=e.text;return"string"==typeof n?n:void 0}if(Array.isArray(e))for(const n of e){const e=c(n);if(void 0!==e)return e}}function p(e,n={}){return{...e,listen:async t=>{const o=t?.transport??{type:"stdio"},r=n.logLevel??"info";"http"===o.type?await f(e,r,o.port,o.host,n.onShutdown):await l(e,r,n.onShutdown)}}}function d(e){let n;const t=t=>{n??=e(t).catch(()=>{process.exit(1)})};process.once("SIGTERM",()=>{t("SIGTERM")}),process.once("SIGINT",()=>{t("SIGINT")})}async function l(e,n,r){const s=new t({name:e.name,version:"0.0.1"}),i=a(e.name,n,s);for(const n of e.tools)u(s,n,i);const c=new o;await s.connect(c),i.logger.info("MCP Server running on stdio");d(async e=>{i.logger.info(`${e} received, shutting down...`),r&&await r(),await s.close(),process.exit(0)})}async function f(o,s,c,p,l){const f=i(o.name,s),m=new Map,w=e(async(e,i)=>{if("/mcp"!==new URL(e.url??"/",`http://${e.headers.host??"localhost"}`).pathname)return i.writeHead(404,{"Content-Type":"application/json"}),void i.end(JSON.stringify({error:"Not found"}));const c="string"==typeof e.headers["mcp-session-id"]?e.headers["mcp-session-id"]:void 0;if(c){const n=m.get(c);if(n){try{await n.transport.handleRequest(e,i)}catch(e){f.error(`Error handling request for session ${c}: ${String(e)}`),i.headersSent||(i.writeHead(500,{"Content-Type":"application/json"}),i.end(JSON.stringify({error:"Internal server error"})))}return}return i.writeHead(404,{"Content-Type":"application/json"}),void i.end(JSON.stringify({error:"Session not found"}))}try{const c=new r({sessionIdGenerator:()=>n()}),p=new t({name:o.name,version:"0.0.1"}),d=a(o.name,s,p);for(const e of o.tools)u(p,e,d);c.onclose=()=>{const e=c.sessionId;e&&(m.delete(e),f.info(`Session ${e} closed`))},c.onerror=e=>{f.error(`Transport error (session ${c.sessionId??"unknown"}): ${e.message}`)},await p.connect(c),await c.handleRequest(e,i),c.sessionId&&m.set(c.sessionId,{transport:c,server:p})}catch(e){f.error(`Error creating new session: ${String(e)}`),i.headersSent||(i.writeHead(500,{"Content-Type":"application/json"}),i.end(JSON.stringify({error:"Failed to create session"})))}});w.on("error",e=>{f.error(`HTTP server error: ${e.message}`)});const g=p??"127.0.0.1";w.listen(c,g,()=>{f.info(`MCP Server running on http://${g}:${c}/mcp`)});d(async e=>{f.info(`${e} received, shutting down HTTP server...`),await new Promise(e=>{w.close(()=>e())});const n=[];for(const[,e]of m)n.push(e.server.close());await Promise.all(n),m.clear(),l&&await l(),process.exit(0)})}function u(e,n,t){e.registerTool(n.name,{description:n.description,inputSchema:n.input},async e=>{const o=await n.execute(e,t);return{content:[{type:"text",text:JSON.stringify(o)}]}})}function m(e){return e}export{i as createAgentLogger,p as defineAgent,m as defineTool};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roll-agent/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@types/node": "^22.0.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "rm -rf dist && tsc -p tsconfig.build.json && node ../../scripts/obfuscate.mjs",
|
|
36
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json --emitDeclarationOnly && node ../../scripts/bundle.mjs && node ../../scripts/obfuscate.mjs",
|
|
37
37
|
"typecheck": "tsc --noEmit",
|
|
38
38
|
"test": "node --experimental-strip-types --test \"src/**/*.test.ts\"",
|
|
39
39
|
"clean": "rm -rf dist"
|
package/dist/context.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const r={debug:0,info:1,warn:2,error:3};export function createAgentLogger(e,n="info"){const o=r[n],t=(n,t)=>{if(r[n]<o)return;const a=(new Date).toISOString(),g=n.toUpperCase().padEnd(5);console.error(`${a} [${g}] [${e}] ${t}`)};return{debug:r=>t("debug",r),info:r=>t("info",r),warn:r=>t("warn",r),error:r=>t("error",r)}}
|
package/dist/define-agent.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createServer as e}from"node:http";import{randomUUID as t}from"node:crypto";import{McpServer as n}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as o}from"@modelcontextprotocol/sdk/server/stdio.js";import{StreamableHTTPServerTransport as r}from"@modelcontextprotocol/sdk/server/streamableHttp.js";import{z as s}from"zod";import{createAgentLogger as i}from"./context.js";function a(e,t,n){return{llm:{generateText:async e=>{try{const t=c((await n.server.createMessage({messages:[{role:"user",content:{type:"text",text:e}}],maxTokens:1024})).content);if(void 0===t)throw new Error("Sampling response did not include text content");return t}catch(e){throw new Error("LLM sampling unavailable. Ensure roll-core client enables sampling capability.",{cause:e})}}},logger:i(e,t)}}function c(e){if("object"==typeof e&&null!==e&&"type"in e&&"text"===e.type&&"text"in e){const t=e.text;return"string"==typeof t?t:void 0}if(Array.isArray(e))for(const t of e){const e=c(t);if(void 0!==e)return e}}export function defineAgent(e,t={}){return{...e,listen:async n=>{const o=n?.transport??{type:"stdio"},r=t.logLevel??"info";"http"===o.type?await l(e,r,o.port,o.host,t.onShutdown):await d(e,r,t.onShutdown)}}}function p(e){let t;const n=n=>{t??=e(n).catch(()=>{process.exit(1)})};process.once("SIGTERM",()=>{n("SIGTERM")}),process.once("SIGINT",()=>{n("SIGINT")})}async function d(e,t,r){const s=new n({name:e.name,version:"0.0.1"}),i=a(e.name,t,s);for(const t of e.tools)f(s,t,i);const c=new o;await s.connect(c),i.logger.info("MCP Server running on stdio");p(async e=>{i.logger.info(`${e} received, shutting down...`),r&&await r(),await s.close(),process.exit(0)})}async function l(o,s,c,d,l){const m=i(o.name,s),u=new Map,w=e(async(e,i)=>{if("/mcp"!==new URL(e.url??"/",`http://${e.headers.host??"localhost"}`).pathname)return i.writeHead(404,{"Content-Type":"application/json"}),void i.end(JSON.stringify({error:"Not found"}));const c="string"==typeof e.headers["mcp-session-id"]?e.headers["mcp-session-id"]:void 0;if(c){const t=u.get(c);if(t){try{await t.transport.handleRequest(e,i)}catch(e){m.error(`Error handling request for session ${c}: ${String(e)}`),i.headersSent||(i.writeHead(500,{"Content-Type":"application/json"}),i.end(JSON.stringify({error:"Internal server error"})))}return}return i.writeHead(404,{"Content-Type":"application/json"}),void i.end(JSON.stringify({error:"Session not found"}))}try{const c=new r({sessionIdGenerator:()=>t()}),p=new n({name:o.name,version:"0.0.1"}),d=a(o.name,s,p);for(const e of o.tools)f(p,e,d);c.onclose=()=>{const e=c.sessionId;e&&(u.delete(e),m.info(`Session ${e} closed`))},c.onerror=e=>{m.error(`Transport error (session ${c.sessionId??"unknown"}): ${e.message}`)},await p.connect(c),await c.handleRequest(e,i),c.sessionId&&u.set(c.sessionId,{transport:c,server:p})}catch(e){m.error(`Error creating new session: ${String(e)}`),i.headersSent||(i.writeHead(500,{"Content-Type":"application/json"}),i.end(JSON.stringify({error:"Failed to create session"})))}});w.on("error",e=>{m.error(`HTTP server error: ${e.message}`)});const g=d??"127.0.0.1";w.listen(c,g,()=>{m.info(`MCP Server running on http://${g}:${c}/mcp`)});p(async e=>{m.info(`${e} received, shutting down HTTP server...`),await new Promise(e=>{w.close(()=>e())});const t=[];for(const[,e]of u)t.push(e.server.close());await Promise.all(t),u.clear(),l&&await l(),process.exit(0)})}function f(e,t,n){e.registerTool(t.name,{description:t.description,inputSchema:t.input},async e=>{const o=await t.execute(e,n);return{content:[{type:"text",text:JSON.stringify(o)}]}})}
|
package/dist/define-tool.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function defineTool(e){return e}
|
package/dist/types/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{};
|