@agenticmail/enterprise 0.5.326 → 0.5.328
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/dashboard/app.js +1 -1
- package/dist/dashboard/pages/cluster.js +1 -1
- package/logs/cloudflared-error.log +6 -0
- package/logs/enterprise-out.log +2 -0
- package/package.json +1 -1
- package/god_is_great.html +0 -35
- 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/HELP-TOOLTIPS-GUIDE.md +0 -45
- 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
|
@@ -1,1386 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Knowledge Contribution System
|
|
3
|
-
*
|
|
4
|
-
* Agents contribute knowledge from their memory to shared knowledge bases,
|
|
5
|
-
* categorized by role and domain. Future agents in the same role get
|
|
6
|
-
* bootstrapped with this collective knowledge.
|
|
7
|
-
*
|
|
8
|
-
* - Weekly scheduled contribution cycles
|
|
9
|
-
* - Role-based knowledge bases (support, sales, engineering, etc.)
|
|
10
|
-
* - Category taxonomy within each base
|
|
11
|
-
* - Quality scoring, deduplication, and decay
|
|
12
|
-
* - Contribution approval workflow (optional)
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
// ─── Types ──────────────────────────────────────────────
|
|
16
|
-
|
|
17
|
-
export type KnowledgeRole =
|
|
18
|
-
| 'support'
|
|
19
|
-
| 'sales'
|
|
20
|
-
| 'engineering'
|
|
21
|
-
| 'operations'
|
|
22
|
-
| 'hr'
|
|
23
|
-
| 'finance'
|
|
24
|
-
| 'legal'
|
|
25
|
-
| 'marketing'
|
|
26
|
-
| 'research'
|
|
27
|
-
| 'security'
|
|
28
|
-
| 'executive'
|
|
29
|
-
| 'general';
|
|
30
|
-
|
|
31
|
-
export interface KnowledgeBase {
|
|
32
|
-
id: string;
|
|
33
|
-
orgId: string;
|
|
34
|
-
name: string;
|
|
35
|
-
description: string;
|
|
36
|
-
role: KnowledgeRole;
|
|
37
|
-
categories: KnowledgeCategory[];
|
|
38
|
-
contributorCount: number;
|
|
39
|
-
entryCount: number;
|
|
40
|
-
lastContributionAt: string;
|
|
41
|
-
createdAt: string;
|
|
42
|
-
updatedAt: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface KnowledgeCategory {
|
|
46
|
-
id: string;
|
|
47
|
-
name: string;
|
|
48
|
-
description: string;
|
|
49
|
-
parentId?: string;
|
|
50
|
-
entryCount: number;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface KnowledgeEntry {
|
|
54
|
-
id: string;
|
|
55
|
-
baseId: string;
|
|
56
|
-
orgId: string;
|
|
57
|
-
categoryId: string;
|
|
58
|
-
category?: string;
|
|
59
|
-
title: string;
|
|
60
|
-
content: string;
|
|
61
|
-
summary: string;
|
|
62
|
-
tags: string[];
|
|
63
|
-
sourceAgentId: string;
|
|
64
|
-
sourceMemoryId?: string;
|
|
65
|
-
confidence: number;
|
|
66
|
-
qualityScore: number;
|
|
67
|
-
useCount: number;
|
|
68
|
-
voteUp: number;
|
|
69
|
-
voteDown: number;
|
|
70
|
-
status: 'pending' | 'approved' | 'rejected' | 'archived';
|
|
71
|
-
createdAt: string;
|
|
72
|
-
updatedAt: string;
|
|
73
|
-
expiresAt?: string;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface ContributionSchedule {
|
|
77
|
-
id: string;
|
|
78
|
-
orgId: string;
|
|
79
|
-
agentId: string;
|
|
80
|
-
baseId: string;
|
|
81
|
-
frequency: 'daily' | 'weekly' | 'biweekly' | 'monthly';
|
|
82
|
-
dayOfWeek?: number;
|
|
83
|
-
lastRunAt?: string;
|
|
84
|
-
nextRunAt: string;
|
|
85
|
-
enabled: boolean;
|
|
86
|
-
filters: {
|
|
87
|
-
minConfidence: number;
|
|
88
|
-
categories?: string[];
|
|
89
|
-
minImportance?: string;
|
|
90
|
-
};
|
|
91
|
-
createdAt: string;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface ContributionCycle {
|
|
95
|
-
id: string;
|
|
96
|
-
orgId: string;
|
|
97
|
-
agentId: string;
|
|
98
|
-
baseId: string;
|
|
99
|
-
scheduleId: string;
|
|
100
|
-
status: 'running' | 'completed' | 'failed';
|
|
101
|
-
memoriesScanned: number;
|
|
102
|
-
entriesContributed: number;
|
|
103
|
-
duplicatesSkipped: number;
|
|
104
|
-
startedAt: string;
|
|
105
|
-
completedAt?: string;
|
|
106
|
-
error?: string;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// ─── Helpers ─────────────────────────────────────────────
|
|
110
|
-
|
|
111
|
-
function uid(): string {
|
|
112
|
-
return Date.now().toString(36) + Math.random().toString(36).slice(2, 10);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** Compute a simple Jaccard-like similarity between two strings based on word-level token overlap. */
|
|
116
|
-
function contentSimilarity(a: string, b: string): number {
|
|
117
|
-
const tokenize = (text: string): Set<string> => {
|
|
118
|
-
const tokens = new Set<string>();
|
|
119
|
-
const words = text.toLowerCase().replace(/[^a-z0-9\s]/g, '').split(/\s+/);
|
|
120
|
-
for (const w of words) {
|
|
121
|
-
if (w.length > 2) tokens.add(w);
|
|
122
|
-
}
|
|
123
|
-
return tokens;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const tokensA = tokenize(a);
|
|
127
|
-
const tokensB = tokenize(b);
|
|
128
|
-
if (tokensA.size === 0 || tokensB.size === 0) return 0;
|
|
129
|
-
|
|
130
|
-
let intersection = 0;
|
|
131
|
-
for (const t of tokensA) {
|
|
132
|
-
if (tokensB.has(t)) intersection++;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const union = new Set([...tokensA, ...tokensB]).size;
|
|
136
|
-
return union > 0 ? intersection / union : 0;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** Compute a quality score from votes, usage, and freshness. */
|
|
140
|
-
function computeQualityScore(entry: {
|
|
141
|
-
voteUp: number;
|
|
142
|
-
voteDown: number;
|
|
143
|
-
useCount: number;
|
|
144
|
-
confidence: number;
|
|
145
|
-
createdAt: string;
|
|
146
|
-
}): number {
|
|
147
|
-
// Vote component: net votes (capped at reasonable range)
|
|
148
|
-
const netVotes = entry.voteUp - entry.voteDown;
|
|
149
|
-
const voteScore = Math.min(1, Math.max(0, (netVotes + 5) / 10)); // -5..+5 -> 0..1
|
|
150
|
-
|
|
151
|
-
// Usage component: logarithmic usage
|
|
152
|
-
const usageScore = Math.min(1, Math.log1p(entry.useCount) / Math.log1p(50)); // 0..50 -> 0..1
|
|
153
|
-
|
|
154
|
-
// Freshness component: decay over 180 days
|
|
155
|
-
const ageMs = Date.now() - new Date(entry.createdAt).getTime();
|
|
156
|
-
const ageDays = ageMs / 86_400_000;
|
|
157
|
-
const freshnessScore = Math.max(0.1, 1 - (ageDays / 180));
|
|
158
|
-
|
|
159
|
-
// Weighted combination
|
|
160
|
-
const quality = (
|
|
161
|
-
entry.confidence * 0.3 +
|
|
162
|
-
voteScore * 0.25 +
|
|
163
|
-
usageScore * 0.25 +
|
|
164
|
-
freshnessScore * 0.2
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
return parseFloat(Math.min(1, Math.max(0, quality)).toFixed(4));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** Compute the next run timestamp from a frequency and optional dayOfWeek. */
|
|
171
|
-
function computeNextRunAt(frequency: ContributionSchedule['frequency'], dayOfWeek?: number): string {
|
|
172
|
-
const now = new Date();
|
|
173
|
-
let next: Date;
|
|
174
|
-
|
|
175
|
-
switch (frequency) {
|
|
176
|
-
case 'daily':
|
|
177
|
-
next = new Date(now.getTime() + 86_400_000);
|
|
178
|
-
break;
|
|
179
|
-
case 'weekly': {
|
|
180
|
-
next = new Date(now.getTime());
|
|
181
|
-
const targetDay = dayOfWeek ?? 1; // default Monday
|
|
182
|
-
const currentDay = now.getDay();
|
|
183
|
-
let daysUntil = targetDay - currentDay;
|
|
184
|
-
if (daysUntil <= 0) daysUntil += 7;
|
|
185
|
-
next.setDate(next.getDate() + daysUntil);
|
|
186
|
-
next.setHours(2, 0, 0, 0); // 2 AM
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
case 'biweekly': {
|
|
190
|
-
next = new Date(now.getTime());
|
|
191
|
-
const targetDay2 = dayOfWeek ?? 1;
|
|
192
|
-
const currentDay2 = now.getDay();
|
|
193
|
-
let daysUntil2 = targetDay2 - currentDay2;
|
|
194
|
-
if (daysUntil2 <= 0) daysUntil2 += 7;
|
|
195
|
-
next.setDate(next.getDate() + daysUntil2 + 7);
|
|
196
|
-
next.setHours(2, 0, 0, 0);
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
case 'monthly':
|
|
200
|
-
next = new Date(now.getFullYear(), now.getMonth() + 1, 1, 2, 0, 0, 0);
|
|
201
|
-
break;
|
|
202
|
-
default:
|
|
203
|
-
next = new Date(now.getTime() + 7 * 86_400_000);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return next.toISOString();
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// ─── Available Roles ────────────────────────────────────
|
|
210
|
-
|
|
211
|
-
const AVAILABLE_ROLES: Array<{ id: KnowledgeRole; name: string; description: string }> = [
|
|
212
|
-
{ id: 'support', name: 'Support', description: 'Customer support and success teams' },
|
|
213
|
-
{ id: 'sales', name: 'Sales', description: 'Sales and business development teams' },
|
|
214
|
-
{ id: 'engineering', name: 'Engineering', description: 'Software engineering and development teams' },
|
|
215
|
-
{ id: 'operations', name: 'Operations', description: 'Business operations teams' },
|
|
216
|
-
{ id: 'hr', name: 'Human Resources', description: 'HR and people operations teams' },
|
|
217
|
-
{ id: 'finance', name: 'Finance', description: 'Finance and accounting teams' },
|
|
218
|
-
{ id: 'legal', name: 'Legal', description: 'Legal and compliance teams' },
|
|
219
|
-
{ id: 'marketing', name: 'Marketing', description: 'Marketing and growth teams' },
|
|
220
|
-
{ id: 'research', name: 'Research', description: 'Research and data science teams' },
|
|
221
|
-
{ id: 'security', name: 'Security', description: 'Information security teams' },
|
|
222
|
-
{ id: 'executive', name: 'Executive', description: 'Executive leadership and strategy' },
|
|
223
|
-
{ id: 'general', name: 'General', description: 'Cross-functional shared knowledge' },
|
|
224
|
-
];
|
|
225
|
-
|
|
226
|
-
// ─── Default Category Taxonomy ──────────────────────────
|
|
227
|
-
|
|
228
|
-
const ROLE_CATEGORIES: Record<string, Omit<KnowledgeCategory, 'entryCount'>[]> = {
|
|
229
|
-
support: [
|
|
230
|
-
{ id: 'troubleshooting', name: 'Troubleshooting', description: 'Common issues and solutions' },
|
|
231
|
-
{ id: 'product-knowledge', name: 'Product Knowledge', description: 'Product features, limitations, and workarounds' },
|
|
232
|
-
{ id: 'customer-patterns', name: 'Customer Patterns', description: 'Common customer behaviors and needs' },
|
|
233
|
-
{ id: 'escalation-playbooks', name: 'Escalation Playbooks', description: 'When and how to escalate issues' },
|
|
234
|
-
{ id: 'faq-responses', name: 'FAQ Responses', description: 'Frequently asked questions and best responses' },
|
|
235
|
-
{ id: 'tools-integrations', name: 'Tools & Integrations', description: 'How to use support tools effectively' },
|
|
236
|
-
],
|
|
237
|
-
sales: [
|
|
238
|
-
{ id: 'objection-handling', name: 'Objection Handling', description: 'Responses to common objections' },
|
|
239
|
-
{ id: 'competitor-intel', name: 'Competitor Intelligence', description: 'Competitor strengths, weaknesses, positioning' },
|
|
240
|
-
{ id: 'pricing-strategies', name: 'Pricing Strategies', description: 'Effective pricing and discount approaches' },
|
|
241
|
-
{ id: 'qualification-criteria', name: 'Qualification Criteria', description: 'Lead qualification patterns' },
|
|
242
|
-
{ id: 'pitch-templates', name: 'Pitch Templates', description: 'Effective pitch structures and talking points' },
|
|
243
|
-
{ id: 'deal-patterns', name: 'Deal Patterns', description: 'Successful deal closure patterns' },
|
|
244
|
-
],
|
|
245
|
-
engineering: [
|
|
246
|
-
{ id: 'architecture-decisions', name: 'Architecture Decisions', description: 'ADRs and design rationale' },
|
|
247
|
-
{ id: 'debugging-patterns', name: 'Debugging Patterns', description: 'Common bugs and debugging approaches' },
|
|
248
|
-
{ id: 'code-standards', name: 'Code Standards', description: 'Coding conventions and best practices' },
|
|
249
|
-
{ id: 'infrastructure', name: 'Infrastructure', description: 'Infrastructure setup and operations knowledge' },
|
|
250
|
-
{ id: 'incident-learnings', name: 'Incident Learnings', description: 'Post-mortem insights and prevention' },
|
|
251
|
-
{ id: 'tool-configs', name: 'Tool Configurations', description: 'Development tool setups and configs' },
|
|
252
|
-
],
|
|
253
|
-
operations: [
|
|
254
|
-
{ id: 'process-docs', name: 'Process Documentation', description: 'Standard operating procedures' },
|
|
255
|
-
{ id: 'vendor-management', name: 'Vendor Management', description: 'Vendor relationships and negotiations' },
|
|
256
|
-
{ id: 'compliance-notes', name: 'Compliance Notes', description: 'Regulatory compliance knowledge' },
|
|
257
|
-
{ id: 'efficiency-tips', name: 'Efficiency Tips', description: 'Process optimization insights' },
|
|
258
|
-
],
|
|
259
|
-
hr: [
|
|
260
|
-
{ id: 'policy-interpretations', name: 'Policy Interpretations', description: 'HR policy applications and edge cases' },
|
|
261
|
-
{ id: 'interview-guides', name: 'Interview Guides', description: 'Interview questions and evaluation criteria' },
|
|
262
|
-
{ id: 'onboarding-tips', name: 'Onboarding Tips', description: 'Employee onboarding best practices' },
|
|
263
|
-
{ id: 'benefits-faq', name: 'Benefits FAQ', description: 'Benefits questions and answers' },
|
|
264
|
-
],
|
|
265
|
-
finance: [
|
|
266
|
-
{ id: 'accounting-procedures', name: 'Accounting Procedures', description: 'Standard accounting workflows' },
|
|
267
|
-
{ id: 'tax-knowledge', name: 'Tax Knowledge', description: 'Tax rules and compliance notes' },
|
|
268
|
-
{ id: 'budget-templates', name: 'Budget Templates', description: 'Budget planning templates and guides' },
|
|
269
|
-
{ id: 'audit-prep', name: 'Audit Preparation', description: 'Audit preparation checklists and tips' },
|
|
270
|
-
],
|
|
271
|
-
legal: [
|
|
272
|
-
{ id: 'contract-templates', name: 'Contract Templates', description: 'Standard contract clauses and templates' },
|
|
273
|
-
{ id: 'regulatory-updates', name: 'Regulatory Updates', description: 'Regulatory changes and implications' },
|
|
274
|
-
{ id: 'risk-assessments', name: 'Risk Assessments', description: 'Legal risk evaluation patterns' },
|
|
275
|
-
],
|
|
276
|
-
marketing: [
|
|
277
|
-
{ id: 'campaign-playbooks', name: 'Campaign Playbooks', description: 'Successful campaign strategies' },
|
|
278
|
-
{ id: 'content-guidelines', name: 'Content Guidelines', description: 'Brand voice and content standards' },
|
|
279
|
-
{ id: 'channel-strategies', name: 'Channel Strategies', description: 'Channel-specific marketing approaches' },
|
|
280
|
-
{ id: 'analytics-insights', name: 'Analytics Insights', description: 'Marketing analytics patterns' },
|
|
281
|
-
],
|
|
282
|
-
research: [
|
|
283
|
-
{ id: 'methodologies', name: 'Research Methodologies', description: 'Research methods and frameworks' },
|
|
284
|
-
{ id: 'data-sources', name: 'Data Sources', description: 'Useful data sources and APIs' },
|
|
285
|
-
{ id: 'findings-library', name: 'Findings Library', description: 'Key research findings and insights' },
|
|
286
|
-
],
|
|
287
|
-
security: [
|
|
288
|
-
{ id: 'threat-intel', name: 'Threat Intelligence', description: 'Known threats and attack patterns' },
|
|
289
|
-
{ id: 'incident-response', name: 'Incident Response', description: 'IR procedures and playbooks' },
|
|
290
|
-
{ id: 'security-configs', name: 'Security Configurations', description: 'Hardening guides and configs' },
|
|
291
|
-
],
|
|
292
|
-
executive: [
|
|
293
|
-
{ id: 'strategy-frameworks', name: 'Strategy Frameworks', description: 'Strategic planning frameworks' },
|
|
294
|
-
{ id: 'market-analysis', name: 'Market Analysis', description: 'Market trends and analysis' },
|
|
295
|
-
{ id: 'decision-frameworks', name: 'Decision Frameworks', description: 'Decision-making frameworks and criteria' },
|
|
296
|
-
],
|
|
297
|
-
general: [
|
|
298
|
-
{ id: 'best-practices', name: 'Best Practices', description: 'Cross-functional best practices' },
|
|
299
|
-
{ id: 'tools-guides', name: 'Tools & Guides', description: 'Tool usage guides and tips' },
|
|
300
|
-
{ id: 'lessons-learned', name: 'Lessons Learned', description: 'Cross-team lessons learned' },
|
|
301
|
-
{ id: 'templates', name: 'Templates', description: 'Reusable templates and frameworks' },
|
|
302
|
-
],
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
// ─── Memory Callback Type ───────────────────────────────
|
|
306
|
-
|
|
307
|
-
export type MemoryCallback = (agentId: string) => Promise<MemoryItem[]>;
|
|
308
|
-
|
|
309
|
-
/** Shape of a memory item returned by the memory callback. */
|
|
310
|
-
export interface MemoryItem {
|
|
311
|
-
id: string;
|
|
312
|
-
agentId: string;
|
|
313
|
-
orgId: string;
|
|
314
|
-
category: string;
|
|
315
|
-
title: string;
|
|
316
|
-
content: string;
|
|
317
|
-
source: string;
|
|
318
|
-
importance: string;
|
|
319
|
-
confidence: number;
|
|
320
|
-
tags: string[];
|
|
321
|
-
createdAt: string;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// ─── Knowledge Contribution Manager ────────────────────
|
|
325
|
-
|
|
326
|
-
export class KnowledgeContributionManager {
|
|
327
|
-
private bases = new Map<string, KnowledgeBase>();
|
|
328
|
-
private entries = new Map<string, KnowledgeEntry>();
|
|
329
|
-
private schedules = new Map<string, ContributionSchedule>();
|
|
330
|
-
private cycles = new Map<string, ContributionCycle>();
|
|
331
|
-
private memoryCallback?: MemoryCallback;
|
|
332
|
-
private schedulerTimer?: ReturnType<typeof setInterval>;
|
|
333
|
-
|
|
334
|
-
/** Per-base index: baseId -> Set of entry IDs for O(1) base lookups */
|
|
335
|
-
private baseEntryIndex = new Map<string, Set<string>>();
|
|
336
|
-
/** Per-agent index: agentId -> Set of entry IDs */
|
|
337
|
-
private agentEntryIndex = new Map<string, Set<string>>();
|
|
338
|
-
/** Per-agent schedule index: agentId -> scheduleId */
|
|
339
|
-
private agentScheduleIndex = new Map<string, string>();
|
|
340
|
-
/** Contributor tracking: baseId -> Set of agent IDs that contributed */
|
|
341
|
-
private baseContributors = new Map<string, Set<string>>();
|
|
342
|
-
|
|
343
|
-
private db?: any; // DatabaseAdapter
|
|
344
|
-
|
|
345
|
-
constructor(opts?: { memoryCallback?: MemoryCallback }) {
|
|
346
|
-
this.memoryCallback = opts?.memoryCallback;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
async setDb(engineDb: any): Promise<void> {
|
|
350
|
-
// Accept EngineDatabase wrapper or raw adapter
|
|
351
|
-
const db = engineDb?.db || engineDb;
|
|
352
|
-
this.db = db;
|
|
353
|
-
// Load persisted bases
|
|
354
|
-
try {
|
|
355
|
-
const rows = await db.all('SELECT * FROM knowledge_contribution_bases ORDER BY created_at');
|
|
356
|
-
for (const row of rows || []) {
|
|
357
|
-
const data = typeof row.data === 'string' ? JSON.parse(row.data) : (row.data || {});
|
|
358
|
-
const base: KnowledgeBase = {
|
|
359
|
-
id: row.id,
|
|
360
|
-
orgId: row.org_id,
|
|
361
|
-
name: row.name,
|
|
362
|
-
description: row.description,
|
|
363
|
-
role: row.role as KnowledgeRole,
|
|
364
|
-
categories: data.categories || [],
|
|
365
|
-
contributorCount: data.contributorCount || 0,
|
|
366
|
-
entryCount: data.entryCount || 0,
|
|
367
|
-
lastContributionAt: data.lastContributionAt || row.updated_at,
|
|
368
|
-
createdAt: row.created_at,
|
|
369
|
-
updatedAt: row.updated_at,
|
|
370
|
-
};
|
|
371
|
-
this.bases.set(base.id, base);
|
|
372
|
-
}
|
|
373
|
-
// Load entries
|
|
374
|
-
const entryRows = await db.all('SELECT * FROM knowledge_contribution_entries ORDER BY created_at');
|
|
375
|
-
for (const row of entryRows || []) {
|
|
376
|
-
const data = typeof row.data === 'string' ? JSON.parse(row.data) : (row.data || {});
|
|
377
|
-
const entry: KnowledgeEntry = { id: row.id, baseId: row.base_id, sourceAgentId: row.source_agent_id, category: row.category, ...data, createdAt: row.created_at };
|
|
378
|
-
this.entries.set(entry.id, entry);
|
|
379
|
-
this.indexEntryAdd(entry);
|
|
380
|
-
}
|
|
381
|
-
} catch (e) {
|
|
382
|
-
// Table may not exist yet (pre-migration)
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
private async persistBase(base: KnowledgeBase): Promise<void> {
|
|
387
|
-
if (!this.db) return;
|
|
388
|
-
const data = JSON.stringify({ categories: base.categories, contributorCount: base.contributorCount, entryCount: base.entryCount, lastContributionAt: base.lastContributionAt });
|
|
389
|
-
await this.db.run(
|
|
390
|
-
`INSERT INTO knowledge_contribution_bases (id, org_id, name, description, role, data, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(id) DO UPDATE SET name=excluded.name, description=excluded.description, data=excluded.data, updated_at=excluded.updated_at`,
|
|
391
|
-
[base.id, base.orgId, base.name, base.description || '', base.role, data, base.createdAt, base.updatedAt]
|
|
392
|
-
);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
private async persistEntry(entry: KnowledgeEntry): Promise<void> {
|
|
396
|
-
if (!this.db) return;
|
|
397
|
-
const { id, baseId, sourceAgentId, category, createdAt, ...rest } = entry;
|
|
398
|
-
await this.db.run(
|
|
399
|
-
`INSERT INTO knowledge_contribution_entries (id, base_id, org_id, source_agent_id, category, data, created_at) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT(id) DO UPDATE SET data=excluded.data`,
|
|
400
|
-
[id, baseId, this.bases.get(baseId)?.orgId || '', sourceAgentId, category || '', JSON.stringify(rest), createdAt]
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
private async deleteBaseFromDb(baseId: string): Promise<void> {
|
|
405
|
-
if (!this.db) return;
|
|
406
|
-
await this.db.run('DELETE FROM knowledge_contribution_bases WHERE id = ?', [baseId]);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// ─── Index Helpers ──────────────────────────────────
|
|
410
|
-
|
|
411
|
-
private indexEntryAdd(entry: KnowledgeEntry): void {
|
|
412
|
-
// Base index
|
|
413
|
-
let baseSet = this.baseEntryIndex.get(entry.baseId);
|
|
414
|
-
if (!baseSet) { baseSet = new Set(); this.baseEntryIndex.set(entry.baseId, baseSet); }
|
|
415
|
-
baseSet.add(entry.id);
|
|
416
|
-
|
|
417
|
-
// Agent index
|
|
418
|
-
let agentSet = this.agentEntryIndex.get(entry.sourceAgentId);
|
|
419
|
-
if (!agentSet) { agentSet = new Set(); this.agentEntryIndex.set(entry.sourceAgentId, agentSet); }
|
|
420
|
-
agentSet.add(entry.id);
|
|
421
|
-
|
|
422
|
-
// Contributor tracking
|
|
423
|
-
let contributors = this.baseContributors.get(entry.baseId);
|
|
424
|
-
if (!contributors) { contributors = new Set(); this.baseContributors.set(entry.baseId, contributors); }
|
|
425
|
-
contributors.add(entry.sourceAgentId);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
private _indexEntryRemove(entry: KnowledgeEntry): void {
|
|
429
|
-
const baseSet = this.baseEntryIndex.get(entry.baseId);
|
|
430
|
-
if (baseSet) { baseSet.delete(entry.id); if (baseSet.size === 0) this.baseEntryIndex.delete(entry.baseId); }
|
|
431
|
-
|
|
432
|
-
const agentSet = this.agentEntryIndex.get(entry.sourceAgentId);
|
|
433
|
-
if (agentSet) { agentSet.delete(entry.id); if (agentSet.size === 0) this.agentEntryIndex.delete(entry.sourceAgentId); }
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
private getEntriesForBase(baseId: string): KnowledgeEntry[] {
|
|
437
|
-
const ids = this.baseEntryIndex.get(baseId);
|
|
438
|
-
if (!ids || ids.size === 0) return [];
|
|
439
|
-
const result: KnowledgeEntry[] = [];
|
|
440
|
-
for (const id of ids) {
|
|
441
|
-
const entry = this.entries.get(id);
|
|
442
|
-
if (entry) result.push(entry);
|
|
443
|
-
}
|
|
444
|
-
return result;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
private getEntriesForAgent(agentId: string): KnowledgeEntry[] {
|
|
448
|
-
const ids = this.agentEntryIndex.get(agentId);
|
|
449
|
-
if (!ids || ids.size === 0) return [];
|
|
450
|
-
const result: KnowledgeEntry[] = [];
|
|
451
|
-
for (const id of ids) {
|
|
452
|
-
const entry = this.entries.get(id);
|
|
453
|
-
if (entry) result.push(entry);
|
|
454
|
-
}
|
|
455
|
-
return result;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
// ─── Knowledge Base CRUD ────────────────────────────
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Create a knowledge base.
|
|
462
|
-
* Accepts either (orgId, { name, description, role }) positional args
|
|
463
|
-
* or a single object { orgId, name, description, role, createdBy? }.
|
|
464
|
-
*/
|
|
465
|
-
createBase(
|
|
466
|
-
orgIdOrOpts: string | { orgId: string; name: string; description: string; role: string; createdBy?: string },
|
|
467
|
-
opts?: { name: string; description: string; role: string },
|
|
468
|
-
): KnowledgeBase {
|
|
469
|
-
let orgId: string;
|
|
470
|
-
let name: string;
|
|
471
|
-
let description: string;
|
|
472
|
-
let role: string;
|
|
473
|
-
|
|
474
|
-
if (typeof orgIdOrOpts === 'object') {
|
|
475
|
-
orgId = orgIdOrOpts.orgId;
|
|
476
|
-
name = orgIdOrOpts.name;
|
|
477
|
-
description = orgIdOrOpts.description;
|
|
478
|
-
role = orgIdOrOpts.role;
|
|
479
|
-
} else {
|
|
480
|
-
orgId = orgIdOrOpts;
|
|
481
|
-
if (!opts) throw new Error('Options required when orgId is a string');
|
|
482
|
-
name = opts.name;
|
|
483
|
-
description = opts.description;
|
|
484
|
-
role = opts.role;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
const now = new Date().toISOString();
|
|
488
|
-
const roleCategories = ROLE_CATEGORIES[role] || ROLE_CATEGORIES.general;
|
|
489
|
-
const categories: KnowledgeCategory[] = roleCategories.map(c => ({
|
|
490
|
-
...c,
|
|
491
|
-
entryCount: 0,
|
|
492
|
-
}));
|
|
493
|
-
|
|
494
|
-
const base: KnowledgeBase = {
|
|
495
|
-
id: uid(),
|
|
496
|
-
orgId,
|
|
497
|
-
name,
|
|
498
|
-
description,
|
|
499
|
-
role: role as KnowledgeRole,
|
|
500
|
-
categories,
|
|
501
|
-
contributorCount: 0,
|
|
502
|
-
entryCount: 0,
|
|
503
|
-
lastContributionAt: now,
|
|
504
|
-
createdAt: now,
|
|
505
|
-
updatedAt: now,
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
this.bases.set(base.id, base);
|
|
509
|
-
this.persistBase(base).catch(() => {});
|
|
510
|
-
return base;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
getBase(baseId: string): KnowledgeBase | undefined {
|
|
514
|
-
return this.bases.get(baseId);
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* List knowledge bases for an org.
|
|
519
|
-
* The second argument can be a string (role name) or { role? } filter object.
|
|
520
|
-
*/
|
|
521
|
-
listBases(orgId: string, filters?: string | { role?: KnowledgeRole }): KnowledgeBase[] {
|
|
522
|
-
let results = Array.from(this.bases.values()).filter(b => b.orgId === orgId);
|
|
523
|
-
|
|
524
|
-
const roleFilter = typeof filters === 'string' ? filters : filters?.role;
|
|
525
|
-
if (roleFilter) {
|
|
526
|
-
results = results.filter(b => b.role === roleFilter);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
return results;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* Delete a knowledge base and all associated entries, schedules, and contributor tracking.
|
|
534
|
-
*/
|
|
535
|
-
deleteBase(baseId: string, _userId?: string): void {
|
|
536
|
-
const base = this.bases.get(baseId);
|
|
537
|
-
if (!base) return;
|
|
538
|
-
|
|
539
|
-
// Remove all entries for this base
|
|
540
|
-
const entryIds = this.baseEntryIndex.get(baseId);
|
|
541
|
-
if (entryIds) {
|
|
542
|
-
for (const id of entryIds) {
|
|
543
|
-
const entry = this.entries.get(id);
|
|
544
|
-
if (entry) {
|
|
545
|
-
const agentSet = this.agentEntryIndex.get(entry.sourceAgentId);
|
|
546
|
-
if (agentSet) { agentSet.delete(id); if (agentSet.size === 0) this.agentEntryIndex.delete(entry.sourceAgentId); }
|
|
547
|
-
}
|
|
548
|
-
this.entries.delete(id);
|
|
549
|
-
}
|
|
550
|
-
this.baseEntryIndex.delete(baseId);
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
// Remove contributor tracking
|
|
554
|
-
this.baseContributors.delete(baseId);
|
|
555
|
-
|
|
556
|
-
// Remove schedules targeting this base
|
|
557
|
-
for (const [scheduleId, schedule] of Array.from(this.schedules.entries())) {
|
|
558
|
-
if (schedule.baseId === baseId) {
|
|
559
|
-
this.agentScheduleIndex.delete(schedule.agentId);
|
|
560
|
-
this.schedules.delete(scheduleId);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
this.bases.delete(baseId);
|
|
565
|
-
this.deleteBaseFromDb(baseId).catch(() => {});
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
// ─── Roles ──────────────────────────────────────────
|
|
569
|
-
|
|
570
|
-
/** List all available roles with metadata. */
|
|
571
|
-
listRoles(): Array<{ id: KnowledgeRole; name: string; description: string; categoryCount: number }> {
|
|
572
|
-
return AVAILABLE_ROLES.map(r => ({
|
|
573
|
-
...r,
|
|
574
|
-
categoryCount: (ROLE_CATEGORIES[r.id] || []).length,
|
|
575
|
-
}));
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// ─── Category Management ────────────────────────────
|
|
579
|
-
|
|
580
|
-
addCategory(baseId: string, category: { id?: string; name: string; description: string; parentId?: string }): KnowledgeCategory {
|
|
581
|
-
const base = this.bases.get(baseId);
|
|
582
|
-
if (!base) throw new Error(`Knowledge base ${baseId} not found`);
|
|
583
|
-
|
|
584
|
-
const cat: KnowledgeCategory = {
|
|
585
|
-
id: category.id || uid(),
|
|
586
|
-
name: category.name,
|
|
587
|
-
description: category.description,
|
|
588
|
-
parentId: category.parentId,
|
|
589
|
-
entryCount: 0,
|
|
590
|
-
};
|
|
591
|
-
|
|
592
|
-
// Check for duplicate ID
|
|
593
|
-
const existing = base.categories.find(c => c.id === cat.id);
|
|
594
|
-
if (existing) throw new Error(`Category ${cat.id} already exists in base ${baseId}`);
|
|
595
|
-
|
|
596
|
-
base.categories.push(cat);
|
|
597
|
-
base.updatedAt = new Date().toISOString();
|
|
598
|
-
return cat;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
removeCategory(baseId: string, categoryId: string): void {
|
|
602
|
-
const base = this.bases.get(baseId);
|
|
603
|
-
if (!base) throw new Error(`Knowledge base ${baseId} not found`);
|
|
604
|
-
|
|
605
|
-
const idx = base.categories.findIndex(c => c.id === categoryId);
|
|
606
|
-
if (idx < 0) throw new Error(`Category ${categoryId} not found in base ${baseId}`);
|
|
607
|
-
|
|
608
|
-
base.categories.splice(idx, 1);
|
|
609
|
-
base.updatedAt = new Date().toISOString();
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
getCategoriesForRole(role: string): KnowledgeCategory[] {
|
|
613
|
-
const defs = ROLE_CATEGORIES[role] || ROLE_CATEGORIES.general;
|
|
614
|
-
return defs.map(d => ({ ...d, entryCount: 0 }));
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
// ─── Entries ────────────────────────────────────────
|
|
618
|
-
|
|
619
|
-
/**
|
|
620
|
-
* Low-level contribute: all fields provided explicitly including baseId and orgId.
|
|
621
|
-
* Used internally by contribution cycles.
|
|
622
|
-
*/
|
|
623
|
-
contribute(opts: {
|
|
624
|
-
baseId: string;
|
|
625
|
-
orgId: string;
|
|
626
|
-
categoryId: string;
|
|
627
|
-
title: string;
|
|
628
|
-
content: string;
|
|
629
|
-
summary: string;
|
|
630
|
-
tags: string[];
|
|
631
|
-
sourceAgentId: string;
|
|
632
|
-
sourceMemoryId?: string;
|
|
633
|
-
confidence: number;
|
|
634
|
-
}): KnowledgeEntry {
|
|
635
|
-
const base = this.bases.get(opts.baseId);
|
|
636
|
-
if (!base) throw new Error(`Knowledge base ${opts.baseId} not found`);
|
|
637
|
-
|
|
638
|
-
// Validate category exists in the base
|
|
639
|
-
const category = base.categories.find(c => c.id === opts.categoryId);
|
|
640
|
-
if (!category) throw new Error(`Category ${opts.categoryId} not found in base ${opts.baseId}`);
|
|
641
|
-
|
|
642
|
-
const now = new Date().toISOString();
|
|
643
|
-
|
|
644
|
-
const entry: KnowledgeEntry = {
|
|
645
|
-
id: uid(),
|
|
646
|
-
baseId: opts.baseId,
|
|
647
|
-
orgId: opts.orgId,
|
|
648
|
-
categoryId: opts.categoryId,
|
|
649
|
-
title: opts.title,
|
|
650
|
-
content: opts.content,
|
|
651
|
-
summary: opts.summary,
|
|
652
|
-
tags: [...opts.tags],
|
|
653
|
-
sourceAgentId: opts.sourceAgentId,
|
|
654
|
-
sourceMemoryId: opts.sourceMemoryId,
|
|
655
|
-
confidence: Math.min(1, Math.max(0, opts.confidence)),
|
|
656
|
-
qualityScore: 0,
|
|
657
|
-
useCount: 0,
|
|
658
|
-
voteUp: 0,
|
|
659
|
-
voteDown: 0,
|
|
660
|
-
status: 'pending',
|
|
661
|
-
createdAt: now,
|
|
662
|
-
updatedAt: now,
|
|
663
|
-
};
|
|
664
|
-
|
|
665
|
-
// Compute initial quality score
|
|
666
|
-
entry.qualityScore = computeQualityScore(entry);
|
|
667
|
-
|
|
668
|
-
this.entries.set(entry.id, entry);
|
|
669
|
-
this.indexEntryAdd(entry);
|
|
670
|
-
|
|
671
|
-
// Update base stats
|
|
672
|
-
base.entryCount = (this.baseEntryIndex.get(opts.baseId)?.size) || 0;
|
|
673
|
-
base.contributorCount = (this.baseContributors.get(opts.baseId)?.size) || 0;
|
|
674
|
-
base.lastContributionAt = now;
|
|
675
|
-
base.updatedAt = now;
|
|
676
|
-
|
|
677
|
-
// Update category entry count
|
|
678
|
-
category.entryCount = this.getEntriesForBase(opts.baseId)
|
|
679
|
-
.filter(e => e.categoryId === opts.categoryId).length;
|
|
680
|
-
|
|
681
|
-
this.persistEntry(entry).catch(() => {});
|
|
682
|
-
this.persistBase(base).catch(() => {});
|
|
683
|
-
return entry;
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
/**
|
|
687
|
-
* Route-friendly contribute: baseId as first arg, entry fields as second arg.
|
|
688
|
-
* Resolves orgId from the base.
|
|
689
|
-
*/
|
|
690
|
-
contributeEntry(baseId: string, opts: {
|
|
691
|
-
categoryId: string;
|
|
692
|
-
title: string;
|
|
693
|
-
content: string;
|
|
694
|
-
summary?: string;
|
|
695
|
-
tags?: string[];
|
|
696
|
-
sourceAgentId?: string;
|
|
697
|
-
sourceMemoryId?: string;
|
|
698
|
-
confidence?: number;
|
|
699
|
-
contributedBy?: string;
|
|
700
|
-
}): KnowledgeEntry {
|
|
701
|
-
const base = this.bases.get(baseId);
|
|
702
|
-
if (!base) throw new Error(`Knowledge base ${baseId} not found`);
|
|
703
|
-
|
|
704
|
-
return this.contribute({
|
|
705
|
-
baseId,
|
|
706
|
-
orgId: base.orgId,
|
|
707
|
-
categoryId: opts.categoryId,
|
|
708
|
-
title: opts.title,
|
|
709
|
-
content: opts.content,
|
|
710
|
-
summary: opts.summary || '',
|
|
711
|
-
tags: opts.tags || [],
|
|
712
|
-
sourceAgentId: opts.sourceAgentId || opts.contributedBy || 'unknown',
|
|
713
|
-
sourceMemoryId: opts.sourceMemoryId,
|
|
714
|
-
confidence: opts.confidence ?? 1.0,
|
|
715
|
-
});
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
getEntry(entryId: string): KnowledgeEntry | undefined {
|
|
719
|
-
return this.entries.get(entryId);
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
listEntries(baseId: string, filters?: {
|
|
723
|
-
categoryId?: string;
|
|
724
|
-
status?: KnowledgeEntry['status'];
|
|
725
|
-
minQuality?: number;
|
|
726
|
-
search?: string;
|
|
727
|
-
limit?: number;
|
|
728
|
-
offset?: number;
|
|
729
|
-
}): { entries: KnowledgeEntry[]; total: number } {
|
|
730
|
-
let results = this.getEntriesForBase(baseId);
|
|
731
|
-
|
|
732
|
-
if (filters?.categoryId) {
|
|
733
|
-
results = results.filter(e => e.categoryId === filters.categoryId);
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
if (filters?.status) {
|
|
737
|
-
results = results.filter(e => e.status === filters.status);
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
if (filters?.minQuality !== undefined) {
|
|
741
|
-
results = results.filter(e => e.qualityScore >= filters.minQuality!);
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
if (filters?.search) {
|
|
745
|
-
const q = filters.search.toLowerCase();
|
|
746
|
-
results = results.filter(e =>
|
|
747
|
-
e.title.toLowerCase().includes(q) ||
|
|
748
|
-
e.content.toLowerCase().includes(q) ||
|
|
749
|
-
e.summary.toLowerCase().includes(q) ||
|
|
750
|
-
e.tags.some(t => t.toLowerCase().includes(q))
|
|
751
|
-
);
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
// Sort by quality score descending
|
|
755
|
-
results.sort((a, b) => b.qualityScore - a.qualityScore);
|
|
756
|
-
|
|
757
|
-
const total = results.length;
|
|
758
|
-
const offset = filters?.offset || 0;
|
|
759
|
-
const limit = filters?.limit || 50;
|
|
760
|
-
const paged = results.slice(offset, offset + limit);
|
|
761
|
-
|
|
762
|
-
return { entries: paged, total };
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
approveEntry(entryId: string, _userId?: string): KnowledgeEntry | undefined {
|
|
766
|
-
const entry = this.entries.get(entryId);
|
|
767
|
-
if (!entry) return undefined;
|
|
768
|
-
entry.status = 'approved';
|
|
769
|
-
entry.updatedAt = new Date().toISOString();
|
|
770
|
-
return entry;
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
rejectEntry(entryId: string, _userId?: string): KnowledgeEntry | undefined {
|
|
774
|
-
const entry = this.entries.get(entryId);
|
|
775
|
-
if (!entry) return undefined;
|
|
776
|
-
entry.status = 'rejected';
|
|
777
|
-
entry.updatedAt = new Date().toISOString();
|
|
778
|
-
return entry;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
archiveEntry(entryId: string, _userId?: string): KnowledgeEntry | undefined {
|
|
782
|
-
const entry = this.entries.get(entryId);
|
|
783
|
-
if (!entry) return undefined;
|
|
784
|
-
entry.status = 'archived';
|
|
785
|
-
entry.updatedAt = new Date().toISOString();
|
|
786
|
-
return entry;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
/**
|
|
790
|
-
* Vote on an entry. Accepts either (entryId, direction) or (entryId, userId, direction).
|
|
791
|
-
*/
|
|
792
|
-
vote(entryId: string, userIdOrDirection: string, directionArg?: 'up' | 'down'): KnowledgeEntry | undefined {
|
|
793
|
-
const entry = this.entries.get(entryId);
|
|
794
|
-
if (!entry) return undefined;
|
|
795
|
-
|
|
796
|
-
const direction: 'up' | 'down' = directionArg ?? (userIdOrDirection as 'up' | 'down');
|
|
797
|
-
|
|
798
|
-
if (direction === 'up') {
|
|
799
|
-
entry.voteUp++;
|
|
800
|
-
} else {
|
|
801
|
-
entry.voteDown++;
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
entry.qualityScore = computeQualityScore(entry);
|
|
805
|
-
entry.updatedAt = new Date().toISOString();
|
|
806
|
-
return entry;
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
/** Legacy alias for vote(). */
|
|
810
|
-
voteEntry(entryId: string, direction: 'up' | 'down'): void {
|
|
811
|
-
this.vote(entryId, direction);
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
recordUsage(entryId: string, _agentId?: string): void {
|
|
815
|
-
const entry = this.entries.get(entryId);
|
|
816
|
-
if (!entry) return;
|
|
817
|
-
|
|
818
|
-
entry.useCount++;
|
|
819
|
-
entry.qualityScore = computeQualityScore(entry);
|
|
820
|
-
entry.updatedAt = new Date().toISOString();
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
// ─── Deduplication ──────────────────────────────────
|
|
824
|
-
|
|
825
|
-
findSimilar(baseId: string, content: string, threshold: number = 0.6): KnowledgeEntry[] {
|
|
826
|
-
const baseEntries = this.getEntriesForBase(baseId);
|
|
827
|
-
const matches: Array<{ entry: KnowledgeEntry; similarity: number }> = [];
|
|
828
|
-
|
|
829
|
-
for (const entry of baseEntries) {
|
|
830
|
-
if (entry.status === 'rejected' || entry.status === 'archived') continue;
|
|
831
|
-
|
|
832
|
-
const similarity = contentSimilarity(content, entry.content);
|
|
833
|
-
if (similarity >= threshold) {
|
|
834
|
-
matches.push({ entry, similarity });
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
// Sort by similarity descending
|
|
839
|
-
matches.sort((a, b) => b.similarity - a.similarity);
|
|
840
|
-
return matches.map(m => m.entry);
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
// ─── Schedules ──────────────────────────────────────
|
|
844
|
-
|
|
845
|
-
/**
|
|
846
|
-
* Create a contribution schedule.
|
|
847
|
-
* Accepts filters with defaults for minConfidence.
|
|
848
|
-
*/
|
|
849
|
-
createSchedule(opts: {
|
|
850
|
-
orgId: string;
|
|
851
|
-
agentId: string;
|
|
852
|
-
baseId: string;
|
|
853
|
-
frequency: ContributionSchedule['frequency'];
|
|
854
|
-
dayOfWeek?: number;
|
|
855
|
-
filters?: Partial<ContributionSchedule['filters']>;
|
|
856
|
-
createdBy?: string;
|
|
857
|
-
}): ContributionSchedule {
|
|
858
|
-
// Validate base exists
|
|
859
|
-
const base = this.bases.get(opts.baseId);
|
|
860
|
-
if (!base) throw new Error(`Knowledge base ${opts.baseId} not found`);
|
|
861
|
-
|
|
862
|
-
// Validate dayOfWeek range
|
|
863
|
-
if (opts.dayOfWeek !== undefined && (opts.dayOfWeek < 0 || opts.dayOfWeek > 6)) {
|
|
864
|
-
throw new Error('dayOfWeek must be between 0 (Sunday) and 6 (Saturday)');
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
const filters = opts.filters || {};
|
|
868
|
-
|
|
869
|
-
const schedule: ContributionSchedule = {
|
|
870
|
-
id: uid(),
|
|
871
|
-
orgId: opts.orgId,
|
|
872
|
-
agentId: opts.agentId,
|
|
873
|
-
baseId: opts.baseId,
|
|
874
|
-
frequency: opts.frequency,
|
|
875
|
-
dayOfWeek: opts.dayOfWeek,
|
|
876
|
-
nextRunAt: computeNextRunAt(opts.frequency, opts.dayOfWeek),
|
|
877
|
-
enabled: true,
|
|
878
|
-
filters: {
|
|
879
|
-
minConfidence: filters.minConfidence ?? 0.5,
|
|
880
|
-
categories: filters.categories,
|
|
881
|
-
minImportance: filters.minImportance,
|
|
882
|
-
},
|
|
883
|
-
createdAt: new Date().toISOString(),
|
|
884
|
-
};
|
|
885
|
-
|
|
886
|
-
this.schedules.set(schedule.id, schedule);
|
|
887
|
-
this.agentScheduleIndex.set(opts.agentId, schedule.id);
|
|
888
|
-
|
|
889
|
-
return schedule;
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
/** Get a schedule by agent ID. */
|
|
893
|
-
getSchedule(agentId: string): ContributionSchedule | undefined {
|
|
894
|
-
const scheduleId = this.agentScheduleIndex.get(agentId);
|
|
895
|
-
if (!scheduleId) return undefined;
|
|
896
|
-
return this.schedules.get(scheduleId);
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
/** Alias used by routes. */
|
|
900
|
-
getScheduleForAgent(agentId: string): ContributionSchedule | undefined {
|
|
901
|
-
return this.getSchedule(agentId);
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
listSchedules(orgId: string): ContributionSchedule[] {
|
|
905
|
-
return Array.from(this.schedules.values()).filter(s => s.orgId === orgId);
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
updateSchedule(
|
|
909
|
-
scheduleId: string,
|
|
910
|
-
updates: Partial<Pick<ContributionSchedule, 'frequency' | 'dayOfWeek' | 'enabled' | 'filters'>>,
|
|
911
|
-
_userId?: string,
|
|
912
|
-
): ContributionSchedule | undefined {
|
|
913
|
-
const schedule = this.schedules.get(scheduleId);
|
|
914
|
-
if (!schedule) return undefined;
|
|
915
|
-
|
|
916
|
-
if (updates.frequency !== undefined) {
|
|
917
|
-
schedule.frequency = updates.frequency;
|
|
918
|
-
schedule.nextRunAt = computeNextRunAt(updates.frequency, updates.dayOfWeek ?? schedule.dayOfWeek);
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
if (updates.dayOfWeek !== undefined) {
|
|
922
|
-
if (updates.dayOfWeek < 0 || updates.dayOfWeek > 6) {
|
|
923
|
-
throw new Error('dayOfWeek must be between 0 (Sunday) and 6 (Saturday)');
|
|
924
|
-
}
|
|
925
|
-
schedule.dayOfWeek = updates.dayOfWeek;
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
if (updates.enabled !== undefined) {
|
|
929
|
-
schedule.enabled = updates.enabled;
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
if (updates.filters !== undefined) {
|
|
933
|
-
schedule.filters = { ...schedule.filters, ...updates.filters };
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
return schedule;
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
deleteSchedule(scheduleId: string, _userId?: string): void {
|
|
940
|
-
const schedule = this.schedules.get(scheduleId);
|
|
941
|
-
if (!schedule) return;
|
|
942
|
-
|
|
943
|
-
this.agentScheduleIndex.delete(schedule.agentId);
|
|
944
|
-
this.schedules.delete(scheduleId);
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
// ─── Contribution Cycles ────────────────────────────
|
|
948
|
-
|
|
949
|
-
async runContributionCycle(agentId: string): Promise<ContributionCycle> {
|
|
950
|
-
const schedule = this.getSchedule(agentId);
|
|
951
|
-
if (!schedule) throw new Error(`No contribution schedule found for agent ${agentId}`);
|
|
952
|
-
|
|
953
|
-
const base = this.bases.get(schedule.baseId);
|
|
954
|
-
if (!base) throw new Error(`Knowledge base ${schedule.baseId} not found`);
|
|
955
|
-
|
|
956
|
-
const now = new Date().toISOString();
|
|
957
|
-
const cycle: ContributionCycle = {
|
|
958
|
-
id: uid(),
|
|
959
|
-
orgId: schedule.orgId,
|
|
960
|
-
agentId,
|
|
961
|
-
baseId: schedule.baseId,
|
|
962
|
-
scheduleId: schedule.id,
|
|
963
|
-
status: 'running',
|
|
964
|
-
memoriesScanned: 0,
|
|
965
|
-
entriesContributed: 0,
|
|
966
|
-
duplicatesSkipped: 0,
|
|
967
|
-
startedAt: now,
|
|
968
|
-
};
|
|
969
|
-
|
|
970
|
-
this.cycles.set(cycle.id, cycle);
|
|
971
|
-
|
|
972
|
-
try {
|
|
973
|
-
// Fetch memories via callback
|
|
974
|
-
if (!this.memoryCallback) {
|
|
975
|
-
throw new Error('No memory callback configured — cannot fetch agent memories');
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
const memories = await this.memoryCallback(agentId);
|
|
979
|
-
cycle.memoriesScanned = memories.length;
|
|
980
|
-
|
|
981
|
-
// Filter memories based on schedule criteria
|
|
982
|
-
let filtered = memories.filter(m => m.confidence >= schedule.filters.minConfidence);
|
|
983
|
-
|
|
984
|
-
if (schedule.filters.minImportance) {
|
|
985
|
-
const importanceLevels: Record<string, number> = {
|
|
986
|
-
low: 1,
|
|
987
|
-
normal: 2,
|
|
988
|
-
high: 3,
|
|
989
|
-
critical: 4,
|
|
990
|
-
};
|
|
991
|
-
const minLevel = importanceLevels[schedule.filters.minImportance] || 0;
|
|
992
|
-
filtered = filtered.filter(m => (importanceLevels[m.importance] || 0) >= minLevel);
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
if (schedule.filters.categories && schedule.filters.categories.length > 0) {
|
|
996
|
-
filtered = filtered.filter(m => schedule.filters.categories!.includes(m.category));
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
// Process each filtered memory
|
|
1000
|
-
for (const memory of filtered) {
|
|
1001
|
-
// Check for duplicates via content similarity
|
|
1002
|
-
const similars = this.findSimilar(schedule.baseId, memory.content, 0.6);
|
|
1003
|
-
if (similars.length > 0) {
|
|
1004
|
-
cycle.duplicatesSkipped++;
|
|
1005
|
-
continue;
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
// Determine best category match from the base categories
|
|
1009
|
-
const categoryId = this.matchCategory(memory, base.categories);
|
|
1010
|
-
|
|
1011
|
-
// Generate a summary from the content (first 200 chars or full content if shorter)
|
|
1012
|
-
const summary = memory.content.length > 200
|
|
1013
|
-
? memory.content.slice(0, 200).replace(/\s+\S*$/, '') + '...'
|
|
1014
|
-
: memory.content;
|
|
1015
|
-
|
|
1016
|
-
try {
|
|
1017
|
-
this.contribute({
|
|
1018
|
-
baseId: schedule.baseId,
|
|
1019
|
-
orgId: schedule.orgId,
|
|
1020
|
-
categoryId,
|
|
1021
|
-
title: memory.title,
|
|
1022
|
-
content: memory.content,
|
|
1023
|
-
summary,
|
|
1024
|
-
tags: memory.tags || [],
|
|
1025
|
-
sourceAgentId: agentId,
|
|
1026
|
-
sourceMemoryId: memory.id,
|
|
1027
|
-
confidence: memory.confidence,
|
|
1028
|
-
});
|
|
1029
|
-
|
|
1030
|
-
cycle.entriesContributed++;
|
|
1031
|
-
} catch (err: any) {
|
|
1032
|
-
// Log but continue with remaining memories
|
|
1033
|
-
console.error(`[knowledge-contribution] Failed to contribute memory ${memory.id}:`, err.message);
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
cycle.status = 'completed';
|
|
1038
|
-
cycle.completedAt = new Date().toISOString();
|
|
1039
|
-
|
|
1040
|
-
// Update schedule timestamps
|
|
1041
|
-
schedule.lastRunAt = now;
|
|
1042
|
-
schedule.nextRunAt = computeNextRunAt(schedule.frequency, schedule.dayOfWeek);
|
|
1043
|
-
|
|
1044
|
-
} catch (err: any) {
|
|
1045
|
-
cycle.status = 'failed';
|
|
1046
|
-
cycle.error = err.message;
|
|
1047
|
-
cycle.completedAt = new Date().toISOString();
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
return cycle;
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
/** Alias used by routes: trigger a contribution cycle for an agent. */
|
|
1054
|
-
async triggerContribution(agentId: string, _userId?: string): Promise<ContributionCycle> {
|
|
1055
|
-
return this.runContributionCycle(agentId);
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
/** Find the best-matching category in a base for a given memory item. */
|
|
1059
|
-
private matchCategory(memory: MemoryItem, categories: KnowledgeCategory[]): string {
|
|
1060
|
-
if (categories.length === 0) return 'general';
|
|
1061
|
-
|
|
1062
|
-
// Try matching memory category/tags against base category IDs and names
|
|
1063
|
-
const memCat = memory.category.toLowerCase();
|
|
1064
|
-
const memTitle = memory.title.toLowerCase();
|
|
1065
|
-
const memTags = memory.tags.map(t => t.toLowerCase());
|
|
1066
|
-
|
|
1067
|
-
let bestMatch: string | undefined;
|
|
1068
|
-
let bestScore = 0;
|
|
1069
|
-
|
|
1070
|
-
for (const cat of categories) {
|
|
1071
|
-
let score = 0;
|
|
1072
|
-
const catId = cat.id.toLowerCase();
|
|
1073
|
-
const catName = cat.name.toLowerCase();
|
|
1074
|
-
const catDesc = cat.description.toLowerCase();
|
|
1075
|
-
|
|
1076
|
-
// Direct category match
|
|
1077
|
-
if (memCat.includes(catId) || catId.includes(memCat)) score += 3;
|
|
1078
|
-
|
|
1079
|
-
// Title overlap
|
|
1080
|
-
if (memTitle.includes(catId) || memTitle.includes(catName)) score += 2;
|
|
1081
|
-
|
|
1082
|
-
// Tag matches
|
|
1083
|
-
for (const tag of memTags) {
|
|
1084
|
-
if (catId.includes(tag) || catName.includes(tag) || tag.includes(catId)) score += 1;
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
// Description keyword overlap
|
|
1088
|
-
const descWords = catDesc.split(/\s+/).filter(w => w.length > 3);
|
|
1089
|
-
for (const word of descWords) {
|
|
1090
|
-
if (memTitle.includes(word) || memory.content.toLowerCase().includes(word)) score += 0.5;
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
if (score > bestScore) {
|
|
1094
|
-
bestScore = score;
|
|
1095
|
-
bestMatch = cat.id;
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
// Fall back to the first category if no meaningful match found
|
|
1100
|
-
return bestMatch || categories[0].id;
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
checkDueSchedules(): ContributionSchedule[] {
|
|
1104
|
-
const now = new Date().toISOString();
|
|
1105
|
-
return Array.from(this.schedules.values()).filter(s =>
|
|
1106
|
-
s.enabled && s.nextRunAt <= now
|
|
1107
|
-
);
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
async runDueContributions(): Promise<ContributionCycle[]> {
|
|
1111
|
-
const due = this.checkDueSchedules();
|
|
1112
|
-
const results: ContributionCycle[] = [];
|
|
1113
|
-
|
|
1114
|
-
for (const schedule of due) {
|
|
1115
|
-
try {
|
|
1116
|
-
const cycle = await this.runContributionCycle(schedule.agentId);
|
|
1117
|
-
results.push(cycle);
|
|
1118
|
-
} catch (err: any) {
|
|
1119
|
-
console.error(`[knowledge-contribution] Failed contribution cycle for agent ${schedule.agentId}:`, err.message);
|
|
1120
|
-
const failedCycle: ContributionCycle = {
|
|
1121
|
-
id: uid(),
|
|
1122
|
-
orgId: schedule.orgId,
|
|
1123
|
-
agentId: schedule.agentId,
|
|
1124
|
-
baseId: schedule.baseId,
|
|
1125
|
-
scheduleId: schedule.id,
|
|
1126
|
-
status: 'failed',
|
|
1127
|
-
memoriesScanned: 0,
|
|
1128
|
-
entriesContributed: 0,
|
|
1129
|
-
duplicatesSkipped: 0,
|
|
1130
|
-
startedAt: new Date().toISOString(),
|
|
1131
|
-
completedAt: new Date().toISOString(),
|
|
1132
|
-
error: err.message,
|
|
1133
|
-
};
|
|
1134
|
-
this.cycles.set(failedCycle.id, failedCycle);
|
|
1135
|
-
results.push(failedCycle);
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
return results;
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
/** Alias used by routes. */
|
|
1143
|
-
async runDueCycles(_userId?: string): Promise<{ cyclesRun: number; completed: number; failed: number; cycles: ContributionCycle[] }> {
|
|
1144
|
-
const cycles = await this.runDueContributions();
|
|
1145
|
-
return {
|
|
1146
|
-
cyclesRun: cycles.length,
|
|
1147
|
-
completed: cycles.filter(c => c.status === 'completed').length,
|
|
1148
|
-
failed: cycles.filter(c => c.status === 'failed').length,
|
|
1149
|
-
cycles,
|
|
1150
|
-
};
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
/** List contribution cycles with optional filters. */
|
|
1154
|
-
listCycles(opts?: { orgId?: string; agentId?: string; limit?: number }): ContributionCycle[] {
|
|
1155
|
-
let results = Array.from(this.cycles.values());
|
|
1156
|
-
|
|
1157
|
-
if (opts?.orgId) {
|
|
1158
|
-
results = results.filter(c => c.orgId === opts.orgId);
|
|
1159
|
-
}
|
|
1160
|
-
if (opts?.agentId) {
|
|
1161
|
-
results = results.filter(c => c.agentId === opts.agentId);
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
// Sort by startedAt descending (most recent first)
|
|
1165
|
-
results.sort((a, b) => b.startedAt.localeCompare(a.startedAt));
|
|
1166
|
-
|
|
1167
|
-
const limit = opts?.limit || 50;
|
|
1168
|
-
return results.slice(0, limit);
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
// ─── Bootstrap ──────────────────────────────────────
|
|
1172
|
-
|
|
1173
|
-
getBootstrapKnowledge(role: string, opts?: {
|
|
1174
|
-
categories?: string[];
|
|
1175
|
-
minQuality?: number;
|
|
1176
|
-
limit?: number;
|
|
1177
|
-
}): KnowledgeEntry[] {
|
|
1178
|
-
const minQuality = opts?.minQuality ?? 0.4;
|
|
1179
|
-
const limit = opts?.limit ?? 50;
|
|
1180
|
-
|
|
1181
|
-
// Find all bases matching the role across all orgs
|
|
1182
|
-
const matchingBases = Array.from(this.bases.values()).filter(b => b.role === role);
|
|
1183
|
-
|
|
1184
|
-
let entries: KnowledgeEntry[] = [];
|
|
1185
|
-
for (const base of matchingBases) {
|
|
1186
|
-
const baseEntries = this.getEntriesForBase(base.id);
|
|
1187
|
-
entries.push(...baseEntries);
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
// Filter to approved/pending entries with sufficient quality
|
|
1191
|
-
entries = entries.filter(e =>
|
|
1192
|
-
(e.status === 'approved' || e.status === 'pending') &&
|
|
1193
|
-
e.qualityScore >= minQuality
|
|
1194
|
-
);
|
|
1195
|
-
|
|
1196
|
-
// Filter by categories if specified
|
|
1197
|
-
if (opts?.categories && opts.categories.length > 0) {
|
|
1198
|
-
entries = entries.filter(e => opts.categories!.includes(e.categoryId));
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
// Sort by quality score descending
|
|
1202
|
-
entries.sort((a, b) => b.qualityScore - a.qualityScore);
|
|
1203
|
-
|
|
1204
|
-
return entries.slice(0, limit);
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
// ─── Stats ──────────────────────────────────────────
|
|
1208
|
-
|
|
1209
|
-
getStats(orgId?: string): {
|
|
1210
|
-
totalBases: number;
|
|
1211
|
-
totalEntries: number;
|
|
1212
|
-
totalContributors: number;
|
|
1213
|
-
topCategories: Array<{ categoryId: string; count: number }>;
|
|
1214
|
-
recentContributions: KnowledgeEntry[];
|
|
1215
|
-
} {
|
|
1216
|
-
// If no orgId, aggregate across all orgs
|
|
1217
|
-
const allBases = orgId
|
|
1218
|
-
? Array.from(this.bases.values()).filter(b => b.orgId === orgId)
|
|
1219
|
-
: Array.from(this.bases.values());
|
|
1220
|
-
const baseIds = new Set(allBases.map(b => b.id));
|
|
1221
|
-
|
|
1222
|
-
// Collect all entries
|
|
1223
|
-
const allEntries: KnowledgeEntry[] = [];
|
|
1224
|
-
for (const baseId of baseIds) {
|
|
1225
|
-
allEntries.push(...this.getEntriesForBase(baseId));
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
// Count unique contributors
|
|
1229
|
-
const contributors = new Set<string>();
|
|
1230
|
-
for (const baseId of baseIds) {
|
|
1231
|
-
const c = this.baseContributors.get(baseId);
|
|
1232
|
-
if (c) for (const agentId of c) contributors.add(agentId);
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
// Top categories
|
|
1236
|
-
const categoryCounts = new Map<string, number>();
|
|
1237
|
-
for (const entry of allEntries) {
|
|
1238
|
-
categoryCounts.set(entry.categoryId, (categoryCounts.get(entry.categoryId) || 0) + 1);
|
|
1239
|
-
}
|
|
1240
|
-
const topCategories = Array.from(categoryCounts.entries())
|
|
1241
|
-
.map(([categoryId, count]) => ({ categoryId, count }))
|
|
1242
|
-
.sort((a, b) => b.count - a.count)
|
|
1243
|
-
.slice(0, 10);
|
|
1244
|
-
|
|
1245
|
-
// Recent contributions (last 20)
|
|
1246
|
-
const recentContributions = [...allEntries]
|
|
1247
|
-
.sort((a, b) => b.createdAt.localeCompare(a.createdAt))
|
|
1248
|
-
.slice(0, 20);
|
|
1249
|
-
|
|
1250
|
-
return {
|
|
1251
|
-
totalBases: allBases.length,
|
|
1252
|
-
totalEntries: allEntries.length,
|
|
1253
|
-
totalContributors: contributors.size,
|
|
1254
|
-
topCategories,
|
|
1255
|
-
recentContributions,
|
|
1256
|
-
};
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
getAgentContributions(agentId: string): {
|
|
1260
|
-
totalContributed: number;
|
|
1261
|
-
totalUsed: number;
|
|
1262
|
-
avgQuality: number;
|
|
1263
|
-
categories: Array<{ categoryId: string; count: number }>;
|
|
1264
|
-
} {
|
|
1265
|
-
const entries = this.getEntriesForAgent(agentId);
|
|
1266
|
-
|
|
1267
|
-
const totalUsed = entries.reduce((sum, e) => sum + e.useCount, 0);
|
|
1268
|
-
const avgQuality = entries.length > 0
|
|
1269
|
-
? parseFloat((entries.reduce((sum, e) => sum + e.qualityScore, 0) / entries.length).toFixed(4))
|
|
1270
|
-
: 0;
|
|
1271
|
-
|
|
1272
|
-
const categoryCounts = new Map<string, number>();
|
|
1273
|
-
for (const entry of entries) {
|
|
1274
|
-
categoryCounts.set(entry.categoryId, (categoryCounts.get(entry.categoryId) || 0) + 1);
|
|
1275
|
-
}
|
|
1276
|
-
const categories = Array.from(categoryCounts.entries())
|
|
1277
|
-
.map(([categoryId, count]) => ({ categoryId, count }))
|
|
1278
|
-
.sort((a, b) => b.count - a.count);
|
|
1279
|
-
|
|
1280
|
-
return {
|
|
1281
|
-
totalContributed: entries.length,
|
|
1282
|
-
totalUsed,
|
|
1283
|
-
avgQuality,
|
|
1284
|
-
categories,
|
|
1285
|
-
};
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
/** Alias used by routes. */
|
|
1289
|
-
getAgentStats(agentId: string): {
|
|
1290
|
-
totalContributed: number;
|
|
1291
|
-
totalUsed: number;
|
|
1292
|
-
avgQuality: number;
|
|
1293
|
-
categories: Array<{ categoryId: string; count: number }>;
|
|
1294
|
-
} {
|
|
1295
|
-
return this.getAgentContributions(agentId);
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
// ─── Maintenance ────────────────────────────────────
|
|
1299
|
-
|
|
1300
|
-
decayQuality(): { entriesDecayed: number } {
|
|
1301
|
-
const now = Date.now();
|
|
1302
|
-
let entriesDecayed = 0;
|
|
1303
|
-
|
|
1304
|
-
for (const entry of this.entries.values()) {
|
|
1305
|
-
// Skip recently updated entries (less than 30 days old)
|
|
1306
|
-
const ageMs = now - new Date(entry.updatedAt).getTime();
|
|
1307
|
-
const ageDays = ageMs / 86_400_000;
|
|
1308
|
-
if (ageDays < 30) continue;
|
|
1309
|
-
|
|
1310
|
-
// Skip entries that are actively used
|
|
1311
|
-
const usageRate = entry.useCount / Math.max(1, ageDays / 7); // uses per week
|
|
1312
|
-
if (usageRate >= 1) continue;
|
|
1313
|
-
|
|
1314
|
-
// Decay: reduce quality score by a small amount
|
|
1315
|
-
const decayFactor = 0.95; // 5% decay per maintenance cycle
|
|
1316
|
-
const newQuality = parseFloat((entry.qualityScore * decayFactor).toFixed(4));
|
|
1317
|
-
|
|
1318
|
-
if (newQuality !== entry.qualityScore) {
|
|
1319
|
-
entry.qualityScore = newQuality;
|
|
1320
|
-
entry.updatedAt = new Date().toISOString();
|
|
1321
|
-
entriesDecayed++;
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
return { entriesDecayed };
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
/** Alias used by routes. */
|
|
1329
|
-
runQualityDecay(_userId?: string): { entriesDecayed: number } {
|
|
1330
|
-
return this.decayQuality();
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
archiveStale(maxAgeDays: number = 365): number {
|
|
1334
|
-
const cutoff = new Date(Date.now() - maxAgeDays * 86_400_000).toISOString();
|
|
1335
|
-
let archived = 0;
|
|
1336
|
-
|
|
1337
|
-
for (const entry of this.entries.values()) {
|
|
1338
|
-
if (entry.status === 'archived' || entry.status === 'rejected') continue;
|
|
1339
|
-
|
|
1340
|
-
// Archive if older than threshold AND low quality AND low usage
|
|
1341
|
-
if (entry.createdAt < cutoff && entry.qualityScore < 0.2 && entry.useCount < 3) {
|
|
1342
|
-
entry.status = 'archived';
|
|
1343
|
-
entry.updatedAt = new Date().toISOString();
|
|
1344
|
-
archived++;
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
|
-
return archived;
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
/** Alias used by routes. */
|
|
1352
|
-
archiveStaleEntries(maxAgeDays: number = 90, _userId?: string): { entriesArchived: number } {
|
|
1353
|
-
const count = this.archiveStale(maxAgeDays);
|
|
1354
|
-
return { entriesArchived: count };
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
// ─── Scheduler ──────────────────────────────────────
|
|
1358
|
-
|
|
1359
|
-
startScheduler(intervalMs: number = 60_000): void {
|
|
1360
|
-
this.stopScheduler();
|
|
1361
|
-
|
|
1362
|
-
this.schedulerTimer = setInterval(() => {
|
|
1363
|
-
this.runDueContributions().then(cycles => {
|
|
1364
|
-
if (cycles.length > 0) {
|
|
1365
|
-
const succeeded = cycles.filter(c => c.status === 'completed').length;
|
|
1366
|
-
const failed = cycles.filter(c => c.status === 'failed').length;
|
|
1367
|
-
console.log(`[knowledge-contribution] Ran ${cycles.length} contribution cycles: ${succeeded} completed, ${failed} failed`);
|
|
1368
|
-
}
|
|
1369
|
-
}).catch(err => {
|
|
1370
|
-
console.error('[knowledge-contribution] Scheduler error:', err.message);
|
|
1371
|
-
});
|
|
1372
|
-
}, intervalMs);
|
|
1373
|
-
|
|
1374
|
-
// Don't block process exit
|
|
1375
|
-
if (this.schedulerTimer && typeof this.schedulerTimer === 'object' && 'unref' in this.schedulerTimer) {
|
|
1376
|
-
this.schedulerTimer.unref();
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
stopScheduler(): void {
|
|
1381
|
-
if (this.schedulerTimer) {
|
|
1382
|
-
clearInterval(this.schedulerTimer);
|
|
1383
|
-
this.schedulerTimer = undefined;
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
}
|