@xopcai/xopc 0.0.25 → 0.0.27
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/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/agents-w8_jzuiX.js +216 -0
- package/dist/gateway/static/root/assets/agents-w8_jzuiX.js.map +1 -0
- package/dist/gateway/static/root/assets/{apps-page-DbzO48lg.js → apps-page-CBBh_Ww8.js} +2 -2
- package/dist/gateway/static/root/assets/{apps-page-DbzO48lg.js.map → apps-page-CBBh_Ww8.js.map} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-DUKRPC7C.js +9 -0
- package/dist/gateway/static/root/assets/{channels-settings-CeGoU9v8.js.map → channels-settings-DUKRPC7C.js.map} +1 -1
- package/dist/gateway/static/root/assets/cron-page-S18t1yG-.js +2 -0
- package/dist/gateway/static/root/assets/{cron-page-DpEYUvxB.js.map → cron-page-S18t1yG-.js.map} +1 -1
- package/dist/gateway/static/root/assets/{cron-utils-Cvv0F3pa.js → cron-utils-08gdQfl9.js} +2 -2
- package/dist/gateway/static/root/assets/{cron-utils-Cvv0F3pa.js.map → cron-utils-08gdQfl9.js.map} +1 -1
- package/dist/gateway/static/root/assets/dist-C1MrygQH.js +2 -0
- package/dist/gateway/static/root/assets/{dist-C41N3YrO.js.map → dist-C1MrygQH.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-CkkYZjNP.js → extension-debug-page-DN3HKUGS.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-debug-page-CkkYZjNP.js.map → extension-debug-page-DN3HKUGS.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-BjUIPVNG.js → extension-page-CoFDHZtZ.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-page-BjUIPVNG.js.map → extension-page-CoFDHZtZ.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-CwuFDOdk.js → extension-settings-page-BcPCu_Go.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-settings-page-CwuFDOdk.js.map → extension-settings-page-BcPCu_Go.js.map} +1 -1
- package/dist/gateway/static/root/assets/index-OT4cGzon.css +1 -0
- package/dist/gateway/static/root/assets/index-PfkB8N37.js +4734 -0
- package/dist/gateway/static/root/assets/index-PfkB8N37.js.map +1 -0
- package/dist/gateway/static/root/assets/logs-page-DoWe1GWy.js +2 -0
- package/dist/gateway/static/root/assets/{logs-page-BtwGPuw2.js.map → logs-page-DoWe1GWy.js.map} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-2uOYwEwd.js +2 -0
- package/dist/gateway/static/root/assets/{sessions-page-4rKFDn2k.js.map → sessions-page-2uOYwEwd.js.map} +1 -1
- package/dist/gateway/static/root/assets/settings-page-fQWswCuq.js +2 -0
- package/dist/gateway/static/root/assets/settings-page-fQWswCuq.js.map +1 -0
- package/dist/gateway/static/root/assets/skills-page-BmBDCEbY.js +3 -0
- package/dist/gateway/static/root/assets/{skills-page-_siDuHeF.js.map → skills-page-BmBDCEbY.js.map} +1 -1
- package/dist/gateway/static/root/index.html +2 -2
- package/dist/package.js +1 -1
- package/dist/src/agent/memory/dreaming/config.d.ts +37 -9
- package/dist/src/agent/memory/dreaming/config.js +60 -18
- package/dist/src/agent/memory/dreaming/config.js.map +1 -1
- package/dist/src/agent/memory/dreaming/constants.d.ts +22 -1
- package/dist/src/agent/memory/dreaming/constants.js +26 -2
- package/dist/src/agent/memory/dreaming/constants.js.map +1 -1
- package/dist/src/agent/memory/dreaming/deep-promotion.d.ts +5 -6
- package/dist/src/agent/memory/dreaming/deep-promotion.js +90 -156
- package/dist/src/agent/memory/dreaming/deep-promotion.js.map +1 -1
- package/dist/src/agent/memory/dreaming/events.d.ts +36 -0
- package/dist/src/agent/memory/dreaming/events.js +44 -0
- package/dist/src/agent/memory/dreaming/events.js.map +1 -0
- package/dist/src/agent/memory/dreaming/last-run.d.ts +80 -0
- package/dist/src/agent/memory/dreaming/last-run.js +98 -0
- package/dist/src/agent/memory/dreaming/last-run.js.map +1 -0
- package/dist/src/agent/memory/dreaming/light-sweep.d.ts +19 -0
- package/dist/src/agent/memory/dreaming/light-sweep.js +328 -0
- package/dist/src/agent/memory/dreaming/light-sweep.js.map +1 -0
- package/dist/src/agent/memory/dreaming/preview.d.ts +3 -1
- package/dist/src/agent/memory/dreaming/preview.js +11 -90
- package/dist/src/agent/memory/dreaming/preview.js.map +1 -1
- package/dist/src/agent/memory/dreaming/rem-patterns.d.ts +21 -0
- package/dist/src/agent/memory/dreaming/rem-patterns.js +286 -0
- package/dist/src/agent/memory/dreaming/rem-patterns.js.map +1 -0
- package/dist/src/agent/memory/dreaming/short-term-store.d.ts +20 -0
- package/dist/src/agent/memory/dreaming/short-term-store.js +25 -15
- package/dist/src/agent/memory/dreaming/short-term-store.js.map +1 -1
- package/dist/src/agent/memory/dreaming/utils.d.ts +42 -0
- package/dist/src/agent/memory/dreaming/utils.js +141 -0
- package/dist/src/agent/memory/dreaming/utils.js.map +1 -0
- package/dist/src/agent/orchestration/agent-orchestrator.js +54 -12
- package/dist/src/agent/orchestration/agent-orchestrator.js.map +1 -1
- package/dist/src/agent/service.js +54 -28
- package/dist/src/agent/service.js.map +1 -1
- package/dist/src/config/schema.d.ts +54 -0
- package/dist/src/config/schema.js +34 -8
- package/dist/src/config/schema.js.map +1 -1
- package/dist/src/gateway/hono/lib/config-payload.d.ts +18 -0
- package/dist/src/gateway/hono/routes/dreaming.js +105 -15
- package/dist/src/gateway/hono/routes/dreaming.js.map +1 -1
- package/dist/src/gateway/hono/routes/models.js +26 -1
- package/dist/src/gateway/hono/routes/models.js.map +1 -1
- package/dist/src/gateway/hono/routes/public-gateway.js +1 -0
- package/dist/src/gateway/hono/routes/public-gateway.js.map +1 -1
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/agents-C_bPhtBs.js +0 -216
- package/dist/gateway/static/root/assets/agents-C_bPhtBs.js.map +0 -1
- package/dist/gateway/static/root/assets/channels-settings-CeGoU9v8.js +0 -9
- package/dist/gateway/static/root/assets/cron-page-DpEYUvxB.js +0 -2
- package/dist/gateway/static/root/assets/dist-C41N3YrO.js +0 -2
- package/dist/gateway/static/root/assets/index-DwzwDCjW.js +0 -150
- package/dist/gateway/static/root/assets/index-DwzwDCjW.js.map +0 -1
- package/dist/gateway/static/root/assets/index-dhtHG1nU.css +0 -1
- package/dist/gateway/static/root/assets/logs-page-BtwGPuw2.js +0 -2
- package/dist/gateway/static/root/assets/sessions-page-4rKFDn2k.js +0 -2
- package/dist/gateway/static/root/assets/settings-page-iYLSxQYc.js +0 -2
- package/dist/gateway/static/root/assets/settings-page-iYLSxQYc.js.map +0 -1
- package/dist/gateway/static/root/assets/skills-page-_siDuHeF.js +0 -3
|
@@ -116,19 +116,45 @@ var init_schema = __esmMin((() => {
|
|
|
116
116
|
/** Reserved for future external “dialectic” sync cadence (not wired yet). */
|
|
117
117
|
dialecticCadence: z.number().int().min(1).optional(),
|
|
118
118
|
/**
|
|
119
|
-
* Background memory consolidation ("dreaming"):
|
|
120
|
-
*
|
|
119
|
+
* Background memory consolidation ("dreaming"): three-phase sleep model that
|
|
120
|
+
* promotes short-term recall signals into long-term memory (`MEMORY.md`).
|
|
121
|
+
*
|
|
122
|
+
* Phases:
|
|
123
|
+
* - **light** — fast, frequent sweep (default every 6 h): dedup + signal collection.
|
|
124
|
+
* - **deep** — daily deep promotion (default 3 AM): score-gated write to MEMORY.md.
|
|
125
|
+
* - **rem** — weekly pattern discovery (default Sun 5 AM): cross-session insight mining.
|
|
121
126
|
*/
|
|
122
127
|
dreaming: z.object({
|
|
123
128
|
enabled: z.boolean().optional(),
|
|
129
|
+
/** Legacy top-level cron; prefer per-phase `cron` instead. */
|
|
124
130
|
frequency: z.string().optional(),
|
|
125
131
|
timezone: z.string().optional(),
|
|
126
|
-
phases: z.object({
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
phases: z.object({
|
|
133
|
+
light: z.object({
|
|
134
|
+
enabled: z.boolean().optional(),
|
|
135
|
+
cron: z.string().optional(),
|
|
136
|
+
lookbackDays: z.number().int().min(1).optional(),
|
|
137
|
+
limit: z.number().int().min(0).optional(),
|
|
138
|
+
dedupeSimilarity: z.number().min(0).max(1).optional()
|
|
139
|
+
}).optional(),
|
|
140
|
+
deep: z.object({
|
|
141
|
+
enabled: z.boolean().optional(),
|
|
142
|
+
cron: z.string().optional(),
|
|
143
|
+
minScore: z.number().min(0).max(1).optional(),
|
|
144
|
+
minRecallCount: z.number().int().min(1).optional(),
|
|
145
|
+
minUniqueQueries: z.number().int().min(1).optional(),
|
|
146
|
+
limit: z.number().int().min(0).optional(),
|
|
147
|
+
recencyHalfLifeDays: z.number().min(1).optional(),
|
|
148
|
+
maxAgeDays: z.number().int().min(1).optional()
|
|
149
|
+
}).optional(),
|
|
150
|
+
rem: z.object({
|
|
151
|
+
enabled: z.boolean().optional(),
|
|
152
|
+
cron: z.string().optional(),
|
|
153
|
+
lookbackDays: z.number().int().min(1).optional(),
|
|
154
|
+
limit: z.number().int().min(0).optional(),
|
|
155
|
+
minPatternStrength: z.number().min(0).max(1).optional()
|
|
156
|
+
}).optional()
|
|
157
|
+
}).optional()
|
|
132
158
|
}).optional()
|
|
133
159
|
}).optional(),
|
|
134
160
|
/** Cross-session transcript search (`session_search` tool). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../../../src/config/schema.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { getDefaultWorkspacePath } from '../agent/agent-scope.js';\n\n// ============================================\n// Agent Configs\n// ============================================\n\nexport const AgentModelRefSchema = z.union([\n z.string(),\n z\n .object({\n primary: z.string().optional(),\n fallbacks: z.array(z.string()).optional(),\n })\n .strict(),\n]);\n\nexport type AgentModelConfig = z.infer<typeof AgentModelRefSchema>;\n\nexport const AgentDefaultsSchema = z.object({\n /** Parent directory: each agent’s Markdown root is `<expanded>/<agentId>/` (e.g. `.../workspace/main`). */\n workspace: z.string().default('~/.xopc/workspace'),\n model: z.union([\n z.string(),\n z.object({\n primary: z.string().optional(),\n fallbacks: z.array(z.string()).optional(),\n }).strict(),\n ]).default(''), // Empty default - will be resolved dynamically at runtime\n /** Vision / image understanding model (provider/model). Falls back to heuristics when unset. */\n imageModel: AgentModelRefSchema.optional(),\n /** Image generation model (provider/model), e.g. openai/gpt-image-1. Thin REST wrapper; OpenAI supported. */\n imageGenerationModel: AgentModelRefSchema.optional(),\n /** Max image size for image tool loads (MB). */\n mediaMaxMb: z.number().positive().optional(),\n maxTokens: z.number().default(8192),\n temperature: z.number().default(0.7),\n maxToolIterations: z.number().default(20),\n // Wall-clock limit for one user turn (LLM + tools). Default 30m if unset; cap 4h.\n maxTaskDurationMs: z.number().min(60000).max(14_400_000).optional(),\n // Reliability settings\n maxRequestsPerTurn: z.number().min(10).max(200).default(50),\n maxToolFailuresPerTurn: z.number().min(1).max(20).default(3),\n // Thinking ability settings\n thinkingDefault: z.enum(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'adaptive']).optional(),\n reasoningDefault: z.enum(['off', 'on', 'stream']).optional(),\n verboseDefault: z.enum(['off', 'on', 'full']).optional(),\n compaction: z.object({\n enabled: z.boolean().default(true),\n mode: z.enum(['default', 'safeguard']).default('default'),\n reserveTokens: z.number().default(8000),\n triggerThreshold: z.number().min(0.5).max(0.95).default(0.8),\n minMessagesBeforeCompact: z.number().default(10),\n keepRecentMessages: z.number().default(5),\n // Dual-strategy compaction\n evictionWindow: z.number().min(0.1).max(0.5).default(0.2),\n retentionWindow: z.number().min(3).max(20).default(6),\n }).optional(),\n pruning: z.object({\n enabled: z.boolean().default(true),\n maxToolResultChars: z.number().default(10000),\n headKeepRatio: z.number().default(0.3),\n tailKeepRatio: z.number().default(0.3),\n }).optional(),\n /**\n * Curated memory (`agents/<id>/memories/`) + pluggable external provider.\n * Only one external provider at a time.\n */\n memory: z\n .object({\n /** Master switch: curated snapshot, `curated_memory`, prefetch, and external provider. Default true. */\n enabled: z.boolean().optional(),\n /** When false, use workspace bootstrap only (no curated snapshot / tool). Default true. */\n useEnhancedSystem: z.boolean().optional(),\n /** Include USER.md in snapshot. Default true. */\n userProfileEnabled: z.boolean().optional(),\n memoryCharLimit: z.number().positive().optional(),\n userCharLimit: z.number().positive().optional(),\n provider: z.enum(['none', 'stub']).optional(),\n /** How often prefetched external memory is injected into the user message. */\n injectionFrequency: z.enum(['every-turn', 'first-turn']).optional(),\n /** Inject prefetch on turns 1, 1+N, 1+2N, … (only when injectionFrequency is every-turn). Min 1. */\n contextCadence: z.number().int().min(1).optional(),\n /** Reserved for future external “dialectic” sync cadence (not wired yet). */\n dialecticCadence: z.number().int().min(1).optional(),\n /**\n * Background memory consolidation (\"dreaming\"): cron-triggered deep promotion of short-term recall signals\n * (workspace `memory/YYYY-MM-DD.md`) into `MEMORY.md`.\n */\n dreaming: z\n .object({\n enabled: z.boolean().optional(),\n frequency: z.string().optional(),\n timezone: z.string().optional(),\n phases: z\n .object({\n deep: z\n .object({\n enabled: z.boolean().optional(),\n minScore: z.number().min(0).max(1).optional(),\n minRecallCount: z.number().int().min(1).optional(),\n limit: z.number().int().min(0).optional(),\n })\n .optional(),\n })\n .optional(),\n })\n .optional(),\n })\n .optional(),\n /** Cross-session transcript search (`session_search` tool). */\n sessionSearch: z\n .object({\n /** Model ref for per-session summaries (e.g. openai/gpt-4o-mini). */\n summaryModel: z.string().optional(),\n })\n .optional(),\n /**\n * Post-turn background review (Hermes-style): optional quiet follow-up that may call\n * `curated_memory` / `skill_manage` so durable facts and reusable workflows persist\n * without bloating the main user-visible turn.\n */\n backgroundReview: z\n .object({\n /** When true, nudges may run after successful turns. Default false (opt-in). */\n enabled: z.boolean().optional(),\n /** User-turn cadence for memory review. 0 disables the memory channel. Default 10. */\n memoryNudgeInterval: z.number().int().min(0).optional(),\n /** LLM rounds without `skill_manage` before a skill review. 0 disables the skill channel. Default 10. */\n skillNudgeInterval: z.number().int().min(0).optional(),\n /** Max tool executions for the review agent. Default 8. */\n maxToolRounds: z.number().int().min(1).max(32).optional(),\n /** Max prior messages passed into the review context (tail). Default 80. */\n maxHistoryMessages: z.number().int().min(10).max(200).optional(),\n /** Wall-clock cap for the review run (ms). Default 120000. */\n maxDurationMs: z.number().int().min(30_000).max(600_000).optional(),\n })\n .optional(),\n /** LLM pass for `web_extract` (markdown-focused extraction). */\n webExtract: z\n .object({\n model: z.string().optional(),\n maxLength: z.number().positive().optional(),\n })\n .optional(),\n /**\n * Headless Playwright tools (`browser_*`). Opt-in. Install browsers once: `npx playwright install chromium`.\n */\n browser: z\n .object({\n enabled: z.boolean().optional(),\n /** Default true when browser tools are enabled. */\n headless: z.boolean().optional(),\n })\n .optional(),\n /** Sub-agent delegation (`delegate_task`). Opt-in. */\n delegate: z\n .object({\n enabled: z.boolean().optional(),\n })\n .optional(),\n /** Sandboxed `execute_code` (programmatic tool calls). Opt-in. */\n executeCode: z\n .object({\n enabled: z.boolean().optional(),\n })\n .optional(),\n /** Optional full system prompt replacement (merged with per-agent entry; entry wins). */\n systemPromptOverride: z.string().optional(),\n /** Optional allowlist of skill names for `<available_skills>`; when set, replaces unfiltered list. */\n skills: z.array(z.string()).optional(),\n /** Disable built-in tools by name (e.g. `shell`, `web_search`). */\n tools: z\n .object({\n disable: z.array(z.string()).optional(),\n })\n .optional(),\n /** Opaque per-process params (reserved for extensions / future use). */\n params: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport const AgentConfigSchema = z.object({\n id: z.string(),\n /** When true, this entry is the default routing agent. */\n default: z.boolean().optional(),\n name: z.string().optional(),\n /** Short human-readable summary for UIs (gateway console, pickers). */\n description: z.string().max(4000).optional(),\n enabled: z.boolean().default(true),\n /** Per-agent workspace root (`~` expanded at runtime). */\n workspace: z.string().optional(),\n /**\n * Internal agent state directory (`…/credentials`, `agent.json`, pid, inbox).\n * Default: `<stateDir>/agents/<id>/agent`.\n */\n agentDir: z.string().optional(),\n model: AgentModelRefSchema.optional(),\n thinkingDefault: z.enum(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'adaptive']).optional(),\n reasoningDefault: z.enum(['off', 'on', 'stream']).optional(),\n verboseDefault: z.enum(['off', 'on', 'full']).optional(),\n systemPromptOverride: z.string().optional(),\n skills: z.array(z.string()).optional(),\n tools: z\n .object({\n disable: z.array(z.string()).optional(),\n })\n .optional(),\n params: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport const AgentsConfigSchema = z.object({\n /** Default agent id when not specified (routing / session creation). */\n default: z.string().optional(),\n defaults: AgentDefaultsSchema.optional(),\n list: z.array(AgentConfigSchema).optional(),\n}).default({\n defaults: {\n workspace: '~/.xopc/workspace',\n model: '', // Empty default - will be resolved dynamically at runtime\n maxTokens: 8192,\n temperature: 0.7,\n maxToolIterations: 20,\n maxRequestsPerTurn: 50,\n maxToolFailuresPerTurn: 3,\n compaction: {\n enabled: true,\n mode: 'default',\n reserveTokens: 8000,\n triggerThreshold: 0.8,\n minMessagesBeforeCompact: 10,\n keepRecentMessages: 5,\n evictionWindow: 0.2,\n retentionWindow: 6,\n },\n pruning: {\n enabled: true,\n maxToolResultChars: 10000,\n headKeepRatio: 0.3,\n tailKeepRatio: 0.3,\n },\n },\n} as any);\n\n// ============================================\n// Channel Configs (per-channel Zod lives in bundled extensions; root schema is open)\n// ============================================\n\nexport {\n TelegramTopicConfigSchema,\n TelegramGroupConfigSchema,\n TelegramAccountConfigSchema,\n TelegramConfigSchema,\n} from '../../extensions/telegram/src/config-schema.js';\nexport type { TelegramConfig } from '../../extensions/telegram/src/config-schema.js';\nexport { WeixinAccountConfigSchema, WeixinConfigSchema } from '../../extensions/weixin/src/config-schema.js';\nexport type { WeixinConfig } from '../../extensions/weixin/src/config-schema.js';\n\n// ============================================\n// Session Routing Configuration\n// ============================================\n\nexport const BindingMatchSchema = z.object({\n channel: z.string(),\n accountId: z.string().optional(),\n peerKind: z.string().optional(),\n peerId: z.string().optional(),\n guildId: z.string().optional(),\n teamId: z.string().optional(),\n memberRoleIds: z.array(z.string()).optional(),\n});\n\nexport const BindingRuleSchema = z.object({\n id: z.string().optional(),\n agentId: z.string(),\n priority: z.number().default(100),\n match: BindingMatchSchema,\n enabled: z.boolean().default(true),\n});\n\nexport const BindingsConfigSchema = z.array(BindingRuleSchema).default([]);\n\nexport const SessionDmScopeSchema = z.enum([\n 'main',\n 'per-peer',\n 'per-channel-peer',\n 'per-account-channel-peer',\n]);\n\nexport const SessionStorageConfigSchema = z.object({\n pruneAfterMs: z.number().optional(),\n maxEntries: z.number().optional(),\n});\n\nexport const SessionConfigSchema = z.object({\n dmScope: SessionDmScopeSchema.default('main'),\n identityLinks: z.record(z.string(), z.array(z.string())).optional(),\n storage: SessionStorageConfigSchema.optional(),\n}).default({\n dmScope: 'main',\n});\n\n/** Channel buckets — shapes validated post-parse by registered channel plugins. */\nexport const ChannelsConfigSchema = z.record(z.string(), z.unknown()).default({\n telegram: {\n enabled: false,\n botToken: '',\n allowFrom: [],\n groupAllowFrom: [],\n debug: false,\n dmPolicy: 'pairing' as const,\n groupPolicy: 'open' as const,\n replyToMode: 'off' as const,\n historyLimit: 50,\n textChunkLimit: 4000,\n },\n});\n\nexport const SearchProviderEntrySchema = z.object({\n type: z.enum(['brave', 'tavily', 'bing', 'searxng']),\n apiKey: z.string().optional(),\n /** SearXNG instance base URL (e.g. http://localhost:8080) */\n url: z.string().optional(),\n disabled: z.boolean().optional(),\n});\n\nexport type SearchProviderEntry = z.infer<typeof SearchProviderEntrySchema>;\n\nexport const WebSearchConfigSchema = z.object({\n maxResults: z.number().default(5),\n /** Ordered API providers; empty → HTML fallback only */\n providers: z.array(SearchProviderEntrySchema).default([]),\n});\n\nexport type WebSearchConfig = z.infer<typeof WebSearchConfigSchema>;\n\nexport const WebToolsConfigSchema = z.object({\n /** Search result HTML fallback: cn → Bing, otherwise DuckDuckGo */\n region: z.enum(['cn', 'global']).optional(),\n search: WebSearchConfigSchema.optional(),\n});\n\nexport type WebToolsConfig = z.infer<typeof WebToolsConfigSchema>;\n\nexport const ToolsConfigSchema = z.object({\n web: WebToolsConfigSchema.optional(),\n}).default({\n web: {\n search: {\n maxResults: 5,\n providers: [],\n },\n },\n});\n\n// ============================================\n// Gateway Configuration\n// ============================================\n\nexport const GatewayAuthRateLimitSchema = z\n .object({\n enabled: z.boolean().default(true),\n maxAttempts: z.number().int().min(1).default(5),\n windowMs: z.number().default(900_000),\n blockDurationMs: z.number().default(300_000),\n })\n .optional();\n\nexport const GatewayAuthSchema = z\n .object({\n mode: z.enum(['none', 'token']).default('token'),\n token: z.string().optional(),\n rateLimit: GatewayAuthRateLimitSchema,\n })\n .default({\n mode: 'token',\n });\n\nexport const HeartbeatConfigSchema = z\n .object({\n enabled: z.boolean(),\n intervalMs: z.number(),\n /** When false, heartbeat instructions are only sent during heartbeat polling turns (not in every chat system prompt). */\n includeSystemPromptSection: z.boolean().optional().default(false),\n target: z.string().optional(),\n targetChatId: z.string().optional(),\n prompt: z.string().optional(),\n ackMaxChars: z.number().optional(),\n isolatedSession: z.boolean().optional(),\n activeHours: z\n .object({\n start: z.string(),\n end: z.string(),\n timezone: z.string().optional(),\n })\n .optional(),\n })\n .default({\n enabled: true,\n intervalMs: 1_800_000,\n includeSystemPromptSection: false,\n });\n\nexport const GatewayConfigSchema = z.object({\n host: z.string().optional(),\n port: z.number().optional(),\n auth: GatewayAuthSchema.optional(),\n heartbeat: HeartbeatConfigSchema.optional(),\n maxSseConnections: z.number().optional(),\n corsOrigins: z.array(z.string()).optional(),\n /** Base URL for the xopc skills marketplace (public REST API). */\n skillsStoreBaseUrl: z.string().url().optional(),\n}).default({\n host: '127.0.0.1',\n port: 18790,\n auth: {\n mode: 'token',\n },\n heartbeat: {\n enabled: true,\n intervalMs: 1_800_000,\n includeSystemPromptSection: false,\n },\n maxSseConnections: 100,\n corsOrigins: [],\n skillsStoreBaseUrl: 'https://store.xopc.ai',\n});\n\nexport const CronConfigSchema = z.object({\n enabled: z.boolean().optional(),\n maxConcurrentJobs: z.number().optional(),\n defaultTimezone: z.string().optional(),\n historyRetentionDays: z.number().optional(),\n enableMetrics: z.boolean().optional(),\n}).default({\n enabled: true,\n maxConcurrentJobs: 5,\n defaultTimezone: 'UTC',\n historyRetentionDays: 7,\n enableMetrics: true,\n});\n\nexport const ModelsDevConfigSchema = z.object({\n enabled: z.boolean().default(true),\n}).default({\n enabled: true,\n});\n\n// ============================================\n// STT (Speech-to-Text) Config\n// ============================================\n\nexport const STTProviderConfigSchema = z.object({\n apiKey: z.string().optional(),\n model: z.string().optional(),\n});\n\nexport const STTFallbackConfigSchema = z.object({\n enabled: z.boolean().default(true),\n order: z.array(z.enum(['alibaba', 'openai'])).default(['alibaba', 'openai']),\n});\n\nexport const STTConfigSchema = z.object({\n enabled: z.boolean().default(false),\n provider: z.enum(['alibaba', 'openai']).default('alibaba'),\n alibaba: STTProviderConfigSchema.optional(),\n openai: STTProviderConfigSchema.optional(),\n fallback: STTFallbackConfigSchema.optional(),\n});\n\n// ============================================\n// TTS (Text-to-Speech) Config\n// ============================================\n\nexport const TTSProviderConfigSchema = z.object({\n apiKey: z.string().optional(),\n model: z.string().optional(),\n voice: z.string().optional(),\n});\n\nexport const TTSFallbackConfigSchema = z.object({\n enabled: z.boolean().default(true),\n order: z\n .array(z.enum(['openai', 'alibaba', 'edge', 'minimax']))\n .default(['openai', 'alibaba', 'minimax', 'edge']),\n});\n\nexport const TTSModelOverridesConfigSchema = z.object({\n enabled: z.boolean().default(true),\n allowText: z.boolean().default(true),\n allowProvider: z.boolean().default(false),\n allowVoice: z.boolean().default(true),\n allowModelId: z.boolean().default(true),\n allowVoiceSettings: z.boolean().default(false),\n allowNormalization: z.boolean().default(false),\n allowSeed: z.boolean().default(false),\n});\n\nexport const TTSEdgeConfigSchema = z.object({\n enabled: z.boolean().default(true),\n voice: z.string().optional(),\n lang: z.string().optional(),\n outputFormat: z.string().optional(),\n pitch: z.string().optional(),\n rate: z.string().optional(),\n volume: z.string().optional(),\n proxy: z.string().optional(),\n timeoutMs: z.number().int().min(1000).max(120000).optional(),\n});\n\nexport const TTSSummarizationConfigSchema = z.object({\n enabled: z.boolean().optional(),\n targetLength: z.number().int().min(1).optional(),\n threshold: z.number().int().min(1).optional(),\n model: z.string().optional(),\n});\n\nexport const TTSConfigSchema = z.object({\n enabled: z.boolean().default(false),\n provider: z.enum(['openai', 'alibaba', 'edge', 'minimax']).default('openai'),\n trigger: z\n .preprocess(\n (v) => (v === 'auto' ? 'inbound' : v),\n z.enum(['off', 'always', 'inbound', 'tagged']).default('always'),\n ),\n fallback: TTSFallbackConfigSchema.optional(),\n maxTextLength: z.number().int().min(1).default(512), // Conservative default to accommodate all providers (Alibaba limit is 512)\n timeoutMs: z.number().int().min(1000).max(180000).default(60000),\n summarization: TTSSummarizationConfigSchema.optional(),\n modelOverrides: TTSModelOverridesConfigSchema.optional(),\n alibaba: TTSProviderConfigSchema.optional(),\n openai: TTSProviderConfigSchema.optional(),\n edge: TTSEdgeConfigSchema.optional(),\n minimax: TTSProviderConfigSchema.optional(),\n});\n\n// ============================================\n// Extension Configs \n// ============================================\n\n// Security config for extensions \nexport const ExtensionSecurityConfigSchema = z.object({\n checkPermissions: z.boolean().default(true),\n allowUntrusted: z.boolean().default(false),\n allow: z.array(z.string()).default([]),\n trackProvenance: z.boolean().default(true),\n allowPromptInjection: z.boolean().default(false),\n});\n\n// Slot config for extensions \nexport const ExtensionSlotsConfigSchema = z.object({\n memory: z.string().optional(),\n tts: z.string().optional(),\n imageGeneration: z.string().optional(),\n webSearch: z.string().optional(),\n});\n\n// Complete extensions config\n// Extension config allows both known fields AND arbitrary extension-specific config\n// Known fields: enabled (array), allow (array), security (object), slots (object)\n// Arbitrary: any other key is extension-specific config (e.g., extensions.hello.greeting)\nexport const ExtensionsConfigSchema: z.ZodType<Record<string, unknown>> = z.record(z.string(), z.unknown());\n\n// ============================================\n// Update Config\n// ============================================\n\nexport const UpdateAutoConfigSchema = z\n .object({\n /** Enable automatic update installation. Default false. */\n enabled: z.boolean().default(false),\n /** Hours to wait before applying a stable update after first detection. */\n stableDelayHours: z.number().min(0).default(6),\n /** Additional random jitter hours for stable rollout (avoids thundering herd). */\n stableJitterHours: z.number().min(0).default(12),\n /** How often to re-check for beta updates (hours). Min 0.25. */\n betaCheckIntervalHours: z.number().min(0.25).default(1),\n })\n .strict()\n .optional();\n\nexport const UpdateConfigSchema = z\n .object({\n /** Check for updates on gateway startup. Default true. */\n checkOnStart: z.boolean().default(true),\n /** Update channel: stable (default), beta, or dev. */\n channel: z.enum(['stable', 'beta', 'dev']).default('stable'),\n /** Automatic update policy. */\n auto: UpdateAutoConfigSchema,\n })\n .strict()\n .optional();\n\nexport type UpdateConfig = z.infer<typeof UpdateConfigSchema>;\n\n// ============================================\n// Root Config\n// ============================================\n\nexport const ConfigSchema = z.object({\n agents: AgentsConfigSchema,\n bindings: BindingsConfigSchema,\n session: SessionConfigSchema,\n channels: ChannelsConfigSchema,\n gateway: GatewayConfigSchema,\n tools: ToolsConfigSchema,\n cron: CronConfigSchema,\n extensions: ExtensionsConfigSchema.default({}),\n modelsDev: ModelsDevConfigSchema,\n stt: STTConfigSchema.optional(),\n tts: TTSConfigSchema.optional(),\n update: UpdateConfigSchema,\n}).default({\n agents: {\n defaults: {\n workspace: '~/.xopc/workspace',\n model: '', // Empty default - will be resolved dynamically at runtime\n maxTokens: 8192,\n temperature: 0.7,\n maxToolIterations: 20,\n maxRequestsPerTurn: 50,\n maxToolFailuresPerTurn: 3,\n thinkingDefault: 'medium',\n reasoningDefault: 'off',\n verboseDefault: 'off',\n compaction: {\n enabled: true,\n mode: 'default',\n reserveTokens: 8000,\n triggerThreshold: 0.8,\n minMessagesBeforeCompact: 10,\n keepRecentMessages: 5,\n evictionWindow: 0.2,\n retentionWindow: 6,\n },\n pruning: {\n enabled: true,\n maxToolResultChars: 10000,\n headKeepRatio: 0.3,\n tailKeepRatio: 0.3,\n },\n },\n },\n bindings: [],\n session: {\n dmScope: 'main' as const,\n },\n channels: {\n telegram: {\n enabled: false,\n botToken: '',\n allowFrom: [],\n groupAllowFrom: [],\n debug: false,\n dmPolicy: 'pairing' as const,\n groupPolicy: 'open' as const,\n replyToMode: 'off' as const,\n historyLimit: 50,\n textChunkLimit: 4000,\n },\n },\n gateway: {\n host: '127.0.0.1',\n port: 18790,\n auth: {\n mode: 'token',\n },\n heartbeat: {\n enabled: true,\n intervalMs: 1_800_000,\n includeSystemPromptSection: false,\n },\n maxSseConnections: 100,\n corsOrigins: [],\n skillsStoreBaseUrl: 'https://store.xopc.ai',\n },\n tools: {\n web: {\n search: {\n maxResults: 5,\n providers: [],\n },\n },\n },\n cron: {\n enabled: true,\n maxConcurrentJobs: 5,\n defaultTimezone: 'UTC',\n historyRetentionDays: 7,\n enableMetrics: true,\n },\n extensions: {\n allow: [],\n security: {\n checkPermissions: true,\n allowUntrusted: false,\n allow: [],\n trackProvenance: true,\n allowPromptInjection: false,\n },\n slots: {},\n },\n modelsDev: {\n enabled: true,\n },\n stt: {\n enabled: false,\n provider: 'alibaba',\n alibaba: {\n model: 'paraformer-v2',\n },\n openai: {\n model: 'whisper-1',\n },\n fallback: {\n enabled: true,\n order: ['alibaba', 'openai'],\n },\n },\n tts: {\n enabled: false,\n provider: 'openai',\n trigger: 'always',\n fallback: {\n enabled: true,\n order: ['openai', 'alibaba', 'minimax', 'edge'],\n },\n maxTextLength: 4096,\n timeoutMs: 30000,\n modelOverrides: {\n enabled: true,\n allowText: true,\n allowProvider: false,\n allowVoice: true,\n allowModelId: true,\n allowVoiceSettings: false,\n allowNormalization: false,\n allowSeed: false,\n },\n alibaba: {\n model: 'qwen-tts',\n voice: 'Cherry',\n },\n openai: {\n model: 'tts-1',\n voice: 'alloy',\n },\n edge: {\n enabled: true,\n voice: 'en-US-MichelleNeural',\n lang: 'en-US',\n outputFormat: 'audio-24khz-48kbitrate-mono-mp3',\n },\n minimax: {\n model: 'speech-2.8-hd',\n voice: 'male-qn-qingse',\n },\n },\n});\n\nexport type Config = z.infer<typeof ConfigSchema>;\nexport type AgentDefaults = z.infer<typeof AgentDefaultsSchema>;\nexport type GatewayAuthConfig = z.infer<typeof GatewayAuthSchema>;\nexport type GatewayAuthRateLimitConfig = z.infer<typeof GatewayAuthRateLimitSchema>;\nexport type STTConfig = z.infer<typeof STTConfigSchema>;\nexport type TTSConfig = z.infer<typeof TTSConfigSchema>;\n\n// ============================================\n// Helper Functions\n// ============================================\n\n/**\n * Parse a model reference string.\n */\nexport interface ParsedModelRef {\n provider: string;\n model: string;\n}\n\n/**\n * Default agent’s resolved Markdown workspace root (`resolveAgentWorkspaceDir` for the default agent id).\n */\nexport function getWorkspacePath(config: Config): string {\n return getDefaultWorkspacePath(config);\n}\n\n/**\n * Primary model ref from `agents.defaults.model` (string or `{ primary }`).\n * Returns undefined when unset or empty.\n */\nexport function getAgentDefaultModelRef(config: Config): string | undefined {\n const raw = config.agents?.defaults?.model;\n if (raw === undefined || raw === null) return undefined;\n const ref = typeof raw === 'string' ? raw : raw.primary;\n if (ref === undefined || ref === null) return undefined;\n const s = String(ref).trim();\n return s ? s : undefined;\n}\n\n/** `provider/model` or null when invalid. */\nexport function parseModelRef(ref: string): ParsedModelRef | null {\n const trimmed = ref.trim();\n const idx = trimmed.indexOf('/');\n if (idx <= 0 || idx === trimmed.length - 1) {\n return null;\n }\n return { provider: trimmed.slice(0, idx).trim(), model: trimmed.slice(idx + 1).trim() };\n}\n"],"mappings":";;;;;;;;;AA8wBA,SAAgB,iBAAiB,QAAwB;AACvD,QAAO,wBAAwB,OAAO;;;;;;AAOxC,SAAgB,wBAAwB,QAAoC;CAC1E,MAAM,MAAM,OAAO,QAAQ,UAAU;AACrC,KAAI,QAAQ,KAAA,KAAa,QAAQ,KAAM,QAAO,KAAA;CAC9C,MAAM,MAAM,OAAO,QAAQ,WAAW,MAAM,IAAI;AAChD,KAAI,QAAQ,KAAA,KAAa,QAAQ,KAAM,QAAO,KAAA;CAC9C,MAAM,IAAI,OAAO,IAAI,CAAC,MAAM;AAC5B,QAAO,I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D,QAAQ,EACN,OAAO,aACR;GACD,UAAU;IACR,SAAS;IACT,OAAO,CAAC,WAAW,SAAS;IAC7B;GACF;EACD,KAAK;GACH,SAAS;GACT,UAAU;GACV,SAAS;GACT,UAAU;IACR,SAAS;IACT,OAAO;KAAC;KAAU;KAAW;KAAW;KAAO;IAChD;GACD,eAAe;GACf,WAAW;GACX,gBAAgB;IACd,SAAS;IACT,WAAW;IACX,eAAe;IACf,YAAY;IACZ,cAAc;IACd,oBAAoB;IACpB,oBAAoB;IACpB,WAAW;IACZ;GACD,SAAS;IACP,OAAO;IACP,OAAO;IACR;GACD,QAAQ;IACN,OAAO;IACP,OAAO;IACR;GACD,MAAM;IACJ,SAAS;IACT,OAAO;IACP,MAAM;IACN,cAAc;IACf;GACD,SAAS;IACP,OAAO;IACP,OAAO;IACR;GACF;EACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../../src/config/schema.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { getDefaultWorkspacePath } from '../agent/agent-scope.js';\n\n// ============================================\n// Agent Configs\n// ============================================\n\nexport const AgentModelRefSchema = z.union([\n z.string(),\n z\n .object({\n primary: z.string().optional(),\n fallbacks: z.array(z.string()).optional(),\n })\n .strict(),\n]);\n\nexport type AgentModelConfig = z.infer<typeof AgentModelRefSchema>;\n\nexport const AgentDefaultsSchema = z.object({\n /** Parent directory: each agent’s Markdown root is `<expanded>/<agentId>/` (e.g. `.../workspace/main`). */\n workspace: z.string().default('~/.xopc/workspace'),\n model: z.union([\n z.string(),\n z.object({\n primary: z.string().optional(),\n fallbacks: z.array(z.string()).optional(),\n }).strict(),\n ]).default(''), // Empty default - will be resolved dynamically at runtime\n /** Vision / image understanding model (provider/model). Falls back to heuristics when unset. */\n imageModel: AgentModelRefSchema.optional(),\n /** Image generation model (provider/model), e.g. openai/gpt-image-1. Thin REST wrapper; OpenAI supported. */\n imageGenerationModel: AgentModelRefSchema.optional(),\n /** Max image size for image tool loads (MB). */\n mediaMaxMb: z.number().positive().optional(),\n maxTokens: z.number().default(8192),\n temperature: z.number().default(0.7),\n maxToolIterations: z.number().default(20),\n // Wall-clock limit for one user turn (LLM + tools). Default 30m if unset; cap 4h.\n maxTaskDurationMs: z.number().min(60000).max(14_400_000).optional(),\n // Reliability settings\n maxRequestsPerTurn: z.number().min(10).max(200).default(50),\n maxToolFailuresPerTurn: z.number().min(1).max(20).default(3),\n // Thinking ability settings\n thinkingDefault: z.enum(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'adaptive']).optional(),\n reasoningDefault: z.enum(['off', 'on', 'stream']).optional(),\n verboseDefault: z.enum(['off', 'on', 'full']).optional(),\n compaction: z.object({\n enabled: z.boolean().default(true),\n mode: z.enum(['default', 'safeguard']).default('default'),\n reserveTokens: z.number().default(8000),\n triggerThreshold: z.number().min(0.5).max(0.95).default(0.8),\n minMessagesBeforeCompact: z.number().default(10),\n keepRecentMessages: z.number().default(5),\n // Dual-strategy compaction\n evictionWindow: z.number().min(0.1).max(0.5).default(0.2),\n retentionWindow: z.number().min(3).max(20).default(6),\n }).optional(),\n pruning: z.object({\n enabled: z.boolean().default(true),\n maxToolResultChars: z.number().default(10000),\n headKeepRatio: z.number().default(0.3),\n tailKeepRatio: z.number().default(0.3),\n }).optional(),\n /**\n * Curated memory (`agents/<id>/memories/`) + pluggable external provider.\n * Only one external provider at a time.\n */\n memory: z\n .object({\n /** Master switch: curated snapshot, `curated_memory`, prefetch, and external provider. Default true. */\n enabled: z.boolean().optional(),\n /** When false, use workspace bootstrap only (no curated snapshot / tool). Default true. */\n useEnhancedSystem: z.boolean().optional(),\n /** Include USER.md in snapshot. Default true. */\n userProfileEnabled: z.boolean().optional(),\n memoryCharLimit: z.number().positive().optional(),\n userCharLimit: z.number().positive().optional(),\n provider: z.enum(['none', 'stub']).optional(),\n /** How often prefetched external memory is injected into the user message. */\n injectionFrequency: z.enum(['every-turn', 'first-turn']).optional(),\n /** Inject prefetch on turns 1, 1+N, 1+2N, … (only when injectionFrequency is every-turn). Min 1. */\n contextCadence: z.number().int().min(1).optional(),\n /** Reserved for future external “dialectic” sync cadence (not wired yet). */\n dialecticCadence: z.number().int().min(1).optional(),\n /**\n * Background memory consolidation (\"dreaming\"): three-phase sleep model that\n * promotes short-term recall signals into long-term memory (`MEMORY.md`).\n *\n * Phases:\n * - **light** — fast, frequent sweep (default every 6 h): dedup + signal collection.\n * - **deep** — daily deep promotion (default 3 AM): score-gated write to MEMORY.md.\n * - **rem** — weekly pattern discovery (default Sun 5 AM): cross-session insight mining.\n */\n dreaming: z\n .object({\n enabled: z.boolean().optional(),\n /** Legacy top-level cron; prefer per-phase `cron` instead. */\n frequency: z.string().optional(),\n timezone: z.string().optional(),\n phases: z\n .object({\n light: z\n .object({\n enabled: z.boolean().optional(),\n cron: z.string().optional(),\n lookbackDays: z.number().int().min(1).optional(),\n limit: z.number().int().min(0).optional(),\n dedupeSimilarity: z.number().min(0).max(1).optional(),\n })\n .optional(),\n deep: z\n .object({\n enabled: z.boolean().optional(),\n cron: z.string().optional(),\n minScore: z.number().min(0).max(1).optional(),\n minRecallCount: z.number().int().min(1).optional(),\n minUniqueQueries: z.number().int().min(1).optional(),\n limit: z.number().int().min(0).optional(),\n recencyHalfLifeDays: z.number().min(1).optional(),\n maxAgeDays: z.number().int().min(1).optional(),\n })\n .optional(),\n rem: z\n .object({\n enabled: z.boolean().optional(),\n cron: z.string().optional(),\n lookbackDays: z.number().int().min(1).optional(),\n limit: z.number().int().min(0).optional(),\n minPatternStrength: z.number().min(0).max(1).optional(),\n })\n .optional(),\n })\n .optional(),\n })\n .optional(),\n })\n .optional(),\n /** Cross-session transcript search (`session_search` tool). */\n sessionSearch: z\n .object({\n /** Model ref for per-session summaries (e.g. openai/gpt-4o-mini). */\n summaryModel: z.string().optional(),\n })\n .optional(),\n /**\n * Post-turn background review (Hermes-style): optional quiet follow-up that may call\n * `curated_memory` / `skill_manage` so durable facts and reusable workflows persist\n * without bloating the main user-visible turn.\n */\n backgroundReview: z\n .object({\n /** When true, nudges may run after successful turns. Default false (opt-in). */\n enabled: z.boolean().optional(),\n /** User-turn cadence for memory review. 0 disables the memory channel. Default 10. */\n memoryNudgeInterval: z.number().int().min(0).optional(),\n /** LLM rounds without `skill_manage` before a skill review. 0 disables the skill channel. Default 10. */\n skillNudgeInterval: z.number().int().min(0).optional(),\n /** Max tool executions for the review agent. Default 8. */\n maxToolRounds: z.number().int().min(1).max(32).optional(),\n /** Max prior messages passed into the review context (tail). Default 80. */\n maxHistoryMessages: z.number().int().min(10).max(200).optional(),\n /** Wall-clock cap for the review run (ms). Default 120000. */\n maxDurationMs: z.number().int().min(30_000).max(600_000).optional(),\n })\n .optional(),\n /** LLM pass for `web_extract` (markdown-focused extraction). */\n webExtract: z\n .object({\n model: z.string().optional(),\n maxLength: z.number().positive().optional(),\n })\n .optional(),\n /**\n * Headless Playwright tools (`browser_*`). Opt-in. Install browsers once: `npx playwright install chromium`.\n */\n browser: z\n .object({\n enabled: z.boolean().optional(),\n /** Default true when browser tools are enabled. */\n headless: z.boolean().optional(),\n })\n .optional(),\n /** Sub-agent delegation (`delegate_task`). Opt-in. */\n delegate: z\n .object({\n enabled: z.boolean().optional(),\n })\n .optional(),\n /** Sandboxed `execute_code` (programmatic tool calls). Opt-in. */\n executeCode: z\n .object({\n enabled: z.boolean().optional(),\n })\n .optional(),\n /** Optional full system prompt replacement (merged with per-agent entry; entry wins). */\n systemPromptOverride: z.string().optional(),\n /** Optional allowlist of skill names for `<available_skills>`; when set, replaces unfiltered list. */\n skills: z.array(z.string()).optional(),\n /** Disable built-in tools by name (e.g. `shell`, `web_search`). */\n tools: z\n .object({\n disable: z.array(z.string()).optional(),\n })\n .optional(),\n /** Opaque per-process params (reserved for extensions / future use). */\n params: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport const AgentConfigSchema = z.object({\n id: z.string(),\n /** When true, this entry is the default routing agent. */\n default: z.boolean().optional(),\n name: z.string().optional(),\n /** Short human-readable summary for UIs (gateway console, pickers). */\n description: z.string().max(4000).optional(),\n enabled: z.boolean().default(true),\n /** Per-agent workspace root (`~` expanded at runtime). */\n workspace: z.string().optional(),\n /**\n * Internal agent state directory (`…/credentials`, `agent.json`, pid, inbox).\n * Default: `<stateDir>/agents/<id>/agent`.\n */\n agentDir: z.string().optional(),\n model: AgentModelRefSchema.optional(),\n thinkingDefault: z.enum(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'adaptive']).optional(),\n reasoningDefault: z.enum(['off', 'on', 'stream']).optional(),\n verboseDefault: z.enum(['off', 'on', 'full']).optional(),\n systemPromptOverride: z.string().optional(),\n skills: z.array(z.string()).optional(),\n tools: z\n .object({\n disable: z.array(z.string()).optional(),\n })\n .optional(),\n params: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport const AgentsConfigSchema = z.object({\n /** Default agent id when not specified (routing / session creation). */\n default: z.string().optional(),\n defaults: AgentDefaultsSchema.optional(),\n list: z.array(AgentConfigSchema).optional(),\n}).default({\n defaults: {\n workspace: '~/.xopc/workspace',\n model: '', // Empty default - will be resolved dynamically at runtime\n maxTokens: 8192,\n temperature: 0.7,\n maxToolIterations: 20,\n maxRequestsPerTurn: 50,\n maxToolFailuresPerTurn: 3,\n compaction: {\n enabled: true,\n mode: 'default',\n reserveTokens: 8000,\n triggerThreshold: 0.8,\n minMessagesBeforeCompact: 10,\n keepRecentMessages: 5,\n evictionWindow: 0.2,\n retentionWindow: 6,\n },\n pruning: {\n enabled: true,\n maxToolResultChars: 10000,\n headKeepRatio: 0.3,\n tailKeepRatio: 0.3,\n },\n },\n} as any);\n\n// ============================================\n// Channel Configs (per-channel Zod lives in bundled extensions; root schema is open)\n// ============================================\n\nexport {\n TelegramTopicConfigSchema,\n TelegramGroupConfigSchema,\n TelegramAccountConfigSchema,\n TelegramConfigSchema,\n} from '../../extensions/telegram/src/config-schema.js';\nexport type { TelegramConfig } from '../../extensions/telegram/src/config-schema.js';\nexport { WeixinAccountConfigSchema, WeixinConfigSchema } from '../../extensions/weixin/src/config-schema.js';\nexport type { WeixinConfig } from '../../extensions/weixin/src/config-schema.js';\n\n// ============================================\n// Session Routing Configuration\n// ============================================\n\nexport const BindingMatchSchema = z.object({\n channel: z.string(),\n accountId: z.string().optional(),\n peerKind: z.string().optional(),\n peerId: z.string().optional(),\n guildId: z.string().optional(),\n teamId: z.string().optional(),\n memberRoleIds: z.array(z.string()).optional(),\n});\n\nexport const BindingRuleSchema = z.object({\n id: z.string().optional(),\n agentId: z.string(),\n priority: z.number().default(100),\n match: BindingMatchSchema,\n enabled: z.boolean().default(true),\n});\n\nexport const BindingsConfigSchema = z.array(BindingRuleSchema).default([]);\n\nexport const SessionDmScopeSchema = z.enum([\n 'main',\n 'per-peer',\n 'per-channel-peer',\n 'per-account-channel-peer',\n]);\n\nexport const SessionStorageConfigSchema = z.object({\n pruneAfterMs: z.number().optional(),\n maxEntries: z.number().optional(),\n});\n\nexport const SessionConfigSchema = z.object({\n dmScope: SessionDmScopeSchema.default('main'),\n identityLinks: z.record(z.string(), z.array(z.string())).optional(),\n storage: SessionStorageConfigSchema.optional(),\n}).default({\n dmScope: 'main',\n});\n\n/** Channel buckets — shapes validated post-parse by registered channel plugins. */\nexport const ChannelsConfigSchema = z.record(z.string(), z.unknown()).default({\n telegram: {\n enabled: false,\n botToken: '',\n allowFrom: [],\n groupAllowFrom: [],\n debug: false,\n dmPolicy: 'pairing' as const,\n groupPolicy: 'open' as const,\n replyToMode: 'off' as const,\n historyLimit: 50,\n textChunkLimit: 4000,\n },\n});\n\nexport const SearchProviderEntrySchema = z.object({\n type: z.enum(['brave', 'tavily', 'bing', 'searxng']),\n apiKey: z.string().optional(),\n /** SearXNG instance base URL (e.g. http://localhost:8080) */\n url: z.string().optional(),\n disabled: z.boolean().optional(),\n});\n\nexport type SearchProviderEntry = z.infer<typeof SearchProviderEntrySchema>;\n\nexport const WebSearchConfigSchema = z.object({\n maxResults: z.number().default(5),\n /** Ordered API providers; empty → HTML fallback only */\n providers: z.array(SearchProviderEntrySchema).default([]),\n});\n\nexport type WebSearchConfig = z.infer<typeof WebSearchConfigSchema>;\n\nexport const WebToolsConfigSchema = z.object({\n /** Search result HTML fallback: cn → Bing, otherwise DuckDuckGo */\n region: z.enum(['cn', 'global']).optional(),\n search: WebSearchConfigSchema.optional(),\n});\n\nexport type WebToolsConfig = z.infer<typeof WebToolsConfigSchema>;\n\nexport const ToolsConfigSchema = z.object({\n web: WebToolsConfigSchema.optional(),\n}).default({\n web: {\n search: {\n maxResults: 5,\n providers: [],\n },\n },\n});\n\n// ============================================\n// Gateway Configuration\n// ============================================\n\nexport const GatewayAuthRateLimitSchema = z\n .object({\n enabled: z.boolean().default(true),\n maxAttempts: z.number().int().min(1).default(5),\n windowMs: z.number().default(900_000),\n blockDurationMs: z.number().default(300_000),\n })\n .optional();\n\nexport const GatewayAuthSchema = z\n .object({\n mode: z.enum(['none', 'token']).default('token'),\n token: z.string().optional(),\n rateLimit: GatewayAuthRateLimitSchema,\n })\n .default({\n mode: 'token',\n });\n\nexport const HeartbeatConfigSchema = z\n .object({\n enabled: z.boolean(),\n intervalMs: z.number(),\n /** When false, heartbeat instructions are only sent during heartbeat polling turns (not in every chat system prompt). */\n includeSystemPromptSection: z.boolean().optional().default(false),\n target: z.string().optional(),\n targetChatId: z.string().optional(),\n prompt: z.string().optional(),\n ackMaxChars: z.number().optional(),\n isolatedSession: z.boolean().optional(),\n activeHours: z\n .object({\n start: z.string(),\n end: z.string(),\n timezone: z.string().optional(),\n })\n .optional(),\n })\n .default({\n enabled: true,\n intervalMs: 1_800_000,\n includeSystemPromptSection: false,\n });\n\nexport const GatewayConfigSchema = z.object({\n host: z.string().optional(),\n port: z.number().optional(),\n auth: GatewayAuthSchema.optional(),\n heartbeat: HeartbeatConfigSchema.optional(),\n maxSseConnections: z.number().optional(),\n corsOrigins: z.array(z.string()).optional(),\n /** Base URL for the xopc skills marketplace (public REST API). */\n skillsStoreBaseUrl: z.string().url().optional(),\n}).default({\n host: '127.0.0.1',\n port: 18790,\n auth: {\n mode: 'token',\n },\n heartbeat: {\n enabled: true,\n intervalMs: 1_800_000,\n includeSystemPromptSection: false,\n },\n maxSseConnections: 100,\n corsOrigins: [],\n skillsStoreBaseUrl: 'https://store.xopc.ai',\n});\n\nexport const CronConfigSchema = z.object({\n enabled: z.boolean().optional(),\n maxConcurrentJobs: z.number().optional(),\n defaultTimezone: z.string().optional(),\n historyRetentionDays: z.number().optional(),\n enableMetrics: z.boolean().optional(),\n}).default({\n enabled: true,\n maxConcurrentJobs: 5,\n defaultTimezone: 'UTC',\n historyRetentionDays: 7,\n enableMetrics: true,\n});\n\nexport const ModelsDevConfigSchema = z.object({\n enabled: z.boolean().default(true),\n}).default({\n enabled: true,\n});\n\n// ============================================\n// STT (Speech-to-Text) Config\n// ============================================\n\nexport const STTProviderConfigSchema = z.object({\n apiKey: z.string().optional(),\n model: z.string().optional(),\n});\n\nexport const STTFallbackConfigSchema = z.object({\n enabled: z.boolean().default(true),\n order: z.array(z.enum(['alibaba', 'openai'])).default(['alibaba', 'openai']),\n});\n\nexport const STTConfigSchema = z.object({\n enabled: z.boolean().default(false),\n provider: z.enum(['alibaba', 'openai']).default('alibaba'),\n alibaba: STTProviderConfigSchema.optional(),\n openai: STTProviderConfigSchema.optional(),\n fallback: STTFallbackConfigSchema.optional(),\n});\n\n// ============================================\n// TTS (Text-to-Speech) Config\n// ============================================\n\nexport const TTSProviderConfigSchema = z.object({\n apiKey: z.string().optional(),\n model: z.string().optional(),\n voice: z.string().optional(),\n});\n\nexport const TTSFallbackConfigSchema = z.object({\n enabled: z.boolean().default(true),\n order: z\n .array(z.enum(['openai', 'alibaba', 'edge', 'minimax']))\n .default(['openai', 'alibaba', 'minimax', 'edge']),\n});\n\nexport const TTSModelOverridesConfigSchema = z.object({\n enabled: z.boolean().default(true),\n allowText: z.boolean().default(true),\n allowProvider: z.boolean().default(false),\n allowVoice: z.boolean().default(true),\n allowModelId: z.boolean().default(true),\n allowVoiceSettings: z.boolean().default(false),\n allowNormalization: z.boolean().default(false),\n allowSeed: z.boolean().default(false),\n});\n\nexport const TTSEdgeConfigSchema = z.object({\n enabled: z.boolean().default(true),\n voice: z.string().optional(),\n lang: z.string().optional(),\n outputFormat: z.string().optional(),\n pitch: z.string().optional(),\n rate: z.string().optional(),\n volume: z.string().optional(),\n proxy: z.string().optional(),\n timeoutMs: z.number().int().min(1000).max(120000).optional(),\n});\n\nexport const TTSSummarizationConfigSchema = z.object({\n enabled: z.boolean().optional(),\n targetLength: z.number().int().min(1).optional(),\n threshold: z.number().int().min(1).optional(),\n model: z.string().optional(),\n});\n\nexport const TTSConfigSchema = z.object({\n enabled: z.boolean().default(false),\n provider: z.enum(['openai', 'alibaba', 'edge', 'minimax']).default('openai'),\n trigger: z\n .preprocess(\n (v) => (v === 'auto' ? 'inbound' : v),\n z.enum(['off', 'always', 'inbound', 'tagged']).default('always'),\n ),\n fallback: TTSFallbackConfigSchema.optional(),\n maxTextLength: z.number().int().min(1).default(512), // Conservative default to accommodate all providers (Alibaba limit is 512)\n timeoutMs: z.number().int().min(1000).max(180000).default(60000),\n summarization: TTSSummarizationConfigSchema.optional(),\n modelOverrides: TTSModelOverridesConfigSchema.optional(),\n alibaba: TTSProviderConfigSchema.optional(),\n openai: TTSProviderConfigSchema.optional(),\n edge: TTSEdgeConfigSchema.optional(),\n minimax: TTSProviderConfigSchema.optional(),\n});\n\n// ============================================\n// Extension Configs \n// ============================================\n\n// Security config for extensions \nexport const ExtensionSecurityConfigSchema = z.object({\n checkPermissions: z.boolean().default(true),\n allowUntrusted: z.boolean().default(false),\n allow: z.array(z.string()).default([]),\n trackProvenance: z.boolean().default(true),\n allowPromptInjection: z.boolean().default(false),\n});\n\n// Slot config for extensions \nexport const ExtensionSlotsConfigSchema = z.object({\n memory: z.string().optional(),\n tts: z.string().optional(),\n imageGeneration: z.string().optional(),\n webSearch: z.string().optional(),\n});\n\n// Complete extensions config\n// Extension config allows both known fields AND arbitrary extension-specific config\n// Known fields: enabled (array), allow (array), security (object), slots (object)\n// Arbitrary: any other key is extension-specific config (e.g., extensions.hello.greeting)\nexport const ExtensionsConfigSchema: z.ZodType<Record<string, unknown>> = z.record(z.string(), z.unknown());\n\n// ============================================\n// Update Config\n// ============================================\n\nexport const UpdateAutoConfigSchema = z\n .object({\n /** Enable automatic update installation. Default false. */\n enabled: z.boolean().default(false),\n /** Hours to wait before applying a stable update after first detection. */\n stableDelayHours: z.number().min(0).default(6),\n /** Additional random jitter hours for stable rollout (avoids thundering herd). */\n stableJitterHours: z.number().min(0).default(12),\n /** How often to re-check for beta updates (hours). Min 0.25. */\n betaCheckIntervalHours: z.number().min(0.25).default(1),\n })\n .strict()\n .optional();\n\nexport const UpdateConfigSchema = z\n .object({\n /** Check for updates on gateway startup. Default true. */\n checkOnStart: z.boolean().default(true),\n /** Update channel: stable (default), beta, or dev. */\n channel: z.enum(['stable', 'beta', 'dev']).default('stable'),\n /** Automatic update policy. */\n auto: UpdateAutoConfigSchema,\n })\n .strict()\n .optional();\n\nexport type UpdateConfig = z.infer<typeof UpdateConfigSchema>;\n\n// ============================================\n// Root Config\n// ============================================\n\nexport const ConfigSchema = z.object({\n agents: AgentsConfigSchema,\n bindings: BindingsConfigSchema,\n session: SessionConfigSchema,\n channels: ChannelsConfigSchema,\n gateway: GatewayConfigSchema,\n tools: ToolsConfigSchema,\n cron: CronConfigSchema,\n extensions: ExtensionsConfigSchema.default({}),\n modelsDev: ModelsDevConfigSchema,\n stt: STTConfigSchema.optional(),\n tts: TTSConfigSchema.optional(),\n update: UpdateConfigSchema,\n}).default({\n agents: {\n defaults: {\n workspace: '~/.xopc/workspace',\n model: '', // Empty default - will be resolved dynamically at runtime\n maxTokens: 8192,\n temperature: 0.7,\n maxToolIterations: 20,\n maxRequestsPerTurn: 50,\n maxToolFailuresPerTurn: 3,\n thinkingDefault: 'medium',\n reasoningDefault: 'off',\n verboseDefault: 'off',\n compaction: {\n enabled: true,\n mode: 'default',\n reserveTokens: 8000,\n triggerThreshold: 0.8,\n minMessagesBeforeCompact: 10,\n keepRecentMessages: 5,\n evictionWindow: 0.2,\n retentionWindow: 6,\n },\n pruning: {\n enabled: true,\n maxToolResultChars: 10000,\n headKeepRatio: 0.3,\n tailKeepRatio: 0.3,\n },\n },\n },\n bindings: [],\n session: {\n dmScope: 'main' as const,\n },\n channels: {\n telegram: {\n enabled: false,\n botToken: '',\n allowFrom: [],\n groupAllowFrom: [],\n debug: false,\n dmPolicy: 'pairing' as const,\n groupPolicy: 'open' as const,\n replyToMode: 'off' as const,\n historyLimit: 50,\n textChunkLimit: 4000,\n },\n },\n gateway: {\n host: '127.0.0.1',\n port: 18790,\n auth: {\n mode: 'token',\n },\n heartbeat: {\n enabled: true,\n intervalMs: 1_800_000,\n includeSystemPromptSection: false,\n },\n maxSseConnections: 100,\n corsOrigins: [],\n skillsStoreBaseUrl: 'https://store.xopc.ai',\n },\n tools: {\n web: {\n search: {\n maxResults: 5,\n providers: [],\n },\n },\n },\n cron: {\n enabled: true,\n maxConcurrentJobs: 5,\n defaultTimezone: 'UTC',\n historyRetentionDays: 7,\n enableMetrics: true,\n },\n extensions: {\n allow: [],\n security: {\n checkPermissions: true,\n allowUntrusted: false,\n allow: [],\n trackProvenance: true,\n allowPromptInjection: false,\n },\n slots: {},\n },\n modelsDev: {\n enabled: true,\n },\n stt: {\n enabled: false,\n provider: 'alibaba',\n alibaba: {\n model: 'paraformer-v2',\n },\n openai: {\n model: 'whisper-1',\n },\n fallback: {\n enabled: true,\n order: ['alibaba', 'openai'],\n },\n },\n tts: {\n enabled: false,\n provider: 'openai',\n trigger: 'always',\n fallback: {\n enabled: true,\n order: ['openai', 'alibaba', 'minimax', 'edge'],\n },\n maxTextLength: 4096,\n timeoutMs: 30000,\n modelOverrides: {\n enabled: true,\n allowText: true,\n allowProvider: false,\n allowVoice: true,\n allowModelId: true,\n allowVoiceSettings: false,\n allowNormalization: false,\n allowSeed: false,\n },\n alibaba: {\n model: 'qwen-tts',\n voice: 'Cherry',\n },\n openai: {\n model: 'tts-1',\n voice: 'alloy',\n },\n edge: {\n enabled: true,\n voice: 'en-US-MichelleNeural',\n lang: 'en-US',\n outputFormat: 'audio-24khz-48kbitrate-mono-mp3',\n },\n minimax: {\n model: 'speech-2.8-hd',\n voice: 'male-qn-qingse',\n },\n },\n});\n\nexport type Config = z.infer<typeof ConfigSchema>;\nexport type AgentDefaults = z.infer<typeof AgentDefaultsSchema>;\nexport type GatewayAuthConfig = z.infer<typeof GatewayAuthSchema>;\nexport type GatewayAuthRateLimitConfig = z.infer<typeof GatewayAuthRateLimitSchema>;\nexport type STTConfig = z.infer<typeof STTConfigSchema>;\nexport type TTSConfig = z.infer<typeof TTSConfigSchema>;\n\n// ============================================\n// Helper Functions\n// ============================================\n\n/**\n * Parse a model reference string.\n */\nexport interface ParsedModelRef {\n provider: string;\n model: string;\n}\n\n/**\n * Default agent’s resolved Markdown workspace root (`resolveAgentWorkspaceDir` for the default agent id).\n */\nexport function getWorkspacePath(config: Config): string {\n return getDefaultWorkspacePath(config);\n}\n\n/**\n * Primary model ref from `agents.defaults.model` (string or `{ primary }`).\n * Returns undefined when unset or empty.\n */\nexport function getAgentDefaultModelRef(config: Config): string | undefined {\n const raw = config.agents?.defaults?.model;\n if (raw === undefined || raw === null) return undefined;\n const ref = typeof raw === 'string' ? raw : raw.primary;\n if (ref === undefined || ref === null) return undefined;\n const s = String(ref).trim();\n return s ? s : undefined;\n}\n\n/** `provider/model` or null when invalid. */\nexport function parseModelRef(ref: string): ParsedModelRef | null {\n const trimmed = ref.trim();\n const idx = trimmed.indexOf('/');\n if (idx <= 0 || idx === trimmed.length - 1) {\n return null;\n }\n return { provider: trimmed.slice(0, idx).trim(), model: trimmed.slice(idx + 1).trim() };\n}\n"],"mappings":";;;;;;;;;AA0yBA,SAAgB,iBAAiB,QAAwB;AACvD,QAAO,wBAAwB,OAAO;;;;;;AAOxC,SAAgB,wBAAwB,QAAoC;CAC1E,MAAM,MAAM,OAAO,QAAQ,UA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AAS;GACT,UAAU;GACV,SAAS;GACT,UAAU;IACR,SAAS;IACT,OAAO;KAAC;KAAU;KAAW;KAAW;KAAO;IAChD;GACD,eAAe;GACf,WAAW;GACX,gBAAgB;IACd,SAAS;IACT,WAAW;IACX,eAAe;IACf,YAAY;IACZ,cAAc;IACd,oBAAoB;IACpB,oBAAoB;IACpB,WAAW;IACZ;GACD,SAAS;IACP,OAAO;IACP,OAAO;IACR;GACD,QAAQ;IACN,OAAO;IACP,OAAO;IACR;GACD,MAAM;IACJ,SAAS;IACT,OAAO;IACP,MAAM;IACN,cAAc;IACf;GACD,SAAS;IACP,OAAO;IACP,OAAO;IACR;GACF;EACF,CAAC"}
|
|
@@ -60,11 +60,29 @@ export declare function buildSafeWebConfigPayload(service: GatewayService): Prom
|
|
|
60
60
|
frequency?: string;
|
|
61
61
|
timezone?: string;
|
|
62
62
|
phases?: {
|
|
63
|
+
light?: {
|
|
64
|
+
enabled?: boolean;
|
|
65
|
+
cron?: string;
|
|
66
|
+
lookbackDays?: number;
|
|
67
|
+
limit?: number;
|
|
68
|
+
dedupeSimilarity?: number;
|
|
69
|
+
};
|
|
63
70
|
deep?: {
|
|
64
71
|
enabled?: boolean;
|
|
72
|
+
cron?: string;
|
|
65
73
|
minScore?: number;
|
|
66
74
|
minRecallCount?: number;
|
|
75
|
+
minUniqueQueries?: number;
|
|
76
|
+
limit?: number;
|
|
77
|
+
recencyHalfLifeDays?: number;
|
|
78
|
+
maxAgeDays?: number;
|
|
79
|
+
};
|
|
80
|
+
rem?: {
|
|
81
|
+
enabled?: boolean;
|
|
82
|
+
cron?: string;
|
|
83
|
+
lookbackDays?: number;
|
|
67
84
|
limit?: number;
|
|
85
|
+
minPatternStrength?: number;
|
|
68
86
|
};
|
|
69
87
|
};
|
|
70
88
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { getWorkspacePath, init_schema } from "../../../config/schema.js";
|
|
2
|
-
import { DREAMING_LAST_RUN_RELATIVE, SHORT_TERM_PROMOTION_LOCK_RELATIVE, SHORT_TERM_RECALL_STORE_RELATIVE } from "../../../agent/memory/dreaming/constants.js";
|
|
2
|
+
import { DREAMING_CRON_NAME, DREAMING_DIR_RELATIVE, DREAMING_LAST_RUN_RELATIVE, DREAMING_LIGHT_CRON_NAME, DREAMING_LIGHT_SWEEP_TOKEN, DREAMING_REM_CRON_NAME, DREAMING_REM_SWEEP_TOKEN, DREAMING_SWEEP_TOKEN, SHORT_TERM_PROMOTION_LOCK_RELATIVE, SHORT_TERM_RECALL_STORE_RELATIVE } from "../../../agent/memory/dreaming/constants.js";
|
|
3
3
|
import { loadDreamingStore, saveDreamingStore } from "../../../agent/memory/dreaming/short-term-store.js";
|
|
4
4
|
import { resolveDreamingConfig } from "../../../agent/memory/dreaming/config.js";
|
|
5
|
+
import { parseDreamingLastRunFile } from "../../../agent/memory/dreaming/last-run.js";
|
|
6
|
+
import { readDreamingEvents } from "../../../agent/memory/dreaming/events.js";
|
|
5
7
|
import { previewDreamingDeepPromotion } from "../../../agent/memory/dreaming/preview.js";
|
|
6
8
|
import path from "node:path";
|
|
7
9
|
import fs from "node:fs/promises";
|
|
@@ -34,18 +36,50 @@ async function readLastRun(workspaceDir) {
|
|
|
34
36
|
const fullPath = path.join(workspaceDir, DREAMING_LAST_RUN_RELATIVE);
|
|
35
37
|
try {
|
|
36
38
|
const text = await fs.readFile(fullPath, "utf-8");
|
|
39
|
+
let raw;
|
|
40
|
+
try {
|
|
41
|
+
raw = JSON.parse(text);
|
|
42
|
+
} catch (parseErr) {
|
|
43
|
+
return {
|
|
44
|
+
exists: true,
|
|
45
|
+
path: DREAMING_LAST_RUN_RELATIVE,
|
|
46
|
+
raw: null,
|
|
47
|
+
record: null,
|
|
48
|
+
parseError: parseErr instanceof Error ? parseErr.message : String(parseErr)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const record = parseDreamingLastRunFile(raw);
|
|
37
52
|
return {
|
|
38
53
|
exists: true,
|
|
39
54
|
path: DREAMING_LAST_RUN_RELATIVE,
|
|
40
|
-
raw
|
|
55
|
+
raw,
|
|
56
|
+
record,
|
|
57
|
+
parseError: record ? null : "Invalid or unsupported last-run.json (expected v2 deep record)."
|
|
41
58
|
};
|
|
42
59
|
} catch (err) {
|
|
43
60
|
if (err?.code === "ENOENT") return { exists: false };
|
|
44
61
|
return {
|
|
45
62
|
exists: true,
|
|
46
63
|
path: DREAMING_LAST_RUN_RELATIVE,
|
|
47
|
-
raw: null
|
|
64
|
+
raw: null,
|
|
65
|
+
record: null,
|
|
66
|
+
parseError: err instanceof Error ? err.message : String(err)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function readPhaseLastRun(workspaceDir, filename) {
|
|
71
|
+
const relPath = path.join(DREAMING_DIR_RELATIVE, filename);
|
|
72
|
+
const fullPath = path.join(workspaceDir, relPath);
|
|
73
|
+
try {
|
|
74
|
+
const text = await fs.readFile(fullPath, "utf-8");
|
|
75
|
+
return {
|
|
76
|
+
exists: true,
|
|
77
|
+
path: relPath,
|
|
78
|
+
raw: JSON.parse(text)
|
|
48
79
|
};
|
|
80
|
+
} catch (err) {
|
|
81
|
+
if (err?.code === "ENOENT") return { exists: false };
|
|
82
|
+
return { exists: false };
|
|
49
83
|
}
|
|
50
84
|
}
|
|
51
85
|
function storeStats(store) {
|
|
@@ -80,7 +114,11 @@ function registerDreamingRoutes(authenticated, deps) {
|
|
|
80
114
|
const resolved = resolveDreamingConfig(cfg);
|
|
81
115
|
const { store } = await loadDreamingStore({ workspaceDir });
|
|
82
116
|
const lock = await readLockInfo(workspaceDir);
|
|
83
|
-
const lastRun = await
|
|
117
|
+
const [lastRun, lightLastRun, remLastRun] = await Promise.all([
|
|
118
|
+
readLastRun(workspaceDir),
|
|
119
|
+
readPhaseLastRun(workspaceDir, "last-run-light.json"),
|
|
120
|
+
readPhaseLastRun(workspaceDir, "last-run-rem.json")
|
|
121
|
+
]);
|
|
84
122
|
return c.json({
|
|
85
123
|
ok: true,
|
|
86
124
|
payload: {
|
|
@@ -89,7 +127,9 @@ function registerDreamingRoutes(authenticated, deps) {
|
|
|
89
127
|
storePath: SHORT_TERM_RECALL_STORE_RELATIVE,
|
|
90
128
|
store: storeStats(store),
|
|
91
129
|
lock,
|
|
92
|
-
lastRun
|
|
130
|
+
lastRun,
|
|
131
|
+
lightLastRun,
|
|
132
|
+
remLastRun
|
|
93
133
|
}
|
|
94
134
|
});
|
|
95
135
|
});
|
|
@@ -105,12 +145,7 @@ function registerDreamingRoutes(authenticated, deps) {
|
|
|
105
145
|
const limit = rawLimit ? Number(rawLimit) : 20;
|
|
106
146
|
const preview = await previewDreamingDeepPromotion({
|
|
107
147
|
workspaceDir,
|
|
108
|
-
config:
|
|
109
|
-
enabled: resolved.deep.enabled,
|
|
110
|
-
minScore: resolved.deep.minScore,
|
|
111
|
-
minRecallCount: resolved.deep.minRecallCount,
|
|
112
|
-
limit: resolved.deep.limit
|
|
113
|
-
},
|
|
148
|
+
config: resolved.deep,
|
|
114
149
|
limit: Number.isFinite(limit) ? limit : 20
|
|
115
150
|
});
|
|
116
151
|
return c.json({
|
|
@@ -119,27 +154,68 @@ function registerDreamingRoutes(authenticated, deps) {
|
|
|
119
154
|
});
|
|
120
155
|
});
|
|
121
156
|
authenticated.post("/api/dreaming/run", async (c) => {
|
|
157
|
+
let body;
|
|
158
|
+
try {
|
|
159
|
+
body = await c.req.json();
|
|
160
|
+
} catch {
|
|
161
|
+
body = {};
|
|
162
|
+
}
|
|
163
|
+
const requestedPhase = isRecord(body) && typeof body.phase === "string" && [
|
|
164
|
+
"light",
|
|
165
|
+
"deep",
|
|
166
|
+
"rem"
|
|
167
|
+
].includes(body.phase) ? body.phase : "deep";
|
|
168
|
+
const { token, cronName } = {
|
|
169
|
+
light: {
|
|
170
|
+
token: DREAMING_LIGHT_SWEEP_TOKEN,
|
|
171
|
+
cronName: DREAMING_LIGHT_CRON_NAME
|
|
172
|
+
},
|
|
173
|
+
deep: {
|
|
174
|
+
token: DREAMING_SWEEP_TOKEN,
|
|
175
|
+
cronName: DREAMING_CRON_NAME
|
|
176
|
+
},
|
|
177
|
+
rem: {
|
|
178
|
+
token: DREAMING_REM_SWEEP_TOKEN,
|
|
179
|
+
cronName: DREAMING_REM_CRON_NAME
|
|
180
|
+
}
|
|
181
|
+
}[requestedPhase];
|
|
122
182
|
const jobs = await service.cronServiceInstance.listJobs();
|
|
123
|
-
const primary = jobs.find((job) => payloadMessageFromJob(job) ===
|
|
183
|
+
const primary = jobs.find((job) => payloadMessageFromJob(job) === token) ?? jobs.find((job) => job.name === cronName) ?? (requestedPhase === "deep" ? jobs.find((job) => job.name?.includes?.("[managed-by=xopc.memory.dreaming]") ?? false) : void 0);
|
|
124
184
|
if (!primary) {
|
|
125
185
|
const dreaming = resolveDreamingConfig(service.currentConfig);
|
|
126
|
-
const hint = dreaming.enabled && dreaming.
|
|
186
|
+
const hint = dreaming.enabled && dreaming.phases[requestedPhase].enabled ? `Dreaming ${requestedPhase} phase is enabled, but no cron job was found yet. Restart the gateway/agent process so it can reconcile managed cron jobs.` : `Dreaming ${requestedPhase} phase is disabled in config. Enable it first.`;
|
|
127
187
|
return c.json({
|
|
128
188
|
ok: false,
|
|
129
|
-
error: { message: `Dreaming cron job not found. ${hint}` }
|
|
189
|
+
error: { message: `Dreaming ${requestedPhase} cron job not found. ${hint}` }
|
|
130
190
|
}, 404);
|
|
131
191
|
}
|
|
132
192
|
try {
|
|
193
|
+
service.emit("dreaming.phase.start", {
|
|
194
|
+
phase: requestedPhase,
|
|
195
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
196
|
+
});
|
|
133
197
|
await service.cronServiceInstance.runJobNow(primary.id);
|
|
198
|
+
service.emit("dreaming.phase.end", {
|
|
199
|
+
phase: requestedPhase,
|
|
200
|
+
ok: true,
|
|
201
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
202
|
+
});
|
|
134
203
|
return c.json({
|
|
135
204
|
ok: true,
|
|
136
205
|
payload: {
|
|
137
206
|
triggered: true,
|
|
138
|
-
jobId: primary.id
|
|
207
|
+
jobId: primary.id,
|
|
208
|
+
phase: requestedPhase
|
|
139
209
|
}
|
|
140
210
|
});
|
|
141
211
|
} catch (err) {
|
|
142
212
|
const em = err instanceof Error ? err.message : String(err);
|
|
213
|
+
service.emit("dreaming.phase.end", {
|
|
214
|
+
phase: requestedPhase,
|
|
215
|
+
ok: false,
|
|
216
|
+
error: em,
|
|
217
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
218
|
+
});
|
|
143
219
|
return c.json({
|
|
144
220
|
ok: false,
|
|
145
221
|
error: { message: em || "Failed to trigger job" }
|
|
@@ -191,6 +267,20 @@ function registerDreamingRoutes(authenticated, deps) {
|
|
|
191
267
|
}
|
|
192
268
|
});
|
|
193
269
|
});
|
|
270
|
+
authenticated.get("/api/dreaming/events", async (c) => {
|
|
271
|
+
const cfg = service.currentConfig;
|
|
272
|
+
const workspaceDir = getWorkspacePath(cfg);
|
|
273
|
+
if (!workspaceDir) return c.json({
|
|
274
|
+
ok: false,
|
|
275
|
+
error: { message: "Workspace not configured" }
|
|
276
|
+
}, 400);
|
|
277
|
+
const rawLimit = c.req.query("limit");
|
|
278
|
+
const events = await readDreamingEvents(workspaceDir, rawLimit ? Math.min(Math.max(Number(rawLimit) || 50, 1), 200) : 50);
|
|
279
|
+
return c.json({
|
|
280
|
+
ok: true,
|
|
281
|
+
payload: { events }
|
|
282
|
+
});
|
|
283
|
+
});
|
|
194
284
|
}
|
|
195
285
|
//#endregion
|
|
196
286
|
export { registerDreamingRoutes };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dreaming.js","names":[],"sources":["../../../../../src/gateway/hono/routes/dreaming.ts"],"sourcesContent":["import type { Hono } from 'hono';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { getWorkspacePath, type Config } from '../../../config/schema.js';\nimport { resolveDreamingConfig } from '../../../agent/memory/dreaming/config.js';\nimport {\n DREAMING_CRON_NAME,\n DREAMING_CRON_TAG,\n DREAMING_LAST_RUN_RELATIVE,\n DREAMING_SWEEP_TOKEN,\n SHORT_TERM_PROMOTION_LOCK_RELATIVE,\n SHORT_TERM_RECALL_STORE_RELATIVE,\n} from '../../../agent/memory/dreaming/constants.js';\nimport { previewDreamingDeepPromotion } from '../../../agent/memory/dreaming/preview.js';\nimport {\n loadDreamingStore,\n saveDreamingStore,\n type DreamingStore,\n} from '../../../agent/memory/dreaming/short-term-store.js';\nimport type { AuthenticatedRouteDeps } from './deps.js';\n\nfunction isRecord(v: unknown): v is Record<string, unknown> {\n return v !== null && typeof v === 'object' && !Array.isArray(v);\n}\n\nasync function readLockInfo(workspaceDir: string): Promise<\n | { locked: false }\n | { locked: true; path: string; content: string; mtimeMs?: number }\n> {\n const lockPath = path.join(workspaceDir, SHORT_TERM_PROMOTION_LOCK_RELATIVE);\n try {\n const [content, st] = await Promise.all([fs.readFile(lockPath, 'utf-8'), fs.stat(lockPath)]);\n return {\n locked: true,\n path: SHORT_TERM_PROMOTION_LOCK_RELATIVE,\n content: content.trim(),\n mtimeMs: st.mtimeMs,\n };\n } catch (err) {\n const code = (err as NodeJS.ErrnoException | undefined)?.code;\n if (code === 'ENOENT') return { locked: false };\n return { locked: true, path: SHORT_TERM_PROMOTION_LOCK_RELATIVE, content: 'unknown', mtimeMs: undefined };\n }\n}\n\nasync function readLastRun(\n workspaceDir: string,\n): Promise<{ exists: false } | { exists: true; path: string; raw: unknown }> {\n const fullPath = path.join(workspaceDir, DREAMING_LAST_RUN_RELATIVE);\n try {\n const text = await fs.readFile(fullPath, 'utf-8');\n return { exists: true, path: DREAMING_LAST_RUN_RELATIVE, raw: JSON.parse(text) as unknown };\n } catch (err) {\n const code = (err as NodeJS.ErrnoException | undefined)?.code;\n if (code === 'ENOENT') return { exists: false };\n return { exists: true, path: DREAMING_LAST_RUN_RELATIVE, raw: null };\n }\n}\n\nfunction storeStats(store: DreamingStore): {\n version: number;\n updatedAt: string;\n entryCount: number;\n promotedCount: number;\n lastPromotedAt: string | null;\n} {\n const entries = Object.values(store.entries ?? {});\n const promoted = entries.filter((e) => typeof e.promotedAt === 'string' && e.promotedAt.trim());\n const lastPromotedAt = promoted\n .map((e) => e.promotedAt!)\n .sort((a, b) => (a < b ? 1 : a > b ? -1 : 0))[0];\n return {\n version: store.version,\n updatedAt: store.updatedAt,\n entryCount: entries.length,\n promotedCount: promoted.length,\n lastPromotedAt: lastPromotedAt ?? null,\n };\n}\n\nfunction payloadMessageFromJob(job: any): string {\n const p = job?.payload;\n if (!p) return '';\n if (p.kind === 'agentTurn' && typeof p.message === 'string') return p.message;\n if (typeof p.text === 'string') return p.text;\n if (typeof p.message === 'string') return p.message;\n return '';\n}\n\nexport function registerDreamingRoutes(authenticated: Hono, deps: AuthenticatedRouteDeps): void {\n const { service } = deps;\n\n authenticated.get('/api/dreaming', async (c) => {\n const cfg = service.currentConfig as Config;\n const workspaceDir = getWorkspacePath(cfg);\n if (!workspaceDir) {\n return c.json({ ok: false, error: { message: 'Workspace not configured' } }, 400);\n }\n\n const resolved = resolveDreamingConfig(cfg);\n const { store } = await loadDreamingStore({ workspaceDir });\n const lock = await readLockInfo(workspaceDir);\n const lastRun = await readLastRun(workspaceDir);\n\n return c.json({\n ok: true,\n payload: {\n workspaceDir,\n config: resolved,\n storePath: SHORT_TERM_RECALL_STORE_RELATIVE,\n store: storeStats(store),\n lock,\n lastRun,\n },\n });\n });\n\n authenticated.get('/api/dreaming/preview', async (c) => {\n const cfg = service.currentConfig as Config;\n const workspaceDir = getWorkspacePath(cfg);\n if (!workspaceDir) {\n return c.json({ ok: false, error: { message: 'Workspace not configured' } }, 400);\n }\n\n const resolved = resolveDreamingConfig(cfg);\n const rawLimit = c.req.query('limit');\n const limit = rawLimit ? Number(rawLimit) : 20;\n\n const preview = await previewDreamingDeepPromotion({\n workspaceDir,\n config: {\n enabled: resolved.deep.enabled,\n minScore: resolved.deep.minScore,\n minRecallCount: resolved.deep.minRecallCount,\n limit: resolved.deep.limit,\n },\n limit: Number.isFinite(limit) ? limit : 20,\n });\n\n return c.json({ ok: true, payload: preview });\n });\n\n authenticated.post('/api/dreaming/run', async (c) => {\n const jobs = await service.cronServiceInstance.listJobs();\n const primary =\n jobs.find((job) => payloadMessageFromJob(job) === DREAMING_SWEEP_TOKEN) ??\n jobs.find((job) => job.name === DREAMING_CRON_NAME) ??\n jobs.find((job) => (job.name?.includes?.(DREAMING_CRON_TAG) ?? false));\n if (!primary) {\n const dreaming = resolveDreamingConfig(service.currentConfig as Config);\n const hint = dreaming.enabled && dreaming.deep.enabled\n ? 'Dreaming is enabled, but no cron job was found yet. Restart the gateway/agent process so it can reconcile managed cron jobs.'\n : 'Dreaming cron is disabled in config (agents.defaults.memory.dreaming.enabled / phases.deep.enabled). Enable it first.';\n return c.json({ ok: false, error: { message: `Dreaming cron job not found. ${hint}` } }, 404);\n }\n\n try {\n await service.cronServiceInstance.runJobNow(primary.id);\n return c.json({ ok: true, payload: { triggered: true, jobId: primary.id } });\n } catch (err) {\n const em = err instanceof Error ? err.message : String(err);\n return c.json({ ok: false, error: { message: em || 'Failed to trigger job' } }, 400);\n }\n });\n\n authenticated.post('/api/dreaming/action', async (c) => {\n const cfg = service.currentConfig as Config;\n const workspaceDir = getWorkspacePath(cfg);\n if (!workspaceDir) {\n return c.json({ ok: false, error: { message: 'Workspace not configured' } }, 400);\n }\n\n let body: unknown;\n try {\n body = await c.req.json();\n } catch {\n body = {};\n }\n const action = isRecord(body) && typeof body.action === 'string' ? body.action.trim() : '';\n\n if (action !== 'reset_store' && action !== 'clear_lock') {\n return c.json({ ok: false, error: { message: 'Invalid action' } }, 400);\n }\n\n if (action === 'reset_store') {\n const nowIso = new Date().toISOString();\n const next: DreamingStore = { version: 1, updatedAt: nowIso, entries: {} };\n await saveDreamingStore({ workspaceDir, store: next });\n return c.json({ ok: true, payload: { reset: true, storePath: SHORT_TERM_RECALL_STORE_RELATIVE } });\n }\n\n const lockPath = path.join(workspaceDir, SHORT_TERM_PROMOTION_LOCK_RELATIVE);\n await fs.unlink(lockPath).catch(() => undefined);\n return c.json({ ok: true, payload: { cleared: true, lockPath: SHORT_TERM_PROMOTION_LOCK_RELATIVE } });\n });\n}\n\n"],"mappings":";;;;;;;;aAI0E;AAkB1E,SAAS,SAAS,GAA0C;AAC1D,QAAO,MAAM,QAAQ,OAAO,MAAM,YAAY,CAAC,MAAM,QAAQ,EAAE;;AAGjE,eAAe,aAAa,cAG1B;CACA,MAAM,WAAW,KAAK,KAAK,cAAc,mCAAmC;AAC5E,KAAI;EACF,MAAM,CAAC,SAAS,MAAM,MAAM,QAAQ,IAAI,CAAC,GAAG,SAAS,UAAU,QAAQ,EAAE,GAAG,KAAK,SAAS,CAAC,CAAC;AAC5F,SAAO;GACL,QAAQ;GACR,MAAM;GACN,SAAS,QAAQ,MAAM;GACvB,SAAS,GAAG;GACb;UACM,KAAK;AAEZ,MADc,KAA2C,SAC5C,SAAU,QAAO,EAAE,QAAQ,OAAO;AAC/C,SAAO;GAAE,QAAQ;GAAM,MAAM;GAAoC,SAAS;GAAW,SAAS,KAAA;GAAW;;;AAI7G,eAAe,YACb,cAC2E;CAC3E,MAAM,WAAW,KAAK,KAAK,cAAc,2BAA2B;AACpE,KAAI;EACF,MAAM,OAAO,MAAM,GAAG,SAAS,UAAU,QAAQ;AACjD,SAAO;GAAE,QAAQ;GAAM,MAAM;GAA4B,KAAK,KAAK,MAAM,KAAK;GAAa;UACpF,KAAK;AAEZ,MADc,KAA2C,SAC5C,SAAU,QAAO,EAAE,QAAQ,OAAO;AAC/C,SAAO;GAAE,QAAQ;GAAM,MAAM;GAA4B,KAAK;GAAM;;;AAIxE,SAAS,WAAW,OAMlB;CACA,MAAM,UAAU,OAAO,OAAO,MAAM,WAAW,EAAE,CAAC;CAClD,MAAM,WAAW,QAAQ,QAAQ,MAAM,OAAO,EAAE,eAAe,YAAY,EAAE,WAAW,MAAM,CAAC;CAC/F,MAA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wBAAwB,OAAO,MAAM;EACtD,MAAM,MAAM,QAAQ;EACpB,MAAM,eAAe,iBAAiB,IAAI;AAC1C,MAAI,CAAC,aACH,QAAO,EAAE,KAAK;GAAE,IAAI;GAAO,OAAO,EAAE,SAAS,4BAA4B;GAAE,EAAE,IAAI;EAGnF,IAAI;AACJ,MAAI;AACF,UAAO,MAAM,EAAE,IAAI,MAAM;UACnB;AACN,UAAO,EAAE;;EAEX,MAAM,SAAS,SAAS,KAAK,IAAI,OAAO,KAAK,WAAW,WAAW,KAAK,OAAO,MAAM,GAAG;AAExF,MAAI,WAAW,iBAAiB,WAAW,aACzC,QAAO,EAAE,KAAK;GAAE,IAAI;GAAO,OAAO,EAAE,SAAS,kBAAkB;GAAE,EAAE,IAAI;AAGzE,MAAI,WAAW,eAAe;AAG5B,SAAM,kBAAkB;IAAE;IAAc,OAAO;KADjB,SAAS;KAAG,4BAD3B,IAAI,MAAM,EAAC,aACiC;KAAE,SAAS,EAAE;KACrB;IAAE,CAAC;AACtD,UAAO,EAAE,KAAK;IAAE,IAAI;IAAM,SAAS;KAAE,OAAO;KAAM,WAAW;KAAkC;IAAE,CAAC;;EAGpG,MAAM,WAAW,KAAK,KAAK,cAAc,mCAAmC;AAC5E,QAAM,GAAG,OAAO,SAAS,CAAC,YAAY,KAAA,EAAU;AAChD,SAAO,EAAE,KAAK;GAAE,IAAI;GAAM,SAAS;IAAE,SAAS;IAAM,UAAU;IAAoC;GAAE,CAAC;GACrG"}
|
|
1
|
+
{"version":3,"file":"dreaming.js","names":[],"sources":["../../../../../src/gateway/hono/routes/dreaming.ts"],"sourcesContent":["import type { Hono } from 'hono';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { getWorkspacePath, type Config } from '../../../config/schema.js';\nimport { resolveDreamingConfig } from '../../../agent/memory/dreaming/config.js';\nimport {\n DREAMING_CRON_NAME,\n DREAMING_CRON_TAG,\n DREAMING_DIR_RELATIVE,\n DREAMING_LAST_RUN_RELATIVE,\n DREAMING_LIGHT_CRON_NAME,\n DREAMING_LIGHT_SWEEP_TOKEN,\n DREAMING_REM_CRON_NAME,\n DREAMING_REM_SWEEP_TOKEN,\n DREAMING_SWEEP_TOKEN,\n SHORT_TERM_PROMOTION_LOCK_RELATIVE,\n SHORT_TERM_RECALL_STORE_RELATIVE,\n type DreamingPhaseId,\n} from '../../../agent/memory/dreaming/constants.js';\nimport { readDreamingEvents } from '../../../agent/memory/dreaming/events.js';\nimport { previewDreamingDeepPromotion } from '../../../agent/memory/dreaming/preview.js';\nimport { parseDreamingLastRunFile, type DreamingDeepLastRun } from '../../../agent/memory/dreaming/last-run.js';\nimport {\n loadDreamingStore,\n saveDreamingStore,\n type DreamingStore,\n} from '../../../agent/memory/dreaming/short-term-store.js';\nimport type { AuthenticatedRouteDeps } from './deps.js';\n\nfunction isRecord(v: unknown): v is Record<string, unknown> {\n return v !== null && typeof v === 'object' && !Array.isArray(v);\n}\n\nasync function readLockInfo(workspaceDir: string): Promise<\n | { locked: false }\n | { locked: true; path: string; content: string; mtimeMs?: number }\n> {\n const lockPath = path.join(workspaceDir, SHORT_TERM_PROMOTION_LOCK_RELATIVE);\n try {\n const [content, st] = await Promise.all([fs.readFile(lockPath, 'utf-8'), fs.stat(lockPath)]);\n return {\n locked: true,\n path: SHORT_TERM_PROMOTION_LOCK_RELATIVE,\n content: content.trim(),\n mtimeMs: st.mtimeMs,\n };\n } catch (err) {\n const code = (err as NodeJS.ErrnoException | undefined)?.code;\n if (code === 'ENOENT') return { locked: false };\n return { locked: true, path: SHORT_TERM_PROMOTION_LOCK_RELATIVE, content: 'unknown', mtimeMs: undefined };\n }\n}\n\nasync function readLastRun(\n workspaceDir: string,\n): Promise<\n | { exists: false }\n | {\n exists: true;\n path: string;\n raw: unknown;\n record: DreamingDeepLastRun | null;\n parseError: string | null;\n }\n> {\n const fullPath = path.join(workspaceDir, DREAMING_LAST_RUN_RELATIVE);\n try {\n const text = await fs.readFile(fullPath, 'utf-8');\n let raw: unknown;\n try {\n raw = JSON.parse(text) as unknown;\n } catch (parseErr) {\n return {\n exists: true,\n path: DREAMING_LAST_RUN_RELATIVE,\n raw: null,\n record: null,\n parseError: parseErr instanceof Error ? parseErr.message : String(parseErr),\n };\n }\n const record = parseDreamingLastRunFile(raw);\n return {\n exists: true,\n path: DREAMING_LAST_RUN_RELATIVE,\n raw,\n record,\n parseError: record ? null : 'Invalid or unsupported last-run.json (expected v2 deep record).',\n };\n } catch (err) {\n const code = (err as NodeJS.ErrnoException | undefined)?.code;\n if (code === 'ENOENT') return { exists: false };\n return {\n exists: true,\n path: DREAMING_LAST_RUN_RELATIVE,\n raw: null,\n record: null,\n parseError: err instanceof Error ? err.message : String(err),\n };\n }\n}\n\nasync function readPhaseLastRun(\n workspaceDir: string,\n filename: string,\n): Promise<{ exists: false } | { exists: true; path: string; raw: unknown }> {\n const relPath = path.join(DREAMING_DIR_RELATIVE, filename);\n const fullPath = path.join(workspaceDir, relPath);\n try {\n const text = await fs.readFile(fullPath, 'utf-8');\n const raw = JSON.parse(text) as unknown;\n return { exists: true, path: relPath, raw };\n } catch (err) {\n const code = (err as NodeJS.ErrnoException | undefined)?.code;\n if (code === 'ENOENT') return { exists: false };\n return { exists: false };\n }\n}\n\nfunction storeStats(store: DreamingStore): {\n version: number;\n updatedAt: string;\n entryCount: number;\n promotedCount: number;\n lastPromotedAt: string | null;\n} {\n const entries = Object.values(store.entries ?? {});\n const promoted = entries.filter((e) => typeof e.promotedAt === 'string' && e.promotedAt.trim());\n const lastPromotedAt = promoted\n .map((e) => e.promotedAt!)\n .sort((a, b) => (a < b ? 1 : a > b ? -1 : 0))[0];\n return {\n version: store.version,\n updatedAt: store.updatedAt,\n entryCount: entries.length,\n promotedCount: promoted.length,\n lastPromotedAt: lastPromotedAt ?? null,\n };\n}\n\nfunction payloadMessageFromJob(job: any): string {\n const p = job?.payload;\n if (!p) return '';\n if (p.kind === 'agentTurn' && typeof p.message === 'string') return p.message;\n if (typeof p.text === 'string') return p.text;\n if (typeof p.message === 'string') return p.message;\n return '';\n}\n\nexport function registerDreamingRoutes(authenticated: Hono, deps: AuthenticatedRouteDeps): void {\n const { service } = deps;\n\n authenticated.get('/api/dreaming', async (c) => {\n const cfg = service.currentConfig as Config;\n const workspaceDir = getWorkspacePath(cfg);\n if (!workspaceDir) {\n return c.json({ ok: false, error: { message: 'Workspace not configured' } }, 400);\n }\n\n const resolved = resolveDreamingConfig(cfg);\n const { store } = await loadDreamingStore({ workspaceDir });\n const lock = await readLockInfo(workspaceDir);\n\n // Read all three phase last-run files in parallel.\n const [lastRun, lightLastRun, remLastRun] = await Promise.all([\n readLastRun(workspaceDir),\n readPhaseLastRun(workspaceDir, 'last-run-light.json'),\n readPhaseLastRun(workspaceDir, 'last-run-rem.json'),\n ]);\n\n return c.json({\n ok: true,\n payload: {\n workspaceDir,\n config: resolved,\n storePath: SHORT_TERM_RECALL_STORE_RELATIVE,\n store: storeStats(store),\n lock,\n lastRun,\n lightLastRun,\n remLastRun,\n },\n });\n });\n\n authenticated.get('/api/dreaming/preview', async (c) => {\n const cfg = service.currentConfig as Config;\n const workspaceDir = getWorkspacePath(cfg);\n if (!workspaceDir) {\n return c.json({ ok: false, error: { message: 'Workspace not configured' } }, 400);\n }\n\n const resolved = resolveDreamingConfig(cfg);\n const rawLimit = c.req.query('limit');\n const limit = rawLimit ? Number(rawLimit) : 20;\n\n const preview = await previewDreamingDeepPromotion({\n workspaceDir,\n config: resolved.deep,\n limit: Number.isFinite(limit) ? limit : 20,\n });\n\n return c.json({ ok: true, payload: preview });\n });\n\n authenticated.post('/api/dreaming/run', async (c) => {\n let body: unknown;\n try { body = await c.req.json(); } catch { body = {}; }\n const requestedPhase: DreamingPhaseId =\n isRecord(body) && typeof body.phase === 'string' && ['light', 'deep', 'rem'].includes(body.phase)\n ? (body.phase as DreamingPhaseId)\n : 'deep';\n\n // Map phase → token + cron name for job lookup.\n const phaseTokenMap: Record<DreamingPhaseId, { token: string; cronName: string }> = {\n light: { token: DREAMING_LIGHT_SWEEP_TOKEN, cronName: DREAMING_LIGHT_CRON_NAME },\n deep: { token: DREAMING_SWEEP_TOKEN, cronName: DREAMING_CRON_NAME },\n rem: { token: DREAMING_REM_SWEEP_TOKEN, cronName: DREAMING_REM_CRON_NAME },\n };\n const { token, cronName } = phaseTokenMap[requestedPhase];\n\n const jobs = await service.cronServiceInstance.listJobs();\n const primary =\n jobs.find((job) => payloadMessageFromJob(job) === token) ??\n jobs.find((job) => job.name === cronName) ??\n (requestedPhase === 'deep'\n ? jobs.find((job) => (job.name?.includes?.(DREAMING_CRON_TAG) ?? false))\n : undefined);\n\n if (!primary) {\n const dreaming = resolveDreamingConfig(service.currentConfig as Config);\n const phaseEnabled = dreaming.enabled && dreaming.phases[requestedPhase].enabled;\n const hint = phaseEnabled\n ? `Dreaming ${requestedPhase} phase is enabled, but no cron job was found yet. Restart the gateway/agent process so it can reconcile managed cron jobs.`\n : `Dreaming ${requestedPhase} phase is disabled in config. Enable it first.`;\n return c.json({ ok: false, error: { message: `Dreaming ${requestedPhase} cron job not found. ${hint}` } }, 404);\n }\n\n try {\n // Broadcast phase start to all SSE subscribers (drives dreaming animation overlay).\n service.emit('dreaming.phase.start', { phase: requestedPhase, timestamp: new Date().toISOString() });\n\n await service.cronServiceInstance.runJobNow(primary.id);\n\n // Broadcast phase end (the cron job runs async, so this only marks \"triggered\").\n service.emit('dreaming.phase.end', { phase: requestedPhase, ok: true, timestamp: new Date().toISOString() });\n\n return c.json({ ok: true, payload: { triggered: true, jobId: primary.id, phase: requestedPhase } });\n } catch (err) {\n const em = err instanceof Error ? err.message : String(err);\n service.emit('dreaming.phase.end', { phase: requestedPhase, ok: false, error: em, timestamp: new Date().toISOString() });\n return c.json({ ok: false, error: { message: em || 'Failed to trigger job' } }, 400);\n }\n });\n\n authenticated.post('/api/dreaming/action', async (c) => {\n const cfg = service.currentConfig as Config;\n const workspaceDir = getWorkspacePath(cfg);\n if (!workspaceDir) {\n return c.json({ ok: false, error: { message: 'Workspace not configured' } }, 400);\n }\n\n let body: unknown;\n try {\n body = await c.req.json();\n } catch {\n body = {};\n }\n const action = isRecord(body) && typeof body.action === 'string' ? body.action.trim() : '';\n\n if (action !== 'reset_store' && action !== 'clear_lock') {\n return c.json({ ok: false, error: { message: 'Invalid action' } }, 400);\n }\n\n if (action === 'reset_store') {\n const nowIso = new Date().toISOString();\n const next: DreamingStore = { version: 1, updatedAt: nowIso, entries: {} };\n await saveDreamingStore({ workspaceDir, store: next });\n return c.json({ ok: true, payload: { reset: true, storePath: SHORT_TERM_RECALL_STORE_RELATIVE } });\n }\n\n const lockPath = path.join(workspaceDir, SHORT_TERM_PROMOTION_LOCK_RELATIVE);\n await fs.unlink(lockPath).catch(() => undefined);\n return c.json({ ok: true, payload: { cleared: true, lockPath: SHORT_TERM_PROMOTION_LOCK_RELATIVE } });\n });\n\n authenticated.get('/api/dreaming/events', async (c) => {\n const cfg = service.currentConfig as Config;\n const workspaceDir = getWorkspacePath(cfg);\n if (!workspaceDir) {\n return c.json({ ok: false, error: { message: 'Workspace not configured' } }, 400);\n }\n\n const rawLimit = c.req.query('limit');\n const limit = rawLimit ? Math.min(Math.max(Number(rawLimit) || 50, 1), 200) : 50;\n\n const events = await readDreamingEvents(workspaceDir, limit);\n return c.json({ ok: true, payload: { events } });\n });\n}\n\n"],"mappings":";;;;;;;;;;aAI0E;AA0B1E,SAAS,SAAS,GAA0C;AAC1D,QAAO,MAAM,QAAQ,OAAO,MAAM,YAAY,CAAC,MAAM,QAAQ,EAAE;;AAGjE,eAAe,aAAa,cAG1B;CACA,MAAM,WAAW,KAAK,KAAK,cAAc,mCAAmC;AAC5E,KAAI;EACF,MAAM,CAAC,SAAS,MAAM,MAAM,QAAQ,IAAI,CAAC,GAAG,SAAS,UAAU,QAAQ,EAAE,GAAG,KAAK,SAAS,CAAC,CAAC;AAC5F,SAAO;GACL,QAAQ;GACR,MAAM;GACN,SAAS,QAAQ,MAAM;GACvB,SAAS,GAAG;GACb;UACM,KA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,WAAW,aACzC,QAAO,EAAE,KAAK;GAAE,IAAI;GAAO,OAAO,EAAE,SAAS,kBAAkB;GAAE,EAAE,IAAI;AAGzE,MAAI,WAAW,eAAe;AAG5B,SAAM,kBAAkB;IAAE;IAAc,OAAO;KADjB,SAAS;KAAG,4BAD3B,IAAI,MAAM,EAAC,aACiC;KAAE,SAAS,EAAE;KACrB;IAAE,CAAC;AACtD,UAAO,EAAE,KAAK;IAAE,IAAI;IAAM,SAAS;KAAE,OAAO;KAAM,WAAW;KAAkC;IAAE,CAAC;;EAGpG,MAAM,WAAW,KAAK,KAAK,cAAc,mCAAmC;AAC5E,QAAM,GAAG,OAAO,SAAS,CAAC,YAAY,KAAA,EAAU;AAChD,SAAO,EAAE,KAAK;GAAE,IAAI;GAAM,SAAS;IAAE,SAAS;IAAM,UAAU;IAAoC;GAAE,CAAC;GACrG;AAEF,eAAc,IAAI,wBAAwB,OAAO,MAAM;EACrD,MAAM,MAAM,QAAQ;EACpB,MAAM,eAAe,iBAAiB,IAAI;AAC1C,MAAI,CAAC,aACH,QAAO,EAAE,KAAK;GAAE,IAAI;GAAO,OAAO,EAAE,SAAS,4BAA4B;GAAE,EAAE,IAAI;EAGnF,MAAM,WAAW,EAAE,IAAI,MAAM,QAAQ;EAGrC,MAAM,SAAS,MAAM,mBAAmB,cAF1B,WAAW,KAAK,IAAI,KAAK,IAAI,OAAO,SAAS,IAAI,IAAI,EAAE,EAAE,IAAI,GAAG,GAElB;AAC5D,SAAO,EAAE,KAAK;GAAE,IAAI;GAAM,SAAS,EAAE,QAAQ;GAAE,CAAC;GAChD"}
|
|
@@ -2,6 +2,7 @@ import { resolveModelsJsonPath } from "../../../config/paths.js";
|
|
|
2
2
|
import { init_resolve_config_value, testApiKeyResolution } from "../../../config/resolve-config-value.js";
|
|
3
3
|
import { init_models_json, loadModelsJson, saveModelsJson, validateModelsConfig } from "../../../config/models-json.js";
|
|
4
4
|
import { getModelRegistry } from "../../../providers/model-registry.js";
|
|
5
|
+
import { CredentialResolver, init_credentials } from "../../../auth/credentials.js";
|
|
5
6
|
import { getProviderRegistry, init_plugin_registry } from "../../../providers/plugin-registry.js";
|
|
6
7
|
import { PROVIDER_META, getAllModels, getAllProviders, getAvailableModels, getProviderActiveKeySource, init_providers, isProviderConfigured } from "../../../providers/index.js";
|
|
7
8
|
import { listImageGenerationProvidersSummary } from "../../../agent/image/generation/runtime.js";
|
|
@@ -9,6 +10,7 @@ import { listImageGenerationProvidersSummary } from "../../../agent/image/genera
|
|
|
9
10
|
init_models_json();
|
|
10
11
|
init_resolve_config_value();
|
|
11
12
|
init_providers();
|
|
13
|
+
init_credentials();
|
|
12
14
|
init_plugin_registry();
|
|
13
15
|
function mapPluginModel(providerId, model, available) {
|
|
14
16
|
return {
|
|
@@ -28,7 +30,7 @@ function mapPluginModel(providerId, model, available) {
|
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
function registerModelsRoutes(authenticated, deps) {
|
|
31
|
-
const { service } = deps;
|
|
33
|
+
const { service, strictRateLimitMiddleware } = deps;
|
|
32
34
|
authenticated.get("/api/models-json", async (c) => {
|
|
33
35
|
const path = resolveModelsJsonPath();
|
|
34
36
|
const { config, error } = loadModelsJson(path);
|
|
@@ -201,6 +203,29 @@ function registerModelsRoutes(authenticated, deps) {
|
|
|
201
203
|
payload: { providers: meta }
|
|
202
204
|
});
|
|
203
205
|
});
|
|
206
|
+
authenticated.delete("/api/providers/:providerId/key", strictRateLimitMiddleware, async (c) => {
|
|
207
|
+
const providerId = c.req.param("providerId");
|
|
208
|
+
if (!providerId) return c.json({
|
|
209
|
+
ok: false,
|
|
210
|
+
error: { message: "Missing providerId" }
|
|
211
|
+
}, 400);
|
|
212
|
+
const normalizedProvider = providerId.toLowerCase();
|
|
213
|
+
const profileId = `${normalizedProvider}:default`;
|
|
214
|
+
const resolver = new CredentialResolver();
|
|
215
|
+
try {
|
|
216
|
+
await resolver.deleteProfile(profileId);
|
|
217
|
+
return c.json({
|
|
218
|
+
ok: true,
|
|
219
|
+
payload: { deleted: normalizedProvider }
|
|
220
|
+
});
|
|
221
|
+
} catch (error) {
|
|
222
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
223
|
+
return c.json({
|
|
224
|
+
ok: false,
|
|
225
|
+
error: { message: `Failed to delete key: ${errorMessage}` }
|
|
226
|
+
}, 500);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
204
229
|
}
|
|
205
230
|
//#endregion
|
|
206
231
|
export { registerModelsRoutes };
|