@jdr377/mapapp-agent-connector 0.1.0-pre.10 → 0.1.0-pre.12

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,2 +1,2 @@
1
1
  // @bun
2
- import{participantErrorDiagnostic}from"./chunk-z0hbdn1f.js";import"./chunk-btwmey1h.js";import{createReadStream}from"fs";import{Client,InMemoryTransport}from"@modelcontextprotocol/client";class ParticipantInvocationError extends Error{code;constructor(code){super(code);this.code=code}}function readParticipantInvocation(args){const command=args[0];if(command!=="tools"&&command!=="call")return null;const result={command,walletArgs:[]};for(let index=1;index<args.length;index+=2){const key=args[index],value=args[index+1];if(!key||!value||value.startsWith("--"))throw new ParticipantInvocationError("participant_invocation_invalid");if(key==="--tool"){if(result.tool||!/^mapapp_[a-z0-9_]+$/u.test(value))throw new ParticipantInvocationError("participant_invocation_invalid");result.tool=value}else if(key==="--arguments-file"){if(command!=="call"||result.argumentsFile)throw new ParticipantInvocationError("participant_invocation_invalid");result.argumentsFile=value}else result.walletArgs.push(key,value)}if(command==="call"&&!result.tool)throw new ParticipantInvocationError("participant_invocation_invalid");return result}async function readInvocationArguments(filename,maxBytes){if(!filename)return{};const chunks=[];let length=0;try{const input=filename==="-"?process.stdin:createReadStream(filename,{end:maxBytes});for await(const chunk of input){const bytes=Buffer.isBuffer(chunk)?chunk:Buffer.from(chunk);length+=bytes.length;if(length>maxBytes)throw new ParticipantInvocationError("participant_arguments_too_large");chunks.push(bytes)}}catch(error){if(error instanceof ParticipantInvocationError)throw error;throw new ParticipantInvocationError("participant_arguments_unavailable")}try{const value=JSON.parse(new TextDecoder("utf-8",{fatal:true}).decode(Buffer.concat(chunks,length)));if(!value||typeof value!=="object"||Array.isArray(value))throw new Error("not_object");return value}catch{throw new ParticipantInvocationError("participant_arguments_invalid")}}async function invokeParticipant(server,invocation,args={}){const client=new Client({name:"mapapp-participant-command",version:"1"});const[left,right]=InMemoryTransport.createLinkedPair();try{await server.connect(right);await client.connect(left);const listed=await client.listTools();const selected=invocation.tool?listed.tools.find((tool)=>tool.name===invocation.tool):undefined;if(invocation.tool&&!selected)throw new ParticipantInvocationError("participant_tool_not_found");if(invocation.command==="tools")return selected?{tools:[selected]}:{tools:listed.tools.map((tool)=>({name:tool.name,description:tool.description})),next:"Use tools --tool <name> for the selected input/output schemas."};return await client.callTool({name:invocation.tool,arguments:args},{onprogress:()=>{},resetTimeoutOnProgress:true})}finally{await client.close()}}function invocationFailure(error){const diagnostic=participantErrorDiagnostic(error,"participant_invocation_unavailable");return{isError:true,error:diagnostic,next:"Check tool schemas and retained configuration. After an uncertain action, use its original operationId with status/reconcile. Do not create a replacement."}}export{readParticipantInvocation,readInvocationArguments,invokeParticipant,invocationFailure,ParticipantInvocationError};
2
+ import{participantErrorDiagnostic}from"./chunk-w6cmjk3w.js";import"./chunk-btwmey1h.js";import{createReadStream}from"fs";import{Client,InMemoryTransport}from"@modelcontextprotocol/client";class ParticipantInvocationError extends Error{code;constructor(code){super(code);this.code=code}}function readParticipantInvocation(args){const command=args[0];if(command!=="tools"&&command!=="call")return null;const result={command,walletArgs:[]};for(let index=1;index<args.length;index+=2){const key=args[index],value=args[index+1];if(!key||!value||value.startsWith("--"))throw new ParticipantInvocationError("participant_invocation_invalid");if(key==="--tool"){if(result.tool||!/^mapapp_[a-z0-9_]+$/u.test(value))throw new ParticipantInvocationError("participant_invocation_invalid");result.tool=value}else if(key==="--arguments-file"){if(command!=="call"||result.argumentsFile)throw new ParticipantInvocationError("participant_invocation_invalid");result.argumentsFile=value}else result.walletArgs.push(key,value)}if(command==="call"&&!result.tool)throw new ParticipantInvocationError("participant_invocation_invalid");return result}async function readInvocationArguments(filename,maxBytes){if(!filename)return{};const chunks=[];let length=0;try{const input=filename==="-"?process.stdin:createReadStream(filename,{end:maxBytes});for await(const chunk of input){const bytes=Buffer.isBuffer(chunk)?chunk:Buffer.from(chunk);length+=bytes.length;if(length>maxBytes)throw new ParticipantInvocationError("participant_arguments_too_large");chunks.push(bytes)}}catch(error){if(error instanceof ParticipantInvocationError)throw error;throw new ParticipantInvocationError("participant_arguments_unavailable")}try{const value=JSON.parse(new TextDecoder("utf-8",{fatal:true}).decode(Buffer.concat(chunks,length)));if(!value||typeof value!=="object"||Array.isArray(value))throw new Error("not_object");return value}catch{throw new ParticipantInvocationError("participant_arguments_invalid")}}async function invokeParticipant(server,invocation,args={}){const client=new Client({name:"mapapp-participant-command",version:"1"});const[left,right]=InMemoryTransport.createLinkedPair();try{await server.connect(right);await client.connect(left);const listed=await client.listTools();const selected=invocation.tool?listed.tools.find((tool)=>tool.name===invocation.tool):undefined;if(invocation.tool&&!selected)throw new ParticipantInvocationError("participant_tool_not_found");if(invocation.command==="tools")return selected?{tools:[selected]}:{tools:listed.tools.map((tool)=>({name:tool.name,description:tool.description})),next:"Use tools --tool <name> for the selected input/output schemas."};return await client.callTool({name:invocation.tool,arguments:args},{onprogress:()=>{},resetTimeoutOnProgress:true})}finally{await client.close()}}function invocationFailure(error){const diagnostic=participantErrorDiagnostic(error,"participant_invocation_unavailable");return{isError:true,error:diagnostic,next:"Check tool schemas and retained configuration. After an uncertain action, use its original operationId with status/reconcile. Do not create a replacement."}}export{readParticipantInvocation,readInvocationArguments,invokeParticipant,invocationFailure,ParticipantInvocationError};
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{participantErrorDiagnostic,silenceParticipantConsole}from"./chunk-z0hbdn1f.js";import{__require}from"./chunk-btwmey1h.js";import{StdioServerTransport}from"@modelcontextprotocol/server/stdio";var invocationUsage=`Tools: mapapp-participant tools --wallet-dir <existing-state> [--tool <name>]
3
+ import{participantErrorDiagnostic,silenceParticipantConsole}from"./chunk-w6cmjk3w.js";import{__require}from"./chunk-btwmey1h.js";import{StdioServerTransport}from"@modelcontextprotocol/server/stdio";var invocationUsage=`Tools: mapapp-participant tools --wallet-dir <existing-state> [--tool <name>]
4
4
  Call: mapapp-participant call --wallet-dir <existing-state> --tool <name> [--arguments-file <utf8-json-file-or->]
