bantou 0.1.1 → 0.2.0
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/.output/nitro.json +13 -0
- package/.output/public/_nuxt/BmGsA4i2.js +1 -0
- package/.output/public/_nuxt/D_G6gzEa.js +1 -0
- package/.output/public/_nuxt/builds/latest.json +1 -0
- package/.output/public/_nuxt/builds/meta/1a8fc623-6671-445b-bdd3-c3d073520a3a.json +1 -0
- package/.output/public/_nuxt/entry.CZSvzYhH.css +1 -0
- package/.output/public/_nuxt/error-404.C3wqHTJz.css +1 -0
- package/.output/public/_nuxt/error-500.D6rBzoDj.css +1 -0
- package/.output/public/_nuxt/pdFQkwM_.js +4 -0
- package/.output/server/chunks/_/error-500.mjs +20 -0
- package/.output/server/chunks/_/error-500.mjs.map +1 -0
- package/.output/server/chunks/nitro/nitro.mjs +5870 -0
- package/.output/server/chunks/nitro/nitro.mjs.map +1 -0
- package/.output/server/chunks/routes/mcp.mjs +22 -0
- package/.output/server/chunks/routes/mcp.mjs.map +1 -0
- package/.output/server/chunks/routes/renderer.mjs +462 -0
- package/.output/server/chunks/routes/renderer.mjs.map +1 -0
- package/.output/server/chunks/virtual/_virtual_spa-template.mjs +4 -0
- package/.output/server/chunks/virtual/_virtual_spa-template.mjs.map +1 -0
- package/.output/server/chunks/virtual/precomputed.mjs +4 -0
- package/.output/server/chunks/virtual/precomputed.mjs.map +1 -0
- package/.output/server/index.mjs +18 -0
- package/.output/server/index.mjs.map +1 -0
- package/.output/server/node_modules/@babel/parser/lib/index.js +14657 -0
- package/.output/server/node_modules/@babel/parser/package.json +50 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/helpers.js +64 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/interfaces.js +16 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/mcp-server.js +32 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/server.js +246 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/package.json +1 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js +41 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js +429 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js +971 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/requestBody.js +58 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sseKeepAlive.js +13 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js +961 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js +228 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js +51 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js +57 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js +1137 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/toolNameValidation.js +92 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/uriTemplate.js +239 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js +2065 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/validation/ajv-provider.js +87 -0
- package/.output/server/node_modules/@modelcontextprotocol/sdk/package.json +165 -0
- package/.output/server/node_modules/@parcel/watcher-wasm/index.mjs +349 -0
- package/.output/server/node_modules/@parcel/watcher-wasm/package.json +44 -0
- package/.output/server/node_modules/@parcel/watcher-wasm/watcher.wasm +0 -0
- package/.output/server/node_modules/@parcel/watcher-wasm/wrapper.js +88 -0
- package/.output/server/node_modules/@unagents/messenger-broker/dist/index.mjs +12 -0
- package/.output/server/node_modules/@unagents/messenger-broker/dist/shared/messenger-broker.B8W77sqB.mjs +1177 -0
- package/.output/server/node_modules/@unagents/messenger-broker/package.json +37 -0
- package/.output/server/node_modules/@unagents/messenger-client/dist/index.mjs +9 -0
- package/.output/server/node_modules/@unagents/messenger-client/dist/shared/messenger-client.CfQVmH_Z.mjs +975 -0
- package/.output/server/node_modules/@unagents/messenger-client/dist/shared/messenger-client.CoDKzubj.mjs +1000 -0
- package/.output/server/node_modules/@unagents/messenger-client/package.json +37 -0
- package/.output/server/node_modules/@unagents/messenger-protocol/dist/index.mjs +103 -0
- package/.output/server/node_modules/@unagents/messenger-protocol/package.json +29 -0
- package/.output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6802 -0
- package/.output/server/node_modules/@vue/compiler-core/package.json +58 -0
- package/.output/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +729 -0
- package/.output/server/node_modules/@vue/compiler-dom/package.json +57 -0
- package/.output/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1420 -0
- package/.output/server/node_modules/@vue/compiler-ssr/package.json +34 -0
- package/.output/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1933 -0
- package/.output/server/node_modules/@vue/reactivity/package.json +55 -0
- package/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +7085 -0
- package/.output/server/node_modules/@vue/runtime-core/package.json +52 -0
- package/.output/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1917 -0
- package/.output/server/node_modules/@vue/runtime-dom/package.json +60 -0
- package/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +951 -0
- package/.output/server/node_modules/@vue/server-renderer/package.json +53 -0
- package/.output/server/node_modules/@vue/shared/dist/shared.cjs.prod.js +655 -0
- package/.output/server/node_modules/@vue/shared/package.json +47 -0
- package/.output/server/node_modules/ajv/dist/ajv.js +50 -0
- package/.output/server/node_modules/ajv/dist/compile/codegen/code.js +156 -0
- package/.output/server/node_modules/ajv/dist/compile/codegen/index.js +697 -0
- package/.output/server/node_modules/ajv/dist/compile/codegen/scope.js +143 -0
- package/.output/server/node_modules/ajv/dist/compile/errors.js +123 -0
- package/.output/server/node_modules/ajv/dist/compile/index.js +242 -0
- package/.output/server/node_modules/ajv/dist/compile/names.js +28 -0
- package/.output/server/node_modules/ajv/dist/compile/ref_error.js +12 -0
- package/.output/server/node_modules/ajv/dist/compile/resolve.js +155 -0
- package/.output/server/node_modules/ajv/dist/compile/rules.js +26 -0
- package/.output/server/node_modules/ajv/dist/compile/util.js +178 -0
- package/.output/server/node_modules/ajv/dist/compile/validate/applicability.js +19 -0
- package/.output/server/node_modules/ajv/dist/compile/validate/boolSchema.js +50 -0
- package/.output/server/node_modules/ajv/dist/compile/validate/dataType.js +203 -0
- package/.output/server/node_modules/ajv/dist/compile/validate/defaults.js +35 -0
- package/.output/server/node_modules/ajv/dist/compile/validate/index.js +520 -0
- package/.output/server/node_modules/ajv/dist/compile/validate/keyword.js +124 -0
- package/.output/server/node_modules/ajv/dist/compile/validate/subschema.js +81 -0
- package/.output/server/node_modules/ajv/dist/core.js +618 -0
- package/.output/server/node_modules/ajv/dist/refs/data.json +13 -0
- package/.output/server/node_modules/ajv/dist/refs/json-schema-draft-07.json +151 -0
- package/.output/server/node_modules/ajv/dist/runtime/equal.js +7 -0
- package/.output/server/node_modules/ajv/dist/runtime/ucs2length.js +24 -0
- package/.output/server/node_modules/ajv/dist/runtime/uri.js +6 -0
- package/.output/server/node_modules/ajv/dist/runtime/validation_error.js +11 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +49 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +106 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/allOf.js +23 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +12 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/contains.js +95 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +85 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/if.js +66 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/index.js +44 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/items.js +52 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/items2020.js +30 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/not.js +26 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +60 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +75 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +12 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/properties.js +54 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +38 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +13 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/code.js +131 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/core/id.js +10 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/core/index.js +16 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/core/ref.js +122 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/discriminator/index.js +104 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/discriminator/types.js +9 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/draft7.js +17 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/format/index.js +6 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/metadata.js +18 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/const.js +25 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/enum.js +48 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/index.js +33 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/limitItems.js +24 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/limitLength.js +27 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +27 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +24 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +26 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/pattern.js +33 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/required.js +79 -0
- package/.output/server/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +64 -0
- package/.output/server/node_modules/ajv/package.json +126 -0
- package/.output/server/node_modules/ajv-formats/dist/formats.js +208 -0
- package/.output/server/node_modules/ajv-formats/dist/index.js +37 -0
- package/.output/server/node_modules/ajv-formats/dist/limit.js +69 -0
- package/.output/server/node_modules/ajv-formats/package.json +74 -0
- package/.output/server/node_modules/consola/dist/chunks/prompt.mjs +280 -0
- package/.output/server/node_modules/consola/dist/core.mjs +512 -0
- package/.output/server/node_modules/consola/dist/index.mjs +651 -0
- package/.output/server/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +72 -0
- package/.output/server/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +288 -0
- package/.output/server/node_modules/consola/dist/utils.mjs +54 -0
- package/.output/server/node_modules/consola/package.json +136 -0
- package/.output/server/node_modules/content-type/index.js +225 -0
- package/.output/server/node_modules/content-type/package.json +42 -0
- package/.output/server/node_modules/cookie-es/dist/index.mjs +268 -0
- package/.output/server/node_modules/cookie-es/package.json +46 -0
- package/.output/server/node_modules/crossws/dist/_chunks/_request.mjs +83 -0
- package/.output/server/node_modules/crossws/dist/_chunks/adapter.mjs +234 -0
- package/.output/server/node_modules/crossws/dist/_chunks/error.mjs +7 -0
- package/.output/server/node_modules/crossws/dist/_chunks/libs/ws.mjs +6 -0
- package/.output/server/node_modules/crossws/dist/_chunks/node.mjs +220 -0
- package/.output/server/node_modules/crossws/dist/_chunks/peer.mjs +208 -0
- package/.output/server/node_modules/crossws/dist/adapters/node.mjs +1 -0
- package/.output/server/node_modules/crossws/package.json +115 -0
- package/.output/server/node_modules/defu/dist/defu.mjs +69 -0
- package/.output/server/node_modules/defu/package.json +48 -0
- package/.output/server/node_modules/destr/dist/index.mjs +72 -0
- package/.output/server/node_modules/destr/package.json +47 -0
- package/.output/server/node_modules/devalue/index.js +17 -0
- package/.output/server/node_modules/devalue/package.json +39 -0
- package/.output/server/node_modules/devalue/src/base64.js +60 -0
- package/.output/server/node_modules/devalue/src/constants.js +12 -0
- package/.output/server/node_modules/devalue/src/operations.js +221 -0
- package/.output/server/node_modules/devalue/src/parse.js +279 -0
- package/.output/server/node_modules/devalue/src/stringify.js +433 -0
- package/.output/server/node_modules/devalue/src/uneval.js +698 -0
- package/.output/server/node_modules/devalue/src/utils.js +190 -0
- package/.output/server/node_modules/entities/dist/commonjs/decode-codepoint.js +77 -0
- package/.output/server/node_modules/entities/dist/commonjs/decode.js +568 -0
- package/.output/server/node_modules/entities/dist/commonjs/generated/decode-data-html.js +7 -0
- package/.output/server/node_modules/entities/dist/commonjs/generated/decode-data-xml.js +7 -0
- package/.output/server/node_modules/entities/dist/commonjs/internal/bin-trie-flags.js +21 -0
- package/.output/server/node_modules/entities/dist/commonjs/internal/decode-shared.js +31 -0
- package/.output/server/node_modules/entities/dist/commonjs/package.json +3 -0
- package/.output/server/node_modules/entities/package.json +120 -0
- package/.output/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
- package/.output/server/node_modules/estree-walker/package.json +37 -0
- package/.output/server/node_modules/fast-deep-equal/index.js +46 -0
- package/.output/server/node_modules/fast-deep-equal/package.json +61 -0
- package/.output/server/node_modules/fast-uri/index.js +711 -0
- package/.output/server/node_modules/fast-uri/lib/schemes.js +272 -0
- package/.output/server/node_modules/fast-uri/lib/utils.js +799 -0
- package/.output/server/node_modules/fast-uri/package.json +68 -0
- package/.output/server/node_modules/get-port-please/dist/index.mjs +430 -0
- package/.output/server/node_modules/get-port-please/package.json +39 -0
- package/.output/server/node_modules/h3/dist/index.mjs +2498 -0
- package/.output/server/node_modules/h3/package.json +75 -0
- package/.output/server/node_modules/hookable/dist/index.mjs +257 -0
- package/.output/server/node_modules/hookable/package.json +54 -0
- package/.output/server/node_modules/http-shutdown/index.js +85 -0
- package/.output/server/node_modules/http-shutdown/package.json +32 -0
- package/.output/server/node_modules/iron-webcrypto/dist/index.js +298 -0
- package/.output/server/node_modules/iron-webcrypto/package.json +72 -0
- package/.output/server/node_modules/is-extglob/index.js +20 -0
- package/.output/server/node_modules/is-extglob/package.json +69 -0
- package/.output/server/node_modules/is-glob/index.js +150 -0
- package/.output/server/node_modules/is-glob/package.json +81 -0
- package/.output/server/node_modules/jiti/dist/jiti.cjs +1 -0
- package/.output/server/node_modules/jiti/lib/jiti.mjs +29 -0
- package/.output/server/node_modules/jiti/package.json +146 -0
- package/.output/server/node_modules/json-schema-traverse/index.js +93 -0
- package/.output/server/node_modules/json-schema-traverse/package.json +43 -0
- package/.output/server/node_modules/listhen/dist/chunks/xdg-open.mjs +1069 -0
- package/.output/server/node_modules/listhen/dist/index.mjs +19 -0
- package/.output/server/node_modules/listhen/dist/shared/listhen.tqe5I1Rl.mjs +1040 -0
- package/.output/server/node_modules/listhen/package.json +84 -0
- package/.output/server/node_modules/napi-wasm/index.mjs +1371 -0
- package/.output/server/node_modules/napi-wasm/package.json +33 -0
- package/.output/server/node_modules/node-forge/lib/aes.js +1091 -0
- package/.output/server/node_modules/node-forge/lib/aesCipherSuites.js +282 -0
- package/.output/server/node_modules/node-forge/lib/asn1-validator.js +91 -0
- package/.output/server/node_modules/node-forge/lib/asn1.js +1522 -0
- package/.output/server/node_modules/node-forge/lib/baseN.js +186 -0
- package/.output/server/node_modules/node-forge/lib/cipher.js +230 -0
- package/.output/server/node_modules/node-forge/lib/cipherModes.js +1027 -0
- package/.output/server/node_modules/node-forge/lib/des.js +496 -0
- package/.output/server/node_modules/node-forge/lib/ed25519.js +1091 -0
- package/.output/server/node_modules/node-forge/lib/forge.js +13 -0
- package/.output/server/node_modules/node-forge/lib/hmac.js +146 -0
- package/.output/server/node_modules/node-forge/lib/index.js +33 -0
- package/.output/server/node_modules/node-forge/lib/jsbn.js +1294 -0
- package/.output/server/node_modules/node-forge/lib/kem.js +168 -0
- package/.output/server/node_modules/node-forge/lib/log.js +319 -0
- package/.output/server/node_modules/node-forge/lib/md.all.js +13 -0
- package/.output/server/node_modules/node-forge/lib/md.js +11 -0
- package/.output/server/node_modules/node-forge/lib/md5.js +289 -0
- package/.output/server/node_modules/node-forge/lib/mgf.js +12 -0
- package/.output/server/node_modules/node-forge/lib/mgf1.js +57 -0
- package/.output/server/node_modules/node-forge/lib/oids.js +180 -0
- package/.output/server/node_modules/node-forge/lib/pbe.js +1029 -0
- package/.output/server/node_modules/node-forge/lib/pbkdf2.js +211 -0
- package/.output/server/node_modules/node-forge/lib/pem.js +413 -0
- package/.output/server/node_modules/node-forge/lib/pkcs1.js +276 -0
- package/.output/server/node_modules/node-forge/lib/pkcs12.js +1081 -0
- package/.output/server/node_modules/node-forge/lib/pkcs7.js +1260 -0
- package/.output/server/node_modules/node-forge/lib/pkcs7asn1.js +410 -0
- package/.output/server/node_modules/node-forge/lib/pki.js +102 -0
- package/.output/server/node_modules/node-forge/lib/prime.js +297 -0
- package/.output/server/node_modules/node-forge/lib/prng.js +419 -0
- package/.output/server/node_modules/node-forge/lib/pss.js +241 -0
- package/.output/server/node_modules/node-forge/lib/random.js +191 -0
- package/.output/server/node_modules/node-forge/lib/rc2.js +410 -0
- package/.output/server/node_modules/node-forge/lib/rsa.js +2014 -0
- package/.output/server/node_modules/node-forge/lib/sha1.js +319 -0
- package/.output/server/node_modules/node-forge/lib/sha256.js +327 -0
- package/.output/server/node_modules/node-forge/lib/sha512.js +561 -0
- package/.output/server/node_modules/node-forge/lib/ssh.js +236 -0
- package/.output/server/node_modules/node-forge/lib/tls.js +4334 -0
- package/.output/server/node_modules/node-forge/lib/util.js +2652 -0
- package/.output/server/node_modules/node-forge/lib/x509.js +3257 -0
- package/.output/server/node_modules/node-forge/package.json +123 -0
- package/.output/server/node_modules/node-mock-http/dist/_polyfill/buffer/node.mjs +1 -0
- package/.output/server/node_modules/node-mock-http/dist/_polyfill/events/node.mjs +1 -0
- package/.output/server/node_modules/node-mock-http/dist/index.mjs +1 -0
- package/.output/server/node_modules/node-mock-http/package.json +63 -0
- package/.output/server/node_modules/nostics/dist/formatters/ansi.mjs +19 -0
- package/.output/server/node_modules/nostics/dist/index.mjs +194 -0
- package/.output/server/node_modules/nostics/package.json +126 -0
- package/.output/server/node_modules/pathe/dist/index.mjs +19 -0
- package/.output/server/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +249 -0
- package/.output/server/node_modules/pathe/package.json +61 -0
- package/.output/server/node_modules/picomatch/index.js +17 -0
- package/.output/server/node_modules/picomatch/lib/constants.js +184 -0
- package/.output/server/node_modules/picomatch/lib/parse.js +1425 -0
- package/.output/server/node_modules/picomatch/lib/picomatch.js +361 -0
- package/.output/server/node_modules/picomatch/lib/scan.js +403 -0
- package/.output/server/node_modules/picomatch/lib/utils.js +72 -0
- package/.output/server/node_modules/picomatch/package.json +83 -0
- package/.output/server/node_modules/radix3/dist/index.mjs +262 -0
- package/.output/server/node_modules/radix3/package.json +52 -0
- package/.output/server/node_modules/source-map-js/lib/array-set.js +121 -0
- package/.output/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
- package/.output/server/node_modules/source-map-js/lib/base64.js +67 -0
- package/.output/server/node_modules/source-map-js/lib/binary-search.js +111 -0
- package/.output/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
- package/.output/server/node_modules/source-map-js/lib/quick-sort.js +141 -0
- package/.output/server/node_modules/source-map-js/lib/source-map-consumer.js +1236 -0
- package/.output/server/node_modules/source-map-js/lib/source-map-generator.js +446 -0
- package/.output/server/node_modules/source-map-js/lib/source-node.js +420 -0
- package/.output/server/node_modules/source-map-js/lib/util.js +594 -0
- package/.output/server/node_modules/source-map-js/package.json +71 -0
- package/.output/server/node_modules/source-map-js/source-map.js +8 -0
- package/.output/server/node_modules/std-env/dist/index.mjs +1 -0
- package/.output/server/node_modules/std-env/package.json +43 -0
- package/.output/server/node_modules/tinyclip/dist/index.js +143 -0
- package/.output/server/node_modules/tinyclip/package.json +48 -0
- package/.output/server/node_modules/ufo/dist/index.mjs +645 -0
- package/.output/server/node_modules/ufo/package.json +48 -0
- package/.output/server/node_modules/uncrypto/dist/crypto.node.mjs +16 -0
- package/.output/server/node_modules/uncrypto/package.json +60 -0
- package/.output/server/node_modules/unhead/dist/client.mjs +22 -0
- package/.output/server/node_modules/unhead/dist/legacy.mjs +33 -0
- package/.output/server/node_modules/unhead/dist/minify.mjs +183 -0
- package/.output/server/node_modules/unhead/dist/parser.mjs +518 -0
- package/.output/server/node_modules/unhead/dist/plugins.mjs +782 -0
- package/.output/server/node_modules/unhead/dist/server.mjs +99 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.BEmVMkeA.mjs +673 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.Bf_fPVYA.mjs +6 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.Bm4Y6XQI.mjs +17 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.C5Bksi2B.mjs +49 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.CGPOfp5O.mjs +32 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.CHEy9ana.mjs +7 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.C_7zwq8E.mjs +11 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.CaeaMM5q.mjs +19 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.D7HkBzZn.mjs +59 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.D9VfQWNo.mjs +240 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.DD4N5B4k.mjs +224 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.DGl9jcjg.mjs +196 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.DJuZwX9c.mjs +400 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.DkxnqlHC.mjs +264 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.DspMpm6y.mjs +48 -0
- package/.output/server/node_modules/unhead/dist/shared/unhead.o8j9utSy.mjs +208 -0
- package/.output/server/node_modules/unhead/dist/stream/client.mjs +33 -0
- package/.output/server/node_modules/unhead/dist/stream/iife.mjs +2 -0
- package/.output/server/node_modules/unhead/dist/stream/server.mjs +446 -0
- package/.output/server/node_modules/unhead/dist/utils.mjs +7 -0
- package/.output/server/node_modules/unhead/package.json +179 -0
- package/.output/server/node_modules/untun/dist/_chunks/cloudflared.mjs +179 -0
- package/.output/server/node_modules/untun/dist/_chunks/log.mjs +27 -0
- package/.output/server/node_modules/untun/dist/index.mjs +47 -0
- package/.output/server/node_modules/untun/package.json +44 -0
- package/.output/server/node_modules/uqr/dist/index.mjs +739 -0
- package/.output/server/node_modules/uqr/package.json +69 -0
- package/.output/server/node_modules/vue/dist/vue.cjs.js +80 -0
- package/.output/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
- package/.output/server/node_modules/vue/index.js +7 -0
- package/.output/server/node_modules/vue/index.mjs +1 -0
- package/.output/server/node_modules/vue/package.json +112 -0
- package/.output/server/node_modules/vue/server-renderer/index.mjs +1 -0
- package/.output/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +687 -0
- package/.output/server/node_modules/vue-bundle-renderer/package.json +66 -0
- package/.output/server/node_modules/zod/index.js +7 -0
- package/.output/server/node_modules/zod/package.json +147 -0
- package/.output/server/node_modules/zod/v3/ZodError.js +143 -0
- package/.output/server/node_modules/zod/v3/errors.js +9 -0
- package/.output/server/node_modules/zod/v3/external.js +6 -0
- package/.output/server/node_modules/zod/v3/helpers/errorUtil.js +6 -0
- package/.output/server/node_modules/zod/v3/helpers/parseUtil.js +109 -0
- package/.output/server/node_modules/zod/v3/helpers/typeAliases.js +1 -0
- package/.output/server/node_modules/zod/v3/helpers/util.js +133 -0
- package/.output/server/node_modules/zod/v3/index.js +4 -0
- package/.output/server/node_modules/zod/v3/locales/en.js +109 -0
- package/.output/server/node_modules/zod/v3/package.json +7 -0
- package/.output/server/node_modules/zod/v3/types.js +3697 -0
- package/.output/server/node_modules/zod/v4/classic/checks.js +1 -0
- package/.output/server/node_modules/zod/v4/classic/coerce.js +17 -0
- package/.output/server/node_modules/zod/v4/classic/compat.js +31 -0
- package/.output/server/node_modules/zod/v4/classic/deep-partial.js +13 -0
- package/.output/server/node_modules/zod/v4/classic/errors.js +57 -0
- package/.output/server/node_modules/zod/v4/classic/external.js +17 -0
- package/.output/server/node_modules/zod/v4/classic/from-json-schema.js +881 -0
- package/.output/server/node_modules/zod/v4/classic/in-out.js +36 -0
- package/.output/server/node_modules/zod/v4/classic/index.js +4 -0
- package/.output/server/node_modules/zod/v4/classic/iso.js +15 -0
- package/.output/server/node_modules/zod/v4/classic/package.json +7 -0
- package/.output/server/node_modules/zod/v4/classic/parse.js +16 -0
- package/.output/server/node_modules/zod/v4/classic/schemas.js +1535 -0
- package/.output/server/node_modules/zod/v4/core/api.js +1107 -0
- package/.output/server/node_modules/zod/v4/core/checks.js +516 -0
- package/.output/server/node_modules/zod/v4/core/compile.js +1866 -0
- package/.output/server/node_modules/zod/v4/core/core.js +141 -0
- package/.output/server/node_modules/zod/v4/core/doc.js +38 -0
- package/.output/server/node_modules/zod/v4/core/errors.js +267 -0
- package/.output/server/node_modules/zod/v4/core/index.js +19 -0
- package/.output/server/node_modules/zod/v4/core/json-schema-generator.js +99 -0
- package/.output/server/node_modules/zod/v4/core/json-schema-processors.js +843 -0
- package/.output/server/node_modules/zod/v4/core/json-schema.js +1 -0
- package/.output/server/node_modules/zod/v4/core/memoizer.js +311 -0
- package/.output/server/node_modules/zod/v4/core/package.json +7 -0
- package/.output/server/node_modules/zod/v4/core/parse.js +175 -0
- package/.output/server/node_modules/zod/v4/core/regexes.js +156 -0
- package/.output/server/node_modules/zod/v4/core/registries.js +51 -0
- package/.output/server/node_modules/zod/v4/core/schemas.js +2636 -0
- package/.output/server/node_modules/zod/v4/core/to-json-schema.js +651 -0
- package/.output/server/node_modules/zod/v4/core/util.js +873 -0
- package/.output/server/node_modules/zod/v4/core/versions.js +5 -0
- package/.output/server/node_modules/zod/v4/core/visit.js +169 -0
- package/.output/server/node_modules/zod/v4/index.js +4 -0
- package/.output/server/node_modules/zod/v4/locales/ar.js +111 -0
- package/.output/server/node_modules/zod/v4/locales/az.js +110 -0
- package/.output/server/node_modules/zod/v4/locales/be.js +168 -0
- package/.output/server/node_modules/zod/v4/locales/bg.js +125 -0
- package/.output/server/node_modules/zod/v4/locales/bn.js +113 -0
- package/.output/server/node_modules/zod/v4/locales/ca.js +112 -0
- package/.output/server/node_modules/zod/v4/locales/ckb.js +133 -0
- package/.output/server/node_modules/zod/v4/locales/cs.js +116 -0
- package/.output/server/node_modules/zod/v4/locales/da.js +120 -0
- package/.output/server/node_modules/zod/v4/locales/de.js +113 -0
- package/.output/server/node_modules/zod/v4/locales/el.js +112 -0
- package/.output/server/node_modules/zod/v4/locales/en.js +125 -0
- package/.output/server/node_modules/zod/v4/locales/eo.js +114 -0
- package/.output/server/node_modules/zod/v4/locales/es.js +136 -0
- package/.output/server/node_modules/zod/v4/locales/fa.js +119 -0
- package/.output/server/node_modules/zod/v4/locales/fi.js +117 -0
- package/.output/server/node_modules/zod/v4/locales/fr-CA.js +112 -0
- package/.output/server/node_modules/zod/v4/locales/fr.js +129 -0
- package/.output/server/node_modules/zod/v4/locales/gu.js +113 -0
- package/.output/server/node_modules/zod/v4/locales/he.js +221 -0
- package/.output/server/node_modules/zod/v4/locales/hi.js +111 -0
- package/.output/server/node_modules/zod/v4/locales/hr.js +126 -0
- package/.output/server/node_modules/zod/v4/locales/hu.js +113 -0
- package/.output/server/node_modules/zod/v4/locales/hy.js +158 -0
- package/.output/server/node_modules/zod/v4/locales/id.js +111 -0
- package/.output/server/node_modules/zod/v4/locales/index.js +63 -0
- package/.output/server/node_modules/zod/v4/locales/is.js +114 -0
- package/.output/server/node_modules/zod/v4/locales/it.js +113 -0
- package/.output/server/node_modules/zod/v4/locales/ja.js +112 -0
- package/.output/server/node_modules/zod/v4/locales/ka.js +117 -0
- package/.output/server/node_modules/zod/v4/locales/kh.js +5 -0
- package/.output/server/node_modules/zod/v4/locales/km.js +115 -0
- package/.output/server/node_modules/zod/v4/locales/kn.js +116 -0
- package/.output/server/node_modules/zod/v4/locales/ko.js +116 -0
- package/.output/server/node_modules/zod/v4/locales/lt.js +207 -0
- package/.output/server/node_modules/zod/v4/locales/mk.js +114 -0
- package/.output/server/node_modules/zod/v4/locales/ms.js +112 -0
- package/.output/server/node_modules/zod/v4/locales/ne.js +111 -0
- package/.output/server/node_modules/zod/v4/locales/nl.js +115 -0
- package/.output/server/node_modules/zod/v4/locales/nn.js +113 -0
- package/.output/server/node_modules/zod/v4/locales/no.js +113 -0
- package/.output/server/node_modules/zod/v4/locales/ota.js +114 -0
- package/.output/server/node_modules/zod/v4/locales/package.json +7 -0
- package/.output/server/node_modules/zod/v4/locales/pl.js +114 -0
- package/.output/server/node_modules/zod/v4/locales/ps.js +119 -0
- package/.output/server/node_modules/zod/v4/locales/pt-BR.js +143 -0
- package/.output/server/node_modules/zod/v4/locales/pt.js +142 -0
- package/.output/server/node_modules/zod/v4/locales/ro.js +122 -0
- package/.output/server/node_modules/zod/v4/locales/ru.js +168 -0
- package/.output/server/node_modules/zod/v4/locales/sk.js +116 -0
- package/.output/server/node_modules/zod/v4/locales/sl.js +114 -0
- package/.output/server/node_modules/zod/v4/locales/sv.js +115 -0
- package/.output/server/node_modules/zod/v4/locales/ta.js +115 -0
- package/.output/server/node_modules/zod/v4/locales/tg.js +117 -0
- package/.output/server/node_modules/zod/v4/locales/th.js +115 -0
- package/.output/server/node_modules/zod/v4/locales/tk.js +107 -0
- package/.output/server/node_modules/zod/v4/locales/tr.js +110 -0
- package/.output/server/node_modules/zod/v4/locales/ua.js +5 -0
- package/.output/server/node_modules/zod/v4/locales/uk.js +113 -0
- package/.output/server/node_modules/zod/v4/locales/ur.js +115 -0
- package/.output/server/node_modules/zod/v4/locales/uz.js +113 -0
- package/.output/server/node_modules/zod/v4/locales/vi.js +113 -0
- package/.output/server/node_modules/zod/v4/locales/yo.js +112 -0
- package/.output/server/node_modules/zod/v4/locales/zh-CN.js +114 -0
- package/.output/server/node_modules/zod/v4/locales/zh-TW.js +112 -0
- package/.output/server/node_modules/zod/v4/mini/checks.js +1 -0
- package/.output/server/node_modules/zod/v4/mini/coerce.js +22 -0
- package/.output/server/node_modules/zod/v4/mini/deep-partial.js +13 -0
- package/.output/server/node_modules/zod/v4/mini/external.js +16 -0
- package/.output/server/node_modules/zod/v4/mini/in-out.js +36 -0
- package/.output/server/node_modules/zod/v4/mini/iso.js +34 -0
- package/.output/server/node_modules/zod/v4/mini/package.json +7 -0
- package/.output/server/node_modules/zod/v4/mini/parse.js +1 -0
- package/.output/server/node_modules/zod/v4/mini/schemas.js +1002 -0
- package/.output/server/node_modules/zod/v4/package.json +7 -0
- package/.output/server/node_modules/zod/v4-mini/index.js +3 -0
- package/.output/server/node_modules/zod/v4-mini/package.json +7 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/Options.js +46 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/Refs.js +22 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/errorMessages.js +14 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/getRelativePath.js +8 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/index.js +40 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/package.json +1 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parseDef.js +62 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parseTypes.js +1 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/any.js +17 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/array.js +26 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js +49 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js +5 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js +4 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js +4 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/date.js +46 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/default.js +7 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js +7 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js +6 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js +52 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js +21 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/map.js +26 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js +16 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/never.js +11 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/null.js +10 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js +33 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/number.js +52 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/object.js +72 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js +21 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js +20 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js +4 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js +4 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/record.js +61 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/set.js +20 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/string.js +352 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js +32 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js +6 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/union.js +80 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js +4 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/selectParser.js +105 -0
- package/.output/server/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js +87 -0
- package/.output/server/node_modules/zod-to-json-schema/package.json +85 -0
- package/.output/server/package.json +64 -0
- package/README.md +226 -23
- package/bin/bantou.mjs +33 -0
- package/package.json +18 -8
- package/protocol/PROTOCOL.md +26 -0
- package/protocol/protocol.json +92 -0
- package/dist/cap.js +0 -7
- package/dist/cli.js +0 -27
- package/dist/config.js +0 -23
- package/dist/daemon.js +0 -23
- package/dist/session.js +0 -7
- package/dist/workspace.js +0 -8
|
@@ -0,0 +1,1000 @@
|
|
|
1
|
+
import { homedir, hostname, networkInterfaces } from 'node:os';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { E as ENV, D as DEFAULT_BROKER_CMD, P as POLL_INTERVAL_MS, B as BROKER_CMD_ENV, o as SESSION_TOKEN_ENV, S as SESSION_SOCKET_ENV, G as GRACE_MS_ENV, c as DEFAULT_GRACE_MS, i as HEARTBEAT_INTERVAL_MS, b as DEFAULT_DISCOVERY_TIMEOUT_MS, a as DEFAULT_DISCOVERY_PORT, d as DEFAULT_HTTP_PORT, L as LOCAL_HOSTS, I as INSTRUCTIONS, V as VERSION, H as HEALTH_ROUTE, u as recordSeen, v as describeMeta, f as DISCOVERY_KEY, h as DISCOVERY_REPLY_VALUE, g as DISCOVERY_PROBE_VALUE, e as DISCOVERY_BROADCAST_ADDR, q as createToolRegistry, w as getProtocol, x as unsetProtocol, y as setProtocol, z as listPeers, A as parseMeta, C as createProtocolState, J as planOutgoing, K as wireDecls, M as resendDefinitions, F as FALLBACK_ENV, R as RESOLVE_RETRY_MS } from './messenger-client.CfQVmH_Z.mjs';
|
|
4
|
+
import { connect } from 'node:net';
|
|
5
|
+
import { spawnSync, spawn } from 'node:child_process';
|
|
6
|
+
import { readFileSync, mkdirSync, openSync } from 'node:fs';
|
|
7
|
+
import { createSocket } from 'node:dgram';
|
|
8
|
+
|
|
9
|
+
function loadConfig(env) {
|
|
10
|
+
const rawHost = (env[ENV.HOST] ?? "").trim();
|
|
11
|
+
const stateDir = join(homedir(), ".agent-messenger");
|
|
12
|
+
return {
|
|
13
|
+
host: rawHost && rawHost.toLowerCase() !== "auto" ? rawHost : "",
|
|
14
|
+
port: parseInt(env[ENV.PORT] ?? String(DEFAULT_HTTP_PORT), 10),
|
|
15
|
+
token: env[ENV.TOKEN] ?? "",
|
|
16
|
+
name: env[ENV.NAME] ?? "",
|
|
17
|
+
stateDir,
|
|
18
|
+
configFile: env[ENV.CONFIG] ?? join(stateDir, "config.json"),
|
|
19
|
+
discoveryEnabled: (env[ENV.DISCOVERY] ?? "on").toLowerCase() !== "off",
|
|
20
|
+
discoveryPort: parseInt(env[ENV.DISCOVERY_PORT] ?? String(DEFAULT_DISCOVERY_PORT), 10),
|
|
21
|
+
discoveryAddr: env[ENV.DISCOVERY_ADDR] ?? "",
|
|
22
|
+
discoveryTimeoutMs: parseInt(env[ENV.DISCOVERY_TIMEOUT_MS] ?? String(DEFAULT_DISCOVERY_TIMEOUT_MS), 10),
|
|
23
|
+
heartbeatIntervalMs: parseInt(env[ENV.HEARTBEAT_MS] ?? String(HEARTBEAT_INTERVAL_MS), 10),
|
|
24
|
+
graceMs: parseInt(env[GRACE_MS_ENV] ?? String(DEFAULT_GRACE_MS), 10),
|
|
25
|
+
pollIntervalMs: POLL_INTERVAL_MS,
|
|
26
|
+
sessionSocket: env[SESSION_SOCKET_ENV] ?? "",
|
|
27
|
+
sessionToken: env[SESSION_TOKEN_ENV] ?? "",
|
|
28
|
+
delivery: env[ENV.DELIVERY] ?? "auto",
|
|
29
|
+
brokerCmd: env[BROKER_CMD_ENV] ?? DEFAULT_BROKER_CMD
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function isLocalHost(host) {
|
|
33
|
+
for (const h of LOCAL_HOSTS) if (h === host) return true;
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const LATEST_PROTOCOL_VERSION = "2025-11-25";
|
|
38
|
+
const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
|
|
39
|
+
function createStdioServer(opts) {
|
|
40
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
41
|
+
const onError = opts.onError ?? (() => {
|
|
42
|
+
});
|
|
43
|
+
const write = (msg) => new Promise((resolve) => {
|
|
44
|
+
const line = JSON.stringify(msg) + "\n";
|
|
45
|
+
const flushed = process.stdout.write(line, (err) => {
|
|
46
|
+
if (err) onError(err);
|
|
47
|
+
});
|
|
48
|
+
if (flushed) resolve();
|
|
49
|
+
else process.stdout.once("drain", () => resolve());
|
|
50
|
+
});
|
|
51
|
+
const sendResult = (id, result) => write({ jsonrpc: "2.0", id, result });
|
|
52
|
+
const sendError = (id, code, message, data) => write({ jsonrpc: "2.0", id, error: data === void 0 ? { code, message } : { code, message, data } });
|
|
53
|
+
handlers.set("initialize", (params) => {
|
|
54
|
+
const p = params ?? {};
|
|
55
|
+
const requested = typeof p.protocolVersion === "string" ? p.protocolVersion : "";
|
|
56
|
+
const protocolVersion = SUPPORTED_PROTOCOL_VERSIONS.includes(requested) ? requested : LATEST_PROTOCOL_VERSION;
|
|
57
|
+
if (opts.onInitialize) opts.onInitialize(params);
|
|
58
|
+
const result = {
|
|
59
|
+
protocolVersion,
|
|
60
|
+
capabilities: opts.capabilities,
|
|
61
|
+
serverInfo: opts.serverInfo
|
|
62
|
+
};
|
|
63
|
+
if (opts.instructions) result.instructions = opts.instructions;
|
|
64
|
+
return result;
|
|
65
|
+
});
|
|
66
|
+
handlers.set("ping", () => ({}));
|
|
67
|
+
const dispatchRequest = (req) => {
|
|
68
|
+
const handler = handlers.get(req.method);
|
|
69
|
+
if (!handler) {
|
|
70
|
+
sendError(req.id, -32601, "Method not found").catch(onError);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
Promise.resolve().then(() => handler(req.params)).then(
|
|
74
|
+
(result) => sendResult(req.id, result),
|
|
75
|
+
(err) => {
|
|
76
|
+
const e = err ?? {};
|
|
77
|
+
const code = typeof e.code === "number" && Number.isSafeInteger(e.code) ? e.code : -32603;
|
|
78
|
+
const message = typeof e.message === "string" ? e.message : "Internal error";
|
|
79
|
+
return sendError(req.id, code, message, e.data);
|
|
80
|
+
}
|
|
81
|
+
).catch(onError);
|
|
82
|
+
};
|
|
83
|
+
const handleLine = (raw) => {
|
|
84
|
+
const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
|
|
85
|
+
let msg;
|
|
86
|
+
try {
|
|
87
|
+
msg = JSON.parse(line);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
onError(e instanceof Error ? e : new Error(String(e)));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (typeof msg !== "object" || msg === null) {
|
|
93
|
+
onError(new Error("invalid JSON-RPC message"));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const m = msg;
|
|
97
|
+
if (m.jsonrpc !== "2.0") {
|
|
98
|
+
onError(new Error("invalid JSON-RPC message"));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const hasId = typeof m.id === "number" || typeof m.id === "string";
|
|
102
|
+
if (typeof m.method === "string") {
|
|
103
|
+
if (hasId) dispatchRequest(m);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
setRequestHandler(method, handler) {
|
|
109
|
+
handlers.set(method, handler);
|
|
110
|
+
},
|
|
111
|
+
notification(method, params) {
|
|
112
|
+
const n = { jsonrpc: "2.0", method, params };
|
|
113
|
+
return write(n);
|
|
114
|
+
},
|
|
115
|
+
connect() {
|
|
116
|
+
let buf = "";
|
|
117
|
+
process.stdin.setEncoding("utf8");
|
|
118
|
+
const read = async () => {
|
|
119
|
+
try {
|
|
120
|
+
for await (const chunk of process.stdin) {
|
|
121
|
+
buf += chunk;
|
|
122
|
+
let i;
|
|
123
|
+
while ((i = buf.indexOf("\n")) !== -1) {
|
|
124
|
+
const line = buf.slice(0, i);
|
|
125
|
+
buf = buf.slice(i + 1);
|
|
126
|
+
handleLine(line);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
onError(e instanceof Error ? e : new Error(String(e)));
|
|
131
|
+
}
|
|
132
|
+
if (opts.onClose) opts.onClose();
|
|
133
|
+
};
|
|
134
|
+
read().catch(onError);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function postToSession(socketPath, token, text) {
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
if (!socketPath) {
|
|
142
|
+
reject(new Error("CLAUDE_CODE_MESSAGING_SOCKET not set"));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const sock = connect(socketPath);
|
|
146
|
+
const timer = setTimeout(() => {
|
|
147
|
+
sock.destroy();
|
|
148
|
+
reject(new Error("session socket timeout"));
|
|
149
|
+
}, 5e3);
|
|
150
|
+
sock.on("connect", () => {
|
|
151
|
+
if (token) {
|
|
152
|
+
const auth = { type: "auth", token };
|
|
153
|
+
sock.write(JSON.stringify(auth) + "\n");
|
|
154
|
+
}
|
|
155
|
+
const user = { type: "user", message: { role: "user", content: text } };
|
|
156
|
+
sock.write(JSON.stringify(user) + "\n");
|
|
157
|
+
sock.end();
|
|
158
|
+
});
|
|
159
|
+
sock.on("error", (e) => {
|
|
160
|
+
clearTimeout(timer);
|
|
161
|
+
reject(e);
|
|
162
|
+
});
|
|
163
|
+
sock.on("close", () => {
|
|
164
|
+
clearTimeout(timer);
|
|
165
|
+
resolve();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const CAPABILITIES = {
|
|
171
|
+
experimental: { "claude/channel": {} },
|
|
172
|
+
tools: {}
|
|
173
|
+
};
|
|
174
|
+
function errorMessage$2(e) {
|
|
175
|
+
return e instanceof Error ? e.message : String(e);
|
|
176
|
+
}
|
|
177
|
+
function senderLabel(entry) {
|
|
178
|
+
return `${entry.from_name || entry.from_id}${entry.from_hostname ? `@${entry.from_hostname}` : ""}`;
|
|
179
|
+
}
|
|
180
|
+
function channelMeta(entry) {
|
|
181
|
+
return {
|
|
182
|
+
from_id: entry.from_id,
|
|
183
|
+
from_name: entry.from_name,
|
|
184
|
+
from_hostname: entry.from_hostname,
|
|
185
|
+
from_summary: entry.from_summary,
|
|
186
|
+
from_cwd: entry.from_cwd,
|
|
187
|
+
sent_at: entry.sent_at
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function createStdioHost(opts) {
|
|
191
|
+
const { cfg, log } = opts;
|
|
192
|
+
const mcp = createStdioServer({
|
|
193
|
+
serverInfo: { name: "agent-messenger", version: VERSION },
|
|
194
|
+
capabilities: CAPABILITIES,
|
|
195
|
+
instructions: INSTRUCTIONS,
|
|
196
|
+
onClose: opts.onClose
|
|
197
|
+
});
|
|
198
|
+
const notifier = {
|
|
199
|
+
/**
|
|
200
|
+
* body=pull: put one unread notice into the session (session socket → channel).
|
|
201
|
+
* The text stays unacknowledged at the broker until `check_messages`.
|
|
202
|
+
*/
|
|
203
|
+
async unread(latest, count) {
|
|
204
|
+
const who = senderLabel(latest);
|
|
205
|
+
const notice = `[agent-messenger] \u672A\u8AAD ${count} \u4EF6\uFF08from ${who}\uFF09\u3002check_messages \u3067\u53D7\u4FE1\u3057\u3066\u304F\u3060\u3055\u3044${latest.protocol_line ? `
|
|
206
|
+
${latest.protocol_line}` : ""}`;
|
|
207
|
+
let delivered = false;
|
|
208
|
+
const useSocket = cfg.delivery === "socket" || cfg.delivery === "auto" && cfg.sessionSocket;
|
|
209
|
+
if (useSocket) {
|
|
210
|
+
try {
|
|
211
|
+
await postToSession(cfg.sessionSocket, cfg.sessionToken, notice);
|
|
212
|
+
log(`Session socket unread notice OK (${count}) from ${who}`);
|
|
213
|
+
delivered = true;
|
|
214
|
+
} catch (e) {
|
|
215
|
+
log(`Session socket unread notice FAILED from ${latest.from_id}: ${errorMessage$2(e)} \u2014 trying channel`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (!delivered) {
|
|
219
|
+
try {
|
|
220
|
+
await mcp.notification("notifications/claude/channel", { content: notice, meta: channelMeta(latest) });
|
|
221
|
+
log(`Channel unread notice OK (${count}) from ${who}`);
|
|
222
|
+
delivered = true;
|
|
223
|
+
} catch (e) {
|
|
224
|
+
log(`Channel unread notice FAILED from ${latest.from_id}: ${errorMessage$2(e)}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return delivered;
|
|
228
|
+
},
|
|
229
|
+
/**
|
|
230
|
+
* mode=ping: put a one-line ping notice into the session (session socket →
|
|
231
|
+
* channel), with the subject (message text) when given.
|
|
232
|
+
*/
|
|
233
|
+
async ping(entry) {
|
|
234
|
+
const who = senderLabel(entry);
|
|
235
|
+
const notice = `[agent-messenger] ping\uFF08from ${who}\uFF09${entry.text ? `: ${entry.text}` : ""}`;
|
|
236
|
+
const useSocket = cfg.delivery === "socket" || cfg.delivery === "auto" && cfg.sessionSocket;
|
|
237
|
+
if (useSocket) {
|
|
238
|
+
try {
|
|
239
|
+
await postToSession(cfg.sessionSocket, cfg.sessionToken, notice);
|
|
240
|
+
log(`Session socket ping notice OK from ${who}`);
|
|
241
|
+
return;
|
|
242
|
+
} catch (e) {
|
|
243
|
+
log(`Session socket ping notice FAILED from ${entry.from_id}: ${errorMessage$2(e)} \u2014 trying channel`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
await mcp.notification("notifications/claude/channel", { content: notice, meta: channelMeta(entry) });
|
|
248
|
+
log(`Channel ping notice OK from ${who}`);
|
|
249
|
+
} catch (e) {
|
|
250
|
+
log(`Channel ping notice FAILED from ${entry.from_id}: ${errorMessage$2(e)}`);
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
/** mode=push: deliver the text (session socket → channel). true = delivered. */
|
|
254
|
+
async push(entry) {
|
|
255
|
+
const useSocket = cfg.delivery === "socket" || cfg.delivery === "auto" && cfg.sessionSocket;
|
|
256
|
+
if (useSocket) {
|
|
257
|
+
try {
|
|
258
|
+
const who = `${entry.from_name || entry.from_id}${entry.from_hostname ? `@${entry.from_hostname}` : ""}`;
|
|
259
|
+
const replyTo = entry.from_name || entry.from_id;
|
|
260
|
+
await postToSession(
|
|
261
|
+
cfg.sessionSocket,
|
|
262
|
+
cfg.sessionToken,
|
|
263
|
+
`[agent-messenger] message from ${who}
|
|
264
|
+
${entry.protocol_line ? `${entry.protocol_line}
|
|
265
|
+
` : ""}${entry.text}
|
|
266
|
+
|
|
267
|
+
(reply with the agent-messenger send_message tool, to: "${replyTo}")`
|
|
268
|
+
);
|
|
269
|
+
log(`Session socket delivery OK from ${who}: ${entry.text.slice(0, 80)}`);
|
|
270
|
+
return true;
|
|
271
|
+
} catch (e) {
|
|
272
|
+
log(`Session socket delivery FAILED from ${entry.from_id}: ${errorMessage$2(e)} \u2014 trying channel`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
try {
|
|
276
|
+
await mcp.notification("notifications/claude/channel", {
|
|
277
|
+
content: entry.protocol_line ? `${entry.protocol_line}
|
|
278
|
+
${entry.text}` : entry.text,
|
|
279
|
+
meta: {
|
|
280
|
+
from_id: entry.from_id,
|
|
281
|
+
from_name: entry.from_name,
|
|
282
|
+
from_hostname: entry.from_hostname,
|
|
283
|
+
from_summary: entry.from_summary,
|
|
284
|
+
from_cwd: entry.from_cwd,
|
|
285
|
+
sent_at: entry.sent_at
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
log(`Channel push OK from ${entry.from_name || entry.from_id}: ${entry.text.slice(0, 80)}`);
|
|
289
|
+
return true;
|
|
290
|
+
} catch (e) {
|
|
291
|
+
log(`Channel push FAILED from ${entry.from_id}: ${errorMessage$2(e)}`);
|
|
292
|
+
}
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
return {
|
|
297
|
+
notifier,
|
|
298
|
+
attach(registry) {
|
|
299
|
+
mcp.setRequestHandler("tools/list", () => ({ tools: registry.list() }));
|
|
300
|
+
mcp.setRequestHandler("tools/call", async (params) => {
|
|
301
|
+
const p = params ?? {};
|
|
302
|
+
return registry.call(p.name ?? "", p.arguments ?? {});
|
|
303
|
+
});
|
|
304
|
+
},
|
|
305
|
+
connect() {
|
|
306
|
+
mcp.connect();
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function httpRequest(method, url, headers, body, timeoutMs) {
|
|
312
|
+
return new Promise((resolve, reject) => {
|
|
313
|
+
let u;
|
|
314
|
+
try {
|
|
315
|
+
u = new URL(url);
|
|
316
|
+
} catch (e) {
|
|
317
|
+
reject(e instanceof Error ? e : new Error(String(e)));
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (u.protocol !== "http:") {
|
|
321
|
+
reject(new Error(`unsupported protocol: ${u.protocol}`));
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const host = u.hostname;
|
|
325
|
+
const port = u.port ? Number(u.port) : 80;
|
|
326
|
+
const path = `${u.pathname}${u.search}`;
|
|
327
|
+
const chunks = [];
|
|
328
|
+
let settled = false;
|
|
329
|
+
const sock = connect(port, host);
|
|
330
|
+
const finish = (err) => {
|
|
331
|
+
if (settled) return;
|
|
332
|
+
settled = true;
|
|
333
|
+
clearTimeout(timer);
|
|
334
|
+
if (err) {
|
|
335
|
+
sock.destroy();
|
|
336
|
+
reject(err);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
try {
|
|
340
|
+
resolve(parseResponse(Buffer.concat(chunks)));
|
|
341
|
+
} catch (e) {
|
|
342
|
+
reject(e instanceof Error ? e : new Error(String(e)));
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
const timer = setTimeout(() => finish(new Error(`request timeout after ${timeoutMs}ms`)), timeoutMs);
|
|
346
|
+
sock.on("connect", () => {
|
|
347
|
+
const lines = [
|
|
348
|
+
`${method} ${path} HTTP/1.1`,
|
|
349
|
+
`Host: ${host}:${port}`,
|
|
350
|
+
"Connection: close",
|
|
351
|
+
`Content-Length: ${Buffer.byteLength(body)}`
|
|
352
|
+
];
|
|
353
|
+
for (const k of Object.keys(headers)) lines.push(`${k}: ${headers[k]}`);
|
|
354
|
+
sock.write(lines.join("\r\n") + "\r\n\r\n" + body);
|
|
355
|
+
});
|
|
356
|
+
sock.on("data", (d) => {
|
|
357
|
+
chunks.push(d);
|
|
358
|
+
});
|
|
359
|
+
sock.on("error", (e) => finish(e));
|
|
360
|
+
sock.on("close", () => finish(null));
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
function parseResponse(raw) {
|
|
364
|
+
const sep = raw.indexOf("\r\n\r\n");
|
|
365
|
+
if (sep === -1) throw new Error("malformed HTTP response (no header terminator)");
|
|
366
|
+
const head = raw.subarray(0, sep).toString("utf8");
|
|
367
|
+
const headLines = head.split("\r\n");
|
|
368
|
+
const status = Number(headLines[0].split(" ")[1]);
|
|
369
|
+
if (!Number.isFinite(status)) throw new Error(`malformed HTTP status line: ${headLines[0]}`);
|
|
370
|
+
const h = {};
|
|
371
|
+
for (let i = 1; i < headLines.length; i++) {
|
|
372
|
+
const c = headLines[i].indexOf(":");
|
|
373
|
+
if (c === -1) continue;
|
|
374
|
+
h[headLines[i].slice(0, c).trim().toLowerCase()] = headLines[i].slice(c + 1).trim();
|
|
375
|
+
}
|
|
376
|
+
let bodyBuf = raw.subarray(sep + 4);
|
|
377
|
+
if ((h["transfer-encoding"] ?? "").toLowerCase() === "chunked") {
|
|
378
|
+
bodyBuf = dechunk(bodyBuf);
|
|
379
|
+
} else if (h["content-length"] !== void 0) {
|
|
380
|
+
bodyBuf = bodyBuf.subarray(0, Number(h["content-length"]));
|
|
381
|
+
}
|
|
382
|
+
return { status, ok: status >= 200 && status < 300, body: bodyBuf.toString("utf8") };
|
|
383
|
+
}
|
|
384
|
+
function dechunk(buf) {
|
|
385
|
+
const out = [];
|
|
386
|
+
let pos = 0;
|
|
387
|
+
for (; ; ) {
|
|
388
|
+
const eol = buf.indexOf("\r\n", pos);
|
|
389
|
+
if (eol === -1) break;
|
|
390
|
+
const size = parseInt(buf.subarray(pos, eol).toString("ascii").split(";")[0], 16);
|
|
391
|
+
if (!Number.isFinite(size) || size === 0) break;
|
|
392
|
+
out.push(buf.subarray(eol + 2, eol + 2 + size));
|
|
393
|
+
pos = eol + 2 + size + 2;
|
|
394
|
+
}
|
|
395
|
+
return Buffer.concat(out);
|
|
396
|
+
}
|
|
397
|
+
function createBrokerClient(token) {
|
|
398
|
+
let brokerUrl = "";
|
|
399
|
+
return {
|
|
400
|
+
setUrl(url) {
|
|
401
|
+
brokerUrl = url.replace(/\/$/, "");
|
|
402
|
+
},
|
|
403
|
+
getUrl() {
|
|
404
|
+
return brokerUrl;
|
|
405
|
+
},
|
|
406
|
+
async post(path, body, opts = {}) {
|
|
407
|
+
if (!brokerUrl) throw new Error("broker not resolved");
|
|
408
|
+
const headers = { "Content-Type": "application/json" };
|
|
409
|
+
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
410
|
+
const res = await httpRequest("POST", `${brokerUrl}${path}`, headers, JSON.stringify(body ?? {}), opts.timeoutMs ?? 5e3);
|
|
411
|
+
if (!res.ok) {
|
|
412
|
+
throw new Error(`Broker error (${path}): ${res.status} ${res.body}`);
|
|
413
|
+
}
|
|
414
|
+
return JSON.parse(res.body);
|
|
415
|
+
},
|
|
416
|
+
async health(url = brokerUrl, timeoutMs = 2e3) {
|
|
417
|
+
if (!url) return null;
|
|
418
|
+
try {
|
|
419
|
+
const res = await httpRequest("GET", `${url}${HEALTH_ROUTE}`, {}, "", timeoutMs);
|
|
420
|
+
if (!res.ok) return null;
|
|
421
|
+
return JSON.parse(res.body);
|
|
422
|
+
} catch {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const MAX_BUFFER = 200;
|
|
430
|
+
function errorMessage$1(e) {
|
|
431
|
+
return e instanceof Error ? e.message : String(e);
|
|
432
|
+
}
|
|
433
|
+
function createInbox(opts) {
|
|
434
|
+
const { broker, peer, log, notifier, protocols } = opts;
|
|
435
|
+
const localBuffer = [];
|
|
436
|
+
const notifiedIds = /* @__PURE__ */ new Set();
|
|
437
|
+
const handlers = [];
|
|
438
|
+
let dispatching = false;
|
|
439
|
+
let stopped = false;
|
|
440
|
+
async function lookupSender(fromId) {
|
|
441
|
+
try {
|
|
442
|
+
const peers = await broker.post("/list-peers", { scope: "all", cwd: peer.cwd, git_root: peer.gitRoot });
|
|
443
|
+
return peers.find((p) => p.id === fromId) ?? null;
|
|
444
|
+
} catch {
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
async function acknowledge(messageId) {
|
|
449
|
+
await broker.post("/acknowledge-messages", { id: peer.id, message_ids: [messageId] }).catch(() => {
|
|
450
|
+
});
|
|
451
|
+
const i = localBuffer.findIndex((b) => b.id === messageId);
|
|
452
|
+
if (i !== -1) localBuffer.splice(i, 1);
|
|
453
|
+
}
|
|
454
|
+
function markProtocol(entry) {
|
|
455
|
+
if (!protocols || !entry.meta) return;
|
|
456
|
+
recordSeen(protocols, entry.from_id, entry.from_name, entry.meta);
|
|
457
|
+
entry.protocol_line = describeMeta(protocols, entry.meta);
|
|
458
|
+
}
|
|
459
|
+
function pushBuffer(entry) {
|
|
460
|
+
markProtocol(entry);
|
|
461
|
+
localBuffer.push(entry);
|
|
462
|
+
if (localBuffer.length > MAX_BUFFER) localBuffer.splice(0, localBuffer.length - MAX_BUFFER);
|
|
463
|
+
}
|
|
464
|
+
async function notifyUnread() {
|
|
465
|
+
if (!notifier) return;
|
|
466
|
+
if (localBuffer.length === 0) return;
|
|
467
|
+
if (!localBuffer.some((b) => !notifiedIds.has(b.id))) return;
|
|
468
|
+
const latest = localBuffer[localBuffer.length - 1];
|
|
469
|
+
const delivered = await notifier.unread(latest, localBuffer.length);
|
|
470
|
+
if (delivered) for (const b of localBuffer) notifiedIds.add(b.id);
|
|
471
|
+
}
|
|
472
|
+
async function dispatch() {
|
|
473
|
+
if (dispatching) return;
|
|
474
|
+
dispatching = true;
|
|
475
|
+
try {
|
|
476
|
+
for (const entry of localBuffer.slice()) {
|
|
477
|
+
if (stopped || handlers.length === 0) break;
|
|
478
|
+
try {
|
|
479
|
+
for (const h of handlers.slice()) await h(entry);
|
|
480
|
+
} catch (e) {
|
|
481
|
+
log(`Message handler failed for ${entry.id}: ${errorMessage$1(e)} \u2014 will retry`);
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
if (stopped) break;
|
|
485
|
+
await acknowledge(entry.id);
|
|
486
|
+
}
|
|
487
|
+
} finally {
|
|
488
|
+
dispatching = false;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
async function poll(push) {
|
|
492
|
+
if (stopped || !peer.id) return;
|
|
493
|
+
const result = await broker.post("/poll-messages", { id: peer.id });
|
|
494
|
+
for (const msg of result.messages) {
|
|
495
|
+
if (stopped) return;
|
|
496
|
+
const sender = await lookupSender(msg.from_id);
|
|
497
|
+
const entry = {
|
|
498
|
+
...msg,
|
|
499
|
+
from_name: msg.from_name || sender?.name || "",
|
|
500
|
+
from_hostname: sender?.hostname ?? "",
|
|
501
|
+
from_summary: sender?.summary ?? "",
|
|
502
|
+
from_cwd: sender?.cwd ?? ""
|
|
503
|
+
};
|
|
504
|
+
if (handlers.length > 0) {
|
|
505
|
+
pushBuffer(entry);
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
if (msg.mode === "ping") {
|
|
509
|
+
if (notifier) await notifier.ping(entry);
|
|
510
|
+
await acknowledge(msg.id);
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
pushBuffer(entry);
|
|
514
|
+
if (!push || msg.mode !== "push") continue;
|
|
515
|
+
if (notifier && await notifier.push(entry)) await acknowledge(msg.id);
|
|
516
|
+
}
|
|
517
|
+
if (handlers.length > 0) await dispatch();
|
|
518
|
+
else if (push) await notifyUnread();
|
|
519
|
+
}
|
|
520
|
+
async function checkMessages() {
|
|
521
|
+
await poll(false);
|
|
522
|
+
const buffered = await broker.post("/get-buffered-messages", { id: peer.id });
|
|
523
|
+
for (const m of buffered.messages) {
|
|
524
|
+
if (m.mode === "ping") {
|
|
525
|
+
await acknowledge(m.id);
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
if (!localBuffer.some((b) => b.id === m.id)) {
|
|
529
|
+
const entry = { ...m, from_hostname: "", from_summary: "", from_cwd: "" };
|
|
530
|
+
markProtocol(entry);
|
|
531
|
+
localBuffer.push(entry);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
for (const b of localBuffer.slice()) {
|
|
535
|
+
if (b.mode === "ping") await acknowledge(b.id);
|
|
536
|
+
}
|
|
537
|
+
if (localBuffer.length === 0) return [];
|
|
538
|
+
const ids = localBuffer.map((m) => m.id);
|
|
539
|
+
await broker.post("/acknowledge-messages", { id: peer.id, message_ids: ids }).catch(() => {
|
|
540
|
+
});
|
|
541
|
+
const out = localBuffer.slice();
|
|
542
|
+
localBuffer.length = 0;
|
|
543
|
+
notifiedIds.clear();
|
|
544
|
+
return out;
|
|
545
|
+
}
|
|
546
|
+
function onMessage(handler) {
|
|
547
|
+
handlers.push(handler);
|
|
548
|
+
return () => {
|
|
549
|
+
const i = handlers.indexOf(handler);
|
|
550
|
+
if (i !== -1) handlers.splice(i, 1);
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
function stop() {
|
|
554
|
+
stopped = true;
|
|
555
|
+
}
|
|
556
|
+
return { poll, checkMessages, onMessage, stop };
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
function createPeerState(init) {
|
|
560
|
+
return {
|
|
561
|
+
id: null,
|
|
562
|
+
name: init.name,
|
|
563
|
+
summary: init.summary ?? "",
|
|
564
|
+
hostname: init.hostname ?? hostname(),
|
|
565
|
+
cwd: init.cwd ?? process.cwd(),
|
|
566
|
+
gitRoot: null,
|
|
567
|
+
tty: null
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
function git(args, cwd) {
|
|
571
|
+
const r = spawnSync("git", args, { cwd, stdio: ["ignore", "pipe", "ignore"] });
|
|
572
|
+
return r.status === 0 ? r.stdout.toString().trim() : null;
|
|
573
|
+
}
|
|
574
|
+
function detectGitRoot(cwd) {
|
|
575
|
+
return git(["rev-parse", "--show-toplevel"], cwd);
|
|
576
|
+
}
|
|
577
|
+
function detectTty() {
|
|
578
|
+
try {
|
|
579
|
+
const r = spawnSync("ps", ["-o", "tty=", "-p", String(process.ppid)]);
|
|
580
|
+
const tty = r.stdout.toString().trim();
|
|
581
|
+
if (tty && tty !== "?" && tty !== "??") return tty;
|
|
582
|
+
} catch {
|
|
583
|
+
}
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
async function registerPeer(broker, peer, log, protocols) {
|
|
587
|
+
const reg = await broker.post("/register", {
|
|
588
|
+
pid: process.pid,
|
|
589
|
+
hostname: peer.hostname,
|
|
590
|
+
cwd: peer.cwd,
|
|
591
|
+
git_root: peer.gitRoot,
|
|
592
|
+
tty: peer.tty,
|
|
593
|
+
summary: peer.summary,
|
|
594
|
+
name: peer.name,
|
|
595
|
+
...protocols === void 0 ? {} : { protocols }
|
|
596
|
+
});
|
|
597
|
+
peer.id = reg.id;
|
|
598
|
+
log(`Registered as peer ${peer.id}`);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
async function resolveBroker(cfg, broker, log, brokers) {
|
|
602
|
+
const done = (r) => {
|
|
603
|
+
broker.setUrl(r.url);
|
|
604
|
+
return r;
|
|
605
|
+
};
|
|
606
|
+
if (cfg.host) {
|
|
607
|
+
const url2 = `http://${cfg.host}:${cfg.port}`;
|
|
608
|
+
return done({ url: url2, host: cfg.host, source: "env", isLocal: isLocalHost(cfg.host) });
|
|
609
|
+
}
|
|
610
|
+
const configured = brokers === void 0 ? readConfigBrokers(cfg) : brokers.map((s) => normalizeUrl(s, cfg.port));
|
|
611
|
+
const configSource = brokers === void 0 ? `config ${cfg.configFile}` : "config (options)";
|
|
612
|
+
for (const url2 of configured) {
|
|
613
|
+
if (await broker.health(url2, 1500)) {
|
|
614
|
+
const host = hostOf(url2);
|
|
615
|
+
return done({ url: url2, host, source: configSource, isLocal: isLocalHost(host) });
|
|
616
|
+
}
|
|
617
|
+
log(`config broker not reachable: ${url2}`);
|
|
618
|
+
}
|
|
619
|
+
if (cfg.discoveryEnabled) {
|
|
620
|
+
const found = await discoverBrokers(cfg);
|
|
621
|
+
if (found.length) {
|
|
622
|
+
const b = found[0];
|
|
623
|
+
return done({ url: b.url, host: b.host, source: `discovery (${b.id})`, isLocal: isLocalHost(b.host) });
|
|
624
|
+
}
|
|
625
|
+
log("discovery: no broker answered");
|
|
626
|
+
}
|
|
627
|
+
const url = `http://127.0.0.1:${cfg.port}`;
|
|
628
|
+
return done({ url, host: "127.0.0.1", source: "local fallback", isLocal: true });
|
|
629
|
+
}
|
|
630
|
+
function hostOf(url) {
|
|
631
|
+
try {
|
|
632
|
+
return new URL(url).hostname;
|
|
633
|
+
} catch {
|
|
634
|
+
return url;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
function readConfigBrokers(cfg) {
|
|
638
|
+
try {
|
|
639
|
+
const parsed = JSON.parse(readFileSync(cfg.configFile, "utf8"));
|
|
640
|
+
const list = Array.isArray(parsed.brokers) ? parsed.brokers : parsed.broker ? [parsed.broker] : [];
|
|
641
|
+
const out = [];
|
|
642
|
+
for (const s of list) {
|
|
643
|
+
if (typeof s === "string" && s.trim()) out.push(normalizeUrl(s, cfg.port));
|
|
644
|
+
}
|
|
645
|
+
return out;
|
|
646
|
+
} catch {
|
|
647
|
+
return [];
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
function normalizeUrl(s, defaultPort) {
|
|
651
|
+
s = s.trim();
|
|
652
|
+
if (!/^https?:\/\//.test(s)) s = `http://${s}`;
|
|
653
|
+
const u = new URL(s);
|
|
654
|
+
if (!u.port) u.port = String(defaultPort);
|
|
655
|
+
return u.origin;
|
|
656
|
+
}
|
|
657
|
+
function probeTargets(cfg) {
|
|
658
|
+
if (cfg.discoveryAddr) return [cfg.discoveryAddr];
|
|
659
|
+
const targets = /* @__PURE__ */ new Set([DISCOVERY_BROADCAST_ADDR]);
|
|
660
|
+
const ifaces = networkInterfaces();
|
|
661
|
+
for (const name of Object.keys(ifaces)) {
|
|
662
|
+
const list = ifaces[name] ?? [];
|
|
663
|
+
for (const i of list) {
|
|
664
|
+
if (i.family !== "IPv4" || i.internal || !i.netmask) continue;
|
|
665
|
+
const ip = i.address.split(".").map(Number);
|
|
666
|
+
const mask = i.netmask.split(".").map(Number);
|
|
667
|
+
const parts = [];
|
|
668
|
+
for (let k = 0; k < 4; k++) parts.push(String(ip[k] & mask[k] | ~mask[k] & 255));
|
|
669
|
+
targets.add(parts.join("."));
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return [...targets];
|
|
673
|
+
}
|
|
674
|
+
function discoverBrokers(cfg, timeoutMs = cfg.discoveryTimeoutMs) {
|
|
675
|
+
return new Promise((resolve) => {
|
|
676
|
+
const sock = createSocket({ type: "udp4", reuseAddr: true });
|
|
677
|
+
const found = /* @__PURE__ */ new Map();
|
|
678
|
+
let settled = false;
|
|
679
|
+
const finish = () => {
|
|
680
|
+
if (settled) return;
|
|
681
|
+
settled = true;
|
|
682
|
+
clearTimeout(timer);
|
|
683
|
+
try {
|
|
684
|
+
sock.close();
|
|
685
|
+
} catch {
|
|
686
|
+
}
|
|
687
|
+
resolve([...found.values()].sort((a, b) => Number(a.fallback) - Number(b.fallback)));
|
|
688
|
+
};
|
|
689
|
+
const timer = setTimeout(finish, timeoutMs);
|
|
690
|
+
sock.on("error", finish);
|
|
691
|
+
sock.on("message", (msg, rinfo) => {
|
|
692
|
+
try {
|
|
693
|
+
const m = JSON.parse(msg.toString());
|
|
694
|
+
if (m[DISCOVERY_KEY] !== DISCOVERY_REPLY_VALUE || !m.port) return;
|
|
695
|
+
const host = rinfo.address;
|
|
696
|
+
const url = `http://${host}:${m.port}`;
|
|
697
|
+
if (!found.has(url)) {
|
|
698
|
+
found.set(url, { url, host, port: m.port, id: m.id ?? host, version: m.version ?? "", fallback: m.fallback === true });
|
|
699
|
+
}
|
|
700
|
+
} catch {
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
sock.bind(0, () => {
|
|
704
|
+
try {
|
|
705
|
+
sock.setBroadcast(true);
|
|
706
|
+
} catch {
|
|
707
|
+
}
|
|
708
|
+
const probe = Buffer.from(JSON.stringify({ [DISCOVERY_KEY]: DISCOVERY_PROBE_VALUE }));
|
|
709
|
+
for (const t of probeTargets(cfg)) {
|
|
710
|
+
sock.send(probe, cfg.discoveryPort, t, () => {
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function errorMessage(e) {
|
|
718
|
+
return e instanceof Error ? e.message : String(e);
|
|
719
|
+
}
|
|
720
|
+
async function ensureBroker(cfg, env, broker, resolved, log, autoStart) {
|
|
721
|
+
if (await broker.health()) {
|
|
722
|
+
log("Broker already running");
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
if (!resolved.isLocal) {
|
|
726
|
+
throw new Error(
|
|
727
|
+
`Remote broker at ${broker.getUrl()} is not reachable. Start it on the broker host: agent-messenger broker`
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
if (!autoStart) {
|
|
731
|
+
throw new Error(`Local broker at ${broker.getUrl()} is not reachable (autoStartBroker is off)`);
|
|
732
|
+
}
|
|
733
|
+
log("Starting local broker daemon...");
|
|
734
|
+
mkdirSync(cfg.stateDir, { recursive: true });
|
|
735
|
+
const out = openSync(`${cfg.stateDir}/broker.log`, "a");
|
|
736
|
+
const argv = cfg.brokerCmd.trim().split(/\s+/);
|
|
737
|
+
const cmd = argv[0];
|
|
738
|
+
const args = argv.slice(1);
|
|
739
|
+
const proc = spawn(cmd, args, {
|
|
740
|
+
stdio: ["ignore", out, out],
|
|
741
|
+
detached: true,
|
|
742
|
+
// FALLBACK_ENV: this broker is a stop-gap; it hands over to a real broker once one shows up and exits
|
|
743
|
+
env: { ...env, AGENT_MESSENGER_PORT: new URL(broker.getUrl()).port, [FALLBACK_ENV]: "1" }
|
|
744
|
+
});
|
|
745
|
+
proc.unref();
|
|
746
|
+
for (let i = 0; i < 30; i++) {
|
|
747
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
748
|
+
if (await broker.health()) {
|
|
749
|
+
log("Broker started");
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
throw new Error("Failed to start broker daemon after 6 seconds");
|
|
754
|
+
}
|
|
755
|
+
function createMessengerClient(options = {}) {
|
|
756
|
+
const env = options.env ?? process.env;
|
|
757
|
+
const log = options.log ?? ((msg) => console.error(`[agent-messenger] ${msg}`));
|
|
758
|
+
const cfg = options.config ?? loadConfig(env);
|
|
759
|
+
const autoStart = options.autoStartBroker === true;
|
|
760
|
+
const notifier = options.notifier;
|
|
761
|
+
const broker = createBrokerClient(cfg.token);
|
|
762
|
+
const peer = createPeerState({ name: options.name ?? cfg.name, summary: options.summary });
|
|
763
|
+
const protocols = createProtocolState();
|
|
764
|
+
const inbox = createInbox({ broker, peer, log, notifier, protocols });
|
|
765
|
+
const registry = createToolRegistry({ broker, peer, inbox, protocols });
|
|
766
|
+
const protocolEnv = { broker, peer, protocols };
|
|
767
|
+
let connectPromise = null;
|
|
768
|
+
let closePromise = null;
|
|
769
|
+
let closed = false;
|
|
770
|
+
let pollTimer = null;
|
|
771
|
+
let recoverTimer = null;
|
|
772
|
+
let heartbeatTimer = null;
|
|
773
|
+
let failSince = null;
|
|
774
|
+
let lastResolveAttempt = 0;
|
|
775
|
+
let resolving = false;
|
|
776
|
+
let inflightReresolve = null;
|
|
777
|
+
function noteFailure() {
|
|
778
|
+
if (failSince !== null) return;
|
|
779
|
+
failSince = Date.now();
|
|
780
|
+
log(`Broker ${broker.getUrl()} unreachable \u2014 retrying it for ${cfg.graceMs} ms before re-resolving`);
|
|
781
|
+
}
|
|
782
|
+
function noteOk() {
|
|
783
|
+
if (failSince === null) return;
|
|
784
|
+
failSince = null;
|
|
785
|
+
log(`Broker ${broker.getUrl()} reachable again`);
|
|
786
|
+
}
|
|
787
|
+
async function doReresolve(reason) {
|
|
788
|
+
resolving = true;
|
|
789
|
+
lastResolveAttempt = Date.now();
|
|
790
|
+
try {
|
|
791
|
+
const prev = broker.getUrl();
|
|
792
|
+
log(`Re-resolving broker (${reason})`);
|
|
793
|
+
const r = await resolveBroker(cfg, broker, log, options.brokers);
|
|
794
|
+
await ensureBroker(cfg, env, broker, r, log, autoStart);
|
|
795
|
+
if (closed) return;
|
|
796
|
+
await registerPeer(broker, peer, log, wireDecls(protocols));
|
|
797
|
+
await resendDefinitions(protocolEnv, log);
|
|
798
|
+
log(`broker=${broker.getUrl()} (${r.isLocal ? "local" : "remote"}, via ${r.source})${prev === broker.getUrl() ? "" : ` \u2014 was ${prev}`}`);
|
|
799
|
+
failSince = null;
|
|
800
|
+
} catch (e) {
|
|
801
|
+
log(`Re-resolve failed: ${errorMessage(e)}`);
|
|
802
|
+
noteFailure();
|
|
803
|
+
} finally {
|
|
804
|
+
resolving = false;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
async function reresolve(reason) {
|
|
808
|
+
if (resolving || closed) return;
|
|
809
|
+
const p = doReresolve(reason);
|
|
810
|
+
inflightReresolve = p;
|
|
811
|
+
try {
|
|
812
|
+
await p;
|
|
813
|
+
} finally {
|
|
814
|
+
if (inflightReresolve === p) inflightReresolve = null;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
async function pollLoop() {
|
|
818
|
+
if (resolving || closed) return;
|
|
819
|
+
try {
|
|
820
|
+
await inbox.poll(true);
|
|
821
|
+
noteOk();
|
|
822
|
+
} catch (e) {
|
|
823
|
+
log(`Poll error: ${errorMessage(e)}`);
|
|
824
|
+
noteFailure();
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
async function recoverLoop() {
|
|
828
|
+
if (failSince === null || resolving || closed) return;
|
|
829
|
+
const now = Date.now();
|
|
830
|
+
if (now - failSince < cfg.graceMs || now - lastResolveAttempt < RESOLVE_RETRY_MS) return;
|
|
831
|
+
await reresolve("connection failure");
|
|
832
|
+
}
|
|
833
|
+
async function heartbeat() {
|
|
834
|
+
if (resolving || closed) return;
|
|
835
|
+
try {
|
|
836
|
+
const decls = wireDecls(protocols);
|
|
837
|
+
const r = await broker.post("/heartbeat", decls === void 0 ? { id: peer.id } : { id: peer.id, protocols: decls });
|
|
838
|
+
if (r && r.ok === false) {
|
|
839
|
+
log(`Heartbeat rejected (${r.error}) \u2014 re-registering`);
|
|
840
|
+
await reresolve("heartbeat rejected");
|
|
841
|
+
} else {
|
|
842
|
+
noteOk();
|
|
843
|
+
if (r && r.ok && Array.isArray(r.resend) && r.resend.length > 0) await resendDefinitions(protocolEnv, log, r.resend);
|
|
844
|
+
}
|
|
845
|
+
} catch {
|
|
846
|
+
noteFailure();
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
async function doConnect() {
|
|
850
|
+
const resolved = await resolveBroker(cfg, broker, log, options.brokers);
|
|
851
|
+
await ensureBroker(cfg, env, broker, resolved, log, autoStart);
|
|
852
|
+
peer.gitRoot = detectGitRoot(peer.cwd);
|
|
853
|
+
peer.tty = detectTty();
|
|
854
|
+
log(`v${VERSION} host=${peer.hostname} broker=${broker.getUrl()} (${resolved.isLocal ? "local" : "remote"}, via ${resolved.source})`);
|
|
855
|
+
log(`cwd=${peer.cwd} git_root=${peer.gitRoot ?? "(none)"} tty=${peer.tty ?? "(unknown)"} name=${peer.name || "(unset)"}`);
|
|
856
|
+
if (notifier) log(`delivery=${cfg.delivery} session_socket=${cfg.sessionSocket || "(none)"}`);
|
|
857
|
+
await registerPeer(broker, peer, log, wireDecls(protocols));
|
|
858
|
+
if (closed) return;
|
|
859
|
+
pollTimer = setInterval(pollLoop, cfg.pollIntervalMs);
|
|
860
|
+
recoverTimer = setInterval(recoverLoop, cfg.pollIntervalMs);
|
|
861
|
+
heartbeatTimer = setInterval(heartbeat, cfg.heartbeatIntervalMs);
|
|
862
|
+
}
|
|
863
|
+
function connect() {
|
|
864
|
+
if (closed) return Promise.reject(new Error("client closed"));
|
|
865
|
+
if (connectPromise) return connectPromise;
|
|
866
|
+
const p = doConnect();
|
|
867
|
+
connectPromise = p;
|
|
868
|
+
p.catch(() => {
|
|
869
|
+
if (connectPromise === p) connectPromise = null;
|
|
870
|
+
});
|
|
871
|
+
return p;
|
|
872
|
+
}
|
|
873
|
+
async function doClose(cp) {
|
|
874
|
+
closed = true;
|
|
875
|
+
inbox.stop();
|
|
876
|
+
try {
|
|
877
|
+
await cp;
|
|
878
|
+
} catch {
|
|
879
|
+
}
|
|
880
|
+
if (pollTimer) clearInterval(pollTimer);
|
|
881
|
+
if (heartbeatTimer) clearInterval(heartbeatTimer);
|
|
882
|
+
if (recoverTimer) clearInterval(recoverTimer);
|
|
883
|
+
pollTimer = null;
|
|
884
|
+
heartbeatTimer = null;
|
|
885
|
+
recoverTimer = null;
|
|
886
|
+
if (inflightReresolve) await inflightReresolve.catch(() => {
|
|
887
|
+
});
|
|
888
|
+
if (!peer.id) return;
|
|
889
|
+
try {
|
|
890
|
+
await broker.post("/unregister", { id: peer.id });
|
|
891
|
+
log("Unregistered from broker");
|
|
892
|
+
} catch {
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
function close() {
|
|
896
|
+
if (closePromise) return closePromise;
|
|
897
|
+
if (!connectPromise) return Promise.resolve();
|
|
898
|
+
closePromise = doClose(connectPromise);
|
|
899
|
+
return closePromise;
|
|
900
|
+
}
|
|
901
|
+
function requireRegistered() {
|
|
902
|
+
if (!peer.id) throw new Error("Not registered with broker yet");
|
|
903
|
+
return peer.id;
|
|
904
|
+
}
|
|
905
|
+
async function sendMode(to, text, mode, meta) {
|
|
906
|
+
const id = requireRegistered();
|
|
907
|
+
const plan = mode === "ping" ? { text, meta, warning: void 0 } : planOutgoing(protocols, to, text, meta);
|
|
908
|
+
const r = await broker.post("/send-message", {
|
|
909
|
+
from_id: id,
|
|
910
|
+
from_name: peer.name,
|
|
911
|
+
to,
|
|
912
|
+
text: plan.text,
|
|
913
|
+
mode,
|
|
914
|
+
...plan.meta === void 0 ? {} : { meta: plan.meta }
|
|
915
|
+
});
|
|
916
|
+
if (!r.ok) throw new Error(`Failed to send: ${r.error}`);
|
|
917
|
+
const out = { to_id: r.to_id, to_name: r.to_name ?? "", message_id: r.message_id };
|
|
918
|
+
if (plan.warning) out.warning = plan.warning;
|
|
919
|
+
return out;
|
|
920
|
+
}
|
|
921
|
+
protocols.reregister = () => reresolve("protocol call: unknown peer");
|
|
922
|
+
return {
|
|
923
|
+
peer,
|
|
924
|
+
registry,
|
|
925
|
+
connect,
|
|
926
|
+
close,
|
|
927
|
+
async send(to, text, delivery, meta) {
|
|
928
|
+
requireRegistered();
|
|
929
|
+
const d = delivery === void 0 ? "pull" : String(delivery);
|
|
930
|
+
if (d !== "pull" && d !== "push") throw new Error(`Invalid delivery: ${d} (use "pull" or "push")`);
|
|
931
|
+
return sendMode(to, text, d, parseMeta(meta));
|
|
932
|
+
},
|
|
933
|
+
ping(to, subject) {
|
|
934
|
+
return sendMode(to, subject ?? "", "ping");
|
|
935
|
+
},
|
|
936
|
+
async listPeers(scope = "all", filter) {
|
|
937
|
+
requireRegistered();
|
|
938
|
+
return listPeers(protocolEnv, scope, filter);
|
|
939
|
+
},
|
|
940
|
+
setProtocol(repo, version) {
|
|
941
|
+
return setProtocol(protocolEnv, repo, version);
|
|
942
|
+
},
|
|
943
|
+
async unsetProtocol(name) {
|
|
944
|
+
await unsetProtocol(protocolEnv, name);
|
|
945
|
+
},
|
|
946
|
+
getProtocol(name, version) {
|
|
947
|
+
return getProtocol(protocolEnv, name, version);
|
|
948
|
+
},
|
|
949
|
+
async setName(name) {
|
|
950
|
+
const id = requireRegistered();
|
|
951
|
+
const r = await broker.post("/set-name", { id, name });
|
|
952
|
+
if (!r.ok) throw new Error(`Failed: ${r.error}`);
|
|
953
|
+
peer.name = name;
|
|
954
|
+
},
|
|
955
|
+
async setSummary(summary) {
|
|
956
|
+
const id = requireRegistered();
|
|
957
|
+
const r = await broker.post("/set-summary", { id, summary });
|
|
958
|
+
if (!r.ok) throw new Error(`Failed: ${r.error}`);
|
|
959
|
+
peer.summary = summary;
|
|
960
|
+
},
|
|
961
|
+
checkMessages() {
|
|
962
|
+
requireRegistered();
|
|
963
|
+
return inbox.checkMessages();
|
|
964
|
+
},
|
|
965
|
+
onMessage: inbox.onMessage
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
async function startClient(options = {}) {
|
|
970
|
+
const env = options.env ?? process.env;
|
|
971
|
+
const log = options.log ?? ((msg) => console.error(`[agent-messenger] ${msg}`));
|
|
972
|
+
const cfg = loadConfig(env);
|
|
973
|
+
let cleaningUp = false;
|
|
974
|
+
const host = createStdioHost({
|
|
975
|
+
cfg,
|
|
976
|
+
log,
|
|
977
|
+
onClose: () => {
|
|
978
|
+
cleanup();
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
const client = createMessengerClient({ env, log, config: cfg, autoStartBroker: true, notifier: host.notifier });
|
|
982
|
+
await client.connect();
|
|
983
|
+
host.attach(client.registry);
|
|
984
|
+
host.connect();
|
|
985
|
+
log("MCP connected");
|
|
986
|
+
async function cleanup() {
|
|
987
|
+
if (cleaningUp) return;
|
|
988
|
+
cleaningUp = true;
|
|
989
|
+
await client.close();
|
|
990
|
+
process.exit(0);
|
|
991
|
+
}
|
|
992
|
+
process.on("SIGINT", () => {
|
|
993
|
+
cleanup();
|
|
994
|
+
});
|
|
995
|
+
process.on("SIGTERM", () => {
|
|
996
|
+
cleanup();
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
export { CAPABILITIES as C, LATEST_PROTOCOL_VERSION as L, SUPPORTED_PROTOCOL_VERSIONS as S, createMessengerClient as a, createStdioServer as b, createBrokerClient as c, discoverBrokers as d, resolveBroker as e, isLocalHost as i, loadConfig as l, postToSession as p, readConfigBrokers as r, startClient as s };
|