botinabox 2.4.2 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +190 -190
- package/bin/botinabox.mjs +2 -2
- package/dist/channels/slack/index.d.ts +1 -1
- package/dist/{chat-pipeline-BWrtVqEP.d.ts → chat-pipeline-DuNX5WoL.d.ts} +3 -0
- package/dist/cli.js +0 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +64 -27
- package/package.json +100 -99
- package/dist/channels/discord/adapter.d.ts +0 -32
- package/dist/channels/discord/adapter.js +0 -70
- package/dist/channels/discord/inbound.d.ts +0 -25
- package/dist/channels/discord/inbound.js +0 -24
- package/dist/channels/discord/models.d.ts +0 -8
- package/dist/channels/discord/models.js +0 -5
- package/dist/channels/discord/outbound.d.ts +0 -14
- package/dist/channels/discord/outbound.js +0 -38
- package/dist/channels/slack/adapter.d.ts +0 -33
- package/dist/channels/slack/adapter.js +0 -74
- package/dist/channels/slack/inbound.d.ts +0 -59
- package/dist/channels/slack/inbound.js +0 -96
- package/dist/channels/slack/models.d.ts +0 -9
- package/dist/channels/slack/models.js +0 -5
- package/dist/channels/slack/outbound.d.ts +0 -12
- package/dist/channels/slack/outbound.js +0 -18
- package/dist/channels/slack/transcribe.d.ts +0 -41
- package/dist/channels/slack/transcribe.js +0 -106
- package/dist/channels/webhook/adapter.d.ts +0 -23
- package/dist/channels/webhook/adapter.js +0 -86
- package/dist/channels/webhook/hmac.d.ts +0 -13
- package/dist/channels/webhook/hmac.js +0 -26
- package/dist/channels/webhook/models.d.ts +0 -9
- package/dist/channels/webhook/models.js +0 -5
- package/dist/channels/webhook/server.d.ts +0 -20
- package/dist/channels/webhook/server.js +0 -91
- package/dist/chat-pipeline-C-XlLGNl.d.ts +0 -648
- package/dist/chat-pipeline-CR1KF6eX.d.ts +0 -652
- package/dist/chat-pipeline-DisuC8SB.d.ts +0 -643
- package/dist/chunk-2LGXQPEA.js +0 -41
- package/dist/chunk-3X3YKI4T.js +0 -357
- package/dist/chunk-D47AIFOD.js +0 -351
- package/dist/chunk-DSNJKNEW.js +0 -328
- package/dist/chunk-GS2JFL6I.js +0 -144
- package/dist/chunk-J6S6QMUY.js +0 -144
- package/dist/chunk-QLA6YOFN.js +0 -22
- package/dist/chunk-UACT2WXX.js +0 -381
- package/dist/cli/templates/config.yml.d.ts +0 -7
- package/dist/cli/templates/config.yml.js +0 -61
- package/dist/cli/templates/env.d.ts +0 -1
- package/dist/cli/templates/env.js +0 -30
- package/dist/cli/templates/index.ts.d.ts +0 -2
- package/dist/cli/templates/index.ts.js +0 -30
- package/dist/cli/templates/package.json.d.ts +0 -5
- package/dist/cli/templates/package.json.js +0 -28
- package/dist/connector-DDahQw-2.d.ts +0 -63
- package/dist/connectors/google/calendar-connector.d.ts +0 -40
- package/dist/connectors/google/calendar-connector.js +0 -243
- package/dist/connectors/google/gmail-connector.d.ts +0 -42
- package/dist/connectors/google/gmail-connector.js +0 -345
- package/dist/connectors/google/oauth.d.ts +0 -48
- package/dist/connectors/google/oauth.js +0 -112
- package/dist/connectors/google/types.d.ts +0 -78
- package/dist/connectors/google/types.js +0 -2
- package/dist/core/chat/auto-discovery.d.ts +0 -16
- package/dist/core/chat/auto-discovery.js +0 -54
- package/dist/core/chat/channel-registry.d.ts +0 -45
- package/dist/core/chat/channel-registry.js +0 -96
- package/dist/core/chat/chat-pipeline.d.ts +0 -113
- package/dist/core/chat/chat-pipeline.js +0 -395
- package/dist/core/chat/chat-responder.d.ts +0 -90
- package/dist/core/chat/chat-responder.js +0 -185
- package/dist/core/chat/formatter.d.ts +0 -11
- package/dist/core/chat/formatter.js +0 -60
- package/dist/core/chat/index.d.ts +0 -24
- package/dist/core/chat/index.js +0 -18
- package/dist/core/chat/message-interpreter.d.ts +0 -91
- package/dist/core/chat/message-interpreter.js +0 -166
- package/dist/core/chat/message-store.d.ts +0 -66
- package/dist/core/chat/message-store.js +0 -131
- package/dist/core/chat/notification-queue.d.ts +0 -34
- package/dist/core/chat/notification-queue.js +0 -111
- package/dist/core/chat/pipeline.d.ts +0 -38
- package/dist/core/chat/pipeline.js +0 -89
- package/dist/core/chat/policies.d.ts +0 -16
- package/dist/core/chat/policies.js +0 -25
- package/dist/core/chat/routing.d.ts +0 -17
- package/dist/core/chat/routing.js +0 -36
- package/dist/core/chat/session-key.d.ts +0 -30
- package/dist/core/chat/session-key.js +0 -65
- package/dist/core/chat/session-manager.d.ts +0 -17
- package/dist/core/chat/session-manager.js +0 -23
- package/dist/core/chat/text-chunker.d.ts +0 -9
- package/dist/core/chat/text-chunker.js +0 -48
- package/dist/core/chat/triage-router.d.ts +0 -75
- package/dist/core/chat/triage-router.js +0 -142
- package/dist/core/chat/types.d.ts +0 -5
- package/dist/core/chat/types.js +0 -5
- package/dist/core/config/defaults.d.ts +0 -2
- package/dist/core/config/defaults.js +0 -38
- package/dist/core/config/index.d.ts +0 -6
- package/dist/core/config/index.js +0 -4
- package/dist/core/config/interpolate.d.ts +0 -5
- package/dist/core/config/interpolate.js +0 -27
- package/dist/core/config/loader.d.ts +0 -24
- package/dist/core/config/loader.js +0 -59
- package/dist/core/config/schema.d.ts +0 -5
- package/dist/core/config/schema.js +0 -119
- package/dist/core/data/core-entity-contexts.d.ts +0 -14
- package/dist/core/data/core-entity-contexts.js +0 -197
- package/dist/core/data/core-migrations.d.ts +0 -5
- package/dist/core/data/core-migrations.js +0 -45
- package/dist/core/data/core-schema.d.ts +0 -6
- package/dist/core/data/core-schema.js +0 -454
- package/dist/core/data/data-store.d.ts +0 -67
- package/dist/core/data/data-store.js +0 -218
- package/dist/core/data/domain-entity-contexts.d.ts +0 -29
- package/dist/core/data/domain-entity-contexts.js +0 -321
- package/dist/core/data/domain-schema.d.ts +0 -36
- package/dist/core/data/domain-schema.js +0 -323
- package/dist/core/data/index.d.ts +0 -7
- package/dist/core/data/index.js +0 -7
- package/dist/core/data/types.d.ts +0 -111
- package/dist/core/data/types.js +0 -1
- package/dist/core/hooks/hook-bus.d.ts +0 -18
- package/dist/core/hooks/hook-bus.js +0 -120
- package/dist/core/hooks/index.d.ts +0 -2
- package/dist/core/hooks/index.js +0 -1
- package/dist/core/hooks/types.d.ts +0 -19
- package/dist/core/hooks/types.js +0 -1
- package/dist/core/index.d.ts +0 -4
- package/dist/core/index.js +0 -4
- package/dist/core/llm/auto-discovery.d.ts +0 -11
- package/dist/core/llm/auto-discovery.js +0 -49
- package/dist/core/llm/cost-tracker.d.ts +0 -6
- package/dist/core/llm/cost-tracker.js +0 -38
- package/dist/core/llm/index.d.ts +0 -4
- package/dist/core/llm/index.js +0 -3
- package/dist/core/llm/model-router.d.ts +0 -25
- package/dist/core/llm/model-router.js +0 -49
- package/dist/core/llm/provider-registry.d.ts +0 -9
- package/dist/core/llm/provider-registry.js +0 -25
- package/dist/core/llm/types.d.ts +0 -2
- package/dist/core/llm/types.js +0 -2
- package/dist/core/orchestrator/adapters/api-adapter.d.ts +0 -34
- package/dist/core/orchestrator/adapters/api-adapter.js +0 -88
- package/dist/core/orchestrator/adapters/cli-adapter.d.ts +0 -22
- package/dist/core/orchestrator/adapters/cli-adapter.js +0 -69
- package/dist/core/orchestrator/adapters/deterministic-adapter.d.ts +0 -35
- package/dist/core/orchestrator/adapters/deterministic-adapter.js +0 -75
- package/dist/core/orchestrator/adapters/env-whitelist.d.ts +0 -4
- package/dist/core/orchestrator/adapters/env-whitelist.js +0 -27
- package/dist/core/orchestrator/adapters/output-extractor.d.ts +0 -11
- package/dist/core/orchestrator/adapters/output-extractor.js +0 -59
- package/dist/core/orchestrator/adapters/process-manager.d.ts +0 -15
- package/dist/core/orchestrator/adapters/process-manager.js +0 -26
- package/dist/core/orchestrator/adapters/tool-loop.d.ts +0 -22
- package/dist/core/orchestrator/adapters/tool-loop.js +0 -66
- package/dist/core/orchestrator/agent-registry.d.ts +0 -31
- package/dist/core/orchestrator/agent-registry.js +0 -135
- package/dist/core/orchestrator/budget-controller.d.ts +0 -19
- package/dist/core/orchestrator/budget-controller.js +0 -73
- package/dist/core/orchestrator/chain-guard.d.ts +0 -14
- package/dist/core/orchestrator/chain-guard.js +0 -23
- package/dist/core/orchestrator/circuit-breaker.d.ts +0 -65
- package/dist/core/orchestrator/circuit-breaker.js +0 -159
- package/dist/core/orchestrator/claude-stream-parser.d.ts +0 -31
- package/dist/core/orchestrator/claude-stream-parser.js +0 -99
- package/dist/core/orchestrator/config-revisions.d.ts +0 -6
- package/dist/core/orchestrator/config-revisions.js +0 -17
- package/dist/core/orchestrator/dependency-resolver.d.ts +0 -20
- package/dist/core/orchestrator/dependency-resolver.js +0 -78
- package/dist/core/orchestrator/governance-gate.d.ts +0 -110
- package/dist/core/orchestrator/governance-gate.js +0 -170
- package/dist/core/orchestrator/learning-pipeline.d.ts +0 -109
- package/dist/core/orchestrator/learning-pipeline.js +0 -249
- package/dist/core/orchestrator/loop-detector.d.ts +0 -51
- package/dist/core/orchestrator/loop-detector.js +0 -133
- package/dist/core/orchestrator/ndjson-logger.d.ts +0 -6
- package/dist/core/orchestrator/ndjson-logger.js +0 -18
- package/dist/core/orchestrator/permission-relay.d.ts +0 -72
- package/dist/core/orchestrator/permission-relay.js +0 -164
- package/dist/core/orchestrator/run-manager.d.ts +0 -31
- package/dist/core/orchestrator/run-manager.js +0 -178
- package/dist/core/orchestrator/scheduler.d.ts +0 -70
- package/dist/core/orchestrator/scheduler.js +0 -198
- package/dist/core/orchestrator/secret-store.d.ts +0 -57
- package/dist/core/orchestrator/secret-store.js +0 -171
- package/dist/core/orchestrator/session-manager.d.ts +0 -13
- package/dist/core/orchestrator/session-manager.js +0 -66
- package/dist/core/orchestrator/task-queue.d.ts +0 -34
- package/dist/core/orchestrator/task-queue.js +0 -83
- package/dist/core/orchestrator/template-interpolate.d.ts +0 -5
- package/dist/core/orchestrator/template-interpolate.js +0 -18
- package/dist/core/orchestrator/user-registry.d.ts +0 -47
- package/dist/core/orchestrator/user-registry.js +0 -76
- package/dist/core/orchestrator/wakeup-queue.d.ts +0 -9
- package/dist/core/orchestrator/wakeup-queue.js +0 -45
- package/dist/core/orchestrator/workflow-engine.d.ts +0 -47
- package/dist/core/orchestrator/workflow-engine.js +0 -204
- package/dist/core/security/audit.d.ts +0 -20
- package/dist/core/security/audit.js +0 -33
- package/dist/core/security/column-validator.d.ts +0 -20
- package/dist/core/security/column-validator.js +0 -37
- package/dist/core/security/index.d.ts +0 -5
- package/dist/core/security/index.js +0 -5
- package/dist/core/security/process-env.d.ts +0 -13
- package/dist/core/security/process-env.js +0 -49
- package/dist/core/security/sanitizer.d.ts +0 -11
- package/dist/core/security/sanitizer.js +0 -39
- package/dist/core/security/types.d.ts +0 -11
- package/dist/core/security/types.js +0 -1
- package/dist/core/update/auto-update.d.ts +0 -21
- package/dist/core/update/auto-update.js +0 -102
- package/dist/core/update/backup-manager.d.ts +0 -7
- package/dist/core/update/backup-manager.js +0 -24
- package/dist/core/update/index.d.ts +0 -8
- package/dist/core/update/index.js +0 -6
- package/dist/core/update/migration-hooks.d.ts +0 -11
- package/dist/core/update/migration-hooks.js +0 -10
- package/dist/core/update/types.d.ts +0 -11
- package/dist/core/update/types.js +0 -1
- package/dist/core/update/update-checker.d.ts +0 -11
- package/dist/core/update/update-checker.js +0 -63
- package/dist/core/update/update-manager.d.ts +0 -25
- package/dist/core/update/update-manager.js +0 -101
- package/dist/core/update/version-utils.d.ts +0 -6
- package/dist/core/update/version-utils.js +0 -34
- package/dist/gmail-connector-2FVYTQJH.js +0 -6
- package/dist/gmail-connector-MNUBRNFM.js +0 -6
- package/dist/gmail-connector-PS2VLGNE.js +0 -6
- package/dist/gmail-connector-ULSMN6X2.js +0 -6
- package/dist/gmail-connector-URRFX6A3.js +0 -6
- package/dist/inbound-AFBUPSPG.js +0 -10
- package/dist/inbound-AFOHYNUY.js +0 -6
- package/dist/inbound-CGIXRXGC.js +0 -8
- package/dist/inbound-MCOLRH6U.js +0 -10
- package/dist/inbound-SNEMBLGA.js +0 -6
- package/dist/inbound-ZJHAYVMF.js +0 -10
- package/dist/provider-qqJYv9nv.d.ts +0 -75
- package/dist/providers/anthropic/models.d.ts +0 -2
- package/dist/providers/anthropic/models.js +0 -29
- package/dist/providers/anthropic/provider.d.ts +0 -13
- package/dist/providers/anthropic/provider.js +0 -119
- package/dist/providers/anthropic/tool-converter.d.ts +0 -10
- package/dist/providers/anthropic/tool-converter.js +0 -7
- package/dist/providers/ollama/provider.d.ts +0 -17
- package/dist/providers/ollama/provider.js +0 -185
- package/dist/providers/openai/models.d.ts +0 -2
- package/dist/providers/openai/models.js +0 -29
- package/dist/providers/openai/provider.d.ts +0 -13
- package/dist/providers/openai/provider.js +0 -163
- package/dist/providers/openai/tool-converter.d.ts +0 -10
- package/dist/providers/openai/tool-converter.js +0 -10
- package/dist/shared/constants.d.ts +0 -50
- package/dist/shared/constants.js +0 -64
- package/dist/shared/index.d.ts +0 -14
- package/dist/shared/index.js +0 -14
- package/dist/shared/types/agent.d.ts +0 -36
- package/dist/shared/types/agent.js +0 -2
- package/dist/shared/types/channel.d.ts +0 -70
- package/dist/shared/types/channel.js +0 -2
- package/dist/shared/types/config.d.ts +0 -111
- package/dist/shared/types/config.js +0 -2
- package/dist/shared/types/connector.d.ts +0 -77
- package/dist/shared/types/connector.js +0 -2
- package/dist/shared/types/execution.d.ts +0 -29
- package/dist/shared/types/execution.js +0 -2
- package/dist/shared/types/provider.d.ts +0 -73
- package/dist/shared/types/provider.js +0 -2
- package/dist/shared/types/task.d.ts +0 -47
- package/dist/shared/types/task.js +0 -2
- package/dist/shared/types/workflow.d.ts +0 -39
- package/dist/shared/types/workflow.js +0 -2
- package/dist/shared/utils.d.ts +0 -6
- package/dist/shared/utils.js +0 -13
- package/dist/update-check.d.ts +0 -5
- package/dist/update-check.js +0 -56
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Google OAuth2 helpers.
|
|
3
|
-
*
|
|
4
|
-
* Uses dynamic `import('googleapis')` so the package is only required
|
|
5
|
-
* at runtime by consumers who actually use the Google connectors.
|
|
6
|
-
*/
|
|
7
|
-
// ── Lazy googleapis import ─────────────────────────────────────────
|
|
8
|
-
let _google;
|
|
9
|
-
async function getGoogle() {
|
|
10
|
-
if (!_google) {
|
|
11
|
-
try {
|
|
12
|
-
const mod = await import('googleapis');
|
|
13
|
-
_google = mod.google;
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
throw new Error('googleapis is required for Google connectors. Install it: npm install googleapis');
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return _google;
|
|
20
|
-
}
|
|
21
|
-
// ── Public helpers ─────────────────────────────────────────────────
|
|
22
|
-
/**
|
|
23
|
-
* Create a Google OAuth2 client from app credentials.
|
|
24
|
-
*/
|
|
25
|
-
export async function createOAuth2Client(config) {
|
|
26
|
-
const google = await getGoogle();
|
|
27
|
-
return new google.auth.OAuth2(config.clientId, config.clientSecret, config.redirectUri);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Generate the consent screen URL for the given scopes.
|
|
31
|
-
*/
|
|
32
|
-
export function getAuthUrl(client, scopes) {
|
|
33
|
-
return client.generateAuthUrl({
|
|
34
|
-
access_type: 'offline',
|
|
35
|
-
prompt: 'consent',
|
|
36
|
-
scope: scopes,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Exchange an authorization code for tokens.
|
|
41
|
-
*/
|
|
42
|
-
export async function exchangeCode(client, code) {
|
|
43
|
-
const { tokens } = await client.getToken(code);
|
|
44
|
-
return tokens;
|
|
45
|
-
}
|
|
46
|
-
// ── Service account auth ──────────────────────────────────────────
|
|
47
|
-
/**
|
|
48
|
-
* Create an authenticated client using a service account with
|
|
49
|
-
* domain-wide delegation (impersonation). No browser flow needed.
|
|
50
|
-
*/
|
|
51
|
-
export async function createServiceAccountClient(config, scopes) {
|
|
52
|
-
const google = await getGoogle();
|
|
53
|
-
const auth = new google.auth.GoogleAuth({
|
|
54
|
-
...(config.keyFile ? { keyFile: config.keyFile } : {}),
|
|
55
|
-
...(config.credentials ? { credentials: config.credentials } : {}),
|
|
56
|
-
scopes,
|
|
57
|
-
clientOptions: { subject: config.subject },
|
|
58
|
-
});
|
|
59
|
-
return auth.getClient();
|
|
60
|
-
}
|
|
61
|
-
// ── Token persistence ──────────────────────────────────────────────
|
|
62
|
-
/**
|
|
63
|
-
* Load persisted tokens via a generic getter callback.
|
|
64
|
-
*
|
|
65
|
-
* @param getter Reads a string value by key (e.g. SecretStore.get)
|
|
66
|
-
* @param accountKey Unique key prefix for this account
|
|
67
|
-
*/
|
|
68
|
-
export async function loadTokens(getter, accountKey) {
|
|
69
|
-
const raw = await getter(`google_tokens:${accountKey}`);
|
|
70
|
-
if (!raw)
|
|
71
|
-
return null;
|
|
72
|
-
try {
|
|
73
|
-
return JSON.parse(raw);
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Persist tokens via a generic setter callback.
|
|
81
|
-
*
|
|
82
|
-
* @param setter Writes a string value by key (e.g. SecretStore.set)
|
|
83
|
-
* @param accountKey Unique key prefix for this account
|
|
84
|
-
* @param tokens Tokens to persist
|
|
85
|
-
*/
|
|
86
|
-
export async function saveTokens(setter, accountKey, tokens) {
|
|
87
|
-
await setter(`google_tokens:${accountKey}`, JSON.stringify(tokens));
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Refresh the access token if it has expired (or is about to within 60 s).
|
|
91
|
-
*
|
|
92
|
-
* If the token was refreshed and a `saver` callback is provided, the new
|
|
93
|
-
* tokens are persisted automatically.
|
|
94
|
-
*/
|
|
95
|
-
export async function refreshIfNeeded(client, tokens, saver) {
|
|
96
|
-
const buffer = 60_000; // 60 seconds
|
|
97
|
-
const isExpired = tokens.expiry_date != null && Date.now() >= tokens.expiry_date - buffer;
|
|
98
|
-
if (!isExpired)
|
|
99
|
-
return tokens;
|
|
100
|
-
client.setCredentials(tokens);
|
|
101
|
-
const { credentials } = await client.refreshAccessToken();
|
|
102
|
-
const refreshed = {
|
|
103
|
-
access_token: credentials.access_token,
|
|
104
|
-
refresh_token: credentials.refresh_token ?? tokens.refresh_token,
|
|
105
|
-
expiry_date: credentials.expiry_date ?? undefined,
|
|
106
|
-
token_type: credentials.token_type ?? 'Bearer',
|
|
107
|
-
};
|
|
108
|
-
if (saver) {
|
|
109
|
-
await saver(refreshed);
|
|
110
|
-
}
|
|
111
|
-
return refreshed;
|
|
112
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/** Google connector types. */
|
|
2
|
-
import type { ConnectorConfig } from '../../shared/types/connector.js';
|
|
3
|
-
export interface GoogleOAuthConfig {
|
|
4
|
-
clientId: string;
|
|
5
|
-
clientSecret: string;
|
|
6
|
-
redirectUri: string;
|
|
7
|
-
}
|
|
8
|
-
export interface GoogleTokens {
|
|
9
|
-
access_token: string;
|
|
10
|
-
refresh_token?: string;
|
|
11
|
-
expiry_date?: number;
|
|
12
|
-
token_type: string;
|
|
13
|
-
}
|
|
14
|
-
export interface GoogleServiceAccountConfig {
|
|
15
|
-
/** Path to service account key JSON file */
|
|
16
|
-
keyFile?: string;
|
|
17
|
-
/** Inline service account credentials (alternative to keyFile) */
|
|
18
|
-
credentials?: {
|
|
19
|
-
client_email: string;
|
|
20
|
-
private_key: string;
|
|
21
|
-
project_id?: string;
|
|
22
|
-
};
|
|
23
|
-
/** Email of the user to impersonate via domain-wide delegation */
|
|
24
|
-
subject: string;
|
|
25
|
-
}
|
|
26
|
-
export interface GoogleConnectorConfig extends ConnectorConfig {
|
|
27
|
-
/** Google account email */
|
|
28
|
-
account: string;
|
|
29
|
-
/** OAuth2 user auth (requires browser flow) */
|
|
30
|
-
oauth?: GoogleOAuthConfig;
|
|
31
|
-
/** Service account auth (headless, for cloud deployments) */
|
|
32
|
-
serviceAccount?: GoogleServiceAccountConfig;
|
|
33
|
-
scopes?: string[];
|
|
34
|
-
}
|
|
35
|
-
export interface EmailAddress {
|
|
36
|
-
name?: string;
|
|
37
|
-
email: string;
|
|
38
|
-
}
|
|
39
|
-
export interface EmailRecord {
|
|
40
|
-
gmailId: string;
|
|
41
|
-
threadId: string;
|
|
42
|
-
account: string;
|
|
43
|
-
subject: string;
|
|
44
|
-
from: EmailAddress;
|
|
45
|
-
to: EmailAddress[];
|
|
46
|
-
cc: EmailAddress[];
|
|
47
|
-
bcc: EmailAddress[];
|
|
48
|
-
/** ISO 8601 timestamp */
|
|
49
|
-
date: string;
|
|
50
|
-
snippet: string;
|
|
51
|
-
body?: string;
|
|
52
|
-
labels: string[];
|
|
53
|
-
isRead: boolean;
|
|
54
|
-
}
|
|
55
|
-
export interface CalendarAttendee {
|
|
56
|
-
email: string;
|
|
57
|
-
displayName?: string;
|
|
58
|
-
responseStatus?: string;
|
|
59
|
-
}
|
|
60
|
-
export interface CalendarEventRecord {
|
|
61
|
-
googleEventId: string;
|
|
62
|
-
calendarId: string;
|
|
63
|
-
account: string;
|
|
64
|
-
title: string;
|
|
65
|
-
description?: string;
|
|
66
|
-
location?: string;
|
|
67
|
-
/** ISO 8601 timestamp */
|
|
68
|
-
startAt: string;
|
|
69
|
-
/** ISO 8601 timestamp */
|
|
70
|
-
endAt: string;
|
|
71
|
-
allDay: boolean;
|
|
72
|
-
timezone?: string;
|
|
73
|
-
status: string;
|
|
74
|
-
organizerEmail: string;
|
|
75
|
-
attendees: CalendarAttendee[];
|
|
76
|
-
recurrence?: string[];
|
|
77
|
-
htmlLink?: string;
|
|
78
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-discovery for channel adapters.
|
|
3
|
-
* Scans @botinabox/* packages for botinabox.type === 'channel'.
|
|
4
|
-
* Story 4.1
|
|
5
|
-
*/
|
|
6
|
-
import type { ChannelAdapter } from "./types.js";
|
|
7
|
-
type Importer = (packageName: string) => Promise<unknown>;
|
|
8
|
-
/**
|
|
9
|
-
* Scans nodeModulesPath/@botinabox/{pkg}/package.json for each package in the scope.
|
|
10
|
-
* If pkg.botinabox?.type === 'channel', dynamically imports the package
|
|
11
|
-
* and returns the discovered ChannelAdapter instances.
|
|
12
|
-
*
|
|
13
|
-
* The optional importer parameter allows injection for testing.
|
|
14
|
-
*/
|
|
15
|
-
export declare function discoverChannels(nodeModulesPath: string, importer?: Importer): Promise<ChannelAdapter[]>;
|
|
16
|
-
export {};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-discovery for channel adapters.
|
|
3
|
-
* Scans @botinabox/* packages for botinabox.type === 'channel'.
|
|
4
|
-
* Story 4.1
|
|
5
|
-
*/
|
|
6
|
-
import { readdir, readFile } from "node:fs/promises";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
/**
|
|
9
|
-
* Scans nodeModulesPath/@botinabox/{pkg}/package.json for each package in the scope.
|
|
10
|
-
* If pkg.botinabox?.type === 'channel', dynamically imports the package
|
|
11
|
-
* and returns the discovered ChannelAdapter instances.
|
|
12
|
-
*
|
|
13
|
-
* The optional importer parameter allows injection for testing.
|
|
14
|
-
*/
|
|
15
|
-
export async function discoverChannels(nodeModulesPath, importer = (name) => import(name)) {
|
|
16
|
-
const scopeDir = join(nodeModulesPath, "@botinabox");
|
|
17
|
-
let entries;
|
|
18
|
-
try {
|
|
19
|
-
entries = await readdir(scopeDir);
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
// No @botinabox scope directory — gracefully return empty
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
const adapters = [];
|
|
26
|
-
for (const entry of entries) {
|
|
27
|
-
const pkgPath = join(scopeDir, entry, "package.json");
|
|
28
|
-
let pkg;
|
|
29
|
-
try {
|
|
30
|
-
const raw = await readFile(pkgPath, "utf8");
|
|
31
|
-
pkg = JSON.parse(raw);
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
const botinabox = pkg.botinabox;
|
|
37
|
-
if (botinabox?.type !== "channel") {
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
const packageName = pkg.name;
|
|
41
|
-
if (!packageName) {
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const mod = await importer(packageName);
|
|
46
|
-
const adapter = "default" in mod && mod.default ? mod.default : mod;
|
|
47
|
-
adapters.push(adapter);
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
// Failed to import — skip silently
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return adapters;
|
|
54
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ChannelRegistry — manages channel adapter lifecycle.
|
|
3
|
-
* Story 4.1
|
|
4
|
-
*/
|
|
5
|
-
import type { ChannelAdapter, HealthStatus } from "./types.js";
|
|
6
|
-
export declare class ChannelRegistryError extends Error {
|
|
7
|
-
constructor(message: string);
|
|
8
|
-
}
|
|
9
|
-
export declare class ChannelRegistry {
|
|
10
|
-
private readonly adapters;
|
|
11
|
-
private started;
|
|
12
|
-
/**
|
|
13
|
-
* Register a channel adapter.
|
|
14
|
-
* Throws if an adapter with the same id is already registered.
|
|
15
|
-
* If registry is already started, immediately connects the adapter.
|
|
16
|
-
*/
|
|
17
|
-
register(adapter: ChannelAdapter, config?: unknown): void;
|
|
18
|
-
/**
|
|
19
|
-
* Unregister a channel adapter.
|
|
20
|
-
* Disconnects the adapter if it exists.
|
|
21
|
-
*/
|
|
22
|
-
unregister(id: string): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Reconfigure an adapter: disconnect, update config, reconnect.
|
|
25
|
-
*/
|
|
26
|
-
reconfigure(id: string, config: unknown): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* Run health checks on all registered adapters.
|
|
29
|
-
*/
|
|
30
|
-
healthCheck(): Promise<Record<string, HealthStatus>>;
|
|
31
|
-
/** Check if an adapter is registered. */
|
|
32
|
-
has(id: string): boolean;
|
|
33
|
-
/** Get an adapter by ID. */
|
|
34
|
-
get(id: string): ChannelAdapter | undefined;
|
|
35
|
-
/** List all registered adapters. */
|
|
36
|
-
list(): ChannelAdapter[];
|
|
37
|
-
/**
|
|
38
|
-
* Start: connect all registered adapters and mark registry as started.
|
|
39
|
-
*/
|
|
40
|
-
start(): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Stop: disconnect all registered adapters.
|
|
43
|
-
*/
|
|
44
|
-
stop(): Promise<void>;
|
|
45
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ChannelRegistry — manages channel adapter lifecycle.
|
|
3
|
-
* Story 4.1
|
|
4
|
-
*/
|
|
5
|
-
export class ChannelRegistryError extends Error {
|
|
6
|
-
constructor(message) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = "ChannelRegistryError";
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export class ChannelRegistry {
|
|
12
|
-
adapters = new Map();
|
|
13
|
-
started = false;
|
|
14
|
-
/**
|
|
15
|
-
* Register a channel adapter.
|
|
16
|
-
* Throws if an adapter with the same id is already registered.
|
|
17
|
-
* If registry is already started, immediately connects the adapter.
|
|
18
|
-
*/
|
|
19
|
-
register(adapter, config) {
|
|
20
|
-
if (this.adapters.has(adapter.id)) {
|
|
21
|
-
throw new ChannelRegistryError(`Channel adapter already registered: ${adapter.id}`);
|
|
22
|
-
}
|
|
23
|
-
this.adapters.set(adapter.id, { adapter, config });
|
|
24
|
-
if (this.started) {
|
|
25
|
-
void adapter.connect((config ?? {}));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Unregister a channel adapter.
|
|
30
|
-
* Disconnects the adapter if it exists.
|
|
31
|
-
*/
|
|
32
|
-
async unregister(id) {
|
|
33
|
-
const entry = this.adapters.get(id);
|
|
34
|
-
if (!entry)
|
|
35
|
-
return;
|
|
36
|
-
await entry.adapter.disconnect();
|
|
37
|
-
this.adapters.delete(id);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Reconfigure an adapter: disconnect, update config, reconnect.
|
|
41
|
-
*/
|
|
42
|
-
async reconfigure(id, config) {
|
|
43
|
-
const entry = this.adapters.get(id);
|
|
44
|
-
if (!entry) {
|
|
45
|
-
throw new ChannelRegistryError(`Channel adapter not found: ${id}`);
|
|
46
|
-
}
|
|
47
|
-
await entry.adapter.disconnect();
|
|
48
|
-
entry.config = config;
|
|
49
|
-
await entry.adapter.connect((config ?? {}));
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Run health checks on all registered adapters.
|
|
53
|
-
*/
|
|
54
|
-
async healthCheck() {
|
|
55
|
-
const results = {};
|
|
56
|
-
for (const [id, entry] of this.adapters) {
|
|
57
|
-
try {
|
|
58
|
-
results[id] = await entry.adapter.healthCheck();
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
results[id] = { ok: false, error: String(err) };
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return results;
|
|
65
|
-
}
|
|
66
|
-
/** Check if an adapter is registered. */
|
|
67
|
-
has(id) {
|
|
68
|
-
return this.adapters.has(id);
|
|
69
|
-
}
|
|
70
|
-
/** Get an adapter by ID. */
|
|
71
|
-
get(id) {
|
|
72
|
-
return this.adapters.get(id)?.adapter;
|
|
73
|
-
}
|
|
74
|
-
/** List all registered adapters. */
|
|
75
|
-
list() {
|
|
76
|
-
return Array.from(this.adapters.values()).map((e) => e.adapter);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Start: connect all registered adapters and mark registry as started.
|
|
80
|
-
*/
|
|
81
|
-
async start() {
|
|
82
|
-
this.started = true;
|
|
83
|
-
for (const entry of this.adapters.values()) {
|
|
84
|
-
await entry.adapter.connect((entry.config ?? {}));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Stop: disconnect all registered adapters.
|
|
89
|
-
*/
|
|
90
|
-
async stop() {
|
|
91
|
-
for (const entry of this.adapters.values()) {
|
|
92
|
-
await entry.adapter.disconnect();
|
|
93
|
-
}
|
|
94
|
-
this.started = false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ChatPipeline — configurable 6-layer chat orchestration.
|
|
3
|
-
* Story 7.4
|
|
4
|
-
*
|
|
5
|
-
* Replaces duplicated handler code across apps with a single configurable
|
|
6
|
-
* pipeline. Apps provide: system prompt, routing rules, LLM call function,
|
|
7
|
-
* and optional message filter. Everything else is framework-level.
|
|
8
|
-
*
|
|
9
|
-
* Layers:
|
|
10
|
-
* 1. Dedup + Storage (MessageStore)
|
|
11
|
-
* 2. Fast Response (ChatResponder)
|
|
12
|
-
* 3. Interpretation (MessageInterpreter)
|
|
13
|
-
* 4. Post-Interpretation Response
|
|
14
|
-
* 5. Task Dispatch (TriageRouter)
|
|
15
|
-
* 6. Task Execution Response
|
|
16
|
-
*/
|
|
17
|
-
import type { DataStore } from '../data/data-store.js';
|
|
18
|
-
import type { HookBus } from '../hooks/hook-bus.js';
|
|
19
|
-
import type { InboundMessage } from './types.js';
|
|
20
|
-
import { MessageStore } from './message-store.js';
|
|
21
|
-
import { ChatResponder } from './chat-responder.js';
|
|
22
|
-
import type { ChatResponderConfig } from './chat-responder.js';
|
|
23
|
-
import { MessageInterpreter } from './message-interpreter.js';
|
|
24
|
-
import type { Extractor } from './message-interpreter.js';
|
|
25
|
-
import { TriageRouter } from './triage-router.js';
|
|
26
|
-
import type { RoutingRule } from './triage-router.js';
|
|
27
|
-
export interface ChatPipelineConfig {
|
|
28
|
-
/** LLM call function for chat responses and interpretation */
|
|
29
|
-
llmCall: ChatResponderConfig['llmCall'];
|
|
30
|
-
/** System prompt for the conversational responder */
|
|
31
|
-
systemPrompt: string;
|
|
32
|
-
/** Agent routing rules for task dispatch */
|
|
33
|
-
routingRules: RoutingRule[];
|
|
34
|
-
/** Default agent when no rule matches */
|
|
35
|
-
fallbackAgent: string;
|
|
36
|
-
/** Optional message filter — return false to ignore a message */
|
|
37
|
-
messageFilter?: (msg: InboundMessage) => boolean;
|
|
38
|
-
/** Optional capabilities description for the responder */
|
|
39
|
-
capabilities?: string;
|
|
40
|
-
/** Channel this pipeline handles (default: 'slack') */
|
|
41
|
-
channel?: string;
|
|
42
|
-
/** Custom extractors for MessageInterpreter */
|
|
43
|
-
extractors?: Extractor[];
|
|
44
|
-
/** Dedup window in ms (default: 300_000 = 5 min) */
|
|
45
|
-
dedupWindowMs?: number;
|
|
46
|
-
/** Model for fast responses (default: 'fast') */
|
|
47
|
-
model?: string;
|
|
48
|
-
/** Enable LLM fallback routing (default: false) */
|
|
49
|
-
llmRouting?: boolean;
|
|
50
|
-
/** TaskQueue instance — required for task dispatch */
|
|
51
|
-
tasks: {
|
|
52
|
-
create(task: Record<string, unknown>): Promise<string>;
|
|
53
|
-
update(id: string, changes: Record<string, unknown>): Promise<void>;
|
|
54
|
-
get(id: string): Promise<Record<string, unknown> | undefined>;
|
|
55
|
-
};
|
|
56
|
-
/** WakeupQueue instance — required for agent waking */
|
|
57
|
-
wakeups: {
|
|
58
|
-
enqueue(agentId: string, source: string, context?: Record<string, unknown>): Promise<string>;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
export declare class ChatPipeline {
|
|
62
|
-
private db;
|
|
63
|
-
private hooks;
|
|
64
|
-
readonly messageStore: MessageStore;
|
|
65
|
-
readonly responder: ChatResponder;
|
|
66
|
-
readonly interpreter: MessageInterpreter;
|
|
67
|
-
readonly router: TriageRouter;
|
|
68
|
-
private readonly channel;
|
|
69
|
-
private readonly messageFilter?;
|
|
70
|
-
private readonly capabilities?;
|
|
71
|
-
private readonly dedupWindowMs;
|
|
72
|
-
private readonly tasks;
|
|
73
|
-
private readonly wakeups;
|
|
74
|
-
private readonly threadChannelMap;
|
|
75
|
-
/** Last dispatch promise — exposed for testing. */
|
|
76
|
-
lastDispatch: Promise<void>;
|
|
77
|
-
constructor(db: DataStore, hooks: HookBus, config: ChatPipelineConfig);
|
|
78
|
-
/**
|
|
79
|
-
* Resolve the Slack channel ID for a thread (for response delivery).
|
|
80
|
-
*/
|
|
81
|
-
resolveChannel(threadId: string, taskId?: string): Promise<string | undefined>;
|
|
82
|
-
/**
|
|
83
|
-
* Register the 6-layer pipeline on the HookBus.
|
|
84
|
-
*/
|
|
85
|
-
private registerHandlers;
|
|
86
|
-
/**
|
|
87
|
-
* Check and record message dedup (SHA256 hash, configurable window).
|
|
88
|
-
*/
|
|
89
|
-
private isDuplicate;
|
|
90
|
-
/**
|
|
91
|
-
* Async interpretation + task dispatch (Layers 3-5).
|
|
92
|
-
*
|
|
93
|
-
* ALWAYS creates a task programmatically — task creation does not depend
|
|
94
|
-
* on LLM classification. Interpretation enriches but never gates dispatch.
|
|
95
|
-
*/
|
|
96
|
-
private interpretAndDispatch;
|
|
97
|
-
/**
|
|
98
|
-
* Programmatic task creation — guaranteed, no LLM dependency.
|
|
99
|
-
*/
|
|
100
|
-
private guaranteedTaskDispatch;
|
|
101
|
-
/**
|
|
102
|
-
* Route and dispatch extracted tasks.
|
|
103
|
-
*/
|
|
104
|
-
private dispatchTasks;
|
|
105
|
-
/**
|
|
106
|
-
* Resolve Slack channel ID from thread_task_map or in-memory fallback.
|
|
107
|
-
*/
|
|
108
|
-
private resolveChannelId;
|
|
109
|
-
/**
|
|
110
|
-
* Build human-readable interpretation summary.
|
|
111
|
-
*/
|
|
112
|
-
private buildSummary;
|
|
113
|
-
}
|