@agenticmail/enterprise 0.5.327 → 0.5.329
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-tools-F3CYENMK.js +13949 -0
- package/dist/browser-tool-P57PLVW2.js +4002 -0
- package/dist/chunk-3RI3AIJN.js +1519 -0
- package/dist/chunk-AD4DFKHR.js +4928 -0
- package/dist/chunk-UQXPVWXG.js +5101 -0
- package/dist/cli-agent-K6UFZRXC.js +2473 -0
- package/dist/cli-serve-4MT7RDEL.js +260 -0
- package/dist/cli.js +3 -3
- package/dist/dashboard/app.js +1 -1
- package/dist/dashboard/components/transport-encryption.js +0 -62
- package/dist/dashboard/pages/agent-detail/index.js +5 -2
- package/dist/dashboard/pages/agent-detail/manager.js +1 -1
- package/dist/dashboard/pages/agent-detail/overview.js +4 -2
- package/dist/dashboard/pages/agent-detail/tool-security.js +1 -1
- package/dist/dashboard/pages/domain-status.js +3 -6
- package/dist/dashboard/pages/memory-transfer.js +1 -1
- package/dist/dashboard/pages/messages.js +0 -1
- package/dist/dashboard/pages/roles.js +0 -2
- package/dist/dashboard/pages/workforce.js +0 -1
- package/dist/index.js +3 -3
- package/dist/runtime-L5ADJORP.js +45 -0
- package/dist/server-KSN56EZQ.js +28 -0
- package/dist/setup-UUNBBOQH.js +20 -0
- package/logs/cloudflared-error.log +42 -0
- package/logs/enterprise-out.log +6 -0
- package/package.json +1 -1
- package/src/admin/page-registry.ts +0 -290
- package/src/admin/routes.ts +0 -2968
- package/src/agent-tools/common.ts +0 -260
- package/src/agent-tools/index.ts +0 -542
- package/src/agent-tools/merge.ts +0 -62
- package/src/agent-tools/middleware.ts +0 -436
- package/src/agent-tools/schema/typebox.ts +0 -25
- package/src/agent-tools/security.ts +0 -352
- package/src/agent-tools/tool-resolver.ts +0 -1018
- package/src/agent-tools/tools/agenticmail.ts +0 -1017
- package/src/agent-tools/tools/bash.ts +0 -179
- package/src/agent-tools/tools/browser-tool.schema.ts +0 -112
- package/src/agent-tools/tools/browser-tool.ts +0 -388
- package/src/agent-tools/tools/browser.ts +0 -764
- package/src/agent-tools/tools/edit.ts +0 -100
- package/src/agent-tools/tools/enterprise-code-sandbox.ts +0 -395
- package/src/agent-tools/tools/enterprise-database.ts +0 -377
- package/src/agent-tools/tools/enterprise-diff.ts +0 -580
- package/src/agent-tools/tools/enterprise-documents.ts +0 -896
- package/src/agent-tools/tools/enterprise-http.ts +0 -485
- package/src/agent-tools/tools/enterprise-security-scan.ts +0 -528
- package/src/agent-tools/tools/enterprise-spreadsheet.ts +0 -825
- package/src/agent-tools/tools/glob.ts +0 -129
- package/src/agent-tools/tools/google/calendar.ts +0 -230
- package/src/agent-tools/tools/google/chat.ts +0 -725
- package/src/agent-tools/tools/google/contacts.ts +0 -209
- package/src/agent-tools/tools/google/docs.ts +0 -162
- package/src/agent-tools/tools/google/drive.ts +0 -392
- package/src/agent-tools/tools/google/forms.ts +0 -367
- package/src/agent-tools/tools/google/gmail.ts +0 -897
- package/src/agent-tools/tools/google/index.ts +0 -86
- package/src/agent-tools/tools/google/maps.ts +0 -543
- package/src/agent-tools/tools/google/meeting-voice.ts +0 -885
- package/src/agent-tools/tools/google/meetings.ts +0 -1094
- package/src/agent-tools/tools/google/sheets.ts +0 -215
- package/src/agent-tools/tools/google/slides.ts +0 -559
- package/src/agent-tools/tools/google/tasks.ts +0 -200
- package/src/agent-tools/tools/grep.ts +0 -178
- package/src/agent-tools/tools/integrations/_factory.ts +0 -102
- package/src/agent-tools/tools/integrations/activecampaign.ts +0 -14
- package/src/agent-tools/tools/integrations/adobe-sign.ts +0 -14
- package/src/agent-tools/tools/integrations/adp.ts +0 -14
- package/src/agent-tools/tools/integrations/airtable.ts +0 -14
- package/src/agent-tools/tools/integrations/apollo.ts +0 -14
- package/src/agent-tools/tools/integrations/asana.ts +0 -14
- package/src/agent-tools/tools/integrations/auth0.ts +0 -14
- package/src/agent-tools/tools/integrations/aws.ts +0 -14
- package/src/agent-tools/tools/integrations/azure-devops.ts +0 -14
- package/src/agent-tools/tools/integrations/bamboohr.ts +0 -14
- package/src/agent-tools/tools/integrations/basecamp.ts +0 -14
- package/src/agent-tools/tools/integrations/bigcommerce.ts +0 -14
- package/src/agent-tools/tools/integrations/bitbucket.ts +0 -14
- package/src/agent-tools/tools/integrations/box.ts +0 -14
- package/src/agent-tools/tools/integrations/brex.ts +0 -14
- package/src/agent-tools/tools/integrations/buffer.ts +0 -14
- package/src/agent-tools/tools/integrations/calendly.ts +0 -14
- package/src/agent-tools/tools/integrations/canva.ts +0 -14
- package/src/agent-tools/tools/integrations/chargebee.ts +0 -14
- package/src/agent-tools/tools/integrations/circleci.ts +0 -14
- package/src/agent-tools/tools/integrations/clickup.ts +0 -14
- package/src/agent-tools/tools/integrations/close.ts +0 -14
- package/src/agent-tools/tools/integrations/cloudflare.ts +0 -14
- package/src/agent-tools/tools/integrations/confluence.ts +0 -14
- package/src/agent-tools/tools/integrations/contentful.ts +0 -14
- package/src/agent-tools/tools/integrations/copper.ts +0 -14
- package/src/agent-tools/tools/integrations/crisp.ts +0 -14
- package/src/agent-tools/tools/integrations/crowdstrike.ts +0 -14
- package/src/agent-tools/tools/integrations/datadog.ts +0 -14
- package/src/agent-tools/tools/integrations/digitalocean.ts +0 -14
- package/src/agent-tools/tools/integrations/discord.ts +0 -14
- package/src/agent-tools/tools/integrations/docker.ts +0 -14
- package/src/agent-tools/tools/integrations/docusign.ts +0 -14
- package/src/agent-tools/tools/integrations/drift.ts +0 -14
- package/src/agent-tools/tools/integrations/dropbox.ts +0 -14
- package/src/agent-tools/tools/integrations/figma.ts +0 -14
- package/src/agent-tools/tools/integrations/firebase.ts +0 -14
- package/src/agent-tools/tools/integrations/flyio.ts +0 -14
- package/src/agent-tools/tools/integrations/freshbooks.ts +0 -14
- package/src/agent-tools/tools/integrations/freshdesk.ts +0 -14
- package/src/agent-tools/tools/integrations/freshsales.ts +0 -14
- package/src/agent-tools/tools/integrations/freshservice.ts +0 -14
- package/src/agent-tools/tools/integrations/front.ts +0 -14
- package/src/agent-tools/tools/integrations/github-actions.ts +0 -14
- package/src/agent-tools/tools/integrations/github.ts +0 -14
- package/src/agent-tools/tools/integrations/gitlab.ts +0 -14
- package/src/agent-tools/tools/integrations/gong.ts +0 -14
- package/src/agent-tools/tools/integrations/google-ads.ts +0 -14
- package/src/agent-tools/tools/integrations/google-analytics.ts +0 -14
- package/src/agent-tools/tools/integrations/google-cloud.ts +0 -14
- package/src/agent-tools/tools/integrations/gotomeeting.ts +0 -14
- package/src/agent-tools/tools/integrations/grafana.ts +0 -14
- package/src/agent-tools/tools/integrations/greenhouse.ts +0 -14
- package/src/agent-tools/tools/integrations/gusto.ts +0 -14
- package/src/agent-tools/tools/integrations/hashicorp-vault.ts +0 -14
- package/src/agent-tools/tools/integrations/heroku.ts +0 -14
- package/src/agent-tools/tools/integrations/hibob.ts +0 -14
- package/src/agent-tools/tools/integrations/hootsuite.ts +0 -14
- package/src/agent-tools/tools/integrations/hubspot.ts +0 -14
- package/src/agent-tools/tools/integrations/huggingface.ts +0 -14
- package/src/agent-tools/tools/integrations/index.ts +0 -474
- package/src/agent-tools/tools/integrations/intercom.ts +0 -14
- package/src/agent-tools/tools/integrations/jira.ts +0 -14
- package/src/agent-tools/tools/integrations/klaviyo.ts +0 -14
- package/src/agent-tools/tools/integrations/kubernetes.ts +0 -14
- package/src/agent-tools/tools/integrations/lattice.ts +0 -14
- package/src/agent-tools/tools/integrations/launchdarkly.ts +0 -14
- package/src/agent-tools/tools/integrations/lever.ts +0 -14
- package/src/agent-tools/tools/integrations/linear.ts +0 -14
- package/src/agent-tools/tools/integrations/linkedin.ts +0 -14
- package/src/agent-tools/tools/integrations/livechat.ts +0 -14
- package/src/agent-tools/tools/integrations/loom.ts +0 -14
- package/src/agent-tools/tools/integrations/mailchimp.ts +0 -14
- package/src/agent-tools/tools/integrations/mailgun.ts +0 -14
- package/src/agent-tools/tools/integrations/miro.ts +0 -14
- package/src/agent-tools/tools/integrations/mixpanel.ts +0 -14
- package/src/agent-tools/tools/integrations/monday.ts +0 -14
- package/src/agent-tools/tools/integrations/mongodb-atlas.ts +0 -14
- package/src/agent-tools/tools/integrations/neon.ts +0 -14
- package/src/agent-tools/tools/integrations/netlify.ts +0 -14
- package/src/agent-tools/tools/integrations/netsuite.ts +0 -14
- package/src/agent-tools/tools/integrations/newrelic.ts +0 -14
- package/src/agent-tools/tools/integrations/notion.ts +0 -14
- package/src/agent-tools/tools/integrations/okta.ts +0 -14
- package/src/agent-tools/tools/integrations/openai.ts +0 -14
- package/src/agent-tools/tools/integrations/opsgenie.ts +0 -14
- package/src/agent-tools/tools/integrations/outreach.ts +0 -14
- package/src/agent-tools/tools/integrations/paddle.ts +0 -14
- package/src/agent-tools/tools/integrations/pagerduty.ts +0 -14
- package/src/agent-tools/tools/integrations/pandadoc.ts +0 -14
- package/src/agent-tools/tools/integrations/paypal.ts +0 -14
- package/src/agent-tools/tools/integrations/personio.ts +0 -14
- package/src/agent-tools/tools/integrations/pinecone.ts +0 -14
- package/src/agent-tools/tools/integrations/pipedrive.ts +0 -14
- package/src/agent-tools/tools/integrations/plaid.ts +0 -14
- package/src/agent-tools/tools/integrations/postmark.ts +0 -14
- package/src/agent-tools/tools/integrations/power-automate.ts +0 -14
- package/src/agent-tools/tools/integrations/quickbooks.ts +0 -14
- package/src/agent-tools/tools/integrations/recurly.ts +0 -14
- package/src/agent-tools/tools/integrations/reddit.ts +0 -14
- package/src/agent-tools/tools/integrations/render.ts +0 -14
- package/src/agent-tools/tools/integrations/ringcentral.ts +0 -14
- package/src/agent-tools/tools/integrations/rippling.ts +0 -14
- package/src/agent-tools/tools/integrations/salesforce.ts +0 -14
- package/src/agent-tools/tools/integrations/salesloft.ts +0 -14
- package/src/agent-tools/tools/integrations/sanity.ts +0 -14
- package/src/agent-tools/tools/integrations/sap.ts +0 -14
- package/src/agent-tools/tools/integrations/segment.ts +0 -14
- package/src/agent-tools/tools/integrations/sendgrid.ts +0 -14
- package/src/agent-tools/tools/integrations/sentry.ts +0 -14
- package/src/agent-tools/tools/integrations/servicenow.ts +0 -14
- package/src/agent-tools/tools/integrations/shopify.ts +0 -14
- package/src/agent-tools/tools/integrations/shortcut.ts +0 -14
- package/src/agent-tools/tools/integrations/slack.ts +0 -14
- package/src/agent-tools/tools/integrations/smartsheet.ts +0 -14
- package/src/agent-tools/tools/integrations/snowflake.ts +0 -14
- package/src/agent-tools/tools/integrations/snyk.ts +0 -14
- package/src/agent-tools/tools/integrations/splunk.ts +0 -14
- package/src/agent-tools/tools/integrations/square.ts +0 -14
- package/src/agent-tools/tools/integrations/statuspage.ts +0 -14
- package/src/agent-tools/tools/integrations/stripe.ts +0 -14
- package/src/agent-tools/tools/integrations/supabase.ts +0 -14
- package/src/agent-tools/tools/integrations/teamwork.ts +0 -14
- package/src/agent-tools/tools/integrations/telegram.ts +0 -14
- package/src/agent-tools/tools/integrations/terraform.ts +0 -14
- package/src/agent-tools/tools/integrations/todoist.ts +0 -14
- package/src/agent-tools/tools/integrations/trello.ts +0 -14
- package/src/agent-tools/tools/integrations/twilio.ts +0 -14
- package/src/agent-tools/tools/integrations/twitter.ts +0 -14
- package/src/agent-tools/tools/integrations/vercel.ts +0 -14
- package/src/agent-tools/tools/integrations/weaviate.ts +0 -14
- package/src/agent-tools/tools/integrations/webex.ts +0 -14
- package/src/agent-tools/tools/integrations/webflow.ts +0 -14
- package/src/agent-tools/tools/integrations/whatsapp.ts +0 -14
- package/src/agent-tools/tools/integrations/whereby.ts +0 -14
- package/src/agent-tools/tools/integrations/woocommerce.ts +0 -14
- package/src/agent-tools/tools/integrations/wordpress.ts +0 -14
- package/src/agent-tools/tools/integrations/workday.ts +0 -14
- package/src/agent-tools/tools/integrations/wrike.ts +0 -14
- package/src/agent-tools/tools/integrations/xero.ts +0 -14
- package/src/agent-tools/tools/integrations/youtube.ts +0 -14
- package/src/agent-tools/tools/integrations/zendesk.ts +0 -14
- package/src/agent-tools/tools/integrations/zoho-crm.ts +0 -14
- package/src/agent-tools/tools/integrations/zoom.ts +0 -14
- package/src/agent-tools/tools/integrations/zuora.ts +0 -14
- package/src/agent-tools/tools/knowledge-search.ts +0 -318
- package/src/agent-tools/tools/local/coding.ts +0 -626
- package/src/agent-tools/tools/local/dependency-manager.ts +0 -647
- package/src/agent-tools/tools/local/file-edit.ts +0 -31
- package/src/agent-tools/tools/local/file-list.ts +0 -39
- package/src/agent-tools/tools/local/file-ops.ts +0 -48
- package/src/agent-tools/tools/local/file-read.ts +0 -39
- package/src/agent-tools/tools/local/file-search.ts +0 -46
- package/src/agent-tools/tools/local/file-write.ts +0 -28
- package/src/agent-tools/tools/local/filesystem.ts +0 -5
- package/src/agent-tools/tools/local/index.ts +0 -55
- package/src/agent-tools/tools/local/resolve-path.ts +0 -18
- package/src/agent-tools/tools/local/shell.ts +0 -277
- package/src/agent-tools/tools/local/system-info.ts +0 -29
- package/src/agent-tools/tools/management.ts +0 -425
- package/src/agent-tools/tools/mcp-bridge.ts +0 -142
- package/src/agent-tools/tools/mcp-server-tools.ts +0 -91
- package/src/agent-tools/tools/meeting-lifecycle.ts +0 -438
- package/src/agent-tools/tools/memory.ts +0 -509
- package/src/agent-tools/tools/messaging/index.ts +0 -6
- package/src/agent-tools/tools/messaging/telegram.ts +0 -167
- package/src/agent-tools/tools/messaging/whatsapp.ts +0 -651
- package/src/agent-tools/tools/microsoft/contacts.ts +0 -176
- package/src/agent-tools/tools/microsoft/excel-vba.ts +0 -331
- package/src/agent-tools/tools/microsoft/excel.ts +0 -261
- package/src/agent-tools/tools/microsoft/graph-api.ts +0 -161
- package/src/agent-tools/tools/microsoft/index.ts +0 -95
- package/src/agent-tools/tools/microsoft/onedrive.ts +0 -429
- package/src/agent-tools/tools/microsoft/onenote.ts +0 -186
- package/src/agent-tools/tools/microsoft/outlook-calendar.ts +0 -286
- package/src/agent-tools/tools/microsoft/outlook-mail.ts +0 -723
- package/src/agent-tools/tools/microsoft/planner.ts +0 -200
- package/src/agent-tools/tools/microsoft/powerbi.ts +0 -266
- package/src/agent-tools/tools/microsoft/powerpoint.ts +0 -186
- package/src/agent-tools/tools/microsoft/sharepoint.ts +0 -328
- package/src/agent-tools/tools/microsoft/teams.ts +0 -463
- package/src/agent-tools/tools/microsoft/todo.ts +0 -181
- package/src/agent-tools/tools/oauth-token-provider.ts +0 -101
- package/src/agent-tools/tools/read.ts +0 -160
- package/src/agent-tools/tools/visual-memory/capture.ts +0 -217
- package/src/agent-tools/tools/visual-memory/diff.ts +0 -283
- package/src/agent-tools/tools/visual-memory/index.ts +0 -698
- package/src/agent-tools/tools/visual-memory/phash.ts +0 -120
- package/src/agent-tools/tools/visual-memory/similarity.ts +0 -354
- package/src/agent-tools/tools/visual-memory/storage.ts +0 -534
- package/src/agent-tools/tools/visual-memory/types.ts +0 -100
- package/src/agent-tools/tools/web-fetch-utils.ts +0 -202
- package/src/agent-tools/tools/web-fetch.ts +0 -464
- package/src/agent-tools/tools/web-search.ts +0 -480
- package/src/agent-tools/tools/web-shared.ts +0 -232
- package/src/agent-tools/tools/write.ts +0 -68
- package/src/agent-tools/types.ts +0 -214
- package/src/agenticmail/index.ts +0 -34
- package/src/agenticmail/manager.ts +0 -253
- package/src/agenticmail/providers/google.ts +0 -391
- package/src/agenticmail/providers/imap.ts +0 -454
- package/src/agenticmail/providers/index.ts +0 -28
- package/src/agenticmail/providers/microsoft.ts +0 -260
- package/src/agenticmail/types.ts +0 -173
- package/src/auth/routes.ts +0 -1589
- package/src/browser/bridge-auth-registry.ts +0 -34
- package/src/browser/bridge-server.ts +0 -93
- package/src/browser/cdp.helpers.ts +0 -180
- package/src/browser/cdp.ts +0 -466
- package/src/browser/chrome.executables.ts +0 -625
- package/src/browser/chrome.profile-decoration.ts +0 -198
- package/src/browser/chrome.ts +0 -349
- package/src/browser/client-actions-core.ts +0 -259
- package/src/browser/client-actions-observe.ts +0 -184
- package/src/browser/client-actions-state.ts +0 -284
- package/src/browser/client-actions-types.ts +0 -16
- package/src/browser/client-actions-url.ts +0 -11
- package/src/browser/client-actions.ts +0 -4
- package/src/browser/client-fetch.ts +0 -253
- package/src/browser/client.ts +0 -337
- package/src/browser/config.ts +0 -301
- package/src/browser/constants.ts +0 -8
- package/src/browser/control-auth.ts +0 -94
- package/src/browser/control-service.ts +0 -81
- package/src/browser/csrf.ts +0 -87
- package/src/browser/enterprise-compat.ts +0 -562
- package/src/browser/extension-relay.ts +0 -834
- package/src/browser/http-auth.ts +0 -63
- package/src/browser/navigation-guard.ts +0 -50
- package/src/browser/paths.ts +0 -49
- package/src/browser/playwright.d.ts +0 -12
- package/src/browser/profiles-service.ts +0 -187
- package/src/browser/profiles.ts +0 -114
- package/src/browser/proxy-files.ts +0 -41
- package/src/browser/pw-ai-module.ts +0 -52
- package/src/browser/pw-ai-state.ts +0 -9
- package/src/browser/pw-ai.ts +0 -65
- package/src/browser/pw-role-snapshot.ts +0 -434
- package/src/browser/pw-session.ts +0 -810
- package/src/browser/pw-tools-core.activity.ts +0 -68
- package/src/browser/pw-tools-core.downloads.ts +0 -281
- package/src/browser/pw-tools-core.interactions.ts +0 -646
- package/src/browser/pw-tools-core.responses.ts +0 -124
- package/src/browser/pw-tools-core.shared.ts +0 -70
- package/src/browser/pw-tools-core.snapshot.ts +0 -213
- package/src/browser/pw-tools-core.state.ts +0 -209
- package/src/browser/pw-tools-core.storage.ts +0 -128
- package/src/browser/pw-tools-core.trace.ts +0 -37
- package/src/browser/pw-tools-core.ts +0 -8
- package/src/browser/resolved-config-refresh.ts +0 -59
- package/src/browser/routes/agent.act.shared.ts +0 -52
- package/src/browser/routes/agent.act.ts +0 -575
- package/src/browser/routes/agent.debug.ts +0 -149
- package/src/browser/routes/agent.shared.ts +0 -143
- package/src/browser/routes/agent.snapshot.ts +0 -333
- package/src/browser/routes/agent.storage.ts +0 -451
- package/src/browser/routes/agent.ts +0 -13
- package/src/browser/routes/basic.ts +0 -202
- package/src/browser/routes/dispatcher.ts +0 -126
- package/src/browser/routes/index.ts +0 -11
- package/src/browser/routes/path-output.ts +0 -1
- package/src/browser/routes/tabs.ts +0 -217
- package/src/browser/routes/types.ts +0 -26
- package/src/browser/routes/utils.ts +0 -73
- package/src/browser/screenshot.ts +0 -54
- package/src/browser/server-context.ts +0 -688
- package/src/browser/server-context.types.ts +0 -65
- package/src/browser/server-lifecycle.ts +0 -48
- package/src/browser/server-middleware.ts +0 -37
- package/src/browser/server.ts +0 -110
- package/src/browser/target-id.ts +0 -30
- package/src/browser/trash.ts +0 -21
- package/src/cli-agent.ts +0 -2452
- package/src/cli-reset-password.ts +0 -138
- package/src/cli-serve.ts +0 -314
- package/src/cli.ts +0 -103
- package/src/dashboard/app.js +0 -579
- package/src/dashboard/assets/brand-logos.js +0 -350
- package/src/dashboard/assets/icons/emoji-icons.js +0 -893
- package/src/dashboard/assets/logo.png +0 -0
- package/src/dashboard/assets/provider-logos.js +0 -139
- package/src/dashboard/components/error-boundary.js +0 -21
- package/src/dashboard/components/help-button.js +0 -65
- package/src/dashboard/components/icons.js +0 -64
- package/src/dashboard/components/knowledge-link.js +0 -79
- package/src/dashboard/components/modal.js +0 -125
- package/src/dashboard/components/org-switcher.js +0 -156
- package/src/dashboard/components/persona-fields.js +0 -460
- package/src/dashboard/components/settings-help.js +0 -193
- package/src/dashboard/components/tag-input.js +0 -96
- package/src/dashboard/components/timezones.js +0 -352
- package/src/dashboard/components/transport-encryption.js +0 -288
- package/src/dashboard/components/utils.js +0 -205
- package/src/dashboard/data/countries.js +0 -255
- package/src/dashboard/docs/activity.html +0 -253
- package/src/dashboard/docs/agent-activity.html +0 -199
- package/src/dashboard/docs/agent-autonomy.html +0 -161
- package/src/dashboard/docs/agent-budget.html +0 -190
- package/src/dashboard/docs/agent-channels.html +0 -189
- package/src/dashboard/docs/agent-communication.html +0 -171
- package/src/dashboard/docs/agent-configuration.html +0 -194
- package/src/dashboard/docs/agent-deployment.html +0 -323
- package/src/dashboard/docs/agent-email.html +0 -184
- package/src/dashboard/docs/agent-guardrails.html +0 -206
- package/src/dashboard/docs/agent-manager.html +0 -226
- package/src/dashboard/docs/agent-memory.html +0 -215
- package/src/dashboard/docs/agent-overview.html +0 -226
- package/src/dashboard/docs/agent-permissions.html +0 -305
- package/src/dashboard/docs/agent-personal.html +0 -155
- package/src/dashboard/docs/agent-security.html +0 -188
- package/src/dashboard/docs/agent-skills.html +0 -224
- package/src/dashboard/docs/agent-tool-security.html +0 -205
- package/src/dashboard/docs/agent-tools.html +0 -238
- package/src/dashboard/docs/agent-whatsapp.html +0 -210
- package/src/dashboard/docs/agent-workforce.html +0 -199
- package/src/dashboard/docs/agents.html +0 -258
- package/src/dashboard/docs/approvals.html +0 -200
- package/src/dashboard/docs/audit.html +0 -206
- package/src/dashboard/docs/browser-providers.html +0 -313
- package/src/dashboard/docs/cluster.html +0 -285
- package/src/dashboard/docs/community-skills.html +0 -253
- package/src/dashboard/docs/compliance.html +0 -221
- package/src/dashboard/docs/dashboard.html +0 -84
- package/src/dashboard/docs/database-access.html +0 -322
- package/src/dashboard/docs/dlp.html +0 -268
- package/src/dashboard/docs/docs-style.css +0 -26
- package/src/dashboard/docs/domain-status.html +0 -294
- package/src/dashboard/docs/guardrails.html +0 -265
- package/src/dashboard/docs/journal.html +0 -197
- package/src/dashboard/docs/knowledge-contributions.html +0 -286
- package/src/dashboard/docs/knowledge.html +0 -268
- package/src/dashboard/docs/memory-transfer.html +0 -311
- package/src/dashboard/docs/messages.html +0 -217
- package/src/dashboard/docs/multi-tenant.html +0 -311
- package/src/dashboard/docs/org-chart.html +0 -239
- package/src/dashboard/docs/organizations.html +0 -182
- package/src/dashboard/docs/roles.html +0 -195
- package/src/dashboard/docs/settings-network.html +0 -321
- package/src/dashboard/docs/settings-security.html +0 -347
- package/src/dashboard/docs/settings-tool-security.html +0 -176
- package/src/dashboard/docs/settings.html +0 -280
- package/src/dashboard/docs/skill-connections.html +0 -270
- package/src/dashboard/docs/skills.html +0 -206
- package/src/dashboard/docs/task-pipeline.html +0 -261
- package/src/dashboard/docs/transport-encryption.html +0 -359
- package/src/dashboard/docs/users.html +0 -225
- package/src/dashboard/docs/vault.html +0 -260
- package/src/dashboard/docs/workforce.html +0 -245
- package/src/dashboard/index.html +0 -444
- package/src/dashboard/pages/activity.js +0 -379
- package/src/dashboard/pages/agent-detail/activity.js +0 -277
- package/src/dashboard/pages/agent-detail/autonomy.js +0 -244
- package/src/dashboard/pages/agent-detail/budget.js +0 -269
- package/src/dashboard/pages/agent-detail/channels.js +0 -494
- package/src/dashboard/pages/agent-detail/communication.js +0 -296
- package/src/dashboard/pages/agent-detail/configuration.js +0 -882
- package/src/dashboard/pages/agent-detail/deployment.js +0 -958
- package/src/dashboard/pages/agent-detail/email.js +0 -674
- package/src/dashboard/pages/agent-detail/guardrails.js +0 -521
- package/src/dashboard/pages/agent-detail/index.js +0 -261
- package/src/dashboard/pages/agent-detail/manager.js +0 -357
- package/src/dashboard/pages/agent-detail/meeting-browser.js +0 -933
- package/src/dashboard/pages/agent-detail/memory.js +0 -368
- package/src/dashboard/pages/agent-detail/overview.js +0 -844
- package/src/dashboard/pages/agent-detail/permissions.js +0 -1163
- package/src/dashboard/pages/agent-detail/personal-details.js +0 -404
- package/src/dashboard/pages/agent-detail/security.js +0 -409
- package/src/dashboard/pages/agent-detail/shared.js +0 -85
- package/src/dashboard/pages/agent-detail/skills-section.js +0 -183
- package/src/dashboard/pages/agent-detail/tool-security.js +0 -380
- package/src/dashboard/pages/agent-detail/tools.js +0 -322
- package/src/dashboard/pages/agent-detail/whatsapp.js +0 -824
- package/src/dashboard/pages/agent-detail/workforce.js +0 -683
- package/src/dashboard/pages/agents.js +0 -1242
- package/src/dashboard/pages/approvals.js +0 -100
- package/src/dashboard/pages/audit.js +0 -198
- package/src/dashboard/pages/cluster.js +0 -512
- package/src/dashboard/pages/community-skills.js +0 -1219
- package/src/dashboard/pages/compliance.js +0 -475
- package/src/dashboard/pages/dashboard.js +0 -180
- package/src/dashboard/pages/database-access.js +0 -812
- package/src/dashboard/pages/dlp.js +0 -293
- package/src/dashboard/pages/domain-status.js +0 -951
- package/src/dashboard/pages/guardrails.js +0 -1035
- package/src/dashboard/pages/journal.js +0 -172
- package/src/dashboard/pages/knowledge-contributions.js +0 -1682
- package/src/dashboard/pages/knowledge-import.js +0 -455
- package/src/dashboard/pages/knowledge.js +0 -582
- package/src/dashboard/pages/login.js +0 -1056
- package/src/dashboard/pages/memory-transfer.js +0 -631
- package/src/dashboard/pages/messages.js +0 -303
- package/src/dashboard/pages/org-chart.js +0 -349
- package/src/dashboard/pages/organizations.js +0 -1081
- package/src/dashboard/pages/roles.js +0 -780
- package/src/dashboard/pages/settings.js +0 -3790
- package/src/dashboard/pages/skill-connections.js +0 -982
- package/src/dashboard/pages/skills.js +0 -879
- package/src/dashboard/pages/task-pipeline.js +0 -684
- package/src/dashboard/pages/users.js +0 -867
- package/src/dashboard/pages/vault.js +0 -791
- package/src/dashboard/pages/workforce.js +0 -851
- package/src/dashboard/vendor/react-dom.development.js +0 -29924
- package/src/dashboard/vendor/react-dom.production.min.js +0 -267
- package/src/dashboard/vendor/react.development.js +0 -3343
- package/src/dashboard/vendor/react.production.min.js +0 -31
- package/src/database-access/agent-tools.ts +0 -193
- package/src/database-access/connection-manager.ts +0 -1341
- package/src/database-access/index.ts +0 -21
- package/src/database-access/query-sanitizer.ts +0 -220
- package/src/database-access/routes.ts +0 -226
- package/src/database-access/types.ts +0 -226
- package/src/db/adapter.ts +0 -510
- package/src/db/dynamodb.ts +0 -454
- package/src/db/factory.ts +0 -129
- package/src/db/mongodb.ts +0 -360
- package/src/db/mysql.ts +0 -531
- package/src/db/postgres.ts +0 -863
- package/src/db/proxy.ts +0 -39
- package/src/db/resolve-driver.ts +0 -29
- package/src/db/sql-schema.ts +0 -124
- package/src/db/sqlite.ts +0 -493
- package/src/db/turso.ts +0 -470
- package/src/deploy/fly.ts +0 -368
- package/src/deploy/managed.ts +0 -235
- package/src/domain-lock/cli-recover.ts +0 -591
- package/src/domain-lock/cli-verify.ts +0 -190
- package/src/domain-lock/index.ts +0 -220
- package/src/engine/activity-routes.ts +0 -154
- package/src/engine/activity.ts +0 -568
- package/src/engine/agent-autonomy.ts +0 -974
- package/src/engine/agent-config.ts +0 -646
- package/src/engine/agent-heartbeat.ts +0 -720
- package/src/engine/agent-hierarchy.ts +0 -1064
- package/src/engine/agent-memory.ts +0 -806
- package/src/engine/agent-notify.ts +0 -50
- package/src/engine/agent-routes.ts +0 -2583
- package/src/engine/agent-status.ts +0 -311
- package/src/engine/ambient-memory.ts +0 -401
- package/src/engine/approvals.ts +0 -615
- package/src/engine/assets/thinking-hum.mp3 +0 -0
- package/src/engine/catalog-routes.ts +0 -232
- package/src/engine/chat-poller.ts +0 -913
- package/src/engine/chat-webhook-routes.ts +0 -304
- package/src/engine/cli-build-skill.ts +0 -285
- package/src/engine/cli-submit-skill.ts +0 -200
- package/src/engine/cli-validate.ts +0 -188
- package/src/engine/cluster.ts +0 -278
- package/src/engine/communication-routes.ts +0 -139
- package/src/engine/communication.ts +0 -765
- package/src/engine/community-registry.ts +0 -1529
- package/src/engine/community-routes.ts +0 -260
- package/src/engine/compliance-routes.ts +0 -133
- package/src/engine/compliance.ts +0 -1679
- package/src/engine/config-bus.ts +0 -103
- package/src/engine/db-adapter.ts +0 -1156
- package/src/engine/db-schema.ts +0 -1945
- package/src/engine/deploy-schema-routes.ts +0 -176
- package/src/engine/deployer.ts +0 -957
- package/src/engine/dlp-routes.ts +0 -101
- package/src/engine/dlp.ts +0 -410
- package/src/engine/email-poller.ts +0 -855
- package/src/engine/emoji.ts +0 -106
- package/src/engine/guardrail-routes.ts +0 -125
- package/src/engine/guardrails.ts +0 -465
- package/src/engine/index.ts +0 -255
- package/src/engine/journal-routes.ts +0 -56
- package/src/engine/journal.ts +0 -249
- package/src/engine/knowledge-contribution-routes.ts +0 -633
- package/src/engine/knowledge-contribution.ts +0 -1386
- package/src/engine/knowledge-import/chunker.ts +0 -241
- package/src/engine/knowledge-import/import-manager.ts +0 -416
- package/src/engine/knowledge-import/index.ts +0 -27
- package/src/engine/knowledge-import/processors/clean.ts +0 -149
- package/src/engine/knowledge-import/processors/extract-gdrive.ts +0 -102
- package/src/engine/knowledge-import/processors/extract-github.ts +0 -74
- package/src/engine/knowledge-import/processors/extract-sharepoint.ts +0 -69
- package/src/engine/knowledge-import/processors/extract-web.ts +0 -275
- package/src/engine/knowledge-import/processors/index.ts +0 -18
- package/src/engine/knowledge-import/processors/pipeline.ts +0 -171
- package/src/engine/knowledge-import/processors/types.ts +0 -78
- package/src/engine/knowledge-import/processors/validate.ts +0 -150
- package/src/engine/knowledge-import/provider-file-upload.ts +0 -95
- package/src/engine/knowledge-import/provider-github.ts +0 -144
- package/src/engine/knowledge-import/provider-google-sites.ts +0 -323
- package/src/engine/knowledge-import/provider-sharepoint.ts +0 -276
- package/src/engine/knowledge-import/provider-url.ts +0 -218
- package/src/engine/knowledge-import/routes.ts +0 -94
- package/src/engine/knowledge-import/types.ts +0 -92
- package/src/engine/knowledge-routes.ts +0 -231
- package/src/engine/knowledge.ts +0 -587
- package/src/engine/lifecycle.ts +0 -1420
- package/src/engine/mcp-process-manager.ts +0 -573
- package/src/engine/meeting-monitor.ts +0 -483
- package/src/engine/meeting-voice-intelligence.ts +0 -340
- package/src/engine/memory-routes.ts +0 -142
- package/src/engine/memory-transfer-routes.ts +0 -339
- package/src/engine/messaging-history.ts +0 -177
- package/src/engine/messaging-poller.ts +0 -786
- package/src/engine/model-fallback.ts +0 -141
- package/src/engine/oauth-connect-routes.ts +0 -603
- package/src/engine/oauth-connect.ts +0 -304
- package/src/engine/onboarding-routes.ts +0 -148
- package/src/engine/onboarding.ts +0 -574
- package/src/engine/org-approval-routes.ts +0 -146
- package/src/engine/org-integration-routes.ts +0 -399
- package/src/engine/org-integrations.ts +0 -608
- package/src/engine/org-policies.ts +0 -502
- package/src/engine/policy-import-routes.ts +0 -125
- package/src/engine/policy-import.ts +0 -1186
- package/src/engine/policy-routes.ts +0 -163
- package/src/engine/routes.ts +0 -1236
- package/src/engine/screen-unlock.ts +0 -136
- package/src/engine/session-router.ts +0 -212
- package/src/engine/skill-updater-routes.ts +0 -132
- package/src/engine/skill-updater.ts +0 -480
- package/src/engine/skill-validator.ts +0 -331
- package/src/engine/skills/agent-management.ts +0 -119
- package/src/engine/skills/agent-memory.ts +0 -19
- package/src/engine/skills/agenticmail.ts +0 -116
- package/src/engine/skills/core-tools.ts +0 -25
- package/src/engine/skills/database-access.ts +0 -78
- package/src/engine/skills/enterprise-code-sandbox.ts +0 -113
- package/src/engine/skills/enterprise-database.ts +0 -123
- package/src/engine/skills/enterprise-diff.ts +0 -95
- package/src/engine/skills/enterprise-documents.ts +0 -162
- package/src/engine/skills/enterprise-http.ts +0 -99
- package/src/engine/skills/enterprise-security-scan.ts +0 -125
- package/src/engine/skills/enterprise-spreadsheet.ts +0 -171
- package/src/engine/skills/gws-admin.ts +0 -18
- package/src/engine/skills/gws-calendar.ts +0 -21
- package/src/engine/skills/gws-chat.ts +0 -29
- package/src/engine/skills/gws-contacts.ts +0 -20
- package/src/engine/skills/gws-docs.ts +0 -18
- package/src/engine/skills/gws-drive.ts +0 -23
- package/src/engine/skills/gws-forms.ts +0 -23
- package/src/engine/skills/gws-gmail.ts +0 -30
- package/src/engine/skills/gws-groups.ts +0 -17
- package/src/engine/skills/gws-keep.ts +0 -17
- package/src/engine/skills/gws-maps.ts +0 -25
- package/src/engine/skills/gws-meet.ts +0 -23
- package/src/engine/skills/gws-sheets.ts +0 -22
- package/src/engine/skills/gws-sites.ts +0 -16
- package/src/engine/skills/gws-slides.ts +0 -27
- package/src/engine/skills/gws-tasks.ts +0 -22
- package/src/engine/skills/gws-vault.ts +0 -17
- package/src/engine/skills/index.ts +0 -159
- package/src/engine/skills/knowledge-search.ts +0 -18
- package/src/engine/skills/local-system.ts +0 -61
- package/src/engine/skills/m365-admin.ts +0 -18
- package/src/engine/skills/m365-bookings.ts +0 -17
- package/src/engine/skills/m365-copilot.ts +0 -17
- package/src/engine/skills/m365-excel.ts +0 -60
- package/src/engine/skills/m365-forms.ts +0 -17
- package/src/engine/skills/m365-onedrive.ts +0 -60
- package/src/engine/skills/m365-onenote.ts +0 -17
- package/src/engine/skills/m365-outlook.ts +0 -27
- package/src/engine/skills/m365-planner.ts +0 -18
- package/src/engine/skills/m365-power-automate.ts +0 -18
- package/src/engine/skills/m365-power-bi.ts +0 -19
- package/src/engine/skills/m365-powerpoint.ts +0 -33
- package/src/engine/skills/m365-sharepoint.ts +0 -20
- package/src/engine/skills/m365-teams.ts +0 -21
- package/src/engine/skills/m365-todo.ts +0 -17
- package/src/engine/skills/m365-whiteboard.ts +0 -16
- package/src/engine/skills/m365-word.ts +0 -42
- package/src/engine/skills/mcp-bridge.ts +0 -45
- package/src/engine/skills/meeting-lifecycle.ts +0 -20
- package/src/engine/skills/messaging.ts +0 -46
- package/src/engine/skills/visual-memory.ts +0 -25
- package/src/engine/skills.ts +0 -688
- package/src/engine/soul-library.ts +0 -142
- package/src/engine/soul-templates.json +0 -1525
- package/src/engine/storage-manager.ts +0 -252
- package/src/engine/storage-routes.ts +0 -113
- package/src/engine/storage.ts +0 -528
- package/src/engine/task-poller.ts +0 -394
- package/src/engine/task-queue-after-spawn.ts +0 -66
- package/src/engine/task-queue-before-spawn.ts +0 -113
- package/src/engine/task-queue-routes.ts +0 -161
- package/src/engine/task-queue.ts +0 -664
- package/src/engine/tenant.ts +0 -409
- package/src/engine/tool-catalog.ts +0 -354
- package/src/engine/vault-routes.ts +0 -134
- package/src/engine/vault.ts +0 -601
- package/src/engine/workforce-routes.ts +0 -331
- package/src/engine/workforce.ts +0 -1161
- package/src/index.ts +0 -77
- package/src/lib/cidr.ts +0 -122
- package/src/lib/config-store.ts +0 -86
- package/src/lib/resilience.ts +0 -326
- package/src/lib/text-search.ts +0 -358
- package/src/mcp/adapters/activecampaign.adapter.ts +0 -391
- package/src/mcp/adapters/adobe-sign.adapter.ts +0 -469
- package/src/mcp/adapters/adp.adapter.ts +0 -358
- package/src/mcp/adapters/airtable.adapter.ts +0 -273
- package/src/mcp/adapters/apollo.adapter.ts +0 -420
- package/src/mcp/adapters/asana.adapter.ts +0 -315
- package/src/mcp/adapters/auth0.adapter.ts +0 -386
- package/src/mcp/adapters/aws.adapter.ts +0 -345
- package/src/mcp/adapters/azure-devops.adapter.ts +0 -389
- package/src/mcp/adapters/bamboohr.adapter.ts +0 -376
- package/src/mcp/adapters/basecamp.adapter.ts +0 -366
- package/src/mcp/adapters/bigcommerce.adapter.ts +0 -429
- package/src/mcp/adapters/bitbucket.adapter.ts +0 -260
- package/src/mcp/adapters/box.adapter.ts +0 -350
- package/src/mcp/adapters/brex.adapter.ts +0 -367
- package/src/mcp/adapters/buffer.adapter.ts +0 -303
- package/src/mcp/adapters/calendly.adapter.ts +0 -262
- package/src/mcp/adapters/canva.adapter.ts +0 -256
- package/src/mcp/adapters/chargebee.adapter.ts +0 -448
- package/src/mcp/adapters/circleci.adapter.ts +0 -216
- package/src/mcp/adapters/clickup.adapter.ts +0 -335
- package/src/mcp/adapters/close.adapter.ts +0 -390
- package/src/mcp/adapters/cloudflare.adapter.ts +0 -378
- package/src/mcp/adapters/confluence.adapter.ts +0 -301
- package/src/mcp/adapters/contentful.adapter.ts +0 -355
- package/src/mcp/adapters/copper.adapter.ts +0 -468
- package/src/mcp/adapters/crisp.adapter.ts +0 -415
- package/src/mcp/adapters/crowdstrike.adapter.ts +0 -413
- package/src/mcp/adapters/datadog.adapter.ts +0 -373
- package/src/mcp/adapters/digitalocean.adapter.ts +0 -336
- package/src/mcp/adapters/discord.adapter.ts +0 -248
- package/src/mcp/adapters/docker.adapter.ts +0 -238
- package/src/mcp/adapters/docusign.adapter.ts +0 -431
- package/src/mcp/adapters/drift.adapter.ts +0 -386
- package/src/mcp/adapters/dropbox.adapter.ts +0 -315
- package/src/mcp/adapters/figma.adapter.ts +0 -302
- package/src/mcp/adapters/firebase.adapter.ts +0 -446
- package/src/mcp/adapters/flyio.adapter.ts +0 -302
- package/src/mcp/adapters/freshbooks.adapter.ts +0 -474
- package/src/mcp/adapters/freshdesk.adapter.ts +0 -441
- package/src/mcp/adapters/freshsales.adapter.ts +0 -457
- package/src/mcp/adapters/freshservice.adapter.ts +0 -481
- package/src/mcp/adapters/front.adapter.ts +0 -357
- package/src/mcp/adapters/github-actions.adapter.ts +0 -329
- package/src/mcp/adapters/github.adapter.ts +0 -387
- package/src/mcp/adapters/gitlab.adapter.ts +0 -368
- package/src/mcp/adapters/gong.adapter.ts +0 -386
- package/src/mcp/adapters/google-ads.adapter.ts +0 -363
- package/src/mcp/adapters/google-analytics.adapter.ts +0 -316
- package/src/mcp/adapters/google-cloud.adapter.ts +0 -312
- package/src/mcp/adapters/gotomeeting.adapter.ts +0 -255
- package/src/mcp/adapters/grafana.adapter.ts +0 -361
- package/src/mcp/adapters/greenhouse.adapter.ts +0 -354
- package/src/mcp/adapters/gusto.adapter.ts +0 -329
- package/src/mcp/adapters/hashicorp-vault.adapter.ts +0 -355
- package/src/mcp/adapters/heroku.adapter.ts +0 -291
- package/src/mcp/adapters/hibob.adapter.ts +0 -334
- package/src/mcp/adapters/hootsuite.adapter.ts +0 -322
- package/src/mcp/adapters/hubspot.adapter.ts +0 -400
- package/src/mcp/adapters/huggingface.adapter.ts +0 -349
- package/src/mcp/adapters/index.ts +0 -524
- package/src/mcp/adapters/intercom.adapter.ts +0 -269
- package/src/mcp/adapters/jira.adapter.ts +0 -482
- package/src/mcp/adapters/klaviyo.adapter.ts +0 -353
- package/src/mcp/adapters/kubernetes.adapter.ts +0 -431
- package/src/mcp/adapters/lattice.adapter.ts +0 -339
- package/src/mcp/adapters/launchdarkly.adapter.ts +0 -368
- package/src/mcp/adapters/lever.adapter.ts +0 -347
- package/src/mcp/adapters/linear.adapter.ts +0 -300
- package/src/mcp/adapters/linkedin.adapter.ts +0 -331
- package/src/mcp/adapters/livechat.adapter.ts +0 -259
- package/src/mcp/adapters/loom.adapter.ts +0 -230
- package/src/mcp/adapters/mailchimp.adapter.ts +0 -394
- package/src/mcp/adapters/mailgun.adapter.ts +0 -425
- package/src/mcp/adapters/miro.adapter.ts +0 -274
- package/src/mcp/adapters/mixpanel.adapter.ts +0 -324
- package/src/mcp/adapters/monday.adapter.ts +0 -308
- package/src/mcp/adapters/mongodb-atlas.adapter.ts +0 -345
- package/src/mcp/adapters/neon.adapter.ts +0 -312
- package/src/mcp/adapters/netlify.adapter.ts +0 -324
- package/src/mcp/adapters/netsuite.adapter.ts +0 -411
- package/src/mcp/adapters/newrelic.adapter.ts +0 -339
- package/src/mcp/adapters/notion.adapter.ts +0 -338
- package/src/mcp/adapters/okta.adapter.ts +0 -394
- package/src/mcp/adapters/openai.adapter.ts +0 -315
- package/src/mcp/adapters/opsgenie.adapter.ts +0 -375
- package/src/mcp/adapters/outreach.adapter.ts +0 -372
- package/src/mcp/adapters/paddle.adapter.ts +0 -467
- package/src/mcp/adapters/pagerduty.adapter.ts +0 -412
- package/src/mcp/adapters/pandadoc.adapter.ts +0 -389
- package/src/mcp/adapters/paypal.adapter.ts +0 -465
- package/src/mcp/adapters/personio.adapter.ts +0 -401
- package/src/mcp/adapters/pinecone.adapter.ts +0 -340
- package/src/mcp/adapters/pipedrive.adapter.ts +0 -324
- package/src/mcp/adapters/plaid.adapter.ts +0 -444
- package/src/mcp/adapters/postmark.adapter.ts +0 -387
- package/src/mcp/adapters/power-automate.adapter.ts +0 -388
- package/src/mcp/adapters/quickbooks.adapter.ts +0 -431
- package/src/mcp/adapters/recurly.adapter.ts +0 -433
- package/src/mcp/adapters/reddit.adapter.ts +0 -371
- package/src/mcp/adapters/render.adapter.ts +0 -332
- package/src/mcp/adapters/ringcentral.adapter.ts +0 -281
- package/src/mcp/adapters/rippling.adapter.ts +0 -287
- package/src/mcp/adapters/salesforce.adapter.ts +0 -321
- package/src/mcp/adapters/salesloft.adapter.ts +0 -413
- package/src/mcp/adapters/sanity.adapter.ts +0 -363
- package/src/mcp/adapters/sap.adapter.ts +0 -483
- package/src/mcp/adapters/segment.adapter.ts +0 -260
- package/src/mcp/adapters/sendgrid.adapter.ts +0 -265
- package/src/mcp/adapters/sentry.adapter.ts +0 -331
- package/src/mcp/adapters/servicenow.adapter.ts +0 -468
- package/src/mcp/adapters/shopify.adapter.ts +0 -451
- package/src/mcp/adapters/shortcut.adapter.ts +0 -290
- package/src/mcp/adapters/slack.adapter.ts +0 -380
- package/src/mcp/adapters/smartsheet.adapter.ts +0 -326
- package/src/mcp/adapters/snowflake.adapter.ts +0 -347
- package/src/mcp/adapters/snyk.adapter.ts +0 -394
- package/src/mcp/adapters/splunk.adapter.ts +0 -403
- package/src/mcp/adapters/square.adapter.ts +0 -467
- package/src/mcp/adapters/statuspage.adapter.ts +0 -401
- package/src/mcp/adapters/stripe.adapter.ts +0 -380
- package/src/mcp/adapters/supabase.adapter.ts +0 -334
- package/src/mcp/adapters/teamwork.adapter.ts +0 -404
- package/src/mcp/adapters/telegram.adapter.ts +0 -299
- package/src/mcp/adapters/terraform.adapter.ts +0 -300
- package/src/mcp/adapters/todoist.adapter.ts +0 -239
- package/src/mcp/adapters/trello.adapter.ts +0 -316
- package/src/mcp/adapters/twilio.adapter.ts +0 -233
- package/src/mcp/adapters/twitter.adapter.ts +0 -348
- package/src/mcp/adapters/vercel.adapter.ts +0 -219
- package/src/mcp/adapters/weaviate.adapter.ts +0 -371
- package/src/mcp/adapters/webex.adapter.ts +0 -237
- package/src/mcp/adapters/webflow.adapter.ts +0 -287
- package/src/mcp/adapters/whatsapp.adapter.ts +0 -273
- package/src/mcp/adapters/whereby.adapter.ts +0 -240
- package/src/mcp/adapters/woocommerce.adapter.ts +0 -454
- package/src/mcp/adapters/wordpress.adapter.ts +0 -455
- package/src/mcp/adapters/workday.adapter.ts +0 -354
- package/src/mcp/adapters/wrike.adapter.ts +0 -349
- package/src/mcp/adapters/xero.adapter.ts +0 -472
- package/src/mcp/adapters/youtube.adapter.ts +0 -401
- package/src/mcp/adapters/zendesk.adapter.ts +0 -399
- package/src/mcp/adapters/zoho-crm.adapter.ts +0 -410
- package/src/mcp/adapters/zoom.adapter.ts +0 -241
- package/src/mcp/adapters/zuora.adapter.ts +0 -476
- package/src/mcp/framework/api-executor.ts +0 -192
- package/src/mcp/framework/aws-sigv4.ts +0 -216
- package/src/mcp/framework/credential-resolver.ts +0 -128
- package/src/mcp/framework/oauth-token-manager.ts +0 -22
- package/src/mcp/framework/skill-mcp-framework.ts +0 -226
- package/src/mcp/framework/types.ts +0 -130
- package/src/mcp/index.ts +0 -124
- package/src/mcp/integration-catalog.ts +0 -178
- package/src/middleware/dns-rebinding.ts +0 -44
- package/src/middleware/egress-filter.ts +0 -104
- package/src/middleware/firewall.ts +0 -192
- package/src/middleware/geo-ip.ts +0 -156
- package/src/middleware/index.ts +0 -390
- package/src/middleware/network-config.ts +0 -90
- package/src/middleware/proxy-config.ts +0 -71
- package/src/middleware/request-limits.ts +0 -59
- package/src/middleware/transport-encryption.ts +0 -398
- package/src/registry/cli.ts +0 -63
- package/src/registry/server.ts +0 -504
- package/src/runtime/agent-loop.ts +0 -779
- package/src/runtime/compaction.ts +0 -638
- package/src/runtime/email-channel.ts +0 -120
- package/src/runtime/environment.ts +0 -300
- package/src/runtime/followup.ts +0 -211
- package/src/runtime/gateway.ts +0 -260
- package/src/runtime/hooks.ts +0 -564
- package/src/runtime/index.ts +0 -1110
- package/src/runtime/llm-client.ts +0 -1056
- package/src/runtime/model-router.ts +0 -97
- package/src/runtime/providers.ts +0 -228
- package/src/runtime/session-manager.ts +0 -345
- package/src/runtime/subagent.ts +0 -153
- package/src/runtime/tool-executor.ts +0 -208
- package/src/runtime/types.ts +0 -255
- package/src/security/brute-force.ts +0 -423
- package/src/security/config.ts +0 -159
- package/src/security/csp.ts +0 -407
- package/src/security/external-content.ts +0 -299
- package/src/security/index.ts +0 -557
- package/src/security/input-sanitizer.ts +0 -452
- package/src/security/output-filter.ts +0 -575
- package/src/security/port-scanner.ts +0 -342
- package/src/security/prompt-guard.ts +0 -387
- package/src/security/sql-guard.ts +0 -338
- package/src/security/threat-logger.ts +0 -484
- package/src/server.ts +0 -828
- package/src/setup/company.ts +0 -183
- package/src/setup/database.ts +0 -153
- package/src/setup/deployment.ts +0 -561
- package/src/setup/domain.ts +0 -112
- package/src/setup/index.ts +0 -171
- package/src/setup/provision.ts +0 -532
- package/src/setup/registration.ts +0 -302
- package/src/system-prompts/catchup.ts +0 -48
- package/src/system-prompts/google/calendar.ts +0 -37
- package/src/system-prompts/google/chat.ts +0 -92
- package/src/system-prompts/google/contacts.ts +0 -25
- package/src/system-prompts/google/docs.ts +0 -29
- package/src/system-prompts/google/drive.ts +0 -34
- package/src/system-prompts/google/forms.ts +0 -25
- package/src/system-prompts/google/gmail.ts +0 -50
- package/src/system-prompts/google/index.ts +0 -23
- package/src/system-prompts/google/maps.ts +0 -20
- package/src/system-prompts/google/meet.ts +0 -130
- package/src/system-prompts/google/sheets.ts +0 -32
- package/src/system-prompts/google/slides.ts +0 -26
- package/src/system-prompts/google/tasks.ts +0 -27
- package/src/system-prompts/index.ts +0 -88
- package/src/system-prompts/microsoft/contacts.ts +0 -34
- package/src/system-prompts/microsoft/excel.ts +0 -52
- package/src/system-prompts/microsoft/index.ts +0 -31
- package/src/system-prompts/microsoft/onedrive.ts +0 -41
- package/src/system-prompts/microsoft/onenote.ts +0 -36
- package/src/system-prompts/microsoft/outlook-calendar.ts +0 -37
- package/src/system-prompts/microsoft/outlook-mail.ts +0 -46
- package/src/system-prompts/microsoft/planner.ts +0 -37
- package/src/system-prompts/microsoft/powerbi.ts +0 -38
- package/src/system-prompts/microsoft/powerpoint.ts +0 -35
- package/src/system-prompts/microsoft/sharepoint.ts +0 -44
- package/src/system-prompts/microsoft/teams.ts +0 -49
- package/src/system-prompts/microsoft/todo.ts +0 -37
- package/src/system-prompts/shared-blocks.ts +0 -87
- package/src/system-prompts/task.ts +0 -21
- package/src/system-prompts/triage.ts +0 -34
- package/src/types/hono-env.ts +0 -18
- package/src/types/optional-deps.d.ts +0 -10
- /package/{src → dist}/dashboard/HELP-TOOLTIPS-GUIDE.md +0 -0
|
@@ -1,2583 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Lifecycle + Budget + Bridge Routes
|
|
3
|
-
* Mounted at / on the engine sub-app (routes define /agents/*, /usage/*, /budget/*, /bridge/*).
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Emoji } from './emoji.js';
|
|
7
|
-
import { configBus } from './config-bus.js';
|
|
8
|
-
import { Hono } from 'hono';
|
|
9
|
-
import type { AgentLifecycleManager } from './lifecycle.js';
|
|
10
|
-
import type { PermissionEngine } from './skills.js';
|
|
11
|
-
import type { DatabaseAdapter } from '../db/adapter.js';
|
|
12
|
-
|
|
13
|
-
export function createAgentRoutes(opts: {
|
|
14
|
-
lifecycle: AgentLifecycleManager;
|
|
15
|
-
permissions: PermissionEngine;
|
|
16
|
-
getAdminDb: () => DatabaseAdapter | null;
|
|
17
|
-
engineDb?: any;
|
|
18
|
-
}) {
|
|
19
|
-
const { lifecycle, permissions, getAdminDb } = opts;
|
|
20
|
-
const router = new Hono();
|
|
21
|
-
|
|
22
|
-
// ─── Agent Lifecycle ────────────────────────────────────
|
|
23
|
-
|
|
24
|
-
router.post('/agents', async (c) => {
|
|
25
|
-
const { orgId, config, createdBy } = await c.req.json();
|
|
26
|
-
try {
|
|
27
|
-
const actor = c.req.header('X-User-Id') || createdBy;
|
|
28
|
-
const agent = await lifecycle.createAgent(orgId, config, actor);
|
|
29
|
-
return c.json({ agent }, 201);
|
|
30
|
-
} catch (e: any) {
|
|
31
|
-
return c.json({ error: e.message }, 400);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
router.get('/agents', (c) => {
|
|
36
|
-
const orgId = c.req.query('orgId');
|
|
37
|
-
const clientOrgId = c.req.query('clientOrgId');
|
|
38
|
-
let agents = orgId ? lifecycle.getAgentsByOrg(orgId) : lifecycle.getAllAgents();
|
|
39
|
-
if (clientOrgId) {
|
|
40
|
-
agents = agents.filter(a => (a as any).clientOrgId === clientOrgId || (a as any).client_org_id === clientOrgId);
|
|
41
|
-
}
|
|
42
|
-
return c.json({ agents, total: agents.length });
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
router.get('/agents/:id', async (c) => {
|
|
46
|
-
const agent = lifecycle.getAgent(c.req.param('id'));
|
|
47
|
-
if (!agent) return c.json({ error: 'Agent not found' }, 404);
|
|
48
|
-
// Refresh state and usage from DB (agent machine writes directly)
|
|
49
|
-
try {
|
|
50
|
-
const fresh = await lifecycle.loadAgentFromDb(c.req.param('id'));
|
|
51
|
-
if (fresh) {
|
|
52
|
-
if (fresh.state) agent.state = fresh.state;
|
|
53
|
-
if (fresh.usage) agent.usage = fresh.usage;
|
|
54
|
-
}
|
|
55
|
-
} catch {}
|
|
56
|
-
return c.json({ agent });
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
router.patch('/agents/:id/config', async (c) => {
|
|
60
|
-
const { updates, updatedBy } = await c.req.json();
|
|
61
|
-
try {
|
|
62
|
-
const agentId = c.req.param('id');
|
|
63
|
-
const actor = c.req.header('X-User-Id') || updatedBy;
|
|
64
|
-
|
|
65
|
-
// Capture old deployment config for change detection
|
|
66
|
-
const oldAgent = lifecycle.getAgent(agentId);
|
|
67
|
-
const oldDep = oldAgent?.config?.deployment;
|
|
68
|
-
|
|
69
|
-
const agent = await lifecycle.updateConfig(agentId, updates, actor);
|
|
70
|
-
|
|
71
|
-
// Sync name/email to admin agents table
|
|
72
|
-
const adminDb = getAdminDb();
|
|
73
|
-
if (adminDb && (updates.name || updates.email)) {
|
|
74
|
-
const sync: any = {};
|
|
75
|
-
if (updates.name) sync.name = updates.name;
|
|
76
|
-
if (updates.email) sync.email = updates.email;
|
|
77
|
-
adminDb.updateAgent(agentId, sync).catch(() => {});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Auto-restart agent if deployment config changed (port, host, target)
|
|
81
|
-
if (updates.deployment) {
|
|
82
|
-
const newDep = agent.config?.deployment;
|
|
83
|
-
const portChanged = oldDep?.port !== newDep?.port;
|
|
84
|
-
const hostChanged = oldDep?.host !== newDep?.host;
|
|
85
|
-
const targetChanged = oldDep?.target !== newDep?.target;
|
|
86
|
-
if (portChanged || hostChanged || targetChanged) {
|
|
87
|
-
console.log(`[agent-routes] Deployment config changed for ${agent.name || agentId} (port: ${oldDep?.port}→${newDep?.port}, host: ${oldDep?.host}→${newDep?.host}). Triggering agent restart...`);
|
|
88
|
-
// Try PM2 restart for locally deployed agents
|
|
89
|
-
try {
|
|
90
|
-
const { exec } = await import('node:child_process');
|
|
91
|
-
const pm2Name = (agent.name || '').toLowerCase().replace(/\s+/g, '-') + '-agent';
|
|
92
|
-
exec(`pm2 restart ${pm2Name} --update-env 2>/dev/null || pm2 restart ${agentId} --update-env 2>/dev/null`, (err) => {
|
|
93
|
-
if (err) console.warn(`[agent-routes] PM2 restart for ${pm2Name} failed (may not be PM2-managed): ${err.message}`);
|
|
94
|
-
else console.log(`[agent-routes] PM2 restart triggered for ${pm2Name}`);
|
|
95
|
-
});
|
|
96
|
-
} catch (e: any) {
|
|
97
|
-
console.warn(`[agent-routes] Agent restart failed: ${e.message}`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return c.json({ agent });
|
|
103
|
-
} catch (e: any) {
|
|
104
|
-
return c.json({ error: e.message }, 400);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
router.post('/agents/:id/deploy', async (c) => {
|
|
109
|
-
const { deployedBy } = await c.req.json();
|
|
110
|
-
try {
|
|
111
|
-
const actor = c.req.header('X-User-Id') || deployedBy;
|
|
112
|
-
const agent = await lifecycle.deploy(c.req.param('id'), actor);
|
|
113
|
-
return c.json({ agent });
|
|
114
|
-
} catch (e: any) {
|
|
115
|
-
return c.json({ error: e.message }, 400);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
router.post('/agents/:id/reset-state', async (c) => {
|
|
120
|
-
try {
|
|
121
|
-
const agent = lifecycle.getAgent(c.req.param('id'));
|
|
122
|
-
if (!agent) return c.json({ error: 'Agent not found' }, 404);
|
|
123
|
-
if (!['error', 'degraded', 'deploying', 'provisioning', 'starting', 'draft'].includes(agent.state)) {
|
|
124
|
-
return c.json({ error: `Cannot reset from state "${agent.state}"` }, 400);
|
|
125
|
-
}
|
|
126
|
-
// Reset to ready
|
|
127
|
-
(agent as any).state = 'ready';
|
|
128
|
-
(agent as any).stateMessage = 'State reset by admin';
|
|
129
|
-
(agent as any).updatedAt = new Date().toISOString();
|
|
130
|
-
await lifecycle.saveAgent(c.req.param('id'));
|
|
131
|
-
return c.json({ agent, message: 'State reset to ready' });
|
|
132
|
-
} catch (e: any) {
|
|
133
|
-
return c.json({ error: e.message }, 400);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
router.post('/agents/:id/stop', async (c) => {
|
|
138
|
-
const { stoppedBy, reason } = await c.req.json();
|
|
139
|
-
try {
|
|
140
|
-
const actor = c.req.header('X-User-Id') || stoppedBy;
|
|
141
|
-
const agent = await lifecycle.stop(c.req.param('id'), actor, reason);
|
|
142
|
-
return c.json({ agent });
|
|
143
|
-
} catch (e: any) {
|
|
144
|
-
return c.json({ error: e.message }, 400);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
router.post('/agents/:id/restart', async (c) => {
|
|
149
|
-
const { restartedBy } = await c.req.json();
|
|
150
|
-
try {
|
|
151
|
-
const actor = c.req.header('X-User-Id') || restartedBy;
|
|
152
|
-
const agent = await lifecycle.restart(c.req.param('id'), actor);
|
|
153
|
-
return c.json({ agent });
|
|
154
|
-
} catch (e: any) {
|
|
155
|
-
return c.json({ error: e.message }, 400);
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
router.post('/agents/:id/hot-update', async (c) => {
|
|
160
|
-
const { updates, updatedBy } = await c.req.json();
|
|
161
|
-
try {
|
|
162
|
-
const actor = c.req.header('X-User-Id') || updatedBy;
|
|
163
|
-
const agent = await lifecycle.hotUpdate(c.req.param('id'), updates, actor);
|
|
164
|
-
// Sync name/email to admin agents table
|
|
165
|
-
const adminDb = getAdminDb();
|
|
166
|
-
if (adminDb && (updates.name || updates.email)) {
|
|
167
|
-
const sync: any = {};
|
|
168
|
-
if (updates.name) sync.name = updates.name;
|
|
169
|
-
if (updates.email) sync.email = updates.email;
|
|
170
|
-
adminDb.updateAgent(c.req.param('id'), sync).catch(() => {});
|
|
171
|
-
}
|
|
172
|
-
return c.json({ agent });
|
|
173
|
-
} catch (e: any) {
|
|
174
|
-
return c.json({ error: e.message }, 400);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
// ─── Inject a system message into an agent's active session ──────
|
|
179
|
-
router.post('/agents/:id/inject-message', async (c) => {
|
|
180
|
-
try {
|
|
181
|
-
const { role, content } = await c.req.json();
|
|
182
|
-
if (!content) return c.json({ error: 'content is required' }, 400);
|
|
183
|
-
const agentId = c.req.param('id');
|
|
184
|
-
|
|
185
|
-
// Find the agent's active session in the runtime
|
|
186
|
-
const runtime = (globalThis as any).__agenticmail_runtime;
|
|
187
|
-
if (!runtime) return c.json({ error: 'Runtime not available' }, 503);
|
|
188
|
-
|
|
189
|
-
// Try to send via the runtime's session manager (private, accessed via any)
|
|
190
|
-
const sessionMgr = (runtime as any).sessionManager;
|
|
191
|
-
if (!sessionMgr) return c.json({ error: 'Session manager not available' }, 503);
|
|
192
|
-
|
|
193
|
-
// Find active sessions for this agent
|
|
194
|
-
const activeSessions = await sessionMgr.findActiveSessions();
|
|
195
|
-
const agentSessions = activeSessions.filter((s: any) => s.agentId === agentId);
|
|
196
|
-
|
|
197
|
-
if (agentSessions.length === 0) {
|
|
198
|
-
return c.json({ injected: false, reason: 'No active sessions for this agent' });
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Inject into the most recent active session
|
|
202
|
-
const session = agentSessions[agentSessions.length - 1];
|
|
203
|
-
await sessionMgr.appendMessage(session.id, {
|
|
204
|
-
role: role || 'system',
|
|
205
|
-
content: content,
|
|
206
|
-
timestamp: new Date().toISOString(),
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
return c.json({ injected: true, sessionId: session.id });
|
|
210
|
-
} catch (e: any) {
|
|
211
|
-
return c.json({ error: e.message }, 500);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
router.delete('/agents/:id', async (c) => {
|
|
216
|
-
const { destroyedBy } = await c.req.json().catch(() => ({ destroyedBy: 'unknown' }));
|
|
217
|
-
try {
|
|
218
|
-
const actor = c.req.header('X-User-Id') || destroyedBy;
|
|
219
|
-
await lifecycle.destroy(c.req.param('id'), actor);
|
|
220
|
-
return c.json({ success: true });
|
|
221
|
-
} catch (e: any) {
|
|
222
|
-
return c.json({ error: e.message }, 400);
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
router.get('/agents/:id/usage', async (c) => {
|
|
227
|
-
const agentId = c.req.param('id');
|
|
228
|
-
const agent = lifecycle.getAgent(agentId);
|
|
229
|
-
if (!agent) return c.json({ error: 'Agent not found' }, 404);
|
|
230
|
-
// Read fresh usage from DB (agent machine writes directly to DB, not to this server's memory)
|
|
231
|
-
try {
|
|
232
|
-
const freshAgent = await lifecycle.loadAgentFromDb(agentId);
|
|
233
|
-
if (freshAgent) {
|
|
234
|
-
const dbUsage = freshAgent.usage || {};
|
|
235
|
-
const freshState = freshAgent.state || agent.state;
|
|
236
|
-
// Also update in-memory state so other endpoints see it
|
|
237
|
-
if (freshAgent.state && freshAgent.state !== agent.state) {
|
|
238
|
-
agent.state = freshAgent.state;
|
|
239
|
-
}
|
|
240
|
-
if (dbUsage.tokensToday > 0 || (dbUsage.lastUpdated && dbUsage.lastUpdated > (agent.usage?.lastUpdated || ''))) {
|
|
241
|
-
return c.json({ usage: dbUsage, health: agent.health, state: freshState });
|
|
242
|
-
}
|
|
243
|
-
return c.json({ usage: agent.usage, health: agent.health, state: freshState });
|
|
244
|
-
}
|
|
245
|
-
} catch (err: any) {
|
|
246
|
-
console.error('[usage-api] DB load failed:', err.message);
|
|
247
|
-
}
|
|
248
|
-
return c.json({ usage: agent.usage, health: agent.health, state: agent.state });
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
router.get('/usage/:orgId', (c) => {
|
|
252
|
-
return c.json(lifecycle.getOrgUsage(c.req.param('orgId')));
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
// ─── Per-Agent Budget Controls ─────────────────────────
|
|
256
|
-
|
|
257
|
-
router.get('/agents/:id/budget', (c) => {
|
|
258
|
-
const config = lifecycle.getBudgetConfig(c.req.param('id'));
|
|
259
|
-
if (!config) return c.json({ budgetConfig: null });
|
|
260
|
-
return c.json({ budgetConfig: config });
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
router.put('/agents/:id/budget', async (c) => {
|
|
264
|
-
const config = await c.req.json();
|
|
265
|
-
try {
|
|
266
|
-
const aid = c.req.param('id');
|
|
267
|
-
await lifecycle.setBudgetConfig(aid, config);
|
|
268
|
-
import('./agent-notify.js').then(({ notifyAgent }) => notifyAgent(aid, 'budget', lifecycle)).catch(() => {});
|
|
269
|
-
return c.json({ success: true, budgetConfig: config });
|
|
270
|
-
} catch (e: any) {
|
|
271
|
-
return c.json({ error: e.message }, 400);
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
router.get('/budget/alerts', (c) => {
|
|
276
|
-
const alerts = lifecycle.getBudgetAlerts({
|
|
277
|
-
orgId: c.req.query('orgId') || undefined,
|
|
278
|
-
agentId: c.req.query('agentId') || undefined,
|
|
279
|
-
acknowledged: c.req.query('acknowledged') === 'true' ? true : c.req.query('acknowledged') === 'false' ? false : undefined,
|
|
280
|
-
limit: parseInt(c.req.query('limit') || '50'),
|
|
281
|
-
});
|
|
282
|
-
return c.json({ alerts, total: alerts.length });
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
router.post('/budget/alerts/:id/acknowledge', async (c) => {
|
|
286
|
-
try {
|
|
287
|
-
await lifecycle.acknowledgeBudgetAlert(c.req.param('id'));
|
|
288
|
-
return c.json({ success: true });
|
|
289
|
-
} catch (e: any) {
|
|
290
|
-
return c.json({ error: e.message }, 400);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
router.get('/budget/summary/:orgId', (c) => {
|
|
295
|
-
return c.json(lifecycle.getBudgetSummary(c.req.param('orgId')));
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
// ─── Per-Agent Tool Security ──────────────────────────
|
|
299
|
-
|
|
300
|
-
router.get('/agents/:id/tool-security', async (c) => {
|
|
301
|
-
const agent = lifecycle.getAgent(c.req.param('id'));
|
|
302
|
-
if (!agent) return c.json({ error: 'Agent not found' }, 404);
|
|
303
|
-
|
|
304
|
-
const agentOverrides = agent.config?.toolSecurity || {};
|
|
305
|
-
|
|
306
|
-
// Get org defaults from admin DB if available
|
|
307
|
-
var orgDefaults: Record<string, any> = {};
|
|
308
|
-
var adminDb = getAdminDb();
|
|
309
|
-
if (adminDb) {
|
|
310
|
-
try {
|
|
311
|
-
var settings = await adminDb.getSettings();
|
|
312
|
-
orgDefaults = settings?.toolSecurityConfig || {};
|
|
313
|
-
} catch { /* ignore — admin DB may not be available */ }
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Deep merge org defaults + agent overrides
|
|
317
|
-
var merged = { ...orgDefaults };
|
|
318
|
-
if (agentOverrides.security) {
|
|
319
|
-
merged.security = { ...(merged.security || {}), ...agentOverrides.security };
|
|
320
|
-
}
|
|
321
|
-
if (agentOverrides.middleware) {
|
|
322
|
-
merged.middleware = { ...(merged.middleware || {}), ...agentOverrides.middleware };
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return c.json({ toolSecurity: merged, orgDefaults, agentOverrides });
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
router.patch('/agents/:id/tool-security', async (c) => {
|
|
329
|
-
const { toolSecurity, updatedBy } = await c.req.json();
|
|
330
|
-
try {
|
|
331
|
-
const actor = c.req.header('X-User-Id') || updatedBy || 'dashboard';
|
|
332
|
-
const agent = await lifecycle.updateConfig(c.req.param('id'), { toolSecurity }, actor);
|
|
333
|
-
return c.json({ agent });
|
|
334
|
-
} catch (e: any) {
|
|
335
|
-
return c.json({ error: e.message }, 400);
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
// ─── System Dependencies ─────────────────────────────────
|
|
340
|
-
|
|
341
|
-
router.get('/system/process-managers', async (c) => {
|
|
342
|
-
const { execSync } = await import('child_process');
|
|
343
|
-
const check = (cmd: string): boolean => {
|
|
344
|
-
try { execSync(`which ${cmd}`, { stdio: 'pipe' }); return true; } catch { return false; }
|
|
345
|
-
};
|
|
346
|
-
const pm2Version = (() => { try { return execSync('pm2 -v', { stdio: 'pipe', encoding: 'utf-8' }).trim(); } catch { return null; } })();
|
|
347
|
-
const systemdAvailable = check('systemctl');
|
|
348
|
-
const platform = process.platform;
|
|
349
|
-
|
|
350
|
-
return c.json({
|
|
351
|
-
pm2: { installed: !!pm2Version, version: pm2Version, installCmd: 'npm install -g pm2' },
|
|
352
|
-
systemd: { available: systemdAvailable, note: systemdAvailable ? 'Available on this system' : platform === 'darwin' ? 'Not available on macOS — use PM2 or launchd' : 'Install via your package manager' },
|
|
353
|
-
launchd: { available: platform === 'darwin', note: platform === 'darwin' ? 'macOS native — always available' : 'macOS only' },
|
|
354
|
-
platform,
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
router.post('/system/install-pm2', async (c) => {
|
|
359
|
-
try {
|
|
360
|
-
const { ensurePm2 } = await import('./deployer.js');
|
|
361
|
-
const result = await ensurePm2();
|
|
362
|
-
if (result.installed) {
|
|
363
|
-
return c.json({ success: true, message: `PM2 ${result.version} installed successfully` });
|
|
364
|
-
}
|
|
365
|
-
return c.json({ success: false, error: result.error, hint: 'Try running: sudo npm install -g pm2' }, 500);
|
|
366
|
-
} catch (e: any) {
|
|
367
|
-
return c.json({ success: false, error: e.message, hint: 'Try running: sudo npm install -g pm2' }, 500);
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
// ─── Port Availability Check ──────────────────────────────
|
|
372
|
-
|
|
373
|
-
router.post('/system/check-port', async (c) => {
|
|
374
|
-
try {
|
|
375
|
-
const { port } = await c.req.json();
|
|
376
|
-
const p = parseInt(port);
|
|
377
|
-
if (!p || p < 1 || p > 65535) {
|
|
378
|
-
return c.json({ available: false, error: 'Invalid port number (1-65535)' });
|
|
379
|
-
}
|
|
380
|
-
// Try to bind to the port on all interfaces to check availability
|
|
381
|
-
const net = await import('net');
|
|
382
|
-
const tryBind = (host: string) => new Promise<boolean>((resolve) => {
|
|
383
|
-
const server = net.createServer();
|
|
384
|
-
server.once('error', () => resolve(false));
|
|
385
|
-
server.once('listening', () => { server.close(() => resolve(true)); });
|
|
386
|
-
server.listen(p, host);
|
|
387
|
-
});
|
|
388
|
-
// Check both 0.0.0.0 and 127.0.0.1 — a port is only available if free on both
|
|
389
|
-
const [availAll, availLocal] = await Promise.all([tryBind('0.0.0.0'), tryBind('127.0.0.1')]);
|
|
390
|
-
const available = availAll && availLocal;
|
|
391
|
-
if (!available) {
|
|
392
|
-
// Try to identify what's using it
|
|
393
|
-
let processInfo = '';
|
|
394
|
-
try {
|
|
395
|
-
const { execSync } = await import('child_process');
|
|
396
|
-
if (process.platform === 'darwin' || process.platform === 'linux') {
|
|
397
|
-
const lsofBin = process.platform === 'darwin' ? '/usr/sbin/lsof' : 'lsof';
|
|
398
|
-
const out = execSync(`${lsofBin} -i :${p} -P -n 2>/dev/null | head -5`, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 3000 }).trim();
|
|
399
|
-
if (out) {
|
|
400
|
-
const lines = out.split('\n').slice(1); // skip header
|
|
401
|
-
if (lines.length > 0) {
|
|
402
|
-
const parts = lines[0].split(/\s+/);
|
|
403
|
-
processInfo = parts[0] ? `${parts[0]} (PID ${parts[1]})` : '';
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
} else if (process.platform === 'win32') {
|
|
407
|
-
const out = execSync(`netstat -ano | findstr :${p}`, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 3000 }).trim();
|
|
408
|
-
if (out) {
|
|
409
|
-
const parts = out.split(/\s+/);
|
|
410
|
-
processInfo = `PID ${parts[parts.length - 1]}`;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
} catch {}
|
|
414
|
-
return c.json({ available: false, port: p, inUse: true, process: processInfo || 'Unknown process' });
|
|
415
|
-
}
|
|
416
|
-
return c.json({ available: true, port: p });
|
|
417
|
-
} catch (e: any) {
|
|
418
|
-
return c.json({ available: false, error: e.message });
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
// ─── Screen Unlock ──────────────────────────────────────
|
|
423
|
-
|
|
424
|
-
router.post('/system/unlock-screen', async (c) => {
|
|
425
|
-
try {
|
|
426
|
-
const platform = process.platform;
|
|
427
|
-
if (platform === 'darwin') {
|
|
428
|
-
// macOS: Use AppleScript via osascript to wake and unlock
|
|
429
|
-
const { execSync } = await import('child_process');
|
|
430
|
-
// First wake the display
|
|
431
|
-
try { execSync('caffeinate -u -t 2', { stdio: 'pipe', timeout: 5000 }); } catch {}
|
|
432
|
-
// Check if screen is locked
|
|
433
|
-
const isLocked = (() => {
|
|
434
|
-
try {
|
|
435
|
-
const out = execSync('python3 -c "import Quartz; d=Quartz.CGSessionCopyCurrentDictionary(); print(d.get(\'CGSSessionScreenIsLocked\', 0))"', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 3000 }).trim();
|
|
436
|
-
return out === '1' || out === 'True';
|
|
437
|
-
} catch {
|
|
438
|
-
// Fallback: check if loginwindow is frontmost
|
|
439
|
-
try {
|
|
440
|
-
const out = execSync('osascript -e \'tell application "System Events" to get name of first application process whose frontmost is true\'', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 3000 }).trim();
|
|
441
|
-
return out === 'loginwindow' || out === 'ScreenSaverEngine';
|
|
442
|
-
} catch { return false; }
|
|
443
|
-
}
|
|
444
|
-
})();
|
|
445
|
-
if (!isLocked) {
|
|
446
|
-
return c.json({ success: true, wasLocked: false, message: 'Screen is already unlocked' });
|
|
447
|
-
}
|
|
448
|
-
// Get password from agent's security config or request body
|
|
449
|
-
const body = await c.req.json().catch(() => ({}));
|
|
450
|
-
const password = body.password;
|
|
451
|
-
if (!password) {
|
|
452
|
-
return c.json({ success: false, locked: true, error: 'Screen is locked but no password provided. Configure the system password in Settings > Security or the agent\'s Permissions tab.' });
|
|
453
|
-
}
|
|
454
|
-
// Use cliclick or AppleScript to type password and press Enter
|
|
455
|
-
// Method 1: Use osascript to simulate keystrokes at the login window
|
|
456
|
-
try {
|
|
457
|
-
execSync(`osascript -e 'tell application "System Events" to keystroke "${password.replace(/["\\]/g, '\\$&')}"' -e 'delay 0.3' -e 'tell application "System Events" to key code 36'`, {
|
|
458
|
-
stdio: 'pipe', timeout: 10000
|
|
459
|
-
});
|
|
460
|
-
// Wait a moment and check if unlocked
|
|
461
|
-
await new Promise(r => setTimeout(r, 2000));
|
|
462
|
-
const stillLocked = (() => {
|
|
463
|
-
try {
|
|
464
|
-
const out = execSync('python3 -c "import Quartz; d=Quartz.CGSessionCopyCurrentDictionary(); print(d.get(\'CGSSessionScreenIsLocked\', 0))"', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 3000 }).trim();
|
|
465
|
-
return out === '1' || out === 'True';
|
|
466
|
-
} catch { return false; }
|
|
467
|
-
})();
|
|
468
|
-
if (stillLocked) {
|
|
469
|
-
return c.json({ success: false, error: 'Failed to unlock — password may be incorrect' });
|
|
470
|
-
}
|
|
471
|
-
return c.json({ success: true, wasLocked: true, message: 'Screen unlocked successfully' });
|
|
472
|
-
} catch (e: any) {
|
|
473
|
-
return c.json({ success: false, error: 'Unlock attempt failed: ' + e.message });
|
|
474
|
-
}
|
|
475
|
-
} else if (platform === 'linux') {
|
|
476
|
-
const { execSync } = await import('child_process');
|
|
477
|
-
// Check for common screen lockers and unlock them
|
|
478
|
-
const body = await c.req.json().catch(() => ({}));
|
|
479
|
-
const password = body.password;
|
|
480
|
-
// Try loginctl unlock-session
|
|
481
|
-
try {
|
|
482
|
-
execSync('loginctl unlock-session $(loginctl list-sessions --no-legend | head -1 | awk \'{print $1}\')', { stdio: 'pipe', timeout: 5000 });
|
|
483
|
-
return c.json({ success: true, message: 'Session unlocked via loginctl' });
|
|
484
|
-
} catch {}
|
|
485
|
-
// Try xdotool for X11 based lockers
|
|
486
|
-
if (password) {
|
|
487
|
-
try {
|
|
488
|
-
execSync(`xdotool key --clearmodifiers super; sleep 0.5; xdotool type --clearmodifiers "${password.replace(/["\\]/g, '\\$&')}"; xdotool key Return`, { stdio: 'pipe', timeout: 10000 });
|
|
489
|
-
return c.json({ success: true, message: 'Unlock attempted via xdotool' });
|
|
490
|
-
} catch {}
|
|
491
|
-
}
|
|
492
|
-
return c.json({ success: false, error: 'Could not unlock Linux session. Supported: loginctl, xdotool.' });
|
|
493
|
-
} else if (platform === 'win32') {
|
|
494
|
-
return c.json({ success: false, error: 'Windows unlock not yet supported. Use Remote Desktop or disable lock screen.' });
|
|
495
|
-
} else {
|
|
496
|
-
return c.json({ success: false, error: `Unsupported platform: ${platform}` });
|
|
497
|
-
}
|
|
498
|
-
} catch (e: any) {
|
|
499
|
-
return c.json({ success: false, error: e.message });
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
router.get('/system/screen-status', async (c) => {
|
|
504
|
-
try {
|
|
505
|
-
const platform = process.platform;
|
|
506
|
-
if (platform === 'darwin') {
|
|
507
|
-
const { execSync } = await import('child_process');
|
|
508
|
-
const isLocked = (() => {
|
|
509
|
-
try {
|
|
510
|
-
const out = execSync('python3 -c "import Quartz; d=Quartz.CGSessionCopyCurrentDictionary(); print(d.get(\'CGSSessionScreenIsLocked\', 0))"', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 3000 }).trim();
|
|
511
|
-
return out === '1' || out === 'True';
|
|
512
|
-
} catch {
|
|
513
|
-
try {
|
|
514
|
-
const out = execSync('osascript -e \'tell application "System Events" to get name of first application process whose frontmost is true\'', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 3000 }).trim();
|
|
515
|
-
return out === 'loginwindow' || out === 'ScreenSaverEngine';
|
|
516
|
-
} catch { return false; }
|
|
517
|
-
}
|
|
518
|
-
})();
|
|
519
|
-
// Check if display is asleep
|
|
520
|
-
const displayAsleep = (() => {
|
|
521
|
-
try {
|
|
522
|
-
const out = execSync('ioreg -r -d 1 -k IODisplayWrangler | grep -i "currentpowerstate"', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 3000 });
|
|
523
|
-
return out.includes('= 0') || out.includes('= 1');
|
|
524
|
-
} catch { return false; }
|
|
525
|
-
})();
|
|
526
|
-
return c.json({ locked: isLocked, displayAsleep, platform: 'macOS' });
|
|
527
|
-
} else if (platform === 'linux') {
|
|
528
|
-
const { execSync } = await import('child_process');
|
|
529
|
-
const isLocked = (() => {
|
|
530
|
-
try {
|
|
531
|
-
const out = execSync('loginctl show-session $(loginctl list-sessions --no-legend | head -1 | awk \'{print $1}\') -p LockedHint --value', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 3000 }).trim();
|
|
532
|
-
return out === 'yes';
|
|
533
|
-
} catch { return false; }
|
|
534
|
-
})();
|
|
535
|
-
return c.json({ locked: isLocked, platform: 'Linux' });
|
|
536
|
-
}
|
|
537
|
-
return c.json({ locked: false, platform });
|
|
538
|
-
} catch (e: any) {
|
|
539
|
-
return c.json({ locked: false, error: e.message });
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
// ─── Agent Creation Bridge ──────────────────────────────
|
|
544
|
-
|
|
545
|
-
/**
|
|
546
|
-
* POST /bridge/agents — Unified agent creation that creates both:
|
|
547
|
-
* 1. An admin-level agent record (via the base DatabaseAdapter)
|
|
548
|
-
* 2. An engine managed_agent record (via lifecycle manager)
|
|
549
|
-
* Returns both IDs and the full agent object.
|
|
550
|
-
*/
|
|
551
|
-
router.post('/bridge/agents', async (c) => {
|
|
552
|
-
const { orgId, name, email, displayName, role, model, deployment, permissionProfile, presetName, createdBy, persona, permissions: permissionsData, skills, knowledgeBases, description, soulId, deployTarget } = await c.req.json();
|
|
553
|
-
|
|
554
|
-
if (!name || !orgId) {
|
|
555
|
-
return c.json({ error: 'name and orgId are required' }, 400);
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
const actor = c.req.header('X-User-Id') || createdBy || 'system';
|
|
559
|
-
const agentId = crypto.randomUUID();
|
|
560
|
-
|
|
561
|
-
// Build the engine AgentConfig — store EVERYTHING from the wizard
|
|
562
|
-
const agentEmail = email || `${name.toLowerCase().replace(/\s+/g, '-')}@agenticmail.local`;
|
|
563
|
-
const agentRole = role || 'assistant';
|
|
564
|
-
const agentDescription = description || persona?.description || '';
|
|
565
|
-
|
|
566
|
-
const config: any = {
|
|
567
|
-
id: agentId,
|
|
568
|
-
name,
|
|
569
|
-
displayName: displayName || name,
|
|
570
|
-
email: agentEmail,
|
|
571
|
-
role: agentRole,
|
|
572
|
-
description: agentDescription,
|
|
573
|
-
soulId: soulId || null,
|
|
574
|
-
identity: {
|
|
575
|
-
name,
|
|
576
|
-
displayName: displayName || name,
|
|
577
|
-
email: agentEmail,
|
|
578
|
-
role: agentRole,
|
|
579
|
-
personality: persona?.personality || 'professional',
|
|
580
|
-
description: agentDescription,
|
|
581
|
-
avatar: persona?.avatar || null,
|
|
582
|
-
gender: persona?.gender || '',
|
|
583
|
-
dateOfBirth: persona?.dateOfBirth || '',
|
|
584
|
-
maritalStatus: persona?.maritalStatus || '',
|
|
585
|
-
culturalBackground: persona?.culturalBackground || '',
|
|
586
|
-
language: persona?.language || 'en-us',
|
|
587
|
-
traits: persona?.traits || {},
|
|
588
|
-
},
|
|
589
|
-
model: model || {
|
|
590
|
-
provider: 'anthropic',
|
|
591
|
-
modelId: 'claude-sonnet-4-5-20250929',
|
|
592
|
-
thinkingLevel: 'medium',
|
|
593
|
-
},
|
|
594
|
-
skills: Array.isArray(skills) ? skills : [],
|
|
595
|
-
knowledgeBases: Array.isArray(knowledgeBases) ? knowledgeBases : [],
|
|
596
|
-
deployment: deployment || {
|
|
597
|
-
target: deployTarget || 'docker',
|
|
598
|
-
config: { docker: { image: 'agenticmail/agent', tag: 'latest', ports: [3000], env: {}, volumes: [], restart: 'unless-stopped' } },
|
|
599
|
-
},
|
|
600
|
-
permissionProfileId: permissionProfile || 'default',
|
|
601
|
-
};
|
|
602
|
-
|
|
603
|
-
// Apply permissions: start from preset if specified, then overlay granular settings
|
|
604
|
-
if (presetName || permissionsData) {
|
|
605
|
-
let profile: any = { id: agentId, name: presetName || 'Custom', createdAt: new Date().toISOString(), updatedAt: new Date().toISOString() };
|
|
606
|
-
|
|
607
|
-
if (presetName) {
|
|
608
|
-
const { PRESET_PROFILES } = await import('./skills.js');
|
|
609
|
-
const preset = PRESET_PROFILES.find((p: any) => p.name === presetName);
|
|
610
|
-
if (preset) Object.assign(profile, preset);
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
// Overlay granular permission settings from the UI
|
|
614
|
-
if (permissionsData) {
|
|
615
|
-
if (permissionsData.maxRiskLevel) profile.maxRiskLevel = permissionsData.maxRiskLevel;
|
|
616
|
-
if (permissionsData.blockedSideEffects) profile.blockedSideEffects = permissionsData.blockedSideEffects;
|
|
617
|
-
if (permissionsData.requireApproval) profile.requireApproval = permissionsData.requireApproval;
|
|
618
|
-
if (permissionsData.rateLimits) profile.rateLimits = permissionsData.rateLimits;
|
|
619
|
-
if (permissionsData.constraints) profile.constraints = permissionsData.constraints;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
permissions.setProfile(agentId, profile as any, orgId);
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
const _adminDb = getAdminDb();
|
|
626
|
-
|
|
627
|
-
try {
|
|
628
|
-
// 1) Create admin agent record (shared ID)
|
|
629
|
-
let adminAgent = null;
|
|
630
|
-
if (_adminDb) {
|
|
631
|
-
adminAgent = await _adminDb.createAgent({
|
|
632
|
-
id: agentId,
|
|
633
|
-
name,
|
|
634
|
-
email: agentEmail,
|
|
635
|
-
role: agentRole,
|
|
636
|
-
metadata: { engineLinked: true, orgId, soulId: soulId || undefined },
|
|
637
|
-
createdBy: actor,
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
// 2) Create engine managed agent (same ID via config.id)
|
|
642
|
-
const managedAgent = await lifecycle.createAgent(orgId, config, actor);
|
|
643
|
-
|
|
644
|
-
// 3) Auto-assign knowledge bases based on org context
|
|
645
|
-
try {
|
|
646
|
-
const { knowledgeBase: kbEngine } = await import('./routes.js');
|
|
647
|
-
const allKbs = kbEngine.getAllKnowledgeBases();
|
|
648
|
-
const clientOrgId = (managedAgent as any)?.clientOrgId || (config as any)?.clientOrgId || null;
|
|
649
|
-
let kbAssigned = 0;
|
|
650
|
-
for (const kb of allKbs) {
|
|
651
|
-
const ids: string[] = Array.isArray((kb as any).agentIds) ? (kb as any).agentIds : [];
|
|
652
|
-
if (ids.includes(agentId)) continue;
|
|
653
|
-
let shouldAssign = false;
|
|
654
|
-
if (clientOrgId) {
|
|
655
|
-
shouldAssign = (kb as any).orgId === clientOrgId || (kb as any).clientOrgId === clientOrgId;
|
|
656
|
-
} else {
|
|
657
|
-
shouldAssign = !(kb as any).clientOrgId;
|
|
658
|
-
}
|
|
659
|
-
if (shouldAssign) {
|
|
660
|
-
ids.push(agentId);
|
|
661
|
-
(kb as any).agentIds = ids;
|
|
662
|
-
(kb as any).updatedAt = new Date().toISOString();
|
|
663
|
-
const _db = getAdminDb();
|
|
664
|
-
if (_db) {
|
|
665
|
-
try { await (_db as any).execute?.('UPDATE knowledge_bases SET agent_ids = $1, updated_at = $2 WHERE id = $3', [JSON.stringify(ids), (kb as any).updatedAt, kb.id]); } catch {}
|
|
666
|
-
}
|
|
667
|
-
kbAssigned++;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
if (kbAssigned > 0) console.log(`[agent-create] Auto-assigned ${kbAssigned} knowledge base(s) to agent ${agentId}`);
|
|
671
|
-
} catch (e: any) {
|
|
672
|
-
console.warn(`[agent-create] KB auto-assign failed: ${e.message}`);
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
return c.json({
|
|
676
|
-
agent: managedAgent,
|
|
677
|
-
adminAgent,
|
|
678
|
-
agentId,
|
|
679
|
-
}, 201);
|
|
680
|
-
} catch (e: any) {
|
|
681
|
-
// If engine creation fails but admin was created, best-effort cleanup
|
|
682
|
-
if (_adminDb) {
|
|
683
|
-
try { await _adminDb.deleteAgent(agentId); } catch { /* best effort */ }
|
|
684
|
-
}
|
|
685
|
-
return c.json({ error: e.message }, 400);
|
|
686
|
-
}
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
/**
|
|
690
|
-
* DELETE /bridge/agents/:id — Unified agent deletion.
|
|
691
|
-
* Removes both the admin record and the engine managed agent.
|
|
692
|
-
*/
|
|
693
|
-
router.delete('/bridge/agents/:id', async (c) => {
|
|
694
|
-
const agentId = c.req.param('id');
|
|
695
|
-
const { destroyedBy } = await c.req.json().catch(() => ({ destroyedBy: 'unknown' }));
|
|
696
|
-
const actor = c.req.header('X-User-Id') || destroyedBy;
|
|
697
|
-
const errors: string[] = [];
|
|
698
|
-
const _adminDb = getAdminDb();
|
|
699
|
-
|
|
700
|
-
// 1) Destroy engine agent
|
|
701
|
-
try {
|
|
702
|
-
await lifecycle.destroy(agentId, actor);
|
|
703
|
-
} catch (e: any) {
|
|
704
|
-
errors.push(`engine: ${e.message}`);
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
// 2) Delete admin agent
|
|
708
|
-
if (_adminDb) {
|
|
709
|
-
try {
|
|
710
|
-
await _adminDb.deleteAgent(agentId);
|
|
711
|
-
} catch (e: any) {
|
|
712
|
-
errors.push(`admin: ${e.message}`);
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
if (errors.length > 0) {
|
|
717
|
-
return c.json({ success: false, errors }, 207);
|
|
718
|
-
}
|
|
719
|
-
return c.json({ success: true });
|
|
720
|
-
});
|
|
721
|
-
|
|
722
|
-
/**
|
|
723
|
-
* GET /bridge/agents/:id/full — Get full agent info combining admin + engine data
|
|
724
|
-
*/
|
|
725
|
-
router.get('/bridge/agents/:id/full', (c) => {
|
|
726
|
-
const agentId = c.req.param('id');
|
|
727
|
-
const managed = lifecycle.getAgent(agentId);
|
|
728
|
-
|
|
729
|
-
if (!managed) {
|
|
730
|
-
return c.json({ error: 'Agent not found' }, 404);
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
const profile = permissions.getProfile(agentId);
|
|
734
|
-
const tools = permissions.getAvailableTools(agentId);
|
|
735
|
-
|
|
736
|
-
return c.json({
|
|
737
|
-
agent: managed,
|
|
738
|
-
permissions: profile,
|
|
739
|
-
availableTools: tools.length,
|
|
740
|
-
state: managed.state,
|
|
741
|
-
health: managed.health,
|
|
742
|
-
usage: managed.usage,
|
|
743
|
-
});
|
|
744
|
-
});
|
|
745
|
-
|
|
746
|
-
// ─── Birthday Routes ──────────────────────────────────
|
|
747
|
-
|
|
748
|
-
router.get('/birthdays/upcoming', (c) => {
|
|
749
|
-
const days = parseInt(c.req.query('days') || '30');
|
|
750
|
-
const upcoming = lifecycle.getUpcomingBirthdays(days);
|
|
751
|
-
return c.json({
|
|
752
|
-
upcoming: upcoming.map(b => ({
|
|
753
|
-
agentId: b.agent.id,
|
|
754
|
-
name: b.agent.config.displayName,
|
|
755
|
-
dateOfBirth: b.dateOfBirth,
|
|
756
|
-
turningAge: b.age,
|
|
757
|
-
daysUntil: b.daysUntil,
|
|
758
|
-
})),
|
|
759
|
-
total: upcoming.length,
|
|
760
|
-
});
|
|
761
|
-
});
|
|
762
|
-
|
|
763
|
-
// ─── Email Configuration ──────────────────────────────
|
|
764
|
-
|
|
765
|
-
/**
|
|
766
|
-
* GET /bridge/agents/:id/email-config — Get agent's email configuration (without password).
|
|
767
|
-
*/
|
|
768
|
-
router.get('/bridge/agents/:id/email-config', async (c) => {
|
|
769
|
-
const agentId = c.req.param('id');
|
|
770
|
-
const managed = lifecycle.getAgent(agentId);
|
|
771
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
772
|
-
|
|
773
|
-
// Fetch org-level email config
|
|
774
|
-
let orgEmailConfig: any = null;
|
|
775
|
-
try {
|
|
776
|
-
const adminDb = getAdminDb();
|
|
777
|
-
if (adminDb) {
|
|
778
|
-
const settings = await adminDb.getSettings();
|
|
779
|
-
if (settings?.orgEmailConfig?.configured) {
|
|
780
|
-
orgEmailConfig = {
|
|
781
|
-
provider: settings.orgEmailConfig.provider,
|
|
782
|
-
label: settings.orgEmailConfig.label,
|
|
783
|
-
oauthClientId: settings.orgEmailConfig.oauthClientId,
|
|
784
|
-
oauthTenantId: settings.orgEmailConfig.oauthTenantId,
|
|
785
|
-
};
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
} catch {}
|
|
789
|
-
|
|
790
|
-
const emailConfig = managed.config?.emailConfig || null;
|
|
791
|
-
if (!emailConfig) return c.json({ configured: false, orgEmailConfig });
|
|
792
|
-
|
|
793
|
-
// Return config without sensitive data
|
|
794
|
-
return c.json({
|
|
795
|
-
configured: true,
|
|
796
|
-
provider: emailConfig.provider,
|
|
797
|
-
email: emailConfig.email,
|
|
798
|
-
status: emailConfig.status || 'unknown',
|
|
799
|
-
// IMAP details (no password)
|
|
800
|
-
imapHost: emailConfig.imapHost,
|
|
801
|
-
imapPort: emailConfig.imapPort,
|
|
802
|
-
smtpHost: emailConfig.smtpHost,
|
|
803
|
-
smtpPort: emailConfig.smtpPort,
|
|
804
|
-
// OAuth details (no tokens)
|
|
805
|
-
oauthProvider: emailConfig.oauthProvider,
|
|
806
|
-
oauthClientId: emailConfig.oauthClientId,
|
|
807
|
-
oauthConfigured: !!emailConfig.oauthAccessToken,
|
|
808
|
-
oauthAuthUrl: emailConfig.oauthAuthUrl || undefined,
|
|
809
|
-
lastConnected: emailConfig.lastConnected,
|
|
810
|
-
lastError: emailConfig.lastError,
|
|
811
|
-
orgEmailConfig,
|
|
812
|
-
// Sending config override (no password)
|
|
813
|
-
sendingConfig: emailConfig.sendingConfig ? {
|
|
814
|
-
provider: 'smtp',
|
|
815
|
-
email: emailConfig.sendingConfig.email,
|
|
816
|
-
smtpHost: emailConfig.sendingConfig.smtpHost,
|
|
817
|
-
smtpPort: emailConfig.sendingConfig.smtpPort,
|
|
818
|
-
configured: true,
|
|
819
|
-
} : undefined,
|
|
820
|
-
});
|
|
821
|
-
});
|
|
822
|
-
|
|
823
|
-
/**
|
|
824
|
-
* PUT /bridge/agents/:id/email-config — Set or update agent's email configuration.
|
|
825
|
-
*
|
|
826
|
-
* Supports three modes:
|
|
827
|
-
* 1. IMAP/SMTP: { provider: 'imap', email, password, imapHost, smtpHost, ... }
|
|
828
|
-
* 2. Microsoft OAuth: { provider: 'microsoft', oauthClientId, oauthClientSecret, oauthTenantId }
|
|
829
|
-
* 3. Google OAuth: { provider: 'google', oauthClientId, oauthClientSecret }
|
|
830
|
-
*
|
|
831
|
-
* For IMAP, auto-detects settings for known providers (Microsoft 365, Gmail, etc.)
|
|
832
|
-
*/
|
|
833
|
-
router.put('/bridge/agents/:id/email-config', async (c) => {
|
|
834
|
-
const agentId = c.req.param('id');
|
|
835
|
-
const managed = lifecycle.getAgent(agentId);
|
|
836
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
837
|
-
|
|
838
|
-
const body = await c.req.json();
|
|
839
|
-
let { provider, email, password, imapHost, imapPort, smtpHost, smtpPort, preset,
|
|
840
|
-
oauthClientId, oauthClientSecret, oauthTenantId, oauthRedirectUri } = body;
|
|
841
|
-
const useOrgConfig = body.useOrgConfig === true;
|
|
842
|
-
|
|
843
|
-
if (!provider) return c.json({ error: 'provider is required (imap, microsoft, or google)' }, 400);
|
|
844
|
-
|
|
845
|
-
// If using org-level OAuth config, inherit client credentials
|
|
846
|
-
if (useOrgConfig && (provider === 'google' || provider === 'microsoft')) {
|
|
847
|
-
try {
|
|
848
|
-
const adminDb = getAdminDb();
|
|
849
|
-
if (adminDb) {
|
|
850
|
-
const settings = await adminDb.getSettings();
|
|
851
|
-
if (settings?.orgEmailConfig?.configured && settings.orgEmailConfig.provider === provider) {
|
|
852
|
-
oauthClientId = oauthClientId || settings.orgEmailConfig.oauthClientId;
|
|
853
|
-
oauthClientSecret = oauthClientSecret || settings.orgEmailConfig.oauthClientSecret;
|
|
854
|
-
if (provider === 'microsoft') oauthTenantId = oauthTenantId || settings.orgEmailConfig.oauthTenantId;
|
|
855
|
-
} else {
|
|
856
|
-
return c.json({ error: 'Organization email config not found or provider mismatch' }, 400);
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
} catch {}
|
|
860
|
-
}
|
|
861
|
-
if (!email && provider === 'imap') return c.json({ error: 'email is required' }, 400);
|
|
862
|
-
|
|
863
|
-
// Preserve existing tokens/state when re-configuring (e.g. to pick up new scopes)
|
|
864
|
-
const existingConfig = managed.config?.emailConfig || {};
|
|
865
|
-
const emailConfig: any = {
|
|
866
|
-
provider,
|
|
867
|
-
email: email || existingConfig.email || (managed.config?.identity as any)?.email || managed.config?.email,
|
|
868
|
-
updatedAt: new Date().toISOString(),
|
|
869
|
-
};
|
|
870
|
-
// Preserve existing OAuth tokens so re-auth doesn't lose refresh_token
|
|
871
|
-
if (existingConfig.oauthRefreshToken) emailConfig.oauthRefreshToken = existingConfig.oauthRefreshToken;
|
|
872
|
-
if (existingConfig.oauthAccessToken) emailConfig.oauthAccessToken = existingConfig.oauthAccessToken;
|
|
873
|
-
if (existingConfig.oauthTokenExpiry) emailConfig.oauthTokenExpiry = existingConfig.oauthTokenExpiry;
|
|
874
|
-
if (existingConfig.lastConnected) emailConfig.lastConnected = existingConfig.lastConnected;
|
|
875
|
-
|
|
876
|
-
if (provider === 'imap') {
|
|
877
|
-
// Auto-detect IMAP/SMTP from well-known providers
|
|
878
|
-
if (preset && !imapHost) {
|
|
879
|
-
const PRESETS: Record<string, any> = {
|
|
880
|
-
'microsoft365': { imapHost: 'outlook.office365.com', imapPort: 993, smtpHost: 'smtp.office365.com', smtpPort: 587 },
|
|
881
|
-
'gmail': { imapHost: 'imap.gmail.com', imapPort: 993, smtpHost: 'smtp.gmail.com', smtpPort: 587 },
|
|
882
|
-
'yahoo': { imapHost: 'imap.mail.yahoo.com', imapPort: 993, smtpHost: 'smtp.mail.yahoo.com', smtpPort: 465 },
|
|
883
|
-
'zoho': { imapHost: 'imap.zoho.com', imapPort: 993, smtpHost: 'smtp.zoho.com', smtpPort: 587 },
|
|
884
|
-
'fastmail': { imapHost: 'imap.fastmail.com', imapPort: 993, smtpHost: 'smtp.fastmail.com', smtpPort: 587 },
|
|
885
|
-
'icloud': { imapHost: 'imap.mail.me.com', imapPort: 993, smtpHost: 'smtp.mail.me.com', smtpPort: 587 },
|
|
886
|
-
};
|
|
887
|
-
const presetConfig = PRESETS[preset];
|
|
888
|
-
if (presetConfig) Object.assign(emailConfig, presetConfig);
|
|
889
|
-
else return c.json({ error: `Unknown preset: ${preset}. Valid: ${Object.keys(PRESETS).join(', ')}` }, 400);
|
|
890
|
-
} else {
|
|
891
|
-
emailConfig.imapHost = imapHost;
|
|
892
|
-
emailConfig.imapPort = imapPort || 993;
|
|
893
|
-
emailConfig.smtpHost = smtpHost;
|
|
894
|
-
emailConfig.smtpPort = smtpPort || 587;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
if (!emailConfig.imapHost || !emailConfig.smtpHost) {
|
|
898
|
-
return c.json({ error: 'imapHost and smtpHost are required (or use a preset)' }, 400);
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
if (password) {
|
|
902
|
-
emailConfig.password = password; // stored encrypted in production
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
emailConfig.status = 'configured';
|
|
906
|
-
|
|
907
|
-
} else if (provider === 'microsoft') {
|
|
908
|
-
// Microsoft OAuth (Azure AD / Entra ID)
|
|
909
|
-
emailConfig.oauthProvider = 'microsoft';
|
|
910
|
-
emailConfig.oauthClientId = oauthClientId;
|
|
911
|
-
emailConfig.oauthClientSecret = oauthClientSecret;
|
|
912
|
-
emailConfig.oauthTenantId = oauthTenantId || 'common';
|
|
913
|
-
emailConfig.oauthRedirectUri = oauthRedirectUri || '';
|
|
914
|
-
emailConfig.oauthScopes = [
|
|
915
|
-
'https://graph.microsoft.com/Mail.ReadWrite',
|
|
916
|
-
'https://graph.microsoft.com/Mail.Send',
|
|
917
|
-
'https://graph.microsoft.com/Calendars.ReadWrite',
|
|
918
|
-
'https://graph.microsoft.com/Files.ReadWrite',
|
|
919
|
-
'https://graph.microsoft.com/Contacts.ReadWrite',
|
|
920
|
-
'offline_access',
|
|
921
|
-
];
|
|
922
|
-
|
|
923
|
-
if (!oauthClientId) return c.json({ error: 'oauthClientId is required for Microsoft OAuth' }, 400);
|
|
924
|
-
|
|
925
|
-
// Build the authorization URL
|
|
926
|
-
const authUrl = `https://login.microsoftonline.com/${emailConfig.oauthTenantId}/oauth2/v2.0/authorize?` +
|
|
927
|
-
`client_id=${encodeURIComponent(oauthClientId)}&response_type=code&` +
|
|
928
|
-
`redirect_uri=${encodeURIComponent(emailConfig.oauthRedirectUri)}&` +
|
|
929
|
-
`scope=${encodeURIComponent(emailConfig.oauthScopes.join(' '))}&` +
|
|
930
|
-
`state=${agentId}&prompt=consent`;
|
|
931
|
-
emailConfig.oauthAuthUrl = authUrl;
|
|
932
|
-
emailConfig.status = 'awaiting_oauth';
|
|
933
|
-
|
|
934
|
-
} else if (provider === 'google') {
|
|
935
|
-
// Google OAuth (Google Workspace)
|
|
936
|
-
emailConfig.oauthProvider = 'google';
|
|
937
|
-
emailConfig.oauthClientId = oauthClientId;
|
|
938
|
-
emailConfig.oauthClientSecret = oauthClientSecret;
|
|
939
|
-
emailConfig.oauthRedirectUri = oauthRedirectUri || '';
|
|
940
|
-
emailConfig.oauthScopes = [
|
|
941
|
-
'https://www.googleapis.com/auth/gmail.modify',
|
|
942
|
-
'https://www.googleapis.com/auth/gmail.send',
|
|
943
|
-
'https://www.googleapis.com/auth/gmail.settings.basic',
|
|
944
|
-
'https://www.googleapis.com/auth/calendar',
|
|
945
|
-
'https://www.googleapis.com/auth/drive',
|
|
946
|
-
'https://www.googleapis.com/auth/spreadsheets',
|
|
947
|
-
'https://www.googleapis.com/auth/documents',
|
|
948
|
-
'https://www.googleapis.com/auth/contacts',
|
|
949
|
-
'https://www.googleapis.com/auth/tasks',
|
|
950
|
-
'https://www.googleapis.com/auth/chat.spaces',
|
|
951
|
-
'https://www.googleapis.com/auth/chat.spaces.create',
|
|
952
|
-
'https://www.googleapis.com/auth/chat.messages',
|
|
953
|
-
'https://www.googleapis.com/auth/chat.messages.create',
|
|
954
|
-
'https://www.googleapis.com/auth/chat.memberships',
|
|
955
|
-
'https://www.googleapis.com/auth/presentations',
|
|
956
|
-
'https://www.googleapis.com/auth/forms.body',
|
|
957
|
-
'https://www.googleapis.com/auth/forms.responses.readonly',
|
|
958
|
-
];
|
|
959
|
-
|
|
960
|
-
if (!oauthClientId) return c.json({ error: 'oauthClientId is required for Google OAuth' }, 400);
|
|
961
|
-
|
|
962
|
-
const authUrl = `https://accounts.google.com/o/oauth2/v2/auth?` +
|
|
963
|
-
`client_id=${encodeURIComponent(oauthClientId)}&response_type=code&` +
|
|
964
|
-
`redirect_uri=${encodeURIComponent(emailConfig.oauthRedirectUri)}&` +
|
|
965
|
-
`scope=${encodeURIComponent(emailConfig.oauthScopes.join(' '))}&` +
|
|
966
|
-
`access_type=offline&prompt=consent&state=${agentId}`;
|
|
967
|
-
emailConfig.oauthAuthUrl = authUrl;
|
|
968
|
-
emailConfig.status = 'awaiting_oauth';
|
|
969
|
-
} else {
|
|
970
|
-
return c.json({ error: `Unknown provider: ${provider}. Valid: imap, microsoft, google` }, 400);
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
// Attach sending config override if provided
|
|
974
|
-
if (body.sendingConfig && body.sendingConfig.smtpHost) {
|
|
975
|
-
emailConfig.sendingConfig = {
|
|
976
|
-
provider: 'smtp',
|
|
977
|
-
email: body.sendingConfig.email || emailConfig.email,
|
|
978
|
-
password: body.sendingConfig.password,
|
|
979
|
-
smtpHost: body.sendingConfig.smtpHost,
|
|
980
|
-
smtpPort: body.sendingConfig.smtpPort || 587,
|
|
981
|
-
};
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
// Save to agent config and persist to DB
|
|
985
|
-
const _managed = lifecycle.getAgent(agentId); if (_managed) { _managed.config.emailConfig = emailConfig; _managed.updatedAt = new Date().toISOString(); }
|
|
986
|
-
await lifecycle.saveAgent(agentId);
|
|
987
|
-
|
|
988
|
-
// Also update the primary agents table email if we have one
|
|
989
|
-
if (emailConfig.email) {
|
|
990
|
-
try {
|
|
991
|
-
const adminDb = getAdminDb();
|
|
992
|
-
if (adminDb) await adminDb.updateAgent(agentId, { email: emailConfig.email });
|
|
993
|
-
} catch { /* non-critical */ }
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
return c.json({
|
|
997
|
-
success: true,
|
|
998
|
-
emailConfig: {
|
|
999
|
-
provider: emailConfig.provider,
|
|
1000
|
-
email: emailConfig.email,
|
|
1001
|
-
status: emailConfig.status,
|
|
1002
|
-
oauthAuthUrl: emailConfig.oauthAuthUrl || undefined,
|
|
1003
|
-
},
|
|
1004
|
-
});
|
|
1005
|
-
});
|
|
1006
|
-
|
|
1007
|
-
/**
|
|
1008
|
-
* POST /bridge/agents/:id/email-config/oauth-callback — Exchange OAuth code for tokens.
|
|
1009
|
-
* Called after user completes the OAuth consent flow.
|
|
1010
|
-
*/
|
|
1011
|
-
router.post('/bridge/agents/:id/email-config/oauth-callback', async (c) => {
|
|
1012
|
-
const agentId = c.req.param('id');
|
|
1013
|
-
const managed = lifecycle.getAgent(agentId);
|
|
1014
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
1015
|
-
|
|
1016
|
-
const { code } = await c.req.json();
|
|
1017
|
-
if (!code) return c.json({ error: 'OAuth authorization code is required' }, 400);
|
|
1018
|
-
|
|
1019
|
-
const emailConfig = managed.config?.emailConfig;
|
|
1020
|
-
if (!emailConfig) return c.json({ error: 'No email config found — configure email first' }, 400);
|
|
1021
|
-
|
|
1022
|
-
try {
|
|
1023
|
-
if (emailConfig.oauthProvider === 'microsoft') {
|
|
1024
|
-
const tokenRes = await fetch(`https://login.microsoftonline.com/${emailConfig.oauthTenantId || 'common'}/oauth2/v2.0/token`, {
|
|
1025
|
-
method: 'POST',
|
|
1026
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
1027
|
-
body: new URLSearchParams({
|
|
1028
|
-
client_id: emailConfig.oauthClientId,
|
|
1029
|
-
client_secret: emailConfig.oauthClientSecret,
|
|
1030
|
-
code,
|
|
1031
|
-
redirect_uri: emailConfig.oauthRedirectUri,
|
|
1032
|
-
grant_type: 'authorization_code',
|
|
1033
|
-
scope: emailConfig.oauthScopes.join(' '),
|
|
1034
|
-
}),
|
|
1035
|
-
});
|
|
1036
|
-
|
|
1037
|
-
if (!tokenRes.ok) {
|
|
1038
|
-
const errText = await tokenRes.text();
|
|
1039
|
-
return c.json({ error: `Microsoft token exchange failed: ${errText}` }, 400);
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
const tokens = await tokenRes.json() as any;
|
|
1043
|
-
emailConfig.oauthAccessToken = tokens.access_token;
|
|
1044
|
-
emailConfig.oauthRefreshToken = tokens.refresh_token;
|
|
1045
|
-
emailConfig.oauthTokenExpiry = new Date(Date.now() + (tokens.expires_in * 1000)).toISOString();
|
|
1046
|
-
|
|
1047
|
-
// Get the user's email from Graph
|
|
1048
|
-
try {
|
|
1049
|
-
const profileRes = await fetch('https://graph.microsoft.com/v1.0/me?$select=mail,displayName', {
|
|
1050
|
-
headers: { Authorization: `Bearer ${tokens.access_token}` },
|
|
1051
|
-
});
|
|
1052
|
-
if (profileRes.ok) {
|
|
1053
|
-
const profile = await profileRes.json() as any;
|
|
1054
|
-
if (profile.mail) emailConfig.email = profile.mail;
|
|
1055
|
-
}
|
|
1056
|
-
} catch {}
|
|
1057
|
-
|
|
1058
|
-
} else if (emailConfig.oauthProvider === 'google') {
|
|
1059
|
-
const tokenRes = await fetch('https://oauth2.googleapis.com/token', {
|
|
1060
|
-
method: 'POST',
|
|
1061
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
1062
|
-
body: new URLSearchParams({
|
|
1063
|
-
client_id: emailConfig.oauthClientId,
|
|
1064
|
-
client_secret: emailConfig.oauthClientSecret,
|
|
1065
|
-
code,
|
|
1066
|
-
redirect_uri: emailConfig.oauthRedirectUri,
|
|
1067
|
-
grant_type: 'authorization_code',
|
|
1068
|
-
}),
|
|
1069
|
-
});
|
|
1070
|
-
|
|
1071
|
-
if (!tokenRes.ok) {
|
|
1072
|
-
const errText = await tokenRes.text();
|
|
1073
|
-
return c.json({ error: `Google token exchange failed: ${errText}` }, 400);
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
const tokens = await tokenRes.json() as any;
|
|
1077
|
-
emailConfig.oauthAccessToken = tokens.access_token;
|
|
1078
|
-
// Only overwrite refresh_token if Google returned one (re-auth may not include it)
|
|
1079
|
-
if (tokens.refresh_token) {
|
|
1080
|
-
emailConfig.oauthRefreshToken = tokens.refresh_token;
|
|
1081
|
-
}
|
|
1082
|
-
emailConfig.oauthTokenExpiry = new Date(Date.now() + (tokens.expires_in * 1000)).toISOString();
|
|
1083
|
-
|
|
1084
|
-
// Get the user's email from Gmail
|
|
1085
|
-
try {
|
|
1086
|
-
const profileRes = await fetch('https://gmail.googleapis.com/gmail/v1/users/me/profile', {
|
|
1087
|
-
headers: { Authorization: `Bearer ${tokens.access_token}` },
|
|
1088
|
-
});
|
|
1089
|
-
if (profileRes.ok) {
|
|
1090
|
-
const profile = await profileRes.json() as any;
|
|
1091
|
-
if (profile.emailAddress) emailConfig.email = profile.emailAddress;
|
|
1092
|
-
}
|
|
1093
|
-
} catch {}
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
emailConfig.status = 'connected';
|
|
1097
|
-
emailConfig.lastConnected = new Date().toISOString();
|
|
1098
|
-
emailConfig.lastError = null;
|
|
1099
|
-
const _managed = lifecycle.getAgent(agentId); if (_managed) { _managed.config.emailConfig = emailConfig; _managed.updatedAt = new Date().toISOString(); }
|
|
1100
|
-
await lifecycle.saveAgent(agentId);
|
|
1101
|
-
|
|
1102
|
-
return c.json({ success: true, email: emailConfig.email, status: 'connected' });
|
|
1103
|
-
} catch (err: any) {
|
|
1104
|
-
emailConfig.status = 'error';
|
|
1105
|
-
emailConfig.lastError = err.message;
|
|
1106
|
-
const _managed = lifecycle.getAgent(agentId); if (_managed) { _managed.config.emailConfig = emailConfig; _managed.updatedAt = new Date().toISOString(); }
|
|
1107
|
-
await lifecycle.saveAgent(agentId);
|
|
1108
|
-
return c.json({ error: err.message }, 500);
|
|
1109
|
-
}
|
|
1110
|
-
});
|
|
1111
|
-
|
|
1112
|
-
/**
|
|
1113
|
-
* POST /bridge/agents/:id/email-config/test — Test email connection.
|
|
1114
|
-
*/
|
|
1115
|
-
router.post('/bridge/agents/:id/email-config/test', async (c) => {
|
|
1116
|
-
const agentId = c.req.param('id');
|
|
1117
|
-
const managed = lifecycle.getAgent(agentId);
|
|
1118
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
1119
|
-
|
|
1120
|
-
const emailConfig = managed.config?.emailConfig;
|
|
1121
|
-
if (!emailConfig) return c.json({ error: 'No email config found' }, 400);
|
|
1122
|
-
|
|
1123
|
-
try {
|
|
1124
|
-
if (emailConfig.provider === 'imap') {
|
|
1125
|
-
// Test IMAP connection
|
|
1126
|
-
const { ImapFlow } = await import('imapflow');
|
|
1127
|
-
const client = new (ImapFlow as any)({
|
|
1128
|
-
host: emailConfig.imapHost,
|
|
1129
|
-
port: emailConfig.imapPort || 993,
|
|
1130
|
-
secure: true,
|
|
1131
|
-
auth: { user: emailConfig.email, pass: emailConfig.password },
|
|
1132
|
-
logger: false,
|
|
1133
|
-
});
|
|
1134
|
-
await client.connect();
|
|
1135
|
-
const status = await client.status('INBOX', { messages: true, unseen: true });
|
|
1136
|
-
await client.logout();
|
|
1137
|
-
|
|
1138
|
-
return c.json({ success: true, inbox: { total: status.messages, unread: status.unseen } });
|
|
1139
|
-
} else if (emailConfig.provider === 'microsoft' && emailConfig.oauthAccessToken) {
|
|
1140
|
-
const res = await fetch('https://graph.microsoft.com/v1.0/me/mailFolders/inbox?$select=totalItemCount,unreadItemCount', {
|
|
1141
|
-
headers: { Authorization: `Bearer ${emailConfig.oauthAccessToken}` },
|
|
1142
|
-
});
|
|
1143
|
-
if (!res.ok) throw new Error(`Graph API ${res.status}`);
|
|
1144
|
-
const data = await res.json() as any;
|
|
1145
|
-
return c.json({ success: true, inbox: { total: data.totalItemCount, unread: data.unreadItemCount } });
|
|
1146
|
-
} else if (emailConfig.provider === 'google' && emailConfig.oauthAccessToken) {
|
|
1147
|
-
const res = await fetch('https://gmail.googleapis.com/gmail/v1/users/me/profile', {
|
|
1148
|
-
headers: { Authorization: `Bearer ${emailConfig.oauthAccessToken}` },
|
|
1149
|
-
});
|
|
1150
|
-
if (!res.ok) throw new Error(`Gmail API ${res.status}`);
|
|
1151
|
-
const data = await res.json() as any;
|
|
1152
|
-
return c.json({ success: true, email: data.emailAddress, totalMessages: data.messagesTotal });
|
|
1153
|
-
} else {
|
|
1154
|
-
return c.json({ error: 'Provider not fully configured or unsupported' }, 400);
|
|
1155
|
-
}
|
|
1156
|
-
} catch (err: any) {
|
|
1157
|
-
return c.json({ success: false, error: err.message }, 200);
|
|
1158
|
-
}
|
|
1159
|
-
});
|
|
1160
|
-
|
|
1161
|
-
/**
|
|
1162
|
-
* POST /bridge/agents/:id/email-config/test-credentials — Test SMTP/IMAP credentials WITHOUT saving.
|
|
1163
|
-
* Allows user to verify email+password works before committing the config.
|
|
1164
|
-
*/
|
|
1165
|
-
router.post('/bridge/agents/:id/email-config/test-credentials', async (c) => {
|
|
1166
|
-
const body = await c.req.json();
|
|
1167
|
-
const { email, password, imapHost, imapPort, smtpHost, smtpPort } = body;
|
|
1168
|
-
|
|
1169
|
-
if (!email || !password) return c.json({ error: 'Email and password are required' }, 400);
|
|
1170
|
-
if (!imapHost && !smtpHost) return c.json({ error: 'At least IMAP or SMTP host is required' }, 400);
|
|
1171
|
-
|
|
1172
|
-
const results: any = { email };
|
|
1173
|
-
|
|
1174
|
-
// Test IMAP
|
|
1175
|
-
if (imapHost) {
|
|
1176
|
-
try {
|
|
1177
|
-
const { ImapFlow } = await import('imapflow');
|
|
1178
|
-
const client = new (ImapFlow as any)({
|
|
1179
|
-
host: imapHost,
|
|
1180
|
-
port: imapPort || 993,
|
|
1181
|
-
secure: true,
|
|
1182
|
-
auth: { user: email, pass: password },
|
|
1183
|
-
logger: false,
|
|
1184
|
-
tls: { rejectUnauthorized: false },
|
|
1185
|
-
});
|
|
1186
|
-
await client.connect();
|
|
1187
|
-
const status = await client.status('INBOX', { messages: true, unseen: true });
|
|
1188
|
-
await client.logout();
|
|
1189
|
-
results.imap = { success: true, inbox: { total: status.messages, unread: status.unseen } };
|
|
1190
|
-
} catch (err: any) {
|
|
1191
|
-
results.imap = { success: false, error: err.message };
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
// Test SMTP
|
|
1196
|
-
if (smtpHost) {
|
|
1197
|
-
try {
|
|
1198
|
-
const nodemailer = await import('nodemailer');
|
|
1199
|
-
const transport = nodemailer.createTransport({
|
|
1200
|
-
host: smtpHost,
|
|
1201
|
-
port: smtpPort || 587,
|
|
1202
|
-
secure: (smtpPort || 587) === 465,
|
|
1203
|
-
auth: { user: email, pass: password },
|
|
1204
|
-
tls: { rejectUnauthorized: false },
|
|
1205
|
-
} as any);
|
|
1206
|
-
await transport.verify();
|
|
1207
|
-
transport.close();
|
|
1208
|
-
results.smtp = { success: true };
|
|
1209
|
-
} catch (err: any) {
|
|
1210
|
-
results.smtp = { success: false, error: err.message };
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
const allPassed = (!results.imap || results.imap.success) && (!results.smtp || results.smtp.success);
|
|
1215
|
-
return c.json({ success: allPassed, ...results });
|
|
1216
|
-
});
|
|
1217
|
-
|
|
1218
|
-
/**
|
|
1219
|
-
* POST /bridge/agents/:id/email-config/reauthorize — Generate a new OAuth URL with updated scopes.
|
|
1220
|
-
* Preserves all existing config/tokens. Just builds a fresh auth URL for re-consent.
|
|
1221
|
-
*/
|
|
1222
|
-
router.post('/bridge/agents/:id/email-config/reauthorize', async (c) => {
|
|
1223
|
-
const agentId = c.req.param('id');
|
|
1224
|
-
const managed = lifecycle.getAgent(agentId);
|
|
1225
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
1226
|
-
|
|
1227
|
-
const emailConfig = managed.config?.emailConfig;
|
|
1228
|
-
if (!emailConfig) return c.json({ error: 'No email config found' }, 400);
|
|
1229
|
-
|
|
1230
|
-
if (emailConfig.oauthProvider === 'google') {
|
|
1231
|
-
const clientId = emailConfig.oauthClientId;
|
|
1232
|
-
const redirectUri = emailConfig.oauthRedirectUri;
|
|
1233
|
-
if (!clientId) return c.json({ error: 'No OAuth client ID configured' }, 400);
|
|
1234
|
-
|
|
1235
|
-
// Updated scopes
|
|
1236
|
-
const scopes = [
|
|
1237
|
-
'https://www.googleapis.com/auth/gmail.modify',
|
|
1238
|
-
'https://www.googleapis.com/auth/gmail.send',
|
|
1239
|
-
'https://www.googleapis.com/auth/gmail.settings.basic',
|
|
1240
|
-
'https://www.googleapis.com/auth/calendar',
|
|
1241
|
-
'https://www.googleapis.com/auth/drive',
|
|
1242
|
-
'https://www.googleapis.com/auth/spreadsheets',
|
|
1243
|
-
'https://www.googleapis.com/auth/documents',
|
|
1244
|
-
'https://www.googleapis.com/auth/contacts',
|
|
1245
|
-
'https://www.googleapis.com/auth/tasks',
|
|
1246
|
-
'https://www.googleapis.com/auth/chat.spaces',
|
|
1247
|
-
'https://www.googleapis.com/auth/chat.spaces.create',
|
|
1248
|
-
'https://www.googleapis.com/auth/chat.messages',
|
|
1249
|
-
'https://www.googleapis.com/auth/chat.messages.create',
|
|
1250
|
-
'https://www.googleapis.com/auth/chat.memberships',
|
|
1251
|
-
'https://www.googleapis.com/auth/presentations',
|
|
1252
|
-
'https://www.googleapis.com/auth/forms.body',
|
|
1253
|
-
'https://www.googleapis.com/auth/forms.responses.readonly',
|
|
1254
|
-
];
|
|
1255
|
-
|
|
1256
|
-
emailConfig.oauthScopes = scopes;
|
|
1257
|
-
const authUrl = `https://accounts.google.com/o/oauth2/v2/auth?` +
|
|
1258
|
-
`client_id=${encodeURIComponent(clientId)}&response_type=code&` +
|
|
1259
|
-
`redirect_uri=${encodeURIComponent(redirectUri)}&` +
|
|
1260
|
-
`scope=${encodeURIComponent(scopes.join(' '))}&` +
|
|
1261
|
-
`access_type=offline&prompt=consent&state=${agentId}`;
|
|
1262
|
-
emailConfig.oauthAuthUrl = authUrl;
|
|
1263
|
-
|
|
1264
|
-
const _managed = lifecycle.getAgent(agentId);
|
|
1265
|
-
if (_managed) { _managed.config.emailConfig = emailConfig; _managed.updatedAt = new Date().toISOString(); }
|
|
1266
|
-
await lifecycle.saveAgent(agentId);
|
|
1267
|
-
|
|
1268
|
-
return c.json({ success: true, oauthAuthUrl: authUrl, scopeCount: scopes.length });
|
|
1269
|
-
} else if (emailConfig.oauthProvider === 'microsoft') {
|
|
1270
|
-
return c.json({ error: 'Microsoft re-authorization not yet implemented' }, 400);
|
|
1271
|
-
}
|
|
1272
|
-
return c.json({ error: 'No OAuth provider configured' }, 400);
|
|
1273
|
-
});
|
|
1274
|
-
|
|
1275
|
-
/**
|
|
1276
|
-
* DELETE /bridge/agents/:id/email-config — Disconnect email.
|
|
1277
|
-
*/
|
|
1278
|
-
router.delete('/bridge/agents/:id/email-config', async (c) => {
|
|
1279
|
-
const agentId = c.req.param('id');
|
|
1280
|
-
const managed = lifecycle.getAgent(agentId);
|
|
1281
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
1282
|
-
|
|
1283
|
-
const _m = lifecycle.getAgent(agentId); if (_m) { _m.config.emailConfig = null; _m.updatedAt = new Date().toISOString(); }
|
|
1284
|
-
await lifecycle.saveAgent(agentId);
|
|
1285
|
-
return c.json({ success: true });
|
|
1286
|
-
});
|
|
1287
|
-
|
|
1288
|
-
/**
|
|
1289
|
-
* POST /agents/:id/clear-email — Deep clear all email config (agent + DB).
|
|
1290
|
-
* Used when reassigning orgs or manually resetting.
|
|
1291
|
-
*/
|
|
1292
|
-
router.post('/agents/:id/clear-email', async (c) => {
|
|
1293
|
-
const agentId = c.req.param('id');
|
|
1294
|
-
const managed = lifecycle.getAgent(agentId);
|
|
1295
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
1296
|
-
|
|
1297
|
-
// Clear in-memory config
|
|
1298
|
-
managed.config.emailConfig = null;
|
|
1299
|
-
if ((managed.config as any).email) (managed.config as any).email = null;
|
|
1300
|
-
managed.updatedAt = new Date().toISOString();
|
|
1301
|
-
await lifecycle.saveAgent(agentId);
|
|
1302
|
-
|
|
1303
|
-
// Also clear directly in DB to ensure no stale data
|
|
1304
|
-
try {
|
|
1305
|
-
const db = (lifecycle as any).getDb?.() || (globalThis as any).__engineDb;
|
|
1306
|
-
if (db) {
|
|
1307
|
-
const isPostgres = !!(db as any).pool;
|
|
1308
|
-
if (isPostgres) {
|
|
1309
|
-
await (db as any).pool.query(
|
|
1310
|
-
`UPDATE managed_agents SET config = config - 'emailConfig' - 'email', updated_at = NOW() WHERE id = $1`,
|
|
1311
|
-
[agentId]
|
|
1312
|
-
);
|
|
1313
|
-
} else {
|
|
1314
|
-
// SQLite: read, modify, write back
|
|
1315
|
-
const row = await db.get(`SELECT config FROM managed_agents WHERE id = ?`, [agentId]);
|
|
1316
|
-
if (row) {
|
|
1317
|
-
const cfg = JSON.parse((row as any).config || '{}');
|
|
1318
|
-
delete cfg.emailConfig;
|
|
1319
|
-
delete cfg.email;
|
|
1320
|
-
await db.run(`UPDATE managed_agents SET config = ?, updated_at = datetime('now') WHERE id = ?`, [JSON.stringify(cfg), agentId]);
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
} catch { /* best effort DB cleanup */ }
|
|
1325
|
-
|
|
1326
|
-
return c.json({ success: true, cleared: true });
|
|
1327
|
-
});
|
|
1328
|
-
|
|
1329
|
-
// ═══════════════════════════════════════════════════════════
|
|
1330
|
-
// TOOL ACCESS CONFIGURATION
|
|
1331
|
-
// ═══════════════════════════════════════════════════════════
|
|
1332
|
-
|
|
1333
|
-
/** Master tool catalog — all available tools grouped by category */
|
|
1334
|
-
const TOOL_CATALOG = [
|
|
1335
|
-
{
|
|
1336
|
-
id: 'core', name: 'Core Tools', description: 'File operations, shell, search, and browser',
|
|
1337
|
-
icon: Emoji.wrench, alwaysOn: true,
|
|
1338
|
-
tools: ['read', 'write', 'edit', 'bash', 'glob', 'grep', 'web_fetch', 'web_search', 'browser', 'memory'],
|
|
1339
|
-
},
|
|
1340
|
-
{
|
|
1341
|
-
id: 'agenticmail', name: 'AgenticMail', description: 'Email send/receive, inbox management, inter-agent messaging',
|
|
1342
|
-
icon: Emoji.envelope,
|
|
1343
|
-
tools: ['agenticmail_inbox', 'agenticmail_read', 'agenticmail_send', 'agenticmail_reply', 'agenticmail_forward',
|
|
1344
|
-
'agenticmail_search', 'agenticmail_labels', 'agenticmail_folders', 'agenticmail_drafts',
|
|
1345
|
-
'agenticmail_move', 'agenticmail_delete', 'agenticmail_batch_read', 'agenticmail_batch_delete',
|
|
1346
|
-
'agenticmail_contacts', 'agenticmail_templates', 'agenticmail_message_agent', 'agenticmail_call_agent',
|
|
1347
|
-
'agenticmail_check_tasks', 'agenticmail_complete_task', 'agenticmail_identity'],
|
|
1348
|
-
},
|
|
1349
|
-
{
|
|
1350
|
-
id: 'gmail', name: 'Gmail', description: 'Native Gmail API — search, send, reply, labels, drafts, threads, attachments',
|
|
1351
|
-
icon: Emoji.email, requiresOAuth: 'google',
|
|
1352
|
-
tools: ['gmail_search', 'gmail_read', 'gmail_thread', 'gmail_send', 'gmail_reply', 'gmail_forward',
|
|
1353
|
-
'gmail_modify', 'gmail_trash', 'gmail_labels', 'gmail_drafts', 'gmail_attachment', 'gmail_profile', 'gmail_vacation'],
|
|
1354
|
-
},
|
|
1355
|
-
{
|
|
1356
|
-
id: 'google_calendar', name: 'Google Calendar', description: 'Event management, scheduling, free/busy lookup',
|
|
1357
|
-
icon: Emoji.calendar, requiresOAuth: 'google',
|
|
1358
|
-
tools: ['google_calendar_list', 'google_calendar_events', 'google_calendar_create_event',
|
|
1359
|
-
'google_calendar_update_event', 'google_calendar_delete_event', 'google_calendar_freebusy'],
|
|
1360
|
-
},
|
|
1361
|
-
{
|
|
1362
|
-
id: 'google_drive', name: 'Google Drive', description: 'File management, search, sharing, content export',
|
|
1363
|
-
icon: Emoji.folder, requiresOAuth: 'google',
|
|
1364
|
-
tools: ['google_drive_list', 'google_drive_get', 'google_drive_create', 'google_drive_delete',
|
|
1365
|
-
'google_drive_share', 'google_drive_move'],
|
|
1366
|
-
},
|
|
1367
|
-
{
|
|
1368
|
-
id: 'google_sheets', name: 'Google Sheets', description: 'Spreadsheet read/write, cell operations, formulas',
|
|
1369
|
-
icon: Emoji.barChart, requiresOAuth: 'google',
|
|
1370
|
-
tools: ['google_sheets_get', 'google_sheets_read', 'google_sheets_write', 'google_sheets_append',
|
|
1371
|
-
'google_sheets_clear', 'google_sheets_create', 'google_sheets_add_sheet'],
|
|
1372
|
-
},
|
|
1373
|
-
{
|
|
1374
|
-
id: 'google_docs', name: 'Google Docs', description: 'Document read/write, text insert, find & replace',
|
|
1375
|
-
icon: Emoji.note, requiresOAuth: 'google',
|
|
1376
|
-
tools: ['google_docs_read', 'google_docs_create', 'google_docs_write'],
|
|
1377
|
-
},
|
|
1378
|
-
{
|
|
1379
|
-
id: 'google_contacts', name: 'Google Contacts', description: 'Contact search, directory lookup, CRUD',
|
|
1380
|
-
icon: Emoji.people, requiresOAuth: 'google',
|
|
1381
|
-
tools: ['google_contacts_list', 'google_contacts_search', 'google_contacts_search_directory',
|
|
1382
|
-
'google_contacts_create', 'google_contacts_update'],
|
|
1383
|
-
},
|
|
1384
|
-
{
|
|
1385
|
-
id: 'google_tasks', name: 'Google Tasks', description: 'Task lists, create/complete/update tasks, due dates',
|
|
1386
|
-
icon: Emoji.check, requiresOAuth: 'google',
|
|
1387
|
-
tools: ['google_tasks_list_tasklists', 'google_tasks_list', 'google_tasks_create', 'google_tasks_update',
|
|
1388
|
-
'google_tasks_complete', 'google_tasks_delete'],
|
|
1389
|
-
},
|
|
1390
|
-
{
|
|
1391
|
-
id: 'google_chat', name: 'Google Chat', description: 'Send messages, manage spaces, read conversations',
|
|
1392
|
-
icon: Emoji.chat, requiresOAuth: 'google',
|
|
1393
|
-
tools: ['google_chat_list_spaces', 'google_chat_list_members', 'google_chat_list_messages',
|
|
1394
|
-
'google_chat_send_message', 'google_chat_setup_space', 'google_chat_find_dm',
|
|
1395
|
-
'google_chat_get_space', 'google_chat_update_message', 'google_chat_delete_message',
|
|
1396
|
-
'google_chat_add_member', 'google_chat_upload_attachment', 'google_chat_send_image',
|
|
1397
|
-
'google_chat_download_attachment', 'google_chat_react'],
|
|
1398
|
-
},
|
|
1399
|
-
{
|
|
1400
|
-
id: 'google_slides', name: 'Google Slides', description: 'Create and edit presentations, add slides, text, images',
|
|
1401
|
-
icon: Emoji.art, requiresOAuth: 'google',
|
|
1402
|
-
tools: ['google_slides_get', 'google_slides_create', 'google_slides_add_slide',
|
|
1403
|
-
'google_slides_add_text', 'google_slides_add_image'],
|
|
1404
|
-
},
|
|
1405
|
-
{
|
|
1406
|
-
id: 'google_forms', name: 'Google Forms', description: 'Create forms, add questions, read responses',
|
|
1407
|
-
icon: Emoji.clipboard, requiresOAuth: 'google',
|
|
1408
|
-
tools: ['google_forms_get', 'google_forms_create', 'google_forms_add_question',
|
|
1409
|
-
'google_forms_responses', 'google_forms_response_summary'],
|
|
1410
|
-
},
|
|
1411
|
-
{
|
|
1412
|
-
id: 'meetings', name: 'Meetings', description: 'Join Google Meet calls. Take notes, chat, share screen, send summaries.',
|
|
1413
|
-
icon: Emoji.video, requiresOAuth: 'google',
|
|
1414
|
-
tools: ['meetings_upcoming', 'meeting_join', 'meeting_action', 'meetings_scan_inbox', 'meeting_rsvp'],
|
|
1415
|
-
},
|
|
1416
|
-
{
|
|
1417
|
-
id: 'google_maps', name: 'Google Maps', description: 'Places search, directions, distance calculation, geocoding, autocomplete',
|
|
1418
|
-
icon: Emoji.map, requiresIntegration: 'google-maps',
|
|
1419
|
-
tools: ['google_maps_search', 'google_maps_nearby', 'google_maps_place_details', 'google_maps_directions',
|
|
1420
|
-
'google_maps_distance', 'google_maps_geocode', 'google_maps_autocomplete', 'google_maps_static',
|
|
1421
|
-
'google_maps_timezone', 'google_maps_elevation'],
|
|
1422
|
-
},
|
|
1423
|
-
{
|
|
1424
|
-
id: 'enterprise_database', name: 'Database', description: 'SQL queries, schema inspection, data sampling',
|
|
1425
|
-
icon: Emoji.database,
|
|
1426
|
-
tools: ['enterprise_sql_query', 'enterprise_sql_schema', 'enterprise_sql_explain',
|
|
1427
|
-
'enterprise_sql_tables', 'enterprise_sql_sample', 'enterprise_sql_write'],
|
|
1428
|
-
},
|
|
1429
|
-
{
|
|
1430
|
-
id: 'enterprise_spreadsheet', name: 'Spreadsheet', description: 'CSV/Excel read, write, filter, aggregate, transform, pivot',
|
|
1431
|
-
icon: Emoji.chartUp,
|
|
1432
|
-
tools: ['enterprise_csv_read', 'enterprise_csv_write', 'enterprise_csv_filter', 'enterprise_csv_aggregate',
|
|
1433
|
-
'enterprise_csv_transform', 'enterprise_csv_merge', 'enterprise_csv_pivot', 'enterprise_csv_convert'],
|
|
1434
|
-
},
|
|
1435
|
-
{
|
|
1436
|
-
id: 'enterprise_documents', name: 'Documents', description: 'PDF/DOCX generation, OCR, format conversion',
|
|
1437
|
-
icon: Emoji.document,
|
|
1438
|
-
tools: ['enterprise_pdf_generate', 'enterprise_docx_generate', 'enterprise_ocr', 'enterprise_invoice_parse',
|
|
1439
|
-
'enterprise_doc_convert', 'enterprise_doc_merge', 'enterprise_doc_extract', 'enterprise_doc_sign'],
|
|
1440
|
-
},
|
|
1441
|
-
{
|
|
1442
|
-
id: 'enterprise_http', name: 'HTTP Client', description: 'HTTP requests, GraphQL, batch calls, downloads',
|
|
1443
|
-
icon: Emoji.globe,
|
|
1444
|
-
tools: ['enterprise_http_request', 'enterprise_http_graphql', 'enterprise_http_batch', 'enterprise_http_download'],
|
|
1445
|
-
},
|
|
1446
|
-
{
|
|
1447
|
-
id: 'enterprise_security', name: 'Security Scanning', description: 'Secret scanning, PII detection, dependency audit',
|
|
1448
|
-
icon: Emoji.lock,
|
|
1449
|
-
tools: ['enterprise_secret_scan', 'enterprise_pii_scan', 'enterprise_pii_redact',
|
|
1450
|
-
'enterprise_dep_audit', 'enterprise_compliance_check', 'enterprise_hash'],
|
|
1451
|
-
},
|
|
1452
|
-
{
|
|
1453
|
-
id: 'enterprise_code', name: 'Code Sandbox', description: 'Run JavaScript, Python, shell scripts, JSON transforms',
|
|
1454
|
-
icon: Emoji.computer,
|
|
1455
|
-
tools: ['enterprise_run_js', 'enterprise_run_python', 'enterprise_run_shell',
|
|
1456
|
-
'enterprise_json_transform', 'enterprise_regex'],
|
|
1457
|
-
},
|
|
1458
|
-
{
|
|
1459
|
-
id: 'enterprise_diff', name: 'Diff', description: 'Text, JSON, and spreadsheet comparison',
|
|
1460
|
-
icon: Emoji.biDirectional,
|
|
1461
|
-
tools: ['enterprise_text_diff', 'enterprise_json_diff', 'enterprise_spreadsheet_diff', 'enterprise_diff_summary'],
|
|
1462
|
-
},
|
|
1463
|
-
{
|
|
1464
|
-
id: 'visual-memory', name: 'Visual Memory', description: 'Persistent visual memory — capture screenshots, detect changes, recall visual history. Enterprise DB-backed with BM25F search.',
|
|
1465
|
-
icon: Emoji.eye,
|
|
1466
|
-
tools: ['vision_capture', 'vision_query', 'vision_compare', 'vision_diff', 'vision_similar',
|
|
1467
|
-
'vision_track', 'vision_ocr', 'vision_health', 'vision_session_start', 'vision_session_end'],
|
|
1468
|
-
},
|
|
1469
|
-
{
|
|
1470
|
-
id: 'local_filesystem', name: 'Filesystem', description: 'Read, write, edit, move, delete, search, and list files on the host machine.',
|
|
1471
|
-
icon: Emoji.folder,
|
|
1472
|
-
tools: ['file_read', 'file_write', 'file_edit', 'file_list', 'file_search', 'file_move', 'file_delete'],
|
|
1473
|
-
},
|
|
1474
|
-
{
|
|
1475
|
-
id: 'local_shell', name: 'Shell & System', description: 'Execute commands, interactive PTY sessions, sudo, package installation, system info.',
|
|
1476
|
-
icon: Emoji.terminal,
|
|
1477
|
-
tools: ['shell_exec', 'shell_interactive', 'shell_sudo', 'shell_install', 'shell_session_list', 'shell_session_kill', 'system_info'],
|
|
1478
|
-
},
|
|
1479
|
-
{
|
|
1480
|
-
id: 'whatsapp', name: 'WhatsApp', description: 'WhatsApp messaging via linked device. QR code scan to connect — no Business API needed.',
|
|
1481
|
-
icon: Emoji.whatsapp || Emoji.chat,
|
|
1482
|
-
tools: ['whatsapp_connect', 'whatsapp_status', 'whatsapp_send', 'whatsapp_send_media', 'whatsapp_get_groups',
|
|
1483
|
-
'whatsapp_send_voice', 'whatsapp_send_location', 'whatsapp_send_contact', 'whatsapp_react',
|
|
1484
|
-
'whatsapp_typing', 'whatsapp_read_receipts', 'whatsapp_profile', 'whatsapp_group_manage',
|
|
1485
|
-
'whatsapp_delete_message', 'whatsapp_forward', 'whatsapp_disconnect'],
|
|
1486
|
-
},
|
|
1487
|
-
{
|
|
1488
|
-
id: 'telegram', name: 'Telegram', description: 'Telegram Bot API — send messages, media, manage chats. Requires a bot token.',
|
|
1489
|
-
icon: Emoji.telegram || Emoji.chat, requiresIntegration: 'telegram',
|
|
1490
|
-
tools: ['telegram_send', 'telegram_send_media', 'telegram_get_me', 'telegram_get_chat'],
|
|
1491
|
-
},
|
|
1492
|
-
// ── Microsoft 365 ──────────────────────────────────
|
|
1493
|
-
{
|
|
1494
|
-
id: 'outlook_mail', name: 'Outlook Mail', description: 'Full email management — inbox, send, reply, forward, search, threads, drafts, rules, auto-reply, categories',
|
|
1495
|
-
icon: Emoji.envelope, requiresOAuth: 'microsoft',
|
|
1496
|
-
tools: ['outlook_mail_list', 'outlook_mail_read', 'outlook_mail_thread', 'outlook_mail_send', 'outlook_mail_reply',
|
|
1497
|
-
'outlook_mail_forward', 'outlook_mail_move', 'outlook_mail_delete', 'outlook_mail_update', 'outlook_mail_search',
|
|
1498
|
-
'outlook_mail_draft', 'outlook_mail_send_draft', 'outlook_mail_folders', 'outlook_mail_create_folder',
|
|
1499
|
-
'outlook_mail_attachment_download', 'outlook_mail_auto_reply', 'outlook_mail_get_auto_reply',
|
|
1500
|
-
'outlook_mail_rules', 'outlook_mail_categories', 'outlook_mail_profile'],
|
|
1501
|
-
},
|
|
1502
|
-
{
|
|
1503
|
-
id: 'outlook_calendar', name: 'Outlook Calendar', description: 'Calendar events, scheduling, free/busy lookup, Teams meeting creation, invite responses',
|
|
1504
|
-
icon: Emoji.calendar, requiresOAuth: 'microsoft',
|
|
1505
|
-
tools: ['outlook_calendar_list', 'outlook_calendar_events', 'outlook_calendar_create', 'outlook_calendar_update',
|
|
1506
|
-
'outlook_calendar_delete', 'outlook_calendar_respond', 'outlook_calendar_freebusy'],
|
|
1507
|
-
},
|
|
1508
|
-
{
|
|
1509
|
-
id: 'onedrive', name: 'OneDrive', description: 'Cloud file management — list, search, read, upload, share, create folders',
|
|
1510
|
-
icon: Emoji.folder, requiresOAuth: 'microsoft',
|
|
1511
|
-
tools: ['onedrive_list', 'onedrive_search', 'onedrive_read', 'onedrive_upload', 'onedrive_create_folder',
|
|
1512
|
-
'onedrive_delete', 'onedrive_share'],
|
|
1513
|
-
},
|
|
1514
|
-
{
|
|
1515
|
-
id: 'teams', name: 'Microsoft Teams', description: 'Team messaging, channels, chats, file sharing, presence, member management',
|
|
1516
|
-
icon: Emoji.chat, requiresOAuth: 'microsoft',
|
|
1517
|
-
tools: ['teams_list_teams', 'teams_list_channels', 'teams_create_channel', 'teams_send_channel_message',
|
|
1518
|
-
'teams_reply_to_message', 'teams_read_channel_messages', 'teams_list_chats', 'teams_send_chat_message',
|
|
1519
|
-
'teams_read_chat_messages', 'teams_list_members', 'teams_add_member', 'teams_share_file',
|
|
1520
|
-
'teams_presence', 'teams_set_status'],
|
|
1521
|
-
},
|
|
1522
|
-
{
|
|
1523
|
-
id: 'todo', name: 'Microsoft To Do', description: 'Task lists, task CRUD with due dates, reminders, and importance',
|
|
1524
|
-
icon: Emoji.check, requiresOAuth: 'microsoft',
|
|
1525
|
-
tools: ['todo_list_lists', 'todo_list_tasks', 'todo_create_task', 'todo_update_task', 'todo_delete_task', 'todo_create_list'],
|
|
1526
|
-
},
|
|
1527
|
-
{
|
|
1528
|
-
id: 'outlook_contacts', name: 'Outlook Contacts', description: 'Contact management, address book, people search',
|
|
1529
|
-
icon: Emoji.people, requiresOAuth: 'microsoft',
|
|
1530
|
-
tools: ['outlook_contacts_list', 'outlook_contacts_create', 'outlook_contacts_update', 'outlook_contacts_delete', 'outlook_people_search'],
|
|
1531
|
-
},
|
|
1532
|
-
{
|
|
1533
|
-
id: 'excel', name: 'Microsoft Excel', description: 'Read/write cells, ranges, tables, worksheets, formulas, charts, formatting',
|
|
1534
|
-
icon: Emoji.chartUp, requiresOAuth: 'microsoft',
|
|
1535
|
-
tools: ['excel_list_worksheets', 'excel_read_range', 'excel_write_range', 'excel_add_row', 'excel_list_tables',
|
|
1536
|
-
'excel_read_table', 'excel_create_worksheet', 'excel_create_session', 'excel_close_session',
|
|
1537
|
-
'excel_evaluate_formula', 'excel_named_ranges', 'excel_read_named_range', 'excel_list_charts',
|
|
1538
|
-
'excel_chart_image', 'excel_pivot_refresh', 'excel_set_cell_format'],
|
|
1539
|
-
},
|
|
1540
|
-
{
|
|
1541
|
-
id: 'sharepoint', name: 'SharePoint', description: 'Sites, document libraries, lists, search, file management across SharePoint Online',
|
|
1542
|
-
icon: Emoji.database, requiresOAuth: 'microsoft',
|
|
1543
|
-
tools: ['sharepoint_list_sites', 'sharepoint_get_site', 'sharepoint_list_drives', 'sharepoint_list_files',
|
|
1544
|
-
'sharepoint_upload_file', 'sharepoint_list_lists', 'sharepoint_list_items', 'sharepoint_create_list_item',
|
|
1545
|
-
'sharepoint_update_list_item', 'sharepoint_search'],
|
|
1546
|
-
},
|
|
1547
|
-
{
|
|
1548
|
-
id: 'onenote', name: 'OneNote', description: 'Notebooks, sections, pages — read, create, and update notes',
|
|
1549
|
-
icon: Emoji.note, requiresOAuth: 'microsoft',
|
|
1550
|
-
tools: ['onenote_list_notebooks', 'onenote_list_sections', 'onenote_list_pages', 'onenote_read_page',
|
|
1551
|
-
'onenote_create_page', 'onenote_update_page'],
|
|
1552
|
-
},
|
|
1553
|
-
{
|
|
1554
|
-
id: 'powerpoint', name: 'PowerPoint', description: 'Presentation metadata, PDF export, thumbnails, templates, embed URLs',
|
|
1555
|
-
icon: Emoji.art, requiresOAuth: 'microsoft',
|
|
1556
|
-
tools: ['powerpoint_get_info', 'powerpoint_export_pdf', 'powerpoint_get_thumbnails',
|
|
1557
|
-
'powerpoint_create_from_template', 'powerpoint_get_embed_url'],
|
|
1558
|
-
},
|
|
1559
|
-
{
|
|
1560
|
-
id: 'planner', name: 'Microsoft Planner', description: 'Project boards — plans, buckets, tasks (Kanban-style task management)',
|
|
1561
|
-
icon: Emoji.clipboard, requiresOAuth: 'microsoft',
|
|
1562
|
-
tools: ['planner_list_plans', 'planner_list_buckets', 'planner_list_tasks', 'planner_create_task',
|
|
1563
|
-
'planner_update_task', 'planner_delete_task'],
|
|
1564
|
-
},
|
|
1565
|
-
{
|
|
1566
|
-
id: 'powerbi', name: 'Power BI', description: 'Workspaces, reports, dashboards, datasets, DAX queries, data refresh',
|
|
1567
|
-
icon: Emoji.barChart, requiresOAuth: 'microsoft',
|
|
1568
|
-
tools: ['powerbi_list_workspaces', 'powerbi_list_reports', 'powerbi_list_dashboards', 'powerbi_list_datasets',
|
|
1569
|
-
'powerbi_refresh_dataset', 'powerbi_refresh_history', 'powerbi_execute_query', 'powerbi_dashboard_tiles'],
|
|
1570
|
-
},
|
|
1571
|
-
];
|
|
1572
|
-
|
|
1573
|
-
// ═══════════════════════════════════════════════════════════
|
|
1574
|
-
// SYSTEM CAPABILITIES
|
|
1575
|
-
// ═══════════════════════════════════════════════════════════
|
|
1576
|
-
|
|
1577
|
-
router.get('/bridge/system/capabilities', async (c) => {
|
|
1578
|
-
try {
|
|
1579
|
-
const { detectCapabilities, getCapabilitySummary } = await import('../runtime/environment.js');
|
|
1580
|
-
const caps = detectCapabilities();
|
|
1581
|
-
const summary = getCapabilitySummary(caps);
|
|
1582
|
-
return c.json({ ...summary, raw: caps });
|
|
1583
|
-
} catch (e: any) {
|
|
1584
|
-
return c.json({ error: e.message }, 500);
|
|
1585
|
-
}
|
|
1586
|
-
});
|
|
1587
|
-
|
|
1588
|
-
// BROWSER CONFIGURATION
|
|
1589
|
-
// ═══════════════════════════════════════════════════════════
|
|
1590
|
-
|
|
1591
|
-
router.get('/bridge/agents/:id/browser-config', (c) => {
|
|
1592
|
-
const agentId = c.req.param('id');
|
|
1593
|
-
const managed = lifecycle.getAgent(agentId);
|
|
1594
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
1595
|
-
return c.json({ config: managed.config?.browserConfig || {} });
|
|
1596
|
-
});
|
|
1597
|
-
|
|
1598
|
-
// ── In-memory registry of running meeting browsers (survives config save/reload issues) ──
|
|
1599
|
-
const meetingBrowsers = new Map<string, { port: number; cdpUrl: string; pid?: number }>();
|
|
1600
|
-
|
|
1601
|
-
/**
|
|
1602
|
-
* POST /bridge/agents/:id/browser-config/launch-meeting-browser
|
|
1603
|
-
* Launches a meeting-ready headed Chrome instance with virtual display + audio.
|
|
1604
|
-
* Returns the CDP URL for the agent to connect to.
|
|
1605
|
-
*/
|
|
1606
|
-
router.post('/bridge/agents/:id/browser-config/launch-meeting-browser', async (c) => {
|
|
1607
|
-
const agentId = c.req.param('id');
|
|
1608
|
-
const managed = lifecycle.getAgent(agentId);
|
|
1609
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
1610
|
-
|
|
1611
|
-
try {
|
|
1612
|
-
// Check system capabilities first
|
|
1613
|
-
const { detectCapabilities, getCapabilitySummary } = await import('../runtime/environment.js');
|
|
1614
|
-
const caps = detectCapabilities();
|
|
1615
|
-
if (!caps.canJoinMeetings) {
|
|
1616
|
-
const summary = getCapabilitySummary(caps);
|
|
1617
|
-
return c.json({
|
|
1618
|
-
error: 'Meeting browser cannot run on this ' + summary.deployment + ' deployment',
|
|
1619
|
-
deployment: summary.deployment,
|
|
1620
|
-
missing: summary.unavailable,
|
|
1621
|
-
recommendations: summary.recommendations,
|
|
1622
|
-
hint: 'Deploy on a VM with display + audio, or configure a Remote Browser (CDP) provider.',
|
|
1623
|
-
}, 400);
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1626
|
-
const { execSync, spawn } = await import('node:child_process');
|
|
1627
|
-
const { existsSync, mkdirSync, writeFileSync } = await import('node:fs');
|
|
1628
|
-
const { join, dirname } = await import('node:path');
|
|
1629
|
-
const { homedir } = await import('node:os');
|
|
1630
|
-
|
|
1631
|
-
// ── Auto-detect Chrome/Chromium across all platforms ──
|
|
1632
|
-
const chromeCandidates = [
|
|
1633
|
-
process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH,
|
|
1634
|
-
// macOS
|
|
1635
|
-
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
1636
|
-
'/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
|
|
1637
|
-
'/Applications/Chromium.app/Contents/MacOS/Chromium',
|
|
1638
|
-
// Linux
|
|
1639
|
-
'/usr/bin/google-chrome',
|
|
1640
|
-
'/usr/bin/google-chrome-stable',
|
|
1641
|
-
'/usr/bin/chromium',
|
|
1642
|
-
'/usr/bin/chromium-browser',
|
|
1643
|
-
'/snap/bin/chromium',
|
|
1644
|
-
'/usr/local/bin/chromium',
|
|
1645
|
-
// Windows
|
|
1646
|
-
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
1647
|
-
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
|
|
1648
|
-
// Playwright bundled (check common install locations)
|
|
1649
|
-
join(homedir(), '.cache', 'ms-playwright', 'chromium-*', 'chrome-linux', 'chrome'),
|
|
1650
|
-
join(homedir(), '.cache', 'ms-playwright', 'chromium-*', 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium'),
|
|
1651
|
-
].filter(Boolean) as string[];
|
|
1652
|
-
|
|
1653
|
-
let chromePath = '';
|
|
1654
|
-
for (const candidate of chromeCandidates) {
|
|
1655
|
-
if (candidate.includes('*')) {
|
|
1656
|
-
// Glob pattern — resolve with fs
|
|
1657
|
-
try {
|
|
1658
|
-
const { globSync } = await import('node:fs');
|
|
1659
|
-
const matches = (globSync as any)(candidate);
|
|
1660
|
-
if (matches?.length && existsSync(matches[0])) { chromePath = matches[0]; break; }
|
|
1661
|
-
} catch {
|
|
1662
|
-
// globSync not available in older Node, try manual resolve
|
|
1663
|
-
try {
|
|
1664
|
-
const parentDir = dirname(candidate.split('*')[0]);
|
|
1665
|
-
if (existsSync(parentDir)) {
|
|
1666
|
-
const { readdirSync } = await import('node:fs');
|
|
1667
|
-
const dirs = readdirSync(parentDir).filter((d: string) => d.startsWith('chromium-')).sort().reverse();
|
|
1668
|
-
for (const d of dirs) {
|
|
1669
|
-
const suffix = candidate.split('*')[1];
|
|
1670
|
-
const resolved = join(parentDir, d, suffix);
|
|
1671
|
-
if (existsSync(resolved)) { chromePath = resolved; break; }
|
|
1672
|
-
}
|
|
1673
|
-
if (chromePath) break;
|
|
1674
|
-
}
|
|
1675
|
-
} catch { /* skip */ }
|
|
1676
|
-
}
|
|
1677
|
-
} else if (existsSync(candidate)) {
|
|
1678
|
-
chromePath = candidate;
|
|
1679
|
-
break;
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
// If no Chrome found, try to install Playwright Chromium automatically
|
|
1684
|
-
if (!chromePath) {
|
|
1685
|
-
try {
|
|
1686
|
-
console.log('[meeting-browser] No Chrome/Chromium found — installing Playwright Chromium...');
|
|
1687
|
-
execSync('npx playwright install chromium 2>&1', { timeout: 120_000, stdio: 'pipe' });
|
|
1688
|
-
// Re-check for Playwright Chromium
|
|
1689
|
-
const pwCacheDir = join(homedir(), '.cache', 'ms-playwright');
|
|
1690
|
-
if (existsSync(pwCacheDir)) {
|
|
1691
|
-
const { readdirSync } = await import('node:fs');
|
|
1692
|
-
const chromiumDirs = readdirSync(pwCacheDir).filter((d: string) => d.startsWith('chromium-')).sort().reverse();
|
|
1693
|
-
for (const d of chromiumDirs) {
|
|
1694
|
-
// Try Linux path
|
|
1695
|
-
const linuxPath = join(pwCacheDir, d, 'chrome-linux', 'chrome');
|
|
1696
|
-
if (existsSync(linuxPath)) { chromePath = linuxPath; break; }
|
|
1697
|
-
// Try macOS path
|
|
1698
|
-
const macPath = join(pwCacheDir, d, 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium');
|
|
1699
|
-
if (existsSync(macPath)) { chromePath = macPath; break; }
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
} catch (installErr: any) {
|
|
1703
|
-
console.error('[meeting-browser] Failed to auto-install Chromium:', installErr.message);
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
|
|
1707
|
-
if (!chromePath) {
|
|
1708
|
-
return c.json({
|
|
1709
|
-
error: 'No Chrome or Chromium browser found on this machine. Install Google Chrome or run: npx playwright install chromium',
|
|
1710
|
-
hint: 'On macOS: brew install --cask google-chrome | On Linux: apt install chromium-browser | On Windows: download from google.com/chrome',
|
|
1711
|
-
}, 400);
|
|
1712
|
-
}
|
|
1713
|
-
|
|
1714
|
-
// Check if a meeting browser is already running for this agent (in-memory registry first, then config fallback)
|
|
1715
|
-
const tracked = meetingBrowsers.get(agentId);
|
|
1716
|
-
const existingPort = tracked?.port || (managed.config as any)?.meetingBrowserPort;
|
|
1717
|
-
if (existingPort) {
|
|
1718
|
-
try {
|
|
1719
|
-
const resp = await fetch(`http://127.0.0.1:${existingPort}/json/version`, { signal: AbortSignal.timeout(2000) });
|
|
1720
|
-
if (resp.ok) {
|
|
1721
|
-
const data = await resp.json() as any;
|
|
1722
|
-
// Ensure registry is up to date
|
|
1723
|
-
meetingBrowsers.set(agentId, { port: existingPort, cdpUrl: data.webSocketDebuggerUrl, pid: tracked?.pid });
|
|
1724
|
-
return c.json({ ok: true, alreadyRunning: true, cdpUrl: data.webSocketDebuggerUrl, port: existingPort, browserVersion: data.Browser });
|
|
1725
|
-
}
|
|
1726
|
-
} catch { /* not running, will launch new one */ }
|
|
1727
|
-
// Was tracked but not responding — clean up
|
|
1728
|
-
meetingBrowsers.delete(agentId);
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
// ── Create a realistic browser profile using agent identity ──
|
|
1732
|
-
const agentName = managed.displayName || managed.display_name || managed.name || (managed.config as any)?.displayName || (managed.config as any)?.name || 'Agent';
|
|
1733
|
-
const _agentRole = (managed.config as any)?.role || (managed.config as any)?.description || 'AI Assistant';
|
|
1734
|
-
const profileDir = join(homedir(), '.agenticmail', 'browser-profiles', agentId);
|
|
1735
|
-
mkdirSync(profileDir, { recursive: true });
|
|
1736
|
-
|
|
1737
|
-
// Write Chrome preferences to make the browser look like a real user
|
|
1738
|
-
const prefsDir = join(profileDir, 'Default');
|
|
1739
|
-
mkdirSync(prefsDir, { recursive: true });
|
|
1740
|
-
const prefsFile = join(prefsDir, 'Preferences');
|
|
1741
|
-
if (!existsSync(prefsFile)) {
|
|
1742
|
-
const prefs = {
|
|
1743
|
-
profile: {
|
|
1744
|
-
name: agentName,
|
|
1745
|
-
avatar_index: Math.floor(Math.random() * 28), // Chrome has 28 avatar options
|
|
1746
|
-
managed_user_id: '',
|
|
1747
|
-
is_using_default_name: false,
|
|
1748
|
-
is_using_default_avatar: false,
|
|
1749
|
-
},
|
|
1750
|
-
browser: {
|
|
1751
|
-
has_seen_welcome_page: true,
|
|
1752
|
-
check_default_browser: false,
|
|
1753
|
-
},
|
|
1754
|
-
distribution: {
|
|
1755
|
-
import_bookmarks: false,
|
|
1756
|
-
import_history: false,
|
|
1757
|
-
import_search_engine: false,
|
|
1758
|
-
suppress_first_run_bubble: true,
|
|
1759
|
-
suppress_first_run_default_browser_prompt: true,
|
|
1760
|
-
skip_first_run_ui: true,
|
|
1761
|
-
make_chrome_default_for_user: false,
|
|
1762
|
-
},
|
|
1763
|
-
session: { restore_on_startup: 1 },
|
|
1764
|
-
search: { suggest_enabled: true },
|
|
1765
|
-
translate: { enabled: false },
|
|
1766
|
-
net: { network_prediction_options: 2 }, // don't prefetch
|
|
1767
|
-
webkit: { webprefs: { default_font_size: 16 } },
|
|
1768
|
-
download: { prompt_for_download: true, default_directory: join(profileDir, 'Downloads') },
|
|
1769
|
-
savefile: { default_directory: join(profileDir, 'Downloads') },
|
|
1770
|
-
credentials_enable_service: false,
|
|
1771
|
-
credentials_enable_autosign_in: false,
|
|
1772
|
-
};
|
|
1773
|
-
mkdirSync(join(profileDir, 'Downloads'), { recursive: true });
|
|
1774
|
-
writeFileSync(prefsFile, JSON.stringify(prefs, null, 2));
|
|
1775
|
-
}
|
|
1776
|
-
|
|
1777
|
-
// Find available port
|
|
1778
|
-
const net = await import('node:net');
|
|
1779
|
-
const port = await new Promise<number>((resolve, reject) => {
|
|
1780
|
-
const srv = net.createServer();
|
|
1781
|
-
srv.listen(0, '127.0.0.1', () => {
|
|
1782
|
-
const p = (srv.address() as any).port;
|
|
1783
|
-
srv.close(() => resolve(p));
|
|
1784
|
-
});
|
|
1785
|
-
srv.on('error', reject);
|
|
1786
|
-
});
|
|
1787
|
-
|
|
1788
|
-
// Launch Chrome with meeting-optimized flags and realistic profile
|
|
1789
|
-
const chromeArgs = [
|
|
1790
|
-
`--remote-debugging-port=${port}`,
|
|
1791
|
-
'--remote-debugging-address=127.0.0.1',
|
|
1792
|
-
'--no-first-run',
|
|
1793
|
-
'--no-default-browser-check',
|
|
1794
|
-
'--disable-background-networking',
|
|
1795
|
-
'--disable-sync',
|
|
1796
|
-
'--disable-translate',
|
|
1797
|
-
'--metrics-recording-only',
|
|
1798
|
-
// Meeting-specific: auto-grant camera/mic permissions
|
|
1799
|
-
'--use-fake-ui-for-media-stream',
|
|
1800
|
-
'--auto-accept-camera-and-microphone-capture',
|
|
1801
|
-
// Anti-detection: remove automation indicators
|
|
1802
|
-
'--disable-blink-features=AutomationControlled',
|
|
1803
|
-
'--disable-infobars',
|
|
1804
|
-
// Window size for meeting UI
|
|
1805
|
-
'--window-size=1920,1080',
|
|
1806
|
-
'--start-maximized',
|
|
1807
|
-
// Use the agent's persistent profile directory
|
|
1808
|
-
`--user-data-dir=${profileDir}`,
|
|
1809
|
-
// Realistic user-agent lang
|
|
1810
|
-
'--lang=en-US',
|
|
1811
|
-
];
|
|
1812
|
-
|
|
1813
|
-
// Add --no-sandbox on Linux (required for non-root in containers)
|
|
1814
|
-
if (process.platform === 'linux') {
|
|
1815
|
-
chromeArgs.push('--no-sandbox');
|
|
1816
|
-
}
|
|
1817
|
-
|
|
1818
|
-
// Detect display environment
|
|
1819
|
-
const display = process.env.DISPLAY || (process.platform === 'linux' ? ':99' : undefined);
|
|
1820
|
-
const envVars: Record<string, string> = { ...process.env } as any;
|
|
1821
|
-
if (display) envVars.DISPLAY = display;
|
|
1822
|
-
|
|
1823
|
-
const child = spawn(chromePath, chromeArgs, {
|
|
1824
|
-
detached: true,
|
|
1825
|
-
stdio: 'ignore',
|
|
1826
|
-
env: envVars,
|
|
1827
|
-
});
|
|
1828
|
-
child.unref();
|
|
1829
|
-
|
|
1830
|
-
// Wait for Chrome to be ready
|
|
1831
|
-
let cdpUrl = '';
|
|
1832
|
-
let browserVersion = '';
|
|
1833
|
-
for (let i = 0; i < 30; i++) {
|
|
1834
|
-
await new Promise(r => setTimeout(r, 500));
|
|
1835
|
-
try {
|
|
1836
|
-
const resp = await fetch(`http://127.0.0.1:${port}/json/version`, { signal: AbortSignal.timeout(2000) });
|
|
1837
|
-
if (resp.ok) {
|
|
1838
|
-
const data = await resp.json() as any;
|
|
1839
|
-
cdpUrl = data.webSocketDebuggerUrl;
|
|
1840
|
-
browserVersion = data.Browser;
|
|
1841
|
-
break;
|
|
1842
|
-
}
|
|
1843
|
-
} catch { /* retry */ }
|
|
1844
|
-
}
|
|
1845
|
-
|
|
1846
|
-
if (!cdpUrl) {
|
|
1847
|
-
return c.json({ error: 'Chrome launched but CDP not responding after 15s' });
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
// Save to in-memory registry (primary) and agent config (backup)
|
|
1851
|
-
meetingBrowsers.set(agentId, { port, cdpUrl, pid: child.pid });
|
|
1852
|
-
if (!managed.config) managed.config = {} as any;
|
|
1853
|
-
(managed.config as any).meetingBrowserPort = port;
|
|
1854
|
-
(managed.config as any).meetingBrowserCdpUrl = cdpUrl;
|
|
1855
|
-
managed.updatedAt = new Date().toISOString();
|
|
1856
|
-
try { await lifecycle.saveAgent(agentId); } catch (e) { console.warn('[meeting-browser] Config save failed (non-fatal):', e); }
|
|
1857
|
-
|
|
1858
|
-
return c.json({ ok: true, cdpUrl, port, browserVersion, pid: child.pid });
|
|
1859
|
-
} catch (e: any) {
|
|
1860
|
-
return c.json({ error: 'Failed to launch meeting browser: ' + e.message });
|
|
1861
|
-
}
|
|
1862
|
-
});
|
|
1863
|
-
|
|
1864
|
-
/**
|
|
1865
|
-
* POST /bridge/agents/:id/browser-config/stop-meeting-browser
|
|
1866
|
-
* Kills the meeting browser process for this agent.
|
|
1867
|
-
*/
|
|
1868
|
-
router.post('/bridge/agents/:id/browser-config/stop-meeting-browser', async (c) => {
|
|
1869
|
-
const agentId = c.req.param('id');
|
|
1870
|
-
const managed = lifecycle.getAgent(agentId);
|
|
1871
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
1872
|
-
|
|
1873
|
-
try {
|
|
1874
|
-
const body = await c.req.json().catch(() => ({})) as any;
|
|
1875
|
-
const tracked = meetingBrowsers.get(agentId);
|
|
1876
|
-
const port = tracked?.port || (managed.config as any)?.meetingBrowserPort || body.port;
|
|
1877
|
-
if (!port) return c.json({ error: 'No meeting browser is tracked for this agent' }, 400);
|
|
1878
|
-
|
|
1879
|
-
// Try to close gracefully via CDP
|
|
1880
|
-
let closed = false;
|
|
1881
|
-
try {
|
|
1882
|
-
const resp = await fetch(`http://127.0.0.1:${port}/json/version`, { signal: AbortSignal.timeout(2000) });
|
|
1883
|
-
if (resp.ok) {
|
|
1884
|
-
// Get the websocket URL and send Browser.close
|
|
1885
|
-
const data = await resp.json() as any;
|
|
1886
|
-
if (data.webSocketDebuggerUrl) {
|
|
1887
|
-
try {
|
|
1888
|
-
const _closeResp = await fetch(`http://127.0.0.1:${port}/json/close`, { method: 'PUT', signal: AbortSignal.timeout(3000) });
|
|
1889
|
-
closed = true;
|
|
1890
|
-
} catch { /* fallback to kill */ }
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
} catch { /* not running or not reachable */ }
|
|
1894
|
-
|
|
1895
|
-
// Fallback: kill by PID first (most reliable), then by port
|
|
1896
|
-
if (!closed && tracked?.pid) {
|
|
1897
|
-
try { process.kill(tracked.pid, 'SIGTERM'); closed = true; } catch { /* already dead */ }
|
|
1898
|
-
}
|
|
1899
|
-
if (!closed) {
|
|
1900
|
-
try {
|
|
1901
|
-
const { execSync } = await import('node:child_process');
|
|
1902
|
-
if (process.platform === 'win32') {
|
|
1903
|
-
execSync(`for /f "tokens=5" %a in ('netstat -ano ^| findstr :${port}') do taskkill /PID %a /F 2>nul`, { timeout: 5000 });
|
|
1904
|
-
} else {
|
|
1905
|
-
execSync(`lsof -ti:${port} | xargs kill -9 2>/dev/null || fuser -k ${port}/tcp 2>/dev/null || true`, { timeout: 5000 });
|
|
1906
|
-
}
|
|
1907
|
-
closed = true;
|
|
1908
|
-
} catch { /* already dead */ }
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
|
-
// Clear from registry and config
|
|
1912
|
-
meetingBrowsers.delete(agentId);
|
|
1913
|
-
delete (managed.config as any).meetingBrowserPort;
|
|
1914
|
-
delete (managed.config as any).meetingBrowserCdpUrl;
|
|
1915
|
-
managed.updatedAt = new Date().toISOString();
|
|
1916
|
-
try { await lifecycle.saveAgent(agentId); } catch (e) { console.warn('[meeting-browser] Config save failed (non-fatal):', e); }
|
|
1917
|
-
|
|
1918
|
-
return c.json({ ok: true, stopped: true, port });
|
|
1919
|
-
} catch (e: any) {
|
|
1920
|
-
return c.json({ error: 'Failed to stop meeting browser: ' + e.message }, 500);
|
|
1921
|
-
}
|
|
1922
|
-
});
|
|
1923
|
-
|
|
1924
|
-
router.post('/bridge/agents/:id/browser-config/test', async (c) => {
|
|
1925
|
-
const agentId = c.req.param('id');
|
|
1926
|
-
const managed = lifecycle.getAgent(agentId);
|
|
1927
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
1928
|
-
|
|
1929
|
-
const cfg = managed.config?.browserConfig || {};
|
|
1930
|
-
const provider = cfg.provider || 'local';
|
|
1931
|
-
|
|
1932
|
-
try {
|
|
1933
|
-
if (provider === 'local') {
|
|
1934
|
-
// Test local Chromium availability — auto-detect across platforms
|
|
1935
|
-
try {
|
|
1936
|
-
const { execSync } = await import('node:child_process');
|
|
1937
|
-
const { existsSync } = await import('node:fs');
|
|
1938
|
-
const { homedir } = await import('node:os');
|
|
1939
|
-
const { join } = await import('node:path');
|
|
1940
|
-
const candidates = [
|
|
1941
|
-
cfg.executablePath,
|
|
1942
|
-
process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH,
|
|
1943
|
-
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
1944
|
-
'/usr/bin/google-chrome', '/usr/bin/google-chrome-stable',
|
|
1945
|
-
'/usr/bin/chromium', '/usr/bin/chromium-browser', '/snap/bin/chromium',
|
|
1946
|
-
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
1947
|
-
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
|
|
1948
|
-
].filter(Boolean) as string[];
|
|
1949
|
-
let foundPath = '';
|
|
1950
|
-
for (const p of candidates) { if (existsSync(p)) { foundPath = p; break; } }
|
|
1951
|
-
// Also check Playwright bundled chromium
|
|
1952
|
-
if (!foundPath) {
|
|
1953
|
-
const pwCache = join(homedir(), '.cache', 'ms-playwright');
|
|
1954
|
-
if (existsSync(pwCache)) {
|
|
1955
|
-
const { readdirSync } = await import('node:fs');
|
|
1956
|
-
const dirs = readdirSync(pwCache).filter((d: string) => d.startsWith('chromium-')).sort().reverse();
|
|
1957
|
-
for (const d of dirs) {
|
|
1958
|
-
const linuxP = join(pwCache, d, 'chrome-linux', 'chrome');
|
|
1959
|
-
const macP = join(pwCache, d, 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium');
|
|
1960
|
-
if (existsSync(linuxP)) { foundPath = linuxP; break; }
|
|
1961
|
-
if (existsSync(macP)) { foundPath = macP; break; }
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
if (!foundPath) {
|
|
1966
|
-
return c.json({ error: 'No Chrome or Chromium found. Install Google Chrome or run: npx playwright install chromium' });
|
|
1967
|
-
}
|
|
1968
|
-
const version = execSync(`"${foundPath}" --version 2>/dev/null || echo "not found"`, { timeout: 5000 }).toString().trim();
|
|
1969
|
-
if (version.includes('not found')) {
|
|
1970
|
-
return c.json({ error: 'Chrome found at ' + foundPath + ' but --version failed' });
|
|
1971
|
-
}
|
|
1972
|
-
return c.json({ ok: true, browserVersion: version, provider: 'local', path: foundPath });
|
|
1973
|
-
} catch (e: any) {
|
|
1974
|
-
return c.json({ error: 'Chromium not available: ' + e.message });
|
|
1975
|
-
}
|
|
1976
|
-
}
|
|
1977
|
-
|
|
1978
|
-
if (provider === 'remote-cdp') {
|
|
1979
|
-
if (!cfg.cdpUrl) return c.json({ error: 'CDP URL not configured' });
|
|
1980
|
-
try {
|
|
1981
|
-
// Extract HTTP URL from WS URL to query /json/version
|
|
1982
|
-
const wsUrl = new URL(cfg.cdpUrl);
|
|
1983
|
-
const httpUrl = `http://${wsUrl.hostname}:${wsUrl.port}/json/version`;
|
|
1984
|
-
const resp = await fetch(httpUrl, { signal: AbortSignal.timeout(cfg.cdpTimeout || 10000) });
|
|
1985
|
-
if (!resp.ok) return c.json({ error: `CDP endpoint returned ${resp.status}` });
|
|
1986
|
-
const data = await resp.json() as any;
|
|
1987
|
-
return c.json({ ok: true, browserVersion: data.Browser || data['User-Agent'], webSocketUrl: data.webSocketDebuggerUrl, provider: 'remote-cdp' });
|
|
1988
|
-
} catch (e: any) {
|
|
1989
|
-
return c.json({ error: 'Cannot connect to CDP: ' + e.message });
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
1992
|
-
|
|
1993
|
-
if (provider === 'browserless') {
|
|
1994
|
-
if (!cfg.browserlessToken) return c.json({ error: 'Browserless API token not configured' });
|
|
1995
|
-
const endpoint = cfg.browserlessEndpoint || 'https://chrome.browserless.io';
|
|
1996
|
-
try {
|
|
1997
|
-
const resp = await fetch(`${endpoint}/config?token=${cfg.browserlessToken}`, { signal: AbortSignal.timeout(10000) });
|
|
1998
|
-
if (!resp.ok) return c.json({ error: `Browserless returned ${resp.status}` });
|
|
1999
|
-
const data = await resp.json() as any;
|
|
2000
|
-
return c.json({ ok: true, browserVersion: data.chrome?.version || 'Connected', provider: 'browserless', concurrent: data.concurrent });
|
|
2001
|
-
} catch (e: any) {
|
|
2002
|
-
return c.json({ error: 'Cannot connect to Browserless: ' + e.message });
|
|
2003
|
-
}
|
|
2004
|
-
}
|
|
2005
|
-
|
|
2006
|
-
if (provider === 'browserbase') {
|
|
2007
|
-
if (!cfg.browserbaseApiKey) return c.json({ error: 'Browserbase API key not configured' });
|
|
2008
|
-
try {
|
|
2009
|
-
const resp = await fetch('https://www.browserbase.com/v1/sessions', {
|
|
2010
|
-
method: 'POST',
|
|
2011
|
-
headers: { 'x-bb-api-key': cfg.browserbaseApiKey, 'Content-Type': 'application/json' },
|
|
2012
|
-
body: JSON.stringify({ projectId: cfg.browserbaseProjectId }),
|
|
2013
|
-
signal: AbortSignal.timeout(15000),
|
|
2014
|
-
});
|
|
2015
|
-
if (!resp.ok) return c.json({ error: `Browserbase returned ${resp.status}` });
|
|
2016
|
-
const data = await resp.json() as any;
|
|
2017
|
-
return c.json({ ok: true, browserVersion: 'Session created: ' + (data.id || 'OK'), provider: 'browserbase' });
|
|
2018
|
-
} catch (e: any) {
|
|
2019
|
-
return c.json({ error: 'Cannot connect to Browserbase: ' + e.message });
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
|
-
if (provider === 'steel') {
|
|
2024
|
-
if (!cfg.steelApiKey) return c.json({ error: 'Steel API key not configured' });
|
|
2025
|
-
const endpoint = cfg.steelEndpoint || 'https://api.steel.dev';
|
|
2026
|
-
try {
|
|
2027
|
-
const resp = await fetch(`${endpoint}/v1/sessions`, {
|
|
2028
|
-
method: 'POST',
|
|
2029
|
-
headers: { 'Authorization': `Bearer ${cfg.steelApiKey}`, 'Content-Type': 'application/json' },
|
|
2030
|
-
body: JSON.stringify({ timeout: 60 }),
|
|
2031
|
-
signal: AbortSignal.timeout(15000),
|
|
2032
|
-
});
|
|
2033
|
-
if (!resp.ok) return c.json({ error: `Steel returned ${resp.status}` });
|
|
2034
|
-
const data = await resp.json() as any;
|
|
2035
|
-
return c.json({ ok: true, browserVersion: 'Session: ' + (data.id || 'OK'), provider: 'steel' });
|
|
2036
|
-
} catch (e: any) {
|
|
2037
|
-
return c.json({ error: 'Cannot connect to Steel: ' + e.message });
|
|
2038
|
-
}
|
|
2039
|
-
}
|
|
2040
|
-
|
|
2041
|
-
if (provider === 'scrapingbee') {
|
|
2042
|
-
if (!cfg.scrapingbeeApiKey) return c.json({ error: 'ScrapingBee API key not configured' });
|
|
2043
|
-
try {
|
|
2044
|
-
const resp = await fetch(`https://app.scrapingbee.com/api/v1/usage?api_key=${cfg.scrapingbeeApiKey}`, {
|
|
2045
|
-
signal: AbortSignal.timeout(10000),
|
|
2046
|
-
});
|
|
2047
|
-
if (!resp.ok) return c.json({ error: `ScrapingBee returned ${resp.status}` });
|
|
2048
|
-
const data = await resp.json() as any;
|
|
2049
|
-
return c.json({ ok: true, provider: 'scrapingbee', creditsUsed: data.used_api_credit, creditsMax: data.max_api_credit });
|
|
2050
|
-
} catch (e: any) {
|
|
2051
|
-
return c.json({ error: 'Cannot connect to ScrapingBee: ' + e.message });
|
|
2052
|
-
}
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
|
-
return c.json({ ok: true, provider, note: 'Connection test not implemented for this provider' });
|
|
2056
|
-
} catch (e: any) {
|
|
2057
|
-
return c.json({ error: e.message });
|
|
2058
|
-
}
|
|
2059
|
-
});
|
|
2060
|
-
|
|
2061
|
-
router.put('/bridge/agents/:id/browser-config', async (c) => {
|
|
2062
|
-
const agentId = c.req.param('id');
|
|
2063
|
-
const managed = lifecycle.getAgent(agentId);
|
|
2064
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
2065
|
-
const body = await c.req.json();
|
|
2066
|
-
if (!managed.config) managed.config = {} as any;
|
|
2067
|
-
managed.config.browserConfig = body;
|
|
2068
|
-
managed.updatedAt = new Date().toISOString();
|
|
2069
|
-
await lifecycle.saveAgent(agentId);
|
|
2070
|
-
return c.json({ success: true });
|
|
2071
|
-
});
|
|
2072
|
-
|
|
2073
|
-
// ═══════════════════════════════════════════════════════════
|
|
2074
|
-
// TOOL RESTRICTIONS
|
|
2075
|
-
// ═══════════════════════════════════════════════════════════
|
|
2076
|
-
|
|
2077
|
-
router.get('/bridge/agents/:id/tool-restrictions', (c) => {
|
|
2078
|
-
const agentId = c.req.param('id');
|
|
2079
|
-
const managed = lifecycle.getAgent(agentId);
|
|
2080
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
2081
|
-
return c.json({ restrictions: managed.config?.toolRestrictions || {} });
|
|
2082
|
-
});
|
|
2083
|
-
|
|
2084
|
-
router.put('/bridge/agents/:id/tool-restrictions', async (c) => {
|
|
2085
|
-
const agentId = c.req.param('id');
|
|
2086
|
-
const managed = lifecycle.getAgent(agentId);
|
|
2087
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
2088
|
-
const body = await c.req.json();
|
|
2089
|
-
if (!managed.config) managed.config = {} as any;
|
|
2090
|
-
managed.config.toolRestrictions = body;
|
|
2091
|
-
|
|
2092
|
-
// Sync restrictions to permission profile
|
|
2093
|
-
const profile = permissions.getProfile(agentId);
|
|
2094
|
-
if (profile) {
|
|
2095
|
-
if (body.blockedTools) profile.tools = { ...profile.tools, blocked: body.blockedTools };
|
|
2096
|
-
if (body.maxRiskLevel) profile.maxRiskLevel = body.maxRiskLevel;
|
|
2097
|
-
if (body.blockedSideEffects) profile.blockedSideEffects = body.blockedSideEffects;
|
|
2098
|
-
if (body.requireApproval) profile.requireApproval = body.requireApproval;
|
|
2099
|
-
if (body.rateLimits) profile.rateLimits = body.rateLimits;
|
|
2100
|
-
if (body.constraints) profile.constraints = body.constraints;
|
|
2101
|
-
permissions.setProfile(agentId, profile, managed.orgId);
|
|
2102
|
-
}
|
|
2103
|
-
|
|
2104
|
-
managed.updatedAt = new Date().toISOString();
|
|
2105
|
-
await lifecycle.saveAgent(agentId);
|
|
2106
|
-
return c.json({ success: true });
|
|
2107
|
-
});
|
|
2108
|
-
|
|
2109
|
-
/**
|
|
2110
|
-
* GET /bridge/agents/:id/tools — List available tool categories with enabled/disabled status
|
|
2111
|
-
*/
|
|
2112
|
-
router.get('/bridge/agents/:id/tools', async (c) => {
|
|
2113
|
-
const agentId = c.req.param('id');
|
|
2114
|
-
const managed = lifecycle.getAgent(agentId);
|
|
2115
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
2116
|
-
|
|
2117
|
-
const os = await import('node:os');
|
|
2118
|
-
const serverPlatform = os.platform();
|
|
2119
|
-
const toolConfig = managed.config?.toolAccess || {};
|
|
2120
|
-
const emailConfig = managed.config?.emailConfig;
|
|
2121
|
-
const hasGoogleOAuth = emailConfig?.oauthProvider === 'google' && emailConfig?.oauthAccessToken;
|
|
2122
|
-
const hasMicrosoftOAuth = emailConfig?.oauthProvider === 'microsoft' && emailConfig?.oauthAccessToken;
|
|
2123
|
-
|
|
2124
|
-
const categories = TOOL_CATALOG.map((cat: any) => {
|
|
2125
|
-
// Platform check
|
|
2126
|
-
if (cat.requiresPlatform && cat.requiresPlatform !== serverPlatform) {
|
|
2127
|
-
return {
|
|
2128
|
-
id: cat.id, name: cat.name, description: cat.description, icon: cat.icon,
|
|
2129
|
-
toolCount: cat.tools.length, tools: cat.tools,
|
|
2130
|
-
enabled: false, isAvailable: false, alwaysOn: false,
|
|
2131
|
-
requiresOAuth: null, requiresIntegration: null,
|
|
2132
|
-
requiresPlatform: cat.requiresPlatform,
|
|
2133
|
-
platformUnavailable: true,
|
|
2134
|
-
platformMessage: 'Requires ' + cat.requiresPlatform,
|
|
2135
|
-
};
|
|
2136
|
-
}
|
|
2137
|
-
|
|
2138
|
-
const isAvailable = cat.requiresOAuth
|
|
2139
|
-
? (cat.requiresOAuth === 'google' && hasGoogleOAuth) || (cat.requiresOAuth === 'microsoft' && hasMicrosoftOAuth)
|
|
2140
|
-
: cat.requiresIntegration
|
|
2141
|
-
? true // Integration availability is checked at runtime via vault
|
|
2142
|
-
: true;
|
|
2143
|
-
|
|
2144
|
-
// Default: core is always on, others on if available
|
|
2145
|
-
const defaultEnabled = cat.alwaysOn || isAvailable;
|
|
2146
|
-
const enabled = cat.alwaysOn ? true : (toolConfig[cat.id] !== undefined ? toolConfig[cat.id] : defaultEnabled);
|
|
2147
|
-
|
|
2148
|
-
return {
|
|
2149
|
-
id: cat.id, name: cat.name, description: cat.description, icon: cat.icon,
|
|
2150
|
-
toolCount: cat.tools.length, tools: cat.tools,
|
|
2151
|
-
enabled, isAvailable, alwaysOn: cat.alwaysOn || false,
|
|
2152
|
-
requiresOAuth: cat.requiresOAuth || null,
|
|
2153
|
-
requiresIntegration: cat.requiresIntegration || null,
|
|
2154
|
-
};
|
|
2155
|
-
});
|
|
2156
|
-
|
|
2157
|
-
const totalTools = categories.reduce((s, c) => s + c.toolCount, 0);
|
|
2158
|
-
const enabledTools = categories.filter(c => c.enabled).reduce((s, c) => s + c.toolCount, 0);
|
|
2159
|
-
|
|
2160
|
-
return c.json({ categories, totalTools, enabledTools });
|
|
2161
|
-
});
|
|
2162
|
-
|
|
2163
|
-
/**
|
|
2164
|
-
* PUT /bridge/agents/:id/tools — Update tool access configuration
|
|
2165
|
-
* Body: { [categoryId]: boolean }
|
|
2166
|
-
*/
|
|
2167
|
-
router.put('/bridge/agents/:id/tools', async (c) => {
|
|
2168
|
-
const agentId = c.req.param('id');
|
|
2169
|
-
const managed = lifecycle.getAgent(agentId);
|
|
2170
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
2171
|
-
|
|
2172
|
-
const body = await c.req.json();
|
|
2173
|
-
if (!managed.config) managed.config = {} as any;
|
|
2174
|
-
if (!managed.config.toolAccess) managed.config.toolAccess = {};
|
|
2175
|
-
|
|
2176
|
-
for (const [catId, enabled] of Object.entries(body)) {
|
|
2177
|
-
// Don't allow disabling core tools
|
|
2178
|
-
const cat = TOOL_CATALOG.find(c => c.id === catId);
|
|
2179
|
-
if (cat?.alwaysOn) continue;
|
|
2180
|
-
managed.config.toolAccess[catId] = !!enabled;
|
|
2181
|
-
}
|
|
2182
|
-
|
|
2183
|
-
// Sync toolAccess categories → permission profile blocked/allowed tools
|
|
2184
|
-
const profile = permissions.getProfile(agentId);
|
|
2185
|
-
if (profile) {
|
|
2186
|
-
if (!profile.tools) profile.tools = { blocked: [], allowed: [] };
|
|
2187
|
-
const newBlocked = new Set(profile.tools.blocked || []);
|
|
2188
|
-
const newAllowed = new Set(profile.tools.allowed || []);
|
|
2189
|
-
for (const [catId, enabled] of Object.entries(managed.config.toolAccess)) {
|
|
2190
|
-
const cat = TOOL_CATALOG.find((c: any) => c.id === catId);
|
|
2191
|
-
if (!cat) continue;
|
|
2192
|
-
for (const toolId of cat.tools) {
|
|
2193
|
-
if (enabled) {
|
|
2194
|
-
newBlocked.delete(toolId);
|
|
2195
|
-
newAllowed.add(toolId);
|
|
2196
|
-
} else {
|
|
2197
|
-
newAllowed.delete(toolId);
|
|
2198
|
-
newBlocked.add(toolId);
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
}
|
|
2202
|
-
profile.tools.blocked = [...newBlocked];
|
|
2203
|
-
profile.tools.allowed = [...newAllowed];
|
|
2204
|
-
permissions.setProfile(agentId, profile, managed.orgId);
|
|
2205
|
-
}
|
|
2206
|
-
|
|
2207
|
-
managed.updatedAt = new Date().toISOString();
|
|
2208
|
-
await lifecycle.saveAgent(agentId);
|
|
2209
|
-
return c.json({ success: true, toolAccess: managed.config.toolAccess });
|
|
2210
|
-
});
|
|
2211
|
-
|
|
2212
|
-
// ─── Messaging Channels Config ──────────────────────
|
|
2213
|
-
|
|
2214
|
-
/**
|
|
2215
|
-
* PUT /bridge/agents/:id/config — Update agent config fields (messaging channels, etc.)
|
|
2216
|
-
*/
|
|
2217
|
-
router.put('/bridge/agents/:id/config', async (c) => {
|
|
2218
|
-
const agentId = c.req.param('id');
|
|
2219
|
-
const managed = lifecycle.getAgent(agentId);
|
|
2220
|
-
if (!managed) return c.json({ error: 'Agent not found' }, 404);
|
|
2221
|
-
const body = await c.req.json();
|
|
2222
|
-
// Merge into config
|
|
2223
|
-
if ((body as any).messagingChannels) {
|
|
2224
|
-
managed.config = managed.config || {} as any;
|
|
2225
|
-
(managed.config as any).messagingChannels = {
|
|
2226
|
-
...(((managed.config as any).messagingChannels) || {}),
|
|
2227
|
-
...(body as any).messagingChannels,
|
|
2228
|
-
};
|
|
2229
|
-
}
|
|
2230
|
-
// Merge any other config keys
|
|
2231
|
-
for (const key of Object.keys(body)) {
|
|
2232
|
-
if (key === 'messagingChannels') continue; // Already handled above
|
|
2233
|
-
(managed.config as any)[key] = body[key];
|
|
2234
|
-
}
|
|
2235
|
-
managed.updatedAt = new Date().toISOString();
|
|
2236
|
-
await lifecycle.saveAgent(agentId);
|
|
2237
|
-
|
|
2238
|
-
// Emit config change events so running services update in real-time
|
|
2239
|
-
for (const key of Object.keys(body)) {
|
|
2240
|
-
configBus.emitAgentConfig(agentId, key, body[key]);
|
|
2241
|
-
}
|
|
2242
|
-
return c.json({ success: true });
|
|
2243
|
-
});
|
|
2244
|
-
|
|
2245
|
-
/**
|
|
2246
|
-
* POST /bridge/agents/:id/whatsapp/connect — Start WhatsApp connection
|
|
2247
|
-
* Supports mode=business for separate business number connection
|
|
2248
|
-
*/
|
|
2249
|
-
router.post('/bridge/agents/:id/whatsapp/connect', async (c) => {
|
|
2250
|
-
const agentId = c.req.param('id');
|
|
2251
|
-
try {
|
|
2252
|
-
const body = await c.req.json().catch(() => ({}));
|
|
2253
|
-
const mode = body.mode || ''; // 'business' or ''
|
|
2254
|
-
const { createWhatsAppTools } = await import('../agent-tools/tools/messaging/whatsapp.js');
|
|
2255
|
-
const dataDir = process.env.DATA_DIR || '/tmp/agenticmail-data';
|
|
2256
|
-
const connId = mode === 'business' ? `biz-${agentId}` : agentId;
|
|
2257
|
-
const connDir = mode === 'business' ? `${dataDir}/agents/${agentId}/whatsapp-business` : `${dataDir}/agents/${agentId}/whatsapp`;
|
|
2258
|
-
const tools = createWhatsAppTools({ agentId: connId, dataDir: connDir });
|
|
2259
|
-
const connectTool = tools.find(t => t.name === 'whatsapp_connect');
|
|
2260
|
-
if (!connectTool) return c.json({ error: 'WhatsApp not available' }, 500);
|
|
2261
|
-
const result = await connectTool.execute!(connId, {});
|
|
2262
|
-
return c.json(result);
|
|
2263
|
-
} catch (err: any) {
|
|
2264
|
-
return c.json({ error: err.message }, 500);
|
|
2265
|
-
}
|
|
2266
|
-
});
|
|
2267
|
-
|
|
2268
|
-
/**
|
|
2269
|
-
* GET /bridge/agents/:id/whatsapp/status — Check WhatsApp status
|
|
2270
|
-
* Supports ?mode=business for business number status
|
|
2271
|
-
*/
|
|
2272
|
-
router.get('/bridge/agents/:id/whatsapp/status', async (c) => {
|
|
2273
|
-
const agentId = c.req.param('id');
|
|
2274
|
-
const mode = c.req.query('mode') || '';
|
|
2275
|
-
try {
|
|
2276
|
-
const { getConnectionStatus } = await import('../agent-tools/tools/messaging/whatsapp.js');
|
|
2277
|
-
const connId = mode === 'business' ? `biz-${agentId}` : agentId;
|
|
2278
|
-
return c.json(getConnectionStatus(connId));
|
|
2279
|
-
} catch {
|
|
2280
|
-
return c.json({ connected: false });
|
|
2281
|
-
}
|
|
2282
|
-
});
|
|
2283
|
-
|
|
2284
|
-
/**
|
|
2285
|
-
* POST /bridge/agents/:id/whatsapp/test — Send a test message
|
|
2286
|
-
* Supports mode in body for business number
|
|
2287
|
-
*/
|
|
2288
|
-
router.post('/bridge/agents/:id/whatsapp/test', async (c) => {
|
|
2289
|
-
const agentId = c.req.param('id');
|
|
2290
|
-
try {
|
|
2291
|
-
const body = await c.req.json().catch(() => ({}));
|
|
2292
|
-
const mode = body.mode || '';
|
|
2293
|
-
const connId = mode === 'business' ? `biz-${agentId}` : agentId;
|
|
2294
|
-
const { sendTestMessage } = await import('../agent-tools/tools/messaging/whatsapp.js');
|
|
2295
|
-
const result = await sendTestMessage(connId, body.to);
|
|
2296
|
-
return c.json(result);
|
|
2297
|
-
} catch (err: any) {
|
|
2298
|
-
return c.json({ ok: false, error: err.message }, 500);
|
|
2299
|
-
}
|
|
2300
|
-
});
|
|
2301
|
-
|
|
2302
|
-
/**
|
|
2303
|
-
* POST /bridge/agents/:id/whatsapp/proxy-send — Proxy send from standalone agent
|
|
2304
|
-
*/
|
|
2305
|
-
router.post('/bridge/agents/:id/whatsapp/proxy-send', async (c) => {
|
|
2306
|
-
const agentId = c.req.param('id');
|
|
2307
|
-
try {
|
|
2308
|
-
const body = await c.req.json();
|
|
2309
|
-
const { getConnection } = await import('../agent-tools/tools/messaging/whatsapp.js');
|
|
2310
|
-
const conn = getConnection(agentId);
|
|
2311
|
-
if (!conn?.connected) return c.json({ error: 'Not connected' }, 503);
|
|
2312
|
-
const toJid = (to: string) => to?.includes('@') ? to : (to || '').replace(/[^0-9]/g, '') + '@s.whatsapp.net';
|
|
2313
|
-
if (!body.to) return c.json({ error: 'Missing "to" field', received: body }, 400);
|
|
2314
|
-
const jid = toJid(body.to);
|
|
2315
|
-
if (body.action === 'presence') {
|
|
2316
|
-
await conn.sock.sendPresenceUpdate(body.type || 'composing', jid);
|
|
2317
|
-
return c.json({ ok: true });
|
|
2318
|
-
}
|
|
2319
|
-
// Show typing indicator before sending
|
|
2320
|
-
try { await conn.sock.sendPresenceUpdate('composing', jid); } catch {}
|
|
2321
|
-
const r = await conn.sock.sendMessage(jid, body.content || { text: body.text });
|
|
2322
|
-
try { await conn.sock.sendPresenceUpdate('paused', jid); } catch {}
|
|
2323
|
-
|
|
2324
|
-
// Store outbound message for conversation history
|
|
2325
|
-
if (body.text && opts.engineDb) {
|
|
2326
|
-
const { storeMessage } = await import('./messaging-history.js');
|
|
2327
|
-
const agentData = lifecycle.getAgent(agentId);
|
|
2328
|
-
storeMessage(opts.engineDb, {
|
|
2329
|
-
agentId,
|
|
2330
|
-
platform: 'whatsapp',
|
|
2331
|
-
contactId: body.to,
|
|
2332
|
-
direction: 'outbound',
|
|
2333
|
-
senderName: agentData?.display_name as any || agentData?.name || 'Agent',
|
|
2334
|
-
messageText: body.text,
|
|
2335
|
-
messageId: r?.key?.id,
|
|
2336
|
-
}).catch(() => {});
|
|
2337
|
-
}
|
|
2338
|
-
|
|
2339
|
-
return c.json({ ok: true, id: r?.key?.id });
|
|
2340
|
-
} catch (err: any) {
|
|
2341
|
-
console.error(`[wa-proxy] Error:`, err.message, err.stack?.split('\n')[1]);
|
|
2342
|
-
return c.json({ ok: false, error: err.message }, 500);
|
|
2343
|
-
}
|
|
2344
|
-
});
|
|
2345
|
-
|
|
2346
|
-
/**
|
|
2347
|
-
* POST /bridge/agents/:id/whatsapp/disconnect — Disconnect WhatsApp
|
|
2348
|
-
*/
|
|
2349
|
-
router.post('/bridge/agents/:id/whatsapp/disconnect', async (c) => {
|
|
2350
|
-
const agentId = c.req.param('id');
|
|
2351
|
-
try {
|
|
2352
|
-
const body = await c.req.json().catch(() => ({}));
|
|
2353
|
-
const mode = body.mode || '';
|
|
2354
|
-
const { createWhatsAppTools } = await import('../agent-tools/tools/messaging/whatsapp.js');
|
|
2355
|
-
const dataDir = process.env.DATA_DIR || '/tmp/agenticmail-data';
|
|
2356
|
-
const connId = mode === 'business' ? `biz-${agentId}` : agentId;
|
|
2357
|
-
const connDir = mode === 'business' ? `${dataDir}/agents/${agentId}/whatsapp-business` : `${dataDir}/agents/${agentId}/whatsapp`;
|
|
2358
|
-
const tools = createWhatsAppTools({ agentId: connId, dataDir: connDir });
|
|
2359
|
-
const disconnectTool = tools.find(t => t.name === 'whatsapp_disconnect');
|
|
2360
|
-
if (!disconnectTool) return c.json({ error: 'Not available' }, 500);
|
|
2361
|
-
const result = await disconnectTool.execute!(connId, body);
|
|
2362
|
-
return c.json(result);
|
|
2363
|
-
} catch (err: any) {
|
|
2364
|
-
return c.json({ error: err.message }, 500);
|
|
2365
|
-
}
|
|
2366
|
-
});
|
|
2367
|
-
|
|
2368
|
-
// ═══════════════════════════════════════════════
|
|
2369
|
-
// Telegram
|
|
2370
|
-
// ═══════════════════════════════════════════════
|
|
2371
|
-
|
|
2372
|
-
/**
|
|
2373
|
-
* POST /bridge/agents/:id/telegram/validate — Validate bot token via getMe
|
|
2374
|
-
*/
|
|
2375
|
-
router.post('/bridge/agents/:id/telegram/validate', async (c) => {
|
|
2376
|
-
try {
|
|
2377
|
-
const body = await c.req.json().catch(() => ({}));
|
|
2378
|
-
const token = body.botToken;
|
|
2379
|
-
if (!token) return c.json({ ok: false, error: 'Bot token required' }, 400);
|
|
2380
|
-
const resp = await fetch(`https://api.telegram.org/bot${token}/getMe`, { signal: AbortSignal.timeout(10000) });
|
|
2381
|
-
const data = await resp.json() as any;
|
|
2382
|
-
if (data.ok) {
|
|
2383
|
-
return c.json({ ok: true, bot: { id: data.result.id, username: data.result.username, firstName: data.result.first_name } });
|
|
2384
|
-
}
|
|
2385
|
-
return c.json({ ok: false, error: data.description || 'Invalid token' });
|
|
2386
|
-
} catch (err: any) {
|
|
2387
|
-
return c.json({ ok: false, error: err.message }, 500);
|
|
2388
|
-
}
|
|
2389
|
-
});
|
|
2390
|
-
|
|
2391
|
-
/**
|
|
2392
|
-
* POST /bridge/agents/:id/telegram/test — Send a test message to a chat ID
|
|
2393
|
-
*/
|
|
2394
|
-
router.post('/bridge/agents/:id/telegram/test', async (c) => {
|
|
2395
|
-
try {
|
|
2396
|
-
const agentId = c.req.param('id');
|
|
2397
|
-
const body = await c.req.json().catch(() => ({}));
|
|
2398
|
-
const chatId = body.chatId;
|
|
2399
|
-
// Get bot token from agent config
|
|
2400
|
-
const agent = lifecycle.getAgent(agentId);
|
|
2401
|
-
const channels = agent?.config?.messagingChannels as any || {};
|
|
2402
|
-
const tgConfig = channels.telegram || {};
|
|
2403
|
-
const token = tgConfig.botToken;
|
|
2404
|
-
if (!token) return c.json({ ok: false, error: 'No bot token configured' }, 400);
|
|
2405
|
-
if (!chatId) return c.json({ ok: false, error: 'Chat ID required' }, 400);
|
|
2406
|
-
const agentName = agent?.displayName || agent?.name || 'Agent';
|
|
2407
|
-
const resp = await fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
|
|
2408
|
-
method: 'POST',
|
|
2409
|
-
headers: { 'Content-Type': 'application/json' },
|
|
2410
|
-
body: JSON.stringify({ chat_id: chatId, text: `${Emoji.check} Test message from ${agentName}. Your Telegram connection is working!` }),
|
|
2411
|
-
signal: AbortSignal.timeout(10000),
|
|
2412
|
-
});
|
|
2413
|
-
const data = await resp.json() as any;
|
|
2414
|
-
if (data.ok) return c.json({ ok: true });
|
|
2415
|
-
return c.json({ ok: false, error: data.description || 'Send failed' });
|
|
2416
|
-
} catch (err: any) {
|
|
2417
|
-
return c.json({ ok: false, error: err.message }, 500);
|
|
2418
|
-
}
|
|
2419
|
-
});
|
|
2420
|
-
|
|
2421
|
-
// ═══════════════════════════════════════════════
|
|
2422
|
-
// WhatsApp Pairing System
|
|
2423
|
-
// ═══════════════════════════════════════════════
|
|
2424
|
-
|
|
2425
|
-
/**
|
|
2426
|
-
* GET /bridge/agents/:id/whatsapp/pairing-requests — List pending pairing requests
|
|
2427
|
-
*/
|
|
2428
|
-
router.get('/bridge/agents/:id/whatsapp/pairing-requests', async (c) => {
|
|
2429
|
-
const agentId = c.req.param('id');
|
|
2430
|
-
try {
|
|
2431
|
-
if (!opts.engineDb) return c.json({ requests: [] });
|
|
2432
|
-
const r = await opts.engineDb.query(
|
|
2433
|
-
`SELECT phone, name, code, created_at as timestamp FROM whatsapp_pairing_requests WHERE agent_id = $1 AND status = 'pending' ORDER BY created_at DESC`,
|
|
2434
|
-
[agentId]
|
|
2435
|
-
);
|
|
2436
|
-
return c.json({ requests: r.rows || [] });
|
|
2437
|
-
} catch {
|
|
2438
|
-
return c.json({ requests: [] });
|
|
2439
|
-
}
|
|
2440
|
-
});
|
|
2441
|
-
|
|
2442
|
-
/**
|
|
2443
|
-
* POST /bridge/agents/:id/whatsapp/pairing-approve — Approve a pairing request
|
|
2444
|
-
*/
|
|
2445
|
-
router.post('/bridge/agents/:id/whatsapp/pairing-approve', async (c) => {
|
|
2446
|
-
const agentId = c.req.param('id');
|
|
2447
|
-
const body = await c.req.json();
|
|
2448
|
-
try {
|
|
2449
|
-
if (!opts.engineDb) return c.json({ error: 'No database' }, 500);
|
|
2450
|
-
await opts.engineDb.query(
|
|
2451
|
-
`UPDATE whatsapp_pairing_requests SET status = 'approved' WHERE agent_id = $1 AND code = $2`,
|
|
2452
|
-
[agentId, body.code]
|
|
2453
|
-
);
|
|
2454
|
-
return c.json({ ok: true });
|
|
2455
|
-
} catch (err: any) {
|
|
2456
|
-
return c.json({ error: err.message }, 500);
|
|
2457
|
-
}
|
|
2458
|
-
});
|
|
2459
|
-
|
|
2460
|
-
/**
|
|
2461
|
-
* POST /bridge/agents/:id/whatsapp/pairing-reject — Reject a pairing request
|
|
2462
|
-
*/
|
|
2463
|
-
router.post('/bridge/agents/:id/whatsapp/pairing-reject', async (c) => {
|
|
2464
|
-
const agentId = c.req.param('id');
|
|
2465
|
-
const body = await c.req.json();
|
|
2466
|
-
try {
|
|
2467
|
-
if (!opts.engineDb) return c.json({ error: 'No database' }, 500);
|
|
2468
|
-
await opts.engineDb.query(
|
|
2469
|
-
`UPDATE whatsapp_pairing_requests SET status = 'rejected' WHERE agent_id = $1 AND code = $2`,
|
|
2470
|
-
[agentId, body.code]
|
|
2471
|
-
);
|
|
2472
|
-
return c.json({ ok: true });
|
|
2473
|
-
} catch (err: any) {
|
|
2474
|
-
return c.json({ error: err.message }, 500);
|
|
2475
|
-
}
|
|
2476
|
-
});
|
|
2477
|
-
|
|
2478
|
-
/**
|
|
2479
|
-
* GET /bridge/agents/:id/whatsapp/conversations — Conversation list with pagination, search, filters
|
|
2480
|
-
*/
|
|
2481
|
-
router.get('/bridge/agents/:id/whatsapp/conversations', async (c) => {
|
|
2482
|
-
const agentId = c.req.param('id');
|
|
2483
|
-
const limit = Math.min(parseInt(c.req.query('limit') || '20') || 20, 100);
|
|
2484
|
-
const offset = parseInt(c.req.query('offset') || '0') || 0;
|
|
2485
|
-
const search = (c.req.query('search') || '').trim();
|
|
2486
|
-
const direction = c.req.query('direction') || ''; // 'inbound' | 'outbound' | ''
|
|
2487
|
-
try {
|
|
2488
|
-
if (!opts.engineDb) return c.json({ conversations: [], total: 0 });
|
|
2489
|
-
|
|
2490
|
-
let whereExtra = '';
|
|
2491
|
-
const params: any[] = [agentId];
|
|
2492
|
-
let paramIdx = 2;
|
|
2493
|
-
if (search) {
|
|
2494
|
-
whereExtra += ` AND (sender_name ILIKE $${paramIdx} OR contact_id ILIKE $${paramIdx} OR message_text ILIKE $${paramIdx})`;
|
|
2495
|
-
params.push(`%${search}%`);
|
|
2496
|
-
paramIdx++;
|
|
2497
|
-
}
|
|
2498
|
-
if (direction) {
|
|
2499
|
-
whereExtra += ` AND direction = $${paramIdx}`;
|
|
2500
|
-
params.push(direction);
|
|
2501
|
-
paramIdx++;
|
|
2502
|
-
}
|
|
2503
|
-
|
|
2504
|
-
// Total count
|
|
2505
|
-
const countR = await opts.engineDb.query(
|
|
2506
|
-
`SELECT COUNT(DISTINCT contact_id) as total FROM messaging_history WHERE agent_id = $1 AND platform = 'whatsapp'${whereExtra}`,
|
|
2507
|
-
params
|
|
2508
|
-
);
|
|
2509
|
-
const total = parseInt(countR.rows?.[0]?.total || '0');
|
|
2510
|
-
|
|
2511
|
-
// Conversation summaries
|
|
2512
|
-
const r = await opts.engineDb.query(
|
|
2513
|
-
`SELECT contact_id as "contactId",
|
|
2514
|
-
MAX(sender_name) as name,
|
|
2515
|
-
COUNT(*) as "messageCount",
|
|
2516
|
-
COUNT(*) FILTER (WHERE direction = 'inbound') as "inboundCount",
|
|
2517
|
-
COUNT(*) FILTER (WHERE direction = 'outbound') as "outboundCount",
|
|
2518
|
-
MAX(created_at) as "lastAt",
|
|
2519
|
-
MIN(created_at) as "firstAt",
|
|
2520
|
-
(array_agg(message_text ORDER BY created_at DESC))[1] as "lastMessage",
|
|
2521
|
-
(array_agg(direction ORDER BY created_at DESC))[1] as "lastDirection"
|
|
2522
|
-
FROM messaging_history
|
|
2523
|
-
WHERE agent_id = $1 AND platform = 'whatsapp'${whereExtra}
|
|
2524
|
-
GROUP BY contact_id
|
|
2525
|
-
ORDER BY MAX(created_at) DESC
|
|
2526
|
-
LIMIT ${limit} OFFSET ${offset}`,
|
|
2527
|
-
params
|
|
2528
|
-
);
|
|
2529
|
-
|
|
2530
|
-
const agentData = lifecycle.getAgent(agentId);
|
|
2531
|
-
const waCfg = (agentData?.config as any)?.messagingChannels?.whatsapp || {};
|
|
2532
|
-
const trusted = waCfg.trustedContacts || [];
|
|
2533
|
-
const bizCustomers = waCfg.business?.approvedCustomers || [];
|
|
2534
|
-
const convos = (r.rows || []).map((row: any) => {
|
|
2535
|
-
const norm = (row.contactId || '').replace(/[^0-9]/g, '');
|
|
2536
|
-
return {
|
|
2537
|
-
...row,
|
|
2538
|
-
messageCount: parseInt(row.messageCount) || 0,
|
|
2539
|
-
inboundCount: parseInt(row.inboundCount) || 0,
|
|
2540
|
-
outboundCount: parseInt(row.outboundCount) || 0,
|
|
2541
|
-
isTrusted: trusted.some((t: string) => norm.includes(t.replace(/[^0-9]/g, ''))),
|
|
2542
|
-
isCustomer: bizCustomers.some((c: any) => norm.includes((c.phone || '').replace(/[^0-9]/g, ''))),
|
|
2543
|
-
};
|
|
2544
|
-
});
|
|
2545
|
-
return c.json({ conversations: convos, total, limit, offset });
|
|
2546
|
-
} catch {
|
|
2547
|
-
return c.json({ conversations: [], total: 0 });
|
|
2548
|
-
}
|
|
2549
|
-
});
|
|
2550
|
-
|
|
2551
|
-
/**
|
|
2552
|
-
* GET /bridge/agents/:id/whatsapp/conversations/:contactId — Full message history for a conversation
|
|
2553
|
-
*/
|
|
2554
|
-
router.get('/bridge/agents/:id/whatsapp/conversations/:contactId', async (c) => {
|
|
2555
|
-
const agentId = c.req.param('id');
|
|
2556
|
-
const contactId = decodeURIComponent(c.req.param('contactId'));
|
|
2557
|
-
const limit = Math.min(parseInt(c.req.query('limit') || '50') || 50, 200);
|
|
2558
|
-
const before = c.req.query('before') || ''; // ISO timestamp for older messages
|
|
2559
|
-
try {
|
|
2560
|
-
if (!opts.engineDb) return c.json({ messages: [] });
|
|
2561
|
-
let whereExtra = '';
|
|
2562
|
-
const params: any[] = [agentId, contactId];
|
|
2563
|
-
if (before) {
|
|
2564
|
-
whereExtra = ' AND created_at < $3';
|
|
2565
|
-
params.push(before);
|
|
2566
|
-
}
|
|
2567
|
-
const r = await opts.engineDb.query(
|
|
2568
|
-
`SELECT id, direction, sender_name as "senderName", message_text as text,
|
|
2569
|
-
message_id as "messageId", created_at as "timestamp"
|
|
2570
|
-
FROM messaging_history
|
|
2571
|
-
WHERE agent_id = $1 AND platform = 'whatsapp' AND contact_id = $2${whereExtra}
|
|
2572
|
-
ORDER BY created_at DESC
|
|
2573
|
-
LIMIT ${limit}`,
|
|
2574
|
-
params
|
|
2575
|
-
);
|
|
2576
|
-
return c.json({ messages: (r.rows || []).reverse() });
|
|
2577
|
-
} catch {
|
|
2578
|
-
return c.json({ messages: [] });
|
|
2579
|
-
}
|
|
2580
|
-
});
|
|
2581
|
-
|
|
2582
|
-
return router;
|
|
2583
|
-
}
|