5
5
  Omit --arguments-file for {}. Use - to read JSON from stdin. Calls use the same MCP tools; retain original operation IDs after uncertainty.
6
6
  `;var usage=`Usage: mapapp-participant --wallet-dir <existing-protected-wallet>
@@ -10,10 +10,10 @@ Connect: mapapp-participant connect --wallet-dir <new-connector-directory> --dep
10
10
  First setup/connect/restore: the final destination must not already exist, even empty. Keep the MCP host/client session open until awaited calls finish.
11
11
  One local stdio MCP provides discovery, paid/sponsored/social actions and private messaging. No HTTP listener. Delegation belongs to the user and agent; connected wallets enforce their own permissions. Preserve original operation IDs after uncertainty. Read /developers?guide=agent-setup.
12
12
  `;function readParticipantSetupCommand(args){if(!["setup","restore","connect"].includes(args[0]??""))return null;const fields={};const allowed=args[0]==="restore"?["--wallet-dir","--deployment","--root-file","--backup-file","--connection-file","--operations-file"]:args[0]==="connect"?["--wallet-dir","--deployment","--wallet-endpoint","--identity-key"]:["--wallet-dir","--deployment"];for(let i=1;i<args.length;i+=2){const key=args[i],value=args[i+1];if(!allowed.includes(key)||fields[key]||!value||value.startsWith("--"))throw new Error("participant_configuration_invalid");fields[key]=value}if(allowed.some((key)=>!fields[key]))throw new Error("participant_configuration_invalid");return{walletDirectory:fields["--wallet-dir"],deployment:fields["--deployment"],...args[0]==="connect"?{walletEndpoint:fields["--wallet-endpoint"],identityKey:fields["--identity-key"]}:{},...args[0]==="restore"?{restore:{rootFile:fields["--root-file"],backupFile:fields["--backup-file"],connectionFile:fields["--connection-file"],operationsFile:fields["--operations-file"]}}:{}}}function readParticipantMcpConfig(args){if(args.length===1&&["--help","-h"].includes(args[0]))return null;let walletDirectory;let connectionFile;const seen=new Set;for(let i=0;i<args.length;i++){const key=args[i];if(seen.has(key))throw new Error("participant_configuration_invalid");seen.add(key);const value=args[++i];if(!value||value.startsWith("--"))throw new Error("participant_configuration_invalid");if(key==="--wallet-dir")walletDirectory=value;else if(key==="--connection-file")connectionFile=value;else throw new Error("participant_configuration_invalid")}if(!walletDirectory)throw new Error("participant_configuration_invalid");return{walletDirectory,...connectionFile?{connectionFile}:{}}}if(import.meta.main){silenceParticipantConsole();let runtime;let participant;let closing;const setupMode=["setup","restore","connect"].includes(process.argv[2]??"");const invocationMode=["tools","call"].includes(process.argv[2]??"");const close=()=>closing??=(async()=>{try{await participant?.close()}finally{await runtime?.close()}})();const closeInvocation=async()=>{try{await close()}catch{process.stderr.write(JSON.stringify({error:participantErrorDiagnostic(null,"participant_close_unavailable")})+`
