@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,29 @@
1
+ export interface V14SlotConfig {
2
+ provider: string;
3
+ model: string;
4
+ apiKey?: string;
5
+ }
6
+ export type V14ProvidersConfig = Record<string, V14SlotConfig>;
7
+ export interface V15ModalityConfig {
8
+ model: string;
9
+ }
10
+ export interface V15ProviderEntry {
11
+ provider: string;
12
+ apiKeys?: string[];
13
+ apiKey?: string;
14
+ modalities: Record<string, V15ModalityConfig>;
15
+ }
16
+ export type V15ProvidersConfig = V15ProviderEntry[];
17
+ export interface ResolvedSlot {
18
+ slot: string;
19
+ provider: string;
20
+ model: string;
21
+ apiKeys: string[];
22
+ }
23
+ export interface ResolvedProviderConfig {
24
+ slots: ResolvedSlot[];
25
+ }
26
+ export declare function isV14Format(providers: unknown): providers is V14ProvidersConfig;
27
+ export declare function isV15Format(providers: unknown): providers is V15ProvidersConfig;
28
+ export declare function resolveEnvVar(value: string): string;
29
+ export declare function normalizeProviderConfig(providers: V14ProvidersConfig | V15ProvidersConfig): ResolvedProviderConfig;
@@ -0,0 +1,118 @@
1
+ /**
2
+ * WorkspaceProfile schema — full configuration surface for a Fenix workspace.
3
+ */
4
+ export interface ProviderSlot {
5
+ provider: string;
6
+ model: string;
7
+ apiKeyEnv?: string;
8
+ }
9
+ export interface ProvidersConfig {
10
+ chat: ProviderSlot;
11
+ utility: ProviderSlot;
12
+ embedding?: ProviderSlot;
13
+ vision?: ProviderSlot;
14
+ }
15
+ export interface VoiceConfig {
16
+ enabled: boolean;
17
+ sttProvider?: string;
18
+ sttModel?: string;
19
+ ttsProvider?: string;
20
+ ttsModel?: string;
21
+ ttsVoice?: string;
22
+ sidecarPort?: number;
23
+ }
24
+ export interface ChannelConfig {
25
+ type: string;
26
+ enabled: boolean;
27
+ tokenEnv?: string;
28
+ options?: Record<string, unknown>;
29
+ }
30
+ export interface ChannelsConfig {
31
+ [channelName: string]: ChannelConfig;
32
+ }
33
+ export interface ObservationsConfig {
34
+ enabled: boolean;
35
+ captureModel: string;
36
+ maxResultTruncation: number;
37
+ autoPromoteThreshold: number;
38
+ reviewThreshold: number;
39
+ tensionThreshold: number;
40
+ }
41
+ export interface MemoryConfig {
42
+ enabled: boolean;
43
+ backend: string;
44
+ path?: string;
45
+ observations: ObservationsConfig;
46
+ }
47
+ export interface RateLimitRule {
48
+ window: string;
49
+ max: number;
50
+ }
51
+ export interface SecurityConfig {
52
+ maxToolIterations: number;
53
+ loopGuardMaxTotal: number;
54
+ sandboxTimeout: number;
55
+ ssrfProtection: boolean;
56
+ shellBleedAction: "log" | "block" | "abort";
57
+ rateLimits: Record<string, RateLimitRule>;
58
+ approvalGates: string[];
59
+ toolAccess: Record<string, "allow" | "deny" | "approve">;
60
+ }
61
+ export interface CompactionConfig {
62
+ enabled: boolean;
63
+ strategy: string;
64
+ targetTokens: number;
65
+ }
66
+ export interface QualityGatesConfig {
67
+ enabled: boolean;
68
+ checks: string[];
69
+ }
70
+ export interface AgentLoopConfig {
71
+ verbosity: "quiet" | "normal" | "verbose" | "debug";
72
+ modalLoop: boolean;
73
+ parallelToolExecution: boolean;
74
+ wrapupOnLimit: boolean;
75
+ qualityGates: QualityGatesConfig;
76
+ compaction: CompactionConfig;
77
+ }
78
+ export interface BudgetsConfig {
79
+ hourlyUsd?: number;
80
+ dailyUsd?: number;
81
+ monthlyUsd?: number;
82
+ }
83
+ export interface WorkspaceProfile {
84
+ name: string;
85
+ version: string;
86
+ providers: ProvidersConfig;
87
+ voice?: VoiceConfig;
88
+ channels?: ChannelsConfig;
89
+ memory?: MemoryConfig;
90
+ security?: SecurityConfig;
91
+ agentLoop?: AgentLoopConfig;
92
+ budgets?: BudgetsConfig;
93
+ }
94
+ export interface V15ModalityEntry {
95
+ model: string;
96
+ }
97
+ export interface V15ProviderEntry {
98
+ provider: string;
99
+ apiKeys?: string[];
100
+ apiKey?: string;
101
+ modalities: Record<string, V15ModalityEntry>;
102
+ }
103
+ /** Raw providers input: v1.4 object OR v1.5 array */
104
+ export type ProvidersInput = ProvidersConfig | V15ProviderEntry[];
105
+ export type DeepPartial<T> = {
106
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
107
+ };
108
+ export interface WorkspaceProfileInput {
109
+ name: string;
110
+ version?: string;
111
+ providers: ProvidersInput;
112
+ voice?: DeepPartial<VoiceConfig>;
113
+ channels?: ChannelsConfig;
114
+ memory?: DeepPartial<MemoryConfig>;
115
+ security?: DeepPartial<SecurityConfig>;
116
+ agentLoop?: DeepPartial<AgentLoopConfig>;
117
+ budgets?: BudgetsConfig;
118
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Steering rules loader — reads markdown rule files from a workspace
3
+ * rules/ directory and resolves which apply to the current context.
4
+ *
5
+ * rules/always/ → always injected into system prompt
6
+ * rules/conditional/ → injected when file/tool/topic conditions match
7
+ * rules/manual/ → only when user invokes @rulename or /rule rulename
8
+ */
9
+ export type RuleKind = "always" | "conditional" | "manual";
10
+ export interface SteeringRule {
11
+ name: string;
12
+ kind: RuleKind;
13
+ priority: number;
14
+ content: string;
15
+ fileMatch?: string;
16
+ toolMatch?: string;
17
+ topicMatch?: string;
18
+ }
19
+ export interface SteeringRuleSet {
20
+ rules: SteeringRule[];
21
+ }
22
+ export interface ConversationContext {
23
+ files?: string[];
24
+ tools?: string[];
25
+ userMessage?: string;
26
+ }
27
+ export declare function loadSteeringRules(rulesDir: string): Promise<SteeringRuleSet>;
28
+ export declare function resolveRules(ruleSet: SteeringRuleSet, ctx: ConversationContext): string[];
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Text Chunker — splits text into overlapping chunks suitable for
3
+ * embedding and semantic search.
4
+ *
5
+ * Features:
6
+ * - Configurable max chunk size and overlap
7
+ * - Paragraph-aware splitting (prefers breaking at paragraph boundaries)
8
+ * - Sentence-aware fallback (splits at sentence boundaries within paragraphs)
9
+ * - Character-level fallback for very long unbroken text
10
+ * - Simple token estimation (word-based, ~1.3 tokens per word)
11
+ */
12
+ export interface ChunkOptions {
13
+ /** Maximum tokens per chunk. Default 512. */
14
+ maxTokens?: number;
15
+ /** Overlap tokens between consecutive chunks. Default 64. */
16
+ overlapTokens?: number;
17
+ /** Approximate tokens-per-word ratio for estimation. Default 1.3. */
18
+ tokensPerWord?: number;
19
+ }
20
+ export interface TextChunk {
21
+ /** Chunk index (0-based). */
22
+ index: number;
23
+ /** The chunk text content. */
24
+ text: string;
25
+ /** Estimated token count. */
26
+ estimatedTokens: number;
27
+ /** Character offset in the original text where this chunk starts. */
28
+ startOffset: number;
29
+ /** Character offset in the original text where this chunk ends (exclusive). */
30
+ endOffset: number;
31
+ }
32
+ /**
33
+ * Split text into overlapping chunks suitable for embedding.
34
+ *
35
+ * Strategy:
36
+ * 1. Split into paragraphs (double newline)
37
+ * 2. Accumulate paragraphs into chunks up to maxTokens
38
+ * 3. If a single paragraph exceeds maxTokens, split on sentences
39
+ * 4. If a single sentence exceeds maxTokens, hard-split on words/chars
40
+ * 5. Apply overlap by repeating trailing text from previous chunk
41
+ */
42
+ export declare function chunkText(text: string, opts?: ChunkOptions): TextChunk[];
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Entity Extractor — extract structured entities and relations from
3
+ * content pipeline chunks using an LLM completion function.
4
+ *
5
+ * Integrates with the content pipeline (IndexedChunk) and knowledge
6
+ * graph (ExtractedEntity, ExtractedRelation) to form a bridge between
7
+ * ingested content and the entity store.
8
+ */
9
+ import type { IndexedChunk } from "./pipeline.js";
10
+ import type { ExtractedEntity, ExtractedRelation, LLMCompleteFn } from "../memory/knowledge-graph.js";
11
+ export interface EntityExtractionConfig {
12
+ /** LLM function for generating extractions. */
13
+ llm: LLMCompleteFn;
14
+ /** Maximum chunks to process in parallel. Default 5. */
15
+ concurrency?: number;
16
+ /** Custom extraction prompt template. Use {text} as placeholder. */
17
+ promptTemplate?: string;
18
+ }
19
+ export interface ChunkExtractionResult {
20
+ /** The chunk that was processed. */
21
+ chunkIndex: number;
22
+ sourceId: string;
23
+ /** Extracted entities from this chunk. */
24
+ entities: ExtractedEntity[];
25
+ /** Extracted relations from this chunk. */
26
+ relations: ExtractedRelation[];
27
+ }
28
+ export interface BatchExtractionResult {
29
+ /** All extractions grouped by chunk. */
30
+ chunks: ChunkExtractionResult[];
31
+ /** Deduplicated, merged entities across all chunks. */
32
+ entities: ExtractedEntity[];
33
+ /** All relations across all chunks. */
34
+ relations: ExtractedRelation[];
35
+ /** Number of chunks processed. */
36
+ processedCount: number;
37
+ /** Number of chunks that failed extraction. */
38
+ errorCount: number;
39
+ }
40
+ export type EntityExtractorEventType = "extraction_start" | "chunk_extracted" | "chunk_error" | "extraction_done";
41
+ export interface EntityExtractorEvent {
42
+ type: EntityExtractorEventType;
43
+ timestamp: Date;
44
+ detail: string;
45
+ sourceId?: string;
46
+ chunkIndex?: number;
47
+ }
48
+ export type EntityExtractorEventListener = (event: EntityExtractorEvent) => void;
49
+ export interface EntityExtractor {
50
+ /** Extract entities/relations from a single chunk. */
51
+ extractFromChunk(chunk: IndexedChunk): Promise<ChunkExtractionResult>;
52
+ /** Extract entities/relations from multiple chunks in batch. */
53
+ extractFromChunks(chunks: IndexedChunk[]): Promise<BatchExtractionResult>;
54
+ /** Events. */
55
+ on(listener: EntityExtractorEventListener): void;
56
+ off(listener: EntityExtractorEventListener): void;
57
+ }
58
+ export declare function createEntityExtractor(config: EntityExtractionConfig): EntityExtractor;
@@ -0,0 +1,8 @@
1
+ export { chunkText } from "./chunker.js";
2
+ export type { ChunkOptions, TextChunk } from "./chunker.js";
3
+ export { ContentPipeline, createContentPipeline, _resetPipelineIds, } from "./pipeline.js";
4
+ export type { ContentType, PipelineStage, ContentSource, IndexedChunk, SearchResult, ContentExtractor, EmbedProvider, PipelineJobQueue, PipelineEventType, PipelineEvent, PipelineEventListener, UploadRequest, HttpResult, ContentPipelineConfig, } from "./pipeline.js";
5
+ export { OCREngine, createOCREngine, DEFAULT_PROVIDER_CASCADE } from "./ocr.js";
6
+ export type { OCRProviderName, OCRProvider, OCRInput, BoundingBox, OCRTextBlock, OCRResult, OCREventType, OCREvent, OCREventListener, OCREngineConfig, } from "./ocr.js";
7
+ export { EntityExtractor, createEntityExtractor } from "./entity-extractor.js";
8
+ export type { EntityExtractionConfig, ChunkExtractionResult, BatchExtractionResult, EntityExtractorEventType, EntityExtractorEvent, EntityExtractorEventListener, } from "./entity-extractor.js";
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Vision-LLM OCR — provider-agnostic OCR via vision-language models.
3
+ *
4
+ * Provider preference cascade (first available wins):
5
+ * Chandra → PaddleOCR-VL → Qwen2.5-VL → DeepSeek-OCR → Cloud APIs
6
+ *
7
+ * No Surya, Docker, or Python dependencies. Pure TypeScript with
8
+ * pluggable provider backends.
9
+ */
10
+ export type OCRProviderName = "chandra" | "paddleocr-vl" | "qwen2.5-vl" | "deepseek-ocr" | "cloud" | (string & {});
11
+ export interface OCRProvider {
12
+ /** Provider identifier. */
13
+ name: OCRProviderName;
14
+ /** Whether this provider is currently available/healthy. */
15
+ isAvailable(): Promise<boolean>;
16
+ /** Run OCR on an image and return extracted text. */
17
+ recognize(input: OCRInput): Promise<OCRResult>;
18
+ }
19
+ export interface OCRInput {
20
+ /** Image data as base64-encoded string. */
21
+ imageBase64: string;
22
+ /** MIME type (e.g. "image/png", "image/jpeg"). */
23
+ mimeType: string;
24
+ /** Optional language hint (e.g. "en", "zh"). */
25
+ language?: string;
26
+ /** Optional: request structured output (bounding boxes). */
27
+ structured?: boolean;
28
+ }
29
+ export interface BoundingBox {
30
+ x: number;
31
+ y: number;
32
+ width: number;
33
+ height: number;
34
+ }
35
+ export interface OCRTextBlock {
36
+ text: string;
37
+ confidence: number;
38
+ boundingBox?: BoundingBox;
39
+ }
40
+ export interface OCRResult {
41
+ /** Full extracted text. */
42
+ text: string;
43
+ /** Provider that produced this result. */
44
+ provider: OCRProviderName;
45
+ /** Individual text blocks (if structured output requested). */
46
+ blocks: OCRTextBlock[];
47
+ /** Processing time in milliseconds. */
48
+ durationMs: number;
49
+ }
50
+ export type OCREventType = "provider_selected" | "provider_unavailable" | "ocr_start" | "ocr_done" | "ocr_error" | "fallback";
51
+ export interface OCREvent {
52
+ type: OCREventType;
53
+ timestamp: Date;
54
+ provider?: OCRProviderName;
55
+ detail: string;
56
+ }
57
+ export type OCREventListener = (event: OCREvent) => void;
58
+ /** Default provider cascade order. */
59
+ export declare const DEFAULT_PROVIDER_CASCADE: OCRProviderName[];
60
+ export interface OCREngineConfig {
61
+ /** Registered providers (order matters for cascade). */
62
+ providers: OCRProvider[];
63
+ /** Override the default cascade order. If omitted, uses registration order. */
64
+ cascadeOrder?: OCRProviderName[];
65
+ /** Maximum retries on provider failure before trying next. Default 1. */
66
+ maxRetries?: number;
67
+ }
68
+ export interface OCREngine {
69
+ /** Run OCR with automatic provider cascade. */
70
+ recognize(input: OCRInput): Promise<OCRResult>;
71
+ /** Check which providers are currently available. */
72
+ availableProviders(): Promise<OCRProviderName[]>;
73
+ /** List all registered providers. */
74
+ listProviders(): OCRProviderName[];
75
+ /** Events. */
76
+ on(listener: OCREventListener): void;
77
+ off(listener: OCREventListener): void;
78
+ }
79
+ export declare function createOCREngine(config: OCREngineConfig): OCREngine;
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Content Ingestion Pipeline — full content lifecycle:
3
+ * upload → extract → chunk → embed → index
4
+ *
5
+ * Features:
6
+ * - Pluggable content extractors (text, HTML, markdown, PDF, etc.)
7
+ * - Pluggable embed provider (maps chunk text → vector)
8
+ * - In-memory vector store with cosine similarity search
9
+ * - Job queue integration for async processing
10
+ * - Framework-agnostic HTTP endpoint handlers
11
+ * - Full event system for monitoring pipeline stages
12
+ * - Source management (status, deletion)
13
+ */
14
+ import type { ChunkOptions } from "./chunker.js";
15
+ export declare function _resetPipelineIds(): void;
16
+ export type ContentType = "text" | "html" | "markdown" | "pdf" | "json";
17
+ export type PipelineStage = "uploaded" | "extracting" | "chunking" | "embedding" | "indexing" | "ready" | "failed";
18
+ export interface ContentSource {
19
+ id: string;
20
+ /** Original file name or label. */
21
+ name: string;
22
+ contentType: ContentType;
23
+ /** Current pipeline stage. */
24
+ stage: PipelineStage;
25
+ /** Number of chunks produced. */
26
+ chunkCount: number;
27
+ /** Error message if stage is "failed". */
28
+ error?: string;
29
+ /** Size of original content in bytes. */
30
+ sizeBytes: number;
31
+ createdAt: Date;
32
+ updatedAt: Date;
33
+ /** Optional metadata attached at upload time. */
34
+ metadata?: Record<string, unknown>;
35
+ }
36
+ export interface IndexedChunk {
37
+ /** Source ID this chunk belongs to. */
38
+ sourceId: string;
39
+ /** Chunk index within the source. */
40
+ chunkIndex: number;
41
+ /** The chunk text. */
42
+ text: string;
43
+ /** Estimated token count. */
44
+ estimatedTokens: number;
45
+ /** Embedding vector. */
46
+ vector: number[];
47
+ /** Character offset in original extracted text. */
48
+ startOffset: number;
49
+ endOffset: number;
50
+ }
51
+ export interface SearchResult {
52
+ /** The matched chunk. */
53
+ chunk: IndexedChunk;
54
+ /** Cosine similarity score (0-1). */
55
+ score: number;
56
+ /** The content source this chunk belongs to. */
57
+ source: ContentSource;
58
+ }
59
+ /**
60
+ * Content extractor: transforms raw content into plain text for chunking.
61
+ */
62
+ export interface ContentExtractor {
63
+ /** Content types this extractor handles. */
64
+ types: ContentType[];
65
+ /** Extract plain text from raw content. */
66
+ extract(raw: string, contentType: ContentType): Promise<string>;
67
+ }
68
+ /**
69
+ * Embedding provider: maps text to a vector.
70
+ */
71
+ export interface EmbedProvider {
72
+ /** Dimension of output vectors. */
73
+ dimensions: number;
74
+ /** Embed a single text string. */
75
+ embed(text: string): Promise<number[]>;
76
+ /** Batch embed multiple texts. Returns vectors in same order. */
77
+ embedBatch?(texts: string[]): Promise<number[][]>;
78
+ }
79
+ export interface PipelineJobQueue {
80
+ enqueue(type: string, payload: unknown, chatId?: string): {
81
+ id: string;
82
+ };
83
+ }
84
+ export type PipelineEventType = "source_uploaded" | "extraction_start" | "extraction_done" | "chunking_start" | "chunking_done" | "embedding_start" | "embedding_done" | "indexing_done" | "source_ready" | "source_failed" | "source_deleted" | "search_executed";
85
+ export interface PipelineEvent {
86
+ type: PipelineEventType;
87
+ timestamp: Date;
88
+ sourceId?: string;
89
+ detail: string;
90
+ }
91
+ export type PipelineEventListener = (event: PipelineEvent) => void;
92
+ export interface UploadRequest {
93
+ /** Content as a string. */
94
+ content: string;
95
+ /** File name or label. */
96
+ name: string;
97
+ /** Content type. Default "text". */
98
+ contentType?: ContentType;
99
+ /** Optional metadata. */
100
+ metadata?: Record<string, unknown>;
101
+ }
102
+ export interface HttpResult {
103
+ status: number;
104
+ body: Record<string, unknown>;
105
+ }
106
+ export interface ContentPipelineConfig {
107
+ /** Embedding provider. Required. */
108
+ embedProvider: EmbedProvider;
109
+ /** Custom content extractors. Merged with defaults. */
110
+ extractors?: ContentExtractor[];
111
+ /** Chunk options passed to the text chunker. */
112
+ chunkOptions?: ChunkOptions;
113
+ /** Optional job queue for async processing. */
114
+ queue?: PipelineJobQueue;
115
+ /** Job type for async ingestion. Default "tool.execute". */
116
+ jobType?: string;
117
+ }
118
+ export interface ContentPipeline {
119
+ /**
120
+ * Ingest content through the full pipeline.
121
+ * Returns the content source with stage "ready" on success.
122
+ */
123
+ ingest(request: UploadRequest): Promise<ContentSource>;
124
+ /** Get the status of a content source by ID. */
125
+ getStatus(sourceId: string): ContentSource | undefined;
126
+ /** List all content sources. */
127
+ listSources(): ContentSource[];
128
+ /**
129
+ * Search indexed chunks by query text.
130
+ * Embeds the query, then finds top-k chunks by cosine similarity.
131
+ */
132
+ search(query: string, opts?: {
133
+ topK?: number;
134
+ minScore?: number;
135
+ sourceId?: string;
136
+ }): Promise<SearchResult[]>;
137
+ /** Delete a source and all its indexed chunks. */
138
+ deleteSource(sourceId: string): boolean;
139
+ /** Handle POST /api/v1/content/upload */
140
+ handleUpload(body: unknown): Promise<HttpResult>;
141
+ /** Handle GET /api/v1/content/:id */
142
+ handleGetStatus(sourceId: string): HttpResult;
143
+ /** Handle GET /api/v1/content/search?q=... */
144
+ handleSearch(query: string, opts?: {
145
+ topK?: number;
146
+ sourceId?: string;
147
+ }): Promise<HttpResult>;
148
+ /** Handle DELETE /api/v1/content/:id */
149
+ handleDelete(sourceId: string): HttpResult;
150
+ on(listener: PipelineEventListener): void;
151
+ off(listener: PipelineEventListener): void;
152
+ }
153
+ export declare function createContentPipeline(config: ContentPipelineConfig): ContentPipeline;
@@ -0,0 +1,19 @@
1
+ import type { Message, LLMProvider } from "./providers/interface.js";
2
+ import type { AgentEvent } from "./events/types.js";
3
+ export interface OverflowContext {
4
+ contextWindowTokens?: number;
5
+ utilityProvider?: LLMProvider;
6
+ utilityModel?: string;
7
+ sessionId?: string;
8
+ }
9
+ export interface OverflowResult {
10
+ messages: Message[];
11
+ stage: number;
12
+ strategy: string;
13
+ }
14
+ export declare function estimateTokens(messages: Message[]): number;
15
+ export declare function contextOverflowRecovery(messages: Message[], context: OverflowContext): AsyncGenerator<AgentEvent, OverflowResult>;
16
+ export declare function contextOverflowCheck(messages: Message[], contextWindowTokens?: number): {
17
+ ratio: number;
18
+ overLimit: boolean;
19
+ };
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Fenix Agent — Mobile Edition
4
+ *
5
+ * Lightweight edition with:
6
+ * - Real agent loop (LLM-powered responses)
7
+ * - Telegram channel adapter (long-polling)
8
+ * - Single-threaded worker (no pool)
9
+ * - Local-only job types (no browser, scrape, image gen)
10
+ * - Job tool router registered
11
+ */
12
+ export {};
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Fenix Agent — Pro Edition
4
+ *
5
+ * Full-featured edition with:
6
+ * - Real agent loop (LLM-powered responses)
7
+ * - Telegram channel adapter (long-polling)
8
+ * - Job queue with worker pool (default 3 workers)
9
+ * - All job types enabled
10
+ * - Job tool router registered
11
+ */
12
+ export {};
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Fenix Agent — Voices Edition
4
+ *
5
+ * Voice-first edition with:
6
+ * - Real agent loop (LLM-powered responses)
7
+ * - Telegram channel adapter (long-polling)
8
+ * - Job queue with worker pool (default 3 workers)
9
+ * - All job types enabled (including audio.transcribe, image.generate)
10
+ * - Voice/audio-specific job priorities
11
+ * - Voice pipeline (SidecarManager, SpeechQueue, markers)
12
+ * - Job tool router registered
13
+ */
14
+ export {};
@@ -0,0 +1,37 @@
1
+ import type { Block, BlockType, BlockPatch } from "./types.js";
2
+ import type { EventBus } from "./bus.js";
3
+ export interface BlockManagerConfig {
4
+ /** Event bus for emitting block events */
5
+ bus: EventBus;
6
+ /** Session ID for event context */
7
+ sessionId: string;
8
+ }
9
+ /**
10
+ * Manages structured blocks and emits events through the EventBus.
11
+ *
12
+ * Usage:
13
+ * - `emitBlock("text", "Hello")` → creates block, emits `block:emitted`
14
+ * - `updateBlock(id, [{ op: "append", path: "data", value: " world" }])`
15
+ * → patches block in-place, emits `block:updated` per patch
16
+ *
17
+ * Clients maintain a local block map and apply patches as they arrive.
18
+ */
19
+ export declare class EventBlockManager {
20
+ private blocks;
21
+ private nextId;
22
+ private bus;
23
+ private sessionId;
24
+ constructor(config: BlockManagerConfig);
25
+ /** Create and emit a new block. Returns the block ID. */
26
+ emitBlock(type: BlockType, data: unknown): Promise<string>;
27
+ /** Apply patches to an existing block. Returns false if block not found. */
28
+ updateBlock(blockId: string, patches: BlockPatch[]): Promise<boolean>;
29
+ /** Get a block by ID. */
30
+ getBlock(blockId: string): Block | undefined;
31
+ /** Get all blocks in creation order. */
32
+ getAllBlocks(): Block[];
33
+ /** Total blocks managed. */
34
+ get size(): number;
35
+ /** Apply a single patch to a block in-place. */
36
+ private applyPatch;
37
+ }
@@ -0,0 +1,39 @@
1
+ import type { AgentEvent, AgentEventType } from "./types.js";
2
+ export type EventHandler<T extends AgentEvent = AgentEvent> = (event: T) => void | Promise<void>;
3
+ export type ErrorHandler = (error: unknown, event: AgentEvent) => void;
4
+ export declare class EventBus {
5
+ private handlers;
6
+ private allHandlers;
7
+ private errorHandler?;
8
+ /** "soon" events — drained on next microtask. */
9
+ private soonQueue;
10
+ private soonScheduled;
11
+ /** "later" events — drained explicitly via drainDeferred(). */
12
+ private laterQueue;
13
+ /** Subscribe to a specific event type. Returns an unsubscribe function. */
14
+ subscribe<T extends AgentEventType>(type: T, handler: EventHandler<Extract<AgentEvent, {
15
+ type: T;
16
+ }>>): () => void;
17
+ /** Subscribe to all events. Returns an unsubscribe function. */
18
+ subscribeAll(handler: EventHandler<AgentEvent>): () => void;
19
+ /** Set error handler for handler failures (error isolation). */
20
+ onError(handler: ErrorHandler): void;
21
+ /**
22
+ * Emit an event with urgency-aware delivery.
23
+ *
24
+ * - immediate: delivered synchronously (default, backward-compatible)
25
+ * - soon: queued and delivered on next microtask
26
+ * - later: queued and delivered when drainDeferred() is called
27
+ */
28
+ emit(event: AgentEvent): Promise<void>;
29
+ /** Drain all "later" events (call when agent is idle). */
30
+ drainDeferred(): Promise<number>;
31
+ /** Number of pending "soon" + "later" events. */
32
+ get pendingCount(): number;
33
+ /** Count of handlers for a specific type, or total if omitted. */
34
+ listenerCount(type?: AgentEventType): number;
35
+ /** Remove all handlers and flush queues. */
36
+ clear(): void;
37
+ private deliver;
38
+ private scheduleSoonDrain;
39
+ }
@@ -0,0 +1,8 @@
1
+ export * from "./types.js";
2
+ export { EventBus, type EventHandler, type ErrorHandler } from "./bus.js";
3
+ export { pipeToEventBus, collectEvents, type StreamAdapterConfig } from "./stream-adapter.js";
4
+ export { setupDualWebSocket, type WebSocketChannel, type WebSocketMessage, type WebSocketSender, type DualWebSocketConfig, } from "./websocket.js";
5
+ export { EventBlockManager } from "./block-manager.js";
6
+ export type { BlockManagerConfig } from "./block-manager.js";
7
+ export { SessionManager } from "./session-manager.js";
8
+ export type { EventListener, Session, SessionManagerConfig } from "./session-manager.js";