freddie 0.0.41 → 0.0.42

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.
Files changed (152) hide show
  1. package/AGENTS.md +85 -11
  2. package/CHANGELOG.md +16 -0
  3. package/README.md +2 -2
  4. package/bin/freddie.js +12 -109
  5. package/package.json +11 -2
  6. package/src/acp/server.js +3 -3
  7. package/src/acp/session.js +8 -8
  8. package/src/acp/tools.js +5 -4
  9. package/src/agent/account_usage.js +5 -5
  10. package/src/agent/credential_sources.js +2 -2
  11. package/src/agent/curator.js +5 -5
  12. package/src/agent/machine.js +3 -2
  13. package/src/agent/manual_compression_feedback.js +5 -5
  14. package/src/agent/shell_hooks.js +2 -2
  15. package/src/auth.js +2 -2
  16. package/src/batch.js +2 -2
  17. package/src/cli/backup.js +3 -3
  18. package/src/cli/doctor.js +3 -3
  19. package/src/cli/dump.js +4 -2
  20. package/src/cli/env_loader.js +2 -2
  21. package/src/cli/gateway_cli.js +3 -4
  22. package/src/cli/hooks.js +2 -2
  23. package/src/cli/logs.js +4 -4
  24. package/src/cli/mcp_config.js +2 -2
  25. package/src/cli/plugins_cmd.js +3 -3
  26. package/src/cli/status.js +1 -1
  27. package/src/cli/tools_config.js +2 -2
  28. package/src/cli/uninstall.js +2 -2
  29. package/src/config.js +2 -2
  30. package/src/db.js +3 -3
  31. package/src/gateway/platforms.js +21 -0
  32. package/src/home.js +2 -2
  33. package/src/host/contract.js +39 -0
  34. package/src/host/host.js +159 -0
  35. package/src/host/index.js +27 -0
  36. package/src/index.js +2 -1
  37. package/src/mcp/server.js +5 -4
  38. package/src/observability/log.js +2 -2
  39. package/src/plugins/disk_cleanup/index.js +2 -2
  40. package/src/plugins/manager.js +13 -63
  41. package/src/plugins/memory/provider.js +26 -26
  42. package/src/plugins/observability/index.js +3 -3
  43. package/src/skills/index.js +2 -2
  44. package/src/skin/engine.js +2 -2
  45. package/src/toolsets.js +13 -15
  46. package/src/web/index.html +1 -1
  47. package/src/web/server.js +8 -94
  48. package/src/gateway/platforms/api_server.js +0 -21
  49. package/src/gateway/platforms/bluebubbles.js +0 -32
  50. package/src/gateway/platforms/dingtalk.js +0 -32
  51. package/src/gateway/platforms/discord.js +0 -24
  52. package/src/gateway/platforms/email.js +0 -51
  53. package/src/gateway/platforms/feishu.js +0 -32
  54. package/src/gateway/platforms/feishu_comment.js +0 -12
  55. package/src/gateway/platforms/feishu_comment_rules.js +0 -11
  56. package/src/gateway/platforms/homeassistant.js +0 -32
  57. package/src/gateway/platforms/matrix.js +0 -40
  58. package/src/gateway/platforms/mattermost.js +0 -29
  59. package/src/gateway/platforms/qqbot.js +0 -32
  60. package/src/gateway/platforms/signal.js +0 -33
  61. package/src/gateway/platforms/slack.js +0 -34
  62. package/src/gateway/platforms/sms.js +0 -34
  63. package/src/gateway/platforms/telegram.js +0 -38
  64. package/src/gateway/platforms/telegram_network.js +0 -17
  65. package/src/gateway/platforms/webhook.js +0 -19
  66. package/src/gateway/platforms/wecom.js +0 -32
  67. package/src/gateway/platforms/wecom_callback.js +0 -15
  68. package/src/gateway/platforms/wecom_crypto.js +0 -16
  69. package/src/gateway/platforms/weixin.js +0 -32
  70. package/src/gateway/platforms/whatsapp.js +0 -40
  71. package/src/gateway/platforms/yuanbao.js +0 -9
  72. package/src/gateway/platforms/yuanbao_media.js +0 -5
  73. package/src/gateway/platforms/yuanbao_proto.js +0 -9
  74. package/src/gateway/platforms/yuanbao_sticker.js +0 -6
  75. package/src/plugins/memory/_index.js +0 -8
  76. package/src/plugins/memory/byterover.js +0 -25
  77. package/src/plugins/memory/hindsight.js +0 -25
  78. package/src/plugins/memory/holographic.js +0 -31
  79. package/src/plugins/memory/honcho.js +0 -25
  80. package/src/plugins/memory/mem0.js +0 -25
  81. package/src/plugins/memory/openviking.js +0 -25
  82. package/src/plugins/memory/retaindb.js +0 -25
  83. package/src/plugins/memory/supermemory.js +0 -25
  84. package/src/tools/ansi_strip.js +0 -8
  85. package/src/tools/approval.js +0 -15
  86. package/src/tools/bash.js +0 -35
  87. package/src/tools/binary_extensions.js +0 -22
  88. package/src/tools/browser.js +0 -48
  89. package/src/tools/budget_config.js +0 -13
  90. package/src/tools/checkpoint.js +0 -29
  91. package/src/tools/clarify.js +0 -15
  92. package/src/tools/code_execution.js +0 -27
  93. package/src/tools/credential_files.js +0 -16
  94. package/src/tools/cronjob.js +0 -16
  95. package/src/tools/debug_helpers.js +0 -9
  96. package/src/tools/delegate.js +0 -28
  97. package/src/tools/discord_tool.js +0 -13
  98. package/src/tools/edit.js +0 -31
  99. package/src/tools/env_passthrough.js +0 -15
  100. package/src/tools/feishu_doc.js +0 -15
  101. package/src/tools/feishu_drive.js +0 -14
  102. package/src/tools/file_operations.js +0 -17
  103. package/src/tools/file_state.js +0 -16
  104. package/src/tools/file_tools.js +0 -23
  105. package/src/tools/fuzzy_match.js +0 -8
  106. package/src/tools/grep.js +0 -51
  107. package/src/tools/homeassistant_tool.js +0 -15
  108. package/src/tools/image_gen.js +0 -33
  109. package/src/tools/interrupt.js +0 -18
  110. package/src/tools/managed_tool_gateway.js +0 -11
  111. package/src/tools/mcp_oauth.js +0 -21
  112. package/src/tools/mcp_oauth_manager.js +0 -20
  113. package/src/tools/mcp_tool.js +0 -36
  114. package/src/tools/memory.js +0 -66
  115. package/src/tools/mixture_of_agents.js +0 -14
  116. package/src/tools/neutts_synth.js +0 -13
  117. package/src/tools/openrouter_client.js +0 -13
  118. package/src/tools/osv_check.js +0 -11
  119. package/src/tools/patch_parser.js +0 -42
  120. package/src/tools/path_security.js +0 -16
  121. package/src/tools/process_registry.js +0 -17
  122. package/src/tools/read.js +0 -26
  123. package/src/tools/registry.js +0 -54
  124. package/src/tools/rl_training.js +0 -13
  125. package/src/tools/schema_sanitizer.js +0 -18
  126. package/src/tools/send_message.js +0 -32
  127. package/src/tools/session_search.js +0 -23
  128. package/src/tools/skill_manager.js +0 -17
  129. package/src/tools/skill_usage.js +0 -20
  130. package/src/tools/skills_guard.js +0 -17
  131. package/src/tools/skills_hub.js +0 -31
  132. package/src/tools/skills_index.js +0 -14
  133. package/src/tools/skills_sync.js +0 -19
  134. package/src/tools/skills_tool.js +0 -11
  135. package/src/tools/slash_confirm.js +0 -16
  136. package/src/tools/terminal.js +0 -29
  137. package/src/tools/tirith_security.js +0 -25
  138. package/src/tools/todo.js +0 -54
  139. package/src/tools/tool_backend_helpers.js +0 -26
  140. package/src/tools/tool_output_limits.js +0 -15
  141. package/src/tools/tool_result_storage.js +0 -20
  142. package/src/tools/transcription.js +0 -19
  143. package/src/tools/tts.js +0 -19
  144. package/src/tools/url_safety.js +0 -15
  145. package/src/tools/vision.js +0 -18
  146. package/src/tools/voice_mode.js +0 -10
  147. package/src/tools/web_search.js +0 -37
  148. package/src/tools/web_tools.js +0 -18
  149. package/src/tools/website_policy.js +0 -14
  150. package/src/tools/write.js +0 -25
  151. package/src/tools/xai_http.js +0 -13
  152. package/src/tools/yuanbao_tools.js +0 -13
