@sylphx/flow 0.2.10 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +36 -0
  2. package/dist/chunk-01gv4qey.js +4 -0
  3. package/dist/chunk-01gv4qey.js.map +11 -0
  4. package/dist/{chunk-f9yb2zk3.js → chunk-3m9whg4q.js} +2 -2
  5. package/dist/{chunk-f9yb2zk3.js.map → chunk-3m9whg4q.js.map} +1 -1
  6. package/dist/{chunk-sgafqzer.js → chunk-3w6pd43t.js} +3 -3
  7. package/dist/{chunk-sgafqzer.js.map → chunk-3w6pd43t.js.map} +2 -2
  8. package/dist/{chunk-d6k94684.js → chunk-4nm4ere4.js} +3 -3
  9. package/dist/{chunk-d6k94684.js.map → chunk-4nm4ere4.js.map} +1 -1
  10. package/dist/{chunk-ceyg2zjg.js → chunk-4vrj3f8r.js} +3 -3
  11. package/dist/{chunk-ceyg2zjg.js.map → chunk-4vrj3f8r.js.map} +1 -1
  12. package/dist/chunk-5njgv5k5.js +161 -0
  13. package/dist/{chunk-rsagxdqj.js.map → chunk-5njgv5k5.js.map} +4 -6
  14. package/dist/{chunk-6eb5a8kv.js → chunk-67n29s4q.js} +4 -4
  15. package/dist/chunk-67n29s4q.js.map +10 -0
  16. package/dist/{chunk-66qzap9m.js → chunk-86ce45n6.js} +2 -2
  17. package/dist/{chunk-66qzap9m.js.map → chunk-86ce45n6.js.map} +1 -1
  18. package/dist/{chunk-fyvtp08n.js → chunk-99pz5wm0.js} +2 -2
  19. package/dist/{chunk-fyvtp08n.js.map → chunk-99pz5wm0.js.map} +1 -1
  20. package/dist/chunk-d409xn8f.js +6 -0
  21. package/dist/{chunk-cjy100rr.js.map → chunk-d409xn8f.js.map} +2 -2
  22. package/dist/chunk-g0qpndpd.js +23 -0
  23. package/dist/{chunk-gmmm7xpw.js.map → chunk-g0qpndpd.js.map} +5 -5
  24. package/dist/{chunk-51kpynby.js → chunk-g4baca7p.js} +3 -3
  25. package/dist/{chunk-51kpynby.js.map → chunk-g4baca7p.js.map} +1 -1
  26. package/dist/chunk-gc66xe7z.js +4 -0
  27. package/dist/{chunk-8ep9gk6d.js.map → chunk-gc66xe7z.js.map} +2 -2
  28. package/dist/{chunk-2nfq57ym.js → chunk-hj6qtsqp.js} +2 -2
  29. package/dist/{chunk-2nfq57ym.js.map → chunk-hj6qtsqp.js.map} +2 -2
  30. package/dist/{chunk-etqfkn4f.js → chunk-jbd95k1f.js} +3 -3
  31. package/dist/{chunk-etqfkn4f.js.map → chunk-jbd95k1f.js.map} +1 -1
  32. package/dist/{chunk-z61qdct1.js → chunk-kn908zkk.js} +2 -2
  33. package/dist/{chunk-z61qdct1.js.map → chunk-kn908zkk.js.map} +1 -1
  34. package/dist/{chunk-rvx8bgqk.js → chunk-mw13a082.js} +3 -3
  35. package/dist/{chunk-rvx8bgqk.js.map → chunk-mw13a082.js.map} +1 -1
  36. package/dist/chunk-nke51f3c.js +4 -0
  37. package/dist/chunk-nke51f3c.js.map +10 -0
  38. package/dist/{chunk-ny1s8fnh.js → chunk-ns5atzyz.js} +2 -2
  39. package/dist/{chunk-ny1s8fnh.js.map → chunk-ns5atzyz.js.map} +1 -1
  40. package/dist/chunk-pp4r3hp4.js +105 -0
  41. package/dist/chunk-pp4r3hp4.js.map +27 -0
  42. package/dist/{chunk-372bgp30.js → chunk-q4nh3vst.js} +3 -3
  43. package/dist/{chunk-372bgp30.js.map → chunk-q4nh3vst.js.map} +1 -1
  44. package/dist/{chunk-585jp0rg.js → chunk-q5gqgs0p.js} +3 -3
  45. package/dist/chunk-q5gqgs0p.js.map +10 -0
  46. package/dist/{chunk-f676awyz.js → chunk-s9bsh0gp.js} +3 -3
  47. package/dist/{chunk-f676awyz.js.map → chunk-s9bsh0gp.js.map} +1 -1
  48. package/dist/chunk-ss51dw5h.js +27 -0
  49. package/dist/{chunk-weshapwk.js.map → chunk-ss51dw5h.js.map} +5 -5
  50. package/dist/{chunk-mtrcdhzn.js → chunk-xs370t8p.js} +3 -3
  51. package/dist/{chunk-mtrcdhzn.js.map → chunk-xs370t8p.js.map} +8 -8
  52. package/dist/chunk-xtrn4wn0.js +3 -0
  53. package/dist/{chunk-b0047ggx.js.map → chunk-xtrn4wn0.js.map} +2 -2
  54. package/dist/{chunk-7h737bp8.js → chunk-xvfz960r.js} +3 -3
  55. package/dist/{chunk-7h737bp8.js.map → chunk-xvfz960r.js.map} +1 -1
  56. package/dist/chunk-xytc0fks.js +27 -0
  57. package/dist/{chunk-vc4xy6dm.js.map → chunk-xytc0fks.js.map} +2 -2
  58. package/dist/chunk-yxv7hqse.js +23 -0
  59. package/dist/chunk-yxv7hqse.js.map +11 -0
  60. package/dist/chunk-zv5y8yfq.js +19 -0
  61. package/dist/chunk-zv5y8yfq.js.map +11 -0
  62. package/dist/index.js +278 -285
  63. package/dist/index.js.map +34 -30
  64. package/drizzle/0002_lyrical_random.sql +2 -0
  65. package/drizzle/0003_romantic_lockjaw.sql +4 -0
  66. package/drizzle/0004_blushing_meteorite.sql +6 -0
  67. package/drizzle/meta/0002_snapshot.json +920 -0
  68. package/drizzle/meta/0003_snapshot.json +920 -0
  69. package/drizzle/meta/0004_snapshot.json +921 -0
  70. package/drizzle/meta/_journal.json +21 -0
  71. package/package.json +4 -1
  72. package/dist/chunk-057m762a.js +0 -4
  73. package/dist/chunk-057m762a.js.map +0 -10
  74. package/dist/chunk-2j2gmjg5.js +0 -107
  75. package/dist/chunk-2j2gmjg5.js.map +0 -25
  76. package/dist/chunk-585jp0rg.js.map +0 -10
  77. package/dist/chunk-6eb5a8kv.js.map +0 -10
  78. package/dist/chunk-8ep9gk6d.js +0 -4
  79. package/dist/chunk-9qzv4trv.js +0 -23
  80. package/dist/chunk-9qzv4trv.js.map +0 -11
  81. package/dist/chunk-b0047ggx.js +0 -3
  82. package/dist/chunk-cjy100rr.js +0 -6
  83. package/dist/chunk-e74zv5ct.js +0 -19
  84. package/dist/chunk-e74zv5ct.js.map +0 -10
  85. package/dist/chunk-gmmm7xpw.js +0 -23
  86. package/dist/chunk-rsagxdqj.js +0 -161
  87. package/dist/chunk-vc4xy6dm.js +0 -27
  88. package/dist/chunk-weshapwk.js +0 -27
