botinabox 2.5.2 → 2.5.3
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/{chunk-UACT2WXX.js → chunk-7AGWGYZC.js} +43 -5
- package/dist/cli.js +1 -1
- package/dist/connectors/google/index.d.ts +10 -1
- package/dist/connectors/google/index.js +1 -1
- package/dist/{gmail-connector-2FVYTQJH.js → gmail-connector-VP5FF56J.js} +2 -1
- package/package.json +100 -100
- 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-BWrtVqEP.d.ts +0 -652
- 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/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-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,61 +0,0 @@
|
|
|
1
|
-
export function configYmlTemplate(opts) {
|
|
2
|
-
const { name, channel = 'slack', provider = 'anthropic' } = opts;
|
|
3
|
-
const channelSection = channel === 'slack'
|
|
4
|
-
? ` slack:
|
|
5
|
-
enabled: true
|
|
6
|
-
token: \${SLACK_BOT_TOKEN}
|
|
7
|
-
appToken: \${SLACK_APP_TOKEN}
|
|
8
|
-
signingSecret: \${SLACK_SIGNING_SECRET}`
|
|
9
|
-
: channel === 'discord'
|
|
10
|
-
? ` discord:
|
|
11
|
-
enabled: true
|
|
12
|
-
token: \${DISCORD_BOT_TOKEN}`
|
|
13
|
-
: ` ${channel}:
|
|
14
|
-
enabled: true`;
|
|
15
|
-
const providerSection = provider === 'anthropic'
|
|
16
|
-
? ` anthropic:
|
|
17
|
-
enabled: true
|
|
18
|
-
apiKey: \${ANTHROPIC_API_KEY}`
|
|
19
|
-
: provider === 'openai'
|
|
20
|
-
? ` openai:
|
|
21
|
-
enabled: true
|
|
22
|
-
apiKey: \${OPENAI_API_KEY}`
|
|
23
|
-
: ` ${provider}:
|
|
24
|
-
enabled: true`;
|
|
25
|
-
return `name: ${name}
|
|
26
|
-
version: "1.0.0"
|
|
27
|
-
|
|
28
|
-
data:
|
|
29
|
-
path: ./data/bot.db
|
|
30
|
-
walMode: true
|
|
31
|
-
|
|
32
|
-
channels:
|
|
33
|
-
${channelSection}
|
|
34
|
-
|
|
35
|
-
providers:
|
|
36
|
-
${providerSection}
|
|
37
|
-
|
|
38
|
-
agents: []
|
|
39
|
-
|
|
40
|
-
models:
|
|
41
|
-
default: claude-3-5-sonnet-20241022
|
|
42
|
-
aliases: {}
|
|
43
|
-
routing: {}
|
|
44
|
-
fallbackChain: []
|
|
45
|
-
|
|
46
|
-
entities: {}
|
|
47
|
-
|
|
48
|
-
security: {}
|
|
49
|
-
|
|
50
|
-
render:
|
|
51
|
-
outputDir: ./generated
|
|
52
|
-
watchIntervalMs: 1000
|
|
53
|
-
|
|
54
|
-
updates:
|
|
55
|
-
policy: notify
|
|
56
|
-
checkIntervalMs: 3600000
|
|
57
|
-
|
|
58
|
-
budget:
|
|
59
|
-
warnPercent: 80
|
|
60
|
-
`;
|
|
61
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function envTemplate(channel?: string, provider?: string): string;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export function envTemplate(channel, provider) {
|
|
2
|
-
const lines = [
|
|
3
|
-
'# Bot environment variables',
|
|
4
|
-
'# Copy this file to .env and fill in the values',
|
|
5
|
-
'',
|
|
6
|
-
];
|
|
7
|
-
if (provider === 'anthropic' || !provider) {
|
|
8
|
-
lines.push('ANTHROPIC_API_KEY=your_anthropic_api_key_here');
|
|
9
|
-
}
|
|
10
|
-
else if (provider === 'openai') {
|
|
11
|
-
lines.push('OPENAI_API_KEY=your_openai_api_key_here');
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
lines.push(`${provider.toUpperCase()}_API_KEY=your_api_key_here`);
|
|
15
|
-
}
|
|
16
|
-
lines.push('');
|
|
17
|
-
if (channel === 'slack' || !channel) {
|
|
18
|
-
lines.push('SLACK_BOT_TOKEN=xoxb-your-slack-bot-token');
|
|
19
|
-
lines.push('SLACK_APP_TOKEN=xapp-your-slack-app-token');
|
|
20
|
-
lines.push('SLACK_SIGNING_SECRET=your_slack_signing_secret');
|
|
21
|
-
}
|
|
22
|
-
else if (channel === 'discord') {
|
|
23
|
-
lines.push('DISCORD_BOT_TOKEN=your_discord_bot_token');
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
lines.push(`${channel.toUpperCase()}_TOKEN=your_token_here`);
|
|
27
|
-
}
|
|
28
|
-
lines.push('');
|
|
29
|
-
return lines.join('\n');
|
|
30
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export function indexTsTemplate(name) {
|
|
2
|
-
return `import { DataStore } from 'botinabox';
|
|
3
|
-
import { readFileSync } from 'fs';
|
|
4
|
-
|
|
5
|
-
// Load config
|
|
6
|
-
const config = JSON.parse(readFileSync('./config.yml', 'utf-8'));
|
|
7
|
-
|
|
8
|
-
async function main(): Promise<void> {
|
|
9
|
-
console.log('Starting ${name}...');
|
|
10
|
-
// Initialize your bot here
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
main().catch(console.error);
|
|
14
|
-
`;
|
|
15
|
-
}
|
|
16
|
-
export function indexJsTemplate(name) {
|
|
17
|
-
return `import { DataStore } from 'botinabox';
|
|
18
|
-
import { readFileSync } from 'fs';
|
|
19
|
-
|
|
20
|
-
// Load config
|
|
21
|
-
const config = JSON.parse(readFileSync('./config.yml', 'utf-8'));
|
|
22
|
-
|
|
23
|
-
async function main() {
|
|
24
|
-
console.log('Starting ${name}...');
|
|
25
|
-
// Initialize your bot here
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
main().catch(console.error);
|
|
29
|
-
`;
|
|
30
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export function packageJsonTemplate(opts) {
|
|
2
|
-
const { name, typescript = false } = opts;
|
|
3
|
-
const scripts = typescript
|
|
4
|
-
? {
|
|
5
|
-
build: 'tsc',
|
|
6
|
-
start: 'node dist/index.js',
|
|
7
|
-
dev: 'ts-node src/index.ts',
|
|
8
|
-
}
|
|
9
|
-
: {
|
|
10
|
-
start: 'node index.js',
|
|
11
|
-
};
|
|
12
|
-
const devDeps = typescript
|
|
13
|
-
? {
|
|
14
|
-
typescript: '^5.7.2',
|
|
15
|
-
'@types/node': '^22.10.0',
|
|
16
|
-
}
|
|
17
|
-
: {};
|
|
18
|
-
return JSON.stringify({
|
|
19
|
-
name,
|
|
20
|
-
version: '0.1.0',
|
|
21
|
-
type: 'module',
|
|
22
|
-
scripts,
|
|
23
|
-
dependencies: {
|
|
24
|
-
'botinabox': 'latest',
|
|
25
|
-
},
|
|
26
|
-
devDependencies: devDeps,
|
|
27
|
-
}, null, 2);
|
|
28
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/** Connector types — generic external service integrations. */
|
|
2
|
-
interface ConnectorMeta {
|
|
3
|
-
displayName: string;
|
|
4
|
-
/** Provider identifier, e.g. "google", "trello", "jira", "salesforce" */
|
|
5
|
-
provider: string;
|
|
6
|
-
/** Data type this connector handles, e.g. "email", "calendar", "board", "crm" */
|
|
7
|
-
dataType: string;
|
|
8
|
-
}
|
|
9
|
-
interface SyncOptions {
|
|
10
|
-
/** Only sync records after this ISO 8601 timestamp */
|
|
11
|
-
since?: string;
|
|
12
|
-
/** Provider-specific incremental sync token */
|
|
13
|
-
cursor?: string;
|
|
14
|
-
/** Maximum number of records to fetch */
|
|
15
|
-
limit?: number;
|
|
16
|
-
/** Provider-specific query filters */
|
|
17
|
-
filters?: Record<string, unknown>;
|
|
18
|
-
}
|
|
19
|
-
interface SyncResult<T = Record<string, unknown>> {
|
|
20
|
-
/** Typed records produced by the connector — consumer decides where to store */
|
|
21
|
-
records: T[];
|
|
22
|
-
/** Next incremental sync token (persist for future calls) */
|
|
23
|
-
cursor?: string;
|
|
24
|
-
/** Whether more records are available (pagination) */
|
|
25
|
-
hasMore: boolean;
|
|
26
|
-
/** Errors encountered during sync (non-fatal per-record failures) */
|
|
27
|
-
errors: Array<{
|
|
28
|
-
id?: string;
|
|
29
|
-
error: string;
|
|
30
|
-
}>;
|
|
31
|
-
}
|
|
32
|
-
interface PushResult {
|
|
33
|
-
success: boolean;
|
|
34
|
-
externalId?: string;
|
|
35
|
-
error?: string;
|
|
36
|
-
}
|
|
37
|
-
type ConnectorConfig = Record<string, unknown>;
|
|
38
|
-
/**
|
|
39
|
-
* Generic connector interface for external service integrations.
|
|
40
|
-
*
|
|
41
|
-
* Connectors pull and optionally push data to/from external services
|
|
42
|
-
* (Gmail, Calendar, Trello, Jira, Salesforce, etc.). They produce
|
|
43
|
-
* typed records — the consuming application decides where to store them.
|
|
44
|
-
*
|
|
45
|
-
* @typeParam T - The record type this connector produces/consumes.
|
|
46
|
-
*/
|
|
47
|
-
interface Connector<T = Record<string, unknown>> {
|
|
48
|
-
readonly id: string;
|
|
49
|
-
readonly meta: ConnectorMeta;
|
|
50
|
-
connect(config: ConnectorConfig): Promise<void>;
|
|
51
|
-
disconnect(): Promise<void>;
|
|
52
|
-
healthCheck(): Promise<{
|
|
53
|
-
ok: boolean;
|
|
54
|
-
account?: string;
|
|
55
|
-
error?: string;
|
|
56
|
-
}>;
|
|
57
|
-
/** Pull records from external source */
|
|
58
|
-
sync(options?: SyncOptions): Promise<SyncResult<T>>;
|
|
59
|
-
/** Push a record to external source (optional) */
|
|
60
|
-
push?(payload: T): Promise<PushResult>;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export type { ConnectorConfig as C, PushResult as P, SyncOptions as S, Connector as a, ConnectorMeta as b, SyncResult as c };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Google Calendar connector — pulls calendar events.
|
|
3
|
-
*
|
|
4
|
-
* Produces `CalendarEventRecord` objects. Does NOT write to any database
|
|
5
|
-
* table; the consuming application decides how to store records.
|
|
6
|
-
*/
|
|
7
|
-
import type { Connector, ConnectorMeta, AuthResult, SyncOptions, SyncResult } from '../../shared/types/connector.js';
|
|
8
|
-
import type { CalendarEventRecord, GoogleConnectorConfig } from './types.js';
|
|
9
|
-
export interface CalendarConnectorOpts {
|
|
10
|
-
/** Load persisted tokens for a given account key (OAuth2 flow only). */
|
|
11
|
-
tokenLoader?: (key: string) => Promise<string | null>;
|
|
12
|
-
/** Persist tokens for a given account key (OAuth2 flow only). */
|
|
13
|
-
tokenSaver?: (key: string, value: string) => Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
export declare class GoogleCalendarConnector implements Connector<CalendarEventRecord> {
|
|
16
|
-
readonly id = "google-calendar";
|
|
17
|
-
readonly meta: ConnectorMeta;
|
|
18
|
-
private tokenLoader?;
|
|
19
|
-
private tokenSaver?;
|
|
20
|
-
private client;
|
|
21
|
-
private config;
|
|
22
|
-
private tokens;
|
|
23
|
-
private calendar;
|
|
24
|
-
constructor(opts?: CalendarConnectorOpts);
|
|
25
|
-
connect(config: GoogleConnectorConfig): Promise<void>;
|
|
26
|
-
disconnect(): Promise<void>;
|
|
27
|
-
healthCheck(): Promise<{
|
|
28
|
-
ok: boolean;
|
|
29
|
-
account?: string;
|
|
30
|
-
error?: string;
|
|
31
|
-
}>;
|
|
32
|
-
authenticate(codeProvider: (authUrl: string) => Promise<string>): Promise<AuthResult>;
|
|
33
|
-
sync(options?: SyncOptions): Promise<SyncResult<CalendarEventRecord>>;
|
|
34
|
-
/** Incremental sync using Calendar syncToken. */
|
|
35
|
-
private syncIncremental;
|
|
36
|
-
/** Full sync using timeMin. */
|
|
37
|
-
private syncFull;
|
|
38
|
-
private ensureConnected;
|
|
39
|
-
private mapEvent;
|
|
40
|
-
}
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Google Calendar connector — pulls calendar events.
|
|
3
|
-
*
|
|
4
|
-
* Produces `CalendarEventRecord` objects. Does NOT write to any database
|
|
5
|
-
* table; the consuming application decides how to store records.
|
|
6
|
-
*/
|
|
7
|
-
import { createOAuth2Client, createServiceAccountClient, getAuthUrl, exchangeCode, loadTokens, saveTokens, refreshIfNeeded, } from './oauth.js';
|
|
8
|
-
// ── Connector ──────────────────────────────────────────────────────
|
|
9
|
-
export class GoogleCalendarConnector {
|
|
10
|
-
id = 'google-calendar';
|
|
11
|
-
meta = {
|
|
12
|
-
displayName: 'Google Calendar',
|
|
13
|
-
provider: 'google',
|
|
14
|
-
dataType: 'calendar',
|
|
15
|
-
};
|
|
16
|
-
tokenLoader;
|
|
17
|
-
tokenSaver;
|
|
18
|
-
client = null;
|
|
19
|
-
config = null;
|
|
20
|
-
tokens = null;
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
calendar = null;
|
|
23
|
-
constructor(opts = {}) {
|
|
24
|
-
this.tokenLoader = opts.tokenLoader;
|
|
25
|
-
this.tokenSaver = opts.tokenSaver;
|
|
26
|
-
}
|
|
27
|
-
// ── Lifecycle ──────────────────────────────────────────────────
|
|
28
|
-
async connect(config) {
|
|
29
|
-
this.config = config;
|
|
30
|
-
const scopes = config.scopes ?? [
|
|
31
|
-
'https://www.googleapis.com/auth/calendar.readonly',
|
|
32
|
-
];
|
|
33
|
-
if (config.serviceAccount) {
|
|
34
|
-
this.client = await createServiceAccountClient(config.serviceAccount, scopes);
|
|
35
|
-
}
|
|
36
|
-
else if (config.oauth) {
|
|
37
|
-
this.client = await createOAuth2Client(config.oauth);
|
|
38
|
-
if (!this.tokenLoader) {
|
|
39
|
-
throw new Error('tokenLoader required for OAuth2 flow');
|
|
40
|
-
}
|
|
41
|
-
this.tokens = await loadTokens(this.tokenLoader, config.account);
|
|
42
|
-
if (!this.tokens) {
|
|
43
|
-
throw new Error(`No stored tokens for account ${config.account}. Complete the OAuth flow first.`);
|
|
44
|
-
}
|
|
45
|
-
this.tokens = await refreshIfNeeded(this.client, this.tokens, this.tokenSaver
|
|
46
|
-
? async (t) => saveTokens(this.tokenSaver, config.account, t)
|
|
47
|
-
: undefined);
|
|
48
|
-
this.client.setCredentials(this.tokens);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
throw new Error('Either serviceAccount or oauth config is required');
|
|
52
|
-
}
|
|
53
|
-
const { google } = await import('googleapis');
|
|
54
|
-
this.calendar = google.calendar({ version: 'v3', auth: this.client });
|
|
55
|
-
}
|
|
56
|
-
async disconnect() {
|
|
57
|
-
this.client = null;
|
|
58
|
-
this.calendar = null;
|
|
59
|
-
this.tokens = null;
|
|
60
|
-
this.config = null;
|
|
61
|
-
}
|
|
62
|
-
async healthCheck() {
|
|
63
|
-
try {
|
|
64
|
-
this.ensureConnected();
|
|
65
|
-
const res = await this.calendar.calendarList.list({ maxResults: 1 });
|
|
66
|
-
const primary = (res.data.items ?? []).find(
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
-
(c) => c.primary);
|
|
69
|
-
return { ok: true, account: primary?.id ?? this.config.account };
|
|
70
|
-
}
|
|
71
|
-
catch (err) {
|
|
72
|
-
return { ok: false, error: errorMessage(err) };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// ── Auth ───────────────────────────────────────────────────────
|
|
76
|
-
async authenticate(codeProvider) {
|
|
77
|
-
if (!this.config) {
|
|
78
|
-
return { success: false, error: 'Call connect() first to set config, or pass config and call authenticate() before connect().' };
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
if (!this.config.oauth) {
|
|
82
|
-
return { success: false, error: 'OAuth config required for browser-based authenticate(). Use serviceAccount for headless auth.' };
|
|
83
|
-
}
|
|
84
|
-
if (!this.tokenSaver) {
|
|
85
|
-
return { success: false, error: 'tokenSaver required for authenticate() flow.' };
|
|
86
|
-
}
|
|
87
|
-
const client = await createOAuth2Client(this.config.oauth);
|
|
88
|
-
const scopes = this.config.scopes ?? [
|
|
89
|
-
'https://www.googleapis.com/auth/calendar.readonly',
|
|
90
|
-
];
|
|
91
|
-
const authUrl = getAuthUrl(client, scopes);
|
|
92
|
-
const code = await codeProvider(authUrl);
|
|
93
|
-
const tokens = await exchangeCode(client, code);
|
|
94
|
-
await saveTokens(this.tokenSaver, this.config.account, tokens);
|
|
95
|
-
this.tokens = tokens;
|
|
96
|
-
this.client = client;
|
|
97
|
-
this.client.setCredentials(tokens);
|
|
98
|
-
const { google } = await import('googleapis');
|
|
99
|
-
this.calendar = google.calendar({ version: 'v3', auth: this.client });
|
|
100
|
-
return { success: true, account: this.config.account };
|
|
101
|
-
}
|
|
102
|
-
catch (err) {
|
|
103
|
-
return { success: false, error: errorMessage(err) };
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
// ── Sync ───────────────────────────────────────────────────────
|
|
107
|
-
async sync(options) {
|
|
108
|
-
this.ensureConnected();
|
|
109
|
-
if (options?.cursor) {
|
|
110
|
-
return this.syncIncremental(options.cursor, options);
|
|
111
|
-
}
|
|
112
|
-
return this.syncFull(options);
|
|
113
|
-
}
|
|
114
|
-
/** Incremental sync using Calendar syncToken. */
|
|
115
|
-
async syncIncremental(syncToken, options) {
|
|
116
|
-
const calendarId = options?.filters?.calendarId ?? 'primary';
|
|
117
|
-
const records = [];
|
|
118
|
-
const errors = [];
|
|
119
|
-
let pageToken;
|
|
120
|
-
let nextSyncToken;
|
|
121
|
-
try {
|
|
122
|
-
do {
|
|
123
|
-
const res = await this.calendar.events.list({
|
|
124
|
-
calendarId,
|
|
125
|
-
syncToken,
|
|
126
|
-
...(pageToken ? { pageToken } : {}),
|
|
127
|
-
maxResults: options?.limit ? Math.min(options.limit - records.length, 250) : 250,
|
|
128
|
-
});
|
|
129
|
-
for (const event of res.data.items ?? []) {
|
|
130
|
-
try {
|
|
131
|
-
records.push(this.mapEvent(event, calendarId));
|
|
132
|
-
}
|
|
133
|
-
catch (err) {
|
|
134
|
-
errors.push({ id: event.id, error: errorMessage(err) });
|
|
135
|
-
}
|
|
136
|
-
if (options?.limit && records.length >= options.limit)
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
pageToken = res.data.nextPageToken ?? undefined;
|
|
140
|
-
nextSyncToken = res.data.nextSyncToken ?? undefined;
|
|
141
|
-
} while (pageToken && (!options?.limit || records.length < options.limit));
|
|
142
|
-
}
|
|
143
|
-
catch (err) {
|
|
144
|
-
// If syncToken is expired/invalid, fall back to full sync
|
|
145
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
146
|
-
if (err?.code === 410) {
|
|
147
|
-
return this.syncFull(options);
|
|
148
|
-
}
|
|
149
|
-
throw err;
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
records,
|
|
153
|
-
cursor: nextSyncToken,
|
|
154
|
-
hasMore: !!pageToken,
|
|
155
|
-
errors,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
/** Full sync using timeMin. */
|
|
159
|
-
async syncFull(options) {
|
|
160
|
-
const calendarId = options?.filters?.calendarId ?? 'primary';
|
|
161
|
-
const records = [];
|
|
162
|
-
const errors = [];
|
|
163
|
-
const maxResults = options?.limit ?? 250;
|
|
164
|
-
const timeMin = options?.since
|
|
165
|
-
? new Date(options.since).toISOString()
|
|
166
|
-
: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString(); // default: 30 days ago
|
|
167
|
-
let pageToken;
|
|
168
|
-
let nextSyncToken;
|
|
169
|
-
do {
|
|
170
|
-
const res = await this.calendar.events.list({
|
|
171
|
-
calendarId,
|
|
172
|
-
timeMin,
|
|
173
|
-
singleEvents: true,
|
|
174
|
-
orderBy: 'startTime',
|
|
175
|
-
maxResults: Math.min(maxResults - records.length, 250),
|
|
176
|
-
...(pageToken ? { pageToken } : {}),
|
|
177
|
-
});
|
|
178
|
-
for (const event of res.data.items ?? []) {
|
|
179
|
-
try {
|
|
180
|
-
records.push(this.mapEvent(event, calendarId));
|
|
181
|
-
}
|
|
182
|
-
catch (err) {
|
|
183
|
-
errors.push({ id: event.id, error: errorMessage(err) });
|
|
184
|
-
}
|
|
185
|
-
if (records.length >= maxResults)
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
pageToken = res.data.nextPageToken ?? undefined;
|
|
189
|
-
nextSyncToken = res.data.nextSyncToken ?? undefined;
|
|
190
|
-
} while (pageToken && records.length < maxResults);
|
|
191
|
-
return {
|
|
192
|
-
records,
|
|
193
|
-
cursor: nextSyncToken,
|
|
194
|
-
hasMore: !!pageToken,
|
|
195
|
-
errors,
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
// ── Internals ─────────────────────────────────────────────────
|
|
199
|
-
ensureConnected() {
|
|
200
|
-
if (!this.calendar || !this.config) {
|
|
201
|
-
throw new Error('GoogleCalendarConnector is not connected. Call connect() first.');
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
205
|
-
mapEvent(event, calendarId) {
|
|
206
|
-
const start = event.start ?? {};
|
|
207
|
-
const end = event.end ?? {};
|
|
208
|
-
const allDay = !!start.date;
|
|
209
|
-
const startAt = allDay
|
|
210
|
-
? new Date(start.date).toISOString()
|
|
211
|
-
: new Date(start.dateTime).toISOString();
|
|
212
|
-
const endAt = allDay
|
|
213
|
-
? new Date(end.date).toISOString()
|
|
214
|
-
: new Date(end.dateTime).toISOString();
|
|
215
|
-
const attendees = (event.attendees ?? []).map(
|
|
216
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
217
|
-
(a) => ({
|
|
218
|
-
email: a.email,
|
|
219
|
-
displayName: a.displayName,
|
|
220
|
-
responseStatus: a.responseStatus,
|
|
221
|
-
}));
|
|
222
|
-
return {
|
|
223
|
-
googleEventId: event.id,
|
|
224
|
-
calendarId,
|
|
225
|
-
account: this.config.account,
|
|
226
|
-
title: event.summary ?? '(No title)',
|
|
227
|
-
description: event.description ?? undefined,
|
|
228
|
-
location: event.location ?? undefined,
|
|
229
|
-
startAt,
|
|
230
|
-
endAt,
|
|
231
|
-
allDay,
|
|
232
|
-
timezone: start.timeZone ?? undefined,
|
|
233
|
-
status: event.status ?? 'confirmed',
|
|
234
|
-
organizerEmail: event.organizer?.email ?? '',
|
|
235
|
-
attendees,
|
|
236
|
-
recurrence: event.recurrence ?? undefined,
|
|
237
|
-
htmlLink: event.htmlLink ?? undefined,
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
function errorMessage(err) {
|
|
242
|
-
return err instanceof Error ? err.message : String(err);
|
|
243
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gmail connector — pulls email metadata and optionally sends mail.
|
|
3
|
-
*
|
|
4
|
-
* Produces `EmailRecord` objects. Does NOT write to any database table;
|
|
5
|
-
* the consuming application decides how to store records.
|
|
6
|
-
*/
|
|
7
|
-
import type { Connector, ConnectorMeta, AuthResult, SyncOptions, SyncResult, PushResult } from '../../shared/types/connector.js';
|
|
8
|
-
import type { EmailRecord, GoogleConnectorConfig } from './types.js';
|
|
9
|
-
export interface GmailConnectorOpts {
|
|
10
|
-
/** Load persisted tokens for a given account key (OAuth2 flow only). */
|
|
11
|
-
tokenLoader?: (key: string) => Promise<string | null>;
|
|
12
|
-
/** Persist tokens for a given account key (OAuth2 flow only). */
|
|
13
|
-
tokenSaver?: (key: string, value: string) => Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
export declare class GoogleGmailConnector implements Connector<EmailRecord> {
|
|
16
|
-
readonly id = "google-gmail";
|
|
17
|
-
readonly meta: ConnectorMeta;
|
|
18
|
-
private tokenLoader?;
|
|
19
|
-
private tokenSaver?;
|
|
20
|
-
private client;
|
|
21
|
-
private config;
|
|
22
|
-
private tokens;
|
|
23
|
-
private gmail;
|
|
24
|
-
constructor(opts?: GmailConnectorOpts);
|
|
25
|
-
connect(config: GoogleConnectorConfig): Promise<void>;
|
|
26
|
-
disconnect(): Promise<void>;
|
|
27
|
-
healthCheck(): Promise<{
|
|
28
|
-
ok: boolean;
|
|
29
|
-
account?: string;
|
|
30
|
-
error?: string;
|
|
31
|
-
}>;
|
|
32
|
-
authenticate(codeProvider: (authUrl: string) => Promise<string>): Promise<AuthResult>;
|
|
33
|
-
sync(options?: SyncOptions): Promise<SyncResult<EmailRecord>>;
|
|
34
|
-
/** Incremental sync using Gmail history API. */
|
|
35
|
-
private syncIncremental;
|
|
36
|
-
/** Full sync — list messages and fetch each one. */
|
|
37
|
-
private syncFull;
|
|
38
|
-
push(payload: EmailRecord): Promise<PushResult>;
|
|
39
|
-
private ensureConnected;
|
|
40
|
-
/** Fetch a single message by ID and parse into an EmailRecord. */
|
|
41
|
-
private fetchMessage;
|
|
42
|
-
}
|