@@ -1,32 +0,0 @@
1
- import express from 'express'
2
- import { EventEmitter } from 'node:events'
3
-
4
- export class QqbotAdapter extends EventEmitter {
5
- constructor(opts = {}) {
6
- super()
7
- this.platform = 'qqbot'
8
- this.token = opts.token || process.env.QQBOT_TOKEN
9
- this.port = opts.port || 0
10
- this.api = opts.api || "https://api.sgroup.qq.com/channels/messages"
11
- this._server = null
12
- }
13
- getRequiredEnv() { return ["QQBOT_TOKEN"] }
14
- async start() {
15
- if (!this.token) throw new Error('QqbotAdapter: ' + this.getRequiredEnv().join(', ') + ' required')
16
- const app = express()
17
- app.use(express.json())
18
- app.post('/webhook', (req, res) => {
19
- const text = req.body?.text || req.body?.message?.text || req.body?.content || ''
20
- const from = req.body?.from || req.body?.user_id || req.body?.sender_id || ''
21
- this.emit('message', { from: String(from), text, raw: req.body })
22
- res.json({ ok: true })
23
- })
24
- await new Promise(r => { this._server = app.listen(this.port, () => r()) })
25
- this.port = this._server.address().port
26
- }
27
- async stop() { if (this._server) await new Promise(r => this._server.close(() => r())) }
28
- async send(reply) {
29
- if (!this.token) throw new Error('QqbotAdapter: token required')
30
- return fetch(this.api, { method: 'POST', headers: { authorization: `Bearer ${this.token}`, 'content-type': 'application/json' }, body: JSON.stringify({ to: reply.to, text: reply.text }) }).then(r => r.json())
31
- }
32
- }
@@ -1,33 +0,0 @@
1
- import { EventEmitter } from 'node:events'
2
-
3
- export class SignalAdapter extends EventEmitter {
4
- constructor(opts = {}) {
5
- super()
6
- this.platform = 'signal'
7
- this.api = opts.api || process.env.SIGNAL_CLI_URL || 'http://127.0.0.1:8080'
8
- this.number = opts.number || process.env.SIGNAL_NUMBER
9
- this._running = false
10
- }
11
- getRequiredEnv() { return ['SIGNAL_CLI_URL', 'SIGNAL_NUMBER'] }
12
- async start() {
13
- if (!this.number) throw new Error('SignalAdapter: SIGNAL_NUMBER required')
14
- this._running = true
15
- this._loop()
16
- }
17
- async stop() { this._running = false }
18
- async _loop() {
19
- while (this._running) {
20
- try {
21
- const res = await fetch(`${this.api}/v1/receive/${this.number}`)
22
- const items = await res.json()
23
- for (const it of items) {
24
- const msg = it?.envelope?.dataMessage
25
- if (msg) this.emit('message', { from: it.envelope.source, text: msg.message || '', raw: it })
26
- }
27
- } catch (e) { await new Promise(r => setTimeout(r, 2000)) }
28
- }
29
- }
30
- async send(reply) {
31
- return fetch(`${this.api}/v2/send`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ number: this.number, recipients: [reply.to], message: reply.text }) }).then(r => r.json())
32
- }
33
- }
@@ -1,34 +0,0 @@
1
- import express from 'express'
2
- import { EventEmitter } from 'node:events'
3
-
4
- export class SlackAdapter extends EventEmitter {
5
- constructor(opts = {}) {
6
- super()
7
- this.platform = 'slack'
8
- this.token = opts.token || process.env.SLACK_BOT_TOKEN
9
- this.signingSecret = opts.signingSecret || process.env.SLACK_SIGNING_SECRET
10
- this.port = opts.port || 0
11
- this.path = opts.path || '/slack/events'
12
- this.api = opts.api || 'https://slack.com/api'
13
- this._server = null
14
- }
15
- getRequiredEnv() { return ['SLACK_BOT_TOKEN', 'SLACK_SIGNING_SECRET'] }
16
- async start() {
17
- if (!this.token) throw new Error('SlackAdapter: SLACK_BOT_TOKEN required')
18
- const app = express()
19
- app.use(express.json())
20
- app.post(this.path, (req, res) => {
21
- if (req.body?.type === 'url_verification') return res.json({ challenge: req.body.challenge })
22
- const ev = req.body?.event
23
- if (ev?.type === 'message' && !ev.bot_id) this.emit('message', { from: ev.channel, text: ev.text || '', user: ev.user, raw: req.body })
24
- res.json({ ok: true })
25
- })
26
- await new Promise(r => { this._server = app.listen(this.port, () => r()) })
27
- this.port = this._server.address().port
28
- }
29
- async stop() { if (this._server) await new Promise(r => this._server.close(() => r())) }
30
- async send(reply) {
31
- if (!this.token) throw new Error('SlackAdapter: token required')
32
- return fetch(`${this.api}/chat.postMessage`, { method: 'POST', headers: { authorization: `Bearer ${this.token}`, 'content-type': 'application/json' }, body: JSON.stringify({ channel: reply.to, text: reply.text }) }).then(r => r.json())
33
- }
34
- }
@@ -1,34 +0,0 @@
1
- import express from 'express'
2
- import { EventEmitter } from 'node:events'
3
-
4
- export class SmsAdapter extends EventEmitter {
5
- constructor(opts = {}) {
6
- super()
7
- this.platform = 'sms'
8
- this.sid = opts.sid || process.env.TWILIO_SID
9
- this.token = opts.token || process.env.TWILIO_TOKEN
10
- this.from = opts.from || process.env.TWILIO_FROM
11
- this.port = opts.port || 0
12
- this._server = null
13
- }
14
- getRequiredEnv() { return ['TWILIO_SID', 'TWILIO_TOKEN', 'TWILIO_FROM'] }
15
- async start() {
16
- if (!this.sid || !this.token || !this.from) throw new Error('SmsAdapter: TWILIO_SID/TOKEN/FROM required')
17
- const app = express()
18
- app.use(express.urlencoded({ extended: true }))
19
- app.post('/sms', (req, res) => {
20
- this.emit('message', { from: req.body.From, text: req.body.Body || '', raw: req.body })
21
- res.set('content-type', 'text/xml')
22
- res.send('<Response/>')
23
- })
24
- await new Promise(r => { this._server = app.listen(this.port, () => r()) })
25
- this.port = this._server.address().port
26
- }
27
- async stop() { if (this._server) await new Promise(r => this._server.close(() => r())) }
28
- async send(reply) {
29
- const url = `https://api.twilio.com/2010-04-01/Accounts/${this.sid}/Messages.json`
30
- const body = new URLSearchParams({ To: reply.to, From: this.from, Body: reply.text }).toString()
31
- const auth = 'Basic ' + Buffer.from(`${this.sid}:${this.token}`).toString('base64')
32
- return fetch(url, { method: 'POST', headers: { authorization: auth, 'content-type': 'application/x-www-form-urlencoded' }, body }).then(r => r.json())
33
- }
34
- }
@@ -1,38 +0,0 @@
1
- import { EventEmitter } from 'node:events'
2
-
3
- export class TelegramAdapter extends EventEmitter {
4
- constructor(opts = {}) {
5
- super()
6
- this.platform = 'telegram'
7
- this.token = opts.token || process.env.TELEGRAM_BOT_TOKEN
8
- this.api = opts.api || 'https://api.telegram.org'
9
- this.offset = 0
10
- this._running = false
11
- this._poll = null
12
- }
13
- getRequiredEnv() { return ['TELEGRAM_BOT_TOKEN'] }
14
- async start() {
15
- if (!this.token) throw new Error('TelegramAdapter: TELEGRAM_BOT_TOKEN required')
16
- this._running = true
17
- this._loop()
18
- }
19
- async stop() { this._running = false; if (this._poll) clearTimeout(this._poll) }
20
- async _loop() {
21
- while (this._running) {
22
- try {
23
- const url = `${this.api}/bot${this.token}/getUpdates?timeout=25&offset=${this.offset + 1}`
24
- const res = await fetch(url)
25
- const data = await res.json()
26
- if (data.ok) for (const u of data.result) {
27
- this.offset = Math.max(this.offset, u.update_id)
28
- if (u.message) this.emit('message', { from: String(u.message.from?.id || ''), text: u.message.text || '', raw: u })
29
- }
30
- } catch (e) { await new Promise(r => setTimeout(r, 5000)) }
31
- }
32
- }
33
- async send(reply) {
34
- if (!this.token) throw new Error('TelegramAdapter: token required')
35
- const url = `${this.api}/bot${this.token}/sendMessage`
36
- return fetch(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ chat_id: reply.to, text: reply.text }) }).then(r => r.json())
37
- }
38
- }
@@ -1,17 +0,0 @@
1
- export function tgFloodWait(error) {
2
- const m = String(error?.message || '').match(/FLOOD_WAIT_(\d+)/)
3
- return m ? Number(m[1]) * 1000 : null
4
- }
5
- export async function tgWithRetry(fn, { attempts = 3 } = {}) {
6
- let last
7
- for (let i = 0; i < attempts; i++) {
8
- try { return await fn() } catch (e) {
9
- last = e
10
- const wait = tgFloodWait(e)
11
- if (wait != null) await new Promise(r => setTimeout(r, wait + 100))
12
- else if (i < attempts - 1) await new Promise(r => setTimeout(r, 500 * (i + 1)))
13
- }
14
- }
15
- throw last
16
- }
17
- export function withProxy(fetchOpts, proxy) { return proxy ? { ...fetchOpts, proxy } : fetchOpts }
@@ -1,19 +0,0 @@
1
- import express from 'express'
2
- import { EventEmitter } from 'node:events'
3
-
4
- export class WebhookAdapter extends EventEmitter {
5
- constructor({ port = 0, path = '/webhook' } = {}) { super(); this.port = port; this.path = path; this._server = null; this.outbox = [] }
6
- async start() {
7
- const app = express()
8
- app.use(express.json())
9
- app.post(this.path, (req, res) => {
10
- const m = { from: req.body?.from || 'webhook', text: req.body?.text || '', raw: req.body }
11
- this.emit('message', m)
12
- res.json({ ok: true })
13
- })
14
- await new Promise(resolve => { this._server = app.listen(this.port, () => resolve()) })
15
- this.port = this._server.address().port
16
- }
17
- async stop() { if (this._server) await new Promise(r => this._server.close(() => r())) }
18
- async send(reply) { this.outbox.push(reply) }
19
- }
@@ -1,32 +0,0 @@
1
- import express from 'express'
2
- import { EventEmitter } from 'node:events'
3
-
4
- export class WecomAdapter extends EventEmitter {
5
- constructor(opts = {}) {
6
- super()
7
- this.platform = 'wecom'
8
- this.token = opts.token || process.env.WECOM_WEBHOOK_KEY
9
- this.port = opts.port || 0
10
- this.api = opts.api || "https://qyapi.weixin.qq.com/cgi-bin/webhook/send"
11
- this._server = null
12
- }
13
- getRequiredEnv() { return ["WECOM_WEBHOOK_KEY"] }
14
- async start() {
15
- if (!this.token) throw new Error('WecomAdapter: ' + this.getRequiredEnv().join(', ') + ' required')
16
- const app = express()
17
- app.use(express.json())
18
- app.post('/webhook', (req, res) => {
19
- const text = req.body?.text || req.body?.message?.text || req.body?.content || ''
20
- const from = req.body?.from || req.body?.user_id || req.body?.sender_id || ''
21
- this.emit('message', { from: String(from), text, raw: req.body })
22
- res.json({ ok: true })
23
- })
24
- await new Promise(r => { this._server = app.listen(this.port, () => r()) })
25
- this.port = this._server.address().port
26
- }
27
- async stop() { if (this._server) await new Promise(r => this._server.close(() => r())) }
28
- async send(reply) {
29
- if (!this.token) throw new Error('WecomAdapter: token required')
30
- return fetch(this.api, { method: 'POST', headers: { authorization: `Bearer ${this.token}`, 'content-type': 'application/json' }, body: JSON.stringify({ to: reply.to, text: reply.text }) }).then(r => r.json())
31
- }
32
- }
@@ -1,15 +0,0 @@
1
- import express from 'express'
2
- import { EventEmitter } from 'node:events'
3
- export class WecomCallbackAdapter extends EventEmitter {
4
- constructor(opts = {}) { super(); this.platform = 'wecom_callback'; this.token = opts.token || process.env.WECOM_CALLBACK_TOKEN; this.aesKey = opts.aesKey || process.env.WECOM_ENCODING_AES_KEY; this.port = opts.port || 0 }
5
- getRequiredEnv() { return ['WECOM_CALLBACK_TOKEN'] }
6
- async start() {
7
- if (!this.token) throw new Error('WECOM_CALLBACK_TOKEN required')
8
- const app = express(); app.use(express.text({ type: '*/*' }))
9
- app.post('/wecom/callback', (req, res) => { this.emit('message', { from: 'wecom', text: req.body || '', raw: req.body }); res.send('') })
10
- this._server = await new Promise(r => { const s = app.listen(this.port, () => r(s)) })
11
- this.port = this._server.address().port
12
- }
13
- async stop() { if (this._server) await new Promise(r => this._server.close(() => r())) }
14
- async send() { return { error: 'wecom_callback is receive-only; use wecom adapter for outbound' } }
15
- }
@@ -1,16 +0,0 @@
1
- import crypto from 'node:crypto'
2
- export function sha1(...parts) { return crypto.createHash('sha1').update(parts.sort().join('')).digest('hex') }
3
- export function verifyMsgSignature({ token, timestamp, nonce, encrypt, signature }) {
4
- return sha1(token, timestamp, nonce, encrypt) === signature
5
- }
6
- export function decryptMsg(encryptedB64, encodingAesKey) {
7
- const aesKey = Buffer.from(encodingAesKey + '=', 'base64')
8
- const iv = aesKey.slice(0, 16)
9
- const decipher = crypto.createDecipheriv('aes-256-cbc', aesKey, iv)
10
- decipher.setAutoPadding(false)
11
- const decrypted = Buffer.concat([decipher.update(Buffer.from(encryptedB64, 'base64')), decipher.final()])
12
- const padLen = decrypted[decrypted.length - 1]
13
- const trimmed = decrypted.slice(16, decrypted.length - padLen)
14
- const xmlLen = trimmed.readUInt32BE(0)
15
- return { xml: trimmed.slice(4, 4 + xmlLen).toString('utf8'), corpId: trimmed.slice(4 + xmlLen).toString('utf8') }
16
- }
@@ -1,32 +0,0 @@
1
- import express from 'express'
2
- import { EventEmitter } from 'node:events'
3
-
4
- export class WeixinAdapter extends EventEmitter {
5
- constructor(opts = {}) {
6
- super()
7
- this.platform = 'weixin'
8
- this.token = opts.token || process.env.WEIXIN_TOKEN
9
- this.port = opts.port || 0
10
- this.api = opts.api || "https://api.weixin.qq.com/cgi-bin/message/send"
11
- this._server = null
12
- }
13
- getRequiredEnv() { return ["WEIXIN_TOKEN"] }
14
- async start() {
15
- if (!this.token) throw new Error('WeixinAdapter: ' + this.getRequiredEnv().join(', ') + ' required')
16
- const app = express()
17
- app.use(express.json())
18
- app.post('/webhook', (req, res) => {
19
- const text = req.body?.text || req.body?.message?.text || req.body?.content || ''
20
- const from = req.body?.from || req.body?.user_id || req.body?.sender_id || ''
21
- this.emit('message', { from: String(from), text, raw: req.body })
22
- res.json({ ok: true })
23
- })
24
- await new Promise(r => { this._server = app.listen(this.port, () => r()) })
25
- this.port = this._server.address().port
26
- }
27
- async stop() { if (this._server) await new Promise(r => this._server.close(() => r())) }
28
- async send(reply) {
29
- if (!this.token) throw new Error('WeixinAdapter: token required')
30
- return fetch(this.api, { method: 'POST', headers: { authorization: `Bearer ${this.token}`, 'content-type': 'application/json' }, body: JSON.stringify({ to: reply.to, text: reply.text }) }).then(r => r.json())
31
- }
32
- }
@@ -1,40 +0,0 @@
1
- import express from 'express'
2
- import { EventEmitter } from 'node:events'
3
-
4
- export class WhatsappAdapter extends EventEmitter {
5
- constructor(opts = {}) {
6
- super()
7
- this.platform = 'whatsapp'
8
- this.token = opts.token || process.env.WHATSAPP_API_TOKEN
9
- this.phoneId = opts.phoneId || process.env.WHATSAPP_PHONE_NUMBER_ID
10
- this.verifyToken = opts.verifyToken || process.env.WHATSAPP_VERIFY_TOKEN || 'freddie'
11
- this.port = opts.port || 0
12
- this.api = opts.api || 'https://graph.facebook.com/v20.0'
13
- this._server = null
14
- }
15
- getRequiredEnv() { return ['WHATSAPP_API_TOKEN', 'WHATSAPP_PHONE_NUMBER_ID'] }
16
- async start() {
17
- if (!this.token || !this.phoneId) throw new Error('WhatsappAdapter: WHATSAPP_API_TOKEN + WHATSAPP_PHONE_NUMBER_ID required')
18
- const app = express()
19
- app.use(express.json())
20
- app.get('/webhook', (req, res) => {
21
- if (req.query['hub.verify_token'] === this.verifyToken) return res.send(req.query['hub.challenge'])
22
- res.sendStatus(403)
23
- })
24
- app.post('/webhook', (req, res) => {
25
- const entries = req.body?.entry || []
26
- for (const e of entries) for (const c of (e.changes || [])) {
27
- const msgs = c.value?.messages || []
28
- for (const m of msgs) this.emit('message', { from: m.from, text: m.text?.body || '', raw: m })
29
- }
30
- res.json({ ok: true })
31
- })
32
- await new Promise(r => { this._server = app.listen(this.port, () => r()) })
33
- this.port = this._server.address().port
34
- }
35
- async stop() { if (this._server) await new Promise(r => this._server.close(() => r())) }
36
- async send(reply) {
37
- if (!this.token) throw new Error('WhatsappAdapter: token required')
38
- return fetch(`${this.api}/${this.phoneId}/messages`, { method: 'POST', headers: { authorization: `Bearer ${this.token}`, 'content-type': 'application/json' }, body: JSON.stringify({ messaging_product: 'whatsapp', to: reply.to, text: { body: reply.text } }) }).then(r => r.json())
39
- }
40
- }
@@ -1,9 +0,0 @@
1
- import { BasePlatformAdapter } from '../base.js'
2
- export class YuanbaoAdapter extends BasePlatformAdapter {
3
- constructor(opts = {}) { super({ ...opts, platform: 'yuanbao' }); this.token = opts.token || process.env.YUANBAO_API_KEY; this.api = opts.api || 'https://api.hunyuan.cloud.tencent.com/v1' }
4
- getRequiredEnv() { return ['YUANBAO_API_KEY'] }
5
- async send(reply) {
6
- const r = await fetch(this.api + '/chat/completions', { method: 'POST', headers: { authorization: 'Bearer ' + this.token, 'content-type': 'application/json' }, body: JSON.stringify({ model: 'hunyuan-pro', messages: [{ role: 'user', content: reply.text }] }) })
7
- return await r.json()
8
- }
9
- }
@@ -1,5 +0,0 @@
1
- export async function uploadMedia({ token, file, mime = 'image/png' }) {
2
- if (!token) throw new Error('yuanbao token required')
3
- const r = await fetch('https://api.hunyuan.cloud.tencent.com/v1/files', { method: 'POST', headers: { authorization: 'Bearer ' + token, 'content-type': mime }, body: file })
4
- return await r.json()
5
- }
@@ -1,9 +0,0 @@
1
- export function buildChatPayload({ model = 'hunyuan-pro', messages, stream = false, tools = [] }) {
2
- return { model, messages, stream, ...(tools.length ? { tools: tools.map(t => ({ type: 'function', function: t })) } : {}) }
3
- }
4
- export function parseChatResponse(json) {
5
- const choice = json?.choices?.[0]
6
- if (!choice) return { content: '', tool_calls: [] }
7
- const tc = (choice.message?.tool_calls || []).map(c => ({ id: c.id, name: c.function?.name, arguments: c.function?.arguments ? JSON.parse(c.function.arguments) : {} }))
8
- return { content: choice.message?.content || '', tool_calls: tc }
9
- }
@@ -1,6 +0,0 @@
1
- export const STICKER_PACK = ['cute', 'work', 'celebration', 'thinking', 'thumbs-up']
2
- export function buildStickerMessage({ to, sticker }) {
3
- if (!STICKER_PACK.includes(sticker)) throw new Error('unknown sticker: ' + sticker)
4
- return { to, type: 'sticker', sticker }
5
- }
6
- export function listStickers() { return STICKER_PACK }
@@ -1,8 +0,0 @@
1
- export { HonchoMemory } from './honcho.js'
2
- export { Mem0Memory } from './mem0.js'
3
- export { SupermemoryMemory } from './supermemory.js'
4
- export { ByteroverMemory } from './byterover.js'
5
- export { HindsightMemory } from './hindsight.js'
6
- export { HolographicMemory } from './holographic.js'
7
- export { OpenvikingMemory } from './openviking.js'
8
- export { RetaindbMemory } from './retaindb.js'
@@ -1,25 +0,0 @@
1
- export class ByteroverMemory {
2
- constructor(opts = {}) {
3
- this.name = 'byterover'
4
- this.apiKey = opts.apiKey || process.env.BYTEROVER_API_KEY
5
- this.base = opts.base || "https://api.byterover.com"
6
- this.userId = opts.userId || 'default'
7
- }
8
- getRequiredEnv() { return ["BYTEROVER_API_KEY"] }
9
- _headers() {
10
- if (!this.apiKey) throw new Error('ByteroverMemory: BYTEROVER_API_KEY required')
11
- return { authorization: `Bearer ${this.apiKey}`, 'content-type': 'application/json' }
12
- }
13
- async syncTurn(messages) {
14
- const res = await fetch(`${this.base}/memories`, { method: 'POST', headers: this._headers(), body: JSON.stringify({ user_id: this.userId, messages }) })
15
- return { status: res.status, ok: res.ok }
16
- }
17
- async prefetch(query) {
18
- const url = `${this.base}/memories/search?query=${encodeURIComponent(query || '')}&user_id=${encodeURIComponent(this.userId)}`
19
- const res = await fetch(url, { headers: this._headers() })
20
- if (!res.ok) return { items: [], status: res.status }
21
- return { items: await res.json() }
22
- }
23
- async shutdown() {}
24
- async postSetup() {}
25
- }
@@ -1,25 +0,0 @@
1
- export class HindsightMemory {
2
- constructor(opts = {}) {
3
- this.name = 'hindsight'
4
- this.apiKey = opts.apiKey || process.env.HINDSIGHT_API_KEY
5
- this.base = opts.base || "https://api.hindsightai.com"
6
- this.userId = opts.userId || 'default'
7
- }
8
- getRequiredEnv() { return ["HINDSIGHT_API_KEY"] }
9
- _headers() {
10
- if (!this.apiKey) throw new Error('HindsightMemory: HINDSIGHT_API_KEY required')
11
- return { authorization: `Bearer ${this.apiKey}`, 'content-type': 'application/json' }
12
- }
13
- async syncTurn(messages) {
14
- const res = await fetch(`${this.base}/memories`, { method: 'POST', headers: this._headers(), body: JSON.stringify({ user_id: this.userId, messages }) })
15
- return { status: res.status, ok: res.ok }
16
- }
17
- async prefetch(query) {
18
- const url = `${this.base}/memories/search?query=${encodeURIComponent(query || '')}&user_id=${encodeURIComponent(this.userId)}`
19
- const res = await fetch(url, { headers: this._headers() })
20
- if (!res.ok) return { items: [], status: res.status }
21
- return { items: await res.json() }
22
- }
23
- async shutdown() {}
24
- async postSetup() {}
25
- }
@@ -1,31 +0,0 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import { getFophHome } from '../../home.js'
4
-
5
- export class HolographicMemory {
6
- constructor(opts = {}) {
7
- this.name = 'holographic'
8
- this.dir = opts.dir || path.join(getFophHome(), 'memory', 'holographic')
9
- fs.mkdirSync(this.dir, { recursive: true })
10
- }
11
- getRequiredEnv() { return [] }
12
- async syncTurn(messages) {
13
- const file = path.join(this.dir, Date.now() + '.json')
14
- fs.writeFileSync(file, JSON.stringify({ ts: Date.now(), messages }), 'utf8')
15
- return { stored: file }
16
- }
17
- async prefetch(query) {
18
- const files = fs.readdirSync(this.dir).filter(f => f.endsWith('.json')).sort().slice(-20)
19
- const items = []
20
- for (const f of files) {
21
- try {
22
- const data = JSON.parse(fs.readFileSync(path.join(this.dir, f), 'utf8'))
23
- const last = data.messages?.slice(-2).map(m => m.content).join(' ') || ''
24
- if (!query || last.toLowerCase().includes(String(query).toLowerCase())) items.push({ file: f, summary: last.slice(0, 200) })
25
- } catch {}
26
- }
27
- return { items }
28
- }
29
- async shutdown() {}
30
- async postSetup() {}
31
- }
@@ -1,25 +0,0 @@
1
- export class HonchoMemory {
2
- constructor(opts = {}) {
3
- this.name = 'honcho'
4
- this.apiKey = opts.apiKey || process.env.HONCHO_API_KEY
5
- this.base = opts.base || "https://api.honcho.dev"
6
- this.userId = opts.userId || 'default'
7
- }
8
- getRequiredEnv() { return ["HONCHO_API_KEY"] }
9
- _headers() {
10
- if (!this.apiKey) throw new Error('HonchoMemory: HONCHO_API_KEY required')
11
- return { authorization: `Bearer ${this.apiKey}`, 'content-type': 'application/json' }
12
- }
13
- async syncTurn(messages) {
14
- const res = await fetch(`${this.base}/memories`, { method: 'POST', headers: this._headers(), body: JSON.stringify({ user_id: this.userId, messages }) })
15
- return { status: res.status, ok: res.ok }
16
- }
17
- async prefetch(query) {
18
- const url = `${this.base}/memories/search?query=${encodeURIComponent(query || '')}&user_id=${encodeURIComponent(this.userId)}`
19
- const res = await fetch(url, { headers: this._headers() })
20
- if (!res.ok) return { items: [], status: res.status }
21
- return { items: await res.json() }
22
- }
23
- async shutdown() {}
24
- async postSetup() {}
25
- }
@@ -1,25 +0,0 @@
1
- export class Mem0Memory {
2
- constructor(opts = {}) {
3
- this.name = 'mem0'
4
- this.apiKey = opts.apiKey || process.env.MEM0_API_KEY
5
- this.base = opts.base || "https://api.mem0.ai/v1"
6
- this.userId = opts.userId || 'default'
7
- }
8
- getRequiredEnv() { return ["MEM0_API_KEY"] }
9
- _headers() {
10
- if (!this.apiKey) throw new Error('Mem0Memory: MEM0_API_KEY required')
11
- return { authorization: `Bearer ${this.apiKey}`, 'content-type': 'application/json' }
12
- }
13
- async syncTurn(messages) {
14
- const res = await fetch(`${this.base}/memories`, { method: 'POST', headers: this._headers(), body: JSON.stringify({ user_id: this.userId, messages }) })
15
- return { status: res.status, ok: res.ok }
16
- }
17
- async prefetch(query) {
18
- const url = `${this.base}/memories/search?query=${encodeURIComponent(query || '')}&user_id=${encodeURIComponent(this.userId)}`
19
- const res = await fetch(url, { headers: this._headers() })
20
- if (!res.ok) return { items: [], status: res.status }
21
- return { items: await res.json() }
22
- }
23
- async shutdown() {}
24
- async postSetup() {}
25
- }
@@ -1,25 +0,0 @@
1
- export class OpenvikingMemory {
2
- constructor(opts = {}) {
3
- this.name = 'openviking'
4
- this.apiKey = opts.apiKey || process.env.OPENVIKING_API_KEY
5
- this.base = opts.base || "https://api.openviking.com"
6
- this.userId = opts.userId || 'default'
7
- }
8
- getRequiredEnv() { return ["OPENVIKING_API_KEY"] }
9
- _headers() {
10
- if (!this.apiKey) throw new Error('OpenvikingMemory: OPENVIKING_API_KEY required')
11
- return { authorization: `Bearer ${this.apiKey}`, 'content-type': 'application/json' }
12
- }
13
- async syncTurn(messages) {
14
- const res = await fetch(`${this.base}/memories`, { method: 'POST', headers: this._headers(), body: JSON.stringify({ user_id: this.userId, messages }) })
15
- return { status: res.status, ok: res.ok }
16
- }
17
- async prefetch(query) {
18
- const url = `${this.base}/memories/search?query=${encodeURIComponent(query || '')}&user_id=${encodeURIComponent(this.userId)}`
19
- const res = await fetch(url, { headers: this._headers() })
20
- if (!res.ok) return { items: [], status: res.status }
21
- return { items: await res.json() }
22
- }
23
- async shutdown() {}
24
- async postSetup() {}
25
- }
@@ -1,25 +0,0 @@
1
- export class RetaindbMemory {
2
- constructor(opts = {}) {
3
- this.name = 'retaindb'
4
- this.apiKey = opts.apiKey || process.env.RETAINDB_API_KEY
5
- this.base = opts.base || "https://api.retaindb.com"
6
- this.userId = opts.userId || 'default'
7
- }
8
- getRequiredEnv() { return ["RETAINDB_API_KEY"] }
9
- _headers() {
10
- if (!this.apiKey) throw new Error('RetaindbMemory: RETAINDB_API_KEY required')
11
- return { authorization: `Bearer ${this.apiKey}`, 'content-type': 'application/json' }
12
- }
13
- async syncTurn(messages) {
14
- const res = await fetch(`${this.base}/memories`, { method: 'POST', headers: this._headers(), body: JSON.stringify({ user_id: this.userId, messages }) })
15
- return { status: res.status, ok: res.ok }
16
- }
17
- async prefetch(query) {
18
- const url = `${this.base}/memories/search?query=${encodeURIComponent(query || '')}&user_id=${encodeURIComponent(this.userId)}`
19
- const res = await fetch(url, { headers: this._headers() })
20
- if (!res.ok) return { items: [], status: res.status }
21
- return { items: await res.json() }
22
- }
23
- async shutdown() {}
24
- async postSetup() {}
25
- }
@@ -1,25 +0,0 @@
1
- export class SupermemoryMemory {
2
- constructor(opts = {}) {
3
- this.name = 'supermemory'
4
- this.apiKey = opts.apiKey || process.env.SUPERMEMORY_API_KEY
5
- this.base = opts.base || "https://api.supermemory.ai/v3"
6
- this.userId = opts.userId || 'default'
7
- }
8
- getRequiredEnv() { return ["SUPERMEMORY_API_KEY"] }
9
- _headers() {
10
- if (!this.apiKey) throw new Error('SupermemoryMemory: SUPERMEMORY_API_KEY required')
11
- return { authorization: `Bearer ${this.apiKey}`, 'content-type': 'application/json' }
12
- }
13
- async syncTurn(messages) {
14
- const res = await fetch(`${this.base}/memories`, { method: 'POST', headers: this._headers(), body: JSON.stringify({ user_id: this.userId, messages }) })
15
- return { status: res.status, ok: res.ok }
16
- }
17
- async prefetch(query) {
18
- const url = `${this.base}/memories/search?query=${encodeURIComponent(query || '')}&user_id=${encodeURIComponent(this.userId)}`
19
- const res = await fetch(url, { headers: this._headers() })
20
- if (!res.ok) return { items: [], status: res.status }
21
- return { items: await res.json() }
22
- }
23
- async shutdown() {}
24
- async postSetup() {}
25
- }
@@ -1,8 +0,0 @@
1
- import { ansiStrip } from '../utils.js'
2
- import { registry } from './registry.js'
3
- registry.register({
4
- name: 'ansi_strip',
5
- toolset: 'core',
6
- schema: { name: 'ansi_strip', description: 'Strip ANSI escape sequences.', parameters: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] } },
7
- handler: async ({ text }) => ({ text: ansiStrip(text) }),
8
- })