Skip to content

Commit bd60491

Browse files
committed
support github action
1 parent c292caf commit bd60491

File tree

4 files changed

+46
-89
lines changed

4 files changed

+46
-89
lines changed

.github/workflows/submit.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
name: "Submit to Web Store"
22
on:
33
workflow_dispatch:
4+
push:
5+
tags:
6+
- 'v*' # 当推送版本标签时自动触发
47

58
jobs:
69
build:
710
runs-on: ubuntu-latest
811
steps:
9-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1013
- name: Cache pnpm modules
1114
uses: actions/cache@v3
1215
with:
@@ -18,17 +21,24 @@ jobs:
1821
with:
1922
version: latest
2023
run_install: true
21-
- name: Use Node.js 16.x
22-
uses: actions/setup-node@v3.4.1
24+
- name: Use Node.js 18.x
25+
uses: actions/setup-node@v4
2326
with:
24-
node-version: 16.x
27+
node-version: 18.x
2528
cache: "pnpm"
2629
- name: Build the extension
2730
run: pnpm build
31+
env:
32+
# AI 配置环境变量(可选)
33+
AI_HOST: ${{ secrets.AI_HOST }}
34+
AI_MODEL: ${{ secrets.AI_MODEL }}
35+
AI_TOKEN: ${{ secrets.AI_TOKEN }}
2836
- name: Package the extension into a zip artifact
2937
run: pnpm package
3038
- name: Browser Platform Publish
3139
uses: PlasmoHQ/bpp@v3
3240
with:
3341
keys: ${{ secrets.SUBMIT_KEYS }}
3442
artifact: build/chrome-mv3-prod.zip
43+
# 可选:指定要发布的浏览器
44+
# browsers: chrome,firefox,edge

plasmo.config.ts

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,13 @@
1-
import type { PlasmoCSConfig } from "plasmo"
1+
// Plasmo 配置
2+
// 注意:Plasmo 会自动处理多浏览器构建和 manifest 配置
3+
// 大部分配置通过 package.json 中的 manifest 字段处理
24

3-
export const config: PlasmoConfig = {
4-
// 支持多浏览器构建
5-
targets: ["chrome", "firefox", "edge", "safari"],
6-
5+
export const config = {
76
// 构建时环境变量处理
7+
// 这些环境变量可以通过 GitHub Secrets 在构建时注入
88
env: {
99
AI_HOST: process.env.AI_HOST || "https://api.openai.com/v1/chat/completions",
1010
AI_MODEL: process.env.AI_MODEL || "gpt-3.5-turbo",
1111
AI_TOKEN: process.env.AI_TOKEN || ""
12-
},
13-
14-
// 构建配置
15-
build: {
16-
// 为不同浏览器生成不同的manifest
17-
manifest: {
18-
// Chrome/Edge 使用 Manifest V3
19-
chrome: {
20-
manifest_version: 3,
21-
permissions: [
22-
"tabs",
23-
"windows",
24-
"tabGroups",
25-
"activeTab",
26-
"bookmarks",
27-
"browsingData",
28-
"history",
29-
"scripting",
30-
"search",
31-
"commands",
32-
"storage",
33-
"contextMenus",
34-
"sessions",
35-
"sidePanel",
36-
"management",
37-
"downloads"
38-
],
39-
host_permissions: ["https://*/*"],
40-
web_accessible_resources: [
41-
{
42-
resources: ["*"],
43-
matches: ["<all_urls>"]
44-
}
45-
],
46-
commands: {
47-
"open-aipex": {
48-
suggested_key: {
49-
default: "Ctrl+M",
50-
mac: "Command+M"
51-
},
52-
description: "Open command menu"
53-
}
54-
}
55-
},
56-
// Firefox 使用 Manifest V2
57-
firefox: {
58-
manifest_version: 2,
59-
permissions: [
60-
"tabs",
61-
"windows",
62-
"bookmarks",
63-
"browsingData",
64-
"history",
65-
"search",
66-
"storage",
67-
"contextMenus",
68-
"sessions",
69-
"management",
70-
"downloads",
71-
"https://*/*"
72-
],
73-
commands: {
74-
"open-aipex": {
75-
suggested_key: {
76-
default: "Ctrl+M",
77-
mac: "Command+M"
78-
},
79-
description: "Open command menu"
80-
}
81-
}
82-
}
83-
}
8412
}
8513
}

src/background.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,18 @@ const ungroupAllTabs = async () => {
553553
// OpenAI chat completion helper
554554
async function chatCompletion(messages, stream = true, options = {}, messageId?: string) {
555555
const storage = new Storage()
556-
const aiHost = (await storage.get("aiHost")) || "https://api.openai.com/v1/chat/completions"
557-
const aiToken = await storage.get("aiToken")
558-
const aiModel = (await storage.get("aiModel")) || "gpt-3.5-turbo"
556+
557+
// 优先使用环境变量,如果环境变量不存在则使用存储配置,最后使用默认值
558+
const aiHost = process.env.AI_HOST ||
559+
(await storage.get("aiHost")) ||
560+
"https://api.openai.com/v1/chat/completions"
561+
562+
const aiToken = process.env.AI_TOKEN ||
563+
(await storage.get("aiToken"))
564+
565+
const aiModel = process.env.AI_MODEL ||
566+
(await storage.get("aiModel")) ||
567+
"gpt-3.5-turbo"
559568
if (!aiToken) throw new Error("No OpenAI API token set")
560569

561570
// If messages is a string (legacy support), convert to new format

src/mcp-servers/storage.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ export async function getExtensionSettings(): Promise<{
9393
aiModel: settings.aiModel,
9494
theme: settings.theme,
9595
language: settings.language,
96-
autoOrganize: settings.autoOrganize,
97-
notifications: settings.notifications
96+
autoOrganize: Boolean(settings.autoOrganize === 'true' || settings.autoOrganize),
97+
notifications: Boolean(settings.notifications === 'true' || settings.notifications)
9898
}
9999
}
100100
} catch (error: any) {
@@ -131,6 +131,7 @@ export async function updateExtensionSettings(updates: {
131131

132132
/**
133133
* Get AI configuration
134+
* 优先级:环境变量 > 存储配置 > 默认值
134135
*/
135136
export async function getAiConfig(): Promise<{
136137
success: boolean
@@ -143,9 +144,18 @@ export async function getAiConfig(): Promise<{
143144
}> {
144145
try {
145146
const storage = new Storage()
146-
const aiHost = (await storage.get("aiHost")) || "https://api.openai.com/v1/chat/completions"
147-
const aiToken = await storage.get("aiToken")
148-
const aiModel = (await storage.get("aiModel")) || "gpt-3.5-turbo"
147+
148+
// 优先使用环境变量,如果环境变量不存在则使用存储配置,最后使用默认值
149+
const aiHost = process.env.AI_HOST ||
150+
(await storage.get("aiHost")) ||
151+
"https://api.openai.com/v1/chat/completions"
152+
153+
const aiToken = process.env.AI_TOKEN ||
154+
(await storage.get("aiToken"))
155+
156+
const aiModel = process.env.AI_MODEL ||
157+
(await storage.get("aiModel")) ||
158+
"gpt-3.5-turbo"
149159

150160
return {
151161
success: true,

0 commit comments

Comments
 (0)