botinabox 1.8.1 → 1.8.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/dist/channels/discord/adapter.d.ts +32 -0
- package/dist/channels/discord/adapter.js +70 -0
- package/dist/channels/discord/inbound.d.ts +25 -0
- package/dist/channels/discord/inbound.js +24 -0
- package/dist/channels/discord/models.d.ts +8 -0
- package/dist/channels/discord/models.js +5 -0
- package/dist/channels/discord/outbound.d.ts +14 -0
- package/dist/channels/discord/outbound.js +38 -0
- package/dist/channels/slack/adapter.d.ts +33 -0
- package/dist/channels/slack/adapter.js +74 -0
- package/dist/channels/slack/inbound.d.ts +59 -0
- package/dist/channels/slack/inbound.js +96 -0
- package/dist/channels/slack/models.d.ts +9 -0
- package/dist/channels/slack/models.js +5 -0
- package/dist/channels/slack/outbound.d.ts +12 -0
- package/dist/channels/slack/outbound.js +18 -0
- package/dist/channels/slack/transcribe.d.ts +41 -0
- package/dist/channels/slack/transcribe.js +106 -0
- package/dist/channels/webhook/adapter.d.ts +23 -0
- package/dist/channels/webhook/adapter.js +86 -0
- package/dist/channels/webhook/hmac.d.ts +13 -0
- package/dist/channels/webhook/hmac.js +26 -0
- package/dist/channels/webhook/models.d.ts +9 -0
- package/dist/channels/webhook/models.js +5 -0
- package/dist/channels/webhook/server.d.ts +20 -0
- package/dist/channels/webhook/server.js +91 -0
- package/dist/cli/templates/config.yml.d.ts +7 -0
- package/dist/cli/templates/config.yml.js +61 -0
- package/dist/cli/templates/env.d.ts +1 -0
- package/dist/cli/templates/env.js +30 -0
- package/dist/cli/templates/index.ts.d.ts +2 -0
- package/dist/cli/templates/index.ts.js +30 -0
- package/dist/cli/templates/package.json.d.ts +5 -0
- package/dist/cli/templates/package.json.js +28 -0
- package/dist/connectors/google/calendar-connector.d.ts +40 -0
- package/dist/connectors/google/calendar-connector.js +243 -0
- package/dist/connectors/google/gmail-connector.d.ts +42 -0
- package/dist/connectors/google/gmail-connector.js +345 -0
- package/dist/connectors/google/oauth.d.ts +48 -0
- package/dist/connectors/google/oauth.js +112 -0
- package/dist/connectors/google/types.d.ts +78 -0
- package/dist/connectors/google/types.js +2 -0
- package/dist/core/chat/auto-discovery.d.ts +16 -0
- package/dist/core/chat/auto-discovery.js +54 -0
- package/dist/core/chat/channel-registry.d.ts +45 -0
- package/dist/core/chat/channel-registry.js +96 -0
- package/dist/core/chat/chat-pipeline.d.ts +104 -0
- package/dist/core/chat/chat-pipeline.js +282 -0
- package/dist/core/chat/chat-responder.d.ts +90 -0
- package/dist/core/chat/chat-responder.js +185 -0
- package/dist/core/chat/formatter.d.ts +11 -0
- package/dist/core/chat/formatter.js +60 -0
- package/dist/core/chat/index.d.ts +24 -0
- package/dist/core/chat/index.js +18 -0
- package/dist/core/chat/message-interpreter.d.ts +91 -0
- package/dist/core/chat/message-interpreter.js +164 -0
- package/dist/core/chat/message-store.d.ts +66 -0
- package/dist/core/chat/message-store.js +131 -0
- package/dist/core/chat/notification-queue.d.ts +34 -0
- package/dist/core/chat/notification-queue.js +111 -0
- package/dist/core/chat/pipeline.d.ts +38 -0
- package/dist/core/chat/pipeline.js +89 -0
- package/dist/core/chat/policies.d.ts +16 -0
- package/dist/core/chat/policies.js +25 -0
- package/dist/core/chat/routing.d.ts +17 -0
- package/dist/core/chat/routing.js +36 -0
- package/dist/core/chat/session-key.d.ts +30 -0
- package/dist/core/chat/session-key.js +65 -0
- package/dist/core/chat/session-manager.d.ts +17 -0
- package/dist/core/chat/session-manager.js +23 -0
- package/dist/core/chat/text-chunker.d.ts +9 -0
- package/dist/core/chat/text-chunker.js +48 -0
- package/dist/core/chat/triage-router.d.ts +75 -0
- package/dist/core/chat/triage-router.js +142 -0
- package/dist/core/chat/types.d.ts +5 -0
- package/dist/core/chat/types.js +5 -0
- package/dist/core/config/defaults.d.ts +2 -0
- package/dist/core/config/defaults.js +38 -0
- package/dist/core/config/index.d.ts +6 -0
- package/dist/core/config/index.js +4 -0
- package/dist/core/config/interpolate.d.ts +5 -0
- package/dist/core/config/interpolate.js +27 -0
- package/dist/core/config/loader.d.ts +24 -0
- package/dist/core/config/loader.js +59 -0
- package/dist/core/config/schema.d.ts +5 -0
- package/dist/core/config/schema.js +119 -0
- package/dist/core/data/core-entity-contexts.d.ts +14 -0
- package/dist/core/data/core-entity-contexts.js +197 -0
- package/dist/core/data/core-migrations.d.ts +5 -0
- package/dist/core/data/core-migrations.js +45 -0
- package/dist/core/data/core-schema.d.ts +6 -0
- package/dist/core/data/core-schema.js +454 -0
- package/dist/core/data/data-store.d.ts +67 -0
- package/dist/core/data/data-store.js +218 -0
- package/dist/core/data/domain-entity-contexts.d.ts +29 -0
- package/dist/core/data/domain-entity-contexts.js +321 -0
- package/dist/core/data/domain-schema.d.ts +36 -0
- package/dist/core/data/domain-schema.js +323 -0
- package/dist/core/data/index.d.ts +7 -0
- package/dist/core/data/index.js +7 -0
- package/dist/core/data/types.d.ts +111 -0
- package/dist/core/data/types.js +1 -0
- package/dist/core/hooks/hook-bus.d.ts +18 -0
- package/dist/core/hooks/hook-bus.js +120 -0
- package/dist/core/hooks/index.d.ts +2 -0
- package/dist/core/hooks/index.js +1 -0
- package/dist/core/hooks/types.d.ts +19 -0
- package/dist/core/hooks/types.js +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +4 -0
- package/dist/core/llm/auto-discovery.d.ts +11 -0
- package/dist/core/llm/auto-discovery.js +49 -0
- package/dist/core/llm/cost-tracker.d.ts +6 -0
- package/dist/core/llm/cost-tracker.js +38 -0
- package/dist/core/llm/index.d.ts +4 -0
- package/dist/core/llm/index.js +3 -0
- package/dist/core/llm/model-router.d.ts +25 -0
- package/dist/core/llm/model-router.js +49 -0
- package/dist/core/llm/provider-registry.d.ts +9 -0
- package/dist/core/llm/provider-registry.js +25 -0
- package/dist/core/llm/types.d.ts +2 -0
- package/dist/core/llm/types.js +2 -0
- package/dist/core/orchestrator/adapters/api-adapter.d.ts +34 -0
- package/dist/core/orchestrator/adapters/api-adapter.js +88 -0
- package/dist/core/orchestrator/adapters/cli-adapter.d.ts +22 -0
- package/dist/core/orchestrator/adapters/cli-adapter.js +69 -0
- package/dist/core/orchestrator/adapters/deterministic-adapter.d.ts +35 -0
- package/dist/core/orchestrator/adapters/deterministic-adapter.js +75 -0
- package/dist/core/orchestrator/adapters/env-whitelist.d.ts +4 -0
- package/dist/core/orchestrator/adapters/env-whitelist.js +27 -0
- package/dist/core/orchestrator/adapters/output-extractor.d.ts +11 -0
- package/dist/core/orchestrator/adapters/output-extractor.js +59 -0
- package/dist/core/orchestrator/adapters/process-manager.d.ts +15 -0
- package/dist/core/orchestrator/adapters/process-manager.js +26 -0
- package/dist/core/orchestrator/adapters/tool-loop.d.ts +22 -0
- package/dist/core/orchestrator/adapters/tool-loop.js +66 -0
- package/dist/core/orchestrator/agent-registry.d.ts +31 -0
- package/dist/core/orchestrator/agent-registry.js +135 -0
- package/dist/core/orchestrator/budget-controller.d.ts +19 -0
- package/dist/core/orchestrator/budget-controller.js +73 -0
- package/dist/core/orchestrator/chain-guard.d.ts +14 -0
- package/dist/core/orchestrator/chain-guard.js +23 -0
- package/dist/core/orchestrator/circuit-breaker.d.ts +65 -0
- package/dist/core/orchestrator/circuit-breaker.js +159 -0
- package/dist/core/orchestrator/claude-stream-parser.d.ts +31 -0
- package/dist/core/orchestrator/claude-stream-parser.js +99 -0
- package/dist/core/orchestrator/config-revisions.d.ts +6 -0
- package/dist/core/orchestrator/config-revisions.js +17 -0
- package/dist/core/orchestrator/dependency-resolver.d.ts +20 -0
- package/dist/core/orchestrator/dependency-resolver.js +78 -0
- package/dist/core/orchestrator/governance-gate.d.ts +110 -0
- package/dist/core/orchestrator/governance-gate.js +170 -0
- package/dist/core/orchestrator/learning-pipeline.d.ts +109 -0
- package/dist/core/orchestrator/learning-pipeline.js +249 -0
- package/dist/core/orchestrator/loop-detector.d.ts +51 -0
- package/dist/core/orchestrator/loop-detector.js +133 -0
- package/dist/core/orchestrator/ndjson-logger.d.ts +6 -0
- package/dist/core/orchestrator/ndjson-logger.js +18 -0
- package/dist/core/orchestrator/permission-relay.d.ts +72 -0
- package/dist/core/orchestrator/permission-relay.js +164 -0
- package/dist/core/orchestrator/run-manager.d.ts +31 -0
- package/dist/core/orchestrator/run-manager.js +178 -0
- package/dist/core/orchestrator/scheduler.d.ts +70 -0
- package/dist/core/orchestrator/scheduler.js +198 -0
- package/dist/core/orchestrator/secret-store.d.ts +57 -0
- package/dist/core/orchestrator/secret-store.js +171 -0
- package/dist/core/orchestrator/session-manager.d.ts +13 -0
- package/dist/core/orchestrator/session-manager.js +66 -0
- package/dist/core/orchestrator/task-queue.d.ts +34 -0
- package/dist/core/orchestrator/task-queue.js +83 -0
- package/dist/core/orchestrator/template-interpolate.d.ts +5 -0
- package/dist/core/orchestrator/template-interpolate.js +18 -0
- package/dist/core/orchestrator/user-registry.d.ts +47 -0
- package/dist/core/orchestrator/user-registry.js +76 -0
- package/dist/core/orchestrator/wakeup-queue.d.ts +9 -0
- package/dist/core/orchestrator/wakeup-queue.js +45 -0
- package/dist/core/orchestrator/workflow-engine.d.ts +47 -0
- package/dist/core/orchestrator/workflow-engine.js +204 -0
- package/dist/core/security/audit.d.ts +20 -0
- package/dist/core/security/audit.js +33 -0
- package/dist/core/security/column-validator.d.ts +20 -0
- package/dist/core/security/column-validator.js +37 -0
- package/dist/core/security/index.d.ts +5 -0
- package/dist/core/security/index.js +5 -0
- package/dist/core/security/process-env.d.ts +13 -0
- package/dist/core/security/process-env.js +49 -0
- package/dist/core/security/sanitizer.d.ts +11 -0
- package/dist/core/security/sanitizer.js +39 -0
- package/dist/core/security/types.d.ts +11 -0
- package/dist/core/security/types.js +1 -0
- package/dist/core/update/auto-update.d.ts +21 -0
- package/dist/core/update/auto-update.js +102 -0
- package/dist/core/update/backup-manager.d.ts +7 -0
- package/dist/core/update/backup-manager.js +24 -0
- package/dist/core/update/index.d.ts +8 -0
- package/dist/core/update/index.js +6 -0
- package/dist/core/update/migration-hooks.d.ts +11 -0
- package/dist/core/update/migration-hooks.js +10 -0
- package/dist/core/update/types.d.ts +11 -0
- package/dist/core/update/types.js +1 -0
- package/dist/core/update/update-checker.d.ts +11 -0
- package/dist/core/update/update-checker.js +63 -0
- package/dist/core/update/update-manager.d.ts +25 -0
- package/dist/core/update/update-manager.js +101 -0
- package/dist/core/update/version-utils.d.ts +6 -0
- package/dist/core/update/version-utils.js +34 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +47 -14
- package/dist/providers/anthropic/models.d.ts +2 -0
- package/dist/providers/anthropic/models.js +29 -0
- package/dist/providers/anthropic/provider.d.ts +13 -0
- package/dist/providers/anthropic/provider.js +119 -0
- package/dist/providers/anthropic/tool-converter.d.ts +10 -0
- package/dist/providers/anthropic/tool-converter.js +7 -0
- package/dist/providers/ollama/provider.d.ts +17 -0
- package/dist/providers/ollama/provider.js +185 -0
- package/dist/providers/openai/models.d.ts +2 -0
- package/dist/providers/openai/models.js +29 -0
- package/dist/providers/openai/provider.d.ts +13 -0
- package/dist/providers/openai/provider.js +163 -0
- package/dist/providers/openai/tool-converter.d.ts +10 -0
- package/dist/providers/openai/tool-converter.js +10 -0
- package/dist/shared/constants.d.ts +50 -0
- package/dist/shared/constants.js +64 -0
- package/dist/shared/index.d.ts +14 -0
- package/dist/shared/index.js +14 -0
- package/dist/shared/types/agent.d.ts +36 -0
- package/dist/shared/types/agent.js +2 -0
- package/dist/shared/types/channel.d.ts +70 -0
- package/dist/shared/types/channel.js +2 -0
- package/dist/shared/types/config.d.ts +111 -0
- package/dist/shared/types/config.js +2 -0
- package/dist/shared/types/connector.d.ts +77 -0
- package/dist/shared/types/connector.js +2 -0
- package/dist/shared/types/execution.d.ts +29 -0
- package/dist/shared/types/execution.js +2 -0
- package/dist/shared/types/provider.d.ts +73 -0
- package/dist/shared/types/provider.js +2 -0
- package/dist/shared/types/task.d.ts +47 -0
- package/dist/shared/types/task.js +2 -0
- package/dist/shared/types/workflow.d.ts +39 -0
- package/dist/shared/types/workflow.js +2 -0
- package/dist/shared/utils.d.ts +6 -0
- package/dist/shared/utils.js +13 -0
- package/dist/update-check.d.ts +5 -0
- package/dist/update-check.js +56 -0
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DiscordAdapter — ChannelAdapter implementation for Discord.
|
|
3
|
+
* Story 4.6
|
|
4
|
+
*/
|
|
5
|
+
import type { ChannelAdapter, ChannelCapabilities, ChannelMeta, ChannelConfig, InboundMessage, OutboundPayload, SendResult, HealthStatus } from "../../shared/index.js";
|
|
6
|
+
/** Minimal Discord client interface for mockability. */
|
|
7
|
+
export interface DiscordClient {
|
|
8
|
+
sendMessage(channelId: string, content: string): Promise<{
|
|
9
|
+
id: string;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export declare class DiscordAdapter implements ChannelAdapter {
|
|
13
|
+
readonly id = "discord";
|
|
14
|
+
readonly meta: ChannelMeta;
|
|
15
|
+
readonly capabilities: ChannelCapabilities;
|
|
16
|
+
onMessage?: (message: InboundMessage) => Promise<void>;
|
|
17
|
+
private connected;
|
|
18
|
+
private config;
|
|
19
|
+
private client;
|
|
20
|
+
constructor(client?: DiscordClient);
|
|
21
|
+
connect(config: ChannelConfig): Promise<void>;
|
|
22
|
+
disconnect(): Promise<void>;
|
|
23
|
+
healthCheck(): Promise<HealthStatus>;
|
|
24
|
+
send(target: {
|
|
25
|
+
peerId: string;
|
|
26
|
+
threadId?: string;
|
|
27
|
+
}, payload: OutboundPayload): Promise<SendResult>;
|
|
28
|
+
/** Simulate receiving an inbound message (for testing/webhooks). */
|
|
29
|
+
receive(event: Record<string, unknown>): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/** Factory function — default export for auto-discovery. */
|
|
32
|
+
export default function createDiscordAdapter(client?: DiscordClient): DiscordAdapter;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DiscordAdapter — ChannelAdapter implementation for Discord.
|
|
3
|
+
* Story 4.6
|
|
4
|
+
*/
|
|
5
|
+
import { formatForDiscord } from "./outbound.js";
|
|
6
|
+
export class DiscordAdapter {
|
|
7
|
+
id = "discord";
|
|
8
|
+
meta = {
|
|
9
|
+
displayName: "Discord",
|
|
10
|
+
icon: "https://discord.com/favicon.ico",
|
|
11
|
+
homepage: "https://discord.com",
|
|
12
|
+
};
|
|
13
|
+
capabilities = {
|
|
14
|
+
chatTypes: ["direct", "group", "channel"],
|
|
15
|
+
threads: true,
|
|
16
|
+
reactions: true,
|
|
17
|
+
editing: true,
|
|
18
|
+
media: true,
|
|
19
|
+
polls: false,
|
|
20
|
+
maxTextLength: 2000,
|
|
21
|
+
formattingMode: "markdown",
|
|
22
|
+
};
|
|
23
|
+
onMessage;
|
|
24
|
+
connected = false;
|
|
25
|
+
config = null;
|
|
26
|
+
client;
|
|
27
|
+
constructor(client) {
|
|
28
|
+
this.client = client ?? null;
|
|
29
|
+
}
|
|
30
|
+
async connect(config) {
|
|
31
|
+
this.config = config;
|
|
32
|
+
this.connected = true;
|
|
33
|
+
}
|
|
34
|
+
async disconnect() {
|
|
35
|
+
this.connected = false;
|
|
36
|
+
this.config = null;
|
|
37
|
+
}
|
|
38
|
+
async healthCheck() {
|
|
39
|
+
return { ok: this.connected };
|
|
40
|
+
}
|
|
41
|
+
async send(target, payload) {
|
|
42
|
+
if (!this.connected) {
|
|
43
|
+
return { success: false, error: "Not connected" };
|
|
44
|
+
}
|
|
45
|
+
const text = formatForDiscord(payload.text);
|
|
46
|
+
if (this.client) {
|
|
47
|
+
try {
|
|
48
|
+
const result = await this.client.sendMessage(target.peerId, text);
|
|
49
|
+
return { success: true, messageId: result.id };
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
return { success: false, error: String(err) };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// No-op when no client provided
|
|
56
|
+
return { success: true };
|
|
57
|
+
}
|
|
58
|
+
/** Simulate receiving an inbound message (for testing/webhooks). */
|
|
59
|
+
async receive(event) {
|
|
60
|
+
if (this.onMessage) {
|
|
61
|
+
const { parseDiscordEvent } = await import("./inbound.js");
|
|
62
|
+
const msg = parseDiscordEvent(event);
|
|
63
|
+
await this.onMessage(msg);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Factory function — default export for auto-discovery. */
|
|
68
|
+
export default function createDiscordAdapter(client) {
|
|
69
|
+
return new DiscordAdapter(client);
|
|
70
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord inbound message parsing.
|
|
3
|
+
* Story 4.6
|
|
4
|
+
*/
|
|
5
|
+
import type { InboundMessage } from "../../shared/index.js";
|
|
6
|
+
export interface DiscordEvent {
|
|
7
|
+
id?: string;
|
|
8
|
+
channel_id?: string;
|
|
9
|
+
guild_id?: string;
|
|
10
|
+
author?: {
|
|
11
|
+
id?: string;
|
|
12
|
+
username?: string;
|
|
13
|
+
};
|
|
14
|
+
content?: string;
|
|
15
|
+
message_reference?: {
|
|
16
|
+
message_id?: string;
|
|
17
|
+
channel_id?: string;
|
|
18
|
+
};
|
|
19
|
+
timestamp?: string;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parse a Discord message event into an InboundMessage.
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseDiscordEvent(event: DiscordEvent): InboundMessage;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord inbound message parsing.
|
|
3
|
+
* Story 4.6
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Parse a Discord message event into an InboundMessage.
|
|
7
|
+
*/
|
|
8
|
+
export function parseDiscordEvent(event) {
|
|
9
|
+
const id = event.id ?? `discord-${Date.now()}`;
|
|
10
|
+
const channel = event.channel_id ?? "unknown";
|
|
11
|
+
const from = event.author?.id ?? "unknown";
|
|
12
|
+
const body = event.content ?? "";
|
|
13
|
+
const replyToId = event.message_reference?.message_id;
|
|
14
|
+
const receivedAt = event.timestamp ?? new Date().toISOString();
|
|
15
|
+
return {
|
|
16
|
+
id,
|
|
17
|
+
channel,
|
|
18
|
+
from,
|
|
19
|
+
body,
|
|
20
|
+
replyToId,
|
|
21
|
+
receivedAt,
|
|
22
|
+
raw: event,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord outbound formatting.
|
|
3
|
+
* Discord uses native markdown — just enforce the 2000-char limit.
|
|
4
|
+
* Story 4.6
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Split text into Discord-compatible chunks (2000 char max each).
|
|
8
|
+
*/
|
|
9
|
+
export declare function chunkForDiscord(text: string): string[];
|
|
10
|
+
/**
|
|
11
|
+
* Discord uses native markdown — no conversion needed.
|
|
12
|
+
* Returns the text unchanged (Discord renders it natively).
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatForDiscord(text: string): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord outbound formatting.
|
|
3
|
+
* Discord uses native markdown — just enforce the 2000-char limit.
|
|
4
|
+
* Story 4.6
|
|
5
|
+
*/
|
|
6
|
+
const DISCORD_MAX_LENGTH = 2000;
|
|
7
|
+
/**
|
|
8
|
+
* Split text into Discord-compatible chunks (2000 char max each).
|
|
9
|
+
*/
|
|
10
|
+
export function chunkForDiscord(text) {
|
|
11
|
+
if (text.length <= DISCORD_MAX_LENGTH)
|
|
12
|
+
return [text];
|
|
13
|
+
const chunks = [];
|
|
14
|
+
let remaining = text;
|
|
15
|
+
while (remaining.length > DISCORD_MAX_LENGTH) {
|
|
16
|
+
// Try to split at a word boundary
|
|
17
|
+
const slice = remaining.slice(0, DISCORD_MAX_LENGTH);
|
|
18
|
+
const lastSpace = slice.lastIndexOf(" ");
|
|
19
|
+
if (lastSpace > 0) {
|
|
20
|
+
chunks.push(remaining.slice(0, lastSpace));
|
|
21
|
+
remaining = remaining.slice(lastSpace + 1);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
chunks.push(remaining.slice(0, DISCORD_MAX_LENGTH));
|
|
25
|
+
remaining = remaining.slice(DISCORD_MAX_LENGTH);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (remaining.length > 0)
|
|
29
|
+
chunks.push(remaining);
|
|
30
|
+
return chunks;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Discord uses native markdown — no conversion needed.
|
|
34
|
+
* Returns the text unchanged (Discord renders it natively).
|
|
35
|
+
*/
|
|
36
|
+
export function formatForDiscord(text) {
|
|
37
|
+
return text;
|
|
38
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SlackAdapter — ChannelAdapter implementation for Slack.
|
|
3
|
+
* Story 4.5
|
|
4
|
+
*/
|
|
5
|
+
import type { ChannelAdapter, ChannelCapabilities, ChannelMeta, ChannelConfig, InboundMessage, OutboundPayload, SendResult, HealthStatus } from "../../shared/index.js";
|
|
6
|
+
/** Minimal Bolt-compatible client interface for mockability. */
|
|
7
|
+
export interface BoltClient {
|
|
8
|
+
postMessage(channel: string, text: string, threadTs?: string): Promise<{
|
|
9
|
+
ok: boolean;
|
|
10
|
+
ts?: string;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
export declare class SlackAdapter implements ChannelAdapter {
|
|
14
|
+
readonly id = "slack";
|
|
15
|
+
readonly meta: ChannelMeta;
|
|
16
|
+
readonly capabilities: ChannelCapabilities;
|
|
17
|
+
onMessage?: (message: InboundMessage) => Promise<void>;
|
|
18
|
+
private connected;
|
|
19
|
+
private config;
|
|
20
|
+
private client;
|
|
21
|
+
constructor(client?: BoltClient);
|
|
22
|
+
connect(config: ChannelConfig): Promise<void>;
|
|
23
|
+
disconnect(): Promise<void>;
|
|
24
|
+
healthCheck(): Promise<HealthStatus>;
|
|
25
|
+
send(target: {
|
|
26
|
+
peerId: string;
|
|
27
|
+
threadId?: string;
|
|
28
|
+
}, payload: OutboundPayload): Promise<SendResult>;
|
|
29
|
+
/** Simulate receiving an inbound message (for testing/webhooks). */
|
|
30
|
+
receive(event: Record<string, unknown>): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
/** Factory function — default export for auto-discovery. */
|
|
33
|
+
export default function createSlackAdapter(client?: BoltClient): SlackAdapter;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SlackAdapter — ChannelAdapter implementation for Slack.
|
|
3
|
+
* Story 4.5
|
|
4
|
+
*/
|
|
5
|
+
import { formatForSlack } from "./outbound.js";
|
|
6
|
+
export class SlackAdapter {
|
|
7
|
+
id = "slack";
|
|
8
|
+
meta = {
|
|
9
|
+
displayName: "Slack",
|
|
10
|
+
icon: "https://slack.com/favicon.ico",
|
|
11
|
+
homepage: "https://slack.com",
|
|
12
|
+
};
|
|
13
|
+
capabilities = {
|
|
14
|
+
chatTypes: ["direct", "group", "channel"],
|
|
15
|
+
threads: true,
|
|
16
|
+
reactions: true,
|
|
17
|
+
editing: true,
|
|
18
|
+
media: true,
|
|
19
|
+
polls: false,
|
|
20
|
+
maxTextLength: 40_000,
|
|
21
|
+
formattingMode: "mrkdwn",
|
|
22
|
+
};
|
|
23
|
+
onMessage;
|
|
24
|
+
connected = false;
|
|
25
|
+
config = null;
|
|
26
|
+
client;
|
|
27
|
+
constructor(client) {
|
|
28
|
+
this.client = client ?? null;
|
|
29
|
+
}
|
|
30
|
+
async connect(config) {
|
|
31
|
+
this.config = config;
|
|
32
|
+
this.connected = true;
|
|
33
|
+
}
|
|
34
|
+
async disconnect() {
|
|
35
|
+
this.connected = false;
|
|
36
|
+
this.config = null;
|
|
37
|
+
}
|
|
38
|
+
async healthCheck() {
|
|
39
|
+
return { ok: this.connected };
|
|
40
|
+
}
|
|
41
|
+
async send(target, payload) {
|
|
42
|
+
if (!this.connected) {
|
|
43
|
+
return { success: false, error: "Not connected" };
|
|
44
|
+
}
|
|
45
|
+
const text = formatForSlack(payload.text);
|
|
46
|
+
if (this.client) {
|
|
47
|
+
try {
|
|
48
|
+
const result = await this.client.postMessage(target.peerId, text, target.threadId);
|
|
49
|
+
return { success: result.ok, messageId: result.ts };
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
return { success: false, error: String(err) };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// No-op when no client provided
|
|
56
|
+
return { success: true };
|
|
57
|
+
}
|
|
58
|
+
/** Simulate receiving an inbound message (for testing/webhooks). */
|
|
59
|
+
async receive(event) {
|
|
60
|
+
if (this.onMessage) {
|
|
61
|
+
const { parseSlackEvent } = await import("./inbound.js");
|
|
62
|
+
const { enrichVoiceMessage } = await import("./inbound.js");
|
|
63
|
+
let msg = parseSlackEvent(event);
|
|
64
|
+
if (msg.body.includes("[Voice message") && this.config?.botToken) {
|
|
65
|
+
msg = await enrichVoiceMessage(msg, this.config.botToken);
|
|
66
|
+
}
|
|
67
|
+
await this.onMessage(msg);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** Factory function — default export for auto-discovery. */
|
|
72
|
+
export default function createSlackAdapter(client) {
|
|
73
|
+
return new SlackAdapter(client);
|
|
74
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack inbound message parsing.
|
|
3
|
+
* Story 4.5
|
|
4
|
+
*/
|
|
5
|
+
import type { InboundMessage } from "../../shared/index.js";
|
|
6
|
+
export interface SlackFile {
|
|
7
|
+
id?: string;
|
|
8
|
+
filetype?: string;
|
|
9
|
+
subtype?: string;
|
|
10
|
+
url_private?: string;
|
|
11
|
+
preview?: string;
|
|
12
|
+
transcription?: {
|
|
13
|
+
status?: string;
|
|
14
|
+
preview?: {
|
|
15
|
+
content?: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface SlackEvent {
|
|
21
|
+
type: string;
|
|
22
|
+
subtype?: string;
|
|
23
|
+
client_msg_id?: string;
|
|
24
|
+
ts?: string;
|
|
25
|
+
event_ts?: string;
|
|
26
|
+
channel?: string;
|
|
27
|
+
user?: string;
|
|
28
|
+
text?: string;
|
|
29
|
+
thread_ts?: string;
|
|
30
|
+
files?: SlackFile[];
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Extract the text content from a voice message file.
|
|
35
|
+
* Prefers the transcription preview; falls back to the file preview text.
|
|
36
|
+
* Returns null if the file is not a voice message or has no transcript.
|
|
37
|
+
*/
|
|
38
|
+
export declare function extractVoiceTranscript(file: SlackFile): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* Parse a Slack event into an InboundMessage.
|
|
41
|
+
*
|
|
42
|
+
* Handles standard text messages and voice messages (file_share subtype
|
|
43
|
+
* with audio files). Voice message transcripts are extracted and prefixed
|
|
44
|
+
* with `[Voice message]`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseSlackEvent(event: SlackEvent): InboundMessage;
|
|
47
|
+
/**
|
|
48
|
+
* Enrich a voice message with local transcription when Slack's built-in
|
|
49
|
+
* transcription is unavailable.
|
|
50
|
+
*
|
|
51
|
+
* Downloads the audio file from Slack using the bot token, converts to WAV,
|
|
52
|
+
* and transcribes locally via whisper-node. Returns the original message
|
|
53
|
+
* unchanged if transcription fails or is not needed.
|
|
54
|
+
*
|
|
55
|
+
* @param msg - The parsed inbound message (from parseSlackEvent)
|
|
56
|
+
* @param botToken - Slack bot token for authenticated file download
|
|
57
|
+
* @returns The message with body replaced by transcript, or original on failure
|
|
58
|
+
*/
|
|
59
|
+
export declare function enrichVoiceMessage(msg: InboundMessage, botToken: string): Promise<InboundMessage>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack inbound message parsing.
|
|
3
|
+
* Story 4.5
|
|
4
|
+
*/
|
|
5
|
+
import { transcribeAudio, downloadAudio } from "./transcribe.js";
|
|
6
|
+
const AUDIO_TYPES = new Set(["aac", "mp4", "m4a", "ogg", "webm", "mp3", "wav"]);
|
|
7
|
+
/**
|
|
8
|
+
* Extract the text content from a voice message file.
|
|
9
|
+
* Prefers the transcription preview; falls back to the file preview text.
|
|
10
|
+
* Returns null if the file is not a voice message or has no transcript.
|
|
11
|
+
*/
|
|
12
|
+
export function extractVoiceTranscript(file) {
|
|
13
|
+
const isAudio = file.subtype === "slack_audio" || AUDIO_TYPES.has(file.filetype ?? "");
|
|
14
|
+
if (!isAudio)
|
|
15
|
+
return null;
|
|
16
|
+
const transcript = file.transcription?.preview?.content ??
|
|
17
|
+
(typeof file.preview === "string" ? file.preview : null);
|
|
18
|
+
return transcript ?? null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Parse a Slack event into an InboundMessage.
|
|
22
|
+
*
|
|
23
|
+
* Handles standard text messages and voice messages (file_share subtype
|
|
24
|
+
* with audio files). Voice message transcripts are extracted and prefixed
|
|
25
|
+
* with `[Voice message]`.
|
|
26
|
+
*/
|
|
27
|
+
export function parseSlackEvent(event) {
|
|
28
|
+
const id = event.client_msg_id ?? event.ts ?? event.event_ts ?? `slack-${Date.now()}`;
|
|
29
|
+
const channel = event.channel ?? "unknown";
|
|
30
|
+
const from = event.user ?? "unknown";
|
|
31
|
+
const threadId = event.thread_ts !== undefined ? event.thread_ts : undefined;
|
|
32
|
+
const receivedAt = event.ts
|
|
33
|
+
? new Date(parseFloat(event.ts) * 1000).toISOString()
|
|
34
|
+
: new Date().toISOString();
|
|
35
|
+
let body = event.text ?? "";
|
|
36
|
+
// Voice messages: extract transcript from audio file attachments
|
|
37
|
+
if (event.subtype === "file_share" && event.files?.length) {
|
|
38
|
+
for (const file of event.files) {
|
|
39
|
+
const transcript = extractVoiceTranscript(file);
|
|
40
|
+
if (transcript) {
|
|
41
|
+
body = body ? `${body}\n\n[Voice message] ${transcript}` : `[Voice message] ${transcript}`;
|
|
42
|
+
break; // Only one voice message per event
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// If voice message had no Slack transcript, mark for local transcription
|
|
47
|
+
if (event.subtype === "file_share" && event.files?.length && !body) {
|
|
48
|
+
const hasAudio = event.files.some((f) => f.subtype === "slack_audio" || AUDIO_TYPES.has(f.filetype ?? ""));
|
|
49
|
+
if (hasAudio) {
|
|
50
|
+
body = "[Voice message — no transcript available]";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
id,
|
|
55
|
+
channel,
|
|
56
|
+
from,
|
|
57
|
+
body,
|
|
58
|
+
threadId,
|
|
59
|
+
receivedAt,
|
|
60
|
+
raw: event,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Enrich a voice message with local transcription when Slack's built-in
|
|
65
|
+
* transcription is unavailable.
|
|
66
|
+
*
|
|
67
|
+
* Downloads the audio file from Slack using the bot token, converts to WAV,
|
|
68
|
+
* and transcribes locally via whisper-node. Returns the original message
|
|
69
|
+
* unchanged if transcription fails or is not needed.
|
|
70
|
+
*
|
|
71
|
+
* @param msg - The parsed inbound message (from parseSlackEvent)
|
|
72
|
+
* @param botToken - Slack bot token for authenticated file download
|
|
73
|
+
* @returns The message with body replaced by transcript, or original on failure
|
|
74
|
+
*/
|
|
75
|
+
export async function enrichVoiceMessage(msg, botToken) {
|
|
76
|
+
if (!msg.body.includes("[Voice message — no transcript available]"))
|
|
77
|
+
return msg;
|
|
78
|
+
const raw = msg.raw;
|
|
79
|
+
const files = raw?.files;
|
|
80
|
+
if (!files?.length)
|
|
81
|
+
return msg;
|
|
82
|
+
const audioFile = files.find((f) => f.subtype === "slack_audio" || AUDIO_TYPES.has(f.filetype ?? ""));
|
|
83
|
+
if (!audioFile?.url_private)
|
|
84
|
+
return msg;
|
|
85
|
+
const buffer = await downloadAudio(audioFile.url_private, botToken);
|
|
86
|
+
if (!buffer)
|
|
87
|
+
return msg;
|
|
88
|
+
const filename = audioFile.name ?? `voice.${audioFile.filetype ?? "aac"}`;
|
|
89
|
+
const transcript = await transcribeAudio(buffer, filename);
|
|
90
|
+
if (!transcript)
|
|
91
|
+
return msg;
|
|
92
|
+
return {
|
|
93
|
+
...msg,
|
|
94
|
+
body: `[Voice message] ${transcript}`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -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,18 @@
|
|
|
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 function formatForSlack(text) {
|
|
13
|
+
// **bold** → *bold*
|
|
14
|
+
let result = text.replace(/\*\*(.+?)\*\*/gs, "*$1*");
|
|
15
|
+
// __bold__ → *bold*
|
|
16
|
+
result = result.replace(/__(.+?)__/gs, "*$1*");
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
@@ -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>;
|