@fenixforce/kernel 0.1.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.
Files changed (213) hide show
  1. package/dist/agent/execution-result.d.ts +27 -0
  2. package/dist/agent-loop.d.ts +55 -0
  3. package/dist/api/dashboard.d.ts +260 -0
  4. package/dist/api/index.d.ts +9 -0
  5. package/dist/api/middleware.d.ts +46 -0
  6. package/dist/api/openai-compat.d.ts +163 -0
  7. package/dist/api/server.d.ts +44 -0
  8. package/dist/api/streaming.d.ts +15 -0
  9. package/dist/api/webhook-triggers.d.ts +139 -0
  10. package/dist/billing/cost-meter.d.ts +123 -0
  11. package/dist/billing/index.d.ts +2 -0
  12. package/dist/boot.d.ts +109 -0
  13. package/dist/channels/discord.d.ts +99 -0
  14. package/dist/channels/email.d.ts +88 -0
  15. package/dist/channels/http-api.d.ts +155 -0
  16. package/dist/channels/index.d.ts +20 -0
  17. package/dist/channels/mcp-channel.d.ts +75 -0
  18. package/dist/channels/mobile-hil.d.ts +88 -0
  19. package/dist/channels/openai-compat.d.ts +42 -0
  20. package/dist/channels/registry.d.ts +80 -0
  21. package/dist/channels/signal.d.ts +75 -0
  22. package/dist/channels/slack.d.ts +115 -0
  23. package/dist/channels/teams.d.ts +106 -0
  24. package/dist/channels/telegram.d.ts +164 -0
  25. package/dist/channels/types.d.ts +71 -0
  26. package/dist/channels/whatsapp.d.ts +83 -0
  27. package/dist/checkpoint.d.ts +77 -0
  28. package/dist/config/canary.d.ts +74 -0
  29. package/dist/config/constitution.d.ts +57 -0
  30. package/dist/config/defaults.d.ts +17 -0
  31. package/dist/config/index.d.ts +8 -0
  32. package/dist/config/loader.d.ts +11 -0
  33. package/dist/config/provider-config.d.ts +29 -0
  34. package/dist/config/schema.d.ts +118 -0
  35. package/dist/config/steering-rules.d.ts +28 -0
  36. package/dist/content/chunker.d.ts +42 -0
  37. package/dist/content/entity-extractor.d.ts +58 -0
  38. package/dist/content/index.d.ts +8 -0
  39. package/dist/content/ocr.d.ts +79 -0
  40. package/dist/content/pipeline.d.ts +153 -0
  41. package/dist/context-overflow.d.ts +19 -0
  42. package/dist/editions/mobile.d.ts +12 -0
  43. package/dist/editions/pro.d.ts +12 -0
  44. package/dist/editions/voices.d.ts +14 -0
  45. package/dist/events/block-manager.d.ts +37 -0
  46. package/dist/events/bus.d.ts +39 -0
  47. package/dist/events/index.d.ts +8 -0
  48. package/dist/events/session-manager.d.ts +59 -0
  49. package/dist/events/stream-adapter.d.ts +24 -0
  50. package/dist/events/types.d.ts +465 -0
  51. package/dist/events/websocket.d.ts +34 -0
  52. package/dist/extensions/defaults/05-session-repair.d.ts +6 -0
  53. package/dist/extensions/defaults/10-logging.d.ts +6 -0
  54. package/dist/extensions/defaults/15-loop-guard.d.ts +6 -0
  55. package/dist/extensions/defaults/20-cost-tracking.d.ts +7 -0
  56. package/dist/extensions/defaults/25-ssrf-protection.d.ts +6 -0
  57. package/dist/extensions/defaults/30-rate-limiting.d.ts +6 -0
  58. package/dist/extensions/defaults/35-shell-bleed.d.ts +6 -0
  59. package/dist/extensions/defaults/40-observation-capture.d.ts +7 -0
  60. package/dist/extensions/defaults/45-context-survival.d.ts +6 -0
  61. package/dist/extensions/defaults/50-context-budget.d.ts +6 -0
  62. package/dist/extensions/defaults/55-steering-rules.d.ts +7 -0
  63. package/dist/extensions/defaults/60-quality-gates.d.ts +7 -0
  64. package/dist/extensions/defaults/65-job-dispatch.d.ts +24 -0
  65. package/dist/extensions/defaults/70-skill-loader.d.ts +18 -0
  66. package/dist/extensions/hooks.d.ts +74 -0
  67. package/dist/extensions/index.d.ts +21 -0
  68. package/dist/extensions/intervention.d.ts +59 -0
  69. package/dist/extensions/manager.d.ts +63 -0
  70. package/dist/extensions/runner.d.ts +63 -0
  71. package/dist/hooks/hook-manager.d.ts +39 -0
  72. package/dist/hooks/hook-types.d.ts +60 -0
  73. package/dist/identity/assembler.d.ts +45 -0
  74. package/dist/identity/ccc-adapter.d.ts +33 -0
  75. package/dist/identity/index.d.ts +6 -0
  76. package/dist/identity/persona-parser.d.ts +24 -0
  77. package/dist/identity/soul-parser.d.ts +23 -0
  78. package/dist/identity/user-populator.d.ts +20 -0
  79. package/dist/index.d.ts +227 -0
  80. package/dist/index.js +579 -0
  81. package/dist/interrupt.d.ts +84 -0
  82. package/dist/job-queue.d.ts +69 -0
  83. package/dist/jobs/index.d.ts +12 -0
  84. package/dist/jobs/memory-queue.d.ts +23 -0
  85. package/dist/jobs/planned-tasks.d.ts +121 -0
  86. package/dist/jobs/queue.d.ts +79 -0
  87. package/dist/jobs/router.d.ts +23 -0
  88. package/dist/jobs/synthesize-memories.d.ts +26 -0
  89. package/dist/jobs/types.d.ts +47 -0
  90. package/dist/jobs/worker-pool.d.ts +25 -0
  91. package/dist/jobs/worker.d.ts +40 -0
  92. package/dist/loop/autonomous-controller.d.ts +91 -0
  93. package/dist/loop/backpressure.d.ts +64 -0
  94. package/dist/loop/fresh-context.d.ts +48 -0
  95. package/dist/loop/prd-importer.d.ts +134 -0
  96. package/dist/loop/stop-controller.d.ts +31 -0
  97. package/dist/loop-guard.d.ts +32 -0
  98. package/dist/mcp/tool-executor.d.ts +57 -0
  99. package/dist/memory/brain-artifacts.d.ts +25 -0
  100. package/dist/memory/dual-search.d.ts +67 -0
  101. package/dist/memory/episodic.d.ts +45 -0
  102. package/dist/memory/index.d.ts +27 -0
  103. package/dist/memory/knowledge-graph.d.ts +89 -0
  104. package/dist/memory/markdown-store.d.ts +64 -0
  105. package/dist/memory/metadata-filter.d.ts +29 -0
  106. package/dist/memory/mid-conversation-saves.d.ts +17 -0
  107. package/dist/memory/note-parser.d.ts +34 -0
  108. package/dist/memory/observation-store.d.ts +36 -0
  109. package/dist/memory/observation-thresholds.d.ts +26 -0
  110. package/dist/memory/progressive-search.d.ts +25 -0
  111. package/dist/memory/synthesis.d.ts +36 -0
  112. package/dist/memory/tree-index.d.ts +104 -0
  113. package/dist/memory/write-gate.d.ts +63 -0
  114. package/dist/mission-control.d.ts +34 -0
  115. package/dist/pre-classifier-widgets.d.ts +40 -0
  116. package/dist/pre-classifier.d.ts +19 -0
  117. package/dist/prompt/context-budget.d.ts +68 -0
  118. package/dist/prompt/index.d.ts +3 -0
  119. package/dist/prompt/system-prompt.d.ts +32 -0
  120. package/dist/prompt/templates.d.ts +11 -0
  121. package/dist/providers/anthropic.d.ts +24 -0
  122. package/dist/providers/auto-detect.d.ts +16 -0
  123. package/dist/providers/auto-discover.d.ts +28 -0
  124. package/dist/providers/bedrock.d.ts +38 -0
  125. package/dist/providers/cache-strategy.d.ts +58 -0
  126. package/dist/providers/circuit-breaker.d.ts +33 -0
  127. package/dist/providers/cost-meter.d.ts +74 -0
  128. package/dist/providers/cost-tracking.d.ts +36 -0
  129. package/dist/providers/google.d.ts +35 -0
  130. package/dist/providers/index.d.ts +32 -0
  131. package/dist/providers/interface.d.ts +98 -0
  132. package/dist/providers/json-repair.d.ts +10 -0
  133. package/dist/providers/key-rotation.d.ts +36 -0
  134. package/dist/providers/manager.d.ts +64 -0
  135. package/dist/providers/model-registry.d.ts +50 -0
  136. package/dist/providers/openai-compatible.d.ts +26 -0
  137. package/dist/providers/optimization-modes.d.ts +38 -0
  138. package/dist/providers/provider-manager.d.ts +71 -0
  139. package/dist/providers/runtime-crud.d.ts +68 -0
  140. package/dist/providers/sidecar-lifecycle.d.ts +40 -0
  141. package/dist/providers/stream-wrapper.d.ts +21 -0
  142. package/dist/providers/structured-verify.d.ts +31 -0
  143. package/dist/providers/versioning.d.ts +18 -0
  144. package/dist/quality-gates.d.ts +10 -0
  145. package/dist/scheduler/engine.d.ts +95 -0
  146. package/dist/scheduler/index.d.ts +4 -0
  147. package/dist/scheduler/webhook-handler.d.ts +37 -0
  148. package/dist/sdk/agent.d.ts +22 -0
  149. package/dist/sdk/cli.d.ts +2 -0
  150. package/dist/sdk/client.d.ts +19 -0
  151. package/dist/sdk/index.d.ts +24 -0
  152. package/dist/sdk/jobs.d.ts +25 -0
  153. package/dist/sdk/memory.d.ts +18 -0
  154. package/dist/sdk/types.d.ts +69 -0
  155. package/dist/security/approval-gates.d.ts +166 -0
  156. package/dist/security/content-wrapper.d.ts +38 -0
  157. package/dist/security/guard-rails.d.ts +6 -0
  158. package/dist/security/index.d.ts +21 -0
  159. package/dist/security/instruction-hierarchy.d.ts +109 -0
  160. package/dist/security/pii-tokenizer.d.ts +30 -0
  161. package/dist/security/reputation.d.ts +53 -0
  162. package/dist/security/secret-store.d.ts +41 -0
  163. package/dist/security/security-engine.d.ts +53 -0
  164. package/dist/security/shell-bleed.d.ts +15 -0
  165. package/dist/security/ssrf.d.ts +12 -0
  166. package/dist/security/taint-tracker.d.ts +63 -0
  167. package/dist/security/tool-access-control.d.ts +114 -0
  168. package/dist/session-compaction.d.ts +20 -0
  169. package/dist/session-orient.d.ts +22 -0
  170. package/dist/session-repair.d.ts +6 -0
  171. package/dist/storage/index.d.ts +24 -0
  172. package/dist/storage/interface.d.ts +245 -0
  173. package/dist/storage/postgres.d.ts +6 -0
  174. package/dist/storage/sqlite.d.ts +2 -0
  175. package/dist/streaming/reasoning.d.ts +67 -0
  176. package/dist/task-tracker.d.ts +26 -0
  177. package/dist/testing/action-cache.d.ts +39 -0
  178. package/dist/testing/incident-eval.d.ts +49 -0
  179. package/dist/testing/workflow-evals.d.ts +73 -0
  180. package/dist/tools/access-control.d.ts +60 -0
  181. package/dist/tools/browser-engine.d.ts +73 -0
  182. package/dist/tools/builtins/jobs-router.d.ts +7 -0
  183. package/dist/tools/builtins/tasks-router.d.ts +25 -0
  184. package/dist/tools/index.d.ts +20 -0
  185. package/dist/tools/map-reduce.d.ts +64 -0
  186. package/dist/tools/registry.d.ts +39 -0
  187. package/dist/tools/router.d.ts +30 -0
  188. package/dist/tools/routers/browser-router.d.ts +12 -0
  189. package/dist/tools/routers/code-router.d.ts +34 -0
  190. package/dist/tools/routers/file-router.d.ts +35 -0
  191. package/dist/tools/routers/memory-router.d.ts +21 -0
  192. package/dist/tools/routers/schedule-router.d.ts +31 -0
  193. package/dist/tools/routers/search-backends.d.ts +47 -0
  194. package/dist/tools/routers/task-router.d.ts +32 -0
  195. package/dist/tools/routers/web-router.d.ts +36 -0
  196. package/dist/tools/skill-discovery.d.ts +32 -0
  197. package/dist/tools/skill-loader.d.ts +76 -0
  198. package/dist/tools/skill-types.d.ts +21 -0
  199. package/dist/voice/audio-intelligence.d.ts +42 -0
  200. package/dist/voice/barge-in.d.ts +51 -0
  201. package/dist/voice/index.d.ts +22 -0
  202. package/dist/voice/marker-parser.d.ts +31 -0
  203. package/dist/voice/sidecar-manager.d.ts +68 -0
  204. package/dist/voice/speaker-focus.d.ts +41 -0
  205. package/dist/voice/speaker-voiceprint.d.ts +47 -0
  206. package/dist/voice/speech-intent.d.ts +51 -0
  207. package/dist/voice/speechmatics-stt.d.ts +77 -0
  208. package/dist/voice/speechmatics-tts.d.ts +39 -0
  209. package/dist/voice/stt-provider.d.ts +40 -0
  210. package/dist/voice/transcript.d.ts +19 -0
  211. package/dist/voice/turn-detection.d.ts +53 -0
  212. package/dist/wrapup.d.ts +15 -0
  213. package/package.json +39 -0
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Microsoft Teams Channel Adapter
3
+ *
4
+ * Integrates with Azure Bot Service via the Bot Framework webhook
5
+ * pattern. Handles incoming activities on /api/messages, validates
6
+ * JWT tokens, and sends responses using Adaptive Cards for rich
7
+ * formatting and approval gates.
8
+ */
9
+ import type { MessageHandler } from "./types.js";
10
+ import type { STTProvider, TTSProvider, TaskInfo, JobInfo } from "./telegram.js";
11
+ export interface TeamsConfig {
12
+ /** Azure AD app registration ID. */
13
+ appId: string;
14
+ /** Azure AD client secret. */
15
+ appPassword: string;
16
+ /** Restrict to specific Azure AD tenant. */
17
+ tenantId?: string;
18
+ /** Webhook endpoint path. Default: "/api/messages". */
19
+ webhookPath?: string;
20
+ /** Restrict to specific team IDs. */
21
+ allowedTeamIds?: string[];
22
+ onMessage: MessageHandler;
23
+ onReset?: (conversationId: string) => Promise<string>;
24
+ onTasks?: (conversationId: string) => Promise<TaskInfo[]>;
25
+ onJobs?: (conversationId: string) => Promise<JobInfo[]>;
26
+ stt?: STTProvider;
27
+ tts?: TTSProvider;
28
+ /** Override fetch for testing. */
29
+ fetchFn?: typeof globalThis.fetch;
30
+ }
31
+ /** Bot Framework Activity (subset). */
32
+ export interface TeamsActivity {
33
+ type: "message" | "conversationUpdate" | "invoke" | "event";
34
+ id: string;
35
+ timestamp: string;
36
+ channelId: string;
37
+ from: {
38
+ id: string;
39
+ name?: string;
40
+ aadObjectId?: string;
41
+ };
42
+ conversation: {
43
+ id: string;
44
+ conversationType?: "personal" | "channel" | "groupChat";
45
+ tenantId?: string;
46
+ isGroup?: boolean;
47
+ };
48
+ recipient?: {
49
+ id: string;
50
+ name?: string;
51
+ };
52
+ text?: string;
53
+ attachments?: TeamsActivityAttachment[];
54
+ entities?: TeamsEntity[];
55
+ channelData?: Record<string, unknown>;
56
+ replyToId?: string;
57
+ serviceUrl: string;
58
+ value?: Record<string, unknown>;
59
+ }
60
+ export interface TeamsActivityAttachment {
61
+ contentType: string;
62
+ contentUrl?: string;
63
+ content?: unknown;
64
+ name?: string;
65
+ }
66
+ export interface TeamsEntity {
67
+ type: string;
68
+ mentioned?: {
69
+ id: string;
70
+ name: string;
71
+ };
72
+ text?: string;
73
+ }
74
+ /** Conversation reference for proactive messaging. */
75
+ export interface ConversationReference {
76
+ activityId: string;
77
+ conversationId: string;
78
+ serviceUrl: string;
79
+ userId: string;
80
+ tenantId?: string;
81
+ }
82
+ export interface PendingTeamsApproval {
83
+ id: string;
84
+ conversationId: string;
85
+ replyToId: string;
86
+ resolve: (choice: string) => void;
87
+ }
88
+ export interface TeamsChannelAdapter {
89
+ start(): Promise<void>;
90
+ stop(): Promise<void>;
91
+ sendMessage(conversationId: string, text: string): Promise<void>;
92
+ /** Handle incoming Bot Framework activity. */
93
+ handleActivity(activity: TeamsActivity): Promise<TeamsActivityResponse | null>;
94
+ /** Handle Adaptive Card action (invoke activity). */
95
+ handleCardAction(activity: TeamsActivity): Promise<TeamsActivityResponse | null>;
96
+ /** Send proactive message to a stored conversation reference. */
97
+ sendProactive(ref: ConversationReference, text: string): Promise<void>;
98
+ /** Get stored conversation reference for a user. */
99
+ getConversationRef(userId: string): ConversationReference | undefined;
100
+ readonly isRunning: boolean;
101
+ }
102
+ export interface TeamsActivityResponse {
103
+ status: number;
104
+ body?: Record<string, unknown>;
105
+ }
106
+ export declare function createTeamsAdapter(config: TeamsConfig): TeamsChannelAdapter;
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Telegram Channel Adapter — long-polling based.
3
+ *
4
+ * Converts Telegram Bot API updates into MessageEnvelopes,
5
+ * handles slash-commands (/reset, /tasks, /jobs), and sends
6
+ * inline-keyboard approval prompts for tool confirmations.
7
+ */
8
+ export interface Attachment {
9
+ type: "image" | "audio" | "video" | "document";
10
+ url?: string;
11
+ base64?: string;
12
+ mimeType: string;
13
+ fileName?: string;
14
+ }
15
+ export interface MessageEnvelope {
16
+ channel: "telegram" | "whatsapp" | "discord" | "slack" | "voice" | "web" | "sms";
17
+ userId: string;
18
+ userName?: string;
19
+ conversationId: string;
20
+ messageType: "text" | "voice" | "image" | "file";
21
+ content: string;
22
+ attachments?: Attachment[];
23
+ metadata: Record<string, unknown>;
24
+ timestamp: Date;
25
+ }
26
+ export type MessageHandler = (envelope: MessageEnvelope) => Promise<string>;
27
+ export interface TaskInfo {
28
+ id: string;
29
+ description: string;
30
+ status: "pending" | "running" | "done" | "failed";
31
+ }
32
+ export interface JobInfo {
33
+ id: string;
34
+ description: string;
35
+ status: "pending" | "running" | "done" | "failed";
36
+ startedAt?: Date;
37
+ }
38
+ /** Speech-to-text provider for voice messages. */
39
+ export interface STTProvider {
40
+ transcribe(audioUrl: string): Promise<{
41
+ text: string;
42
+ confidence: number;
43
+ }>;
44
+ }
45
+ /** Text-to-speech provider for voice responses. */
46
+ export interface TTSProvider {
47
+ synthesize(text: string): Promise<{
48
+ audioUrl: string;
49
+ durationMs: number;
50
+ }>;
51
+ }
52
+ export type AdapterMode = "polling" | "webhook";
53
+ export interface TelegramAdapterConfig {
54
+ botToken: string;
55
+ onMessage: MessageHandler;
56
+ /** Called when user presses /reset. Return the message to send back. */
57
+ onReset?: (chatId: string) => Promise<string>;
58
+ /** Return current tasks for /tasks command. */
59
+ onTasks?: (chatId: string) => Promise<TaskInfo[]>;
60
+ /** Return current async jobs for /jobs command. */
61
+ onJobs?: (chatId: string) => Promise<JobInfo[]>;
62
+ /** "polling" (development) or "webhook" (production). Default: "polling". */
63
+ mode?: AdapterMode;
64
+ /** Webhook URL for production mode (required when mode is "webhook"). */
65
+ webhookUrl?: string;
66
+ /** Secret token for webhook verification. */
67
+ webhookSecret?: string;
68
+ /** Polling interval in ms (default 1000). */
69
+ pollingInterval?: number;
70
+ /** Polling timeout for long-poll in seconds (default 30). */
71
+ pollingTimeout?: number;
72
+ /** STT provider for voice message transcription. */
73
+ stt?: STTProvider;
74
+ /** TTS provider for voice responses. */
75
+ tts?: TTSProvider;
76
+ /** Override fetch for testing. */
77
+ fetchFn?: typeof globalThis.fetch;
78
+ }
79
+ export interface TelegramUser {
80
+ id: number;
81
+ is_bot: boolean;
82
+ first_name: string;
83
+ last_name?: string;
84
+ username?: string;
85
+ }
86
+ export interface TelegramChat {
87
+ id: number;
88
+ type: "private" | "group" | "supergroup" | "channel";
89
+ }
90
+ export interface TelegramVoice {
91
+ file_id: string;
92
+ file_unique_id: string;
93
+ duration: number;
94
+ mime_type?: string;
95
+ file_size?: number;
96
+ }
97
+ export interface TelegramMessage {
98
+ message_id: number;
99
+ from?: TelegramUser;
100
+ chat: TelegramChat;
101
+ date: number;
102
+ text?: string;
103
+ photo?: TelegramPhotoSize[];
104
+ document?: TelegramDocument;
105
+ voice?: TelegramVoice;
106
+ caption?: string;
107
+ }
108
+ export interface TelegramPhotoSize {
109
+ file_id: string;
110
+ file_unique_id: string;
111
+ width: number;
112
+ height: number;
113
+ file_size?: number;
114
+ }
115
+ export interface TelegramDocument {
116
+ file_id: string;
117
+ file_unique_id: string;
118
+ file_name?: string;
119
+ mime_type?: string;
120
+ file_size?: number;
121
+ }
122
+ export interface TelegramCallbackQuery {
123
+ id: string;
124
+ from: TelegramUser;
125
+ message?: TelegramMessage;
126
+ data?: string;
127
+ }
128
+ export interface TelegramUpdate {
129
+ update_id: number;
130
+ message?: TelegramMessage;
131
+ callback_query?: TelegramCallbackQuery;
132
+ }
133
+ export interface InlineKeyboardButton {
134
+ text: string;
135
+ callback_data?: string;
136
+ }
137
+ export interface InlineKeyboardMarkup {
138
+ inline_keyboard: InlineKeyboardButton[][];
139
+ }
140
+ export interface PendingApproval {
141
+ id: string;
142
+ chatId: string;
143
+ toolName: string;
144
+ args: Record<string, unknown>;
145
+ resolve: (approved: boolean) => void;
146
+ }
147
+ export type ModeIndicator = "typing" | "planning" | "executing";
148
+ export interface TelegramChannelAdapter {
149
+ start(): Promise<void>;
150
+ stop(): void;
151
+ sendMessage(chatId: string, text: string): Promise<void>;
152
+ sendApprovalKeyboard(chatId: string, approvalId: string, toolName: string, args: Record<string, unknown>): Promise<boolean>;
153
+ /** Send a mode indicator (typing, planning, executing) to a chat. */
154
+ sendModeIndicator(chatId: string, mode: ModeIndicator): Promise<void>;
155
+ /** Handle an inbound webhook update (production mode). */
156
+ handleWebhookUpdate(update: TelegramUpdate, secret?: string): Promise<void>;
157
+ readonly isRunning: boolean;
158
+ readonly adapterMode: AdapterMode;
159
+ }
160
+ export declare function createTelegramChannelAdapter(config: TelegramAdapterConfig): TelegramChannelAdapter;
161
+ declare function splitMessage(text: string, maxLength: number): string[];
162
+ declare function statusIcon(status: string): string;
163
+ declare function formatElapsed(ms: number): string;
164
+ export { splitMessage, statusIcon, formatElapsed };
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Channel adapter types for Fenix kernel.
3
+ */
4
+ export interface Attachment {
5
+ type: "image" | "audio" | "video" | "document";
6
+ url?: string;
7
+ base64?: string;
8
+ mimeType: string;
9
+ fileName?: string;
10
+ }
11
+ export interface MessageEnvelope {
12
+ channel: "telegram" | "whatsapp" | "discord" | "slack" | "voice" | "web" | "sms";
13
+ userId: string;
14
+ userName?: string;
15
+ conversationId: string;
16
+ messageType: "text" | "voice" | "image" | "file";
17
+ content: string;
18
+ attachments?: Attachment[];
19
+ metadata: Record<string, unknown>;
20
+ timestamp: Date;
21
+ }
22
+ export type MessageHandler = (envelope: MessageEnvelope) => Promise<string>;
23
+ export type AgentEvent = {
24
+ type: "text";
25
+ content: string;
26
+ } | {
27
+ type: "thinking";
28
+ content: string;
29
+ } | {
30
+ type: "tool_call";
31
+ name: string;
32
+ args: Record<string, unknown>;
33
+ } | {
34
+ type: "tool_result";
35
+ name: string;
36
+ output: string;
37
+ } | {
38
+ type: "approval_request";
39
+ id: string;
40
+ description: string;
41
+ options: string[];
42
+ } | {
43
+ type: "mode_change";
44
+ mode: string;
45
+ } | {
46
+ type: "task_update";
47
+ tasks: TaskStatus[];
48
+ } | {
49
+ type: "done";
50
+ content: string;
51
+ } | {
52
+ type: "error";
53
+ message: string;
54
+ };
55
+ export interface TaskStatus {
56
+ id: string;
57
+ title: string;
58
+ status: "pending" | "in_progress" | "completed" | "failed";
59
+ }
60
+ export interface ChannelAdapter {
61
+ /** Start listening for inbound messages. */
62
+ start(): Promise<void>;
63
+ /** Gracefully stop the adapter. */
64
+ stop(): Promise<void>;
65
+ /** Send a plain text reply to a conversation. */
66
+ sendText(conversationId: string, text: string): Promise<void>;
67
+ /** Stream agent events to the user (typing, tool calls, final answer). */
68
+ sendAgentEvents(conversationId: string, events: AsyncIterable<AgentEvent>): Promise<void>;
69
+ /** Send an approval gate (inline keyboard) and wait for the user's choice. */
70
+ sendApprovalGate(conversationId: string, description: string, options: string[]): Promise<string>;
71
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * WhatsApp Channel Adapter
3
+ *
4
+ * Two integration paths selectable via config:
5
+ * - Path A "baileys" → self-hosted via @whiskeysockets/baileys (WebSocket)
6
+ * - Path B "business-api" → official Cloud API via HTTP webhooks
7
+ *
8
+ * Converts WhatsApp messages into MessageEnvelopes, supports text, images,
9
+ * voice notes, documents, reactions, and group chats.
10
+ */
11
+ import type { MessageHandler } from "./types.js";
12
+ import type { STTProvider, TTSProvider, TaskInfo, JobInfo } from "./telegram.js";
13
+ export interface WhatsAppConfig {
14
+ /** "baileys" for self-hosted, "business-api" for Cloud API. */
15
+ mode: "baileys" | "business-api";
16
+ onMessage: MessageHandler;
17
+ onReset?: (conversationId: string) => Promise<string>;
18
+ onTasks?: (conversationId: string) => Promise<TaskInfo[]>;
19
+ onJobs?: (conversationId: string) => Promise<JobInfo[]>;
20
+ stt?: STTProvider;
21
+ tts?: TTSProvider;
22
+ /** Directory to persist session credentials (default: workspace/channels/whatsapp/auth/) */
23
+ authDir?: string;
24
+ /** Phone number ID from Meta Business dashboard. */
25
+ phoneNumberId?: string;
26
+ /** Permanent access token for Cloud API. */
27
+ accessToken?: string;
28
+ /** Verify token for webhook registration. */
29
+ verifyToken?: string;
30
+ /** Path for incoming webhooks (default: /webhook/whatsapp). */
31
+ webhookPath?: string;
32
+ /** JIDs allowed in group chats (empty = all). */
33
+ groupAllowList?: string[];
34
+ /** Override fetch for testing. */
35
+ fetchFn?: typeof globalThis.fetch;
36
+ }
37
+ /** Lightweight internal representation of inbound WhatsApp messages. */
38
+ export interface WAInboundMessage {
39
+ id: string;
40
+ from: string;
41
+ pushName?: string;
42
+ timestamp: number;
43
+ type: "text" | "image" | "audio" | "document" | "reaction" | "sticker";
44
+ body?: string;
45
+ caption?: string;
46
+ mimetype?: string;
47
+ mediaUrl?: string;
48
+ mediaBase64?: string;
49
+ fileName?: string;
50
+ /** For group messages. */
51
+ groupId?: string;
52
+ groupSubject?: string;
53
+ /** Reaction target message id. */
54
+ reactionTarget?: string;
55
+ }
56
+ /** Events emitted by the adapter. */
57
+ export type WhatsAppAdapterEvent = {
58
+ type: "qr";
59
+ qr: string;
60
+ } | {
61
+ type: "authenticated";
62
+ } | {
63
+ type: "disconnected";
64
+ reason: string;
65
+ } | {
66
+ type: "error";
67
+ error: string;
68
+ };
69
+ export type WhatsAppEventHandler = (event: WhatsAppAdapterEvent) => void;
70
+ export interface WhatsAppChannelAdapter {
71
+ start(): Promise<void>;
72
+ stop(): Promise<void>;
73
+ sendMessage(conversationId: string, text: string): Promise<void>;
74
+ /** Process inbound webhook payload (Business API mode). */
75
+ handleWebhook(payload: unknown, signatureHeader?: string): Promise<void>;
76
+ /** Verify webhook challenge (Business API mode). */
77
+ verifyWebhook(query: Record<string, string>): string | null;
78
+ /** Register event handler. */
79
+ onEvent(handler: WhatsAppEventHandler): void;
80
+ readonly isRunning: boolean;
81
+ readonly mode: "baileys" | "business-api";
82
+ }
83
+ export declare function createWhatsAppAdapter(config: WhatsAppConfig): WhatsAppChannelAdapter;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Checkpoint Durable Execution — save and restore execution state
3
+ * for crash recovery, time travel, and fork-from-any-point.
4
+ *
5
+ * Checkpoints are created after each tool execution. On crash,
6
+ * execution resumes from the most recent checkpoint. Pruning keeps
7
+ * the last N checkpoints (default 50) to bound memory.
8
+ */
9
+ export interface CheckpointMessage {
10
+ role: string;
11
+ content: string;
12
+ timestamp?: string;
13
+ }
14
+ export interface Checkpoint {
15
+ /** Unique checkpoint ID. */
16
+ id: string;
17
+ /** Session this checkpoint belongs to. */
18
+ sessionId: string;
19
+ /** Step number (monotonically increasing within a session). */
20
+ step: number;
21
+ /** Conversation messages at this point. */
22
+ messages: CheckpointMessage[];
23
+ /** Serialized memory/context snapshot. */
24
+ memorySnapshot: Record<string, unknown>;
25
+ /** Tool state at checkpoint time. */
26
+ toolState: Record<string, unknown>;
27
+ /** Task tracker state (planned tasks, steps). */
28
+ taskTrackerState: Record<string, unknown>;
29
+ /** When this checkpoint was created. */
30
+ timestamp: Date;
31
+ /** Parent checkpoint ID (null for initial). */
32
+ parentId: string | null;
33
+ }
34
+ export type CheckpointEventType = "checkpoint_created" | "checkpoint_restored" | "checkpoint_pruned" | "checkpoint_forked" | "checkpoint_deleted";
35
+ export interface CheckpointEvent {
36
+ type: CheckpointEventType;
37
+ timestamp: Date;
38
+ checkpointId: string;
39
+ sessionId: string;
40
+ detail: string;
41
+ }
42
+ export type CheckpointEventListener = (event: CheckpointEvent) => void;
43
+ export interface CheckpointManagerConfig {
44
+ /** Maximum checkpoints to keep per session. Default 50. */
45
+ maxPerSession?: number;
46
+ /** Override Date.now() for testing. */
47
+ nowFn?: () => number;
48
+ }
49
+ export declare function _resetCheckpointIds(): void;
50
+ export interface CheckpointManager {
51
+ /** Save a checkpoint after a tool execution step. Returns the checkpoint. */
52
+ save(opts: {
53
+ sessionId: string;
54
+ messages: CheckpointMessage[];
55
+ memorySnapshot?: Record<string, unknown>;
56
+ toolState?: Record<string, unknown>;
57
+ taskTrackerState?: Record<string, unknown>;
58
+ }): Checkpoint;
59
+ /** Restore execution state from a specific checkpoint. */
60
+ restore(checkpointId: string): Checkpoint | undefined;
61
+ /** Get the latest checkpoint for a session. */
62
+ latest(sessionId: string): Checkpoint | undefined;
63
+ /** List all checkpoints for a session, ordered by step. */
64
+ list(sessionId: string): Checkpoint[];
65
+ /** Fork a new session from any checkpoint. Returns the forked checkpoint. */
66
+ fork(checkpointId: string, newSessionId: string): Checkpoint | undefined;
67
+ /** Delete a specific checkpoint. */
68
+ delete(checkpointId: string): boolean;
69
+ /** Delete all checkpoints for a session. */
70
+ deleteSession(sessionId: string): number;
71
+ /** Get a checkpoint by ID. */
72
+ get(checkpointId: string): Checkpoint | undefined;
73
+ /** Events. */
74
+ on(listener: CheckpointEventListener): void;
75
+ off(listener: CheckpointEventListener): void;
76
+ }
77
+ export declare function createCheckpointManager(config?: CheckpointManagerConfig): CheckpointManager;
@@ -0,0 +1,74 @@
1
+ import type { SteeringRule } from "./steering-rules.js";
2
+ export type PolicyStatus = "canary" | "stable" | "rolled-back";
3
+ export interface PolicyMetrics {
4
+ errorRate: number;
5
+ loopWarningRate: number;
6
+ approvalEscalationRate: number;
7
+ costPerSession: number;
8
+ }
9
+ export interface PolicyVersion {
10
+ id: string;
11
+ rules: SteeringRule[];
12
+ createdAt: Date;
13
+ status: PolicyStatus;
14
+ trafficPercent: number;
15
+ metrics: PolicyMetrics;
16
+ }
17
+ export interface CanaryConfig {
18
+ /** Rollout stages as traffic percentages */
19
+ stages: number[];
20
+ /** Time each stage must hold before advancing (ms) */
21
+ stageDurationMs: number;
22
+ /** Metric thresholds — rollback if any exceeded */
23
+ thresholds: Partial<PolicyMetrics>;
24
+ /** Auto-promote to next stage when duration passes */
25
+ autoPromote: boolean;
26
+ }
27
+ export declare const DEFAULT_CANARY_CONFIG: CanaryConfig;
28
+ export type CanaryEventEmitter = (event: string, payload: Record<string, unknown>) => void;
29
+ export declare class CanaryManager {
30
+ private versions;
31
+ private stableVersion;
32
+ private config;
33
+ private emit;
34
+ private stageEnteredAt;
35
+ constructor(config?: Partial<CanaryConfig>, emit?: CanaryEventEmitter);
36
+ /**
37
+ * Register a new policy version and start canary at stage 0.
38
+ */
39
+ createCanary(id: string, rules: SteeringRule[]): PolicyVersion;
40
+ /**
41
+ * Assign a policy version to a new session via weighted random.
42
+ * Returns the canary version if selected, otherwise stable.
43
+ */
44
+ assignVersion(sessionId: string): PolicyVersion | null;
45
+ /**
46
+ * Update live metrics for a policy version.
47
+ */
48
+ updateMetrics(policyId: string, metrics: Partial<PolicyMetrics>): void;
49
+ /**
50
+ * Check metrics and auto-rollback if thresholds breached.
51
+ * Call this on a 5-minute interval.
52
+ */
53
+ monitorAndRollback(): {
54
+ rolledBack: boolean;
55
+ policyId?: string;
56
+ breachingMetric?: string;
57
+ };
58
+ /**
59
+ * Manually promote a canary to the next traffic stage.
60
+ */
61
+ promote(policyId: string): {
62
+ promoted: boolean;
63
+ newTraffic: number;
64
+ };
65
+ /**
66
+ * Set a version as the stable baseline.
67
+ */
68
+ setStable(version: PolicyVersion): void;
69
+ /** Get currently active canary, if any. */
70
+ getActiveCanary(): PolicyVersion | null;
71
+ /** Get a version by ID. */
72
+ getVersion(id: string): PolicyVersion | null;
73
+ private checkThresholds;
74
+ }
@@ -0,0 +1,57 @@
1
+ import type { SteeringRule } from "./steering-rules.js";
2
+ export type ConstitutionChangeType = "major" | "minor" | "patch";
3
+ export interface ConstitutionVersion {
4
+ semver: string;
5
+ rules: SteeringRule[];
6
+ /** HMAC-SHA256 of rule content + semver */
7
+ signature: string;
8
+ changeType: ConstitutionChangeType;
9
+ changeDescription: string;
10
+ authorId: string;
11
+ activatedAt?: Date;
12
+ }
13
+ export interface LintResult {
14
+ passed: boolean;
15
+ errors: LintDiagnostic[];
16
+ warnings: LintDiagnostic[];
17
+ requiresApproval: boolean;
18
+ }
19
+ export interface LintDiagnostic {
20
+ rule: string;
21
+ message: string;
22
+ severity: "error" | "warning";
23
+ }
24
+ export type ConstitutionEventEmitter = (event: string, payload: Record<string, unknown>) => void;
25
+ export declare class ConstitutionManager {
26
+ private versions;
27
+ private signingKey;
28
+ private emit;
29
+ constructor(signingKey: string, emit?: ConstitutionEventEmitter);
30
+ /**
31
+ * Create a new constitution version. Does NOT activate it.
32
+ */
33
+ createVersion(rules: SteeringRule[], changeType: ConstitutionChangeType, changeDescription: string, authorId: string): ConstitutionVersion;
34
+ /**
35
+ * Lint a new version against the current active version.
36
+ * Must pass before activation.
37
+ */
38
+ lint(newVersion: ConstitutionVersion): LintResult;
39
+ /**
40
+ * Activate a version (only if lint passes).
41
+ */
42
+ activate(semver: string): boolean;
43
+ /**
44
+ * Rollback to a previous version.
45
+ * Creates a new PATCH version with rollback description.
46
+ */
47
+ rollback(targetSemver: string, authorId: string): ConstitutionVersion | null;
48
+ /** Get the currently active version. */
49
+ getActiveVersion(): ConstitutionVersion | null;
50
+ /** Get all versions. */
51
+ listVersions(): ConstitutionVersion[];
52
+ /** Get a specific version by semver. */
53
+ getVersion(semver: string): ConstitutionVersion | null;
54
+ private sign;
55
+ verifySignature(version: ConstitutionVersion): boolean;
56
+ private computeNextSemver;
57
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Sensible defaults for every optional field in WorkspaceProfile.
3
+ */
4
+ import type { VoiceConfig, MemoryConfig, SecurityConfig, AgentLoopConfig, BudgetsConfig } from "./schema.js";
5
+ export declare const DEFAULT_VOICE: VoiceConfig;
6
+ export declare const DEFAULT_MEMORY: MemoryConfig;
7
+ export declare const DEFAULT_SECURITY: SecurityConfig;
8
+ export declare const DEFAULT_AGENT_LOOP: AgentLoopConfig;
9
+ export declare const DEFAULT_BUDGETS: BudgetsConfig;
10
+ export declare const DEFAULTS: {
11
+ readonly version: "1.0.0";
12
+ readonly voice: VoiceConfig;
13
+ readonly memory: MemoryConfig;
14
+ readonly security: SecurityConfig;
15
+ readonly agentLoop: AgentLoopConfig;
16
+ readonly budgets: BudgetsConfig;
17
+ };
@@ -0,0 +1,8 @@
1
+ export * from "./schema.js";
2
+ export * from "./defaults.js";
3
+ export { loadProfile, loadProfileFromObject, interpolateEnv, ConfigError } from "./loader.js";
4
+ export { loadSteeringRules, resolveRules, type SteeringRule, type SteeringRuleSet, type RuleKind, type ConversationContext } from "./steering-rules.js";
5
+ export { CanaryManager, DEFAULT_CANARY_CONFIG } from "./canary.js";
6
+ export type { PolicyStatus, PolicyMetrics, PolicyVersion, CanaryConfig, CanaryEventEmitter, } from "./canary.js";
7
+ export { ConstitutionManager } from "./constitution.js";
8
+ export type { ConstitutionChangeType, ConstitutionVersion, LintResult, LintDiagnostic, ConstitutionEventEmitter, } from "./constitution.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Config loader — reads workspace.json, interpolates env vars,
3
+ * merges with defaults, and validates required fields.
4
+ */
5
+ import type { WorkspaceProfile } from "./schema.js";
6
+ export declare function interpolateEnv(value: string, env?: Record<string, string | undefined>): string;
7
+ export declare class ConfigError extends Error {
8
+ constructor(message: string);
9
+ }
10
+ export declare function loadProfileFromObject(raw: Record<string, unknown>, env?: Record<string, string | undefined>): WorkspaceProfile;
11
+ export declare function loadProfile(filePath: string, env?: Record<string, string | undefined>): Promise<WorkspaceProfile>;