Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ jobs:
git diff --exit-code -- calcit.cirru

- name: Check Calcit types
run: calcit calcit.cirru --check-only
run: calcit calcit.cirru --compat-types --check-only

- name: Check application dynamic methods
run: calcit calcit.cirru analyze dynamic-methods --max 0 --format json
run: calcit calcit.cirru --compat-types analyze dynamic-methods --max 0 --format json

- name: Check deprecated Calcit APIs
run: calcit calcit.cirru analyze deprecated --summary-only

- name: Audit provider dynamic methods
run: calcit calcit.cirru analyze dynamic-methods --deps --format json
run: calcit calcit.cirru --compat-types analyze dynamic-methods --deps --format json

- name: Check Calcit quality baseline
run: calcit calcit.cirru analyze quality --baseline config/calcit-quality.cirru

- name: Run Calcit regression tests
run: calcit calcit.cirru test --summary-only --format json
run: calcit calcit.cirru --compat-types test --summary-only --format json

- name: Build extension package
run: yarn build
Expand All @@ -74,10 +74,14 @@ jobs:
run: |
test -f extension/dist/index.html
find extension/dist/assets -maxdepth 1 -name '*.css' -print -quit | grep -q .
node --check extension/content.js
find extension/dist/assets -maxdepth 1 -name 'gemini-icon-*.png' -print -quit | grep -q .
find extension/dist/assets -maxdepth 1 -name 'axios-*.js' -print -quit | grep -q .
node --check extension/service-worker.js
node --check extension/get-selected.mjs
node -e 'const manifest = require("./extension/manifest.json"); if (manifest.manifest_version !== 3 || manifest.side_panel?.default_path !== "dist/index.html") process.exit(1)'
node -e 'const manifest = require("./extension/manifest.json"); if (manifest.manifest_version !== 3 || manifest.side_panel?.default_path !== "dist/index.html" || manifest.content_scripts || manifest.permissions.includes("tabs")) process.exit(1)'
test -z "$(grep -E 'https?://' extension/dist/index.html)"
test -z "$(grep -E 'axios-' extension/dist/index.html)"
test -z "$(grep -R 'feathericons.com' extension/dist/assets || true)"