@@ -1,23 +0,0 @@
1
- import{N}from"./chunk-weshapwk.js";import{O as I}from"./chunk-sgafqzer.js";import{T as j}from"./chunk-cjy100rr.js";import{Z as Y}from"./chunk-7h737bp8.js";import"./chunk-372bgp30.js";import"./chunk-rvx8bgqk.js";import"./chunk-f676awyz.js";import"./chunk-gmmm7xpw.js";import"./chunk-51kpynby.js";import"./chunk-etqfkn4f.js";import"./chunk-cv1nhr27.js";import"./chunk-ceyg2zjg.js";import"./chunk-f9yb2zk3.js";import*as D from"node:os";function E(w){let Q=w.filter((J)=>J.status!=="completed"&&J.status!=="removed");if(Q.length===0)return"<todo_reminder>For multi-step tasks, use updateTodos tool</todo_reminder>";let V=[...Q].sort((J,Z)=>{if(J.ordering!==Z.ordering)return J.ordering-Z.ordering;return J.id-Z.id}),X=V.filter((J)=>J.status==="pending"),z=V.filter((J)=>J.status==="in_progress"),W=["<pending_tasks>"];if(z.length>0)W.push("In Progress:"),z.forEach((J)=>W.push(` - [${J.id}] ${J.activeForm}`));if(X.length>0)W.push("Pending:"),X.forEach((J)=>W.push(` - [${J.id}] ${J.content}`));return W.push("</pending_tasks>"),W.join(`
2
- `)}var F=`You are a helpful coding assistant.
3
-
4
- You help users with:
5
- - Programming tasks and code review
6
- - Debugging and troubleshooting
7
- - File operations and system tasks
8
- - Software development best practices
9
-
10
- Guidelines:
11
- - Write clean, functional, well-documented code
12
- - Use tools proactively when needed to complete tasks
13
- - Explain complex concepts clearly
14
- - Follow language-specific best practices
15
- - Test and verify your work when possible`,f="You are Sylphx, an AI development assistant.";function C(){let w=[];w.push(f);try{let Q=j();if(Q)w.push(Q)}catch{}try{let Q=Y();w.push(Q)}catch{w.push(F)}return w.join(`
16
-
17
- `)}var l=F;function g(){let w=new Date().toISOString(),Q=D.totalmem(),V=D.freemem(),z=((Q-V)/1024/1024/1024).toFixed(1),W=(Q/1024/1024/1024).toFixed(1),J=D.cpus(),Z=J.length,v=0,$=0;J.forEach((K)=>{for(let B in K.times)$+=K.times[B];v+=K.times.idle});let U=(100-100*v/$).toFixed(1);return{timestamp:w,cpu:`${U}% (${Z} cores)`,memory:`${z}GB/${W}GB`}}function R(w){return`<system_status>
18
- Time: ${w.timestamp}
19
- CPU: ${w.cpu}
20
- Memory: ${w.memory}
21
- </system_status>`}function d(w,Q){if(!w||typeof w!=="object")return w;let V={type:"content",value:[]};if(w.type==="content")V.value=w.value;else if(w.type==="text"||w.type==="error-text")V.value.push({type:"text",text:w.value});else if(w.type==="json"||w.type==="error-json")V.value.push({type:"text",text:JSON.stringify(w.value,null,2)});let X=R(Q);return V.value.unshift({type:"text",text:X}),V}function P(w){let Q=w.content;if(typeof Q==="string")w.content=[{type:"text",text:Q}];return w}async function*c(w){let{systemPrompt:Q=C(),model:V,messages:X,abortSignal:z,onStepFinish:W,onPrepareMessages:J,onTransformToolResult:Z}=w,v=X.map(P),$=0,U=1000;while($<U){yield{type:"step-start",stepNumber:$};let K=J?J(v,$):v,{fullStream:B,response:_,finishReason:O,usage:G,content:A}=I({model:V,messages:K,system:Q,tools:N(),abortSignal:z});for await(let q of B)switch(q.type){case"text-start":yield{type:"text-start"};break;case"text-delta":yield{type:"text-delta",textDelta:q.text};break;case"text-end":yield{type:"text-end"};break;case"reasoning-start":yield{type:"reasoning-start"};break;case"reasoning-delta":yield{type:"reasoning-delta",textDelta:q.text};break;case"reasoning-end":yield{type:"reasoning-end"};break;case"tool-call":yield{type:"tool-call",toolCallId:q.toolCallId,toolName:q.toolName,args:q.input};break;case"tool-input-start":yield{type:"tool-input-start",toolCallId:q.id,toolName:q.toolName};break;case"tool-input-delta":yield{type:"tool-input-delta",toolCallId:q.id,argsTextDelta:q.delta};break;case"tool-input-end":yield{type:"tool-input-end",toolCallId:q.id};break;case"tool-result":yield{type:"tool-result",toolCallId:q.toolCallId,toolName:q.toolName,result:q.output};break;case"finish":yield{type:"finish",finishReason:q.finishReason,usage:{promptTokens:q.totalUsage.inputTokens??0,completionTokens:q.totalUsage.outputTokens??0,totalTokens:q.totalUsage.totalTokens??0}};break;case"error":yield{type:"error",error:q.error instanceof Error?q.error.message:String(q.error)};break;case"tool-error":yield{type:"tool-error",toolCallId:q.toolCallId,toolName:q.toolName,error:q.error instanceof Error?q.error.message:String(q.error)};break;case"abort":yield{type:"error",error:"Stream aborted"};break;default:break}if(W){let q={finishReason:await O,usage:{promptTokens:(await G).inputTokens??0,completionTokens:(await G).outputTokens??0,totalTokens:(await G).totalTokens??0},content:await A};W(q)}let L=(await _).messages;for(let q of L)if(q.role==="tool"&&Z)v.push({...q,content:q.content.map((H)=>({...H,output:Z(H.output,H.toolName)}))});else v.push(q);let x=await O;if(yield{type:"step-end",stepNumber:$,finishReason:x},x!=="tool-calls")break;$++}}export{P as normalizeMessage,d as injectSystemStatusToOutput,g as getSystemStatus,C as getSystemPrompt,N as getAISDKTools,c as createAIStream,E as buildTodoContext,R as buildSystemStatusFromMetadata,l as SYSTEM_PROMPT};export{E as x,g as y,R as z,d as A,c as B};
22
-
23
- //# debugId=9A0CBF72C3074EE364756E2164756E21
@@ -1,11 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/core/ai-sdk.ts", "../src/utils/todo-context.ts"],
4
- "sourcesContent": [
5
- "/**\n * Sylphx Flow AI SDK\n * Unified AI streaming interface with tool support\n * Content parts based design - own type system with proper conversion\n */\n\nimport { streamText, stepCountIs, type UserContent, type AssistantContent, type DataContent, type ModelMessage } from 'ai';\nimport type { LanguageModelV2, LanguageModelV2ToolResultOutput } from '@ai-sdk/provider';\nimport * as os from 'node:os';\nimport { getAISDKTools } from '../tools/index.js';\nimport { getCurrentSystemPrompt } from './agent-manager.js';\nimport { getEnabledRulesContent } from './rule-manager.js';\nimport { useAppStore } from '../ui/stores/app-store.js';\nimport { buildTodoContext } from '../utils/todo-context.js';\n\n// Legacy system prompt - kept for backwards compatibility and fallback\nconst LEGACY_SYSTEM_PROMPT = `You are a helpful coding assistant.\n\nYou help users with:\n- Programming tasks and code review\n- Debugging and troubleshooting\n- File operations and system tasks\n- Software development best practices\n\nGuidelines:\n- Write clean, functional, well-documented code\n- Use tools proactively when needed to complete tasks\n- Explain complex concepts clearly\n- Follow language-specific best practices\n- Test and verify your work when possible`;\n\n/**\n * Base system prompt - introduces Sylphx\n */\nconst BASE_SYSTEM_PROMPT = `You are Sylphx, an AI development assistant.`;\n\n/**\n * Get the system prompt to use (combines base + rules + agent)\n */\nexport function getSystemPrompt(): string {\n const parts: string[] = [];\n\n // 1. Base prompt (introduces Sylphx)\n parts.push(BASE_SYSTEM_PROMPT);\n\n // 2. Enabled rules (shared across all agents)\n try {\n const rulesContent = getEnabledRulesContent();\n if (rulesContent) {\n parts.push(rulesContent);\n }\n } catch {\n // Rule manager not initialized or no rules enabled\n }\n\n // 3. Agent-specific prompt\n try {\n const agentPrompt = getCurrentSystemPrompt();\n parts.push(agentPrompt);\n } catch {\n // Fallback to legacy if agent manager not initialized\n parts.push(LEGACY_SYSTEM_PROMPT);\n }\n\n return parts.join('\\n\\n');\n}\n\n// Export for backwards compatibility\nexport const SYSTEM_PROMPT = LEGACY_SYSTEM_PROMPT;\n\n/**\n * Stream chunk types (our own)\n */\nexport type TextStartChunk = {\n type: 'text-start';\n};\n\nexport type TextDeltaChunk = {\n type: 'text-delta';\n textDelta: string;\n};\n\nexport type TextEndChunk = {\n type: 'text-end';\n};\n\nexport type ReasoningStartChunk = {\n type: 'reasoning-start';\n};\n\nexport type ReasoningDeltaChunk = {\n type: 'reasoning-delta';\n textDelta: string;\n};\n\nexport type ReasoningEndChunk = {\n type: 'reasoning-end';\n};\n\nexport type ToolCallChunk = {\n type: 'tool-call';\n toolCallId: string;\n toolName: string;\n args: unknown;\n};\n\nexport type ToolInputStartChunk = {\n type: 'tool-input-start';\n toolCallId: string;\n toolName: string;\n};\n\nexport type ToolInputDeltaChunk = {\n type: 'tool-input-delta';\n toolCallId: string;\n argsTextDelta: string;\n};\n\nexport type ToolInputEndChunk = {\n type: 'tool-input-end';\n toolCallId: string;\n};\n\nexport type ToolResultChunk = {\n type: 'tool-result';\n toolCallId: string;\n toolName: string;\n result: unknown;\n};\n\nexport type ToolErrorChunk = {\n type: 'tool-error';\n toolCallId: string;\n toolName: string;\n error: string;\n};\n\nexport type StreamErrorChunk = {\n type: 'error';\n error: string;\n};\n\nexport type FinishChunk = {\n type: 'finish';\n finishReason: string;\n usage: {\n promptTokens: number;\n completionTokens: number;\n totalTokens: number;\n };\n};\n\nexport type StreamChunk =\n | TextStartChunk\n | TextDeltaChunk\n | TextEndChunk\n | ReasoningStartChunk\n | ReasoningDeltaChunk\n | ReasoningEndChunk\n | ToolCallChunk\n | ToolInputStartChunk\n | ToolInputDeltaChunk\n | ToolInputEndChunk\n | ToolResultChunk\n | ToolErrorChunk\n | StreamErrorChunk\n | FinishChunk;\n\n/**\n * Step info (our own)\n */\nexport interface StepInfo {\n finishReason: string;\n usage: {\n promptTokens: number;\n completionTokens: number;\n totalTokens: number;\n };\n content: AssistantContent[];\n}\n\n/**\n * Create AI stream options\n */\nexport interface CreateAIStreamOptions {\n model: LanguageModelV2;\n messages: ModelMessage[];\n systemPrompt?: string;\n /**\n * Optional abort signal to cancel the stream\n */\n abortSignal?: AbortSignal;\n onStepFinish?: (step: StepInfo) => void;\n /**\n * Called before each step to prepare messages\n * Can be used to inject context (e.g., todo list, system status)\n * @param messages - Current message history\n * @param stepNumber - Current step number\n * @returns Modified messages array\n */\n onPrepareMessages?: (messages: ModelMessage[], stepNumber: number) => ModelMessage[];\n /**\n * Called to transform tool result output before saving to history\n * Can be used to inject metadata (e.g., system status, timestamp)\n * @param output - Tool result output\n * @param toolName - Name of the tool\n * @returns Modified output\n */\n onTransformToolResult?: (\n output: LanguageModelV2ToolResultOutput,\n toolName: string\n ) => LanguageModelV2ToolResultOutput;\n}\n\n/**\n * System status object (captured at message creation time)\n *\n * Design: Separation of capture vs construction\n * ==============================================\n *\n * Why we have TWO functions (getSystemStatus + buildSystemStatusFromMetadata):\n *\n * 1. getSystemStatus() - Captures CURRENT system state\n * - Called when creating a NEW message\n * - Returns object { timestamp, cpu, memory }\n * - Stored in SessionMessage.metadata\n * - NEVER called again for historical messages\n *\n * 2. buildSystemStatusFromMetadata() - Constructs string from STORED values\n * - Called when building ModelMessage from SessionMessage\n * - Uses HISTORICAL values from metadata (never current values)\n * - Ensures prompt cache works (historical messages never change)\n *\n * ⚠️ CRITICAL for prompt cache:\n * - Historical messages must be IMMUTABLE\n * - If we use current values, messages change every request → cache miss\n * - Using stored metadata values → messages stay same → cache hit ✅\n *\n * Example timeline:\n * T1: User sends \"hi\"\n * → getSystemStatus() returns { cpu: \"45%\", memory: \"4.2GB\" }\n * → Store in message.metadata\n * T2: User sends \"bye\" (10 minutes later)\n * → getSystemStatus() returns { cpu: \"67%\", memory: \"5.1GB\" } for NEW message\n * → buildSystemStatusFromMetadata(T1.metadata) still returns \"45%, 4.2GB\" for T1 ✅\n * → Prompt cache recognizes T1 message as unchanged → cache hit!\n */\nexport interface SystemStatus {\n timestamp: string; // ISO format\n cpu: string; // e.g., \"45.3% (8 cores)\"\n memory: string; // e.g., \"4.2GB/16.0GB\"\n}\n\n/**\n * Get CURRENT system status (called only when creating NEW messages)\n *\n * ⚠️ IMPORTANT: Never call this for historical messages!\n * Use buildSystemStatusFromMetadata() instead to preserve prompt cache.\n */\nfunction getSystemStatus(): SystemStatus {\n const timestamp = new Date().toISOString();\n\n // Get memory usage\n const totalMem = os.totalmem();\n const freeMem = os.freemem();\n const usedMem = totalMem - freeMem;\n const memUsageGB = (usedMem / 1024 / 1024 / 1024).toFixed(1);\n const totalMemGB = (totalMem / 1024 / 1024 / 1024).toFixed(1);\n\n // Get CPU usage (average load)\n const cpus = os.cpus();\n const cpuCount = cpus.length;\n\n // Calculate average CPU usage from all cores\n let totalIdle = 0;\n let totalTick = 0;\n\n cpus.forEach((cpu) => {\n for (const type in cpu.times) {\n totalTick += cpu.times[type as keyof typeof cpu.times];\n }\n totalIdle += cpu.times.idle;\n });\n\n const cpuUsage = (100 - (100 * totalIdle) / totalTick).toFixed(1);\n\n return {\n timestamp,\n cpu: `${cpuUsage}% (${cpuCount} cores)`,\n memory: `${memUsageGB}GB/${totalMemGB}GB`,\n };\n}\n\n/**\n * Build system status string from STORED metadata (not current values)\n *\n * ⚠️ CRITICAL: This function MUST use the metadata parameter values,\n * NEVER call getSystemStatus() or use current system values!\n *\n * Why: Prompt cache requires historical messages to be immutable.\n * Using stored metadata ensures the same message always produces the same output.\n *\n * Called by:\n * - useChat when building ModelMessage from SessionMessage (historical messages)\n * - Tool result injection (for current step's system status)\n *\n * @param metadata - Stored SystemStatus from SessionMessage.metadata\n * @returns Formatted system status string for LLM\n */\nfunction buildSystemStatusFromMetadata(metadata: SystemStatus): string {\n return `<system_status>\nTime: ${metadata.timestamp}\nCPU: ${metadata.cpu}\nMemory: ${metadata.memory}\n</system_status>`;\n}\n\n/**\n * Inject system status into tool result output\n * Convert all types to content type and prepend system status as text part\n */\nfunction injectSystemStatusToOutput(output: LanguageModelV2ToolResultOutput, systemStatus: SystemStatus): Extract<\n LanguageModelV2ToolResultOutput,\n { type: 'content' }\n> {\n if (!output || typeof output !== 'object') {\n return output;\n }\n\n // Convert to content type if not already\n const content: Extract<\n LanguageModelV2ToolResultOutput,\n { type: 'content' }\n > = {\n type: 'content',\n value: [],\n }\n\n if (output.type === 'content') {\n // Already content type\n content.value = output.value;\n } else if (output.type === 'text' || output.type === 'error-text') {\n content.value.push({\n type: 'text',\n text: output.value,\n });\n } else if (output.type === 'json' || output.type === 'error-json') {\n // Convert JSON to content (stringify)\n content.value.push({\n type: 'text',\n text: JSON.stringify(output.value, null, 2),\n });\n }\n\n // Prepend system status as text part\n const systemStatusString = buildSystemStatusFromMetadata(systemStatus);\n\n content.value.unshift({\n type: 'text',\n text: systemStatusString,\n })\n return content;\n}\n\n/**\n * Normalize content to modern array format\n * Converts legacy string content to Array<TextPart | ImagePart | FilePart | ... >\n */\nfunction normalizeMessage(message: ModelMessage): ModelMessage {\n const content = message.content;\n if (typeof content === 'string') {\n // Legacy string format → convert to TextPart array\n message.content = [\n {\n type: 'text',\n text: content,\n },\n ];\n }\n\n // Already array format (or other object)\n return message;\n}\n\n/**\n * Create AI stream with Sylphx tools pre-configured\n * Uses manual loop to control message history with timestamps\n */\nexport async function* createAIStream(\n options: CreateAIStreamOptions\n): AsyncIterable<StreamChunk> {\n const {\n systemPrompt = getSystemPrompt(),\n model,\n messages: initialMessages,\n abortSignal,\n onStepFinish,\n onPrepareMessages,\n onTransformToolResult,\n } = options;\n\n // Normalize all messages to array format\n let messageHistory = initialMessages.map(normalizeMessage);\n\n let stepNumber = 0;\n const MAX_STEPS = 1000;\n\n while (stepNumber < MAX_STEPS) {\n // Emit step-start event\n yield {\n type: 'step-start' as any,\n stepNumber,\n };\n\n // Prepare messages for this step (caller can inject context)\n const preparedMessages = onPrepareMessages\n ? onPrepareMessages(messageHistory, stepNumber)\n : messageHistory;\n\n // Call AI SDK with single step\n const { fullStream, response, finishReason, usage, content } = streamText({\n model,\n messages: preparedMessages,\n system: systemPrompt,\n tools: getAISDKTools(),\n abortSignal, // Pass abort signal to allow cancellation\n // Don't handle errors here - let them propagate to the caller\n // onError callback is for non-fatal errors, fatal ones should throw\n });\n\n // Stream all chunks to user\n for await (const chunk of fullStream) {\n switch (chunk.type) {\n case 'text-start':\n yield { type: 'text-start' };\n break;\n\n case 'text-delta':\n yield { type: 'text-delta', textDelta: chunk.text };\n break;\n\n case 'text-end':\n yield { type: 'text-end' };\n break;\n\n case 'reasoning-start':\n yield { type: 'reasoning-start' };\n break;\n\n case 'reasoning-delta':\n yield { type: 'reasoning-delta', textDelta: chunk.text };\n break;\n\n case 'reasoning-end':\n yield { type: 'reasoning-end' };\n break;\n\n case 'tool-call':\n yield {\n type: 'tool-call',\n toolCallId: chunk.toolCallId,\n toolName: chunk.toolName,\n args: chunk.input,\n };\n break;\n\n case 'tool-input-start':\n yield {\n type: 'tool-input-start',\n toolCallId: chunk.id,\n toolName: chunk.toolName,\n };\n break;\n\n case 'tool-input-delta':\n yield {\n type: 'tool-input-delta',\n toolCallId: chunk.id,\n argsTextDelta: chunk.delta,\n };\n break;\n\n case 'tool-input-end':\n yield {\n type: 'tool-input-end',\n toolCallId: chunk.id,\n };\n break;\n\n case 'tool-result':\n yield {\n type: 'tool-result',\n toolCallId: chunk.toolCallId,\n toolName: chunk.toolName,\n result: chunk.output,\n };\n break;\n\n case 'finish':\n yield {\n type: 'finish',\n finishReason: chunk.finishReason,\n usage: {\n promptTokens: chunk.totalUsage.inputTokens ?? 0,\n completionTokens: chunk.totalUsage.outputTokens ?? 0,\n totalTokens: chunk.totalUsage.totalTokens ?? 0,\n },\n };\n break;\n\n case 'error':\n yield {\n type: 'error',\n error: chunk.error instanceof Error ? chunk.error.message : String(chunk.error),\n };\n break;\n\n case 'tool-error':\n yield {\n type: 'tool-error',\n toolCallId: chunk.toolCallId,\n toolName: chunk.toolName,\n error: chunk.error instanceof Error ? chunk.error.message : String(chunk.error),\n };\n break;\n\n case 'abort':\n yield {\n type: 'error',\n error: 'Stream aborted',\n };\n break;\n\n default:\n break;\n }\n }\n\n // Call onStepFinish callback if provided\n if (onStepFinish) {\n const stepInfo: StepInfo = {\n finishReason: await finishReason,\n usage: {\n promptTokens: (await usage).inputTokens ?? 0,\n completionTokens: (await usage).outputTokens ?? 0,\n totalTokens: (await usage).totalTokens ?? 0,\n },\n content: await content,\n };\n onStepFinish(stepInfo);\n }\n\n // Save LLM response messages to history\n const responseMessages = (await response).messages;\n\n for (const msg of responseMessages) {\n // Transform tool result output if callback provided\n if (msg.role === 'tool' && onTransformToolResult) {\n messageHistory.push({\n ...msg,\n content: msg.content.map((part) => ({\n ...part,\n output: onTransformToolResult(part.output, part.toolName),\n })),\n });\n } else {\n messageHistory.push(msg);\n }\n }\n\n const currentFinishReason = await finishReason;\n\n // Emit step-end event\n yield {\n type: 'step-end' as any,\n stepNumber,\n finishReason: currentFinishReason,\n };\n\n // Check if we should continue the loop\n if (currentFinishReason !== 'tool-calls') {\n // No more tool calls, exit loop\n break;\n }\n\n stepNumber++;\n }\n}\n\n/**\n * Export helper functions\n */\nexport { getAISDKTools, getSystemStatus, buildSystemStatusFromMetadata, injectSystemStatusToOutput, buildTodoContext, normalizeMessage };\n",
6
- "/**\n * Todo Context Builder\n * Builds todo reminder context for LLM messages\n */\n\nimport type { Todo } from '../types/todo.types.js';\n\n/**\n * Build todo context string from todos\n */\nexport function buildTodoContext(todos: Todo[]): string {\n // Filter active todos (exclude completed and removed)\n const activeTodos = todos.filter((t) => t.status !== 'completed' && t.status !== 'removed');\n\n // If no active todos, return minimal reminder\n if (activeTodos.length === 0) {\n return '<todo_reminder>For multi-step tasks, use updateTodos tool</todo_reminder>';\n }\n\n // Sort by ordering ASC, id ASC (first added = first to do)\n const sortedTodos = [...activeTodos].sort((a, b) => {\n if (a.ordering !== b.ordering) {\n return a.ordering - b.ordering;\n }\n return a.id - b.id;\n });\n\n const pendingTodos = sortedTodos.filter((t) => t.status === 'pending');\n const inProgressTodos = sortedTodos.filter((t) => t.status === 'in_progress');\n\n const todoLines: string[] = ['<pending_tasks>'];\n\n if (inProgressTodos.length > 0) {\n todoLines.push('In Progress:');\n inProgressTodos.forEach((t) => todoLines.push(` - [${t.id}] ${t.activeForm}`));\n }\n\n if (pendingTodos.length > 0) {\n todoLines.push('Pending:');\n pendingTodos.forEach((t) => todoLines.push(` - [${t.id}] ${t.content}`));\n }\n\n todoLines.push('</pending_tasks>');\n\n return todoLines.join('\\n');\n}\n"
7
- ],
8
- "mappings": "+dAQA,oBCEO,GAAS,LAAgB,LAAC,JAAuB,LAEtD,FAAM,JAAc,JAAM,CAAO,LAAC,FAAM,EAAE,SAAW,aAAe,EAAE,SAAW,SAAS,EAG1F,GAAI,EAAY,SAAW,EACzB,MAAO,4EAIT,IA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iBAAiB,MAAQ,EAAM,MAAM,QAAU,OAAO,EAAM,KAAK,CAChF,EACA,UAEG,aACH,KAAM,CACJ,KAAM,aACN,WAAY,EAAM,WAClB,SAAU,EAAM,SAChB,MAAO,EAAM,iBAAiB,MAAQ,EAAM,MAAM,QAAU,OAAO,EAAM,KAAK,CAChF,EACA,UAEG,QACH,KAAM,CACJ,KAAM,QACN,MAAO,gBACT,EACA,cAGA,MAKN,GAAI,EAAc,CAChB,IAAM,EAAqB,CACzB,aAAc,MAAM,EACpB,MAAO,CACL,cAAe,MAAM,GAAO,aAAe,EAC3C,kBAAmB,MAAM,GAAO,cAAgB,EAChD,aAAc,MAAM,GAAO,aAAe,CAC5C,EACA,QAAS,MAAM,CACjB,EACA,EAAa,CAAQ,EAIvB,IAAM,GAAoB,MAAM,GAAU,SAE1C,QAAW,KAAO,EAEhB,GAAI,EAAI,OAAS,QAAU,EACzB,EAAe,KAAK,IACf,EACH,QAAS,EAAI,QAAQ,IAAI,CAAC,KAAU,IAC/B,EACH,OAAQ,EAAsB,EAAK,OAAQ,EAAK,QAAQ,CAC1D,EAAE,CACJ,CAAC,EAED,OAAe,KAAK,CAAG,EAI3B,IAAM,EAAsB,MAAM,EAUlC,GAPA,KAAM,CACJ,KAAM,WACN,aACA,aAAc,CAChB,EAGI,IAAwB,aAE1B,MAGF",
9
- "debugId": "9A0CBF72C3074EE364756E2164756E21",
10
- "names": []
11
- }
@@ -1,3 +0,0 @@
1
- import{aa as V}from"./chunk-8ep9gk6d.js";import{ba as U}from"./chunk-f676awyz.js";import{Sb as R}from"./chunk-f9yb2zk3.js";var E=R((M,Q)=>{var{defineProperty:K,getOwnPropertyDescriptor:W,getOwnPropertyNames:X}=Object,Y=Object.prototype.hasOwnProperty,Z=(q,v)=>{for(var z in v)K(q,z,{get:v[z],enumerable:!0})},$=(q,v,z,F)=>{if(v&&typeof v==="object"||typeof v==="function"){for(let G of X(v))if(!Y.call(q,G)&&G!==z)K(q,G,{get:()=>v[G],enumerable:!(F=W(v,G))||F.enumerable})}return q},A=(q)=>$(K({},"__esModule",{value:!0}),q),L={};Z(L,{refreshToken:()=>D});Q.exports=A(L);var H=U(),B=V();async function D(){let{projectId:q,teamId:v}=(0,B.findProjectInfo)(),z=(0,B.loadToken)(q);if(!z||(0,B.isExpired)((0,B.getTokenPayload)(z.token))){let F=(0,B.getVercelCliToken)();if(!F)throw new H.VercelOidcTokenError("Failed to refresh OIDC token: login to vercel cli");if(!q)throw new H.VercelOidcTokenError("Failed to refresh OIDC token: project id not found");if(z=await(0,B.getVercelOidcToken)(F,q,v),!z)throw new H.VercelOidcTokenError("Failed to refresh OIDC token");(0,B.saveToken)(z,q)}process.env.VERCEL_OIDC_TOKEN=z.token;return}});export default E();
2
-
3
- //# debugId=BEA32655A2D5EDDC64756E2164756E21
@@ -1,6 +0,0 @@
1
- import{_}from"./chunk-372bgp30.js";import{Rb as Z}from"./chunk-f9yb2zk3.js";var W=Z(_(),1);import{readFile as $,readdir as z,access as C}from"node:fs/promises";import{join as U,parse as G,relative as B}from"node:path";import{homedir as D}from"node:os";async function v(k,q=!1,x){try{let H=await $(k,"utf-8"),{data:N,content:K}=W.default(H);if(!N.name||typeof N.name!=="string")return console.error(`Rule file ${k} missing required 'name' field`),null;let O={name:N.name,description:N.description||"",enabled:N.enabled!==void 0?Boolean(N.enabled):!0};return{id:x||G(k).name,metadata:O,content:K.trim(),isBuiltin:q,filePath:k}}catch(H){return console.error(`Failed to load rule from ${k}:`,H),null}}async function V(k,q=!1){try{let H=(await z(k,{recursive:!0,withFileTypes:!0})).filter((K)=>K.isFile()&&K.name.endsWith(".md")).map((K)=>{let O=U(K.parentPath||K.path,K.name),T=B(k,O).replace(/\.md$/,"");return{fullPath:O,ruleId:T}});return(await Promise.all(H.map(({fullPath:K,ruleId:O})=>v(K,q,O)))).filter((K)=>K!==null)}catch(x){return[]}}async function F(){let k=new URL(".",import.meta.url).pathname,q=U(k,"..","assets","rules"),x=U(k,"..","..","assets","rules");try{return await C(q),q}catch{return x}}function M(k){let q=U(D(),".sylphx-flow","rules"),x=U(k,".sylphx-flow","rules");return[q,x]}async function X(k){let q=await F(),[x,H]=M(k),[N,K,O]=await Promise.all([V(q,!0),V(x,!1),V(H,!1)]),T=new Map;for(let Q of N)T.set(Q.id,Q);for(let Q of K)T.set(Q.id,Q);for(let Q of O)T.set(Q.id,Q);return Array.from(T.values())}var J=null,L=null;function b(k){L=k}async function y(k){let q=await X(k),x=new Map;for(let H of q)x.set(H.id,H);if(J={rules:x,cwd:k},L){let H=L();if(H.getState){if((H.getState().enabledRuleIds||[]).length===0){let K=q.filter((O)=>O.metadata.enabled!==!1).map((O)=>O.id);if(K.length>0)H.getState().setEnabledRuleIds(K)}}}}function R(){if(!J)return[];return Array.from(J.rules.values())}function I(k){if(!J)return null;return J.rules.get(k)||null}function Y(){if(L){let k=L();if(k.getState)return k.getState().enabledRuleIds||[]}return[]}function w(){if(!J)return[];return Y().map((q)=>J.rules.get(q)).filter((q)=>q!==null)}function g(k){if(!J||!J.rules.has(k))return!1;if(L){let q=L();if(q.getState){let x=q.getState().enabledRuleIds||[];if(x.includes(k))q.getState().setEnabledRuleIds(x.filter((H)=>H!==k));else q.getState().setEnabledRuleIds([...x,k]);return!0}}return!1}function f(k){if(!J||!J.rules.has(k))return!1;if(L){let q=L();if(q.getState){let x=q.getState().enabledRuleIds||[];if(!x.includes(k))q.getState().setEnabledRuleIds([...x,k]);return!0}}return!1}function P(k){if(!J||!J.rules.has(k))return!1;if(L){let q=L();if(q.getState){let x=q.getState().enabledRuleIds||[];return q.getState().setEnabledRuleIds(x.filter((H)=>H!==k)),!0}}return!1}async function c(){if(!J)return;let k=J.cwd,q=Y();if(await y(k),J&&L){let x=L();if(x.getState){let H=q.filter((N)=>J.rules.has(N));x.getState().setEnabledRuleIds(H)}}}function h(k){if(!J)return!1;let q=k.filter((x)=>J.rules.has(x));if(L){let x=L();if(x.getState)return x.getState().setEnabledRuleIds(q),!0}return!1}function p(){let k=w();if(k.length===0)return"";return k.map((q)=>q.content).join(`
2
-
3
- `)}export{g as toggleRule,b as setRuleAppStoreGetter,h as setEnabledRules,c as reloadRules,y as initializeRuleManager,I as getRuleById,p as getEnabledRulesContent,w as getEnabledRules,Y as getEnabledRuleIds,R as getAllRules,f as enableRule,P as disableRule};
4
- export{b as P,y as Q,R,g as S,p as T};
5
-
6
- //# debugId=F127EC77C11840CE64756E2164756E21
@@ -1,19 +0,0 @@
1
- import{B as Q}from"./chunk-9qzv4trv.js";import"./chunk-weshapwk.js";import"./chunk-sgafqzer.js";import"./chunk-cjy100rr.js";import"./chunk-7h737bp8.js";import"./chunk-372bgp30.js";import"./chunk-rvx8bgqk.js";import"./chunk-f676awyz.js";import"./chunk-gmmm7xpw.js";import"./chunk-51kpynby.js";import"./chunk-etqfkn4f.js";import"./chunk-cv1nhr27.js";import"./chunk-ceyg2zjg.js";import{Rb as U,Ub as V}from"./chunk-f9yb2zk3.js";function W(q){if(!q||q.trim().length===0)return"New Chat";let B=q.trim().replace(/\n+/g," "),D=50;if(B.length<=D)return B;let z=B.substring(0,D),E=z.lastIndexOf(" ");if(E>30)return z.substring(0,E)+"...";return z+"..."}async function Y(q,B,D,z,E){if(!q||q.trim().length===0)return"New Chat";try{let{getProvider:H}=await import("./chunk-mtrcdhzn.js"),J=H(B).createClient(z,D),R=Q({model:J,messages:[{role:"user",content:`You need to generate a SHORT, DESCRIPTIVE title (maximum 50 characters) for a chat conversation.
2
-
3
- User's first message: "${q}"
4
-
5
- Requirements:
6
- - Summarize the TOPIC or INTENT, don't just copy the message
7
- - Be concise and descriptive
8
- - Maximum 50 characters
9
- - Output ONLY the title, nothing else
10
-
11
- Examples:
12
- - Message: "How do I implement authentication?" → Title: "Authentication Implementation"
13
- - Message: "你好,请帮我修复这个 bug" → Title: "Bug 修复请求"
14
- - Message: "Can you help me with React hooks?" → Title: "React Hooks Help"
15
-
16
- Now generate the title:`}]}),O="";for await(let F of R)if(F.type==="text-delta"&&F.textDelta)O+=F.textDelta,E(F.textDelta);let b=O.trim();return b=b.replace(/^["'「『]+|["'」』]+$/g,""),b=b.replace(/^(Title:|标题:)\s*/i,""),b=b.replace(/\n+/g," "),b=b.trim(),b.length>50?b.substring(0,50)+"...":b}catch(H){return W(q)}}function Z(q,B){let D=q||"New Chat",z=new Date(B),E=new Date;if(z.toDateString()===E.toDateString()){let J=z.toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit"});return`${D} (${J})`}let K=z.toLocaleDateString("en-US",{month:"short",day:"numeric"});return`${D} (${K})`}export{Y as generateSessionTitleWithStreaming,W as generateSessionTitle,Z as formatSessionDisplay};
17
- export{W as v,Y as w};
18
-
19
- //# debugId=11D99B7085F3144F64756E2164756E21
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/utils/session-title.ts"],
4
- "sourcesContent": [
5
- "/**\n * Session Title Generation Utility\n * Generate concise titles from user messages\n */\n\nimport { createAIStream } from '../core/ai-sdk.js';\nimport type { ProviderId } from '../types/config.types.js';\n\n/**\n * Generate a session title from the first user message\n * Takes the first 50 characters and adds ellipsis if truncated\n */\nexport function generateSessionTitle(firstMessage: string): string {\n if (!firstMessage || firstMessage.trim().length === 0) {\n return 'New Chat';\n }\n\n // Remove leading/trailing whitespace and newlines\n const cleaned = firstMessage.trim().replace(/\\n+/g, ' ');\n\n // Truncate to 50 characters\n const maxLength = 50;\n if (cleaned.length <= maxLength) {\n return cleaned;\n }\n\n // Find last space before maxLength to avoid cutting words\n const truncated = cleaned.substring(0, maxLength);\n const lastSpace = truncated.lastIndexOf(' ');\n\n if (lastSpace > 30) {\n // If there's a space in reasonable range, cut there\n return truncated.substring(0, lastSpace) + '...';\n }\n\n // Otherwise just truncate and add ellipsis\n return truncated + '...';\n}\n\n/**\n * Generate a session title using LLM with streaming\n */\nexport async function generateSessionTitleWithStreaming(\n firstMessage: string,\n provider: ProviderId,\n modelName: string,\n providerConfig: any,\n onChunk: (chunk: string) => void\n): Promise<string> {\n if (!firstMessage || firstMessage.trim().length === 0) {\n return 'New Chat';\n }\n\n try {\n // Get the provider instance and create the model\n const { getProvider } = await import('../providers/index.js');\n const providerInstance = getProvider(provider);\n const model = providerInstance.createClient(providerConfig, modelName);\n\n const streamGenerator = createAIStream({\n model,\n messages: [\n {\n role: 'user',\n content: `You need to generate a SHORT, DESCRIPTIVE title (maximum 50 characters) for a chat conversation.\n\nUser's first message: \"${firstMessage}\"\n\nRequirements:\n- Summarize the TOPIC or INTENT, don't just copy the message\n- Be concise and descriptive\n- Maximum 50 characters\n- Output ONLY the title, nothing else\n\nExamples:\n- Message: \"How do I implement authentication?\" → Title: \"Authentication Implementation\"\n- Message: \"你好,请帮我修复这个 bug\" → Title: \"Bug 修复请求\"\n- Message: \"Can you help me with React hooks?\" → Title: \"React Hooks Help\"\n\nNow generate the title:`,\n },\n ],\n });\n\n let fullTitle = '';\n\n // Iterate the async generator and stream to UI\n for await (const chunk of streamGenerator) {\n if (chunk.type === 'text-delta' && chunk.textDelta) {\n fullTitle += chunk.textDelta;\n onChunk(chunk.textDelta);\n }\n }\n\n // Clean up title\n let cleaned = fullTitle.trim();\n cleaned = cleaned.replace(/^[\"'「『]+|[\"'」』]+$/g, ''); // Remove quotes\n cleaned = cleaned.replace(/^(Title:|标题:)\\s*/i, ''); // Remove \"Title:\" prefix\n cleaned = cleaned.replace(/\\n+/g, ' '); // Replace newlines with spaces\n cleaned = cleaned.trim();\n\n // Return truncated if needed\n return cleaned.length > 50 ? cleaned.substring(0, 50) + '...' : cleaned;\n } catch (error) {\n // Fallback to simple title generation on any error\n return generateSessionTitle(firstMessage);\n }\n}\n\n/**\n * Format session title for display with timestamp\n */\nexport function formatSessionDisplay(title: string | undefined, created: number): string {\n const displayTitle = title || 'New Chat';\n const date = new Date(created);\n const now = new Date();\n\n // Show time if today, otherwise show date\n const isToday = date.toDateString() === now.toDateString();\n\n if (isToday) {\n const timeStr = date.toLocaleTimeString('en-US', {\n hour: '2-digit',\n minute: '2-digit',\n });\n return `${displayTitle} (${timeStr})`;\n }\n\n const dateStr = date.toLocaleDateString('en-US', {\n month: 'short',\n day: 'numeric',\n });\n return `${displayTitle} (${dateStr})`;\n}\n"
6
- ],
7
- "mappings": "ufAYO,GAAS,LAAoB,LAAC,JAA8B,LACjE,HAAI,LAAC,HAAgB,JAAa,DAAK,JAAE,GAAW,JAClD,MAAO,WAIT,IAAM,EAAU,EAAa,KAAK,EAAE,QAAQ,OAAQ,GAAG,EAGjD,EAAY,GAClB,GAAI,EAAQ,QAAU,EACpB,OAAO,EAIT,IAAM,EAAY,EAAQ,UAAU,EAAG,CAAS,EAC1C,EAAY,EAAU,YAAY,GAAG,EAE3C,GAAI,EAAY,GAEd,OAAO,EAAU,UAAU,EAAG,CAAS,EAAI,MAI7C,OAAO,EAAY,MAMrB,eAAsB,CAAiC,CACrD,EACA,EACA,EACA,EACA,EACiB,CACjB,GAAI,CAAC,GAAgB,EAAa,KAAK,EAAE,SAAW,EAClD,MAAO,WAGT,GAAI,CAEF,IAAQ,eAAgB,KAAa,+BAE/B,EADmB,EAAY,CAAQ,EACd,aAAa,EAAgB,CAAS,EAE/D,EAAkB,EAAe,CACrC,QACA,SAAU,CACR,CACE,KAAM,OACN,QAAS;AAAA;AAAA,yBAEM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAcjB,CACF,CACF,CAAC,EAEG,EAAY,GAGhB,cAAiB,KAAS,EACxB,GAAI,EAAM,OAAS,cAAgB,EAAM,UACvC,GAAa,EAAM,UACnB,EAAQ,EAAM,SAAS,EAK3B,IAAI,EAAU,EAAU,KAAK,EAO7B,OANA,EAAU,EAAQ,QAAQ,qBAAqB,EAAE,EACjD,EAAU,EAAQ,QAAQ,oBAAoB,EAAE,EAChD,EAAU,EAAQ,QAAQ,OAAQ,GAAG,EACrC,EAAU,EAAQ,KAAK,EAGhB,EAAQ,OAAS,GAAK,EAAQ,UAAU,EAAG,EAAE,EA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