13
- `);process.exitCode=1}};try{const args=process.argv.slice(2);const invocation=invocationMode?(await import("./chunk-x34n6pw4.js")).readParticipantInvocation(args):null;const setup=readParticipantSetupCommand(args);const config=setup?null:readParticipantMcpConfig(invocation?.walletArgs??args);if(setup){const{setupParticipantWallet,connectParticipantWallet}=await import("./chunk-kk02ctwf.js");const outcome=setup.walletEndpoint&&setup.identityKey?await connectParticipantWallet({...setup,walletEndpoint:setup.walletEndpoint,identityKey:setup.identityKey}):await setupParticipantWallet(setup);process.stdout.write(JSON.stringify(outcome)+`
14
- `)}else if(!config)process.stderr.write(usage+invocationUsage);else{const[{openAgentParticipantRuntime},{createMapAppParticipantServer,PARTICIPANT_MCP_MAX_MESSAGE_BYTES}]=await Promise.all([import("./chunk-3ah5hd7r.js"),import("./chunk-595sk0qe.js")]);const invocationArgs=invocation?await(await import("./chunk-x34n6pw4.js")).readInvocationArguments(invocation.argumentsFile,PARTICIPANT_MCP_MAX_MESSAGE_BYTES):undefined;runtime=await openAgentParticipantRuntime(config);participant=createMapAppParticipantServer(runtime);const stop=()=>{close().then(()=>process.exit(invocation?130:0),()=>{process.stderr.write(JSON.stringify({error:participantErrorDiagnostic(null,"participant_close_unavailable")})+`
15
- `);process.exit(1)})};process.once("SIGINT",stop);process.once("SIGTERM",stop);if(invocation){try{const outcome=await(await import("./chunk-x34n6pw4.js")).invokeParticipant(participant.server,invocation,invocationArgs);process.stdout.write(JSON.stringify(outcome)+`
16
- `);process.exitCode="isError"in outcome&&outcome.isError?1:0}finally{await closeInvocation();process.off("SIGINT",stop);process.off("SIGTERM",stop)}}else{process.stdin.once("end",stop);await participant.server.connect(new StdioServerTransport(process.stdin,process.stdout,{maxBufferSize:PARTICIPANT_MCP_MAX_MESSAGE_BYTES}))}}}catch(error){if(invocationMode){process.stdout.write(JSON.stringify((await import("./chunk-x34n6pw4.js")).invocationFailure(error))+`
13
+ `);process.exitCode=1}};try{const args=process.argv.slice(2);const invocation=invocationMode?(await import("./chunk-zqcj030q.js")).readParticipantInvocation(args):null;const setup=readParticipantSetupCommand(args);const config=setup?null:readParticipantMcpConfig(invocation?.walletArgs??args);if(setup){const{setupParticipantWallet,connectParticipantWallet}=await import("./chunk-wd3q2byr.js");const outcome=setup.walletEndpoint&&setup.identityKey?await connectParticipantWallet({...setup,walletEndpoint:setup.walletEndpoint,identityKey:setup.identityKey}):await setupParticipantWallet(setup);process.stdout.write(JSON.stringify(outcome)+`
14
+ `)}else if(!config)process.stderr.write(usage+invocationUsage);else{const[{openAgentParticipantRuntime},{createMapAppParticipantServer,PARTICIPANT_MCP_MAX_MESSAGE_BYTES}]=await Promise.all([import("./chunk-1c876c9w.js"),import("./chunk-28ykvb04.js")]);const invocationArgs=invocation?await(await import("./chunk-zqcj030q.js")).readInvocationArguments(invocation.argumentsFile,PARTICIPANT_MCP_MAX_MESSAGE_BYTES):undefined;runtime=await openAgentParticipantRuntime(config);participant=createMapAppParticipantServer(runtime);const stop=()=>{close().then(()=>process.exit(invocation?130:0),()=>{process.stderr.write(JSON.stringify({error:participantErrorDiagnostic(null,"participant_close_unavailable")})+`
15
+ `);process.exit(1)})};process.once("SIGINT",stop);process.once("SIGTERM",stop);if(invocation){try{const outcome=await(await import("./chunk-zqcj030q.js")).invokeParticipant(participant.server,invocation,invocationArgs);process.stdout.write(JSON.stringify(outcome)+`
16
+ `);process.exitCode="isError"in outcome&&outcome.isError?1:0}finally{await closeInvocation();process.off("SIGINT",stop);process.off("SIGTERM",stop)}}else{process.stdin.once("end",stop);await participant.server.connect(new StdioServerTransport(process.stdin,process.stdout,{maxBufferSize:PARTICIPANT_MCP_MAX_MESSAGE_BYTES}))}}}catch(error){if(invocationMode){process.stdout.write(JSON.stringify((await import("./chunk-zqcj030q.js")).invocationFailure(error))+`
17
17
  `);await closeInvocation();process.exitCode=1}else{const diagnostic=participantErrorDiagnostic(error,setupMode?"participant_setup_unavailable":"participant_startup_unavailable");if(setupMode){process.stdout.write(JSON.stringify({state:"blocked",reason:diagnostic.code,diagnostic})+`