- name: Select deployment path
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Expand Down
37 changes: 29 additions & 8 deletions calcit.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:entries $ {}
:default $ {} (:description |) (:init-fn 'app.main/main!) (:mode :js) (:reload-fn 'app.main/reload!)
:feature-policy $ {}
:modules $ [] |respo.calcit/ |respo-ui.calcit/ |reel.calcit/ |respo-markdown.calcit/ |alerts.calcit/ |respo-feather.calcit/
:modules $ [] |respo.calcit/ |respo-ui.calcit/ |reel.calcit/ |respo-markdown.calcit/ |alerts.calcit/
:type-slots $ {}
:files $ {}
'app.comp.container $ %{} 'FileEntry
Expand Down Expand Up @@ -83,6 +83,7 @@
:code $ quote
defn call-anthropic-msg! (cursor state prompt-text model thinking? d!)
hint-fn $ {} (:async true)
:args $ [] 'List 'app.schema/ChatState 'String 'String 'Bool 'Dynamic
let
abort $ deref *abort-control
when (js-present-dynamic? abort)
Expand All @@ -91,9 +92,12 @@
do (js/console.warn |Aborting-prev) (.!abort abort-controller)
d! $ :: :change-model
let
axios $ unsafe-coerce
.-default $ js-await (js/import |axios)
, 'Dynamic
selected $ let
selected0 $ js-await (get-selected)
if (js-present? selected0) (unsafe-coerce selected0 'String) "|<未找到内容>"
if (js-present? selected0) (stream-text selected0) "|<未找到内容>"
content $ .replace prompt-text |{{selected}} selected
messages0 $ append-user-message (:messages state) content
messages1 $ upsert-assistant-message messages0 | |
Expand Down Expand Up @@ -275,6 +279,7 @@
:code $ quote
defn call-genai-msg! (variant cursor state prompt-text search? think? d! *text *thinking-text)
hint-fn $ {} (:async true)
:args $ [] 'Tag 'List 'app.schema/ChatState 'String 'Bool 'Bool 'Dynamic 'Ref 'Ref
if (= false @*gen-ai-new)
let
mod $ js-await (js/import |@google/genai)
Expand Down Expand Up @@ -434,6 +439,7 @@
:code $ quote
defn call-openrouter! (cursor state prompt-text variant thinking? d! *text)
hint-fn $ {} (:async true)
:args $ [] 'List 'app.schema/ChatState 'String 'String 'Bool 'Dynamic 'Ref
if (= false @*openai)
let
mod $ js-await (js/import |openai)
Expand Down Expand Up @@ -801,7 +807,7 @@
:on-click $ fn (e d!) (.show sessions-plugin d!) &unit
div
{} $ :class-name style-history-button
comp-i |clock
comp-local-icon :clock 14
=< 4 nil
if
> (count sessions) 0
Expand Down Expand Up @@ -933,7 +939,7 @@
if dev? $ comp-inspect |Store app-store nil
:examples $ []
:schema $ :: 'Fn
{} (:return 'Dynamic)
{} (:return 'respo.schema/Component)
:args $ [] (:: 'Map 'Tag 'Dynamic)
:features $ #{} :js-ffi
'comp-fill $ %{} 'CodeEntry (:doc |)
Expand All @@ -945,9 +951,22 @@
when chrome-extension? $ js/chrome.runtime.sendMessage
js-object (:action |fill-text) (:text text)
, &unit
comp-i :send 12 :currentColor
comp-local-icon :send 12
:examples $ []
:schema $ :: 'Dynamic
'comp-local-icon $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-local-icon (icon size)
span $ {} (:aria-hidden |true)
:style $ {} (:display :inline-flex) (:align-items :center) (:justify-content :center)
:width $ str size |px
:height $ str size |px
:line-height |0
:innerHTML $ case-default icon | (:clock "|<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"12\" cy=\"12\" r=\"10\"></circle><polyline points=\"12 6 12 12 16 14\"></polyline></svg>") (:send "|<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><line x1=\"22\" y1=\"2\" x2=\"11\" y2=\"13\"></line><polygon points=\"22 2 15 22 11 13 2 9 22 2\"></polygon></svg>")
:examples $ []
:schema $ :: 'Fn
{} (:return 'respo.schema/Component)
:args $ [] 'Tag 'Number
'comp-message-box $ %{} 'CodeEntry (:doc |)
:code $ quote
defcomp comp-message-box (states picker-el on-submit model)
Expand Down Expand Up @@ -1921,6 +1940,7 @@
:code $ quote
defn submit-message! (cursor state prompt-text search? think? model d!)
hint-fn $ {} (:async true)
:args $ [] 'List 'app.schema/ChatState 'String 'Bool 'Bool 'Tag 'Dynamic
let
state1 $ unsafe-coerce
assoc state :messages $ append-user-message (:messages state) prompt-text
Expand Down Expand Up @@ -2033,13 +2053,11 @@
respo.comp.inspect :refer $ comp-inspect
reel.comp.reel :refer $ comp-reel
app.config :refer $ dev? chrome-extension? site
|axios :default axios
respo-md.comp.md :refer $ comp-md-block style-code-block
respo-ui.comp :refer $ comp-copy style-close
|../extension/get-selected :refer $ get-selected
|../lib/db :refer $ db-get db-set
|../lib/image :refer $ base64ToBlob
feather.core :refer $ comp-i
respo-alerts.core :refer $ [] use-modal-menu use-prompt use-drawer use-alert
respo-ui.util :refer $ tab-echo!
app.schema :refer $ Store ChatState ChatSession ChatMessage MessageBoxState store
Expand Down Expand Up @@ -2276,7 +2294,10 @@
, t_start
, |ms
:examples $ []
:schema $ :: 'Dynamic
:schema $ :: 'Fn
{} (:return 'Unit)
:args $ []
:features $ #{} :js-ffi
'sync-gemini-key! $ %{} 'CodeEntry (:doc |)
:code $ quote
defn sync-gemini-key! () $ when config/chrome-extension?
Expand Down
3 changes: 1 addition & 2 deletions deps.cirru
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

{} (:calcit-version |0.13.77)
{} (:calcit-version |0.14.4)
:version |0.0.6
:dependencies $ {} (|Respo/alerts.calcit |0.10.30)
|Respo/reel.calcit |0.6.19
|Respo/respo-feather.calcit |0.4.11
|Respo/respo-markdown.calcit |0.4.33
|Respo/respo-ui.calcit |0.7.19
|Respo/respo.calcit |0.16.95
61 changes: 0 additions & 61 deletions extension/content.js

This file was deleted.

73 changes: 22 additions & 51 deletions extension/get-selected.mjs
Original file line number Diff line number Diff line change
@@ -1,53 +1,24 @@
export let get_selected = () => {
return new Promise((resolve, reject) => {
if (window.chrome?.runtime?.id == null) {
resolve(null);
return;
}
console.log("calling content script...");
window.chrome.tabs
.query({ active: true, currentWindow: true })
.then((x) => {
let activeTab = x[0];
if (activeTab) {
let id = activeTab.id;
window.chrome.tabs.sendMessage(id, { get: "selected" }, function (response) {
// 接收来自 content.js 的返回数据
// console.info('Content script returned: ' + response);
resolve(response);
});
} else {
reject("found not active tab");
}
})
.catch((error) => {
console.error("Error", error);
});
});
};

// setTimeout(()=>{
// chrome.tabs.query({active: true, currentWindow: true}).then(x => {
// let activeTab = x[0]
// if (activeTab) {
// let id = activeTab.id
// chrome.tabs.sendMessage(id, {get: 'selected'}, function(response) {
// // 接收来自 content.js 的返回数据
// console.info('Content script returned: ' + response);
// });
export let get_selected = async () => {
if (window.chrome?.runtime?.id == null) {
return null;
}

// } else {
// throw Error("no active tab found")
// }
// })
// }, 2000)

// chrome.scripting.executeScript({
// target: { tabId: 1201634844 },
// function: () => { console.log(document.body.innerText) }
// });
try {
let [activeTab] = await window.chrome.tabs.query({
active: true,
currentWindow: true,
});
if (activeTab?.id == null) {
return null;
}

// chrome.tabs.sendMessage(1201634844, {get: 'selected'}, function(response) {
// // 接收来自 content.js 的返回数据
// console.info('Content script returned: ' + response.message);
// });
let results = await window.chrome.scripting.executeScript({
target: { tabId: activeTab.id },
func: () => window.getSelection?.().toString() ?? "",
});
return results[0]?.result ?? "";
} catch (error) {
console.warn("Unable to read selection from the active tab", error);
return null;
}
};
9 changes: 1 addition & 8 deletions extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
"icons": {
"128": "gemini-icon.png"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"match_origin_as_fallback": true,
"js": ["content.js"]
}
],
"side_panel": {
"default_path": "dist/index.html"
},
Expand All @@ -29,5 +22,5 @@
}
}
},
"permissions": ["sidePanel", "scripting", "activeTab", "tabs", "contextMenus", "storage"]
"permissions": ["sidePanel", "scripting", "activeTab", "contextMenus", "storage"]
}
Loading