botinabox 2.5.2 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +190 -190
- package/bin/botinabox.mjs +1 -1
- 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/dist/index.d.ts +64 -1
- package/dist/index.js +44 -10
- 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-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,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MessageStore — store-before-respond guarantee for all chat interactions.
|
|
3
|
-
* Story 7.1
|
|
4
|
-
*
|
|
5
|
-
* Every inbound message (with attachments) is stored BEFORE the bot responds.
|
|
6
|
-
* Every outbound message is stored BEFORE it is sent to the user.
|
|
7
|
-
* Storage confirmation is required before any response flows.
|
|
8
|
-
*/
|
|
9
|
-
import type { DataStore } from '../data/data-store.js';
|
|
10
|
-
import type { HookBus } from '../hooks/hook-bus.js';
|
|
11
|
-
import type { InboundMessage } from './types.js';
|
|
12
|
-
export interface StoredAttachment {
|
|
13
|
-
fileType: string;
|
|
14
|
-
filename?: string;
|
|
15
|
-
mimeType?: string;
|
|
16
|
-
sizeBytes?: number;
|
|
17
|
-
contents?: string;
|
|
18
|
-
summary?: string;
|
|
19
|
-
url?: string;
|
|
20
|
-
}
|
|
21
|
-
export interface StoreResult {
|
|
22
|
-
messageId: string;
|
|
23
|
-
attachmentIds: string[];
|
|
24
|
-
}
|
|
25
|
-
export declare class MessageStore {
|
|
26
|
-
private db;
|
|
27
|
-
private hooks;
|
|
28
|
-
constructor(db: DataStore, hooks: HookBus);
|
|
29
|
-
/**
|
|
30
|
-
* Store an inbound message and its attachments.
|
|
31
|
-
* Must complete successfully before any bot response is generated.
|
|
32
|
-
*/
|
|
33
|
-
storeInbound(msg: InboundMessage): Promise<StoreResult>;
|
|
34
|
-
/**
|
|
35
|
-
* Store an outbound message BEFORE sending it.
|
|
36
|
-
* Returns the message ID for confirmation tracking.
|
|
37
|
-
*/
|
|
38
|
-
storeOutbound(opts: {
|
|
39
|
-
channel: string;
|
|
40
|
-
text: string;
|
|
41
|
-
threadId?: string;
|
|
42
|
-
agentId?: string;
|
|
43
|
-
agentSlug?: string;
|
|
44
|
-
taskId?: string;
|
|
45
|
-
}): Promise<string>;
|
|
46
|
-
/**
|
|
47
|
-
* Store an attachment linked to a message.
|
|
48
|
-
*/
|
|
49
|
-
storeAttachment(messageId: string, att: StoredAttachment): Promise<string>;
|
|
50
|
-
/**
|
|
51
|
-
* Get recent messages in a thread for context building.
|
|
52
|
-
*/
|
|
53
|
-
getThreadHistory(threadId: string, limit?: number): Promise<Array<Record<string, unknown>>>;
|
|
54
|
-
/**
|
|
55
|
-
* Get recent outbound messages in a thread for redundancy checking.
|
|
56
|
-
*/
|
|
57
|
-
getRecentOutbound(threadId: string, limit?: number): Promise<Array<Record<string, unknown>>>;
|
|
58
|
-
/**
|
|
59
|
-
* Get recent messages from a specific user across all threads.
|
|
60
|
-
*/
|
|
61
|
-
getUserHistory(userId: string, channel: string, limit?: number): Promise<Array<Record<string, unknown>>>;
|
|
62
|
-
/**
|
|
63
|
-
* Get attachments for a message.
|
|
64
|
-
*/
|
|
65
|
-
getAttachments(messageId: string): Promise<Array<Record<string, unknown>>>;
|
|
66
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MessageStore — store-before-respond guarantee for all chat interactions.
|
|
3
|
-
* Story 7.1
|
|
4
|
-
*
|
|
5
|
-
* Every inbound message (with attachments) is stored BEFORE the bot responds.
|
|
6
|
-
* Every outbound message is stored BEFORE it is sent to the user.
|
|
7
|
-
* Storage confirmation is required before any response flows.
|
|
8
|
-
*/
|
|
9
|
-
export class MessageStore {
|
|
10
|
-
db;
|
|
11
|
-
hooks;
|
|
12
|
-
constructor(db, hooks) {
|
|
13
|
-
this.db = db;
|
|
14
|
-
this.hooks = hooks;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Store an inbound message and its attachments.
|
|
18
|
-
* Must complete successfully before any bot response is generated.
|
|
19
|
-
*/
|
|
20
|
-
async storeInbound(msg) {
|
|
21
|
-
const row = await this.db.insert('messages', {
|
|
22
|
-
channel: msg.channel,
|
|
23
|
-
direction: 'inbound',
|
|
24
|
-
from_user: msg.from,
|
|
25
|
-
user_id: msg.userId,
|
|
26
|
-
body: msg.body,
|
|
27
|
-
thread_id: msg.threadId,
|
|
28
|
-
});
|
|
29
|
-
const messageId = row['id'];
|
|
30
|
-
const attachmentIds = [];
|
|
31
|
-
// Store each attachment
|
|
32
|
-
if (msg.attachments && msg.attachments.length > 0) {
|
|
33
|
-
for (const att of msg.attachments) {
|
|
34
|
-
const attId = await this.storeAttachment(messageId, {
|
|
35
|
-
fileType: att.type,
|
|
36
|
-
filename: att.filename,
|
|
37
|
-
mimeType: att.mimeType,
|
|
38
|
-
sizeBytes: att.size,
|
|
39
|
-
url: att.url,
|
|
40
|
-
});
|
|
41
|
-
attachmentIds.push(attId);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
await this.hooks.emit('message.stored', {
|
|
45
|
-
messageId,
|
|
46
|
-
direction: 'inbound',
|
|
47
|
-
channel: msg.channel,
|
|
48
|
-
from: msg.from,
|
|
49
|
-
attachmentCount: attachmentIds.length,
|
|
50
|
-
});
|
|
51
|
-
return { messageId, attachmentIds };
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Store an outbound message BEFORE sending it.
|
|
55
|
-
* Returns the message ID for confirmation tracking.
|
|
56
|
-
*/
|
|
57
|
-
async storeOutbound(opts) {
|
|
58
|
-
const row = await this.db.insert('messages', {
|
|
59
|
-
channel: opts.channel,
|
|
60
|
-
direction: 'outbound',
|
|
61
|
-
from_agent: opts.agentSlug,
|
|
62
|
-
agent_id: opts.agentId,
|
|
63
|
-
body: opts.text,
|
|
64
|
-
thread_id: opts.threadId,
|
|
65
|
-
task_id: opts.taskId,
|
|
66
|
-
});
|
|
67
|
-
const messageId = row['id'];
|
|
68
|
-
await this.hooks.emit('message.stored', {
|
|
69
|
-
messageId,
|
|
70
|
-
direction: 'outbound',
|
|
71
|
-
channel: opts.channel,
|
|
72
|
-
});
|
|
73
|
-
return messageId;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Store an attachment linked to a message.
|
|
77
|
-
*/
|
|
78
|
-
async storeAttachment(messageId, att) {
|
|
79
|
-
const row = await this.db.insert('message_attachments', {
|
|
80
|
-
message_id: messageId,
|
|
81
|
-
file_type: att.fileType,
|
|
82
|
-
filename: att.filename,
|
|
83
|
-
mime_type: att.mimeType,
|
|
84
|
-
size_bytes: att.sizeBytes,
|
|
85
|
-
contents: att.contents,
|
|
86
|
-
summary: att.summary,
|
|
87
|
-
url: att.url,
|
|
88
|
-
});
|
|
89
|
-
return row['id'];
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Get recent messages in a thread for context building.
|
|
93
|
-
*/
|
|
94
|
-
async getThreadHistory(threadId, limit = 20) {
|
|
95
|
-
const messages = await this.db.query('messages', {
|
|
96
|
-
where: { thread_id: threadId },
|
|
97
|
-
orderBy: 'created_at',
|
|
98
|
-
limit,
|
|
99
|
-
});
|
|
100
|
-
return messages;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Get recent outbound messages in a thread for redundancy checking.
|
|
104
|
-
*/
|
|
105
|
-
async getRecentOutbound(threadId, limit = 10) {
|
|
106
|
-
const messages = await this.db.query('messages', {
|
|
107
|
-
where: { thread_id: threadId, direction: 'outbound' },
|
|
108
|
-
orderBy: 'created_at',
|
|
109
|
-
limit,
|
|
110
|
-
});
|
|
111
|
-
return messages;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Get recent messages from a specific user across all threads.
|
|
115
|
-
*/
|
|
116
|
-
async getUserHistory(userId, channel, limit = 50) {
|
|
117
|
-
return this.db.query('messages', {
|
|
118
|
-
where: { from_user: userId, channel },
|
|
119
|
-
orderBy: 'created_at',
|
|
120
|
-
limit,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Get attachments for a message.
|
|
125
|
-
*/
|
|
126
|
-
async getAttachments(messageId) {
|
|
127
|
-
return this.db.query('message_attachments', {
|
|
128
|
-
where: { message_id: messageId },
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NotificationQueue — persistent outbound notification queue with retry.
|
|
3
|
-
* Story 4.4
|
|
4
|
-
*/
|
|
5
|
-
import type { DataStore } from "../data/data-store.js";
|
|
6
|
-
import type { HookBus } from "../hooks/hook-bus.js";
|
|
7
|
-
import type { ChannelRegistry } from "./channel-registry.js";
|
|
8
|
-
export interface NotificationQueueOpts {
|
|
9
|
-
maxRetries?: number;
|
|
10
|
-
pollIntervalMs?: number;
|
|
11
|
-
}
|
|
12
|
-
export declare class NotificationQueue {
|
|
13
|
-
private readonly db;
|
|
14
|
-
private readonly hooks;
|
|
15
|
-
private readonly channelRegistry;
|
|
16
|
-
private readonly maxRetries;
|
|
17
|
-
private readonly pollIntervalMs;
|
|
18
|
-
private timer;
|
|
19
|
-
constructor(db: DataStore, hooks: HookBus, channelRegistry: ChannelRegistry, opts?: NotificationQueueOpts);
|
|
20
|
-
/**
|
|
21
|
-
* Enqueue a notification for delivery.
|
|
22
|
-
* Returns the notification ID.
|
|
23
|
-
*/
|
|
24
|
-
enqueue(channel: string, recipient: string, payload: {
|
|
25
|
-
text: string;
|
|
26
|
-
threadId?: string;
|
|
27
|
-
[key: string]: unknown;
|
|
28
|
-
}): Promise<string>;
|
|
29
|
-
/** Start the background worker polling for pending notifications. */
|
|
30
|
-
startWorker(): void;
|
|
31
|
-
/** Stop the background worker. */
|
|
32
|
-
stopWorker(): void;
|
|
33
|
-
private processNext;
|
|
34
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* NotificationQueue — persistent outbound notification queue with retry.
|
|
3
|
-
* Story 4.4
|
|
4
|
-
*/
|
|
5
|
-
export class NotificationQueue {
|
|
6
|
-
db;
|
|
7
|
-
hooks;
|
|
8
|
-
channelRegistry;
|
|
9
|
-
maxRetries;
|
|
10
|
-
pollIntervalMs;
|
|
11
|
-
timer = null;
|
|
12
|
-
constructor(db, hooks, channelRegistry, opts) {
|
|
13
|
-
this.db = db;
|
|
14
|
-
this.hooks = hooks;
|
|
15
|
-
this.channelRegistry = channelRegistry;
|
|
16
|
-
this.maxRetries = opts?.maxRetries ?? 3;
|
|
17
|
-
this.pollIntervalMs = opts?.pollIntervalMs ?? 5_000;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Enqueue a notification for delivery.
|
|
21
|
-
* Returns the notification ID.
|
|
22
|
-
*/
|
|
23
|
-
async enqueue(channel, recipient, payload) {
|
|
24
|
-
if (!this.channelRegistry.has(channel)) {
|
|
25
|
-
throw new Error(`No registered adapter for channel: ${channel}`);
|
|
26
|
-
}
|
|
27
|
-
const row = await this.db.insert("notifications", {
|
|
28
|
-
channel,
|
|
29
|
-
recipient_id: recipient,
|
|
30
|
-
message: JSON.stringify(payload),
|
|
31
|
-
status: "pending",
|
|
32
|
-
retries: 0,
|
|
33
|
-
});
|
|
34
|
-
await this.hooks.emit("notification.enqueued", {
|
|
35
|
-
notificationId: row["id"],
|
|
36
|
-
channel,
|
|
37
|
-
recipient,
|
|
38
|
-
});
|
|
39
|
-
return row["id"];
|
|
40
|
-
}
|
|
41
|
-
/** Start the background worker polling for pending notifications. */
|
|
42
|
-
startWorker() {
|
|
43
|
-
if (this.timer)
|
|
44
|
-
return;
|
|
45
|
-
this.timer = setInterval(() => {
|
|
46
|
-
void this.processNext();
|
|
47
|
-
}, this.pollIntervalMs);
|
|
48
|
-
}
|
|
49
|
-
/** Stop the background worker. */
|
|
50
|
-
stopWorker() {
|
|
51
|
-
if (this.timer) {
|
|
52
|
-
clearInterval(this.timer);
|
|
53
|
-
this.timer = null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async processNext() {
|
|
57
|
-
// Query up to 10 pending or retry notifications
|
|
58
|
-
const rows = await this.db.query("notifications", {
|
|
59
|
-
where: { status: "pending" },
|
|
60
|
-
limit: 10,
|
|
61
|
-
});
|
|
62
|
-
for (const row of rows) {
|
|
63
|
-
const id = row["id"];
|
|
64
|
-
const channel = row["channel"];
|
|
65
|
-
const recipient = row["recipient_id"];
|
|
66
|
-
const retries = row["retries"] ?? 0;
|
|
67
|
-
let payload;
|
|
68
|
-
try {
|
|
69
|
-
payload = JSON.parse(row["message"]);
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
await this.db.update("notifications", { id }, { status: "failed", error: "Invalid payload" });
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const adapter = this.channelRegistry.get(channel);
|
|
76
|
-
if (!adapter) {
|
|
77
|
-
await this.db.update("notifications", { id }, {
|
|
78
|
-
status: "failed",
|
|
79
|
-
error: `No adapter for channel: ${channel}`,
|
|
80
|
-
});
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
try {
|
|
84
|
-
await adapter.send({ peerId: recipient, threadId: payload.threadId }, payload);
|
|
85
|
-
await this.db.update("notifications", { id }, {
|
|
86
|
-
status: "sent",
|
|
87
|
-
sent_at: new Date().toISOString(),
|
|
88
|
-
});
|
|
89
|
-
await this.hooks.emit("notification.sent", { notificationId: id, channel, recipient });
|
|
90
|
-
}
|
|
91
|
-
catch (err) {
|
|
92
|
-
const newRetries = retries + 1;
|
|
93
|
-
if (newRetries >= this.maxRetries) {
|
|
94
|
-
await this.db.update("notifications", { id }, {
|
|
95
|
-
status: "failed",
|
|
96
|
-
retries: newRetries,
|
|
97
|
-
error: String(err),
|
|
98
|
-
});
|
|
99
|
-
await this.hooks.emit("notification.failed", { notificationId: id, channel, recipient, error: String(err) });
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
await this.db.update("notifications", { id }, {
|
|
103
|
-
status: "pending",
|
|
104
|
-
retries: newRetries,
|
|
105
|
-
error: String(err),
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MessagePipeline — routes inbound messages to the task queue.
|
|
3
|
-
* Story 4.2
|
|
4
|
-
*/
|
|
5
|
-
import type { HookBus } from "../hooks/hook-bus.js";
|
|
6
|
-
import type { AgentRegistry } from "../orchestrator/agent-registry.js";
|
|
7
|
-
import type { TaskQueue } from "../orchestrator/task-queue.js";
|
|
8
|
-
import type { UserRegistry } from "../orchestrator/user-registry.js";
|
|
9
|
-
import type { BotConfig } from "../../shared/index.js";
|
|
10
|
-
import type { InboundMessage } from "./types.js";
|
|
11
|
-
export declare class MessagePipeline {
|
|
12
|
-
private readonly hooks;
|
|
13
|
-
private readonly agentRegistry;
|
|
14
|
-
private readonly taskQueue;
|
|
15
|
-
private readonly config;
|
|
16
|
-
private readonly agentBindings;
|
|
17
|
-
private readonly userRegistry?;
|
|
18
|
-
constructor(hooks: HookBus, agentRegistry: AgentRegistry, taskQueue: TaskQueue, config: BotConfig, userRegistry?: UserRegistry);
|
|
19
|
-
/**
|
|
20
|
-
* Process an inbound message end-to-end.
|
|
21
|
-
* 1. Emit 'message.inbound'
|
|
22
|
-
* 2. Resolve agent
|
|
23
|
-
* 3. Check policy (allowlist / mention gate)
|
|
24
|
-
* 4. Create task
|
|
25
|
-
* 5. Emit 'message.processed'
|
|
26
|
-
*/
|
|
27
|
-
processInbound(msg: InboundMessage): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* Resolve the best agent for a given inbound message.
|
|
30
|
-
* Returns agentId (slug) or undefined if no match.
|
|
31
|
-
*/
|
|
32
|
-
resolveAgent(msg: InboundMessage): string | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* Evaluate messaging policy for the given agent.
|
|
35
|
-
* Returns false if the message is blocked.
|
|
36
|
-
*/
|
|
37
|
-
evaluatePolicy(msg: InboundMessage, agentId: string): boolean;
|
|
38
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MessagePipeline — routes inbound messages to the task queue.
|
|
3
|
-
* Story 4.2
|
|
4
|
-
*/
|
|
5
|
-
import { buildAgentBindings } from "./routing.js";
|
|
6
|
-
import { checkAllowlist, checkMentionGate } from "./policies.js";
|
|
7
|
-
export class MessagePipeline {
|
|
8
|
-
hooks;
|
|
9
|
-
agentRegistry;
|
|
10
|
-
taskQueue;
|
|
11
|
-
config;
|
|
12
|
-
agentBindings;
|
|
13
|
-
userRegistry;
|
|
14
|
-
constructor(hooks, agentRegistry, taskQueue, config, userRegistry) {
|
|
15
|
-
this.hooks = hooks;
|
|
16
|
-
this.agentRegistry = agentRegistry;
|
|
17
|
-
this.taskQueue = taskQueue;
|
|
18
|
-
this.config = config;
|
|
19
|
-
this.agentBindings = buildAgentBindings(config.agents);
|
|
20
|
-
this.userRegistry = userRegistry;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Process an inbound message end-to-end.
|
|
24
|
-
* 1. Emit 'message.inbound'
|
|
25
|
-
* 2. Resolve agent
|
|
26
|
-
* 3. Check policy (allowlist / mention gate)
|
|
27
|
-
* 4. Create task
|
|
28
|
-
* 5. Emit 'message.processed'
|
|
29
|
-
*/
|
|
30
|
-
async processInbound(msg) {
|
|
31
|
-
await this.hooks.emit("message.inbound", { message: msg, channel: msg.channel });
|
|
32
|
-
// Resolve sender to a user record (auto-creates if UserRegistry is available)
|
|
33
|
-
if (this.userRegistry && !msg.userId) {
|
|
34
|
-
const user = await this.userRegistry.resolveOrCreate(msg.from, msg.channel);
|
|
35
|
-
msg.userId = user.id;
|
|
36
|
-
}
|
|
37
|
-
const agentId = this.resolveAgent(msg);
|
|
38
|
-
if (agentId !== undefined) {
|
|
39
|
-
const allowed = this.evaluatePolicy(msg, agentId);
|
|
40
|
-
if (allowed) {
|
|
41
|
-
await this.taskQueue.create({
|
|
42
|
-
title: `Message from ${msg.from} on ${msg.channel}`,
|
|
43
|
-
description: msg.body,
|
|
44
|
-
assignee_id: agentId,
|
|
45
|
-
context: JSON.stringify({ message: msg, userId: msg.userId }),
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
await this.hooks.emit("message.processed", {
|
|
50
|
-
message: msg,
|
|
51
|
-
channel: msg.channel,
|
|
52
|
-
agentId: agentId ?? null,
|
|
53
|
-
userId: msg.userId ?? null,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Resolve the best agent for a given inbound message.
|
|
58
|
-
* Returns agentId (slug) or undefined if no match.
|
|
59
|
-
*/
|
|
60
|
-
resolveAgent(msg) {
|
|
61
|
-
// Try direct channel binding first
|
|
62
|
-
const bound = this.agentBindings.get(msg.channel);
|
|
63
|
-
if (bound)
|
|
64
|
-
return bound;
|
|
65
|
-
// Fallback: first agent in config
|
|
66
|
-
const first = this.config.agents[0];
|
|
67
|
-
return first?.slug;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Evaluate messaging policy for the given agent.
|
|
71
|
-
* Returns false if the message is blocked.
|
|
72
|
-
*/
|
|
73
|
-
evaluatePolicy(msg, agentId) {
|
|
74
|
-
const channelConfig = this.config.channels[msg.channel];
|
|
75
|
-
// Check allowlist
|
|
76
|
-
const allowFrom = channelConfig?.["allowFrom"] ?? [];
|
|
77
|
-
if (!checkAllowlist(allowFrom, msg.from)) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
// Check mention gate
|
|
81
|
-
const mentionGated = channelConfig?.["requireMention"] ?? false;
|
|
82
|
-
if (mentionGated) {
|
|
83
|
-
if (!checkMentionGate(msg, agentId)) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chat policy helpers — allowlist and mention gate checks.
|
|
3
|
-
* Story 4.2
|
|
4
|
-
*/
|
|
5
|
-
import type { InboundMessage } from "./types.js";
|
|
6
|
-
/**
|
|
7
|
-
* Returns true if the sender is in the allowlist.
|
|
8
|
-
* If allowFrom is empty, all senders are allowed.
|
|
9
|
-
*/
|
|
10
|
-
export declare function checkAllowlist(allowFrom: string[], senderId: string): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Returns true if the message passes the mention gate.
|
|
13
|
-
* In group/channel contexts, the bot must be mentioned (body contains @botId or similar).
|
|
14
|
-
* In direct contexts, always passes.
|
|
15
|
-
*/
|
|
16
|
-
export declare function checkMentionGate(msg: InboundMessage, botId: string): boolean;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chat policy helpers — allowlist and mention gate checks.
|
|
3
|
-
* Story 4.2
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Returns true if the sender is in the allowlist.
|
|
7
|
-
* If allowFrom is empty, all senders are allowed.
|
|
8
|
-
*/
|
|
9
|
-
export function checkAllowlist(allowFrom, senderId) {
|
|
10
|
-
if (allowFrom.length === 0)
|
|
11
|
-
return true;
|
|
12
|
-
return allowFrom.includes(senderId);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Returns true if the message passes the mention gate.
|
|
16
|
-
* In group/channel contexts, the bot must be mentioned (body contains @botId or similar).
|
|
17
|
-
* In direct contexts, always passes.
|
|
18
|
-
*/
|
|
19
|
-
export function checkMentionGate(msg, botId) {
|
|
20
|
-
// For direct messages, no mention required
|
|
21
|
-
// We check via a simple heuristic: if the message contains the botId mention
|
|
22
|
-
// This is called only when mention gating is enabled
|
|
23
|
-
const body = msg.body ?? "";
|
|
24
|
-
return body.includes(`@${botId}`) || body.includes(botId);
|
|
25
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chat routing — maps channel/scope to agentId.
|
|
3
|
-
* Story 4.2
|
|
4
|
-
*
|
|
5
|
-
* @deprecated Use TriageRouter for content-aware routing with keyword/regex
|
|
6
|
-
* matching and LLM fallback. This static channel→agent binding is kept for
|
|
7
|
-
* backward compatibility only. See `./triage-router.ts`.
|
|
8
|
-
*/
|
|
9
|
-
import type { AgentConfig } from "../../shared/index.js";
|
|
10
|
-
/**
|
|
11
|
-
* Build a map from channel identifier to agentId.
|
|
12
|
-
* Each agent may have a config.channel or config.channels binding.
|
|
13
|
-
*
|
|
14
|
-
* @deprecated Use TriageRouter instead — it supports keyword, regex,
|
|
15
|
-
* and LLM-based routing with ownership chain logging.
|
|
16
|
-
*/
|
|
17
|
-
export declare function buildAgentBindings(agents: AgentConfig[]): Map<string, string>;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chat routing — maps channel/scope to agentId.
|
|
3
|
-
* Story 4.2
|
|
4
|
-
*
|
|
5
|
-
* @deprecated Use TriageRouter for content-aware routing with keyword/regex
|
|
6
|
-
* matching and LLM fallback. This static channel→agent binding is kept for
|
|
7
|
-
* backward compatibility only. See `./triage-router.ts`.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Build a map from channel identifier to agentId.
|
|
11
|
-
* Each agent may have a config.channel or config.channels binding.
|
|
12
|
-
*
|
|
13
|
-
* @deprecated Use TriageRouter instead — it supports keyword, regex,
|
|
14
|
-
* and LLM-based routing with ownership chain logging.
|
|
15
|
-
*/
|
|
16
|
-
export function buildAgentBindings(agents) {
|
|
17
|
-
const bindings = new Map();
|
|
18
|
-
for (const agent of agents) {
|
|
19
|
-
const agentId = agent.slug;
|
|
20
|
-
const cfg = agent.config ?? {};
|
|
21
|
-
// Support config.channel (single) or config.channels (array)
|
|
22
|
-
const channels = [];
|
|
23
|
-
if (typeof cfg["channel"] === "string") {
|
|
24
|
-
channels.push(cfg["channel"]);
|
|
25
|
-
}
|
|
26
|
-
if (Array.isArray(cfg["channels"])) {
|
|
27
|
-
for (const ch of cfg["channels"]) {
|
|
28
|
-
channels.push(ch);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
for (const ch of channels) {
|
|
32
|
-
bindings.set(ch, agentId);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return bindings;
|
|
36
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SessionKey — structured key for chat sessions.
|
|
3
|
-
* Story 4.3
|
|
4
|
-
*/
|
|
5
|
-
export declare class SessionKey {
|
|
6
|
-
readonly agentId: string;
|
|
7
|
-
readonly channel: string;
|
|
8
|
-
readonly scope: string;
|
|
9
|
-
constructor(agentId: string, channel: string, scope: string);
|
|
10
|
-
toString(): string;
|
|
11
|
-
toJSON(): {
|
|
12
|
-
agentId: string;
|
|
13
|
-
channel: string;
|
|
14
|
-
scope: string;
|
|
15
|
-
};
|
|
16
|
-
static fromString(key: string): SessionKey;
|
|
17
|
-
/**
|
|
18
|
-
* Build a session key from structured parameters.
|
|
19
|
-
*
|
|
20
|
-
* @param agentId - The agent identifier
|
|
21
|
-
* @param channel - The channel identifier
|
|
22
|
-
* @param chatType - 'dm' or 'group'
|
|
23
|
-
* @param peerId - The peer/user ID
|
|
24
|
-
* @param dmScope - DM scoping strategy
|
|
25
|
-
* - 'main' → single session per agent+channel regardless of peer
|
|
26
|
-
* - 'per-peer' → one session per (agent, peer)
|
|
27
|
-
* - 'per-channel-peer' → one session per (agent, channel, peer)
|
|
28
|
-
*/
|
|
29
|
-
static build(agentId: string, channel: string, chatType: "dm" | "group", peerId: string, dmScope: "main" | "per-peer" | "per-channel-peer"): SessionKey;
|
|
30
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SessionKey — structured key for chat sessions.
|
|
3
|
-
* Story 4.3
|
|
4
|
-
*/
|
|
5
|
-
export class SessionKey {
|
|
6
|
-
agentId;
|
|
7
|
-
channel;
|
|
8
|
-
scope;
|
|
9
|
-
constructor(agentId, channel, scope) {
|
|
10
|
-
this.agentId = agentId;
|
|
11
|
-
this.channel = channel;
|
|
12
|
-
this.scope = scope;
|
|
13
|
-
}
|
|
14
|
-
toString() {
|
|
15
|
-
return `agent:${this.agentId}:${this.channel}:${this.scope}`;
|
|
16
|
-
}
|
|
17
|
-
toJSON() {
|
|
18
|
-
return {
|
|
19
|
-
agentId: this.agentId,
|
|
20
|
-
channel: this.channel,
|
|
21
|
-
scope: this.scope,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
static fromString(key) {
|
|
25
|
-
const parts = key.split(":");
|
|
26
|
-
if (parts.length < 4 || parts[0] !== "agent") {
|
|
27
|
-
throw new Error(`Invalid SessionKey format: ${key}`);
|
|
28
|
-
}
|
|
29
|
-
// agentId might contain ':', so reconstruct carefully
|
|
30
|
-
// Format: "agent:{agentId}:{channel}:{scope}"
|
|
31
|
-
// We assume agentId, channel, scope do NOT contain ':'
|
|
32
|
-
const [, agentId, channel, scope] = parts;
|
|
33
|
-
if (!agentId || !channel || !scope) {
|
|
34
|
-
throw new Error(`Invalid SessionKey format: ${key}`);
|
|
35
|
-
}
|
|
36
|
-
return new SessionKey(agentId, channel, scope);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Build a session key from structured parameters.
|
|
40
|
-
*
|
|
41
|
-
* @param agentId - The agent identifier
|
|
42
|
-
* @param channel - The channel identifier
|
|
43
|
-
* @param chatType - 'dm' or 'group'
|
|
44
|
-
* @param peerId - The peer/user ID
|
|
45
|
-
* @param dmScope - DM scoping strategy
|
|
46
|
-
* - 'main' → single session per agent+channel regardless of peer
|
|
47
|
-
* - 'per-peer' → one session per (agent, peer)
|
|
48
|
-
* - 'per-channel-peer' → one session per (agent, channel, peer)
|
|
49
|
-
*/
|
|
50
|
-
static build(agentId, channel, chatType, peerId, dmScope) {
|
|
51
|
-
if (chatType === "group") {
|
|
52
|
-
// Groups are always scoped to the channel
|
|
53
|
-
return new SessionKey(agentId, channel, channel);
|
|
54
|
-
}
|
|
55
|
-
// DM scoping
|
|
56
|
-
switch (dmScope) {
|
|
57
|
-
case "main":
|
|
58
|
-
return new SessionKey(agentId, channel, "main");
|
|
59
|
-
case "per-peer":
|
|
60
|
-
return new SessionKey(agentId, channel, peerId);
|
|
61
|
-
case "per-channel-peer":
|
|
62
|
-
return new SessionKey(agentId, channel, `${channel}:${peerId}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ChatSessionManager — wraps orchestrator SessionManager with SessionKey-based lookup.
|
|
3
|
-
* Story 4.3
|
|
4
|
-
*/
|
|
5
|
-
import type { DataStore } from "../data/data-store.js";
|
|
6
|
-
import { SessionKey } from "./session-key.js";
|
|
7
|
-
export declare class ChatSessionManager {
|
|
8
|
-
private readonly inner;
|
|
9
|
-
constructor(db: DataStore);
|
|
10
|
-
save(key: SessionKey, params: Record<string, unknown>): Promise<string>;
|
|
11
|
-
load(key: SessionKey): Promise<Record<string, unknown> | undefined>;
|
|
12
|
-
clear(key: SessionKey): Promise<void>;
|
|
13
|
-
shouldClear(session: Record<string, unknown>, opts: {
|
|
14
|
-
maxRuns?: number;
|
|
15
|
-
maxAgeHours?: number;
|
|
16
|
-
}): Promise<boolean>;
|
|
17
|
-
}
|