18
18
  `)}process.stderr.write(JSON.stringify({error:diagnostic})+`
19
19
  `);await closeInvocation();process.exitCode=1}}}export{readParticipantSetupCommand,readParticipantMcpConfig};
package/distribution.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema": "mapapp-agent-connector-distribution/v1",
3
3
  "name": "@jdr377/mapapp-agent-connector",
4
- "version": "0.1.0-pre.10",
4
+ "version": "0.1.0-pre.12",
5
5
  "runtime": {
6
6
  "bun": "1.3.11",
7
7
  "requirement": ">=1.3.11 <2.0.0",
@@ -63,7 +63,7 @@
63
63
  },
64
64
  {
65
65
  "path": "server/agent/mcp/diagnostics.ts",
66
- "sha256": "7653dc78e7777f51e4e0774a678aee3b0a1d83f6091512d0afa60abdbc0daf48"
66
+ "sha256": "2e995347a6edab229c503782d6089a696f446789a4ba972ebe7e6a313fec5acf"
67
67
  },
68
68
  {
69
69
  "path": "server/agent/mcp/invoke.ts",
@@ -71,7 +71,7 @@
71
71
  },
72
72
  {
73
73
  "path": "server/agent/mcp/participant.ts",
74
- "sha256": "1d067ad92c27fcb6d5a1bf5cc8a476eb8af922aeabc7518f03b38922866bafb6"
74
+ "sha256": "093462605f20a887cafaa9e3f29c523ad30b439599e7470e2a7c8dc33efec5a2"
75
75
  },
76
76
  {
77
77
  "path": "server/agent/mcp/publication.ts",
@@ -79,7 +79,7 @@
79
79
  },
80
80
  {
81
81
  "path": "server/agent/onboarding.ts",
82
- "sha256": "7712296a380f8344cfad7b3fe1a892a220575a9ad2a1daacccf668410f3be2e3"
82
+ "sha256": "42e7cc5841de518629f5d936f404ee0f0875826698774431a62319dd3548400d"
83
83
  },
84
84
  {
85
85
  "path": "server/agent/parser.ts",
@@ -143,7 +143,7 @@
143
143
  },
144
144
  {
145
145
  "path": "src/bitcoin/agentPaidPost.ts",
146
- "sha256": "b1def54f78c9e9decb1aeb1ace46373b994f797d28a0fd77c126dca0ed84e488"
146
+ "sha256": "2b9f40342dcf1aa3b4062b429d28f6e6ace1999aa84817654511815aa58b64cc"
147
147
  },
148
148
  {
149
149
  "path": "src/bitcoin/agentParticipantBinding.ts",
@@ -155,11 +155,11 @@
155
155
  },
156
156
  {
157
157
  "path": "src/bitcoin/agentSocialAction.ts",
158
- "sha256": "15db1009f84777e1fa3c97066f9d531c1c7606ee6b2d107e218139a2876748c4"
158
+ "sha256": "28ea4e687fec308a9e77961e85af70714b271b69074419ed847a25aa95e3ee94"
159
159
  },
160
160
  {
161
161
  "path": "src/bitcoin/agentSponsoredPost.ts",
162
- "sha256": "035b55959fb910ac5427e5922c44d48fc52068596250eaead2cbea41ca2a8f1e"
162
+ "sha256": "daa7e54574ae0b58b12d6e91a9d01ea25c79a7f39da05f023cb558820a525806"
163
163
  },
164
164
  {
165
165
  "path": "src/bitcoin/agentWalletConnection.ts",
@@ -255,20 +255,20 @@
255
255
  }
256
256
  ],
257
257
  "files": {
258
- "README.md": "a73330da7148be3ff595acfc6ce8e552e9e552d233e80711a7f97e600e35eb83",
258
+ "README.md": "41230b2bc211fff24367c4ba0c4b8052b54d78b8ab706fe6ca0705c23da08da7",
259
259
  "bun.lock": "70b49fe644812578e2c365f4600fa57b694710f16a8095dc05e4dbc257b3c58a",
260
- "dist/chunk-0wyrdcyb.js": "1b1d1239d99a370d703f85c4e800e82c0d63b6cfe4e747a2808b38d38e284add",
261
- "dist/chunk-3ah5hd7r.js": "2fd0080cada3b965dc2ee813056a5f714b0e07789903dd38f95b42975b20a20b",
262
- "dist/chunk-595sk0qe.js": "700dd1cb7b717ea2b106dc9000b9f11a833b234f909dcdca0f1e7d213f3e405d",
260
+ "dist/chunk-1c876c9w.js": "8d115abb8f31aea136380adf3ff08a492ed4a69ee8866e6426e9cc660e48853e",
261
+ "dist/chunk-28ykvb04.js": "e51aaea925f167bccacf15e340365b9eec1ec7659481e80a6053921102a05df9",
263
262
  "dist/chunk-btwmey1h.js": "4e3cec1f9adaea9464cd99ea40ea0b7a693d800040e59540856f6c2b8ff013ee",
264
263
  "dist/chunk-c74qq5ek.js": "36c949a5d21a3a2ac2c0e7a1020ebc995f1b665194ea43e8e29244eb8e166257",
265
264
  "dist/chunk-e6y2yzbj.js": "4be64909a0536718a794f3d7bd11c4b5af95097ca7295c05cde1394a80027b38",
266
- "dist/chunk-kk02ctwf.js": "abbe9e7ab08c941ff9d77aecbc7bc7afe5e3c3bbac40b005d6b3240fc1cd0323",
267
265
  "dist/chunk-v1y901rb.js": "15dcac0514ced3cec54a8475dfcf6990c300078af1256cea5adb79dc7fc69914",
268
- "dist/chunk-x34n6pw4.js": "2727168ae85e5aa9f61cced8cf68306f4c80dbfcf21f39416cebd557bb4d4f53",
269
- "dist/chunk-z0hbdn1f.js": "87a36fa987198195835a5599d13664091a1ad420899e14a4fdf9a0c0f9892193",
270
- "dist/participant-mcp-server.js": "03d1b36a380276f4b779805576cd271d86c9c02981e3a476250f1b0befd6503b",
271
- "package.json": "837ee47ee6d22bbc08920a470efab4152ee9f90c45302bf5a7775577908c9b3b"
266
+ "dist/chunk-w6cmjk3w.js": "4a5d04ce759889fc646c7f525658ca32fd211210ae34646fb1be730c46cb044e",
267
+ "dist/chunk-wd3q2byr.js": "d8a0cddc9eac0ca29efc977c1312b94e30066813d881595106d39d4556415397",
268
+ "dist/chunk-yw2vsz4v.js": "451942dfd8882e39645ebfa80043d3ca4c54dff181ecb35d00b35c6beaea5fe7",
269
+ "dist/chunk-zqcj030q.js": "b509ed2d619bd38e7288c22a42d81a985458658c4786c5e57847c0edb4603875",
270
+ "dist/participant-mcp-server.js": "5bd80d7fb1b9dde6f877179bb11528637a6cce3c071991177f7b0cbe4d1341c9",
271
+ "package.json": "7bd94ca671845b540dfa5ba8ccc445b76c2b9e20b661d18946b02340f6020826"
272
272
  },
273
273
  "dependencies": {
274
274
  "@1sat/actions": "0.0.224",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jdr377/mapapp-agent-connector",
3
- "version": "0.1.0-pre.10",
3
+ "version": "0.1.0-pre.12",
4
4
  "description": "Local MCP for MapApp discovery, participant wallet actions and private messaging",
5
5
  "private": false,
6
6
  "license": "UNLICENSED",