mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
316ddf284d | ||
|
|
5fc96c9007 | ||
|
|
9352b70df8 | ||
|
|
b4cfc1a5ee | ||
|
|
a07368b190 | ||
|
|
66bfb56694 | ||
|
|
3cb7a8f673 | ||
|
|
6edc623c13 | ||
|
|
027cd819f8 | ||
|
|
ef55e80c35 | ||
|
|
3666aac2a1 | ||
|
|
f58f75ae8b |
No files matched your search
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://opencode.ai/config.json",
|
||||||
|
"mcp": {
|
||||||
|
"nostr": {
|
||||||
|
"type": "local",
|
||||||
|
"command": ["npx", "-y", "@nostrbook/mcp@latest"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+11
-53
@@ -195,7 +195,6 @@
|
|||||||
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
|
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/code-frame": "^7.27.1",
|
"@babel/code-frame": "^7.27.1",
|
||||||
"@babel/generator": "^7.28.5",
|
"@babel/generator": "^7.28.5",
|
||||||
@@ -1831,7 +1830,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
},
|
},
|
||||||
@@ -1855,7 +1853,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -1877,7 +1874,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@dnd-kit/core/-/core-6.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/@dnd-kit/core/-/core-6.3.1.tgz",
|
||||||
"integrity": "sha512-xkGBRQQab4RLwgXxoqETICr6S5JlogafbhNsidmrkVv2YRs5MLwpjoF2qpiGjQt8S9AoxtIV603s0GIUpY5eYQ==",
|
"integrity": "sha512-xkGBRQQab4RLwgXxoqETICr6S5JlogafbhNsidmrkVv2YRs5MLwpjoF2qpiGjQt8S9AoxtIV603s0GIUpY5eYQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dnd-kit/accessibility": "^3.1.1",
|
"@dnd-kit/accessibility": "^3.1.1",
|
||||||
"@dnd-kit/utilities": "^3.2.2",
|
"@dnd-kit/utilities": "^3.2.2",
|
||||||
@@ -4492,7 +4488,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm"
|
"arm"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4506,7 +4501,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4520,7 +4514,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4534,7 +4527,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4548,7 +4540,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4562,7 +4553,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4576,7 +4566,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm"
|
"arm"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4590,7 +4579,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm"
|
"arm"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4604,7 +4592,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4618,7 +4605,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4632,7 +4618,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"loong64"
|
"loong64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4646,7 +4631,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"ppc64"
|
"ppc64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4660,7 +4644,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"riscv64"
|
"riscv64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4674,7 +4657,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"riscv64"
|
"riscv64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4688,7 +4670,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"s390x"
|
"s390x"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4702,7 +4683,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4716,7 +4696,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4730,7 +4709,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4744,7 +4722,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"ia32"
|
"ia32"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -4758,7 +4735,6 @@
|
|||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -5446,7 +5422,8 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz",
|
||||||
"integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==",
|
"integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT",
|
||||||
|
"peer": true
|
||||||
},
|
},
|
||||||
"node_modules/@types/chrome": {
|
"node_modules/@types/chrome": {
|
||||||
"version": "0.0.74",
|
"version": "0.0.74",
|
||||||
@@ -5658,7 +5635,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.20.tgz",
|
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.20.tgz",
|
||||||
"integrity": "sha512-IPaCZN7PShZK/3t6Q87pfTkRm6oLTd4vztyoj+cbHUF1g3FfVb2tFIL79uCRKEfv16AhqDMBywP2VW3KIZUvcg==",
|
"integrity": "sha512-IPaCZN7PShZK/3t6Q87pfTkRm6oLTd4vztyoj+cbHUF1g3FfVb2tFIL79uCRKEfv16AhqDMBywP2VW3KIZUvcg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/prop-types": "*",
|
"@types/prop-types": "*",
|
||||||
"csstype": "^3.0.2"
|
"csstype": "^3.0.2"
|
||||||
@@ -5670,7 +5646,6 @@
|
|||||||
"integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==",
|
"integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==",
|
||||||
"devOptional": true,
|
"devOptional": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@types/react": "^18.0.0"
|
"@types/react": "^18.0.0"
|
||||||
}
|
}
|
||||||
@@ -5754,7 +5729,6 @@
|
|||||||
"integrity": "sha512-oU/OtYVydhXnumd0BobL9rkJg7wFJ9bFFPmSmB/bf/XWN85hlViji59ko6bSKBXyseT9V8l+CN1nwmlbiN0G7Q==",
|
"integrity": "sha512-oU/OtYVydhXnumd0BobL9rkJg7wFJ9bFFPmSmB/bf/XWN85hlViji59ko6bSKBXyseT9V8l+CN1nwmlbiN0G7Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@typescript-eslint/scope-manager": "8.31.1",
|
"@typescript-eslint/scope-manager": "8.31.1",
|
||||||
"@typescript-eslint/types": "8.31.1",
|
"@typescript-eslint/types": "8.31.1",
|
||||||
@@ -6114,7 +6088,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
|
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
|
||||||
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
|
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"acorn": "bin/acorn"
|
"acorn": "bin/acorn"
|
||||||
},
|
},
|
||||||
@@ -6629,7 +6602,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"baseline-browser-mapping": "^2.8.19",
|
"baseline-browser-mapping": "^2.8.19",
|
||||||
"caniuse-lite": "^1.0.30001751",
|
"caniuse-lite": "^1.0.30001751",
|
||||||
@@ -6859,7 +6831,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
||||||
"integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==",
|
"integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"anymatch": "~3.1.2",
|
"anymatch": "~3.1.2",
|
||||||
"braces": "~3.0.2",
|
"braces": "~3.0.2",
|
||||||
@@ -7619,7 +7590,8 @@
|
|||||||
"resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz",
|
"resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz",
|
||||||
"integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==",
|
"integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT",
|
||||||
|
"peer": true
|
||||||
},
|
},
|
||||||
"node_modules/dom-helpers": {
|
"node_modules/dom-helpers": {
|
||||||
"version": "5.2.1",
|
"version": "5.2.1",
|
||||||
@@ -7684,8 +7656,7 @@
|
|||||||
"version": "8.6.0",
|
"version": "8.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/embla-carousel/-/embla-carousel-8.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/embla-carousel/-/embla-carousel-8.6.0.tgz",
|
||||||
"integrity": "sha512-SjWyZBHJPbqxHOzckOfo8lHisEaJWmwd23XppYFYVh10bU66/Pn5tkVkbkCMZVdbUE5eTCI2nD8OyIP4Z+uwkA==",
|
"integrity": "sha512-SjWyZBHJPbqxHOzckOfo8lHisEaJWmwd23XppYFYVh10bU66/Pn5tkVkbkCMZVdbUE5eTCI2nD8OyIP4Z+uwkA==",
|
||||||
"license": "MIT",
|
"license": "MIT"
|
||||||
"peer": true
|
|
||||||
},
|
},
|
||||||
"node_modules/embla-carousel-react": {
|
"node_modules/embla-carousel-react": {
|
||||||
"version": "8.6.0",
|
"version": "8.6.0",
|
||||||
@@ -7971,7 +7942,6 @@
|
|||||||
"integrity": "sha512-QldCVh/ztyKJJZLr4jXNUByx3gR+TDYZCRXEktiZoUR3PGy4qCmSbkxcIle8GEwGpb5JBZazlaJ/CxLidXdEbQ==",
|
"integrity": "sha512-QldCVh/ztyKJJZLr4jXNUByx3gR+TDYZCRXEktiZoUR3PGy4qCmSbkxcIle8GEwGpb5JBZazlaJ/CxLidXdEbQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@eslint-community/eslint-utils": "^4.2.0",
|
"@eslint-community/eslint-utils": "^4.2.0",
|
||||||
"@eslint-community/regexpp": "^4.12.1",
|
"@eslint-community/regexpp": "^4.12.1",
|
||||||
@@ -8237,7 +8207,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz",
|
||||||
"integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==",
|
"integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"accepts": "^2.0.0",
|
"accepts": "^2.0.0",
|
||||||
"body-parser": "^2.2.0",
|
"body-parser": "^2.2.0",
|
||||||
@@ -9335,7 +9304,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.27.6"
|
"@babel/runtime": "^7.27.6"
|
||||||
},
|
},
|
||||||
@@ -10129,7 +10097,6 @@
|
|||||||
"integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==",
|
"integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cssstyle": "^4.2.1",
|
"cssstyle": "^4.2.1",
|
||||||
"data-urls": "^5.0.0",
|
"data-urls": "^5.0.0",
|
||||||
@@ -10514,6 +10481,7 @@
|
|||||||
"integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==",
|
"integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"lz-string": "bin/bin.js"
|
"lz-string": "bin/bin.js"
|
||||||
}
|
}
|
||||||
@@ -12267,7 +12235,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nanoid": "^3.3.8",
|
"nanoid": "^3.3.8",
|
||||||
"picocolors": "^1.1.1",
|
"picocolors": "^1.1.1",
|
||||||
@@ -12435,6 +12402,7 @@
|
|||||||
"integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==",
|
"integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ansi-regex": "^5.0.1",
|
"ansi-regex": "^5.0.1",
|
||||||
"ansi-styles": "^5.0.0",
|
"ansi-styles": "^5.0.0",
|
||||||
@@ -12450,6 +12418,7 @@
|
|||||||
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
@@ -12460,6 +12429,7 @@
|
|||||||
"integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
|
"integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
},
|
},
|
||||||
@@ -12472,7 +12442,8 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
|
||||||
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
|
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT",
|
||||||
|
"peer": true
|
||||||
},
|
},
|
||||||
"node_modules/prismjs": {
|
"node_modules/prismjs": {
|
||||||
"version": "1.30.0",
|
"version": "1.30.0",
|
||||||
@@ -12646,7 +12617,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
|
||||||
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
|
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"loose-envify": "^1.1.0"
|
"loose-envify": "^1.1.0"
|
||||||
},
|
},
|
||||||
@@ -12673,7 +12643,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",
|
||||||
"integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",
|
"integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"loose-envify": "^1.1.0",
|
"loose-envify": "^1.1.0",
|
||||||
"scheduler": "^0.23.2"
|
"scheduler": "^0.23.2"
|
||||||
@@ -12699,7 +12668,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.56.1.tgz",
|
"resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.56.1.tgz",
|
||||||
"integrity": "sha512-qWAVokhSpshhcEuQDSANHx3jiAEFzu2HAaaQIzi/r9FNPm1ioAvuJSD4EuZzWd7Al7nTRKcKPnBKO7sRn+zavQ==",
|
"integrity": "sha512-qWAVokhSpshhcEuQDSANHx3jiAEFzu2HAaaQIzi/r9FNPm1ioAvuJSD4EuZzWd7Al7nTRKcKPnBKO7sRn+zavQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0.0"
|
"node": ">=18.0.0"
|
||||||
},
|
},
|
||||||
@@ -12748,7 +12716,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react-markdown/-/react-markdown-10.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-markdown/-/react-markdown-10.1.0.tgz",
|
||||||
"integrity": "sha512-qKxVopLT/TyA6BX3Ue5NwabOsAzm0Q7kAPwq6L+wWDwisYs7R8vZ0nRXqq6rkueboxpkjvLGU9fWifiX/ZZFxQ==",
|
"integrity": "sha512-qKxVopLT/TyA6BX3Ue5NwabOsAzm0Q7kAPwq6L+wWDwisYs7R8vZ0nRXqq6rkueboxpkjvLGU9fWifiX/ZZFxQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/hast": "^3.0.0",
|
"@types/hast": "^3.0.0",
|
||||||
"@types/mdast": "^4.0.0",
|
"@types/mdast": "^4.0.0",
|
||||||
@@ -13291,7 +13258,6 @@
|
|||||||
"integrity": "sha512-C5VvvgCCyfyotVITIAv+4efVytl5F7wt+/I2i9q9GZcEXW9BP52YYOXC58igUi+LFZVHukErIIqQSWwv/M3WRw==",
|
"integrity": "sha512-C5VvvgCCyfyotVITIAv+4efVytl5F7wt+/I2i9q9GZcEXW9BP52YYOXC58igUi+LFZVHukErIIqQSWwv/M3WRw==",
|
||||||
"devOptional": true,
|
"devOptional": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/estree": "1.0.7"
|
"@types/estree": "1.0.7"
|
||||||
},
|
},
|
||||||
@@ -14346,7 +14312,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.17.tgz",
|
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.17.tgz",
|
||||||
"integrity": "sha512-w33E2aCvSDP0tW9RZuNXadXlkHXqFzSkQew/aIa2i/Sj8fThxwovwlXHSPXTbAHwEIhBFXAedUhP2tueAKP8Og==",
|
"integrity": "sha512-w33E2aCvSDP0tW9RZuNXadXlkHXqFzSkQew/aIa2i/Sj8fThxwovwlXHSPXTbAHwEIhBFXAedUhP2tueAKP8Og==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alloc/quick-lru": "^5.2.0",
|
"@alloc/quick-lru": "^5.2.0",
|
||||||
"arg": "^5.0.2",
|
"arg": "^5.0.2",
|
||||||
@@ -14550,7 +14515,6 @@
|
|||||||
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
|
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
},
|
},
|
||||||
@@ -14846,7 +14810,6 @@
|
|||||||
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
|
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
|
||||||
"devOptional": true,
|
"devOptional": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
"tsserver": "bin/tsserver"
|
"tsserver": "bin/tsserver"
|
||||||
@@ -15374,7 +15337,6 @@
|
|||||||
"integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==",
|
"integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"esbuild": "^0.25.0",
|
"esbuild": "^0.25.0",
|
||||||
"fdir": "^6.4.4",
|
"fdir": "^6.4.4",
|
||||||
@@ -15519,7 +15481,6 @@
|
|||||||
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
|
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
},
|
},
|
||||||
@@ -15991,7 +15952,6 @@
|
|||||||
"integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
|
"integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
"fast-uri": "^3.0.1",
|
"fast-uri": "^3.0.1",
|
||||||
@@ -16068,7 +16028,6 @@
|
|||||||
"integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==",
|
"integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"rollup": "dist/bin/rollup"
|
"rollup": "dist/bin/rollup"
|
||||||
},
|
},
|
||||||
@@ -16517,7 +16476,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
|
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
|
||||||
"integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
|
"integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/colinhacks"
|
"url": "https://github.com/sponsors/colinhacks"
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -28,7 +28,6 @@ import { DynamicFavicon } from '@/components/DynamicFavicon';
|
|||||||
import { OfflineIndicator } from '@/components/OfflineIndicator';
|
import { OfflineIndicator } from '@/components/OfflineIndicator';
|
||||||
import { PWAUpdatePrompt } from '@/components/PWAUpdatePrompt';
|
import { PWAUpdatePrompt } from '@/components/PWAUpdatePrompt';
|
||||||
import { ErrorBoundary } from '@/components/ErrorBoundary';
|
import { ErrorBoundary } from '@/components/ErrorBoundary';
|
||||||
import { BadgeAwardNotification } from '@/components/BadgeAwardNotification';
|
|
||||||
|
|
||||||
import AppRouter from './AppRouter';
|
import AppRouter from './AppRouter';
|
||||||
|
|
||||||
@@ -153,7 +152,6 @@ export function App() {
|
|||||||
<DynamicFavicon />
|
<DynamicFavicon />
|
||||||
<OfflineIndicator />
|
<OfflineIndicator />
|
||||||
<PWAUpdatePrompt />
|
<PWAUpdatePrompt />
|
||||||
<BadgeAwardNotification />
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<AppRouter />
|
<AppRouter />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import DeploySettings from "./pages/DeploySettings";
|
|||||||
import SystemSettings from "./pages/SystemSettings";
|
import SystemSettings from "./pages/SystemSettings";
|
||||||
import StorageSettings from "./pages/StorageSettings";
|
import StorageSettings from "./pages/StorageSettings";
|
||||||
import AboutSettings from "./pages/AboutSettings";
|
import AboutSettings from "./pages/AboutSettings";
|
||||||
import BadgesSettings from "./pages/BadgesSettings";
|
|
||||||
|
|
||||||
import GitHubOAuth from "./pages/GitHubOAuth";
|
import GitHubOAuth from "./pages/GitHubOAuth";
|
||||||
import NetlifyOAuth from "./pages/NetlifyOAuth";
|
import NetlifyOAuth from "./pages/NetlifyOAuth";
|
||||||
@@ -52,7 +51,6 @@ export function AppRouter() {
|
|||||||
<Route path="system" element={<SystemSettings />} />
|
<Route path="system" element={<SystemSettings />} />
|
||||||
<Route path="storage" element={<StorageSettings />} />
|
<Route path="storage" element={<StorageSettings />} />
|
||||||
<Route path="about" element={<AboutSettings />} />
|
<Route path="about" element={<AboutSettings />} />
|
||||||
<Route path="badges" element={<BadgesSettings />} />
|
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/project/:projectId" element={<ProjectView />} />
|
<Route path="/project/:projectId" element={<ProjectView />} />
|
||||||
{/* NIP-19 route for npub1, note1, naddr1, nevent1, nprofile1 */}
|
{/* NIP-19 route for npub1, note1, naddr1, nevent1, nprofile1 */}
|
||||||
|
|||||||
@@ -1,135 +0,0 @@
|
|||||||
import { useEffect, useRef } from 'react';
|
|
||||||
import { Dialog, DialogContent, DialogTitle, DialogDescription } from "@/components/ui/dialog";
|
|
||||||
import { Award } from "lucide-react";
|
|
||||||
import type { NostrEvent } from '@nostrify/nostrify';
|
|
||||||
import { useNostr } from '@nostrify/react';
|
|
||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
|
||||||
import { BADGE_ISSUER_PUBKEY } from '@/pages/BadgesSettings';
|
|
||||||
|
|
||||||
interface BadgeAwardModalProps {
|
|
||||||
award?: NostrEvent | null;
|
|
||||||
badgeDefinition?: NostrEvent | null;
|
|
||||||
onClose: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function BadgeAwardModal({ award, badgeDefinition: providedBadgeDefinition, onClose }: BadgeAwardModalProps) {
|
|
||||||
const { nostr } = useNostr();
|
|
||||||
const audioRef = useRef<HTMLAudioElement | null>(null);
|
|
||||||
|
|
||||||
// If we have a badge definition directly, use it
|
|
||||||
// Otherwise, extract from award event
|
|
||||||
let dTag: string | undefined;
|
|
||||||
|
|
||||||
if (providedBadgeDefinition) {
|
|
||||||
dTag = providedBadgeDefinition.tags.find(([t]) => t === "d")?.[1];
|
|
||||||
} else if (award) {
|
|
||||||
const aTag = award.tags.find(([t]) => t === "a")?.[1];
|
|
||||||
if (aTag) {
|
|
||||||
const [kindStr, pubkey, parsedDTag] = aTag.split(':');
|
|
||||||
if (kindStr === '30009' && pubkey === BADGE_ISSUER_PUBKEY && parsedDTag) {
|
|
||||||
dTag = parsedDTag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch badge definition if we don't have it directly
|
|
||||||
const { data: fetchedBadgeDefinition, isLoading } = useQuery({
|
|
||||||
queryKey: ['badge-definition', BADGE_ISSUER_PUBKEY, dTag],
|
|
||||||
queryFn: async (c) => {
|
|
||||||
if (!dTag) return null;
|
|
||||||
const signal = AbortSignal.any([c.signal, AbortSignal.timeout(5000)]);
|
|
||||||
const events = await nostr.query([{
|
|
||||||
kinds: [30009],
|
|
||||||
authors: [BADGE_ISSUER_PUBKEY],
|
|
||||||
"#d": [dTag],
|
|
||||||
limit: 1,
|
|
||||||
}], { signal });
|
|
||||||
return events[0] || null;
|
|
||||||
},
|
|
||||||
enabled: !!dTag && !providedBadgeDefinition,
|
|
||||||
});
|
|
||||||
|
|
||||||
const badgeDefinition = providedBadgeDefinition || fetchedBadgeDefinition;
|
|
||||||
const isModalOpen = !!award || !!providedBadgeDefinition;
|
|
||||||
|
|
||||||
// Play sound when badge is awarded (only when award is present, not just viewing badge definition)
|
|
||||||
useEffect(() => {
|
|
||||||
if (award && badgeDefinition && isModalOpen && !isLoading) {
|
|
||||||
// Create audio element if it doesn't exist
|
|
||||||
if (!audioRef.current) {
|
|
||||||
audioRef.current = new Audio('/badgeAwarded.mp3');
|
|
||||||
audioRef.current.volume = 0.5; // Set volume to 50%
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset to beginning and play the sound
|
|
||||||
audioRef.current.currentTime = 0;
|
|
||||||
audioRef.current.play().catch((error) => {
|
|
||||||
// Silently handle autoplay restrictions
|
|
||||||
console.debug('Audio playback failed:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [award, badgeDefinition, isModalOpen, isLoading]);
|
|
||||||
|
|
||||||
// Return null after all hooks if we don't have a badge definition
|
|
||||||
if (!badgeDefinition) return null;
|
|
||||||
|
|
||||||
const nameTag = badgeDefinition?.tags?.find(([t]) => t === "name")?.[1];
|
|
||||||
const descriptionTag = badgeDefinition?.tags?.find(([t]) => t === "description")?.[1];
|
|
||||||
const imageTag = badgeDefinition?.tags?.find(([t]) => t === "image")?.[1];
|
|
||||||
const thumbTags = badgeDefinition?.tags?.filter(([t]) => t === "thumb") || [];
|
|
||||||
|
|
||||||
const badgeName = nameTag || dTag || "Unnamed Badge";
|
|
||||||
const description = descriptionTag || "";
|
|
||||||
const imageUrl = imageTag || (thumbTags.length > 0 ? thumbTags[thumbTags.length - 1]?.[1] : null);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog open={isModalOpen} onOpenChange={(open) => !open && onClose()}>
|
|
||||||
<DialogContent className="w-[min(90vw,600px)] aspect-square bg-transparent [&>button]:hidden border-0 ring-0 outline-none shadow-none flex items-center justify-center p-[min(4vw,2rem)]">
|
|
||||||
<DialogTitle className="sr-only">
|
|
||||||
{award ? `Badge Awarded: ${badgeName}` : badgeName}
|
|
||||||
</DialogTitle>
|
|
||||||
<DialogDescription className="sr-only">
|
|
||||||
{description || `Badge: ${badgeName}`}
|
|
||||||
</DialogDescription>
|
|
||||||
<div className="flex flex-col items-center justify-center space-y-[min(4vw,2rem)] w-full h-full">
|
|
||||||
{isLoading ? (
|
|
||||||
<>
|
|
||||||
<Skeleton className="w-[min(60vw,384px)] aspect-square rounded-lg" />
|
|
||||||
<div className="space-y-2 text-center w-full">
|
|
||||||
<Skeleton className="h-[clamp(1.5rem,4vw,2rem)] w-[min(80%,16rem)] mx-auto" />
|
|
||||||
<Skeleton className="h-[clamp(1rem,3vw,1.25rem)] w-[min(90%,20rem)] mx-auto" />
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{/* Badge image */}
|
|
||||||
<div className="relative aspect-square w-[min(60vw,384px)] before:absolute before:inset-0 before:rounded-lg before:bg-white/30 before:blur-2xl before:animate-pulse before:-z-10">
|
|
||||||
{imageUrl ? (
|
|
||||||
<img
|
|
||||||
src={imageUrl}
|
|
||||||
alt={badgeName}
|
|
||||||
className="h-full w-full rounded-lg object-cover shadow-2xl"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Award className="h-full w-full text-primary drop-shadow-lg" />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Title */}
|
|
||||||
<div className="text-center space-y-[min(1vw,0.75rem)] w-full px-4">
|
|
||||||
<p className="text-[clamp(1.25rem,5vw,1.5rem)] font-semibold">{badgeName}</p>
|
|
||||||
{description && (
|
|
||||||
<p className="text-[clamp(0.875rem,3vw,1rem)] text-muted-foreground max-w-md mx-auto">
|
|
||||||
{description}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import { useBadgeAwardNotifications } from '@/hooks/useBadgeAwardNotifications';
|
|
||||||
import { BadgeAwardModal } from './BadgeAwardModal';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Global badge award notification component.
|
|
||||||
* Listens for badge awards and displays a modal when a new badge is received.
|
|
||||||
* This component should be placed at the App level to work globally.
|
|
||||||
*/
|
|
||||||
export function BadgeAwardNotification() {
|
|
||||||
const { newAward, clearNewAward } = useBadgeAwardNotifications();
|
|
||||||
|
|
||||||
return <BadgeAwardModal award={newAward} onClose={clearNewAward} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ export function ProjectTitleMenu({
|
|||||||
className="gap-2"
|
className="gap-2"
|
||||||
>
|
>
|
||||||
<MessageSquarePlus className="h-4 w-4" />
|
<MessageSquarePlus className="h-4 w-4" />
|
||||||
New Chat
|
{t('newChat')}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
/** Visual divider between chat sessions */
|
||||||
|
export function SessionDivider() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-3 text-xs text-muted-foreground py-4">
|
||||||
|
<div className="flex-1 h-px bg-border" />
|
||||||
|
<span className="uppercase tracking-wide">
|
||||||
|
{t('newChat', 'New chat')}
|
||||||
|
</span>
|
||||||
|
<div className="flex-1 h-px bg-border" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -17,8 +17,6 @@ interface SettingsPageLayoutProps {
|
|||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
/** Optional className for the content container */
|
/** Optional className for the content container */
|
||||||
className?: string;
|
className?: string;
|
||||||
/** Optional element to render next to the title */
|
|
||||||
titleSuffix?: ReactNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,8 +28,7 @@ export function SettingsPageLayout({
|
|||||||
titleKey,
|
titleKey,
|
||||||
descriptionKey,
|
descriptionKey,
|
||||||
children,
|
children,
|
||||||
className = 'space-y-6',
|
className,
|
||||||
titleSuffix,
|
|
||||||
}: SettingsPageLayoutProps) {
|
}: SettingsPageLayoutProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
@@ -51,10 +48,9 @@ export function SettingsPageLayout({
|
|||||||
{t('backToSettings')}
|
{t('backToSettings')}
|
||||||
</Button>
|
</Button>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<h1 className="text-2xl font-bold flex flex-wrap items-center gap-3">
|
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||||
<Icon className="h-6 w-6 text-primary" />
|
<Icon className="h-6 w-6 text-primary" />
|
||||||
{t(titleKey)}
|
{t(titleKey)}
|
||||||
{titleSuffix}
|
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-muted-foreground">
|
<p className="text-muted-foreground">
|
||||||
{t(descriptionKey)}
|
{t(descriptionKey)}
|
||||||
@@ -65,10 +61,9 @@ export function SettingsPageLayout({
|
|||||||
|
|
||||||
{!isMobile && (
|
{!isMobile && (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<h1 className="text-2xl font-bold flex flex-wrap items-center gap-3">
|
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||||
<Icon className="h-6 w-6 text-primary" />
|
<Icon className="h-6 w-6 text-primary" />
|
||||||
{t(titleKey)}
|
{t(titleKey)}
|
||||||
{titleSuffix}
|
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-muted-foreground">
|
<p className="text-muted-foreground">
|
||||||
{t(descriptionKey)}
|
{t(descriptionKey)}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
import { OnboardingDialog } from '@/components/OnboardingDialog';
|
import { OnboardingDialog } from '@/components/OnboardingDialog';
|
||||||
import { ChevronDown, Play } from 'lucide-react';
|
import { ChevronDown, ChevronUp, Play } from 'lucide-react';
|
||||||
import { useAISettings } from '@/hooks/useAISettings';
|
import { useAISettings } from '@/hooks/useAISettings';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
import { useFSPaths } from '@/hooks/useFSPaths';
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
@@ -47,11 +47,12 @@ import OpenAI from 'openai';
|
|||||||
import { useGit } from '@/hooks/useGit';
|
import { useGit } from '@/hooks/useGit';
|
||||||
import { Quilly } from '@/components/Quilly';
|
import { Quilly } from '@/components/Quilly';
|
||||||
import { ShakespeareLogo } from '@/components/ShakespeareLogo';
|
import { ShakespeareLogo } from '@/components/ShakespeareLogo';
|
||||||
|
import { SessionDivider } from '@/components/SessionDivider';
|
||||||
import { ChatInput } from '@/components/Shakespeare/ChatInput';
|
import { ChatInput } from '@/components/Shakespeare/ChatInput';
|
||||||
import { buildMessageContent } from '@/lib/buildMessageContent';
|
import { buildMessageContent } from '@/lib/buildMessageContent';
|
||||||
import { DotAI } from '@/lib/DotAI';
|
import { DotAI } from '@/lib/DotAI';
|
||||||
import { parseProviderModel } from '@/lib/parseProviderModel';
|
import { parseProviderModel } from '@/lib/parseProviderModel';
|
||||||
import { AIMessage } from '@/lib/SessionManager';
|
import { AIMessage, DisplayMessage } from '@/lib/SessionManager';
|
||||||
|
|
||||||
// Clean interfaces now handled by proper hooks
|
// Clean interfaces now handled by proper hooks
|
||||||
|
|
||||||
@@ -294,9 +295,13 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
messages,
|
messages,
|
||||||
|
displayMessages,
|
||||||
|
sessionName,
|
||||||
streamingMessage,
|
streamingMessage,
|
||||||
isLoading: internalIsLoading,
|
isLoading: internalIsLoading,
|
||||||
isLoadingHistory,
|
isLoadingHistory,
|
||||||
|
hasMoreHistory,
|
||||||
|
isLoadingMoreHistory,
|
||||||
totalCost,
|
totalCost,
|
||||||
lastInputTokens,
|
lastInputTokens,
|
||||||
lastFinishReason,
|
lastFinishReason,
|
||||||
@@ -305,6 +310,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
startGeneration,
|
startGeneration,
|
||||||
stopGeneration,
|
stopGeneration,
|
||||||
startNewSession: internalStartNewSession,
|
startNewSession: internalStartNewSession,
|
||||||
|
loadMoreHistory,
|
||||||
} = useAIChat({
|
} = useAIChat({
|
||||||
projectId,
|
projectId,
|
||||||
tools,
|
tools,
|
||||||
@@ -318,7 +324,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
const checkTemplateInfo = async () => {
|
const checkTemplateInfo = async () => {
|
||||||
try {
|
try {
|
||||||
// Only check if we have at least 1 message
|
// Only check if we have at least 1 message
|
||||||
if (messages.length === 0) {
|
if (displayMessages.length === 0) {
|
||||||
setShowTemplateInfo(false);
|
setShowTemplateInfo(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -357,7 +363,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
};
|
};
|
||||||
|
|
||||||
checkTemplateInfo();
|
checkTemplateInfo();
|
||||||
}, [fs, projectsPath, projectId, messages.length]);
|
}, [fs, projectsPath, projectId, displayMessages.length]);
|
||||||
|
|
||||||
// Handle console error help requests
|
// Handle console error help requests
|
||||||
const handleConsoleErrorHelp = useCallback(async () => {
|
const handleConsoleErrorHelp = useCallback(async () => {
|
||||||
@@ -436,7 +442,11 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
// Function to scroll to bottom
|
// Function to scroll to bottom
|
||||||
const scrollToBottom = useCallback(() => {
|
const scrollToBottom = useCallback(() => {
|
||||||
if (scrollAreaRef.current) {
|
if (scrollAreaRef.current) {
|
||||||
scrollAreaRef.current.scrollTop = scrollAreaRef.current.scrollHeight;
|
requestAnimationFrame(() => {
|
||||||
|
if (scrollAreaRef.current) {
|
||||||
|
scrollAreaRef.current.scrollTop = scrollAreaRef.current.scrollHeight;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -489,17 +499,20 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (scrollAreaRef.current && (messages || streamingMessage)) {
|
if (scrollAreaRef.current && (messages || streamingMessage)) {
|
||||||
// Check if user was already at or near the bottom (within 100px threshold)
|
|
||||||
const threshold = 100;
|
|
||||||
const container = scrollAreaRef.current;
|
const container = scrollAreaRef.current;
|
||||||
|
const lastMessage = messages[messages.length - 1];
|
||||||
|
const isUserMessage = lastMessage?.role === 'user';
|
||||||
|
|
||||||
|
// Check if user was already near the bottom (within 100px threshold)
|
||||||
|
const threshold = 100;
|
||||||
const isNearBottom = container.scrollTop + container.clientHeight >= container.scrollHeight - threshold;
|
const isNearBottom = container.scrollTop + container.clientHeight >= container.scrollHeight - threshold;
|
||||||
|
|
||||||
// Only auto-scroll if user was already near the bottom
|
// Scroll to bottom if user sent a message or was already near the bottom
|
||||||
if (isNearBottom) {
|
if (isUserMessage || isNearBottom) {
|
||||||
container.scrollTop = container.scrollHeight;
|
scrollToBottom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [messages, streamingMessage, isLoading]);
|
}, [messages, streamingMessage, isLoading, scrollToBottom]);
|
||||||
|
|
||||||
// Scroll to bottom when first visiting a project (including page refresh)
|
// Scroll to bottom when first visiting a project (including page refresh)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -577,8 +590,11 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
// Add model to recently used when sending a message
|
// Add model to recently used when sending a message
|
||||||
addRecentlyUsedModel(modelToUse);
|
addRecentlyUsedModel(modelToUse);
|
||||||
|
|
||||||
|
// Scroll to bottom when user sends a message
|
||||||
|
scrollToBottom();
|
||||||
|
|
||||||
await sendMessage(messageContent, modelToUse);
|
await sendMessage(messageContent, modelToUse);
|
||||||
}, [addRecentlyUsedModel, fs, isConfigured, isLoading, providerModel, sendMessage, tmpPath]);
|
}, [addRecentlyUsedModel, fs, isConfigured, isLoading, providerModel, sendMessage, tmpPath, scrollToBottom]);
|
||||||
|
|
||||||
// Handle textarea focus - show onboarding if not configured
|
// Handle textarea focus - show onboarding if not configured
|
||||||
const handleTextareaFocus = useCallback(() => {
|
const handleTextareaFocus = useCallback(() => {
|
||||||
@@ -757,7 +773,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Empty state when no messages and not loading */}
|
{/* Empty state when no messages and not loading */}
|
||||||
{!isLoadingHistory && messages.length === 0 && !streamingMessage && !isLoading && (
|
{!isLoadingHistory && displayMessages.length === 0 && !streamingMessage && !isLoading && (
|
||||||
<div className="flex-1 flex items-center justify-center min-h-[400px]">
|
<div className="flex-1 flex items-center justify-center min-h-[400px]">
|
||||||
<div className="text-center space-y-4 max-w-md mx-auto">
|
<div className="text-center space-y-4 max-w-md mx-auto">
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
@@ -781,13 +797,49 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isLoadingHistory && messages.map((message, index) => {
|
{/* Load older messages button */}
|
||||||
|
{!isLoadingHistory && hasMoreHistory && (
|
||||||
|
<div className="flex justify-center py-3">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={async () => {
|
||||||
|
const container = scrollAreaRef.current;
|
||||||
|
const oldScrollHeight = container?.scrollHeight || 0;
|
||||||
|
await loadMoreHistory();
|
||||||
|
// Preserve scroll position after prepending content
|
||||||
|
if (container) {
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
container.scrollTop += container.scrollHeight - oldScrollHeight;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={isLoadingMoreHistory}
|
||||||
|
className="gap-2 text-muted-foreground"
|
||||||
|
>
|
||||||
|
<ChevronUp className="h-4 w-4" />
|
||||||
|
{isLoadingMoreHistory ? t('loading') : t('loadOlderMessages', 'Load older messages')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isLoadingHistory && displayMessages.map((message, index) => {
|
||||||
|
// Get the current message's session ID and compare to previous
|
||||||
|
const currentSessionId = (message as DisplayMessage).sessionId;
|
||||||
|
const prevSessionId = index > 0 ? (displayMessages[index - 1] as DisplayMessage).sessionId : undefined;
|
||||||
|
|
||||||
|
// Show divider when session changes (not on first message)
|
||||||
|
const showDivider = index > 0 && currentSessionId !== prevSessionId;
|
||||||
|
|
||||||
|
// Dim messages from older sessions (compare against current active session)
|
||||||
|
const isOlderSession = currentSessionId !== sessionName;
|
||||||
|
|
||||||
// Find the corresponding tool call for tool messages
|
// Find the corresponding tool call for tool messages
|
||||||
let toolCall: OpenAI.Chat.Completions.ChatCompletionMessageToolCall | undefined = undefined;
|
let toolCall: OpenAI.Chat.Completions.ChatCompletionMessageToolCall | undefined = undefined;
|
||||||
if (message.role === 'tool') {
|
if (message.role === 'tool') {
|
||||||
// Look backwards to find the assistant message with matching tool call
|
// Look backwards to find the assistant message with matching tool call
|
||||||
for (let i = index - 1; i >= 0; i--) {
|
for (let i = index - 1; i >= 0; i--) {
|
||||||
const prevMessage = messages[i];
|
const prevMessage = displayMessages[i];
|
||||||
if (prevMessage.role === 'assistant' && 'tool_calls' in prevMessage && prevMessage.tool_calls) {
|
if (prevMessage.role === 'assistant' && 'tool_calls' in prevMessage && prevMessage.tool_calls) {
|
||||||
toolCall = prevMessage.tool_calls.find(tc => tc.id === message.tool_call_id);
|
toolCall = prevMessage.tool_calls.find(tc => tc.id === message.tool_call_id);
|
||||||
if (toolCall) break;
|
if (toolCall) break;
|
||||||
@@ -796,14 +848,27 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AIMessageItem
|
<div
|
||||||
key={`${index}-${message.role}-${typeof message.content === 'string' ? message.content.slice(0, 50) : 'content'}`}
|
key={`${index}-${message.role}-${typeof message.content === 'string' ? message.content.slice(0, 50) : 'content'}`}
|
||||||
message={message}
|
className={isOlderSession ? 'opacity-65' : ''}
|
||||||
toolCall={toolCall}
|
>
|
||||||
/>
|
{showDivider && <SessionDivider />}
|
||||||
|
<AIMessageItem
|
||||||
|
message={message}
|
||||||
|
toolCall={toolCall}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
|
{/* Trailing session divider - shown when New Chat is clicked before sending a message */}
|
||||||
|
{!isLoadingHistory && displayMessages.length > 0 && (() => {
|
||||||
|
const lastSessionId = (displayMessages[displayMessages.length - 1] as DisplayMessage).sessionId;
|
||||||
|
return sessionName && lastSessionId && sessionName !== lastSessionId ? (
|
||||||
|
<SessionDivider key="trailing-divider" />
|
||||||
|
) : null;
|
||||||
|
})()}
|
||||||
|
|
||||||
{!isLoadingHistory && renderStreamingMessage()}
|
{!isLoadingHistory && renderStreamingMessage()}
|
||||||
|
|
||||||
{/* Resume button - shown when not loading and finish reason is not "stop" or "length" (or no finish reason) */}
|
{/* Resume button - shown when not loading and finish reason is not "stop" or "length" (or no finish reason) */}
|
||||||
|
|||||||
+44
-2
@@ -2,7 +2,7 @@ import { useState, useEffect, useCallback } from 'react';
|
|||||||
import { useSessionManager } from '@/hooks/useSessionManager';
|
import { useSessionManager } from '@/hooks/useSessionManager';
|
||||||
import { useSessionSubscription } from '@/hooks/useSessionSubscription';
|
import { useSessionSubscription } from '@/hooks/useSessionSubscription';
|
||||||
import { useAISettings } from '@/hooks/useAISettings';
|
import { useAISettings } from '@/hooks/useAISettings';
|
||||||
import type { AIMessage } from '@/lib/SessionManager';
|
import type { AIMessage, DisplayMessage } from '@/lib/SessionManager';
|
||||||
import type OpenAI from 'openai';
|
import type OpenAI from 'openai';
|
||||||
import type { Tool } from '@/lib/tools/Tool';
|
import type { Tool } from '@/lib/tools/Tool';
|
||||||
|
|
||||||
@@ -39,12 +39,16 @@ export function useAIChat({
|
|||||||
|
|
||||||
// Split session state into individual variables for efficient updates
|
// Split session state into individual variables for efficient updates
|
||||||
const [messages, setMessages] = useState<AIMessage[]>([]);
|
const [messages, setMessages] = useState<AIMessage[]>([]);
|
||||||
|
const [displayMessages, setDisplayMessages] = useState<DisplayMessage[]>([]);
|
||||||
|
const [sessionName, setSessionName] = useState<string>('');
|
||||||
const [streamingMessage, setStreamingMessage] = useState<StreamingMessage | undefined>(undefined);
|
const [streamingMessage, setStreamingMessage] = useState<StreamingMessage | undefined>(undefined);
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
const [totalCost, setTotalCost] = useState<number>(0);
|
const [totalCost, setTotalCost] = useState<number>(0);
|
||||||
const [lastInputTokens, setLastInputTokens] = useState<number>(0);
|
const [lastInputTokens, setLastInputTokens] = useState<number>(0);
|
||||||
const [lastFinishReason, setLastFinishReason] = useState<string | null>(null);
|
const [lastFinishReason, setLastFinishReason] = useState<string | null>(null);
|
||||||
const [isLoadingHistory, setIsLoadingHistory] = useState<boolean>(true);
|
const [isLoadingHistory, setIsLoadingHistory] = useState<boolean>(true);
|
||||||
|
const [hasMoreHistory, setHasMoreHistory] = useState<boolean>(false);
|
||||||
|
const [isLoadingMoreHistory, setIsLoadingMoreHistory] = useState<boolean>(false);
|
||||||
|
|
||||||
const initSession = useCallback(async () => {
|
const initSession = useCallback(async () => {
|
||||||
setIsLoadingHistory(true);
|
setIsLoadingHistory(true);
|
||||||
@@ -53,11 +57,15 @@ export function useAIChat({
|
|||||||
const session = await sessionManager.loadSession(projectId, tools, customTools, maxSteps);
|
const session = await sessionManager.loadSession(projectId, tools, customTools, maxSteps);
|
||||||
// Initialize individual state variables from existing session
|
// Initialize individual state variables from existing session
|
||||||
setMessages([...session.messages]);
|
setMessages([...session.messages]);
|
||||||
|
setDisplayMessages([...session.displayMessages]);
|
||||||
|
setSessionName(session.sessionName);
|
||||||
setStreamingMessage(session.streamingMessage ? { ...session.streamingMessage } : undefined);
|
setStreamingMessage(session.streamingMessage ? { ...session.streamingMessage } : undefined);
|
||||||
setIsLoading(session.isLoading);
|
setIsLoading(session.isLoading);
|
||||||
setTotalCost(session.totalCost || 0);
|
setTotalCost(session.totalCost || 0);
|
||||||
setLastInputTokens(session.lastInputTokens || 0);
|
setLastInputTokens(session.lastInputTokens || 0);
|
||||||
setLastFinishReason(session.lastFinishReason ?? null);
|
setLastFinishReason(session.lastFinishReason ?? null);
|
||||||
|
setHasMoreHistory(sessionManager.hasMoreHistory(projectId));
|
||||||
|
setIsLoadingMoreHistory(session.isLoadingMoreHistory || false);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoadingHistory(false);
|
setIsLoadingHistory(false);
|
||||||
}
|
}
|
||||||
@@ -123,6 +131,25 @@ export function useAIChat({
|
|||||||
}
|
}
|
||||||
}, [projectId]);
|
}, [projectId]);
|
||||||
|
|
||||||
|
useSessionSubscription('displayMessageAdded', (updatedProjectId: string, message: DisplayMessage) => {
|
||||||
|
if (updatedProjectId === projectId) {
|
||||||
|
setDisplayMessages(prev => [...prev, message]);
|
||||||
|
}
|
||||||
|
}, [projectId]);
|
||||||
|
|
||||||
|
useSessionSubscription('displayMessagesPrepended', (updatedProjectId: string, newMessages: DisplayMessage[]) => {
|
||||||
|
if (updatedProjectId === projectId) {
|
||||||
|
setDisplayMessages(prev => [...newMessages, ...prev]);
|
||||||
|
setHasMoreHistory(sessionManager.hasMoreHistory(projectId));
|
||||||
|
}
|
||||||
|
}, [projectId, sessionManager]);
|
||||||
|
|
||||||
|
useSessionSubscription('loadingMoreHistoryChanged', (updatedProjectId: string, loading: boolean) => {
|
||||||
|
if (updatedProjectId === projectId) {
|
||||||
|
setIsLoadingMoreHistory(loading);
|
||||||
|
}
|
||||||
|
}, [projectId]);
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
const sendMessage = useCallback(async (
|
const sendMessage = useCallback(async (
|
||||||
content: string | Array<OpenAI.Chat.Completions.ChatCompletionContentPartText | OpenAI.Chat.Completions.ChatCompletionContentPartImage>,
|
content: string | Array<OpenAI.Chat.Completions.ChatCompletionContentPartText | OpenAI.Chat.Completions.ChatCompletionContentPartImage>,
|
||||||
@@ -164,7 +191,13 @@ export function useAIChat({
|
|||||||
const startNewSession = useCallback(async () => {
|
const startNewSession = useCallback(async () => {
|
||||||
await sessionManager.startNewSession(projectId);
|
await sessionManager.startNewSession(projectId);
|
||||||
|
|
||||||
// Reset individual state variables
|
// Get the updated session to retrieve the new session name
|
||||||
|
const session = sessionManager.getSession(projectId);
|
||||||
|
if (session) {
|
||||||
|
setSessionName(session.sessionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset only AI prompt state (not display state which is handled via events)
|
||||||
setMessages([]);
|
setMessages([]);
|
||||||
setStreamingMessage(undefined);
|
setStreamingMessage(undefined);
|
||||||
setTotalCost(0);
|
setTotalCost(0);
|
||||||
@@ -177,11 +210,19 @@ export function useAIChat({
|
|||||||
await startNewSession();
|
await startNewSession();
|
||||||
}, [startNewSession]);
|
}, [startNewSession]);
|
||||||
|
|
||||||
|
const loadMoreHistory = useCallback(async () => {
|
||||||
|
await sessionManager.loadOlderSession(projectId);
|
||||||
|
}, [projectId, sessionManager]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messages,
|
messages,
|
||||||
|
displayMessages,
|
||||||
|
sessionName,
|
||||||
streamingMessage,
|
streamingMessage,
|
||||||
isLoading,
|
isLoading,
|
||||||
isLoadingHistory,
|
isLoadingHistory,
|
||||||
|
hasMoreHistory,
|
||||||
|
isLoadingMoreHistory,
|
||||||
totalCost,
|
totalCost,
|
||||||
lastInputTokens,
|
lastInputTokens,
|
||||||
lastFinishReason,
|
lastFinishReason,
|
||||||
@@ -191,6 +232,7 @@ export function useAIChat({
|
|||||||
clearMessages,
|
clearMessages,
|
||||||
startNewSession,
|
startNewSession,
|
||||||
addMessage,
|
addMessage,
|
||||||
|
loadMoreHistory,
|
||||||
isConfigured,
|
isConfigured,
|
||||||
projectId
|
projectId
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
|
||||||
import { useNostr } from '@nostrify/react';
|
|
||||||
import { useCurrentUser } from './useCurrentUser';
|
|
||||||
import type { NostrEvent } from '@nostrify/nostrify';
|
|
||||||
import { BADGE_ISSUER_PUBKEY } from '@/pages/BadgesSettings';
|
|
||||||
|
|
||||||
export function useBadgeAwardNotifications() {
|
|
||||||
const { nostr } = useNostr();
|
|
||||||
const { user } = useCurrentUser();
|
|
||||||
const [newAward, setNewAward] = useState<NostrEvent | null>(null);
|
|
||||||
const abortControllerRef = useRef<AbortController | null>(null);
|
|
||||||
const isMountedRef = useRef(true);
|
|
||||||
const subscriptionStartTimeRef = useRef<number | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
isMountedRef.current = true;
|
|
||||||
return () => {
|
|
||||||
isMountedRef.current = false;
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!user?.pubkey) {
|
|
||||||
// Clear subscription if user logs out
|
|
||||||
if (abortControllerRef.current) {
|
|
||||||
abortControllerRef.current.abort();
|
|
||||||
abortControllerRef.current = null;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create abort controller for this subscription
|
|
||||||
const abortController = new AbortController();
|
|
||||||
abortControllerRef.current = abortController;
|
|
||||||
|
|
||||||
// Set the subscription start time to now, so we only get new events
|
|
||||||
const subscriptionStartTime = Math.floor(Date.now() / 1000);
|
|
||||||
subscriptionStartTimeRef.current = subscriptionStartTime;
|
|
||||||
|
|
||||||
// Set up subscription for new badge awards
|
|
||||||
const setupSubscription = async () => {
|
|
||||||
try {
|
|
||||||
const subscription = nostr.req([{
|
|
||||||
kinds: [8],
|
|
||||||
authors: [BADGE_ISSUER_PUBKEY],
|
|
||||||
"#p": [user.pubkey],
|
|
||||||
since: subscriptionStartTime, // Only get events from now onwards
|
|
||||||
}]);
|
|
||||||
|
|
||||||
// Process messages from the subscription
|
|
||||||
// Messages are in format: [type, subscriptionId, event]
|
|
||||||
for await (const msg of subscription) {
|
|
||||||
// Check if subscription was aborted or component unmounted
|
|
||||||
if (abortController.signal.aborted || !isMountedRef.current) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle EVENT messages (msg[0] === 'EVENT')
|
|
||||||
if (msg[0] === 'EVENT') {
|
|
||||||
const event = msg[2] as NostrEvent;
|
|
||||||
|
|
||||||
// Only show if component is still mounted and not aborted
|
|
||||||
if (isMountedRef.current && !abortController.signal.aborted) {
|
|
||||||
setNewAward(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// EOSE (End of Stored Events) - subscription is complete for initial query
|
|
||||||
// We continue listening for new events, so we don't break here
|
|
||||||
if (msg[0] === 'EOSE') {
|
|
||||||
// Initial query complete, now listening for new events
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Subscription closed or error - this is normal on cleanup
|
|
||||||
// Ignore errors if we aborted or unmounted
|
|
||||||
if (abortController.signal.aborted || !isMountedRef.current) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.error('Error in badge award subscription:', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
setupSubscription();
|
|
||||||
|
|
||||||
// Cleanup on unmount or user change
|
|
||||||
return () => {
|
|
||||||
if (abortControllerRef.current) {
|
|
||||||
abortControllerRef.current.abort();
|
|
||||||
abortControllerRef.current = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [nostr, user?.pubkey]);
|
|
||||||
|
|
||||||
const clearNewAward = () => {
|
|
||||||
setNewAward(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
newAward,
|
|
||||||
clearNewAward,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -27,73 +27,6 @@ describe('DotAI', () => {
|
|||||||
dotAI = new DotAI(mockFS, '/test-project');
|
dotAI = new DotAI(mockFS, '/test-project');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('readLastSessionHistory', () => {
|
|
||||||
it('should return null when history directory does not exist', async () => {
|
|
||||||
// Mock historyDirExists to return false
|
|
||||||
vi.spyOn(dotAI, 'historyDirExists').mockResolvedValue(false);
|
|
||||||
|
|
||||||
const result = await dotAI.readLastSessionHistory();
|
|
||||||
expect(result).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return null when no session files exist', async () => {
|
|
||||||
// Mock historyDirExists to return true
|
|
||||||
vi.spyOn(dotAI, 'historyDirExists').mockResolvedValue(true);
|
|
||||||
|
|
||||||
// Mock readdir to return empty array
|
|
||||||
vi.mocked(mockFS.readdir).mockResolvedValue([]);
|
|
||||||
|
|
||||||
const result = await dotAI.readLastSessionHistory();
|
|
||||||
expect(result).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return messages and session name from most recent file', async () => {
|
|
||||||
// Mock historyDirExists to return true
|
|
||||||
vi.spyOn(dotAI, 'historyDirExists').mockResolvedValue(true);
|
|
||||||
|
|
||||||
// Mock readdir to return session files
|
|
||||||
vi.mocked(mockFS.readdir).mockResolvedValue([
|
|
||||||
'2024-08-24T16-30-45Z-abc.jsonl',
|
|
||||||
'2024-08-24T17-15-22Z-def.jsonl', // This should be the most recent
|
|
||||||
'2024-08-24T15-00-00Z-xyz.jsonl'
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Mock readFile to return JSONL content
|
|
||||||
const mockContent = `{"role":"user","content":"Hello"}
|
|
||||||
{"role":"assistant","content":"Hi there!"}`;
|
|
||||||
vi.mocked(mockFS.readFile).mockResolvedValue(mockContent);
|
|
||||||
|
|
||||||
const result = await dotAI.readLastSessionHistory();
|
|
||||||
|
|
||||||
expect(result).not.toBeNull();
|
|
||||||
expect(result?.sessionName).toBe('2024-08-24T17-15-22Z-def');
|
|
||||||
expect(result?.messages).toHaveLength(2);
|
|
||||||
expect(result?.messages[0]).toEqual({ role: 'user', content: 'Hello' });
|
|
||||||
expect(result?.messages[1]).toEqual({ role: 'assistant', content: 'Hi there!' });
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle malformed JSON lines gracefully', async () => {
|
|
||||||
// Mock historyDirExists to return true
|
|
||||||
vi.spyOn(dotAI, 'historyDirExists').mockResolvedValue(true);
|
|
||||||
|
|
||||||
// Mock readdir to return session files
|
|
||||||
vi.mocked(mockFS.readdir).mockResolvedValue(['session.jsonl']);
|
|
||||||
|
|
||||||
// Mock readFile to return content with malformed JSON
|
|
||||||
const mockContent = `{"role":"user","content":"Hello"}
|
|
||||||
invalid json line
|
|
||||||
{"role":"assistant","content":"Hi there!"}`;
|
|
||||||
vi.mocked(mockFS.readFile).mockResolvedValue(mockContent);
|
|
||||||
|
|
||||||
const result = await dotAI.readLastSessionHistory();
|
|
||||||
|
|
||||||
expect(result).not.toBeNull();
|
|
||||||
expect(result?.messages).toHaveLength(2); // Should skip the malformed line
|
|
||||||
expect(result?.messages[0]).toEqual({ role: 'user', content: 'Hello' });
|
|
||||||
expect(result?.messages[1]).toEqual({ role: 'assistant', content: 'Hi there!' });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('setHistory', () => {
|
describe('setHistory', () => {
|
||||||
it('should create history directory if it does not exist', async () => {
|
it('should create history directory if it does not exist', async () => {
|
||||||
// Mock historyDirExists to return false initially
|
// Mock historyDirExists to return false initially
|
||||||
|
|||||||
+34
-50
@@ -216,66 +216,50 @@ export class DotAI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the most recent session history
|
* List all session names sorted chronologically (oldest first)
|
||||||
* @returns Object containing messages array and session name, or null if no history found
|
* Fast operation - does not load message content
|
||||||
|
* @returns Array of session names (filenames without .jsonl extension)
|
||||||
*/
|
*/
|
||||||
async readLastSessionHistory(): Promise<{
|
async listSessionNames(): Promise<string[]> {
|
||||||
messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[];
|
|
||||||
sessionName: string;
|
|
||||||
} | null> {
|
|
||||||
try {
|
try {
|
||||||
// Check if history directory exists
|
|
||||||
if (!(await this.historyDirExists())) {
|
if (!(await this.historyDirExists())) {
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the most recent session file
|
const files = await this.fs.readdir(this.historyDir);
|
||||||
try {
|
return files
|
||||||
const files = await this.fs.readdir(this.historyDir);
|
.filter(file => file.endsWith('.jsonl'))
|
||||||
const sessionFiles = files
|
.map(file => file.replace('.jsonl', ''))
|
||||||
.filter(file => file.endsWith('.jsonl'))
|
.sort(); // Chronological order (oldest first) - filenames contain timestamps
|
||||||
.sort()
|
} catch {
|
||||||
.reverse(); // Most recent first
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sessionFiles.length === 0) {
|
/**
|
||||||
return null;
|
* Read messages for a single session
|
||||||
}
|
* @param sessionName The session name (filename without .jsonl)
|
||||||
|
* @returns Array of messages, or empty array if session not found
|
||||||
const latestSessionFile = sessionFiles[0];
|
*/
|
||||||
const sessionPath = join(this.historyDir, latestSessionFile);
|
async readSessionHistory(sessionName: string): Promise<OpenAI.Chat.Completions.ChatCompletionMessageParam[]> {
|
||||||
|
try {
|
||||||
|
const sessionPath = join(this.historyDir, sessionName + '.jsonl');
|
||||||
|
const content = await this.fs.readFile(sessionPath, 'utf8');
|
||||||
|
const lines = content.trim().split('\n').filter(line => line.trim());
|
||||||
|
const messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[] = [];
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
try {
|
try {
|
||||||
const content = await this.fs.readFile(sessionPath, 'utf8');
|
const message = JSON.parse(line) as OpenAI.Chat.Completions.ChatCompletionMessageParam;
|
||||||
const lines = content.trim().split('\n').filter(line => line.trim());
|
messages.push(message);
|
||||||
const messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[] = [];
|
} catch {
|
||||||
|
// Skip malformed lines
|
||||||
for (const line of lines) {
|
|
||||||
try {
|
|
||||||
const message = JSON.parse(line) as OpenAI.Chat.Completions.ChatCompletionMessageParam;
|
|
||||||
messages.push(message);
|
|
||||||
} catch (parseError) {
|
|
||||||
console.warn('Failed to parse message from history:', parseError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return session name without .jsonl extension
|
|
||||||
const sessionName = latestSessionFile.replace('.jsonl', '');
|
|
||||||
|
|
||||||
return {
|
|
||||||
messages,
|
|
||||||
sessionName
|
|
||||||
};
|
|
||||||
} catch (readError) {
|
|
||||||
console.warn('Failed to read session file:', readError);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
} catch (readdirError) {
|
|
||||||
console.warn('Failed to read history directory:', readdirError);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.warn('Failed to read last session history:', error);
|
return messages;
|
||||||
return null;
|
} catch {
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+118
-11
@@ -24,12 +24,20 @@ export type AIMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam | {
|
|||||||
tool_calls?: OpenAI.Chat.Completions.ChatCompletionMessageToolCall[];
|
tool_calls?: OpenAI.Chat.Completions.ChatCompletionMessageToolCall[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** AIMessage with session tracking for UI display */
|
||||||
|
export type DisplayMessage = AIMessage & {
|
||||||
|
sessionId?: string; // Session identifier for grouping messages in UI
|
||||||
|
};
|
||||||
|
|
||||||
export interface SessionState {
|
export interface SessionState {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
tools: Record<string, OpenAI.Chat.Completions.ChatCompletionTool>;
|
tools: Record<string, OpenAI.Chat.Completions.ChatCompletionTool>;
|
||||||
customTools: Record<string, Tool<unknown>>;
|
customTools: Record<string, Tool<unknown>>;
|
||||||
maxSteps?: number;
|
maxSteps?: number;
|
||||||
messages: AIMessage[];
|
messages: AIMessage[]; // Current session messages (sent to AI)
|
||||||
|
displayMessages: DisplayMessage[]; // All messages from all sessions (for UI, with sessionId)
|
||||||
|
availableSessionNames: string[]; // All session names (for lazy loading)
|
||||||
|
loadedSessionCount: number; // How many sessions loaded from the end
|
||||||
streamingMessage?: {
|
streamingMessage?: {
|
||||||
role: 'assistant';
|
role: 'assistant';
|
||||||
content: string;
|
content: string;
|
||||||
@@ -37,6 +45,7 @@ export interface SessionState {
|
|||||||
tool_calls?: OpenAI.Chat.Completions.ChatCompletionMessageToolCall[];
|
tool_calls?: OpenAI.Chat.Completions.ChatCompletionMessageToolCall[];
|
||||||
};
|
};
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
isLoadingMoreHistory: boolean; // Loading older sessions
|
||||||
sessionName: string;
|
sessionName: string;
|
||||||
lastActivity: Date;
|
lastActivity: Date;
|
||||||
abortController?: AbortController;
|
abortController?: AbortController;
|
||||||
@@ -50,8 +59,11 @@ export interface SessionManagerEvents {
|
|||||||
sessionCreated: (projectId: string) => void;
|
sessionCreated: (projectId: string) => void;
|
||||||
sessionDeleted: (projectId: string) => void;
|
sessionDeleted: (projectId: string) => void;
|
||||||
messageAdded: (projectId: string, message: AIMessage) => void;
|
messageAdded: (projectId: string, message: AIMessage) => void;
|
||||||
|
displayMessageAdded: (projectId: string, message: DisplayMessage) => void;
|
||||||
|
displayMessagesPrepended: (projectId: string, messages: DisplayMessage[]) => void;
|
||||||
streamingUpdate: (projectId: string, content: string, reasoningContent?: string, toolCalls?: OpenAI.Chat.Completions.ChatCompletionMessageToolCall[]) => void;
|
streamingUpdate: (projectId: string, content: string, reasoningContent?: string, toolCalls?: OpenAI.Chat.Completions.ChatCompletionMessageToolCall[]) => void;
|
||||||
loadingChanged: (projectId: string, isLoading: boolean) => void;
|
loadingChanged: (projectId: string, isLoading: boolean) => void;
|
||||||
|
loadingMoreHistoryChanged: (projectId: string, isLoading: boolean) => void;
|
||||||
costUpdated: (projectId: string, totalCost: number) => void;
|
costUpdated: (projectId: string, totalCost: number) => void;
|
||||||
contextUsageUpdated: (projectId: string, inputTokens: number) => void;
|
contextUsageUpdated: (projectId: string, inputTokens: number) => void;
|
||||||
fileChanged: (projectId: string, filePath: string) => void;
|
fileChanged: (projectId: string, filePath: string) => void;
|
||||||
@@ -97,7 +109,7 @@ export class SessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new session for a project
|
* Create a new session for a project (lazy loading - only loads most recent session)
|
||||||
*/
|
*/
|
||||||
async loadSession(
|
async loadSession(
|
||||||
projectId: string,
|
projectId: string,
|
||||||
@@ -105,18 +117,39 @@ export class SessionManager {
|
|||||||
customTools: Record<string, Tool<unknown>>,
|
customTools: Record<string, Tool<unknown>>,
|
||||||
maxSteps?: number
|
maxSteps?: number
|
||||||
): Promise<SessionState> {
|
): Promise<SessionState> {
|
||||||
let messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[] = [];
|
const messages: AIMessage[] = [];
|
||||||
|
const displayMessages: DisplayMessage[] = [];
|
||||||
let sessionName = DotAI.generateSessionName();
|
let sessionName = DotAI.generateSessionName();
|
||||||
|
let availableSessionNames: string[] = [];
|
||||||
|
let loadedSessionCount = 0;
|
||||||
let lastFinishReason: string | null | undefined;
|
let lastFinishReason: string | null | undefined;
|
||||||
|
|
||||||
// Try to load existing history
|
// Try to load existing history (lazy - only load last session)
|
||||||
try {
|
try {
|
||||||
const config = this.getConfig();
|
const config = this.getConfig();
|
||||||
const dotAI = new DotAI(this.fs, `${config.fsPathProjects}/${projectId}`);
|
const dotAI = new DotAI(this.fs, `${config.fsPathProjects}/${projectId}`);
|
||||||
const lastSession = await dotAI.readLastSessionHistory();
|
|
||||||
if (lastSession) {
|
// Get all available session names (fast - no content loading)
|
||||||
messages = lastSession.messages;
|
availableSessionNames = await dotAI.listSessionNames();
|
||||||
sessionName = lastSession.sessionName;
|
|
||||||
|
if (availableSessionNames.length > 0) {
|
||||||
|
// Only load the most recent session
|
||||||
|
const lastSessionName = availableSessionNames[availableSessionNames.length - 1];
|
||||||
|
const lastSessionMessages = await dotAI.readSessionHistory(lastSessionName);
|
||||||
|
|
||||||
|
if (lastSessionMessages.length > 0) {
|
||||||
|
// Add messages with sessionId annotation
|
||||||
|
for (const msg of lastSessionMessages) {
|
||||||
|
displayMessages.push({
|
||||||
|
...msg as AIMessage,
|
||||||
|
sessionId: lastSessionName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
messages.push(...lastSessionMessages as AIMessage[]);
|
||||||
|
sessionName = lastSessionName;
|
||||||
|
loadedSessionCount = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load last finish reason
|
// Load last finish reason
|
||||||
@@ -131,22 +164,34 @@ export class SessionManager {
|
|||||||
customTools,
|
customTools,
|
||||||
maxSteps,
|
maxSteps,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
isLoadingMoreHistory: false,
|
||||||
lastActivity: new Date(),
|
lastActivity: new Date(),
|
||||||
totalCost: 0,
|
totalCost: 0,
|
||||||
lastInputTokens: 0,
|
lastInputTokens: 0,
|
||||||
lastFinishReason,
|
lastFinishReason,
|
||||||
...this.sessions.get(projectId),
|
...this.sessions.get(projectId),
|
||||||
messages,
|
messages,
|
||||||
|
displayMessages,
|
||||||
|
availableSessionNames,
|
||||||
|
loadedSessionCount,
|
||||||
sessionName,
|
sessionName,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update session configuration
|
// Update session configuration
|
||||||
session.projectId = projectId;
|
session.projectId = projectId;
|
||||||
session.tools = tools;
|
session.tools = tools;
|
||||||
|
|
||||||
session.customTools = customTools;
|
session.customTools = customTools;
|
||||||
session.maxSteps = maxSteps;
|
session.maxSteps = maxSteps;
|
||||||
|
|
||||||
|
// Update messages from loaded history if not already set by an existing session
|
||||||
|
if (!this.sessions.has(projectId)) {
|
||||||
|
session.messages = messages;
|
||||||
|
session.displayMessages = displayMessages;
|
||||||
|
session.availableSessionNames = availableSessionNames;
|
||||||
|
session.loadedSessionCount = loadedSessionCount;
|
||||||
|
session.sessionName = sessionName;
|
||||||
|
}
|
||||||
|
|
||||||
this.sessions.set(projectId, session);
|
this.sessions.set(projectId, session);
|
||||||
|
|
||||||
this.emit('sessionCreated', projectId);
|
this.emit('sessionCreated', projectId);
|
||||||
@@ -187,11 +232,69 @@ export class SessionManager {
|
|||||||
const session = this.sessions.get(projectId);
|
const session = this.sessions.get(projectId);
|
||||||
if (!session) return;
|
if (!session) return;
|
||||||
|
|
||||||
|
// Add to current session messages (for AI prompts)
|
||||||
session.messages.push(message);
|
session.messages.push(message);
|
||||||
|
|
||||||
|
// Also add to display messages with session ID annotation (for UI)
|
||||||
|
const displayMessage: DisplayMessage = { ...message, sessionId: session.sessionName };
|
||||||
|
session.displayMessages.push(displayMessage);
|
||||||
|
|
||||||
session.lastActivity = new Date();
|
session.lastActivity = new Date();
|
||||||
|
|
||||||
await this.saveSessionHistory(projectId);
|
await this.saveSessionHistory(projectId);
|
||||||
this.emit('messageAdded', projectId, message);
|
this.emit('messageAdded', projectId, message);
|
||||||
|
this.emit('displayMessageAdded', projectId, displayMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if there are more historical sessions to load
|
||||||
|
*/
|
||||||
|
hasMoreHistory(projectId: string): boolean {
|
||||||
|
const session = this.sessions.get(projectId);
|
||||||
|
if (!session) return false;
|
||||||
|
return session.loadedSessionCount < session.availableSessionNames.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the next older session and prepend to displayMessages
|
||||||
|
*/
|
||||||
|
async loadOlderSession(projectId: string): Promise<void> {
|
||||||
|
const session = this.sessions.get(projectId);
|
||||||
|
if (!session || !this.hasMoreHistory(projectId) || session.isLoadingMoreHistory) return;
|
||||||
|
|
||||||
|
session.isLoadingMoreHistory = true;
|
||||||
|
this.emit('loadingMoreHistoryChanged', projectId, true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const config = this.getConfig();
|
||||||
|
const dotAI = new DotAI(this.fs, `${config.fsPathProjects}/${projectId}`);
|
||||||
|
|
||||||
|
// Get the next older session (counting from the end)
|
||||||
|
const nextIndex = session.availableSessionNames.length - session.loadedSessionCount - 1;
|
||||||
|
if (nextIndex < 0) return;
|
||||||
|
|
||||||
|
const olderSessionName = session.availableSessionNames[nextIndex];
|
||||||
|
const olderMessages = await dotAI.readSessionHistory(olderSessionName);
|
||||||
|
|
||||||
|
if (olderMessages.length > 0) {
|
||||||
|
// Create display messages with sessionId
|
||||||
|
const newDisplayMessages: DisplayMessage[] = olderMessages.map(msg => ({
|
||||||
|
...msg as AIMessage,
|
||||||
|
sessionId: olderSessionName,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Prepend to displayMessages
|
||||||
|
session.displayMessages = [...newDisplayMessages, ...session.displayMessages];
|
||||||
|
session.loadedSessionCount++;
|
||||||
|
|
||||||
|
this.emit('displayMessagesPrepended', projectId, newDisplayMessages);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to load older session:', error);
|
||||||
|
} finally {
|
||||||
|
session.isLoadingMoreHistory = false;
|
||||||
|
this.emit('loadingMoreHistoryChanged', projectId, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -699,7 +802,7 @@ export class SessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a new session (clear messages but keep configuration)
|
* Start a new session (clear AI messages but keep display history)
|
||||||
*/
|
*/
|
||||||
async startNewSession(projectId: string): Promise<void> {
|
async startNewSession(projectId: string): Promise<void> {
|
||||||
const session = this.sessions.get(projectId);
|
const session = this.sessions.get(projectId);
|
||||||
@@ -707,9 +810,13 @@ export class SessionManager {
|
|||||||
|
|
||||||
this.stopGeneration(projectId);
|
this.stopGeneration(projectId);
|
||||||
|
|
||||||
|
// Generate new session name - new messages will automatically get this sessionId
|
||||||
|
const newSessionName = DotAI.generateSessionName();
|
||||||
|
|
||||||
|
// Clear only the AI prompt messages (not display messages)
|
||||||
session.messages = [];
|
session.messages = [];
|
||||||
session.streamingMessage = undefined;
|
session.streamingMessage = undefined;
|
||||||
session.sessionName = DotAI.generateSessionName();
|
session.sessionName = newSessionName;
|
||||||
session.lastActivity = new Date();
|
session.lastActivity = new Date();
|
||||||
session.totalCost = 0;
|
session.totalCost = 0;
|
||||||
session.lastInputTokens = 0;
|
session.lastInputTokens = 0;
|
||||||
|
|||||||
+40
-3
@@ -58,10 +58,36 @@ export function createAIClient(provider: AIProvider, user?: NUser, corsProxy?: s
|
|||||||
= openai.chat.completions.create.bind(openai.chat.completions);
|
= openai.chat.completions.create.bind(openai.chat.completions);
|
||||||
|
|
||||||
openai.chat.completions.create = ((...[body, options]: Parameters<typeof createCompletion>) => {
|
openai.chat.completions.create = ((...[body, options]: Parameters<typeof createCompletion>) => {
|
||||||
// OpenRouter usage accounting
|
// OpenRouter-specific hacks
|
||||||
// https://openrouter.ai/docs/use-cases/usage-accounting
|
if (provider.id === "openrouter" || provider.baseURL === "https://openrouter.ai/api/v1") {
|
||||||
if (provider.id === 'openrouter') {
|
// Usage accounting field to get token usage and cost per request
|
||||||
|
// https://openrouter.ai/docs/use-cases/usage-accounting
|
||||||
(body as { usage?: { include?: boolean } }).usage = { include: true };
|
(body as { usage?: { include?: boolean } }).usage = { include: true };
|
||||||
|
|
||||||
|
// Prompt caching for Claude models
|
||||||
|
// https://openrouter.ai/docs/guides/best-practices/prompt-caching#anthropic-claude
|
||||||
|
if (body.model.startsWith("anthropic/")) {
|
||||||
|
// First normalize the message history to use content blocks
|
||||||
|
body.messages = structuredClone(body.messages);
|
||||||
|
body.messages = body.messages.map((m) => {
|
||||||
|
if (m.role !== "function" && typeof m.content === "string") {
|
||||||
|
return { ...m, content: [{ type: "text", text: m.content }] };
|
||||||
|
} else {
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const systemMessage = body.messages.find((m) => m.role === "system");
|
||||||
|
const nonSystemMessages = body.messages.filter((m) => m.role !== "system");
|
||||||
|
const lastTwoMessages = nonSystemMessages.slice(-2);
|
||||||
|
|
||||||
|
if (systemMessage) {
|
||||||
|
addCacheControl(systemMessage);
|
||||||
|
}
|
||||||
|
for (const msg of lastTwoMessages) {
|
||||||
|
addCacheControl(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return createCompletion(body, options);
|
return createCompletion(body, options);
|
||||||
@@ -69,3 +95,14 @@ export function createAIClient(provider: AIProvider, user?: NUser, corsProxy?: s
|
|||||||
|
|
||||||
return openai;
|
return openai;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Mutate msg to add an Anthropic `cache_control` property to its last text block */
|
||||||
|
function addCacheControl(msg: OpenAI.Chat.Completions.ChatCompletionMessageParam) {
|
||||||
|
if (Array.isArray(msg.content)) {
|
||||||
|
const lastTextBlock = msg.content.findLast((b) => b.type === "text");
|
||||||
|
if (lastTextBlock) {
|
||||||
|
(lastTextBlock as { cache_control?: { type: "ephemeral" } })
|
||||||
|
.cache_control = { type: "ephemeral" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -23,6 +23,14 @@ export const AI_PROVIDER_PRESETS: PresetProvider[] = [
|
|||||||
apiKeysURL: "https://openrouter.ai/settings/keys",
|
apiKeysURL: "https://openrouter.ai/settings/keys",
|
||||||
tosURL: "https://openrouter.ai/terms",
|
tosURL: "https://openrouter.ai/terms",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "opencode",
|
||||||
|
name: "OpenCode Zen",
|
||||||
|
baseURL: "https://opencode.ai/zen/v1",
|
||||||
|
apiKeysURL: "https://opencode.ai/auth",
|
||||||
|
tosURL: "https://opencode.ai/legal/terms-of-service",
|
||||||
|
proxy: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "ppq",
|
id: "ppq",
|
||||||
name: "PayPerQ",
|
name: "PayPerQ",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Bot, GitBranch, Database, Wifi, Settings2, Info, Settings, Rocket, Award } from 'lucide-react';
|
import { Bot, GitBranch, Database, Wifi, Settings2, Info, Settings, Rocket } from 'lucide-react';
|
||||||
|
|
||||||
export interface SettingsItem {
|
export interface SettingsItem {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -29,12 +29,6 @@ export const getSettingsCategories = (t: (key: string) => string): SettingsCateg
|
|||||||
title: t('preferences'),
|
title: t('preferences'),
|
||||||
href: '/settings/preferences',
|
href: '/settings/preferences',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
id: 'badges',
|
|
||||||
icon: Award,
|
|
||||||
title: t('badges'),
|
|
||||||
href: '/settings/badges',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-7
@@ -9,6 +9,8 @@
|
|||||||
"anonymous": "Anonymous",
|
"anonymous": "Anonymous",
|
||||||
"logIn": "Log in",
|
"logIn": "Log in",
|
||||||
"signUp": "Sign up",
|
"signUp": "Sign up",
|
||||||
|
"newChat": "New Chat",
|
||||||
|
"loadOlderMessages": "Load older messages",
|
||||||
"preferencesDescription": "Manage your general application preferences and appearance settings.",
|
"preferencesDescription": "Manage your general application preferences and appearance settings.",
|
||||||
"theme": "Theme",
|
"theme": "Theme",
|
||||||
"themeDescription": "Choose between light, dark, or system theme preference.",
|
"themeDescription": "Choose between light, dark, or system theme preference.",
|
||||||
@@ -561,11 +563,5 @@
|
|||||||
"failedToDuplicateProject": "Failed to duplicate project",
|
"failedToDuplicateProject": "Failed to duplicate project",
|
||||||
"newProjectName": "New Project Name",
|
"newProjectName": "New Project Name",
|
||||||
"duplicateProjectDescription": "Create a copy of this project with a new name",
|
"duplicateProjectDescription": "Create a copy of this project with a new name",
|
||||||
"resume": "Resume",
|
"resume": "Resume"
|
||||||
"badges": "Badges",
|
|
||||||
"badgesDescription": "View and manage your earned badges and achievements",
|
|
||||||
"noBadgesFound": "No badges found",
|
|
||||||
"tokenProgress": "Tokens",
|
|
||||||
"imageProgress": "Images",
|
|
||||||
"nextBadgeAt": "Next badge at {{milestone}}"
|
|
||||||
}
|
}
|
||||||
+3
-7
@@ -9,6 +9,8 @@
|
|||||||
"anonymous": "Maras Suna",
|
"anonymous": "Maras Suna",
|
||||||
"logIn": "Shiga",
|
"logIn": "Shiga",
|
||||||
"signUp": "Yi Rajista",
|
"signUp": "Yi Rajista",
|
||||||
|
"newChat": "Sabon Tattaunawa",
|
||||||
|
"loadOlderMessages": "Loda saƙonni masu tsufa",
|
||||||
"preferencesDescription": "Sarrafa zaɓuɓɓukan aikace-aikacenku da saitunan bayyanar.",
|
"preferencesDescription": "Sarrafa zaɓuɓɓukan aikace-aikacenku da saitunan bayyanar.",
|
||||||
"theme": "Jigogi",
|
"theme": "Jigogi",
|
||||||
"themeDescription": "Zaɓi tsakanin haske, duhu, ko zaɓin jigogi na tsarin.",
|
"themeDescription": "Zaɓi tsakanin haske, duhu, ko zaɓin jigogi na tsarin.",
|
||||||
@@ -477,11 +479,5 @@
|
|||||||
"failedToDuplicateProject": "An kasa kwafin aikin",
|
"failedToDuplicateProject": "An kasa kwafin aikin",
|
||||||
"newProjectName": "Sunan Sabon Aikin",
|
"newProjectName": "Sunan Sabon Aikin",
|
||||||
"duplicateProjectDescription": "Ƙirƙiri kwafin wannan aikin da sabon suna",
|
"duplicateProjectDescription": "Ƙirƙiri kwafin wannan aikin da sabon suna",
|
||||||
"resume": "Ci gaba",
|
"resume": "Ci gaba"
|
||||||
"badges": "Tambari",
|
|
||||||
"badgesDescription": "Duba da sarrafa tambarin da kuka samu da nasarorin",
|
|
||||||
"noBadgesFound": "Ba a sami tambari ba",
|
|
||||||
"tokenProgress": "Tokens",
|
|
||||||
"imageProgress": "Hotuna",
|
|
||||||
"nextBadgeAt": "Tambari na gaba a {{milestone}}"
|
|
||||||
}
|
}
|
||||||
+3
-7
@@ -9,6 +9,8 @@
|
|||||||
"anonymous": "Onye na-amaghị aha",
|
"anonymous": "Onye na-amaghị aha",
|
||||||
"logIn": "Banye",
|
"logIn": "Banye",
|
||||||
"signUp": "Debanye aha",
|
"signUp": "Debanye aha",
|
||||||
|
"newChat": "Nkata Ọhụrụ",
|
||||||
|
"loadOlderMessages": "Bulite ozi ochie",
|
||||||
"preferencesDescription": "Jikwaa nhọrọ ngwa gị na ntọala ngosipụta.",
|
"preferencesDescription": "Jikwaa nhọrọ ngwa gị na ntọala ngosipụta.",
|
||||||
"theme": "Isiokwu",
|
"theme": "Isiokwu",
|
||||||
"themeDescription": "Họrọ n'etiti ìhè, ọchịchịrị, ma ọ bụ nhọrọ isiokwu sistemu.",
|
"themeDescription": "Họrọ n'etiti ìhè, ọchịchịrị, ma ọ bụ nhọrọ isiokwu sistemu.",
|
||||||
@@ -474,11 +476,5 @@
|
|||||||
"failedToDuplicateProject": "Ọ dara ada imepụta ọrụ",
|
"failedToDuplicateProject": "Ọ dara ada imepụta ọrụ",
|
||||||
"newProjectName": "Aha Ọrụ Ọhụrụ",
|
"newProjectName": "Aha Ọrụ Ọhụrụ",
|
||||||
"duplicateProjectDescription": "Mepụta oyiri nke ọrụ a na aha ọhụrụ",
|
"duplicateProjectDescription": "Mepụta oyiri nke ọrụ a na aha ọhụrụ",
|
||||||
"resume": "Gaa n'ihu",
|
"resume": "Gaa n'ihu"
|
||||||
"badges": "Baajị",
|
|
||||||
"badgesDescription": "Lelee ma jikwaa baajị na mmeri gị",
|
|
||||||
"noBadgesFound": "Achọtaghị baajị",
|
|
||||||
"tokenProgress": "Tokens",
|
|
||||||
"imageProgress": "Foto",
|
|
||||||
"nextBadgeAt": "Baajị ọzọ na {{milestone}}"
|
|
||||||
}
|
}
|
||||||
+3
-7
@@ -9,6 +9,8 @@
|
|||||||
"anonymous": "Anônimo",
|
"anonymous": "Anônimo",
|
||||||
"logIn": "Entrar",
|
"logIn": "Entrar",
|
||||||
"signUp": "Cadastrar",
|
"signUp": "Cadastrar",
|
||||||
|
"newChat": "Nova Conversa",
|
||||||
|
"loadOlderMessages": "Carregar mensagens anteriores",
|
||||||
"preferencesDescription": "Gerencie suas preferências gerais da aplicação e configurações de aparência.",
|
"preferencesDescription": "Gerencie suas preferências gerais da aplicação e configurações de aparência.",
|
||||||
"theme": "Tema",
|
"theme": "Tema",
|
||||||
"themeDescription": "Escolha entre preferência de tema claro, escuro ou do sistema.",
|
"themeDescription": "Escolha entre preferência de tema claro, escuro ou do sistema.",
|
||||||
@@ -486,11 +488,5 @@
|
|||||||
"failedToDuplicateProject": "Falha ao duplicar projeto",
|
"failedToDuplicateProject": "Falha ao duplicar projeto",
|
||||||
"newProjectName": "Nome do Novo Projeto",
|
"newProjectName": "Nome do Novo Projeto",
|
||||||
"duplicateProjectDescription": "Criar uma cópia deste projeto com um novo nome",
|
"duplicateProjectDescription": "Criar uma cópia deste projeto com um novo nome",
|
||||||
"resume": "Retomar",
|
"resume": "Retomar"
|
||||||
"badges": "Distintivos",
|
|
||||||
"badgesDescription": "Visualizar e gerenciar seus distintivos e conquistas",
|
|
||||||
"noBadgesFound": "Nenhum distintivo encontrado",
|
|
||||||
"tokenProgress": "Tokens",
|
|
||||||
"imageProgress": "Imagens",
|
|
||||||
"nextBadgeAt": "Próximo distintivo em {{milestone}}"
|
|
||||||
}
|
}
|
||||||
+3
-7
@@ -9,6 +9,8 @@
|
|||||||
"anonymous": "Alainidamọ",
|
"anonymous": "Alainidamọ",
|
||||||
"logIn": "Wọle",
|
"logIn": "Wọle",
|
||||||
"signUp": "Forukọsilẹ",
|
"signUp": "Forukọsilẹ",
|
||||||
|
"newChat": "Ọrọ Tuntun",
|
||||||
|
"loadOlderMessages": "Gbe awọn ifiranṣẹ atijọ",
|
||||||
"preferencesDescription": "Ṣakoso awọn ayanfẹ ohun elo rẹ ati awọn eto iwoye.",
|
"preferencesDescription": "Ṣakoso awọn ayanfẹ ohun elo rẹ ati awọn eto iwoye.",
|
||||||
"theme": "Akori",
|
"theme": "Akori",
|
||||||
"themeDescription": "Yan laarin imọlẹ, okunkun, tabi ayanfẹ akori eto.",
|
"themeDescription": "Yan laarin imọlẹ, okunkun, tabi ayanfẹ akori eto.",
|
||||||
@@ -474,11 +476,5 @@
|
|||||||
"failedToDuplicateProject": "O kuna lati ṣe ẹda iṣẹ akanṣe",
|
"failedToDuplicateProject": "O kuna lati ṣe ẹda iṣẹ akanṣe",
|
||||||
"newProjectName": "Orukọ Iṣẹ Akanṣe Tuntun",
|
"newProjectName": "Orukọ Iṣẹ Akanṣe Tuntun",
|
||||||
"duplicateProjectDescription": "Ṣẹda ẹda ti iṣẹ akanṣe yii pẹlu orukọ tuntun",
|
"duplicateProjectDescription": "Ṣẹda ẹda ti iṣẹ akanṣe yii pẹlu orukọ tuntun",
|
||||||
"resume": "Tẹsiwaju",
|
"resume": "Tẹsiwaju"
|
||||||
"badges": "Àmì-ẹ̀yẹ",
|
|
||||||
"badgesDescription": "Wo ati ṣakoso àmì-ẹ̀yẹ àti àwọn àṣeyọrí rẹ",
|
|
||||||
"noBadgesFound": "Ko ri àmì-ẹ̀yẹ",
|
|
||||||
"tokenProgress": "Àwọn tókẹ̀n",
|
|
||||||
"imageProgress": "Àwọn àwòrán",
|
|
||||||
"nextBadgeAt": "Àmì-ẹ̀yẹ tó kàn ní {{milestone}}"
|
|
||||||
}
|
}
|
||||||
+3
-7
@@ -9,6 +9,8 @@
|
|||||||
"anonymous": "匿名",
|
"anonymous": "匿名",
|
||||||
"logIn": "登录",
|
"logIn": "登录",
|
||||||
"signUp": "注册",
|
"signUp": "注册",
|
||||||
|
"newChat": "新对话",
|
||||||
|
"loadOlderMessages": "加载更早的消息",
|
||||||
"preferencesDescription": "管理您的应用程序偏好设置和外观设置。",
|
"preferencesDescription": "管理您的应用程序偏好设置和外观设置。",
|
||||||
"theme": "主题",
|
"theme": "主题",
|
||||||
"themeDescription": "选择浅色、深色或系统主题偏好。",
|
"themeDescription": "选择浅色、深色或系统主题偏好。",
|
||||||
@@ -486,11 +488,5 @@
|
|||||||
"failedToDuplicateProject": "复制项目失败",
|
"failedToDuplicateProject": "复制项目失败",
|
||||||
"newProjectName": "新项目名称",
|
"newProjectName": "新项目名称",
|
||||||
"duplicateProjectDescription": "使用新名称创建此项目的副本",
|
"duplicateProjectDescription": "使用新名称创建此项目的副本",
|
||||||
"resume": "继续",
|
"resume": "继续"
|
||||||
"badges": "徽章",
|
|
||||||
"badgesDescription": "查看和管理您获得的徽章和成就",
|
|
||||||
"noBadgesFound": "未找到徽章",
|
|
||||||
"tokenProgress": "代币",
|
|
||||||
"imageProgress": "图片",
|
|
||||||
"nextBadgeAt": "下一个徽章需要 {{milestone}}"
|
|
||||||
}
|
}
|
||||||
@@ -1,535 +0,0 @@
|
|||||||
import { Award, Lock } from "lucide-react";
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { SettingsPageLayout } from '@/components/SettingsPageLayout';
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
||||||
import { Progress } from "@/components/ui/progress";
|
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
import { useNostr } from '@nostrify/react';
|
|
||||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
|
||||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
|
||||||
import { useAISettings } from '@/hooks/useAISettings';
|
|
||||||
import { useAppContext } from '@/hooks/useAppContext';
|
|
||||||
import { BadgeAwardModal } from '@/components/BadgeAwardModal';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
import { useState, useMemo } from 'react';
|
|
||||||
import type { NostrEvent } from '@nostrify/nostrify';
|
|
||||||
import { createAIClient } from '@/lib/ai-client';
|
|
||||||
import { nip19 } from 'nostr-tools';
|
|
||||||
|
|
||||||
export const BADGE_ISSUER_NPUB = "npub1e0u5dfurw3dmd0n5lul873c5g3p89et6x372sa35spajcxjh4f6svcvahk";
|
|
||||||
export const BADGE_ISSUER_PUBKEY = nip19.decode(BADGE_ISSUER_NPUB).data as string;
|
|
||||||
|
|
||||||
// Badge sync response from the server
|
|
||||||
interface BadgeSyncResponse {
|
|
||||||
object: 'badge_sync';
|
|
||||||
synced: string[];
|
|
||||||
stats: {
|
|
||||||
generation_count: number;
|
|
||||||
total_tokens: number;
|
|
||||||
image_count: number;
|
|
||||||
has_lightning_payment: boolean;
|
|
||||||
giftcards_sent: number;
|
|
||||||
max_giftcard_amount: number;
|
|
||||||
};
|
|
||||||
milestones?: {
|
|
||||||
tokenMilestones: Array<{ threshold: number; type: 'generation' | 'tokens'; creditReward?: number }>;
|
|
||||||
imageMilestones: Array<{ count: number; creditReward?: number }>;
|
|
||||||
giftcardMilestones: Array<{ threshold: number; type: 'count' | 'amount'; creditReward?: number }>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function formatNumber(num: number): string {
|
|
||||||
if (num >= 1_000_000_000) return `${(num / 1_000_000_000).toFixed(1)}B`;
|
|
||||||
if (num >= 1_000_000) return `${(num / 1_000_000).toFixed(1)}M`;
|
|
||||||
if (num >= 1_000) return `${(num / 1_000).toFixed(1)}K`;
|
|
||||||
return num.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TokenMilestone {
|
|
||||||
threshold: number;
|
|
||||||
type: 'generation' | 'tokens';
|
|
||||||
creditReward?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TokenProgressResult {
|
|
||||||
progress: number;
|
|
||||||
current: number;
|
|
||||||
next: number;
|
|
||||||
type: 'generation' | 'tokens';
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTokenMilestoneProgress(
|
|
||||||
generationCount: number,
|
|
||||||
totalTokens: number,
|
|
||||||
milestones: TokenMilestone[]
|
|
||||||
): TokenProgressResult | null {
|
|
||||||
// Find the first uncompleted milestone
|
|
||||||
for (let i = 0; i < milestones.length; i++) {
|
|
||||||
const milestone = milestones[i];
|
|
||||||
const currentValue = milestone.type === 'generation' ? generationCount : totalTokens;
|
|
||||||
|
|
||||||
if (currentValue < milestone.threshold) {
|
|
||||||
// This is the next milestone to achieve
|
|
||||||
const prevMilestone = i > 0 ? milestones[i - 1] : null;
|
|
||||||
const prevThreshold = prevMilestone
|
|
||||||
? (prevMilestone.type === milestone.type ? prevMilestone.threshold : 0)
|
|
||||||
: 0;
|
|
||||||
|
|
||||||
const range = milestone.threshold - prevThreshold;
|
|
||||||
const progressInRange = currentValue - prevThreshold;
|
|
||||||
const progress = Math.min(100, Math.max(0, (progressInRange / range) * 100));
|
|
||||||
|
|
||||||
return {
|
|
||||||
progress,
|
|
||||||
current: currentValue,
|
|
||||||
next: milestone.threshold,
|
|
||||||
type: milestone.type,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// All milestones achieved
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getImageMilestoneProgress(
|
|
||||||
imageCount: number,
|
|
||||||
milestones: number[]
|
|
||||||
): { progress: number; current: number; next: number } | null {
|
|
||||||
// Find the first uncompleted milestone
|
|
||||||
for (let i = 0; i < milestones.length; i++) {
|
|
||||||
const milestone = milestones[i];
|
|
||||||
|
|
||||||
if (imageCount < milestone) {
|
|
||||||
const prevThreshold = i > 0 ? milestones[i - 1] : 0;
|
|
||||||
const range = milestone - prevThreshold;
|
|
||||||
const progressInRange = imageCount - prevThreshold;
|
|
||||||
const progress = Math.min(100, Math.max(0, (progressInRange / range) * 100));
|
|
||||||
|
|
||||||
return { progress, current: imageCount, next: milestone };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// All milestones achieved
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isCreditMilestone(milestone: number | null, creditMilestones: number[]): boolean {
|
|
||||||
return milestone !== null && creditMilestones.includes(milestone);
|
|
||||||
}
|
|
||||||
|
|
||||||
function BadgeCard({
|
|
||||||
event,
|
|
||||||
awarded,
|
|
||||||
unlockDate,
|
|
||||||
onClick
|
|
||||||
}: {
|
|
||||||
event: NostrEvent;
|
|
||||||
awarded: boolean;
|
|
||||||
unlockDate?: number | null;
|
|
||||||
onClick?: () => void;
|
|
||||||
}) {
|
|
||||||
const dTag = event.tags.find(([t]) => t === "d")?.[1];
|
|
||||||
const nameTag = event.tags.find(([t]) => t === "name")?.[1];
|
|
||||||
const descriptionTag = event.tags.find(([t]) => t === "description")?.[1];
|
|
||||||
const imageTag = event.tags.find(([t]) => t === "image")?.[1];
|
|
||||||
const thumbTags = event.tags.filter(([t]) => t === "thumb");
|
|
||||||
|
|
||||||
const badgeName = nameTag || dTag || "Unnamed Badge";
|
|
||||||
const description = descriptionTag || "";
|
|
||||||
const imageUrl = imageTag || (thumbTags.length > 0 ? thumbTags[thumbTags.length - 1]?.[1] : null);
|
|
||||||
|
|
||||||
const formattedDate = unlockDate
|
|
||||||
? new Date(unlockDate * 1000).toLocaleDateString('en-US', {
|
|
||||||
year: 'numeric',
|
|
||||||
month: 'short',
|
|
||||||
day: 'numeric'
|
|
||||||
})
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card
|
|
||||||
className={cn(
|
|
||||||
"transition-all bg-transparent border-none shadow-none h-full",
|
|
||||||
awarded ? "cursor-pointer hover:scale-105" : ""
|
|
||||||
)}
|
|
||||||
onClick={awarded ? onClick : undefined}
|
|
||||||
>
|
|
||||||
<CardHeader className="text-center p-0 h-full flex flex-col">
|
|
||||||
<div className="flex justify-center">
|
|
||||||
{imageUrl ? (
|
|
||||||
<img
|
|
||||||
src={imageUrl}
|
|
||||||
alt={badgeName}
|
|
||||||
className={cn(
|
|
||||||
"w-32 h-32 rounded-lg object-cover",
|
|
||||||
awarded ? "" : "opacity-50 grayscale blur-md"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
) : null}
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-col flex-1 mt-4">
|
|
||||||
{/* Title area - fixed height for 2 lines */}
|
|
||||||
<div className="min-h-[3.5rem] flex items-start justify-center">
|
|
||||||
{awarded ? (
|
|
||||||
<CardTitle className="text-lg leading-tight line-clamp-2">
|
|
||||||
{badgeName}
|
|
||||||
</CardTitle>
|
|
||||||
) : (
|
|
||||||
<Lock className="h-5 w-5 text-muted-foreground mt-1" />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{/* Description area - fixed height for 2 lines */}
|
|
||||||
{description && (
|
|
||||||
<p className={cn(
|
|
||||||
"text-sm min-h-[2.5rem] line-clamp-2 mt-1",
|
|
||||||
awarded ? "text-muted-foreground" : "text-muted-foreground/70"
|
|
||||||
)}>
|
|
||||||
{description}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
{/* Unlock date - pushed to bottom */}
|
|
||||||
<div className="mt-auto pt-2">
|
|
||||||
{awarded && formattedDate && (
|
|
||||||
<p className="text-xs text-muted-foreground/70">
|
|
||||||
Unlocked {formattedDate}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function BadgesSettings() {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const { nostr } = useNostr();
|
|
||||||
const { user } = useCurrentUser();
|
|
||||||
const { settings } = useAISettings();
|
|
||||||
const { config } = useAppContext();
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const userPubkey = user?.pubkey;
|
|
||||||
const [selectedBadge, setSelectedBadge] = useState<NostrEvent | null>(null);
|
|
||||||
const [progressIndex, setProgressIndex] = useState(0);
|
|
||||||
|
|
||||||
// Find a Shakespeare provider (one with nostr auth) for badge sync
|
|
||||||
const shakespeareProvider = useMemo(
|
|
||||||
() => settings.providers.find(p => p.nostr),
|
|
||||||
[settings.providers]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Badge sync query - calls the server to sync badges and get stats
|
|
||||||
const { data: syncData } = useQuery({
|
|
||||||
queryKey: ['badge-sync', userPubkey, shakespeareProvider?.id],
|
|
||||||
queryFn: async (): Promise<BadgeSyncResponse> => {
|
|
||||||
if (!shakespeareProvider || !user) {
|
|
||||||
throw new Error('No provider or user available');
|
|
||||||
}
|
|
||||||
const ai = createAIClient(shakespeareProvider, user, config.corsProxy);
|
|
||||||
const response = await ai.post('/badges/sync', {}) as BadgeSyncResponse;
|
|
||||||
|
|
||||||
// If any badges were synced, invalidate the badge awards query
|
|
||||||
if (response.synced.length > 0) {
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['badge-awards', BADGE_ISSUER_PUBKEY, userPubkey] });
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
},
|
|
||||||
enabled: !!user && !!shakespeareProvider,
|
|
||||||
staleTime: 0, // Always refetch on mount for fresh progress
|
|
||||||
gcTime: 5 * 60 * 1000, // Keep in cache for 5 min
|
|
||||||
retry: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get stats from sync response
|
|
||||||
const stats = syncData?.stats;
|
|
||||||
|
|
||||||
// Get milestones from server (no fallbacks - if server doesn't provide, use empty arrays)
|
|
||||||
const tokenMilestones = useMemo((): TokenMilestone[] => {
|
|
||||||
return syncData?.milestones?.tokenMilestones || [];
|
|
||||||
}, [syncData?.milestones]);
|
|
||||||
|
|
||||||
const imageMilestones = useMemo(() => {
|
|
||||||
return syncData?.milestones?.imageMilestones.map(m => m.count) || [];
|
|
||||||
}, [syncData?.milestones]);
|
|
||||||
|
|
||||||
// Get credit milestones (thresholds with credit rewards)
|
|
||||||
const creditMilestones = useMemo(() => {
|
|
||||||
return syncData?.milestones?.tokenMilestones
|
|
||||||
.filter(m => m.creditReward !== undefined)
|
|
||||||
.map(m => m.threshold) || [];
|
|
||||||
}, [syncData?.milestones]);
|
|
||||||
|
|
||||||
const tokenProgress = stats
|
|
||||||
? getTokenMilestoneProgress(stats.generation_count, stats.total_tokens, tokenMilestones)
|
|
||||||
: null;
|
|
||||||
const imageProgress = stats
|
|
||||||
? getImageMilestoneProgress(stats.image_count, imageMilestones)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const { data: badgeDefinitions, isLoading: isLoadingDefinitions } = useQuery({
|
|
||||||
queryKey: ['badge-definitions', BADGE_ISSUER_PUBKEY],
|
|
||||||
queryFn: async (c) => {
|
|
||||||
const signal = AbortSignal.any([c.signal, AbortSignal.timeout(5000)]);
|
|
||||||
const events = await nostr.query([{
|
|
||||||
kinds: [30009],
|
|
||||||
authors: [BADGE_ISSUER_PUBKEY],
|
|
||||||
limit: 100,
|
|
||||||
}], { signal });
|
|
||||||
return events;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Query for badge awards if user is logged in
|
|
||||||
const { data: badgeAwards, isLoading: isLoadingAwards } = useQuery({
|
|
||||||
queryKey: ['badge-awards', BADGE_ISSUER_PUBKEY, userPubkey],
|
|
||||||
queryFn: async (c) => {
|
|
||||||
if (!userPubkey) return [];
|
|
||||||
|
|
||||||
const signal = AbortSignal.any([c.signal, AbortSignal.timeout(5000)]);
|
|
||||||
const events = await nostr.query([{
|
|
||||||
kinds: [8],
|
|
||||||
authors: [BADGE_ISSUER_PUBKEY],
|
|
||||||
"#p": [userPubkey],
|
|
||||||
limit: 100,
|
|
||||||
}], { signal });
|
|
||||||
return events;
|
|
||||||
},
|
|
||||||
enabled: !!userPubkey,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create a map of awarded badges (a-tag -> first award date)
|
|
||||||
const awardedBadges = new Map<string, number>();
|
|
||||||
if (badgeAwards) {
|
|
||||||
for (const award of badgeAwards) {
|
|
||||||
const aTag = award.tags.find(([t]) => t === "a")?.[1];
|
|
||||||
if (aTag) {
|
|
||||||
// Store the earliest award date for this badge
|
|
||||||
const existingDate = awardedBadges.get(aTag);
|
|
||||||
if (!existingDate || award.created_at < existingDate) {
|
|
||||||
awardedBadges.set(aTag, award.created_at);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper to check if a badge is awarded
|
|
||||||
const isBadgeAwarded = (badgeDefinition: NostrEvent): boolean => {
|
|
||||||
if (!userPubkey) return false;
|
|
||||||
const dTag = badgeDefinition.tags.find(([t]) => t === "d")?.[1];
|
|
||||||
if (!dTag) return false;
|
|
||||||
const aTag = `30009:${BADGE_ISSUER_PUBKEY}:${dTag}`;
|
|
||||||
return awardedBadges.has(aTag);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper to get first award date for a badge
|
|
||||||
const getFirstAwardDate = (badgeDefinition: NostrEvent): number | null => {
|
|
||||||
if (!userPubkey) return null;
|
|
||||||
const dTag = badgeDefinition.tags.find(([t]) => t === "d")?.[1];
|
|
||||||
if (!dTag) return null;
|
|
||||||
const aTag = `30009:${BADGE_ISSUER_PUBKEY}:${dTag}`;
|
|
||||||
return awardedBadges.get(aTag) || null;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Sort badges: unlocked by first award date (earliest first), then locked badges
|
|
||||||
const sortedBadgeDefinitions = badgeDefinitions ? [...badgeDefinitions].sort((a, b) => {
|
|
||||||
const aAwarded = isBadgeAwarded(a);
|
|
||||||
const bAwarded = isBadgeAwarded(b);
|
|
||||||
|
|
||||||
// If both are awarded, sort by first award date (earliest first)
|
|
||||||
if (aAwarded && bAwarded) {
|
|
||||||
const aDate = getFirstAwardDate(a) || 0;
|
|
||||||
const bDate = getFirstAwardDate(b) || 0;
|
|
||||||
return aDate - bDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If only one is awarded, awarded comes first
|
|
||||||
if (aAwarded && !bAwarded) return -1;
|
|
||||||
if (!aAwarded && bAwarded) return 1;
|
|
||||||
|
|
||||||
// Both are locked, maintain original order
|
|
||||||
return 0;
|
|
||||||
}) : [];
|
|
||||||
|
|
||||||
const isLoading = isLoadingDefinitions || (userPubkey && isLoadingAwards);
|
|
||||||
|
|
||||||
// Calculate badge counts
|
|
||||||
const totalBadges = sortedBadgeDefinitions.length;
|
|
||||||
const unlockedBadges = sortedBadgeDefinitions.filter(badge => isBadgeAwarded(badge)).length;
|
|
||||||
const progressPercentage = totalBadges > 0 ? (unlockedBadges / totalBadges) * 100 : 0;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<SettingsPageLayout
|
|
||||||
icon={Award}
|
|
||||||
titleKey="badges"
|
|
||||||
descriptionKey="badgesDescription"
|
|
||||||
titleSuffix={
|
|
||||||
!isLoading && totalBadges > 0 ? (
|
|
||||||
<div className="flex flex-wrap items-center gap-3 ml-3">
|
|
||||||
<Card className="bg-muted/50 border">
|
|
||||||
<CardContent className="py-1.5 px-4">
|
|
||||||
<p className="text-sm font-medium">
|
|
||||||
<span className="text-foreground">{unlockedBadges}</span>
|
|
||||||
<span className="text-muted-foreground"> / </span>
|
|
||||||
<span className="text-foreground">{totalBadges}</span>
|
|
||||||
<span className="text-muted-foreground"> unlocked</span>
|
|
||||||
</p>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
<Card className="bg-muted/50 border">
|
|
||||||
<CardContent className="py-1.5 px-4">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Progress value={progressPercentage} className="h-1.5 w-24" />
|
|
||||||
<span className="text-sm font-medium">{Math.round(progressPercentage)}%</span>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
) : undefined
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<BadgeAwardModal
|
|
||||||
badgeDefinition={selectedBadge}
|
|
||||||
onClose={() => setSelectedBadge(null)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Progress Tracking Section */}
|
|
||||||
{stats && (() => {
|
|
||||||
type ProgressItem =
|
|
||||||
| { category: 'token'; progress: TokenProgressResult }
|
|
||||||
| { category: 'image'; progress: { progress: number; current: number; next: number } };
|
|
||||||
|
|
||||||
const progressItems: ProgressItem[] = [];
|
|
||||||
if (tokenProgress) {
|
|
||||||
progressItems.push({ category: 'token', progress: tokenProgress });
|
|
||||||
}
|
|
||||||
if (imageProgress) {
|
|
||||||
progressItems.push({ category: 'image', progress: imageProgress });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (progressItems.length === 0) return null;
|
|
||||||
|
|
||||||
const currentIndex = progressIndex % progressItems.length;
|
|
||||||
const current = progressItems[currentIndex];
|
|
||||||
|
|
||||||
// Format progress display based on milestone type
|
|
||||||
const formatProgress = () => {
|
|
||||||
if (current.category === 'token') {
|
|
||||||
const tokenProg = current.progress as TokenProgressResult;
|
|
||||||
const next = tokenProg.next ?? 0;
|
|
||||||
// For generation-based milestones, show simple numbers
|
|
||||||
if (tokenProg.type === 'generation') {
|
|
||||||
return `${tokenProg.current} / ${next}`;
|
|
||||||
}
|
|
||||||
// For token-based milestones, format large numbers
|
|
||||||
return `${formatNumber(tokenProg.current)} / ${formatNumber(next)}`;
|
|
||||||
}
|
|
||||||
// Image progress - simple numbers
|
|
||||||
return `${current.progress.current} / ${current.progress.next}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card
|
|
||||||
className="mb-6 cursor-pointer hover:bg-muted/50 transition-colors"
|
|
||||||
onClick={() => setProgressIndex(prev => prev + 1)}
|
|
||||||
>
|
|
||||||
<CardContent className="py-4">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<div className="flex justify-between items-center">
|
|
||||||
<span className="text-sm font-medium">
|
|
||||||
{current.category === 'token' ? t('tokenProgress') : t('imageProgress')}
|
|
||||||
</span>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span className="text-xs text-muted-foreground">
|
|
||||||
{formatProgress()}
|
|
||||||
</span>
|
|
||||||
{current.category === 'token' && current.progress.next && isCreditMilestone(current.progress.next, creditMilestones) && (() => {
|
|
||||||
const milestone = syncData?.milestones?.tokenMilestones.find(m => m.threshold === current.progress.next);
|
|
||||||
const creditAmount = milestone?.creditReward ?? 0;
|
|
||||||
// Only show badge if credit amount is greater than 0
|
|
||||||
if (creditAmount <= 0) return null;
|
|
||||||
return (
|
|
||||||
<Badge variant="default" className="text-xs">
|
|
||||||
${creditAmount} Credit
|
|
||||||
</Badge>
|
|
||||||
);
|
|
||||||
})()}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<Progress value={current.progress.progress} className="h-2" />
|
|
||||||
<div className="flex justify-between items-center">
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{t('nextBadgeAt', { milestone: formatNumber(current.progress.next ?? 0) })}
|
|
||||||
</p>
|
|
||||||
{progressItems.length > 1 && (
|
|
||||||
<div className="flex gap-1">
|
|
||||||
{progressItems.map((_, i) => (
|
|
||||||
<div
|
|
||||||
key={i}
|
|
||||||
className={cn(
|
|
||||||
"w-1.5 h-1.5 rounded-full transition-colors",
|
|
||||||
i === currentIndex ? "bg-primary" : "bg-muted-foreground/30"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
})()}
|
|
||||||
|
|
||||||
<div className="space-y-4">
|
|
||||||
{isLoading ? (
|
|
||||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
|
||||||
{[1, 2, 3].map((i) => (
|
|
||||||
<Card key={i}>
|
|
||||||
<CardHeader className="text-center space-y-4">
|
|
||||||
<div className="flex justify-center">
|
|
||||||
<Skeleton className="w-32 h-32 rounded-lg" />
|
|
||||||
</div>
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Skeleton className="h-5 w-32 mx-auto" />
|
|
||||||
<Skeleton className="h-4 w-full" />
|
|
||||||
<Skeleton className="h-4 w-3/4 mx-auto" />
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
|
||||||
</Card>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
) : sortedBadgeDefinitions && sortedBadgeDefinitions.length > 0 ? (
|
|
||||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
|
||||||
{sortedBadgeDefinitions.map((event) => (
|
|
||||||
<BadgeCard
|
|
||||||
key={event.id}
|
|
||||||
event={event}
|
|
||||||
awarded={isBadgeAwarded(event)}
|
|
||||||
unlockDate={getFirstAwardDate(event)}
|
|
||||||
onClick={isBadgeAwarded(event) ? () => setSelectedBadge(event) : undefined}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<Card>
|
|
||||||
<CardContent className="py-12 px-8 text-center">
|
|
||||||
<div className="max-w-sm mx-auto space-y-4">
|
|
||||||
<Award className="h-12 w-12 mx-auto text-muted-foreground" />
|
|
||||||
<p className="text-muted-foreground">
|
|
||||||
{t('noBadgesFound')}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</SettingsPageLayout>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default BadgesSettings;
|
|
||||||
|
|
||||||
+1
-1
@@ -29,7 +29,7 @@ export default defineConfig(() => ({
|
|||||||
plugins: [
|
plugins: [
|
||||||
react(),
|
react(),
|
||||||
VitePWA({
|
VitePWA({
|
||||||
includeAssets: ['shakespeare.svg', 'shakespeare-192x192.png', 'shakespeare-512x512.png', 'sine.mp3', 'badgeAwarded.mp3'],
|
includeAssets: ['shakespeare.svg', 'shakespeare-192x192.png', 'shakespeare-512x512.png', 'sine.mp3'],
|
||||||
manifest: false, // Use existing manifest.webmanifest from public folder
|
manifest: false, // Use existing manifest.webmanifest from public folder
|
||||||
workbox: {
|
workbox: {
|
||||||
globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2,wasm,mp3}'],
|
globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2,wasm,mp3}'],
|
||||||
|
|||||||
Reference in new issue
Block a user