@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,27 @@
|
|
|
1
|
+
export type FinishReason = "completed" | "interrupted" | "timeout" | "error" | "hook-halted" | "max-iterations";
|
|
2
|
+
export interface TokenUsage {
|
|
3
|
+
inputTokens: number;
|
|
4
|
+
outputTokens: number;
|
|
5
|
+
cacheReadTokens?: number;
|
|
6
|
+
cacheWriteTokens?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ExecutionResult {
|
|
9
|
+
/** Final output text from the agent. */
|
|
10
|
+
output: string;
|
|
11
|
+
/** Why execution ended. */
|
|
12
|
+
finishReason: FinishReason;
|
|
13
|
+
/** Whether the run was interrupted by user or stop signal. */
|
|
14
|
+
interrupted: boolean;
|
|
15
|
+
/** Wall-clock duration in milliseconds. */
|
|
16
|
+
durationMs: number;
|
|
17
|
+
/** Number of agent loop iterations completed. */
|
|
18
|
+
iterationCount: number;
|
|
19
|
+
/** Aggregated token usage across all LLM calls. */
|
|
20
|
+
tokenUsage?: TokenUsage;
|
|
21
|
+
}
|
|
22
|
+
export declare function createResult(output: string, finishReason: FinishReason, opts: {
|
|
23
|
+
durationMs: number;
|
|
24
|
+
iterationCount: number;
|
|
25
|
+
tokenUsage?: TokenUsage;
|
|
26
|
+
}): ExecutionResult;
|
|
27
|
+
export declare function mergeTokenUsage(a?: TokenUsage, b?: TokenUsage): TokenUsage;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ProviderManager } from "./providers/manager.js";
|
|
2
|
+
import type { ToolRouter } from "./tools/router.js";
|
|
3
|
+
import type { JobQueue } from "./job-queue.js";
|
|
4
|
+
import type { ExtensionManager } from "./extensions/manager.js";
|
|
5
|
+
import type { AgentEvent, AgentMode, AgentInput, AgentContext, QueryClassification, BlockType, BlockPatch } from "./events/types.js";
|
|
6
|
+
export interface AgentLoopConfig {
|
|
7
|
+
/** Provider manager for slot-based routing */
|
|
8
|
+
providers: ProviderManager;
|
|
9
|
+
/** Tool router for dispatching tool calls */
|
|
10
|
+
toolRouter: ToolRouter;
|
|
11
|
+
/** Job queue for async work (optional) */
|
|
12
|
+
jobQueue?: JobQueue;
|
|
13
|
+
/** Extension manager for hook dispatch (optional) */
|
|
14
|
+
extensions?: ExtensionManager;
|
|
15
|
+
/** Session ID */
|
|
16
|
+
sessionId: string;
|
|
17
|
+
/** Maximum turns before forced stop */
|
|
18
|
+
maxTurns?: number;
|
|
19
|
+
/** Token budget per session */
|
|
20
|
+
tokenBudget?: number;
|
|
21
|
+
/** Context window size for overflow detection */
|
|
22
|
+
contextWindowTokens?: number;
|
|
23
|
+
/** Initial mode */
|
|
24
|
+
initialMode?: AgentMode;
|
|
25
|
+
/** System prompt */
|
|
26
|
+
systemPrompt?: string;
|
|
27
|
+
/** Mode permissions for tool context */
|
|
28
|
+
permissions?: string[];
|
|
29
|
+
/** Query classifier — if provided, runs pre-classification (G26) */
|
|
30
|
+
classifyQuery?: QueryClassifier;
|
|
31
|
+
/** Whether to emit structured blocks (G25) instead of raw tokens */
|
|
32
|
+
emitBlocks?: boolean;
|
|
33
|
+
/** Read-only tool names for parallel execution */
|
|
34
|
+
readOnlyTools?: Set<string>;
|
|
35
|
+
}
|
|
36
|
+
/** G26 query pre-classifier function */
|
|
37
|
+
export type QueryClassifier = (query: string, context: AgentContext) => Promise<QueryClassificationResult>;
|
|
38
|
+
export interface QueryClassificationResult {
|
|
39
|
+
classification: QueryClassification;
|
|
40
|
+
standaloneQuery: string;
|
|
41
|
+
skipAgent: boolean;
|
|
42
|
+
directResponse?: string;
|
|
43
|
+
}
|
|
44
|
+
export declare class BlockManager {
|
|
45
|
+
private blocks;
|
|
46
|
+
private nextId;
|
|
47
|
+
create(type: BlockType, data: unknown): string;
|
|
48
|
+
append(blockId: string, content: string): BlockPatch | null;
|
|
49
|
+
get(blockId: string): {
|
|
50
|
+
type: BlockType;
|
|
51
|
+
data: unknown;
|
|
52
|
+
} | undefined;
|
|
53
|
+
get size(): number;
|
|
54
|
+
}
|
|
55
|
+
export declare function agentLoop(config: AgentLoopConfig, input: AgentInput): AsyncGenerator<AgentEvent, void, undefined>;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mission Control Dashboard API — unified API surface for the Fenix
|
|
3
|
+
* dashboard frontend. Three pillars: Activity Feed, Task Calendar,
|
|
4
|
+
* Global Search, plus stats/providers/jobs/costs endpoints.
|
|
5
|
+
*
|
|
6
|
+
* Endpoints:
|
|
7
|
+
* GET /api/v1/dashboard/activity — Activity feed with filters
|
|
8
|
+
* GET /api/v1/dashboard/calendar — Scheduled tasks for date range
|
|
9
|
+
* GET /api/v1/dashboard/search — Global search
|
|
10
|
+
* GET /api/v1/dashboard/stats — Token usage, provider health, memory
|
|
11
|
+
* GET /api/v1/dashboard/providers — Circuit breaker states, cost per provider
|
|
12
|
+
* GET /api/v1/dashboard/jobs — Job queue status
|
|
13
|
+
* GET /api/v1/dashboard/costs — Cost breakdown by provider/time
|
|
14
|
+
*/
|
|
15
|
+
export interface ActivityEntry {
|
|
16
|
+
id: string;
|
|
17
|
+
/** Event type from the agent event system. */
|
|
18
|
+
eventType: string;
|
|
19
|
+
/** Channel that generated this event. */
|
|
20
|
+
channel?: string;
|
|
21
|
+
/** Session ID. */
|
|
22
|
+
sessionId?: string;
|
|
23
|
+
/** Short human-readable description. */
|
|
24
|
+
summary: string;
|
|
25
|
+
/** Status indicator. */
|
|
26
|
+
status: "info" | "success" | "warning" | "error";
|
|
27
|
+
/** Full event payload. */
|
|
28
|
+
payload: Record<string, unknown>;
|
|
29
|
+
/** When this event occurred. */
|
|
30
|
+
timestamp: Date;
|
|
31
|
+
}
|
|
32
|
+
export interface ActivityFilter {
|
|
33
|
+
/** Filter by event types. */
|
|
34
|
+
eventTypes?: string[];
|
|
35
|
+
/** Filter by channel. */
|
|
36
|
+
channels?: string[];
|
|
37
|
+
/** Filter by date range. */
|
|
38
|
+
dateRange?: {
|
|
39
|
+
from: Date;
|
|
40
|
+
to: Date;
|
|
41
|
+
};
|
|
42
|
+
/** Filter by status. */
|
|
43
|
+
status?: ActivityEntry["status"];
|
|
44
|
+
/** Full-text search in summary. */
|
|
45
|
+
search?: string;
|
|
46
|
+
/** Maximum results. Default 50. */
|
|
47
|
+
limit?: number;
|
|
48
|
+
/** Offset for pagination. */
|
|
49
|
+
offset?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface ActivityFeed {
|
|
52
|
+
/** Log an agent event to the activity feed. */
|
|
53
|
+
log(entry: Omit<ActivityEntry, "id" | "timestamp">): ActivityEntry;
|
|
54
|
+
/** Query the activity feed. */
|
|
55
|
+
query(filter?: ActivityFilter): ActivityEntry[];
|
|
56
|
+
/** Total count matching filter (for pagination). */
|
|
57
|
+
count(filter?: ActivityFilter): number;
|
|
58
|
+
/** Clear all entries. */
|
|
59
|
+
clear(): void;
|
|
60
|
+
}
|
|
61
|
+
export interface CalendarTask {
|
|
62
|
+
id: string;
|
|
63
|
+
/** Task or job name. */
|
|
64
|
+
name: string;
|
|
65
|
+
/** Schedule type. */
|
|
66
|
+
scheduleType: "cron" | "once" | "recurring";
|
|
67
|
+
/** Next scheduled execution time. */
|
|
68
|
+
nextRun: Date | null;
|
|
69
|
+
/** Last execution time. */
|
|
70
|
+
lastRun: Date | null;
|
|
71
|
+
/** Current status. */
|
|
72
|
+
status: "active" | "paused" | "completed" | "cancelled";
|
|
73
|
+
/** Source: scheduler or job queue. */
|
|
74
|
+
source: "scheduler" | "job_queue";
|
|
75
|
+
/** Additional metadata. */
|
|
76
|
+
metadata?: Record<string, unknown>;
|
|
77
|
+
}
|
|
78
|
+
export interface CalendarQuery {
|
|
79
|
+
/** Start of date range. */
|
|
80
|
+
from: Date;
|
|
81
|
+
/** End of date range. */
|
|
82
|
+
to: Date;
|
|
83
|
+
/** Filter by status. */
|
|
84
|
+
status?: CalendarTask["status"];
|
|
85
|
+
/** Filter by source. */
|
|
86
|
+
source?: CalendarTask["source"];
|
|
87
|
+
}
|
|
88
|
+
export interface TaskCalendar {
|
|
89
|
+
/** Get scheduled tasks for a date range. */
|
|
90
|
+
query(opts: CalendarQuery): CalendarTask[];
|
|
91
|
+
/** Pause a scheduled task. */
|
|
92
|
+
pause(taskId: string): boolean;
|
|
93
|
+
/** Resume a paused task. */
|
|
94
|
+
resume(taskId: string): boolean;
|
|
95
|
+
/** Cancel a scheduled task. */
|
|
96
|
+
cancel(taskId: string): boolean;
|
|
97
|
+
/** Reschedule a task to a new time. */
|
|
98
|
+
reschedule(taskId: string, newTime: Date): boolean;
|
|
99
|
+
}
|
|
100
|
+
export type SearchScope = "memory" | "conversations" | "tools" | "tasks" | "content" | "all";
|
|
101
|
+
export interface GlobalSearchResult {
|
|
102
|
+
/** Result identifier. */
|
|
103
|
+
id: string;
|
|
104
|
+
/** Which scope this result came from. */
|
|
105
|
+
scope: SearchScope;
|
|
106
|
+
/** Display title. */
|
|
107
|
+
title: string;
|
|
108
|
+
/** Content snippet. */
|
|
109
|
+
snippet: string;
|
|
110
|
+
/** Relevance score. */
|
|
111
|
+
score: number;
|
|
112
|
+
/** Metadata. */
|
|
113
|
+
metadata?: Record<string, unknown>;
|
|
114
|
+
}
|
|
115
|
+
export interface GlobalSearchOpts {
|
|
116
|
+
/** Scopes to search. Default ["all"]. */
|
|
117
|
+
scopes?: SearchScope[];
|
|
118
|
+
/** Maximum results per scope. Default 10. */
|
|
119
|
+
maxResults?: number;
|
|
120
|
+
}
|
|
121
|
+
export type GlobalSearchFn = (query: string, opts?: GlobalSearchOpts) => Promise<GlobalSearchResult[]>;
|
|
122
|
+
export interface DashboardStats {
|
|
123
|
+
/** Token usage summary. */
|
|
124
|
+
tokenUsage: {
|
|
125
|
+
totalInput: number;
|
|
126
|
+
totalOutput: number;
|
|
127
|
+
totalCost: number;
|
|
128
|
+
period: string;
|
|
129
|
+
};
|
|
130
|
+
/** Provider health overview. */
|
|
131
|
+
providerHealth: ProviderStatus[];
|
|
132
|
+
/** Memory breakdown. */
|
|
133
|
+
memory: {
|
|
134
|
+
totalEntities: number;
|
|
135
|
+
totalRelations: number;
|
|
136
|
+
totalFacts: number;
|
|
137
|
+
totalContentSources: number;
|
|
138
|
+
};
|
|
139
|
+
/** Active sessions. */
|
|
140
|
+
activeSessions: number;
|
|
141
|
+
/** Pending jobs. */
|
|
142
|
+
pendingJobs: number;
|
|
143
|
+
}
|
|
144
|
+
export interface ProviderStatus {
|
|
145
|
+
name: string;
|
|
146
|
+
/** Circuit breaker state. */
|
|
147
|
+
circuitState: "closed" | "open" | "half-open";
|
|
148
|
+
/** Total cost for this provider. */
|
|
149
|
+
totalCost: number;
|
|
150
|
+
/** Request count. */
|
|
151
|
+
requestCount: number;
|
|
152
|
+
/** Error count. */
|
|
153
|
+
errorCount: number;
|
|
154
|
+
/** Average latency in ms. */
|
|
155
|
+
avgLatencyMs: number;
|
|
156
|
+
}
|
|
157
|
+
export interface CostBreakdown {
|
|
158
|
+
/** Provider name. */
|
|
159
|
+
provider: string;
|
|
160
|
+
/** Time period label. */
|
|
161
|
+
period: string;
|
|
162
|
+
/** Input token cost. */
|
|
163
|
+
inputCost: number;
|
|
164
|
+
/** Output token cost. */
|
|
165
|
+
outputCost: number;
|
|
166
|
+
/** Total cost. */
|
|
167
|
+
totalCost: number;
|
|
168
|
+
/** Request count. */
|
|
169
|
+
requestCount: number;
|
|
170
|
+
}
|
|
171
|
+
export interface JobStatus {
|
|
172
|
+
/** Total jobs. */
|
|
173
|
+
total: number;
|
|
174
|
+
/** Breakdown by status. */
|
|
175
|
+
queued: number;
|
|
176
|
+
running: number;
|
|
177
|
+
completed: number;
|
|
178
|
+
failed: number;
|
|
179
|
+
dead: number;
|
|
180
|
+
/** Recent completions. */
|
|
181
|
+
recentCompletions: Array<{
|
|
182
|
+
id: string;
|
|
183
|
+
type: string;
|
|
184
|
+
completedAt: Date;
|
|
185
|
+
}>;
|
|
186
|
+
/** Recent failures. */
|
|
187
|
+
recentFailures: Array<{
|
|
188
|
+
id: string;
|
|
189
|
+
type: string;
|
|
190
|
+
error: string;
|
|
191
|
+
failedAt: Date;
|
|
192
|
+
}>;
|
|
193
|
+
}
|
|
194
|
+
export interface DashboardConfig {
|
|
195
|
+
/** Maximum activity entries to retain in memory. Default 1000. */
|
|
196
|
+
maxActivityEntries?: number;
|
|
197
|
+
/** Stats data providers (pluggable). */
|
|
198
|
+
getStats?: () => Promise<DashboardStats>;
|
|
199
|
+
/** Provider status data. */
|
|
200
|
+
getProviders?: () => Promise<ProviderStatus[]>;
|
|
201
|
+
/** Job status data. */
|
|
202
|
+
getJobs?: () => Promise<JobStatus>;
|
|
203
|
+
/** Cost breakdown data. */
|
|
204
|
+
getCosts?: (period?: string) => Promise<CostBreakdown[]>;
|
|
205
|
+
/** Global search implementation (e.g. backed by DualSearch). */
|
|
206
|
+
searchFn?: GlobalSearchFn;
|
|
207
|
+
}
|
|
208
|
+
export interface Dashboard {
|
|
209
|
+
/** Activity feed. */
|
|
210
|
+
readonly activity: ActivityFeed;
|
|
211
|
+
/** Task calendar. */
|
|
212
|
+
readonly calendar: TaskCalendar;
|
|
213
|
+
/** Global search. */
|
|
214
|
+
search(query: string, opts?: GlobalSearchOpts): Promise<GlobalSearchResult[]>;
|
|
215
|
+
/** Get dashboard stats. */
|
|
216
|
+
getStats(): Promise<DashboardStats>;
|
|
217
|
+
/** Get provider statuses. */
|
|
218
|
+
getProviders(): Promise<ProviderStatus[]>;
|
|
219
|
+
/** Get job status overview. */
|
|
220
|
+
getJobs(): Promise<JobStatus>;
|
|
221
|
+
/** Get cost breakdown. */
|
|
222
|
+
getCosts(period?: string): Promise<CostBreakdown[]>;
|
|
223
|
+
/** Handle GET /api/v1/dashboard/activity */
|
|
224
|
+
handleActivity(params: Record<string, string | undefined>): {
|
|
225
|
+
status: number;
|
|
226
|
+
body: unknown;
|
|
227
|
+
};
|
|
228
|
+
/** Handle GET /api/v1/dashboard/calendar */
|
|
229
|
+
handleCalendar(params: Record<string, string | undefined>): {
|
|
230
|
+
status: number;
|
|
231
|
+
body: unknown;
|
|
232
|
+
};
|
|
233
|
+
/** Handle GET /api/v1/dashboard/search */
|
|
234
|
+
handleSearch(params: Record<string, string | undefined>): Promise<{
|
|
235
|
+
status: number;
|
|
236
|
+
body: unknown;
|
|
237
|
+
}>;
|
|
238
|
+
/** Handle GET /api/v1/dashboard/stats */
|
|
239
|
+
handleStats(): Promise<{
|
|
240
|
+
status: number;
|
|
241
|
+
body: unknown;
|
|
242
|
+
}>;
|
|
243
|
+
/** Handle GET /api/v1/dashboard/providers */
|
|
244
|
+
handleProviders(): Promise<{
|
|
245
|
+
status: number;
|
|
246
|
+
body: unknown;
|
|
247
|
+
}>;
|
|
248
|
+
/** Handle GET /api/v1/dashboard/jobs */
|
|
249
|
+
handleJobs(): Promise<{
|
|
250
|
+
status: number;
|
|
251
|
+
body: unknown;
|
|
252
|
+
}>;
|
|
253
|
+
/** Handle GET /api/v1/dashboard/costs */
|
|
254
|
+
handleCosts(params: Record<string, string | undefined>): Promise<{
|
|
255
|
+
status: number;
|
|
256
|
+
body: unknown;
|
|
257
|
+
}>;
|
|
258
|
+
}
|
|
259
|
+
export declare function _resetDashboardIds(): void;
|
|
260
|
+
export declare function createDashboard(config?: DashboardConfig): Dashboard;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createApiServer, type ApiServer, type ApiServerConfig } from "./server.js";
|
|
2
|
+
export { createSSEStream, createSSEStreamFromIterable } from "./streaming.js";
|
|
3
|
+
export { jsonResponse, errorResponse, parseJsonBody, CORS_HEADERS, corsPreflightResponse, validateAuth, validateRequired, withErrorHandling, buildRoute, matchRoute, ApiException, type ApiError, type RouteHandler, type Route, } from "./middleware.js";
|
|
4
|
+
export { createDashboard, _resetDashboardIds } from "./dashboard.js";
|
|
5
|
+
export type { ActivityEntry, ActivityFilter, ActivityFeed, CalendarTask, CalendarQuery, TaskCalendar, SearchScope, GlobalSearchResult, GlobalSearchOpts, GlobalSearchFn, DashboardStats, ProviderStatus, CostBreakdown, JobStatus, DashboardConfig, Dashboard, } from "./dashboard.js";
|
|
6
|
+
export { validateRequest, createOpenAICompatHandler, _resetCompletionIds, } from "./openai-compat.js";
|
|
7
|
+
export type { ChatRole, ChatMessage, ChatCompletionRequest, ChatCompletionChoice, CompletionUsage, ChatCompletionResponse, ChatCompletionChunkDelta, ChatCompletionChunkChoice, ChatCompletionChunk, AgentCompletionResult, AgentCompletionFn, AgentStreamFn, CompatEventType, CompatEvent, CompatEventListener, ValidationError, OpenAICompatConfig, OpenAICompatHandler, } from "./openai-compat.js";
|
|
8
|
+
export { safeEqual, verifyGitHubSignature, verifyStripeSignature, verifyGenericAuth, extractWebhookContent, createWebhookEnvelope, createWebhookHandler, } from "./webhook-triggers.js";
|
|
9
|
+
export type { WebhookMessageEnvelope, WebhookProvider, GitHubWebhookConfig, StripeWebhookConfig, GenericWebhookConfig, WebhookConfig, WebhookRegistration, WebhookRequest, WebhookResult, WebhookEventType, WebhookEvent, WebhookEventListener, WebhookJobQueue, WebhookHandlerConfig, WebhookHandler, } from "./webhook-triggers.js";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface ApiError {
|
|
2
|
+
error: string;
|
|
3
|
+
code?: string;
|
|
4
|
+
status: number;
|
|
5
|
+
}
|
|
6
|
+
export type RouteHandler = (req: Request, params: Record<string, string>) => Promise<Response> | Response;
|
|
7
|
+
export declare const CORS_HEADERS: Record<string, string>;
|
|
8
|
+
export declare function corsPreflightResponse(): Response;
|
|
9
|
+
export declare function errorResponse(status: number, error: string, code?: string): Response;
|
|
10
|
+
export declare function jsonResponse(data: unknown, status?: number): Response;
|
|
11
|
+
/**
|
|
12
|
+
* Wrap a route handler with error handling.
|
|
13
|
+
* Catches thrown errors and returns structured JSON error responses.
|
|
14
|
+
*/
|
|
15
|
+
export declare function withErrorHandling(handler: RouteHandler): RouteHandler;
|
|
16
|
+
/**
|
|
17
|
+
* Validate bearer token from Authorization header.
|
|
18
|
+
* Returns null if valid or missing (when optional), throws if invalid.
|
|
19
|
+
*/
|
|
20
|
+
export declare function validateAuth(req: Request, expectedToken?: string): string | null;
|
|
21
|
+
export declare function parseJsonBody<T = unknown>(req: Request): Promise<T>;
|
|
22
|
+
export declare function validateRequired(body: Record<string, unknown>, fields: string[]): void;
|
|
23
|
+
export interface Route {
|
|
24
|
+
method: string;
|
|
25
|
+
pattern: RegExp;
|
|
26
|
+
paramNames: string[];
|
|
27
|
+
handler: RouteHandler;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build a route from a pattern like "/api/v1/jobs/:id/cancel".
|
|
31
|
+
* Extracts named parameters from the URL.
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildRoute(method: string, path: string, handler: RouteHandler): Route;
|
|
34
|
+
/**
|
|
35
|
+
* Match a request against a list of routes.
|
|
36
|
+
* Returns the matched route and extracted parameters, or null.
|
|
37
|
+
*/
|
|
38
|
+
export declare function matchRoute(routes: Route[], method: string, pathname: string): {
|
|
39
|
+
route: Route;
|
|
40
|
+
params: Record<string, string>;
|
|
41
|
+
} | null;
|
|
42
|
+
export declare class ApiException extends Error {
|
|
43
|
+
readonly status: number;
|
|
44
|
+
readonly code?: string | undefined;
|
|
45
|
+
constructor(status: number, message: string, code?: string | undefined);
|
|
46
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-Compatible API — accepts POST /v1/chat/completions in the
|
|
3
|
+
* OpenAI SDK format, runs the request through the Fenix agent loop,
|
|
4
|
+
* and returns a response shaped exactly like OpenAI's API.
|
|
5
|
+
*
|
|
6
|
+
* Supports:
|
|
7
|
+
* - Non-streaming completions (returns full JSON body)
|
|
8
|
+
* - Streaming via SSE (Server-Sent Events) with `stream: true`
|
|
9
|
+
* - Token usage tracking
|
|
10
|
+
* - Multiple message roles (system, user, assistant, tool)
|
|
11
|
+
* - Model routing (passed through to the completion function)
|
|
12
|
+
* - stop reasons (stop, length, tool_calls)
|
|
13
|
+
*/
|
|
14
|
+
export type ChatRole = "system" | "user" | "assistant" | "tool";
|
|
15
|
+
export interface ChatMessage {
|
|
16
|
+
role: ChatRole;
|
|
17
|
+
content: string | null;
|
|
18
|
+
name?: string;
|
|
19
|
+
tool_call_id?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ChatCompletionRequest {
|
|
22
|
+
model: string;
|
|
23
|
+
messages: ChatMessage[];
|
|
24
|
+
temperature?: number;
|
|
25
|
+
top_p?: number;
|
|
26
|
+
max_tokens?: number;
|
|
27
|
+
stream?: boolean;
|
|
28
|
+
stop?: string | string[];
|
|
29
|
+
presence_penalty?: number;
|
|
30
|
+
frequency_penalty?: number;
|
|
31
|
+
user?: string;
|
|
32
|
+
/** Fenix extension: pass-through metadata for the agent loop. */
|
|
33
|
+
metadata?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
export interface ChatCompletionChoice {
|
|
36
|
+
index: number;
|
|
37
|
+
message: ChatMessage;
|
|
38
|
+
finish_reason: "stop" | "length" | "tool_calls" | null;
|
|
39
|
+
}
|
|
40
|
+
export interface CompletionUsage {
|
|
41
|
+
prompt_tokens: number;
|
|
42
|
+
completion_tokens: number;
|
|
43
|
+
total_tokens: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ChatCompletionResponse {
|
|
46
|
+
id: string;
|
|
47
|
+
object: "chat.completion";
|
|
48
|
+
created: number;
|
|
49
|
+
model: string;
|
|
50
|
+
choices: ChatCompletionChoice[];
|
|
51
|
+
usage: CompletionUsage;
|
|
52
|
+
}
|
|
53
|
+
export interface ChatCompletionChunkDelta {
|
|
54
|
+
role?: ChatRole;
|
|
55
|
+
content?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface ChatCompletionChunkChoice {
|
|
58
|
+
index: number;
|
|
59
|
+
delta: ChatCompletionChunkDelta;
|
|
60
|
+
finish_reason: "stop" | "length" | "tool_calls" | null;
|
|
61
|
+
}
|
|
62
|
+
export interface ChatCompletionChunk {
|
|
63
|
+
id: string;
|
|
64
|
+
object: "chat.completion.chunk";
|
|
65
|
+
created: number;
|
|
66
|
+
model: string;
|
|
67
|
+
choices: ChatCompletionChunkChoice[];
|
|
68
|
+
}
|
|
69
|
+
export interface AgentCompletionResult {
|
|
70
|
+
content: string;
|
|
71
|
+
finishReason?: "stop" | "length" | "tool_calls";
|
|
72
|
+
usage?: {
|
|
73
|
+
promptTokens: number;
|
|
74
|
+
completionTokens: number;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A completion function that the Fenix agent loop exposes.
|
|
79
|
+
* The OpenAI compat layer calls this, and it runs through the full
|
|
80
|
+
* agent pipeline (instruction hierarchy, approval gates, cost metering, etc.)
|
|
81
|
+
*/
|
|
82
|
+
export type AgentCompletionFn = (opts: {
|
|
83
|
+
model: string;
|
|
84
|
+
messages: ChatMessage[];
|
|
85
|
+
temperature?: number;
|
|
86
|
+
topP?: number;
|
|
87
|
+
maxTokens?: number;
|
|
88
|
+
stop?: string | string[];
|
|
89
|
+
user?: string;
|
|
90
|
+
metadata?: Record<string, unknown>;
|
|
91
|
+
}) => Promise<AgentCompletionResult>;
|
|
92
|
+
/**
|
|
93
|
+
* Streaming variant — yields content chunks.
|
|
94
|
+
*/
|
|
95
|
+
export type AgentStreamFn = (opts: {
|
|
96
|
+
model: string;
|
|
97
|
+
messages: ChatMessage[];
|
|
98
|
+
temperature?: number;
|
|
99
|
+
topP?: number;
|
|
100
|
+
maxTokens?: number;
|
|
101
|
+
stop?: string | string[];
|
|
102
|
+
user?: string;
|
|
103
|
+
metadata?: Record<string, unknown>;
|
|
104
|
+
}) => AsyncIterable<{
|
|
105
|
+
content: string;
|
|
106
|
+
done: boolean;
|
|
107
|
+
}>;
|
|
108
|
+
export declare function _resetCompletionIds(): void;
|
|
109
|
+
export type CompatEventType = "request_received" | "completion_success" | "completion_error" | "stream_start" | "stream_end" | "validation_error";
|
|
110
|
+
export interface CompatEvent {
|
|
111
|
+
type: CompatEventType;
|
|
112
|
+
timestamp: Date;
|
|
113
|
+
requestId?: string;
|
|
114
|
+
model?: string;
|
|
115
|
+
detail: string;
|
|
116
|
+
}
|
|
117
|
+
export type CompatEventListener = (event: CompatEvent) => void;
|
|
118
|
+
export interface ValidationError {
|
|
119
|
+
error: {
|
|
120
|
+
message: string;
|
|
121
|
+
type: "invalid_request_error";
|
|
122
|
+
param: string | null;
|
|
123
|
+
code: string | null;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export declare function validateRequest(body: unknown): {
|
|
127
|
+
valid: true;
|
|
128
|
+
request: ChatCompletionRequest;
|
|
129
|
+
} | {
|
|
130
|
+
valid: false;
|
|
131
|
+
error: ValidationError;
|
|
132
|
+
};
|
|
133
|
+
export interface OpenAICompatConfig {
|
|
134
|
+
/** The agent completion function (non-streaming). */
|
|
135
|
+
complete: AgentCompletionFn;
|
|
136
|
+
/** Optional streaming completion function. If not provided,
|
|
137
|
+
* streaming requests fall back to non-streaming + single chunk. */
|
|
138
|
+
stream?: AgentStreamFn;
|
|
139
|
+
/** Default model name when none specified in routing. */
|
|
140
|
+
defaultModel?: string;
|
|
141
|
+
}
|
|
142
|
+
export interface OpenAICompatHandler {
|
|
143
|
+
/** Handle a /v1/chat/completions request. Returns the response
|
|
144
|
+
* body and status code. For streaming, returns an AsyncIterable of SSE lines. */
|
|
145
|
+
handleCompletion(body: unknown): Promise<{
|
|
146
|
+
status: number;
|
|
147
|
+
body: ChatCompletionResponse | ValidationError;
|
|
148
|
+
} | {
|
|
149
|
+
status: number;
|
|
150
|
+
stream: AsyncIterable<string>;
|
|
151
|
+
}>;
|
|
152
|
+
/** Handle just validation (useful for middleware). */
|
|
153
|
+
validate(body: unknown): {
|
|
154
|
+
valid: true;
|
|
155
|
+
request: ChatCompletionRequest;
|
|
156
|
+
} | {
|
|
157
|
+
valid: false;
|
|
158
|
+
error: ValidationError;
|
|
159
|
+
};
|
|
160
|
+
on(listener: CompatEventListener): void;
|
|
161
|
+
off(listener: CompatEventListener): void;
|
|
162
|
+
}
|
|
163
|
+
export declare function createOpenAICompatHandler(config: OpenAICompatConfig): OpenAICompatHandler;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AgentEvent } from "../events/types.js";
|
|
2
|
+
import type { EventBus } from "../events/bus.js";
|
|
3
|
+
import type { SessionManager } from "../events/session-manager.js";
|
|
4
|
+
import type { JobQueue } from "../job-queue.js";
|
|
5
|
+
export interface ApiServerConfig {
|
|
6
|
+
/** Port to listen on (default: 3000) */
|
|
7
|
+
port?: number;
|
|
8
|
+
/** Hostname to bind to (default: "0.0.0.0") */
|
|
9
|
+
hostname?: string;
|
|
10
|
+
/** EventBus for pub/sub */
|
|
11
|
+
bus: EventBus;
|
|
12
|
+
/** Session manager for reconnection */
|
|
13
|
+
sessions: SessionManager;
|
|
14
|
+
/** Job queue for async work (optional) */
|
|
15
|
+
jobQueue?: JobQueue;
|
|
16
|
+
/** Bearer token for auth (optional — no auth if omitted) */
|
|
17
|
+
authToken?: string;
|
|
18
|
+
/** Handler for incoming messages — should return an async iterable of events */
|
|
19
|
+
onMessage?: (sessionId: string, message: string) => AsyncIterable<AgentEvent>;
|
|
20
|
+
}
|
|
21
|
+
export interface ApiServer {
|
|
22
|
+
/** The underlying Bun server */
|
|
23
|
+
server: ReturnType<typeof Bun.serve>;
|
|
24
|
+
/** The port the server is listening on */
|
|
25
|
+
port: number;
|
|
26
|
+
/** Stop the server */
|
|
27
|
+
stop(): void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create and start the Fenix HTTP API server.
|
|
31
|
+
*
|
|
32
|
+
* Endpoints:
|
|
33
|
+
* - GET /api/v1/health
|
|
34
|
+
* - POST /api/v1/conversations
|
|
35
|
+
* - GET /api/v1/conversations/:id
|
|
36
|
+
* - DELETE /api/v1/conversations/:id
|
|
37
|
+
* - POST /api/v1/conversations/:id/messages
|
|
38
|
+
* - GET /api/v1/jobs
|
|
39
|
+
* - GET /api/v1/jobs/:id
|
|
40
|
+
* - POST /api/v1/jobs/:id/cancel
|
|
41
|
+
* - POST /api/v1/jobs/:id/retry
|
|
42
|
+
* - POST /api/v1/reconnect/:sessionId
|
|
43
|
+
*/
|
|
44
|
+
export declare function createApiServer(config: ApiServerConfig): ApiServer;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AgentEvent } from "../events/types.js";
|
|
2
|
+
import type { SessionManager } from "../events/session-manager.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create an SSE streaming response that replays buffered events
|
|
5
|
+
* then streams live events from a session.
|
|
6
|
+
*
|
|
7
|
+
* Used by both the message endpoint (new session) and the
|
|
8
|
+
* reconnect endpoint (existing session).
|
|
9
|
+
*/
|
|
10
|
+
export declare function createSSEStream(sessionManager: SessionManager, sessionId: string): Response;
|
|
11
|
+
/**
|
|
12
|
+
* Create an SSE stream that pipes events from an async iterable.
|
|
13
|
+
* Used when running a fresh agent loop (not reconnecting).
|
|
14
|
+
*/
|
|
15
|
+
export declare function createSSEStreamFromIterable(events: AsyncIterable<AgentEvent>): Response;
|