-
Notifications
You must be signed in to change notification settings - Fork 202
Add Atlas Cloud built-in chat provider #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
binyangzhu000-sudo
wants to merge
1
commit into
sightflow-dev:main
Choose a base branch
from
binyangzhu000-sudo:codex/add-atlascloud-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "apiVersion": 1, | ||
| "id": "atlascloud", | ||
| "name": "Atlas Cloud", | ||
| "version": "1.0.0", | ||
| "entry": "provider.bundle.js", | ||
| "moduleType": "module", | ||
| "capabilities": ["chat"], | ||
| "configSchema": { | ||
| "type": "object", | ||
| "properties": { | ||
| "apiKey": { | ||
| "type": "password", | ||
| "title": "接口密钥", | ||
| "description": "Atlas Cloud API Key,建议通过 ATLASCLOUD_API_KEY 管理。" | ||
| }, | ||
| "model": { | ||
| "type": "select", | ||
| "title": "模型名称", | ||
| "default": "qwen/qwen3.5-flash", | ||
| "enum": [ | ||
| "qwen/qwen3.5-flash", | ||
| "qwen/qwen3-vl-235b-a22b-thinking", | ||
| "google/gemini-3.5-flash", | ||
| "xai/grok-4.3" | ||
| ] | ||
| }, | ||
| "systemPrompt": { | ||
| "type": "string", | ||
| "title": "系统提示词", | ||
| "default": "" | ||
| } | ||
| }, | ||
| "required": ["apiKey"] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| /* eslint-disable @typescript-eslint/explicit-function-return-type */ | ||
| const DEFAULT_MODEL = 'qwen/qwen3.5-flash' | ||
| const DEFAULT_BASE_URL = 'https://api.atlascloud.ai/v1' | ||
| const DEFAULT_PROMPT = `你是一个桌面聊天自动回复助手。你会收到一张聊天窗口截图。 | ||
|
|
||
| ## 你的任务 | ||
| 分析截图中的聊天内容,生成合适的回复。 | ||
|
|
||
| ## 规则 | ||
| 1. 只输出回复文字,不要解释、不要添加多余内容 | ||
| 2. 防自我循环:仔细观察截图。如果最后一条消息明显是"我"发送的,必须输出 [SKIP] | ||
| 3. 如果最新消息是系统消息、群公告、红包、转账等非对话消息,输出 [SKIP] | ||
| 4. 如果无法判断是否需要回复,输出 [SKIP] | ||
| 5. 回复要自然、口语化,像真人对话` | ||
|
|
||
| export const manifest = { | ||
| id: 'atlascloud', | ||
| apiVersion: 1 | ||
| } | ||
|
|
||
| export function createProvider(context) { | ||
| const providerConfig = context && context.providerConfig ? context.providerConfig : {} | ||
|
|
||
| return { | ||
| async *run(input) { | ||
| if (!input || !input.screenshot) { | ||
| yield { type: 'skip' } | ||
| return | ||
| } | ||
|
|
||
| const apiKey = providerConfig.apiKey | ||
| if (!apiKey) { | ||
| yield { type: 'error', error: 'Atlas Cloud 缺少接口密钥' } | ||
| return | ||
| } | ||
|
|
||
| const memorySection = buildMemorySection(input.memoryCards) | ||
| yield { | ||
| type: 'thinking', | ||
| content: memorySection | ||
| ? `正在通过 Atlas Cloud 分析聊天内容(已加载 ${input.memoryCards.length} 条团队经验)...` | ||
| : '正在通过 Atlas Cloud 分析聊天内容...' | ||
| } | ||
|
|
||
| try { | ||
| const reply = await requestReply({ | ||
| screenshot: input.screenshot, | ||
| apiKey, | ||
| model: providerConfig.model || DEFAULT_MODEL, | ||
| systemPrompt: (providerConfig.systemPrompt || DEFAULT_PROMPT) + memorySection | ||
| }) | ||
|
|
||
| if (!reply || reply.trim() === '[SKIP]') { | ||
| yield { type: 'skip' } | ||
| return | ||
| } | ||
|
|
||
| yield { type: 'reply_text', content: reply.trim() } | ||
| } catch (error) { | ||
| const message = error && error.message ? error.message : String(error) | ||
| if (context && context.host && typeof context.host.log === 'function') { | ||
| context.host.log(`provider error: ${message}`) | ||
| } | ||
| yield { type: 'error', error: message || 'Atlas Cloud 调用失败' } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async function requestReply({ screenshot, apiKey, model, systemPrompt }) { | ||
| const body = { | ||
| model, | ||
| messages: [ | ||
| { role: 'system', content: systemPrompt }, | ||
| { | ||
| role: 'user', | ||
| content: [ | ||
| { type: 'image_url', image_url: { url: normalizeImageUrl(screenshot) } }, | ||
| { type: 'text', text: '请根据截图中聊天窗口的最新消息进行回复。' } | ||
| ] | ||
| } | ||
| ], | ||
| stream: false | ||
| } | ||
|
|
||
| const response = await fetch(`${DEFAULT_BASE_URL}/chat/completions`, { | ||
| method: 'POST', | ||
| headers: { | ||
| Authorization: `Bearer ${apiKey}`, | ||
| 'Content-Type': 'application/json' | ||
| }, | ||
| body: JSON.stringify(body) | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| const details = await readErrorDetails(response) | ||
| throw new Error( | ||
| `Atlas Cloud API request failed: ${response.status} ${response.statusText}${details}` | ||
| ) | ||
| } | ||
|
|
||
| const json = await response.json() | ||
| return json && json.choices && json.choices[0] && json.choices[0].message | ||
| ? json.choices[0].message.content || '' | ||
| : '' | ||
| } | ||
|
|
||
| async function readErrorDetails(response) { | ||
| try { | ||
| const text = await response.text() | ||
| return text ? ` - ${text.slice(0, 300)}` : '' | ||
| } catch { | ||
| return '' | ||
| } | ||
| } | ||
|
|
||
| function buildMemorySection(memoryCards) { | ||
| if (!Array.isArray(memoryCards) || memoryCards.length === 0) { | ||
| return '' | ||
| } | ||
| const lines = memoryCards.map((card, index) => { | ||
| const rationale = card.rationale ? `(原因:${card.rationale})` : '' | ||
| return `${index + 1}. 【${card.scenario}】${card.guidance}${rationale}` | ||
| }) | ||
| return `\n\n## 团队经验(来自工作记忆,优先遵循)\n${lines.join('\n')}` | ||
| } | ||
|
|
||
| function normalizeImageUrl(screenshot) { | ||
| const rawBase64 = stripBase64Prefix(screenshot) | ||
| if (rawBase64.startsWith('http')) { | ||
| return rawBase64 | ||
| } | ||
| return `data:image/png;base64,${rawBase64}` | ||
| } | ||
|
|
||
| function stripBase64Prefix(base64) { | ||
| const idx = String(base64).indexOf('base64,') | ||
| return idx !== -1 ? String(base64).slice(idx + 'base64,'.length) : String(base64) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢PR。这里不应该硬编码到内置代码里。menu信息应该在
manifest.json中就提供了。辛苦修改下。