botinabox 2.9.1 → 2.9.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/README.md +2 -1
- package/bin/botinabox.mjs +1 -1
- package/dist/channels/discord/adapter.d.ts +32 -0
- package/dist/channels/discord/inbound.d.ts +25 -0
- package/dist/channels/discord/index.d.ts +8 -84
- package/dist/channels/discord/models.d.ts +8 -0
- package/dist/channels/discord/outbound.d.ts +14 -0
- package/dist/channels/slack/adapter.d.ts +33 -0
- package/dist/channels/slack/bolt-adapter.d.ts +31 -0
- package/dist/channels/slack/enrichers/enrich.d.ts +12 -0
- package/dist/channels/slack/enrichers/image-enricher.d.ts +10 -0
- package/dist/channels/slack/enrichers/index.d.ts +4 -0
- package/dist/channels/slack/enrichers/pdf-enricher.d.ts +8 -0
- package/dist/channels/slack/enrichers/types.d.ts +33 -0
- package/dist/channels/slack/inbound.d.ts +59 -0
- package/dist/channels/slack/index.d.ts +13 -252
- package/dist/channels/slack/media-type.d.ts +14 -0
- package/dist/channels/slack/models.d.ts +9 -0
- package/dist/channels/slack/outbound.d.ts +12 -0
- package/dist/channels/slack/transcribe.d.ts +41 -0
- package/dist/channels/webhook/adapter.d.ts +23 -0
- package/dist/channels/webhook/hmac.d.ts +13 -0
- package/dist/channels/webhook/index.d.ts +7 -70
- package/dist/channels/webhook/models.d.ts +9 -0
- package/dist/channels/webhook/server.d.ts +20 -0
- package/dist/cli/templates/config.yml.d.ts +7 -0
- package/dist/cli/templates/env.d.ts +1 -0
- package/dist/cli/templates/index.ts.d.ts +2 -0
- package/dist/cli/templates/package.json.d.ts +5 -0
- package/dist/cli.d.ts +1 -3
- package/dist/connectors/google/calendar-connector.d.ts +40 -0
- package/dist/connectors/google/drive-connector.d.ts +43 -0
- package/dist/connectors/google/drive-read.d.ts +81 -0
- package/dist/connectors/google/gmail-connector.d.ts +42 -0
- package/dist/connectors/google/index.d.ts +10 -369
- package/dist/connectors/google/oauth.d.ts +48 -0
- package/dist/connectors/google/types.d.ts +110 -0
- package/dist/core/chat/auto-discovery.d.ts +16 -0
- package/dist/core/chat/channel-registry.d.ts +45 -0
- package/dist/core/chat/chat-pipeline-v2.d.ts +138 -0
- package/dist/core/chat/chat-pipeline.d.ts +116 -0
- package/dist/core/chat/chat-responder.d.ts +94 -0
- package/dist/core/chat/formatter.d.ts +11 -0
- package/dist/core/chat/index.d.ts +26 -0
- package/dist/core/chat/message-interpreter.d.ts +91 -0
- package/dist/core/chat/message-store.d.ts +71 -0
- package/dist/core/chat/notification-queue.d.ts +34 -0
- package/dist/core/chat/pipeline.d.ts +38 -0
- package/dist/core/chat/policies.d.ts +16 -0
- package/dist/core/chat/routing.d.ts +17 -0
- package/dist/core/chat/session-key.d.ts +30 -0
- package/dist/core/chat/session-manager.d.ts +17 -0
- package/dist/core/chat/text-chunker.d.ts +9 -0
- package/dist/core/chat/triage-router.d.ts +75 -0
- package/dist/core/chat/types.d.ts +5 -0
- package/dist/core/config/defaults.d.ts +2 -0
- package/dist/core/config/index.d.ts +6 -0
- package/dist/core/config/interpolate.d.ts +5 -0
- package/dist/core/config/loader.d.ts +24 -0
- package/dist/core/config/schema.d.ts +5 -0
- package/dist/core/data/context-builder.d.ts +27 -0
- package/dist/core/data/core-entity-contexts.d.ts +14 -0
- package/dist/core/data/core-migrations.d.ts +5 -0
- package/dist/core/data/core-schema.d.ts +6 -0
- package/dist/core/data/data-store.d.ts +67 -0
- package/dist/core/data/domain-entity-contexts.d.ts +35 -0
- package/dist/core/data/domain-schema.d.ts +36 -0
- package/dist/core/data/index.d.ts +8 -0
- package/dist/core/data/types.d.ts +111 -0
- package/dist/core/hooks/hook-bus.d.ts +24 -0
- package/dist/core/hooks/index.d.ts +2 -0
- package/dist/core/hooks/types.d.ts +19 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/llm/auto-discovery.d.ts +11 -0
- package/dist/core/llm/cost-tracker.d.ts +6 -0
- package/dist/core/llm/default-llm-call.d.ts +35 -0
- package/dist/core/llm/index.d.ts +6 -0
- package/dist/core/llm/model-router.d.ts +25 -0
- package/dist/core/llm/provider-registry.d.ts +9 -0
- package/dist/core/llm/types.d.ts +2 -0
- package/dist/core/orchestrator/adapters/api-adapter.d.ts +34 -0
- package/dist/core/orchestrator/adapters/cli-adapter.d.ts +62 -0
- package/dist/core/orchestrator/adapters/deterministic-adapter.d.ts +35 -0
- package/dist/core/orchestrator/adapters/env-whitelist.d.ts +4 -0
- package/dist/core/orchestrator/adapters/output-extractor.d.ts +11 -0
- package/dist/core/orchestrator/adapters/process-manager.d.ts +15 -0
- package/dist/core/orchestrator/adapters/tool-loop.d.ts +22 -0
- package/dist/core/orchestrator/agent-registry.d.ts +31 -0
- package/dist/core/orchestrator/budget-controller.d.ts +19 -0
- package/dist/core/orchestrator/chain-guard.d.ts +14 -0
- package/dist/core/orchestrator/circuit-breaker.d.ts +65 -0
- package/dist/core/orchestrator/claude-stream-parser.d.ts +31 -0
- package/dist/core/orchestrator/config-revisions.d.ts +6 -0
- package/dist/core/orchestrator/dependency-resolver.d.ts +20 -0
- package/dist/core/orchestrator/execution-engine.d.ts +99 -0
- package/dist/core/orchestrator/governance-gate.d.ts +110 -0
- package/dist/core/orchestrator/learning-pipeline.d.ts +112 -0
- package/dist/core/orchestrator/loop-detector.d.ts +51 -0
- package/dist/core/orchestrator/ndjson-logger.d.ts +6 -0
- package/dist/core/orchestrator/permission-relay.d.ts +72 -0
- package/dist/core/orchestrator/run-manager.d.ts +31 -0
- package/dist/core/orchestrator/scheduler.d.ts +74 -0
- package/dist/core/orchestrator/secret-store.d.ts +57 -0
- package/dist/core/orchestrator/session-manager.d.ts +13 -0
- package/dist/core/orchestrator/task-queue.d.ts +34 -0
- package/dist/core/orchestrator/template-interpolate.d.ts +5 -0
- package/dist/core/orchestrator/tools/file-ops.d.ts +12 -0
- package/dist/core/orchestrator/tools/index.d.ts +47 -0
- package/dist/core/orchestrator/tools/management.d.ts +12 -0
- package/dist/core/orchestrator/tools/messaging.d.ts +21 -0
- package/dist/core/orchestrator/tools/read-file.d.ts +5 -0
- package/dist/core/orchestrator/tools/resolve-agent.d.ts +9 -0
- package/dist/core/orchestrator/tools/roster.d.ts +16 -0
- package/dist/core/orchestrator/tools/send-file.d.ts +5 -0
- package/dist/core/orchestrator/tools/status.d.ts +20 -0
- package/dist/core/orchestrator/tools/task-ops.d.ts +13 -0
- package/dist/core/orchestrator/user-registry.d.ts +47 -0
- package/dist/core/orchestrator/wakeup-queue.d.ts +9 -0
- package/dist/core/orchestrator/workflow-engine.d.ts +47 -0
- package/dist/core/security/audit.d.ts +20 -0
- package/dist/core/security/column-validator.d.ts +20 -0
- package/dist/core/security/index.d.ts +5 -0
- package/dist/core/security/process-env.d.ts +13 -0
- package/dist/core/security/sanitizer.d.ts +11 -0
- package/dist/core/security/types.d.ts +11 -0
- package/dist/core/update/auto-update.d.ts +21 -0
- package/dist/core/update/backup-manager.d.ts +7 -0
- package/dist/core/update/index.d.ts +8 -0
- package/dist/core/update/migration-hooks.d.ts +11 -0
- package/dist/core/update/types.d.ts +11 -0
- package/dist/core/update/update-checker.d.ts +11 -0
- package/dist/core/update/update-manager.d.ts +25 -0
- package/dist/core/update/version-utils.d.ts +6 -0
- package/dist/index.d.ts +38 -2366
- package/dist/index.js +117 -10
- package/dist/providers/anthropic/index.d.ts +5 -20
- package/dist/providers/anthropic/models.d.ts +2 -0
- package/dist/providers/anthropic/provider.d.ts +13 -0
- package/dist/providers/anthropic/tool-converter.d.ts +10 -0
- package/dist/providers/ollama/index.d.ts +4 -22
- package/dist/providers/ollama/provider.d.ts +17 -0
- package/dist/providers/openai/index.d.ts +5 -20
- package/dist/providers/openai/models.d.ts +2 -0
- package/dist/providers/openai/provider.d.ts +13 -0
- package/dist/providers/openai/tool-converter.d.ts +10 -0
- package/dist/shared/constants.d.ts +50 -0
- package/dist/shared/index.d.ts +14 -0
- package/dist/shared/types/agent.d.ts +36 -0
- package/dist/{channel-CVm1AWUF.d.ts → shared/types/channel.d.ts} +13 -17
- package/dist/shared/types/config.d.ts +160 -0
- package/dist/shared/types/connector.d.ts +77 -0
- package/dist/shared/types/execution.d.ts +29 -0
- package/dist/{provider-BHkqkSdq.d.ts → shared/types/provider.d.ts} +10 -12
- package/dist/shared/types/task.d.ts +47 -0
- package/dist/shared/types/workflow.d.ts +39 -0
- package/dist/shared/utils.d.ts +6 -0
- package/dist/update-check.d.ts +5 -0
- package/package.json +3 -3
- package/dist/channel-DziSPayj.d.ts +0 -73
- package/dist/chat-pipeline-BGgmH_ap.d.ts +0 -655
- package/dist/chat-pipeline-BWrtVqEP.d.ts +0 -652
- package/dist/chat-pipeline-aBSj7a4E.d.ts +0 -655
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack filetype → AttachmentMediaType mapping.
|
|
3
|
+
*
|
|
4
|
+
* Extensible: add new entries to FILETYPE_MAP to support new formats.
|
|
5
|
+
* The categories align with observation media_type values used elsewhere
|
|
6
|
+
* in the broader platform.
|
|
7
|
+
*/
|
|
8
|
+
import type { AttachmentMediaType } from "../../shared/types/channel.js";
|
|
9
|
+
/**
|
|
10
|
+
* Map a Slack `filetype` string to an AttachmentMediaType category.
|
|
11
|
+
* Unknown types fall through to `"misc"`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function slackFiletypeToMediaType(filetype: string | undefined): AttachmentMediaType;
|
|
14
|
+
export declare function extractUrls(text: string): string[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack outbound formatting.
|
|
3
|
+
* Story 4.5
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Convert standard markdown to Slack's mrkdwn format.
|
|
7
|
+
* - **bold** → *bold*
|
|
8
|
+
* - _italic_ preserved
|
|
9
|
+
* - `code` preserved
|
|
10
|
+
* - ```code block``` preserved
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatForSlack(text: string): string;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local voice transcription via whisper-node (whisper.cpp bindings).
|
|
3
|
+
*
|
|
4
|
+
* whisper-node is an optional dependency — if not installed, transcription
|
|
5
|
+
* degrades gracefully (returns null). Requires ffmpeg on the system PATH
|
|
6
|
+
* for audio format conversion.
|
|
7
|
+
*
|
|
8
|
+
* Setup:
|
|
9
|
+
* npm install whisper-node
|
|
10
|
+
* npx whisper-node download # download a model (e.g. base.en)
|
|
11
|
+
* brew install ffmpeg # or equivalent for your platform
|
|
12
|
+
*/
|
|
13
|
+
export interface TranscribeOptions {
|
|
14
|
+
/** Whisper model name (default: "base.en"). Run `npx whisper-node download` to get models. */
|
|
15
|
+
modelName?: string;
|
|
16
|
+
/** Language code (default: "auto"). Use "en" for English-only models. */
|
|
17
|
+
language?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface TranscribeResult {
|
|
20
|
+
/** The full transcribed text */
|
|
21
|
+
text: string;
|
|
22
|
+
/** Individual segments with timestamps */
|
|
23
|
+
segments: Array<{
|
|
24
|
+
start: string;
|
|
25
|
+
end: string;
|
|
26
|
+
speech: string;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Transcribe an audio buffer using whisper-node.
|
|
31
|
+
*
|
|
32
|
+
* @param audioBuffer - Raw audio data (any format ffmpeg can decode)
|
|
33
|
+
* @param filename - Original filename (used for temp file extension)
|
|
34
|
+
* @param opts - Transcription options
|
|
35
|
+
* @returns Transcribed text, or null if transcription fails or whisper-node is not installed
|
|
36
|
+
*/
|
|
37
|
+
export declare function transcribeAudio(audioBuffer: Buffer, filename: string, opts?: TranscribeOptions): Promise<string | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Download an audio file from a URL with bearer token authentication.
|
|
40
|
+
*/
|
|
41
|
+
export declare function downloadAudio(url: string, token: string): Promise<Buffer | null>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebhookAdapter — ChannelAdapter implementation for webhook-based channels.
|
|
3
|
+
* Story 4.7
|
|
4
|
+
*/
|
|
5
|
+
import type { ChannelAdapter, ChannelCapabilities, ChannelMeta, ChannelConfig, InboundMessage, OutboundPayload, SendResult, HealthStatus } from "../../shared/index.js";
|
|
6
|
+
export declare class WebhookAdapter implements ChannelAdapter {
|
|
7
|
+
readonly id = "webhook";
|
|
8
|
+
readonly meta: ChannelMeta;
|
|
9
|
+
readonly capabilities: ChannelCapabilities;
|
|
10
|
+
onMessage?: (message: InboundMessage) => Promise<void>;
|
|
11
|
+
private connected;
|
|
12
|
+
private config;
|
|
13
|
+
private webhookServer;
|
|
14
|
+
connect(config: ChannelConfig): Promise<void>;
|
|
15
|
+
disconnect(): Promise<void>;
|
|
16
|
+
healthCheck(): Promise<HealthStatus>;
|
|
17
|
+
send(target: {
|
|
18
|
+
peerId: string;
|
|
19
|
+
threadId?: string;
|
|
20
|
+
}, payload: OutboundPayload): Promise<SendResult>;
|
|
21
|
+
}
|
|
22
|
+
/** Factory function — default export for auto-discovery. */
|
|
23
|
+
export default function createWebhookAdapter(): WebhookAdapter;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HMAC signature verification for webhook payloads.
|
|
3
|
+
* Story 4.7
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Verify that the HMAC-SHA256 signature of body matches the provided signature.
|
|
7
|
+
* Uses timing-safe comparison to prevent timing attacks.
|
|
8
|
+
*
|
|
9
|
+
* @param body - The raw request body string
|
|
10
|
+
* @param secret - The shared HMAC secret
|
|
11
|
+
* @param signature - The signature to verify (hex string, possibly prefixed with "sha256=")
|
|
12
|
+
*/
|
|
13
|
+
export declare function verifyHmac(body: string, secret: string, signature: string): boolean;
|
|
@@ -1,73 +1,10 @@
|
|
|
1
|
-
import { C as ChannelAdapter, d as ChannelMeta, b as ChannelCapabilities, I as InboundMessage, c as ChannelConfig, H as HealthStatus, O as OutboundPayload, S as SendResult } from '../../channel-CVm1AWUF.js';
|
|
2
|
-
import '../../provider-BHkqkSdq.js';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
2
|
+
* @botinabox/channel-webhook — Webhook channel adapter.
|
|
6
3
|
* Story 4.7
|
|
7
4
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
private connected;
|
|
15
|
-
private config;
|
|
16
|
-
private webhookServer;
|
|
17
|
-
connect(config: ChannelConfig): Promise<void>;
|
|
18
|
-
disconnect(): Promise<void>;
|
|
19
|
-
healthCheck(): Promise<HealthStatus>;
|
|
20
|
-
send(target: {
|
|
21
|
-
peerId: string;
|
|
22
|
-
threadId?: string;
|
|
23
|
-
}, payload: OutboundPayload): Promise<SendResult>;
|
|
24
|
-
}
|
|
25
|
-
/** Factory function — default export for auto-discovery. */
|
|
26
|
-
declare function createWebhookAdapter(): WebhookAdapter;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Minimal HTTP server for webhook inbound messages.
|
|
30
|
-
* Story 4.7
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
interface WebhookServerOpts {
|
|
34
|
-
port?: number;
|
|
35
|
-
secret?: string;
|
|
36
|
-
onMessage: (msg: InboundMessage) => Promise<void>;
|
|
37
|
-
}
|
|
38
|
-
declare class WebhookServer {
|
|
39
|
-
private server;
|
|
40
|
-
private readonly port;
|
|
41
|
-
private readonly secret;
|
|
42
|
-
private readonly onMessage;
|
|
43
|
-
constructor(opts: WebhookServerOpts);
|
|
44
|
-
start(): Promise<void>;
|
|
45
|
-
stop(): Promise<void>;
|
|
46
|
-
private handleRequest;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* HMAC signature verification for webhook payloads.
|
|
51
|
-
* Story 4.7
|
|
52
|
-
*/
|
|
53
|
-
/**
|
|
54
|
-
* Verify that the HMAC-SHA256 signature of body matches the provided signature.
|
|
55
|
-
* Uses timing-safe comparison to prevent timing attacks.
|
|
56
|
-
*
|
|
57
|
-
* @param body - The raw request body string
|
|
58
|
-
* @param secret - The shared HMAC secret
|
|
59
|
-
* @param signature - The signature to verify (hex string, possibly prefixed with "sha256=")
|
|
60
|
-
*/
|
|
61
|
-
declare function verifyHmac(body: string, secret: string, signature: string): boolean;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Webhook channel configuration types.
|
|
65
|
-
* Story 4.7
|
|
66
|
-
*/
|
|
67
|
-
interface WebhookConfig {
|
|
68
|
-
callbackUrl?: string;
|
|
69
|
-
secret?: string;
|
|
70
|
-
port?: number;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export { WebhookAdapter, type WebhookConfig, WebhookServer, type WebhookServerOpts, createWebhookAdapter as default, verifyHmac };
|
|
5
|
+
export { WebhookAdapter } from "./adapter.js";
|
|
6
|
+
export { WebhookServer } from "./server.js";
|
|
7
|
+
export type { WebhookServerOpts } from "./server.js";
|
|
8
|
+
export { verifyHmac } from "./hmac.js";
|
|
9
|
+
export type { WebhookConfig } from "./models.js";
|
|
10
|
+
export { default } from "./adapter.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal HTTP server for webhook inbound messages.
|
|
3
|
+
* Story 4.7
|
|
4
|
+
*/
|
|
5
|
+
import type { InboundMessage } from "../../shared/index.js";
|
|
6
|
+
export interface WebhookServerOpts {
|
|
7
|
+
port?: number;
|
|
8
|
+
secret?: string;
|
|
9
|
+
onMessage: (msg: InboundMessage) => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare class WebhookServer {
|
|
12
|
+
private server;
|
|
13
|
+
private readonly port;
|
|
14
|
+
private readonly secret;
|
|
15
|
+
private readonly onMessage;
|
|
16
|
+
constructor(opts: WebhookServerOpts);
|
|
17
|
+
start(): Promise<void>;
|
|
18
|
+
stop(): Promise<void>;
|
|
19
|
+
private handleRequest;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function envTemplate(channel?: string, provider?: string): string;
|
package/dist/cli.d.ts
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Drive connector — pulls file metadata from Drive.
|
|
3
|
+
*
|
|
4
|
+
* Produces `DriveFileRecord` objects. Does NOT write to any database
|
|
5
|
+
* table; the consuming application decides how to store records.
|
|
6
|
+
*
|
|
7
|
+
* Supports incremental sync via Drive Changes API (startPageToken)
|
|
8
|
+
* and full sync via files.list with optional folder/MIME filters.
|
|
9
|
+
*/
|
|
10
|
+
import type { Connector, ConnectorMeta, AuthResult, SyncOptions, SyncResult } from '../../shared/types/connector.js';
|
|
11
|
+
import type { DriveFileRecord, GoogleConnectorConfig } from './types.js';
|
|
12
|
+
export interface DriveConnectorOpts {
|
|
13
|
+
/** Load persisted tokens for a given account key (OAuth2 flow only). */
|
|
14
|
+
tokenLoader?: (key: string) => Promise<string | null>;
|
|
15
|
+
/** Persist tokens for a given account key (OAuth2 flow only). */
|
|
16
|
+
tokenSaver?: (key: string, value: string) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare class GoogleDriveConnector implements Connector<DriveFileRecord> {
|
|
19
|
+
readonly id = "google-drive";
|
|
20
|
+
readonly meta: ConnectorMeta;
|
|
21
|
+
private tokenLoader?;
|
|
22
|
+
private tokenSaver?;
|
|
23
|
+
private client;
|
|
24
|
+
private config;
|
|
25
|
+
private tokens;
|
|
26
|
+
private drive;
|
|
27
|
+
constructor(opts?: DriveConnectorOpts);
|
|
28
|
+
connect(config: GoogleConnectorConfig): Promise<void>;
|
|
29
|
+
disconnect(): Promise<void>;
|
|
30
|
+
healthCheck(): Promise<{
|
|
31
|
+
ok: boolean;
|
|
32
|
+
account?: string;
|
|
33
|
+
error?: string;
|
|
34
|
+
}>;
|
|
35
|
+
authenticate(codeProvider: (authUrl: string) => Promise<string>): Promise<AuthResult>;
|
|
36
|
+
sync(options?: SyncOptions): Promise<SyncResult<DriveFileRecord>>;
|
|
37
|
+
/** Incremental sync using Drive Changes API. */
|
|
38
|
+
private syncIncremental;
|
|
39
|
+
/** Full sync using files.list. */
|
|
40
|
+
private syncFull;
|
|
41
|
+
private ensureConnected;
|
|
42
|
+
private mapFile;
|
|
43
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Drive file read primitives — download or export files to raw bytes.
|
|
3
|
+
*
|
|
4
|
+
* Signature-agnostic primitives that produce `{ buffer, mimeType, filename }`
|
|
5
|
+
* tuples for use in attachment enrichment pipelines and other file consumers.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Raw file bytes fetched from Google Drive, plus the metadata needed to
|
|
9
|
+
* decide what to do with them (MIME type → extractor, filename → display).
|
|
10
|
+
*/
|
|
11
|
+
export interface DriveFileBytes {
|
|
12
|
+
buffer: Buffer;
|
|
13
|
+
mimeType: string;
|
|
14
|
+
filename: string;
|
|
15
|
+
/** Size in bytes as reported by the download response. */
|
|
16
|
+
size: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Supported export target formats for Google-native file types
|
|
20
|
+
* (Docs, Sheets, Slides, Drawings).
|
|
21
|
+
*/
|
|
22
|
+
export type GoogleDocExportAs = 'docx' | 'xlsx' | 'pptx' | 'png' | 'pdf' | 'txt' | 'csv' | 'html';
|
|
23
|
+
/**
|
|
24
|
+
* Download a binary Drive file as raw bytes.
|
|
25
|
+
*
|
|
26
|
+
* Use this for files uploaded to Drive in their native format (pdf, docx,
|
|
27
|
+
* xlsx, pptx, jpg, png, mp4, etc.) — anything where the Drive `mimeType`
|
|
28
|
+
* is NOT `application/vnd.google-apps.*`.
|
|
29
|
+
*
|
|
30
|
+
* For Google-native formats (Docs, Sheets, Slides, Drawings) use
|
|
31
|
+
* `exportGoogleDoc` instead — `files.get` with `alt: 'media'` fails on
|
|
32
|
+
* those with `fileNotDownloadable`.
|
|
33
|
+
*
|
|
34
|
+
* @param drive - googleapis `drive_v3.Drive` instance (kept as `any` to avoid hard type import)
|
|
35
|
+
* @param fileId - Drive file ID
|
|
36
|
+
* @returns Promise resolving to `DriveFileBytes` with buffer, mimeType, filename, and size
|
|
37
|
+
*/
|
|
38
|
+
export declare function downloadDriveFile(drive: any, fileId: string): Promise<DriveFileBytes>;
|
|
39
|
+
/**
|
|
40
|
+
* Export a Google-native document to a downloadable format.
|
|
41
|
+
*
|
|
42
|
+
* The `exportAs` argument picks the target MIME type:
|
|
43
|
+
* - docx → application/vnd.openxmlformats-officedocument.wordprocessingml.document
|
|
44
|
+
* - xlsx → application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
|
45
|
+
* - pptx → application/vnd.openxmlformats-officedocument.presentationml.presentation
|
|
46
|
+
* - png → image/png
|
|
47
|
+
* - pdf → application/pdf
|
|
48
|
+
* - txt → text/plain
|
|
49
|
+
* - csv → text/csv (only valid for spreadsheets)
|
|
50
|
+
* - html → text/html
|
|
51
|
+
*
|
|
52
|
+
* Throws if the source file is not a Google-native type, or if the
|
|
53
|
+
* requested export is not supported for that type (e.g., csv on a Doc).
|
|
54
|
+
*
|
|
55
|
+
* @param drive - googleapis `drive_v3.Drive` instance
|
|
56
|
+
* @param fileId - Drive file ID
|
|
57
|
+
* @param exportAs - Target export format
|
|
58
|
+
* @returns Promise resolving to `DriveFileBytes` with exported content
|
|
59
|
+
*/
|
|
60
|
+
export declare function exportGoogleDoc(drive: any, fileId: string, exportAs: GoogleDocExportAs): Promise<DriveFileBytes>;
|
|
61
|
+
/**
|
|
62
|
+
* High-level dispatcher. Fetches file metadata, inspects the mimeType,
|
|
63
|
+
* and picks `downloadDriveFile` (binary) or `exportGoogleDoc` (native)
|
|
64
|
+
* automatically.
|
|
65
|
+
*
|
|
66
|
+
* Google-native → exported format mapping:
|
|
67
|
+
* - Docs → docx
|
|
68
|
+
* - Sheets → xlsx
|
|
69
|
+
* - Slides → pptx
|
|
70
|
+
* - Drawings → png
|
|
71
|
+
* - Scripts → throws (not supported)
|
|
72
|
+
* - Forms/Site → throws (not supported)
|
|
73
|
+
*
|
|
74
|
+
* Consumers that want a different export target (e.g., gdoc → pdf for
|
|
75
|
+
* Claude's native PDF reading) should call `exportGoogleDoc` directly.
|
|
76
|
+
*
|
|
77
|
+
* @param drive - googleapis `drive_v3.Drive` instance
|
|
78
|
+
* @param fileId - Drive file ID
|
|
79
|
+
* @returns Promise resolving to `DriveFileBytes` with automatically chosen format
|
|
80
|
+
*/
|
|
81
|
+
export declare function readDriveFile(drive: any, fileId: string): Promise<DriveFileBytes>;
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
}
|