@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
package/src/engine/lifecycle.ts
DELETED
|
@@ -1,1420 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Lifecycle Manager
|
|
3
|
-
*
|
|
4
|
-
* Manages the full lifecycle of an autonomous AI agent employee:
|
|
5
|
-
* create → configure → deploy → running → monitor → update → stop
|
|
6
|
-
*
|
|
7
|
-
* This is the core state machine. Every agent goes through these states
|
|
8
|
-
* and the manager handles transitions, health checks, auto-recovery,
|
|
9
|
-
* and status tracking.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import type { AgentConfig, DeploymentStatus } from './agent-config.js';
|
|
13
|
-
import { AgentConfigGenerator } from './agent-config.js';
|
|
14
|
-
import { DeploymentEngine } from './deployer.js';
|
|
15
|
-
import { PermissionEngine } from './skills.js';
|
|
16
|
-
import type { EngineDatabase } from './db-adapter.js';
|
|
17
|
-
import { withRetry } from '../lib/resilience.js';
|
|
18
|
-
import { configBus } from './config-bus.js';
|
|
19
|
-
|
|
20
|
-
// ─── Types ──────────────────────────────────────────────
|
|
21
|
-
|
|
22
|
-
export type AgentState =
|
|
23
|
-
| 'draft' // Created but not configured
|
|
24
|
-
| 'configuring' // Skills/permissions/identity being set up
|
|
25
|
-
| 'ready' // Fully configured, waiting for deploy
|
|
26
|
-
| 'provisioning' // Infrastructure being created
|
|
27
|
-
| 'deploying' // Code/config being pushed
|
|
28
|
-
| 'starting' // Container/process starting up
|
|
29
|
-
| 'running' // Active and healthy
|
|
30
|
-
| 'degraded' // Running but with issues
|
|
31
|
-
| 'stopped' // Intentionally stopped
|
|
32
|
-
| 'error' // Failed — needs attention
|
|
33
|
-
| 'updating' // Config/code update in progress
|
|
34
|
-
| 'destroying'; // Being torn down
|
|
35
|
-
|
|
36
|
-
export interface ManagedAgent {
|
|
37
|
-
id: string;
|
|
38
|
-
name?: string; // Display name (may differ from config.name)
|
|
39
|
-
displayName?: string; // Human-facing display name
|
|
40
|
-
display_name?: string; // Snake_case alias (DB compat)
|
|
41
|
-
orgId: string; // Which company owns this agent
|
|
42
|
-
org_id?: string; // Snake_case alias (DB compat)
|
|
43
|
-
client_org_id?: string; // Client org binding (if external)
|
|
44
|
-
config: AgentConfig;
|
|
45
|
-
state: AgentState;
|
|
46
|
-
permissionProfileId?: string; // Permission profile reference
|
|
47
|
-
stateHistory: StateTransition[];
|
|
48
|
-
health: AgentHealth;
|
|
49
|
-
usage: AgentUsage;
|
|
50
|
-
budgetConfig?: AgentBudgetConfig; // Per-agent budget controls
|
|
51
|
-
createdAt: string;
|
|
52
|
-
updatedAt: string;
|
|
53
|
-
lastDeployedAt?: string;
|
|
54
|
-
lastHealthCheckAt?: string;
|
|
55
|
-
version: number; // Config version for optimistic locking
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface StateTransition {
|
|
59
|
-
from: AgentState;
|
|
60
|
-
to: AgentState;
|
|
61
|
-
reason: string;
|
|
62
|
-
triggeredBy: string; // User ID or 'system'
|
|
63
|
-
timestamp: string;
|
|
64
|
-
error?: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface AgentHealth {
|
|
68
|
-
status: 'healthy' | 'degraded' | 'unhealthy' | 'unknown';
|
|
69
|
-
lastCheck: string;
|
|
70
|
-
uptime: number; // Seconds since last start
|
|
71
|
-
consecutiveFailures: number;
|
|
72
|
-
checks: HealthCheck[];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface HealthCheck {
|
|
76
|
-
name: string;
|
|
77
|
-
status: 'pass' | 'fail' | 'warn';
|
|
78
|
-
message?: string;
|
|
79
|
-
timestamp: string;
|
|
80
|
-
durationMs: number;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export interface AgentUsage {
|
|
84
|
-
// Token usage
|
|
85
|
-
tokensToday: number;
|
|
86
|
-
tokensThisWeek: number;
|
|
87
|
-
tokensThisMonth: number;
|
|
88
|
-
tokensThisYear: number;
|
|
89
|
-
tokenBudgetMonthly: number; // 0 = unlimited
|
|
90
|
-
|
|
91
|
-
// Tool calls
|
|
92
|
-
toolCallsToday: number;
|
|
93
|
-
toolCallsThisMonth: number;
|
|
94
|
-
|
|
95
|
-
// External actions (emails sent, messages, etc.)
|
|
96
|
-
externalActionsToday: number;
|
|
97
|
-
externalActionsThisMonth: number;
|
|
98
|
-
|
|
99
|
-
// Cost estimate (USD)
|
|
100
|
-
costToday: number;
|
|
101
|
-
costThisWeek: number;
|
|
102
|
-
costThisMonth: number;
|
|
103
|
-
costThisYear: number;
|
|
104
|
-
costBudgetMonthly: number; // 0 = unlimited
|
|
105
|
-
|
|
106
|
-
// Sessions
|
|
107
|
-
activeSessionCount: number;
|
|
108
|
-
totalSessionsToday: number;
|
|
109
|
-
|
|
110
|
-
// Errors
|
|
111
|
-
errorsToday: number;
|
|
112
|
-
errorRate1h: number; // Errors per hour in last hour
|
|
113
|
-
|
|
114
|
-
lastUpdated: string;
|
|
115
|
-
|
|
116
|
-
// Aliases used by runtime hooks
|
|
117
|
-
dailyCostUsd?: number;
|
|
118
|
-
monthlyCostUsd?: number;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// ─── Per-Agent Budget Controls ──────────────────────────
|
|
122
|
-
|
|
123
|
-
export interface AgentBudgetConfig {
|
|
124
|
-
dailyCostCap: number; // 0 = unlimited
|
|
125
|
-
monthlyCostCap: number; // 0 = unlimited (overrides costBudgetMonthly)
|
|
126
|
-
dailyTokenCap: number; // 0 = unlimited
|
|
127
|
-
monthlyTokenCap: number; // 0 = unlimited (overrides tokenBudgetMonthly)
|
|
128
|
-
weeklyCostCap: number; // 0 = unlimited
|
|
129
|
-
weeklyTokenCap: number; // 0 = unlimited
|
|
130
|
-
annualCostCap: number; // 0 = unlimited
|
|
131
|
-
annualTokenCap: number; // 0 = unlimited
|
|
132
|
-
warningThresholds: number[]; // e.g. [50, 80, 95] — emit alerts at these %
|
|
133
|
-
dailyLimitUsd?: number; // Alias for dailyCostCap
|
|
134
|
-
monthlyLimitUsd?: number; // Alias for monthlyCostCap
|
|
135
|
-
poolDelegation?: {
|
|
136
|
-
orgPoolPercent: number; // Max % of org budget this agent can use
|
|
137
|
-
maxDailyFromPool: number; // Daily cap from org pool
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export interface BudgetAlert {
|
|
142
|
-
id: string;
|
|
143
|
-
orgId: string;
|
|
144
|
-
agentId: string;
|
|
145
|
-
alertType: string; // 'warning_50' | 'warning_80' | 'warning_95' | 'exceeded' | 'daily_exceeded'
|
|
146
|
-
budgetType: 'cost' | 'tokens';
|
|
147
|
-
currentValue: number;
|
|
148
|
-
limitValue: number;
|
|
149
|
-
acknowledged: boolean;
|
|
150
|
-
createdAt: string;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export interface LifecycleEvent {
|
|
154
|
-
id: string;
|
|
155
|
-
agentId: string;
|
|
156
|
-
orgId: string;
|
|
157
|
-
type: LifecycleEventType;
|
|
158
|
-
data: Record<string, any>;
|
|
159
|
-
timestamp: string;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export type LifecycleEventType =
|
|
163
|
-
| 'created'
|
|
164
|
-
| 'configured'
|
|
165
|
-
| 'deployed'
|
|
166
|
-
| 'started'
|
|
167
|
-
| 'stopped'
|
|
168
|
-
| 'restarted'
|
|
169
|
-
| 'updated'
|
|
170
|
-
| 'error'
|
|
171
|
-
| 'health_check'
|
|
172
|
-
| 'auto_recovered'
|
|
173
|
-
| 'budget_warning'
|
|
174
|
-
| 'budget_exceeded'
|
|
175
|
-
| 'tool_call'
|
|
176
|
-
| 'approval_requested'
|
|
177
|
-
| 'approval_decided'
|
|
178
|
-
| 'destroyed'
|
|
179
|
-
| 'birthday'
|
|
180
|
-
| 'onboarding_required';
|
|
181
|
-
|
|
182
|
-
// ─── Lifecycle Manager ──────────────────────────────────
|
|
183
|
-
|
|
184
|
-
export class AgentLifecycleManager {
|
|
185
|
-
private agents = new Map<string, ManagedAgent>();
|
|
186
|
-
private healthCheckIntervals = new Map<string, NodeJS.Timeout>();
|
|
187
|
-
private deployer = new DeploymentEngine();
|
|
188
|
-
/** When true, this lifecycle runs on a standalone agent machine (not the enterprise server).
|
|
189
|
-
* In standalone mode, persistAgent reloads dashboard-managed fields from DB before saving. */
|
|
190
|
-
public standaloneMode = false;
|
|
191
|
-
private _configGen = new AgentConfigGenerator();
|
|
192
|
-
private permissions: PermissionEngine;
|
|
193
|
-
private engineDb?: EngineDatabase;
|
|
194
|
-
private eventListeners: ((event: LifecycleEvent) => void)[] = [];
|
|
195
|
-
private dirtyAgents = new Set<string>();
|
|
196
|
-
private flushTimer: NodeJS.Timeout | null = null;
|
|
197
|
-
/** Track which budget alert thresholds have already fired per agent per day to avoid duplicates */
|
|
198
|
-
private firedAlerts = new Map<string, Set<string>>();
|
|
199
|
-
private budgetAlerts: BudgetAlert[] = [];
|
|
200
|
-
private birthdayTimer: NodeJS.Timeout | null = null;
|
|
201
|
-
private lastBirthdayCheck: string = '';
|
|
202
|
-
private configRefreshTimer: NodeJS.Timeout | null = null;
|
|
203
|
-
/** External callback for sending birthday messages (set via setBirthdaySender) */
|
|
204
|
-
private birthdaySender: ((agent: ManagedAgent) => Promise<void>) | null = null;
|
|
205
|
-
/** Vault for decrypting deploy credentials */
|
|
206
|
-
private vault?: any;
|
|
207
|
-
|
|
208
|
-
constructor(opts?: { db?: EngineDatabase; permissions?: PermissionEngine }) {
|
|
209
|
-
this.engineDb = opts?.db;
|
|
210
|
-
this.permissions = opts?.permissions || new PermissionEngine();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Set the database adapter and load existing agents from DB
|
|
215
|
-
*/
|
|
216
|
-
async setDb(db: EngineDatabase): Promise<void> {
|
|
217
|
-
this.engineDb = db;
|
|
218
|
-
await this.loadFromDb();
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
setVault(vault: any): void {
|
|
222
|
-
this.vault = vault;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Load all agents from DB into memory
|
|
227
|
-
*/
|
|
228
|
-
async loadFromDb(): Promise<void> {
|
|
229
|
-
if (!this.engineDb) return;
|
|
230
|
-
try {
|
|
231
|
-
const agents = await this.engineDb.getAllManagedAgents();
|
|
232
|
-
for (const agent of agents) {
|
|
233
|
-
this.agents.set(agent.id, agent);
|
|
234
|
-
// Restart health check loops for running agents
|
|
235
|
-
if (agent.state === 'running' || agent.state === 'degraded') {
|
|
236
|
-
this.startHealthCheckLoop(agent);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
} catch {
|
|
240
|
-
// Table may not exist yet if migrations haven't run
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/** Load a single agent fresh from DB (bypasses in-memory cache) */
|
|
245
|
-
async loadAgentFromDb(agentId: string): Promise<any | null> {
|
|
246
|
-
if (!this.engineDb) return null;
|
|
247
|
-
return this.engineDb.getManagedAgent(agentId);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Refresh all agent configs from DB — picks up dashboard changes without restart.
|
|
252
|
-
* Merges DB config into in-memory state, preserving runtime-only fields (tokens, sessions).
|
|
253
|
-
*/
|
|
254
|
-
async refreshAgentConfigs(): Promise<void> {
|
|
255
|
-
if (!this.engineDb) return;
|
|
256
|
-
try {
|
|
257
|
-
const dbAgents = await this.engineDb.getAllManagedAgents();
|
|
258
|
-
for (const dbAgent of dbAgents) {
|
|
259
|
-
const mem = this.agents.get(dbAgent.id);
|
|
260
|
-
if (!mem) { this.agents.set(dbAgent.id, dbAgent); continue; }
|
|
261
|
-
|
|
262
|
-
// Merge dashboard-managed config fields from DB into memory
|
|
263
|
-
const dbCfg = (dbAgent.config || {}) as any;
|
|
264
|
-
const memCfg = (mem.config || {}) as any;
|
|
265
|
-
|
|
266
|
-
// These fields are owned by the dashboard — always take DB version
|
|
267
|
-
// This is exhaustive: every AgentConfig field that can be changed from the dashboard
|
|
268
|
-
const dashboardOwned = [
|
|
269
|
-
// Core identity & personal details
|
|
270
|
-
'identity', 'name', 'displayName', 'description',
|
|
271
|
-
// Model & runtime
|
|
272
|
-
'model', 'deployment',
|
|
273
|
-
// Communication
|
|
274
|
-
'messagingChannels', 'channels', 'email', 'emailConfig', 'managerEmail',
|
|
275
|
-
// Tools & permissions
|
|
276
|
-
'toolAccess', 'toolRestrictions', 'toolSecurity', 'permissionProfileId',
|
|
277
|
-
// Skills & services
|
|
278
|
-
'skills', 'enabledGoogleServices',
|
|
279
|
-
// Scheduling & behavior
|
|
280
|
-
'schedule', 'heartbeat', 'autonomy', 'catchUp', 'workHours', 'timezone',
|
|
281
|
-
// Voice & browser
|
|
282
|
-
'voiceConfig', 'browserConfig',
|
|
283
|
-
// Context & knowledge
|
|
284
|
-
'context', 'workspace',
|
|
285
|
-
// Budget (also in dedicated column)
|
|
286
|
-
'budget',
|
|
287
|
-
];
|
|
288
|
-
for (const key of dashboardOwned) {
|
|
289
|
-
if (dbCfg[key] !== undefined) {
|
|
290
|
-
memCfg[key] = dbCfg[key];
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// Update top-level agent fields (outside config blob)
|
|
295
|
-
mem.display_name = dbAgent.display_name || mem.display_name;
|
|
296
|
-
mem.name = dbAgent.name || mem.name;
|
|
297
|
-
if (dbAgent.budgetConfig) mem.budgetConfig = dbAgent.budgetConfig;
|
|
298
|
-
if ((dbAgent as any).client_org_id !== undefined) (mem as any).client_org_id = (dbAgent as any).client_org_id;
|
|
299
|
-
if ((dbAgent as any).org_id) mem.orgId = (dbAgent as any).org_id;
|
|
300
|
-
if ((dbAgent as any).permissionProfileId) mem.permissionProfileId = (dbAgent as any).permissionProfileId;
|
|
301
|
-
}
|
|
302
|
-
} catch (e: any) {
|
|
303
|
-
// Non-fatal — will retry on next interval
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Start periodic config refresh from DB (default: every 30s).
|
|
309
|
-
* Ensures dashboard changes take effect on running agents without restart.
|
|
310
|
-
*/
|
|
311
|
-
startConfigRefresh(intervalMs = 30_000): void {
|
|
312
|
-
if (this.configRefreshTimer) return;
|
|
313
|
-
this.configRefreshTimer = setInterval(() => {
|
|
314
|
-
this.refreshAgentConfigs().catch(() => {});
|
|
315
|
-
}, intervalMs);
|
|
316
|
-
if (this.configRefreshTimer?.unref) this.configRefreshTimer.unref();
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
stopConfigRefresh(): void {
|
|
320
|
-
if (this.configRefreshTimer) {
|
|
321
|
-
clearInterval(this.configRefreshTimer);
|
|
322
|
-
this.configRefreshTimer = null;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// ─── Agent CRUD ─────────────────────────────────────
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Create a new managed agent (starts in 'draft' state)
|
|
330
|
-
*/
|
|
331
|
-
async createAgent(orgId: string, config: AgentConfig, createdBy: string): Promise<ManagedAgent> {
|
|
332
|
-
const agent: ManagedAgent = {
|
|
333
|
-
id: config.id || crypto.randomUUID(),
|
|
334
|
-
orgId,
|
|
335
|
-
config,
|
|
336
|
-
state: 'draft',
|
|
337
|
-
stateHistory: [],
|
|
338
|
-
health: {
|
|
339
|
-
status: 'unknown',
|
|
340
|
-
lastCheck: new Date().toISOString(),
|
|
341
|
-
uptime: 0,
|
|
342
|
-
consecutiveFailures: 0,
|
|
343
|
-
checks: [],
|
|
344
|
-
},
|
|
345
|
-
usage: this.emptyUsage(),
|
|
346
|
-
createdAt: new Date().toISOString(),
|
|
347
|
-
updatedAt: new Date().toISOString(),
|
|
348
|
-
version: 1,
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
this.agents.set(agent.id, agent);
|
|
352
|
-
await this.persistAgent(agent);
|
|
353
|
-
this.emitEvent(agent, 'created', { createdBy });
|
|
354
|
-
|
|
355
|
-
return agent;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Update agent configuration (must be in draft, ready, stopped, or error state)
|
|
360
|
-
*/
|
|
361
|
-
async updateConfig(agentId: string, updates: Partial<AgentConfig>, updatedBy: string): Promise<ManagedAgent> {
|
|
362
|
-
const agent = this.getAgent(agentId);
|
|
363
|
-
if (!agent) throw new Error(`Agent ${agentId} not found`);
|
|
364
|
-
|
|
365
|
-
// Allow config updates in any state — config bus propagates changes to running agents
|
|
366
|
-
// Only block during transient states like 'deploying' or 'starting'
|
|
367
|
-
const blockedStates: AgentState[] = ['deploying', 'starting'];
|
|
368
|
-
if (blockedStates.includes(agent.state)) {
|
|
369
|
-
throw new Error(`Cannot update config while agent is ${agent.state}. Please wait.`);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// Deep-merge nested objects (identity, model, deployment) to prevent field loss
|
|
373
|
-
const merged: any = { ...agent.config, ...updates, updatedAt: new Date().toISOString() };
|
|
374
|
-
if (updates.identity && agent.config.identity) {
|
|
375
|
-
merged.identity = { ...agent.config.identity, ...updates.identity };
|
|
376
|
-
}
|
|
377
|
-
if (updates.model && agent.config.model) {
|
|
378
|
-
merged.model = { ...agent.config.model, ...updates.model };
|
|
379
|
-
}
|
|
380
|
-
if (updates.deployment && agent.config.deployment) {
|
|
381
|
-
merged.deployment = { ...agent.config.deployment, ...updates.deployment };
|
|
382
|
-
}
|
|
383
|
-
agent.config = merged;
|
|
384
|
-
agent.updatedAt = new Date().toISOString();
|
|
385
|
-
agent.version++;
|
|
386
|
-
|
|
387
|
-
// If all required fields are set, transition to 'ready'
|
|
388
|
-
if (agent.state === 'draft' && this.isConfigComplete(agent.config)) {
|
|
389
|
-
this.transition(agent, 'ready', 'Configuration complete', updatedBy);
|
|
390
|
-
} else if (agent.state !== 'draft') {
|
|
391
|
-
this.transition(agent, 'ready', 'Configuration updated', updatedBy);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
await this.persistAgent(agent);
|
|
395
|
-
this.emitEvent(agent, 'configured', { updatedBy, changes: Object.keys(updates) });
|
|
396
|
-
|
|
397
|
-
return agent;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Deploy an agent to its target environment
|
|
402
|
-
*/
|
|
403
|
-
async deploy(agentId: string, deployedBy: string): Promise<ManagedAgent> {
|
|
404
|
-
const agent = this.getAgent(agentId);
|
|
405
|
-
if (!agent) throw new Error(`Agent ${agentId} not found`);
|
|
406
|
-
|
|
407
|
-
if (!['ready', 'stopped', 'error'].includes(agent.state)) {
|
|
408
|
-
throw new Error(`Cannot deploy from state "${agent.state}"`);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
if (!this.isConfigComplete(agent.config)) {
|
|
412
|
-
throw new Error('Agent configuration is incomplete');
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// Transition: provisioning
|
|
416
|
-
this.transition(agent, 'provisioning', 'Deployment initiated', deployedBy);
|
|
417
|
-
await this.persistAgent(agent);
|
|
418
|
-
|
|
419
|
-
try {
|
|
420
|
-
// Resolve org-level deploy credentials if agent doesn't have its own
|
|
421
|
-
await this.resolveDeployCredentials(agent);
|
|
422
|
-
|
|
423
|
-
// Run deployment
|
|
424
|
-
this.transition(agent, 'deploying', 'Pushing configuration', 'system');
|
|
425
|
-
|
|
426
|
-
const result = await this.deployer.deploy(agent.config, (event) => {
|
|
427
|
-
this.emitEvent(agent, 'deployed', { phase: event.phase, status: event.status, message: event.message });
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
if (result.success) {
|
|
431
|
-
this.transition(agent, 'starting', 'Deployment successful, agent starting', 'system');
|
|
432
|
-
agent.lastDeployedAt = new Date().toISOString();
|
|
433
|
-
|
|
434
|
-
// Wait for agent to be healthy
|
|
435
|
-
const healthy = await this.waitForHealthy(agent, 60_000);
|
|
436
|
-
if (healthy) {
|
|
437
|
-
this.transition(agent, 'running', 'Agent is healthy and running', 'system');
|
|
438
|
-
this.emitEvent(agent, 'started', { deployedBy });
|
|
439
|
-
this.emitEvent(agent, 'onboarding_required', { message: 'Agent should complete onboarding: read org policies, acknowledge each, and internalize knowledge.' });
|
|
440
|
-
this.startHealthCheckLoop(agent);
|
|
441
|
-
} else {
|
|
442
|
-
this.transition(agent, 'degraded', 'Agent started but health check failed', 'system');
|
|
443
|
-
this.startHealthCheckLoop(agent);
|
|
444
|
-
}
|
|
445
|
-
} else {
|
|
446
|
-
this.transition(agent, 'error', `Deployment failed: ${result.error}`, 'system');
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
await this.persistAgent(agent);
|
|
450
|
-
return agent;
|
|
451
|
-
|
|
452
|
-
} catch (error: any) {
|
|
453
|
-
this.transition(agent, 'error', `Deployment error: ${error.message}`, 'system');
|
|
454
|
-
await this.persistAgent(agent);
|
|
455
|
-
throw error;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* Stop a running agent
|
|
461
|
-
*/
|
|
462
|
-
async stop(agentId: string, stoppedBy: string, reason?: string): Promise<ManagedAgent> {
|
|
463
|
-
const agent = this.getAgent(agentId);
|
|
464
|
-
if (!agent) throw new Error(`Agent ${agentId} not found`);
|
|
465
|
-
|
|
466
|
-
if (!['running', 'degraded', 'starting', 'error'].includes(agent.state)) {
|
|
467
|
-
throw new Error(`Cannot stop from state "${agent.state}"`);
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
this.stopHealthCheckLoop(agentId);
|
|
471
|
-
|
|
472
|
-
try {
|
|
473
|
-
await this.deployer.stop(agent.config);
|
|
474
|
-
this.transition(agent, 'stopped', reason || 'Stopped by user', stoppedBy);
|
|
475
|
-
} catch (error: any) {
|
|
476
|
-
this.transition(agent, 'stopped', `Stopped with error: ${error.message}`, stoppedBy);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
await this.persistAgent(agent);
|
|
480
|
-
this.emitEvent(agent, 'stopped', { stoppedBy, reason });
|
|
481
|
-
return agent;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* Restart a running agent
|
|
486
|
-
*/
|
|
487
|
-
async restart(agentId: string, restartedBy: string): Promise<ManagedAgent> {
|
|
488
|
-
const agent = this.getAgent(agentId);
|
|
489
|
-
if (!agent) throw new Error(`Agent ${agentId} not found`);
|
|
490
|
-
|
|
491
|
-
this.transition(agent, 'updating', 'Restarting', restartedBy);
|
|
492
|
-
|
|
493
|
-
try {
|
|
494
|
-
await this.deployer.restart(agent.config);
|
|
495
|
-
const healthy = await this.waitForHealthy(agent, 30_000);
|
|
496
|
-
this.transition(agent, healthy ? 'running' : 'degraded', 'Restarted', 'system');
|
|
497
|
-
} catch (error: any) {
|
|
498
|
-
this.transition(agent, 'error', `Restart failed: ${error.message}`, 'system');
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
await this.persistAgent(agent);
|
|
502
|
-
this.emitEvent(agent, 'restarted', { restartedBy });
|
|
503
|
-
return agent;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* Hot-update config on a running agent (no full redeploy)
|
|
508
|
-
*/
|
|
509
|
-
async hotUpdate(agentId: string, updates: Partial<AgentConfig>, updatedBy: string): Promise<ManagedAgent> {
|
|
510
|
-
const agent = this.getAgent(agentId);
|
|
511
|
-
if (!agent) throw new Error(`Agent ${agentId} not found`);
|
|
512
|
-
|
|
513
|
-
if (agent.state !== 'running' && agent.state !== 'degraded') {
|
|
514
|
-
throw new Error(`Hot update only works on running agents (current: "${agent.state}")`);
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
const prevState = agent.state;
|
|
518
|
-
this.transition(agent, 'updating', 'Hot config update', updatedBy);
|
|
519
|
-
|
|
520
|
-
// Deep-merge nested objects (identity, model, deployment) to prevent field loss
|
|
521
|
-
const merged: any = { ...agent.config, ...updates, updatedAt: new Date().toISOString() };
|
|
522
|
-
if (updates.identity && agent.config.identity) {
|
|
523
|
-
merged.identity = { ...agent.config.identity, ...updates.identity };
|
|
524
|
-
}
|
|
525
|
-
if (updates.model && agent.config.model) {
|
|
526
|
-
merged.model = { ...agent.config.model, ...updates.model };
|
|
527
|
-
}
|
|
528
|
-
if (updates.deployment && agent.config.deployment) {
|
|
529
|
-
merged.deployment = { ...agent.config.deployment, ...updates.deployment };
|
|
530
|
-
}
|
|
531
|
-
agent.config = merged;
|
|
532
|
-
agent.version++;
|
|
533
|
-
|
|
534
|
-
try {
|
|
535
|
-
await this.deployer.updateConfig(agent.config);
|
|
536
|
-
this.transition(agent, prevState, 'Config updated successfully', 'system');
|
|
537
|
-
} catch (error: any) {
|
|
538
|
-
this.transition(agent, 'degraded', `Config update failed: ${error.message}`, 'system');
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
await this.persistAgent(agent);
|
|
542
|
-
this.emitEvent(agent, 'updated', { updatedBy, hotUpdate: true });
|
|
543
|
-
return agent;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* Destroy an agent completely (stop + delete all resources)
|
|
548
|
-
*/
|
|
549
|
-
async destroy(agentId: string, destroyedBy: string): Promise<void> {
|
|
550
|
-
const agent = this.getAgent(agentId);
|
|
551
|
-
if (!agent) throw new Error(`Agent ${agentId} not found`);
|
|
552
|
-
|
|
553
|
-
this.transition(agent, 'destroying', 'Agent being destroyed', destroyedBy);
|
|
554
|
-
this.stopHealthCheckLoop(agentId);
|
|
555
|
-
|
|
556
|
-
// Stop if running
|
|
557
|
-
if (['running', 'degraded', 'starting'].includes(agent.state)) {
|
|
558
|
-
try { await this.deployer.stop(agent.config); } catch { /* best effort */ }
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
this.emitEvent(agent, 'destroyed', { destroyedBy });
|
|
562
|
-
this.agents.delete(agentId);
|
|
563
|
-
try {
|
|
564
|
-
await this.engineDb?.deleteManagedAgent(agentId);
|
|
565
|
-
} catch (err) {
|
|
566
|
-
console.error(`[lifecycle] Failed to delete agent ${agentId} from DB:`, err);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// ─── Monitoring ─────────────────────────────────────
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* Record LLM usage (tokens + cost) from an agent session turn.
|
|
574
|
-
*/
|
|
575
|
-
recordLLMUsage(agentId: string, opts: {
|
|
576
|
-
inputTokens?: number;
|
|
577
|
-
outputTokens?: number;
|
|
578
|
-
costUsd?: number;
|
|
579
|
-
}) {
|
|
580
|
-
const agent = this.agents.get(agentId);
|
|
581
|
-
if (!agent) {
|
|
582
|
-
console.log(`[lifecycle] recordLLMUsage: agent ${agentId} not found (have ${this.agents.size} agents: ${[...this.agents.keys()].join(', ')})`);
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
|
-
console.log(`[lifecycle] recordLLMUsage: agent=${agentId}, input=${opts.inputTokens}, output=${opts.outputTokens}, cost=${opts.costUsd}`);
|
|
586
|
-
|
|
587
|
-
const totalTokens = (opts.inputTokens || 0) + (opts.outputTokens || 0);
|
|
588
|
-
const usage = agent.usage;
|
|
589
|
-
if (totalTokens > 0) {
|
|
590
|
-
usage.tokensToday += totalTokens;
|
|
591
|
-
usage.tokensThisWeek += totalTokens;
|
|
592
|
-
usage.tokensThisMonth += totalTokens;
|
|
593
|
-
usage.tokensThisYear += totalTokens;
|
|
594
|
-
}
|
|
595
|
-
if (opts.costUsd) {
|
|
596
|
-
usage.costToday += opts.costUsd;
|
|
597
|
-
usage.costThisWeek += opts.costUsd;
|
|
598
|
-
usage.costThisMonth += opts.costUsd;
|
|
599
|
-
usage.costThisYear += opts.costUsd;
|
|
600
|
-
}
|
|
601
|
-
usage.lastUpdated = new Date().toISOString();
|
|
602
|
-
|
|
603
|
-
// Persist usage directly to DB (just the usage column, not the whole agent)
|
|
604
|
-
if (this.engineDb) {
|
|
605
|
-
this.engineDb.execute(
|
|
606
|
-
`UPDATE managed_agents SET usage = $1, updated_at = $2 WHERE id = $3`,
|
|
607
|
-
[JSON.stringify(usage), new Date().toISOString(), agentId]
|
|
608
|
-
).catch(() => {});
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
// Check budget caps
|
|
612
|
-
const budget = agent.budgetConfig;
|
|
613
|
-
if (budget) {
|
|
614
|
-
if (budget.dailyCostCap > 0 && usage.costToday >= budget.dailyCostCap) {
|
|
615
|
-
this.fireBudgetAlert(agent, 'daily_exceeded', 'cost', usage.costToday, budget.dailyCostCap);
|
|
616
|
-
this.stop(agentId, 'system', 'Daily cost budget exceeded').catch(() => {});
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
/**
|
|
622
|
-
* Record a tool call for usage tracking with per-agent budget controls
|
|
623
|
-
*/
|
|
624
|
-
recordToolCall(agentId: string, toolIdOrOpts: string | { toolId: string; tokensUsed?: number; costUsd?: number; isExternalAction?: boolean; error?: boolean }, opts?: {
|
|
625
|
-
tokensUsed?: number;
|
|
626
|
-
costUsd?: number;
|
|
627
|
-
isExternalAction?: boolean;
|
|
628
|
-
error?: boolean;
|
|
629
|
-
}) {
|
|
630
|
-
if (typeof toolIdOrOpts === 'object') {
|
|
631
|
-
opts = toolIdOrOpts;
|
|
632
|
-
}
|
|
633
|
-
const toolId = typeof toolIdOrOpts === 'string' ? toolIdOrOpts : toolIdOrOpts.toolId;
|
|
634
|
-
const agent = this.agents.get(agentId);
|
|
635
|
-
if (!agent) return;
|
|
636
|
-
|
|
637
|
-
const usage = agent.usage;
|
|
638
|
-
usage.toolCallsToday++;
|
|
639
|
-
usage.toolCallsThisMonth++;
|
|
640
|
-
if (opts?.tokensUsed) {
|
|
641
|
-
usage.tokensToday += opts.tokensUsed;
|
|
642
|
-
usage.tokensThisWeek += opts.tokensUsed;
|
|
643
|
-
usage.tokensThisMonth += opts.tokensUsed;
|
|
644
|
-
usage.tokensThisYear += opts.tokensUsed;
|
|
645
|
-
}
|
|
646
|
-
if (opts?.costUsd) {
|
|
647
|
-
usage.costToday += opts.costUsd;
|
|
648
|
-
usage.costThisWeek += opts.costUsd;
|
|
649
|
-
usage.costThisMonth += opts.costUsd;
|
|
650
|
-
usage.costThisYear += opts.costUsd;
|
|
651
|
-
}
|
|
652
|
-
if (opts?.isExternalAction) {
|
|
653
|
-
usage.externalActionsToday++;
|
|
654
|
-
usage.externalActionsThisMonth++;
|
|
655
|
-
}
|
|
656
|
-
if (opts?.error) {
|
|
657
|
-
usage.errorsToday++;
|
|
658
|
-
}
|
|
659
|
-
usage.lastUpdated = new Date().toISOString();
|
|
660
|
-
|
|
661
|
-
// ─── Per-Agent Budget Controls ─────────────────────
|
|
662
|
-
const budget = agent.budgetConfig;
|
|
663
|
-
if (budget) {
|
|
664
|
-
// Daily cost cap
|
|
665
|
-
if (budget.dailyCostCap > 0 && usage.costToday >= budget.dailyCostCap) {
|
|
666
|
-
this.fireBudgetAlert(agent, 'daily_exceeded', 'cost', usage.costToday, budget.dailyCostCap);
|
|
667
|
-
this.stop(agentId, 'system', 'Daily cost budget exceeded').catch(() => {});
|
|
668
|
-
}
|
|
669
|
-
// Monthly cost cap
|
|
670
|
-
if (budget.monthlyCostCap > 0 && usage.costThisMonth >= budget.monthlyCostCap) {
|
|
671
|
-
this.fireBudgetAlert(agent, 'exceeded', 'cost', usage.costThisMonth, budget.monthlyCostCap);
|
|
672
|
-
this.stop(agentId, 'system', 'Monthly cost budget exceeded').catch(() => {});
|
|
673
|
-
}
|
|
674
|
-
// Daily token cap
|
|
675
|
-
if (budget.dailyTokenCap > 0 && usage.tokensToday >= budget.dailyTokenCap) {
|
|
676
|
-
this.fireBudgetAlert(agent, 'daily_exceeded', 'tokens', usage.tokensToday, budget.dailyTokenCap);
|
|
677
|
-
this.stop(agentId, 'system', 'Daily token budget exceeded').catch(() => {});
|
|
678
|
-
}
|
|
679
|
-
// Monthly token cap
|
|
680
|
-
if (budget.monthlyTokenCap > 0 && usage.tokensThisMonth >= budget.monthlyTokenCap) {
|
|
681
|
-
this.fireBudgetAlert(agent, 'exceeded', 'tokens', usage.tokensThisMonth, budget.monthlyTokenCap);
|
|
682
|
-
this.stop(agentId, 'system', 'Monthly token budget exceeded').catch(() => {});
|
|
683
|
-
}
|
|
684
|
-
// Weekly cost cap
|
|
685
|
-
if (budget.weeklyCostCap > 0 && usage.costThisWeek >= budget.weeklyCostCap) {
|
|
686
|
-
this.fireBudgetAlert(agent, 'weekly_exceeded', 'cost', usage.costThisWeek, budget.weeklyCostCap);
|
|
687
|
-
this.stop(agentId, 'system', 'Weekly cost budget exceeded').catch(() => {});
|
|
688
|
-
}
|
|
689
|
-
// Weekly token cap
|
|
690
|
-
if (budget.weeklyTokenCap > 0 && usage.tokensThisWeek >= budget.weeklyTokenCap) {
|
|
691
|
-
this.fireBudgetAlert(agent, 'weekly_exceeded', 'tokens', usage.tokensThisWeek, budget.weeklyTokenCap);
|
|
692
|
-
this.stop(agentId, 'system', 'Weekly token budget exceeded').catch(() => {});
|
|
693
|
-
}
|
|
694
|
-
// Annual cost cap
|
|
695
|
-
if (budget.annualCostCap > 0 && usage.costThisYear >= budget.annualCostCap) {
|
|
696
|
-
this.fireBudgetAlert(agent, 'annual_exceeded', 'cost', usage.costThisYear, budget.annualCostCap);
|
|
697
|
-
this.stop(agentId, 'system', 'Annual cost budget exceeded').catch(() => {});
|
|
698
|
-
}
|
|
699
|
-
// Annual token cap
|
|
700
|
-
if (budget.annualTokenCap > 0 && usage.tokensThisYear >= budget.annualTokenCap) {
|
|
701
|
-
this.fireBudgetAlert(agent, 'annual_exceeded', 'tokens', usage.tokensThisYear, budget.annualTokenCap);
|
|
702
|
-
this.stop(agentId, 'system', 'Annual token budget exceeded').catch(() => {});
|
|
703
|
-
}
|
|
704
|
-
// Warning thresholds
|
|
705
|
-
const thresholds = budget.warningThresholds || [50, 80, 95];
|
|
706
|
-
for (const pct of thresholds) {
|
|
707
|
-
if (budget.monthlyCostCap > 0) {
|
|
708
|
-
const ratio = usage.costThisMonth / budget.monthlyCostCap * 100;
|
|
709
|
-
if (ratio >= pct) {
|
|
710
|
-
this.fireBudgetAlert(agent, `warning_${pct}`, 'cost', usage.costThisMonth, budget.monthlyCostCap);
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
if (budget.monthlyTokenCap > 0) {
|
|
714
|
-
const ratio = usage.tokensThisMonth / budget.monthlyTokenCap * 100;
|
|
715
|
-
if (ratio >= pct) {
|
|
716
|
-
this.fireBudgetAlert(agent, `warning_${pct}`, 'tokens', usage.tokensThisMonth, budget.monthlyTokenCap);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
if (budget.weeklyCostCap > 0) {
|
|
720
|
-
const ratio = usage.costThisWeek / budget.weeklyCostCap * 100;
|
|
721
|
-
if (ratio >= pct) {
|
|
722
|
-
this.fireBudgetAlert(agent, `weekly_warning_${pct}`, 'cost', usage.costThisWeek, budget.weeklyCostCap);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
if (budget.weeklyTokenCap > 0) {
|
|
726
|
-
const ratio = usage.tokensThisWeek / budget.weeklyTokenCap * 100;
|
|
727
|
-
if (ratio >= pct) {
|
|
728
|
-
this.fireBudgetAlert(agent, `weekly_warning_${pct}`, 'tokens', usage.tokensThisWeek, budget.weeklyTokenCap);
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
if (budget.annualCostCap > 0) {
|
|
732
|
-
const ratio = usage.costThisYear / budget.annualCostCap * 100;
|
|
733
|
-
if (ratio >= pct) {
|
|
734
|
-
this.fireBudgetAlert(agent, `annual_warning_${pct}`, 'cost', usage.costThisYear, budget.annualCostCap);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
if (budget.annualTokenCap > 0) {
|
|
738
|
-
const ratio = usage.tokensThisYear / budget.annualTokenCap * 100;
|
|
739
|
-
if (ratio >= pct) {
|
|
740
|
-
this.fireBudgetAlert(agent, `annual_warning_${pct}`, 'tokens', usage.tokensThisYear, budget.annualTokenCap);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
} else {
|
|
745
|
-
// Legacy budget checks (from AgentUsage fields)
|
|
746
|
-
if (usage.tokenBudgetMonthly > 0 && usage.tokensThisMonth >= usage.tokenBudgetMonthly) {
|
|
747
|
-
this.emitEvent(agent, 'budget_exceeded', { type: 'tokens', used: usage.tokensThisMonth, budget: usage.tokenBudgetMonthly });
|
|
748
|
-
this.stop(agentId, 'system', 'Monthly token budget exceeded').catch(() => {});
|
|
749
|
-
} else if (usage.tokenBudgetMonthly > 0 && usage.tokensThisMonth >= usage.tokenBudgetMonthly * 0.8) {
|
|
750
|
-
this.emitEvent(agent, 'budget_warning', { type: 'tokens', used: usage.tokensThisMonth, budget: usage.tokenBudgetMonthly, percent: 80 });
|
|
751
|
-
}
|
|
752
|
-
if (usage.costBudgetMonthly > 0 && usage.costThisMonth >= usage.costBudgetMonthly) {
|
|
753
|
-
this.emitEvent(agent, 'budget_exceeded', { type: 'cost', used: usage.costThisMonth, budget: usage.costBudgetMonthly });
|
|
754
|
-
this.stop(agentId, 'system', 'Monthly cost budget exceeded').catch(() => {});
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
this.emitEvent(agent, 'tool_call', { toolId, ...opts });
|
|
759
|
-
|
|
760
|
-
// Mark agent dirty for debounced usage flush
|
|
761
|
-
this.dirtyAgents.add(agentId);
|
|
762
|
-
this.scheduleUsageFlush();
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
/**
|
|
766
|
-
* Get all agents for an org
|
|
767
|
-
*/
|
|
768
|
-
getAgentsByOrg(orgId: string): ManagedAgent[] {
|
|
769
|
-
return Array.from(this.agents.values()).filter(a => a.orgId === orgId);
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
/** Get all agents across all orgs */
|
|
773
|
-
getAllAgents(): ManagedAgent[] {
|
|
774
|
-
return Array.from(this.agents.values());
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
/**
|
|
778
|
-
* Get standalone agent processes (for chat webhook routing).
|
|
779
|
-
* Reads from agent deployment config — no hardcoded IDs.
|
|
780
|
-
*/
|
|
781
|
-
getStandaloneAgents(): { id: string; port: number; host?: string }[] {
|
|
782
|
-
const result: { id: string; port: number; host?: string }[] = [];
|
|
783
|
-
for (const agent of this.agents.values()) {
|
|
784
|
-
const dep = agent.config?.deployment;
|
|
785
|
-
// Check deployment.port (top-level) or deployment.config.local.port
|
|
786
|
-
const port = dep?.port || dep?.config?.local?.port;
|
|
787
|
-
if (port) {
|
|
788
|
-
const host = dep?.host || dep?.config?.local?.host || 'localhost';
|
|
789
|
-
result.push({ id: agent.config.id || agent.id, port, host });
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
return result;
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
/**
|
|
796
|
-
* Get a single agent
|
|
797
|
-
*/
|
|
798
|
-
getAgent(agentId: string): ManagedAgent | undefined {
|
|
799
|
-
return this.agents.get(agentId);
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
/** Get budget config for an agent */
|
|
803
|
-
getBudget(agentId: string): AgentBudgetConfig | undefined {
|
|
804
|
-
return this.agents.get(agentId)?.budgetConfig;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
/** Get usage stats for an agent */
|
|
808
|
-
getUsage(agentId: string): AgentUsage | undefined {
|
|
809
|
-
return this.agents.get(agentId)?.usage;
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
/**
|
|
813
|
-
* Get org-wide usage summary
|
|
814
|
-
*/
|
|
815
|
-
getOrgUsage(orgId: string): {
|
|
816
|
-
totalAgents: number;
|
|
817
|
-
runningAgents: number;
|
|
818
|
-
totalTokensToday: number;
|
|
819
|
-
totalCostToday: number;
|
|
820
|
-
totalToolCallsToday: number;
|
|
821
|
-
totalErrorsToday: number;
|
|
822
|
-
agents: { id: string; name: string; state: AgentState; usage: AgentUsage }[];
|
|
823
|
-
} {
|
|
824
|
-
const agents = this.getAgentsByOrg(orgId);
|
|
825
|
-
return {
|
|
826
|
-
totalAgents: agents.length,
|
|
827
|
-
runningAgents: agents.filter(a => a.state === 'running').length,
|
|
828
|
-
totalTokensToday: agents.reduce((sum, a) => sum + a.usage.tokensToday, 0),
|
|
829
|
-
totalCostToday: agents.reduce((sum, a) => sum + a.usage.costToday, 0),
|
|
830
|
-
totalToolCallsToday: agents.reduce((sum, a) => sum + a.usage.toolCallsToday, 0),
|
|
831
|
-
totalErrorsToday: agents.reduce((sum, a) => sum + a.usage.errorsToday, 0),
|
|
832
|
-
agents: agents.map(a => ({ id: a.id, name: a.config.displayName, state: a.state, usage: a.usage })),
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
/**
|
|
837
|
-
* Subscribe to lifecycle events (for dashboard real-time updates)
|
|
838
|
-
*/
|
|
839
|
-
onEvent(listener: (event: LifecycleEvent) => void): () => void {
|
|
840
|
-
this.eventListeners.push(listener);
|
|
841
|
-
return () => { this.eventListeners = this.eventListeners.filter(l => l !== listener); };
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
/**
|
|
845
|
-
* Reset daily counters (call at midnight via cron)
|
|
846
|
-
*/
|
|
847
|
-
resetDailyCounters() {
|
|
848
|
-
for (const agent of this.agents.values()) {
|
|
849
|
-
agent.usage.tokensToday = 0;
|
|
850
|
-
agent.usage.toolCallsToday = 0;
|
|
851
|
-
agent.usage.externalActionsToday = 0;
|
|
852
|
-
agent.usage.costToday = 0;
|
|
853
|
-
agent.usage.errorsToday = 0;
|
|
854
|
-
agent.usage.totalSessionsToday = 0;
|
|
855
|
-
this.dirtyAgents.add(agent.id);
|
|
856
|
-
}
|
|
857
|
-
// Reset daily alert tracking
|
|
858
|
-
this.firedAlerts.clear();
|
|
859
|
-
this.scheduleUsageFlush();
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
/**
|
|
863
|
-
* Reset monthly counters (call on 1st of month)
|
|
864
|
-
*/
|
|
865
|
-
resetMonthlyCounters() {
|
|
866
|
-
for (const agent of this.agents.values()) {
|
|
867
|
-
agent.usage.tokensThisMonth = 0;
|
|
868
|
-
agent.usage.toolCallsThisMonth = 0;
|
|
869
|
-
agent.usage.externalActionsThisMonth = 0;
|
|
870
|
-
agent.usage.costThisMonth = 0;
|
|
871
|
-
this.dirtyAgents.add(agent.id);
|
|
872
|
-
}
|
|
873
|
-
this.scheduleUsageFlush();
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
/**
|
|
877
|
-
* Reset weekly counters (call on Monday via workforce scheduler)
|
|
878
|
-
*/
|
|
879
|
-
resetWeeklyCounters() {
|
|
880
|
-
for (const agent of this.agents.values()) {
|
|
881
|
-
agent.usage.tokensThisWeek = 0;
|
|
882
|
-
agent.usage.costThisWeek = 0;
|
|
883
|
-
this.dirtyAgents.add(agent.id);
|
|
884
|
-
}
|
|
885
|
-
this.scheduleUsageFlush();
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
/**
|
|
889
|
-
* Reset annual counters (call on Jan 1 via workforce scheduler)
|
|
890
|
-
*/
|
|
891
|
-
resetAnnualCounters() {
|
|
892
|
-
for (const agent of this.agents.values()) {
|
|
893
|
-
agent.usage.tokensThisYear = 0;
|
|
894
|
-
agent.usage.costThisYear = 0;
|
|
895
|
-
this.dirtyAgents.add(agent.id);
|
|
896
|
-
}
|
|
897
|
-
this.scheduleUsageFlush();
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
// ─── Budget Management ─────────────────────────────────
|
|
901
|
-
|
|
902
|
-
/**
|
|
903
|
-
* Set per-agent budget configuration
|
|
904
|
-
*/
|
|
905
|
-
async setBudgetConfig(agentId: string, config: AgentBudgetConfig): Promise<void> {
|
|
906
|
-
const agent = this.agents.get(agentId);
|
|
907
|
-
if (!agent) throw new Error(`Agent ${agentId} not found`);
|
|
908
|
-
agent.budgetConfig = config;
|
|
909
|
-
if (!agent.config) agent.config = {} as any;
|
|
910
|
-
agent.updatedAt = new Date().toISOString();
|
|
911
|
-
|
|
912
|
-
// Write to dedicated budget_config column — completely separate from config blob
|
|
913
|
-
if (this.engineDb) {
|
|
914
|
-
await this.engineDb.execute(
|
|
915
|
-
`UPDATE managed_agents SET budget_config = ?::jsonb, updated_at = ? WHERE id = ?`,
|
|
916
|
-
[JSON.stringify(config), agent.updatedAt, agentId]
|
|
917
|
-
);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
/**
|
|
922
|
-
* Get per-agent budget configuration
|
|
923
|
-
*/
|
|
924
|
-
getBudgetConfig(agentId: string): AgentBudgetConfig | undefined {
|
|
925
|
-
const agent = this.agents.get(agentId);
|
|
926
|
-
if (!agent) return undefined;
|
|
927
|
-
// Restore from config JSON if not on top-level
|
|
928
|
-
if (!agent.budgetConfig && (agent.config as any)?.budgetConfig) {
|
|
929
|
-
agent.budgetConfig = (agent.config as any).budgetConfig;
|
|
930
|
-
}
|
|
931
|
-
return agent.budgetConfig;
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
/**
|
|
935
|
-
* Get budget alerts (optionally filtered)
|
|
936
|
-
*/
|
|
937
|
-
getBudgetAlerts(opts?: { orgId?: string; agentId?: string; acknowledged?: boolean; limit?: number }): BudgetAlert[] {
|
|
938
|
-
let alerts = [...this.budgetAlerts];
|
|
939
|
-
if (opts?.orgId) alerts = alerts.filter(a => a.orgId === opts.orgId);
|
|
940
|
-
if (opts?.agentId) alerts = alerts.filter(a => a.agentId === opts.agentId);
|
|
941
|
-
if (opts?.acknowledged !== undefined) alerts = alerts.filter(a => a.acknowledged === opts.acknowledged);
|
|
942
|
-
return alerts.slice(0, opts?.limit || 100);
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
/**
|
|
946
|
-
* Acknowledge a budget alert
|
|
947
|
-
*/
|
|
948
|
-
async acknowledgeBudgetAlert(alertId: string): Promise<void> {
|
|
949
|
-
const alert = this.budgetAlerts.find(a => a.id === alertId);
|
|
950
|
-
if (alert) {
|
|
951
|
-
alert.acknowledged = true;
|
|
952
|
-
this.engineDb?.execute(
|
|
953
|
-
'UPDATE budget_alerts SET acknowledged = 1 WHERE id = ?', [alertId]
|
|
954
|
-
).catch((err) => { console.error(`[lifecycle] Failed to acknowledge alert ${alertId}:`, err); });
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
/**
|
|
959
|
-
* Get org-wide budget summary
|
|
960
|
-
*/
|
|
961
|
-
getBudgetSummary(orgId: string): {
|
|
962
|
-
totalDailyCost: number;
|
|
963
|
-
totalWeeklyCost: number;
|
|
964
|
-
totalMonthlyCost: number;
|
|
965
|
-
totalAnnualCost: number;
|
|
966
|
-
totalDailyTokens: number;
|
|
967
|
-
totalWeeklyTokens: number;
|
|
968
|
-
totalMonthlyTokens: number;
|
|
969
|
-
totalAnnualTokens: number;
|
|
970
|
-
agentBudgets: { id: string; name: string; budget?: AgentBudgetConfig; usage: { costToday: number; costThisWeek: number; costThisMonth: number; costThisYear: number; tokensToday: number; tokensThisWeek: number; tokensThisMonth: number; tokensThisYear: number } }[];
|
|
971
|
-
recentAlerts: BudgetAlert[];
|
|
972
|
-
} {
|
|
973
|
-
const agents = this.getAgentsByOrg(orgId);
|
|
974
|
-
return {
|
|
975
|
-
totalDailyCost: agents.reduce((s, a) => s + a.usage.costToday, 0),
|
|
976
|
-
totalWeeklyCost: agents.reduce((s, a) => s + a.usage.costThisWeek, 0),
|
|
977
|
-
totalMonthlyCost: agents.reduce((s, a) => s + a.usage.costThisMonth, 0),
|
|
978
|
-
totalAnnualCost: agents.reduce((s, a) => s + a.usage.costThisYear, 0),
|
|
979
|
-
totalDailyTokens: agents.reduce((s, a) => s + a.usage.tokensToday, 0),
|
|
980
|
-
totalWeeklyTokens: agents.reduce((s, a) => s + a.usage.tokensThisWeek, 0),
|
|
981
|
-
totalMonthlyTokens: agents.reduce((s, a) => s + a.usage.tokensThisMonth, 0),
|
|
982
|
-
totalAnnualTokens: agents.reduce((s, a) => s + a.usage.tokensThisYear, 0),
|
|
983
|
-
agentBudgets: agents.map(a => ({
|
|
984
|
-
id: a.id, name: a.config.displayName, budget: a.budgetConfig,
|
|
985
|
-
usage: {
|
|
986
|
-
costToday: a.usage.costToday, costThisWeek: a.usage.costThisWeek, costThisMonth: a.usage.costThisMonth, costThisYear: a.usage.costThisYear,
|
|
987
|
-
tokensToday: a.usage.tokensToday, tokensThisWeek: a.usage.tokensThisWeek, tokensThisMonth: a.usage.tokensThisMonth, tokensThisYear: a.usage.tokensThisYear,
|
|
988
|
-
},
|
|
989
|
-
})),
|
|
990
|
-
recentAlerts: this.budgetAlerts.filter(a => a.orgId === orgId).slice(0, 20),
|
|
991
|
-
};
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
private fireBudgetAlert(agent: ManagedAgent, alertType: string, budgetType: 'cost' | 'tokens', currentValue: number, limitValue: number) {
|
|
995
|
-
const key = `${agent.id}:${alertType}:${budgetType}`;
|
|
996
|
-
if (!this.firedAlerts.has(agent.id)) this.firedAlerts.set(agent.id, new Set());
|
|
997
|
-
const fired = this.firedAlerts.get(agent.id)!;
|
|
998
|
-
if (fired.has(key)) return; // Already fired this alert today
|
|
999
|
-
fired.add(key);
|
|
1000
|
-
|
|
1001
|
-
const alert: BudgetAlert = {
|
|
1002
|
-
id: crypto.randomUUID(),
|
|
1003
|
-
orgId: agent.orgId,
|
|
1004
|
-
agentId: agent.id,
|
|
1005
|
-
alertType,
|
|
1006
|
-
budgetType,
|
|
1007
|
-
currentValue,
|
|
1008
|
-
limitValue,
|
|
1009
|
-
acknowledged: false,
|
|
1010
|
-
createdAt: new Date().toISOString(),
|
|
1011
|
-
};
|
|
1012
|
-
this.budgetAlerts.push(alert);
|
|
1013
|
-
// Keep only last 500 alerts in memory
|
|
1014
|
-
if (this.budgetAlerts.length > 500) this.budgetAlerts = this.budgetAlerts.slice(-500);
|
|
1015
|
-
|
|
1016
|
-
// Persist
|
|
1017
|
-
this.engineDb?.execute(
|
|
1018
|
-
'INSERT INTO budget_alerts (id, org_id, agent_id, alert_type, budget_type, current_value, limit_value, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
|
|
1019
|
-
[alert.id, alert.orgId, alert.agentId, alert.alertType, alert.budgetType, alert.currentValue, alert.limitValue, alert.createdAt]
|
|
1020
|
-
).catch((err) => { console.error(`[lifecycle] Failed to persist budget alert:`, err); });
|
|
1021
|
-
|
|
1022
|
-
// Emit lifecycle event
|
|
1023
|
-
const eventType = alertType.startsWith('warning') ? 'budget_warning' : 'budget_exceeded';
|
|
1024
|
-
this.emitEvent(agent, eventType, { alertType, budgetType, currentValue, limitValue, percent: Math.round(currentValue / limitValue * 100) });
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
// ─── Health Check Loop ────────────────────────────────
|
|
1028
|
-
|
|
1029
|
-
private startHealthCheckLoop(agent: ManagedAgent) {
|
|
1030
|
-
this.stopHealthCheckLoop(agent.id);
|
|
1031
|
-
|
|
1032
|
-
const interval = setInterval(async () => {
|
|
1033
|
-
try {
|
|
1034
|
-
const status = await this.deployer.getStatus(agent.config);
|
|
1035
|
-
agent.lastHealthCheckAt = new Date().toISOString();
|
|
1036
|
-
|
|
1037
|
-
const check: HealthCheck = {
|
|
1038
|
-
name: 'deployment_status',
|
|
1039
|
-
status: status.status === 'running' ? 'pass' : 'fail',
|
|
1040
|
-
message: `Status: ${status.status}, Health: ${status.healthStatus}`,
|
|
1041
|
-
timestamp: new Date().toISOString(),
|
|
1042
|
-
durationMs: 0,
|
|
1043
|
-
};
|
|
1044
|
-
|
|
1045
|
-
// Keep last 10 checks
|
|
1046
|
-
agent.health.checks = [check, ...agent.health.checks].slice(0, 10);
|
|
1047
|
-
|
|
1048
|
-
if (status.status === 'running' && status.healthStatus === 'healthy') {
|
|
1049
|
-
agent.health.status = 'healthy';
|
|
1050
|
-
agent.health.consecutiveFailures = 0;
|
|
1051
|
-
if (status.uptime) agent.health.uptime = status.uptime;
|
|
1052
|
-
if (status.metrics) {
|
|
1053
|
-
agent.usage.activeSessionCount = status.metrics.activeSessionCount;
|
|
1054
|
-
}
|
|
1055
|
-
// Recover from degraded
|
|
1056
|
-
if (agent.state === 'degraded') {
|
|
1057
|
-
this.transition(agent, 'running', 'Health restored', 'system');
|
|
1058
|
-
this.emitEvent(agent, 'auto_recovered', {});
|
|
1059
|
-
}
|
|
1060
|
-
} else {
|
|
1061
|
-
agent.health.consecutiveFailures++;
|
|
1062
|
-
agent.health.status = agent.health.consecutiveFailures >= 3 ? 'unhealthy' : 'degraded';
|
|
1063
|
-
|
|
1064
|
-
if (agent.state === 'running' && agent.health.consecutiveFailures >= 2) {
|
|
1065
|
-
this.transition(agent, 'degraded', `Health degraded: ${agent.health.consecutiveFailures} consecutive failures`, 'system');
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
// Auto-restart after 5 consecutive failures
|
|
1069
|
-
if (agent.health.consecutiveFailures >= 5 && agent.state !== 'error') {
|
|
1070
|
-
this.emitEvent(agent, 'auto_recovered', { action: 'restart', failures: agent.health.consecutiveFailures });
|
|
1071
|
-
agent.health.consecutiveFailures = 0;
|
|
1072
|
-
try {
|
|
1073
|
-
await this.deployer.restart(agent.config);
|
|
1074
|
-
this.transition(agent, 'starting', 'Auto-restarted after health failures', 'system');
|
|
1075
|
-
} catch {
|
|
1076
|
-
this.transition(agent, 'error', 'Auto-restart failed', 'system');
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
agent.health.lastCheck = new Date().toISOString();
|
|
1082
|
-
await this.persistAgent(agent);
|
|
1083
|
-
|
|
1084
|
-
} catch (error: any) {
|
|
1085
|
-
agent.health.consecutiveFailures++;
|
|
1086
|
-
agent.health.status = 'unhealthy';
|
|
1087
|
-
}
|
|
1088
|
-
}, 30_000); // Every 30 seconds
|
|
1089
|
-
|
|
1090
|
-
this.healthCheckIntervals.set(agent.id, interval);
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
private stopHealthCheckLoop(agentId: string) {
|
|
1094
|
-
const interval = this.healthCheckIntervals.get(agentId);
|
|
1095
|
-
if (interval) {
|
|
1096
|
-
clearInterval(interval);
|
|
1097
|
-
this.healthCheckIntervals.delete(agentId);
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
// ─── Private Helpers ──────────────────────────────────
|
|
1102
|
-
|
|
1103
|
-
private transition(agent: ManagedAgent, to: AgentState, reason: string, triggeredBy: string) {
|
|
1104
|
-
const from = agent.state;
|
|
1105
|
-
const transition: StateTransition = {
|
|
1106
|
-
from, to, reason, triggeredBy,
|
|
1107
|
-
timestamp: new Date().toISOString(),
|
|
1108
|
-
};
|
|
1109
|
-
agent.stateHistory.push(transition);
|
|
1110
|
-
// Keep last 50 transitions
|
|
1111
|
-
if (agent.stateHistory.length > 50) agent.stateHistory = agent.stateHistory.slice(-50);
|
|
1112
|
-
agent.state = to;
|
|
1113
|
-
agent.updatedAt = new Date().toISOString();
|
|
1114
|
-
|
|
1115
|
-
// Persist state transition to DB
|
|
1116
|
-
this.engineDb?.addStateTransition(agent.id, transition).catch((err) => {
|
|
1117
|
-
console.error(`[lifecycle] Failed to persist state transition for ${agent.id}:`, err);
|
|
1118
|
-
});
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
/**
|
|
1122
|
-
* Resolve org-level deploy credentials and merge into agent config.
|
|
1123
|
-
* If the agent's deployment config is missing an API token, look up
|
|
1124
|
-
* the org's deploy_credentials table for a matching target type.
|
|
1125
|
-
* Also sanitizes app names to be valid for the target platform.
|
|
1126
|
-
*/
|
|
1127
|
-
private async resolveDeployCredentials(agent: ManagedAgent): Promise<void> {
|
|
1128
|
-
const target = agent.config?.deployment?.target;
|
|
1129
|
-
if (!target) return;
|
|
1130
|
-
|
|
1131
|
-
// Ensure deployment.config exists
|
|
1132
|
-
if (!agent.config.deployment.config) agent.config.deployment.config = {} as any;
|
|
1133
|
-
|
|
1134
|
-
// Sanitize cloud.appName if present (Fly.io requires lowercase alphanumeric + hyphens)
|
|
1135
|
-
if (target === 'fly' || target === 'railway') {
|
|
1136
|
-
if (!agent.config.deployment.config.cloud) agent.config.deployment.config.cloud = {} as any;
|
|
1137
|
-
const cloud = agent.config.deployment.config.cloud!;
|
|
1138
|
-
|
|
1139
|
-
if (cloud.appName) {
|
|
1140
|
-
cloud.appName = cloud.appName.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '').slice(0, 30);
|
|
1141
|
-
}
|
|
1142
|
-
// Ensure provider is set
|
|
1143
|
-
if (!cloud.provider) cloud.provider = target as any;
|
|
1144
|
-
|
|
1145
|
-
// If agent already has a token, we're done
|
|
1146
|
-
if (cloud.apiToken) return;
|
|
1147
|
-
|
|
1148
|
-
// Look up org-level credentials
|
|
1149
|
-
if (this.engineDb) {
|
|
1150
|
-
try {
|
|
1151
|
-
const orgId = agent.orgId || 'default';
|
|
1152
|
-
const creds = await this.engineDb.getDeployCredentialsByType(orgId, target);
|
|
1153
|
-
if (creds.length > 0) {
|
|
1154
|
-
let credConfig = creds[0].config;
|
|
1155
|
-
|
|
1156
|
-
// Decrypt if encrypted
|
|
1157
|
-
if (credConfig?._encrypted && this.vault) {
|
|
1158
|
-
try {
|
|
1159
|
-
credConfig = JSON.parse(this.vault.decrypt(credConfig._encrypted));
|
|
1160
|
-
} catch (decErr) {
|
|
1161
|
-
console.error('[lifecycle] Failed to decrypt deploy credential:', decErr);
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
if (credConfig?.apiToken || credConfig?.token) {
|
|
1166
|
-
cloud.apiToken = credConfig.apiToken || credConfig.token;
|
|
1167
|
-
if (credConfig.region && !cloud.region) cloud.region = credConfig.region;
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
} catch (err) {
|
|
1171
|
-
console.error('[lifecycle] Failed to resolve deploy credentials:', err);
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
private isConfigComplete(config: AgentConfig): boolean {
|
|
1178
|
-
return !!(
|
|
1179
|
-
config.name &&
|
|
1180
|
-
config.displayName &&
|
|
1181
|
-
config.identity?.role &&
|
|
1182
|
-
config.model?.modelId &&
|
|
1183
|
-
config.deployment?.target &&
|
|
1184
|
-
config.permissionProfileId
|
|
1185
|
-
);
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
private async waitForHealthy(agent: ManagedAgent, timeoutMs: number): Promise<boolean> {
|
|
1189
|
-
const start = Date.now();
|
|
1190
|
-
while (Date.now() - start < timeoutMs) {
|
|
1191
|
-
try {
|
|
1192
|
-
const status = await this.deployer.getStatus(agent.config);
|
|
1193
|
-
if (status.status === 'running') return true;
|
|
1194
|
-
} catch { /* retry */ }
|
|
1195
|
-
await new Promise(r => setTimeout(r, 3000));
|
|
1196
|
-
}
|
|
1197
|
-
return false;
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
/** Public persist — for use by routes that mutate agent config directly (e.g. email config) */
|
|
1201
|
-
async saveAgent(agentId: string): Promise<void> {
|
|
1202
|
-
const agent = this.agents.get(agentId);
|
|
1203
|
-
if (agent) {
|
|
1204
|
-
await this.persistAgent(agent);
|
|
1205
|
-
// Emit generic agent save event — all config keys may have changed
|
|
1206
|
-
configBus.emitAgentConfig(agentId, '_save', undefined, 'lifecycle');
|
|
1207
|
-
// Push config to standalone agent process in real-time
|
|
1208
|
-
import('./agent-notify.js').then(({ notifyAgent }) => notifyAgent(agentId, 'config', this)).catch(() => {});
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
private async persistAgent(agent: ManagedAgent) {
|
|
1213
|
-
if (!agent.name) agent.name = agent.id;
|
|
1214
|
-
this.agents.set(agent.id, agent);
|
|
1215
|
-
if (!this.engineDb) return;
|
|
1216
|
-
try {
|
|
1217
|
-
// Reload select fields from DB before saving to avoid overwriting changes
|
|
1218
|
-
// made by other processes (enterprise server, standalone agents, direct DB updates).
|
|
1219
|
-
const dbAgent = await this.engineDb.getManagedAgent(agent.id);
|
|
1220
|
-
if (dbAgent) {
|
|
1221
|
-
const dbConfig = dbAgent.config as any;
|
|
1222
|
-
const memConfig = agent.config as any;
|
|
1223
|
-
|
|
1224
|
-
// budgetConfig: lives in its own DB column now, read via rowToManagedAgent.
|
|
1225
|
-
// Sync from DB agent object (not config JSON).
|
|
1226
|
-
if (dbAgent.budgetConfig && Object.keys(dbAgent.budgetConfig).length > 0) {
|
|
1227
|
-
agent.budgetConfig = dbAgent.budgetConfig;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
// voiceConfig: always preserve from DB (set by dashboard, used by both server + agent)
|
|
1231
|
-
if (dbConfig.voiceConfig && !memConfig.voiceConfig) {
|
|
1232
|
-
memConfig.voiceConfig = dbConfig.voiceConfig;
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
// messagingChannels: always preserve from DB (set by dashboard Channels tab)
|
|
1236
|
-
if (dbConfig.messagingChannels && !memConfig.messagingChannels) {
|
|
1237
|
-
memConfig.messagingChannels = dbConfig.messagingChannels;
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
// In standalone mode, reload dashboard-managed fields (enterprise server is source of truth)
|
|
1241
|
-
if (this.standaloneMode) {
|
|
1242
|
-
if (dbConfig.model) memConfig.model = dbConfig.model;
|
|
1243
|
-
if (dbConfig.identity) memConfig.identity = dbConfig.identity;
|
|
1244
|
-
if (dbConfig.manager) memConfig.manager = dbConfig.manager;
|
|
1245
|
-
if (dbConfig.catchUp) memConfig.catchUp = dbConfig.catchUp;
|
|
1246
|
-
if (dbConfig.autonomy) memConfig.autonomy = dbConfig.autonomy;
|
|
1247
|
-
if (dbConfig.deployment) memConfig.deployment = dbConfig.deployment;
|
|
1248
|
-
if (dbConfig.schedule) memConfig.schedule = dbConfig.schedule;
|
|
1249
|
-
if (dbConfig.skills) memConfig.skills = dbConfig.skills;
|
|
1250
|
-
if (dbConfig.enabledGoogleServices) memConfig.enabledGoogleServices = dbConfig.enabledGoogleServices;
|
|
1251
|
-
if (dbConfig.permissionProfileId) memConfig.permissionProfileId = dbConfig.permissionProfileId;
|
|
1252
|
-
if (dbConfig.voiceConfig) memConfig.voiceConfig = { ...(memConfig.voiceConfig || {}), ...dbConfig.voiceConfig };
|
|
1253
|
-
if (dbConfig.messagingChannels) memConfig.messagingChannels = { ...(memConfig.messagingChannels || {}), ...dbConfig.messagingChannels };
|
|
1254
|
-
if (dbConfig.emailConfig && memConfig.emailConfig) {
|
|
1255
|
-
const dbEmail = dbConfig.emailConfig;
|
|
1256
|
-
const memEmail = memConfig.emailConfig;
|
|
1257
|
-
if (dbEmail.oauthClientId) memEmail.oauthClientId = dbEmail.oauthClientId;
|
|
1258
|
-
if (dbEmail.oauthClientSecret) memEmail.oauthClientSecret = dbEmail.oauthClientSecret;
|
|
1259
|
-
if (dbEmail.oauthRedirectUri) memEmail.oauthRedirectUri = dbEmail.oauthRedirectUri;
|
|
1260
|
-
if (dbEmail.oauthScopes) memEmail.oauthScopes = dbEmail.oauthScopes;
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
await withRetry(
|
|
1266
|
-
() => this.engineDb!.upsertManagedAgent(agent),
|
|
1267
|
-
{ maxAttempts: 3, baseDelayMs: 100, maxDelayMs: 2000 }
|
|
1268
|
-
);
|
|
1269
|
-
} catch (err) {
|
|
1270
|
-
console.error(`[lifecycle] Failed to persist agent ${agent.id}:`, err);
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
private scheduleUsageFlush(): void {
|
|
1275
|
-
if (this.flushTimer) return;
|
|
1276
|
-
this.flushTimer = setTimeout(async () => {
|
|
1277
|
-
this.flushTimer = null;
|
|
1278
|
-
const agentIds = [...this.dirtyAgents];
|
|
1279
|
-
this.dirtyAgents.clear();
|
|
1280
|
-
for (const id of agentIds) {
|
|
1281
|
-
const agent = this.agents.get(id);
|
|
1282
|
-
if (agent) {
|
|
1283
|
-
await this.persistAgent(agent);
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
}, 5_000);
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
private emitEvent(agent: ManagedAgent, type: LifecycleEventType, data: Record<string, any>) {
|
|
1290
|
-
const event: LifecycleEvent = {
|
|
1291
|
-
id: crypto.randomUUID(),
|
|
1292
|
-
agentId: agent.id,
|
|
1293
|
-
orgId: agent.orgId,
|
|
1294
|
-
type,
|
|
1295
|
-
data,
|
|
1296
|
-
timestamp: new Date().toISOString(),
|
|
1297
|
-
};
|
|
1298
|
-
for (const listener of this.eventListeners) {
|
|
1299
|
-
try { listener(event); } catch { /* ignore */ }
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
private emptyUsage(): AgentUsage {
|
|
1304
|
-
return {
|
|
1305
|
-
tokensToday: 0, tokensThisWeek: 0, tokensThisMonth: 0, tokensThisYear: 0, tokenBudgetMonthly: 0,
|
|
1306
|
-
toolCallsToday: 0, toolCallsThisMonth: 0,
|
|
1307
|
-
externalActionsToday: 0, externalActionsThisMonth: 0,
|
|
1308
|
-
costToday: 0, costThisWeek: 0, costThisMonth: 0, costThisYear: 0, costBudgetMonthly: 0,
|
|
1309
|
-
activeSessionCount: 0, totalSessionsToday: 0,
|
|
1310
|
-
errorsToday: 0, errorRate1h: 0,
|
|
1311
|
-
lastUpdated: new Date().toISOString(),
|
|
1312
|
-
};
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
|
-
// ─── Birthday Automation ────────────────────────────
|
|
1316
|
-
|
|
1317
|
-
/**
|
|
1318
|
-
* Register a callback to send birthday messages to agents.
|
|
1319
|
-
* Called once during server startup with access to the communication bus.
|
|
1320
|
-
*/
|
|
1321
|
-
setBirthdaySender(sender: (agent: ManagedAgent) => Promise<void>) {
|
|
1322
|
-
this.birthdaySender = sender;
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
/**
|
|
1326
|
-
* Start the daily birthday check loop.
|
|
1327
|
-
* Runs every hour, but only triggers once per calendar day.
|
|
1328
|
-
*/
|
|
1329
|
-
startBirthdayScheduler() {
|
|
1330
|
-
this.checkBirthdays(); // Run immediately on startup
|
|
1331
|
-
this.birthdayTimer = setInterval(() => this.checkBirthdays(), 60 * 60 * 1000); // Every hour
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
/**
|
|
1335
|
-
* Check all agents for birthdays and send greetings.
|
|
1336
|
-
* Only fires once per calendar day.
|
|
1337
|
-
*/
|
|
1338
|
-
private async checkBirthdays() {
|
|
1339
|
-
const today = new Date();
|
|
1340
|
-
const dateKey = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`;
|
|
1341
|
-
if (this.lastBirthdayCheck === dateKey) return; // Already checked today
|
|
1342
|
-
this.lastBirthdayCheck = dateKey;
|
|
1343
|
-
|
|
1344
|
-
const todayMonth = today.getMonth() + 1;
|
|
1345
|
-
const todayDay = today.getDate();
|
|
1346
|
-
|
|
1347
|
-
for (const agent of this.agents.values()) {
|
|
1348
|
-
const dob = agent.config?.identity?.dateOfBirth;
|
|
1349
|
-
if (!dob) continue;
|
|
1350
|
-
|
|
1351
|
-
const dobDate = new Date(dob);
|
|
1352
|
-
if (dobDate.getMonth() + 1 === todayMonth && dobDate.getDate() === todayDay) {
|
|
1353
|
-
const age = AgentConfigGenerator.deriveAge(dob);
|
|
1354
|
-
this.emitEvent(agent, 'birthday', { dateOfBirth: dob, age, name: agent.config.displayName });
|
|
1355
|
-
|
|
1356
|
-
if (this.birthdaySender) {
|
|
1357
|
-
try {
|
|
1358
|
-
await this.birthdaySender(agent);
|
|
1359
|
-
} catch (err) {
|
|
1360
|
-
console.error(`[lifecycle] Failed to send birthday message to ${agent.config.displayName}:`, err);
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
/** Get agents with upcoming birthdays (next N days) */
|
|
1368
|
-
getUpcomingBirthdays(days: number = 30): { agent: ManagedAgent; dateOfBirth: string; age: number; daysUntil: number }[] {
|
|
1369
|
-
const today = new Date();
|
|
1370
|
-
const results: { agent: ManagedAgent; dateOfBirth: string; age: number; daysUntil: number }[] = [];
|
|
1371
|
-
|
|
1372
|
-
for (const agent of this.agents.values()) {
|
|
1373
|
-
const dob = agent.config?.identity?.dateOfBirth;
|
|
1374
|
-
if (!dob) continue;
|
|
1375
|
-
|
|
1376
|
-
const dobDate = new Date(dob);
|
|
1377
|
-
// Calculate next birthday this year or next
|
|
1378
|
-
const thisYearBday = new Date(today.getFullYear(), dobDate.getMonth(), dobDate.getDate());
|
|
1379
|
-
if (thisYearBday < today) {
|
|
1380
|
-
thisYearBday.setFullYear(today.getFullYear() + 1);
|
|
1381
|
-
}
|
|
1382
|
-
const diffMs = thisYearBday.getTime() - today.getTime();
|
|
1383
|
-
const daysUntil = Math.ceil(diffMs / (1000 * 60 * 60 * 24));
|
|
1384
|
-
|
|
1385
|
-
if (daysUntil <= days) {
|
|
1386
|
-
results.push({
|
|
1387
|
-
agent,
|
|
1388
|
-
dateOfBirth: dob,
|
|
1389
|
-
age: AgentConfigGenerator.deriveAge(dob) + (daysUntil > 0 ? 1 : 0),
|
|
1390
|
-
daysUntil,
|
|
1391
|
-
});
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
|
-
return results.sort((a, b) => a.daysUntil - b.daysUntil);
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
/**
|
|
1399
|
-
* Cleanup: stop all health check loops
|
|
1400
|
-
*/
|
|
1401
|
-
shutdown() {
|
|
1402
|
-
// Clear debounced flush timer
|
|
1403
|
-
if (this.flushTimer) { clearTimeout(this.flushTimer); this.flushTimer = null; }
|
|
1404
|
-
// Clear birthday scheduler
|
|
1405
|
-
if (this.birthdayTimer) { clearInterval(this.birthdayTimer); this.birthdayTimer = null; }
|
|
1406
|
-
|
|
1407
|
-
// Best-effort flush of dirty agents before stopping
|
|
1408
|
-
for (const id of this.dirtyAgents) {
|
|
1409
|
-
const agent = this.agents.get(id);
|
|
1410
|
-
if (agent) {
|
|
1411
|
-
this.engineDb?.upsertManagedAgent(agent).catch(() => {});
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
this.dirtyAgents.clear();
|
|
1415
|
-
|
|
1416
|
-
for (const [id] of this.healthCheckIntervals) {
|
|
1417
|
-
this.stopHealthCheckLoop(id);
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
}
|