mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
Initial public release
This commit is contained in:
commit
f1036a860c
289 files changed
+54589
No files matched your search
@@ -0,0 +1,72 @@
|
||||
import type { i18n as I18nType } from "i18next";
|
||||
|
||||
const STORAGE_KEY = "i18nextLng";
|
||||
|
||||
interface ChromeStorageLocal {
|
||||
get(
|
||||
keys: string | string[] | Record<string, unknown>,
|
||||
callback: (items: Record<string, unknown>) => void,
|
||||
): void;
|
||||
set(items: Record<string, unknown>, callback?: () => void): void;
|
||||
}
|
||||
|
||||
interface StorageChange {
|
||||
newValue?: unknown;
|
||||
}
|
||||
|
||||
declare const chrome:
|
||||
| {
|
||||
storage?: {
|
||||
local?: ChromeStorageLocal;
|
||||
onChanged?: {
|
||||
addListener: (
|
||||
callback: (changes: Record<string, StorageChange>, areaName: string) => void,
|
||||
) => void;
|
||||
};
|
||||
};
|
||||
}
|
||||
| undefined;
|
||||
|
||||
function getChromeLocal(): ChromeStorageLocal | undefined {
|
||||
return typeof chrome !== "undefined" ? chrome.storage?.local : undefined;
|
||||
}
|
||||
|
||||
/** Avoid page-origin localStorage; use extension storage + navigator only. */
|
||||
export function getLanguageDetectionOptions(): {
|
||||
order: string[];
|
||||
caches: string[];
|
||||
} {
|
||||
return {
|
||||
order: ["navigator"],
|
||||
caches: [],
|
||||
};
|
||||
}
|
||||
|
||||
/** Load persisted locale and keep popup/content scripts in sync via chrome.storage. */
|
||||
export function bindChromeStorageLanguageSync(i18n: I18nType): void {
|
||||
const storage = getChromeLocal();
|
||||
if (!storage) {
|
||||
return;
|
||||
}
|
||||
|
||||
storage.get(STORAGE_KEY, (items) => {
|
||||
const saved = items[STORAGE_KEY];
|
||||
if (typeof saved === "string" && saved !== i18n.language) {
|
||||
void i18n.changeLanguage(saved);
|
||||
}
|
||||
});
|
||||
|
||||
i18n.on("languageChanged", (lng) => {
|
||||
storage.set({ [STORAGE_KEY]: lng });
|
||||
});
|
||||
|
||||
chrome?.storage?.onChanged?.addListener((changes, area) => {
|
||||
if (area !== "local" || !(STORAGE_KEY in changes)) {
|
||||
return;
|
||||
}
|
||||
const next = changes[STORAGE_KEY]?.newValue;
|
||||
if (typeof next === "string" && next !== i18n.language) {
|
||||
void i18n.changeLanguage(next);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import i18n from "i18next";
|
||||
import LanguageDetector from "i18next-browser-languagedetector";
|
||||
import { initReactI18next } from "react-i18next";
|
||||
|
||||
import { bindChromeStorageLanguageSync, getLanguageDetectionOptions } from "./chrome-storage-sync";
|
||||
import enUSCommon from "./locales/en-US/common.json";
|
||||
import enUSExtension from "./locales/en-US/extension.json";
|
||||
import zhCNCommon from "./locales/zh-CN/common.json";
|
||||
import zhCNExtension from "./locales/zh-CN/extension.json";
|
||||
|
||||
const resources = {
|
||||
"zh-CN": {
|
||||
common: zhCNCommon,
|
||||
extension: zhCNExtension,
|
||||
},
|
||||
"en-US": {
|
||||
common: enUSCommon,
|
||||
extension: enUSExtension,
|
||||
},
|
||||
} as const;
|
||||
|
||||
i18n
|
||||
.use(LanguageDetector)
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
resources,
|
||||
fallbackLng: "zh-CN",
|
||||
defaultNS: "common",
|
||||
ns: ["common", "extension"],
|
||||
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
|
||||
detection: getLanguageDetectionOptions(),
|
||||
|
||||
react: {
|
||||
useSuspense: false,
|
||||
},
|
||||
});
|
||||
|
||||
bindChromeStorageLanguageSync(i18n);
|
||||
|
||||
export default i18n;
|
||||
@@ -0,0 +1,4 @@
|
||||
import i18n from "./i18n";
|
||||
import "./types";
|
||||
|
||||
export { i18n };
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"app": {
|
||||
"name": "browser-skill",
|
||||
"description": "Drive your logged-in browser from AI agents via the bsk CLI"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"popup": {
|
||||
"brandCategory": "Browser Automation",
|
||||
"brandName": "BrowserSkill",
|
||||
"stateLabel": {
|
||||
"disconnected": "Disconnected",
|
||||
"connecting": "Connecting…",
|
||||
"connected": "Connected",
|
||||
"version_skew": "Protocol mismatch",
|
||||
"disabled": "Connection off"
|
||||
},
|
||||
"stateDetail": {
|
||||
"disconnected": "Open BrowserSkill to connect.",
|
||||
"connecting": "Connecting to BrowserSkill…",
|
||||
"connected": "Ready for automation tasks.",
|
||||
"version_skew": "Some features may be unavailable."
|
||||
},
|
||||
"stateBadge": {
|
||||
"disconnected": "Standby",
|
||||
"connecting": "Igniting",
|
||||
"connected": "Ready",
|
||||
"version_skew": "Action needed",
|
||||
"disabled": "Off"
|
||||
},
|
||||
"connectionToggleTitle": "BrowserSkill connection",
|
||||
"versionSkewWarning": "Extension protocol v{{extensionProtocol}}, daemon v{{daemonProtocol}}.",
|
||||
"upgradeAvailable": "Upgradable",
|
||||
"labelTitle": "Browser alias",
|
||||
"labelDescription": "Distinguish multiple browser instances.",
|
||||
"labelPlaceholder": "e.g. Personal Chrome",
|
||||
"runtimeTitle": "Runtime",
|
||||
"daemonVersion": "daemon v{{version}}",
|
||||
"extensionVersion": "extension v{{version}}",
|
||||
"extensionVersionHint": "Extension version",
|
||||
"daemonVersionHint": "bsk version",
|
||||
"protocolVersion": "protocol v{{version}}",
|
||||
"extensionProtocol": "extension protocol v{{version}}",
|
||||
"daemonProtocol": "daemon protocol v{{version}}",
|
||||
"instanceTitle": "Instance ID",
|
||||
"instanceDescription": "Unique connection identifier for this browser",
|
||||
"copy": "Copy",
|
||||
"copied": "Copied",
|
||||
"copyInstanceId": "Copy instance ID"
|
||||
},
|
||||
"controlOverlay": {
|
||||
"status": "Agent controlling",
|
||||
"interrupt": "Interrupt",
|
||||
"interrupting": "Interrupting…"
|
||||
},
|
||||
"borrowConfirmation": {
|
||||
"title": "Allow tab borrow?",
|
||||
"titleInactive": "Agent wants to borrow a tab",
|
||||
"body": "An AI agent wants to move this tab into its workspace. You can deny or allow the borrow.",
|
||||
"targetTab": "Target tab:",
|
||||
"autoAllow": "Auto-allowing in {{count}}s",
|
||||
"deny": "Deny",
|
||||
"allow": "Allow",
|
||||
"notificationTitle": "BrowserSkill: Agent wants to borrow a tab",
|
||||
"notificationBody": "Approve or deny the borrow of \"{{tabTitle}}\" in your browser."
|
||||
},
|
||||
"helpRequest": {
|
||||
"title": "Agent needs your help",
|
||||
"noteLabel": "Optional note back to the agent",
|
||||
"notePlaceholder": "Add a note for the agent (optional)",
|
||||
"continue": "Continue",
|
||||
"cancel": "Cancel",
|
||||
"collapse": "Collapse",
|
||||
"expand": "Expand",
|
||||
"dragHandle": "Drag to move",
|
||||
"notificationTitle": "BrowserSkill: Agent needs your help"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"app": {
|
||||
"name": "browser-skill",
|
||||
"description": "通过 bsk CLI 让 AI Agent 驱动你已登录的浏览器"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"popup": {
|
||||
"brandCategory": "Browser Automation",
|
||||
"brandName": "BrowserSkill",
|
||||
"stateLabel": {
|
||||
"disconnected": "未连接",
|
||||
"connecting": "连接中…",
|
||||
"connected": "已连接",
|
||||
"version_skew": "协议不一致",
|
||||
"disabled": "连接已关闭"
|
||||
},
|
||||
"stateDetail": {
|
||||
"disconnected": "请先打开 BrowserSkill。",
|
||||
"connecting": "正在连接 BrowserSkill…",
|
||||
"connected": "可接收自动化任务。",
|
||||
"version_skew": "部分能力可能不可用。"
|
||||
},
|
||||
"stateBadge": {
|
||||
"disconnected": "Standby",
|
||||
"connecting": "Igniting",
|
||||
"connected": "Ready",
|
||||
"version_skew": "Action needed",
|
||||
"disabled": "Off"
|
||||
},
|
||||
"connectionToggleTitle": "BrowserSkill 连接",
|
||||
"versionSkewWarning": "扩展协议 v{{extensionProtocol}},daemon 协议 v{{daemonProtocol}}。",
|
||||
"upgradeAvailable": "可升级",
|
||||
"labelTitle": "浏览器别名",
|
||||
"labelDescription": "用于区分多个浏览器实例。",
|
||||
"labelPlaceholder": "例如:个人 Chrome",
|
||||
"runtimeTitle": "运行版本",
|
||||
"daemonVersion": "daemon v{{version}}",
|
||||
"extensionVersion": "扩展 v{{version}}",
|
||||
"extensionVersionHint": "扩展版本",
|
||||
"daemonVersionHint": "bsk 版本",
|
||||
"protocolVersion": "协议 v{{version}}",
|
||||
"extensionProtocol": "扩展协议 v{{version}}",
|
||||
"daemonProtocol": "daemon 协议 v{{version}}",
|
||||
"instanceTitle": "实例 ID",
|
||||
"instanceDescription": "本浏览器的唯一连接标识",
|
||||
"copy": "复制",
|
||||
"copied": "已复制",
|
||||
"copyInstanceId": "复制实例 ID"
|
||||
},
|
||||
"controlOverlay": {
|
||||
"status": "Agent 正在控制",
|
||||
"interrupt": "中断",
|
||||
"interrupting": "中断中…"
|
||||
},
|
||||
"borrowConfirmation": {
|
||||
"title": "允许借用标签页?",
|
||||
"titleInactive": "Agent 请求借用标签页",
|
||||
"body": "AI Agent 希望将此标签页移入工作区。您可以拒绝或允许借用。",
|
||||
"targetTab": "目标标签页:",
|
||||
"autoAllow": "{{count}} 秒后自动允许",
|
||||
"deny": "拒绝",
|
||||
"allow": "允许",
|
||||
"notificationTitle": "BrowserSkill:Agent 请求借用标签页",
|
||||
"notificationBody": "请在浏览器中允许或拒绝对「{{tabTitle}}」的借用。"
|
||||
},
|
||||
"helpRequest": {
|
||||
"title": "Agent 需要你的帮助",
|
||||
"noteLabel": "给 Agent 的备注(可选)",
|
||||
"notePlaceholder": "给 Agent 留言(可选)",
|
||||
"continue": "继续",
|
||||
"cancel": "取消",
|
||||
"collapse": "折叠",
|
||||
"expand": "展开",
|
||||
"dragHandle": "拖动以移动",
|
||||
"notificationTitle": "BrowserSkill:Agent 需要你的帮助"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { KeyPrefix } from "i18next";
|
||||
import {
|
||||
type FallbackNs,
|
||||
I18nextProvider,
|
||||
Trans as TransBase,
|
||||
type UseTranslationOptions,
|
||||
useTranslation as useTranslationBase,
|
||||
} from "react-i18next";
|
||||
import "./types";
|
||||
|
||||
type BrowserSkillNamespace = "common" | "extension";
|
||||
|
||||
/** Re-export with `const Ns` so `t()` keys are scoped to the namespace you pass. */
|
||||
export function useTranslation<
|
||||
const Ns extends BrowserSkillNamespace | undefined = undefined,
|
||||
const KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined,
|
||||
>(ns?: Ns, options?: UseTranslationOptions<KPrefix>) {
|
||||
return useTranslationBase(ns, options);
|
||||
}
|
||||
|
||||
export const Trans = TransBase;
|
||||
export { I18nextProvider };
|
||||
@@ -0,0 +1,13 @@
|
||||
import "i18next";
|
||||
import type zhCNCommon from "./locales/zh-CN/common.json";
|
||||
import type zhCNExtension from "./locales/zh-CN/extension.json";
|
||||
|
||||
declare module "i18next" {
|
||||
interface CustomTypeOptions {
|
||||
defaultNS: "common";
|
||||
resources: {
|
||||
common: typeof zhCNCommon;
|
||||
extension: typeof zhCNExtension;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user