@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.
- package/dist/agent/execution-result.d.ts +27 -0
- package/dist/agent-loop.d.ts +55 -0
- package/dist/api/dashboard.d.ts +260 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/api/middleware.d.ts +46 -0
- package/dist/api/openai-compat.d.ts +163 -0
- package/dist/api/server.d.ts +44 -0
- package/dist/api/streaming.d.ts +15 -0
- package/dist/api/webhook-triggers.d.ts +139 -0
- package/dist/billing/cost-meter.d.ts +123 -0
- package/dist/billing/index.d.ts +2 -0
- package/dist/boot.d.ts +109 -0
- package/dist/channels/discord.d.ts +99 -0
- package/dist/channels/email.d.ts +88 -0
- package/dist/channels/http-api.d.ts +155 -0
- package/dist/channels/index.d.ts +20 -0
- package/dist/channels/mcp-channel.d.ts +75 -0
- package/dist/channels/mobile-hil.d.ts +88 -0
- package/dist/channels/openai-compat.d.ts +42 -0
- package/dist/channels/registry.d.ts +80 -0
- package/dist/channels/signal.d.ts +75 -0
- package/dist/channels/slack.d.ts +115 -0
- package/dist/channels/teams.d.ts +106 -0
- package/dist/channels/telegram.d.ts +164 -0
- package/dist/channels/types.d.ts +71 -0
- package/dist/channels/whatsapp.d.ts +83 -0
- package/dist/checkpoint.d.ts +77 -0
- package/dist/config/canary.d.ts +74 -0
- package/dist/config/constitution.d.ts +57 -0
- package/dist/config/defaults.d.ts +17 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/config/loader.d.ts +11 -0
- package/dist/config/provider-config.d.ts +29 -0
- package/dist/config/schema.d.ts +118 -0
- package/dist/config/steering-rules.d.ts +28 -0
- package/dist/content/chunker.d.ts +42 -0
- package/dist/content/entity-extractor.d.ts +58 -0
- package/dist/content/index.d.ts +8 -0
- package/dist/content/ocr.d.ts +79 -0
- package/dist/content/pipeline.d.ts +153 -0
- package/dist/context-overflow.d.ts +19 -0
- package/dist/editions/mobile.d.ts +12 -0
- package/dist/editions/pro.d.ts +12 -0
- package/dist/editions/voices.d.ts +14 -0
- package/dist/events/block-manager.d.ts +37 -0
- package/dist/events/bus.d.ts +39 -0
- package/dist/events/index.d.ts +8 -0
- package/dist/events/session-manager.d.ts +59 -0
- package/dist/events/stream-adapter.d.ts +24 -0
- package/dist/events/types.d.ts +465 -0
- package/dist/events/websocket.d.ts +34 -0
- package/dist/extensions/defaults/05-session-repair.d.ts +6 -0
- package/dist/extensions/defaults/10-logging.d.ts +6 -0
- package/dist/extensions/defaults/15-loop-guard.d.ts +6 -0
- package/dist/extensions/defaults/20-cost-tracking.d.ts +7 -0
- package/dist/extensions/defaults/25-ssrf-protection.d.ts +6 -0
- package/dist/extensions/defaults/30-rate-limiting.d.ts +6 -0
- package/dist/extensions/defaults/35-shell-bleed.d.ts +6 -0
- package/dist/extensions/defaults/40-observation-capture.d.ts +7 -0
- package/dist/extensions/defaults/45-context-survival.d.ts +6 -0
- package/dist/extensions/defaults/50-context-budget.d.ts +6 -0
- package/dist/extensions/defaults/55-steering-rules.d.ts +7 -0
- package/dist/extensions/defaults/60-quality-gates.d.ts +7 -0
- package/dist/extensions/defaults/65-job-dispatch.d.ts +24 -0
- package/dist/extensions/defaults/70-skill-loader.d.ts +18 -0
- package/dist/extensions/hooks.d.ts +74 -0
- package/dist/extensions/index.d.ts +21 -0
- package/dist/extensions/intervention.d.ts +59 -0
- package/dist/extensions/manager.d.ts +63 -0
- package/dist/extensions/runner.d.ts +63 -0
- package/dist/hooks/hook-manager.d.ts +39 -0
- package/dist/hooks/hook-types.d.ts +60 -0
- package/dist/identity/assembler.d.ts +45 -0
- package/dist/identity/ccc-adapter.d.ts +33 -0
- package/dist/identity/index.d.ts +6 -0
- package/dist/identity/persona-parser.d.ts +24 -0
- package/dist/identity/soul-parser.d.ts +23 -0
- package/dist/identity/user-populator.d.ts +20 -0
- package/dist/index.d.ts +227 -0
- package/dist/index.js +579 -0
- package/dist/interrupt.d.ts +84 -0
- package/dist/job-queue.d.ts +69 -0
- package/dist/jobs/index.d.ts +12 -0
- package/dist/jobs/memory-queue.d.ts +23 -0
- package/dist/jobs/planned-tasks.d.ts +121 -0
- package/dist/jobs/queue.d.ts +79 -0
- package/dist/jobs/router.d.ts +23 -0
- package/dist/jobs/synthesize-memories.d.ts +26 -0
- package/dist/jobs/types.d.ts +47 -0
- package/dist/jobs/worker-pool.d.ts +25 -0
- package/dist/jobs/worker.d.ts +40 -0
- package/dist/loop/autonomous-controller.d.ts +91 -0
- package/dist/loop/backpressure.d.ts +64 -0
- package/dist/loop/fresh-context.d.ts +48 -0
- package/dist/loop/prd-importer.d.ts +134 -0
- package/dist/loop/stop-controller.d.ts +31 -0
- package/dist/loop-guard.d.ts +32 -0
- package/dist/mcp/tool-executor.d.ts +57 -0
- package/dist/memory/brain-artifacts.d.ts +25 -0
- package/dist/memory/dual-search.d.ts +67 -0
- package/dist/memory/episodic.d.ts +45 -0
- package/dist/memory/index.d.ts +27 -0
- package/dist/memory/knowledge-graph.d.ts +89 -0
- package/dist/memory/markdown-store.d.ts +64 -0
- package/dist/memory/metadata-filter.d.ts +29 -0
- package/dist/memory/mid-conversation-saves.d.ts +17 -0
- package/dist/memory/note-parser.d.ts +34 -0
- package/dist/memory/observation-store.d.ts +36 -0
- package/dist/memory/observation-thresholds.d.ts +26 -0
- package/dist/memory/progressive-search.d.ts +25 -0
- package/dist/memory/synthesis.d.ts +36 -0
- package/dist/memory/tree-index.d.ts +104 -0
- package/dist/memory/write-gate.d.ts +63 -0
- package/dist/mission-control.d.ts +34 -0
- package/dist/pre-classifier-widgets.d.ts +40 -0
- package/dist/pre-classifier.d.ts +19 -0
- package/dist/prompt/context-budget.d.ts +68 -0
- package/dist/prompt/index.d.ts +3 -0
- package/dist/prompt/system-prompt.d.ts +32 -0
- package/dist/prompt/templates.d.ts +11 -0
- package/dist/providers/anthropic.d.ts +24 -0
- package/dist/providers/auto-detect.d.ts +16 -0
- package/dist/providers/auto-discover.d.ts +28 -0
- package/dist/providers/bedrock.d.ts +38 -0
- package/dist/providers/cache-strategy.d.ts +58 -0
- package/dist/providers/circuit-breaker.d.ts +33 -0
- package/dist/providers/cost-meter.d.ts +74 -0
- package/dist/providers/cost-tracking.d.ts +36 -0
- package/dist/providers/google.d.ts +35 -0
- package/dist/providers/index.d.ts +32 -0
- package/dist/providers/interface.d.ts +98 -0
- package/dist/providers/json-repair.d.ts +10 -0
- package/dist/providers/key-rotation.d.ts +36 -0
- package/dist/providers/manager.d.ts +64 -0
- package/dist/providers/model-registry.d.ts +50 -0
- package/dist/providers/openai-compatible.d.ts +26 -0
- package/dist/providers/optimization-modes.d.ts +38 -0
- package/dist/providers/provider-manager.d.ts +71 -0
- package/dist/providers/runtime-crud.d.ts +68 -0
- package/dist/providers/sidecar-lifecycle.d.ts +40 -0
- package/dist/providers/stream-wrapper.d.ts +21 -0
- package/dist/providers/structured-verify.d.ts +31 -0
- package/dist/providers/versioning.d.ts +18 -0
- package/dist/quality-gates.d.ts +10 -0
- package/dist/scheduler/engine.d.ts +95 -0
- package/dist/scheduler/index.d.ts +4 -0
- package/dist/scheduler/webhook-handler.d.ts +37 -0
- package/dist/sdk/agent.d.ts +22 -0
- package/dist/sdk/cli.d.ts +2 -0
- package/dist/sdk/client.d.ts +19 -0
- package/dist/sdk/index.d.ts +24 -0
- package/dist/sdk/jobs.d.ts +25 -0
- package/dist/sdk/memory.d.ts +18 -0
- package/dist/sdk/types.d.ts +69 -0
- package/dist/security/approval-gates.d.ts +166 -0
- package/dist/security/content-wrapper.d.ts +38 -0
- package/dist/security/guard-rails.d.ts +6 -0
- package/dist/security/index.d.ts +21 -0
- package/dist/security/instruction-hierarchy.d.ts +109 -0
- package/dist/security/pii-tokenizer.d.ts +30 -0
- package/dist/security/reputation.d.ts +53 -0
- package/dist/security/secret-store.d.ts +41 -0
- package/dist/security/security-engine.d.ts +53 -0
- package/dist/security/shell-bleed.d.ts +15 -0
- package/dist/security/ssrf.d.ts +12 -0
- package/dist/security/taint-tracker.d.ts +63 -0
- package/dist/security/tool-access-control.d.ts +114 -0
- package/dist/session-compaction.d.ts +20 -0
- package/dist/session-orient.d.ts +22 -0
- package/dist/session-repair.d.ts +6 -0
- package/dist/storage/index.d.ts +24 -0
- package/dist/storage/interface.d.ts +245 -0
- package/dist/storage/postgres.d.ts +6 -0
- package/dist/storage/sqlite.d.ts +2 -0
- package/dist/streaming/reasoning.d.ts +67 -0
- package/dist/task-tracker.d.ts +26 -0
- package/dist/testing/action-cache.d.ts +39 -0
- package/dist/testing/incident-eval.d.ts +49 -0
- package/dist/testing/workflow-evals.d.ts +73 -0
- package/dist/tools/access-control.d.ts +60 -0
- package/dist/tools/browser-engine.d.ts +73 -0
- package/dist/tools/builtins/jobs-router.d.ts +7 -0
- package/dist/tools/builtins/tasks-router.d.ts +25 -0
- package/dist/tools/index.d.ts +20 -0
- package/dist/tools/map-reduce.d.ts +64 -0
- package/dist/tools/registry.d.ts +39 -0
- package/dist/tools/router.d.ts +30 -0
- package/dist/tools/routers/browser-router.d.ts +12 -0
- package/dist/tools/routers/code-router.d.ts +34 -0
- package/dist/tools/routers/file-router.d.ts +35 -0
- package/dist/tools/routers/memory-router.d.ts +21 -0
- package/dist/tools/routers/schedule-router.d.ts +31 -0
- package/dist/tools/routers/search-backends.d.ts +47 -0
- package/dist/tools/routers/task-router.d.ts +32 -0
- package/dist/tools/routers/web-router.d.ts +36 -0
- package/dist/tools/skill-discovery.d.ts +32 -0
- package/dist/tools/skill-loader.d.ts +76 -0
- package/dist/tools/skill-types.d.ts +21 -0
- package/dist/voice/audio-intelligence.d.ts +42 -0
- package/dist/voice/barge-in.d.ts +51 -0
- package/dist/voice/index.d.ts +22 -0
- package/dist/voice/marker-parser.d.ts +31 -0
- package/dist/voice/sidecar-manager.d.ts +68 -0
- package/dist/voice/speaker-focus.d.ts +41 -0
- package/dist/voice/speaker-voiceprint.d.ts +47 -0
- package/dist/voice/speech-intent.d.ts +51 -0
- package/dist/voice/speechmatics-stt.d.ts +77 -0
- package/dist/voice/speechmatics-tts.d.ts +39 -0
- package/dist/voice/stt-provider.d.ts +40 -0
- package/dist/voice/transcript.d.ts +19 -0
- package/dist/voice/turn-detection.d.ts +53 -0
- package/dist/wrapup.d.ts +15 -0
- package/package.json +39 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook Triggers — handles POST /api/v1/webhooks/:id
|
|
3
|
+
*
|
|
4
|
+
* Validates incoming webhook signatures, creates MessageEnvelopes,
|
|
5
|
+
* enqueues to the job queue for async processing, and returns 200
|
|
6
|
+
* immediately. The worker processes the webhook asynchronously.
|
|
7
|
+
*
|
|
8
|
+
* Supported providers:
|
|
9
|
+
* - GitHub: SHA-256 HMAC via x-hub-signature-256
|
|
10
|
+
* - Stripe: Custom t=...,v1=... signature via stripe-signature
|
|
11
|
+
* - Generic: Bearer token, custom header, or IP allowlist
|
|
12
|
+
*
|
|
13
|
+
* All signature comparisons use crypto.timingSafeEqual.
|
|
14
|
+
*/
|
|
15
|
+
export interface WebhookMessageEnvelope {
|
|
16
|
+
channel: "webhook";
|
|
17
|
+
userId: string;
|
|
18
|
+
userName?: string;
|
|
19
|
+
conversationId: string;
|
|
20
|
+
messageType: "text";
|
|
21
|
+
content: string;
|
|
22
|
+
attachments?: undefined;
|
|
23
|
+
metadata: Record<string, unknown>;
|
|
24
|
+
timestamp: Date;
|
|
25
|
+
}
|
|
26
|
+
export type WebhookProvider = "github" | "stripe" | "generic";
|
|
27
|
+
export interface GitHubWebhookConfig {
|
|
28
|
+
provider: "github";
|
|
29
|
+
/** The shared HMAC secret configured in GitHub webhook settings. */
|
|
30
|
+
secret: string;
|
|
31
|
+
}
|
|
32
|
+
export interface StripeWebhookConfig {
|
|
33
|
+
provider: "stripe";
|
|
34
|
+
/** The Stripe webhook signing secret (whsec_...). */
|
|
35
|
+
secret: string;
|
|
36
|
+
/** Tolerance in seconds for timestamp validation. Default 300 (5 min). */
|
|
37
|
+
toleranceSec?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface GenericWebhookConfig {
|
|
40
|
+
provider: "generic";
|
|
41
|
+
/** Bearer token for Authorization header validation. */
|
|
42
|
+
bearerToken?: string;
|
|
43
|
+
/** Custom header name + expected value. */
|
|
44
|
+
customHeader?: {
|
|
45
|
+
name: string;
|
|
46
|
+
value: string;
|
|
47
|
+
};
|
|
48
|
+
/** List of allowed source IPs. */
|
|
49
|
+
ipAllowlist?: string[];
|
|
50
|
+
}
|
|
51
|
+
export type WebhookConfig = GitHubWebhookConfig | StripeWebhookConfig | GenericWebhookConfig;
|
|
52
|
+
export interface WebhookRegistration {
|
|
53
|
+
id: string;
|
|
54
|
+
config: WebhookConfig;
|
|
55
|
+
/** Optional label for this webhook. */
|
|
56
|
+
label?: string;
|
|
57
|
+
/** Optional conversation/chat ID to route to. Defaults to "webhook:<id>". */
|
|
58
|
+
conversationId?: string;
|
|
59
|
+
/** Whether the webhook is active. Default true. */
|
|
60
|
+
active: boolean;
|
|
61
|
+
createdAt: Date;
|
|
62
|
+
}
|
|
63
|
+
export interface WebhookRequest {
|
|
64
|
+
/** Raw body as string (for signature verification). */
|
|
65
|
+
rawBody: string;
|
|
66
|
+
/** Parsed JSON body. */
|
|
67
|
+
body: Record<string, unknown>;
|
|
68
|
+
/** HTTP headers (lowercased keys). */
|
|
69
|
+
headers: Record<string, string>;
|
|
70
|
+
/** Source IP address. */
|
|
71
|
+
sourceIp?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface WebhookResult {
|
|
74
|
+
status: number;
|
|
75
|
+
body: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
export type WebhookEventType = "webhook_received" | "webhook_validated" | "webhook_enqueued" | "webhook_validation_failed" | "webhook_not_found" | "webhook_inactive";
|
|
78
|
+
export interface WebhookEvent {
|
|
79
|
+
type: WebhookEventType;
|
|
80
|
+
timestamp: Date;
|
|
81
|
+
webhookId?: string;
|
|
82
|
+
detail: string;
|
|
83
|
+
}
|
|
84
|
+
export type WebhookEventListener = (event: WebhookEvent) => void;
|
|
85
|
+
export interface WebhookJobQueue {
|
|
86
|
+
enqueue(type: string, payload: unknown, chatId?: string): {
|
|
87
|
+
id: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Timing-safe string comparison using crypto.timingSafeEqual.
|
|
92
|
+
*/
|
|
93
|
+
export declare function safeEqual(a: string, b: string): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Verify GitHub webhook signature (x-hub-signature-256).
|
|
96
|
+
* Format: sha256=<hex-digest>
|
|
97
|
+
*/
|
|
98
|
+
export declare function verifyGitHubSignature(rawBody: string, secret: string, signatureHeader: string): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Verify Stripe webhook signature (stripe-signature header).
|
|
101
|
+
* Format: t=<timestamp>,v1=<signature>[,v1=<signature>...]
|
|
102
|
+
*/
|
|
103
|
+
export declare function verifyStripeSignature(rawBody: string, secret: string, signatureHeader: string, toleranceSec?: number): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Verify generic webhook authentication.
|
|
106
|
+
*/
|
|
107
|
+
export declare function verifyGenericAuth(request: WebhookRequest, config: GenericWebhookConfig): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Extract a meaningful content summary from a webhook payload.
|
|
110
|
+
*/
|
|
111
|
+
export declare function extractWebhookContent(provider: WebhookProvider, body: Record<string, unknown>, headers: Record<string, string>): string;
|
|
112
|
+
export declare function createWebhookEnvelope(webhookId: string, provider: WebhookProvider, request: WebhookRequest, conversationId?: string): WebhookMessageEnvelope;
|
|
113
|
+
export interface WebhookHandlerConfig {
|
|
114
|
+
/** Job queue to enqueue validated webhooks into. */
|
|
115
|
+
queue: WebhookJobQueue;
|
|
116
|
+
/** Job type to use when enqueuing. Default "tool.execute". */
|
|
117
|
+
jobType?: string;
|
|
118
|
+
}
|
|
119
|
+
export interface WebhookHandler {
|
|
120
|
+
/** Register a new webhook endpoint. Returns the registration. */
|
|
121
|
+
register(id: string, config: WebhookConfig, opts?: {
|
|
122
|
+
label?: string;
|
|
123
|
+
conversationId?: string;
|
|
124
|
+
}): WebhookRegistration;
|
|
125
|
+
/** Unregister a webhook. */
|
|
126
|
+
unregister(id: string): boolean;
|
|
127
|
+
/** Get a webhook registration. */
|
|
128
|
+
get(id: string): WebhookRegistration | undefined;
|
|
129
|
+
/** List all registrations. */
|
|
130
|
+
list(): WebhookRegistration[];
|
|
131
|
+
/** Enable/disable a webhook. */
|
|
132
|
+
setActive(id: string, active: boolean): boolean;
|
|
133
|
+
/** Handle an incoming webhook request (POST /api/v1/webhooks/:id).
|
|
134
|
+
* Validates, creates envelope, enqueues to job queue, returns 200. */
|
|
135
|
+
handleRequest(webhookId: string, request: WebhookRequest): WebhookResult;
|
|
136
|
+
on(listener: WebhookEventListener): void;
|
|
137
|
+
off(listener: WebhookEventListener): void;
|
|
138
|
+
}
|
|
139
|
+
export declare function createWebhookHandler(config: WebhookHandlerConfig): WebhookHandler;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost Meter — tracks LLM token usage, enforces per-user budgets,
|
|
3
|
+
* emits warning events at 80% threshold, supports admin overrides,
|
|
4
|
+
* and provides usage dashboard data.
|
|
5
|
+
*/
|
|
6
|
+
export interface ModelPricing {
|
|
7
|
+
/** Cost per 1M input tokens in USD. */
|
|
8
|
+
inputPer1M: number;
|
|
9
|
+
/** Cost per 1M output tokens in USD. */
|
|
10
|
+
outputPer1M: number;
|
|
11
|
+
}
|
|
12
|
+
export interface TokenUsage {
|
|
13
|
+
inputTokens: number;
|
|
14
|
+
outputTokens: number;
|
|
15
|
+
totalTokens: number;
|
|
16
|
+
}
|
|
17
|
+
export interface UsageRecord {
|
|
18
|
+
id: string;
|
|
19
|
+
userId: string;
|
|
20
|
+
model: string;
|
|
21
|
+
inputTokens: number;
|
|
22
|
+
outputTokens: number;
|
|
23
|
+
cost: number;
|
|
24
|
+
timestamp: Date;
|
|
25
|
+
/** Optional context (e.g. tool name, job type). */
|
|
26
|
+
context?: string;
|
|
27
|
+
}
|
|
28
|
+
export type BudgetPeriod = "hourly" | "daily" | "monthly";
|
|
29
|
+
export interface BudgetConfig {
|
|
30
|
+
/** Maximum spend in USD for this budget period. */
|
|
31
|
+
limit: number;
|
|
32
|
+
/** Budget period. */
|
|
33
|
+
period: BudgetPeriod;
|
|
34
|
+
/** Warning threshold as fraction (default 0.8 = 80%). */
|
|
35
|
+
warningThreshold?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface UserBudget {
|
|
38
|
+
userId: string;
|
|
39
|
+
config: BudgetConfig;
|
|
40
|
+
/** Whether admin override is active (bypasses budget). */
|
|
41
|
+
adminOverride: boolean;
|
|
42
|
+
}
|
|
43
|
+
export type MeterEventType = "usage_recorded" | "budget_warning" | "budget_exceeded" | "quota:warning" | "quota:exceeded" | "budget_override_set" | "budget_override_cleared" | "budget_reset";
|
|
44
|
+
export interface MeterEvent {
|
|
45
|
+
type: MeterEventType;
|
|
46
|
+
userId: string;
|
|
47
|
+
timestamp: Date;
|
|
48
|
+
data: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
export type MeterEventListener = (event: MeterEvent) => void;
|
|
51
|
+
export interface PreCallCheck {
|
|
52
|
+
allowed: boolean;
|
|
53
|
+
reason?: string;
|
|
54
|
+
remainingBudget?: number;
|
|
55
|
+
usedFraction?: number;
|
|
56
|
+
}
|
|
57
|
+
/** Per-period usage summary for dashboard. */
|
|
58
|
+
export interface PeriodSummary {
|
|
59
|
+
userId: string;
|
|
60
|
+
period: string;
|
|
61
|
+
totalCost: number;
|
|
62
|
+
totalInputTokens: number;
|
|
63
|
+
totalOutputTokens: number;
|
|
64
|
+
requestCount: number;
|
|
65
|
+
budgetLimit?: number;
|
|
66
|
+
usedFraction?: number;
|
|
67
|
+
}
|
|
68
|
+
/** Model-level breakdown for dashboard. */
|
|
69
|
+
export interface ModelBreakdown {
|
|
70
|
+
model: string;
|
|
71
|
+
totalCost: number;
|
|
72
|
+
totalInputTokens: number;
|
|
73
|
+
totalOutputTokens: number;
|
|
74
|
+
requestCount: number;
|
|
75
|
+
}
|
|
76
|
+
export interface DashboardData {
|
|
77
|
+
userId: string;
|
|
78
|
+
currentPeriod: PeriodSummary;
|
|
79
|
+
modelBreakdown: ModelBreakdown[];
|
|
80
|
+
recentRecords: UsageRecord[];
|
|
81
|
+
budget?: {
|
|
82
|
+
limit: number;
|
|
83
|
+
period: string;
|
|
84
|
+
used: number;
|
|
85
|
+
remaining: number;
|
|
86
|
+
fraction: number;
|
|
87
|
+
adminOverride: boolean;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export interface CostMeter {
|
|
91
|
+
/** Register pricing for a model. */
|
|
92
|
+
setModelPricing(model: string, pricing: ModelPricing): void;
|
|
93
|
+
/** Get pricing for a model, or undefined. */
|
|
94
|
+
getModelPricing(model: string): ModelPricing | undefined;
|
|
95
|
+
/** Set a budget for a user. */
|
|
96
|
+
setBudget(userId: string, config: BudgetConfig): void;
|
|
97
|
+
/** Get budget for a user. */
|
|
98
|
+
getBudget(userId: string): UserBudget | undefined;
|
|
99
|
+
/** Remove a user's budget entirely. */
|
|
100
|
+
removeBudget(userId: string): boolean;
|
|
101
|
+
/** Enable admin override: user's calls bypass budget checks. */
|
|
102
|
+
setAdminOverride(userId: string, enabled: boolean): void;
|
|
103
|
+
/** Check if a call should be allowed, given estimated cost. */
|
|
104
|
+
checkBudget(userId: string, estimatedCost: number): PreCallCheck;
|
|
105
|
+
/** Convenience: estimate cost for a given model + token count. */
|
|
106
|
+
estimateCost(model: string, usage: TokenUsage): number;
|
|
107
|
+
/** Record actual usage after a call completes. */
|
|
108
|
+
recordUsage(userId: string, model: string, usage: TokenUsage, context?: string): UsageRecord;
|
|
109
|
+
/** Get total spend for user in the current budget period. */
|
|
110
|
+
getCurrentPeriodSpend(userId: string): number;
|
|
111
|
+
/** Get all records for a user (optionally filtered by period). */
|
|
112
|
+
getRecords(userId: string, periodKey?: string): UsageRecord[];
|
|
113
|
+
/** Get usage dashboard data for a user. */
|
|
114
|
+
getDashboardData(userId: string): DashboardData;
|
|
115
|
+
/** Subscribe to meter events. */
|
|
116
|
+
on(listener: MeterEventListener): void;
|
|
117
|
+
/** Unsubscribe. */
|
|
118
|
+
off(listener: MeterEventListener): void;
|
|
119
|
+
/** Reset spend tracking for a user (new period). */
|
|
120
|
+
resetPeriod(userId: string): void;
|
|
121
|
+
}
|
|
122
|
+
export declare function _resetMeterIds(): void;
|
|
123
|
+
export declare function createCostMeter(): CostMeter;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { CostMeter, createCostMeter, _resetMeterIds } from "./cost-meter.js";
|
|
2
|
+
export type { ModelPricing, TokenUsage, UsageRecord, BudgetPeriod, BudgetConfig, UserBudget, MeterEventType, MeterEvent, MeterEventListener, PreCallCheck, PeriodSummary, ModelBreakdown, DashboardData, } from "./cost-meter.js";
|
package/dist/boot.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { AgentEvent, AgentInput } from "./events/types.js";
|
|
2
|
+
import type { StorageAdapter } from "./storage/interface.js";
|
|
3
|
+
import type { MemoryBackend } from "./tools/routers/memory-router.js";
|
|
4
|
+
import type { WebBackend } from "./tools/routers/web-router.js";
|
|
5
|
+
import type { CodeBackend } from "./tools/routers/code-router.js";
|
|
6
|
+
import type { FileBackend } from "./tools/routers/file-router.js";
|
|
7
|
+
import type { ScheduleBackend } from "./tools/routers/schedule-router.js";
|
|
8
|
+
import type { TaskPlanBackend } from "./tools/routers/task-router.js";
|
|
9
|
+
import type { BrowserEngine } from "./tools/browser-engine.js";
|
|
10
|
+
import { EventBus } from "./events/bus.js";
|
|
11
|
+
import { SessionManager } from "./events/session-manager.js";
|
|
12
|
+
import { ProviderManager } from "./providers/manager.js";
|
|
13
|
+
import { ExtensionManager } from "./extensions/manager.js";
|
|
14
|
+
import { ToolRegistry } from "./tools/registry.js";
|
|
15
|
+
import { ToolRouter } from "./tools/router.js";
|
|
16
|
+
import { SidecarManager } from "./voice/sidecar-manager.js";
|
|
17
|
+
import { SpeechQueue } from "./voice/speech-intent.js";
|
|
18
|
+
import { parseMarkers, stripMarkers } from "./voice/marker-parser.js";
|
|
19
|
+
import { ProgressiveSearch } from "./memory/progressive-search.js";
|
|
20
|
+
import { verifiedGenerateObject } from "./providers/structured-verify.js";
|
|
21
|
+
export interface BootConfig {
|
|
22
|
+
/** Edition name */
|
|
23
|
+
edition: string;
|
|
24
|
+
/** Database URL for PostgreSQL storage */
|
|
25
|
+
databaseUrl?: string;
|
|
26
|
+
/** Storage backend override */
|
|
27
|
+
storageBackend?: "postgres" | "sqlite";
|
|
28
|
+
/** Provider configuration overrides */
|
|
29
|
+
providers?: Record<string, {
|
|
30
|
+
provider: string;
|
|
31
|
+
model: string;
|
|
32
|
+
apiKey?: string;
|
|
33
|
+
baseUrl?: string;
|
|
34
|
+
}>;
|
|
35
|
+
/** Channels to enable */
|
|
36
|
+
channels?: string[];
|
|
37
|
+
/** Tool categories to enable ("*" for all) */
|
|
38
|
+
tools?: string[];
|
|
39
|
+
/** Domain-specific layers */
|
|
40
|
+
layers?: string[];
|
|
41
|
+
/** Maximum agent loop turns */
|
|
42
|
+
maxTurns?: number;
|
|
43
|
+
/** Token budget per session */
|
|
44
|
+
tokenBudget?: number;
|
|
45
|
+
/** Context window token limit */
|
|
46
|
+
contextWindowTokens?: number;
|
|
47
|
+
/** Enable query pre-classification */
|
|
48
|
+
enablePreClassification?: boolean;
|
|
49
|
+
/** Enable structured block emission */
|
|
50
|
+
emitBlocks?: boolean;
|
|
51
|
+
/** System prompt text (when provided, skips dynamic prompt building) */
|
|
52
|
+
systemPrompt?: string;
|
|
53
|
+
/** Read-only tool names for parallel execution */
|
|
54
|
+
readOnlyTools?: string[];
|
|
55
|
+
}
|
|
56
|
+
/** Optional backend dependencies for tool routers */
|
|
57
|
+
export interface BootDeps {
|
|
58
|
+
memoryBackend?: MemoryBackend;
|
|
59
|
+
webBackend?: WebBackend;
|
|
60
|
+
codeBackend?: CodeBackend;
|
|
61
|
+
fileBackend?: FileBackend;
|
|
62
|
+
scheduleBackend?: ScheduleBackend;
|
|
63
|
+
taskBackend?: TaskPlanBackend;
|
|
64
|
+
browserEngine?: BrowserEngine;
|
|
65
|
+
storage?: StorageAdapter;
|
|
66
|
+
}
|
|
67
|
+
export interface RunningKernel {
|
|
68
|
+
readonly edition: string;
|
|
69
|
+
readonly version: string;
|
|
70
|
+
readonly config: BootConfig;
|
|
71
|
+
readonly bus: EventBus;
|
|
72
|
+
readonly sessions: SessionManager;
|
|
73
|
+
readonly providers: ProviderManager;
|
|
74
|
+
readonly extensions: ExtensionManager;
|
|
75
|
+
readonly toolRegistry: ToolRegistry;
|
|
76
|
+
readonly toolRouter: ToolRouter;
|
|
77
|
+
readonly storage: StorageAdapter | null;
|
|
78
|
+
/** Voice utilities (available when voice modules are loaded) */
|
|
79
|
+
readonly voice: {
|
|
80
|
+
sidecarManager: SidecarManager;
|
|
81
|
+
speechQueue: SpeechQueue;
|
|
82
|
+
parseMarkers: typeof parseMarkers;
|
|
83
|
+
stripMarkers: typeof stripMarkers;
|
|
84
|
+
};
|
|
85
|
+
/** Memory utilities */
|
|
86
|
+
readonly memory: {
|
|
87
|
+
progressiveSearch: ProgressiveSearch | null;
|
|
88
|
+
};
|
|
89
|
+
/** Verified structured output wrapper */
|
|
90
|
+
readonly verifiedGenerateObject: typeof verifiedGenerateObject;
|
|
91
|
+
/** Send a message through the agent loop */
|
|
92
|
+
sendMessage(sessionId: string, input: AgentInput): AsyncGenerator<AgentEvent, void, undefined>;
|
|
93
|
+
health(): KernelHealth;
|
|
94
|
+
stop(): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
export interface KernelHealth {
|
|
97
|
+
status: "ok" | "degraded" | "error";
|
|
98
|
+
edition: string;
|
|
99
|
+
version: string;
|
|
100
|
+
providers: {
|
|
101
|
+
slot: string;
|
|
102
|
+
healthy: boolean;
|
|
103
|
+
}[];
|
|
104
|
+
storage: boolean;
|
|
105
|
+
extensions: number;
|
|
106
|
+
tools: number;
|
|
107
|
+
}
|
|
108
|
+
export declare const KERNEL_VERSION = "0.1.0";
|
|
109
|
+
export declare function bootKernel(config: BootConfig, deps?: BootDeps): Promise<RunningKernel>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord Channel Adapter
|
|
3
|
+
*
|
|
4
|
+
* Connects to Discord via Gateway WebSocket using discord.js.
|
|
5
|
+
* Supports slash commands, thread-based conversations, voice channels,
|
|
6
|
+
* rich embeds, message chunking, and reaction-based approval gates.
|
|
7
|
+
*/
|
|
8
|
+
import type { MessageHandler } from "./types.js";
|
|
9
|
+
import type { STTProvider, TTSProvider, TaskInfo, JobInfo } from "./telegram.js";
|
|
10
|
+
export interface DiscordConfig {
|
|
11
|
+
botToken: string;
|
|
12
|
+
onMessage: MessageHandler;
|
|
13
|
+
onReset?: (conversationId: string) => Promise<string>;
|
|
14
|
+
onTasks?: (conversationId: string) => Promise<TaskInfo[]>;
|
|
15
|
+
onJobs?: (conversationId: string) => Promise<JobInfo[]>;
|
|
16
|
+
/** Restrict to specific servers (guild IDs). */
|
|
17
|
+
guildIds?: string[];
|
|
18
|
+
/** Restrict to specific channels. */
|
|
19
|
+
allowedChannelIds?: string[];
|
|
20
|
+
/** Join voice channels for audio I/O. */
|
|
21
|
+
enableVoice?: boolean;
|
|
22
|
+
/** Command prefix for text commands (e.g. "!"). Default: use slash commands only. */
|
|
23
|
+
commandPrefix?: string;
|
|
24
|
+
stt?: STTProvider;
|
|
25
|
+
tts?: TTSProvider;
|
|
26
|
+
/** Override fetch for testing. */
|
|
27
|
+
fetchFn?: typeof globalThis.fetch;
|
|
28
|
+
}
|
|
29
|
+
/** Discord message structure (subset). */
|
|
30
|
+
export interface DiscordMessage {
|
|
31
|
+
id: string;
|
|
32
|
+
channel_id: string;
|
|
33
|
+
guild_id?: string;
|
|
34
|
+
author: {
|
|
35
|
+
id: string;
|
|
36
|
+
username: string;
|
|
37
|
+
discriminator?: string;
|
|
38
|
+
bot?: boolean;
|
|
39
|
+
};
|
|
40
|
+
content: string;
|
|
41
|
+
timestamp: string;
|
|
42
|
+
attachments?: DiscordAttachment[];
|
|
43
|
+
referenced_message?: DiscordMessage | null;
|
|
44
|
+
thread?: {
|
|
45
|
+
id: string;
|
|
46
|
+
};
|
|
47
|
+
type?: number;
|
|
48
|
+
}
|
|
49
|
+
export interface DiscordAttachment {
|
|
50
|
+
id: string;
|
|
51
|
+
filename: string;
|
|
52
|
+
content_type?: string;
|
|
53
|
+
url: string;
|
|
54
|
+
size: number;
|
|
55
|
+
}
|
|
56
|
+
export interface DiscordInteraction {
|
|
57
|
+
id: string;
|
|
58
|
+
type: number;
|
|
59
|
+
data?: {
|
|
60
|
+
name: string;
|
|
61
|
+
options?: Array<{
|
|
62
|
+
name: string;
|
|
63
|
+
value: unknown;
|
|
64
|
+
type: number;
|
|
65
|
+
}>;
|
|
66
|
+
};
|
|
67
|
+
channel_id: string;
|
|
68
|
+
guild_id?: string;
|
|
69
|
+
member?: {
|
|
70
|
+
user: {
|
|
71
|
+
id: string;
|
|
72
|
+
username: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
user?: {
|
|
76
|
+
id: string;
|
|
77
|
+
username: string;
|
|
78
|
+
};
|
|
79
|
+
token: string;
|
|
80
|
+
}
|
|
81
|
+
export interface PendingDiscordApproval {
|
|
82
|
+
id: string;
|
|
83
|
+
channelId: string;
|
|
84
|
+
messageId: string;
|
|
85
|
+
resolve: (choice: string) => void;
|
|
86
|
+
}
|
|
87
|
+
export interface DiscordChannelAdapter {
|
|
88
|
+
start(): Promise<void>;
|
|
89
|
+
stop(): Promise<void>;
|
|
90
|
+
sendMessage(conversationId: string, text: string): Promise<void>;
|
|
91
|
+
/** Process inbound message (for testing). */
|
|
92
|
+
handleMessage(message: DiscordMessage): Promise<void>;
|
|
93
|
+
/** Process inbound interaction (slash command). */
|
|
94
|
+
handleInteraction(interaction: DiscordInteraction): Promise<void>;
|
|
95
|
+
/** Process reaction add for approval gates. */
|
|
96
|
+
handleReaction(messageId: string, emoji: string, userId: string): Promise<void>;
|
|
97
|
+
readonly isRunning: boolean;
|
|
98
|
+
}
|
|
99
|
+
export declare function createDiscordAdapter(config: DiscordConfig): DiscordChannelAdapter;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email Channel Adapter (IMAP/SMTP)
|
|
3
|
+
*
|
|
4
|
+
* Polls an IMAP mailbox for inbound emails, converts them to
|
|
5
|
+
* MessageEnvelopes, and sends replies via SMTP with proper
|
|
6
|
+
* threading (In-Reply-To / References headers).
|
|
7
|
+
*
|
|
8
|
+
* Supports consent gating, sender allow-lists, HTML-to-text
|
|
9
|
+
* conversion, attachment extraction, and rate limiting.
|
|
10
|
+
*/
|
|
11
|
+
import type { MessageHandler } from "./types.js";
|
|
12
|
+
export interface EmailConfig {
|
|
13
|
+
imap: {
|
|
14
|
+
host: string;
|
|
15
|
+
port: number;
|
|
16
|
+
user: string;
|
|
17
|
+
password: string;
|
|
18
|
+
tls: boolean;
|
|
19
|
+
/** Mailbox to poll. Default: "INBOX". */
|
|
20
|
+
mailbox?: string;
|
|
21
|
+
/** Poll interval in ms. Default: 30000. */
|
|
22
|
+
pollIntervalMs?: number;
|
|
23
|
+
};
|
|
24
|
+
smtp: {
|
|
25
|
+
host: string;
|
|
26
|
+
port: number;
|
|
27
|
+
user: string;
|
|
28
|
+
password: string;
|
|
29
|
+
tls: boolean;
|
|
30
|
+
};
|
|
31
|
+
onMessage: MessageHandler;
|
|
32
|
+
/** Only process emails from these addresses. Empty = allow all. */
|
|
33
|
+
allowedSenders?: string[];
|
|
34
|
+
/** Require explicit opt-in before processing. Default: false. */
|
|
35
|
+
consentRequired?: boolean;
|
|
36
|
+
/** Prefix prepended to reply subject lines. Default: "[Fenix] ". */
|
|
37
|
+
subjectPrefix?: string;
|
|
38
|
+
/** Max outbound emails per sender per hour. Default: 10. */
|
|
39
|
+
rateLimitPerHour?: number;
|
|
40
|
+
/** Override for testing — inject mock IMAP fetch. */
|
|
41
|
+
fetchEmails?: () => Promise<InboundEmail[]>;
|
|
42
|
+
/** Override for testing — inject mock SMTP send. */
|
|
43
|
+
sendEmail?: (email: OutboundEmail) => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
/** Parsed inbound email. */
|
|
46
|
+
export interface InboundEmail {
|
|
47
|
+
messageId: string;
|
|
48
|
+
from: string;
|
|
49
|
+
fromName?: string;
|
|
50
|
+
to: string;
|
|
51
|
+
subject: string;
|
|
52
|
+
textBody: string;
|
|
53
|
+
htmlBody?: string;
|
|
54
|
+
date: Date;
|
|
55
|
+
inReplyTo?: string;
|
|
56
|
+
references?: string[];
|
|
57
|
+
attachments?: EmailAttachment[];
|
|
58
|
+
}
|
|
59
|
+
export interface EmailAttachment {
|
|
60
|
+
filename: string;
|
|
61
|
+
contentType: string;
|
|
62
|
+
content: string;
|
|
63
|
+
size: number;
|
|
64
|
+
}
|
|
65
|
+
/** Outbound email for SMTP. */
|
|
66
|
+
export interface OutboundEmail {
|
|
67
|
+
from: string;
|
|
68
|
+
to: string;
|
|
69
|
+
subject: string;
|
|
70
|
+
textBody: string;
|
|
71
|
+
htmlBody?: string;
|
|
72
|
+
inReplyTo?: string;
|
|
73
|
+
references?: string[];
|
|
74
|
+
attachments?: EmailAttachment[];
|
|
75
|
+
}
|
|
76
|
+
export interface EmailChannelAdapter {
|
|
77
|
+
start(): Promise<void>;
|
|
78
|
+
stop(): Promise<void>;
|
|
79
|
+
sendMessage(conversationId: string, text: string): Promise<void>;
|
|
80
|
+
/** Process a batch of inbound emails (for testing / manual trigger). */
|
|
81
|
+
processInbox(emails: InboundEmail[]): Promise<void>;
|
|
82
|
+
/** Check consent status for a sender. */
|
|
83
|
+
hasConsent(senderEmail: string): boolean;
|
|
84
|
+
/** Grant consent for a sender. */
|
|
85
|
+
grantConsent(senderEmail: string): void;
|
|
86
|
+
readonly isRunning: boolean;
|
|
87
|
+
}
|
|
88
|
+
export declare function createEmailAdapter(config: EmailConfig): EmailChannelAdapter;
|